1#!/usr/bin/perl -w 2 3use strict; 4 5## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## 6## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## 7## Copyright (C) 2001 Simon Huggins ## 8## Copyright (C) 2005-2012 Randy Dunlap ## 9## Copyright (C) 2012 Dan Luedtke ## 10## ## 11## #define enhancements by Armin Kuster <akuster@mvista.com> ## 12## Copyright (c) 2000 MontaVista Software, Inc. ## 13## ## 14## This software falls under the GNU General Public License. ## 15## Please read the COPYING file for more information ## 16 17# 18/01/2001 - Cleanups 18# Functions prototyped as foo(void) same as foo() 19# Stop eval'ing where we don't need to. 20# -- huggie@earth.li 21 22# 27/06/2001 - Allowed whitespace after initial "/**" and 23# allowed comments before function declarations. 24# -- Christian Kreibich <ck@whoop.org> 25 26# Still to do: 27# - add perldoc documentation 28# - Look more closely at some of the scarier bits :) 29 30# 26/05/2001 - Support for separate source and object trees. 31# Return error code. 32# Keith Owens <kaos@ocs.com.au> 33 34# 23/09/2001 - Added support for typedefs, structs, enums and unions 35# Support for Context section; can be terminated using empty line 36# Small fixes (like spaces vs. \s in regex) 37# -- Tim Jansen <tim@tjansen.de> 38 39# 25/07/2012 - Added support for HTML5 40# -- Dan Luedtke <mail@danrl.de> 41 42sub usage { 43 my $message = <<"EOF"; 44Usage: $0 [OPTION ...] FILE ... 45 46Read C language source or header FILEs, extract embedded documentation comments, 47and print formatted documentation to standard output. 48 49The documentation comments are identified by "/**" opening comment mark. See 50Documentation/kernel-doc-nano-HOWTO.txt for the documentation comment syntax. 51 52Output format selection (mutually exclusive): 53 -docbook Output DocBook format. 54 -html Output HTML format. 55 -html5 Output HTML5 format. 56 -list Output symbol list format. This is for use by docproc. 57 -man Output troff manual page format. This is the default. 58 -text Output plain text format. 59 60Output selection (mutually exclusive): 61 -function NAME Only output documentation for the given function(s) 62 or DOC: section title(s). All other functions and DOC: 63 sections are ignored. May be specified multiple times. 64 -nofunction NAME Do NOT output documentation for the given function(s); 65 only output documentation for the other functions and 66 DOC: sections. May be specified multiple times. 67 68Output selection modifiers: 69 -no-doc-sections Do not output DOC: sections. 70 71Other parameters: 72 -v Verbose output, more warnings and other information. 73 -h Print this help. 74 75EOF 76 print $message; 77 exit 1; 78} 79 80# 81# format of comments. 82# In the following table, (...)? signifies optional structure. 83# (...)* signifies 0 or more structure elements 84# /** 85# * function_name(:)? (- short description)? 86# (* @parameterx: (description of parameter x)?)* 87# (* a blank line)? 88# * (Description:)? (Description of function)? 89# * (section header: (section description)? )* 90# (*)?*/ 91# 92# So .. the trivial example would be: 93# 94# /** 95# * my_function 96# */ 97# 98# If the Description: header tag is omitted, then there must be a blank line 99# after the last parameter specification. 100# e.g. 101# /** 102# * my_function - does my stuff 103# * @my_arg: its mine damnit 104# * 105# * Does my stuff explained. 106# */ 107# 108# or, could also use: 109# /** 110# * my_function - does my stuff 111# * @my_arg: its mine damnit 112# * Description: Does my stuff explained. 113# */ 114# etc. 115# 116# Besides functions you can also write documentation for structs, unions, 117# enums and typedefs. Instead of the function name you must write the name 118# of the declaration; the struct/union/enum/typedef must always precede 119# the name. Nesting of declarations is not supported. 120# Use the argument mechanism to document members or constants. 121# e.g. 122# /** 123# * struct my_struct - short description 124# * @a: first member 125# * @b: second member 126# * 127# * Longer description 128# */ 129# struct my_struct { 130# int a; 131# int b; 132# /* private: */ 133# int c; 134# }; 135# 136# All descriptions can be multiline, except the short function description. 137# 138# For really longs structs, you can also describe arguments inside the 139# body of the struct. 140# eg. 141# /** 142# * struct my_struct - short description 143# * @a: first member 144# * @b: second member 145# * 146# * Longer description 147# */ 148# struct my_struct { 149# int a; 150# int b; 151# /** 152# * @c: This is longer description of C 153# * 154# * You can use paragraphs to describe arguments 155# * using this method. 156# */ 157# int c; 158# }; 159# 160# This should be use only for struct/enum members. 161# 162# You can also add additional sections. When documenting kernel functions you 163# should document the "Context:" of the function, e.g. whether the functions 164# can be called form interrupts. Unlike other sections you can end it with an 165# empty line. 166# A non-void function should have a "Return:" section describing the return 167# value(s). 168# Example-sections should contain the string EXAMPLE so that they are marked 169# appropriately in DocBook. 170# 171# Example: 172# /** 173# * user_function - function that can only be called in user context 174# * @a: some argument 175# * Context: !in_interrupt() 176# * 177# * Some description 178# * Example: 179# * user_function(22); 180# */ 181# ... 182# 183# 184# All descriptive text is further processed, scanning for the following special 185# patterns, which are highlighted appropriately. 186# 187# 'funcname()' - function 188# '$ENVVAR' - environmental variable 189# '&struct_name' - name of a structure (up to two words including 'struct') 190# '@parameter' - name of a parameter 191# '%CONST' - name of a constant. 192 193## init lots of data 194 195my $errors = 0; 196my $warnings = 0; 197my $anon_struct_union = 0; 198 199# match expressions used to find embedded type information 200my $type_constant = '\%([-_\w]+)'; 201my $type_func = '(\w+)\(\)'; 202my $type_param = '\@(\w+)'; 203my $type_struct = '\&((struct\s*)*[_\w]+)'; 204my $type_struct_xml = '\\&((struct\s*)*[_\w]+)'; 205my $type_env = '(\$\w+)'; 206 207# Output conversion substitutions. 208# One for each output format 209 210# these work fairly well 211my @highlights_html = ( 212 [$type_constant, "<i>\$1</i>"], 213 [$type_func, "<b>\$1</b>"], 214 [$type_struct_xml, "<i>\$1</i>"], 215 [$type_env, "<b><i>\$1</i></b>"], 216 [$type_param, "<tt><b>\$1</b></tt>"] 217 ); 218my $local_lt = "\\\\\\\\lt:"; 219my $local_gt = "\\\\\\\\gt:"; 220my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" 221 222# html version 5 223my @highlights_html5 = ( 224 [$type_constant, "<span class=\"const\">\$1</span>"], 225 [$type_func, "<span class=\"func\">\$1</span>"], 226 [$type_struct_xml, "<span class=\"struct\">\$1</span>"], 227 [$type_env, "<span class=\"env\">\$1</span>"], 228 [$type_param, "<span class=\"param\">\$1</span>]"] 229 ); 230my $blankline_html5 = $local_lt . "br /" . $local_gt; 231 232# XML, docbook format 233my @highlights_xml = ( 234 ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"], 235 [$type_constant, "<constant>\$1</constant>"], 236 [$type_struct_xml, "<structname>\$1</structname>"], 237 [$type_param, "<parameter>\$1</parameter>"], 238 [$type_func, "<function>\$1</function>"], 239 [$type_env, "<envar>\$1</envar>"] 240 ); 241my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; 242 243# gnome, docbook format 244my @highlights_gnome = ( 245 [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"], 246 [$type_func, "<function>\$1</function>"], 247 [$type_struct, "<structname>\$1</structname>"], 248 [$type_env, "<envar>\$1</envar>"], 249 [$type_param, "<parameter>\$1</parameter>" ] 250 ); 251my $blankline_gnome = "</para><para>\n"; 252 253# these are pretty rough 254my @highlights_man = ( 255 [$type_constant, "\$1"], 256 [$type_func, "\\\\fB\$1\\\\fP"], 257 [$type_struct, "\\\\fI\$1\\\\fP"], 258 [$type_param, "\\\\fI\$1\\\\fP"] 259 ); 260my $blankline_man = ""; 261 262# text-mode 263my @highlights_text = ( 264 [$type_constant, "\$1"], 265 [$type_func, "\$1"], 266 [$type_struct, "\$1"], 267 [$type_param, "\$1"] 268 ); 269my $blankline_text = ""; 270 271# list mode 272my @highlights_list = ( 273 [$type_constant, "\$1"], 274 [$type_func, "\$1"], 275 [$type_struct, "\$1"], 276 [$type_param, "\$1"] 277 ); 278my $blankline_list = ""; 279 280# read arguments 281if ($#ARGV == -1) { 282 usage(); 283} 284 285my $kernelversion; 286my $dohighlight = ""; 287 288my $verbose = 0; 289my $output_mode = "man"; 290my $output_preformatted = 0; 291my $no_doc_sections = 0; 292my @highlights = @highlights_man; 293my $blankline = $blankline_man; 294my $modulename = "Kernel API"; 295my $function_only = 0; 296my $show_not_found = 0; 297 298my @build_time; 299if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 300 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 301 @build_time = gmtime($seconds); 302} else { 303 @build_time = localtime; 304} 305 306my $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 307 'July', 'August', 'September', 'October', 308 'November', 'December')[$build_time[4]] . 309 " " . ($build_time[5]+1900); 310 311# Essentially these are globals. 312# They probably want to be tidied up, made more localised or something. 313# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 314# could cause "use of undefined value" or other bugs. 315my ($function, %function_table, %parametertypes, $declaration_purpose); 316my ($type, $declaration_name, $return_type); 317my ($newsection, $newcontents, $prototype, $brcount, %source_map); 318 319if (defined($ENV{'KBUILD_VERBOSE'})) { 320 $verbose = "$ENV{'KBUILD_VERBOSE'}"; 321} 322 323# Generated docbook code is inserted in a template at a point where 324# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 325# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 326# We keep track of number of generated entries and generate a dummy 327# if needs be to ensure the expanded template can be postprocessed 328# into html. 329my $section_counter = 0; 330 331my $lineprefix=""; 332 333# states 334# 0 - normal code 335# 1 - looking for function name 336# 2 - scanning field start. 337# 3 - scanning prototype. 338# 4 - documentation block 339# 5 - gathering documentation outside main block 340my $state; 341my $in_doc_sect; 342 343# Split Doc State 344# 0 - Invalid (Before start or after finish) 345# 1 - Is started (the /** was found inside a struct) 346# 2 - The @parameter header was found, start accepting multi paragraph text. 347# 3 - Finished (the */ was found) 348# 4 - Error - Comment without header was found. Spit a warning as it's not 349# proper kernel-doc and ignore the rest. 350my $split_doc_state; 351 352#declaration types: can be 353# 'function', 'struct', 'union', 'enum', 'typedef' 354my $decl_type; 355 356my $doc_special = "\@\%\$\&"; 357 358my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 359my $doc_end = '\*/'; 360my $doc_com = '\s*\*\s*'; 361my $doc_com_body = '\s*\* ?'; 362my $doc_decl = $doc_com . '(\w+)'; 363my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)'; 364my $doc_content = $doc_com_body . '(.*)'; 365my $doc_block = $doc_com . 'DOC:\s*(.*)?'; 366my $doc_split_start = '^\s*/\*\*\s*$'; 367my $doc_split_sect = '\s*\*\s*(@[\w\s]+):(.*)'; 368my $doc_split_end = '^\s*\*/\s*$'; 369 370my %constants; 371my %parameterdescs; 372my @parameterlist; 373my %sections; 374my @sectionlist; 375my $sectcheck; 376my $struct_actual; 377 378my $contents = ""; 379my $section_default = "Description"; # default section 380my $section_intro = "Introduction"; 381my $section = $section_default; 382my $section_context = "Context"; 383my $section_return = "Return"; 384 385my $undescribed = "-- undescribed --"; 386 387reset_state(); 388 389while ($ARGV[0] =~ m/^-(.*)/) { 390 my $cmd = shift @ARGV; 391 if ($cmd eq "-html") { 392 $output_mode = "html"; 393 @highlights = @highlights_html; 394 $blankline = $blankline_html; 395 } elsif ($cmd eq "-html5") { 396 $output_mode = "html5"; 397 @highlights = @highlights_html5; 398 $blankline = $blankline_html5; 399 } elsif ($cmd eq "-man") { 400 $output_mode = "man"; 401 @highlights = @highlights_man; 402 $blankline = $blankline_man; 403 } elsif ($cmd eq "-text") { 404 $output_mode = "text"; 405 @highlights = @highlights_text; 406 $blankline = $blankline_text; 407 } elsif ($cmd eq "-docbook") { 408 $output_mode = "xml"; 409 @highlights = @highlights_xml; 410 $blankline = $blankline_xml; 411 } elsif ($cmd eq "-list") { 412 $output_mode = "list"; 413 @highlights = @highlights_list; 414 $blankline = $blankline_list; 415 } elsif ($cmd eq "-gnome") { 416 $output_mode = "gnome"; 417 @highlights = @highlights_gnome; 418 $blankline = $blankline_gnome; 419 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document 420 $modulename = shift @ARGV; 421 } elsif ($cmd eq "-function") { # to only output specific functions 422 $function_only = 1; 423 $function = shift @ARGV; 424 $function_table{$function} = 1; 425 } elsif ($cmd eq "-nofunction") { # to only output specific functions 426 $function_only = 2; 427 $function = shift @ARGV; 428 $function_table{$function} = 1; 429 } elsif ($cmd eq "-v") { 430 $verbose = 1; 431 } elsif (($cmd eq "-h") || ($cmd eq "--help")) { 432 usage(); 433 } elsif ($cmd eq '-no-doc-sections') { 434 $no_doc_sections = 1; 435 } elsif ($cmd eq '-show-not-found') { 436 $show_not_found = 1; 437 } 438} 439 440# continue execution near EOF; 441 442# get kernel version from env 443sub get_kernel_version() { 444 my $version = 'unknown kernel version'; 445 446 if (defined($ENV{'KERNELVERSION'})) { 447 $version = $ENV{'KERNELVERSION'}; 448 } 449 return $version; 450} 451 452## 453# dumps section contents to arrays/hashes intended for that purpose. 454# 455sub dump_section { 456 my $file = shift; 457 my $name = shift; 458 my $contents = join "\n", @_; 459 460 if ($name =~ m/$type_constant/) { 461 $name = $1; 462# print STDERR "constant section '$1' = '$contents'\n"; 463 $constants{$name} = $contents; 464 } elsif ($name =~ m/$type_param/) { 465# print STDERR "parameter def '$1' = '$contents'\n"; 466 $name = $1; 467 $parameterdescs{$name} = $contents; 468 $sectcheck = $sectcheck . $name . " "; 469 } elsif ($name eq "@\.\.\.") { 470# print STDERR "parameter def '...' = '$contents'\n"; 471 $name = "..."; 472 $parameterdescs{$name} = $contents; 473 $sectcheck = $sectcheck . $name . " "; 474 } else { 475# print STDERR "other section '$name' = '$contents'\n"; 476 if (defined($sections{$name}) && ($sections{$name} ne "")) { 477 print STDERR "${file}:$.: error: duplicate section name '$name'\n"; 478 ++$errors; 479 } 480 $sections{$name} = $contents; 481 push @sectionlist, $name; 482 } 483} 484 485## 486# dump DOC: section after checking that it should go out 487# 488sub dump_doc_section { 489 my $file = shift; 490 my $name = shift; 491 my $contents = join "\n", @_; 492 493 if ($no_doc_sections) { 494 return; 495 } 496 497 if (($function_only == 0) || 498 ( $function_only == 1 && defined($function_table{$name})) || 499 ( $function_only == 2 && !defined($function_table{$name}))) 500 { 501 dump_section($file, $name, $contents); 502 output_blockhead({'sectionlist' => \@sectionlist, 503 'sections' => \%sections, 504 'module' => $modulename, 505 'content-only' => ($function_only != 0), }); 506 } 507} 508 509## 510# output function 511# 512# parameterdescs, a hash. 513# function => "function name" 514# parameterlist => @list of parameters 515# parameterdescs => %parameter descriptions 516# sectionlist => @list of sections 517# sections => %section descriptions 518# 519 520sub output_highlight { 521 my $contents = join "\n",@_; 522 my $line; 523 524# DEBUG 525# if (!defined $contents) { 526# use Carp; 527# confess "output_highlight got called with no args?\n"; 528# } 529 530 if ($output_mode eq "html" || $output_mode eq "html5" || 531 $output_mode eq "xml") { 532 $contents = local_unescape($contents); 533 # convert data read & converted thru xml_escape() into &xyz; format: 534 $contents =~ s/\\\\\\/\&/g; 535 } 536# print STDERR "contents b4:$contents\n"; 537 eval $dohighlight; 538 die $@ if $@; 539# print STDERR "contents af:$contents\n"; 540 541# strip whitespaces when generating html5 542 if ($output_mode eq "html5") { 543 $contents =~ s/^\s+//; 544 $contents =~ s/\s+$//; 545 } 546 foreach $line (split "\n", $contents) { 547 if (! $output_preformatted) { 548 $line =~ s/^\s*//; 549 } 550 if ($line eq ""){ 551 if (! $output_preformatted) { 552 print $lineprefix, local_unescape($blankline); 553 } 554 } else { 555 $line =~ s/\\\\\\/\&/g; 556 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 557 print "\\&$line"; 558 } else { 559 print $lineprefix, $line; 560 } 561 } 562 print "\n"; 563 } 564} 565 566# output sections in html 567sub output_section_html(%) { 568 my %args = %{$_[0]}; 569 my $section; 570 571 foreach $section (@{$args{'sectionlist'}}) { 572 print "<h3>$section</h3>\n"; 573 print "<blockquote>\n"; 574 output_highlight($args{'sections'}{$section}); 575 print "</blockquote>\n"; 576 } 577} 578 579# output enum in html 580sub output_enum_html(%) { 581 my %args = %{$_[0]}; 582 my ($parameter); 583 my $count; 584 print "<h2>enum " . $args{'enum'} . "</h2>\n"; 585 586 print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; 587 $count = 0; 588 foreach $parameter (@{$args{'parameterlist'}}) { 589 print " <b>" . $parameter . "</b>"; 590 if ($count != $#{$args{'parameterlist'}}) { 591 $count++; 592 print ",\n"; 593 } 594 print "<br>"; 595 } 596 print "};<br>\n"; 597 598 print "<h3>Constants</h3>\n"; 599 print "<dl>\n"; 600 foreach $parameter (@{$args{'parameterlist'}}) { 601 print "<dt><b>" . $parameter . "</b>\n"; 602 print "<dd>"; 603 output_highlight($args{'parameterdescs'}{$parameter}); 604 } 605 print "</dl>\n"; 606 output_section_html(@_); 607 print "<hr>\n"; 608} 609 610# output typedef in html 611sub output_typedef_html(%) { 612 my %args = %{$_[0]}; 613 my ($parameter); 614 my $count; 615 print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; 616 617 print "<b>typedef " . $args{'typedef'} . "</b>\n"; 618 output_section_html(@_); 619 print "<hr>\n"; 620} 621 622# output struct in html 623sub output_struct_html(%) { 624 my %args = %{$_[0]}; 625 my ($parameter); 626 627 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; 628 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; 629 foreach $parameter (@{$args{'parameterlist'}}) { 630 if ($parameter =~ /^#/) { 631 print "$parameter<br>\n"; 632 next; 633 } 634 my $parameter_name = $parameter; 635 $parameter_name =~ s/\[.*//; 636 637 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 638 $type = $args{'parametertypes'}{$parameter}; 639 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 640 # pointer-to-function 641 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; 642 } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 643 # bitfield 644 print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; 645 } else { 646 print " <i>$type</i> <b>$parameter</b>;<br>\n"; 647 } 648 } 649 print "};<br>\n"; 650 651 print "<h3>Members</h3>\n"; 652 print "<dl>\n"; 653 foreach $parameter (@{$args{'parameterlist'}}) { 654 ($parameter =~ /^#/) && next; 655 656 my $parameter_name = $parameter; 657 $parameter_name =~ s/\[.*//; 658 659 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 660 print "<dt><b>" . $parameter . "</b>\n"; 661 print "<dd>"; 662 output_highlight($args{'parameterdescs'}{$parameter_name}); 663 } 664 print "</dl>\n"; 665 output_section_html(@_); 666 print "<hr>\n"; 667} 668 669# output function in html 670sub output_function_html(%) { 671 my %args = %{$_[0]}; 672 my ($parameter, $section); 673 my $count; 674 675 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; 676 print "<i>" . $args{'functiontype'} . "</i>\n"; 677 print "<b>" . $args{'function'} . "</b>\n"; 678 print "("; 679 $count = 0; 680 foreach $parameter (@{$args{'parameterlist'}}) { 681 $type = $args{'parametertypes'}{$parameter}; 682 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 683 # pointer-to-function 684 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; 685 } else { 686 print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; 687 } 688 if ($count != $#{$args{'parameterlist'}}) { 689 $count++; 690 print ",\n"; 691 } 692 } 693 print ")\n"; 694 695 print "<h3>Arguments</h3>\n"; 696 print "<dl>\n"; 697 foreach $parameter (@{$args{'parameterlist'}}) { 698 my $parameter_name = $parameter; 699 $parameter_name =~ s/\[.*//; 700 701 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 702 print "<dt><b>" . $parameter . "</b>\n"; 703 print "<dd>"; 704 output_highlight($args{'parameterdescs'}{$parameter_name}); 705 } 706 print "</dl>\n"; 707 output_section_html(@_); 708 print "<hr>\n"; 709} 710 711# output DOC: block header in html 712sub output_blockhead_html(%) { 713 my %args = %{$_[0]}; 714 my ($parameter, $section); 715 my $count; 716 717 foreach $section (@{$args{'sectionlist'}}) { 718 print "<h3>$section</h3>\n"; 719 print "<ul>\n"; 720 output_highlight($args{'sections'}{$section}); 721 print "</ul>\n"; 722 } 723 print "<hr>\n"; 724} 725 726# output sections in html5 727sub output_section_html5(%) { 728 my %args = %{$_[0]}; 729 my $section; 730 731 foreach $section (@{$args{'sectionlist'}}) { 732 print "<section>\n"; 733 print "<h1>$section</h1>\n"; 734 print "<p>\n"; 735 output_highlight($args{'sections'}{$section}); 736 print "</p>\n"; 737 print "</section>\n"; 738 } 739} 740 741# output enum in html5 742sub output_enum_html5(%) { 743 my %args = %{$_[0]}; 744 my ($parameter); 745 my $count; 746 my $html5id; 747 748 $html5id = $args{'enum'}; 749 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 750 print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; 751 print "<h1>enum " . $args{'enum'} . "</h1>\n"; 752 print "<ol class=\"code\">\n"; 753 print "<li>"; 754 print "<span class=\"keyword\">enum</span> "; 755 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; 756 print "</li>\n"; 757 $count = 0; 758 foreach $parameter (@{$args{'parameterlist'}}) { 759 print "<li class=\"indent\">"; 760 print "<span class=\"param\">" . $parameter . "</span>"; 761 if ($count != $#{$args{'parameterlist'}}) { 762 $count++; 763 print ","; 764 } 765 print "</li>\n"; 766 } 767 print "<li>};</li>\n"; 768 print "</ol>\n"; 769 770 print "<section>\n"; 771 print "<h1>Constants</h1>\n"; 772 print "<dl>\n"; 773 foreach $parameter (@{$args{'parameterlist'}}) { 774 print "<dt>" . $parameter . "</dt>\n"; 775 print "<dd>"; 776 output_highlight($args{'parameterdescs'}{$parameter}); 777 print "</dd>\n"; 778 } 779 print "</dl>\n"; 780 print "</section>\n"; 781 output_section_html5(@_); 782 print "</article>\n"; 783} 784 785# output typedef in html5 786sub output_typedef_html5(%) { 787 my %args = %{$_[0]}; 788 my ($parameter); 789 my $count; 790 my $html5id; 791 792 $html5id = $args{'typedef'}; 793 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 794 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; 795 print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; 796 797 print "<ol class=\"code\">\n"; 798 print "<li>"; 799 print "<span class=\"keyword\">typedef</span> "; 800 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; 801 print "</li>\n"; 802 print "</ol>\n"; 803 output_section_html5(@_); 804 print "</article>\n"; 805} 806 807# output struct in html5 808sub output_struct_html5(%) { 809 my %args = %{$_[0]}; 810 my ($parameter); 811 my $html5id; 812 813 $html5id = $args{'struct'}; 814 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 815 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n"; 816 print "<hgroup>\n"; 817 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>"; 818 print "<h2>". $args{'purpose'} . "</h2>\n"; 819 print "</hgroup>\n"; 820 print "<ol class=\"code\">\n"; 821 print "<li>"; 822 print "<span class=\"type\">" . $args{'type'} . "</span> "; 823 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {"; 824 print "</li>\n"; 825 foreach $parameter (@{$args{'parameterlist'}}) { 826 print "<li class=\"indent\">"; 827 if ($parameter =~ /^#/) { 828 print "<span class=\"param\">" . $parameter ."</span>\n"; 829 print "</li>\n"; 830 next; 831 } 832 my $parameter_name = $parameter; 833 $parameter_name =~ s/\[.*//; 834 835 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 836 $type = $args{'parametertypes'}{$parameter}; 837 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 838 # pointer-to-function 839 print "<span class=\"type\">$1</span> "; 840 print "<span class=\"param\">$parameter</span>"; 841 print "<span class=\"type\">)</span> "; 842 print "(<span class=\"args\">$2</span>);"; 843 } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 844 # bitfield 845 print "<span class=\"type\">$1</span> "; 846 print "<span class=\"param\">$parameter</span>"; 847 print "<span class=\"bits\">$2</span>;"; 848 } else { 849 print "<span class=\"type\">$type</span> "; 850 print "<span class=\"param\">$parameter</span>;"; 851 } 852 print "</li>\n"; 853 } 854 print "<li>};</li>\n"; 855 print "</ol>\n"; 856 857 print "<section>\n"; 858 print "<h1>Members</h1>\n"; 859 print "<dl>\n"; 860 foreach $parameter (@{$args{'parameterlist'}}) { 861 ($parameter =~ /^#/) && next; 862 863 my $parameter_name = $parameter; 864 $parameter_name =~ s/\[.*//; 865 866 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 867 print "<dt>" . $parameter . "</dt>\n"; 868 print "<dd>"; 869 output_highlight($args{'parameterdescs'}{$parameter_name}); 870 print "</dd>\n"; 871 } 872 print "</dl>\n"; 873 print "</section>\n"; 874 output_section_html5(@_); 875 print "</article>\n"; 876} 877 878# output function in html5 879sub output_function_html5(%) { 880 my %args = %{$_[0]}; 881 my ($parameter, $section); 882 my $count; 883 my $html5id; 884 885 $html5id = $args{'function'}; 886 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 887 print "<article class=\"function\" id=\"func:". $html5id . "\">\n"; 888 print "<hgroup>\n"; 889 print "<h1>" . $args{'function'} . "</h1>"; 890 print "<h2>" . $args{'purpose'} . "</h2>\n"; 891 print "</hgroup>\n"; 892 print "<ol class=\"code\">\n"; 893 print "<li>"; 894 print "<span class=\"type\">" . $args{'functiontype'} . "</span> "; 895 print "<span class=\"identifier\">" . $args{'function'} . "</span> ("; 896 print "</li>"; 897 $count = 0; 898 foreach $parameter (@{$args{'parameterlist'}}) { 899 print "<li class=\"indent\">"; 900 $type = $args{'parametertypes'}{$parameter}; 901 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 902 # pointer-to-function 903 print "<span class=\"type\">$1</span> "; 904 print "<span class=\"param\">$parameter</span>"; 905 print "<span class=\"type\">)</span> "; 906 print "(<span class=\"args\">$2</span>)"; 907 } else { 908 print "<span class=\"type\">$type</span> "; 909 print "<span class=\"param\">$parameter</span>"; 910 } 911 if ($count != $#{$args{'parameterlist'}}) { 912 $count++; 913 print ","; 914 } 915 print "</li>\n"; 916 } 917 print "<li>)</li>\n"; 918 print "</ol>\n"; 919 920 print "<section>\n"; 921 print "<h1>Arguments</h1>\n"; 922 print "<p>\n"; 923 print "<dl>\n"; 924 foreach $parameter (@{$args{'parameterlist'}}) { 925 my $parameter_name = $parameter; 926 $parameter_name =~ s/\[.*//; 927 928 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 929 print "<dt>" . $parameter . "</dt>\n"; 930 print "<dd>"; 931 output_highlight($args{'parameterdescs'}{$parameter_name}); 932 print "</dd>\n"; 933 } 934 print "</dl>\n"; 935 print "</section>\n"; 936 output_section_html5(@_); 937 print "</article>\n"; 938} 939 940# output DOC: block header in html5 941sub output_blockhead_html5(%) { 942 my %args = %{$_[0]}; 943 my ($parameter, $section); 944 my $count; 945 my $html5id; 946 947 foreach $section (@{$args{'sectionlist'}}) { 948 $html5id = $section; 949 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 950 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n"; 951 print "<h1>$section</h1>\n"; 952 print "<p>\n"; 953 output_highlight($args{'sections'}{$section}); 954 print "</p>\n"; 955 } 956 print "</article>\n"; 957} 958 959sub output_section_xml(%) { 960 my %args = %{$_[0]}; 961 my $section; 962 # print out each section 963 $lineprefix=" "; 964 foreach $section (@{$args{'sectionlist'}}) { 965 print "<refsect1>\n"; 966 print "<title>$section</title>\n"; 967 if ($section =~ m/EXAMPLE/i) { 968 print "<informalexample><programlisting>\n"; 969 $output_preformatted = 1; 970 } else { 971 print "<para>\n"; 972 } 973 output_highlight($args{'sections'}{$section}); 974 $output_preformatted = 0; 975 if ($section =~ m/EXAMPLE/i) { 976 print "</programlisting></informalexample>\n"; 977 } else { 978 print "</para>\n"; 979 } 980 print "</refsect1>\n"; 981 } 982} 983 984# output function in XML DocBook 985sub output_function_xml(%) { 986 my %args = %{$_[0]}; 987 my ($parameter, $section); 988 my $count; 989 my $id; 990 991 $id = "API-" . $args{'function'}; 992 $id =~ s/[^A-Za-z0-9]/-/g; 993 994 print "<refentry id=\"$id\">\n"; 995 print "<refentryinfo>\n"; 996 print " <title>LINUX</title>\n"; 997 print " <productname>Kernel Hackers Manual</productname>\n"; 998 print " <date>$man_date</date>\n"; 999 print "</refentryinfo>\n"; 1000 print "<refmeta>\n"; 1001 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; 1002 print " <manvolnum>9</manvolnum>\n"; 1003 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 1004 print "</refmeta>\n"; 1005 print "<refnamediv>\n"; 1006 print " <refname>" . $args{'function'} . "</refname>\n"; 1007 print " <refpurpose>\n"; 1008 print " "; 1009 output_highlight ($args{'purpose'}); 1010 print " </refpurpose>\n"; 1011 print "</refnamediv>\n"; 1012 1013 print "<refsynopsisdiv>\n"; 1014 print " <title>Synopsis</title>\n"; 1015 print " <funcsynopsis><funcprototype>\n"; 1016 print " <funcdef>" . $args{'functiontype'} . " "; 1017 print "<function>" . $args{'function'} . " </function></funcdef>\n"; 1018 1019 $count = 0; 1020 if ($#{$args{'parameterlist'}} >= 0) { 1021 foreach $parameter (@{$args{'parameterlist'}}) { 1022 $type = $args{'parametertypes'}{$parameter}; 1023 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1024 # pointer-to-function 1025 print " <paramdef>$1<parameter>$parameter</parameter>)\n"; 1026 print " <funcparams>$2</funcparams></paramdef>\n"; 1027 } else { 1028 print " <paramdef>" . $type; 1029 print " <parameter>$parameter</parameter></paramdef>\n"; 1030 } 1031 } 1032 } else { 1033 print " <void/>\n"; 1034 } 1035 print " </funcprototype></funcsynopsis>\n"; 1036 print "</refsynopsisdiv>\n"; 1037 1038 # print parameters 1039 print "<refsect1>\n <title>Arguments</title>\n"; 1040 if ($#{$args{'parameterlist'}} >= 0) { 1041 print " <variablelist>\n"; 1042 foreach $parameter (@{$args{'parameterlist'}}) { 1043 my $parameter_name = $parameter; 1044 $parameter_name =~ s/\[.*//; 1045 1046 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; 1047 print " <listitem>\n <para>\n"; 1048 $lineprefix=" "; 1049 output_highlight($args{'parameterdescs'}{$parameter_name}); 1050 print " </para>\n </listitem>\n </varlistentry>\n"; 1051 } 1052 print " </variablelist>\n"; 1053 } else { 1054 print " <para>\n None\n </para>\n"; 1055 } 1056 print "</refsect1>\n"; 1057 1058 output_section_xml(@_); 1059 print "</refentry>\n\n"; 1060} 1061 1062# output struct in XML DocBook 1063sub output_struct_xml(%) { 1064 my %args = %{$_[0]}; 1065 my ($parameter, $section); 1066 my $id; 1067 1068 $id = "API-struct-" . $args{'struct'}; 1069 $id =~ s/[^A-Za-z0-9]/-/g; 1070 1071 print "<refentry id=\"$id\">\n"; 1072 print "<refentryinfo>\n"; 1073 print " <title>LINUX</title>\n"; 1074 print " <productname>Kernel Hackers Manual</productname>\n"; 1075 print " <date>$man_date</date>\n"; 1076 print "</refentryinfo>\n"; 1077 print "<refmeta>\n"; 1078 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; 1079 print " <manvolnum>9</manvolnum>\n"; 1080 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 1081 print "</refmeta>\n"; 1082 print "<refnamediv>\n"; 1083 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; 1084 print " <refpurpose>\n"; 1085 print " "; 1086 output_highlight ($args{'purpose'}); 1087 print " </refpurpose>\n"; 1088 print "</refnamediv>\n"; 1089 1090 print "<refsynopsisdiv>\n"; 1091 print " <title>Synopsis</title>\n"; 1092 print " <programlisting>\n"; 1093 print $args{'type'} . " " . $args{'struct'} . " {\n"; 1094 foreach $parameter (@{$args{'parameterlist'}}) { 1095 if ($parameter =~ /^#/) { 1096 my $prm = $parameter; 1097 # convert data read & converted thru xml_escape() into &xyz; format: 1098 # This allows us to have #define macros interspersed in a struct. 1099 $prm =~ s/\\\\\\/\&/g; 1100 print "$prm\n"; 1101 next; 1102 } 1103 1104 my $parameter_name = $parameter; 1105 $parameter_name =~ s/\[.*//; 1106 1107 defined($args{'parameterdescs'}{$parameter_name}) || next; 1108 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1109 $type = $args{'parametertypes'}{$parameter}; 1110 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1111 # pointer-to-function 1112 print " $1 $parameter) ($2);\n"; 1113 } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 1114 # bitfield 1115 print " $1 $parameter$2;\n"; 1116 } else { 1117 print " " . $type . " " . $parameter . ";\n"; 1118 } 1119 } 1120 print "};"; 1121 print " </programlisting>\n"; 1122 print "</refsynopsisdiv>\n"; 1123 1124 print " <refsect1>\n"; 1125 print " <title>Members</title>\n"; 1126 1127 if ($#{$args{'parameterlist'}} >= 0) { 1128 print " <variablelist>\n"; 1129 foreach $parameter (@{$args{'parameterlist'}}) { 1130 ($parameter =~ /^#/) && next; 1131 1132 my $parameter_name = $parameter; 1133 $parameter_name =~ s/\[.*//; 1134 1135 defined($args{'parameterdescs'}{$parameter_name}) || next; 1136 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1137 print " <varlistentry>"; 1138 print " <term>$parameter</term>\n"; 1139 print " <listitem><para>\n"; 1140 output_highlight($args{'parameterdescs'}{$parameter_name}); 1141 print " </para></listitem>\n"; 1142 print " </varlistentry>\n"; 1143 } 1144 print " </variablelist>\n"; 1145 } else { 1146 print " <para>\n None\n </para>\n"; 1147 } 1148 print " </refsect1>\n"; 1149 1150 output_section_xml(@_); 1151 1152 print "</refentry>\n\n"; 1153} 1154 1155# output enum in XML DocBook 1156sub output_enum_xml(%) { 1157 my %args = %{$_[0]}; 1158 my ($parameter, $section); 1159 my $count; 1160 my $id; 1161 1162 $id = "API-enum-" . $args{'enum'}; 1163 $id =~ s/[^A-Za-z0-9]/-/g; 1164 1165 print "<refentry id=\"$id\">\n"; 1166 print "<refentryinfo>\n"; 1167 print " <title>LINUX</title>\n"; 1168 print " <productname>Kernel Hackers Manual</productname>\n"; 1169 print " <date>$man_date</date>\n"; 1170 print "</refentryinfo>\n"; 1171 print "<refmeta>\n"; 1172 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; 1173 print " <manvolnum>9</manvolnum>\n"; 1174 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 1175 print "</refmeta>\n"; 1176 print "<refnamediv>\n"; 1177 print " <refname>enum " . $args{'enum'} . "</refname>\n"; 1178 print " <refpurpose>\n"; 1179 print " "; 1180 output_highlight ($args{'purpose'}); 1181 print " </refpurpose>\n"; 1182 print "</refnamediv>\n"; 1183 1184 print "<refsynopsisdiv>\n"; 1185 print " <title>Synopsis</title>\n"; 1186 print " <programlisting>\n"; 1187 print "enum " . $args{'enum'} . " {\n"; 1188 $count = 0; 1189 foreach $parameter (@{$args{'parameterlist'}}) { 1190 print " $parameter"; 1191 if ($count != $#{$args{'parameterlist'}}) { 1192 $count++; 1193 print ","; 1194 } 1195 print "\n"; 1196 } 1197 print "};"; 1198 print " </programlisting>\n"; 1199 print "</refsynopsisdiv>\n"; 1200 1201 print "<refsect1>\n"; 1202 print " <title>Constants</title>\n"; 1203 print " <variablelist>\n"; 1204 foreach $parameter (@{$args{'parameterlist'}}) { 1205 my $parameter_name = $parameter; 1206 $parameter_name =~ s/\[.*//; 1207 1208 print " <varlistentry>"; 1209 print " <term>$parameter</term>\n"; 1210 print " <listitem><para>\n"; 1211 output_highlight($args{'parameterdescs'}{$parameter_name}); 1212 print " </para></listitem>\n"; 1213 print " </varlistentry>\n"; 1214 } 1215 print " </variablelist>\n"; 1216 print "</refsect1>\n"; 1217 1218 output_section_xml(@_); 1219 1220 print "</refentry>\n\n"; 1221} 1222 1223# output typedef in XML DocBook 1224sub output_typedef_xml(%) { 1225 my %args = %{$_[0]}; 1226 my ($parameter, $section); 1227 my $id; 1228 1229 $id = "API-typedef-" . $args{'typedef'}; 1230 $id =~ s/[^A-Za-z0-9]/-/g; 1231 1232 print "<refentry id=\"$id\">\n"; 1233 print "<refentryinfo>\n"; 1234 print " <title>LINUX</title>\n"; 1235 print " <productname>Kernel Hackers Manual</productname>\n"; 1236 print " <date>$man_date</date>\n"; 1237 print "</refentryinfo>\n"; 1238 print "<refmeta>\n"; 1239 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; 1240 print " <manvolnum>9</manvolnum>\n"; 1241 print "</refmeta>\n"; 1242 print "<refnamediv>\n"; 1243 print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; 1244 print " <refpurpose>\n"; 1245 print " "; 1246 output_highlight ($args{'purpose'}); 1247 print " </refpurpose>\n"; 1248 print "</refnamediv>\n"; 1249 1250 print "<refsynopsisdiv>\n"; 1251 print " <title>Synopsis</title>\n"; 1252 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; 1253 print "</refsynopsisdiv>\n"; 1254 1255 output_section_xml(@_); 1256 1257 print "</refentry>\n\n"; 1258} 1259 1260# output in XML DocBook 1261sub output_blockhead_xml(%) { 1262 my %args = %{$_[0]}; 1263 my ($parameter, $section); 1264 my $count; 1265 1266 my $id = $args{'module'}; 1267 $id =~ s/[^A-Za-z0-9]/-/g; 1268 1269 # print out each section 1270 $lineprefix=" "; 1271 foreach $section (@{$args{'sectionlist'}}) { 1272 if (!$args{'content-only'}) { 1273 print "<refsect1>\n <title>$section</title>\n"; 1274 } 1275 if ($section =~ m/EXAMPLE/i) { 1276 print "<example><para>\n"; 1277 $output_preformatted = 1; 1278 } else { 1279 print "<para>\n"; 1280 } 1281 output_highlight($args{'sections'}{$section}); 1282 $output_preformatted = 0; 1283 if ($section =~ m/EXAMPLE/i) { 1284 print "</para></example>\n"; 1285 } else { 1286 print "</para>"; 1287 } 1288 if (!$args{'content-only'}) { 1289 print "\n</refsect1>\n"; 1290 } 1291 } 1292 1293 print "\n\n"; 1294} 1295 1296# output in XML DocBook 1297sub output_function_gnome { 1298 my %args = %{$_[0]}; 1299 my ($parameter, $section); 1300 my $count; 1301 my $id; 1302 1303 $id = $args{'module'} . "-" . $args{'function'}; 1304 $id =~ s/[^A-Za-z0-9]/-/g; 1305 1306 print "<sect2>\n"; 1307 print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; 1308 1309 print " <funcsynopsis>\n"; 1310 print " <funcdef>" . $args{'functiontype'} . " "; 1311 print "<function>" . $args{'function'} . " "; 1312 print "</function></funcdef>\n"; 1313 1314 $count = 0; 1315 if ($#{$args{'parameterlist'}} >= 0) { 1316 foreach $parameter (@{$args{'parameterlist'}}) { 1317 $type = $args{'parametertypes'}{$parameter}; 1318 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1319 # pointer-to-function 1320 print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; 1321 print " <funcparams>$2</funcparams></paramdef>\n"; 1322 } else { 1323 print " <paramdef>" . $type; 1324 print " <parameter>$parameter</parameter></paramdef>\n"; 1325 } 1326 } 1327 } else { 1328 print " <void>\n"; 1329 } 1330 print " </funcsynopsis>\n"; 1331 if ($#{$args{'parameterlist'}} >= 0) { 1332 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; 1333 print "<tgroup cols=\"2\">\n"; 1334 print "<colspec colwidth=\"2*\">\n"; 1335 print "<colspec colwidth=\"8*\">\n"; 1336 print "<tbody>\n"; 1337 foreach $parameter (@{$args{'parameterlist'}}) { 1338 my $parameter_name = $parameter; 1339 $parameter_name =~ s/\[.*//; 1340 1341 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; 1342 print " <entry>\n"; 1343 $lineprefix=" "; 1344 output_highlight($args{'parameterdescs'}{$parameter_name}); 1345 print " </entry></row>\n"; 1346 } 1347 print " </tbody></tgroup></informaltable>\n"; 1348 } else { 1349 print " <para>\n None\n </para>\n"; 1350 } 1351 1352 # print out each section 1353 $lineprefix=" "; 1354 foreach $section (@{$args{'sectionlist'}}) { 1355 print "<simplesect>\n <title>$section</title>\n"; 1356 if ($section =~ m/EXAMPLE/i) { 1357 print "<example><programlisting>\n"; 1358 $output_preformatted = 1; 1359 } else { 1360 } 1361 print "<para>\n"; 1362 output_highlight($args{'sections'}{$section}); 1363 $output_preformatted = 0; 1364 print "</para>\n"; 1365 if ($section =~ m/EXAMPLE/i) { 1366 print "</programlisting></example>\n"; 1367 } else { 1368 } 1369 print " </simplesect>\n"; 1370 } 1371 1372 print "</sect2>\n\n"; 1373} 1374 1375## 1376# output function in man 1377sub output_function_man(%) { 1378 my %args = %{$_[0]}; 1379 my ($parameter, $section); 1380 my $count; 1381 1382 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 1383 1384 print ".SH NAME\n"; 1385 print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 1386 1387 print ".SH SYNOPSIS\n"; 1388 if ($args{'functiontype'} ne "") { 1389 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 1390 } else { 1391 print ".B \"" . $args{'function'} . "\n"; 1392 } 1393 $count = 0; 1394 my $parenth = "("; 1395 my $post = ","; 1396 foreach my $parameter (@{$args{'parameterlist'}}) { 1397 if ($count == $#{$args{'parameterlist'}}) { 1398 $post = ");"; 1399 } 1400 $type = $args{'parametertypes'}{$parameter}; 1401 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1402 # pointer-to-function 1403 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 1404 } else { 1405 $type =~ s/([^\*])$/$1 /; 1406 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 1407 } 1408 $count++; 1409 $parenth = ""; 1410 } 1411 1412 print ".SH ARGUMENTS\n"; 1413 foreach $parameter (@{$args{'parameterlist'}}) { 1414 my $parameter_name = $parameter; 1415 $parameter_name =~ s/\[.*//; 1416 1417 print ".IP \"" . $parameter . "\" 12\n"; 1418 output_highlight($args{'parameterdescs'}{$parameter_name}); 1419 } 1420 foreach $section (@{$args{'sectionlist'}}) { 1421 print ".SH \"", uc $section, "\"\n"; 1422 output_highlight($args{'sections'}{$section}); 1423 } 1424} 1425 1426## 1427# output enum in man 1428sub output_enum_man(%) { 1429 my %args = %{$_[0]}; 1430 my ($parameter, $section); 1431 my $count; 1432 1433 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 1434 1435 print ".SH NAME\n"; 1436 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 1437 1438 print ".SH SYNOPSIS\n"; 1439 print "enum " . $args{'enum'} . " {\n"; 1440 $count = 0; 1441 foreach my $parameter (@{$args{'parameterlist'}}) { 1442 print ".br\n.BI \" $parameter\"\n"; 1443 if ($count == $#{$args{'parameterlist'}}) { 1444 print "\n};\n"; 1445 last; 1446 } 1447 else { 1448 print ", \n.br\n"; 1449 } 1450 $count++; 1451 } 1452 1453 print ".SH Constants\n"; 1454 foreach $parameter (@{$args{'parameterlist'}}) { 1455 my $parameter_name = $parameter; 1456 $parameter_name =~ s/\[.*//; 1457 1458 print ".IP \"" . $parameter . "\" 12\n"; 1459 output_highlight($args{'parameterdescs'}{$parameter_name}); 1460 } 1461 foreach $section (@{$args{'sectionlist'}}) { 1462 print ".SH \"$section\"\n"; 1463 output_highlight($args{'sections'}{$section}); 1464 } 1465} 1466 1467## 1468# output struct in man 1469sub output_struct_man(%) { 1470 my %args = %{$_[0]}; 1471 my ($parameter, $section); 1472 1473 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 1474 1475 print ".SH NAME\n"; 1476 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 1477 1478 print ".SH SYNOPSIS\n"; 1479 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 1480 1481 foreach my $parameter (@{$args{'parameterlist'}}) { 1482 if ($parameter =~ /^#/) { 1483 print ".BI \"$parameter\"\n.br\n"; 1484 next; 1485 } 1486 my $parameter_name = $parameter; 1487 $parameter_name =~ s/\[.*//; 1488 1489 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1490 $type = $args{'parametertypes'}{$parameter}; 1491 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1492 # pointer-to-function 1493 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; 1494 } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 1495 # bitfield 1496 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; 1497 } else { 1498 $type =~ s/([^\*])$/$1 /; 1499 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; 1500 } 1501 print "\n.br\n"; 1502 } 1503 print "};\n.br\n"; 1504 1505 print ".SH Members\n"; 1506 foreach $parameter (@{$args{'parameterlist'}}) { 1507 ($parameter =~ /^#/) && next; 1508 1509 my $parameter_name = $parameter; 1510 $parameter_name =~ s/\[.*//; 1511 1512 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1513 print ".IP \"" . $parameter . "\" 12\n"; 1514 output_highlight($args{'parameterdescs'}{$parameter_name}); 1515 } 1516 foreach $section (@{$args{'sectionlist'}}) { 1517 print ".SH \"$section\"\n"; 1518 output_highlight($args{'sections'}{$section}); 1519 } 1520} 1521 1522## 1523# output typedef in man 1524sub output_typedef_man(%) { 1525 my %args = %{$_[0]}; 1526 my ($parameter, $section); 1527 1528 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 1529 1530 print ".SH NAME\n"; 1531 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 1532 1533 foreach $section (@{$args{'sectionlist'}}) { 1534 print ".SH \"$section\"\n"; 1535 output_highlight($args{'sections'}{$section}); 1536 } 1537} 1538 1539sub output_blockhead_man(%) { 1540 my %args = %{$_[0]}; 1541 my ($parameter, $section); 1542 my $count; 1543 1544 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 1545 1546 foreach $section (@{$args{'sectionlist'}}) { 1547 print ".SH \"$section\"\n"; 1548 output_highlight($args{'sections'}{$section}); 1549 } 1550} 1551 1552## 1553# output in text 1554sub output_function_text(%) { 1555 my %args = %{$_[0]}; 1556 my ($parameter, $section); 1557 my $start; 1558 1559 print "Name:\n\n"; 1560 print $args{'function'} . " - " . $args{'purpose'} . "\n"; 1561 1562 print "\nSynopsis:\n\n"; 1563 if ($args{'functiontype'} ne "") { 1564 $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1565 } else { 1566 $start = $args{'function'} . " ("; 1567 } 1568 print $start; 1569 1570 my $count = 0; 1571 foreach my $parameter (@{$args{'parameterlist'}}) { 1572 $type = $args{'parametertypes'}{$parameter}; 1573 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1574 # pointer-to-function 1575 print $1 . $parameter . ") (" . $2; 1576 } else { 1577 print $type . " " . $parameter; 1578 } 1579 if ($count != $#{$args{'parameterlist'}}) { 1580 $count++; 1581 print ",\n"; 1582 print " " x length($start); 1583 } else { 1584 print ");\n\n"; 1585 } 1586 } 1587 1588 print "Arguments:\n\n"; 1589 foreach $parameter (@{$args{'parameterlist'}}) { 1590 my $parameter_name = $parameter; 1591 $parameter_name =~ s/\[.*//; 1592 1593 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; 1594 } 1595 output_section_text(@_); 1596} 1597 1598#output sections in text 1599sub output_section_text(%) { 1600 my %args = %{$_[0]}; 1601 my $section; 1602 1603 print "\n"; 1604 foreach $section (@{$args{'sectionlist'}}) { 1605 print "$section:\n\n"; 1606 output_highlight($args{'sections'}{$section}); 1607 } 1608 print "\n\n"; 1609} 1610 1611# output enum in text 1612sub output_enum_text(%) { 1613 my %args = %{$_[0]}; 1614 my ($parameter); 1615 my $count; 1616 print "Enum:\n\n"; 1617 1618 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; 1619 print "enum " . $args{'enum'} . " {\n"; 1620 $count = 0; 1621 foreach $parameter (@{$args{'parameterlist'}}) { 1622 print "\t$parameter"; 1623 if ($count != $#{$args{'parameterlist'}}) { 1624 $count++; 1625 print ","; 1626 } 1627 print "\n"; 1628 } 1629 print "};\n\n"; 1630 1631 print "Constants:\n\n"; 1632 foreach $parameter (@{$args{'parameterlist'}}) { 1633 print "$parameter\n\t"; 1634 print $args{'parameterdescs'}{$parameter} . "\n"; 1635 } 1636 1637 output_section_text(@_); 1638} 1639 1640# output typedef in text 1641sub output_typedef_text(%) { 1642 my %args = %{$_[0]}; 1643 my ($parameter); 1644 my $count; 1645 print "Typedef:\n\n"; 1646 1647 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; 1648 output_section_text(@_); 1649} 1650 1651# output struct as text 1652sub output_struct_text(%) { 1653 my %args = %{$_[0]}; 1654 my ($parameter); 1655 1656 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; 1657 print $args{'type'} . " " . $args{'struct'} . " {\n"; 1658 foreach $parameter (@{$args{'parameterlist'}}) { 1659 if ($parameter =~ /^#/) { 1660 print "$parameter\n"; 1661 next; 1662 } 1663 1664 my $parameter_name = $parameter; 1665 $parameter_name =~ s/\[.*//; 1666 1667 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1668 $type = $args{'parametertypes'}{$parameter}; 1669 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1670 # pointer-to-function 1671 print "\t$1 $parameter) ($2);\n"; 1672 } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 1673 # bitfield 1674 print "\t$1 $parameter$2;\n"; 1675 } else { 1676 print "\t" . $type . " " . $parameter . ";\n"; 1677 } 1678 } 1679 print "};\n\n"; 1680 1681 print "Members:\n\n"; 1682 foreach $parameter (@{$args{'parameterlist'}}) { 1683 ($parameter =~ /^#/) && next; 1684 1685 my $parameter_name = $parameter; 1686 $parameter_name =~ s/\[.*//; 1687 1688 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1689 print "$parameter\n\t"; 1690 print $args{'parameterdescs'}{$parameter_name} . "\n"; 1691 } 1692 print "\n"; 1693 output_section_text(@_); 1694} 1695 1696sub output_blockhead_text(%) { 1697 my %args = %{$_[0]}; 1698 my ($parameter, $section); 1699 1700 foreach $section (@{$args{'sectionlist'}}) { 1701 print " $section:\n"; 1702 print " -> "; 1703 output_highlight($args{'sections'}{$section}); 1704 } 1705} 1706 1707## list mode output functions 1708 1709sub output_function_list(%) { 1710 my %args = %{$_[0]}; 1711 1712 print $args{'function'} . "\n"; 1713} 1714 1715# output enum in list 1716sub output_enum_list(%) { 1717 my %args = %{$_[0]}; 1718 print $args{'enum'} . "\n"; 1719} 1720 1721# output typedef in list 1722sub output_typedef_list(%) { 1723 my %args = %{$_[0]}; 1724 print $args{'typedef'} . "\n"; 1725} 1726 1727# output struct as list 1728sub output_struct_list(%) { 1729 my %args = %{$_[0]}; 1730 1731 print $args{'struct'} . "\n"; 1732} 1733 1734sub output_blockhead_list(%) { 1735 my %args = %{$_[0]}; 1736 my ($parameter, $section); 1737 1738 foreach $section (@{$args{'sectionlist'}}) { 1739 print "DOC: $section\n"; 1740 } 1741} 1742 1743## 1744# generic output function for all types (function, struct/union, typedef, enum); 1745# calls the generated, variable output_ function name based on 1746# functype and output_mode 1747sub output_declaration { 1748 no strict 'refs'; 1749 my $name = shift; 1750 my $functype = shift; 1751 my $func = "output_${functype}_$output_mode"; 1752 if (($function_only==0) || 1753 ( $function_only == 1 && defined($function_table{$name})) || 1754 ( $function_only == 2 && !($functype eq "function" && defined($function_table{$name})))) 1755 { 1756 &$func(@_); 1757 $section_counter++; 1758 } 1759} 1760 1761## 1762# generic output function - calls the right one based on current output mode. 1763sub output_blockhead { 1764 no strict 'refs'; 1765 my $func = "output_blockhead_" . $output_mode; 1766 &$func(@_); 1767 $section_counter++; 1768} 1769 1770## 1771# takes a declaration (struct, union, enum, typedef) and 1772# invokes the right handler. NOT called for functions. 1773sub dump_declaration($$) { 1774 no strict 'refs'; 1775 my ($prototype, $file) = @_; 1776 my $func = "dump_" . $decl_type; 1777 &$func(@_); 1778} 1779 1780sub dump_union($$) { 1781 dump_struct(@_); 1782} 1783 1784sub dump_struct($$) { 1785 my $x = shift; 1786 my $file = shift; 1787 my $nested; 1788 1789 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 1790 #my $decl_type = $1; 1791 $declaration_name = $2; 1792 my $members = $3; 1793 1794 # ignore embedded structs or unions 1795 $members =~ s/({.*})//g; 1796 $nested = $1; 1797 1798 # ignore members marked private: 1799 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 1800 $members =~ s/\/\*\s*private:.*//gosi; 1801 # strip comments: 1802 $members =~ s/\/\*.*?\*\///gos; 1803 $nested =~ s/\/\*.*?\*\///gos; 1804 # strip kmemcheck_bitfield_{begin,end}.*; 1805 $members =~ s/kmemcheck_bitfield_.*?;//gos; 1806 # strip attributes 1807 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 1808 $members =~ s/__aligned\s*\([^;]*\)//gos; 1809 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; 1810 # replace DECLARE_BITMAP 1811 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 1812 1813 create_parameterlist($members, ';', $file); 1814 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); 1815 1816 output_declaration($declaration_name, 1817 'struct', 1818 {'struct' => $declaration_name, 1819 'module' => $modulename, 1820 'parameterlist' => \@parameterlist, 1821 'parameterdescs' => \%parameterdescs, 1822 'parametertypes' => \%parametertypes, 1823 'sectionlist' => \@sectionlist, 1824 'sections' => \%sections, 1825 'purpose' => $declaration_purpose, 1826 'type' => $decl_type 1827 }); 1828 } 1829 else { 1830 print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 1831 ++$errors; 1832 } 1833} 1834 1835sub dump_enum($$) { 1836 my $x = shift; 1837 my $file = shift; 1838 1839 $x =~ s@/\*.*?\*/@@gos; # strip comments. 1840 # strip #define macros inside enums 1841 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 1842 1843 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 1844 $declaration_name = $1; 1845 my $members = $2; 1846 1847 foreach my $arg (split ',', $members) { 1848 $arg =~ s/^\s*(\w+).*/$1/; 1849 push @parameterlist, $arg; 1850 if (!$parameterdescs{$arg}) { 1851 $parameterdescs{$arg} = $undescribed; 1852 print STDERR "${file}:$.: warning: Enum value '$arg' ". 1853 "not described in enum '$declaration_name'\n"; 1854 } 1855 1856 } 1857 1858 output_declaration($declaration_name, 1859 'enum', 1860 {'enum' => $declaration_name, 1861 'module' => $modulename, 1862 'parameterlist' => \@parameterlist, 1863 'parameterdescs' => \%parameterdescs, 1864 'sectionlist' => \@sectionlist, 1865 'sections' => \%sections, 1866 'purpose' => $declaration_purpose 1867 }); 1868 } 1869 else { 1870 print STDERR "${file}:$.: error: Cannot parse enum!\n"; 1871 ++$errors; 1872 } 1873} 1874 1875sub dump_typedef($$) { 1876 my $x = shift; 1877 my $file = shift; 1878 1879 $x =~ s@/\*.*?\*/@@gos; # strip comments. 1880 1881 # Parse function prototypes 1882 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) { 1883 # Function typedefs 1884 $return_type = $1; 1885 $declaration_name = $2; 1886 my $args = $3; 1887 1888 create_parameterlist($args, ',', $file); 1889 1890 output_declaration($declaration_name, 1891 'function', 1892 {'function' => $declaration_name, 1893 'module' => $modulename, 1894 'functiontype' => $return_type, 1895 'parameterlist' => \@parameterlist, 1896 'parameterdescs' => \%parameterdescs, 1897 'parametertypes' => \%parametertypes, 1898 'sectionlist' => \@sectionlist, 1899 'sections' => \%sections, 1900 'purpose' => $declaration_purpose 1901 }); 1902 return; 1903 } 1904 1905 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 1906 $x =~ s/\(*.\)\s*;$/;/; 1907 $x =~ s/\[*.\]\s*;$/;/; 1908 } 1909 1910 if ($x =~ /typedef.*\s+(\w+)\s*;/) { 1911 $declaration_name = $1; 1912 1913 output_declaration($declaration_name, 1914 'typedef', 1915 {'typedef' => $declaration_name, 1916 'module' => $modulename, 1917 'sectionlist' => \@sectionlist, 1918 'sections' => \%sections, 1919 'purpose' => $declaration_purpose 1920 }); 1921 } 1922 else { 1923 print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 1924 ++$errors; 1925 } 1926} 1927 1928sub save_struct_actual($) { 1929 my $actual = shift; 1930 1931 # strip all spaces from the actual param so that it looks like one string item 1932 $actual =~ s/\s*//g; 1933 $struct_actual = $struct_actual . $actual . " "; 1934} 1935 1936sub create_parameterlist($$$) { 1937 my $args = shift; 1938 my $splitter = shift; 1939 my $file = shift; 1940 my $type; 1941 my $param; 1942 1943 # temporarily replace commas inside function pointer definition 1944 while ($args =~ /(\([^\),]+),/) { 1945 $args =~ s/(\([^\),]+),/$1#/g; 1946 } 1947 1948 foreach my $arg (split($splitter, $args)) { 1949 # strip comments 1950 $arg =~ s/\/\*.*\*\///; 1951 # strip leading/trailing spaces 1952 $arg =~ s/^\s*//; 1953 $arg =~ s/\s*$//; 1954 $arg =~ s/\s+/ /; 1955 1956 if ($arg =~ /^#/) { 1957 # Treat preprocessor directive as a typeless variable just to fill 1958 # corresponding data structures "correctly". Catch it later in 1959 # output_* subs. 1960 push_parameter($arg, "", $file); 1961 } elsif ($arg =~ m/\(.+\)\s*\(/) { 1962 # pointer-to-function 1963 $arg =~ tr/#/,/; 1964 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 1965 $param = $1; 1966 $type = $arg; 1967 $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1968 save_struct_actual($param); 1969 push_parameter($param, $type, $file); 1970 } elsif ($arg) { 1971 $arg =~ s/\s*:\s*/:/g; 1972 $arg =~ s/\s*\[/\[/g; 1973 1974 my @args = split('\s*,\s*', $arg); 1975 if ($args[0] =~ m/\*/) { 1976 $args[0] =~ s/(\*+)\s*/ $1/; 1977 } 1978 1979 my @first_arg; 1980 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1981 shift @args; 1982 push(@first_arg, split('\s+', $1)); 1983 push(@first_arg, $2); 1984 } else { 1985 @first_arg = split('\s+', shift @args); 1986 } 1987 1988 unshift(@args, pop @first_arg); 1989 $type = join " ", @first_arg; 1990 1991 foreach $param (@args) { 1992 if ($param =~ m/^(\*+)\s*(.*)/) { 1993 save_struct_actual($2); 1994 push_parameter($2, "$type $1", $file); 1995 } 1996 elsif ($param =~ m/(.*?):(\d+)/) { 1997 if ($type ne "") { # skip unnamed bit-fields 1998 save_struct_actual($1); 1999 push_parameter($1, "$type:$2", $file) 2000 } 2001 } 2002 else { 2003 save_struct_actual($param); 2004 push_parameter($param, $type, $file); 2005 } 2006 } 2007 } 2008 } 2009} 2010 2011sub push_parameter($$$) { 2012 my $param = shift; 2013 my $type = shift; 2014 my $file = shift; 2015 2016 if (($anon_struct_union == 1) && ($type eq "") && 2017 ($param eq "}")) { 2018 return; # ignore the ending }; from anon. struct/union 2019 } 2020 2021 $anon_struct_union = 0; 2022 my $param_name = $param; 2023 $param_name =~ s/\[.*//; 2024 2025 if ($type eq "" && $param =~ /\.\.\.$/) 2026 { 2027 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 2028 $parameterdescs{$param} = "variable arguments"; 2029 } 2030 } 2031 elsif ($type eq "" && ($param eq "" or $param eq "void")) 2032 { 2033 $param="void"; 2034 $parameterdescs{void} = "no arguments"; 2035 } 2036 elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 2037 # handle unnamed (anonymous) union or struct: 2038 { 2039 $type = $param; 2040 $param = "{unnamed_" . $param . "}"; 2041 $parameterdescs{$param} = "anonymous\n"; 2042 $anon_struct_union = 1; 2043 } 2044 2045 # warn if parameter has no description 2046 # (but ignore ones starting with # as these are not parameters 2047 # but inline preprocessor statements); 2048 # also ignore unnamed structs/unions; 2049 if (!$anon_struct_union) { 2050 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { 2051 2052 $parameterdescs{$param_name} = $undescribed; 2053 2054 if (($type eq 'function') || ($type eq 'enum')) { 2055 print STDERR "${file}:$.: warning: Function parameter ". 2056 "or member '$param' not " . 2057 "described in '$declaration_name'\n"; 2058 } 2059 print STDERR "${file}:$.: warning:" . 2060 " No description found for parameter '$param'\n"; 2061 ++$warnings; 2062 } 2063 } 2064 2065 $param = xml_escape($param); 2066 2067 # strip spaces from $param so that it is one continuous string 2068 # on @parameterlist; 2069 # this fixes a problem where check_sections() cannot find 2070 # a parameter like "addr[6 + 2]" because it actually appears 2071 # as "addr[6", "+", "2]" on the parameter list; 2072 # but it's better to maintain the param string unchanged for output, 2073 # so just weaken the string compare in check_sections() to ignore 2074 # "[blah" in a parameter string; 2075 ###$param =~ s/\s*//g; 2076 push @parameterlist, $param; 2077 $parametertypes{$param} = $type; 2078} 2079 2080sub check_sections($$$$$$) { 2081 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; 2082 my @sects = split ' ', $sectcheck; 2083 my @prms = split ' ', $prmscheck; 2084 my $err; 2085 my ($px, $sx); 2086 my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 2087 2088 foreach $sx (0 .. $#sects) { 2089 $err = 1; 2090 foreach $px (0 .. $#prms) { 2091 $prm_clean = $prms[$px]; 2092 $prm_clean =~ s/\[.*\]//; 2093 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 2094 # ignore array size in a parameter string; 2095 # however, the original param string may contain 2096 # spaces, e.g.: addr[6 + 2] 2097 # and this appears in @prms as "addr[6" since the 2098 # parameter list is split at spaces; 2099 # hence just ignore "[..." for the sections check; 2100 $prm_clean =~ s/\[.*//; 2101 2102 ##$prm_clean =~ s/^\**//; 2103 if ($prm_clean eq $sects[$sx]) { 2104 $err = 0; 2105 last; 2106 } 2107 } 2108 if ($err) { 2109 if ($decl_type eq "function") { 2110 print STDERR "${file}:$.: warning: " . 2111 "Excess function parameter " . 2112 "'$sects[$sx]' " . 2113 "description in '$decl_name'\n"; 2114 ++$warnings; 2115 } else { 2116 if ($nested !~ m/\Q$sects[$sx]\E/) { 2117 print STDERR "${file}:$.: warning: " . 2118 "Excess struct/union/enum/typedef member " . 2119 "'$sects[$sx]' " . 2120 "description in '$decl_name'\n"; 2121 ++$warnings; 2122 } 2123 } 2124 } 2125 } 2126} 2127 2128## 2129# Checks the section describing the return value of a function. 2130sub check_return_section { 2131 my $file = shift; 2132 my $declaration_name = shift; 2133 my $return_type = shift; 2134 2135 # Ignore an empty return type (It's a macro) 2136 # Ignore functions with a "void" return type. (But don't ignore "void *") 2137 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 2138 return; 2139 } 2140 2141 if (!defined($sections{$section_return}) || 2142 $sections{$section_return} eq "") { 2143 print STDERR "${file}:$.: warning: " . 2144 "No description found for return value of " . 2145 "'$declaration_name'\n"; 2146 ++$warnings; 2147 } 2148} 2149 2150## 2151# takes a function prototype and the name of the current file being 2152# processed and spits out all the details stored in the global 2153# arrays/hashes. 2154sub dump_function($$) { 2155 my $prototype = shift; 2156 my $file = shift; 2157 my $noret = 0; 2158 2159 $prototype =~ s/^static +//; 2160 $prototype =~ s/^extern +//; 2161 $prototype =~ s/^asmlinkage +//; 2162 $prototype =~ s/^inline +//; 2163 $prototype =~ s/^__inline__ +//; 2164 $prototype =~ s/^__inline +//; 2165 $prototype =~ s/^__always_inline +//; 2166 $prototype =~ s/^noinline +//; 2167 $prototype =~ s/__init +//; 2168 $prototype =~ s/__init_or_module +//; 2169 $prototype =~ s/__meminit +//; 2170 $prototype =~ s/__must_check +//; 2171 $prototype =~ s/__weak +//; 2172 my $define = $prototype =~ s/^#\s*define\s+//; #ak added 2173 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; 2174 2175 # Yes, this truly is vile. We are looking for: 2176 # 1. Return type (may be nothing if we're looking at a macro) 2177 # 2. Function name 2178 # 3. Function parameters. 2179 # 2180 # All the while we have to watch out for function pointer parameters 2181 # (which IIRC is what the two sections are for), C types (these 2182 # regexps don't even start to express all the possibilities), and 2183 # so on. 2184 # 2185 # If you mess with these regexps, it's a good idea to check that 2186 # the following functions' documentation still comes out right: 2187 # - parport_register_device (function pointer parameters) 2188 # - atomic_set (macro) 2189 # - pci_match_device, __copy_to_user (long return type) 2190 2191 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 2192 # This is an object-like macro, it has no return type and no parameter 2193 # list. 2194 # Function-like macros are not allowed to have spaces between 2195 # declaration_name and opening parenthesis (notice the \s+). 2196 $return_type = $1; 2197 $declaration_name = $2; 2198 $noret = 1; 2199 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 2200 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 2201 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 2202 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 2203 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 2204 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 2205 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 2206 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2207 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2208 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2209 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2210 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2211 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2212 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2213 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2214 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2215 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 2216 $return_type = $1; 2217 $declaration_name = $2; 2218 my $args = $3; 2219 2220 create_parameterlist($args, ',', $file); 2221 } else { 2222 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 2223 return; 2224 } 2225 2226 my $prms = join " ", @parameterlist; 2227 check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); 2228 2229 # This check emits a lot of warnings at the moment, because many 2230 # functions don't have a 'Return' doc section. So until the number 2231 # of warnings goes sufficiently down, the check is only performed in 2232 # verbose mode. 2233 # TODO: always perform the check. 2234 if ($verbose && !$noret) { 2235 check_return_section($file, $declaration_name, $return_type); 2236 } 2237 2238 output_declaration($declaration_name, 2239 'function', 2240 {'function' => $declaration_name, 2241 'module' => $modulename, 2242 'functiontype' => $return_type, 2243 'parameterlist' => \@parameterlist, 2244 'parameterdescs' => \%parameterdescs, 2245 'parametertypes' => \%parametertypes, 2246 'sectionlist' => \@sectionlist, 2247 'sections' => \%sections, 2248 'purpose' => $declaration_purpose 2249 }); 2250} 2251 2252sub reset_state { 2253 $function = ""; 2254 %constants = (); 2255 %parameterdescs = (); 2256 %parametertypes = (); 2257 @parameterlist = (); 2258 %sections = (); 2259 @sectionlist = (); 2260 $sectcheck = ""; 2261 $struct_actual = ""; 2262 $prototype = ""; 2263 2264 $state = 0; 2265 $split_doc_state = 0; 2266} 2267 2268sub tracepoint_munge($) { 2269 my $file = shift; 2270 my $tracepointname = 0; 2271 my $tracepointargs = 0; 2272 2273 if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 2274 $tracepointname = $1; 2275 } 2276 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 2277 $tracepointname = $1; 2278 } 2279 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 2280 $tracepointname = $2; 2281 } 2282 $tracepointname =~ s/^\s+//; #strip leading whitespace 2283 if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 2284 $tracepointargs = $1; 2285 } 2286 if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 2287 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 2288 "$prototype\n"; 2289 } else { 2290 $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 2291 } 2292} 2293 2294sub syscall_munge() { 2295 my $void = 0; 2296 2297 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs 2298## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 2299 if ($prototype =~ m/SYSCALL_DEFINE0/) { 2300 $void = 1; 2301## $prototype = "long sys_$1(void)"; 2302 } 2303 2304 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 2305 if ($prototype =~ m/long (sys_.*?),/) { 2306 $prototype =~ s/,/\(/; 2307 } elsif ($void) { 2308 $prototype =~ s/\)/\(void\)/; 2309 } 2310 2311 # now delete all of the odd-number commas in $prototype 2312 # so that arg types & arg names don't have a comma between them 2313 my $count = 0; 2314 my $len = length($prototype); 2315 if ($void) { 2316 $len = 0; # skip the for-loop 2317 } 2318 for (my $ix = 0; $ix < $len; $ix++) { 2319 if (substr($prototype, $ix, 1) eq ',') { 2320 $count++; 2321 if ($count % 2 == 1) { 2322 substr($prototype, $ix, 1) = ' '; 2323 } 2324 } 2325 } 2326} 2327 2328sub process_state3_function($$) { 2329 my $x = shift; 2330 my $file = shift; 2331 2332 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 2333 2334 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 2335 # do nothing 2336 } 2337 elsif ($x =~ /([^\{]*)/) { 2338 $prototype .= $1; 2339 } 2340 2341 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 2342 $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 2343 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 2344 $prototype =~ s@^\s+@@gos; # strip leading spaces 2345 if ($prototype =~ /SYSCALL_DEFINE/) { 2346 syscall_munge(); 2347 } 2348 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 2349 $prototype =~ /DEFINE_SINGLE_EVENT/) 2350 { 2351 tracepoint_munge($file); 2352 } 2353 dump_function($prototype, $file); 2354 reset_state(); 2355 } 2356} 2357 2358sub process_state3_type($$) { 2359 my $x = shift; 2360 my $file = shift; 2361 2362 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 2363 $x =~ s@^\s+@@gos; # strip leading spaces 2364 $x =~ s@\s+$@@gos; # strip trailing spaces 2365 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 2366 2367 if ($x =~ /^#/) { 2368 # To distinguish preprocessor directive from regular declaration later. 2369 $x .= ";"; 2370 } 2371 2372 while (1) { 2373 if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 2374 $prototype .= $1 . $2; 2375 ($2 eq '{') && $brcount++; 2376 ($2 eq '}') && $brcount--; 2377 if (($2 eq ';') && ($brcount == 0)) { 2378 dump_declaration($prototype, $file); 2379 reset_state(); 2380 last; 2381 } 2382 $x = $3; 2383 } else { 2384 $prototype .= $x; 2385 last; 2386 } 2387 } 2388} 2389 2390# xml_escape: replace <, >, and & in the text stream; 2391# 2392# however, formatting controls that are generated internally/locally in the 2393# kernel-doc script are not escaped here; instead, they begin life like 2394# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings 2395# are converted to their mnemonic-expected output, without the 4 * '\' & ':', 2396# just before actual output; (this is done by local_unescape()) 2397sub xml_escape($) { 2398 my $text = shift; 2399 if (($output_mode eq "text") || ($output_mode eq "man")) { 2400 return $text; 2401 } 2402 $text =~ s/\&/\\\\\\amp;/g; 2403 $text =~ s/\</\\\\\\lt;/g; 2404 $text =~ s/\>/\\\\\\gt;/g; 2405 return $text; 2406} 2407 2408# convert local escape strings to html 2409# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) 2410sub local_unescape($) { 2411 my $text = shift; 2412 if (($output_mode eq "text") || ($output_mode eq "man")) { 2413 return $text; 2414 } 2415 $text =~ s/\\\\\\\\lt:/</g; 2416 $text =~ s/\\\\\\\\gt:/>/g; 2417 return $text; 2418} 2419 2420sub process_file($) { 2421 my $file; 2422 my $identifier; 2423 my $func; 2424 my $descr; 2425 my $in_purpose = 0; 2426 my $initial_section_counter = $section_counter; 2427 my ($orig_file) = @_; 2428 2429 if (defined($ENV{'SRCTREE'})) { 2430 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 2431 } 2432 else { 2433 $file = $orig_file; 2434 } 2435 if (defined($source_map{$file})) { 2436 $file = $source_map{$file}; 2437 } 2438 2439 if (!open(IN,"<$file")) { 2440 print STDERR "Error: Cannot open file $file\n"; 2441 ++$errors; 2442 return; 2443 } 2444 2445 $. = 1; 2446 2447 $section_counter = 0; 2448 while (<IN>) { 2449 while (s/\\\s*$//) { 2450 $_ .= <IN>; 2451 } 2452 if ($state == 0) { 2453 if (/$doc_start/o) { 2454 $state = 1; # next line is always the function name 2455 $in_doc_sect = 0; 2456 } 2457 } elsif ($state == 1) { # this line is the function name (always) 2458 if (/$doc_block/o) { 2459 $state = 4; 2460 $contents = ""; 2461 if ( $1 eq "" ) { 2462 $section = $section_intro; 2463 } else { 2464 $section = $1; 2465 } 2466 } 2467 elsif (/$doc_decl/o) { 2468 $identifier = $1; 2469 if (/\s*([\w\s]+?)\s*-/) { 2470 $identifier = $1; 2471 } 2472 2473 $state = 2; 2474 if (/-(.*)/) { 2475 # strip leading/trailing/multiple spaces 2476 $descr= $1; 2477 $descr =~ s/^\s*//; 2478 $descr =~ s/\s*$//; 2479 $descr =~ s/\s+/ /g; 2480 $declaration_purpose = xml_escape($descr); 2481 $in_purpose = 1; 2482 } else { 2483 $declaration_purpose = ""; 2484 } 2485 2486 if (($declaration_purpose eq "") && $verbose) { 2487 print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 2488 print STDERR $_; 2489 ++$warnings; 2490 } 2491 2492 if ($identifier =~ m/^struct/) { 2493 $decl_type = 'struct'; 2494 } elsif ($identifier =~ m/^union/) { 2495 $decl_type = 'union'; 2496 } elsif ($identifier =~ m/^enum/) { 2497 $decl_type = 'enum'; 2498 } elsif ($identifier =~ m/^typedef/) { 2499 $decl_type = 'typedef'; 2500 } else { 2501 $decl_type = 'function'; 2502 } 2503 2504 if ($verbose) { 2505 print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; 2506 } 2507 } else { 2508 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 2509 " - I thought it was a doc line\n"; 2510 ++$warnings; 2511 $state = 0; 2512 } 2513 } elsif ($state == 2) { # look for head: lines, and include content 2514 if (/$doc_sect/o) { 2515 $newsection = $1; 2516 $newcontents = $2; 2517 2518 if (($contents ne "") && ($contents ne "\n")) { 2519 if (!$in_doc_sect && $verbose) { 2520 print STDERR "${file}:$.: warning: contents before sections\n"; 2521 ++$warnings; 2522 } 2523 dump_section($file, $section, xml_escape($contents)); 2524 $section = $section_default; 2525 } 2526 2527 $in_doc_sect = 1; 2528 $in_purpose = 0; 2529 $contents = $newcontents; 2530 if ($contents ne "") { 2531 while ((substr($contents, 0, 1) eq " ") || 2532 substr($contents, 0, 1) eq "\t") { 2533 $contents = substr($contents, 1); 2534 } 2535 $contents .= "\n"; 2536 } 2537 $section = $newsection; 2538 } elsif (/$doc_end/) { 2539 if (($contents ne "") && ($contents ne "\n")) { 2540 dump_section($file, $section, xml_escape($contents)); 2541 $section = $section_default; 2542 $contents = ""; 2543 } 2544 # look for doc_com + <text> + doc_end: 2545 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2546 print STDERR "${file}:$.: warning: suspicious ending line: $_"; 2547 ++$warnings; 2548 } 2549 2550 $prototype = ""; 2551 $state = 3; 2552 $brcount = 0; 2553# print STDERR "end of doc comment, looking for prototype\n"; 2554 } elsif (/$doc_content/) { 2555 # miguel-style comment kludge, look for blank lines after 2556 # @parameter line to signify start of description 2557 if ($1 eq "") { 2558 if ($section =~ m/^@/ || $section eq $section_context) { 2559 dump_section($file, $section, xml_escape($contents)); 2560 $section = $section_default; 2561 $contents = ""; 2562 } else { 2563 $contents .= "\n"; 2564 } 2565 $in_purpose = 0; 2566 } elsif ($in_purpose == 1) { 2567 # Continued declaration purpose 2568 chomp($declaration_purpose); 2569 $declaration_purpose .= " " . xml_escape($1); 2570 $declaration_purpose =~ s/\s+/ /g; 2571 } else { 2572 $contents .= $1 . "\n"; 2573 } 2574 } else { 2575 # i dont know - bad line? ignore. 2576 print STDERR "${file}:$.: warning: bad line: $_"; 2577 ++$warnings; 2578 } 2579 } elsif ($state == 5) { # scanning for split parameters 2580 # First line (state 1) needs to be a @parameter 2581 if ($split_doc_state == 1 && /$doc_split_sect/o) { 2582 $section = $1; 2583 $contents = $2; 2584 if ($contents ne "") { 2585 while ((substr($contents, 0, 1) eq " ") || 2586 substr($contents, 0, 1) eq "\t") { 2587 $contents = substr($contents, 1); 2588 } 2589 $contents .= "\n"; 2590 } 2591 $split_doc_state = 2; 2592 # Documentation block end */ 2593 } elsif (/$doc_split_end/) { 2594 if (($contents ne "") && ($contents ne "\n")) { 2595 dump_section($file, $section, xml_escape($contents)); 2596 $section = $section_default; 2597 $contents = ""; 2598 } 2599 $state = 3; 2600 $split_doc_state = 0; 2601 # Regular text 2602 } elsif (/$doc_content/) { 2603 if ($split_doc_state == 2) { 2604 $contents .= $1 . "\n"; 2605 } elsif ($split_doc_state == 1) { 2606 $split_doc_state = 4; 2607 print STDERR "Warning(${file}:$.): "; 2608 print STDERR "Incorrect use of kernel-doc format: $_"; 2609 ++$warnings; 2610 } 2611 } 2612 } elsif ($state == 3) { # scanning for function '{' (end of prototype) 2613 if (/$doc_split_start/) { 2614 $state = 5; 2615 $split_doc_state = 1; 2616 } elsif ($decl_type eq 'function') { 2617 process_state3_function($_, $file); 2618 } else { 2619 process_state3_type($_, $file); 2620 } 2621 } elsif ($state == 4) { 2622 # Documentation block 2623 if (/$doc_block/) { 2624 dump_doc_section($file, $section, xml_escape($contents)); 2625 $contents = ""; 2626 $function = ""; 2627 %constants = (); 2628 %parameterdescs = (); 2629 %parametertypes = (); 2630 @parameterlist = (); 2631 %sections = (); 2632 @sectionlist = (); 2633 $prototype = ""; 2634 if ( $1 eq "" ) { 2635 $section = $section_intro; 2636 } else { 2637 $section = $1; 2638 } 2639 } 2640 elsif (/$doc_end/) 2641 { 2642 dump_doc_section($file, $section, xml_escape($contents)); 2643 $contents = ""; 2644 $function = ""; 2645 %constants = (); 2646 %parameterdescs = (); 2647 %parametertypes = (); 2648 @parameterlist = (); 2649 %sections = (); 2650 @sectionlist = (); 2651 $prototype = ""; 2652 $state = 0; 2653 } 2654 elsif (/$doc_content/) 2655 { 2656 if ( $1 eq "" ) 2657 { 2658 $contents .= $blankline; 2659 } 2660 else 2661 { 2662 $contents .= $1 . "\n"; 2663 } 2664 } 2665 } 2666 } 2667 if ($initial_section_counter == $section_counter) { 2668 print STDERR "${file}:1: warning: no structured comments found\n"; 2669 if (($function_only == 1) && ($show_not_found == 1)) { 2670 print STDERR " Was looking for '$_'.\n" for keys %function_table; 2671 } 2672 if ($output_mode eq "xml") { 2673 # The template wants at least one RefEntry here; make one. 2674 print "<refentry>\n"; 2675 print " <refnamediv>\n"; 2676 print " <refname>\n"; 2677 print " ${orig_file}\n"; 2678 print " </refname>\n"; 2679 print " <refpurpose>\n"; 2680 print " Document generation inconsistency\n"; 2681 print " </refpurpose>\n"; 2682 print " </refnamediv>\n"; 2683 print " <refsect1>\n"; 2684 print " <title>\n"; 2685 print " Oops\n"; 2686 print " </title>\n"; 2687 print " <warning>\n"; 2688 print " <para>\n"; 2689 print " The template for this document tried to insert\n"; 2690 print " the structured comment from the file\n"; 2691 print " <filename>${orig_file}</filename> at this point,\n"; 2692 print " but none was found.\n"; 2693 print " This dummy section is inserted to allow\n"; 2694 print " generation to continue.\n"; 2695 print " </para>\n"; 2696 print " </warning>\n"; 2697 print " </refsect1>\n"; 2698 print "</refentry>\n"; 2699 } 2700 } 2701} 2702 2703 2704$kernelversion = get_kernel_version(); 2705 2706# generate a sequence of code that will splice in highlighting information 2707# using the s// operator. 2708for (my $k = 0; $k < @highlights; $k++) { 2709 my $pattern = $highlights[$k][0]; 2710 my $result = $highlights[$k][1]; 2711# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 2712 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 2713} 2714 2715# Read the file that maps relative names to absolute names for 2716# separate source and object directories and for shadow trees. 2717if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 2718 my ($relname, $absname); 2719 while(<SOURCE_MAP>) { 2720 chop(); 2721 ($relname, $absname) = (split())[0..1]; 2722 $relname =~ s:^/+::; 2723 $source_map{$relname} = $absname; 2724 } 2725 close(SOURCE_MAP); 2726} 2727 2728foreach (@ARGV) { 2729 chomp; 2730 process_file($_); 2731} 2732if ($verbose && $errors) { 2733 print STDERR "$errors errors\n"; 2734} 2735if ($verbose && $warnings) { 2736 print STDERR "$warnings warnings\n"; 2737} 2738 2739exit($errors); 2740