#!/usr/local/bin/perl

#
# Copyright (c) 2002-2004 Eric Wallengren
# This file is part of the Continuous Automated Build and Integration
# Environment (CABIE)
#
# CABIE is distributed under the terms of the GNU General Public
# License version 2 or any later version.  See the file COPYING for copying
# permission or http://www.gnu.org.
#
# THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED OR
# IMPLIED, without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  ANY USE IS AT YOUR OWN RISK.
#
# Permission to modify the code and to distribute modified code is granted,
# provided the above notices are retained, and a notice that the code was
# modified is included with the above copyright notice.
#

#
# use packages...
#
use Sys::Hostname;

my $POSIX = 1;
my $hostname = hostname();
my $ostype;

if ($ =~ /MSWin32/) {
    $POSIX = 0;
    $ostype = "winsys";
} else {
    $ostype = "unixsys";
}

BEGIN {push @INC, "./lib";}

require "$ostype.pm";
require "$hostname.pm";

#
# Create instances of packages...
#
my $config   = new $hostname;
my $os       = new $ostype;

my $cgibin     = $config->CGIBIN;
my $logo       = $config->LOGOICON;

my $basename;
my $jobname;
my $port;

print("Content-Type: text/html\n\n");

$HtmlRequest = $ENV{"REQUEST_URI"};

_processHtmlRequest($HtmlRequest);

$ENV{"BLDSERVER"} = "$Server:$port";

print <<EOF;
<html><title>Build instructions for job $jobname</title>
<head></head>
<body bgcolor=#f0f0f0>
<img src="$logo" alt="LOGO" align=middle>
<hr>
<table><tr>
<pre>
EOF

@info = `/usr/bin/build instructions -n $jobname`;

foreach $line (@info) {
   print "$line";
}

print <<EOF;
</pre>
<hr>
<pre>
EOF

@info = `build describe -n $jobname`;

print "<b>Build Server Job Spec:</b>\n";
foreach $line (@info) {
   print "$line";
}

print <<EOF;
<pre>
</td></tr></table>
</body></html>
EOF


sub _processHtmlRequest() {

    ($basename, $jobname, $server, $port) = split(/\?/,$_[0]);
    $Server = lc($server);

}
