2 * Wine Message Compiler main program
4 * Copyright 2000 Bertho A. Stultiens (BS)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
34 static const char usage[] =
35 "Usage: wmc [options...] [inputfile.mc]\n"
36 " -B x Set output byte-order x={n[ative], l[ittle], b[ig]}\n"
37 " (default is n[ative] which equals "
38 #ifdef WORDS_BIGENDIAN
44 " -c Set 'custom-bit' in values\n"
45 " -d Use decimal values in output\n"
46 " -D Set debug flag\n"
48 " -H file Write headerfile to file (default is inputfile.h)\n"
49 " -i Inline messagetable(s)\n"
50 " -o file Output to file (default is inputfile.rc)\n"
51 " -O fmt Set output format (rc, res)\n"
52 " -u Inputfile is in unicode\n"
53 " -U Output unicode messagetable(s)\n"
54 " -v Show supported codepages and languages\n"
55 " -V Print version end exit\n"
56 " -W Enable pedantic warnings\n"
57 "Input is taken from stdin if no inputfile is specified.\n"
58 "Byteorder of unicode input is based upon the first couple of\n"
59 "bytes read, which should be 0x0000..0x00ff.\n"
62 static const char version_string[] =
63 "Wine Message Compiler version " PACKAGE_VERSION "\n"
64 "Copyright 2000 Bertho A. Stultiens\n"
68 * The output byte-order of resources (set with -B)
70 int byteorder = WMC_BO_NATIVE;
73 * Custom bit (bit 29) in output values must be set (-c option)
78 * Output decimal values (-d option)
83 * Enable pedantic warnings; check arg references (-W option)
88 * Unicode input (-u option)
93 * Unicode output (-U option)
98 * Inline the messagetables (don't write *.bin files; -i option)
103 * Debugging flag (-D option)
105 static int dodebug = 0;
107 char *output_name = NULL; /* The name given by the -o option */
108 char *input_name = NULL; /* The name given on the command-line */
109 char *header_name = NULL; /* The name given by the -H option */
111 int line_number = 1; /* The current line */
112 int char_number = 1; /* The current char pos within the line */
114 char *cmdline; /* The entire commandline */
115 time_t now; /* The time of start of wmc */
127 int getopt (int argc, char *const *argv, const char *optstring);
128 static void segvhandler(int sig);
130 static void cleanup_files(void)
132 if (output_name) unlink( output_name );
133 if (header_name) unlink( header_name );
136 static void exit_on_signal( int sig )
138 exit(1); /* this will call the atexit functions */
141 int main(int argc,char *argv[])
151 atexit( cleanup_files );
152 signal(SIGSEGV, segvhandler);
153 signal( SIGTERM, exit_on_signal );
154 signal( SIGINT, exit_on_signal );
156 signal( SIGHUP, exit_on_signal );
161 /* First rebuild the commandline to put in destination */
162 /* Could be done through env[], but not all OS-es support it */
163 cmdlen = 4; /* for "wmc " */
164 for(i = 1; i < argc; i++)
165 cmdlen += strlen(argv[i]) + 1;
166 cmdline = xmalloc(cmdlen);
167 strcpy(cmdline, "wmc ");
168 for(i = 1; i < argc; i++)
170 strcat(cmdline, argv[i]);
172 strcat(cmdline, " ");
175 while((optc = getopt(argc, argv, "B:cdDhH:io:O:p:uUvVW")) != EOF)
184 byteorder = WMC_BO_NATIVE;
188 byteorder = WMC_BO_LITTLE;
192 byteorder = WMC_BO_BIG;
195 fprintf(stderr, "Byteordering must be n[ative], l[ittle] or b[ig]\n");
213 header_name = xstrdup(optarg);
219 output_name = xstrdup(optarg);
222 if (!strcmp( optarg, "rc" )) output_format = FORMAT_RC;
223 else if (!strcmp( optarg, "res" )) output_format = FORMAT_RES;
226 fprintf(stderr, "Output format must be rc or res\n" );
242 printf(version_string);
256 fprintf(stderr, "%s", usage);
263 setbuf(stdout, NULL);
264 setbuf(stderr, NULL);
267 /* Check for input file on command-line */
270 input_name = argv[optind];
273 /* Generate appropriate outfile names */
276 output_name = dup_basename(input_name, ".mc");
277 strcat(output_name, ".rc");
282 header_name = dup_basename(input_name, ".mc");
283 strcat(header_name, ".h");
288 if(!(yyin = fopen(input_name, "rb")))
289 error("Could not open %s for input\n", input_name);
301 /* Error during parse */
305 #ifdef WORDS_BIGENDIAN
306 byte_swapped = (byteorder == WMC_BO_LITTLE);
308 byte_swapped = (byteorder == WMC_BO_BIG);
311 switch (output_format)
314 write_h_file(header_name);
315 write_rc_file(output_name);
320 write_res_file( output_name );
328 static void segvhandler(int sig)
330 fprintf(stderr, "\n%s:%d: Oops, segment violation\n", input_name, line_number);