From d15752f082af7e941cc55f5f71ea5cff1a6b4653 Mon Sep 17 00:00:00 2001 From: Kalle Wallin Date: Mon, 22 Mar 2004 12:43:30 +0000 Subject: [PATCH] Updated charset support git-svn-id: https://svn.musicpd.org/ncmpc/trunk@364 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- configure.ac | 64 ++++++++++++++++++++++++++++------------------------ support.c | 43 ++++++++++++++++++++++------------- 2 files changed, 62 insertions(+), 45 deletions(-) diff --git a/configure.ac b/configure.ac index 1d537c6..6452834 100644 --- a/configure.ac +++ b/configure.ac @@ -17,24 +17,6 @@ dnl ======================================================= set -- $CFLAGS CFLAGS="-Wall $CFLAGS" - - -dnl -dnl Check for libaries -dnl - -dnl ncurses -AC_CHECK_LIB(ncurses, initscr,, [AC_MSG_ERROR(ncurses library is required)]) - -dnl glib-2.0 -AM_PATH_GLIB_2_0(, , [AC_MSG_ERROR(glib-2.x is required)], glib) - -dnl popt -AC_CHECK_LIB(popt, - poptGetArg, - LIBS="$LIBS -lpopt", - AC_MSG_ERROR(Missing popt command line parsing library)) - dnl dnl Check for types dnl @@ -42,24 +24,41 @@ AC_CHECK_TYPE(socklen_t, AC_DEFINE(HAVE_SOCKLEN_T, 1, socklen_t defined in sys/socket.h), ) + dnl dnl Check for headers dnl -AM_ICONV - -AC_CHECK_HEADER(langinfo.h, - AC_DEFINE(HAVE_LANGINFO_H, 1, langinfo.h), +AC_CHECK_HEADER(libgen.h, + AC_DEFINE(HAVE_LIBGEN_H, 1, glibc - libgen.h), ,) AC_CHECK_HEADER(locale.h, - AC_DEFINE(HAVE_LOCALE_H, 1, locale.h), + AC_DEFINE(HAVE_LOCALE_H, 1, locale.h), ,) -AC_CHECK_HEADER(libgen.h, - AC_DEFINE(HAVE_LIBGEN_H, 1, glibc - libgen.h), - ,) +dnl +dnl Check for libaries +dnl + +dnl iconv +AM_ICONV + +dnl nl_langinfo() +AM_LANGINFO_CODESET + +dnl ncurses +AC_CHECK_LIB(ncurses, initscr,, [AC_MSG_ERROR(ncurses library is required)]) + +dnl glib-2.0 +AM_PATH_GLIB_2_0(, , [AC_MSG_ERROR(glib-2.x is required)], glib) + +dnl popt +AC_CHECK_LIB(popt, + poptGetArg, + LIBS="$LIBS -lpopt", + AC_MSG_ERROR(Missing popt command line parsing library)) dnl dnl X11 @@ -76,6 +75,12 @@ if test "$enable_debug" = yes; then CFLAGS="$CFLAGS -g -DDEBUG" fi +dnl Default charset +AC_ARG_WITH(default-charset, + [ --with-default-charset=ARG Default charset (ISO-8859-1)], + DEFAULT_CHARSET="$withval", + DEFAULT_CHARSET="ISO-8859-1") + dnl Default host AC_ARG_WITH(default-host, [ --with-default-host=HOST Default host (localhost)], @@ -94,9 +99,10 @@ LIBS="$LIBS $GLIB_LIBS -lncurses" dnl Autoheader -AC_DEFINE_UNQUOTED(DEFAULT_PORT, $DEFAULT_PORT, Default MPD port) -AC_DEFINE_UNQUOTED(DEFAULT_PORT_STR, "$DEFAULT_PORT", Default MPD port) -AC_DEFINE_UNQUOTED(DEFAULT_HOST, "$DEFAULT_HOST", Default MPD host) +AC_DEFINE_UNQUOTED(DEFAULT_PORT, $DEFAULT_PORT, Default MPD port) +AC_DEFINE_UNQUOTED(DEFAULT_PORT_STR, "$DEFAULT_PORT", Default MPD port) +AC_DEFINE_UNQUOTED(DEFAULT_HOST, "$DEFAULT_HOST", Default MPD host) +AC_DEFINE_UNQUOTED(DEFAULT_CHARSET, "$DEFAULT_CHARSET", Default charset) AM_CONFIG_HEADER(config.h) diff --git a/support.c b/support.c index d2dc975..15f084c 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; -- 2.30.2