1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <strbuf.h>
#include <string.h>
#include <sexp.h>
#include "common/debug_priv.h"
static int print_sexp (SEXP_t *s_exp)
{
strbuf_t *sb;
/*
* print the S-exp in advanced format
*/
printf ("a> ");
SEXP_fprintfa (stdout, s_exp);
printf ("\n");
/*
* print the S-exp in transport format
*/
printf ("t> ");
sb = strbuf_new (8);
SEXP_sbprintf_t (s_exp, sb);
strbuf_fwrite (stdout, sb);
strbuf_free (sb);
printf ("\n");
return (0);
}
int main (int argc, char *argv[])
{
char *input;
size_t inlen;
SEXP_psetup_t *psetup;
SEXP_pstate_t *pstate;
SEXP_t *s_exp;
setbuf (stdout, NULL);
setbuf (stdin, NULL);
psetup = SEXP_psetup_new ();
pstate = NULL;
if (argc == 1) {
while (!feof (stdin)) {
input = NULL;
inlen = 0;
#if defined(__FreeBSD__)
input = fgetln (stdin, &inlen);
#elif defined(__linux__) || defined(__GLIBC__)
getline (&input, &inlen, stdin);
#elif defined(__SVR4) && defined(__sun)
rpl_getline (&input, &inlen, stdin);
#else
# error "FIXME"
#endif
s_exp = SEXP_parse (psetup, input, inlen, &pstate);
if (s_exp != NULL) {
_A(pstate == NULL);
print_sexp (s_exp);
SEXP_free (s_exp);
}
/* FIXME: getline/fgetln leak */
}
} else {
int i;
for (i = 0; i < (argc - 1); ++i) {
s_exp = SEXP_parse (psetup, argv[i + 1], strlen (argv[i + 1]), &pstate);
if (s_exp != NULL) {
_A(pstate == NULL);
print_sexp (s_exp);
SEXP_free (s_exp);
}
}
if (pstate != NULL)
return (1);
}
SEXP_psetup_free (psetup);
return (0);
}
|