From: Bruno Haible Date: Thu, 1 Nov 2001 11:08:16 +0000 (+0000) Subject: Make the msgcat-2 test work. X-Git-Tag: v0.11~352 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3c83b2b0bbdb68e0dfa4a42f490ab7ab3afcebf1;p=thirdparty%2Fgettext.git Make the msgcat-2 test work. --- diff --git a/src/ChangeLog b/src/ChangeLog index 95ecd76cd..3ba32e8a3 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2001-11-01 Bruno Haible + + * msgl-equal.h (string_list_equal): New declaration. + * msgl-equal.c (string_list_equal): Export function. + * message.h (struct altstr): New fields 'comment', 'comment_dot'. + * msgl-cat.c: Include msgl-equal.h. + (catenate_msgdomain_list): If all alternative comments are equal, + use one copy of them, instead of concatenating them. Likewise for dot + comments. + * Makefile.am (libgettextsrc_la_SOURCES): Add msgl-equal.c. + (msgmerge_SOURCES): Remove msgl-equal.c. + 2001-10-31 Bruno Haible * Makefile.am (noinst_HEADERS): Add read-java.h, write-java.h, diff --git a/src/Makefile.am b/src/Makefile.am index 188dfd80d..1c01150b7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -71,8 +71,8 @@ format-ycp.c # libgettextsrc contains all code that is needed by at least two programs. libgettextsrc_la_SOURCES = \ -$(COMMON_SOURCE) read-po.c write-po.c msgl-ascii.c msgl-iconv.c msgl-cat.c \ -msgl-english.c file-list.c msgl-charset.c po-time.c \ +$(COMMON_SOURCE) read-po.c write-po.c msgl-ascii.c msgl-iconv.c msgl-equal.c \ +msgl-cat.c msgl-english.c file-list.c msgl-charset.c po-time.c \ $(FORMAT_SOURCE) # Source dependencies. @@ -80,7 +80,7 @@ gettext_SOURCES = gettext.c ngettext_SOURCES = ngettext.c msgcmp_SOURCES = msgcmp.c msgfmt_SOURCES = msgfmt.c write-mo.c write-java.c plural.c plural-eval.c -msgmerge_SOURCES = msgmerge.c msgl-equal.c +msgmerge_SOURCES = msgmerge.c msgunfmt_SOURCES = msgunfmt.c read-mo.c read-java.c xgettext_SOURCES = xgettext.c x-c.c x-po.c x-java.l x-ycp.c x-rst.c msgattrib_SOURCES = msgattrib.c diff --git a/src/message.h b/src/message.h index 432cd17ee..8634507de 100644 --- a/src/message.h +++ b/src/message.h @@ -125,6 +125,8 @@ struct message_ty const char *msgstr; size_t msgstr_len; const char *msgstr_end; + string_list_ty *comment; + string_list_ty *comment_dot; char *id; } *alternative; diff --git a/src/msgl-cat.c b/src/msgl-cat.c index 44622e834..7d8f950fa 100644 --- a/src/msgl-cat.c +++ b/src/msgl-cat.c @@ -33,6 +33,7 @@ #include "read-po.h" #include "po-charset.h" #include "msgl-ascii.h" +#include "msgl-equal.h" #include "msgl-iconv.h" #include "xmalloc.h" #include "strstr.h" @@ -530,22 +531,11 @@ To select a different output encoding, use the --to-code option.\n\ tmp->alternative[i].msgstr_len = mp->msgstr_len; tmp->alternative[i].msgstr_end = tmp->alternative[i].msgstr + tmp->alternative[i].msgstr_len; + tmp->alternative[i].comment = mp->comment; + tmp->alternative[i].comment_dot = mp->comment_dot; tmp->alternative[i].id = id; tmp->alternative_count = i + 1; - if (mp->comment) - { - message_comment_append (tmp, id); - for (i = 0; i < mp->comment->nitems; i++) - message_comment_append (tmp, mp->comment->item[i]); - } - if (mp->comment_dot) - { - message_comment_dot_append (tmp, id); - for (i = 0; i < mp->comment_dot->nitems; i++) - message_comment_dot_append (tmp, - mp->comment_dot->item[i]); - } for (i = 0; i < mp->filepos_count; i++) message_comment_filepos (tmp, mp->filepos[i].file_name, mp->filepos[i].line_number); @@ -655,6 +645,61 @@ To select a different output encoding, use the --to-code option.\n\ tmp->is_fuzzy = true; } + + /* Test whether all alternative comments are equal. */ + for (i = 0; i < tmp->alternative_count; i++) + if (tmp->alternative[i].comment == NULL + || !string_list_equal (tmp->alternative[i].comment, + first->comment)) + break; + + if (i == tmp->alternative_count) + /* All alternatives are equal. */ + tmp->comment = first->comment; + else + /* Concatenate the alternative comments into a single one, + separated by markers. */ + for (i = 0; i < tmp->alternative_count; i++) + { + string_list_ty *slp = tmp->alternative[i].comment; + + if (slp != NULL) + { + size_t l; + + message_comment_append (tmp, tmp->alternative[i].id); + for (l = 0; l < slp->nitems; l++) + message_comment_append (tmp, slp->item[i]); + } + } + + /* Test whether all alternative dot comments are equal. */ + for (i = 0; i < tmp->alternative_count; i++) + if (tmp->alternative[i].comment_dot == NULL + || !string_list_equal (tmp->alternative[i].comment_dot, + first->comment_dot)) + break; + + if (i == tmp->alternative_count) + /* All alternatives are equal. */ + tmp->comment_dot = first->comment_dot; + else + /* Concatenate the alternative dot comments into a single one, + separated by markers. */ + for (i = 0; i < tmp->alternative_count; i++) + { + string_list_ty *slp = tmp->alternative[i].comment_dot; + + if (slp != NULL) + { + size_t l; + + message_comment_dot_append (tmp, + tmp->alternative[i].id); + for (l = 0; l < slp->nitems; l++) + message_comment_dot_append (tmp, slp->item[i]); + } + } } } } diff --git a/src/msgl-equal.c b/src/msgl-equal.c index 4c827ec51..f66b561a1 100644 --- a/src/msgl-equal.c +++ b/src/msgl-equal.c @@ -29,8 +29,6 @@ function argument counts despite of K&R C function definition syntax. */ static inline bool pos_equal PARAMS ((const lex_pos_ty *pos1, const lex_pos_ty *pos2)); -static inline bool string_list_equal PARAMS ((const string_list_ty *slp1, - const string_list_ty *slp2)); static inline bool msgdomain_equal PARAMS ((const msgdomain_ty *mdp1, const msgdomain_ty *mdp2)); @@ -45,7 +43,7 @@ pos_equal (pos1, pos2) && pos1->line_number == pos2->line_number); } -static inline bool +bool string_list_equal (slp1, slp2) const string_list_ty *slp1; const string_list_ty *slp2; diff --git a/src/msgl-equal.h b/src/msgl-equal.h index 9953f9746..c707289c0 100644 --- a/src/msgl-equal.h +++ b/src/msgl-equal.h @@ -23,6 +23,10 @@ #include +extern bool + string_list_equal PARAMS ((const string_list_ty *slp1, + const string_list_ty *slp2)); + /* Test whether the written representation of two messages / message lists would be the same. */