]> git.deb.at Git - deb/packages.git/blobdiff - bin/parse-contents
Update all .po and .pot files
[deb/packages.git] / bin / parse-contents
index 767aad433ff57b01e5bf0c41e5b86994f4aea252..ef5c09ce2b4645395371392f5f3a732dd913cae6 100755 (executable)
@@ -2,8 +2,6 @@
 # Convert Contents.gz files into Sleepycat db files for efficient usage of
 # data
 #
-# $Id$
-#
 # Copyright (C) 2006  Jeroen van Wolffelaar <jeroen@wolffelaar.nl>
 # 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
 
 # You should have received a copy of the GNU General Public License
 # along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 use strict;
+use warnings;
 use lib './lib';
 
 $| = 1;
@@ -83,13 +82,16 @@ for my $suite (@suites) {
                
                open CONT, "zcat $filename|$what"
                    or die $!;
-               while (<CONT>) {last if /^FILE/mo;}
-               open CONT, "zcat $filename|$what" if eof(CONT);
+               while (<CONT>) { last if /^FILE/mo; }
+               if (eof(CONT)) { # no header found
+                   close CONT; # explicit close to reset $.
+                   open CONT, "zcat $filename|$what";
+               }
                while (<CONT>) {
                    my $data = "";
                    my %data = ();
                    chomp;
-                   print "Doing line ".($./1000)."k (out of approx 1.5M)\n" if $. % 250000 == 0;
+                   print "Doing line ".($./1000)."k (out of approx 2.0M)\n" if $. % 250000 == 0;
                    /^(.+?)\s+(\S+)$/o;
                    my ($file, $value) = ($1, $2);
                    $value =~ s#[^,/]+/##og;
@@ -105,9 +107,11 @@ for my $suite (@suites) {
                        $packages_contents_lastword{$_} = "$file\0";
                    }
                    # Searches are case-insensitive
-                   $file =~ tr [A-Z] [a-z];
-                   
-                   print REVERSED (reverse $file)."\0".(join ":$arch\0", @packages).":$arch\n";
+                   (my $nocase = $file) =~ tr [A-Z] [a-z];
+                   my $case = ($nocase eq $file) ? '-' : $file;
+
+                   print REVERSED (reverse $nocase)."\0".$case."\0".
+                       (join ":$arch\0", @packages).":$arch\n";
                }
                close CONT;
                
@@ -132,7 +136,7 @@ for my $suite (@suites) {
            rename("$DBDIR/reverse.tmp", "$DBDIR/reverse_${suite}_${arch}.txt");
        
            rename("$filelist_db.new", $filelist_db);
-           system("ln -sf $filelist_db $DBDIR/filelists_${suite}_all.db") == 0
+           system("ln", "-sf", $filelist_db, "$DBDIR/filelists_${suite}_all.db") == 0
                or die "Oops";
        }
     }
@@ -147,26 +151,33 @@ for my $suite (@suites) {
 
     print "Merging reverse path lists for ${suite}...\n";
 
-    open MERGED, "sort -m $DBDIR/reverse_${suite}_*.txt |"
+    open MERGED, "-|", "sort -m $DBDIR/reverse_${suite}_*.txt"
        or die "Failed to open merged list";
-    open FILENAMES, "> $DBDIR/filenames_$suite.txt.new"
+    open FILENAMES, ">", "$DBDIR/filenames_$suite.txt.new"
        or die "Failed to open filenames list";
     tie my %reverse_path_db, "DB_File", "$DBDIR/reverse_${suite}.db.new",
     O_RDWR|O_CREAT, 0666, $DB_BTREE
        or die "Error creating DB: $!";
 
-    my $lastpath = "";
-    my $lastfile = "";
-    my @matches = ();
+    my $lastpath = my $lastcasepath = my $lastfile = "";
+    my %matches = ();
     while (<MERGED>) {
-       print "Doing line ".($./1000000)."M (out of approx. 16M)\n"
+       print "Doing line ".($./1000000)."M (out of approx. 20M)\n"
            if $. % 1000000 == 0;
        chomp;
        my @line = split /\0/o, $_;
        my $revpath = shift @line;
+       my $casepath = shift @line;
        if ($revpath ne $lastpath) {
            # Wrap: Do useful stuff with this ($lastpath, @matches)
-           $reverse_path_db{$lastpath} = join "\0", @matches if $lastpath ne "";
+           if ($lastpath ne "") {
+               my @matches;
+               while (my ($k, $v) = each %matches) {
+                   push @matches, join("\0", $k, @$v);
+               }
+               $reverse_path_db{$lastpath} = join "\1", @matches;
+               %matches = ();
+           }
            $lastpath =~ s,/.*,,o;
            if ($lastfile ne $lastpath) {
                $lastfile = $lastpath;
@@ -174,15 +185,24 @@ for my $suite (@suites) {
            }
            #
            $lastpath = $revpath;
-           @matches = @line;
+           $lastcasepath = $casepath;
+           $matches{$casepath} = \@line;
            next;
+#      } elsif ($lastcasepath ne "" and $casepath ne $lastcasepath) {
+#          warn reverse($revpath)." has more than one casepath: $casepath $lastcasepath\n";
        }
-       push @matches, @line
-       }
+       push @{$matches{$casepath}}, @line;
+    }
     # Note: do useful stuff here too, for out last entry. Maybe prevent this by
     # adding a fake ultimate entry?
-    $reverse_path_db{$lastpath} = join "\0", @matches;
-    
+    {
+       my @matches;
+       while (my ($k, $v) = each %matches) {
+           push @matches, join("\0", $k, @$v);
+       }
+       $reverse_path_db{$lastpath} = join "\1", @matches;
+    }
+
     untie %reverse_path_db;
     close FILENAMES;
     close MERGED;