3 # search_packages.pl -- CGI interface to the Packages files on packages.debian.org
5 # Copyright (C) 1998 James Treacy
6 # Copyright (C) 2000, 2001 Josip Rodin
7 # Copyright (C) 2001 Adam Heath
8 # Copyright (C) 2004 Martin Schulze
9 # Copyright (C) 2004-2006 Frank Lichtenheld
11 # use is allowed under the terms of the GNU Public License (GPL)
12 # see http://www.fsf.org/copyleft/gpl.html for a copy of the license
18 print "Extremely blunt ends-with search results:<br><pre>";
19 # only thing implemented yet: ends-with search
20 my $kw = lc $cgi->param("keywords");
22 # FIXME: ensure $suite is sanitized
25 my $reverses = tie my %reverses, 'DB_File', "$DBDIR/contents/reverse_$suite.db",
26 O_RDONLY, 0666, $DB_BTREE
27 or die "Failed opening reverse DB: $!";
29 my ($key, $rest) = ($kw, "");
31 for (my $status = $reverses->seq($key, $value, R_CURSOR);
33 $status = $reverses->seq( $key, $value, R_NEXT)) {
35 # FIXME: what's the most efficient "is prefix of" thingy? We only want to know
36 # whether $kw is or is not a prefix of $key
37 last unless index($key, $kw) == 0;
39 @hits = split /\0/o, $value;
40 print reverse($key)." is found in @hits\n";
41 last if $nres++ > 100;
46 print "</pre>$nres results displayed";