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