]> sjero.net Git - wget/blob - src/safe-ctype.c
Updated licensing exception for OpenSSL from the SFLC.
[wget] / src / safe-ctype.c
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 <http://www.gnu.org/licenses/>.
19
20 Additional permission under GNU GPL version 3 section 7
21
22 If you modify this program, or any covered work, by linking or
23 combining it with the OpenSSL project's OpenSSL library (or a
24 modified version of that library), containing parts covered by the
25 terms of the OpenSSL or SSLeay licenses, the Free Software Foundation
26 grants you additional permission to convey the resulting work.
27 Corresponding Source for a non-source form of such a combination
28 shall include the source code for the parts of OpenSSL used as well
29 as that of the covered work.  */
30
31 /* This is a compatible replacement of the standard C library's <ctype.h>
32    with the following properties:
33
34    - Implements all isxxx() macros required by C99.
35    - Also implements some character classes useful when
36      parsing C-like languages.
37    - Does not change behavior depending on the current locale.
38    - Behaves properly for all values in the range of a signed or
39      unsigned char.  */
40
41 #include <config.h>
42 #include <safe-ctype.h>
43 #include <stdio.h>  /* for EOF */
44
45 /* Shorthand */
46 #define bl _sch_isblank
47 #define cn _sch_iscntrl
48 #define di _sch_isdigit
49 #define is _sch_isidst
50 #define lo _sch_islower
51 #define nv _sch_isnvsp
52 #define pn _sch_ispunct
53 #define pr _sch_isprint
54 #define sp _sch_isspace
55 #define up _sch_isupper
56 #define vs _sch_isvsp
57 #define xd _sch_isxdigit
58
59 /* Masks.  */
60 #define L  lo|is   |pr  /* lower case letter */
61 #define XL lo|is|xd|pr  /* lowercase hex digit */
62 #define U  up|is   |pr  /* upper case letter */
63 #define XU up|is|xd|pr  /* uppercase hex digit */
64 #define D  di   |xd|pr  /* decimal digit */
65 #define P  pn      |pr  /* punctuation */
66 #define _  pn|is   |pr  /* underscore */
67
68 #define C           cn  /* control character */
69 #define Z  nv      |cn  /* NUL */
70 #define M  nv|sp   |cn  /* cursor movement: \f \v */
71 #define V  vs|sp   |cn  /* vertical space: \r \n */
72 #define T  nv|sp|bl|cn  /* tab */
73 #define S  nv|sp|bl|pr  /* space */
74
75 /* Are we ASCII? */
76 #if '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \
77   && 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21 \
78   && EOF == -1
79
80 const unsigned short _sch_istable[256] =
81 {
82   Z,  C,  C,  C,   C,  C,  C,  C,   /* NUL SOH STX ETX  EOT ENQ ACK BEL */
83   C,  T,  V,  M,   M,  V,  C,  C,   /* BS  HT  LF  VT   FF  CR  SO  SI  */
84   C,  C,  C,  C,   C,  C,  C,  C,   /* DLE DC1 DC2 DC3  DC4 NAK SYN ETB */
85   C,  C,  C,  C,   C,  C,  C,  C,   /* CAN EM  SUB ESC  FS  GS  RS  US  */
86   S,  P,  P,  P,   P,  P,  P,  P,   /* SP  !   "   #    $   %   &   '   */
87   P,  P,  P,  P,   P,  P,  P,  P,   /* (   )   *   +    ,   -   .   /   */
88   D,  D,  D,  D,   D,  D,  D,  D,   /* 0   1   2   3    4   5   6   7   */
89   D,  D,  P,  P,   P,  P,  P,  P,   /* 8   9   :   ;    <   =   >   ?   */
90   P, XU, XU, XU,  XU, XU, XU,  U,   /* @   A   B   C    D   E   F   G   */
91   U,  U,  U,  U,   U,  U,  U,  U,   /* H   I   J   K    L   M   N   O   */
92   U,  U,  U,  U,   U,  U,  U,  U,   /* P   Q   R   S    T   U   V   W   */
93   U,  U,  U,  P,   P,  P,  P,  _,   /* X   Y   Z   [    \   ]   ^   _   */
94   P, XL, XL, XL,  XL, XL, XL,  L,   /* `   a   b   c    d   e   f   g   */
95   L,  L,  L,  L,   L,  L,  L,  L,   /* h   i   j   k    l   m   n   o   */
96   L,  L,  L,  L,   L,  L,  L,  L,   /* p   q   r   s    t   u   v   w   */
97   L,  L,  L,  P,   P,  P,  P,  C,   /* x   y   z   {    |   }   ~   DEL */
98
99   /* high half of unsigned char is locale-specific, so all tests are
100      false in "C" locale */
101   0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
102   0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
103   0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
104   0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
105
106   0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
107   0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
108   0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
109   0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,  0, 0, 0, 0,
110 };
111
112 const unsigned char _sch_tolower[256] =
113 {
114    0,  1,  2,  3,   4,  5,  6,  7,   8,  9, 10, 11,  12, 13, 14, 15,
115   16, 17, 18, 19,  20, 21, 22, 23,  24, 25, 26, 27,  28, 29, 30, 31,
116   32, 33, 34, 35,  36, 37, 38, 39,  40, 41, 42, 43,  44, 45, 46, 47,
117   48, 49, 50, 51,  52, 53, 54, 55,  56, 57, 58, 59,  60, 61, 62, 63,
118   64,
119
120   'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
121   'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
122
123   91, 92, 93, 94, 95, 96,
124
125   'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
126   'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
127
128  123,124,125,126,127,
129
130  128,129,130,131, 132,133,134,135, 136,137,138,139, 140,141,142,143,
131  144,145,146,147, 148,149,150,151, 152,153,154,155, 156,157,158,159,
132  160,161,162,163, 164,165,166,167, 168,169,170,171, 172,173,174,175,
133  176,177,178,179, 180,181,182,183, 184,185,186,187, 188,189,190,191,
134
135  192,193,194,195, 196,197,198,199, 200,201,202,203, 204,205,206,207,
136  208,209,210,211, 212,213,214,215, 216,217,218,219, 220,221,222,223,
137  224,225,226,227, 228,229,230,231, 232,233,234,235, 236,237,238,239,
138  240,241,242,243, 244,245,246,247, 248,249,250,251, 252,253,254,255,
139 };
140
141 const unsigned char _sch_toupper[256] =
142 {
143    0,  1,  2,  3,   4,  5,  6,  7,   8,  9, 10, 11,  12, 13, 14, 15,
144   16, 17, 18, 19,  20, 21, 22, 23,  24, 25, 26, 27,  28, 29, 30, 31,
145   32, 33, 34, 35,  36, 37, 38, 39,  40, 41, 42, 43,  44, 45, 46, 47,
146   48, 49, 50, 51,  52, 53, 54, 55,  56, 57, 58, 59,  60, 61, 62, 63,
147   64,
148
149   'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
150   'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
151
152   91, 92, 93, 94, 95, 96,
153
154   'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
155   'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
156
157  123,124,125,126,127,
158
159  128,129,130,131, 132,133,134,135, 136,137,138,139, 140,141,142,143,
160  144,145,146,147, 148,149,150,151, 152,153,154,155, 156,157,158,159,
161  160,161,162,163, 164,165,166,167, 168,169,170,171, 172,173,174,175,
162  176,177,178,179, 180,181,182,183, 184,185,186,187, 188,189,190,191,
163
164  192,193,194,195, 196,197,198,199, 200,201,202,203, 204,205,206,207,
165  208,209,210,211, 212,213,214,215, 216,217,218,219, 220,221,222,223,
166  224,225,226,227, 228,229,230,231, 232,233,234,235, 236,237,238,239,
167  240,241,242,243, 244,245,246,247, 248,249,250,251, 252,253,254,255,
168 };
169
170 #else
171  #error "Unsupported host character set"
172 #endif /* not ASCII */