#!/usr/bin/perl

use CGI qw(:standard);
use CGI::Carp qw/fatalsToBrowser/;

my($cgiObj)= new CGI;
print $cgiObj->header();
$ARGV[0] = $cgiObj->param('name');
$fileroot = "/home/rizwank/";
$enscript_path = "/home/rizwank/bin/enscript ";

print $cgiObj->h3("geekymedia.com code colorizer - $ARGV[0]");
print "<br>All code (C) Rizwan Kassim 1998-2005 unless otherwise noted.<br>"
print "Insert CCL here<p>"
print "<hr>"

# ok I stole directly from SyntaxHighlightingPlugin.pm for Twiki

my $highlighted = pipeThru("enscript --color --language=html --highlight=$langs{lc($lang)} -o - -q", $text);
    
if ($highlighted =~ s/.*\<PRE\>\n(.*?)\n?\<\/PRE\>.*/$1/os)
{
    if ($nb_option eq " numbered")
	{
	    my $line = ($nb_start eq "") ? 1 : $nb_start;
	    $highlighted =~ s/(^.*)/sprintf("<b><font color=\"#000000\">%5d<\/font><\/b>\t%s", $line++, $1)/mgeo
	}
	print "<table width=\"100%\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\"><tr><td bgcolor=\"#FFFFFF\"><pre>".$highlighted."</pre><\/td><\/tr><\/table>";
}	
else
{
	print "<font color=\"red\"> Syntax Highlighting: internal error  </font>";
}
    
    
system "/home/rizwank/bin/enscript /home/rizwank/                   '--color', '--language=html', '-E' + lang, '-o',
                               '-', '-'),
                              ('sed', '-n', '/^<PRE>$/,/<\\/PRE>$/p')])
