diff --git a/src/charsets.c b/src/charsets.c index 5666c23e3..5c28a997d 100644 --- a/src/charsets.c +++ b/src/charsets.c @@ -29,6 +29,8 @@ #include "global.h" #include "charsets.h" +#include "strutil.h" /* utf-8 functions */ +#include "main.h" int n_codepages = 0; @@ -249,4 +251,34 @@ convert_from_input (char *str) str++; } } + +unsigned char +convert_from_utf_to_current (char *str) +{ + if (!str) + return '.'; + + unsigned char ch; + char *cp_to = NULL; + GIConv conv; + GString *translated_data; + + translated_data = g_string_new (""); + cp_to = g_strdup ( get_codepage_id ( display_codepage ) ); + conv = str_crt_conv_to (cp_to); + + if (conv != INVALID_CONV) { + if (str_convert (conv, str, translated_data) != ESTR_FAILURE) { + ch = translated_data->str[0]; + } else { + ch = '.'; + } + str_close_conv (conv); + } + g_free (cp_to); + g_string_free (translated_data, TRUE); + return ch; + +} + #endif /* HAVE_CHARSET */ diff --git a/src/charsets.h b/src/charsets.h index b701d5aba..a517dd25d 100644 --- a/src/charsets.h +++ b/src/charsets.h @@ -6,7 +6,6 @@ #define UNKNCHAR '\001' #define CHARSETS_INDEX "mc.charsets" - extern int n_codepages; extern unsigned char conv_displ[256]; @@ -27,6 +26,7 @@ const char *init_translation_table (int cpsource, int cpdisplay); void convert_to_display (char *str); void convert_from_input (char *str); void convert_string (unsigned char *str); +unsigned char convert_from_utf_to_current (char *str); /* Convert single characters */ static inline int