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