implement API changes to accomodate for XDG

- add is_xdg_supported() (C and Perl).
- use $XDG_CONFIG_HOME/irssi/ only when it is present.
- fallback mechanism added.
- scripts are run from $XDG_DATA_HOME/irssi/scripts/[autorun], if and
only if xdg is used.
This commit is contained in:
altffour 2021-01-06 19:07:18 +03:00
commit e6b9a07f9a
No known key found for this signature in database
GPG key ID: B4ADFA86EDF5CCE9
4 changed files with 51 additions and 48 deletions

View file

@ -65,22 +65,23 @@ void log_away_deinit(void);
void wcwidth_wrapper_init(void);
void wcwidth_wrapper_deinit(void);
int xdg_support;
int irssi_gui;
int irssi_init_finished;
int sighup_received;
time_t client_start_time;
static char *irssi_dir, *irssi_xdg_dir, *irssi_config_file;
static char *irssi_dir, *irssi_config_file;
static GSList *dialog_type_queue, *dialog_text_queue;
int is_xdg_supported()
{
return xdg_support;
}
const char *get_irssi_dir(void)
{
return irssi_dir;
}
const char *get_irssi_xdg_dir(void)
{
return irssi_xdg_dir;
return (xdg_support = 1) ? irssi_xdg_dir : irssi_dir;
}
/* return full path for ~/.irssi/config */
@ -194,19 +195,26 @@ void core_register_options(void)
void core_preinit(const char *path)
{
struct stat statbuf;
const char *home;
char *str;
int len;
const char *home;
if (irssi_dir == NULL) {
irssi_dir = g_build_filename(g_get_user_config_dir(), "irssi", NULL);
if (g_file_test(irssi_dir, G_FILE_TEST_IS_DIR) == FALSE) {
home = ".";
g_free(irssi_dir);
/* check if %XDG_CONFIG_HOME/irssi exists and default to it */
char *dirp = g_build_filename(g_get_user_config_dir(), "irssi", NULL);
if (stat(dirp, &statbuf) == 0) {
xdg_support = 1;
irssi_dir = dirp;
} else { /* fallback to non-xdg location */
g_free(dirp);
home = g_get_home_dir();
if (home == NULL)
home = ".";
home = g_get_home_dir();
irssi_dir = g_build_filename(home ? home : ".", ".irssi", NULL);
}
irssi_dir = g_strdup_printf(IRSSI_DIR_FULL, home);
xdg_support = 0;
}
} else {
str = irssi_dir;
irssi_dir = fix_path(str);
@ -216,7 +224,10 @@ void core_preinit(const char *path)
irssi_dir[len-1] = '\0';
}
if (irssi_config_file == NULL)
irssi_config_file = g_build_filename(irssi_dir, IRSSI_HOME_CONFIG, NULL);
if (is_xdg_supported())
irssi_config_file = g_build_filename(irssi_dir, IRSSI_HOME_CONFIG, NULL);
else
irssi_config_file = g_strdup_printf("%s/" IRSSI_HOME_CONFIG, irssi_dir);
else {
str = irssi_config_file;
irssi_config_file = fix_path(str);