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