blob: 67d051edd6151b8f3264840349cd4f985d815c1d [file] [log] [blame]
Kamil Rytarowskicb77f0d2017-05-07 23:25:26 +02001#!/usr/bin/env perl
Linus Torvalds1da177e2005-04-16 15:20:36 -07002
Kamil Rytarowskicb77f0d2017-05-07 23:25:26 +02003use warnings;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004use strict;
5
6## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ##
7## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ##
8## Copyright (C) 2001 Simon Huggins ##
Randy Dunlap70c95b02012-01-21 10:31:54 -08009## Copyright (C) 2005-2012 Randy Dunlap ##
Dan Luedtke1b40c192012-08-12 10:46:15 +020010## Copyright (C) 2012 Dan Luedtke ##
Linus Torvalds1da177e2005-04-16 15:20:36 -070011## ##
12## #define enhancements by Armin Kuster <akuster@mvista.com> ##
13## Copyright (c) 2000 MontaVista Software, Inc. ##
14## ##
15## This software falls under the GNU General Public License. ##
16## Please read the COPYING file for more information ##
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018# 18/01/2001 - Cleanups
19# Functions prototyped as foo(void) same as foo()
20# Stop eval'ing where we don't need to.
21# -- huggie@earth.li
22
23# 27/06/2001 - Allowed whitespace after initial "/**" and
24# allowed comments before function declarations.
25# -- Christian Kreibich <ck@whoop.org>
26
27# Still to do:
28# - add perldoc documentation
29# - Look more closely at some of the scarier bits :)
30
31# 26/05/2001 - Support for separate source and object trees.
32# Return error code.
33# Keith Owens <kaos@ocs.com.au>
34
35# 23/09/2001 - Added support for typedefs, structs, enums and unions
36# Support for Context section; can be terminated using empty line
37# Small fixes (like spaces vs. \s in regex)
38# -- Tim Jansen <tim@tjansen.de>
39
Dan Luedtke1b40c192012-08-12 10:46:15 +020040# 25/07/2012 - Added support for HTML5
41# -- Dan Luedtke <mail@danrl.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Jani Nikulafadc0b32016-05-12 16:15:36 +030043sub usage {
44 my $message = <<"EOF";
45Usage: $0 [OPTION ...] FILE ...
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Jani Nikulafadc0b32016-05-12 16:15:36 +030047Read C language source or header FILEs, extract embedded documentation comments,
48and print formatted documentation to standard output.
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Jani Nikulafadc0b32016-05-12 16:15:36 +030050The documentation comments are identified by "/**" opening comment mark. See
51Documentation/kernel-doc-nano-HOWTO.txt for the documentation comment syntax.
52
53Output format selection (mutually exclusive):
54 -docbook Output DocBook format.
55 -html Output HTML format.
56 -html5 Output HTML5 format.
57 -list Output symbol list format. This is for use by docproc.
58 -man Output troff manual page format. This is the default.
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +030059 -rst Output reStructuredText format.
Jani Nikulafadc0b32016-05-12 16:15:36 +030060 -text Output plain text format.
61
62Output selection (mutually exclusive):
Jani Nikula86ae2e32016-01-21 13:05:22 +020063 -export Only output documentation for symbols that have been
64 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
Jani Nikulac9b2cfb2016-06-07 11:05:53 +030065 in any input FILE or -export-file FILE.
Jani Nikula86ae2e32016-01-21 13:05:22 +020066 -internal Only output documentation for symbols that have NOT been
67 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
Jani Nikulac9b2cfb2016-06-07 11:05:53 +030068 in any input FILE or -export-file FILE.
Jani Nikulafadc0b32016-05-12 16:15:36 +030069 -function NAME Only output documentation for the given function(s)
70 or DOC: section title(s). All other functions and DOC:
71 sections are ignored. May be specified multiple times.
72 -nofunction NAME Do NOT output documentation for the given function(s);
73 only output documentation for the other functions and
74 DOC: sections. May be specified multiple times.
75
76Output selection modifiers:
77 -no-doc-sections Do not output DOC: sections.
Daniel Vetter0b0f5f292016-06-03 22:21:34 +020078 -enable-lineno Enable output of #define LINENO lines. Only works with
79 reStructuredText format.
Jani Nikula88c2b572016-06-07 11:00:52 +030080 -export-file FILE Specify an additional FILE in which to look for
81 EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with
82 -export or -internal. May be specified multiple times.
Jani Nikulafadc0b32016-05-12 16:15:36 +030083
84Other parameters:
85 -v Verbose output, more warnings and other information.
86 -h Print this help.
87
88EOF
89 print $message;
90 exit 1;
91}
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93#
94# format of comments.
95# In the following table, (...)? signifies optional structure.
96# (...)* signifies 0 or more structure elements
97# /**
98# * function_name(:)? (- short description)?
99# (* @parameterx: (description of parameter x)?)*
100# (* a blank line)?
101# * (Description:)? (Description of function)?
102# * (section header: (section description)? )*
103# (*)?*/
104#
105# So .. the trivial example would be:
106#
107# /**
108# * my_function
Randy Dunlapb9d973282009-06-09 08:50:38 -0700109# */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#
Randy Dunlap891dcd22007-02-10 01:45:53 -0800111# If the Description: header tag is omitted, then there must be a blank line
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112# after the last parameter specification.
113# e.g.
114# /**
115# * my_function - does my stuff
116# * @my_arg: its mine damnit
117# *
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800118# * Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119# */
120#
121# or, could also use:
122# /**
123# * my_function - does my stuff
124# * @my_arg: its mine damnit
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800125# * Description: Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126# */
127# etc.
128#
Randy Dunlapb9d973282009-06-09 08:50:38 -0700129# Besides functions you can also write documentation for structs, unions,
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800130# enums and typedefs. Instead of the function name you must write the name
131# of the declaration; the struct/union/enum/typedef must always precede
132# the name. Nesting of declarations is not supported.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133# Use the argument mechanism to document members or constants.
134# e.g.
135# /**
136# * struct my_struct - short description
137# * @a: first member
138# * @b: second member
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800139# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140# * Longer description
141# */
142# struct my_struct {
143# int a;
144# int b;
Martin Waitzaeec46b2005-11-13 16:08:13 -0800145# /* private: */
146# int c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147# };
148#
149# All descriptions can be multiline, except the short function description.
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800150#
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300151# For really longs structs, you can also describe arguments inside the
152# body of the struct.
153# eg.
154# /**
155# * struct my_struct - short description
156# * @a: first member
157# * @b: second member
158# *
159# * Longer description
160# */
161# struct my_struct {
162# int a;
163# int b;
164# /**
165# * @c: This is longer description of C
166# *
167# * You can use paragraphs to describe arguments
168# * using this method.
169# */
170# int c;
171# };
172#
173# This should be use only for struct/enum members.
174#
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800175# You can also add additional sections. When documenting kernel functions you
176# should document the "Context:" of the function, e.g. whether the functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177# can be called form interrupts. Unlike other sections you can end it with an
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800178# empty line.
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100179# A non-void function should have a "Return:" section describing the return
180# value(s).
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800181# Example-sections should contain the string EXAMPLE so that they are marked
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182# appropriately in DocBook.
183#
184# Example:
185# /**
186# * user_function - function that can only be called in user context
187# * @a: some argument
188# * Context: !in_interrupt()
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800189# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190# * Some description
191# * Example:
192# * user_function(22);
193# */
194# ...
195#
196#
197# All descriptive text is further processed, scanning for the following special
198# patterns, which are highlighted appropriately.
199#
200# 'funcname()' - function
201# '$ENVVAR' - environmental variable
202# '&struct_name' - name of a structure (up to two words including 'struct')
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100203# '&struct_name.member' - name of a structure member
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204# '@parameter' - name of a parameter
205# '%CONST' - name of a constant.
Mauro Carvalho Chehabb97f1932017-03-30 17:11:28 -0300206# '``LITERAL``' - literal string without any spaces on it.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Randy Dunlap8484baa2011-01-05 16:28:43 -0800208## init lots of data
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210my $errors = 0;
211my $warnings = 0;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -0700212my $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214# match expressions used to find embedded type information
Mauro Carvalho Chehabb97f1932017-03-30 17:11:28 -0300215my $type_constant = '\b``([^\`]+)``\b';
216my $type_constant2 = '\%([-_\w]+)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217my $type_func = '(\w+)\(\)';
Silvio Frickec950a172016-10-28 10:14:08 +0200218my $type_param = '\@(\w+(\.\.\.)?)';
Jonathan Corbet5219f182016-08-24 16:31:15 -0600219my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220my $type_env = '(\$\w+)';
Paolo Bonzinidf311752017-01-02 16:22:27 +0100221my $type_enum = '\&(enum\s*([_\w]+))';
222my $type_struct = '\&(struct\s*([_\w]+))';
223my $type_typedef = '\&(typedef\s*([_\w]+))';
224my $type_union = '\&(union\s*([_\w]+))';
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100225my $type_member = '\&([_\w]+)(\.|->)([_\w]+)';
Paolo Bonzinidf311752017-01-02 16:22:27 +0100226my $type_fallback = '\&([_\w]+)';
227my $type_enum_xml = '\&amp;(enum\s*([_\w]+))';
228my $type_struct_xml = '\&amp;(struct\s*([_\w]+))';
229my $type_typedef_xml = '\&amp;(typedef\s*([_\w]+))';
230my $type_union_xml = '\&amp;(union\s*([_\w]+))';
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100231my $type_member_xml = '\&amp;([_\w]+)(\.|-\&gt;)([_\w]+)';
Paolo Bonzinidf311752017-01-02 16:22:27 +0100232my $type_fallback_xml = '\&amp([_\w]+)';
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300233my $type_member_func = $type_member . '\(\)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235# Output conversion substitutions.
236# One for each output format
237
238# these work fairly well
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300239my @highlights_html = (
240 [$type_constant, "<i>\$1</i>"],
Mauro Carvalho Chehabb97f1932017-03-30 17:11:28 -0300241 [$type_constant2, "<i>\$1</i>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300242 [$type_func, "<b>\$1</b>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100243 [$type_enum_xml, "<i>\$1</i>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300244 [$type_struct_xml, "<i>\$1</i>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100245 [$type_typedef_xml, "<i>\$1</i>"],
246 [$type_union_xml, "<i>\$1</i>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300247 [$type_env, "<b><i>\$1</i></b>"],
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100248 [$type_param, "<tt><b>\$1</b></tt>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100249 [$type_member_xml, "<tt><i>\$1</i>\$2\$3</tt>"],
250 [$type_fallback_xml, "<i>\$1</i>"]
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300251 );
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700252my $local_lt = "\\\\\\\\lt:";
253my $local_gt = "\\\\\\\\gt:";
254my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Dan Luedtke1b40c192012-08-12 10:46:15 +0200256# html version 5
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300257my @highlights_html5 = (
258 [$type_constant, "<span class=\"const\">\$1</span>"],
Mauro Carvalho Chehabb97f1932017-03-30 17:11:28 -0300259 [$type_constant2, "<span class=\"const\">\$1</span>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300260 [$type_func, "<span class=\"func\">\$1</span>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100261 [$type_enum_xml, "<span class=\"enum\">\$1</span>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300262 [$type_struct_xml, "<span class=\"struct\">\$1</span>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100263 [$type_typedef_xml, "<span class=\"typedef\">\$1</span>"],
264 [$type_union_xml, "<span class=\"union\">\$1</span>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300265 [$type_env, "<span class=\"env\">\$1</span>"],
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100266 [$type_param, "<span class=\"param\">\$1</span>]"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100267 [$type_member_xml, "<span class=\"literal\"><span class=\"struct\">\$1</span>\$2<span class=\"member\">\$3</span></span>"],
268 [$type_fallback_xml, "<span class=\"struct\">\$1</span>"]
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300269 );
Dan Luedtke1b40c192012-08-12 10:46:15 +0200270my $blankline_html5 = $local_lt . "br /" . $local_gt;
271
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272# XML, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300273my @highlights_xml = (
274 ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
275 [$type_constant, "<constant>\$1</constant>"],
Mauro Carvalho Chehabb97f1932017-03-30 17:11:28 -0300276 [$type_constant2, "<constant>\$1</constant>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100277 [$type_enum_xml, "<type>\$1</type>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300278 [$type_struct_xml, "<structname>\$1</structname>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100279 [$type_typedef_xml, "<type>\$1</type>"],
280 [$type_union_xml, "<structname>\$1</structname>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300281 [$type_param, "<parameter>\$1</parameter>"],
282 [$type_func, "<function>\$1</function>"],
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100283 [$type_env, "<envar>\$1</envar>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100284 [$type_member_xml, "<literal><structname>\$1</structname>\$2<structfield>\$3</structfield></literal>"],
285 [$type_fallback_xml, "<structname>\$1</structname>"]
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300286 );
Johannes Berg5c98fc02007-10-24 15:08:48 -0700287my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289# gnome, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300290my @highlights_gnome = (
291 [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
Mauro Carvalho Chehabb97f1932017-03-30 17:11:28 -0300292 [$type_constant2, "<replaceable class=\"option\">\$1</replaceable>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300293 [$type_func, "<function>\$1</function>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100294 [$type_enum, "<type>\$1</type>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300295 [$type_struct, "<structname>\$1</structname>"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100296 [$type_typedef, "<type>\$1</type>"],
297 [$type_union, "<structname>\$1</structname>"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300298 [$type_env, "<envar>\$1</envar>"],
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100299 [$type_param, "<parameter>\$1</parameter>" ],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100300 [$type_member, "<literal><structname>\$1</structname>\$2<structfield>\$3</structfield></literal>"],
301 [$type_fallback, "<structname>\$1</structname>"]
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300302 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303my $blankline_gnome = "</para><para>\n";
304
305# these are pretty rough
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300306my @highlights_man = (
307 [$type_constant, "\$1"],
Mauro Carvalho Chehabb97f1932017-03-30 17:11:28 -0300308 [$type_constant2, "\$1"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300309 [$type_func, "\\\\fB\$1\\\\fP"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100310 [$type_enum, "\\\\fI\$1\\\\fP"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300311 [$type_struct, "\\\\fI\$1\\\\fP"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100312 [$type_typedef, "\\\\fI\$1\\\\fP"],
313 [$type_union, "\\\\fI\$1\\\\fP"],
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100314 [$type_param, "\\\\fI\$1\\\\fP"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100315 [$type_member, "\\\\fI\$1\$2\$3\\\\fP"],
316 [$type_fallback, "\\\\fI\$1\\\\fP"]
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300317 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318my $blankline_man = "";
319
320# text-mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300321my @highlights_text = (
322 [$type_constant, "\$1"],
Mauro Carvalho Chehabb97f1932017-03-30 17:11:28 -0300323 [$type_constant2, "\$1"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300324 [$type_func, "\$1"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100325 [$type_enum, "\$1"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300326 [$type_struct, "\$1"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100327 [$type_typedef, "\$1"],
328 [$type_union, "\$1"],
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100329 [$type_param, "\$1"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100330 [$type_member, "\$1\$2\$3"],
331 [$type_fallback, "\$1"]
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300332 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333my $blankline_text = "";
334
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300335# rst-mode
336my @highlights_rst = (
337 [$type_constant, "``\$1``"],
Mauro Carvalho Chehabb97f1932017-03-30 17:11:28 -0300338 [$type_constant2, "``\$1``"],
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300339 # Note: need to escape () to avoid func matching later
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100340 [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"],
341 [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"],
Jonathan Corbet5219f182016-08-24 16:31:15 -0600342 [$type_fp_param, "**\$1\\\\(\\\\)**"],
Jani Nikulaa19bce62016-05-26 11:28:16 +0300343 [$type_func, "\\:c\\:func\\:`\$1()`"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100344 [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"],
345 [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"],
346 [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"],
347 [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"],
Jani Nikulaa7291e72016-05-26 13:57:06 +0300348 # in rst this can refer to any type
Paolo Bonzinidf311752017-01-02 16:22:27 +0100349 [$type_fallback, "\\:c\\:type\\:`\$1`"],
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300350 [$type_param, "**\$1**"]
351 );
352my $blankline_rst = "\n";
353
Johannes Bergeda603f2010-09-11 15:55:22 -0700354# list mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300355my @highlights_list = (
356 [$type_constant, "\$1"],
Mauro Carvalho Chehabb97f1932017-03-30 17:11:28 -0300357 [$type_constant2, "\$1"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300358 [$type_func, "\$1"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100359 [$type_enum, "\$1"],
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300360 [$type_struct, "\$1"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100361 [$type_typedef, "\$1"],
362 [$type_union, "\$1"],
Paolo Bonzini5267dd32017-01-02 16:22:26 +0100363 [$type_param, "\$1"],
Paolo Bonzinidf311752017-01-02 16:22:27 +0100364 [$type_member, "\$1"],
365 [$type_fallback, "\$1"]
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300366 );
Johannes Bergeda603f2010-09-11 15:55:22 -0700367my $blankline_list = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369# read arguments
Randy Dunlapb9d973282009-06-09 08:50:38 -0700370if ($#ARGV == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 usage();
372}
373
Randy Dunlap8484baa2011-01-05 16:28:43 -0800374my $kernelversion;
375my $dohighlight = "";
376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377my $verbose = 0;
378my $output_mode = "man";
Daniel Santose314ba32012-10-04 17:15:08 -0700379my $output_preformatted = 0;
Johannes Berg4b445952007-10-24 15:08:48 -0700380my $no_doc_sections = 0;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200381my $enable_lineno = 0;
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300382my @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383my $blankline = $blankline_man;
384my $modulename = "Kernel API";
Jani Nikulab6c3f452016-05-29 22:19:35 +0300385
386use constant {
387 OUTPUT_ALL => 0, # output all symbols and doc sections
388 OUTPUT_INCLUDE => 1, # output only specified symbols
389 OUTPUT_EXCLUDE => 2, # output everything except specified symbols
390 OUTPUT_EXPORTED => 3, # output exported symbols
391 OUTPUT_INTERNAL => 4, # output non-exported symbols
392};
393my $output_selection = OUTPUT_ALL;
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100394my $show_not_found = 0;
395
Jani Nikula88c2b572016-06-07 11:00:52 +0300396my @export_file_list;
397
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100398my @build_time;
399if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
400 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
401 @build_time = gmtime($seconds);
402} else {
403 @build_time = localtime;
404}
405
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800406my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
407 'July', 'August', 'September', 'October',
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100408 'November', 'December')[$build_time[4]] .
409 " " . ($build_time[5]+1900);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Randy Dunlap8484baa2011-01-05 16:28:43 -0800411# Essentially these are globals.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700412# They probably want to be tidied up, made more localised or something.
413# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414# could cause "use of undefined value" or other bugs.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700415my ($function, %function_table, %parametertypes, $declaration_purpose);
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200416my $declaration_start_line;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700417my ($type, $declaration_name, $return_type);
Ilya Dryomov1c32fd02010-02-26 13:06:03 -0800418my ($newsection, $newcontents, $prototype, $brcount, %source_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700420if (defined($ENV{'KBUILD_VERBOSE'})) {
421 $verbose = "$ENV{'KBUILD_VERBOSE'}";
422}
423
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800424# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
426# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
427# We keep track of number of generated entries and generate a dummy
428# if needs be to ensure the expanded template can be postprocessed
429# into html.
430my $section_counter = 0;
431
432my $lineprefix="";
433
Jani Nikula48af6062016-05-26 14:56:05 +0300434# Parser states
435use constant {
436 STATE_NORMAL => 0, # normal code
437 STATE_NAME => 1, # looking for function name
438 STATE_FIELD => 2, # scanning field start
439 STATE_PROTO => 3, # scanning prototype
440 STATE_DOCBLOCK => 4, # documentation block
441 STATE_INLINE => 5, # gathering documentation outside main block
442};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700444my $in_doc_sect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Jani Nikula48af6062016-05-26 14:56:05 +0300446# Inline documentation state
447use constant {
448 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
449 STATE_INLINE_NAME => 1, # looking for member name (@foo:)
450 STATE_INLINE_TEXT => 2, # looking for member documentation
451 STATE_INLINE_END => 3, # done
452 STATE_INLINE_ERROR => 4, # error - Comment without header was found.
453 # Spit a warning as it's not
454 # proper kernel-doc and ignore the rest.
455};
456my $inline_doc_state;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458#declaration types: can be
459# 'function', 'struct', 'union', 'enum', 'typedef'
460my $decl_type;
461
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
463my $doc_end = '\*/';
464my $doc_com = '\s*\*\s*';
Daniel Santos12ae6772012-10-04 17:15:10 -0700465my $doc_com_body = '\s*\* ?';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700466my $doc_decl = $doc_com . '(\w+)';
Jani Nikulaf624ade2016-05-29 11:35:28 +0300467# @params and a strictly limited set of supported section names
Jonathan Corbet8569de62016-06-09 13:35:05 -0600468my $doc_sect = $doc_com .
Jonathan Corbetef000282016-08-26 07:14:08 -0600469 '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700470my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700471my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Jani Nikula48af6062016-05-26 14:56:05 +0300472my $doc_inline_start = '^\s*/\*\*\s*$';
473my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
474my $doc_inline_end = '^\s*\*/\s*$';
Jani Nikula0c9aa202016-11-16 17:26:16 +0200475my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200476my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478my %parameterdescs;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200479my %parameterdesc_start_lines;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480my @parameterlist;
481my %sections;
482my @sectionlist;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200483my %section_start_lines;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800484my $sectcheck;
485my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487my $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200488my $new_start_line = 0;
Jani Nikulaf624ade2016-05-29 11:35:28 +0300489
490# the canonical section names. see also $doc_sect above.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491my $section_default = "Description"; # default section
492my $section_intro = "Introduction";
493my $section = $section_default;
494my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100495my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497my $undescribed = "-- undescribed --";
498
499reset_state();
500
501while ($ARGV[0] =~ m/^-(.*)/) {
502 my $cmd = shift @ARGV;
503 if ($cmd eq "-html") {
504 $output_mode = "html";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300505 @highlights = @highlights_html;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200507 } elsif ($cmd eq "-html5") {
508 $output_mode = "html5";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300509 @highlights = @highlights_html5;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200510 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 } elsif ($cmd eq "-man") {
512 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300513 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 $blankline = $blankline_man;
515 } elsif ($cmd eq "-text") {
516 $output_mode = "text";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300517 @highlights = @highlights_text;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 $blankline = $blankline_text;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300519 } elsif ($cmd eq "-rst") {
520 $output_mode = "rst";
521 @highlights = @highlights_rst;
522 $blankline = $blankline_rst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 } elsif ($cmd eq "-docbook") {
524 $output_mode = "xml";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300525 @highlights = @highlights_xml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700527 } elsif ($cmd eq "-list") {
528 $output_mode = "list";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300529 @highlights = @highlights_list;
Johannes Bergeda603f2010-09-11 15:55:22 -0700530 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 } elsif ($cmd eq "-gnome") {
532 $output_mode = "gnome";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300533 @highlights = @highlights_gnome;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 $blankline = $blankline_gnome;
535 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
536 $modulename = shift @ARGV;
537 } elsif ($cmd eq "-function") { # to only output specific functions
Jani Nikulab6c3f452016-05-29 22:19:35 +0300538 $output_selection = OUTPUT_INCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 $function = shift @ARGV;
540 $function_table{$function} = 1;
Jani Nikulab6c3f452016-05-29 22:19:35 +0300541 } elsif ($cmd eq "-nofunction") { # output all except specific functions
542 $output_selection = OUTPUT_EXCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 $function = shift @ARGV;
544 $function_table{$function} = 1;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200545 } elsif ($cmd eq "-export") { # only exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300546 $output_selection = OUTPUT_EXPORTED;
Jani Nikulada9726e2016-06-07 10:29:59 +0300547 %function_table = ();
Jani Nikula86ae2e32016-01-21 13:05:22 +0200548 } elsif ($cmd eq "-internal") { # only non-exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300549 $output_selection = OUTPUT_INTERNAL;
Jani Nikulada9726e2016-06-07 10:29:59 +0300550 %function_table = ();
Jani Nikula88c2b572016-06-07 11:00:52 +0300551 } elsif ($cmd eq "-export-file") {
552 my $file = shift @ARGV;
553 push(@export_file_list, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 } elsif ($cmd eq "-v") {
555 $verbose = 1;
556 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
557 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700558 } elsif ($cmd eq '-no-doc-sections') {
559 $no_doc_sections = 1;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200560 } elsif ($cmd eq '-enable-lineno') {
561 $enable_lineno = 1;
Johannes Berge946c43a2013-11-12 15:11:12 -0800562 } elsif ($cmd eq '-show-not-found') {
563 $show_not_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 }
565}
566
Randy Dunlap8484baa2011-01-05 16:28:43 -0800567# continue execution near EOF;
568
Borislav Petkov53f049f2007-05-08 00:30:54 -0700569# get kernel version from env
570sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700571 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700572
573 if (defined($ENV{'KERNELVERSION'})) {
574 $version = $ENV{'KERNELVERSION'};
575 }
576 return $version;
577}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200579#
580sub print_lineno {
581 my $lineno = shift;
582 if ($enable_lineno && defined($lineno)) {
583 print "#define LINENO " . $lineno . "\n";
584 }
585}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586##
587# dumps section contents to arrays/hashes intended for that purpose.
588#
589sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700590 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 my $name = shift;
592 my $contents = join "\n", @_;
593
Jani Nikula13901ef2016-05-26 08:57:29 +0300594 if ($name =~ m/$type_param/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 $name = $1;
596 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800597 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200598 $parameterdesc_start_lines{$name} = $new_start_line;
599 $new_start_line = 0;
Randy Dunlapced69092008-12-01 13:14:03 -0800600 } elsif ($name eq "@\.\.\.") {
Randy Dunlapced69092008-12-01 13:14:03 -0800601 $name = "...";
602 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800603 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200604 $parameterdesc_start_lines{$name} = $new_start_line;
605 $new_start_line = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 } else {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700607 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Jani Nikula95b6be92016-06-10 11:14:05 +0300608 # Only warn on user specified duplicate section names.
609 if ($name ne $section_default) {
610 print STDERR "${file}:$.: warning: duplicate section name '$name'\n";
611 ++$warnings;
612 }
Jani Nikula32217762016-05-29 09:40:44 +0300613 $sections{$name} .= $contents;
614 } else {
615 $sections{$name} = $contents;
616 push @sectionlist, $name;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200617 $section_start_lines{$name} = $new_start_line;
618 $new_start_line = 0;
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700619 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 }
621}
622
623##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700624# dump DOC: section after checking that it should go out
625#
626sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700627 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700628 my $name = shift;
629 my $contents = join "\n", @_;
630
Johannes Berg4b445952007-10-24 15:08:48 -0700631 if ($no_doc_sections) {
632 return;
633 }
634
Jani Nikulab6c3f452016-05-29 22:19:35 +0300635 if (($output_selection == OUTPUT_ALL) ||
636 ($output_selection == OUTPUT_INCLUDE &&
637 defined($function_table{$name})) ||
638 ($output_selection == OUTPUT_EXCLUDE &&
639 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700640 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700641 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700642 output_blockhead({'sectionlist' => \@sectionlist,
643 'sections' => \%sections,
644 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300645 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700646 }
647}
648
649##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650# output function
651#
652# parameterdescs, a hash.
653# function => "function name"
654# parameterlist => @list of parameters
655# parameterdescs => %parameter descriptions
656# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800657# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800658#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
660sub output_highlight {
661 my $contents = join "\n",@_;
662 my $line;
663
664# DEBUG
665# if (!defined $contents) {
666# use Carp;
667# confess "output_highlight got called with no args?\n";
668# }
669
Dan Luedtke1b40c192012-08-12 10:46:15 +0200670 if ($output_mode eq "html" || $output_mode eq "html5" ||
671 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700672 $contents = local_unescape($contents);
673 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800674 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700675 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700676# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 eval $dohighlight;
678 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700679# print STDERR "contents af:$contents\n";
680
Dan Luedtke1b40c192012-08-12 10:46:15 +0200681# strip whitespaces when generating html5
682 if ($output_mode eq "html5") {
683 $contents =~ s/^\s+//;
684 $contents =~ s/\s+$//;
685 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700687 if (! $output_preformatted) {
688 $line =~ s/^\s*//;
689 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700690 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700691 if (! $output_preformatted) {
692 print $lineprefix, local_unescape($blankline);
693 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700695 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700696 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
697 print "\\&$line";
698 } else {
699 print $lineprefix, $line;
700 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 }
702 print "\n";
703 }
704}
705
Dan Luedtke1b40c192012-08-12 10:46:15 +0200706# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707sub output_section_html(%) {
708 my %args = %{$_[0]};
709 my $section;
710
711 foreach $section (@{$args{'sectionlist'}}) {
712 print "<h3>$section</h3>\n";
713 print "<blockquote>\n";
714 output_highlight($args{'sections'}{$section});
715 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800716 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717}
718
719# output enum in html
720sub output_enum_html(%) {
721 my %args = %{$_[0]};
722 my ($parameter);
723 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700724 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Randy Dunlapb9d973282009-06-09 08:50:38 -0700726 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 $count = 0;
728 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700729 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 if ($count != $#{$args{'parameterlist'}}) {
731 $count++;
732 print ",\n";
733 }
734 print "<br>";
735 }
736 print "};<br>\n";
737
738 print "<h3>Constants</h3>\n";
739 print "<dl>\n";
740 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700741 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 print "<dd>";
743 output_highlight($args{'parameterdescs'}{$parameter});
744 }
745 print "</dl>\n";
746 output_section_html(@_);
747 print "<hr>\n";
748}
749
Randy Dunlapd28bee02006-02-01 03:06:57 -0800750# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751sub output_typedef_html(%) {
752 my %args = %{$_[0]};
753 my ($parameter);
754 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700755 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
Randy Dunlapb9d973282009-06-09 08:50:38 -0700757 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 output_section_html(@_);
759 print "<hr>\n";
760}
761
762# output struct in html
763sub output_struct_html(%) {
764 my %args = %{$_[0]};
765 my ($parameter);
766
Randy Dunlapb9d973282009-06-09 08:50:38 -0700767 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
768 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 foreach $parameter (@{$args{'parameterlist'}}) {
770 if ($parameter =~ /^#/) {
771 print "$parameter<br>\n";
772 next;
773 }
774 my $parameter_name = $parameter;
775 $parameter_name =~ s/\[.*//;
776
Randy Dunlap3c308792007-05-08 00:24:39 -0700777 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 $type = $args{'parametertypes'}{$parameter};
779 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
780 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700781 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700783 # bitfield
784 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700786 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 }
788 }
789 print "};<br>\n";
790
791 print "<h3>Members</h3>\n";
792 print "<dl>\n";
793 foreach $parameter (@{$args{'parameterlist'}}) {
794 ($parameter =~ /^#/) && next;
795
796 my $parameter_name = $parameter;
797 $parameter_name =~ s/\[.*//;
798
Randy Dunlap3c308792007-05-08 00:24:39 -0700799 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700800 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 print "<dd>";
802 output_highlight($args{'parameterdescs'}{$parameter_name});
803 }
804 print "</dl>\n";
805 output_section_html(@_);
806 print "<hr>\n";
807}
808
809# output function in html
810sub output_function_html(%) {
811 my %args = %{$_[0]};
812 my ($parameter, $section);
813 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Randy Dunlapb9d973282009-06-09 08:50:38 -0700815 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
816 print "<i>" . $args{'functiontype'} . "</i>\n";
817 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 print "(";
819 $count = 0;
820 foreach $parameter (@{$args{'parameterlist'}}) {
821 $type = $args{'parametertypes'}{$parameter};
822 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
823 # pointer-to-function
824 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
825 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700826 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 }
828 if ($count != $#{$args{'parameterlist'}}) {
829 $count++;
830 print ",\n";
831 }
832 }
833 print ")\n";
834
835 print "<h3>Arguments</h3>\n";
836 print "<dl>\n";
837 foreach $parameter (@{$args{'parameterlist'}}) {
838 my $parameter_name = $parameter;
839 $parameter_name =~ s/\[.*//;
840
Randy Dunlap3c308792007-05-08 00:24:39 -0700841 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700842 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 print "<dd>";
844 output_highlight($args{'parameterdescs'}{$parameter_name});
845 }
846 print "</dl>\n";
847 output_section_html(@_);
848 print "<hr>\n";
849}
850
Johannes Bergb112e0f2007-10-24 15:08:48 -0700851# output DOC: block header in html
852sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 my %args = %{$_[0]};
854 my ($parameter, $section);
855 my $count;
856
857 foreach $section (@{$args{'sectionlist'}}) {
858 print "<h3>$section</h3>\n";
859 print "<ul>\n";
860 output_highlight($args{'sections'}{$section});
861 print "</ul>\n";
862 }
863 print "<hr>\n";
864}
865
Dan Luedtke1b40c192012-08-12 10:46:15 +0200866# output sections in html5
867sub output_section_html5(%) {
868 my %args = %{$_[0]};
869 my $section;
870
871 foreach $section (@{$args{'sectionlist'}}) {
872 print "<section>\n";
873 print "<h1>$section</h1>\n";
874 print "<p>\n";
875 output_highlight($args{'sections'}{$section});
876 print "</p>\n";
877 print "</section>\n";
878 }
879}
880
881# output enum in html5
882sub output_enum_html5(%) {
883 my %args = %{$_[0]};
884 my ($parameter);
885 my $count;
886 my $html5id;
887
888 $html5id = $args{'enum'};
889 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
890 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
891 print "<h1>enum " . $args{'enum'} . "</h1>\n";
892 print "<ol class=\"code\">\n";
893 print "<li>";
894 print "<span class=\"keyword\">enum</span> ";
895 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
896 print "</li>\n";
897 $count = 0;
898 foreach $parameter (@{$args{'parameterlist'}}) {
899 print "<li class=\"indent\">";
900 print "<span class=\"param\">" . $parameter . "</span>";
901 if ($count != $#{$args{'parameterlist'}}) {
902 $count++;
903 print ",";
904 }
905 print "</li>\n";
906 }
907 print "<li>};</li>\n";
908 print "</ol>\n";
909
910 print "<section>\n";
911 print "<h1>Constants</h1>\n";
912 print "<dl>\n";
913 foreach $parameter (@{$args{'parameterlist'}}) {
914 print "<dt>" . $parameter . "</dt>\n";
915 print "<dd>";
916 output_highlight($args{'parameterdescs'}{$parameter});
917 print "</dd>\n";
918 }
919 print "</dl>\n";
920 print "</section>\n";
921 output_section_html5(@_);
922 print "</article>\n";
923}
924
925# output typedef in html5
926sub output_typedef_html5(%) {
927 my %args = %{$_[0]};
928 my ($parameter);
929 my $count;
930 my $html5id;
931
932 $html5id = $args{'typedef'};
933 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
934 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
935 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
936
937 print "<ol class=\"code\">\n";
938 print "<li>";
939 print "<span class=\"keyword\">typedef</span> ";
940 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
941 print "</li>\n";
942 print "</ol>\n";
943 output_section_html5(@_);
944 print "</article>\n";
945}
946
947# output struct in html5
948sub output_struct_html5(%) {
949 my %args = %{$_[0]};
950 my ($parameter);
951 my $html5id;
952
953 $html5id = $args{'struct'};
954 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
955 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
956 print "<hgroup>\n";
957 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
958 print "<h2>". $args{'purpose'} . "</h2>\n";
959 print "</hgroup>\n";
960 print "<ol class=\"code\">\n";
961 print "<li>";
962 print "<span class=\"type\">" . $args{'type'} . "</span> ";
963 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
964 print "</li>\n";
965 foreach $parameter (@{$args{'parameterlist'}}) {
966 print "<li class=\"indent\">";
967 if ($parameter =~ /^#/) {
968 print "<span class=\"param\">" . $parameter ."</span>\n";
969 print "</li>\n";
970 next;
971 }
972 my $parameter_name = $parameter;
973 $parameter_name =~ s/\[.*//;
974
975 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
976 $type = $args{'parametertypes'}{$parameter};
977 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
978 # pointer-to-function
979 print "<span class=\"type\">$1</span> ";
980 print "<span class=\"param\">$parameter</span>";
981 print "<span class=\"type\">)</span> ";
982 print "(<span class=\"args\">$2</span>);";
983 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
984 # bitfield
985 print "<span class=\"type\">$1</span> ";
986 print "<span class=\"param\">$parameter</span>";
987 print "<span class=\"bits\">$2</span>;";
988 } else {
989 print "<span class=\"type\">$type</span> ";
990 print "<span class=\"param\">$parameter</span>;";
991 }
992 print "</li>\n";
993 }
994 print "<li>};</li>\n";
995 print "</ol>\n";
996
997 print "<section>\n";
998 print "<h1>Members</h1>\n";
999 print "<dl>\n";
1000 foreach $parameter (@{$args{'parameterlist'}}) {
1001 ($parameter =~ /^#/) && next;
1002
1003 my $parameter_name = $parameter;
1004 $parameter_name =~ s/\[.*//;
1005
1006 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1007 print "<dt>" . $parameter . "</dt>\n";
1008 print "<dd>";
1009 output_highlight($args{'parameterdescs'}{$parameter_name});
1010 print "</dd>\n";
1011 }
1012 print "</dl>\n";
1013 print "</section>\n";
1014 output_section_html5(@_);
1015 print "</article>\n";
1016}
1017
1018# output function in html5
1019sub output_function_html5(%) {
1020 my %args = %{$_[0]};
1021 my ($parameter, $section);
1022 my $count;
1023 my $html5id;
1024
1025 $html5id = $args{'function'};
1026 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1027 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
1028 print "<hgroup>\n";
1029 print "<h1>" . $args{'function'} . "</h1>";
1030 print "<h2>" . $args{'purpose'} . "</h2>\n";
1031 print "</hgroup>\n";
1032 print "<ol class=\"code\">\n";
1033 print "<li>";
1034 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
1035 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
1036 print "</li>";
1037 $count = 0;
1038 foreach $parameter (@{$args{'parameterlist'}}) {
1039 print "<li class=\"indent\">";
1040 $type = $args{'parametertypes'}{$parameter};
1041 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1042 # pointer-to-function
1043 print "<span class=\"type\">$1</span> ";
1044 print "<span class=\"param\">$parameter</span>";
1045 print "<span class=\"type\">)</span> ";
1046 print "(<span class=\"args\">$2</span>)";
1047 } else {
1048 print "<span class=\"type\">$type</span> ";
1049 print "<span class=\"param\">$parameter</span>";
1050 }
1051 if ($count != $#{$args{'parameterlist'}}) {
1052 $count++;
1053 print ",";
1054 }
1055 print "</li>\n";
1056 }
1057 print "<li>)</li>\n";
1058 print "</ol>\n";
1059
1060 print "<section>\n";
1061 print "<h1>Arguments</h1>\n";
1062 print "<p>\n";
1063 print "<dl>\n";
1064 foreach $parameter (@{$args{'parameterlist'}}) {
1065 my $parameter_name = $parameter;
1066 $parameter_name =~ s/\[.*//;
1067
1068 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1069 print "<dt>" . $parameter . "</dt>\n";
1070 print "<dd>";
1071 output_highlight($args{'parameterdescs'}{$parameter_name});
1072 print "</dd>\n";
1073 }
1074 print "</dl>\n";
1075 print "</section>\n";
1076 output_section_html5(@_);
1077 print "</article>\n";
1078}
1079
1080# output DOC: block header in html5
1081sub output_blockhead_html5(%) {
1082 my %args = %{$_[0]};
1083 my ($parameter, $section);
1084 my $count;
1085 my $html5id;
1086
1087 foreach $section (@{$args{'sectionlist'}}) {
1088 $html5id = $section;
1089 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1090 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1091 print "<h1>$section</h1>\n";
1092 print "<p>\n";
1093 output_highlight($args{'sections'}{$section});
1094 print "</p>\n";
1095 }
1096 print "</article>\n";
1097}
1098
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099sub output_section_xml(%) {
1100 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001101 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 # print out each section
1103 $lineprefix=" ";
1104 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001105 print "<refsect1>\n";
1106 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001108 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001109 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001110 } else {
1111 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 }
1113 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001114 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001116 print "</programlisting></informalexample>\n";
1117 } else {
1118 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001120 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 }
1122}
1123
1124# output function in XML DocBook
1125sub output_function_xml(%) {
1126 my %args = %{$_[0]};
1127 my ($parameter, $section);
1128 my $count;
1129 my $id;
1130
Randy Dunlapb9d973282009-06-09 08:50:38 -07001131 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 $id =~ s/[^A-Za-z0-9]/-/g;
1133
Pavel Pisa5449bc92007-02-10 01:45:37 -08001134 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001135 print "<refentryinfo>\n";
1136 print " <title>LINUX</title>\n";
1137 print " <productname>Kernel Hackers Manual</productname>\n";
1138 print " <date>$man_date</date>\n";
1139 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001141 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001142 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001143 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 print "</refmeta>\n";
1145 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001146 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 print " <refpurpose>\n";
1148 print " ";
1149 output_highlight ($args{'purpose'});
1150 print " </refpurpose>\n";
1151 print "</refnamediv>\n";
1152
1153 print "<refsynopsisdiv>\n";
1154 print " <title>Synopsis</title>\n";
1155 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001156 print " <funcdef>" . $args{'functiontype'} . " ";
1157 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158
1159 $count = 0;
1160 if ($#{$args{'parameterlist'}} >= 0) {
1161 foreach $parameter (@{$args{'parameterlist'}}) {
1162 $type = $args{'parametertypes'}{$parameter};
1163 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1164 # pointer-to-function
1165 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1166 print " <funcparams>$2</funcparams></paramdef>\n";
1167 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001168 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 print " <parameter>$parameter</parameter></paramdef>\n";
1170 }
1171 }
1172 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001173 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 }
1175 print " </funcprototype></funcsynopsis>\n";
1176 print "</refsynopsisdiv>\n";
1177
1178 # print parameters
1179 print "<refsect1>\n <title>Arguments</title>\n";
1180 if ($#{$args{'parameterlist'}} >= 0) {
1181 print " <variablelist>\n";
1182 foreach $parameter (@{$args{'parameterlist'}}) {
1183 my $parameter_name = $parameter;
1184 $parameter_name =~ s/\[.*//;
Paolo Bonzinifc6d7af2017-01-02 16:22:25 +01001185 $type = $args{'parametertypes'}{$parameter};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
Paolo Bonzinifc6d7af2017-01-02 16:22:25 +01001187 print " <varlistentry>\n <term><parameter>$type $parameter</parameter></term>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 print " <listitem>\n <para>\n";
1189 $lineprefix=" ";
1190 output_highlight($args{'parameterdescs'}{$parameter_name});
1191 print " </para>\n </listitem>\n </varlistentry>\n";
1192 }
1193 print " </variablelist>\n";
1194 } else {
1195 print " <para>\n None\n </para>\n";
1196 }
1197 print "</refsect1>\n";
1198
1199 output_section_xml(@_);
1200 print "</refentry>\n\n";
1201}
1202
1203# output struct in XML DocBook
1204sub output_struct_xml(%) {
1205 my %args = %{$_[0]};
1206 my ($parameter, $section);
1207 my $id;
1208
Randy Dunlapb9d973282009-06-09 08:50:38 -07001209 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 $id =~ s/[^A-Za-z0-9]/-/g;
1211
Pavel Pisa5449bc92007-02-10 01:45:37 -08001212 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001213 print "<refentryinfo>\n";
1214 print " <title>LINUX</title>\n";
1215 print " <productname>Kernel Hackers Manual</productname>\n";
1216 print " <date>$man_date</date>\n";
1217 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001219 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001220 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001221 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 print "</refmeta>\n";
1223 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001224 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 print " <refpurpose>\n";
1226 print " ";
1227 output_highlight ($args{'purpose'});
1228 print " </refpurpose>\n";
1229 print "</refnamediv>\n";
1230
1231 print "<refsynopsisdiv>\n";
1232 print " <title>Synopsis</title>\n";
1233 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001234 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 foreach $parameter (@{$args{'parameterlist'}}) {
1236 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001237 my $prm = $parameter;
1238 # convert data read & converted thru xml_escape() into &xyz; format:
1239 # This allows us to have #define macros interspersed in a struct.
1240 $prm =~ s/\\\\\\/\&/g;
1241 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 next;
1243 }
1244
1245 my $parameter_name = $parameter;
1246 $parameter_name =~ s/\[.*//;
1247
1248 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001249 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 $type = $args{'parametertypes'}{$parameter};
1251 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1252 # pointer-to-function
1253 print " $1 $parameter) ($2);\n";
1254 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001255 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 print " $1 $parameter$2;\n";
1257 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001258 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 }
1260 }
1261 print "};";
1262 print " </programlisting>\n";
1263 print "</refsynopsisdiv>\n";
1264
1265 print " <refsect1>\n";
1266 print " <title>Members</title>\n";
1267
Randy Dunlap39f00c02008-09-22 13:57:44 -07001268 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 print " <variablelist>\n";
1270 foreach $parameter (@{$args{'parameterlist'}}) {
1271 ($parameter =~ /^#/) && next;
1272
1273 my $parameter_name = $parameter;
1274 $parameter_name =~ s/\[.*//;
1275
1276 defined($args{'parameterdescs'}{$parameter_name}) || next;
1277 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Paolo Bonzinifc6d7af2017-01-02 16:22:25 +01001278 $type = $args{'parametertypes'}{$parameter};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 print " <varlistentry>";
Paolo Bonzinifc6d7af2017-01-02 16:22:25 +01001280 print " <term><literal>$type $parameter</literal></term>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 print " <listitem><para>\n";
1282 output_highlight($args{'parameterdescs'}{$parameter_name});
1283 print " </para></listitem>\n";
1284 print " </varlistentry>\n";
1285 }
1286 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001287 } else {
1288 print " <para>\n None\n </para>\n";
1289 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 print " </refsect1>\n";
1291
1292 output_section_xml(@_);
1293
1294 print "</refentry>\n\n";
1295}
1296
1297# output enum in XML DocBook
1298sub output_enum_xml(%) {
1299 my %args = %{$_[0]};
1300 my ($parameter, $section);
1301 my $count;
1302 my $id;
1303
Randy Dunlapb9d973282009-06-09 08:50:38 -07001304 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 $id =~ s/[^A-Za-z0-9]/-/g;
1306
Pavel Pisa5449bc92007-02-10 01:45:37 -08001307 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001308 print "<refentryinfo>\n";
1309 print " <title>LINUX</title>\n";
1310 print " <productname>Kernel Hackers Manual</productname>\n";
1311 print " <date>$man_date</date>\n";
1312 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001314 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001315 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001316 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 print "</refmeta>\n";
1318 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001319 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 print " <refpurpose>\n";
1321 print " ";
1322 output_highlight ($args{'purpose'});
1323 print " </refpurpose>\n";
1324 print "</refnamediv>\n";
1325
1326 print "<refsynopsisdiv>\n";
1327 print " <title>Synopsis</title>\n";
1328 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001329 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 $count = 0;
1331 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001332 print " $parameter";
1333 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 $count++;
1335 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 print "\n";
1338 }
1339 print "};";
1340 print " </programlisting>\n";
1341 print "</refsynopsisdiv>\n";
1342
1343 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001344 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 print " <variablelist>\n";
1346 foreach $parameter (@{$args{'parameterlist'}}) {
1347 my $parameter_name = $parameter;
1348 $parameter_name =~ s/\[.*//;
1349
1350 print " <varlistentry>";
1351 print " <term>$parameter</term>\n";
1352 print " <listitem><para>\n";
1353 output_highlight($args{'parameterdescs'}{$parameter_name});
1354 print " </para></listitem>\n";
1355 print " </varlistentry>\n";
1356 }
1357 print " </variablelist>\n";
1358 print "</refsect1>\n";
1359
1360 output_section_xml(@_);
1361
1362 print "</refentry>\n\n";
1363}
1364
1365# output typedef in XML DocBook
1366sub output_typedef_xml(%) {
1367 my %args = %{$_[0]};
1368 my ($parameter, $section);
1369 my $id;
1370
Randy Dunlapb9d973282009-06-09 08:50:38 -07001371 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 $id =~ s/[^A-Za-z0-9]/-/g;
1373
Pavel Pisa5449bc92007-02-10 01:45:37 -08001374 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001375 print "<refentryinfo>\n";
1376 print " <title>LINUX</title>\n";
1377 print " <productname>Kernel Hackers Manual</productname>\n";
1378 print " <date>$man_date</date>\n";
1379 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001381 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001382 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 print "</refmeta>\n";
1384 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001385 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 print " <refpurpose>\n";
1387 print " ";
1388 output_highlight ($args{'purpose'});
1389 print " </refpurpose>\n";
1390 print "</refnamediv>\n";
1391
1392 print "<refsynopsisdiv>\n";
1393 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001394 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 print "</refsynopsisdiv>\n";
1396
1397 output_section_xml(@_);
1398
1399 print "</refentry>\n\n";
1400}
1401
1402# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001403sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 my %args = %{$_[0]};
1405 my ($parameter, $section);
1406 my $count;
1407
1408 my $id = $args{'module'};
1409 $id =~ s/[^A-Za-z0-9]/-/g;
1410
1411 # print out each section
1412 $lineprefix=" ";
1413 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001414 if (!$args{'content-only'}) {
1415 print "<refsect1>\n <title>$section</title>\n";
1416 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 if ($section =~ m/EXAMPLE/i) {
1418 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001419 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001420 } else {
1421 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 }
1423 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001424 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 if ($section =~ m/EXAMPLE/i) {
1426 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001427 } else {
1428 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001430 if (!$args{'content-only'}) {
1431 print "\n</refsect1>\n";
1432 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 }
1434
1435 print "\n\n";
1436}
1437
1438# output in XML DocBook
1439sub output_function_gnome {
1440 my %args = %{$_[0]};
1441 my ($parameter, $section);
1442 my $count;
1443 my $id;
1444
Randy Dunlapb9d973282009-06-09 08:50:38 -07001445 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 $id =~ s/[^A-Za-z0-9]/-/g;
1447
1448 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001449 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450
1451 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001452 print " <funcdef>" . $args{'functiontype'} . " ";
1453 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 print "</function></funcdef>\n";
1455
1456 $count = 0;
1457 if ($#{$args{'parameterlist'}} >= 0) {
1458 foreach $parameter (@{$args{'parameterlist'}}) {
1459 $type = $args{'parametertypes'}{$parameter};
1460 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1461 # pointer-to-function
1462 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1463 print " <funcparams>$2</funcparams></paramdef>\n";
1464 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001465 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466 print " <parameter>$parameter</parameter></paramdef>\n";
1467 }
1468 }
1469 } else {
1470 print " <void>\n";
1471 }
1472 print " </funcsynopsis>\n";
1473 if ($#{$args{'parameterlist'}} >= 0) {
1474 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1475 print "<tgroup cols=\"2\">\n";
1476 print "<colspec colwidth=\"2*\">\n";
1477 print "<colspec colwidth=\"8*\">\n";
1478 print "<tbody>\n";
1479 foreach $parameter (@{$args{'parameterlist'}}) {
1480 my $parameter_name = $parameter;
1481 $parameter_name =~ s/\[.*//;
1482
1483 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1484 print " <entry>\n";
1485 $lineprefix=" ";
1486 output_highlight($args{'parameterdescs'}{$parameter_name});
1487 print " </entry></row>\n";
1488 }
1489 print " </tbody></tgroup></informaltable>\n";
1490 } else {
1491 print " <para>\n None\n </para>\n";
1492 }
1493
1494 # print out each section
1495 $lineprefix=" ";
1496 foreach $section (@{$args{'sectionlist'}}) {
1497 print "<simplesect>\n <title>$section</title>\n";
1498 if ($section =~ m/EXAMPLE/i) {
1499 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001500 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 } else {
1502 }
1503 print "<para>\n";
1504 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001505 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 print "</para>\n";
1507 if ($section =~ m/EXAMPLE/i) {
1508 print "</programlisting></example>\n";
1509 } else {
1510 }
1511 print " </simplesect>\n";
1512 }
1513
1514 print "</sect2>\n\n";
1515}
1516
1517##
1518# output function in man
1519sub output_function_man(%) {
1520 my %args = %{$_[0]};
1521 my ($parameter, $section);
1522 my $count;
1523
1524 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1525
1526 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001527 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
1529 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001530 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001531 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001532 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001533 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 $count = 0;
1536 my $parenth = "(";
1537 my $post = ",";
1538 foreach my $parameter (@{$args{'parameterlist'}}) {
1539 if ($count == $#{$args{'parameterlist'}}) {
1540 $post = ");";
1541 }
1542 $type = $args{'parametertypes'}{$parameter};
1543 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1544 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001545 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 } else {
1547 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001548 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 }
1550 $count++;
1551 $parenth = "";
1552 }
1553
1554 print ".SH ARGUMENTS\n";
1555 foreach $parameter (@{$args{'parameterlist'}}) {
1556 my $parameter_name = $parameter;
1557 $parameter_name =~ s/\[.*//;
1558
Randy Dunlapb9d973282009-06-09 08:50:38 -07001559 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 output_highlight($args{'parameterdescs'}{$parameter_name});
1561 }
1562 foreach $section (@{$args{'sectionlist'}}) {
1563 print ".SH \"", uc $section, "\"\n";
1564 output_highlight($args{'sections'}{$section});
1565 }
1566}
1567
1568##
1569# output enum in man
1570sub output_enum_man(%) {
1571 my %args = %{$_[0]};
1572 my ($parameter, $section);
1573 my $count;
1574
1575 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1576
1577 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001578 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579
1580 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001581 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 $count = 0;
1583 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001584 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 if ($count == $#{$args{'parameterlist'}}) {
1586 print "\n};\n";
1587 last;
1588 }
1589 else {
1590 print ", \n.br\n";
1591 }
1592 $count++;
1593 }
1594
1595 print ".SH Constants\n";
1596 foreach $parameter (@{$args{'parameterlist'}}) {
1597 my $parameter_name = $parameter;
1598 $parameter_name =~ s/\[.*//;
1599
Randy Dunlapb9d973282009-06-09 08:50:38 -07001600 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 output_highlight($args{'parameterdescs'}{$parameter_name});
1602 }
1603 foreach $section (@{$args{'sectionlist'}}) {
1604 print ".SH \"$section\"\n";
1605 output_highlight($args{'sections'}{$section});
1606 }
1607}
1608
1609##
1610# output struct in man
1611sub output_struct_man(%) {
1612 my %args = %{$_[0]};
1613 my ($parameter, $section);
1614
Randy Dunlapb9d973282009-06-09 08:50:38 -07001615 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
1617 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001618 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619
1620 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001621 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
1623 foreach my $parameter (@{$args{'parameterlist'}}) {
1624 if ($parameter =~ /^#/) {
1625 print ".BI \"$parameter\"\n.br\n";
1626 next;
1627 }
1628 my $parameter_name = $parameter;
1629 $parameter_name =~ s/\[.*//;
1630
Randy Dunlap3c308792007-05-08 00:24:39 -07001631 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 $type = $args{'parametertypes'}{$parameter};
1633 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1634 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001635 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001637 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001638 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 } else {
1640 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001641 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 }
1643 print "\n.br\n";
1644 }
1645 print "};\n.br\n";
1646
Randy Dunlapc51d3dac2006-06-25 05:49:14 -07001647 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 foreach $parameter (@{$args{'parameterlist'}}) {
1649 ($parameter =~ /^#/) && next;
1650
1651 my $parameter_name = $parameter;
1652 $parameter_name =~ s/\[.*//;
1653
Randy Dunlap3c308792007-05-08 00:24:39 -07001654 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001655 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 output_highlight($args{'parameterdescs'}{$parameter_name});
1657 }
1658 foreach $section (@{$args{'sectionlist'}}) {
1659 print ".SH \"$section\"\n";
1660 output_highlight($args{'sections'}{$section});
1661 }
1662}
1663
1664##
1665# output typedef in man
1666sub output_typedef_man(%) {
1667 my %args = %{$_[0]};
1668 my ($parameter, $section);
1669
1670 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1671
1672 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001673 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
1675 foreach $section (@{$args{'sectionlist'}}) {
1676 print ".SH \"$section\"\n";
1677 output_highlight($args{'sections'}{$section});
1678 }
1679}
1680
Johannes Bergb112e0f2007-10-24 15:08:48 -07001681sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 my %args = %{$_[0]};
1683 my ($parameter, $section);
1684 my $count;
1685
1686 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1687
1688 foreach $section (@{$args{'sectionlist'}}) {
1689 print ".SH \"$section\"\n";
1690 output_highlight($args{'sections'}{$section});
1691 }
1692}
1693
1694##
1695# output in text
1696sub output_function_text(%) {
1697 my %args = %{$_[0]};
1698 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001699 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700
Randy Dunlapf47634b2006-07-01 04:36:36 -07001701 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001702 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001703
1704 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001705 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001706 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001707 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001708 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001709 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001711
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 my $count = 0;
1713 foreach my $parameter (@{$args{'parameterlist'}}) {
1714 $type = $args{'parametertypes'}{$parameter};
1715 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1716 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001717 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001719 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 }
1721 if ($count != $#{$args{'parameterlist'}}) {
1722 $count++;
1723 print ",\n";
1724 print " " x length($start);
1725 } else {
1726 print ");\n\n";
1727 }
1728 }
1729
1730 print "Arguments:\n\n";
1731 foreach $parameter (@{$args{'parameterlist'}}) {
1732 my $parameter_name = $parameter;
1733 $parameter_name =~ s/\[.*//;
1734
Randy Dunlapb9d973282009-06-09 08:50:38 -07001735 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 }
1737 output_section_text(@_);
1738}
1739
1740#output sections in text
1741sub output_section_text(%) {
1742 my %args = %{$_[0]};
1743 my $section;
1744
1745 print "\n";
1746 foreach $section (@{$args{'sectionlist'}}) {
1747 print "$section:\n\n";
1748 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 print "\n\n";
1751}
1752
1753# output enum in text
1754sub output_enum_text(%) {
1755 my %args = %{$_[0]};
1756 my ($parameter);
1757 my $count;
1758 print "Enum:\n\n";
1759
Randy Dunlapb9d973282009-06-09 08:50:38 -07001760 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1761 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 $count = 0;
1763 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001764 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 if ($count != $#{$args{'parameterlist'}}) {
1766 $count++;
1767 print ",";
1768 }
1769 print "\n";
1770 }
1771 print "};\n\n";
1772
1773 print "Constants:\n\n";
1774 foreach $parameter (@{$args{'parameterlist'}}) {
1775 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001776 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 }
1778
1779 output_section_text(@_);
1780}
1781
1782# output typedef in text
1783sub output_typedef_text(%) {
1784 my %args = %{$_[0]};
1785 my ($parameter);
1786 my $count;
1787 print "Typedef:\n\n";
1788
Randy Dunlapb9d973282009-06-09 08:50:38 -07001789 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 output_section_text(@_);
1791}
1792
1793# output struct as text
1794sub output_struct_text(%) {
1795 my %args = %{$_[0]};
1796 my ($parameter);
1797
Randy Dunlapb9d973282009-06-09 08:50:38 -07001798 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1799 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 foreach $parameter (@{$args{'parameterlist'}}) {
1801 if ($parameter =~ /^#/) {
1802 print "$parameter\n";
1803 next;
1804 }
1805
1806 my $parameter_name = $parameter;
1807 $parameter_name =~ s/\[.*//;
1808
Randy Dunlap3c308792007-05-08 00:24:39 -07001809 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 $type = $args{'parametertypes'}{$parameter};
1811 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1812 # pointer-to-function
1813 print "\t$1 $parameter) ($2);\n";
1814 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001815 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 print "\t$1 $parameter$2;\n";
1817 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001818 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 }
1820 }
1821 print "};\n\n";
1822
1823 print "Members:\n\n";
1824 foreach $parameter (@{$args{'parameterlist'}}) {
1825 ($parameter =~ /^#/) && next;
1826
1827 my $parameter_name = $parameter;
1828 $parameter_name =~ s/\[.*//;
1829
Randy Dunlap3c308792007-05-08 00:24:39 -07001830 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001832 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 }
1834 print "\n";
1835 output_section_text(@_);
1836}
1837
Johannes Bergb112e0f2007-10-24 15:08:48 -07001838sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839 my %args = %{$_[0]};
1840 my ($parameter, $section);
1841
1842 foreach $section (@{$args{'sectionlist'}}) {
1843 print " $section:\n";
1844 print " -> ";
1845 output_highlight($args{'sections'}{$section});
1846 }
1847}
1848
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001849##
1850# output in restructured text
1851#
1852
1853#
1854# This could use some work; it's used to output the DOC: sections, and
1855# starts by putting out the name of the doc section itself, but that tends
1856# to duplicate a header already in the template file.
1857#
1858sub output_blockhead_rst(%) {
1859 my %args = %{$_[0]};
1860 my ($parameter, $section);
1861
1862 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001863 if ($output_selection != OUTPUT_INCLUDE) {
1864 print "**$section**\n\n";
1865 }
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001866 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001867 output_highlight_rst($args{'sections'}{$section});
1868 print "\n";
1869 }
1870}
1871
1872sub output_highlight_rst {
1873 my $contents = join "\n",@_;
1874 my $line;
1875
1876 # undo the evil effects of xml_escape() earlier
1877 $contents = xml_unescape($contents);
1878
1879 eval $dohighlight;
1880 die $@ if $@;
1881
1882 foreach $line (split "\n", $contents) {
Jani Nikula830066a2016-05-26 22:04:33 +03001883 print $lineprefix . $line . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001884 }
1885}
1886
1887sub output_function_rst(%) {
1888 my %args = %{$_[0]};
1889 my ($parameter, $section);
Jani Nikulac099ff62016-05-26 17:18:17 +03001890 my $oldprefix = $lineprefix;
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001891 my $start = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001892
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001893 if ($args{'typedef'}) {
1894 print ".. c:type:: ". $args{'function'} . "\n\n";
1895 print_lineno($declaration_start_line);
1896 print " **Typedef**: ";
1897 $lineprefix = "";
1898 output_highlight_rst($args{'purpose'});
1899 $start = "\n\n**Syntax**\n\n ``";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001900 } else {
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001901 print ".. c:function:: ";
1902 }
1903 if ($args{'functiontype'} ne "") {
1904 $start .= $args{'functiontype'} . " " . $args{'function'} . " (";
1905 } else {
1906 $start .= $args{'function'} . " (";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001907 }
1908 print $start;
1909
1910 my $count = 0;
1911 foreach my $parameter (@{$args{'parameterlist'}}) {
1912 if ($count ne 0) {
1913 print ", ";
1914 }
1915 $count++;
1916 $type = $args{'parametertypes'}{$parameter};
Mauro Carvalho Chehaba88b1672016-07-22 11:46:36 -03001917
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001918 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1919 # pointer-to-function
1920 print $1 . $parameter . ") (" . $2;
1921 } else {
1922 print $type . " " . $parameter;
1923 }
1924 }
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001925 if ($args{'typedef'}) {
1926 print ");``\n\n";
1927 } else {
1928 print ")\n\n";
1929 print_lineno($declaration_start_line);
1930 $lineprefix = " ";
1931 output_highlight_rst($args{'purpose'});
1932 print "\n";
1933 }
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001934
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001935 print "**Parameters**\n\n";
1936 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001937 foreach $parameter (@{$args{'parameterlist'}}) {
1938 my $parameter_name = $parameter;
Gabriel Krisman Bertaziada5f442017-01-09 18:11:57 -02001939 $parameter_name =~ s/\[.*//;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001940 $type = $args{'parametertypes'}{$parameter};
1941
1942 if ($type ne "") {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001943 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001944 } else {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001945 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001946 }
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001947
1948 print_lineno($parameterdesc_start_lines{$parameter_name});
1949
Jani Nikula5e64fa92016-05-19 20:32:48 +03001950 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1951 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001952 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001953 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001954 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001955 }
1956 print "\n";
1957 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001958
1959 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001960 output_section_rst(@_);
1961}
1962
1963sub output_section_rst(%) {
1964 my %args = %{$_[0]};
1965 my $section;
1966 my $oldprefix = $lineprefix;
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001967 $lineprefix = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001968
1969 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001970 print "**$section**\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001971 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001972 output_highlight_rst($args{'sections'}{$section});
1973 print "\n";
1974 }
1975 print "\n";
1976 $lineprefix = $oldprefix;
1977}
1978
1979sub output_enum_rst(%) {
1980 my %args = %{$_[0]};
1981 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001982 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001983 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001984 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001985
1986 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001987 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001988 $lineprefix = " ";
1989 output_highlight_rst($args{'purpose'});
1990 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001991
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001992 print "**Constants**\n\n";
1993 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001994 foreach $parameter (@{$args{'parameterlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001995 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001996 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1997 output_highlight_rst($args{'parameterdescs'}{$parameter});
1998 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001999 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002000 }
2001 print "\n";
2002 }
Jani Nikulac099ff62016-05-26 17:18:17 +03002003
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002004 $lineprefix = $oldprefix;
2005 output_section_rst(@_);
2006}
2007
2008sub output_typedef_rst(%) {
2009 my %args = %{$_[0]};
2010 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03002011 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002012 my $name = "typedef " . $args{'typedef'};
2013
Jani Nikula62850972016-05-12 16:15:38 +03002014 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002015 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03002016 $lineprefix = " ";
2017 output_highlight_rst($args{'purpose'});
2018 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002019
Jani Nikulac099ff62016-05-26 17:18:17 +03002020 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002021 output_section_rst(@_);
2022}
2023
2024sub output_struct_rst(%) {
2025 my %args = %{$_[0]};
2026 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03002027 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002028 my $name = $args{'type'} . " " . $args{'struct'};
2029
Jani Nikula62850972016-05-12 16:15:38 +03002030 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002031 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03002032 $lineprefix = " ";
2033 output_highlight_rst($args{'purpose'});
2034 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002035
Jani Nikulaecbcfba2016-05-26 18:30:27 +03002036 print "**Definition**\n\n";
2037 print "::\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002038 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
2039 foreach $parameter (@{$args{'parameterlist'}}) {
2040 if ($parameter =~ /^#/) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03002041 print " " . "$parameter\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002042 next;
2043 }
2044
2045 my $parameter_name = $parameter;
2046 $parameter_name =~ s/\[.*//;
2047
2048 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
2049 $type = $args{'parametertypes'}{$parameter};
2050 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
2051 # pointer-to-function
2052 print " $1 $parameter) ($2);\n";
2053 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
2054 # bitfield
2055 print " $1 $parameter$2;\n";
2056 } else {
2057 print " " . $type . " " . $parameter . ";\n";
2058 }
2059 }
2060 print " };\n\n";
2061
Jani Nikulaecbcfba2016-05-26 18:30:27 +03002062 print "**Members**\n\n";
2063 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002064 foreach $parameter (@{$args{'parameterlist'}}) {
2065 ($parameter =~ /^#/) && next;
2066
2067 my $parameter_name = $parameter;
2068 $parameter_name =~ s/\[.*//;
2069
2070 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
2071 $type = $args{'parametertypes'}{$parameter};
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002072 print_lineno($parameterdesc_start_lines{$parameter_name});
Mauro Carvalho Chehab6d232c82016-08-22 22:02:57 -03002073 print "``" . $parameter . "``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002074 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002075 print "\n";
2076 }
2077 print "\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03002078
2079 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002080 output_section_rst(@_);
2081}
2082
2083
Johannes Bergeda603f2010-09-11 15:55:22 -07002084## list mode output functions
2085
2086sub output_function_list(%) {
2087 my %args = %{$_[0]};
2088
2089 print $args{'function'} . "\n";
2090}
2091
2092# output enum in list
2093sub output_enum_list(%) {
2094 my %args = %{$_[0]};
2095 print $args{'enum'} . "\n";
2096}
2097
2098# output typedef in list
2099sub output_typedef_list(%) {
2100 my %args = %{$_[0]};
2101 print $args{'typedef'} . "\n";
2102}
2103
2104# output struct as list
2105sub output_struct_list(%) {
2106 my %args = %{$_[0]};
2107
2108 print $args{'struct'} . "\n";
2109}
2110
2111sub output_blockhead_list(%) {
2112 my %args = %{$_[0]};
2113 my ($parameter, $section);
2114
2115 foreach $section (@{$args{'sectionlist'}}) {
2116 print "DOC: $section\n";
2117 }
2118}
2119
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120##
Randy Dunlap27205742006-10-11 01:22:12 -07002121# generic output function for all types (function, struct/union, typedef, enum);
2122# calls the generated, variable output_ function name based on
2123# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124sub output_declaration {
2125 no strict 'refs';
2126 my $name = shift;
2127 my $functype = shift;
2128 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002129 if (($output_selection == OUTPUT_ALL) ||
2130 (($output_selection == OUTPUT_INCLUDE ||
2131 $output_selection == OUTPUT_EXPORTED) &&
2132 defined($function_table{$name})) ||
2133 (($output_selection == OUTPUT_EXCLUDE ||
2134 $output_selection == OUTPUT_INTERNAL) &&
2135 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002137 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 $section_counter++;
2139 }
2140}
2141
2142##
Randy Dunlap27205742006-10-11 01:22:12 -07002143# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002144sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002146 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 &$func(@_);
2148 $section_counter++;
2149}
2150
2151##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002152# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153# invokes the right handler. NOT called for functions.
2154sub dump_declaration($$) {
2155 no strict 'refs';
2156 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002157 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 &$func(@_);
2159}
2160
2161sub dump_union($$) {
2162 dump_struct(@_);
2163}
2164
2165sub dump_struct($$) {
2166 my $x = shift;
2167 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002168 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002170 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
Johannes Berg5cb5c312017-09-19 13:08:13 +02002171 my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002172 $declaration_name = $2;
2173 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
2175 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002176 $members =~ s/({.*})//g;
2177 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Martin Waitzaeec46b2005-11-13 16:08:13 -08002179 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002180 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2181 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002182 # strip comments:
2183 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002184 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002185 # strip kmemcheck_bitfield_{begin,end}.*;
2186 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002187 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002188 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002189 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002190 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002191 # replace DECLARE_BITMAP
2192 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Jakub Kicinski1cb566b2017-06-30 19:09:59 -07002193 # replace DECLARE_HASHTABLE
2194 $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002195
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 create_parameterlist($members, ';', $file);
Johannes Berg5cb5c312017-09-19 13:08:13 +02002197 check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198
2199 output_declaration($declaration_name,
2200 'struct',
2201 {'struct' => $declaration_name,
2202 'module' => $modulename,
2203 'parameterlist' => \@parameterlist,
2204 'parameterdescs' => \%parameterdescs,
2205 'parametertypes' => \%parametertypes,
2206 'sectionlist' => \@sectionlist,
2207 'sections' => \%sections,
2208 'purpose' => $declaration_purpose,
2209 'type' => $decl_type
2210 });
2211 }
2212 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002213 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 ++$errors;
2215 }
2216}
2217
2218sub dump_enum($$) {
2219 my $x = shift;
2220 my $file = shift;
2221
Martin Waitzaeec46b2005-11-13 16:08:13 -08002222 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002223 # strip #define macros inside enums
2224 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002225
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002227 $declaration_name = $1;
2228 my $members = $2;
Johannes Berg5cb5c312017-09-19 13:08:13 +02002229 my %_members;
2230
Markus Heiser463a0fd2017-06-16 21:27:48 +02002231 $members =~ s/\s+$//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
2233 foreach my $arg (split ',', $members) {
2234 $arg =~ s/^\s*(\w+).*/$1/;
2235 push @parameterlist, $arg;
2236 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002237 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002238 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 "not described in enum '$declaration_name'\n";
2240 }
Johannes Berg5cb5c312017-09-19 13:08:13 +02002241 $_members{$arg} = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002243
Johannes Berg5cb5c312017-09-19 13:08:13 +02002244 while (my ($k, $v) = each %parameterdescs) {
2245 if (!exists($_members{$k})) {
2246 print STDERR "${file}:$.: warning: Excess enum value " .
2247 "'$k' description in '$declaration_name'\n";
2248 }
2249 }
2250
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 output_declaration($declaration_name,
2252 'enum',
2253 {'enum' => $declaration_name,
2254 'module' => $modulename,
2255 'parameterlist' => \@parameterlist,
2256 'parameterdescs' => \%parameterdescs,
2257 'sectionlist' => \@sectionlist,
2258 'sections' => \%sections,
2259 'purpose' => $declaration_purpose
2260 });
2261 }
2262 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002263 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 ++$errors;
2265 }
2266}
2267
2268sub dump_typedef($$) {
2269 my $x = shift;
2270 my $file = shift;
2271
Martin Waitzaeec46b2005-11-13 16:08:13 -08002272 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002273
2274 # Parse function prototypes
Mauro Carvalho Chehabd37c43c2016-08-30 20:20:57 -03002275 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ ||
2276 $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) {
2277
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002278 # Function typedefs
2279 $return_type = $1;
2280 $declaration_name = $2;
2281 my $args = $3;
2282
2283 create_parameterlist($args, ',', $file);
2284
2285 output_declaration($declaration_name,
2286 'function',
2287 {'function' => $declaration_name,
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03002288 'typedef' => 1,
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002289 'module' => $modulename,
2290 'functiontype' => $return_type,
2291 'parameterlist' => \@parameterlist,
2292 'parameterdescs' => \%parameterdescs,
2293 'parametertypes' => \%parametertypes,
2294 'sectionlist' => \@sectionlist,
2295 'sections' => \%sections,
2296 'purpose' => $declaration_purpose
2297 });
2298 return;
2299 }
2300
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002302 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 $x =~ s/\[*.\]\s*;$/;/;
2304 }
2305
2306 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002307 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308
2309 output_declaration($declaration_name,
2310 'typedef',
2311 {'typedef' => $declaration_name,
2312 'module' => $modulename,
2313 'sectionlist' => \@sectionlist,
2314 'sections' => \%sections,
2315 'purpose' => $declaration_purpose
2316 });
2317 }
2318 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002319 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 ++$errors;
2321 }
2322}
2323
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002324sub save_struct_actual($) {
2325 my $actual = shift;
2326
2327 # strip all spaces from the actual param so that it looks like one string item
2328 $actual =~ s/\s*//g;
2329 $struct_actual = $struct_actual . $actual . " ";
2330}
2331
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332sub create_parameterlist($$$) {
2333 my $args = shift;
2334 my $splitter = shift;
2335 my $file = shift;
2336 my $type;
2337 my $param;
2338
Martin Waitza6d3fe72006-01-09 20:53:55 -08002339 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002341 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002343
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 foreach my $arg (split($splitter, $args)) {
2345 # strip comments
2346 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002347 # strip leading/trailing spaces
2348 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 $arg =~ s/\s*$//;
2350 $arg =~ s/\s+/ /;
2351
2352 if ($arg =~ /^#/) {
2353 # Treat preprocessor directive as a typeless variable just to fill
2354 # corresponding data structures "correctly". Catch it later in
2355 # output_* subs.
2356 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002357 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 # pointer-to-function
2359 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002360 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 $param = $1;
2362 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002363 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002364 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002366 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 $arg =~ s/\s*:\s*/:/g;
2368 $arg =~ s/\s*\[/\[/g;
2369
2370 my @args = split('\s*,\s*', $arg);
2371 if ($args[0] =~ m/\*/) {
2372 $args[0] =~ s/(\*+)\s*/ $1/;
2373 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002374
2375 my @first_arg;
2376 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2377 shift @args;
2378 push(@first_arg, split('\s+', $1));
2379 push(@first_arg, $2);
2380 } else {
2381 @first_arg = split('\s+', shift @args);
2382 }
2383
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 unshift(@args, pop @first_arg);
2385 $type = join " ", @first_arg;
2386
2387 foreach $param (@args) {
2388 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002389 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 push_parameter($2, "$type $1", $file);
2391 }
2392 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002393 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002394 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002395 push_parameter($1, "$type:$2", $file)
2396 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 }
2398 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002399 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 push_parameter($param, $type, $file);
2401 }
2402 }
2403 }
2404 }
2405}
2406
2407sub push_parameter($$$) {
2408 my $param = shift;
2409 my $type = shift;
2410 my $file = shift;
2411
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002412 if (($anon_struct_union == 1) && ($type eq "") &&
2413 ($param eq "}")) {
2414 return; # ignore the ending }; from anon. struct/union
2415 }
2416
2417 $anon_struct_union = 0;
Mauro Carvalho Chehabf9b5c532017-03-30 17:11:29 -03002418 $param =~ s/[\[\)].*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
Martin Waitza6d3fe72006-01-09 20:53:55 -08002420 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 {
Silvio Frickec950a172016-10-28 10:14:08 +02002422 if (!$param =~ /\w\.\.\.$/) {
2423 # handles unnamed variable parameters
2424 $param = "...";
2425 }
Randy Dunlapced69092008-12-01 13:14:03 -08002426 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2427 $parameterdescs{$param} = "variable arguments";
2428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 }
2430 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2431 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 $param="void";
2433 $parameterdescs{void} = "no arguments";
2434 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002435 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2436 # handle unnamed (anonymous) union or struct:
2437 {
2438 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002439 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002440 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002441 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002442 }
2443
Martin Waitza6d3fe72006-01-09 20:53:55 -08002444 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002445 # (but ignore ones starting with # as these are not parameters
2446 # but inline preprocessor statements);
2447 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002448 if (!$anon_struct_union) {
Mauro Carvalho Chehabf9b5c532017-03-30 17:11:29 -03002449 if (!defined $parameterdescs{$param} && $param !~ /^#/) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002450
Mauro Carvalho Chehabf9b5c532017-03-30 17:11:29 -03002451 $parameterdescs{$param} = $undescribed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452
2453 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002454 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 "or member '$param' not " .
2456 "described in '$declaration_name'\n";
2457 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002458 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002459 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002461 }
2462 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002464 $param = xml_escape($param);
2465
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002466 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002467 # on @parameterlist;
2468 # this fixes a problem where check_sections() cannot find
2469 # a parameter like "addr[6 + 2]" because it actually appears
2470 # as "addr[6", "+", "2]" on the parameter list;
2471 # but it's better to maintain the param string unchanged for output,
2472 # so just weaken the string compare in check_sections() to ignore
2473 # "[blah" in a parameter string;
2474 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 push @parameterlist, $param;
Paolo Bonzini02a4f4f2017-01-02 16:22:23 +01002476 $type =~ s/\s\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 $parametertypes{$param} = $type;
2478}
2479
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002480sub check_sections($$$$$$) {
2481 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2482 my @sects = split ' ', $sectcheck;
2483 my @prms = split ' ', $prmscheck;
2484 my $err;
2485 my ($px, $sx);
2486 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2487
2488 foreach $sx (0 .. $#sects) {
2489 $err = 1;
2490 foreach $px (0 .. $#prms) {
2491 $prm_clean = $prms[$px];
2492 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002493 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002494 # ignore array size in a parameter string;
2495 # however, the original param string may contain
2496 # spaces, e.g.: addr[6 + 2]
2497 # and this appears in @prms as "addr[6" since the
2498 # parameter list is split at spaces;
2499 # hence just ignore "[..." for the sections check;
2500 $prm_clean =~ s/\[.*//;
2501
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002502 ##$prm_clean =~ s/^\**//;
2503 if ($prm_clean eq $sects[$sx]) {
2504 $err = 0;
2505 last;
2506 }
2507 }
2508 if ($err) {
2509 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002510 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002511 "Excess function parameter " .
2512 "'$sects[$sx]' " .
2513 "description in '$decl_name'\n";
2514 ++$warnings;
2515 } else {
2516 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002517 print STDERR "${file}:$.: warning: " .
Johannes Berg5cb5c312017-09-19 13:08:13 +02002518 "Excess $decl_type member " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002519 "'$sects[$sx]' " .
2520 "description in '$decl_name'\n";
2521 ++$warnings;
2522 }
2523 }
2524 }
2525 }
2526}
2527
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002529# Checks the section describing the return value of a function.
2530sub check_return_section {
2531 my $file = shift;
2532 my $declaration_name = shift;
2533 my $return_type = shift;
2534
2535 # Ignore an empty return type (It's a macro)
2536 # Ignore functions with a "void" return type. (But don't ignore "void *")
2537 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2538 return;
2539 }
2540
2541 if (!defined($sections{$section_return}) ||
2542 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002543 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002544 "No description found for return value of " .
2545 "'$declaration_name'\n";
2546 ++$warnings;
2547 }
2548}
2549
2550##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551# takes a function prototype and the name of the current file being
2552# processed and spits out all the details stored in the global
2553# arrays/hashes.
2554sub dump_function($$) {
2555 my $prototype = shift;
2556 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002557 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558
2559 $prototype =~ s/^static +//;
2560 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002561 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 $prototype =~ s/^inline +//;
2563 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002564 $prototype =~ s/^__inline +//;
2565 $prototype =~ s/^__always_inline +//;
2566 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002567 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002568 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002569 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002570 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002571 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002572 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Paolo Bonzinib1aaa542017-01-02 16:22:24 +01002573 $prototype =~ s/__attribute__\s*\(\(
2574 (?:
2575 [\w\s]++ # attribute name
2576 (?:\([^)]*+\))? # attribute arguments
2577 \s*+,? # optional comma at the end
2578 )+
2579 \)\)\s+//x;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580
2581 # Yes, this truly is vile. We are looking for:
2582 # 1. Return type (may be nothing if we're looking at a macro)
2583 # 2. Function name
2584 # 3. Function parameters.
2585 #
2586 # All the while we have to watch out for function pointer parameters
2587 # (which IIRC is what the two sections are for), C types (these
2588 # regexps don't even start to express all the possibilities), and
2589 # so on.
2590 #
2591 # If you mess with these regexps, it's a good idea to check that
2592 # the following functions' documentation still comes out right:
2593 # - parport_register_device (function pointer parameters)
2594 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002595 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002597 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2598 # This is an object-like macro, it has no return type and no parameter
2599 # list.
2600 # Function-like macros are not allowed to have spaces between
2601 # declaration_name and opening parenthesis (notice the \s+).
2602 $return_type = $1;
2603 $declaration_name = $2;
2604 $noret = 1;
2605 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08002607 $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002609 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08002611 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2613 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08002614 $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08002616 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08002618 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002619 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Matthew Wilcox5a0bc572017-01-23 00:18:10 -08002620 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2621 $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 $return_type = $1;
2623 $declaration_name = $2;
2624 my $args = $3;
2625
2626 create_parameterlist($args, ',', $file);
2627 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002628 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 return;
2630 }
2631
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002632 my $prms = join " ", @parameterlist;
2633 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2634
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002635 # This check emits a lot of warnings at the moment, because many
2636 # functions don't have a 'Return' doc section. So until the number
2637 # of warnings goes sufficiently down, the check is only performed in
2638 # verbose mode.
2639 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002640 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002641 check_return_section($file, $declaration_name, $return_type);
2642 }
2643
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002644 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 'function',
2646 {'function' => $declaration_name,
2647 'module' => $modulename,
2648 'functiontype' => $return_type,
2649 'parameterlist' => \@parameterlist,
2650 'parameterdescs' => \%parameterdescs,
2651 'parametertypes' => \%parametertypes,
2652 'sectionlist' => \@sectionlist,
2653 'sections' => \%sections,
2654 'purpose' => $declaration_purpose
2655 });
2656}
2657
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658sub reset_state {
2659 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 %parameterdescs = ();
2661 %parametertypes = ();
2662 @parameterlist = ();
2663 %sections = ();
2664 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002665 $sectcheck = "";
2666 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002668
Jani Nikula48af6062016-05-26 14:56:05 +03002669 $state = STATE_NORMAL;
2670 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671}
2672
Jason Baron56afb0f2009-04-30 13:29:36 -04002673sub tracepoint_munge($) {
2674 my $file = shift;
2675 my $tracepointname = 0;
2676 my $tracepointargs = 0;
2677
Jason Baron3a9089f2009-12-01 12:18:49 -05002678 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002679 $tracepointname = $1;
2680 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002681 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2682 $tracepointname = $1;
2683 }
2684 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2685 $tracepointname = $2;
2686 }
2687 $tracepointname =~ s/^\s+//; #strip leading whitespace
2688 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002689 $tracepointargs = $1;
2690 }
2691 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002692 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002693 "$prototype\n";
2694 } else {
2695 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2696 }
2697}
2698
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002699sub syscall_munge() {
2700 my $void = 0;
2701
2702 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2703## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2704 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2705 $void = 1;
2706## $prototype = "long sys_$1(void)";
2707 }
2708
2709 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2710 if ($prototype =~ m/long (sys_.*?),/) {
2711 $prototype =~ s/,/\(/;
2712 } elsif ($void) {
2713 $prototype =~ s/\)/\(void\)/;
2714 }
2715
2716 # now delete all of the odd-number commas in $prototype
2717 # so that arg types & arg names don't have a comma between them
2718 my $count = 0;
2719 my $len = length($prototype);
2720 if ($void) {
2721 $len = 0; # skip the for-loop
2722 }
2723 for (my $ix = 0; $ix < $len; $ix++) {
2724 if (substr($prototype, $ix, 1) eq ',') {
2725 $count++;
2726 if ($count % 2 == 1) {
2727 substr($prototype, $ix, 1) = ' ';
2728 }
2729 }
2730 }
2731}
2732
Daniel Vetterb7afa922016-06-01 23:46:24 +02002733sub process_proto_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 my $x = shift;
2735 my $file = shift;
2736
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002737 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2738
Randy Dunlap890c78c2008-10-25 17:06:43 -07002739 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 # do nothing
2741 }
2742 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002743 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002744 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002745
Randy Dunlap890c78c2008-10-25 17:06:43 -07002746 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002747 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2749 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002750 if ($prototype =~ /SYSCALL_DEFINE/) {
2751 syscall_munge();
2752 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002753 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2754 $prototype =~ /DEFINE_SINGLE_EVENT/)
2755 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002756 tracepoint_munge($file);
2757 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002758 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 reset_state();
2760 }
2761}
2762
Daniel Vetterb7afa922016-06-01 23:46:24 +02002763sub process_proto_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 my $x = shift;
2765 my $file = shift;
2766
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2768 $x =~ s@^\s+@@gos; # strip leading spaces
2769 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002770 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2771
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 if ($x =~ /^#/) {
2773 # To distinguish preprocessor directive from regular declaration later.
2774 $x .= ";";
2775 }
2776
2777 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002778 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Markus Heiser463a0fd2017-06-16 21:27:48 +02002779 if( length $prototype ) {
2780 $prototype .= " "
2781 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 $prototype .= $1 . $2;
2783 ($2 eq '{') && $brcount++;
2784 ($2 eq '}') && $brcount--;
2785 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002786 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002788 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 }
2790 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002791 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 $prototype .= $x;
2793 last;
2794 }
2795 }
2796}
2797
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002798# xml_escape: replace <, >, and & in the text stream;
2799#
2800# however, formatting controls that are generated internally/locally in the
2801# kernel-doc script are not escaped here; instead, they begin life like
2802# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2803# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2804# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805sub xml_escape($) {
2806 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002807 if (($output_mode eq "text") || ($output_mode eq "man")) {
2808 return $text;
2809 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 $text =~ s/\&/\\\\\\amp;/g;
2811 $text =~ s/\</\\\\\\lt;/g;
2812 $text =~ s/\>/\\\\\\gt;/g;
2813 return $text;
2814}
2815
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002816# xml_unescape: reverse the effects of xml_escape
2817sub xml_unescape($) {
2818 my $text = shift;
2819 if (($output_mode eq "text") || ($output_mode eq "man")) {
2820 return $text;
2821 }
2822 $text =~ s/\\\\\\amp;/\&/g;
2823 $text =~ s/\\\\\\lt;/</g;
2824 $text =~ s/\\\\\\gt;/>/g;
2825 return $text;
2826}
2827
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002828# convert local escape strings to html
2829# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2830sub local_unescape($) {
2831 my $text = shift;
2832 if (($output_mode eq "text") || ($output_mode eq "man")) {
2833 return $text;
2834 }
2835 $text =~ s/\\\\\\\\lt:/</g;
2836 $text =~ s/\\\\\\\\gt:/>/g;
2837 return $text;
2838}
2839
Jani Nikula1ad560e2016-06-07 10:53:39 +03002840sub map_filename($) {
2841 my $file;
2842 my ($orig_file) = @_;
2843
2844 if (defined($ENV{'SRCTREE'})) {
2845 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
2846 } else {
2847 $file = $orig_file;
2848 }
2849
2850 if (defined($source_map{$file})) {
2851 $file = $source_map{$file};
2852 }
2853
2854 return $file;
2855}
2856
Jani Nikula88c2b572016-06-07 11:00:52 +03002857sub process_export_file($) {
2858 my ($orig_file) = @_;
2859 my $file = map_filename($orig_file);
2860
2861 if (!open(IN,"<$file")) {
2862 print STDERR "Error: Cannot open file $file\n";
2863 ++$errors;
2864 return;
2865 }
2866
2867 while (<IN>) {
2868 if (/$export_symbol/) {
2869 $function_table{$2} = 1;
2870 }
2871 }
2872
2873 close(IN);
2874}
2875
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002877 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 my $identifier;
2879 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002880 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002881 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002883 my ($orig_file) = @_;
Jani Nikulab7886de2016-05-28 00:41:50 +03002884 my $leading_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885
Jani Nikula1ad560e2016-06-07 10:53:39 +03002886 $file = map_filename($orig_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887
2888 if (!open(IN,"<$file")) {
2889 print STDERR "Error: Cannot open file $file\n";
2890 ++$errors;
2891 return;
2892 }
2893
Ilya Dryomova9e73142010-02-26 13:05:47 -08002894 $. = 1;
2895
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 $section_counter = 0;
2897 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002898 while (s/\\\s*$//) {
2899 $_ .= <IN>;
2900 }
Jani Nikula48af6062016-05-26 14:56:05 +03002901 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002903 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002904 $in_doc_sect = 0;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002905 $declaration_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 }
Jani Nikula48af6062016-05-26 14:56:05 +03002907 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002909 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002911 $new_start_line = $. + 1;
2912
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 if ( $1 eq "" ) {
2914 $section = $section_intro;
2915 } else {
2916 $section = $1;
2917 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002918 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 elsif (/$doc_decl/o) {
2920 $identifier = $1;
2921 if (/\s*([\w\s]+?)\s*-/) {
2922 $identifier = $1;
2923 }
2924
Jani Nikula48af6062016-05-26 14:56:05 +03002925 $state = STATE_FIELD;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002926 # if there's no @param blocks need to set up default section
2927 # here
Jani Nikula2f4ad402016-05-30 11:21:06 +03002928 $contents = "";
2929 $section = $section_default;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002930 $new_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002932 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002933 $descr= $1;
2934 $descr =~ s/^\s*//;
2935 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002936 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002937 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002938 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 } else {
2940 $declaration_purpose = "";
2941 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002942
2943 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002944 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002945 print STDERR $_;
2946 ++$warnings;
2947 }
2948
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 if ($identifier =~ m/^struct/) {
2950 $decl_type = 'struct';
2951 } elsif ($identifier =~ m/^union/) {
2952 $decl_type = 'union';
2953 } elsif ($identifier =~ m/^enum/) {
2954 $decl_type = 'enum';
2955 } elsif ($identifier =~ m/^typedef/) {
2956 $decl_type = 'typedef';
2957 } else {
2958 $decl_type = 'function';
2959 }
2960
2961 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002962 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 }
2964 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002965 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 " - I thought it was a doc line\n";
2967 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002968 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 }
Jani Nikula48af6062016-05-26 14:56:05 +03002970 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Jani Nikulaf624ade2016-05-29 11:35:28 +03002971 if (/$doc_sect/i) { # case insensitive for supported section names
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 $newsection = $1;
2973 $newcontents = $2;
2974
Jani Nikulaf624ade2016-05-29 11:35:28 +03002975 # map the supported section names to the canonical names
2976 if ($newsection =~ m/^description$/i) {
2977 $newsection = $section_default;
2978 } elsif ($newsection =~ m/^context$/i) {
2979 $newsection = $section_context;
2980 } elsif ($newsection =~ m/^returns?$/i) {
2981 $newsection = $section_return;
2982 } elsif ($newsection =~ m/^\@return$/) {
2983 # special: @return is a section, not a param description
2984 $newsection = $section_return;
2985 }
2986
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002987 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002988 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002989 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002990 ++$warnings;
2991 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002992 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 $section = $section_default;
2994 }
2995
Randy Dunlap850622d2006-06-25 05:48:55 -07002996 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002997 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 $contents = $newcontents;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002999 $new_start_line = $.;
Jani Nikula0a726302016-05-28 14:50:20 +03003000 while ((substr($contents, 0, 1) eq " ") ||
3001 substr($contents, 0, 1) eq "\t") {
3002 $contents = substr($contents, 1);
3003 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 if ($contents ne "") {
3005 $contents .= "\n";
3006 }
3007 $section = $newsection;
Jani Nikulab7886de2016-05-28 00:41:50 +03003008 $leading_space = undef;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08003010 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07003011 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 $section = $section_default;
3013 $contents = "";
3014 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07003015 # look for doc_com + <text> + doc_end:
3016 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07003017 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07003018 ++$warnings;
3019 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020
3021 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03003022 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07003024# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 } elsif (/$doc_content/) {
3026 # miguel-style comment kludge, look for blank lines after
3027 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07003028 if ($1 eq "") {
3029 if ($section =~ m/^@/ || $section eq $section_context) {
3030 dump_section($file, $section, xml_escape($contents));
3031 $section = $section_default;
3032 $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02003033 $new_start_line = $.;
Johannes Weiner64231332009-09-17 19:26:53 -07003034 } else {
3035 $contents .= "\n";
3036 }
3037 $in_purpose = 0;
3038 } elsif ($in_purpose == 1) {
3039 # Continued declaration purpose
3040 chomp($declaration_purpose);
3041 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07003042 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 } else {
Jani Nikulab7886de2016-05-28 00:41:50 +03003044 my $cont = $1;
3045 if ($section =~ m/^@/ || $section eq $section_context) {
3046 if (!defined $leading_space) {
3047 if ($cont =~ m/^(\s+)/) {
3048 $leading_space = $1;
3049 } else {
3050 $leading_space = "";
3051 }
3052 }
3053
3054 $cont =~ s/^$leading_space//;
3055 }
3056 $contents .= $cont . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 }
3058 } else {
3059 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07003060 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 ++$warnings;
3062 }
Jani Nikula48af6062016-05-26 14:56:05 +03003063 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003064 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03003065 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003066 $section = $1;
3067 $contents = $2;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02003068 $new_start_line = $.;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003069 if ($contents ne "") {
3070 while ((substr($contents, 0, 1) eq " ") ||
3071 substr($contents, 0, 1) eq "\t") {
3072 $contents = substr($contents, 1);
3073 }
Jani Nikulaa0b96c22016-05-26 22:04:06 +03003074 $contents .= "\n";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003075 }
Jani Nikula48af6062016-05-26 14:56:05 +03003076 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003077 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03003078 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003079 if (($contents ne "") && ($contents ne "\n")) {
3080 dump_section($file, $section, xml_escape($contents));
3081 $section = $section_default;
3082 $contents = "";
3083 }
Jani Nikula48af6062016-05-26 14:56:05 +03003084 $state = STATE_PROTO;
3085 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003086 # Regular text
3087 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03003088 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003089 $contents .= $1 . "\n";
Jani Nikula6450c892016-05-26 22:04:42 +03003090 # nuke leading blank lines
3091 if ($contents =~ /^\s*$/) {
3092 $contents = "";
3093 }
Jani Nikula48af6062016-05-26 14:56:05 +03003094 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
3095 $inline_doc_state = STATE_INLINE_ERROR;
Daniel Vettere7ca3112016-07-15 10:19:30 +02003096 print STDERR "${file}:$.: warning: ";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003097 print STDERR "Incorrect use of kernel-doc format: $_";
3098 ++$warnings;
3099 }
3100 }
Jani Nikula48af6062016-05-26 14:56:05 +03003101 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
Jani Nikula0c9aa202016-11-16 17:26:16 +02003102 if (/$doc_inline_oneline/) {
3103 $section = $1;
3104 $contents = $2;
3105 if ($contents ne "") {
3106 $contents .= "\n";
3107 dump_section($file, $section, xml_escape($contents));
3108 $section = $section_default;
3109 $contents = "";
3110 }
3111 } elsif (/$doc_inline_start/) {
Jani Nikula48af6062016-05-26 14:56:05 +03003112 $state = STATE_INLINE;
3113 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003114 } elsif ($decl_type eq 'function') {
Daniel Vetterb7afa922016-06-01 23:46:24 +02003115 process_proto_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116 } else {
Daniel Vetterb7afa922016-06-01 23:46:24 +02003117 process_proto_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003118 }
Jani Nikula48af6062016-05-26 14:56:05 +03003119 } elsif ($state == STATE_DOCBLOCK) {
Daniel Vetterebff7f92016-06-01 23:46:23 +02003120 if (/$doc_end/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07003122 dump_doc_section($file, $section, xml_escape($contents));
Jani Nikula2f4ad402016-05-30 11:21:06 +03003123 $section = $section_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 $contents = "";
3125 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 %parameterdescs = ();
3127 %parametertypes = ();
3128 @parameterlist = ();
3129 %sections = ();
3130 @sectionlist = ();
3131 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03003132 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 }
3134 elsif (/$doc_content/)
3135 {
3136 if ( $1 eq "" )
3137 {
3138 $contents .= $blankline;
3139 }
3140 else
3141 {
3142 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08003143 }
Randy Dunlap3c308792007-05-08 00:24:39 -07003144 }
3145 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 }
3147 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07003148 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03003149 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08003150 print STDERR " Was looking for '$_'.\n" for keys %function_table;
3151 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 if ($output_mode eq "xml") {
3153 # The template wants at least one RefEntry here; make one.
3154 print "<refentry>\n";
3155 print " <refnamediv>\n";
3156 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003157 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 print " </refname>\n";
3159 print " <refpurpose>\n";
3160 print " Document generation inconsistency\n";
3161 print " </refpurpose>\n";
3162 print " </refnamediv>\n";
3163 print " <refsect1>\n";
3164 print " <title>\n";
3165 print " Oops\n";
3166 print " </title>\n";
3167 print " <warning>\n";
3168 print " <para>\n";
3169 print " The template for this document tried to insert\n";
3170 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003171 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 print " but none was found.\n";
3173 print " This dummy section is inserted to allow\n";
3174 print " generation to continue.\n";
3175 print " </para>\n";
3176 print " </warning>\n";
3177 print " </refsect1>\n";
3178 print "</refentry>\n";
3179 }
3180 }
3181}
Randy Dunlap8484baa2011-01-05 16:28:43 -08003182
3183
3184$kernelversion = get_kernel_version();
3185
3186# generate a sequence of code that will splice in highlighting information
3187# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02003188for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03003189 my $pattern = $highlights[$k][0];
3190 my $result = $highlights[$k][1];
3191# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
3192 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08003193}
3194
3195# Read the file that maps relative names to absolute names for
3196# separate source and object directories and for shadow trees.
3197if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3198 my ($relname, $absname);
3199 while(<SOURCE_MAP>) {
3200 chop();
3201 ($relname, $absname) = (split())[0..1];
3202 $relname =~ s:^/+::;
3203 $source_map{$relname} = $absname;
3204 }
3205 close(SOURCE_MAP);
3206}
3207
Jani Nikula88c2b572016-06-07 11:00:52 +03003208if ($output_selection == OUTPUT_EXPORTED ||
3209 $output_selection == OUTPUT_INTERNAL) {
Jani Nikulac9b2cfb2016-06-07 11:05:53 +03003210
3211 push(@export_file_list, @ARGV);
3212
Jani Nikula88c2b572016-06-07 11:00:52 +03003213 foreach (@export_file_list) {
3214 chomp;
3215 process_export_file($_);
3216 }
3217}
3218
Randy Dunlap8484baa2011-01-05 16:28:43 -08003219foreach (@ARGV) {
3220 chomp;
3221 process_file($_);
3222}
3223if ($verbose && $errors) {
3224 print STDERR "$errors errors\n";
3225}
3226if ($verbose && $warnings) {
3227 print STDERR "$warnings warnings\n";
3228}
3229
3230exit($errors);