Blob
1 #include "mk.h"3 static Shell *shells[] = {4 &rcshell,5 &shshell6 };8 Shell *shelldefault = &shshell;10 Shell *shellt;11 Word *shellcmd;13 typedef struct Shellstack Shellstack;14 struct Shellstack15 {16 Shell *t;17 Word *w;18 Shellstack *next;19 };21 Shellstack *shellstack;23 char*24 setshell(Word *w)25 {26 int i;28 if(w->s == nil)29 return "shell name not found on line";31 for(i=0; i<nelem(shells); i++)32 if(shells[i]->matchname(w->s))33 break;34 if(i == nelem(shells))35 return "cannot determine shell type";36 shellt = shells[i];37 shellcmd = w;38 return nil;39 }41 void42 initshell(void)43 {44 shellcmd = stow(shelldefault->name);45 shellt = shelldefault;46 setvar("MKSHELL", shellcmd);47 }49 void50 pushshell(void)51 {52 Shellstack *s;54 /* save */55 s = Malloc(sizeof *s);56 s->t = shellt;57 s->w = shellcmd;58 s->next = shellstack;59 shellstack = s;61 initshell(); /* reset to defaults */62 }64 void65 popshell(void)66 {67 Shellstack *s;69 if(shellstack == nil){70 fprint(2, "internal shellstack error\n");71 Exit();72 }74 s = shellstack;75 shellstack = s->next;76 shellt = s->t;77 shellcmd = s->w;78 setvar("MKSHELL", shellcmd);79 free(s);80 }