diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2011-10-29 16:52:19 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2011-10-29 16:52:19 +0200 |
commit | 34e0226ee083b1cbd6277c0704288cb3c01d85d9 (patch) | |
tree | 080082042c74c2eb56e20157c8c4f549c58f89a0 /src | |
parent | 6d6e0e0ad92307e3fcb4c269716044da86f34bc0 (diff) | |
download | weechat-34e0226ee083b1cbd6277c0704288cb3c01d85d9.zip |
core: add WEECHAT_HOME option in cmake and configure to setup default WeeChat home (default is "~/.weechat") (task #11266)
Syntax for cmake: cmake <dir> -DWEECHAT_HOME="~/.weechat"
Syntax for configure: ./configure WEECHAT_HOME="~/.weechat"
Diffstat (limited to 'src')
-rw-r--r-- | src/core/weechat.c | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/core/weechat.c b/src/core/weechat.c index 735fc15f7..d1cfb0ca2 100644 --- a/src/core/weechat.c +++ b/src/core/weechat.c @@ -282,23 +282,47 @@ weechat_parse_args (int argc, char *argv[]) void weechat_create_home_dirs () { - char *ptr_home; + char *ptr_home, *config_weechat_home = WEECHAT_HOME; int dir_length; struct stat statinfo; if (!weechat_home) { - ptr_home = getenv ("HOME"); - if (!ptr_home) + if (strlen (config_weechat_home) == 0) { string_iconv_fprintf (stderr, - _("Error: unable to get HOME directory\n")); + _("Error: WEECHAT_HOME is undefined, check " + "build options\n")); weechat_shutdown (EXIT_FAILURE, 0); /* make C static analyzer happy (never executed) */ return; } - dir_length = strlen (ptr_home) + 10; - weechat_home = malloc (dir_length); + + if (config_weechat_home[0] == '~') + { + /* replace leading '~' by $HOME */ + ptr_home = getenv ("HOME"); + if (!ptr_home) + { + string_iconv_fprintf (stderr, + _("Error: unable to get HOME directory\n")); + weechat_shutdown (EXIT_FAILURE, 0); + /* make C static analyzer happy (never executed) */ + return; + } + dir_length = strlen (ptr_home) + strlen (config_weechat_home + 1) + 1; + weechat_home = malloc (dir_length); + if (weechat_home) + { + snprintf (weechat_home, dir_length, + "%s%s", ptr_home, config_weechat_home + 1); + } + } + else + { + weechat_home = strdup (config_weechat_home); + } + if (!weechat_home) { string_iconv_fprintf (stderr, @@ -308,8 +332,6 @@ weechat_create_home_dirs () /* make C static analyzer happy (never executed) */ return; } - snprintf (weechat_home, dir_length, "%s%s.weechat", ptr_home, - DIR_SEPARATOR); } /* if home already exists, it has to be a directory */ |