1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
#!@perl_exec@
#
# The XML -> HTML WebBuilder script,
# Copyright (c)1999 by Magnus Norddahl / ClanSoft.
#
use English;
use File::Basename;
if ($ARGV[0] eq "")
{
print "\nThe XML -> HTML WebBuilder script,\n";
print "Copyright (c)1999 by Magnus Norddahl / ClanSoft.\n\n";
print "Syntax: webbuilder.pl <theme> <file.xml>\n\n";
exit(0);
}
open (INPUT, $ARGV[1]) || die "Could not open: $ARGV[1]";
my @input = <INPUT>;
my $input = join("", @input);
close (INPUT);
basename ($ARGV[1]) =~ /^(.*).xml$/;
$output = "$1.html";
open (OUTPUT, ">$output") || die "Could not open $output for writing.";
print OUTPUT convert($input);
close (OUTPUT);
sub convert
{
my ($input) = @ARG;
my $html_output;
if ($input =~ /<xml>(.*)<\/xml>/si)
{
my $xml_input = $1;
if ($input =~ /(<head[>\w].*<\/head>)/si)
{
my $xml_head = $1;
$html_output .= print_head($xml_head, $ARGV[0]);
}
else
{
die "Document has no head";
}
if ($input =~ /<body[>\w](.*)<\/body>/si)
{
my $xml_body = $1;
$html_output .= print_body($xml_body, $ARGV[0]);
}
else
{
die "Document has no head";
}
}
else
{
die "Not valid XML input";
}
return $html_output;
}
sub print_head
{
my ($xml_head, $file) = @ARG;
my $buffer;
# Read theme from disk and execute it:
if ( -e $file )
{
open(FILT, "<$file");
while (<FILT>) { $buffer.=$_; }
close(FILT);
eval($buffer);
return theme_header($xml_head);
}
else
{
die "theme '$file' not found";
}
}
sub print_body
{
my ($xml_body, $file) = @ARG;
my $buffer;
# Read theme from disk and execute it:
if ( -e $file )
{
open(FILT, "<$file");
while (<FILT>) { $buffer.=$_; }
close(FILT);
eval($buffer);
my @filters = theme_body_filters();
foreach $filter (@filters)
{
$xml_body = $filter->($xml_body);
}
$xml_body .= theme_body_end();
}
else
{
die "theme '$file' not found";
}
return $xml_body."\n";
}
|