Daiki Ueno <u...@gnu.org> writes: >> I really do like the ability to change this via --keyword since it lets us >> avoid having to write the key twice. > > That sounds like a reasonable use-case.
Here is a tentative patch (against the git master, you will need the two previous commits to apply it cleanly). Regards, -- Daiki Ueno
>From f364f4d6ecbd0b0d57a80f606202a4b18ee0189c Mon Sep 17 00:00:00 2001 From: Daiki Ueno <u...@gnu.org> Date: Tue, 28 Oct 2014 16:38:40 +0900 Subject: [PATCH] xgettext: Allow plural extraction from a single argument function * gettext-tools/src/xgettext.c (arglist_parser_remember_literal): Don't ignore plural argument even if ARGNUM1 equals to ARGNUM2. (arglist_parser_done): Make a copy of best_cp->msgid_plural when passing it to remember_a_message_plural, if it equals to best_cp->msgid. * gettext-tools/src/xgettext-12: Test a single argument function. --- gettext-tools/src/ChangeLog | 9 +++++++++ gettext-tools/src/xgettext.c | 11 +++++++++-- gettext-tools/tests/ChangeLog | 5 +++++ gettext-tools/tests/xgettext-12 | 15 ++++++++++++++- 4 files changed, 37 insertions(+), 3 deletions(-) diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index e5ff794..7eaa967 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,5 +1,14 @@ 2014-10-28 Daiki Ueno <u...@gnu.org> + xgettext: Allow plural extraction from a single argument function + * xgettext.c (arglist_parser_remember_literal): Don't ignore + plural argument even if ARGNUM1 equals to ARGNUM2. + (arglist_parser_done): Make a copy of best_cp->msgid_plural when + passing it to remember_a_message_plural, if it equals to + best_cp->msgid. + +2014-10-28 Daiki Ueno <u...@gnu.org> + xgettext: Fix double-free in singular/plural argument extraction After commit 6aa7b7ed in 2009, xgettext assumed that ARGNUM1 and ARGNUM2 of -k are different. That could cause an double-free in diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c index a8f3af6..f75fbb6 100644 --- a/gettext-tools/src/xgettext.c +++ b/gettext-tools/src/xgettext.c @@ -2791,7 +2791,7 @@ arglist_parser_remember_literal (struct arglist_parser *ap, /* Mark msgid as done. */ cp->argnum1 = 0; } - else if (argnum == cp->argnum2) + if (argnum == cp->argnum2) { cp->msgid_plural = string; cp->msgid_plural_escape = type; @@ -3154,7 +3154,14 @@ arglist_parser_done (struct arglist_parser *ap, int argnum) encoding = xgettext_current_source_encoding; xgettext_current_source_encoding = po_charset_utf8; - remember_a_message_plural (mp, best_cp->msgid_plural, + /* If best_cp->msgid_plural equals to best_cp->msgid, + the ownership is already transferred to + remember_a_message above. Make a copy of the + string in that case. */ + remember_a_message_plural (mp, + best_cp->msgid == best_cp->msgid_plural + ? xstrdup (best_cp->msgid_plural) + : best_cp->msgid_plural, msgid_plural_context, &best_cp->msgid_plural_pos, NULL); diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index 8fb2051..d6d6788 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,5 +1,10 @@ 2014-10-28 Daiki Ueno <u...@gnu.org> + xgettext: Allow plural extraction from a single argument function + * xgettext-12: Test a single argument function. + +2014-10-28 Daiki Ueno <u...@gnu.org> + tests: Add test for same ARGNUM1/ARGNUM2 given to xgettext -k * xgettext-12: New file. * Makefile.am (TESTS): Add new test. diff --git a/gettext-tools/tests/xgettext-12 b/gettext-tools/tests/xgettext-12 index 0438ca7..fe76f1a 100755 --- a/gettext-tools/tests/xgettext-12 +++ b/gettext-tools/tests/xgettext-12 @@ -7,10 +7,15 @@ cat <<\EOF > xg-test12.c ngettext ("abc", "abc", 1); ngettext ("abc", "abc", 1); + +/* Hypothetical case: plural extraction from a function + with a single argument. */ +xngettext ("def", 1); +xngettext ("def", 1); EOF : ${XGETTEXT=xgettext} -${XGETTEXT} --omit-header --add-comments -kngettext:1,1 -d xg-test12.tmp xg-test12.c || exit 1 +${XGETTEXT} --omit-header --add-comments -kngettext:1,1 -kxngettext:1,1 -d xg-test12.tmp xg-test12.c || exit 1 LC_ALL=C tr -d '\r' < xg-test12.tmp.po > xg-test12.po || exit 1 cat <<\EOF > xg-test12.ok @@ -19,6 +24,14 @@ msgid "abc" msgid_plural "abc" msgstr[0] "" msgstr[1] "" + +#. Hypothetical case: plural extraction from a function +#. with a single argument. +#: xg-test12.c:6 xg-test12.c:7 +msgid "def" +msgid_plural "def" +msgstr[0] "" +msgstr[1] "" EOF : ${DIFF=diff} -- 1.9.3