blob: 2deddb876156e4a57fbdb74bb217d6cf1b4f5445 [file] [log] [blame]
Kamil Rytarowskicb77f0d2017-05-07 23:25:26 +02001#!/usr/bin/env perl
Linus Torvalds1da177e2005-04-16 15:20:36 -07002
Kamil Rytarowskicb77f0d2017-05-07 23:25:26 +02003use warnings;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004use strict;
5
6## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ##
7## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ##
8## Copyright (C) 2001 Simon Huggins ##
Randy Dunlap70c95b02012-01-21 10:31:54 -08009## Copyright (C) 2005-2012 Randy Dunlap ##
Dan Luedtke1b40c192012-08-12 10:46:15 +020010## Copyright (C) 2012 Dan Luedtke ##
Linus Torvalds1da177e2005-04-16 15:20:36 -070011## ##
12## #define enhancements by Armin Kuster <akuster@mvista.com> ##
13## Copyright (c) 2000 MontaVista Software, Inc. ##
14## ##
15## This software falls under the GNU General Public License. ##
16## Please read the COPYING file for more information ##
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018# 18/01/2001 - Cleanups
19# Functions prototyped as foo(void) same as foo()
20# Stop eval'ing where we don't need to.
21# -- huggie@earth.li
22
23# 27/06/2001 - Allowed whitespace after initial "/**" and
24# allowed comments before function declarations.
25# -- Christian Kreibich <ck@whoop.org>
26
27# Still to do:
28# - add perldoc documentation
29# - Look more closely at some of the scarier bits :)
30
31# 26/05/2001 - Support for separate source and object trees.
32# Return error code.
33# Keith Owens <kaos@ocs.com.au>
34
35# 23/09/2001 - Added support for typedefs, structs, enums and unions
36# Support for Context section; can be terminated using empty line
37# Small fixes (like spaces vs. \s in regex)
38# -- Tim Jansen <tim@tjansen.de>
39
Dan Luedtke1b40c192012-08-12 10:46:15 +020040# 25/07/2012 - Added support for HTML5
41# -- Dan Luedtke <mail@danrl.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Jani Nikulafadc0b32016-05-12 16:15:36 +030043sub usage {
44 my $message = <<"EOF";
45Usage: $0 [OPTION ...] FILE ...
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Jani Nikulafadc0b32016-05-12 16:15:36 +030047Read C language source or header FILEs, extract embedded documentation comments,
48and print formatted documentation to standard output.
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Jani Nikulafadc0b32016-05-12 16:15:36 +030050The documentation comments are identified by "/**" opening comment mark. See
Mauro Carvalho Chehab857af3b2017-12-18 10:30:08 -020051Documentation/doc-guide/kernel-doc.rst for the documentation comment syntax.
Jani Nikulafadc0b32016-05-12 16:15:36 +030052
53Output format selection (mutually exclusive):
Jani Nikulafadc0b32016-05-12 16:15:36 +030054 -man Output troff manual page format. This is the default.
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +030055 -rst Output reStructuredText format.
Matthew Wilcox3a025e12017-11-20 10:40:40 -080056 -none Do not output documentation, only warnings.
Jani Nikulafadc0b32016-05-12 16:15:36 +030057
58Output selection (mutually exclusive):
Jani Nikula86ae2e32016-01-21 13:05:22 +020059 -export Only output documentation for symbols that have been
60 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
Jani Nikulac9b2cfb2016-06-07 11:05:53 +030061 in any input FILE or -export-file FILE.
Jani Nikula86ae2e32016-01-21 13:05:22 +020062 -internal Only output documentation for symbols that have NOT been
63 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
Jani Nikulac9b2cfb2016-06-07 11:05:53 +030064 in any input FILE or -export-file FILE.
Jani Nikulafadc0b32016-05-12 16:15:36 +030065 -function NAME Only output documentation for the given function(s)
66 or DOC: section title(s). All other functions and DOC:
67 sections are ignored. May be specified multiple times.
68 -nofunction NAME Do NOT output documentation for the given function(s);
69 only output documentation for the other functions and
70 DOC: sections. May be specified multiple times.
71
72Output selection modifiers:
73 -no-doc-sections Do not output DOC: sections.
Daniel Vetter0b0f5f292016-06-03 22:21:34 +020074 -enable-lineno Enable output of #define LINENO lines. Only works with
75 reStructuredText format.
Jani Nikula88c2b572016-06-07 11:00:52 +030076 -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.
Jani Nikulafadc0b32016-05-12 16:15:36 +030079
80Other parameters:
81 -v Verbose output, more warnings and other information.
82 -h Print this help.
83
84EOF
85 print $message;
86 exit 1;
87}
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89#
90# format of comments.
91# In the following table, (...)? signifies optional structure.
92# (...)* signifies 0 or more structure elements
93# /**
94# * function_name(:)? (- short description)?
95# (* @parameterx: (description of parameter x)?)*
96# (* a blank line)?
97# * (Description:)? (Description of function)?
98# * (section header: (section description)? )*
99# (*)?*/
100#
101# So .. the trivial example would be:
102#
103# /**
104# * my_function
Randy Dunlapb9d973282009-06-09 08:50:38 -0700105# */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#
Randy Dunlap891dcd22007-02-10 01:45:53 -0800107# If the Description: header tag is omitted, then there must be a blank line
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108# after the last parameter specification.
109# e.g.
110# /**
111# * my_function - does my stuff
112# * @my_arg: its mine damnit
113# *
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800114# * Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115# */
116#
117# or, could also use:
118# /**
119# * my_function - does my stuff
120# * @my_arg: its mine damnit
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800121# * Description: Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122# */
123# etc.
124#
Randy Dunlapb9d973282009-06-09 08:50:38 -0700125# Besides functions you can also write documentation for structs, unions,
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800126# enums and typedefs. Instead of the function name you must write the name
127# of the declaration; the struct/union/enum/typedef must always precede
128# the name. Nesting of declarations is not supported.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129# Use the argument mechanism to document members or constants.
130# e.g.
131# /**
132# * struct my_struct - short description
133# * @a: first member
134# * @b: second member
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800135# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136# * Longer description
137# */
138# struct my_struct {
139# int a;
140# int b;
Martin Waitzaeec46b2005-11-13 16:08:13 -0800141# /* private: */
142# int c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143# };
144#
145# All descriptions can be multiline, except the short function description.
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800146#
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300147# For really longs structs, you can also describe arguments inside the
148# body of the struct.
149# eg.
150# /**
151# * struct my_struct - short description
152# * @a: first member
153# * @b: second member
154# *
155# * Longer description
156# */
157# struct my_struct {
158# int a;
159# int b;
160# /**
161# * @c: This is longer description of C
162# *
163# * You can use paragraphs to describe arguments
164# * using this method.
165# */
166# int c;
167# };
168#
169# This should be use only for struct/enum members.
170#
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800171# You can also add additional sections. When documenting kernel functions you
172# should document the "Context:" of the function, e.g. whether the functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173# can be called form interrupts. Unlike other sections you can end it with an
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800174# empty line.
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100175# A non-void function should have a "Return:" section describing the return
176# value(s).
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800177# Example-sections should contain the string EXAMPLE so that they are marked
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178# appropriately in DocBook.
179#
180# Example:
181# /**
182# * user_function - function that can only be called in user context
183# * @a: some argument
184# * Context: !in_interrupt()
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800185# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186# * Some description
187# * Example:
188# * user_function(22);
189# */
190# ...
191#
192#
193# All descriptive text is further processed, scanning for the following special
194# patterns, which are highlighted appropriately.
195#
196# 'funcname()' - function
197# '$ENVVAR' - environmental variable
198# '&struct_name' - name of a structure (up to two words including 'struct')
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100199# '&struct_name.member' - name of a structure member
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200# '@parameter' - name of a parameter
201# '%CONST' - name of a constant.
Mauro Carvalho Chehabb97f1932017-03-30 17:11:28 -0300202# '``LITERAL``' - literal string without any spaces on it.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Randy Dunlap8484baa2011-01-05 16:28:43 -0800204## init lots of data
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206my $errors = 0;
207my $warnings = 0;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -0700208my $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210# match expressions used to find embedded type information
Mauro Carvalho Chehabb97f1932017-03-30 17:11:28 -0300211my $type_constant = '\b``([^\`]+)``\b';
212my $type_constant2 = '\%([-_\w]+)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213my $type_func = '(\w+)\(\)';
Mauro Carvalho Chehab8ad72162017-12-18 10:30:13 -0200214my $type_param = '\@(\w*(\.\w+)*(\.\.\.)?)';
Jonathan Corbet5219f182016-08-24 16:31:15 -0600215my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216my $type_env = '(\$\w+)';
Paolo Bonzinidf311752017-01-02 16:22:27 +0100217my $type_enum = '\&(enum\s*([_\w]+))';
218my $type_struct = '\&(struct\s*([_\w]+))';
219my $type_typedef = '\&(typedef\s*([_\w]+))';
220my $type_union = '\&(union\s*([_\w]+))';
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100221my $type_member = '\&([_\w]+)(\.|->)([_\w]+)';
Paolo Bonzinidf311752017-01-02 16:22:27 +0100222my $type_fallback = '\&([_\w]+)';
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300223my $type_member_func = $type_member . '\(\)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225# Output conversion substitutions.
226# One for each output format
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228# these are pretty rough
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300229my @highlights_man = (
230 [$type_constant, "\$1"],
Mauro Carvalho Chehabb97f1932017-03-30 17:11:28 -0300231 [$type_constant2, "\$1"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300232 [$type_func, "\\\\fB\$1\\\\fP"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100233 [$type_enum, "\\\\fI\$1\\\\fP"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300234 [$type_struct, "\\\\fI\$1\\\\fP"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100235 [$type_typedef, "\\\\fI\$1\\\\fP"],
236 [$type_union, "\\\\fI\$1\\\\fP"],
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100237 [$type_param, "\\\\fI\$1\\\\fP"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100238 [$type_member, "\\\\fI\$1\$2\$3\\\\fP"],
239 [$type_fallback, "\\\\fI\$1\\\\fP"]
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300240 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241my $blankline_man = "";
242
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300243# rst-mode
244my @highlights_rst = (
245 [$type_constant, "``\$1``"],
Mauro Carvalho Chehabb97f1932017-03-30 17:11:28 -0300246 [$type_constant2, "``\$1``"],
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300247 # Note: need to escape () to avoid func matching later
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100248 [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"],
249 [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"],
Jonathan Corbet5219f182016-08-24 16:31:15 -0600250 [$type_fp_param, "**\$1\\\\(\\\\)**"],
Jani Nikulaa19bce62016-05-26 11:28:16 +0300251 [$type_func, "\\:c\\:func\\:`\$1()`"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100252 [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"],
253 [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"],
254 [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"],
255 [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"],
Jani Nikulaa7291e72016-05-26 13:57:06 +0300256 # in rst this can refer to any type
Paolo Bonzinidf311752017-01-02 16:22:27 +0100257 [$type_fallback, "\\:c\\:type\\:`\$1`"],
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300258 [$type_param, "**\$1**"]
259 );
260my $blankline_rst = "\n";
261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262# read arguments
Randy Dunlapb9d973282009-06-09 08:50:38 -0700263if ($#ARGV == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 usage();
265}
266
Randy Dunlap8484baa2011-01-05 16:28:43 -0800267my $kernelversion;
268my $dohighlight = "";
269
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270my $verbose = 0;
Mauro Carvalho Chehabbdfe2be2017-12-18 10:30:11 -0200271my $output_mode = "rst";
Daniel Santose314ba32012-10-04 17:15:08 -0700272my $output_preformatted = 0;
Johannes Berg4b445952007-10-24 15:08:48 -0700273my $no_doc_sections = 0;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200274my $enable_lineno = 0;
Mauro Carvalho Chehabbdfe2be2017-12-18 10:30:11 -0200275my @highlights = @highlights_rst;
276my $blankline = $blankline_rst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277my $modulename = "Kernel API";
Jani Nikulab6c3f452016-05-29 22:19:35 +0300278
279use constant {
280 OUTPUT_ALL => 0, # output all symbols and doc sections
281 OUTPUT_INCLUDE => 1, # output only specified symbols
282 OUTPUT_EXCLUDE => 2, # output everything except specified symbols
283 OUTPUT_EXPORTED => 3, # output exported symbols
284 OUTPUT_INTERNAL => 4, # output non-exported symbols
285};
286my $output_selection = OUTPUT_ALL;
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100287my $show_not_found = 0;
288
Jani Nikula88c2b572016-06-07 11:00:52 +0300289my @export_file_list;
290
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100291my @build_time;
292if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
293 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
294 @build_time = gmtime($seconds);
295} else {
296 @build_time = localtime;
297}
298
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800299my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
300 'July', 'August', 'September', 'October',
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100301 'November', 'December')[$build_time[4]] .
302 " " . ($build_time[5]+1900);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Randy Dunlap8484baa2011-01-05 16:28:43 -0800304# Essentially these are globals.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700305# They probably want to be tidied up, made more localised or something.
306# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307# could cause "use of undefined value" or other bugs.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700308my ($function, %function_table, %parametertypes, $declaration_purpose);
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200309my $declaration_start_line;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700310my ($type, $declaration_name, $return_type);
Ilya Dryomov1c32fd02010-02-26 13:06:03 -0800311my ($newsection, $newcontents, $prototype, $brcount, %source_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700313if (defined($ENV{'KBUILD_VERBOSE'})) {
314 $verbose = "$ENV{'KBUILD_VERBOSE'}";
315}
316
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800317# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
319# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
320# We keep track of number of generated entries and generate a dummy
321# if needs be to ensure the expanded template can be postprocessed
322# into html.
323my $section_counter = 0;
324
325my $lineprefix="";
326
Jani Nikula48af6062016-05-26 14:56:05 +0300327# Parser states
328use constant {
329 STATE_NORMAL => 0, # normal code
330 STATE_NAME => 1, # looking for function name
Jonathan Corbet17b78712018-02-05 13:56:45 -0700331 STATE_BODY_MAYBE => 2, # body - or maybe more description
332 STATE_BODY => 3, # the body of the comment
333 STATE_PROTO => 4, # scanning prototype
334 STATE_DOCBLOCK => 5, # documentation block
335 STATE_INLINE => 6, # gathering documentation outside main block
Jani Nikula48af6062016-05-26 14:56:05 +0300336};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700338my $in_doc_sect;
Jonathan Corbetd742f242018-02-05 15:36:05 -0700339my $leading_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Jani Nikula48af6062016-05-26 14:56:05 +0300341# Inline documentation state
342use constant {
343 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
344 STATE_INLINE_NAME => 1, # looking for member name (@foo:)
345 STATE_INLINE_TEXT => 2, # looking for member documentation
346 STATE_INLINE_END => 3, # done
347 STATE_INLINE_ERROR => 4, # error - Comment without header was found.
348 # Spit a warning as it's not
349 # proper kernel-doc and ignore the rest.
350};
351my $inline_doc_state;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300352
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353#declaration types: can be
354# 'function', 'struct', 'union', 'enum', 'typedef'
355my $decl_type;
356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
358my $doc_end = '\*/';
359my $doc_com = '\s*\*\s*';
Daniel Santos12ae6772012-10-04 17:15:10 -0700360my $doc_com_body = '\s*\* ?';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700361my $doc_decl = $doc_com . '(\w+)';
Jani Nikulaf624ade2016-05-29 11:35:28 +0300362# @params and a strictly limited set of supported section names
Jonathan Corbet8569de62016-06-09 13:35:05 -0600363my $doc_sect = $doc_com .
Jonathan Corbetef000282016-08-26 07:14:08 -0600364 '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700365my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700366my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Jani Nikula48af6062016-05-26 14:56:05 +0300367my $doc_inline_start = '^\s*/\*\*\s*$';
368my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
369my $doc_inline_end = '^\s*\*/\s*$';
Jani Nikula0c9aa202016-11-16 17:26:16 +0200370my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200371my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373my %parameterdescs;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200374my %parameterdesc_start_lines;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375my @parameterlist;
376my %sections;
377my @sectionlist;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200378my %section_start_lines;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800379my $sectcheck;
380my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
382my $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200383my $new_start_line = 0;
Jani Nikulaf624ade2016-05-29 11:35:28 +0300384
385# the canonical section names. see also $doc_sect above.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386my $section_default = "Description"; # default section
387my $section_intro = "Introduction";
388my $section = $section_default;
389my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100390my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392my $undescribed = "-- undescribed --";
393
394reset_state();
395
Mauro Carvalho Chehabb031ac42017-12-18 10:30:10 -0200396while ($ARGV[0] =~ m/^--?(.*)/) {
397 my $cmd = $1;
398 shift @ARGV;
399 if ($cmd eq "man") {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300401 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 $blankline = $blankline_man;
Mauro Carvalho Chehabb031ac42017-12-18 10:30:10 -0200403 } elsif ($cmd eq "rst") {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300404 $output_mode = "rst";
405 @highlights = @highlights_rst;
406 $blankline = $blankline_rst;
Mauro Carvalho Chehabb031ac42017-12-18 10:30:10 -0200407 } elsif ($cmd eq "none") {
Matthew Wilcox3a025e12017-11-20 10:40:40 -0800408 $output_mode = "none";
Mauro Carvalho Chehabb031ac42017-12-18 10:30:10 -0200409 } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 $modulename = shift @ARGV;
Mauro Carvalho Chehabb031ac42017-12-18 10:30:10 -0200411 } elsif ($cmd eq "function") { # to only output specific functions
Jani Nikulab6c3f452016-05-29 22:19:35 +0300412 $output_selection = OUTPUT_INCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 $function = shift @ARGV;
414 $function_table{$function} = 1;
Mauro Carvalho Chehabb031ac42017-12-18 10:30:10 -0200415 } elsif ($cmd eq "nofunction") { # output all except specific functions
Jani Nikulab6c3f452016-05-29 22:19:35 +0300416 $output_selection = OUTPUT_EXCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 $function = shift @ARGV;
418 $function_table{$function} = 1;
Mauro Carvalho Chehabb031ac42017-12-18 10:30:10 -0200419 } elsif ($cmd eq "export") { # only exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300420 $output_selection = OUTPUT_EXPORTED;
Jani Nikulada9726e2016-06-07 10:29:59 +0300421 %function_table = ();
Mauro Carvalho Chehabb031ac42017-12-18 10:30:10 -0200422 } elsif ($cmd eq "internal") { # only non-exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300423 $output_selection = OUTPUT_INTERNAL;
Jani Nikulada9726e2016-06-07 10:29:59 +0300424 %function_table = ();
Mauro Carvalho Chehabb031ac42017-12-18 10:30:10 -0200425 } elsif ($cmd eq "export-file") {
Jani Nikula88c2b572016-06-07 11:00:52 +0300426 my $file = shift @ARGV;
427 push(@export_file_list, $file);
Mauro Carvalho Chehabb031ac42017-12-18 10:30:10 -0200428 } elsif ($cmd eq "v") {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 $verbose = 1;
Mauro Carvalho Chehabb031ac42017-12-18 10:30:10 -0200430 } elsif (($cmd eq "h") || ($cmd eq "help")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 usage();
Mauro Carvalho Chehabb031ac42017-12-18 10:30:10 -0200432 } elsif ($cmd eq 'no-doc-sections') {
Johannes Berg4b445952007-10-24 15:08:48 -0700433 $no_doc_sections = 1;
Mauro Carvalho Chehabb031ac42017-12-18 10:30:10 -0200434 } elsif ($cmd eq 'enable-lineno') {
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200435 $enable_lineno = 1;
Mauro Carvalho Chehabb031ac42017-12-18 10:30:10 -0200436 } elsif ($cmd eq 'show-not-found') {
Johannes Berge946c43a2013-11-12 15:11:12 -0800437 $show_not_found = 1;
Mauro Carvalho Chehabb031ac42017-12-18 10:30:10 -0200438 } else {
439 # Unknown argument
440 usage();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 }
442}
443
Randy Dunlap8484baa2011-01-05 16:28:43 -0800444# continue execution near EOF;
445
Borislav Petkov53f049f2007-05-08 00:30:54 -0700446# get kernel version from env
447sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700448 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700449
450 if (defined($ENV{'KERNELVERSION'})) {
451 $version = $ENV{'KERNELVERSION'};
452 }
453 return $version;
454}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200456#
457sub print_lineno {
458 my $lineno = shift;
459 if ($enable_lineno && defined($lineno)) {
460 print "#define LINENO " . $lineno . "\n";
461 }
462}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463##
464# dumps section contents to arrays/hashes intended for that purpose.
465#
466sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700467 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 my $name = shift;
469 my $contents = join "\n", @_;
470
Jani Nikula13901ef2016-05-26 08:57:29 +0300471 if ($name =~ m/$type_param/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 $name = $1;
473 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800474 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200475 $parameterdesc_start_lines{$name} = $new_start_line;
476 $new_start_line = 0;
Randy Dunlapced69092008-12-01 13:14:03 -0800477 } elsif ($name eq "@\.\.\.") {
Randy Dunlapced69092008-12-01 13:14:03 -0800478 $name = "...";
479 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800480 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200481 $parameterdesc_start_lines{$name} = $new_start_line;
482 $new_start_line = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 } else {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700484 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Jani Nikula95b6be92016-06-10 11:14:05 +0300485 # Only warn on user specified duplicate section names.
486 if ($name ne $section_default) {
487 print STDERR "${file}:$.: warning: duplicate section name '$name'\n";
488 ++$warnings;
489 }
Jani Nikula32217762016-05-29 09:40:44 +0300490 $sections{$name} .= $contents;
491 } else {
492 $sections{$name} = $contents;
493 push @sectionlist, $name;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200494 $section_start_lines{$name} = $new_start_line;
495 $new_start_line = 0;
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 }
498}
499
500##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700501# dump DOC: section after checking that it should go out
502#
503sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700504 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700505 my $name = shift;
506 my $contents = join "\n", @_;
507
Johannes Berg4b445952007-10-24 15:08:48 -0700508 if ($no_doc_sections) {
509 return;
510 }
511
Jani Nikulab6c3f452016-05-29 22:19:35 +0300512 if (($output_selection == OUTPUT_ALL) ||
513 ($output_selection == OUTPUT_INCLUDE &&
514 defined($function_table{$name})) ||
515 ($output_selection == OUTPUT_EXCLUDE &&
516 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700517 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700518 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700519 output_blockhead({'sectionlist' => \@sectionlist,
520 'sections' => \%sections,
521 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300522 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700523 }
524}
525
526##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527# output function
528#
529# parameterdescs, a hash.
530# function => "function name"
531# parameterlist => @list of parameters
532# parameterdescs => %parameter descriptions
533# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800534# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800535#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
537sub output_highlight {
538 my $contents = join "\n",@_;
539 my $line;
540
541# DEBUG
542# if (!defined $contents) {
543# use Carp;
544# confess "output_highlight got called with no args?\n";
545# }
546
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700547# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 eval $dohighlight;
549 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700550# print STDERR "contents af:$contents\n";
551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700553 if (! $output_preformatted) {
554 $line =~ s/^\s*//;
555 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700556 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700557 if (! $output_preformatted) {
Jonathan Corbet0bba9242018-02-05 12:40:15 -0700558 print $lineprefix, $blankline;
Daniel Santose314ba32012-10-04 17:15:08 -0700559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 } else {
Randy Dunlapcdccb312007-07-19 01:48:25 -0700561 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
562 print "\\&$line";
563 } else {
564 print $lineprefix, $line;
565 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 }
567 print "\n";
568 }
569}
570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571##
572# output function in man
573sub output_function_man(%) {
574 my %args = %{$_[0]};
575 my ($parameter, $section);
576 my $count;
577
578 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
579
580 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -0700581 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
583 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -0800584 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700585 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -0800586 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700587 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -0800588 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 $count = 0;
590 my $parenth = "(";
591 my $post = ",";
592 foreach my $parameter (@{$args{'parameterlist'}}) {
593 if ($count == $#{$args{'parameterlist'}}) {
594 $post = ");";
595 }
596 $type = $args{'parametertypes'}{$parameter};
597 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
598 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -0700599 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 } else {
601 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700602 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 }
604 $count++;
605 $parenth = "";
606 }
607
608 print ".SH ARGUMENTS\n";
609 foreach $parameter (@{$args{'parameterlist'}}) {
610 my $parameter_name = $parameter;
611 $parameter_name =~ s/\[.*//;
612
Randy Dunlapb9d973282009-06-09 08:50:38 -0700613 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 output_highlight($args{'parameterdescs'}{$parameter_name});
615 }
616 foreach $section (@{$args{'sectionlist'}}) {
617 print ".SH \"", uc $section, "\"\n";
618 output_highlight($args{'sections'}{$section});
619 }
620}
621
622##
623# output enum in man
624sub output_enum_man(%) {
625 my %args = %{$_[0]};
626 my ($parameter, $section);
627 my $count;
628
629 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
630
631 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -0700632 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -0700635 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 $count = 0;
637 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -0700638 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 if ($count == $#{$args{'parameterlist'}}) {
640 print "\n};\n";
641 last;
642 }
643 else {
644 print ", \n.br\n";
645 }
646 $count++;
647 }
648
649 print ".SH Constants\n";
650 foreach $parameter (@{$args{'parameterlist'}}) {
651 my $parameter_name = $parameter;
652 $parameter_name =~ s/\[.*//;
653
Randy Dunlapb9d973282009-06-09 08:50:38 -0700654 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655 output_highlight($args{'parameterdescs'}{$parameter_name});
656 }
657 foreach $section (@{$args{'sectionlist'}}) {
658 print ".SH \"$section\"\n";
659 output_highlight($args{'sections'}{$section});
660 }
661}
662
663##
664# output struct in man
665sub output_struct_man(%) {
666 my %args = %{$_[0]};
667 my ($parameter, $section);
668
Randy Dunlapb9d973282009-06-09 08:50:38 -0700669 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
671 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -0700672 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Mauro Carvalho Chehab8ad72162017-12-18 10:30:13 -0200674 my $declaration = $args{'definition'};
675 $declaration =~ s/\t/ /g;
676 $declaration =~ s/\n/"\n.br\n.BI \"/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -0700678 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Mauro Carvalho Chehab8ad72162017-12-18 10:30:13 -0200679 print ".BI \"$declaration\n};\n.br\n\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
Randy Dunlapc51d3dac2006-06-25 05:49:14 -0700681 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 foreach $parameter (@{$args{'parameterlist'}}) {
683 ($parameter =~ /^#/) && next;
684
685 my $parameter_name = $parameter;
686 $parameter_name =~ s/\[.*//;
687
Randy Dunlap3c308792007-05-08 00:24:39 -0700688 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700689 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 output_highlight($args{'parameterdescs'}{$parameter_name});
691 }
692 foreach $section (@{$args{'sectionlist'}}) {
693 print ".SH \"$section\"\n";
694 output_highlight($args{'sections'}{$section});
695 }
696}
697
698##
699# output typedef in man
700sub output_typedef_man(%) {
701 my %args = %{$_[0]};
702 my ($parameter, $section);
703
704 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
705
706 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -0700707 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708
709 foreach $section (@{$args{'sectionlist'}}) {
710 print ".SH \"$section\"\n";
711 output_highlight($args{'sections'}{$section});
712 }
713}
714
Johannes Bergb112e0f2007-10-24 15:08:48 -0700715sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 my %args = %{$_[0]};
717 my ($parameter, $section);
718 my $count;
719
720 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
721
722 foreach $section (@{$args{'sectionlist'}}) {
723 print ".SH \"$section\"\n";
724 output_highlight($args{'sections'}{$section});
725 }
726}
727
728##
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300729# output in restructured text
730#
731
732#
733# This could use some work; it's used to output the DOC: sections, and
734# starts by putting out the name of the doc section itself, but that tends
735# to duplicate a header already in the template file.
736#
737sub output_blockhead_rst(%) {
738 my %args = %{$_[0]};
739 my ($parameter, $section);
740
741 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +0300742 if ($output_selection != OUTPUT_INCLUDE) {
743 print "**$section**\n\n";
744 }
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200745 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300746 output_highlight_rst($args{'sections'}{$section});
747 print "\n";
748 }
749}
750
751sub output_highlight_rst {
752 my $contents = join "\n",@_;
753 my $line;
754
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300755 eval $dohighlight;
756 die $@ if $@;
757
758 foreach $line (split "\n", $contents) {
Jani Nikula830066a2016-05-26 22:04:33 +0300759 print $lineprefix . $line . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300760 }
761}
762
763sub output_function_rst(%) {
764 my %args = %{$_[0]};
765 my ($parameter, $section);
Jani Nikulac099ff62016-05-26 17:18:17 +0300766 my $oldprefix = $lineprefix;
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -0300767 my $start = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300768
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -0300769 if ($args{'typedef'}) {
770 print ".. c:type:: ". $args{'function'} . "\n\n";
771 print_lineno($declaration_start_line);
772 print " **Typedef**: ";
773 $lineprefix = "";
774 output_highlight_rst($args{'purpose'});
775 $start = "\n\n**Syntax**\n\n ``";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300776 } else {
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -0300777 print ".. c:function:: ";
778 }
779 if ($args{'functiontype'} ne "") {
780 $start .= $args{'functiontype'} . " " . $args{'function'} . " (";
781 } else {
782 $start .= $args{'function'} . " (";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300783 }
784 print $start;
785
786 my $count = 0;
787 foreach my $parameter (@{$args{'parameterlist'}}) {
788 if ($count ne 0) {
789 print ", ";
790 }
791 $count++;
792 $type = $args{'parametertypes'}{$parameter};
Mauro Carvalho Chehaba88b1672016-07-22 11:46:36 -0300793
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300794 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
795 # pointer-to-function
796 print $1 . $parameter . ") (" . $2;
797 } else {
798 print $type . " " . $parameter;
799 }
800 }
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -0300801 if ($args{'typedef'}) {
802 print ");``\n\n";
803 } else {
804 print ")\n\n";
805 print_lineno($declaration_start_line);
806 $lineprefix = " ";
807 output_highlight_rst($args{'purpose'});
808 print "\n";
809 }
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300810
Jani Nikulaecbcfba2016-05-26 18:30:27 +0300811 print "**Parameters**\n\n";
812 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300813 foreach $parameter (@{$args{'parameterlist'}}) {
814 my $parameter_name = $parameter;
Gabriel Krisman Bertaziada5f442017-01-09 18:11:57 -0200815 $parameter_name =~ s/\[.*//;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300816 $type = $args{'parametertypes'}{$parameter};
817
818 if ($type ne "") {
Jani Nikulaecbcfba2016-05-26 18:30:27 +0300819 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300820 } else {
Jani Nikulaecbcfba2016-05-26 18:30:27 +0300821 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300822 }
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200823
824 print_lineno($parameterdesc_start_lines{$parameter_name});
825
Jani Nikula5e64fa92016-05-19 20:32:48 +0300826 if (defined($args{'parameterdescs'}{$parameter_name}) &&
827 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300828 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300829 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +0300830 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300831 }
832 print "\n";
833 }
Jani Nikulac099ff62016-05-26 17:18:17 +0300834
835 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300836 output_section_rst(@_);
837}
838
839sub output_section_rst(%) {
840 my %args = %{$_[0]};
841 my $section;
842 my $oldprefix = $lineprefix;
Jani Nikulaecbcfba2016-05-26 18:30:27 +0300843 $lineprefix = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300844
845 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +0300846 print "**$section**\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200847 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300848 output_highlight_rst($args{'sections'}{$section});
849 print "\n";
850 }
851 print "\n";
852 $lineprefix = $oldprefix;
853}
854
855sub output_enum_rst(%) {
856 my %args = %{$_[0]};
857 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +0300858 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300859 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300860 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +0300861
862 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200863 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +0300864 $lineprefix = " ";
865 output_highlight_rst($args{'purpose'});
866 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300867
Jani Nikulaecbcfba2016-05-26 18:30:27 +0300868 print "**Constants**\n\n";
869 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300870 foreach $parameter (@{$args{'parameterlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +0300871 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300872 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
873 output_highlight_rst($args{'parameterdescs'}{$parameter});
874 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +0300875 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300876 }
877 print "\n";
878 }
Jani Nikulac099ff62016-05-26 17:18:17 +0300879
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300880 $lineprefix = $oldprefix;
881 output_section_rst(@_);
882}
883
884sub output_typedef_rst(%) {
885 my %args = %{$_[0]};
886 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +0300887 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300888 my $name = "typedef " . $args{'typedef'};
889
Jani Nikula62850972016-05-12 16:15:38 +0300890 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200891 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +0300892 $lineprefix = " ";
893 output_highlight_rst($args{'purpose'});
894 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300895
Jani Nikulac099ff62016-05-26 17:18:17 +0300896 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300897 output_section_rst(@_);
898}
899
900sub output_struct_rst(%) {
901 my %args = %{$_[0]};
902 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +0300903 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300904 my $name = $args{'type'} . " " . $args{'struct'};
905
Jani Nikula62850972016-05-12 16:15:38 +0300906 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200907 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +0300908 $lineprefix = " ";
909 output_highlight_rst($args{'purpose'});
910 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300911
Jani Nikulaecbcfba2016-05-26 18:30:27 +0300912 print "**Definition**\n\n";
913 print "::\n\n";
Mauro Carvalho Chehab8ad72162017-12-18 10:30:13 -0200914 my $declaration = $args{'definition'};
915 $declaration =~ s/\t/ /g;
916 print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300917
Jani Nikulaecbcfba2016-05-26 18:30:27 +0300918 print "**Members**\n\n";
919 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300920 foreach $parameter (@{$args{'parameterlist'}}) {
921 ($parameter =~ /^#/) && next;
922
923 my $parameter_name = $parameter;
924 $parameter_name =~ s/\[.*//;
925
926 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
927 $type = $args{'parametertypes'}{$parameter};
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200928 print_lineno($parameterdesc_start_lines{$parameter_name});
Mauro Carvalho Chehab6d232c82016-08-22 22:02:57 -0300929 print "``" . $parameter . "``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300930 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300931 print "\n";
932 }
933 print "\n";
Jani Nikulac099ff62016-05-26 17:18:17 +0300934
935 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300936 output_section_rst(@_);
937}
938
Matthew Wilcox3a025e12017-11-20 10:40:40 -0800939## none mode output functions
940
941sub output_function_none(%) {
942}
943
944sub output_enum_none(%) {
945}
946
947sub output_typedef_none(%) {
948}
949
950sub output_struct_none(%) {
951}
952
953sub output_blockhead_none(%) {
954}
955
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956##
Randy Dunlap27205742006-10-11 01:22:12 -0700957# generic output function for all types (function, struct/union, typedef, enum);
958# calls the generated, variable output_ function name based on
959# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960sub output_declaration {
961 no strict 'refs';
962 my $name = shift;
963 my $functype = shift;
964 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +0300965 if (($output_selection == OUTPUT_ALL) ||
966 (($output_selection == OUTPUT_INCLUDE ||
967 $output_selection == OUTPUT_EXPORTED) &&
968 defined($function_table{$name})) ||
969 (($output_selection == OUTPUT_EXCLUDE ||
970 $output_selection == OUTPUT_INTERNAL) &&
971 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 {
Randy Dunlap3c308792007-05-08 00:24:39 -0700973 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 $section_counter++;
975 }
976}
977
978##
Randy Dunlap27205742006-10-11 01:22:12 -0700979# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -0700980sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700982 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 &$func(@_);
984 $section_counter++;
985}
986
987##
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800988# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989# invokes the right handler. NOT called for functions.
990sub dump_declaration($$) {
991 no strict 'refs';
992 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700993 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 &$func(@_);
995}
996
997sub dump_union($$) {
998 dump_struct(@_);
999}
1000
1001sub dump_struct($$) {
1002 my $x = shift;
1003 my $file = shift;
1004
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07001005 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
Johannes Berg5cb5c312017-09-19 13:08:13 +02001006 my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07001007 $declaration_name = $2;
1008 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
Martin Waitzaeec46b2005-11-13 16:08:13 -08001010 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03001011 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
1012 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08001013 # strip comments:
1014 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07001015 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06001016 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08001017 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06001018 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01001019 # replace DECLARE_BITMAP
Mauro Carvalho Chehab45005b22017-12-08 09:05:12 -05001020 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Jakub Kicinski1cb566b2017-06-30 19:09:59 -07001021 # replace DECLARE_HASHTABLE
Mauro Carvalho Chehab45005b22017-12-08 09:05:12 -05001022 $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos;
1023 # replace DECLARE_KFIFO
1024 $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos;
1025 # replace DECLARE_KFIFO_PTR
1026 $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08001027
Mauro Carvalho Chehab8ad72162017-12-18 10:30:13 -02001028 my $declaration = $members;
1029
1030 # Split nested struct/union elements as newer ones
Mauro Carvalho Chehab84ce5b92017-12-18 10:30:17 -02001031 while ($members =~ m/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/) {
1032 my $newmember;
1033 my $maintype = $1;
1034 my $ids = $4;
1035 my $content = $3;
1036 foreach my $id(split /,/, $ids) {
1037 $newmember .= "$maintype $id; ";
1038
Mauro Carvalho Chehab8ad72162017-12-18 10:30:13 -02001039 $id =~ s/[:\[].*//;
Mauro Carvalho Chehab84ce5b92017-12-18 10:30:17 -02001040 $id =~ s/^\s*\**(\S+)\s*/$1/;
Mauro Carvalho Chehab8ad72162017-12-18 10:30:13 -02001041 foreach my $arg (split /;/, $content) {
1042 next if ($arg =~ m/^\s*$/);
Mauro Carvalho Chehab7c0d7e82017-12-18 10:30:16 -02001043 if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) {
1044 # pointer-to-function
1045 my $type = $1;
1046 my $name = $2;
1047 my $extra = $3;
1048 next if (!$name);
1049 if ($id =~ m/^\s*$/) {
1050 # anonymous struct/union
Mauro Carvalho Chehab84ce5b92017-12-18 10:30:17 -02001051 $newmember .= "$type$name$extra; ";
Mauro Carvalho Chehab7c0d7e82017-12-18 10:30:16 -02001052 } else {
Mauro Carvalho Chehab84ce5b92017-12-18 10:30:17 -02001053 $newmember .= "$type$id.$name$extra; ";
Mauro Carvalho Chehab7c0d7e82017-12-18 10:30:16 -02001054 }
Mauro Carvalho Chehab8ad72162017-12-18 10:30:13 -02001055 } else {
Mauro Carvalho Chehab84ce5b92017-12-18 10:30:17 -02001056 my $type;
1057 my $names;
1058 $arg =~ s/^\s+//;
1059 $arg =~ s/\s+$//;
1060 # Handle bitmaps
1061 $arg =~ s/:\s*\d+\s*//g;
1062 # Handle arrays
1063 $arg =~ s/\[\S+\]//g;
1064 # The type may have multiple words,
1065 # and multiple IDs can be defined, like:
1066 # const struct foo, *bar, foobar
1067 # So, we remove spaces when parsing the
1068 # names, in order to match just names
1069 # and commas for the names
1070 $arg =~ s/\s*,\s*/,/g;
1071 if ($arg =~ m/(.*)\s+([\S+,]+)/) {
1072 $type = $1;
1073 $names = $2;
Mauro Carvalho Chehab7c0d7e82017-12-18 10:30:16 -02001074 } else {
Mauro Carvalho Chehab84ce5b92017-12-18 10:30:17 -02001075 $newmember .= "$arg; ";
1076 next;
1077 }
1078 foreach my $name (split /,/, $names) {
1079 $name =~ s/^\s*\**(\S+)\s*/$1/;
1080 next if (($name =~ m/^\s*$/));
1081 if ($id =~ m/^\s*$/) {
1082 # anonymous struct/union
1083 $newmember .= "$type $name; ";
1084 } else {
1085 $newmember .= "$type $id.$name; ";
1086 }
Mauro Carvalho Chehab7c0d7e82017-12-18 10:30:16 -02001087 }
Mauro Carvalho Chehab8ad72162017-12-18 10:30:13 -02001088 }
1089 }
Mauro Carvalho Chehab84ce5b92017-12-18 10:30:17 -02001090 }
1091 $members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)}([^\{\}\;]*)\;/$newmember/;
1092 }
Mauro Carvalho Chehab8ad72162017-12-18 10:30:13 -02001093
1094 # Ignore other nested elements, like enums
1095 $members =~ s/({[^\{\}]*})//g;
Mauro Carvalho Chehab8ad72162017-12-18 10:30:13 -02001096
Mauro Carvalho Chehab151c4682017-12-18 10:30:15 -02001097 create_parameterlist($members, ';', $file, $declaration_name);
Mauro Carvalho Chehab1081de22017-12-18 10:30:14 -02001098 check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
Mauro Carvalho Chehab8ad72162017-12-18 10:30:13 -02001100 # Adjust declaration for better display
1101 $declaration =~ s/([{;])/$1\n/g;
1102 $declaration =~ s/}\s+;/};/g;
1103 # Better handle inlined enums
1104 do {} while ($declaration =~ s/(enum\s+{[^}]+),([^\n])/$1,\n$2/);
1105
1106 my @def_args = split /\n/, $declaration;
1107 my $level = 1;
1108 $declaration = "";
1109 foreach my $clause (@def_args) {
1110 $clause =~ s/^\s+//;
1111 $clause =~ s/\s+$//;
1112 $clause =~ s/\s+/ /;
1113 next if (!$clause);
1114 $level-- if ($clause =~ m/(})/ && $level > 1);
1115 if (!($clause =~ m/^\s*#/)) {
1116 $declaration .= "\t" x $level;
1117 }
1118 $declaration .= "\t" . $clause . "\n";
1119 $level++ if ($clause =~ m/({)/ && !($clause =~m/}/));
1120 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 output_declaration($declaration_name,
1122 'struct',
1123 {'struct' => $declaration_name,
1124 'module' => $modulename,
Mauro Carvalho Chehab8ad72162017-12-18 10:30:13 -02001125 'definition' => $declaration,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 'parameterlist' => \@parameterlist,
1127 'parameterdescs' => \%parameterdescs,
1128 'parametertypes' => \%parametertypes,
1129 'sectionlist' => \@sectionlist,
1130 'sections' => \%sections,
1131 'purpose' => $declaration_purpose,
1132 'type' => $decl_type
1133 });
1134 }
1135 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07001136 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 ++$errors;
1138 }
1139}
1140
Mauro Carvalho Chehab85afe602017-12-30 22:32:55 -02001141
1142sub show_warnings($$) {
1143 my $functype = shift;
1144 my $name = shift;
1145
1146 return 1 if ($output_selection == OUTPUT_ALL);
1147
1148 if ($output_selection == OUTPUT_EXPORTED) {
1149 if (defined($function_table{$name})) {
1150 return 1;
1151 } else {
1152 return 0;
1153 }
1154 }
1155 if ($output_selection == OUTPUT_INTERNAL) {
1156 if (!($functype eq "function" && defined($function_table{$name}))) {
1157 return 1;
1158 } else {
1159 return 0;
1160 }
1161 }
1162 if ($output_selection == OUTPUT_INCLUDE) {
1163 if (defined($function_table{$name})) {
1164 return 1;
1165 } else {
1166 return 0;
1167 }
1168 }
1169 if ($output_selection == OUTPUT_EXCLUDE) {
1170 if (!defined($function_table{$name})) {
1171 return 1;
1172 } else {
1173 return 0;
1174 }
1175 }
1176 die("Please add the new output type at show_warnings()");
1177}
1178
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179sub dump_enum($$) {
1180 my $x = shift;
1181 my $file = shift;
1182
Martin Waitzaeec46b2005-11-13 16:08:13 -08001183 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01001184 # strip #define macros inside enums
1185 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07001186
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001188 $declaration_name = $1;
1189 my $members = $2;
Johannes Berg5cb5c312017-09-19 13:08:13 +02001190 my %_members;
1191
Markus Heiser463a0fd2017-06-16 21:27:48 +02001192 $members =~ s/\s+$//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
1194 foreach my $arg (split ',', $members) {
1195 $arg =~ s/^\s*(\w+).*/$1/;
1196 push @parameterlist, $arg;
1197 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001198 $parameterdescs{$arg} = $undescribed;
Mauro Carvalho Chehab85afe602017-12-30 22:32:55 -02001199 if (show_warnings("enum", $declaration_name)) {
Mauro Carvalho Chehab2defb272017-12-18 10:30:18 -02001200 print STDERR "${file}:$.: warning: Enum value '$arg' not described in enum '$declaration_name'\n";
1201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 }
Johannes Berg5cb5c312017-09-19 13:08:13 +02001203 $_members{$arg} = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001205
Johannes Berg5cb5c312017-09-19 13:08:13 +02001206 while (my ($k, $v) = each %parameterdescs) {
1207 if (!exists($_members{$k})) {
Mauro Carvalho Chehab85afe602017-12-30 22:32:55 -02001208 if (show_warnings("enum", $declaration_name)) {
Mauro Carvalho Chehab2defb272017-12-18 10:30:18 -02001209 print STDERR "${file}:$.: warning: Excess enum value '$k' description in '$declaration_name'\n";
1210 }
Johannes Berg5cb5c312017-09-19 13:08:13 +02001211 }
1212 }
1213
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 output_declaration($declaration_name,
1215 'enum',
1216 {'enum' => $declaration_name,
1217 'module' => $modulename,
1218 'parameterlist' => \@parameterlist,
1219 'parameterdescs' => \%parameterdescs,
1220 'sectionlist' => \@sectionlist,
1221 'sections' => \%sections,
1222 'purpose' => $declaration_purpose
1223 });
1224 }
1225 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07001226 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 ++$errors;
1228 }
1229}
1230
1231sub dump_typedef($$) {
1232 my $x = shift;
1233 my $file = shift;
1234
Martin Waitzaeec46b2005-11-13 16:08:13 -08001235 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03001236
1237 # Parse function prototypes
Mauro Carvalho Chehabd37c43c2016-08-30 20:20:57 -03001238 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ ||
1239 $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) {
1240
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03001241 # Function typedefs
1242 $return_type = $1;
1243 $declaration_name = $2;
1244 my $args = $3;
1245
Mauro Carvalho Chehab151c4682017-12-18 10:30:15 -02001246 create_parameterlist($args, ',', $file, $declaration_name);
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03001247
1248 output_declaration($declaration_name,
1249 'function',
1250 {'function' => $declaration_name,
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001251 'typedef' => 1,
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03001252 'module' => $modulename,
1253 'functiontype' => $return_type,
1254 'parameterlist' => \@parameterlist,
1255 'parameterdescs' => \%parameterdescs,
1256 'parametertypes' => \%parametertypes,
1257 'sectionlist' => \@sectionlist,
1258 'sections' => \%sections,
1259 'purpose' => $declaration_purpose
1260 });
1261 return;
1262 }
1263
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001265 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 $x =~ s/\[*.\]\s*;$/;/;
1267 }
1268
1269 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001270 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
1272 output_declaration($declaration_name,
1273 'typedef',
1274 {'typedef' => $declaration_name,
1275 'module' => $modulename,
1276 'sectionlist' => \@sectionlist,
1277 'sections' => \%sections,
1278 'purpose' => $declaration_purpose
1279 });
1280 }
1281 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07001282 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 ++$errors;
1284 }
1285}
1286
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001287sub save_struct_actual($) {
1288 my $actual = shift;
1289
1290 # strip all spaces from the actual param so that it looks like one string item
1291 $actual =~ s/\s*//g;
1292 $struct_actual = $struct_actual . $actual . " ";
1293}
1294
Mauro Carvalho Chehab151c4682017-12-18 10:30:15 -02001295sub create_parameterlist($$$$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 my $args = shift;
1297 my $splitter = shift;
1298 my $file = shift;
Mauro Carvalho Chehab151c4682017-12-18 10:30:15 -02001299 my $declaration_name = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 my $type;
1301 my $param;
1302
Martin Waitza6d3fe72006-01-09 20:53:55 -08001303 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001305 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001307
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 foreach my $arg (split($splitter, $args)) {
1309 # strip comments
1310 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07001311 # strip leading/trailing spaces
1312 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 $arg =~ s/\s*$//;
1314 $arg =~ s/\s+/ /;
1315
1316 if ($arg =~ /^#/) {
1317 # Treat preprocessor directive as a typeless variable just to fill
1318 # corresponding data structures "correctly". Catch it later in
1319 # output_* subs.
1320 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08001321 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 # pointer-to-function
1323 $arg =~ tr/#/,/;
Mauro Carvalho Chehab7c0d7e82017-12-18 10:30:16 -02001324 $arg =~ m/[^\(]+\(\*?\s*([\w\.]*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 $param = $1;
1326 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08001327 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001328 save_struct_actual($param);
Mauro Carvalho Chehab151c4682017-12-18 10:30:15 -02001329 push_parameter($param, $type, $file, $declaration_name);
Martin Waitzaeec46b2005-11-13 16:08:13 -08001330 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 $arg =~ s/\s*:\s*/:/g;
1332 $arg =~ s/\s*\[/\[/g;
1333
1334 my @args = split('\s*,\s*', $arg);
1335 if ($args[0] =~ m/\*/) {
1336 $args[0] =~ s/(\*+)\s*/ $1/;
1337 }
Borislav Petkov884f2812007-05-08 00:29:05 -07001338
1339 my @first_arg;
1340 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1341 shift @args;
1342 push(@first_arg, split('\s+', $1));
1343 push(@first_arg, $2);
1344 } else {
1345 @first_arg = split('\s+', shift @args);
1346 }
1347
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 unshift(@args, pop @first_arg);
1349 $type = join " ", @first_arg;
1350
1351 foreach $param (@args) {
1352 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001353 save_struct_actual($2);
Mauro Carvalho Chehab151c4682017-12-18 10:30:15 -02001354 push_parameter($2, "$type $1", $file, $declaration_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 }
1356 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07001357 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001358 save_struct_actual($1);
Mauro Carvalho Chehab151c4682017-12-18 10:30:15 -02001359 push_parameter($1, "$type:$2", $file, $declaration_name)
Randy Dunlap7b978872008-05-16 15:45:52 -07001360 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 }
1362 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001363 save_struct_actual($param);
Mauro Carvalho Chehab151c4682017-12-18 10:30:15 -02001364 push_parameter($param, $type, $file, $declaration_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 }
1366 }
1367 }
1368 }
1369}
1370
Mauro Carvalho Chehab151c4682017-12-18 10:30:15 -02001371sub push_parameter($$$$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 my $param = shift;
1373 my $type = shift;
1374 my $file = shift;
Mauro Carvalho Chehab151c4682017-12-18 10:30:15 -02001375 my $declaration_name = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07001377 if (($anon_struct_union == 1) && ($type eq "") &&
1378 ($param eq "}")) {
1379 return; # ignore the ending }; from anon. struct/union
1380 }
1381
1382 $anon_struct_union = 0;
Mauro Carvalho Chehabf9b5c532017-03-30 17:11:29 -03001383 $param =~ s/[\[\)].*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
Martin Waitza6d3fe72006-01-09 20:53:55 -08001385 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 {
Silvio Frickec950a172016-10-28 10:14:08 +02001387 if (!$param =~ /\w\.\.\.$/) {
1388 # handles unnamed variable parameters
1389 $param = "...";
1390 }
Randy Dunlapced69092008-12-01 13:14:03 -08001391 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
1392 $parameterdescs{$param} = "variable arguments";
1393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 }
1395 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1396 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 $param="void";
1398 $parameterdescs{void} = "no arguments";
1399 }
Randy Dunlap134fe012006-12-22 01:10:50 -08001400 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1401 # handle unnamed (anonymous) union or struct:
1402 {
1403 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07001404 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08001405 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07001406 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08001407 }
1408
Martin Waitza6d3fe72006-01-09 20:53:55 -08001409 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08001410 # (but ignore ones starting with # as these are not parameters
1411 # but inline preprocessor statements);
Mauro Carvalho Chehab151c4682017-12-18 10:30:15 -02001412 # Note: It will also ignore void params and unnamed structs/unions
Mauro Carvalho Chehabf9b5c532017-03-30 17:11:29 -03001413 if (!defined $parameterdescs{$param} && $param !~ /^#/) {
Mauro Carvalho Chehab151c4682017-12-18 10:30:15 -02001414 $parameterdescs{$param} = $undescribed;
Martin Waitza6d3fe72006-01-09 20:53:55 -08001415
Mauro Carvalho Chehab85afe602017-12-30 22:32:55 -02001416 if (show_warnings($type, $declaration_name)) {
Mauro Carvalho Chehab2defb272017-12-18 10:30:18 -02001417 print STDERR
1418 "${file}:$.: warning: Function parameter or member '$param' not described in '$declaration_name'\n";
1419 ++$warnings;
1420 }
Randy Dunlap3c308792007-05-08 00:24:39 -07001421 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001423 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07001424 # on @parameterlist;
1425 # this fixes a problem where check_sections() cannot find
1426 # a parameter like "addr[6 + 2]" because it actually appears
1427 # as "addr[6", "+", "2]" on the parameter list;
1428 # but it's better to maintain the param string unchanged for output,
1429 # so just weaken the string compare in check_sections() to ignore
1430 # "[blah" in a parameter string;
1431 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 push @parameterlist, $param;
Paolo Bonzini02a4f4f2017-01-02 16:22:23 +01001433 $type =~ s/\s\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 $parametertypes{$param} = $type;
1435}
1436
Mauro Carvalho Chehab1081de22017-12-18 10:30:14 -02001437sub check_sections($$$$$) {
1438 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001439 my @sects = split ' ', $sectcheck;
1440 my @prms = split ' ', $prmscheck;
1441 my $err;
1442 my ($px, $sx);
1443 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
1444
1445 foreach $sx (0 .. $#sects) {
1446 $err = 1;
1447 foreach $px (0 .. $#prms) {
1448 $prm_clean = $prms[$px];
1449 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07001450 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07001451 # ignore array size in a parameter string;
1452 # however, the original param string may contain
1453 # spaces, e.g.: addr[6 + 2]
1454 # and this appears in @prms as "addr[6" since the
1455 # parameter list is split at spaces;
1456 # hence just ignore "[..." for the sections check;
1457 $prm_clean =~ s/\[.*//;
1458
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001459 ##$prm_clean =~ s/^\**//;
1460 if ($prm_clean eq $sects[$sx]) {
1461 $err = 0;
1462 last;
1463 }
1464 }
1465 if ($err) {
1466 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07001467 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001468 "Excess function parameter " .
1469 "'$sects[$sx]' " .
1470 "description in '$decl_name'\n";
1471 ++$warnings;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001472 }
1473 }
1474 }
1475}
1476
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01001478# Checks the section describing the return value of a function.
1479sub check_return_section {
1480 my $file = shift;
1481 my $declaration_name = shift;
1482 my $return_type = shift;
1483
1484 # Ignore an empty return type (It's a macro)
1485 # Ignore functions with a "void" return type. (But don't ignore "void *")
1486 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
1487 return;
1488 }
1489
1490 if (!defined($sections{$section_return}) ||
1491 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07001492 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01001493 "No description found for return value of " .
1494 "'$declaration_name'\n";
1495 ++$warnings;
1496 }
1497}
1498
1499##
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500# takes a function prototype and the name of the current file being
1501# processed and spits out all the details stored in the global
1502# arrays/hashes.
1503sub dump_function($$) {
1504 my $prototype = shift;
1505 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07001506 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
1508 $prototype =~ s/^static +//;
1509 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07001510 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 $prototype =~ s/^inline +//;
1512 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07001513 $prototype =~ s/^__inline +//;
1514 $prototype =~ s/^__always_inline +//;
1515 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07001516 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07001517 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07001518 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08001519 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07001520 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07001521 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Paolo Bonzinib1aaa542017-01-02 16:22:24 +01001522 $prototype =~ s/__attribute__\s*\(\(
1523 (?:
1524 [\w\s]++ # attribute name
1525 (?:\([^)]*+\))? # attribute arguments
1526 \s*+,? # optional comma at the end
1527 )+
1528 \)\)\s+//x;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
1530 # Yes, this truly is vile. We are looking for:
1531 # 1. Return type (may be nothing if we're looking at a macro)
1532 # 2. Function name
1533 # 3. Function parameters.
1534 #
1535 # All the while we have to watch out for function pointer parameters
1536 # (which IIRC is what the two sections are for), C types (these
1537 # regexps don't even start to express all the possibilities), and
1538 # so on.
1539 #
1540 # If you mess with these regexps, it's a good idea to check that
1541 # the following functions' documentation still comes out right:
1542 # - parport_register_device (function pointer parameters)
1543 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08001544 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545
Horia Geantacbb4d3e2014-07-12 09:55:03 -07001546 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
1547 # This is an object-like macro, it has no return type and no parameter
1548 # list.
1549 # Function-like macros are not allowed to have spaces between
1550 # declaration_name and opening parenthesis (notice the \s+).
1551 $return_type = $1;
1552 $declaration_name = $2;
1553 $noret = 1;
1554 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08001556 $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08001558 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08001560 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1562 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08001563 $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08001565 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08001567 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08001568 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08001569 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1570 $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 $return_type = $1;
1572 $declaration_name = $2;
1573 my $args = $3;
1574
Mauro Carvalho Chehab151c4682017-12-18 10:30:15 -02001575 create_parameterlist($args, ',', $file, $declaration_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07001577 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 return;
1579 }
1580
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001581 my $prms = join " ", @parameterlist;
Mauro Carvalho Chehab1081de22017-12-18 10:30:14 -02001582 check_sections($file, $declaration_name, "function", $sectcheck, $prms);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001583
Yacine Belkadi4092bac2012-11-26 22:22:27 +01001584 # This check emits a lot of warnings at the moment, because many
1585 # functions don't have a 'Return' doc section. So until the number
1586 # of warnings goes sufficiently down, the check is only performed in
1587 # verbose mode.
1588 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07001589 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01001590 check_return_section($file, $declaration_name, $return_type);
1591 }
1592
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001593 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 'function',
1595 {'function' => $declaration_name,
1596 'module' => $modulename,
1597 'functiontype' => $return_type,
1598 'parameterlist' => \@parameterlist,
1599 'parameterdescs' => \%parameterdescs,
1600 'parametertypes' => \%parametertypes,
1601 'sectionlist' => \@sectionlist,
1602 'sections' => \%sections,
1603 'purpose' => $declaration_purpose
1604 });
1605}
1606
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607sub reset_state {
1608 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 %parameterdescs = ();
1610 %parametertypes = ();
1611 @parameterlist = ();
1612 %sections = ();
1613 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001614 $sectcheck = "";
1615 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001617
Jani Nikula48af6062016-05-26 14:56:05 +03001618 $state = STATE_NORMAL;
1619 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620}
1621
Jason Baron56afb0f2009-04-30 13:29:36 -04001622sub tracepoint_munge($) {
1623 my $file = shift;
1624 my $tracepointname = 0;
1625 my $tracepointargs = 0;
1626
Jason Baron3a9089f2009-12-01 12:18:49 -05001627 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04001628 $tracepointname = $1;
1629 }
Jason Baron3a9089f2009-12-01 12:18:49 -05001630 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
1631 $tracepointname = $1;
1632 }
1633 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
1634 $tracepointname = $2;
1635 }
1636 $tracepointname =~ s/^\s+//; #strip leading whitespace
1637 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04001638 $tracepointargs = $1;
1639 }
1640 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07001641 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04001642 "$prototype\n";
1643 } else {
1644 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
1645 }
1646}
1647
Randy Dunlapb4870bc2009-02-11 13:04:33 -08001648sub syscall_munge() {
1649 my $void = 0;
1650
Mauro Carvalho Chehab7c9aa012017-12-18 10:30:12 -02001651 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's
Randy Dunlapb4870bc2009-02-11 13:04:33 -08001652## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
1653 if ($prototype =~ m/SYSCALL_DEFINE0/) {
1654 $void = 1;
1655## $prototype = "long sys_$1(void)";
1656 }
1657
1658 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
1659 if ($prototype =~ m/long (sys_.*?),/) {
1660 $prototype =~ s/,/\(/;
1661 } elsif ($void) {
1662 $prototype =~ s/\)/\(void\)/;
1663 }
1664
1665 # now delete all of the odd-number commas in $prototype
1666 # so that arg types & arg names don't have a comma between them
1667 my $count = 0;
1668 my $len = length($prototype);
1669 if ($void) {
1670 $len = 0; # skip the for-loop
1671 }
1672 for (my $ix = 0; $ix < $len; $ix++) {
1673 if (substr($prototype, $ix, 1) eq ',') {
1674 $count++;
1675 if ($count % 2 == 1) {
1676 substr($prototype, $ix, 1) = ' ';
1677 }
1678 }
1679 }
1680}
1681
Daniel Vetterb7afa922016-06-01 23:46:24 +02001682sub process_proto_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 my $x = shift;
1684 my $file = shift;
1685
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001686 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1687
Randy Dunlap890c78c2008-10-25 17:06:43 -07001688 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 # do nothing
1690 }
1691 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001692 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08001694
Randy Dunlap890c78c2008-10-25 17:06:43 -07001695 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001696 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1698 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08001699 if ($prototype =~ /SYSCALL_DEFINE/) {
1700 syscall_munge();
1701 }
Jason Baron3a9089f2009-12-01 12:18:49 -05001702 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
1703 $prototype =~ /DEFINE_SINGLE_EVENT/)
1704 {
Jason Baron56afb0f2009-04-30 13:29:36 -04001705 tracepoint_munge($file);
1706 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08001707 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 reset_state();
1709 }
1710}
1711
Daniel Vetterb7afa922016-06-01 23:46:24 +02001712sub process_proto_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 my $x = shift;
1714 my $file = shift;
1715
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1717 $x =~ s@^\s+@@gos; # strip leading spaces
1718 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001719 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1720
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 if ($x =~ /^#/) {
1722 # To distinguish preprocessor directive from regular declaration later.
1723 $x .= ";";
1724 }
1725
1726 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001727 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Markus Heiser463a0fd2017-06-16 21:27:48 +02001728 if( length $prototype ) {
1729 $prototype .= " "
1730 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 $prototype .= $1 . $2;
1732 ($2 eq '{') && $brcount++;
1733 ($2 eq '}') && $brcount--;
1734 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001735 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07001737 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 }
1739 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07001740 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 $prototype .= $x;
1742 last;
1743 }
1744 }
1745}
1746
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07001747
Jani Nikula1ad560e2016-06-07 10:53:39 +03001748sub map_filename($) {
1749 my $file;
1750 my ($orig_file) = @_;
1751
1752 if (defined($ENV{'SRCTREE'})) {
1753 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
1754 } else {
1755 $file = $orig_file;
1756 }
1757
1758 if (defined($source_map{$file})) {
1759 $file = $source_map{$file};
1760 }
1761
1762 return $file;
1763}
1764
Jani Nikula88c2b572016-06-07 11:00:52 +03001765sub process_export_file($) {
1766 my ($orig_file) = @_;
1767 my $file = map_filename($orig_file);
1768
1769 if (!open(IN,"<$file")) {
1770 print STDERR "Error: Cannot open file $file\n";
1771 ++$errors;
1772 return;
1773 }
1774
1775 while (<IN>) {
1776 if (/$export_symbol/) {
1777 $function_table{$2} = 1;
1778 }
1779 }
1780
1781 close(IN);
1782}
1783
Jonathan Corbet07048d12018-02-05 14:15:19 -07001784#
1785# Parsers for the various processing states.
1786#
1787# STATE_NORMAL: looking for the /** to begin everything.
1788#
1789sub process_normal() {
1790 if (/$doc_start/o) {
1791 $state = STATE_NAME; # next line is always the function name
1792 $in_doc_sect = 0;
1793 $declaration_start_line = $. + 1;
1794 }
1795}
1796
Jonathan Corbet3cac2bc2018-02-05 14:36:33 -07001797#
1798# STATE_NAME: Looking for the "name - description" line
1799#
1800sub process_name($$) {
1801 my $file = shift;
1802 my $identifier;
1803 my $descr;
Jonathan Corbet07048d12018-02-05 14:15:19 -07001804
Jonathan Corbet3cac2bc2018-02-05 14:36:33 -07001805 if (/$doc_block/o) {
1806 $state = STATE_DOCBLOCK;
1807 $contents = "";
1808 $new_start_line = $. + 1;
1809
1810 if ( $1 eq "" ) {
1811 $section = $section_intro;
1812 } else {
1813 $section = $1;
1814 }
1815 }
1816 elsif (/$doc_decl/o) {
1817 $identifier = $1;
1818 if (/\s*([\w\s]+?)\s*-/) {
1819 $identifier = $1;
1820 }
1821
1822 $state = STATE_BODY;
1823 # if there's no @param blocks need to set up default section
1824 # here
1825 $contents = "";
1826 $section = $section_default;
1827 $new_start_line = $. + 1;
1828 if (/-(.*)/) {
1829 # strip leading/trailing/multiple spaces
1830 $descr= $1;
1831 $descr =~ s/^\s*//;
1832 $descr =~ s/\s*$//;
1833 $descr =~ s/\s+/ /g;
1834 $declaration_purpose = $descr;
1835 $state = STATE_BODY_MAYBE;
1836 } else {
1837 $declaration_purpose = "";
1838 }
1839
1840 if (($declaration_purpose eq "") && $verbose) {
1841 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
1842 print STDERR $_;
1843 ++$warnings;
1844 }
1845
1846 if ($identifier =~ m/^struct/) {
1847 $decl_type = 'struct';
1848 } elsif ($identifier =~ m/^union/) {
1849 $decl_type = 'union';
1850 } elsif ($identifier =~ m/^enum/) {
1851 $decl_type = 'enum';
1852 } elsif ($identifier =~ m/^typedef/) {
1853 $decl_type = 'typedef';
1854 } else {
1855 $decl_type = 'function';
1856 }
1857
1858 if ($verbose) {
1859 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
1860 }
1861 } else {
1862 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
1863 " - I thought it was a doc line\n";
1864 ++$warnings;
1865 $state = STATE_NORMAL;
1866 }
1867}
Jonathan Corbet07048d12018-02-05 14:15:19 -07001868
Jonathan Corbetd742f242018-02-05 15:36:05 -07001869
1870#
1871# STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment.
1872#
1873sub process_body($$) {
1874 my $file = shift;
1875
1876 if (/$doc_sect/i) { # case insensitive for supported section names
1877 $newsection = $1;
1878 $newcontents = $2;
1879
1880 # map the supported section names to the canonical names
1881 if ($newsection =~ m/^description$/i) {
1882 $newsection = $section_default;
1883 } elsif ($newsection =~ m/^context$/i) {
1884 $newsection = $section_context;
1885 } elsif ($newsection =~ m/^returns?$/i) {
1886 $newsection = $section_return;
1887 } elsif ($newsection =~ m/^\@return$/) {
1888 # special: @return is a section, not a param description
1889 $newsection = $section_return;
1890 }
1891
1892 if (($contents ne "") && ($contents ne "\n")) {
1893 if (!$in_doc_sect && $verbose) {
1894 print STDERR "${file}:$.: warning: contents before sections\n";
1895 ++$warnings;
1896 }
1897 dump_section($file, $section, $contents);
1898 $section = $section_default;
1899 }
1900
1901 $in_doc_sect = 1;
1902 $state = STATE_BODY;
1903 $contents = $newcontents;
1904 $new_start_line = $.;
1905 while (substr($contents, 0, 1) eq " ") {
1906 $contents = substr($contents, 1);
1907 }
1908 if ($contents ne "") {
1909 $contents .= "\n";
1910 }
1911 $section = $newsection;
1912 $leading_space = undef;
1913 } elsif (/$doc_end/) {
1914 if (($contents ne "") && ($contents ne "\n")) {
1915 dump_section($file, $section, $contents);
1916 $section = $section_default;
1917 $contents = "";
1918 }
1919 # look for doc_com + <text> + doc_end:
1920 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
1921 print STDERR "${file}:$.: warning: suspicious ending line: $_";
1922 ++$warnings;
1923 }
1924
1925 $prototype = "";
1926 $state = STATE_PROTO;
1927 $brcount = 0;
1928 } elsif (/$doc_content/) {
1929 # miguel-style comment kludge, look for blank lines after
1930 # @parameter line to signify start of description
1931 if ($1 eq "") {
1932 if ($section =~ m/^@/ || $section eq $section_context) {
1933 dump_section($file, $section, $contents);
1934 $section = $section_default;
1935 $contents = "";
1936 $new_start_line = $.;
1937 } else {
1938 $contents .= "\n";
1939 }
1940 $state = STATE_BODY;
1941 } elsif ($state == STATE_BODY_MAYBE) {
1942 # Continued declaration purpose
1943 chomp($declaration_purpose);
1944 $declaration_purpose .= " " . $1;
1945 $declaration_purpose =~ s/\s+/ /g;
1946 } else {
1947 my $cont = $1;
1948 if ($section =~ m/^@/ || $section eq $section_context) {
1949 if (!defined $leading_space) {
1950 if ($cont =~ m/^(\s+)/) {
1951 $leading_space = $1;
1952 } else {
1953 $leading_space = "";
1954 }
1955 }
1956 $cont =~ s/^$leading_space//;
1957 }
1958 $contents .= $cont . "\n";
1959 }
1960 } else {
1961 # i dont know - bad line? ignore.
1962 print STDERR "${file}:$.: warning: bad line: $_";
1963 ++$warnings;
1964 }
1965}
1966
1967
Jonathan Corbetcc794812018-02-05 15:46:30 -07001968#
1969# STATE_PROTO: reading a function/whatever prototype.
1970#
1971sub process_proto($$) {
1972 my $file = shift;
1973
1974 if (/$doc_inline_oneline/) {
1975 $section = $1;
1976 $contents = $2;
1977 if ($contents ne "") {
1978 $contents .= "\n";
1979 dump_section($file, $section, $contents);
1980 $section = $section_default;
1981 $contents = "";
1982 }
1983 } elsif (/$doc_inline_start/) {
1984 $state = STATE_INLINE;
1985 $inline_doc_state = STATE_INLINE_NAME;
1986 } elsif ($decl_type eq 'function') {
1987 process_proto_function($_, $file);
1988 } else {
1989 process_proto_type($_, $file);
1990 }
1991}
1992
1993
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07001995 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 my $func;
1997 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01001998 my ($orig_file) = @_;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
Jani Nikula1ad560e2016-06-07 10:53:39 +03002000 $file = map_filename($orig_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
2002 if (!open(IN,"<$file")) {
2003 print STDERR "Error: Cannot open file $file\n";
2004 ++$errors;
2005 return;
2006 }
2007
Ilya Dryomova9e73142010-02-26 13:05:47 -08002008 $. = 1;
2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 $section_counter = 0;
2011 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002012 while (s/\\\s*$//) {
2013 $_ .= <IN>;
2014 }
Mauro Carvalho Chehab7c9aa012017-12-18 10:30:12 -02002015 # Replace tabs by spaces
2016 while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {};
Jani Nikula48af6062016-05-26 14:56:05 +03002017 if ($state == STATE_NORMAL) {
Jonathan Corbet07048d12018-02-05 14:15:19 -07002018 process_normal();
Jonathan Corbet3cac2bc2018-02-05 14:36:33 -07002019 } elsif ($state == STATE_NAME) {
2020 process_name($file, $_);
Jonathan Corbet17b78712018-02-05 13:56:45 -07002021 } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE) {
Jonathan Corbetd742f242018-02-05 15:36:05 -07002022 process_body($file, $_);
Jani Nikula48af6062016-05-26 14:56:05 +03002023 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002024 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03002025 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002026 $section = $1;
2027 $contents = $2;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002028 $new_start_line = $.;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002029 if ($contents ne "") {
Mauro Carvalho Chehab7c9aa012017-12-18 10:30:12 -02002030 while (substr($contents, 0, 1) eq " ") {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002031 $contents = substr($contents, 1);
2032 }
Jani Nikulaa0b96c22016-05-26 22:04:06 +03002033 $contents .= "\n";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002034 }
Jani Nikula48af6062016-05-26 14:56:05 +03002035 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002036 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03002037 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002038 if (($contents ne "") && ($contents ne "\n")) {
Jonathan Corbet0bba9242018-02-05 12:40:15 -07002039 dump_section($file, $section, $contents);
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002040 $section = $section_default;
2041 $contents = "";
2042 }
Jani Nikula48af6062016-05-26 14:56:05 +03002043 $state = STATE_PROTO;
2044 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002045 # Regular text
2046 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03002047 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002048 $contents .= $1 . "\n";
Jani Nikula6450c892016-05-26 22:04:42 +03002049 # nuke leading blank lines
2050 if ($contents =~ /^\s*$/) {
2051 $contents = "";
2052 }
Jani Nikula48af6062016-05-26 14:56:05 +03002053 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
2054 $inline_doc_state = STATE_INLINE_ERROR;
Daniel Vettere7ca3112016-07-15 10:19:30 +02002055 print STDERR "${file}:$.: warning: ";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002056 print STDERR "Incorrect use of kernel-doc format: $_";
2057 ++$warnings;
2058 }
2059 }
Jonathan Corbetcc794812018-02-05 15:46:30 -07002060 } elsif ($state == STATE_PROTO) {
2061 process_proto($file, $_);
Jani Nikula48af6062016-05-26 14:56:05 +03002062 } elsif ($state == STATE_DOCBLOCK) {
Daniel Vetterebff7f92016-06-01 23:46:23 +02002063 if (/$doc_end/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 {
Jonathan Corbet0bba9242018-02-05 12:40:15 -07002065 dump_doc_section($file, $section, $contents);
Jani Nikula2f4ad402016-05-30 11:21:06 +03002066 $section = $section_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 $contents = "";
2068 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 %parameterdescs = ();
2070 %parametertypes = ();
2071 @parameterlist = ();
2072 %sections = ();
2073 @sectionlist = ();
2074 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002075 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 }
2077 elsif (/$doc_content/)
2078 {
2079 if ( $1 eq "" )
2080 {
2081 $contents .= $blankline;
2082 }
2083 else
2084 {
2085 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002086 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002087 }
2088 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 }
2090 if ($initial_section_counter == $section_counter) {
Matthew Wilcox3a025e12017-11-20 10:40:40 -08002091 if ($output_mode ne "none") {
2092 print STDERR "${file}:1: warning: no structured comments found\n";
2093 }
Jani Nikulab6c3f452016-05-29 22:19:35 +03002094 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08002095 print STDERR " Was looking for '$_'.\n" for keys %function_table;
2096 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 }
2098}
Randy Dunlap8484baa2011-01-05 16:28:43 -08002099
2100
2101$kernelversion = get_kernel_version();
2102
2103# generate a sequence of code that will splice in highlighting information
2104# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02002105for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03002106 my $pattern = $highlights[$k][0];
2107 my $result = $highlights[$k][1];
2108# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
2109 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08002110}
2111
2112# Read the file that maps relative names to absolute names for
2113# separate source and object directories and for shadow trees.
2114if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
2115 my ($relname, $absname);
2116 while(<SOURCE_MAP>) {
2117 chop();
2118 ($relname, $absname) = (split())[0..1];
2119 $relname =~ s:^/+::;
2120 $source_map{$relname} = $absname;
2121 }
2122 close(SOURCE_MAP);
2123}
2124
Jani Nikula88c2b572016-06-07 11:00:52 +03002125if ($output_selection == OUTPUT_EXPORTED ||
2126 $output_selection == OUTPUT_INTERNAL) {
Jani Nikulac9b2cfb2016-06-07 11:05:53 +03002127
2128 push(@export_file_list, @ARGV);
2129
Jani Nikula88c2b572016-06-07 11:00:52 +03002130 foreach (@export_file_list) {
2131 chomp;
2132 process_export_file($_);
2133 }
2134}
2135
Randy Dunlap8484baa2011-01-05 16:28:43 -08002136foreach (@ARGV) {
2137 chomp;
2138 process_file($_);
2139}
2140if ($verbose && $errors) {
2141 print STDERR "$errors errors\n";
2142}
2143if ($verbose && $warnings) {
2144 print STDERR "$warnings warnings\n";
2145}
2146
Will Deacone814bcc2017-11-29 15:20:03 +00002147exit($output_mode eq "none" ? 0 : $errors);