GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.bin/mklocale/yacc.c Lines: 0 176 0.0 %
Date: 2017-11-07 Branches: 0 129 0.0 %

Line Branch Exec Source
1
#include <stdlib.h>
2
#include <string.h>
3
#define YYBYACC 1
4
#define YYMAJOR 1
5
#define YYMINOR 9
6
#define YYLEX yylex()
7
#define YYEMPTY -1
8
#define yyclearin (yychar=(YYEMPTY))
9
#define yyerrok (yyerrflag=0)
10
#define YYRECOVERING() (yyerrflag!=0)
11
#define YYPREFIX "yy"
12
#line 5 "yacc.y"
13
/*-
14
 * Copyright (c) 1993
15
 *	The Regents of the University of California.  All rights reserved.
16
 *
17
 * This code is derived from software contributed to Berkeley by
18
 * Paul Borman at Krystal Technologies.
19
 *
20
 * Redistribution and use in source and binary forms, with or without
21
 * modification, are permitted provided that the following conditions
22
 * are met:
23
 * 1. Redistributions of source code must retain the above copyright
24
 *    notice, this list of conditions and the following disclaimer.
25
 * 2. Redistributions in binary form must reproduce the above copyright
26
 *    notice, this list of conditions and the following disclaimer in the
27
 *    documentation and/or other materials provided with the distribution.
28
 * 3. Neither the name of the University nor the names of its contributors
29
 *    may be used to endorse or promote products derived from this software
30
 *    without specific prior written permission.
31
 *
32
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42
 * SUCH DAMAGE.
43
 */
44
45
#include <sys/types.h>
46
#include <netinet/in.h>	/* Needed by <arpa/inet.h> on NetBSD 1.5. */
47
#include <arpa/inet.h>	/* Needed for htonl on POSIX systems. */
48
49
#include <err.h>
50
#include "locale/runetype.h"
51
#include <stddef.h>
52
#include <stdio.h>
53
#include <stdlib.h>
54
#include <string.h>
55
#include <unistd.h>
56
#include <ctype.h>
57
58
#include "ldef.h"
59
60
const char	*locale_file = "<stdout>";
61
62
rune_map	maplower = { { 0, }, };
63
rune_map	mapupper = { { 0, }, };
64
rune_map	types = { { 0, }, };
65
66
_RuneLocale	new_locale = { { 0, }, };
67
68
rune_t	charsetbits = (rune_t)0x00000000;
69
#if 0
70
rune_t	charsetmask = (rune_t)0x0000007f;
71
#endif
72
rune_t	charsetmask = (rune_t)0xffffffff;
73
74
void set_map(rune_map *, rune_list *, u_int32_t);
75
void add_map(rune_map *, rune_list *, u_int32_t);
76
77
int		main(int, char *[]);
78
int		yyerror(const char *s);
79
void		*xmalloc(size_t sz);
80
u_int32_t	*xlalloc(size_t sz);
81
u_int32_t	*xrelalloc(u_int32_t *old, size_t sz);
82
void		dump_tables(void);
83
int		yyparse(void);
84
extern int	yylex(void);
85
#line 79 "yacc.y"
86
#ifndef YYSTYPE_DEFINED
87
#define YYSTYPE_DEFINED
88
typedef union	{
89
    rune_t	rune;
90
    int		i;
91
    char	*str;
92
93
    rune_list	*list;
94
} YYSTYPE;
95
#endif /* YYSTYPE_DEFINED */
96
#line 97 "yacc.c"
97
#define RUNE 257
98
#define LBRK 258
99
#define RBRK 259
100
#define THRU 260
101
#define MAPLOWER 261
102
#define MAPUPPER 262
103
#define DIGITMAP 263
104
#define LIST 264
105
#define VARIABLE 265
106
#define CHARSET 266
107
#define ENCODING 267
108
#define INVALID 268
109
#define STRING 269
110
#define YYERRCODE 256
111
const short yylhs[] =
112
	{                                        -1,
113
    0,    0,    3,    3,    4,    4,    4,    4,    4,    4,
114
    4,    4,    4,    4,    1,    1,    1,    1,    2,    2,
115
    2,    2,    5,    5,    5,    5,
116
};
117
const short yylen[] =
118
	{                                         2,
119
    0,    1,    1,    2,    2,    1,    2,    3,    2,    2,
120
    2,    2,    2,    2,    1,    3,    2,    4,    4,    5,
121
    7,    8,    4,    5,    7,    8,
122
};
123
const short yydefred[] =
124
	{                                      0,
125
    0,    0,    0,    0,    6,    0,    0,    0,    0,    0,
126
    3,    0,    0,    0,    0,    0,   14,    0,    0,    0,
127
    9,    5,   10,    4,    0,    0,    0,    0,    0,    0,
128
    8,    0,    0,    0,    0,    0,    0,   16,    0,   19,
129
    0,    0,    0,    0,    0,    0,    0,   18,    0,   20,
130
    0,    0,    0,    0,    0,    0,    0,    0,   21,    0,
131
    0,    0,   22,    0,
132
};
133
const short yydgoto[] =
134
	{                                       9,
135
   19,   13,   10,   11,   17,
136
};
137
const short yysindex[] =
138
	{                                   -259,
139
 -248, -248, -235, -232,    0, -257, -243, -230,    0, -259,
140
    0, -229, -228, -228, -226, -225,    0, -231, -223, -221,
141
    0,    0,    0,    0, -246, -220, -242, -219, -218, -217,
142
    0, -227, -216, -241, -215, -212, -240,    0, -210,    0,
143
  -18, -211, -208,    0,  -16, -209, -206,    0, -205,    0,
144
   -5, -203,    0,   -3, -201, -198, -199, -196,    0, -197,
145
    0, -195,    0,    0,};
146
const short yyrindex[] =
147
	{                                     56,
148
    0,    0,    0,    0,    0,    0,    0,    0,    0,   63,
149
    0,    0,   65,   73,    0,    0,    0,    1,   81,   89,
150
    0,    0,    0,    0,    0,    0,    0,    0,    0,   13,
151
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
152
    0,    0,    0,   24,    0,    0,    0,    0,    0,    0,
153
    0,    0,   35,    0,    0,    0,    0,    0,    0,    0,
154
   46,    0,    0,   57,};
