#!/usr/bin/perl --
-$version= '1.0.11'; # This line modified by Makefile
-$admindir= "/var/lib/dpkg"; # This line modified by Makefile
-$dpkglibdir= "../utils"; # This line modified by Makefile
+use strict;
+use warnings;
+
+my $version = '1.0.11'; # This line modified by Makefile
+my $admindir = "/var/lib/dpkg"; # This line modified by Makefile
+my $dpkglibdir = "../utils"; # This line modified by Makefile
($0) = $0 =~ m:.*/(.+):;
push (@INC, $dpkglibdir);
require 'dpkg-gettext.pl';
textdomain("dpkg");
-$enoent=`$dpkglibdir/enoent` || die sprintf(_g("Cannot get ENOENT value from %s: %s"), "$dpkglibdir/enoent", $!);
+my $enoent = `$dpkglibdir/enoent` || die sprintf(_g("Cannot get ENOENT value from %s: %s"), "$dpkglibdir/enoent", $!);
sub ENOENT { $enoent; }
sub version {
"), $0);
}
-$testmode= 0;
-$dorename= 0;
-$verbose= 1;
-$mode='';
+my $testmode = 0;
+my $dorename = 0;
+my $verbose = 1;
+my $mode = '';
+my $package = '';
+my $divertto = '';
+my @contest;
+my @altname;
+my @package;
+my $file;
$|=1;
+
+# FIXME: those should be local.
+my ($rsrc, $rdest);
+my (@ssrc, @sdest);
+
sub checkmanymodes {
return unless $mode;
&badusage(sprintf(_g("two modes specified: %s and --%s"), $_, $mode));
$divertto= "$file.distrib" unless defined($divertto);
$divertto =~ m#^/# || &badusage(sprintf(_g("filename \"%s\" is not absolute"), $divertto));
$package= ':' unless defined($package);
- for ($i=0; $i<=$#contest; $i++) {
+ for (my $i = 0; $i <= $#contest; $i++) {
if ($contest[$i] eq $file || $altname[$i] eq $file ||
$contest[$i] eq $divertto || $altname[$i] eq $divertto) {
if ($contest[$i] eq $file && $altname[$i] eq $divertto &&
} elsif ($mode eq 'remove') {
@ARGV == 1 || &badusage(sprintf(_g("--%s needs a single argument"), "remove"));
$file= $ARGV[0];
- for ($i=0; $i<=$#contest; $i++) {
+ for (my $i = 0; $i <= $#contest; $i++) {
next unless $file eq $contest[$i];
&quit(sprintf(_g("mismatch on divert-to\n when removing \`%s'\n found \`%s'"), &infoa, &infon($i)))
if defined($divertto) && $altname[$i] ne $divertto;
&quit(sprintf(_g("mismatch on package\n when removing \`%s'\n found \`%s'"), &infoa, &infon($i)))
if defined($package) && $package[$i] ne $package;
printf(_g("Removing \`%s'")."\n", &infon($i)) if $verbose > 0;
- $orgfile= $contest[$i];
- $orgdivertto= $altname[$i];
+ my $orgfile = $contest[$i];
+ my $orgdivertto = $altname[$i];
@contest= (($i > 0 ? @contest[0..$i-1] : ()),
($i < $#contest ? @contest[$i+1..$#contest] : ()));
@altname= (($i > 0 ? @altname[0..$i-1] : ()),
printf(_g("No diversion \`%s', none removed")."\n", &infoa) if $verbose > 0;
exit(0);
} elsif ($mode eq 'list') {
- @ilist= @ARGV ? @ARGV : ('*');
+ my @list;
+ my @ilist = @ARGV ? @ARGV : ('*');
while (defined($_=shift(@ilist))) {
s/\W/\\$&/g;
s/\\\?/./g;
s/\\\*/.*/g;
push(@list,"^$_\$");
}
- $pat= join('|',@list);
- for ($i=0; $i<=$#contest; $i++) {
+ my $pat = join('|', @list);
+ for (my $i = 0; $i <= $#contest; $i++) {
next unless ($contest[$i] =~ m/$pat/o ||
$altname[$i] =~ m/$pat/o ||
$package[$i] =~ m/$pat/o);
} elsif ($mode eq 'truename') {
@ARGV == 1 || &badusage(sprintf(_g("--%s needs a single argument"), "truename"));
$file= $ARGV[0];
- for ($i=0; $i<=$#contest; $i++) {
+ for (my $i = 0; $i <= $#contest; $i++) {
next unless $file eq $contest[$i];
print $altname[$i], "\n";
exit(0);
# same name as the diversions but with an extension that
# (hopefully) wont overwrite anything. If it succeeds, we
# assume a writable filesystem.
- foreach $file ($rsrc,$rdest) {
+ foreach my $file ($rsrc, $rdest) {
if (open (TMP, ">> ${file}.dpkg-devert.tmp")) {
close TMP;
unlink ("${file}.dpkg-devert.tmp");
return if $testmode;
open(N,"> $admindir/diversions-new") || &quit(sprintf(_g("create diversions-new: %s"), $!));
chmod 0644, "$admindir/diversions-new";
- for ($i=0; $i<=$#contest; $i++) {
+ for (my $i = 0; $i <= $#contest; $i++) {
print(N "$contest[$i]\n$altname[$i]\n$package[$i]\n")
|| &quit(sprintf(_g("write diversions-new: %s"), $!));
}
}
sub infoa { &infol($file,$divertto,$package); }
-sub infon { &infol($contest[$i],$altname[$i],$package[$i]); }
+sub infon
+{
+ my $i = shift;
+ &infol($contest[$i], $altname[$i], $package[$i]);
+}
sub quit
{
#!/usr/bin/perl --
-$admindir= "/var/lib/dpkg"; # This line modified by Makefile
-$dpkglibdir= "../utils"; # This line modified by Makefile
-$version= '0.93.80'; # This line modified by Makefile
+use strict;
+use warnings;
+
+my $admindir = "/var/lib/dpkg"; # This line modified by Makefile
+my $dpkglibdir = "../utils"; # This line modified by Makefile
+my $version = '0.93.80'; # This line modified by Makefile
push (@INC, $dpkglibdir);
require 'dpkg-gettext.pl';
textdomain("dpkg");
($0) = $0 =~ m:.*/(.+):;
# Global variables:
-# $alink Alternative we are managing (ie the symlink we're making/removing) (install only)
-# $name Name of the alternative (the symlink) we are processing
-# $apath Path of alternative we are offering
-# $apriority Priority of link (only when we are installing an alternative)
-# $mode action to perform (display / install / remove / display / auto / config)
-# $manual update-mode for alternative (manual / auto)
-# $state State of alternative:
-# expected: alternative with highest priority is the active alternative
-# expected-inprogress: busy selecting alternative with highest priority
-# unexpected: alternative another alternative is active / error during readlink
-# nonexistent: alternative-symlink does not exist
-# $link Link we are working with
-# @slavenames List with names of slavelinks
-# %slavenum Map from name of slavelink to slave-index (into @slavelinks)
-# @slavelinks List of slavelinks (indexed by slave-index)
-# %versionnum Map from currently available versions into @versions and @priorities
-# @versions List of available versions for alternative
-# %priorities Map from @version-index to priority
-# %slavepath Map from (@version-index,slavename) to slave-path
-
-$enoent=`$dpkglibdir/enoent` || die sprintf(_g("Cannot get ENOENT value from %s: %s"), "$dpkglibdir/enoent", $!);
+my $mode = ''; # Action to perform (display / install / remove / display / auto / config)
+my $manual = 'auto'; # Update mode for alternative (manual / auto)
+my $state; # State of alternative:
+ # expected: alternative with highest priority is the active alternative
+ # expected-inprogress: busy selecting alternative with highest priority
+ # unexpected: alternative another alternative is active / error during readlink
+ # nonexistent: alternative-symlink does not exist
+my $dataread;
+
+my %versionnum; # Map from currently available versions into @versions and @priorities
+my @versions; # List of available versions for alternative
+my @priorities; # Map from @version-index to priority
+
+my $best;
+my $bestpri;
+my $bestnum;
+
+my $link; # Link we are working with
+my $linkname;
+
+my $alink; # Alternative we are managing (ie the symlink we're making/removing) (install only)
+my $name; # Name of the alternative (the symlink) we are processing
+my $apath; # Path of alternative we are offering
+my $apriority; # Priority of link (only when we are installing an alternative)
+my %aslavelink;
+my %aslavepath;
+my %aslavelinkcount;
+
+my $slink;
+my $sname;
+my $spath;
+my @slavenames; # List with names of slavelinks
+my %slavenum; # Map from name of slavelink to slave-index (into @slavelinks)
+my @slavelinks; # List of slavelinks (indexed by slave-index)
+my %slavepath; # Map from (@version-index,slavename) to slave-path
+my %slavelinkcount;
+
+my $enoent = `$dpkglibdir/enoent` || die sprintf(_g("Cannot get ENOENT value from %s: %s"), "$dpkglibdir/enoent", $!);
sub ENOENT { $enoent; }
sub version {
exit(2);
}
-$altdir= '/etc/alternatives';
-$admindir= $admindir . '/alternatives';
-$testmode= 0;
-$verbosemode= 0;
-$mode='';
-$manual= 'auto';
+my $altdir = '/etc/alternatives';
+# FIXME: this should not override the previous assignment.
+$admindir = $admindir . '/alternatives';
+my $testmode = 0;
+my $verbosemode = 0;
$|=1;
sub checkmanymodes {
defined($versionnum{$version}) && &badfmt(sprintf(_g("duplicate path %s"), $version));
if ( -r $version ) {
push(@versions,$version);
+ my $i;
$versionnum{$version}= $i= $#versions;
- $priority= &gl("priority");
+ my $priority = &gl("priority");
$priority =~ m/^[-+]?\d+$/ || &badfmt(sprintf(_g("priority %s %s"), $version, $priority));
$priorities[$i]= $priority;
- for ($j=0; $j<=$#slavenames; $j++) {
+ for (my $j = 0; $j <= $#slavenames; $j++) {
$slavepath{$i,$j}= &gl("spath");
}
} else {
&pr(sprintf(_g("Alternative for %s points to %s - which wasn't found. Removing from list of alternatives."), $name, $version))
if $verbosemode > 0;
&gl("priority");
- for ($j=0; $j<=$#slavenames; $j++) {
+ for (my $j = 0; $j <= $#slavenames; $j++) {
&gl("spath");
}
}
&pr(sprintf(_g(" link unreadable - %s"), $!));
}
$best= '';
- for ($i=0; $i<=$#versions; $i++) {
+ for (my $i = 0; $i <= $#versions; $i++) {
if ($best eq '' || $priorities[$i] > $bestpri) {
$best= $versions[$i]; $bestpri= $priorities[$i];
}
&pr(sprintf(_g("%s - priority %s"), $versions[$i], $priorities[$i]));
- for ($j=0; $j<=$#slavenames; $j++) {
- next unless length($tspath= $slavepath{$i,$j});
+ for (my $j = 0; $j <= $#slavenames; $j++) {
+ my $tspath = $slavepath{$i, $j};
+ next unless length($tspath);
&pr(sprintf(_g(" slave %s: %s"), $slavenames[$j], $tspath));
}
}
if ($mode eq 'list') {
if ($dataread) {
- for ($i = 0; $i<=$#versions; $i++) {
+ for (my $i = 0; $i <= $#versions; $i++) {
&pr("$versions[$i]");
}
}
}
$best= '';
-for ($i=0; $i<=$#versions; $i++) {
+for (my $i = 0; $i <= $#versions; $i++) {
if ($best eq '' || $priorities[$i] > $bestpri) {
$best= $versions[$i]; $bestpri= $priorities[$i];
}
&quit(sprintf(_g("unable to rename %s to %s: %s"), $link, $alink, $!));
}
$link= $alink;
+ my $i;
if (!defined($i= $versionnum{$apath})) {
push(@versions,$apath);
$versionnum{$apath}= $i= $#versions;
}
$priorities[$i]= $apriority;
for $sname (keys %aslavelink) {
+ my $j;
if (!defined($j= $slavenum{$sname})) {
push(@slavenames,$sname);
$slavenum{$sname}= $j= $#slavenames;
}
- $oldslavelink= $slavelinks[$j];
- $newslavelink= $aslavelink{$sname};
+ my $oldslavelink = $slavelinks[$j];
+ my $newslavelink = $aslavelink{$sname};
$slavelinkcount{$oldslavelink}-- if $oldslavelink ne '';
$slavelinkcount{$newslavelink}++ &&
&quit(sprintf(_g("slave link name %s duplicated"), $newslavelink));
}
$slavelinks[$j]= $newslavelink;
}
- for ($j=0; $j<=$#slavenames; $j++) {
+ for (my $j = 0; $j <= $#slavenames; $j++) {
$slavepath{$i,$j}= $aslavepath{$slavenames[$j]};
}
}
if ($mode eq 'remove') {
+ my $hits = 0;
if ($manual eq "manual" and $state ne "expected" and (map { $hits += $apath eq $_ } @versions) and $hits and $linkname eq $apath) {
&pr(_g("Removing manually selected alternative - switching to auto mode"));
$manual= "auto";
}
- if (defined($i= $versionnum{$apath})) {
- $k= $#versions;
+ if (defined(my $i = $versionnum{$apath})) {
+ my $k = $#versions;
$versionnum{$versions[$k]}= $i;
delete $versionnum{$versions[$i]};
$versions[$i]= $versions[$k]; $#versions--;
$priorities[$i]= $priorities[$k]; $#priorities--;
- for ($j=0; $j<=$#slavenames; $j++) {
+ for (my $j = 0; $j <= $#slavenames; $j++) {
$slavepath{$i,$j}= $slavepath{$k,$j};
delete $slavepath{$k,$j};
}
if ($mode eq 'remove-all') {
$manual= "auto";
- $k= $#versions;
- for ($i=0; $i<=$#versions; $i++) {
+ my $k = $#versions;
+ for (my $i = 0; $i <= $#versions; $i++) {
$k--;
delete $versionnum{$versions[$i]};
$#priorities--;
- for ($j=0; $j<=$#slavenames; $j++) {
+ for (my $j = 0; $j <= $#slavenames; $j++) {
$slavepath{$i,$j}= $slavepath{$k,$j};
delete $slavepath{$k,$j};
}
}
-for ($j=0; $j<=$#slavenames; $j++) {
- for ($i=0; $i<=$#versions; $i++) {
+for (my $j = 0; $j <= $#slavenames; $j++) {
+ my $i;
+ for ($i = 0; $i <= $#versions; $i++) {
last if $slavepath{$i,$j} ne '';
}
if ($i > $#versions) {
&quit(sprintf(_g("unable to remove %s: %s"), "$altdir/$slavenames[$j]", $!));
unlink($slavelinks[$j]) || $! == &ENOENT ||
&quit(sprintf(_g("unable to remove %s: %s"), $slavelinks[$j], $!));
- $k= $#slavenames;
+ my $k = $#slavenames;
$slavenum{$slavenames[$k]}= $j;
delete $slavenum{$slavenames[$j]};
$slavelinkcount{$slavelinks[$j]}--;
$slavenames[$j]= $slavenames[$k]; $#slavenames--;
$slavelinks[$j]= $slavelinks[$k]; $#slavelinks--;
- for ($i=0; $i<=$#versions; $i++) {
+ for (my $i = 0; $i <= $#versions; $i++) {
$slavepath{$i,$j}= $slavepath{$i,$k};
delete $slavepath{$i,$k};
}
&quit(sprintf(_g("unable to open %s for write: %s"), "$admindir/$name.dpkg-new", $!));
&paf($manual);
&paf($link);
-for ($j=0; $j<=$#slavenames; $j++) {
+for (my $j = 0; $j <= $#slavenames; $j++) {
&paf($slavenames[$j]);
&paf($slavelinks[$j]);
}
&paf('');
$best= '';
-for ($i=0; $i<=$#versions; $i++) {
+for (my $i = 0; $i <= $#versions; $i++) {
if ($best eq '' || $priorities[$i] > $bestpri) {
$best= $versions[$i]; $bestpri= $priorities[$i]; $bestnum= $i;
}
&paf($versions[$i]);
&paf($priorities[$i]);
- for ($j=0; $j<=$#slavenames; $j++) {
+ for (my $j = 0; $j <= $#slavenames; $j++) {
&paf($slavepath{$i,$j});
}
}
if ($manual eq 'auto') {
rename_mv("$altdir/$name.dpkg-tmp","$altdir/$name") ||
&quit(sprintf(_g("unable to install %s as %s: %s"), "$altdir/$name.dpkg-tmp", "$altdir/$name", $!));
- for ($j=0; $j<=$#slavenames; $j++) {
+ for (my $j = 0; $j <= $#slavenames; $j++) {
$sname= $slavenames[$j];
$slink= $slavelinks[$j];
if (!defined($linkname= readlink($slink)) && $! != &ENOENT) {
" Selection Alternative\n".
"-----------------------------------------------\n"),
$#versions+1, $name);
- for ($i=0; $i<=$#versions; $i++) {
+ for (my $i = 0; $i <= $#versions; $i++) {
printf(STDOUT "%s%s %8s %s\n",
(readlink("$altdir/$name") eq $versions[$i]) ? '*' : ' ',
($best eq $versions[$i]) ? '+' : ' ',
}
sub config_alternatives {
+ my $preferred;
do {
&config_message;
if ($#versions == 0) { return; }
sub set_alternatives {
$manual = "manual";
# Get prefered number
- $preferred = -1;
- for ($i=0; $i<=$#versions; $i++) {
+ my $preferred = -1;
+ for (my $i = 0; $i <= $#versions; $i++) {
if($versions[$i] eq $apath) {
$preferred = $i;
last;
rename_mv("$altdir/$name.dpkg-tmp","$altdir/$name") ||
&quit(sprintf(_g("unable to install %s as %s: %s"), "$altdir/$name.dpkg-tmp", "$altdir/$name", $!));
# Link slaves...
- for( $slnum = 0; $slnum < @slavenames; $slnum++ ) {
- $slave = $slavenames[$slnum];
+ for (my $slnum = 0; $slnum < @slavenames; $slnum++ ) {
+ my $slave = $slavenames[$slnum];
if ($slavepath{$preferred,$slnum} ne '') {
checked_symlink($slavepath{$preferred,$slnum},
"$altdir/$slave.dpkg-tmp");