master
Alessandro Mauri 3 years ago
parent 01d4457763
commit 8618d3daf0
  1. 18
      msh.c

18
msh.c

@ -12,6 +12,8 @@
#include "fstr.h" #include "fstr.h"
#include "err.h" #include "err.h"
#define S_ESCAPE 0x1
fstr_t PS1 = {0}; fstr_t PS1 = {0};
unsigned int histsize = DEF_HISTSIZE; unsigned int histsize = DEF_HISTSIZE;
@ -44,6 +46,7 @@ int main(int argc, char **argv)
(void)argc; (void)argc;
(void)argv; (void)argv;
char i; char i;
unsigned int state = 0;
sh_setup_terminal(); sh_setup_terminal();
for (;;) { for (;;) {
@ -52,12 +55,23 @@ int main(int argc, char **argv)
sh_update_ps1(); sh_update_ps1();
sh_print_ps1(); sh_print_ps1();
fflush(stdout); fflush(stdout);
while (1) { for (int line = 1; line;) {
read(STDIN_FILENO, &i, 1); // This blocks read(STDIN_FILENO, &i, 1); // This blocks
fputc(i, stdout); fputc(i, stdout);
fflush(stdout); fflush(stdout);
if (i == '\n')
switch (i) {
case '\n':
line = state & S_ESCAPE;
break;
case '\\':
state ^= ~S_ESCAPE;
break;
default:
state &= ~S_ESCAPE;
break; break;
}
} }
} }