1 /* $OpenBSD: ctype_.c,v 1.9 2005/08/08 08:05:33 espie Exp $ */
2 /*
3 * Copyright (c) 1989 The Regents of the University of California.
4 * All rights reserved.
5 * (c) UNIX System Laboratories, Inc.
6 * All or some portions of this file are derived from material licensed
7 * to the University of California by American Telephone and Telegraph
8 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
9 * the permission of UNIX System Laboratories, Inc.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 #include <ctype.h>
37 #include "ctype_private.h"
38
39 const char _C_ctype_[1 + CTYPE_NUM_CHARS] = {
40 0,
41 _C, _C, _C, _C, _C, _C, _C, _C,
42 _C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C,
43 _C, _C, _C, _C, _C, _C, _C, _C,
44 _C, _C, _C, _C, _C, _C, _C, _C,
45 _S|(char)_B, _P, _P, _P, _P, _P, _P, _P,
46 _P, _P, _P, _P, _P, _P, _P, _P,
47 _N, _N, _N, _N, _N, _N, _N, _N,
48 _N, _N, _P, _P, _P, _P, _P, _P,
49 _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U,
50 _U, _U, _U, _U, _U, _U, _U, _U,
51 _U, _U, _U, _U, _U, _U, _U, _U,
52 _U, _U, _U, _P, _P, _P, _P, _P,
53 _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L,
54 _L, _L, _L, _L, _L, _L, _L, _L,
55 _L, _L, _L, _L, _L, _L, _L, _L,
56 /* determine printability based on the IS0 8859 8-bit standard */
57 _L, _L, _L, _P, _P, _P, _P, _C,
58
59 _C, _C, _C, _C, _C, _C, _C, _C, /* 80 */
60 _C, _C, _C, _C, _C, _C, _C, _C, /* 88 */
61 _C, _C, _C, _C, _C, _C, _C, _C, /* 90 */
62 _C, _C, _C, _C, _C, _C, _C, _C, /* 98 */
63 _P, _P, _P, _P, _P, _P, _P, _P, /* A0 */
64 _P, _P, _P, _P, _P, _P, _P, _P, /* A8 */
65 _P, _P, _P, _P, _P, _P, _P, _P, /* B0 */
66 _P, _P, _P, _P, _P, _P, _P, _P, /* B8 */
67 _P, _P, _P, _P, _P, _P, _P, _P, /* C0 */
68 _P, _P, _P, _P, _P, _P, _P, _P, /* C8 */
69 _P, _P, _P, _P, _P, _P, _P, _P, /* D0 */
70 _P, _P, _P, _P, _P, _P, _P, _P, /* D8 */
71 _P, _P, _P, _P, _P, _P, _P, _P, /* E0 */
72 _P, _P, _P, _P, _P, _P, _P, _P, /* E8 */
73 _P, _P, _P, _P, _P, _P, _P, _P, /* F0 */
74 _P, _P, _P, _P, _P, _P, _P, _P /* F8 */
75 };
76
77 const char *_ctype_ = _C_ctype_;
78
79
80 #if 1 /* ndef NDEBUG */
isalnum(int c)81 int isalnum(int c)
82 {
83 return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_U|_L|_N)));
84 }
85
isalpha(int c)86 int isalpha(int c)
87 {
88 return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_U|_L)));
89 }
90
iscntrl(int c)91 int iscntrl(int c)
92 {
93 return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _C));
94 }
95
isdigit(int c)96 int isdigit(int c)
97 {
98 return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _N));
99 }
100
isgraph(int c)101 int isgraph(int c)
102 {
103 return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N)));
104 }
105
islower(int c)106 int islower(int c)
107 {
108 return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _L));
109 }
110
isprint(int c)111 int isprint(int c)
112 {
113 return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_P|_U|_L|_N|_B)));
114 }
115
ispunct(int c)116 int ispunct(int c)
117 {
118 return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _P));
119 }
120
isspace(int c)121 int isspace(int c)
122 {
123 return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _S));
124 }
125
isupper(int c)126 int isupper(int c)
127 {
128 return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & _U));
129 }
130
isxdigit(int c)131 int isxdigit(int c)
132 {
133 return (c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)c] & (_N|_X)));
134 }
135
136 #if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \
137 || __XPG_VISIBLE > 600
isblank(int c)138 int isblank(int c)
139 {
140 return (c == ' ' || c == '\t');
141 }
142 #endif
143
144 #if __BSD_VISIBLE || __XPG_VISIBLE
isascii(int c)145 int isascii(int c)
146 {
147 return ((unsigned int)c <= 0177);
148 }
149
toascii(int c)150 int toascii(int c)
151 {
152 return (c & 0177);
153 }
154
155 #endif /* __BSD_VISIBLE || __XPG_VISIBLE */
156
157 #endif /* !NDBEUG */
158
159