155
const short yygindex[] =
156
	{                                      0,
157
    0,   19,    0,   58,    0,
158
};
159
#define YYTABLESIZE 357
160
const short yytable[] =
161
	{                                      20,
162
   15,    1,    2,    3,    4,    5,    6,    7,    8,   12,
163
   32,   21,   17,   33,   35,   42,   46,   36,   43,   47,
164
   14,   16,   15,   23,   18,   22,   23,   25,   29,   26,
165
   27,   40,   28,   30,   24,   31,   34,   37,   38,   49,
166
   41,   52,   39,   44,   45,   25,   48,   50,   51,   53,
167
   54,   55,   56,   57,   58,    1,   26,   59,   60,   61,
168
   62,   63,    2,   64,   12,    0,    0,   24,    0,    0,
169
    0,    0,   13,    0,    0,    0,    0,    0,    0,    0,
170
   11,    0,    0,    0,    0,    0,    0,    0,    7,    0,
171
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
172
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
173
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
174
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
175
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
176
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
177
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
178
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
179
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
180
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
181
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
182
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
183
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
184
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
185
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
186
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
187
    0,    0,    0,    0,    0,    0,    0,   15,    0,    0,
188
    0,   15,   15,   15,   15,   15,   15,   15,   15,   17,
189
    0,    0,    0,   17,   17,   17,   17,   17,   17,   17,
190
   17,   19,    0,    0,   23,   23,   23,   23,   23,   23,
191
   23,   23,   20,    0,    0,   24,   24,   24,   24,   24,
192
   24,   24,   24,   21,    0,    0,   25,   25,   25,   25,
193
   25,   25,   25,   25,   22,    0,    0,   26,   26,   26,
194
   26,   26,   26,   26,   26,   12,   12,   12,   12,   12,
195
   12,   12,   12,   13,   13,   13,   13,   13,   13,   13,
196
   13,   11,   11,   11,   11,   11,   11,   11,   11,    7,
197
    7,    7,    7,    7,    7,    7,    7,
198
};
199
const short yycheck[] =
200
	{                                     257,
201
    0,  261,  262,  263,  264,  265,  266,  267,  268,  258,
202
  257,  269,    0,  260,  257,  257,  257,  260,  260,  260,
203
    2,    3,  258,    0,  257,  269,  257,  257,  260,  258,
204
  257,  259,  258,  257,    0,  257,  257,  257,  257,   58,
205
  257,   58,  260,  259,  257,    0,  257,  259,  257,  259,
206
  257,  257,   58,  257,   58,    0,    0,  259,  257,  259,
207
  257,  259,    0,  259,    0,   -1,   -1,   10,   -1,   -1,
208
   -1,   -1,    0,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
209
    0,   -1,   -1,   -1,   -1,   -1,   -1,   -1,    0,   -1,
210
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
211
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
212
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
213
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
214
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
215
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
216
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
217
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
218
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
219
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
220
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
221
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
222
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
223
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
224
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
225
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
226
   -1,   -1,   -1,   -1,   -1,   -1,   -1,  257,   -1,   -1,
227
   -1,  261,  262,  263,  264,  265,  266,  267,  268,  257,
228
   -1,   -1,   -1,  261,  262,  263,  264,  265,  266,  267,
229
  268,  258,   -1,   -1,  261,  262,  263,  264,  265,  266,
230
  267,  268,  258,   -1,   -1,  261,  262,  263,  264,  265,
231
  266,  267,  268,  258,   -1,   -1,  261,  262,  263,  264,
232
  265,  266,  267,  268,  258,   -1,   -1,  261,  262,  263,
233
  264,  265,  266,  267,  268,  261,  262,  263,  264,  265,
234
  266,  267,  268,  261,  262,  263,  264,  265,  266,  267,
235
  268,  261,  262,  263,  264,  265,  266,  267,  268,  261,
236
  262,  263,  264,  265,  266,  267,  268,
237
};
238
#define YYFINAL 9
239
#ifndef YYDEBUG
240
#define YYDEBUG 0
241
#endif
242
#define YYMAXTOKEN 269
243
#if YYDEBUG
244
const char * const yyname[] =
245
	{
246
"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
247
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"':'",0,0,0,0,0,0,0,0,0,0,0,0,0,
248
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
249
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
250
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
251
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
252
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"RUNE","LBRK","RBRK","THRU",
253
"MAPLOWER","MAPUPPER","DIGITMAP","LIST","VARIABLE","CHARSET","ENCODING",
254
"INVALID","STRING",
255
};
256
const char * const yyrule[] =
257
	{"$accept : locale",
258
"locale :",
259
"locale : table",
260
"table : entry",
261
"table : table entry",
262
"entry : ENCODING STRING",
263
"entry : VARIABLE",
264
"entry : CHARSET RUNE",
265
"entry : CHARSET RUNE RUNE",
266
"entry : CHARSET STRING",
267
"entry : INVALID RUNE",
268
"entry : LIST list",
269
"entry : MAPLOWER map",
270
"entry : MAPUPPER map",
271
"entry : DIGITMAP mapignore",
272
"list : RUNE",
273
"list : RUNE THRU RUNE",
274
"list : list RUNE",
275
"list : list RUNE THRU RUNE",
276
"map : LBRK RUNE RUNE RBRK",
277
"map : map LBRK RUNE RUNE RBRK",
278
"map : LBRK RUNE THRU RUNE ':' RUNE RBRK",
279
"map : map LBRK RUNE THRU RUNE ':' RUNE RBRK",
280
"mapignore : LBRK RUNE RUNE RBRK",
281
"mapignore : map LBRK RUNE RUNE RBRK",
282
"mapignore : LBRK RUNE THRU RUNE ':' RUNE RBRK",
283
"mapignore : map LBRK RUNE THRU RUNE ':' RUNE RBRK",
284
};
285
#endif
286
#ifdef YYSTACKSIZE
287
#undef YYMAXDEPTH
288
#define YYMAXDEPTH YYSTACKSIZE
289
#else
290
#ifdef YYMAXDEPTH
291
#define YYSTACKSIZE YYMAXDEPTH
292
#else
293
#define YYSTACKSIZE 10000
294
#define YYMAXDEPTH 10000
295
#endif
296
#endif
297
#define YYINITSTACKSIZE 200
298
/* LINTUSED */
299
int yydebug;
300
int yynerrs;
301
int yyerrflag;
302
int yychar;
303
short *yyssp;
304
YYSTYPE *yyvsp;
305
YYSTYPE yyval;
306
YYSTYPE yylval;
307
short *yyss;
308
short *yysslim;
309
YYSTYPE *yyvs;
310
unsigned int yystacksize;
311
int yyparse(void);
312
#line 244 "yacc.y"
313
314
int debug = 0;
315
FILE *ofile;
316
317
int
318
main(int ac, char *av[])
319
{
320
    int x;
321
322
    extern char *optarg;
323
    extern int optind;
324
325
    if (pledge("stdio rpath wpath cpath", NULL) == -1) {
326
	perror("pledge");
327
	exit(1);
328
    }
329
330
    while ((x = getopt(ac, av, "do:")) != -1) {
331
	switch(x) {
332
	case 'd':
333
	    debug = 1;
334
	    break;
335
	case 'o':
336
	    locale_file = optarg;
337
	    if ((ofile = fopen(locale_file, "w")) == 0)
338
		err(1, "unable to open output file %s", locale_file);
339
	    break;
340
	default:
341
	usage:
342
	    fprintf(stderr,
343
		"usage: mklocale [-d] [src-file] language/LC_CTYPE\n"
344
		"       mklocale [-d] -o language/LC_CTYPE src-file\n");
345
	    exit(1);
346
	}
347
    }
348
349
    switch (ac - optind) {
350
    case 0:
351
	break;
352
    case 1:
353
	if (freopen(av[optind], "r", stdin) == 0)
354
	    err(1, "unable to open input file %s", av[optind]);
355
	break;
356
    default:
357
	goto usage;
358
    }
359
    for (x = 0; x < _CACHED_RUNES; ++x) {
360
	mapupper.map[x] = x;
361
	maplower.map[x] = x;
362
    }
363
    new_locale.rl_invalid_rune = _DEFAULT_INVALID_RUNE;
364
    memcpy(new_locale.rl_magic, _RUNE_MAGIC_1, sizeof(new_locale.rl_magic));
365
366
    yyparse();
367
368
    return 0;
369
}
370
371
int
372
yyerror(const char *s)
373
{
374
    fprintf(stderr, "%s\n", s);
375
376
    return 0;
377
}
378
379
void *
380
xmalloc(size_t sz)
381
{
382
    void *r = malloc(sz);
383
    if (!r) {
384
	perror("xmalloc");
385
	abort();
386
    }
387
    return(r);
388
}
389
390
u_int32_t *
391
xlalloc(size_t sz)
392
{
393
    u_int32_t *r = reallocarray(NULL, sz, sizeof(u_int32_t));
394
    if (!r) {
395
	perror("xlalloc");
396
	abort();
397
    }
398
    return(r);
399
}
400
401
u_int32_t *
402
xrelalloc(u_int32_t *old, size_t sz)
403
{
404
    u_int32_t *r = reallocarray(old, sz, sizeof(u_int32_t));
405
    if (!r) {
406
	perror("xrelalloc");
407
	abort();
408
    }
409
    return(r);
410
}
411
412
void
413
set_map(rune_map *map, rune_list *list, u_int32_t flag)
414
{
415
    list->map &= charsetmask;
416
    list->map |= charsetbits;
417
    while (list) {
418
	rune_list *nlist = list->next;
419
	add_map(map, list, flag);
420
	list = nlist;
421
    }
422
}
423
424
void
425
add_map(rune_map *map, rune_list *list, u_int32_t flag)
426
{
427
    rune_t i;
428
    rune_list *lr = 0;
429
    rune_list *r;
430
    rune_t run;
431
432
    while (list->min < _CACHED_RUNES && list->min <= list->max) {
433
	if (flag)
434
	    map->map[list->min++] |= flag;
435
	else
436
	    map->map[list->min++] = list->map++;
437
    }
438
439
    if (list->min > list->max) {
440
	free(list);
441
	return;
442
    }
443
444
    run = list->max - list->min + 1;
445
446
    if (!(r = map->root) || (list->max < r->min - 1)
447
			 || (!flag && list->max == r->min - 1)) {
448
	if (flag) {
449
	    list->types = xlalloc(run);
450
	    for (i = 0; i < run; ++i)
451
		list->types[i] = flag;
452
	}
453
	list->next = map->root;
454
	map->root = list;
455
	return;
456
    }
457
458
    for (r = map->root; r && r->max + 1 < list->min; r = r->next)
459
	lr = r;
460
461
    if (!r) {
462
	/*
463
	 * We are off the end.
464
	 */
465
	if (flag) {
466
	    list->types = xlalloc(run);
467
	    for (i = 0; i < run; ++i)
468
		list->types[i] = flag;
469
	}
470
	list->next = 0;
471
	lr->next = list;
472
	return;
473
    }
474
475
    if (list->max < r->min - 1) {
476
	/*
477
	 * We come before this range and we do not intersect it.
478
	 * We are not before the root node, it was checked before the loop
479
	 */
480
	if (flag) {
481
	    list->types = xlalloc(run);
482
	    for (i = 0; i < run; ++i)
483
		list->types[i] = flag;
484
	}
485
	list->next = lr->next;
486
	lr->next = list;
487
	return;
488
    }
489
490
    /*
491
     * At this point we have found that we at least intersect with
492
     * the range pointed to by `r', we might intersect with one or
493
     * more ranges beyond `r' as well.
494
     */
495
496
    if (!flag && list->map - list->min != r->map - r->min) {
497
	/*
498
	 * There are only two cases when we are doing case maps and
499
	 * our maps needn't have the same offset.  When we are adjoining
500
	 * but not intersecting.
501
	 */
502
	if (list->max + 1 == r->min) {
503
	    lr->next = list;
504
	    list->next = r;
505
	    return;
506
	}
507
	if (list->min - 1 == r->max) {
508
	    list->next = r->next;
509
	    r->next = list;
510
	    return;
511
	}
512
	fprintf(stderr, "Error: conflicting map entries\n");
513
	exit(1);
514
    }
515
516
    if (list->min >= r->min && list->max <= r->max) {
517
	/*
518
	 * Subset case.
519
	 */
520
521
	if (flag) {
522
	    for (i = list->min; i <= list->max; ++i)
523
		r->types[i - r->min] |= flag;
524
	}
525
	free(list);
526
	return;
527
    }
528
    if (list->min <= r->min && list->max >= r->max) {
529
	/*
530
	 * Superset case.  Make him big enough to hold us.
531
	 * We might need to merge with the guy after him.
532
	 */
533
	if (flag) {
534
	    list->types = xlalloc(list->max - list->min + 1);
535
536
	    for (i = list->min; i <= list->max; ++i)
537
		list->types[i - list->min] = flag;
538
539
	    for (i = r->min; i <= r->max; ++i)
540
		list->types[i - list->min] |= r->types[i - r->min];
541
542
	    free(r->types);
543
	    r->types = list->types;
544
	} else {
545
	    r->map = list->map;
546
	}
547
	r->min = list->min;
548
	r->max = list->max;
549
	free(list);
550
    } else if (list->min < r->min) {
551
	/*
552
	 * Our tail intersects his head.
553
	 */
554
	if (flag) {
555
	    list->types = xlalloc(r->max - list->min + 1);
556
557
	    for (i = r->min; i <= r->max; ++i)
558
		list->types[i - list->min] = r->types[i - r->min];
559
560
	    for (i = list->min; i < r->min; ++i)
561
		list->types[i - list->min] = flag;
562
563
	    for (i = r->min; i <= list->max; ++i)
564
		list->types[i - list->min] |= flag;
565
566
	    free(r->types);
567
	    r->types = list->types;
568
	} else {
569
	    r->map = list->map;
570
	}
571
	r->min = list->min;
572
	free(list);
573
	return;
574
    } else {
575
	/*
576
	 * Our head intersects his tail.
577
	 * We might need to merge with the guy after him.
578
	 */
579
	if (flag) {
580
	    r->types = xrelalloc(r->types, list->max - r->min + 1);
581
582
	    for (i = list->min; i <= r->max; ++i)
583
		r->types[i - r->min] |= flag;
584
585
	    for (i = r->max+1; i <= list->max; ++i)
586
		r->types[i - r->min] = flag;
587
	}
588
	r->max = list->max;
589
	free(list);
590
    }
591
592
    /*
593
     * Okay, check to see if we grew into the next guy(s)
594
     */
595
    while ((lr = r->next) && r->max >= lr->min) {
596
	if (flag) {
597
	    if (r->max >= lr->max) {
598
		/*
599
		 * Good, we consumed all of him.
600
		 */
601
		for (i = lr->min; i <= lr->max; ++i)
602
		    r->types[i - r->min] |= lr->types[i - lr->min];
603
	    } else {
604
		/*
605
		 * "append" him on to the end of us.
606
		 */
607
		r->types = xrelalloc(r->types, lr->max - r->min + 1);
608
609
		for (i = lr->min; i <= r->max; ++i)
610
		    r->types[i - r->min] |= lr->types[i - lr->min];
611
612
		for (i = r->max+1; i <= lr->max; ++i)
613
		    r->types[i - r->min] = lr->types[i - lr->min];
614
615
		r->max = lr->max;
616
	    }
617
	} else {
618
	    if (lr->max > r->max)
619
		r->max = lr->max;
620
	}
621
622
	r->next = lr->next;
623
624
	if (flag)
625
	    free(lr->types);
626
	free(lr);
627
    }
628
}
629
630
void
631
dump_tables()
632
{
633
    int x, n;
634
    rune_list *list;
635
    _FileRuneLocale file_new_locale;
636
    FILE *fp = (ofile ? ofile : stdout);
637
638
    memset(&file_new_locale, 0, sizeof(file_new_locale));
639
640
    /*
641
     * See if we can compress some of the istype arrays
642
     */
643
    for(list = types.root; list; list = list->next) {
644
	list->map = list->types[0];
645
	for (x = 1; x < list->max - list->min + 1; ++x) {
646
	    if (list->types[x] != list->map) {
647
		list->map = 0;
648
		break;
649
	    }
650
	}
651
    }
652
653
    memcpy(&file_new_locale.frl_magic, new_locale.rl_magic,
654
	sizeof(file_new_locale.frl_magic));
655
    memcpy(&file_new_locale.frl_encoding, new_locale.rl_encoding,
656
	sizeof(file_new_locale.frl_encoding));
657
658
    file_new_locale.frl_invalid_rune = htonl(new_locale.rl_invalid_rune);
659
660
    /*
661
     * Fill in our tables.  Do this in network order so that
662
     * diverse machines have a chance of sharing data.
663
     * (Machines like Crays cannot share with little machines due to
664
     *  word size.  Sigh.  We tried.)
665
     */
666
    for (x = 0; x < _CACHED_RUNES; ++x) {
667
	file_new_locale.frl_runetype[x] = htonl(types.map[x]);
668
	file_new_locale.frl_maplower[x] = htonl(maplower.map[x]);
669
	file_new_locale.frl_mapupper[x] = htonl(mapupper.map[x]);
670
    }
671
672
    /*
673
     * Count up how many ranges we will need for each of the extents.
674
     */
675
    list = types.root;
676
677
    while (list) {
678
	new_locale.rl_runetype_ext.rr_nranges++;
679
	list = list->next;
680
    }
681
    file_new_locale.frl_runetype_ext.frr_nranges =
682
	htonl(new_locale.rl_runetype_ext.rr_nranges);
683
684
    list = maplower.root;
685
686
    while (list) {
687
	new_locale.rl_maplower_ext.rr_nranges++;
688
	list = list->next;
689
    }
690
    file_new_locale.frl_maplower_ext.frr_nranges =
691
	htonl(new_locale.rl_maplower_ext.rr_nranges);
692
693
    list = mapupper.root;
694
695
    while (list) {
696
	new_locale.rl_mapupper_ext.rr_nranges++;
697
	list = list->next;
698
    }
699
    file_new_locale.frl_mapupper_ext.frr_nranges =
700
	htonl(new_locale.rl_mapupper_ext.rr_nranges);
701
702
    file_new_locale.frl_variable_len = htonl(new_locale.rl_variable_len);
703
704
    /*
705
     * Okay, we are now ready to write the new locale file.
706
     */
707
708
    /*
709
     * PART 1: The _RuneLocale structure
710
     */
711
    if (fwrite((char *)&file_new_locale, sizeof(file_new_locale), 1, fp) != 1)
712
	err(1, "writing _RuneLocale to %s", locale_file);
713
    /*
714
     * PART 2: The runetype_ext structures (not the actual tables)
715
     */
716
    for (list = types.root, n = 0; list != NULL; list = list->next, n++) {
717
	_FileRuneEntry re;
718
719
	memset(&re, 0, sizeof(re));
720
	re.fre_min = htonl(list->min);
721
	re.fre_max = htonl(list->max);
722
	re.fre_map = htonl(list->map);
723
724
	if (fwrite((char *)&re, sizeof(re), 1, fp) != 1)
725
	    err(1, "writing runetype_ext #%d to %s", n, locale_file);
726
    }
727
    /*
728
     * PART 3: The maplower_ext structures
729
     */
730
    for (list = maplower.root, n = 0; list != NULL; list = list->next, n++) {
731
	_FileRuneEntry re;
732
733
	memset(&re, 0, sizeof(re));
734
	re.fre_min = htonl(list->min);
735
	re.fre_max = htonl(list->max);
736
	re.fre_map = htonl(list->map);
737
738
	if (fwrite((char *)&re, sizeof(re), 1, fp) != 1)
739
	    err(1, "writing maplower_ext #%d to %s", n, locale_file);
740
    }
741
    /*
742
     * PART 4: The mapupper_ext structures
743
     */
744
    for (list = mapupper.root, n = 0; list != NULL; list = list->next, n++) {
745
	_FileRuneEntry re;
746
747
	memset(&re, 0, sizeof(re));
748
	re.fre_min = htonl(list->min);
749
	re.fre_max = htonl(list->max);
750
	re.fre_map = htonl(list->map);
751
752
	if (fwrite((char *)&re, sizeof(re), 1, fp) != 1)
753
	    err(1, "writing mapupper_ext #%d to %s", n, locale_file);
754
    }
755
    /*
756
     * PART 5: The runetype_ext tables
757
     */
758
    for (list = types.root, n = 0; list != NULL; list = list->next, n++) {
759
	for (x = 0; x < list->max - list->min + 1; ++x)
760
	    list->types[x] = htonl(list->types[x]);
761
762
	if (!list->map) {
763
	    if (fwrite((char *)list->types,
764
		       (list->max - list->min + 1) * sizeof(u_int32_t),
765
		       1, fp) != 1)
766
		err(1, "writing runetype_ext table #%d to %s", n, locale_file);
767
	}
768
    }
769
    /*
770
     * PART 5: And finally the variable data
771
     */
772
    if (new_locale.rl_variable_len != 0 &&
773
	fwrite((char *)new_locale.rl_variable,
774
	       new_locale.rl_variable_len, 1, fp) != 1)
775
	err(1, "writing variable data to %s", locale_file);
776
    fclose(fp);
777
778
    if (!debug)
779
	return;
780
781
    if (new_locale.rl_encoding[0])
782
	fprintf(stderr, "ENCODING	%s\n", new_locale.rl_encoding);
783
    if (new_locale.rl_variable)
784
	fprintf(stderr, "VARIABLE	%s\n",
785
		(char *)new_locale.rl_variable);
786
787
    fprintf(stderr, "\nMAPLOWER:\n\n");
788
789
    for (x = 0; x < _CACHED_RUNES; ++x) {
790
	if (isprint(maplower.map[x]))
791
	    fprintf(stderr, " '%c'", (int)maplower.map[x]);
792
	else if (maplower.map[x])
793
	    fprintf(stderr, "%04x", maplower.map[x]);
794
	else
795
	    fprintf(stderr, "%4x", 0);
796
	if ((x & 0xf) == 0xf)
797
	    fprintf(stderr, "\n");
798
	else
799
	    fprintf(stderr, " ");
800
    }
801
    fprintf(stderr, "\n");
802
803
    for (list = maplower.root; list; list = list->next)
804
	fprintf(stderr, "\t%04x - %04x : %04x\n", list->min, list->max, list->map);
805
806
    fprintf(stderr, "\nMAPUPPER:\n\n");
807
808
    for (x = 0; x < _CACHED_RUNES; ++x) {
809
	if (isprint(mapupper.map[x]))
810
	    fprintf(stderr, " '%c'", (int)mapupper.map[x]);
811
	else if (mapupper.map[x])
812
	    fprintf(stderr, "%04x", mapupper.map[x]);
813
	else
814
	    fprintf(stderr, "%4x", 0);
815
	if ((x & 0xf) == 0xf)
816
	    fprintf(stderr, "\n");
817
	else
818
	    fprintf(stderr, " ");
819
    }
820
    fprintf(stderr, "\n");
821
822
    for (list = mapupper.root; list; list = list->next)
823
	fprintf(stderr, "\t%04x - %04x : %04x\n", list->min, list->max, list->map);
824
825
826
    fprintf(stderr, "\nTYPES:\n\n");
827
828
    for (x = 0; x < _CACHED_RUNES; ++x) {
829
	u_int32_t r = types.map[x];
830
831
	if (r) {
832
	    if (isprint(x))
833
		fprintf(stderr, " '%c':%2d", x, (int)(r & 0xff));
834
	    else
835
		fprintf(stderr, "%04x:%2d", x, (int)(r & 0xff));
836
837
	    fprintf(stderr, " %4s", (r & _RUNETYPE_A) ? "alph" : "");
838
	    fprintf(stderr, " %4s", (r & _RUNETYPE_C) ? "ctrl" : "");
839
	    fprintf(stderr, " %4s", (r & _RUNETYPE_D) ? "dig" : "");
840
	    fprintf(stderr, " %4s", (r & _RUNETYPE_G) ? "graf" : "");
841
	    fprintf(stderr, " %4s", (r & _RUNETYPE_L) ? "low" : "");
842
	    fprintf(stderr, " %4s", (r & _RUNETYPE_P) ? "punc" : "");
843
	    fprintf(stderr, " %4s", (r & _RUNETYPE_S) ? "spac" : "");
844
	    fprintf(stderr, " %4s", (r & _RUNETYPE_U) ? "upp" : "");
845
	    fprintf(stderr, " %4s", (r & _RUNETYPE_X) ? "xdig" : "");
846
	    fprintf(stderr, " %4s", (r & _RUNETYPE_B) ? "blnk" : "");
847
	    fprintf(stderr, " %4s", (r & _RUNETYPE_R) ? "prnt" : "");
848
	    fprintf(stderr, " %4s", (r & _RUNETYPE_I) ? "ideo" : "");
849
	    fprintf(stderr, " %4s", (r & _RUNETYPE_T) ? "spec" : "");
850
	    fprintf(stderr, " %4s", (r & _RUNETYPE_Q) ? "phon" : "");
851
	    fprintf(stderr, "\n");
852
	}
853
    }
854
855
    for (list = types.root; list; list = list->next) {
856
	if (list->map && list->min + 3 < list->max) {
857
	    u_int32_t r = list->map;
858
859
	    fprintf(stderr, "%04x:%2d", list->min, r & 0xff);
860
861
	    fprintf(stderr, " %4s", (r & _RUNETYPE_A) ? "alph" : "");
862
	    fprintf(stderr, " %4s", (r & _RUNETYPE_C) ? "ctrl" : "");
863
	    fprintf(stderr, " %4s", (r & _RUNETYPE_D) ? "dig" : "");
864
	    fprintf(stderr, " %4s", (r & _RUNETYPE_G) ? "graf" : "");
865
	    fprintf(stderr, " %4s", (r & _RUNETYPE_L) ? "low" : "");
866
	    fprintf(stderr, " %4s", (r & _RUNETYPE_P) ? "punc" : "");
867
	    fprintf(stderr, " %4s", (r & _RUNETYPE_S) ? "spac" : "");
868
	    fprintf(stderr, " %4s", (r & _RUNETYPE_U) ? "upp" : "");
869
	    fprintf(stderr, " %4s", (r & _RUNETYPE_X) ? "xdig" : "");
870
	    fprintf(stderr, " %4s", (r & _RUNETYPE_B) ? "blnk" : "");
871
	    fprintf(stderr, " %4s", (r & _RUNETYPE_R) ? "prnt" : "");
872
	    fprintf(stderr, " %4s", (r & _RUNETYPE_I) ? "ideo" : "");
873
	    fprintf(stderr, " %4s", (r & _RUNETYPE_T) ? "spec" : "");
874
	    fprintf(stderr, " %4s", (r & _RUNETYPE_Q) ? "phon" : "");
875
	    fprintf(stderr, "\n...\n");
876
877
	    fprintf(stderr, "%04x:%2d", list->max, r & 0xff);
878
879
	    fprintf(stderr, " %4s", (r & _RUNETYPE_A) ? "alph" : "");
880
	    fprintf(stderr, " %4s", (r & _RUNETYPE_C) ? "ctrl" : "");
881
	    fprintf(stderr, " %4s", (r & _RUNETYPE_D) ? "dig" : "");
882
	    fprintf(stderr, " %4s", (r & _RUNETYPE_G) ? "graf" : "");
883
	    fprintf(stderr, " %4s", (r & _RUNETYPE_L) ? "low" : "");
884
	    fprintf(stderr, " %4s", (r & _RUNETYPE_P) ? "punc" : "");
885
	    fprintf(stderr, " %4s", (r & _RUNETYPE_S) ? "spac" : "");
886
	    fprintf(stderr, " %4s", (r & _RUNETYPE_U) ? "upp" : "");
887
	    fprintf(stderr, " %4s", (r & _RUNETYPE_X) ? "xdig" : "");
888
	    fprintf(stderr, " %4s", (r & _RUNETYPE_B) ? "blnk" : "");
889
	    fprintf(stderr, " %4s", (r & _RUNETYPE_R) ? "prnt" : "");
890
	    fprintf(stderr, " %4s", (r & _RUNETYPE_I) ? "ideo" : "");
891
	    fprintf(stderr, " %4s", (r & _RUNETYPE_T) ? "spec" : "");
892
	    fprintf(stderr, " %4s", (r & _RUNETYPE_Q) ? "phon" : "");
893
            fprintf(stderr, " %1u", (unsigned)((r & _RUNETYPE_SWM)>>_RUNETYPE_SWS));
894
	    fprintf(stderr, "\n");
895
	} else
896
	for (x = list->min; x <= list->max; ++x) {
897
	    u_int32_t r = ntohl(list->types[x - list->min]);
898
899
	    if (r) {
900
		fprintf(stderr, "%04x:%2d", x, (int)(r & 0xff));
901
902
		fprintf(stderr, " %4s", (r & _RUNETYPE_A) ? "alph" : "");
903
		fprintf(stderr, " %4s", (r & _RUNETYPE_C) ? "ctrl" : "");
904
		fprintf(stderr, " %4s", (r & _RUNETYPE_D) ? "dig" : "");
905
		fprintf(stderr, " %4s", (r & _RUNETYPE_G) ? "graf" : "");
906
		fprintf(stderr, " %4s", (r & _RUNETYPE_L) ? "low" : "");
907
		fprintf(stderr, " %4s", (r & _RUNETYPE_P) ? "punc" : "");
908
		fprintf(stderr, " %4s", (r & _RUNETYPE_S) ? "spac" : "");
909
		fprintf(stderr, " %4s", (r & _RUNETYPE_U) ? "upp" : "");
910
		fprintf(stderr, " %4s", (r & _RUNETYPE_X) ? "xdig" : "");
911
		fprintf(stderr, " %4s", (r & _RUNETYPE_B) ? "blnk" : "");
912
		fprintf(stderr, " %4s", (r & _RUNETYPE_R) ? "prnt" : "");
913
		fprintf(stderr, " %4s", (r & _RUNETYPE_I) ? "ideo" : "");
914
		fprintf(stderr, " %4s", (r & _RUNETYPE_T) ? "spec" : "");
915
		fprintf(stderr, " %4s", (r & _RUNETYPE_Q) ? "phon" : "");
916
                fprintf(stderr, " %1u", (unsigned)((r & _RUNETYPE_SWM)>>_RUNETYPE_SWS));
917
		fprintf(stderr, "\n");
918
	    }
919
	}
920
    }
921
}
922
#line 915 "yacc.c"
923
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
924
static int yygrowstack(void)
925
{
926
    unsigned int newsize;
927
    long sslen;
928
    short *newss;
929
    YYSTYPE *newvs;
930
931
    if ((newsize = yystacksize) == 0)
932
        newsize = YYINITSTACKSIZE;
933
    else if (newsize >= YYMAXDEPTH)
934
        return -1;
935
    else if ((newsize *= 2) > YYMAXDEPTH)
936
        newsize = YYMAXDEPTH;
937
    sslen = yyssp - yyss;
938
#ifdef SIZE_MAX
939
#define YY_SIZE_MAX SIZE_MAX
940
#else
941
#define YY_SIZE_MAX 0xffffffffU
942
#endif
943
    if (newsize && YY_SIZE_MAX / newsize < sizeof *newss)
944
        goto bail;
945
    newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :
946
      (short *)malloc(newsize * sizeof *newss); /* overflow check above */
947
    if (newss == NULL)
948
        goto bail;
949
    yyss = newss;
950
    yyssp = newss + sslen;
951
    if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs)
