#! /bin/sh /usr/share/dpatch/dpatch-run
## 25-use-getopt-513473.dpatch by Jonathan Wiltshire <debian@jwiltshire.org.uk>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Use Perl's Getopt::Long module for handling parameters
## DP: Patch from Steve Cotton <steve0001@s.cotton.clara.co.uk>
## DP: Status: Forwarded upstream to phi1ipp@yahoo.com

@DPATCH@
--- whohas-0.23.orig/program/whohas
+++ whohas-0.23/program/whohas
@@ -78,62 +78,65 @@
 my $useThreads = 1;
 my $goDeep = 1;
 
+use Getopt::Long;
+my @option_distro;
+my $option_nothreads;
+my $option_shallow;
+
+GetOptions(
+	"d=s" => \@option_distro,
+	"no-threads" => \$option_nothreads,
+	"shallow" => \$option_shallow,
+);
+$useThreads = !$option_nothreads;
+$goDeep = !$option_shallow;
+
 if (@ARGV > 1) {
-	for (my $i = 0; $i < @ARGV; $i++) {
-		if ($ARGV[$i] eq "--shallow") {
-			$goDeep = 0;
-			splice @ARGV, $i, 1;
-			last;
-		}
-	}
+	die "Error:\tToo many parameters. Usage: $0 [--no-threads] [-d Dist1[,Dist2[,Dist3...]]] pkgname\n";
+} elsif (@ARGV < 1) {
+	die "Error:\tPlease specify a search term.\n";
 }
 
