1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-02 07:46:38 +02:00

core: move main() function into Curses GUI

This commit is contained in:
Sébastien Helleu
2014-06-15 09:36:24 +02:00
parent 1f65f80db4
commit 9935b336ed
11 changed files with 161 additions and 105 deletions
+10 -1
View File
@@ -6076,7 +6076,16 @@ COMMAND_CALLBACK(upgrade)
}
}
if (!ptr_binary && !quit)
ptr_binary = strdup (weechat_argv0);
{
ptr_binary = (weechat_argv0) ? strdup (weechat_argv0) : NULL;
if (!ptr_binary)
{
gui_chat_printf (NULL,
_("%sNo binary specified"),
gui_chat_prefix[GUI_CHAT_PREFIX_ERROR]);
return WEECHAT_RC_OK;
}
}
if (!ptr_binary && !quit)
{
+66 -15
View File
@@ -162,7 +162,7 @@ weechat_parse_args (int argc, char *argv[])
{
int i;
weechat_argv0 = strdup (argv[0]);
weechat_argv0 = (argv && argv[0]) ? strdup (argv[0]) : NULL;
weechat_upgrading = 0;
weechat_home = NULL;
weechat_server_cmd_line = 0;
@@ -429,6 +429,42 @@ weechat_term_check ()
}
}
/*
* Callback for system signal SIGHUP: quits WeeChat.
*/
void
weechat_sighup ()
{
log_printf (_("Signal %s received, exiting WeeChat..."), "SIGHUP");
(void) hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL);
weechat_quit = 1;
}
/*
* Callback for system signal SIGQUIT: quits WeeChat.
*/
void
weechat_sigquit ()
{
log_printf (_("Signal %s received, exiting WeeChat..."), "SIGQUIT");
(void) hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL);
weechat_quit = 1;
}
/*
* Callback for system signal SIGTERM: quits WeeChat.
*/
void
weechat_sigterm ()
{
log_printf (_("Signal %s received, exiting WeeChat..."), "SIGTERM");
(void) hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL);
weechat_quit = 1;
}
/*
* Shutdowns WeeChat.
*/
@@ -455,11 +491,11 @@ weechat_shutdown (int return_code, int crash)
}
/*
* Entry point for WeeChat.
* Initializes WeeChat.
*/
int
main (int argc, char *argv[])
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);
@@ -478,15 +514,20 @@ main (int argc, char *argv[])
#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 */
/* 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_main_pre_init (&argc, &argv); /* pre-initialize interface */
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 */
@@ -502,7 +543,10 @@ main (int argc, char *argv[])
secure_read (); /* read secured data options */
config_weechat_read (); /* read WeeChat options */
network_init_gnutls (); /* init GnuTLS */
gui_main_init (); /* init WeeChat interface */
if (gui_init_cb)
(*gui_init_cb) (); /* init WeeChat interface */
if (weechat_upgrading)
{
upgrade_weechat_load (); /* upgrade with session file */
@@ -519,15 +563,24 @@ main (int argc, char *argv[])
gui_layout_window_apply (gui_layout_current, -1);
if (weechat_upgrading)
upgrade_weechat_end (); /* remove .upgrade files + signal */
}
gui_main_loop (); /* WeeChat main loop */
/*
* Ends WeeChat.
*/
void
weechat_end (void (*gui_end_cb)(int clean_exit))
{
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 */
if (gui_end_cb)
(*gui_end_cb) (1); /* shut down WeeChat GUI */
proxy_free_all (); /* free all proxies */
config_weechat_free (); /* free WeeChat options */
secure_free (); /* free secured data options */
@@ -538,6 +591,4 @@ main (int argc, char *argv[])
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 */
}
+2
View File
@@ -108,5 +108,7 @@ extern char *weechat_startup_commands;
extern void weechat_term_check ();
extern void weechat_shutdown (int return_code, int crash);
extern void weechat_init (int argc, char *argv[], void (*gui_init_cb)());
extern void weechat_end (void (*gui_end_cb)(int clean_exit));
#endif /* WEECHAT_H */
+11 -4
View File
@@ -19,7 +19,7 @@
# along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
#
set(WEECHAT_CURSES_SRC
set(LIB_GUI_CURSES_SRC
gui-curses.h
gui-curses-bar-window.c
gui-curses-chat.c
@@ -30,6 +30,9 @@ gui-curses-mouse.c
gui-curses-term.c
gui-curses-window.c)
set(WEECHAT_CURSES_MAIN_SRC
main.c)
set(EXECUTABLE weechat)
find_package(Ncurses)
@@ -70,12 +73,16 @@ list(APPEND EXTRA_LIBS "m")
list(APPEND EXTRA_LIBS ${CURL_LIBRARIES})
add_executable(${EXECUTABLE} ${WEECHAT_CURSES_SRC})
include_directories(.. ../../core ../../plugins ${NCURSES_INCLUDE_PATH})
add_library(weechat_gui_curses STATIC ${LIB_GUI_CURSES_SRC})
add_executable(${EXECUTABLE} ${WEECHAT_CURSES_MAIN_SRC})
add_dependencies(${EXECUTABLE} weechat_gui_curses)
# Because of a linker bug, we have to link 2 times with libweechat_core.a
target_link_libraries(${EXECUTABLE} ${STATIC_LIBS} ${EXTRA_LIBS} ${STATIC_LIBS})
target_link_libraries(${EXECUTABLE} ${STATIC_LIBS} ${EXTRA_LIBS} ${STATIC_LIBS} weechat_gui_curses)
install(TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin)
+2 -17
View File
@@ -1481,26 +1481,11 @@ gui_color_init_weechat ()
}
/*
* Pre-initializes colors.
* Allocates GUI colors.
*/
void
gui_color_pre_init ()
{
int i;
for (i = 0; i < GUI_COLOR_NUM_COLORS; i++)
{
gui_color[i] = NULL;
}
}
/*
* Initializes GUI colors.
*/
void
gui_color_init ()
gui_color_alloc ()
{
if (has_colors())
{
+1 -63
View File
@@ -122,24 +122,6 @@ gui_main_get_password (const char *prompt1, const char *prompt2,
endwin ();
}
/*
* Pre-initializes GUI (called before gui_init).
*/
void
gui_main_pre_init (int *argc, char **argv[])
{
/* make C compiler happy */
(void) argc;
(void) argv;
/* pre-init colors */
gui_color_pre_init ();
/* init some variables for chat area */
gui_chat_init ();
}
/*
* Initializes GUI.
*/
@@ -162,7 +144,7 @@ gui_main_init ()
nodelay (stdscr, TRUE);
raw ();
gui_color_init ();
gui_color_alloc ();
/* build prefixes according to configuration */
gui_chat_prefix_build ();
@@ -246,45 +228,6 @@ gui_main_init ()
gui_window_set_bracketed_paste_mode (CONFIG_BOOLEAN(config_look_paste_bracketed));
}
/*
* Callback for system signal SIGQUIT: quits WeeChat.
*/
void
gui_main_signal_sigquit ()
{
log_printf (_("Signal %s received, exiting WeeChat..."),
"SIGQUIT");
(void) hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL);
weechat_quit = 1;
}
/*
* Callback for system signal SIGTERM: quits WeeChat.
*/
void
gui_main_signal_sigterm ()
{
log_printf (_("Signal %s received, exiting WeeChat..."),
"SIGTERM");
(void) hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL);
weechat_quit = 1;
}
/*
* Callback for system signal SIGHUP: quits WeeChat.
*/
void
gui_main_signal_sighup ()
{
log_printf (_("Signal %s received, exiting WeeChat..."),
"SIGHUP");
(void) hook_signal_send ("quit", WEECHAT_HOOK_SIGNAL_STRING, NULL);
weechat_quit = 1;
}
/*
* Callback for system signal SIGWINCH: refreshes screen.
*/
@@ -432,11 +375,6 @@ gui_main_loop ()
int max_fd;
int ready;
/* catch SIGTERM/SIGQUIT/SIGHUP signals: quit program */
util_catch_signal (SIGTERM, &gui_main_signal_sigterm);
util_catch_signal (SIGQUIT, &gui_main_signal_sigquit);
util_catch_signal (SIGHUP, &gui_main_signal_sighup);
/* catch SIGWINCH signal: redraw screen */
util_catch_signal (SIGWINCH, &gui_main_signal_sigwinch);
+6 -2
View File
@@ -31,6 +31,7 @@
#endif
struct t_gui_buffer;
struct t_gui_line;
struct t_gui_window;
struct t_gui_bar_window;
@@ -80,12 +81,15 @@ extern time_t gui_color_pairs_auto_reset_last;
extern int gui_color_buffer_refresh_needed;
extern int gui_window_current_emphasis;
/* main functions */
extern void gui_main_init ();
extern void gui_main_loop ();
/* color functions */
extern int gui_color_get_extended_attrs (int color);
extern int gui_color_get_pair (int fg, int bg);
extern int gui_color_weechat_get_pair (int weechat_color);
extern void gui_color_pre_init ();
extern void gui_color_init ();
extern void gui_color_alloc ();
/* chat functions */
extern void gui_chat_calculate_line_diff (struct t_gui_window *window,
+46
View File
@@ -0,0 +1,46 @@
/*
* main.c - entry point for Curses GUI
*
* Copyright (C) 2003-2014 Sébastien Helleu <flashcode@flashtux.org>
*
* This file is part of WeeChat, the extensible chat client.
*
* WeeChat is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* WeeChat is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with WeeChat. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include "../../core/weechat.h"
#include "../gui-main.h"
#include "gui-curses.h"
/*
* Entry point for WeeChat (Curses GUI).
*/
int
main (int argc, char *argv[])
{
weechat_init (argc, argv, &gui_main_init);
gui_main_loop ();
weechat_end (&gui_main_end);
/* make C compiler happy (never executed) */
return EXIT_SUCCESS;
}
+16
View File
@@ -1274,6 +1274,21 @@ gui_color_palette_free_structs ()
weelist_free (gui_color_list_with_alias);
}
/*
* Initializes colors.
*/
void
gui_color_init ()
{
int i;
for (i = 0; i < GUI_COLOR_NUM_COLORS; i++)
{
gui_color[i] = NULL;
}
}
/*
* Ends GUI colors.
*/
@@ -1286,6 +1301,7 @@ gui_color_end ()
for (i = 0; i < GUI_COLOR_NUM_COLORS; i++)
{
gui_color_free (gui_color[i]);
gui_color[i] = NULL;
}
gui_color_palette_free_structs ();
gui_color_free_vars ();
+1
View File
@@ -187,6 +187,7 @@ extern int gui_color_palette_get_alias (const char *alias);
extern struct t_gui_color_palette *gui_color_palette_get (int number);
extern void gui_color_palette_add (int number, const char *value);
extern void gui_color_palette_remove (int number);
extern void gui_color_init ();
extern void gui_color_end ();
/* color functions (GUI dependent) */
-3
View File
@@ -26,9 +26,6 @@ extern void gui_main_get_password (const char *prompt1, const char *prompt2,
const char *prompt3,
char *password, int size);
extern void gui_main_debug_libs ();
extern void gui_main_loop ();
extern void gui_main_pre_init (int *argc, char **argv[]);
extern void gui_main_init ();
extern void gui_main_end (int clean_exit);
/* terminal functions (GUI dependent) */