Magellan Linux

Contents of /trunk/mkinitrd-magellan/klibc/usr/include/ctype.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 815 - (show annotations) (download)
Fri Apr 24 18:32:46 2009 UTC (15 years ago) by niro
File MIME type: text/plain
File size: 3183 byte(s)
-updated to klibc-1.5.15
1 /*
2 * ctype.h
3 *
4 * This assumes ISO 8859-1, being a reasonable superset of ASCII.
5 */
6
7 #ifndef _CTYPE_H
8 #define _CTYPE_H
9
10 #include <klibc/extern.h>
11 #include <klibc/compiler.h>
12
13 /*
14 * This relies on the following definitions:
15 *
16 * cntrl = !print
17 * alpha = upper|lower
18 * graph = punct|alpha|digit
19 * blank = '\t' || ' ' (per POSIX requirement)
20 */
21 enum {
22 __ctype_upper = (1 << 0),
23 __ctype_lower = (1 << 1),
24 __ctype_digit = (1 << 2),
25 __ctype_xdigit = (1 << 3),
26 __ctype_space = (1 << 4),
27 __ctype_print = (1 << 5),
28 __ctype_punct = (1 << 6),
29 __ctype_cntrl = (1 << 7),
30 };
31
32 __extern int isalnum(int);
33 __extern int isalpha(int);
34 __extern int isascii(int);
35 __extern int isblank(int);
36 __extern int iscntrl(int);
37 __extern int isdigit(int);
38 __extern int isgraph(int);
39 __extern int islower(int);
40 __extern int isprint(int);
41 __extern int ispunct(int);
42 __extern int isspace(int);
43 __extern int isupper(int);
44 __extern int isxdigit(int);
45 __extern int toupper(int);
46 __extern int tolower(int);
47
48 extern const unsigned char __ctypes[];
49
50 __must_inline int __ctype_isalnum(int __c)
51 {
52 return __ctypes[__c + 1] &
53 (__ctype_upper | __ctype_lower | __ctype_digit);
54 }
55
56 __must_inline int __ctype_isalpha(int __c)
57 {
58 return __ctypes[__c + 1] & (__ctype_upper | __ctype_lower);
59 }
60
61 __must_inline int __ctype_isascii(int __c)
62 {
63 return !(__c & ~0x7f);
64 }
65
66 __must_inline int __ctype_isblank(int __c)
67 {
68 return (__c == '\t') || (__c == ' ');
69 }
70
71 __must_inline int __ctype_iscntrl(int __c)
72 {
73 return __ctypes[__c + 1] & __ctype_cntrl;
74 }
75
76 __must_inline int __ctype_isdigit(int __c)
77 {
78 return ((unsigned)__c - '0') <= 9;
79 }
80
81 __must_inline int __ctype_isgraph(int __c)
82 {
83 return __ctypes[__c + 1] &
84 (__ctype_upper | __ctype_lower | __ctype_digit | __ctype_punct);
85 }
86
87 __must_inline int __ctype_islower(int __c)
88 {
89 return __ctypes[__c + 1] & __ctype_lower;
90 }
91
92 __must_inline int __ctype_isprint(int __c)
93 {
94 return __ctypes[__c + 1] & __ctype_print;
95 }
96
97 __must_inline int __ctype_ispunct(int __c)
98 {
99 return __ctypes[__c + 1] & __ctype_punct;
100 }
101
102 __must_inline int __ctype_isspace(int __c)
103 {
104 return __ctypes[__c + 1] & __ctype_space;
105 }
106
107 __must_inline int __ctype_isupper(int __c)
108 {
109 return __ctypes[__c + 1] & __ctype_upper;
110 }
111
112 __must_inline int __ctype_isxdigit(int __c)
113 {
114 return __ctypes[__c + 1] & __ctype_xdigit;
115 }
116
117 /* Note: this is decimal, not hex, to avoid accidental promotion to unsigned */
118 #define _toupper(__c) ((__c) & ~32)
119 #define _tolower(__c) ((__c) | 32)
120
121 __must_inline int __ctype_toupper(int __c)
122 {
123 return __ctype_islower(__c) ? _toupper(__c) : __c;
124 }
125
126 __must_inline int __ctype_tolower(int __c)
127 {
128 return __ctype_isupper(__c) ? _tolower(__c) : __c;
129 }
130
131 #ifdef __CTYPE_NO_INLINE
132 # define __CTYPEFUNC(X) \
133 __extern int X(int);
134 #else
135 #define __CTYPEFUNC(X) \
136 __extern inline int X(int __c) \
137 { \
138 return __ctype_##X(__c); \
139 }
140 #endif
141
142 __CTYPEFUNC(isalnum)
143 __CTYPEFUNC(isalpha)
144 __CTYPEFUNC(isascii)
145 __CTYPEFUNC(isblank)
146 __CTYPEFUNC(iscntrl)
147 __CTYPEFUNC(isdigit)
148 __CTYPEFUNC(isgraph)
149 __CTYPEFUNC(islower)
150 __CTYPEFUNC(isprint)
151 __CTYPEFUNC(ispunct)
152 __CTYPEFUNC(isspace)
153 __CTYPEFUNC(isupper)
154 __CTYPEFUNC(isxdigit)
155 __CTYPEFUNC(toupper)
156 __CTYPEFUNC(tolower)
157 #endif /* _CTYPE_H */