#! /usr/local/bin/perl if ($ARGV[0]) { if ($ARGV[0] =~ /^([1-9]\d{0,4})\.(0|[1-9]\d{0,2})$/) { $maxrel = 1000 * $1 + $2; } else { die "illegal release number $ARGV[0]"; }; } else { $maxrel = 100000000; }; opendir (DIR, '.'); foreach $f (readdir (DIR)) { next unless -f $f; if ($f =~ /^(.+)\.([1-9]\d{0,4})\.(0|[1-9]\d{0,2})$/) { $name = $1; $rel = 1000 * $2 + $3; if ($rel <= $maxrel) { if ($rel > $target{$name}) { $target{$name} = $rel; }; } elsif (!$target{$name}) { $target{$name} = -1; }; }; }; closedir (DIR); foreach $n (keys %target) { if ($target{$n} > 0) { $t = $n . '.' . int ($target{$n} / 1000) . '.' . ($target{$n} % 1000); }; if (-e $n) { if ($target{$n} < 0) { print "rm $n\n"; unlink ($n); next; }; if (-f $n) { @stat = stat ($n); $inode = $stat[1]; @stat = stat ($t); if ($inode != $stat[1]) { print "rm $n\nln $t $n\n"; unlink ($n); link ($t, $n); }; } else { print "+++++ $n is not a plain file.\n"; next; }; } else { print "ln $t $n\n"; link ($t, $n); }; };