amyroh 01/05/31 17:24:22
Added: tester/web/WEB-INF/cgi array.pl binary.pl chores.pl
concat.pl days.pl dowhile.pl else.pl elsif.pl
exponents.pl for.pl getday.pl helloperl.pl if.pl
increment.pl modifyall.pl preference.pl
subparseform.lib subroutines.lib test-cgi.pl
Log:
Add CGI perl tests.
Revision Changes Path
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/array.pl
Index: array.pl
===================================================================
#!/usr/bin/perl
print "Content-type: text/html\n\n";
@days = ("Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday");
print "These are the days of the week:";
print "<p>";
print "@days";
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/binary.pl
Index: binary.pl
===================================================================
#!/usr/bin/perl
require "subparseform.lib";
&Parse_Form;
$counter = $formdata{'counter'};
$counter +=1;
print "Content-type: text/html\n\n";
print "<FONT SIZE=+2>If you add one to your number, the result is <B>$counter</B>";
$counter +=5;
print "<P>If you add 5 to that, the result is <B>$counter</B></FONT>";
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/chores.pl
Index: chores.pl
===================================================================
#!/usr/bin/perl
%chores = ("Monday", "vacuum", "Wednesday", "mop", "Friday", "wash windows");
print "Content-type: text/html\n\n";
foreach $day (keys (%chores)) {
print "<P>On $day, we have to $chores{$day}";
}
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/concat.pl
Index: concat.pl
===================================================================
#!/usr/bin/perl
require "subparseform.lib";
&Parse_Form;
$first = $formdata{'first_name'};
$married = $formdata{'fiance_last'};
$fullname = $first . " " . $married;
print "Content-type: text/html\n\n";
print "Congratulations! Your married name would be $fullname.";
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/days.pl
Index: days.pl
===================================================================
#!/usr/bin/perl
@days = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday",
"Sunday");
print "Content-type: text/html\n\n";
print "These are the days of the week:";
print "<P>";
print "@days";
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/dowhile.pl
Index: dowhile.pl
===================================================================
#!/usr/bin/perl
require "subparseform.lib";
&Parse_Form;
$start = $formdata{'start'};
print "Content-type: text/html\n\n";
print "<P>Starting countdown...";
do {
print "$start... ";
--$start;
} while ($start > 0);
print "KABOOM!";
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/else.pl
Index: else.pl
===================================================================
#!/usr/bin/perl
require "subparseform.lib";
&Parse_Form;
$food = $formdata{'food'};
print "Content-type: text/html\n\n";
if ($food eq "spinach") {
print "You ate spinach, so you get dessert!";
} else {
print "No spinach, no dessert!";
}
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/elsif.pl
Index: elsif.pl
===================================================================
#!/usr/bin/perl
require "subparseform.lib";
&Parse_Form;
$food = $formdata{'food'};
print "Content-type: text/html\n\n";
if ($food eq "spinach") {
print "You ate spinach, so you get dessert!";
} elsif ($food eq "broccoli") {
print "Broccoli's OK. Maybe you'll get dessert.";
} else {
print "No spinach, no dessert!";
}
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/exponents.pl
Index: exponents.pl
===================================================================
#!/usr/bin/perl
require "subparseform.lib";
&Parse_Form;
$number = $formdata{'number'};
$power = $formdata{'power'};
$result = $number ** $power;
print "Content-type: text/html\n\n";
print "<P>You entered $number with an exponent of $power";
print "<P>$number raised to the $power power is $result.";
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/for.pl
Index: for.pl
===================================================================
#!/usr/bin/perl
require "subparseform.lib";
&Parse_Form;
$start = $formdata{'start'};
print "Content-type: text/html\n\n";
print "<P>Starting countdown...";
for ($i = $start; $i > 0; --$i) {
print "$i... ";
}
print "KABOOM!";
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/getday.pl
Index: getday.pl
===================================================================
#!/usr/bin/perl
@days = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);
print "Content-type: text/html\n\n";
print "The first day of the week is $days[0]";
print "<P>The third day of the week is $days[2]";
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/helloperl.pl
Index: helloperl.pl
===================================================================
#!/usr/bin/perl
$t = "Hello World!";
print <<EOT;
Content-type: text/html
<Title> $t </Title>
<H1> $t </H1>
EOT
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/if.pl
Index: if.pl
===================================================================
#!/usr/bin/perl
require "subparseform.lib";
&Parse_Form;
$food = $formdata{'food'};
if ($food eq "spinach") {
print "Content-type: text/html\n\n";
print "You ate spinach, so you get dessert!\n";
}
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/increment.pl
Index: increment.pl
===================================================================
#!/usr/bin/perl
require "subparseform.lib";
&Parse_Form;
print "Content-type: text/html\n\n";
$counter = $formdata{'counter'};
++$counter;
print "Your number incremented by 1 is $counter";
$watch = ++$counter;
print "<BR>Your number, incremented again by 1, is now $counter. If we store that
operation, its value is also $watch.";
$counter = $formdata{'counter'};
print "<HR>Let's start over, with your original number $counter";
$counter++;
print "<BR>Again, your number incremented by 1 is $counter";
$watch = $counter++;
print "<BR>Now we store the value of your number in a second variable, which is now
equal to $watch, and then we increment your number again. It's now $counter.";
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/modifyall.pl
Index: modifyall.pl
===================================================================
#!/usr/bin/perl
require "subparseform.lib";
&Parse_Form;
@numbers = split(/,/, $formdata{'number'});
print "Content-type: text/html\n\n";
print "The numbers you entered were:";
foreach $number (@numbers) {
print "<LI>$number";
}
foreach $number(@numbers) {
$number = sqrt($number);
}
print "<P>The square roots of those numbers are: ";
foreach $number(@numbers) {
print "<LI>$number";
}
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/preference.pl
Index: preference.pl
===================================================================
#!/usr/bin/perl
$div = 40 / 5 + 3;
$parens = 40 / (5 + 3);
$subadd = 9 - 3 + 5;
$parens_subadd = 9 - (3 + 5);
print "Content-type: text/html\n\n";
print "div is $div, parens is $parens, subadd is $subadd and parens_subadd is
$parens_subadd";
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/subparseform.lib
Index: subparseform.lib
===================================================================
sub Parse_Form
{
if ($ENV{'REQUEST_METHOD'} eq 'GET')
{
@pairs = split(/&/, $ENV{'QUERY_STRING'});
}
elsif ($ENV{'REQUEST_METHOD'} eq 'POST')
{
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
if ($ENV{'QUERY_STRING'})
{
@getpairs =split(/&/, $ENV{'QUERY_STRING'});
push(@pairs,@getpairs);
}
}
else
{
print "Content-type: text/html\n\n";
print "<P>Use Post or Get";
}
foreach $pair (@pairs)
{
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~s/<!--(.|\n)*-->//g;
if ($formdata{$key})
{
$formdata{$key} .= ", $value";
}
else
{
$formdata{$key} = $value;
}
}
}
1;
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/subroutines.lib
Index: subroutines.lib
===================================================================
#!/usr/local/bin/perl;
sub cap {
$captext = $_[0];
$captext =~ tr/a-z/A-Z/;
return $captext;
}
sub which {
$browser = $ENV{'HTTP_USER_AGENT'};
if ($browser =~ /MSIE/) {
$browser = "Explorer";
} elsif ($browser =~/Mozilla/) {
$browser = "Netscape";
} else {
$browser = "something besides Netscape and Explorer";
}
}
sub header {
print "<HTML><HEAD><TITLE>";
print "$_[0]";
print "<TITLE><HEAD><BODY>"
}
sub footer {
print "<BODY><HTML>";
}
sub mime {
print "Content-type: text/html\n\n";
}
1;
1.1 jakarta-tomcat-4.0/tester/web/WEB-INF/cgi/test-cgi.pl
Index: test-cgi.pl
===================================================================
#!/usr/local/bin/perl
#
# @(#)test-cgi.pl 1.2 98/05/28
#
# Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software
# and its documentation for NON-COMMERCIAL purposes and without
# fee is hereby granted provided that this copyright notice
# appears in all copies. Please refer to the file "copyright.html"
# for further important copyright and licensing information.
#
# SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
# THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
# TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
# ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
# DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
#
print <<EOM;
Content-type: text/html
<html>
<head><title>CGI Test</title></head>
<body>
<h1>CGI Test</h1>
<pre>
EOM
print "argc is " . ($#ARGV + 1) . "\n\n";
print "argv is\n";
for($i = 0; $i<($#ARGV+1); $i++) {
print $ARGV[$i] . "\n";
}
print "\n";
foreach $key (sort keys %ENV) {
print("$key: $ENV{$key}\n");
}
print <<EOM;
</pre>
</body>
</html>
EOM
close OUT;