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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34 "Usage: wmc [options...] [inputfile.mc]\n"
35 " -B x Set output byte-order x={n[ative], l[ittle], b[ig]}\n"
36 " (default is n[ative] which equals "
37 #ifdef WORDS_BIGENDIAN
43 " -c Set 'custom-bit' in values\n"
44 " -d Use decimal values in output\n"
45 " -D Set debug flag\n"
47 " -H file Write headerfile to file (default is inputfile.h)\n"
48 " -i Inline messagetable(s)\n"
49 " -o file Output to file (default is inputfile.rc)\n"
50 " -u Inputfile is in unicode\n"
51 " -U Output unicode messagetable(s)\n"
52 " -v Show supported codepages and languages\n"
53 " -V Print version end exit\n"
54 " -W Enable pedantic warnings\n"
55 "Input is taken from stdin if no inputfile is specified.\n"
56 "Byteorder of unicode input is based upon the first couple of\n"
57 "bytes read, which should be 0x0000..0x00ff.\n"
60 static char version_string[] =
61 "Wine Message Compiler Version " WMC_FULLVERSION "\n"
62 "Copyright 2000 Bertho A. Stultiens\n"
66 * The output byte-order of resources (set with -B)
68 int byteorder = WMC_BO_NATIVE;
71 * Custom bit (bit 29) in output values must be set (-c option)
76 * Output decimal values (-d option)
81 * Enable pedantic warnings; check arg references (-W option)
86 * Unicode input (-u option)
91 * Unicode output (-U option)
96 * Inline the messagetables (don't write *.bin files; -i option)
101 * Debugging flag (-D option)
105 char *output_name = NULL; /* The name given by the -o option */
106 char *input_name = NULL; /* The name given on the command-line */
107 char *header_name = NULL; /* The name given by the -H option */
109 int line_number = 1; /* The current line */
110 int char_number = 1; /* The current char pos within the line */
112 char *cmdline; /* The entire commandline */
113 time_t now; /* The time of start of wmc */
115 int getopt (int argc, char *const *argv, const char *optstring);
116 static void segvhandler(int sig);
118 int main(int argc,char *argv[])
128 signal(SIGSEGV, segvhandler);
132 /* First rebuild the commandline to put in destination */
133 /* Could be done through env[], but not all OS-es support it */
134 cmdlen = 4; /* for "wmc " */
135 for(i = 1; i < argc; i++)
136 cmdlen += strlen(argv[i]) + 1;
137 cmdline = (char *)xmalloc(cmdlen);
138 strcpy(cmdline, "wmc ");
139 for(i = 1; i < argc; i++)
141 strcat(cmdline, argv[i]);
143 strcat(cmdline, " ");
146 while((optc = getopt(argc, argv, "B:cdDhH:io:p:uUvVW")) != EOF)
155 byteorder = WMC_BO_NATIVE;
159 byteorder = WMC_BO_LITTLE;
163 byteorder = WMC_BO_BIG;
166 fprintf(stderr, "Byteordering must be n[ative], l[ittle] or b[ig]\n");
184 header_name = xstrdup(optarg);
190 output_name = xstrdup(optarg);
204 printf(version_string);
218 fprintf(stderr, "%s", usage);
229 /* Check for input file on command-line */
232 input_name = argv[optind];
235 /* Generate appropriate outfile names */
238 output_name = dup_basename(input_name, ".mc");
239 strcat(output_name, ".rc");
244 header_name = dup_basename(input_name, ".mc");
245 strcat(header_name, ".h");
250 if(!(yyin = fopen(input_name, "rb")))
251 error("Could not open %s for input\n", input_name);
263 /* Error during parse */
267 write_h_file(header_name);
268 write_rc_file(output_name);
275 static void segvhandler(int sig)
277 fprintf(stderr, "\n%s:%d: Oops, segment violation\n", input_name, line_number);