Back to index

nagios-plugins  1.4.16
wctype.in.h
Go to the documentation of this file.
00001 /* A substitute for ISO C99 <wctype.h>, for platforms that lack it.
00002 
00003    Copyright (C) 2006-2010 Free Software Foundation, Inc.
00004 
00005    This program is free software; you can redistribute it and/or modify
00006    it under the terms of the GNU General Public License as published by
00007    the Free Software Foundation; either version 3, or (at your option)
00008    any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software Foundation,
00017    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
00018 
00019 /* Written by Bruno Haible and Paul Eggert.  */
00020 
00021 /*
00022  * ISO C 99 <wctype.h> for platforms that lack it.
00023  * <http://www.opengroup.org/susv3xbd/wctype.h.html>
00024  *
00025  * iswctype, towctrans, towlower, towupper, wctrans, wctype,
00026  * wctrans_t, and wctype_t are not yet implemented.
00027  */
00028 
00029 #ifndef _GL_WCTYPE_H
00030 
00031 #if __GNUC__ >= 3
00032 @PRAGMA_SYSTEM_HEADER@
00033 #endif
00034 
00035 #if @HAVE_WINT_T@
00036 /* Solaris 2.5 has a bug: <wchar.h> must be included before <wctype.h>.
00037    Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
00038    <wchar.h>.
00039    BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
00040    included before <wchar.h>.  */
00041 # include <stddef.h>
00042 # include <stdio.h>
00043 # include <time.h>
00044 # include <wchar.h>
00045 #endif
00046 
00047 /* Include the original <wctype.h> if it exists.
00048    BeOS 5 has the functions but no <wctype.h>.  */
00049 /* The include_next requires a split double-inclusion guard.  */
00050 #if @HAVE_WCTYPE_H@
00051 # @INCLUDE_NEXT@ @NEXT_WCTYPE_H@
00052 #endif
00053 
00054 #ifndef _GL_WCTYPE_H
00055 #define _GL_WCTYPE_H
00056 
00057 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
00058 
00059 /* The definition of _GL_WARN_ON_USE is copied here.  */
00060 
00061 /* Define wint_t and WEOF.  (Also done in wchar.in.h.)  */
00062 #if !@HAVE_WINT_T@ && !defined wint_t
00063 # define wint_t int
00064 # ifndef WEOF
00065 #  define WEOF -1
00066 # endif
00067 #else
00068 # ifndef WEOF
00069 #  define WEOF ((wint_t) -1)
00070 # endif
00071 #endif
00072 
00073 
00074 /* FreeBSD 4.4 to 4.11 has <wctype.h> but lacks the functions.
00075    Linux libc5 has <wctype.h> and the functions but they are broken.
00076    Assume all 11 functions (all isw* except iswblank) are implemented the
00077    same way, or not at all.  */
00078 #if ! @HAVE_ISWCNTRL@ || @REPLACE_ISWCNTRL@
00079 
00080 /* IRIX 5.3 has macros but no functions, its isw* macros refer to an
00081    undefined variable _ctmp_ and to <ctype.h> macros like _P, and they
00082    refer to system functions like _iswctype that are not in the
00083    standard C library.  Rather than try to get ancient buggy
00084    implementations like this to work, just disable them.  */
00085 # undef iswalnum
00086 # undef iswalpha
00087 # undef iswblank
00088 # undef iswcntrl
00089 # undef iswdigit
00090 # undef iswgraph
00091 # undef iswlower
00092 # undef iswprint
00093 # undef iswpunct
00094 # undef iswspace
00095 # undef iswupper
00096 # undef iswxdigit
00097 # undef towlower
00098 # undef towupper
00099 
00100 /* Linux libc5 has <wctype.h> and the functions but they are broken.  */
00101 # if @REPLACE_ISWCNTRL@
00102 #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
00103 #   define iswalnum rpl_iswalnum
00104 #   define iswalpha rpl_iswalpha
00105 #   define iswblank rpl_iswblank
00106 #   define iswcntrl rpl_iswcntrl
00107 #   define iswdigit rpl_iswdigit
00108 #   define iswgraph rpl_iswgraph
00109 #   define iswlower rpl_iswlower
00110 #   define iswprint rpl_iswprint
00111 #   define iswpunct rpl_iswpunct
00112 #   define iswspace rpl_iswspace
00113 #   define iswupper rpl_iswupper
00114 #   define iswxdigit rpl_iswxdigit
00115 #   define towlower rpl_towlower
00116 #   define towupper rpl_towupper
00117 #  endif
00118 # endif
00119 
00120 static inline int
00121 # if @REPLACE_ISWCNTRL@
00122 rpl_iswalnum
00123 # else
00124 iswalnum
00125 # endif
00126          (wint_t wc)
00127 {
00128   return ((wc >= '0' && wc <= '9')
00129           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z'));
00130 }
00131 
00132 static inline int
00133 # if @REPLACE_ISWCNTRL@
00134 rpl_iswalpha
00135 # else
00136 iswalpha
00137 # endif
00138          (wint_t wc)
00139 {
00140   return (wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z';
00141 }
00142 
00143 static inline int
00144 # if @REPLACE_ISWCNTRL@
00145 rpl_iswblank
00146 # else
00147 iswblank
00148 # endif
00149          (wint_t wc)
00150 {
00151   return wc == ' ' || wc == '\t';
00152 }
00153 
00154 static inline int
00155 # if @REPLACE_ISWCNTRL@
00156 rpl_iswcntrl
00157 # else
00158 iswcntrl
00159 # endif
00160         (wint_t wc)
00161 {
00162   return (wc & ~0x1f) == 0 || wc == 0x7f;
00163 }
00164 
00165 static inline int
00166 # if @REPLACE_ISWCNTRL@
00167 rpl_iswdigit
00168 # else
00169 iswdigit
00170 # endif
00171          (wint_t wc)
00172 {
00173   return wc >= '0' && wc <= '9';
00174 }
00175 
00176 static inline int
00177 # if @REPLACE_ISWCNTRL@
00178 rpl_iswgraph
00179 # else
00180 iswgraph
00181 # endif
00182          (wint_t wc)
00183 {
00184   return wc >= '!' && wc <= '~';
00185 }
00186 
00187 static inline int
00188 # if @REPLACE_ISWCNTRL@
00189 rpl_iswlower
00190 # else
00191 iswlower
00192 # endif
00193          (wint_t wc)
00194 {
00195   return wc >= 'a' && wc <= 'z';
00196 }
00197 
00198 static inline int
00199 # if @REPLACE_ISWCNTRL@
00200 rpl_iswprint
00201 # else
00202 iswprint
00203 # endif
00204          (wint_t wc)
00205 {
00206   return wc >= ' ' && wc <= '~';
00207 }
00208 
00209 static inline int
00210 # if @REPLACE_ISWCNTRL@
00211 rpl_iswpunct
00212 # else
00213 iswpunct
00214 # endif
00215          (wint_t wc)
00216 {
00217   return (wc >= '!' && wc <= '~'
00218           && !((wc >= '0' && wc <= '9')
00219                || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'Z')));
00220 }
00221 
00222 static inline int
00223 # if @REPLACE_ISWCNTRL@
00224 rpl_iswspace
00225 # else
00226 iswspace
00227 # endif
00228          (wint_t wc)
00229 {
00230   return (wc == ' ' || wc == '\t'
00231           || wc == '\n' || wc == '\v' || wc == '\f' || wc == '\r');
00232 }
00233 
00234 static inline int
00235 # if @REPLACE_ISWCNTRL@
00236 rpl_iswupper
00237 # else
00238 iswupper
00239 # endif
00240          (wint_t wc)
00241 {
00242   return wc >= 'A' && wc <= 'Z';
00243 }
00244 
00245 static inline int
00246 # if @REPLACE_ISWCNTRL@
00247 rpl_iswxdigit
00248 # else
00249 iswxdigit
00250 # endif
00251           (wint_t wc)
00252 {
00253   return ((wc >= '0' && wc <= '9')
00254           || ((wc & ~0x20) >= 'A' && (wc & ~0x20) <= 'F'));
00255 }
00256 
00257 static inline wint_t
00258 # if @REPLACE_ISWCNTRL@
00259 rpl_towlower
00260 # else
00261 towlower
00262 # endif
00263          (wint_t wc)
00264 {
00265   return (wc >= 'A' && wc <= 'Z' ? wc - 'A' + 'a' : wc);
00266 }
00267 
00268 static inline wint_t
00269 # if @REPLACE_ISWCNTRL@
00270 rpl_towupper
00271 # else
00272 towupper
00273 # endif
00274          (wint_t wc)
00275 {
00276   return (wc >= 'a' && wc <= 'z' ? wc - 'a' + 'A' : wc);
00277 }
00278 
00279 #elif ! @HAVE_ISWBLANK@
00280 /* Only the iswblank function is missing.  */
00281 
00282 static inline int
00283 iswblank (wint_t wc)
00284 {
00285   return wc == ' ' || wc == '\t';
00286 }
00287 
00288 #endif
00289 
00290 #if defined __MINGW32__
00291 
00292 /* On native Windows, wchar_t is uint16_t, and wint_t is uint32_t.
00293    The functions towlower and towupper are implemented in the MSVCRT library
00294    to take a wchar_t argument and return a wchar_t result.  mingw declares
00295    these functions to take a wint_t argument and return a wint_t result.
00296    This means that:
00297    1. When the user passes an argument outside the range 0x0000..0xFFFF, the
00298       function will look only at the lower 16 bits.  This is allowed according
00299       to POSIX.
00300    2. The return value is returned in the lower 16 bits of the result register.
00301       The upper 16 bits are random: whatever happened to be in that part of the
00302       result register.  We need to fix this by adding a zero-extend from
00303       wchar_t to wint_t after the call.  */
00304 
00305 static inline wint_t
00306 rpl_towlower (wint_t wc)
00307 {
00308   return (wint_t) (wchar_t) towlower (wc);
00309 }
00310 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
00311 #  define towlower rpl_towlower
00312 # endif
00313 
00314 static inline wint_t
00315 rpl_towupper (wint_t wc)
00316 {
00317   return (wint_t) (wchar_t) towupper (wc);
00318 }
00319 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
00320 #  define towupper rpl_towupper
00321 # endif
00322 
00323 #endif /* __MINGW32__ */
00324 
00325 #if @REPLACE_ISWCNTRL@
00326 _GL_CXXALIAS_RPL (iswalnum, int, (wint_t wc));
00327 _GL_CXXALIAS_RPL (iswalpha, int, (wint_t wc));
00328 _GL_CXXALIAS_RPL (iswblank, int, (wint_t wc));
00329 _GL_CXXALIAS_RPL (iswcntrl, int, (wint_t wc));
00330 _GL_CXXALIAS_RPL (iswdigit, int, (wint_t wc));
00331 _GL_CXXALIAS_RPL (iswgraph, int, (wint_t wc));
00332 _GL_CXXALIAS_RPL (iswlower, int, (wint_t wc));
00333 _GL_CXXALIAS_RPL (iswprint, int, (wint_t wc));
00334 _GL_CXXALIAS_RPL (iswpunct, int, (wint_t wc));
00335 _GL_CXXALIAS_RPL (iswspace, int, (wint_t wc));
00336 _GL_CXXALIAS_RPL (iswupper, int, (wint_t wc));
00337 _GL_CXXALIAS_RPL (iswxdigit, int, (wint_t wc));
00338 #else
00339 _GL_CXXALIAS_SYS (iswalnum, int, (wint_t wc));
00340 _GL_CXXALIAS_SYS (iswalpha, int, (wint_t wc));
00341 _GL_CXXALIAS_SYS (iswblank, int, (wint_t wc));
00342 _GL_CXXALIAS_SYS (iswcntrl, int, (wint_t wc));
00343 _GL_CXXALIAS_SYS (iswdigit, int, (wint_t wc));
00344 _GL_CXXALIAS_SYS (iswgraph, int, (wint_t wc));
00345 _GL_CXXALIAS_SYS (iswlower, int, (wint_t wc));
00346 _GL_CXXALIAS_SYS (iswprint, int, (wint_t wc));
00347 _GL_CXXALIAS_SYS (iswpunct, int, (wint_t wc));
00348 _GL_CXXALIAS_SYS (iswspace, int, (wint_t wc));
00349 _GL_CXXALIAS_SYS (iswupper, int, (wint_t wc));
00350 _GL_CXXALIAS_SYS (iswxdigit, int, (wint_t wc));
00351 #endif
00352 _GL_CXXALIASWARN (iswalnum);
00353 _GL_CXXALIASWARN (iswalpha);
00354 _GL_CXXALIASWARN (iswblank);
00355 _GL_CXXALIASWARN (iswcntrl);
00356 _GL_CXXALIASWARN (iswdigit);
00357 _GL_CXXALIASWARN (iswgraph);
00358 _GL_CXXALIASWARN (iswlower);
00359 _GL_CXXALIASWARN (iswprint);
00360 _GL_CXXALIASWARN (iswpunct);
00361 _GL_CXXALIASWARN (iswspace);
00362 _GL_CXXALIASWARN (iswupper);
00363 _GL_CXXALIASWARN (iswxdigit);
00364 
00365 #if @REPLACE_ISWCNTRL@ || defined __MINGW32__
00366 _GL_CXXALIAS_RPL (towlower, wint_t, (wint_t wc));
00367 _GL_CXXALIAS_RPL (towupper, wint_t, (wint_t wc));
00368 #else
00369 _GL_CXXALIAS_SYS (towlower, wint_t, (wint_t wc));
00370 _GL_CXXALIAS_SYS (towupper, wint_t, (wint_t wc));
00371 #endif
00372 _GL_CXXALIASWARN (towlower);
00373 _GL_CXXALIASWARN (towupper);
00374 
00375 
00376 #endif /* _GL_WCTYPE_H */
00377 #endif /* _GL_WCTYPE_H */