RCSID updates, warning fixes
[dfdiff.git] / include / ctype.h
blob572358e42135d3d3b0b3e6cd509df878e0416584
1 /*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
34 * @(#)ctype.h 5.3 (Berkeley) 4/3/91
35 * $NetBSD: src/include/ctype.h,v 1.25 2003/10/22 15:51:18 kleink Exp $
36 * $DragonFly: src/include/ctype.h,v 1.17 2006/03/06 02:54:12 swildner Exp $
39 #ifndef _CTYPE_H_
40 #define _CTYPE_H_
42 #include <sys/cdefs.h>
43 #include <machine/stdint.h>
45 #define _CTYPEMASK_U 0x0001
46 #define _CTYPEMASK_L 0x0002
47 #define _CTYPEMASK_D 0x0004
48 #define _CTYPEMASK_S 0x0008
49 #define _CTYPEMASK_P 0x0010
50 #define _CTYPEMASK_C 0x0020
51 #define _CTYPEMASK_X 0x0040
52 #define _CTYPEMASK_B 0x0080
53 #define _CTYPEMASK_A 0x0100
54 #define _CTYPEMASK_G 0x0200
55 #define _CTYPEMASK_R 0x0400
57 extern const __uint16_t *__libc_ctype_;
58 extern const __int16_t *__libc_tolower_tab_;
59 extern const __int16_t *__libc_toupper_tab_;
61 __BEGIN_DECLS
62 int isalnum(int);
63 int isalpha(int);
64 int iscntrl(int);
65 int isdigit(int);
66 int isgraph(int);
67 int islower(int);
68 int isprint(int);
69 int ispunct(int);
70 int isspace(int);
71 int isupper(int);
72 int isxdigit(int);
73 int tolower(int);
74 int toupper(int);
76 #if defined(__XSI_VISIBLE)
77 int isascii(int);
78 int toascii(int);
79 int _tolower(int);
80 int _toupper(int);
81 #endif
83 #if __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE >= 200112L || \
84 __XSI_VISIBLE >= 600
85 int isblank(int);
86 #endif
87 __END_DECLS
89 #ifdef _CTYPE_PRIVATE
90 extern const __uint16_t __libc_C_ctype_[];
91 extern const __int16_t __libc_C_toupper_[];
92 extern const __int16_t __libc_C_tolower_[];
93 #endif
96 * don't get all wishy washy and try to support architectures where
97 * char isn't 8 bits. It's 8 bits, period.
99 #if !defined(_CTYPE_H_DISABLE_MACROS_)
101 #define _CTYPE_NUM_CHARS (1 << (8*sizeof(char)))
103 static __inline int
104 __libc_ctype_index(__uint16_t mask, int c)
106 if (c < -1 || c >= _CTYPE_NUM_CHARS)
107 return(0); /* XXX maybe assert instead? */
108 return(__libc_ctype_[c + 1] & mask);
111 static __inline int
112 __libc_ctype_convert(const __int16_t *array, int c)
114 if (c < -1 || c >= _CTYPE_NUM_CHARS)
115 return(c); /* XXX maybe assert instead? */
116 return(array[c + 1]);
119 #ifndef _CTYPE_PRIVATE
120 #undef _CTYPE_NUM_CHARS
121 #endif
123 #define isdigit(c) __libc_ctype_index(_CTYPEMASK_D, c)
124 #define islower(c) __libc_ctype_index(_CTYPEMASK_L, c)
125 #define isspace(c) __libc_ctype_index(_CTYPEMASK_S, c)
126 #define ispunct(c) __libc_ctype_index(_CTYPEMASK_P, c)
127 #define isupper(c) __libc_ctype_index(_CTYPEMASK_U, c)
128 #define isalpha(c) __libc_ctype_index(_CTYPEMASK_A, c)
129 #define isxdigit(c) __libc_ctype_index(_CTYPEMASK_X, c)
130 #define isalnum(c) __libc_ctype_index(_CTYPEMASK_A|_CTYPEMASK_D, c)
131 #define isprint(c) __libc_ctype_index(_CTYPEMASK_R, c)
132 #define isgraph(c) __libc_ctype_index(_CTYPEMASK_G, c)
133 #define iscntrl(c) __libc_ctype_index(_CTYPEMASK_C, c)
134 #define tolower(c) __libc_ctype_convert(__libc_tolower_tab_, c)
135 #define toupper(c) __libc_ctype_convert(__libc_toupper_tab_, c)
137 #if defined(__XSI_VISIBLE)
138 #define isascii(c) ((unsigned)(c) <= 0177)
139 #define toascii(c) ((c) & 0177)
140 #define _tolower(c) ((c) - 'A' + 'a')
141 #define _toupper(c) ((c) - 'a' + 'A')
142 #endif
144 #if __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE >= 200112L || \
145 __XSI_VISIBLE >= 600
146 #define isblank(c) __libc_ctype_index(_CTYPEMASK_B, c)
147 #endif
149 #endif /* !_CTYPE_H_DISABLE_MACROS_ */
151 #endif /* !_CTYPE_H_ */