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