Sfoglia il codice sorgente

* scripts/dpkg-architecture.pl: Use get_valid_arches instead of
directly using @os and @cpu variables.
($pkgdatadir): Change from a 'my' to an 'our' variable.
(@cpu, @os, %cputable, %ostable, %cputable_re, %ostable_re,
read_cputable, read_ostable, split_debian, debian_to_gnu,
split_gnu, gnu_to_debian): Move to ...
* scripts/controllib.pl: ... here.
($pkgdatadir): Declare as 'our'.
(get_valid_arches): New function.

Guillem Jover 19 anni fa
parent
commit
648c97ce17
3 ha cambiato i file con 114 aggiunte e 84 eliminazioni
  1. 12 0
      ChangeLog
  2. 99 0
      scripts/controllib.pl
  3. 3 84
      scripts/dpkg-architecture.pl

+ 12 - 0
ChangeLog

@@ -1,3 +1,15 @@
+2007-05-04  Guillem Jover  <guillem@debian.org>
+
+	* scripts/dpkg-architecture.pl: Use get_valid_arches instead of
+	directly using @os and @cpu variables.
+	($pkgdatadir): Change from a 'my' to an 'our' variable.
+	(@cpu, @os, %cputable, %ostable, %cputable_re, %ostable_re,
+	read_cputable, read_ostable, split_debian, debian_to_gnu,
+	split_gnu, gnu_to_debian): Move to ...
+	* scripts/controllib.pl: ... here.
+	($pkgdatadir): Declare as 'our'.
+	(get_valid_arches): New function.
+
 2007-05-04  Guillem Jover  <guillem@debian.org>
 
 	* scripts/update-alternatives.pl: Call read_link_group also in

+ 99 - 0
scripts/controllib.pl

@@ -7,6 +7,7 @@ use English;
 use POSIX qw(:errno_h);
 
 our $dpkglibdir;
+our $pkgdatadir;
 
 push(@INC,$dpkglibdir);
 require 'dpkg-gettext.pl';
@@ -92,6 +93,14 @@ sub capit {
     return join '-', @pieces;
 }
 
+#
+# Architecture library
+#
+
+my (@cpu, @os);
+my (%cputable, %ostable);
+my (%cputable_re, %ostable_re);
+
 {
     my $host_arch;
 
@@ -106,6 +115,96 @@ sub capit {
     }
 }
 
