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