Yoann Vandoorselaere wrote: > > Just for info: Which system is this which has a <wchar.h> and a <wctype.h> > > header file but no iswcntrl function? The isw* functions are the main > > contents of <wctype.h>. I don't expect a system to have <wctype.h> > > but lack the functions. > > FreeBSD 4.x got the wctype.h header, however, the header start with #if > 0 and end with #endif directive. :-)
How insane! And it affects all releases from FreeBSD 4.4 to 4.11. [1] [2] I'm committing the appended fix. (There's not only iswcntrl which needs a substitute, but also all others, because of mb_isalpha..mb_isxdigit.) [1] http://www.freebsd.org/cgi/cvsweb.cgi/src/include/wctype.h [2] http://cvsup.pt.freebsd.org/cgi-bin/cvsweb/cvsweb.cgi/src/include/wctype.h 2006-07-28 Bruno Haible <[EMAIL PROTECTED]> * m4/mbchar.m4 (gl_MBCHAR): Also test for iswcntrl. * lib/mbchar.h (iswalnum, iswalpha, iswblank, iswcntrl, iswdigit, iswgraph, iswlower, iswprint, iswpunct, iswspace, iswupper, iswxdigit): Define fallbacks. Avoids link error on FreeBSD 4.x. Reported by Yoann Vandoorselaere <[EMAIL PROTECTED]>. * lib/wcwidth.h (iswprint): Assume an ASCII compatible wide character encoding. * lib/mbswidth.c (iswcntrl): Likewise. *** m4/mbchar.m4 26 Sep 2005 13:58:51 -0000 1.2 --- m4/mbchar.m4 28 Jul 2006 15:14:39 -0000 *************** *** 1,5 **** ! # mbchar.m4 serial 2 ! dnl Copyright (C) 2005 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. --- 1,5 ---- ! # mbchar.m4 serial 3 ! dnl Copyright (C) 2005-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. *************** *** 16,20 **** --- 16,22 ---- dnl Compile mbchar.c only if HAVE_WCHAR_H && HAVE_WCTYPE_H. if test $ac_cv_header_wchar_h = yes && test $ac_cv_header_wctype_h = yes; then AC_LIBOBJ([mbchar]) + dnl Prerequisites of mbchar.h and mbchar.c. + AC_CHECK_FUNCS([iswcntrl]) fi ]) *** lib/mbchar.h 28 Jun 2006 13:11:03 -0000 1.3 --- lib/mbchar.h 28 Jul 2006 15:14:39 -0000 *************** *** 157,162 **** --- 157,271 ---- #include <wchar.h> #include <wctype.h> + /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions. + Assume all 12 functions are implemented the same way, or not at all. */ + #if !defined iswalnum && !HAVE_ISWCNTRL + ststic inline int + iswalnum (wint_t wc) + { + return (wc >= 0 && wc < 128 + ? (wc >= '0' && wc <= '9') || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z') + : 0); + } + #endif + #if !defined iswalpha && !HAVE_ISWCNTRL + ststic inline int + iswalpha (wint_t wc) + { + return (wc >= 0 && wc < 128 + ? (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z' + : 0); + } + #endif + #if !defined iswblank && !HAVE_ISWCNTRL + ststic inline int + iswblank (wint_t wc) + { + return (wc >= 0 && wc < 128 + ? wc == ' ' || wc == '\t' + : 0); + } + #endif + #if !defined iswcntrl && !HAVE_ISWCNTRL + ststic inline int + iswcntrl (wint_t wc) + { + return (wc >= 0 && wc < 128 + ? (wc & ~0x1f) == 0 || wc == 0x7f + : 0); + } + #endif + #if !defined iswdigit && !HAVE_ISWCNTRL + ststic inline int + iswdigit (wint_t wc) + { + return (wc >= '0' && wc <= '9'); + } + #endif + #if !defined iswgraph && !HAVE_ISWCNTRL + ststic inline int + iswgraph (wint_t wc) + { + return (wc >= 0 && wc < 128 + ? wc >= '!' && wc <= '~' + : 1); + } + #endif + #if !defined iswlower && !HAVE_ISWCNTRL + ststic inline int + iswlower (wint_t wc) + { + return (wc >= 0 && wc < 128 + ? wc >= 'a' && wc <= 'z' + : 0); + } + #endif + #if !defined iswprint && !HAVE_ISWCNTRL + ststic inline int + iswprint (wint_t wc) + { + return (wc >= 0 && wc < 128 + ? wc >= ' ' && wc <= '~' + : 1); + } + #endif + #if !defined iswpunct && !HAVE_ISWCNTRL + ststic inline int + iswpunct (wint_t wc) + { + return (wc >= 0 && wc < 128 + ? wc >= '!' && wc <= '~' + && !((wc >= '0' && wc <= '9') + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')) + : 1); + } + #endif + #if !defined iswspace && !HAVE_ISWCNTRL + ststic inline int + iswspace (wint_t wc) + { + return (wc >= 0 && wc < 128 + ? wc == ' ' || wc == '\t' + || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r' + : 0); + } + #endif + #if !defined iswupper && !HAVE_ISWCNTRL + ststic inline int + iswupper (wint_t wc) + { + return (wc >= 0 && wc < 128 + ? wc >= 'A' && wc <= 'Z' + : 0); + } + #endif + #if !defined iswxdigit && !HAVE_ISWCNTRL + ststic inline int + iswxdigit (wint_t wc) + { + return (wc >= '0' && wc <= '9') || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'); + } + #endif #include "wcwidth.h" *** lib/wcwidth.h 28 Jun 2006 17:03:53 -0000 1.2 --- lib/wcwidth.h 28 Jul 2006 15:14:39 -0000 *************** *** 36,42 **** # include <wctype.h> # endif # if !defined iswprint && !HAVE_ISWPRINT ! # define iswprint(wc) 1 # endif # ifndef HAVE_DECL_WCWIDTH --- 36,48 ---- # include <wctype.h> # endif # if !defined iswprint && !HAVE_ISWPRINT ! ststic inline int ! iswprint (wint_t wc) ! { ! return (wc >= 0 && wc < 128 ! ? wc >= ' ' && wc <= '~' ! : 1); ! } # endif # ifndef HAVE_DECL_WCWIDTH *** lib/mbswidth.c 4 Jul 2006 16:46:23 -0000 1.17 --- lib/mbswidth.c 28 Jul 2006 15:14:39 -0000 *************** *** 51,57 **** # include <wctype.h> #endif #if !defined iswcntrl && !HAVE_ISWCNTRL ! # define iswcntrl(wc) 0 #endif #ifndef mbsinit --- 51,57 ---- # include <wctype.h> #endif #if !defined iswcntrl && !HAVE_ISWCNTRL ! # define iswcntrl(wc) (((wc) & ~0x1f) == 0 || (wc) == 0x7f) #endif #ifndef mbsinit