1 |
root |
1.1 |
#! perl |
2 |
|
|
|
3 |
root |
1.5 |
# convert given .pod files to wiki style |
4 |
root |
1.1 |
|
5 |
root |
1.5 |
# base path of arch tree, only used for new arch graphics |
6 |
elmex |
1.7 |
my $ARCH = "/root/devel/cvs/cf.schmorp.de/arch"; |
7 |
root |
1.1 |
|
8 |
|
|
use strict; |
9 |
|
|
|
10 |
root |
1.5 |
use Storable; |
11 |
root |
1.1 |
use Pod::POM; |
12 |
|
|
|
13 |
|
|
our @result; |
14 |
|
|
our $indent; |
15 |
|
|
our $level; |
16 |
|
|
|
17 |
root |
1.3 |
my $MA_BEG = "\x{fcd0}"; |
18 |
|
|
my $MA_SEP = "\x{fcd1}"; |
19 |
|
|
my $MA_END = "\x{fcd2}"; |
20 |
|
|
|
21 |
root |
1.1 |
sub asxml($) { |
22 |
|
|
local $_ = $_[0]; |
23 |
|
|
|
24 |
|
|
s/&/&/g; |
25 |
|
|
s/>/>/g; |
26 |
|
|
s/</</g; |
27 |
|
|
|
28 |
|
|
$_ |
29 |
|
|
} |
30 |
|
|
|
31 |
|
|
sub flatten($) { |
32 |
|
|
local $_ = $_[0]; |
33 |
|
|
|
34 |
|
|
s/<[^>]+>//g; |
35 |
|
|
s/^\s+//; |
36 |
|
|
s/\s+$//; |
37 |
|
|
s/\s+/ /g; |
38 |
|
|
|
39 |
|
|
$_ |
40 |
|
|
} |
41 |
|
|
|
42 |
root |
1.8 |
sub special { |
43 |
|
|
$MA_BEG . (join $MA_SEP, @_) . $MA_END |
44 |
|
|
} |
45 |
|
|
|
46 |
root |
1.1 |
package AsParagraphs; |
47 |
|
|
|
48 |
|
|
use strict; |
49 |
|
|
|
50 |
|
|
use base "Pod::POM::View"; |
51 |
|
|
|
52 |
root |
1.11 |
# nodes (order must stay as it is) |
53 |
|
|
sub N_PARENT (){ 0 } |
54 |
|
|
sub N_PAR (){ 1 } |
55 |
|
|
sub N_LEVEL (){ 2 } |
56 |
|
|
sub N_KW (){ 3 } |
57 |
|
|
sub N_DOC (){ 4 } |
58 |
|
|
|
59 |
|
|
# paragraphs (order must stay as it is) |
60 |
|
|
sub P_INDENT (){ 0 } |
61 |
|
|
sub P_LEVEL (){ 1 } |
62 |
|
|
sub P_MARKUP (){ 2 } |
63 |
|
|
sub P_INDEX (){ 3 } |
64 |
|
|
|
65 |
root |
1.1 |
*view_seq_file = |
66 |
|
|
*view_seq_code = |
67 |
|
|
*view_seq_bold = sub { "<b>$_[1]</b>" }; |
68 |
|
|
*view_seq_italic = sub { "<i>$_[1]</i>" }; |
69 |
|
|
*view_seq_zero = sub { }; |
70 |
|
|
*view_seq_space = sub { my $text = $_[1]; $text =~ s/ / /g; $text }; |
71 |
root |
1.11 |
*view_seq_index = sub { push @{ $result[-1][P_INDEX] }, $_[1]; "" }; |
72 |
root |
1.1 |
|
73 |
|
|
sub view_seq_text { |
74 |
|
|
my $text = $_[1]; |
75 |
|
|
$text =~ s/\s+/ /g; |
76 |
|
|
::asxml $text |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
sub view_seq_link { |
80 |
|
|
my (undef, $link) = @_; |
81 |
|
|
|
82 |
root |
1.4 |
my $text = $link =~ s/^(.*)\|// ? $1 : $link; |
83 |
|
|
|
84 |
root |
1.3 |
if ($link =~ /http:/) { |
85 |
|
|
"<u>" . (::asxml $link) . "</u>" |
86 |
root |
1.5 |
} elsif ($link =~ /^\$ARCH\/(.+)$/) { |
87 |
|
|
my $path = $1; |
88 |
|
|
(my $base = $path) =~ s/.*\///; |
89 |
root |
1.6 |
-f "$ARCH/$path" && system "rsync -av -c \Q$ARCH/$path\E \Qresources/arch/$base"; |
90 |
root |
1.8 |
::special image => "arch/$base", 1; |
91 |
root |
1.3 |
} else { |
92 |
root |
1.8 |
::special link => $text, $link |
93 |
root |
1.3 |
} |
94 |
root |
1.1 |
} |
95 |
|
|
|
96 |
|
|
sub view_verbatim { |
97 |
root |
1.11 |
push @result, [ $indent * 16, $level, "<tt>" . (::asxml $_[1]) . "</tt>\n" ]; |
98 |
root |
1.1 |
() |
99 |
|
|
} |
100 |
|
|
|
101 |
|
|
sub view_textblock { |
102 |
root |
1.11 |
push @result, [ $indent * 16, $level, "$_[1]\n" ]; |
103 |
root |
1.1 |
() |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
sub view_head1 { |
107 |
root |
1.11 |
push @result, [ $indent * 16, $level ]; |
108 |
root |
1.1 |
my $title = $_[1]->title->present ($_[0]); |
109 |
root |
1.15 |
$result[-1][P_MARKUP] = ::special h1 => $title if length $title; |
110 |
root |
1.11 |
$title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title; |
111 |
root |
1.1 |
local $level = $level + 1; |
112 |
|
|
$_[1]->content->present ($_[0]); |
113 |
|
|
() |
114 |
|
|
}; |
115 |
|
|
|
116 |
|
|
sub view_head2 { |
117 |
root |
1.11 |
push @result, [ $indent * 16, $level ]; |
118 |
root |
1.1 |
my $title = $_[1]->title->present ($_[0]); |
119 |
root |
1.15 |
$result[-1][P_MARKUP] = ::special h2 => $title if length $title; |
120 |
root |
1.11 |
$title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title; |
121 |
root |
1.1 |
local $level = $level + 1; |
122 |
|
|
$_[1]->content->present ($_[0]); |
123 |
|
|
() |
124 |
|
|
}; |
125 |
|
|
|
126 |
|
|
sub view_head3 { |
127 |
root |
1.11 |
push @result, [ $indent * 16, $level ]; |
128 |
root |
1.1 |
my $title = $_[1]->title->present ($_[0]); |
129 |
root |
1.15 |
$result[-1][P_MARKUP] = ::special h3 => $title if length $title; |
130 |
root |
1.11 |
$title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title; |
131 |
root |
1.1 |
local $level = $level + 1; |
132 |
|
|
$_[1]->content->present ($_[0]); |
133 |
|
|
() |
134 |
|
|
}; |
135 |
|
|
|
136 |
|
|
sub view_over { |
137 |
|
|
local $indent = $indent + $_[1]->indent; |
138 |
root |
1.11 |
push @result, [ $indent, $level ]; |
139 |
root |
1.12 |
$_[1]->content->present ($_[0]); |
140 |
|
|
() |
141 |
|
|
} |
142 |
|
|
|
143 |
|
|
sub view_item { |
144 |
|
|
push @result, [ $indent * 8, $level ]; |
145 |
|
|
my $title = $_[1]->title->present ($_[0]); |
146 |
|
|
$result[-1][P_MARKUP] = "$title\n" if length $title; |
147 |
|
|
$title = ::flatten $title; unshift @{ $result[-1][P_INDEX] }, $title if length $title; |
148 |
root |
1.11 |
local $level = $level + 1; |
149 |
root |
1.1 |
$_[1]->content->present ($_[0]); |
150 |
|
|
() |
151 |
|
|
} |
152 |
|
|
|
153 |
|
|
sub view_for { |
154 |
|
|
if ($_[1]->format eq "image") { |
155 |
root |
1.11 |
push @result, [ |
156 |
|
|
$indent * 16, |
157 |
|
|
$level, |
158 |
|
|
(::special image => "pod/" . $_->text), |
159 |
|
|
]; |
160 |
root |
1.1 |
} |
161 |
|
|
() |
162 |
|
|
} |
163 |
|
|
|
164 |
root |
1.10 |
sub view_begin { |
165 |
|
|
() |
166 |
|
|
} |
167 |
|
|
|
168 |
root |
1.1 |
sub view { |
169 |
|
|
my ($self, $type, $item) = @_; |
170 |
|
|
|
171 |
|
|
$item->content->present ($self); |
172 |
|
|
} |
173 |
|
|
|
174 |
|
|
############################################################################# |
175 |
|
|
|
176 |
|
|
sub as_paragraphs($) { |
177 |
|
|
my ($pom) = @_; |
178 |
|
|
|
179 |
|
|
local $indent = 0; |
180 |
root |
1.11 |
local $level = 2; |
181 |
|
|
local @result = ( [] ); |
182 |
root |
1.1 |
|
183 |
|
|
$pom->present ("AsParagraphs"); |
184 |
|
|
|
185 |
root |
1.11 |
[grep $_->[P_INDEX] || defined $_->[P_MARKUP], @result] |
186 |
root |
1.1 |
} |
187 |
|
|
|
188 |
|
|
############################################################################# |
189 |
|
|
|
190 |
|
|
my %wiki; |
191 |
|
|
|
192 |
|
|
sub add_node($) { |
193 |
|
|
my ($node) = @_; |
194 |
|
|
|
195 |
root |
1.12 |
for (@{ $node->[N_KW] || {} }) { |
196 |
root |
1.5 |
push @{$wiki{lc $_}}, $node; |
197 |
root |
1.1 |
} |
198 |
|
|
} |
199 |
|
|
|
200 |
root |
1.12 |
my $root; |
201 |
|
|
$root->[N_KW] = ["pod"]; |
202 |
root |
1.1 |
|
203 |
|
|
for my $path (@ARGV) { |
204 |
|
|
$path =~ /([^\/\\]+)\.pod$/ or die "$path: illegal pathname"; |
205 |
|
|
my $base = $1; |
206 |
|
|
my $pom = Pod::POM->new->parse_text (do { |
207 |
|
|
local $/; |
208 |
|
|
open my $pod, "<:utf8", $path |
209 |
|
|
or die "$path: $!"; |
210 |
|
|
<$pod> |
211 |
|
|
}); |
212 |
|
|
|
213 |
|
|
my $para = as_paragraphs $pom; |
214 |
|
|
|
215 |
root |
1.12 |
my $pod; |
216 |
|
|
$pod->[N_PARENT] = $root; |
217 |
|
|
$pod->[N_PAR] = 0; |
218 |
|
|
$pod->[N_LEVEL] = 1; |
219 |
|
|
$pod->[N_KW] = [$base]; |
220 |
|
|
$pod->[N_DOC] = $para; |
221 |
|
|
|
222 |
|
|
my @parent = ($pod); |
223 |
root |
1.1 |
|
224 |
|
|
for my $idx (0 .. $#$para) { |
225 |
|
|
my $par = $para->[$idx]; |
226 |
|
|
|
227 |
root |
1.12 |
while ($parent[-1][N_LEVEL] >= $par->[P_LEVEL]) { |
228 |
root |
1.1 |
pop @parent; |
229 |
|
|
} |
230 |
|
|
|
231 |
root |
1.11 |
if ($par->[P_INDEX]) { |
232 |
root |
1.12 |
my $node; |
233 |
|
|
$node->[N_PARENT] = $parent[-1]; |
234 |
|
|
$node->[N_PAR] = $idx; |
235 |
|
|
$node->[N_LEVEL] = $par->[P_LEVEL]; |
236 |
|
|
$node->[N_KW] = $par->[P_INDEX]; |
237 |
|
|
$node->[N_DOC] = $para; |
238 |
root |
1.1 |
push @parent, $node; |
239 |
|
|
add_node $node; |
240 |
|
|
} |
241 |
|
|
} |
242 |
root |
1.14 |
|
243 |
|
|
add_node $pod; |
244 |
root |
1.1 |
} |
245 |
|
|
|
246 |
root |
1.14 |
add_node $root; |
247 |
|
|
|
248 |
root |
1.1 |
Storable::nstore \%wiki, "docwiki.pst"; |
249 |
|
|
|