pkgsrc-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/devel/gettext-lib Fix the msgfmt.pl script to deal wit...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/dfb81cc22369
branches:  trunk
changeset: 498346:dfb81cc22369
user:      jmmv <jmmv%pkgsrc.org@localhost>
date:      Sat Aug 20 12:04:09 2005 +0000

description:
Fix the msgfmt.pl script to deal with messages with plurals whose strings
are identical (e.g., msgid == msgid_plural) by ignoring the duplicates.
In fact, this is a rewrite of the script, since I couldn't understand the
old one (ew).

Also change the way we use it to only pull it in the build if the real
msgfmt does not support plurals (i.e., it's older than 0.10.36).

Fixes PR pkg/30596 and PR pkg/30938 (both related to epiphany).
It also fixes the build of evolution-data-server and probably others.

diffstat:

 devel/gettext-lib/builtin.mk  |   27 ++++++--
 devel/gettext/files/msgfmt.pl |  122 ++++++++++++++++++++++++++++++-----------
 2 files changed, 110 insertions(+), 39 deletions(-)

diffs (185 lines):

diff -r b9b5528cfa97 -r dfb81cc22369 devel/gettext-lib/builtin.mk
--- a/devel/gettext-lib/builtin.mk      Sat Aug 20 11:44:09 2005 +0000
+++ b/devel/gettext-lib/builtin.mk      Sat Aug 20 12:04:09 2005 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: builtin.mk,v 1.26 2005/07/16 01:19:08 jlam Exp $
+# $NetBSD: builtin.mk,v 1.27 2005/08/20 12:04:09 jmmv Exp $
 
 BUILTIN_PKG:=  gettext
 
@@ -222,12 +222,25 @@
 buildlink-msgfmt: ${BUILDLINK_DIR}/bin/msgfmt
 
 ${BUILDLINK_DIR}/bin/msgfmt: ${.CURDIR}/../../devel/gettext/files/msgfmt.pl
-       @${MKDIR} ${.TARGET:H}
-       @${CAT} ${.ALLSRC} |                                            \
-        ${SED} -e "s|@PERL@|"${PERL5:Q}"|g"                            \
-               -e "s|@MSGFMT@|"${BUILDLINK_PREFIX.gettext:Q}/bin/msgfmt"|g" \
-               > ${.TARGET}
-       @${CHMOD} +x ${.TARGET}
+       @ver=`${BUILDLINK_PREFIX.gettext:Q}/bin/msgfmt --version |      \
+               ${HEAD} -n 1 | ${CUT} -d ' ' -f 4`;                     \
+       ${MKDIR} ${.TARGET:H};                                          \
+       case $${ver} in                                                 \
+       0.10.[1-3][0-5]|0.[0-9].*)                                      \
+               ${ECHO} "=> Creating msgfmt wrapper to work-around"     \
+                       "plurals";                                      \
+               ${CAT} ${.ALLSRC} |                                     \
+                       ${SED} -e "s|@PERL@|"${PERL5:Q}"|g"             \
+                       -e "s|@MSGFMT@|"${BUILDLINK_PREFIX.gettext:Q}/bin/msgfmt"|g" \
+                       > ${.TARGET};                                   \
+               ;;                                                      \
+       *)                                                              \
+               ${ECHO} "#! ${SH}" >${.TARGET};                         \
+               ${ECHO} "${BUILDLINK_PREFIX.gettext:Q}/bin/msgfmt"      \
+                       '"$$@"' >>${.TARGET};                           \
+               ;;                                                      \
+       esac;                                                           \
+       ${CHMOD} +x ${.TARGET}
 .  endif
 
 .endif # CHECK_BUILTIN.gettext
diff -r b9b5528cfa97 -r dfb81cc22369 devel/gettext/files/msgfmt.pl
--- a/devel/gettext/files/msgfmt.pl     Sat Aug 20 11:44:09 2005 +0000
+++ b/devel/gettext/files/msgfmt.pl     Sat Aug 20 12:04:09 2005 +0000
@@ -1,11 +1,11 @@
 #!@PERL@
 #
-# $NetBSD: msgfmt.pl,v 1.1 2004/04/01 18:33:20 jmmv Exp $
+# $NetBSD: msgfmt.pl,v 1.2 2005/08/20 12:04:09 jmmv Exp $
 #
 # msgfmt.pl - Workaround uses of msgid_plural to work with implementations
 #             that don't support it.
 #
