A
alexjaquet
Hi,
I'm trying to use Syntax::Highlight:erl but the problem I get is when
I print the result I didn't get carriage return between lines.
thx
Here my script :
#!c:/Perl/bin/perl.exe
#usage
http://avant-garde.no-ip.biz/cgi-bin/edit.cgi?action=edit&filename=edit.cgi&dir=C:\Apache2\cgi-bin/
use strict;
use CGI;
use Syntax::Highlight:erl;
local our $query = CGI->new ;
local our $action = $query->param("action");
local our $dir = $query->param("dir");
local our $filename = $query->param("filename");
local our %VALUE;
local our $current_dir = "C:/Apache2/htdocs/edit";
local our $filedir = "C:/Apache2/cgi-bin/";
if ($action eq "edit") {edit(); }
elsif ($action eq "save") {save(); }
sub edit {
local our $content;
local our $content2;
open (FILE, "<$dir/$filename") or die "cannot open file
$dir/$filename";
while (<FILE>) {
$content .= $_;
}
close (FILE);
open (FILE, "<$current_dir/edit.html") or die "cannot open file
$current_dir/edit.html";
while (<FILE>) {
s/\$VALUE{'filename'}/$filename/g;
s/\$VALUE{'dir'}/$dir/g;
s/\$VALUE/$content/g;
$content2 .= $_;
}
print "Content-Type: text/html\n\n";
$content2 = colorize($filename,$dir);
print $content2;
}
sub save {
local our
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime();
local our $date = sprintf "%4d-%02d-%02d",$year+1900,$mon+1,$mday;
local our $time = sprintf("%4d:%02d:%02d",$hour,$min,$sec);
local our $old_file = $filename .".$date $time";
rename $filedir ."/" . $filename, $filedir ."/" . $old_file;
print "Content-Type: text/html\n\n";
print "Saved";
}
sub colorize {
my $file = shift || '';
my $dir = shift || '';
my $color_table = {
'Variable_Scalar' => 'color:#080;',
'Variable_Array' => 'color:#f70;',
'Variable_Hash' => 'color:#80f;',
'Variable_Typeglob' => 'color:#f03;',
'Subroutine' => 'color:#980;',
'Quote' => 'color:#00a;',
'String' => 'color:#00a;',
'Comment_Normal' => 'color:#069;font-style:italic;',
'Comment_POD' => 'color:#014;font-family:' .
'garamond,serif;font-size:11pt;',
'Bareword' => 'color:#3A3;',
'Package' => 'color:#900;',
'Number' => 'color:#f0f;',
'Operator' => 'color:#000;',
'Symbol' => 'color:#000;',
'Keyword' => 'color:#000;',
'Builtin_Operator' => 'color:#300;',
'Builtin_Function' => 'color:#001;',
'Character' => 'color:#800;',
'Directive' => 'color:#399;font-style:italic;',
'Label' => 'color:#939;font-style:italic;',
'Line' => 'color:#000;',
};
# Program proper
#=====================================================================
my $formatter = Syntax::Highlight:erl->new();
$formatter->define_substitution('<' => '<',
'>' => '>',
'&' => '&'); # HTML escapes.
# install the formats set up above
while ( my ( $type, $style ) = each %{$color_table} ) {
$formatter->set_format($type, [ qq|<span style="$style">|,
'</span>' ] );
}
open F, '<', $dir."/".$file or die $!;
$formatter .'<pre style="font-size:10pt;color:#336;">';
while (<F>) {
print $formatter->format_string;
$formatter ."<br/>";
}
$formatter ."</pre>";
return $formatter->format_string;
}
I'm trying to use Syntax::Highlight:erl but the problem I get is when
I print the result I didn't get carriage return between lines.
thx
Here my script :
#!c:/Perl/bin/perl.exe
#usage
http://avant-garde.no-ip.biz/cgi-bin/edit.cgi?action=edit&filename=edit.cgi&dir=C:\Apache2\cgi-bin/
use strict;
use CGI;
use Syntax::Highlight:erl;
local our $query = CGI->new ;
local our $action = $query->param("action");
local our $dir = $query->param("dir");
local our $filename = $query->param("filename");
local our %VALUE;
local our $current_dir = "C:/Apache2/htdocs/edit";
local our $filedir = "C:/Apache2/cgi-bin/";
if ($action eq "edit") {edit(); }
elsif ($action eq "save") {save(); }
sub edit {
local our $content;
local our $content2;
open (FILE, "<$dir/$filename") or die "cannot open file
$dir/$filename";
while (<FILE>) {
$content .= $_;
}
close (FILE);
open (FILE, "<$current_dir/edit.html") or die "cannot open file
$current_dir/edit.html";
while (<FILE>) {
s/\$VALUE{'filename'}/$filename/g;
s/\$VALUE{'dir'}/$dir/g;
s/\$VALUE/$content/g;
$content2 .= $_;
}
print "Content-Type: text/html\n\n";
$content2 = colorize($filename,$dir);
print $content2;
}
sub save {
local our
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime();
local our $date = sprintf "%4d-%02d-%02d",$year+1900,$mon+1,$mday;
local our $time = sprintf("%4d:%02d:%02d",$hour,$min,$sec);
local our $old_file = $filename .".$date $time";
rename $filedir ."/" . $filename, $filedir ."/" . $old_file;
print "Content-Type: text/html\n\n";
print "Saved";
}
sub colorize {
my $file = shift || '';
my $dir = shift || '';
my $color_table = {
'Variable_Scalar' => 'color:#080;',
'Variable_Array' => 'color:#f70;',
'Variable_Hash' => 'color:#80f;',
'Variable_Typeglob' => 'color:#f03;',
'Subroutine' => 'color:#980;',
'Quote' => 'color:#00a;',
'String' => 'color:#00a;',
'Comment_Normal' => 'color:#069;font-style:italic;',
'Comment_POD' => 'color:#014;font-family:' .
'garamond,serif;font-size:11pt;',
'Bareword' => 'color:#3A3;',
'Package' => 'color:#900;',
'Number' => 'color:#f0f;',
'Operator' => 'color:#000;',
'Symbol' => 'color:#000;',
'Keyword' => 'color:#000;',
'Builtin_Operator' => 'color:#300;',
'Builtin_Function' => 'color:#001;',
'Character' => 'color:#800;',
'Directive' => 'color:#399;font-style:italic;',
'Label' => 'color:#939;font-style:italic;',
'Line' => 'color:#000;',
};
# Program proper
#=====================================================================
my $formatter = Syntax::Highlight:erl->new();
$formatter->define_substitution('<' => '<',
'>' => '>',
'&' => '&'); # HTML escapes.
# install the formats set up above
while ( my ( $type, $style ) = each %{$color_table} ) {
$formatter->set_format($type, [ qq|<span style="$style">|,
'</span>' ] );
}
open F, '<', $dir."/".$file or die $!;
$formatter .'<pre style="font-size:10pt;color:#336;">';
while (<F>) {
print $formatter->format_string;
$formatter ."<br/>";
}
$formatter ."</pre>";
return $formatter->format_string;
}