1
0
mirror of https://github.com/irssi/irssi.git synced 2024-09-15 04:28:09 -04:00

/SET translation now says if there were any errors

git-svn-id: http://svn.irssi.org/repos/irssi/trunk@1810 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2001-09-22 11:25:08 +00:00 committed by cras
parent d246f862e8
commit bb507a8b85
3 changed files with 38 additions and 4 deletions

View File

@ -248,6 +248,8 @@ FORMAT_REC fecommon_core_formats[] = {
{ "set_item", "$0 = $1", 2, { 0, 0 } }, { "set_item", "$0 = $1", 2, { 0, 0 } },
{ "set_unknown", "Unknown setting $0", 1, { 0 } }, { "set_unknown", "Unknown setting $0", 1, { 0 } },
{ "set_not_boolean", "Setting {hilight $0} isn't boolean, use /SET", 1, { 0 } }, { "set_not_boolean", "Setting {hilight $0} isn't boolean, use /SET", 1, { 0 } },
{ "translation_not_found", "Error opening translation table file $0: $1", 2, { 0, 0 } },
{ "translation_file_error", "Error parsing translation table file $0", 1, { 0 } },
{ NULL, NULL, 0 } { NULL, NULL, 0 }
}; };

View File

@ -213,7 +213,9 @@ enum {
TXT_SET_TITLE, TXT_SET_TITLE,
TXT_SET_ITEM, TXT_SET_ITEM,
TXT_SET_UNKNOWN, TXT_SET_UNKNOWN,
TXT_SET_NOT_BOOLEAN TXT_SET_NOT_BOOLEAN,
TXT_TRANSLATION_NOT_FOUND,
TXT_TRANSLATION_FILE_ERROR
}; };
extern FORMAT_REC fecommon_core_formats[]; extern FORMAT_REC fecommon_core_formats[];

View File

@ -19,12 +19,17 @@
*/ */
#include "module.h" #include "module.h"
#include "module-formats.h"
#include "signals.h" #include "signals.h"
#include "line-split.h" #include "line-split.h"
#include "misc.h" #include "misc.h"
#include "levels.h"
#include "settings.h" #include "settings.h"
#include "printtext.h"
unsigned char translation_in[256], translation_out[256]; unsigned char translation_in[256], translation_out[256];
static char *current_translation;
void translation_reset(void) void translation_reset(void)
{ {
@ -81,7 +86,12 @@ int translation_read(const char *file)
f = open(file, O_RDONLY); f = open(file, O_RDONLY);
g_free(path); g_free(path);
if (f == -1) return FALSE; if (f == -1) {
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
TXT_TRANSLATION_NOT_FOUND, file,
g_strerror(errno));
return FALSE;
}
pos = 0; buffer = NULL; pos = 0; buffer = NULL;
while (pos < 512) { while (pos < 512) {
@ -95,20 +105,40 @@ int translation_read(const char *file)
line_split_free(buffer); line_split_free(buffer);
close(f); close(f);
if (pos != 512) if (pos != 512) {
translation_reset(); translation_reset();
printformat(NULL, NULL, MSGLEVEL_CLIENTERROR,
TXT_TRANSLATION_FILE_ERROR, file);
}
return pos == 512; return pos == 512;
} }
static void read_settings(void) static void read_settings(void)
{ {
translation_read(settings_get_str("translation")); const char *translation;
translation = settings_get_str("translation");
if (*translation == '\0') {
if (current_translation != NULL) {
g_free_and_null(current_translation);
translation_reset();
}
return;
}
if (current_translation != NULL &&
strcmp(translation, current_translation) != 0) {
g_free_not_null(current_translation);
current_translation = g_strdup(translation);
translation_read(translation);
}
} }
void translation_init(void) void translation_init(void)
{ {
translation_reset(); translation_reset();
current_translation = NULL;
settings_add_str("misc", "translation", ""); settings_add_str("misc", "translation", "");
signal_add("setup changed", (SIGNAL_FUNC) read_settings); signal_add("setup changed", (SIGNAL_FUNC) read_settings);