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