From 150bcf10c2ddea6c91d3d0684ac50c90a369fb67 Mon Sep 17 00:00:00 2001 From: John Zaitseff Date: Sat, 20 Aug 2011 16:27:11 +1000 Subject: [PATCH] Try loading UTF-8 strings with transliteration, if at all possible Also fix a bug in save_game(): the iconv_open() parameters were the wrong way around! --- src/fileio.c | 14 +++++++++++--- src/trader.h | 1 + 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/fileio.c b/src/fileio.c index 15d2df4..1224695 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -258,9 +258,17 @@ bool load_game (int num) } need_icd = (strcmp(codeset, GAME_FILE_CHARSET) != 0); if (need_icd) { - icd = iconv_open(codeset, GAME_FILE_CHARSET); + // Try using the GNU libiconv "//TRANSLIT" option + strcpy(buf, codeset); + strcat(buf, GAME_FILE_TRANSLIT); + + icd = iconv_open(buf, GAME_FILE_CHARSET); if (icd == (iconv_t) -1) { - errno_exit("iconv_open"); + // Try iconv_open() without "//TRANSLIT" + icd = iconv_open(codeset, GAME_FILE_CHARSET); + if (icd == (iconv_t) -1) { + errno_exit("iconv_open"); + } } } else { icd = (iconv_t) -1; @@ -469,7 +477,7 @@ bool save_game (int num) } need_icd = (strcmp(codeset, GAME_FILE_CHARSET) != 0); if (need_icd) { - icd = iconv_open(codeset, GAME_FILE_CHARSET); + icd = iconv_open(GAME_FILE_CHARSET, codeset); if (icd == (iconv_t) -1) { errno_exit("iconv_open"); } diff --git a/src/trader.h b/src/trader.h index 0c61045..0ae2f4c 100644 --- a/src/trader.h +++ b/src/trader.h @@ -58,6 +58,7 @@ #ifdef USE_UTF8_GAME_FILE # define GAME_FILE_CHARSET "UTF-8" // For strings in game file +# define GAME_FILE_TRANSLIT "//TRANSLIT" // Transliterate (GNU libiconv) #endif #define BUFSIZE 1024 // For various string buffers