952
        goto bail;
953
    newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :
954
      (YYSTYPE *)malloc(newsize * sizeof *newvs); /* overflow check above */
955
    if (newvs == NULL)
956
        goto bail;
957
    yyvs = newvs;
958
    yyvsp = newvs + sslen;
959
    yystacksize = newsize;
960
    yysslim = yyss + newsize - 1;
961
    return 0;
962
bail:
963
    if (yyss)
964
            free(yyss);
965
    if (yyvs)
966
            free(yyvs);
967
    yyss = yyssp = NULL;
968
    yyvs = yyvsp = NULL;
969
    yystacksize = 0;
970
    return -1;
971
}
972
973
#define YYABORT goto yyabort
974
#define YYREJECT goto yyabort
975
#define YYACCEPT goto yyaccept
976
#define YYERROR goto yyerrlab
977
int
978
yyparse(void)
979
{
980
    int yym, yyn, yystate;
981
#if YYDEBUG
982
    const char *yys;
983
984
    if ((yys = getenv("YYDEBUG")))
985
    {
986
        yyn = *yys;
987
        if (yyn >= '0' && yyn <= '9')
988
            yydebug = yyn - '0';
989
    }
990
#endif /* YYDEBUG */
991
992
    yynerrs = 0;
993
    yyerrflag = 0;
994
    yychar = (-1);
995
996
    if (yyss == NULL && yygrowstack()) goto yyoverflow;
997
    yyssp = yyss;
998
    yyvsp = yyvs;
999
    *yyssp = yystate = 0;
1000
1001
yyloop:
1002
    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
1003
    if (yychar < 0)
1004
    {
1005
        if ((yychar = yylex()) < 0) yychar = 0;
1006
#if YYDEBUG
1007
        if (yydebug)
1008
        {
1009
            yys = 0;
1010
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1011
            if (!yys) yys = "illegal-symbol";
1012
            printf("%sdebug: state %d, reading %d (%s)\n",
1013
                    YYPREFIX, yystate, yychar, yys);
1014
        }
1015
#endif
1016
    }
1017
    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
1018
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1019
    {
1020
#if YYDEBUG
1021
        if (yydebug)
1022
            printf("%sdebug: state %d, shifting to state %d\n",
1023
                    YYPREFIX, yystate, yytable[yyn]);
1024
#endif
1025
        if (yyssp >= yysslim && yygrowstack())
1026
        {
1027
            goto yyoverflow;
1028
        }
1029
        *++yyssp = yystate = yytable[yyn];
1030
        *++yyvsp = yylval;
1031
        yychar = (-1);
1032
        if (yyerrflag > 0)  --yyerrflag;
1033
        goto yyloop;
1034
    }
1035
    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
1036
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1037
    {
1038
        yyn = yytable[yyn];
1039
        goto yyreduce;
1040
    }
1041
    if (yyerrflag) goto yyinrecovery;
1042
#if defined(__GNUC__)
1043
    goto yynewerror;
1044
#endif
1045
yynewerror:
1046
    yyerror("syntax error");
1047
#if defined(__GNUC__)
1048
    goto yyerrlab;
1049
#endif
1050
yyerrlab:
1051
    ++yynerrs;
1052
yyinrecovery:
1053
    if (yyerrflag < 3)
1054
    {
1055
        yyerrflag = 3;
1056
        for (;;)
1057
        {
1058
            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
1059
                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
1060
            {
1061
#if YYDEBUG
1062
                if (yydebug)
1063
                    printf("%sdebug: state %d, error recovery shifting\
1064
 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
1065
#endif
1066
                if (yyssp >= yysslim && yygrowstack())
1067
                {
1068
                    goto yyoverflow;
1069
                }
1070
                *++yyssp = yystate = yytable[yyn];
1071
                *++yyvsp = yylval;
1072
                goto yyloop;
1073
            }
1074
            else
1075
            {
1076
#if YYDEBUG
1077
                if (yydebug)
1078
                    printf("%sdebug: error recovery discarding state %d\n",
1079
                            YYPREFIX, *yyssp);
1080
#endif
1081
                if (yyssp <= yyss) goto yyabort;
1082
                --yyssp;
1083
                --yyvsp;
1084
            }
1085
        }
1086
    }
1087
    else
1088
    {
1089
        if (yychar == 0) goto yyabort;
1090
#if YYDEBUG
1091
        if (yydebug)
1092
        {
1093
            yys = 0;
1094
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1095
            if (!yys) yys = "illegal-symbol";
1096
            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1097
                    YYPREFIX, yystate, yychar, yys);
1098
        }
1099
#endif
1100
        yychar = (-1);
1101
        goto yyloop;
1102
    }
1103
yyreduce:
1104
#if YYDEBUG
1105
    if (yydebug)
1106
        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1107
                YYPREFIX, yystate, yyn, yyrule[yyn]);
