]> git.sur5r.net Git - cc65/blob - include/ctype.h
Fixed a naming problem (Stefan Haubenthal).
[cc65] / include / ctype.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  ctype.h                                  */
4 /*                                                                           */
5 /*                            Character handling                             */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2004 Ullrich von Bassewitz                                       */
10 /*               Römerstrasse 52                                             */
11 /*               D-70794 Filderstadt                                         */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef _CTYPE_H
37 #define _CTYPE_H
38
39
40 /* The array containing character classification data */
41 extern unsigned char _ctype[256];
42
43 /* Bits used to specify characters classes */
44 #define _CT_LOWER       0x01    /* 0 - Lower case char */
45 #define _CT_UPPER       0x02    /* 1 - Upper case char */
46 #define _CT_DIGIT       0x04    /* 2 - Numeric digit */
47 #define _CT_XDIGIT      0x08    /* 3 - Hex digit (both, lower and upper) */
48 #define _CT_CNTRL       0x10    /* 4 - Control character */
49 #define _CT_SPACE       0x20    /* 5 - The space character itself */
50 #define _CT_OTHER_WS    0x40    /* 6 - Other whitespace ('\f', '\n', '\r', '\t' and '\v') */
51 #define _CT_SPACE_TAB   0x80    /* 7 - Space or tab character */
52
53 /* Bit combinations */
54 #define _CT_ALNUM       (_CT_LOWER | _CT_UPPER | _CT_DIGIT)
55 #define _CT_ALPHA       (_CT_LOWER | _CT_UPPER)
56 #define _CT_NOT_GRAPH   (_CT_CNTRL | _CT_SPACE)
57 #define _CT_NOT_PRINT   (_CT_CNTRL)
58 #define _CT_NOT_PUNCT   (_CT_SPACE | _CT_CNTRL | _CT_DIGIT | _CT_UPPER | _CT_LOWER)
59 #define _CT_WS          (_CT_SPACE | _CT_OTHER_WS)
60
61 /* Character classification functions */
62 int __fastcall__ isalnum (int c);
63 int __fastcall__ isalpha (int c);
64 int __fastcall__ iscntrl (int c);
65 int __fastcall__ isdigit (int c);
66 int __fastcall__ isgraph (int c);
67 int __fastcall__ islower (int c);
68 int __fastcall__ isprint (int c);
69 int __fastcall__ ispunct (int c);
70 int __fastcall__ isspace (int c);
71 int __fastcall__ isupper (int c);
72 int __fastcall__ isxdigit (int c);
73 #if __CC65_STD__ >= __CC65_STD_C99__
74 int __fastcall__ isblank (int c);       /* New in C99 */
75 #endif
76
77 int __fastcall__ toupper (int c);       /* Always external */
78 int __fastcall__ tolower (int c);       /* Always external */
79
80
81
82 /* When inlining of known function is enabled, overload most of the above
83  * functions by macros. The function prototypes are again available after
84  * #undef'ing the macros.
85  * Please note that the following macros do NOT handle EOF correctly, as
86  * stated in the manual. If you need correct behaviour for EOF, don't
87  * use -Os, or #undefine the following macros.
88  */
89 #ifdef __OPT_s__
90
91 #define isalnum(c)  (__AX__ = (c),                      \
92                     __asm__ ("tay"),                    \
93                     __asm__ ("lda %v,y", _ctype),       \
94                     __asm__ ("and #%b", _CT_ALNUM),     \
95                     __AX__)
96
97 #define isalpha(c)  (__AX__ = (c),                      \
98                     __asm__ ("tay"),                    \
99                     __asm__ ("lda %v,y", _ctype),       \
100                     __asm__ ("and #%b", _CT_ALPHA),     \
101                     __AX__)
102
103 #if __CC65_STD__ >= __CC65_STD_C99__
104 #define isblank(c)  (__AX__ = (c),                      \
105                     __asm__ ("tay"),                    \
106                     __asm__ ("lda %v,y", _ctype),       \
107                     __asm__ ("and #%b", _CT_SPACE_TAB), \
108                     __AX__)
109 #endif
110
111 #define iscntrl(c)  (__AX__ = (c),                      \
112                     __asm__ ("tay"),                    \
113                     __asm__ ("lda %v,y", _ctype),       \
114                     __asm__ ("and #%b", _CT_CNTRL),     \
115                     __AX__)
116
117 #define isdigit(c)  (__AX__ = (c),                      \
118                     __asm__ ("tay"),                    \
119                     __asm__ ("lda %v,y", _ctype),       \
120                     __asm__ ("and #%b", _CT_DIGIT),     \
121                     __AX__)
122
123 #define isgraph(c)  (__AX__ = (c),                      \
124                     __asm__ ("tay"),                    \
125                     __asm__ ("lda %v,y", _ctype),       \
126                     __asm__ ("eor #%b", _CT_NOT_GRAPH), \
127                     __asm__ ("and #%b", _CT_NOT_GRAPH), \
128                     __AX__)
129
130 #define islower(c)  (__AX__ = (c),                      \
131                     __asm__ ("tay"),                    \
132                     __asm__ ("lda %v,y", _ctype),       \
133                     __asm__ ("and #%b", _CT_LOWER),     \
134                     __AX__)
135
136 #define isprint(c)  (__AX__ = (c),                      \
137                     __asm__ ("tay"),                    \
138                     __asm__ ("lda %v,y", _ctype),       \
139                     __asm__ ("eor #%b", _CT_NOT_PRINT), \
140                     __asm__ ("and #%b", _CT_NOT_PRINT), \
141                     __AX__)
142
143 #define ispunct(c)  (__AX__ = (c),                      \
144                     __asm__ ("tay"),                    \
145                     __asm__ ("lda %v,y", _ctype),       \
146                     __asm__ ("eor #%b", _CT_NOT_PUNCT), \
147                     __asm__ ("and #%b", _CT_NOT_PUNCT), \
148                     __AX__)
149
150 #define isspace(c)  (__AX__ = (c),                      \
151                     __asm__ ("tay"),                    \
152                     __asm__ ("lda %v,y", _ctype),       \
153                     __asm__ ("and #%b", _CT_WS),        \
154                     __AX__)
155
156 #define isupper(c)  (__AX__ = (c),                      \
157                     __asm__ ("tay"),                    \
158                     __asm__ ("lda %v,y", _ctype),       \
159                     __asm__ ("and #%b", _CT_UPPER),     \
160                     __AX__)
161
162 #define isxdigit(c) (__AX__ = (c),                      \
163                     __asm__ ("tay"),                    \
164                     __asm__ ("lda %v,y", _ctype),       \
165                     __asm__ ("and #%b", _CT_XDIGIT),    \
166                     __AX__)
167
168 #endif
169
170
171
172 /* End of ctype.h */
173 #endif
174
175
176