aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJ. Alexander Treuman <jat@spatialrift.net>2007-01-08 04:31:44 +0000
committerJ. Alexander Treuman <jat@spatialrift.net>2007-01-08 04:31:44 +0000
commit438c1add9de7aff5968add3b9e02fac30a62e74a (patch)
tree3d4a982db74f0c6d7da66f8bf5e746217f8f9545 /src
parent90b4af03410cb151225853c458546abe6d696f1c (diff)
downloadmpd-438c1add9de7aff5968add3b9e02fac30a62e74a.tar.gz
mpd-438c1add9de7aff5968add3b9e02fac30a62e74a.tar.xz
mpd-438c1add9de7aff5968add3b9e02fac30a62e74a.zip
Convert log messages sent to stdout to the current locale's charset.
git-svn-id: https://svn.musicpd.org/mpd/trunk@5227 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/localization.c16
-rw-r--r--src/localization.h2
-rw-r--r--src/log.c13
-rw-r--r--src/main.c2
-rw-r--r--src/path.c10
5 files changed, 32 insertions, 11 deletions
diff --git a/src/localization.c b/src/localization.c
index 23250a6a9..f2f51d911 100644
--- a/src/localization.c
+++ b/src/localization.c
@@ -17,6 +17,7 @@
*/
#include "localization.h"
+#include "charConv.h"
#include "utils.h"
#include <stdlib.h>
@@ -30,6 +31,19 @@
static char *localeCharset = NULL;
+char *utf8ToLocaleCharset(char *str)
+{
+ static char *ret = NULL;
+
+ if (localeCharset)
+ ret = convCharset(localeCharset, "UTF-8", str, ret);
+
+ if (!ret)
+ ret = xstrdup(str);
+
+ return ret;
+}
+
void setLocaleCharset(char *charset)
{
if (localeCharset)
@@ -63,7 +77,7 @@ void initLocalization(void)
strcmp(currentLocale, "POSIX") == 0) {
WARNING("current locale is \"%s\"\n",
currentLocale);
- setLocaleCharset(xstrdup(""));
+ setLocaleCharset(xstrdup("ISO-8859-1"));
} else if ((temp = nl_langinfo(CODESET))) {
setLocaleCharset(xstrdup(temp));
} else {
diff --git a/src/localization.h b/src/localization.h
index b70692358..75a0b0b68 100644
--- a/src/localization.h
+++ b/src/localization.h
@@ -16,6 +16,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+char *utf8ToLocaleCharset(char *str);
+
void setLocaleCharset(char *charset);
char *getLocaleCharset(void);
diff --git a/src/log.c b/src/log.c
index 2e6eb3575..d38de4f25 100644
--- a/src/log.c
+++ b/src/log.c
@@ -21,6 +21,7 @@
#include "conf.h"
#include "myfprintf.h"
#include "utils.h"
+#include "localization.h"
#include <assert.h>
#include <stdlib.h>
@@ -86,9 +87,17 @@ static void buffer_warning(const char *fmt, va_list args)
static void do_log(FILE *fp, const char *fmt, va_list args)
{
- if (!stdout_mode)
+ char buffer[BUFFER_LENGTH + 1];
+ char *localized;
+
+ if (!stdout_mode) {
fwrite(log_date(), 15, 1, fp);
- vfprintf(fp, fmt, args);
+ vfprintf(fp, fmt, args);
+ } else {
+ vsnprintf(buffer, BUFFER_LENGTH, fmt, args);
+ localized = utf8ToLocaleCharset(buffer);
+ fputs(localized, fp);
+ }
}
void flushWarningLog(void)
diff --git a/src/main.c b/src/main.c
index a09e8a6ad..e32146e6c 100644
--- a/src/main.c
+++ b/src/main.c
@@ -429,6 +429,7 @@ int main(int argc, char *argv[])
initStats();
initTagConfig();
+ initLocalization();
initLog(options.verbose);
if (options.createDB <= 0 && !options.updateDB)
@@ -438,7 +439,6 @@ int main(int argc, char *argv[])
open_log_files(options.stdOutput);
- initLocalization();
initPaths();
initPermissions();
initPlaylist();
diff --git a/src/path.c b/src/path.c
index 35836ea46..21597f5e6 100644
--- a/src/path.c
+++ b/src/path.c
@@ -143,14 +143,10 @@ void initPaths(void)
}
closedir(dir);
- if (fsCharsetParam) {
+ if (fsCharsetParam)
charset = xstrdup(fsCharsetParam->value);
- } else if ((charset = getLocaleCharset())) {
- if (*charset == '\0')
- charset = NULL;
- else
- charset = xstrdup(charset);
- }
+ else if ((charset = getLocaleCharset()))
+ charset = xstrdup(charset);
if (charset) {
setFsCharset(charset);