Annotation of src/include/ctype.h, Revision 1.11
1.11 ! millert 1: /* $OpenBSD: ctype.h,v 1.10 2002/12/15 13:53:39 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.11 ! millert 57: #ifndef __EOF
! 58: #define __EOF (-1) /* must match stdio.h */
! 59: #endif
1.5 millert 60:
1.1 deraadt 61: extern const char *_ctype_;
62: extern const short *_tolower_tab_;
63: extern const short *_toupper_tab_;
64:
1.5 millert 65: #ifdef _ANSI_LIBRARY
1.1 deraadt 66: __BEGIN_DECLS
1.5 millert 67: int isalnum(int);
68: int isalpha(int);
69: int iscntrl(int);
70: int isdigit(int);
71: int isgraph(int);
72: int islower(int);
73: int isprint(int);
74: int ispunct(int);
75: int isspace(int);
76: int isupper(int);
77: int isxdigit(int);
78: int tolower(int);
79: int toupper(int);
1.1 deraadt 80:
81: #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
1.5 millert 82: int isblank(int);
83: int isascii(int);
84: int toascii(int);
85: int _tolower(int);
86: int _toupper(int);
1.1 deraadt 87: #endif
88: __END_DECLS
89:
1.5 millert 90: #else /* !_ANSI_LIBRARY */
91:
92: static __inline int isalnum(int c)
93: {
1.11 ! millert 94: return (c == __EOF ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & (_U|_L|_N)));
1.5 millert 95: }
96:
97: static __inline int isalpha(int c)
98: {
1.11 ! millert 99: return (c == __EOF ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & (_U|_L)));
1.5 millert 100: }
101:
102: static __inline int iscntrl(int c)
103: {
1.11 ! millert 104: return (c == __EOF ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & _C));
1.5 millert 105: }
106:
107: static __inline int isdigit(int c)
108: {
1.11 ! millert 109: return (c == __EOF ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & _N));
1.5 millert 110: }
111:
112: static __inline int isgraph(int c)
113: {
1.11 ! millert 114: return (c == __EOF ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & (_P|_U|_L|_N)));
1.5 millert 115: }
116:
117: static __inline int islower(int c)
118: {
1.11 ! millert 119: return (c == __EOF ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & _L));
1.5 millert 120: }
121:
122: static __inline int isprint(int c)
123: {
1.11 ! millert 124: return (c == __EOF ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & (_P|_U|_L|_N|_B)));
1.5 millert 125: }
126:
127: static __inline int ispunct(int c)
128: {
1.11 ! millert 129: return (c == __EOF ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & _P));
1.5 millert 130: }
131:
132: static __inline int isspace(int c)
133: {
1.11 ! millert 134: return (c == __EOF ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & _S));
1.5 millert 135: }
136:
137: static __inline int isupper(int c)
138: {
1.11 ! millert 139: return (c == __EOF ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & _U));
1.5 millert 140: }
141:
142: static __inline int isxdigit(int c)
143: {
1.11 ! millert 144: return (c == __EOF ? 0 : ((_ctype_ + 1)[(unsigned char)(c & 0xff)] & (_N|_X)));
1.5 millert 145: }
146:
147: static __inline int tolower(int c)
148: {
1.7 millert 149: if ((unsigned int)c > 0177)
1.5 millert 150: return (c);
151: return ((_tolower_tab_ + 1)[c]);
152: }
153:
154: static __inline int toupper(int c)
155: {
1.7 millert 156: if ((unsigned int)c > 0177)
1.5 millert 157: return (c);
158: return ((_toupper_tab_ + 1)[c]);
159: }
1.1 deraadt 160:
161: #if !defined(_ANSI_SOURCE) && !defined (_POSIX_SOURCE)
1.5 millert 162: static __inline int isblank(int c)
163: {
164: return (c == ' ' || c == '\t');
165: }
166:
167: static __inline int isascii(int c)
168: {
1.7 millert 169: return ((unsigned int)c <= 0177);
1.5 millert 170: }
171:
172: static __inline int toascii(int c)
173: {
174: return (c & 0177);
175: }
176:
177: static __inline int _tolower(int c)
178: {
179: return (c - 'A' + 'a');
180: }
181:
182: static __inline int _toupper(int c)
183: {
184: return (c - 'a' + 'A');
185: }
1.1 deraadt 186: #endif
1.5 millert 187:
188: #endif /* !_ANSI_LIBRARY */
1.1 deraadt 189:
190: #endif /* !_CTYPE_H_ */