From f96fa66168827cc7db7fbd6415f00734dad93e17 Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sat, 12 Mar 2016 14:28:17 +0100 Subject: degesch: add a --format switch --- NEWS | 2 ++ degesch.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/NEWS b/NEWS index 047c527..170e0d5 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,8 @@ * degesch: M-! and M-@ to go to the next buffer in order with a highlight or new activity respectively + * degesch: added --format for previewing things like MOTD files + * kike: add support for IRCv3.2 server-time * ZyklonB: plugins now run in a dedicated data directory diff --git a/degesch.c b/degesch.c index fcff422..4befc02 100644 --- a/degesch.c +++ b/degesch.c @@ -12803,6 +12803,21 @@ show_logo (struct app_context *ctx) log_global_indent (ctx, "#m", g_logo[i]); } +static void +format_input_and_die (struct app_context *ctx) +{ + char buf[513]; + while (fgets (buf, sizeof buf, stdin)) + { + struct formatter f; + formatter_init (&f, ctx, NULL); + formatter_add (&f, "#m", buf); + formatter_flush (&f, stdout, false); + formatter_free (&f); + } + exit (EXIT_SUCCESS); +} + int main (int argc, char *argv[]) { @@ -12814,11 +12829,14 @@ main (int argc, char *argv[]) { { 'h', "help", NULL, 0, "display this help and exit" }, { 'V', "version", NULL, 0, "output version information and exit" }, + // This is mostly intended for previewing formatted MOTD files + { 'f', "format", NULL, OPT_LONG_ONLY, "format IRC text from stdin" }, { 0, NULL, NULL, 0, NULL } }; struct opt_handler oh; opt_handler_init (&oh, argc, argv, opts, NULL, "Experimental IRC client."); + bool format_mode = false; int c; while ((c = opt_handler_get (&oh)) != -1) @@ -12830,6 +12848,9 @@ main (int argc, char *argv[]) case 'V': printf (PROGRAM_NAME " " PROGRAM_VERSION "\n"); exit (EXIT_SUCCESS); + case 'f': + format_mode = true; + break; default: print_error ("wrong options"); opt_handler_usage (&oh, stderr); @@ -12855,6 +12876,7 @@ main (int argc, char *argv[]) // The following part is a bit brittle because of interdependencies init_colors (&ctx); + if (format_mode) format_input_and_die (&ctx); init_global_buffer (&ctx); show_logo (&ctx); setup_signal_handlers (); -- cgit v1.2.3-70-g09d2