bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gnulib] wcwidth on mingw


From: Eric Blake
Subject: Re: [bug-gnulib] wcwidth on mingw
Date: Wed, 28 Jun 2006 07:06:56 -0600
User-agent: Thunderbird 1.5.0.4 (Windows/20060516)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Bruno Haible on 6/27/2006 12:15 PM:
>> I note that mbswidth.c takes precautions to ensure wcwidth exists;
>> should we break that out into a wcwidth module and make both mbchar and
>> mbswidth depend on it?
> 
> This would make sense, yes. I'm normally not fond of major changes
> that avoid an "implicit declaration of function" warning of a function
> that returns 'int' anyway. But here we have gone through the trouble
> of doing it right already in mbswidth.c - why not reuse this technique.

OK, applied as follows based on your feedback, after testing in both
cygwin (which has wcwidth) and mingw (which has iswprint, but not
wcwidth).  If there is any fallout, we can add further patches later.

By the way, is it safe to assume wchar_t exists, or should wcwidth pull in
m4/wchar_t.m4?  Also, on mingw, where sizeof(wchar_t)==2 but
sizeof(int)==4, a prototype of
int wcwidth()
is incompatible with a declaration of
int wcwidth(wchar_t wc)
because of promotion rules.

2006-06-28  Eric Blake  <address@hidden>

        * modules/wcwidth: New file.
        * modules/mbchar (Depends-on): Add wcwidth.
        * modules/mbswidth (Depends-on): Add wcwidth.
        * MODULES.html.sh: Add wcwidth.

2006-06-28  Eric Blake  <address@hidden>

        * mbchar.h (wcwidth): Include wcwidth.h.
        * mbswidth.c (wcwidth): Move from here...
        * wcwidth.h: ...to this new file.

2006-06-28  Eric Blake  <address@hidden>

        * mbswidth.m4 (gl_MBSDWIDTH): Move wcwidth from here...
        * wcwidth.m4 (gl_FUNC_WCWIDTH): ...to this new file.

- --
Life is short - so eat dessert first!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEon7w84KuGfSFAYARAsT1AJ4qlkfCp+/rIwjVwq8FUs9V57er4ACfSSw4
17OsMd39JW8XI0oqc4xJk1E=
=MRhe
-----END PGP SIGNATURE-----
Index: lib/wcwidth.h
===================================================================
RCS file: lib/wcwidth.h
diff -N lib/wcwidth.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ lib/wcwidth.h       28 Jun 2006 12:59:33 -0000
@@ -0,0 +1,52 @@
+/* Determine the number of screen columns needed for a character.
+   Copyright (C) 2006 Free Software Foundation, Inc.
+
+   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, 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 _gl_WCWIDTH_H
+#define _gl_WCWIDTH_H
+
+/* Get wcwidth if available, along with wchar_t.  */
+#if HAVE_WCHAR_H
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+   <wchar.h>.
+   BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
+   <wchar.h>.  */
+# include <stdio.h>
+# include <time.h>
+# include <wchar.h>
+#endif
+
+/* Get iswprint.  */
+#if HAVE_WCTYPE_H
+# include <wctype.h>
+#endif
+#if !defined iswprint && !HAVE_ISWPRINT
+# define iswprint(wc) 1
+#endif
+
+#if !defined wcwidth && !HAVE_WCWIDTH
+
+/* wcwidth doesn't exist, so assume all printable characters have
+   width 1.  */
+static inline int
+wcwidth (wchar_t wc)
+{
+  return wc == 0 ? 0 : iswprint (wc) ? 1 : -1;
+}
+
+#endif
+
+#endif /* _gl_WCWIDTH_H */
Index: lib/mbchar.h
===================================================================
RCS file: /sources/gnulib/gnulib/lib/mbchar.h,v
retrieving revision 1.2
diff -u -p -r1.2 mbchar.h
--- lib/mbchar.h        16 Aug 2005 16:07:59 -0000      1.2
+++ lib/mbchar.h        28 Jun 2006 12:59:33 -0000
@@ -1,5 +1,5 @@
 /* Multibyte character data type.
-   Copyright (C) 2001, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2005-2006 Free Software Foundation, Inc.
 
    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
@@ -158,6 +158,8 @@
 
 #include <wctype.h>
 
+#include "wcwidth.h"
+
 #define MBCHAR_BUF_SIZE 24
 
 struct mbchar
Index: lib/mbswidth.c
===================================================================
RCS file: /sources/gnulib/gnulib/lib/mbswidth.c,v
retrieving revision 1.14
diff -u -p -r1.14 mbswidth.c
--- lib/mbswidth.c      14 May 2005 06:03:58 -0000      1.14
+++ lib/mbswidth.c      28 Jun 2006 12:59:33 -0000
@@ -1,5 +1,5 @@
 /* Determine the number of screen columns needed for a string.
-   Copyright (C) 2000-2005 Free Software Foundation, Inc.
+   Copyright (C) 2000-2006 Free Software Foundation, Inc.
 
    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
@@ -33,23 +33,9 @@
 #include <ctype.h>
 
 /* Get mbstate_t, mbrtowc(), mbsinit(), wcwidth().  */
