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 | f1180055eaa4470e6f0e6400943088cbaa05358f (patch) | |
tree | 46eea9763a9c8f3780fbbcd9fa52f5fe158c37d1 | |
parent | Actually do HTML " escaping (diff) | |
download | src-f1180055eaa4470e6f0e6400943088cbaa05358f.tar.gz src-f1180055eaa4470e6f0e6400943088cbaa05358f.zip |
Add hi debug output
Diffstat (limited to '')
-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 e8673e44..24f825ff 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) { |