fix to do writes in memory properly
[unix-history] / usr / src / old / sh / stak.c
CommitLineData
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
14STKPTR stakbot=nullstr;
15
16
17
18/* ======== storage allocation ======== */
19
20STKPTR 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
32STKPTR 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
45STKPTR savstak()
46{
47 assert(staktop==stakbot);
48 return(stakbot);
49}
50
51STKPTR 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
60VOID 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
72stakchk()
73{
74 IF (brkend-stakbas)>BRKINCR+BRKINCR
75 THEN setbrk(-BRKINCR);
76 FI
77}
78
79STKPTR cpystak(x)
80 STKPTR x;
81{
82 return(endstak(movstr(x,locstak())));
83}