wmc: Add --nls-dir option.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-02-12 09:03:57 +01:00
parent 64ff68c884
commit a4fc84bd4d
4 changed files with 45 additions and 3 deletions

View File

@ -11,6 +11,10 @@ C_SRCS = \
BISON_SRCS = mcy.y
wmc_EXTRADEFS = \
-DNLSDIR="\"${nlsdir}\"" \
-DBIN_TO_NLSDIR=\"`$(MAKEDEP) -R ${bindir} ${nlsdir}`\"
EXTRALIBS = $(GETTEXTPO_LIBS)
INSTALL_DEV = $(PROGRAMS)

View File

@ -50,6 +50,7 @@ static const char usage[] =
" -h, --help Print this message\n"
" -H FILE Write header file to FILE (default is inputfile.h)\n"
" -i Inline messagetable(s)\n"
" --nls-dir=DIR Directory containing the NLS codepage mappings\n"
" -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"
@ -109,6 +110,8 @@ char *output_name = NULL; /* The name given by the -o option */
char *input_name = NULL; /* The name given on the command-line */
char *header_name = NULL; /* The name given by the -H option */
const char *nlsdirs[3] = { NULL, NLSDIR, NULL };
int line_number = 1; /* The current line */
int char_number = 1; /* The current char pos within the line */
@ -127,10 +130,16 @@ static enum
FORMAT_POT
} output_format;
enum long_options_values
{
LONG_OPT_NLS_DIR = 1,
};
static const char short_options[] = "B:cdDhH:io:O:P:uUvVW";
static const struct option long_options[] =
{
{ "help", 0, NULL, 'h' },
{ "nls-dir", 1, NULL, LONG_OPT_NLS_DIR },
{ "output", 1, NULL, 'o' },
{ "output-format", 1, NULL, 'O' },
{ "pedantic", 0, NULL, 'W' },
@ -151,6 +160,28 @@ static void exit_on_signal( int sig )
exit(1); /* this will call the atexit functions */
}
static void init_argv0_dir( const char *argv0 )
{
#ifndef _WIN32
char *p, *dir;
#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;
if (!(p = strrchr( dir, '/' ))) return;
if (p == dir) p++;
*p = 0;
if (strendswith( dir, "/tools/wmc" )) nlsdirs[0] = strmake( "%s/../../nls", dir );
else nlsdirs[0] = strmake( "%s/%s", dir, BIN_TO_NLSDIR );
free( dir );
#endif
}
int main(int argc,char *argv[])
{
int optc;
@ -167,6 +198,7 @@ int main(int argc,char *argv[])
#ifdef SIGHUP
signal( SIGHUP, exit_on_signal );
#endif
init_argv0_dir( argv[0] );
/* First rebuild the commandline to put in destination */
/* Could be done through env[], but not all OS-es support it */
@ -257,6 +289,9 @@ int main(int argc,char *argv[])
case 'W':
pedantic = 1;
break;
case LONG_OPT_NLS_DIR:
nlsdirs[0] = xstrdup( optarg );
break;
default:
lose++;
break;

View File

@ -49,6 +49,8 @@ extern char *input_name;
extern char *header_name;
extern char *cmdline;
extern const char *nlsdirs[];
extern int line_number;
extern int char_number;

View File

@ -45,6 +45,10 @@ Inline messagetable(s). This option skips the generation of all \fI.bin\fR files
and writes all output into the \fI.rc\fR file. This encoding is parsable with
wrc(1).
.TP
.BI \-\-nls-dir= directory
Specify the directory to search for the NLS files containing the
codepage mapping tables.
.TP
.BR \-o ,\ \-\-output =\fIfile
Output to \fIfile\fR. Default is \fIinputfile.rc\fR.
.TP
@ -94,9 +98,6 @@ The message compiler should be able to have multiple input files and combine
them into one output file. This would enable the splitting of languages into
separate files.
.PP
Unicode detection of the input is suboptimal, to say the least. It should
recognize byte order marks (BOM) and decide what to do.
.PP
Decimal output is completely lacking. Don't know whether it should be
implemented because it is a, well, non-informative format change. It is
recognized on the commandline for some form of compatibility.