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