1#!/usr/bin/env perl 2 3use warnings; 4use strict; 5 6## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## 7## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## 8## Copyright (C) 2001 Simon Huggins ## 9## Copyright (C) 2005-2012 Randy Dunlap ## 10## Copyright (C) 2012 Dan Luedtke ## 11## ## 12## #define enhancements by Armin Kuster <akuster@mvista.com> ## 13## Copyright (c) 2000 MontaVista Software, Inc. ## 14## ## 15## This software falls under the GNU General Public License. ## 16## Please read the COPYING file for more information ## 17 18# 18/01/2001 - Cleanups 19# Functions prototyped as foo(void) same as foo() 20# Stop eval'ing where we don't need to. 21# -- huggie@earth.li 22 23# 27/06/2001 - Allowed whitespace after initial "/**" and 24# allowed comments before function declarations. 25# -- Christian Kreibich <ck@whoop.org> 26 27# Still to do: 28# - add perldoc documentation 29# - Look more closely at some of the scarier bits :) 30 31# 26/05/2001 - Support for separate source and object trees. 32# Return error code. 33# Keith Owens <kaos@ocs.com.au> 34 35# 23/09/2001 - Added support for typedefs, structs, enums and unions 36# Support for Context section; can be terminated using empty line 37# Small fixes (like spaces vs. \s in regex) 38# -- Tim Jansen <tim@tjansen.de> 39 40# 25/07/2012 - Added support for HTML5 41# -- Dan Luedtke <mail@danrl.de> 42 43sub usage { 44 my $message = <<"EOF"; 45Usage: $0 [OPTION ...] FILE ... 46 47Read C language source or header FILEs, extract embedded documentation comments, 48and print formatted documentation to standard output. 49 50The documentation comments are identified by "/**" opening comment mark. See 51Documentation/doc-guide/kernel-doc.rst for the documentation comment syntax. 52 53Output format selection (mutually exclusive): 54 -man Output troff manual page format. This is the default. 55 -rst Output reStructuredText format. 56 -none Do not output documentation, only warnings. 57 58Output selection (mutually exclusive): 59 -export Only output documentation for symbols that have been 60 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 61 in any input FILE or -export-file FILE. 62 -internal Only output documentation for symbols that have NOT been 63 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 64 in any input FILE or -export-file FILE. 65 -function NAME Only output documentation for the given function(s) 66 or DOC: section title(s). All other functions and DOC: 67 sections are ignored. May be specified multiple times. 68 -nofunction NAME Do NOT output documentation for the given function(s); 69 only output documentation for the other functions and 70 DOC: sections. May be specified multiple times. 71 72Output selection modifiers: 73 -no-doc-sections Do not output DOC: sections. 74 -enable-lineno Enable output of #define LINENO lines. Only works with 75 reStructuredText format. 76 -export-file FILE Specify an additional FILE in which to look for 77 EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with 78 -export or -internal. May be specified multiple times. 79 80Other parameters: 81 -v Verbose output, more warnings and other information. 82 -h Print this help. 83 84EOF 85 print $message; 86 exit 1; 87} 88 89# 90# format of comments. 91# In the following table, (...)? signifies optional structure. 92# (...)* signifies 0 or more structure elements 93# /** 94# * function_name(:)? (- short description)? 95# (* @parameterx: (description of parameter x)?)* 96# (* a blank line)? 97# * (Description:)? (Description of function)? 98# * (section header: (section description)? )* 99# (*)?*/ 100# 101# So .. the trivial example would be: 102# 103# /** 104# * my_function 105# */ 106# 107# If the Description: header tag is omitted, then there must be a blank line 108# after the last parameter specification. 109# e.g. 110# /** 111# * my_function - does my stuff 112# * @my_arg: its mine damnit 113# * 114# * Does my stuff explained. 115# */ 116# 117# or, could also use: 118# /** 119# * my_function - does my stuff 120# * @my_arg: its mine damnit 121# * Description: Does my stuff explained. 122# */ 123# etc. 124# 125# Besides functions you can also write documentation for structs, unions, 126# enums and typedefs. Instead of the function name you must write the name 127# of the declaration; the struct/union/enum/typedef must always precede 128# the name. Nesting of declarations is not supported. 129# Use the argument mechanism to document members or constants. 130# e.g. 131# /** 132# * struct my_struct - short description 133# * @a: first member 134# * @b: second member 135# * 136# * Longer description 137# */ 138# struct my_struct { 139# int a; 140# int b; 141# /* private: */ 142# int c; 143# }; 144# 145# All descriptions can be multiline, except the short function description. 146# 147# For really longs structs, you can also describe arguments inside the 148# body of the struct. 149# eg. 150# /** 151# * struct my_struct - short description 152# * @a: first member 153# * @b: second member 154# * 155# * Longer description 156# */ 157# struct my_struct { 158# int a; 159# int b; 160# /** 161# * @c: This is longer description of C 162# * 163# * You can use paragraphs to describe arguments 164# * using this method. 165# */ 166# int c; 167# }; 168# 169# This should be use only for struct/enum members. 170# 171# You can also add additional sections. When documenting kernel functions you 172# should document the "Context:" of the function, e.g. whether the functions 173# can be called form interrupts. Unlike other sections you can end it with an 174# empty line. 175# A non-void function should have a "Return:" section describing the return 176# value(s). 177# Example-sections should contain the string EXAMPLE so that they are marked 178# appropriately in DocBook. 179# 180# Example: 181# /** 182# * user_function - function that can only be called in user context 183# * @a: some argument 184# * Context: !in_interrupt() 185# * 186# * Some description 187# * Example: 188# * user_function(22); 189# */ 190# ... 191# 192# 193# All descriptive text is further processed, scanning for the following special 194# patterns, which are highlighted appropriately. 195# 196# 'funcname()' - function 197# '$ENVVAR' - environmental variable 198# '&struct_name' - name of a structure (up to two words including 'struct') 199# '&struct_name.member' - name of a structure member 200# '@parameter' - name of a parameter 201# '%CONST' - name of a constant. 202# '``LITERAL``' - literal string without any spaces on it. 203 204## init lots of data 205 206my $errors = 0; 207my $warnings = 0; 208my $anon_struct_union = 0; 209 210# match expressions used to find embedded type information 211my $type_constant = '\b``([^\`]+)``\b'; 212my $type_constant2 = '\%([-_\w]+)'; 213my $type_func = '(\w+)\(\)'; 214my $type_param = '\@(\w*(\.\w+)*(\.\.\.)?)'; 215my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params 216my $type_env = '(\$\w+)'; 217my $type_enum = '\&(enum\s*([_\w]+))'; 218my $type_struct = '\&(struct\s*([_\w]+))'; 219my $type_typedef = '\&(typedef\s*([_\w]+))'; 220my $type_union = '\&(union\s*([_\w]+))'; 221my $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; 222my $type_fallback = '\&([_\w]+)'; 223my $type_member_func = $type_member . '\(\)'; 224 225# Output conversion substitutions. 226# One for each output format 227 228# these are pretty rough 229my @highlights_man = ( 230 [$type_constant, "\$1"], 231 [$type_constant2, "\$1"], 232 [$type_func, "\\\\fB\$1\\\\fP"], 233 [$type_enum, "\\\\fI\$1\\\\fP"], 234 [$type_struct, "\\\\fI\$1\\\\fP"], 235 [$type_typedef, "\\\\fI\$1\\\\fP"], 236 [$type_union, "\\\\fI\$1\\\\fP"], 237 [$type_param, "\\\\fI\$1\\\\fP"], 238 [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], 239 [$type_fallback, "\\\\fI\$1\\\\fP"] 240 ); 241my $blankline_man = ""; 242 243# rst-mode 244my @highlights_rst = ( 245 [$type_constant, "``\$1``"], 246 [$type_constant2, "``\$1``"], 247 # Note: need to escape () to avoid func matching later 248 [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], 249 [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], 250 [$type_fp_param, "**\$1\\\\(\\\\)**"], 251 [$type_func, "\\:c\\:func\\:`\$1()`"], 252 [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], 253 [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], 254 [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], 255 [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], 256 # in rst this can refer to any type 257 [$type_fallback, "\\:c\\:type\\:`\$1`"], 258 [$type_param, "**\$1**"] 259 ); 260my $blankline_rst = "\n"; 261 262# read arguments 263if ($#ARGV == -1) { 264 usage(); 265} 266 267my $kernelversion; 268my $dohighlight = ""; 269 270my $verbose = 0; 271my $output_mode = "rst"; 272my $output_preformatted = 0; 273my $no_doc_sections = 0; 274my $enable_lineno = 0; 275my @highlights = @highlights_rst; 276my $blankline = $blankline_rst; 277my $modulename = "Kernel API"; 278 279use constant { 280 OUTPUT_ALL => 0, # output all symbols and doc sections 281 OUTPUT_INCLUDE => 1, # output only specified symbols 282 OUTPUT_EXCLUDE => 2, # output everything except specified symbols 283 OUTPUT_EXPORTED => 3, # output exported symbols 284 OUTPUT_INTERNAL => 4, # output non-exported symbols 285}; 286my $output_selection = OUTPUT_ALL; 287my $show_not_found = 0; 288 289my @export_file_list; 290 291my @build_time; 292if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 293 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 294 @build_time = gmtime($seconds); 295} else { 296 @build_time = localtime; 297} 298 299my $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 300 'July', 'August', 'September', 'October', 301 'November', 'December')[$build_time[4]] . 302 " " . ($build_time[5]+1900); 303 304# Essentially these are globals. 305# They probably want to be tidied up, made more localised or something. 306# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 307# could cause "use of undefined value" or other bugs. 308my ($function, %function_table, %parametertypes, $declaration_purpose); 309my $declaration_start_line; 310my ($type, $declaration_name, $return_type); 311my ($newsection, $newcontents, $prototype, $brcount, %source_map); 312 313if (defined($ENV{'KBUILD_VERBOSE'})) { 314 $verbose = "$ENV{'KBUILD_VERBOSE'}"; 315} 316 317# Generated docbook code is inserted in a template at a point where 318# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 319# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 320# We keep track of number of generated entries and generate a dummy 321# if needs be to ensure the expanded template can be postprocessed 322# into html. 323my $section_counter = 0; 324 325my $lineprefix=""; 326 327# Parser states 328use constant { 329 STATE_NORMAL => 0, # normal code 330 STATE_NAME => 1, # looking for function name 331 STATE_FIELD => 2, # scanning field start 332 STATE_PROTO => 3, # scanning prototype 333 STATE_DOCBLOCK => 4, # documentation block 334 STATE_INLINE => 5, # gathering documentation outside main block 335}; 336my $state; 337my $in_doc_sect; 338 339# Inline documentation state 340use constant { 341 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 342 STATE_INLINE_NAME => 1, # looking for member name (@foo:) 343 STATE_INLINE_TEXT => 2, # looking for member documentation 344 STATE_INLINE_END => 3, # done 345 STATE_INLINE_ERROR => 4, # error - Comment without header was found. 346 # Spit a warning as it's not 347 # proper kernel-doc and ignore the rest. 348}; 349my $inline_doc_state; 350 351#declaration types: can be 352# 'function', 'struct', 'union', 'enum', 'typedef' 353my $decl_type; 354 355my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 356my $doc_end = '\*/'; 357my $doc_com = '\s*\*\s*'; 358my $doc_com_body = '\s*\* ?'; 359my $doc_decl = $doc_com . '(\w+)'; 360# @params and a strictly limited set of supported section names 361my $doc_sect = $doc_com . 362 '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)'; 363my $doc_content = $doc_com_body . '(.*)'; 364my $doc_block = $doc_com . 'DOC:\s*(.*)?'; 365my $doc_inline_start = '^\s*/\*\*\s*$'; 366my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)'; 367my $doc_inline_end = '^\s*\*/\s*$'; 368my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; 369my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 370 371my %parameterdescs; 372my %parameterdesc_start_lines; 373my @parameterlist; 374my %sections; 375my @sectionlist; 376my %section_start_lines; 377my $sectcheck; 378my $struct_actual; 379 380my $contents = ""; 381my $new_start_line = 0; 382 383# the canonical section names. see also $doc_sect above. 384my $section_default = "Description"; # default section 385my $section_intro = "Introduction"; 386my $section = $section_default; 387my $section_context = "Context"; 388my $section_return = "Return"; 389 390my $undescribed = "-- undescribed --"; 391 392reset_state(); 393 394while ($ARGV[0] =~ m/^--?(.*)/) { 395 my $cmd = $1; 396 shift @ARGV; 397 if ($cmd eq "man") { 398 $output_mode = "man"; 399 @highlights = @highlights_man; 400 $blankline = $blankline_man; 401 } elsif ($cmd eq "rst") { 402 $output_mode = "rst"; 403 @highlights = @highlights_rst; 404 $blankline = $blankline_rst; 405 } elsif ($cmd eq "none") { 406 $output_mode = "none"; 407 } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document 408 $modulename = shift @ARGV; 409 } elsif ($cmd eq "function") { # to only output specific functions 410 $output_selection = OUTPUT_INCLUDE; 411 $function = shift @ARGV; 412 $function_table{$function} = 1; 413 } elsif ($cmd eq "nofunction") { # output all except specific functions 414 $output_selection = OUTPUT_EXCLUDE; 415 $function = shift @ARGV; 416 $function_table{$function} = 1; 417 } elsif ($cmd eq "export") { # only exported symbols 418 $output_selection = OUTPUT_EXPORTED; 419 %function_table = (); 420 } elsif ($cmd eq "internal") { # only non-exported symbols 421 $output_selection = OUTPUT_INTERNAL; 422 %function_table = (); 423 } elsif ($cmd eq "export-file") { 424 my $file = shift @ARGV; 425 push(@export_file_list, $file); 426 } elsif ($cmd eq "v") { 427 $verbose = 1; 428 } elsif (($cmd eq "h") || ($cmd eq "help")) { 429 usage(); 430 } elsif ($cmd eq 'no-doc-sections') { 431 $no_doc_sections = 1; 432 } elsif ($cmd eq 'enable-lineno') { 433 $enable_lineno = 1; 434 } elsif ($cmd eq 'show-not-found') { 435 $show_not_found = 1; 436 } else { 437 # Unknown argument 438 usage(); 439 } 440} 441 442# continue execution near EOF; 443 444# get kernel version from env 445sub get_kernel_version() { 446 my $version = 'unknown kernel version'; 447 448 if (defined($ENV{'KERNELVERSION'})) { 449 $version = $ENV{'KERNELVERSION'}; 450 } 451 return $version; 452} 453 454# 455sub print_lineno { 456 my $lineno = shift; 457 if ($enable_lineno && defined($lineno)) { 458 print "#define LINENO " . $lineno . "\n"; 459 } 460} 461## 462# dumps section contents to arrays/hashes intended for that purpose. 463# 464sub dump_section { 465 my $file = shift; 466 my $name = shift; 467 my $contents = join "\n", @_; 468 469 if ($name =~ m/$type_param/) { 470 $name = $1; 471 $parameterdescs{$name} = $contents; 472 $sectcheck = $sectcheck . $name . " "; 473 $parameterdesc_start_lines{$name} = $new_start_line; 474 $new_start_line = 0; 475 } elsif ($name eq "@\.\.\.") { 476 $name = "..."; 477 $parameterdescs{$name} = $contents; 478 $sectcheck = $sectcheck . $name . " "; 479 $parameterdesc_start_lines{$name} = $new_start_line; 480 $new_start_line = 0; 481 } else { 482 if (defined($sections{$name}) && ($sections{$name} ne "")) { 483 # Only warn on user specified duplicate section names. 484 if ($name ne $section_default) { 485 print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; 486 ++$warnings; 487 } 488 $sections{$name} .= $contents; 489 } else { 490 $sections{$name} = $contents; 491 push @sectionlist, $name; 492 $section_start_lines{$name} = $new_start_line; 493 $new_start_line = 0; 494 } 495 } 496} 497 498## 499# dump DOC: section after checking that it should go out 500# 501sub dump_doc_section { 502 my $file = shift; 503 my $name = shift; 504 my $contents = join "\n", @_; 505 506 if ($no_doc_sections) { 507 return; 508 } 509 510 if (($output_selection == OUTPUT_ALL) || 511 ($output_selection == OUTPUT_INCLUDE && 512 defined($function_table{$name})) || 513 ($output_selection == OUTPUT_EXCLUDE && 514 !defined($function_table{$name}))) 515 { 516 dump_section($file, $name, $contents); 517 output_blockhead({'sectionlist' => \@sectionlist, 518 'sections' => \%sections, 519 'module' => $modulename, 520 'content-only' => ($output_selection != OUTPUT_ALL), }); 521 } 522} 523 524## 525# output function 526# 527# parameterdescs, a hash. 528# function => "function name" 529# parameterlist => @list of parameters 530# parameterdescs => %parameter descriptions 531# sectionlist => @list of sections 532# sections => %section descriptions 533# 534 535sub output_highlight { 536 my $contents = join "\n",@_; 537 my $line; 538 539# DEBUG 540# if (!defined $contents) { 541# use Carp; 542# confess "output_highlight got called with no args?\n"; 543# } 544 545# print STDERR "contents b4:$contents\n"; 546 eval $dohighlight; 547 die $@ if $@; 548# print STDERR "contents af:$contents\n"; 549 550 foreach $line (split "\n", $contents) { 551 if (! $output_preformatted) { 552 $line =~ s/^\s*//; 553 } 554 if ($line eq ""){ 555 if (! $output_preformatted) { 556 print $lineprefix, $blankline; 557 } 558 } else { 559 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 560 print "\\&$line"; 561 } else { 562 print $lineprefix, $line; 563 } 564 } 565 print "\n"; 566 } 567} 568 569## 570# output function in man 571sub output_function_man(%) { 572 my %args = %{$_[0]}; 573 my ($parameter, $section); 574 my $count; 575 576 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 577 578 print ".SH NAME\n"; 579 print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 580 581 print ".SH SYNOPSIS\n"; 582 if ($args{'functiontype'} ne "") { 583 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 584 } else { 585 print ".B \"" . $args{'function'} . "\n"; 586 } 587 $count = 0; 588 my $parenth = "("; 589 my $post = ","; 590 foreach my $parameter (@{$args{'parameterlist'}}) { 591 if ($count == $#{$args{'parameterlist'}}) { 592 $post = ");"; 593 } 594 $type = $args{'parametertypes'}{$parameter}; 595 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 596 # pointer-to-function 597 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 598 } else { 599 $type =~ s/([^\*])$/$1 /; 600 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 601 } 602 $count++; 603 $parenth = ""; 604 } 605 606 print ".SH ARGUMENTS\n"; 607 foreach $parameter (@{$args{'parameterlist'}}) { 608 my $parameter_name = $parameter; 609 $parameter_name =~ s/\[.*//; 610 611 print ".IP \"" . $parameter . "\" 12\n"; 612 output_highlight($args{'parameterdescs'}{$parameter_name}); 613 } 614 foreach $section (@{$args{'sectionlist'}}) { 615 print ".SH \"", uc $section, "\"\n"; 616 output_highlight($args{'sections'}{$section}); 617 } 618} 619 620## 621# output enum in man 622sub output_enum_man(%) { 623 my %args = %{$_[0]}; 624 my ($parameter, $section); 625 my $count; 626 627 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 628 629 print ".SH NAME\n"; 630 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 631 632 print ".SH SYNOPSIS\n"; 633 print "enum " . $args{'enum'} . " {\n"; 634 $count = 0; 635 foreach my $parameter (@{$args{'parameterlist'}}) { 636 print ".br\n.BI \" $parameter\"\n"; 637 if ($count == $#{$args{'parameterlist'}}) { 638 print "\n};\n"; 639 last; 640 } 641 else { 642 print ", \n.br\n"; 643 } 644 $count++; 645 } 646 647 print ".SH Constants\n"; 648 foreach $parameter (@{$args{'parameterlist'}}) { 649 my $parameter_name = $parameter; 650 $parameter_name =~ s/\[.*//; 651 652 print ".IP \"" . $parameter . "\" 12\n"; 653 output_highlight($args{'parameterdescs'}{$parameter_name}); 654 } 655 foreach $section (@{$args{'sectionlist'}}) { 656 print ".SH \"$section\"\n"; 657 output_highlight($args{'sections'}{$section}); 658 } 659} 660 661## 662# output struct in man 663sub output_struct_man(%) { 664 my %args = %{$_[0]}; 665 my ($parameter, $section); 666 667 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 668 669 print ".SH NAME\n"; 670 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 671 672 my $declaration = $args{'definition'}; 673 $declaration =~ s/\t/ /g; 674 $declaration =~ s/\n/"\n.br\n.BI \"/g; 675 print ".SH SYNOPSIS\n"; 676 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 677 print ".BI \"$declaration\n};\n.br\n\n"; 678 679 print ".SH Members\n"; 680 foreach $parameter (@{$args{'parameterlist'}}) { 681 ($parameter =~ /^#/) && next; 682 683 my $parameter_name = $parameter; 684 $parameter_name =~ s/\[.*//; 685 686 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 687 print ".IP \"" . $parameter . "\" 12\n"; 688 output_highlight($args{'parameterdescs'}{$parameter_name}); 689 } 690 foreach $section (@{$args{'sectionlist'}}) { 691 print ".SH \"$section\"\n"; 692 output_highlight($args{'sections'}{$section}); 693 } 694} 695 696## 697# output typedef in man 698sub output_typedef_man(%) { 699 my %args = %{$_[0]}; 700 my ($parameter, $section); 701 702 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 703 704 print ".SH NAME\n"; 705 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 706 707 foreach $section (@{$args{'sectionlist'}}) { 708 print ".SH \"$section\"\n"; 709 output_highlight($args{'sections'}{$section}); 710 } 711} 712 713sub output_blockhead_man(%) { 714 my %args = %{$_[0]}; 715 my ($parameter, $section); 716 my $count; 717 718 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 719 720 foreach $section (@{$args{'sectionlist'}}) { 721 print ".SH \"$section\"\n"; 722 output_highlight($args{'sections'}{$section}); 723 } 724} 725 726## 727# output in restructured text 728# 729 730# 731# This could use some work; it's used to output the DOC: sections, and 732# starts by putting out the name of the doc section itself, but that tends 733# to duplicate a header already in the template file. 734# 735sub output_blockhead_rst(%) { 736 my %args = %{$_[0]}; 737 my ($parameter, $section); 738 739 foreach $section (@{$args{'sectionlist'}}) { 740 if ($output_selection != OUTPUT_INCLUDE) { 741 print "**$section**\n\n"; 742 } 743 print_lineno($section_start_lines{$section}); 744 output_highlight_rst($args{'sections'}{$section}); 745 print "\n"; 746 } 747} 748 749sub output_highlight_rst { 750 my $contents = join "\n",@_; 751 my $line; 752 753 eval $dohighlight; 754 die $@ if $@; 755 756 foreach $line (split "\n", $contents) { 757 print $lineprefix . $line . "\n"; 758 } 759} 760 761sub output_function_rst(%) { 762 my %args = %{$_[0]}; 763 my ($parameter, $section); 764 my $oldprefix = $lineprefix; 765 my $start = ""; 766 767 if ($args{'typedef'}) { 768 print ".. c:type:: ". $args{'function'} . "\n\n"; 769 print_lineno($declaration_start_line); 770 print " **Typedef**: "; 771 $lineprefix = ""; 772 output_highlight_rst($args{'purpose'}); 773 $start = "\n\n**Syntax**\n\n ``"; 774 } else { 775 print ".. c:function:: "; 776 } 777 if ($args{'functiontype'} ne "") { 778 $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; 779 } else { 780 $start .= $args{'function'} . " ("; 781 } 782 print $start; 783 784 my $count = 0; 785 foreach my $parameter (@{$args{'parameterlist'}}) { 786 if ($count ne 0) { 787 print ", "; 788 } 789 $count++; 790 $type = $args{'parametertypes'}{$parameter}; 791 792 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 793 # pointer-to-function 794 print $1 . $parameter . ") (" . $2; 795 } else { 796 print $type . " " . $parameter; 797 } 798 } 799 if ($args{'typedef'}) { 800 print ");``\n\n"; 801 } else { 802 print ")\n\n"; 803 print_lineno($declaration_start_line); 804 $lineprefix = " "; 805 output_highlight_rst($args{'purpose'}); 806 print "\n"; 807 } 808 809 print "**Parameters**\n\n"; 810 $lineprefix = " "; 811 foreach $parameter (@{$args{'parameterlist'}}) { 812 my $parameter_name = $parameter; 813 $parameter_name =~ s/\[.*//; 814 $type = $args{'parametertypes'}{$parameter}; 815 816 if ($type ne "") { 817 print "``$type $parameter``\n"; 818 } else { 819 print "``$parameter``\n"; 820 } 821 822 print_lineno($parameterdesc_start_lines{$parameter_name}); 823 824 if (defined($args{'parameterdescs'}{$parameter_name}) && 825 $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 826 output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 827 } else { 828 print " *undescribed*\n"; 829 } 830 print "\n"; 831 } 832 833 $lineprefix = $oldprefix; 834 output_section_rst(@_); 835} 836 837sub output_section_rst(%) { 838 my %args = %{$_[0]}; 839 my $section; 840 my $oldprefix = $lineprefix; 841 $lineprefix = ""; 842 843 foreach $section (@{$args{'sectionlist'}}) { 844 print "**$section**\n\n"; 845 print_lineno($section_start_lines{$section}); 846 output_highlight_rst($args{'sections'}{$section}); 847 print "\n"; 848 } 849 print "\n"; 850 $lineprefix = $oldprefix; 851} 852 853sub output_enum_rst(%) { 854 my %args = %{$_[0]}; 855 my ($parameter); 856 my $oldprefix = $lineprefix; 857 my $count; 858 my $name = "enum " . $args{'enum'}; 859 860 print "\n\n.. c:type:: " . $name . "\n\n"; 861 print_lineno($declaration_start_line); 862 $lineprefix = " "; 863 output_highlight_rst($args{'purpose'}); 864 print "\n"; 865 866 print "**Constants**\n\n"; 867 $lineprefix = " "; 868 foreach $parameter (@{$args{'parameterlist'}}) { 869 print "``$parameter``\n"; 870 if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 871 output_highlight_rst($args{'parameterdescs'}{$parameter}); 872 } else { 873 print " *undescribed*\n"; 874 } 875 print "\n"; 876 } 877 878 $lineprefix = $oldprefix; 879 output_section_rst(@_); 880} 881 882sub output_typedef_rst(%) { 883 my %args = %{$_[0]}; 884 my ($parameter); 885 my $oldprefix = $lineprefix; 886 my $name = "typedef " . $args{'typedef'}; 887 888 print "\n\n.. c:type:: " . $name . "\n\n"; 889 print_lineno($declaration_start_line); 890 $lineprefix = " "; 891 output_highlight_rst($args{'purpose'}); 892 print "\n"; 893 894 $lineprefix = $oldprefix; 895 output_section_rst(@_); 896} 897 898sub output_struct_rst(%) { 899 my %args = %{$_[0]}; 900 my ($parameter); 901 my $oldprefix = $lineprefix; 902 my $name = $args{'type'} . " " . $args{'struct'}; 903 904 print "\n\n.. c:type:: " . $name . "\n\n"; 905 print_lineno($declaration_start_line); 906 $lineprefix = " "; 907 output_highlight_rst($args{'purpose'}); 908 print "\n"; 909 910 print "**Definition**\n\n"; 911 print "::\n\n"; 912 my $declaration = $args{'definition'}; 913 $declaration =~ s/\t/ /g; 914 print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n"; 915 916 print "**Members**\n\n"; 917 $lineprefix = " "; 918 foreach $parameter (@{$args{'parameterlist'}}) { 919 ($parameter =~ /^#/) && next; 920 921 my $parameter_name = $parameter; 922 $parameter_name =~ s/\[.*//; 923 924 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 925 $type = $args{'parametertypes'}{$parameter}; 926 print_lineno($parameterdesc_start_lines{$parameter_name}); 927 print "``" . $parameter . "``\n"; 928 output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 929 print "\n"; 930 } 931 print "\n"; 932 933 $lineprefix = $oldprefix; 934 output_section_rst(@_); 935} 936 937## none mode output functions 938 939sub output_function_none(%) { 940} 941 942sub output_enum_none(%) { 943} 944 945sub output_typedef_none(%) { 946} 947 948sub output_struct_none(%) { 949} 950 951sub output_blockhead_none(%) { 952} 953 954## 955# generic output function for all types (function, struct/union, typedef, enum); 956# calls the generated, variable output_ function name based on 957# functype and output_mode 958sub output_declaration { 959 no strict 'refs'; 960 my $name = shift; 961 my $functype = shift; 962 my $func = "output_${functype}_$output_mode"; 963 if (($output_selection == OUTPUT_ALL) || 964 (($output_selection == OUTPUT_INCLUDE || 965 $output_selection == OUTPUT_EXPORTED) && 966 defined($function_table{$name})) || 967 (($output_selection == OUTPUT_EXCLUDE || 968 $output_selection == OUTPUT_INTERNAL) && 969 !($functype eq "function" && defined($function_table{$name})))) 970 { 971 &$func(@_); 972 $section_counter++; 973 } 974} 975 976## 977# generic output function - calls the right one based on current output mode. 978sub output_blockhead { 979 no strict 'refs'; 980 my $func = "output_blockhead_" . $output_mode; 981 &$func(@_); 982 $section_counter++; 983} 984 985## 986# takes a declaration (struct, union, enum, typedef) and 987# invokes the right handler. NOT called for functions. 988sub dump_declaration($$) { 989 no strict 'refs'; 990 my ($prototype, $file) = @_; 991 my $func = "dump_" . $decl_type; 992 &$func(@_); 993} 994 995sub dump_union($$) { 996 dump_struct(@_); 997} 998 999sub dump_struct($$) { 1000 my $x = shift; 1001 my $file = shift; 1002 1003 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 1004 my $decl_type = $1; 1005 $declaration_name = $2; 1006 my $members = $3; 1007 1008 # ignore members marked private: 1009 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 1010 $members =~ s/\/\*\s*private:.*//gosi; 1011 # strip comments: 1012 $members =~ s/\/\*.*?\*\///gos; 1013 # strip attributes 1014 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 1015 $members =~ s/__aligned\s*\([^;]*\)//gos; 1016 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; 1017 # replace DECLARE_BITMAP 1018 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 1019 # replace DECLARE_HASHTABLE 1020 $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos; 1021 # replace DECLARE_KFIFO 1022 $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; 1023 # replace DECLARE_KFIFO_PTR 1024 $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; 1025 1026 my $declaration = $members; 1027 1028 # Split nested struct/union elements as newer ones 1029 while ($members =~ m/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/) { 1030 my $newmember; 1031 my $maintype = $1; 1032 my $ids = $4; 1033 my $content = $3; 1034 foreach my $id(split /,/, $ids) { 1035 $newmember .= "$maintype $id; "; 1036 1037 $id =~ s/[:\[].*//; 1038 $id =~ s/^\s*\**(\S+)\s*/$1/; 1039 foreach my $arg (split /;/, $content) { 1040 next if ($arg =~ m/^\s*$/); 1041 if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) { 1042 # pointer-to-function 1043 my $type = $1; 1044 my $name = $2; 1045 my $extra = $3; 1046 next if (!$name); 1047 if ($id =~ m/^\s*$/) { 1048 # anonymous struct/union 1049 $newmember .= "$type$name$extra; "; 1050 } else { 1051 $newmember .= "$type$id.$name$extra; "; 1052 } 1053 } else { 1054 my $type; 1055 my $names; 1056 $arg =~ s/^\s+//; 1057 $arg =~ s/\s+$//; 1058 # Handle bitmaps 1059 $arg =~ s/:\s*\d+\s*//g; 1060 # Handle arrays 1061 $arg =~ s/\[\S+\]//g; 1062 # The type may have multiple words, 1063 # and multiple IDs can be defined, like: 1064 # const struct foo, *bar, foobar 1065 # So, we remove spaces when parsing the 1066 # names, in order to match just names 1067 # and commas for the names 1068 $arg =~ s/\s*,\s*/,/g; 1069 if ($arg =~ m/(.*)\s+([\S+,]+)/) { 1070 $type = $1; 1071 $names = $2; 1072 } else { 1073 $newmember .= "$arg; "; 1074 next; 1075 } 1076 foreach my $name (split /,/, $names) { 1077 $name =~ s/^\s*\**(\S+)\s*/$1/; 1078 next if (($name =~ m/^\s*$/)); 1079 if ($id =~ m/^\s*$/) { 1080 # anonymous struct/union 1081 $newmember .= "$type $name; "; 1082 } else { 1083 $newmember .= "$type $id.$name; "; 1084 } 1085 } 1086 } 1087 } 1088 } 1089 $members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)}([^\{\}\;]*)\;/$newmember/; 1090 } 1091 1092 # Ignore other nested elements, like enums 1093 $members =~ s/({[^\{\}]*})//g; 1094 1095 create_parameterlist($members, ';', $file, $declaration_name); 1096 check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual); 1097 1098 # Adjust declaration for better display 1099 $declaration =~ s/([{;])/$1\n/g; 1100 $declaration =~ s/}\s+;/};/g; 1101 # Better handle inlined enums 1102 do {} while ($declaration =~ s/(enum\s+{[^}]+),([^\n])/$1,\n$2/); 1103 1104 my @def_args = split /\n/, $declaration; 1105 my $level = 1; 1106 $declaration = ""; 1107 foreach my $clause (@def_args) { 1108 $clause =~ s/^\s+//; 1109 $clause =~ s/\s+$//; 1110 $clause =~ s/\s+/ /; 1111 next if (!$clause); 1112 $level-- if ($clause =~ m/(})/ && $level > 1); 1113 if (!($clause =~ m/^\s*#/)) { 1114 $declaration .= "\t" x $level; 1115 } 1116 $declaration .= "\t" . $clause . "\n"; 1117 $level++ if ($clause =~ m/({)/ && !($clause =~m/}/)); 1118 } 1119 output_declaration($declaration_name, 1120 'struct', 1121 {'struct' => $declaration_name, 1122 'module' => $modulename, 1123 'definition' => $declaration, 1124 'parameterlist' => \@parameterlist, 1125 'parameterdescs' => \%parameterdescs, 1126 'parametertypes' => \%parametertypes, 1127 'sectionlist' => \@sectionlist, 1128 'sections' => \%sections, 1129 'purpose' => $declaration_purpose, 1130 'type' => $decl_type 1131 }); 1132 } 1133 else { 1134 print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 1135 ++$errors; 1136 } 1137} 1138 1139 1140sub show_warnings($$) { 1141 my $functype = shift; 1142 my $name = shift; 1143 1144 return 1 if ($output_selection == OUTPUT_ALL); 1145 1146 if ($output_selection == OUTPUT_EXPORTED) { 1147 if (defined($function_table{$name})) { 1148 return 1; 1149 } else { 1150 return 0; 1151 } 1152 } 1153 if ($output_selection == OUTPUT_INTERNAL) { 1154 if (!($functype eq "function" && defined($function_table{$name}))) { 1155 return 1; 1156 } else { 1157 return 0; 1158 } 1159 } 1160 if ($output_selection == OUTPUT_INCLUDE) { 1161 if (defined($function_table{$name})) { 1162 return 1; 1163 } else { 1164 return 0; 1165 } 1166 } 1167 if ($output_selection == OUTPUT_EXCLUDE) { 1168 if (!defined($function_table{$name})) { 1169 return 1; 1170 } else { 1171 return 0; 1172 } 1173 } 1174 die("Please add the new output type at show_warnings()"); 1175} 1176 1177sub dump_enum($$) { 1178 my $x = shift; 1179 my $file = shift; 1180 1181 $x =~ s@/\*.*?\*/@@gos; # strip comments. 1182 # strip #define macros inside enums 1183 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 1184 1185 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 1186 $declaration_name = $1; 1187 my $members = $2; 1188 my %_members; 1189 1190 $members =~ s/\s+$//; 1191 1192 foreach my $arg (split ',', $members) { 1193 $arg =~ s/^\s*(\w+).*/$1/; 1194 push @parameterlist, $arg; 1195 if (!$parameterdescs{$arg}) { 1196 $parameterdescs{$arg} = $undescribed; 1197 if (show_warnings("enum", $declaration_name)) { 1198 print STDERR "${file}:$.: warning: Enum value '$arg' not described in enum '$declaration_name'\n"; 1199 } 1200 } 1201 $_members{$arg} = 1; 1202 } 1203 1204 while (my ($k, $v) = each %parameterdescs) { 1205 if (!exists($_members{$k})) { 1206 if (show_warnings("enum", $declaration_name)) { 1207 print STDERR "${file}:$.: warning: Excess enum value '$k' description in '$declaration_name'\n"; 1208 } 1209 } 1210 } 1211 1212 output_declaration($declaration_name, 1213 'enum', 1214 {'enum' => $declaration_name, 1215 'module' => $modulename, 1216 'parameterlist' => \@parameterlist, 1217 'parameterdescs' => \%parameterdescs, 1218 'sectionlist' => \@sectionlist, 1219 'sections' => \%sections, 1220 'purpose' => $declaration_purpose 1221 }); 1222 } 1223 else { 1224 print STDERR "${file}:$.: error: Cannot parse enum!\n"; 1225 ++$errors; 1226 } 1227} 1228 1229sub dump_typedef($$) { 1230 my $x = shift; 1231 my $file = shift; 1232 1233 $x =~ s@/\*.*?\*/@@gos; # strip comments. 1234 1235 # Parse function prototypes 1236 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ || 1237 $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) { 1238 1239 # Function typedefs 1240 $return_type = $1; 1241 $declaration_name = $2; 1242 my $args = $3; 1243 1244 create_parameterlist($args, ',', $file, $declaration_name); 1245 1246 output_declaration($declaration_name, 1247 'function', 1248 {'function' => $declaration_name, 1249 'typedef' => 1, 1250 'module' => $modulename, 1251 'functiontype' => $return_type, 1252 'parameterlist' => \@parameterlist, 1253 'parameterdescs' => \%parameterdescs, 1254 'parametertypes' => \%parametertypes, 1255 'sectionlist' => \@sectionlist, 1256 'sections' => \%sections, 1257 'purpose' => $declaration_purpose 1258 }); 1259 return; 1260 } 1261 1262 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 1263 $x =~ s/\(*.\)\s*;$/;/; 1264 $x =~ s/\[*.\]\s*;$/;/; 1265 } 1266 1267 if ($x =~ /typedef.*\s+(\w+)\s*;/) { 1268 $declaration_name = $1; 1269 1270 output_declaration($declaration_name, 1271 'typedef', 1272 {'typedef' => $declaration_name, 1273 'module' => $modulename, 1274 'sectionlist' => \@sectionlist, 1275 'sections' => \%sections, 1276 'purpose' => $declaration_purpose 1277 }); 1278 } 1279 else { 1280 print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 1281 ++$errors; 1282 } 1283} 1284 1285sub save_struct_actual($) { 1286 my $actual = shift; 1287 1288 # strip all spaces from the actual param so that it looks like one string item 1289 $actual =~ s/\s*//g; 1290 $struct_actual = $struct_actual . $actual . " "; 1291} 1292 1293sub create_parameterlist($$$$) { 1294 my $args = shift; 1295 my $splitter = shift; 1296 my $file = shift; 1297 my $declaration_name = shift; 1298 my $type; 1299 my $param; 1300 1301 # temporarily replace commas inside function pointer definition 1302 while ($args =~ /(\([^\),]+),/) { 1303 $args =~ s/(\([^\),]+),/$1#/g; 1304 } 1305 1306 foreach my $arg (split($splitter, $args)) { 1307 # strip comments 1308 $arg =~ s/\/\*.*\*\///; 1309 # strip leading/trailing spaces 1310 $arg =~ s/^\s*//; 1311 $arg =~ s/\s*$//; 1312 $arg =~ s/\s+/ /; 1313 1314 if ($arg =~ /^#/) { 1315 # Treat preprocessor directive as a typeless variable just to fill 1316 # corresponding data structures "correctly". Catch it later in 1317 # output_* subs. 1318 push_parameter($arg, "", $file); 1319 } elsif ($arg =~ m/\(.+\)\s*\(/) { 1320 # pointer-to-function 1321 $arg =~ tr/#/,/; 1322 $arg =~ m/[^\(]+\(\*?\s*([\w\.]*)\s*\)/; 1323 $param = $1; 1324 $type = $arg; 1325 $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1326 save_struct_actual($param); 1327 push_parameter($param, $type, $file, $declaration_name); 1328 } elsif ($arg) { 1329 $arg =~ s/\s*:\s*/:/g; 1330 $arg =~ s/\s*\[/\[/g; 1331 1332 my @args = split('\s*,\s*', $arg); 1333 if ($args[0] =~ m/\*/) { 1334 $args[0] =~ s/(\*+)\s*/ $1/; 1335 } 1336 1337 my @first_arg; 1338 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1339 shift @args; 1340 push(@first_arg, split('\s+', $1)); 1341 push(@first_arg, $2); 1342 } else { 1343 @first_arg = split('\s+', shift @args); 1344 } 1345 1346 unshift(@args, pop @first_arg); 1347 $type = join " ", @first_arg; 1348 1349 foreach $param (@args) { 1350 if ($param =~ m/^(\*+)\s*(.*)/) { 1351 save_struct_actual($2); 1352 push_parameter($2, "$type $1", $file, $declaration_name); 1353 } 1354 elsif ($param =~ m/(.*?):(\d+)/) { 1355 if ($type ne "") { # skip unnamed bit-fields 1356 save_struct_actual($1); 1357 push_parameter($1, "$type:$2", $file, $declaration_name) 1358 } 1359 } 1360 else { 1361 save_struct_actual($param); 1362 push_parameter($param, $type, $file, $declaration_name); 1363 } 1364 } 1365 } 1366 } 1367} 1368 1369sub push_parameter($$$$) { 1370 my $param = shift; 1371 my $type = shift; 1372 my $file = shift; 1373 my $declaration_name = shift; 1374 1375 if (($anon_struct_union == 1) && ($type eq "") && 1376 ($param eq "}")) { 1377 return; # ignore the ending }; from anon. struct/union 1378 } 1379 1380 $anon_struct_union = 0; 1381 $param =~ s/[\[\)].*//; 1382 1383 if ($type eq "" && $param =~ /\.\.\.$/) 1384 { 1385 if (!$param =~ /\w\.\.\.$/) { 1386 # handles unnamed variable parameters 1387 $param = "..."; 1388 } 1389 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1390 $parameterdescs{$param} = "variable arguments"; 1391 } 1392 } 1393 elsif ($type eq "" && ($param eq "" or $param eq "void")) 1394 { 1395 $param="void"; 1396 $parameterdescs{void} = "no arguments"; 1397 } 1398 elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1399 # handle unnamed (anonymous) union or struct: 1400 { 1401 $type = $param; 1402 $param = "{unnamed_" . $param . "}"; 1403 $parameterdescs{$param} = "anonymous\n"; 1404 $anon_struct_union = 1; 1405 } 1406 1407 # warn if parameter has no description 1408 # (but ignore ones starting with # as these are not parameters 1409 # but inline preprocessor statements); 1410 # Note: It will also ignore void params and unnamed structs/unions 1411 if (!defined $parameterdescs{$param} && $param !~ /^#/) { 1412 $parameterdescs{$param} = $undescribed; 1413 1414 if (show_warnings($type, $declaration_name)) { 1415 print STDERR 1416 "${file}:$.: warning: Function parameter or member '$param' not described in '$declaration_name'\n"; 1417 ++$warnings; 1418 } 1419 } 1420 1421 # strip spaces from $param so that it is one continuous string 1422 # on @parameterlist; 1423 # this fixes a problem where check_sections() cannot find 1424 # a parameter like "addr[6 + 2]" because it actually appears 1425 # as "addr[6", "+", "2]" on the parameter list; 1426 # but it's better to maintain the param string unchanged for output, 1427 # so just weaken the string compare in check_sections() to ignore 1428 # "[blah" in a parameter string; 1429 ###$param =~ s/\s*//g; 1430 push @parameterlist, $param; 1431 $type =~ s/\s\s+/ /g; 1432 $parametertypes{$param} = $type; 1433} 1434 1435sub check_sections($$$$$) { 1436 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_; 1437 my @sects = split ' ', $sectcheck; 1438 my @prms = split ' ', $prmscheck; 1439 my $err; 1440 my ($px, $sx); 1441 my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 1442 1443 foreach $sx (0 .. $#sects) { 1444 $err = 1; 1445 foreach $px (0 .. $#prms) { 1446 $prm_clean = $prms[$px]; 1447 $prm_clean =~ s/\[.*\]//; 1448 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 1449 # ignore array size in a parameter string; 1450 # however, the original param string may contain 1451 # spaces, e.g.: addr[6 + 2] 1452 # and this appears in @prms as "addr[6" since the 1453 # parameter list is split at spaces; 1454 # hence just ignore "[..." for the sections check; 1455 $prm_clean =~ s/\[.*//; 1456 1457 ##$prm_clean =~ s/^\**//; 1458 if ($prm_clean eq $sects[$sx]) { 1459 $err = 0; 1460 last; 1461 } 1462 } 1463 if ($err) { 1464 if ($decl_type eq "function") { 1465 print STDERR "${file}:$.: warning: " . 1466 "Excess function parameter " . 1467 "'$sects[$sx]' " . 1468 "description in '$decl_name'\n"; 1469 ++$warnings; 1470 } 1471 } 1472 } 1473} 1474 1475## 1476# Checks the section describing the return value of a function. 1477sub check_return_section { 1478 my $file = shift; 1479 my $declaration_name = shift; 1480 my $return_type = shift; 1481 1482 # Ignore an empty return type (It's a macro) 1483 # Ignore functions with a "void" return type. (But don't ignore "void *") 1484 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 1485 return; 1486 } 1487 1488 if (!defined($sections{$section_return}) || 1489 $sections{$section_return} eq "") { 1490 print STDERR "${file}:$.: warning: " . 1491 "No description found for return value of " . 1492 "'$declaration_name'\n"; 1493 ++$warnings; 1494 } 1495} 1496 1497## 1498# takes a function prototype and the name of the current file being 1499# processed and spits out all the details stored in the global 1500# arrays/hashes. 1501sub dump_function($$) { 1502 my $prototype = shift; 1503 my $file = shift; 1504 my $noret = 0; 1505 1506 $prototype =~ s/^static +//; 1507 $prototype =~ s/^extern +//; 1508 $prototype =~ s/^asmlinkage +//; 1509 $prototype =~ s/^inline +//; 1510 $prototype =~ s/^__inline__ +//; 1511 $prototype =~ s/^__inline +//; 1512 $prototype =~ s/^__always_inline +//; 1513 $prototype =~ s/^noinline +//; 1514 $prototype =~ s/__init +//; 1515 $prototype =~ s/__init_or_module +//; 1516 $prototype =~ s/__meminit +//; 1517 $prototype =~ s/__must_check +//; 1518 $prototype =~ s/__weak +//; 1519 my $define = $prototype =~ s/^#\s*define\s+//; #ak added 1520 $prototype =~ s/__attribute__\s*\(\( 1521 (?: 1522 [\w\s]++ # attribute name 1523 (?:\([^)]*+\))? # attribute arguments 1524 \s*+,? # optional comma at the end 1525 )+ 1526 \)\)\s+//x; 1527 1528 # Yes, this truly is vile. We are looking for: 1529 # 1. Return type (may be nothing if we're looking at a macro) 1530 # 2. Function name 1531 # 3. Function parameters. 1532 # 1533 # All the while we have to watch out for function pointer parameters 1534 # (which IIRC is what the two sections are for), C types (these 1535 # regexps don't even start to express all the possibilities), and 1536 # so on. 1537 # 1538 # If you mess with these regexps, it's a good idea to check that 1539 # the following functions' documentation still comes out right: 1540 # - parport_register_device (function pointer parameters) 1541 # - atomic_set (macro) 1542 # - pci_match_device, __copy_to_user (long return type) 1543 1544 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 1545 # This is an object-like macro, it has no return type and no parameter 1546 # list. 1547 # Function-like macros are not allowed to have spaces between 1548 # declaration_name and opening parenthesis (notice the \s+). 1549 $return_type = $1; 1550 $declaration_name = $2; 1551 $noret = 1; 1552 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1553 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1554 $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1555 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1556 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1557 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1558 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1559 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1560 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1561 $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1562 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1563 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1564 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1565 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1566 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1567 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1568 $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 1569 $return_type = $1; 1570 $declaration_name = $2; 1571 my $args = $3; 1572 1573 create_parameterlist($args, ',', $file, $declaration_name); 1574 } else { 1575 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 1576 return; 1577 } 1578 1579 my $prms = join " ", @parameterlist; 1580 check_sections($file, $declaration_name, "function", $sectcheck, $prms); 1581 1582 # This check emits a lot of warnings at the moment, because many 1583 # functions don't have a 'Return' doc section. So until the number 1584 # of warnings goes sufficiently down, the check is only performed in 1585 # verbose mode. 1586 # TODO: always perform the check. 1587 if ($verbose && !$noret) { 1588 check_return_section($file, $declaration_name, $return_type); 1589 } 1590 1591 output_declaration($declaration_name, 1592 'function', 1593 {'function' => $declaration_name, 1594 'module' => $modulename, 1595 'functiontype' => $return_type, 1596 'parameterlist' => \@parameterlist, 1597 'parameterdescs' => \%parameterdescs, 1598 'parametertypes' => \%parametertypes, 1599 'sectionlist' => \@sectionlist, 1600 'sections' => \%sections, 1601 'purpose' => $declaration_purpose 1602 }); 1603} 1604 1605sub reset_state { 1606 $function = ""; 1607 %parameterdescs = (); 1608 %parametertypes = (); 1609 @parameterlist = (); 1610 %sections = (); 1611 @sectionlist = (); 1612 $sectcheck = ""; 1613 $struct_actual = ""; 1614 $prototype = ""; 1615 1616 $state = STATE_NORMAL; 1617 $inline_doc_state = STATE_INLINE_NA; 1618} 1619 1620sub tracepoint_munge($) { 1621 my $file = shift; 1622 my $tracepointname = 0; 1623 my $tracepointargs = 0; 1624 1625 if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 1626 $tracepointname = $1; 1627 } 1628 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 1629 $tracepointname = $1; 1630 } 1631 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 1632 $tracepointname = $2; 1633 } 1634 $tracepointname =~ s/^\s+//; #strip leading whitespace 1635 if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 1636 $tracepointargs = $1; 1637 } 1638 if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 1639 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 1640 "$prototype\n"; 1641 } else { 1642 $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 1643 } 1644} 1645 1646sub syscall_munge() { 1647 my $void = 0; 1648 1649 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's 1650## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 1651 if ($prototype =~ m/SYSCALL_DEFINE0/) { 1652 $void = 1; 1653## $prototype = "long sys_$1(void)"; 1654 } 1655 1656 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 1657 if ($prototype =~ m/long (sys_.*?),/) { 1658 $prototype =~ s/,/\(/; 1659 } elsif ($void) { 1660 $prototype =~ s/\)/\(void\)/; 1661 } 1662 1663 # now delete all of the odd-number commas in $prototype 1664 # so that arg types & arg names don't have a comma between them 1665 my $count = 0; 1666 my $len = length($prototype); 1667 if ($void) { 1668 $len = 0; # skip the for-loop 1669 } 1670 for (my $ix = 0; $ix < $len; $ix++) { 1671 if (substr($prototype, $ix, 1) eq ',') { 1672 $count++; 1673 if ($count % 2 == 1) { 1674 substr($prototype, $ix, 1) = ' '; 1675 } 1676 } 1677 } 1678} 1679 1680sub process_proto_function($$) { 1681 my $x = shift; 1682 my $file = shift; 1683 1684 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 1685 1686 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 1687 # do nothing 1688 } 1689 elsif ($x =~ /([^\{]*)/) { 1690 $prototype .= $1; 1691 } 1692 1693 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 1694 $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 1695 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 1696 $prototype =~ s@^\s+@@gos; # strip leading spaces 1697 if ($prototype =~ /SYSCALL_DEFINE/) { 1698 syscall_munge(); 1699 } 1700 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 1701 $prototype =~ /DEFINE_SINGLE_EVENT/) 1702 { 1703 tracepoint_munge($file); 1704 } 1705 dump_function($prototype, $file); 1706 reset_state(); 1707 } 1708} 1709 1710sub process_proto_type($$) { 1711 my $x = shift; 1712 my $file = shift; 1713 1714 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 1715 $x =~ s@^\s+@@gos; # strip leading spaces 1716 $x =~ s@\s+$@@gos; # strip trailing spaces 1717 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 1718 1719 if ($x =~ /^#/) { 1720 # To distinguish preprocessor directive from regular declaration later. 1721 $x .= ";"; 1722 } 1723 1724 while (1) { 1725 if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 1726 if( length $prototype ) { 1727 $prototype .= " " 1728 } 1729 $prototype .= $1 . $2; 1730 ($2 eq '{') && $brcount++; 1731 ($2 eq '}') && $brcount--; 1732 if (($2 eq ';') && ($brcount == 0)) { 1733 dump_declaration($prototype, $file); 1734 reset_state(); 1735 last; 1736 } 1737 $x = $3; 1738 } else { 1739 $prototype .= $x; 1740 last; 1741 } 1742 } 1743} 1744 1745 1746sub map_filename($) { 1747 my $file; 1748 my ($orig_file) = @_; 1749 1750 if (defined($ENV{'SRCTREE'})) { 1751 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 1752 } else { 1753 $file = $orig_file; 1754 } 1755 1756 if (defined($source_map{$file})) { 1757 $file = $source_map{$file}; 1758 } 1759 1760 return $file; 1761} 1762 1763sub process_export_file($) { 1764 my ($orig_file) = @_; 1765 my $file = map_filename($orig_file); 1766 1767 if (!open(IN,"<$file")) { 1768 print STDERR "Error: Cannot open file $file\n"; 1769 ++$errors; 1770 return; 1771 } 1772 1773 while (<IN>) { 1774 if (/$export_symbol/) { 1775 $function_table{$2} = 1; 1776 } 1777 } 1778 1779 close(IN); 1780} 1781 1782sub process_file($) { 1783 my $file; 1784 my $identifier; 1785 my $func; 1786 my $descr; 1787 my $in_purpose = 0; 1788 my $initial_section_counter = $section_counter; 1789 my ($orig_file) = @_; 1790 my $leading_space; 1791 1792 $file = map_filename($orig_file); 1793 1794 if (!open(IN,"<$file")) { 1795 print STDERR "Error: Cannot open file $file\n"; 1796 ++$errors; 1797 return; 1798 } 1799 1800 $. = 1; 1801 1802 $section_counter = 0; 1803 while (<IN>) { 1804 while (s/\\\s*$//) { 1805 $_ .= <IN>; 1806 } 1807 # Replace tabs by spaces 1808 while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; 1809 if ($state == STATE_NORMAL) { 1810 if (/$doc_start/o) { 1811 $state = STATE_NAME; # next line is always the function name 1812 $in_doc_sect = 0; 1813 $declaration_start_line = $. + 1; 1814 } 1815 } elsif ($state == STATE_NAME) {# this line is the function name (always) 1816 if (/$doc_block/o) { 1817 $state = STATE_DOCBLOCK; 1818 $contents = ""; 1819 $new_start_line = $. + 1; 1820 1821 if ( $1 eq "" ) { 1822 $section = $section_intro; 1823 } else { 1824 $section = $1; 1825 } 1826 } 1827 elsif (/$doc_decl/o) { 1828 $identifier = $1; 1829 if (/\s*([\w\s]+?)\s*-/) { 1830 $identifier = $1; 1831 } 1832 1833 $state = STATE_FIELD; 1834 # if there's no @param blocks need to set up default section 1835 # here 1836 $contents = ""; 1837 $section = $section_default; 1838 $new_start_line = $. + 1; 1839 if (/-(.*)/) { 1840 # strip leading/trailing/multiple spaces 1841 $descr= $1; 1842 $descr =~ s/^\s*//; 1843 $descr =~ s/\s*$//; 1844 $descr =~ s/\s+/ /g; 1845 $declaration_purpose = $descr; 1846 $in_purpose = 1; 1847 } else { 1848 $declaration_purpose = ""; 1849 } 1850 1851 if (($declaration_purpose eq "") && $verbose) { 1852 print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 1853 print STDERR $_; 1854 ++$warnings; 1855 } 1856 1857 if ($identifier =~ m/^struct/) { 1858 $decl_type = 'struct'; 1859 } elsif ($identifier =~ m/^union/) { 1860 $decl_type = 'union'; 1861 } elsif ($identifier =~ m/^enum/) { 1862 $decl_type = 'enum'; 1863 } elsif ($identifier =~ m/^typedef/) { 1864 $decl_type = 'typedef'; 1865 } else { 1866 $decl_type = 'function'; 1867 } 1868 1869 if ($verbose) { 1870 print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; 1871 } 1872 } else { 1873 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 1874 " - I thought it was a doc line\n"; 1875 ++$warnings; 1876 $state = STATE_NORMAL; 1877 } 1878 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content 1879 if (/$doc_sect/i) { # case insensitive for supported section names 1880 $newsection = $1; 1881 $newcontents = $2; 1882 1883 # map the supported section names to the canonical names 1884 if ($newsection =~ m/^description$/i) { 1885 $newsection = $section_default; 1886 } elsif ($newsection =~ m/^context$/i) { 1887 $newsection = $section_context; 1888 } elsif ($newsection =~ m/^returns?$/i) { 1889 $newsection = $section_return; 1890 } elsif ($newsection =~ m/^\@return$/) { 1891 # special: @return is a section, not a param description 1892 $newsection = $section_return; 1893 } 1894 1895 if (($contents ne "") && ($contents ne "\n")) { 1896 if (!$in_doc_sect && $verbose) { 1897 print STDERR "${file}:$.: warning: contents before sections\n"; 1898 ++$warnings; 1899 } 1900 dump_section($file, $section, $contents); 1901 $section = $section_default; 1902 } 1903 1904 $in_doc_sect = 1; 1905 $in_purpose = 0; 1906 $contents = $newcontents; 1907 $new_start_line = $.; 1908 while (substr($contents, 0, 1) eq " ") { 1909 $contents = substr($contents, 1); 1910 } 1911 if ($contents ne "") { 1912 $contents .= "\n"; 1913 } 1914 $section = $newsection; 1915 $leading_space = undef; 1916 } elsif (/$doc_end/) { 1917 if (($contents ne "") && ($contents ne "\n")) { 1918 dump_section($file, $section, $contents); 1919 $section = $section_default; 1920 $contents = ""; 1921 } 1922 # look for doc_com + <text> + doc_end: 1923 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 1924 print STDERR "${file}:$.: warning: suspicious ending line: $_"; 1925 ++$warnings; 1926 } 1927 1928 $prototype = ""; 1929 $state = STATE_PROTO; 1930 $brcount = 0; 1931# print STDERR "end of doc comment, looking for prototype\n"; 1932 } elsif (/$doc_content/) { 1933 # miguel-style comment kludge, look for blank lines after 1934 # @parameter line to signify start of description 1935 if ($1 eq "") { 1936 if ($section =~ m/^@/ || $section eq $section_context) { 1937 dump_section($file, $section, $contents); 1938 $section = $section_default; 1939 $contents = ""; 1940 $new_start_line = $.; 1941 } else { 1942 $contents .= "\n"; 1943 } 1944 $in_purpose = 0; 1945 } elsif ($in_purpose == 1) { 1946 # Continued declaration purpose 1947 chomp($declaration_purpose); 1948 $declaration_purpose .= " " . $1; 1949 $declaration_purpose =~ s/\s+/ /g; 1950 } else { 1951 my $cont = $1; 1952 if ($section =~ m/^@/ || $section eq $section_context) { 1953 if (!defined $leading_space) { 1954 if ($cont =~ m/^(\s+)/) { 1955 $leading_space = $1; 1956 } else { 1957 $leading_space = ""; 1958 } 1959 } 1960 1961 $cont =~ s/^$leading_space//; 1962 } 1963 $contents .= $cont . "\n"; 1964 } 1965 } else { 1966 # i dont know - bad line? ignore. 1967 print STDERR "${file}:$.: warning: bad line: $_"; 1968 ++$warnings; 1969 } 1970 } elsif ($state == STATE_INLINE) { # scanning for inline parameters 1971 # First line (state 1) needs to be a @parameter 1972 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 1973 $section = $1; 1974 $contents = $2; 1975 $new_start_line = $.; 1976 if ($contents ne "") { 1977 while (substr($contents, 0, 1) eq " ") { 1978 $contents = substr($contents, 1); 1979 } 1980 $contents .= "\n"; 1981 } 1982 $inline_doc_state = STATE_INLINE_TEXT; 1983 # Documentation block end */ 1984 } elsif (/$doc_inline_end/) { 1985 if (($contents ne "") && ($contents ne "\n")) { 1986 dump_section($file, $section, $contents); 1987 $section = $section_default; 1988 $contents = ""; 1989 } 1990 $state = STATE_PROTO; 1991 $inline_doc_state = STATE_INLINE_NA; 1992 # Regular text 1993 } elsif (/$doc_content/) { 1994 if ($inline_doc_state == STATE_INLINE_TEXT) { 1995 $contents .= $1 . "\n"; 1996 # nuke leading blank lines 1997 if ($contents =~ /^\s*$/) { 1998 $contents = ""; 1999 } 2000 } elsif ($inline_doc_state == STATE_INLINE_NAME) { 2001 $inline_doc_state = STATE_INLINE_ERROR; 2002 print STDERR "${file}:$.: warning: "; 2003 print STDERR "Incorrect use of kernel-doc format: $_"; 2004 ++$warnings; 2005 } 2006 } 2007 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype) 2008 if (/$doc_inline_oneline/) { 2009 $section = $1; 2010 $contents = $2; 2011 if ($contents ne "") { 2012 $contents .= "\n"; 2013 dump_section($file, $section, $contents); 2014 $section = $section_default; 2015 $contents = ""; 2016 } 2017 } elsif (/$doc_inline_start/) { 2018 $state = STATE_INLINE; 2019 $inline_doc_state = STATE_INLINE_NAME; 2020 } elsif ($decl_type eq 'function') { 2021 process_proto_function($_, $file); 2022 } else { 2023 process_proto_type($_, $file); 2024 } 2025 } elsif ($state == STATE_DOCBLOCK) { 2026 if (/$doc_end/) 2027 { 2028 dump_doc_section($file, $section, $contents); 2029 $section = $section_default; 2030 $contents = ""; 2031 $function = ""; 2032 %parameterdescs = (); 2033 %parametertypes = (); 2034 @parameterlist = (); 2035 %sections = (); 2036 @sectionlist = (); 2037 $prototype = ""; 2038 $state = STATE_NORMAL; 2039 } 2040 elsif (/$doc_content/) 2041 { 2042 if ( $1 eq "" ) 2043 { 2044 $contents .= $blankline; 2045 } 2046 else 2047 { 2048 $contents .= $1 . "\n"; 2049 } 2050 } 2051 } 2052 } 2053 if ($initial_section_counter == $section_counter) { 2054 if ($output_mode ne "none") { 2055 print STDERR "${file}:1: warning: no structured comments found\n"; 2056 } 2057 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) { 2058 print STDERR " Was looking for '$_'.\n" for keys %function_table; 2059 } 2060 } 2061} 2062 2063 2064$kernelversion = get_kernel_version(); 2065 2066# generate a sequence of code that will splice in highlighting information 2067# using the s// operator. 2068for (my $k = 0; $k < @highlights; $k++) { 2069 my $pattern = $highlights[$k][0]; 2070 my $result = $highlights[$k][1]; 2071# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 2072 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 2073} 2074 2075# Read the file that maps relative names to absolute names for 2076# separate source and object directories and for shadow trees. 2077if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 2078 my ($relname, $absname); 2079 while(<SOURCE_MAP>) { 2080 chop(); 2081 ($relname, $absname) = (split())[0..1]; 2082 $relname =~ s:^/+::; 2083 $source_map{$relname} = $absname; 2084 } 2085 close(SOURCE_MAP); 2086} 2087 2088if ($output_selection == OUTPUT_EXPORTED || 2089 $output_selection == OUTPUT_INTERNAL) { 2090 2091 push(@export_file_list, @ARGV); 2092 2093 foreach (@export_file_list) { 2094 chomp; 2095 process_export_file($_); 2096 } 2097} 2098 2099foreach (@ARGV) { 2100 chomp; 2101 process_file($_); 2102} 2103if ($verbose && $errors) { 2104 print STDERR "$errors errors\n"; 2105} 2106if ($verbose && $warnings) { 2107 print STDERR "$warnings warnings\n"; 2108} 2109 2110exit($output_mode eq "none" ? 0 : $errors); 2111