]> git.cameronkatri.com Git - apple_cmds.git/blob - adv_cmds/mklocale/yacc.y
All: add Makefile.inc
[apple_cmds.git] / adv_cmds / mklocale / yacc.y
1 %{
2 /*-
3 * Copyright (c) 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Paul Borman at Krystal Technologies.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38 #ifndef lint
39 #if 0
40 static char sccsid[] = "@(#)yacc.y 8.1 (Berkeley) 6/6/93";
41 #endif /* 0 */
42 #endif /* not lint */
43
44 #include <sys/cdefs.h>
45 __FBSDID("$FreeBSD: src/usr.bin/mklocale/yacc.y,v 1.28 2008/01/22 00:04:50 ache Exp $");
46
47 #include <arpa/inet.h>
48
49 #include <ctype.h>
50 #include <err.h>
51 #include <stddef.h>
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include <string.h>
55 #include <unistd.h>
56
57 #include "ldef.h"
58 #include "extern.h"
59 #include "runefile.h"
60
61 #define MAX_CHARCLASS 4
62 #define CHARCLASSBIT 4
63
64 static void *xmalloc(unsigned int sz);
65 static uint32_t *xlalloc(unsigned int sz);
66 void yyerror(const char *s);
67 static uint32_t *xrelalloc(uint32_t *old, unsigned int sz);
68 static void dump_tables(void);
69 static void cleanout(void);
70
71 const char *locale_file = "<stdout>";
72
73 rune_map maplower = { { 0 }, NULL };
74 rune_map mapupper = { { 0 }, NULL };
75 rune_map types = { { 0 }, NULL };
76
77 _FileRuneLocale new_locale = { "", "", 0, 0, 0, {}, {}, {}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
78 char *variable = NULL;
79
80 rune_charclass charclasses[MAX_CHARCLASS];
81 int charclass_index = 0;
82
83 void set_map(rune_map *, rune_list *, uint32_t);
84 void set_digitmap(rune_map *, rune_list *);
85 void add_map(rune_map *, rune_list *, uint32_t);
86 static void usage(void);
87 %}
88
89 %union {
90 int32_t rune;
91 int i;
92 char *str;
93
94 rune_list *list;
95 }
96
97 %token <rune> RUNE
98 %token LBRK
99 %token RBRK
100 %token THRU
101 %token MAPLOWER
102 %token MAPUPPER
103 %token DIGITMAP
104 %token CHARCLASS
105 %token <i> LIST
106 %token <str> VARIABLE
107 %token ENCODING
108 %token INVALID
109 %token <str> STRING
110
111 %type <list> list
112 %type <list> map
113
114
115 %%
116
117 locale : /* empty */
118 | table
119 { dump_tables(); }
120 ;
121
122 table : entry
123 | table entry
124 ;
125
126 entry : ENCODING STRING
127 { if (strcmp($2, "NONE") &&
128 strcmp($2, "ASCII") &&
129 strcmp($2, "UTF-8") &&
130 strcmp($2, "EUC") &&
131 strcmp($2, "GBK") &&
132 strcmp($2, "GB18030") &&
133 strcmp($2, "GB2312") &&
134 strcmp($2, "BIG5") &&
135 strcmp($2, "MSKanji") &&
136 strcmp($2, "UTF2"))
137 warnx("ENCODING %s is not supported by libc", $2);
138 strncpy(new_locale.encoding, $2,
139 sizeof(new_locale.encoding)); }
140 | VARIABLE
141 { new_locale.variable_len = strlen($1) + 1;
142 variable = xmalloc(new_locale.variable_len);
143 strcpy(variable, $1);
144 }
145 | INVALID RUNE
146 { warnx("the INVALID keyword is deprecated"); }
147 | LIST list
148 { set_map(&types, $2, $1); }
149 | MAPLOWER map
150 { set_map(&maplower, $2, 0); }
151 | MAPUPPER map
152 { set_map(&mapupper, $2, 0); }
153 | DIGITMAP map
154 {
155 if (($2->map >= 0) && ($2->map <= 255)) { /* Data corruption otherwise */
156 set_digitmap(&types, $2);
157 }
158 }
159 | CHARCLASS STRING list
160 {
161 int i;
162 if (strlen($2) > CHARCLASS_NAME_MAX)
163 errx(1, "Exceeded maximum charclass name size (%d) \"%s\"", CHARCLASS_NAME_MAX, $2);
164 for(i = 0; i < charclass_index; i++)
165 if (strncmp(charclasses[i].name, $2, CHARCLASS_NAME_MAX) == 0)
166 break;
167 if (i >= charclass_index) {
168 if (charclass_index >= MAX_CHARCLASS)
169 errx(1, "Exceeded maximum number of charclasses (%d)", MAX_CHARCLASS);
170 strncpy(charclasses[charclass_index].name, $2, CHARCLASS_NAME_MAX);
171 charclasses[charclass_index].mask = (1 << (charclass_index + CHARCLASSBIT));
172 charclass_index++;
173 }
174 set_map(&types, $3, charclasses[i].mask);
175 }
176 ;
177
178 list : RUNE
179 {
180 $$ = (rune_list *)xmalloc(sizeof(rune_list));
181 $$->min = $1;
182 $$->max = $1;
183 $$->next = 0;
184 }
185 | RUNE THRU RUNE
186 {
187 $$ = (rune_list *)xmalloc(sizeof(rune_list));
188 $$->min = $1;
189 $$->max = $3;
190 $$->next = 0;
191 }
192 | list RUNE
193 {
194 $$ = (rune_list *)xmalloc(sizeof(rune_list));
195 $$->min = $2;
196 $$->max = $2;
197 $$->next = $1;
198 }
199 | list RUNE THRU RUNE
200 {
201 $$ = (rune_list *)xmalloc(sizeof(rune_list));
202 $$->min = $2;
203 $$->max = $4;
204 $$->next = $1;
205 }
206 ;
207
208 map : LBRK RUNE RUNE RBRK
209 {
210 $$ = (rune_list *)xmalloc(sizeof(rune_list));
211 $$->min = $2;
212 $$->max = $2;
213 $$->map = $3;
214 $$->next = 0;
215 }
216 | map LBRK RUNE RUNE RBRK
217 {
218 $$ = (rune_list *)xmalloc(sizeof(rune_list));
219 $$->min = $3;
220 $$->max = $3;
221 $$->map = $4;
222 $$->next = $1;
223 }
224 | LBRK RUNE THRU RUNE ':' RUNE RBRK
225 {
226 $$ = (rune_list *)xmalloc(sizeof(rune_list));
227 $$->min = $2;
228 $$->max = $4;
229 $$->map = $6;
230 $$->next = 0;
231 }
232 | map LBRK RUNE THRU RUNE ':' RUNE RBRK
233 {
234 $$ = (rune_list *)xmalloc(sizeof(rune_list));
235 $$->min = $3;
236 $$->max = $5;
237 $$->map = $7;
238 $$->next = $1;
239 }
240 ;
241 %%
242
243 int debug;
244 FILE *fp;
245
246 static void
247 cleanout(void)
248 {
249 if (fp != NULL)
250 unlink(locale_file);
251 }
252
253 int
254 main(int ac, char *av[])
255 {
256 int x;
257
258 fp = stdout;
259
260 while ((x = getopt(ac, av, "do:")) != -1) {
261 switch(x) {
262 case 'd':
263 debug = 1;
264 break;
265 case 'o':
266 locale_file = optarg;
267 if ((fp = fopen(locale_file, "w")) == NULL)
268 err(1, "%s: fopen", locale_file);
269 atexit(cleanout);
270 break;
271 default:
272 usage();
273 }
274 }
275
276 switch (ac - optind) {
277 case 0:
278 break;
279 case 1:
280 if (freopen(av[optind], "r", stdin) == 0)
281 err(1, "%s: freopen", av[optind]);
282 break;
283 default:
284 usage();
285 }
286 for (x = 0; x < _CACHED_RUNES; ++x) {
287 mapupper.map[x] = x;
288 maplower.map[x] = x;
289 }
290 memcpy(new_locale.magic, _RUNE_MAGIC_A, sizeof(new_locale.magic));
291
292 yyparse();
293
294 return(0);
295 }
296
297 static void
298 usage()
299 {
300 fprintf(stderr, "usage: mklocale [-d] [-o output] [source]\n");
301 exit(1);
302 }
303
304 void
305 yyerror(s)
306 const char *s;
307 {
308 fprintf(stderr, "%s\n", s);
309 }
310
311 static void *
312 xmalloc(sz)
313 unsigned int sz;
314 {
315 void *r = malloc(sz);
316 if (!r)
317 errx(1, "xmalloc");
318 return(r);
319 }
320
321 static uint32_t *
322 xlalloc(sz)
323 unsigned int sz;
324 {
325 uint32_t *r = (uint32_t *)malloc(sz * sizeof(uint32_t));
326 if (!r)
327 errx(1, "xlalloc");
328 return(r);
329 }
330
331 static uint32_t *
332 xrelalloc(old, sz)
333 uint32_t *old;
334 unsigned int sz;
335 {
336 uint32_t *r = (uint32_t *)realloc((char *)old,
337 sz * sizeof(uint32_t));
338 if (!r)
339 errx(1, "xrelalloc");
340 return(r);
341 }
342
343 void
344 set_map(map, list, flag)
345 rune_map *map;
346 rune_list *list;
347 uint32_t flag;
348 {
349 while (list) {
350 rune_list *nlist = list->next;
351 add_map(map, list, flag);
352 list = nlist;
353 }
354 }
355
356 void
357 set_digitmap(map, list)
358 rune_map *map;
359 rune_list *list;
360 {
361 int32_t i;
362
363 while (list) {
364 rune_list *nlist = list->next;
365 for (i = list->min; i <= list->max; ++i) {
366 if (list->map + (i - list->min)) {
367 rune_list *tmp = (rune_list *)xmalloc(sizeof(rune_list));
368 tmp->min = i;
369 tmp->max = i;
370 add_map(map, tmp, list->map + (i - list->min));
371 }
372 }
373 free(list);
374 list = nlist;
375 }
376 }
377
378 void
379 add_map(map, list, flag)
380 rune_map *map;
381 rune_list *list;
382 uint32_t flag;
383 {
384 int32_t i;
385 rune_list *lr = 0;
386 rune_list *r;
387 int32_t run;
388
389 while (list->min < _CACHED_RUNES && list->min <= list->max) {
390 if (flag)
391 map->map[list->min++] |= flag;
392 else
393 map->map[list->min++] = list->map++;
394 }
395
396 if (list->min > list->max) {
397 free(list);
398 return;
399 }
400
401 run = list->max - list->min + 1;
402
403 if (!(r = map->root) || (list->max < r->min - 1)
404 || (!flag && list->max == r->min - 1)) {
405 if (flag) {
406 list->types = xlalloc(run);
407 for (i = 0; i < run; ++i)
408 list->types[i] = flag;
409 }
410 list->next = map->root;
411 map->root = list;
412 return;
413 }
414
415 for (r = map->root; r && r->max + 1 < list->min; r = r->next)
416 lr = r;
417
418 if (!r) {
419 /*
420 * We are off the end.
421 */
422 if (flag) {
423 list->types = xlalloc(run);
424 for (i = 0; i < run; ++i)
425 list->types[i] = flag;
426 }
427 list->next = 0;
428 lr->next = list;
429 return;
430 }
431
432 if (list->max < r->min - 1) {
433 /*
434 * We come before this range and we do not intersect it.
435 * We are not before the root node, it was checked before the loop
436 */
437 if (flag) {
438 list->types = xlalloc(run);
439 for (i = 0; i < run; ++i)
440 list->types[i] = flag;
441 }
442 list->next = lr->next;
443 lr->next = list;
444 return;
445 }
446
447 /*
448 * At this point we have found that we at least intersect with
449 * the range pointed to by `r', we might intersect with one or
450 * more ranges beyond `r' as well.
451 */
452
453 if (!flag && list->map - list->min != r->map - r->min) {
454 /*
455 * There are only two cases when we are doing case maps and
456 * our maps needn't have the same offset. When we are adjoining
457 * but not intersecting.
458 */
459 if (list->max + 1 == r->min) {
460 lr->next = list;
461 list->next = r;
462 return;
463 }
464 if (list->min - 1 == r->max) {
465 list->next = r->next;
466 r->next = list;
467 return;
468 }
469 errx(1, "error: conflicting map entries");
470 }
471
472 if (list->min >= r->min && list->max <= r->max) {
473 /*
474 * Subset case.
475 */
476
477 if (flag) {
478 for (i = list->min; i <= list->max; ++i)
479 r->types[i - r->min] |= flag;
480 }
481 free(list);
482 return;
483 }
484 if (list->min <= r->min && list->max >= r->max) {
485 /*
486 * Superset case. Make him big enough to hold us.
487 * We might need to merge with the guy after him.
488 */
489 if (flag) {
490 list->types = xlalloc(list->max - list->min + 1);
491
492 for (i = list->min; i <= list->max; ++i)
493 list->types[i - list->min] = flag;
494
495 for (i = r->min; i <= r->max; ++i)
496 list->types[i - list->min] |= r->types[i - r->min];
497
498 free(r->types);
499 r->types = list->types;
500 } else {
501 r->map = list->map;
502 }
503 r->min = list->min;
504 r->max = list->max;
505 free(list);
506 } else if (list->min < r->min) {
507 /*
508 * Our tail intersects his head.
509 */
510 if (flag) {
511 list->types = xlalloc(r->max - list->min + 1);
512
513 for (i = r->min; i <= r->max; ++i)
514 list->types[i - list->min] = r->types[i - r->min];
515
516 for (i = list->min; i < r->min; ++i)
517 list->types[i - list->min] = flag;
518
519 for (i = r->min; i <= list->max; ++i)
520 list->types[i - list->min] |= flag;
521
522 free(r->types);
523 r->types = list->types;
524 } else {
525 r->map = list->map;
526 }
527 r->min = list->min;
528 free(list);
529 return;
530 } else {
531 /*
532 * Our head intersects his tail.
533 * We might need to merge with the guy after him.
534 */
535 if (flag) {
536 r->types = xrelalloc(r->types, list->max - r->min + 1);
537
538 for (i = list->min; i <= r->max; ++i)
539 r->types[i - r->min] |= flag;
540
541 for (i = r->max+1; i <= list->max; ++i)
542 r->types[i - r->min] = flag;
543 }
544 r->max = list->max;
545 free(list);
546 }
547
548 /*
549 * Okay, check to see if we grew into the next guy(s)
550 */
551 while ((lr = r->next) && r->max >= lr->min) {
552 if (flag) {
553 if (r->max >= lr->max) {
554 /*
555 * Good, we consumed all of him.
556 */
557 for (i = lr->min; i <= lr->max; ++i)
558 r->types[i - r->min] |= lr->types[i - lr->min];
559 } else {
560 /*
561 * "append" him on to the end of us.
562 */
563 r->types = xrelalloc(r->types, lr->max - r->min + 1);
564
565 for (i = lr->min; i <= r->max; ++i)
566 r->types[i - r->min] |= lr->types[i - lr->min];
567
568 for (i = r->max+1; i <= lr->max; ++i)
569 r->types[i - r->min] = lr->types[i - lr->min];
570
571 r->max = lr->max;
572 }
573 } else {
574 if (lr->max > r->max)
575 r->max = lr->max;
576 }
577
578 r->next = lr->next;
579
580 if (flag)
581 free(lr->types);
582 free(lr);
583 }
584 }
585
586 static void
587 dump_tables()
588 {
589 int x, first_d, curr_d;
590 rune_list *list;
591
592 /*
593 * See if we can compress some of the istype arrays
594 */
595 for(list = types.root; list; list = list->next) {
596 list->map = list->types[0];
597 for (x = 1; x < list->max - list->min + 1; ++x) {
598 if ((int32_t)list->types[x] != list->map) {
599 list->map = 0;
600 break;
601 }
602 }
603 }
604
605 first_d = curr_d = -1;
606 for (x = 0; x < _CACHED_RUNES; ++x) {
607 uint32_t r = types.map[x];
608
609 if (r & _CTYPE_D) {
610 if (first_d < 0)
611 first_d = curr_d = x;
612 else if (x != curr_d + 1)
613 errx(1, "error: DIGIT range is not contiguous");
614 else if (x - first_d > 9)
615 errx(1, "error: DIGIT range is too big");
616 else
617 curr_d++;
618 if (!(r & _CTYPE_X))
619 errx(1,
620 "error: DIGIT range is not a subset of XDIGIT range");
621 }
622 }
623 if (first_d < 0)
624 errx(1, "error: no DIGIT range defined in the single byte area");
625 else if (curr_d - first_d < 9)
626 errx(1, "error: DIGIT range is too small in the single byte area");
627
628 new_locale.ncharclasses = htonl(charclass_index);
629
630 /*
631 * Fill in our tables. Do this in network order so that
632 * diverse machines have a chance of sharing data.
633 * (Machines like Crays cannot share with little machines due to
634 * word size. Sigh. We tried.)
635 */
636 for (x = 0; x < _CACHED_RUNES; ++x) {
637 new_locale.runetype[x] = htonl(types.map[x]);
638 new_locale.maplower[x] = htonl(maplower.map[x]);
639 new_locale.mapupper[x] = htonl(mapupper.map[x]);
640 }
641
642 /*
643 * Count up how many ranges we will need for each of the extents.
644 */
645 list = types.root;
646
647 while (list) {
648 new_locale.runetype_ext_nranges++;
649 list = list->next;
650 }
651 new_locale.runetype_ext_nranges =
652 htonl(new_locale.runetype_ext_nranges);
653
654 list = maplower.root;
655
656 while (list) {
657 new_locale.maplower_ext_nranges++;
658 list = list->next;
659 }
660 new_locale.maplower_ext_nranges =
661 htonl(new_locale.maplower_ext_nranges);
662
663 list = mapupper.root;
664
665 while (list) {
666 new_locale.mapupper_ext_nranges++;
667 list = list->next;
668 }
669 new_locale.mapupper_ext_nranges =
670 htonl(new_locale.mapupper_ext_nranges);
671
672 new_locale.variable_len = htonl(new_locale.variable_len);
673
674 /*
675 * Okay, we are now ready to write the new locale file.
676 */
677
678 /*
679 * PART 1: The _FileRuneLocale structure
680 */
681 if (fwrite((char *)&new_locale, sizeof(new_locale), 1, fp) != 1) {
682 err(1, "%s: _FileRuneLocale structure", locale_file);
683 }
684 /*
685 * PART 2: The runetype_ext structures (not the actual tables)
686 */
687 list = types.root;
688
689 while (list) {
690 _FileRuneEntry re;
691
692 re.min = htonl(list->min);
693 re.max = htonl(list->max);
694 re.map = htonl(list->map);
695 #ifdef __APPLE__
696 re.__types_fake = 0;
697 #endif
698
699 if (fwrite((char *)&re, sizeof(re), 1, fp) != 1) {
700 err(1, "%s: runetype_ext structures", locale_file);
701 }
702
703 list = list->next;
704 }
705 /*
706 * PART 3: The maplower_ext structures
707 */
708 list = maplower.root;
709
710 while (list) {
711 _FileRuneEntry re;
712
713 re.min = htonl(list->min);
714 re.max = htonl(list->max);
715 re.map = htonl(list->map);
716 #ifdef __APPLE__
717 re.__types_fake = 0;
718 #endif
719
720 if (fwrite((char *)&re, sizeof(re), 1, fp) != 1) {
721 err(1, "%s: maplower_ext structures", locale_file);
722 }
723
724 list = list->next;
725 }
726 /*
727 * PART 4: The mapupper_ext structures
728 */
729 list = mapupper.root;
730
731 while (list) {
732 _FileRuneEntry re;
733
734 re.min = htonl(list->min);
735 re.max = htonl(list->max);
736 re.map = htonl(list->map);
737 #ifdef __APPLE__
738 re.__types_fake = 0;
739 #endif
740
741 if (fwrite((char *)&re, sizeof(re), 1, fp) != 1) {
742 err(1, "%s: mapupper_ext structures", locale_file);
743 }
744
745 list = list->next;
746 }
747 /*
748 * PART 5: The runetype_ext tables
749 */
750 list = types.root;
751
752 while (list) {
753 for (x = 0; x < list->max - list->min + 1; ++x)
754 list->types[x] = htonl(list->types[x]);
755
756 if (!list->map) {
757 if (fwrite((char *)list->types,
758 (list->max - list->min + 1) * sizeof(uint32_t),
759 1, fp) != 1) {
760 err(1, "%s: runetype_ext tables", locale_file);
761 }
762 }
763 list = list->next;
764 }
765 /*
766 * PART 6: The charclass names table
767 */
768 for (x = 0; x < charclass_index; ++x) {
769 charclasses[x].mask = ntohl(charclasses[x].mask);
770 if (fwrite((char *)&charclasses[x], sizeof(rune_charclass), 1, fp) != 1) {
771 err(1, "%s: charclass names tables", locale_file);
772 }
773 }
774 /*
775 * PART 7: And finally the variable data
776 * SUSv3 says fwrite returns zero when either size or nitems is zero.
777 */
778 if (ntohl(new_locale.variable_len) > 0 && fwrite(variable,
779 ntohl(new_locale.variable_len), 1, fp) != 1) {
780 err(1, "%s: variable data", locale_file);
781 }
782 if (fclose(fp) != 0) {
783 err(1, "%s: fclose", locale_file);
784 }
785 fp = NULL;
786
787 if (!debug)
788 return;
789
790 if (new_locale.encoding[0])
791 fprintf(stderr, "ENCODING %s\n", new_locale.encoding);
792 if (variable)
793 fprintf(stderr, "VARIABLE %s\n", variable);
794
795 fprintf(stderr, "\nMAPLOWER:\n\n");
796
797 for (x = 0; x < _CACHED_RUNES; ++x) {
798 if (isprint(maplower.map[x]))
799 fprintf(stderr, " '%c'", (int)maplower.map[x]);
800 else if (maplower.map[x])
801 fprintf(stderr, "%04x", maplower.map[x]);
802 else
803 fprintf(stderr, "%4x", 0);
804 if ((x & 0xf) == 0xf)
805 fprintf(stderr, "\n");
806 else
807 fprintf(stderr, " ");
808 }
809 fprintf(stderr, "\n");
810
811 for (list = maplower.root; list; list = list->next)
812 fprintf(stderr, "\t%04x - %04x : %04x\n", list->min, list->max, list->map);
813
814 fprintf(stderr, "\nMAPUPPER:\n\n");
815
816 for (x = 0; x < _CACHED_RUNES; ++x) {
817 if (isprint(mapupper.map[x]))
818 fprintf(stderr, " '%c'", (int)mapupper.map[x]);
819 else if (mapupper.map[x])
820 fprintf(stderr, "%04x", mapupper.map[x]);
821 else
822 fprintf(stderr, "%4x", 0);
823 if ((x & 0xf) == 0xf)
824 fprintf(stderr, "\n");
825 else
826 fprintf(stderr, " ");
827 }
828 fprintf(stderr, "\n");
829
830 for (list = mapupper.root; list; list = list->next)
831 fprintf(stderr, "\t%04x - %04x : %04x\n", list->min, list->max, list->map);
832
833
834 fprintf(stderr, "\nTYPES:\n\n");
835
836 for (x = 0; x < _CACHED_RUNES; ++x) {
837 uint32_t r = types.map[x];
838
839 if (r) {
840 if (isprint(x))
841 fprintf(stderr, " '%c': %2d", x, (int)(r & 0xff));
842 else
843 fprintf(stderr, "%04x: %2d", x, (int)(r & 0xff));
844
845 fprintf(stderr, " %4s", (r & _CTYPE_A) ? "alph" : "");
846 fprintf(stderr, " %4s", (r & _CTYPE_C) ? "ctrl" : "");
847 fprintf(stderr, " %4s", (r & _CTYPE_D) ? "dig" : "");
848 fprintf(stderr, " %4s", (r & _CTYPE_G) ? "graf" : "");
849 fprintf(stderr, " %4s", (r & _CTYPE_L) ? "low" : "");
850 fprintf(stderr, " %4s", (r & _CTYPE_P) ? "punc" : "");
851 fprintf(stderr, " %4s", (r & _CTYPE_S) ? "spac" : "");
852 fprintf(stderr, " %4s", (r & _CTYPE_U) ? "upp" : "");
853 fprintf(stderr, " %4s", (r & _CTYPE_X) ? "xdig" : "");
854 fprintf(stderr, " %4s", (r & _CTYPE_B) ? "blnk" : "");
855 fprintf(stderr, " %4s", (r & _CTYPE_R) ? "prnt" : "");
856 fprintf(stderr, " %4s", (r & _CTYPE_I) ? "ideo" : "");
857 fprintf(stderr, " %4s", (r & _CTYPE_T) ? "spec" : "");
858 fprintf(stderr, " %4s", (r & _CTYPE_Q) ? "phon" : "");
859 fprintf(stderr, "\n");
860 }
861 }
862
863 for (list = types.root; list; list = list->next) {
864 if (list->map && list->min + 3 < list->max) {
865 uint32_t r = list->map;
866
867 fprintf(stderr, "%04x: %2d",
868 (uint32_t)list->min, (int)(r & 0xff));
869
870 fprintf(stderr, " %4s", (r & _CTYPE_A) ? "alph" : "");
871 fprintf(stderr, " %4s", (r & _CTYPE_C) ? "ctrl" : "");
872 fprintf(stderr, " %4s", (r & _CTYPE_D) ? "dig" : "");
873 fprintf(stderr, " %4s", (r & _CTYPE_G) ? "graf" : "");
874 fprintf(stderr, " %4s", (r & _CTYPE_L) ? "low" : "");
875 fprintf(stderr, " %4s", (r & _CTYPE_P) ? "punc" : "");
876 fprintf(stderr, " %4s", (r & _CTYPE_S) ? "spac" : "");
877 fprintf(stderr, " %4s", (r & _CTYPE_U) ? "upp" : "");
878 fprintf(stderr, " %4s", (r & _CTYPE_X) ? "xdig" : "");
879 fprintf(stderr, " %4s", (r & _CTYPE_B) ? "blnk" : "");
880 fprintf(stderr, " %4s", (r & _CTYPE_R) ? "prnt" : "");
881 fprintf(stderr, " %4s", (r & _CTYPE_I) ? "ideo" : "");
882 fprintf(stderr, " %4s", (r & _CTYPE_T) ? "spec" : "");
883 fprintf(stderr, " %4s", (r & _CTYPE_Q) ? "phon" : "");
884 fprintf(stderr, "\n...\n");
885
886 fprintf(stderr, "%04x: %2d",
887 (uint32_t)list->max, (int)(r & 0xff));
888
889 fprintf(stderr, " %4s", (r & _CTYPE_A) ? "alph" : "");
890 fprintf(stderr, " %4s", (r & _CTYPE_C) ? "ctrl" : "");
891 fprintf(stderr, " %4s", (r & _CTYPE_D) ? "dig" : "");
892 fprintf(stderr, " %4s", (r & _CTYPE_G) ? "graf" : "");
893 fprintf(stderr, " %4s", (r & _CTYPE_L) ? "low" : "");
894 fprintf(stderr, " %4s", (r & _CTYPE_P) ? "punc" : "");
895 fprintf(stderr, " %4s", (r & _CTYPE_S) ? "spac" : "");
896 fprintf(stderr, " %4s", (r & _CTYPE_U) ? "upp" : "");
897 fprintf(stderr, " %4s", (r & _CTYPE_X) ? "xdig" : "");
898 fprintf(stderr, " %4s", (r & _CTYPE_B) ? "blnk" : "");
899 fprintf(stderr, " %4s", (r & _CTYPE_R) ? "prnt" : "");
900 fprintf(stderr, " %4s", (r & _CTYPE_I) ? "ideo" : "");
901 fprintf(stderr, " %4s", (r & _CTYPE_T) ? "spec" : "");
902 fprintf(stderr, " %4s", (r & _CTYPE_Q) ? "phon" : "");
903 fprintf(stderr, "\n");
904 } else
905 for (x = list->min; x <= list->max; ++x) {
906 uint32_t r = ntohl(list->types[x - list->min]);
907
908 if (r) {
909 fprintf(stderr, "%04x: %2d", x, (int)(r & 0xff));
910
911 fprintf(stderr, " %4s", (r & _CTYPE_A) ? "alph" : "");
912 fprintf(stderr, " %4s", (r & _CTYPE_C) ? "ctrl" : "");
913 fprintf(stderr, " %4s", (r & _CTYPE_D) ? "dig" : "");
914 fprintf(stderr, " %4s", (r & _CTYPE_G) ? "graf" : "");
915 fprintf(stderr, " %4s", (r & _CTYPE_L) ? "low" : "");
916 fprintf(stderr, " %4s", (r & _CTYPE_P) ? "punc" : "");
917 fprintf(stderr, " %4s", (r & _CTYPE_S) ? "spac" : "");
918 fprintf(stderr, " %4s", (r & _CTYPE_U) ? "upp" : "");
919 fprintf(stderr, " %4s", (r & _CTYPE_X) ? "xdig" : "");
920 fprintf(stderr, " %4s", (r & _CTYPE_B) ? "blnk" : "");
921 fprintf(stderr, " %4s", (r & _CTYPE_R) ? "prnt" : "");
922 fprintf(stderr, " %4s", (r & _CTYPE_I) ? "ideo" : "");
923 fprintf(stderr, " %4s", (r & _CTYPE_T) ? "spec" : "");
924 fprintf(stderr, " %4s", (r & _CTYPE_Q) ? "phon" : "");
925 fprintf(stderr, "\n");
926 }
927 }
928 }
929 }