X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=build%2Fdoc-extract;h=e20e7a941ce3c9b3088764a5950341c88b4885c6;hb=df17c554147ac4d68ead793d60ca1f8208bd2e6f;hp=ca4e42e2874fb771ae0b5b0d7aba25206093dafb;hpb=776f1a3bb4ee326f60cf4e1944ff80c1a3878d1e;p=libucw.git diff --git a/build/doc-extract b/build/doc-extract index ca4e42e2..e20e7a94 100755 --- a/build/doc-extract +++ b/build/doc-extract @@ -18,10 +18,30 @@ if( defined $outname ) { } my $hasdump; if( defined $defdump ) { - open DUMP, ">>$defdump" or die "Could not write definition dump $defdump ($!)\n"; + open DUMP, ">$defdump" or die "Could not write definition dump $defdump ($!)\n"; $hasdump = 1; } +sub detect( $ ) { + ( $_ ) = @_; + return( $1, 1, $2, "typedef $1 { ... } $2;" ) if /^\s*typedef\s+(struct|enum)\s*{.*}\s*(\w+)\s*;\s*$/s; + return( $1, 1, $2, $_ ) if /^\s*(struct|enum)\s+(\w+)\s*;\s*$/s; + my $l = length; + s/\n.*//s; + return( $1, 0, $2, $_ ) if /(struct|enum)\s+(\w+)\s+{/; + return( 'def', 0, $1, $_ ) if /#define\s+(\w+)/; + if( $l > length ) { + warn( "Unknown multiline statement $_\n" ); + return( '', 0, $_, $_ ); + } + return( 'type', 1, $2, $_ ) if /^\s*typedef[^()]+?(\(\s*?\*\s*?)?(\w+)(\s*\))?\s*\(.*\)/; + return( 'fun', 1, $2, $1 ) if /^(.*?(\w+)\([^{]*\)[^{]*)/; + return( 'type', 1, $1, $_ ) if /^\s*typedef.*?(\w+);/; + return( 'var', 1, $1, $_ ) if /\s\**(\w+);/; + warn( "Unknown statement $_\n" ); + return( '', 0, $_, $_ ); +} + my @deps; my $id = 0; @@ -31,17 +51,18 @@ sub formatNote( $$ ) { print OUT "\n"; print OUT "''''\n"; chomp $head; - print OUT "[[auto_$id]]\n"; - if($head =~ /\w+\([^()]*\)/ && $head !~ /\n/) { - print OUT "!!f!$head!!!\n\n"; - } else { - print OUT "..................\n"; - print OUT "$head\n"; - print OUT "..................\n\n"; - } + my( $type, $semicolon, $name, $oneline ) = detect( $head ); + $oneline =~ s/\s+$//; + $oneline =~ s/;?$/;/ if( $semicolon ); + $head =~ s/;?\s*$/;/ if( $semicolon ); + $head =~ s/(\.\.\.)/\\$1/g; + print OUT "[[${type}_$name]]\n"; + $head = $oneline if $type eq 'fun';#Remove { from inline functions + print OUT "..................\n"; + print OUT "$head\n"; + print OUT "..................\n\n"; if( $hasdump ) { - $head =~ s/\n.*//s; - print DUMP "$outname,$id,$head\n"; + print DUMP "$outname,${type}_$name,$type,$name,$oneline\n"; $id ++; } print OUT "$comment\n\n"; @@ -56,9 +77,18 @@ sub process( $ ) { my $buff; my $head; my $struct; + my $def; while( defined( $line = ) ) { chomp $line; - if( $struct ) { + if( $def ) { + $head .= "\n".$line; + $line =~ s/(\/\*.*?\*\/|\/\/.*)//g; + if( $line !~ /\\\s*$/ ) { + formatNote( $head, $buff ); + $def = 0; + $buff = $head = undef; + } + } elsif( $struct ) { $head .= "\n".$line; if( $line =~ /}/ ) { formatNote( $head, $buff ); @@ -83,13 +113,14 @@ sub process( $ ) { } } else { if( ( $line =~ /\S/ ) && ( defined $buff ) ) { - if( $line =~ /\(/ || $line !~ /{/ ) { + if( $line =~ /^\s*#define.*\\(\s*(\/\/.*|\/\*.*?\*\/|))*/ ) { + $head = $line; + $def = 1; + } elsif( $line =~ /\(/ || $line !~ /{/ || $line =~ /^\s*#define/ ) { $_ = $line; s/^\s*\s?//; s/\/\/.*//; s/\/\*.*?\*\///gs; - s/([;{]).*/";"x length( $1 )/e; - s/\)\s*;$/);/; formatNote( $_, $buff ); $head = undef; $buff = undef; @@ -104,11 +135,9 @@ sub process( $ ) { } elsif( ( $head, $buff ) = ( $line =~ /^(.*)\/\*\*(.*)\*\*\// ) ) { $buff =~ s/^\s*//; $buff =~ s/\s*$//; - if( $head =~ /\(/ || $head !~ /{/ ) { + if( $head =~ /\(/ || $head !~ /{/ || $head =~/}/ ) { $head =~ s/^\s*//; $head =~ s/\/\*.*?\*\///gs; - $head =~ s/([;{]).*/";"x length( $1 )/e; - $head =~ s/\)\s*;$/);/; formatNote( $head, $buff ); $head = undef; $buff = undef;