version 1.3, 2018/03/07 12:29:28
|
version 1.4, 2021/03/21 01:32:04
|
Line 258 run_make()
|
Line 258 run_make()
|
} |
} |
|
|
int |
int |
|
run_stdin(json_t *json) |
|
{ |
|
char szJSON[BUFSIZ] = { [0 ... BUFSIZ - 1] = 0 }; |
|
jtok_t *tok, toks[1024]; |
|
int ret; |
|
char *str; |
|
|
|
printf("Input JSON> "); |
|
fgets(szJSON, sizeof szJSON, stdin); |
|
printf("Readed JSON> %s", szJSON); |
|
|
|
json_init(json, 0); |
|
ret = json_parse(json, szJSON, strlen(szJSON), toks, sizeof toks/sizeof *toks); |
|
if (ret == -1) { |
|
printf("Error:: #%d - %s\n", elwix_GetErrno(), elwix_GetError()); |
|
return 1; |
|
} else |
|
printf("We parsed %d tokens next=%lu\n", ret, json->h_next); |
|
|
|
printf("dump=%d\n", json_dump(stdout, szJSON, toks, json->h_next, 0)); |
|
|
|
tok = json_findbykey(szJSON, "aaa", J_STRING, toks, ret); |
|
if (tok) { |
|
str = json_token2str(szJSON, tok); |
|
if (str) { |
|
printf("str=%s\n", str); |
|
json_freestr(str); |
|
} |
|
} |
|
return 0; |
|
} |
|
|
|
int |
main(int argc, char **argv) |
main(int argc, char **argv) |
{ |
{ |
json_t json; |
json_t json; |
|
|
if (argc < 2) |
if (argc < 2) |
return run_simple(&json); | return run_stdin(&json); |
else if (argc < 3) |
else if (argc < 3) |
|
return run_simple(&json); |
|
else if (argc < 4) |
return run_make(); |
return run_make(); |
else |
else |
return run_dump(&json, argv); |
return run_dump(&json, argv); |