X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=scripts%2Fkernel-doc;h=88e3934a8b8c86f6e5962ac64acb36ab7d0c08dd;hb=6c386e58aadb90fb5d8b5be979e02d74f8be52fe;hp=1d1401807e95809a43e2b72c84ee17d4be2854e8;hpb=c548f08a4f7b89b93c805e0c4024b8302afa7121;p=linux-2.6 diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 1d1401807e..88e3934a8b 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc @@ -5,7 +5,7 @@ use strict; ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## ## Copyright (C) 2000, 1 Tim Waugh ## ## Copyright (C) 2001 Simon Huggins ## -## Copyright (C) 2005-2007 Randy Dunlap ## +## Copyright (C) 2005-2008 Randy Dunlap ## ## ## ## #define enhancements by Armin Kuster ## ## Copyright (c) 2000 MontaVista Software, Inc. ## @@ -46,21 +46,24 @@ use strict; # Note: This only supports 'c'. # usage: -# kernel-doc [ -docbook | -html | -text | -man ] +# kernel-doc [ -docbook | -html | -text | -man ] [ -no-doc-sections ] # [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile # or # [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile # # Set output format using one of -docbook -html -text or -man. Default is man. # +# -no-doc-sections +# Do not output DOC: sections +# # -function funcname -# If set, then only generate documentation for the given function(s). All -# other functions are ignored. +# If set, then only generate documentation for the given function(s) or +# DOC: section titles. All other functions and DOC: sections are ignored. # # -nofunction funcname -# If set, then only generate documentation for the other function(s). -# Cannot be used together with -function -# (yes, that's a bug -- perl hackers can fix it 8)) +# If set, then only generate documentation for the other function(s)/DOC: +# sections. Cannot be used together with -function (yes, that's a bug -- +# perl hackers can fix it 8)) # # c files - list of 'c' files to process # @@ -182,10 +185,10 @@ my $blankline_html = $local_lt . "p" . $local_gt; # was "

" my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1\$2", $type_constant, "\$1", $type_func, "\$1", - $type_struct, "\$1", + $type_struct_xml, "\$1", $type_env, "\$1", $type_param, "\$1" ); -my $blankline_xml = "\n"; +my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; # gnome, docbook format my %highlights_gnome = ( $type_constant, "\$1", @@ -211,10 +214,11 @@ my $blankline_text = ""; sub usage { - print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ]\n"; + print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ] [ -no-doc-sections ]\n"; 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; } @@ -225,6 +229,7 @@ if ($#ARGV==-1) { my $verbose = 0; my $output_mode = "man"; +my $no_doc_sections = 0; my %highlights = %highlights_man; my $blankline = $blankline_man; my $modulename = "Kernel API"; @@ -242,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 @@ -329,12 +338,14 @@ while ($ARGV[0] =~ m/^-(.*)/) { usage(); } elsif ($cmd eq '-filelist') { $filelist = shift @ARGV; + } elsif ($cmd eq '-no-doc-sections') { + $no_doc_sections = 1; } } # get kernel version from env sub get_kernel_version() { - my $version; + my $version = 'unknown kernel version'; if (defined($ENV{'KERNELVERSION'})) { $version = $ENV{'KERNELVERSION'}; @@ -355,6 +366,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", @_; @@ -368,11 +380,39 @@ sub dump_section { $parameterdescs{$name} = $contents; } 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; } } +## +# dump DOC: section after checking that it should go out +# +sub dump_doc_section { + my $file = shift; + my $name = shift; + my $contents = join "\n", @_; + + if ($no_doc_sections) { + return; + } + + if (($function_only == 0) || + ( $function_only == 1 && defined($function_table{$name})) || + ( $function_only == 2 && !defined($function_table{$name}))) + { + dump_section($file, $name, $contents); + output_blockhead({'sectionlist' => \@sectionlist, + 'sections' => \%sections, + 'module' => $modulename, + 'content-only' => ($function_only != 0), }); + } +} + ## # output function # @@ -394,7 +434,7 @@ sub output_highlight { # confess "output_highlight got called with no args?\n"; # } - if ($output_mode eq "html") { + if ($output_mode eq "html" || $output_mode eq "xml") { $contents = local_unescape($contents); # convert data read & converted thru xml_escape() into &xyz; format: $contents =~ s/\\\\\\/&/g; @@ -564,8 +604,8 @@ sub output_function_html(%) { print "


