2 # Script for extracting documentation out of header files
3 # (c) 2008 Michal Vaner <vorner@ucw.cz>
8 my( $inname, $outname, $depname, $basedir, $defdump ) = @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 $defdump ) {
21 open DUMP, ">>$defdump" or die "Could not write definition dump $defdump ($!)\n";
28 sub formatNote( $$ ) {
29 my( $head, $comment ) = @_;
30 $head =~ s/(\S)[ ]+/$1 /g;
34 print OUT "[[auto_$id]]\n";
35 if($head =~ /\w+\([^()]*\)/ && $head !~ /\n/) {
36 print OUT "!!f!$head!!!\n\n";
38 print OUT "..................\n";
40 print OUT "..................\n\n";
44 print DUMP "$outname,$id,$head\n";
47 print OUT "$comment\n\n";
52 open FILE, $file or die "Could nod read $file ($!)\n";
59 while( defined( $line = <FILE> ) ) {
64 formatNote( $head, $buff );
69 } elsif( $verbatim ) {
70 if( $line =~ /\*\// ) {
74 $line =~ s/^\s*\* ?//;
78 if( $line =~ /\*\// ) {
81 $line =~ s/^\s*\* ?//;
85 if( ( $line =~ /\S/ ) && ( defined $buff ) ) {
86 if( $line =~ /\(/ || $line !~ /{/ ) {
91 s/([;{]).*/";"x length( $1 )/e;
93 formatNote( $_, $buff );
100 } elsif( ( $buff ) = ( $line =~ /\/\*\*\*(.*)\*\*\*\// ) ) {
102 print OUT "$buff\n\n";
104 } elsif( ( $head, $buff ) = ( $line =~ /^(.*)\/\*\*(.*)\*\*\// ) ) {
107 if( $head =~ /\(/ || $head !~ /{/ ) {
109 $head =~ s/\/\*.*?\*\///gs;
110 $head =~ s/([;{]).*/";"x length( $1 )/e;
111 $head =~ s/\)\s*;$/);/;
112 formatNote( $head, $buff );
118 } elsif( $line =~ /\/\*\*\*/ ) {
120 } elsif( $line =~ /\/\*\*/ ) {
129 while( defined( $line = <IN> ) ) {
131 if( my( $fname ) = ( $line =~ /^!!\s*(.*\S)/ ) ) {
132 $fname = "$basedir/$fname" if( ( $fname !~ /^\// ) && defined $basedir );
140 if( defined $depname ) {
141 open DEP, ">$depname" or die "Could not write dep file $depname ($!)\n";
142 print DEP "$outname:";
143 print DEP " $_" foreach( @deps );
146 print DEP "$defdump:";
147 print DEP " $_" foreach( @deps );