Fix duplicate bitmask for _A and _G.
[dragonfly.git] / include / ctype.h
1 /*      $NetBSD: src/include/ctype.h,v 1.25 2003/10/22 15:51:18 kleink Exp $    */
2 /*      $DragonFly: src/include/ctype.h,v 1.11 2005/05/09 09:53:07 y0netan1 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. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *      @(#)ctype.h     5.3 (Berkeley) 4/3/91
38  */
39
40 #ifndef _CTYPE_H_
41 #define _CTYPE_H_
42
43 #include <sys/cdefs.h>
44 #include <machine/stdint.h>
45
46 #define _U      0x0001
47 #define _L      0x0002
48 #define _D      0x0004
49 #define _S      0x0008
50 #define _P      0x0010
51 #define _C      0x0020
52 #define _X      0x0040
53 #define _B      0x0080
54 #define _A      0x0100
55 #define _G      0x0200
56 #define _R      0x0400
57
58 extern const __uint16_t *__libc_ctype_;
59 extern const __int16_t  *__libc_tolower_tab_;
60 extern const __int16_t  *__libc_toupper_tab_;
61
62 __BEGIN_DECLS
63 int     isalnum(int);
64 int     isalpha(int);
65 int     iscntrl(int);
66 int     isdigit(int);
67 int     isgraph(int);
68 int     islower(int);
69 int     isprint(int);
70 int     ispunct(int);
71 int     isspace(int);
72 int     isupper(int);
73 int     isxdigit(int);
74 int     tolower(int);
75 int     toupper(int);
76
77 #if defined(__XSI_VISIBLE)
78 int     isascii(int);
79 int     toascii(int);
80 int     _tolower(int);
81 int     _toupper(int);
82 #endif
83
84 #if _ISO_C_VISIBLE >= 1999 || _POSIX_VISIBLE >= 200112L || \
85     __XSI_VISIBLE >= 600
86 int     isblank(int);
87 #endif
88 __END_DECLS
89
90 #define isdigit(c)      ((int)((__libc_ctype_ + 1)[(int)(c)] & _D))
91 #define islower(c)      ((int)((__libc_ctype_ + 1)[(int)(c)] & _L))
92 #define isspace(c)      ((int)((__libc_ctype_ + 1)[(int)(c)] & _S))
93 #define ispunct(c)      ((int)((__libc_ctype_ + 1)[(int)(c)] & _P))
94 #define isupper(c)      ((int)((__libc_ctype_ + 1)[(int)(c)] & _U))
95 #define isalpha(c)      ((int)((__libc_ctype_ + 1)[(int)(c)] & _A))
96 #define isxdigit(c)     ((int)((__libc_ctype_ + 1)[(int)(c)] & _X))
97 #define isalnum(c)      ((int)((__libc_ctype_ + 1)[(int)(c)] & (_A|_D)))
98 #define isprint(c)      ((int)((__libc_ctype_ + 1)[(int)(c)] & _R))
99 #define isgraph(c)      ((int)((__libc_ctype_ + 1)[(int)(c)] & _G))
100 #define iscntrl(c)      ((int)((__libc_ctype_ + 1)[(int)(c)] & _C))
101 #define tolower(c)      ((int)((__libc_tolower_tab_ + 1)[(int)(c)]))
102 #define toupper(c)      ((int)((__libc_toupper_tab_ + 1)[(int)(c)]))
103
104 #if defined(__XSI_VISIBLE)
105 #define isascii(c)      ((unsigned)(c) <= 0177)
106 #define toascii(c)      ((c) & 0177)
107 #define _tolower(c)     ((c) - 'A' + 'a')
108 #define _toupper(c)     ((c) - 'a' + 'A')
109 #endif
110
111 #if __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE >= 200112L || \
112     __XSI_VISIBLE >= 600
113 #define isblank(c)      ((int)((__libc_ctype_ + 1)[(int)(c)] & _B))
114 #endif
115
116 #ifdef _CTYPE_PRIVATE
117 #include <machine/limits.h>     /* for CHAR_BIT */
118
119 #define _CTYPE_NUM_CHARS        (1 << CHAR_BIT)
120
121 extern const __uint16_t __libc_C_ctype_[];
122 extern const __int16_t  __libc_C_toupper_[];
123 extern const __int16_t  __libc_C_tolower_[];
124 #endif
125
126 #endif /* !_CTYPE_H_ */