bios/main: handle all types of carriage return (\r, \n, \r\n or \n\r)
authorFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 9 Oct 2018 08:06:32 +0000 (10:06 +0200)
committerFlorent Kermarrec <florent@enjoy-digital.fr>
Tue, 9 Oct 2018 08:06:51 +0000 (10:06 +0200)
litex/soc/software/bios/main.c

index 818a069d5b8e07cc19eb1735c32f24d283f0887e..e3db0ac0407163c3ff400ea5f22facb43b445f27 100644 (file)
@@ -442,6 +442,7 @@ static void crcbios(void)
 
 static void readstr(char *s, int size)
 {
+       static char skip = 0;
        char c[2];
        int ptr;
 
@@ -449,6 +450,9 @@ static void readstr(char *s, int size)
        ptr = 0;
        while(1) {
                c[0] = readchar();
+               if (c[0] == skip)
+                       continue;
+               skip = 0;
                switch(c[0]) {
                        case 0x7f:
                        case 0x08:
@@ -460,7 +464,12 @@ static void readstr(char *s, int size)
                        case 0x07:
                                break;
                        case '\r':
+                               skip = '\n';
+                               s[ptr] = 0x00;
+                               putsnonl("\n");
+                               return;
                        case '\n':
+                               skip = '\r';
                                s[ptr] = 0x00;
                                putsnonl("\n");
                                return;