From f08fdedcee12c06e3ce9ac9bec363915978e8289 Mon Sep 17 00:00:00 2001 From: rsc Date: Sun, 23 Nov 2003 18:04:08 +0000 Subject: Plan 9's rc. not a clear win over byron's, but at least it has the right syntax. --- src/cmd/rc/trap.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/cmd/rc/trap.c (limited to 'src/cmd/rc/trap.c') diff --git a/src/cmd/rc/trap.c b/src/cmd/rc/trap.c new file mode 100644 index 00000000..96ef364a --- /dev/null +++ b/src/cmd/rc/trap.c @@ -0,0 +1,34 @@ +#include "rc.h" +#include "exec.h" +#include "fns.h" +#include "io.h" +extern char *Signame[]; +void dotrap(void){ + register int i; + register struct var *trapreq; + register 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()); + } +} -- cgit v1.2.3