1 /*****************************************************************************/
5 /* Character handling */
9 /* (C) 1998-2000 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
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. */
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: */
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 */
32 /*****************************************************************************/
40 /* The array containing character classification data */
41 extern unsigned char _ctype[256];
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 */
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)
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 #ifndef __STRICT_ANSI__
74 int __fastcall__ isblank (int c); /* cc65 (and GNU) extension */
77 int __fastcall__ toupper (int c); /* Always external */
78 int __fastcall__ tolower (int c); /* Always external */
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.
91 #define isalnum(c) (__AX__ = (c), \
93 __asm__ ("lda %v,y", _ctype), \
94 __asm__ ("and #%b", _CT_ALNUM), \
97 #define isalpha(c) (__AX__ = (c), \
99 __asm__ ("lda %v,y", _ctype), \
100 __asm__ ("and #%b", _CT_ALPHA), \
104 #define isblank(c) (__AX__ = (c), \
106 __asm__ ("lda %v,y", _ctype), \
107 __asm__ ("and #%b", _CT_SPACE_TAB), \
111 #define iscntrl(c) (__AX__ = (c), \
113 __asm__ ("lda %v,y", _ctype), \
114 __asm__ ("and #%b", _CT_CNTRL), \
117 #define isdigit(c) (__AX__ = (c), \
119 __asm__ ("lda %v,y", _ctype), \
120 __asm__ ("and #%b", _CT_DIGIT), \
123 #define isgraph(c) (__AX__ = (c), \
125 __asm__ ("lda %v,y", _ctype), \
126 __asm__ ("eor #%b", _CT_NOT_GRAPH), \
127 __asm__ ("and #%b", _CT_NOT_GRAPH), \
130 #define islower(c) (__AX__ = (c), \
132 __asm__ ("lda %v,y", _ctype), \
133 __asm__ ("and #%b", _CT_LOWER), \
136 #define isprint(c) (__AX__ = (c), \
138 __asm__ ("lda %v,y", _ctype), \
139 __asm__ ("eor #%b", _CT_NOT_PRINT), \
140 __asm__ ("and #%b", _CT_NOT_PRINT), \
143 #define ispunct(c) (__AX__ = (c), \
145 __asm__ ("lda %v,y", _ctype), \
146 __asm__ ("eor #%b", _CT_NOT_PUNCT), \
147 __asm__ ("and #%b", _CT_NOT_PUNCT), \
150 #define isspace(c) (__AX__ = (c), \
152 __asm__ ("lda %v,y", _ctype), \
153 __asm__ ("and #%b", _CT_WS), \
156 #define isupper(c) (__AX__ = (c), \
158 __asm__ ("lda %v,y", _ctype), \
159 __asm__ ("and #%b", _CT_UPPER), \
162 #define isxdigit(c) (__AX__ = (c), \
164 __asm__ ("lda %v,y", _ctype), \
165 __asm__ ("and #%b", _CT_XDIGIT), \