]> git.sur5r.net Git - cc65/blob - include/ctype.h
Fixed _textcolor definition.
[cc65] / include / ctype.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  ctype.h                                  */
4 /*                                                                           */
5 /*                            Character handling                             */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2013, Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 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 character 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 #if __CC65_STD__ >= __CC65_STD_CC65__
81 unsigned char __fastcall__ toascii (unsigned char c);
82 /* Convert a target-specific character to ASCII. */
83 #endif
84
85
86
87 /* When --eagerly-inline-funcs is enabled, overload most of the above
88 ** functions by macroes. The function prototypes are available again after
89 ** #undef'ing the macroes.
90 ** Please note that the following macroes do NOT handle EOF correctly, as
91 ** stated in the manual. If you need correct behaviour for EOF, don't
92 ** use --eagerly-inline-funcs, or #undefine the following macroes.
93 */
94 #ifdef __EAGERLY_INLINE_FUNCS__
95
96 #define isalnum(c)  (__AX__ = (c),                      \
97                     __asm__ ("tay"),                    \
98                     __asm__ ("lda %v,y", _ctype),       \
99                     __asm__ ("and #%b", _CT_ALNUM),     \
100                     __AX__)
101
102 #define isalpha(c)  (__AX__ = (c),                      \
103                     __asm__ ("tay"),                    \
104                     __asm__ ("lda %v,y", _ctype),       \
105                     __asm__ ("and #%b", _CT_ALPHA),     \
106                     __AX__)
107
108 #if __CC65_STD__ >= __CC65_STD_C99__
109 #define isblank(c)  (__AX__ = (c),                      \
110                     __asm__ ("tay"),                    \
111                     __asm__ ("lda %v,y", _ctype),       \
112                     __asm__ ("and #%b", _CT_SPACE_TAB), \
113                     __AX__)
114 #endif
115
116 #define iscntrl(c)  (__AX__ = (c),                      \
117                     __asm__ ("tay"),                    \
118                     __asm__ ("lda %v,y", _ctype),       \
119                     __asm__ ("and #%b", _CT_CNTRL),     \
120                     __AX__)
121
122 #define isdigit(c)  (__AX__ = (c),                      \
123                     __asm__ ("tay"),                    \
124                     __asm__ ("lda %v,y", _ctype),       \
125                     __asm__ ("and #%b", _CT_DIGIT),     \
126                     __AX__)
127
128 #define isgraph(c)  (__AX__ = (c),                      \
129                     __asm__ ("tay"),                    \
130                     __asm__ ("lda %v,y", _ctype),       \
131                     __asm__ ("and #%b", _CT_NOT_GRAPH), \
132                     __asm__ ("cmp #1"),                 \
133                     __asm__ ("lda #1"),                 \
134                     __asm__ ("sbc #1"),                 \
135                     __AX__)
136
137 #define islower(c)  (__AX__ = (c),                      \
138                     __asm__ ("tay"),                    \
139                     __asm__ ("lda %v,y", _ctype),       \
140                     __asm__ ("and #%b", _CT_LOWER),     \
141                     __AX__)
142
143 #define isprint(c)  (__AX__ = (c),                      \
144                     __asm__ ("tay"),                    \
145                     __asm__ ("lda %v,y", _ctype),       \
146                     __asm__ ("and #%b", _CT_NOT_PRINT), \
147                     __asm__ ("eor #%b", _CT_NOT_PRINT), \
148                     __AX__)
149
150 #define ispunct(c)  (__AX__ = (c),                      \
151                     __asm__ ("tay"),                    \
152                     __asm__ ("lda %v,y", _ctype),       \
153                     __asm__ ("and #%b", _CT_NOT_PUNCT), \
154                     __asm__ ("cmp #1"),                 \
155                     __asm__ ("lda #1"),                 \
156                     __asm__ ("sbc #1"),                 \
157                     __AX__)
158
159 #define isspace(c)  (__AX__ = (c),                      \
160                     __asm__ ("tay"),                    \
161                     __asm__ ("lda %v,y", _ctype),       \
162                     __asm__ ("and #%b", _CT_WS),        \
163                     __AX__)
164
165 #define isupper(c)  (__AX__ = (c),                      \
166                     __asm__ ("tay"),                    \
167                     __asm__ ("lda %v,y", _ctype),       \
168                     __asm__ ("and #%b", _CT_UPPER),     \
169                     __AX__)
170
171 #define isxdigit(c) (__AX__ = (c),                      \
172                     __asm__ ("tay"),                    \
173                     __asm__ ("lda %v,y", _ctype),       \
174                     __asm__ ("and #%b", _CT_XDIGIT),    \
175                     __AX__)
176
177 #endif
178
179
180
181 /* End of ctype.h */
182 #endif
183
184
185