ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/doc/pod2texi
Revision: 1.2
Committed: Fri Mar 28 20:30:54 2003 UTC (21 years, 8 months ago) by pcg
Branch: MAIN
Changes since 1.1: +3 -2 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.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 pcg 1.2 print "\n\n\@example\n";
42 pcg 1.1 my $text = $n->get_text;
43     $text =~ s/\n+$//;
44 pcg 1.2 $text =~ s/([\@\{\}])/@$1/g;
45 pcg 1.1 print $text;
46 pcg 1.2 print "\n\@end example\n\n";
47 pcg 1.1 } 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") {
53     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};
78     print "\@refill\n";
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};
84     print "\@end itemize\n\n";
85     } elsif ($n->is_item) {
86     print "\n\n\@item\n";
87     print "\@b{";
88     $walker->($_) for @{$n->get_children};
89     print "}\n\n";
90     $walker->($_) for @{$n->get_siblings};
91     } else {
92     die "UNKNOWN NODE $_[0]{type}<br/>";
93     $walker->($_) for @{$n->get_children};
94     }
95     };
96    
97     $walker->($pod->get_root);
98     } else {
99     print;
100     }
101     }
102