1 | #!/opt/bin/perl |
1 | #!/opt/bin/perl |
2 | |
2 | |
|
|
3 | # cfarch2html - convert crossfire archetypes to html |
|
|
4 | # Copyright (C) 2005,2007 Marc Lehmann <cfmaps@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 | our $VERSION = '2.001'; |
|
|
21 | |
|
|
22 | use Crossfire 1.0; |
3 | use Storable; |
23 | use Storable; |
4 | |
|
|
5 | my $LIBDIR = $ENV{CROSSFIRE_LIBDIR} |
|
|
6 | or die "\$CROSSFIRE_LIBDIR must be set\n"; |
|
|
7 | |
|
|
8 | our $VERSION = '1.0'; |
|
|
9 | |
|
|
10 | my $arch; |
|
|
11 | |
24 | |
12 | sub escape_html($) { |
25 | sub escape_html($) { |
13 | local $_ = shift; |
26 | local $_ = shift; |
14 | s/([<>&])/sprintf "&#%d;", ord $1/ge; |
27 | s/([<>&])/sprintf "&#%d;", ord $1/ge; |
15 | $_ |
28 | $_ |
16 | } |
29 | } |
17 | |
30 | |
18 | $arch = Storable::retrieve "$LIBDIR/archetypes.pst"; |
31 | system "rm", -rf => "a"; |
19 | |
32 | mkdir "a", 0777; |
20 | open my $fh, ">:utf8", "archetypes.html" |
|
|
21 | or die "archetypes.html: $!"; |
|
|
22 | |
|
|
23 | select $fh; |
|
|
24 | |
|
|
25 | my $W = $meta->{width} * $T; |
|
|
26 | my $H = $meta->{height} * $T; |
|
|
27 | |
|
|
28 | my (@path) = split /\//, $path; |
|
|
29 | |
|
|
30 | print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">", |
|
|
31 | "<html>", |
|
|
32 | "<head>", |
|
|
33 | "<title>archetypes</title>", |
|
|
34 | "<style type='text/css'><!--\n", |
|
|
35 | "body { background: white; text-color: black; }\n", |
|
|
36 | "a { text-color: blue; }\n", |
|
|
37 | "a:hover { text-color: red; }\n", |
|
|
38 | "a:visited { text-color: #008; }\n", |
|
|
39 | |
|
|
40 | "li { white-space: pre; }\n", |
|
|
41 | "p.m { white-space: pre; margin-left: 2em; background: #ddd; padding: 2px; border: 1px solid black; }\n", |
|
|
42 | "-->\n</style>", |
|
|
43 | "</head>", |
|
|
44 | "<body>"; |
|
|
45 | |
|
|
46 | print "<table>"; |
|
|
47 | |
33 | |
48 | sub print_arch { |
34 | sub print_arch { |
49 | my ($a) = @_; |
35 | my ($a) = @_; |
50 | print "<ul>"; |
36 | print "<ul>"; |
51 | for (sort keys %$a) { |
37 | for (sort keys %$a) { |
52 | next if $_ eq "_name"; |
38 | next if $_ eq "_name"; |
|
|
39 | next if $_ eq "_atype"; |
53 | my $v = escape_html $a->{$_}; |
40 | my $v = escape_html $a->{$_}; |
54 | |
41 | |
55 | print "<li>"; |
42 | print "<li>"; |
56 | if ($_ eq "more") { |
43 | if ($_ eq "more") { |
57 | print "more =>\n"; |
44 | print "more =>\n"; |
58 | print_arch ($a->{more}); |
45 | print_arch ($a->{more}); |
59 | } elsif ($_ eq "other_arch") { |
46 | } elsif ($_ eq "other_arch") { |
60 | print "$_ => <a href='#", (lc $a->{$_}), "'>$v</a>\n"; |
47 | print "$_ => <a href='#$a->{$_}'>$v</a>\n"; |
61 | } elsif ($_ eq "msg" || $_ eq "lore") { |
48 | } elsif ($_ eq "msg" || $_ eq "lore") { |
62 | print "<p class='m'>$v</p>"; |
49 | print "$_ =><p class='m'>$v</p>"; |
63 | } else { |
50 | } else { |
64 | print "$_ => $v\n"; |
51 | print "$_ => $v\n"; |
65 | } |
52 | } |
66 | print "</li>"; |
53 | print "</li>"; |
67 | } |
54 | } |
68 | print "</ul>"; |
55 | print "</ul>"; |
69 | } |
56 | } |
|
|
57 | |
|
|
58 | Crossfire::load_archetypes; |
|
|
59 | |
70 | for my $name (sort keys %$arch) { |
60 | for my $name (sort keys %ARCH) { |
71 | print "<tr valign='top'><th align='left'><a name='", (lc $name), "'>$name</a></th><td>"; |
61 | open my $fh, ">:utf8", "a/$name.xhtml" |
|
|
62 | or die "a/$name.xhtml: $!"; |
|
|
63 | |
|
|
64 | select $fh; |
|
|
65 | |
|
|
66 | print "<?xml version='1.0' encoding='utf-8'?>", |
|
|
67 | '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">', |
|
|
68 | "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>", |
|
|
69 | "<head>", |
|
|
70 | "<title>Crossfire Archetype '$name'</title>", |
|
|
71 | "<link rel='stylesheet' type='text/css' media='all' href='/common.css'/>", |
|
|
72 | "</head>", |
|
|
73 | "<body>", |
|
|
74 | "<h1>Crossfire Archetype '$name'</h1>"; |
|
|
75 | |
72 | print_arch $arch->{$name}; |
76 | print_arch $ARCH{$name}; |
73 | print "</td></tr>"; |
77 | |
|
|
78 | print "<p class='footer'>created by <a href='http://software.schmorp.de/pkg/cfmaps'>cfarch2html</a> version $VERSION</p>", |
|
|
79 | "</body></html>"; |
|
|
80 | |
|
|
81 | close $fh; |
|
|
82 | |
|
|
83 | #system "gzip", "-7f", "arc.xhtml"; |
74 | } |
84 | } |
75 | |
85 | |
76 | print "</table><hr/><p style='font-size: 6pt'>created by <b>cfarch2html</b> version $VERSION</p>", |
|
|
77 | "</body></html>"; |
|
|
78 | |
86 | |
79 | close $fh; |
|
|
80 | |
|
|
81 | system "gzip", "-7f", "archetypes.html"; |
|
|
82 | __END__ |
|
|
83 | |
|
|
84 | print_archs $as; |
|
|
85 | print "</div></span>"; |
|
|
86 | } |
|
|
87 | print "</td>"; |
|
|
88 | } |
|
|
89 | print "</tr>"; |
|
|
90 | } |
|
|
91 | |
|
|
92 | } |
|
|
93 | |
|
|