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

Comparing gvpe/doc/pod2texi (file contents):
Revision 1.2 by pcg, Fri Mar 28 20:30:54 2003 UTC vs.
Revision 1.3 by pcg, Sun Apr 13 16:00:31 2003 UTC

1#!/usr/bin/perl -p 1#!/usr/bin/perl -p
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\@example\n";
42 my $text = $n->get_text;
43 $text =~ s/\n+$//;
44 $text =~ s/([\@\{\}])/@$1/g;
45 print $text;
46 print "\n\@end example\n\n";
47 } elsif ($n->is_sequence) {
48 if ($n->get_letter eq "C") {
49 print "\@t{";
50 $walker->($_) for @{$n->get_children};
51 print "}";
52 } elsif ($n->get_letter eq "B") { 59 } elsif ($n->get_letter eq "B") {
53 print "\@strong{"; 60 print "\@strong{";
54 $walker->($_) for @{$n->get_children};
55 print "}";
56 } elsif ($n->get_letter eq "I" or $n->get_letter eq "F") {
57 print "\@emph{";
58 $walker->($_) for @{$n->get_children};
59 print "}";
60 } else {
61 # S would mean to use nbsp
62 $walker->($_) for @{$n->get_children};
63 }
64 } elsif ($n->is_command) {
65 if ($n->is_c_head1) {
66 print "\n\@subsection ";
67 $walker->($_) for @{$n->get_children};
68 print "\n";
69 } elsif ($n->is_c_head2) {
70 print "\n\n\@subsubsection ";
71 $walker->($_) for @{$n->get_children};
72 print "\n";
73 } else {
74 # nop?
75 }
76 } elsif ($n->is_ordinary) {
77 $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") {
78 print "\@refill\n"; 64 print "\@emph{";
79 } elsif ($n->is_root) {
80 $walker->($_) for @{$n->get_children};
81 } elsif ($n->is_list) {
82 print "\n\n\@itemize\n";
83 $walker->($_) for @{$n->get_children}; 65 $walker->($_) for @{$n->get_children};
84 print "\@end itemize\n\n";
85 } elsif ($n->is_item) {
86 print "\n\n\@item\n";
87 print "\@b{"; 66 print "}";
67 } else {
68 # S would mean to use nbsp
88 $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\@subsection ";
74 $walker->($_) for @{$n->get_children};
75 print "\n";
76 } elsif ($n->is_c_head2) {
77 print "\n\n\@subsubsection ";
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};
89 print "}\n\n"; 96 print "}\n\n";
90 $walker->($_) for @{$n->get_siblings}; 97 $walker->($_) for @{$n->get_siblings};
91 } else { 98 } else {
92 die "UNKNOWN NODE $_[0]{type}<br/>"; 99 die "UNKNOWN NODE $_[0]{type}<br/>";
93 $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;
94 } 115 }
95 };
96
97 $walker->($pod->get_root);
98 } else { 116 } else {
99 print; 117 print;
100 } 118 }
101} 119}
102 120

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines