From 4daf68aad82524b012d0e0d85abf53d378fe1d8a Mon Sep 17 00:00:00 2001 From: erickson Date: Thu, 31 Mar 2005 00:16:31 +0000 Subject: [PATCH] updated to newest code, made my usual usability changes. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@255 9efc2488-bf62-4759-914b-345cdb29e865 --- src/libjson/json_object.c | 3 ++- src/libjson/json_tokener.c | 12 ++++++++---- src/libjson/json_util.c | 17 +++++++++++------ src/libjson/printbuf.c | 24 +++--------------------- 4 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/libjson/json_object.c b/src/libjson/json_object.c index b11e4c5..5c205db 100644 --- a/src/libjson/json_object.c +++ b/src/libjson/json_object.c @@ -25,6 +25,7 @@ #include "libjson/linkhash.h" #include "libjson/arraylist.h" #include "libjson/json_object.h" +#include "libjson/ossupport.h" #include "libjson/json_object_private.h" @@ -91,7 +92,7 @@ static int json_escape_str(struct printbuf *pb, char *str) case '\n': case '\r': case '\t': - case '"': + case '"': if(pos - start_offset > 0) printbuf_memappend(pb, str + start_offset, pos - start_offset); if(c == '\b') printbuf_memappend(pb, "\\b", 2); diff --git a/src/libjson/json_tokener.c b/src/libjson/json_tokener.c index abfe279..70a0147 100644 --- a/src/libjson/json_tokener.c +++ b/src/libjson/json_tokener.c @@ -21,12 +21,16 @@ #include #include +#include "libjson/json_tokener.h" #include "libjson/bits.h" #include "libjson/debug.h" #include "libjson/printbuf.h" +#include "libjson/linkhash.h" #include "libjson/arraylist.h" #include "libjson/json_object.h" -#include "libjson/json_tokener.h" +#include "libjson/ossupport.h" +#include "libjson/json_object_private.h" + static struct json_object* json_tokener_do_parse(struct json_tokener *this); @@ -50,9 +54,8 @@ static struct json_object* json_tokener_do_parse(struct json_tokener *this) enum json_tokener_error err = json_tokener_success; struct json_object *current = NULL, *obj; char *obj_field_name = NULL; - char quote_char = 0; - int deemed_double = 0; - int start_offset = 0; + char quote_char; + int deemed_double, start_offset; state = json_tokener_state_eatws; saved_state = json_tokener_state_start; @@ -197,6 +200,7 @@ static struct json_object* json_tokener_do_parse(struct json_tokener *this) switch(c) { case '"': case '\\': + case '/': printbuf_memappend(this->pb, this->source + start_offset, this->pos - start_offset - 1); start_offset = this->pos++; diff --git a/src/libjson/json_util.c b/src/libjson/json_util.c index 483644e..7cd4eb3 100644 --- a/src/libjson/json_util.c +++ b/src/libjson/json_util.c @@ -7,12 +7,17 @@ #include #include -#include "bits.h" -#include "debug.h" -#include "printbuf.h" -#include "json_object.h" -#include "json_tokener.h" -#include "json_util.h" +#include "libjson/json_util.h" +#include "libjson/json_tokener.h" +#include "libjson/bits.h" +#include "libjson/debug.h" +#include "libjson/printbuf.h" +#include "libjson/linkhash.h" +#include "libjson/arraylist.h" +#include "libjson/json_object.h" +#include "libjson/ossupport.h" +#include "libjson/json_object_private.h" + struct json_object* json_object_from_file(char *filename) diff --git a/src/libjson/printbuf.c b/src/libjson/printbuf.c index 528a750..1dfbccd 100644 --- a/src/libjson/printbuf.c +++ b/src/libjson/printbuf.c @@ -30,23 +30,13 @@ struct printbuf* printbuf_new() { struct printbuf *p; - //if(!(p = calloc(1, sizeof(struct printbuf)))) return NULL; - - size_t len = sizeof(struct printbuf); - p = (struct printbuf*) malloc(len); - if(!p) return NULL; - memset( p, 0, len ); - + if(!(p = calloc(1, sizeof(struct printbuf)))) return NULL; p->size = 32; p->bpos = 0; - - if(!(p->buf = (char*) malloc(p->size))) { + if(!(p->buf = malloc(p->size))) { free(p); return NULL; } - - memset(p->buf, 0, p->size); - return p; } @@ -65,15 +55,7 @@ int printbuf_memappend(struct printbuf *p, char *buf, int size) p->size = new_size; p->buf = t; } - - char* tmp = strdup(p->buf); - memset( p->buf, 0, p->size); - memcpy( p->buf, tmp, strlen(tmp)); - memcpy(p->buf + p->bpos, buf, size); - free(tmp); - - -// memcpy(p->buf + p->bpos, buf, size); + memcpy(p->buf + p->bpos, buf, size); p->bpos += size; p->buf[p->bpos]= '\0'; return size; -- 2.11.0