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