1*4887Schin /***********************************************************************
2*4887Schin *                                                                      *
3*4887Schin *               This software is part of the ast package               *
4*4887Schin *           Copyright (c) 1986-2007 AT&T Knowledge Ventures            *
5*4887Schin *                      and is licensed under the                       *
6*4887Schin *                  Common Public License, Version 1.0                  *
7*4887Schin *                      by AT&T Knowledge Ventures                      *
8*4887Schin *                                                                      *
9*4887Schin *                A copy of the License is available at                 *
10*4887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
11*4887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12*4887Schin *                                                                      *
13*4887Schin *              Information and Software Systems Research               *
14*4887Schin *                            AT&T Research                             *
15*4887Schin *                           Florham Park NJ                            *
16*4887Schin *                                                                      *
17*4887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
18*4887Schin *                                                                      *
19*4887Schin ***********************************************************************/
20*4887Schin #pragma prototyped
21*4887Schin /*
22*4887Schin  * Glenn Fowler
23*4887Schin  * AT&T Research
24*4887Schin  *
25*4887Schin  * preprocessor context switch
26*4887Schin  *
27*4887Schin  *	args		op				return
28*4887Schin  *	(0,0)		free current context		0
29*4887Schin  *	(0,1)		save current context		current
30*4887Schin  *	(p,0)		free context p			0
31*4887Schin  *	(p,1)		make p current context		previous
32*4887Schin  */
33*4887Schin 
34*4887Schin #include "pplib.h"
35*4887Schin 
36*4887Schin void*
37*4887Schin ppcontext(void* context, int flags)
38*4887Schin {
39*4887Schin 	struct ppcontext*	np = (struct ppcontext*)context;
40*4887Schin 	struct ppcontext*	op;
41*4887Schin 
42*4887Schin 	if (flags & 01)
43*4887Schin 	{
44*4887Schin 		if (!(op = pp.context)) op = pp.context = newof(0, struct ppcontext, 1, 0);
45*4887Schin 		memcpy(op, _PP_CONTEXT_BASE_, sizeof(struct ppcontext));
46*4887Schin 	}
47*4887Schin 	else
48*4887Schin 	{
49*4887Schin 		if (!(op = np)) op = (struct ppcontext*)_PP_CONTEXT_BASE_;
50*4887Schin 		if (op->filtab) hashfree(op->filtab);
51*4887Schin 		if (op->prdtab) hashfree(op->prdtab);
52*4887Schin 		if (op->symtab) hashfree(op->symtab);
53*4887Schin 		if (op->date) free(op->date);
54*4887Schin 		if (op->time) free(op->time);
55*4887Schin 		if (np)
56*4887Schin 		{
57*4887Schin 			free(np);
58*4887Schin 			np = 0;
59*4887Schin 		}
60*4887Schin 		memzero(op, sizeof(struct ppcontext));
61*4887Schin 		op = 0;
62*4887Schin 	}
63*4887Schin 	if (np) memcpy(_PP_CONTEXT_BASE_, np, sizeof(struct ppcontext));
64*4887Schin 	return((void*)op);
65*4887Schin }
66