Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libast/misc/optctx.c
1810 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1985-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
* Glenn Fowler <[email protected]> *
18
* David Korn <[email protected]> *
19
* Phong Vo <[email protected]> *
20
* *
21
***********************************************************************/
22
#pragma prototyped
23
/*
24
* Glenn Fowler
25
* AT&T Research
26
*
27
* _opt_infop_ context control
28
*
29
* allocate new context:
30
* new_context = optctx(0, 0);
31
* free new context:
32
* optctx(0, new_context);
33
* switch to new_context:
34
* old_context = optctx(new_context, 0);
35
* switch to old_context and free new_context:
36
* optctx(old_context, new_context);
37
*/
38
39
#include <optlib.h>
40
41
static Opt_t* freecontext;
42
43
Opt_t*
44
optctx(Opt_t* p, Opt_t* o)
45
{
46
if (o)
47
{
48
if (freecontext)
49
free(o);
50
else
51
freecontext = o;
52
if (!p)
53
return 0;
54
}
55
if (p)
56
{
57
o = _opt_infop_;
58
_opt_infop_ = p;
59
}
60
else
61
{
62
if (o = freecontext)
63
freecontext = 0;
64
else if (!(o = newof(0, Opt_t, 1, 0)))
65
return 0;
66
memset(o, 0, sizeof(Opt_t));
67
o->state = _opt_infop_->state;
68
}
69
return o;
70
}
71
72