"add a few constructs"
This commit is contained in:
parent
e7a7447550
commit
118f706b00
2 changed files with 54 additions and 36 deletions
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue