From: Bruno Haible Date: Thu, 17 Aug 2006 11:49:47 +0000 (+0000) Subject: msgunfmt must mark system-dependent messages with "#, c-format". X-Git-Tag: 0.16.x-branchpoint~201 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=913ad122fbb3a14a383000f2ec9d3548d9f54949;p=thirdparty%2Fgettext.git msgunfmt must mark system-dependent messages with "#, c-format". --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 2486d2004..410e97062 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,10 @@ +2006-08-16 Bruno Haible + + * 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 . + 2006-08-07 Bruno Haible * xgettext.c (remember_a_message): Use the position passed as argument diff --git a/gettext-tools/src/read-mo.c b/gettext-tools/src/read-mo.c index f0684eb59..a7524c497 100644 --- a/gettext-tools/src/read-mo.c +++ b/gettext-tools/src/read-mo.c @@ -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 , April 1995. This program is free software; you can redistribute it and/or modify @@ -24,8 +24,10 @@ #include "read-mo.h" #include +#include #include #include +#include #include /* 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; diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index 278037197..69e4e468a 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,3 +1,8 @@ +2006-08-16 Bruno Haible + + * msgunfmt-2: New file. + * Makefile.am (TESTS): Add it. + 2006-08-01 Bruno Haible * msgmerge-compendium-6: New file. diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index a1a399f85..ed2121bc2 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -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 \