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";
27 return( 'struct', 1, $1, "typedef struct { ... } $1;" ) if( /^\s*typedef\s+struct\s*{.*}\s*(\w+)\s*;\s*$/s );
28 return( 'enum', 1, $1, "typedef enum { ... } $1;" ) if( /^\s*typedef\s+enum\s*{.*}\s*(\w+)\s*;\s*$/s );
31 return( 'struct', 0, $1, $_ ) if( /struct\s+(\w+)\s+{/ );
32 return( 'enum', 0, $1, $_ ) if( /enum\s+(\w+)\s+{/ );
34 warn( "Unknown statement $_\n" );
35 return( '', 0, $_, $_ );
37 return( 'define', 0, $1, $_ ) if( /#define\s+(\w+)/ );
38 return( 'function', 1, $1, $_ ) if( /(\w+)\(.*\)/ );
39 return( 'variable', 1, $1, $_ ) if( /\s(\w+);/ );
40 warn( "Unknown statement $_\n" );
41 return( '', 0, $_, $_ );
47 sub formatNote( $$ ) {
48 my( $head, $comment ) = @_;
49 $head =~ s/(\S)[ ]+/$1 /g;
53 print OUT "[[auto_$id]]\n";
54 my( $type, $semicolon, $name, $oneline ) = detect( $head );
55 $head =~ s/;?\s*$/;/ if( $semicolon );
56 if( $type eq 'function' ) {
57 print OUT "!!f!$head!!!\n\n";
59 print OUT "..................\n";
61 print OUT "..................\n\n";
64 print DUMP "$outname,$id,$type,$name,$oneline\n";
67 print OUT "$comment\n\n";
72 open FILE, $file or die "Could nod read $file ($!)\n";
79 while( defined( $line = <FILE> ) ) {
84 formatNote( $head, $buff );
89 } elsif( $verbatim ) {
90 if( $line =~ /\*\// ) {
94 $line =~ s/^\s*\* ?//;
98 if( $line =~ /\*\// ) {
101 $line =~ s/^\s*\* ?//;
105 if( ( $line =~ /\S/ ) && ( defined $buff ) ) {
106 if( $line =~ /\(/ || $line !~ /{/ ) {
111 formatNote( $_, $buff );
118 } elsif( ( $buff ) = ( $line =~ /\/\*\*\*(.*)\*\*\*\// ) ) {
120 print OUT "$buff\n\n";
122 } elsif( ( $head, $buff ) = ( $line =~ /^(.*)\/\*\*(.*)\*\*\// ) ) {
125 if( $head =~ /\(/ || $head !~ /{/ ) {
127 $head =~ s/\/\*.*?\*\///gs;
128 formatNote( $head, $buff );
134 } elsif( $line =~ /\/\*\*\*/ ) {
136 } elsif( $line =~ /\/\*\*/ ) {
145 while( defined( $line = <IN> ) ) {
147 if( my( $fname ) = ( $line =~ /^!!\s*(.*\S)/ ) ) {
148 $fname = "$basedir/$fname" if( ( $fname !~ /^\// ) && defined $basedir );
156 if( defined $depname ) {
157 open DEP, ">>$depname" or die "Could not write dep file $depname ($!)\n";
158 print DEP "$outname:";
159 print DEP " $_" foreach( @deps );
162 print DEP "$defdump:";
163 print DEP " $_" foreach( @deps );