Annotation of src/include/ctype.h, Revision 1.8
1.8 ! millert 1: /* $OpenBSD: ctype.h,v 1.7 2002/12/13 23:16:38 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: {
1.8 ! millert 92: return (c == EOF ? 0 : (_ctype_ + 1)[(unsigned int)c] & (_U|_L|_N));
1.5 millert 93: }
94:
95: static __inline int isalpha(int c)
96: {
1.8 ! millert 97: return (c == EOF ? 0 : (_ctype_ + 1)[(unsigned int)c] & (_U|_L));
1.5 millert 98: }
99:
100: static __inline int iscntrl(int c)
101: {
1.8 ! millert 102: return (c == EOF ? 0 : (_ctype_ + 1)[(unsigned int)c] & _C);
1.5 millert 103: }
104:
105: static __inline int isdigit(int c)
106: {
1.8 ! millert 107: return (c == EOF ? 0 : (_ctype_ + 1)[(unsigned int)c] & _N);
1.5 millert 108: }
109:
110: static __inline int isgraph(int c)
111: {
1.8 ! millert 112: return (c == EOF ? 0 : (_ctype_ + 1)[(unsigned int)c] & (_P|_U|_L|_N));
1.5 millert 113: }
114:
115: static __inline int islower(int c)
116: {
1.8 ! millert 117: return (c == EOF ? 0 : (_ctype_ + 1)[(unsigned int)c] & _L);
1.5 millert 118: }
119:
120: static __inline int isprint(int c)
121: {
1.8 ! millert 122: return (c == EOF ? 0 : (_ctype_ + 1)[(unsigned int)c] & (_P|_U|_L|_N|_B));
1.5 millert 123: }
124:
125: static __inline int ispunct(int c)
126: {
1.8 ! millert 127: return (c == EOF ? 0 : (_ctype_ + 1)[(unsigned int)c] & _P);
1.5 millert 128: }
129:
130: static __inline int isspace(int c)
131: {
1.8 ! millert 132: return (c == EOF ? 0 : (_ctype_ + 1)[(unsigned int)c] & _S);
1.5 millert 133: }
134:
135: static __inline int isupper(int c)
136: {
1.8 ! millert 137: return (c == EOF ? : (_ctype_ + 1)[(unsigned int)c] & _U);
1.5 millert 138: }
139:
140: static __inline int isxdigit(int c)
141: {
1.8 ! millert 142: return (c == EOF ? 0 : (_ctype_ + 1)[(unsigned int)c] & (_N|_X));
1.5 millert 143: }
144:
145: static __inline int tolower(int c)
146: {
1.7 millert 147: if ((unsigned int)c > 0177)
1.5 millert 148: return (c);
149: return ((_tolower_tab_ + 1)[c]);
150: }
151:
152: static __inline int toupper(int c)
153: {
1.7 millert 154: if ((unsigned int)c > 0177)
1.5 millert 155: return (c);
156: return ((_toupper_tab_ + 1)[c]);
157: }
1.1 deraadt 158:
159: #if !defined(_ANSI_SOURCE) && !defined (_POSIX_SOURCE)
1.5 millert 160: static __inline int isblank(int c)
161: {
162: return (c == ' ' || c == '\t');
163: }
164:
165: static __inline int isascii(int c)
166: {
1.7 millert 167: return ((unsigned int)c <= 0177);
1.5 millert 168: }
169:
170: static __inline int toascii(int c)
171: {
172: return (c & 0177);
173: }
174:
175: static __inline int _tolower(int c)
176: {
177: return (c - 'A' + 'a');
178: }
179:
180: static __inline int _toupper(int c)
181: {
182: return (c - 'a' + 'A');
183: }
1.1 deraadt 184: #endif
1.5 millert 185:
186: #endif /* !_ANSI_LIBRARY */
1.1 deraadt 187:
188: #endif /* !_CTYPE_H_ */