]> git.ipfire.org Git - thirdparty/kernel/linux.git/blame - scripts/kernel-doc
scripts: kernel-doc: fix typedef identification
[thirdparty/kernel/linux.git] / scripts / kernel-doc
CommitLineData
cb77f0d6 1#!/usr/bin/env perl
38476378 2# SPDX-License-Identifier: GPL-2.0
1da177e4 3
cb77f0d6 4use warnings;
1da177e4
LT
5use strict;
6
7## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ##
8## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ##
9## Copyright (C) 2001 Simon Huggins ##
70c95b00 10## Copyright (C) 2005-2012 Randy Dunlap ##
1b40c194 11## Copyright (C) 2012 Dan Luedtke ##
1da177e4
LT
12## ##
13## #define enhancements by Armin Kuster <akuster@mvista.com> ##
14## Copyright (c) 2000 MontaVista Software, Inc. ##
15## ##
16## This software falls under the GNU General Public License. ##
17## Please read the COPYING file for more information ##
18
1da177e4
LT
19# 18/01/2001 - Cleanups
20# Functions prototyped as foo(void) same as foo()
21# Stop eval'ing where we don't need to.
22# -- huggie@earth.li
23
24# 27/06/2001 - Allowed whitespace after initial "/**" and
25# allowed comments before function declarations.
26# -- Christian Kreibich <ck@whoop.org>
27
28# Still to do:
29# - add perldoc documentation
30# - Look more closely at some of the scarier bits :)
31
32# 26/05/2001 - Support for separate source and object trees.
33# Return error code.
34# Keith Owens <kaos@ocs.com.au>
35
36# 23/09/2001 - Added support for typedefs, structs, enums and unions
37# Support for Context section; can be terminated using empty line
38# Small fixes (like spaces vs. \s in regex)
39# -- Tim Jansen <tim@tjansen.de>
40
1b40c194
DL
41# 25/07/2012 - Added support for HTML5
42# -- Dan Luedtke <mail@danrl.de>
1da177e4 43
fadc0b31
JN
44sub usage {
45 my $message = <<"EOF";
46Usage: $0 [OPTION ...] FILE ...
47
48Read C language source or header FILEs, extract embedded documentation comments,
49and print formatted documentation to standard output.
50
51The documentation comments are identified by "/**" opening comment mark. See
857af3b7 52Documentation/doc-guide/kernel-doc.rst for the documentation comment syntax.
fadc0b31
JN
53
54Output format selection (mutually exclusive):
fadc0b31 55 -man Output troff manual page format. This is the default.
c0d1b6ee 56 -rst Output reStructuredText format.
3a025e1d 57 -none Do not output documentation, only warnings.
fadc0b31
JN
58
59Output selection (mutually exclusive):
86ae2e38
JN
60 -export Only output documentation for symbols that have been
61 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
c9b2cfb3 62 in any input FILE or -export-file FILE.
86ae2e38
JN
63 -internal Only output documentation for symbols that have NOT been
64 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
c9b2cfb3 65 in any input FILE or -export-file FILE.
fadc0b31
JN
66 -function NAME Only output documentation for the given function(s)
67 or DOC: section title(s). All other functions and DOC:
68 sections are ignored. May be specified multiple times.
eab795dd
MCC
69 -nosymbol NAME Exclude the specified symbols from the output
70 documentation. May be specified multiple times.
fadc0b31
JN
71
72Output selection modifiers:
73 -no-doc-sections Do not output DOC: sections.
0b0f5f29
DV
74 -enable-lineno Enable output of #define LINENO lines. Only works with
75 reStructuredText format.
88c2b57d
JN
76 -export-file FILE Specify an additional FILE in which to look for
77 EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with
78 -export or -internal. May be specified multiple times.
fadc0b31
JN
79
80Other parameters:
81 -v Verbose output, more warnings and other information.
82 -h Print this help.
2c12c810 83 -Werror Treat warnings as errors.
fadc0b31
JN
84
85EOF
86 print $message;
87 exit 1;
88}
1da177e4
LT
89
90#
91# format of comments.
92# In the following table, (...)? signifies optional structure.
93# (...)* signifies 0 or more structure elements
94# /**
95# * function_name(:)? (- short description)?
96# (* @parameterx: (description of parameter x)?)*
97# (* a blank line)?
98# * (Description:)? (Description of function)?
99# * (section header: (section description)? )*
100# (*)?*/
101#
102# So .. the trivial example would be:
103#
104# /**
105# * my_function
b9d97328 106# */
1da177e4 107#
891dcd2f 108# If the Description: header tag is omitted, then there must be a blank line
1da177e4
LT
109# after the last parameter specification.
110# e.g.
111# /**
112# * my_function - does my stuff
113# * @my_arg: its mine damnit
114# *
3c3b809e 115# * Does my stuff explained.
1da177e4
LT
116# */
117#
118# or, could also use:
119# /**
120# * my_function - does my stuff
121# * @my_arg: its mine damnit
3c3b809e 122# * Description: Does my stuff explained.
1da177e4
LT
123# */
124# etc.
125#
b9d97328 126# Besides functions you can also write documentation for structs, unions,
3c3b809e
RD
127# enums and typedefs. Instead of the function name you must write the name
128# of the declaration; the struct/union/enum/typedef must always precede
129# the name. Nesting of declarations is not supported.
1da177e4
LT
130# Use the argument mechanism to document members or constants.
131# e.g.
132# /**
133# * struct my_struct - short description
134# * @a: first member
135# * @b: second member
3c3b809e 136# *
1da177e4
LT
137# * Longer description
138# */
139# struct my_struct {
140# int a;
141# int b;
aeec46b9
MW
142# /* private: */
143# int c;
1da177e4
LT
144# };
145#
146# All descriptions can be multiline, except the short function description.
3c3b809e 147#
a4c6ebed
DCLP
148# For really longs structs, you can also describe arguments inside the
149# body of the struct.
150# eg.
151# /**
152# * struct my_struct - short description
153# * @a: first member
154# * @b: second member
155# *
156# * Longer description
157# */
158# struct my_struct {
159# int a;
160# int b;
161# /**
162# * @c: This is longer description of C
163# *
164# * You can use paragraphs to describe arguments
165# * using this method.
166# */
167# int c;
168# };
169#
170# This should be use only for struct/enum members.
171#
3c3b809e
RD
172# You can also add additional sections. When documenting kernel functions you
173# should document the "Context:" of the function, e.g. whether the functions
1da177e4 174# can be called form interrupts. Unlike other sections you can end it with an
3c3b809e 175# empty line.
4092bac7
YB
176# A non-void function should have a "Return:" section describing the return
177# value(s).
3c3b809e 178# Example-sections should contain the string EXAMPLE so that they are marked
1da177e4
LT
179# appropriately in DocBook.
180#
181# Example:
182# /**
183# * user_function - function that can only be called in user context
184# * @a: some argument
185# * Context: !in_interrupt()
3c3b809e 186# *
1da177e4
LT
187# * Some description
188# * Example:
189# * user_function(22);
190# */
191# ...
192#
193#
194# All descriptive text is further processed, scanning for the following special
195# patterns, which are highlighted appropriately.
196#
197# 'funcname()' - function
198# '$ENVVAR' - environmental variable
199# '&struct_name' - name of a structure (up to two words including 'struct')
5267dd35 200# '&struct_name.member' - name of a structure member
1da177e4
LT
201# '@parameter' - name of a parameter
202# '%CONST' - name of a constant.
b97f193a 203# '``LITERAL``' - literal string without any spaces on it.
1da177e4 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
b97f193a
MCC
212my $type_constant = '\b``([^\`]+)``\b';
213my $type_constant2 = '\%([-_\w]+)';
1da177e4 214my $type_func = '(\w+)\(\)';
bfd228c7 215my $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)';
ee2aa759 216my $type_param_ref = '([\!]?)\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)';
5219f18a 217my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params
346282db 218my $type_fp_param2 = '\@(\w+->\S+)\(\)'; # Special RST handling for structs with func ptr params
1da177e4 219my $type_env = '(\$\w+)';
df31175b
PB
220my $type_enum = '\&(enum\s*([_\w]+))';
221my $type_struct = '\&(struct\s*([_\w]+))';
222my $type_typedef = '\&(typedef\s*([_\w]+))';
223my $type_union = '\&(union\s*([_\w]+))';
5267dd35 224my $type_member = '\&([_\w]+)(\.|->)([_\w]+)';
df31175b 225my $type_fallback = '\&([_\w]+)';
f3341dcf 226my $type_member_func = $type_member . '\(\)';
1da177e4
LT
227
228# Output conversion substitutions.
229# One for each output format
230
1da177e4 231# these are pretty rough
4d732701
DCLP
232my @highlights_man = (
233 [$type_constant, "\$1"],
b97f193a 234 [$type_constant2, "\$1"],
4d732701 235 [$type_func, "\\\\fB\$1\\\\fP"],
df31175b 236 [$type_enum, "\\\\fI\$1\\\\fP"],
4d732701 237 [$type_struct, "\\\\fI\$1\\\\fP"],
df31175b
PB
238 [$type_typedef, "\\\\fI\$1\\\\fP"],
239 [$type_union, "\\\\fI\$1\\\\fP"],
5267dd35 240 [$type_param, "\\\\fI\$1\\\\fP"],
ee2aa759 241 [$type_param_ref, "\\\\fI\$1\$2\\\\fP"],
df31175b
PB
242 [$type_member, "\\\\fI\$1\$2\$3\\\\fP"],
243 [$type_fallback, "\\\\fI\$1\\\\fP"]
4d732701 244 );
1da177e4
LT
245my $blankline_man = "";
246
c0d1b6ee
JC
247# rst-mode
248my @highlights_rst = (
249 [$type_constant, "``\$1``"],
b97f193a 250 [$type_constant2, "``\$1``"],
f3341dcf 251 # Note: need to escape () to avoid func matching later
5267dd35
PB
252 [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"],
253 [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"],
5219f18a 254 [$type_fp_param, "**\$1\\\\(\\\\)**"],
346282db 255 [$type_fp_param2, "**\$1\\\\(\\\\)**"],
344fdb28 256 [$type_func, "\$1()"],
df31175b
PB
257 [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"],
258 [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"],
259 [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"],
260 [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"],
a7291e7e 261 # in rst this can refer to any type
df31175b 262 [$type_fallback, "\\:c\\:type\\:`\$1`"],
ee2aa759 263 [$type_param_ref, "**\$1\$2**"]
c0d1b6ee
JC
264 );
265my $blankline_rst = "\n";
266
1da177e4 267# read arguments
b9d97328 268if ($#ARGV == -1) {
1da177e4
LT
269 usage();
270}
271
8484baaa 272my $kernelversion;
efa44475
MCC
273my $sphinx_major;
274
8484baaa
RD
275my $dohighlight = "";
276
1da177e4 277my $verbose = 0;
2c12c810 278my $Werror = 0;
bdfe2be3 279my $output_mode = "rst";
e314ba31 280my $output_preformatted = 0;
4b44595a 281my $no_doc_sections = 0;
0b0f5f29 282my $enable_lineno = 0;
bdfe2be3
MCC
283my @highlights = @highlights_rst;
284my $blankline = $blankline_rst;
1da177e4 285my $modulename = "Kernel API";
b6c3f456
JN
286
287use constant {
288 OUTPUT_ALL => 0, # output all symbols and doc sections
289 OUTPUT_INCLUDE => 1, # output only specified symbols
eab795dd
MCC
290 OUTPUT_EXPORTED => 2, # output exported symbols
291 OUTPUT_INTERNAL => 3, # output non-exported symbols
b6c3f456
JN
292};
293my $output_selection = OUTPUT_ALL;
b0d60bfb 294my $show_not_found = 0; # No longer used
b2c4105b 295
88c2b57d
JN
296my @export_file_list;
297
b2c4105b
BH
298my @build_time;
299if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
300 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
301 @build_time = gmtime($seconds);
302} else {
303 @build_time = localtime;
304}
305
3c3b809e
RD
306my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
307 'July', 'August', 'September', 'October',
b2c4105b
BH
308 'November', 'December')[$build_time[4]] .
309 " " . ($build_time[5]+1900);
1da177e4 310
8484baaa 311# Essentially these are globals.
b9d97328
RD
312# They probably want to be tidied up, made more localised or something.
313# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
1da177e4 314# could cause "use of undefined value" or other bugs.
b9d97328 315my ($function, %function_table, %parametertypes, $declaration_purpose);
eab795dd 316my %nosymbol_table = ();
0b0f5f29 317my $declaration_start_line;
b9d97328 318my ($type, $declaration_name, $return_type);
1c32fd0c 319my ($newsection, $newcontents, $prototype, $brcount, %source_map);
1da177e4 320
bd0e88e5
RD
321if (defined($ENV{'KBUILD_VERBOSE'})) {
322 $verbose = "$ENV{'KBUILD_VERBOSE'}";
323}
324
2c12c810
PLB
325if (defined($ENV{'KDOC_WERROR'})) {
326 $Werror = "$ENV{'KDOC_WERROR'}";
327}
328
329if (defined($ENV{'KCFLAGS'})) {
330 my $kcflags = "$ENV{'KCFLAGS'}";
331
332 if ($kcflags =~ /Werror/) {
333 $Werror = 1;
334 }
335}
336
3c3b809e 337# Generated docbook code is inserted in a template at a point where
1da177e4 338# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
93431e06 339# https://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
1da177e4
LT
340# We keep track of number of generated entries and generate a dummy
341# if needs be to ensure the expanded template can be postprocessed
342# into html.
343my $section_counter = 0;
344
345my $lineprefix="";
346
48af606a
JN
347# Parser states
348use constant {
0d55d48b
MCC
349 STATE_NORMAL => 0, # normal code
350 STATE_NAME => 1, # looking for function name
351 STATE_BODY_MAYBE => 2, # body - or maybe more description
352 STATE_BODY => 3, # the body of the comment
353 STATE_BODY_WITH_BLANK_LINE => 4, # the body, which has a blank line
354 STATE_PROTO => 5, # scanning prototype
355 STATE_DOCBLOCK => 6, # documentation block
356 STATE_INLINE => 7, # gathering doc outside main block
48af606a 357};
1da177e4 358my $state;
850622df 359my $in_doc_sect;
d742f24d 360my $leading_space;
1da177e4 361
48af606a
JN
362# Inline documentation state
363use constant {
364 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
365 STATE_INLINE_NAME => 1, # looking for member name (@foo:)
366 STATE_INLINE_TEXT => 2, # looking for member documentation
367 STATE_INLINE_END => 3, # done
368 STATE_INLINE_ERROR => 4, # error - Comment without header was found.
369 # Spit a warning as it's not
370 # proper kernel-doc and ignore the rest.
371};
372my $inline_doc_state;
a4c6ebed 373
1da177e4
LT
374#declaration types: can be
375# 'function', 'struct', 'union', 'enum', 'typedef'
376my $decl_type;
377
1da177e4
LT
378my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
379my $doc_end = '\*/';
380my $doc_com = '\s*\*\s*';
12ae6779 381my $doc_com_body = '\s*\* ?';
b9d97328 382my $doc_decl = $doc_com . '(\w+)';
f624adef 383# @params and a strictly limited set of supported section names
76dd3e7b 384my $doc_sect = $doc_com .
ef00028b 385 '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)';
12ae6779 386my $doc_content = $doc_com_body . '(.*)';
b9d97328 387my $doc_block = $doc_com . 'DOC:\s*(.*)?';
48af606a 388my $doc_inline_start = '^\s*/\*\*\s*$';
fe7bc493 389my $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)';
48af606a 390my $doc_inline_end = '^\s*\*/\s*$';
0c9aa209 391my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$';
86ae2e38 392my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
1da177e4 393
1da177e4 394my %parameterdescs;
0b0f5f29 395my %parameterdesc_start_lines;
1da177e4
LT
396my @parameterlist;
397my %sections;
398my @sectionlist;
0b0f5f29 399my %section_start_lines;
a1d94aa5
RD
400my $sectcheck;
401my $struct_actual;
1da177e4
LT
402
403my $contents = "";
0b0f5f29 404my $new_start_line = 0;
f624adef
JN
405
406# the canonical section names. see also $doc_sect above.
1da177e4
LT
407my $section_default = "Description"; # default section
408my $section_intro = "Introduction";
409my $section = $section_default;
410my $section_context = "Context";
4092bac7 411my $section_return = "Return";
1da177e4
LT
412
413my $undescribed = "-- undescribed --";
414
415reset_state();
416
b031ac4e
MCC
417while ($ARGV[0] =~ m/^--?(.*)/) {
418 my $cmd = $1;
419 shift @ARGV;
420 if ($cmd eq "man") {
1da177e4 421 $output_mode = "man";
4d732701 422 @highlights = @highlights_man;
1da177e4 423 $blankline = $blankline_man;
b031ac4e 424 } elsif ($cmd eq "rst") {
c0d1b6ee
JC
425 $output_mode = "rst";
426 @highlights = @highlights_rst;
427 $blankline = $blankline_rst;
b031ac4e 428 } elsif ($cmd eq "none") {
3a025e1d 429 $output_mode = "none";
b031ac4e 430 } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document
1da177e4 431 $modulename = shift @ARGV;
b031ac4e 432 } elsif ($cmd eq "function") { # to only output specific functions
b6c3f456 433 $output_selection = OUTPUT_INCLUDE;
1da177e4
LT
434 $function = shift @ARGV;
435 $function_table{$function} = 1;
eab795dd
MCC
436 } elsif ($cmd eq "nosymbol") { # Exclude specific symbols
437 my $symbol = shift @ARGV;
438 $nosymbol_table{$symbol} = 1;
b031ac4e 439 } elsif ($cmd eq "export") { # only exported symbols
b6c3f456 440 $output_selection = OUTPUT_EXPORTED;
da9726ec 441 %function_table = ();
b031ac4e 442 } elsif ($cmd eq "internal") { # only non-exported symbols
b6c3f456 443 $output_selection = OUTPUT_INTERNAL;
da9726ec 444 %function_table = ();
b031ac4e 445 } elsif ($cmd eq "export-file") {
88c2b57d
JN
446 my $file = shift @ARGV;
447 push(@export_file_list, $file);
b031ac4e 448 } elsif ($cmd eq "v") {
1da177e4 449 $verbose = 1;
2c12c810
PLB
450 } elsif ($cmd eq "Werror") {
451 $Werror = 1;
b031ac4e 452 } elsif (($cmd eq "h") || ($cmd eq "help")) {
1da177e4 453 usage();
b031ac4e 454 } elsif ($cmd eq 'no-doc-sections') {
4b44595a 455 $no_doc_sections = 1;
b031ac4e 456 } elsif ($cmd eq 'enable-lineno') {
0b0f5f29 457 $enable_lineno = 1;
b031ac4e 458 } elsif ($cmd eq 'show-not-found') {
b0d60bfb 459 $show_not_found = 1; # A no-op but don't fail
b031ac4e
MCC
460 } else {
461 # Unknown argument
462 usage();
1da177e4
LT
463 }
464}
465
8484baaa
RD
466# continue execution near EOF;
467
efa44475
MCC
468# The C domain dialect changed on Sphinx 3. So, we need to check the
469# version in order to produce the right tags.
470sub findprog($)
471{
472 foreach(split(/:/, $ENV{PATH})) {
473 return "$_/$_[0]" if(-x "$_/$_[0]");
474 }
475}
476
477sub get_sphinx_version()
478{
479 my $ver;
480 my $major = 1;
481
482 my $cmd = "sphinx-build";
483 if (!findprog($cmd)) {
484 my $cmd = "sphinx-build3";
485 return $major if (!findprog($cmd));
486 }
487
488 open IN, "$cmd --version 2>&1 |";
489 while (<IN>) {
490 if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) {
491 $major=$1;
492 last;
493 }
494 # Sphinx 1.2.x uses a different format
495 if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+)$/) {
496 $major=$1;
497 last;
498 }
499 }
500 close IN;
501
502 return $major;
503}
504
53f049fa
BP
505# get kernel version from env
506sub get_kernel_version() {
1b9bc22d 507 my $version = 'unknown kernel version';
53f049fa
BP
508
509 if (defined($ENV{'KERNELVERSION'})) {
510 $version = $ENV{'KERNELVERSION'};
511 }
512 return $version;
513}
1da177e4 514
0b0f5f29
DV
515#
516sub print_lineno {
517 my $lineno = shift;
518 if ($enable_lineno && defined($lineno)) {
519 print "#define LINENO " . $lineno . "\n";
520 }
521}
1da177e4
LT
522##
523# dumps section contents to arrays/hashes intended for that purpose.
524#
525sub dump_section {
94dc7ad5 526 my $file = shift;
1da177e4
LT
527 my $name = shift;
528 my $contents = join "\n", @_;
529
13901ef2 530 if ($name =~ m/$type_param/) {
1da177e4
LT
531 $name = $1;
532 $parameterdescs{$name} = $contents;
a1d94aa5 533 $sectcheck = $sectcheck . $name . " ";
0b0f5f29
DV
534 $parameterdesc_start_lines{$name} = $new_start_line;
535 $new_start_line = 0;
ced69090 536 } elsif ($name eq "@\.\.\.") {
ced69090
RD
537 $name = "...";
538 $parameterdescs{$name} = $contents;
a1d94aa5 539 $sectcheck = $sectcheck . $name . " ";
0b0f5f29
DV
540 $parameterdesc_start_lines{$name} = $new_start_line;
541 $new_start_line = 0;
1da177e4 542 } else {
94dc7ad5 543 if (defined($sections{$name}) && ($sections{$name} ne "")) {
95b6be9d
JN
544 # Only warn on user specified duplicate section names.
545 if ($name ne $section_default) {
546 print STDERR "${file}:$.: warning: duplicate section name '$name'\n";
547 ++$warnings;
548 }
32217761
JN
549 $sections{$name} .= $contents;
550 } else {
551 $sections{$name} = $contents;
552 push @sectionlist, $name;
0b0f5f29
DV
553 $section_start_lines{$name} = $new_start_line;
554 $new_start_line = 0;
94dc7ad5 555 }
1da177e4
LT
556 }
557}
558
b112e0f7
JB
559##
560# dump DOC: section after checking that it should go out
561#
562sub dump_doc_section {
94dc7ad5 563 my $file = shift;
b112e0f7
JB
564 my $name = shift;
565 my $contents = join "\n", @_;
566
4b44595a
JB
567 if ($no_doc_sections) {
568 return;
569 }
570
eab795dd
MCC
571 return if (defined($nosymbol_table{$name}));
572
b6c3f456 573 if (($output_selection == OUTPUT_ALL) ||
eab795dd
MCC
574 (($output_selection == OUTPUT_INCLUDE) &&
575 defined($function_table{$name})))
b112e0f7 576 {
94dc7ad5 577 dump_section($file, $name, $contents);
b112e0f7
JB
578 output_blockhead({'sectionlist' => \@sectionlist,
579 'sections' => \%sections,
580 'module' => $modulename,
b6c3f456 581 'content-only' => ($output_selection != OUTPUT_ALL), });
b112e0f7
JB
582 }
583}
584
1da177e4
LT
585##
586# output function
587#
588# parameterdescs, a hash.
589# function => "function name"
590# parameterlist => @list of parameters
591# parameterdescs => %parameter descriptions
592# sectionlist => @list of sections
a21217da 593# sections => %section descriptions
3c3b809e 594#
1da177e4
LT
595
596sub output_highlight {
597 my $contents = join "\n",@_;
598 my $line;
599
600# DEBUG
601# if (!defined $contents) {
602# use Carp;
603# confess "output_highlight got called with no args?\n";
604# }
605
3eb014a1 606# print STDERR "contents b4:$contents\n";
1da177e4
LT
607 eval $dohighlight;
608 die $@ if $@;
3eb014a1
RD
609# print STDERR "contents af:$contents\n";
610
1da177e4 611 foreach $line (split "\n", $contents) {
12ae6779
DS
612 if (! $output_preformatted) {
613 $line =~ s/^\s*//;
614 }
3c308798 615 if ($line eq ""){
e314ba31 616 if (! $output_preformatted) {
0bba924c 617 print $lineprefix, $blankline;
e314ba31 618 }
1da177e4 619 } else {
cdccb316
RD
620 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
621 print "\\&$line";
622 } else {
623 print $lineprefix, $line;
624 }
1da177e4
LT
625 }
626 print "\n";
627 }
628}
629
1da177e4
LT
630##
631# output function in man
632sub output_function_man(%) {
633 my %args = %{$_[0]};
634 my ($parameter, $section);
635 my $count;
636
637 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
638
639 print ".SH NAME\n";
b9d97328 640 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
1da177e4
LT
641
642 print ".SH SYNOPSIS\n";
a21217da 643 if ($args{'functiontype'} ne "") {
b9d97328 644 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
a21217da 645 } else {
b9d97328 646 print ".B \"" . $args{'function'} . "\n";
a21217da 647 }
1da177e4
LT
648 $count = 0;
649 my $parenth = "(";
650 my $post = ",";
651 foreach my $parameter (@{$args{'parameterlist'}}) {
652 if ($count == $#{$args{'parameterlist'}}) {
653 $post = ");";
654 }
655 $type = $args{'parametertypes'}{$parameter};
656 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
657 # pointer-to-function
b9d97328 658 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
1da177e4
LT
659 } else {
660 $type =~ s/([^\*])$/$1 /;
b9d97328 661 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
1da177e4
LT
662 }
663 $count++;
664 $parenth = "";
665 }
666
667 print ".SH ARGUMENTS\n";
668 foreach $parameter (@{$args{'parameterlist'}}) {
669 my $parameter_name = $parameter;
670 $parameter_name =~ s/\[.*//;
671
b9d97328 672 print ".IP \"" . $parameter . "\" 12\n";
1da177e4
LT
673 output_highlight($args{'parameterdescs'}{$parameter_name});
674 }
675 foreach $section (@{$args{'sectionlist'}}) {
676 print ".SH \"", uc $section, "\"\n";
677 output_highlight($args{'sections'}{$section});
678 }
679}
680
681##
682# output enum in man
683sub output_enum_man(%) {
684 my %args = %{$_[0]};
685 my ($parameter, $section);
686 my $count;
687
688 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
689
690 print ".SH NAME\n";
b9d97328 691 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
1da177e4
LT
692
693 print ".SH SYNOPSIS\n";
b9d97328 694 print "enum " . $args{'enum'} . " {\n";
1da177e4
LT
695 $count = 0;
696 foreach my $parameter (@{$args{'parameterlist'}}) {
3c308798 697 print ".br\n.BI \" $parameter\"\n";
1da177e4
LT
698 if ($count == $#{$args{'parameterlist'}}) {
699 print "\n};\n";
700 last;
701 }
702 else {
703 print ", \n.br\n";
704 }
705 $count++;
706 }
707
708 print ".SH Constants\n";
709 foreach $parameter (@{$args{'parameterlist'}}) {
710 my $parameter_name = $parameter;
711 $parameter_name =~ s/\[.*//;
712
b9d97328 713 print ".IP \"" . $parameter . "\" 12\n";
1da177e4
LT
714 output_highlight($args{'parameterdescs'}{$parameter_name});
715 }
716 foreach $section (@{$args{'sectionlist'}}) {
717 print ".SH \"$section\"\n";
718 output_highlight($args{'sections'}{$section});
719 }
720}
721
722##
723# output struct in man
724sub output_struct_man(%) {
725 my %args = %{$_[0]};
726 my ($parameter, $section);
727
b9d97328 728 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
1da177e4
LT
729
730 print ".SH NAME\n";
b9d97328 731 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
1da177e4 732
8ad72163
MCC
733 my $declaration = $args{'definition'};
734 $declaration =~ s/\t/ /g;
735 $declaration =~ s/\n/"\n.br\n.BI \"/g;
1da177e4 736 print ".SH SYNOPSIS\n";
b9d97328 737 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
8ad72163 738 print ".BI \"$declaration\n};\n.br\n\n";
1da177e4 739
c51d3dac 740 print ".SH Members\n";
1da177e4
LT
741 foreach $parameter (@{$args{'parameterlist'}}) {
742 ($parameter =~ /^#/) && next;
743
744 my $parameter_name = $parameter;
745 $parameter_name =~ s/\[.*//;
746
3c308798 747 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
b9d97328 748 print ".IP \"" . $parameter . "\" 12\n";
1da177e4
LT
749 output_highlight($args{'parameterdescs'}{$parameter_name});
750 }
751 foreach $section (@{$args{'sectionlist'}}) {
752 print ".SH \"$section\"\n";
753 output_highlight($args{'sections'}{$section});
754 }
755}
756
757##
758# output typedef in man
759sub output_typedef_man(%) {
760 my %args = %{$_[0]};
761 my ($parameter, $section);
762
763 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
764
765 print ".SH NAME\n";
b9d97328 766 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
1da177e4
LT
767
768 foreach $section (@{$args{'sectionlist'}}) {
769 print ".SH \"$section\"\n";
770 output_highlight($args{'sections'}{$section});
771 }
772}
773
b112e0f7 774sub output_blockhead_man(%) {
1da177e4
LT
775 my %args = %{$_[0]};
776 my ($parameter, $section);
777 my $count;
778
779 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
780
781 foreach $section (@{$args{'sectionlist'}}) {
782 print ".SH \"$section\"\n";
783 output_highlight($args{'sections'}{$section});
784 }
785}
786
c0d1b6ee
JC
787##
788# output in restructured text
789#
790
791#
792# This could use some work; it's used to output the DOC: sections, and
793# starts by putting out the name of the doc section itself, but that tends
794# to duplicate a header already in the template file.
795#
796sub output_blockhead_rst(%) {
797 my %args = %{$_[0]};
798 my ($parameter, $section);
799
800 foreach $section (@{$args{'sectionlist'}}) {
eab795dd
MCC
801 next if (defined($nosymbol_table{$section}));
802
9e72184b
JN
803 if ($output_selection != OUTPUT_INCLUDE) {
804 print "**$section**\n\n";
805 }
0b0f5f29 806 print_lineno($section_start_lines{$section});
c0d1b6ee
JC
807 output_highlight_rst($args{'sections'}{$section});
808 print "\n";
809 }
810}
811
af250290
JC
812#
813# Apply the RST highlights to a sub-block of text.
76dd3e7b 814#
af250290
JC
815sub highlight_block($) {
816 # The dohighlight kludge requires the text be called $contents
817 my $contents = shift;
c0d1b6ee
JC
818 eval $dohighlight;
819 die $@ if $@;
af250290
JC
820 return $contents;
821}
c0d1b6ee 822
af250290
JC
823#
824# Regexes used only here.
825#
826my $sphinx_literal = '^[^.].*::$';
827my $sphinx_cblock = '^\.\.\ +code-block::';
828
829sub output_highlight_rst {
830 my $input = join "\n",@_;
831 my $output = "";
832 my $line;
833 my $in_literal = 0;
834 my $litprefix;
835 my $block = "";
836
837 foreach $line (split "\n",$input) {
838 #
839 # If we're in a literal block, see if we should drop out
840 # of it. Otherwise pass the line straight through unmunged.
841 #
842 if ($in_literal) {
843 if (! ($line =~ /^\s*$/)) {
844 #
845 # If this is the first non-blank line in a literal
846 # block we need to figure out what the proper indent is.
847 #
848 if ($litprefix eq "") {
849 $line =~ /^(\s*)/;
850 $litprefix = '^' . $1;
851 $output .= $line . "\n";
852 } elsif (! ($line =~ /$litprefix/)) {
853 $in_literal = 0;
854 } else {
855 $output .= $line . "\n";
856 }
857 } else {
858 $output .= $line . "\n";
859 }
860 }
861 #
862 # Not in a literal block (or just dropped out)
863 #
864 if (! $in_literal) {
865 $block .= $line . "\n";
866 if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) {
867 $in_literal = 1;
868 $litprefix = "";
869 $output .= highlight_block($block);
870 $block = ""
871 }
872 }
873 }
874
875 if ($block) {
876 $output .= highlight_block($block);
877 }
878 foreach $line (split "\n", $output) {
830066a7 879 print $lineprefix . $line . "\n";
c0d1b6ee
JC
880 }
881}
882
883sub output_function_rst(%) {
884 my %args = %{$_[0]};
885 my ($parameter, $section);
c099ff69 886 my $oldprefix = $lineprefix;
82801d06
MCC
887 my $start = "";
888
e3ad05fe
MCC
889 if ($sphinx_major < 3) {
890 if ($args{'typedef'}) {
efa44475 891 print ".. c:type:: ". $args{'function'} . "\n\n";
e3ad05fe
MCC
892 print_lineno($declaration_start_line);
893 print " **Typedef**: ";
894 $lineprefix = "";
895 output_highlight_rst($args{'purpose'});
896 $start = "\n\n**Syntax**\n\n ``";
efa44475 897 } else {
e3ad05fe 898 print ".. c:function:: ";
efa44475 899 }
82801d06 900 } else {
e3ad05fe
MCC
901 print ".. c:macro:: ". $args{'function'} . "\n\n";
902
903 if ($args{'typedef'}) {
904 print_lineno($declaration_start_line);
905 print " **Typedef**: ";
906 $lineprefix = "";
907 output_highlight_rst($args{'purpose'});
908 $start = "\n\n**Syntax**\n\n ``";
909 } else {
910 print "``";
911 }
82801d06 912 }
c0d1b6ee 913 if ($args{'functiontype'} ne "") {
82801d06 914 $start .= $args{'functiontype'} . " " . $args{'function'} . " (";
c0d1b6ee 915 } else {
82801d06 916 $start .= $args{'function'} . " (";
c0d1b6ee
JC
917 }
918 print $start;
919
920 my $count = 0;
921 foreach my $parameter (@{$args{'parameterlist'}}) {
922 if ($count ne 0) {
923 print ", ";
924 }
925 $count++;
926 $type = $args{'parametertypes'}{$parameter};
a88b1672 927
c0d1b6ee
JC
928 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
929 # pointer-to-function
e8f4ba83 930 print $1 . $parameter . ") (" . $2 . ")";
c0d1b6ee
JC
931 } else {
932 print $type . " " . $parameter;
933 }
934 }
82801d06
MCC
935 if ($args{'typedef'}) {
936 print ");``\n\n";
937 } else {
e3ad05fe
MCC
938 if ($sphinx_major < 3) {
939 print ")\n\n";
940 } else {
941 print ")``\n";
942 }
82801d06
MCC
943 print_lineno($declaration_start_line);
944 $lineprefix = " ";
945 output_highlight_rst($args{'purpose'});
946 print "\n";
947 }
c0d1b6ee 948
ecbcfba1
JN
949 print "**Parameters**\n\n";
950 $lineprefix = " ";
c0d1b6ee
JC
951 foreach $parameter (@{$args{'parameterlist'}}) {
952 my $parameter_name = $parameter;
ada5f446 953 $parameter_name =~ s/\[.*//;
c0d1b6ee
JC
954 $type = $args{'parametertypes'}{$parameter};
955
956 if ($type ne "") {
ecbcfba1 957 print "``$type $parameter``\n";
c0d1b6ee 958 } else {
ecbcfba1 959 print "``$parameter``\n";
c0d1b6ee 960 }
0b0f5f29
DV
961
962 print_lineno($parameterdesc_start_lines{$parameter_name});
963
5e64fa9c
JN
964 if (defined($args{'parameterdescs'}{$parameter_name}) &&
965 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
c0d1b6ee 966 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
c0d1b6ee 967 } else {
d4b08e0c 968 print " *undescribed*\n";
c0d1b6ee
JC
969 }
970 print "\n";
971 }
c099ff69
JN
972
973 $lineprefix = $oldprefix;
c0d1b6ee
JC
974 output_section_rst(@_);
975}
976
977sub output_section_rst(%) {
978 my %args = %{$_[0]};
979 my $section;
980 my $oldprefix = $lineprefix;
ecbcfba1 981 $lineprefix = "";
c0d1b6ee
JC
982
983 foreach $section (@{$args{'sectionlist'}}) {
ecbcfba1 984 print "**$section**\n\n";
0b0f5f29 985 print_lineno($section_start_lines{$section});
c0d1b6ee
JC
986 output_highlight_rst($args{'sections'}{$section});
987 print "\n";
988 }
989 print "\n";
990 $lineprefix = $oldprefix;
991}
992
993sub output_enum_rst(%) {
994 my %args = %{$_[0]};
995 my ($parameter);
c099ff69 996 my $oldprefix = $lineprefix;
c0d1b6ee 997 my $count;
62850976 998
efa44475
MCC
999 if ($sphinx_major < 3) {
1000 my $name = "enum " . $args{'enum'};
1001 print "\n\n.. c:type:: " . $name . "\n\n";
1002 } else {
1003 my $name = $args{'enum'};
1004 print "\n\n.. c:enum:: " . $name . "\n\n";
1005 }
0b0f5f29 1006 print_lineno($declaration_start_line);
c099ff69
JN
1007 $lineprefix = " ";
1008 output_highlight_rst($args{'purpose'});
1009 print "\n";
c0d1b6ee 1010
ecbcfba1
JN
1011 print "**Constants**\n\n";
1012 $lineprefix = " ";
c0d1b6ee 1013 foreach $parameter (@{$args{'parameterlist'}}) {
ecbcfba1 1014 print "``$parameter``\n";
c0d1b6ee
JC
1015 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1016 output_highlight_rst($args{'parameterdescs'}{$parameter});
1017 } else {
d4b08e0c 1018 print " *undescribed*\n";
c0d1b6ee
JC
1019 }
1020 print "\n";
1021 }
c099ff69 1022
c0d1b6ee
JC
1023 $lineprefix = $oldprefix;
1024 output_section_rst(@_);
1025}
1026
1027sub output_typedef_rst(%) {
1028 my %args = %{$_[0]};
1029 my ($parameter);
c099ff69 1030 my $oldprefix = $lineprefix;
efa44475 1031 my $name;
c0d1b6ee 1032
efa44475
MCC
1033 if ($sphinx_major < 3) {
1034 $name = "typedef " . $args{'typedef'};
1035 } else {
1036 $name = $args{'typedef'};
1037 }
62850976 1038 print "\n\n.. c:type:: " . $name . "\n\n";
0b0f5f29 1039 print_lineno($declaration_start_line);
c099ff69
JN
1040 $lineprefix = " ";
1041 output_highlight_rst($args{'purpose'});
1042 print "\n";
c0d1b6ee 1043
c099ff69 1044 $lineprefix = $oldprefix;
c0d1b6ee
JC
1045 output_section_rst(@_);
1046}
1047
1048sub output_struct_rst(%) {
1049 my %args = %{$_[0]};
1050 my ($parameter);
c099ff69 1051 my $oldprefix = $lineprefix;
c0d1b6ee 1052
efa44475
MCC
1053 if ($sphinx_major < 3) {
1054 my $name = $args{'type'} . " " . $args{'struct'};
1055 print "\n\n.. c:type:: " . $name . "\n\n";
1056 } else {
1057 my $name = $args{'struct'};
1058 print "\n\n.. c:struct:: " . $name . "\n\n";
1059 }
0b0f5f29 1060 print_lineno($declaration_start_line);
c099ff69
JN
1061 $lineprefix = " ";
1062 output_highlight_rst($args{'purpose'});
1063 print "\n";
c0d1b6ee 1064
ecbcfba1
JN
1065 print "**Definition**\n\n";
1066 print "::\n\n";
8ad72163
MCC
1067 my $declaration = $args{'definition'};
1068 $declaration =~ s/\t/ /g;
1069 print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n";
c0d1b6ee 1070
ecbcfba1
JN
1071 print "**Members**\n\n";
1072 $lineprefix = " ";
c0d1b6ee
JC
1073 foreach $parameter (@{$args{'parameterlist'}}) {
1074 ($parameter =~ /^#/) && next;
1075
1076 my $parameter_name = $parameter;
1077 $parameter_name =~ s/\[.*//;
1078
1079 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1080 $type = $args{'parametertypes'}{$parameter};
0b0f5f29 1081 print_lineno($parameterdesc_start_lines{$parameter_name});
6d232c80 1082 print "``" . $parameter . "``\n";
c0d1b6ee 1083 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
c0d1b6ee
JC
1084 print "\n";
1085 }
1086 print "\n";
c099ff69
JN
1087
1088 $lineprefix = $oldprefix;
c0d1b6ee
JC
1089 output_section_rst(@_);
1090}
1091
3a025e1d
MW
1092## none mode output functions
1093
1094sub output_function_none(%) {
1095}
1096
1097sub output_enum_none(%) {
1098}
1099
1100sub output_typedef_none(%) {
1101}
1102
1103sub output_struct_none(%) {
1104}
1105
1106sub output_blockhead_none(%) {
1107}
1108
1da177e4 1109##
27205744
RD
1110# generic output function for all types (function, struct/union, typedef, enum);
1111# calls the generated, variable output_ function name based on
1112# functype and output_mode
1da177e4
LT
1113sub output_declaration {
1114 no strict 'refs';
1115 my $name = shift;
1116 my $functype = shift;
1117 my $func = "output_${functype}_$output_mode";
eab795dd
MCC
1118
1119 return if (defined($nosymbol_table{$name}));
1120
b6c3f456
JN
1121 if (($output_selection == OUTPUT_ALL) ||
1122 (($output_selection == OUTPUT_INCLUDE ||
1123 $output_selection == OUTPUT_EXPORTED) &&
1124 defined($function_table{$name})) ||
eab795dd 1125 ($output_selection == OUTPUT_INTERNAL &&
b6c3f456 1126 !($functype eq "function" && defined($function_table{$name}))))
1da177e4 1127 {
3c308798 1128 &$func(@_);
1da177e4
LT
1129 $section_counter++;
1130 }
1131}
1132
1133##
27205744 1134# generic output function - calls the right one based on current output mode.
b112e0f7 1135sub output_blockhead {
1da177e4 1136 no strict 'refs';
b9d97328 1137 my $func = "output_blockhead_" . $output_mode;
1da177e4
LT
1138 &$func(@_);
1139 $section_counter++;
1140}
1141
1142##
3c3b809e 1143# takes a declaration (struct, union, enum, typedef) and
1da177e4
LT
1144# invokes the right handler. NOT called for functions.
1145sub dump_declaration($$) {
1146 no strict 'refs';
1147 my ($prototype, $file) = @_;
b9d97328 1148 my $func = "dump_" . $decl_type;
1da177e4
LT
1149 &$func(@_);
1150}
1151
1152sub dump_union($$) {
1153 dump_struct(@_);
1154}
1155
1156sub dump_struct($$) {
1157 my $x = shift;
1158 my $file = shift;
1159
a070991f 1160 if ($x =~ /(struct|union)\s+(\w+)\s*\{(.*)\}(\s*(__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*/) {
5cb5c31c 1161 my $decl_type = $1;
3c308798
RD
1162 $declaration_name = $2;
1163 my $members = $3;
1da177e4 1164
aeec46b9 1165 # ignore members marked private:
0d8c39e6
MCC
1166 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
1167 $members =~ s/\/\*\s*private:.*//gosi;
aeec46b9
MW
1168 # strip comments:
1169 $members =~ s/\/\*.*?\*\///gos;
ef5da59f 1170 # strip attributes
2b5f78e5
AA
1171 $members =~ s/\s*__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)/ /gi;
1172 $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos;
1173 $members =~ s/\s*__packed\s*/ /gos;
1174 $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos;
f861537d 1175 $members =~ s/\s*____cacheline_aligned_in_smp/ /gos;
a070991f 1176 $members =~ s/\s*____cacheline_aligned/ /gos;
3556108e 1177
b22b5a9e 1178 # replace DECLARE_BITMAP
3556108e 1179 $members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos;
45005b27 1180 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
1cb566ba 1181 # replace DECLARE_HASHTABLE
45005b27
MCC
1182 $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos;
1183 # replace DECLARE_KFIFO
1184 $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos;
1185 # replace DECLARE_KFIFO_PTR
1186 $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos;
aeec46b9 1187
8ad72163
MCC
1188 my $declaration = $members;
1189
1190 # Split nested struct/union elements as newer ones
84ce5b98
MCC
1191 while ($members =~ m/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/) {
1192 my $newmember;
1193 my $maintype = $1;
1194 my $ids = $4;
1195 my $content = $3;
1196 foreach my $id(split /,/, $ids) {
1197 $newmember .= "$maintype $id; ";
1198
8ad72163 1199 $id =~ s/[:\[].*//;
84ce5b98 1200 $id =~ s/^\s*\**(\S+)\s*/$1/;
8ad72163
MCC
1201 foreach my $arg (split /;/, $content) {
1202 next if ($arg =~ m/^\s*$/);
7c0d7e87
MCC
1203 if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) {
1204 # pointer-to-function
1205 my $type = $1;
1206 my $name = $2;
1207 my $extra = $3;
1208 next if (!$name);
1209 if ($id =~ m/^\s*$/) {
1210 # anonymous struct/union
84ce5b98 1211 $newmember .= "$type$name$extra; ";
7c0d7e87 1212 } else {
84ce5b98 1213 $newmember .= "$type$id.$name$extra; ";
7c0d7e87 1214 }
8ad72163 1215 } else {
84ce5b98
MCC
1216 my $type;
1217 my $names;
1218 $arg =~ s/^\s+//;
1219 $arg =~ s/\s+$//;
1220 # Handle bitmaps
1221 $arg =~ s/:\s*\d+\s*//g;
1222 # Handle arrays
d404d579 1223 $arg =~ s/\[.*\]//g;
84ce5b98
MCC
1224 # The type may have multiple words,
1225 # and multiple IDs can be defined, like:
1226 # const struct foo, *bar, foobar
1227 # So, we remove spaces when parsing the
1228 # names, in order to match just names
1229 # and commas for the names
1230 $arg =~ s/\s*,\s*/,/g;
1231 if ($arg =~ m/(.*)\s+([\S+,]+)/) {
1232 $type = $1;
1233 $names = $2;
7c0d7e87 1234 } else {
84ce5b98
MCC
1235 $newmember .= "$arg; ";
1236 next;
1237 }
1238 foreach my $name (split /,/, $names) {
1239 $name =~ s/^\s*\**(\S+)\s*/$1/;
1240 next if (($name =~ m/^\s*$/));
1241 if ($id =~ m/^\s*$/) {
1242 # anonymous struct/union
1243 $newmember .= "$type $name; ";
1244 } else {
1245 $newmember .= "$type $id.$name; ";
1246 }
7c0d7e87 1247 }
8ad72163
MCC
1248 }
1249 }
84ce5b98 1250 }
673bb2df 1251 $members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/$newmember/;
84ce5b98 1252 }
8ad72163
MCC
1253
1254 # Ignore other nested elements, like enums
673bb2df 1255 $members =~ s/(\{[^\{\}]*\})//g;
8ad72163 1256
151c468b 1257 create_parameterlist($members, ';', $file, $declaration_name);
1081de2d 1258 check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual);
1da177e4 1259
8ad72163 1260 # Adjust declaration for better display
673bb2df
BH
1261 $declaration =~ s/([\{;])/$1\n/g;
1262 $declaration =~ s/\}\s+;/};/g;
8ad72163 1263 # Better handle inlined enums
673bb2df 1264 do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/);
8ad72163
MCC
1265
1266 my @def_args = split /\n/, $declaration;
1267 my $level = 1;
1268 $declaration = "";
1269 foreach my $clause (@def_args) {
1270 $clause =~ s/^\s+//;
1271 $clause =~ s/\s+$//;
1272 $clause =~ s/\s+/ /;
1273 next if (!$clause);
673bb2df 1274 $level-- if ($clause =~ m/(\})/ && $level > 1);
8ad72163
MCC
1275 if (!($clause =~ m/^\s*#/)) {
1276 $declaration .= "\t" x $level;
1277 }
1278 $declaration .= "\t" . $clause . "\n";
673bb2df 1279 $level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/));
8ad72163 1280 }
1da177e4
LT
1281 output_declaration($declaration_name,
1282 'struct',
1283 {'struct' => $declaration_name,
1284 'module' => $modulename,
8ad72163 1285 'definition' => $declaration,
1da177e4
LT
1286 'parameterlist' => \@parameterlist,
1287 'parameterdescs' => \%parameterdescs,
1288 'parametertypes' => \%parametertypes,
1289 'sectionlist' => \@sectionlist,
1290 'sections' => \%sections,
1291 'purpose' => $declaration_purpose,
1292 'type' => $decl_type
1293 });
1294 }
1295 else {
d40e1e65 1296 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
1da177e4
LT
1297 ++$errors;
1298 }
1299}
1300
85afe608
MCC
1301
1302sub show_warnings($$) {
1303 my $functype = shift;
1304 my $name = shift;
1305
eab795dd
MCC
1306 return 0 if (defined($nosymbol_table{$name}));
1307
85afe608
MCC
1308 return 1 if ($output_selection == OUTPUT_ALL);
1309
1310 if ($output_selection == OUTPUT_EXPORTED) {
1311 if (defined($function_table{$name})) {
1312 return 1;
1313 } else {
1314 return 0;
1315 }
1316 }
1317 if ($output_selection == OUTPUT_INTERNAL) {
1318 if (!($functype eq "function" && defined($function_table{$name}))) {
1319 return 1;
1320 } else {
1321 return 0;
1322 }
1323 }
1324 if ($output_selection == OUTPUT_INCLUDE) {
1325 if (defined($function_table{$name})) {
1326 return 1;
1327 } else {
1328 return 0;
1329 }
1330 }
85afe608
MCC
1331 die("Please add the new output type at show_warnings()");
1332}
1333
1da177e4
LT
1334sub dump_enum($$) {
1335 my $x = shift;
1336 my $file = shift;
d38c8cfb
MCC
1337 my $members;
1338
1da177e4 1339
aeec46b9 1340 $x =~ s@/\*.*?\*/@@gos; # strip comments.
4468e21e
CN
1341 # strip #define macros inside enums
1342 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
b6d676db 1343
d38c8cfb
MCC
1344 if ($x =~ /typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;/) {
1345 $declaration_name = $2;
1346 $members = $1;
1347 } elsif ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) {
3c308798 1348 $declaration_name = $1;
d38c8cfb
MCC
1349 $members = $2;
1350 }
1351
1352 if ($declaration_name) {
5cb5c31c
JB
1353 my %_members;
1354
463a0fdc 1355 $members =~ s/\s+$//;
1da177e4
LT
1356
1357 foreach my $arg (split ',', $members) {
1358 $arg =~ s/^\s*(\w+).*/$1/;
1359 push @parameterlist, $arg;
1360 if (!$parameterdescs{$arg}) {
3c308798 1361 $parameterdescs{$arg} = $undescribed;
85afe608 1362 if (show_warnings("enum", $declaration_name)) {
2defb272
MCC
1363 print STDERR "${file}:$.: warning: Enum value '$arg' not described in enum '$declaration_name'\n";
1364 }
1da177e4 1365 }
5cb5c31c 1366 $_members{$arg} = 1;
1da177e4 1367 }
3c3b809e 1368
5cb5c31c
JB
1369 while (my ($k, $v) = each %parameterdescs) {
1370 if (!exists($_members{$k})) {
85afe608 1371 if (show_warnings("enum", $declaration_name)) {
2defb272
MCC
1372 print STDERR "${file}:$.: warning: Excess enum value '$k' description in '$declaration_name'\n";
1373 }
5cb5c31c
JB
1374 }
1375 }
1376
1da177e4
LT
1377 output_declaration($declaration_name,
1378 'enum',
1379 {'enum' => $declaration_name,
1380 'module' => $modulename,
1381 'parameterlist' => \@parameterlist,
1382 'parameterdescs' => \%parameterdescs,
1383 'sectionlist' => \@sectionlist,
1384 'sections' => \%sections,
1385 'purpose' => $declaration_purpose
1386 });
d38c8cfb 1387 } else {
d40e1e65 1388 print STDERR "${file}:$.: error: Cannot parse enum!\n";
1da177e4
LT
1389 ++$errors;
1390 }
1391}
1392
1393sub dump_typedef($$) {
1394 my $x = shift;
1395 my $file = shift;
1396
aeec46b9 1397 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1da177e4 1398
83766452 1399 # Parse function prototypes
d37c43ce
MCC
1400 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ ||
1401 $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) {
1402
83766452
MCC
1403 # Function typedefs
1404 $return_type = $1;
1405 $declaration_name = $2;
1406 my $args = $3;
1407
151c468b 1408 create_parameterlist($args, ',', $file, $declaration_name);
1da177e4
LT
1409
1410 output_declaration($declaration_name,
83766452
MCC
1411 'function',
1412 {'function' => $declaration_name,
82801d06 1413 'typedef' => 1,
1da177e4 1414 'module' => $modulename,
83766452
MCC
1415 'functiontype' => $return_type,
1416 'parameterlist' => \@parameterlist,
1417 'parameterdescs' => \%parameterdescs,
1418 'parametertypes' => \%parametertypes,
1da177e4
LT
1419 'sectionlist' => \@sectionlist,
1420 'sections' => \%sections,
1421 'purpose' => $declaration_purpose
1422 });
83766452
MCC
1423 return;
1424 }
1425
1426 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1427 $x =~ s/\(*.\)\s*;$/;/;
1428 $x =~ s/\[*.\]\s*;$/;/;
1da177e4 1429 }
83766452
MCC
1430
1431 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
3a80a766
MCC
1432 $declaration_name = $1;
1433
1434 output_declaration($declaration_name,
1435 'typedef',
1436 {'typedef' => $declaration_name,
1437 'module' => $modulename,
1438 'sectionlist' => \@sectionlist,
1439 'sections' => \%sections,
1440 'purpose' => $declaration_purpose
1441 });
1442 }
1da177e4 1443 else {
d40e1e65 1444 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
1da177e4
LT
1445 ++$errors;
1446 }
1447}
1448
a1d94aa5
RD
1449sub save_struct_actual($) {
1450 my $actual = shift;
1451
1452 # strip all spaces from the actual param so that it looks like one string item
1453 $actual =~ s/\s*//g;
1454 $struct_actual = $struct_actual . $actual . " ";
1455}
1456
151c468b 1457sub create_parameterlist($$$$) {
1da177e4
LT
1458 my $args = shift;
1459 my $splitter = shift;
1460 my $file = shift;
151c468b 1461 my $declaration_name = shift;
1da177e4
LT
1462 my $type;
1463 my $param;
1464
a6d3fe77 1465 # temporarily replace commas inside function pointer definition
1da177e4 1466 while ($args =~ /(\([^\),]+),/) {
3c308798 1467 $args =~ s/(\([^\),]+),/$1#/g;
1da177e4 1468 }
3c3b809e 1469
1da177e4
LT
1470 foreach my $arg (split($splitter, $args)) {
1471 # strip comments
1472 $arg =~ s/\/\*.*\*\///;
3c308798
RD
1473 # strip leading/trailing spaces
1474 $arg =~ s/^\s*//;
1da177e4
LT
1475 $arg =~ s/\s*$//;
1476 $arg =~ s/\s+/ /;
1477
1478 if ($arg =~ /^#/) {
1479 # Treat preprocessor directive as a typeless variable just to fill
1480 # corresponding data structures "correctly". Catch it later in
1481 # output_* subs.
1482 push_parameter($arg, "", $file);
00d62961 1483 } elsif ($arg =~ m/\(.+\)\s*\(/) {
1da177e4
LT
1484 # pointer-to-function
1485 $arg =~ tr/#/,/;
7c0d7e87 1486 $arg =~ m/[^\(]+\(\*?\s*([\w\.]*)\s*\)/;
1da177e4
LT
1487 $param = $1;
1488 $type = $arg;
00d62961 1489 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
a1d94aa5 1490 save_struct_actual($param);
151c468b 1491 push_parameter($param, $type, $file, $declaration_name);
aeec46b9 1492 } elsif ($arg) {
1da177e4
LT
1493 $arg =~ s/\s*:\s*/:/g;
1494 $arg =~ s/\s*\[/\[/g;
1495
1496 my @args = split('\s*,\s*', $arg);
1497 if ($args[0] =~ m/\*/) {
1498 $args[0] =~ s/(\*+)\s*/ $1/;
1499 }
884f2810
BP
1500
1501 my @first_arg;
1502 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1503 shift @args;
1504 push(@first_arg, split('\s+', $1));
1505 push(@first_arg, $2);
1506 } else {
1507 @first_arg = split('\s+', shift @args);
1508 }
1509
1da177e4
LT
1510 unshift(@args, pop @first_arg);
1511 $type = join " ", @first_arg;
1512
1513 foreach $param (@args) {
1514 if ($param =~ m/^(\*+)\s*(.*)/) {
a1d94aa5 1515 save_struct_actual($2);
151c468b 1516 push_parameter($2, "$type $1", $file, $declaration_name);
1da177e4
LT
1517 }
1518 elsif ($param =~ m/(.*?):(\d+)/) {
7b97887e 1519 if ($type ne "") { # skip unnamed bit-fields
a1d94aa5 1520 save_struct_actual($1);
151c468b 1521 push_parameter($1, "$type:$2", $file, $declaration_name)
7b97887e 1522 }
1da177e4
LT
1523 }
1524 else {
a1d94aa5 1525 save_struct_actual($param);
151c468b 1526 push_parameter($param, $type, $file, $declaration_name);
1da177e4
LT
1527 }
1528 }
1529 }
1530 }
1531}
1532
151c468b 1533sub push_parameter($$$$) {
1da177e4
LT
1534 my $param = shift;
1535 my $type = shift;
1536 my $file = shift;
151c468b 1537 my $declaration_name = shift;
1da177e4 1538
5f8c7c98
RD
1539 if (($anon_struct_union == 1) && ($type eq "") &&
1540 ($param eq "}")) {
1541 return; # ignore the ending }; from anon. struct/union
1542 }
1543
1544 $anon_struct_union = 0;
f9b5c530 1545 $param =~ s/[\[\)].*//;
1da177e4 1546
a6d3fe77 1547 if ($type eq "" && $param =~ /\.\.\.$/)
1da177e4 1548 {
c950a173
SF
1549 if (!$param =~ /\w\.\.\.$/) {
1550 # handles unnamed variable parameters
1551 $param = "...";
1552 }
43756e34
JN
1553 elsif ($param =~ /\w\.\.\.$/) {
1554 # for named variable parameters of the form `x...`, remove the dots
1555 $param =~ s/\.\.\.$//;
1556 }
ced69090
RD
1557 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
1558 $parameterdescs{$param} = "variable arguments";
1559 }
1da177e4
LT
1560 }
1561 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1562 {
1da177e4
LT
1563 $param="void";
1564 $parameterdescs{void} = "no arguments";
1565 }
134fe01b
RD
1566 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1567 # handle unnamed (anonymous) union or struct:
1568 {
1569 $type = $param;
5f8c7c98 1570 $param = "{unnamed_" . $param . "}";
134fe01b 1571 $parameterdescs{$param} = "anonymous\n";
5f8c7c98 1572 $anon_struct_union = 1;
134fe01b
RD
1573 }
1574
a6d3fe77 1575 # warn if parameter has no description
134fe01b
RD
1576 # (but ignore ones starting with # as these are not parameters
1577 # but inline preprocessor statements);
151c468b 1578 # Note: It will also ignore void params and unnamed structs/unions
f9b5c530 1579 if (!defined $parameterdescs{$param} && $param !~ /^#/) {
151c468b 1580 $parameterdescs{$param} = $undescribed;
a6d3fe77 1581
be5cd20c 1582 if (show_warnings($type, $declaration_name) && $param !~ /\./) {
2defb272
MCC
1583 print STDERR
1584 "${file}:$.: warning: Function parameter or member '$param' not described in '$declaration_name'\n";
1585 ++$warnings;
1586 }
3c308798 1587 }
1da177e4 1588
25985edc 1589 # strip spaces from $param so that it is one continuous string
e34e7dbb
RD
1590 # on @parameterlist;
1591 # this fixes a problem where check_sections() cannot find
1592 # a parameter like "addr[6 + 2]" because it actually appears
1593 # as "addr[6", "+", "2]" on the parameter list;
1594 # but it's better to maintain the param string unchanged for output,
1595 # so just weaken the string compare in check_sections() to ignore
1596 # "[blah" in a parameter string;
1597 ###$param =~ s/\s*//g;
1da177e4 1598 push @parameterlist, $param;
02a4f4fe 1599 $type =~ s/\s\s+/ /g;
1da177e4
LT
1600 $parametertypes{$param} = $type;
1601}
1602
1081de2d
MCC
1603sub check_sections($$$$$) {
1604 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_;
a1d94aa5
RD
1605 my @sects = split ' ', $sectcheck;
1606 my @prms = split ' ', $prmscheck;
1607 my $err;
1608 my ($px, $sx);
1609 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
1610
1611 foreach $sx (0 .. $#sects) {
1612 $err = 1;
1613 foreach $px (0 .. $#prms) {
1614 $prm_clean = $prms[$px];
1615 $prm_clean =~ s/\[.*\]//;
1f3a6688 1616 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
e34e7dbb
RD
1617 # ignore array size in a parameter string;
1618 # however, the original param string may contain
1619 # spaces, e.g.: addr[6 + 2]
1620 # and this appears in @prms as "addr[6" since the
1621 # parameter list is split at spaces;
1622 # hence just ignore "[..." for the sections check;
1623 $prm_clean =~ s/\[.*//;
1624
a1d94aa5
RD
1625 ##$prm_clean =~ s/^\**//;
1626 if ($prm_clean eq $sects[$sx]) {
1627 $err = 0;
1628 last;
1629 }
1630 }
1631 if ($err) {
1632 if ($decl_type eq "function") {
d40e1e65 1633 print STDERR "${file}:$.: warning: " .
a1d94aa5
RD
1634 "Excess function parameter " .
1635 "'$sects[$sx]' " .
1636 "description in '$decl_name'\n";
1637 ++$warnings;
a1d94aa5
RD
1638 }
1639 }
1640 }
1641}
1642
4092bac7
YB
1643##
1644# Checks the section describing the return value of a function.
1645sub check_return_section {
1646 my $file = shift;
1647 my $declaration_name = shift;
1648 my $return_type = shift;
1649
1650 # Ignore an empty return type (It's a macro)
1651 # Ignore functions with a "void" return type. (But don't ignore "void *")
1652 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
1653 return;
1654 }
1655
1656 if (!defined($sections{$section_return}) ||
1657 $sections{$section_return} eq "") {
d40e1e65 1658 print STDERR "${file}:$.: warning: " .
4092bac7
YB
1659 "No description found for return value of " .
1660 "'$declaration_name'\n";
1661 ++$warnings;
1662 }
1663}
1664
1da177e4
LT
1665##
1666# takes a function prototype and the name of the current file being
1667# processed and spits out all the details stored in the global
1668# arrays/hashes.
1669sub dump_function($$) {
1670 my $prototype = shift;
1671 my $file = shift;
cbb4d3e6 1672 my $noret = 0;
1da177e4 1673
5eb6b4b3
MCC
1674 print_lineno($.);
1675
1da177e4
LT
1676 $prototype =~ s/^static +//;
1677 $prototype =~ s/^extern +//;
4dc3b16b 1678 $prototype =~ s/^asmlinkage +//;
1da177e4
LT
1679 $prototype =~ s/^inline +//;
1680 $prototype =~ s/^__inline__ +//;
32e79401
RD
1681 $prototype =~ s/^__inline +//;
1682 $prototype =~ s/^__always_inline +//;
1683 $prototype =~ s/^noinline +//;
74fc5c65 1684 $prototype =~ s/__init +//;
20072205 1685 $prototype =~ s/__init_or_module +//;
270a0096 1686 $prototype =~ s/__meminit +//;
70c95b00 1687 $prototype =~ s/__must_check +//;
0df7c0e3 1688 $prototype =~ s/__weak +//;
0891f959 1689 $prototype =~ s/__sched +//;
95e760cb 1690 $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//;
cbb4d3e6 1691 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
b1aaa546
PB
1692 $prototype =~ s/__attribute__\s*\(\(
1693 (?:
1694 [\w\s]++ # attribute name
1695 (?:\([^)]*+\))? # attribute arguments
1696 \s*+,? # optional comma at the end
1697 )+
1698 \)\)\s+//x;
1da177e4
LT
1699
1700 # Yes, this truly is vile. We are looking for:
1701 # 1. Return type (may be nothing if we're looking at a macro)
1702 # 2. Function name
1703 # 3. Function parameters.
1704 #
1705 # All the while we have to watch out for function pointer parameters
1706 # (which IIRC is what the two sections are for), C types (these
1707 # regexps don't even start to express all the possibilities), and
1708 # so on.
1709 #
1710 # If you mess with these regexps, it's a good idea to check that
1711 # the following functions' documentation still comes out right:
1712 # - parport_register_device (function pointer parameters)
1713 # - atomic_set (macro)
9598f91f 1714 # - pci_match_device, __copy_to_user (long return type)
1da177e4 1715
cbb4d3e6
HG
1716 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
1717 # This is an object-like macro, it has no return type and no parameter
1718 # list.
1719 # Function-like macros are not allowed to have spaces between
1720 # declaration_name and opening parenthesis (notice the \s+).
1721 $return_type = $1;
1722 $declaration_name = $2;
1723 $noret = 1;
1724 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1da177e4 1725 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
5a0bc578 1726 $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1da177e4 1727 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
94b3e03c 1728 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1da177e4 1729 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
5a0bc578 1730 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1da177e4
LT
1731 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1732 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
5a0bc578 1733 $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1da177e4 1734 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
5a0bc578 1735 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1da177e4 1736 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
5a0bc578 1737 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
9598f91f 1738 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
5a0bc578
MW
1739 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1740 $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1da177e4
LT
1741 $return_type = $1;
1742 $declaration_name = $2;
1743 my $args = $3;
1744
151c468b 1745 create_parameterlist($args, ',', $file, $declaration_name);
1da177e4 1746 } else {
d40e1e65 1747 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
1da177e4
LT
1748 return;
1749 }
1750
47bcacfd
MCC
1751 my $prms = join " ", @parameterlist;
1752 check_sections($file, $declaration_name, "function", $sectcheck, $prms);
1753
1754 # This check emits a lot of warnings at the moment, because many
1755 # functions don't have a 'Return' doc section. So until the number
1756 # of warnings goes sufficiently down, the check is only performed in
1757 # verbose mode.
1758 # TODO: always perform the check.
1759 if ($verbose && !$noret) {
1760 check_return_section($file, $declaration_name, $return_type);
1761 }
4092bac7 1762
47bcacfd
MCC
1763 # The function parser can be called with a typedef parameter.
1764 # Handle it.
1765 if ($return_type =~ /typedef/) {
1766 output_declaration($declaration_name,
1767 'function',
1768 {'function' => $declaration_name,
1769 'typedef' => 1,
1770 'module' => $modulename,
1771 'functiontype' => $return_type,
1772 'parameterlist' => \@parameterlist,
1773 'parameterdescs' => \%parameterdescs,
1774 'parametertypes' => \%parametertypes,
1775 'sectionlist' => \@sectionlist,
1776 'sections' => \%sections,
1777 'purpose' => $declaration_purpose
1778 });
1779 } else {
1780 output_declaration($declaration_name,
1781 'function',
1782 {'function' => $declaration_name,
1783 'module' => $modulename,
1784 'functiontype' => $return_type,
1785 'parameterlist' => \@parameterlist,
1786 'parameterdescs' => \%parameterdescs,
1787 'parametertypes' => \%parametertypes,
1788 'sectionlist' => \@sectionlist,
1789 'sections' => \%sections,
1790 'purpose' => $declaration_purpose
1791 });
1792 }
1da177e4
LT
1793}
1794
1da177e4
LT
1795sub reset_state {
1796 $function = "";
1da177e4
LT
1797 %parameterdescs = ();
1798 %parametertypes = ();
1799 @parameterlist = ();
1800 %sections = ();
1801 @sectionlist = ();
a1d94aa5
RD
1802 $sectcheck = "";
1803 $struct_actual = "";
1da177e4 1804 $prototype = "";
3c3b809e 1805
48af606a
JN
1806 $state = STATE_NORMAL;
1807 $inline_doc_state = STATE_INLINE_NA;
1da177e4
LT
1808}
1809
56afb0f8
JB
1810sub tracepoint_munge($) {
1811 my $file = shift;
1812 my $tracepointname = 0;
1813 my $tracepointargs = 0;
1814
3a9089fd 1815 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
56afb0f8
JB
1816 $tracepointname = $1;
1817 }
3a9089fd
JB
1818 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
1819 $tracepointname = $1;
1820 }
1821 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
1822 $tracepointname = $2;
1823 }
1824 $tracepointname =~ s/^\s+//; #strip leading whitespace
1825 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
56afb0f8
JB
1826 $tracepointargs = $1;
1827 }
1828 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
d40e1e65 1829 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
56afb0f8
JB
1830 "$prototype\n";
1831 } else {
1832 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
1833 }
1834}
1835
b4870bc5
RD
1836sub syscall_munge() {
1837 my $void = 0;
1838
7c9aa015 1839 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's
b4870bc5
RD
1840## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
1841 if ($prototype =~ m/SYSCALL_DEFINE0/) {
1842 $void = 1;
1843## $prototype = "long sys_$1(void)";
1844 }
1845
1846 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
1847 if ($prototype =~ m/long (sys_.*?),/) {
1848 $prototype =~ s/,/\(/;
1849 } elsif ($void) {
1850 $prototype =~ s/\)/\(void\)/;
1851 }
1852
1853 # now delete all of the odd-number commas in $prototype
1854 # so that arg types & arg names don't have a comma between them
1855 my $count = 0;
1856 my $len = length($prototype);
1857 if ($void) {
1858 $len = 0; # skip the for-loop
1859 }
1860 for (my $ix = 0; $ix < $len; $ix++) {
1861 if (substr($prototype, $ix, 1) eq ',') {
1862 $count++;
1863 if ($count % 2 == 1) {
1864 substr($prototype, $ix, 1) = ' ';
1865 }
1866 }
1867 }
1868}
1869
b7afa92b 1870sub process_proto_function($$) {
1da177e4
LT
1871 my $x = shift;
1872 my $file = shift;
1873
51f5a0c8
RD
1874 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1875
890c78c2 1876 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
1da177e4
LT
1877 # do nothing
1878 }
1879 elsif ($x =~ /([^\{]*)/) {
3c308798 1880 $prototype .= $1;
1da177e4 1881 }
b4870bc5 1882
890c78c2 1883 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
3c308798 1884 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
1da177e4
LT
1885 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1886 $prototype =~ s@^\s+@@gos; # strip leading spaces
7ae281b0
MCC
1887
1888 # Handle prototypes for function pointers like:
1889 # int (*pcs_config)(struct foo)
1890 $prototype =~ s@^(\S+\s+)\(\s*\*(\S+)\)@$1$2@gos;
1891
b4870bc5
RD
1892 if ($prototype =~ /SYSCALL_DEFINE/) {
1893 syscall_munge();
1894 }
3a9089fd
JB
1895 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
1896 $prototype =~ /DEFINE_SINGLE_EVENT/)
1897 {
56afb0f8
JB
1898 tracepoint_munge($file);
1899 }
b4870bc5 1900 dump_function($prototype, $file);
1da177e4
LT
1901 reset_state();
1902 }
1903}
1904
b7afa92b 1905sub process_proto_type($$) {
1da177e4
LT
1906 my $x = shift;
1907 my $file = shift;
1908
1da177e4
LT
1909 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1910 $x =~ s@^\s+@@gos; # strip leading spaces
1911 $x =~ s@\s+$@@gos; # strip trailing spaces
51f5a0c8
RD
1912 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1913
1da177e4
LT
1914 if ($x =~ /^#/) {
1915 # To distinguish preprocessor directive from regular declaration later.
1916 $x .= ";";
1917 }
1918
1919 while (1) {
673bb2df 1920 if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) {
463a0fdc
MH
1921 if( length $prototype ) {
1922 $prototype .= " "
1923 }
1da177e4
LT
1924 $prototype .= $1 . $2;
1925 ($2 eq '{') && $brcount++;
1926 ($2 eq '}') && $brcount--;
1927 if (($2 eq ';') && ($brcount == 0)) {
b9d97328 1928 dump_declaration($prototype, $file);
1da177e4 1929 reset_state();
3c308798 1930 last;
1da177e4
LT
1931 }
1932 $x = $3;
3c308798 1933 } else {
1da177e4
LT
1934 $prototype .= $x;
1935 last;
1936 }
1937 }
1938}
1939
6b5b55f6 1940
1ad560e4 1941sub map_filename($) {
2283a117 1942 my $file;
68f86662 1943 my ($orig_file) = @_;
1da177e4 1944
2283a117 1945 if (defined($ENV{'SRCTREE'})) {
68f86662 1946 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
1ad560e4 1947 } else {
68f86662 1948 $file = $orig_file;
2283a117 1949 }
1ad560e4 1950
1da177e4
LT
1951 if (defined($source_map{$file})) {
1952 $file = $source_map{$file};
1953 }
1954
1ad560e4
JN
1955 return $file;
1956}
1957
88c2b57d
JN
1958sub process_export_file($) {
1959 my ($orig_file) = @_;
1960 my $file = map_filename($orig_file);
1961
1962 if (!open(IN,"<$file")) {
1963 print STDERR "Error: Cannot open file $file\n";
1964 ++$errors;
1965 return;
1966 }
1967
1968 while (<IN>) {
1969 if (/$export_symbol/) {
eab795dd 1970 next if (defined($nosymbol_table{$2}));
88c2b57d
JN
1971 $function_table{$2} = 1;
1972 }
1973 }
1974
1975 close(IN);
1976}
1977
07048d13
JC
1978#
1979# Parsers for the various processing states.
1980#
1981# STATE_NORMAL: looking for the /** to begin everything.
1982#
1983sub process_normal() {
1984 if (/$doc_start/o) {
1985 $state = STATE_NAME; # next line is always the function name
1986 $in_doc_sect = 0;
1987 $declaration_start_line = $. + 1;
1988 }
1989}
1990
3cac2bc4
JC
1991#
1992# STATE_NAME: Looking for the "name - description" line
1993#
1994sub process_name($$) {
1995 my $file = shift;
1ad560e4 1996 my $identifier;
1ad560e4 1997 my $descr;
3cac2bc4
JC
1998
1999 if (/$doc_block/o) {
2000 $state = STATE_DOCBLOCK;
2001 $contents = "";
2002 $new_start_line = $. + 1;
2003
2004 if ( $1 eq "" ) {
2005 $section = $section_intro;
2006 } else {
2007 $section = $1;
2008 }
2009 }
2010 elsif (/$doc_decl/o) {
2011 $identifier = $1;
fcdf1df2 2012 if (/\s*([\w\s]+?)(\(\))?\s*-/) {
3cac2bc4
JC
2013 $identifier = $1;
2014 }
07048d13 2015
3cac2bc4
JC
2016 $state = STATE_BODY;
2017 # if there's no @param blocks need to set up default section
2018 # here
2019 $contents = "";
2020 $section = $section_default;
2021 $new_start_line = $. + 1;
2022 if (/-(.*)/) {
2023 # strip leading/trailing/multiple spaces
2024 $descr= $1;
2025 $descr =~ s/^\s*//;
2026 $descr =~ s/\s*$//;
2027 $descr =~ s/\s+/ /g;
2028 $declaration_purpose = $descr;
2029 $state = STATE_BODY_MAYBE;
2030 } else {
2031 $declaration_purpose = "";
2032 }
2033
2034 if (($declaration_purpose eq "") && $verbose) {
2035 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
2036 print STDERR $_;
2037 ++$warnings;
2038 }
2039
cf419d54 2040 if ($identifier =~ m/^struct\b/) {
3cac2bc4 2041 $decl_type = 'struct';
cf419d54 2042 } elsif ($identifier =~ m/^union\b/) {
3cac2bc4 2043 $decl_type = 'union';
cf419d54 2044 } elsif ($identifier =~ m/^enum\b/) {
3cac2bc4 2045 $decl_type = 'enum';
cf419d54 2046 } elsif ($identifier =~ m/^typedef\b/) {
3cac2bc4
JC
2047 $decl_type = 'typedef';
2048 } else {
2049 $decl_type = 'function';
2050 }
2051
2052 if ($verbose) {
2053 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
2054 }
2055 } else {
2056 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
2057 " - I thought it was a doc line\n";
2058 ++$warnings;
2059 $state = STATE_NORMAL;
2060 }
2061}
07048d13 2062
d742f24d
JC
2063
2064#
2065# STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment.
2066#
2067sub process_body($$) {
2068 my $file = shift;
2069
43756e34
JN
2070 # Until all named variable macro parameters are
2071 # documented using the bare name (`x`) rather than with
2072 # dots (`x...`), strip the dots:
2073 if ($section =~ /\w\.\.\.$/) {
2074 $section =~ s/\.\.\.$//;
2075
2076 if ($verbose) {
2077 print STDERR "${file}:$.: warning: Variable macro arguments should be documented without dots\n";
2078 ++$warnings;
2079 }
2080 }
2081
0d55d48b
MCC
2082 if ($state == STATE_BODY_WITH_BLANK_LINE && /^\s*\*\s?\S/) {
2083 dump_section($file, $section, $contents);
2084 $section = $section_default;
2085 $contents = "";
2086 }
2087
d742f24d
JC
2088 if (/$doc_sect/i) { # case insensitive for supported section names
2089 $newsection = $1;
2090 $newcontents = $2;
2091
2092 # map the supported section names to the canonical names
2093 if ($newsection =~ m/^description$/i) {
2094 $newsection = $section_default;
2095 } elsif ($newsection =~ m/^context$/i) {
2096 $newsection = $section_context;
2097 } elsif ($newsection =~ m/^returns?$/i) {
2098 $newsection = $section_return;
2099 } elsif ($newsection =~ m/^\@return$/) {
2100 # special: @return is a section, not a param description
2101 $newsection = $section_return;
2102 }
2103
2104 if (($contents ne "") && ($contents ne "\n")) {
2105 if (!$in_doc_sect && $verbose) {
2106 print STDERR "${file}:$.: warning: contents before sections\n";
2107 ++$warnings;
2108 }
2109 dump_section($file, $section, $contents);
2110 $section = $section_default;
2111 }
2112
2113 $in_doc_sect = 1;
2114 $state = STATE_BODY;
2115 $contents = $newcontents;
2116 $new_start_line = $.;
2117 while (substr($contents, 0, 1) eq " ") {
2118 $contents = substr($contents, 1);
2119 }
2120 if ($contents ne "") {
2121 $contents .= "\n";
2122 }
2123 $section = $newsection;
2124 $leading_space = undef;
2125 } elsif (/$doc_end/) {
2126 if (($contents ne "") && ($contents ne "\n")) {
2127 dump_section($file, $section, $contents);
2128 $section = $section_default;
2129 $contents = "";
2130 }
2131 # look for doc_com + <text> + doc_end:
2132 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
2133 print STDERR "${file}:$.: warning: suspicious ending line: $_";
2134 ++$warnings;
2135 }
2136
2137 $prototype = "";
2138 $state = STATE_PROTO;
2139 $brcount = 0;
2140 } elsif (/$doc_content/) {
d742f24d 2141 if ($1 eq "") {
0d55d48b 2142 if ($section eq $section_context) {
d742f24d
JC
2143 dump_section($file, $section, $contents);
2144 $section = $section_default;
2145 $contents = "";
2146 $new_start_line = $.;
0d55d48b 2147 $state = STATE_BODY;
d742f24d 2148 } else {
0d55d48b
MCC
2149 if ($section ne $section_default) {
2150 $state = STATE_BODY_WITH_BLANK_LINE;
2151 } else {
2152 $state = STATE_BODY;
2153 }
d742f24d
JC
2154 $contents .= "\n";
2155 }
d742f24d
JC
2156 } elsif ($state == STATE_BODY_MAYBE) {
2157 # Continued declaration purpose
2158 chomp($declaration_purpose);
2159 $declaration_purpose .= " " . $1;
2160 $declaration_purpose =~ s/\s+/ /g;
2161 } else {
2162 my $cont = $1;
2163 if ($section =~ m/^@/ || $section eq $section_context) {
2164 if (!defined $leading_space) {
2165 if ($cont =~ m/^(\s+)/) {
2166 $leading_space = $1;
2167 } else {
2168 $leading_space = "";
2169 }
2170 }
2171 $cont =~ s/^$leading_space//;
2172 }
2173 $contents .= $cont . "\n";
2174 }
2175 } else {
2176 # i dont know - bad line? ignore.
2177 print STDERR "${file}:$.: warning: bad line: $_";
2178 ++$warnings;
2179 }
2180}
2181
2182
cc794812
JC
2183#
2184# STATE_PROTO: reading a function/whatever prototype.
2185#
2186sub process_proto($$) {
2187 my $file = shift;
2188
2189 if (/$doc_inline_oneline/) {
2190 $section = $1;
2191 $contents = $2;
2192 if ($contents ne "") {
2193 $contents .= "\n";
2194 dump_section($file, $section, $contents);
2195 $section = $section_default;
2196 $contents = "";
2197 }
2198 } elsif (/$doc_inline_start/) {
2199 $state = STATE_INLINE;
2200 $inline_doc_state = STATE_INLINE_NAME;
2201 } elsif ($decl_type eq 'function') {
2202 process_proto_function($_, $file);
2203 } else {
2204 process_proto_type($_, $file);
2205 }
2206}
2207
c17add56
JC
2208#
2209# STATE_DOCBLOCK: within a DOC: block.
2210#
2211sub process_docblock($$) {
2212 my $file = shift;
2213
2214 if (/$doc_end/) {
2215 dump_doc_section($file, $section, $contents);
2216 $section = $section_default;
2217 $contents = "";
2218 $function = "";
2219 %parameterdescs = ();
2220 %parametertypes = ();
2221 @parameterlist = ();
2222 %sections = ();
2223 @sectionlist = ();
2224 $prototype = "";
2225 $state = STATE_NORMAL;
2226 } elsif (/$doc_content/) {
2227 if ( $1 eq "" ) {
2228 $contents .= $blankline;
2229 } else {
2230 $contents .= $1 . "\n";
2231 }
2232 }
2233}
2234
2235#
2236# STATE_INLINE: docbook comments within a prototype.
2237#
2238sub process_inline($$) {
2239 my $file = shift;
2240
2241 # First line (state 1) needs to be a @parameter
2242 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
2243 $section = $1;
2244 $contents = $2;
2245 $new_start_line = $.;
2246 if ($contents ne "") {
2247 while (substr($contents, 0, 1) eq " ") {
2248 $contents = substr($contents, 1);
2249 }
2250 $contents .= "\n";
2251 }
2252 $inline_doc_state = STATE_INLINE_TEXT;
2253 # Documentation block end */
2254 } elsif (/$doc_inline_end/) {
2255 if (($contents ne "") && ($contents ne "\n")) {
2256 dump_section($file, $section, $contents);
2257 $section = $section_default;
2258 $contents = "";
2259 }
2260 $state = STATE_PROTO;
2261 $inline_doc_state = STATE_INLINE_NA;
2262 # Regular text
2263 } elsif (/$doc_content/) {
2264 if ($inline_doc_state == STATE_INLINE_TEXT) {
2265 $contents .= $1 . "\n";
2266 # nuke leading blank lines
2267 if ($contents =~ /^\s*$/) {
2268 $contents = "";
2269 }
2270 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
2271 $inline_doc_state = STATE_INLINE_ERROR;
2272 print STDERR "${file}:$.: warning: ";
2273 print STDERR "Incorrect use of kernel-doc format: $_";
2274 ++$warnings;
2275 }
2276 }
2277}
2278
cc794812 2279
1ad560e4
JN
2280sub process_file($) {
2281 my $file;
1ad560e4
JN
2282 my $initial_section_counter = $section_counter;
2283 my ($orig_file) = @_;
1ad560e4
JN
2284
2285 $file = map_filename($orig_file);
2286
dbe8ba00 2287 if (!open(IN_FILE,"<$file")) {
1da177e4
LT
2288 print STDERR "Error: Cannot open file $file\n";
2289 ++$errors;
2290 return;
2291 }
2292
a9e7314b
ID
2293 $. = 1;
2294
1da177e4 2295 $section_counter = 0;
dbe8ba00 2296 while (<IN_FILE>) {
65478428 2297 while (s/\\\s*$//) {
dbe8ba00 2298 $_ .= <IN_FILE>;
65478428 2299 }
7c9aa015
MCC
2300 # Replace tabs by spaces
2301 while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {};
c17add56 2302 # Hand this line to the appropriate state handler
48af606a 2303 if ($state == STATE_NORMAL) {
07048d13 2304 process_normal();
3cac2bc4
JC
2305 } elsif ($state == STATE_NAME) {
2306 process_name($file, $_);
0d55d48b
MCC
2307 } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE ||
2308 $state == STATE_BODY_WITH_BLANK_LINE) {
d742f24d 2309 process_body($file, $_);
48af606a 2310 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
c17add56 2311 process_inline($file, $_);
cc794812
JC
2312 } elsif ($state == STATE_PROTO) {
2313 process_proto($file, $_);
48af606a 2314 } elsif ($state == STATE_DOCBLOCK) {
c17add56 2315 process_docblock($file, $_);
3c308798 2316 }
1da177e4 2317 }
c17add56
JC
2318
2319 # Make sure we got something interesting.
b0d60bfb
JC
2320 if ($initial_section_counter == $section_counter && $
2321 output_mode ne "none") {
2322 if ($output_selection == OUTPUT_INCLUDE) {
2323 print STDERR "${file}:1: warning: '$_' not found\n"
2324 for keys %function_table;
3a025e1d 2325 }
b0d60bfb
JC
2326 else {
2327 print STDERR "${file}:1: warning: no structured comments found\n";
e946c43a 2328 }
1da177e4 2329 }
dbe8ba00 2330 close IN_FILE;
1da177e4 2331}
8484baaa
RD
2332
2333
efa44475 2334$sphinx_major = get_sphinx_version();
8484baaa
RD
2335$kernelversion = get_kernel_version();
2336
2337# generate a sequence of code that will splice in highlighting information
2338# using the s// operator.
1ef06233 2339for (my $k = 0; $k < @highlights; $k++) {
4d732701
DCLP
2340 my $pattern = $highlights[$k][0];
2341 my $result = $highlights[$k][1];
2342# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
2343 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
8484baaa
RD
2344}
2345
2346# Read the file that maps relative names to absolute names for
2347# separate source and object directories and for shadow trees.
2348if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
2349 my ($relname, $absname);
2350 while(<SOURCE_MAP>) {
2351 chop();
2352 ($relname, $absname) = (split())[0..1];
2353 $relname =~ s:^/+::;
2354 $source_map{$relname} = $absname;
2355 }
2356 close(SOURCE_MAP);
2357}
2358
88c2b57d
JN
2359if ($output_selection == OUTPUT_EXPORTED ||
2360 $output_selection == OUTPUT_INTERNAL) {
c9b2cfb3
JN
2361
2362 push(@export_file_list, @ARGV);
2363
88c2b57d
JN
2364 foreach (@export_file_list) {
2365 chomp;
2366 process_export_file($_);
2367 }
2368}
2369
8484baaa
RD
2370foreach (@ARGV) {
2371 chomp;
2372 process_file($_);
2373}
2374if ($verbose && $errors) {
2375 print STDERR "$errors errors\n";
2376}
2377if ($verbose && $warnings) {
2378 print STDERR "$warnings warnings\n";
2379}
2380
2c12c810
PLB
2381if ($Werror && $warnings) {
2382 print STDERR "$warnings warnings as Errors\n";
2383 exit($warnings);
2384} else {
2385 exit($output_mode eq "none" ? 0 : $errors)
2386}