"add a few constructs"

This commit is contained in:
IoIxD 2026-01-21 11:21:23 -07:00
commit 118f706b00
2 changed files with 54 additions and 36 deletions

View file

@ -44,9 +44,6 @@ void msh_lexer_parse(msh_lexer *lexer, char *buf, SIZE_TYPE sz) {
char *cur_word_buf = msh_callocate(1024, sizeof(char)); char *cur_word_buf = msh_callocate(1024, sizeof(char));
for (i = 0; i < sz; i++) {
int do_clear = 0;
switch (buf[i]) {
/*case '#': /*case '#':
do_clear = 1; do_clear = 1;
break; break;
@ -79,7 +76,25 @@ void msh_lexer_parse(msh_lexer *lexer, char *buf, SIZE_TYPE sz) {
do_clear = 1; do_clear = 1;
break; break;
*/ */
int quote_mode = 0;
for (i = 0; i < sz; i++) {
int do_clear = 0;
switch (buf[i]) {
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 ' ': case ' ':
if (quote_mode == 1) {
goto do_add;
break;
}
case '\n': case '\n':
case '\0': case '\0':
cur_word_buf[n++] = '\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; do_clear = 1;
break; break;
default: default:
do_add:
cur_word_buf[n++] = buf[i]; cur_word_buf[n++] = buf[i];
break; break;
} }
@ -97,6 +113,7 @@ void msh_lexer_parse(msh_lexer *lexer, char *buf, SIZE_TYPE sz) {
n = 0; n = 0;
} }
} }
lexer_cancel:
msh_deallocate(cur_word_buf); msh_deallocate(cur_word_buf);
} }
@ -134,8 +151,12 @@ void msh_lexer_execute(msh_lexer *lexer) {
} }
args[n++] = 0; args[n++] = 0;
/* Do nothing on blank commands */
if (*cmd == '\0') {
exec_success = 1;
}
/* Check if the command is a built-in */ /* Check if the command is a built-in */
if (msh_try_builtin(cmd, args)) { else if (msh_try_builtin(cmd, args)) {
exec_success = 1; exec_success = 1;
} }
/* If the command is a folder, cd to it */ /* If the command is a folder, cd to it */

View file

@ -59,9 +59,6 @@ void msh_write(char *st, SIZE_TYPE size) { SYSCALL(write, 1, st, size); }
int msh_execute(char *cmd, char **args) { int msh_execute(char *cmd, char **args) {
SIZE_TYPE fork; SIZE_TYPE fork;
if (*cmd == '\0') {
return 0;
}
fork = (SIZE_TYPE)SYSCALL(fork, 0); fork = (SIZE_TYPE)SYSCALL(fork, 0);
if (fork == 0) { if (fork == 0) {