projects
/
oweals
/
jsonpath.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
eliminate global variables and use a private parser/lexer state
[oweals/jsonpath.git]
/
main.c
diff --git
a/main.c
b/main.c
index 7a19091900573f656617c5ea699afac7c45eff7a..05e445c1569353f666aac89a2c872409e3c57b03 100644
(file)
--- a/
main.c
+++ b/
main.c
@@
-76,23
+76,25
@@
static void
export_json(struct json_object *jsobj, char *expr)
{
bool first;
export_json(struct json_object *jsobj, char *expr)
{
bool first;
- struct jp_
opcode *tre
e;
+ struct jp_
state *stat
e;
struct json_object *res;
struct json_object *res;
- const char *
error, *
prefix;
+ const char *prefix;
-
tree = jp_parse(expr, &erro
r);
+
state = jp_parse(exp
r);
- 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))
{
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));
}
printf("%s\n", json_object_to_json_string(res));
}
- jp_free();
+out:
+ if (state)
+ jp_free(state);
}
int main(int argc, char **argv)
}
int main(int argc, char **argv)