summaryrefslogtreecommitdiff
path: root/src/fe-common
diff options
context:
space:
mode:
authorTimo Sirainen <cras@irssi.org>2001-02-20 01:54:14 +0000
committercras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564>2001-02-20 01:54:14 +0000
commit7a6c3f0b7c98c380e2225c358020704bdad73fa7 (patch)
treeefb771edc6a6e70f125130bdf2e388e16eb41874 /src/fe-common
parent25845074d66fc132f890aa861ca7ac567b6b6b34 (diff)
downloadirssi-7a6c3f0b7c98c380e2225c358020704bdad73fa7.zip
Errors reading/writing config and theme files are now handled properly
and printed to screen git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1266 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/fe-common')
-rw-r--r--src/fe-common/core/fe-log.c8
-rw-r--r--src/fe-common/core/themes.c92
2 files changed, 54 insertions, 46 deletions
diff --git a/src/fe-common/core/fe-log.c b/src/fe-common/core/fe-log.c
index 4278f6a9..434e094e 100644
--- a/src/fe-common/core/fe-log.c
+++ b/src/fe-common/core/fe-log.c
@@ -69,7 +69,7 @@ static void cmd_log_open(const char *data)
{
SERVER_REC *server;
GHashTable *optlist;
- char *targetarg, *fname, *levels;
+ char *targetarg, *fname, *levels, *servertag;
void *free_arg;
char window[MAX_INT_STRLEN];
LOG_REC *log;
@@ -86,15 +86,17 @@ static void cmd_log_open(const char *data)
/* -<server tag> */
server = cmd_options_get_server("join", optlist, NULL);
+ servertag = server == NULL ? NULL : server->tag;
if (g_hash_table_lookup(optlist, "window")) {
/* log by window ref# */
ltoa(window, active_win->refnum);
- log_item_add(log, LOG_ITEM_WINDOW_REFNUM, window, server->tag);
+ log_item_add(log, LOG_ITEM_WINDOW_REFNUM, window,
+ servertag);
} else {
targetarg = g_hash_table_lookup(optlist, "targets");
if (targetarg != NULL && *targetarg != '\0')
- log_add_targets(log, targetarg, server->tag);
+ log_add_targets(log, targetarg, servertag);
}
if (g_hash_table_lookup(optlist, "autoopen"))
diff --git a/src/fe-common/core/themes.c b/src/fe-common/core/themes.c
index cf91e95a..317b3bf5 100644
--- a/src/fe-common/core/themes.c
+++ b/src/fe-common/core/themes.c
@@ -40,7 +40,7 @@ GHashTable *default_formats;
static int init_finished;
static char *init_errors;
-static void theme_read(THEME_REC *theme, const char *path, const char *data);
+static int theme_read(THEME_REC *theme, const char *path, const char *data);
THEME_REC *theme_create(const char *path, const char *name)
{
@@ -631,10 +631,9 @@ static void window_themes_update(void)
THEME_REC *theme_load(const char *setname)
{
- THEME_REC *theme;
+ THEME_REC *theme, *oldtheme;
struct stat statbuf;
char *fname, *name, *p;
- int modified;
name = g_strdup(setname);
p = strrchr(name, '.');
@@ -659,24 +658,24 @@ THEME_REC *theme_load(const char *setname)
}
}
- modified = theme != NULL;
- if (theme != NULL) {
- if (theme->last_modify == statbuf.st_mtime) {
- /* theme not modified, use the one already in memory */
- g_free(fname);
- g_free(name);
- return theme;
- }
-
- theme_destroy(theme);
+ if (theme != NULL && theme->last_modify == statbuf.st_mtime) {
+ /* theme not modified, use the one already in memory */
+ g_free(fname);
+ g_free(name);
+ return theme;
}
+ oldtheme = theme;
theme = theme_create(fname, name);
theme->last_modify = statbuf.st_mtime;
- theme_read(theme, theme->path, NULL);
+ if (!theme_read(theme, theme->path, NULL)) {
+ /* error reading .theme file */
+ theme_destroy(theme);
+ theme = NULL;
+ }
- if (modified) {
- /* make sure no windows use the theme we just destroyed */
+ if (oldtheme != NULL && theme != NULL) {
+ theme_destroy(oldtheme);
window_themes_update();
}
@@ -696,42 +695,47 @@ static void theme_read_modules(const char *module, void *value,
theme_init_module(rec->theme, module, rec->config);
}
-static void theme_read(THEME_REC *theme, const char *path, const char *data)
+static void read_error(const char *str)
+{
+ char *old;
+
+ if (init_finished)
+ printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "%s", str);
+ else if (init_errors == NULL)
+ init_errors = g_strdup(str);
+ else {
+ old = init_errors;
+ init_errors = g_strconcat(init_errors, "\n", str, NULL);
+ g_free(old);
+ }
+}
+
+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 = config_open(path, -1);
- if (config == NULL) {
- /* didn't exist or no access? */
- theme->default_color = 0;
- theme->default_bold_color = 7;
- return;
- }
- config_parse(config);
- } else {
- config = config_open(NULL, -1);
+ if (data != NULL)
config_parse_data(config, data, "internal");
- }
+ else
+ config_parse(config);
if (config_last_error(config) != NULL) {
- char *str;
-
str = g_strdup_printf(_("Ignored errors in theme %s:\n%s"),
theme->name, config_last_error(config));
- if (!init_finished) {
- if (init_errors == NULL)
- init_errors = str;
- else {
- init_errors = g_strconcat(init_errors, "\n",
- str, NULL);
- g_free(str);
- }
- } else {
- signal_emit("gui dialog", 2, "error", str);
- g_free(str);
- }
+ read_error(str);
+ g_free(str);
}
theme->default_color =
@@ -746,6 +750,8 @@ static void theme_read(THEME_REC *theme, const char *path, const char *data)
g_hash_table_foreach(default_formats,
(GHFunc) theme_read_modules, &rec);
config_close(config);
+
+ return TRUE;
}
typedef struct {