Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libcoshell/coexport.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1990-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
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* Glenn Fowler
23
* at&t Research
24
*
25
* coshell export var set/unset
26
*/
27
28
#include "colib.h"
29
30
/*
31
* set or unset coshell export variable
32
*/
33
34
int
35
coexport(Coshell_t* co, const char* name, const char* value)
36
{
37
Coexport_t* ex;
38
char* v;
39
40
if (!co->export)
41
{
42
if (!(co->exdisc = vmnewof(co->vm, 0, Dtdisc_t, 1, 0)))
43
return -1;
44
co->exdisc->link = offsetof(Coexport_t, link);
45
co->exdisc->key = offsetof(Coexport_t, name);
46
co->exdisc->size = 0;
47
if (!(co->export = dtnew(co->vm, co->exdisc, Dtset)))
48
{
49
vmfree(co->vm, co->exdisc);
50
return -1;
51
}
52
}
53
if (!(ex = (Coexport_t*)dtmatch(co->export, name)))
54
{
55
if (!value)
56
return 0;
57
if (!(ex = vmnewof(co->vm, 0, Coexport_t, 1, strlen(name))))
58
return -1;
59
strcpy(ex->name, name);
60
dtinsert(co->export, ex);
61
}
62
if (ex->value)
63
{
64
vmfree(co->vm, ex->value);
65
ex->value = 0;
66
}
67
if (value)
68
{
69
if (!(v = vmstrdup(co->vm, value)))
70
return -1;
71
ex->value = v;
72
}
73
else
74
{
75
dtdelete(co->export, ex);
76
vmfree(co->vm, ex);
77
}
78
co->init.sync = 1;
79
return 0;
80
}
81
82