Beispiel #1
0
static CONFIG_REC *parse_configfile(const char *fname)
{
	CONFIG_REC *config;
	char *real_fname;

	real_fname = fname != NULL ? g_strdup(fname) :
		g_strdup_printf("%s/.irssi/config", g_get_home_dir());
	config = config_open(real_fname, -1);

	if (config != NULL)
		config_parse(config);
	else if (fname == NULL) {
		/* user configuration file not found, use the default one
		   from sysconfdir */
		config = config_open(SYSCONFDIR"/irssi/config", -1);
		if (config != NULL)
			config_parse(config);
		else {
			/* no configuration file in sysconfdir ..
			   use the build-in configuration */
			config = config_open(NULL, -1);
			config_parse_data(config, default_config, "internal");
		}

                config_change_file_name(config, real_fname, 0660);
	}

	g_free(real_fname);
	return config;
}
Beispiel #2
0
static CONFIG_REC *parse_configfile(const char *fname)
{
	CONFIG_REC *config;
	struct stat statbuf;
        const char *path;
	char *str;

	if (fname == NULL)
		fname = get_irssi_config();

	if (stat(fname, &statbuf) == 0)
		path = fname;
	else {
		/* user configuration file not found, use the default one
		   from sysconfdir */
                path = SYSCONFDIR"/"IRSSI_GLOBAL_CONFIG;
		if (stat(path, &statbuf) != 0) {
			/* no configuration file in sysconfdir ..
			   use the build-in configuration */
                        path = NULL;
		}
	}

	config = config_open(path, -1);
	if (config == NULL) {
		str = g_strdup_printf("Error opening configuration file %s: %s",
				      path, g_strerror(errno));
		signal_emit("gui dialog", 2, "error", str);
                g_free(str);

		config = config_open(NULL, -1);
	}

        if (config->fname != NULL)
		config_parse(config);
        else
		config_parse_data(config, default_config, "internal");

	config_change_file_name(config, fname, 0660);
        irssi_config_save_state(fname);
	return config;
}
Beispiel #3
0
static void theme_save(THEME_REC *theme, int save_all)
{
	CONFIG_REC *config;
	THEME_SAVE_REC data;
	char *path;
	int ok;

	config = config_open(theme->path, -1);
        if (config != NULL)
                config_parse(config);
        else {
                if (g_ascii_strcasecmp(theme->name, "default") == 0) {
                        config = config_open(NULL, -1);
                        config_parse_data(config, default_theme, "internal");
                        config_change_file_name(config, theme->path, 0660);
                } else {
                        config = config_open(theme->path, 0660);
                        if (config == NULL)
                                return;
                        config_parse(config);
                }
        }

	data.config = config;
        data.save_all = save_all;
	g_hash_table_foreach(theme->modules, (GHFunc) module_save, &data);

        /* always save the theme to ~/.irssi/ */
	path = g_strdup_printf("%s/%s", get_irssi_dir(),
			       g_basename(theme->path));
	ok = config_write(config, path, 0660) == 0;

	printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
		    ok ? TXT_THEME_SAVED : TXT_THEME_SAVE_FAILED,
		    path, config_last_error(config));

	g_free(path);
	config_close(config);
}