4.4BSD snapshot (revision 8.1)
[unix-history] / usr / src / include / ctype.h
CommitLineData
7a00777e
KB
1/*
2 * Copyright (c) 1989 The Regents of the University of California.
3 * All rights reserved.
4 *
2c85d9be
KB
5 * This code is derived from software contributed to Berkeley by
6 * Paul Borman at Krystal Technologies.
7 *
863005e5 8 * %sccs.include.redist.c%
7a00777e 9 *
56559b70 10 * @(#)ctype.h 8.1 (Berkeley) %G%
7a00777e 11 */
a5c4c76d 12
2c85d9be 13#ifndef _CTYPE_H_
d2b7358e
KB
14#define _CTYPE_H_
15
19c596d9 16#ifndef _ANSI_SOURCE
2c85d9be 17#include <runetype.h>
19c596d9 18#endif
2c85d9be
KB
19
20#define _A 0x00000100L /* Alpha */
21#define _C 0x00000200L /* Control */
22#define _D 0x00000400L /* Digit */
23#define _G 0x00000800L /* Graph */
24#define _L 0x00001000L /* Lower */
25#define _P 0x00002000L /* Punct */
26#define _S 0x00004000L /* Space */
27#define _U 0x00008000L /* Upper */
28#define _X 0x00010000L /* X digit */
29#define _B 0x00020000L /* Blank */
30#define _R 0x00040000L /* Print */
31#define _I 0x00080000L /* Ideogram */
32#define _T 0x00100000L /* Special */
33#define _Q 0x00200000L /* Phonogram */
34
35#define isalnum(c) __istype((c), (_A|_D))
19c596d9
KB
36#define isalpha(c) __istype((c), _A)
37#define iscntrl(c) __istype((c), _C)
38#define isdigit(c) __isctype((c), _D) /* ANSI -- locale independent */
39#define isgraph(c) __istype((c), _G)
40#define islower(c) __istype((c), _L)
41#define isprint(c) __istype((c), _R)
42#define ispunct(c) __istype((c), _P)
43#define isspace(c) __istype((c), _S)
44#define isupper(c) __istype((c), _U)
45#define isxdigit(c) __isctype((c), _X) /* ANSI -- locale independent */
d2b7358e 46
02fa8db5 47#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
2c85d9be
KB
48#define isascii(c) ((c & ~0x7F) == 0)
49#define toascii(c) ((c) & 0x7F)
50#define digittoint(c) __istype((c), 0xFF)
51#define isideogram(c) __istype((c), _I)
52#define isphonogram(c) __istype((c), _T)
53#define isspecial(c) __istype((c), _Q)
54#define isblank(c) __istype((c), _B)
55#define isrune(c) __istype((c), 0xFFFFFF00L)
56#define isnumber(c) __istype((c), _D)
57#define ishexnumber(c) __istype((c), _X)
02fa8db5
KB
58#endif
59
19c596d9 60/* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */
2c85d9be
KB
61__BEGIN_DECLS
62extern unsigned long ___runetype __P((_BSD_RUNE_T_));
63extern _BSD_RUNE_T_ ___tolower __P((_BSD_RUNE_T_));
64extern _BSD_RUNE_T_ ___toupper __P((_BSD_RUNE_T_));
65__END_DECLS
66
67/*
19c596d9
KB
68 * If your compiler supports prototypes and inline functions,
69 * #define _USE_CTYPE_INLINE_. Otherwise, use the C library
70 * functions.
2c85d9be 71 */
19c596d9
KB
72#if !defined(_USE_CTYPE_CLIBRARY_) && defined(__GNUC__) || defined(__cplusplus)
73#define _USE_CTYPE_INLINE_ 1
74#endif
2c85d9be
KB
75
76#if defined(_USE_CTYPE_INLINE_)
77static inline int
5a622724 78__istype(_BSD_RUNE_T_ c, unsigned long f)
2c85d9be
KB
79{
80 return((((c & _CRMASK) ? ___runetype(c) :
81 _CurrentRuneLocale->runetype[c]) & f) ? 1 : 0);
82}
83
84static inline int
5a622724 85__isctype(_BSD_RUNE_T_ c, unsigned long f)
2c85d9be
KB
86{
87 return((((c & _CRMASK) ? 0 :
88 _DefaultRuneLocale.runetype[c]) & f) ? 1 : 0);
89}
90
19c596d9
KB
91/* _ANSI_LIBRARY is defined by lib/libc/gen/isctype.c. */
92#if !defined(_ANSI_LIBRARY)
2c85d9be 93static inline _BSD_RUNE_T_
5a622724 94toupper(_BSD_RUNE_T_ c)
2c85d9be
KB
95{
96 return((c & _CRMASK) ?
97 ___toupper(c) : _CurrentRuneLocale->mapupper[c]);
98}
99
100static inline _BSD_RUNE_T_
5a622724 101tolower(_BSD_RUNE_T_ c)
2c85d9be
KB
102{
103 return((c & _CRMASK) ?
104 ___tolower(c) : _CurrentRuneLocale->maplower[c]);
105}
106#endif /* !_ANSI_LIBRARY */
2c85d9be 107
19c596d9 108#else /* !_USE_CTYPE_INLINE_ */
2c85d9be 109
2c85d9be
KB
110__BEGIN_DECLS
111extern int __istype __P((_BSD_RUNE_T_, unsigned long));
112extern int __isctype __P((_BSD_RUNE_T_, unsigned long));
113extern _BSD_RUNE_T_ toupper __P((_BSD_RUNE_T_));
114extern _BSD_RUNE_T_ tolower __P((_BSD_RUNE_T_));
115__END_DECLS
19c596d9 116#endif /* _USE_CTYPE_INLINE_ */
2c85d9be 117
d2b7358e 118#endif /* !_CTYPE_H_ */