From a4fc84bd4d37ca2f1cd73f33cff1af71e065cc23 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 12 Feb 2020 09:03:57 +0100 Subject: [PATCH] wmc: Add --nls-dir option. Signed-off-by: Alexandre Julliard --- tools/wmc/Makefile.in | 4 ++++ tools/wmc/wmc.c | 35 +++++++++++++++++++++++++++++++++++ tools/wmc/wmc.h | 2 ++ tools/wmc/wmc.man.in | 7 ++++--- 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/tools/wmc/Makefile.in b/tools/wmc/Makefile.in index a97da85ea35..660bc940f4b 100644 --- a/tools/wmc/Makefile.in +++ b/tools/wmc/Makefile.in @@ -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) diff --git a/tools/wmc/wmc.c b/tools/wmc/wmc.c index 057b9eef039..3b93fed40e0 100644 --- a/tools/wmc/wmc.c +++ b/tools/wmc/wmc.c @@ -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; diff --git a/tools/wmc/wmc.h b/tools/wmc/wmc.h index 441072b3f72..ae3a1dc1d3a 100644 --- a/tools/wmc/wmc.h +++ b/tools/wmc/wmc.h @@ -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; diff --git a/tools/wmc/wmc.man.in b/tools/wmc/wmc.man.in index 03f99acfee5..123af446a5e 100644 --- a/tools/wmc/wmc.man.in +++ b/tools/wmc/wmc.man.in @@ -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.