mirror of
https://github.com/irssi/irssi.git
synced 2024-09-01 04:14:16 -04:00
Cleanup option handling.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4510 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
afa4292466
commit
841cd8d0cf
@ -154,45 +154,34 @@ static void sig_init_finished(void)
|
||||
g_slist_free(dialog_text_queue);
|
||||
}
|
||||
|
||||
void core_init_paths(int argc, char *argv[])
|
||||
static char *fix_path(const char *str)
|
||||
{
|
||||
char *new_str = convert_home(str);
|
||||
if (!g_path_is_absolute(new_str)) {
|
||||
char *tmp_str = new_str;
|
||||
new_str = g_strdup_printf("%s/%s", g_get_current_dir(), tmp_str);
|
||||
g_free(tmp_str);
|
||||
}
|
||||
return new_str;
|
||||
}
|
||||
|
||||
void core_register_options(void)
|
||||
{
|
||||
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" },
|
||||
{ "config", 0, POPT_ARG_STRING, &irssi_config_file, 0, "Configuration file location (~/.irssi/config)", "PATH" },
|
||||
{ "home", 0, POPT_ARG_STRING, &irssi_dir, 0, "Irssi home dir location (~/.irssi)", "PATH" },
|
||||
{ NULL, '\0', 0, NULL }
|
||||
};
|
||||
const char *home;
|
||||
char *str;
|
||||
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';
|
||||
} else if (strncmp(argv[n], "--config=", 9) == 0) {
|
||||
g_free_not_null(irssi_config_file);
|
||||
irssi_config_file = convert_home(argv[n]+9);
|
||||
}
|
||||
}
|
||||
|
||||
if (irssi_dir != NULL && !g_path_is_absolute(irssi_dir)) {
|
||||
str = irssi_dir;
|
||||
irssi_dir = g_strdup_printf("%s/%s", g_get_current_dir(), str);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
if (irssi_config_file != NULL &&
|
||||
!g_path_is_absolute(irssi_config_file)) {
|
||||
str = irssi_config_file;
|
||||
irssi_config_file =
|
||||
g_strdup_printf("%s/%s", g_get_current_dir(), str);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
args_register(options);
|
||||
session_register_options();
|
||||
}
|
||||
|
||||
void core_preinit(const char *path)
|
||||
{
|
||||
const char *home;
|
||||
char *str;
|
||||
int len;
|
||||
|
||||
if (irssi_dir == NULL) {
|
||||
home = g_get_home_dir();
|
||||
@ -200,11 +189,23 @@ void core_init_paths(int argc, char *argv[])
|
||||
home = ".";
|
||||
|
||||
irssi_dir = g_strdup_printf(IRSSI_DIR_FULL, home);
|
||||
} else {
|
||||
str = irssi_dir;
|
||||
irssi_dir = fix_path(str);
|
||||
g_free(str);
|
||||
len = strlen(irssi_dir);
|
||||
if (irssi_dir[len-1] == G_DIR_SEPARATOR)
|
||||
irssi_dir[len-1] = '\0';
|
||||
}
|
||||
if (irssi_config_file == NULL)
|
||||
irssi_config_file = g_strdup_printf("%s/"IRSSI_HOME_CONFIG, irssi_dir);
|
||||
else {
|
||||
str = irssi_config_file;
|
||||
irssi_config_file = fix_path(str);
|
||||
g_free(str);
|
||||
}
|
||||
|
||||
session_set_binary(argv[0]);
|
||||
session_set_binary(path);
|
||||
}
|
||||
|
||||
static void sig_irssi_init_finished(void)
|
||||
|
@ -16,8 +16,9 @@ extern int irssi_init_finished; /* TRUE after "irssi init finished" signal is se
|
||||
extern int reload_config; /* TRUE after received SIGHUP. */
|
||||
extern time_t client_start_time;
|
||||
|
||||
void core_init_paths(int argc, char *argv[]);
|
||||
void core_preinit(const char *path);
|
||||
|
||||
void core_register_options(void);
|
||||
void core_init(void);
|
||||
void core_deinit(void);
|
||||
|
||||
|
@ -332,7 +332,7 @@ static void sig_init_finished(void)
|
||||
session_file = NULL;
|
||||
}
|
||||
|
||||
void session_init(void)
|
||||
void session_register_options(void)
|
||||
{
|
||||
static struct poptOption options[] = {
|
||||
{ "session", 0, POPT_ARG_STRING, &session_file, 0, "Used by /UPGRADE command", "PATH" },
|
||||
@ -341,7 +341,10 @@ void session_init(void)
|
||||
|
||||
session_file = NULL;
|
||||
args_register(options);
|
||||
}
|
||||
|
||||
void session_init(void)
|
||||
{
|
||||
command_bind("upgrade", NULL, (SIGNAL_FUNC) cmd_upgrade);
|
||||
|
||||
signal_add("session save", (SIGNAL_FUNC) sig_session_save);
|
||||
|
@ -6,6 +6,7 @@ extern char *irssi_binary;
|
||||
void session_set_binary(const char *path);
|
||||
void session_upgrade(void);
|
||||
|
||||
void session_register_options(void);
|
||||
void session_init(void);
|
||||
void session_deinit(void);
|
||||
|
||||
|
@ -131,7 +131,7 @@ static void sig_channel_destroyed(CHANNEL_REC *channel)
|
||||
MODULE_DATA_UNSET(channel);
|
||||
}
|
||||
|
||||
void fe_common_core_init(void)
|
||||
void fe_common_core_register_options(void)
|
||||
{
|
||||
static struct poptOption version_options[] = {
|
||||
{ NULL, '\0', POPT_ARG_CALLBACK, (void *)&print_version, '\0', NULL },
|
||||
@ -158,7 +158,10 @@ void fe_common_core_init(void)
|
||||
cmdline_nick = NULL;
|
||||
cmdline_hostname = NULL;
|
||||
args_register(options);
|
||||
}
|
||||
|
||||
void fe_common_core_init(void)
|
||||
{
|
||||
settings_add_bool("lookandfeel", "timestamps", TRUE);
|
||||
settings_add_level("lookandfeel", "timestamp_level", "ALL");
|
||||
settings_add_time("lookandfeel", "timestamp_timeout", "0");
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef __FE_COMMON_CORE_H
|
||||
#define __FE_COMMON_CORE_H
|
||||
|
||||
void fe_common_core_register_options(void);
|
||||
void fe_common_core_init(void);
|
||||
void fe_common_core_deinit(void);
|
||||
void fe_common_core_finish_init(void);
|
||||
|
@ -332,6 +332,11 @@ int main(int argc, char **argv)
|
||||
{ NULL, '\0', 0, NULL }
|
||||
};
|
||||
|
||||
core_register_options();
|
||||
fe_common_core_register_options();
|
||||
args_register(options);
|
||||
args_execute(argc, argv);
|
||||
|
||||
#ifdef USE_GC
|
||||
g_mem_set_vtable(&gc_mem_table);
|
||||
#endif
|
||||
@ -340,7 +345,7 @@ int main(int argc, char **argv)
|
||||
|
||||
dummy = FALSE;
|
||||
quitting = FALSE;
|
||||
core_init_paths(argc, argv);
|
||||
core_preinit(argv[0]);
|
||||
|
||||
check_files();
|
||||
|
||||
@ -363,8 +368,6 @@ int main(int argc, char **argv)
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
textui_init();
|
||||
args_register(options);
|
||||
args_execute(argc, argv);
|
||||
|
||||
if (!dummy && !term_init()) {
|
||||
fprintf(stderr, "Can't initialize screen handling, quitting.\n");
|
||||
|
Loading…
Reference in New Issue
Block a user