diff --git a/Makefile.am b/Makefile.am index 0f3e3218..e5860b27 100644 --- a/Makefile.am +++ b/Makefile.am @@ -53,6 +53,8 @@ mocp_SOURCES = log.c \ tags_cache.h \ utf8.c \ utf8.h \ + rcc.c \ + rcc.h \ audio_helper.h \ audio_helper.c \ softmixer.c \ diff --git a/configure.in b/configure.in index f77b2958..23e86cc6 100644 --- a/configure.in +++ b/configure.in @@ -115,6 +115,21 @@ if test "x$am_cv_func_iconv" != xyes; then fi EXTRA_LIBS="$EXTRA_LIBS $LIBICONV" +dnl librcc +COMPILE_RCC=no +AC_ARG_WITH(rcc, AS_HELP_STRING([--without-rcc], + [Compile without LIBRCC support])) +if test "x$with_rcc" != "xno" +then +AC_CHECK_HEADERS([librcc.h], + [AC_DEFINE([HAVE_RCC], 1, [Define if you have librcc.h]) + AC_CHECK_LIB(rcc, rccInit, + [RCC_LIBS="-lrcc" + AC_SUBST([RCC_LIBS]) + COMPILE_RCC=yes]) + ]) +fi + AC_C_CONST AC_C_INLINE AC_TYPE_OFF_T diff --git a/decoder_plugins/mp3/mp3.c b/decoder_plugins/mp3/mp3.c index e0570be9..c121f472 100644 --- a/decoder_plugins/mp3/mp3.c +++ b/decoder_plugins/mp3/mp3.c @@ -33,9 +33,6 @@ #ifdef HAVE_ICONV # include #endif -#ifdef HAVE_RCC -# include -#endif #define DEBUG @@ -48,6 +45,7 @@ #include "options.h" #include "files.h" #include "utf8.h" +#include "rcc.h" #include "options.h" #define INPUT_BUFFER (32 * 1024) @@ -117,28 +115,6 @@ static size_t fill_buff (struct mp3_data *data) return read_size; } -#ifdef HAVE_RCC -static char *do_rcc (char *str) -{ - rcc_string rccstring; - char *reencoded; - - assert (str != NULL); - - rccstring = rccFrom(NULL, 0, str); - if (rccstring) { - if (*rccstring && (reencoded = rccToCharset(NULL, "UTF-8", rccstring))) { - free(str); - free(rccstring); - return reencoded; - } - - free (rccstring); - } - return str; -} -#endif - static char *id3v1_fix (const char *str) { if (iconv_id3_fix != (iconv_t)-1) @@ -191,7 +167,7 @@ static char *get_tag (struct id3_tag *tag, const char *what) #ifdef HAVE_RCC if (options_get_int("UseRCC")) - comm = do_rcc (comm); + comm = rcc_reencode (comm); else { #endif /* HAVE_RCC */ t = comm; @@ -795,23 +771,6 @@ static int mp3_can_decode (struct io_stream *stream) static void mp3_init () { -#ifdef HAVE_RCC - rcc_class classes[] = { - { "input", RCC_CLASS_STANDARD, NULL, NULL, "Input Encoding", - 0 }, - { "output", RCC_CLASS_KNOWN, NULL, NULL, - "Output Encoding", 0 }, - { NULL, 0, NULL, NULL, NULL, 0 } - }; - - rccInit (); - rccInitDefaultContext(NULL, 0, 0, classes, 0); - rccLoad(NULL, "moc"); - rccSetOption(NULL, RCC_OPTION_TRANSLATE, - RCC_OPTION_TRANSLATE_SKIP_PARRENT); - rccSetOption(NULL, RCC_OPTION_AUTODETECT_LANGUAGE, 1); -#endif - iconv_id3_fix = iconv_open ("UTF-8", options_get_str("ID3v1TagsEncoding")); if (iconv_id3_fix == (iconv_t)(-1)) @@ -820,10 +779,6 @@ static void mp3_init () static void mp3_destroy () { -#ifdef HAVE_RCC - rccFree (); -#endif - if (iconv_close(iconv_id3_fix) == -1) logit ("iconv_close() failed: %s", strerror(errno)); } diff --git a/decoder_plugins/mp3/mp3.m4 b/decoder_plugins/mp3/mp3.m4 index bb9d6903..539cf2b7 100644 --- a/decoder_plugins/mp3/mp3.m4 +++ b/decoder_plugins/mp3/mp3.m4 @@ -3,7 +3,6 @@ dnl libmad (mp3) AC_ARG_WITH(mp3, AS_HELP_STRING([--without-mp3], [Compile without mp3 support (libmad)])) -COMPILE_RCC=no if test "x$with_mp3" != "xno" then AC_CHECK_LIB(mad, mad_stream_init, [ @@ -11,20 +10,6 @@ then if test "$ac_cv_lib_mad_mad_stream_init" = "yes" -a "$HAVE_ID3TAG" = "yes" then - dnl librcc - AC_ARG_WITH(rcc, AS_HELP_STRING([--without-rcc], - [Compile without LIBRCC support])) - if test "x$with_rcc" != "xno" - then - AC_CHECK_HEADERS([librcc.h], - [AC_DEFINE([HAVE_RCC], 1, [Define if you have librcc.h]) - AC_CHECK_LIB(rcc, rccInit, - [RCC_LIBS="-lrcc" - AC_SUBST([RCC_LIBS]) - COMPILE_RCC=yes]) - ]) - fi - want_mp3="yes" DECODER_PLUGINS="$DECODER_PLUGINS mp3" fi diff --git a/interface_elements.c b/interface_elements.c index 89974740..ddeafe98 100644 --- a/interface_elements.c +++ b/interface_elements.c @@ -58,6 +58,7 @@ #include "protocol.h" #include "interface.h" #include "utf8.h" +#include "rcc.h" #include "lyrics.h" #ifndef PACKAGE_REVISION @@ -1142,7 +1143,7 @@ static void side_menu_make_list_content (struct side_menu *m, strcpy (title, strrchr (lists_strs_at (dirs, i), '/') + 1); strcat (title, "/"); t_str = xstrdup (title); - t_str = iconv_rcc (t_str); + t_str = rcc_reencode (t_str); snprintf(title, PATH_MAX, "%s", t_str); free(t_str); } diff --git a/main.c b/main.c index 86118e91..4e27655d 100644 --- a/main.c +++ b/main.c @@ -41,6 +41,7 @@ #include "compat.h" #include "decoder.h" #include "lists.h" +#include "rcc.h" struct parameters { @@ -174,6 +175,7 @@ static void start_moc (const struct parameters *params, lists_t_strs *args) signal (SIGCHLD, sig_chld); server_loop (list_sock); options_free (); + rcc_cleanup (); exit (0); case -1: fatal ("fork() failed: %s", strerror(errno)); @@ -832,6 +834,7 @@ int main (int argc, char *argv[]) check_moc_dir (); + rcc_init (); decoder_init (params.debug); srand (time(NULL)); @@ -840,5 +843,7 @@ int main (int argc, char *argv[]) else start_moc (¶ms, args); + rcc_cleanup (); + return 0; } diff --git a/playlist.c b/playlist.c index fd0b4210..57249fd0 100644 --- a/playlist.c +++ b/playlist.c @@ -32,6 +32,7 @@ #include "files.h" #include "rbtree.h" #include "utf8.h" +#include "rcc.h" /* Initial size of the table */ #define INIT_SIZE 64 @@ -679,7 +680,7 @@ void plist_set_title_file (struct plist *plist, const int num, #ifdef HAVE_RCC if (options_get_int("UseRCCForFilesystem")) { char *t_str = xstrdup (title); - plist->items[num].title_file = iconv_rcc(t_str); + plist->items[num].title_file = rcc_reencode (t_str); return; } #endif diff --git a/rcc.c b/rcc.c new file mode 100644 index 00000000..9bb0f48e --- /dev/null +++ b/rcc.c @@ -0,0 +1,77 @@ +/* + * MOC - music on console + * Copyright (C) 2005,2011 Damian Pietras + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include + +#ifdef HAVE_RCC +# include +#endif + +#include + +#include "rcc.h" + +char *rcc_reencode (char *str) +{ + char *result = str; + + assert (str != NULL); + +#ifdef HAVE_RCC + rcc_string rccstring; + + rccstring = rccFrom (NULL, 0, str); + if (rccstring) { + if (*rccstring) { + char *reencoded; + + reencoded = rccToCharset (NULL, "UTF-8", rccstring); + if (reencoded) { + free (result); + result = reencoded; + } + } + + free (rccstring); + } +#endif /* HAVE_RCC */ + + return result; +} + +void rcc_init () +{ +#ifdef HAVE_RCC + rcc_class classes[] = { + {"input", RCC_CLASS_STANDARD, NULL, NULL, "Input Encoding", 0}, + {"output", RCC_CLASS_KNOWN, NULL, NULL, "Output Encoding", 0}, + {NULL, 0, NULL, NULL, NULL, 0} + }; + + rccInit (); + rccInitDefaultContext (NULL, 0, 0, classes, 0); + rccLoad (NULL, "moc"); + rccSetOption (NULL, RCC_OPTION_TRANSLATE, + RCC_OPTION_TRANSLATE_SKIP_PARRENT); + rccSetOption (NULL, RCC_OPTION_AUTODETECT_LANGUAGE, 1); +#endif /* HAVE_RCC */ +} + +void rcc_cleanup () +{ +#ifdef HAVE_RCC + rccFree (); +#endif /* HAVE_RCC */ +} diff --git a/rcc.h b/rcc.h new file mode 100644 index 00000000..1d2ce09b --- /dev/null +++ b/rcc.h @@ -0,0 +1,16 @@ +#ifndef RCC_H +#define RCC_H + +#ifdef __cplusplus +extern "C" { +#endif + +char *rcc_reencode (char *); +void rcc_init (); +void rcc_cleanup (); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/utf8.c b/utf8.c index 7901ed11..e2b09a90 100644 --- a/utf8.c +++ b/utf8.c @@ -23,9 +23,6 @@ #ifdef HAVE_ICONV # include #endif -#ifdef HAVE_RCC -# include -#endif #ifdef HAVE_NL_TYPES_H # include #endif @@ -49,6 +46,7 @@ #include "log.h" #include "options.h" #include "utf8.h" +#include "rcc.h" static char *terminal_charset = NULL; static int using_utf8 = 0; @@ -58,30 +56,6 @@ static iconv_t files_iconv_desc = (iconv_t)(-1); static iconv_t xterm_iconv_desc = (iconv_t)(-1); -char *iconv_rcc (char *str) -{ -#ifdef HAVE_RCC - rcc_string rccstring; - char *reencoded; - - assert (str != NULL); - - rccstring = rccFrom(NULL, 0, str); - if (rccstring) { - if (*rccstring && (reencoded = rccToCharset(NULL, "UTF-8", rccstring))) { - free(str); - free(rccstring); - return reencoded; - } - - free (rccstring); - } - return str; -#endif /* HAVE_RCC */ - return xstrdup (str); -} - - /* Return a malloc()ed string converted using iconv(). * If for_file_name is not 0, use the conversion defined for file names. * For NULL returns NULL. */ @@ -330,9 +304,6 @@ static void iconv_cleanup () if (iconv_desc != (iconv_t)(-1) && iconv_close(iconv_desc) == -1) logit ("iconv_close() failed: %s", strerror(errno)); -#ifdef HAVE_RCC - rccFree (); -#endif } void utf8_init () @@ -365,22 +336,6 @@ void utf8_init () if (iconv_desc == (iconv_t)(-1)) logit ("iconv_open() failed: %s", strerror(errno)); } -#ifdef HAVE_RCC - rcc_class classes[] = { - { "input", RCC_CLASS_STANDARD, NULL, NULL, "Input Encoding", - 0 }, - { "output", RCC_CLASS_KNOWN, NULL, NULL, - "Output Encoding", 0 }, - { NULL, 0, NULL, NULL, NULL, 0 } - }; - - rccInit (); - rccInitDefaultContext(NULL, 0, 0, classes, 0); - rccLoad(NULL, "moc"); - rccSetOption(NULL, RCC_OPTION_TRANSLATE, - RCC_OPTION_TRANSLATE_SKIP_PARRENT); - rccSetOption(NULL, RCC_OPTION_AUTODETECT_LANGUAGE, 1); -#endif /* HAVE_RCC */ if (options_get_int ("FileNamesIconv")) { diff --git a/utf8.h b/utf8.h index ff60be70..09282aae 100644 --- a/utf8.h +++ b/utf8.h @@ -39,7 +39,6 @@ size_t strwidth (const char *s); char *xstrtail (const char *str, const int len); char *iconv_str (const iconv_t desc, const char *str); -char *iconv_rcc (char *str); char *files_iconv_str (const char *str); char *xterm_iconv_str (const char *str);