87 lines
1.6 KiB
Diff
87 lines
1.6 KiB
Diff
--- mc-4.6.1-pre2b/src/util.c
|
|
+++ mc-4.6.1-pre2b/src/util.c
|
|
@@ -32,6 +32,9 @@
|
|
#include <stdarg.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
+#include <iconv.h>
|
|
+#include <langinfo.h>
|
|
+#include <errno.h>
|
|
|
|
#include "tty.h"
|
|
#include "global.h"
|
|
@@ -827,11 +830,61 @@
|
|
}
|
|
|
|
char *
|
|
+utf8_to_local(char *str)
|
|
+{
|
|
+ iconv_t cd;
|
|
+ size_t buflen = strlen(str);
|
|
+ char *output;
|
|
+ int retry = 1;
|
|
+
|
|
+ cd = iconv_open (nl_langinfo(CODESET), "UTF-8");
|
|
+ if (cd == (iconv_t) -1) {
|
|
+ return g_strdup(str);
|
|
+ }
|
|
+
|
|
+ output = g_malloc(buflen + 1);
|
|
+
|
|
+ while (retry)
|
|
+ {
|
|
+ char *wrptr = output;
|
|
+ char *inptr = str;
|
|
+ size_t insize = buflen;
|
|
+ size_t avail = buflen;
|
|
+ size_t nconv;
|
|
+
|
|
+ nconv = iconv (cd, &inptr, &insize, &wrptr, &avail);
|
|
+ if (nconv == (size_t) -1)
|
|
+ {
|
|
+ if (errno == E2BIG)
|
|
+ {
|
|
+ buflen *= 2;
|
|
+ g_free(output);
|
|
+ output = g_malloc(buflen + 1);
|
|
+ }
|
|
+ else
|
|
+ {
|
|
+ g_free(output);
|
|
+ return g_strdup(str);
|
|
+ }
|
|
+ }
|
|
+ else {
|
|
+ retry = 0;
|
|
+ *wrptr = 0;
|
|
+ }
|
|
+ }
|
|
+
|
|
+ iconv_close (cd);
|
|
+
|
|
+ return output;
|
|
+}
|
|
+
|
|
+char *
|
|
load_mc_home_file (const char *filename, char **allocated_filename)
|
|
{
|
|
char *hintfile_base, *hintfile;
|
|
char *lang;
|
|
char *data;
|
|
+ char *conv_data;
|
|
|
|
hintfile_base = concat_dir_and_file (mc_home, filename);
|
|
lang = guess_message_value ();
|
|
@@ -864,7 +917,10 @@
|
|
else
|
|
g_free (hintfile);
|
|
|
|
- return data;
|
|
+ conv_data = utf8_to_local(data);
|
|
+ g_free(data);
|
|
+
|
|
+ return conv_data;
|
|
}
|
|
|
|
/* Check strftime() results. Some systems (i.e. Solaris) have different
|