| 1 | /*- |
| 2 | * Copyright (c) 1991 The Regents of the University of California. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This code is derived from software contributed to Berkeley by |
| 6 | * Kenneth Almquist. |
| 7 | * |
| 8 | * %sccs.include.redist.c% |
| 9 | * |
| 10 | * @(#)memalloc.h 5.1 (Berkeley) %G% |
| 11 | */ |
| 12 | |
| 13 | struct stackmark { |
| 14 | struct stack_block *stackp; |
| 15 | char *stacknxt; |
| 16 | int stacknleft; |
| 17 | }; |
| 18 | |
| 19 | |
| 20 | extern char *stacknxt; |
| 21 | extern int stacknleft; |
| 22 | extern int sstrnleft; |
| 23 | extern int herefd; |
| 24 | |
| 25 | #ifdef __STDC__ |
| 26 | pointer ckmalloc(int); |
| 27 | pointer ckrealloc(pointer, int); |
| 28 | void free(pointer); /* defined in C library */ |
| 29 | char *savestr(char *); |
| 30 | pointer stalloc(int); |
| 31 | void stunalloc(pointer); |
| 32 | void setstackmark(struct stackmark *); |
| 33 | void popstackmark(struct stackmark *); |
| 34 | void growstackblock(void); |
| 35 | void grabstackblock(int); |
| 36 | char *growstackstr(void); |
| 37 | char *makestrspace(void); |
| 38 | void ungrabstackstr(char *, char *); |
| 39 | #else |
| 40 | pointer ckmalloc(); |
| 41 | pointer ckrealloc(); |
| 42 | void free(); /* defined in C library */ |
| 43 | char *savestr(); |
| 44 | pointer stalloc(); |
| 45 | void stunalloc(); |
| 46 | void setstackmark(); |
| 47 | void popstackmark(); |
| 48 | void growstackblock(); |
| 49 | void grabstackblock(); |
| 50 | char *growstackstr(); |
| 51 | char *makestrspace(); |
| 52 | void ungrabstackstr(); |
| 53 | #endif |
| 54 | |
| 55 | |
| 56 | |
| 57 | #define stackblock() stacknxt |
| 58 | #define stackblocksize() stacknleft |
| 59 | #define STARTSTACKSTR(p) p = stackblock(), sstrnleft = stackblocksize() |
| 60 | #define STPUTC(c, p) (--sstrnleft >= 0? (*p++ = (c)) : (p = growstackstr(), *p++ = (c))) |
| 61 | #define CHECKSTRSPACE(n, p) if (sstrnleft < n) p = makestrspace(); else |
| 62 | #define USTPUTC(c, p) (--sstrnleft, *p++ = (c)) |
| 63 | #define STACKSTRNUL(p) (sstrnleft == 0? (p = growstackstr(), *p = '\0') : (*p = '\0')) |
| 64 | #define STUNPUTC(p) (++sstrnleft, --p) |
| 65 | #define STTOPC(p) p[-1] |
| 66 | #define STADJUST(amount, p) (p += (amount), sstrnleft -= (amount)) |
| 67 | #define grabstackstr(p) stalloc(stackblocksize() - sstrnleft) |
| 68 | |
| 69 | #define ckfree(p) free((pointer)(p)) |