\n"; } -# output intro in html -sub output_intro_html(%) { +# output DOC: block header in html +sub output_blockhead_html(%) { my %args = %{$_[0]}; my ($parameter, $section); my $count; @@ -871,7 +911,7 @@ sub output_typedef_xml(%) { } # output in XML DocBook -sub output_intro_xml(%) { +sub output_blockhead_xml(%) { my %args = %{$_[0]}; my ($parameter, $section); my $count; @@ -882,15 +922,23 @@ sub output_intro_xml(%) { # print out each section $lineprefix=" "; foreach $section (@{$args{'sectionlist'}}) { - print "\n $section\n \n"; + if (!$args{'content-only'}) { + print "\n $section\n"; + } if ($section =~ m/EXAMPLE/i) { print "\n"; + } else { + print "\n"; } output_highlight($args{'sections'}{$section}); if ($section =~ m/EXAMPLE/i) { print "\n"; + } else { + print ""; + } + if (!$args{'content-only'}) { + print "\n\n"; } - print " \n\n"; } print "\n\n"; @@ -1137,7 +1185,7 @@ sub output_typedef_man(%) { } } -sub output_intro_man(%) { +sub output_blockhead_man(%) { my %args = %{$_[0]}; my ($parameter, $section); my $count; @@ -1294,7 +1342,7 @@ sub output_struct_text(%) { output_section_text(@_); } -sub output_intro_text(%) { +sub output_blockhead_text(%) { my %args = %{$_[0]}; my ($parameter, $section); @@ -1325,9 +1373,9 @@ sub output_declaration { ## # generic output function - calls the right one based on current output mode. -sub output_intro { +sub output_blockhead { no strict 'refs'; - my $func = "output_intro_".$output_mode; + my $func = "output_blockhead_".$output_mode; &$func(@_); $section_counter++; } @@ -1474,13 +1522,13 @@ 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/; push_parameter($param, $type, $file); } elsif ($arg) { $arg =~ s/\s*:\s*/:/g; @@ -1508,7 +1556,9 @@ sub create_parameterlist($$$) { push_parameter($2, "$type $1", $file); } elsif ($param =~ m/(.*?):(\d+)/) { - push_parameter($1, "$type:$2", $file) + if ($type ne "") { # skip unnamed bit-fields + push_parameter($1, "$type:$2", $file) + } } else { push_parameter($param, $type, $file); @@ -1586,7 +1636,6 @@ sub dump_function($$) { $prototype =~ s/^static +//; $prototype =~ s/^extern +//; - $prototype =~ s/^fastcall +//; $prototype =~ s/^asmlinkage +//; $prototype =~ s/^inline +//; $prototype =~ s/^__inline__ +//; @@ -1617,7 +1666,7 @@ sub dump_function($$) { $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || - $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || + $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || @@ -1844,6 +1893,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/) { @@ -1870,12 +1926,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; } @@ -1892,10 +1948,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 + + doc_end: + if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { + print STDERR "Warning(${file}:$.): suspicious ending line: $_"; + ++$warnings; + } $prototype = ""; $state = 3; @@ -1906,7 +1967,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 { @@ -1926,9 +1987,7 @@ sub process_file($) { } elsif ($state == 4) { # Documentation block if (/$doc_block/) { - dump_section($section, xml_escape($contents)); - output_intro({'sectionlist' => \@sectionlist, - 'sections' => \%sections }); + dump_doc_section($file, $section, xml_escape($contents)); $contents = ""; $function = ""; %constants = (); @@ -1946,9 +2005,7 @@ sub process_file($) { } elsif (/$doc_end/) { - dump_section($section, xml_escape($contents)); - output_intro({'sectionlist' => \@sectionlist, - 'sections' => \%sections }); + dump_doc_section($file, $section, xml_escape($contents)); $contents = ""; $function = ""; %constants = ();