#!/usr/bin/perl -w # # Debhelper option processing library. # # Joey Hess GPL copyright 1998-2002 package Debian::Debhelper::Dh_Getopt; use strict; use Debian::Debhelper::Dh_Lib; use Getopt::Long; my %exclude_package; sub showhelp { my $prog=basename($0); print "Usage: $prog [options]\n\n"; print " $prog is a part of debhelper. See debhelper(7)\n"; print " and $prog(1) for complete usage instructions.\n"; exit(1); } # Passed an option name and an option value, adds packages to the list # of packages. We need this so the list will be built up in the right # order. sub AddPackage { my($option,$value)=@_; if ($option eq 'i' or $option eq 'indep') { push @{$dh{DOPACKAGES}}, getpackages('indep'); $dh{DOINDEP}=1; } elsif ($option eq 'a' or $option eq 'arch') { push @{$dh{DOPACKAGES}}, getpackages('arch'); $dh{DOARCH}=1; } elsif ($option eq 'p' or $option eq 'package') { push @{$dh{DOPACKAGES}}, $value; } elsif ($option eq 's' or $option eq 'same-arch') { push @{$dh{DOPACKAGES}}, getpackages('same'); $dh{DOSAME}=1; } else { error("bad option $option - should never happen!\n"); } } # Adds packages to the list of debug packages. sub AddDebugPackage { my($option,$value)=@_; push @{$dh{DEBUGPACKAGES}}, $value; } # Add a package to a list of packages that should not be acted on. sub ExcludePackage { my($option,$value)=@_; $exclude_package{$value}=1; } # Add another item to the exclude list. sub AddExclude { my($option,$value)=@_; push @{$dh{EXCLUDE}},$value; } # Add a file to the ignore list. sub AddIgnore { my($option,$file)=@_; $dh{IGNORE}->{$file}=1; } # This collects non-options values. sub NonOption { push @{$dh{ARGV}}, @_; } sub getoptions { my $array=shift; my $extraoptions=shift; my %options=( "v" => \$dh{VERBOSE}, "verbose" => \$dh{VERBOSE}, "no-act" => \$dh{NO_ACT}, "i" => \&AddPackage, "indep" => \&AddPackage, "a" => \&AddPackage, "arch" => \&AddPackage, "p=s" => \&AddPackage, "package=s" => \&AddPackage, "N=s" => \&ExcludePackage, "no-package=s" => \&ExcludePackage, "remaining-packages" => \$dh{EXCLUDE_LOGGED}, "dbg-package=s" => \&AddDebugPackage, "s" => \&AddPackage, "same-arch" => \&AddPackage, "n" => \$dh{NOSCRIPTS}, "noscripts" => \$dh{NOSCRIPTS}, "o" => \$dh{ONLYSCRIPTS}, "onlyscripts" => \$dh{ONLYSCRIPTS}, "X=s" => \&AddExclude, "exclude=s" => \&AddExclude, "d" => \$dh{D_FLAG}, "k" => \$dh{K_FLAG}, "keep" => \$dh{K_FLAG}, "P=s" => \$dh{TMPDIR}, "tmpdir=s" => \$dh{TMPDIR}, "u=s", => \$dh{U_PARAMS}, "V:s", => \$dh{V_FLAG}, "A" => \$dh{PARAMS_ALL}, "all" => \$dh{PARAMS_ALL}, "sourcedir=s" => \$dh{SOURCEDIR}, "destdir=s" => \$dh{DESTDIR}, "priority=s" => \$dh{PRIORITY}, "h|help" => \&showhelp, "mainpackage=s" => \$dh{MAINPACKAGE}, "name=s" => \$dh{NAME}, "error-handler=s" => \$dh{ERROR_HANDLER}, "ignore=s" => \&AddIgnore, "<>" => \&NonOption, ); # Merge extra options and cancel default ones as needed (undef) if (defined $extraoptions) { for my $opt (keys %$extraoptions) { if (defined $extraoptions->{$opt}) { $options{$opt}=$extraoptions->{$opt}; } else { delete $options{$opt}; } } } Getopt::Long::GetOptionsFromArray($array, %options); } sub split_options_string { my $str=shift; $str=~s/^\s+//; return map { $_=~s/\\(\s)/$1/g; $_=~s/\s+$//g; $_ } split(/(?