diff options
author | lloydh <lloydh@e775cfb5-b74b-0410-aad5-5bebe4a96390> | 2007-07-26 05:46:53 +0000 |
---|---|---|
committer | lloydh <lloydh@e775cfb5-b74b-0410-aad5-5bebe4a96390> | 2007-07-26 05:46:53 +0000 |
commit | ae8238f5d9320f5ec16d67b62083f5897c228974 (patch) | |
tree | 3216191a54c1335f637d7ee463437440a5bb89f8 | |
parent | cae73394d4500528d6a282a39990412af9c28f7e (diff) | |
download | yajl-ae8238f5d9320f5ec16d67b62083f5897c228974.tar.gz |
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
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | reformatter/CMakeLists.txt | 12 | ||||
-rw-r--r-- | reformatter/json_reformat.c | 48 | ||||
-rw-r--r-- | verify/CMakeLists.txt | 12 | ||||
-rw-r--r-- | verify/json_verify.c | 45 |
5 files changed, 83 insertions, 36 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index faef0a3..289864c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,7 @@ IF (WIN32) ELSE () SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -ansi") SET(CMAKE_C_FLAGS_DEBUG "-DDEBUG -g") - SET(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -02") + SET(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2") ENDIF () diff --git a/reformatter/CMakeLists.txt b/reformatter/CMakeLists.txt index 2df8807..1476e4c 100644 --- a/reformatter/CMakeLists.txt +++ b/reformatter/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 a paths +SET (binDir ${CMAKE_CURRENT_BINARY_DIR}/../dist/bin) + +# create a directories +FILE(MAKE_DIRECTORY ${binDir}) + SET (SRCS json_reformat.c) # use the library we build, duh. @@ -37,3 +43,9 @@ LINK_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/../dist/lib) ADD_EXECUTABLE(json_reformat ${SRCS}) TARGET_LINK_LIBRARIES(json_reformat yajl_s) + +# copy the binary into the output directory +GET_TARGET_PROPERTY(binPath json_reformat LOCATION) + +ADD_CUSTOM_COMMAND(TARGET json_reformat POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${binPath} ${binDir}) diff --git a/reformatter/json_reformat.c b/reformatter/json_reformat.c index b47b7da..4a8cddb 100644 --- a/reformatter/json_reformat.c +++ b/reformatter/json_reformat.c @@ -137,7 +137,7 @@ int main(int argc, char ** argv) { yajl_handle hand; - static unsigned char fileData[8192]; + static unsigned char fileData[65536]; /* generator config */ yajl_gen_config conf = { 1, " " }; yajl_gen g; @@ -162,29 +162,39 @@ main(int argc, char ** argv) /* ok. open file. let's read and parse */ hand = yajl_alloc(&callbacks, &cfg, (void *) g); - rd = fread((void *) fileData, 1, sizeof(fileData) - 1, stdin); + for (;;) { + rd = fread((void *) fileData, 1, sizeof(fileData) - 1, stdin); - 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) { - 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 { + fprintf(stderr, "error on file read.\n"); + break; + } } else { - const unsigned char * buf; - unsigned int len; - yajl_gen_get_buf(g, &buf, &len); - printf((const char *) buf); + 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) + { + unsigned char * str = yajl_get_error(hand, 1, fileData, rd); + fprintf(stderr, (const char *) str); + yajl_free_error(str); + } else { + const unsigned char * buf; + unsigned int len; + yajl_gen_get_buf(g, &buf, &len); + fwrite(buf, 1, len, stdout); + yajl_gen_clear(g); + } } } + yajl_gen_free(g); yajl_free(hand); - + return 0; } 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) { |