blob: 446c0912395e1e13c7f0e24852d3f866f92ea96a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#!/usr/bin/perl -w
2
3use strict;
4
5## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ##
6## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ##
7## Copyright (C) 2001 Simon Huggins ##
Randy Dunlap70c95b02012-01-21 10:31:54 -08008## Copyright (C) 2005-2012 Randy Dunlap ##
Dan Luedtke1b40c192012-08-12 10:46:15 +02009## Copyright (C) 2012 Dan Luedtke ##
Linus Torvalds1da177e2005-04-16 15:20:36 -070010## ##
11## #define enhancements by Armin Kuster <akuster@mvista.com> ##
12## Copyright (c) 2000 MontaVista Software, Inc. ##
13## ##
14## This software falls under the GNU General Public License. ##
15## Please read the COPYING file for more information ##
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017# 18/01/2001 - Cleanups
18# Functions prototyped as foo(void) same as foo()
19# Stop eval'ing where we don't need to.
20# -- huggie@earth.li
21
22# 27/06/2001 - Allowed whitespace after initial "/**" and
23# allowed comments before function declarations.
24# -- Christian Kreibich <ck@whoop.org>
25
26# Still to do:
27# - add perldoc documentation
28# - Look more closely at some of the scarier bits :)
29
30# 26/05/2001 - Support for separate source and object trees.
31# Return error code.
32# Keith Owens <kaos@ocs.com.au>
33
34# 23/09/2001 - Added support for typedefs, structs, enums and unions
35# Support for Context section; can be terminated using empty line
36# Small fixes (like spaces vs. \s in regex)
37# -- Tim Jansen <tim@tjansen.de>
38
Dan Luedtke1b40c192012-08-12 10:46:15 +020039# 25/07/2012 - Added support for HTML5
40# -- Dan Luedtke <mail@danrl.de>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Jani Nikulafadc0b32016-05-12 16:15:36 +030042sub usage {
43 my $message = <<"EOF";
44Usage: $0 [OPTION ...] FILE ...
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Jani Nikulafadc0b32016-05-12 16:15:36 +030046Read C language source or header FILEs, extract embedded documentation comments,
47and print formatted documentation to standard output.
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Jani Nikulafadc0b32016-05-12 16:15:36 +030049The documentation comments are identified by "/**" opening comment mark. See
50Documentation/kernel-doc-nano-HOWTO.txt for the documentation comment syntax.
51
52Output format selection (mutually exclusive):
53 -docbook Output DocBook format.
54 -html Output HTML format.
55 -html5 Output HTML5 format.
56 -list Output symbol list format. This is for use by docproc.
57 -man Output troff manual page format. This is the default.
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +030058 -rst Output reStructuredText format.
Jani Nikulafadc0b32016-05-12 16:15:36 +030059 -text Output plain text format.
60
61Output selection (mutually exclusive):
Jani Nikula86ae2e32016-01-21 13:05:22 +020062 -export Only output documentation for symbols that have been
63 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
64 in the same FILE.
65 -internal Only output documentation for symbols that have NOT been
66 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
67 in the same FILE.
Jani Nikulafadc0b32016-05-12 16:15:36 +030068 -function NAME Only output documentation for the given function(s)
69 or DOC: section title(s). All other functions and DOC:
70 sections are ignored. May be specified multiple times.
71 -nofunction NAME Do NOT output documentation for the given function(s);
72 only output documentation for the other functions and
73 DOC: sections. May be specified multiple times.
74
75Output selection modifiers:
76 -no-doc-sections Do not output DOC: sections.
77
78Other parameters:
79 -v Verbose output, more warnings and other information.
80 -h Print this help.
81
82EOF
83 print $message;
84 exit 1;
85}
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87#
88# format of comments.
89# In the following table, (...)? signifies optional structure.
90# (...)* signifies 0 or more structure elements
91# /**
92# * function_name(:)? (- short description)?
93# (* @parameterx: (description of parameter x)?)*
94# (* a blank line)?
95# * (Description:)? (Description of function)?
96# * (section header: (section description)? )*
97# (*)?*/
98#
99# So .. the trivial example would be:
100#
101# /**
102# * my_function
Randy Dunlapb9d973282009-06-09 08:50:38 -0700103# */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104#
Randy Dunlap891dcd22007-02-10 01:45:53 -0800105# If the Description: header tag is omitted, then there must be a blank line
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106# after the last parameter specification.
107# e.g.
108# /**
109# * my_function - does my stuff
110# * @my_arg: its mine damnit
111# *
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800112# * Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113# */
114#
115# or, could also use:
116# /**
117# * my_function - does my stuff
118# * @my_arg: its mine damnit
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800119# * Description: Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120# */
121# etc.
122#
Randy Dunlapb9d973282009-06-09 08:50:38 -0700123# Besides functions you can also write documentation for structs, unions,
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800124# enums and typedefs. Instead of the function name you must write the name
125# of the declaration; the struct/union/enum/typedef must always precede
126# the name. Nesting of declarations is not supported.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127# Use the argument mechanism to document members or constants.
128# e.g.
129# /**
130# * struct my_struct - short description
131# * @a: first member
132# * @b: second member
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800133# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134# * Longer description
135# */
136# struct my_struct {
137# int a;
138# int b;
Martin Waitzaeec46b2005-11-13 16:08:13 -0800139# /* private: */
140# int c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141# };
142#
143# All descriptions can be multiline, except the short function description.
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800144#
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300145# For really longs structs, you can also describe arguments inside the
146# body of the struct.
147# eg.
148# /**
149# * struct my_struct - short description
150# * @a: first member
151# * @b: second member
152# *
153# * Longer description
154# */
155# struct my_struct {
156# int a;
157# int b;
158# /**
159# * @c: This is longer description of C
160# *
161# * You can use paragraphs to describe arguments
162# * using this method.
163# */
164# int c;
165# };
166#
167# This should be use only for struct/enum members.
168#
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800169# You can also add additional sections. When documenting kernel functions you
170# should document the "Context:" of the function, e.g. whether the functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171# can be called form interrupts. Unlike other sections you can end it with an
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800172# empty line.
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100173# A non-void function should have a "Return:" section describing the return
174# value(s).
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800175# Example-sections should contain the string EXAMPLE so that they are marked
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176# appropriately in DocBook.
177#
178# Example:
179# /**
180# * user_function - function that can only be called in user context
181# * @a: some argument
182# * Context: !in_interrupt()
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800183# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184# * Some description
185# * Example:
186# * user_function(22);
187# */
188# ...
189#
190#
191# All descriptive text is further processed, scanning for the following special
192# patterns, which are highlighted appropriately.
193#
194# 'funcname()' - function
195# '$ENVVAR' - environmental variable
196# '&struct_name' - name of a structure (up to two words including 'struct')
197# '@parameter' - name of a parameter
198# '%CONST' - name of a constant.
199
Randy Dunlap8484baa2011-01-05 16:28:43 -0800200## init lots of data
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202my $errors = 0;
203my $warnings = 0;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -0700204my $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206# match expressions used to find embedded type information
207my $type_constant = '\%([-_\w]+)';
208my $type_func = '(\w+)\(\)';
209my $type_param = '\@(\w+)';
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700210my $type_struct = '\&((struct\s*)*[_\w]+)';
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700211my $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212my $type_env = '(\$\w+)';
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300213my $type_enum_full = '\&(enum)\s*([_\w]+)';
214my $type_struct_full = '\&(struct)\s*([_\w]+)';
Jani Nikula47ae7ae2016-05-26 13:57:18 +0300215my $type_typedef_full = '\&(typedef)\s*([_\w]+)';
216my $type_union_full = '\&(union)\s*([_\w]+)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218# Output conversion substitutions.
219# One for each output format
220
221# these work fairly well
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300222my @highlights_html = (
223 [$type_constant, "<i>\$1</i>"],
224 [$type_func, "<b>\$1</b>"],
225 [$type_struct_xml, "<i>\$1</i>"],
226 [$type_env, "<b><i>\$1</i></b>"],
227 [$type_param, "<tt><b>\$1</b></tt>"]
228 );
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700229my $local_lt = "\\\\\\\\lt:";
230my $local_gt = "\\\\\\\\gt:";
231my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Dan Luedtke1b40c192012-08-12 10:46:15 +0200233# html version 5
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300234my @highlights_html5 = (
235 [$type_constant, "<span class=\"const\">\$1</span>"],
236 [$type_func, "<span class=\"func\">\$1</span>"],
237 [$type_struct_xml, "<span class=\"struct\">\$1</span>"],
238 [$type_env, "<span class=\"env\">\$1</span>"],
239 [$type_param, "<span class=\"param\">\$1</span>]"]
240 );
Dan Luedtke1b40c192012-08-12 10:46:15 +0200241my $blankline_html5 = $local_lt . "br /" . $local_gt;
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243# XML, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300244my @highlights_xml = (
245 ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
246 [$type_constant, "<constant>\$1</constant>"],
247 [$type_struct_xml, "<structname>\$1</structname>"],
248 [$type_param, "<parameter>\$1</parameter>"],
249 [$type_func, "<function>\$1</function>"],
250 [$type_env, "<envar>\$1</envar>"]
251 );
Johannes Berg5c98fc02007-10-24 15:08:48 -0700252my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
254# gnome, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300255my @highlights_gnome = (
256 [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
257 [$type_func, "<function>\$1</function>"],
258 [$type_struct, "<structname>\$1</structname>"],
259 [$type_env, "<envar>\$1</envar>"],
260 [$type_param, "<parameter>\$1</parameter>" ]
261 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262my $blankline_gnome = "</para><para>\n";
263
264# these are pretty rough
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300265my @highlights_man = (
266 [$type_constant, "\$1"],
267 [$type_func, "\\\\fB\$1\\\\fP"],
268 [$type_struct, "\\\\fI\$1\\\\fP"],
269 [$type_param, "\\\\fI\$1\\\\fP"]
270 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271my $blankline_man = "";
272
273# text-mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300274my @highlights_text = (
275 [$type_constant, "\$1"],
276 [$type_func, "\$1"],
277 [$type_struct, "\$1"],
278 [$type_param, "\$1"]
279 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280my $blankline_text = "";
281
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300282# rst-mode
283my @highlights_rst = (
284 [$type_constant, "``\$1``"],
Jani Nikulaa19bce62016-05-26 11:28:16 +0300285 [$type_func, "\\:c\\:func\\:`\$1()`"],
Jani Nikula62850972016-05-12 16:15:38 +0300286 [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
287 [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
Jani Nikula47ae7ae2016-05-26 13:57:18 +0300288 [$type_typedef_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
289 [$type_union_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
Jani Nikulaa7291e72016-05-26 13:57:06 +0300290 # in rst this can refer to any type
291 [$type_struct, "\\:c\\:type\\:`\$1`"],
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300292 [$type_param, "**\$1**"]
293 );
294my $blankline_rst = "\n";
295
Johannes Bergeda603f2010-09-11 15:55:22 -0700296# list mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300297my @highlights_list = (
298 [$type_constant, "\$1"],
299 [$type_func, "\$1"],
300 [$type_struct, "\$1"],
301 [$type_param, "\$1"]
302 );
Johannes Bergeda603f2010-09-11 15:55:22 -0700303my $blankline_list = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305# read arguments
Randy Dunlapb9d973282009-06-09 08:50:38 -0700306if ($#ARGV == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 usage();
308}
309
Randy Dunlap8484baa2011-01-05 16:28:43 -0800310my $kernelversion;
311my $dohighlight = "";
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313my $verbose = 0;
314my $output_mode = "man";
Daniel Santose314ba32012-10-04 17:15:08 -0700315my $output_preformatted = 0;
Johannes Berg4b445952007-10-24 15:08:48 -0700316my $no_doc_sections = 0;
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300317my @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318my $blankline = $blankline_man;
319my $modulename = "Kernel API";
Jani Nikulab6c3f452016-05-29 22:19:35 +0300320
321use constant {
322 OUTPUT_ALL => 0, # output all symbols and doc sections
323 OUTPUT_INCLUDE => 1, # output only specified symbols
324 OUTPUT_EXCLUDE => 2, # output everything except specified symbols
325 OUTPUT_EXPORTED => 3, # output exported symbols
326 OUTPUT_INTERNAL => 4, # output non-exported symbols
327};
328my $output_selection = OUTPUT_ALL;
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100329my $show_not_found = 0;
330
331my @build_time;
332if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
333 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
334 @build_time = gmtime($seconds);
335} else {
336 @build_time = localtime;
337}
338
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800339my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
340 'July', 'August', 'September', 'October',
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100341 'November', 'December')[$build_time[4]] .
342 " " . ($build_time[5]+1900);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
Randy Dunlap8484baa2011-01-05 16:28:43 -0800344# Essentially these are globals.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700345# They probably want to be tidied up, made more localised or something.
346# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347# could cause "use of undefined value" or other bugs.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700348my ($function, %function_table, %parametertypes, $declaration_purpose);
349my ($type, $declaration_name, $return_type);
Ilya Dryomov1c32fd02010-02-26 13:06:03 -0800350my ($newsection, $newcontents, $prototype, $brcount, %source_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700352if (defined($ENV{'KBUILD_VERBOSE'})) {
353 $verbose = "$ENV{'KBUILD_VERBOSE'}";
354}
355
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800356# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
358# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
359# We keep track of number of generated entries and generate a dummy
360# if needs be to ensure the expanded template can be postprocessed
361# into html.
362my $section_counter = 0;
363
364my $lineprefix="";
365
Jani Nikula48af6062016-05-26 14:56:05 +0300366# Parser states
367use constant {
368 STATE_NORMAL => 0, # normal code
369 STATE_NAME => 1, # looking for function name
370 STATE_FIELD => 2, # scanning field start
371 STATE_PROTO => 3, # scanning prototype
372 STATE_DOCBLOCK => 4, # documentation block
373 STATE_INLINE => 5, # gathering documentation outside main block
374};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700376my $in_doc_sect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Jani Nikula48af6062016-05-26 14:56:05 +0300378# Inline documentation state
379use constant {
380 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
381 STATE_INLINE_NAME => 1, # looking for member name (@foo:)
382 STATE_INLINE_TEXT => 2, # looking for member documentation
383 STATE_INLINE_END => 3, # done
384 STATE_INLINE_ERROR => 4, # error - Comment without header was found.
385 # Spit a warning as it's not
386 # proper kernel-doc and ignore the rest.
387};
388my $inline_doc_state;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390#declaration types: can be
391# 'function', 'struct', 'union', 'enum', 'typedef'
392my $decl_type;
393
394my $doc_special = "\@\%\$\&";
395
396my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
397my $doc_end = '\*/';
398my $doc_com = '\s*\*\s*';
Daniel Santos12ae6772012-10-04 17:15:10 -0700399my $doc_com_body = '\s*\* ?';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700400my $doc_decl = $doc_com . '(\w+)';
401my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700402my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700403my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Jani Nikula48af6062016-05-26 14:56:05 +0300404my $doc_inline_start = '^\s*/\*\*\s*$';
405my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
406my $doc_inline_end = '^\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200407my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409my %constants;
410my %parameterdescs;
411my @parameterlist;
412my %sections;
413my @sectionlist;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800414my $sectcheck;
415my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
417my $contents = "";
418my $section_default = "Description"; # default section
419my $section_intro = "Introduction";
420my $section = $section_default;
421my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100422my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
424my $undescribed = "-- undescribed --";
425
426reset_state();
427
428while ($ARGV[0] =~ m/^-(.*)/) {
429 my $cmd = shift @ARGV;
430 if ($cmd eq "-html") {
431 $output_mode = "html";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300432 @highlights = @highlights_html;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200434 } elsif ($cmd eq "-html5") {
435 $output_mode = "html5";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300436 @highlights = @highlights_html5;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200437 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 } elsif ($cmd eq "-man") {
439 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300440 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 $blankline = $blankline_man;
442 } elsif ($cmd eq "-text") {
443 $output_mode = "text";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300444 @highlights = @highlights_text;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 $blankline = $blankline_text;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300446 } elsif ($cmd eq "-rst") {
447 $output_mode = "rst";
448 @highlights = @highlights_rst;
449 $blankline = $blankline_rst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 } elsif ($cmd eq "-docbook") {
451 $output_mode = "xml";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300452 @highlights = @highlights_xml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700454 } elsif ($cmd eq "-list") {
455 $output_mode = "list";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300456 @highlights = @highlights_list;
Johannes Bergeda603f2010-09-11 15:55:22 -0700457 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 } elsif ($cmd eq "-gnome") {
459 $output_mode = "gnome";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300460 @highlights = @highlights_gnome;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 $blankline = $blankline_gnome;
462 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
463 $modulename = shift @ARGV;
464 } elsif ($cmd eq "-function") { # to only output specific functions
Jani Nikulab6c3f452016-05-29 22:19:35 +0300465 $output_selection = OUTPUT_INCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 $function = shift @ARGV;
467 $function_table{$function} = 1;
Jani Nikulab6c3f452016-05-29 22:19:35 +0300468 } elsif ($cmd eq "-nofunction") { # output all except specific functions
469 $output_selection = OUTPUT_EXCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 $function = shift @ARGV;
471 $function_table{$function} = 1;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200472 } elsif ($cmd eq "-export") { # only exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300473 $output_selection = OUTPUT_EXPORTED;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200474 %function_table = ()
475 } elsif ($cmd eq "-internal") { # only non-exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300476 $output_selection = OUTPUT_INTERNAL;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200477 %function_table = ()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 } elsif ($cmd eq "-v") {
479 $verbose = 1;
480 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
481 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700482 } elsif ($cmd eq '-no-doc-sections') {
483 $no_doc_sections = 1;
Johannes Berge946c43a2013-11-12 15:11:12 -0800484 } elsif ($cmd eq '-show-not-found') {
485 $show_not_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 }
487}
488
Randy Dunlap8484baa2011-01-05 16:28:43 -0800489# continue execution near EOF;
490
Borislav Petkov53f049f2007-05-08 00:30:54 -0700491# get kernel version from env
492sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700493 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700494
495 if (defined($ENV{'KERNELVERSION'})) {
496 $version = $ENV{'KERNELVERSION'};
497 }
498 return $version;
499}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500
501##
502# dumps section contents to arrays/hashes intended for that purpose.
503#
504sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700505 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 my $name = shift;
507 my $contents = join "\n", @_;
508
509 if ($name =~ m/$type_constant/) {
510 $name = $1;
511# print STDERR "constant section '$1' = '$contents'\n";
512 $constants{$name} = $contents;
513 } elsif ($name =~ m/$type_param/) {
514# print STDERR "parameter def '$1' = '$contents'\n";
515 $name = $1;
516 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800517 $sectcheck = $sectcheck . $name . " ";
Randy Dunlapced69092008-12-01 13:14:03 -0800518 } elsif ($name eq "@\.\.\.") {
519# print STDERR "parameter def '...' = '$contents'\n";
520 $name = "...";
521 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800522 $sectcheck = $sectcheck . $name . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 } else {
524# print STDERR "other section '$name' = '$contents'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700525 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Bart Van Assched40e1e62015-09-04 15:43:21 -0700526 print STDERR "${file}:$.: error: duplicate section name '$name'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700527 ++$errors;
528 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 $sections{$name} = $contents;
530 push @sectionlist, $name;
531 }
532}
533
534##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700535# dump DOC: section after checking that it should go out
536#
537sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700538 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700539 my $name = shift;
540 my $contents = join "\n", @_;
541
Johannes Berg4b445952007-10-24 15:08:48 -0700542 if ($no_doc_sections) {
543 return;
544 }
545
Jani Nikulab6c3f452016-05-29 22:19:35 +0300546 if (($output_selection == OUTPUT_ALL) ||
547 ($output_selection == OUTPUT_INCLUDE &&
548 defined($function_table{$name})) ||
549 ($output_selection == OUTPUT_EXCLUDE &&
550 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700551 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700552 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700553 output_blockhead({'sectionlist' => \@sectionlist,
554 'sections' => \%sections,
555 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300556 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700557 }
558}
559
560##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561# output function
562#
563# parameterdescs, a hash.
564# function => "function name"
565# parameterlist => @list of parameters
566# parameterdescs => %parameter descriptions
567# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800568# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800569#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
571sub output_highlight {
572 my $contents = join "\n",@_;
573 my $line;
574
575# DEBUG
576# if (!defined $contents) {
577# use Carp;
578# confess "output_highlight got called with no args?\n";
579# }
580
Dan Luedtke1b40c192012-08-12 10:46:15 +0200581 if ($output_mode eq "html" || $output_mode eq "html5" ||
582 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700583 $contents = local_unescape($contents);
584 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800585 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700586 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700587# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 eval $dohighlight;
589 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700590# print STDERR "contents af:$contents\n";
591
Dan Luedtke1b40c192012-08-12 10:46:15 +0200592# strip whitespaces when generating html5
593 if ($output_mode eq "html5") {
594 $contents =~ s/^\s+//;
595 $contents =~ s/\s+$//;
596 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700598 if (! $output_preformatted) {
599 $line =~ s/^\s*//;
600 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700601 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700602 if (! $output_preformatted) {
603 print $lineprefix, local_unescape($blankline);
604 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700606 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700607 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
608 print "\\&$line";
609 } else {
610 print $lineprefix, $line;
611 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 }
613 print "\n";
614 }
615}
616
Dan Luedtke1b40c192012-08-12 10:46:15 +0200617# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618sub output_section_html(%) {
619 my %args = %{$_[0]};
620 my $section;
621
622 foreach $section (@{$args{'sectionlist'}}) {
623 print "<h3>$section</h3>\n";
624 print "<blockquote>\n";
625 output_highlight($args{'sections'}{$section});
626 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800627 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628}
629
630# output enum in html
631sub output_enum_html(%) {
632 my %args = %{$_[0]};
633 my ($parameter);
634 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700635 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
Randy Dunlapb9d973282009-06-09 08:50:38 -0700637 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 $count = 0;
639 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700640 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 if ($count != $#{$args{'parameterlist'}}) {
642 $count++;
643 print ",\n";
644 }
645 print "<br>";
646 }
647 print "};<br>\n";
648
649 print "<h3>Constants</h3>\n";
650 print "<dl>\n";
651 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700652 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 print "<dd>";
654 output_highlight($args{'parameterdescs'}{$parameter});
655 }
656 print "</dl>\n";
657 output_section_html(@_);
658 print "<hr>\n";
659}
660
Randy Dunlapd28bee02006-02-01 03:06:57 -0800661# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662sub output_typedef_html(%) {
663 my %args = %{$_[0]};
664 my ($parameter);
665 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700666 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Randy Dunlapb9d973282009-06-09 08:50:38 -0700668 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 output_section_html(@_);
670 print "<hr>\n";
671}
672
673# output struct in html
674sub output_struct_html(%) {
675 my %args = %{$_[0]};
676 my ($parameter);
677
Randy Dunlapb9d973282009-06-09 08:50:38 -0700678 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
679 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 foreach $parameter (@{$args{'parameterlist'}}) {
681 if ($parameter =~ /^#/) {
682 print "$parameter<br>\n";
683 next;
684 }
685 my $parameter_name = $parameter;
686 $parameter_name =~ s/\[.*//;
687
Randy Dunlap3c308792007-05-08 00:24:39 -0700688 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 $type = $args{'parametertypes'}{$parameter};
690 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
691 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700692 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700694 # bitfield
695 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700697 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 }
699 }
700 print "};<br>\n";
701
702 print "<h3>Members</h3>\n";
703 print "<dl>\n";
704 foreach $parameter (@{$args{'parameterlist'}}) {
705 ($parameter =~ /^#/) && next;
706
707 my $parameter_name = $parameter;
708 $parameter_name =~ s/\[.*//;
709
Randy Dunlap3c308792007-05-08 00:24:39 -0700710 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700711 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 print "<dd>";
713 output_highlight($args{'parameterdescs'}{$parameter_name});
714 }
715 print "</dl>\n";
716 output_section_html(@_);
717 print "<hr>\n";
718}
719
720# output function in html
721sub output_function_html(%) {
722 my %args = %{$_[0]};
723 my ($parameter, $section);
724 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Randy Dunlapb9d973282009-06-09 08:50:38 -0700726 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
727 print "<i>" . $args{'functiontype'} . "</i>\n";
728 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 print "(";
730 $count = 0;
731 foreach $parameter (@{$args{'parameterlist'}}) {
732 $type = $args{'parametertypes'}{$parameter};
733 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
734 # pointer-to-function
735 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
736 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700737 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 }
739 if ($count != $#{$args{'parameterlist'}}) {
740 $count++;
741 print ",\n";
742 }
743 }
744 print ")\n";
745
746 print "<h3>Arguments</h3>\n";
747 print "<dl>\n";
748 foreach $parameter (@{$args{'parameterlist'}}) {
749 my $parameter_name = $parameter;
750 $parameter_name =~ s/\[.*//;
751
Randy Dunlap3c308792007-05-08 00:24:39 -0700752 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700753 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 print "<dd>";
755 output_highlight($args{'parameterdescs'}{$parameter_name});
756 }
757 print "</dl>\n";
758 output_section_html(@_);
759 print "<hr>\n";
760}
761
Johannes Bergb112e0f2007-10-24 15:08:48 -0700762# output DOC: block header in html
763sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 my %args = %{$_[0]};
765 my ($parameter, $section);
766 my $count;
767
768 foreach $section (@{$args{'sectionlist'}}) {
769 print "<h3>$section</h3>\n";
770 print "<ul>\n";
771 output_highlight($args{'sections'}{$section});
772 print "</ul>\n";
773 }
774 print "<hr>\n";
775}
776
Dan Luedtke1b40c192012-08-12 10:46:15 +0200777# output sections in html5
778sub output_section_html5(%) {
779 my %args = %{$_[0]};
780 my $section;
781
782 foreach $section (@{$args{'sectionlist'}}) {
783 print "<section>\n";
784 print "<h1>$section</h1>\n";
785 print "<p>\n";
786 output_highlight($args{'sections'}{$section});
787 print "</p>\n";
788 print "</section>\n";
789 }
790}
791
792# output enum in html5
793sub output_enum_html5(%) {
794 my %args = %{$_[0]};
795 my ($parameter);
796 my $count;
797 my $html5id;
798
799 $html5id = $args{'enum'};
800 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
801 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
802 print "<h1>enum " . $args{'enum'} . "</h1>\n";
803 print "<ol class=\"code\">\n";
804 print "<li>";
805 print "<span class=\"keyword\">enum</span> ";
806 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
807 print "</li>\n";
808 $count = 0;
809 foreach $parameter (@{$args{'parameterlist'}}) {
810 print "<li class=\"indent\">";
811 print "<span class=\"param\">" . $parameter . "</span>";
812 if ($count != $#{$args{'parameterlist'}}) {
813 $count++;
814 print ",";
815 }
816 print "</li>\n";
817 }
818 print "<li>};</li>\n";
819 print "</ol>\n";
820
821 print "<section>\n";
822 print "<h1>Constants</h1>\n";
823 print "<dl>\n";
824 foreach $parameter (@{$args{'parameterlist'}}) {
825 print "<dt>" . $parameter . "</dt>\n";
826 print "<dd>";
827 output_highlight($args{'parameterdescs'}{$parameter});
828 print "</dd>\n";
829 }
830 print "</dl>\n";
831 print "</section>\n";
832 output_section_html5(@_);
833 print "</article>\n";
834}
835
836# output typedef in html5
837sub output_typedef_html5(%) {
838 my %args = %{$_[0]};
839 my ($parameter);
840 my $count;
841 my $html5id;
842
843 $html5id = $args{'typedef'};
844 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
845 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
846 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
847
848 print "<ol class=\"code\">\n";
849 print "<li>";
850 print "<span class=\"keyword\">typedef</span> ";
851 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
852 print "</li>\n";
853 print "</ol>\n";
854 output_section_html5(@_);
855 print "</article>\n";
856}
857
858# output struct in html5
859sub output_struct_html5(%) {
860 my %args = %{$_[0]};
861 my ($parameter);
862 my $html5id;
863
864 $html5id = $args{'struct'};
865 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
866 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
867 print "<hgroup>\n";
868 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
869 print "<h2>". $args{'purpose'} . "</h2>\n";
870 print "</hgroup>\n";
871 print "<ol class=\"code\">\n";
872 print "<li>";
873 print "<span class=\"type\">" . $args{'type'} . "</span> ";
874 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
875 print "</li>\n";
876 foreach $parameter (@{$args{'parameterlist'}}) {
877 print "<li class=\"indent\">";
878 if ($parameter =~ /^#/) {
879 print "<span class=\"param\">" . $parameter ."</span>\n";
880 print "</li>\n";
881 next;
882 }
883 my $parameter_name = $parameter;
884 $parameter_name =~ s/\[.*//;
885
886 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
887 $type = $args{'parametertypes'}{$parameter};
888 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
889 # pointer-to-function
890 print "<span class=\"type\">$1</span> ";
891 print "<span class=\"param\">$parameter</span>";
892 print "<span class=\"type\">)</span> ";
893 print "(<span class=\"args\">$2</span>);";
894 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
895 # bitfield
896 print "<span class=\"type\">$1</span> ";
897 print "<span class=\"param\">$parameter</span>";
898 print "<span class=\"bits\">$2</span>;";
899 } else {
900 print "<span class=\"type\">$type</span> ";
901 print "<span class=\"param\">$parameter</span>;";
902 }
903 print "</li>\n";
904 }
905 print "<li>};</li>\n";
906 print "</ol>\n";
907
908 print "<section>\n";
909 print "<h1>Members</h1>\n";
910 print "<dl>\n";
911 foreach $parameter (@{$args{'parameterlist'}}) {
912 ($parameter =~ /^#/) && next;
913
914 my $parameter_name = $parameter;
915 $parameter_name =~ s/\[.*//;
916
917 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
918 print "<dt>" . $parameter . "</dt>\n";
919 print "<dd>";
920 output_highlight($args{'parameterdescs'}{$parameter_name});
921 print "</dd>\n";
922 }
923 print "</dl>\n";
924 print "</section>\n";
925 output_section_html5(@_);
926 print "</article>\n";
927}
928
929# output function in html5
930sub output_function_html5(%) {
931 my %args = %{$_[0]};
932 my ($parameter, $section);
933 my $count;
934 my $html5id;
935
936 $html5id = $args{'function'};
937 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
938 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
939 print "<hgroup>\n";
940 print "<h1>" . $args{'function'} . "</h1>";
941 print "<h2>" . $args{'purpose'} . "</h2>\n";
942 print "</hgroup>\n";
943 print "<ol class=\"code\">\n";
944 print "<li>";
945 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
946 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
947 print "</li>";
948 $count = 0;
949 foreach $parameter (@{$args{'parameterlist'}}) {
950 print "<li class=\"indent\">";
951 $type = $args{'parametertypes'}{$parameter};
952 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
953 # pointer-to-function
954 print "<span class=\"type\">$1</span> ";
955 print "<span class=\"param\">$parameter</span>";
956 print "<span class=\"type\">)</span> ";
957 print "(<span class=\"args\">$2</span>)";
958 } else {
959 print "<span class=\"type\">$type</span> ";
960 print "<span class=\"param\">$parameter</span>";
961 }
962 if ($count != $#{$args{'parameterlist'}}) {
963 $count++;
964 print ",";
965 }
966 print "</li>\n";
967 }
968 print "<li>)</li>\n";
969 print "</ol>\n";
970
971 print "<section>\n";
972 print "<h1>Arguments</h1>\n";
973 print "<p>\n";
974 print "<dl>\n";
975 foreach $parameter (@{$args{'parameterlist'}}) {
976 my $parameter_name = $parameter;
977 $parameter_name =~ s/\[.*//;
978
979 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
980 print "<dt>" . $parameter . "</dt>\n";
981 print "<dd>";
982 output_highlight($args{'parameterdescs'}{$parameter_name});
983 print "</dd>\n";
984 }
985 print "</dl>\n";
986 print "</section>\n";
987 output_section_html5(@_);
988 print "</article>\n";
989}
990
991# output DOC: block header in html5
992sub output_blockhead_html5(%) {
993 my %args = %{$_[0]};
994 my ($parameter, $section);
995 my $count;
996 my $html5id;
997
998 foreach $section (@{$args{'sectionlist'}}) {
999 $html5id = $section;
1000 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1001 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1002 print "<h1>$section</h1>\n";
1003 print "<p>\n";
1004 output_highlight($args{'sections'}{$section});
1005 print "</p>\n";
1006 }
1007 print "</article>\n";
1008}
1009
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010sub output_section_xml(%) {
1011 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001012 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 # print out each section
1014 $lineprefix=" ";
1015 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001016 print "<refsect1>\n";
1017 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001019 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001020 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001021 } else {
1022 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 }
1024 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001025 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001027 print "</programlisting></informalexample>\n";
1028 } else {
1029 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001031 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 }
1033}
1034
1035# output function in XML DocBook
1036sub output_function_xml(%) {
1037 my %args = %{$_[0]};
1038 my ($parameter, $section);
1039 my $count;
1040 my $id;
1041
Randy Dunlapb9d973282009-06-09 08:50:38 -07001042 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 $id =~ s/[^A-Za-z0-9]/-/g;
1044
Pavel Pisa5449bc92007-02-10 01:45:37 -08001045 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001046 print "<refentryinfo>\n";
1047 print " <title>LINUX</title>\n";
1048 print " <productname>Kernel Hackers Manual</productname>\n";
1049 print " <date>$man_date</date>\n";
1050 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001052 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001053 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001054 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 print "</refmeta>\n";
1056 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001057 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 print " <refpurpose>\n";
1059 print " ";
1060 output_highlight ($args{'purpose'});
1061 print " </refpurpose>\n";
1062 print "</refnamediv>\n";
1063
1064 print "<refsynopsisdiv>\n";
1065 print " <title>Synopsis</title>\n";
1066 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001067 print " <funcdef>" . $args{'functiontype'} . " ";
1068 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
1070 $count = 0;
1071 if ($#{$args{'parameterlist'}} >= 0) {
1072 foreach $parameter (@{$args{'parameterlist'}}) {
1073 $type = $args{'parametertypes'}{$parameter};
1074 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1075 # pointer-to-function
1076 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1077 print " <funcparams>$2</funcparams></paramdef>\n";
1078 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001079 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 print " <parameter>$parameter</parameter></paramdef>\n";
1081 }
1082 }
1083 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001084 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 }
1086 print " </funcprototype></funcsynopsis>\n";
1087 print "</refsynopsisdiv>\n";
1088
1089 # print parameters
1090 print "<refsect1>\n <title>Arguments</title>\n";
1091 if ($#{$args{'parameterlist'}} >= 0) {
1092 print " <variablelist>\n";
1093 foreach $parameter (@{$args{'parameterlist'}}) {
1094 my $parameter_name = $parameter;
1095 $parameter_name =~ s/\[.*//;
1096
1097 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1098 print " <listitem>\n <para>\n";
1099 $lineprefix=" ";
1100 output_highlight($args{'parameterdescs'}{$parameter_name});
1101 print " </para>\n </listitem>\n </varlistentry>\n";
1102 }
1103 print " </variablelist>\n";
1104 } else {
1105 print " <para>\n None\n </para>\n";
1106 }
1107 print "</refsect1>\n";
1108
1109 output_section_xml(@_);
1110 print "</refentry>\n\n";
1111}
1112
1113# output struct in XML DocBook
1114sub output_struct_xml(%) {
1115 my %args = %{$_[0]};
1116 my ($parameter, $section);
1117 my $id;
1118
Randy Dunlapb9d973282009-06-09 08:50:38 -07001119 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 $id =~ s/[^A-Za-z0-9]/-/g;
1121
Pavel Pisa5449bc92007-02-10 01:45:37 -08001122 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001123 print "<refentryinfo>\n";
1124 print " <title>LINUX</title>\n";
1125 print " <productname>Kernel Hackers Manual</productname>\n";
1126 print " <date>$man_date</date>\n";
1127 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001129 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001130 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001131 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 print "</refmeta>\n";
1133 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001134 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 print " <refpurpose>\n";
1136 print " ";
1137 output_highlight ($args{'purpose'});
1138 print " </refpurpose>\n";
1139 print "</refnamediv>\n";
1140
1141 print "<refsynopsisdiv>\n";
1142 print " <title>Synopsis</title>\n";
1143 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001144 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 foreach $parameter (@{$args{'parameterlist'}}) {
1146 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001147 my $prm = $parameter;
1148 # convert data read & converted thru xml_escape() into &xyz; format:
1149 # This allows us to have #define macros interspersed in a struct.
1150 $prm =~ s/\\\\\\/\&/g;
1151 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 next;
1153 }
1154
1155 my $parameter_name = $parameter;
1156 $parameter_name =~ s/\[.*//;
1157
1158 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001159 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 $type = $args{'parametertypes'}{$parameter};
1161 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1162 # pointer-to-function
1163 print " $1 $parameter) ($2);\n";
1164 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001165 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 print " $1 $parameter$2;\n";
1167 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001168 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 }
1170 }
1171 print "};";
1172 print " </programlisting>\n";
1173 print "</refsynopsisdiv>\n";
1174
1175 print " <refsect1>\n";
1176 print " <title>Members</title>\n";
1177
Randy Dunlap39f00c02008-09-22 13:57:44 -07001178 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 print " <variablelist>\n";
1180 foreach $parameter (@{$args{'parameterlist'}}) {
1181 ($parameter =~ /^#/) && next;
1182
1183 my $parameter_name = $parameter;
1184 $parameter_name =~ s/\[.*//;
1185
1186 defined($args{'parameterdescs'}{$parameter_name}) || next;
1187 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1188 print " <varlistentry>";
1189 print " <term>$parameter</term>\n";
1190 print " <listitem><para>\n";
1191 output_highlight($args{'parameterdescs'}{$parameter_name});
1192 print " </para></listitem>\n";
1193 print " </varlistentry>\n";
1194 }
1195 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001196 } else {
1197 print " <para>\n None\n </para>\n";
1198 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 print " </refsect1>\n";
1200
1201 output_section_xml(@_);
1202
1203 print "</refentry>\n\n";
1204}
1205
1206# output enum in XML DocBook
1207sub output_enum_xml(%) {
1208 my %args = %{$_[0]};
1209 my ($parameter, $section);
1210 my $count;
1211 my $id;
1212
Randy Dunlapb9d973282009-06-09 08:50:38 -07001213 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 $id =~ s/[^A-Za-z0-9]/-/g;
1215
Pavel Pisa5449bc92007-02-10 01:45:37 -08001216 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001217 print "<refentryinfo>\n";
1218 print " <title>LINUX</title>\n";
1219 print " <productname>Kernel Hackers Manual</productname>\n";
1220 print " <date>$man_date</date>\n";
1221 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001223 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001224 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001225 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 print "</refmeta>\n";
1227 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001228 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 print " <refpurpose>\n";
1230 print " ";
1231 output_highlight ($args{'purpose'});
1232 print " </refpurpose>\n";
1233 print "</refnamediv>\n";
1234
1235 print "<refsynopsisdiv>\n";
1236 print " <title>Synopsis</title>\n";
1237 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001238 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 $count = 0;
1240 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001241 print " $parameter";
1242 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243 $count++;
1244 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001245 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 print "\n";
1247 }
1248 print "};";
1249 print " </programlisting>\n";
1250 print "</refsynopsisdiv>\n";
1251
1252 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001253 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 print " <variablelist>\n";
1255 foreach $parameter (@{$args{'parameterlist'}}) {
1256 my $parameter_name = $parameter;
1257 $parameter_name =~ s/\[.*//;
1258
1259 print " <varlistentry>";
1260 print " <term>$parameter</term>\n";
1261 print " <listitem><para>\n";
1262 output_highlight($args{'parameterdescs'}{$parameter_name});
1263 print " </para></listitem>\n";
1264 print " </varlistentry>\n";
1265 }
1266 print " </variablelist>\n";
1267 print "</refsect1>\n";
1268
1269 output_section_xml(@_);
1270
1271 print "</refentry>\n\n";
1272}
1273
1274# output typedef in XML DocBook
1275sub output_typedef_xml(%) {
1276 my %args = %{$_[0]};
1277 my ($parameter, $section);
1278 my $id;
1279
Randy Dunlapb9d973282009-06-09 08:50:38 -07001280 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 $id =~ s/[^A-Za-z0-9]/-/g;
1282
Pavel Pisa5449bc92007-02-10 01:45:37 -08001283 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001284 print "<refentryinfo>\n";
1285 print " <title>LINUX</title>\n";
1286 print " <productname>Kernel Hackers Manual</productname>\n";
1287 print " <date>$man_date</date>\n";
1288 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001290 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001291 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 print "</refmeta>\n";
1293 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001294 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 print " <refpurpose>\n";
1296 print " ";
1297 output_highlight ($args{'purpose'});
1298 print " </refpurpose>\n";
1299 print "</refnamediv>\n";
1300
1301 print "<refsynopsisdiv>\n";
1302 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001303 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 print "</refsynopsisdiv>\n";
1305
1306 output_section_xml(@_);
1307
1308 print "</refentry>\n\n";
1309}
1310
1311# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001312sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 my %args = %{$_[0]};
1314 my ($parameter, $section);
1315 my $count;
1316
1317 my $id = $args{'module'};
1318 $id =~ s/[^A-Za-z0-9]/-/g;
1319
1320 # print out each section
1321 $lineprefix=" ";
1322 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001323 if (!$args{'content-only'}) {
1324 print "<refsect1>\n <title>$section</title>\n";
1325 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 if ($section =~ m/EXAMPLE/i) {
1327 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001328 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001329 } else {
1330 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 }
1332 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001333 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 if ($section =~ m/EXAMPLE/i) {
1335 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001336 } else {
1337 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001339 if (!$args{'content-only'}) {
1340 print "\n</refsect1>\n";
1341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 }
1343
1344 print "\n\n";
1345}
1346
1347# output in XML DocBook
1348sub output_function_gnome {
1349 my %args = %{$_[0]};
1350 my ($parameter, $section);
1351 my $count;
1352 my $id;
1353
Randy Dunlapb9d973282009-06-09 08:50:38 -07001354 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 $id =~ s/[^A-Za-z0-9]/-/g;
1356
1357 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001358 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359
1360 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001361 print " <funcdef>" . $args{'functiontype'} . " ";
1362 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 print "</function></funcdef>\n";
1364
1365 $count = 0;
1366 if ($#{$args{'parameterlist'}} >= 0) {
1367 foreach $parameter (@{$args{'parameterlist'}}) {
1368 $type = $args{'parametertypes'}{$parameter};
1369 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1370 # pointer-to-function
1371 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1372 print " <funcparams>$2</funcparams></paramdef>\n";
1373 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001374 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 print " <parameter>$parameter</parameter></paramdef>\n";
1376 }
1377 }
1378 } else {
1379 print " <void>\n";
1380 }
1381 print " </funcsynopsis>\n";
1382 if ($#{$args{'parameterlist'}} >= 0) {
1383 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1384 print "<tgroup cols=\"2\">\n";
1385 print "<colspec colwidth=\"2*\">\n";
1386 print "<colspec colwidth=\"8*\">\n";
1387 print "<tbody>\n";
1388 foreach $parameter (@{$args{'parameterlist'}}) {
1389 my $parameter_name = $parameter;
1390 $parameter_name =~ s/\[.*//;
1391
1392 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1393 print " <entry>\n";
1394 $lineprefix=" ";
1395 output_highlight($args{'parameterdescs'}{$parameter_name});
1396 print " </entry></row>\n";
1397 }
1398 print " </tbody></tgroup></informaltable>\n";
1399 } else {
1400 print " <para>\n None\n </para>\n";
1401 }
1402
1403 # print out each section
1404 $lineprefix=" ";
1405 foreach $section (@{$args{'sectionlist'}}) {
1406 print "<simplesect>\n <title>$section</title>\n";
1407 if ($section =~ m/EXAMPLE/i) {
1408 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001409 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 } else {
1411 }
1412 print "<para>\n";
1413 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001414 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 print "</para>\n";
1416 if ($section =~ m/EXAMPLE/i) {
1417 print "</programlisting></example>\n";
1418 } else {
1419 }
1420 print " </simplesect>\n";
1421 }
1422
1423 print "</sect2>\n\n";
1424}
1425
1426##
1427# output function in man
1428sub output_function_man(%) {
1429 my %args = %{$_[0]};
1430 my ($parameter, $section);
1431 my $count;
1432
1433 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1434
1435 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001436 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
1438 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001439 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001440 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001441 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001442 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001443 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 $count = 0;
1445 my $parenth = "(";
1446 my $post = ",";
1447 foreach my $parameter (@{$args{'parameterlist'}}) {
1448 if ($count == $#{$args{'parameterlist'}}) {
1449 $post = ");";
1450 }
1451 $type = $args{'parametertypes'}{$parameter};
1452 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1453 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001454 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 } else {
1456 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001457 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 }
1459 $count++;
1460 $parenth = "";
1461 }
1462
1463 print ".SH ARGUMENTS\n";
1464 foreach $parameter (@{$args{'parameterlist'}}) {
1465 my $parameter_name = $parameter;
1466 $parameter_name =~ s/\[.*//;
1467
Randy Dunlapb9d973282009-06-09 08:50:38 -07001468 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 output_highlight($args{'parameterdescs'}{$parameter_name});
1470 }
1471 foreach $section (@{$args{'sectionlist'}}) {
1472 print ".SH \"", uc $section, "\"\n";
1473 output_highlight($args{'sections'}{$section});
1474 }
1475}
1476
1477##
1478# output enum in man
1479sub output_enum_man(%) {
1480 my %args = %{$_[0]};
1481 my ($parameter, $section);
1482 my $count;
1483
1484 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1485
1486 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001487 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
1489 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001490 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 $count = 0;
1492 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001493 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 if ($count == $#{$args{'parameterlist'}}) {
1495 print "\n};\n";
1496 last;
1497 }
1498 else {
1499 print ", \n.br\n";
1500 }
1501 $count++;
1502 }
1503
1504 print ".SH Constants\n";
1505 foreach $parameter (@{$args{'parameterlist'}}) {
1506 my $parameter_name = $parameter;
1507 $parameter_name =~ s/\[.*//;
1508
Randy Dunlapb9d973282009-06-09 08:50:38 -07001509 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 output_highlight($args{'parameterdescs'}{$parameter_name});
1511 }
1512 foreach $section (@{$args{'sectionlist'}}) {
1513 print ".SH \"$section\"\n";
1514 output_highlight($args{'sections'}{$section});
1515 }
1516}
1517
1518##
1519# output struct in man
1520sub output_struct_man(%) {
1521 my %args = %{$_[0]};
1522 my ($parameter, $section);
1523
Randy Dunlapb9d973282009-06-09 08:50:38 -07001524 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
1526 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001527 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
1529 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001530 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
1532 foreach my $parameter (@{$args{'parameterlist'}}) {
1533 if ($parameter =~ /^#/) {
1534 print ".BI \"$parameter\"\n.br\n";
1535 next;
1536 }
1537 my $parameter_name = $parameter;
1538 $parameter_name =~ s/\[.*//;
1539
Randy Dunlap3c308792007-05-08 00:24:39 -07001540 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 $type = $args{'parametertypes'}{$parameter};
1542 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1543 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001544 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001546 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001547 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 } else {
1549 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001550 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 }
1552 print "\n.br\n";
1553 }
1554 print "};\n.br\n";
1555
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001556 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 foreach $parameter (@{$args{'parameterlist'}}) {
1558 ($parameter =~ /^#/) && next;
1559
1560 my $parameter_name = $parameter;
1561 $parameter_name =~ s/\[.*//;
1562
Randy Dunlap3c308792007-05-08 00:24:39 -07001563 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001564 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 output_highlight($args{'parameterdescs'}{$parameter_name});
1566 }
1567 foreach $section (@{$args{'sectionlist'}}) {
1568 print ".SH \"$section\"\n";
1569 output_highlight($args{'sections'}{$section});
1570 }
1571}
1572
1573##
1574# output typedef in man
1575sub output_typedef_man(%) {
1576 my %args = %{$_[0]};
1577 my ($parameter, $section);
1578
1579 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1580
1581 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001582 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583
1584 foreach $section (@{$args{'sectionlist'}}) {
1585 print ".SH \"$section\"\n";
1586 output_highlight($args{'sections'}{$section});
1587 }
1588}
1589
Johannes Bergb112e0f2007-10-24 15:08:48 -07001590sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 my %args = %{$_[0]};
1592 my ($parameter, $section);
1593 my $count;
1594
1595 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1596
1597 foreach $section (@{$args{'sectionlist'}}) {
1598 print ".SH \"$section\"\n";
1599 output_highlight($args{'sections'}{$section});
1600 }
1601}
1602
1603##
1604# output in text
1605sub output_function_text(%) {
1606 my %args = %{$_[0]};
1607 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001608 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
Randy Dunlapf47634b2006-07-01 04:36:36 -07001610 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001611 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001612
1613 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001614 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001615 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001616 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001617 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001618 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001620
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 my $count = 0;
1622 foreach my $parameter (@{$args{'parameterlist'}}) {
1623 $type = $args{'parametertypes'}{$parameter};
1624 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1625 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001626 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001628 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 }
1630 if ($count != $#{$args{'parameterlist'}}) {
1631 $count++;
1632 print ",\n";
1633 print " " x length($start);
1634 } else {
1635 print ");\n\n";
1636 }
1637 }
1638
1639 print "Arguments:\n\n";
1640 foreach $parameter (@{$args{'parameterlist'}}) {
1641 my $parameter_name = $parameter;
1642 $parameter_name =~ s/\[.*//;
1643
Randy Dunlapb9d973282009-06-09 08:50:38 -07001644 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 }
1646 output_section_text(@_);
1647}
1648
1649#output sections in text
1650sub output_section_text(%) {
1651 my %args = %{$_[0]};
1652 my $section;
1653
1654 print "\n";
1655 foreach $section (@{$args{'sectionlist'}}) {
1656 print "$section:\n\n";
1657 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001658 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 print "\n\n";
1660}
1661
1662# output enum in text
1663sub output_enum_text(%) {
1664 my %args = %{$_[0]};
1665 my ($parameter);
1666 my $count;
1667 print "Enum:\n\n";
1668
Randy Dunlapb9d973282009-06-09 08:50:38 -07001669 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1670 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 $count = 0;
1672 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001673 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 if ($count != $#{$args{'parameterlist'}}) {
1675 $count++;
1676 print ",";
1677 }
1678 print "\n";
1679 }
1680 print "};\n\n";
1681
1682 print "Constants:\n\n";
1683 foreach $parameter (@{$args{'parameterlist'}}) {
1684 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001685 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 }
1687
1688 output_section_text(@_);
1689}
1690
1691# output typedef in text
1692sub output_typedef_text(%) {
1693 my %args = %{$_[0]};
1694 my ($parameter);
1695 my $count;
1696 print "Typedef:\n\n";
1697
Randy Dunlapb9d973282009-06-09 08:50:38 -07001698 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 output_section_text(@_);
1700}
1701
1702# output struct as text
1703sub output_struct_text(%) {
1704 my %args = %{$_[0]};
1705 my ($parameter);
1706
Randy Dunlapb9d973282009-06-09 08:50:38 -07001707 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1708 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 foreach $parameter (@{$args{'parameterlist'}}) {
1710 if ($parameter =~ /^#/) {
1711 print "$parameter\n";
1712 next;
1713 }
1714
1715 my $parameter_name = $parameter;
1716 $parameter_name =~ s/\[.*//;
1717
Randy Dunlap3c308792007-05-08 00:24:39 -07001718 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 $type = $args{'parametertypes'}{$parameter};
1720 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1721 # pointer-to-function
1722 print "\t$1 $parameter) ($2);\n";
1723 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001724 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 print "\t$1 $parameter$2;\n";
1726 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001727 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 }
1729 }
1730 print "};\n\n";
1731
1732 print "Members:\n\n";
1733 foreach $parameter (@{$args{'parameterlist'}}) {
1734 ($parameter =~ /^#/) && next;
1735
1736 my $parameter_name = $parameter;
1737 $parameter_name =~ s/\[.*//;
1738
Randy Dunlap3c308792007-05-08 00:24:39 -07001739 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001741 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 }
1743 print "\n";
1744 output_section_text(@_);
1745}
1746
Johannes Bergb112e0f2007-10-24 15:08:48 -07001747sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 my %args = %{$_[0]};
1749 my ($parameter, $section);
1750
1751 foreach $section (@{$args{'sectionlist'}}) {
1752 print " $section:\n";
1753 print " -> ";
1754 output_highlight($args{'sections'}{$section});
1755 }
1756}
1757
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001758##
1759# output in restructured text
1760#
1761
1762#
1763# This could use some work; it's used to output the DOC: sections, and
1764# starts by putting out the name of the doc section itself, but that tends
1765# to duplicate a header already in the template file.
1766#
1767sub output_blockhead_rst(%) {
1768 my %args = %{$_[0]};
1769 my ($parameter, $section);
1770
1771 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001772 if ($output_selection != OUTPUT_INCLUDE) {
1773 print "**$section**\n\n";
1774 }
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001775 output_highlight_rst($args{'sections'}{$section});
1776 print "\n";
1777 }
1778}
1779
1780sub output_highlight_rst {
1781 my $contents = join "\n",@_;
1782 my $line;
1783
1784 # undo the evil effects of xml_escape() earlier
1785 $contents = xml_unescape($contents);
1786
1787 eval $dohighlight;
1788 die $@ if $@;
1789
1790 foreach $line (split "\n", $contents) {
1791 if ($line eq "") {
1792 print $lineprefix, $blankline;
1793 } else {
1794 $line =~ s/\\\\\\/\&/g;
1795 print $lineprefix, $line;
1796 }
1797 print "\n";
1798 }
1799}
1800
1801sub output_function_rst(%) {
1802 my %args = %{$_[0]};
1803 my ($parameter, $section);
1804 my $start;
1805
1806 print ".. c:function:: ";
1807 if ($args{'functiontype'} ne "") {
1808 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1809 } else {
1810 $start = $args{'function'} . " (";
1811 }
1812 print $start;
1813
1814 my $count = 0;
1815 foreach my $parameter (@{$args{'parameterlist'}}) {
1816 if ($count ne 0) {
1817 print ", ";
1818 }
1819 $count++;
1820 $type = $args{'parametertypes'}{$parameter};
1821 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1822 # pointer-to-function
1823 print $1 . $parameter . ") (" . $2;
1824 } else {
1825 print $type . " " . $parameter;
1826 }
1827 }
1828 print ")\n\n " . $args{'purpose'} . "\n\n";
1829
1830 print ":Parameters:\n\n";
1831 foreach $parameter (@{$args{'parameterlist'}}) {
1832 my $parameter_name = $parameter;
1833 #$parameter_name =~ s/\[.*//;
1834 $type = $args{'parametertypes'}{$parameter};
1835
1836 if ($type ne "") {
1837 print " ``$type $parameter``\n";
1838 } else {
1839 print " ``$parameter``\n";
1840 }
Jani Nikula5e64fa92016-05-19 20:32:48 +03001841 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1842 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001843 my $oldprefix = $lineprefix;
1844 $lineprefix = " ";
1845 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
1846 $lineprefix = $oldprefix;
1847 } else {
1848 print "\n _undescribed_\n";
1849 }
1850 print "\n";
1851 }
1852 output_section_rst(@_);
1853}
1854
1855sub output_section_rst(%) {
1856 my %args = %{$_[0]};
1857 my $section;
1858 my $oldprefix = $lineprefix;
1859 $lineprefix = " ";
1860
1861 foreach $section (@{$args{'sectionlist'}}) {
1862 print ":$section:\n\n";
1863 output_highlight_rst($args{'sections'}{$section});
1864 print "\n";
1865 }
1866 print "\n";
1867 $lineprefix = $oldprefix;
1868}
1869
1870sub output_enum_rst(%) {
1871 my %args = %{$_[0]};
1872 my ($parameter);
1873 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001874 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001875
1876 print "\n\n.. c:type:: " . $name . "\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001877 print " " . $args{'purpose'} . "\n\n";
1878
1879 print "..\n\n:Constants:\n\n";
1880 my $oldprefix = $lineprefix;
1881 $lineprefix = " ";
1882 foreach $parameter (@{$args{'parameterlist'}}) {
1883 print " `$parameter`\n";
1884 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1885 output_highlight_rst($args{'parameterdescs'}{$parameter});
1886 } else {
1887 print " undescribed\n";
1888 }
1889 print "\n";
1890 }
1891 $lineprefix = $oldprefix;
1892 output_section_rst(@_);
1893}
1894
1895sub output_typedef_rst(%) {
1896 my %args = %{$_[0]};
1897 my ($parameter);
1898 my $count;
1899 my $name = "typedef " . $args{'typedef'};
1900
Jani Nikula62850972016-05-12 16:15:38 +03001901 ### FIXME: should the name below contain "typedef" or not?
1902 print "\n\n.. c:type:: " . $name . "\n\n";
1903 print " " . $args{'purpose'} . "\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001904
1905 output_section_rst(@_);
1906}
1907
1908sub output_struct_rst(%) {
1909 my %args = %{$_[0]};
1910 my ($parameter);
1911 my $name = $args{'type'} . " " . $args{'struct'};
1912
Jani Nikula62850972016-05-12 16:15:38 +03001913 print "\n\n.. c:type:: " . $name . "\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001914 print " " . $args{'purpose'} . "\n\n";
1915
1916 print ":Definition:\n\n";
1917 print " ::\n\n";
1918 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1919 foreach $parameter (@{$args{'parameterlist'}}) {
1920 if ($parameter =~ /^#/) {
1921 print " " . "$parameter\n";
1922 next;
1923 }
1924
1925 my $parameter_name = $parameter;
1926 $parameter_name =~ s/\[.*//;
1927
1928 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1929 $type = $args{'parametertypes'}{$parameter};
1930 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1931 # pointer-to-function
1932 print " $1 $parameter) ($2);\n";
1933 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1934 # bitfield
1935 print " $1 $parameter$2;\n";
1936 } else {
1937 print " " . $type . " " . $parameter . ";\n";
1938 }
1939 }
1940 print " };\n\n";
1941
1942 print ":Members:\n\n";
1943 foreach $parameter (@{$args{'parameterlist'}}) {
1944 ($parameter =~ /^#/) && next;
1945
1946 my $parameter_name = $parameter;
1947 $parameter_name =~ s/\[.*//;
1948
1949 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1950 $type = $args{'parametertypes'}{$parameter};
1951 print " `$type $parameter`" . "\n";
1952 my $oldprefix = $lineprefix;
1953 $lineprefix = " ";
1954 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
1955 $lineprefix = $oldprefix;
1956 print "\n";
1957 }
1958 print "\n";
1959 output_section_rst(@_);
1960}
1961
1962
Johannes Bergeda603f2010-09-11 15:55:22 -07001963## list mode output functions
1964
1965sub output_function_list(%) {
1966 my %args = %{$_[0]};
1967
1968 print $args{'function'} . "\n";
1969}
1970
1971# output enum in list
1972sub output_enum_list(%) {
1973 my %args = %{$_[0]};
1974 print $args{'enum'} . "\n";
1975}
1976
1977# output typedef in list
1978sub output_typedef_list(%) {
1979 my %args = %{$_[0]};
1980 print $args{'typedef'} . "\n";
1981}
1982
1983# output struct as list
1984sub output_struct_list(%) {
1985 my %args = %{$_[0]};
1986
1987 print $args{'struct'} . "\n";
1988}
1989
1990sub output_blockhead_list(%) {
1991 my %args = %{$_[0]};
1992 my ($parameter, $section);
1993
1994 foreach $section (@{$args{'sectionlist'}}) {
1995 print "DOC: $section\n";
1996 }
1997}
1998
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999##
Randy Dunlap27205742006-10-11 01:22:12 -07002000# generic output function for all types (function, struct/union, typedef, enum);
2001# calls the generated, variable output_ function name based on
2002# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003sub output_declaration {
2004 no strict 'refs';
2005 my $name = shift;
2006 my $functype = shift;
2007 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002008 if (($output_selection == OUTPUT_ALL) ||
2009 (($output_selection == OUTPUT_INCLUDE ||
2010 $output_selection == OUTPUT_EXPORTED) &&
2011 defined($function_table{$name})) ||
2012 (($output_selection == OUTPUT_EXCLUDE ||
2013 $output_selection == OUTPUT_INTERNAL) &&
2014 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002016 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 $section_counter++;
2018 }
2019}
2020
2021##
Randy Dunlap27205742006-10-11 01:22:12 -07002022# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002023sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002025 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 &$func(@_);
2027 $section_counter++;
2028}
2029
2030##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002031# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032# invokes the right handler. NOT called for functions.
2033sub dump_declaration($$) {
2034 no strict 'refs';
2035 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002036 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 &$func(@_);
2038}
2039
2040sub dump_union($$) {
2041 dump_struct(@_);
2042}
2043
2044sub dump_struct($$) {
2045 my $x = shift;
2046 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002047 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002049 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2050 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002051 $declaration_name = $2;
2052 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
2054 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002055 $members =~ s/({.*})//g;
2056 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
Martin Waitzaeec46b2005-11-13 16:08:13 -08002058 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002059 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2060 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002061 # strip comments:
2062 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002063 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002064 # strip kmemcheck_bitfield_{begin,end}.*;
2065 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002066 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002067 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002068 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002069 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002070 # replace DECLARE_BITMAP
2071 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002072
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002074 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075
2076 output_declaration($declaration_name,
2077 'struct',
2078 {'struct' => $declaration_name,
2079 'module' => $modulename,
2080 'parameterlist' => \@parameterlist,
2081 'parameterdescs' => \%parameterdescs,
2082 'parametertypes' => \%parametertypes,
2083 'sectionlist' => \@sectionlist,
2084 'sections' => \%sections,
2085 'purpose' => $declaration_purpose,
2086 'type' => $decl_type
2087 });
2088 }
2089 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002090 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 ++$errors;
2092 }
2093}
2094
2095sub dump_enum($$) {
2096 my $x = shift;
2097 my $file = shift;
2098
Martin Waitzaeec46b2005-11-13 16:08:13 -08002099 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002100 # strip #define macros inside enums
2101 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002102
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002104 $declaration_name = $1;
2105 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106
2107 foreach my $arg (split ',', $members) {
2108 $arg =~ s/^\s*(\w+).*/$1/;
2109 push @parameterlist, $arg;
2110 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002111 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002112 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 "not described in enum '$declaration_name'\n";
2114 }
2115
2116 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002117
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 output_declaration($declaration_name,
2119 'enum',
2120 {'enum' => $declaration_name,
2121 'module' => $modulename,
2122 'parameterlist' => \@parameterlist,
2123 'parameterdescs' => \%parameterdescs,
2124 'sectionlist' => \@sectionlist,
2125 'sections' => \%sections,
2126 'purpose' => $declaration_purpose
2127 });
2128 }
2129 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002130 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 ++$errors;
2132 }
2133}
2134
2135sub dump_typedef($$) {
2136 my $x = shift;
2137 my $file = shift;
2138
Martin Waitzaeec46b2005-11-13 16:08:13 -08002139 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002140
2141 # Parse function prototypes
2142 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
2143 # Function typedefs
2144 $return_type = $1;
2145 $declaration_name = $2;
2146 my $args = $3;
2147
2148 create_parameterlist($args, ',', $file);
2149
2150 output_declaration($declaration_name,
2151 'function',
2152 {'function' => $declaration_name,
2153 'module' => $modulename,
2154 'functiontype' => $return_type,
2155 'parameterlist' => \@parameterlist,
2156 'parameterdescs' => \%parameterdescs,
2157 'parametertypes' => \%parametertypes,
2158 'sectionlist' => \@sectionlist,
2159 'sections' => \%sections,
2160 'purpose' => $declaration_purpose
2161 });
2162 return;
2163 }
2164
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002166 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 $x =~ s/\[*.\]\s*;$/;/;
2168 }
2169
2170 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002171 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
2173 output_declaration($declaration_name,
2174 'typedef',
2175 {'typedef' => $declaration_name,
2176 'module' => $modulename,
2177 'sectionlist' => \@sectionlist,
2178 'sections' => \%sections,
2179 'purpose' => $declaration_purpose
2180 });
2181 }
2182 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002183 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 ++$errors;
2185 }
2186}
2187
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002188sub save_struct_actual($) {
2189 my $actual = shift;
2190
2191 # strip all spaces from the actual param so that it looks like one string item
2192 $actual =~ s/\s*//g;
2193 $struct_actual = $struct_actual . $actual . " ";
2194}
2195
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196sub create_parameterlist($$$) {
2197 my $args = shift;
2198 my $splitter = shift;
2199 my $file = shift;
2200 my $type;
2201 my $param;
2202
Martin Waitza6d3fe72006-01-09 20:53:55 -08002203 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002205 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002207
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 foreach my $arg (split($splitter, $args)) {
2209 # strip comments
2210 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002211 # strip leading/trailing spaces
2212 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 $arg =~ s/\s*$//;
2214 $arg =~ s/\s+/ /;
2215
2216 if ($arg =~ /^#/) {
2217 # Treat preprocessor directive as a typeless variable just to fill
2218 # corresponding data structures "correctly". Catch it later in
2219 # output_* subs.
2220 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002221 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 # pointer-to-function
2223 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002224 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 $param = $1;
2226 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002227 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002228 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002230 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 $arg =~ s/\s*:\s*/:/g;
2232 $arg =~ s/\s*\[/\[/g;
2233
2234 my @args = split('\s*,\s*', $arg);
2235 if ($args[0] =~ m/\*/) {
2236 $args[0] =~ s/(\*+)\s*/ $1/;
2237 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002238
2239 my @first_arg;
2240 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2241 shift @args;
2242 push(@first_arg, split('\s+', $1));
2243 push(@first_arg, $2);
2244 } else {
2245 @first_arg = split('\s+', shift @args);
2246 }
2247
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 unshift(@args, pop @first_arg);
2249 $type = join " ", @first_arg;
2250
2251 foreach $param (@args) {
2252 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002253 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 push_parameter($2, "$type $1", $file);
2255 }
2256 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002257 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002258 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002259 push_parameter($1, "$type:$2", $file)
2260 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 }
2262 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002263 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 push_parameter($param, $type, $file);
2265 }
2266 }
2267 }
2268 }
2269}
2270
2271sub push_parameter($$$) {
2272 my $param = shift;
2273 my $type = shift;
2274 my $file = shift;
2275
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002276 if (($anon_struct_union == 1) && ($type eq "") &&
2277 ($param eq "}")) {
2278 return; # ignore the ending }; from anon. struct/union
2279 }
2280
2281 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 my $param_name = $param;
2283 $param_name =~ s/\[.*//;
2284
Martin Waitza6d3fe72006-01-09 20:53:55 -08002285 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 {
Randy Dunlapced69092008-12-01 13:14:03 -08002287 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2288 $parameterdescs{$param} = "variable arguments";
2289 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 }
2291 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2292 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 $param="void";
2294 $parameterdescs{void} = "no arguments";
2295 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002296 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2297 # handle unnamed (anonymous) union or struct:
2298 {
2299 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002300 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002301 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002302 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002303 }
2304
Martin Waitza6d3fe72006-01-09 20:53:55 -08002305 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002306 # (but ignore ones starting with # as these are not parameters
2307 # but inline preprocessor statements);
2308 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002309 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002310 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2311
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 $parameterdescs{$param_name} = $undescribed;
2313
2314 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002315 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 "or member '$param' not " .
2317 "described in '$declaration_name'\n";
2318 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002319 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002320 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002322 }
2323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002325 $param = xml_escape($param);
2326
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002327 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002328 # on @parameterlist;
2329 # this fixes a problem where check_sections() cannot find
2330 # a parameter like "addr[6 + 2]" because it actually appears
2331 # as "addr[6", "+", "2]" on the parameter list;
2332 # but it's better to maintain the param string unchanged for output,
2333 # so just weaken the string compare in check_sections() to ignore
2334 # "[blah" in a parameter string;
2335 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 push @parameterlist, $param;
2337 $parametertypes{$param} = $type;
2338}
2339
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002340sub check_sections($$$$$$) {
2341 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2342 my @sects = split ' ', $sectcheck;
2343 my @prms = split ' ', $prmscheck;
2344 my $err;
2345 my ($px, $sx);
2346 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2347
2348 foreach $sx (0 .. $#sects) {
2349 $err = 1;
2350 foreach $px (0 .. $#prms) {
2351 $prm_clean = $prms[$px];
2352 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002353 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002354 # ignore array size in a parameter string;
2355 # however, the original param string may contain
2356 # spaces, e.g.: addr[6 + 2]
2357 # and this appears in @prms as "addr[6" since the
2358 # parameter list is split at spaces;
2359 # hence just ignore "[..." for the sections check;
2360 $prm_clean =~ s/\[.*//;
2361
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002362 ##$prm_clean =~ s/^\**//;
2363 if ($prm_clean eq $sects[$sx]) {
2364 $err = 0;
2365 last;
2366 }
2367 }
2368 if ($err) {
2369 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002370 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002371 "Excess function parameter " .
2372 "'$sects[$sx]' " .
2373 "description in '$decl_name'\n";
2374 ++$warnings;
2375 } else {
2376 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002377 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002378 "Excess struct/union/enum/typedef member " .
2379 "'$sects[$sx]' " .
2380 "description in '$decl_name'\n";
2381 ++$warnings;
2382 }
2383 }
2384 }
2385 }
2386}
2387
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002389# Checks the section describing the return value of a function.
2390sub check_return_section {
2391 my $file = shift;
2392 my $declaration_name = shift;
2393 my $return_type = shift;
2394
2395 # Ignore an empty return type (It's a macro)
2396 # Ignore functions with a "void" return type. (But don't ignore "void *")
2397 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2398 return;
2399 }
2400
2401 if (!defined($sections{$section_return}) ||
2402 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002403 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002404 "No description found for return value of " .
2405 "'$declaration_name'\n";
2406 ++$warnings;
2407 }
2408}
2409
2410##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411# takes a function prototype and the name of the current file being
2412# processed and spits out all the details stored in the global
2413# arrays/hashes.
2414sub dump_function($$) {
2415 my $prototype = shift;
2416 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002417 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418
2419 $prototype =~ s/^static +//;
2420 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002421 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 $prototype =~ s/^inline +//;
2423 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002424 $prototype =~ s/^__inline +//;
2425 $prototype =~ s/^__always_inline +//;
2426 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002427 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002428 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002429 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002430 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002431 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002432 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002433 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434
2435 # Yes, this truly is vile. We are looking for:
2436 # 1. Return type (may be nothing if we're looking at a macro)
2437 # 2. Function name
2438 # 3. Function parameters.
2439 #
2440 # All the while we have to watch out for function pointer parameters
2441 # (which IIRC is what the two sections are for), C types (these
2442 # regexps don't even start to express all the possibilities), and
2443 # so on.
2444 #
2445 # If you mess with these regexps, it's a good idea to check that
2446 # the following functions' documentation still comes out right:
2447 # - parport_register_device (function pointer parameters)
2448 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002449 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002451 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2452 # This is an object-like macro, it has no return type and no parameter
2453 # list.
2454 # Function-like macros are not allowed to have spaces between
2455 # declaration_name and opening parenthesis (notice the \s+).
2456 $return_type = $1;
2457 $declaration_name = $2;
2458 $noret = 1;
2459 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2461 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2462 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002463 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2465 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2466 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2467 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2468 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2469 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2470 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2471 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002472 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2473 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002474 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2475 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 $return_type = $1;
2477 $declaration_name = $2;
2478 my $args = $3;
2479
2480 create_parameterlist($args, ',', $file);
2481 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002482 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 return;
2484 }
2485
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002486 my $prms = join " ", @parameterlist;
2487 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2488
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002489 # This check emits a lot of warnings at the moment, because many
2490 # functions don't have a 'Return' doc section. So until the number
2491 # of warnings goes sufficiently down, the check is only performed in
2492 # verbose mode.
2493 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002494 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002495 check_return_section($file, $declaration_name, $return_type);
2496 }
2497
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002498 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 'function',
2500 {'function' => $declaration_name,
2501 'module' => $modulename,
2502 'functiontype' => $return_type,
2503 'parameterlist' => \@parameterlist,
2504 'parameterdescs' => \%parameterdescs,
2505 'parametertypes' => \%parametertypes,
2506 'sectionlist' => \@sectionlist,
2507 'sections' => \%sections,
2508 'purpose' => $declaration_purpose
2509 });
2510}
2511
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512sub reset_state {
2513 $function = "";
2514 %constants = ();
2515 %parameterdescs = ();
2516 %parametertypes = ();
2517 @parameterlist = ();
2518 %sections = ();
2519 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002520 $sectcheck = "";
2521 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002523
Jani Nikula48af6062016-05-26 14:56:05 +03002524 $state = STATE_NORMAL;
2525 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526}
2527
Jason Baron56afb0f2009-04-30 13:29:36 -04002528sub tracepoint_munge($) {
2529 my $file = shift;
2530 my $tracepointname = 0;
2531 my $tracepointargs = 0;
2532
Jason Baron3a9089f2009-12-01 12:18:49 -05002533 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002534 $tracepointname = $1;
2535 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002536 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2537 $tracepointname = $1;
2538 }
2539 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2540 $tracepointname = $2;
2541 }
2542 $tracepointname =~ s/^\s+//; #strip leading whitespace
2543 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002544 $tracepointargs = $1;
2545 }
2546 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002547 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002548 "$prototype\n";
2549 } else {
2550 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2551 }
2552}
2553
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002554sub syscall_munge() {
2555 my $void = 0;
2556
2557 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2558## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2559 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2560 $void = 1;
2561## $prototype = "long sys_$1(void)";
2562 }
2563
2564 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2565 if ($prototype =~ m/long (sys_.*?),/) {
2566 $prototype =~ s/,/\(/;
2567 } elsif ($void) {
2568 $prototype =~ s/\)/\(void\)/;
2569 }
2570
2571 # now delete all of the odd-number commas in $prototype
2572 # so that arg types & arg names don't have a comma between them
2573 my $count = 0;
2574 my $len = length($prototype);
2575 if ($void) {
2576 $len = 0; # skip the for-loop
2577 }
2578 for (my $ix = 0; $ix < $len; $ix++) {
2579 if (substr($prototype, $ix, 1) eq ',') {
2580 $count++;
2581 if ($count % 2 == 1) {
2582 substr($prototype, $ix, 1) = ' ';
2583 }
2584 }
2585 }
2586}
2587
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002588sub process_state3_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 my $x = shift;
2590 my $file = shift;
2591
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002592 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2593
Randy Dunlap890c78c2008-10-25 17:06:43 -07002594 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 # do nothing
2596 }
2597 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002598 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002600
Randy Dunlap890c78c2008-10-25 17:06:43 -07002601 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002602 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2604 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002605 if ($prototype =~ /SYSCALL_DEFINE/) {
2606 syscall_munge();
2607 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002608 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2609 $prototype =~ /DEFINE_SINGLE_EVENT/)
2610 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002611 tracepoint_munge($file);
2612 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002613 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 reset_state();
2615 }
2616}
2617
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002618sub process_state3_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 my $x = shift;
2620 my $file = shift;
2621
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2623 $x =~ s@^\s+@@gos; # strip leading spaces
2624 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002625 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2626
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 if ($x =~ /^#/) {
2628 # To distinguish preprocessor directive from regular declaration later.
2629 $x .= ";";
2630 }
2631
2632 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002633 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 $prototype .= $1 . $2;
2635 ($2 eq '{') && $brcount++;
2636 ($2 eq '}') && $brcount--;
2637 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002638 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002640 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 }
2642 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002643 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 $prototype .= $x;
2645 last;
2646 }
2647 }
2648}
2649
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002650# xml_escape: replace <, >, and & in the text stream;
2651#
2652# however, formatting controls that are generated internally/locally in the
2653# kernel-doc script are not escaped here; instead, they begin life like
2654# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2655# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2656# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657sub xml_escape($) {
2658 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002659 if (($output_mode eq "text") || ($output_mode eq "man")) {
2660 return $text;
2661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 $text =~ s/\&/\\\\\\amp;/g;
2663 $text =~ s/\</\\\\\\lt;/g;
2664 $text =~ s/\>/\\\\\\gt;/g;
2665 return $text;
2666}
2667
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002668# xml_unescape: reverse the effects of xml_escape
2669sub xml_unescape($) {
2670 my $text = shift;
2671 if (($output_mode eq "text") || ($output_mode eq "man")) {
2672 return $text;
2673 }
2674 $text =~ s/\\\\\\amp;/\&/g;
2675 $text =~ s/\\\\\\lt;/</g;
2676 $text =~ s/\\\\\\gt;/>/g;
2677 return $text;
2678}
2679
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002680# convert local escape strings to html
2681# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2682sub local_unescape($) {
2683 my $text = shift;
2684 if (($output_mode eq "text") || ($output_mode eq "man")) {
2685 return $text;
2686 }
2687 $text =~ s/\\\\\\\\lt:/</g;
2688 $text =~ s/\\\\\\\\gt:/>/g;
2689 return $text;
2690}
2691
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002693 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 my $identifier;
2695 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002696 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002697 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002699 my ($orig_file) = @_;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700
Randy Dunlap2283a112005-07-07 15:39:26 -07002701 if (defined($ENV{'SRCTREE'})) {
Ben Hutchings68f86662015-09-01 23:48:49 +01002702 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002703 }
2704 else {
Ben Hutchings68f86662015-09-01 23:48:49 +01002705 $file = $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002706 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 if (defined($source_map{$file})) {
2708 $file = $source_map{$file};
2709 }
2710
2711 if (!open(IN,"<$file")) {
2712 print STDERR "Error: Cannot open file $file\n";
2713 ++$errors;
2714 return;
2715 }
2716
Jani Nikula86ae2e32016-01-21 13:05:22 +02002717 # two passes for -export and -internal
Jani Nikulab6c3f452016-05-29 22:19:35 +03002718 if ($output_selection == OUTPUT_EXPORTED ||
2719 $output_selection == OUTPUT_INTERNAL) {
Jani Nikula86ae2e32016-01-21 13:05:22 +02002720 while (<IN>) {
2721 if (/$export_symbol/o) {
2722 $function_table{$2} = 1;
2723 }
2724 }
2725 seek(IN, 0, 0);
2726 }
2727
Ilya Dryomova9e73142010-02-26 13:05:47 -08002728 $. = 1;
2729
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 $section_counter = 0;
2731 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002732 while (s/\\\s*$//) {
2733 $_ .= <IN>;
2734 }
Jani Nikula48af6062016-05-26 14:56:05 +03002735 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002737 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002738 $in_doc_sect = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 }
Jani Nikula48af6062016-05-26 14:56:05 +03002740 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002742 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 $contents = "";
2744 if ( $1 eq "" ) {
2745 $section = $section_intro;
2746 } else {
2747 $section = $1;
2748 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 elsif (/$doc_decl/o) {
2751 $identifier = $1;
2752 if (/\s*([\w\s]+?)\s*-/) {
2753 $identifier = $1;
2754 }
2755
Jani Nikula48af6062016-05-26 14:56:05 +03002756 $state = STATE_FIELD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002758 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002759 $descr= $1;
2760 $descr =~ s/^\s*//;
2761 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002762 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002763 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002764 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 } else {
2766 $declaration_purpose = "";
2767 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002768
2769 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002770 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002771 print STDERR $_;
2772 ++$warnings;
2773 }
2774
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 if ($identifier =~ m/^struct/) {
2776 $decl_type = 'struct';
2777 } elsif ($identifier =~ m/^union/) {
2778 $decl_type = 'union';
2779 } elsif ($identifier =~ m/^enum/) {
2780 $decl_type = 'enum';
2781 } elsif ($identifier =~ m/^typedef/) {
2782 $decl_type = 'typedef';
2783 } else {
2784 $decl_type = 'function';
2785 }
2786
2787 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002788 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 }
2790 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002791 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 " - I thought it was a doc line\n";
2793 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002794 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 }
Jani Nikula48af6062016-05-26 14:56:05 +03002796 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 if (/$doc_sect/o) {
2798 $newsection = $1;
2799 $newcontents = $2;
2800
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002801 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002802 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002803 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002804 ++$warnings;
2805 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002806 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 $section = $section_default;
2808 }
2809
Randy Dunlap850622d2006-06-25 05:48:55 -07002810 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002811 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 $contents = $newcontents;
2813 if ($contents ne "") {
Randy Dunlap27205742006-10-11 01:22:12 -07002814 while ((substr($contents, 0, 1) eq " ") ||
2815 substr($contents, 0, 1) eq "\t") {
2816 $contents = substr($contents, 1);
Randy Dunlap05189492006-06-25 05:47:47 -07002817 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 $contents .= "\n";
2819 }
2820 $section = $newsection;
2821 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002822 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002823 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 $section = $section_default;
2825 $contents = "";
2826 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002827 # look for doc_com + <text> + doc_end:
2828 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002829 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002830 ++$warnings;
2831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832
2833 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002834 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002836# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 } elsif (/$doc_content/) {
2838 # miguel-style comment kludge, look for blank lines after
2839 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002840 if ($1 eq "") {
2841 if ($section =~ m/^@/ || $section eq $section_context) {
2842 dump_section($file, $section, xml_escape($contents));
2843 $section = $section_default;
2844 $contents = "";
2845 } else {
2846 $contents .= "\n";
2847 }
2848 $in_purpose = 0;
2849 } elsif ($in_purpose == 1) {
2850 # Continued declaration purpose
2851 chomp($declaration_purpose);
2852 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002853 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002855 $contents .= $1 . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 }
2857 } else {
2858 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002859 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 ++$warnings;
2861 }
Jani Nikula48af6062016-05-26 14:56:05 +03002862 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002863 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03002864 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002865 $section = $1;
2866 $contents = $2;
2867 if ($contents ne "") {
2868 while ((substr($contents, 0, 1) eq " ") ||
2869 substr($contents, 0, 1) eq "\t") {
2870 $contents = substr($contents, 1);
2871 }
2872 $contents .= "\n";
2873 }
Jani Nikula48af6062016-05-26 14:56:05 +03002874 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002875 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03002876 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002877 if (($contents ne "") && ($contents ne "\n")) {
2878 dump_section($file, $section, xml_escape($contents));
2879 $section = $section_default;
2880 $contents = "";
2881 }
Jani Nikula48af6062016-05-26 14:56:05 +03002882 $state = STATE_PROTO;
2883 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002884 # Regular text
2885 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03002886 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002887 $contents .= $1 . "\n";
Jani Nikula48af6062016-05-26 14:56:05 +03002888 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
2889 $inline_doc_state = STATE_INLINE_ERROR;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002890 print STDERR "Warning(${file}:$.): ";
2891 print STDERR "Incorrect use of kernel-doc format: $_";
2892 ++$warnings;
2893 }
2894 }
Jani Nikula48af6062016-05-26 14:56:05 +03002895 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
2896 if (/$doc_inline_start/) {
2897 $state = STATE_INLINE;
2898 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002899 } elsif ($decl_type eq 'function') {
Randy Dunlap3c308792007-05-08 00:24:39 -07002900 process_state3_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -07002902 process_state3_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 }
Jani Nikula48af6062016-05-26 14:56:05 +03002904 } elsif ($state == STATE_DOCBLOCK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 # Documentation block
Randy Dunlap3c308792007-05-08 00:24:39 -07002906 if (/$doc_block/) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002907 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 $contents = "";
2909 $function = "";
2910 %constants = ();
2911 %parameterdescs = ();
2912 %parametertypes = ();
2913 @parameterlist = ();
2914 %sections = ();
2915 @sectionlist = ();
2916 $prototype = "";
2917 if ( $1 eq "" ) {
2918 $section = $section_intro;
2919 } else {
2920 $section = $1;
2921 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002922 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 elsif (/$doc_end/)
2924 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002925 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 $contents = "";
2927 $function = "";
2928 %constants = ();
2929 %parameterdescs = ();
2930 %parametertypes = ();
2931 @parameterlist = ();
2932 %sections = ();
2933 @sectionlist = ();
2934 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002935 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 }
2937 elsif (/$doc_content/)
2938 {
2939 if ( $1 eq "" )
2940 {
2941 $contents .= $blankline;
2942 }
2943 else
2944 {
2945 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002946 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002947 }
2948 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 }
2950 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002951 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002952 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08002953 print STDERR " Was looking for '$_'.\n" for keys %function_table;
2954 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 if ($output_mode eq "xml") {
2956 # The template wants at least one RefEntry here; make one.
2957 print "<refentry>\n";
2958 print " <refnamediv>\n";
2959 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01002960 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 print " </refname>\n";
2962 print " <refpurpose>\n";
2963 print " Document generation inconsistency\n";
2964 print " </refpurpose>\n";
2965 print " </refnamediv>\n";
2966 print " <refsect1>\n";
2967 print " <title>\n";
2968 print " Oops\n";
2969 print " </title>\n";
2970 print " <warning>\n";
2971 print " <para>\n";
2972 print " The template for this document tried to insert\n";
2973 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01002974 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 print " but none was found.\n";
2976 print " This dummy section is inserted to allow\n";
2977 print " generation to continue.\n";
2978 print " </para>\n";
2979 print " </warning>\n";
2980 print " </refsect1>\n";
2981 print "</refentry>\n";
2982 }
2983 }
2984}
Randy Dunlap8484baa2011-01-05 16:28:43 -08002985
2986
2987$kernelversion = get_kernel_version();
2988
2989# generate a sequence of code that will splice in highlighting information
2990# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02002991for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03002992 my $pattern = $highlights[$k][0];
2993 my $result = $highlights[$k][1];
2994# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
2995 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08002996}
2997
2998# Read the file that maps relative names to absolute names for
2999# separate source and object directories and for shadow trees.
3000if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3001 my ($relname, $absname);
3002 while(<SOURCE_MAP>) {
3003 chop();
3004 ($relname, $absname) = (split())[0..1];
3005 $relname =~ s:^/+::;
3006 $source_map{$relname} = $absname;
3007 }
3008 close(SOURCE_MAP);
3009}
3010
3011foreach (@ARGV) {
3012 chomp;
3013 process_file($_);
3014}
3015if ($verbose && $errors) {
3016 print STDERR "$errors errors\n";
3017}
3018if ($verbose && $warnings) {
3019 print STDERR "$warnings warnings\n";
3020}
3021
3022exit($errors);