summaryrefslogtreecommitdiff
path: root/verify
diff options
context:
space:
mode:
authorlloydh <lloydh@e775cfb5-b74b-0410-aad5-5bebe4a96390>2007-07-26 05:46:53 +0000
committerlloydh <lloydh@e775cfb5-b74b-0410-aad5-5bebe4a96390>2007-07-26 05:46:53 +0000
commitae8238f5d9320f5ec16d67b62083f5897c228974 (patch)
tree3216191a54c1335f637d7ee463437440a5bb89f8 /verify
parentcae73394d4500528d6a282a39990412af9c28f7e (diff)
downloadyajl-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 'verify')
-rw-r--r--verify/CMakeLists.txt12
-rw-r--r--verify/json_verify.c45
2 files changed, 41 insertions, 16 deletions
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) {