bug-gettext
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gettext] Bug#682580: xgettext: fails to properly replace some p


From: Daiki Ueno
Subject: Re: [bug-gettext] Bug#682580: xgettext: fails to properly replace some placeholders in output .pot (PACKAGE, YEAR, C. HOLDER) (fwd)
Date: Tue, 21 Jul 2015 14:03:09 +0900
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

Francesco Poli <address@hidden> writes:

> I am frankly having a hard time in seeing why the placeholder PACKAGE
> should be replaced in one occurrence, but not in the other.
> And in figuring out why the placeholder THE PACKAGE'S COPYRIGHT HOLDER
> should be replaced, while the YEAR placeholder should be left untouched
> in the *same* copyright notice.

I think it would be nice to fix them so those occurrences be replaced as
well.

By the way, after looking into the history and the documentation more
closely, I realized that my argument on copyright notice was pointless.
I'm sorry.  I'm now in favor of adding support for multiple copyright
holders, like the attached patch, which makes xgettext allow multiple
--copyright-holder options.

It is not straightforward to support multiple copyright holders in
po/Makevars, but it might be sufficient to supply it as part of
XGETTEXT_OPTIONS in combination with COPYRIGHT_HOLDER.

Regards,
-- 
Daiki Ueno
>From 7aba166af10a4b64aa07d7f5afc91bdd239beef2 Mon Sep 17 00:00:00 2001
From: Daiki Ueno <address@hidden>
Date: Tue, 21 Jul 2015 13:51:31 +0900
Subject: [PATCH] xgettext: Allow multiple copyright holders

* gettext-tools/src/xgettext.c (default_copyright_holder): New constant,
renamed from copyright_holder.
(copyright_holder): Define as a variable.
(main): Allow multiple --copyright-holder options.
(construct_header): Support multiple --copyright-holder options.
---
 gettext-tools/src/ChangeLog  |  8 +++++
 gettext-tools/src/xgettext.c | 70 ++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 72 insertions(+), 6 deletions(-)

diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog
index 6685505..74dd518 100644
--- a/gettext-tools/src/ChangeLog
+++ b/gettext-tools/src/ChangeLog
@@ -1,3 +1,11 @@
+2015-07-21  Daiki Ueno  <address@hidden>
+
+       * xgettext.c (default_copyright_holder): New constant, renamed
+       from copyright_holder.
+       (copyright_holder): Define as a variable.
+       (main): Allow multiple --copyright-holder options.
+       (construct_header): Support multiple --copyright-holder options.
+
 2015-07-10  Daiki Ueno  <address@hidden>
 
        * gettext 0.19.5 released.
diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c
index 9f5d300..8e303c7 100644
--- a/gettext-tools/src/xgettext.c
+++ b/gettext-tools/src/xgettext.c
@@ -124,7 +124,8 @@ message_list_ty *exclude;
 static int force_po;
 
 /* Copyright holder of the output file and the translations.  */
-static const char *copyright_holder = "THE PACKAGE'S COPYRIGHT HOLDER";
+static const char *default_copyright_holder = "THE PACKAGE'S COPYRIGHT HOLDER";
+static char *copyright_holder = NULL;
 
 /* Package name.  */
 static const char *package_name = NULL;
@@ -540,11 +541,19 @@ main (int argc, char *argv[])
         break;
 
       case CHAR_MAX + 1:        /* --copyright-holder */
-        copyright_holder = optarg;
+        if (copyright_holder == NULL)
+          copyright_holder = xstrdup (optarg);
+        else
+          {
+            size_t total_len = strlen (copyright_holder) + 2 + strlen (optarg);
+            copyright_holder = xrealloc (copyright_holder, total_len);
+            strcat (copyright_holder, "\n");
+            strcat (copyright_holder, optarg);
+          }
         break;
 
       case CHAR_MAX + 2:        /* --foreign-user */
-        copyright_holder = "";
+        copyright_holder = xstrdup ("");
         break;
 
       case CHAR_MAX + 3:        /* --from-code */
@@ -3559,13 +3568,61 @@ Content-Transfer-Encoding: 8bit\n",
 
   mp = message_alloc (NULL, "", NULL, msgstr, strlen (msgstr) + 1, &pos);
 
+  if (copyright_holder == NULL)
+    copyright_holder = xstrdup (default_copyright_holder);
+
   if (copyright_holder[0] != '\0')
-    comment = xasprintf ("\
+    {
+      size_t copyright_comment_len;
+      char *copyright_comment;
+      const char *p;
+      char *q;
+      size_t count = 1;
+
+      p = copyright_holder;
+      while (*p != '\0')
+        {
+          p = strchr (p, '\n');
+          if (p == NULL)
+            break;
+          count++;
+          p++;
+        }
+
+      copyright_comment_len =
+        strlen (copyright_holder) + strlen ("Copyright (C) YEAR \n") * count;
+      copyright_comment = XNMALLOC (copyright_comment_len, char);
+
+      p = copyright_holder;
+      q = copyright_comment;
+      while (*p != '\0')
+        {
+          char *newline = strchr (p, '\n');
+
+          q = stpcpy (q, "Copyright (C) YEAR ");
+          if (newline != NULL)
+            {
+              *newline = '\0';
+              q = stpcpy (q, p);
+              q = stpcpy (q, "\n");
+              p = newline + 1;
+            }
+          else
+            {
+              q = stpcpy (q, p);
+              q = stpcpy (q, "\n");
+              break;
+            }
+        }
+
+      comment = xasprintf ("\
 SOME DESCRIPTIVE TITLE.\n\
-Copyright (C) YEAR %s\n\
+%s\
 This file is distributed under the same license as the PACKAGE package.\n\
 FIRST AUTHOR <address@hidden>, YEAR.\n",
-                         copyright_holder);
+                         copyright_comment);
+      free (copyright_comment);
+    }
   else
     comment = xstrdup ("\
 SOME DESCRIPTIVE TITLE.\n\
@@ -3573,6 +3630,7 @@ This file is put in the public domain.\n\
 FIRST AUTHOR <address@hidden>, YEAR.\n");
   message_comment_append (mp, comment);
   free (comment);
+  free (copyright_holder);
 
   mp->is_fuzzy = true;
 
-- 
2.4.3


reply via email to

[Prev in Thread] Current Thread [Next in Thread]