Blob
1 #include "mk.h"3 static Shell *shells[] = {4 &shshell,5 &rcshell6 };8 Shell *shellt;9 Word *shellcmd;11 typedef struct Shellstack Shellstack;12 struct Shellstack13 {14 Shell *t;15 Word *w;16 Shellstack *next;17 };19 Shellstack *shellstack;21 char*22 setshell(Word *w)23 {24 int i;26 if(w->s == nil)27 return "shell name not found on line";29 for(i=0; i<nelem(shells); i++)30 if(shells[i]->matchname(w->s))31 break;32 if(i == nelem(shells))33 return "cannot determine shell type";34 shellt = shells[i];35 shellcmd = w;36 return nil;37 }39 void40 initshell(void)41 {42 shellcmd = stow(shells[0]->name);43 shellt = shells[0];44 }46 void47 pushshell(void)48 {49 Shellstack *s;51 /* save */52 s = Malloc(sizeof *s);53 s->t = shellt;54 s->w = shellcmd;55 s->next = shellstack;56 shellstack = s;58 initshell(); /* reset to defaults */59 }61 void62 popshell(void)63 {64 Shellstack *s;66 if(shellstack == nil){67 fprint(2, "internal shellstack error\n");68 Exit();69 }71 s = shellstack;72 shellstack = s->next;73 shellt = s->t;74 shellcmd = s->w;75 free(s);76 }