User Interface Module


The Danish user interface consists of an HTML form posting to a Perl CGI script. The user enters the names of the input files through the HTML form, and those names are passed to the CGI script, where all of the action takes place.

The HTML form consists of file input tags (for the user file names), a radio input tag (for the report length selection), and the standard submit and reset buttons. To learn more about HTML, try one of the many tutorials on the web.

The HTML form posts to the CGI script on the wwwx.cs.unc.edu server, which is currently "capefear". To learn more about Perl, try this on-line man page. The CGI script performs the following steps:

  1. Set directory paths
  2. Create header for results web page
  3. Check for all required files
  4. Copy user's files to local temp directory
  5. Run Danish
  6. Compile, run and display results of Danish
  7. Clean up local directory

Web Page Source Code

<HTML>
<HEAD>
<TITLE>Java Tester User Interface
</TITLE>
</HEAD>

<BODY BGCOLOR="#FFFFFF">
<A HREF="../index.html" TARGET="_top">
<IMG SRC="../gifs/javalogo.gif" ALT="Java " BORDER="no"></A>
<FONT COLOR="#3333cc"><BR>
<B>Tester</B></FONT>
<HR>

<CENTER>

<FORM METHOD="POST" ACTION="http://wwwx.cs.unc.edu/~stotts/COMP145/homes/taster/gui/gui_query.cgi">

<TABLE>

<TR VALIGN="bottom">
<TD>
<B>Java Class File</B><BR>
<INPUT TYPE="FILE" SIZE="13" NAME="JavaIn">
</TD>

<TD>
<B>Axiom File</B><BR>
<INPUT TYPE="FILE" SIZE="13" NAME="AxiomIn">
</TD>
</TR>

<TR VALIGN="bottom">
<TD><FONT COLOR="#3333CC">
<B>Vector File</B><BR>
<INPUT TYPE="FILE" SIZE="13" NAME="VectorIn">
</FONT>
</TD>

<TD><FONT COLOR="#3333CC">
<B>Alias File</B><BR>
<INPUT TYPE="FILE" SIZE="13" NAME="AliasIn">
</FONT>
</TD>
</TR>

<TR VALIGN="bottom">
<TD><FONT COLOR="#3333CC">
<B>Signature File</B><BR>
<INPUT TYPE="FILE" SIZE="13" NAME="SigIn">
</FONT>
</TD>

<TD>   
<FONT COLOR="#3333CC">
<B>Import File</B><BR>
<INPUT TYPE="FILE" SIZE="13" NAME="ImportIn">
</FONT>
</TD>  
</TR>

<TR>
<TD>
<B>Report Format:</B>
<INPUT TYPE="RADIO" NAME="VerboseIn" VALUE="off" CHECKED>Short
<INPUT TYPE="RADIO" NAME="VerboseIn" VALUE="on">Long<BR>
</TD>
  
<TD>
<FONT COLOR="#3333CC">
<B>Resource File</B><BR>
<INPUT TYPE="FILE" SIZE="13" NAME="RcIn">
</FONT>
</TD>  
</TR>
  
<TR>
<TD>
<INPUT TYPE="SUBMIT" VALUE="Run Java Tester">
<INPUT TYPE="RESET" VALUE="Reset Form">
</TD>

</TR>

</TABLE>
</FORM>
</CENTER>

</BODY>
</HTML>


CGI Script Source Code

#!/usr/local/bin/perl

#########################################################################
#
# gui_query.cgi          Comp 145         Java Tester team      Spring '98
#
# This CGI script is called by gui.html and acts as a front-end for
# the Java testing program, danish.
#
# Directory paths may need to be changed if this file is moved or the
# Java library gets relocated.
#
# This program copies files from the user's computer to the /tmp directory
# of capefear.  Next, it invokes danish, which creates a test suite
# program.  That program gets compiled and run, with the results displayed
# to the user's browser.
#
# Possible improvements (which we did not have time to address) include
# allowing access from non-Unix browsers, giving a non-HTML option for
# the report format, and adding security measures such as password and
# registration.
############################################################################

require "cgi-lib.pl";

##########################################################################
#
# Directory paths

$ENV{"PATH"} .= ":/afs/cs.unc.edu/project/courses/comp145/s98/taster/final";

$temp = "/tmp";
$javahome = "http://www.cs.unc.edu/~stotts/COMP145/homes/taster/index.html";
$javalogo = "http://www.cs.unc.edu/~stotts/COMP145/homes/taster/gifs/javalogo.gif";
$contract = "/afs/cs.unc.edu/project/courses/comp145/s98/taster/final/contract.java";
$gui = "http://www.cs.unc.edu/~stotts/COMP145/homes/taster/gui/gui.html";
$leftgif = "http://www.cs.unc.edu/~stotts/COMP145/homes/taster/gifs/left.gif";
$classpath = "$temp:/afs/cs.unc.edu/pkg/JDK/1.1/sparc_solaris/lib/classes.zip";
$compile = "/usr/local/bin/javac";
$run = "/usr/local/bin/java";

