#include #include "scan.h" #include "json.h" #include "filter.h" void *jsonp_alloc(void *(*mallocProc)(size_t)); void jsonp_parse(void *parser, int token, struct token tokentype, struct parser *); void jsonp_free(void *p, void (*freeProc)(void*)); void jsonp_trace(FILE *out, char *prompt); int main(void) { char line[1024]; char *in = 0; struct token t = {0}; struct parser state = {0}; void *jp = 0; int ttype; jp = jsonp_alloc(malloc); line[0] = 0; //jsonp_trace(stdout, "trace: "); while (fgets(line, sizeof line, stdin)) { state.line = line; for (in = line; *in; in++) { t.ch = *in; if (*in == '\n') { state.line++; state.pos = 0; } state.pos++; while (t.ch) { ttype = scan_json_ch(*in, &t); if (t.error) { printf("scanning error\n"); exit(EXIT_FAILURE); } if (ttype) { t.str[t.len] = 0; //printf("feeding %d\n", ttype); jsonp_parse(jp, ttype, t, &state); t.type = 0; } } } } ttype = scan_json_ch(0, &t); if (ttype) { t.str[t.len] = 0; jsonp_parse(jp, ttype, t, &state); t.type = 0; } jsonp_parse(jp, 0, t, &state); jsonp_free(jp, free); return 0; }