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
This commit is contained in:
J. Alexander Treuman 2007-02-18 00:42:22 +00:00
parent d7e8507eaf
commit 7b1e14b8e8
8 changed files with 58 additions and 171 deletions

View File

@ -73,7 +73,6 @@ mpd_headers = \
utf8.h \
utils.h \
volume.h \
localization.h \
zeroconf.h
@ -124,7 +123,6 @@ mpd_SOURCES = \
utils.c \
volume.c \
utf8.c \
localization.c \
zeroconf.c

View File

@ -150,13 +150,6 @@ char *convStrDup(char *string)
return NULL;
}
char *convCharset(char *to, char *from, char *str, char *ret)
{
if (ret)
free(ret);
return setCharSetConversion(to, from) ? NULL : convStrDup(str);
}
static void closeCharSetConversion(void)
{
if (char_conv_to) {

View File

@ -25,6 +25,4 @@ int setCharSetConversion(char *to, char *from);
char *convStrDup(char *string);
char *convCharset(char *to, char *from, char *str, char *ret);
#endif

View File

@ -1,105 +0,0 @@
/* the Music Player Daemon (MPD)
* (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
* This project's homepage is: http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "localization.h"
#include "charConv.h"
#include "utils.h"
#include "log.h"
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_LOCALE
#ifdef HAVE_LANGINFO_CODESET
#include <locale.h>
#include <langinfo.h>
#endif
#endif
static char *localeCharset;
char *utf8ToLocaleCharset(char *str)
{
static char *ret;
if (localeCharset)
ret = convCharset(localeCharset, "UTF-8", str, ret);
if (!ret)
ret = xstrdup(str);
return ret;
}
void setLocaleCharset(char *charset)
{
if (localeCharset)
free(localeCharset);
localeCharset = charset;
}
char *getLocaleCharset(void)
{
return localeCharset;
}
void initLocalization(void)
{
#ifdef HAVE_LOCALE
#ifdef HAVE_LANGINFO_CODESET
char *temp;
char *originalLocale;
char *currentLocale;
if (!(originalLocale = setlocale(LC_CTYPE, NULL))) {
WARNING("problems getting locale with setlocale()\n");
} else {
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);
setLocaleCharset(xstrdup("ISO-8859-1"));
} else if ((temp = nl_langinfo(CODESET))) {
setLocaleCharset(xstrdup(temp));
} else {
WARNING("problems getting charset for "
"locale\n");
}
if (!setlocale(LC_CTYPE, originalLocale)) {
WARNING("problems resetting locale with "
"setlocale()\n");
}
}
free(originalLocale);
}
#endif
#endif
}
void finishLocalization(void)
{
setLocaleCharset(NULL);
}

View File

@ -1,27 +0,0 @@
/* the Music Player Daemon (MPD)
* (c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
* This project's homepage is: http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
char *utf8ToLocaleCharset(char *str);
void setLocaleCharset(char *charset);
char *getLocaleCharset(void);
void initLocalization(void);
void finishLocalization(void);

View File

@ -21,7 +21,6 @@
#include "conf.h"
#include "myfprintf.h"
#include "utils.h"
#include "localization.h"
#include <assert.h>
#include <stdlib.h>
@ -87,17 +86,9 @@ static void buffer_warning(const char *fmt, va_list args)
static void do_log(FILE *fp, const char *fmt, va_list args)
{
char buffer[BUFFER_LENGTH + 1];
char *localized;
if (!stdout_mode) {
if (!stdout_mode)
fwrite(log_date(), 15, 1, fp);
vfprintf(fp, fmt, args);
} else {
vsnprintf(buffer, BUFFER_LENGTH, fmt, args);
localized = utf8ToLocaleCharset(buffer);
fputs(localized, fp);
}
vfprintf(fp, fmt, args);
}
void flushWarningLog(void)
@ -109,14 +100,12 @@ void flushWarningLog(void)
if (warningBuffer != NULL)
{
while (s != NULL) {
char *next = strchr(s, '\n');
if (next == NULL) break;
*next = '\0';
next++;
if (stdout_mode)
fprintf(stderr, "%s\n", utf8ToLocaleCharset(s));
else
fprintf(stderr, "%s\n", s);
char * next = strchr(s, '\n');
if (next != NULL) {
*next = '\0';
next++;
}
fprintf(stderr, "%s\n", s);
s = next;
}

View File

@ -43,7 +43,6 @@
#include "utils.h"
#include "normalize.h"
#include "zeroconf.h"
#include "localization.h"
#include <stdio.h>
#include <sys/select.h>
@ -421,7 +420,6 @@ int main(int argc, char *argv[])
closeAllFDs();
initLocalization();
initConf();
parseOptions(argc, argv, &options);
@ -494,7 +492,6 @@ int main(int argc, char *argv[])
finishAudioConfig();
finishVolume();
finishPaths();
finishLocalization();
finishPermissions();
finishCommands();
finishInputPlugins();

View File

@ -22,7 +22,6 @@
#include "conf.h"
#include "utf8.h"
#include "utils.h"
#include "localization.h"
#include <stdlib.h>
#include <string.h>
@ -32,15 +31,29 @@
#include <errno.h>
#include <dirent.h>
#ifdef HAVE_LOCALE
#ifdef HAVE_LANGINFO_CODESET
#include <locale.h>
#include <langinfo.h>
#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);