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