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