Changeset 5523 for trunk/tools/wrc/wrc.c
- Timestamp:
- Apr 16, 2001, 7:12:53 PM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/wrc/wrc.c
r3426 r5523 4 4 * Copyrignt 1998 Bertho A. Stultiens (BS) 5 5 * 6 * 30-Apr-2000 BS - Integrated a new preprocessor (-E and -N) 6 7 * 20-Jun-1998 BS - Added -L option to prevent case conversion 7 8 * of embedded filenames. … … 37 38 #include <stdio.h> 38 39 #include <stdlib.h> 40 #include <unistd.h> 39 41 #include <string.h> 40 42 #include <assert.h> 41 43 #include <ctype.h> 44 #include <signal.h> 42 45 43 46 #include "wrc.h" … … 51 54 #include "parser.h" 52 55 53 char usage[] = "Usage: wrc [options...] [infile[.rc|.res]]\n" 56 static char usage[] = 57 "Usage: wrc [options...] [infile[.rc|.res]]\n" 54 58 " -a n Alignment of resource (win16 only, default is 4)\n" 55 59 " -A Auto register resources (only with gcc 2.7 and better)\n" 56 " -b Create a C array from a binary .res file\n" 60 " -b Create an assembly array from a binary .res file\n" 61 " -B x Set output byte-order x={n[ative], l[ittle], b[ig]}\n" 62 " (win32 only; default is n[ative] which equals " 63 #ifdef WORDS_BIGENDIAN 64 "big" 65 #else 66 "little" 67 #endif 68 "-endian)\n" 57 69 " -c Add 'const' prefix to C constants\n" 58 70 " -C cp Set the resource's codepage to cp (default is 0)\n" … … 60 72 " -D id[=val] Define preprocessor identifier id=val\n" 61 73 " -e Disable recognition of win32 keywords in 16bit compile\n" 74 " -E Preprocess only\n" 62 75 " -g Add symbols to the global c namespace\n" 63 76 " -h Also generate a .h file\n" 64 77 " -H file Same as -h but written to file\n" 65 78 " -I path Set include search dir to path (multiple -I allowed)\n" 66 " -l lan Set default language to lan (default is neutral {0 })\n"79 " -l lan Set default language to lan (default is neutral {0, 0})\n" 67 80 " -L Leave case of embedded filenames as is\n" 81 " -m Do not remap numerical resource IDs\n" 68 82 " -n Do not generate .s file\n" 83 " -N Do not preprocess input\n" 69 84 " -o file Output to file (default is infile.[res|s|h]\n" 70 85 " -p prefix Give a prefix for the generated names\n" … … 81 96 " * 0x02 Dump internal structures\n" 82 97 " * 0x04 Create a parser trace (yydebug=1)\n" 98 " * 0x08 Preprocessor messages\n" 99 " * 0x10 Preprocessor lex messages\n" 100 " * 0x20 Preprocessor yacc trace\n" 83 101 "The -o option only applies to the final destination file, which is\n" 84 102 "in case of normal compile a .s file. You must use the '-H header.h'\n" … … 89 107 90 108 char version_string[] = "Wine Resource Compiler Version " WRC_FULLVERSION "\n" 91 "Copyright 1998 ,1999Bertho A. Stultiens\n"109 "Copyright 1998-2000 Bertho A. Stultiens\n" 92 110 " 1994 Martin von Loewis\n"; 93 111 … … 122 140 * debuglevel & DEBUGLEVEL_DUMP Dump internal structures 123 141 * debuglevel & DEBUGLEVEL_TRACE Create parser trace 142 * debuglevel & DEBUGLEVEL_PPMSG Preprocessor messages 143 * debuglevel & DEBUGLEVEL_PPLEX Preprocessor lex trace 144 * debuglevel & DEBUGLEVEL_PPTRACE Preprocessor yacc trace 124 145 */ 125 146 int debuglevel = DEBUGLEVEL_NONE; … … 198 219 */ 199 220 int leave_case = 0; 221 222 /* 223 * The output byte-order of resources (set with -B) 224 */ 225 int byteorder = WRC_BO_NATIVE; 226 227 /* 228 * Set when _only_ to run the preprocessor (-E option) 229 */ 230 int preprocess_only = 0; 231 232 /* 233 * Set when _not_ to run the preprocessor (-N option) 234 */ 235 int no_preprocess = 0; 236 237 /* 238 * Cleared when _not_ to remap resource types (-m option) 239 */ 240 int remap = 1; 200 241 201 242 char *output_name; /* The name given by the -o option */ 202 243 char *input_name; /* The name given on the command-line */ 203 244 char *header_name; /* The name given by the -H option */ 245 char *temp_name; /* Temporary file for preprocess pipe */ 246 247 int line_number = 1; /* The current line */ 248 int char_number = 1; /* The current char pos within the line */ 204 249 205 250 char *cmdline; /* The entire commandline */ 251 time_t now; /* The time of start of wrc */ 206 252 207 253 resource_t *resource_top; /* The top of the parsed resources */ 208 254 255 #ifdef __EMX__ 256 int getopt (int argc, char **argv, const char *optstring); 257 #else 209 258 int getopt (int argc, char *const *argv, const char *optstring); 259 #endif 260 261 static void rm_tempfile(void); 262 static void segvhandler(int sig); 210 263 211 264 int main(int argc,char *argv[]) … … 220 273 int cmdlen; 221 274 275 signal(SIGSEGV, segvhandler); 276 277 now = time(NULL); 278 222 279 /* First rebuild the commandline to put in destination */ 223 280 /* Could be done through env[], but not all OS-es support it */ … … 234 291 } 235 292 236 while((optc = getopt(argc, argv, "a:Ab cC:d:D:eghH:I:l:Lno:p:rstTVw:W")) != EOF)293 while((optc = getopt(argc, argv, "a:AbB:cC:d:D:eEghH:I:l:LmnNo:p:rstTVw:W")) != EOF) 237 294 { 238 295 switch(optc) … … 247 304 binary = 1; 248 305 break; 306 case 'B': 307 switch(optarg[0]) 308 { 309 case 'n': 310 case 'N': 311 byteorder = WRC_BO_NATIVE; 312 break; 313 case 'l': 314 case 'L': 315 byteorder = WRC_BO_LITTLE; 316 break; 317 case 'b': 318 case 'B': 319 byteorder = WRC_BO_BIG; 320 break; 321 default: 322 fprintf(stderr, "Byteordering must be n[ative], l[ittle] or b[ig]\n"); 323 lose++; 324 } 325 break; 249 326 case 'c': 250 327 constant = 1; … … 261 338 case 'e': 262 339 extensions = 0; 340 break; 341 case 'E': 342 preprocess_only = 1; 263 343 break; 264 344 case 'g': … … 284 364 leave_case = 1; 285 365 break; 366 case 'm': 367 remap = 0; 368 break; 286 369 case 'n': 287 370 create_s = 0; 371 break; 372 case 'N': 373 no_preprocess = 1; 288 374 break; 289 375 case 'o': … … 391 477 } 392 478 479 if(byteorder != WRC_BO_NATIVE) 480 { 481 if(binary) 482 error("Forced byteordering not supported for binary resources\n"); 483 } 484 485 if(preprocess_only) 486 { 487 if(constant) 488 { 489 warning("Option -c ignored with preprocess only\n"); 490 constant = 0; 491 } 492 493 if(create_header) 494 { 495 warning("Option -[h|H] ignored with preprocess only\n"); 496 create_header = 0; 497 } 498 499 if(indirect) 500 { 501 warning("Option -l ignored with preprocess only\n"); 502 indirect = 0; 503 } 504 505 if(indirect_only) 506 { 507 error("Option -E and -L cannot be used together\n"); 508 } 509 510 if(global) 511 { 512 warning("Option -g ignored with preprocess only\n"); 513 global = 0; 514 } 515 516 if(create_dir) 517 { 518 warning("Option -s ignored with preprocess only\n"); 519 create_dir = 0; 520 } 521 522 if(binary) 523 { 524 error("Option -E and -b cannot be used together\n"); 525 } 526 527 if(no_preprocess) 528 { 529 error("Option -E and -N cannot be used together\n"); 530 } 531 } 532 533 #if !defined(HAVE_WINE_CONSTRUCTOR) 534 if(auto_register) 535 { 536 warning("Autoregister code non-operable (HAVE_WINE_CONSTRUCTOR not defined)"); 537 auto_register = 0; 538 } 539 #endif 540 393 541 /* Set alignment power */ 394 542 a = alignment; … … 414 562 415 563 yydebug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0; 564 yy_flex_debug = debuglevel & DEBUGLEVEL_TRACE ? 1 : 0; 565 ppdebug = debuglevel & DEBUGLEVEL_PPTRACE ? 1 : 0; 566 pp_flex_debug = debuglevel & DEBUGLEVEL_PPLEX ? 1 : 0; 416 567 417 568 /* Set the default defined stuff */ 569 add_cmdline_define("__WRC__=" WRC_EXP_STRINGIZE(WRC_MAJOR_VERSION)); 570 add_cmdline_define("__WRC_MINOR__=" WRC_EXP_STRINGIZE(WRC_MINOR_VERSION)); 571 add_cmdline_define("__WRC_MICRO__=" WRC_EXP_STRINGIZE(WRC_MICRO_VERSION)); 572 add_cmdline_define("__WRC_PATCH__=" WRC_EXP_STRINGIZE(WRC_MICRO_VERSION)); 573 418 574 add_cmdline_define("RC_INVOKED=1"); 419 add_cmdline_define("__WRC__=1"); 575 420 576 if(win32) 421 577 { … … 423 579 add_cmdline_define("__FLAT__=1"); 424 580 } 581 582 add_special_define("__FILE__"); 583 add_special_define("__LINE__"); 584 add_special_define("__DATE__"); 585 add_special_define("__TIME__"); 425 586 426 587 /* Check if the user set a language, else set default */ … … 432 593 { 433 594 input_name = argv[optind]; 434 yyin = fopen(input_name, "rb");435 if(!yyin)436 {437 error("Could not open %s\n", input_name);438 }439 }440 else441 {442 yyin = stdin;443 595 } 444 596 445 597 if(binary && !input_name) 446 598 { 447 error("Binary mode requires .res file as input"); 448 } 449 450 if(!output_name) 599 error("Binary mode requires .res file as input\n"); 600 } 601 602 /* Generate appropriate outfile names */ 603 if(!output_name && !preprocess_only) 451 604 { 452 605 output_name = dup_basename(input_name, binary ? ".res" : ".rc"); … … 460 613 } 461 614 615 /* Run the preprocessor on the input */ 616 if(!no_preprocess && !binary) 617 { 618 char *real_name; 619 /* 620 * Preprocess the input to a temp-file, or stdout if 621 * no output was given. 622 */ 623 624 chat("Starting preprocess"); 625 626 if(preprocess_only && !output_name) 627 { 628 ppout = stdout; 629 } 630 else if(preprocess_only && output_name) 631 { 632 if(!(ppout = fopen(output_name, "wb"))) 633 error("Could not open %s for writing\n", output_name); 634 } 635 else 636 { 637 if(!(temp_name = tmpnam(NULL))) 638 error("Could nor generate a temp-name\n"); 639 temp_name = xstrdup(temp_name); 640 if(!(ppout = fopen(temp_name, "wb"))) 641 error("Could not create a temp-file\n"); 642 643 atexit(rm_tempfile); 644 } 645 646 real_name = input_name; /* Because it gets overwritten */ 647 648 if(!input_name) 649 ppin = stdin; 650 else 651 { 652 if(!(ppin = fopen(input_name, "rb"))) 653 error("Could not open %s\n", input_name); 654 } 655 656 fprintf(ppout, "# 1 \"%s\" 1\n", input_name ? input_name : ""); 657 658 ret = ppparse(); 659 660 input_name = real_name; 661 662 if(input_name) 663 fclose(ppin); 664 665 fclose(ppout); 666 667 input_name = temp_name; 668 669 if(ret) 670 exit(1); /* Error during preprocess */ 671 672 if(preprocess_only) 673 exit(0); 674 } 675 462 676 if(!binary) 463 677 { 464 678 /* Go from .rc to .res or .s */ 465 679 chat("Starting parse"); 680 681 if(!(yyin = fopen(input_name, "rb"))) 682 error("Could not open %s for input\n", input_name); 683 466 684 ret = yyparse(); 467 685 … … 522 740 523 741 524 525 742 static void rm_tempfile(void) 743 { 744 if(temp_name) 745 unlink(temp_name); 746 } 747 748 static void segvhandler(int sig) 749 { 750 fprintf(stderr, "\n%s:%d: Oops, segment violation\n", input_name, line_number); 751 fflush(stdout); 752 fflush(stderr); 753 abort(); 754 } 755
Note:
See TracChangeset
for help on using the changeset viewer.