14887Schin /*********************************************************************** 24887Schin * * 34887Schin * This software is part of the ast package * 4*8462SApril.Chin@Sun.COM * Copyright (c) 1986-2008 AT&T Intellectual Property * 54887Schin * and is licensed under the * 64887Schin * Common Public License, Version 1.0 * 7*8462SApril.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 * * 194887Schin ***********************************************************************/ 204887Schin #pragma prototyped 214887Schin /* 224887Schin * Glenn Fowler 234887Schin * AT&T Research 244887Schin * 254887Schin * preprocessor context switch 264887Schin * 274887Schin * args op return 284887Schin * (0,0) free current context 0 294887Schin * (0,1) save current context current 304887Schin * (p,0) free context p 0 314887Schin * (p,1) make p current context previous 324887Schin */ 334887Schin 344887Schin #include "pplib.h" 354887Schin 364887Schin void* 374887Schin ppcontext(void* context, int flags) 384887Schin { 394887Schin struct ppcontext* np = (struct ppcontext*)context; 404887Schin struct ppcontext* op; 414887Schin 424887Schin if (flags & 01) 434887Schin { 444887Schin if (!(op = pp.context)) op = pp.context = newof(0, struct ppcontext, 1, 0); 454887Schin memcpy(op, _PP_CONTEXT_BASE_, sizeof(struct ppcontext)); 464887Schin } 474887Schin else 484887Schin { 494887Schin if (!(op = np)) op = (struct ppcontext*)_PP_CONTEXT_BASE_; 504887Schin if (op->filtab) hashfree(op->filtab); 514887Schin if (op->prdtab) hashfree(op->prdtab); 524887Schin if (op->symtab) hashfree(op->symtab); 534887Schin if (op->date) free(op->date); 544887Schin if (op->time) free(op->time); 554887Schin if (np) 564887Schin { 574887Schin free(np); 584887Schin np = 0; 594887Schin } 604887Schin memzero(op, sizeof(struct ppcontext)); 614887Schin op = 0; 624887Schin } 634887Schin if (np) memcpy(_PP_CONTEXT_BASE_, np, sizeof(struct ppcontext)); 644887Schin return((void*)op); 654887Schin } 66