From f0f73c6dd19f6cc605e70626f4996e507a3ae0a2 Mon Sep 17 00:00:00 2001 From: Eric Fischer Date: Thu, 6 Feb 2014 21:06:27 -0800 Subject: [PATCH] Keep track of the root of the parse tree for the caller --- jsonpull.c | 5 ++++- jsonpull.h | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/jsonpull.c b/jsonpull.c index 845ff2a..c70285c 100644 --- a/jsonpull.c +++ b/jsonpull.c @@ -11,9 +11,10 @@ typedef enum json_expect { static json_pull *json_init() { json_pull *j = malloc(sizeof(json_pull)); - j->container = NULL; j->error = NULL; j->line = 1; + j->root = NULL; + j->container = NULL; return j; } @@ -126,6 +127,8 @@ static json_object *add_object(json_pull *j, json_type type) { return NULL; } } + } else { + j->root = o; } return o; diff --git a/jsonpull.h b/jsonpull.h index b4f315c..6a19f90 100644 --- a/jsonpull.h +++ b/jsonpull.h @@ -18,13 +18,15 @@ typedef struct json_object { } json_object; struct json_pull { - json_object *container; + json_object *root; char *error; int (*read)(struct json_pull *); int (*peek)(struct json_pull *); void *source; int line; + + json_object *container; }; typedef struct json_pull json_pull;