Build aicasm as host program, not via world's compiler.
[dragonfly.git] / include / ctype.h
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. 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.
9 *
10 * This code is derived from software contributed to Berkeley by
11 * Paul Borman at Krystal Technologies.
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 8.4 (Berkeley) 1/21/94
42 * $FreeBSD: src/include/ctype.h,v 1.16 2000/02/08 07:43:23 obrien Exp $
e5b1cd61 43 * $DragonFly: src/include/ctype.h,v 1.5 2004/10/29 05:44:40 asmodai Exp $
984263bc
MD
44 */
45
46#ifndef _CTYPE_H_
47#define _CTYPE_H_
48
e2565a42
MD
49#ifndef _SYS_STDINT_H_
50#include <sys/stdint.h> /* __ct_rune_t and friends */
51#endif
52
984263bc
MD
53/*
54 * XXX <runetype.h> brings massive namespace pollution (rune_t and struct
55 * member names).
56 */
57#include <runetype.h>
58
59#define _CTYPE_A 0x00000100L /* Alpha */
60#define _CTYPE_C 0x00000200L /* Control */
61#define _CTYPE_D 0x00000400L /* Digit */
62#define _CTYPE_G 0x00000800L /* Graph */
63#define _CTYPE_L 0x00001000L /* Lower */
64#define _CTYPE_P 0x00002000L /* Punct */
65#define _CTYPE_S 0x00004000L /* Space */
66#define _CTYPE_U 0x00008000L /* Upper */
67#define _CTYPE_X 0x00010000L /* X digit */
68#define _CTYPE_B 0x00020000L /* Blank */
69#define _CTYPE_R 0x00040000L /* Print */
70#define _CTYPE_I 0x00080000L /* Ideogram */
71#define _CTYPE_T 0x00100000L /* Special */
72#define _CTYPE_Q 0x00200000L /* Phonogram */
e5b1cd61
JR
73#define _CTYPE_SW0 0x20000000L /* 0 width character */
74#define _CTYPE_SW1 0x40000000L /* 1 width character */
75#define _CTYPE_SW2 0x80000000L /* 2 width character */
76#define _CTYPE_SW3 0xc0000000L /* 3 width character */
77#define _CTYPE_SWM 0xe0000000L /* Mask for screen width data */
78#define _CTYPE_SWS 30 /* Bits to shift to get width */
984263bc
MD
79
80__BEGIN_DECLS
7c4af8e1
MD
81int isalnum (int);
82int isalpha (int);
83int iscntrl (int);
84int isdigit (int);
85int isgraph (int);
86int islower (int);
87int isprint (int);
88int ispunct (int);
89int isspace (int);
90int isupper (int);
91int isxdigit (int);
92int tolower (int);
93int toupper (int);
984263bc
MD
94
95#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
7c4af8e1
MD
96int digittoint (int);
97int isascii (int);
98int isblank (int);
99int ishexnumber (int);
100int isideogram (int);
101int isnumber (int);
102int isphonogram (int);
103int isrune (int);
104int isspecial (int);
105int toascii (int);
984263bc
MD
106#endif
107__END_DECLS
108
109#define __istype(c,f) (!!__maskrune((c),(f)))
110
111#define isalnum(c) __istype((c), _CTYPE_A|_CTYPE_D)
112#define isalpha(c) __istype((c), _CTYPE_A)
113#define iscntrl(c) __istype((c), _CTYPE_C)
114#define isdigit(c) __isctype((c), _CTYPE_D) /* ANSI -- locale independent */
115#define isgraph(c) __istype((c), _CTYPE_G)
116#define islower(c) __istype((c), _CTYPE_L)
117#define isprint(c) __istype((c), _CTYPE_R)
118#define ispunct(c) __istype((c), _CTYPE_P)
119#define isspace(c) __istype((c), _CTYPE_S)
120#define isupper(c) __istype((c), _CTYPE_U)
121#define isxdigit(c) __isctype((c), _CTYPE_X) /* ANSI -- locale independent */
122#define tolower(c) __tolower(c)
123#define toupper(c) __toupper(c)
124
125#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
126#define digittoint(c) __maskrune((c), 0xFF)
127#define isascii(c) (((c) & ~0x7F) == 0)
128#define isblank(c) __istype((c), _CTYPE_B)
129#define ishexnumber(c) __istype((c), _CTYPE_X)
130#define isideogram(c) __istype((c), _CTYPE_I)
131#define isnumber(c) __istype((c), _CTYPE_D)
132#define isphonogram(c) __istype((c), _CTYPE_Q)
133#define isrune(c) __istype((c), 0xFFFFFF00L)
134#define isspecial(c) __istype((c), _CTYPE_T)
135#define toascii(c) ((c) & 0x7F)
136#endif
137
984263bc 138__BEGIN_DECLS
7c4af8e1
MD
139unsigned long ___runetype (__ct_rune_t);
140__ct_rune_t ___tolower (__ct_rune_t);
141__ct_rune_t ___toupper (__ct_rune_t);
984263bc
MD
142__END_DECLS
143
144/*
145 * _EXTERNALIZE_CTYPE_INLINES_ is defined in locale/nomacros.c to tell us
146 * to generate code for extern versions of all our inline functions.
147 */
148#ifdef _EXTERNALIZE_CTYPE_INLINES_
149#define _USE_CTYPE_INLINE_
150#define static
151#define __inline
152#endif
153
154/*
155 * Use inline functions if we are allowed to and the compiler supports them.
156 */
157#if !defined(_DONT_USE_CTYPE_INLINE_) && \
158 (defined(_USE_CTYPE_INLINE_) || defined(__GNUC__) || defined(__cplusplus))
159static __inline int
e2565a42 160__maskrune(__ct_rune_t _c, unsigned long _f)
984263bc
MD
161{
162 return ((_c < 0 || _c >= _CACHED_RUNES) ? ___runetype(_c) :
163 _CurrentRuneLocale->runetype[_c]) & _f;
164}
165
166static __inline int
e2565a42 167__isctype(__ct_rune_t _c, unsigned long _f)
984263bc
MD
168{
169 return (_c < 0 || _c >= _CACHED_RUNES) ? 0 :
170 !!(_DefaultRuneLocale.runetype[_c] & _f);
171}
172
e2565a42
MD
173static __inline __ct_rune_t
174__toupper(__ct_rune_t _c)
984263bc
MD
175{
176 return (_c < 0 || _c >= _CACHED_RUNES) ? ___toupper(_c) :
177 _CurrentRuneLocale->mapupper[_c];
178}
179
e2565a42
MD
180static __inline __ct_rune_t
181__tolower(__ct_rune_t _c)
984263bc
MD
182{
183 return (_c < 0 || _c >= _CACHED_RUNES) ? ___tolower(_c) :
184 _CurrentRuneLocale->maplower[_c];
185}
186
187#else /* not using inlines */
188
189__BEGIN_DECLS
7c4af8e1
MD
190int __maskrune (__ct_rune_t, unsigned long);
191int __isctype (__ct_rune_t, unsigned long);
192__ct_rune_t __toupper (__ct_rune_t);
193__ct_rune_t __tolower (__ct_rune_t);
984263bc
MD
194__END_DECLS
195#endif /* using inlines */
196
197#endif /* !_CTYPE_H_ */