1 9aa1c92f 2005-01-04 devnull #include "mk.h"
3 9aa1c92f 2005-01-04 devnull static Shell *shells[] = {
8 2222020e 2005-10-29 devnull Shell *shelldefault = &shshell;
10 9aa1c92f 2005-01-04 devnull Shell *shellt;
11 9aa1c92f 2005-01-04 devnull Word *shellcmd;
13 9aa1c92f 2005-01-04 devnull typedef struct Shellstack Shellstack;
14 9aa1c92f 2005-01-04 devnull struct Shellstack
16 9aa1c92f 2005-01-04 devnull Shell *t;
18 9aa1c92f 2005-01-04 devnull Shellstack *next;
21 9aa1c92f 2005-01-04 devnull Shellstack *shellstack;
24 9aa1c92f 2005-01-04 devnull setshell(Word *w)
28 9aa1c92f 2005-01-04 devnull if(w->s == nil)
29 9aa1c92f 2005-01-04 devnull return "shell name not found on line";
31 9aa1c92f 2005-01-04 devnull for(i=0; i<nelem(shells); i++)
32 9aa1c92f 2005-01-04 devnull if(shells[i]->matchname(w->s))
34 9aa1c92f 2005-01-04 devnull if(i == nelem(shells))
35 9aa1c92f 2005-01-04 devnull return "cannot determine shell type";
36 9aa1c92f 2005-01-04 devnull shellt = shells[i];
37 9aa1c92f 2005-01-04 devnull shellcmd = w;
38 9aa1c92f 2005-01-04 devnull return nil;
42 9aa1c92f 2005-01-04 devnull initshell(void)
44 2222020e 2005-10-29 devnull shellcmd = stow(shelldefault->name);
45 2222020e 2005-10-29 devnull shellt = shelldefault;
46 c8b6342d 2005-01-13 devnull setvar("MKSHELL", shellcmd);
50 9aa1c92f 2005-01-04 devnull pushshell(void)
52 9aa1c92f 2005-01-04 devnull Shellstack *s;
54 9aa1c92f 2005-01-04 devnull /* save */
55 9aa1c92f 2005-01-04 devnull s = Malloc(sizeof *s);
56 9aa1c92f 2005-01-04 devnull s->t = shellt;
57 9aa1c92f 2005-01-04 devnull s->w = shellcmd;
58 9aa1c92f 2005-01-04 devnull s->next = shellstack;
59 9aa1c92f 2005-01-04 devnull shellstack = s;
61 9aa1c92f 2005-01-04 devnull initshell(); /* reset to defaults */
65 9aa1c92f 2005-01-04 devnull popshell(void)
67 9aa1c92f 2005-01-04 devnull Shellstack *s;
69 9aa1c92f 2005-01-04 devnull if(shellstack == nil){
70 9aa1c92f 2005-01-04 devnull fprint(2, "internal shellstack error\n");
74 9aa1c92f 2005-01-04 devnull s = shellstack;
75 9aa1c92f 2005-01-04 devnull shellstack = s->next;
76 9aa1c92f 2005-01-04 devnull shellt = s->t;
77 9aa1c92f 2005-01-04 devnull shellcmd = s->w;
78 c8b6342d 2005-01-13 devnull setvar("MKSHELL", shellcmd);