aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJ. Alexander Treuman <jat@spatialrift.net>2007-02-18 00:42:22 +0000
committerJ. Alexander Treuman <jat@spatialrift.net>2007-02-18 00:42:22 +0000
commit7b1e14b8e81c2dc44def58f2781bcfcc3cc9e58b (patch)
tree16ed8f0c622cc6c9d7569d12c9442992cc23b4b5 /src
parentd7e8507eaf9ac76d207a51ac850964b9373ba2d3 (diff)
downloadmpd-7b1e14b8e81c2dc44def58f2781bcfcc3cc9e58b.tar.gz
mpd-7b1e14b8e81c2dc44def58f2781bcfcc3cc9e58b.tar.xz
mpd-7b1e14b8e81c2dc44def58f2781bcfcc3cc9e58b.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/charConv.c7
-rw-r--r--src/charConv.h2
-rw-r--r--src/localization.c105
-rw-r--r--src/localization.h27
-rw-r--r--src/log.c27
-rw-r--r--src/main.c3
-rw-r--r--src/path.c56
8 files changed, 58 insertions, 171 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index be9cd2a31..0207cb90f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -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
diff --git a/src/charConv.c b/src/charConv.c
index de1fcbbae..5392bcecb 100644
--- a/src/charConv.c
+++ b/src/charConv.c
@@ -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) {
diff --git a/src/charConv.h b/src/charConv.h
index f2d619469..d3d0fa70d 100644
--- a/src/charConv.h
+++ b/src/charConv.h
@@ -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
diff --git a/src/localization.c b/src/localization.c
deleted file mode 100644
index b58c83945..000000000
--- a/src/localization.c
+++ /dev/null
@@ -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);
-}
diff --git a/src/localization.h b/src/localization.h
deleted file mode 100644
index 75a0b0b68..000000000
--- a/src/localization.h
+++ /dev/null
@@ -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);
diff --git a/src/log.c b/src/log.c
index b2e1e1339..5185bb9c3 100644
--- a/src/log.c
+++ b/src/log.c
@@ -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;
}
diff --git a/src/main.c b/src/main.c
index 79600223b..41db55b79 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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();
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 <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);