xref: /original-bsd/local/toolchest/ksh/sh/stak.h (revision 74d2fb93)
1 /*
2 
3  *      Copyright (c) 1984, 1985, 1986 AT&T
4  *      All Rights Reserved
5 
6  *      THIS IS UNPUBLISHED PROPRIETARY SOURCE
7  *      CODE OF AT&T.
8  *      The copyright notice above does not
9  *      evidence any actual or intended
10  *      publication of such source code.
11 
12  */
13 /* @(#)stak.h	1.1 */
14 
15 /*
16  *	UNIX shell
17  *
18  *	S. R. Bourne
19  *	AT&T Bell Laboratories
20  *
21  */
22 
23 /*
24  * To use stack as temporary workspace across
25  * possible storage allocation (eg name lookup)
26  * a) get ptr from `relstak'
27  * b) can now use `pushstak'
28  * c) then reset with `setstak'
29  * d) `absstak' gives real address if needed
30  */
31 #define		relstak()	(staktop-stakbot)
32 #define		absstak(x)	(stakbot+Rcheat(x))
33 #define		setstak(x)	(staktop=absstak(x))
34 #define		pushstak(c)	(*staktop++=(c))
35 #define		zerostak()	(*staktop=0)
36 #define	savstak()	(stakbot)
37 
38 /*
39  * Used to address an item left on the top of
40  * the stack (very temporary)
41  */
42 #define		curstak()	(stakbot)
43 
44 /*
45  * `usestak' before `pushstak' then `fixstak'
46  * These routines are safe against heap
47  * being allocated.
48  */
49 #define		usestak()	{locstak();}
50 
51 /*
52  * for local use only since it hands
53  * out a real address for the stack top
54  */
55 STKPTR		locstak();
56 
57 /*
58  * Will allocate the item being used and return its
59  * address (safe now).
60  */
61 #define		fixstak()	endstak(staktop)
62 
63 /*
64  * For use after `locstak' to hand back
65  * new stack top and then allocate item
66  */
67 STKPTR		endstak();
68 
69 /*
70  * Copy a string onto the stack and
71  * allocate the space.
72  */
73 STKPTR		cpystak();
74 
75 /* Allocate given amount of stack space */
76 STKPTR		getstak();
77 
78 /*
79  * A chain of ptrs of stack blocks that
80  * have become covered by heap allocation.
81  * `tdystak' will return them to the heap.
82  */
83 extern BLKPTR		stakbsy;
84 
85 /* Base of the entire stack */
86 extern STKPTR		stakbas;
87 
88 /* Top of entire stack */
89 extern STKPTR		brkend;
90 
91 /* Base of current item */
92 extern STKPTR		stakbot;
93 
94 /* Top of current item */
95 extern STKPTR		staktop;
96 
97