From 37109fbb22fdf89d573e01dc77abc575ce8119ed Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Thu, 2 Jun 2022 21:45:47 -0400 Subject: Clean up parsing a little --- bin/qf.c | 28 +++++++++++----------------- 1 file 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); } -- cgit 1.4.1 hotel.txt'>
path: root/txt/trouble-at-jinx-hotel.txt (unfollow)
Commit message (Collapse)Author
2019-07-14Fix OSC PT handlingJune McEnroe
Undo gone wrong!
2019-07-14Handle OSC in shottyJune McEnroe
2019-07-14Add shotty -dJune McEnroe
2019-07-13Add shotty -cJune McEnroe
2019-07-13Add DL to shottyJune McEnroe
2019-07-12Color html rather than bodyJune McEnroe
If background-color is only set on body then overscroll in Safari reveals white.
2019-07-12Make author consistent and update URLsJune McEnroe
2019-07-12Move to www/text.causal.agencyJune McEnroe
2019-07-12Add new causal.agency with shotty shotsJune McEnroe
2019-07-12Use -s to infer terminal sizeJune McEnroe
2019-07-12Add DCH to shottyJune McEnroe
This makes htop mostly work. Scrolling region still missing.
2019-07-12Support insert mode in shottyJune McEnroe
This is how curses puts characters into the bottom-right cell of the terminal.
2019-07-11Don't do carriage return on line feedJune McEnroe
2019-07-11Interpret 256color-style SGRsJune McEnroe
2019-07-11Use inline style rather than <b>, <i>, <u>June McEnroe
2019-07-11Factor out clearJune McEnroe
2019-07-11Add bright option to shottyJune McEnroe
2019-07-11Output <b>, <i>, <u> in shottyJune McEnroe
2019-07-10Ignore SM and RMJune McEnroe
2019-07-09Add shotty man page and build itJune McEnroe
2019-07-09Add up -cJune McEnroe
2019-07-09Add options for default colors to shottyJune McEnroe
2019-07-08Use char literals consistentlyJune McEnroe