Merge from vendor branch GCC:
[dragonfly.git] / include / ctype.h
CommitLineData
984263bc 1/*
32a7b49a
JS
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
984263bc
MD
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.
9 *
984263bc
MD
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.
32a7b49a 18 * 3. Neither the name of the University nor the names of its contributors
984263bc
MD
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
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.
33 *
32a7b49a 34 * @(#)ctype.h 5.3 (Berkeley) 4/3/91
6e1e925c 35 * $NetBSD: src/include/ctype.h,v 1.25 2003/10/22 15:51:18 kleink Exp $
82ca767a 36 * $DragonFly: src/include/ctype.h,v 1.15 2005/07/07 07:20:11 dillon Exp $
984263bc
MD
37 */
38
39#ifndef _CTYPE_H_
32a7b49a 40#define _CTYPE_H_
984263bc 41
32a7b49a
JS
42#include <sys/cdefs.h>
43#include <machine/stdint.h>
e2565a42 44
2bbbc6f2
JS
45#define _U 0x0001
46#define _L 0x0002
47#define _D 0x0004
48#define _S 0x0008
49#define _P 0x0010
50#define _C 0x0020
51#define _X 0x0040
52#define _B 0x0080
53#define _A 0x0100
6d318c6e
YT
54#define _G 0x0200
55#define _R 0x0400
32a7b49a
JS
56
57extern const __uint16_t *__libc_ctype_;
58extern const __int16_t *__libc_tolower_tab_;
59extern const __int16_t *__libc_toupper_tab_;
984263bc
MD
60
61__BEGIN_DECLS
32a7b49a
JS
62int isalnum(int);
63int isalpha(int);
64int iscntrl(int);
65int isdigit(int);
66int isgraph(int);
67int islower(int);
68int isprint(int);
69int ispunct(int);
70int isspace(int);
71int isupper(int);
72int isxdigit(int);
73int tolower(int);
74int toupper(int);
75
76#if defined(__XSI_VISIBLE)
77int isascii(int);
78int toascii(int);
79int _tolower(int);
80int _toupper(int);
984263bc 81#endif
984263bc 82
32a7b49a
JS
83#if _ISO_C_VISIBLE >= 1999 || _POSIX_VISIBLE >= 200112L || \
84 __XSI_VISIBLE >= 600
85int isblank(int);
984263bc 86#endif
984263bc
MD
87__END_DECLS
88
b30a327b
MD
89#ifdef _CTYPE_PRIVATE
90extern const __uint16_t __libc_C_ctype_[];
91extern const __int16_t __libc_C_toupper_[];
92extern const __int16_t __libc_C_tolower_[];
93#endif
94
95/*
96 * don't get all wishy washy and try to support architectures where
97 * char isn't 8 bits. It's 8 bits, period.
98 */
6e1e925c
MD
99#if !defined(_CTYPE_H_DISABLE_MACROS_)
100
b30a327b
MD
101#define _CTYPE_NUM_CHARS (1 << (8*sizeof(char)))
102
103static __inline int
104__libc_ctype_index(__uint16_t mask, int c)
105{
106 if (c < -1 || c >= _CTYPE_NUM_CHARS)
107 return(0); /* XXX maybe assert instead? */
108 return(__libc_ctype_[c + 1] & mask);
109}
110
111static __inline int
82ca767a 112__libc_ctype_convert(const __int16_t *array, int c)
b30a327b
MD
113{
114 if (c < -1 || c >= _CTYPE_NUM_CHARS)
115 return(c); /* XXX maybe assert instead? */
116 return(array[c + 1]);
117}
118
119#ifndef _CTYPE_PRIVATE
120#undef _CTYPE_NUM_CHARS
121#endif
122
123#define isdigit(c) __libc_ctype_index(_D, c)
124#define islower(c) __libc_ctype_index(_L, c)
125#define isspace(c) __libc_ctype_index(_S, c)
126#define ispunct(c) __libc_ctype_index(_P, c)
127#define isupper(c) __libc_ctype_index(_U, c)
128#define isalpha(c) __libc_ctype_index(_A, c)
129#define isxdigit(c) __libc_ctype_index(_X, c)
130#define isalnum(c) __libc_ctype_index(_A|_D, c)
131#define isprint(c) __libc_ctype_index(_R, c)
132#define isgraph(c) __libc_ctype_index(_G, c)
133#define iscntrl(c) __libc_ctype_index(_C, c)
134#define tolower(c) __libc_ctype_convert(__libc_tolower_tab_, c)
135#define toupper(c) __libc_ctype_convert(__libc_toupper_tab_, c)
32a7b49a
JS
136
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')
984263bc
MD
142#endif
143
32a7b49a
JS
144#if __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE >= 200112L || \
145 __XSI_VISIBLE >= 600
b30a327b 146#define isblank(c) __libc_ctype_index(_B, c)
32a7b49a 147#endif
984263bc 148
6e1e925c
MD
149#endif /* !_CTYPE_H_DISABLE_MACROS_ */
150
984263bc 151#endif /* !_CTYPE_H_ */