| 1 |
#!/usr/local/bin/perl -w |
| 2 |
use strict; |
| 3 |
use Getopt::Std; |
| 4 |
use ExtUtils::Manifest "/mani/"; |
| 5 |
my $tkdir = "../.."; |
| 6 |
my %opt; |
| 7 |
getopts('e',\%opt); |
| 8 |
|
| 9 |
my $files = maniread("$tkdir/MANIFEST"); |
| 10 |
|
| 11 |
@ARGV = grep(/\.pm$/,map("$tkdir/$_",sort keys %$files)); |
| 12 |
|
| 13 |
die "No pm files" unless @ARGV; |
| 14 |
|
| 15 |
BEGIN |
| 16 |
{ |
| 17 |
mkdir 'podnew', 0755 unless -d 'podnew'; # extracted POD |
| 18 |
mkdir 'podcoll', 0755 unless -d 'podcoll'; # exists already in ../pod/ |
| 19 |
mkdir 'tmppm', 0755 unless -d 'tmppm'; # finaly modified .pm? |
| 20 |
} |
| 21 |
|
| 22 |
my $modified; # has pod |
| 23 |
my $outfile; # tmp pm file |
| 24 |
my $infile; |
| 25 |
my $podname; |
| 26 |
my $inpod = 0; |
| 27 |
|
| 28 |
while (<>) |
| 29 |
{ |
| 30 |
if ($. == 1) |
| 31 |
{ |
| 32 |
$infile = $ARGV; |
| 33 |
my ($leaf) = $ARGV =~ m#/([^/]+)$#; |
| 34 |
$outfile = "tmppm/$leaf"; |
| 35 |
close(FILE) if (defined fileno(FILE)); |
| 36 |
close(POD) if (defined fileno(POD)); |
| 37 |
open(FILE,">$outfile") || die "Cannot open $outfile:$!"; |
| 38 |
$modified = 0; |
| 39 |
$inpod = 0; |
| 40 |
($podname = $leaf ) =~ s/[^.]+$/pod/; |
| 41 |
} |
| 42 |
###### |
| 43 |
|
| 44 |
if (/^=[a-z]/ && !defined(fileno(POD))) |
| 45 |
{ |
| 46 |
if (-f "$tkdir/pod/$podname") |
| 47 |
{ |
| 48 |
print "# Oops, pod name collision: $podname\n"; |
| 49 |
open POD, ">podcoll/$podname" or die "can't open podcoll/$podname"; |
| 50 |
} |
| 51 |
else |
| 52 |
{ |
| 53 |
open POD, ">podnew/$podname" or die "can't open podnew/$podname"; |
| 54 |
} |
| 55 |
my ($targ) = $ARGV =~ m#^$tkdir/(.*)$#; |
| 56 |
print POD "\n=for pm $targ\n\n"; |
| 57 |
|
| 58 |
} |
| 59 |
|
| 60 |
if (/^=cut/) |
| 61 |
{ |
| 62 |
$inpod = 0; |
| 63 |
print POD "\n" or die "can't print \\n for =cut"; |
| 64 |
} |
| 65 |
elsif (/^=[a-z]/) |
| 66 |
{ |
| 67 |
$inpod = 1; |
| 68 |
} |
| 69 |
|
| 70 |
if ($inpod) |
| 71 |
{ |
| 72 |
$modified++; |
| 73 |
print POD; |
| 74 |
} |
| 75 |
else |
| 76 |
{ |
| 77 |
print FILE; |
| 78 |
} |
| 79 |
|
| 80 |
###### |
| 81 |
if (eof) |
| 82 |
{ |
| 83 |
close(FILE) if (defined fileno(FILE)); |
| 84 |
if ($modified) |
| 85 |
{ |
| 86 |
warn "$infile modified"; |
| 87 |
print POD "\n\n=cut\n\n"; |
| 88 |
close POD; |
| 89 |
if ($opt{'e'}) |
| 90 |
{ |
| 91 |
if (-f "$infile.bak") |
| 92 |
{ |
| 93 |
chmod(0644,"$infile.bak") unless -w "$infile.bak"; |
| 94 |
unlink "$infile.bak"; |
| 95 |
} |
| 96 |
rename $infile, "$infile.bak"; |
| 97 |
system('p4',edit => $infile); |
| 98 |
rename $outfile, $infile or die "can't rename $ARGV $outfile: $!"; |
| 99 |
} |
| 100 |
print "diff -u $infile $outfile\t# $podname $modified POD lines\n"; |
| 101 |
} |
| 102 |
else |
| 103 |
{ |
| 104 |
unlink $outfile; |
| 105 |
} |
| 106 |
$modified = 0; |
| 107 |
$inpod = 0; |
| 108 |
$. = 0; |
| 109 |
} |
| 110 |
} |
| 111 |
|