From ae8238f5d9320f5ec16d67b62083f5897c228974 Mon Sep 17 00:00:00 2001 From: lloydh Date: Thu, 26 Jul 2007 05:46:53 +0000 Subject: clean up json_verify and json_reformat, copy into sdk. git-svn-id: http://yajl-c.googlecode.com/svn/yajl/trunk@68 e775cfb5-b74b-0410-aad5-5bebe4a96390 --- verify/CMakeLists.txt | 12 ++++++++++++ verify/json_verify.c | 45 +++++++++++++++++++++++++++++---------------- 2 files changed, 41 insertions(+), 16 deletions(-) (limited to 'verify') diff --git a/verify/CMakeLists.txt b/verify/CMakeLists.txt index 3e7c52f..fa13553 100644 --- a/verify/CMakeLists.txt +++ b/verify/CMakeLists.txt @@ -28,6 +28,12 @@ # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. +# set up some paths +SET (binDir ${CMAKE_CURRENT_BINARY_DIR}/../dist/bin) + +# create some directories +FILE(MAKE_DIRECTORY ${binDir}) + SET (SRCS json_verify.c) # use the library we build, duh. @@ -37,3 +43,9 @@ LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../dist/lib) ADD_EXECUTABLE(json_verify ${SRCS}) TARGET_LINK_LIBRARIES(json_verify yajl_s) + +# copy in the binary +GET_TARGET_PROPERTY(binPath json_verify LOCATION) + +ADD_CUSTOM_COMMAND(TARGET json_verify POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${binPath} ${binDir}) diff --git a/verify/json_verify.c b/verify/json_verify.c index 449fb36..2b656ae 100644 --- a/verify/json_verify.c +++ b/verify/json_verify.c @@ -52,7 +52,7 @@ main(int argc, char ** argv) yajl_status stat; size_t rd; yajl_handle hand; - static unsigned char fileData[8192]; + static unsigned char fileData[65536]; int quiet = 0; int retval; yajl_parser_config cfg = { 0 }; @@ -78,26 +78,39 @@ main(int argc, char ** argv) /* allocate a parser */ hand = yajl_alloc(NULL, &cfg, NULL); - rd = fread((void *) fileData, 1, sizeof(fileData) - 1, stdin); + for (;;) { + rd = fread((void *) fileData, 1, sizeof(fileData) - 1, stdin); - retval = 0; + retval = 0; - if (rd == 0) { - fprintf(stderr, "read EOF\n"); - } else { - fileData[rd] = 0; - - /* read file data, pass to parser */ - stat = yajl_parse(hand, fileData, rd); - if (stat != yajl_status_ok) { - if (!quiet) { - unsigned char * str = yajl_get_error(hand, 1, fileData, rd); - fprintf(stderr, (const char *) str); - yajl_free_error(str); + if (rd == 0) { + if (feof(stdin)) { + break; + } else { + if (!quiet) { + fprintf(stderr, "error encountered on file read\n"); + } + retval = 1; + break; + } + } else { + fileData[rd] = 0; + + /* 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; } - retval = 1; } } + yajl_free(hand); if (!quiet) { -- cgit v1.2.1