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
This commit is contained in:
J. Alexander Treuman 2007-01-08 04:31:44 +00:00
parent 90b4af0341
commit 438c1add9d
5 changed files with 32 additions and 11 deletions

View File

@ -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 {

View File

@ -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);

View File

@ -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)

View File

@ -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();

View File

@ -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);