blob: 33c85dfdfce9b3b6f3509c71d4fd91ef2bf43e2e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#!/usr/bin/perl -w
2
3use strict;
4
5## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ##
6## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ##
7## Copyright (C) 2001 Simon Huggins ##
Randy Dunlap70c95b02012-01-21 10:31:54 -08008## Copyright (C) 2005-2012 Randy Dunlap ##
Dan Luedtke1b40c192012-08-12 10:46:15 +02009## Copyright (C) 2012 Dan Luedtke ##
Linus Torvalds1da177e2005-04-16 15:20:36 -070010## ##
11## #define enhancements by Armin Kuster <akuster@mvista.com> ##
12## Copyright (c) 2000 MontaVista Software, Inc. ##
13## ##
14## This software falls under the GNU General Public License. ##
15## Please read the COPYING file for more information ##
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017# 18/01/2001 - Cleanups
18# Functions prototyped as foo(void) same as foo()
19# Stop eval'ing where we don't need to.
20# -- huggie@earth.li
21
22# 27/06/2001 - Allowed whitespace after initial "/**" and
23# allowed comments before function declarations.
24# -- Christian Kreibich <ck@whoop.org>
25
26# Still to do:
27# - add perldoc documentation
28# - Look more closely at some of the scarier bits :)
29
30# 26/05/2001 - Support for separate source and object trees.
31# Return error code.
32# Keith Owens <kaos@ocs.com.au>
33
34# 23/09/2001 - Added support for typedefs, structs, enums and unions
35# Support for Context section; can be terminated using empty line
36# Small fixes (like spaces vs. \s in regex)
37# -- Tim Jansen <tim@tjansen.de>
38
Dan Luedtke1b40c192012-08-12 10:46:15 +020039# 25/07/2012 - Added support for HTML5
40# -- Dan Luedtke <mail@danrl.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Jani Nikulafadc0b32016-05-12 16:15:36 +030042sub usage {
43 my $message = <<"EOF";
44Usage: $0 [OPTION ...] FILE ...
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Jani Nikulafadc0b32016-05-12 16:15:36 +030046Read C language source or header FILEs, extract embedded documentation comments,
47and print formatted documentation to standard output.
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Jani Nikulafadc0b32016-05-12 16:15:36 +030049The documentation comments are identified by "/**" opening comment mark. See
50Documentation/kernel-doc-nano-HOWTO.txt for the documentation comment syntax.
51
52Output format selection (mutually exclusive):
53 -docbook Output DocBook format.
54 -html Output HTML format.
55 -html5 Output HTML5 format.
56 -list Output symbol list format. This is for use by docproc.
57 -man Output troff manual page format. This is the default.
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +030058 -rst Output reStructuredText format.
Jani Nikulafadc0b32016-05-12 16:15:36 +030059 -text Output plain text format.
60
61Output selection (mutually exclusive):
Jani Nikula86ae2e32016-01-21 13:05:22 +020062 -export Only output documentation for symbols that have 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 Nikula86ae2e32016-01-21 13:05:22 +020065 -internal Only output documentation for symbols that have NOT been
66 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
Jani Nikulac9b2cfb2016-06-07 11:05:53 +030067 in any input FILE or -export-file FILE.
Jani Nikulafadc0b32016-05-12 16:15:36 +030068 -function NAME Only output documentation for the given function(s)
69 or DOC: section title(s). All other functions and DOC:
70 sections are ignored. May be specified multiple times.
71 -nofunction NAME Do NOT output documentation for the given function(s);
72 only output documentation for the other functions and
73 DOC: sections. May be specified multiple times.
74
75Output selection modifiers:
76 -no-doc-sections Do not output DOC: sections.
Daniel Vetter0b0f5f292016-06-03 22:21:34 +020077 -enable-lineno Enable output of #define LINENO lines. Only works with
78 reStructuredText format.
Jani Nikula88c2b572016-06-07 11:00:52 +030079 -export-file FILE Specify an additional FILE in which to look for
80 EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with
81 -export or -internal. May be specified multiple times.
Jani Nikulafadc0b32016-05-12 16:15:36 +030082
83Other parameters:
84 -v Verbose output, more warnings and other information.
85 -h Print this help.
86
87EOF
88 print $message;
89 exit 1;
90}
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92#
93# format of comments.
94# In the following table, (...)? signifies optional structure.
95# (...)* signifies 0 or more structure elements
96# /**
97# * function_name(:)? (- short description)?
98# (* @parameterx: (description of parameter x)?)*
99# (* a blank line)?
100# * (Description:)? (Description of function)?
101# * (section header: (section description)? )*
102# (*)?*/
103#
104# So .. the trivial example would be:
105#
106# /**
107# * my_function
Randy Dunlapb9d973282009-06-09 08:50:38 -0700108# */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#
Randy Dunlap891dcd22007-02-10 01:45:53 -0800110# If the Description: header tag is omitted, then there must be a blank line
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111# after the last parameter specification.
112# e.g.
113# /**
114# * my_function - does my stuff
115# * @my_arg: its mine damnit
116# *
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800117# * Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118# */
119#
120# or, could also use:
121# /**
122# * my_function - does my stuff
123# * @my_arg: its mine damnit
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800124# * Description: Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125# */
126# etc.
127#
Randy Dunlapb9d973282009-06-09 08:50:38 -0700128# Besides functions you can also write documentation for structs, unions,
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800129# enums and typedefs. Instead of the function name you must write the name
130# of the declaration; the struct/union/enum/typedef must always precede
131# the name. Nesting of declarations is not supported.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132# Use the argument mechanism to document members or constants.
133# e.g.
134# /**
135# * struct my_struct - short description
136# * @a: first member
137# * @b: second member
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800138# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139# * Longer description
140# */
141# struct my_struct {
142# int a;
143# int b;
Martin Waitzaeec46b2005-11-13 16:08:13 -0800144# /* private: */
145# int c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146# };
147#
148# All descriptions can be multiline, except the short function description.
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800149#
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300150# For really longs structs, you can also describe arguments inside the
151# body of the struct.
152# eg.
153# /**
154# * struct my_struct - short description
155# * @a: first member
156# * @b: second member
157# *
158# * Longer description
159# */
160# struct my_struct {
161# int a;
162# int b;
163# /**
164# * @c: This is longer description of C
165# *
166# * You can use paragraphs to describe arguments
167# * using this method.
168# */
169# int c;
170# };
171#
172# This should be use only for struct/enum members.
173#
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800174# You can also add additional sections. When documenting kernel functions you
175# should document the "Context:" of the function, e.g. whether the functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176# can be called form interrupts. Unlike other sections you can end it with an
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800177# empty line.
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100178# A non-void function should have a "Return:" section describing the return
179# value(s).
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800180# Example-sections should contain the string EXAMPLE so that they are marked
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181# appropriately in DocBook.
182#
183# Example:
184# /**
185# * user_function - function that can only be called in user context
186# * @a: some argument
187# * Context: !in_interrupt()
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800188# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189# * Some description
190# * Example:
191# * user_function(22);
192# */
193# ...
194#
195#
196# All descriptive text is further processed, scanning for the following special
197# patterns, which are highlighted appropriately.
198#
199# 'funcname()' - function
200# '$ENVVAR' - environmental variable
201# '&struct_name' - name of a structure (up to two words including 'struct')
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100202# '&struct_name.member' - name of a structure member
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203# '@parameter' - name of a parameter
204# '%CONST' - name of a constant.
205
Randy Dunlap8484baa2011-01-05 16:28:43 -0800206## init lots of data
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208my $errors = 0;
209my $warnings = 0;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -0700210my $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212# match expressions used to find embedded type information
213my $type_constant = '\%([-_\w]+)';
214my $type_func = '(\w+)\(\)';
Silvio Frickec950a172016-10-28 10:14:08 +0200215my $type_param = '\@(\w+(\.\.\.)?)';
Jonathan Corbet5219f182016-08-24 16:31:15 -0600216my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217my $type_env = '(\$\w+)';
Paolo Bonzinidf311752017-01-02 16:22:27 +0100218my $type_enum = '\&(enum\s*([_\w]+))';
219my $type_struct = '\&(struct\s*([_\w]+))';
220my $type_typedef = '\&(typedef\s*([_\w]+))';
221my $type_union = '\&(union\s*([_\w]+))';
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100222my $type_member = '\&([_\w]+)(\.|->)([_\w]+)';
Paolo Bonzinidf311752017-01-02 16:22:27 +0100223my $type_fallback = '\&([_\w]+)';
224my $type_enum_xml = '\&amp;(enum\s*([_\w]+))';
225my $type_struct_xml = '\&amp;(struct\s*([_\w]+))';
226my $type_typedef_xml = '\&amp;(typedef\s*([_\w]+))';
227my $type_union_xml = '\&amp;(union\s*([_\w]+))';
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100228my $type_member_xml = '\&amp;([_\w]+)(\.|-\&gt;)([_\w]+)';
Paolo Bonzinidf311752017-01-02 16:22:27 +0100229my $type_fallback_xml = '\&amp([_\w]+)';
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300230my $type_member_func = $type_member . '\(\)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232# Output conversion substitutions.
233# One for each output format
234
235# these work fairly well
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300236my @highlights_html = (
237 [$type_constant, "<i>\$1</i>"],
238 [$type_func, "<b>\$1</b>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100239 [$type_enum_xml, "<i>\$1</i>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300240 [$type_struct_xml, "<i>\$1</i>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100241 [$type_typedef_xml, "<i>\$1</i>"],
242 [$type_union_xml, "<i>\$1</i>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300243 [$type_env, "<b><i>\$1</i></b>"],
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100244 [$type_param, "<tt><b>\$1</b></tt>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100245 [$type_member_xml, "<tt><i>\$1</i>\$2\$3</tt>"],
246 [$type_fallback_xml, "<i>\$1</i>"]
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300247 );
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700248my $local_lt = "\\\\\\\\lt:";
249my $local_gt = "\\\\\\\\gt:";
250my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Dan Luedtke1b40c192012-08-12 10:46:15 +0200252# html version 5
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300253my @highlights_html5 = (
254 [$type_constant, "<span class=\"const\">\$1</span>"],
255 [$type_func, "<span class=\"func\">\$1</span>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100256 [$type_enum_xml, "<span class=\"enum\">\$1</span>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300257 [$type_struct_xml, "<span class=\"struct\">\$1</span>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100258 [$type_typedef_xml, "<span class=\"typedef\">\$1</span>"],
259 [$type_union_xml, "<span class=\"union\">\$1</span>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300260 [$type_env, "<span class=\"env\">\$1</span>"],
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100261 [$type_param, "<span class=\"param\">\$1</span>]"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100262 [$type_member_xml, "<span class=\"literal\"><span class=\"struct\">\$1</span>\$2<span class=\"member\">\$3</span></span>"],
263 [$type_fallback_xml, "<span class=\"struct\">\$1</span>"]
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300264 );
Dan Luedtke1b40c192012-08-12 10:46:15 +0200265my $blankline_html5 = $local_lt . "br /" . $local_gt;
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267# XML, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300268my @highlights_xml = (
269 ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
270 [$type_constant, "<constant>\$1</constant>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100271 [$type_enum_xml, "<type>\$1</type>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300272 [$type_struct_xml, "<structname>\$1</structname>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100273 [$type_typedef_xml, "<type>\$1</type>"],
274 [$type_union_xml, "<structname>\$1</structname>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300275 [$type_param, "<parameter>\$1</parameter>"],
276 [$type_func, "<function>\$1</function>"],
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100277 [$type_env, "<envar>\$1</envar>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100278 [$type_member_xml, "<literal><structname>\$1</structname>\$2<structfield>\$3</structfield></literal>"],
279 [$type_fallback_xml, "<structname>\$1</structname>"]
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300280 );
Johannes Berg5c98fc02007-10-24 15:08:48 -0700281my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
283# gnome, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300284my @highlights_gnome = (
285 [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
286 [$type_func, "<function>\$1</function>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100287 [$type_enum, "<type>\$1</type>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300288 [$type_struct, "<structname>\$1</structname>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100289 [$type_typedef, "<type>\$1</type>"],
290 [$type_union, "<structname>\$1</structname>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300291 [$type_env, "<envar>\$1</envar>"],
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100292 [$type_param, "<parameter>\$1</parameter>" ],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100293 [$type_member, "<literal><structname>\$1</structname>\$2<structfield>\$3</structfield></literal>"],
294 [$type_fallback, "<structname>\$1</structname>"]
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300295 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296my $blankline_gnome = "</para><para>\n";
297
298# these are pretty rough
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300299my @highlights_man = (
300 [$type_constant, "\$1"],
301 [$type_func, "\\\\fB\$1\\\\fP"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100302 [$type_enum, "\\\\fI\$1\\\\fP"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300303 [$type_struct, "\\\\fI\$1\\\\fP"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100304 [$type_typedef, "\\\\fI\$1\\\\fP"],
305 [$type_union, "\\\\fI\$1\\\\fP"],
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100306 [$type_param, "\\\\fI\$1\\\\fP"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100307 [$type_member, "\\\\fI\$1\$2\$3\\\\fP"],
308 [$type_fallback, "\\\\fI\$1\\\\fP"]
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300309 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310my $blankline_man = "";
311
312# text-mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300313my @highlights_text = (
314 [$type_constant, "\$1"],
315 [$type_func, "\$1"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100316 [$type_enum, "\$1"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300317 [$type_struct, "\$1"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100318 [$type_typedef, "\$1"],
319 [$type_union, "\$1"],
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100320 [$type_param, "\$1"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100321 [$type_member, "\$1\$2\$3"],
322 [$type_fallback, "\$1"]
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300323 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324my $blankline_text = "";
325
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300326# rst-mode
327my @highlights_rst = (
328 [$type_constant, "``\$1``"],
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300329 # Note: need to escape () to avoid func matching later
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100330 [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"],
331 [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"],
Jonathan Corbet5219f182016-08-24 16:31:15 -0600332 [$type_fp_param, "**\$1\\\\(\\\\)**"],
Jani Nikulaa19bce62016-05-26 11:28:16 +0300333 [$type_func, "\\:c\\:func\\:`\$1()`"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100334 [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"],
335 [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"],
336 [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"],
337 [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"],
Jani Nikulaa7291e72016-05-26 13:57:06 +0300338 # in rst this can refer to any type
Paolo Bonzinidf311752017-01-02 16:22:27 +0100339 [$type_fallback, "\\:c\\:type\\:`\$1`"],
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300340 [$type_param, "**\$1**"]
341 );
342my $blankline_rst = "\n";
343
Johannes Bergeda603f2010-09-11 15:55:22 -0700344# list mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300345my @highlights_list = (
346 [$type_constant, "\$1"],
347 [$type_func, "\$1"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100348 [$type_enum, "\$1"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300349 [$type_struct, "\$1"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100350 [$type_typedef, "\$1"],
351 [$type_union, "\$1"],
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100352 [$type_param, "\$1"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100353 [$type_member, "\$1"],
354 [$type_fallback, "\$1"]
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300355 );
Johannes Bergeda603f2010-09-11 15:55:22 -0700356my $blankline_list = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358# read arguments
Randy Dunlapb9d973282009-06-09 08:50:38 -0700359if ($#ARGV == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 usage();
361}
362
Randy Dunlap8484baa2011-01-05 16:28:43 -0800363my $kernelversion;
364my $dohighlight = "";
365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366my $verbose = 0;
367my $output_mode = "man";
Daniel Santose314ba32012-10-04 17:15:08 -0700368my $output_preformatted = 0;
Johannes Berg4b445952007-10-24 15:08:48 -0700369my $no_doc_sections = 0;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200370my $enable_lineno = 0;
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300371my @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372my $blankline = $blankline_man;
373my $modulename = "Kernel API";
Jani Nikulab6c3f452016-05-29 22:19:35 +0300374
375use constant {
376 OUTPUT_ALL => 0, # output all symbols and doc sections
377 OUTPUT_INCLUDE => 1, # output only specified symbols
378 OUTPUT_EXCLUDE => 2, # output everything except specified symbols
379 OUTPUT_EXPORTED => 3, # output exported symbols
380 OUTPUT_INTERNAL => 4, # output non-exported symbols
381};
382my $output_selection = OUTPUT_ALL;
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100383my $show_not_found = 0;
384
Jani Nikula88c2b572016-06-07 11:00:52 +0300385my @export_file_list;
386
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100387my @build_time;
388if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
389 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
390 @build_time = gmtime($seconds);
391} else {
392 @build_time = localtime;
393}
394
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800395my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
396 'July', 'August', 'September', 'October',
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100397 'November', 'December')[$build_time[4]] .
398 " " . ($build_time[5]+1900);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Randy Dunlap8484baa2011-01-05 16:28:43 -0800400# Essentially these are globals.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700401# They probably want to be tidied up, made more localised or something.
402# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403# could cause "use of undefined value" or other bugs.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700404my ($function, %function_table, %parametertypes, $declaration_purpose);
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200405my $declaration_start_line;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700406my ($type, $declaration_name, $return_type);
Ilya Dryomov1c32fd02010-02-26 13:06:03 -0800407my ($newsection, $newcontents, $prototype, $brcount, %source_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700409if (defined($ENV{'KBUILD_VERBOSE'})) {
410 $verbose = "$ENV{'KBUILD_VERBOSE'}";
411}
412
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800413# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
415# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
416# We keep track of number of generated entries and generate a dummy
417# if needs be to ensure the expanded template can be postprocessed
418# into html.
419my $section_counter = 0;
420
421my $lineprefix="";
422
Jani Nikula48af6062016-05-26 14:56:05 +0300423# Parser states
424use constant {
425 STATE_NORMAL => 0, # normal code
426 STATE_NAME => 1, # looking for function name
427 STATE_FIELD => 2, # scanning field start
428 STATE_PROTO => 3, # scanning prototype
429 STATE_DOCBLOCK => 4, # documentation block
430 STATE_INLINE => 5, # gathering documentation outside main block
431};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700433my $in_doc_sect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Jani Nikula48af6062016-05-26 14:56:05 +0300435# Inline documentation state
436use constant {
437 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
438 STATE_INLINE_NAME => 1, # looking for member name (@foo:)
439 STATE_INLINE_TEXT => 2, # looking for member documentation
440 STATE_INLINE_END => 3, # done
441 STATE_INLINE_ERROR => 4, # error - Comment without header was found.
442 # Spit a warning as it's not
443 # proper kernel-doc and ignore the rest.
444};
445my $inline_doc_state;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300446
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447#declaration types: can be
448# 'function', 'struct', 'union', 'enum', 'typedef'
449my $decl_type;
450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
452my $doc_end = '\*/';
453my $doc_com = '\s*\*\s*';
Daniel Santos12ae6772012-10-04 17:15:10 -0700454my $doc_com_body = '\s*\* ?';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700455my $doc_decl = $doc_com . '(\w+)';
Jani Nikulaf624ade2016-05-29 11:35:28 +0300456# @params and a strictly limited set of supported section names
Jonathan Corbet8569de62016-06-09 13:35:05 -0600457my $doc_sect = $doc_com .
Jonathan Corbetef000282016-08-26 07:14:08 -0600458 '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700459my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700460my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Jani Nikula48af6062016-05-26 14:56:05 +0300461my $doc_inline_start = '^\s*/\*\*\s*$';
462my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
463my $doc_inline_end = '^\s*\*/\s*$';
Jani Nikula0c9aa202016-11-16 17:26:16 +0200464my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200465my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467my %parameterdescs;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200468my %parameterdesc_start_lines;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469my @parameterlist;
470my %sections;
471my @sectionlist;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200472my %section_start_lines;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800473my $sectcheck;
474my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
476my $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200477my $new_start_line = 0;
Jani Nikulaf624ade2016-05-29 11:35:28 +0300478
479# the canonical section names. see also $doc_sect above.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480my $section_default = "Description"; # default section
481my $section_intro = "Introduction";
482my $section = $section_default;
483my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100484my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
486my $undescribed = "-- undescribed --";
487
488reset_state();
489
490while ($ARGV[0] =~ m/^-(.*)/) {
491 my $cmd = shift @ARGV;
492 if ($cmd eq "-html") {
493 $output_mode = "html";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300494 @highlights = @highlights_html;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200496 } elsif ($cmd eq "-html5") {
497 $output_mode = "html5";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300498 @highlights = @highlights_html5;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200499 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 } elsif ($cmd eq "-man") {
501 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300502 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 $blankline = $blankline_man;
504 } elsif ($cmd eq "-text") {
505 $output_mode = "text";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300506 @highlights = @highlights_text;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 $blankline = $blankline_text;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300508 } elsif ($cmd eq "-rst") {
509 $output_mode = "rst";
510 @highlights = @highlights_rst;
511 $blankline = $blankline_rst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 } elsif ($cmd eq "-docbook") {
513 $output_mode = "xml";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300514 @highlights = @highlights_xml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700516 } elsif ($cmd eq "-list") {
517 $output_mode = "list";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300518 @highlights = @highlights_list;
Johannes Bergeda603f2010-09-11 15:55:22 -0700519 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 } elsif ($cmd eq "-gnome") {
521 $output_mode = "gnome";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300522 @highlights = @highlights_gnome;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 $blankline = $blankline_gnome;
524 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
525 $modulename = shift @ARGV;
526 } elsif ($cmd eq "-function") { # to only output specific functions
Jani Nikulab6c3f452016-05-29 22:19:35 +0300527 $output_selection = OUTPUT_INCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 $function = shift @ARGV;
529 $function_table{$function} = 1;
Jani Nikulab6c3f452016-05-29 22:19:35 +0300530 } elsif ($cmd eq "-nofunction") { # output all except specific functions
531 $output_selection = OUTPUT_EXCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 $function = shift @ARGV;
533 $function_table{$function} = 1;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200534 } elsif ($cmd eq "-export") { # only exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300535 $output_selection = OUTPUT_EXPORTED;
Jani Nikulada9726e2016-06-07 10:29:59 +0300536 %function_table = ();
Jani Nikula86ae2e32016-01-21 13:05:22 +0200537 } elsif ($cmd eq "-internal") { # only non-exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300538 $output_selection = OUTPUT_INTERNAL;
Jani Nikulada9726e2016-06-07 10:29:59 +0300539 %function_table = ();
Jani Nikula88c2b572016-06-07 11:00:52 +0300540 } elsif ($cmd eq "-export-file") {
541 my $file = shift @ARGV;
542 push(@export_file_list, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 } elsif ($cmd eq "-v") {
544 $verbose = 1;
545 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
546 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700547 } elsif ($cmd eq '-no-doc-sections') {
548 $no_doc_sections = 1;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200549 } elsif ($cmd eq '-enable-lineno') {
550 $enable_lineno = 1;
Johannes Berge946c43a2013-11-12 15:11:12 -0800551 } elsif ($cmd eq '-show-not-found') {
552 $show_not_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 }
554}
555
Randy Dunlap8484baa2011-01-05 16:28:43 -0800556# continue execution near EOF;
557
Borislav Petkov53f049f2007-05-08 00:30:54 -0700558# get kernel version from env
559sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700560 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700561
562 if (defined($ENV{'KERNELVERSION'})) {
563 $version = $ENV{'KERNELVERSION'};
564 }
565 return $version;
566}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200568#
569sub print_lineno {
570 my $lineno = shift;
571 if ($enable_lineno && defined($lineno)) {
572 print "#define LINENO " . $lineno . "\n";
573 }
574}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575##
576# dumps section contents to arrays/hashes intended for that purpose.
577#
578sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700579 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 my $name = shift;
581 my $contents = join "\n", @_;
582
Jani Nikula13901ef2016-05-26 08:57:29 +0300583 if ($name =~ m/$type_param/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 $name = $1;
585 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800586 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200587 $parameterdesc_start_lines{$name} = $new_start_line;
588 $new_start_line = 0;
Randy Dunlapced69092008-12-01 13:14:03 -0800589 } elsif ($name eq "@\.\.\.") {
Randy Dunlapced69092008-12-01 13:14:03 -0800590 $name = "...";
591 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800592 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200593 $parameterdesc_start_lines{$name} = $new_start_line;
594 $new_start_line = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 } else {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700596 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Jani Nikula95b6be92016-06-10 11:14:05 +0300597 # Only warn on user specified duplicate section names.
598 if ($name ne $section_default) {
599 print STDERR "${file}:$.: warning: duplicate section name '$name'\n";
600 ++$warnings;
601 }
Jani Nikula32217762016-05-29 09:40:44 +0300602 $sections{$name} .= $contents;
603 } else {
604 $sections{$name} = $contents;
605 push @sectionlist, $name;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200606 $section_start_lines{$name} = $new_start_line;
607 $new_start_line = 0;
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700608 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 }
610}
611
612##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700613# dump DOC: section after checking that it should go out
614#
615sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700616 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700617 my $name = shift;
618 my $contents = join "\n", @_;
619
Johannes Berg4b445952007-10-24 15:08:48 -0700620 if ($no_doc_sections) {
621 return;
622 }
623
Jani Nikulab6c3f452016-05-29 22:19:35 +0300624 if (($output_selection == OUTPUT_ALL) ||
625 ($output_selection == OUTPUT_INCLUDE &&
626 defined($function_table{$name})) ||
627 ($output_selection == OUTPUT_EXCLUDE &&
628 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700629 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700630 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700631 output_blockhead({'sectionlist' => \@sectionlist,
632 'sections' => \%sections,
633 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300634 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700635 }
636}
637
638##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639# output function
640#
641# parameterdescs, a hash.
642# function => "function name"
643# parameterlist => @list of parameters
644# parameterdescs => %parameter descriptions
645# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800646# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800647#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
649sub output_highlight {
650 my $contents = join "\n",@_;
651 my $line;
652
653# DEBUG
654# if (!defined $contents) {
655# use Carp;
656# confess "output_highlight got called with no args?\n";
657# }
658
Dan Luedtke1b40c192012-08-12 10:46:15 +0200659 if ($output_mode eq "html" || $output_mode eq "html5" ||
660 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700661 $contents = local_unescape($contents);
662 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800663 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700664 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700665# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 eval $dohighlight;
667 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700668# print STDERR "contents af:$contents\n";
669
Dan Luedtke1b40c192012-08-12 10:46:15 +0200670# strip whitespaces when generating html5
671 if ($output_mode eq "html5") {
672 $contents =~ s/^\s+//;
673 $contents =~ s/\s+$//;
674 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700676 if (! $output_preformatted) {
677 $line =~ s/^\s*//;
678 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700679 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700680 if (! $output_preformatted) {
681 print $lineprefix, local_unescape($blankline);
682 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700684 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700685 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
686 print "\\&$line";
687 } else {
688 print $lineprefix, $line;
689 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 }
691 print "\n";
692 }
693}
694
Dan Luedtke1b40c192012-08-12 10:46:15 +0200695# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696sub output_section_html(%) {
697 my %args = %{$_[0]};
698 my $section;
699
700 foreach $section (@{$args{'sectionlist'}}) {
701 print "<h3>$section</h3>\n";
702 print "<blockquote>\n";
703 output_highlight($args{'sections'}{$section});
704 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800705 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706}
707
708# output enum in html
709sub output_enum_html(%) {
710 my %args = %{$_[0]};
711 my ($parameter);
712 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700713 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
Randy Dunlapb9d973282009-06-09 08:50:38 -0700715 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 $count = 0;
717 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700718 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 if ($count != $#{$args{'parameterlist'}}) {
720 $count++;
721 print ",\n";
722 }
723 print "<br>";
724 }
725 print "};<br>\n";
726
727 print "<h3>Constants</h3>\n";
728 print "<dl>\n";
729 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700730 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 print "<dd>";
732 output_highlight($args{'parameterdescs'}{$parameter});
733 }
734 print "</dl>\n";
735 output_section_html(@_);
736 print "<hr>\n";
737}
738
Randy Dunlapd28bee02006-02-01 03:06:57 -0800739# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740sub output_typedef_html(%) {
741 my %args = %{$_[0]};
742 my ($parameter);
743 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700744 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745
Randy Dunlapb9d973282009-06-09 08:50:38 -0700746 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 output_section_html(@_);
748 print "<hr>\n";
749}
750
751# output struct in html
752sub output_struct_html(%) {
753 my %args = %{$_[0]};
754 my ($parameter);
755
Randy Dunlapb9d973282009-06-09 08:50:38 -0700756 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
757 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 foreach $parameter (@{$args{'parameterlist'}}) {
759 if ($parameter =~ /^#/) {
760 print "$parameter<br>\n";
761 next;
762 }
763 my $parameter_name = $parameter;
764 $parameter_name =~ s/\[.*//;
765
Randy Dunlap3c308792007-05-08 00:24:39 -0700766 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 $type = $args{'parametertypes'}{$parameter};
768 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
769 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700770 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700772 # bitfield
773 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700775 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 }
777 }
778 print "};<br>\n";
779
780 print "<h3>Members</h3>\n";
781 print "<dl>\n";
782 foreach $parameter (@{$args{'parameterlist'}}) {
783 ($parameter =~ /^#/) && next;
784
785 my $parameter_name = $parameter;
786 $parameter_name =~ s/\[.*//;
787
Randy Dunlap3c308792007-05-08 00:24:39 -0700788 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700789 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 print "<dd>";
791 output_highlight($args{'parameterdescs'}{$parameter_name});
792 }
793 print "</dl>\n";
794 output_section_html(@_);
795 print "<hr>\n";
796}
797
798# output function in html
799sub output_function_html(%) {
800 my %args = %{$_[0]};
801 my ($parameter, $section);
802 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Randy Dunlapb9d973282009-06-09 08:50:38 -0700804 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
805 print "<i>" . $args{'functiontype'} . "</i>\n";
806 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 print "(";
808 $count = 0;
809 foreach $parameter (@{$args{'parameterlist'}}) {
810 $type = $args{'parametertypes'}{$parameter};
811 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
812 # pointer-to-function
813 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
814 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700815 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 }
817 if ($count != $#{$args{'parameterlist'}}) {
818 $count++;
819 print ",\n";
820 }
821 }
822 print ")\n";
823
824 print "<h3>Arguments</h3>\n";
825 print "<dl>\n";
826 foreach $parameter (@{$args{'parameterlist'}}) {
827 my $parameter_name = $parameter;
828 $parameter_name =~ s/\[.*//;
829
Randy Dunlap3c308792007-05-08 00:24:39 -0700830 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700831 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 print "<dd>";
833 output_highlight($args{'parameterdescs'}{$parameter_name});
834 }
835 print "</dl>\n";
836 output_section_html(@_);
837 print "<hr>\n";
838}
839
Johannes Bergb112e0f2007-10-24 15:08:48 -0700840# output DOC: block header in html
841sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 my %args = %{$_[0]};
843 my ($parameter, $section);
844 my $count;
845
846 foreach $section (@{$args{'sectionlist'}}) {
847 print "<h3>$section</h3>\n";
848 print "<ul>\n";
849 output_highlight($args{'sections'}{$section});
850 print "</ul>\n";
851 }
852 print "<hr>\n";
853}
854
Dan Luedtke1b40c192012-08-12 10:46:15 +0200855# output sections in html5
856sub output_section_html5(%) {
857 my %args = %{$_[0]};
858 my $section;
859
860 foreach $section (@{$args{'sectionlist'}}) {
861 print "<section>\n";
862 print "<h1>$section</h1>\n";
863 print "<p>\n";
864 output_highlight($args{'sections'}{$section});
865 print "</p>\n";
866 print "</section>\n";
867 }
868}
869
870# output enum in html5
871sub output_enum_html5(%) {
872 my %args = %{$_[0]};
873 my ($parameter);
874 my $count;
875 my $html5id;
876
877 $html5id = $args{'enum'};
878 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
879 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
880 print "<h1>enum " . $args{'enum'} . "</h1>\n";
881 print "<ol class=\"code\">\n";
882 print "<li>";
883 print "<span class=\"keyword\">enum</span> ";
884 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
885 print "</li>\n";
886 $count = 0;
887 foreach $parameter (@{$args{'parameterlist'}}) {
888 print "<li class=\"indent\">";
889 print "<span class=\"param\">" . $parameter . "</span>";
890 if ($count != $#{$args{'parameterlist'}}) {
891 $count++;
892 print ",";
893 }
894 print "</li>\n";
895 }
896 print "<li>};</li>\n";
897 print "</ol>\n";
898
899 print "<section>\n";
900 print "<h1>Constants</h1>\n";
901 print "<dl>\n";
902 foreach $parameter (@{$args{'parameterlist'}}) {
903 print "<dt>" . $parameter . "</dt>\n";
904 print "<dd>";
905 output_highlight($args{'parameterdescs'}{$parameter});
906 print "</dd>\n";
907 }
908 print "</dl>\n";
909 print "</section>\n";
910 output_section_html5(@_);
911 print "</article>\n";
912}
913
914# output typedef in html5
915sub output_typedef_html5(%) {
916 my %args = %{$_[0]};
917 my ($parameter);
918 my $count;
919 my $html5id;
920
921 $html5id = $args{'typedef'};
922 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
923 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
924 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
925
926 print "<ol class=\"code\">\n";
927 print "<li>";
928 print "<span class=\"keyword\">typedef</span> ";
929 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
930 print "</li>\n";
931 print "</ol>\n";
932 output_section_html5(@_);
933 print "</article>\n";
934}
935
936# output struct in html5
937sub output_struct_html5(%) {
938 my %args = %{$_[0]};
939 my ($parameter);
940 my $html5id;
941
942 $html5id = $args{'struct'};
943 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
944 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
945 print "<hgroup>\n";
946 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
947 print "<h2>". $args{'purpose'} . "</h2>\n";
948 print "</hgroup>\n";
949 print "<ol class=\"code\">\n";
950 print "<li>";
951 print "<span class=\"type\">" . $args{'type'} . "</span> ";
952 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
953 print "</li>\n";
954 foreach $parameter (@{$args{'parameterlist'}}) {
955 print "<li class=\"indent\">";
956 if ($parameter =~ /^#/) {
957 print "<span class=\"param\">" . $parameter ."</span>\n";
958 print "</li>\n";
959 next;
960 }
961 my $parameter_name = $parameter;
962 $parameter_name =~ s/\[.*//;
963
964 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
965 $type = $args{'parametertypes'}{$parameter};
966 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
967 # pointer-to-function
968 print "<span class=\"type\">$1</span> ";
969 print "<span class=\"param\">$parameter</span>";
970 print "<span class=\"type\">)</span> ";
971 print "(<span class=\"args\">$2</span>);";
972 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
973 # bitfield
974 print "<span class=\"type\">$1</span> ";
975 print "<span class=\"param\">$parameter</span>";
976 print "<span class=\"bits\">$2</span>;";
977 } else {
978 print "<span class=\"type\">$type</span> ";
979 print "<span class=\"param\">$parameter</span>;";
980 }
981 print "</li>\n";
982 }
983 print "<li>};</li>\n";
984 print "</ol>\n";
985
986 print "<section>\n";
987 print "<h1>Members</h1>\n";
988 print "<dl>\n";
989 foreach $parameter (@{$args{'parameterlist'}}) {
990 ($parameter =~ /^#/) && next;
991
992 my $parameter_name = $parameter;
993 $parameter_name =~ s/\[.*//;
994
995 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
996 print "<dt>" . $parameter . "</dt>\n";
997 print "<dd>";
998 output_highlight($args{'parameterdescs'}{$parameter_name});
999 print "</dd>\n";
1000 }
1001 print "</dl>\n";
1002 print "</section>\n";
1003 output_section_html5(@_);
1004 print "</article>\n";
1005}
1006
1007# output function in html5
1008sub output_function_html5(%) {
1009 my %args = %{$_[0]};
1010 my ($parameter, $section);
1011 my $count;
1012 my $html5id;
1013
1014 $html5id = $args{'function'};
1015 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1016 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
1017 print "<hgroup>\n";
1018 print "<h1>" . $args{'function'} . "</h1>";
1019 print "<h2>" . $args{'purpose'} . "</h2>\n";
1020 print "</hgroup>\n";
1021 print "<ol class=\"code\">\n";
1022 print "<li>";
1023 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
1024 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
1025 print "</li>";
1026 $count = 0;
1027 foreach $parameter (@{$args{'parameterlist'}}) {
1028 print "<li class=\"indent\">";
1029 $type = $args{'parametertypes'}{$parameter};
1030 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1031 # pointer-to-function
1032 print "<span class=\"type\">$1</span> ";
1033 print "<span class=\"param\">$parameter</span>";
1034 print "<span class=\"type\">)</span> ";
1035 print "(<span class=\"args\">$2</span>)";
1036 } else {
1037 print "<span class=\"type\">$type</span> ";
1038 print "<span class=\"param\">$parameter</span>";
1039 }
1040 if ($count != $#{$args{'parameterlist'}}) {
1041 $count++;
1042 print ",";
1043 }
1044 print "</li>\n";
1045 }
1046 print "<li>)</li>\n";
1047 print "</ol>\n";
1048
1049 print "<section>\n";
1050 print "<h1>Arguments</h1>\n";
1051 print "<p>\n";
1052 print "<dl>\n";
1053 foreach $parameter (@{$args{'parameterlist'}}) {
1054 my $parameter_name = $parameter;
1055 $parameter_name =~ s/\[.*//;
1056
1057 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1058 print "<dt>" . $parameter . "</dt>\n";
1059 print "<dd>";
1060 output_highlight($args{'parameterdescs'}{$parameter_name});
1061 print "</dd>\n";
1062 }
1063 print "</dl>\n";
1064 print "</section>\n";
1065 output_section_html5(@_);
1066 print "</article>\n";
1067}
1068
1069# output DOC: block header in html5
1070sub output_blockhead_html5(%) {
1071 my %args = %{$_[0]};
1072 my ($parameter, $section);
1073 my $count;
1074 my $html5id;
1075
1076 foreach $section (@{$args{'sectionlist'}}) {
1077 $html5id = $section;
1078 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1079 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1080 print "<h1>$section</h1>\n";
1081 print "<p>\n";
1082 output_highlight($args{'sections'}{$section});
1083 print "</p>\n";
1084 }
1085 print "</article>\n";
1086}
1087
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088sub output_section_xml(%) {
1089 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001090 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 # print out each section
1092 $lineprefix=" ";
1093 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001094 print "<refsect1>\n";
1095 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001097 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001098 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001099 } else {
1100 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 }
1102 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001103 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001105 print "</programlisting></informalexample>\n";
1106 } else {
1107 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001109 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 }
1111}
1112
1113# output function in XML DocBook
1114sub output_function_xml(%) {
1115 my %args = %{$_[0]};
1116 my ($parameter, $section);
1117 my $count;
1118 my $id;
1119
Randy Dunlapb9d973282009-06-09 08:50:38 -07001120 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 $id =~ s/[^A-Za-z0-9]/-/g;
1122
Pavel Pisa5449bc92007-02-10 01:45:37 -08001123 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001124 print "<refentryinfo>\n";
1125 print " <title>LINUX</title>\n";
1126 print " <productname>Kernel Hackers Manual</productname>\n";
1127 print " <date>$man_date</date>\n";
1128 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001130 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001131 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001132 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 print "</refmeta>\n";
1134 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001135 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 print " <refpurpose>\n";
1137 print " ";
1138 output_highlight ($args{'purpose'});
1139 print " </refpurpose>\n";
1140 print "</refnamediv>\n";
1141
1142 print "<refsynopsisdiv>\n";
1143 print " <title>Synopsis</title>\n";
1144 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001145 print " <funcdef>" . $args{'functiontype'} . " ";
1146 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
1148 $count = 0;
1149 if ($#{$args{'parameterlist'}} >= 0) {
1150 foreach $parameter (@{$args{'parameterlist'}}) {
1151 $type = $args{'parametertypes'}{$parameter};
1152 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1153 # pointer-to-function
1154 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1155 print " <funcparams>$2</funcparams></paramdef>\n";
1156 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001157 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 print " <parameter>$parameter</parameter></paramdef>\n";
1159 }
1160 }
1161 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001162 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 }
1164 print " </funcprototype></funcsynopsis>\n";
1165 print "</refsynopsisdiv>\n";
1166
1167 # print parameters
1168 print "<refsect1>\n <title>Arguments</title>\n";
1169 if ($#{$args{'parameterlist'}} >= 0) {
1170 print " <variablelist>\n";
1171 foreach $parameter (@{$args{'parameterlist'}}) {
1172 my $parameter_name = $parameter;
1173 $parameter_name =~ s/\[.*//;
Paolo Bonzinifc6d7af2017-01-02 16:22:25 +01001174 $type = $args{'parametertypes'}{$parameter};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Paolo Bonzinifc6d7af2017-01-02 16:22:25 +01001176 print " <varlistentry>\n <term><parameter>$type $parameter</parameter></term>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 print " <listitem>\n <para>\n";
1178 $lineprefix=" ";
1179 output_highlight($args{'parameterdescs'}{$parameter_name});
1180 print " </para>\n </listitem>\n </varlistentry>\n";
1181 }
1182 print " </variablelist>\n";
1183 } else {
1184 print " <para>\n None\n </para>\n";
1185 }
1186 print "</refsect1>\n";
1187
1188 output_section_xml(@_);
1189 print "</refentry>\n\n";
1190}
1191
1192# output struct in XML DocBook
1193sub output_struct_xml(%) {
1194 my %args = %{$_[0]};
1195 my ($parameter, $section);
1196 my $id;
1197
Randy Dunlapb9d973282009-06-09 08:50:38 -07001198 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 $id =~ s/[^A-Za-z0-9]/-/g;
1200
Pavel Pisa5449bc92007-02-10 01:45:37 -08001201 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001202 print "<refentryinfo>\n";
1203 print " <title>LINUX</title>\n";
1204 print " <productname>Kernel Hackers Manual</productname>\n";
1205 print " <date>$man_date</date>\n";
1206 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001208 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001209 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001210 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 print "</refmeta>\n";
1212 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001213 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 print " <refpurpose>\n";
1215 print " ";
1216 output_highlight ($args{'purpose'});
1217 print " </refpurpose>\n";
1218 print "</refnamediv>\n";
1219
1220 print "<refsynopsisdiv>\n";
1221 print " <title>Synopsis</title>\n";
1222 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001223 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 foreach $parameter (@{$args{'parameterlist'}}) {
1225 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001226 my $prm = $parameter;
1227 # convert data read & converted thru xml_escape() into &xyz; format:
1228 # This allows us to have #define macros interspersed in a struct.
1229 $prm =~ s/\\\\\\/\&/g;
1230 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 next;
1232 }
1233
1234 my $parameter_name = $parameter;
1235 $parameter_name =~ s/\[.*//;
1236
1237 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001238 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 $type = $args{'parametertypes'}{$parameter};
1240 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1241 # pointer-to-function
1242 print " $1 $parameter) ($2);\n";
1243 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001244 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 print " $1 $parameter$2;\n";
1246 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001247 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 }
1249 }
1250 print "};";
1251 print " </programlisting>\n";
1252 print "</refsynopsisdiv>\n";
1253
1254 print " <refsect1>\n";
1255 print " <title>Members</title>\n";
1256
Randy Dunlap39f00c02008-09-22 13:57:44 -07001257 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 print " <variablelist>\n";
1259 foreach $parameter (@{$args{'parameterlist'}}) {
1260 ($parameter =~ /^#/) && next;
1261
1262 my $parameter_name = $parameter;
1263 $parameter_name =~ s/\[.*//;
1264
1265 defined($args{'parameterdescs'}{$parameter_name}) || next;
1266 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Paolo Bonzinifc6d7af2017-01-02 16:22:25 +01001267 $type = $args{'parametertypes'}{$parameter};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 print " <varlistentry>";
Paolo Bonzinifc6d7af2017-01-02 16:22:25 +01001269 print " <term><literal>$type $parameter</literal></term>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 print " <listitem><para>\n";
1271 output_highlight($args{'parameterdescs'}{$parameter_name});
1272 print " </para></listitem>\n";
1273 print " </varlistentry>\n";
1274 }
1275 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001276 } else {
1277 print " <para>\n None\n </para>\n";
1278 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 print " </refsect1>\n";
1280
1281 output_section_xml(@_);
1282
1283 print "</refentry>\n\n";
1284}
1285
1286# output enum in XML DocBook
1287sub output_enum_xml(%) {
1288 my %args = %{$_[0]};
1289 my ($parameter, $section);
1290 my $count;
1291 my $id;
1292
Randy Dunlapb9d973282009-06-09 08:50:38 -07001293 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 $id =~ s/[^A-Za-z0-9]/-/g;
1295
Pavel Pisa5449bc92007-02-10 01:45:37 -08001296 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001297 print "<refentryinfo>\n";
1298 print " <title>LINUX</title>\n";
1299 print " <productname>Kernel Hackers Manual</productname>\n";
1300 print " <date>$man_date</date>\n";
1301 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001303 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001304 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001305 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 print "</refmeta>\n";
1307 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001308 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 print " <refpurpose>\n";
1310 print " ";
1311 output_highlight ($args{'purpose'});
1312 print " </refpurpose>\n";
1313 print "</refnamediv>\n";
1314
1315 print "<refsynopsisdiv>\n";
1316 print " <title>Synopsis</title>\n";
1317 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001318 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 $count = 0;
1320 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001321 print " $parameter";
1322 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 $count++;
1324 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001325 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 print "\n";
1327 }
1328 print "};";
1329 print " </programlisting>\n";
1330 print "</refsynopsisdiv>\n";
1331
1332 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001333 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 print " <variablelist>\n";
1335 foreach $parameter (@{$args{'parameterlist'}}) {
1336 my $parameter_name = $parameter;
1337 $parameter_name =~ s/\[.*//;
1338
1339 print " <varlistentry>";
1340 print " <term>$parameter</term>\n";
1341 print " <listitem><para>\n";
1342 output_highlight($args{'parameterdescs'}{$parameter_name});
1343 print " </para></listitem>\n";
1344 print " </varlistentry>\n";
1345 }
1346 print " </variablelist>\n";
1347 print "</refsect1>\n";
1348
1349 output_section_xml(@_);
1350
1351 print "</refentry>\n\n";
1352}
1353
1354# output typedef in XML DocBook
1355sub output_typedef_xml(%) {
1356 my %args = %{$_[0]};
1357 my ($parameter, $section);
1358 my $id;
1359
Randy Dunlapb9d973282009-06-09 08:50:38 -07001360 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 $id =~ s/[^A-Za-z0-9]/-/g;
1362
Pavel Pisa5449bc92007-02-10 01:45:37 -08001363 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001364 print "<refentryinfo>\n";
1365 print " <title>LINUX</title>\n";
1366 print " <productname>Kernel Hackers Manual</productname>\n";
1367 print " <date>$man_date</date>\n";
1368 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001370 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001371 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 print "</refmeta>\n";
1373 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001374 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 print " <refpurpose>\n";
1376 print " ";
1377 output_highlight ($args{'purpose'});
1378 print " </refpurpose>\n";
1379 print "</refnamediv>\n";
1380
1381 print "<refsynopsisdiv>\n";
1382 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001383 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 print "</refsynopsisdiv>\n";
1385
1386 output_section_xml(@_);
1387
1388 print "</refentry>\n\n";
1389}
1390
1391# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001392sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 my %args = %{$_[0]};
1394 my ($parameter, $section);
1395 my $count;
1396
1397 my $id = $args{'module'};
1398 $id =~ s/[^A-Za-z0-9]/-/g;
1399
1400 # print out each section
1401 $lineprefix=" ";
1402 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001403 if (!$args{'content-only'}) {
1404 print "<refsect1>\n <title>$section</title>\n";
1405 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 if ($section =~ m/EXAMPLE/i) {
1407 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001408 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001409 } else {
1410 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 }
1412 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001413 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 if ($section =~ m/EXAMPLE/i) {
1415 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001416 } else {
1417 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001419 if (!$args{'content-only'}) {
1420 print "\n</refsect1>\n";
1421 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 }
1423
1424 print "\n\n";
1425}
1426
1427# output in XML DocBook
1428sub output_function_gnome {
1429 my %args = %{$_[0]};
1430 my ($parameter, $section);
1431 my $count;
1432 my $id;
1433
Randy Dunlapb9d973282009-06-09 08:50:38 -07001434 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 $id =~ s/[^A-Za-z0-9]/-/g;
1436
1437 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001438 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439
1440 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001441 print " <funcdef>" . $args{'functiontype'} . " ";
1442 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 print "</function></funcdef>\n";
1444
1445 $count = 0;
1446 if ($#{$args{'parameterlist'}} >= 0) {
1447 foreach $parameter (@{$args{'parameterlist'}}) {
1448 $type = $args{'parametertypes'}{$parameter};
1449 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1450 # pointer-to-function
1451 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1452 print " <funcparams>$2</funcparams></paramdef>\n";
1453 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001454 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 print " <parameter>$parameter</parameter></paramdef>\n";
1456 }
1457 }
1458 } else {
1459 print " <void>\n";
1460 }
1461 print " </funcsynopsis>\n";
1462 if ($#{$args{'parameterlist'}} >= 0) {
1463 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1464 print "<tgroup cols=\"2\">\n";
1465 print "<colspec colwidth=\"2*\">\n";
1466 print "<colspec colwidth=\"8*\">\n";
1467 print "<tbody>\n";
1468 foreach $parameter (@{$args{'parameterlist'}}) {
1469 my $parameter_name = $parameter;
1470 $parameter_name =~ s/\[.*//;
1471
1472 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1473 print " <entry>\n";
1474 $lineprefix=" ";
1475 output_highlight($args{'parameterdescs'}{$parameter_name});
1476 print " </entry></row>\n";
1477 }
1478 print " </tbody></tgroup></informaltable>\n";
1479 } else {
1480 print " <para>\n None\n </para>\n";
1481 }
1482
1483 # print out each section
1484 $lineprefix=" ";
1485 foreach $section (@{$args{'sectionlist'}}) {
1486 print "<simplesect>\n <title>$section</title>\n";
1487 if ($section =~ m/EXAMPLE/i) {
1488 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001489 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 } else {
1491 }
1492 print "<para>\n";
1493 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001494 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 print "</para>\n";
1496 if ($section =~ m/EXAMPLE/i) {
1497 print "</programlisting></example>\n";
1498 } else {
1499 }
1500 print " </simplesect>\n";
1501 }
1502
1503 print "</sect2>\n\n";
1504}
1505
1506##
1507# output function in man
1508sub output_function_man(%) {
1509 my %args = %{$_[0]};
1510 my ($parameter, $section);
1511 my $count;
1512
1513 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1514
1515 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001516 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
1518 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001519 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001520 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001521 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001522 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 $count = 0;
1525 my $parenth = "(";
1526 my $post = ",";
1527 foreach my $parameter (@{$args{'parameterlist'}}) {
1528 if ($count == $#{$args{'parameterlist'}}) {
1529 $post = ");";
1530 }
1531 $type = $args{'parametertypes'}{$parameter};
1532 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1533 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001534 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 } else {
1536 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001537 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 }
1539 $count++;
1540 $parenth = "";
1541 }
1542
1543 print ".SH ARGUMENTS\n";
1544 foreach $parameter (@{$args{'parameterlist'}}) {
1545 my $parameter_name = $parameter;
1546 $parameter_name =~ s/\[.*//;
1547
Randy Dunlapb9d973282009-06-09 08:50:38 -07001548 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 output_highlight($args{'parameterdescs'}{$parameter_name});
1550 }
1551 foreach $section (@{$args{'sectionlist'}}) {
1552 print ".SH \"", uc $section, "\"\n";
1553 output_highlight($args{'sections'}{$section});
1554 }
1555}
1556
1557##
1558# output enum in man
1559sub output_enum_man(%) {
1560 my %args = %{$_[0]};
1561 my ($parameter, $section);
1562 my $count;
1563
1564 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1565
1566 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001567 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
1569 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001570 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 $count = 0;
1572 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001573 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 if ($count == $#{$args{'parameterlist'}}) {
1575 print "\n};\n";
1576 last;
1577 }
1578 else {
1579 print ", \n.br\n";
1580 }
1581 $count++;
1582 }
1583
1584 print ".SH Constants\n";
1585 foreach $parameter (@{$args{'parameterlist'}}) {
1586 my $parameter_name = $parameter;
1587 $parameter_name =~ s/\[.*//;
1588
Randy Dunlapb9d973282009-06-09 08:50:38 -07001589 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 output_highlight($args{'parameterdescs'}{$parameter_name});
1591 }
1592 foreach $section (@{$args{'sectionlist'}}) {
1593 print ".SH \"$section\"\n";
1594 output_highlight($args{'sections'}{$section});
1595 }
1596}
1597
1598##
1599# output struct in man
1600sub output_struct_man(%) {
1601 my %args = %{$_[0]};
1602 my ($parameter, $section);
1603
Randy Dunlapb9d973282009-06-09 08:50:38 -07001604 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605
1606 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001607 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
1609 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001610 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611
1612 foreach my $parameter (@{$args{'parameterlist'}}) {
1613 if ($parameter =~ /^#/) {
1614 print ".BI \"$parameter\"\n.br\n";
1615 next;
1616 }
1617 my $parameter_name = $parameter;
1618 $parameter_name =~ s/\[.*//;
1619
Randy Dunlap3c308792007-05-08 00:24:39 -07001620 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 $type = $args{'parametertypes'}{$parameter};
1622 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1623 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001624 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001626 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001627 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 } else {
1629 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001630 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 }
1632 print "\n.br\n";
1633 }
1634 print "};\n.br\n";
1635
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001636 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 foreach $parameter (@{$args{'parameterlist'}}) {
1638 ($parameter =~ /^#/) && next;
1639
1640 my $parameter_name = $parameter;
1641 $parameter_name =~ s/\[.*//;
1642
Randy Dunlap3c308792007-05-08 00:24:39 -07001643 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001644 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 output_highlight($args{'parameterdescs'}{$parameter_name});
1646 }
1647 foreach $section (@{$args{'sectionlist'}}) {
1648 print ".SH \"$section\"\n";
1649 output_highlight($args{'sections'}{$section});
1650 }
1651}
1652
1653##
1654# output typedef in man
1655sub output_typedef_man(%) {
1656 my %args = %{$_[0]};
1657 my ($parameter, $section);
1658
1659 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1660
1661 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001662 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663
1664 foreach $section (@{$args{'sectionlist'}}) {
1665 print ".SH \"$section\"\n";
1666 output_highlight($args{'sections'}{$section});
1667 }
1668}
1669
Johannes Bergb112e0f2007-10-24 15:08:48 -07001670sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 my %args = %{$_[0]};
1672 my ($parameter, $section);
1673 my $count;
1674
1675 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1676
1677 foreach $section (@{$args{'sectionlist'}}) {
1678 print ".SH \"$section\"\n";
1679 output_highlight($args{'sections'}{$section});
1680 }
1681}
1682
1683##
1684# output in text
1685sub output_function_text(%) {
1686 my %args = %{$_[0]};
1687 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001688 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
Randy Dunlapf47634b2006-07-01 04:36:36 -07001690 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001691 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001692
1693 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001694 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001695 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001696 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001697 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001698 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001700
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 my $count = 0;
1702 foreach my $parameter (@{$args{'parameterlist'}}) {
1703 $type = $args{'parametertypes'}{$parameter};
1704 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1705 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001706 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001708 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 }
1710 if ($count != $#{$args{'parameterlist'}}) {
1711 $count++;
1712 print ",\n";
1713 print " " x length($start);
1714 } else {
1715 print ");\n\n";
1716 }
1717 }
1718
1719 print "Arguments:\n\n";
1720 foreach $parameter (@{$args{'parameterlist'}}) {
1721 my $parameter_name = $parameter;
1722 $parameter_name =~ s/\[.*//;
1723
Randy Dunlapb9d973282009-06-09 08:50:38 -07001724 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 }
1726 output_section_text(@_);
1727}
1728
1729#output sections in text
1730sub output_section_text(%) {
1731 my %args = %{$_[0]};
1732 my $section;
1733
1734 print "\n";
1735 foreach $section (@{$args{'sectionlist'}}) {
1736 print "$section:\n\n";
1737 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001738 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 print "\n\n";
1740}
1741
1742# output enum in text
1743sub output_enum_text(%) {
1744 my %args = %{$_[0]};
1745 my ($parameter);
1746 my $count;
1747 print "Enum:\n\n";
1748
Randy Dunlapb9d973282009-06-09 08:50:38 -07001749 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1750 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 $count = 0;
1752 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001753 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 if ($count != $#{$args{'parameterlist'}}) {
1755 $count++;
1756 print ",";
1757 }
1758 print "\n";
1759 }
1760 print "};\n\n";
1761
1762 print "Constants:\n\n";
1763 foreach $parameter (@{$args{'parameterlist'}}) {
1764 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001765 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 }
1767
1768 output_section_text(@_);
1769}
1770
1771# output typedef in text
1772sub output_typedef_text(%) {
1773 my %args = %{$_[0]};
1774 my ($parameter);
1775 my $count;
1776 print "Typedef:\n\n";
1777
Randy Dunlapb9d973282009-06-09 08:50:38 -07001778 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 output_section_text(@_);
1780}
1781
1782# output struct as text
1783sub output_struct_text(%) {
1784 my %args = %{$_[0]};
1785 my ($parameter);
1786
Randy Dunlapb9d973282009-06-09 08:50:38 -07001787 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1788 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 foreach $parameter (@{$args{'parameterlist'}}) {
1790 if ($parameter =~ /^#/) {
1791 print "$parameter\n";
1792 next;
1793 }
1794
1795 my $parameter_name = $parameter;
1796 $parameter_name =~ s/\[.*//;
1797
Randy Dunlap3c308792007-05-08 00:24:39 -07001798 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 $type = $args{'parametertypes'}{$parameter};
1800 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1801 # pointer-to-function
1802 print "\t$1 $parameter) ($2);\n";
1803 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001804 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 print "\t$1 $parameter$2;\n";
1806 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001807 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 }
1809 }
1810 print "};\n\n";
1811
1812 print "Members:\n\n";
1813 foreach $parameter (@{$args{'parameterlist'}}) {
1814 ($parameter =~ /^#/) && next;
1815
1816 my $parameter_name = $parameter;
1817 $parameter_name =~ s/\[.*//;
1818
Randy Dunlap3c308792007-05-08 00:24:39 -07001819 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001821 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 }
1823 print "\n";
1824 output_section_text(@_);
1825}
1826
Johannes Bergb112e0f2007-10-24 15:08:48 -07001827sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 my %args = %{$_[0]};
1829 my ($parameter, $section);
1830
1831 foreach $section (@{$args{'sectionlist'}}) {
1832 print " $section:\n";
1833 print " -> ";
1834 output_highlight($args{'sections'}{$section});
1835 }
1836}
1837
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001838##
1839# output in restructured text
1840#
1841
1842#
1843# This could use some work; it's used to output the DOC: sections, and
1844# starts by putting out the name of the doc section itself, but that tends
1845# to duplicate a header already in the template file.
1846#
1847sub output_blockhead_rst(%) {
1848 my %args = %{$_[0]};
1849 my ($parameter, $section);
1850
1851 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001852 if ($output_selection != OUTPUT_INCLUDE) {
1853 print "**$section**\n\n";
1854 }
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001855 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001856 output_highlight_rst($args{'sections'}{$section});
1857 print "\n";
1858 }
1859}
1860
1861sub output_highlight_rst {
1862 my $contents = join "\n",@_;
1863 my $line;
1864
1865 # undo the evil effects of xml_escape() earlier
1866 $contents = xml_unescape($contents);
1867
1868 eval $dohighlight;
1869 die $@ if $@;
1870
1871 foreach $line (split "\n", $contents) {
Jani Nikula830066a2016-05-26 22:04:33 +03001872 print $lineprefix . $line . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001873 }
1874}
1875
1876sub output_function_rst(%) {
1877 my %args = %{$_[0]};
1878 my ($parameter, $section);
Jani Nikulac099ff62016-05-26 17:18:17 +03001879 my $oldprefix = $lineprefix;
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001880 my $start = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001881
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001882 if ($args{'typedef'}) {
1883 print ".. c:type:: ". $args{'function'} . "\n\n";
1884 print_lineno($declaration_start_line);
1885 print " **Typedef**: ";
1886 $lineprefix = "";
1887 output_highlight_rst($args{'purpose'});
1888 $start = "\n\n**Syntax**\n\n ``";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001889 } else {
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001890 print ".. c:function:: ";
1891 }
1892 if ($args{'functiontype'} ne "") {
1893 $start .= $args{'functiontype'} . " " . $args{'function'} . " (";
1894 } else {
1895 $start .= $args{'function'} . " (";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001896 }
1897 print $start;
1898
1899 my $count = 0;
1900 foreach my $parameter (@{$args{'parameterlist'}}) {
1901 if ($count ne 0) {
1902 print ", ";
1903 }
1904 $count++;
1905 $type = $args{'parametertypes'}{$parameter};
Mauro Carvalho Chehaba88b1672016-07-22 11:46:36 -03001906
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001907 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1908 # pointer-to-function
1909 print $1 . $parameter . ") (" . $2;
1910 } else {
1911 print $type . " " . $parameter;
1912 }
1913 }
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001914 if ($args{'typedef'}) {
1915 print ");``\n\n";
1916 } else {
1917 print ")\n\n";
1918 print_lineno($declaration_start_line);
1919 $lineprefix = " ";
1920 output_highlight_rst($args{'purpose'});
1921 print "\n";
1922 }
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001923
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001924 print "**Parameters**\n\n";
1925 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001926 foreach $parameter (@{$args{'parameterlist'}}) {
1927 my $parameter_name = $parameter;
Gabriel Krisman Bertaziada5f442017-01-09 18:11:57 -02001928 $parameter_name =~ s/\[.*//;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001929 $type = $args{'parametertypes'}{$parameter};
1930
1931 if ($type ne "") {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001932 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001933 } else {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001934 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001935 }
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001936
1937 print_lineno($parameterdesc_start_lines{$parameter_name});
1938
Jani Nikula5e64fa92016-05-19 20:32:48 +03001939 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1940 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001941 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001942 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001943 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001944 }
1945 print "\n";
1946 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001947
1948 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001949 output_section_rst(@_);
1950}
1951
1952sub output_section_rst(%) {
1953 my %args = %{$_[0]};
1954 my $section;
1955 my $oldprefix = $lineprefix;
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001956 $lineprefix = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001957
1958 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001959 print "**$section**\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001960 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001961 output_highlight_rst($args{'sections'}{$section});
1962 print "\n";
1963 }
1964 print "\n";
1965 $lineprefix = $oldprefix;
1966}
1967
1968sub output_enum_rst(%) {
1969 my %args = %{$_[0]};
1970 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001971 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001972 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001973 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001974
1975 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001976 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001977 $lineprefix = " ";
1978 output_highlight_rst($args{'purpose'});
1979 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001980
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001981 print "**Constants**\n\n";
1982 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001983 foreach $parameter (@{$args{'parameterlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001984 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001985 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1986 output_highlight_rst($args{'parameterdescs'}{$parameter});
1987 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001988 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001989 }
1990 print "\n";
1991 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001992
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001993 $lineprefix = $oldprefix;
1994 output_section_rst(@_);
1995}
1996
1997sub output_typedef_rst(%) {
1998 my %args = %{$_[0]};
1999 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03002000 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002001 my $name = "typedef " . $args{'typedef'};
2002
Jani Nikula62850972016-05-12 16:15:38 +03002003 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002004 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03002005 $lineprefix = " ";
2006 output_highlight_rst($args{'purpose'});
2007 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002008
Jani Nikulac099ff62016-05-26 17:18:17 +03002009 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002010 output_section_rst(@_);
2011}
2012
2013sub output_struct_rst(%) {
2014 my %args = %{$_[0]};
2015 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03002016 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002017 my $name = $args{'type'} . " " . $args{'struct'};
2018
Jani Nikula62850972016-05-12 16:15:38 +03002019 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002020 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03002021 $lineprefix = " ";
2022 output_highlight_rst($args{'purpose'});
2023 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002024
Jani Nikulaecbcfba2016-05-26 18:30:27 +03002025 print "**Definition**\n\n";
2026 print "::\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002027 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
2028 foreach $parameter (@{$args{'parameterlist'}}) {
2029 if ($parameter =~ /^#/) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03002030 print " " . "$parameter\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002031 next;
2032 }
2033
2034 my $parameter_name = $parameter;
2035 $parameter_name =~ s/\[.*//;
2036
2037 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
2038 $type = $args{'parametertypes'}{$parameter};
2039 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
2040 # pointer-to-function
2041 print " $1 $parameter) ($2);\n";
2042 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
2043 # bitfield
2044 print " $1 $parameter$2;\n";
2045 } else {
2046 print " " . $type . " " . $parameter . ";\n";
2047 }
2048 }
2049 print " };\n\n";
2050
Jani Nikulaecbcfba2016-05-26 18:30:27 +03002051 print "**Members**\n\n";
2052 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002053 foreach $parameter (@{$args{'parameterlist'}}) {
2054 ($parameter =~ /^#/) && next;
2055
2056 my $parameter_name = $parameter;
2057 $parameter_name =~ s/\[.*//;
2058
2059 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
2060 $type = $args{'parametertypes'}{$parameter};
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002061 print_lineno($parameterdesc_start_lines{$parameter_name});
Mauro Carvalho Chehab6d232c82016-08-22 22:02:57 -03002062 print "``" . $parameter . "``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002063 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002064 print "\n";
2065 }
2066 print "\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03002067
2068 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002069 output_section_rst(@_);
2070}
2071
2072
Johannes Bergeda603f2010-09-11 15:55:22 -07002073## list mode output functions
2074
2075sub output_function_list(%) {
2076 my %args = %{$_[0]};
2077
2078 print $args{'function'} . "\n";
2079}
2080
2081# output enum in list
2082sub output_enum_list(%) {
2083 my %args = %{$_[0]};
2084 print $args{'enum'} . "\n";
2085}
2086
2087# output typedef in list
2088sub output_typedef_list(%) {
2089 my %args = %{$_[0]};
2090 print $args{'typedef'} . "\n";
2091}
2092
2093# output struct as list
2094sub output_struct_list(%) {
2095 my %args = %{$_[0]};
2096
2097 print $args{'struct'} . "\n";
2098}
2099
2100sub output_blockhead_list(%) {
2101 my %args = %{$_[0]};
2102 my ($parameter, $section);
2103
2104 foreach $section (@{$args{'sectionlist'}}) {
2105 print "DOC: $section\n";
2106 }
2107}
2108
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109##
Randy Dunlap27205742006-10-11 01:22:12 -07002110# generic output function for all types (function, struct/union, typedef, enum);
2111# calls the generated, variable output_ function name based on
2112# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113sub output_declaration {
2114 no strict 'refs';
2115 my $name = shift;
2116 my $functype = shift;
2117 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002118 if (($output_selection == OUTPUT_ALL) ||
2119 (($output_selection == OUTPUT_INCLUDE ||
2120 $output_selection == OUTPUT_EXPORTED) &&
2121 defined($function_table{$name})) ||
2122 (($output_selection == OUTPUT_EXCLUDE ||
2123 $output_selection == OUTPUT_INTERNAL) &&
2124 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002126 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 $section_counter++;
2128 }
2129}
2130
2131##
Randy Dunlap27205742006-10-11 01:22:12 -07002132# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002133sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002135 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 &$func(@_);
2137 $section_counter++;
2138}
2139
2140##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002141# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142# invokes the right handler. NOT called for functions.
2143sub dump_declaration($$) {
2144 no strict 'refs';
2145 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002146 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 &$func(@_);
2148}
2149
2150sub dump_union($$) {
2151 dump_struct(@_);
2152}
2153
2154sub dump_struct($$) {
2155 my $x = shift;
2156 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002157 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002159 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2160 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002161 $declaration_name = $2;
2162 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
2164 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002165 $members =~ s/({.*})//g;
2166 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
Martin Waitzaeec46b2005-11-13 16:08:13 -08002168 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002169 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2170 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002171 # strip comments:
2172 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002173 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002174 # strip kmemcheck_bitfield_{begin,end}.*;
2175 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002176 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002177 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002178 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002179 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002180 # replace DECLARE_BITMAP
2181 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002182
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002184 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185
2186 output_declaration($declaration_name,
2187 'struct',
2188 {'struct' => $declaration_name,
2189 'module' => $modulename,
2190 'parameterlist' => \@parameterlist,
2191 'parameterdescs' => \%parameterdescs,
2192 'parametertypes' => \%parametertypes,
2193 'sectionlist' => \@sectionlist,
2194 'sections' => \%sections,
2195 'purpose' => $declaration_purpose,
2196 'type' => $decl_type
2197 });
2198 }
2199 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002200 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 ++$errors;
2202 }
2203}
2204
2205sub dump_enum($$) {
2206 my $x = shift;
2207 my $file = shift;
2208
Martin Waitzaeec46b2005-11-13 16:08:13 -08002209 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002210 # strip #define macros inside enums
2211 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002212
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002214 $declaration_name = $1;
2215 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
2217 foreach my $arg (split ',', $members) {
2218 $arg =~ s/^\s*(\w+).*/$1/;
2219 push @parameterlist, $arg;
2220 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002221 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002222 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 "not described in enum '$declaration_name'\n";
2224 }
2225
2226 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002227
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 output_declaration($declaration_name,
2229 'enum',
2230 {'enum' => $declaration_name,
2231 'module' => $modulename,
2232 'parameterlist' => \@parameterlist,
2233 'parameterdescs' => \%parameterdescs,
2234 'sectionlist' => \@sectionlist,
2235 'sections' => \%sections,
2236 'purpose' => $declaration_purpose
2237 });
2238 }
2239 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002240 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 ++$errors;
2242 }
2243}
2244
2245sub dump_typedef($$) {
2246 my $x = shift;
2247 my $file = shift;
2248
Martin Waitzaeec46b2005-11-13 16:08:13 -08002249 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002250
2251 # Parse function prototypes
Mauro Carvalho Chehabd37c43c2016-08-30 20:20:57 -03002252 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ ||
2253 $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) {
2254
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002255 # Function typedefs
2256 $return_type = $1;
2257 $declaration_name = $2;
2258 my $args = $3;
2259
2260 create_parameterlist($args, ',', $file);
2261
2262 output_declaration($declaration_name,
2263 'function',
2264 {'function' => $declaration_name,
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03002265 'typedef' => 1,
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002266 'module' => $modulename,
2267 'functiontype' => $return_type,
2268 'parameterlist' => \@parameterlist,
2269 'parameterdescs' => \%parameterdescs,
2270 'parametertypes' => \%parametertypes,
2271 'sectionlist' => \@sectionlist,
2272 'sections' => \%sections,
2273 'purpose' => $declaration_purpose
2274 });
2275 return;
2276 }
2277
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002279 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 $x =~ s/\[*.\]\s*;$/;/;
2281 }
2282
2283 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002284 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285
2286 output_declaration($declaration_name,
2287 'typedef',
2288 {'typedef' => $declaration_name,
2289 'module' => $modulename,
2290 'sectionlist' => \@sectionlist,
2291 'sections' => \%sections,
2292 'purpose' => $declaration_purpose
2293 });
2294 }
2295 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002296 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 ++$errors;
2298 }
2299}
2300
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002301sub save_struct_actual($) {
2302 my $actual = shift;
2303
2304 # strip all spaces from the actual param so that it looks like one string item
2305 $actual =~ s/\s*//g;
2306 $struct_actual = $struct_actual . $actual . " ";
2307}
2308
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309sub create_parameterlist($$$) {
2310 my $args = shift;
2311 my $splitter = shift;
2312 my $file = shift;
2313 my $type;
2314 my $param;
2315
Martin Waitza6d3fe72006-01-09 20:53:55 -08002316 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002318 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002320
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 foreach my $arg (split($splitter, $args)) {
2322 # strip comments
2323 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002324 # strip leading/trailing spaces
2325 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 $arg =~ s/\s*$//;
2327 $arg =~ s/\s+/ /;
2328
2329 if ($arg =~ /^#/) {
2330 # Treat preprocessor directive as a typeless variable just to fill
2331 # corresponding data structures "correctly". Catch it later in
2332 # output_* subs.
2333 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002334 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 # pointer-to-function
2336 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002337 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 $param = $1;
2339 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002340 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002341 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002343 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 $arg =~ s/\s*:\s*/:/g;
2345 $arg =~ s/\s*\[/\[/g;
2346
2347 my @args = split('\s*,\s*', $arg);
2348 if ($args[0] =~ m/\*/) {
2349 $args[0] =~ s/(\*+)\s*/ $1/;
2350 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002351
2352 my @first_arg;
2353 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2354 shift @args;
2355 push(@first_arg, split('\s+', $1));
2356 push(@first_arg, $2);
2357 } else {
2358 @first_arg = split('\s+', shift @args);
2359 }
2360
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 unshift(@args, pop @first_arg);
2362 $type = join " ", @first_arg;
2363
2364 foreach $param (@args) {
2365 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002366 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 push_parameter($2, "$type $1", $file);
2368 }
2369 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002370 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002371 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002372 push_parameter($1, "$type:$2", $file)
2373 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 }
2375 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002376 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 push_parameter($param, $type, $file);
2378 }
2379 }
2380 }
2381 }
2382}
2383
2384sub push_parameter($$$) {
2385 my $param = shift;
2386 my $type = shift;
2387 my $file = shift;
2388
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002389 if (($anon_struct_union == 1) && ($type eq "") &&
2390 ($param eq "}")) {
2391 return; # ignore the ending }; from anon. struct/union
2392 }
2393
2394 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 my $param_name = $param;
2396 $param_name =~ s/\[.*//;
2397
Martin Waitza6d3fe72006-01-09 20:53:55 -08002398 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 {
Silvio Frickec950a172016-10-28 10:14:08 +02002400 if (!$param =~ /\w\.\.\.$/) {
2401 # handles unnamed variable parameters
2402 $param = "...";
2403 }
Randy Dunlapced69092008-12-01 13:14:03 -08002404 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2405 $parameterdescs{$param} = "variable arguments";
2406 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 }
2408 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2409 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 $param="void";
2411 $parameterdescs{void} = "no arguments";
2412 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002413 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2414 # handle unnamed (anonymous) union or struct:
2415 {
2416 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002417 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002418 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002419 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002420 }
2421
Martin Waitza6d3fe72006-01-09 20:53:55 -08002422 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002423 # (but ignore ones starting with # as these are not parameters
2424 # but inline preprocessor statements);
2425 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002426 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002427 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2428
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 $parameterdescs{$param_name} = $undescribed;
2430
2431 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002432 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 "or member '$param' not " .
2434 "described in '$declaration_name'\n";
2435 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002436 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002437 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002438 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002439 }
2440 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002442 $param = xml_escape($param);
2443
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002444 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002445 # on @parameterlist;
2446 # this fixes a problem where check_sections() cannot find
2447 # a parameter like "addr[6 + 2]" because it actually appears
2448 # as "addr[6", "+", "2]" on the parameter list;
2449 # but it's better to maintain the param string unchanged for output,
2450 # so just weaken the string compare in check_sections() to ignore
2451 # "[blah" in a parameter string;
2452 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 push @parameterlist, $param;
Paolo Bonzini02a4f4f2017-01-02 16:22:23 +01002454 $type =~ s/\s\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 $parametertypes{$param} = $type;
2456}
2457
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002458sub check_sections($$$$$$) {
2459 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2460 my @sects = split ' ', $sectcheck;
2461 my @prms = split ' ', $prmscheck;
2462 my $err;
2463 my ($px, $sx);
2464 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2465
2466 foreach $sx (0 .. $#sects) {
2467 $err = 1;
2468 foreach $px (0 .. $#prms) {
2469 $prm_clean = $prms[$px];
2470 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002471 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002472 # ignore array size in a parameter string;
2473 # however, the original param string may contain
2474 # spaces, e.g.: addr[6 + 2]
2475 # and this appears in @prms as "addr[6" since the
2476 # parameter list is split at spaces;
2477 # hence just ignore "[..." for the sections check;
2478 $prm_clean =~ s/\[.*//;
2479
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002480 ##$prm_clean =~ s/^\**//;
2481 if ($prm_clean eq $sects[$sx]) {
2482 $err = 0;
2483 last;
2484 }
2485 }
2486 if ($err) {
2487 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002488 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002489 "Excess function parameter " .
2490 "'$sects[$sx]' " .
2491 "description in '$decl_name'\n";
2492 ++$warnings;
2493 } else {
2494 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002495 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002496 "Excess struct/union/enum/typedef member " .
2497 "'$sects[$sx]' " .
2498 "description in '$decl_name'\n";
2499 ++$warnings;
2500 }
2501 }
2502 }
2503 }
2504}
2505
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002507# Checks the section describing the return value of a function.
2508sub check_return_section {
2509 my $file = shift;
2510 my $declaration_name = shift;
2511 my $return_type = shift;
2512
2513 # Ignore an empty return type (It's a macro)
2514 # Ignore functions with a "void" return type. (But don't ignore "void *")
2515 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2516 return;
2517 }
2518
2519 if (!defined($sections{$section_return}) ||
2520 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002521 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002522 "No description found for return value of " .
2523 "'$declaration_name'\n";
2524 ++$warnings;
2525 }
2526}
2527
2528##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529# takes a function prototype and the name of the current file being
2530# processed and spits out all the details stored in the global
2531# arrays/hashes.
2532sub dump_function($$) {
2533 my $prototype = shift;
2534 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002535 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536
2537 $prototype =~ s/^static +//;
2538 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002539 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 $prototype =~ s/^inline +//;
2541 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002542 $prototype =~ s/^__inline +//;
2543 $prototype =~ s/^__always_inline +//;
2544 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002545 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002546 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002547 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002548 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002549 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002550 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Paolo Bonzinib1aaa542017-01-02 16:22:24 +01002551 $prototype =~ s/__attribute__\s*\(\(
2552 (?:
2553 [\w\s]++ # attribute name
2554 (?:\([^)]*+\))? # attribute arguments
2555 \s*+,? # optional comma at the end
2556 )+
2557 \)\)\s+//x;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558
2559 # Yes, this truly is vile. We are looking for:
2560 # 1. Return type (may be nothing if we're looking at a macro)
2561 # 2. Function name
2562 # 3. Function parameters.
2563 #
2564 # All the while we have to watch out for function pointer parameters
2565 # (which IIRC is what the two sections are for), C types (these
2566 # regexps don't even start to express all the possibilities), and
2567 # so on.
2568 #
2569 # If you mess with these regexps, it's a good idea to check that
2570 # the following functions' documentation still comes out right:
2571 # - parport_register_device (function pointer parameters)
2572 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002573 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002575 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2576 # This is an object-like macro, it has no return type and no parameter
2577 # list.
2578 # Function-like macros are not allowed to have spaces between
2579 # declaration_name and opening parenthesis (notice the \s+).
2580 $return_type = $1;
2581 $declaration_name = $2;
2582 $noret = 1;
2583 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08002585 $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002587 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08002589 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2591 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08002592 $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08002594 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08002596 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002597 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08002598 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2599 $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 $return_type = $1;
2601 $declaration_name = $2;
2602 my $args = $3;
2603
2604 create_parameterlist($args, ',', $file);
2605 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002606 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 return;
2608 }
2609
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002610 my $prms = join " ", @parameterlist;
2611 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2612
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002613 # This check emits a lot of warnings at the moment, because many
2614 # functions don't have a 'Return' doc section. So until the number
2615 # of warnings goes sufficiently down, the check is only performed in
2616 # verbose mode.
2617 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002618 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002619 check_return_section($file, $declaration_name, $return_type);
2620 }
2621
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002622 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 'function',
2624 {'function' => $declaration_name,
2625 'module' => $modulename,
2626 'functiontype' => $return_type,
2627 'parameterlist' => \@parameterlist,
2628 'parameterdescs' => \%parameterdescs,
2629 'parametertypes' => \%parametertypes,
2630 'sectionlist' => \@sectionlist,
2631 'sections' => \%sections,
2632 'purpose' => $declaration_purpose
2633 });
2634}
2635
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636sub reset_state {
2637 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 %parameterdescs = ();
2639 %parametertypes = ();
2640 @parameterlist = ();
2641 %sections = ();
2642 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002643 $sectcheck = "";
2644 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002646
Jani Nikula48af6062016-05-26 14:56:05 +03002647 $state = STATE_NORMAL;
2648 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649}
2650
Jason Baron56afb0f2009-04-30 13:29:36 -04002651sub tracepoint_munge($) {
2652 my $file = shift;
2653 my $tracepointname = 0;
2654 my $tracepointargs = 0;
2655
Jason Baron3a9089f2009-12-01 12:18:49 -05002656 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002657 $tracepointname = $1;
2658 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002659 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2660 $tracepointname = $1;
2661 }
2662 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2663 $tracepointname = $2;
2664 }
2665 $tracepointname =~ s/^\s+//; #strip leading whitespace
2666 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002667 $tracepointargs = $1;
2668 }
2669 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002670 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002671 "$prototype\n";
2672 } else {
2673 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2674 }
2675}
2676
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002677sub syscall_munge() {
2678 my $void = 0;
2679
2680 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2681## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2682 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2683 $void = 1;
2684## $prototype = "long sys_$1(void)";
2685 }
2686
2687 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2688 if ($prototype =~ m/long (sys_.*?),/) {
2689 $prototype =~ s/,/\(/;
2690 } elsif ($void) {
2691 $prototype =~ s/\)/\(void\)/;
2692 }
2693
2694 # now delete all of the odd-number commas in $prototype
2695 # so that arg types & arg names don't have a comma between them
2696 my $count = 0;
2697 my $len = length($prototype);
2698 if ($void) {
2699 $len = 0; # skip the for-loop
2700 }
2701 for (my $ix = 0; $ix < $len; $ix++) {
2702 if (substr($prototype, $ix, 1) eq ',') {
2703 $count++;
2704 if ($count % 2 == 1) {
2705 substr($prototype, $ix, 1) = ' ';
2706 }
2707 }
2708 }
2709}
2710
Daniel Vetterb7afa922016-06-01 23:46:24 +02002711sub process_proto_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 my $x = shift;
2713 my $file = shift;
2714
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002715 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2716
Randy Dunlap890c78c2008-10-25 17:06:43 -07002717 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 # do nothing
2719 }
2720 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002721 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002723
Randy Dunlap890c78c2008-10-25 17:06:43 -07002724 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002725 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2727 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002728 if ($prototype =~ /SYSCALL_DEFINE/) {
2729 syscall_munge();
2730 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002731 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2732 $prototype =~ /DEFINE_SINGLE_EVENT/)
2733 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002734 tracepoint_munge($file);
2735 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002736 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 reset_state();
2738 }
2739}
2740
Daniel Vetterb7afa922016-06-01 23:46:24 +02002741sub process_proto_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 my $x = shift;
2743 my $file = shift;
2744
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2746 $x =~ s@^\s+@@gos; # strip leading spaces
2747 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002748 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2749
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 if ($x =~ /^#/) {
2751 # To distinguish preprocessor directive from regular declaration later.
2752 $x .= ";";
2753 }
2754
2755 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002756 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 $prototype .= $1 . $2;
2758 ($2 eq '{') && $brcount++;
2759 ($2 eq '}') && $brcount--;
2760 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002761 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002763 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 }
2765 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002766 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 $prototype .= $x;
2768 last;
2769 }
2770 }
2771}
2772
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002773# xml_escape: replace <, >, and & in the text stream;
2774#
2775# however, formatting controls that are generated internally/locally in the
2776# kernel-doc script are not escaped here; instead, they begin life like
2777# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2778# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2779# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780sub xml_escape($) {
2781 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002782 if (($output_mode eq "text") || ($output_mode eq "man")) {
2783 return $text;
2784 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 $text =~ s/\&/\\\\\\amp;/g;
2786 $text =~ s/\</\\\\\\lt;/g;
2787 $text =~ s/\>/\\\\\\gt;/g;
2788 return $text;
2789}
2790
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002791# xml_unescape: reverse the effects of xml_escape
2792sub xml_unescape($) {
2793 my $text = shift;
2794 if (($output_mode eq "text") || ($output_mode eq "man")) {
2795 return $text;
2796 }
2797 $text =~ s/\\\\\\amp;/\&/g;
2798 $text =~ s/\\\\\\lt;/</g;
2799 $text =~ s/\\\\\\gt;/>/g;
2800 return $text;
2801}
2802
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002803# convert local escape strings to html
2804# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2805sub local_unescape($) {
2806 my $text = shift;
2807 if (($output_mode eq "text") || ($output_mode eq "man")) {
2808 return $text;
2809 }
2810 $text =~ s/\\\\\\\\lt:/</g;
2811 $text =~ s/\\\\\\\\gt:/>/g;
2812 return $text;
2813}
2814
Jani Nikula1ad560e2016-06-07 10:53:39 +03002815sub map_filename($) {
2816 my $file;
2817 my ($orig_file) = @_;
2818
2819 if (defined($ENV{'SRCTREE'})) {
2820 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
2821 } else {
2822 $file = $orig_file;
2823 }
2824
2825 if (defined($source_map{$file})) {
2826 $file = $source_map{$file};
2827 }
2828
2829 return $file;
2830}
2831
Jani Nikula88c2b572016-06-07 11:00:52 +03002832sub process_export_file($) {
2833 my ($orig_file) = @_;
2834 my $file = map_filename($orig_file);
2835
2836 if (!open(IN,"<$file")) {
2837 print STDERR "Error: Cannot open file $file\n";
2838 ++$errors;
2839 return;
2840 }
2841
2842 while (<IN>) {
2843 if (/$export_symbol/) {
2844 $function_table{$2} = 1;
2845 }
2846 }
2847
2848 close(IN);
2849}
2850
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002852 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 my $identifier;
2854 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002855 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002856 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002858 my ($orig_file) = @_;
Jani Nikulab7886de2016-05-28 00:41:50 +03002859 my $leading_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860
Jani Nikula1ad560e2016-06-07 10:53:39 +03002861 $file = map_filename($orig_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862
2863 if (!open(IN,"<$file")) {
2864 print STDERR "Error: Cannot open file $file\n";
2865 ++$errors;
2866 return;
2867 }
2868
Ilya Dryomova9e73142010-02-26 13:05:47 -08002869 $. = 1;
2870
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 $section_counter = 0;
2872 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002873 while (s/\\\s*$//) {
2874 $_ .= <IN>;
2875 }
Jani Nikula48af6062016-05-26 14:56:05 +03002876 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002878 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002879 $in_doc_sect = 0;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002880 $declaration_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 }
Jani Nikula48af6062016-05-26 14:56:05 +03002882 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002884 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002886 $new_start_line = $. + 1;
2887
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 if ( $1 eq "" ) {
2889 $section = $section_intro;
2890 } else {
2891 $section = $1;
2892 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002893 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 elsif (/$doc_decl/o) {
2895 $identifier = $1;
2896 if (/\s*([\w\s]+?)\s*-/) {
2897 $identifier = $1;
2898 }
2899
Jani Nikula48af6062016-05-26 14:56:05 +03002900 $state = STATE_FIELD;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002901 # if there's no @param blocks need to set up default section
2902 # here
Jani Nikula2f4ad402016-05-30 11:21:06 +03002903 $contents = "";
2904 $section = $section_default;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002905 $new_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002907 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002908 $descr= $1;
2909 $descr =~ s/^\s*//;
2910 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002911 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002912 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002913 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 } else {
2915 $declaration_purpose = "";
2916 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002917
2918 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002919 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002920 print STDERR $_;
2921 ++$warnings;
2922 }
2923
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 if ($identifier =~ m/^struct/) {
2925 $decl_type = 'struct';
2926 } elsif ($identifier =~ m/^union/) {
2927 $decl_type = 'union';
2928 } elsif ($identifier =~ m/^enum/) {
2929 $decl_type = 'enum';
2930 } elsif ($identifier =~ m/^typedef/) {
2931 $decl_type = 'typedef';
2932 } else {
2933 $decl_type = 'function';
2934 }
2935
2936 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002937 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 }
2939 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002940 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 " - I thought it was a doc line\n";
2942 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002943 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 }
Jani Nikula48af6062016-05-26 14:56:05 +03002945 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Jani Nikulaf624ade2016-05-29 11:35:28 +03002946 if (/$doc_sect/i) { # case insensitive for supported section names
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 $newsection = $1;
2948 $newcontents = $2;
2949
Jani Nikulaf624ade2016-05-29 11:35:28 +03002950 # map the supported section names to the canonical names
2951 if ($newsection =~ m/^description$/i) {
2952 $newsection = $section_default;
2953 } elsif ($newsection =~ m/^context$/i) {
2954 $newsection = $section_context;
2955 } elsif ($newsection =~ m/^returns?$/i) {
2956 $newsection = $section_return;
2957 } elsif ($newsection =~ m/^\@return$/) {
2958 # special: @return is a section, not a param description
2959 $newsection = $section_return;
2960 }
2961
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002962 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002963 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002964 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002965 ++$warnings;
2966 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002967 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 $section = $section_default;
2969 }
2970
Randy Dunlap850622d2006-06-25 05:48:55 -07002971 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002972 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 $contents = $newcontents;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002974 $new_start_line = $.;
Jani Nikula0a726302016-05-28 14:50:20 +03002975 while ((substr($contents, 0, 1) eq " ") ||
2976 substr($contents, 0, 1) eq "\t") {
2977 $contents = substr($contents, 1);
2978 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 if ($contents ne "") {
2980 $contents .= "\n";
2981 }
2982 $section = $newsection;
Jani Nikulab7886de2016-05-28 00:41:50 +03002983 $leading_space = undef;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002985 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002986 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 $section = $section_default;
2988 $contents = "";
2989 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002990 # look for doc_com + <text> + doc_end:
2991 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002992 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002993 ++$warnings;
2994 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995
2996 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002997 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002999# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 } elsif (/$doc_content/) {
3001 # miguel-style comment kludge, look for blank lines after
3002 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07003003 if ($1 eq "") {
3004 if ($section =~ m/^@/ || $section eq $section_context) {
3005 dump_section($file, $section, xml_escape($contents));
3006 $section = $section_default;
3007 $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02003008 $new_start_line = $.;
Johannes Weiner64231332009-09-17 19:26:53 -07003009 } else {
3010 $contents .= "\n";
3011 }
3012 $in_purpose = 0;
3013 } elsif ($in_purpose == 1) {
3014 # Continued declaration purpose
3015 chomp($declaration_purpose);
3016 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07003017 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 } else {
Jani Nikulab7886de2016-05-28 00:41:50 +03003019 my $cont = $1;
3020 if ($section =~ m/^@/ || $section eq $section_context) {
3021 if (!defined $leading_space) {
3022 if ($cont =~ m/^(\s+)/) {
3023 $leading_space = $1;
3024 } else {
3025 $leading_space = "";
3026 }
3027 }
3028
3029 $cont =~ s/^$leading_space//;
3030 }
3031 $contents .= $cont . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 }
3033 } else {
3034 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07003035 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 ++$warnings;
3037 }
Jani Nikula48af6062016-05-26 14:56:05 +03003038 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003039 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03003040 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003041 $section = $1;
3042 $contents = $2;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02003043 $new_start_line = $.;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003044 if ($contents ne "") {
3045 while ((substr($contents, 0, 1) eq " ") ||
3046 substr($contents, 0, 1) eq "\t") {
3047 $contents = substr($contents, 1);
3048 }
Jani Nikulaa0b96c22016-05-26 22:04:06 +03003049 $contents .= "\n";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003050 }
Jani Nikula48af6062016-05-26 14:56:05 +03003051 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003052 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03003053 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003054 if (($contents ne "") && ($contents ne "\n")) {
3055 dump_section($file, $section, xml_escape($contents));
3056 $section = $section_default;
3057 $contents = "";
3058 }
Jani Nikula48af6062016-05-26 14:56:05 +03003059 $state = STATE_PROTO;
3060 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003061 # Regular text
3062 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03003063 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003064 $contents .= $1 . "\n";
Jani Nikula6450c892016-05-26 22:04:42 +03003065 # nuke leading blank lines
3066 if ($contents =~ /^\s*$/) {
3067 $contents = "";
3068 }
Jani Nikula48af6062016-05-26 14:56:05 +03003069 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
3070 $inline_doc_state = STATE_INLINE_ERROR;
Daniel Vettere7ca3112016-07-15 10:19:30 +02003071 print STDERR "${file}:$.: warning: ";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003072 print STDERR "Incorrect use of kernel-doc format: $_";
3073 ++$warnings;
3074 }
3075 }
Jani Nikula48af6062016-05-26 14:56:05 +03003076 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
Jani Nikula0c9aa202016-11-16 17:26:16 +02003077 if (/$doc_inline_oneline/) {
3078 $section = $1;
3079 $contents = $2;
3080 if ($contents ne "") {
3081 $contents .= "\n";
3082 dump_section($file, $section, xml_escape($contents));
3083 $section = $section_default;
3084 $contents = "";
3085 }
3086 } elsif (/$doc_inline_start/) {
Jani Nikula48af6062016-05-26 14:56:05 +03003087 $state = STATE_INLINE;
3088 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003089 } elsif ($decl_type eq 'function') {
Daniel Vetterb7afa922016-06-01 23:46:24 +02003090 process_proto_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 } else {
Daniel Vetterb7afa922016-06-01 23:46:24 +02003092 process_proto_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 }
Jani Nikula48af6062016-05-26 14:56:05 +03003094 } elsif ($state == STATE_DOCBLOCK) {
Daniel Vetterebff7f92016-06-01 23:46:23 +02003095 if (/$doc_end/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07003097 dump_doc_section($file, $section, xml_escape($contents));
Jani Nikula2f4ad402016-05-30 11:21:06 +03003098 $section = $section_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 $contents = "";
3100 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 %parameterdescs = ();
3102 %parametertypes = ();
3103 @parameterlist = ();
3104 %sections = ();
3105 @sectionlist = ();
3106 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03003107 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 }
3109 elsif (/$doc_content/)
3110 {
3111 if ( $1 eq "" )
3112 {
3113 $contents .= $blankline;
3114 }
3115 else
3116 {
3117 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08003118 }
Randy Dunlap3c308792007-05-08 00:24:39 -07003119 }
3120 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 }
3122 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07003123 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03003124 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08003125 print STDERR " Was looking for '$_'.\n" for keys %function_table;
3126 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 if ($output_mode eq "xml") {
3128 # The template wants at least one RefEntry here; make one.
3129 print "<refentry>\n";
3130 print " <refnamediv>\n";
3131 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003132 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 print " </refname>\n";
3134 print " <refpurpose>\n";
3135 print " Document generation inconsistency\n";
3136 print " </refpurpose>\n";
3137 print " </refnamediv>\n";
3138 print " <refsect1>\n";
3139 print " <title>\n";
3140 print " Oops\n";
3141 print " </title>\n";
3142 print " <warning>\n";
3143 print " <para>\n";
3144 print " The template for this document tried to insert\n";
3145 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003146 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 print " but none was found.\n";
3148 print " This dummy section is inserted to allow\n";
3149 print " generation to continue.\n";
3150 print " </para>\n";
3151 print " </warning>\n";
3152 print " </refsect1>\n";
3153 print "</refentry>\n";
3154 }
3155 }
3156}
Randy Dunlap8484baa2011-01-05 16:28:43 -08003157
3158
3159$kernelversion = get_kernel_version();
3160
3161# generate a sequence of code that will splice in highlighting information
3162# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02003163for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03003164 my $pattern = $highlights[$k][0];
3165 my $result = $highlights[$k][1];
3166# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
3167 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08003168}
3169
3170# Read the file that maps relative names to absolute names for
3171# separate source and object directories and for shadow trees.
3172if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3173 my ($relname, $absname);
3174 while(<SOURCE_MAP>) {
3175 chop();
3176 ($relname, $absname) = (split())[0..1];
3177 $relname =~ s:^/+::;
3178 $source_map{$relname} = $absname;
3179 }
3180 close(SOURCE_MAP);
3181}
3182
Jani Nikula88c2b572016-06-07 11:00:52 +03003183if ($output_selection == OUTPUT_EXPORTED ||
3184 $output_selection == OUTPUT_INTERNAL) {
Jani Nikulac9b2cfb2016-06-07 11:05:53 +03003185
3186 push(@export_file_list, @ARGV);
3187
Jani Nikula88c2b572016-06-07 11:00:52 +03003188 foreach (@export_file_list) {
3189 chomp;
3190 process_export_file($_);
3191 }
3192}
3193
Randy Dunlap8484baa2011-01-05 16:28:43 -08003194foreach (@ARGV) {
3195 chomp;
3196 process_file($_);
3197}
3198if ($verbose && $errors) {
3199 print STDERR "$errors errors\n";
3200}
3201if ($verbose && $warnings) {
3202 print STDERR "$warnings warnings\n";
3203}
3204
3205exit($errors);