From 91bb43a64f479c1fe2dbb54500912049505875c1 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 28 Dec 2020 23:48:24 -0500 Subject: Add hilex IRC formatter --- bin/hilex/hilex.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'bin/hilex/hilex.c') diff --git a/bin/hilex/hilex.c b/bin/hilex/hilex.c index aa8d4e05..089f85ee 100644 --- a/bin/hilex/hilex.c +++ b/bin/hilex/hilex.c @@ -63,6 +63,7 @@ static const struct { } Formatters[] = { { &FormatANSI, "ansi" }, { &FormatDebug, "debug" }, + { &FormatIRC, "irc" }, }; static const struct Formatter *parseFormatter(const char *name) { @@ -87,18 +88,35 @@ debugFormat(const char *opts[], enum Class class, const char *text) { const struct Formatter FormatDebug = { .format = debugFormat }; +static char *const OptionKeys[OptionCap + 1] = { +#define X(option, key) [option] = key, + ENUM_OPTION +#undef X + NULL, +}; + int main(int argc, char *argv[]) { bool text = false; const char *name = NULL; const struct Lexer *lexer = NULL; const struct Formatter *formatter = &FormatANSI; + const char *opts[OptionCap] = {0}; - for (int opt; 0 < (opt = getopt(argc, argv, "f:l:n:t"));) { + for (int opt; 0 < (opt = getopt(argc, argv, "f:l:n:o:t"));) { switch (opt) { break; case 'f': formatter = parseFormatter(optarg); break; case 'l': lexer = parseLexer(optarg); break; case 'n': name = optarg; + break; case 'o': { + while (*optarg) { + char *val; + int key = getsubopt(&optarg, OptionKeys, &val); + if (key < 0) errx(EX_USAGE, "no such option %s", val); + opts[key] = (val ? val : ""); + } + } break; case 't': text = true; + break; default: return EX_USAGE; } } @@ -122,10 +140,10 @@ int main(int argc, char *argv[]) { if (!lexer) errx(EX_USAGE, "cannot infer lexer for %s", name); *lexer->in = file; - if (formatter->header) formatter->header(NULL); + if (formatter->header) formatter->header(opts); for (enum Class class; None != (class = lexer->lex());) { assert(class < ClassCap); - formatter->format(NULL, class, *lexer->text); + formatter->format(opts, class, *lexer->text); } - if (formatter->footer) formatter->footer(NULL); + if (formatter->footer) formatter->footer(opts); } -- cgit 1.4.1 ref='/src/log/etc/tf?id=4ee4b6ee965e37c3a7375d7a296e143faf1faee0&showmsg=1&follow=1'>tf/cfg/engineer.cfg (unfollow)
Commit message (Collapse)Author
2018-09-02Install bc(1) on ArchJune McEnroe
2018-09-02SendEnv LANGJune McEnroe
2018-08-27Add New Order — TemptationJune McEnroe
2018-08-26Add NetBSD to install.shJune McEnroe
2018-08-24Show hostname in title over SSHJune McEnroe
2018-08-23Alias bc='bc -l'June McEnroe
2018-08-20Update usage of scheme in READMEJune McEnroe
2018-08-20Use scheme.h in fbatt and fbclockJune McEnroe
2018-08-20Generate scheme.hJune McEnroe
2018-08-20Add dependencies on gfx.hJune McEnroe
2018-08-18Add Blondie — Heart of GlassJune McEnroe
Why didn't I know about this song? I love it.
2018-08-18Set FCEDIT=$EDITORJune McEnroe
2018-08-18Only post commits with bodies to MastodonJune McEnroe
2018-08-18Run tf/cfg link script with /bin/shJune McEnroe
2018-08-18Run {,s,t}up with /bin/shJune McEnroe
2018-08-18Use whence instead of typeJune McEnroe
type is an alias for whence -v and is more for human consumption.
2018-08-18Cut off path components until right prompt fitsJune McEnroe
Keeps paths valid (from somehwere) rather than abrupt truncation.
2018-08-17Add "private" alias to source encrypted fileJune McEnroe
Why is there no easy way to *edit* an encrypted file?
2018-08-17Add vim mapping to add a #includeJune McEnroe