nfsd: Pull write-gathering code out of nfsd_vfs_write
[safe/jmp/linux-2.6] / scripts / kernel-doc
index 1c1d350..3208a3a 100755 (executable)
@@ -5,7 +5,7 @@ use strict;
 ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved        ##
 ## Copyright (C) 2000, 1  Tim Waugh <twaugh@redhat.com>          ##
 ## Copyright (C) 2001  Simon Huggins                             ##
-## Copyright (C) 2005-2007  Randy Dunlap                         ##
+## Copyright (C) 2005-2008  Randy Dunlap                         ##
 ##                                                              ##
 ## #define enhancements by Armin Kuster <akuster@mvista.com>    ##
 ## Copyright (c) 2000 MontaVista Software, Inc.                         ##
@@ -218,6 +218,7 @@ sub usage {
     print "         [ -function funcname [ -function funcname ...] ]\n";
     print "         [ -nofunction funcname [ -nofunction funcname ...] ]\n";
     print "         c source file(s) > outputfile\n";
+    print "         -v : verbose output, more warnings & other info listed\n";
     exit 1;
 }
 
@@ -246,6 +247,10 @@ my ($function, %function_table,%parametertypes,$declaration_purpose);
 my ($type,$declaration_name,$return_type);
 my ($newsection,$newcontents,$prototype,$filelist, $brcount, %source_map);
 
+if (defined($ENV{'KBUILD_VERBOSE'})) {
+       $verbose = "$ENV{'KBUILD_VERBOSE'}";
+}
+
 # Generated docbook code is inserted in a template at a point where
 # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
 # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
@@ -284,6 +289,8 @@ my %parameterdescs;
 my @parameterlist;
 my %sections;
 my @sectionlist;
+my $sectcheck;
+my $struct_actual;
 
 my $contents = "";
 my $section_default = "Description";   # default section
