blob: 20136564f2649a3463f10c9e2c39aa8c26c6e8e2 [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 Nikulaf624ade2016-05-29 11:35:28 +0300404# @params and a strictly limited set of supported section names
405my $doc_sect = $doc_com . '\s*(\@\w+|description|context|returns?)\s*:(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700406my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700407my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Jani Nikula48af6062016-05-26 14:56:05 +0300408my $doc_inline_start = '^\s*/\*\*\s*$';
409my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
410my $doc_inline_end = '^\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200411my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413my %parameterdescs;
414my @parameterlist;
415my %sections;
416my @sectionlist;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800417my $sectcheck;
418my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420my $contents = "";
Jani Nikulaf624ade2016-05-29 11:35:28 +0300421
422# the canonical section names. see also $doc_sect above.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423my $section_default = "Description"; # default section
424my $section_intro = "Introduction";
425my $section = $section_default;
426my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100427my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428
429my $undescribed = "-- undescribed --";
430
431reset_state();
432
433while ($ARGV[0] =~ m/^-(.*)/) {
434 my $cmd = shift @ARGV;
435 if ($cmd eq "-html") {
436 $output_mode = "html";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300437 @highlights = @highlights_html;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200439 } elsif ($cmd eq "-html5") {
440 $output_mode = "html5";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300441 @highlights = @highlights_html5;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200442 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 } elsif ($cmd eq "-man") {
444 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300445 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 $blankline = $blankline_man;
447 } elsif ($cmd eq "-text") {
448 $output_mode = "text";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300449 @highlights = @highlights_text;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 $blankline = $blankline_text;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300451 } elsif ($cmd eq "-rst") {
452 $output_mode = "rst";
453 @highlights = @highlights_rst;
454 $blankline = $blankline_rst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 } elsif ($cmd eq "-docbook") {
456 $output_mode = "xml";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300457 @highlights = @highlights_xml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700459 } elsif ($cmd eq "-list") {
460 $output_mode = "list";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300461 @highlights = @highlights_list;
Johannes Bergeda603f2010-09-11 15:55:22 -0700462 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 } elsif ($cmd eq "-gnome") {
464 $output_mode = "gnome";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300465 @highlights = @highlights_gnome;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 $blankline = $blankline_gnome;
467 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
468 $modulename = shift @ARGV;
469 } elsif ($cmd eq "-function") { # to only output specific functions
Jani Nikulab6c3f452016-05-29 22:19:35 +0300470 $output_selection = OUTPUT_INCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 $function = shift @ARGV;
472 $function_table{$function} = 1;
Jani Nikulab6c3f452016-05-29 22:19:35 +0300473 } elsif ($cmd eq "-nofunction") { # output all except specific functions
474 $output_selection = OUTPUT_EXCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 $function = shift @ARGV;
476 $function_table{$function} = 1;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200477 } elsif ($cmd eq "-export") { # only exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300478 $output_selection = OUTPUT_EXPORTED;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200479 %function_table = ()
480 } elsif ($cmd eq "-internal") { # only non-exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300481 $output_selection = OUTPUT_INTERNAL;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200482 %function_table = ()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 } elsif ($cmd eq "-v") {
484 $verbose = 1;
485 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
486 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700487 } elsif ($cmd eq '-no-doc-sections') {
488 $no_doc_sections = 1;
Johannes Berge946c43a2013-11-12 15:11:12 -0800489 } elsif ($cmd eq '-show-not-found') {
490 $show_not_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 }
492}
493
Randy Dunlap8484baa2011-01-05 16:28:43 -0800494# continue execution near EOF;
495
Borislav Petkov53f049f2007-05-08 00:30:54 -0700496# get kernel version from env
497sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700498 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700499
500 if (defined($ENV{'KERNELVERSION'})) {
501 $version = $ENV{'KERNELVERSION'};
502 }
503 return $version;
504}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506##
507# dumps section contents to arrays/hashes intended for that purpose.
508#
509sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700510 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 my $name = shift;
512 my $contents = join "\n", @_;
513
Jani Nikula13901ef2016-05-26 08:57:29 +0300514 if ($name =~ m/$type_param/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515# print STDERR "parameter def '$1' = '$contents'\n";
516 $name = $1;
517 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800518 $sectcheck = $sectcheck . $name . " ";
Randy Dunlapced69092008-12-01 13:14:03 -0800519 } elsif ($name eq "@\.\.\.") {
520# print STDERR "parameter def '...' = '$contents'\n";
521 $name = "...";
522 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800523 $sectcheck = $sectcheck . $name . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 } else {
525# print STDERR "other section '$name' = '$contents'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700526 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Bart Van Assched40e1e62015-09-04 15:43:21 -0700527 print STDERR "${file}:$.: error: duplicate section name '$name'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700528 ++$errors;
529 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 $sections{$name} = $contents;
531 push @sectionlist, $name;
532 }
533}
534
535##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700536# dump DOC: section after checking that it should go out
537#
538sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700539 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700540 my $name = shift;
541 my $contents = join "\n", @_;
542
Johannes Berg4b445952007-10-24 15:08:48 -0700543 if ($no_doc_sections) {
544 return;
545 }
546
Jani Nikulab6c3f452016-05-29 22:19:35 +0300547 if (($output_selection == OUTPUT_ALL) ||
548 ($output_selection == OUTPUT_INCLUDE &&
549 defined($function_table{$name})) ||
550 ($output_selection == OUTPUT_EXCLUDE &&
551 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700552 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700553 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700554 output_blockhead({'sectionlist' => \@sectionlist,
555 'sections' => \%sections,
556 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300557 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700558 }
559}
560
561##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562# output function
563#
564# parameterdescs, a hash.
565# function => "function name"
566# parameterlist => @list of parameters
567# parameterdescs => %parameter descriptions
568# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800569# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800570#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
572sub output_highlight {
573 my $contents = join "\n",@_;
574 my $line;
575
576# DEBUG
577# if (!defined $contents) {
578# use Carp;
579# confess "output_highlight got called with no args?\n";
580# }
581
Dan Luedtke1b40c192012-08-12 10:46:15 +0200582 if ($output_mode eq "html" || $output_mode eq "html5" ||
583 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700584 $contents = local_unescape($contents);
585 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800586 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700587 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700588# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 eval $dohighlight;
590 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700591# print STDERR "contents af:$contents\n";
592
Dan Luedtke1b40c192012-08-12 10:46:15 +0200593# strip whitespaces when generating html5
594 if ($output_mode eq "html5") {
595 $contents =~ s/^\s+//;
596 $contents =~ s/\s+$//;
597 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700599 if (! $output_preformatted) {
600 $line =~ s/^\s*//;
601 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700602 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700603 if (! $output_preformatted) {
604 print $lineprefix, local_unescape($blankline);
605 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700607 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700608 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
609 print "\\&$line";
610 } else {
611 print $lineprefix, $line;
612 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
614 print "\n";
615 }
616}
617
Dan Luedtke1b40c192012-08-12 10:46:15 +0200618# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619sub output_section_html(%) {
620 my %args = %{$_[0]};
621 my $section;
622
623 foreach $section (@{$args{'sectionlist'}}) {
624 print "<h3>$section</h3>\n";
625 print "<blockquote>\n";
626 output_highlight($args{'sections'}{$section});
627 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800628 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629}
630
631# output enum in html
632sub output_enum_html(%) {
633 my %args = %{$_[0]};
634 my ($parameter);
635 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700636 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637
Randy Dunlapb9d973282009-06-09 08:50:38 -0700638 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 $count = 0;
640 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700641 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 if ($count != $#{$args{'parameterlist'}}) {
643 $count++;
644 print ",\n";
645 }
646 print "<br>";
647 }
648 print "};<br>\n";
649
650 print "<h3>Constants</h3>\n";
651 print "<dl>\n";
652 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700653 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 print "<dd>";
655 output_highlight($args{'parameterdescs'}{$parameter});
656 }
657 print "</dl>\n";
658 output_section_html(@_);
659 print "<hr>\n";
660}
661
Randy Dunlapd28bee02006-02-01 03:06:57 -0800662# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663sub output_typedef_html(%) {
664 my %args = %{$_[0]};
665 my ($parameter);
666 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700667 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Randy Dunlapb9d973282009-06-09 08:50:38 -0700669 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 output_section_html(@_);
671 print "<hr>\n";
672}
673
674# output struct in html
675sub output_struct_html(%) {
676 my %args = %{$_[0]};
677 my ($parameter);
678
Randy Dunlapb9d973282009-06-09 08:50:38 -0700679 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
680 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 foreach $parameter (@{$args{'parameterlist'}}) {
682 if ($parameter =~ /^#/) {
683 print "$parameter<br>\n";
684 next;
685 }
686 my $parameter_name = $parameter;
687 $parameter_name =~ s/\[.*//;
688
Randy Dunlap3c308792007-05-08 00:24:39 -0700689 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 $type = $args{'parametertypes'}{$parameter};
691 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
692 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700693 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700695 # bitfield
696 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700698 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 }
700 }
701 print "};<br>\n";
702
703 print "<h3>Members</h3>\n";
704 print "<dl>\n";
705 foreach $parameter (@{$args{'parameterlist'}}) {
706 ($parameter =~ /^#/) && next;
707
708 my $parameter_name = $parameter;
709 $parameter_name =~ s/\[.*//;
710
Randy Dunlap3c308792007-05-08 00:24:39 -0700711 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700712 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 print "<dd>";
714 output_highlight($args{'parameterdescs'}{$parameter_name});
715 }
716 print "</dl>\n";
717 output_section_html(@_);
718 print "<hr>\n";
719}
720
721# output function in html
722sub output_function_html(%) {
723 my %args = %{$_[0]};
724 my ($parameter, $section);
725 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726
Randy Dunlapb9d973282009-06-09 08:50:38 -0700727 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
728 print "<i>" . $args{'functiontype'} . "</i>\n";
729 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 print "(";
731 $count = 0;
732 foreach $parameter (@{$args{'parameterlist'}}) {
733 $type = $args{'parametertypes'}{$parameter};
734 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
735 # pointer-to-function
736 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
737 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700738 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 }
740 if ($count != $#{$args{'parameterlist'}}) {
741 $count++;
742 print ",\n";
743 }
744 }
745 print ")\n";
746
747 print "<h3>Arguments</h3>\n";
748 print "<dl>\n";
749 foreach $parameter (@{$args{'parameterlist'}}) {
750 my $parameter_name = $parameter;
751 $parameter_name =~ s/\[.*//;
752
Randy Dunlap3c308792007-05-08 00:24:39 -0700753 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700754 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 print "<dd>";
756 output_highlight($args{'parameterdescs'}{$parameter_name});
757 }
758 print "</dl>\n";
759 output_section_html(@_);
760 print "<hr>\n";
761}
762
Johannes Bergb112e0f2007-10-24 15:08:48 -0700763# output DOC: block header in html
764sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 my %args = %{$_[0]};
766 my ($parameter, $section);
767 my $count;
768
769 foreach $section (@{$args{'sectionlist'}}) {
770 print "<h3>$section</h3>\n";
771 print "<ul>\n";
772 output_highlight($args{'sections'}{$section});
773 print "</ul>\n";
774 }
775 print "<hr>\n";
776}
777
Dan Luedtke1b40c192012-08-12 10:46:15 +0200778# output sections in html5
779sub output_section_html5(%) {
780 my %args = %{$_[0]};
781 my $section;
782
783 foreach $section (@{$args{'sectionlist'}}) {
784 print "<section>\n";
785 print "<h1>$section</h1>\n";
786 print "<p>\n";
787 output_highlight($args{'sections'}{$section});
788 print "</p>\n";
789 print "</section>\n";
790 }
791}
792
793# output enum in html5
794sub output_enum_html5(%) {
795 my %args = %{$_[0]};
796 my ($parameter);
797 my $count;
798 my $html5id;
799
800 $html5id = $args{'enum'};
801 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
802 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
803 print "<h1>enum " . $args{'enum'} . "</h1>\n";
804 print "<ol class=\"code\">\n";
805 print "<li>";
806 print "<span class=\"keyword\">enum</span> ";
807 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
808 print "</li>\n";
809 $count = 0;
810 foreach $parameter (@{$args{'parameterlist'}}) {
811 print "<li class=\"indent\">";
812 print "<span class=\"param\">" . $parameter . "</span>";
813 if ($count != $#{$args{'parameterlist'}}) {
814 $count++;
815 print ",";
816 }
817 print "</li>\n";
818 }
819 print "<li>};</li>\n";
820 print "</ol>\n";
821
822 print "<section>\n";
823 print "<h1>Constants</h1>\n";
824 print "<dl>\n";
825 foreach $parameter (@{$args{'parameterlist'}}) {
826 print "<dt>" . $parameter . "</dt>\n";
827 print "<dd>";
828 output_highlight($args{'parameterdescs'}{$parameter});
829 print "</dd>\n";
830 }
831 print "</dl>\n";
832 print "</section>\n";
833 output_section_html5(@_);
834 print "</article>\n";
835}
836
837# output typedef in html5
838sub output_typedef_html5(%) {
839 my %args = %{$_[0]};
840 my ($parameter);
841 my $count;
842 my $html5id;
843
844 $html5id = $args{'typedef'};
845 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
846 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
847 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
848
849 print "<ol class=\"code\">\n";
850 print "<li>";
851 print "<span class=\"keyword\">typedef</span> ";
852 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
853 print "</li>\n";
854 print "</ol>\n";
855 output_section_html5(@_);
856 print "</article>\n";
857}
858
859# output struct in html5
860sub output_struct_html5(%) {
861 my %args = %{$_[0]};
862 my ($parameter);
863 my $html5id;
864
865 $html5id = $args{'struct'};
866 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
867 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
868 print "<hgroup>\n";
869 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
870 print "<h2>". $args{'purpose'} . "</h2>\n";
871 print "</hgroup>\n";
872 print "<ol class=\"code\">\n";
873 print "<li>";
874 print "<span class=\"type\">" . $args{'type'} . "</span> ";
875 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
876 print "</li>\n";
877 foreach $parameter (@{$args{'parameterlist'}}) {
878 print "<li class=\"indent\">";
879 if ($parameter =~ /^#/) {
880 print "<span class=\"param\">" . $parameter ."</span>\n";
881 print "</li>\n";
882 next;
883 }
884 my $parameter_name = $parameter;
885 $parameter_name =~ s/\[.*//;
886
887 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
888 $type = $args{'parametertypes'}{$parameter};
889 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
890 # pointer-to-function
891 print "<span class=\"type\">$1</span> ";
892 print "<span class=\"param\">$parameter</span>";
893 print "<span class=\"type\">)</span> ";
894 print "(<span class=\"args\">$2</span>);";
895 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
896 # bitfield
897 print "<span class=\"type\">$1</span> ";
898 print "<span class=\"param\">$parameter</span>";
899 print "<span class=\"bits\">$2</span>;";
900 } else {
901 print "<span class=\"type\">$type</span> ";
902 print "<span class=\"param\">$parameter</span>;";
903 }
904 print "</li>\n";
905 }
906 print "<li>};</li>\n";
907 print "</ol>\n";
908
909 print "<section>\n";
910 print "<h1>Members</h1>\n";
911 print "<dl>\n";
912 foreach $parameter (@{$args{'parameterlist'}}) {
913 ($parameter =~ /^#/) && next;
914
915 my $parameter_name = $parameter;
916 $parameter_name =~ s/\[.*//;
917
918 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
919 print "<dt>" . $parameter . "</dt>\n";
920 print "<dd>";
921 output_highlight($args{'parameterdescs'}{$parameter_name});
922 print "</dd>\n";
923 }
924 print "</dl>\n";
925 print "</section>\n";
926 output_section_html5(@_);
927 print "</article>\n";
928}
929
930# output function in html5
931sub output_function_html5(%) {
932 my %args = %{$_[0]};
933 my ($parameter, $section);
934 my $count;
935 my $html5id;
936
937 $html5id = $args{'function'};
938 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
939 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
940 print "<hgroup>\n";
941 print "<h1>" . $args{'function'} . "</h1>";
942 print "<h2>" . $args{'purpose'} . "</h2>\n";
943 print "</hgroup>\n";
944 print "<ol class=\"code\">\n";
945 print "<li>";
946 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
947 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
948 print "</li>";
949 $count = 0;
950 foreach $parameter (@{$args{'parameterlist'}}) {
951 print "<li class=\"indent\">";
952 $type = $args{'parametertypes'}{$parameter};
953 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
954 # pointer-to-function
955 print "<span class=\"type\">$1</span> ";
956 print "<span class=\"param\">$parameter</span>";
957 print "<span class=\"type\">)</span> ";
958 print "(<span class=\"args\">$2</span>)";
959 } else {
960 print "<span class=\"type\">$type</span> ";
961 print "<span class=\"param\">$parameter</span>";
962 }
963 if ($count != $#{$args{'parameterlist'}}) {
964 $count++;
965 print ",";
966 }
967 print "</li>\n";
968 }
969 print "<li>)</li>\n";
970 print "</ol>\n";
971
972 print "<section>\n";
973 print "<h1>Arguments</h1>\n";
974 print "<p>\n";
975 print "<dl>\n";
976 foreach $parameter (@{$args{'parameterlist'}}) {
977 my $parameter_name = $parameter;
978 $parameter_name =~ s/\[.*//;
979
980 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
981 print "<dt>" . $parameter . "</dt>\n";
982 print "<dd>";
983 output_highlight($args{'parameterdescs'}{$parameter_name});
984 print "</dd>\n";
985 }
986 print "</dl>\n";
987 print "</section>\n";
988 output_section_html5(@_);
989 print "</article>\n";
990}
991
992# output DOC: block header in html5
993sub output_blockhead_html5(%) {
994 my %args = %{$_[0]};
995 my ($parameter, $section);
996 my $count;
997 my $html5id;
998
999 foreach $section (@{$args{'sectionlist'}}) {
1000 $html5id = $section;
1001 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1002 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1003 print "<h1>$section</h1>\n";
1004 print "<p>\n";
1005 output_highlight($args{'sections'}{$section});
1006 print "</p>\n";
1007 }
1008 print "</article>\n";
1009}
1010
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011sub output_section_xml(%) {
1012 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001013 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 # print out each section
1015 $lineprefix=" ";
1016 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001017 print "<refsect1>\n";
1018 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001020 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001021 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001022 } else {
1023 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 }
1025 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001026 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001028 print "</programlisting></informalexample>\n";
1029 } else {
1030 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001032 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 }
1034}
1035
1036# output function in XML DocBook
1037sub output_function_xml(%) {
1038 my %args = %{$_[0]};
1039 my ($parameter, $section);
1040 my $count;
1041 my $id;
1042
Randy Dunlapb9d973282009-06-09 08:50:38 -07001043 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 $id =~ s/[^A-Za-z0-9]/-/g;
1045
Pavel Pisa5449bc92007-02-10 01:45:37 -08001046 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001047 print "<refentryinfo>\n";
1048 print " <title>LINUX</title>\n";
1049 print " <productname>Kernel Hackers Manual</productname>\n";
1050 print " <date>$man_date</date>\n";
1051 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001053 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001054 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001055 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 print "</refmeta>\n";
1057 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001058 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 print " <refpurpose>\n";
1060 print " ";
1061 output_highlight ($args{'purpose'});
1062 print " </refpurpose>\n";
1063 print "</refnamediv>\n";
1064
1065 print "<refsynopsisdiv>\n";
1066 print " <title>Synopsis</title>\n";
1067 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001068 print " <funcdef>" . $args{'functiontype'} . " ";
1069 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
1071 $count = 0;
1072 if ($#{$args{'parameterlist'}} >= 0) {
1073 foreach $parameter (@{$args{'parameterlist'}}) {
1074 $type = $args{'parametertypes'}{$parameter};
1075 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1076 # pointer-to-function
1077 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1078 print " <funcparams>$2</funcparams></paramdef>\n";
1079 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001080 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 print " <parameter>$parameter</parameter></paramdef>\n";
1082 }
1083 }
1084 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001085 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 }
1087 print " </funcprototype></funcsynopsis>\n";
1088 print "</refsynopsisdiv>\n";
1089
1090 # print parameters
1091 print "<refsect1>\n <title>Arguments</title>\n";
1092 if ($#{$args{'parameterlist'}} >= 0) {
1093 print " <variablelist>\n";
1094 foreach $parameter (@{$args{'parameterlist'}}) {
1095 my $parameter_name = $parameter;
1096 $parameter_name =~ s/\[.*//;
1097
1098 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1099 print " <listitem>\n <para>\n";
1100 $lineprefix=" ";
1101 output_highlight($args{'parameterdescs'}{$parameter_name});
1102 print " </para>\n </listitem>\n </varlistentry>\n";
1103 }
1104 print " </variablelist>\n";
1105 } else {
1106 print " <para>\n None\n </para>\n";
1107 }
1108 print "</refsect1>\n";
1109
1110 output_section_xml(@_);
1111 print "</refentry>\n\n";
1112}
1113
1114# output struct in XML DocBook
1115sub output_struct_xml(%) {
1116 my %args = %{$_[0]};
1117 my ($parameter, $section);
1118 my $id;
1119
Randy Dunlapb9d973282009-06-09 08:50:38 -07001120 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 $id =~ s/[^A-Za-z0-9]/-/g;
1122
Pavel Pisa5449bc92007-02-10 01:45:37 -08001123 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001124 print "<refentryinfo>\n";
1125 print " <title>LINUX</title>\n";
1126 print " <productname>Kernel Hackers Manual</productname>\n";
1127 print " <date>$man_date</date>\n";
1128 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001130 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001131 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001132 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 print "</refmeta>\n";
1134 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001135 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 print " <refpurpose>\n";
1137 print " ";
1138 output_highlight ($args{'purpose'});
1139 print " </refpurpose>\n";
1140 print "</refnamediv>\n";
1141
1142 print "<refsynopsisdiv>\n";
1143 print " <title>Synopsis</title>\n";
1144 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001145 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 foreach $parameter (@{$args{'parameterlist'}}) {
1147 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001148 my $prm = $parameter;
1149 # convert data read & converted thru xml_escape() into &xyz; format:
1150 # This allows us to have #define macros interspersed in a struct.
1151 $prm =~ s/\\\\\\/\&/g;
1152 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 next;
1154 }
1155
1156 my $parameter_name = $parameter;
1157 $parameter_name =~ s/\[.*//;
1158
1159 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001160 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 $type = $args{'parametertypes'}{$parameter};
1162 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1163 # pointer-to-function
1164 print " $1 $parameter) ($2);\n";
1165 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001166 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 print " $1 $parameter$2;\n";
1168 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001169 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 }
1171 }
1172 print "};";
1173 print " </programlisting>\n";
1174 print "</refsynopsisdiv>\n";
1175
1176 print " <refsect1>\n";
1177 print " <title>Members</title>\n";
1178
Randy Dunlap39f00c02008-09-22 13:57:44 -07001179 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180 print " <variablelist>\n";
1181 foreach $parameter (@{$args{'parameterlist'}}) {
1182 ($parameter =~ /^#/) && next;
1183
1184 my $parameter_name = $parameter;
1185 $parameter_name =~ s/\[.*//;
1186
1187 defined($args{'parameterdescs'}{$parameter_name}) || next;
1188 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1189 print " <varlistentry>";
1190 print " <term>$parameter</term>\n";
1191 print " <listitem><para>\n";
1192 output_highlight($args{'parameterdescs'}{$parameter_name});
1193 print " </para></listitem>\n";
1194 print " </varlistentry>\n";
1195 }
1196 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001197 } else {
1198 print " <para>\n None\n </para>\n";
1199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 print " </refsect1>\n";
1201
1202 output_section_xml(@_);
1203
1204 print "</refentry>\n\n";
1205}
1206
1207# output enum in XML DocBook
1208sub output_enum_xml(%) {
1209 my %args = %{$_[0]};
1210 my ($parameter, $section);
1211 my $count;
1212 my $id;
1213
Randy Dunlapb9d973282009-06-09 08:50:38 -07001214 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 $id =~ s/[^A-Za-z0-9]/-/g;
1216
Pavel Pisa5449bc92007-02-10 01:45:37 -08001217 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001218 print "<refentryinfo>\n";
1219 print " <title>LINUX</title>\n";
1220 print " <productname>Kernel Hackers Manual</productname>\n";
1221 print " <date>$man_date</date>\n";
1222 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001224 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001225 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001226 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 print "</refmeta>\n";
1228 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001229 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 print " <refpurpose>\n";
1231 print " ";
1232 output_highlight ($args{'purpose'});
1233 print " </refpurpose>\n";
1234 print "</refnamediv>\n";
1235
1236 print "<refsynopsisdiv>\n";
1237 print " <title>Synopsis</title>\n";
1238 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001239 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 $count = 0;
1241 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001242 print " $parameter";
1243 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 $count++;
1245 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001246 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 print "\n";
1248 }
1249 print "};";
1250 print " </programlisting>\n";
1251 print "</refsynopsisdiv>\n";
1252
1253 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001254 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 print " <variablelist>\n";
1256 foreach $parameter (@{$args{'parameterlist'}}) {
1257 my $parameter_name = $parameter;
1258 $parameter_name =~ s/\[.*//;
1259
1260 print " <varlistentry>";
1261 print " <term>$parameter</term>\n";
1262 print " <listitem><para>\n";
1263 output_highlight($args{'parameterdescs'}{$parameter_name});
1264 print " </para></listitem>\n";
1265 print " </varlistentry>\n";
1266 }
1267 print " </variablelist>\n";
1268 print "</refsect1>\n";
1269
1270 output_section_xml(@_);
1271
1272 print "</refentry>\n\n";
1273}
1274
1275# output typedef in XML DocBook
1276sub output_typedef_xml(%) {
1277 my %args = %{$_[0]};
1278 my ($parameter, $section);
1279 my $id;
1280
Randy Dunlapb9d973282009-06-09 08:50:38 -07001281 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 $id =~ s/[^A-Za-z0-9]/-/g;
1283
Pavel Pisa5449bc92007-02-10 01:45:37 -08001284 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001285 print "<refentryinfo>\n";
1286 print " <title>LINUX</title>\n";
1287 print " <productname>Kernel Hackers Manual</productname>\n";
1288 print " <date>$man_date</date>\n";
1289 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001291 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001292 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 print "</refmeta>\n";
1294 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001295 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 print " <refpurpose>\n";
1297 print " ";
1298 output_highlight ($args{'purpose'});
1299 print " </refpurpose>\n";
1300 print "</refnamediv>\n";
1301
1302 print "<refsynopsisdiv>\n";
1303 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001304 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 print "</refsynopsisdiv>\n";
1306
1307 output_section_xml(@_);
1308
1309 print "</refentry>\n\n";
1310}
1311
1312# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001313sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 my %args = %{$_[0]};
1315 my ($parameter, $section);
1316 my $count;
1317
1318 my $id = $args{'module'};
1319 $id =~ s/[^A-Za-z0-9]/-/g;
1320
1321 # print out each section
1322 $lineprefix=" ";
1323 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001324 if (!$args{'content-only'}) {
1325 print "<refsect1>\n <title>$section</title>\n";
1326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 if ($section =~ m/EXAMPLE/i) {
1328 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001329 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001330 } else {
1331 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 }
1333 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001334 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 if ($section =~ m/EXAMPLE/i) {
1336 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001337 } else {
1338 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001340 if (!$args{'content-only'}) {
1341 print "\n</refsect1>\n";
1342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 }
1344
1345 print "\n\n";
1346}
1347
1348# output in XML DocBook
1349sub output_function_gnome {
1350 my %args = %{$_[0]};
1351 my ($parameter, $section);
1352 my $count;
1353 my $id;
1354
Randy Dunlapb9d973282009-06-09 08:50:38 -07001355 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 $id =~ s/[^A-Za-z0-9]/-/g;
1357
1358 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001359 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360
1361 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001362 print " <funcdef>" . $args{'functiontype'} . " ";
1363 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 print "</function></funcdef>\n";
1365
1366 $count = 0;
1367 if ($#{$args{'parameterlist'}} >= 0) {
1368 foreach $parameter (@{$args{'parameterlist'}}) {
1369 $type = $args{'parametertypes'}{$parameter};
1370 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1371 # pointer-to-function
1372 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1373 print " <funcparams>$2</funcparams></paramdef>\n";
1374 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001375 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 print " <parameter>$parameter</parameter></paramdef>\n";
1377 }
1378 }
1379 } else {
1380 print " <void>\n";
1381 }
1382 print " </funcsynopsis>\n";
1383 if ($#{$args{'parameterlist'}} >= 0) {
1384 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1385 print "<tgroup cols=\"2\">\n";
1386 print "<colspec colwidth=\"2*\">\n";
1387 print "<colspec colwidth=\"8*\">\n";
1388 print "<tbody>\n";
1389 foreach $parameter (@{$args{'parameterlist'}}) {
1390 my $parameter_name = $parameter;
1391 $parameter_name =~ s/\[.*//;
1392
1393 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1394 print " <entry>\n";
1395 $lineprefix=" ";
1396 output_highlight($args{'parameterdescs'}{$parameter_name});
1397 print " </entry></row>\n";
1398 }
1399 print " </tbody></tgroup></informaltable>\n";
1400 } else {
1401 print " <para>\n None\n </para>\n";
1402 }
1403
1404 # print out each section
1405 $lineprefix=" ";
1406 foreach $section (@{$args{'sectionlist'}}) {
1407 print "<simplesect>\n <title>$section</title>\n";
1408 if ($section =~ m/EXAMPLE/i) {
1409 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001410 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 } else {
1412 }
1413 print "<para>\n";
1414 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001415 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 print "</para>\n";
1417 if ($section =~ m/EXAMPLE/i) {
1418 print "</programlisting></example>\n";
1419 } else {
1420 }
1421 print " </simplesect>\n";
1422 }
1423
1424 print "</sect2>\n\n";
1425}
1426
1427##
1428# output function in man
1429sub output_function_man(%) {
1430 my %args = %{$_[0]};
1431 my ($parameter, $section);
1432 my $count;
1433
1434 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1435
1436 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001437 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
1439 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001440 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001441 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001442 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001443 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001444 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 $count = 0;
1446 my $parenth = "(";
1447 my $post = ",";
1448 foreach my $parameter (@{$args{'parameterlist'}}) {
1449 if ($count == $#{$args{'parameterlist'}}) {
1450 $post = ");";
1451 }
1452 $type = $args{'parametertypes'}{$parameter};
1453 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1454 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001455 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 } else {
1457 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001458 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 }
1460 $count++;
1461 $parenth = "";
1462 }
1463
1464 print ".SH ARGUMENTS\n";
1465 foreach $parameter (@{$args{'parameterlist'}}) {
1466 my $parameter_name = $parameter;
1467 $parameter_name =~ s/\[.*//;
1468
Randy Dunlapb9d973282009-06-09 08:50:38 -07001469 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 output_highlight($args{'parameterdescs'}{$parameter_name});
1471 }
1472 foreach $section (@{$args{'sectionlist'}}) {
1473 print ".SH \"", uc $section, "\"\n";
1474 output_highlight($args{'sections'}{$section});
1475 }
1476}
1477
1478##
1479# output enum in man
1480sub output_enum_man(%) {
1481 my %args = %{$_[0]};
1482 my ($parameter, $section);
1483 my $count;
1484
1485 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1486
1487 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001488 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
1490 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001491 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 $count = 0;
1493 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001494 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 if ($count == $#{$args{'parameterlist'}}) {
1496 print "\n};\n";
1497 last;
1498 }
1499 else {
1500 print ", \n.br\n";
1501 }
1502 $count++;
1503 }
1504
1505 print ".SH Constants\n";
1506 foreach $parameter (@{$args{'parameterlist'}}) {
1507 my $parameter_name = $parameter;
1508 $parameter_name =~ s/\[.*//;
1509
Randy Dunlapb9d973282009-06-09 08:50:38 -07001510 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 output_highlight($args{'parameterdescs'}{$parameter_name});
1512 }
1513 foreach $section (@{$args{'sectionlist'}}) {
1514 print ".SH \"$section\"\n";
1515 output_highlight($args{'sections'}{$section});
1516 }
1517}
1518
1519##
1520# output struct in man
1521sub output_struct_man(%) {
1522 my %args = %{$_[0]};
1523 my ($parameter, $section);
1524
Randy Dunlapb9d973282009-06-09 08:50:38 -07001525 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
1527 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001528 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
1530 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001531 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
1533 foreach my $parameter (@{$args{'parameterlist'}}) {
1534 if ($parameter =~ /^#/) {
1535 print ".BI \"$parameter\"\n.br\n";
1536 next;
1537 }
1538 my $parameter_name = $parameter;
1539 $parameter_name =~ s/\[.*//;
1540
Randy Dunlap3c308792007-05-08 00:24:39 -07001541 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 $type = $args{'parametertypes'}{$parameter};
1543 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1544 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001545 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001547 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001548 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 } else {
1550 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001551 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 }
1553 print "\n.br\n";
1554 }
1555 print "};\n.br\n";
1556
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001557 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 foreach $parameter (@{$args{'parameterlist'}}) {
1559 ($parameter =~ /^#/) && next;
1560
1561 my $parameter_name = $parameter;
1562 $parameter_name =~ s/\[.*//;
1563
Randy Dunlap3c308792007-05-08 00:24:39 -07001564 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001565 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 output_highlight($args{'parameterdescs'}{$parameter_name});
1567 }
1568 foreach $section (@{$args{'sectionlist'}}) {
1569 print ".SH \"$section\"\n";
1570 output_highlight($args{'sections'}{$section});
1571 }
1572}
1573
1574##
1575# output typedef in man
1576sub output_typedef_man(%) {
1577 my %args = %{$_[0]};
1578 my ($parameter, $section);
1579
1580 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1581
1582 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001583 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584
1585 foreach $section (@{$args{'sectionlist'}}) {
1586 print ".SH \"$section\"\n";
1587 output_highlight($args{'sections'}{$section});
1588 }
1589}
1590
Johannes Bergb112e0f2007-10-24 15:08:48 -07001591sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 my %args = %{$_[0]};
1593 my ($parameter, $section);
1594 my $count;
1595
1596 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1597
1598 foreach $section (@{$args{'sectionlist'}}) {
1599 print ".SH \"$section\"\n";
1600 output_highlight($args{'sections'}{$section});
1601 }
1602}
1603
1604##
1605# output in text
1606sub output_function_text(%) {
1607 my %args = %{$_[0]};
1608 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001609 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610
Randy Dunlapf47634b2006-07-01 04:36:36 -07001611 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001612 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001613
1614 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001615 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001616 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001617 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001618 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001619 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001621
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 my $count = 0;
1623 foreach my $parameter (@{$args{'parameterlist'}}) {
1624 $type = $args{'parametertypes'}{$parameter};
1625 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1626 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001627 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001629 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 }
1631 if ($count != $#{$args{'parameterlist'}}) {
1632 $count++;
1633 print ",\n";
1634 print " " x length($start);
1635 } else {
1636 print ");\n\n";
1637 }
1638 }
1639
1640 print "Arguments:\n\n";
1641 foreach $parameter (@{$args{'parameterlist'}}) {
1642 my $parameter_name = $parameter;
1643 $parameter_name =~ s/\[.*//;
1644
Randy Dunlapb9d973282009-06-09 08:50:38 -07001645 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 }
1647 output_section_text(@_);
1648}
1649
1650#output sections in text
1651sub output_section_text(%) {
1652 my %args = %{$_[0]};
1653 my $section;
1654
1655 print "\n";
1656 foreach $section (@{$args{'sectionlist'}}) {
1657 print "$section:\n\n";
1658 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001659 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 print "\n\n";
1661}
1662
1663# output enum in text
1664sub output_enum_text(%) {
1665 my %args = %{$_[0]};
1666 my ($parameter);
1667 my $count;
1668 print "Enum:\n\n";
1669
Randy Dunlapb9d973282009-06-09 08:50:38 -07001670 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1671 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 $count = 0;
1673 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001674 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 if ($count != $#{$args{'parameterlist'}}) {
1676 $count++;
1677 print ",";
1678 }
1679 print "\n";
1680 }
1681 print "};\n\n";
1682
1683 print "Constants:\n\n";
1684 foreach $parameter (@{$args{'parameterlist'}}) {
1685 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001686 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687 }
1688
1689 output_section_text(@_);
1690}
1691
1692# output typedef in text
1693sub output_typedef_text(%) {
1694 my %args = %{$_[0]};
1695 my ($parameter);
1696 my $count;
1697 print "Typedef:\n\n";
1698
Randy Dunlapb9d973282009-06-09 08:50:38 -07001699 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 output_section_text(@_);
1701}
1702
1703# output struct as text
1704sub output_struct_text(%) {
1705 my %args = %{$_[0]};
1706 my ($parameter);
1707
Randy Dunlapb9d973282009-06-09 08:50:38 -07001708 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1709 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 foreach $parameter (@{$args{'parameterlist'}}) {
1711 if ($parameter =~ /^#/) {
1712 print "$parameter\n";
1713 next;
1714 }
1715
1716 my $parameter_name = $parameter;
1717 $parameter_name =~ s/\[.*//;
1718
Randy Dunlap3c308792007-05-08 00:24:39 -07001719 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 $type = $args{'parametertypes'}{$parameter};
1721 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1722 # pointer-to-function
1723 print "\t$1 $parameter) ($2);\n";
1724 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001725 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 print "\t$1 $parameter$2;\n";
1727 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001728 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729 }
1730 }
1731 print "};\n\n";
1732
1733 print "Members:\n\n";
1734 foreach $parameter (@{$args{'parameterlist'}}) {
1735 ($parameter =~ /^#/) && next;
1736
1737 my $parameter_name = $parameter;
1738 $parameter_name =~ s/\[.*//;
1739
Randy Dunlap3c308792007-05-08 00:24:39 -07001740 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001741 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001742 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 }
1744 print "\n";
1745 output_section_text(@_);
1746}
1747
Johannes Bergb112e0f2007-10-24 15:08:48 -07001748sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 my %args = %{$_[0]};
1750 my ($parameter, $section);
1751
1752 foreach $section (@{$args{'sectionlist'}}) {
1753 print " $section:\n";
1754 print " -> ";
1755 output_highlight($args{'sections'}{$section});
1756 }
1757}
1758
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001759##
1760# output in restructured text
1761#
1762
1763#
1764# This could use some work; it's used to output the DOC: sections, and
1765# starts by putting out the name of the doc section itself, but that tends
1766# to duplicate a header already in the template file.
1767#
1768sub output_blockhead_rst(%) {
1769 my %args = %{$_[0]};
1770 my ($parameter, $section);
1771
1772 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001773 if ($output_selection != OUTPUT_INCLUDE) {
1774 print "**$section**\n\n";
1775 }
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001776 output_highlight_rst($args{'sections'}{$section});
1777 print "\n";
1778 }
1779}
1780
1781sub output_highlight_rst {
1782 my $contents = join "\n",@_;
1783 my $line;
1784
1785 # undo the evil effects of xml_escape() earlier
1786 $contents = xml_unescape($contents);
1787
1788 eval $dohighlight;
1789 die $@ if $@;
1790
1791 foreach $line (split "\n", $contents) {
Jani Nikula830066a2016-05-26 22:04:33 +03001792 print $lineprefix . $line . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001793 }
1794}
1795
1796sub output_function_rst(%) {
1797 my %args = %{$_[0]};
1798 my ($parameter, $section);
Jani Nikulac099ff62016-05-26 17:18:17 +03001799 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001800 my $start;
1801
1802 print ".. c:function:: ";
1803 if ($args{'functiontype'} ne "") {
1804 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1805 } else {
1806 $start = $args{'function'} . " (";
1807 }
1808 print $start;
1809
1810 my $count = 0;
1811 foreach my $parameter (@{$args{'parameterlist'}}) {
1812 if ($count ne 0) {
1813 print ", ";
1814 }
1815 $count++;
1816 $type = $args{'parametertypes'}{$parameter};
1817 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1818 # pointer-to-function
1819 print $1 . $parameter . ") (" . $2;
1820 } else {
1821 print $type . " " . $parameter;
1822 }
1823 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001824 print ")\n\n";
1825 $lineprefix = " ";
1826 output_highlight_rst($args{'purpose'});
1827 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001828
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001829 print "**Parameters**\n\n";
1830 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001831 foreach $parameter (@{$args{'parameterlist'}}) {
1832 my $parameter_name = $parameter;
1833 #$parameter_name =~ s/\[.*//;
1834 $type = $args{'parametertypes'}{$parameter};
1835
1836 if ($type ne "") {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001837 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001838 } else {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001839 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001840 }
Jani Nikula5e64fa92016-05-19 20:32:48 +03001841 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1842 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001843 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001844 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001845 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001846 }
1847 print "\n";
1848 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001849
1850 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001851 output_section_rst(@_);
1852}
1853
1854sub output_section_rst(%) {
1855 my %args = %{$_[0]};
1856 my $section;
1857 my $oldprefix = $lineprefix;
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001858 $lineprefix = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001859
1860 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001861 print "**$section**\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001862 output_highlight_rst($args{'sections'}{$section});
1863 print "\n";
1864 }
1865 print "\n";
1866 $lineprefix = $oldprefix;
1867}
1868
1869sub output_enum_rst(%) {
1870 my %args = %{$_[0]};
1871 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001872 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001873 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001874 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001875
1876 print "\n\n.. c:type:: " . $name . "\n\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001877 $lineprefix = " ";
1878 output_highlight_rst($args{'purpose'});
1879 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001880
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001881 print "**Constants**\n\n";
1882 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001883 foreach $parameter (@{$args{'parameterlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001884 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001885 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1886 output_highlight_rst($args{'parameterdescs'}{$parameter});
1887 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001888 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001889 }
1890 print "\n";
1891 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001892
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001893 $lineprefix = $oldprefix;
1894 output_section_rst(@_);
1895}
1896
1897sub output_typedef_rst(%) {
1898 my %args = %{$_[0]};
1899 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001900 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001901 my $name = "typedef " . $args{'typedef'};
1902
Jani Nikula62850972016-05-12 16:15:38 +03001903 print "\n\n.. c:type:: " . $name . "\n\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001904 $lineprefix = " ";
1905 output_highlight_rst($args{'purpose'});
1906 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001907
Jani Nikulac099ff62016-05-26 17:18:17 +03001908 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001909 output_section_rst(@_);
1910}
1911
1912sub output_struct_rst(%) {
1913 my %args = %{$_[0]};
1914 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001915 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001916 my $name = $args{'type'} . " " . $args{'struct'};
1917
Jani Nikula62850972016-05-12 16:15:38 +03001918 print "\n\n.. c:type:: " . $name . "\n\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001919 $lineprefix = " ";
1920 output_highlight_rst($args{'purpose'});
1921 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001922
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001923 print "**Definition**\n\n";
1924 print "::\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001925 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1926 foreach $parameter (@{$args{'parameterlist'}}) {
1927 if ($parameter =~ /^#/) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001928 print " " . "$parameter\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001929 next;
1930 }
1931
1932 my $parameter_name = $parameter;
1933 $parameter_name =~ s/\[.*//;
1934
1935 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1936 $type = $args{'parametertypes'}{$parameter};
1937 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1938 # pointer-to-function
1939 print " $1 $parameter) ($2);\n";
1940 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1941 # bitfield
1942 print " $1 $parameter$2;\n";
1943 } else {
1944 print " " . $type . " " . $parameter . ";\n";
1945 }
1946 }
1947 print " };\n\n";
1948
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001949 print "**Members**\n\n";
1950 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001951 foreach $parameter (@{$args{'parameterlist'}}) {
1952 ($parameter =~ /^#/) && next;
1953
1954 my $parameter_name = $parameter;
1955 $parameter_name =~ s/\[.*//;
1956
1957 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1958 $type = $args{'parametertypes'}{$parameter};
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001959 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001960 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001961 print "\n";
1962 }
1963 print "\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001964
1965 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001966 output_section_rst(@_);
1967}
1968
1969
Johannes Bergeda603f2010-09-11 15:55:22 -07001970## list mode output functions
1971
1972sub output_function_list(%) {
1973 my %args = %{$_[0]};
1974
1975 print $args{'function'} . "\n";
1976}
1977
1978# output enum in list
1979sub output_enum_list(%) {
1980 my %args = %{$_[0]};
1981 print $args{'enum'} . "\n";
1982}
1983
1984# output typedef in list
1985sub output_typedef_list(%) {
1986 my %args = %{$_[0]};
1987 print $args{'typedef'} . "\n";
1988}
1989
1990# output struct as list
1991sub output_struct_list(%) {
1992 my %args = %{$_[0]};
1993
1994 print $args{'struct'} . "\n";
1995}
1996
1997sub output_blockhead_list(%) {
1998 my %args = %{$_[0]};
1999 my ($parameter, $section);
2000
2001 foreach $section (@{$args{'sectionlist'}}) {
2002 print "DOC: $section\n";
2003 }
2004}
2005
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006##
Randy Dunlap27205742006-10-11 01:22:12 -07002007# generic output function for all types (function, struct/union, typedef, enum);
2008# calls the generated, variable output_ function name based on
2009# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010sub output_declaration {
2011 no strict 'refs';
2012 my $name = shift;
2013 my $functype = shift;
2014 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002015 if (($output_selection == OUTPUT_ALL) ||
2016 (($output_selection == OUTPUT_INCLUDE ||
2017 $output_selection == OUTPUT_EXPORTED) &&
2018 defined($function_table{$name})) ||
2019 (($output_selection == OUTPUT_EXCLUDE ||
2020 $output_selection == OUTPUT_INTERNAL) &&
2021 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002023 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 $section_counter++;
2025 }
2026}
2027
2028##
Randy Dunlap27205742006-10-11 01:22:12 -07002029# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002030sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002032 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 &$func(@_);
2034 $section_counter++;
2035}
2036
2037##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002038# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039# invokes the right handler. NOT called for functions.
2040sub dump_declaration($$) {
2041 no strict 'refs';
2042 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002043 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 &$func(@_);
2045}
2046
2047sub dump_union($$) {
2048 dump_struct(@_);
2049}
2050
2051sub dump_struct($$) {
2052 my $x = shift;
2053 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002054 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002056 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2057 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002058 $declaration_name = $2;
2059 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060
2061 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002062 $members =~ s/({.*})//g;
2063 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
Martin Waitzaeec46b2005-11-13 16:08:13 -08002065 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002066 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2067 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002068 # strip comments:
2069 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002070 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002071 # strip kmemcheck_bitfield_{begin,end}.*;
2072 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002073 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002074 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002075 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002076 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002077 # replace DECLARE_BITMAP
2078 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002079
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002081 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
2083 output_declaration($declaration_name,
2084 'struct',
2085 {'struct' => $declaration_name,
2086 'module' => $modulename,
2087 'parameterlist' => \@parameterlist,
2088 'parameterdescs' => \%parameterdescs,
2089 'parametertypes' => \%parametertypes,
2090 'sectionlist' => \@sectionlist,
2091 'sections' => \%sections,
2092 'purpose' => $declaration_purpose,
2093 'type' => $decl_type
2094 });
2095 }
2096 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002097 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 ++$errors;
2099 }
2100}
2101
2102sub dump_enum($$) {
2103 my $x = shift;
2104 my $file = shift;
2105
Martin Waitzaeec46b2005-11-13 16:08:13 -08002106 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002107 # strip #define macros inside enums
2108 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002109
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002111 $declaration_name = $1;
2112 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113
2114 foreach my $arg (split ',', $members) {
2115 $arg =~ s/^\s*(\w+).*/$1/;
2116 push @parameterlist, $arg;
2117 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002118 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002119 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 "not described in enum '$declaration_name'\n";
2121 }
2122
2123 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002124
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 output_declaration($declaration_name,
2126 'enum',
2127 {'enum' => $declaration_name,
2128 'module' => $modulename,
2129 'parameterlist' => \@parameterlist,
2130 'parameterdescs' => \%parameterdescs,
2131 'sectionlist' => \@sectionlist,
2132 'sections' => \%sections,
2133 'purpose' => $declaration_purpose
2134 });
2135 }
2136 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002137 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 ++$errors;
2139 }
2140}
2141
2142sub dump_typedef($$) {
2143 my $x = shift;
2144 my $file = shift;
2145
Martin Waitzaeec46b2005-11-13 16:08:13 -08002146 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002147
2148 # Parse function prototypes
2149 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
2150 # Function typedefs
2151 $return_type = $1;
2152 $declaration_name = $2;
2153 my $args = $3;
2154
2155 create_parameterlist($args, ',', $file);
2156
2157 output_declaration($declaration_name,
2158 'function',
2159 {'function' => $declaration_name,
2160 'module' => $modulename,
2161 'functiontype' => $return_type,
2162 'parameterlist' => \@parameterlist,
2163 'parameterdescs' => \%parameterdescs,
2164 'parametertypes' => \%parametertypes,
2165 'sectionlist' => \@sectionlist,
2166 'sections' => \%sections,
2167 'purpose' => $declaration_purpose
2168 });
2169 return;
2170 }
2171
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002173 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 $x =~ s/\[*.\]\s*;$/;/;
2175 }
2176
2177 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002178 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179
2180 output_declaration($declaration_name,
2181 'typedef',
2182 {'typedef' => $declaration_name,
2183 'module' => $modulename,
2184 'sectionlist' => \@sectionlist,
2185 'sections' => \%sections,
2186 'purpose' => $declaration_purpose
2187 });
2188 }
2189 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002190 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 ++$errors;
2192 }
2193}
2194
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002195sub save_struct_actual($) {
2196 my $actual = shift;
2197
2198 # strip all spaces from the actual param so that it looks like one string item
2199 $actual =~ s/\s*//g;
2200 $struct_actual = $struct_actual . $actual . " ";
2201}
2202
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203sub create_parameterlist($$$) {
2204 my $args = shift;
2205 my $splitter = shift;
2206 my $file = shift;
2207 my $type;
2208 my $param;
2209
Martin Waitza6d3fe72006-01-09 20:53:55 -08002210 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002212 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002214
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 foreach my $arg (split($splitter, $args)) {
2216 # strip comments
2217 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002218 # strip leading/trailing spaces
2219 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 $arg =~ s/\s*$//;
2221 $arg =~ s/\s+/ /;
2222
2223 if ($arg =~ /^#/) {
2224 # Treat preprocessor directive as a typeless variable just to fill
2225 # corresponding data structures "correctly". Catch it later in
2226 # output_* subs.
2227 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002228 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 # pointer-to-function
2230 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002231 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 $param = $1;
2233 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002234 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002235 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002237 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 $arg =~ s/\s*:\s*/:/g;
2239 $arg =~ s/\s*\[/\[/g;
2240
2241 my @args = split('\s*,\s*', $arg);
2242 if ($args[0] =~ m/\*/) {
2243 $args[0] =~ s/(\*+)\s*/ $1/;
2244 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002245
2246 my @first_arg;
2247 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2248 shift @args;
2249 push(@first_arg, split('\s+', $1));
2250 push(@first_arg, $2);
2251 } else {
2252 @first_arg = split('\s+', shift @args);
2253 }
2254
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 unshift(@args, pop @first_arg);
2256 $type = join " ", @first_arg;
2257
2258 foreach $param (@args) {
2259 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002260 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 push_parameter($2, "$type $1", $file);
2262 }
2263 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002264 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002265 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002266 push_parameter($1, "$type:$2", $file)
2267 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 }
2269 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002270 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 push_parameter($param, $type, $file);
2272 }
2273 }
2274 }
2275 }
2276}
2277
2278sub push_parameter($$$) {
2279 my $param = shift;
2280 my $type = shift;
2281 my $file = shift;
2282
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002283 if (($anon_struct_union == 1) && ($type eq "") &&
2284 ($param eq "}")) {
2285 return; # ignore the ending }; from anon. struct/union
2286 }
2287
2288 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 my $param_name = $param;
2290 $param_name =~ s/\[.*//;
2291
Martin Waitza6d3fe72006-01-09 20:53:55 -08002292 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 {
Randy Dunlapced69092008-12-01 13:14:03 -08002294 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2295 $parameterdescs{$param} = "variable arguments";
2296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 }
2298 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2299 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 $param="void";
2301 $parameterdescs{void} = "no arguments";
2302 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002303 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2304 # handle unnamed (anonymous) union or struct:
2305 {
2306 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002307 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002308 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002309 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002310 }
2311
Martin Waitza6d3fe72006-01-09 20:53:55 -08002312 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002313 # (but ignore ones starting with # as these are not parameters
2314 # but inline preprocessor statements);
2315 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002316 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002317 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2318
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 $parameterdescs{$param_name} = $undescribed;
2320
2321 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002322 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 "or member '$param' not " .
2324 "described in '$declaration_name'\n";
2325 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002326 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002327 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002329 }
2330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002332 $param = xml_escape($param);
2333
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002334 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002335 # on @parameterlist;
2336 # this fixes a problem where check_sections() cannot find
2337 # a parameter like "addr[6 + 2]" because it actually appears
2338 # as "addr[6", "+", "2]" on the parameter list;
2339 # but it's better to maintain the param string unchanged for output,
2340 # so just weaken the string compare in check_sections() to ignore
2341 # "[blah" in a parameter string;
2342 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 push @parameterlist, $param;
2344 $parametertypes{$param} = $type;
2345}
2346
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002347sub check_sections($$$$$$) {
2348 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2349 my @sects = split ' ', $sectcheck;
2350 my @prms = split ' ', $prmscheck;
2351 my $err;
2352 my ($px, $sx);
2353 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2354
2355 foreach $sx (0 .. $#sects) {
2356 $err = 1;
2357 foreach $px (0 .. $#prms) {
2358 $prm_clean = $prms[$px];
2359 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002360 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002361 # ignore array size in a parameter string;
2362 # however, the original param string may contain
2363 # spaces, e.g.: addr[6 + 2]
2364 # and this appears in @prms as "addr[6" since the
2365 # parameter list is split at spaces;
2366 # hence just ignore "[..." for the sections check;
2367 $prm_clean =~ s/\[.*//;
2368
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002369 ##$prm_clean =~ s/^\**//;
2370 if ($prm_clean eq $sects[$sx]) {
2371 $err = 0;
2372 last;
2373 }
2374 }
2375 if ($err) {
2376 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002377 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002378 "Excess function parameter " .
2379 "'$sects[$sx]' " .
2380 "description in '$decl_name'\n";
2381 ++$warnings;
2382 } else {
2383 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002384 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002385 "Excess struct/union/enum/typedef member " .
2386 "'$sects[$sx]' " .
2387 "description in '$decl_name'\n";
2388 ++$warnings;
2389 }
2390 }
2391 }
2392 }
2393}
2394
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002396# Checks the section describing the return value of a function.
2397sub check_return_section {
2398 my $file = shift;
2399 my $declaration_name = shift;
2400 my $return_type = shift;
2401
2402 # Ignore an empty return type (It's a macro)
2403 # Ignore functions with a "void" return type. (But don't ignore "void *")
2404 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2405 return;
2406 }
2407
2408 if (!defined($sections{$section_return}) ||
2409 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002410 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002411 "No description found for return value of " .
2412 "'$declaration_name'\n";
2413 ++$warnings;
2414 }
2415}
2416
2417##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418# takes a function prototype and the name of the current file being
2419# processed and spits out all the details stored in the global
2420# arrays/hashes.
2421sub dump_function($$) {
2422 my $prototype = shift;
2423 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002424 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425
2426 $prototype =~ s/^static +//;
2427 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002428 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 $prototype =~ s/^inline +//;
2430 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002431 $prototype =~ s/^__inline +//;
2432 $prototype =~ s/^__always_inline +//;
2433 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002434 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002435 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002436 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002437 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002438 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002439 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002440 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
2442 # Yes, this truly is vile. We are looking for:
2443 # 1. Return type (may be nothing if we're looking at a macro)
2444 # 2. Function name
2445 # 3. Function parameters.
2446 #
2447 # All the while we have to watch out for function pointer parameters
2448 # (which IIRC is what the two sections are for), C types (these
2449 # regexps don't even start to express all the possibilities), and
2450 # so on.
2451 #
2452 # If you mess with these regexps, it's a good idea to check that
2453 # the following functions' documentation still comes out right:
2454 # - parport_register_device (function pointer parameters)
2455 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002456 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002458 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2459 # This is an object-like macro, it has no return type and no parameter
2460 # list.
2461 # Function-like macros are not allowed to have spaces between
2462 # declaration_name and opening parenthesis (notice the \s+).
2463 $return_type = $1;
2464 $declaration_name = $2;
2465 $noret = 1;
2466 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2468 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2469 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002470 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2472 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2473 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2474 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2475 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2476 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2477 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2478 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002479 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2480 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002481 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2482 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 $return_type = $1;
2484 $declaration_name = $2;
2485 my $args = $3;
2486
2487 create_parameterlist($args, ',', $file);
2488 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002489 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 return;
2491 }
2492
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002493 my $prms = join " ", @parameterlist;
2494 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2495
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002496 # This check emits a lot of warnings at the moment, because many
2497 # functions don't have a 'Return' doc section. So until the number
2498 # of warnings goes sufficiently down, the check is only performed in
2499 # verbose mode.
2500 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002501 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002502 check_return_section($file, $declaration_name, $return_type);
2503 }
2504
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002505 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 'function',
2507 {'function' => $declaration_name,
2508 'module' => $modulename,
2509 'functiontype' => $return_type,
2510 'parameterlist' => \@parameterlist,
2511 'parameterdescs' => \%parameterdescs,
2512 'parametertypes' => \%parametertypes,
2513 'sectionlist' => \@sectionlist,
2514 'sections' => \%sections,
2515 'purpose' => $declaration_purpose
2516 });
2517}
2518
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519sub reset_state {
2520 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521 %parameterdescs = ();
2522 %parametertypes = ();
2523 @parameterlist = ();
2524 %sections = ();
2525 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002526 $sectcheck = "";
2527 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002529
Jani Nikula48af6062016-05-26 14:56:05 +03002530 $state = STATE_NORMAL;
2531 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532}
2533
Jason Baron56afb0f2009-04-30 13:29:36 -04002534sub tracepoint_munge($) {
2535 my $file = shift;
2536 my $tracepointname = 0;
2537 my $tracepointargs = 0;
2538
Jason Baron3a9089f2009-12-01 12:18:49 -05002539 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002540 $tracepointname = $1;
2541 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002542 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2543 $tracepointname = $1;
2544 }
2545 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2546 $tracepointname = $2;
2547 }
2548 $tracepointname =~ s/^\s+//; #strip leading whitespace
2549 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002550 $tracepointargs = $1;
2551 }
2552 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002553 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002554 "$prototype\n";
2555 } else {
2556 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2557 }
2558}
2559
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002560sub syscall_munge() {
2561 my $void = 0;
2562
2563 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2564## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2565 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2566 $void = 1;
2567## $prototype = "long sys_$1(void)";
2568 }
2569
2570 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2571 if ($prototype =~ m/long (sys_.*?),/) {
2572 $prototype =~ s/,/\(/;
2573 } elsif ($void) {
2574 $prototype =~ s/\)/\(void\)/;
2575 }
2576
2577 # now delete all of the odd-number commas in $prototype
2578 # so that arg types & arg names don't have a comma between them
2579 my $count = 0;
2580 my $len = length($prototype);
2581 if ($void) {
2582 $len = 0; # skip the for-loop
2583 }
2584 for (my $ix = 0; $ix < $len; $ix++) {
2585 if (substr($prototype, $ix, 1) eq ',') {
2586 $count++;
2587 if ($count % 2 == 1) {
2588 substr($prototype, $ix, 1) = ' ';
2589 }
2590 }
2591 }
2592}
2593
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002594sub process_state3_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 my $x = shift;
2596 my $file = shift;
2597
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002598 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2599
Randy Dunlap890c78c2008-10-25 17:06:43 -07002600 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 # do nothing
2602 }
2603 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002604 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002606
Randy Dunlap890c78c2008-10-25 17:06:43 -07002607 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002608 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2610 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002611 if ($prototype =~ /SYSCALL_DEFINE/) {
2612 syscall_munge();
2613 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002614 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2615 $prototype =~ /DEFINE_SINGLE_EVENT/)
2616 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002617 tracepoint_munge($file);
2618 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002619 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 reset_state();
2621 }
2622}
2623
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002624sub process_state3_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 my $x = shift;
2626 my $file = shift;
2627
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2629 $x =~ s@^\s+@@gos; # strip leading spaces
2630 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002631 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2632
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 if ($x =~ /^#/) {
2634 # To distinguish preprocessor directive from regular declaration later.
2635 $x .= ";";
2636 }
2637
2638 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002639 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 $prototype .= $1 . $2;
2641 ($2 eq '{') && $brcount++;
2642 ($2 eq '}') && $brcount--;
2643 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002644 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002646 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 }
2648 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002649 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 $prototype .= $x;
2651 last;
2652 }
2653 }
2654}
2655
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002656# xml_escape: replace <, >, and & in the text stream;
2657#
2658# however, formatting controls that are generated internally/locally in the
2659# kernel-doc script are not escaped here; instead, they begin life like
2660# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2661# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2662# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663sub xml_escape($) {
2664 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002665 if (($output_mode eq "text") || ($output_mode eq "man")) {
2666 return $text;
2667 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 $text =~ s/\&/\\\\\\amp;/g;
2669 $text =~ s/\</\\\\\\lt;/g;
2670 $text =~ s/\>/\\\\\\gt;/g;
2671 return $text;
2672}
2673
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002674# xml_unescape: reverse the effects of xml_escape
2675sub xml_unescape($) {
2676 my $text = shift;
2677 if (($output_mode eq "text") || ($output_mode eq "man")) {
2678 return $text;
2679 }
2680 $text =~ s/\\\\\\amp;/\&/g;
2681 $text =~ s/\\\\\\lt;/</g;
2682 $text =~ s/\\\\\\gt;/>/g;
2683 return $text;
2684}
2685
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002686# convert local escape strings to html
2687# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2688sub local_unescape($) {
2689 my $text = shift;
2690 if (($output_mode eq "text") || ($output_mode eq "man")) {
2691 return $text;
2692 }
2693 $text =~ s/\\\\\\\\lt:/</g;
2694 $text =~ s/\\\\\\\\gt:/>/g;
2695 return $text;
2696}
2697
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002699 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 my $identifier;
2701 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002702 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002703 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002705 my ($orig_file) = @_;
Jani Nikulab7886de2016-05-28 00:41:50 +03002706 my $leading_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707
Randy Dunlap2283a112005-07-07 15:39:26 -07002708 if (defined($ENV{'SRCTREE'})) {
Ben Hutchings68f86662015-09-01 23:48:49 +01002709 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002710 }
2711 else {
Ben Hutchings68f86662015-09-01 23:48:49 +01002712 $file = $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002713 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 if (defined($source_map{$file})) {
2715 $file = $source_map{$file};
2716 }
2717
2718 if (!open(IN,"<$file")) {
2719 print STDERR "Error: Cannot open file $file\n";
2720 ++$errors;
2721 return;
2722 }
2723
Jani Nikula86ae2e32016-01-21 13:05:22 +02002724 # two passes for -export and -internal
Jani Nikulab6c3f452016-05-29 22:19:35 +03002725 if ($output_selection == OUTPUT_EXPORTED ||
2726 $output_selection == OUTPUT_INTERNAL) {
Jani Nikula86ae2e32016-01-21 13:05:22 +02002727 while (<IN>) {
2728 if (/$export_symbol/o) {
2729 $function_table{$2} = 1;
2730 }
2731 }
2732 seek(IN, 0, 0);
2733 }
2734
Ilya Dryomova9e73142010-02-26 13:05:47 -08002735 $. = 1;
2736
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 $section_counter = 0;
2738 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002739 while (s/\\\s*$//) {
2740 $_ .= <IN>;
2741 }
Jani Nikula48af6062016-05-26 14:56:05 +03002742 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002744 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002745 $in_doc_sect = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 }
Jani Nikula48af6062016-05-26 14:56:05 +03002747 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002749 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 $contents = "";
2751 if ( $1 eq "" ) {
2752 $section = $section_intro;
2753 } else {
2754 $section = $1;
2755 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002756 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 elsif (/$doc_decl/o) {
2758 $identifier = $1;
2759 if (/\s*([\w\s]+?)\s*-/) {
2760 $identifier = $1;
2761 }
2762
Jani Nikula48af6062016-05-26 14:56:05 +03002763 $state = STATE_FIELD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002765 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002766 $descr= $1;
2767 $descr =~ s/^\s*//;
2768 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002769 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002770 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002771 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 } else {
2773 $declaration_purpose = "";
2774 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002775
2776 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002777 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002778 print STDERR $_;
2779 ++$warnings;
2780 }
2781
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 if ($identifier =~ m/^struct/) {
2783 $decl_type = 'struct';
2784 } elsif ($identifier =~ m/^union/) {
2785 $decl_type = 'union';
2786 } elsif ($identifier =~ m/^enum/) {
2787 $decl_type = 'enum';
2788 } elsif ($identifier =~ m/^typedef/) {
2789 $decl_type = 'typedef';
2790 } else {
2791 $decl_type = 'function';
2792 }
2793
2794 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002795 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 }
2797 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002798 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 " - I thought it was a doc line\n";
2800 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002801 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 }
Jani Nikula48af6062016-05-26 14:56:05 +03002803 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Jani Nikulaf624ade2016-05-29 11:35:28 +03002804 if (/$doc_sect/i) { # case insensitive for supported section names
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 $newsection = $1;
2806 $newcontents = $2;
2807
Jani Nikulaf624ade2016-05-29 11:35:28 +03002808 # map the supported section names to the canonical names
2809 if ($newsection =~ m/^description$/i) {
2810 $newsection = $section_default;
2811 } elsif ($newsection =~ m/^context$/i) {
2812 $newsection = $section_context;
2813 } elsif ($newsection =~ m/^returns?$/i) {
2814 $newsection = $section_return;
2815 } elsif ($newsection =~ m/^\@return$/) {
2816 # special: @return is a section, not a param description
2817 $newsection = $section_return;
2818 }
2819
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002820 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002821 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002822 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002823 ++$warnings;
2824 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002825 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 $section = $section_default;
2827 }
2828
Randy Dunlap850622d2006-06-25 05:48:55 -07002829 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002830 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 $contents = $newcontents;
Jani Nikula0a726302016-05-28 14:50:20 +03002832 while ((substr($contents, 0, 1) eq " ") ||
2833 substr($contents, 0, 1) eq "\t") {
2834 $contents = substr($contents, 1);
2835 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 if ($contents ne "") {
2837 $contents .= "\n";
2838 }
2839 $section = $newsection;
Jani Nikulab7886de2016-05-28 00:41:50 +03002840 $leading_space = undef;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002842 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002843 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 $section = $section_default;
2845 $contents = "";
2846 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002847 # look for doc_com + <text> + doc_end:
2848 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002849 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002850 ++$warnings;
2851 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852
2853 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002854 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002856# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 } elsif (/$doc_content/) {
2858 # miguel-style comment kludge, look for blank lines after
2859 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002860 if ($1 eq "") {
2861 if ($section =~ m/^@/ || $section eq $section_context) {
2862 dump_section($file, $section, xml_escape($contents));
2863 $section = $section_default;
2864 $contents = "";
2865 } else {
2866 $contents .= "\n";
2867 }
2868 $in_purpose = 0;
2869 } elsif ($in_purpose == 1) {
2870 # Continued declaration purpose
2871 chomp($declaration_purpose);
2872 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002873 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 } else {
Jani Nikulab7886de2016-05-28 00:41:50 +03002875 my $cont = $1;
2876 if ($section =~ m/^@/ || $section eq $section_context) {
2877 if (!defined $leading_space) {
2878 if ($cont =~ m/^(\s+)/) {
2879 $leading_space = $1;
2880 } else {
2881 $leading_space = "";
2882 }
2883 }
2884
2885 $cont =~ s/^$leading_space//;
2886 }
2887 $contents .= $cont . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 }
2889 } else {
2890 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002891 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 ++$warnings;
2893 }
Jani Nikula48af6062016-05-26 14:56:05 +03002894 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002895 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03002896 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002897 $section = $1;
2898 $contents = $2;
2899 if ($contents ne "") {
2900 while ((substr($contents, 0, 1) eq " ") ||
2901 substr($contents, 0, 1) eq "\t") {
2902 $contents = substr($contents, 1);
2903 }
Jani Nikulaa0b96c22016-05-26 22:04:06 +03002904 $contents .= "\n";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002905 }
Jani Nikula48af6062016-05-26 14:56:05 +03002906 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002907 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03002908 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002909 if (($contents ne "") && ($contents ne "\n")) {
2910 dump_section($file, $section, xml_escape($contents));
2911 $section = $section_default;
2912 $contents = "";
2913 }
Jani Nikula48af6062016-05-26 14:56:05 +03002914 $state = STATE_PROTO;
2915 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002916 # Regular text
2917 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03002918 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002919 $contents .= $1 . "\n";
Jani Nikula6450c892016-05-26 22:04:42 +03002920 # nuke leading blank lines
2921 if ($contents =~ /^\s*$/) {
2922 $contents = "";
2923 }
Jani Nikula48af6062016-05-26 14:56:05 +03002924 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
2925 $inline_doc_state = STATE_INLINE_ERROR;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002926 print STDERR "Warning(${file}:$.): ";
2927 print STDERR "Incorrect use of kernel-doc format: $_";
2928 ++$warnings;
2929 }
2930 }
Jani Nikula48af6062016-05-26 14:56:05 +03002931 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
2932 if (/$doc_inline_start/) {
2933 $state = STATE_INLINE;
2934 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002935 } elsif ($decl_type eq 'function') {
Randy Dunlap3c308792007-05-08 00:24:39 -07002936 process_state3_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -07002938 process_state3_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 }
Jani Nikula48af6062016-05-26 14:56:05 +03002940 } elsif ($state == STATE_DOCBLOCK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 # Documentation block
Randy Dunlap3c308792007-05-08 00:24:39 -07002942 if (/$doc_block/) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002943 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 $contents = "";
2945 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 %parameterdescs = ();
2947 %parametertypes = ();
2948 @parameterlist = ();
2949 %sections = ();
2950 @sectionlist = ();
2951 $prototype = "";
2952 if ( $1 eq "" ) {
2953 $section = $section_intro;
2954 } else {
2955 $section = $1;
2956 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002957 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 elsif (/$doc_end/)
2959 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002960 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 $contents = "";
2962 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 %parameterdescs = ();
2964 %parametertypes = ();
2965 @parameterlist = ();
2966 %sections = ();
2967 @sectionlist = ();
2968 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002969 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 }
2971 elsif (/$doc_content/)
2972 {
2973 if ( $1 eq "" )
2974 {
2975 $contents .= $blankline;
2976 }
2977 else
2978 {
2979 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002980 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002981 }
2982 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 }
2984 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002985 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002986 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08002987 print STDERR " Was looking for '$_'.\n" for keys %function_table;
2988 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 if ($output_mode eq "xml") {
2990 # The template wants at least one RefEntry here; make one.
2991 print "<refentry>\n";
2992 print " <refnamediv>\n";
2993 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01002994 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 print " </refname>\n";
2996 print " <refpurpose>\n";
2997 print " Document generation inconsistency\n";
2998 print " </refpurpose>\n";
2999 print " </refnamediv>\n";
3000 print " <refsect1>\n";
3001 print " <title>\n";
3002 print " Oops\n";
3003 print " </title>\n";
3004 print " <warning>\n";
3005 print " <para>\n";
3006 print " The template for this document tried to insert\n";
3007 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003008 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 print " but none was found.\n";
3010 print " This dummy section is inserted to allow\n";
3011 print " generation to continue.\n";
3012 print " </para>\n";
3013 print " </warning>\n";
3014 print " </refsect1>\n";
3015 print "</refentry>\n";
3016 }
3017 }
3018}
Randy Dunlap8484baa2011-01-05 16:28:43 -08003019
3020
3021$kernelversion = get_kernel_version();
3022
3023# generate a sequence of code that will splice in highlighting information
3024# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02003025for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03003026 my $pattern = $highlights[$k][0];
3027 my $result = $highlights[$k][1];
3028# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
3029 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08003030}
3031
3032# Read the file that maps relative names to absolute names for
3033# separate source and object directories and for shadow trees.
3034if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3035 my ($relname, $absname);
3036 while(<SOURCE_MAP>) {
3037 chop();
3038 ($relname, $absname) = (split())[0..1];
3039 $relname =~ s:^/+::;
3040 $source_map{$relname} = $absname;
3041 }
3042 close(SOURCE_MAP);
3043}
3044
3045foreach (@ARGV) {
3046 chomp;
3047 process_file($_);
3048}
3049if ($verbose && $errors) {
3050 print STDERR "$errors errors\n";
3051}
3052if ($verbose && $warnings) {
3053 print STDERR "$warnings warnings\n";
3054}
3055
3056exit($errors);