Eric Blake wrote: > Using cygwin to cross-compile to mingw, I got: > > $ CFLAGS='-Wall -O2' CC='gcc -mno-cygwin' ./gnulib-tool --test mbchar > ... > gcc -mno-cygwin -DHAVE_CONFIG_H -I. -I../../lib -I.. -Wall -O2 - > c ../../lib/mbchar.c > In file included from ../../lib/mbchar.c:24: > ../../lib/mbchar.h: In function `mb_width_aux': > ../../lib/mbchar.h:243: warning: implicit declaration of function `wcwidth' > rm -f libgnu.a > > 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. > This patch is my first cut at it; Bruno, I think you would be better as > the maintainer since I broke it out of your mbswidth. Agreed. > --- MODULES.html.sh 21 Jun 2006 10:00:08 -0000 1.117 > +++ MODULES.html.sh 27 Jun 2006 15:42:53 -0000 > @@ -1775,6 +1775,7 @@ > func_module mbiter > func_module mbuiter > func_module mbfile > + func_module wcwidth > func_end_table > > element="Support for systems lacking POSIX:2001" I think this belongs in section "Support for systems lacking POSIX:2001", not in section "Extra functions based on ISO C 99". > 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 27 Jun 2006 15:42:54 -0000 > @@ -0,0 +1,34 @@ > +/* Determine the number of screen columns needed for a character. > + 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 > + 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 HAVE_DECL_WCWIDTH > +"this configure-time declaration test was not run" > +#endif > +#if !HAVE_DECL_WCWIDTH > +# ifdef __cplusplus No tabs here, please. > +extern "C" > +# endif > +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 Here I would use an inline function. A macro is fine for limited use, as in mbswidth.c, but for a .h file, an inline function is safer. Also, for iswprint to be usable here, you need this code: -------------------------------------------------------------------------- /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>. */ #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 -------------------------------------------------------------------------- > --- /dev/null 1 Jan 1970 00:00:00 -0000 > +++ m4/wcwidth.m4 27 Jun 2006 15:42:54 -0000 > @@ -0,0 +1,34 @@ > +# 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_WCWIDTH], I would call this macro gl_FUNC_WCWIDTH, since it provides only the function 'wcwidth'. > +[ > + AC_CHECK_FUNCS([wcwidth]) An AC_REQUIRE([AC_GNU_SOURCE]) needs to be inserted here, for glibc systems. Thanks! Bruno