Added --home and --config command line parameters to irssi to specify

locations for ~/.irssi and ~/.irssi/config


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1626 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-07-15 00:39:48 +00:00 committed by cras
commit 79d1d7089a
19 changed files with 129 additions and 276 deletions

View file

@ -21,6 +21,7 @@
#include "module.h"
#include <signal.h>
#include "args.h"
#include "pidwait.h"
#include "misc.h"
@ -49,8 +50,20 @@ void chat_commands_deinit(void);
int irssi_gui;
static char *irssi_dir, *irssi_config_file;
static GSList *dialog_type_queue, *dialog_text_queue;
const char *get_irssi_dir(void)
{
return irssi_dir;
}
/* return full path for ~/.irssi/config */
const char *get_irssi_config(void)
{
return irssi_config_file;
}
static void read_signals(void)
{
#ifndef WIN32
@ -106,7 +119,40 @@ static void sig_init_finished(void)
g_slist_free(dialog_text_queue);
}
void core_init(void)
void core_init_paths(int argc, char *argv[])
{
static struct poptOption options[] = {
{ "config", 0, POPT_ARG_STRING, NULL, 0, "Configuration file location (~/.irssi/config)", "PATH" },
{ "home", 0, POPT_ARG_STRING, NULL, 0, "Irssi home dir location (~/.irssi)", "PATH" },
{ NULL, '\0', 0, NULL }
};
int n, len;
for (n = 1; n < argc; n++) {
if (strncmp(argv[n], "--home=", 7) == 0) {
g_free_not_null(irssi_dir);
irssi_dir = convert_home(argv[n]+7);
len = strlen(irssi_dir);
if (irssi_dir[len-1] == G_DIR_SEPARATOR)
irssi_dir[len-1] = '\0';
break;
}
if (strncmp(argv[n], "--config=", 9) == 0) {
g_free_not_null(irssi_config_file);
irssi_config_file = convert_home(argv[n]+9);
break;
}
}
args_register(options);
if (irssi_dir == NULL)
irssi_dir = g_strdup_printf(IRSSI_DIR_FULL, g_get_home_dir());
if (irssi_config_file == NULL)
irssi_config_file = g_strdup_printf("%s/config", irssi_dir);
}
void core_init(int argc, char *argv[])
{
dialog_type_queue = NULL;
dialog_text_queue = NULL;
@ -179,4 +225,7 @@ void core_deinit(void)
pidwait_deinit();
#endif
modules_deinit();
g_free(irssi_dir);
g_free(irssi_config_file);
}

View file

@ -11,6 +11,8 @@
extern int irssi_gui;
void core_init_paths(int argc, char *argv[]);
void core_init(void);
void core_deinit(void);

View file

@ -255,7 +255,7 @@ static GModule *module_open(const char *name)
path = g_strdup(name);
else {
/* first try from home dir */
str = g_strdup_printf("%s/.irssi/modules", g_get_home_dir());
str = g_strdup_printf("%s/modules", get_irssi_dir());
path = g_module_build_path(str, name);
g_free(str);

View file

@ -483,14 +483,13 @@ static CONFIG_REC *parse_configfile(const char *fname)
CONFIG_REC *config;
struct stat statbuf;
const char *path;
char *real_fname, *str;
char *str;
real_fname = fname != NULL ? g_strdup(fname) :
g_strdup_printf("%s"G_DIR_SEPARATOR_S".irssi"
G_DIR_SEPARATOR_S"config", g_get_home_dir());
if (fname == NULL)
fname = get_irssi_config();
if (stat(real_fname, &statbuf) == 0)
path = real_fname;
if (stat(fname, &statbuf) == 0)
path = fname;
else {
/* user configuration file not found, use the default one
from sysconfdir */
@ -517,9 +516,8 @@ static CONFIG_REC *parse_configfile(const char *fname)
else
config_parse_data(config, default_config, "internal");
config_change_file_name(config, real_fname, 0660);
irssi_config_save_state(real_fname);
g_free(real_fname);
config_change_file_name(config, fname, 0660);
irssi_config_save_state(fname);
return config;
}
@ -528,17 +526,16 @@ static void init_configfile(void)
struct stat statbuf;
char *str;
str = g_strdup_printf("%s"G_DIR_SEPARATOR_S".irssi", g_get_home_dir());
if (stat(str, &statbuf) != 0) {
if (stat(get_irssi_dir(), &statbuf) != 0) {
/* ~/.irssi not found, create it. */
if (mkpath(str, 0700) != 0) {
g_error("Couldn't create %s directory", str);
if (mkpath(get_irssi_dir(), 0700) != 0) {
g_error("Couldn't create %s directory", get_irssi_dir());
}
} else if (!S_ISDIR(statbuf.st_mode)) {
g_error("%s is not a directory.\n"
"You should remove it with command: rm ~/.irssi", str);
"You should remove it with command: rm %s",
get_irssi_dir(), get_irssi_dir());
}
g_free(str);
mainconfig = parse_configfile(NULL);
config_last_modifycounter = mainconfig->modifycounter;
@ -559,11 +556,9 @@ int settings_reread(const char *fname)
CONFIG_REC *tempconfig;
char *str;
if (fname == NULL) fname = "~/.irssi/config";
str = convert_home(fname);
str = convert_home(fname);
tempconfig = parse_configfile(str);
g_free(str);
g_free(str);
if (tempconfig == NULL) {
signal_emit("gui dialog", 2, "error", g_strerror(errno));