diff options
author | June McEnroe <june@causal.agency> | 2019-02-10 15:32:35 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-02-10 15:32:35 -0500 |
commit | c63280aff71db5f49b8af4f2c85b775df0047985 (patch) | |
tree | 247b2fca8b9b39bbe26dcf3648ff6e5f001b387c /bin | |
parent | Actually do HTML " escaping (diff) | |
download | src-c63280aff71db5f49b8af4f2c85b775df0047985.tar.gz src-c63280aff71db5f49b8af4f2c85b775df0047985.zip |
Add hi debug output
Diffstat (limited to 'bin')
-rw-r--r-- | bin/hi.c | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/bin/hi.c b/bin/hi.c index 2bb626e7..abd8aea8 100644 --- a/bin/hi.c +++ b/bin/hi.c @@ -49,6 +49,12 @@ enum Class { ClassLen, }; +static const char *ClassName[ClassLen] = { +#define X(class) [class] = #class, + ENUM_CLASS +#undef X +}; + struct Syntax { enum Class class; Set parent; @@ -460,12 +466,6 @@ static void htmlEscape(const char *str, size_t len) { } } -static const char *ClassName[ClassLen] = { -#define X(class) [class] = #class, - ENUM_CLASS -#undef X -}; - static const char *HTMLStyle[ClassLen] = { [Keyword] = "color: dimgray;", [Macro] = "color: green;", @@ -534,15 +534,38 @@ htmlOutput(const char *opts[], enum Class class, const char *str, size_t len) { // }}} +// Debug format {{{ +static void +debugOutput(const char *opts[], enum Class class, const char *str, size_t len) { + (void)opts; + printf("%s\t\"", ClassName[class]); + while (len) { + size_t run = strcspn(str, "\t\n\"\\"); + if (run > len) run = len; + switch (str[0]) { + break; case '\t': run = 1; printf("\\t"); + break; case '\n': run = 1; printf("\\n"); + break; case '"': run = 1; printf("\\\""); + break; case '\\': run = 1; printf("\\\\"); + break; default: printf("%.*s", (int)run, str); + } + str += run; + len -= run; + } + printf("\"\n"); +} +// }}} + static const struct Format { const char *name; OutputFn *output; HeaderFn *header; HeaderFn *footer; } Formats[] = { - { "ansi", ansiOutput, NULL, NULL }, - { "irc", ircOutput, ircHeader, NULL }, - { "html", htmlOutput, htmlHeader, htmlFooter }, + { "ansi", ansiOutput, NULL, NULL }, + { "irc", ircOutput, ircHeader, NULL }, + { "html", htmlOutput, htmlHeader, htmlFooter }, + { "debug", debugOutput, NULL, NULL }, }; static bool findLanguage(struct Language *lang, const char *name) { |