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