| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: yacc.y,v 1.34 2019/10/13 21:12:32 christos Exp $ */ | | 1 | /* $NetBSD: yacc.y,v 1.35 2023/12/28 03:49:35 rin Exp $ */ |
2 | | | 2 | |
3 | %{ | | 3 | %{ |
4 | /*- | | 4 | /*- |
5 | * Copyright (c) 1993 | | 5 | * Copyright (c) 1993 |
6 | * The Regents of the University of California. All rights reserved. | | 6 | * The Regents of the University of California. All rights reserved. |
7 | * | | 7 | * |
8 | * This code is derived from software contributed to Berkeley by | | 8 | * This code is derived from software contributed to Berkeley by |
9 | * Paul Borman at Krystal Technologies. | | 9 | * Paul Borman at Krystal Technologies. |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
| @@ -33,27 +33,27 @@ | | | @@ -33,27 +33,27 @@ |
33 | * SUCH DAMAGE. | | 33 | * SUCH DAMAGE. |
34 | */ | | 34 | */ |
35 | | | 35 | |
36 | #if HAVE_NBTOOL_CONFIG_H | | 36 | #if HAVE_NBTOOL_CONFIG_H |
37 | #include "nbtool_config.h" | | 37 | #include "nbtool_config.h" |
38 | #endif | | 38 | #endif |
39 | | | 39 | |
40 | #include <sys/cdefs.h> | | 40 | #include <sys/cdefs.h> |
41 | #ifndef lint | | 41 | #ifndef lint |
42 | #if 0 | | 42 | #if 0 |
43 | static char sccsid[] = "@(#)yacc.y 8.1 (Berkeley) 6/6/93"; | | 43 | static char sccsid[] = "@(#)yacc.y 8.1 (Berkeley) 6/6/93"; |
44 | static char rcsid[] = "$FreeBSD$"; | | 44 | static char rcsid[] = "$FreeBSD$"; |
45 | #else | | 45 | #else |
46 | __RCSID("$NetBSD: yacc.y,v 1.34 2019/10/13 21:12:32 christos Exp $"); | | 46 | __RCSID("$NetBSD: yacc.y,v 1.35 2023/12/28 03:49:35 rin Exp $"); |
47 | #endif | | 47 | #endif |
48 | #endif /* not lint */ | | 48 | #endif /* not lint */ |
49 | | | 49 | |
50 | #include <sys/types.h> | | 50 | #include <sys/types.h> |
51 | #include <netinet/in.h> /* Needed by <arpa/inet.h> on NetBSD 1.5. */ | | 51 | #include <netinet/in.h> /* Needed by <arpa/inet.h> on NetBSD 1.5. */ |
52 | #include <arpa/inet.h> /* Needed for htonl on POSIX systems. */ | | 52 | #include <arpa/inet.h> /* Needed for htonl on POSIX systems. */ |
53 | | | 53 | |
54 | #include <err.h> | | 54 | #include <err.h> |
55 | #include <locale.h> | | 55 | #include <locale.h> |
56 | #include <stddef.h> | | 56 | #include <stddef.h> |
57 | #include <stdio.h> | | 57 | #include <stdio.h> |
58 | #include <stdlib.h> | | 58 | #include <stdlib.h> |
59 | #include <string.h> | | 59 | #include <string.h> |
| @@ -72,27 +72,29 @@ rune_map types = { { 0, }, }; | | | @@ -72,27 +72,29 @@ rune_map types = { { 0, }, }; |
72 | | | 72 | |
73 | _FileRuneLocale new_locale = { { 0, }, }; | | 73 | _FileRuneLocale new_locale = { { 0, }, }; |
74 | | | 74 | |
75 | size_t rl_variable_len = (size_t)0; | | 75 | size_t rl_variable_len = (size_t)0; |
76 | void *rl_variable = NULL; | | 76 | void *rl_variable = NULL; |
77 | | | 77 | |
78 | __nbrune_t charsetbits = (__nbrune_t)0x00000000; | | 78 | __nbrune_t charsetbits = (__nbrune_t)0x00000000; |
79 | #if 0 | | 79 | #if 0 |
80 | __nbrune_t charsetmask = (__nbrune_t)0x0000007f; | | 80 | __nbrune_t charsetmask = (__nbrune_t)0x0000007f; |
81 | #endif | | 81 | #endif |
82 | __nbrune_t charsetmask = (__nbrune_t)0xffffffff; | | 82 | __nbrune_t charsetmask = (__nbrune_t)0xffffffff; |
83 | | | 83 | |
84 | void set_map(rune_map *, rune_list *, u_int32_t); | | 84 | void set_map(rune_map *, rune_list *, u_int32_t); |
| | | 85 | #if 0 |
85 | void set_digitmap(rune_map *, rune_list *); | | 86 | void set_digitmap(rune_map *, rune_list *); |
| | | 87 | #endif |
86 | void add_map(rune_map *, rune_list *, u_int32_t); | | 88 | void add_map(rune_map *, rune_list *, u_int32_t); |
87 | | | 89 | |
88 | __dead void usage(void); | | 90 | __dead void usage(void); |
89 | int yyerror(const char *s); | | 91 | int yyerror(const char *s); |
90 | void *xmalloc(unsigned int sz); | | 92 | void *xmalloc(unsigned int sz); |
91 | u_int32_t *xlalloc(unsigned int sz); | | 93 | u_int32_t *xlalloc(unsigned int sz); |
92 | u_int32_t *xrelalloc(u_int32_t *old, unsigned int sz); | | 94 | u_int32_t *xrelalloc(u_int32_t *old, unsigned int sz); |
93 | void dump_tables(void); | | 95 | void dump_tables(void); |
94 | int yyparse(void); | | 96 | int yyparse(void); |
95 | extern int yylex(void); | | 97 | extern int yylex(void); |
96 | | | 98 | |
97 | /* mklocaledb.c */ | | 99 | /* mklocaledb.c */ |
98 | extern void mklocaledb(const char *, FILE *, FILE *); | | 100 | extern void mklocaledb(const char *, FILE *, FILE *); |
| @@ -177,28 +179,39 @@ entry : ENCODING STRING | | | @@ -177,28 +179,39 @@ entry : ENCODING STRING |
177 | /*Latin1: 96A*/ | | 179 | /*Latin1: 96A*/ |
178 | charsetbits = 0x80; | | 180 | charsetbits = 0x80; |
179 | charsetmask = 0x0000007f; | | 181 | charsetmask = 0x0000007f; |
180 | } | | 182 | } |
181 | } | | 183 | } |
182 | | INVALID RUNE | | 184 | | INVALID RUNE |
183 | { new_locale.frl_invalid_rune = htonl((u_int32_t)$2); } | | 185 | { new_locale.frl_invalid_rune = htonl((u_int32_t)$2); } |
184 | | LIST list | | 186 | | LIST list |
185 | { set_map(&types, $2, $1); } | | 187 | { set_map(&types, $2, $1); } |
186 | | MAPLOWER map | | 188 | | MAPLOWER map |
187 | { set_map(&maplower, $2, 0); } | | 189 | { set_map(&maplower, $2, 0); } |
188 | | MAPUPPER map | | 190 | | MAPUPPER map |
189 | { set_map(&mapupper, $2, 0); } | | 191 | { set_map(&mapupper, $2, 0); } |
190 | | DIGITMAP map | | 192 | /* |
191 | { set_digitmap(&types, $2); } | | 193 | * XXX PR lib/57798 |
| | | 194 | * set_digitmap() was implemented with an assumption that |
| | | 195 | * all characters are mapped to numerical values <= 255. |
| | | 196 | * This is no longer true for Unicode, and results in, e.g., |
| | | 197 | * wrong return values of wcwidth(3) for U+5146 or U+16B60. |
| | | 198 | * |
| | | 199 | * | DIGITMAP map |
| | | 200 | * { set_digitmap(&types, $2); } |
| | | 201 | * |
| | | 202 | */ |
| | | 203 | | DIGITMAP mapignore |
| | | 204 | { } |
192 | ; | | 205 | ; |
193 | | | 206 | |
194 | list : RUNE | | 207 | list : RUNE |
195 | { | | 208 | { |
196 | $$ = (rune_list *)malloc(sizeof(rune_list)); | | 209 | $$ = (rune_list *)malloc(sizeof(rune_list)); |
197 | $$->min = ($1 & charsetmask) | charsetbits; | | 210 | $$->min = ($1 & charsetmask) | charsetbits; |
198 | $$->max = ($1 & charsetmask) | charsetbits; | | 211 | $$->max = ($1 & charsetmask) | charsetbits; |
199 | $$->next = 0; | | 212 | $$->next = 0; |
200 | } | | 213 | } |
201 | | RUNE THRU RUNE | | 214 | | RUNE THRU RUNE |
202 | { | | 215 | { |
203 | $$ = (rune_list *)malloc(sizeof(rune_list)); | | 216 | $$ = (rune_list *)malloc(sizeof(rune_list)); |
204 | $$->min = ($1 & charsetmask) | charsetbits; | | 217 | $$->min = ($1 & charsetmask) | charsetbits; |
| @@ -244,26 +257,32 @@ map : LBRK RUNE RUNE RBRK | | | @@ -244,26 +257,32 @@ map : LBRK RUNE RUNE RBRK |
244 | $$->max = ($4 & charsetmask) | charsetbits; | | 257 | $$->max = ($4 & charsetmask) | charsetbits; |
245 | $$->map = $6; | | 258 | $$->map = $6; |
246 | $$->next = 0; | | 259 | $$->next = 0; |
247 | } | | 260 | } |
248 | | map LBRK RUNE THRU RUNE ':' RUNE RBRK | | 261 | | map LBRK RUNE THRU RUNE ':' RUNE RBRK |
249 | { | | 262 | { |
250 | $$ = (rune_list *)malloc(sizeof(rune_list)); | | 263 | $$ = (rune_list *)malloc(sizeof(rune_list)); |
251 | $$->min = ($3 & charsetmask) | charsetbits; | | 264 | $$->min = ($3 & charsetmask) | charsetbits; |
252 | $$->max = ($5 & charsetmask) | charsetbits; | | 265 | $$->max = ($5 & charsetmask) | charsetbits; |
253 | $$->map = $7; | | 266 | $$->map = $7; |
254 | $$->next = $1; | | 267 | $$->next = $1; |
255 | } | | 268 | } |
256 | ; | | 269 | ; |
| | | 270 | |
| | | 271 | mapignore : LBRK RUNE RUNE RBRK { } |
| | | 272 | | map LBRK RUNE RUNE RBRK { } |
| | | 273 | | LBRK RUNE THRU RUNE ':' RUNE RBRK { } |
| | | 274 | | map LBRK RUNE THRU RUNE ':' RUNE RBRK { } |
| | | 275 | ; |
257 | %% | | 276 | %% |
258 | | | 277 | |
259 | int debug = 0; | | 278 | int debug = 0; |
260 | FILE *ofile; | | 279 | FILE *ofile; |
261 | | | 280 | |
262 | int | | 281 | int |
263 | main(int ac, char *av[]) | | 282 | main(int ac, char *av[]) |
264 | { | | 283 | { |
265 | int x; | | 284 | int x; |
266 | const char *locale_type; | | 285 | const char *locale_type; |
267 | | | 286 | |
268 | extern char *optarg; | | 287 | extern char *optarg; |
269 | extern int optind; | | 288 | extern int optind; |
| @@ -372,45 +391,47 @@ xrelalloc(u_int32_t *old, unsigned int s | | | @@ -372,45 +391,47 @@ xrelalloc(u_int32_t *old, unsigned int s |
372 | | | 391 | |
373 | void | | 392 | void |
374 | set_map(rune_map *map, rune_list *list, u_int32_t flag) | | 393 | set_map(rune_map *map, rune_list *list, u_int32_t flag) |
375 | { | | 394 | { |
376 | list->map &= charsetmask; | | 395 | list->map &= charsetmask; |
377 | list->map |= charsetbits; | | 396 | list->map |= charsetbits; |
378 | while (list) { | | 397 | while (list) { |
379 | rune_list *nlist = list->next; | | 398 | rune_list *nlist = list->next; |
380 | add_map(map, list, flag); | | 399 | add_map(map, list, flag); |
381 | list = nlist; | | 400 | list = nlist; |
382 | } | | 401 | } |
383 | } | | 402 | } |
384 | | | 403 | |
| | | 404 | #if 0 |
385 | void | | 405 | void |
386 | set_digitmap(rune_map *map, rune_list *list) | | 406 | set_digitmap(rune_map *map, rune_list *list) |
387 | { | | 407 | { |
388 | __nbrune_t i; | | 408 | __nbrune_t i; |
389 | | | 409 | |
390 | while (list) { | | 410 | while (list) { |
391 | rune_list *nlist = list->next; | | 411 | rune_list *nlist = list->next; |
392 | for (i = list->min; i <= list->max; ++i) { | | 412 | for (i = list->min; i <= list->max; ++i) { |
393 | if (list->map + (i - list->min)) { | | 413 | if (list->map + (i - list->min)) { |
394 | rune_list *tmp = (rune_list *)xmalloc(sizeof(rune_list)); | | 414 | rune_list *tmp = (rune_list *)xmalloc(sizeof(rune_list)); |
395 | tmp->min = i; | | 415 | tmp->min = i; |
396 | tmp->max = i; | | 416 | tmp->max = i; |
397 | add_map(map, tmp, list->map + (i - list->min)); | | 417 | add_map(map, tmp, list->map + (i - list->min)); |
398 | } | | 418 | } |
399 | } | | 419 | } |
400 | free(list); | | 420 | free(list); |
401 | list = nlist; | | 421 | list = nlist; |
402 | } | | 422 | } |
403 | } | | 423 | } |
| | | 424 | #endif |
404 | | | 425 | |
405 | void | | 426 | void |
406 | add_map(rune_map *map, rune_list *list, u_int32_t flag) | | 427 | add_map(rune_map *map, rune_list *list, u_int32_t flag) |
407 | { | | 428 | { |
408 | __nbrune_t i; | | 429 | __nbrune_t i; |
409 | rune_list *lr = 0; | | 430 | rune_list *lr = 0; |
410 | rune_list *r; | | 431 | rune_list *r; |
411 | __nbrune_t run; | | 432 | __nbrune_t run; |
412 | | | 433 | |
413 | while (list->min < _CTYPE_CACHE_SIZE && list->min <= list->max) { | | 434 | while (list->min < _CTYPE_CACHE_SIZE && list->min <= list->max) { |
414 | if (flag) | | 435 | if (flag) |
415 | map->map[list->min++] |= flag; | | 436 | map->map[list->min++] |= flag; |
416 | else | | 437 | else |