summaryrefslogtreecommitdiff
path: root/src/core/weechat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/weechat.c')
-rw-r--r--src/core/weechat.c61
1 files changed, 46 insertions, 15 deletions
diff --git a/src/core/weechat.c b/src/core/weechat.c
index 6d89679a4..f74598ad5 100644
--- a/src/core/weechat.c
+++ b/src/core/weechat.c
@@ -17,7 +17,7 @@
*
* weechat.c - WeeChat main functions
*
- * Copyright (C) 2003-2017 Sébastien Helleu <flashcode@flashtux.org>
+ * Copyright (C) 2003-2018 Sébastien Helleu <flashcode@flashtux.org>
*
* This file is part of WeeChat, the extensible chat client.
*
@@ -79,6 +79,7 @@
#include "../plugins/plugin-api.h"
+int weechat_headless = 0; /* 1 if running headless (no GUI) */
int weechat_debug_core = 0; /* debug level for core */
char *weechat_argv0 = NULL; /* WeeChat binary file name (argv[0])*/
int weechat_upgrading = 0; /* =1 if WeeChat is upgrading */
@@ -87,7 +88,7 @@ time_t weechat_first_start_time = 0; /* start time (used by /uptime cmd) */
int weechat_upgrade_count = 0; /* number of /upgrade done */
struct timeval weechat_current_start_timeval; /* start time used to display */
/* duration of /upgrade */
-int weechat_quit = 0; /* = 1 if quit request from user */
+volatile sig_atomic_t weechat_quit = 0; /* = 1 if quit request from user */
volatile sig_atomic_t weechat_quit_signal = 0; /* signal received, */
/* WeeChat must quit */
char *weechat_home = NULL; /* home dir. (default: ~/.weechat) */
@@ -131,13 +132,13 @@ weechat_display_copyright ()
*/
void
-weechat_display_usage (char *exec_name)
+weechat_display_usage ()
{
weechat_display_copyright ();
string_fprintf (stdout, "\n");
string_fprintf (stdout,
_("Usage: %s [option...] [plugin:option...]\n"),
- exec_name, exec_name);
+ weechat_argv0);
string_fprintf (stdout, "\n");
string_fprintf (
stdout,
@@ -159,7 +160,22 @@ weechat_display_usage (char *exec_name)
"(see /help upgrade in WeeChat)\n"
" -v, --version display WeeChat version\n"
" plugin:option option for plugin (see man weechat)\n"));
- string_fprintf(stdout, "\n");
+ string_fprintf (stdout, "\n");
+
+ /* extra options in headless mode */
+ if (weechat_headless)
+ {
+ string_fprintf (stdout, _("Extra options in headless mode:\n"));
+ string_fprintf (
+ stdout,
+ _(" --daemon run WeeChat as a daemon (fork, "
+ "new process group, file descriptors closed);\n"));
+ string_fprintf (
+ stdout,
+ _(" (by default in headless mode "
+ "WeeChat is blocking and does not run in background)\n"));
+ string_fprintf (stdout, "\n");
+ }
}
/*
@@ -173,7 +189,7 @@ weechat_parse_args (int argc, char *argv[])
{
int i;
- weechat_argv0 = (argv && argv[0]) ? strdup (argv[0]) : NULL;
+ weechat_argv0 = (argv[0]) ? strdup (argv[0]) : NULL;
weechat_upgrading = 0;
weechat_home = NULL;
weechat_server_cmd_line = 0;
@@ -208,7 +224,7 @@ weechat_parse_args (int argc, char *argv[])
else if ((strcmp (argv[i], "-h") == 0)
|| (strcmp (argv[i], "--help") == 0))
{
- weechat_display_usage (argv[0]);
+ weechat_display_usage ();
weechat_shutdown (EXIT_SUCCESS, 0);
}
else if ((strcmp (argv[i], "-l") == 0)
@@ -403,6 +419,14 @@ weechat_create_home_dir ()
void
weechat_startup_message ()
{
+ if (weechat_headless)
+ {
+ string_fprintf (stdout,
+ _("WeeChat is running in headless mode "
+ "(Ctrl-C to quit)."));
+ string_fprintf (stdout, "\n");
+ }
+
if (CONFIG_BOOLEAN(config_startup_display_logo))
{
gui_chat_printf (
@@ -445,8 +469,7 @@ weechat_startup_message ()
"\n"
"Moreover, there is inline help with /help on all commands and "
"options (use Tab key to complete the name).\n"
- "The command /iset (script iset.pl) can help to customize "
- "WeeChat: /script install iset.pl\n"
+ "The command /fset can help to customize WeeChat.\n"
"\n"
"You can add and connect to an IRC server with /server and "
"/connect commands (see /help server)."));
@@ -595,21 +618,18 @@ weechat_shutdown (int return_code, int crash)
free (weechat_local_charset);
if (crash)
- abort();
+ abort ();
else if (return_code >= 0)
exit (return_code);
}
/*
- * Initializes WeeChat.
+ * Initializes gettext.
*/
void
-weechat_init (int argc, char *argv[], void (*gui_init_cb)())
+weechat_init_gettext ()
{
- 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);
@@ -623,6 +643,17 @@ weechat_init (int argc, char *argv[], void (*gui_init_cb)())
weechat_local_charset = strdup ("");
#endif /* HAVE_LANGINFO_CODESET */
utf8_init ();
+}
+
+/*
+ * Initializes WeeChat.
+ */
+
+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 */