&ReadParse;

##########################################################################
#
#set up result web page header

print "Content-type: text/html\n\n";
print <<EOF;
<HTML>
<HEAD>
<TITLE>
Java Tester Results
</TITLE>
</HEAD>

<BODY BGCOLOR="#FFFFFF">
<A HREF="$javahome"><IMG SRC="$javalogo" BORDER="no"></A><BR>
<FONT COLOR="#3333CC"><B>Tester</B></FONT>
<HR>
Go to <A HREF=#Summary>Summary</A><HR>
EOF

##########################################################################
# 
#get file names, make sure have all necessary files
 
#printf(qq!Report format is verbose $in{"VerboseIn"}.<BR>!);

if ($in{"RcIn"} ne "")  {
 open(RCFILE, qq!<$in{"RcIn"}!) || 
 &myDie(qq!<HR>Error opening Resource file $in{"RcIn"}.<BR>!);
 
 #pick up directory name from RcIn to splice onto front of file name      
 $rin = rindex $in{"RcIn"},"/";
 if ($rin == -1)  {
   $rin = rindex $in{"RcIn"}, "\\";
 }
 $rcdir = substr $in{"RcIn"}, 0, $rin + 1;
 $rcJC = "false";
 $rcIM = "false";

 while (<RCFILE>) {
  $parameters = " " . $_;
  if (($parameters =~ s/\s+-j\s*(\S+)\s*/ /) && ($in{"JavaIn"} eq "")) {
    $in{"JavaIn"} = $rcdir . substr $_, 3;
    $rcJC = "true";
  }
  if (($parameters =~ s/\s+-x\s*(\S+)\s*/ /) && ($in{"AxiomIn"} eq "")) {   
    $in{"AxiomIn"} = $rcdir . substr $_, 3;
  }
  if (($parameters =~ s/\s+-a\s*(\S+)\s*/ /) && ($in{"AliasIn"} eq "")) {
    $in{"AliasIn"} = $rcdir . substr $_, 3;
  }
  if (($parameters =~ s/\s+-s\s*(\S+)\s*/ /) && ($in{"SigIn"} eq "")) {
    $in{"SigIn"} = $rcdir . substr $_, 3;
  }
  if (($parameters =~ s/\s+-v\s*(\S+)\s*/ /) && ($in{"VectorIn"} eq "")) {
    $in{"VectorIn"} = $rcdir . substr $_, 3;
  }
  if (($parameters =~ s/\s+-i\s*(\S+)\s*/ /) && ($in{"ImportIn"} eq "")) {
    $in{"ImportIn"} = $rcdir . substr $_, 3;
    $rcIM = "true";
  }
 }
 close(RCFILE);
# print qq!Resource file -- $in{"RcIn"}<BR>!;
}
#else {
#  print "You did not specify a Resource file.<BR>";
#}

@ReqFiles = ( "JavaIn", "AxiomIn", "SigIn", "VectorIn" );
foreach $x (@ReqFiles) {
  if ($in{$x} eq "") {
    &myDie("<HR>Missing required file.<BR>");
  }
}  

###########################################################################
# 
#copy all files to capefear $temp directory
 
#pick up Java Class name
$jcin = rindex $in{"JavaIn"},"/";
if ($jcin == -1)  {
  $jcin = rindex $in{"JavaIn"}, "\\";
}
$jcfile = substr $in{"JavaIn"},$jcin+1;
if ($rcJC eq "true")  {
  $len = (length $jcfile) - 1;
  $jcfile = substr $jcfile,0,$len; 
} 

&copyFile($contract, $temp."/contract.java", "Contract");
&copyFile($in{"JavaIn"}, $temp."/".$jcfile, "Java Class");
&copyFile($in{"AxiomIn"}, $temp."/axioms.d", "Axiom");
&copyFile($in{"SigIn"}, $temp."/signatures.d", "Signature");
&copyFile($in{"VectorIn"}, $temp."/points.d", "Vector");

if ($in{"AliasIn"} ne "")  {
  &copyFile($in{"AliasIn"}, $temp."/alii.d", "Alias");
}  
#else {
#  print "You did not specify an Alias file.<BR>";
#} 
  
