#! /bin/sh /usr/share/dpatch/dpatch-run
## 30-strictness-510020-510524.dpatch by Jonathan Wiltshire <debian@jwiltshire.org.uk>
## 31-strictness.dpatch by Jonathan Wiltshire <debian@jwiltshire.org.uk>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Add a --strict option to output only exactly matching package names
## DP: Status: Sent upstream to phi1ipp@yahoo.com
## DP: No description.

@DPATCH@
diff -urNad whohas-0.23~/program/whohas whohas-0.23/program/whohas
--- whohas-0.23~/program/whohas	2009-03-03 22:22:06.000000000 +0000
+++ whohas-0.23/program/whohas	2009-03-03 22:22:06.000000000 +0000
@@ -77,23 +77,25 @@
 my $option_nothreads;
 my $option_shallow;
 my $option_help;
+my $option_strict;
 
 GetOptions(
 	"d=s" => \@option_distro,
 	"no-threads" => \$option_nothreads,
 	"shallow" => \$option_shallow,
 	"help|usage|h" => \$option_help,
+	"strict|s" => \$option_strict,
 );
 $useThreads = !$option_nothreads;
 $goDeep = !$option_shallow;
 
 if ($option_help) {
-	print "Usage: $0 [--no-threads] [--shallow] [-d Dist1[,Dist2[,Dist3...]]] pkgname\n";
+	print "Usage: $0 [--no-threads] [--shallow] [--strict] [-d Dist1[,Dist2[,Dist3...]]] pkgname\n";
 	exit 0;
 }
 
 if (@ARGV > 1) {
-	die "Error:\tToo many parameters. Usage: $0 [--no-threads] [--shallow]  [-d Dist1[,Dist2[,Dist3...]]] pkgname\n";
+	die "Error:\tToo many parameters. Usage: $0 [--no-threads] [--shallow] [--strict] [-d Dist1[,Dist2[,Dist3...]]] pkgname\n";
 } elsif (@ARGV < 1) {
 	die "Error:\tPlease specify a search term.\n";
 }
@@ -1114,6 +1116,10 @@
 }
 
 sub pretty_print {
+	if( $option_strict && trim($_[$cols+2]) ne $ARGV[0])
+	{
+		return; # strictness enabled, we should print exact matches only
+	}
 	my $n = $_[0];
 	my @colwidths = @_[1..$n];
 	my @colvals = @_[($n+1)..(@_-1)];
@@ -1132,6 +1138,14 @@
 	print $colvals[@colvals-1]."\n"; #last column is unrestricted in length
 }
 
+sub trim($) {
+	# Perl trim function to remove whitespace from the start and end of the string
+	my $string = shift;
+	$string =~ s/^\s+//;
+	$string =~ s/\s+$//;
+	return $string;
+}
+
 sub prep_suse_repo {
 	if ($_[0] =~ /http\:\/\/download\.opensuse\.org/) {
 		if ($_[0] =~ /repositories/) {
diff -urNad whohas-0.23~/usr/share/man/man1/whohas.1 whohas-0.23/usr/share/man/man1/whohas.1
--- whohas-0.23~/usr/share/man/man1/whohas.1	2009-03-03 22:22:06.000000000 +0000
+++ whohas-0.23/usr/share/man/man1/whohas.1	2009-03-03 22:23:19.000000000 +0000
@@ -4,7 +4,7 @@
 whohas \- find packages in various distributions' repositories
 .SH "SYNTAX"
 .LP 
-whohas [\fI\-\-no\-threads\fP] [\fI\-\-shallow\fP] [\fI\-d Dist1[,Dist2[,Dist3 etc.]]\fP] \fIpkgname\fP
+whohas [\fI\-\-no\-threads\fP] [\fI\-\-shallow\fP] [\fI\-\-strict\fP] [\fI\-d Dist1[,Dist2[,Dist3 etc.]]\fP] \fIpkgname\fP
 .SH "DESCRIPTION"
 .LP 
 whohas is a command line tool to query package lists from the Arch, Debian, Fedora, Gentoo, openSUSE, Slackware (and linuxpackages.net), Source Mage, Ubuntu, FreeBSD, NetBSD, OpenBSD, Fink and MacPorts distributions.
@@ -16,6 +16,9 @@
 .TP 
 \fB\-\-shallow\fR
 Limit to one call per server. Faster, but loses some information, typically package size and release date.
+.TP
+\fB\-\-strict\fR
+Return only packages whose name exactly matches \fIpkgname\fP.
 .TP 
 \fB\-d Dist1[,Dist2[,Dist3 etc.]]\fR
 Queries only for packages for the listed distributions. Recognised values for Dist1, Dist2, etc. are "archlinux", "debian", "fedora", "fink", "freebsd", "gentoo", "macports", "netbsd", "openbsd", "opensuse", "slackware", "sourcemage", and "ubuntu".
