diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c index 1c41b35..b5b5ff1 100644 --- a/src/lexer/lexer.c +++ b/src/lexer/lexer.c @@ -44,42 +44,57 @@ void msh_lexer_parse(msh_lexer *lexer, char *buf, SIZE_TYPE sz) { char *cur_word_buf = msh_callocate(1024, sizeof(char)); + /*case '#': + do_clear = 1; + break; + case '|': + if (i + 1 < sz) { + if (buf[i + 1] == '|') { + msh_lexer_push_item(lexer, MSH_LEXER_ITEM_TYPE_OP_OR, buf, 2); + last = i + 2; + } else { + msh_lexer_push_item(lexer, MSH_LEXER_ITEM_TYPE_OP_PIPE, buf, 1); + last = i + 1; + } + } + do_clear = 1; + break; + case '&': + if (i + 1 < sz) { + if (buf[i + 1] == '&') { + msh_lexer_push_item(lexer, MSH_LEXER_ITEM_TYPE_OP_AND, buf, 2); + last = i + 2; + } else { + msh_lexer_push_item(lexer, MSH_LEXER_ITEM_TYPE_OP_CONTROL, buf, 1); + last = i + 1; + } + } + do_clear = 1; + break; + case ';': + msh_lexer_push_item(lexer, MSH_LEXER_ITEM_TYPE_OP_SEMICOLON, buf, 1); + do_clear = 1; + break; + */ + + int quote_mode = 0; + for (i = 0; i < sz; i++) { int do_clear = 0; switch (buf[i]) { - /*case '#': - do_clear = 1; - break; - case '|': - if (i + 1 < sz) { - if (buf[i + 1] == '|') { - msh_lexer_push_item(lexer, MSH_LEXER_ITEM_TYPE_OP_OR, buf, 2); - last = i + 2; - } else { - msh_lexer_push_item(lexer, MSH_LEXER_ITEM_TYPE_OP_PIPE, buf, 1); - last = i + 1; - } - } - do_clear = 1; - break; - case '&': - if (i + 1 < sz) { - if (buf[i + 1] == '&') { - msh_lexer_push_item(lexer, MSH_LEXER_ITEM_TYPE_OP_AND, buf, 2); - last = i + 2; - } else { - msh_lexer_push_item(lexer, MSH_LEXER_ITEM_TYPE_OP_CONTROL, buf, 1); - last = i + 1; - } - } - do_clear = 1; - break; - case ';': - msh_lexer_push_item(lexer, MSH_LEXER_ITEM_TYPE_OP_SEMICOLON, buf, 1); - do_clear = 1; - break; - */ + case '#': + cur_word_buf[n++] = '\0'; + msh_lexer_push_item(lexer, MSH_LEXER_ITEM_TYPE_WORD, cur_word_buf, n); + goto lexer_cancel; + case '"': + case '\'': + quote_mode = !quote_mode; + goto do_add; case ' ': + if (quote_mode == 1) { + goto do_add; + break; + } case '\n': case '\0': cur_word_buf[n++] = '\0'; @@ -87,6 +102,7 @@ void msh_lexer_parse(msh_lexer *lexer, char *buf, SIZE_TYPE sz) { do_clear = 1; break; default: + do_add: cur_word_buf[n++] = buf[i]; break; } @@ -97,6 +113,7 @@ void msh_lexer_parse(msh_lexer *lexer, char *buf, SIZE_TYPE sz) { n = 0; } } +lexer_cancel: msh_deallocate(cur_word_buf); } @@ -134,8 +151,12 @@ void msh_lexer_execute(msh_lexer *lexer) { } args[n++] = 0; + /* Do nothing on blank commands */ + if (*cmd == '\0') { + exec_success = 1; + } /* Check if the command is a built-in */ - if (msh_try_builtin(cmd, args)) { + else if (msh_try_builtin(cmd, args)) { exec_success = 1; } /* If the command is a folder, cd to it */ diff --git a/src/system/linux/linux.c b/src/system/linux/linux.c index b49eb33..1646a38 100644 --- a/src/system/linux/linux.c +++ b/src/system/linux/linux.c @@ -59,9 +59,6 @@ void msh_write(char *st, SIZE_TYPE size) { SYSCALL(write, 1, st, size); } int msh_execute(char *cmd, char **args) { SIZE_TYPE fork; - if (*cmd == '\0') { - return 0; - } fork = (SIZE_TYPE)SYSCALL(fork, 0); if (fork == 0) {