xref: /onnv-gate/usr/src/lib/libast/common/include/stack.h (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
184887Schin *                  David Korn <dgk@research.att.com>                   *
194887Schin *                   Phong Vo <kpv@research.att.com>                    *
204887Schin *                                                                      *
214887Schin ***********************************************************************/
224887Schin #pragma prototyped
234887Schin /*
244887Schin  * Glenn Fowler
254887Schin  * AT&T Research
264887Schin  *
274887Schin  * homogenous stack routine definitions
284887Schin  */
294887Schin 
304887Schin #ifndef _STACK_H
314887Schin #define _STACK_H
324887Schin 
334887Schin typedef struct stacktable* STACK;	/* stack pointer		*/
344887Schin typedef struct stackposition STACKPOS;	/* stack position		*/
354887Schin 
364887Schin struct stackblock			/* stack block cell		*/
374887Schin {
384887Schin 	void**		  stack;	/* actual stack			*/
394887Schin 	struct stackblock* prev;	/* previous block in list	*/
404887Schin 	struct stackblock* next;	/* next block in list		*/
414887Schin };
424887Schin 
434887Schin struct stackposition			/* stack position		*/
444887Schin {
454887Schin 	struct stackblock* block;	/* current block pointer	*/
464887Schin 	int		index;		/* index within current block	*/
474887Schin };
484887Schin 
494887Schin struct stacktable			/* stack information		*/
504887Schin {
514887Schin 	struct stackblock* blocks;	/* stack table blocks		*/
524887Schin 	void*		error;		/* error return value		*/
534887Schin 	int		size;		/* size of each block		*/
544887Schin 	STACKPOS	position;	/* current stack position	*/
554887Schin };
564887Schin 
574887Schin /*
584887Schin  * map old names to new
594887Schin  */
604887Schin 
614887Schin #define mkstack		stackalloc
624887Schin #define rmstack		stackfree
634887Schin #define clrstack	stackclear
644887Schin #define getstack	stackget
654887Schin #define pushstack	stackpush
664887Schin #define popstack	stackpop
674887Schin #define posstack	stacktell
684887Schin 
694887Schin #if _BLD_ast && defined(__EXPORT__)
704887Schin #define extern		__EXPORT__
714887Schin #endif
724887Schin 
734887Schin extern STACK		stackalloc(int, void*);
744887Schin extern void		stackfree(STACK);
754887Schin extern void		stackclear(STACK);
764887Schin extern void*		stackget(STACK);
774887Schin extern int		stackpush(STACK, void*);
784887Schin extern int		stackpop(STACK);
794887Schin extern void		stacktell(STACK, int, STACKPOS*);
804887Schin 
814887Schin #undef	extern
824887Schin 
834887Schin #endif
84