From fab12378d4383f0096da50fcbd4d5779bd50a549 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Fri, 6 Jun 2014 08:18:01 -0400 Subject: [PATCH 1/3] CONFIGURE: Add basic detection for iconv Based entirely on what our tools do --- configure | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/configure b/configure index ed5dea87e01..f9863bbe6f0 100755 --- a/configure +++ b/configure @@ -132,6 +132,7 @@ _opengles2=no _opengl_shaders=no _readline=auto _freetype2=auto +_iconv=auto _taskbar=auto _updates=no _libunity=auto @@ -951,6 +952,8 @@ Optional Libraries: installed (optional) --disable-freetype2 disable freetype2 TTF library usage [autodetect] + --disable-iconv disable iconv support [autodetect] + --with-nasm-prefix=DIR Prefix where nasm executable is installed (optional) --disable-nasm disable assembly language optimizations [autodetect] @@ -1022,6 +1025,8 @@ for ac_option in $@; do --disable-readline) _readline=no ;; --enable-freetype2) _freetype2=yes ;; --disable-freetype2) _freetype2=no ;; + --enable-iconv) _iconv=yes ;; + --disable-iconv) _iconv=no ;; --enable-taskbar) _taskbar=yes ;; --disable-taskbar) _taskbar=no ;; --enable-updates) _updates=yes ;; @@ -3902,6 +3907,82 @@ echo "$_freetype2" define_in_config_if_yes "$_freetype2" "USE_FREETYPE2" +# +# Check for iconv +# +# TODO: Support prefix for iconv +echo_n "Checking whether iconv.h is present... " +if test "$_iconv" = auto ; then + _iconv=no + cat > $TMPC << EOF +#include +int main(int, char **) { + return 0; +} +EOF + cc_check && _iconv=yes +fi + +create_iconv_test() { + cat > $TMPC << EOF +#include +int main(int, char **) { + iconv_t iconv = iconv_open("UTF-32", "SJIS"); + iconv_close(iconv); + return 0; +} +EOF +} +echo "$_iconv" + +if test "$_iconv" = yes ; then + echo_n "Checking whether iconv needs linking against libiconv... " + + needs_iconvlib='auto' + create_iconv_test + cc_check -liconv && needs_iconvlib='yes' + # We do check linking without -liconv here too, just in case + # it would fail otherwise too + create_iconv_test + cc_check && needs_iconvlib='no' + + if test "$needs_iconvlib" = auto ; then + _iconv=no + echo "does not link at all" + else + if test "$needs_iconvlib" = yes ; then + LIBS="$LIBS -liconv" + fi + echo "$needs_iconvlib" + + echo_n "Checking signature of iconv... " + uses_const=no + + cat > $TMPC << EOF +#include +int main(int argc, char **argv) { + iconv_t iconvP; + const char **inbuf = 0; + iconv(iconvP, inbuf, 0, 0, 0); + return 0; +} +EOF + cc_check $_iconvlibs && uses_const=yes + + if test "$uses_const" = yes ; then + echo "iconv_t, const char **, size_t *, char **, size_t *" + else + echo "iconv_t, char **, size_t *, char **, size_t *" + fi + + define_in_config_if_yes "$uses_const" 'ICONV_USES_CONST' + fi +fi + +echocheck "iconv" +define_in_config_if_yes "$_iconv" 'USE_ICONV' +echo "$_iconv" + # # Check for OpenGL (ES) # From 9816b06b17e5db96e62a1e46f78b5c58a6d3c30a Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Thu, 24 Jul 2014 07:24:21 -0400 Subject: [PATCH 2/3] COMMON: Add a function for converting strings using iconv --- common/iconv.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ common/iconv.h | 41 +++++++++++++++++++++++++++++ common/module.mk | 5 ++++ 3 files changed, 114 insertions(+) create mode 100644 common/iconv.cpp create mode 100644 common/iconv.h diff --git a/common/iconv.cpp b/common/iconv.cpp new file mode 100644 index 00000000000..6e275996175 --- /dev/null +++ b/common/iconv.cpp @@ -0,0 +1,68 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#include + +#include "common/str.h" +#include "common/textconsole.h" +#include "common/ustr.h" + +namespace Common { + +U32String convertToU32String(const char *fromCode, const String &string) { + // Apparently UTF-32 isn't native endian. Also, UCS−4−INTERNAL fails + // for me. + iconv_t handle = iconv_open( +#ifdef SCUMM_BIG_ENDIAN + "UTF-32BE", +#else + "UTF-32LE", +#endif + fromCode); + if (handle == ((iconv_t)-1)) + error("Failed to initialize UTF-32 conversion from %s", fromCode); + + size_t inSize = string.size(); + size_t outSize = inSize * 4; // Approximation + size_t originalOutSize = outSize; + + char *buffer = new char[outSize]; + char *dst = buffer; + +#ifdef ICONV_USES_CONST + const char *src = string.c_str(); +#else + char *src = const_cast(string.c_str()); +#endif + + if (iconv(handle, &src, &inSize, &dst, &outSize) == ((size_t)-1)) + error("Failed to convert %s to UTF-32 string", fromCode); + + U32String output((const U32String::value_type *)buffer, (originalOutSize - outSize) / 4); + + delete[] buffer; + iconv_close(handle); + + return output; +} + +} // End of namespace Common diff --git a/common/iconv.h b/common/iconv.h new file mode 100644 index 00000000000..d976084df57 --- /dev/null +++ b/common/iconv.h @@ -0,0 +1,41 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef COMMON_ICONV_H +#define COMMON_ICONV_H + +#include "common/scummsys.h" + +#ifdef USE_ICONV + +namespace Common { + +class String; +class U32String; + +U32String convertToU32String(const char *fromCode, const String &string); + +} // End of namespace Common + +#endif // USE_ICONV + +#endif // COMMON_ICONV_H diff --git a/common/module.mk b/common/module.mk index 919e0d4bfff..e7e2acb8cb2 100644 --- a/common/module.mk +++ b/common/module.mk @@ -57,5 +57,10 @@ MODULE_OBJS += \ recorderfile.o endif +ifdef USE_ICONV +MODULE_OBJS += \ + iconv.o +endif + # Include common rules include $(srcdir)/rules.mk From 33d5705af48106291c92837eb97374fec3c14db1 Mon Sep 17 00:00:00 2001 From: Bastien Bouclet Date: Wed, 10 Sep 2014 20:00:57 +0200 Subject: [PATCH 3/3] CONFIGURE: Allow defining the prefix for iconv --- configure | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/configure b/configure index f9863bbe6f0..1bee6479a90 100755 --- a/configure +++ b/configure @@ -952,6 +952,7 @@ Optional Libraries: installed (optional) --disable-freetype2 disable freetype2 TTF library usage [autodetect] + --with-iconv-prefix=DIR Prefix where iconv is installed (optional) --disable-iconv disable iconv support [autodetect] --with-nasm-prefix=DIR Prefix where nasm executable is installed (optional) @@ -1147,6 +1148,11 @@ for ac_option in $@; do OPENGL_CFLAGS="-I$arg/include" OPENGL_LIBS="-L$arg/lib" ;; + --with-iconv-prefix=*) + arg=`echo $ac_option | cut -d '=' -f 2` + ICONV_CFLAGS="-I$arg/include" + ICONV_LIBS="-L$arg/lib" + ;; --backend=*) _backend=`echo $ac_option | cut -d '=' -f 2` ;; @@ -3910,7 +3916,6 @@ define_in_config_if_yes "$_freetype2" "USE_FREETYPE2" # # Check for iconv # -# TODO: Support prefix for iconv echo_n "Checking whether iconv.h is present... " if test "$_iconv" = auto ; then _iconv=no @@ -3920,7 +3925,7 @@ int main(int, char **) { return 0; } EOF - cc_check && _iconv=yes + cc_check $ICONV_CFLAGS $ICONV_LIBS && _iconv=yes fi create_iconv_test() { @@ -3940,18 +3945,18 @@ if test "$_iconv" = yes ; then needs_iconvlib='auto' create_iconv_test - cc_check -liconv && needs_iconvlib='yes' + cc_check $ICONV_CFLAGS $ICONV_LIBS -liconv && needs_iconvlib='yes' # We do check linking without -liconv here too, just in case # it would fail otherwise too create_iconv_test - cc_check && needs_iconvlib='no' + cc_check $ICONV_CFLAGS $ICONV_LIBS && needs_iconvlib='no' if test "$needs_iconvlib" = auto ; then _iconv=no echo "does not link at all" else if test "$needs_iconvlib" = yes ; then - LIBS="$LIBS -liconv" + ICONV_LIBS="$ICONV_LIBS -liconv" fi echo "$needs_iconvlib" @@ -3967,7 +3972,7 @@ int main(int argc, char **argv) { return 0; } EOF - cc_check $_iconvlibs && uses_const=yes + cc_check $ICONV_CFLAGS $ICONV_LIBS && uses_const=yes if test "$uses_const" = yes ; then echo "iconv_t, const char **, size_t *, char **, size_t *" @@ -3979,6 +3984,11 @@ EOF fi fi +if test "$_iconv" = yes ; then + LIBS="$LIBS $ICONV_LIBS" + INCLUDES="$INCLUDES $ICONV_CFLAGS" +fi + echocheck "iconv" define_in_config_if_yes "$_iconv" 'USE_ICONV' echo "$_iconv"