diff options
Diffstat (limited to 'scripts/kernel-doc')
-rwxr-xr-x | scripts/kernel-doc | 85 |
1 files changed, 59 insertions, 26 deletions
diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 1d1401807e95..ec54f12f57b0 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc | |||
@@ -46,21 +46,24 @@ use strict; | |||
46 | # Note: This only supports 'c'. | 46 | # Note: This only supports 'c'. |
47 | 47 | ||
48 | # usage: | 48 | # usage: |
49 | # kernel-doc [ -docbook | -html | -text | -man ] | 49 | # kernel-doc [ -docbook | -html | -text | -man ] [ -no-doc-sections ] |
50 | # [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile | 50 | # [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile |
51 | # or | 51 | # or |
52 | # [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile | 52 | # [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile |
53 | # | 53 | # |
54 | # Set output format using one of -docbook -html -text or -man. Default is man. | 54 | # Set output format using one of -docbook -html -text or -man. Default is man. |
55 | # | 55 | # |
56 | # -no-doc-sections | ||
57 | # Do not output DOC: sections | ||
58 | # | ||
56 | # -function funcname | 59 | # -function funcname |
57 | # If set, then only generate documentation for the given function(s). All | 60 | # If set, then only generate documentation for the given function(s) or |
58 | # other functions are ignored. | 61 | # DOC: section titles. All other functions and DOC: sections are ignored. |
59 | # | 62 | # |
60 | # -nofunction funcname | 63 | # -nofunction funcname |
61 | # If set, then only generate documentation for the other function(s). | 64 | # If set, then only generate documentation for the other function(s)/DOC: |
62 | # Cannot be used together with -function | 65 | # sections. Cannot be used together with -function (yes, that's a bug -- |
63 | # (yes, that's a bug -- perl hackers can fix it 8)) | 66 | # perl hackers can fix it 8)) |
64 | # | 67 | # |
65 | # c files - list of 'c' files to process | 68 | # c files - list of 'c' files to process |
66 | # | 69 | # |
@@ -182,10 +185,10 @@ my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" | |||
182 | my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>", | 185 | my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>", |
183 | $type_constant, "<constant>\$1</constant>", | 186 | $type_constant, "<constant>\$1</constant>", |
184 | $type_func, "<function>\$1</function>", | 187 | $type_func, "<function>\$1</function>", |
185 | $type_struct, "<structname>\$1</structname>", | 188 | $type_struct_xml, "<structname>\$1</structname>", |
186 | $type_env, "<envar>\$1</envar>", | 189 | $type_env, "<envar>\$1</envar>", |
187 | $type_param, "<parameter>\$1</parameter>" ); | 190 | $type_param, "<parameter>\$1</parameter>" ); |
188 | my $blankline_xml = "</para><para>\n"; | 191 | my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; |
189 | 192 | ||
190 | # gnome, docbook format | 193 | # gnome, docbook format |
191 | my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>", | 194 | my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>", |
@@ -211,7 +214,7 @@ my $blankline_text = ""; | |||
211 | 214 | ||
212 | 215 | ||
213 | sub usage { | 216 | sub usage { |
214 | print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ]\n"; | 217 | print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ] [ -no-doc-sections ]\n"; |
215 | print " [ -function funcname [ -function funcname ...] ]\n"; | 218 | print " [ -function funcname [ -function funcname ...] ]\n"; |
216 | print " [ -nofunction funcname [ -nofunction funcname ...] ]\n"; | 219 | print " [ -nofunction funcname [ -nofunction funcname ...] ]\n"; |
217 | print " c source file(s) > outputfile\n"; | 220 | print " c source file(s) > outputfile\n"; |
@@ -225,6 +228,7 @@ if ($#ARGV==-1) { | |||
225 | 228 | ||
226 | my $verbose = 0; | 229 | my $verbose = 0; |
227 | my $output_mode = "man"; | 230 | my $output_mode = "man"; |
231 | my $no_doc_sections = 0; | ||
228 | my %highlights = %highlights_man; | 232 | my %highlights = %highlights_man; |
229 | my $blankline = $blankline_man; | 233 | my $blankline = $blankline_man; |
230 | my $modulename = "Kernel API"; | 234 | my $modulename = "Kernel API"; |
@@ -329,12 +333,14 @@ while ($ARGV[0] =~ m/^-(.*)/) { | |||
329 | usage(); | 333 | usage(); |
330 | } elsif ($cmd eq '-filelist') { | 334 | } elsif ($cmd eq '-filelist') { |
331 | $filelist = shift @ARGV; | 335 | $filelist = shift @ARGV; |
336 | } elsif ($cmd eq '-no-doc-sections') { | ||
337 | $no_doc_sections = 1; | ||
332 | } | 338 | } |
333 | } | 339 | } |
334 | 340 | ||
335 | # get kernel version from env | 341 | # get kernel version from env |
336 | sub get_kernel_version() { | 342 | sub get_kernel_version() { |
337 | my $version; | 343 | my $version = 'unknown kernel version'; |
338 | 344 | ||
339 | if (defined($ENV{'KERNELVERSION'})) { | 345 | if (defined($ENV{'KERNELVERSION'})) { |
340 | $version = $ENV{'KERNELVERSION'}; | 346 | $version = $ENV{'KERNELVERSION'}; |
@@ -374,6 +380,29 @@ sub dump_section { | |||
374 | } | 380 | } |
375 | 381 | ||
376 | ## | 382 | ## |
383 | # dump DOC: section after checking that it should go out | ||
384 | # | ||
385 | sub dump_doc_section { | ||
386 | my $name = shift; | ||
387 | my $contents = join "\n", @_; | ||
388 | |||
389 | if ($no_doc_sections) { | ||
390 | return; | ||
391 | } | ||
392 | |||
393 | if (($function_only == 0) || | ||
394 | ( $function_only == 1 && defined($function_table{$name})) || | ||
395 | ( $function_only == 2 && !defined($function_table{$name}))) | ||
396 | { | ||
397 | dump_section $name, $contents; | ||
398 | output_blockhead({'sectionlist' => \@sectionlist, | ||
399 | 'sections' => \%sections, | ||
400 | 'module' => $modulename, | ||
401 | 'content-only' => ($function_only != 0), }); | ||
402 | } | ||
403 | } | ||
404 | |||
405 | ## | ||
377 | # output function | 406 | # output function |
378 | # | 407 | # |
379 | # parameterdescs, a hash. | 408 | # parameterdescs, a hash. |
@@ -394,7 +423,7 @@ sub output_highlight { | |||
394 | # confess "output_highlight got called with no args?\n"; | 423 | # confess "output_highlight got called with no args?\n"; |
395 | # } | 424 | # } |
396 | 425 | ||
397 | if ($output_mode eq "html") { | 426 | if ($output_mode eq "html" || $output_mode eq "xml") { |
398 | $contents = local_unescape($contents); | 427 | $contents = local_unescape($contents); |
399 | # convert data read & converted thru xml_escape() into &xyz; format: | 428 | # convert data read & converted thru xml_escape() into &xyz; format: |
400 | $contents =~ s/\\\\\\/&/g; | 429 | $contents =~ s/\\\\\\/&/g; |
@@ -564,8 +593,8 @@ sub output_function_html(%) { | |||
564 | print "<hr>\n"; | 593 | print "<hr>\n"; |
565 | } | 594 | } |
566 | 595 | ||
567 | # output intro in html | 596 | # output DOC: block header in html |
568 | sub output_intro_html(%) { | 597 | sub output_blockhead_html(%) { |
569 | my %args = %{$_[0]}; | 598 | my %args = %{$_[0]}; |
570 | my ($parameter, $section); | 599 | my ($parameter, $section); |
571 | my $count; | 600 | my $count; |
@@ -871,7 +900,7 @@ sub output_typedef_xml(%) { | |||
871 | } | 900 | } |
872 | 901 | ||
873 | # output in XML DocBook | 902 | # output in XML DocBook |
874 | sub output_intro_xml(%) { | 903 | sub output_blockhead_xml(%) { |
875 | my %args = %{$_[0]}; | 904 | my %args = %{$_[0]}; |
876 | my ($parameter, $section); | 905 | my ($parameter, $section); |
877 | my $count; | 906 | my $count; |
@@ -882,15 +911,23 @@ sub output_intro_xml(%) { | |||
882 | # print out each section | 911 | # print out each section |
883 | $lineprefix=" "; | 912 | $lineprefix=" "; |
884 | foreach $section (@{$args{'sectionlist'}}) { | 913 | foreach $section (@{$args{'sectionlist'}}) { |
885 | print "<refsect1>\n <title>$section</title>\n <para>\n"; | 914 | if (!$args{'content-only'}) { |
915 | print "<refsect1>\n <title>$section</title>\n"; | ||
916 | } | ||
886 | if ($section =~ m/EXAMPLE/i) { | 917 | if ($section =~ m/EXAMPLE/i) { |
887 | print "<example><para>\n"; | 918 | print "<example><para>\n"; |
919 | } else { | ||
920 | print "<para>\n"; | ||
888 | } | 921 | } |
889 | output_highlight($args{'sections'}{$section}); | 922 | output_highlight($args{'sections'}{$section}); |
890 | if ($section =~ m/EXAMPLE/i) { | 923 | if ($section =~ m/EXAMPLE/i) { |
891 | print "</para></example>\n"; | 924 | print "</para></example>\n"; |
925 | } else { | ||
926 | print "</para>"; | ||
927 | } | ||
928 | if (!$args{'content-only'}) { | ||
929 | print "\n</refsect1>\n"; | ||
892 | } | 930 | } |
893 | print " </para>\n</refsect1>\n"; | ||
894 | } | 931 | } |
895 | 932 | ||
896 | print "\n\n"; | 933 | print "\n\n"; |
@@ -1137,7 +1174,7 @@ sub output_typedef_man(%) { | |||
1137 | } | 1174 | } |
1138 | } | 1175 | } |
1139 | 1176 | ||
1140 | sub output_intro_man(%) { | 1177 | sub output_blockhead_man(%) { |
1141 | my %args = %{$_[0]}; | 1178 | my %args = %{$_[0]}; |
1142 | my ($parameter, $section); | 1179 | my ($parameter, $section); |
1143 | my $count; | 1180 | my $count; |
@@ -1294,7 +1331,7 @@ sub output_struct_text(%) { | |||
1294 | output_section_text(@_); | 1331 | output_section_text(@_); |
1295 | } | 1332 | } |
1296 | 1333 | ||
1297 | sub output_intro_text(%) { | 1334 | sub output_blockhead_text(%) { |
1298 | my %args = %{$_[0]}; | 1335 | my %args = %{$_[0]}; |
1299 | my ($parameter, $section); | 1336 | my ($parameter, $section); |
1300 | 1337 | ||
@@ -1325,9 +1362,9 @@ sub output_declaration { | |||
1325 | 1362 | ||
1326 | ## | 1363 | ## |
1327 | # generic output function - calls the right one based on current output mode. | 1364 | # generic output function - calls the right one based on current output mode. |
1328 | sub output_intro { | 1365 | sub output_blockhead { |
1329 | no strict 'refs'; | 1366 | no strict 'refs'; |
1330 | my $func = "output_intro_".$output_mode; | 1367 | my $func = "output_blockhead_".$output_mode; |
1331 | &$func(@_); | 1368 | &$func(@_); |
1332 | $section_counter++; | 1369 | $section_counter++; |
1333 | } | 1370 | } |
@@ -1926,9 +1963,7 @@ sub process_file($) { | |||
1926 | } elsif ($state == 4) { | 1963 | } elsif ($state == 4) { |
1927 | # Documentation block | 1964 | # Documentation block |
1928 | if (/$doc_block/) { | 1965 | if (/$doc_block/) { |
1929 | dump_section($section, xml_escape($contents)); | 1966 | dump_doc_section($section, xml_escape($contents)); |
1930 | output_intro({'sectionlist' => \@sectionlist, | ||
1931 | 'sections' => \%sections }); | ||
1932 | $contents = ""; | 1967 | $contents = ""; |
1933 | $function = ""; | 1968 | $function = ""; |
1934 | %constants = (); | 1969 | %constants = (); |
@@ -1946,9 +1981,7 @@ sub process_file($) { | |||
1946 | } | 1981 | } |
1947 | elsif (/$doc_end/) | 1982 | elsif (/$doc_end/) |
1948 | { | 1983 | { |
1949 | dump_section($section, xml_escape($contents)); | 1984 | dump_doc_section($section, xml_escape($contents)); |
1950 | output_intro({'sectionlist' => \@sectionlist, | ||
1951 | 'sections' => \%sections }); | ||
1952 | $contents = ""; | 1985 | $contents = ""; |
1953 | $function = ""; | 1986 | $function = ""; |
1954 | %constants = (); | 1987 | %constants = (); |