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