#!/usr/local/bin/perl # # wais.pl -- WAIS search interface # # wais.pl,v 1.2 1994/04/10 05:33:29 robm Exp # # Tony Sanders , Nov 1993 # # Example configuration (in local.conf): # map topdir wais.pl &do_wais($top, $path, $query, "database", "title") # $waisq = "/usr/local/bin/waisq"; $waisd = "/u/Web/wais-sources"; $src = "www"; $title = "NCSA httpd documentation"; sub send_index { print "Content-type: text/html\n\n"; print "\nIndex of ", $title, "\n\n"; print "\n

", $title, "

\n"; print "This is an index of the information on this server. Please\n"; print "type a query in the search dialog.\n

"; print "You may use compound searches, such as: environment AND cgi\n"; print ""; } sub do_wais { # local($top, $path, $query, $src, $title) = @_; do { &'send_index; return; } unless defined @ARGV; local(@query) = @ARGV; local($pquery) = join(" ", @query); print "Content-type: text/html\n\n"; open(WAISQ, "-|") || exec ($waisq, "-c", $waisd, "-f", "-", "-S", "$src.src", "-g", @query); print "\nSearch of ", $title, "\n\n"; print "\n

", $title, "

\n"; print "Index \`$src\' contains the following\n"; print "items relevant to \`$pquery\':

\n"; print "

\n"; local($hits, $score, $headline, $lines, $bytes, $type, $date); while () { /:score\s+(\d+)/ && ($score = $1); /:number-of-lines\s+(\d+)/ && ($lines = $1); /:number-of-bytes\s+(\d+)/ && ($bytes = $1); /:type "(.*)"/ && ($type = $1); /:headline "(.*)"/ && ($headline = $1); # XXX /:date "(\d+)"/ && ($date = $1, $hits++, &docdone); } close(WAISQ); print "
\n"; if ($hits == 0) { print "Nothing found.\n"; } print "\n"; } sub docdone { if ($headline =~ /Search produced no result/) { print "
"; print $headline, "

\n

";
# the following was &'safeopen
        open(WAISCAT, "$waisd/$src.cat") || die "$src.cat: $!";
        while () {
            s#(Catalog for database:)\s+.*#$1 $src.src#;
            s#Headline:\s+(.*)#Headline: $1#;
            print;
        }
        close(WAISCAT);
        print "\n
\n"; } else { print "
$headline\n"; print "
Score: $score, Lines: $lines, Bytes: $bytes\n"; } $score = $headline = $lines = $bytes = $type = $date = ''; } open (STDERR,"> /dev/null"); eval '&do_wais';