Annotation of src/include/ctype.h, Revision 1.6
1.6 ! millert 1: /* $OpenBSD: ctype.h,v 1.5 2002/12/11 23:01:40 millert Exp $ */
1.1 deraadt 2: /* $NetBSD: ctype.h,v 1.14 1994/10/26 00:55:47 cgd Exp $ */
3:
4: /*
5: * Copyright (c) 1989 The Regents of the University of California.
6: * All rights reserved.
7: * (c) UNIX System Laboratories, Inc.
8: * All or some portions of this file are derived from material licensed
9: * to the University of California by American Telephone and Telegraph
10: * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11: * the permission of UNIX System Laboratories, Inc.
12: *
13: * Redistribution and use in source and binary forms, with or without
14: * modification, are permitted provided that the following conditions
15: * are met:
16: * 1. Redistributions of source code must retain the above copyright
17: * notice, this list of conditions and the following disclaimer.
18: * 2. Redistributions in binary form must reproduce the above copyright
19: * notice, this list of conditions and the following disclaimer in the
20: * documentation and/or other materials provided with the distribution.
21: * 3. All advertising materials mentioning features or use of this software
22: * must display the following acknowledgement:
23: * This product includes software developed by the University of
24: * California, Berkeley and its contributors.
25: * 4. Neither the name of the University nor the names of its contributors
26: * may be used to endorse or promote products derived from this software
27: * without specific prior written permission.
28: *
29: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39: * SUCH DAMAGE.
40: *
41: * @(#)ctype.h 5.3 (Berkeley) 4/3/91
42: */
43:
44: #ifndef _CTYPE_H_
45: #define _CTYPE_H_
46: #include <sys/cdefs.h>
47:
48: #define _U 0x01
49: #define _L 0x02
50: #define _N 0x04
51: #define _S 0x08
52: #define _P 0x10
53: #define _C 0x20
54: #define _X 0x40
55: #define _B 0x80
56:
1.5 millert 57: #define EOF (-1)
58:
1.1 deraadt 59: extern const char *_ctype_;
60: extern const short *_tolower_tab_;
61: extern const short *_toupper_tab_;
62:
1.5 millert 63: #ifdef _ANSI_LIBRARY
1.1 deraadt 64: __BEGIN_DECLS
1.5 millert 65: int isalnum(int);
66: int isalpha(int);
67: int iscntrl(int);
68: int isdigit(int);
69: int isgraph(int);
70: int islower(int);
71: int isprint(int);
72: int ispunct(int);
73: int isspace(int);
74: int isupper(int);
75: int isxdigit(int);
76: int tolower(int);
77: int toupper(int);
1.1 deraadt 78:
79: #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
1.5 millert 80: int isblank(int);
81: int isascii(int);
82: int toascii(int);
83: int _tolower(int);
84: int _toupper(int);
1.1 deraadt 85: #endif
86: __END_DECLS
87:
1.5 millert 88: #else /* !_ANSI_LIBRARY */
89:
90: static __inline int isalnum(int c)
91: {
92: if (c == EOF)
93: return (0);
1.6 ! millert 94: return ((_ctype_ + 1)[(unsigned int)c] & (_U|_L|_N));
1.5 millert 95: }
96:
97: static __inline int isalpha(int c)
98: {
99: if (c == EOF)
100: return (0);
1.6 ! millert 101: return ((_ctype_ + 1)[(unsigned int)c] & (_U|_L));
1.5 millert 102: }
103:
104: static __inline int iscntrl(int c)
105: {
106: if (c == EOF)
107: return (0);
1.6 ! millert 108: return ((_ctype_ + 1)[(unsigned int)c] & _C);
1.5 millert 109: }
110:
111: static __inline int isdigit(int c)
112: {
113: if (c == EOF)
114: return (0);
1.6 ! millert 115: return ((_ctype_ + 1)[(unsigned int)c] & _N);
1.5 millert 116: }
117:
118: static __inline int isgraph(int c)
119: {
120: if (c == EOF)
121: return (0);
1.6 ! millert 122: return ((_ctype_ + 1)[(unsigned int)c] & (_P|_U|_L|_N));
1.5 millert 123: }
124:
125: static __inline int islower(int c)
126: {
127: if (c == EOF)
128: return (0);
1.6 ! millert 129: return ((_ctype_ + 1)[(unsigned int)c] & _L);
1.5 millert 130: }
131:
132: static __inline int isprint(int c)
133: {
134: if (c == EOF)
135: return (0);
1.6 ! millert 136: return ((_ctype_ + 1)[(unsigned int)c] & (_P|_U|_L|_N|_B));
1.5 millert 137: }
138:
139: static __inline int ispunct(int c)
140: {
141: if (c == EOF)
142: return (0);
1.6 ! millert 143: return ((_ctype_ + 1)[(unsigned int)c] & _P);
1.5 millert 144: }
145:
146: static __inline int isspace(int c)
147: {
148: if (c == EOF)
149: return (0);
1.6 ! millert 150: return ((_ctype_ + 1)[(unsigned int)c] & _S);
1.5 millert 151: }
152:
153: static __inline int isupper(int c)
154: {
155: if (c == EOF)
156: return (0);
1.6 ! millert 157: return ((_ctype_ + 1)[(unsigned int)c] & _U);
1.5 millert 158: }
159:
160: static __inline int isxdigit(int c)
161: {
162: if (c == EOF)
163: return (0);
1.6 ! millert 164: return ((_ctype_ + 1)[(unsigned int)c] & (_N|_X));
1.5 millert 165: }
166:
167: static __inline int tolower(int c)
168: {
1.6 ! millert 169: if (c != (c & 0177))
1.5 millert 170: return (c);
171: return ((_tolower_tab_ + 1)[c]);
172: }
173:
174: static __inline int toupper(int c)
175: {
1.6 ! millert 176: if (c != (c & 0177))
1.5 millert 177: return (c);
178: return ((_toupper_tab_ + 1)[c]);
179: }
1.1 deraadt 180:
181: #if !defined(_ANSI_SOURCE) && !defined (_POSIX_SOURCE)
1.5 millert 182: static __inline int isblank(int c)
183: {
184: return (c == ' ' || c == '\t');
185: }
186:
187: static __inline int isascii(int c)
188: {
189: if (c == EOF)
190: return (0);
1.6 ! millert 191: return ((unsigned int)(c) <= 0177);
1.5 millert 192: }
193:
194: static __inline int toascii(int c)
195: {
196: return (c & 0177);
197: }
198:
199: static __inline int _tolower(int c)
200: {
201: return (c - 'A' + 'a');
202: }
203:
204: static __inline int _toupper(int c)
205: {
206: return (c - 'a' + 'A');
207: }
1.1 deraadt 208: #endif
1.5 millert 209:
210: #endif /* !_ANSI_LIBRARY */
1.1 deraadt 211:
212: #endif /* !_CTYPE_H_ */