-# Copyright (c) 2004 Julio M. Merino Vidal <jmmv%NetBSD.org@localhost>
+# Copyright (c) 2004, 2005 Julio M. Merino Vidal <jmmv%NetBSD.org@localhost>
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions
@@ -60,38 +60,96 @@
 open INFILE, $file;
 open OUTFILE, ">$file.tmp";
 
-$read_plural = 0;
-$skip = 0;
-@msgid_plural = ();
-
-printf "Fixing plural forms in $file\n";
+printf "Working-around plural forms in $file\n";
 while (<INFILE>) {
-    if (/^msgid_plural/) {
-        $read_plural = 1;
-        s/^msgid_plural[ \t]+"/"/;
-        push @msgid_plural, $_;
-    } elsif ($read_plural && /^msgstr\[0\]/) {
-        $read_plural = 0;
-        s/^msgstr\[0\]/msgstr/;
+    @msgid_singular = ();
+    @msgid_plural = ();
+
+    s/^#~//;
+
+    if (/^msgid[ \t]+(.*)$/) {
+        push @msgid_singular, "$1\n";
+        while (<INFILE>) {
+            if (/^[ \t]*"/) {
+                push @msgid_singular, $_;
+            } else {
+                last;
+            }
+        }
+    }
+
+    if (/^msgid_plural[ \t]+(.*)$/) {
+        push @msgid_plural, "$1\n";
+        while (<INFILE>) {
+            if (/^[ \t]*"/) {
+                push @msgid_plural, $_;
+            } else {
+                last;
+            }
+        }
+    }
+
+    if (/^msgstr[ \t]+(.*)$/) {
+        print OUTFILE "msgid ";
+       foreach $line (@msgid_singular) { print OUTFILE $line; }
+        print OUTFILE "msgstr $1\n";
+        while (<INFILE>) {
+            if (/^[ \t]*"/) {
+                print OUTFILE;
+            } else {
+                last;
+            }
+        }
+    }
+
+    if (/^msgstr\[0\][ \t]+(.*)$/) {
+        print OUTFILE "msgid ";
+       foreach $line (@msgid_singular) { print OUTFILE $line; }
+        print OUTFILE "msgstr $1\n";
+        while (<INFILE>) {
+            if (/^[ \t]*"/) {
+                print OUTFILE;
+            } else {
+                last;
+            }
+        }
+    }
+
+    if (/^msgstr\[1\][ \t]+(.*)$/) {
+       $equal = (@msgid_singular == @msgid_plural);
+       if ($equal) {
+           for ($i = 0; $i < @msgid_singular; $i++) {
+               if (@msgid_singular[$i] ne @msgid_plural[$i]) {
+                   $equal = 0;
+                   last;
+               }
+           }
+       }
+
+        if (! $equal) {
+            print OUTFILE "msgid ";
+           foreach $line (@msgid_plural) { print OUTFILE $line; }
+            print OUTFILE "msgstr $1\n";
+            while (<INFILE>) {
+                if (/^[ \t]*"/) {
+                    print OUTFILE;
+                } else {
+                    last;
+                }
+            }
+        } else {
+           while (<INFILE>) {
+                last if (! /^[ \t]*"/);
+           }
+       }
+    }
+
+    if (/^msgstr\[2\][ \t]+(.*)$/) {
+    }
+
+    if (/^#/ || /^[ \t]*$/) {
         print OUTFILE;
-    } elsif ($read_plural) {
-        push @msgid_plural, $_;
-    } elsif (/^msgstr\[1\]/) {
-        print OUTFILE "\n";
-        print OUTFILE "msgid ";
-        foreach $line (@msgid_plural) {
-            print OUTFILE "$line";
-        }
-        s/^msgstr\[1\]/msgstr/;
-        print OUTFILE;
-        @msgid_plural = ();
-    } elsif (/^msgstr\[2\]/) {
-       $skip = 1;
-    } elsif (/^[ \t]*$/) {
-       $skip = 0;
-        print OUTFILE;
-    } elsif (! $skip) {
-        print OUTFILE;
+       next;
     }
 }
 



Home | Main Index | Thread Index | Old Index