2
This software and ancillary information (herein called "SOFTWARE")
3
called Supermon is made available under the terms described
4
here. The SOFTWARE has been approved for release with associated
5
LA-CC Number LA-CC 99-51.
7
Unless otherwise indicated, this SOFTWARE has been authored by an
8
employee or employees of the University of California, operator of the
9
Los Alamos National Laboratory under Contract No. W-7405-ENG-36 with
10
the U.S. Department of Energy. The U.S. Government has rights to use,
11
reproduce, and distribute this SOFTWARE, and to allow others to do so.
12
The public may copy, distribute, prepare derivative works and publicly
13
display this SOFTWARE without charge, provided that this Notice and
14
any statement of authorship are reproduced on all copies. Neither the
15
Government nor the University makes any warranty, express or implied,
16
or assumes any liability or responsibility for the use of this
19
If SOFTWARE is modified to produce derivative works, such modified
20
SOFTWARE should be clearly marked, so as not to confuse it with the
21
version available from LANL.
23
/** NOTICE: This software is licensed under the GNU Public License, which
24
is included as LICENSE_GPL in this source distribution. **/
26
/** NOTE: This library is part of the supermon project, hence the name
35
* Given an s-expression, find the atom inside of it with the
36
* value matchine name, and return a reference to it. If the atom
37
* doesn't occur inside start, return NULL.
40
find_sexp (char *name, sexp_t * start)
47
if (start->ty == SEXP_LIST)
49
temp = find_sexp (name, start->list);
51
return find_sexp (name, start->next);
57
assert(start->val != NULL);
58
if (strcmp (start->val, name) == 0)
61
return find_sexp (name, start->next);
64
return NULL; /* shouldn't get here */
68
* Breadth first search - look at ->next before ->list when seeing list
69
* elements of an expression.
71
sexp_t *bfs_find_sexp(char *str, sexp_t *sx) {
75
if (sx == NULL) return NULL;
78
if (t->ty == SEXP_VALUE) {
79
assert(t->val != NULL);
80
if (strcmp(t->val,str) == 0) {
90
if (t->ty == SEXP_LIST) {
91
rt = bfs_find_sexp(str,t->list);
92
if (rt != NULL) return rt;
102
* Copy an s-expression.
104
sexp_t *copy_sexp(sexp_t *s) {
107
if (s == NULL) return NULL;
109
/* snew = (sexp_t *)malloc(sizeof(sexp_t)); */
110
snew = sexp_t_allocate();
111
assert(snew != NULL);
114
if (snew->ty == SEXP_VALUE) {
116
assert(s->val != NULL);
117
strcpy(snew->val,s->val);
120
snew->list = copy_sexp(s->list);
123
snew->next = copy_sexp(s->next);
129
* Cons: Concatenate two s-expressions together, without references to the
132
sexp_t *cons_sexp(sexp_t *r, sexp_t *l) {
136
if (cr->ty == SEXP_VALUE) {
137
fprintf(stderr,"Cannot cons non-lists.\n");
142
while (t != NULL && t->next != NULL) t = t->next;
147
if (cl->ty == SEXP_LIST) {
148
if (t != NULL && cl != NULL) {
150
/* free(cl); */ /* memory leak fix: SMJ, 4/24/2002 */
151
sexp_t_deallocate(cl);
154
fprintf(stderr,"Cannot cons non-lists.\n");
164
* car: similar to head, except this is a copy and not just a reference.
166
sexp_t *car_sexp(sexp_t *s) {
169
/* really dumb - calling on null */
171
fprintf(stderr,"car called on null sexpr.\n");
175
/* less dumb - calling on an atom */
176
if (s->ty == SEXP_VALUE) {
177
fprintf(stderr,"car called on an atom.\n");
181
/* ocr = (sexp_t *)malloc(sizeof(sexp_t));*/
182
ocr = sexp_t_allocate();
187
/* allocate the new sexp_t */
188
/* cr = (sexp_t *)malloc(sizeof(sexp_t)); */
189
cr = sexp_t_allocate();
193
/* copy the head of the sexpr */
194
if (s->list->ty == SEXP_VALUE) {
196
assert(s->list->val != NULL);
197
strcpy(cr->val,s->list->val);
198
cr->next = cr->list = NULL;
202
cr->list = copy_sexp(s->list->list);
209
* cdr: similar to tail, except this is a copy and not just a reference.
211
sexp_t *cdr_sexp(sexp_t *s) {
216
fprintf(stderr,"cdr called on null.\n");
221
if (s->ty != SEXP_LIST) {
222
fprintf(stderr,"cdr called on atom.\n");
226
/* cd = (sexp_t *)malloc(sizeof(sexp_t)); */
227
cd = sexp_t_allocate();
232
cd->list = copy_sexp(s->list->next);