From ab7b4998b156a959c21b8d277f5ae114f48427c9 Mon Sep 17 00:00:00 2001 From: Kalle Wallin Date: Sun, 6 Jun 2004 14:11:06 +0000 Subject: [PATCH] Moved charset initialization code to main.c, added bind_textdomain_codeset() git-svn-id: https://svn.musicpd.org/ncmpc/trunk@1350 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/main.c | 20 +++++++++++++++----- src/support.c | 41 ++++++++--------------------------------- src/support.h | 3 +-- 3 files changed, 24 insertions(+), 40 deletions(-) diff --git a/src/main.c b/src/main.c index 15ecf45..1a3573e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,4 +1,6 @@ /* + * $Id$ + * * (c) 2004 by Kalle Wallin (kaw@linux.se) * * This program is free software; you can redistribute it and/or modify @@ -40,7 +42,6 @@ exit_and_cleanup(void) { screen_exit(); printf("\n"); - charset_close(); if( mpc ) { if( mpc_error(mpc) ) @@ -66,11 +67,24 @@ main(int argc, const char *argv[]) options_t *options; struct sigaction act; gboolean connected; + const char *charset = NULL; + + /* initialize charset */ +#ifdef HAVE_LOCALE_H + if( setlocale(LC_CTYPE,"") == NULL ) + { + g_printerr("setlocale() - failed!\n"); + exit(EXIT_FAILURE); + } + charset_init(g_get_charset(&charset)); + D(printf("charset: %s\n", charset)); +#endif /* initialize i18n support */ #ifdef ENABLE_NLS setlocale(LC_MESSAGES, ""); bindtextdomain(GETTEXT_PACKAGE, LOCALE_DIR); + bind_textdomain_codeset(GETTEXT_PACKAGE, charset); textdomain(GETTEXT_PACKAGE); #endif @@ -93,10 +107,6 @@ main(int argc, const char *argv[]) /* parse command line options - 2 pass */ options_parse(argc, argv); - /* initialize local charset */ - if( charset_init() ) - exit(EXIT_FAILURE); - /* setup signal behavior - SIGINT */ sigemptyset( &act.sa_mask ); act.sa_flags = 0; diff --git a/src/support.c b/src/support.c index 8cb4eca..6ba2612 100644 --- a/src/support.c +++ b/src/support.c @@ -1,4 +1,6 @@ /* + * $Id$ + * * (c) 2004 by Kalle Wallin (kaw@linux.se) * * This program is free software; you can redistribute it and/or modify @@ -26,16 +28,10 @@ #include "ncmpc.h" #include "support.h" -#ifdef HAVE_LOCALE_H -#include -#endif - #define BUFSIZE 1024 extern void screen_status_printf(char *format, ...); -static const char *charset = NULL; -static const char *locale = NULL; static gboolean noconvert = TRUE; char * @@ -120,34 +116,10 @@ strcasestr(const char *haystack, const char *needle) } #endif /* HAVE_STRCASESTR */ - -int -charset_init(void) -{ -#ifdef HAVE_LOCALE_H - /* get current locale */ - if( (locale=setlocale(LC_CTYPE,"")) == NULL ) - { - g_printerr("setlocale() - failed!\n"); - return -1; - } -#endif - - /* get charset */ - noconvert = g_get_charset(&charset); - -#ifdef DEBUG - g_printerr("charset: %s [%d]\n", charset, noconvert); - fflush(stderr); -#endif - - return 0; -} - -int -charset_close(void) +void +charset_init(gboolean disable) { - return 0; + noconvert = disable; } char * @@ -169,6 +141,9 @@ utf8_to_locale(char *utf8str) &error); if( error ) { + const char *charset; + + g_get_charset(&charset); screen_status_printf(_("Error: Unable to convert characters to %s"), charset); D(g_printerr("utf8_to_locale(): %s\n", error->message)); diff --git a/src/support.h b/src/support.h index 1f3aca1..2b79e3a 100644 --- a/src/support.h +++ b/src/support.h @@ -16,8 +16,7 @@ char *remove_trailing_slash(char *path); char *lowerstr(char *str); char *strcasestr(const char *haystack, const char *needle); -int charset_init(void); -int charset_close(void); +void charset_init(gboolean disable); char *utf8_to_locale(char *str); char *locale_to_utf8(char *str); -- 2.30.2