summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/commands.h3
-rw-r--r--src/core/recode.c88
-rw-r--r--src/core/recode.h1
-rw-r--r--src/core/settings.c35
4 files changed, 94 insertions, 33 deletions
diff --git a/src/core/commands.h b/src/core/commands.h
index bdc8755d..b4f4ea0e 100644
--- a/src/core/commands.h
+++ b/src/core/commands.h
@@ -38,7 +38,8 @@ enum {
CMDERR_CHAN_NOT_SYNCED, /* channel not fully synchronized yet */
CMDERR_ILLEGAL_PROTO, /* requires different chat protocol than the active server */
CMDERR_NOT_GOOD_IDEA, /* not good idea to do, -yes overrides this */
- CMDERR_INVALID_TIME /* invalid time specification */
+ CMDERR_INVALID_TIME, /* invalid time specification */
+ CMDERR_INVALID_CHARSET /* invalid charset specification */
};
/* Return the full command for `alias' */
diff --git a/src/core/recode.c b/src/core/recode.c
index aa9f8315..8237e056 100644
--- a/src/core/recode.c
+++ b/src/core/recode.c
@@ -20,7 +20,10 @@
#include "module.h"
#include "settings.h"
+#include "servers.h"
+#include "signals.h"
#include "lib-config/iconfig.h"
+#include "misc.h"
#ifdef HAVE_GLIB2
static gboolean recode_get_charset(const char **charset)
@@ -29,39 +32,65 @@ static gboolean recode_get_charset(const char **charset)
if (**charset)
/* we use the same test as in src/fe-text/term.c:123 */
return !g_strcasecmp(*charset, "utf-8");
-
+
return g_get_charset(charset);
}
#endif
+gboolean is_valid_charset(const char *charset)
+{
+#ifdef HAVE_GLIB2
+ const char *from="UTF-8";
+ const char *str="irssi";
+ char *recoded;
+ gboolean valid;
+
+ if (!charset || *charset == '\0')
+ return FALSE;
+ recoded = g_convert(str, strlen(str), charset, from, NULL, NULL, NULL);
+ valid = (recoded != NULL);
+ g_free(recoded);
+ return valid;
+#else
+ if (!charset || *charset =='\0')
+ return FALSE;
+ return TRUE;
+#endif
+}
+
+static gboolean is_translit(const char *charset)
+{
+ char *pos;
+ pos = stristr(charset, "//translit");
+ return (pos != NULL);
+}
+
char *recode_in(const char *str, const char *target)
{
#ifdef HAVE_GLIB2
const char *from = NULL;
const char *to = NULL;
+ char *translit_to = NULL;
char *recoded = NULL;
- gboolean term_is_utf8;
- gboolean str_is_utf8;
- gboolean translit;
+ gboolean term_is_utf8, str_is_utf8, translit;
int len;
-
+
if (!str)
return g_strdup(str);
-
+
len = strlen(str);
str_is_utf8 = g_utf8_validate(str, len, NULL);
-
translit = settings_get_bool("recode_transliterate");
-
- if (target != NULL)
+
+ if (target != NULL && from == NULL)
from = iconfig_get_str("conversions", target, NULL);
term_is_utf8 = recode_get_charset(&to);
-
- if (translit)
- to = g_strdup_printf("%s//TRANSLIT", to);
-
+
+ if (translit && !is_translit(to))
+ to = translit_to = g_strconcat(to, "//TRANSLIT", NULL);
+
if (from)
recoded = g_convert(str, len, to, from, NULL, NULL, NULL);
@@ -69,10 +98,10 @@ char *recode_in(const char *str, const char *target)
if (term_is_utf8) {
if (!str_is_utf8)
from = settings_get_str("recode_fallback");
-
+
} else if (str_is_utf8)
from = "UTF-8";
-
+
if (from)
recoded = g_convert(str, len, to, from, NULL, NULL, NULL);
@@ -93,31 +122,34 @@ char *recode_out(const char *str, const char *target)
gboolean translit;
gboolean term_is_utf8;
int len;
-
+
if (!str)
return g_strdup(str);
-
+
len = strlen(str);
-
+
translit = settings_get_bool("recode_transliterate");
+
if (target) {
const char *to = NULL;
+ char *translit_to = NULL;
+
+ /* default outgoing charset if set */
+ to = settings_get_str("recode_out_default_charset");
+ if (to == NULL || *to == '\0')
+ to = iconfig_get_str("conversions", target, NULL);
+ if (to && *to != '\0') {
+ if (translit && !is_translit(to))
+ to = translit_to = g_strconcat(to ,"//TRANSLIT", NULL);
- to = iconfig_get_str("conversions", target, NULL);
- if (!to)
- /* default outgoing charset if no conversion is set */
- to = settings_get_str("recode_out_default_charset");
- if (to) {
- if (translit)
- to = g_strdup_printf("%s//TRANSLIT", to);
-
term_is_utf8 = recode_get_charset(&from);
recoded = g_convert(str, len, to, from, NULL, NULL, NULL);
}
+ g_free(translit_to);
}
if (!recoded)
recoded = g_strdup(str);
-
+
return recoded;
#else
return g_strdup(str);
@@ -128,7 +160,7 @@ void recode_init(void)
{
settings_add_str("misc", "recode_fallback", "ISO8859-1");
settings_add_str("misc", "recode_out_default_charset", "");
- settings_add_bool("misc", "recode_transliterate", TRUE);
+ settings_add_bool("misc", "recode_transliterate", FALSE);
}
void recode_deinit(void)
diff --git a/src/core/recode.h b/src/core/recode.h
index 47a11f09..2a50da9e 100644
--- a/src/core/recode.h
+++ b/src/core/recode.h
@@ -3,6 +3,7 @@
char *recode_in (const char *str, const char *target);
char *recode_out (const char *str, const char *target);
+gboolean is_valid_charset(const char *charset);
void recode_init (void);
void recode_deinit (void);
diff --git a/src/core/settings.c b/src/core/settings.c
index ba37ddb1..ce230f8a 100644
--- a/src/core/settings.c
+++ b/src/core/settings.c
@@ -25,6 +25,7 @@
#include "misc.h"
#include "lib-config/iconfig.h"
+#include "recode.h"
#include "settings.h"
#include "default-config.h"
@@ -393,8 +394,8 @@ static void sig_init_finished(void)
if (config_changed) {
/* some backwards compatibility changes were made to
config file, reload it */
- g_warning("Some time and size related settings were "
- "automatically changed to new format, please /SAVE");
+ g_warning("Some settings were automatically "
+ "updated, please /SAVE");
signal_emit("setup changed", 0);
}
}
@@ -439,15 +440,41 @@ void settings_clean_invalid(void)
static int backwards_compatibility(const char *module, CONFIG_NODE *node,
CONFIG_NODE *parent)
{
- const char *new_key;
+ const char *new_key, *new_module;
+ CONFIG_NODE *new_node;
char *new_value;
int old_value;
+ new_value = NULL; new_key = NULL; new_module = NULL;
+
+ /* fe-text term_type -> fe-common/core term_charset - for 0.8.10-> */
+ if (strcmp(module, "fe-text") == 0) {
+ if (strcasecmp(node->key, "term_type") == 0 ||
+ /* kludge for cvs-version where term_charset was in fe-text */
+ strcasecmp(node->key, "term_charset") == 0) {
+ new_module = "fe-common/core";
+ new_key = "term_charset";
+ new_value = !is_valid_charset(node->value) ? NULL :
+ g_strdup(node->value);
+ new_node = iconfig_node_traverse("settings", FALSE);
+ new_node = new_node == NULL ? NULL :
+ config_node_section(new_node, new_module, -1);
+
+ config_node_set_str(mainconfig, new_node,
+ new_key, new_value);
+ /* remove old */
+ config_node_set_str(mainconfig, parent,
+ node->key, NULL);
+ g_free(new_value);
+ config_changed = TRUE;
+ return new_key != NULL;
+ }
+ }
+ new_value = NULL, new_key = NULL;
/* FIXME: remove later - for 0.8.6 -> */
if (node->value == NULL || !is_numeric(node->value, '\0'))
return FALSE;
- new_value = NULL; new_key = NULL;
old_value = atoi(node->value);
if (strcmp(module, "fe-text") == 0) {