ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/doc/pod2texi
Revision: 1.1
Committed: Fri Mar 28 19:46:47 2003 UTC (21 years, 7 months ago) by pcg
Branch: MAIN
Log Message:
*** empty log message ***

File Contents

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