From 648c97ce1757e2834fca679be93e68a52e6a6587 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Fri, 4 May 2007 01:22:56 +0000 Subject: [PATCH] * 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. --- ChangeLog | 12 +++++ scripts/controllib.pl | 99 ++++++++++++++++++++++++++++++++++++ scripts/dpkg-architecture.pl | 87 ++----------------------------- 3 files changed, 114 insertions(+), 84 deletions(-) diff --git a/ChangeLog b/ChangeLog index 166ee4ed..0252c24b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2007-05-04 Guillem Jover + + * 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 * scripts/update-alternatives.pl: Call read_link_group also in diff --git a/scripts/controllib.pl b/scripts/controllib.pl index 58282ef3..047a5758 100755 --- a/scripts/controllib.pl +++ b/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 () { + 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 () { + 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) = @_; diff --git a/scripts/dpkg-architecture.pl b/scripts/dpkg-architecture.pl index a4c9a614..3ec8dc56 100755 --- a/scripts/dpkg-architecture.pl +++ b/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 () { - 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 () { - 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; } -- 2.39.5