]> mj.ucw.cz Git - libucw.git/blobdiff - build/doc-extract
Doc: Described ff-binary.
[libucw.git] / build / doc-extract
index a5af0e4e35ac52a89e062df3e42f1795f55f8747..b8751f903e88b000f21ba691e353a9c6b3270d32 100755 (executable)
@@ -23,20 +23,23 @@ if( defined $defdump ) {
 }
 
 sub detect( $ ) {
 }
 
 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 statement $_\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 statement $_\n" );
-        return( '', 0, $_ );
+       ( $_ ) = @_;
+       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 @deps;
@@ -48,26 +51,35 @@ sub formatNote( $$ ) {
        print OUT "\n";
        print OUT "''''\n";
        chomp $head;
        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 );
+       $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
+       $head =~ s/_OPEN_PAREN_/(/g;
+       $head =~ s/_CLOSE_PAREN_/)/g;
+       print OUT "..................\n";
+       print OUT "$head\n";
+       print OUT "..................\n\n";
        if( $hasdump ) {
        if( $hasdump ) {
-               $head =~ s/\n.*//s;
-               print DUMP "$outname,$id,$type,$name,$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 ++;
        }
                $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";
 }
 
        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;
        open FILE, $file or die "Could nod read $file ($!)\n";
        my $line;
        my $active;
@@ -75,9 +87,19 @@ sub process( $ ) {
        my $buff;
        my $head;
        my $struct;
        my $buff;
        my $head;
        my $struct;
+       my $def;
        while( defined( $line = <FILE> ) ) {
                chomp $line;
        while( defined( $line = <FILE> ) ) {
                chomp $line;
-               if( $struct ) {
+               $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 =~ /}/ ) {
                                formatNote( $head, $buff );
                        $head .= "\n".$line;
                        if( $line =~ /}/ ) {
                                formatNote( $head, $buff );
@@ -102,7 +124,10 @@ sub process( $ ) {
                        }
                } else {
                        if( ( $line =~ /\S/ ) && ( defined $buff ) ) {
                        }
                } 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/\/\/.*//;
                                        $_ = $line;
                                        s/^\s*\s?//;
                                        s/\/\/.*//;
@@ -121,7 +146,7 @@ sub process( $ ) {
                        } elsif( ( $head, $buff ) = ( $line =~ /^(.*)\/\*\*(.*)\*\*\// ) ) {
                                $buff =~ s/^\s*//;
                                $buff =~ s/\s*$//;
                        } elsif( ( $head, $buff ) = ( $line =~ /^(.*)\/\*\*(.*)\*\*\// ) ) {
                                $buff =~ s/^\s*//;
                                $buff =~ s/\s*$//;
-                               if( $head =~ /\(/ || $head !~ /{/ ) {
+                               if( $head =~ /\(/ || $head !~ /{/ || $head =~/}/ ) {
                                        $head =~ s/^\s*//;
                                        $head =~ s/\/\*.*?\*\///gs;
                                        formatNote( $head, $buff );
                                        $head =~ s/^\s*//;
                                        $head =~ s/\/\*.*?\*\///gs;
                                        formatNote( $head, $buff );
@@ -143,9 +168,13 @@ sub process( $ ) {
 my $line;
 while( defined( $line = <IN> ) ) {
        chomp $line;
 my $line;
 while( defined( $line = <IN> ) ) {
        chomp $line;
-       if( my( $fname ) = ( $line =~ /^!!\s*(.*\S)/ ) ) {
+       my $prefixes;
+       if( my( $fname, $prefixes ) = ( $line =~ /^!!\s*(\S+)(.*)/ ) ) {
                $fname = "$basedir/$fname" if( ( $fname !~ /^\// ) && defined $basedir );
                $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";
                push @deps, $fname;
        } else {
                print OUT "$line\n";