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