From: Adam Dickmeiss Date: Fri, 9 Apr 2010 11:40:31 +0000 (+0200) Subject: yaz-json-parse displays leading text until error X-Git-Tag: v4.0.4~24 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=14a92b63a016b6cc96c857cad8283efda91ea867;p=yaz-moved-to-github.git yaz-json-parse displays leading text until error --- diff --git a/util/json-parse.c b/util/json-parse.c index db3e473..ce1da8b 100644 --- a/util/json-parse.c +++ b/util/json-parse.c @@ -22,6 +22,7 @@ static struct json_node *do_parse_from_stdin(void) FILE *f = stdin; WRBUF w = wrbuf_alloc(); struct json_node *n; + size_t pos; const char *json_str; const char *err_msg; int c; @@ -29,9 +30,13 @@ static struct json_node *do_parse_from_stdin(void) 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) - 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; }