3 * Copyright Martin von Loewis, 1994
4 * Copyrignt 1998 Bertho A. Stultiens (BS)
6 * 20-Jun-1998 BS - Added -L option to prevent case conversion
7 * of embedded filenames.
9 * 08-Jun-1998 BS - Added -A option to generate autoregister code
10 * for winelib operation.
12 * 21-May-1998 BS - Removed the CPP option. Its internal now.
13 * - Added implementations for defines and includes
16 * 30-Apr-1998 BS - The options now contain nearly the entire alphabet.
17 * Seems to be a sign for too much freedom. I implemeted
18 * most of them as a user choice possibility for things
19 * that I do not know what to put there by default.
20 * - -l and -L options are now known as -t and -T.
22 * 23-Apr-1998 BS - Finally gave up on backward compatibility on the
23 * commandline (after a blessing from the newsgroup).
24 * So, I changed the lot.
26 * 17-Apr-1998 BS - Added many new command-line options but took care
27 * that it would not break old scripts (sigh).
29 * 16-Apr-1998 BS - There is not much left of the original source...
30 * I had to rewrite most of it because the parser
31 * changed completely with all the types etc..
53 char usage
[] = "Usage: wrc [options...] [infile[.rc|.res]]\n"
54 " -a n Alignment of resource (win16 only, default is 4)\n"
55 " -A Auto register resources (only with gcc 2.7 and better)\n"
56 " -b Create a C array from a binary .res file\n"
57 " -c Add 'const' prefix to C constants\n"
58 " -C cp Set the resource's codepage to cp (default is 0)\n"
59 " -d n Set debug level to 'n'\n"
60 " -D id[=val] Define preprocessor identifier id=val\n"
61 " -e Disable recognition of win32 keywords in 16bit compile\n"
62 " -g Add symbols to the global c namespace\n"
63 " -h Also generate a .h file\n"
64 " -H file Same as -h but written to file\n"
65 " -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"
67 " -L Leave case of embedded filenames as is\n"
68 " -n Do not generate .s file\n"
69 " -o file Output to file (default is infile.[res|s|h]\n"
70 " -p prefix Give a prefix for the generated names\n"
71 " -r Create binary .res file (compile only)\n"
72 " -s Add structure with win32/16 (PE/NE) resource directory\n"
73 " -t Generate indirect loadable resource tables\n"
74 " -T Generate only indirect loadable resources tables\n"
75 " -V Print version end exit\n"
76 " -w 16|32 Select win16 or win32 output (default is win32)\n"
77 " -W Enable pedantic warnings\n"
78 "Input is taken from stdin if no sourcefile specified.\n"
79 "Debug level 'n' is a bitmask with following meaning:\n"
80 " * 0x01 Tell which resource is parsed (verbose mode)\n"
81 " * 0x02 Dump internal structures\n"
82 " * 0x04 Create a parser trace (yydebug=1)\n"
83 "The -o option only applies to the final destination file, which is\n"
84 "in case of normal compile a .s file. You must use the '-H header.h'\n"
85 "option to override the header-filename.\n"
86 "If no input filename is given and the output name is not overridden\n"
87 "with -o and/or -H, then the output is written to \"wrc.tab.[sh]\"\n"
90 char version_string
[] = "Wine Resource Compiler Version " WRC_FULLVERSION
"\n"
91 "Copyright 1998,1999 Bertho A. Stultiens\n"
92 " 1994 Martin von Loewis\n";
95 * Default prefix for resource names used in the C array.
96 * Option '-p name' sets it to 'name'
98 #ifdef NEED_UNDERSCORE_PREFIX
99 char *prefix
= "__Resource";
101 char *prefix
= "_Resource";
105 * Set if compiling in 32bit mode (default).
110 * Set when generated C variables should be prefixed with 'const'
115 * Create a .res file from the source and exit (-r option).
120 * debuglevel == DEBUGLEVEL_NONE Don't bother
121 * debuglevel & DEBUGLEVEL_CHAT Say whats done
122 * debuglevel & DEBUGLEVEL_DUMP Dump internal structures
123 * debuglevel & DEBUGLEVEL_TRACE Create parser trace
125 int debuglevel
= DEBUGLEVEL_NONE
;
128 * Recognize win32 keywords if set (-w 32 enforces this),
129 * otherwise set with -e option.
134 * Set when creating C array from .res file (-b option).
139 * Set when an additional C-header is to be created in compile (-h option).
141 int create_header
= 0;
144 * Set when the NE/PE resource directory should be dumped into
150 * Set when all symbols should be added to the global namespace (-g option)
155 * Set when indirect loadable resource tables should be created (-t)
160 * Set when _only_ indirect loadable resource tables should be created (-T)
162 int indirect_only
= 0;
165 * NE segment resource aligment (-a option)
171 * Cleared when the assembly file must be suppressed (-n option)
176 * Language setting for resources (-l option)
178 language_t
*currentlanguage
= NULL
;
181 * The codepage to write in win32 PE resource segment (-C option)
186 * Set when extra warnings should be generated (-W option)
191 * Set when autoregister code must be added to the output (-A option)
193 int auto_register
= 0;
196 * Set when the case of embedded filenames should not be converted
197 * to lower case (-L option)
201 char *output_name
; /* The name given by the -o option */
202 char *input_name
; /* The name given on the command-line */
203 char *header_name
; /* The name given by the -H option */
205 char *cmdline
; /* The entire commandline */
207 resource_t
*resource_top
; /* The top of the parsed resources */
209 int getopt (int argc
, char *const *argv
, const char *optstring
);
211 int main(int argc
,char *argv
[])
222 /* First rebuild the commandline to put in destination */
223 /* Could be done through env[], but not all OS-es support it */
224 cmdlen
= 4; /* for "wrc " */
225 for(i
= 1; i
< argc
; i
++)
226 cmdlen
+= strlen(argv
[i
]) + 1;
227 cmdline
= (char *)xmalloc(cmdlen
);
228 strcpy(cmdline
, "wrc ");
229 for(i
= 1; i
< argc
; i
++)
231 strcat(cmdline
, argv
[i
]);
233 strcat(cmdline
, " ");
236 while((optc
= getopt(argc
, argv
, "a:AbcC:d:D:eghH:I:l:Lno:p:rstTVw:W")) != EOF
)
241 alignment
= atoi(optarg
);
253 codepage
= strtol(optarg
, NULL
, 0);
256 debuglevel
= strtol(optarg
, NULL
, 0);
259 add_cmdline_define(optarg
);
268 header_name
= strdup(optarg
);
274 add_include_path(optarg
);
279 lan
= strtol(optarg
, NULL
, 0);
280 currentlanguage
= new_language(PRIMARYLANGID(lan
), SUBLANGID(lan
));
290 output_name
= strdup(optarg
);
293 #ifdef NEED_UNDERSCORE_PREFIX
294 prefix
= (char *)xmalloc(strlen(optarg
)+2);
296 strcpy(prefix
+1, optarg
);
298 prefix
= xstrdup(optarg
);
314 printf(version_string
);
318 if(!strcmp(optarg
, "16"))
320 else if(!strcmp(optarg
, "32"))
336 fprintf(stderr
, usage
);
340 /* Check the command line options for invalid combinations */
345 warning("Option -e ignored with 32bit compile\n");
354 warning("Option -c ignored with compile to .res\n");
360 warning("Option -[h|H] ignored with compile to .res\n");
366 warning("Option -l ignored with compile to .res\n");
372 warning("Option -L ignored with compile to .res\n");
378 warning("Option -g ignored with compile to .res\n");
384 error("Option -r and -s cannot be used together\n");
389 error("Option -r and -b cannot be used together\n");
393 /* Set alignment power */
395 for(alignment_pwr
= 0; alignment_pwr
< 10 && a
> 1; alignment_pwr
++)
401 error("Alignment must be between 1 and 1024");
403 if((1 << alignment_pwr
) != alignment
)
405 error("Alignment must be a power of 2");
408 /* Kill io buffering when some kind of debuglevel is enabled */
415 yydebug
= debuglevel
& DEBUGLEVEL_TRACE
? 1 : 0;
417 /* Set the default defined stuff */
418 add_cmdline_define("RC_INVOKED=1");
419 add_cmdline_define("__WRC__=1");
422 add_cmdline_define("__WIN32__=1");
423 add_cmdline_define("__FLAT__=1");
426 /* Check if the user set a language, else set default */
428 currentlanguage
= new_language(0, 0);
430 /* Check for input file on command-line */
433 input_name
= argv
[optind
];
434 yyin
= fopen(input_name
, "rb");
437 error("Could not open %s\n", input_name
);
445 if(binary
&& !input_name
)
447 error("Binary mode requires .res file as input");
452 output_name
= dup_basename(input_name
, binary
? ".res" : ".rc");
453 strcat(output_name
, create_res
? ".res" : ".s");
456 if(!header_name
&& !create_res
)
458 header_name
= dup_basename(input_name
, binary
? ".res" : ".rc");
459 strcat(header_name
, ".h");
464 /* Go from .rc to .res or .s */
465 chat("Starting parse");
473 /* Error during parse */
477 if(debuglevel
& DEBUGLEVEL_DUMP
)
478 dump_resources(resource_top
);
480 /* Convert the internal lists to binary data */
481 resources2res(resource_top
);
485 chat("Writing .res-file");
486 write_resfile(output_name
, resource_top
);
492 chat("Writing .s-file");
493 write_s_file(output_name
, resource_top
);
497 chat("Writing .h-file");
498 write_h_file(header_name
, resource_top
);
505 /* Go from .res to .s */
506 chat("Reading .res-file");
507 resource_top
= read_resfile(input_name
);
510 chat("Writing .s-file");
511 write_s_file(output_name
, resource_top
);
515 chat("Writing .h-file");
516 write_h_file(header_name
, resource_top
);