-#if HAVE_WCHAR_H
-/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
-   <wchar.h>.
-   BSD/OS 4.1 has a bug: <stdio.h> and <time.h> must be included before
-   <wchar.h>.  */
-# include <stdio.h>
-# include <time.h>
-# include <wchar.h>
-#endif
+#include "wcwidth.h"
 
-/* Get iswprint(), iswcntrl().  */
-#if HAVE_WCTYPE_H
-# include <wctype.h>
-#endif
-#if !defined iswprint && !HAVE_ISWPRINT
-# define iswprint(wc) 1
-#endif
+/* Get iswcntrl().  */
 #if !defined iswcntrl && !HAVE_ISWCNTRL
 # define iswcntrl(wc) 0
 #endif
@@ -60,21 +46,6 @@
 # endif
 #endif
 
-#ifndef HAVE_DECL_WCWIDTH
-"this configure-time declaration test was not run"
-#endif
-#if !HAVE_DECL_WCWIDTH
-int wcwidth ();
-#endif
-
-#ifndef wcwidth
-# if !HAVE_WCWIDTH
-/* wcwidth doesn't exist, so assume all printable characters have
-   width 1.  */
-#  define wcwidth(wc) ((wc) == 0 ? 0 : iswprint (wc) ? 1 : -1)
-# endif
-#endif
-
 /* Get ISPRINT.  */
 #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
 # define IN_CTYPE_DOMAIN(c) 1
