#!/usr/local/bin/perl

use CGI qw/:standard/;
$CGI::POST_MAX=1024 * 25;  # max 25K posts

print <<No_Script_Generation;
Content-type: text/html
Location: ../web_ver/web_ver.html

No_Script_Generation
exit(0);

sub allRect {
for ($i = 1; $i <= $NUMBER_RECTANGLES; $i++) {
  local $thisRectangle = 'Rect_'.$i.'_';
  $RectName = param($thisRectangle.'Name');
  $CoordVal = param($thisRectangle.'X').','.param($thisRectangle.'Y');
  $TrackVal = param($thisRectangle.'Track');
  $WidthVal = param($thisRectangle.'Wd');
  $HeightVal = param($thisRectangle.'Ht');
  $ColorVal = param($thisRectangle.'Col');
  &printRect;
} }

sub allOval {
for ($i = 1; $i <= $NUMBER_OVALS; $i++) {
  local $thisOval = 'Oval_'.$i.'_';
  $OvalName = param($thisOval.'Name');
  $CoordVal = param($thisOval.'X').','.param($thisOval.'Y');
  $TrackVal = param($thisOval.'Track');
  $WidthVal = param($thisOval.'Wd');
  $HeightVal = param($thisOval.'Ht');
  $ColorVal = param($thisOval.'Col');
  &printOval;
} }

sub allSprite {
for ($i = 1; $i <= $NUMBER_SPRITES; $i++) {
  local $thisSprite = 'Sprite_'.$i.'_';
  $SpriteName = param($thisSprite.'Name');
  $CoordVal = param($thisSprite.'X').','.param($thisSprite.'Y');
  $TrackVal = param($thisSprite.'Track');
  $FileVal = param($thisSprite.'ServerFile');
  &printSprite;
} }

sub allAnimEvent {
for ($i = 1; $i <= $NUMBER_ANIMEVENTS; $i++) {
  local $thisAnimEvent = 'AnimEvent_'.$i.'_';
  $AnimEventName = param($thisAnimEvent.'Name');
  $AnimationObject = param($thisAnimEvent.'Object');
  $AnimationAction = param($thisAnimEvent.'Action');
  &printAnimEvent;
} }

sub allLtsEvent {
for ($i = 1; $i <= $NUMBER_LTSEVENTS; $i++) {
  local $thisLtsEvent = 'LtsEvent_'.$i.'_';
  $LtsEventName = param($thisLtsEvent.'Name');
  $LtsAnimEvents = param($thisLtsEvent.'AnimEvents');
  &printLtsEvent;
} }

sub printRect {
  $Type_scp = "[Rectangle]\n";
  $Name_scp = "<Name>\n".$RectName."\n<End>\n";
  $Coord_scp = "<Coord>\n".$CoordVal."\n<End>\n";
  $Track_scp = "<Track>\n".$TrackVal."\n<End>\n";
  $Width_scp = "<Width>\n".$WidthVal."\n<End>\n";
  $Height_scp = "<Height>\n".$HeightVal."\n<End>\n";
  $Color_scp = "<Color>\n".$ColorVal."\n<End>\n";
  $EndType_scp = "[End Rectangle]\n";
  $_ = $Type_scp.$Name_scp.$Coord_scp.$Track_scp.$Width_scp.$Height_scp.$Color_scp.$EndType_scp;
  print OSCP;
}

sub printOval {
  $Type_scp = "[Oval]\n";
  $Name_scp = "<Name>\n".$OvalName."\n<End>\n";
  $Coord_scp = "<Coord>\n".$CoordVal."\n<End>\n";
  $Track_scp = "<Track>\n".$TrackVal."\n<End>\n";
  $Width_scp = "<Width>\n".$WidthVal."\n<End>\n";
  $Height_scp = "<Height>\n".$HeightVal."\n<End>\n";
  $Color_scp = "<Color>\n".$ColorVal."\n<End>\n";
  $EndType_scp = "[End Oval]\n";
  $_ = $Type_scp.$Name_scp.$Coord_scp.$Track_scp.$Width_scp.$HeightType_scp.$Color_scp.$EndType_scp;
  print OSCP;
}

