1N/A/*********************************************************************** 1N/A* This software is part of the ast package * 1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property * 1N/A* and is licensed under the * 1N/A* Common Public License, Version 1.0 * 1N/A* by AT&T Intellectual Property * 1N/A* A copy of the License is available at * 1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 1N/A* Information and Software Systems Research * 1N/A* Glenn Fowler <gsf@research.att.com> * 1N/A* David Korn <dgk@research.att.com> * 1N/A* Phong Vo <kpv@research.att.com> * 1N/A***********************************************************************/ 1N/A * Routines to implement a stack-like storage library 1N/A * A stack consists of a link list of variable size frames 1N/A * The beginning of each frame is initialized with a frame structure 1N/A * that contains a pointer to the previous frame and a pointer to the 1N/A * end of the current frame. 1N/A * This is a rewrite of the stk library that uses sfio 1N/A * dgk@research.att.com 1N/A * A stack is a header and a linked list of frames 1N/A * The first frame has structure 1N/A * Frames have structure 1N/A char *
prev;
/* address of previous frame */ 1N/A char *
end;
/* address of end this frame */ 1N/A char *
stkbase;
/* beginning of current stack frame */ 1N/A char *
stkend;
/* end of current stack frame */ 1N/Astatic int init;
/* 1 when initialized */ 1N/A#
endif /* STKSTATS */ 1N/Astatic const char Omsg[] =
"malloc failed while growing stack\n";
1N/A * default overflow exception 1N/A * initialize stkstd, sfio operations may have already occcured 1N/A#
endif /* USE_REALLOC */ 1N/A * return a pointer to the current stack 1N/A * if <stream> is not null, it becomes the new current stack 1N/A * <oflow> becomes the new overflow function 1N/A#
endif /* USE_REALLOC */ 1N/A * increase the reference count on the given <stack> 1N/A * terminate a stack and free up the space 1N/A * >0 returned if reference decremented but still > 0 1N/A * 0 returned on last close 1N/A * <0 returned on error 1N/A * returns 1 if <loc> is on this stack 1N/A * reset the bottom of the current stack back to <loc> 1N/A * if <loc> is not in this stack, then the stack is reset to the beginning 1N/A * otherwise, the top of the stack is set to stkbot+<offset> 1N/A /* see whether <loc> is in current stack frame */ 1N/A /* set stack back to the beginning */ 1N/A * allocate <n> bytes on the current stack 1N/A * begin a new stack word of at least <n> bytes 1N/A * advance the stack to the current top 1N/A * if extra is non-zero, first add a extra bytes and zero the first 1N/A * copy string <str> onto the stack as a new stack word 1N/A register unsigned char *
cp = (
unsigned char*)
str;
1N/A * add a new stack frame of size >= <n> to the current stack. 1N/A * if <n> > 0, copy the bytes from stkbot to stktop to the new stack 1N/A * if <n> is zero, then copy the remainder of the stack frame from stkbot 1N/A * to the end is copied into the new stack frame 1N/A#
endif /* !USE_REALLOC */ 1N/A /* see whether current frame can be extended */