Index: m4/wcwidth.m4
===================================================================
RCS file: m4/wcwidth.m4
diff -N m4/wcwidth.m4
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ m4/wcwidth.m4       28 Jun 2006 12:59:33 -0000
@@ -0,0 +1,37 @@
+# wcwidth.m4 serial 1
+dnl Copyright (C) 2006 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl autoconf tests required for use of mbswidth.c
+
+AC_DEFUN([gl_FUNC_WCWIDTH],
+[ AC_CHECK_HEADERS_ONCE([wchar.h wctype.h])
+  AC_CHECK_FUNCS_ONCE([iswprint wcwidth])
+
+  AC_REQUIRE([AC_GNU_SOURCE])
+
+  AC_CACHE_CHECK([whether wcwidth is declared], [ac_cv_have_decl_wcwidth],
+    [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
+/* AIX 3.2.5 declares wcwidth in <string.h>. */
+#if HAVE_STRING_H
+# include <string.h>
+#endif
+#if HAVE_WCHAR_H
+# include <wchar.h>
+#endif
+], [
+#ifndef wcwidth
+  char *p = (char *) wcwidth;
+#endif
+])], [ac_cv_have_decl_wcwidth=yes], [ac_cv_have_decl_wcwidth=no])])
+  if test $ac_cv_have_decl_wcwidth = yes; then
+    ac_val=1
+  else
+    ac_val=0
+  fi
+  AC_DEFINE_UNQUOTED([HAVE_DECL_WCWIDTH], [$ac_val],
+    [Define to 1 if you have the declaration of wcwidth(), and to 0
+     otherwise.])
+]) 
Index: m4/mbswidth.m4
===================================================================
RCS file: /sources/gnulib/gnulib/m4/mbswidth.m4,v
retrieving revision 1.14
diff -u -p -r1.14 mbswidth.m4
--- m4/mbswidth.m4      18 Jan 2005 13:07:56 -0000      1.14
+++ m4/mbswidth.m4      28 Jun 2006 12:59:33 -0000
@@ -1,5 +1,5 @@
-# mbswidth.m4 serial 11
-dnl Copyright (C) 2000-2002, 2004 Free Software Foundation, Inc.
+# mbswidth.m4 serial 12
+dnl Copyright (C) 2000-2002, 2004, 2006 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -9,33 +9,11 @@ dnl From Bruno Haible.
 
 AC_DEFUN([gl_MBSWIDTH],
 [
-  AC_CHECK_HEADERS_ONCE(wchar.h wctype.h)
-  AC_CHECK_FUNCS_ONCE(isascii iswprint mbsinit)
-  AC_CHECK_FUNCS(iswcntrl wcwidth)
+  AC_CHECK_HEADERS_ONCE([wchar.h wctype.h])
+  AC_CHECK_FUNCS_ONCE([isascii mbsinit])
+  AC_CHECK_FUNCS([iswcntrl])
   gl_FUNC_MBRTOWC
 
-  AC_CACHE_CHECK([whether wcwidth is declared], ac_cv_have_decl_wcwidth,
-    [AC_TRY_COMPILE([
-/* AIX 3.2.5 declares wcwidth in <string.h>. */
-#if HAVE_STRING_H
-# include <string.h>
-#endif
-#if HAVE_WCHAR_H
-# include <wchar.h>
-#endif
-], [
-#ifndef wcwidth
-  char *p = (char *) wcwidth;
-#endif
-], ac_cv_have_decl_wcwidth=yes, ac_cv_have_decl_wcwidth=no)])
-  if test $ac_cv_have_decl_wcwidth = yes; then
-    ac_val=1
-  else
-    ac_val=0
-  fi
-  AC_DEFINE_UNQUOTED(HAVE_DECL_WCWIDTH, $ac_val,
-    [Define to 1 if you have the declaration of wcwidth(), and to 0 
otherwise.])
-
   dnl UnixWare 7.1.1 <wchar.h> has a declaration of a function mbswidth()
   dnl that clashes with ours.
   AC_CACHE_CHECK([whether mbswidth is declared in <wchar.h>],
Index: modules/wcwidth
===================================================================
RCS file: modules/wcwidth
diff -N modules/wcwidth
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ modules/wcwidth     28 Jun 2006 12:59:33 -0000
@@ -0,0 +1,23 @@
+Description:
+Determine the number of screen columns needed for a character.
+
+Files:
+lib/wcwidth.h
+m4/wcwidth.m4
+
+Depends-on:
+
+configure.ac:
+gl_FUNC_WCWIDTH
+
+Makefile.am:
+lib_SOURCES += wcwidth.h
+
+Include:
+"wcwidth.h"
+
+License:
+GPL
+
+Maintainer:
+Bruno Haible
Index: modules/mbchar
===================================================================
RCS file: /sources/gnulib/gnulib/modules/mbchar,v
retrieving revision 1.2
diff -u -p -r1.2 mbchar
--- modules/mbchar      26 Sep 2005 13:58:51 -0000      1.2
+++ modules/mbchar      28 Jun 2006 12:59:33 -0000
@@ -8,6 +8,7 @@ m4/mbchar.m4
 
 Depends-on:
 stdbool
+wcwidth
 
 configure.ac:
 gl_MBCHAR
Index: modules/mbswidth
===================================================================
RCS file: /sources/gnulib/gnulib/modules/mbswidth,v
retrieving revision 1.4
diff -u -p -r1.4 mbswidth
--- modules/mbswidth    22 Sep 2004 15:11:04 -0000      1.4
+++ modules/mbswidth    28 Jun 2006 12:59:33 -0000
@@ -9,6 +9,7 @@ m4/mbrtowc.m4
 m4/mbswidth.m4
 
 Depends-on:
+wcwidth
 
 configure.ac:
 gl_MBSWIDTH
Index: MODULES.html.sh
===================================================================
RCS file: /sources/gnulib/gnulib/MODULES.html.sh,v
retrieving revision 1.117
diff -u -p -r1.117 MODULES.html.sh
--- MODULES.html.sh     21 Jun 2006 10:00:08 -0000      1.117
+++ MODULES.html.sh     28 Jun 2006 12:59:33 -0000
@@ -1811,6 +1811,7 @@ func_all_modules ()
   func_module strtok_r
   func_module unistd
   func_module utime
+  func_module wcwidth
   func_end_table
 
   element="Enhancements for POSIX:2001 functions"

reply via email to

[Prev in Thread] Current Thread [Next in Thread]