summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt14
-rw-r--r--reformatter/json_reformat.c4
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/yajl.c25
-rw-r--r--src/yajl_gen.c2
-rw-r--r--test/yajl_test.c14
-rw-r--r--verify/json_verify.c8
7 files changed, 43 insertions, 26 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1a0dd50..faef0a3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -36,9 +36,17 @@ IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "Debug")
ENDIF ()
-SET(CMAKE_C_FLAGS "-Wall -fPIC -ansi")
-SET(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG -g")
-SET(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -02")
+SET(CMAKE_C_FLAGS "-Wall")
+IF (WIN32)
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996 /wd4255 /wd4130 /wd4100 /wd4711")
+ SET(CMAKE_C_FLAGS_DEBUG "/D DEBUG /Od")
+ SET(CMAKE_C_FLAGS_RELEASE "/D NDEBUG /O2")
+ELSE ()
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -ansi")
+ SET(CMAKE_C_FLAGS_DEBUG "-DDEBUG -g")
+ SET(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -02")
+ENDIF ()
+
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(test)
diff --git a/reformatter/json_reformat.c b/reformatter/json_reformat.c
index ef0b3a7..b47b7da 100644
--- a/reformatter/json_reformat.c
+++ b/reformatter/json_reformat.c
@@ -164,9 +164,7 @@ main(int argc, char ** argv)
rd = fread((void *) fileData, 1, sizeof(fileData) - 1, stdin);
- if (rd < 0) {
- exit(1);
- } else if (rd == 0) {
+ if (rd == 0) {
fprintf(stderr, "read EOF\n");
} else {
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0890303..f740253 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -60,7 +60,7 @@ ADD_CUSTOM_COMMAND(TARGET yajl_s POST_BUILD
GET_TARGET_PROPERTY(libPath yajl LOCATION)
-ADD_CUSTOM_COMMAND(TARGET yajl_s POST_BUILD
+ADD_CUSTOM_COMMAND(TARGET yajl POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${libPath} ${libDir})
FOREACH (header ${PUB_HDRS})
diff --git a/src/yajl.c b/src/yajl.c
index 05f150e..b4a6633 100644
--- a/src/yajl.c
+++ b/src/yajl.c
@@ -39,10 +39,24 @@
#include <assert.h>
const char *
-yajl_status_to_string(yajl_status code)
+yajl_status_to_string(yajl_status stat)
{
- /* XXX */
- return NULL;
+ const char * statStr = "unknown";
+ switch (stat) {
+ case yajl_status_ok:
+ statStr = "ok, no error";
+ break;
+ case yajl_status_client_canceled:
+ statStr = "client canceled parse";
+ break;
+ case yajl_status_insufficient_data:
+ statStr = "eof was met before the parse could complete";
+ break;
+ case yajl_status_error:
+ statStr = "parse error";
+ break;
+ }
+ return statStr;
}
yajl_handle
@@ -51,13 +65,12 @@ yajl_alloc(const yajl_callbacks * callbacks,
void * ctx)
{
unsigned int allowComments = 0;
-
+ yajl_handle hand = (yajl_handle) malloc(sizeof(struct yajl_handle_t));
+
if (config != NULL) {
allowComments = config->allowComments;
}
- yajl_handle hand = (yajl_handle) malloc(sizeof(struct yajl_handle_t));
-
hand->callbacks = callbacks;
hand->ctx = ctx;
hand->lexer = yajl_lex_alloc(allowComments);
diff --git a/src/yajl_gen.c b/src/yajl_gen.c
index e7e8ed9..f15b027 100644
--- a/src/yajl_gen.c
+++ b/src/yajl_gen.c
@@ -91,7 +91,7 @@ yajl_gen_free(yajl_gen g)
#define INSERT_WHITESPACE \
if (g->pretty) { \
if (g->state[g->depth] != yajl_gen_map_val) { \
- int i; \
+ unsigned int i; \
for (i=0;i<g->depth;i++) \
yajl_buf_append(g->buf, g->indentString, \
strlen(g->indentString)); \
diff --git a/test/yajl_test.c b/test/yajl_test.c
index c28565c..9588f79 100644
--- a/test/yajl_test.c
+++ b/test/yajl_test.c
@@ -164,13 +164,13 @@ main(int argc, char ** argv)
/* ok. open file. let's read and parse */
hand = yajl_alloc(&callbacks, &cfg, NULL);
- do {
+ for(;;) {
rd = fread((void *) fileData, 1, sizeof(fileData), fileHand);
- if (rd < 0) {
- fprintf(stderr, "error reading from '%s'\n", fileName);
- break;
- } else if (rd == 0) {
+ if (rd == 0) {
+ if (!feof(fileHand)) {
+ fprintf(stderr, "error reading from '%s'\n", fileName);
+ }
break;
} else {
/* read file data, pass to parser */
@@ -184,8 +184,8 @@ main(int argc, char ** argv)
break;
}
}
- } while (1);
-
+ }
+
yajl_free(hand);
fclose(fileHand);
diff --git a/verify/json_verify.c b/verify/json_verify.c
index 2281998..449fb36 100644
--- a/verify/json_verify.c
+++ b/verify/json_verify.c
@@ -59,7 +59,7 @@ main(int argc, char ** argv)
/* check arguments.*/
if (argc > 1 && argc < 4) {
- unsigned int i;
+ int i;
for (i=1; i < argc;i++) {
if (!strcmp("-q", argv[i])) {
@@ -82,11 +82,9 @@ main(int argc, char ** argv)
retval = 0;
- if (rd < 0) {
- exit(1);
- } else if (rd == 0) {
+ if (rd == 0) {
fprintf(stderr, "read EOF\n");
- } else {
+ } else {
fileData[rd] = 0;
/* read file data, pass to parser */