]> git.donarmstrong.com Git - wannabuild.git/blob - bin/keep-latest
bin/keep-latest
[wannabuild.git] / bin / keep-latest
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use WannaBuild; # for version compare
7
8 if (!@ARGV) {
9         print STDERR "Usage: $0 Packages1 Packages2 ..\n";
10         print STDERR "\n";
11         print STDERR "This perl scripts reads the Packages files given on the command line and\n";
12         print STDERR "outputs a Packages file which contians each package exactly once, using the\n";
13         print STDERR "one with the highest version number.\n";
14         print STDERR "";
15         print STDERR "Since it only looks at Package: and Version:, it works with Sources files\n";
16         print STDERR "as well\n";
17         exit 1;
18 }
19
20 my %version;
21 my %data;
22
23 local($/) = ""; # read in paragraph mode
24 while (<>) {
25         my( $version, $name );
26         /^Package:\s*(\S+)$/mi and $name = $1;
27         /^Version:\s*(\S+)$/mi and $version = $1;
28         if (!defined $name or !defined $version) {
29                 warn "Stanza without Package or Version\n";
30                 next;
31         }
32
33         if ((!exists $version{$name}) or version_less($version{name},$version)) {
34                 $version{$name} = $version;
35                 $data{$name} = $_;
36         }
37 }
38
39 foreach (values %data) {
40         s/\n*$/\n\n/;# always one empty line to separate stanzas
41         print;
42 }
43