Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libvcodex/vccontext.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2003-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Phong Vo <[email protected]> *
18
* *
19
***********************************************************************/
20
#include "vchdr.h"
21
22
/* If a method carries states across vcapply() calls, it needs to
23
** provide a way so that the invoker can set multiple contexts for
24
** transforming data. The below functions create/delete context.
25
**
26
** Written by Kiem-Phong Vo ([email protected])
27
*/
28
29
#if __STD_C
30
Vccontext_t* vcinitcontext(Vcodex_t* vc, Vccontext_t* ctxt)
31
#else
32
Vccontext_t* vcinitcontext(vc, ctxt)
33
Vcodex_t* vc;
34
Vccontext_t* ctxt; /* if NULL, make a new one */
35
#endif
36
{
37
Vccontext_t *c, *p;
38
39
if(ctxt)
40
{ for(p = NIL(Vccontext_t*), c = vc->ctxt; c; p = c, c = c->next)
41
if(c == ctxt)
42
break;
43
if(!c) /* non-existing context */
44
return NIL(Vccontext_t*);
45
if(!p) /* already at head of list */
46
return ctxt;
47
else p->next = ctxt->next;
48
}
49
else
50
{ if(!vc->meth->eventf ||
51
(*vc->meth->eventf)(vc, VC_INITCONTEXT, (Void_t*)(&ctxt)) < 0 || !ctxt)
52
return NIL(Vccontext_t*);
53
}
54
55
ctxt->next = vc->ctxt;
56
vc->ctxt = ctxt;
57
return ctxt;
58
}
59
60
#if __STD_C
61
int vcfreecontext(Vcodex_t* vc, Vccontext_t* ctxt)
62
#else
63
int vcfreecontext(vc, ctxt)
64
Vcodex_t* vc;
65
Vccontext_t* ctxt; /* if NULL, free all */
66
#endif
67
{
68
Vccontext_t *next;
69
70
if(ctxt)
71
{ if(vcinitcontext(vc, ctxt) != ctxt)
72
return -1;
73
vc->ctxt = ctxt->next;
74
ctxt->next = NIL(Vccontext_t*);
75
}
76
else
77
{ ctxt = vc->ctxt;
78
vc->ctxt = NIL(Vccontext_t*);
79
}
80
81
for(; ctxt; ctxt = next)
82
{ next = ctxt->next;
83
if(vc->meth->eventf &&
84
(*vc->meth->eventf)(vc, VC_FREECONTEXT, (Void_t*)ctxt) < 0)
85
return -1;
86
}
87
88
return 0;
89
}
90
91