From d15752f082af7e941cc55f5f71ea5cff1a6b4653 Mon Sep 17 00:00:00 2001 From: Kalle Wallin Date: Mon, 22 Mar 2004 12:43:30 +0000 Subject: Updated charset support git-svn-id: https://svn.musicpd.org/ncmpc/trunk@364 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- support.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'support.c') diff --git a/support.c b/support.c index d2dc9759c..15f084c1c 100644 --- a/support.c +++ b/support.c @@ -5,31 +5,35 @@ #include #include "config.h" +#include "support.h" #ifdef HAVE_LOCALE_H -#ifdef HAVE_LANGINFO_H -#ifdef HAVE_ICONV #include -#include -#include -#define ENABLE_CHARACTER_SET_CONVERSION -#endif #endif + +#ifdef HAVE_ICONV +#include #endif -#include "support.h" +#ifdef HAVE_LANGINFO_CODESET +#include +#endif #define BUFSIZE 1024 -#ifdef ENABLE_CHARACTER_SET_CONVERSION -static char *locale = NULL; + static char *charset = NULL; + +#ifdef HAVE_LOCALE_H +static char *locale = NULL; +#endif + +#ifdef HAVE_ICONV iconv_t iconv_from_uft8 = (iconv_t)(-1); iconv_t iconv_to_uft8 = (iconv_t)(-1); #endif - #ifndef HAVE_LIBGEN_H char * @@ -71,21 +75,28 @@ basename(char *path) int charset_init(void) { -#ifdef ENABLE_CHARACTER_SET_CONVERSION +#ifdef HAVE_LOCALE_H /* get current locale */ if( (locale=setlocale(LC_CTYPE,"")) == NULL ) { fprintf(stderr,"setlocale() - failed!\n"); return -1; } +#endif +#ifdef HAVE_LANGINFO_CODESET /* get charset */ if( (charset=nl_langinfo(CODESET)) == NULL ) { - fprintf(stderr,"nl_langinfo() - failed!\n"); - return -1; + fprintf(stderr, + "nl_langinfo() failed using default:" DEFAULT_CHARSET "\n"); } - +#endif + + if( charset==NULL ) + charset = DEFAULT_CHARSET; + +#ifdef HAVE_ICONV /* allocate descriptor for character set conversion */ iconv_from_uft8 = iconv_open(charset, "UTF-8"); if( iconv_from_uft8 == (iconv_t)(-1) ) @@ -101,7 +112,7 @@ charset_init(void) int charset_close(void) { -#ifdef ENABLE_CHARACTER_SET_CONVERSION +#ifdef HAVE_ICONV if( iconv_from_uft8 == (iconv_t)(-1) ) { iconv_close(iconv_from_uft8); @@ -121,7 +132,7 @@ charset_close(void) char * utf8_to_locale(char *str) { -#ifdef ENABLE_CHARACTER_SET_CONVERSION +#ifdef HAVE_ICONV size_t inleft; size_t retlen; char *ret; -- cgit v1.2.3