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