@@ -361,6 +368,7 @@ foreach my $pattern (keys %highlights) {
 # dumps section contents to arrays/hashes intended for that purpose.
 #
 sub dump_section {
+    my $file = shift;
     my $name = shift;
     my $contents = join "\n", @_;
 
@@ -372,8 +380,18 @@ sub dump_section {
 #      print STDERR "parameter def '$1' = '$contents'\n";
        $name = $1;
        $parameterdescs{$name} = $contents;
+       $sectcheck = $sectcheck . $name . " ";
+    } elsif ($name eq "@\.\.\.") {
+#      print STDERR "parameter def '...' = '$contents'\n";
+       $name = "...";
+       $parameterdescs{$name} = $contents;
+       $sectcheck = $sectcheck . $name . " ";
     } else {
 #      print STDERR "other section '$name' = '$contents'\n";
+       if (defined($sections{$name}) && ($sections{$name} ne "")) {
+               print STDERR "Error(${file}:$.): duplicate section name '$name'\n";
+               ++$errors;
+       }
        $sections{$name} = $contents;
        push @sectionlist, $name;
     }
@@ -383,6 +401,7 @@ sub dump_section {
 # dump DOC: section after checking that it should go out
 #
 sub dump_doc_section {
+    my $file = shift;
     my $name = shift;
     my $contents = join "\n", @_;
 
@@ -394,7 +413,7 @@ sub dump_doc_section {
        ( $function_only == 1 && defined($function_table{$name})) ||
        ( $function_only == 2 && !defined($function_table{$name})))
     {
-       dump_section $name, $contents;
+       dump_section($file, $name, $contents);
        output_blockhead({'sectionlist' => \@sectionlist,
                          'sections' => \%sections,
                          'module' => $modulename,
@@ -770,6 +789,7 @@ sub output_struct_xml(%) {
     print " <refsect1>\n";
     print "  <title>Members</title>\n";
 
+    if ($#{$args{'parameterlist'}} >= 0) {
     print "  <variablelist>\n";
     foreach $parameter (@{$args{'parameterlist'}}) {
       ($parameter =~ /^#/) && next;
@@ -787,6 +807,9 @@ sub output_struct_xml(%) {
       print "    </varlistentry>\n";
     }
     print "  </variablelist>\n";
+    } else {
+       print " <para>\n  None\n </para>\n";
+    }
     print " </refsect1>\n";
 
     output_section_xml(@_);
@@ -1386,21 +1409,26 @@ sub dump_union($$) {
 sub dump_struct($$) {
     my $x = shift;
     my $file = shift;
+    my $nested;
 
-    if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
+    if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
+       #my $decl_type = $1;
        $declaration_name = $2;
        my $members = $3;
 
        # ignore embedded structs or unions
-       $members =~ s/{.*?}//g;
+       $members =~ s/({.*})//g;
+       $nested = $1;
 
        # ignore members marked private:
-       $members =~ s/\/\*.*?private:.*?public:.*?\*\///gos;
-       $members =~ s/\/\*.*?private:.*//gos;
+       $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gos;
+       $members =~ s/\/\*\s*private:.*//gos;
        # strip comments:
        $members =~ s/\/\*.*?\*\///gos;
+       $nested =~ s/\/\*.*?\*\///gos;
 
        create_parameterlist($members, ';', $file);
+       check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
 
        output_declaration($declaration_name,
                           'struct',
@@ -1486,6 +1514,14 @@ sub dump_typedef($$) {
     }
 }
 
+sub save_struct_actual($) {
+    my $actual = shift;
+
+    # strip all spaces from the actual param so that it looks like one string item
+    $actual =~ s/\s*//g;
+    $struct_actual = $struct_actual . $actual . " ";
+}
+
 sub create_parameterlist($$$) {
     my $args = shift;
     my $splitter = shift;
@@ -1511,13 +1547,14 @@ sub create_parameterlist($$$) {
            # corresponding data structures "correctly". Catch it later in
            # output_* subs.
            push_parameter($arg, "", $file);
-       } elsif ($arg =~ m/\(.*\*/) {
+       } elsif ($arg =~ m/\(.+\)\s*\(/) {
            # pointer-to-function
            $arg =~ tr/#/,/;
-           $arg =~ m/[^\(]+\(\*\s*([^\)]+)\)/;
+           $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
            $param = $1;
            $type = $arg;
-           $type =~ s/([^\(]+\(\*)$param/$1/;
+           $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
+           save_struct_actual($param);
            push_parameter($param, $type, $file);
        } elsif ($arg) {
            $arg =~ s/\s*:\s*/:/g;
@@ -1542,12 +1579,17 @@ sub create_parameterlist($$$) {
 
            foreach $param (@args) {
                if ($param =~ m/^(\*+)\s*(.*)/) {
+                   save_struct_actual($2);
                    push_parameter($2, "$type $1", $file);
                }
                elsif ($param =~ m/(.*?):(\d+)/) {
-                   push_parameter($1, "$type:$2", $file)
+                   if ($type ne "") { # skip unnamed bit-fields
+                       save_struct_actual($1);
+                       push_parameter($1, "$type:$2", $file)
+                   }
                }
                else {
+                   save_struct_actual($param);
                    push_parameter($param, $type, $file);
                }
            }
@@ -1571,12 +1613,12 @@ sub push_parameter($$$) {
 
        if ($type eq "" && $param =~ /\.\.\.$/)
        {
-           $type="";
-           $parameterdescs{$param} = "variable arguments";
+           if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
+               $parameterdescs{$param} = "variable arguments";
+           }
        }
        elsif ($type eq "" && ($param eq "" or $param eq "void"))
        {
-           $type="";
            $param="void";
            $parameterdescs{void} = "no arguments";
        }
@@ -1613,6 +1655,46 @@ sub push_parameter($$$) {
        $parametertypes{$param} = $type;
 }
 
+sub check_sections($$$$$$) {
+       my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
+       my @sects = split ' ', $sectcheck;
+       my @prms = split ' ', $prmscheck;
+       my $err;
+       my ($px, $sx);
+       my $prm_clean;          # strip trailing "[array size]" and/or beginning "*"
+
+       foreach $sx (0 .. $#sects) {
+               $err = 1;
+               foreach $px (0 .. $#prms) {
+                       $prm_clean = $prms[$px];
+                       $prm_clean =~ s/\[.*\]//;
+                       $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//;
+                       ##$prm_clean =~ s/^\**//;
+                       if ($prm_clean eq $sects[$sx]) {
+                               $err = 0;
+                               last;
+                       }
+               }
+               if ($err) {
+                       if ($decl_type eq "function") {
+                               print STDERR "Warning(${file}:$.): " .
+                                       "Excess function parameter " .
+                                       "'$sects[$sx]' " .
+                                       "description in '$decl_name'\n";
+                               ++$warnings;
+                       } else {
+                               if ($nested !~ m/\Q$sects[$sx]\E/) {
+                                   print STDERR "Warning(${file}:$.): " .
+                                       "Excess struct/union/enum/typedef member " .
+                                       "'$sects[$sx]' " .
+                                       "description in '$decl_name'\n";
+                                   ++$warnings;
+                               }
+                       }
+               }
+       }
+}
+
 ##
 # takes a function prototype and the name of the current file being
 # processed and spits out all the details stored in the global
@@ -1623,7 +1705,6 @@ sub dump_function($$) {
 
     $prototype =~ s/^static +//;
     $prototype =~ s/^extern +//;
-    $prototype =~ s/^fastcall +//;
     $prototype =~ s/^asmlinkage +//;
     $prototype =~ s/^inline +//;
     $prototype =~ s/^__inline__ +//;
@@ -1631,7 +1712,8 @@ sub dump_function($$) {
     $prototype =~ s/^__always_inline +//;
     $prototype =~ s/^noinline +//;
     $prototype =~ s/__devinit +//;
-    $prototype =~ s/^#define\s+//; #ak added
+    $prototype =~ s/__init +//;
+    $prototype =~ s/^#\s*define\s+//; #ak added
     $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
 
     # Yes, this truly is vile.  We are looking for:
@@ -1678,6 +1760,9 @@ sub dump_function($$) {
        return;
     }
 
+       my $prms = join " ", @parameterlist;
+       check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
+
     output_declaration($declaration_name,
                       'function',
                       {'function' => $declaration_name,
@@ -1736,28 +1821,68 @@ sub reset_state {
     @parameterlist = ();
     %sections = ();
     @sectionlist = ();
+    $sectcheck = "";
+    $struct_actual = "";
     $prototype = "";
 
     $state = 0;
 }
 
+sub syscall_munge() {
+       my $void = 0;
+
+       $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
+##     if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
+       if ($prototype =~ m/SYSCALL_DEFINE0/) {
+               $void = 1;
+##             $prototype = "long sys_$1(void)";
+       }
+
+       $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
+       if ($prototype =~ m/long (sys_.*?),/) {
+               $prototype =~ s/,/\(/;
+       } elsif ($void) {
+               $prototype =~ s/\)/\(void\)/;
+       }
+
+       # now delete all of the odd-number commas in $prototype
+       # so that arg types & arg names don't have a comma between them
+       my $count = 0;
+       my $len = length($prototype);
+       if ($void) {
+               $len = 0;       # skip the for-loop
+       }
+       for (my $ix = 0; $ix < $len; $ix++) {
+               if (substr($prototype, $ix, 1) eq ',') {
+                       $count++;
+                       if ($count % 2 == 1) {
+                               substr($prototype, $ix, 1) = ' ';
+                       }
+               }
+       }
+}
+
 sub process_state3_function($$) {
     my $x = shift;
     my $file = shift;
 
     $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
 
-    if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) {
+    if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
        # do nothing
     }
     elsif ($x =~ /([^\{]*)/) {
        $prototype .= $1;
     }
-    if (($x =~ /\{/) || ($x =~ /\#define/) || ($x =~ /;/)) {
+
+    if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
        $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
        $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
        $prototype =~ s@^\s+@@gos; # strip leading spaces
-       dump_function($prototype,$file);
+       if ($prototype =~ /SYSCALL_DEFINE/) {
+               syscall_munge();
+       }
+       dump_function($prototype, $file);
        reset_state();
     }
 }
@@ -1881,6 +2006,13 @@ sub process_file($) {
                } else {
                    $declaration_purpose = "";
                }
+
+               if (($declaration_purpose eq "") && $verbose) {
+                       print STDERR "Warning(${file}:$.): missing initial short description on line:\n";
+                       print STDERR $_;
+                       ++$warnings;
+               }
+
                if ($identifier =~ m/^struct/) {
                    $decl_type = 'struct';
                } elsif ($identifier =~ m/^union/) {
@@ -1907,12 +2039,12 @@ sub process_file($) {
                $newsection = $1;
                $newcontents = $2;
 
-               if ($contents ne "") {
+               if (($contents ne "") && ($contents ne "\n")) {
                    if (!$in_doc_sect && $verbose) {
                        print STDERR "Warning(${file}:$.): contents before sections\n";
                        ++$warnings;
                    }
-                   dump_section($section, xml_escape($contents));
+                   dump_section($file, $section, xml_escape($contents));
                    $section = $section_default;
                }
 
@@ -1929,10 +2061,15 @@ sub process_file($) {
            } elsif (/$doc_end/) {
 
                if ($contents ne "") {
-                   dump_section($section, xml_escape($contents));
+                   dump_section($file, $section, xml_escape($contents));
                    $section = $section_default;
                    $contents = "";
                }
+               # look for doc_com + <text> + doc_end:
+               if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
+                   print STDERR "Warning(${file}:$.): suspicious ending line: $_";
+                   ++$warnings;
+               }
 
                $prototype = "";
                $state = 3;
@@ -1943,7 +2080,7 @@ sub process_file($) {
                # @parameter line to signify start of description
                if ($1 eq "" &&
                        ($section =~ m/^@/ || $section eq $section_context)) {
-                   dump_section($section, xml_escape($contents));
+                   dump_section($file, $section, xml_escape($contents));
                    $section = $section_default;
                    $contents = "";
                } else {
@@ -1963,7 +2100,7 @@ sub process_file($) {
        } elsif ($state == 4) {
                # Documentation block
                if (/$doc_block/) {
-                       dump_doc_section($section, xml_escape($contents));
+                       dump_doc_section($file, $section, xml_escape($contents));
                        $contents = "";
                        $function = "";
                        %constants = ();
@@ -1981,7 +2118,7 @@ sub process_file($) {
                }
                elsif (/$doc_end/)
                {
-                       dump_doc_section($section, xml_escape($contents));
+                       dump_doc_section($file, $section, xml_escape($contents));
                        $contents = "";
                        $function = "";
                        %constants = ();