blob: a89ff3ca366ca505a73f92321057b28d79be4cae [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]+)';
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300217my $type_member = '\&([_\w]+)((\.|->)[_\w]+)';
218my $type_member_func = $type_member . '\(\)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220# Output conversion substitutions.
221# One for each output format
222
223# these work fairly well
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300224my @highlights_html = (
225 [$type_constant, "<i>\$1</i>"],
226 [$type_func, "<b>\$1</b>"],
227 [$type_struct_xml, "<i>\$1</i>"],
228 [$type_env, "<b><i>\$1</i></b>"],
229 [$type_param, "<tt><b>\$1</b></tt>"]
230 );
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700231my $local_lt = "\\\\\\\\lt:";
232my $local_gt = "\\\\\\\\gt:";
233my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
Dan Luedtke1b40c192012-08-12 10:46:15 +0200235# html version 5
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300236my @highlights_html5 = (
237 [$type_constant, "<span class=\"const\">\$1</span>"],
238 [$type_func, "<span class=\"func\">\$1</span>"],
239 [$type_struct_xml, "<span class=\"struct\">\$1</span>"],
240 [$type_env, "<span class=\"env\">\$1</span>"],
241 [$type_param, "<span class=\"param\">\$1</span>]"]
242 );
Dan Luedtke1b40c192012-08-12 10:46:15 +0200243my $blankline_html5 = $local_lt . "br /" . $local_gt;
244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245# XML, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300246my @highlights_xml = (
247 ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
248 [$type_constant, "<constant>\$1</constant>"],
249 [$type_struct_xml, "<structname>\$1</structname>"],
250 [$type_param, "<parameter>\$1</parameter>"],
251 [$type_func, "<function>\$1</function>"],
252 [$type_env, "<envar>\$1</envar>"]
253 );
Johannes Berg5c98fc02007-10-24 15:08:48 -0700254my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256# gnome, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300257my @highlights_gnome = (
258 [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
259 [$type_func, "<function>\$1</function>"],
260 [$type_struct, "<structname>\$1</structname>"],
261 [$type_env, "<envar>\$1</envar>"],
262 [$type_param, "<parameter>\$1</parameter>" ]
263 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264my $blankline_gnome = "</para><para>\n";
265
266# these are pretty rough
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300267my @highlights_man = (
268 [$type_constant, "\$1"],
269 [$type_func, "\\\\fB\$1\\\\fP"],
270 [$type_struct, "\\\\fI\$1\\\\fP"],
271 [$type_param, "\\\\fI\$1\\\\fP"]
272 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273my $blankline_man = "";
274
275# text-mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300276my @highlights_text = (
277 [$type_constant, "\$1"],
278 [$type_func, "\$1"],
279 [$type_struct, "\$1"],
280 [$type_param, "\$1"]
281 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282my $blankline_text = "";
283
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300284# rst-mode
285my @highlights_rst = (
286 [$type_constant, "``\$1``"],
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300287 # Note: need to escape () to avoid func matching later
288 [$type_member_func, "\\:c\\:type\\:`\$1\$2\\\\(\\\\) <\$1>`"],
289 [$type_member, "\\:c\\:type\\:`\$1\$2 <\$1>`"],
Jani Nikulaa19bce62016-05-26 11:28:16 +0300290 [$type_func, "\\:c\\:func\\:`\$1()`"],
Jani Nikula62850972016-05-12 16:15:38 +0300291 [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
292 [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
Jani Nikula47ae7ae2016-05-26 13:57:18 +0300293 [$type_typedef_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
294 [$type_union_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
Jani Nikulaa7291e72016-05-26 13:57:06 +0300295 # in rst this can refer to any type
296 [$type_struct, "\\:c\\:type\\:`\$1`"],
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300297 [$type_param, "**\$1**"]
298 );
299my $blankline_rst = "\n";
300
Johannes Bergeda603f2010-09-11 15:55:22 -0700301# list mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300302my @highlights_list = (
303 [$type_constant, "\$1"],
304 [$type_func, "\$1"],
305 [$type_struct, "\$1"],
306 [$type_param, "\$1"]
307 );
Johannes Bergeda603f2010-09-11 15:55:22 -0700308my $blankline_list = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310# read arguments
Randy Dunlapb9d973282009-06-09 08:50:38 -0700311if ($#ARGV == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 usage();
313}
314
Randy Dunlap8484baa2011-01-05 16:28:43 -0800315my $kernelversion;
316my $dohighlight = "";
317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318my $verbose = 0;
319my $output_mode = "man";
Daniel Santose314ba32012-10-04 17:15:08 -0700320my $output_preformatted = 0;
Johannes Berg4b445952007-10-24 15:08:48 -0700321my $no_doc_sections = 0;
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300322my @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323my $blankline = $blankline_man;
324my $modulename = "Kernel API";
Jani Nikulab6c3f452016-05-29 22:19:35 +0300325
326use constant {
327 OUTPUT_ALL => 0, # output all symbols and doc sections
328 OUTPUT_INCLUDE => 1, # output only specified symbols
329 OUTPUT_EXCLUDE => 2, # output everything except specified symbols
330 OUTPUT_EXPORTED => 3, # output exported symbols
331 OUTPUT_INTERNAL => 4, # output non-exported symbols
332};
333my $output_selection = OUTPUT_ALL;
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100334my $show_not_found = 0;
335
336my @build_time;
337if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
338 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
339 @build_time = gmtime($seconds);
340} else {
341 @build_time = localtime;
342}
343
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800344my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
345 'July', 'August', 'September', 'October',
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100346 'November', 'December')[$build_time[4]] .
347 " " . ($build_time[5]+1900);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Randy Dunlap8484baa2011-01-05 16:28:43 -0800349# Essentially these are globals.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700350# They probably want to be tidied up, made more localised or something.
351# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352# could cause "use of undefined value" or other bugs.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700353my ($function, %function_table, %parametertypes, $declaration_purpose);
354my ($type, $declaration_name, $return_type);
Ilya Dryomov1c32fd02010-02-26 13:06:03 -0800355my ($newsection, $newcontents, $prototype, $brcount, %source_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700357if (defined($ENV{'KBUILD_VERBOSE'})) {
358 $verbose = "$ENV{'KBUILD_VERBOSE'}";
359}
360
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800361# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
363# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
364# We keep track of number of generated entries and generate a dummy
365# if needs be to ensure the expanded template can be postprocessed
366# into html.
367my $section_counter = 0;
368
369my $lineprefix="";
370
Jani Nikula48af6062016-05-26 14:56:05 +0300371# Parser states
372use constant {
373 STATE_NORMAL => 0, # normal code
374 STATE_NAME => 1, # looking for function name
375 STATE_FIELD => 2, # scanning field start
376 STATE_PROTO => 3, # scanning prototype
377 STATE_DOCBLOCK => 4, # documentation block
378 STATE_INLINE => 5, # gathering documentation outside main block
379};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700381my $in_doc_sect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Jani Nikula48af6062016-05-26 14:56:05 +0300383# Inline documentation state
384use constant {
385 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
386 STATE_INLINE_NAME => 1, # looking for member name (@foo:)
387 STATE_INLINE_TEXT => 2, # looking for member documentation
388 STATE_INLINE_END => 3, # done
389 STATE_INLINE_ERROR => 4, # error - Comment without header was found.
390 # Spit a warning as it's not
391 # proper kernel-doc and ignore the rest.
392};
393my $inline_doc_state;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#declaration types: can be
396# 'function', 'struct', 'union', 'enum', 'typedef'
397my $decl_type;
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
400my $doc_end = '\*/';
401my $doc_com = '\s*\*\s*';
Daniel Santos12ae6772012-10-04 17:15:10 -0700402my $doc_com_body = '\s*\* ?';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700403my $doc_decl = $doc_com . '(\w+)';
Jani Nikula13901ef2016-05-26 08:57:29 +0300404my $doc_sect = $doc_com . '(\@?[\w\s]+):(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700405my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700406my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Jani Nikula48af6062016-05-26 14:56:05 +0300407my $doc_inline_start = '^\s*/\*\*\s*$';
408my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
409my $doc_inline_end = '^\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200410my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412my %parameterdescs;
413my @parameterlist;
414my %sections;
415my @sectionlist;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800416my $sectcheck;
417my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419my $contents = "";
420my $section_default = "Description"; # default section
421my $section_intro = "Introduction";
422my $section = $section_default;
423my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100424my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426my $undescribed = "-- undescribed --";
427
428reset_state();
429
430while ($ARGV[0] =~ m/^-(.*)/) {
431 my $cmd = shift @ARGV;
432 if ($cmd eq "-html") {
433 $output_mode = "html";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300434 @highlights = @highlights_html;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200436 } elsif ($cmd eq "-html5") {
437 $output_mode = "html5";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300438 @highlights = @highlights_html5;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200439 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 } elsif ($cmd eq "-man") {
441 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300442 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 $blankline = $blankline_man;
444 } elsif ($cmd eq "-text") {
445 $output_mode = "text";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300446 @highlights = @highlights_text;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447 $blankline = $blankline_text;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300448 } elsif ($cmd eq "-rst") {
449 $output_mode = "rst";
450 @highlights = @highlights_rst;
451 $blankline = $blankline_rst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 } elsif ($cmd eq "-docbook") {
453 $output_mode = "xml";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300454 @highlights = @highlights_xml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700456 } elsif ($cmd eq "-list") {
457 $output_mode = "list";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300458 @highlights = @highlights_list;
Johannes Bergeda603f2010-09-11 15:55:22 -0700459 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 } elsif ($cmd eq "-gnome") {
461 $output_mode = "gnome";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300462 @highlights = @highlights_gnome;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 $blankline = $blankline_gnome;
464 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
465 $modulename = shift @ARGV;
466 } elsif ($cmd eq "-function") { # to only output specific functions
Jani Nikulab6c3f452016-05-29 22:19:35 +0300467 $output_selection = OUTPUT_INCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 $function = shift @ARGV;
469 $function_table{$function} = 1;
Jani Nikulab6c3f452016-05-29 22:19:35 +0300470 } elsif ($cmd eq "-nofunction") { # output all except specific functions
471 $output_selection = OUTPUT_EXCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 $function = shift @ARGV;
473 $function_table{$function} = 1;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200474 } elsif ($cmd eq "-export") { # only exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300475 $output_selection = OUTPUT_EXPORTED;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200476 %function_table = ()
477 } elsif ($cmd eq "-internal") { # only non-exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300478 $output_selection = OUTPUT_INTERNAL;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200479 %function_table = ()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 } elsif ($cmd eq "-v") {
481 $verbose = 1;
482 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
483 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700484 } elsif ($cmd eq '-no-doc-sections') {
485 $no_doc_sections = 1;
Johannes Berge946c43a2013-11-12 15:11:12 -0800486 } elsif ($cmd eq '-show-not-found') {
487 $show_not_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 }
489}
490
Randy Dunlap8484baa2011-01-05 16:28:43 -0800491# continue execution near EOF;
492
Borislav Petkov53f049f2007-05-08 00:30:54 -0700493# get kernel version from env
494sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700495 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700496
497 if (defined($ENV{'KERNELVERSION'})) {
498 $version = $ENV{'KERNELVERSION'};
499 }
500 return $version;
501}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503##
504# dumps section contents to arrays/hashes intended for that purpose.
505#
506sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700507 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 my $name = shift;
509 my $contents = join "\n", @_;
510
Jani Nikula13901ef2016-05-26 08:57:29 +0300511 if ($name =~ m/$type_param/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512# print STDERR "parameter def '$1' = '$contents'\n";
513 $name = $1;
514 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800515 $sectcheck = $sectcheck . $name . " ";
Randy Dunlapced69092008-12-01 13:14:03 -0800516 } elsif ($name eq "@\.\.\.") {
517# print STDERR "parameter def '...' = '$contents'\n";
518 $name = "...";
519 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800520 $sectcheck = $sectcheck . $name . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 } else {
522# print STDERR "other section '$name' = '$contents'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700523 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Bart Van Assched40e1e62015-09-04 15:43:21 -0700524 print STDERR "${file}:$.: error: duplicate section name '$name'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700525 ++$errors;
526 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 $sections{$name} = $contents;
528 push @sectionlist, $name;
529 }
530}
531
532##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700533# dump DOC: section after checking that it should go out
534#
535sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700536 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700537 my $name = shift;
538 my $contents = join "\n", @_;
539
Johannes Berg4b445952007-10-24 15:08:48 -0700540 if ($no_doc_sections) {
541 return;
542 }
543
Jani Nikulab6c3f452016-05-29 22:19:35 +0300544 if (($output_selection == OUTPUT_ALL) ||
545 ($output_selection == OUTPUT_INCLUDE &&
546 defined($function_table{$name})) ||
547 ($output_selection == OUTPUT_EXCLUDE &&
548 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700549 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700550 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700551 output_blockhead({'sectionlist' => \@sectionlist,
552 'sections' => \%sections,
553 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300554 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700555 }
556}
557
558##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559# output function
560#
561# parameterdescs, a hash.
562# function => "function name"
563# parameterlist => @list of parameters
564# parameterdescs => %parameter descriptions
565# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800566# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800567#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
569sub output_highlight {
570 my $contents = join "\n",@_;
571 my $line;
572
573# DEBUG
574# if (!defined $contents) {
575# use Carp;
576# confess "output_highlight got called with no args?\n";
577# }
578
Dan Luedtke1b40c192012-08-12 10:46:15 +0200579 if ($output_mode eq "html" || $output_mode eq "html5" ||
580 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700581 $contents = local_unescape($contents);
582 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800583 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700584 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700585# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 eval $dohighlight;
587 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700588# print STDERR "contents af:$contents\n";
589
Dan Luedtke1b40c192012-08-12 10:46:15 +0200590# strip whitespaces when generating html5
591 if ($output_mode eq "html5") {
592 $contents =~ s/^\s+//;
593 $contents =~ s/\s+$//;
594 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700596 if (! $output_preformatted) {
597 $line =~ s/^\s*//;
598 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700599 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700600 if (! $output_preformatted) {
601 print $lineprefix, local_unescape($blankline);
602 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700604 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700605 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
606 print "\\&$line";
607 } else {
608 print $lineprefix, $line;
609 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 }
611 print "\n";
612 }
613}
614
Dan Luedtke1b40c192012-08-12 10:46:15 +0200615# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616sub output_section_html(%) {
617 my %args = %{$_[0]};
618 my $section;
619
620 foreach $section (@{$args{'sectionlist'}}) {
621 print "<h3>$section</h3>\n";
622 print "<blockquote>\n";
623 output_highlight($args{'sections'}{$section});
624 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800625 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626}
627
628# output enum in html
629sub output_enum_html(%) {
630 my %args = %{$_[0]};
631 my ($parameter);
632 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700633 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Randy Dunlapb9d973282009-06-09 08:50:38 -0700635 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 $count = 0;
637 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700638 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 if ($count != $#{$args{'parameterlist'}}) {
640 $count++;
641 print ",\n";
642 }
643 print "<br>";
644 }
645 print "};<br>\n";
646
647 print "<h3>Constants</h3>\n";
648 print "<dl>\n";
649 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700650 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 print "<dd>";
652 output_highlight($args{'parameterdescs'}{$parameter});
653 }
654 print "</dl>\n";
655 output_section_html(@_);
656 print "<hr>\n";
657}
658
Randy Dunlapd28bee02006-02-01 03:06:57 -0800659# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660sub output_typedef_html(%) {
661 my %args = %{$_[0]};
662 my ($parameter);
663 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700664 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
Randy Dunlapb9d973282009-06-09 08:50:38 -0700666 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 output_section_html(@_);
668 print "<hr>\n";
669}
670
671# output struct in html
672sub output_struct_html(%) {
673 my %args = %{$_[0]};
674 my ($parameter);
675
Randy Dunlapb9d973282009-06-09 08:50:38 -0700676 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
677 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 foreach $parameter (@{$args{'parameterlist'}}) {
679 if ($parameter =~ /^#/) {
680 print "$parameter<br>\n";
681 next;
682 }
683 my $parameter_name = $parameter;
684 $parameter_name =~ s/\[.*//;
685
Randy Dunlap3c308792007-05-08 00:24:39 -0700686 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 $type = $args{'parametertypes'}{$parameter};
688 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
689 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700690 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700692 # bitfield
693 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700695 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 }
697 }
698 print "};<br>\n";
699
700 print "<h3>Members</h3>\n";
701 print "<dl>\n";
702 foreach $parameter (@{$args{'parameterlist'}}) {
703 ($parameter =~ /^#/) && next;
704
705 my $parameter_name = $parameter;
706 $parameter_name =~ s/\[.*//;
707
Randy Dunlap3c308792007-05-08 00:24:39 -0700708 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700709 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 print "<dd>";
711 output_highlight($args{'parameterdescs'}{$parameter_name});
712 }
713 print "</dl>\n";
714 output_section_html(@_);
715 print "<hr>\n";
716}
717
718# output function in html
719sub output_function_html(%) {
720 my %args = %{$_[0]};
721 my ($parameter, $section);
722 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
Randy Dunlapb9d973282009-06-09 08:50:38 -0700724 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
725 print "<i>" . $args{'functiontype'} . "</i>\n";
726 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 print "(";
728 $count = 0;
729 foreach $parameter (@{$args{'parameterlist'}}) {
730 $type = $args{'parametertypes'}{$parameter};
731 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
732 # pointer-to-function
733 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
734 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700735 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 }
737 if ($count != $#{$args{'parameterlist'}}) {
738 $count++;
739 print ",\n";
740 }
741 }
742 print ")\n";
743
744 print "<h3>Arguments</h3>\n";
745 print "<dl>\n";
746 foreach $parameter (@{$args{'parameterlist'}}) {
747 my $parameter_name = $parameter;
748 $parameter_name =~ s/\[.*//;
749
Randy Dunlap3c308792007-05-08 00:24:39 -0700750 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700751 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 print "<dd>";
753 output_highlight($args{'parameterdescs'}{$parameter_name});
754 }
755 print "</dl>\n";
756 output_section_html(@_);
757 print "<hr>\n";
758}
759
Johannes Bergb112e0f2007-10-24 15:08:48 -0700760# output DOC: block header in html
761sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 my %args = %{$_[0]};
763 my ($parameter, $section);
764 my $count;
765
766 foreach $section (@{$args{'sectionlist'}}) {
767 print "<h3>$section</h3>\n";
768 print "<ul>\n";
769 output_highlight($args{'sections'}{$section});
770 print "</ul>\n";
771 }
772 print "<hr>\n";
773}
774
Dan Luedtke1b40c192012-08-12 10:46:15 +0200775# output sections in html5
776sub output_section_html5(%) {
777 my %args = %{$_[0]};
778 my $section;
779
780 foreach $section (@{$args{'sectionlist'}}) {
781 print "<section>\n";
782 print "<h1>$section</h1>\n";
783 print "<p>\n";
784 output_highlight($args{'sections'}{$section});
785 print "</p>\n";
786 print "</section>\n";
787 }
788}
789
790# output enum in html5
791sub output_enum_html5(%) {
792 my %args = %{$_[0]};
793 my ($parameter);
794 my $count;
795 my $html5id;
796
797 $html5id = $args{'enum'};
798 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
799 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
800 print "<h1>enum " . $args{'enum'} . "</h1>\n";
801 print "<ol class=\"code\">\n";
802 print "<li>";
803 print "<span class=\"keyword\">enum</span> ";
804 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
805 print "</li>\n";
806 $count = 0;
807 foreach $parameter (@{$args{'parameterlist'}}) {
808 print "<li class=\"indent\">";
809 print "<span class=\"param\">" . $parameter . "</span>";
810 if ($count != $#{$args{'parameterlist'}}) {
811 $count++;
812 print ",";
813 }
814 print "</li>\n";
815 }
816 print "<li>};</li>\n";
817 print "</ol>\n";
818
819 print "<section>\n";
820 print "<h1>Constants</h1>\n";
821 print "<dl>\n";
822 foreach $parameter (@{$args{'parameterlist'}}) {
823 print "<dt>" . $parameter . "</dt>\n";
824 print "<dd>";
825 output_highlight($args{'parameterdescs'}{$parameter});
826 print "</dd>\n";
827 }
828 print "</dl>\n";
829 print "</section>\n";
830 output_section_html5(@_);
831 print "</article>\n";
832}
833
834# output typedef in html5
835sub output_typedef_html5(%) {
836 my %args = %{$_[0]};
837 my ($parameter);
838 my $count;
839 my $html5id;
840
841 $html5id = $args{'typedef'};
842 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
843 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
844 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
845
846 print "<ol class=\"code\">\n";
847 print "<li>";
848 print "<span class=\"keyword\">typedef</span> ";
849 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
850 print "</li>\n";
851 print "</ol>\n";
852 output_section_html5(@_);
853 print "</article>\n";
854}
855
856# output struct in html5
857sub output_struct_html5(%) {
858 my %args = %{$_[0]};
859 my ($parameter);
860 my $html5id;
861
862 $html5id = $args{'struct'};
863 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
864 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
865 print "<hgroup>\n";
866 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
867 print "<h2>". $args{'purpose'} . "</h2>\n";
868 print "</hgroup>\n";
869 print "<ol class=\"code\">\n";
870 print "<li>";
871 print "<span class=\"type\">" . $args{'type'} . "</span> ";
872 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
873 print "</li>\n";
874 foreach $parameter (@{$args{'parameterlist'}}) {
875 print "<li class=\"indent\">";
876 if ($parameter =~ /^#/) {
877 print "<span class=\"param\">" . $parameter ."</span>\n";
878 print "</li>\n";
879 next;
880 }
881 my $parameter_name = $parameter;
882 $parameter_name =~ s/\[.*//;
883
884 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
885 $type = $args{'parametertypes'}{$parameter};
886 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
887 # pointer-to-function
888 print "<span class=\"type\">$1</span> ";
889 print "<span class=\"param\">$parameter</span>";
890 print "<span class=\"type\">)</span> ";
891 print "(<span class=\"args\">$2</span>);";
892 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
893 # bitfield
894 print "<span class=\"type\">$1</span> ";
895 print "<span class=\"param\">$parameter</span>";
896 print "<span class=\"bits\">$2</span>;";
897 } else {
898 print "<span class=\"type\">$type</span> ";
899 print "<span class=\"param\">$parameter</span>;";
900 }
901 print "</li>\n";
902 }
903 print "<li>};</li>\n";
904 print "</ol>\n";
905
906 print "<section>\n";
907 print "<h1>Members</h1>\n";
908 print "<dl>\n";
909 foreach $parameter (@{$args{'parameterlist'}}) {
910 ($parameter =~ /^#/) && next;
911
912 my $parameter_name = $parameter;
913 $parameter_name =~ s/\[.*//;
914
915 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
916 print "<dt>" . $parameter . "</dt>\n";
917 print "<dd>";
918 output_highlight($args{'parameterdescs'}{$parameter_name});
919 print "</dd>\n";
920 }
921 print "</dl>\n";
922 print "</section>\n";
923 output_section_html5(@_);
924 print "</article>\n";
925}
926
927# output function in html5
928sub output_function_html5(%) {
929 my %args = %{$_[0]};
930 my ($parameter, $section);
931 my $count;
932 my $html5id;
933
934 $html5id = $args{'function'};
935 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
936 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
937 print "<hgroup>\n";
938 print "<h1>" . $args{'function'} . "</h1>";
939 print "<h2>" . $args{'purpose'} . "</h2>\n";
940 print "</hgroup>\n";
941 print "<ol class=\"code\">\n";
942 print "<li>";
943 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
944 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
945 print "</li>";
946 $count = 0;
947 foreach $parameter (@{$args{'parameterlist'}}) {
948 print "<li class=\"indent\">";
949 $type = $args{'parametertypes'}{$parameter};
950 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
951 # pointer-to-function
952 print "<span class=\"type\">$1</span> ";
953 print "<span class=\"param\">$parameter</span>";
954 print "<span class=\"type\">)</span> ";
955 print "(<span class=\"args\">$2</span>)";
956 } else {
957 print "<span class=\"type\">$type</span> ";
958 print "<span class=\"param\">$parameter</span>";
959 }
960 if ($count != $#{$args{'parameterlist'}}) {
961 $count++;
962 print ",";
963 }
964 print "</li>\n";
965 }
966 print "<li>)</li>\n";
967 print "</ol>\n";
968
969 print "<section>\n";
970 print "<h1>Arguments</h1>\n";
971 print "<p>\n";
972 print "<dl>\n";
973 foreach $parameter (@{$args{'parameterlist'}}) {
974 my $parameter_name = $parameter;
975 $parameter_name =~ s/\[.*//;
976
977 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
978 print "<dt>" . $parameter . "</dt>\n";
979 print "<dd>";
980 output_highlight($args{'parameterdescs'}{$parameter_name});
981 print "</dd>\n";
982 }
983 print "</dl>\n";
984 print "</section>\n";
985 output_section_html5(@_);
986 print "</article>\n";
987}
988
989# output DOC: block header in html5
990sub output_blockhead_html5(%) {
991 my %args = %{$_[0]};
992 my ($parameter, $section);
993 my $count;
994 my $html5id;
995
996 foreach $section (@{$args{'sectionlist'}}) {
997 $html5id = $section;
998 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
999 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1000 print "<h1>$section</h1>\n";
1001 print "<p>\n";
1002 output_highlight($args{'sections'}{$section});
1003 print "</p>\n";
1004 }
1005 print "</article>\n";
1006}
1007
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008sub output_section_xml(%) {
1009 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001010 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 # print out each section
1012 $lineprefix=" ";
1013 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001014 print "<refsect1>\n";
1015 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001017 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001018 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001019 } else {
1020 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 }
1022 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001023 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001025 print "</programlisting></informalexample>\n";
1026 } else {
1027 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001029 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 }
1031}
1032
1033# output function in XML DocBook
1034sub output_function_xml(%) {
1035 my %args = %{$_[0]};
1036 my ($parameter, $section);
1037 my $count;
1038 my $id;
1039
Randy Dunlapb9d973282009-06-09 08:50:38 -07001040 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 $id =~ s/[^A-Za-z0-9]/-/g;
1042
Pavel Pisa5449bc92007-02-10 01:45:37 -08001043 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001044 print "<refentryinfo>\n";
1045 print " <title>LINUX</title>\n";
1046 print " <productname>Kernel Hackers Manual</productname>\n";
1047 print " <date>$man_date</date>\n";
1048 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001050 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001051 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001052 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 print "</refmeta>\n";
1054 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001055 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 print " <refpurpose>\n";
1057 print " ";
1058 output_highlight ($args{'purpose'});
1059 print " </refpurpose>\n";
1060 print "</refnamediv>\n";
1061
1062 print "<refsynopsisdiv>\n";
1063 print " <title>Synopsis</title>\n";
1064 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001065 print " <funcdef>" . $args{'functiontype'} . " ";
1066 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
1068 $count = 0;
1069 if ($#{$args{'parameterlist'}} >= 0) {
1070 foreach $parameter (@{$args{'parameterlist'}}) {
1071 $type = $args{'parametertypes'}{$parameter};
1072 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1073 # pointer-to-function
1074 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1075 print " <funcparams>$2</funcparams></paramdef>\n";
1076 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001077 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 print " <parameter>$parameter</parameter></paramdef>\n";
1079 }
1080 }
1081 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001082 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 }
1084 print " </funcprototype></funcsynopsis>\n";
1085 print "</refsynopsisdiv>\n";
1086
1087 # print parameters
1088 print "<refsect1>\n <title>Arguments</title>\n";
1089 if ($#{$args{'parameterlist'}} >= 0) {
1090 print " <variablelist>\n";
1091 foreach $parameter (@{$args{'parameterlist'}}) {
1092 my $parameter_name = $parameter;
1093 $parameter_name =~ s/\[.*//;
1094
1095 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1096 print " <listitem>\n <para>\n";
1097 $lineprefix=" ";
1098 output_highlight($args{'parameterdescs'}{$parameter_name});
1099 print " </para>\n </listitem>\n </varlistentry>\n";
1100 }
1101 print " </variablelist>\n";
1102 } else {
1103 print " <para>\n None\n </para>\n";
1104 }
1105 print "</refsect1>\n";
1106
1107 output_section_xml(@_);
1108 print "</refentry>\n\n";
1109}
1110
1111# output struct in XML DocBook
1112sub output_struct_xml(%) {
1113 my %args = %{$_[0]};
1114 my ($parameter, $section);
1115 my $id;
1116
Randy Dunlapb9d973282009-06-09 08:50:38 -07001117 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 $id =~ s/[^A-Za-z0-9]/-/g;
1119
Pavel Pisa5449bc92007-02-10 01:45:37 -08001120 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001121 print "<refentryinfo>\n";
1122 print " <title>LINUX</title>\n";
1123 print " <productname>Kernel Hackers Manual</productname>\n";
1124 print " <date>$man_date</date>\n";
1125 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001127 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001128 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001129 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 print "</refmeta>\n";
1131 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001132 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 print " <refpurpose>\n";
1134 print " ";
1135 output_highlight ($args{'purpose'});
1136 print " </refpurpose>\n";
1137 print "</refnamediv>\n";
1138
1139 print "<refsynopsisdiv>\n";
1140 print " <title>Synopsis</title>\n";
1141 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001142 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 foreach $parameter (@{$args{'parameterlist'}}) {
1144 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001145 my $prm = $parameter;
1146 # convert data read & converted thru xml_escape() into &xyz; format:
1147 # This allows us to have #define macros interspersed in a struct.
1148 $prm =~ s/\\\\\\/\&/g;
1149 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 next;
1151 }
1152
1153 my $parameter_name = $parameter;
1154 $parameter_name =~ s/\[.*//;
1155
1156 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001157 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 $type = $args{'parametertypes'}{$parameter};
1159 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1160 # pointer-to-function
1161 print " $1 $parameter) ($2);\n";
1162 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001163 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 print " $1 $parameter$2;\n";
1165 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001166 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 }
1168 }
1169 print "};";
1170 print " </programlisting>\n";
1171 print "</refsynopsisdiv>\n";
1172
1173 print " <refsect1>\n";
1174 print " <title>Members</title>\n";
1175
Randy Dunlap39f00c02008-09-22 13:57:44 -07001176 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 print " <variablelist>\n";
1178 foreach $parameter (@{$args{'parameterlist'}}) {
1179 ($parameter =~ /^#/) && next;
1180
1181 my $parameter_name = $parameter;
1182 $parameter_name =~ s/\[.*//;
1183
1184 defined($args{'parameterdescs'}{$parameter_name}) || next;
1185 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1186 print " <varlistentry>";
1187 print " <term>$parameter</term>\n";
1188 print " <listitem><para>\n";
1189 output_highlight($args{'parameterdescs'}{$parameter_name});
1190 print " </para></listitem>\n";
1191 print " </varlistentry>\n";
1192 }
1193 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001194 } else {
1195 print " <para>\n None\n </para>\n";
1196 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 print " </refsect1>\n";
1198
1199 output_section_xml(@_);
1200
1201 print "</refentry>\n\n";
1202}
1203
1204# output enum in XML DocBook
1205sub output_enum_xml(%) {
1206 my %args = %{$_[0]};
1207 my ($parameter, $section);
1208 my $count;
1209 my $id;
1210
Randy Dunlapb9d973282009-06-09 08:50:38 -07001211 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 $id =~ s/[^A-Za-z0-9]/-/g;
1213
Pavel Pisa5449bc92007-02-10 01:45:37 -08001214 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001215 print "<refentryinfo>\n";
1216 print " <title>LINUX</title>\n";
1217 print " <productname>Kernel Hackers Manual</productname>\n";
1218 print " <date>$man_date</date>\n";
1219 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001221 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001222 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001223 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 print "</refmeta>\n";
1225 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001226 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 print " <refpurpose>\n";
1228 print " ";
1229 output_highlight ($args{'purpose'});
1230 print " </refpurpose>\n";
1231 print "</refnamediv>\n";
1232
1233 print "<refsynopsisdiv>\n";
1234 print " <title>Synopsis</title>\n";
1235 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001236 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 $count = 0;
1238 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001239 print " $parameter";
1240 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 $count++;
1242 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001243 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 print "\n";
1245 }
1246 print "};";
1247 print " </programlisting>\n";
1248 print "</refsynopsisdiv>\n";
1249
1250 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001251 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 print " <variablelist>\n";
1253 foreach $parameter (@{$args{'parameterlist'}}) {
1254 my $parameter_name = $parameter;
1255 $parameter_name =~ s/\[.*//;
1256
1257 print " <varlistentry>";
1258 print " <term>$parameter</term>\n";
1259 print " <listitem><para>\n";
1260 output_highlight($args{'parameterdescs'}{$parameter_name});
1261 print " </para></listitem>\n";
1262 print " </varlistentry>\n";
1263 }
1264 print " </variablelist>\n";
1265 print "</refsect1>\n";
1266
1267 output_section_xml(@_);
1268
1269 print "</refentry>\n\n";
1270}
1271
1272# output typedef in XML DocBook
1273sub output_typedef_xml(%) {
1274 my %args = %{$_[0]};
1275 my ($parameter, $section);
1276 my $id;
1277
Randy Dunlapb9d973282009-06-09 08:50:38 -07001278 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 $id =~ s/[^A-Za-z0-9]/-/g;
1280
Pavel Pisa5449bc92007-02-10 01:45:37 -08001281 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001282 print "<refentryinfo>\n";
1283 print " <title>LINUX</title>\n";
1284 print " <productname>Kernel Hackers Manual</productname>\n";
1285 print " <date>$man_date</date>\n";
1286 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001288 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001289 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 print "</refmeta>\n";
1291 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001292 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 print " <refpurpose>\n";
1294 print " ";
1295 output_highlight ($args{'purpose'});
1296 print " </refpurpose>\n";
1297 print "</refnamediv>\n";
1298
1299 print "<refsynopsisdiv>\n";
1300 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001301 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 print "</refsynopsisdiv>\n";
1303
1304 output_section_xml(@_);
1305
1306 print "</refentry>\n\n";
1307}
1308
1309# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001310sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 my %args = %{$_[0]};
1312 my ($parameter, $section);
1313 my $count;
1314
1315 my $id = $args{'module'};
1316 $id =~ s/[^A-Za-z0-9]/-/g;
1317
1318 # print out each section
1319 $lineprefix=" ";
1320 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001321 if (!$args{'content-only'}) {
1322 print "<refsect1>\n <title>$section</title>\n";
1323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 if ($section =~ m/EXAMPLE/i) {
1325 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001326 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001327 } else {
1328 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 }
1330 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001331 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 if ($section =~ m/EXAMPLE/i) {
1333 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001334 } else {
1335 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001337 if (!$args{'content-only'}) {
1338 print "\n</refsect1>\n";
1339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 }
1341
1342 print "\n\n";
1343}
1344
1345# output in XML DocBook
1346sub output_function_gnome {
1347 my %args = %{$_[0]};
1348 my ($parameter, $section);
1349 my $count;
1350 my $id;
1351
Randy Dunlapb9d973282009-06-09 08:50:38 -07001352 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 $id =~ s/[^A-Za-z0-9]/-/g;
1354
1355 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001356 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
1358 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001359 print " <funcdef>" . $args{'functiontype'} . " ";
1360 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 print "</function></funcdef>\n";
1362
1363 $count = 0;
1364 if ($#{$args{'parameterlist'}} >= 0) {
1365 foreach $parameter (@{$args{'parameterlist'}}) {
1366 $type = $args{'parametertypes'}{$parameter};
1367 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1368 # pointer-to-function
1369 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1370 print " <funcparams>$2</funcparams></paramdef>\n";
1371 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001372 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 print " <parameter>$parameter</parameter></paramdef>\n";
1374 }
1375 }
1376 } else {
1377 print " <void>\n";
1378 }
1379 print " </funcsynopsis>\n";
1380 if ($#{$args{'parameterlist'}} >= 0) {
1381 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1382 print "<tgroup cols=\"2\">\n";
1383 print "<colspec colwidth=\"2*\">\n";
1384 print "<colspec colwidth=\"8*\">\n";
1385 print "<tbody>\n";
1386 foreach $parameter (@{$args{'parameterlist'}}) {
1387 my $parameter_name = $parameter;
1388 $parameter_name =~ s/\[.*//;
1389
1390 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1391 print " <entry>\n";
1392 $lineprefix=" ";
1393 output_highlight($args{'parameterdescs'}{$parameter_name});
1394 print " </entry></row>\n";
1395 }
1396 print " </tbody></tgroup></informaltable>\n";
1397 } else {
1398 print " <para>\n None\n </para>\n";
1399 }
1400
1401 # print out each section
1402 $lineprefix=" ";
1403 foreach $section (@{$args{'sectionlist'}}) {
1404 print "<simplesect>\n <title>$section</title>\n";
1405 if ($section =~ m/EXAMPLE/i) {
1406 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001407 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 } else {
1409 }
1410 print "<para>\n";
1411 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001412 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 print "</para>\n";
1414 if ($section =~ m/EXAMPLE/i) {
1415 print "</programlisting></example>\n";
1416 } else {
1417 }
1418 print " </simplesect>\n";
1419 }
1420
1421 print "</sect2>\n\n";
1422}
1423
1424##
1425# output function in man
1426sub output_function_man(%) {
1427 my %args = %{$_[0]};
1428 my ($parameter, $section);
1429 my $count;
1430
1431 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1432
1433 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001434 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
1436 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001437 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001438 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001439 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001440 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001441 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 $count = 0;
1443 my $parenth = "(";
1444 my $post = ",";
1445 foreach my $parameter (@{$args{'parameterlist'}}) {
1446 if ($count == $#{$args{'parameterlist'}}) {
1447 $post = ");";
1448 }
1449 $type = $args{'parametertypes'}{$parameter};
1450 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1451 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001452 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 } else {
1454 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001455 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 }
1457 $count++;
1458 $parenth = "";
1459 }
1460
1461 print ".SH ARGUMENTS\n";
1462 foreach $parameter (@{$args{'parameterlist'}}) {
1463 my $parameter_name = $parameter;
1464 $parameter_name =~ s/\[.*//;
1465
Randy Dunlapb9d973282009-06-09 08:50:38 -07001466 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 output_highlight($args{'parameterdescs'}{$parameter_name});
1468 }
1469 foreach $section (@{$args{'sectionlist'}}) {
1470 print ".SH \"", uc $section, "\"\n";
1471 output_highlight($args{'sections'}{$section});
1472 }
1473}
1474
1475##
1476# output enum in man
1477sub output_enum_man(%) {
1478 my %args = %{$_[0]};
1479 my ($parameter, $section);
1480 my $count;
1481
1482 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1483
1484 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001485 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486
1487 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001488 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 $count = 0;
1490 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001491 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 if ($count == $#{$args{'parameterlist'}}) {
1493 print "\n};\n";
1494 last;
1495 }
1496 else {
1497 print ", \n.br\n";
1498 }
1499 $count++;
1500 }
1501
1502 print ".SH Constants\n";
1503 foreach $parameter (@{$args{'parameterlist'}}) {
1504 my $parameter_name = $parameter;
1505 $parameter_name =~ s/\[.*//;
1506
Randy Dunlapb9d973282009-06-09 08:50:38 -07001507 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 output_highlight($args{'parameterdescs'}{$parameter_name});
1509 }
1510 foreach $section (@{$args{'sectionlist'}}) {
1511 print ".SH \"$section\"\n";
1512 output_highlight($args{'sections'}{$section});
1513 }
1514}
1515
1516##
1517# output struct in man
1518sub output_struct_man(%) {
1519 my %args = %{$_[0]};
1520 my ($parameter, $section);
1521
Randy Dunlapb9d973282009-06-09 08:50:38 -07001522 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
1524 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001525 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
1527 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001528 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
1530 foreach my $parameter (@{$args{'parameterlist'}}) {
1531 if ($parameter =~ /^#/) {
1532 print ".BI \"$parameter\"\n.br\n";
1533 next;
1534 }
1535 my $parameter_name = $parameter;
1536 $parameter_name =~ s/\[.*//;
1537
Randy Dunlap3c308792007-05-08 00:24:39 -07001538 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 $type = $args{'parametertypes'}{$parameter};
1540 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1541 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001542 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001544 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001545 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 } else {
1547 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001548 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 }
1550 print "\n.br\n";
1551 }
1552 print "};\n.br\n";
1553
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001554 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 foreach $parameter (@{$args{'parameterlist'}}) {
1556 ($parameter =~ /^#/) && next;
1557
1558 my $parameter_name = $parameter;
1559 $parameter_name =~ s/\[.*//;
1560
Randy Dunlap3c308792007-05-08 00:24:39 -07001561 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001562 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 output_highlight($args{'parameterdescs'}{$parameter_name});
1564 }
1565 foreach $section (@{$args{'sectionlist'}}) {
1566 print ".SH \"$section\"\n";
1567 output_highlight($args{'sections'}{$section});
1568 }
1569}
1570
1571##
1572# output typedef in man
1573sub output_typedef_man(%) {
1574 my %args = %{$_[0]};
1575 my ($parameter, $section);
1576
1577 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1578
1579 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001580 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
1582 foreach $section (@{$args{'sectionlist'}}) {
1583 print ".SH \"$section\"\n";
1584 output_highlight($args{'sections'}{$section});
1585 }
1586}
1587
Johannes Bergb112e0f2007-10-24 15:08:48 -07001588sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 my %args = %{$_[0]};
1590 my ($parameter, $section);
1591 my $count;
1592
1593 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1594
1595 foreach $section (@{$args{'sectionlist'}}) {
1596 print ".SH \"$section\"\n";
1597 output_highlight($args{'sections'}{$section});
1598 }
1599}
1600
1601##
1602# output in text
1603sub output_function_text(%) {
1604 my %args = %{$_[0]};
1605 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001606 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
Randy Dunlapf47634b2006-07-01 04:36:36 -07001608 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001609 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001610
1611 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001612 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001613 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001614 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001615 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001616 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001618
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 my $count = 0;
1620 foreach my $parameter (@{$args{'parameterlist'}}) {
1621 $type = $args{'parametertypes'}{$parameter};
1622 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1623 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001624 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001626 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 }
1628 if ($count != $#{$args{'parameterlist'}}) {
1629 $count++;
1630 print ",\n";
1631 print " " x length($start);
1632 } else {
1633 print ");\n\n";
1634 }
1635 }
1636
1637 print "Arguments:\n\n";
1638 foreach $parameter (@{$args{'parameterlist'}}) {
1639 my $parameter_name = $parameter;
1640 $parameter_name =~ s/\[.*//;
1641
Randy Dunlapb9d973282009-06-09 08:50:38 -07001642 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 }
1644 output_section_text(@_);
1645}
1646
1647#output sections in text
1648sub output_section_text(%) {
1649 my %args = %{$_[0]};
1650 my $section;
1651
1652 print "\n";
1653 foreach $section (@{$args{'sectionlist'}}) {
1654 print "$section:\n\n";
1655 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 print "\n\n";
1658}
1659
1660# output enum in text
1661sub output_enum_text(%) {
1662 my %args = %{$_[0]};
1663 my ($parameter);
1664 my $count;
1665 print "Enum:\n\n";
1666
Randy Dunlapb9d973282009-06-09 08:50:38 -07001667 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1668 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 $count = 0;
1670 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001671 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 if ($count != $#{$args{'parameterlist'}}) {
1673 $count++;
1674 print ",";
1675 }
1676 print "\n";
1677 }
1678 print "};\n\n";
1679
1680 print "Constants:\n\n";
1681 foreach $parameter (@{$args{'parameterlist'}}) {
1682 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001683 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 }
1685
1686 output_section_text(@_);
1687}
1688
1689# output typedef in text
1690sub output_typedef_text(%) {
1691 my %args = %{$_[0]};
1692 my ($parameter);
1693 my $count;
1694 print "Typedef:\n\n";
1695
Randy Dunlapb9d973282009-06-09 08:50:38 -07001696 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 output_section_text(@_);
1698}
1699
1700# output struct as text
1701sub output_struct_text(%) {
1702 my %args = %{$_[0]};
1703 my ($parameter);
1704
Randy Dunlapb9d973282009-06-09 08:50:38 -07001705 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1706 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 foreach $parameter (@{$args{'parameterlist'}}) {
1708 if ($parameter =~ /^#/) {
1709 print "$parameter\n";
1710 next;
1711 }
1712
1713 my $parameter_name = $parameter;
1714 $parameter_name =~ s/\[.*//;
1715
Randy Dunlap3c308792007-05-08 00:24:39 -07001716 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 $type = $args{'parametertypes'}{$parameter};
1718 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1719 # pointer-to-function
1720 print "\t$1 $parameter) ($2);\n";
1721 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001722 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 print "\t$1 $parameter$2;\n";
1724 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001725 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 }
1727 }
1728 print "};\n\n";
1729
1730 print "Members:\n\n";
1731 foreach $parameter (@{$args{'parameterlist'}}) {
1732 ($parameter =~ /^#/) && next;
1733
1734 my $parameter_name = $parameter;
1735 $parameter_name =~ s/\[.*//;
1736
Randy Dunlap3c308792007-05-08 00:24:39 -07001737 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001739 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 }
1741 print "\n";
1742 output_section_text(@_);
1743}
1744
Johannes Bergb112e0f2007-10-24 15:08:48 -07001745sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 my %args = %{$_[0]};
1747 my ($parameter, $section);
1748
1749 foreach $section (@{$args{'sectionlist'}}) {
1750 print " $section:\n";
1751 print " -> ";
1752 output_highlight($args{'sections'}{$section});
1753 }
1754}
1755
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001756##
1757# output in restructured text
1758#
1759
1760#
1761# This could use some work; it's used to output the DOC: sections, and
1762# starts by putting out the name of the doc section itself, but that tends
1763# to duplicate a header already in the template file.
1764#
1765sub output_blockhead_rst(%) {
1766 my %args = %{$_[0]};
1767 my ($parameter, $section);
1768
1769 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001770 if ($output_selection != OUTPUT_INCLUDE) {
1771 print "**$section**\n\n";
1772 }
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001773 output_highlight_rst($args{'sections'}{$section});
1774 print "\n";
1775 }
1776}
1777
1778sub output_highlight_rst {
1779 my $contents = join "\n",@_;
1780 my $line;
1781
1782 # undo the evil effects of xml_escape() earlier
1783 $contents = xml_unescape($contents);
1784
1785 eval $dohighlight;
1786 die $@ if $@;
1787
1788 foreach $line (split "\n", $contents) {
Jani Nikula830066a2016-05-26 22:04:33 +03001789 print $lineprefix . $line . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001790 }
1791}
1792
1793sub output_function_rst(%) {
1794 my %args = %{$_[0]};
1795 my ($parameter, $section);
Jani Nikulac099ff62016-05-26 17:18:17 +03001796 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001797 my $start;
1798
1799 print ".. c:function:: ";
1800 if ($args{'functiontype'} ne "") {
1801 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1802 } else {
1803 $start = $args{'function'} . " (";
1804 }
1805 print $start;
1806
1807 my $count = 0;
1808 foreach my $parameter (@{$args{'parameterlist'}}) {
1809 if ($count ne 0) {
1810 print ", ";
1811 }
1812 $count++;
1813 $type = $args{'parametertypes'}{$parameter};
1814 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1815 # pointer-to-function
1816 print $1 . $parameter . ") (" . $2;
1817 } else {
1818 print $type . " " . $parameter;
1819 }
1820 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001821 print ")\n\n";
1822 $lineprefix = " ";
1823 output_highlight_rst($args{'purpose'});
1824 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001825
1826 print ":Parameters:\n\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001827 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001828 foreach $parameter (@{$args{'parameterlist'}}) {
1829 my $parameter_name = $parameter;
1830 #$parameter_name =~ s/\[.*//;
1831 $type = $args{'parametertypes'}{$parameter};
1832
1833 if ($type ne "") {
1834 print " ``$type $parameter``\n";
1835 } else {
1836 print " ``$parameter``\n";
1837 }
Jani Nikula5e64fa92016-05-19 20:32:48 +03001838 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1839 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001840 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001841 } else {
1842 print "\n _undescribed_\n";
1843 }
1844 print "\n";
1845 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001846
1847 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001848 output_section_rst(@_);
1849}
1850
1851sub output_section_rst(%) {
1852 my %args = %{$_[0]};
1853 my $section;
1854 my $oldprefix = $lineprefix;
1855 $lineprefix = " ";
1856
1857 foreach $section (@{$args{'sectionlist'}}) {
1858 print ":$section:\n\n";
1859 output_highlight_rst($args{'sections'}{$section});
1860 print "\n";
1861 }
1862 print "\n";
1863 $lineprefix = $oldprefix;
1864}
1865
1866sub output_enum_rst(%) {
1867 my %args = %{$_[0]};
1868 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001869 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001870 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001871 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001872
1873 print "\n\n.. c:type:: " . $name . "\n\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001874 $lineprefix = " ";
1875 output_highlight_rst($args{'purpose'});
1876 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001877
1878 print "..\n\n:Constants:\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001879 $lineprefix = " ";
1880 foreach $parameter (@{$args{'parameterlist'}}) {
1881 print " `$parameter`\n";
1882 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1883 output_highlight_rst($args{'parameterdescs'}{$parameter});
1884 } else {
1885 print " undescribed\n";
1886 }
1887 print "\n";
1888 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001889
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001890 $lineprefix = $oldprefix;
1891 output_section_rst(@_);
1892}
1893
1894sub output_typedef_rst(%) {
1895 my %args = %{$_[0]};
1896 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001897 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001898 my $name = "typedef " . $args{'typedef'};
1899
Jani Nikula62850972016-05-12 16:15:38 +03001900 ### FIXME: should the name below contain "typedef" or not?
1901 print "\n\n.. c:type:: " . $name . "\n\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001902 $lineprefix = " ";
1903 output_highlight_rst($args{'purpose'});
1904 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001905
Jani Nikulac099ff62016-05-26 17:18:17 +03001906 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001907 output_section_rst(@_);
1908}
1909
1910sub output_struct_rst(%) {
1911 my %args = %{$_[0]};
1912 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001913 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001914 my $name = $args{'type'} . " " . $args{'struct'};
1915
Jani Nikula62850972016-05-12 16:15:38 +03001916 print "\n\n.. c:type:: " . $name . "\n\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001917 $lineprefix = " ";
1918 output_highlight_rst($args{'purpose'});
1919 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001920
1921 print ":Definition:\n\n";
1922 print " ::\n\n";
1923 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1924 foreach $parameter (@{$args{'parameterlist'}}) {
1925 if ($parameter =~ /^#/) {
1926 print " " . "$parameter\n";
1927 next;
1928 }
1929
1930 my $parameter_name = $parameter;
1931 $parameter_name =~ s/\[.*//;
1932
1933 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1934 $type = $args{'parametertypes'}{$parameter};
1935 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1936 # pointer-to-function
1937 print " $1 $parameter) ($2);\n";
1938 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1939 # bitfield
1940 print " $1 $parameter$2;\n";
1941 } else {
1942 print " " . $type . " " . $parameter . ";\n";
1943 }
1944 }
1945 print " };\n\n";
1946
1947 print ":Members:\n\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001948 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001949 foreach $parameter (@{$args{'parameterlist'}}) {
1950 ($parameter =~ /^#/) && next;
1951
1952 my $parameter_name = $parameter;
1953 $parameter_name =~ s/\[.*//;
1954
1955 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1956 $type = $args{'parametertypes'}{$parameter};
1957 print " `$type $parameter`" . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001958 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001959 print "\n";
1960 }
1961 print "\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001962
1963 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001964 output_section_rst(@_);
1965}
1966
1967
Johannes Bergeda603f2010-09-11 15:55:22 -07001968## list mode output functions
1969
1970sub output_function_list(%) {
1971 my %args = %{$_[0]};
1972
1973 print $args{'function'} . "\n";
1974}
1975
1976# output enum in list
1977sub output_enum_list(%) {
1978 my %args = %{$_[0]};
1979 print $args{'enum'} . "\n";
1980}
1981
1982# output typedef in list
1983sub output_typedef_list(%) {
1984 my %args = %{$_[0]};
1985 print $args{'typedef'} . "\n";
1986}
1987
1988# output struct as list
1989sub output_struct_list(%) {
1990 my %args = %{$_[0]};
1991
1992 print $args{'struct'} . "\n";
1993}
1994
1995sub output_blockhead_list(%) {
1996 my %args = %{$_[0]};
1997 my ($parameter, $section);
1998
1999 foreach $section (@{$args{'sectionlist'}}) {
2000 print "DOC: $section\n";
2001 }
2002}
2003
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004##
Randy Dunlap27205742006-10-11 01:22:12 -07002005# generic output function for all types (function, struct/union, typedef, enum);
2006# calls the generated, variable output_ function name based on
2007# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008sub output_declaration {
2009 no strict 'refs';
2010 my $name = shift;
2011 my $functype = shift;
2012 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002013 if (($output_selection == OUTPUT_ALL) ||
2014 (($output_selection == OUTPUT_INCLUDE ||
2015 $output_selection == OUTPUT_EXPORTED) &&
2016 defined($function_table{$name})) ||
2017 (($output_selection == OUTPUT_EXCLUDE ||
2018 $output_selection == OUTPUT_INTERNAL) &&
2019 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002021 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 $section_counter++;
2023 }
2024}
2025
2026##
Randy Dunlap27205742006-10-11 01:22:12 -07002027# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002028sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002030 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 &$func(@_);
2032 $section_counter++;
2033}
2034
2035##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002036# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037# invokes the right handler. NOT called for functions.
2038sub dump_declaration($$) {
2039 no strict 'refs';
2040 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002041 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 &$func(@_);
2043}
2044
2045sub dump_union($$) {
2046 dump_struct(@_);
2047}
2048
2049sub dump_struct($$) {
2050 my $x = shift;
2051 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002052 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002054 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2055 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002056 $declaration_name = $2;
2057 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058
2059 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002060 $members =~ s/({.*})//g;
2061 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
Martin Waitzaeec46b2005-11-13 16:08:13 -08002063 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002064 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2065 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002066 # strip comments:
2067 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002068 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002069 # strip kmemcheck_bitfield_{begin,end}.*;
2070 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002071 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002072 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002073 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002074 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002075 # replace DECLARE_BITMAP
2076 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002077
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002079 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080
2081 output_declaration($declaration_name,
2082 'struct',
2083 {'struct' => $declaration_name,
2084 'module' => $modulename,
2085 'parameterlist' => \@parameterlist,
2086 'parameterdescs' => \%parameterdescs,
2087 'parametertypes' => \%parametertypes,
2088 'sectionlist' => \@sectionlist,
2089 'sections' => \%sections,
2090 'purpose' => $declaration_purpose,
2091 'type' => $decl_type
2092 });
2093 }
2094 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002095 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 ++$errors;
2097 }
2098}
2099
2100sub dump_enum($$) {
2101 my $x = shift;
2102 my $file = shift;
2103
Martin Waitzaeec46b2005-11-13 16:08:13 -08002104 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002105 # strip #define macros inside enums
2106 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002107
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002109 $declaration_name = $1;
2110 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111
2112 foreach my $arg (split ',', $members) {
2113 $arg =~ s/^\s*(\w+).*/$1/;
2114 push @parameterlist, $arg;
2115 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002116 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002117 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 "not described in enum '$declaration_name'\n";
2119 }
2120
2121 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002122
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123 output_declaration($declaration_name,
2124 'enum',
2125 {'enum' => $declaration_name,
2126 'module' => $modulename,
2127 'parameterlist' => \@parameterlist,
2128 'parameterdescs' => \%parameterdescs,
2129 'sectionlist' => \@sectionlist,
2130 'sections' => \%sections,
2131 'purpose' => $declaration_purpose
2132 });
2133 }
2134 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002135 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 ++$errors;
2137 }
2138}
2139
2140sub dump_typedef($$) {
2141 my $x = shift;
2142 my $file = shift;
2143
Martin Waitzaeec46b2005-11-13 16:08:13 -08002144 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002145
2146 # Parse function prototypes
2147 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
2148 # Function typedefs
2149 $return_type = $1;
2150 $declaration_name = $2;
2151 my $args = $3;
2152
2153 create_parameterlist($args, ',', $file);
2154
2155 output_declaration($declaration_name,
2156 'function',
2157 {'function' => $declaration_name,
2158 'module' => $modulename,
2159 'functiontype' => $return_type,
2160 'parameterlist' => \@parameterlist,
2161 'parameterdescs' => \%parameterdescs,
2162 'parametertypes' => \%parametertypes,
2163 'sectionlist' => \@sectionlist,
2164 'sections' => \%sections,
2165 'purpose' => $declaration_purpose
2166 });
2167 return;
2168 }
2169
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002171 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 $x =~ s/\[*.\]\s*;$/;/;
2173 }
2174
2175 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002176 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177
2178 output_declaration($declaration_name,
2179 'typedef',
2180 {'typedef' => $declaration_name,
2181 'module' => $modulename,
2182 'sectionlist' => \@sectionlist,
2183 'sections' => \%sections,
2184 'purpose' => $declaration_purpose
2185 });
2186 }
2187 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002188 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 ++$errors;
2190 }
2191}
2192
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002193sub save_struct_actual($) {
2194 my $actual = shift;
2195
2196 # strip all spaces from the actual param so that it looks like one string item
2197 $actual =~ s/\s*//g;
2198 $struct_actual = $struct_actual . $actual . " ";
2199}
2200
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201sub create_parameterlist($$$) {
2202 my $args = shift;
2203 my $splitter = shift;
2204 my $file = shift;
2205 my $type;
2206 my $param;
2207
Martin Waitza6d3fe72006-01-09 20:53:55 -08002208 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002210 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002212
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 foreach my $arg (split($splitter, $args)) {
2214 # strip comments
2215 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002216 # strip leading/trailing spaces
2217 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 $arg =~ s/\s*$//;
2219 $arg =~ s/\s+/ /;
2220
2221 if ($arg =~ /^#/) {
2222 # Treat preprocessor directive as a typeless variable just to fill
2223 # corresponding data structures "correctly". Catch it later in
2224 # output_* subs.
2225 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002226 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 # pointer-to-function
2228 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002229 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 $param = $1;
2231 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002232 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002233 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002235 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 $arg =~ s/\s*:\s*/:/g;
2237 $arg =~ s/\s*\[/\[/g;
2238
2239 my @args = split('\s*,\s*', $arg);
2240 if ($args[0] =~ m/\*/) {
2241 $args[0] =~ s/(\*+)\s*/ $1/;
2242 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002243
2244 my @first_arg;
2245 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2246 shift @args;
2247 push(@first_arg, split('\s+', $1));
2248 push(@first_arg, $2);
2249 } else {
2250 @first_arg = split('\s+', shift @args);
2251 }
2252
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 unshift(@args, pop @first_arg);
2254 $type = join " ", @first_arg;
2255
2256 foreach $param (@args) {
2257 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002258 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 push_parameter($2, "$type $1", $file);
2260 }
2261 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002262 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002263 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002264 push_parameter($1, "$type:$2", $file)
2265 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 }
2267 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002268 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 push_parameter($param, $type, $file);
2270 }
2271 }
2272 }
2273 }
2274}
2275
2276sub push_parameter($$$) {
2277 my $param = shift;
2278 my $type = shift;
2279 my $file = shift;
2280
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002281 if (($anon_struct_union == 1) && ($type eq "") &&
2282 ($param eq "}")) {
2283 return; # ignore the ending }; from anon. struct/union
2284 }
2285
2286 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 my $param_name = $param;
2288 $param_name =~ s/\[.*//;
2289
Martin Waitza6d3fe72006-01-09 20:53:55 -08002290 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 {
Randy Dunlapced69092008-12-01 13:14:03 -08002292 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2293 $parameterdescs{$param} = "variable arguments";
2294 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 }
2296 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2297 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 $param="void";
2299 $parameterdescs{void} = "no arguments";
2300 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002301 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2302 # handle unnamed (anonymous) union or struct:
2303 {
2304 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002305 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002306 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002307 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002308 }
2309
Martin Waitza6d3fe72006-01-09 20:53:55 -08002310 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002311 # (but ignore ones starting with # as these are not parameters
2312 # but inline preprocessor statements);
2313 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002314 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002315 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2316
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 $parameterdescs{$param_name} = $undescribed;
2318
2319 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002320 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 "or member '$param' not " .
2322 "described in '$declaration_name'\n";
2323 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002324 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002325 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002327 }
2328 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002330 $param = xml_escape($param);
2331
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002332 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002333 # on @parameterlist;
2334 # this fixes a problem where check_sections() cannot find
2335 # a parameter like "addr[6 + 2]" because it actually appears
2336 # as "addr[6", "+", "2]" on the parameter list;
2337 # but it's better to maintain the param string unchanged for output,
2338 # so just weaken the string compare in check_sections() to ignore
2339 # "[blah" in a parameter string;
2340 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 push @parameterlist, $param;
2342 $parametertypes{$param} = $type;
2343}
2344
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002345sub check_sections($$$$$$) {
2346 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2347 my @sects = split ' ', $sectcheck;
2348 my @prms = split ' ', $prmscheck;
2349 my $err;
2350 my ($px, $sx);
2351 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2352
2353 foreach $sx (0 .. $#sects) {
2354 $err = 1;
2355 foreach $px (0 .. $#prms) {
2356 $prm_clean = $prms[$px];
2357 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002358 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002359 # ignore array size in a parameter string;
2360 # however, the original param string may contain
2361 # spaces, e.g.: addr[6 + 2]
2362 # and this appears in @prms as "addr[6" since the
2363 # parameter list is split at spaces;
2364 # hence just ignore "[..." for the sections check;
2365 $prm_clean =~ s/\[.*//;
2366
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002367 ##$prm_clean =~ s/^\**//;
2368 if ($prm_clean eq $sects[$sx]) {
2369 $err = 0;
2370 last;
2371 }
2372 }
2373 if ($err) {
2374 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002375 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002376 "Excess function parameter " .
2377 "'$sects[$sx]' " .
2378 "description in '$decl_name'\n";
2379 ++$warnings;
2380 } else {
2381 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002382 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002383 "Excess struct/union/enum/typedef member " .
2384 "'$sects[$sx]' " .
2385 "description in '$decl_name'\n";
2386 ++$warnings;
2387 }
2388 }
2389 }
2390 }
2391}
2392
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002394# Checks the section describing the return value of a function.
2395sub check_return_section {
2396 my $file = shift;
2397 my $declaration_name = shift;
2398 my $return_type = shift;
2399
2400 # Ignore an empty return type (It's a macro)
2401 # Ignore functions with a "void" return type. (But don't ignore "void *")
2402 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2403 return;
2404 }
2405
2406 if (!defined($sections{$section_return}) ||
2407 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002408 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002409 "No description found for return value of " .
2410 "'$declaration_name'\n";
2411 ++$warnings;
2412 }
2413}
2414
2415##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416# takes a function prototype and the name of the current file being
2417# processed and spits out all the details stored in the global
2418# arrays/hashes.
2419sub dump_function($$) {
2420 my $prototype = shift;
2421 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002422 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423
2424 $prototype =~ s/^static +//;
2425 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002426 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427 $prototype =~ s/^inline +//;
2428 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002429 $prototype =~ s/^__inline +//;
2430 $prototype =~ s/^__always_inline +//;
2431 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002432 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002433 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002434 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002435 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002436 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002437 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002438 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439
2440 # Yes, this truly is vile. We are looking for:
2441 # 1. Return type (may be nothing if we're looking at a macro)
2442 # 2. Function name
2443 # 3. Function parameters.
2444 #
2445 # All the while we have to watch out for function pointer parameters
2446 # (which IIRC is what the two sections are for), C types (these
2447 # regexps don't even start to express all the possibilities), and
2448 # so on.
2449 #
2450 # If you mess with these regexps, it's a good idea to check that
2451 # the following functions' documentation still comes out right:
2452 # - parport_register_device (function pointer parameters)
2453 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002454 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002456 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2457 # This is an object-like macro, it has no return type and no parameter
2458 # list.
2459 # Function-like macros are not allowed to have spaces between
2460 # declaration_name and opening parenthesis (notice the \s+).
2461 $return_type = $1;
2462 $declaration_name = $2;
2463 $noret = 1;
2464 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2466 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2467 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002468 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2470 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2471 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2472 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2473 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2474 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2475 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2476 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002477 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2478 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002479 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2480 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 $return_type = $1;
2482 $declaration_name = $2;
2483 my $args = $3;
2484
2485 create_parameterlist($args, ',', $file);
2486 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002487 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 return;
2489 }
2490
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002491 my $prms = join " ", @parameterlist;
2492 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2493
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002494 # This check emits a lot of warnings at the moment, because many
2495 # functions don't have a 'Return' doc section. So until the number
2496 # of warnings goes sufficiently down, the check is only performed in
2497 # verbose mode.
2498 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002499 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002500 check_return_section($file, $declaration_name, $return_type);
2501 }
2502
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002503 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 'function',
2505 {'function' => $declaration_name,
2506 'module' => $modulename,
2507 'functiontype' => $return_type,
2508 'parameterlist' => \@parameterlist,
2509 'parameterdescs' => \%parameterdescs,
2510 'parametertypes' => \%parametertypes,
2511 'sectionlist' => \@sectionlist,
2512 'sections' => \%sections,
2513 'purpose' => $declaration_purpose
2514 });
2515}
2516
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517sub reset_state {
2518 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 %parameterdescs = ();
2520 %parametertypes = ();
2521 @parameterlist = ();
2522 %sections = ();
2523 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002524 $sectcheck = "";
2525 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002527
Jani Nikula48af6062016-05-26 14:56:05 +03002528 $state = STATE_NORMAL;
2529 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530}
2531
Jason Baron56afb0f2009-04-30 13:29:36 -04002532sub tracepoint_munge($) {
2533 my $file = shift;
2534 my $tracepointname = 0;
2535 my $tracepointargs = 0;
2536
Jason Baron3a9089f2009-12-01 12:18:49 -05002537 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002538 $tracepointname = $1;
2539 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002540 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2541 $tracepointname = $1;
2542 }
2543 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2544 $tracepointname = $2;
2545 }
2546 $tracepointname =~ s/^\s+//; #strip leading whitespace
2547 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002548 $tracepointargs = $1;
2549 }
2550 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002551 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002552 "$prototype\n";
2553 } else {
2554 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2555 }
2556}
2557
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002558sub syscall_munge() {
2559 my $void = 0;
2560
2561 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2562## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2563 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2564 $void = 1;
2565## $prototype = "long sys_$1(void)";
2566 }
2567
2568 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2569 if ($prototype =~ m/long (sys_.*?),/) {
2570 $prototype =~ s/,/\(/;
2571 } elsif ($void) {
2572 $prototype =~ s/\)/\(void\)/;
2573 }
2574
2575 # now delete all of the odd-number commas in $prototype
2576 # so that arg types & arg names don't have a comma between them
2577 my $count = 0;
2578 my $len = length($prototype);
2579 if ($void) {
2580 $len = 0; # skip the for-loop
2581 }
2582 for (my $ix = 0; $ix < $len; $ix++) {
2583 if (substr($prototype, $ix, 1) eq ',') {
2584 $count++;
2585 if ($count % 2 == 1) {
2586 substr($prototype, $ix, 1) = ' ';
2587 }
2588 }
2589 }
2590}
2591
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002592sub process_state3_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 my $x = shift;
2594 my $file = shift;
2595
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002596 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2597
Randy Dunlap890c78c2008-10-25 17:06:43 -07002598 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 # do nothing
2600 }
2601 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002602 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002604
Randy Dunlap890c78c2008-10-25 17:06:43 -07002605 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002606 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2608 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002609 if ($prototype =~ /SYSCALL_DEFINE/) {
2610 syscall_munge();
2611 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002612 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2613 $prototype =~ /DEFINE_SINGLE_EVENT/)
2614 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002615 tracepoint_munge($file);
2616 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002617 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 reset_state();
2619 }
2620}
2621
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002622sub process_state3_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 my $x = shift;
2624 my $file = shift;
2625
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2627 $x =~ s@^\s+@@gos; # strip leading spaces
2628 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002629 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2630
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 if ($x =~ /^#/) {
2632 # To distinguish preprocessor directive from regular declaration later.
2633 $x .= ";";
2634 }
2635
2636 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002637 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 $prototype .= $1 . $2;
2639 ($2 eq '{') && $brcount++;
2640 ($2 eq '}') && $brcount--;
2641 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002642 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002644 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 }
2646 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002647 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 $prototype .= $x;
2649 last;
2650 }
2651 }
2652}
2653
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002654# xml_escape: replace <, >, and & in the text stream;
2655#
2656# however, formatting controls that are generated internally/locally in the
2657# kernel-doc script are not escaped here; instead, they begin life like
2658# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2659# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2660# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661sub xml_escape($) {
2662 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002663 if (($output_mode eq "text") || ($output_mode eq "man")) {
2664 return $text;
2665 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 $text =~ s/\&/\\\\\\amp;/g;
2667 $text =~ s/\</\\\\\\lt;/g;
2668 $text =~ s/\>/\\\\\\gt;/g;
2669 return $text;
2670}
2671
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002672# xml_unescape: reverse the effects of xml_escape
2673sub xml_unescape($) {
2674 my $text = shift;
2675 if (($output_mode eq "text") || ($output_mode eq "man")) {
2676 return $text;
2677 }
2678 $text =~ s/\\\\\\amp;/\&/g;
2679 $text =~ s/\\\\\\lt;/</g;
2680 $text =~ s/\\\\\\gt;/>/g;
2681 return $text;
2682}
2683
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002684# convert local escape strings to html
2685# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2686sub local_unescape($) {
2687 my $text = shift;
2688 if (($output_mode eq "text") || ($output_mode eq "man")) {
2689 return $text;
2690 }
2691 $text =~ s/\\\\\\\\lt:/</g;
2692 $text =~ s/\\\\\\\\gt:/>/g;
2693 return $text;
2694}
2695
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002697 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 my $identifier;
2699 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002700 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002701 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002703 my ($orig_file) = @_;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704
Randy Dunlap2283a112005-07-07 15:39:26 -07002705 if (defined($ENV{'SRCTREE'})) {
Ben Hutchings68f86662015-09-01 23:48:49 +01002706 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002707 }
2708 else {
Ben Hutchings68f86662015-09-01 23:48:49 +01002709 $file = $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002710 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 if (defined($source_map{$file})) {
2712 $file = $source_map{$file};
2713 }
2714
2715 if (!open(IN,"<$file")) {
2716 print STDERR "Error: Cannot open file $file\n";
2717 ++$errors;
2718 return;
2719 }
2720
Jani Nikula86ae2e32016-01-21 13:05:22 +02002721 # two passes for -export and -internal
Jani Nikulab6c3f452016-05-29 22:19:35 +03002722 if ($output_selection == OUTPUT_EXPORTED ||
2723 $output_selection == OUTPUT_INTERNAL) {
Jani Nikula86ae2e32016-01-21 13:05:22 +02002724 while (<IN>) {
2725 if (/$export_symbol/o) {
2726 $function_table{$2} = 1;
2727 }
2728 }
2729 seek(IN, 0, 0);
2730 }
2731
Ilya Dryomova9e73142010-02-26 13:05:47 -08002732 $. = 1;
2733
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 $section_counter = 0;
2735 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002736 while (s/\\\s*$//) {
2737 $_ .= <IN>;
2738 }
Jani Nikula48af6062016-05-26 14:56:05 +03002739 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002741 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002742 $in_doc_sect = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 }
Jani Nikula48af6062016-05-26 14:56:05 +03002744 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002746 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 $contents = "";
2748 if ( $1 eq "" ) {
2749 $section = $section_intro;
2750 } else {
2751 $section = $1;
2752 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002753 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 elsif (/$doc_decl/o) {
2755 $identifier = $1;
2756 if (/\s*([\w\s]+?)\s*-/) {
2757 $identifier = $1;
2758 }
2759
Jani Nikula48af6062016-05-26 14:56:05 +03002760 $state = STATE_FIELD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002762 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002763 $descr= $1;
2764 $descr =~ s/^\s*//;
2765 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002766 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002767 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002768 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 } else {
2770 $declaration_purpose = "";
2771 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002772
2773 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002774 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002775 print STDERR $_;
2776 ++$warnings;
2777 }
2778
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 if ($identifier =~ m/^struct/) {
2780 $decl_type = 'struct';
2781 } elsif ($identifier =~ m/^union/) {
2782 $decl_type = 'union';
2783 } elsif ($identifier =~ m/^enum/) {
2784 $decl_type = 'enum';
2785 } elsif ($identifier =~ m/^typedef/) {
2786 $decl_type = 'typedef';
2787 } else {
2788 $decl_type = 'function';
2789 }
2790
2791 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002792 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 }
2794 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002795 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 " - I thought it was a doc line\n";
2797 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002798 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 }
Jani Nikula48af6062016-05-26 14:56:05 +03002800 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 if (/$doc_sect/o) {
2802 $newsection = $1;
2803 $newcontents = $2;
2804
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002805 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002806 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002807 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002808 ++$warnings;
2809 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002810 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 $section = $section_default;
2812 }
2813
Randy Dunlap850622d2006-06-25 05:48:55 -07002814 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002815 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 $contents = $newcontents;
2817 if ($contents ne "") {
Randy Dunlap27205742006-10-11 01:22:12 -07002818 while ((substr($contents, 0, 1) eq " ") ||
2819 substr($contents, 0, 1) eq "\t") {
2820 $contents = substr($contents, 1);
Randy Dunlap05189492006-06-25 05:47:47 -07002821 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 $contents .= "\n";
2823 }
2824 $section = $newsection;
2825 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002826 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002827 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 $section = $section_default;
2829 $contents = "";
2830 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002831 # look for doc_com + <text> + doc_end:
2832 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002833 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002834 ++$warnings;
2835 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836
2837 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002838 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002840# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 } elsif (/$doc_content/) {
2842 # miguel-style comment kludge, look for blank lines after
2843 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002844 if ($1 eq "") {
2845 if ($section =~ m/^@/ || $section eq $section_context) {
2846 dump_section($file, $section, xml_escape($contents));
2847 $section = $section_default;
2848 $contents = "";
2849 } else {
2850 $contents .= "\n";
2851 }
2852 $in_purpose = 0;
2853 } elsif ($in_purpose == 1) {
2854 # Continued declaration purpose
2855 chomp($declaration_purpose);
2856 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002857 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002859 $contents .= $1 . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 }
2861 } else {
2862 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002863 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 ++$warnings;
2865 }
Jani Nikula48af6062016-05-26 14:56:05 +03002866 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002867 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03002868 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002869 $section = $1;
2870 $contents = $2;
2871 if ($contents ne "") {
2872 while ((substr($contents, 0, 1) eq " ") ||
2873 substr($contents, 0, 1) eq "\t") {
2874 $contents = substr($contents, 1);
2875 }
Jani Nikulaa0b96c22016-05-26 22:04:06 +03002876 $contents .= "\n";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002877 }
Jani Nikula48af6062016-05-26 14:56:05 +03002878 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002879 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03002880 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002881 if (($contents ne "") && ($contents ne "\n")) {
2882 dump_section($file, $section, xml_escape($contents));
2883 $section = $section_default;
2884 $contents = "";
2885 }
Jani Nikula48af6062016-05-26 14:56:05 +03002886 $state = STATE_PROTO;
2887 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002888 # Regular text
2889 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03002890 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002891 $contents .= $1 . "\n";
Jani Nikula48af6062016-05-26 14:56:05 +03002892 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
2893 $inline_doc_state = STATE_INLINE_ERROR;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002894 print STDERR "Warning(${file}:$.): ";
2895 print STDERR "Incorrect use of kernel-doc format: $_";
2896 ++$warnings;
2897 }
2898 }
Jani Nikula48af6062016-05-26 14:56:05 +03002899 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
2900 if (/$doc_inline_start/) {
2901 $state = STATE_INLINE;
2902 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002903 } elsif ($decl_type eq 'function') {
Randy Dunlap3c308792007-05-08 00:24:39 -07002904 process_state3_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -07002906 process_state3_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 }
Jani Nikula48af6062016-05-26 14:56:05 +03002908 } elsif ($state == STATE_DOCBLOCK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 # Documentation block
Randy Dunlap3c308792007-05-08 00:24:39 -07002910 if (/$doc_block/) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002911 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 $contents = "";
2913 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 %parameterdescs = ();
2915 %parametertypes = ();
2916 @parameterlist = ();
2917 %sections = ();
2918 @sectionlist = ();
2919 $prototype = "";
2920 if ( $1 eq "" ) {
2921 $section = $section_intro;
2922 } else {
2923 $section = $1;
2924 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002925 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 elsif (/$doc_end/)
2927 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002928 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 $contents = "";
2930 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 %parameterdescs = ();
2932 %parametertypes = ();
2933 @parameterlist = ();
2934 %sections = ();
2935 @sectionlist = ();
2936 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002937 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 }
2939 elsif (/$doc_content/)
2940 {
2941 if ( $1 eq "" )
2942 {
2943 $contents .= $blankline;
2944 }
2945 else
2946 {
2947 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002948 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002949 }
2950 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 }
2952 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002953 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002954 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08002955 print STDERR " Was looking for '$_'.\n" for keys %function_table;
2956 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 if ($output_mode eq "xml") {
2958 # The template wants at least one RefEntry here; make one.
2959 print "<refentry>\n";
2960 print " <refnamediv>\n";
2961 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01002962 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 print " </refname>\n";
2964 print " <refpurpose>\n";
2965 print " Document generation inconsistency\n";
2966 print " </refpurpose>\n";
2967 print " </refnamediv>\n";
2968 print " <refsect1>\n";
2969 print " <title>\n";
2970 print " Oops\n";
2971 print " </title>\n";
2972 print " <warning>\n";
2973 print " <para>\n";
2974 print " The template for this document tried to insert\n";
2975 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01002976 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 print " but none was found.\n";
2978 print " This dummy section is inserted to allow\n";
2979 print " generation to continue.\n";
2980 print " </para>\n";
2981 print " </warning>\n";
2982 print " </refsect1>\n";
2983 print "</refentry>\n";
2984 }
2985 }
2986}
Randy Dunlap8484baa2011-01-05 16:28:43 -08002987
2988
2989$kernelversion = get_kernel_version();
2990
2991# generate a sequence of code that will splice in highlighting information
2992# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02002993for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03002994 my $pattern = $highlights[$k][0];
2995 my $result = $highlights[$k][1];
2996# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
2997 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08002998}
2999
3000# Read the file that maps relative names to absolute names for
3001# separate source and object directories and for shadow trees.
3002if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3003 my ($relname, $absname);
3004 while(<SOURCE_MAP>) {
3005 chop();
3006 ($relname, $absname) = (split())[0..1];
3007 $relname =~ s:^/+::;
3008 $source_map{$relname} = $absname;
3009 }
3010 close(SOURCE_MAP);
3011}
3012
3013foreach (@ARGV) {
3014 chomp;
3015 process_file($_);
3016}
3017if ($verbose && $errors) {
3018 print STDERR "$errors errors\n";
3019}
3020if ($verbose && $warnings) {
3021 print STDERR "$warnings warnings\n";
3022}
3023
3024exit($errors);