memalloc.h revision 64702
11556Srgrimes/*-
21556Srgrimes * Copyright (c) 1991, 1993
31556Srgrimes *	The Regents of the University of California.  All rights reserved.
41556Srgrimes *
51556Srgrimes * This code is derived from software contributed to Berkeley by
61556Srgrimes * Kenneth Almquist.
71556Srgrimes *
81556Srgrimes * Redistribution and use in source and binary forms, with or without
91556Srgrimes * modification, are permitted provided that the following conditions
101556Srgrimes * are met:
111556Srgrimes * 1. Redistributions of source code must retain the above copyright
121556Srgrimes *    notice, this list of conditions and the following disclaimer.
131556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141556Srgrimes *    notice, this list of conditions and the following disclaimer in the
151556Srgrimes *    documentation and/or other materials provided with the distribution.
161556Srgrimes * 3. All advertising materials mentioning features or use of this software
171556Srgrimes *    must display the following acknowledgement:
181556Srgrimes *	This product includes software developed by the University of
191556Srgrimes *	California, Berkeley and its contributors.
201556Srgrimes * 4. Neither the name of the University nor the names of its contributors
211556Srgrimes *    may be used to endorse or promote products derived from this software
221556Srgrimes *    without specific prior written permission.
231556Srgrimes *
241556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271556Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341556Srgrimes * SUCH DAMAGE.
351556Srgrimes *
3617987Speter *	@(#)memalloc.h	8.2 (Berkeley) 5/4/95
3750471Speter * $FreeBSD: head/bin/sh/memalloc.h 64702 2000-08-16 10:39:43Z cracauer $
381556Srgrimes */
391556Srgrimes
401556Srgrimesstruct stackmark {
411556Srgrimes	struct stack_block *stackp;
421556Srgrimes	char *stacknxt;
431556Srgrimes	int stacknleft;
4464702Scracauer        struct stackmark *marknext;
451556Srgrimes};
461556Srgrimes
471556Srgrimes
481556Srgrimesextern char *stacknxt;
491556Srgrimesextern int stacknleft;
501556Srgrimesextern int sstrnleft;
511556Srgrimesextern int herefd;
521556Srgrimes
5317987Speterpointer ckmalloc __P((int));
5417987Speterpointer ckrealloc __P((pointer, int));
5517987Speterchar *savestr __P((char *));
5617987Speterpointer stalloc __P((int));
5717987Spetervoid stunalloc __P((pointer));
5817987Spetervoid setstackmark __P((struct stackmark *));
5917987Spetervoid popstackmark __P((struct stackmark *));
6017987Spetervoid growstackblock __P((void));
6117987Spetervoid grabstackblock __P((int));
6217987Speterchar *growstackstr __P((void));
6317987Speterchar *makestrspace __P((void));
6417987Spetervoid ungrabstackstr __P((char *, char *));
651556Srgrimes
661556Srgrimes
671556Srgrimes
681556Srgrimes#define stackblock() stacknxt
691556Srgrimes#define stackblocksize() stacknleft
701556Srgrimes#define STARTSTACKSTR(p)	p = stackblock(), sstrnleft = stackblocksize()
711556Srgrimes#define STPUTC(c, p)	(--sstrnleft >= 0? (*p++ = (c)) : (p = growstackstr(), *p++ = (c)))
7217987Speter#define CHECKSTRSPACE(n, p)	{ if (sstrnleft < n) p = makestrspace(); }
731556Srgrimes#define USTPUTC(c, p)	(--sstrnleft, *p++ = (c))
741556Srgrimes#define STACKSTRNUL(p)	(sstrnleft == 0? (p = growstackstr(), *p = '\0') : (*p = '\0'))
751556Srgrimes#define STUNPUTC(p)	(++sstrnleft, --p)
761556Srgrimes#define STTOPC(p)	p[-1]
771556Srgrimes#define STADJUST(amount, p)	(p += (amount), sstrnleft -= (amount))
781556Srgrimes#define grabstackstr(p)	stalloc(stackblocksize() - sstrnleft)
791556Srgrimes
801556Srgrimes#define ckfree(p)	free((pointer)(p))
81