static int theme_read(THEME_REC *theme, const char *path, const char *data) { CONFIG_REC *config; THEME_READ_REC rec; char *str; config = config_open(data == NULL ? path : NULL, -1) ; if (config == NULL) { /* didn't exist or no access? */ str = g_strdup_printf("Error reading theme file %s: %s", path, g_strerror(errno)); read_error(str); g_free(str); return FALSE; } if (data != NULL) config_parse_data(config, data, "internal"); else config_parse(config); if (config_last_error(config) != NULL) { str = g_strdup_printf("Ignored errors in theme %s:\n%s", theme->name, config_last_error(config)); read_error(str); g_free(str); } theme->default_color = config_get_int(config, NULL, "default_color", -1); theme->info_eol = config_get_bool(config, NULL, "info_eol", FALSE); /* FIXME: remove after 0.7.99 */ if (theme->default_color == 0 && config_get_int(config, NULL, "default_real_color", -1) != -1) theme->default_color = -1; theme_read_replaces(config, theme); if (data == NULL) { /* get the default abstracts from default theme. */ CONFIG_REC *default_config; default_config = config_open(NULL, -1); config_parse_data(default_config, default_theme, "internal"); theme_read_abstracts(default_config, theme); config_close(default_config); } theme_read_abstracts(config, theme); rec.theme = theme; rec.config = config; g_hash_table_foreach(default_formats, (GHFunc) theme_read_modules, &rec); config_close(config); return TRUE; }
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; }
static gboolean sbar_node_isdefault(const char *name) { CONFIG_REC *config; CONFIG_NODE *node; /* read the default statusbar settings from internal config */ config = config_open(NULL, -1); config_parse_data(config, default_config, "internal"); node = config_sbar_node(config, name, FALSE); config_close(config); return node != NULL ? TRUE : FALSE; }
static THEME_REC *read_internal_theme(void) { CONFIG_REC *config; THEME_REC *theme; theme = theme_create("internal", "_internal"); theme->refcount++; theme_destroy(theme); config = config_open(NULL, -1); config_parse_data(config, default_theme, "internal"); theme_read_abstracts(config, theme); config_close(config); return theme; }
static void statusbar_reset_defaults(void) { CONFIG_REC *config; CONFIG_NODE *node; while (statusbar_groups != NULL) statusbar_group_destroy(statusbar_groups->data); active_statusbar_group = NULL; /* read the default statusbar settings from internal config */ config = config_open(NULL, -1); config_parse_data(config, default_config, "internal"); node = config_node_traverse(config, "statusbar", FALSE); if (node != NULL) read_statusbar_config_from_node(node); config_close(config); }
static CONFIG_NODE *sbar_find_item_with_defaults(const char *statusbar, const char *item, gboolean create) { CONFIG_REC *config, *close_config; CONFIG_NODE *node; close_config = NULL; config = mainconfig; node = sbar_node(statusbar, FALSE); if (node == NULL) { /* we are looking up defaults from the internal config */ close_config = config = config_open(NULL, -1); config_parse_data(config, default_config, "internal"); node = config_sbar_node(config, statusbar, FALSE); } if (node == NULL) { printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_STATUSBAR_NOT_FOUND, statusbar); if (close_config != NULL) config_close(close_config); return NULL; } node = config_sbar_items_section(config, node, create); if (node == NULL || (!create && config_node_section(config, node, item, -1) == NULL)) { printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, TXT_STATUSBAR_ITEM_NOT_FOUND, item); if (close_config != NULL) config_close(close_config); return NULL; } if (config != mainconfig) { /* we need to copy default to user config */ node = statusbar_copy_config(config, node, sbar_node(statusbar, TRUE)); } if (close_config != NULL) config_close(close_config); return node; }
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; }
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); }