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