X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=build%2Fdoc-extract;h=67fdd64cb070ab919fe7de69cc239c8bf39ccd2f;hb=d4af13508dc83e2c6cca3ad5d7f7b07e370d8ab9;hp=5373a5a2898eba9e8d8966ec0a55a134a7589d92;hpb=b5e77aab53699c98d342e91e91d89472efb53c33;p=libucw.git diff --git a/build/doc-extract b/build/doc-extract index 5373a5a2..67fdd64c 100755 --- a/build/doc-extract +++ b/build/doc-extract @@ -18,25 +18,40 @@ 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; } +# Function to guess type of statement sub detect( $ ) { - ( $_ ) = @_; - my $l = length; - s/\n.*//s; - return( 'struct', 0, $1 ) if( /struct\s+(\w+)\s+{/ ); - return( 'enum', 0, $1 ) if( /enum\s+(\w+)\s+{/ ); - if( $l > length ) { - warn( "Unknown statemen $_\n" ); - return( '', 0, $_ ); - } - return( 'define', 0, $1 ) if( /#define\s+(\w+)/ ); - return( 'function', 1, $1 ) if( /(\w+)\(.*\)/ ); - return( 'variable', 1, $1 ) if( /\s(\w+);/ ); - warn( "Unknown statemen $_\n" ); - return( '', 0, $_ ); + ( $_ ) = @_; + # typedef struct|enum { something } name; + return( $1, 1, $2, "typedef $1 { ... } $2;" ) if /^\s*typedef\s+(struct|enum)\s*{.*}\s*(\w+)\s*;\s*$/s; + # struct|enum name { something }; + return( $1, 1, $2, $_ ) if /^\s*(struct|enum)\s+(\w+)\s*;\s*$/s; + my $l = length; + s/\n.*//s; + # struct|enum name { + # something + # }; + 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, $_, $_ ); + } + # typedef type (*function_type)(params); + return( 'type', 1, $2, $_ ) if /^\s*typedef[^()]+?(\(\s*?\*\s*?)?(\w+)(\s*\))?\s*\(.*\)/; + # type (*function_var)(params); + return( 'var', 1, $1, $_ ) if /^.*?\(\*(\w+)\)\(.*\)/; + # type function(name); + return( 'fun', 1, $2, $1 ) if /^(.*?(\w+)\([^{]*\)[^{]*)/; + # typedef something name; + return( 'type', 1, $1, $_ ) if /^\s*typedef.*?(\w+);/; + # type name; + return( 'var', 1, $1, $_ ) if /\s\**(\w+);/; + warn( "Unknown statement $_\n" ); + return( '', 0, $_, $_ ); } my @deps; @@ -48,26 +63,37 @@ sub formatNote( $$ ) { print OUT "\n"; print OUT "''''\n"; chomp $head; - print OUT "[[auto_$id]]\n"; - my( $type, $semicolon, $name ) = detect( $head ); - $head =~ s/;?\s+$/;/ if( $semicolon ); - if( $type eq 'function' ) { - 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 ); + # Just few transformations of the result + $oneline =~ s/\s+$//; + $oneline =~ s/;?$/;/ if( $semicolon ); + $head =~ s/;?\s*$/;/ if( $semicolon ); + $head =~ s/(\s|,|\()(\.\.\.)/$1\\$2/g; # Do not convert tripple dot into ellipsis + print OUT "[[${type}_$name]]\n"; + $head = $oneline if $type eq 'fun';#Remove { from inline functions + # Remove the generic hack markup + $head =~ s/_OPEN_PAREN_/(/g; + $head =~ s/_CLOSE_PAREN_/)/g; + print OUT "..................\n"; + print OUT "$head\n"; + print OUT "..................\n\n"; if( $hasdump ) { - $head =~ s/\n.*//s; - print DUMP "$outname,$id,$head\n"; + $oneline =~ s/_OPEN_PAREN_/(/g; + $oneline =~ s/_CLOSE_PAREN_/)/g; + my $symname = $type.'_'.$name; + $name =~ s/_OPEN_PAREN_/(/g; + $name =~ s/_CLOSE_PAREN_/)/g; + print DUMP "$outname,$symname,$type,$name,$oneline\n"; $id ++; } + $comment =~ s/_OPEN_PAREN_/(/g; + $comment =~ s/_CLOSE_PAREN_/)/g; + $comment =~ s/_GENERIC_LINK_\|([^|]+)\|([^|]+)\|/${1}_OPEN_PAREN_${2}_CLOSE_PAREN_/g; print OUT "$comment\n\n"; } -sub process( $ ) { - my $file = shift; +sub process( $$ ) { + my( $file, $prefixes ) = @_; open FILE, $file or die "Could nod read $file ($!)\n"; my $line; my $active; @@ -75,11 +101,26 @@ sub process( $ ) { my $buff; my $head; my $struct; + my $def; + my $sdepth; while( defined( $line = ) ) { chomp $line; - if( $struct ) { + # Generic macro hack - replaces the parenthesis so it is valid identifier + $line =~ s/$_\(([^()]+)\)/${_}_OPEN_PAREN_${1}_CLOSE_PAREN_/g foreach @{$prefixes}; + 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 =~ /}/ ) { + my $cp = $line; + $sdepth += ($cp =~ tr/{//); + $sdepth -= ($cp =~ tr/}//); + if( !$sdepth ) { formatNote( $head, $buff ); $struct = 0; $buff = undef; @@ -102,37 +143,39 @@ 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; } else { $head = $line; - $struct = 1; + $struct = $sdepth = 1; } } elsif( ( $buff ) = ( $line =~ /\/\*\*\*(.*)\*\*\*\// ) ) { - $buff =~ s/\s?//; + $buff =~ s/^\s?//; print OUT "$buff\n\n"; $buff = undef; + } elsif( ( $buff ) = ( $line =~ /^\s*\/\*\*(.*)\*\*\// ) ) { + $buff =~ s/^\s*//; + $buff .= "\n"; } 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; } else { - $struct = 1; + $struct = $sdepth = 1; } } elsif( $line =~ /\/\*\*\*/ ) { $verbatim = 1; @@ -147,9 +190,13 @@ sub process( $ ) { my $line; while( defined( $line = ) ) { chomp $line; - if( my( $fname ) = ( $line =~ /^!!\s*(.*\S)/ ) ) { + my $prefixes; + if( my( $fname, $prefixes ) = ( $line =~ /^!!\s*(\S+)(.*)/ ) ) { $fname = "$basedir/$fname" if( ( $fname !~ /^\// ) && defined $basedir ); - process( $fname ); + process( $fname, [ ( map( { + my( $result ) = /^\s*(.*\S)\s*$/; + $result; + } ( split /,/, $prefixes ) ) ) ] ); push @deps, $fname; } else { print OUT "$line\n";