summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxhe <xw897002528@gmail.com>2017-11-06 23:14:44 +0800
committerrofl0r <retnyg@gmx.net>2017-11-07 15:31:16 +0000
commit17e631c409465faabd8fba5719506038375b48cc (patch)
tree45603f73b7d2756f87ad0adb52b1279245e6878e
parent55a5bcf0bf59118c38c643cf56372cf9e7372f19 (diff)
downloadgettext-tiny-17e631c409465faabd8fba5719506038375b48cc.tar.gz
msgfmt: stub implementation for catalog generation
https://github.com/sabotage-linux/gettext-tiny/issues/16 Generally speaking, `-l XX -d po --language` is passed to msgfmt to generate catalog, only one standalone parameter does not make sense. As catalog has been replaced by gettext, we just stub it. Here're the changes to stub these three arguments: 1. -l is followed by a language idetifier, and for -d, it's followed by a directory, which is used to place the generated catalog files. 2. When passed `--language`, like `msgfmt --tcl...`, we cant specific -o at the same time. Gnu error: `msgfmt: --tcl and --output-file are mutually exclusive .` That means there should be no output on terminal but that `-d` despite the input file. Dont check if they're passed at the same time, as the case using `--language` is very rare, no translators are using it, but autobuild scripts, scripts only pass the correct combination.
-rw-r--r--src/msgfmt.c32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/msgfmt.c b/src/msgfmt.c
index d9db752..4f8c7b6 100644
--- a/src/msgfmt.c
+++ b/src/msgfmt.c
@@ -507,7 +507,8 @@ int main(int argc, char**argv) {
int expect_out_fn = 0;
int expect_in_fn = 1;
int statistics = 0;
- char* dest;
+ char* locale = NULL;
+ char* dest = NULL;
#define A argv[arg]
for(; arg < argc; arg++) {
if(expect_out_fn) {
@@ -536,10 +537,10 @@ int main(int argc, char**argv) {
streq(A+2, "no-hash") ||
streq(A+2, "verbose") ||
strstarts(A+2, "check-accelerators=") ||
- strstarts(A+2, "resource=") ||
- strstarts(A+2, "locale=")
-
+ strstarts(A+2, "resource=")
) {
+ } else if((dest = strstarts(A+2, "locale="))) {
+ locale = dest;
} else if((dest = strstarts(A+2, "output-file="))) {
set_file(1, dest, &out);
} else if(streq(A+2, "statistics")) {
@@ -553,7 +554,6 @@ int main(int argc, char**argv) {
} else if(
streq(A+1, "j") ||
streq(A+1, "r") ||
- streq(A+1, "l") ||
streq(A+1, "P") ||
streq(A+1, "f") ||
streq(A+1, "a") ||
@@ -563,21 +563,35 @@ int main(int argc, char**argv) {
) {
} else if (streq(A+1, "V")) {
version();
- } else if (streq(A+1, "d")) {
- // no support for -d at this time
- fprintf(stderr, "EINVAL\n");
- exit(1);
} else if (streq(A+1, "h")) {
syntax();
} else if (expect_in_fn) {
set_file(0, A, &in);
expect_in_fn = 0;
+ } else if (streq(A+1, "l")) {
+ arg++;
+ locale = A;
+ } else if (streq(A+1, "d")) {
+ arg++;
+ dest = A;
}
} else if (expect_in_fn) {
set_file(0, A, &in);
expect_in_fn = 0;
}
}
+
+ if (locale != NULL && dest != NULL) {
+ int sz = snprintf(NULL, 0, "%s/%s.msg", dest, locale);
+ char msg[sz+1];
+ snprintf(msg, sizeof(msg), "%s/%s.msg", dest, locale);
+ FILE *fp = fopen(msg, "w");
+ if (fp) {
+ fclose(fp);
+ return 0;
+ } else return 1;
+ }
+
if(in == NULL || out == NULL) {
if(!statistics) syntax();
else return 0;