From: Bruno Haible Date: Fri, 26 Sep 2008 15:59:35 +0000 (+0000) Subject: When sorting, disambiguate when the msgids are the same. X-Git-Tag: v0.18~334 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3fad0720ff774f2adcfe6d0da02881aba04e7657;p=thirdparty%2Fgettext.git When sorting, disambiguate when the msgids are the same. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index b380d2f14..399b9caf1 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,9 +1,15 @@ -2009-09-15 Bruno Haible +2008-09-26 Bruno Haible + + * write-catalog.c (cmp_by_msgid, cmp_by_filepos): Compare the msgctxt + fields if the msgid fields are the same. + Reported by Rainer Tammer . + +2008-09-15 Bruno Haible * Makefile.am (msg*_DEPENDENCIES, xgettext_DEPENDENCIES, recode_sr_latin_DEPENDENCIES): New variables. -2009-09-15 Bruno Haible +2008-09-15 Bruno Haible * msgl-fsearch.h: Include stdbool.h. (message_fuzzy_index_search): Add 'heuristic' argument. @@ -27,7 +33,7 @@ for a lazily allocated hashed index. * Makefile.am (msgcmp_SOURCES): Add msgl-fsearch.c. -2009-09-15 Bruno Haible +2008-09-15 Bruno Haible * msgcmp.c (use_fuzzy_matching): New variable. (long_options): Add option -N/--no-fuzzy-matching. diff --git a/gettext-tools/src/write-catalog.c b/gettext-tools/src/write-catalog.c index 635f8c136..2f6c8377d 100644 --- a/gettext-tools/src/write-catalog.c +++ b/gettext-tools/src/write-catalog.c @@ -1,5 +1,5 @@ /* GNU gettext - internationalization aids - Copyright (C) 1995-1998, 2000-2007 Free Software Foundation, Inc. + Copyright (C) 1995-1998, 2000-2008 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -332,10 +332,22 @@ cmp_by_msgid (const void *va, const void *vb) { const message_ty *a = *(const message_ty **) va; const message_ty *b = *(const message_ty **) vb; - /* Because msgids normally contain only ASCII characters, it is OK to - sort them as if we were in the C locale. And strcoll() in the C locale - is the same as strcmp(). */ - return strcmp (a->msgid, b->msgid); + + /* Because msgids normally contain only ASCII characters or are UTF-8 + encoded, it is OK to sort them as if we were in a C.UTF-8 locale. And + strcoll() in a C.UTF-8 locale is the same as strcmp(). */ + int cmp = strcmp (a->msgid, b->msgid); + if (cmp != 0) + return cmp; + + /* If the msgids are equal, disambiguate by comparing the contexts. */ + if (a->msgctxt == b->msgctxt) + return 0; + if (a->msgctxt == NULL) + return -1; + if (b->msgctxt == NULL) + return 1; + return strcmp (a->msgctxt, b->msgctxt); } @@ -420,10 +432,21 @@ cmp_by_filepos (const void *va, const void *vb) return cmp; /* If they are equal, compare on the msgid strings. */ - /* Because msgids normally contain only ASCII characters, it is OK to - sort them as if we were in the C locale. And strcoll() in the C locale - is the same as strcmp(). */ - return strcmp (a->msgid, b->msgid); + /* Because msgids normally contain only ASCII characters or are UTF-8 + encoded, it is OK to sort them as if we were in a C.UTF-8 locale. And + strcoll() in a C.UTF-8 locale is the same as strcmp(). */ + cmp = strcmp (a->msgid, b->msgid); + if (cmp != 0) + return cmp; + + /* If the msgids are equal, disambiguate by comparing the contexts. */ + if (a->msgctxt == b->msgctxt) + return 0; + if (a->msgctxt == NULL) + return -1; + if (b->msgctxt == NULL) + return 1; + return strcmp (a->msgctxt, b->msgctxt); }