projects
/
yaz-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add wrbuf_iconv_json_{write,puts}
[yaz-moved-to-github.git]
/
util
/
json-parse.c
diff --git
a/util/json-parse.c
b/util/json-parse.c
index
db3e473
..
833a1b5
100644
(file)
--- a/
util/json-parse.c
+++ b/
util/json-parse.c
@@
-1,7
+1,10
@@
/* This file is part of the YAZ toolkit.
/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2010 Index Data
+ * Copyright (C) 1995-2013 Index Data
* See the file LICENSE for details.
*/
* See the file LICENSE for details.
*/
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
@@
-22,6
+25,7
@@
static struct json_node *do_parse_from_stdin(void)
FILE *f = stdin;
WRBUF w = wrbuf_alloc();
struct json_node *n;
FILE *f = stdin;
WRBUF w = wrbuf_alloc();
struct json_node *n;
+ size_t pos;
const char *json_str;
const char *err_msg;
int c;
const char *json_str;
const char *err_msg;
int c;
@@
-29,9
+33,13
@@
static struct json_node *do_parse_from_stdin(void)
while ((c = getc(f)) != EOF)
wrbuf_putc(w, c);
json_str = wrbuf_cstr(w);
while ((c = getc(f)) != EOF)
wrbuf_putc(w, c);
json_str = wrbuf_cstr(w);
- n = json_parse(json_str, &err_msg);
+ n = json_parse2(json_str, &err_msg, &pos);
if (!n)
if (!n)
- fprintf(stderr, "JSON parse error: %s\n", err_msg);
+ {
+ fprintf(stderr, "JSON parse error: %s\nLeading text was:\n", err_msg);
+ fwrite(json_str, 1, pos, stderr);
+ fprintf(stderr, "^\n");
+ }
wrbuf_destroy(w);
return n;
}
wrbuf_destroy(w);
return n;
}
@@
-47,7
+55,7
@@
int main(int argc, char **argv)
switch (ret)
{
case 'p':
switch (ret)
{
case 'p':
- print = 1;
+ print++;
break;
default:
usage(argv[0]);
break;
default:
usage(argv[0]);
@@
-59,7
+67,10
@@
int main(int argc, char **argv)
if (print)
{
WRBUF result = wrbuf_alloc();
if (print)
{
WRBUF result = wrbuf_alloc();
- json_write_wrbuf(n, result);
+ if (print > 1)
+ json_write_wrbuf_pretty(n, result);
+ else
+ json_write_wrbuf(n, result);
puts(wrbuf_cstr(result));
wrbuf_destroy(result);
}
puts(wrbuf_cstr(result));
wrbuf_destroy(result);
}