2000-06-13 06:34:41 +02:00
|
|
|
/*
|
|
|
|
* Wine Message Compiler main program
|
|
|
|
*
|
|
|
|
* Copyright 2000 Bertho A. Stultiens (BS)
|
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-06-13 06:34:41 +02:00
|
|
|
*/
|
2001-10-14 18:18:52 +02:00
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2000-06-13 06:34:41 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include "wmc.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "write.h"
|
|
|
|
|
2007-08-30 10:18:13 +02:00
|
|
|
static const char usage[] =
|
2000-06-13 06:34:41 +02:00
|
|
|
"Usage: wmc [options...] [inputfile.mc]\n"
|
2013-10-04 19:38:46 +02:00
|
|
|
" -B x Set output byte-order x={n[ative], l[ittle], b[ig]}\n"
|
|
|
|
" (default is n[ative] which equals "
|
2000-06-13 06:34:41 +02:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
"big"
|
|
|
|
#else
|
|
|
|
"little"
|
|
|
|
#endif
|
|
|
|
"-endian)\n"
|
2013-10-04 19:38:46 +02:00
|
|
|
" -c Set 'custom-bit' in values\n"
|
|
|
|
" -d Use decimal values in output\n"
|
|
|
|
" -D Set debug flag\n"
|
|
|
|
" -h, --help Print this message\n"
|
|
|
|
" -H FILE Write header file to FILE (default is inputfile.h)\n"
|
|
|
|
" -i Inline messagetable(s)\n"
|
2020-02-12 09:03:57 +01:00
|
|
|
" --nls-dir=DIR Directory containing the NLS codepage mappings\n"
|
2013-10-04 19:38:46 +02:00
|
|
|
" -o, --output=FILE Output to FILE (default is infile.rc)\n"
|
|
|
|
" -O, --output-format=FORMAT The output format (`rc', `res', or `pot')\n"
|
|
|
|
" -P, --po-dir=DIR Directory containing po files for translations\n"
|
|
|
|
" -u Input file is in unicode\n"
|
|
|
|
" -U Output unicode messagetable(s)\n"
|
|
|
|
" -v Show supported codepages and languages\n"
|
|
|
|
" -V, --version Print version end exit\n"
|
|
|
|
" -W, --pedantic Enable pedantic warnings\n"
|
2000-06-13 06:34:41 +02:00
|
|
|
"Input is taken from stdin if no inputfile is specified.\n"
|
|
|
|
"Byteorder of unicode input is based upon the first couple of\n"
|
|
|
|
"bytes read, which should be 0x0000..0x00ff.\n"
|
|
|
|
;
|
|
|
|
|
2007-08-30 10:18:13 +02:00
|
|
|
static const char version_string[] =
|
2005-10-10 12:43:41 +02:00
|
|
|
"Wine Message Compiler version " PACKAGE_VERSION "\n"
|
2000-06-13 06:34:41 +02:00
|
|
|
"Copyright 2000 Bertho A. Stultiens\n"
|
|
|
|
;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The output byte-order of resources (set with -B)
|
|
|
|
*/
|
|
|
|
int byteorder = WMC_BO_NATIVE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Custom bit (bit 29) in output values must be set (-c option)
|
|
|
|
*/
|
|
|
|
int custombit = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Output decimal values (-d option)
|
|
|
|
*/
|
|
|
|
int decimal = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable pedantic warnings; check arg references (-W option)
|
|
|
|
*/
|
|
|
|
int pedantic = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unicode input (-u option)
|
|
|
|
*/
|
|
|
|
int unicodein = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Inline the messagetables (don't write *.bin files; -i option)
|
|
|
|
*/
|
|
|
|
int rcinline = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Debugging flag (-D option)
|
|
|
|
*/
|
2010-01-21 12:57:27 +01:00
|
|
|
static int dodebug = 0;
|
2000-06-13 06:34:41 +02:00
|
|
|
|
2011-01-24 20:12:54 +01:00
|
|
|
static char *po_dir;
|
|
|
|
|
2000-06-13 06:34:41 +02:00
|
|
|
char *output_name = NULL; /* The name given by the -o option */
|
2021-10-05 11:52:21 +02:00
|
|
|
const char *input_name = NULL; /* The name given on the command-line */
|
2000-06-13 06:34:41 +02:00
|
|
|
char *header_name = NULL; /* The name given by the -H option */
|
|
|
|
|
2020-02-12 09:03:57 +01:00
|
|
|
const char *nlsdirs[3] = { NULL, NLSDIR, NULL };
|
|
|
|
|
2000-06-13 06:34:41 +02:00
|
|
|
int line_number = 1; /* The current line */
|
|
|
|
int char_number = 1; /* The current char pos within the line */
|
|
|
|
|
|
|
|
char *cmdline; /* The entire commandline */
|
|
|
|
time_t now; /* The time of start of wmc */
|
|
|
|
|
2006-09-12 09:05:15 +02:00
|
|
|
int mcy_debug;
|
2006-09-09 11:26:24 +02:00
|
|
|
|
2010-01-21 12:57:27 +01:00
|
|
|
FILE *yyin;
|
|
|
|
|
2011-01-18 16:55:37 +01:00
|
|
|
static enum
|
|
|
|
{
|
2020-02-06 15:05:48 +01:00
|
|
|
FORMAT_UNKNOWN,
|
2011-01-18 16:55:37 +01:00
|
|
|
FORMAT_RC,
|
2011-01-24 20:09:53 +01:00
|
|
|
FORMAT_RES,
|
|
|
|
FORMAT_POT
|
2011-01-18 16:55:37 +01:00
|
|
|
} output_format;
|
|
|
|
|
2020-02-12 09:03:57 +01:00
|
|
|
enum long_options_values
|
|
|
|
{
|
|
|
|
LONG_OPT_NLS_DIR = 1,
|
|
|
|
};
|
|
|
|
|
2013-10-04 19:38:46 +02:00
|
|
|
static const char short_options[] = "B:cdDhH:io:O:P:uUvVW";
|
2021-10-05 11:52:21 +02:00
|
|
|
static const struct long_option long_options[] =
|
2013-10-04 19:38:46 +02:00
|
|
|
{
|
2021-10-05 11:52:21 +02:00
|
|
|
{ "help", 0, 'h' },
|
|
|
|
{ "nls-dir", 1, LONG_OPT_NLS_DIR },
|
|
|
|
{ "output", 1, 'o' },
|
|
|
|
{ "output-format", 1, 'O' },
|
|
|
|
{ "pedantic", 0, 'W' },
|
|
|
|
{ "po-dir", 1, 'P' },
|
|
|
|
{ "version", 0, 'v' },
|
|
|
|
{ NULL }
|
2013-10-04 19:38:46 +02:00
|
|
|
};
|
|
|
|
|
2000-06-13 06:34:41 +02:00
|
|
|
static void segvhandler(int sig);
|
|
|
|
|
2006-05-27 13:23:24 +02:00
|
|
|
static void cleanup_files(void)
|
|
|
|
{
|
|
|
|
if (output_name) unlink( output_name );
|
|
|
|
if (header_name) unlink( header_name );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void exit_on_signal( int sig )
|
|
|
|
{
|
|
|
|
exit(1); /* this will call the atexit functions */
|
|
|
|
}
|
|
|
|
|
2020-02-12 09:03:57 +01:00
|
|
|
static void init_argv0_dir( const char *argv0 )
|
|
|
|
{
|
|
|
|
#ifndef _WIN32
|
2021-09-29 11:13:36 +02:00
|
|
|
char *dir;
|
2020-02-12 09:03:57 +01:00
|
|
|
|
|
|
|
#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
|
|
|
|
dir = realpath( "/proc/self/exe", NULL );
|
|
|
|
#elif defined (__FreeBSD__) || defined(__DragonFly__)
|
|
|
|
dir = realpath( "/proc/curproc/file", NULL );
|
|
|
|
#else
|
|
|
|
dir = realpath( argv0, NULL );
|
|
|
|
#endif
|
|
|
|
if (!dir) return;
|
2021-09-29 11:13:36 +02:00
|
|
|
dir = get_dirname( dir );
|
2020-02-12 09:03:57 +01:00
|
|
|
if (strendswith( dir, "/tools/wmc" )) nlsdirs[0] = strmake( "%s/../../nls", dir );
|
|
|
|
else nlsdirs[0] = strmake( "%s/%s", dir, BIN_TO_NLSDIR );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-10-05 11:52:21 +02:00
|
|
|
static void option_callback( int optc, char *optarg )
|
|
|
|
{
|
|
|
|
switch(optc)
|
|
|
|
{
|
|
|
|
case 'B':
|
|
|
|
switch(optarg[0])
|
|
|
|
{
|
|
|
|
case 'n':
|
|
|
|
case 'N':
|
|
|
|
byteorder = WMC_BO_NATIVE;
|
|
|
|
break;
|
|
|
|
case 'l':
|
|
|
|
case 'L':
|
|
|
|
byteorder = WMC_BO_LITTLE;
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
case 'B':
|
|
|
|
byteorder = WMC_BO_BIG;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Byteordering must be n[ative], l[ittle] or b[ig]\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
custombit = 1;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
decimal = 1;
|
|
|
|
break;
|
|
|
|
case 'D':
|
|
|
|
dodebug = 1;
|
|
|
|
break;
|
|
|
|
case 'h':
|
|
|
|
printf("%s", usage);
|
|
|
|
exit(0);
|
|
|
|
/* No return */
|
|
|
|
case 'H':
|
|
|
|
header_name = xstrdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
rcinline = 1;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
output_name = xstrdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'O':
|
|
|
|
if (!strcmp( optarg, "rc" )) output_format = FORMAT_RC;
|
|
|
|
else if (!strcmp( optarg, "res" )) output_format = FORMAT_RES;
|
|
|
|
else if (!strcmp( optarg, "pot" )) output_format = FORMAT_POT;
|
|
|
|
else error("Output format must be rc or res\n" );
|
|
|
|
break;
|
|
|
|
case 'P':
|
|
|
|
po_dir = xstrdup( optarg );
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
unicodein = 1;
|
|
|
|
break;
|
|
|
|
case 'U': /* ignored for backwards compatibility */
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
show_languages();
|
|
|
|
exit(0);
|
|
|
|
/* No return */
|
|
|
|
case 'V':
|
|
|
|
printf(version_string);
|
|
|
|
exit(0);
|
|
|
|
/* No return */
|
|
|
|
case 'W':
|
|
|
|
pedantic = 1;
|
|
|
|
break;
|
|
|
|
case LONG_OPT_NLS_DIR:
|
|
|
|
nlsdirs[0] = xstrdup( optarg );
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
fprintf(stderr, "wmc: %s\n\n%s", optarg, usage);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-06-13 06:34:41 +02:00
|
|
|
int main(int argc,char *argv[])
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
int cmdlen;
|
2021-10-05 11:52:21 +02:00
|
|
|
struct strarray files;
|
2000-06-13 06:34:41 +02:00
|
|
|
|
2006-05-27 13:23:24 +02:00
|
|
|
atexit( cleanup_files );
|
2000-06-13 06:34:41 +02:00
|
|
|
signal(SIGSEGV, segvhandler);
|
2006-05-27 13:23:24 +02:00
|
|
|
signal( SIGTERM, exit_on_signal );
|
|
|
|
signal( SIGINT, exit_on_signal );
|
|
|
|
#ifdef SIGHUP
|
|
|
|
signal( SIGHUP, exit_on_signal );
|
|
|
|
#endif
|
2020-02-12 09:03:57 +01:00
|
|
|
init_argv0_dir( argv[0] );
|
2000-06-13 06:34:41 +02:00
|
|
|
|
|
|
|
/* First rebuild the commandline to put in destination */
|
|
|
|
/* Could be done through env[], but not all OS-es support it */
|
2011-11-12 09:04:51 +01:00
|
|
|
cmdlen = 5; /* for "wmc " and \0 */
|
2000-06-13 06:34:41 +02:00
|
|
|
for(i = 1; i < argc; i++)
|
|
|
|
cmdlen += strlen(argv[i]) + 1;
|
2006-08-26 21:35:32 +02:00
|
|
|
cmdline = xmalloc(cmdlen);
|
2000-06-13 06:34:41 +02:00
|
|
|
strcpy(cmdline, "wmc ");
|
|
|
|
for(i = 1; i < argc; i++)
|
|
|
|
{
|
|
|
|
strcat(cmdline, argv[i]);
|
|
|
|
if(i < argc-1)
|
|
|
|
strcat(cmdline, " ");
|
|
|
|
}
|
|
|
|
|
2021-10-05 11:52:21 +02:00
|
|
|
files = parse_options( argc, argv, short_options, long_options, 0, option_callback );
|
2000-06-13 06:34:41 +02:00
|
|
|
|
2006-09-12 09:05:15 +02:00
|
|
|
mcy_debug = dodebug;
|
2000-06-13 06:34:41 +02:00
|
|
|
if(dodebug)
|
|
|
|
{
|
2010-01-21 12:57:27 +01:00
|
|
|
setbuf(stdout, NULL);
|
|
|
|
setbuf(stderr, NULL);
|
2000-06-13 06:34:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for input file on command-line */
|
2021-10-05 11:52:21 +02:00
|
|
|
if (files.count) input_name = files.str[0];
|
2000-06-13 06:34:41 +02:00
|
|
|
|
2020-02-06 15:05:48 +01:00
|
|
|
/* Guess output format */
|
|
|
|
if (output_format == FORMAT_UNKNOWN)
|
|
|
|
{
|
|
|
|
if (output_name && strendswith( output_name, ".res" )) output_format = FORMAT_RES;
|
|
|
|
else if (output_name && strendswith( output_name, ".pot" )) output_format = FORMAT_POT;
|
|
|
|
else output_format = FORMAT_RC;
|
|
|
|
}
|
|
|
|
|
2000-06-13 06:34:41 +02:00
|
|
|
/* Generate appropriate outfile names */
|
|
|
|
if(!output_name)
|
|
|
|
{
|
2021-09-29 11:13:36 +02:00
|
|
|
const char *name = input_name ? get_basename(input_name) : "wmc.tab";
|
|
|
|
output_name = replace_extension( name, ".mc", ".rc" );
|
2000-06-13 06:34:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!header_name)
|
|
|
|
{
|
2021-09-29 11:13:36 +02:00
|
|
|
const char *name = input_name ? get_basename(input_name) : "wmc.tab";
|
|
|
|
header_name = replace_extension( name, ".mc", ".h" );
|
2000-06-13 06:34:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(input_name)
|
|
|
|
{
|
|
|
|
if(!(yyin = fopen(input_name, "rb")))
|
|
|
|
error("Could not open %s for input\n", input_name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
yyin = stdin;
|
|
|
|
|
2006-09-12 09:05:15 +02:00
|
|
|
ret = mcy_parse();
|
2000-06-13 06:34:41 +02:00
|
|
|
|
|
|
|
if(input_name)
|
|
|
|
fclose(yyin);
|
|
|
|
|
|
|
|
if(ret)
|
|
|
|
{
|
|
|
|
/* Error during parse */
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-01-18 16:55:37 +01:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
byte_swapped = (byteorder == WMC_BO_LITTLE);
|
|
|
|
#else
|
|
|
|
byte_swapped = (byteorder == WMC_BO_BIG);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (output_format)
|
|
|
|
{
|
|
|
|
case FORMAT_RC:
|
|
|
|
write_h_file(header_name);
|
|
|
|
write_rc_file(output_name);
|
|
|
|
if(!rcinline)
|
2000-06-13 06:34:41 +02:00
|
|
|
write_bin_files();
|
2011-01-18 16:55:37 +01:00
|
|
|
break;
|
|
|
|
case FORMAT_RES:
|
2013-10-04 19:38:46 +02:00
|
|
|
add_translations( po_dir );
|
2011-01-18 16:55:37 +01:00
|
|
|
write_res_file( output_name );
|
|
|
|
break;
|
2011-01-24 20:09:53 +01:00
|
|
|
case FORMAT_POT:
|
|
|
|
write_pot_file( output_name );
|
|
|
|
break;
|
2020-02-06 15:05:48 +01:00
|
|
|
default:
|
|
|
|
break;
|
2011-01-18 16:55:37 +01:00
|
|
|
}
|
2006-05-27 13:23:24 +02:00
|
|
|
output_name = NULL;
|
|
|
|
header_name = NULL;
|
2000-06-13 06:34:41 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void segvhandler(int sig)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "\n%s:%d: Oops, segment violation\n", input_name, line_number);
|
|
|
|
fflush(stdout);
|
|
|
|
fflush(stderr);
|
|
|
|
abort();
|
|
|
|
}
|