## Description: Add a --strict option to output only exactly matching package names
## Origin/Author: Jonathan Wiltshire <debian@jwiltshire.org.uk>
## Bug: http://bugs.debian.org/510020
--- a/program/whohas
+++ b/program/whohas
@@ -72,21 +72,23 @@ my @distroSelections;
 my $nothreads;
 my $shallow;
 my $option_help;
+my $option_strict;
 
 GetOptions(
 	"d=s" => \@distroSelections,
 	"no-threads" => \$nothreads,
 	"shallow" => \$shallow,
 	"help|usage|h" => \$option_help,
+	"strict|s" => \$option_strict,
 );
 
 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";
 }
@@ -1172,6 +1174,9 @@ sub fetchdoc {
 }
 
 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)];
@@ -1190,6 +1195,15 @@ sub pretty_print {
 	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/) {
--- a/usr/share/man/de/man1/whohas.1
+++ b/usr/share/man/de/man1/whohas.1
@@ -1,35 +1,38 @@
-.TH "whohas" "1" "0.23" "Philipp Wesche" ""
+.TH "whohas" "1" "0.29" "Philipp Wesche" ""
 .SH "NAME"
-.LP 
+.LP
 whohas \- findet Pakete in verschiedenen Repositories
 .SH "SYNTAX"
-.LP 
-whohas [\fI\-\-no\-threads\fP] [\fI\-d Dist1[,Dist2[,Dist3 etc.]]\fP] \fIpkgname\fP
+.LP
+whohas [\fI\-\-no\-threads\fP] [\fI\-\-shallow\fP] [\fI\-\-strict\fP] [\fI\-d Dist1[,Dist2[,Dist3 etc.]]\fP] \fIpkgname\fP
 .SH "BESCHREIBUNG"
-.LP 
+.LP
 whohas ist ein Kommandozeilenprogramm, das verfgbare Pakete von Arch, Debian, Fedora, Gentoo, Mandriva, openSUSE, Slackware (and linuxpackages.net), Source Mage, Ubuntu, FreeBSD, NetBSD, OpenBSD, Fink, MacPorts und Cygwin findet, die einem Suchbegriff entsprechen.
 .SH "OPTIONEN"
-.LP 
-.TP 
+.LP
+.TP
 \fB\-\-no\-threads\fR
 Keine Threads bei der Ausfhrung, Repositories werden seriell nacheinander befragt und jeweils die Antwort abgewartet (sehr viel langsamer)
-.TP 
+.TP
 \fB\-\-shallow\fR
 Nur ein Aufruf pro Server. Bietet weniger Informationen, ist aber schneller. Typischerweise sind Informationen ber Gre und Release-Datum der Pakete betroffen.
-.TP 
+.TP
+\fB\-\-strict\fR
+Listet nur die Pakete, die genau \fIpkgname\fP haben wie ihr Name.
+.TP
 \fB\-d Dist1[,Dist2[,Dist3 etc.]]\fR
 Durchsucht nur aufgelistete Distributionen. Gltige Angaben fr Dist1 etc. sind "archlinux", "cygwin", "debian", "fedora", "fink", "freebsd", "gentoo", "macports", "mandriva", "netbsd", "openbsd", "opensuse", "slackware", "sourcemage", und "ubuntu".
-.TP 
+.TP
 \fBpkgname\fR
 Suchbegriff
 .SH "DATEIEN"
 .LP
 whohas speichert Cachedateien fr einige Repositories in ~/.whohas
 .SH "SIEHE AUCH"
-.LP 
+.LP
 \fIintro.txt\fP und \fI/usr/share/doc/whohas/intro.html\fP sind alternative Quellen ber whohas.
 .SH "AUTOR"
-.LP 
+.LP
 whohas wird von Philipp Wesche <phi1ipp@yahoo.com> entwickelt.
-.LP 
+.LP
 Diese Dokumentation wurde von Philipp Wesche <phi1ipp@yahoo.com> geschrieben, basierend auf einer Vorlage von Jonathan Wiltshire <debian@jwiltshire.org.uk> fr das Debian Projekt.
--- a/usr/share/man/man1/whohas.1
+++ b/usr/share/man/man1/whohas.1
@@ -1,32 +1,35 @@
-.TH "whohas" "1" "0.24" "Jonathan Wiltshire" ""
+.TH "whohas" "1" "0.29" "Jonathan Wiltshire" ""
 .SH "NAME"
-.LP 
+.LP
 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
+.LP
+whohas [\fI\-\-no\-threads\fP] [\fI\-\-shallow\fP] [\fI\-\-strict\fP] [\fI\-d Dist1[,Dist2[,Dist3 etc.]]\fP] \fIpkgname\fP
 .SH "DESCRIPTION"
-.LP 
+.LP
 whohas is a command line tool to query package lists from the Arch, Debian, Fedora, Gentoo, Mandriva, openSUSE, Slackware (and linuxpackages.net), Source Mage, Ubuntu, FreeBSD, NetBSD, OpenBSD, Fink, MacPorts and Cygwin distributions.
 .SH "OPTIONS"
-.LP 
-.TP 
+.LP
+.TP
 \fB\-\-no\-threads\fR
 Don't use multiple threads to query package lists (will be much slower)
-.TP 
+.TP
 \fB\-\-shallow\fR
 Limit to one call per server. Faster, but loses some information, typically package size and release date.
-.TP 
+.TP
+\fB\-\-strict\fR
+List only those packages that have exactly \fIpkgname\fP as their name.
+.TP
 \fB\-d Dist1[,Dist2[,Dist3 etc.]]\fR
 Queries only for packages for the listed distributions. Recognised values for Dist1, Dist2, etc. are "archlinux", "cygwin", "debian", "fedora", "fink", "freebsd", "gentoo", "mandriva", "macports", "netbsd", "openbsd", "opensuse", "slackware", "sourcemage", and "ubuntu".
-.TP 
+.TP
 \fBpkgname\fR
 Package name to query for
 .SH "FILES"
 .LP
 whohas uses various files in ~/.whohas to cache package lists for some distributions.
 .SH "SEE ALSO"
-.LP 
+.LP
 See \fIintro.txt\fP or \fIintro.html\fP notes on using whohas.
 .SH "AUTHORS"
 .LP 
