xref: /original-bsd/include/ctype.h (revision 333da485)
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  * %sccs.include.redist.c%
14  *
15  *	@(#)ctype.h	8.4 (Berkeley) 01/21/94
16  */
17 
18 #ifndef	_CTYPE_H_
19 #define _CTYPE_H_
20 
21 #include <runetype.h>
22 
23 #define	_A	0x00000100L		/* Alpha */
24 #define	_C	0x00000200L		/* Control */
25 #define	_D	0x00000400L		/* Digit */
26 #define	_G	0x00000800L		/* Graph */
27 #define	_L	0x00001000L		/* Lower */
28 #define	_P	0x00002000L		/* Punct */
29 #define	_S	0x00004000L		/* Space */
30 #define	_U	0x00008000L		/* Upper */
31 #define	_X	0x00010000L		/* X digit */
32 #define	_B	0x00020000L		/* Blank */
33 #define	_R	0x00040000L		/* Print */
34 #define	_I	0x00080000L		/* Ideogram */
35 #define	_T	0x00100000L		/* Special */
36 #define	_Q	0x00200000L		/* Phonogram */
37 
38 #define isalnum(c)      __istype((c), (_A|_D))
39 #define isalpha(c)      __istype((c),     _A)
40 #define iscntrl(c)      __istype((c),     _C)
41 #define isdigit(c)      __isctype((c),    _D)	/* ANSI -- locale independent */
42 #define isgraph(c)      __istype((c),     _G)
43 #define islower(c)      __istype((c),     _L)
44 #define isprint(c)      __istype((c),     _R)
45 #define ispunct(c)      __istype((c),     _P)
46 #define isspace(c)      __istype((c),     _S)
47 #define isupper(c)      __istype((c),     _U)
48 #define isxdigit(c)     __isctype((c),    _X)	/* ANSI -- locale independent */
49 
50 #if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
51 #define	isascii(c)	((c & ~0x7F) == 0)
52 #define toascii(c)	((c) & 0x7F)
53 #define	digittoint(c)	__istype((c), 0xFF)
54 #define	isideogram(c)	__istype((c), _I)
55 #define	isphonogram(c)	__istype((c), _T)
56 #define	isspecial(c)	__istype((c), _Q)
57 #define isblank(c)	__istype((c), _B)
58 #define	isrune(c)	__istype((c),  0xFFFFFF00L)
59 #define	isnumber(c)	__istype((c), _D)
60 #define	ishexnumber(c)	__istype((c), _X)
61 #endif
62 
63 /* See comments in <machine/ansi.h> about _BSD_RUNE_T_. */
64 __BEGIN_DECLS
65 unsigned long	___runetype __P((_BSD_RUNE_T_));
66 _BSD_RUNE_T_	___tolower __P((_BSD_RUNE_T_));
67 _BSD_RUNE_T_	___toupper __P((_BSD_RUNE_T_));
68 __END_DECLS
69 
70 /*
71  * If your compiler supports prototypes and inline functions,
72  * #define _USE_CTYPE_INLINE_.  Otherwise, use the C library
73  * functions.
74  */
75 #if !defined(_USE_CTYPE_CLIBRARY_) && defined(__GNUC__) || defined(__cplusplus)
76 #define	_USE_CTYPE_INLINE_	1
77 #endif
78 
79 #if defined(_USE_CTYPE_INLINE_)
80 static __inline int
81 __istype(_BSD_RUNE_T_ c, unsigned long f)
82 {
83 	return((((c & _CRMASK) ? ___runetype(c) :
84 	    _CurrentRuneLocale->runetype[c]) & f) ? 1 : 0);
85 }
86 
87 static __inline int
88 __isctype(_BSD_RUNE_T_ c, unsigned long f)
89 {
90 	return((((c & _CRMASK) ? 0 :
91 	    _DefaultRuneLocale.runetype[c]) & f) ? 1 : 0);
92 }
93 
94 /* _ANSI_LIBRARY is defined by lib/libc/gen/isctype.c. */
95 #if !defined(_ANSI_LIBRARY)
96 static __inline _BSD_RUNE_T_
97 toupper(_BSD_RUNE_T_ c)
98 {
99 	return((c & _CRMASK) ?
100 	    ___toupper(c) : _CurrentRuneLocale->mapupper[c]);
101 }
102 
103 static __inline _BSD_RUNE_T_
104 tolower(_BSD_RUNE_T_ c)
105 {
106 	return((c & _CRMASK) ?
107 	    ___tolower(c) : _CurrentRuneLocale->maplower[c]);
108 }
109 #endif /* !_ANSI_LIBRARY */
110 
111 #else /* !_USE_CTYPE_INLINE_ */
112 
113 __BEGIN_DECLS
114 int		__istype __P((_BSD_RUNE_T_, unsigned long));
115 int		__isctype __P((_BSD_RUNE_T_, unsigned long));
116 _BSD_RUNE_T_	toupper __P((_BSD_RUNE_T_));
117 _BSD_RUNE_T_	tolower __P((_BSD_RUNE_T_));
118 __END_DECLS
119 #endif /* _USE_CTYPE_INLINE_ */
120 
121 #endif /* !_CTYPE_H_ */
122