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