if ($in{"ImportIn"} ne "")  {
  #pick up Import Class name
  $imin = rindex $in{"ImportIn"},"/";
  if ($imin == -1)  {
    $imin = rindex $in{"userfile"}, "\\";
  }
  $imfile = substr $in{"ImportIn"},$imin+1; 
  if ($rcIM eq "true")  {
    $len = (length $imfile) - 1;
    $imfile = substr $imfile,0,$len;
  }
  &copyFile($in{"ImportIn"}, $temp."/".$imfile, "Import");
} 
#else {
#  print "You did not specify an Import file.<BR>";
#}


#############################################################################
#
# call danish

$dscommand = "danish -web -o $temp/tester.java";
    
if ($in{"AliasIn"} ne "") {
  $dscommand .= " -a $temp/alii.d";
}

if ($in{"ImportIn"} ne "") {
  $dscommand .= " -i $temp/$imfile";
}

if ($in{"VerboseIn"} eq "on") {  
  $dscommand .= " -dump";
}
 
$dscommand .= " -s $temp/signatures.d -v $temp/points.d -j $temp/$jcfile $temp/axioms.d";

#print "Running: $dscommand<BR><HR>";
open( IN, "$dscommand 2>&1 |");    
while (<IN>)  {
  print;
  print "<BR>";
}
if ($in{"VerboseIn"} eq "on") {
  print "<HR>";
}
close(IN);

##########################################################################
#  
# compile contract.java, $jcfile, $imfile, tester.java.  Run tester,
# display results
   
 $cmd = "$compile ";
 if ($in{"ImportIn"} ne "")  {
   #also have to put import file in compile line
   $cmd .= "$temp/$imfile ";
 }
 $cmd .= "$temp/$jcfile $temp/contract.java $temp/tester.java";
# print "Compiling: $cmd<HR>";

 open( IN, "$cmd 2>&1 |") || die "Can't compile java.<BR>";
 while (<IN>) {
   print;
 } 
 close(IN);
  
 $cmd = "$run -classpath $classpath tester";
 if ($in{"VerboseIn"} eq "on")  {
   $cmd .= " -verbose";
 }
# print "Running: $cmd<HR>";
 open( IN, "$cmd 2>&1 |");
 while (<IN>)  {
    if ((index $_, "Summary") != -1) {
      print qq!<HR><H2><FONT COLOR="#3333CC"><A NAME=Summary>!;
      print;
      print "</FONT></H2>";
    }
    else {
      if ((index $_, "failed") != -1) {
        print qq!<FONT COLOR="#FF0022">!;
        print;
        print "</FONT><BR>";
      }
      else {
        print;
        print "<BR>";
      }
    }
 }
 close(IN);

############################################################################
#
# rm all the files we created
  
$jclen = length $jcfile;
$jcclass = substr $jcfile,0,$jclen - 4;
$jcclass .= "class";
$rmcommand = "rm $temp/tester.java $temp/signatures.d $temp/points.d $temp/axioms.d $temp/$jcfile";
$rmcommand .= " $temp/tester.class $temp/contract.java $temp/contract.class $temp/$jcclass";
#print "<HR> $rmcommand<BR>";
open( IN, "$rmcommand 2>&1 |");
   
if ($in{"ImportIn"} ne "") {
  $imlen = length $imfile;
  $imclass = substr $imfile,0,$imlen - 4;
  $imclass .= "class";
  $rmcommand = "rm $temp/$imfile $temp/$imclass";
#  print "$rmcommand<BR>";
  open( IN, "$rmcommand 2>&1 |");
} 

if ($in{"AliasIn"} ne "") {
  $rmcommand = "rm $temp/alii.d";
#  print "$rmcommand<BR>";
  open( IN, "$rmcommand 2>&1 |");
}
   
&printEnd;
 
############################################################################
#
# exit with error message
   
sub myDie($errormsg) {
  print @_;
  &printEnd;
  die;
}

############################################################################
#
# set up bottom of result web page
    
sub printEnd {
  print <<EOF;
<HR>
        
<A HREF="$gui">
<IMG SRC="$leftgif">
</A>
Back to User Interface
       
</BODY>
</HTML>
EOF

die;
}

############################################################################
#
# copy user's file to $temp directory  

sub copyFile($file, "$temp/file", "file type") {
 open(FILEIN, "<$_[0]") ||  
   &myDie("<HR>Error opening $_[2] file $_[0].<BR>");
 open(FILEOUT, ">$_[1]") ||  
   &myDie("<HR>Error copying $_[2] file $_[1].<BR>");

 while (<FILEIN>) {
   print FILEOUT;
 }
  
 close(FILEIN);
 close(FILEOUT);
# print "$_[2] file -- $_[0]<BR>";
}


GotoPrevious Topic GotoNext Topic
Created 04/08/98 by knight
Revised 04/30/98