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