51 static void zeroTables(
void);
52 static void markString(attr_t macro,
char const* s);
53 static void unMarkString(attr_t macro,
char const* s);
54 static void markRange(attr_t macro,
char from,
char to);
55 static void moveMacro(attr_t from, attr_t to);
56 static void setLowHi(
char const firstlow,
char const lastlow,
char const firsthi);
58 char NTL_tolower_tab[1 + CHAR_MAX - CHAR_MIN];
59 char NTL_toupper_tab[1 + CHAR_MAX - CHAR_MIN];
60 attr_t NTL_char_attrib[1 + CHAR_MAX - CHAR_MIN];
67 static void makeTables(
void)
71 markString(
pgn_blank,
"\011\013\014\040");
87 markString(
pgn_alpha,
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
114 setLowHi(
'a',
'z',
'A');
115 setLowHi(
'\xe0',
'\xf6',
'\xc0');
116 setLowHi(
'\xf8',
'\xfe',
'\xd8');
124 static void dumphw(attr_t* p,
int beg);
125 static void dumphb(
char* p,
int beg);
135 printf(
"/*\n * Automatically Generated Tables - DO NOT EDIT\n* /\n");
136 printf(
"#include <limits.h>\n#include \"chattr.h\"\n");
139 printf(
"char const ToLowerTab_8859_1[] = {\n");
140 printf(
"#if (CHAR_MIN<0)\n");
141 i = (int)((
char)SCHAR_MIN);
142 dumphb(NTL_tolower_tab, i);
144 printf(
"#endif /* (CHAR_MIN<0)* /\n");
146 dumphb(NTL_tolower_tab, i);
147 printf(
"#if (!(CHAR_MIN<0))\n");
149 i = (int)((
char)SCHAR_MIN);
150 dumphb(NTL_tolower_tab, i);
151 printf(
"#endif /* (!(CHAR_MIN<0))* /\n");
155 printf(
"char const ToUpperTab_8859_1[] = {\n");
156 printf(
"#if (CHAR_MIN<0)\n");
157 i = (int)((
char)SCHAR_MIN);
158 dumphb(NTL_toupper_tab, i);
160 printf(
"#endif /* (CHAR_MIN<0)* /\n");
162 dumphb(NTL_toupper_tab, i);
163 printf(
"#if (!(CHAR_MIN<0))\n");
165 i = (int)((
char)SCHAR_MIN);
166 dumphb(NTL_toupper_tab, i);
167 printf(
"#endif /* (!(CHAR_MIN<0))* /\n");
171 printf(
"attr_t const PGN_CharAttrTab[] = {\n");
172 printf(
"#if (CHAR_MIN<0)\n");
173 i = (int)((
char)SCHAR_MIN);
174 dumphw(NTL_char_attrib, i);
176 printf(
"#endif /* (CHAR_MIN<0)* /\n");
178 dumphw(NTL_char_attrib, i);
179 printf(
"#if (!(CHAR_MIN<0))\n");
181 i = (int)((
char)SCHAR_MIN);
182 dumphw(NTL_char_attrib, i);
183 printf(
"#endif /* (!(CHAR_MIN<0))* /\n");
189 static void zeroTables(
void)
191 for (
int i = CHAR_MIN; i <= CHAR_MAX; ++i)
193 NTL_tolower_tab[i - CHAR_MIN] = (char)i;
194 NTL_toupper_tab[i - CHAR_MIN] = (char)i;
195 NTL_char_attrib[i - CHAR_MIN] = 0x0000;
199 static void markString(attr_t macro,
char const* s)
202 NTL_char_attrib[*(s++) - CHAR_MIN] |= macro;
205 static void unMarkString(attr_t macro,
char const* s)
208 NTL_char_attrib[*(s++) - CHAR_MIN]& = ~macro;
211 static void markRange(attr_t macro,
char from,
char to)
213 for (
int i = CHAR_MIN; i <= CHAR_MAX; ++i)
214 if (((
unsigned char)i >= (
unsigned char)from)
215 && ((
unsigned char)i <= (
unsigned char)to))
216 NTL_char_attrib[(char)i - CHAR_MIN] |= macro;
219 static void moveMacro(attr_t from, attr_t to)
221 for (
int i = CHAR_MIN; i <= CHAR_MAX; ++i)
222 if (NTL_char_attrib[i - CHAR_MIN] & from)
223 NTL_char_attrib[i - CHAR_MIN] |= to;
226 static void setLowHi(
char const firstlow,
char const lastlow,
char const firsthi)
228 for (
int i = CHAR_MIN; i <= CHAR_MAX; ++i)
229 if (((
unsigned char)i >= (
unsigned char)firstlow)
230 && ((
unsigned char)i <= (
unsigned char)lastlow))
232 int j = ((int)((
char)(i + (int)(firsthi - firstlow))));
233 NTL_tolower_tab[((char)j) - CHAR_MIN] = (char)i;
234 NTL_toupper_tab[((char)i) - CHAR_MIN] = (char)j;
243 static void dumphb(
char* tbl,
int beg)
246 char* p =& tbl[beg - CHAR_MIN];
248 for (i = 0; i <= SCHAR_MAX; i += ROWSIZE)
254 c = (
unsigned char)(beg + i);
256 if ((c > 0) && (c < SCHAR_MAX) && (isprint(c)) && (c !=
'\\')
260 printf(
" x%02x", ((
int)c));
262 c = (
unsigned char)(beg + k);
264 if ((c > 0) && (c < SCHAR_MAX) && (isprint(c)) && (c !=
'\\')
268 printf(
"x%02x", ((
int)c));
271 for (j = i; j <= k; j++)
274 if ((c > 0) && (c < SCHAR_MAX) && (isprint(c)) && (c !=
'\\')
278 printf(
" '\\x%02x'", ((
int)c));
286 static void dumphw(attr_t* tbl,
int beg)
289 attr_t* p =& tbl[beg - CHAR_MIN];
291 for (i = 0; i <= SCHAR_MAX; i += ROWSIZE)
297 c = (
unsigned char)(beg + i);
299 if ((c > 0) && (c < SCHAR_MAX) && (isprint(c)) && (c !=
'\\')
303 printf(
" x%02x", ((
int)c));
305 c = (
unsigned char)(beg + k);
307 if ((c > 0) && (c < SCHAR_MAX) && (isprint(c)) && (c !=
'\\')
311 printf(
"x%02x", ((
int)c));
314 for (j = i; j <= k; j++)
316 printf(
" 0x%04x", p[j] & 0xffffffff);
attr_t const pgn_digit
0123456789
attr_t const pgn_file
abcdefgh
attr_t const pgn_eol
'\r' |& #39;\n'
attr_t const pgn_tag_separator_junk
:=
attr_t const pgn_piece
RNBQK.
attr_t const pgn_tagname_continuation
(pgn_alnum |& #39;_')
Character attribute definitions and arrays.
attr_t const pgn_alnum
(pgn_alpha | pgn_digit)
attr_t const pgn_comment_start
{;
attr_t const pgn_alpha
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
attr_t const pgn_white_space
(pgn_blank | pgn_eol)
attr_t const pgn_quote_or_eol
(ntl_eol |& #39;"')
attr_t const pgn_punctuation_junk
,;
attr_t const pgn_printable_string
ascii range(-96, -1) | ascii range(35, 91) |& #39;& #39; | ascii range(93, 126) |& #39;!'
attr_t const pgn_printable
ascii range(-96, -1) | ascii range(32, 126)
attr_t const pgn_blank
'& #39; |& #39;\t' |& #39;\v' |& #39;\f'. Note that& #39;\f' is normally not legal in a PGN.
attr_t const pgn_rank
12345678
attr_t const pgn_printable_comment
ascii range(-96, -1) | ascii range(32, 124) |& #39;~' | pgn_blank | pgn_eol