summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-02-10 15:32:35 -0500
committerJune McEnroe <june@causal.agency>2019-02-10 15:32:35 -0500
commitf1180055eaa4470e6f0e6400943088cbaa05358f (patch)
tree46eea9763a9c8f3780fbbcd9fa52f5fe158c37d1
parentActually do HTML &quot; escaping (diff)
downloadsrc-f1180055eaa4470e6f0e6400943088cbaa05358f.tar.gz
src-f1180055eaa4470e6f0e6400943088cbaa05358f.zip
Add hi debug output
-rw-r--r--bin/hi.c41
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) {
09:05:26 -0500'>2019-11-09Avoid the reserved _A names with BIT macroJune McEnroe 2019-11-09Define macro for bit flag enumsJune McEnroe 2019-11-08Check that password is hashedJune McEnroe 2019-11-08Avoid calling getopt_long again after it returns -1June McEnroe On GNU, calling getopt_long again will reset optind back to the first non-option argument, which would cause an infinite loop of reading the same configurtion file forever. 2019-11-08Only change AWAY status for registered clientsJune McEnroe Turns out I did eventually fix this, because I may want to implement "passive clients" for logging or notification stuff, which wouldn't affect AWAY status either. 2019-11-07Just write the example normallyJune McEnroe 2019-11-07Include path in readlinkat errorJune McEnroe 2019-11-07Call clientConsume before clientRecvJune McEnroe This might reduce the frequency of a client getting its own message back because it was behind in the ring when it sent it. 2019-11-06Use -l:filename in Linux.mkJune McEnroe 2019-11-06Fix compat.h for #defined strlcpyJune McEnroe 2019-11-06Allow unsetting LIBRESSL_PREFIXJune McEnroe 2019-11-06Document calico service configurationJune McEnroe 2019-11-06Document SASL EXTERNAL configuration in more detailJune McEnroe 2019-11-06Document pounce service configurationJune McEnroe 2019-11-06Mention Darwin and GNU/Linux in READMEJune McEnroe 2019-11-06Assume LibreSSL from brew on DarwinJune McEnroe 2019-11-06Remove -DNO_EXPLICIT_BZERO from Darwin.mkJune McEnroe 2019-11-06Don't install rc scripts or dirs on LinuxJune McEnroe