void weechat_init (int argc, char *argv[], void (*gui_init_cb)()) { weechat_first_start_time = time (NULL); /* initialize start time */ gettimeofday (&weechat_current_start_timeval, NULL); /* catch signals */ util_catch_signal (SIGINT, SIG_IGN); /* signal ignored */ util_catch_signal (SIGPIPE, SIG_IGN); /* signal ignored */ util_catch_signal (SIGSEGV, &debug_sigsegv); /* crash dump */ util_catch_signal (SIGHUP, &weechat_sighup); /* exit WeeChat */ util_catch_signal (SIGQUIT, &weechat_sigquit); /* exit WeeChat */ util_catch_signal (SIGTERM, &weechat_sigterm); /* exit WeeChat */ hdata_init (); /* initialize hdata */ hook_init (); /* initialize hooks */ debug_init (); /* hook signals for debug */ gui_color_init (); /* initialize colors */ gui_chat_init (); /* initialize chat */ command_init (); /* initialize WeeChat commands */ completion_init (); /* add core completion hooks */ gui_key_init (); /* init keys */ network_init_gcrypt (); /* init gcrypt */ if (!secure_init ()) /* init secured data options (sec.*)*/ weechat_shutdown (EXIT_FAILURE, 0); if (!config_weechat_init ()) /* init WeeChat options (weechat.*) */ 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 */ plugin_api_init (); /* create some hooks (info,hdata,..)*/ secure_read (); /* read secured data options */ config_weechat_read (); /* read WeeChat options */ network_init_gnutls (); /* init GnuTLS */ if (gui_init_cb) (*gui_init_cb) (); /* init WeeChat interface */ if (weechat_upgrading) { upgrade_weechat_load (); /* upgrade with session file */ weechat_upgrade_count++; /* increase /upgrade count */ } weechat_startup_message (); /* display WeeChat startup message */ gui_chat_print_lines_waiting_buffer (NULL); /* display lines waiting */ weechat_term_check (); /* warning about wrong $TERM */ weechat_locale_check (); /* warning about wrong locale */ command_startup (0); /* command executed before plugins */ plugin_init (weechat_force_plugin_autoload, /* init plugin interface(s) */ argc, argv); command_startup (1); /* commands executed after plugins */ if (!weechat_upgrading) gui_layout_window_apply (gui_layout_current, -1); if (weechat_upgrading) upgrade_weechat_end (); /* remove .upgrade files + signal */ }
void gui_main_loop () { struct t_hook *hook_fd_keyboard; /* catch SIGWINCH signal: redraw screen */ util_catch_signal (SIGWINCH, &gui_main_signal_sigwinch); /* hook stdin (read keyboard) */ hook_fd_keyboard = hook_fd (NULL, STDIN_FILENO, 1, 0, 0, &gui_key_read_cb, NULL); gui_window_ask_refresh (1); while (!dogechat_quit) { /* execute timer hooks */ hook_timer_exec (); /* auto reset of color pairs */ if (gui_color_pairs_auto_reset) { gui_color_reset_pairs (); gui_color_pairs_auto_reset_last = time (NULL); gui_color_pairs_auto_reset = 0; gui_color_pairs_auto_reset_pending = 1; } gui_main_refreshs (); if (gui_window_refresh_needed && !gui_window_bare_display) gui_main_refreshs (); if (gui_signal_sigwinch_received) { (void) hook_signal_send ("signal_sigwinch", DOGECHAT_HOOK_SIGNAL_STRING, NULL); gui_signal_sigwinch_received = 0; } gui_color_pairs_auto_reset_pending = 0; /* execute fd hooks */ hook_fd_exec (); } /* remove keyboard hook */ unhook (hook_fd_keyboard); }
void gui_main_loop () { struct t_hook *hook_fd_keyboard; struct timeval tv_timeout; fd_set read_fds, write_fds, except_fds; int max_fd; int ready; /* catch SIGTERM signal: quit program */ util_catch_signal (SIGTERM, &gui_main_signal_sigterm); util_catch_signal (SIGQUIT, &gui_main_signal_sigquit); /* catch SIGHUP signal: reload configuration */ util_catch_signal (SIGHUP, &gui_main_signal_sighup); /* catch SIGWINCH signal: redraw screen */ util_catch_signal (SIGWINCH, &gui_main_signal_sigwinch); /* hook stdin (read keyboard) */ hook_fd_keyboard = hook_fd (NULL, STDIN_FILENO, 1, 0, 0, &gui_key_read_cb, NULL); gui_window_ask_refresh (1); while (!weechat_quit) { /* reload config, if SIGHUP received */ if (gui_reload_config) { gui_reload_config = 0; log_printf (_("Signal SIGHUP received, reloading configuration " "files")); command_reload (NULL, NULL, 0, NULL, NULL); } /* execute hook timers */ hook_timer_exec (); /* auto reset of color pairs */ if (gui_color_pairs_auto_reset) { gui_color_reset_pairs (); gui_color_pairs_auto_reset_last = time (NULL); gui_color_pairs_auto_reset = 0; gui_color_pairs_auto_reset_pending = 1; } gui_main_refreshs (); if (gui_window_refresh_needed && !gui_window_bare_display) gui_main_refreshs (); if (gui_signal_sigwinch_received) { (void) hook_signal_send ("signal_sigwinch", WEECHAT_HOOK_SIGNAL_STRING, NULL); gui_signal_sigwinch_received = 0; } gui_color_pairs_auto_reset_pending = 0; /* wait for keyboard or network activity */ FD_ZERO (&read_fds); FD_ZERO (&write_fds); FD_ZERO (&except_fds); max_fd = hook_fd_set (&read_fds, &write_fds, &except_fds); hook_timer_time_to_next (&tv_timeout); ready = select (max_fd + 1, &read_fds, &write_fds, &except_fds, &tv_timeout); if (ready > 0) { hook_fd_exec (&read_fds, &write_fds, &except_fds); } } /* remove keyboard hook */ unhook (hook_fd_keyboard); }
void weechat_init (int argc, char *argv[], void (*gui_init_cb)()) { weechat_first_start_time = time (NULL); /* initialize start time */ gettimeofday (&weechat_current_start_timeval, NULL); weechat_locale_ok = (setlocale (LC_ALL, "") != NULL); /* init gettext */ #ifdef ENABLE_NLS bindtextdomain (PACKAGE, LOCALEDIR); bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); #endif #ifdef HAVE_LANGINFO_CODESET weechat_local_charset = strdup (nl_langinfo (CODESET)); #else weechat_local_charset = strdup (""); #endif utf8_init (); /* catch signals */ util_catch_signal (SIGINT, SIG_IGN); /* signal ignored */ util_catch_signal (SIGQUIT, SIG_IGN); /* signal ignored */ util_catch_signal (SIGPIPE, SIG_IGN); /* signal ignored */ util_catch_signal (SIGSEGV, &debug_sigsegv); /* crash dump */ util_catch_signal (SIGHUP, &weechat_sighup); /* exit WeeChat */ util_catch_signal (SIGQUIT, &weechat_sigquit); /* exit WeeChat */ util_catch_signal (SIGTERM, &weechat_sigterm); /* exit WeeChat */ hdata_init (); /* initialize hdata */ hook_init (); /* initialize hooks */ debug_init (); /* hook signals for debug */ gui_color_init (); /* initialize colors */ gui_chat_init (); /* initialize chat */ command_init (); /* initialize WeeChat commands */ completion_init (); /* add core completion hooks */ gui_key_init (); /* init keys */ network_init_gcrypt (); /* init gcrypt */ if (!secure_init ()) /* init secured data options (sec.*)*/ weechat_shutdown (EXIT_FAILURE, 0); if (!config_weechat_init ()) /* init WeeChat options (weechat.*) */ 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 */ plugin_api_init (); /* create some hooks (info,hdata,..)*/ secure_read (); /* read secured data options */ config_weechat_read (); /* read WeeChat options */ network_init_gnutls (); /* init GnuTLS */ if (gui_init_cb) (*gui_init_cb) (); /* init WeeChat interface */ if (weechat_upgrading) { upgrade_weechat_load (); /* upgrade with session file */ weechat_upgrade_count++; /* increase /upgrade count */ } weechat_welcome_message (); /* display WeeChat welcome message */ gui_chat_print_lines_waiting_buffer (NULL); /* display lines waiting */ weechat_term_check (); /* warnings about $TERM (if wrong) */ weechat_locale_check (); /* warning about wrong locale */ command_startup (0); /* command executed before plugins */ plugin_init (weechat_auto_load_plugins, /* init plugin interface(s) */ argc, argv); command_startup (1); /* commands executed after plugins */ if (!weechat_upgrading) gui_layout_window_apply (gui_layout_current, -1); if (weechat_upgrading) upgrade_weechat_end (); /* remove .upgrade files + signal */ }
int main (int argc, char *argv[]) { weechat_first_start_time = time (NULL); /* initialize start time */ gettimeofday (&weechat_current_start_timeval, NULL); setlocale (LC_ALL, ""); /* initialize gettext */ #ifdef ENABLE_NLS bindtextdomain (PACKAGE, LOCALEDIR); bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); #endif #ifdef HAVE_LANGINFO_CODESET weechat_local_charset = strdup (nl_langinfo (CODESET)); #else weechat_local_charset = strdup (""); #endif utf8_init (); util_catch_signal (SIGINT, SIG_IGN); /* ignore SIGINT signal */ util_catch_signal (SIGQUIT, SIG_IGN); /* ignore SIGQUIT signal */ util_catch_signal (SIGPIPE, SIG_IGN); /* ignore SIGPIPE signal */ util_catch_signal (SIGSEGV, &debug_sigsegv); /* crash dump for SIGSEGV signal */ hdata_init (); /* initialize hdata */ hook_init (); /* initialize hooks */ debug_init (); /* hook signals for debug */ gui_main_pre_init (&argc, &argv); /* pre-initialize interface */ command_init (); /* initialize WeeChat commands */ completion_init (); /* add core completion hooks */ gui_key_init (); /* init keys */ network_init_gcrypt (); /* init gcrypt */ if (!secure_init ()) /* init secured data options (sec.*)*/ weechat_shutdown (EXIT_FAILURE, 0); if (!config_weechat_init ()) /* init WeeChat options (weechat.*) */ 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 */ plugin_api_init (); /* create some hooks (info,hdata,..)*/ secure_read (); /* read secured data options */ config_weechat_read (); /* read WeeChat options */ network_init_gnutls (); /* init GnuTLS */ gui_main_init (); /* init WeeChat interface */ if (weechat_upgrading) { upgrade_weechat_load (); /* upgrade with session file */ weechat_upgrade_count++; /* increase /upgrade count */ } weechat_welcome_message (); /* display WeeChat welcome message */ 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); command_startup (1); /* commands executed after plugins */ if (!weechat_upgrading) gui_layout_window_apply (gui_layout_current, -1); if (weechat_upgrading) upgrade_weechat_end (); /* remove .upgrade files + signal */ gui_main_loop (); /* WeeChat main loop */ gui_layout_store_on_exit (); /* store layout */ plugin_end (); /* end plugin interface(s) */ if (CONFIG_BOOLEAN(config_look_save_config_on_exit)) (void) config_weechat_write (); /* save WeeChat config file */ (void) secure_write (); /* save secured data */ gui_main_end (1); /* shut down WeeChat GUI */ proxy_free_all (); /* free all proxies */ config_weechat_free (); /* free WeeChat options */ secure_free (); /* free secured data options */ config_file_free_all (); /* free all configuration files */ gui_key_end (); /* remove all keys */ unhook_all (); /* remove all hooks */ hdata_end (); /* end hdata */ secure_end (); /* end secured data */ string_end (); /* end string */ weechat_shutdown (EXIT_SUCCESS, 0); /* quit WeeChat (oh no, why?) */ return EXIT_SUCCESS; /* make C compiler happy */ }