From 7b1e14b8e81c2dc44def58f2781bcfcc3cc9e58b Mon Sep 17 00:00:00 2001 From: "J. Alexander Treuman" Date: Sun, 18 Feb 2007 00:42:22 +0000 Subject: Reverting all of my localization changes. It was a horrible implementation, and fixing it is a big enough job that I don't know when I'll get around to it. Probably best just starting from scratch anyhow. git-svn-id: https://svn.musicpd.org/mpd/trunk@5373 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/path.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'src/path.c') diff --git a/src/path.c b/src/path.c index 0753727ea..118731c5d 100644 --- a/src/path.c +++ b/src/path.c @@ -22,7 +22,6 @@ #include "conf.h" #include "utf8.h" #include "utils.h" -#include "localization.h" #include #include @@ -32,15 +31,29 @@ #include #include +#ifdef HAVE_LOCALE +#ifdef HAVE_LANGINFO_CODESET +#include +#include +#endif +#endif + const char *musicDir; static const char *playlistDir; static char *fsCharset; +static char *pathConvCharset(char *to, char *from, char *str, char *ret) +{ + if (ret) + free(ret); + return setCharSetConversion(to, from) ? NULL : convStrDup(str); +} + char *fsCharsetToUtf8(char *str) { static char *ret; - ret = convCharset("UTF-8", fsCharset, str, ret); + ret = pathConvCharset("UTF-8", fsCharset, str, ret); if (ret && !validUtf8String(ret)) { free(ret); @@ -54,7 +67,7 @@ char *utf8ToFsCharset(char *str) { static char *ret; - ret = convCharset(fsCharset, "UTF-8", str, ret); + ret = pathConvCharset(fsCharset, "UTF-8", str, ret); if (!ret) ret = xstrdup(str); @@ -122,6 +135,7 @@ void initPaths(void) ConfigParam *fsCharsetParam = getConfigParam(CONF_FS_CHARSET); char *charset = NULL; + char *originalLocale; DIR *dir; musicDir = appendSlash(&(musicParam->value)); @@ -143,10 +157,40 @@ void initPaths(void) } closedir(dir); - if (fsCharsetParam) + if (fsCharsetParam) { charset = xstrdup(fsCharsetParam->value); - else if ((charset = getLocaleCharset())) - charset = xstrdup(charset); + } +#ifdef HAVE_LOCALE +#ifdef HAVE_LANGINFO_CODESET + else if ((originalLocale = setlocale(LC_CTYPE, NULL))) { + char *temp; + char *currentLocale; + originalLocale = xstrdup(originalLocale); + + if (!(currentLocale = setlocale(LC_CTYPE, ""))) { + WARNING("problems setting current locale with " + "setlocale()\n"); + } else { + if (strcmp(currentLocale, "C") == 0 || + strcmp(currentLocale, "POSIX") == 0) { + WARNING("current locale is \"%s\"\n", + currentLocale); + } else if ((temp = nl_langinfo(CODESET))) { + charset = xstrdup(temp); + } else + WARNING + ("problems getting charset for locale\n"); + if (!setlocale(LC_CTYPE, originalLocale)) { + WARNING + ("problems resetting locale with setlocale()\n"); + } + } + + free(originalLocale); + } else + WARNING("problems getting locale with setlocale()\n"); +#endif +#endif if (charset) { setFsCharset(charset); -- cgit v1.2.3