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 /reformatter | |
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
Diffstat (limited to 'reformatter')
-rw-r--r-- | reformatter/CMakeLists.txt | 12 | ||||
-rw-r--r-- | reformatter/json_reformat.c | 48 |
2 files changed, 41 insertions, 19 deletions
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; } |