]> sjero.net Git - wget/blob - src/safe-ctype.h
[svn] Update the license to include the OpenSSL exception.
[wget] / src / safe-ctype.h
1 /* <ctype.h> replacement macros.
2
3    Copyright (C) 2000 Free Software Foundation, Inc.
4    Contributed by Zack Weinberg <zackw@stanford.edu>.
5
6 This file is part of the libiberty library.
7 Libiberty is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 Libiberty is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public
18 License along with libiberty; see the file COPYING.LIB.  If
19 not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite
20 Boston, MA 02111-1307, USA.
21
22 In addition, as a special exception, the Free Software Foundation
23 gives permission to link the code of its release of Wget with the
24 OpenSSL project's "OpenSSL" library (or with modified versions of it
25 that use the same license as the "OpenSSL" library), and distribute
26 the linked executables.  You must obey the GNU General Public License
27 in all respects for all of the code used other than "OpenSSL".  If you
28 modify this file, you may extend this exception to your version of the
29 file, but you are not obligated to do so.  If you do not wish to do
30 so, delete this exception statement from your version.  */
31
32 /* This is a compatible replacement of the standard C library's <ctype.h>
33    with the following properties:
34
35    - Implements all isxxx() macros required by C99.
36    - Also implements some character classes useful when
37      parsing C-like languages.
38    - Does not change behavior depending on the current locale.
39    - Behaves properly for all values in the range of a signed or
40      unsigned char.
41
42    To avoid conflicts, this header defines the isxxx functions in upper
43    case, e.g. ISALPHA not isalpha.  */
44
45 #ifndef SAFE_CTYPE_H
46 #define SAFE_CTYPE_H
47
48 /* Catch erroneous use of ctype macros.  Files that really know what
49    they're doing can disable this check by defining the
50    I_REALLY_WANT_CTYPE_MACROS preprocessor constant. */
51
52 #ifndef I_REALLY_WANT_CTYPE_MACROS
53
54 #undef isalpha
55 #define isalpha *** Please use ISALPHA ***
56 #undef isalnum
57 #define isalnum *** Please use ISALNUM ***
58 #undef isblank
59 #define isblank *** Please use ISBLANK ***
60 #undef iscntrl
61 #define iscntrl *** Please use ISCNTRL ***
62 #undef isdigit
63 #define isdigit *** Please use ISDIGIT ***
64 #undef isgraph
65 #define isgraph *** Please use ISGRAPH ***
66 #undef islower
67 #define islower *** Please use ISLOWER ***
68 #undef isprint
69 #define isprint *** Please use ISPRINT ***
70 #undef ispunct
71 #define ispunct *** Please use ISPUNCT ***
72 #undef isspace
73 #define isspace *** Please use ISSPACE ***
74 #undef isupper
75 #define isupper *** Please use ISUPPER ***
76 #undef isxdigit
77 #define isxdigit *** Please use ISXDIGIT ***
78
79 #endif /* I_REALLY_WANT_CTYPE_MACROS */
80
81 /* Categories.  */
82
83 enum {
84   /* In C99 */
85   _sch_isblank  = 0x0001,       /* space \t */
86   _sch_iscntrl  = 0x0002,       /* nonprinting characters */
87   _sch_isdigit  = 0x0004,       /* 0-9 */
88   _sch_islower  = 0x0008,       /* a-z */
89   _sch_isprint  = 0x0010,       /* any printing character including ' ' */
90   _sch_ispunct  = 0x0020,       /* all punctuation */
91   _sch_isspace  = 0x0040,       /* space \t \n \r \f \v */
92   _sch_isupper  = 0x0080,       /* A-Z */
93   _sch_isxdigit = 0x0100,       /* 0-9A-Fa-f */
94
95   /* Extra categories useful to cpplib.  */
96   _sch_isidst   = 0x0200,       /* A-Za-z_ */
97   _sch_isvsp    = 0x0400,       /* \n \r */
98   _sch_isnvsp   = 0x0800,       /* space \t \f \v \0 */
99
100   /* Combinations of the above.  */
101   _sch_isalpha  = _sch_isupper|_sch_islower,    /* A-Za-z */
102   _sch_isalnum  = _sch_isalpha|_sch_isdigit,    /* A-Za-z0-9 */
103   _sch_isidnum  = _sch_isidst|_sch_isdigit,     /* A-Za-z0-9_ */
104   _sch_isgraph  = _sch_isalnum|_sch_ispunct,    /* isprint and not space */
105   _sch_iscppsp  = _sch_isvsp|_sch_isnvsp        /* isspace + \0 */
106 };
107
108 /* Character classification.  */
109 extern const unsigned short _sch_istable[256];
110
111 #define _sch_test(c, bit) (_sch_istable[(c) & 0xff] & (bit))
112
113 #define ISALPHA(c)  _sch_test(c, _sch_isalpha)
114 #define ISALNUM(c)  _sch_test(c, _sch_isalnum)
115 #define ISBLANK(c)  _sch_test(c, _sch_isblank)
116 #define ISCNTRL(c)  _sch_test(c, _sch_iscntrl)
117 #define ISDIGIT(c)  _sch_test(c, _sch_isdigit)
118 #define ISGRAPH(c)  _sch_test(c, _sch_isgraph)
119 #define ISLOWER(c)  _sch_test(c, _sch_islower)
120 #define ISPRINT(c)  _sch_test(c, _sch_isprint)
121 #define ISPUNCT(c)  _sch_test(c, _sch_ispunct)
122 #define ISSPACE(c)  _sch_test(c, _sch_isspace)
123 #define ISUPPER(c)  _sch_test(c, _sch_isupper)
124 #define ISXDIGIT(c) _sch_test(c, _sch_isxdigit)
125
126 #define ISIDNUM(c)      _sch_test(c, _sch_isidnum)
127 #define ISIDST(c)       _sch_test(c, _sch_isidst)
128 #define IS_VSPACE(c)    _sch_test(c, _sch_isvsp)
129 #define IS_NVSPACE(c)   _sch_test(c, _sch_isnvsp)
130 #define IS_SPACE_OR_NUL(c)      _sch_test(c, _sch_iscppsp)
131
132 /* Character transformation.  */
133 extern const unsigned char  _sch_toupper[256];
134 extern const unsigned char  _sch_tolower[256];
135 #define TOUPPER(c) _sch_toupper[(c) & 0xff]
136 #define TOLOWER(c) _sch_tolower[(c) & 0xff]
137
138 #endif /* SAFE_CTYPE_H */