| 1 |
#!/usr/bin/perl -w |
| 2 |
use strict; |
| 3 |
|
| 4 |
use Cwd; |
| 5 |
|
| 6 |
# doco.perl - 24 Jan 18:09:40 EST 2001 |
| 7 |
# Addi - ([email protected]) |
| 8 |
# |
| 9 |
# Extract documentation and help from the source files |
| 10 |
# |
| 11 |
# -f <files> list FIXME comments for files |
| 12 |
# -f list FIXME comments for all files |
| 13 |
# -d <file> list pod comments from file |
| 14 |
|
| 15 |
my $comm = shift or USAGE(); |
| 16 |
|
| 17 |
my @files; |
| 18 |
if ($comm eq "-f") { |
| 19 |
if (@ARGV) { |
| 20 |
@files = @ARGV; |
| 21 |
} |
| 22 |
else { |
| 23 |
@files = getfiles(); |
| 24 |
} |
| 25 |
|
| 26 |
for my $file (@files) { |
| 27 |
local(*FH, $/); open(FH,"< $file") or die $!; |
| 28 |
my $data = <FH>; close(FH); |
| 29 |
while( $data =~ m/FIXME:(.*?)\*\//sg ) { |
| 30 |
printf("%10.10s:%5d %s\n", $file, ptol($data, pos($data)), $1); |
| 31 |
} |
| 32 |
} |
| 33 |
exit(0); |
| 34 |
} |
| 35 |
|
| 36 |
if ($comm eq "-d") { |
| 37 |
USAGE() if !@ARGV; |
| 38 |
my $file = shift; |
| 39 |
getfiles(); |
| 40 |
local(*FH, $/); open(FH, "< $file") or die $!; |
| 41 |
my $data = <FH>; close(FH); |
| 42 |
$data =~ s/^(=item)/\n$1/mg; |
| 43 |
$data =~ s/^(=cut)/\n~~~~~~~~\n\n$1\n\n/mg; |
| 44 |
print "\n"; |
| 45 |
open(FH,"|pod2text ") or die "Cannot run pod2text: $!\n"; |
| 46 |
print FH $data; |
| 47 |
close(FH); |
| 48 |
exit(2); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
sub USAGE { |
| 53 |
|
| 54 |
print<<'EOF'; |
| 55 |
doco.perl [-f files| stuff] |
| 56 |
|
| 57 |
-f <files> list FIXME comments for files. |
| 58 |
-f list FIXME comments for all files. |
| 59 |
|
| 60 |
EOF |
| 61 |
exit; |
| 62 |
} |
| 63 |
|
| 64 |
sub getfiles { |
| 65 |
my $BASE=cwd; |
| 66 |
local(*FH); |
| 67 |
open(FH,"$BASE/MANIFEST") or die "Cannot open MANIFEST file: $!\n"; |
| 68 |
my @MANIFEST = <FH>; |
| 69 |
chomp(@MANIFEST); |
| 70 |
return grep { m/\.(c|im)\s*$/ } @MANIFEST; |
| 71 |
} |
| 72 |
|
| 73 |
# string position to line number in string |
| 74 |
|
| 75 |
sub ptol { |
| 76 |
my ($str, $pos) = @_; |
| 77 |
my $lcnt=1; |
| 78 |
$lcnt++ while(substr($str,0,$pos)=~m/\n/g); |
| 79 |
$lcnt; |
| 80 |
} |