--- gvpe/doc/pod2texi 2003/03/28 20:30:54 1.2 +++ gvpe/doc/pod2texi 2003/04/13 16:00:31 1.3 @@ -1,5 +1,7 @@ #!/usr/bin/perl -p +use Pod::Tree; + sub escape_texi($) { local $_ = shift; s/([\@\{\}])/\@$1/g; @@ -7,94 +9,110 @@ $_; } +sub example { + my $text = $_[0]; + print "\n\n\@example\n"; + $text =~ s/\n+$//; + $text =~ s/([\@\{\}])/@$1/g; + print $text; + print "\n\@end example\n\n"; +} + while (<>) { - if (/^\@c INCLUDE (\S+)/) { - my $name = $1; - my $pod = "$name.pod"; + if (/^\@c INCLUDE-(\S+) (\S+)/) { + my $type = $1; + my $name = $2; + my $path = $2; $name =~ s/\.(\d)$/($1)/; print "\@chapter $name\n\n"; - open $x, "<$pod" or die "$pod: $!"; + if ($type eq "POD") { + open my $x, "<$path.pod" or die "$path.pod: $!"; + my $data = do { local $/; <$x> }; + + my $pod = new Pod::Tree; + $pod->load_string($data); + + my $walker; $walker = sub { + my $n = $_[0]; + if ($n->is_code) { + # nop + } elsif ($n->is_link) { + my $target = $n->get_target; + my $page = $target->get_page; + my $section = $target->get_section; + + #print ""; + $walker->($_) for @{$n->get_children}; + #print ""; + } elsif ($n->is_text) { + print escape_texi $n->get_text; + } elsif ($n->is_verbatim) { + example $n->get_text; + } elsif ($n->is_sequence) { + if ($n->get_letter eq "C") { + print "\@t{"; + $walker->($_) for @{$n->get_children}; + print "}"; + } elsif ($n->get_letter eq "B") { + print "\@strong{"; + $walker->($_) for @{$n->get_children}; + print "}"; + } elsif ($n->get_letter eq "I" or $n->get_letter eq "F") { + print "\@emph{"; + $walker->($_) for @{$n->get_children}; + print "}"; + } else { + # S would mean to use nbsp + $walker->($_) for @{$n->get_children}; + } + } elsif ($n->is_command) { + if ($n->is_c_head1) { + print "\n\@subsection "; + $walker->($_) for @{$n->get_children}; + print "\n"; + } elsif ($n->is_c_head2) { + print "\n\n\@subsubsection "; + $walker->($_) for @{$n->get_children}; + print "\n"; + } else { + # nop? + } + } elsif ($n->is_ordinary) { + $walker->($_) for @{$n->get_children}; + print "\@refill\n"; + } elsif ($n->is_root) { + $walker->($_) for @{$n->get_children}; + } elsif ($n->is_list) { + print "\n\n\@itemize\n"; + $walker->($_) for @{$n->get_children}; + print "\@end itemize\n\n"; + } elsif ($n->is_item) { + print "\n\n\@item\n"; + print "\@b{"; + $walker->($_) for @{$n->get_children}; + print "}\n\n"; + $walker->($_) for @{$n->get_siblings}; + } else { + die "UNKNOWN NODE $_[0]{type}
"; + $walker->($_) for @{$n->get_children}; + } + }; + + $walker->($pod->get_root); + } elsif ($type eq "TEXT") { + open my $x, "<$path" or die "$path: $!"; + my $data = do { local $/; <$x> }; + + print $data; + } elsif ($type eq "EXAMPLE") { + open my $x, "<$path" or die "$path: $!"; + my $data = do { local $/; <$x> }; - use Pod::Tree; - - my $pod = new Pod::Tree; - $pod->load_string(do { local $/; <$x> }); - - my $walker; $walker = sub { - my $n = $_[0]; - if ($n->is_code) { - # nop - } elsif ($n->is_link) { - my $target = $n->get_target; - my $page = $target->get_page; - my $section = $target->get_section; - - #print ""; - $walker->($_) for @{$n->get_children}; - #print ""; - } elsif ($n->is_text) { - print escape_texi $n->get_text; - } elsif ($n->is_verbatim) { - print "\n\n\@example\n"; - my $text = $n->get_text; - $text =~ s/\n+$//; - $text =~ s/([\@\{\}])/@$1/g; - print $text; - print "\n\@end example\n\n"; - } elsif ($n->is_sequence) { - if ($n->get_letter eq "C") { - print "\@t{"; - $walker->($_) for @{$n->get_children}; - print "}"; - } elsif ($n->get_letter eq "B") { - print "\@strong{"; - $walker->($_) for @{$n->get_children}; - print "}"; - } elsif ($n->get_letter eq "I" or $n->get_letter eq "F") { - print "\@emph{"; - $walker->($_) for @{$n->get_children}; - print "}"; - } else { - # S would mean to use nbsp - $walker->($_) for @{$n->get_children}; - } - } elsif ($n->is_command) { - if ($n->is_c_head1) { - print "\n\@subsection "; - $walker->($_) for @{$n->get_children}; - print "\n"; - } elsif ($n->is_c_head2) { - print "\n\n\@subsubsection "; - $walker->($_) for @{$n->get_children}; - print "\n"; - } else { - # nop? - } - } elsif ($n->is_ordinary) { - $walker->($_) for @{$n->get_children}; - print "\@refill\n"; - } elsif ($n->is_root) { - $walker->($_) for @{$n->get_children}; - } elsif ($n->is_list) { - print "\n\n\@itemize\n"; - $walker->($_) for @{$n->get_children}; - print "\@end itemize\n\n"; - } elsif ($n->is_item) { - print "\n\n\@item\n"; - print "\@b{"; - $walker->($_) for @{$n->get_children}; - print "}\n\n"; - $walker->($_) for @{$n->get_siblings}; - } else { - die "UNKNOWN NODE $_[0]{type}
"; - $walker->($_) for @{$n->get_children}; - } - }; - - $walker->($pod->get_root); + example $data; + } } else { print; }