mirror of
https://github.com/irssi/irssi.git
synced 2026-08-09 20:00:23 +02:00
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
This commit is contained in:
parent
25845074d6
commit
7a6c3f0b7c
3 changed files with 85 additions and 64 deletions
|
|
@ -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"))
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
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);
|
||||
config_parse_data(config, data, "internal");
|
||||
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 (config_last_error(config) != NULL) {
|
||||
char *str;
|
||||
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));
|
||||
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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue