summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/command.c5
-rw-r--r--src/common/fifo.c2
-rw-r--r--src/common/log.c29
-rw-r--r--src/common/session.c4
-rw-r--r--src/common/weechat.c127
-rw-r--r--src/common/weechat.h3
-rw-r--r--src/common/weeconfig.c10
7 files changed, 132 insertions, 48 deletions
diff --git a/src/common/command.c b/src/common/command.c
index c32de5a00..30a4e7935 100644
--- a/src/common/command.c
+++ b/src/common/command.c
@@ -3142,7 +3142,7 @@ weechat_cmd_upgrade (t_irc_server *server, t_irc_channel *channel,
t_irc_server *ptr_server;
int filename_length;
char *filename;
- char *exec_args[5] = { NULL, "-a", "--session", NULL, NULL };
+ char *exec_args[7] = { NULL, "-a", "--dir", NULL, "--session", NULL, NULL };
/* make gcc happy */
(void) server;
@@ -3196,7 +3196,8 @@ weechat_cmd_upgrade (t_irc_server *server, t_irc_channel *channel,
}
exec_args[0] = strdup (weechat_argv0);
- exec_args[3] = strdup (filename);
+ exec_args[3] = strdup (weechat_home);
+ exec_args[5] = strdup (filename);
/* unload plugins, save config, then upgrade */
#ifdef PLUGINS
diff --git a/src/common/fifo.c b/src/common/fifo.c
index 3a69d9c57..f42620fc7 100644
--- a/src/common/fifo.c
+++ b/src/common/fifo.c
@@ -54,7 +54,7 @@ fifo_create ()
if (cfg_irc_fifo_pipe)
{
- /* build FIFO filename: "~/.weechat/weechat_fifo_" + process PID */
+ /* build FIFO filename: "<weechat_home>/weechat_fifo_" + process PID */
if (!weechat_fifo_filename)
{
filename_length = strlen (weechat_home) + 64;
diff --git a/src/common/log.c b/src/common/log.c
index a8c08713c..f6881052e 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -107,29 +107,36 @@ void
log_start (t_gui_buffer *buffer)
{
int length;
- char *ptr_home;
+ char *ptr_home, *log_path, *log_path2, *ptr_path;
ptr_home = getenv ("HOME");
- length = strlen (cfg_log_path) +
- ((cfg_log_path[0] == '~') ? strlen (ptr_home) : 0) +
- 64;
+ log_path = weechat_strreplace (cfg_log_path, "~", ptr_home);
+ log_path2 = weechat_strreplace ((log_path) ?
+ log_path : cfg_log_path,
+ "%h", weechat_home);
+ ptr_path = (log_path2) ? log_path2 : ((log_path) ? log_path : cfg_log_path);
+ length = strlen (ptr_path) + 64;
if (SERVER(buffer))
length += strlen (SERVER(buffer)->name);
if (CHANNEL(buffer))
length += strlen (CHANNEL(buffer)->name);
+
buffer->log_filename = (char *) malloc (length);
if (!buffer->log_filename)
{
weechat_log_printf (_("Not enough memory to write log file for a buffer\n"));
+ if (log_path)
+ free (log_path);
+ if (log_path2)
+ free (log_path2);
return;
}
- if (cfg_log_path[0] == '~')
- {
- strcpy (buffer->log_filename, ptr_home);
- strcat (buffer->log_filename, cfg_log_path + 1);
- }
- else
- strcpy (buffer->log_filename, cfg_log_path);
+
+ strcpy (buffer->log_filename, ptr_path);
+ if (log_path)
+ free (log_path);
+ if (log_path2)
+ free (log_path2);
if (buffer->log_filename[strlen (buffer->log_filename) - 1] != DIR_SEPARATOR_CHAR)
strcat (buffer->log_filename, DIR_SEPARATOR);
diff --git a/src/common/session.c b/src/common/session.c
index 78b253940..8a9e53969 100644
--- a/src/common/session.c
+++ b/src/common/session.c
@@ -474,10 +474,12 @@ session_crash (FILE *file, char *message, ...)
session_last_read_pos,
session_last_read_length);
fprintf (stderr,
- _("Please send ~/.weechat/%s, ~/.weechat/%s and "
+ _("Please send %s/%s, %s/%s and "
"above messages to WeeChat developers for support.\n"
"Be careful, private info may be in these files.\n"),
+ weechat_home,
WEECHAT_LOG_NAME,
+ weechat_home,
WEECHAT_SESSION_NAME);
exit (EXIT_FAILURE);
}
diff --git a/src/common/weechat.c b/src/common/weechat.c
index 4dc6b07ea..0afed0183 100644
--- a/src/common/weechat.c
+++ b/src/common/weechat.c
@@ -166,7 +166,7 @@ ascii_strncasecmp (char *string1, char *string2, int max)
}
/*
- * weechat_log_printf: displays a message in WeeChat log (~/.weechat/weechat.log)
+ * weechat_log_printf: displays a message in WeeChat log (<weechat_home>/weechat.log)
*/
void
@@ -263,6 +263,59 @@ weechat_iconv (char *from_code, char *to_code, char *string)
}
/*
+ * weechat_strreplace: replace a string by new one in a string
+ * note: returned value has to be free() after use
+ */
+
+char *
+weechat_strreplace (char *string, char *search, char *replace)
+{
+ char *pos, *new_string;
+ int length1, length2, length_new, count;
+
+ length1 = strlen (search);
+ length2 = strlen (replace);
+
+ /* count number of strings to replace */
+ count = 0;
+ pos = string;
+ while (pos && pos[0] && (pos = strstr (pos, search)))
+ {
+ count++;
+ pos += length1;
+ }
+
+ /* easy: no string to replace! */
+ if (count == 0)
+ return strdup (string);
+
+ /* compute needed memory for new string */
+ length_new = strlen (string) - (count * length1) + (count * length2) + 1;
+
+ /* allocate new string */
+ new_string = (char *)malloc (length_new * sizeof (char));
+ if (!new_string)
+ return strdup (string);
+
+ /* replace all occurences */
+ new_string[0] = '\0';
+ while (string && string[0])
+ {
+ pos = strstr (string, search);
+ if (pos)
+ {
+ strncat (new_string, string, pos - string);
+ strcat (new_string, replace);
+ pos += length1;
+ }
+ else
+ strcat (new_string, string);
+ string = pos;
+ }
+ return new_string;
+}
+
+/*
* get_timeval_diff: calculates difference between two times (return in milliseconds)
*/
@@ -300,6 +353,7 @@ weechat_display_usage (char *exec_name)
printf ("\n\n");
printf (_(" -a, --no-connect disable auto-connect to servers at startup\n"
" -c, --config display config file options\n"
+ " -d, --dir <path> set WeeChat home directory (default: ~/.weechat)\n"
" -f, --key-functions display WeeChat internal functions for keys\n"
" -h, --help this help\n"
" -i, --irc-commands display IRC commands\n"
@@ -320,7 +374,7 @@ weechat_display_config_options ()
{
int i, j, k;
- printf (_("WeeChat configuration options (~/.weechat/weechat.rc):\n\n"));
+ printf (_("WeeChat configuration options (<weechat_home>/weechat.rc):\n\n"));
for (i = 0; i < CONFIG_NUMBER_SECTIONS; i++)
{
if (weechat_options[i])
@@ -498,6 +552,7 @@ weechat_parse_args (int argc, char *argv[])
weechat_argv0 = strdup (argv[0]);
weechat_session = NULL;
+ weechat_home = NULL;
server_cmd_line = 0;
auto_connect = 1;
auto_load_plugins = 1;
@@ -513,6 +568,19 @@ weechat_parse_args (int argc, char *argv[])
weechat_display_config_options ();
weechat_shutdown (EXIT_SUCCESS, 0);
}
+ else if ((strcmp (argv[i], "-d") == 0)
+ || (strcmp (argv[i], "--dir") == 0))
+ {
+ if (i + 1 < argc)
+ weechat_home = strdup (argv[++i]);
+ else
+ {
+ fprintf (stderr,
+ _("%s missing argument for --dir option\n"),
+ WEECHAT_ERROR);
+ weechat_shutdown (EXIT_FAILURE, 0);
+ }
+ }
else if ((strcmp (argv[i], "-f") == 0)
|| (strcmp (argv[i], "--key-functions") == 0))
{
@@ -634,44 +702,47 @@ weechat_create_home_dirs ()
{
char *ptr_home, *dir_name;
int dir_length;
-
- ptr_home = getenv ("HOME");
- if (!ptr_home)
- {
- fprintf (stderr, _("%s unable to get HOME directory\n"),
- WEECHAT_ERROR);
- weechat_shutdown (EXIT_FAILURE, 0);
- }
- dir_length = strlen (ptr_home) + 10;
- weechat_home =
- (char *) malloc (dir_length * sizeof (char));
+
if (!weechat_home)
{
- fprintf (stderr, _("%s not enough memory for home directory\n"),
- WEECHAT_ERROR);
- weechat_shutdown (EXIT_FAILURE, 0);
+ ptr_home = getenv ("HOME");
+ if (!ptr_home)
+ {
+ fprintf (stderr, _("%s unable to get HOME directory\n"),
+ WEECHAT_ERROR);
+ weechat_shutdown (EXIT_FAILURE, 0);
+ }
+ dir_length = strlen (ptr_home) + 10;
+ weechat_home =
+ (char *) malloc (dir_length * sizeof (char));
+ if (!weechat_home)
+ {
+ fprintf (stderr, _("%s not enough memory for home directory\n"),
+ WEECHAT_ERROR);
+ weechat_shutdown (EXIT_FAILURE, 0);
+ }
+ snprintf (weechat_home, dir_length, "%s%s.weechat", ptr_home,
+ DIR_SEPARATOR);
}
- snprintf (weechat_home, dir_length, "%s%s.weechat", ptr_home,
- DIR_SEPARATOR);
- /* create home directory "~/.weechat" ; error is fatal */
+ /* create home directory; error is fatal */
if (!weechat_create_dir (weechat_home))
{
- fprintf (stderr, _("%s unable to create ~/.weechat directory\n"),
- WEECHAT_ERROR);
+ fprintf (stderr, _("%s unable to create \"%s\" directory\n"),
+ WEECHAT_ERROR, weechat_home);
weechat_shutdown (EXIT_FAILURE, 0);
}
dir_length = strlen (weechat_home) + 64;
dir_name = (char *) malloc (dir_length * sizeof (char));
- /* create "~/.weechat/logs" */
+ /* create "<weechat_home>/logs" */
snprintf (dir_name, dir_length, "%s%s%s", weechat_home, DIR_SEPARATOR,
"logs");
if (!weechat_create_dir (dir_name))
{
- fprintf (stderr, _("%s unable to create ~/.weechat/logs directory\n"),
- WEECHAT_WARNING);
+ fprintf (stderr, _("%s unable to create \"%s\" directory\n"),
+ WEECHAT_WARNING, dir_name);
}
chmod (dir_name, 0700);
@@ -716,8 +787,8 @@ weechat_init_log ()
snprintf (filename, filename_length, "%s/" WEECHAT_LOG_NAME, weechat_home);
if ((weechat_log_file = fopen (filename, "wt")) == NULL)
fprintf (stderr,
- _("%s unable to create/append to log file (~/.weechat/%s)"),
- WEECHAT_WARNING, WEECHAT_LOG_NAME);
+ _("%s unable to create/append to log file (%s/%s)"),
+ WEECHAT_WARNING, weechat_home, WEECHAT_LOG_NAME);
free (filename);
}
@@ -921,7 +992,7 @@ weechat_dump (int crash)
}
/*
- * weechat_sigsegv: SIGSEGV handler: save crash log to ~/.weechat/weechat.log and exit
+ * weechat_sigsegv: SIGSEGV handler: save crash log to <weechat_home>/weechat.log and exit
*/
void
@@ -933,7 +1004,7 @@ weechat_sigsegv ()
gui_end ();
fprintf (stderr, "\n");
fprintf (stderr, "*** Very bad! WeeChat has crashed (SIGSEGV received)\n");
- fprintf (stderr, "*** Full crash dump was saved to ~/.weechat/weechat.log file\n");
+ fprintf (stderr, "*** Full crash dump was saved to %s/weechat.log file\n", weechat_home);
fprintf (stderr, "*** Please send this file to WeeChat developers.\n");
fprintf (stderr, "*** (be careful, private info may be in this file since\n");
fprintf (stderr, "*** part of chats are displayed, so remove lines if needed)\n\n");
diff --git a/src/common/weechat.h b/src/common/weechat.h
index 6ce6e62e4..aec1ca321 100644
--- a/src/common/weechat.h
+++ b/src/common/weechat.h
@@ -108,8 +108,9 @@ extern gnutls_certificate_credentials gnutls_xcred;
extern int ascii_strcasecmp (char *, char *);
extern int ascii_strncasecmp (char *, char *, int);
extern void weechat_log_printf (char *, ...);
-extern void weechat_dump (int);
extern char *weechat_iconv (char *, char *, char *);
+extern char *weechat_strreplace (char *, char *, char *);
+extern void weechat_dump (int);
extern long get_timeval_diff (struct timeval *, struct timeval *);
extern void weechat_shutdown (int, int);
diff --git a/src/common/weeconfig.c b/src/common/weeconfig.c
index ac81dade2..ade8ff0a6 100644
--- a/src/common/weeconfig.c
+++ b/src/common/weeconfig.c
@@ -633,9 +633,10 @@ t_config_option weechat_options_log[] =
OPTION_TYPE_BOOLEAN, BOOL_FALSE, BOOL_TRUE, BOOL_FALSE,
NULL, NULL, &cfg_log_plugin_msg, NULL, &config_change_noop },
{ "log_path", N_("path for log files"),
- N_("path for WeeChat log files"),
+ N_("path for WeeChat log files ('%h' will be replaced by WeeChat home, "
+ "~/.weechat by default)"),
OPTION_TYPE_STRING, 0, 0, 0,
- "~/.weechat/logs/", NULL, NULL, &cfg_log_path, &config_change_noop },
+ "%h/logs/", NULL, NULL, &cfg_log_path, &config_change_noop },
{ "log_timestamp", N_("timestamp for log"),
N_("timestamp for log (see man strftime for date/time specifiers)"),
OPTION_TYPE_STRING, 0, 0, 0,
@@ -842,9 +843,10 @@ char *cfg_plugins_extension;
t_config_option weechat_options_plugins[] =
{ { "plugins_path", N_("path for searching plugins"),
- N_("path for searching plugins"),
+ N_("path for searching plugins ('%h' will be replaced by WeeChat home, "
+ "~/.weechat by default)"),
OPTION_TYPE_STRING, 0, 0, 0,
- "~/.weechat/plugins", NULL, NULL, &cfg_plugins_path, &config_change_noop },
+ "%h/plugins", NULL, NULL, &cfg_plugins_path, &config_change_noop },
{ "plugins_autoload", N_("list of plugins to load automatically"),
N_("comma separated list of plugins to load automatically at startup, "
"\"*\" means all plugins found "