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