diff --git a/src/main.c b/src/main.c index 3c4bc8d..62c7bb7 100644 --- a/src/main.c +++ b/src/main.c @@ -17,7 +17,7 @@ MSH_ENTRY_POINT { msh_print_strings(msh_working_directory(), " %> ", 0); - while ((out = msh_read_input(buf, &sz, 2048)), !out) { + while ((out = msh_read_input(buf, &sz, 2048)), out > 0) { } if (*buf != '\0') { diff --git a/src/system/linux/linux.c b/src/system/linux/linux.c index c231f95..e1b598e 100644 --- a/src/system/linux/linux.c +++ b/src/system/linux/linux.c @@ -31,26 +31,27 @@ int msh_read_input(char *ptr, SIZE_TYPE *size, SIZE_TYPE n) { case '\r': ptr[*size] = '\0'; SYSCALL(write, 1, "\n\r", 2); - return 1; + return -1; break; /* backspace */ - case '\177': + case 127: if (*size <= 0) { return 0; } - SYSCALL(write, 1, "\33[D \33[D", 7); *size -= 1; break; + default: + break; } } } if (*size >= n) { - return 2; + return -2; } - return 0; + return ch; }; void msh_write(char *st, SIZE_TYPE size) { SYSCALL(write, 1, st, size); } diff --git a/src/system/system.h b/src/system/system.h index 803c3bb..01186df 100644 --- a/src/system/system.h +++ b/src/system/system.h @@ -59,10 +59,11 @@ void msh_file_read(msh_file *file, char *ptr, SIZE_TYPE n); /* * Read user input into ptr, stopping if it has reached n characters. - * Also responsible for handling backspace. + * Also has to handle backspace since erasing characters is system-dependent. * RETURNS: - * - 1 if finished reading - * - 2 if it ran out of space. + * -2 = if it ran out of space. + * -1 = if finished reading + * 0 < ascii character */ int msh_read_input(char *ptr, SIZE_TYPE *size, SIZE_TYPE n);