ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/doc/pod2texi
(Generate patch)

Comparing gvpe/doc/pod2texi (file contents):
Revision 1.1 by pcg, Fri Mar 28 19:46:47 2003 UTC vs.
Revision 1.4 by pcg, Wed Jul 7 00:28:20 2004 UTC

1#!/usr/bin/perl -p 1#!/usr/bin/perl
2 2
3use Pod::Tree;
4
3sub escape_texi($) { 5sub escape_texi($) {
4 local $_ = shift; 6 local $_ = shift;
5 s/([\@\{\}])/\@$1/g; 7 s/([\@\{\}])/\@$1/g;
6 s/\n+/ /g; 8 s/\n+/ /g;
7 $_; 9 $_;
8} 10}
9 11
12sub 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
10while (<>) { 21while (<>) {
11 if (/^\@c INCLUDE (\S+)/) { 22 if (/^\@c INCLUDE-(\S+) (\S+)/) {
23 my $type = $1;
12 my $name = $1; 24 my $name = $2;
13 my $pod = "$name.pod"; 25 my $path = $2;
14 26
15 $name =~ s/\.(\d)$/($1)/; 27 $name =~ s/\.(\d)$/($1)/;
16 28
17 print "\@chapter $name\n\n"; 29 print "\@chapter $name\n\n";
18 30
31 if ($type eq "POD") {
19 open $x, "<$pod" or die "$pod: $!"; 32 open my $x, "<$path.pod" or die "$path.pod: $!";
33 my $data = do { local $/; <$x> };
20 34
21 use Pod::Tree;
22
23 my $pod = new Pod::Tree; 35 my $pod = new Pod::Tree;
24 $pod->load_string(do { local $/; <$x> }); 36 $pod->load_string($data);
25 37
26 my $walker; $walker = sub { 38 my $walker; $walker = sub {
27 my $n = $_[0]; 39 my $n = $_[0];
28 if ($n->is_code) { 40 if ($n->is_code) {
29 # nop 41 # nop
30 } elsif ($n->is_link) { 42 } elsif ($n->is_link) {
31 my $target = $n->get_target; 43 my $target = $n->get_target;
32 my $page = $target->get_page; 44 my $page = $target->get_page;
33 my $section = $target->get_section; 45 my $section = $target->get_section;
34 46
35 #print "<b>"; 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{";
36 $walker->($_) for @{$n->get_children}; 57 $walker->($_) for @{$n->get_children};
37 #print "</b>"; 58 print "}";
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") { 59 } elsif ($n->get_letter eq "B") {
52 print "\@strong{"; 60 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}; 61 $walker->($_) for @{$n->get_children};
62 print "}";
63 } elsif ($n->get_letter eq "I" or $n->get_letter eq "F") {
77 print "\@refill\n"; 64 print "\@emph{";
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}; 65 $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{"; 66 print "}";
67 } else {
68 # S would mean to use nbsp
87 $walker->($_) for @{$n->get_children}; 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};
88 print "}\n\n"; 96 print "}\n\n";
89 $walker->($_) for @{$n->get_siblings}; 97 $walker->($_) for @{$n->get_siblings};
90 } else { 98 } else {
91 die "UNKNOWN NODE $_[0]{type}<br/>"; 99 die "UNKNOWN NODE $_[0]{type}<br/>";
92 $walker->($_) for @{$n->get_children}; 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;
93 } 115 }
94 };
95
96 $walker->($pod->get_root);
97 } else { 116 } else {
98 print; 117 print;
99 } 118 }
100} 119}
101 120

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines