X-Git-Url: https://git.einval.com/cgi-bin/gitweb.cgi?p=debian-cd-search.git;a=blobdiff_plain;f=find_file_db.pl;h=36e9d3e924145693ebf111f2dd8ede74a0fa7f16;hp=8d41f0a5689bc6f330daf92ea2abda69dd16e350;hb=25f7da68db6407171975a3f2b43e66b65bf360f3;hpb=80685018a954c23d77970721a624dec83c38e71b diff --git a/find_file_db.pl b/find_file_db.pl index 8d41f0a..36e9d3e 100755 --- a/find_file_db.pl +++ b/find_file_db.pl @@ -30,6 +30,7 @@ my %num_files; my %fileinfo; my %imageinfo; my @results; +my $max_count = 1000; # Borrowed from Ikiwiki.pm sub glob2re ($) { @@ -52,6 +53,7 @@ if (!defined($query_term) || !length($query_term)) { die "No query term specified!\n"; } +my $count = 0; my $re_search = glob2re($query_term); foreach my $area (@AREAS) { @@ -59,16 +61,34 @@ foreach my $area (@AREAS) { my $db_file_name = "$dbdir/$area.db"; dbmopen(%fileinfo, "$db_file_name", 0000) || die "Failed to open db file: $!\n"; - foreach my $file (keys %fileinfo) { - if ($file =~ $re_search) { - push(@results, "$file $fileinfo{$file}"); + + if ($query_term =~ /[\*\?]/) { + # Will need to search through all the keys to allow for glob + foreach my $file (keys %fileinfo) { + if ($file =~ $re_search) { + $count++; + push(@results, "$file $fileinfo{$file}"); + if ($count >= $max_count) { + last; + } + } } + } else { + # We've been given an exact name - do the exact key lookup \o/ + push (@results, "$query_term $fileinfo{$query_term}"); + } + if ($count >= $max_count) { + last; } dbmclose %fileinfo; } -my $count = scalar(@results); -print "$count results for \"$query_term\":\n"; +if ($count >= $max_count) { + print "More than $max_count results for \"$query_term\", showing the first $count only\n"; +} else { + print "$count results for \"$query_term\":\n"; +} + foreach my $result (sort (@results)) { my($found, @list) = split(' ', $result); print " $found:\n";