Debian Codegraph @

src/sexpr/sexp_ops.c

raw symbols SCIP
1 /**
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.
6
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
17 SOFTWARE.
18
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.
22 **/
23 /** NOTICE: This software is licensed under the GNU Public License, which
24 is included as LICENSE_GPL in this source distribution. **/
25
26 /** NOTE: This library is part of the supermon project, hence the name
27 supermon above. **/
28 #include <assert.h>
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include "sexp_ops.h"cxx . . $ `<file>/src/sexpr/sexp_ops.h`/
33
34 /**
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.
38 */
39 sexp_tcxx . . $ sexp_t# *
40 find_sexpcxx . . $ find_sexp(5cc8a5fd4a29c275). (char *name, sexp_tcxx . . $ sexp_t# * start)
41 {
42 sexp_tcxx . . $ sexp_t# *temp;
43
44 if (start == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
45 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
46
47 if (start->tycxx . . $ elt#ty. == SEXP_LISTcxx . . $ SEXP_LIST.)
48 {
49 temp = find_sexpcxx . . $ find_sexp(5cc8a5fd4a29c275). (name, start->listcxx . . $ elt#list.);
50 if (temp == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
51 return find_sexpcxx . . $ find_sexp(5cc8a5fd4a29c275). (name, start->nextcxx . . $ elt#next.);
52 else
53 return temp;
54 }
55 else
56 {
57 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(start->val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
58 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88). (start->valcxx . . $ elt#val., name) == 0)
59 return start;
60 else
61 return find_sexpcxx . . $ find_sexp(5cc8a5fd4a29c275). (name, start->nextcxx . . $ elt#next.);
62 }
63
64 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; /* shouldn't get here */
65 }
66
67 /**
68 * Breadth first search - look at ->next before ->list when seeing list
69 * elements of an expression.
70 */
71 sexp_tcxx . . $ sexp_t# *bfs_find_sexpcxx . . $ bfs_find_sexp(5cc8a5fd4a29c275).(char *str, sexp_tcxx . . $ sexp_t# *sx) {
72 sexp_tcxx . . $ sexp_t# *t = sx;
73 sexp_tcxx . . $ sexp_t# *rt;
74
75 if (sx == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
76
77 while (t != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
78 if (t->tycxx . . $ elt#ty. == SEXP_VALUEcxx . . $ SEXP_VALUE.) {
79 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(t->val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
80 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(t->valcxx . . $ elt#val.,str) == 0) {
81 return t;
82 }
83 }
84
85 t = t->nextcxx . . $ elt#next.;
86 }
87
88 t = sx;
89 while (t != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
90 if (t->tycxx . . $ elt#ty. == SEXP_LISTcxx . . $ SEXP_LIST.) {
91 rt = bfs_find_sexpcxx . . $ bfs_find_sexp(5cc8a5fd4a29c275).(str,t->listcxx . . $ elt#list.);
92 if (rt != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) return rt;
93 }
94
95 t = t->nextcxx . . $ elt#next.;
96 }
97
98 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
99 }
100
101 /**
102 * Copy an s-expression.
103 */
104 sexp_tcxx . . $ sexp_t# *copy_sexpcxx . . $ copy_sexp(3cbd8718f67a36ca).(sexp_tcxx . . $ sexp_t# *s) {
105 sexp_tcxx . . $ sexp_t# *snew;
106
107 if (s == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
108
109 /* snew = (sexp_t *)malloc(sizeof(sexp_t)); */
110 snew = sexp_t_allocatecxx . . $ sexp_t_allocate(99317b48064593fe).();
111 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(snew != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
112
113 snew->tycxx . . $ elt#ty. = s->tycxx . . $ elt#ty.;
114 if (snew->tycxx . . $ elt#ty. == SEXP_VALUEcxx . . $ SEXP_VALUE.) {
115 snew->atycxx . . $ elt#aty. = s->atycxx . . $ elt#aty.;
116 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(s->val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
117 strcpycxx . . $ strcpy(b7b3a83273496486).(snew->valcxx . . $ elt#val.,s->valcxx . . $ elt#val.);
118 snew->listcxx . . $ elt#list. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
119 } else {
120 snew->listcxx . . $ elt#list. = copy_sexpcxx . . $ copy_sexp(3cbd8718f67a36ca).(s->listcxx . . $ elt#list.);
121 }
122
123 snew->nextcxx . . $ elt#next. = copy_sexpcxx . . $ copy_sexp(3cbd8718f67a36ca).(s->nextcxx . . $ elt#next.);
124
125 return snew;
126 }
127
128 /**
129 * Cons: Concatenate two s-expressions together, without references to the
130 * originals.
131 */
132 sexp_tcxx . . $ sexp_t# *cons_sexpcxx . . $ cons_sexp(ed01d4d1c8370fc0).(sexp_tcxx . . $ sexp_t# *r, sexp_tcxx . . $ sexp_t# *l) {
133 sexp_tcxx . . $ sexp_t# *cr, *cl, *t;
134
135 cr = copy_sexpcxx . . $ copy_sexp(3cbd8718f67a36ca).(r);
136 if (cr->tycxx . . $ elt#ty. == SEXP_VALUEcxx . . $ SEXP_VALUE.) {
137 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Cannot cons non-lists.\n");
138 destroy_sexpcxx . . $ destroy_sexp(7420e001cc8f68ca).(cr);
139 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
140 } else {
141 t = cr->listcxx . . $ elt#list.;
142 while (t != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && t->nextcxx . . $ elt#next. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) t = t->nextcxx . . $ elt#next.;
143 }
144
145 cl = copy_sexpcxx . . $ copy_sexp(3cbd8718f67a36ca).(l);
146
147 if (cl->tycxx . . $ elt#ty. == SEXP_LISTcxx . . $ SEXP_LIST.) {
148 if (t != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && cl != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
149 t->nextcxx . . $ elt#next. = cl->listcxx . . $ elt#list.;
150 /* free(cl); */ /* memory leak fix: SMJ, 4/24/2002 */
151 sexp_t_deallocatecxx . . $ sexp_t_deallocate(7420e001cc8f68ca).(cl);
152 }
153 } else {
154 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Cannot cons non-lists.\n");
155 destroy_sexpcxx . . $ destroy_sexp(7420e001cc8f68ca).(cr);
156 destroy_sexpcxx . . $ destroy_sexp(7420e001cc8f68ca).(cl);
157 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
158 }
159
160 return cr;
161 }
162
163 /**
164 * car: similar to head, except this is a copy and not just a reference.
165 */
166 sexp_tcxx . . $ sexp_t# *car_sexpcxx . . $ car_sexp(3cbd8718f67a36ca).(sexp_tcxx . . $ sexp_t# *s) {
167 sexp_tcxx . . $ sexp_t# *cr, *ocr;
168
169 /* really dumb - calling on null */
170 if (s == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
171 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"car called on null sexpr.\n");
172 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
173 }
174
175 /* less dumb - calling on an atom */
176 if (s->tycxx . . $ elt#ty. == SEXP_VALUEcxx . . $ SEXP_VALUE.) {
177 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"car called on an atom.\n");
178 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
179 }
180
181 /* ocr = (sexp_t *)malloc(sizeof(sexp_t));*/
182 ocr = sexp_t_allocatecxx . . $ sexp_t_allocate(99317b48064593fe).();
183 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(ocr != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
184 ocr->tycxx . . $ elt#ty. = SEXP_LISTcxx . . $ SEXP_LIST.;
185 ocr->nextcxx . . $ elt#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
186
187 /* allocate the new sexp_t */
188 /* cr = (sexp_t *)malloc(sizeof(sexp_t)); */
189 cr = sexp_t_allocatecxx . . $ sexp_t_allocate(99317b48064593fe).();
190 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(cr != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
191 ocr->listcxx . . $ elt#list. = cr;
192
193 /* copy the head of the sexpr */
194 if (s->listcxx . . $ elt#list.->tycxx . . $ elt#ty. == SEXP_VALUEcxx . . $ SEXP_VALUE.) {
195 cr->tycxx . . $ elt#ty. = SEXP_VALUEcxx . . $ SEXP_VALUE.;
196 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(s->list->val != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
197 strcpycxx . . $ strcpy(b7b3a83273496486).(cr->valcxx . . $ elt#val.,s->listcxx . . $ elt#list.->valcxx . . $ elt#val.);
198 cr->nextcxx . . $ elt#next. = cr->listcxx . . $ elt#list. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
199 } else {
200 cr->tycxx . . $ elt#ty. = SEXP_LISTcxx . . $ SEXP_LIST.;
201 cr->nextcxx . . $ elt#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
202 cr->listcxx . . $ elt#list. = copy_sexpcxx . . $ copy_sexp(3cbd8718f67a36ca).(s->listcxx . . $ elt#list.->listcxx . . $ elt#list.);
203 }
204
205 return ocr;
206 }
207
208 /**
209 * cdr: similar to tail, except this is a copy and not just a reference.
210 */
211 sexp_tcxx . . $ sexp_t# *cdr_sexpcxx . . $ cdr_sexp(3cbd8718f67a36ca).(sexp_tcxx . . $ sexp_t# *s) {
212 sexp_tcxx . . $ sexp_t# *cd;
213
214 /* really dumb */
215 if (s == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
216 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"cdr called on null.\n");
217 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
218 }
219
220 /* less dumb */
221 if (s->tycxx . . $ elt#ty. != SEXP_LISTcxx . . $ SEXP_LIST.) {
222 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"cdr called on atom.\n");
223 return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
224 }
225
226 /* cd = (sexp_t *)malloc(sizeof(sexp_t)); */
227 cd = sexp_t_allocatecxx . . $ sexp_t_allocate(99317b48064593fe).();
228 assertcxx . . $ `<external>/4398592474888995393/assert.h:118:11`!(cd != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
229
230 cd->tycxx . . $ elt#ty. = SEXP_LISTcxx . . $ SEXP_LIST.;
231 cd->nextcxx . . $ elt#next. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
232 cd->listcxx . . $ elt#list. = copy_sexpcxx . . $ copy_sexp(3cbd8718f67a36ca).(s->listcxx . . $ elt#list.->nextcxx . . $ elt#next.);
233 return cd;
234 }
235