2 # Script for extracting documentation out of header files
3 # (c) 2008 Michal Vaner <vorner@ucw.cz>
8 my( $inname, $outname, $depname, $basedir ) = @ARGV;
9 if( defined $inname ) {
10 open IN, $inname or die "Could not read $inname ($!)\n";
12 open IN, "<&STDIN" or die "Could not read stdin ($!)\n";
14 if( defined $outname ) {
15 open OUT, ">$outname" or die "Could not write $outname ($!)\n";
17 open OUT, ">&STDOUT" or die "Could not write to stdout ($!)\n";
20 if( defined $depname ) {
21 open DEP, ">>$depname" or die "Could not write $depname ($!)\n";
25 print DEP "$outname:" if( $hasdep );
27 sub formatNote( $$ ) {
28 my( $head, $comment ) = @_;
29 $head =~ s/(\S)[ ]+/$1 /g;
33 if($head =~ /\w+\([^()]*\)/ && $head !~ /\n/) {
34 print OUT "!!f!$head!!!\n\n";
36 print OUT "..................\n";
38 print OUT "..................\n\n";
40 print OUT "$comment\n\n";
45 open FILE, $file or die "Could nod read $file ($!)\n";
52 while( defined( $line = <FILE> ) ) {
57 formatNote( $head, $buff );
62 } elsif( $verbatim ) {
63 if( $line =~ /\*\// ) {
67 $line =~ s/^\s*\* ?//;
71 if( $line =~ /\*\// ) {
74 $line =~ s/^\s*\* ?//;
78 if( ( $line =~ /\S/ ) && ( defined $buff ) ) {
79 if( $line =~ /\(/ || $line !~ /{/ ) {
85 formatNote( $_, $buff );
92 } elsif( ( $buff ) = ( $line =~ /\/\*\*\*(.*)\*\*\*\// ) ) {
94 print OUT "$buff\n\n";
96 } elsif( ( $head, $buff ) = ( $line =~ /^(.*)\/\*\*(.*)\*\*\// ) ) {
99 if( $head =~ /\(/ || $head !~ /{/ ) {
101 $head =~ s/\/\*.*?\*\///gs;
103 formatNote( $head, $buff );
109 } elsif( $line =~ /\/\*\*\*/ ) {
111 } elsif( $line =~ /\/\*\*/ ) {
120 while( defined( $line = <IN> ) ) {
122 if( my( $fname ) = ( $line =~ /^!!\s*(.*\S)/ ) ) {
123 $fname = "$basedir/$fname" if( ( $fname !~ /^\// ) && defined $basedir );
125 print DEP " $fname" if( $hasdep );
131 print DEP "\n" if( $hasdep );