diff options
Diffstat (limited to 'src/cmd/rc/exec.c')
-rw-r--r-- | src/cmd/rc/exec.c | 133 |
1 files changed, 129 insertions, 4 deletions
diff --git a/src/cmd/rc/exec.c b/src/cmd/rc/exec.c index 71f5359..28b6135 100644 --- a/src/cmd/rc/exec.c +++ b/src/cmd/rc/exec.c @@ -685,12 +685,129 @@ Xmark(void) } void +Xunmark(void) +{ + poplist(); +} + +void Xword(void) { pushword(runner->code.exe[runner->code.i++].s); } void +Xwrite(void) +{ + int fd; + char *path; + + switch(count(runner->args->word)){ + default: + Xerror("> requires singleton\n"); + return; + case 0: + Xerror("> requires path\n"); + return; + case 1: + ; + } + path = runner->args->word->str; + if((fd=open(path,O_CREAT|O_WRONLY,S_IRUSR|S_IWUSR))<0){ + print(shell.err, "%s: ", path); + Xerror("can't open"); + return; + } + pushredir(Ropen, fd, runner->code.exe[runner->code.i++].i); + poplist(); +} + +void +Xappend(void) +{ + int fd; + char *path; + + switch(count(runner->args->word)){ + default: + Xerror(">> requires singleton\n"); + return; + case 0: + Xerror(">> requires path\n"); + return; + case 1: + ; + } + path = runner->args->word->str; + if(((fd=open(path,O_APPEND|O_WRONLY))<0) + && ((fd=open(path,O_CREAT|O_WRONLY,S_IRUSR|S_IWUSR))<0)){ + print(shell.err, "%s: ", path); + Xerror("can't open"); + return; + } + pushredir(Ropen, fd, runner->code.exe[runner->code.i++].i); + poplist(); +} + +void +Xread(void) +{ + int fd; + char *path; + + switch(count(runner->args->word)){ + default: + Xerror("< requires singleton\n"); + return; + case 0: + Xerror("< requires path\n"); + return; + case 1: + ; + } + path = runner->args->word->str; + if((fd=open(path,O_RDONLY))<0){ + print(shell.err, "%s: ", path); + Xerror("can't open"); + return; + } + pushredir(Ropen, fd, runner->code.exe[runner->code.i++].i); + poplist(); +} + +void +Xrdwr(void) +{ + int fd; + char *path; + + switch(count(runner->args->word)){ + default: + Xerror("<> requires singleton\n"); + return; + case 0: + Xerror("<> requires path\n"); + return; + case 1: + ; + } + path = runner->args->word->str; + if((fd=open(path,O_RDWR))<0){ + print(shell.err, "%s: ", path); + Xerror("can't open"); + return; + } + pushredir(Ropen, fd, runner->code.exe[runner->code.i++].i); + poplist(); +} + +void +Xnewpgid(void) +{ + runner->pgid = -1; +} + +void Xsettrue(void) { setstatus(nil); @@ -774,12 +891,15 @@ clean: void Xfor(void) { - if(!runner->args->word){ + if(!runner->args->word){ /* terminate loop */ poplist(); runner->code.i = runner->code.exe[runner->code.i].i; - }else{ + }else{ /* continue loop */ freelist(runner->local->val); + /* reset process group */ + runner->pgid = -1; + /* reset local variables */ runner->local->val = runner->args->word; runner->local->new = 1; runner->args->word = runner->args->word->link; @@ -789,8 +909,7 @@ Xfor(void) } } -static -Word* +static Word* catlist(Word *l, Word *r, Word *tail) { Word *w; @@ -1344,6 +1463,12 @@ Xpopredir(void) } void +Xdelhere(void) +{ + remove(runner->code.exe[runner->code.i++].s); +} + +void Xreturn(void) { Thread *curr = runner; |