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. **/
25
/** NOTE: This library is part of the supermon project, hence the name
28
* Matt's smaller s-expression parsing library
30
* Written by Matt Sottile (matt@lanl.gov), January 2002.
38
#include "faststack.h"
41
* Recursively walk an s-expression and free it.
44
destroy_sexp (sexp_t * s)
50
if (s->ty == SEXP_LIST)
51
destroy_sexp (s->list);
53
if (s->ty == SEXP_VALUE && s->val != NULL)
56
destroy_sexp (s->next);
62
* Iterative method to walk sx and turn it back into the string
63
* representation of the s-expression. Fills the buffer.
66
print_sexp (char *buf, int size, sexp_t * sx)
78
fprintf(stderr,"print_sexp: s-expression is null.\n");
82
/*fakehead = (sexp_t *)malloc(sizeof(sexp_t));*/
83
fakehead = sexp_t_allocate();
84
assert(fakehead!=NULL);
86
/* duplicate the head to prevent going down a sx->next path
87
that we don't really want to see. */
88
fakehead->list = sx->list;
89
fakehead->ty = sx->ty;
90
fakehead->next = NULL; /* this is the important part of fakehead */
91
fakehead->aty = sx->aty;
92
if (fakehead->ty == SEXP_VALUE) {
93
assert(sx->val != NULL);
94
fakehead->val = (char *)malloc(sizeof(char)*sx->val_used);
95
assert(fakehead->val != NULL);
96
fakehead->val_used = fakehead->val_allocated = sx->val_used;
97
strcpy(fakehead->val,sx->val);
103
"Warning: print_sexp not provided sufficient space.\n");
107
stack = make_stack ();
109
push (stack, fakehead);
111
while (stack->top != NULL)
114
tdata = (sexp_t *) top->data;
129
"Warning: print_sexp out of buffer space.\n");
134
if (stack->top == NULL)
138
top->data = ((sexp_t *) top->data)->next;
139
if (top->data != NULL)
147
"Warning: print_sexp out of buffer space.\n");
152
else if (tdata->ty == SEXP_VALUE)
154
if (tdata->aty == SEXP_DQUOTE)
160
else if (tdata->aty == SEXP_SQUOTE)
167
assert(tdata->val != NULL);
169
/* copy value into string */
170
while (tc[0] != 0 && left > 0)
172
/* escape characters that need escaping. */
173
/* if (tc[0] == '\"' || tc[0] == '\'' ||
174
tc[0] == '\\' || ((tc[0] == '(' ||
176
tdata->aty != SEXP_DQUOTE))
181
if (left == 0) break;
192
if (tdata->aty == SEXP_DQUOTE && left > 0)
203
fprintf (stderr, "Warning: print_sexp out of buffer space.\n");
207
top->data = ((sexp_t *) top->data)->next;
209
if (top->data != NULL)
217
"Warning: print_sexp out of buffer space.\n");
222
else if (tdata->ty == SEXP_LIST)
230
fprintf (stderr, "Warning: print_sexp out of buffer space.\n");
234
push (stack, tdata->list);
238
fprintf (stderr, "ERROR: Unknown type in sexp_t.\n");
252
fprintf (stderr, "Warning: print_sexp out of buffer space.\n");
259
retval = (size-left);
266
destroy_stack (stack);
267
sexp_t_deallocate(fakehead);