aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-05-20 01:00:10 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-05-20 01:00:10 -0700
commit85dba49b542bed21d67c2b78d15ebaaf07caff97 (patch)
treee85838ab496050943226b1ab4f6b3f640f1136f7
parent7ac9df98dce310ff781b984e66ba5cad0fe1b4df (diff)
Fixed up JSON output
-rw-r--r--bp.c4
-rw-r--r--json.c2
2 files changed, 3 insertions, 3 deletions
diff --git a/bp.c b/bp.c
index 6eb9c3a..f04c8de 100644
--- a/bp.c
+++ b/bp.c
@@ -165,7 +165,7 @@ static int is_text_file(const char *filename)
//
static int print_matches_as_json(def_t *defs, file_t *f, pat_t *pattern)
{
- int matches = 0;
+ static int matches = 0;
for (match_t *m = NULL; (m = next_match(defs, f, m, pattern, options.skip, options.ignorecase)); ) {
if (++matches > 1)
printf(",\n");
@@ -173,7 +173,7 @@ static int print_matches_as_json(def_t *defs, file_t *f, pat_t *pattern)
printf("\"tree\":{\"rule\":\"text\",\"start\":%d,\"end\":%ld,\"children\":[",
0, f->end - f->contents);
json_match(f->contents, m, options.verbose);
- printf("]}}\n");
+ printf("]}}");
}
return matches;
}
diff --git a/json.c b/json.c
index 18b1fa6..546d99b 100644
--- a/json.c
+++ b/json.c
@@ -17,7 +17,7 @@ static int _json_match(const char *text, match_t *m, int comma, bool verbose);
static int _json_match(const char *text, match_t *m, int comma, bool verbose)
{
if (!verbose) {
- if (m->pat->type != BP_REF) {
+ if (m->pat->type != BP_REF && m->pat->type != BP_ERROR) {
for (match_t *child = m->child; child; child = child->nextsibling) {
comma |= _json_match(text, child, comma, verbose);
}