#!/usr/local/bin/perl

# part of NCSA Doc Finder suite.
# This is public domain code from NCSA>
# Jason NG NCSA May 1994
#
# When this script is invoked with no args, a HTML doc is displayed,
# prompting the user to type in a search string/phrase.
# Otherwise, the inputs are used to lookup the files conatining them, and a 
# list of names of those files are returned.

# ===== These variables should be modified to suit your site.

# waissearch - the waissearch program (a freeWais program). 
# makehtml   - the makehtml filter (C executable) written by me.
# manindex   - the index-table file created for your man pages.
#              (created by waisindex - another freeWais program).
# mylink     - link to info on author, site, or additional help. Optional.

$waissearch  = "/usr/docfinder/bin/waissearch";
$makehtml    = "/usr/docfinder/bin/jwais-html";
$manindex    = "/usr/docfinder/db/webdb";
$mylink      = "http://www.ncsa.uiuc.edu/SDG/People/jason/pub/jason-bio.html";

# Nothing else after this needs changing.

# =======================================================
sub doit
{

$myword = join(' ',@_);
$myword =~ s!%28!(!;  #replace escaped left parens with parens
$myword =~ s!%29!)!;  #replace escaped right parens with parens

print "<TITLE> wais search on (${myword}) </TITLE>\n";

$mycmd = " ${waissearch} -m 99 -d ${manindex} ${myword} < /dev/null | ${makehtml} ${myword} ";
open(OUTP,"$mycmd |"); while(<OUTP>) { print $_; }
close(OUTP);
}

# ==================================================================

sub showfrontpage
{
 
print " <H1> Base NCSA HTML docs finder </H1> <HR> <p>\n";
print " So you've forgotten which NCSA document you want to pull up, but you
vaguely remember a few words. Go ahead and type in those words in the text entry box, separated
by <b> AND </b>. ";
print "<p> Eg try </b> <i>bits AND pieces</i> <b>or</b> <i>urn</i> <b>or</b> <i>party  </i>.";

print " <ISINDEX> <p> "; 
print " <p> <A HREF= \"$mylink\"> jn </A> \n";

}

# START---------------------- 

open (STDERR, ">/tmp/errs");
$nargs = @ARGV;
print "Content-type: text/html\n\n";

if($nargs==0) { &showfrontpage; }
else { &doit(@ARGV); }

# ==================================================================
