#!/usr/local/bin/webwork-perl
############################################################
#	File: source.pl
#	Copyright:  WeBWorK 2000  all rights reserved
#	Description: 	This script will read, interpret, and output .html files
#                    containing .pg source code
############################################################


use lib '.'; use webworkInit; # WeBWorKInitLine
use strict;

use CGI qw(:standard);
use Global;

&CGI::ReadParse;
my %inputs = %main::in;

# get information from CGI inputs  (see also below for additional information)
	my $Course 			= param('course');

# establish environment for this script
	&Global::getCourseEnvironment($Course);

	my $htmlDirectory 	  		= getCourseHtmlDirectory();     		
	my $htmlURL           		= getCourseHtmlURL();           		

# get the rest of the information from the CGI script
my	$fileName = param('displayPath');

$fileName =~ /\.([^.]+)$/;
my $fileType = $1; 

my $headerString = <<EOT;
<HTML> 
<BODY BGCOLOR = "#ffffff"> 
<PRE> 
EOT

my $footerString = <<EOT;
</pre>
</body>
</html>
EOT




if ($fileType eq 'html') {
    my $filePath =  "${htmlDirectory}$fileName";
    open(INPUT, "<$filePath")||  print "content-type: text/plain\n\nCan't open $filePath\n";                        
    print "content-type: text/html\n\n";
    my $input ="";
    my $lineNumber = 0;
    print $headerString;
    #print "$filePath <br>";
    while (<INPUT>) {
        $input = $_;
        $input =~ s/</&lt;/g;
        $input =~ s/>/&gt;/g;
		print sprintf("%5.0d",++$lineNumber),": $input";
    }
    print $footerString;
	close(INPUT);
} else {
	&Global::error("Can't handle |$fileType| filetype yet");
}


exit;

