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