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";
29 return( 'struct', 0, $1 ) if( /struct\s+(\w+)\s+{/ );
30 return( 'enum', 0, $1 ) if( /enum\s+(\w+)\s+{/ );
32 warn( "Unknown statement $_\n" );
35 return( 'define', 0, $1 ) if( /#define\s+(\w+)/ );
36 return( 'function', 1, $1 ) if( /(\w+)\(.*\)/ );
37 return( 'variable', 1, $1 ) if( /\s(\w+);/ );
38 warn( "Unknown statement $_\n" );
45 sub formatNote( $$ ) {
46 my( $head, $comment ) = @_;
47 $head =~ s/(\S)[ ]+/$1 /g;
51 print OUT "[[auto_$id]]\n";
52 my( $type, $semicolon, $name ) = detect( $head );
53 $head =~ s/;?\s*$/;/ if( $semicolon );
54 if( $type eq 'function' ) {
55 print OUT "!!f!$head!!!\n\n";
57 print OUT "..................\n";
59 print OUT "..................\n\n";
63 print DUMP "$outname,$id,$type,$name,$head\n";
66 print OUT "$comment\n\n";
71 open FILE, $file or die "Could nod read $file ($!)\n";
78 while( defined( $line = <FILE> ) ) {
83 formatNote( $head, $buff );
88 } elsif( $verbatim ) {
89 if( $line =~ /\*\// ) {
93 $line =~ s/^\s*\* ?//;
97 if( $line =~ /\*\// ) {
100 $line =~ s/^\s*\* ?//;
104 if( ( $line =~ /\S/ ) && ( defined $buff ) ) {
105 if( $line =~ /\(/ || $line !~ /{/ ) {
110 formatNote( $_, $buff );
117 } elsif( ( $buff ) = ( $line =~ /\/\*\*\*(.*)\*\*\*\// ) ) {
119 print OUT "$buff\n\n";
121 } elsif( ( $head, $buff ) = ( $line =~ /^(.*)\/\*\*(.*)\*\*\// ) ) {
124 if( $head =~ /\(/ || $head !~ /{/ ) {
126 $head =~ s/\/\*.*?\*\///gs;
127 formatNote( $head, $buff );
133 } elsif( $line =~ /\/\*\*\*/ ) {
135 } elsif( $line =~ /\/\*\*/ ) {
144 while( defined( $line = <IN> ) ) {
146 if( my( $fname ) = ( $line =~ /^!!\s*(.*\S)/ ) ) {
147 $fname = "$basedir/$fname" if( ( $fname !~ /^\// ) && defined $basedir );
155 if( defined $depname ) {
156 open DEP, ">>$depname" or die "Could not write dep file $depname ($!)\n";
157 print DEP "$outname:";
158 print DEP " $_" foreach( @deps );
161 print DEP "$defdump:";
162 print DEP " $_" foreach( @deps );