1*6705Smckusick /* stak.h 4.1 82/05/07 */ 2*6705Smckusick 3*6705Smckusick # 4*6705Smckusick /* 5*6705Smckusick * UNIX shell 6*6705Smckusick * 7*6705Smckusick * S. R. Bourne 8*6705Smckusick * Bell Telephone Laboratories 9*6705Smckusick * 10*6705Smckusick */ 11*6705Smckusick 12*6705Smckusick /* To use stack as temporary workspace across 13*6705Smckusick * possible storage allocation (eg name lookup) 14*6705Smckusick * a) get ptr from `relstak' 15*6705Smckusick * b) can now use `pushstak' 16*6705Smckusick * c) then reset with `setstak' 17*6705Smckusick * d) `absstak' gives real address if needed 18*6705Smckusick */ 19*6705Smckusick #define relstak() (staktop-stakbot) 20*6705Smckusick #define absstak(x) (stakbot+Rcheat(x)) 21*6705Smckusick #define setstak(x) (staktop=absstak(x)) 22*6705Smckusick #define pushstak(c) (*staktop++=(c)) 23*6705Smckusick #define zerostak() (*staktop=0) 24*6705Smckusick 25*6705Smckusick /* Used to address an item left on the top of 26*6705Smckusick * the stack (very temporary) 27*6705Smckusick */ 28*6705Smckusick #define curstak() (staktop) 29*6705Smckusick 30*6705Smckusick /* `usestak' before `pushstak' then `fixstak' 31*6705Smckusick * These routines are safe against heap 32*6705Smckusick * being allocated. 33*6705Smckusick */ 34*6705Smckusick #define usestak() {locstak();} 35*6705Smckusick 36*6705Smckusick /* for local use only since it hands 37*6705Smckusick * out a real address for the stack top 38*6705Smckusick */ 39*6705Smckusick STKPTR locstak(); 40*6705Smckusick 41*6705Smckusick /* Will allocate the item being used and return its 42*6705Smckusick * address (safe now). 43*6705Smckusick */ 44*6705Smckusick #define fixstak() endstak(staktop) 45*6705Smckusick 46*6705Smckusick /* For use after `locstak' to hand back 47*6705Smckusick * new stack top and then allocate item 48*6705Smckusick */ 49*6705Smckusick STKPTR endstak(); 50*6705Smckusick 51*6705Smckusick /* Copy a string onto the stack and 52*6705Smckusick * allocate the space. 53*6705Smckusick */ 54*6705Smckusick STKPTR cpystak(); 55*6705Smckusick 56*6705Smckusick /* Allocate given ammount of stack space */ 57*6705Smckusick STKPTR getstak(); 58*6705Smckusick 59*6705Smckusick /* A chain of ptrs of stack blocks that 60*6705Smckusick * have become covered by heap allocation. 61*6705Smckusick * `tdystak' will return them to the heap. 62*6705Smckusick */ 63*6705Smckusick BLKPTR stakbsy; 64*6705Smckusick 65*6705Smckusick /* Base of the entire stack */ 66*6705Smckusick STKPTR stakbas; 67*6705Smckusick 68*6705Smckusick /* Top of entire stack */ 69*6705Smckusick STKPTR brkend; 70*6705Smckusick 71*6705Smckusick /* Base of current item */ 72*6705Smckusick STKPTR stakbot; 73*6705Smckusick 74*6705Smckusick /* Top of current item */ 75*6705Smckusick STKPTR staktop; 76*6705Smckusick 77*6705Smckusick /* Used with tdystak */ 78*6705Smckusick STKPTR savstak(); 79