diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2021-10-13 09:08:59 -0700 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2021-10-13 09:08:59 -0700 |
commit | 2ade60747db41771498ab2b85ce6e3c3389f2c26 (patch) | |
tree | 302927100158a1b50954e5ca4cb5c564bf19beec /sys/cmd/rc/trap.c | |
parent | d1a19f0d477a6249d8af9322317b8434b86260ea (diff) |
feat(rc): added unix port of rc with linenoise
Diffstat (limited to 'sys/cmd/rc/trap.c')
-rw-r--r-- | sys/cmd/rc/trap.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/sys/cmd/rc/trap.c b/sys/cmd/rc/trap.c new file mode 100644 index 0000000..a572cac --- /dev/null +++ b/sys/cmd/rc/trap.c @@ -0,0 +1,37 @@ +#include "rc.h" +#include "exec.h" +#include "fns.h" +#include "io.h" +extern char *Signame[]; + +void +dotrap(void) +{ + int i; + struct var *trapreq; + struct word *starval; + starval = vlook("*")->val; + while(ntrap) for(i = 0;i!=NSIG;i++) while(trap[i]){ + --trap[i]; + --ntrap; + if(getpid()!=mypid) Exit(getstatus()); + trapreq = vlook(Signame[i]); + if(trapreq->fn){ + start(trapreq->fn, trapreq->pc, (struct var *)0); + runq->local = newvar(strdup("*"), runq->local); + runq->local->val = copywords(starval, (struct word *)0); + runq->local->changed = 1; + runq->redir = runq->startredir = 0; + } + else if(i==SIGINT || i==SIGQUIT){ + /* + * run the stack down until we uncover the + * command reading loop. Xreturn will exit + * if there is none (i.e. if this is not + * an interactive rc.) + */ + while(!runq->iflag) Xreturn(); + } + else Exit(getstatus()); + } +} |