#!/usr/bin/perl -T

# driver program for Web-Learning-Project
# supports these types of arguments -
#    Q-filename    quoted file filename
#    W-codename    refer to wirefile for file assoc. w/ codename
#
# (c) burt rosenberg 1995, free to distribute
#

$error = 1 ;
$command = $ENV{'QUERY_STRING'} ;
print "Content-type: text/html\n\n";
if ( $command =~ /^Q-(.*)/ ) {
    #  a Quote type of command
    $file = "docs/$1.html" ; 
    open( DOCUMENT, $file ) ||
       die "<PRE>driver.pl: $file not found\n</PRE>" ;
    while (<DOCUMENT>) {
       print $_ ;
    }
    close(DOCUMENT) ;
    $error = 0 ;
}
if ( $command =~ /^W-(.*)/ ) {
    #  exchange name in the wire file
    $Stim = $1 ;
    open ( WIREFILE, "wire-file" ) ||
       die "<PRE>driver.pl: wire-file not found\n</PRE>" ;
    while (<WIREFILE>) {
       /^#/ && next ;
       if (/$Stim:(.*)/) {
         $Resp = $1 ;
         last ;
       }
    }
    if ($Resp eq "" ) {
       printf "<PRE>driver.pl: translation of $Stim failed.\n</PRE>" ;
    }
    else {
       $file = "docs/$Resp.html" ; 
       open( DOCUMENT, $file ) ||
          die "<PRE>driver.pl: $file not found\n</PRE>" ;
       while (<DOCUMENT>) {
          print $_ ;
       }
       close(DOCUMENT) ;
    }
    $error = 0 ;
}
if ($error) {
   print "<PRE>driver.pl: $command not understood.\n</PRE>" ;
}

