From cce23613a7c9afdb7addf522500b72ba52310be0 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sat, 9 Nov 2013 08:55:57 +0100 Subject: [PATCH] core: display lines waiting for buffer on exit (in case of early exit) --- src/core/weechat.c | 12 +++++++----- src/gui/gui-chat.c | 15 ++++++++++++--- src/gui/gui-chat.h | 2 +- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/core/weechat.c b/src/core/weechat.c index e7a6d030a..d590e41b1 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -390,6 +390,8 @@ weechat_welcome_message () void weechat_shutdown (int return_code, int crash) { + gui_chat_print_lines_waiting_buffer (stderr); + if (weechat_argv0) free (weechat_argv0); if (weechat_home) @@ -444,16 +446,16 @@ main (int argc, char *argv[]) gui_key_init (); /* init keys */ network_init_gcrypt (); /* init gcrypt */ if (!secure_init ()) /* init secured data options (sec.*)*/ - exit (EXIT_FAILURE); + weechat_shutdown (EXIT_FAILURE, 0); if (!config_weechat_init ()) /* init WeeChat options (weechat.*) */ - exit (EXIT_FAILURE); + weechat_shutdown (EXIT_FAILURE, 0); weechat_parse_args (argc, argv); /* parse command line args */ weechat_create_home_dir (); /* create WeeChat home directory */ log_init (); /* init log file */ if (secure_read () < 0) /* read secured data options */ - exit (EXIT_FAILURE); + weechat_shutdown (EXIT_FAILURE, 0); if (config_weechat_read () < 0) /* read WeeChat options */ - exit (EXIT_FAILURE); + weechat_shutdown (EXIT_FAILURE, 0); network_init_gnutls (); /* init GnuTLS */ gui_main_init (); /* init WeeChat interface */ if (weechat_upgrading) @@ -462,7 +464,7 @@ main (int argc, char *argv[]) weechat_upgrade_count++; /* increase /upgrade count */ } weechat_welcome_message (); /* display WeeChat welcome message */ - gui_chat_print_lines_waiting_buffer (); /* print lines waiting for buf. */ + gui_chat_print_lines_waiting_buffer (NULL); /* display lines waiting */ command_startup (0); /* command executed before plugins */ plugin_init (weechat_auto_load_plugins, /* init plugin interface(s) */ argc, argv); diff --git a/src/gui/gui-chat.c b/src/gui/gui-chat.c index e45396acd..2391c15f3 100644 --- a/src/gui/gui-chat.c +++ b/src/gui/gui-chat.c @@ -24,6 +24,7 @@ #endif #include +#include #include #include #include @@ -907,11 +908,16 @@ gui_chat_printf_y (struct t_gui_buffer *buffer, int y, const char *message, ...) } /* - * Prints lines that are waiting for buffer. + * Displays lines that are waiting for buffer. + * + * If "f" is not NULL, the lines are written in this file (which is commonly + * stdout or stderr). + * If "f" is NULL, the lines are displayed in core buffer if the GUI is + * initialized (gui_init_ok == 1), otherwise on stdout. */ void -gui_chat_print_lines_waiting_buffer () +gui_chat_print_lines_waiting_buffer (FILE *f) { char **lines; int num_lines, i; @@ -924,7 +930,10 @@ gui_chat_print_lines_waiting_buffer () { for (i = 0; i < num_lines; i++) { - gui_chat_printf (NULL, "%s", lines[i]); + if (!f && gui_init_ok) + gui_chat_printf (NULL, "%s", lines[i]); + else + string_iconv_fprintf ((f) ? f : stdout, "%s\n", lines[i]); } string_free_split (lines); } diff --git a/src/gui/gui-chat.h b/src/gui/gui-chat.h index 80ec2c622..9e6f65fc7 100644 --- a/src/gui/gui-chat.h +++ b/src/gui/gui-chat.h @@ -87,7 +87,7 @@ extern void gui_chat_printf_date_tags (struct t_gui_buffer *buffer, const char *message, ...); extern void gui_chat_printf_y (struct t_gui_buffer *buffer, int y, const char *message, ...); -extern void gui_chat_print_lines_waiting_buffer (); +extern void gui_chat_print_lines_waiting_buffer (FILE *f); extern int gui_chat_hsignal_quote_line_cb (void *data, const char *signal, struct t_hashtable *hashtable); extern void gui_chat_end ();