summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2022-06-02 21:45:47 -0400
committerJune McEnroe <june@causal.agency>2022-06-02 21:45:47 -0400
commit557f1deb2b1a18ede48950b5421b71f662ea309d (patch)
tree99af486c63e6664f42834362a27ec11d6d2ac2ef
parentDon't duplicate path string (diff)
downloadsrc-557f1deb2b1a18ede48950b5421b71f662ea309d.tar.gz
src-557f1deb2b1a18ede48950b5421b71f662ea309d.zip
Clean up parsing a little
Diffstat (limited to '')
-rw-r--r--bin/qf.c28
1 files changed, 11 insertions, 17 deletions
diff --git a/bin/qf.c b/bin/qf.c
index 98c897ce..0a79307e 100644
--- a/bin/qf.c
+++ b/bin/qf.c
@@ -54,37 +54,31 @@ static void push(struct Line line) {
 }
 
 static void parse(struct Line line) {
-	char *text = line.text;
-	size_t sep = strcspn(text, ":");
-	if (!text[sep]) {
+	line.path = strsep(&line.text, ":");
+	if (!line.text) {
 		line.type = Text;
+		line.text = line.path;
 		if (lines.len) line.path = lines.ptr[lines.len-1].path;
 		push(line);
 		return;
 	}
-	line.path = text;
-	text[sep] = '\0';
-	line.text = &text[sep+1];
-	if (
-		!lines.len ||
-		!lines.ptr[lines.len-1].path ||
-		strcmp(line.path, lines.ptr[lines.len-1].path)
-	) {
-		if (lines.len) {
-			push((struct Line) { .type = Text, .text = " " });
-		}
+	struct Line prev = {0};
+	if (lines.len) prev = lines.ptr[lines.len-1];
+	if (!prev.path || strcmp(line.path, prev.path)) {
+		if (lines.len) push((struct Line) { .type = Text, .text = " " });
 		line.type = File;
 		push(line);
 	}
 	char *rest;
 	line.nr = strtoul(line.text, &rest, 10);
-	line.type = Match;
-	if (rest != line.text && rest[0] == ':') {
+	if (rest > line.text && rest[0] == ':') {
 		line.type = Match;
 		line.text = &rest[1];
-	} else if (rest != line.text && rest[0] == '-') {
+	} else if (rest > line.text && rest[0] == '-') {
 		line.type = Context;
 		line.text = &rest[1];
+	} else {
+		line.type = Text;
 	}
 	push(line);
 }