diff options
author | xhe <xw897002528@gmail.com> | 2017-11-07 13:45:03 +0800 |
---|---|---|
committer | rofl0r <retnyg@gmx.net> | 2017-11-07 15:34:39 +0000 |
commit | 71043f79c540f8223417be69961aad5f19bcf1cd (patch) | |
tree | e95e9f2fad5315932dbd555d90fe40d0d1975e76 | |
parent | 8e6da23cefad907611e0ce76c3d25e5e79fa3d68 (diff) | |
download | gettext-tiny-71043f79c540f8223417be69961aad5f19bcf1cd.tar.gz |
msgfmt: dont generate file when input is empty
GNU one does not generate useless 'only HEADER' file when input is
empty, which is cleaner and reasonable in my view. I decided to do the
same thing.
-rw-r--r-- | src/msgfmt.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/msgfmt.c b/src/msgfmt.c index cb1e23b..51710ab 100644 --- a/src/msgfmt.c +++ b/src/msgfmt.c @@ -406,6 +406,11 @@ int process(FILE *in, FILE *out) { for(d.pass = pass_first; d.pass <= pass_second; d.pass++) { if(d.pass == pass_second) { // start of second pass: + // ensure we dont output when there's no strings at all + if(d.num[pe_msgid] == 0) { + return 1; + } + // check that data gathered in first pass is consistent if((d.num[pe_msgstr] < d.num[pe_msgid]) || (d.num[pe_msgstr] > (d.num[pe_msgid] + d.num[pe_plural] * (p->info.nplurals - 1)))) { // one should actually abort here, @@ -548,6 +553,7 @@ int main(int argc, char**argv) { } else if(streq(A + 1, "o")) { arg++; + dest = A; set_file(1, A, &out); } else if( streq(A+1, "j") || @@ -591,6 +597,7 @@ int main(int argc, char**argv) { } if(out == NULL) { + dest = "messages.mo"; set_file(1, "messages.mo", &out); } @@ -601,5 +608,9 @@ int main(int argc, char**argv) { fflush(in); fflush(out); if(in != stdin) fclose(in); if(out != stdout) fclose(out); + + if (ret == 1) { + return remove(dest); + } return ret; } |