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