sub printSprite {
  $Type_scp = "[Sprite]\n";
  $Name_scp = "<Name>\n".$SpriteName."\n<End>\n";
  $Coord_scp = "<Coord>\n".$CoordVal."\n<End>\n";
  $Track_scp = "<Track>\n".$TrackVal."\n<End>\n";
  $File_scp = "<File>\n".$FileVal."\n<End>\n";
  $EndType_scp = "[End Sprite]\n";
  $_ = $Type_scp.$Name_scp.$Coord_scp.$Track_scp.$File_scp.$EndType_scp;
  print OSCP;
}

sub printAnimEvent {
  $Type_scp = "[AnimEvent]\n";
  $Name_scp = "<Name>\n".$AnimEventName."\n<End>\n";
  $AnimationObject_scp = "<AnimationObject>\n".$AnimationObject."\n<End>\n";
  $EndType_scp = "[End AnimEvent]\n";
  $_ = $Type_scp.$Name_scp.$AnimationObject_scp.$EndType_scp;
  print OSCP;
}

sub printLtsEvent {
  $Type_scp = "[LtsEvent]\n";
  $Name_scp = "<Name>\n".$LtsEventName."\n<End>\n";
  $LtsAnimEvents_scp = "<AnimEvents>\n".$LtsAnimEvents."\n<End>\n";
  $EndType_scp = "[End LtsEvent]\n";
  $_ = $Type_scp.$Name_scp.$LtsAnimEvents_scp.$EndType_scp;
  print OSCP;
}

print <<Middle_of_Html_Document;
Content-type: text/html
Pragma: no-cache

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
   <META NAME="Author" CONTENT="Gaurav S. Kc">
   <META NAME="GENERATOR" CONTENT="Mozilla/4.06 [en] (WinNT; I) [Netscape]">
   <TITLE>Refreshing to manual pages ...</TITLE>
</HEAD>
<BODY TEXT="#FFFFFF" BGCOLOR="#330000" LINK="#000000" VLINK="#000000" ALINK="#000000">
<H1>There ain't nothin' in here now ... </H1>
<PRE>
Middle_of_Html_Document

# #####################################################################################

$NUMBER_RECTANGLES = param('NUMBER_RECTANGLES');
$NUMBER_OVALS = param('NUMBER_OVALS');
$NUMBER_SPRITES = param('NUMBER_SPRITES');
$NUMBER_ANIMEVENTS = param('NUMBER_ANIMEVENTS');
$NUMBER_LTSEVENTS = param('NUMBER_LTSEVENTS');

$Objects_scp = "[Objects]\n";
$Objects_End_scp = "[End Objects]\n";
$Events_scp = "[Events]\n";
$Events_End_scp = "[End Events]\n";
$Lts_scp = "[Lts]\n";
$Lts_End_scp = "[End Lts]\n";

$outputScript = "tmp/script.scp";
open (OSCP, ">$outputScript") or print("Cannot open file for output ...");

$_ = $Objects_scp;
print OSCP;

&allRect;

&allOval;

&allSprite;

$_ = $Objects_End_scp.$Events_scp;
print OSCP;

&allAnimEvent;

$_ = $Events_End_scp.$Lts_scp;
print OSCP;

&allLtsEvent;

$_ = $Lts_End_scp;
print OSCP;

close OSCP;
`chmod 777 $outputScript`;

# #####################################################################################

print "Rectangle: ".$NUMBER_RECTANGLES."\n";
print "Oval: ".$NUMBER_OVALS."\n";
print "Sprite: ".$NUMBER_SPRITES."\n";
print "AnimEvent: ".$NUMBER_ANIMEVENTS."\n";
print "LtsEvent: ".$NUMBER_LTSEVENTS."\n";

print <<End_of_Html_Document;
</PRE>
</BODY>
</HTML>

End_of_Html_Document
