diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2016-03-12 14:28:17 +0100 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2016-03-12 14:28:17 +0100 |
commit | f96fa66168827cc7db7fbd6415f00734dad93e17 (patch) | |
tree | 434355a998519d20aebfe1af10d6d4a3dc9545f7 | |
parent | 781a37c15209335369e3ff153f5589e855ed7ca9 (diff) | |
download | xK-f96fa66168827cc7db7fbd6415f00734dad93e17.tar.gz xK-f96fa66168827cc7db7fbd6415f00734dad93e17.tar.xz xK-f96fa66168827cc7db7fbd6415f00734dad93e17.zip |
degesch: add a --format switch
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | degesch.c | 22 |
2 files changed, 24 insertions, 0 deletions
@@ -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 @@ -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 (); |