Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

configure tests for iconv



The following is an attempt to get the configure tests for iconv to work
properly. I've not actually been able to test this on any of the
critical systems such as Cygwin or Mac OS X (or any system that needs
-liconv for that matter) so I don't know for sure that it works.

I've also tried to clear up the compiler warnings. This includes a
section of configure to find out if the iconv() prototype uses const.
Bits of this was copied from various other configure scripts.

Oliver

Index: configure.ac
===================================================================
RCS file: /cvsroot/zsh/zsh/configure.ac,v
retrieving revision 1.28
diff -u -r1.28 configure.ac
--- configure.ac	14 Feb 2005 13:56:21 -0000	1.28
+++ configure.ac	24 Feb 2005 16:25:26 -0000
@@ -728,13 +728,45 @@
 
 AC_CHECK_LIB(socket, socket)
 
-AC_CHECK_LIB(iconv, iconv)
+dnl ---------------
+dnl CHECK FOR ICONV
+dnl ---------------
 
-case "$host_os" in
-  cygwin | darwin*)
-    dnl cygwin iconv() is really libiconv()
-    AC_CHECK_LIB(iconv, libiconv) ;;
-esac
+dnl Find iconv. It may be in libiconv and may be iconv() or libiconv()
+if test "x$ac_cv_header_iconv_h" = "xyes"; then
+  AC_CHECK_FUNC(iconv, ac_found_iconv=yes, ac_found_iconv=no)
+  if test "x$ac_found_iconv" = "xno"; then
+    AC_CHECK_LIB(iconv, iconv, ac_found_iconv=yes)
+    if test "x$ac_found_iconv" = "xno"; then
+      AC_CHECK_LIB(iconv, libiconv, ac_found_iconv=yes)
+    fi
+    if test "x$ac_found_iconv" != "xno"; then
+      LIBS="-liconv $LIBS"
+    fi
+  fi
+fi
+if test "x$ac_found_iconv" = xyes; then
+  AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.])
+fi
+
+dnl Check if iconv uses const in prototype declaration
+if test "x$ac_found_iconv" = "xyes"; then
+  AC_CACHE_CHECK(for iconv declaration, ac_cv_iconv_const,
+    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <stdlib.h>
+        #include <iconv.h>]],
+        [[#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]])],
+      [ac_cv_iconv_const=],
+      [ac_cv_iconv_const=const])])
+  AC_DEFINE_UNQUOTED([ICONV_CONST], $ac_cv_iconv_const,
+    [Define as const if the declaration of iconv() needs const.])
+fi
 
 if test x$enable_pcre = xyes; then
 dnl pcre-config should probably be employed here
Index: Src/system.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/system.h,v
retrieving revision 1.29
diff -u -r1.29 system.h
--- Src/system.h	22 Feb 2005 13:12:55 -0000	1.29
+++ Src/system.h	24 Feb 2005 16:25:26 -0000
@@ -701,7 +701,7 @@
 #else
 # ifdef HAVE_LANGINFO_H
 #   include <langinfo.h>
-#   if defined(HAVE_ICONV_H) || defined(HAVE_ICONV) || defined(HAVE_LIBICONV)
+#   ifdef HAVE_ICONV
 #     include <iconv.h>
 #   endif
 # endif
Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.73
diff -u -r1.73 utils.c
--- Src/utils.c	22 Feb 2005 18:24:45 -0000	1.73
+++ Src/utils.c	24 Feb 2005 16:25:27 -0000
@@ -3456,6 +3456,7 @@
 # if defined(HAVE_NL_LANGINFO) && defined(CODESET) && !defined(__STDC_ISO_10646__)
 /* Convert a character from UCS4 encoding to UTF-8 */
 
+/**/
 size_t
 ucs4toutf8(char *dest, unsigned int wval)
 {
@@ -3480,7 +3481,7 @@
     case 4: dest[3] = (wval & 0x3f) | 0x80; wval >>= 6;
     case 3: dest[2] = (wval & 0x3f) | 0x80; wval >>= 6;
     case 2: dest[1] = (wval & 0x3f) | 0x80; wval >>= 6;
-	*dest = wval | (0xfc << (6 - len)) & 0xfc;
+	*dest = wval | ((0xfc << (6 - len)) & 0xfc);
 	break;
     case 1: *dest = wval;
     }
@@ -3522,11 +3523,10 @@
     size_t count;
 #else
     unsigned int wval;
-# if defined(HAVE_NL_LANGINFO) && defined(CODESET) && (defined(HAVE_ICONV_H) || defined(HAVE_ICONV) || defined(HAVE_LIBICONV))
+# if defined(HAVE_NL_LANGINFO) && defined(CODESET) && defined(HAVE_ICONV)
     iconv_t cd;
     char inbuf[4];
     size_t inbytes, outbytes;
-    char *inptr;
     size_t count;
 # endif
 #endif
@@ -3643,10 +3643,10 @@
 		    t += ucs4toutf8(t, wval);
 		    continue;
 		} else {
-#   if defined(HAVE_ICONV_H) || defined(HAVE_ICONV) || defined(HAVE_LIBICONV)
+#   ifdef HAVE_ICONV
+		    ICONV_CONST char *inptr = inbuf;
     	    	    inbytes = 4;
 		    outbytes = 6;
-    	    	    inptr = inbuf;
 		    /* assume big endian convention for UCS-4 */
 		    for (i=3;i>=0;i--) {
 			inbuf[i] = wval & 0xff;
@@ -3664,7 +3664,7 @@
 			*len = t - buf;
 			return buf;
 		    }
-                    count = iconv(cd, (char **)&inptr, &inbytes, &t, &outbytes);
+                    count = iconv(cd, &inptr, &inbytes, &t, &outbytes);
 		    iconv_close(cd);
 		    if (count == (size_t)-1) {
                         zerr("cannot do charset conversion", NULL, 0);



Messages sorted by: Reverse Date, Date, Thread, Author