aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--bp.c9
-rw-r--r--explain.c (renamed from matchviz.c)13
-rw-r--r--explain.h (renamed from matchviz.h)6
4 files changed, 14 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index 7b3bc8f..f5eb960 100644
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,7 @@ G=
O=-O3
ALL_FLAGS=$(CFLAGS) $(OSFLAGS) -DBP_NAME="\"$(NAME)\"" $(EXTRA) $(CWARN) $(G) $(O)
-CFILES=pattern.c definitions.c utils.c match.c files.c print.c matchviz.c json.c utf8.c
+CFILES=pattern.c definitions.c utils.c match.c files.c print.c explain.c json.c utf8.c
OBJFILES=$(CFILES:.c=.o)
all: $(NAME) bp.1
diff --git a/bp.c b/bp.c
index 9f20241..51ab8ca 100644
--- a/bp.c
+++ b/bp.c
@@ -21,10 +21,10 @@
#include <unistd.h>
#include "definitions.h"
+#include "explain.h"
#include "files.h"
#include "json.h"
#include "match.h"
-#include "matchviz.h"
#include "pattern.h"
#include "print.h"
#include "utils.h"
@@ -188,12 +188,11 @@ static int explain_matches(def_t *defs, file_t *f, pat_t *pattern)
int matches = 0;
match_t *m = NULL;
while ((m = next_match(defs, f, m, pattern, options.skip, options.ignorecase))) {
- if (++matches == 1) {
+ if (++matches == 1)
fprint_filename(stdout, f->filename);
- } else {
+ else
printf("\n\n");
- }
- visualize_match(m);
+ explain_match(m);
}
if (m) recycle_if_unused(&m);
return matches;
diff --git a/matchviz.c b/explain.c
index 720ff94..2d54234 100644
--- a/matchviz.c
+++ b/explain.c
@@ -1,11 +1,10 @@
//
-// debugviz.c - Debug visualization of pattern matches.
+// explain.c - Debug visualization of pattern matches.
//
#include <stdio.h>
#include <string.h>
-#include "matchviz.h"
#include "types.h"
#include "utils.h"
@@ -17,7 +16,7 @@ typedef struct match_node_s {
__attribute__((nonnull, pure))
static int height_of_match(match_t *m);
__attribute__((nonnull))
-static void _visualize_matches(match_node_t *firstmatch, int depth, const char *text, size_t textlen);
+static void _explain_matches(match_node_t *firstmatch, int depth, const char *text, size_t textlen);
//
// Return the height of a match object (i.e. the number of descendents of the
@@ -37,7 +36,7 @@ static int height_of_match(match_t *m)
//
// Print a visual explanation for the as-yet-unprinted matches provided.
//
-static void _visualize_matches(match_node_t *firstmatch, int depth, const char *text, size_t textlen)
+static void _explain_matches(match_node_t *firstmatch, int depth, const char *text, size_t textlen)
{
const char *V = "│"; // Vertical bar
const char *H = "─"; // Horizontal bar
@@ -152,7 +151,7 @@ static void _visualize_matches(match_node_t *firstmatch, int depth, const char *
printf("\n");
if (children)
- _visualize_matches(children, depth+1, text, textlen);
+ _explain_matches(children, depth+1, text, textlen);
for (match_node_t *c = children, *next = NULL; c; c = next) {
next = c->next;
@@ -163,10 +162,10 @@ static void _visualize_matches(match_node_t *firstmatch, int depth, const char *
//
// Print a visualization of a match object.
//
-void visualize_match(match_t *m)
+void explain_match(match_t *m)
{
printf("\033[?7l"); // Disable line wrapping
match_node_t first = {.m = m};
- _visualize_matches(&first, 0, m->start, (size_t)(m->end - m->start));
+ _explain_matches(&first, 0, m->start, (size_t)(m->end - m->start));
printf("\033[?7h"); // Re-enable line wrapping
}
diff --git a/matchviz.h b/explain.h
index eb87774..75cf184 100644
--- a/matchviz.h
+++ b/explain.h
@@ -1,13 +1,13 @@
//
// Debug visualization of matches
//
-#ifndef DEBUGVIZ__H
-#define DEBUGVIZ__H
+#ifndef EXPLAIN__H
+#define EXPLAIN__H
#include "types.h"
__attribute__((nonnull))
-void visualize_match(match_t *m);
+void explain_match(match_t *m);
#endif
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1