aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.c20
-rw-r--r--src/support.c41
-rw-r--r--src/support.h3
3 files changed, 24 insertions, 40 deletions
diff --git a/src/main.c b/src/main.c
index 15ecf4532..1a3573e7a 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 8cb4ecafd..6ba261213 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 <locale.h>
-#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 1f3aca160..2b79e3aef 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);