From 44fa0d78ad36205f393cd4aa4813d1e7a403d6dc Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 22 Dec 2006 00:21:54 +0000 Subject: [PATCH] * MODULES.html.sh: New module wctype. * lib/wctype_.h, m4/wctype.m4, modules/wctype: New files. * lib/fnmatch.c: Don't bother to include before , since the new wctype module should fix this. * lib/quotearg.c: Include unconditionally, since the wctype module should arrange for it. * lib/regex_internal.h: Likewise. * m4/quotearg.m4 (gl_QUOTEARG): Don't check for wctype.h or iswprint, since the wctype module should handle this now. * m4/regex.m4 (gl_PREREQ_REGEX): Don't check for wctype.h. * modules/fnmatch (Depends-on): Add wctype. * modules/quotearg (Depends-on): Likewise. * modules/regex (Depends-on): Likewise. --- ChangeLog | 16 ++++++ MODULES.html.sh | 10 ++++ lib/fnmatch.c | 2 - lib/quotearg.c | 9 +-- lib/regex_internal.h | 4 +- lib/wctype_.h | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++ m4/quotearg.m4 | 4 +- m4/regex.m4 | 2 +- m4/wctype.m4 | 54 +++++++++++++++++ modules/fnmatch | 1 + modules/quotearg | 1 + modules/regex | 1 + modules/wctype | 36 ++++++++++++ 13 files changed, 284 insertions(+), 16 deletions(-) create mode 100644 lib/wctype_.h create mode 100644 m4/wctype.m4 create mode 100644 modules/wctype diff --git a/ChangeLog b/ChangeLog index 84f5a777d..bf28ed124 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2006-12-21 Paul Eggert + + * MODULES.html.sh: New module wctype. + * lib/wctype_.h, m4/wctype.m4, modules/wctype: New files. + * lib/fnmatch.c: Don't bother to include before + , since the new wctype module should fix this. + * lib/quotearg.c: Include unconditionally, since + the wctype module should arrange for it. + * lib/regex_internal.h: Likewise. + * m4/quotearg.m4 (gl_QUOTEARG): Don't check for wctype.h or iswprint, + since the wctype module should handle this now. + * m4/regex.m4 (gl_PREREQ_REGEX): Don't check for wctype.h. + * modules/fnmatch (Depends-on): Add wctype. + * modules/quotearg (Depends-on): Likewise. + * modules/regex (Depends-on): Likewise. + 2006-12-19 Bruno Haible * lib/strdup.h [C++]: Wrap definitions in extern "C". diff --git a/MODULES.html.sh b/MODULES.html.sh index 9c0253b14..107717bd7 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -1814,6 +1814,16 @@ func_all_modules () func_module strtoull func_end_table + element="Wide character classification and mapping utilities " + element=`printf "%s" "$element" | sed -e "$sed_lt" -e "$sed_gt"` + func_section_wrap isoc_sup_wctype + func_wrap H3 + func_echo "$element" + + func_begin_table + func_module wctype + func_end_table + element="Functions for greatest-width integer types " element=`printf "%s" "$element" | sed -e "$sed_lt" -e "$sed_gt"` func_section_wrap isoc_sup_inttypes diff --git a/lib/fnmatch.c b/lib/fnmatch.c index fd250f42d..ec42b7705 100644 --- a/lib/fnmatch.c +++ b/lib/fnmatch.c @@ -46,8 +46,6 @@ /* For platform which support the ISO C amendement 1 functionality we support user defined character classes. */ #if defined _LIBC || WIDE_CHAR_SUPPORT -/* Solaris 2.5 has a bug: must be included before . */ -# include # include #endif diff --git a/lib/quotearg.c b/lib/quotearg.c index 6f3ee9e86..0ad8da893 100644 --- a/lib/quotearg.c +++ b/lib/quotearg.c @@ -62,14 +62,7 @@ # define mbsinit(ps) 1 #endif -#ifndef iswprint -# if HAVE_WCTYPE_H -# include -# endif -# if !defined iswprint && !HAVE_ISWPRINT -# define iswprint(wc) 1 -# endif -#endif +#include #ifndef SIZE_MAX # define SIZE_MAX ((size_t) -1) diff --git a/lib/regex_internal.h b/lib/regex_internal.h index fbebc539c..5d4b60109 100644 --- a/lib/regex_internal.h +++ b/lib/regex_internal.h @@ -40,9 +40,7 @@ #if defined HAVE_WCHAR_H || defined _LIBC # include #endif /* HAVE_WCHAR_H || _LIBC */ -#if defined HAVE_WCTYPE_H || defined _LIBC -# include -#endif /* HAVE_WCTYPE_H || _LIBC */ +#include #include #if defined _LIBC # include diff --git a/lib/wctype_.h b/lib/wctype_.h new file mode 100644 index 000000000..11efbbb55 --- /dev/null +++ b/lib/wctype_.h @@ -0,0 +1,160 @@ +/* A substitute for ISO C99 , for platforms that lack it. + + 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. */ + +/* Written by Bruno Haible and Paul Eggert. */ + +/* iswctype, towctrans, towlower, towupper, wctrans, wctype, + wctrans_t, and wctype_t are not yet implemented. */ + +#ifndef _GL_WCTYPE_H +#define _GL_WCTYPE_H + +/* Tru64 with Desktop Toolkit C has a bug: must be included before + . + BSD/OS 4.1 has a bug: and must be included before + . */ +#include +#include +#include + +#if @HAVE_WCTYPE_H@ +# include @ABSOLUTE_WCTYPE_H@ +#endif + +#if @HAVE_WCTYPE_CTMP_BUG@ +static wint_t _ctmp_; +#endif + +/* FreeBSD 4.4 to 4.11 has but lacks the functions. + Assume all 12 functions are implemented the same way, or not at all. */ + +#if !defined iswalnum && !HAVE_ISWCNTRL +static inline int +iswalnum (wint_t wc) +{ + return ((wc >= '0' && wc <= '9') + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')); +} +# define iswalnum iswalnum +#endif + +#if !defined iswalpha && !HAVE_ISWCNTRL +static inline int +iswalpha (wint_t wc) +{ + return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'; +} +# define iswalpha iswalpha +#endif + +#if !defined iswblank && !HAVE_ISWCNTRL +static inline int +iswblank (wint_t wc) +{ + return wc == ' ' || wc == '\t'; +} +# define iswblank iswblank +#endif + +#if !defined iswcntrl && !HAVE_ISWCNTRL +static inline int +iswcntrl (wint_t wc) +{ + return (wc & ~0x1f) == 0 || wc == 0x7f; +} +# define iswcntrl iswcntrl +#endif + +#if !defined iswdigit && !HAVE_ISWCNTRL +static inline int +iswdigit (wint_t wc) +{ + return wc >= '0' && wc <= '9'; +} +# define iswdigit iswdigit +#endif + +#if !defined iswgraph && !HAVE_ISWCNTRL +static inline int +iswgraph (wint_t wc) +{ + return wc >= '!' && wc <= '~'; +} +# define iswgraph iswgraph +#endif + +#if !defined iswlower && !HAVE_ISWCNTRL +static inline int +iswlower (wint_t wc) +{ + return wc >= 'a' && wc <= 'z'; +} +# define iswlower iswlower +#endif + +#if !defined iswprint && !HAVE_ISWCNTRL +static inline int +iswprint (wint_t wc) +{ + return wc >= ' ' && wc <= '~'; +} +# define iswprint iswprint +#endif + +#if !defined iswpunct && !HAVE_ISWCNTRL +static inline int +iswpunct (wint_t wc) +{ + return (wc >= '!' && wc <= '~' + && !((wc >= '0' && wc <= '9') + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'))); +} +# define iswpunct iswpunct +#endif + +#if !defined iswspace && !HAVE_ISWCNTRL +static inline int +iswspace (wint_t wc) +{ + return (wc == ' ' || wc == '\t' + || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r'); +} +# define iswspace iswspace +#endif + +#if !defined iswupper && !HAVE_ISWCNTRL +static inline int +iswupper (wint_t wc) +{ + return wc >= 'A' && wc <= 'Z'; +} +# define iswupper iswupper +#endif + +#if !defined iswxdigit && !HAVE_ISWCNTRL +static inline int +iswxdigit (wint_t wc) +{ + return ((wc >= '0' && wc <= '9') + || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F')); +} +# define iswxdigit iswxdigit +#endif + + +#endif /* _GL_WCTYPE_H */ diff --git a/m4/quotearg.m4 b/m4/quotearg.m4 index b6d3d7ae8..36557019f 100644 --- a/m4/quotearg.m4 +++ b/m4/quotearg.m4 @@ -9,8 +9,8 @@ AC_DEFUN([gl_QUOTEARG], AC_LIBOBJ([quotearg]) dnl Prerequisites of lib/quotearg.c. - AC_CHECK_HEADERS_ONCE(wchar.h wctype.h) - AC_CHECK_FUNCS_ONCE(iswprint mbsinit) + AC_CHECK_HEADERS_ONCE([wchar.h]) + AC_CHECK_FUNCS_ONCE([mbsinit]) AC_TYPE_MBSTATE_T gl_FUNC_MBRTOWC ]) diff --git a/m4/regex.m4 b/m4/regex.m4 index 4ba0a03cd..30d7a63ed 100644 --- a/m4/regex.m4 +++ b/m4/regex.m4 @@ -193,7 +193,7 @@ AC_DEFUN([gl_PREREQ_REGEX], AC_REQUIRE([AC_GNU_SOURCE]) AC_REQUIRE([AC_C_RESTRICT]) AC_REQUIRE([AM_LANGINFO_CODESET]) - AC_CHECK_HEADERS_ONCE([wchar.h wctype.h]) + AC_CHECK_HEADERS_ONCE([wchar.h]) AC_CHECK_FUNCS_ONCE([iswctype mbrtowc mempcpy wcrtomb wcscoll]) AC_CHECK_DECLS([isblank], [], [], [#include ]) ]) diff --git a/m4/wctype.m4 b/m4/wctype.m4 new file mode 100644 index 000000000..4fd392e97 --- /dev/null +++ b/m4/wctype.m4 @@ -0,0 +1,54 @@ +dnl A placeholder for ISO C99 , for platforms that lack it. + +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 Written by Paul Eggert. + +AC_DEFUN([gl_WCTYPE_H], +[ + AC_CHECK_FUNCS_ONCE([iswcntrl]) + AC_CHECK_HEADERS_ONCE([wctype.h]) + AC_REQUIRE([AC_C_INLINE]) + + if test $ac_cv_header_wctype_h = yes; then + gl_ABSOLUTE_HEADER([wctype.h]) + ABSOLUTE_WCTYPE_H=\"$gl_cv_absolute_wctype_h\" + HAVE_WCTYPE_H=1 + else + ABSOLUTE_WCTYPE_H=\"no/such/file/wctype.h\" + HAVE_WCTYPE_H=0 + fi + AC_SUBST([ABSOLUTE_WCTYPE_H]) + AC_SUBST([HAVE_WCTYPE_H]) + + WCTYPE_H=wctype.h + HAVE_WCTYPE_CTMP_BUG=0 + if test $ac_cv_header_wctype_h = yes; then + AC_CACHE_CHECK([whether wctype macros need _ctmp_ declared], + [gl_cv_wctype_ctmp_bug], + [gl_cv_wctype_ctmp_bug=no + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + ]], + [[return iswprint (0);]])], + [gl_cv_wctype_ctmp_bug='no, but bare wctype.h does not work'], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + static wint_t _ctmp_;]], + [[return iswprint (0);]])], + [gl_cv_wctype_ctmp_bug=yes])])]) + case $gl_cv_wctype_ctmp_bug,$ac_cv_func_iswcntrl in #( + yes,*) + HAVE_WCTYPE_CTMP_BUG=1;; #( + no,yes) + WCTYPE_H=;; + esac + fi + AC_SUBST([WCTYPE_H]) + AC_SUBST([HAVE_WCTYPE_CTMP_BUG]) +]) diff --git a/modules/fnmatch b/modules/fnmatch index b4d21b027..5abc7b390 100644 --- a/modules/fnmatch +++ b/modules/fnmatch @@ -11,6 +11,7 @@ m4/fnmatch.m4 Depends-on: alloca stdbool +wctype configure.ac: # No macro. You should also use one of fnmatch-posix or fnmatch-gnu. diff --git a/modules/quotearg b/modules/quotearg index bc0b32fb6..301c1bf6b 100644 --- a/modules/quotearg +++ b/modules/quotearg @@ -12,6 +12,7 @@ Depends-on: xalloc gettext-h stdbool +wctype configure.ac: gl_QUOTEARG diff --git a/modules/regex b/modules/regex index 5ca9a7f2d..85368c913 100644 --- a/modules/regex +++ b/modules/regex @@ -19,6 +19,7 @@ malloc stdint strcase ssize_t +wctype configure.ac: gl_REGEX diff --git a/modules/wctype b/modules/wctype new file mode 100644 index 000000000..33e49f605 --- /dev/null +++ b/modules/wctype @@ -0,0 +1,36 @@ +Description: +A that conforms better to C99. + +Files: +lib/wctype_.h +m4/wctype.m4 + +Depends-on: + +configure.ac: +gl_WCTYPE_H + +Makefile.am: +BUILT_SOURCES += $(WCTYPE_H) + +# We need the following in order to create when the system +# doesn't have one that works with the given compiler. +wctype.h: wctype_.h + rm -f $@-t $@ + { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \ + sed -e 's/@''HAVE_WCTYPE_H''@/$(HAVE_WCTYPE_H)/g' \ + -e 's|@''ABSOLUTE_WCTYPE_H''@|$(ABSOLUTE_WCTYPE_H)|g' \ + -e 's/@''HAVE_WCTYPE_CTMP_BUG''@/$(HAVE_WCTYPE_CTMP_BUG)/g' \ + < $(srcdir)/wctype_.h; \ + } > $@-t + mv $@-t $@ +MOSTLYCLEANFILES += wctype.h wctype.h-t + +Include: +#include + +License: +LGPL + +Maintainer: +all -- 2.11.0