2 * Wine Message Compiler main program
4 * Copyright 2000 Bertho A. Stultiens (BS)
20 "Usage: wmc [options...] [inputfile.mc]\n"
21 " -B x Set output byte-order x={n[ative], l[ittle], b[ig]}\n"
22 " (default is n[ative] which equals "
23 #ifdef WORDS_BIGENDIAN
29 " -c Set 'custom-bit' in values\n"
30 " -d Use decimal values in output\n"
31 " -D Set debug flag\n"
33 " -H file Write headerfile to file (default is inputfile.h)\n"
34 " -i Inline messagetable(s)\n"
35 " -o file Output to file (default is inputfile.rc)\n"
36 " -u Inputfile is in unicode\n"
37 " -U Output unicode messagetable(s)\n"
38 " -v Show supported codepages and languages\n"
39 " -V Print version end exit\n"
40 " -W Enable pedantic warnings\n"
41 "Input is taken from stdin if no inputfile is specified.\n"
42 "Byteorder of unicode input is based upon the first couple of\n"
43 "bytes read, which should be 0x0000..0x00ff.\n"
46 static char version_string
[] =
47 "Wine Message Compiler Version " WMC_FULLVERSION
"\n"
48 "Copyright 2000 Bertho A. Stultiens\n"
52 * The output byte-order of resources (set with -B)
54 int byteorder
= WMC_BO_NATIVE
;
57 * Custom bit (bit 29) in output values must be set (-c option)
62 * Output decimal values (-d option)
67 * Enable pedantic warnings; check arg references (-W option)
72 * Unicode input (-u option)
77 * Unicode output (-U option)
82 * Inline the messagetables (don't write *.bin files; -i option)
87 * Debugging flag (-D option)
91 char *output_name
= NULL
; /* The name given by the -o option */
92 char *input_name
= NULL
; /* The name given on the command-line */
93 char *header_name
= NULL
; /* The name given by the -H option */
95 int line_number
= 1; /* The current line */
96 int char_number
= 1; /* The current char pos within the line */
98 char *cmdline
; /* The entire commandline */
99 time_t now
; /* The time of start of wmc */
101 int getopt (int argc
, char *const *argv
, const char *optstring
);
102 static void segvhandler(int sig
);
104 int main(int argc
,char *argv
[])
114 signal(SIGSEGV
, segvhandler
);
118 /* First rebuild the commandline to put in destination */
119 /* Could be done through env[], but not all OS-es support it */
120 cmdlen
= 4; /* for "wmc " */
121 for(i
= 1; i
< argc
; i
++)
122 cmdlen
+= strlen(argv
[i
]) + 1;
123 cmdline
= (char *)xmalloc(cmdlen
);
124 strcpy(cmdline
, "wmc ");
125 for(i
= 1; i
< argc
; i
++)
127 strcat(cmdline
, argv
[i
]);
129 strcat(cmdline
, " ");
132 while((optc
= getopt(argc
, argv
, "B:cdDhH:io:p:uUvVW")) != EOF
)
141 byteorder
= WMC_BO_NATIVE
;
145 byteorder
= WMC_BO_LITTLE
;
149 byteorder
= WMC_BO_BIG
;
152 fprintf(stderr
, "Byteordering must be n[ative], l[ittle] or b[ig]\n");
170 header_name
= xstrdup(optarg
);
176 output_name
= xstrdup(optarg
);
190 printf(version_string
);
204 fprintf(stderr
, "%s", usage
);
215 /* Check for input file on command-line */
218 input_name
= argv
[optind
];
221 /* Generate appropriate outfile names */
224 output_name
= dup_basename(input_name
, ".mc");
225 strcat(output_name
, ".rc");
230 header_name
= dup_basename(input_name
, ".mc");
231 strcat(header_name
, ".h");
236 if(!(yyin
= fopen(input_name
, "rb")))
237 error("Could not open %s for input\n", input_name
);
249 /* Error during parse */
253 write_h_file(header_name
);
254 write_rc_file(output_name
);
261 static void segvhandler(int sig
)
263 fprintf(stderr
, "\n%s:%d: Oops, segment violation\n", input_name
, line_number
);