summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2003-11-07 14:04:57 +0000
committerBruno Haible <bruno@clisp.org>2009-06-23 12:11:14 +0200
commit6ac9b4b9f0eb3bfb038beecb3d8967b0d6d51a8a (patch)
tree6acfad8af115a1fdbba938a12dc15fb5824048f5
parent4704157917cee1f11c286a98c42d50e365030c66 (diff)
downloadexternal_gettext-6ac9b4b9f0eb3bfb038beecb3d8967b0d6d51a8a.zip
external_gettext-6ac9b4b9f0eb3bfb038beecb3d8967b0d6d51a8a.tar.gz
external_gettext-6ac9b4b9f0eb3bfb038beecb3d8967b0d6d51a8a.tar.bz2
Handle comments before duplicated msgids in a better way.
-rw-r--r--gettext-tools/src/ChangeLog6
-rw-r--r--gettext-tools/src/xgettext.c131
-rw-r--r--gettext-tools/tests/ChangeLog5
-rw-r--r--gettext-tools/tests/Makefile.am1
-rwxr-xr-xgettext-tools/tests/xgettext-744
5 files changed, 137 insertions, 50 deletions
diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog
index f6b3b34..85bafb4 100644
--- a/gettext-tools/src/ChangeLog
+++ b/gettext-tools/src/ChangeLog
@@ -1,3 +1,9 @@
+2003-11-07 Bruno Haible <bruno@clisp.org>
+
+ * xgettext.c (remember_a_message): Omit the programmer comments of a
+ duplicated msgid only if they are redundant.
+ Reported by Christian Neumair <chris@gnome-de.org>.
+
2003-11-05 Bruno Haible <bruno@clisp.org>
* user-email.sh.in: Renamed from user-email.in. Internationalize, use
diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c
index 0e1eabb..328a157 100644
--- a/gettext-tools/src/xgettext.c
+++ b/gettext-tools/src/xgettext.c
@@ -1748,66 +1748,97 @@ meta information, not the empty string.\n")));
string. */
set_format_flags_from_context (is_format, context, mp->msgid, pos, "msgid");
- /* Ask the lexer for the comments it has seen. Only do this for the
- first instance, otherwise there could be problems; especially if
- the same comment appears before each. */
- if (!mp->comment_dot)
- {
- int j;
- bool add_all_remaining_comments;
+ /* Ask the lexer for the comments it has seen. */
+ {
+ size_t nitems_before;
+ size_t nitems_after;
+ int j;
+ bool add_all_remaining_comments;
- add_all_remaining_comments = add_all_comments;
- for (j = 0; ; ++j)
- {
- const char *s = xgettext_comment (j);
- const char *t;
- if (s == NULL)
- break;
+ nitems_before = (mp->comment_dot != NULL ? mp->comment_dot->nitems : 0);
- CONVERT_STRING (s);
+ add_all_remaining_comments = add_all_comments;
+ for (j = 0; ; ++j)
+ {
+ const char *s = xgettext_comment (j);
+ const char *t;
+ if (s == NULL)
+ break;
- /* To reduce the possibility of unwanted matches we do a two
- step match: the line must contain `xgettext:' and one of
- the possible format description strings. */
- if ((t = strstr (s, "xgettext:")) != NULL)
- {
- bool tmp_fuzzy;
- enum is_format tmp_format[NFORMATS];
- enum is_wrap tmp_wrap;
- bool interesting;
+ CONVERT_STRING (s);
- t += strlen ("xgettext:");
+ /* To reduce the possibility of unwanted matches we do a two
+ step match: the line must contain `xgettext:' and one of
+ the possible format description strings. */
+ if ((t = strstr (s, "xgettext:")) != NULL)
+ {
+ bool tmp_fuzzy;
+ enum is_format tmp_format[NFORMATS];
+ enum is_wrap tmp_wrap;
+ bool interesting;
- po_parse_comment_special (t, &tmp_fuzzy, tmp_format, &tmp_wrap);
+ t += strlen ("xgettext:");
- interesting = false;
- for (i = 0; i < NFORMATS; i++)
- if (tmp_format[i] != undecided)
- {
- is_format[i] = tmp_format[i];
- interesting = true;
- }
- if (tmp_wrap != undecided)
+ po_parse_comment_special (t, &tmp_fuzzy, tmp_format, &tmp_wrap);
+
+ interesting = false;
+ for (i = 0; i < NFORMATS; i++)
+ if (tmp_format[i] != undecided)
{
- do_wrap = tmp_wrap;
+ is_format[i] = tmp_format[i];
interesting = true;
}
+ if (tmp_wrap != undecided)
+ {
+ do_wrap = tmp_wrap;
+ interesting = true;
+ }
- /* If the "xgettext:" marker was followed by an interesting
- keyword, and we updated our is_format/do_wrap variables,
- we don't print the comment as a #. comment. */
- if (interesting)
- continue;
- }
- /* When the comment tag is seen, it drags in not only the line
- which it starts, but all remaining comment lines. */
- if (add_all_remaining_comments
- || (add_all_remaining_comments =
- (comment_tag != NULL
- && strncmp (s, comment_tag, strlen (comment_tag)) == 0)))
- message_comment_dot_append (mp, s);
- }
- }
+ /* If the "xgettext:" marker was followed by an interesting
+ keyword, and we updated our is_format/do_wrap variables,
+ we don't print the comment as a #. comment. */
+ if (interesting)
+ continue;
+ }
+ /* When the comment tag is seen, it drags in not only the line
+ which it starts, but all remaining comment lines. */
+ if (add_all_remaining_comments
+ || (add_all_remaining_comments =
+ (comment_tag != NULL
+ && strncmp (s, comment_tag, strlen (comment_tag)) == 0)))
+ message_comment_dot_append (mp, s);
+ }
+
+ nitems_after = (mp->comment_dot != NULL ? mp->comment_dot->nitems : 0);
+
+ /* Don't add the comments if they are a repetition of the tail of the
+ already present comments. This avoids unneeded duplication if the
+ same message appears several times, each time with the same comment. */
+ if (nitems_before < nitems_after)
+ {
+ size_t added = nitems_after - nitems_before;
+
+ if (added <= nitems_before)
+ {
+ bool repeated = true;
+
+ for (i = 0; i < added; i++)
+ if (strcmp (mp->comment_dot->item[nitems_before - added + i],
+ mp->comment_dot->item[nitems_before + i]) != 0)
+ {
+ repeated = false;
+ break;
+ }
+
+ if (repeated)
+ {
+ for (i = 0; i < added; i++)
+ free ((char *) mp->comment_dot->item[nitems_before + i]);
+ mp->comment_dot->nitems = nitems_before;
+ }
+ }
+ }
+ }
/* If it is not already decided, through programmer comments, whether the
msgid is a format string, examine the msgid. This is a heuristic. */
diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog
index 140c5d6..6dcee57 100644
--- a/gettext-tools/tests/ChangeLog
+++ b/gettext-tools/tests/ChangeLog
@@ -1,3 +1,8 @@
+2003-11-07 Bruno Haible <bruno@clisp.org>
+
+ * xgettext-7: New file.
+ * Makefile.am (TESTS): Add it.
+
2003-11-06 Bruno Haible <bruno@clisp.org>
* msgcat-stringtable-1: Fix expected test result.
diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am
index 8167eb9..bf24bd3 100644
--- a/gettext-tools/tests/Makefile.am
+++ b/gettext-tools/tests/Makefile.am
@@ -56,6 +56,7 @@ TESTS = gettext-1 gettext-2 \
msgunfmt-tcl-1 \
msguniq-1 msguniq-2 msguniq-3 msguniq-4 \
xgettext-1 xgettext-2 xgettext-3 xgettext-4 xgettext-5 xgettext-6 \
+ xgettext-7 \
xgettext-c-1 xgettext-c-2 xgettext-c-3 xgettext-c-4 xgettext-c-5 \
xgettext-c-6 xgettext-c-7 xgettext-c-8 \
xgettext-glade-1 xgettext-glade-2 xgettext-glade-3 \
diff --git a/gettext-tools/tests/xgettext-7 b/gettext-tools/tests/xgettext-7
new file mode 100755
index 0000000..d78b93b
--- /dev/null
+++ b/gettext-tools/tests/xgettext-7
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+# Test of comment extraction in the case of duplicated msgids.
+
+tmpfiles=""
+trap 'rm -fr $tmpfiles' 1 2 3 15
+
+tmpfiles="$tmpfiles xg-test7.c"
+cat <<\EOF > xg-test7.c
+/* first comment */
+/* xgettext: c-format */
+gettext ("abc");
+
+/* first comment */
+/* xgettext: lisp-format */
+gettext ("abc");
+
+/* second comment */
+/* xgettext: python-format */
+gettext ("abc");
+EOF
+
+tmpfiles="$tmpfiles xg-test6.po"
+: ${XGETTEXT=xgettext}
+${XGETTEXT} --omit-header --add-comments -d xg-test7 xg-test7.c
+test $? = 0 || { rm -fr $tmpfiles; exit 1; }
+
+tmpfiles="$tmpfiles xg-test7.ok"
+cat <<\EOF > xg-test7.ok
+#. first comment
+#. second comment
+#: xg-test7.c:3 xg-test7.c:7 xg-test7.c:11
+#, c-format, python-format, lisp-format
+msgid "abc"
+msgstr ""
+EOF
+
+: ${DIFF=diff}
+${DIFF} xg-test7.ok xg-test7.po
+result=$?
+
+rm -fr $tmpfiles
+
+exit $result