| 1 |
root |
1.1 |
#!/opt/bin/perl |
| 2 |
|
|
|
| 3 |
root |
1.5 |
# cfarch2html - convert crossfire archetypes to html |
| 4 |
|
|
# Copyright (C) 2005 Marc Lehmann <gvpe@schmorp.de> |
| 5 |
|
|
# |
| 6 |
|
|
# CFARCH2HTML is free software; you can redistribute it and/or modify |
| 7 |
|
|
# it under the terms of the GNU General Public License as published by |
| 8 |
|
|
# the Free Software Foundation; either version 2 of the License, or |
| 9 |
|
|
# (at your option) any later version. |
| 10 |
|
|
# |
| 11 |
|
|
# This program is distributed in the hope that it will be useful, |
| 12 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
|
|
# GNU General Public License for more details. |
| 15 |
|
|
# |
| 16 |
|
|
# You should have received a copy of the GNU General Public License |
| 17 |
|
|
# along with gvpe; if not, write to the Free Software |
| 18 |
|
|
# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 |
|
|
|
| 20 |
root |
1.7 |
our $VERSION = '1.02'; |
| 21 |
root |
1.6 |
|
| 22 |
root |
1.1 |
use Storable; |
| 23 |
|
|
|
| 24 |
|
|
my $LIBDIR = $ENV{CROSSFIRE_LIBDIR} |
| 25 |
|
|
or die "\$CROSSFIRE_LIBDIR must be set\n"; |
| 26 |
|
|
|
| 27 |
|
|
my $arch; |
| 28 |
|
|
|
| 29 |
|
|
sub escape_html($) { |
| 30 |
|
|
local $_ = shift; |
| 31 |
|
|
s/([<>&])/sprintf "&#%d;", ord $1/ge; |
| 32 |
|
|
$_ |
| 33 |
|
|
} |
| 34 |
|
|
|
| 35 |
|
|
$arch = Storable::retrieve "$LIBDIR/archetypes.pst"; |
| 36 |
|
|
|
| 37 |
root |
1.7 |
open my $fh, ">:utf8", "arc.xhtml" |
| 38 |
|
|
or die "arc.xhtml: $!"; |
| 39 |
root |
1.1 |
|
| 40 |
|
|
select $fh; |
| 41 |
|
|
|
| 42 |
|
|
my $W = $meta->{width} * $T; |
| 43 |
|
|
my $H = $meta->{height} * $T; |
| 44 |
|
|
|
| 45 |
|
|
my (@path) = split /\//, $path; |
| 46 |
|
|
|
| 47 |
root |
1.7 |
print "<?xml version='1.0' encoding='utf-8'?>", |
| 48 |
|
|
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">", |
| 49 |
|
|
"<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>", |
| 50 |
root |
1.1 |
"<head>", |
| 51 |
root |
1.2 |
"<title>Crossfire Archetypes</title>", |
| 52 |
root |
1.7 |
"<style type='text/css'>\n", |
| 53 |
root |
1.1 |
"body { background: white; text-color: black; }\n", |
| 54 |
|
|
"a { text-color: blue; }\n", |
| 55 |
|
|
"a:hover { text-color: red; }\n", |
| 56 |
|
|
"a:visited { text-color: #008; }\n", |
| 57 |
|
|
|
| 58 |
|
|
"li { white-space: pre; }\n", |
| 59 |
|
|
"p.m { white-space: pre; margin-left: 2em; background: #ddd; padding: 2px; border: 1px solid black; }\n", |
| 60 |
root |
1.7 |
"\n</style>", |
| 61 |
root |
1.1 |
"</head>", |
| 62 |
root |
1.2 |
"<body>", |
| 63 |
|
|
"<h1>Crossfire Archetypes</h1>"; |
| 64 |
root |
1.1 |
|
| 65 |
|
|
print "<table>"; |
| 66 |
|
|
|
| 67 |
|
|
sub print_arch { |
| 68 |
|
|
my ($a) = @_; |
| 69 |
|
|
print "<ul>"; |
| 70 |
|
|
for (sort keys %$a) { |
| 71 |
|
|
next if $_ eq "_name"; |
| 72 |
|
|
my $v = escape_html $a->{$_}; |
| 73 |
|
|
|
| 74 |
|
|
print "<li>"; |
| 75 |
|
|
if ($_ eq "more") { |
| 76 |
|
|
print "more =>\n"; |
| 77 |
|
|
print_arch ($a->{more}); |
| 78 |
|
|
} elsif ($_ eq "other_arch") { |
| 79 |
|
|
print "$_ => <a href='#", (lc $a->{$_}), "'>$v</a>\n"; |
| 80 |
|
|
} elsif ($_ eq "msg" || $_ eq "lore") { |
| 81 |
root |
1.4 |
print "$_ =><p class='m'>$v</p>"; |
| 82 |
root |
1.1 |
} else { |
| 83 |
|
|
print "$_ => $v\n"; |
| 84 |
|
|
} |
| 85 |
|
|
print "</li>"; |
| 86 |
|
|
} |
| 87 |
|
|
print "</ul>"; |
| 88 |
|
|
} |
| 89 |
|
|
for my $name (sort keys %$arch) { |
| 90 |
root |
1.7 |
print "<tr valign='top'><th align='left'><a id='", (lc $name), "'>$name</a></th><td>"; |
| 91 |
root |
1.1 |
print_arch $arch->{$name}; |
| 92 |
|
|
print "</td></tr>"; |
| 93 |
|
|
} |
| 94 |
|
|
|
| 95 |
root |
1.6 |
print "</table><hr/><p style='font-size: 8pt'>created by <a href='http://software.schmorp.de/#crossfire'>cfarch2html</a> version $VERSION</p>", |
| 96 |
root |
1.1 |
"</body></html>"; |
| 97 |
|
|
|
| 98 |
|
|
close $fh; |
| 99 |
|
|
|
| 100 |
root |
1.7 |
system "gzip", "-7f", "arc.xhtml"; |
| 101 |
|
|
|