From e47afdf2f78acbcb5c08f422be5ce37e0e99a5fc Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Fri, 14 Sep 2007 14:46:00 +0200 Subject: [PATCH] Use the more advanced iconv.m4 script from ELinks --- Makefile | 2 +- acinclude.m4 | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 41 +--------------------------------- tig.c | 5 +---- 4 files changed, 65 insertions(+), 45 deletions(-) create mode 100644 acinclude.m4 diff --git a/Makefile b/Makefile index 69668d4..5bf60e3 100644 --- a/Makefile +++ b/Makefile @@ -105,7 +105,7 @@ dist: tig.spec rpm: dist rpmbuild -ta $(TARNAME).tar.gz -configure: configure.ac +configure: configure.ac acinclude.m4 $(AUTORECONF) -v # Maintainer stuff diff --git a/acinclude.m4 b/acinclude.m4 new file mode 100644 index 0000000..d3d618f --- /dev/null +++ b/acinclude.m4 @@ -0,0 +1,62 @@ +dnl From Bruno Haible. +AC_DEFUN([AM_ICONV], +[ + dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and + dnl those with the standalone portable GNU libiconv installed). + + AC_ARG_WITH([libiconv], +[ --with-libiconv=DIR search for libiconv in DIR/include and DIR/lib], [ + for dir in `echo "$withval" | tr : ' '`; do + if test -d $dir/include; then CPPFLAGS="$CPPFLAGS -I$dir/include"; fi + if test -d $dir/lib; then LDFLAGS="$LDFLAGS -L$dir/lib"; fi + done + ]) + + AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [ + am_cv_func_iconv="no, consider installing GNU libiconv" + am_cv_lib_iconv=no + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include +#include ]], [[iconv_t cd = iconv_open("",""); + iconv(cd,NULL,NULL,NULL,NULL); + iconv_close(cd);]])],[am_cv_func_iconv=yes],[]) + if test "$am_cv_func_iconv" != yes; then + am_save_LIBS="$LIBS" + LIBS="$LIBS -liconv" + AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include +#include ]], [[iconv_t cd = iconv_open("",""); + iconv(cd,NULL,NULL,NULL,NULL); + iconv_close(cd);]])],[am_cv_lib_iconv=yes + am_cv_func_iconv=yes],[]) + LIBS="$am_save_LIBS" + fi + ]) + if test "$am_cv_func_iconv" = yes; then + AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.]) + AC_MSG_CHECKING([for iconv declaration]) + AC_CACHE_VAL(am_cv_proto_iconv, [ + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#include +#include +extern +#ifdef __cplusplus +"C" +#endif +#if defined(__STDC__) || defined(__cplusplus) +size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); +#else +size_t iconv(); +#endif +]], [[]])],[am_cv_proto_iconv_arg1=""],[am_cv_proto_iconv_arg1="const"]) + am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"]) + am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'` + AC_MSG_RESULT([$]{ac_t:- + }[$]am_cv_proto_iconv) + AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1, + [Define as const if the declaration of iconv() needs const.]) + else + AC_MSG_FAILURE([iconv() not found. Please install libiconv and use --with-libiconv=/path/to/dir.],[1]) + fi + if test "$am_cv_lib_iconv" = yes; then + LIBS="$LIBS -liconv" + fi +]) diff --git a/configure.ac b/configure.ac index f60d43e..55d81a9 100644 --- a/configure.ac +++ b/configure.ac @@ -5,47 +5,8 @@ AC_LANG([C]) AC_CONFIG_HEADER(config.h) AC_CONFIG_SRCDIR(tig.c) -AC_ARG_WITH(libiconv, - AC_HELP_STRING([--with-libiconv=DIRECTORY],[base directory for libiconv])) -if test "$with_libiconv" != "" -then - CFLAGS="$CFLAGS -I$with_libiconv/include" - LDFLAGS="$LDFLAGS -L$with_libiconv/lib" -fi - -dnl -dnl See if we need to link with -liconv to get the iconv() function. -dnl AC_SEARCH_LIBS([wclear], [ncurses curses]) -AC_SEARCH_LIBS([iconv], [iconv]) - -if test "$ac_cv_search_iconv" = "no" -then - AC_MSG_FAILURE([iconv() not found. Please install libiconv.],[1]) -fi - -dnl -dnl See if iconv() requires a const char ** for the input buffer. -dnl -if test "$GCC" = "yes" -then - OLD_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS -Werror" - AC_MSG_CHECKING([whether iconv needs const char **]) - AC_COMPILE_IFELSE( - [AC_LANG_PROGRAM([[#include ]], - [[char **buf; - size_t *size; - iconv_t cd; - iconv(cd, buf, size, buf, size);]])], - [AC_DEFINE([ICONV_INBUF_TYPE],[char *], - [Type of iconv() input buffer]) - AC_MSG_RESULT([no])], - [AC_DEFINE([ICONV_INBUF_TYPE],[const char *], - [Type of iconv() input buffer]) - AC_MSG_RESULT([yes])]) - CFLAGS="$OLD_CFLAGS" -fi +AM_ICONV AC_PROG_CC AC_CHECK_PROGS(GIT_CONFIG, [git-config git-repo-config]) diff --git a/tig.c b/tig.c index 51d0fee..0390b3a 100644 --- a/tig.c +++ b/tig.c @@ -80,9 +80,6 @@ static size_t utf8_length(const char *string, size_t max_width, int *coloffset, #define COLOR_DEFAULT (-1) #define ICONV_NONE ((iconv_t) -1) -#ifndef ICONV_INBUF_TYPE -#define ICONV_INBUF_TYPE char * -#endif /* The format and size of the date column in the main view. */ #define DATE_FORMAT "%Y-%m-%d %H:%M" @@ -1943,7 +1940,7 @@ update_view(struct view *view) line[linelen - 1] = 0; if (opt_iconv != ICONV_NONE) { - ICONV_INBUF_TYPE inbuf = line; + ICONV_CONST char *inbuf = line; size_t inlen = linelen; char *outbuf = out_buffer; -- 2.30.2