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 setvar("MKSHELL", shellcmd);45 }47 void48 pushshell(void)49 {50 Shellstack *s;52 /* save */53 s = Malloc(sizeof *s);54 s->t = shellt;55 s->w = shellcmd;56 s->next = shellstack;57 shellstack = s;59 initshell(); /* reset to defaults */60 }62 void63 popshell(void)64 {65 Shellstack *s;67 if(shellstack == nil){68 fprint(2, "internal shellstack error\n");69 Exit();70 }72 s = shellstack;73 shellstack = s->next;74 shellt = s->t;75 shellcmd = s->w;76 setvar("MKSHELL", shellcmd);77 free(s);78 }