blob: 6e4454b3ca82e216208b45eebca90a1d99fd3867 [file] [log] [blame]
Rob Herring7a5277a2017-01-04 10:45:20 -06001#!/usr/bin/env perl
Linus Torvalds1da177e2005-04-16 15:20:36 -07002
Rob Herring7a5277a2017-01-04 10:45:20 -06003use 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 Vetter0b0f5f22016-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')
203# '@parameter' - name of a parameter
204# '%CONST' - name of a constant.
205
Randy Dunlap8484baa2011-01-05 16:28:43 -0800206## init lots of data
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208my $errors = 0;
209my $warnings = 0;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -0700210my $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212# match expressions used to find embedded type information
213my $type_constant = '\%([-_\w]+)';
214my $type_func = '(\w+)\(\)';
215my $type_param = '\@(\w+)';
Jonathan Corbet5219f182016-08-24 16:31:15 -0600216my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700217my $type_struct = '\&((struct\s*)*[_\w]+)';
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700218my $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219my $type_env = '(\$\w+)';
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300220my $type_enum_full = '\&(enum)\s*([_\w]+)';
221my $type_struct_full = '\&(struct)\s*([_\w]+)';
Jani Nikula47ae7ae2016-05-26 13:57:18 +0300222my $type_typedef_full = '\&(typedef)\s*([_\w]+)';
223my $type_union_full = '\&(union)\s*([_\w]+)';
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300224my $type_member = '\&([_\w]+)((\.|->)[_\w]+)';
225my $type_member_func = $type_member . '\(\)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227# Output conversion substitutions.
228# One for each output format
229
230# these work fairly well
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300231my @highlights_html = (
232 [$type_constant, "<i>\$1</i>"],
233 [$type_func, "<b>\$1</b>"],
234 [$type_struct_xml, "<i>\$1</i>"],
235 [$type_env, "<b><i>\$1</i></b>"],
236 [$type_param, "<tt><b>\$1</b></tt>"]
237 );
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700238my $local_lt = "\\\\\\\\lt:";
239my $local_gt = "\\\\\\\\gt:";
240my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
Dan Luedtke1b40c192012-08-12 10:46:15 +0200242# html version 5
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300243my @highlights_html5 = (
244 [$type_constant, "<span class=\"const\">\$1</span>"],
245 [$type_func, "<span class=\"func\">\$1</span>"],
246 [$type_struct_xml, "<span class=\"struct\">\$1</span>"],
247 [$type_env, "<span class=\"env\">\$1</span>"],
248 [$type_param, "<span class=\"param\">\$1</span>]"]
249 );
Dan Luedtke1b40c192012-08-12 10:46:15 +0200250my $blankline_html5 = $local_lt . "br /" . $local_gt;
251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252# XML, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300253my @highlights_xml = (
254 ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
255 [$type_constant, "<constant>\$1</constant>"],
256 [$type_struct_xml, "<structname>\$1</structname>"],
257 [$type_param, "<parameter>\$1</parameter>"],
258 [$type_func, "<function>\$1</function>"],
259 [$type_env, "<envar>\$1</envar>"]
260 );
Johannes Berg5c98fc02007-10-24 15:08:48 -0700261my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263# gnome, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300264my @highlights_gnome = (
265 [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
266 [$type_func, "<function>\$1</function>"],
267 [$type_struct, "<structname>\$1</structname>"],
268 [$type_env, "<envar>\$1</envar>"],
269 [$type_param, "<parameter>\$1</parameter>" ]
270 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271my $blankline_gnome = "</para><para>\n";
272
273# these are pretty rough
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300274my @highlights_man = (
275 [$type_constant, "\$1"],
276 [$type_func, "\\\\fB\$1\\\\fP"],
277 [$type_struct, "\\\\fI\$1\\\\fP"],
278 [$type_param, "\\\\fI\$1\\\\fP"]
279 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280my $blankline_man = "";
281
282# text-mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300283my @highlights_text = (
284 [$type_constant, "\$1"],
285 [$type_func, "\$1"],
286 [$type_struct, "\$1"],
287 [$type_param, "\$1"]
288 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289my $blankline_text = "";
290
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300291# rst-mode
292my @highlights_rst = (
293 [$type_constant, "``\$1``"],
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300294 # Note: need to escape () to avoid func matching later
295 [$type_member_func, "\\:c\\:type\\:`\$1\$2\\\\(\\\\) <\$1>`"],
296 [$type_member, "\\:c\\:type\\:`\$1\$2 <\$1>`"],
Jonathan Corbet5219f182016-08-24 16:31:15 -0600297 [$type_fp_param, "**\$1\\\\(\\\\)**"],
Jani Nikulaa19bce62016-05-26 11:28:16 +0300298 [$type_func, "\\:c\\:func\\:`\$1()`"],
Jani Nikula62850972016-05-12 16:15:38 +0300299 [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
300 [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
Jani Nikula47ae7ae2016-05-26 13:57:18 +0300301 [$type_typedef_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
302 [$type_union_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
Jani Nikulaa7291e72016-05-26 13:57:06 +0300303 # in rst this can refer to any type
304 [$type_struct, "\\:c\\:type\\:`\$1`"],
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300305 [$type_param, "**\$1**"]
306 );
307my $blankline_rst = "\n";
308
Johannes Bergeda603f2010-09-11 15:55:22 -0700309# list mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300310my @highlights_list = (
311 [$type_constant, "\$1"],
312 [$type_func, "\$1"],
313 [$type_struct, "\$1"],
314 [$type_param, "\$1"]
315 );
Johannes Bergeda603f2010-09-11 15:55:22 -0700316my $blankline_list = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318# read arguments
Randy Dunlapb9d973282009-06-09 08:50:38 -0700319if ($#ARGV == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 usage();
321}
322
Randy Dunlap8484baa2011-01-05 16:28:43 -0800323my $kernelversion;
324my $dohighlight = "";
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326my $verbose = 0;
327my $output_mode = "man";
Daniel Santose314ba32012-10-04 17:15:08 -0700328my $output_preformatted = 0;
Johannes Berg4b445952007-10-24 15:08:48 -0700329my $no_doc_sections = 0;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200330my $enable_lineno = 0;
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300331my @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332my $blankline = $blankline_man;
333my $modulename = "Kernel API";
Jani Nikulab6c3f452016-05-29 22:19:35 +0300334
335use constant {
336 OUTPUT_ALL => 0, # output all symbols and doc sections
337 OUTPUT_INCLUDE => 1, # output only specified symbols
338 OUTPUT_EXCLUDE => 2, # output everything except specified symbols
339 OUTPUT_EXPORTED => 3, # output exported symbols
340 OUTPUT_INTERNAL => 4, # output non-exported symbols
341};
342my $output_selection = OUTPUT_ALL;
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100343my $show_not_found = 0;
344
Jani Nikula88c2b572016-06-07 11:00:52 +0300345my @export_file_list;
346
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100347my @build_time;
348if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
349 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
350 @build_time = gmtime($seconds);
351} else {
352 @build_time = localtime;
353}
354
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800355my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
356 'July', 'August', 'September', 'October',
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100357 'November', 'December')[$build_time[4]] .
358 " " . ($build_time[5]+1900);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Randy Dunlap8484baa2011-01-05 16:28:43 -0800360# Essentially these are globals.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700361# They probably want to be tidied up, made more localised or something.
362# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363# could cause "use of undefined value" or other bugs.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700364my ($function, %function_table, %parametertypes, $declaration_purpose);
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200365my $declaration_start_line;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700366my ($type, $declaration_name, $return_type);
Ilya Dryomov1c32fd02010-02-26 13:06:03 -0800367my ($newsection, $newcontents, $prototype, $brcount, %source_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700369if (defined($ENV{'KBUILD_VERBOSE'})) {
370 $verbose = "$ENV{'KBUILD_VERBOSE'}";
371}
372
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800373# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
375# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
376# We keep track of number of generated entries and generate a dummy
377# if needs be to ensure the expanded template can be postprocessed
378# into html.
379my $section_counter = 0;
380
381my $lineprefix="";
382
Jani Nikula48af6062016-05-26 14:56:05 +0300383# Parser states
384use constant {
385 STATE_NORMAL => 0, # normal code
386 STATE_NAME => 1, # looking for function name
387 STATE_FIELD => 2, # scanning field start
388 STATE_PROTO => 3, # scanning prototype
389 STATE_DOCBLOCK => 4, # documentation block
390 STATE_INLINE => 5, # gathering documentation outside main block
391};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700393my $in_doc_sect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Jani Nikula48af6062016-05-26 14:56:05 +0300395# Inline documentation state
396use constant {
397 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
398 STATE_INLINE_NAME => 1, # looking for member name (@foo:)
399 STATE_INLINE_TEXT => 2, # looking for member documentation
400 STATE_INLINE_END => 3, # done
401 STATE_INLINE_ERROR => 4, # error - Comment without header was found.
402 # Spit a warning as it's not
403 # proper kernel-doc and ignore the rest.
404};
405my $inline_doc_state;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407#declaration types: can be
408# 'function', 'struct', 'union', 'enum', 'typedef'
409my $decl_type;
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
412my $doc_end = '\*/';
413my $doc_com = '\s*\*\s*';
Daniel Santos12ae6772012-10-04 17:15:10 -0700414my $doc_com_body = '\s*\* ?';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700415my $doc_decl = $doc_com . '(\w+)';
Jani Nikulaf624ade2016-05-29 11:35:28 +0300416# @params and a strictly limited set of supported section names
Jonathan Corbet8569de62016-06-09 13:35:05 -0600417my $doc_sect = $doc_com .
Jonathan Corbetef000282016-08-26 07:14:08 -0600418 '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700419my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700420my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Jani Nikula48af6062016-05-26 14:56:05 +0300421my $doc_inline_start = '^\s*/\*\*\s*$';
422my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
423my $doc_inline_end = '^\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200424my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426my %parameterdescs;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200427my %parameterdesc_start_lines;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428my @parameterlist;
429my %sections;
430my @sectionlist;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200431my %section_start_lines;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800432my $sectcheck;
433my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435my $contents = "";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200436my $new_start_line = 0;
Jani Nikulaf624ade2016-05-29 11:35:28 +0300437
438# the canonical section names. see also $doc_sect above.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439my $section_default = "Description"; # default section
440my $section_intro = "Introduction";
441my $section = $section_default;
442my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100443my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
445my $undescribed = "-- undescribed --";
446
447reset_state();
448
449while ($ARGV[0] =~ m/^-(.*)/) {
450 my $cmd = shift @ARGV;
451 if ($cmd eq "-html") {
452 $output_mode = "html";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300453 @highlights = @highlights_html;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200455 } elsif ($cmd eq "-html5") {
456 $output_mode = "html5";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300457 @highlights = @highlights_html5;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200458 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 } elsif ($cmd eq "-man") {
460 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300461 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 $blankline = $blankline_man;
463 } elsif ($cmd eq "-text") {
464 $output_mode = "text";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300465 @highlights = @highlights_text;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 $blankline = $blankline_text;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300467 } elsif ($cmd eq "-rst") {
468 $output_mode = "rst";
469 @highlights = @highlights_rst;
470 $blankline = $blankline_rst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 } elsif ($cmd eq "-docbook") {
472 $output_mode = "xml";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300473 @highlights = @highlights_xml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700475 } elsif ($cmd eq "-list") {
476 $output_mode = "list";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300477 @highlights = @highlights_list;
Johannes Bergeda603f2010-09-11 15:55:22 -0700478 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 } elsif ($cmd eq "-gnome") {
480 $output_mode = "gnome";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300481 @highlights = @highlights_gnome;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 $blankline = $blankline_gnome;
483 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
484 $modulename = shift @ARGV;
485 } elsif ($cmd eq "-function") { # to only output specific functions
Jani Nikulab6c3f452016-05-29 22:19:35 +0300486 $output_selection = OUTPUT_INCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 $function = shift @ARGV;
488 $function_table{$function} = 1;
Jani Nikulab6c3f452016-05-29 22:19:35 +0300489 } elsif ($cmd eq "-nofunction") { # output all except specific functions
490 $output_selection = OUTPUT_EXCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 $function = shift @ARGV;
492 $function_table{$function} = 1;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200493 } elsif ($cmd eq "-export") { # only exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300494 $output_selection = OUTPUT_EXPORTED;
Jani Nikulada9726e2016-06-07 10:29:59 +0300495 %function_table = ();
Jani Nikula86ae2e32016-01-21 13:05:22 +0200496 } elsif ($cmd eq "-internal") { # only non-exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300497 $output_selection = OUTPUT_INTERNAL;
Jani Nikulada9726e2016-06-07 10:29:59 +0300498 %function_table = ();
Jani Nikula88c2b572016-06-07 11:00:52 +0300499 } elsif ($cmd eq "-export-file") {
500 my $file = shift @ARGV;
501 push(@export_file_list, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 } elsif ($cmd eq "-v") {
503 $verbose = 1;
504 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
505 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700506 } elsif ($cmd eq '-no-doc-sections') {
507 $no_doc_sections = 1;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200508 } elsif ($cmd eq '-enable-lineno') {
509 $enable_lineno = 1;
Johannes Berge946c43a2013-11-12 15:11:12 -0800510 } elsif ($cmd eq '-show-not-found') {
511 $show_not_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 }
513}
514
Randy Dunlap8484baa2011-01-05 16:28:43 -0800515# continue execution near EOF;
516
Borislav Petkov53f049f2007-05-08 00:30:54 -0700517# get kernel version from env
518sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700519 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700520
521 if (defined($ENV{'KERNELVERSION'})) {
522 $version = $ENV{'KERNELVERSION'};
523 }
524 return $version;
525}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200527#
528sub print_lineno {
529 my $lineno = shift;
530 if ($enable_lineno && defined($lineno)) {
531 print "#define LINENO " . $lineno . "\n";
532 }
533}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534##
535# dumps section contents to arrays/hashes intended for that purpose.
536#
537sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700538 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 my $name = shift;
540 my $contents = join "\n", @_;
541
Jani Nikula13901ef2016-05-26 08:57:29 +0300542 if ($name =~ m/$type_param/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 $name = $1;
544 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800545 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200546 $parameterdesc_start_lines{$name} = $new_start_line;
547 $new_start_line = 0;
Randy Dunlapced69092008-12-01 13:14:03 -0800548 } elsif ($name eq "@\.\.\.") {
Randy Dunlapced69092008-12-01 13:14:03 -0800549 $name = "...";
550 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800551 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200552 $parameterdesc_start_lines{$name} = $new_start_line;
553 $new_start_line = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 } else {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700555 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Jani Nikula95b6be92016-06-10 11:14:05 +0300556 # Only warn on user specified duplicate section names.
557 if ($name ne $section_default) {
558 print STDERR "${file}:$.: warning: duplicate section name '$name'\n";
559 ++$warnings;
560 }
Jani Nikula32217762016-05-29 09:40:44 +0300561 $sections{$name} .= $contents;
562 } else {
563 $sections{$name} = $contents;
564 push @sectionlist, $name;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200565 $section_start_lines{$name} = $new_start_line;
566 $new_start_line = 0;
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700567 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 }
569}
570
571##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700572# dump DOC: section after checking that it should go out
573#
574sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700575 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700576 my $name = shift;
577 my $contents = join "\n", @_;
578
Johannes Berg4b445952007-10-24 15:08:48 -0700579 if ($no_doc_sections) {
580 return;
581 }
582
Jani Nikulab6c3f452016-05-29 22:19:35 +0300583 if (($output_selection == OUTPUT_ALL) ||
584 ($output_selection == OUTPUT_INCLUDE &&
585 defined($function_table{$name})) ||
586 ($output_selection == OUTPUT_EXCLUDE &&
587 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700588 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700589 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700590 output_blockhead({'sectionlist' => \@sectionlist,
591 'sections' => \%sections,
592 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300593 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700594 }
595}
596
597##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598# output function
599#
600# parameterdescs, a hash.
601# function => "function name"
602# parameterlist => @list of parameters
603# parameterdescs => %parameter descriptions
604# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800605# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800606#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
608sub output_highlight {
609 my $contents = join "\n",@_;
610 my $line;
611
612# DEBUG
613# if (!defined $contents) {
614# use Carp;
615# confess "output_highlight got called with no args?\n";
616# }
617
Dan Luedtke1b40c192012-08-12 10:46:15 +0200618 if ($output_mode eq "html" || $output_mode eq "html5" ||
619 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700620 $contents = local_unescape($contents);
621 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800622 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700623 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700624# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 eval $dohighlight;
626 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700627# print STDERR "contents af:$contents\n";
628
Dan Luedtke1b40c192012-08-12 10:46:15 +0200629# strip whitespaces when generating html5
630 if ($output_mode eq "html5") {
631 $contents =~ s/^\s+//;
632 $contents =~ s/\s+$//;
633 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700635 if (! $output_preformatted) {
636 $line =~ s/^\s*//;
637 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700638 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700639 if (! $output_preformatted) {
640 print $lineprefix, local_unescape($blankline);
641 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700643 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700644 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
645 print "\\&$line";
646 } else {
647 print $lineprefix, $line;
648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
650 print "\n";
651 }
652}
653
Dan Luedtke1b40c192012-08-12 10:46:15 +0200654# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655sub output_section_html(%) {
656 my %args = %{$_[0]};
657 my $section;
658
659 foreach $section (@{$args{'sectionlist'}}) {
660 print "<h3>$section</h3>\n";
661 print "<blockquote>\n";
662 output_highlight($args{'sections'}{$section});
663 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800664 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665}
666
667# output enum in html
668sub output_enum_html(%) {
669 my %args = %{$_[0]};
670 my ($parameter);
671 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700672 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Randy Dunlapb9d973282009-06-09 08:50:38 -0700674 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 $count = 0;
676 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700677 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 if ($count != $#{$args{'parameterlist'}}) {
679 $count++;
680 print ",\n";
681 }
682 print "<br>";
683 }
684 print "};<br>\n";
685
686 print "<h3>Constants</h3>\n";
687 print "<dl>\n";
688 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700689 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 print "<dd>";
691 output_highlight($args{'parameterdescs'}{$parameter});
692 }
693 print "</dl>\n";
694 output_section_html(@_);
695 print "<hr>\n";
696}
697
Randy Dunlapd28bee02006-02-01 03:06:57 -0800698# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699sub output_typedef_html(%) {
700 my %args = %{$_[0]};
701 my ($parameter);
702 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700703 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Randy Dunlapb9d973282009-06-09 08:50:38 -0700705 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 output_section_html(@_);
707 print "<hr>\n";
708}
709
710# output struct in html
711sub output_struct_html(%) {
712 my %args = %{$_[0]};
713 my ($parameter);
714
Randy Dunlapb9d973282009-06-09 08:50:38 -0700715 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
716 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 foreach $parameter (@{$args{'parameterlist'}}) {
718 if ($parameter =~ /^#/) {
719 print "$parameter<br>\n";
720 next;
721 }
722 my $parameter_name = $parameter;
723 $parameter_name =~ s/\[.*//;
724
Randy Dunlap3c308792007-05-08 00:24:39 -0700725 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 $type = $args{'parametertypes'}{$parameter};
727 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
728 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700729 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700731 # bitfield
732 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700734 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 }
736 }
737 print "};<br>\n";
738
739 print "<h3>Members</h3>\n";
740 print "<dl>\n";
741 foreach $parameter (@{$args{'parameterlist'}}) {
742 ($parameter =~ /^#/) && next;
743
744 my $parameter_name = $parameter;
745 $parameter_name =~ s/\[.*//;
746
Randy Dunlap3c308792007-05-08 00:24:39 -0700747 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700748 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 print "<dd>";
750 output_highlight($args{'parameterdescs'}{$parameter_name});
751 }
752 print "</dl>\n";
753 output_section_html(@_);
754 print "<hr>\n";
755}
756
757# output function in html
758sub output_function_html(%) {
759 my %args = %{$_[0]};
760 my ($parameter, $section);
761 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
Randy Dunlapb9d973282009-06-09 08:50:38 -0700763 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
764 print "<i>" . $args{'functiontype'} . "</i>\n";
765 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 print "(";
767 $count = 0;
768 foreach $parameter (@{$args{'parameterlist'}}) {
769 $type = $args{'parametertypes'}{$parameter};
770 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
771 # pointer-to-function
772 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
773 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700774 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 }
776 if ($count != $#{$args{'parameterlist'}}) {
777 $count++;
778 print ",\n";
779 }
780 }
781 print ")\n";
782
783 print "<h3>Arguments</h3>\n";
784 print "<dl>\n";
785 foreach $parameter (@{$args{'parameterlist'}}) {
786 my $parameter_name = $parameter;
787 $parameter_name =~ s/\[.*//;
788
Randy Dunlap3c308792007-05-08 00:24:39 -0700789 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700790 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 print "<dd>";
792 output_highlight($args{'parameterdescs'}{$parameter_name});
793 }
794 print "</dl>\n";
795 output_section_html(@_);
796 print "<hr>\n";
797}
798
Johannes Bergb112e0f2007-10-24 15:08:48 -0700799# output DOC: block header in html
800sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 my %args = %{$_[0]};
802 my ($parameter, $section);
803 my $count;
804
805 foreach $section (@{$args{'sectionlist'}}) {
806 print "<h3>$section</h3>\n";
807 print "<ul>\n";
808 output_highlight($args{'sections'}{$section});
809 print "</ul>\n";
810 }
811 print "<hr>\n";
812}
813
Dan Luedtke1b40c192012-08-12 10:46:15 +0200814# output sections in html5
815sub output_section_html5(%) {
816 my %args = %{$_[0]};
817 my $section;
818
819 foreach $section (@{$args{'sectionlist'}}) {
820 print "<section>\n";
821 print "<h1>$section</h1>\n";
822 print "<p>\n";
823 output_highlight($args{'sections'}{$section});
824 print "</p>\n";
825 print "</section>\n";
826 }
827}
828
829# output enum in html5
830sub output_enum_html5(%) {
831 my %args = %{$_[0]};
832 my ($parameter);
833 my $count;
834 my $html5id;
835
836 $html5id = $args{'enum'};
837 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
838 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
839 print "<h1>enum " . $args{'enum'} . "</h1>\n";
840 print "<ol class=\"code\">\n";
841 print "<li>";
842 print "<span class=\"keyword\">enum</span> ";
843 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
844 print "</li>\n";
845 $count = 0;
846 foreach $parameter (@{$args{'parameterlist'}}) {
847 print "<li class=\"indent\">";
848 print "<span class=\"param\">" . $parameter . "</span>";
849 if ($count != $#{$args{'parameterlist'}}) {
850 $count++;
851 print ",";
852 }
853 print "</li>\n";
854 }
855 print "<li>};</li>\n";
856 print "</ol>\n";
857
858 print "<section>\n";
859 print "<h1>Constants</h1>\n";
860 print "<dl>\n";
861 foreach $parameter (@{$args{'parameterlist'}}) {
862 print "<dt>" . $parameter . "</dt>\n";
863 print "<dd>";
864 output_highlight($args{'parameterdescs'}{$parameter});
865 print "</dd>\n";
866 }
867 print "</dl>\n";
868 print "</section>\n";
869 output_section_html5(@_);
870 print "</article>\n";
871}
872
873# output typedef in html5
874sub output_typedef_html5(%) {
875 my %args = %{$_[0]};
876 my ($parameter);
877 my $count;
878 my $html5id;
879
880 $html5id = $args{'typedef'};
881 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
882 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
883 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
884
885 print "<ol class=\"code\">\n";
886 print "<li>";
887 print "<span class=\"keyword\">typedef</span> ";
888 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
889 print "</li>\n";
890 print "</ol>\n";
891 output_section_html5(@_);
892 print "</article>\n";
893}
894
895# output struct in html5
896sub output_struct_html5(%) {
897 my %args = %{$_[0]};
898 my ($parameter);
899 my $html5id;
900
901 $html5id = $args{'struct'};
902 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
903 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
904 print "<hgroup>\n";
905 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
906 print "<h2>". $args{'purpose'} . "</h2>\n";
907 print "</hgroup>\n";
908 print "<ol class=\"code\">\n";
909 print "<li>";
910 print "<span class=\"type\">" . $args{'type'} . "</span> ";
911 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
912 print "</li>\n";
913 foreach $parameter (@{$args{'parameterlist'}}) {
914 print "<li class=\"indent\">";
915 if ($parameter =~ /^#/) {
916 print "<span class=\"param\">" . $parameter ."</span>\n";
917 print "</li>\n";
918 next;
919 }
920 my $parameter_name = $parameter;
921 $parameter_name =~ s/\[.*//;
922
923 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
924 $type = $args{'parametertypes'}{$parameter};
925 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
926 # pointer-to-function
927 print "<span class=\"type\">$1</span> ";
928 print "<span class=\"param\">$parameter</span>";
929 print "<span class=\"type\">)</span> ";
930 print "(<span class=\"args\">$2</span>);";
931 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
932 # bitfield
933 print "<span class=\"type\">$1</span> ";
934 print "<span class=\"param\">$parameter</span>";
935 print "<span class=\"bits\">$2</span>;";
936 } else {
937 print "<span class=\"type\">$type</span> ";
938 print "<span class=\"param\">$parameter</span>;";
939 }
940 print "</li>\n";
941 }
942 print "<li>};</li>\n";
943 print "</ol>\n";
944
945 print "<section>\n";
946 print "<h1>Members</h1>\n";
947 print "<dl>\n";
948 foreach $parameter (@{$args{'parameterlist'}}) {
949 ($parameter =~ /^#/) && next;
950
951 my $parameter_name = $parameter;
952 $parameter_name =~ s/\[.*//;
953
954 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
955 print "<dt>" . $parameter . "</dt>\n";
956 print "<dd>";
957 output_highlight($args{'parameterdescs'}{$parameter_name});
958 print "</dd>\n";
959 }
960 print "</dl>\n";
961 print "</section>\n";
962 output_section_html5(@_);
963 print "</article>\n";
964}
965
966# output function in html5
967sub output_function_html5(%) {
968 my %args = %{$_[0]};
969 my ($parameter, $section);
970 my $count;
971 my $html5id;
972
973 $html5id = $args{'function'};
974 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
975 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
976 print "<hgroup>\n";
977 print "<h1>" . $args{'function'} . "</h1>";
978 print "<h2>" . $args{'purpose'} . "</h2>\n";
979 print "</hgroup>\n";
980 print "<ol class=\"code\">\n";
981 print "<li>";
982 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
983 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
984 print "</li>";
985 $count = 0;
986 foreach $parameter (@{$args{'parameterlist'}}) {
987 print "<li class=\"indent\">";
988 $type = $args{'parametertypes'}{$parameter};
989 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
990 # pointer-to-function
991 print "<span class=\"type\">$1</span> ";
992 print "<span class=\"param\">$parameter</span>";
993 print "<span class=\"type\">)</span> ";
994 print "(<span class=\"args\">$2</span>)";
995 } else {
996 print "<span class=\"type\">$type</span> ";
997 print "<span class=\"param\">$parameter</span>";
998 }
999 if ($count != $#{$args{'parameterlist'}}) {
1000 $count++;
1001 print ",";
1002 }
1003 print "</li>\n";
1004 }
1005 print "<li>)</li>\n";
1006 print "</ol>\n";
1007
1008 print "<section>\n";
1009 print "<h1>Arguments</h1>\n";
1010 print "<p>\n";
1011 print "<dl>\n";
1012 foreach $parameter (@{$args{'parameterlist'}}) {
1013 my $parameter_name = $parameter;
1014 $parameter_name =~ s/\[.*//;
1015
1016 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1017 print "<dt>" . $parameter . "</dt>\n";
1018 print "<dd>";
1019 output_highlight($args{'parameterdescs'}{$parameter_name});
1020 print "</dd>\n";
1021 }
1022 print "</dl>\n";
1023 print "</section>\n";
1024 output_section_html5(@_);
1025 print "</article>\n";
1026}
1027
1028# output DOC: block header in html5
1029sub output_blockhead_html5(%) {
1030 my %args = %{$_[0]};
1031 my ($parameter, $section);
1032 my $count;
1033 my $html5id;
1034
1035 foreach $section (@{$args{'sectionlist'}}) {
1036 $html5id = $section;
1037 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1038 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1039 print "<h1>$section</h1>\n";
1040 print "<p>\n";
1041 output_highlight($args{'sections'}{$section});
1042 print "</p>\n";
1043 }
1044 print "</article>\n";
1045}
1046
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047sub output_section_xml(%) {
1048 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001049 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 # print out each section
1051 $lineprefix=" ";
1052 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001053 print "<refsect1>\n";
1054 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001056 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001057 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001058 } else {
1059 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 }
1061 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001062 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001064 print "</programlisting></informalexample>\n";
1065 } else {
1066 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001068 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 }
1070}
1071
1072# output function in XML DocBook
1073sub output_function_xml(%) {
1074 my %args = %{$_[0]};
1075 my ($parameter, $section);
1076 my $count;
1077 my $id;
1078
Randy Dunlapb9d973282009-06-09 08:50:38 -07001079 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 $id =~ s/[^A-Za-z0-9]/-/g;
1081
Pavel Pisa5449bc92007-02-10 01:45:37 -08001082 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001083 print "<refentryinfo>\n";
1084 print " <title>LINUX</title>\n";
1085 print " <productname>Kernel Hackers Manual</productname>\n";
1086 print " <date>$man_date</date>\n";
1087 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001089 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001090 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001091 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 print "</refmeta>\n";
1093 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001094 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 print " <refpurpose>\n";
1096 print " ";
1097 output_highlight ($args{'purpose'});
1098 print " </refpurpose>\n";
1099 print "</refnamediv>\n";
1100
1101 print "<refsynopsisdiv>\n";
1102 print " <title>Synopsis</title>\n";
1103 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001104 print " <funcdef>" . $args{'functiontype'} . " ";
1105 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
1107 $count = 0;
1108 if ($#{$args{'parameterlist'}} >= 0) {
1109 foreach $parameter (@{$args{'parameterlist'}}) {
1110 $type = $args{'parametertypes'}{$parameter};
1111 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1112 # pointer-to-function
1113 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1114 print " <funcparams>$2</funcparams></paramdef>\n";
1115 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001116 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 print " <parameter>$parameter</parameter></paramdef>\n";
1118 }
1119 }
1120 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001121 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 }
1123 print " </funcprototype></funcsynopsis>\n";
1124 print "</refsynopsisdiv>\n";
1125
1126 # print parameters
1127 print "<refsect1>\n <title>Arguments</title>\n";
1128 if ($#{$args{'parameterlist'}} >= 0) {
1129 print " <variablelist>\n";
1130 foreach $parameter (@{$args{'parameterlist'}}) {
1131 my $parameter_name = $parameter;
1132 $parameter_name =~ s/\[.*//;
1133
1134 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1135 print " <listitem>\n <para>\n";
1136 $lineprefix=" ";
1137 output_highlight($args{'parameterdescs'}{$parameter_name});
1138 print " </para>\n </listitem>\n </varlistentry>\n";
1139 }
1140 print " </variablelist>\n";
1141 } else {
1142 print " <para>\n None\n </para>\n";
1143 }
1144 print "</refsect1>\n";
1145
1146 output_section_xml(@_);
1147 print "</refentry>\n\n";
1148}
1149
1150# output struct in XML DocBook
1151sub output_struct_xml(%) {
1152 my %args = %{$_[0]};
1153 my ($parameter, $section);
1154 my $id;
1155
Randy Dunlapb9d973282009-06-09 08:50:38 -07001156 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 $id =~ s/[^A-Za-z0-9]/-/g;
1158
Pavel Pisa5449bc92007-02-10 01:45:37 -08001159 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001160 print "<refentryinfo>\n";
1161 print " <title>LINUX</title>\n";
1162 print " <productname>Kernel Hackers Manual</productname>\n";
1163 print " <date>$man_date</date>\n";
1164 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001166 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001167 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001168 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 print "</refmeta>\n";
1170 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001171 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 print " <refpurpose>\n";
1173 print " ";
1174 output_highlight ($args{'purpose'});
1175 print " </refpurpose>\n";
1176 print "</refnamediv>\n";
1177
1178 print "<refsynopsisdiv>\n";
1179 print " <title>Synopsis</title>\n";
1180 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001181 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 foreach $parameter (@{$args{'parameterlist'}}) {
1183 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001184 my $prm = $parameter;
1185 # convert data read & converted thru xml_escape() into &xyz; format:
1186 # This allows us to have #define macros interspersed in a struct.
1187 $prm =~ s/\\\\\\/\&/g;
1188 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 next;
1190 }
1191
1192 my $parameter_name = $parameter;
1193 $parameter_name =~ s/\[.*//;
1194
1195 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001196 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 $type = $args{'parametertypes'}{$parameter};
1198 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1199 # pointer-to-function
1200 print " $1 $parameter) ($2);\n";
1201 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001202 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 print " $1 $parameter$2;\n";
1204 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001205 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 }
1207 }
1208 print "};";
1209 print " </programlisting>\n";
1210 print "</refsynopsisdiv>\n";
1211
1212 print " <refsect1>\n";
1213 print " <title>Members</title>\n";
1214
Randy Dunlap39f00c02008-09-22 13:57:44 -07001215 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 print " <variablelist>\n";
1217 foreach $parameter (@{$args{'parameterlist'}}) {
1218 ($parameter =~ /^#/) && next;
1219
1220 my $parameter_name = $parameter;
1221 $parameter_name =~ s/\[.*//;
1222
1223 defined($args{'parameterdescs'}{$parameter_name}) || next;
1224 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1225 print " <varlistentry>";
1226 print " <term>$parameter</term>\n";
1227 print " <listitem><para>\n";
1228 output_highlight($args{'parameterdescs'}{$parameter_name});
1229 print " </para></listitem>\n";
1230 print " </varlistentry>\n";
1231 }
1232 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001233 } else {
1234 print " <para>\n None\n </para>\n";
1235 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 print " </refsect1>\n";
1237
1238 output_section_xml(@_);
1239
1240 print "</refentry>\n\n";
1241}
1242
1243# output enum in XML DocBook
1244sub output_enum_xml(%) {
1245 my %args = %{$_[0]};
1246 my ($parameter, $section);
1247 my $count;
1248 my $id;
1249
Randy Dunlapb9d973282009-06-09 08:50:38 -07001250 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 $id =~ s/[^A-Za-z0-9]/-/g;
1252
Pavel Pisa5449bc92007-02-10 01:45:37 -08001253 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001254 print "<refentryinfo>\n";
1255 print " <title>LINUX</title>\n";
1256 print " <productname>Kernel Hackers Manual</productname>\n";
1257 print " <date>$man_date</date>\n";
1258 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001260 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001261 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001262 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 print "</refmeta>\n";
1264 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001265 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 print " <refpurpose>\n";
1267 print " ";
1268 output_highlight ($args{'purpose'});
1269 print " </refpurpose>\n";
1270 print "</refnamediv>\n";
1271
1272 print "<refsynopsisdiv>\n";
1273 print " <title>Synopsis</title>\n";
1274 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001275 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 $count = 0;
1277 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001278 print " $parameter";
1279 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 $count++;
1281 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001282 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 print "\n";
1284 }
1285 print "};";
1286 print " </programlisting>\n";
1287 print "</refsynopsisdiv>\n";
1288
1289 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001290 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 print " <variablelist>\n";
1292 foreach $parameter (@{$args{'parameterlist'}}) {
1293 my $parameter_name = $parameter;
1294 $parameter_name =~ s/\[.*//;
1295
1296 print " <varlistentry>";
1297 print " <term>$parameter</term>\n";
1298 print " <listitem><para>\n";
1299 output_highlight($args{'parameterdescs'}{$parameter_name});
1300 print " </para></listitem>\n";
1301 print " </varlistentry>\n";
1302 }
1303 print " </variablelist>\n";
1304 print "</refsect1>\n";
1305
1306 output_section_xml(@_);
1307
1308 print "</refentry>\n\n";
1309}
1310
1311# output typedef in XML DocBook
1312sub output_typedef_xml(%) {
1313 my %args = %{$_[0]};
1314 my ($parameter, $section);
1315 my $id;
1316
Randy Dunlapb9d973282009-06-09 08:50:38 -07001317 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 $id =~ s/[^A-Za-z0-9]/-/g;
1319
Pavel Pisa5449bc92007-02-10 01:45:37 -08001320 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001321 print "<refentryinfo>\n";
1322 print " <title>LINUX</title>\n";
1323 print " <productname>Kernel Hackers Manual</productname>\n";
1324 print " <date>$man_date</date>\n";
1325 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001327 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001328 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 print "</refmeta>\n";
1330 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001331 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 print " <refpurpose>\n";
1333 print " ";
1334 output_highlight ($args{'purpose'});
1335 print " </refpurpose>\n";
1336 print "</refnamediv>\n";
1337
1338 print "<refsynopsisdiv>\n";
1339 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001340 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 print "</refsynopsisdiv>\n";
1342
1343 output_section_xml(@_);
1344
1345 print "</refentry>\n\n";
1346}
1347
1348# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001349sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 my %args = %{$_[0]};
1351 my ($parameter, $section);
1352 my $count;
1353
1354 my $id = $args{'module'};
1355 $id =~ s/[^A-Za-z0-9]/-/g;
1356
1357 # print out each section
1358 $lineprefix=" ";
1359 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001360 if (!$args{'content-only'}) {
1361 print "<refsect1>\n <title>$section</title>\n";
1362 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 if ($section =~ m/EXAMPLE/i) {
1364 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001365 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001366 } else {
1367 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 }
1369 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001370 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 if ($section =~ m/EXAMPLE/i) {
1372 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001373 } else {
1374 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001376 if (!$args{'content-only'}) {
1377 print "\n</refsect1>\n";
1378 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 }
1380
1381 print "\n\n";
1382}
1383
1384# output in XML DocBook
1385sub output_function_gnome {
1386 my %args = %{$_[0]};
1387 my ($parameter, $section);
1388 my $count;
1389 my $id;
1390
Randy Dunlapb9d973282009-06-09 08:50:38 -07001391 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 $id =~ s/[^A-Za-z0-9]/-/g;
1393
1394 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001395 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
1397 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001398 print " <funcdef>" . $args{'functiontype'} . " ";
1399 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 print "</function></funcdef>\n";
1401
1402 $count = 0;
1403 if ($#{$args{'parameterlist'}} >= 0) {
1404 foreach $parameter (@{$args{'parameterlist'}}) {
1405 $type = $args{'parametertypes'}{$parameter};
1406 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1407 # pointer-to-function
1408 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1409 print " <funcparams>$2</funcparams></paramdef>\n";
1410 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001411 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 print " <parameter>$parameter</parameter></paramdef>\n";
1413 }
1414 }
1415 } else {
1416 print " <void>\n";
1417 }
1418 print " </funcsynopsis>\n";
1419 if ($#{$args{'parameterlist'}} >= 0) {
1420 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1421 print "<tgroup cols=\"2\">\n";
1422 print "<colspec colwidth=\"2*\">\n";
1423 print "<colspec colwidth=\"8*\">\n";
1424 print "<tbody>\n";
1425 foreach $parameter (@{$args{'parameterlist'}}) {
1426 my $parameter_name = $parameter;
1427 $parameter_name =~ s/\[.*//;
1428
1429 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1430 print " <entry>\n";
1431 $lineprefix=" ";
1432 output_highlight($args{'parameterdescs'}{$parameter_name});
1433 print " </entry></row>\n";
1434 }
1435 print " </tbody></tgroup></informaltable>\n";
1436 } else {
1437 print " <para>\n None\n </para>\n";
1438 }
1439
1440 # print out each section
1441 $lineprefix=" ";
1442 foreach $section (@{$args{'sectionlist'}}) {
1443 print "<simplesect>\n <title>$section</title>\n";
1444 if ($section =~ m/EXAMPLE/i) {
1445 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001446 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 } else {
1448 }
1449 print "<para>\n";
1450 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001451 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 print "</para>\n";
1453 if ($section =~ m/EXAMPLE/i) {
1454 print "</programlisting></example>\n";
1455 } else {
1456 }
1457 print " </simplesect>\n";
1458 }
1459
1460 print "</sect2>\n\n";
1461}
1462
1463##
1464# output function in man
1465sub output_function_man(%) {
1466 my %args = %{$_[0]};
1467 my ($parameter, $section);
1468 my $count;
1469
1470 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1471
1472 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001473 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
1475 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001476 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001477 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001478 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001479 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001480 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 $count = 0;
1482 my $parenth = "(";
1483 my $post = ",";
1484 foreach my $parameter (@{$args{'parameterlist'}}) {
1485 if ($count == $#{$args{'parameterlist'}}) {
1486 $post = ");";
1487 }
1488 $type = $args{'parametertypes'}{$parameter};
1489 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1490 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001491 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 } else {
1493 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001494 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 }
1496 $count++;
1497 $parenth = "";
1498 }
1499
1500 print ".SH ARGUMENTS\n";
1501 foreach $parameter (@{$args{'parameterlist'}}) {
1502 my $parameter_name = $parameter;
1503 $parameter_name =~ s/\[.*//;
1504
Randy Dunlapb9d973282009-06-09 08:50:38 -07001505 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 output_highlight($args{'parameterdescs'}{$parameter_name});
1507 }
1508 foreach $section (@{$args{'sectionlist'}}) {
1509 print ".SH \"", uc $section, "\"\n";
1510 output_highlight($args{'sections'}{$section});
1511 }
1512}
1513
1514##
1515# output enum in man
1516sub output_enum_man(%) {
1517 my %args = %{$_[0]};
1518 my ($parameter, $section);
1519 my $count;
1520
1521 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1522
1523 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001524 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
1526 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001527 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 $count = 0;
1529 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001530 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 if ($count == $#{$args{'parameterlist'}}) {
1532 print "\n};\n";
1533 last;
1534 }
1535 else {
1536 print ", \n.br\n";
1537 }
1538 $count++;
1539 }
1540
1541 print ".SH Constants\n";
1542 foreach $parameter (@{$args{'parameterlist'}}) {
1543 my $parameter_name = $parameter;
1544 $parameter_name =~ s/\[.*//;
1545
Randy Dunlapb9d973282009-06-09 08:50:38 -07001546 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 output_highlight($args{'parameterdescs'}{$parameter_name});
1548 }
1549 foreach $section (@{$args{'sectionlist'}}) {
1550 print ".SH \"$section\"\n";
1551 output_highlight($args{'sections'}{$section});
1552 }
1553}
1554
1555##
1556# output struct in man
1557sub output_struct_man(%) {
1558 my %args = %{$_[0]};
1559 my ($parameter, $section);
1560
Randy Dunlapb9d973282009-06-09 08:50:38 -07001561 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
1563 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001564 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
1566 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001567 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
1569 foreach my $parameter (@{$args{'parameterlist'}}) {
1570 if ($parameter =~ /^#/) {
1571 print ".BI \"$parameter\"\n.br\n";
1572 next;
1573 }
1574 my $parameter_name = $parameter;
1575 $parameter_name =~ s/\[.*//;
1576
Randy Dunlap3c308792007-05-08 00:24:39 -07001577 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 $type = $args{'parametertypes'}{$parameter};
1579 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1580 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001581 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001583 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001584 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 } else {
1586 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001587 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 }
1589 print "\n.br\n";
1590 }
1591 print "};\n.br\n";
1592
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001593 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 foreach $parameter (@{$args{'parameterlist'}}) {
1595 ($parameter =~ /^#/) && next;
1596
1597 my $parameter_name = $parameter;
1598 $parameter_name =~ s/\[.*//;
1599
Randy Dunlap3c308792007-05-08 00:24:39 -07001600 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001601 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 output_highlight($args{'parameterdescs'}{$parameter_name});
1603 }
1604 foreach $section (@{$args{'sectionlist'}}) {
1605 print ".SH \"$section\"\n";
1606 output_highlight($args{'sections'}{$section});
1607 }
1608}
1609
1610##
1611# output typedef in man
1612sub output_typedef_man(%) {
1613 my %args = %{$_[0]};
1614 my ($parameter, $section);
1615
1616 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1617
1618 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001619 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
1621 foreach $section (@{$args{'sectionlist'}}) {
1622 print ".SH \"$section\"\n";
1623 output_highlight($args{'sections'}{$section});
1624 }
1625}
1626
Johannes Bergb112e0f2007-10-24 15:08:48 -07001627sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 my %args = %{$_[0]};
1629 my ($parameter, $section);
1630 my $count;
1631
1632 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1633
1634 foreach $section (@{$args{'sectionlist'}}) {
1635 print ".SH \"$section\"\n";
1636 output_highlight($args{'sections'}{$section});
1637 }
1638}
1639
1640##
1641# output in text
1642sub output_function_text(%) {
1643 my %args = %{$_[0]};
1644 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001645 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
Randy Dunlapf47634b2006-07-01 04:36:36 -07001647 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001648 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001649
1650 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001651 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001652 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001653 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001654 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001655 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001657
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 my $count = 0;
1659 foreach my $parameter (@{$args{'parameterlist'}}) {
1660 $type = $args{'parametertypes'}{$parameter};
1661 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1662 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001663 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001665 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 }
1667 if ($count != $#{$args{'parameterlist'}}) {
1668 $count++;
1669 print ",\n";
1670 print " " x length($start);
1671 } else {
1672 print ");\n\n";
1673 }
1674 }
1675
1676 print "Arguments:\n\n";
1677 foreach $parameter (@{$args{'parameterlist'}}) {
1678 my $parameter_name = $parameter;
1679 $parameter_name =~ s/\[.*//;
1680
Randy Dunlapb9d973282009-06-09 08:50:38 -07001681 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 }
1683 output_section_text(@_);
1684}
1685
1686#output sections in text
1687sub output_section_text(%) {
1688 my %args = %{$_[0]};
1689 my $section;
1690
1691 print "\n";
1692 foreach $section (@{$args{'sectionlist'}}) {
1693 print "$section:\n\n";
1694 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001695 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 print "\n\n";
1697}
1698
1699# output enum in text
1700sub output_enum_text(%) {
1701 my %args = %{$_[0]};
1702 my ($parameter);
1703 my $count;
1704 print "Enum:\n\n";
1705
Randy Dunlapb9d973282009-06-09 08:50:38 -07001706 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1707 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 $count = 0;
1709 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001710 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 if ($count != $#{$args{'parameterlist'}}) {
1712 $count++;
1713 print ",";
1714 }
1715 print "\n";
1716 }
1717 print "};\n\n";
1718
1719 print "Constants:\n\n";
1720 foreach $parameter (@{$args{'parameterlist'}}) {
1721 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001722 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 }
1724
1725 output_section_text(@_);
1726}
1727
1728# output typedef in text
1729sub output_typedef_text(%) {
1730 my %args = %{$_[0]};
1731 my ($parameter);
1732 my $count;
1733 print "Typedef:\n\n";
1734
Randy Dunlapb9d973282009-06-09 08:50:38 -07001735 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 output_section_text(@_);
1737}
1738
1739# output struct as text
1740sub output_struct_text(%) {
1741 my %args = %{$_[0]};
1742 my ($parameter);
1743
Randy Dunlapb9d973282009-06-09 08:50:38 -07001744 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1745 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 foreach $parameter (@{$args{'parameterlist'}}) {
1747 if ($parameter =~ /^#/) {
1748 print "$parameter\n";
1749 next;
1750 }
1751
1752 my $parameter_name = $parameter;
1753 $parameter_name =~ s/\[.*//;
1754
Randy Dunlap3c308792007-05-08 00:24:39 -07001755 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 $type = $args{'parametertypes'}{$parameter};
1757 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1758 # pointer-to-function
1759 print "\t$1 $parameter) ($2);\n";
1760 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001761 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 print "\t$1 $parameter$2;\n";
1763 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001764 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 }
1766 }
1767 print "};\n\n";
1768
1769 print "Members:\n\n";
1770 foreach $parameter (@{$args{'parameterlist'}}) {
1771 ($parameter =~ /^#/) && next;
1772
1773 my $parameter_name = $parameter;
1774 $parameter_name =~ s/\[.*//;
1775
Randy Dunlap3c308792007-05-08 00:24:39 -07001776 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001778 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 }
1780 print "\n";
1781 output_section_text(@_);
1782}
1783
Johannes Bergb112e0f2007-10-24 15:08:48 -07001784sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 my %args = %{$_[0]};
1786 my ($parameter, $section);
1787
1788 foreach $section (@{$args{'sectionlist'}}) {
1789 print " $section:\n";
1790 print " -> ";
1791 output_highlight($args{'sections'}{$section});
1792 }
1793}
1794
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001795##
1796# output in restructured text
1797#
1798
1799#
1800# This could use some work; it's used to output the DOC: sections, and
1801# starts by putting out the name of the doc section itself, but that tends
1802# to duplicate a header already in the template file.
1803#
1804sub output_blockhead_rst(%) {
1805 my %args = %{$_[0]};
1806 my ($parameter, $section);
1807
1808 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001809 if ($output_selection != OUTPUT_INCLUDE) {
1810 print "**$section**\n\n";
1811 }
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001812 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001813 output_highlight_rst($args{'sections'}{$section});
1814 print "\n";
1815 }
1816}
1817
1818sub output_highlight_rst {
1819 my $contents = join "\n",@_;
1820 my $line;
1821
1822 # undo the evil effects of xml_escape() earlier
1823 $contents = xml_unescape($contents);
1824
1825 eval $dohighlight;
1826 die $@ if $@;
1827
1828 foreach $line (split "\n", $contents) {
Jani Nikula830066a2016-05-26 22:04:33 +03001829 print $lineprefix . $line . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001830 }
1831}
1832
1833sub output_function_rst(%) {
1834 my %args = %{$_[0]};
1835 my ($parameter, $section);
Jani Nikulac099ff62016-05-26 17:18:17 +03001836 my $oldprefix = $lineprefix;
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001837 my $start = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001838
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001839 if ($args{'typedef'}) {
1840 print ".. c:type:: ". $args{'function'} . "\n\n";
1841 print_lineno($declaration_start_line);
1842 print " **Typedef**: ";
1843 $lineprefix = "";
1844 output_highlight_rst($args{'purpose'});
1845 $start = "\n\n**Syntax**\n\n ``";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001846 } else {
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001847 print ".. c:function:: ";
1848 }
1849 if ($args{'functiontype'} ne "") {
1850 $start .= $args{'functiontype'} . " " . $args{'function'} . " (";
1851 } else {
1852 $start .= $args{'function'} . " (";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001853 }
1854 print $start;
1855
1856 my $count = 0;
1857 foreach my $parameter (@{$args{'parameterlist'}}) {
1858 if ($count ne 0) {
1859 print ", ";
1860 }
1861 $count++;
1862 $type = $args{'parametertypes'}{$parameter};
Mauro Carvalho Chehaba88b1672016-07-22 11:46:36 -03001863
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001864 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1865 # pointer-to-function
1866 print $1 . $parameter . ") (" . $2;
1867 } else {
1868 print $type . " " . $parameter;
1869 }
1870 }
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001871 if ($args{'typedef'}) {
1872 print ");``\n\n";
1873 } else {
1874 print ")\n\n";
1875 print_lineno($declaration_start_line);
1876 $lineprefix = " ";
1877 output_highlight_rst($args{'purpose'});
1878 print "\n";
1879 }
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001880
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001881 print "**Parameters**\n\n";
1882 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001883 foreach $parameter (@{$args{'parameterlist'}}) {
1884 my $parameter_name = $parameter;
1885 #$parameter_name =~ s/\[.*//;
1886 $type = $args{'parametertypes'}{$parameter};
1887
1888 if ($type ne "") {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001889 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001890 } else {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001891 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001892 }
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001893
1894 print_lineno($parameterdesc_start_lines{$parameter_name});
1895
Jani Nikula5e64fa92016-05-19 20:32:48 +03001896 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1897 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001898 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001899 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001900 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001901 }
1902 print "\n";
1903 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001904
1905 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001906 output_section_rst(@_);
1907}
1908
1909sub output_section_rst(%) {
1910 my %args = %{$_[0]};
1911 my $section;
1912 my $oldprefix = $lineprefix;
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001913 $lineprefix = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001914
1915 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001916 print "**$section**\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001917 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001918 output_highlight_rst($args{'sections'}{$section});
1919 print "\n";
1920 }
1921 print "\n";
1922 $lineprefix = $oldprefix;
1923}
1924
1925sub output_enum_rst(%) {
1926 my %args = %{$_[0]};
1927 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001928 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001929 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001930 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001931
1932 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001933 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001934 $lineprefix = " ";
1935 output_highlight_rst($args{'purpose'});
1936 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001937
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001938 print "**Constants**\n\n";
1939 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001940 foreach $parameter (@{$args{'parameterlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001941 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001942 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1943 output_highlight_rst($args{'parameterdescs'}{$parameter});
1944 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001945 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001946 }
1947 print "\n";
1948 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001949
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001950 $lineprefix = $oldprefix;
1951 output_section_rst(@_);
1952}
1953
1954sub output_typedef_rst(%) {
1955 my %args = %{$_[0]};
1956 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001957 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001958 my $name = "typedef " . $args{'typedef'};
1959
Jani Nikula62850972016-05-12 16:15:38 +03001960 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001961 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001962 $lineprefix = " ";
1963 output_highlight_rst($args{'purpose'});
1964 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001965
Jani Nikulac099ff62016-05-26 17:18:17 +03001966 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001967 output_section_rst(@_);
1968}
1969
1970sub output_struct_rst(%) {
1971 my %args = %{$_[0]};
1972 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001973 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001974 my $name = $args{'type'} . " " . $args{'struct'};
1975
Jani Nikula62850972016-05-12 16:15:38 +03001976 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001977 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001978 $lineprefix = " ";
1979 output_highlight_rst($args{'purpose'});
1980 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001981
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001982 print "**Definition**\n\n";
1983 print "::\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001984 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1985 foreach $parameter (@{$args{'parameterlist'}}) {
1986 if ($parameter =~ /^#/) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001987 print " " . "$parameter\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001988 next;
1989 }
1990
1991 my $parameter_name = $parameter;
1992 $parameter_name =~ s/\[.*//;
1993
1994 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1995 $type = $args{'parametertypes'}{$parameter};
1996 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1997 # pointer-to-function
1998 print " $1 $parameter) ($2);\n";
1999 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
2000 # bitfield
2001 print " $1 $parameter$2;\n";
2002 } else {
2003 print " " . $type . " " . $parameter . ";\n";
2004 }
2005 }
2006 print " };\n\n";
2007
Jani Nikulaecbcfba2016-05-26 18:30:27 +03002008 print "**Members**\n\n";
2009 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002010 foreach $parameter (@{$args{'parameterlist'}}) {
2011 ($parameter =~ /^#/) && next;
2012
2013 my $parameter_name = $parameter;
2014 $parameter_name =~ s/\[.*//;
2015
2016 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
2017 $type = $args{'parametertypes'}{$parameter};
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002018 print_lineno($parameterdesc_start_lines{$parameter_name});
Mauro Carvalho Chehab6d232c82016-08-22 22:02:57 -03002019 print "``" . $parameter . "``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002020 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002021 print "\n";
2022 }
2023 print "\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03002024
2025 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002026 output_section_rst(@_);
2027}
2028
2029
Johannes Bergeda603f2010-09-11 15:55:22 -07002030## list mode output functions
2031
2032sub output_function_list(%) {
2033 my %args = %{$_[0]};
2034
2035 print $args{'function'} . "\n";
2036}
2037
2038# output enum in list
2039sub output_enum_list(%) {
2040 my %args = %{$_[0]};
2041 print $args{'enum'} . "\n";
2042}
2043
2044# output typedef in list
2045sub output_typedef_list(%) {
2046 my %args = %{$_[0]};
2047 print $args{'typedef'} . "\n";
2048}
2049
2050# output struct as list
2051sub output_struct_list(%) {
2052 my %args = %{$_[0]};
2053
2054 print $args{'struct'} . "\n";
2055}
2056
2057sub output_blockhead_list(%) {
2058 my %args = %{$_[0]};
2059 my ($parameter, $section);
2060
2061 foreach $section (@{$args{'sectionlist'}}) {
2062 print "DOC: $section\n";
2063 }
2064}
2065
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066##
Randy Dunlap27205742006-10-11 01:22:12 -07002067# generic output function for all types (function, struct/union, typedef, enum);
2068# calls the generated, variable output_ function name based on
2069# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070sub output_declaration {
2071 no strict 'refs';
2072 my $name = shift;
2073 my $functype = shift;
2074 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002075 if (($output_selection == OUTPUT_ALL) ||
2076 (($output_selection == OUTPUT_INCLUDE ||
2077 $output_selection == OUTPUT_EXPORTED) &&
2078 defined($function_table{$name})) ||
2079 (($output_selection == OUTPUT_EXCLUDE ||
2080 $output_selection == OUTPUT_INTERNAL) &&
2081 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002083 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 $section_counter++;
2085 }
2086}
2087
2088##
Randy Dunlap27205742006-10-11 01:22:12 -07002089# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002090sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002092 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 &$func(@_);
2094 $section_counter++;
2095}
2096
2097##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002098# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099# invokes the right handler. NOT called for functions.
2100sub dump_declaration($$) {
2101 no strict 'refs';
2102 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002103 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 &$func(@_);
2105}
2106
2107sub dump_union($$) {
2108 dump_struct(@_);
2109}
2110
2111sub dump_struct($$) {
2112 my $x = shift;
2113 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002114 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002116 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2117 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002118 $declaration_name = $2;
2119 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120
2121 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002122 $members =~ s/({.*})//g;
2123 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
Martin Waitzaeec46b2005-11-13 16:08:13 -08002125 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002126 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2127 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002128 # strip comments:
2129 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002130 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002131 # strip kmemcheck_bitfield_{begin,end}.*;
2132 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002133 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002134 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002135 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002136 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002137 # replace DECLARE_BITMAP
2138 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002139
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002141 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142
2143 output_declaration($declaration_name,
2144 'struct',
2145 {'struct' => $declaration_name,
2146 'module' => $modulename,
2147 'parameterlist' => \@parameterlist,
2148 'parameterdescs' => \%parameterdescs,
2149 'parametertypes' => \%parametertypes,
2150 'sectionlist' => \@sectionlist,
2151 'sections' => \%sections,
2152 'purpose' => $declaration_purpose,
2153 'type' => $decl_type
2154 });
2155 }
2156 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002157 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 ++$errors;
2159 }
2160}
2161
2162sub dump_enum($$) {
2163 my $x = shift;
2164 my $file = shift;
2165
Martin Waitzaeec46b2005-11-13 16:08:13 -08002166 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002167 # strip #define macros inside enums
2168 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002169
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002171 $declaration_name = $1;
2172 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173
2174 foreach my $arg (split ',', $members) {
2175 $arg =~ s/^\s*(\w+).*/$1/;
2176 push @parameterlist, $arg;
2177 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002178 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002179 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 "not described in enum '$declaration_name'\n";
2181 }
2182
2183 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002184
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 output_declaration($declaration_name,
2186 'enum',
2187 {'enum' => $declaration_name,
2188 'module' => $modulename,
2189 'parameterlist' => \@parameterlist,
2190 'parameterdescs' => \%parameterdescs,
2191 'sectionlist' => \@sectionlist,
2192 'sections' => \%sections,
2193 'purpose' => $declaration_purpose
2194 });
2195 }
2196 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002197 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 ++$errors;
2199 }
2200}
2201
2202sub dump_typedef($$) {
2203 my $x = shift;
2204 my $file = shift;
2205
Martin Waitzaeec46b2005-11-13 16:08:13 -08002206 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002207
2208 # Parse function prototypes
Mauro Carvalho Chehabd37c43c2016-08-30 20:20:57 -03002209 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ ||
2210 $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) {
2211
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002212 # Function typedefs
2213 $return_type = $1;
2214 $declaration_name = $2;
2215 my $args = $3;
2216
2217 create_parameterlist($args, ',', $file);
2218
2219 output_declaration($declaration_name,
2220 'function',
2221 {'function' => $declaration_name,
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03002222 'typedef' => 1,
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002223 'module' => $modulename,
2224 'functiontype' => $return_type,
2225 'parameterlist' => \@parameterlist,
2226 'parameterdescs' => \%parameterdescs,
2227 'parametertypes' => \%parametertypes,
2228 'sectionlist' => \@sectionlist,
2229 'sections' => \%sections,
2230 'purpose' => $declaration_purpose
2231 });
2232 return;
2233 }
2234
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002236 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 $x =~ s/\[*.\]\s*;$/;/;
2238 }
2239
2240 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002241 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
2243 output_declaration($declaration_name,
2244 'typedef',
2245 {'typedef' => $declaration_name,
2246 'module' => $modulename,
2247 'sectionlist' => \@sectionlist,
2248 'sections' => \%sections,
2249 'purpose' => $declaration_purpose
2250 });
2251 }
2252 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002253 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 ++$errors;
2255 }
2256}
2257
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002258sub save_struct_actual($) {
2259 my $actual = shift;
2260
2261 # strip all spaces from the actual param so that it looks like one string item
2262 $actual =~ s/\s*//g;
2263 $struct_actual = $struct_actual . $actual . " ";
2264}
2265
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266sub create_parameterlist($$$) {
2267 my $args = shift;
2268 my $splitter = shift;
2269 my $file = shift;
2270 my $type;
2271 my $param;
2272
Martin Waitza6d3fe72006-01-09 20:53:55 -08002273 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002275 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002277
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 foreach my $arg (split($splitter, $args)) {
2279 # strip comments
2280 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002281 # strip leading/trailing spaces
2282 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 $arg =~ s/\s*$//;
2284 $arg =~ s/\s+/ /;
2285
2286 if ($arg =~ /^#/) {
2287 # Treat preprocessor directive as a typeless variable just to fill
2288 # corresponding data structures "correctly". Catch it later in
2289 # output_* subs.
2290 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002291 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 # pointer-to-function
2293 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002294 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 $param = $1;
2296 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002297 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002298 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002300 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 $arg =~ s/\s*:\s*/:/g;
2302 $arg =~ s/\s*\[/\[/g;
2303
2304 my @args = split('\s*,\s*', $arg);
2305 if ($args[0] =~ m/\*/) {
2306 $args[0] =~ s/(\*+)\s*/ $1/;
2307 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002308
2309 my @first_arg;
2310 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2311 shift @args;
2312 push(@first_arg, split('\s+', $1));
2313 push(@first_arg, $2);
2314 } else {
2315 @first_arg = split('\s+', shift @args);
2316 }
2317
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 unshift(@args, pop @first_arg);
2319 $type = join " ", @first_arg;
2320
2321 foreach $param (@args) {
2322 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002323 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 push_parameter($2, "$type $1", $file);
2325 }
2326 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002327 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002328 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002329 push_parameter($1, "$type:$2", $file)
2330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 }
2332 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002333 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 push_parameter($param, $type, $file);
2335 }
2336 }
2337 }
2338 }
2339}
2340
2341sub push_parameter($$$) {
2342 my $param = shift;
2343 my $type = shift;
2344 my $file = shift;
2345
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002346 if (($anon_struct_union == 1) && ($type eq "") &&
2347 ($param eq "}")) {
2348 return; # ignore the ending }; from anon. struct/union
2349 }
2350
2351 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 my $param_name = $param;
2353 $param_name =~ s/\[.*//;
2354
Martin Waitza6d3fe72006-01-09 20:53:55 -08002355 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 {
Jonathan Corbetef000282016-08-26 07:14:08 -06002357 $param = "...";
Randy Dunlapced69092008-12-01 13:14:03 -08002358 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2359 $parameterdescs{$param} = "variable arguments";
2360 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 }
2362 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2363 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 $param="void";
2365 $parameterdescs{void} = "no arguments";
2366 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002367 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2368 # handle unnamed (anonymous) union or struct:
2369 {
2370 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002371 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002372 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002373 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002374 }
2375
Martin Waitza6d3fe72006-01-09 20:53:55 -08002376 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002377 # (but ignore ones starting with # as these are not parameters
2378 # but inline preprocessor statements);
2379 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002380 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002381 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2382
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 $parameterdescs{$param_name} = $undescribed;
2384
2385 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002386 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 "or member '$param' not " .
2388 "described in '$declaration_name'\n";
2389 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002390 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002391 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002393 }
2394 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002396 $param = xml_escape($param);
2397
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002398 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002399 # on @parameterlist;
2400 # this fixes a problem where check_sections() cannot find
2401 # a parameter like "addr[6 + 2]" because it actually appears
2402 # as "addr[6", "+", "2]" on the parameter list;
2403 # but it's better to maintain the param string unchanged for output,
2404 # so just weaken the string compare in check_sections() to ignore
2405 # "[blah" in a parameter string;
2406 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 push @parameterlist, $param;
2408 $parametertypes{$param} = $type;
2409}
2410
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002411sub check_sections($$$$$$) {
2412 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2413 my @sects = split ' ', $sectcheck;
2414 my @prms = split ' ', $prmscheck;
2415 my $err;
2416 my ($px, $sx);
2417 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2418
2419 foreach $sx (0 .. $#sects) {
2420 $err = 1;
2421 foreach $px (0 .. $#prms) {
2422 $prm_clean = $prms[$px];
2423 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002424 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002425 # ignore array size in a parameter string;
2426 # however, the original param string may contain
2427 # spaces, e.g.: addr[6 + 2]
2428 # and this appears in @prms as "addr[6" since the
2429 # parameter list is split at spaces;
2430 # hence just ignore "[..." for the sections check;
2431 $prm_clean =~ s/\[.*//;
2432
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002433 ##$prm_clean =~ s/^\**//;
2434 if ($prm_clean eq $sects[$sx]) {
2435 $err = 0;
2436 last;
2437 }
2438 }
2439 if ($err) {
2440 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002441 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002442 "Excess function parameter " .
2443 "'$sects[$sx]' " .
2444 "description in '$decl_name'\n";
2445 ++$warnings;
2446 } else {
2447 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002448 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002449 "Excess struct/union/enum/typedef member " .
2450 "'$sects[$sx]' " .
2451 "description in '$decl_name'\n";
2452 ++$warnings;
2453 }
2454 }
2455 }
2456 }
2457}
2458
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002460# Checks the section describing the return value of a function.
2461sub check_return_section {
2462 my $file = shift;
2463 my $declaration_name = shift;
2464 my $return_type = shift;
2465
2466 # Ignore an empty return type (It's a macro)
2467 # Ignore functions with a "void" return type. (But don't ignore "void *")
2468 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2469 return;
2470 }
2471
2472 if (!defined($sections{$section_return}) ||
2473 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002474 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002475 "No description found for return value of " .
2476 "'$declaration_name'\n";
2477 ++$warnings;
2478 }
2479}
2480
2481##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482# takes a function prototype and the name of the current file being
2483# processed and spits out all the details stored in the global
2484# arrays/hashes.
2485sub dump_function($$) {
2486 my $prototype = shift;
2487 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002488 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489
2490 $prototype =~ s/^static +//;
2491 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002492 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 $prototype =~ s/^inline +//;
2494 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002495 $prototype =~ s/^__inline +//;
2496 $prototype =~ s/^__always_inline +//;
2497 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002498 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002499 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002500 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002501 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002502 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002503 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002504 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505
2506 # Yes, this truly is vile. We are looking for:
2507 # 1. Return type (may be nothing if we're looking at a macro)
2508 # 2. Function name
2509 # 3. Function parameters.
2510 #
2511 # All the while we have to watch out for function pointer parameters
2512 # (which IIRC is what the two sections are for), C types (these
2513 # regexps don't even start to express all the possibilities), and
2514 # so on.
2515 #
2516 # If you mess with these regexps, it's a good idea to check that
2517 # the following functions' documentation still comes out right:
2518 # - parport_register_device (function pointer parameters)
2519 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002520 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002522 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2523 # This is an object-like macro, it has no return type and no parameter
2524 # list.
2525 # Function-like macros are not allowed to have spaces between
2526 # declaration_name and opening parenthesis (notice the \s+).
2527 $return_type = $1;
2528 $declaration_name = $2;
2529 $noret = 1;
2530 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2532 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2533 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002534 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2536 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2537 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2538 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2539 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2540 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2541 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2542 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002543 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2544 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002545 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2546 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 $return_type = $1;
2548 $declaration_name = $2;
2549 my $args = $3;
2550
2551 create_parameterlist($args, ',', $file);
2552 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002553 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 return;
2555 }
2556
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002557 my $prms = join " ", @parameterlist;
2558 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2559
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002560 # This check emits a lot of warnings at the moment, because many
2561 # functions don't have a 'Return' doc section. So until the number
2562 # of warnings goes sufficiently down, the check is only performed in
2563 # verbose mode.
2564 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002565 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002566 check_return_section($file, $declaration_name, $return_type);
2567 }
2568
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002569 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 'function',
2571 {'function' => $declaration_name,
2572 'module' => $modulename,
2573 'functiontype' => $return_type,
2574 'parameterlist' => \@parameterlist,
2575 'parameterdescs' => \%parameterdescs,
2576 'parametertypes' => \%parametertypes,
2577 'sectionlist' => \@sectionlist,
2578 'sections' => \%sections,
2579 'purpose' => $declaration_purpose
2580 });
2581}
2582
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583sub reset_state {
2584 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 %parameterdescs = ();
2586 %parametertypes = ();
2587 @parameterlist = ();
2588 %sections = ();
2589 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002590 $sectcheck = "";
2591 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002593
Jani Nikula48af6062016-05-26 14:56:05 +03002594 $state = STATE_NORMAL;
2595 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596}
2597
Jason Baron56afb0f2009-04-30 13:29:36 -04002598sub tracepoint_munge($) {
2599 my $file = shift;
2600 my $tracepointname = 0;
2601 my $tracepointargs = 0;
2602
Jason Baron3a9089f2009-12-01 12:18:49 -05002603 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002604 $tracepointname = $1;
2605 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002606 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2607 $tracepointname = $1;
2608 }
2609 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2610 $tracepointname = $2;
2611 }
2612 $tracepointname =~ s/^\s+//; #strip leading whitespace
2613 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002614 $tracepointargs = $1;
2615 }
2616 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002617 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002618 "$prototype\n";
2619 } else {
2620 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2621 }
2622}
2623
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002624sub syscall_munge() {
2625 my $void = 0;
2626
2627 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2628## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2629 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2630 $void = 1;
2631## $prototype = "long sys_$1(void)";
2632 }
2633
2634 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2635 if ($prototype =~ m/long (sys_.*?),/) {
2636 $prototype =~ s/,/\(/;
2637 } elsif ($void) {
2638 $prototype =~ s/\)/\(void\)/;
2639 }
2640
2641 # now delete all of the odd-number commas in $prototype
2642 # so that arg types & arg names don't have a comma between them
2643 my $count = 0;
2644 my $len = length($prototype);
2645 if ($void) {
2646 $len = 0; # skip the for-loop
2647 }
2648 for (my $ix = 0; $ix < $len; $ix++) {
2649 if (substr($prototype, $ix, 1) eq ',') {
2650 $count++;
2651 if ($count % 2 == 1) {
2652 substr($prototype, $ix, 1) = ' ';
2653 }
2654 }
2655 }
2656}
2657
Daniel Vetterb7afa922016-06-01 23:46:24 +02002658sub process_proto_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 my $x = shift;
2660 my $file = shift;
2661
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002662 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2663
Randy Dunlap890c78c2008-10-25 17:06:43 -07002664 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 # do nothing
2666 }
2667 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002668 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002670
Randy Dunlap890c78c2008-10-25 17:06:43 -07002671 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002672 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2674 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002675 if ($prototype =~ /SYSCALL_DEFINE/) {
2676 syscall_munge();
2677 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002678 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2679 $prototype =~ /DEFINE_SINGLE_EVENT/)
2680 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002681 tracepoint_munge($file);
2682 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002683 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 reset_state();
2685 }
2686}
2687
Daniel Vetterb7afa922016-06-01 23:46:24 +02002688sub process_proto_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 my $x = shift;
2690 my $file = shift;
2691
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2693 $x =~ s@^\s+@@gos; # strip leading spaces
2694 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002695 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2696
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 if ($x =~ /^#/) {
2698 # To distinguish preprocessor directive from regular declaration later.
2699 $x .= ";";
2700 }
2701
2702 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002703 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 $prototype .= $1 . $2;
2705 ($2 eq '{') && $brcount++;
2706 ($2 eq '}') && $brcount--;
2707 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002708 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002710 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 }
2712 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002713 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 $prototype .= $x;
2715 last;
2716 }
2717 }
2718}
2719
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002720# xml_escape: replace <, >, and & in the text stream;
2721#
2722# however, formatting controls that are generated internally/locally in the
2723# kernel-doc script are not escaped here; instead, they begin life like
2724# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2725# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2726# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727sub xml_escape($) {
2728 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002729 if (($output_mode eq "text") || ($output_mode eq "man")) {
2730 return $text;
2731 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 $text =~ s/\&/\\\\\\amp;/g;
2733 $text =~ s/\</\\\\\\lt;/g;
2734 $text =~ s/\>/\\\\\\gt;/g;
2735 return $text;
2736}
2737
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002738# xml_unescape: reverse the effects of xml_escape
2739sub xml_unescape($) {
2740 my $text = shift;
2741 if (($output_mode eq "text") || ($output_mode eq "man")) {
2742 return $text;
2743 }
2744 $text =~ s/\\\\\\amp;/\&/g;
2745 $text =~ s/\\\\\\lt;/</g;
2746 $text =~ s/\\\\\\gt;/>/g;
2747 return $text;
2748}
2749
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002750# convert local escape strings to html
2751# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2752sub local_unescape($) {
2753 my $text = shift;
2754 if (($output_mode eq "text") || ($output_mode eq "man")) {
2755 return $text;
2756 }
2757 $text =~ s/\\\\\\\\lt:/</g;
2758 $text =~ s/\\\\\\\\gt:/>/g;
2759 return $text;
2760}
2761
Jani Nikula1ad560e2016-06-07 10:53:39 +03002762sub map_filename($) {
2763 my $file;
2764 my ($orig_file) = @_;
2765
2766 if (defined($ENV{'SRCTREE'})) {
2767 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
2768 } else {
2769 $file = $orig_file;
2770 }
2771
2772 if (defined($source_map{$file})) {
2773 $file = $source_map{$file};
2774 }
2775
2776 return $file;
2777}
2778
Jani Nikula88c2b572016-06-07 11:00:52 +03002779sub process_export_file($) {
2780 my ($orig_file) = @_;
2781 my $file = map_filename($orig_file);
2782
2783 if (!open(IN,"<$file")) {
2784 print STDERR "Error: Cannot open file $file\n";
2785 ++$errors;
2786 return;
2787 }
2788
2789 while (<IN>) {
2790 if (/$export_symbol/) {
2791 $function_table{$2} = 1;
2792 }
2793 }
2794
2795 close(IN);
2796}
2797
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002799 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 my $identifier;
2801 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002802 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002803 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002805 my ($orig_file) = @_;
Jani Nikulab7886de2016-05-28 00:41:50 +03002806 my $leading_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807
Jani Nikula1ad560e2016-06-07 10:53:39 +03002808 $file = map_filename($orig_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809
2810 if (!open(IN,"<$file")) {
2811 print STDERR "Error: Cannot open file $file\n";
2812 ++$errors;
2813 return;
2814 }
2815
Ilya Dryomova9e73142010-02-26 13:05:47 -08002816 $. = 1;
2817
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 $section_counter = 0;
2819 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002820 while (s/\\\s*$//) {
2821 $_ .= <IN>;
2822 }
Jani Nikula48af6062016-05-26 14:56:05 +03002823 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002825 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002826 $in_doc_sect = 0;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002827 $declaration_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 }
Jani Nikula48af6062016-05-26 14:56:05 +03002829 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002831 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 $contents = "";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002833 $new_start_line = $. + 1;
2834
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 if ( $1 eq "" ) {
2836 $section = $section_intro;
2837 } else {
2838 $section = $1;
2839 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002840 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 elsif (/$doc_decl/o) {
2842 $identifier = $1;
2843 if (/\s*([\w\s]+?)\s*-/) {
2844 $identifier = $1;
2845 }
2846
Jani Nikula48af6062016-05-26 14:56:05 +03002847 $state = STATE_FIELD;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002848 # if there's no @param blocks need to set up default section
2849 # here
Jani Nikula2f4ad402016-05-30 11:21:06 +03002850 $contents = "";
2851 $section = $section_default;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002852 $new_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002854 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002855 $descr= $1;
2856 $descr =~ s/^\s*//;
2857 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002858 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002859 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002860 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 } else {
2862 $declaration_purpose = "";
2863 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002864
2865 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002866 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002867 print STDERR $_;
2868 ++$warnings;
2869 }
2870
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 if ($identifier =~ m/^struct/) {
2872 $decl_type = 'struct';
2873 } elsif ($identifier =~ m/^union/) {
2874 $decl_type = 'union';
2875 } elsif ($identifier =~ m/^enum/) {
2876 $decl_type = 'enum';
2877 } elsif ($identifier =~ m/^typedef/) {
2878 $decl_type = 'typedef';
2879 } else {
2880 $decl_type = 'function';
2881 }
2882
2883 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002884 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 }
2886 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002887 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 " - I thought it was a doc line\n";
2889 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002890 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 }
Jani Nikula48af6062016-05-26 14:56:05 +03002892 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Jani Nikulaf624ade2016-05-29 11:35:28 +03002893 if (/$doc_sect/i) { # case insensitive for supported section names
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 $newsection = $1;
2895 $newcontents = $2;
2896
Jani Nikulaf624ade2016-05-29 11:35:28 +03002897 # map the supported section names to the canonical names
2898 if ($newsection =~ m/^description$/i) {
2899 $newsection = $section_default;
2900 } elsif ($newsection =~ m/^context$/i) {
2901 $newsection = $section_context;
2902 } elsif ($newsection =~ m/^returns?$/i) {
2903 $newsection = $section_return;
2904 } elsif ($newsection =~ m/^\@return$/) {
2905 # special: @return is a section, not a param description
2906 $newsection = $section_return;
2907 }
2908
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002909 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002910 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002911 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002912 ++$warnings;
2913 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002914 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 $section = $section_default;
2916 }
2917
Randy Dunlap850622d2006-06-25 05:48:55 -07002918 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002919 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 $contents = $newcontents;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002921 $new_start_line = $.;
Jani Nikula0a726302016-05-28 14:50:20 +03002922 while ((substr($contents, 0, 1) eq " ") ||
2923 substr($contents, 0, 1) eq "\t") {
2924 $contents = substr($contents, 1);
2925 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 if ($contents ne "") {
2927 $contents .= "\n";
2928 }
2929 $section = $newsection;
Jani Nikulab7886de2016-05-28 00:41:50 +03002930 $leading_space = undef;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002932 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002933 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 $section = $section_default;
2935 $contents = "";
2936 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002937 # look for doc_com + <text> + doc_end:
2938 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002939 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002940 ++$warnings;
2941 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942
2943 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002944 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002946# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 } elsif (/$doc_content/) {
2948 # miguel-style comment kludge, look for blank lines after
2949 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002950 if ($1 eq "") {
2951 if ($section =~ m/^@/ || $section eq $section_context) {
2952 dump_section($file, $section, xml_escape($contents));
2953 $section = $section_default;
2954 $contents = "";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002955 $new_start_line = $.;
Johannes Weiner64231332009-09-17 19:26:53 -07002956 } else {
2957 $contents .= "\n";
2958 }
2959 $in_purpose = 0;
2960 } elsif ($in_purpose == 1) {
2961 # Continued declaration purpose
2962 chomp($declaration_purpose);
2963 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002964 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 } else {
Jani Nikulab7886de2016-05-28 00:41:50 +03002966 my $cont = $1;
2967 if ($section =~ m/^@/ || $section eq $section_context) {
2968 if (!defined $leading_space) {
2969 if ($cont =~ m/^(\s+)/) {
2970 $leading_space = $1;
2971 } else {
2972 $leading_space = "";
2973 }
2974 }
2975
2976 $cont =~ s/^$leading_space//;
2977 }
2978 $contents .= $cont . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 }
2980 } else {
2981 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002982 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 ++$warnings;
2984 }
Jani Nikula48af6062016-05-26 14:56:05 +03002985 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002986 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03002987 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002988 $section = $1;
2989 $contents = $2;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002990 $new_start_line = $.;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002991 if ($contents ne "") {
2992 while ((substr($contents, 0, 1) eq " ") ||
2993 substr($contents, 0, 1) eq "\t") {
2994 $contents = substr($contents, 1);
2995 }
Jani Nikulaa0b96c22016-05-26 22:04:06 +03002996 $contents .= "\n";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002997 }
Jani Nikula48af6062016-05-26 14:56:05 +03002998 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002999 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03003000 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003001 if (($contents ne "") && ($contents ne "\n")) {
3002 dump_section($file, $section, xml_escape($contents));
3003 $section = $section_default;
3004 $contents = "";
3005 }
Jani Nikula48af6062016-05-26 14:56:05 +03003006 $state = STATE_PROTO;
3007 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003008 # Regular text
3009 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03003010 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003011 $contents .= $1 . "\n";
Jani Nikula6450c892016-05-26 22:04:42 +03003012 # nuke leading blank lines
3013 if ($contents =~ /^\s*$/) {
3014 $contents = "";
3015 }
Jani Nikula48af6062016-05-26 14:56:05 +03003016 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
3017 $inline_doc_state = STATE_INLINE_ERROR;
Daniel Vettere7ca3112016-07-15 10:19:30 +02003018 print STDERR "${file}:$.: warning: ";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003019 print STDERR "Incorrect use of kernel-doc format: $_";
3020 ++$warnings;
3021 }
3022 }
Jani Nikula48af6062016-05-26 14:56:05 +03003023 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
3024 if (/$doc_inline_start/) {
3025 $state = STATE_INLINE;
3026 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003027 } elsif ($decl_type eq 'function') {
Daniel Vetterb7afa922016-06-01 23:46:24 +02003028 process_proto_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 } else {
Daniel Vetterb7afa922016-06-01 23:46:24 +02003030 process_proto_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 }
Jani Nikula48af6062016-05-26 14:56:05 +03003032 } elsif ($state == STATE_DOCBLOCK) {
Daniel Vetterebff7f92016-06-01 23:46:23 +02003033 if (/$doc_end/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07003035 dump_doc_section($file, $section, xml_escape($contents));
Jani Nikula2f4ad402016-05-30 11:21:06 +03003036 $section = $section_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 $contents = "";
3038 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 %parameterdescs = ();
3040 %parametertypes = ();
3041 @parameterlist = ();
3042 %sections = ();
3043 @sectionlist = ();
3044 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03003045 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 }
3047 elsif (/$doc_content/)
3048 {
3049 if ( $1 eq "" )
3050 {
3051 $contents .= $blankline;
3052 }
3053 else
3054 {
3055 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08003056 }
Randy Dunlap3c308792007-05-08 00:24:39 -07003057 }
3058 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 }
3060 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07003061 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03003062 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08003063 print STDERR " Was looking for '$_'.\n" for keys %function_table;
3064 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 if ($output_mode eq "xml") {
3066 # The template wants at least one RefEntry here; make one.
3067 print "<refentry>\n";
3068 print " <refnamediv>\n";
3069 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003070 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 print " </refname>\n";
3072 print " <refpurpose>\n";
3073 print " Document generation inconsistency\n";
3074 print " </refpurpose>\n";
3075 print " </refnamediv>\n";
3076 print " <refsect1>\n";
3077 print " <title>\n";
3078 print " Oops\n";
3079 print " </title>\n";
3080 print " <warning>\n";
3081 print " <para>\n";
3082 print " The template for this document tried to insert\n";
3083 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003084 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 print " but none was found.\n";
3086 print " This dummy section is inserted to allow\n";
3087 print " generation to continue.\n";
3088 print " </para>\n";
3089 print " </warning>\n";
3090 print " </refsect1>\n";
3091 print "</refentry>\n";
3092 }
3093 }
3094}
Randy Dunlap8484baa2011-01-05 16:28:43 -08003095
3096
3097$kernelversion = get_kernel_version();
3098
3099# generate a sequence of code that will splice in highlighting information
3100# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02003101for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03003102 my $pattern = $highlights[$k][0];
3103 my $result = $highlights[$k][1];
3104# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
3105 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08003106}
3107
3108# Read the file that maps relative names to absolute names for
3109# separate source and object directories and for shadow trees.
3110if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3111 my ($relname, $absname);
3112 while(<SOURCE_MAP>) {
3113 chop();
3114 ($relname, $absname) = (split())[0..1];
3115 $relname =~ s:^/+::;
3116 $source_map{$relname} = $absname;
3117 }
3118 close(SOURCE_MAP);
3119}
3120
Jani Nikula88c2b572016-06-07 11:00:52 +03003121if ($output_selection == OUTPUT_EXPORTED ||
3122 $output_selection == OUTPUT_INTERNAL) {
Jani Nikulac9b2cfb2016-06-07 11:05:53 +03003123
3124 push(@export_file_list, @ARGV);
3125
Jani Nikula88c2b572016-06-07 11:00:52 +03003126 foreach (@export_file_list) {
3127 chomp;
3128 process_export_file($_);
3129 }
3130}
3131
Randy Dunlap8484baa2011-01-05 16:28:43 -08003132foreach (@ARGV) {
3133 chomp;
3134 process_file($_);
3135}
3136if ($verbose && $errors) {
3137 print STDERR "$errors errors\n";
3138}
3139if ($verbose && $warnings) {
3140 print STDERR "$warnings warnings\n";
3141}
3142
Will Deacone985f5a2017-11-29 15:20:03 +00003143exit($output_mode eq "none" ? 0 : $errors);