Commit | Line | Data |
---|---|---|
0ac28e48 KM |
1 | /* stak.c 4.1 82/05/07 */ |
2 | ||
3 | # | |
4 | /* | |
5 | * UNIX shell | |
6 | * | |
7 | * S. R. Bourne | |
8 | * Bell Telephone Laboratories | |
9 | * | |
10 | */ | |
11 | ||
12 | #include "defs.h" | |
13 | ||
14 | STKPTR stakbot=nullstr; | |
15 | ||
16 | ||
17 | ||
18 | /* ======== storage allocation ======== */ | |
19 | ||
20 | STKPTR getstak(asize) | |
21 | INT asize; | |
22 | { /* allocate requested stack */ | |
23 | REG STKPTR oldstak; | |
24 | REG INT size; | |
25 | ||
26 | size=round(asize,BYTESPERWORD); | |
27 | oldstak=stakbot; | |
28 | staktop = stakbot += size; | |
29 | return(oldstak); | |
30 | } | |
31 | ||
32 | STKPTR locstak() | |
33 | { /* set up stack for local use | |
34 | * should be followed by `endstak' | |
35 | */ | |
36 | IF brkend-stakbot<BRKINCR | |
37 | THEN setbrk(brkincr); | |
38 | IF brkincr < BRKMAX | |
39 | THEN brkincr += 256; | |
40 | FI | |
41 | FI | |
42 | return(stakbot); | |
43 | } | |
44 | ||
45 | STKPTR savstak() | |
46 | { | |
47 | assert(staktop==stakbot); | |
48 | return(stakbot); | |
49 | } | |
50 | ||
51 | STKPTR endstak(argp) | |
52 | REG STRING argp; | |
53 | { /* tidy up after `locstak' */ | |
54 | REG STKPTR oldstak; | |
55 | *argp++=0; | |
56 | oldstak=stakbot; stakbot=staktop=round(argp,BYTESPERWORD); | |
57 | return(oldstak); | |
58 | } | |
59 | ||
60 | VOID tdystak(x) | |
61 | REG STKPTR x; | |
62 | { | |
63 | /* try to bring stack back to x */ | |
64 | WHILE ADR(stakbsy)>ADR(x) | |
65 | DO free(stakbsy); | |
66 | stakbsy = stakbsy->word; | |
67 | OD | |
68 | staktop=stakbot=max(ADR(x),ADR(stakbas)); | |
69 | rmtemp(x); | |
70 | } | |
71 | ||
72 | stakchk() | |
73 | { | |
74 | IF (brkend-stakbas)>BRKINCR+BRKINCR | |
75 | THEN setbrk(-BRKINCR); | |
76 | FI | |
77 | } | |
78 | ||
79 | STKPTR cpystak(x) | |
80 | STKPTR x; | |
81 | { | |
82 | return(endstak(movstr(x,locstak()))); | |
83 | } |