#!/usr/bin/perl # system ("(echo dir is `pwd`; echo args are @ARGV; printenv) > /tmp/dbg.$$"); $ENV{'PATH'} = '/bin:/usr/bin:/usr/local/bin/'; use Sys::Syslog qw(openlog syslog closelog); require 'cgi_handlers.pl'; get_request(); $max_happy = 3; # if ($search_string =~ /lf$/ ) { $search_string =~ s/f$/(f|ves)/; } $search_string = $rqpairs{'cardname'}; $title = "Query Results for ``$search_string''"; #html_header("Query Results for $search_string"); print "Content-type: text/html\n\n"; openlog("pickcards", "cons,pid", "daemon"); sub print_header { return if $header_printed++; #print "\n"; print "$title\n"; print "

$title

\n"; print "\n\n"; } if (!$search_string) { print "No search string specified!\n"; } else { match("Exact" => '-w' ); match("Partial" => '' ); my $real = $good; match("Dubious" => '-1' ) if $good < $max_happy; match("Desperate" => '-B -y') if !$real; # match("Dubious" => '-2' ) if $good < $max_happy; unless ($good) { print "Sorry, no matches for ``$search_string''.\n"; } } syslog("info", "selected %d cards for `%s' (%s)", $good, $search_string, $match); closelog(); print "

Generated on ", `date`, ".\n\n"; sub match { my ($string, $opts) = @_; my @opts = ('-i'); push(@opts, split(' ', $opts)); #print "agrep -i $opts '$search_string' CardNames\n"; my @ok = (); if (open(AGREP, "-|")) { while () { chop; next if /^#/; s/ #.*//; push(@ok, $_); } } else { exec 'agrep', @opts, $search_string, 'CardNames'; } my $printed_now; if (@ok == 1 && !$header_printed) { my $file = safename($ok[0]); syslog("info", "selected $ok[0] for `%s'", $search_string); if (1) { open (F, "< $file") || die "can't open $file: $!"; print ; exit; } else { print "Location: $file\n"; exit; } } print_header() if @ok; for (sort @ok) { next if $seen{$_}++; $good++; print "

$string matches

\n" if @ok; if (@ok) { $match .= "$string " . @ok . " "; } } sub safename { local($_) = shift; s/'//g; tr/a-zA-Z \-/a-za-z_-/d; #return "http://mox.perl.com/CARDS/$_.html"; return "/deckmaster/cards/$_.html"; } sub diacriticals { s/\bMa'?ruf\b/Márûf/; s/\bDandan\b/Dandán/g; s/\bGhazban\b/Ghazbán/g; s/\bKhabal\b/Khabál/g; s/\bJunun\b/Junún/g; s/\bJuzam\b/Juzám/g; s/\bEl-Hajjaj\b/El-Hajjâj/g; s/\bAErathi\b/Ærathi/g; s/\bAE\b/Æ/g; }