diff options
Diffstat (limited to '')
-rw-r--r-- | src/localization.c | 16 | ||||
-rw-r--r-- | src/localization.h | 2 | ||||
-rw-r--r-- | src/log.c | 13 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/path.c | 10 |
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); @@ -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); |