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
[])
167 atexit( cleanup_files
);
168 signal(SIGSEGV
, segvhandler
);
169 signal( SIGTERM
, exit_on_signal
);
170 signal( SIGINT
, exit_on_signal
);
172 signal( SIGHUP
, exit_on_signal
);
175 /* First rebuild the commandline to put in destination */
176 /* Could be done through env[], but not all OS-es support it */
177 cmdlen
= 5; /* for "wmc " and \0 */
178 for(i
= 1; i
< argc
; i
++)
179 cmdlen
+= strlen(argv
[i
]) + 1;
180 cmdline
= xmalloc(cmdlen
);
181 strcpy(cmdline
, "wmc ");
182 for(i
= 1; i
< argc
; i
++)
184 strcat(cmdline
, argv
[i
]);
186 strcat(cmdline
, " ");
189 while((optc
= getopt_long(argc
, argv
, short_options
, long_options
, &opti
)) != EOF
)
198 byteorder
= WMC_BO_NATIVE
;
202 byteorder
= WMC_BO_LITTLE
;
206 byteorder
= WMC_BO_BIG
;
209 fprintf(stderr
, "Byteordering must be n[ative], l[ittle] or b[ig]\n");
227 header_name
= xstrdup(optarg
);
233 output_name
= xstrdup(optarg
);
236 if (!strcmp( optarg
, "rc" )) output_format
= FORMAT_RC
;
237 else if (!strcmp( optarg
, "res" )) output_format
= FORMAT_RES
;
238 else if (!strcmp( optarg
, "pot" )) output_format
= FORMAT_POT
;
241 fprintf(stderr
, "Output format must be rc or res\n" );
246 po_dir
= xstrdup( optarg
);
260 printf(version_string
);
274 fprintf(stderr
, "%s", usage
);
281 setbuf(stdout
, NULL
);
282 setbuf(stderr
, NULL
);
285 /* Check for input file on command-line */
288 input_name
= argv
[optind
];
291 /* Generate appropriate outfile names */
294 output_name
= dup_basename(input_name
, ".mc");
295 strcat(output_name
, ".rc");
300 header_name
= dup_basename(input_name
, ".mc");
301 strcat(header_name
, ".h");
306 if(!(yyin
= fopen(input_name
, "rb")))
307 error("Could not open %s for input\n", input_name
);
319 /* Error during parse */
323 #ifdef WORDS_BIGENDIAN
324 byte_swapped
= (byteorder
== WMC_BO_LITTLE
);
326 byte_swapped
= (byteorder
== WMC_BO_BIG
);
329 switch (output_format
)
332 write_h_file(header_name
);
333 write_rc_file(output_name
);
338 add_translations( po_dir
);
339 write_res_file( output_name
);
342 write_pot_file( output_name
);
350 static void segvhandler(int sig
)
352 fprintf(stderr
, "\n%s:%d: Oops, segment violation\n", input_name
, line_number
);