diff options
author | Timothy J. Wood <tjw@omnigroup.com> | 2009-02-26 15:58:13 -0800 |
---|---|---|
committer | Timothy J. Wood <tjw@omnigroup.com> | 2009-02-26 15:58:13 -0800 |
commit | 934b9827046e0d31689996a13faf1635ffce088a (patch) | |
tree | 43450859750e3ec994718d9c3894fe510168e0cb /verify | |
parent | f9dbf2a27b46edc28c0e5df19d7a1bb25488f32e (diff) | |
download | yajl-934b9827046e0d31689996a13faf1635ffce088a.tar.gz |
Update json_reformat and json_verify to use the new yajl_parse_complete()
at the end of their input.
Diffstat (limited to 'verify')
-rw-r--r-- | verify/json_verify.c | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/verify/json_verify.c b/verify/json_verify.c index 334d490..f76fbe9 100644 --- a/verify/json_verify.c +++ b/verify/json_verify.c @@ -56,7 +56,7 @@ main(int argc, char ** argv) yajl_handle hand; static unsigned char fileData[65536]; int quiet = 0; - int retval = 0; + int retval = 0, done = 0; yajl_parser_config cfg = { 0, 1 }; /* check arguments.*/ @@ -82,37 +82,40 @@ main(int argc, char ** argv) /* allocate a parser */ hand = yajl_alloc(NULL, &cfg, NULL); - for (;;) { + while (!done) { rd = fread((void *) fileData, 1, sizeof(fileData) - 1, stdin); retval = 0; if (rd == 0) { - if (feof(stdin)) { - break; - } else { + if (!feof(stdin)) { if (!quiet) { fprintf(stderr, "error encountered on file read\n"); } retval = 1; break; } - } else { - fileData[rd] = 0; - + done = 1; + } + fileData[rd] = 0; + + if (done) + /* parse any remaining buffered data */ + stat = yajl_parse_complete(hand); + else /* read file data, pass to parser */ stat = yajl_parse(hand, fileData, rd); - if (stat != yajl_status_ok && - stat != yajl_status_insufficient_data) - { - if (!quiet) { - unsigned char * str = yajl_get_error(hand, 1, fileData, rd); - fprintf(stderr, (const char *) str); - yajl_free_error(str); - } - retval = 1; - break; + + if (stat != yajl_status_ok && + stat != yajl_status_insufficient_data) + { + if (!quiet) { + unsigned char * str = yajl_get_error(hand, 1, fileData, rd); + fprintf(stderr, (const char *) str); + yajl_free_error(str); } + retval = 1; + break; } } |