X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fjsonpath.git;a=blobdiff_plain;f=main.c;h=05e445c1569353f666aac89a2c872409e3c57b03;hp=7a19091900573f656617c5ea699afac7c45eff7a;hb=bb372e308e2332766d038cef7bcdf74df7b0e31c;hpb=054eb236c524a237f7cd156e8e71151b1b4e0ace diff --git a/main.c b/main.c index 7a19091..05e445c 100644 --- a/main.c +++ b/main.c @@ -76,23 +76,25 @@ static void export_json(struct json_object *jsobj, char *expr) { bool first; - struct jp_opcode *tree; + struct jp_state *state; struct json_object *res; - const char *error, *prefix; + const char *prefix; - tree = jp_parse(expr, &error); + state = jp_parse(expr); - if (error) + if (!state || state->error) { - fprintf(stderr, "In expression '%s': %s\n", expr, error); - return; + fprintf(stderr, "In expression '%s': %s\n", + expr, state ? state->error : "Out of memory"); + + goto out; } - res = jp_match(tree, jsobj); + res = jp_match(state->path, jsobj); - if (tree->type == T_LABEL) + if (state->path->type == T_LABEL) { - prefix = tree->str; + prefix = state->path->str; switch (json_object_get_type(res)) { @@ -163,7 +165,9 @@ export_json(struct json_object *jsobj, char *expr) printf("%s\n", json_object_to_json_string(res)); } - jp_free(); +out: + if (state) + jp_free(state); } int main(int argc, char **argv)