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.
41
static sexp_iowrap_t *_internal_iow = NULL;
49
if (_internal_iow != NULL)
50
destroy_iowrap(_internal_iow);
60
read_sexp (char *buf, int size, int f)
64
if (_internal_iow == NULL)
65
_internal_iow = init_iowrap(f);
66
if (_internal_iow->fd != f) {
67
destroy_iowrap(_internal_iow);
68
if (f > -1) _internal_iow = init_iowrap(f);
72
sx = read_one_sexp(_internal_iow);
74
if (sx == NULL) return 0;
76
print_sexp(buf,size,sx);
87
fread_sexp (char *buf, int size, FILE *fp)
89
return read_sexp(buf,size,fileno(fp));
95
sexp_iowrap_t *init_iowrap(int fd) {
98
iow = (sexp_iowrap_t *)malloc(sizeof(sexp_iowrap_t));
110
void destroy_iowrap(sexp_iowrap_t *iow) {
111
if (iow == NULL) return; /* idiot */
113
destroy_continuation(iow->cc);
120
sexp_t *read_one_sexp(sexp_iowrap_t *iow) {
124
iow->cnt = read(iow->fd,iow->buf,BUFSIZ);
125
if (iow->cnt == 0) return NULL;
128
iow->cc = cparse_sexp(iow->buf,iow->cnt,iow->cc);
130
while (iow->cc->last_sexp == NULL) {
131
if (iow->cc->error != 0) {
132
fprintf(stderr,"ERROR\n");
136
iow->cnt = read(iow->fd,iow->buf,BUFSIZ);
141
iow->cc = cparse_sexp(iow->buf,iow->cnt,iow->cc);
144
sx = iow->cc->last_sexp;
145
iow->cc->last_sexp = NULL;