1108
#endif
1109
    yym = yylen[yyn];
1110
    if (yym)
1111
        yyval = yyvsp[1-yym];
1112
    else
1113
        memset(&yyval, 0, sizeof yyval);
1114
    switch (yyn)
1115
    {
1116
case 2:
1117
#line 109 "yacc.y"
1118
{ dump_tables(); }
1119
break;
1120
case 5:
1121
#line 117 "yacc.y"
1122
{ strncpy(new_locale.rl_encoding, yyvsp[0].str, sizeof(new_locale.rl_encoding)); }
1123
break;
1124
case 6:
1125
#line 119 "yacc.y"
1126
{ new_locale.rl_variable_len = strlen(yyvsp[0].str) + 1;
1127
		  new_locale.rl_variable = strdup(yyvsp[0].str);
1128
		}
1129
break;
1130
case 7:
1131
#line 123 "yacc.y"
1132
{ charsetbits = yyvsp[0].rune; charsetmask = 0x0000007f; }
1133
break;
1134
case 8:
1135
#line 125 "yacc.y"
1136
{ charsetbits = yyvsp[-1].rune; charsetmask = yyvsp[0].rune; }
1137
break;
1138
case 9:
1139
#line 127 "yacc.y"
1140
{ int final = yyvsp[0].str[strlen(yyvsp[0].str) - 1] & 0x7f;
1141
		  charsetbits = final << 24;
1142
		  if (yyvsp[0].str[0] == '$') {
1143
			charsetmask = 0x00007f7f;
1144
			if (strchr(",-./", yyvsp[0].str[1]))
1145
				charsetbits |= 0x80;
1146
			if (0xd0 <= final && final <= 0xdf)
1147
				charsetmask |= 0x007f0000;
1148
		  } else {
1149
			charsetmask = 0x0000007f;
1150
			if (strchr(",-./", yyvsp[0].str[0]))
1151
				charsetbits |= 0x80;
1152
			if (strlen(yyvsp[0].str) == 2 && yyvsp[0].str[0] == '!')
1153
				charsetbits |= ((0x80 | yyvsp[0].str[0]) << 16);
1154
		  }
1155
1156
		  /*
1157
		   * special rules
1158
		   */
1159
		  if (charsetbits == ('B' << 24)
1160
		   && charsetmask == 0x0000007f) {
1161
			/*ASCII: 94B*/
1162
			charsetbits = 0;
1163
			charsetmask = 0x0000007f;
1164
		  } else if (charsetbits == (('A' << 24) | 0x80)
1165
		  	  && charsetmask == 0x0000007f) {
1166
		  	/*Latin1: 96A*/
1167
			charsetbits = 0x80;
1168
			charsetmask = 0x0000007f;
1169
		  }
1170
		}
1171
break;
1172
case 10:
1173
#line 159 "yacc.y"
1174
{ new_locale.rl_invalid_rune = yyvsp[0].rune; }
1175
break;
1176
case 11:
1177
#line 161 "yacc.y"
1178
{ set_map(&types, yyvsp[0].list, yyvsp[-1].i); }
1179
break;
1180
case 12:
1181
#line 163 "yacc.y"
1182
{ set_map(&maplower, yyvsp[0].list, 0); }
1183
break;
1184
case 13:
1185
#line 165 "yacc.y"
1186
{ set_map(&mapupper, yyvsp[0].list, 0); }
1187
break;
1188
case 14:
1189
#line 167 "yacc.y"
1190
{ }
1191
break;
1192
case 15:
1193
#line 171 "yacc.y"
1194
{
1195
		    yyval.list = xmalloc(sizeof(rune_list));
1196
		    yyval.list->min = (yyvsp[0].rune & charsetmask) | charsetbits;
1197
		    yyval.list->max = (yyvsp[0].rune & charsetmask) | charsetbits;
1198
		    yyval.list->map = 0;
1199
		    yyval.list->next = 0;
1200
		}
1201
break;
1202
case 16:
1203
#line 179 "yacc.y"
1204
{
1205
		    yyval.list = xmalloc(sizeof(rune_list));
1206
		    yyval.list->min = (yyvsp[-2].rune & charsetmask) | charsetbits;
1207
		    yyval.list->max = (yyvsp[0].rune & charsetmask) | charsetbits;
1208
		    yyval.list->map = 0;
1209
		    yyval.list->next = 0;
1210
		}
1211
break;
1212
case 17:
1213
#line 187 "yacc.y"
1214
{
1215
		    yyval.list = xmalloc(sizeof(rune_list));
1216
		    yyval.list->min = (yyvsp[0].rune & charsetmask) | charsetbits;
1217
		    yyval.list->max = (yyvsp[0].rune & charsetmask) | charsetbits;
1218
		    yyval.list->map = 0;
1219
		    yyval.list->next = yyvsp[-1].list;
1220
		}
1221
break;
1222
case 18:
1223
#line 195 "yacc.y"
1224
{
1225
		    yyval.list = xmalloc(sizeof(rune_list));
1226
		    yyval.list->min = (yyvsp[-2].rune & charsetmask) | charsetbits;
1227
		    yyval.list->max = (yyvsp[0].rune & charsetmask) | charsetbits;
1228
		    yyval.list->map = 0;
1229
		    yyval.list->next = yyvsp[-3].list;
1230
		}
1231
break;
1232
case 19:
1233
#line 205 "yacc.y"
1234
{
1235
		    yyval.list = xmalloc(sizeof(rune_list));
1236
		    yyval.list->min = (yyvsp[-2].rune & charsetmask) | charsetbits;
1237
		    yyval.list->max = (yyvsp[-2].rune & charsetmask) | charsetbits;
1238
		    yyval.list->map = yyvsp[-1].rune;
1239
		    yyval.list->next = 0;
1240
		}
1241
break;
1242
case 20:
1243
#line 213 "yacc.y"
1244
{
1245
		    yyval.list = xmalloc(sizeof(rune_list));
1246
		    yyval.list->min = (yyvsp[-2].rune & charsetmask) | charsetbits;
1247
		    yyval.list->max = (yyvsp[-2].rune & charsetmask) | charsetbits;
1248
		    yyval.list->map = yyvsp[-1].rune;
1249
		    yyval.list->next = yyvsp[-4].list;
1250
		}
1251
break;
1252
case 21:
1253
#line 221 "yacc.y"
1254
{
1255
		    yyval.list = xmalloc(sizeof(rune_list));
1256
		    yyval.list->min = (yyvsp[-5].rune & charsetmask) | charsetbits;
1257
		    yyval.list->max = (yyvsp[-3].rune & charsetmask) | charsetbits;
1258
		    yyval.list->map = yyvsp[-1].rune;
1259
		    yyval.list->next = 0;
1260
		}
1261
break;
1262
case 22:
1263
#line 229 "yacc.y"
1264
{
1265
		    yyval.list = xmalloc(sizeof(rune_list));
1266
		    yyval.list->min = (yyvsp[-5].rune & charsetmask) | charsetbits;
1267
		    yyval.list->max = (yyvsp[-3].rune & charsetmask) | charsetbits;
1268
		    yyval.list->map = yyvsp[-1].rune;
1269
		    yyval.list->next = yyvsp[-7].list;
1270
		}
1271
break;
1272
case 23:
1273
#line 238 "yacc.y"
1274
{ }
1275
break;
1276
case 24:
1277
#line 239 "yacc.y"
1278
{ }
1279
break;
1280
case 25:
1281
#line 240 "yacc.y"
1282
{ }
1283
break;
1284
case 26:
1285
#line 241 "yacc.y"
1286
{ }
1287
break;
1288
#line 1281 "yacc.c"
1289
    }
