diff --git a/boot/boot.c b/boot/boot.c index 69035fd..8dcd959 100644 --- a/boot/boot.c +++ b/boot/boot.c @@ -33,26 +33,55 @@ machdep(void) static void puts(char *s) { - for(;*s;++s) + for(;*s; ++s) putchar(*s); } +static void +putcn(char *s, int n) +{ + for(int i=0; i < n; ++i) + putchar(s[i]); +} + +static int +rdline(char *buf, int n) +{ + char *p = buf; + char *e = buf + n; + + while(p < e){ + int c = getchar(); + switch(c){ + case '\177': + case '\b': + if(p > buf){ + putchar('\177'); + *--p = 0; + } + break; + case '\n': + case '\r': + goto done; + default: + *p++ = c; + break; + } + } + putchar('\n'); +done: + return p - buf; +} + void boot(int bootdev) { - char buf[8192]; - machdep(); - putchar('\n'); for(;;){ - int i=0, c=0; + char buf[8192]; puts("\nboot >> "); - do{ - c = getchar(); - buf[i++] = c; - }while(c != '\n' && i < sizeof(buf) - 1); - buf[i-1] = 0; - puts(buf); + int l = rdline(buf, sizeof(buf)); + putcn(buf, l); } } diff --git a/boot/print.c b/boot/print.c index 6601606..6d571b5 100644 --- a/boot/print.c +++ b/boot/print.c @@ -3,7 +3,6 @@ #include "fn.h" #define TABWIDTH 8 -#define DEL '\177' static void conputc(int c); static int congetc(void); @@ -16,9 +15,9 @@ getchar(void) int c; c = congetc(); - if( c == '\r') + if(c == '\r') c = '\n'; - if((c < ' ' && c != '\n') || c == DEL) + if((c < ' ' && c != '\n') || c == '\177') return c; putchar(c); return c; @@ -28,12 +27,12 @@ void putchar(int c) { switch(c){ - case DEL: + case '\177': conputc('\b'); conputc(' '); case '\b': conputc('\b'); - if(pos) + if(pos > 0) --pos; break; case '\t':