-
Notifications
You must be signed in to change notification settings - Fork 0
/
mypod2man
executable file
·88 lines (69 loc) · 1.83 KB
/
mypod2man
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
#!/usr/bin/perl
# Just a script to create manochrome manpage.
# To create your own man pages use pod2man.
use strict;
use warnings;
use File::Copy;
use File::Basename;
use Pod::Man;
use Getopt::Std;
my %opts;
getopts('f', \%opts);
my $cwd = dirname(__FILE__);
my $cstring="MANochrome";
my $nstring="manochrome";
my $pod_outfile = "${cwd}/doc/pod/${nstring}.pod";
my $readme="$cwd/Readme.pod";
my $mandir="$cwd/doc/man/man1";
my $infile="$cwd/doc/pod/${nstring}.pod";
my $outfile="$mandir/${nstring}.1";
my $copyoutfile="$mandir/manopod2html.1";
my $date=`date "+%Y-%m-%d"`;
chomp($date);
my $version="v0.1";
die "Could not find $mandir.\n" if (! -d $mandir);
die "Could not find $readme.\n" if (! -e $readme);
die "$infile does not exist.\n" if (! -e $infile);
copy($readme, $pod_outfile);
# Filter HTML from .pod if $opts{f}.
# The HTML is only for github in Readme.pod.
filter_html($pod_outfile) if ($opts{f});
# Convert pod to man.
my $parser = Pod::Man->new(
center => $cstring,
release => $version,
section => 1,
name => $nstring,
date => $date
);
$parser->parse_from_file($infile, $outfile);
# Create copy of manochrome.1
# man pages for manochrome and manopod2html are identical.
copy($outfile, $copyoutfile);
die "$outfile does not exist" if (! -e $outfile);
die "$copyoutfile does not exist" if (! -e $copyoutfile);
print <<END;
Created $outfile
Created $copyoutfile
END
sub filter_html {
my ($file) = @_;
my $filter = 0;
open(RF, "<$file") or die $!;
my @rf = <RF>;
close(RF);
open(EDIT, ">$file") or die $!;
for (@rf) {
if ($_ =~ m/^=begin html/) {
$filter = 1;
next;
}
if ($_ =~ m/^=end html/) {
$filter = 0;
next;
}
next if $filter;
print EDIT $_;
}
close(EDIT);
}