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"
37 static const char usage
[] =
38 "Usage: wmc [options...] [inputfile.mc]\n"
39 " -B x Set output byte-order x={n[ative], l[ittle], b[ig]}\n"
40 " (default is n[ative] which equals "
41 #ifdef WORDS_BIGENDIAN
47 " -c Set 'custom-bit' in values\n"
48 " -d Use decimal values in output\n"
49 " -D Set debug flag\n"
50 " -h, --help Print this message\n"
51 " -H FILE Write header file to FILE (default is inputfile.h)\n"
52 " -i Inline messagetable(s)\n"
53 " -o, --output=FILE Output to FILE (default is infile.rc)\n"
54 " -O, --output-format=FORMAT The output format (`rc', `res', or `pot')\n"
55 " -P, --po-dir=DIR Directory containing po files for translations\n"
56 " -u Input file is in unicode\n"
57 " -U Output unicode messagetable(s)\n"
58 " -v Show supported codepages and languages\n"
59 " -V, --version Print version end exit\n"
60 " -W, --pedantic Enable pedantic warnings\n"
61 "Input is taken from stdin if no inputfile is specified.\n"
62 "Byteorder of unicode input is based upon the first couple of\n"
63 "bytes read, which should be 0x0000..0x00ff.\n"
66 static const char version_string
[] =
67 "Wine Message Compiler version " PACKAGE_VERSION
"\n"
68 "Copyright 2000 Bertho A. Stultiens\n"
72 * The output byte-order of resources (set with -B)
74 int byteorder
= WMC_BO_NATIVE
;
77 * Custom bit (bit 29) in output values must be set (-c option)
82 * Output decimal values (-d option)
87 * Enable pedantic warnings; check arg references (-W option)
92 * Unicode input (-u option)
97 * Unicode output (-U option)
102 * Inline the messagetables (don't write *.bin files; -i option)
107 * Debugging flag (-D option)
109 static int dodebug
= 0;
113 char *output_name
= NULL
; /* The name given by the -o option */
114 char *input_name
= NULL
; /* The name given on the command-line */
115 char *header_name
= NULL
; /* The name given by the -H option */
117 int line_number
= 1; /* The current line */
118 int char_number
= 1; /* The current char pos within the line */
120 char *cmdline
; /* The entire commandline */
121 time_t now
; /* The time of start of wmc */
134 static const char short_options
[] = "B:cdDhH:io:O:P:uUvVW";
135 static const struct option long_options
[] =
137 { "help", 0, NULL
, 'h' },
138 { "output", 1, NULL
, 'o' },
139 { "output-format", 1, NULL
, 'O' },
140 { "pedantic", 0, NULL
, 'W' },
141 { "po-dir", 1, NULL
, 'P' },
142 { "version", 0, NULL
, 'v' }
145 static void segvhandler(int sig
);
147 static void cleanup_files(void)
149 if (output_name
) unlink( output_name
);
150 if (header_name
) unlink( header_name
);
153 static void exit_on_signal( int sig
)
155 exit(1); /* this will call the atexit functions */
158 int main(int argc
,char *argv
[])
169 atexit( cleanup_files
);
170 signal(SIGSEGV
, segvhandler
);
171 signal( SIGTERM
, exit_on_signal
);
172 signal( SIGINT
, exit_on_signal
);
174 signal( SIGHUP
, exit_on_signal
);
177 /* First rebuild the commandline to put in destination */
178 /* Could be done through env[], but not all OS-es support it */
179 cmdlen
= 5; /* for "wmc " and \0 */
180 for(i
= 1; i
< argc
; i
++)
181 cmdlen
+= strlen(argv
[i
]) + 1;
182 cmdline
= xmalloc(cmdlen
);
183 strcpy(cmdline
, "wmc ");
184 for(i
= 1; i
< argc
; i
++)
186 strcat(cmdline
, argv
[i
]);
188 strcat(cmdline
, " ");
191 while((optc
= getopt_long(argc
, argv
, short_options
, long_options
, &opti
)) != EOF
)
200 byteorder
= WMC_BO_NATIVE
;
204 byteorder
= WMC_BO_LITTLE
;
208 byteorder
= WMC_BO_BIG
;
211 fprintf(stderr
, "Byteordering must be n[ative], l[ittle] or b[ig]\n");
229 header_name
= xstrdup(optarg
);
235 output_name
= xstrdup(optarg
);
238 if (!strcmp( optarg
, "rc" )) output_format
= FORMAT_RC
;
239 else if (!strcmp( optarg
, "res" )) output_format
= FORMAT_RES
;
240 else if (!strcmp( optarg
, "pot" )) output_format
= FORMAT_POT
;
243 fprintf(stderr
, "Output format must be rc or res\n" );
248 po_dir
= xstrdup( optarg
);
262 printf(version_string
);
276 fprintf(stderr
, "%s", usage
);
283 setbuf(stdout
, NULL
);
284 setbuf(stderr
, NULL
);
287 /* Check for input file on command-line */
290 input_name
= argv
[optind
];
293 /* Generate appropriate outfile names */
296 output_name
= dup_basename(input_name
, ".mc");
297 strcat(output_name
, ".rc");
302 header_name
= dup_basename(input_name
, ".mc");
303 strcat(header_name
, ".h");
308 if(!(yyin
= fopen(input_name
, "rb")))
309 error("Could not open %s for input\n", input_name
);
321 /* Error during parse */
325 #ifdef WORDS_BIGENDIAN
326 byte_swapped
= (byteorder
== WMC_BO_LITTLE
);
328 byte_swapped
= (byteorder
== WMC_BO_BIG
);
331 switch (output_format
)
334 write_h_file(header_name
);
335 write_rc_file(output_name
);
340 add_translations( po_dir
);
341 write_res_file( output_name
);
344 write_pot_file( output_name
);
352 static void segvhandler(int sig
)
354 fprintf(stderr
, "\n%s:%d: Oops, segment violation\n", input_name
, line_number
);