#!/usr/bin/perl
#
# Name : Dict
# Purpose: perl script cgi program to submit dict queries.
# Author : Doug L. Hoffman (hoffman@shopthenet.net)
# Created: Thu Aug 14 09:51:28 1997 by hoffman
# Revised: Mon Mar 30 12:25:38 1998 by hoffman
#
# This perl script both generates the www-browser form and accepts the results
# of submitting the form. The search is transmitted to a central machine
# and the results are interpreted and reposted for the user.
#
# $Log: Dict,v $
# Revision 1.11 1998/03/30 17:33:26 hoffman
# added text of query to the web page title line.
#
# Revision 1.10 1998/02/23 17:46:04 hoffman
# Fixed problem with word list anchors caused by changes to the "exact"
# resopnse.
#
# Revision 1.9 1998/02/23 16:41:30 hoffman
# Made "exact" return list of words, not definitions.
#
# Revision 1.8 1998/02/20 16:00:01 hoffman
# gave the generated page(s) a general facelift, changed internal processing
# to use the short database name, not the description, and then spent time
# fixing various bugs that the name change caused. The server calls to fetch
# the search and database options have been combined into one.
#
# Revision 1.7 1998/02/19 15:10:26 hoffman
# Rik's updated version.
#
# Revision 1.6 1997/11/12 16:07:50 hoffman
# Added link to copyright info.
#
# Revision 1.5 1997/10/01 17:50:58 hoffman
# Fixed some of the field edits for Rik.
#
# Revision 1.4 1997/10/01 13:56:52 hoffman
# fixed problem with ()'s
#
# Revision 1.3 1997/08/17 20:48:04 hoffman
# added link to dict.org home page
#
# Revision 1.2 1997/08/17 20:07:37 hoffman
# Fixed imbedded blank sequence query scanning.
#
#
# Setup is minimal.
#
# You have to redefine at most the first few lines below
#
# $ReturnUrl is the url of this file. It should be changed to reflect
# the new location.
# ---------- Configuration variables
$Debug = 0;
$Pgm = "dict";
#$hostUrl = "http://www.dict.org";
$hostUrl = "http://10.30.202.24";
$cgiPath = "$hostUrl/mgw";
$ReturnUrl = "$cgiPath/$Pgm";
$bin = "/usr/bin/";
$CRInfo = "$ReturnUrl?Form=$Pgm".
"1&Query=00-database-info&Strategy=*&Database=*";
$SInfo = "$ReturnUrl?Form=$Pgm". "4";
$Dict = "/usr/bin/dict -h 10.30.202.24";
$Counter = "/usr/local/etc/Counter/data/$Pgm.dat";
$Count = "$cgiPath/Count.cgi";
$Background = "/gifs/grayback.jpg";
$Heading1= "The DICT Development Group: Online Dictionary Query";
$Heading2= "The DICT Development Group: Online Dictionary Query";
$Counter1= "";
$Counter2= "";
# $Counter1= "";
# $Counter2= "";
$WebMaster="webmaster\@dict.org";
# --- display stuff
##########################################################################
#
# Driving Program
#
#########################################################################
&init; # init globals
&ReadParse; # read stdin
#
#
# If there is no standard input, this the the users first request to see
# the page. Return a decent looking page. Otherwise, you have work to do.
#
if ($in{"Form"} eq "") {
$in{"Database"} = "*";
$in{"Strategy"} = "*";
print &PrintHeader();
&SendBeginning;
&SendForm1;
&SendEnding;
}
elsif ($in{"Form"} eq ($Pgm . '1')) {
print &PrintHeader();
&SendBeginning;
&StripFields; # clean up user entered data.
&CheckFields; # Make sure all required data are there.
&SendForm1;
if ($Error eq "") {
&SendListing;
}
&SendEnding;
}
elsif ($in{"Form"} eq ($Pgm . '2')) {
$in{"Strategy"} = "*";
print &PrintHeader();
&SendBeginning;
&StripFields; # clean up user entered data.
&CheckFields; # Make sure all required data are there.
&SendForm1;
if ($Error eq "") {
&SendListing;
}
&SendEnding;
}
elsif ($in{"Form"} eq ($Pgm . '3')) {
$in{"Strategy"} = "";
$in{"Query"} = "";
print &PrintHeader();
&SendBeginning;
&StripFields; # clean up user entered data.
# &CheckFields; # Make sure all required data are there.
&SendForm1;
if ($Error eq "") {
&SendListing;
}
&SendEnding;
}
elsif ($in{"Form"} eq ($Pgm . '4')) {
$in{"Strategy"} = "";
$in{"Query"} = "";
print &PrintHeader();
&SendBeginning;
&StripFields; # clean up user entered data.
# &CheckFields; # Make sure all required data are there.
&SendForm1;
if ($Error eq "") {
$in{"Query"} = "Server";
&SendListing;
}
&SendEnding;
}
else {
print &PrintHeader();
&SendBeginning;
print "
\n";
return;
}
$count = \n";
return;
}
print CT $count;
close CT;
}
}
# ---------- Strip fields
#
# change tabs and stuff to blanks, strip any leading/trailing blanks.
#
sub StripFields {
foreach $x (@Fields) {
$in{$x} =~ y/{};/() /; # ensure no {, },",", or ";".
$in{$x} =~ y/\n\r\f\t\e/ /s; # ensure newlines or cr's.
$in{$x} =~ s/\'/\'\'/g;
$in{$x} =~ s/^\s*//;
$in{$x} =~ s/\s*$//;
$in{$x} =~ s/\s+/ /g;
}
}
#
# ---------- Check that the required fields are all present.
#
sub CheckFields {
$Error = "";
foreach $x (@ReqFields) {
if ($in{$x} eq "") {
$Error = $x;
return;
}
}
}
#############################################################################
#
# ---------- Send the html form for the editing of a record
#
sub SendForm1 {
# ----- send the header
#
local($q) = $in{"Query"};
print <