ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/bin/pod2wiki
(Generate patch)

Comparing deliantra/Deliantra-Client/bin/pod2wiki (file contents):
Revision 1.11 by root, Tue Mar 25 01:46:36 2008 UTC vs.
Revision 1.19 by root, Mon May 5 17:07:13 2008 UTC

1#! perl 1#! perl
2 2
3# convert given .pod files to wiki style 3# convert given .pod files to wiki style
4 4
5# base path of arch tree, only used for new arch graphics 5# base path of arch tree, only used for new arch graphics
6my $ARCH = "/root/devel/cvs/cf.schmorp.de/arch"; 6my $ARCH = "/root/src/cf.schmorp.de/arch";
7 7
8use strict; 8use strict;
9 9
10use Storable; 10use Storable;
11use Pod::POM; 11use Pod::POM;
77} 77}
78 78
79sub view_seq_link { 79sub view_seq_link {
80 my (undef, $link) = @_; 80 my (undef, $link) = @_;
81 81
82 my $text = $link =~ s/^(.*)\|// ? $1 : $link; 82 $link =~ s/^(.*)\|//
83 or $link =~ /([^\/]*)$/;
84
85 my $text = $1;
83 86
84 if ($link =~ /http:/) { 87 if ($link =~ /http:/) {
85 "<u>" . (::asxml $link) . "</u>" 88 "<u>" . (::asxml $link) . "</u>"
86 } elsif ($link =~ /^\$ARCH\/(.+)$/) { 89 } elsif ($link =~ /^\$ARCH\/(.+\....)$/) {
87 my $path = $1; 90 my $file = $1;
88 (my $base = $path) =~ s/.*\///; 91
89 -f "$ARCH/$path" && system "rsync -av -c \Q$ARCH/$path\E \Qresources/arch/$base"; 92 unless (-f "resources/arch/$file.png") {
93 print "ARCHIMG $file is missing, trying to supply... ";
94 my ($path) = split /\x00/, qx<find \Q$ARCH\E -name \Q$file.64x64.png*\E -print0>;
95 -f $path or die "$file: could not find arch image";
96 print "$path\n";
97 system "rsync -a \Q$path\E resources/arch/\Q$file.png"
98 and die "rsync failed: $?";
99 system "cvs add -kb resources/arch/\Q$file.png"
100 and ((unlink "resources/arch/$file.png"), die "cvs add failed: $?");
101 }
102
90 ::special image => "arch/$base", 1; 103 ::special image => "arch/$file.png", 1;
91 } else { 104 } else {
92 ::special link => $text, $link 105 ::special link => $text, $link
93 } 106 }
94} 107}
95 108
96sub view_item {
97 push @result, [
98 $indent * 8,
99 $level,
100 ];
101 my $title = $_[1]->title->present ($_[0]);
102 $result[-1][P_MARKUP] = "$title\n" if length $title;
103 $title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title;
104 local $level = $level + 1;
105 $_[1]->content->present ($_[0]);
106 ()
107}
108
109sub view_verbatim { 109sub view_verbatim {
110 push @result, [ $indent * 16, $level, "<tt>" . (::asxml $_[1]) . "</tt>\n" ]; 110 push @result, [ $indent * 16, $level, "<tt>" . (::asxml $_[1]) . "</tt>\n" ];
111 () 111 ()
112} 112}
113 113
117} 117}
118 118
119sub view_head1 { 119sub view_head1 {
120 push @result, [ $indent * 16, $level ]; 120 push @result, [ $indent * 16, $level ];
121 my $title = $_[1]->title->present ($_[0]); 121 my $title = $_[1]->title->present ($_[0]);
122 $result[-1][P_MARKUP] = "\n\n<span foreground='#ffff00' size='x-large'>$title</span>\n" if length $title; 122 $result[-1][P_MARKUP] = ::special h1 => $title if length $title;
123 $title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title; 123 $title = ::flatten $title;
124 unshift @{ $result[-1][P_INDEX] }, $title
125 if !$result[-1][P_INDEX];
124 local $level = $level + 1; 126 local $level = $level + 1;
125 $_[1]->content->present ($_[0]); 127 $_[1]->content->present ($_[0]);
126 () 128 ()
127}; 129};
128 130
129sub view_head2 { 131sub view_head2 {
130 push @result, [ $indent * 16, $level ]; 132 push @result, [ $indent * 16, $level ];
131 my $title = $_[1]->title->present ($_[0]); 133 my $title = $_[1]->title->present ($_[0]);
132 $result[-1][P_MARKUP] = "\n\n<span foreground='#ccccff' size='large'>$title</span>\n" if length $title; 134 $result[-1][P_MARKUP] = ::special h2 => $title if length $title;
133 $title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title; 135 $title = ::flatten $title;
136 unshift @{ $result[-1][P_INDEX] }, $title
137 if !$result[-1][P_INDEX];
134 local $level = $level + 1; 138 local $level = $level + 1;
135 $_[1]->content->present ($_[0]); 139 $_[1]->content->present ($_[0]);
136 () 140 ()
137}; 141};
138 142
139sub view_head3 { 143sub view_head3 {
140 push @result, [ $indent * 16, $level ]; 144 push @result, [ $indent * 16, $level ];
141 my $title = $_[1]->title->present ($_[0]); 145 my $title = $_[1]->title->present ($_[0]);
142 $result[-1][P_MARKUP] = "\n\n<span size='large'>$title</span>\n" if length $title; 146 $result[-1][P_MARKUP] = ::special h3 => $title if length $title;
143 $title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title; 147 $title = ::flatten $title;
148 unshift @{ $result[-1][P_INDEX] || [] }, $title
149 if !$result[-1][P_INDEX];
144 local $level = $level + 1; 150 local $level = $level + 1;
145 $_[1]->content->present ($_[0]); 151 $_[1]->content->present ($_[0]);
146 () 152 ()
147}; 153};
148 154
149sub view_over { 155sub view_over {
150 local $indent = $indent + $_[1]->indent; 156 local $indent = $indent + $_[1]->indent;
151 push @result, [ $indent, $level ]; 157 push @result, [ $indent, $level ];
158 $_[1]->content->present ($_[0]);
159 ()
160}
161
162sub view_item {
163 push @result, [ $indent * 8, $level ];
164 my $title = $_[1]->title->present ($_[0]);
165 $result[-1][P_MARKUP] = "$title\n" if length $title;
166 $title = ::flatten $title;
167 unshift @{ $result[-1][P_INDEX] || [] }, $title
168 if !$result[-1][P_INDEX];
152 local $level = $level + 1; 169 local $level = $level + 1;
153 $_[1]->content->present ($_[0]); 170 $_[1]->content->present ($_[0]);
154 () 171 ()
155} 172}
156 173
189 [grep $_->[P_INDEX] || defined $_->[P_MARKUP], @result] 206 [grep $_->[P_INDEX] || defined $_->[P_MARKUP], @result]
190} 207}
191 208
192############################################################################# 209#############################################################################
193 210
211$| = 1;
212
194my %wiki; 213my %wiki;
195 214
196sub add_node($) { 215sub add_node($) {
197 my ($node) = @_; 216 my ($node) = @_;
198 217
199 for (@{ $node->{kw} || {} }) { 218 for (@{ $node->[N_KW] || {} }) {
200 push @{$wiki{lc $_}}, $node; 219 push @{$wiki{$_}}, $node;
201 } 220 }
202} 221}
203 222
204my $root = { 223my $root;
205 kw => ["pod"], 224$root->[N_KW] = ["Documents", "pod"];
206}; 225$root->[N_DOC] = [[0, 0, ::special link => "All Documents", "pod/*"]];
207 226
208for my $path (@ARGV) { 227for my $path (@ARGV) {
209 $path =~ /([^\/\\]+)\.pod$/ or die "$path: illegal pathname"; 228 $path =~ /([^\/\\]+)\.pod$/ or die "$path: illegal pathname";
210 my $base = $1; 229 my $base = $1;
211 my $pom = Pod::POM->new->parse_text (do { 230 my $pom = Pod::POM->new->parse_text (do {
215 <$pod> 234 <$pod>
216 }); 235 });
217 236
218 my $para = as_paragraphs $pom; 237 my $para = as_paragraphs $pom;
219 238
239 my $pod;
240 $pod->[N_PARENT] = $root;
241 $pod->[N_PAR] = 0;
242 $pod->[N_LEVEL] = 1;
243 $pod->[N_KW] = [$base];
244 $pod->[N_DOC] = $para;
245
220 my @parent = ( 246 my @parent = ($pod);
221 { parent => $root, kw => [$base], doc => $para, par => 0, level => 1 },
222 );
223 add_node $parent[-1];
224 247
225 for my $idx (0 .. $#$para) { 248 for my $idx (0 .. $#$para) {
226 my $par = $para->[$idx]; 249 my $par = $para->[$idx];
227 250
228 while ($parent[-1]{level} >= $par->[P_LEVEL]) { 251 while ($parent[-1][N_LEVEL] >= $par->[P_LEVEL]) {
229 pop @parent; 252 pop @parent;
230 } 253 }
231 254
232 if ($par->[P_INDEX]) { 255 if ($par->[P_INDEX]) {
233 my $node = { 256 my $node;
234 kw => $par->[P_INDEX], 257 $node->[N_PARENT] = $parent[-1];
235 parent => $parent[-1], 258 $node->[N_PAR] = $idx;
236 doc => $para, 259 $node->[N_LEVEL] = $par->[P_LEVEL];
237 par => $idx, 260 $node->[N_KW] = $par->[P_INDEX];
238 level => $par->[P_LEVEL], 261 $node->[N_DOC] = $para;
239 };
240 push @parent, $node; 262 push @parent, $node;
241 add_node $node; 263 add_node $node;
242 } 264 }
243 } 265 }
266
267 add_node $pod;
244} 268}
269
270add_node $root;
245 271
246Storable::nstore \%wiki, "docwiki.pst"; 272Storable::nstore \%wiki, "docwiki.pst";
247 273

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines