]> sjero.net Git - wget/blob - src/safe-ctype.h
Updated licensing exception for OpenSSL from the SFLC.
[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 3 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.  If not, see
19 <http://www.gnu.org/licenses/>.
20
21 Additional permission under GNU GPL version 3 section 7
22
23 If you modify this program, or any covered work, by linking or
24 combining it with the OpenSSL project's OpenSSL library (or a
25 modified version of that library), containing parts covered by the
26 terms of the OpenSSL or SSLeay licenses, the Free Software Foundation
27 grants you additional permission to convey the resulting work.
28 Corresponding Source for a non-source form of such a combination
29 shall include the source code for the parts of OpenSSL used as well
30 as that of the covered work.  */
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 /* We used to #define these to errors, but that loses when real
55    ctype.h is included, usually by a library's (OpenSSL's) header
56    which gets #included after wget.h.  */
57
58 #undef isalpha
59 #undef isalnum
60 #undef isblank
61 #undef iscntrl
62 #undef isdigit
63 #undef isgraph
64 #undef islower
65 #undef isprint
66 #undef ispunct
67 #undef isspace
68 #undef isupper
69 #undef isxdigit
70
71 #endif /* I_REALLY_WANT_CTYPE_MACROS */
72
73 /* Categories.  */
74
75 enum {
76   /* In C99 */
77   _sch_isblank  = 0x0001,       /* space \t */
78   _sch_iscntrl  = 0x0002,       /* nonprinting characters */
79   _sch_isdigit  = 0x0004,       /* 0-9 */
80   _sch_islower  = 0x0008,       /* a-z */
81   _sch_isprint  = 0x0010,       /* any printing character including ' ' */
82   _sch_ispunct  = 0x0020,       /* all punctuation */
83   _sch_isspace  = 0x0040,       /* space \t \n \r \f \v */
84   _sch_isupper  = 0x0080,       /* A-Z */
85   _sch_isxdigit = 0x0100,       /* 0-9A-Fa-f */
86
87   /* Extra categories useful to cpplib.  */
88   _sch_isidst   = 0x0200,       /* A-Za-z_ */
89   _sch_isvsp    = 0x0400,       /* \n \r */
90   _sch_isnvsp   = 0x0800,       /* space \t \f \v \0 */
91
92   /* Combinations of the above.  */
93   _sch_isalpha  = _sch_isupper|_sch_islower,    /* A-Za-z */
94   _sch_isalnum  = _sch_isalpha|_sch_isdigit,    /* A-Za-z0-9 */
95   _sch_isidnum  = _sch_isidst|_sch_isdigit,     /* A-Za-z0-9_ */
96   _sch_isgraph  = _sch_isalnum|_sch_ispunct,    /* isprint and not space */
97   _sch_iscppsp  = _sch_isvsp|_sch_isnvsp        /* isspace + \0 */
98 };
99
100 /* Character classification.  */
101 extern const unsigned short _sch_istable[256];
102
103 #define _sch_test(c, bit) (_sch_istable[(c) & 0xff] & (unsigned short)(bit))
104
105 #define ISALPHA(c)  _sch_test(c, _sch_isalpha)
106 #define ISALNUM(c)  _sch_test(c, _sch_isalnum)
107 #define ISBLANK(c)  _sch_test(c, _sch_isblank)
108 #define ISCNTRL(c)  _sch_test(c, _sch_iscntrl)
109 #define ISDIGIT(c)  _sch_test(c, _sch_isdigit)
110 #define ISGRAPH(c)  _sch_test(c, _sch_isgraph)
111 #define ISLOWER(c)  _sch_test(c, _sch_islower)
112 #define ISPRINT(c)  _sch_test(c, _sch_isprint)
113 #define ISPUNCT(c)  _sch_test(c, _sch_ispunct)
114 #define ISSPACE(c)  _sch_test(c, _sch_isspace)
115 #define ISUPPER(c)  _sch_test(c, _sch_isupper)
116 #define ISXDIGIT(c) _sch_test(c, _sch_isxdigit)
117
118 #define ISIDNUM(c)      _sch_test(c, _sch_isidnum)
119 #define ISIDST(c)       _sch_test(c, _sch_isidst)
120 #define IS_VSPACE(c)    _sch_test(c, _sch_isvsp)
121 #define IS_NVSPACE(c)   _sch_test(c, _sch_isnvsp)
122 #define IS_SPACE_OR_NUL(c)      _sch_test(c, _sch_iscppsp)
123
124 /* Character transformation.  */
125 extern const unsigned char  _sch_toupper[256];
126 extern const unsigned char  _sch_tolower[256];
127 #define TOUPPER(c) _sch_toupper[(c) & 0xff]
128 #define TOLOWER(c) _sch_tolower[(c) & 0xff]
129
130 #endif /* SAFE_CTYPE_H */