diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2021-10-19 10:53:45 -0700 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2021-10-19 10:53:45 -0700 |
commit | af3fa90e8bb41c306c5fe2d2cf105db6bbabd1d9 (patch) | |
tree | 807c8b5a18a1ff663808b5c369bf1262fdf03021 /sys/cmd/rc/exec.c | |
parent | 47e3d475df6244a48b73421cd4210b64c392df8d (diff) |
Feat: word operators and more robust crashing
Added the length and concatenate operators.
Slightly improved the robustness on syntax errors.
Diffstat (limited to 'sys/cmd/rc/exec.c')
-rw-r--r-- | sys/cmd/rc/exec.c | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/sys/cmd/rc/exec.c b/sys/cmd/rc/exec.c index d78cb5d..87b6bb7 100644 --- a/sys/cmd/rc/exec.c +++ b/sys/cmd/rc/exec.c @@ -582,7 +582,11 @@ Xreadcmd(void) root = runner; if(yyparse()){ - exit(1); + // resource cleanup? + if(runner->flag.eof) + Xreturn(); + else + --root->code.i; }else{ --root->code.i; /* re-execute Xreadcmd after codebuf runs */ run(compiled, 1, root->local); @@ -671,8 +675,65 @@ Xbasic(void) } void +Xcount(void) +{ + Word *arg; + char *str, num[12]; + + if(count(runner->args->word) != 1){ + Xerror("variable name not a singleton\n"); + return; + } + + str = runner->args->word->str; + arg = var(str)->val; + poplist(); + + itoa(num, count(arg)); + pushword(num); +} + +void +Xflat(void) +{ + int len; + char *str; + Word *arg, *a; + + if(count(runner->args->word)!=1){ + Xerror("variable name is not a singleton\n"); + return; + } + + str = runner->args->word->str; + arg = var(str)->val; + poplist(); + + len = count(arg); + if(!len){ + pushword(""); + return; + } + + for(a=arg; a; a=a->link) + len += strlen(a->str); + + str = emalloc(len); + if(arg){ + strcpy(str, arg->str); + for(a = arg->link; a; a = a->link){ + strcat(str," "); + strcat(str,a->str); + } + }else + str[0] = 0; + + pushword(str); + efree(str); +} + +void Xexit(void) { exit(shell.status); } - |