-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpod2otl
More file actions
executable file
·107 lines (89 loc) · 2.3 KB
/
Copy pathpod2otl
File metadata and controls
executable file
·107 lines (89 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/perl -w
# translates POD to TVO outliner format
# By Ned Konz Aug 2002
# $Id: pod2otl 73 2002-12-19 19:08:59Z ned $
use strict;
use IO::File;
use Text::Wrap;
use Pod::Parser;
use File::Basename;
package MyParser;
@MyParser::ISA = qw(Pod::Parser);
my $level = 0;
my $indent = "";
my $perl_fh;
$Text::Wrap::columns = 80;
sub level
{
$level = shift;
$indent = "\t" x $level;
# $Text::Wrap::columns = 80 - ($level * 8)
}
sub command
{
my ( $parser, $command, $paragraph, $line_num ) = @_;
my $prefix = "";
# correct level
if ( $command eq 'head1' ) { level(0) }
elsif ( $command eq 'head2' ) { level(1) }
elsif ( $command eq 'over' ) { level( ++$level ); return }
elsif ( $command eq 'back' ) { level( --$level ); return }
elsif ( $command eq 'item' ) { $prefix = '* ' }
my $out_fh = $parser->output_handle();
my $expansion = $parser->interpolate( $paragraph, $line_num );
chomp($paragraph);
$out_fh->print( $indent, $prefix, $paragraph );
}
sub verbatim
{
my ( $parser, $paragraph, $line_num ) = @_;
my $out_fh = $parser->output_handle();
for my $line ( split ( /\n/, $paragraph ) )
{
$line =~ s/^ //;
$out_fh->print( $indent, "|| ", $line, "\n" );
}
}
sub textblock
{
my ( $parser, $paragraph, $line_num ) = @_;
my $out_fh = $parser->output_handle();
my $expansion = $parser->interpolate( $paragraph, $line_num );
$out_fh->print(
Text::Wrap::fill( $indent . "| ", $indent . "| ", $expansion ), "\n" );
}
sub preprocess_paragraph
{
my ( $parser, $text, $line_num ) = @_;
if ( $perl_fh && $parser->cutting() ) { $perl_fh->print($text) }
return $text;
}
sub perl_to
{
my $parser = shift;
my $filename = shift;
$perl_fh = IO::File->new( $filename, 'w' )
or die "can't open $filename\: $!\n";
}
package main;
## Create a parser object and have it parse file whose name was
## given on the command-line (use STDIN if no files were given).
my $parser = new MyParser();
$parser->parseopts( -want_nonPODs => 1 );
if ( @ARGV == 0 )
{
# write Perl to pod2otlout.pl
# write OTL to STDOUT
$parser->perl_to('pod2otlout.pl');
$parser->parse_from_filehandle( \*STDIN );
}
else
{
for (@ARGV)
{
my $filename = $_;
my ($name, $path, $suffix) = fileparse($filename, '.p[lm]');
$parser->perl_to( $path . $name . ".p2o" );
$parser->parse_from_file($filename, $path . $name . ".otl");
}
}