/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 2003-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Phong Vo <[email protected]> *17* *18***********************************************************************/19#include "vchdr.h"2021/* If a method carries states across vcapply() calls, it needs to22** provide a way so that the invoker can set multiple contexts for23** transforming data. The below functions create/delete context.24**25** Written by Kiem-Phong Vo ([email protected])26*/2728#if __STD_C29Vccontext_t* vcinitcontext(Vcodex_t* vc, Vccontext_t* ctxt)30#else31Vccontext_t* vcinitcontext(vc, ctxt)32Vcodex_t* vc;33Vccontext_t* ctxt; /* if NULL, make a new one */34#endif35{36Vccontext_t *c, *p;3738if(ctxt)39{ for(p = NIL(Vccontext_t*), c = vc->ctxt; c; p = c, c = c->next)40if(c == ctxt)41break;42if(!c) /* non-existing context */43return NIL(Vccontext_t*);44if(!p) /* already at head of list */45return ctxt;46else p->next = ctxt->next;47}48else49{ if(!vc->meth->eventf ||50(*vc->meth->eventf)(vc, VC_INITCONTEXT, (Void_t*)(&ctxt)) < 0 || !ctxt)51return NIL(Vccontext_t*);52}5354ctxt->next = vc->ctxt;55vc->ctxt = ctxt;56return ctxt;57}5859#if __STD_C60int vcfreecontext(Vcodex_t* vc, Vccontext_t* ctxt)61#else62int vcfreecontext(vc, ctxt)63Vcodex_t* vc;64Vccontext_t* ctxt; /* if NULL, free all */65#endif66{67Vccontext_t *next;6869if(ctxt)70{ if(vcinitcontext(vc, ctxt) != ctxt)71return -1;72vc->ctxt = ctxt->next;73ctxt->next = NIL(Vccontext_t*);74}75else76{ ctxt = vc->ctxt;77vc->ctxt = NIL(Vccontext_t*);78}7980for(; ctxt; ctxt = next)81{ next = ctxt->next;82if(vc->meth->eventf &&83(*vc->meth->eventf)(vc, VC_FREECONTEXT, (Void_t*)ctxt) < 0)84return -1;85}8687return 0;88}899091