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