From 44bd8403e558e3e9cfe059dcbf548585362034e5 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Thu, 7 Feb 2019 03:01:43 -0500 Subject: Add Todo class and parent syntax constraint --- bin/hi.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bin/hi.c b/bin/hi.c index 2dd210e7..42db61a0 100644 --- a/bin/hi.c +++ b/bin/hi.c @@ -33,20 +33,22 @@ enum Class { Macro, String, Comment, + Todo, ClassCount, }; struct Syntax { enum Class class; - size_t subexp; + enum Class parent; const char *pattern; const char *pattend; + size_t subexp; }; #define CKB "(^|[^[:alnum:]_]|\n)" static const struct Syntax CSyntax[] = { { Keyword, .subexp = 2, .pattern = CKB"(enum|struct|typedef|union)"CKB }, - { Keyword, .subexp = 2, .pattern = CKB"(const|inline|static)"CKB }, + { Keyword, .subexp = 2, .pattern = CKB"(const|extern|inline|static)"CKB }, { Keyword, .subexp = 2, .pattern = CKB"(do|else|for|if|switch|while)"CKB }, { Keyword, .subexp = 2, .pattern = CKB"(break|continue|goto|return)"CKB }, { Keyword, .subexp = 2, .pattern = CKB"(case|default)"CKB }, @@ -57,6 +59,7 @@ static const struct Syntax CSyntax[] = { { Comment, .pattern = "//.*", }, { Comment, .pattern = "/\\*", .pattend = "\\*/" }, { Comment, .pattern = "^#if 0", .pattend = "^#endif" }, + { Todo, .pattern = "FIXME|TODO|XXX", .parent = Comment }, }; static const struct Language { @@ -107,6 +110,7 @@ static void highlight(struct Language lang, enum Class *hi, const char *str) { regmatch_t sub = subs[syn.subexp]; for (regoff_t j = sub.rm_so; j < sub.rm_eo; ++j) { + if (syn.parent && hi[offset + j] != syn.parent) continue; hi[offset + j] = lang.syntax[i].class; } } @@ -129,6 +133,7 @@ static const enum SGR Style[ClassCount][2] = { [Macro] = { Reset, Green }, [String] = { Reset, Cyan }, [Comment] = { Reset, Blue }, + [Todo] = { Bold, Blue }, }; static void ansiOutput(enum Class class, const char *str, size_t len) { @@ -175,6 +180,7 @@ static const char *ClassName[ClassCount] = { [Macro] = "Macro", [String] = "String", [Comment] = "Comment", + [Todo] = "Todo", }; static void htmlOutput(enum Class class, const char *str, size_t len) { @@ -195,6 +201,7 @@ static void htmlDocumentHeader(const char *path) { ".hi.Macro { color: green; }\n" ".hi.String { color: teal; }\n" ".hi.Comment { color: navy; }\n" + ".hi.Todo { color: navy; font-weight: bold }\n" "\n" ); htmlHeader(path); -- cgit 1.4.1 /th>Commit message (Collapse)Author 2019-07-16Add catgirl shottyJune McEnroe 2019-07-16Fix SGRs 90 and 100June McEnroe 2019-07-15Add up -tJune McEnroe 2019-07-15Implement scrolling regionJune McEnroe 2019-07-14Add CSI names to shotty -dJune McEnroe 2019-07-14Ignore CSI tJune McEnroe 2019-07-14Add more info to shotty man pageJune McEnroe 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