summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrantišek Dvořák <valtri@users.sourceforge.net>2004-03-27 12:59:45 +0000
committerFrantišek Dvořák <valtri@users.sourceforge.net>2004-03-27 12:59:45 +0000
commit535d0d6a76675ce39fb52977a948eef0922a964b (patch)
tree00cd1e31a58908c30d60b1f4472e5a40a4fc985c
parentfce47bed538b68593085b841b329d64b65e913cd (diff)
downloadxine-lib-535d0d6a76675ce39fb52977a948eef0922a964b.tar.gz
xine-lib-535d0d6a76675ce39fb52977a948eef0922a964b.tar.bz2
"+y"+p code from xine-ui for guessing locale codeset (default encoding for OSD).
CVS patchset: 6309 CVS date: 2004/03/27 12:59:45
-rw-r--r--ChangeLog1
-rw-r--r--src/xine-engine/osd.c26
-rw-r--r--src/xine-utils/utils.c251
-rw-r--r--src/xine-utils/xineutils.h9
4 files changed, 270 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index b2d0aa853..b67cc896d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,5 @@
* fix the deadlock with non-seekable input plugins
+ * guess codeset for OSD if nl_langinfo(CODESET) is missing or not working
xine-lib (1-rc3b)
* fix SDL plugin that was broken in rc3
diff --git a/src/xine-engine/osd.c b/src/xine-engine/osd.c
index 1fb6ef915..3c80b144f 100644
--- a/src/xine-engine/osd.c
+++ b/src/xine-engine/osd.c
@@ -38,10 +38,6 @@
# include <iconv.h>
#endif
-#ifdef HAVE_LANGINFO_CODESET
-#include <langinfo.h>
-#endif
-
#define LOG_MODULE "osd"
#define LOG_VERBOSE
/*
@@ -899,32 +895,34 @@ static void osd_free_encoding(osd_object_t *osd) {
* "" ... locale encoding
*/
static int osd_set_encoding (osd_object_t *osd, const char *encoding) {
+ char *enc;
+
#ifdef HAVE_ICONV
osd_free_encoding(osd);
lprintf("osd=%p, encoding=%s\n", osd, encoding ? (encoding[0] ? encoding : "locale") : "no conversion");
+ /* no conversion, use latin1 */
if (!encoding) return 1;
+ /* get encoding from system */
if (!encoding[0]) {
-#ifdef HAVE_LANGINFO_CODESET
- if ((encoding = nl_langinfo(CODESET)) == NULL) {
+ if ((enc = xine_get_system_encoding()) == NULL) {
xprintf(osd->renderer->stream->xine, XINE_VERBOSITY_LOG,
_("osd: can't find out current locale character set\n"));
return 0;
}
-#else
- return 0;
-#endif
- lprintf("locale encoding='%s'\n", osd, encoding);
- }
+ lprintf("locale encoding='%s'\n", osd, enc);
+ } else
+ enc = strdup(encoding);
/* prepare conversion to UCS-2 */
- if ((osd->cd = iconv_open(UCS2_ENCODING, encoding)) == (iconv_t)-1) {
+ if ((osd->cd = iconv_open(UCS2_ENCODING, enc)) == (iconv_t)-1) {
xprintf(osd->renderer->stream->xine, XINE_VERBOSITY_LOG,
- _("osd: unsupported conversion %s -> %s, no conversion performed\n"), encoding, UCS2_ENCODING);
+ _("osd: unsupported conversion %s -> %s, no conversion performed\n"), enc, UCS2_ENCODING);
+ free(enc);
return 0;
}
- osd->encoding = strdup(encoding);
+ osd->encoding = enc;
return 1;
#else
return encoding == NULL;
diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c
index b07550421..f6d36dc9d 100644
--- a/src/xine-utils/utils.c
+++ b/src/xine-utils/utils.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: utils.c,v 1.23 2003/12/09 00:02:39 f1rmb Exp $
+ * $Id: utils.c,v 1.24 2004/03/27 12:59:46 valtri Exp $
*
*/
#define _POSIX_PTHREAD_SEMANTICS 1 /* for 5-arg getpwuid_r on solaris */
@@ -36,6 +36,186 @@
#if HAVE_UCONTEXT_H
#include <ucontext.h>
#endif
+#ifdef HAVE_LANGINFO_CODESET
+#include <langinfo.h>
+#endif
+
+
+typedef struct {
+ char *language;
+ char *encoding;
+ char *modifier;
+} lang_locale_t;
+
+
+static lang_locale_t lang_locales[] = {
+ { "af_ZA", "iso88591", NULL },
+ { "ar_AE", "iso88596", NULL },
+ { "ar_BH", "iso88596", NULL },
+ { "ar_DZ", "iso88596", NULL },
+ { "ar_EG", "iso88596", NULL },
+ { "ar_IN", "utf8", NULL },
+ { "ar_IQ", "iso88596", NULL },
+ { "ar_JO", "iso88596", NULL },
+ { "ar_KW", "iso88596", NULL },
+ { "ar_LB", "iso88596", NULL },
+ { "ar_LY", "iso88596", NULL },
+ { "ar_MA", "iso88596", NULL },
+ { "ar_OM", "iso88596", NULL },
+ { "ar_QA", "iso88596", NULL },
+ { "ar_SA", "iso88596", NULL },
+ { "ar_SD", "iso88596", NULL },
+ { "ar_SY", "iso88596", NULL },
+ { "ar_TN", "iso88596", NULL },
+ { "ar_YE", "iso88596", NULL },
+ { "be_BY", "cp1251", NULL },
+ { "bg_BG", "cp1251", NULL },
+ { "br_FR", "iso88591", NULL },
+ { "bs_BA", "iso88592", NULL },
+ { "ca_ES", "iso88591", NULL },
+ { "ca_ES", "iso885915", "euro" },
+ { "cs_CZ", "iso88592", NULL },
+ { "cy_GB", "iso885914", NULL },
+ { "da_DK", "iso88591", NULL },
+ { "de_AT", "iso88591", NULL },
+ { "de_AT", "iso885915", "euro" },
+ { "de_BE", "iso88591", NULL },
+ { "de_BE", "iso885915", "euro" },
+ { "de_CH", "iso88591", NULL },
+ { "de_DE", "iso88591", NULL },
+ { "de_DE", "iso885915", "euro" },
+ { "de_LU", "iso88591", NULL },
+ { "de_LU", "iso885915", "euro" },
+ { "el_GR", "iso88597", NULL },
+ { "en_AU", "iso88591", NULL },
+ { "en_BW", "iso88591", NULL },
+ { "en_CA", "iso88591", NULL },
+ { "en_DK", "iso88591", NULL },
+ { "en_GB", "iso88591", NULL },
+ { "en_HK", "iso88591", NULL },
+ { "en_IE", "iso88591", NULL },
+ { "en_IE", "iso885915", "euro" },
+ { "en_IN", "utf8", NULL },
+ { "en_NZ", "iso88591", NULL },
+ { "en_PH", "iso88591", NULL },
+ { "en_SG", "iso88591", NULL },
+ { "en_US", "iso88591", NULL },
+ { "en_ZA", "iso88591", NULL },
+ { "en_ZW", "iso88591", NULL },
+ { "es_AR", "iso88591", NULL },
+ { "es_BO", "iso88591", NULL },
+ { "es_CL", "iso88591", NULL },
+ { "es_CO", "iso88591", NULL },
+ { "es_CR", "iso88591", NULL },
+ { "es_DO", "iso88591", NULL },
+ { "es_EC", "iso88591", NULL },
+ { "es_ES", "iso88591", NULL },
+ { "es_ES", "iso885915", "euro" },
+ { "es_GT", "iso88591", NULL },
+ { "es_HN", "iso88591", NULL },
+ { "es_MX", "iso88591", NULL },
+ { "es_NI", "iso88591", NULL },
+ { "es_PA", "iso88591", NULL },
+ { "es_PE", "iso88591", NULL },
+ { "es_PR", "iso88591", NULL },
+ { "es_PY", "iso88591", NULL },
+ { "es_SV", "iso88591", NULL },
+ { "es_US", "iso88591", NULL },
+ { "es_UY", "iso88591", NULL },
+ { "es_VE", "iso88591", NULL },
+ { "et_EE", "iso88591", NULL },
+ { "eu_ES", "iso88591", NULL },
+ { "eu_ES", "iso885915", "euro" },
+ { "fa_IR", "utf8", NULL },
+ { "fi_FI", "iso88591", NULL },
+ { "fi_FI", "iso885915", "euro" },
+ { "fo_FO", "iso88591", NULL },
+ { "fr_BE", "iso88591", NULL },
+ { "fr_BE", "iso885915", "euro" },
+ { "fr_CA", "iso88591", NULL },
+ { "fr_CH", "iso88591", NULL },
+ { "fr_FR", "iso88591", NULL },
+ { "fr_FR", "iso885915", "euro" },
+ { "fr_LU", "iso88591", NULL },
+ { "fr_LU", "iso885915", "euro" },
+ { "ga_IE", "iso88591", NULL },
+ { "ga_IE", "iso885915", "euro" },
+ { "gl_ES", "iso88591", NULL },
+ { "gl_ES", "iso885915", "euro" },
+ { "gv_GB", "iso88591", NULL },
+ { "he_IL", "iso88598", NULL },
+ { "hi_IN", "utf8", NULL },
+ { "hr_HR", "iso88592", NULL },
+ { "hu_HU", "iso88592", NULL },
+ { "id_ID", "iso88591", NULL },
+ { "is_IS", "iso88591", NULL },
+ { "it_CH", "iso88591", NULL },
+ { "it_IT", "iso88591", NULL },
+ { "it_IT", "iso885915", "euro" },
+ { "iw_IL", "iso88598", NULL },
+ { "ja_JP", "eucjp", NULL },
+ { "ja_JP", "ujis", NULL },
+ { "japanese", "euc", NULL },
+ { "ka_GE", "georgianps", NULL },
+ { "kl_GL", "iso88591", NULL },
+ { "ko_KR", "euckr", NULL },
+ { "ko_KR", "utf8", NULL },
+ { "korean", "euc", NULL },
+ { "kw_GB", "iso88591", NULL },
+ { "lt_LT", "iso885913", NULL },
+ { "lv_LV", "iso885913", NULL },
+ { "mi_NZ", "iso885913", NULL },
+ { "mk_MK", "iso88595", NULL },
+ { "mr_IN", "utf8", NULL },
+ { "ms_MY", "iso88591", NULL },
+ { "mt_MT", "iso88593", NULL },
+ { "nb_NO", "ISO-8859-1", NULL },
+ { "nl_BE", "iso88591", NULL },
+ { "nl_BE", "iso885915", "euro" },
+ { "nl_NL", "iso88591", NULL },
+ { "nl_NL", "iso885915", "euro" },
+ { "nn_NO", "iso88591", NULL },
+ { "no_NO", "iso88591", NULL },
+ { "oc_FR", "iso88591", NULL },
+ { "pl_PL", "iso88592", NULL },
+ { "pt_BR", "iso88591", NULL },
+ { "pt_PT", "iso88591", NULL },
+ { "pt_PT", "iso885915", "euro" },
+ { "ro_RO", "iso88592", NULL },
+ { "ru_RU", "iso88595", NULL },
+ { "ru_RU", "koi8r", NULL },
+ { "ru_UA", "koi8u", NULL },
+ { "se_NO", "utf8", NULL },
+ { "sk_SK", "iso88592", NULL },
+ { "sl_SI", "iso88592", NULL },
+ { "sq_AL", "iso88591", NULL },
+ { "sr_YU", "iso88592", NULL },
+ { "sr_YU", "iso88595", "cyrillic" },
+ { "sv_FI", "iso88591", NULL },
+ { "sv_FI", "iso885915", "euro" },
+ { "sv_SE", "iso88591", NULL },
+ { "ta_IN", "utf8", NULL },
+ { "te_IN", "utf8", NULL },
+ { "tg_TJ", "koi8t", NULL },
+ { "th_TH", "tis620", NULL },
+ { "tl_PH", "iso88591", NULL },
+ { "tr_TR", "iso88599", NULL },
+ { "uk_UA", "koi8u", NULL },
+ { "ur_PK", "utf8", NULL },
+ { "uz_UZ", "iso88591", NULL },
+ { "vi_VN", "tcvn", NULL },
+ { "vi_VN", "utf8", NULL },
+ { "wa_BE", "iso88591", NULL },
+ { "wa_BE", "iso885915", "euro" },
+ { "yi_US", "cp1255", NULL },
+ { "zh_CN", "gb18030", NULL },
+ { "zh_CN", "gb2312", NULL },
+ { "zh_CN", "gbk", NULL },
+ { "zh_HK", "big5hkscs", NULL },
+ { "zh_TW", "big5", NULL },
+ { "zh_TW", "euctw", NULL },
+ { NULL, NULL, NULL }
+};
void *xine_xmalloc(size_t size) {
@@ -142,6 +322,7 @@ void xine_usec_sleep(unsigned usec) {
#endif
}
+
/* print a hexdump of length bytes from the data given in buf */
void xine_hexdump (const char *buf, int length) {
int i,j;
@@ -178,6 +359,74 @@ void xine_hexdump (const char *buf, int length) {
}
+static const lang_locale_t *_get_first_lang_locale(char *lcal) {
+ const lang_locale_t *llocale;
+
+ if(lcal && strlen(lcal)) {
+ llocale = &*lang_locales;
+
+ while(llocale->language) {
+ if(!strncmp(lcal, llocale->language, strlen(lcal)))
+ return llocale;
+
+ llocale++;
+ }
+ }
+ return NULL;
+}
+
+
+/*
+ * get encoding of current locale
+ */
+char *xine_get_system_encoding() {
+ char *codeset = NULL;
+
+#ifdef HAVE_LANGINFO_CODESET
+ codeset = nl_langinfo(CODESET);
+#endif
+ /*
+ * guess locale codeset according to shell variables
+ * when nl_langinfo(CODESET) isn't available or workig
+ */
+ if (!codeset || strstr(codeset, "ANSI") != 0) {
+ char *lang;
+
+ if(!(lang = getenv("LC_ALL")))
+ if(!(lang = getenv("LC_MESSAGES")))
+ lang = getenv("LANG");
+
+ codeset = NULL;
+
+ if(lang) {
+ char *lg, *enc, *mod;
+
+ lg = strdup(lang);
+
+ if((enc = strchr(lg, '.')) && (strlen(enc) > 1)) {
+ enc++;
+
+ if((mod = strchr(enc, '@')))
+ *mod = '\0';
+
+ codeset = strdup(enc);
+ }
+ else {
+ const lang_locale_t *llocale = _get_first_lang_locale(lg);
+
+ if(llocale && llocale->encoding)
+ codeset = strdup(llocale->encoding);
+ }
+
+ free(lg);
+ }
+ } else
+ codeset = strdup(codeset);
+
+ return codeset;
+}
+
+
#ifndef HAVE_BASENAME
#define FILESYSTEM_PREFIX_LEN(filename) 0
diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h
index dbd1365ba..f78312e28 100644
--- a/src/xine-utils/xineutils.h
+++ b/src/xine-utils/xineutils.h
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: xineutils.h,v 1.81 2004/03/18 16:50:00 komadori Exp $
+ * $Id: xineutils.h,v 1.82 2004/03/27 12:59:46 valtri Exp $
*
*/
#ifndef XINEUTILS_H
@@ -1084,8 +1084,13 @@ void xine_list_insert_content (xine_list_t *l, void *content);
*/
void xine_list_delete_current (xine_list_t *l);
+/**
+ * get encoding of current locale
+ */
+char *xine_get_system_encoding();
+
#ifndef HAVE_BASENAME
-/*
+/**
* get base name
*/
char *basename (char const *name);