1290
    yyssp -= yym;
1291
    yystate = *yyssp;
1292
    yyvsp -= yym;
1293
    yym = yylhs[yyn];
1294
    if (yystate == 0 && yym == 0)
1295
    {
1296
#if YYDEBUG
1297
        if (yydebug)
1298
            printf("%sdebug: after reduction, shifting from state 0 to\
1299
 state %d\n", YYPREFIX, YYFINAL);
1300
#endif
1301
        yystate = YYFINAL;
1302
        *++yyssp = YYFINAL;
1303
        *++yyvsp = yyval;
1304
        if (yychar < 0)
1305
        {
1306
            if ((yychar = yylex()) < 0) yychar = 0;
1307
#if YYDEBUG
1308
            if (yydebug)
1309
            {
1310
                yys = 0;
1311
                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1312
                if (!yys) yys = "illegal-symbol";
1313
                printf("%sdebug: state %d, reading %d (%s)\n",
1314
                        YYPREFIX, YYFINAL, yychar, yys);
1315
            }
1316
#endif
1317
        }
1318
        if (yychar == 0) goto yyaccept;
1319
        goto yyloop;
1320
    }
1321
    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
1322
            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
1323
        yystate = yytable[yyn];
1324
    else
1325
        yystate = yydgoto[yym];
1326
#if YYDEBUG
1327
    if (yydebug)
1328
        printf("%sdebug: after reduction, shifting from state %d \
1329
to state %d\n", YYPREFIX, *yyssp, yystate);
1330
#endif
1331
    if (yyssp >= yysslim && yygrowstack())
1332
    {
1333
        goto yyoverflow;
1334
    }
1335
    *++yyssp = yystate;
1336
    *++yyvsp = yyval;
1337
    goto yyloop;
1338
yyoverflow:
1339
    yyerror("yacc stack overflow");
1340
yyabort:
1341
    if (yyss)
1342
            free(yyss);
1343
    if (yyvs)
1344
            free(yyvs);
1345
    yyss = yyssp = NULL;
1346
    yyvs = yyvsp = NULL;
1347
    yystacksize = 0;
1348
    return (1);
1349
yyaccept:
1350
    if (yyss)
1351
            free(yyss);
1352
    if (yyvs)
1353
            free(yyvs);
1354
    yyss = yyssp = NULL;
1355
    yyvs = yyvsp = NULL;
1356
    yystacksize = 0;
1357
    return (0);
1358
}