1 |
#!/usr/bin/perl |
2 |
|
3 |
use Pod::Tree; |
4 |
|
5 |
sub escape_texi($) { |
6 |
local $_ = shift; |
7 |
s/([\@\{\}])/\@$1/g; |
8 |
s/\n+/ /g; |
9 |
$_; |
10 |
} |
11 |
|
12 |
sub example { |
13 |
my $text = $_[0]; |
14 |
print "\n\n\@example\n"; |
15 |
$text =~ s/\n+$//; |
16 |
$text =~ s/([\@\{\}])/\@$1/g; |
17 |
print $text; |
18 |
print "\n\@end example\n\n"; |
19 |
} |
20 |
|
21 |
while (<>) { |
22 |
if (/^\@c INCLUDE-(\S+) (\S+)/) { |
23 |
my $type = $1; |
24 |
my $name = $2; |
25 |
my $path = $2; |
26 |
|
27 |
$name =~ s/\.(\d)$/($1)/; |
28 |
|
29 |
print "\@chapter $name\n\n"; |
30 |
|
31 |
if ($type eq "POD") { |
32 |
open my $x, "<$path.pod" or die "$path.pod: $!"; |
33 |
my $data = do { local $/; <$x> }; |
34 |
|
35 |
my $pod = new Pod::Tree; |
36 |
$pod->load_string($data); |
37 |
|
38 |
my $walker; $walker = sub { |
39 |
my $n = $_[0]; |
40 |
if ($n->is_code) { |
41 |
# nop |
42 |
} elsif ($n->is_link) { |
43 |
my $target = $n->get_target; |
44 |
my $page = $target->get_page; |
45 |
my $section = $target->get_section; |
46 |
|
47 |
#print "<b>"; |
48 |
$walker->($_) for @{$n->get_children}; |
49 |
#print "</b>"; |
50 |
} elsif ($n->is_text) { |
51 |
print escape_texi $n->get_text; |
52 |
} elsif ($n->is_verbatim) { |
53 |
example $n->get_text; |
54 |
} elsif ($n->is_sequence) { |
55 |
if ($n->get_letter eq "C") { |
56 |
print "\@t{"; |
57 |
$walker->($_) for @{$n->get_children}; |
58 |
print "}"; |
59 |
} elsif ($n->get_letter eq "B") { |
60 |
print "\@strong{"; |
61 |
$walker->($_) for @{$n->get_children}; |
62 |
print "}"; |
63 |
} elsif ($n->get_letter eq "I" or $n->get_letter eq "F") { |
64 |
print "\@emph{"; |
65 |
$walker->($_) for @{$n->get_children}; |
66 |
print "}"; |
67 |
} else { |
68 |
# S would mean to use nbsp |
69 |
$walker->($_) for @{$n->get_children}; |
70 |
} |
71 |
} elsif ($n->is_command) { |
72 |
if ($n->is_c_head1) { |
73 |
print "\n\@section "; |
74 |
$walker->($_) for @{$n->get_children}; |
75 |
print "\n"; |
76 |
} elsif ($n->is_c_head2) { |
77 |
print "\n\n\@subsection "; |
78 |
$walker->($_) for @{$n->get_children}; |
79 |
print "\n"; |
80 |
} else { |
81 |
# nop? |
82 |
} |
83 |
} elsif ($n->is_ordinary) { |
84 |
$walker->($_) for @{$n->get_children}; |
85 |
print "\@refill\n"; |
86 |
} elsif ($n->is_root) { |
87 |
$walker->($_) for @{$n->get_children}; |
88 |
} elsif ($n->is_list) { |
89 |
print "\n\n\@itemize\n"; |
90 |
$walker->($_) for @{$n->get_children}; |
91 |
print "\@end itemize\n\n"; |
92 |
} elsif ($n->is_item) { |
93 |
print "\n\n\@item\n"; |
94 |
print "\@b{"; |
95 |
$walker->($_) for @{$n->get_children}; |
96 |
print "}\n\n"; |
97 |
$walker->($_) for @{$n->get_siblings}; |
98 |
} else { |
99 |
die "UNKNOWN NODE $_[0]{type}<br/>"; |
100 |
$walker->($_) for @{$n->get_children}; |
101 |
} |
102 |
}; |
103 |
|
104 |
$walker->($pod->get_root); |
105 |
} elsif ($type eq "TEXT") { |
106 |
open my $x, "<$path" or die "$path: $!"; |
107 |
my $data = do { local $/; <$x> }; |
108 |
|
109 |
print $data; |
110 |
} elsif ($type eq "EXAMPLE") { |
111 |
open my $x, "<$path" or die "$path: $!"; |
112 |
my $data = do { local $/; <$x> }; |
113 |
|
114 |
example $data; |
115 |
} |
116 |
} else { |
117 |
print; |
118 |
} |
119 |
} |
120 |
|