+sub get_valid_arches()
+{
+    foreach my $os (@os) {
+	foreach my $cpu (@cpu) {
+	    print debian_arch_fix($os, $cpu)."\n";
+	}
+    }
+}
+
+sub read_cputable
+{
+    open CPUTABLE, "$pkgdatadir/cputable"
+	or syserr(_g("unable to open cputable"));
+    while (<CPUTABLE>) {
+	if (m/^(?!\#)(\S+)\s+(\S+)\s+(\S+)/) {
+	    $cputable{$1} = $2;
+	    $cputable_re{$1} = $3;
+	    push @cpu, $1;
+	}
+    }
+    close CPUTABLE;
+}
+
+sub read_ostable
+{
+    open OSTABLE, "$pkgdatadir/ostable"
+	or syserr(_g("unable to open ostable"));
+    while (<OSTABLE>) {
+	if (m/^(?!\#)(\S+)\s+(\S+)\s+(\S+)/) {
+	    $ostable{$1} = $2;
+	    $ostable_re{$1} = $3;
+	    push @os, $1;
+	}
+    }
+    close OSTABLE;
+}
+
+sub split_debian
+{
+    local ($_) = @_;
+
+    if (/^([^-]*)-(.*)/) {
+	return ($1, $2);
+    } else {
+	return ("linux", $_);
+    }
+}
+
+sub debian_to_gnu
+{
+    my ($arch) = @_;
+    my ($os, $cpu) = split_debian($arch);
+
+    return undef unless exists($cputable{$cpu}) && exists($ostable{$os});
+    return join("-", $cputable{$cpu}, $ostable{$os});
+}
+
+sub split_gnu
+{
+    local ($_) = @_;
+
+    /^([^-]*)-(.*)/;
+    return ($1, $2);
+}
+
+sub gnu_to_debian
+{
+    my ($gnu) = @_;
+    my ($cpu, $os);
+
+    my ($gnu_cpu, $gnu_os) = split_gnu($gnu);
+    foreach my $_cpu (@cpu) {
+	if ($gnu_cpu =~ /^$cputable_re{$_cpu}$/) {
+	    $cpu = $_cpu;
+	    last;
+	}
+    }
+
+    foreach my $_os (@os) {
+	if ($gnu_os =~ /^(.*-)?$ostable_re{$_os}$/) {
+	    $os = $_os;
+	    last;
+	}
+    }
+
+    return undef if !defined($cpu) || !defined($os);
+    return debian_arch_fix($os, $cpu);
+}
+
+
 sub debian_arch_fix
 {
     my ($os, $cpu) = @_;

+ 3 - 84
scripts/dpkg-architecture.pl

@@ -25,6 +25,7 @@ use warnings;
 our $progname;
 our $version = "1.0.0"; # This line modified by Makefile
 our $dpkglibdir = "."; # This line modified by Makefile
+our $pkgdatadir = ".."; # This line modified by Makefile
 
 push(@INC,$dpkglibdir);
 require 'controllib.pl';
@@ -32,8 +33,6 @@ require 'controllib.pl';
 require 'dpkg-gettext.pl';
 textdomain("dpkg-dev");
 
-my $pkgdatadir = "..";
-
 sub version {
     printf _g("Debian %s version %s.\n"), $progname, $version;
 
@@ -70,93 +69,13 @@ Actions:
 "), $progname;
 }
 
-my (@cpu, @os);
-my (%cputable, %ostable);
-my (%cputable_re, %ostable_re);
-
-sub read_cputable {
-    open CPUTABLE, "$pkgdatadir/cputable"
-	or &syserr(_g("unable to open cputable"));
-    while (<CPUTABLE>) {
-	if (m/^(?!\#)(\S+)\s+(\S+)\s+(\S+)/) {
-	    $cputable{$1} = $2;
-	    $cputable_re{$1} = $3;
-	    push @cpu, $1;
-	}
-    }
-    close CPUTABLE;
-}
-
-sub read_ostable {
-    open OSTABLE, "$pkgdatadir/ostable"
-	or &syserr(_g("unable to open ostable"));
-    while (<OSTABLE>) {
-	if (m/^(?!\#)(\S+)\s+(\S+)\s+(\S+)/) {
-	    $ostable{$1} = $2;
-	    $ostable_re{$1} = $3;
-	    push @os, $1;
-	}
-    }
-    close OSTABLE;
-}
-
-sub split_debian {
-    local ($_) = @_;
-    
-    if (/^([^-]*)-(.*)/) {
-	return ($1, $2);
-    } else {
-	return ("linux", $_);
-    }
-}
-
-sub debian_to_gnu {
-    my ($arch) = @_;
-    my ($os, $cpu) = split_debian($arch);
-
-    return undef unless exists($cputable{$cpu}) && exists($ostable{$os});
-    return join("-", $cputable{$cpu}, $ostable{$os});
-}
-
-sub split_gnu {
-    local ($_) = @_;
-
-    /^([^-]*)-(.*)/;
-    return ($1, $2);
-}
-
-sub gnu_to_debian {
-    my ($gnu) = @_;
-    my ($cpu, $os);
-
-    my ($gnu_cpu, $gnu_os) = split_gnu($gnu);
-    foreach my $_cpu (@cpu) {
-	if ($gnu_cpu =~ /^$cputable_re{$_cpu}$/) {
-	    $cpu = $_cpu;
-	    last;
-	}
-    }
-
-    foreach my $_os (@os) {
-	if ($gnu_os =~ /^(.*-)?$ostable_re{$_os}$/) {
-	    $os = $_os;
-	    last;
-	}
-    }
-
-    return undef if !defined($cpu) || !defined($os);
-    return debian_arch_fix($os, $cpu);
-}
-
 &read_cputable;
 &read_ostable;
 
 # Check for -L
 if (grep { m/^-L$/ } @ARGV) {
-    foreach my $os (@os) {
-	foreach my $cpu (@cpu) {
-	    print debian_arch_fix($os, $cpu)."\n";
-	}
+    foreach my $arch (get_valid_arches()) {
+	print "$arch\n";
     }
     exit unless $#ARGV;
 }