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..
43 #include "resource.h" /* For HAVE_WINE_CONSTRUCTOR */
55 char usage
[] = "Usage: wrc [options...] [infile[.rc|.res]]\n"
56 " -a n Alignment of resource (win16 only, default is 4)\n"
57 " -A Auto register resources (only with gcc 2.7 and better)\n"
58 " -b Create a C array from a binary .res file\n"
59 " -c Add 'const' prefix to C constants\n"
60 " -C cp Set the resource's codepage to cp (default is 0)\n"
61 " -d n Set debug level to 'n'\n"
62 " -D id[=val] Define preprocessor identifier id=val\n"
63 " -e Disable recognition of win32 keywords in 16bit compile\n"
64 " -g Add symbols to the global c namespace\n"
65 " -h Also generate a .h file\n"
66 " -H file Same as -h but written to file\n"
67 " -I path Set include search dir to path (multiple -I allowed)\n"
68 " -l lan Set default language to lan (default is neutral {0})\n"
69 " -L Leave case of embedded filenames as is\n"
70 " -n Do not generate .s file\n"
71 " -o file Output to file (default is infile.[res|s|h]\n"
72 " -p prefix Give a prefix for the generated names\n"
73 " -r Create binary .res file (compile only)\n"
74 " -s Add structure with win32/16 (PE/NE) resource directory\n"
75 " -t Generate indirect loadable resource tables\n"
76 " -T Generate only indirect loadable resources tables\n"
77 " -V Print version end exit\n"
78 " -w 16|32 Select win16 or win32 output (default is win32)\n"
79 " -W Enable pedantic warnings\n"
80 "Input is taken from stdin if no sourcefile specified.\n"
81 "Debug level 'n' is a bitmask with following meaning:\n"
82 " * 0x01 Tell which resource is parsed (verbose mode)\n"
83 " * 0x02 Dump internal structures\n"
84 " * 0x04 Create a parser trace (yydebug=1)\n"
85 "The -o option only applies to the final destination file, which is\n"
86 "in case of normal compile a .s file. You must use the '-H header.h'\n"
87 "option to override the header-filename.\n"
88 "If no input filename is given and the output name is not overridden\n"
89 "with -o and/or -H, then the output is written to \"wrc.tab.[sh]\"\n"
92 char version_string
[] = "Wine Resource Compiler Version " WRC_FULLVERSION
"\n"
93 "Copyright 1998,1999 Bertho A. Stultiens\n"
94 " 1994 Martin von Loewis\n";
97 * Default prefix for resource names used in the C array.
98 * Option '-p name' sets it to 'name'
100 #ifdef NEED_UNDERSCORE_PREFIX
101 char *prefix
= "__Resource";
103 char *prefix
= "_Resource";
107 * Set if compiling in 32bit mode (default).
112 * Set when generated C variables should be prefixed with 'const'
117 * Create a .res file from the source and exit (-r option).
122 * debuglevel == DEBUGLEVEL_NONE Don't bother
123 * debuglevel & DEBUGLEVEL_CHAT Say whats done
124 * debuglevel & DEBUGLEVEL_DUMP Dump internal structures
125 * debuglevel & DEBUGLEVEL_TRACE Create parser trace
127 int debuglevel
= DEBUGLEVEL_NONE
;
130 * Recognize win32 keywords if set (-w 32 enforces this),
131 * otherwise set with -e option.
136 * Set when creating C array from .res file (-b option).
141 * Set when an additional C-header is to be created in compile (-h option).
143 int create_header
= 0;
146 * Set when the NE/PE resource directory should be dumped into
152 * Set when all symbols should be added to the global namespace (-g option)
157 * Set when indirect loadable resource tables should be created (-t)
162 * Set when _only_ indirect loadable resource tables should be created (-T)
164 int indirect_only
= 0;
167 * NE segment resource aligment (-a option)
173 * Cleared when the assembly file must be suppressed (-n option)
178 * Language setting for resources (-l option)
180 language_t
*currentlanguage
= NULL
;
183 * The codepage to write in win32 PE resource segment (-C option)
188 * Set when extra warnings should be generated (-W option)
193 * Set when autoregister code must be added to the output (-A option)
195 int auto_register
= 0;
198 * Set when the case of embedded filenames should not be converted
199 * to lower case (-L option)
203 char *output_name
; /* The name given by the -o option */
204 char *input_name
; /* The name given on the command-line */
205 char *header_name
; /* The name given by the -H option */
207 char *cmdline
; /* The entire commandline */
209 resource_t
*resource_top
; /* The top of the parsed resources */
211 int getopt (int argc
, char *const *argv
, const char *optstring
);
213 int main(int argc
,char *argv
[])
224 /* First rebuild the commandline to put in destination */
225 /* Could be done through env[], but not all OS-es support it */
226 cmdlen
= 4; /* for "wrc " */
227 for(i
= 1; i
< argc
; i
++)
228 cmdlen
+= strlen(argv
[i
]) + 1;
229 cmdline
= (char *)xmalloc(cmdlen
);
230 strcpy(cmdline
, "wrc ");
231 for(i
= 1; i
< argc
; i
++)
233 strcat(cmdline
, argv
[i
]);
235 strcat(cmdline
, " ");
238 while((optc
= getopt(argc
, argv
, "a:AbcC:d:D:eghH:I:l:Lno:p:rstTVw:W")) != EOF
)
243 alignment
= atoi(optarg
);
255 codepage
= strtol(optarg
, NULL
, 0);
258 debuglevel
= strtol(optarg
, NULL
, 0);
261 add_cmdline_define(optarg
);
270 header_name
= strdup(optarg
);
276 add_include_path(optarg
);
281 lan
= strtol(optarg
, NULL
, 0);
282 currentlanguage
= new_language(PRIMARYLANGID(lan
), SUBLANGID(lan
));
292 output_name
= strdup(optarg
);
295 #ifdef NEED_UNDERSCORE_PREFIX
296 prefix
= (char *)xmalloc(strlen(optarg
)+2);
298 strcpy(prefix
+1, optarg
);
300 prefix
= xstrdup(optarg
);
316 printf(version_string
);
320 if(!strcmp(optarg
, "16"))
322 else if(!strcmp(optarg
, "32"))
338 fprintf(stderr
, usage
);
342 /* Check the command line options for invalid combinations */
347 warning("Option -e ignored with 32bit compile\n");
356 warning("Option -c ignored with compile to .res\n");
362 warning("Option -[h|H] ignored with compile to .res\n");
368 warning("Option -l ignored with compile to .res\n");
374 warning("Option -L ignored with compile to .res\n");
380 warning("Option -g ignored with compile to .res\n");
386 error("Option -r and -s cannot be used together\n");
391 error("Option -r and -b cannot be used together\n");
395 #if !defined(HAVE_WINE_CONSTRUCTOR)
398 warning("Autoregister code non-operable (HAVE_WINE_CONSTRUCTOR not defined)");
403 /* Set alignment power */
405 for(alignment_pwr
= 0; alignment_pwr
< 10 && a
> 1; alignment_pwr
++)
411 error("Alignment must be between 1 and 1024");
413 if((1 << alignment_pwr
) != alignment
)
415 error("Alignment must be a power of 2");
418 /* Kill io buffering when some kind of debuglevel is enabled */
425 yydebug
= debuglevel
& DEBUGLEVEL_TRACE
? 1 : 0;
427 /* Set the default defined stuff */
428 add_cmdline_define("RC_INVOKED=1");
429 add_cmdline_define("__WRC__=1");
432 add_cmdline_define("__WIN32__=1");
433 add_cmdline_define("__FLAT__=1");
436 /* Check if the user set a language, else set default */
438 currentlanguage
= new_language(0, 0);
440 /* Check for input file on command-line */
443 input_name
= argv
[optind
];
444 yyin
= fopen(input_name
, "rb");
447 error("Could not open %s\n", input_name
);
455 if(binary
&& !input_name
)
457 error("Binary mode requires .res file as input");
462 output_name
= dup_basename(input_name
, binary
? ".res" : ".rc");
463 strcat(output_name
, create_res
? ".res" : ".s");
466 if(!header_name
&& !create_res
)
468 header_name
= dup_basename(input_name
, binary
? ".res" : ".rc");
469 strcat(header_name
, ".h");
474 /* Go from .rc to .res or .s */
475 chat("Starting parse");
483 /* Error during parse */
487 if(debuglevel
& DEBUGLEVEL_DUMP
)
488 dump_resources(resource_top
);
490 /* Convert the internal lists to binary data */
491 resources2res(resource_top
);
495 chat("Writing .res-file");
496 write_resfile(output_name
, resource_top
);
502 chat("Writing .s-file");
503 write_s_file(output_name
, resource_top
);
507 chat("Writing .h-file");
508 write_h_file(header_name
, resource_top
);
515 /* Go from .res to .s */
516 chat("Reading .res-file");
517 resource_top
= read_resfile(input_name
);
520 chat("Writing .s-file");
521 write_s_file(output_name
, resource_top
);
525 chat("Writing .h-file");
526 write_h_file(header_name
, resource_top
);