-if (@ARGV > 1) {
-	for (my $i = 0; $i < @ARGV; $i++) {
-		if ($ARGV[$i] eq "-d") {
-			$arch_bool		= 0;
-			$cygwin_bool		= 0;
-			$debian_bool		= 0;
-			$fink_bool		= 0;
-			$freebsd_bool		= 0;
-			$macports_bool		= 0;
-			$mandriva_bool		= 0;
-			$netbsd_bool		= 0;
-			$openbsd_bool		= 0;
-			$opensuse_bool		= 0;
-			$slack_bool		= 0;
-			$sourcemage_bool	= 0;
-			$ubuntu_bool		= 0;
-			$gentoo_bool 		= 0;
-			$fedora_bool 		= 0;
-			my @parts = split /,/, $ARGV[$i+1];
-			for (my $a = 0; $a < @parts; $a++) {
-				if (		$parts[$a] =~ /archlinux/i) {	$arch_bool		= 1;
-				} elsif (	$parts[$a] =~ /cygwin/i) {	$cygwin_bool		= 1;
-				} elsif (	$parts[$a] =~ /debian/i) {	$debian_bool		= 1;
-				} elsif (	$parts[$a] =~ /fink/i) {	$fink_bool		= 1;
-				} elsif (	$parts[$a] =~ /freebsd/i) {	$freebsd_bool		= 1;
-				} elsif (	$parts[$a] =~ /macports/i) {	$macports_bool		= 1;
-				} elsif (	$parts[$a] =~ /mandriva/i) {	$mandriva_bool		= 1;
-				} elsif (	$parts[$a] =~ /netbsd/i) {	$netbsd_bool		= 1;
-				} elsif (	$parts[$a] =~ /openbsd/i) {	$openbsd_bool		= 1;
-				} elsif (	$parts[$a] =~ /opensuse/i) {	$opensuse_bool		= 1;
-				} elsif (	$parts[$a] =~ /slackware/i) {	$slack_bool		= 1;
-				} elsif (	$parts[$a] =~ /sourcemage/i) {	$sourcemage_bool	= 1;
-				} elsif (	$parts[$a] =~ /ubuntu/i) {	$ubuntu_bool		= 1;
-				} elsif (	$parts[$a] =~ /gentoo/i) {	$gentoo_bool		= 1;
-				} elsif (	$parts[$a] =~ /fedora/i) {	$fedora_bool		= 1;
-				} else {
-					warn "Repository or distribution specified has not been recognised. You specified: $parts[$a]. Recognised options are: archlinux, cygwin, debian, fedora, fink, freebsd, gentoo, macports, mandriva, netbsd, openbsd, opensuse, slackware, sourcemage, ubuntu\n";
-				}
-			}
-			splice @ARGV, $i, 2;
-			last;
+if (@option_distro) {
+	$arch_bool              = 0;
+	$cygwin_bool		= 0;
+	$debian_bool            = 0;
+	$fink_bool              = 0;
+	$freebsd_bool           = 0;
+	$macports_bool          = 0;
+	$mandriva_bool          = 0;
+	$netbsd_bool            = 0;
+	$openbsd_bool           = 0;
+	$opensuse_bool          = 0;
+	$slack_bool             = 0;
+	$sourcemage_bool        = 0;
+	$ubuntu_bool            = 0;
+	$gentoo_bool            = 0;
+	$fedora_bool            = 0;
+	@option_distro = split(/,/,join(',',@option_distro));
+	for my $distro (@option_distro) {
+		if (            $distro =~ /archlinux/i) {      $arch_bool              = 1;
+		} elsif (       $distro =~ /cygwin/i) {         $cygwin_bool            = 1;
+		} elsif (       $distro =~ /debian/i) {         $debian_bool            = 1;
+		} elsif (       $distro =~ /fink/i) {           $fink_bool              = 1;
+		} elsif (       $distro =~ /freebsd/i) {        $freebsd_bool           = 1;
+		} elsif (       $distro =~ /macports/i) {       $macports_bool          = 1;
+		} elsif (       $distro =~ /mandriva/i) {       $mandriva_bool          = 1;
+		} elsif (       $distro =~ /netbsd/i) {         $netbsd_bool            = 1;
+		} elsif (       $distro =~ /openbsd/i) {        $openbsd_bool           = 1;
+		} elsif (       $distro =~ /opensuse/i) {       $opensuse_bool          = 1;
+		} elsif (       $distro =~ /slackware/i) {      $slack_bool             = 1;
+		} elsif (       $distro =~ /sourcemage/i) {     $sourcemage_bool        = 1;
+		} elsif (       $distro =~ /ubuntu/i) {         $ubuntu_bool            = 1;
+		} elsif (       $distro =~ /gentoo/i) {         $gentoo_bool            = 1;
+		} elsif (       $distro =~ /fedora/i) {         $fedora_bool            = 1;
+		} else {
+			warn "Repository or distribution specified has not been recognised. You specified: $distro. Recognised options are: archlinux, cygwin, debian, fedora, fink, freebsd, gentoo, macports, netbsd, openbsd, opensuse, slackware, sourcemage, ubuntu\n";
 		}
 	}
 }
 
-if (@ARGV == 1) {
+if($useThreads) {
 	if ($ARGV[0] eq "whohasme") {
 		my $motto = "Congratulations. You discovered an Easter egg. Maybe you can send a quick email to phi1ipp\@yahoo.com to say hello and tell the developer what you think of the software.\n";
 		exit;
@@ -190,60 +193,56 @@
 			$_->join;
 		}
 	}
-} elsif ($ARGV[0] eq "--no-threads") {
+} else {
 	$useThreads = 0;
 	if ($arch_bool == 1) {
-		&arch(		$ARGV[1]);
-		&aur(		$ARGV[1]);
+		&arch(		$ARGV[0]);
+		&aur(		$ARGV[0]);
 	}
 	if ($cygwin_bool == 1) {
-		&cygwin(	$ARGV[1]);
+		&cygwin(	$ARGV[0]);
 	}
 	if ($debian_bool == 1) {
-		&debian(	$ARGV[1]);
+		&debian(	$ARGV[0]);
 	}
 	if ($fedora_bool == 1) {
-		&fedora(	$ARGV[1]);
+		&fedora(	$ARGV[0]);
 	}
 	if ($fink_bool == 1) {
-		&fink(		$ARGV[1]);
+		&fink(		$ARGV[0]);
 	}
 	if ($freebsd_bool == 1) {
-		&freebsd(	$ARGV[1]);
+		&freebsd(	$ARGV[0]);
 	}
 	if ($gentoo_bool == 1) {
-		&gentoo(	$ARGV[1]);
+		&gentoo(	$ARGV[0]);
 	}
 	if ($macports_bool == 1) {
-		&macports(	$ARGV[1]);
+		&macports(	$ARGV[0]);
 	}
 	if ($mandriva_bool == 1) {
-		&mandriva(	$ARGV[1]);
+		&mandriva(	$ARGV[0]);
 	}
 	if ($netbsd_bool == 1) {
-#		&netbsd(	$ARGV[1]);
-		&netbsd_pkgsrc(	$ARGV[1]);
+#		&netbsd(	$ARGV[0]);
+		&netbsd_pkgsrc(	$ARGV[0]);
 	}
 	if ($openbsd_bool == 1) {
-		&openbsd(	$ARGV[1]);
+		&openbsd(	$ARGV[0]);
 	}
 	if ($opensuse_bool == 1) {
-		&opensuse(	$ARGV[1]);
+		&opensuse(	$ARGV[0]);
 	}
 	if ($slack_bool == 1) {
-#		&slack(		$ARGV[1]);
-		&lp_net(	$ARGV[1]);
+#		&slack(		$ARGV[0]);
+		&lp_net(	$ARGV[0]);
 	}
 	if ($sourcemage_bool == 1) {
-		&sourcemage($ARGV[1]);
+		&sourcemage(	$ARGV[0]);
 	}
 	if ($ubuntu_bool == 1) {
-		&ubuntu(	$ARGV[1]);
+		&ubuntu(	$ARGV[0]);
 	}
-} elsif (@ARGV != 0) {
-	die "Error:\tToo many parameters. Usage: $0 [--no-threads] pkgname\n";
-} else {
-	die "Error:\tPlease specify a search term.\n";
 }
 
 sub fedora {
