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+(\.\.\.)?)'; 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, local_unescape($blankline); 557 } 558 } else { 559 $line =~ s/\\\\\\/\&/g; 560 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 561 print "\\&$line"; 562 } else { 563 print $lineprefix, $line; 564 } 565 } 566 print "\n"; 567 } 568} 569 570## 571# output function in man 572sub output_function_man(%) { 573 my %args = %{$_[0]}; 574 my ($parameter, $section); 575 my $count; 576 577 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 578 579 print ".SH NAME\n"; 580 print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 581 582 print ".SH SYNOPSIS\n"; 583 if ($args{'functiontype'} ne "") { 584 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 585 } else { 586 print ".B \"" . $args{'function'} . "\n"; 587 } 588 $count = 0; 589 my $parenth = "("; 590 my $post = ","; 591 foreach my $parameter (@{$args{'parameterlist'}}) { 592 if ($count == $#{$args{'parameterlist'}}) { 593 $post = ");"; 594 } 595 $type = $args{'parametertypes'}{$parameter}; 596 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 597 # pointer-to-function 598 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 599 } else { 600 $type =~ s/([^\*])$/$1 /; 601 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 602 } 603 $count++; 604 $parenth = ""; 605 } 606 607 print ".SH ARGUMENTS\n"; 608 foreach $parameter (@{$args{'parameterlist'}}) { 609 my $parameter_name = $parameter; 610 $parameter_name =~ s/\[.*//; 611 612 print ".IP \"" . $parameter . "\" 12\n"; 613 output_highlight($args{'parameterdescs'}{$parameter_name}); 614 } 615 foreach $section (@{$args{'sectionlist'}}) { 616 print ".SH \"", uc $section, "\"\n"; 617 output_highlight($args{'sections'}{$section}); 618 } 619} 620 621## 622# output enum in man 623sub output_enum_man(%) { 624 my %args = %{$_[0]}; 625 my ($parameter, $section); 626 my $count; 627 628 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 629 630 print ".SH NAME\n"; 631 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 632 633 print ".SH SYNOPSIS\n"; 634 print "enum " . $args{'enum'} . " {\n"; 635 $count = 0; 636 foreach my $parameter (@{$args{'parameterlist'}}) { 637 print ".br\n.BI \" $parameter\"\n"; 638 if ($count == $#{$args{'parameterlist'}}) { 639 print "\n};\n"; 640 last; 641 } 642 else { 643 print ", \n.br\n"; 644 } 645 $count++; 646 } 647 648 print ".SH Constants\n"; 649 foreach $parameter (@{$args{'parameterlist'}}) { 650 my $parameter_name = $parameter; 651 $parameter_name =~ s/\[.*//; 652 653 print ".IP \"" . $parameter . "\" 12\n"; 654 output_highlight($args{'parameterdescs'}{$parameter_name}); 655 } 656 foreach $section (@{$args{'sectionlist'}}) { 657 print ".SH \"$section\"\n"; 658 output_highlight($args{'sections'}{$section}); 659 } 660} 661 662## 663# output struct in man 664sub output_struct_man(%) { 665 my %args = %{$_[0]}; 666 my ($parameter, $section); 667 668 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 669 670 print ".SH NAME\n"; 671 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 672 673 print ".SH SYNOPSIS\n"; 674 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 675 676 foreach my $parameter (@{$args{'parameterlist'}}) { 677 if ($parameter =~ /^#/) { 678 print ".BI \"$parameter\"\n.br\n"; 679 next; 680 } 681 my $parameter_name = $parameter; 682 $parameter_name =~ s/\[.*//; 683 684 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 685 $type = $args{'parametertypes'}{$parameter}; 686 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 687 # pointer-to-function 688 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; 689 } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 690 # bitfield 691 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; 692 } else { 693 $type =~ s/([^\*])$/$1 /; 694 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; 695 } 696 print "\n.br\n"; 697 } 698 print "};\n.br\n"; 699 700 print ".SH Members\n"; 701 foreach $parameter (@{$args{'parameterlist'}}) { 702 ($parameter =~ /^#/) && next; 703 704 my $parameter_name = $parameter; 705 $parameter_name =~ s/\[.*//; 706 707 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 708 print ".IP \"" . $parameter . "\" 12\n"; 709 output_highlight($args{'parameterdescs'}{$parameter_name}); 710 } 711 foreach $section (@{$args{'sectionlist'}}) { 712 print ".SH \"$section\"\n"; 713 output_highlight($args{'sections'}{$section}); 714 } 715} 716 717## 718# output typedef in man 719sub output_typedef_man(%) { 720 my %args = %{$_[0]}; 721 my ($parameter, $section); 722 723 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 724 725 print ".SH NAME\n"; 726 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 727 728 foreach $section (@{$args{'sectionlist'}}) { 729 print ".SH \"$section\"\n"; 730 output_highlight($args{'sections'}{$section}); 731 } 732} 733 734sub output_blockhead_man(%) { 735 my %args = %{$_[0]}; 736 my ($parameter, $section); 737 my $count; 738 739 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 740 741 foreach $section (@{$args{'sectionlist'}}) { 742 print ".SH \"$section\"\n"; 743 output_highlight($args{'sections'}{$section}); 744 } 745} 746 747## 748# output in restructured text 749# 750 751# 752# This could use some work; it's used to output the DOC: sections, and 753# starts by putting out the name of the doc section itself, but that tends 754# to duplicate a header already in the template file. 755# 756sub output_blockhead_rst(%) { 757 my %args = %{$_[0]}; 758 my ($parameter, $section); 759 760 foreach $section (@{$args{'sectionlist'}}) { 761 if ($output_selection != OUTPUT_INCLUDE) { 762 print "**$section**\n\n"; 763 } 764 print_lineno($section_start_lines{$section}); 765 output_highlight_rst($args{'sections'}{$section}); 766 print "\n"; 767 } 768} 769 770sub output_highlight_rst { 771 my $contents = join "\n",@_; 772 my $line; 773 774 # undo the evil effects of xml_escape() earlier 775 $contents = xml_unescape($contents); 776 777 eval $dohighlight; 778 die $@ if $@; 779 780 foreach $line (split "\n", $contents) { 781 print $lineprefix . $line . "\n"; 782 } 783} 784 785sub output_function_rst(%) { 786 my %args = %{$_[0]}; 787 my ($parameter, $section); 788 my $oldprefix = $lineprefix; 789 my $start = ""; 790 791 if ($args{'typedef'}) { 792 print ".. c:type:: ". $args{'function'} . "\n\n"; 793 print_lineno($declaration_start_line); 794 print " **Typedef**: "; 795 $lineprefix = ""; 796 output_highlight_rst($args{'purpose'}); 797 $start = "\n\n**Syntax**\n\n ``"; 798 } else { 799 print ".. c:function:: "; 800 } 801 if ($args{'functiontype'} ne "") { 802 $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; 803 } else { 804 $start .= $args{'function'} . " ("; 805 } 806 print $start; 807 808 my $count = 0; 809 foreach my $parameter (@{$args{'parameterlist'}}) { 810 if ($count ne 0) { 811 print ", "; 812 } 813 $count++; 814 $type = $args{'parametertypes'}{$parameter}; 815 816 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 817 # pointer-to-function 818 print $1 . $parameter . ") (" . $2; 819 } else { 820 print $type . " " . $parameter; 821 } 822 } 823 if ($args{'typedef'}) { 824 print ");``\n\n"; 825 } else { 826 print ")\n\n"; 827 print_lineno($declaration_start_line); 828 $lineprefix = " "; 829 output_highlight_rst($args{'purpose'}); 830 print "\n"; 831 } 832 833 print "**Parameters**\n\n"; 834 $lineprefix = " "; 835 foreach $parameter (@{$args{'parameterlist'}}) { 836 my $parameter_name = $parameter; 837 $parameter_name =~ s/\[.*//; 838 $type = $args{'parametertypes'}{$parameter}; 839 840 if ($type ne "") { 841 print "``$type $parameter``\n"; 842 } else { 843 print "``$parameter``\n"; 844 } 845 846 print_lineno($parameterdesc_start_lines{$parameter_name}); 847 848 if (defined($args{'parameterdescs'}{$parameter_name}) && 849 $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 850 output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 851 } else { 852 print " *undescribed*\n"; 853 } 854 print "\n"; 855 } 856 857 $lineprefix = $oldprefix; 858 output_section_rst(@_); 859} 860 861sub output_section_rst(%) { 862 my %args = %{$_[0]}; 863 my $section; 864 my $oldprefix = $lineprefix; 865 $lineprefix = ""; 866 867 foreach $section (@{$args{'sectionlist'}}) { 868 print "**$section**\n\n"; 869 print_lineno($section_start_lines{$section}); 870 output_highlight_rst($args{'sections'}{$section}); 871 print "\n"; 872 } 873 print "\n"; 874 $lineprefix = $oldprefix; 875} 876 877sub output_enum_rst(%) { 878 my %args = %{$_[0]}; 879 my ($parameter); 880 my $oldprefix = $lineprefix; 881 my $count; 882 my $name = "enum " . $args{'enum'}; 883 884 print "\n\n.. c:type:: " . $name . "\n\n"; 885 print_lineno($declaration_start_line); 886 $lineprefix = " "; 887 output_highlight_rst($args{'purpose'}); 888 print "\n"; 889 890 print "**Constants**\n\n"; 891 $lineprefix = " "; 892 foreach $parameter (@{$args{'parameterlist'}}) { 893 print "``$parameter``\n"; 894 if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 895 output_highlight_rst($args{'parameterdescs'}{$parameter}); 896 } else { 897 print " *undescribed*\n"; 898 } 899 print "\n"; 900 } 901 902 $lineprefix = $oldprefix; 903 output_section_rst(@_); 904} 905 906sub output_typedef_rst(%) { 907 my %args = %{$_[0]}; 908 my ($parameter); 909 my $oldprefix = $lineprefix; 910 my $name = "typedef " . $args{'typedef'}; 911 912 print "\n\n.. c:type:: " . $name . "\n\n"; 913 print_lineno($declaration_start_line); 914 $lineprefix = " "; 915 output_highlight_rst($args{'purpose'}); 916 print "\n"; 917 918 $lineprefix = $oldprefix; 919 output_section_rst(@_); 920} 921 922sub output_struct_rst(%) { 923 my %args = %{$_[0]}; 924 my ($parameter); 925 my $oldprefix = $lineprefix; 926 my $name = $args{'type'} . " " . $args{'struct'}; 927 928 print "\n\n.. c:type:: " . $name . "\n\n"; 929 print_lineno($declaration_start_line); 930 $lineprefix = " "; 931 output_highlight_rst($args{'purpose'}); 932 print "\n"; 933 934 print "**Definition**\n\n"; 935 print "::\n\n"; 936 print " " . $args{'type'} . " " . $args{'struct'} . " {\n"; 937 foreach $parameter (@{$args{'parameterlist'}}) { 938 if ($parameter =~ /^#/) { 939 print " " . "$parameter\n"; 940 next; 941 } 942 943 my $parameter_name = $parameter; 944 $parameter_name =~ s/\[.*//; 945 946 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 947 $type = $args{'parametertypes'}{$parameter}; 948 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 949 # pointer-to-function 950 print " $1 $parameter) ($2);\n"; 951 } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 952 # bitfield 953 print " $1 $parameter$2;\n"; 954 } else { 955 print " " . $type . " " . $parameter . ";\n"; 956 } 957 } 958 print " };\n\n"; 959 960 print "**Members**\n\n"; 961 $lineprefix = " "; 962 foreach $parameter (@{$args{'parameterlist'}}) { 963 ($parameter =~ /^#/) && next; 964 965 my $parameter_name = $parameter; 966 $parameter_name =~ s/\[.*//; 967 968 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 969 $type = $args{'parametertypes'}{$parameter}; 970 print_lineno($parameterdesc_start_lines{$parameter_name}); 971 print "``" . $parameter . "``\n"; 972 output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 973 print "\n"; 974 } 975 print "\n"; 976 977 $lineprefix = $oldprefix; 978 output_section_rst(@_); 979} 980 981## none mode output functions 982 983sub output_function_none(%) { 984} 985 986sub output_enum_none(%) { 987} 988 989sub output_typedef_none(%) { 990} 991 992sub output_struct_none(%) { 993} 994 995sub output_blockhead_none(%) { 996} 997 998## 999# generic output function for all types (function, struct/union, typedef, enum); 1000# calls the generated, variable output_ function name based on 1001# functype and output_mode 1002sub output_declaration { 1003 no strict 'refs'; 1004 my $name = shift; 1005 my $functype = shift; 1006 my $func = "output_${functype}_$output_mode"; 1007 if (($output_selection == OUTPUT_ALL) || 1008 (($output_selection == OUTPUT_INCLUDE || 1009 $output_selection == OUTPUT_EXPORTED) && 1010 defined($function_table{$name})) || 1011 (($output_selection == OUTPUT_EXCLUDE || 1012 $output_selection == OUTPUT_INTERNAL) && 1013 !($functype eq "function" && defined($function_table{$name})))) 1014 { 1015 &$func(@_); 1016 $section_counter++; 1017 } 1018} 1019 1020## 1021# generic output function - calls the right one based on current output mode. 1022sub output_blockhead { 1023 no strict 'refs'; 1024 my $func = "output_blockhead_" . $output_mode; 1025 &$func(@_); 1026 $section_counter++; 1027} 1028 1029## 1030# takes a declaration (struct, union, enum, typedef) and 1031# invokes the right handler. NOT called for functions. 1032sub dump_declaration($$) { 1033 no strict 'refs'; 1034 my ($prototype, $file) = @_; 1035 my $func = "dump_" . $decl_type; 1036 &$func(@_); 1037} 1038 1039sub dump_union($$) { 1040 dump_struct(@_); 1041} 1042 1043sub dump_struct($$) { 1044 my $x = shift; 1045 my $file = shift; 1046 my $nested; 1047 1048 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 1049 my $decl_type = $1; 1050 $declaration_name = $2; 1051 my $members = $3; 1052 1053 # ignore embedded structs or unions 1054 $members =~ s/({.*})//g; 1055 $nested = $1; 1056 1057 # ignore members marked private: 1058 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 1059 $members =~ s/\/\*\s*private:.*//gosi; 1060 # strip comments: 1061 $members =~ s/\/\*.*?\*\///gos; 1062 $nested =~ s/\/\*.*?\*\///gos; 1063 # strip attributes 1064 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 1065 $members =~ s/__aligned\s*\([^;]*\)//gos; 1066 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; 1067 # replace DECLARE_BITMAP 1068 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 1069 # replace DECLARE_HASHTABLE 1070 $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos; 1071 # replace DECLARE_KFIFO 1072 $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; 1073 # replace DECLARE_KFIFO_PTR 1074 $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; 1075 1076 create_parameterlist($members, ';', $file); 1077 check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual, $nested); 1078 1079 output_declaration($declaration_name, 1080 'struct', 1081 {'struct' => $declaration_name, 1082 'module' => $modulename, 1083 'parameterlist' => \@parameterlist, 1084 'parameterdescs' => \%parameterdescs, 1085 'parametertypes' => \%parametertypes, 1086 'sectionlist' => \@sectionlist, 1087 'sections' => \%sections, 1088 'purpose' => $declaration_purpose, 1089 'type' => $decl_type 1090 }); 1091 } 1092 else { 1093 print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 1094 ++$errors; 1095 } 1096} 1097 1098sub dump_enum($$) { 1099 my $x = shift; 1100 my $file = shift; 1101 1102 $x =~ s@/\*.*?\*/@@gos; # strip comments. 1103 # strip #define macros inside enums 1104 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 1105 1106 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 1107 $declaration_name = $1; 1108 my $members = $2; 1109 my %_members; 1110 1111 $members =~ s/\s+$//; 1112 1113 foreach my $arg (split ',', $members) { 1114 $arg =~ s/^\s*(\w+).*/$1/; 1115 push @parameterlist, $arg; 1116 if (!$parameterdescs{$arg}) { 1117 $parameterdescs{$arg} = $undescribed; 1118 print STDERR "${file}:$.: warning: Enum value '$arg' ". 1119 "not described in enum '$declaration_name'\n"; 1120 } 1121 $_members{$arg} = 1; 1122 } 1123 1124 while (my ($k, $v) = each %parameterdescs) { 1125 if (!exists($_members{$k})) { 1126 print STDERR "${file}:$.: warning: Excess enum value " . 1127 "'$k' description in '$declaration_name'\n"; 1128 } 1129 } 1130 1131 output_declaration($declaration_name, 1132 'enum', 1133 {'enum' => $declaration_name, 1134 'module' => $modulename, 1135 'parameterlist' => \@parameterlist, 1136 'parameterdescs' => \%parameterdescs, 1137 'sectionlist' => \@sectionlist, 1138 'sections' => \%sections, 1139 'purpose' => $declaration_purpose 1140 }); 1141 } 1142 else { 1143 print STDERR "${file}:$.: error: Cannot parse enum!\n"; 1144 ++$errors; 1145 } 1146} 1147 1148sub dump_typedef($$) { 1149 my $x = shift; 1150 my $file = shift; 1151 1152 $x =~ s@/\*.*?\*/@@gos; # strip comments. 1153 1154 # Parse function prototypes 1155 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ || 1156 $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) { 1157 1158 # Function typedefs 1159 $return_type = $1; 1160 $declaration_name = $2; 1161 my $args = $3; 1162 1163 create_parameterlist($args, ',', $file); 1164 1165 output_declaration($declaration_name, 1166 'function', 1167 {'function' => $declaration_name, 1168 'typedef' => 1, 1169 'module' => $modulename, 1170 'functiontype' => $return_type, 1171 'parameterlist' => \@parameterlist, 1172 'parameterdescs' => \%parameterdescs, 1173 'parametertypes' => \%parametertypes, 1174 'sectionlist' => \@sectionlist, 1175 'sections' => \%sections, 1176 'purpose' => $declaration_purpose 1177 }); 1178 return; 1179 } 1180 1181 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 1182 $x =~ s/\(*.\)\s*;$/;/; 1183 $x =~ s/\[*.\]\s*;$/;/; 1184 } 1185 1186 if ($x =~ /typedef.*\s+(\w+)\s*;/) { 1187 $declaration_name = $1; 1188 1189 output_declaration($declaration_name, 1190 'typedef', 1191 {'typedef' => $declaration_name, 1192 'module' => $modulename, 1193 'sectionlist' => \@sectionlist, 1194 'sections' => \%sections, 1195 'purpose' => $declaration_purpose 1196 }); 1197 } 1198 else { 1199 print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 1200 ++$errors; 1201 } 1202} 1203 1204sub save_struct_actual($) { 1205 my $actual = shift; 1206 1207 # strip all spaces from the actual param so that it looks like one string item 1208 $actual =~ s/\s*//g; 1209 $struct_actual = $struct_actual . $actual . " "; 1210} 1211 1212sub create_parameterlist($$$) { 1213 my $args = shift; 1214 my $splitter = shift; 1215 my $file = shift; 1216 my $type; 1217 my $param; 1218 1219 # temporarily replace commas inside function pointer definition 1220 while ($args =~ /(\([^\),]+),/) { 1221 $args =~ s/(\([^\),]+),/$1#/g; 1222 } 1223 1224 foreach my $arg (split($splitter, $args)) { 1225 # strip comments 1226 $arg =~ s/\/\*.*\*\///; 1227 # strip leading/trailing spaces 1228 $arg =~ s/^\s*//; 1229 $arg =~ s/\s*$//; 1230 $arg =~ s/\s+/ /; 1231 1232 if ($arg =~ /^#/) { 1233 # Treat preprocessor directive as a typeless variable just to fill 1234 # corresponding data structures "correctly". Catch it later in 1235 # output_* subs. 1236 push_parameter($arg, "", $file); 1237 } elsif ($arg =~ m/\(.+\)\s*\(/) { 1238 # pointer-to-function 1239 $arg =~ tr/#/,/; 1240 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 1241 $param = $1; 1242 $type = $arg; 1243 $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1244 save_struct_actual($param); 1245 push_parameter($param, $type, $file); 1246 } elsif ($arg) { 1247 $arg =~ s/\s*:\s*/:/g; 1248 $arg =~ s/\s*\[/\[/g; 1249 1250 my @args = split('\s*,\s*', $arg); 1251 if ($args[0] =~ m/\*/) { 1252 $args[0] =~ s/(\*+)\s*/ $1/; 1253 } 1254 1255 my @first_arg; 1256 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1257 shift @args; 1258 push(@first_arg, split('\s+', $1)); 1259 push(@first_arg, $2); 1260 } else { 1261 @first_arg = split('\s+', shift @args); 1262 } 1263 1264 unshift(@args, pop @first_arg); 1265 $type = join " ", @first_arg; 1266 1267 foreach $param (@args) { 1268 if ($param =~ m/^(\*+)\s*(.*)/) { 1269 save_struct_actual($2); 1270 push_parameter($2, "$type $1", $file); 1271 } 1272 elsif ($param =~ m/(.*?):(\d+)/) { 1273 if ($type ne "") { # skip unnamed bit-fields 1274 save_struct_actual($1); 1275 push_parameter($1, "$type:$2", $file) 1276 } 1277 } 1278 else { 1279 save_struct_actual($param); 1280 push_parameter($param, $type, $file); 1281 } 1282 } 1283 } 1284 } 1285} 1286 1287sub push_parameter($$$) { 1288 my $param = shift; 1289 my $type = shift; 1290 my $file = shift; 1291 1292 if (($anon_struct_union == 1) && ($type eq "") && 1293 ($param eq "}")) { 1294 return; # ignore the ending }; from anon. struct/union 1295 } 1296 1297 $anon_struct_union = 0; 1298 $param =~ s/[\[\)].*//; 1299 1300 if ($type eq "" && $param =~ /\.\.\.$/) 1301 { 1302 if (!$param =~ /\w\.\.\.$/) { 1303 # handles unnamed variable parameters 1304 $param = "..."; 1305 } 1306 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1307 $parameterdescs{$param} = "variable arguments"; 1308 } 1309 } 1310 elsif ($type eq "" && ($param eq "" or $param eq "void")) 1311 { 1312 $param="void"; 1313 $parameterdescs{void} = "no arguments"; 1314 } 1315 elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1316 # handle unnamed (anonymous) union or struct: 1317 { 1318 $type = $param; 1319 $param = "{unnamed_" . $param . "}"; 1320 $parameterdescs{$param} = "anonymous\n"; 1321 $anon_struct_union = 1; 1322 } 1323 1324 # warn if parameter has no description 1325 # (but ignore ones starting with # as these are not parameters 1326 # but inline preprocessor statements); 1327 # also ignore unnamed structs/unions; 1328 if (!$anon_struct_union) { 1329 if (!defined $parameterdescs{$param} && $param !~ /^#/) { 1330 1331 $parameterdescs{$param} = $undescribed; 1332 1333 if (($type eq 'function') || ($type eq 'enum')) { 1334 print STDERR "${file}:$.: warning: Function parameter ". 1335 "or member '$param' not " . 1336 "described in '$declaration_name'\n"; 1337 } 1338 print STDERR "${file}:$.: warning:" . 1339 " No description found for parameter '$param'\n"; 1340 ++$warnings; 1341 } 1342 } 1343 1344 $param = xml_escape($param); 1345 1346 # strip spaces from $param so that it is one continuous string 1347 # on @parameterlist; 1348 # this fixes a problem where check_sections() cannot find 1349 # a parameter like "addr[6 + 2]" because it actually appears 1350 # as "addr[6", "+", "2]" on the parameter list; 1351 # but it's better to maintain the param string unchanged for output, 1352 # so just weaken the string compare in check_sections() to ignore 1353 # "[blah" in a parameter string; 1354 ###$param =~ s/\s*//g; 1355 push @parameterlist, $param; 1356 $type =~ s/\s\s+/ /g; 1357 $parametertypes{$param} = $type; 1358} 1359 1360sub check_sections($$$$$$) { 1361 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; 1362 my @sects = split ' ', $sectcheck; 1363 my @prms = split ' ', $prmscheck; 1364 my $err; 1365 my ($px, $sx); 1366 my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 1367 1368 foreach $sx (0 .. $#sects) { 1369 $err = 1; 1370 foreach $px (0 .. $#prms) { 1371 $prm_clean = $prms[$px]; 1372 $prm_clean =~ s/\[.*\]//; 1373 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 1374 # ignore array size in a parameter string; 1375 # however, the original param string may contain 1376 # spaces, e.g.: addr[6 + 2] 1377 # and this appears in @prms as "addr[6" since the 1378 # parameter list is split at spaces; 1379 # hence just ignore "[..." for the sections check; 1380 $prm_clean =~ s/\[.*//; 1381 1382 ##$prm_clean =~ s/^\**//; 1383 if ($prm_clean eq $sects[$sx]) { 1384 $err = 0; 1385 last; 1386 } 1387 } 1388 if ($err) { 1389 if ($decl_type eq "function") { 1390 print STDERR "${file}:$.: warning: " . 1391 "Excess function parameter " . 1392 "'$sects[$sx]' " . 1393 "description in '$decl_name'\n"; 1394 ++$warnings; 1395 } else { 1396 if ($nested !~ m/\Q$sects[$sx]\E/) { 1397 print STDERR "${file}:$.: warning: " . 1398 "Excess $decl_type member " . 1399 "'$sects[$sx]' " . 1400 "description in '$decl_name'\n"; 1401 ++$warnings; 1402 } 1403 } 1404 } 1405 } 1406} 1407 1408## 1409# Checks the section describing the return value of a function. 1410sub check_return_section { 1411 my $file = shift; 1412 my $declaration_name = shift; 1413 my $return_type = shift; 1414 1415 # Ignore an empty return type (It's a macro) 1416 # Ignore functions with a "void" return type. (But don't ignore "void *") 1417 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 1418 return; 1419 } 1420 1421 if (!defined($sections{$section_return}) || 1422 $sections{$section_return} eq "") { 1423 print STDERR "${file}:$.: warning: " . 1424 "No description found for return value of " . 1425 "'$declaration_name'\n"; 1426 ++$warnings; 1427 } 1428} 1429 1430## 1431# takes a function prototype and the name of the current file being 1432# processed and spits out all the details stored in the global 1433# arrays/hashes. 1434sub dump_function($$) { 1435 my $prototype = shift; 1436 my $file = shift; 1437 my $noret = 0; 1438 1439 $prototype =~ s/^static +//; 1440 $prototype =~ s/^extern +//; 1441 $prototype =~ s/^asmlinkage +//; 1442 $prototype =~ s/^inline +//; 1443 $prototype =~ s/^__inline__ +//; 1444 $prototype =~ s/^__inline +//; 1445 $prototype =~ s/^__always_inline +//; 1446 $prototype =~ s/^noinline +//; 1447 $prototype =~ s/__init +//; 1448 $prototype =~ s/__init_or_module +//; 1449 $prototype =~ s/__meminit +//; 1450 $prototype =~ s/__must_check +//; 1451 $prototype =~ s/__weak +//; 1452 my $define = $prototype =~ s/^#\s*define\s+//; #ak added 1453 $prototype =~ s/__attribute__\s*\(\( 1454 (?: 1455 [\w\s]++ # attribute name 1456 (?:\([^)]*+\))? # attribute arguments 1457 \s*+,? # optional comma at the end 1458 )+ 1459 \)\)\s+//x; 1460 1461 # Yes, this truly is vile. We are looking for: 1462 # 1. Return type (may be nothing if we're looking at a macro) 1463 # 2. Function name 1464 # 3. Function parameters. 1465 # 1466 # All the while we have to watch out for function pointer parameters 1467 # (which IIRC is what the two sections are for), C types (these 1468 # regexps don't even start to express all the possibilities), and 1469 # so on. 1470 # 1471 # If you mess with these regexps, it's a good idea to check that 1472 # the following functions' documentation still comes out right: 1473 # - parport_register_device (function pointer parameters) 1474 # - atomic_set (macro) 1475 # - pci_match_device, __copy_to_user (long return type) 1476 1477 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 1478 # This is an object-like macro, it has no return type and no parameter 1479 # list. 1480 # Function-like macros are not allowed to have spaces between 1481 # declaration_name and opening parenthesis (notice the \s+). 1482 $return_type = $1; 1483 $declaration_name = $2; 1484 $noret = 1; 1485 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1486 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1487 $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1488 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1489 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1490 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1491 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1492 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1493 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1494 $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1495 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1496 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1497 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1498 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1499 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1500 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1501 $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 1502 $return_type = $1; 1503 $declaration_name = $2; 1504 my $args = $3; 1505 1506 create_parameterlist($args, ',', $file); 1507 } else { 1508 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 1509 return; 1510 } 1511 1512 my $prms = join " ", @parameterlist; 1513 check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); 1514 1515 # This check emits a lot of warnings at the moment, because many 1516 # functions don't have a 'Return' doc section. So until the number 1517 # of warnings goes sufficiently down, the check is only performed in 1518 # verbose mode. 1519 # TODO: always perform the check. 1520 if ($verbose && !$noret) { 1521 check_return_section($file, $declaration_name, $return_type); 1522 } 1523 1524 output_declaration($declaration_name, 1525 'function', 1526 {'function' => $declaration_name, 1527 'module' => $modulename, 1528 'functiontype' => $return_type, 1529 'parameterlist' => \@parameterlist, 1530 'parameterdescs' => \%parameterdescs, 1531 'parametertypes' => \%parametertypes, 1532 'sectionlist' => \@sectionlist, 1533 'sections' => \%sections, 1534 'purpose' => $declaration_purpose 1535 }); 1536} 1537 1538sub reset_state { 1539 $function = ""; 1540 %parameterdescs = (); 1541 %parametertypes = (); 1542 @parameterlist = (); 1543 %sections = (); 1544 @sectionlist = (); 1545 $sectcheck = ""; 1546 $struct_actual = ""; 1547 $prototype = ""; 1548 1549 $state = STATE_NORMAL; 1550 $inline_doc_state = STATE_INLINE_NA; 1551} 1552 1553sub tracepoint_munge($) { 1554 my $file = shift; 1555 my $tracepointname = 0; 1556 my $tracepointargs = 0; 1557 1558 if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 1559 $tracepointname = $1; 1560 } 1561 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 1562 $tracepointname = $1; 1563 } 1564 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 1565 $tracepointname = $2; 1566 } 1567 $tracepointname =~ s/^\s+//; #strip leading whitespace 1568 if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 1569 $tracepointargs = $1; 1570 } 1571 if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 1572 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 1573 "$prototype\n"; 1574 } else { 1575 $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 1576 } 1577} 1578 1579sub syscall_munge() { 1580 my $void = 0; 1581 1582 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs 1583## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 1584 if ($prototype =~ m/SYSCALL_DEFINE0/) { 1585 $void = 1; 1586## $prototype = "long sys_$1(void)"; 1587 } 1588 1589 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 1590 if ($prototype =~ m/long (sys_.*?),/) { 1591 $prototype =~ s/,/\(/; 1592 } elsif ($void) { 1593 $prototype =~ s/\)/\(void\)/; 1594 } 1595 1596 # now delete all of the odd-number commas in $prototype 1597 # so that arg types & arg names don't have a comma between them 1598 my $count = 0; 1599 my $len = length($prototype); 1600 if ($void) { 1601 $len = 0; # skip the for-loop 1602 } 1603 for (my $ix = 0; $ix < $len; $ix++) { 1604 if (substr($prototype, $ix, 1) eq ',') { 1605 $count++; 1606 if ($count % 2 == 1) { 1607 substr($prototype, $ix, 1) = ' '; 1608 } 1609 } 1610 } 1611} 1612 1613sub process_proto_function($$) { 1614 my $x = shift; 1615 my $file = shift; 1616 1617 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 1618 1619 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 1620 # do nothing 1621 } 1622 elsif ($x =~ /([^\{]*)/) { 1623 $prototype .= $1; 1624 } 1625 1626 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 1627 $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 1628 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 1629 $prototype =~ s@^\s+@@gos; # strip leading spaces 1630 if ($prototype =~ /SYSCALL_DEFINE/) { 1631 syscall_munge(); 1632 } 1633 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 1634 $prototype =~ /DEFINE_SINGLE_EVENT/) 1635 { 1636 tracepoint_munge($file); 1637 } 1638 dump_function($prototype, $file); 1639 reset_state(); 1640 } 1641} 1642 1643sub process_proto_type($$) { 1644 my $x = shift; 1645 my $file = shift; 1646 1647 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 1648 $x =~ s@^\s+@@gos; # strip leading spaces 1649 $x =~ s@\s+$@@gos; # strip trailing spaces 1650 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 1651 1652 if ($x =~ /^#/) { 1653 # To distinguish preprocessor directive from regular declaration later. 1654 $x .= ";"; 1655 } 1656 1657 while (1) { 1658 if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 1659 if( length $prototype ) { 1660 $prototype .= " " 1661 } 1662 $prototype .= $1 . $2; 1663 ($2 eq '{') && $brcount++; 1664 ($2 eq '}') && $brcount--; 1665 if (($2 eq ';') && ($brcount == 0)) { 1666 dump_declaration($prototype, $file); 1667 reset_state(); 1668 last; 1669 } 1670 $x = $3; 1671 } else { 1672 $prototype .= $x; 1673 last; 1674 } 1675 } 1676} 1677 1678# xml_escape: replace <, >, and & in the text stream; 1679# 1680# however, formatting controls that are generated internally/locally in the 1681# kernel-doc script are not escaped here; instead, they begin life like 1682# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings 1683# are converted to their mnemonic-expected output, without the 4 * '\' & ':', 1684# just before actual output; (this is done by local_unescape()) 1685sub xml_escape($) { 1686 my $text = shift; 1687 if ($output_mode eq "man") { 1688 return $text; 1689 } 1690 $text =~ s/\&/\\\\\\amp;/g; 1691 $text =~ s/\</\\\\\\lt;/g; 1692 $text =~ s/\>/\\\\\\gt;/g; 1693 return $text; 1694} 1695 1696# xml_unescape: reverse the effects of xml_escape 1697sub xml_unescape($) { 1698 my $text = shift; 1699 if ($output_mode eq "man") { 1700 return $text; 1701 } 1702 $text =~ s/\\\\\\amp;/\&/g; 1703 $text =~ s/\\\\\\lt;/</g; 1704 $text =~ s/\\\\\\gt;/>/g; 1705 return $text; 1706} 1707 1708# convert local escape strings to html 1709# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) 1710sub local_unescape($) { 1711 my $text = shift; 1712 if ($output_mode eq "man") { 1713 return $text; 1714 } 1715 $text =~ s/\\\\\\\\lt:/</g; 1716 $text =~ s/\\\\\\\\gt:/>/g; 1717 return $text; 1718} 1719 1720sub map_filename($) { 1721 my $file; 1722 my ($orig_file) = @_; 1723 1724 if (defined($ENV{'SRCTREE'})) { 1725 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 1726 } else { 1727 $file = $orig_file; 1728 } 1729 1730 if (defined($source_map{$file})) { 1731 $file = $source_map{$file}; 1732 } 1733 1734 return $file; 1735} 1736 1737sub process_export_file($) { 1738 my ($orig_file) = @_; 1739 my $file = map_filename($orig_file); 1740 1741 if (!open(IN,"<$file")) { 1742 print STDERR "Error: Cannot open file $file\n"; 1743 ++$errors; 1744 return; 1745 } 1746 1747 while (<IN>) { 1748 if (/$export_symbol/) { 1749 $function_table{$2} = 1; 1750 } 1751 } 1752 1753 close(IN); 1754} 1755 1756sub process_file($) { 1757 my $file; 1758 my $identifier; 1759 my $func; 1760 my $descr; 1761 my $in_purpose = 0; 1762 my $initial_section_counter = $section_counter; 1763 my ($orig_file) = @_; 1764 my $leading_space; 1765 1766 $file = map_filename($orig_file); 1767 1768 if (!open(IN,"<$file")) { 1769 print STDERR "Error: Cannot open file $file\n"; 1770 ++$errors; 1771 return; 1772 } 1773 1774 $. = 1; 1775 1776 $section_counter = 0; 1777 while (<IN>) { 1778 while (s/\\\s*$//) { 1779 $_ .= <IN>; 1780 } 1781 if ($state == STATE_NORMAL) { 1782 if (/$doc_start/o) { 1783 $state = STATE_NAME; # next line is always the function name 1784 $in_doc_sect = 0; 1785 $declaration_start_line = $. + 1; 1786 } 1787 } elsif ($state == STATE_NAME) {# this line is the function name (always) 1788 if (/$doc_block/o) { 1789 $state = STATE_DOCBLOCK; 1790 $contents = ""; 1791 $new_start_line = $. + 1; 1792 1793 if ( $1 eq "" ) { 1794 $section = $section_intro; 1795 } else { 1796 $section = $1; 1797 } 1798 } 1799 elsif (/$doc_decl/o) { 1800 $identifier = $1; 1801 if (/\s*([\w\s]+?)\s*-/) { 1802 $identifier = $1; 1803 } 1804 1805 $state = STATE_FIELD; 1806 # if there's no @param blocks need to set up default section 1807 # here 1808 $contents = ""; 1809 $section = $section_default; 1810 $new_start_line = $. + 1; 1811 if (/-(.*)/) { 1812 # strip leading/trailing/multiple spaces 1813 $descr= $1; 1814 $descr =~ s/^\s*//; 1815 $descr =~ s/\s*$//; 1816 $descr =~ s/\s+/ /g; 1817 $declaration_purpose = xml_escape($descr); 1818 $in_purpose = 1; 1819 } else { 1820 $declaration_purpose = ""; 1821 } 1822 1823 if (($declaration_purpose eq "") && $verbose) { 1824 print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 1825 print STDERR $_; 1826 ++$warnings; 1827 } 1828 1829 if ($identifier =~ m/^struct/) { 1830 $decl_type = 'struct'; 1831 } elsif ($identifier =~ m/^union/) { 1832 $decl_type = 'union'; 1833 } elsif ($identifier =~ m/^enum/) { 1834 $decl_type = 'enum'; 1835 } elsif ($identifier =~ m/^typedef/) { 1836 $decl_type = 'typedef'; 1837 } else { 1838 $decl_type = 'function'; 1839 } 1840 1841 if ($verbose) { 1842 print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; 1843 } 1844 } else { 1845 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 1846 " - I thought it was a doc line\n"; 1847 ++$warnings; 1848 $state = STATE_NORMAL; 1849 } 1850 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content 1851 if (/$doc_sect/i) { # case insensitive for supported section names 1852 $newsection = $1; 1853 $newcontents = $2; 1854 1855 # map the supported section names to the canonical names 1856 if ($newsection =~ m/^description$/i) { 1857 $newsection = $section_default; 1858 } elsif ($newsection =~ m/^context$/i) { 1859 $newsection = $section_context; 1860 } elsif ($newsection =~ m/^returns?$/i) { 1861 $newsection = $section_return; 1862 } elsif ($newsection =~ m/^\@return$/) { 1863 # special: @return is a section, not a param description 1864 $newsection = $section_return; 1865 } 1866 1867 if (($contents ne "") && ($contents ne "\n")) { 1868 if (!$in_doc_sect && $verbose) { 1869 print STDERR "${file}:$.: warning: contents before sections\n"; 1870 ++$warnings; 1871 } 1872 dump_section($file, $section, xml_escape($contents)); 1873 $section = $section_default; 1874 } 1875 1876 $in_doc_sect = 1; 1877 $in_purpose = 0; 1878 $contents = $newcontents; 1879 $new_start_line = $.; 1880 while ((substr($contents, 0, 1) eq " ") || 1881 substr($contents, 0, 1) eq "\t") { 1882 $contents = substr($contents, 1); 1883 } 1884 if ($contents ne "") { 1885 $contents .= "\n"; 1886 } 1887 $section = $newsection; 1888 $leading_space = undef; 1889 } elsif (/$doc_end/) { 1890 if (($contents ne "") && ($contents ne "\n")) { 1891 dump_section($file, $section, xml_escape($contents)); 1892 $section = $section_default; 1893 $contents = ""; 1894 } 1895 # look for doc_com + <text> + doc_end: 1896 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 1897 print STDERR "${file}:$.: warning: suspicious ending line: $_"; 1898 ++$warnings; 1899 } 1900 1901 $prototype = ""; 1902 $state = STATE_PROTO; 1903 $brcount = 0; 1904# print STDERR "end of doc comment, looking for prototype\n"; 1905 } elsif (/$doc_content/) { 1906 # miguel-style comment kludge, look for blank lines after 1907 # @parameter line to signify start of description 1908 if ($1 eq "") { 1909 if ($section =~ m/^@/ || $section eq $section_context) { 1910 dump_section($file, $section, xml_escape($contents)); 1911 $section = $section_default; 1912 $contents = ""; 1913 $new_start_line = $.; 1914 } else { 1915 $contents .= "\n"; 1916 } 1917 $in_purpose = 0; 1918 } elsif ($in_purpose == 1) { 1919 # Continued declaration purpose 1920 chomp($declaration_purpose); 1921 $declaration_purpose .= " " . xml_escape($1); 1922 $declaration_purpose =~ s/\s+/ /g; 1923 } else { 1924 my $cont = $1; 1925 if ($section =~ m/^@/ || $section eq $section_context) { 1926 if (!defined $leading_space) { 1927 if ($cont =~ m/^(\s+)/) { 1928 $leading_space = $1; 1929 } else { 1930 $leading_space = ""; 1931 } 1932 } 1933 1934 $cont =~ s/^$leading_space//; 1935 } 1936 $contents .= $cont . "\n"; 1937 } 1938 } else { 1939 # i dont know - bad line? ignore. 1940 print STDERR "${file}:$.: warning: bad line: $_"; 1941 ++$warnings; 1942 } 1943 } elsif ($state == STATE_INLINE) { # scanning for inline parameters 1944 # First line (state 1) needs to be a @parameter 1945 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 1946 $section = $1; 1947 $contents = $2; 1948 $new_start_line = $.; 1949 if ($contents ne "") { 1950 while ((substr($contents, 0, 1) eq " ") || 1951 substr($contents, 0, 1) eq "\t") { 1952 $contents = substr($contents, 1); 1953 } 1954 $contents .= "\n"; 1955 } 1956 $inline_doc_state = STATE_INLINE_TEXT; 1957 # Documentation block end */ 1958 } elsif (/$doc_inline_end/) { 1959 if (($contents ne "") && ($contents ne "\n")) { 1960 dump_section($file, $section, xml_escape($contents)); 1961 $section = $section_default; 1962 $contents = ""; 1963 } 1964 $state = STATE_PROTO; 1965 $inline_doc_state = STATE_INLINE_NA; 1966 # Regular text 1967 } elsif (/$doc_content/) { 1968 if ($inline_doc_state == STATE_INLINE_TEXT) { 1969 $contents .= $1 . "\n"; 1970 # nuke leading blank lines 1971 if ($contents =~ /^\s*$/) { 1972 $contents = ""; 1973 } 1974 } elsif ($inline_doc_state == STATE_INLINE_NAME) { 1975 $inline_doc_state = STATE_INLINE_ERROR; 1976 print STDERR "${file}:$.: warning: "; 1977 print STDERR "Incorrect use of kernel-doc format: $_"; 1978 ++$warnings; 1979 } 1980 } 1981 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype) 1982 if (/$doc_inline_oneline/) { 1983 $section = $1; 1984 $contents = $2; 1985 if ($contents ne "") { 1986 $contents .= "\n"; 1987 dump_section($file, $section, xml_escape($contents)); 1988 $section = $section_default; 1989 $contents = ""; 1990 } 1991 } elsif (/$doc_inline_start/) { 1992 $state = STATE_INLINE; 1993 $inline_doc_state = STATE_INLINE_NAME; 1994 } elsif ($decl_type eq 'function') { 1995 process_proto_function($_, $file); 1996 } else { 1997 process_proto_type($_, $file); 1998 } 1999 } elsif ($state == STATE_DOCBLOCK) { 2000 if (/$doc_end/) 2001 { 2002 dump_doc_section($file, $section, xml_escape($contents)); 2003 $section = $section_default; 2004 $contents = ""; 2005 $function = ""; 2006 %parameterdescs = (); 2007 %parametertypes = (); 2008 @parameterlist = (); 2009 %sections = (); 2010 @sectionlist = (); 2011 $prototype = ""; 2012 $state = STATE_NORMAL; 2013 } 2014 elsif (/$doc_content/) 2015 { 2016 if ( $1 eq "" ) 2017 { 2018 $contents .= $blankline; 2019 } 2020 else 2021 { 2022 $contents .= $1 . "\n"; 2023 } 2024 } 2025 } 2026 } 2027 if ($initial_section_counter == $section_counter) { 2028 if ($output_mode ne "none") { 2029 print STDERR "${file}:1: warning: no structured comments found\n"; 2030 } 2031 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) { 2032 print STDERR " Was looking for '$_'.\n" for keys %function_table; 2033 } 2034 } 2035} 2036 2037 2038$kernelversion = get_kernel_version(); 2039 2040# generate a sequence of code that will splice in highlighting information 2041# using the s// operator. 2042for (my $k = 0; $k < @highlights; $k++) { 2043 my $pattern = $highlights[$k][0]; 2044 my $result = $highlights[$k][1]; 2045# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 2046 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 2047} 2048 2049# Read the file that maps relative names to absolute names for 2050# separate source and object directories and for shadow trees. 2051if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 2052 my ($relname, $absname); 2053 while(<SOURCE_MAP>) { 2054 chop(); 2055 ($relname, $absname) = (split())[0..1]; 2056 $relname =~ s:^/+::; 2057 $source_map{$relname} = $absname; 2058 } 2059 close(SOURCE_MAP); 2060} 2061 2062if ($output_selection == OUTPUT_EXPORTED || 2063 $output_selection == OUTPUT_INTERNAL) { 2064 2065 push(@export_file_list, @ARGV); 2066 2067 foreach (@export_file_list) { 2068 chomp; 2069 process_export_file($_); 2070 } 2071} 2072 2073foreach (@ARGV) { 2074 chomp; 2075 process_file($_); 2076} 2077if ($verbose && $errors) { 2078 print STDERR "$errors errors\n"; 2079} 2080if ($verbose && $warnings) { 2081 print STDERR "$warnings warnings\n"; 2082} 2083 2084exit($output_mode eq "none" ? 0 : $errors); 2085