]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
msgunfmt must mark system-dependent messages with "#, c-format".
authorBruno Haible <bruno@clisp.org>
Thu, 17 Aug 2006 11:49:47 +0000 (11:49 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:13:54 +0000 (12:13 +0200)
gettext-tools/src/ChangeLog
gettext-tools/src/read-mo.c
gettext-tools/tests/ChangeLog
gettext-tools/tests/Makefile.am

index 2486d2004954828360c0b473825a4baf44d6fe66..410e970628bf81ca356d781965f99ce876e48ff3 100644 (file)
@@ -1,3 +1,10 @@
+2006-08-16  Bruno Haible  <bruno@clisp.org>
+
+       * read-mo.c: Include stdbool.h, stdlib.h, format.h.
+       (read_mo_file): Mark messages with system-dependent segments as
+       "#, c-format" or "#, objc-format", as appropriate.
+       Reported by Egmont Koblinger <egmont@uhulinux.hu>.
+
 2006-08-07  Bruno Haible  <bruno@clisp.org>
 
        * xgettext.c (remember_a_message): Use the position passed as argument
index f0684eb59e06cab9a2fdb899727a3b189b66af3b..a7524c497dbbee1c3e5e2e92db5198735dde84a8 100644 (file)
@@ -1,5 +1,5 @@
 /* Reading binary .mo files.
-   Copyright (C) 1995-1998, 2000-2005 Free Software Foundation, Inc.
+   Copyright (C) 1995-1998, 2000-2006 Free Software Foundation, Inc.
    Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, April 1995.
 
    This program is free software; you can redistribute it and/or modify
 #include "read-mo.h"
 
 #include <errno.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stddef.h>
+#include <stdlib.h>
 #include <string.h>
 
 /* This include file describes the main part of binary .mo format.  */
@@ -36,6 +38,7 @@
 #include "binary-io.h"
 #include "exit.h"
 #include "message.h"
+#include "format.h"
 #include "gettext.h"
 
 #define _(str) gettext (str)
@@ -349,6 +352,7 @@ read_mo_file (message_list_ty *mlp, const char *filename)
              char *msgstr;
              size_t msgstr_len;
              nls_uint32 offset;
+             size_t f;
 
              /* Read the msgctxt and msgid.  */
              offset = get_uint32 (&bf, header.orig_sysdep_tab_offset + i * 4);
@@ -377,6 +381,66 @@ read_mo_file (message_list_ty *mlp, const char *filename)
                                   : NULL),
                                  msgstr, msgstr_len,
                                  &pos);
+
+             /* Only messages with c-format or objc-format annotation are
+                recognized as having system-dependent strings by msgfmt.
+                Which one of the two, we don't know.  We have to guess,
+                assuming that c-format is more probable than objc-format and
+                that the .mo was likely produced by "msgfmt -c".  */
+             for (f = format_c; ; f = format_objc)
+               {
+                 bool valid = true;
+                 struct formatstring_parser *parser = formatstring_parsers[f];
+                 const char *str_end;
+                 const char *str;
+
+                 str_end = msgid + msgid_len;
+                 for (str = msgid; str < str_end; str += strlen (str) + 1)
+                   {
+                     char *invalid_reason = NULL;
+                     void *descr = parser->parse (str, false, &invalid_reason);
+
+                     if (descr != NULL)
+                       parser->free (descr);
+                     else
+                       {
+                         free (invalid_reason);
+                         valid = false;
+                         break;
+                       }
+                   }
+                 if (valid)
+                   {
+                     str_end = msgstr + msgstr_len;
+                     for (str = msgstr; str < str_end; str += strlen (str) + 1)
+                       {
+                         char *invalid_reason = NULL;
+                         void *descr =
+                           parser->parse (str, true, &invalid_reason);
+
+                         if (descr != NULL)
+                           parser->free (descr);
+                         else
+                           {
+                             free (invalid_reason);
+                             valid = false;
+                             break;
+                           }
+                       }
+                   }
+
+                 if (valid)
+                   {
+                     /* Found the most likely among c-format, objc-format.  */
+                     mp->is_format[f] = yes;
+                     break;
+                   }
+
+                 /* Try next f.  */
+                 if (f == format_objc)
+                   break;
+               }
+
              message_list_append (mlp, mp);
            }
          break;
index 278037197a99859e025fa2c51aa345a327e267ae..69e4e468a4c96db28a65f0414fe0e4ae3c2c30eb 100644 (file)
@@ -1,3 +1,8 @@
+2006-08-16  Bruno Haible  <bruno@clisp.org>
+
+       * msgunfmt-2: New file.
+       * Makefile.am (TESTS): Add it.
+
 2006-08-01  Bruno Haible  <bruno@clisp.org>
 
        * msgmerge-compendium-6: New file.
index a1a399f85e2729a17bd5b5e2f4eb842ceb4c452e..ed2121bc2f225424f21a643228de314b6e9e04c2 100644 (file)
@@ -56,7 +56,7 @@ TESTS = gettext-1 gettext-2 gettext-3 gettext-4 gettext-5 gettext-6 gettext-7 \
        msgmerge-compendium-4 msgmerge-compendium-5 msgmerge-compendium-6 \
        msgmerge-properties-1 msgmerge-properties-2 \
        msgmerge-update-1 msgmerge-update-2 msgmerge-update-3 \
-       msgunfmt-1 \
+       msgunfmt-1 msgunfmt-2 \
        msgunfmt-csharp-1 \
        msgunfmt-java-1 \
        msgunfmt-properties-1 \