]> mj.ucw.cz Git - libucw.git/blobdiff - build/doc-extract
Doc. system: detect function typedefs
[libucw.git] / build / doc-extract
index ca4e42e2874fb771ae0b5b0d7aba25206093dafb..2ef86026c50243f7244acf70f7e16b3a6695c62a 100755 (executable)
@@ -18,10 +18,31 @@ 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( 'struct', 1, $1, "typedef struct { ... } $1;" ) if /^\s*typedef\s+struct\s*{.*}\s*(\w+)\s*;\s*$/s;
+       return( 'enum', 1, $1, "typedef enum { ... } $1;" ) if /^\s*typedef\s+enum\s*{.*}\s*(\w+)\s*;\s*$/s;
+        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( 'def', 0, $1, $_ ) if /#define\s+(\w+)/;
+       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 +52,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";
@@ -88,8 +110,6 @@ sub process( $ ) {
                                        s/^\s*\s?//;
                                        s/\/\/.*//;
                                        s/\/\*.*?\*\///gs;
-                                       s/([;{]).*/";"x length( $1 )/e;
-                                       s/\)\s*;$/);/;
                                        formatNote( $_, $buff );
                                        $head = undef;
                                        $buff = undef;
@@ -107,8 +127,6 @@ sub process( $ ) {
                                if( $head =~ /\(/ || $head !~ /{/ ) {
                                        $head =~ s/^\s*//;
                                        $head =~ s/\/\*.*?\*\///gs;
-                                       $head =~ s/([;{]).*/";"x length( $1 )/e;
-                                       $head =~ s/\)\s*;$/);/;
                                        formatNote( $head, $buff );
                                        $head = undef;
                                        $buff = undef;