diff options
Diffstat (limited to 'scripts/kernel-doc')
-rwxr-xr-x | scripts/kernel-doc | 187 |
1 files changed, 121 insertions, 66 deletions
diff --git a/scripts/kernel-doc b/scripts/kernel-doc index 241310e59cd6..9f85012acf0d 100755 --- a/scripts/kernel-doc +++ b/scripts/kernel-doc | |||
@@ -5,7 +5,7 @@ use strict; | |||
5 | ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## | 5 | ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## |
6 | ## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## | 6 | ## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## |
7 | ## Copyright (C) 2001 Simon Huggins ## | 7 | ## Copyright (C) 2001 Simon Huggins ## |
8 | ## Copyright (C) 2005-2009 Randy Dunlap ## | 8 | ## Copyright (C) 2005-2010 Randy Dunlap ## |
9 | ## ## | 9 | ## ## |
10 | ## #define enhancements by Armin Kuster <akuster@mvista.com> ## | 10 | ## #define enhancements by Armin Kuster <akuster@mvista.com> ## |
11 | ## Copyright (c) 2000 MontaVista Software, Inc. ## | 11 | ## Copyright (c) 2000 MontaVista Software, Inc. ## |
@@ -13,8 +13,6 @@ use strict; | |||
13 | ## This software falls under the GNU General Public License. ## | 13 | ## This software falls under the GNU General Public License. ## |
14 | ## Please read the COPYING file for more information ## | 14 | ## Please read the COPYING file for more information ## |
15 | 15 | ||
16 | # w.o. 03-11-2000: added the '-filelist' option. | ||
17 | |||
18 | # 18/01/2001 - Cleanups | 16 | # 18/01/2001 - Cleanups |
19 | # Functions prototyped as foo(void) same as foo() | 17 | # Functions prototyped as foo(void) same as foo() |
20 | # Stop eval'ing where we don't need to. | 18 | # Stop eval'ing where we don't need to. |
@@ -46,12 +44,13 @@ use strict; | |||
46 | # Note: This only supports 'c'. | 44 | # Note: This only supports 'c'. |
47 | 45 | ||
48 | # usage: | 46 | # usage: |
49 | # kernel-doc [ -docbook | -html | -text | -man ] [ -no-doc-sections ] | 47 | # kernel-doc [ -docbook | -html | -text | -man | -list ] [ -no-doc-sections ] |
50 | # [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile | 48 | # [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile |
51 | # or | 49 | # or |
52 | # [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile | 50 | # [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile |
53 | # | 51 | # |
54 | # Set output format using one of -docbook -html -text or -man. Default is man. | 52 | # Set output format using one of -docbook -html -text or -man. Default is man. |
53 | # The -list format is for internal use by docproc. | ||
55 | # | 54 | # |
56 | # -no-doc-sections | 55 | # -no-doc-sections |
57 | # Do not output DOC: sections | 56 | # Do not output DOC: sections |
@@ -156,6 +155,8 @@ use strict; | |||
156 | # '@parameter' - name of a parameter | 155 | # '@parameter' - name of a parameter |
157 | # '%CONST' - name of a constant. | 156 | # '%CONST' - name of a constant. |
158 | 157 | ||
158 | ## init lots of data | ||
159 | |||
159 | my $errors = 0; | 160 | my $errors = 0; |
160 | my $warnings = 0; | 161 | my $warnings = 0; |
161 | my $anon_struct_union = 0; | 162 | my $anon_struct_union = 0; |
@@ -212,21 +213,21 @@ my %highlights_text = ( $type_constant, "\$1", | |||
212 | $type_param, "\$1" ); | 213 | $type_param, "\$1" ); |
213 | my $blankline_text = ""; | 214 | my $blankline_text = ""; |
214 | 215 | ||
215 | 216 | # list mode | |
216 | sub usage { | 217 | my %highlights_list = ( $type_constant, "\$1", |
217 | print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ] [ -no-doc-sections ]\n"; | 218 | $type_func, "\$1", |
218 | print " [ -function funcname [ -function funcname ...] ]\n"; | 219 | $type_struct, "\$1", |
219 | print " [ -nofunction funcname [ -nofunction funcname ...] ]\n"; | 220 | $type_param, "\$1" ); |
220 | print " c source file(s) > outputfile\n"; | 221 | my $blankline_list = ""; |
221 | print " -v : verbose output, more warnings & other info listed\n"; | ||
222 | exit 1; | ||
223 | } | ||
224 | 222 | ||
225 | # read arguments | 223 | # read arguments |
226 | if ($#ARGV == -1) { | 224 | if ($#ARGV == -1) { |
227 | usage(); | 225 | usage(); |
228 | } | 226 | } |
229 | 227 | ||
228 | my $kernelversion; | ||
229 | my $dohighlight = ""; | ||
230 | |||
230 | my $verbose = 0; | 231 | my $verbose = 0; |
231 | my $output_mode = "man"; | 232 | my $output_mode = "man"; |
232 | my $no_doc_sections = 0; | 233 | my $no_doc_sections = 0; |
@@ -239,13 +240,13 @@ my $man_date = ('January', 'February', 'March', 'April', 'May', 'June', | |||
239 | 'November', 'December')[(localtime)[4]] . | 240 | 'November', 'December')[(localtime)[4]] . |
240 | " " . ((localtime)[5]+1900); | 241 | " " . ((localtime)[5]+1900); |
241 | 242 | ||
242 | # Essentially these are globals | 243 | # Essentially these are globals. |
243 | # They probably want to be tidied up, made more localised or something. | 244 | # They probably want to be tidied up, made more localised or something. |
244 | # CAVEAT EMPTOR! Some of the others I localised may not want to be, which | 245 | # CAVEAT EMPTOR! Some of the others I localised may not want to be, which |
245 | # could cause "use of undefined value" or other bugs. | 246 | # could cause "use of undefined value" or other bugs. |
246 | my ($function, %function_table, %parametertypes, $declaration_purpose); | 247 | my ($function, %function_table, %parametertypes, $declaration_purpose); |
247 | my ($type, $declaration_name, $return_type); | 248 | my ($type, $declaration_name, $return_type); |
248 | my ($newsection, $newcontents, $prototype, $filelist, $brcount, %source_map); | 249 | my ($newsection, $newcontents, $prototype, $brcount, %source_map); |
249 | 250 | ||
250 | if (defined($ENV{'KBUILD_VERBOSE'})) { | 251 | if (defined($ENV{'KBUILD_VERBOSE'})) { |
251 | $verbose = "$ENV{'KBUILD_VERBOSE'}"; | 252 | $verbose = "$ENV{'KBUILD_VERBOSE'}"; |
@@ -320,6 +321,10 @@ while ($ARGV[0] =~ m/^-(.*)/) { | |||
320 | $output_mode = "xml"; | 321 | $output_mode = "xml"; |
321 | %highlights = %highlights_xml; | 322 | %highlights = %highlights_xml; |
322 | $blankline = $blankline_xml; | 323 | $blankline = $blankline_xml; |
324 | } elsif ($cmd eq "-list") { | ||
325 | $output_mode = "list"; | ||
326 | %highlights = %highlights_list; | ||
327 | $blankline = $blankline_list; | ||
323 | } elsif ($cmd eq "-gnome") { | 328 | } elsif ($cmd eq "-gnome") { |
324 | $output_mode = "gnome"; | 329 | $output_mode = "gnome"; |
325 | %highlights = %highlights_gnome; | 330 | %highlights = %highlights_gnome; |
@@ -338,13 +343,23 @@ while ($ARGV[0] =~ m/^-(.*)/) { | |||
338 | $verbose = 1; | 343 | $verbose = 1; |
339 | } elsif (($cmd eq "-h") || ($cmd eq "--help")) { | 344 | } elsif (($cmd eq "-h") || ($cmd eq "--help")) { |
340 | usage(); | 345 | usage(); |
341 | } elsif ($cmd eq '-filelist') { | ||
342 | $filelist = shift @ARGV; | ||
343 | } elsif ($cmd eq '-no-doc-sections') { | 346 | } elsif ($cmd eq '-no-doc-sections') { |
344 | $no_doc_sections = 1; | 347 | $no_doc_sections = 1; |
345 | } | 348 | } |
346 | } | 349 | } |
347 | 350 | ||
351 | # continue execution near EOF; | ||
352 | |||
353 | sub usage { | ||
354 | print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man | -list ]\n"; | ||
355 | print " [ -no-doc-sections ]\n"; | ||
356 | print " [ -function funcname [ -function funcname ...] ]\n"; | ||
357 | print " [ -nofunction funcname [ -nofunction funcname ...] ]\n"; | ||
358 | print " c source file(s) > outputfile\n"; | ||
359 | print " -v : verbose output, more warnings & other info listed\n"; | ||
360 | exit 1; | ||
361 | } | ||
362 | |||
348 | # get kernel version from env | 363 | # get kernel version from env |
349 | sub get_kernel_version() { | 364 | sub get_kernel_version() { |
350 | my $version = 'unknown kernel version'; | 365 | my $version = 'unknown kernel version'; |
@@ -354,15 +369,6 @@ sub get_kernel_version() { | |||
354 | } | 369 | } |
355 | return $version; | 370 | return $version; |
356 | } | 371 | } |
357 | my $kernelversion = get_kernel_version(); | ||
358 | |||
359 | # generate a sequence of code that will splice in highlighting information | ||
360 | # using the s// operator. | ||
361 | my $dohighlight = ""; | ||
362 | foreach my $pattern (keys %highlights) { | ||
363 | # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n"; | ||
364 | $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n"; | ||
365 | } | ||
366 | 372 | ||
367 | ## | 373 | ## |
368 | # dumps section contents to arrays/hashes intended for that purpose. | 374 | # dumps section contents to arrays/hashes intended for that purpose. |
@@ -445,7 +451,7 @@ sub output_highlight { | |||
445 | if ($output_mode eq "html" || $output_mode eq "xml") { | 451 | if ($output_mode eq "html" || $output_mode eq "xml") { |
446 | $contents = local_unescape($contents); | 452 | $contents = local_unescape($contents); |
447 | # convert data read & converted thru xml_escape() into &xyz; format: | 453 | # convert data read & converted thru xml_escape() into &xyz; format: |
448 | $contents =~ s/\\\\\\/&/g; | 454 | $contents =~ s/\\\\\\/\&/g; |
449 | } | 455 | } |
450 | # print STDERR "contents b4:$contents\n"; | 456 | # print STDERR "contents b4:$contents\n"; |
451 | eval $dohighlight; | 457 | eval $dohighlight; |
@@ -762,7 +768,11 @@ sub output_struct_xml(%) { | |||
762 | print $args{'type'} . " " . $args{'struct'} . " {\n"; | 768 | print $args{'type'} . " " . $args{'struct'} . " {\n"; |
763 | foreach $parameter (@{$args{'parameterlist'}}) { | 769 | foreach $parameter (@{$args{'parameterlist'}}) { |
764 | if ($parameter =~ /^#/) { | 770 | if ($parameter =~ /^#/) { |
765 | print "$parameter\n"; | 771 | my $prm = $parameter; |
772 | # convert data read & converted thru xml_escape() into &xyz; format: | ||
773 | # This allows us to have #define macros interspersed in a struct. | ||
774 | $prm =~ s/\\\\\\/\&/g; | ||
775 | print "$prm\n"; | ||
766 | next; | 776 | next; |
767 | } | 777 | } |
768 | 778 | ||
@@ -1365,6 +1375,42 @@ sub output_blockhead_text(%) { | |||
1365 | } | 1375 | } |
1366 | } | 1376 | } |
1367 | 1377 | ||
1378 | ## list mode output functions | ||
1379 | |||
1380 | sub output_function_list(%) { | ||
1381 | my %args = %{$_[0]}; | ||
1382 | |||
1383 | print $args{'function'} . "\n"; | ||
1384 | } | ||
1385 | |||
1386 | # output enum in list | ||
1387 | sub output_enum_list(%) { | ||
1388 | my %args = %{$_[0]}; | ||
1389 | print $args{'enum'} . "\n"; | ||
1390 | } | ||
1391 | |||
1392 | # output typedef in list | ||
1393 | sub output_typedef_list(%) { | ||
1394 | my %args = %{$_[0]}; | ||
1395 | print $args{'typedef'} . "\n"; | ||
1396 | } | ||
1397 | |||
1398 | # output struct as list | ||
1399 | sub output_struct_list(%) { | ||
1400 | my %args = %{$_[0]}; | ||
1401 | |||
1402 | print $args{'struct'} . "\n"; | ||
1403 | } | ||
1404 | |||
1405 | sub output_blockhead_list(%) { | ||
1406 | my %args = %{$_[0]}; | ||
1407 | my ($parameter, $section); | ||
1408 | |||
1409 | foreach $section (@{$args{'sectionlist'}}) { | ||
1410 | print "DOC: $section\n"; | ||
1411 | } | ||
1412 | } | ||
1413 | |||
1368 | ## | 1414 | ## |
1369 | # generic output function for all types (function, struct/union, typedef, enum); | 1415 | # generic output function for all types (function, struct/union, typedef, enum); |
1370 | # calls the generated, variable output_ function name based on | 1416 | # calls the generated, variable output_ function name based on |
@@ -1428,6 +1474,8 @@ sub dump_struct($$) { | |||
1428 | $nested =~ s/\/\*.*?\*\///gos; | 1474 | $nested =~ s/\/\*.*?\*\///gos; |
1429 | # strip kmemcheck_bitfield_{begin,end}.*; | 1475 | # strip kmemcheck_bitfield_{begin,end}.*; |
1430 | $members =~ s/kmemcheck_bitfield_.*?;//gos; | 1476 | $members =~ s/kmemcheck_bitfield_.*?;//gos; |
1477 | # strip attributes | ||
1478 | $members =~ s/__aligned\s*\(\d+\)//gos; | ||
1431 | 1479 | ||
1432 | create_parameterlist($members, ';', $file); | 1480 | create_parameterlist($members, ';', $file); |
1433 | check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); | 1481 | check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); |
@@ -1456,6 +1504,8 @@ sub dump_enum($$) { | |||
1456 | my $file = shift; | 1504 | my $file = shift; |
1457 | 1505 | ||
1458 | $x =~ s@/\*.*?\*/@@gos; # strip comments. | 1506 | $x =~ s@/\*.*?\*/@@gos; # strip comments. |
1507 | $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums | ||
1508 | |||
1459 | if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { | 1509 | if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { |
1460 | $declaration_name = $1; | 1510 | $declaration_name = $1; |
1461 | my $members = $2; | 1511 | my $members = $2; |
@@ -1653,6 +1703,8 @@ sub push_parameter($$$) { | |||
1653 | } | 1703 | } |
1654 | } | 1704 | } |
1655 | 1705 | ||
1706 | $param = xml_escape($param); | ||
1707 | |||
1656 | # strip spaces from $param so that it is one continous string | 1708 | # strip spaces from $param so that it is one continous string |
1657 | # on @parameterlist; | 1709 | # on @parameterlist; |
1658 | # this fixes a problem where check_sections() cannot find | 1710 | # this fixes a problem where check_sections() cannot find |
@@ -1679,7 +1731,7 @@ sub check_sections($$$$$$) { | |||
1679 | foreach $px (0 .. $#prms) { | 1731 | foreach $px (0 .. $#prms) { |
1680 | $prm_clean = $prms[$px]; | 1732 | $prm_clean = $prms[$px]; |
1681 | $prm_clean =~ s/\[.*\]//; | 1733 | $prm_clean =~ s/\[.*\]//; |
1682 | $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//; | 1734 | $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; |
1683 | # ignore array size in a parameter string; | 1735 | # ignore array size in a parameter string; |
1684 | # however, the original param string may contain | 1736 | # however, the original param string may contain |
1685 | # spaces, e.g.: addr[6 + 2] | 1737 | # spaces, e.g.: addr[6 + 2] |
@@ -1732,6 +1784,7 @@ sub dump_function($$) { | |||
1732 | $prototype =~ s/^noinline +//; | 1784 | $prototype =~ s/^noinline +//; |
1733 | $prototype =~ s/__devinit +//; | 1785 | $prototype =~ s/__devinit +//; |
1734 | $prototype =~ s/__init +//; | 1786 | $prototype =~ s/__init +//; |
1787 | $prototype =~ s/__init_or_module +//; | ||
1735 | $prototype =~ s/^#\s*define\s+//; #ak added | 1788 | $prototype =~ s/^#\s*define\s+//; #ak added |
1736 | $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; | 1789 | $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; |
1737 | 1790 | ||
@@ -1796,42 +1849,6 @@ sub dump_function($$) { | |||
1796 | }); | 1849 | }); |
1797 | } | 1850 | } |
1798 | 1851 | ||
1799 | sub process_file($); | ||
1800 | |||
1801 | # Read the file that maps relative names to absolute names for | ||
1802 | # separate source and object directories and for shadow trees. | ||
1803 | if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { | ||
1804 | my ($relname, $absname); | ||
1805 | while(<SOURCE_MAP>) { | ||
1806 | chop(); | ||
1807 | ($relname, $absname) = (split())[0..1]; | ||
1808 | $relname =~ s:^/+::; | ||
1809 | $source_map{$relname} = $absname; | ||
1810 | } | ||
1811 | close(SOURCE_MAP); | ||
1812 | } | ||
1813 | |||
1814 | if ($filelist) { | ||
1815 | open(FLIST,"<$filelist") or die "Can't open file list $filelist"; | ||
1816 | while(<FLIST>) { | ||
1817 | chop; | ||
1818 | process_file($_); | ||
1819 | } | ||
1820 | } | ||
1821 | |||
1822 | foreach (@ARGV) { | ||
1823 | chomp; | ||
1824 | process_file($_); | ||
1825 | } | ||
1826 | if ($verbose && $errors) { | ||
1827 | print STDERR "$errors errors\n"; | ||
1828 | } | ||
1829 | if ($verbose && $warnings) { | ||
1830 | print STDERR "$warnings warnings\n"; | ||
1831 | } | ||
1832 | |||
1833 | exit($errors); | ||
1834 | |||
1835 | sub reset_state { | 1852 | sub reset_state { |
1836 | $function = ""; | 1853 | $function = ""; |
1837 | %constants = (); | 1854 | %constants = (); |
@@ -2023,6 +2040,8 @@ sub process_file($) { | |||
2023 | return; | 2040 | return; |
2024 | } | 2041 | } |
2025 | 2042 | ||
2043 | $. = 1; | ||
2044 | |||
2026 | $section_counter = 0; | 2045 | $section_counter = 0; |
2027 | while (<IN>) { | 2046 | while (<IN>) { |
2028 | if ($state == 0) { | 2047 | if ($state == 0) { |
@@ -2113,7 +2132,7 @@ sub process_file($) { | |||
2113 | $section = $newsection; | 2132 | $section = $newsection; |
2114 | } elsif (/$doc_end/) { | 2133 | } elsif (/$doc_end/) { |
2115 | 2134 | ||
2116 | if ($contents ne "") { | 2135 | if (($contents ne "") && ($contents ne "\n")) { |
2117 | dump_section($file, $section, xml_escape($contents)); | 2136 | dump_section($file, $section, xml_escape($contents)); |
2118 | $section = $section_default; | 2137 | $section = $section_default; |
2119 | $contents = ""; | 2138 | $contents = ""; |
@@ -2236,3 +2255,39 @@ sub process_file($) { | |||
2236 | } | 2255 | } |
2237 | } | 2256 | } |
2238 | } | 2257 | } |
2258 | |||
2259 | |||
2260 | $kernelversion = get_kernel_version(); | ||
2261 | |||
2262 | # generate a sequence of code that will splice in highlighting information | ||
2263 | # using the s// operator. | ||
2264 | foreach my $pattern (keys %highlights) { | ||
2265 | # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n"; | ||
2266 | $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n"; | ||
2267 | } | ||
2268 | |||
2269 | # Read the file that maps relative names to absolute names for | ||
2270 | # separate source and object directories and for shadow trees. | ||
2271 | if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { | ||
2272 | my ($relname, $absname); | ||
2273 | while(<SOURCE_MAP>) { | ||
2274 | chop(); | ||
2275 | ($relname, $absname) = (split())[0..1]; | ||
2276 | $relname =~ s:^/+::; | ||
2277 | $source_map{$relname} = $absname; | ||
2278 | } | ||
2279 | close(SOURCE_MAP); | ||
2280 | } | ||
2281 | |||
2282 | foreach (@ARGV) { | ||
2283 | chomp; | ||
2284 | process_file($_); | ||
2285 | } | ||
2286 | if ($verbose && $errors) { | ||
2287 | print STDERR "$errors errors\n"; | ||
2288 | } | ||
2289 | if ($verbose && $warnings) { | ||
2290 | print STDERR "$warnings warnings\n"; | ||
2291 | } | ||
2292 | |||
2293 | exit($errors); | ||