blob: 3ac4b57ed76a5c5b03db683a431200a694b2a173 [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 "")) {
Jani Nikula32217762016-05-29 09:40:44 +0300527 print STDERR "${file}:$.: warning: duplicate section name '$name'\n";
528 ++$warnings;
529 $sections{$name} .= $contents;
530 } else {
531 $sections{$name} = $contents;
532 push @sectionlist, $name;
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700533 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 }
535}
536
537##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700538# dump DOC: section after checking that it should go out
539#
540sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700541 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700542 my $name = shift;
543 my $contents = join "\n", @_;
544
Johannes Berg4b445952007-10-24 15:08:48 -0700545 if ($no_doc_sections) {
546 return;
547 }
548
Jani Nikulab6c3f452016-05-29 22:19:35 +0300549 if (($output_selection == OUTPUT_ALL) ||
550 ($output_selection == OUTPUT_INCLUDE &&
551 defined($function_table{$name})) ||
552 ($output_selection == OUTPUT_EXCLUDE &&
553 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700554 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700555 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700556 output_blockhead({'sectionlist' => \@sectionlist,
557 'sections' => \%sections,
558 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300559 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700560 }
561}
562
563##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564# output function
565#
566# parameterdescs, a hash.
567# function => "function name"
568# parameterlist => @list of parameters
569# parameterdescs => %parameter descriptions
570# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800571# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800572#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
574sub output_highlight {
575 my $contents = join "\n",@_;
576 my $line;
577
578# DEBUG
579# if (!defined $contents) {
580# use Carp;
581# confess "output_highlight got called with no args?\n";
582# }
583
Dan Luedtke1b40c192012-08-12 10:46:15 +0200584 if ($output_mode eq "html" || $output_mode eq "html5" ||
585 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700586 $contents = local_unescape($contents);
587 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800588 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700589 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700590# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 eval $dohighlight;
592 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700593# print STDERR "contents af:$contents\n";
594
Dan Luedtke1b40c192012-08-12 10:46:15 +0200595# strip whitespaces when generating html5
596 if ($output_mode eq "html5") {
597 $contents =~ s/^\s+//;
598 $contents =~ s/\s+$//;
599 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700601 if (! $output_preformatted) {
602 $line =~ s/^\s*//;
603 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700604 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700605 if (! $output_preformatted) {
606 print $lineprefix, local_unescape($blankline);
607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700609 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700610 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
611 print "\\&$line";
612 } else {
613 print $lineprefix, $line;
614 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 }
616 print "\n";
617 }
618}
619
Dan Luedtke1b40c192012-08-12 10:46:15 +0200620# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621sub output_section_html(%) {
622 my %args = %{$_[0]};
623 my $section;
624
625 foreach $section (@{$args{'sectionlist'}}) {
626 print "<h3>$section</h3>\n";
627 print "<blockquote>\n";
628 output_highlight($args{'sections'}{$section});
629 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800630 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631}
632
633# output enum in html
634sub output_enum_html(%) {
635 my %args = %{$_[0]};
636 my ($parameter);
637 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700638 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
Randy Dunlapb9d973282009-06-09 08:50:38 -0700640 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 $count = 0;
642 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700643 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 if ($count != $#{$args{'parameterlist'}}) {
645 $count++;
646 print ",\n";
647 }
648 print "<br>";
649 }
650 print "};<br>\n";
651
652 print "<h3>Constants</h3>\n";
653 print "<dl>\n";
654 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700655 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 print "<dd>";
657 output_highlight($args{'parameterdescs'}{$parameter});
658 }
659 print "</dl>\n";
660 output_section_html(@_);
661 print "<hr>\n";
662}
663
Randy Dunlapd28bee02006-02-01 03:06:57 -0800664# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665sub output_typedef_html(%) {
666 my %args = %{$_[0]};
667 my ($parameter);
668 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700669 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
Randy Dunlapb9d973282009-06-09 08:50:38 -0700671 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 output_section_html(@_);
673 print "<hr>\n";
674}
675
676# output struct in html
677sub output_struct_html(%) {
678 my %args = %{$_[0]};
679 my ($parameter);
680
Randy Dunlapb9d973282009-06-09 08:50:38 -0700681 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
682 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 foreach $parameter (@{$args{'parameterlist'}}) {
684 if ($parameter =~ /^#/) {
685 print "$parameter<br>\n";
686 next;
687 }
688 my $parameter_name = $parameter;
689 $parameter_name =~ s/\[.*//;
690
Randy Dunlap3c308792007-05-08 00:24:39 -0700691 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 $type = $args{'parametertypes'}{$parameter};
693 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
694 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700695 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700697 # bitfield
698 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700700 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 }
702 }
703 print "};<br>\n";
704
705 print "<h3>Members</h3>\n";
706 print "<dl>\n";
707 foreach $parameter (@{$args{'parameterlist'}}) {
708 ($parameter =~ /^#/) && next;
709
710 my $parameter_name = $parameter;
711 $parameter_name =~ s/\[.*//;
712
Randy Dunlap3c308792007-05-08 00:24:39 -0700713 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700714 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 print "<dd>";
716 output_highlight($args{'parameterdescs'}{$parameter_name});
717 }
718 print "</dl>\n";
719 output_section_html(@_);
720 print "<hr>\n";
721}
722
723# output function in html
724sub output_function_html(%) {
725 my %args = %{$_[0]};
726 my ($parameter, $section);
727 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
Randy Dunlapb9d973282009-06-09 08:50:38 -0700729 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
730 print "<i>" . $args{'functiontype'} . "</i>\n";
731 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 print "(";
733 $count = 0;
734 foreach $parameter (@{$args{'parameterlist'}}) {
735 $type = $args{'parametertypes'}{$parameter};
736 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
737 # pointer-to-function
738 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
739 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700740 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 }
742 if ($count != $#{$args{'parameterlist'}}) {
743 $count++;
744 print ",\n";
745 }
746 }
747 print ")\n";
748
749 print "<h3>Arguments</h3>\n";
750 print "<dl>\n";
751 foreach $parameter (@{$args{'parameterlist'}}) {
752 my $parameter_name = $parameter;
753 $parameter_name =~ s/\[.*//;
754
Randy Dunlap3c308792007-05-08 00:24:39 -0700755 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700756 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 print "<dd>";
758 output_highlight($args{'parameterdescs'}{$parameter_name});
759 }
760 print "</dl>\n";
761 output_section_html(@_);
762 print "<hr>\n";
763}
764
Johannes Bergb112e0f2007-10-24 15:08:48 -0700765# output DOC: block header in html
766sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 my %args = %{$_[0]};
768 my ($parameter, $section);
769 my $count;
770
771 foreach $section (@{$args{'sectionlist'}}) {
772 print "<h3>$section</h3>\n";
773 print "<ul>\n";
774 output_highlight($args{'sections'}{$section});
775 print "</ul>\n";
776 }
777 print "<hr>\n";
778}
779
Dan Luedtke1b40c192012-08-12 10:46:15 +0200780# output sections in html5
781sub output_section_html5(%) {
782 my %args = %{$_[0]};
783 my $section;
784
785 foreach $section (@{$args{'sectionlist'}}) {
786 print "<section>\n";
787 print "<h1>$section</h1>\n";
788 print "<p>\n";
789 output_highlight($args{'sections'}{$section});
790 print "</p>\n";
791 print "</section>\n";
792 }
793}
794
795# output enum in html5
796sub output_enum_html5(%) {
797 my %args = %{$_[0]};
798 my ($parameter);
799 my $count;
800 my $html5id;
801
802 $html5id = $args{'enum'};
803 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
804 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
805 print "<h1>enum " . $args{'enum'} . "</h1>\n";
806 print "<ol class=\"code\">\n";
807 print "<li>";
808 print "<span class=\"keyword\">enum</span> ";
809 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
810 print "</li>\n";
811 $count = 0;
812 foreach $parameter (@{$args{'parameterlist'}}) {
813 print "<li class=\"indent\">";
814 print "<span class=\"param\">" . $parameter . "</span>";
815 if ($count != $#{$args{'parameterlist'}}) {
816 $count++;
817 print ",";
818 }
819 print "</li>\n";
820 }
821 print "<li>};</li>\n";
822 print "</ol>\n";
823
824 print "<section>\n";
825 print "<h1>Constants</h1>\n";
826 print "<dl>\n";
827 foreach $parameter (@{$args{'parameterlist'}}) {
828 print "<dt>" . $parameter . "</dt>\n";
829 print "<dd>";
830 output_highlight($args{'parameterdescs'}{$parameter});
831 print "</dd>\n";
832 }
833 print "</dl>\n";
834 print "</section>\n";
835 output_section_html5(@_);
836 print "</article>\n";
837}
838
839# output typedef in html5
840sub output_typedef_html5(%) {
841 my %args = %{$_[0]};
842 my ($parameter);
843 my $count;
844 my $html5id;
845
846 $html5id = $args{'typedef'};
847 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
848 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
849 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
850
851 print "<ol class=\"code\">\n";
852 print "<li>";
853 print "<span class=\"keyword\">typedef</span> ";
854 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
855 print "</li>\n";
856 print "</ol>\n";
857 output_section_html5(@_);
858 print "</article>\n";
859}
860
861# output struct in html5
862sub output_struct_html5(%) {
863 my %args = %{$_[0]};
864 my ($parameter);
865 my $html5id;
866
867 $html5id = $args{'struct'};
868 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
869 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
870 print "<hgroup>\n";
871 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
872 print "<h2>". $args{'purpose'} . "</h2>\n";
873 print "</hgroup>\n";
874 print "<ol class=\"code\">\n";
875 print "<li>";
876 print "<span class=\"type\">" . $args{'type'} . "</span> ";
877 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
878 print "</li>\n";
879 foreach $parameter (@{$args{'parameterlist'}}) {
880 print "<li class=\"indent\">";
881 if ($parameter =~ /^#/) {
882 print "<span class=\"param\">" . $parameter ."</span>\n";
883 print "</li>\n";
884 next;
885 }
886 my $parameter_name = $parameter;
887 $parameter_name =~ s/\[.*//;
888
889 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
890 $type = $args{'parametertypes'}{$parameter};
891 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
892 # pointer-to-function
893 print "<span class=\"type\">$1</span> ";
894 print "<span class=\"param\">$parameter</span>";
895 print "<span class=\"type\">)</span> ";
896 print "(<span class=\"args\">$2</span>);";
897 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
898 # bitfield
899 print "<span class=\"type\">$1</span> ";
900 print "<span class=\"param\">$parameter</span>";
901 print "<span class=\"bits\">$2</span>;";
902 } else {
903 print "<span class=\"type\">$type</span> ";
904 print "<span class=\"param\">$parameter</span>;";
905 }
906 print "</li>\n";
907 }
908 print "<li>};</li>\n";
909 print "</ol>\n";
910
911 print "<section>\n";
912 print "<h1>Members</h1>\n";
913 print "<dl>\n";
914 foreach $parameter (@{$args{'parameterlist'}}) {
915 ($parameter =~ /^#/) && next;
916
917 my $parameter_name = $parameter;
918 $parameter_name =~ s/\[.*//;
919
920 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
921 print "<dt>" . $parameter . "</dt>\n";
922 print "<dd>";
923 output_highlight($args{'parameterdescs'}{$parameter_name});
924 print "</dd>\n";
925 }
926 print "</dl>\n";
927 print "</section>\n";
928 output_section_html5(@_);
929 print "</article>\n";
930}
931
932# output function in html5
933sub output_function_html5(%) {
934 my %args = %{$_[0]};
935 my ($parameter, $section);
936 my $count;
937 my $html5id;
938
939 $html5id = $args{'function'};
940 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
941 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
942 print "<hgroup>\n";
943 print "<h1>" . $args{'function'} . "</h1>";
944 print "<h2>" . $args{'purpose'} . "</h2>\n";
945 print "</hgroup>\n";
946 print "<ol class=\"code\">\n";
947 print "<li>";
948 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
949 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
950 print "</li>";
951 $count = 0;
952 foreach $parameter (@{$args{'parameterlist'}}) {
953 print "<li class=\"indent\">";
954 $type = $args{'parametertypes'}{$parameter};
955 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
956 # pointer-to-function
957 print "<span class=\"type\">$1</span> ";
958 print "<span class=\"param\">$parameter</span>";
959 print "<span class=\"type\">)</span> ";
960 print "(<span class=\"args\">$2</span>)";
961 } else {
962 print "<span class=\"type\">$type</span> ";
963 print "<span class=\"param\">$parameter</span>";
964 }
965 if ($count != $#{$args{'parameterlist'}}) {
966 $count++;
967 print ",";
968 }
969 print "</li>\n";
970 }
971 print "<li>)</li>\n";
972 print "</ol>\n";
973
974 print "<section>\n";
975 print "<h1>Arguments</h1>\n";
976 print "<p>\n";
977 print "<dl>\n";
978 foreach $parameter (@{$args{'parameterlist'}}) {
979 my $parameter_name = $parameter;
980 $parameter_name =~ s/\[.*//;
981
982 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
983 print "<dt>" . $parameter . "</dt>\n";
984 print "<dd>";
985 output_highlight($args{'parameterdescs'}{$parameter_name});
986 print "</dd>\n";
987 }
988 print "</dl>\n";
989 print "</section>\n";
990 output_section_html5(@_);
991 print "</article>\n";
992}
993
994# output DOC: block header in html5
995sub output_blockhead_html5(%) {
996 my %args = %{$_[0]};
997 my ($parameter, $section);
998 my $count;
999 my $html5id;
1000
1001 foreach $section (@{$args{'sectionlist'}}) {
1002 $html5id = $section;
1003 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1004 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1005 print "<h1>$section</h1>\n";
1006 print "<p>\n";
1007 output_highlight($args{'sections'}{$section});
1008 print "</p>\n";
1009 }
1010 print "</article>\n";
1011}
1012
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013sub output_section_xml(%) {
1014 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001015 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 # print out each section
1017 $lineprefix=" ";
1018 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001019 print "<refsect1>\n";
1020 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001022 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001023 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001024 } else {
1025 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 }
1027 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001028 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001030 print "</programlisting></informalexample>\n";
1031 } else {
1032 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001034 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 }
1036}
1037
1038# output function in XML DocBook
1039sub output_function_xml(%) {
1040 my %args = %{$_[0]};
1041 my ($parameter, $section);
1042 my $count;
1043 my $id;
1044
Randy Dunlapb9d973282009-06-09 08:50:38 -07001045 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 $id =~ s/[^A-Za-z0-9]/-/g;
1047
Pavel Pisa5449bc92007-02-10 01:45:37 -08001048 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001049 print "<refentryinfo>\n";
1050 print " <title>LINUX</title>\n";
1051 print " <productname>Kernel Hackers Manual</productname>\n";
1052 print " <date>$man_date</date>\n";
1053 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001055 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001056 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001057 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 print "</refmeta>\n";
1059 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001060 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 print " <refpurpose>\n";
1062 print " ";
1063 output_highlight ($args{'purpose'});
1064 print " </refpurpose>\n";
1065 print "</refnamediv>\n";
1066
1067 print "<refsynopsisdiv>\n";
1068 print " <title>Synopsis</title>\n";
1069 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001070 print " <funcdef>" . $args{'functiontype'} . " ";
1071 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
1073 $count = 0;
1074 if ($#{$args{'parameterlist'}} >= 0) {
1075 foreach $parameter (@{$args{'parameterlist'}}) {
1076 $type = $args{'parametertypes'}{$parameter};
1077 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1078 # pointer-to-function
1079 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1080 print " <funcparams>$2</funcparams></paramdef>\n";
1081 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001082 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 print " <parameter>$parameter</parameter></paramdef>\n";
1084 }
1085 }
1086 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001087 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 }
1089 print " </funcprototype></funcsynopsis>\n";
1090 print "</refsynopsisdiv>\n";
1091
1092 # print parameters
1093 print "<refsect1>\n <title>Arguments</title>\n";
1094 if ($#{$args{'parameterlist'}} >= 0) {
1095 print " <variablelist>\n";
1096 foreach $parameter (@{$args{'parameterlist'}}) {
1097 my $parameter_name = $parameter;
1098 $parameter_name =~ s/\[.*//;
1099
1100 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1101 print " <listitem>\n <para>\n";
1102 $lineprefix=" ";
1103 output_highlight($args{'parameterdescs'}{$parameter_name});
1104 print " </para>\n </listitem>\n </varlistentry>\n";
1105 }
1106 print " </variablelist>\n";
1107 } else {
1108 print " <para>\n None\n </para>\n";
1109 }
1110 print "</refsect1>\n";
1111
1112 output_section_xml(@_);
1113 print "</refentry>\n\n";
1114}
1115
1116# output struct in XML DocBook
1117sub output_struct_xml(%) {
1118 my %args = %{$_[0]};
1119 my ($parameter, $section);
1120 my $id;
1121
Randy Dunlapb9d973282009-06-09 08:50:38 -07001122 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 $id =~ s/[^A-Za-z0-9]/-/g;
1124
Pavel Pisa5449bc92007-02-10 01:45:37 -08001125 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001126 print "<refentryinfo>\n";
1127 print " <title>LINUX</title>\n";
1128 print " <productname>Kernel Hackers Manual</productname>\n";
1129 print " <date>$man_date</date>\n";
1130 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001132 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001133 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001134 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 print "</refmeta>\n";
1136 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001137 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 print " <refpurpose>\n";
1139 print " ";
1140 output_highlight ($args{'purpose'});
1141 print " </refpurpose>\n";
1142 print "</refnamediv>\n";
1143
1144 print "<refsynopsisdiv>\n";
1145 print " <title>Synopsis</title>\n";
1146 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001147 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 foreach $parameter (@{$args{'parameterlist'}}) {
1149 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001150 my $prm = $parameter;
1151 # convert data read & converted thru xml_escape() into &xyz; format:
1152 # This allows us to have #define macros interspersed in a struct.
1153 $prm =~ s/\\\\\\/\&/g;
1154 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 next;
1156 }
1157
1158 my $parameter_name = $parameter;
1159 $parameter_name =~ s/\[.*//;
1160
1161 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001162 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 $type = $args{'parametertypes'}{$parameter};
1164 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1165 # pointer-to-function
1166 print " $1 $parameter) ($2);\n";
1167 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001168 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 print " $1 $parameter$2;\n";
1170 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001171 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 }
1173 }
1174 print "};";
1175 print " </programlisting>\n";
1176 print "</refsynopsisdiv>\n";
1177
1178 print " <refsect1>\n";
1179 print " <title>Members</title>\n";
1180
Randy Dunlap39f00c02008-09-22 13:57:44 -07001181 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 print " <variablelist>\n";
1183 foreach $parameter (@{$args{'parameterlist'}}) {
1184 ($parameter =~ /^#/) && next;
1185
1186 my $parameter_name = $parameter;
1187 $parameter_name =~ s/\[.*//;
1188
1189 defined($args{'parameterdescs'}{$parameter_name}) || next;
1190 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1191 print " <varlistentry>";
1192 print " <term>$parameter</term>\n";
1193 print " <listitem><para>\n";
1194 output_highlight($args{'parameterdescs'}{$parameter_name});
1195 print " </para></listitem>\n";
1196 print " </varlistentry>\n";
1197 }
1198 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001199 } else {
1200 print " <para>\n None\n </para>\n";
1201 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 print " </refsect1>\n";
1203
1204 output_section_xml(@_);
1205
1206 print "</refentry>\n\n";
1207}
1208
1209# output enum in XML DocBook
1210sub output_enum_xml(%) {
1211 my %args = %{$_[0]};
1212 my ($parameter, $section);
1213 my $count;
1214 my $id;
1215
Randy Dunlapb9d973282009-06-09 08:50:38 -07001216 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 $id =~ s/[^A-Za-z0-9]/-/g;
1218
Pavel Pisa5449bc92007-02-10 01:45:37 -08001219 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001220 print "<refentryinfo>\n";
1221 print " <title>LINUX</title>\n";
1222 print " <productname>Kernel Hackers Manual</productname>\n";
1223 print " <date>$man_date</date>\n";
1224 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001226 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001227 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001228 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 print "</refmeta>\n";
1230 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001231 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 print " <refpurpose>\n";
1233 print " ";
1234 output_highlight ($args{'purpose'});
1235 print " </refpurpose>\n";
1236 print "</refnamediv>\n";
1237
1238 print "<refsynopsisdiv>\n";
1239 print " <title>Synopsis</title>\n";
1240 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001241 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 $count = 0;
1243 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001244 print " $parameter";
1245 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 $count++;
1247 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001248 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 print "\n";
1250 }
1251 print "};";
1252 print " </programlisting>\n";
1253 print "</refsynopsisdiv>\n";
1254
1255 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001256 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 print " <variablelist>\n";
1258 foreach $parameter (@{$args{'parameterlist'}}) {
1259 my $parameter_name = $parameter;
1260 $parameter_name =~ s/\[.*//;
1261
1262 print " <varlistentry>";
1263 print " <term>$parameter</term>\n";
1264 print " <listitem><para>\n";
1265 output_highlight($args{'parameterdescs'}{$parameter_name});
1266 print " </para></listitem>\n";
1267 print " </varlistentry>\n";
1268 }
1269 print " </variablelist>\n";
1270 print "</refsect1>\n";
1271
1272 output_section_xml(@_);
1273
1274 print "</refentry>\n\n";
1275}
1276
1277# output typedef in XML DocBook
1278sub output_typedef_xml(%) {
1279 my %args = %{$_[0]};
1280 my ($parameter, $section);
1281 my $id;
1282
Randy Dunlapb9d973282009-06-09 08:50:38 -07001283 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 $id =~ s/[^A-Za-z0-9]/-/g;
1285
Pavel Pisa5449bc92007-02-10 01:45:37 -08001286 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001287 print "<refentryinfo>\n";
1288 print " <title>LINUX</title>\n";
1289 print " <productname>Kernel Hackers Manual</productname>\n";
1290 print " <date>$man_date</date>\n";
1291 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001293 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001294 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 print "</refmeta>\n";
1296 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001297 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 print " <refpurpose>\n";
1299 print " ";
1300 output_highlight ($args{'purpose'});
1301 print " </refpurpose>\n";
1302 print "</refnamediv>\n";
1303
1304 print "<refsynopsisdiv>\n";
1305 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001306 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 print "</refsynopsisdiv>\n";
1308
1309 output_section_xml(@_);
1310
1311 print "</refentry>\n\n";
1312}
1313
1314# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001315sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 my %args = %{$_[0]};
1317 my ($parameter, $section);
1318 my $count;
1319
1320 my $id = $args{'module'};
1321 $id =~ s/[^A-Za-z0-9]/-/g;
1322
1323 # print out each section
1324 $lineprefix=" ";
1325 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001326 if (!$args{'content-only'}) {
1327 print "<refsect1>\n <title>$section</title>\n";
1328 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 if ($section =~ m/EXAMPLE/i) {
1330 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001331 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001332 } else {
1333 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 }
1335 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001336 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 if ($section =~ m/EXAMPLE/i) {
1338 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001339 } else {
1340 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001342 if (!$args{'content-only'}) {
1343 print "\n</refsect1>\n";
1344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 }
1346
1347 print "\n\n";
1348}
1349
1350# output in XML DocBook
1351sub output_function_gnome {
1352 my %args = %{$_[0]};
1353 my ($parameter, $section);
1354 my $count;
1355 my $id;
1356
Randy Dunlapb9d973282009-06-09 08:50:38 -07001357 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 $id =~ s/[^A-Za-z0-9]/-/g;
1359
1360 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001361 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362
1363 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001364 print " <funcdef>" . $args{'functiontype'} . " ";
1365 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 print "</function></funcdef>\n";
1367
1368 $count = 0;
1369 if ($#{$args{'parameterlist'}} >= 0) {
1370 foreach $parameter (@{$args{'parameterlist'}}) {
1371 $type = $args{'parametertypes'}{$parameter};
1372 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1373 # pointer-to-function
1374 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1375 print " <funcparams>$2</funcparams></paramdef>\n";
1376 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001377 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 print " <parameter>$parameter</parameter></paramdef>\n";
1379 }
1380 }
1381 } else {
1382 print " <void>\n";
1383 }
1384 print " </funcsynopsis>\n";
1385 if ($#{$args{'parameterlist'}} >= 0) {
1386 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1387 print "<tgroup cols=\"2\">\n";
1388 print "<colspec colwidth=\"2*\">\n";
1389 print "<colspec colwidth=\"8*\">\n";
1390 print "<tbody>\n";
1391 foreach $parameter (@{$args{'parameterlist'}}) {
1392 my $parameter_name = $parameter;
1393 $parameter_name =~ s/\[.*//;
1394
1395 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1396 print " <entry>\n";
1397 $lineprefix=" ";
1398 output_highlight($args{'parameterdescs'}{$parameter_name});
1399 print " </entry></row>\n";
1400 }
1401 print " </tbody></tgroup></informaltable>\n";
1402 } else {
1403 print " <para>\n None\n </para>\n";
1404 }
1405
1406 # print out each section
1407 $lineprefix=" ";
1408 foreach $section (@{$args{'sectionlist'}}) {
1409 print "<simplesect>\n <title>$section</title>\n";
1410 if ($section =~ m/EXAMPLE/i) {
1411 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001412 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 } else {
1414 }
1415 print "<para>\n";
1416 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001417 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 print "</para>\n";
1419 if ($section =~ m/EXAMPLE/i) {
1420 print "</programlisting></example>\n";
1421 } else {
1422 }
1423 print " </simplesect>\n";
1424 }
1425
1426 print "</sect2>\n\n";
1427}
1428
1429##
1430# output function in man
1431sub output_function_man(%) {
1432 my %args = %{$_[0]};
1433 my ($parameter, $section);
1434 my $count;
1435
1436 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1437
1438 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001439 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
1441 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001442 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001443 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001444 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001445 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001446 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 $count = 0;
1448 my $parenth = "(";
1449 my $post = ",";
1450 foreach my $parameter (@{$args{'parameterlist'}}) {
1451 if ($count == $#{$args{'parameterlist'}}) {
1452 $post = ");";
1453 }
1454 $type = $args{'parametertypes'}{$parameter};
1455 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1456 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001457 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 } else {
1459 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001460 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 }
1462 $count++;
1463 $parenth = "";
1464 }
1465
1466 print ".SH ARGUMENTS\n";
1467 foreach $parameter (@{$args{'parameterlist'}}) {
1468 my $parameter_name = $parameter;
1469 $parameter_name =~ s/\[.*//;
1470
Randy Dunlapb9d973282009-06-09 08:50:38 -07001471 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 output_highlight($args{'parameterdescs'}{$parameter_name});
1473 }
1474 foreach $section (@{$args{'sectionlist'}}) {
1475 print ".SH \"", uc $section, "\"\n";
1476 output_highlight($args{'sections'}{$section});
1477 }
1478}
1479
1480##
1481# output enum in man
1482sub output_enum_man(%) {
1483 my %args = %{$_[0]};
1484 my ($parameter, $section);
1485 my $count;
1486
1487 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1488
1489 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001490 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
1492 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001493 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 $count = 0;
1495 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001496 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 if ($count == $#{$args{'parameterlist'}}) {
1498 print "\n};\n";
1499 last;
1500 }
1501 else {
1502 print ", \n.br\n";
1503 }
1504 $count++;
1505 }
1506
1507 print ".SH Constants\n";
1508 foreach $parameter (@{$args{'parameterlist'}}) {
1509 my $parameter_name = $parameter;
1510 $parameter_name =~ s/\[.*//;
1511
Randy Dunlapb9d973282009-06-09 08:50:38 -07001512 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 output_highlight($args{'parameterdescs'}{$parameter_name});
1514 }
1515 foreach $section (@{$args{'sectionlist'}}) {
1516 print ".SH \"$section\"\n";
1517 output_highlight($args{'sections'}{$section});
1518 }
1519}
1520
1521##
1522# output struct in man
1523sub output_struct_man(%) {
1524 my %args = %{$_[0]};
1525 my ($parameter, $section);
1526
Randy Dunlapb9d973282009-06-09 08:50:38 -07001527 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
1529 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001530 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531
1532 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001533 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
1535 foreach my $parameter (@{$args{'parameterlist'}}) {
1536 if ($parameter =~ /^#/) {
1537 print ".BI \"$parameter\"\n.br\n";
1538 next;
1539 }
1540 my $parameter_name = $parameter;
1541 $parameter_name =~ s/\[.*//;
1542
Randy Dunlap3c308792007-05-08 00:24:39 -07001543 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 $type = $args{'parametertypes'}{$parameter};
1545 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1546 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001547 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001549 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001550 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 } else {
1552 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001553 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 }
1555 print "\n.br\n";
1556 }
1557 print "};\n.br\n";
1558
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001559 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 foreach $parameter (@{$args{'parameterlist'}}) {
1561 ($parameter =~ /^#/) && next;
1562
1563 my $parameter_name = $parameter;
1564 $parameter_name =~ s/\[.*//;
1565
Randy Dunlap3c308792007-05-08 00:24:39 -07001566 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001567 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 output_highlight($args{'parameterdescs'}{$parameter_name});
1569 }
1570 foreach $section (@{$args{'sectionlist'}}) {
1571 print ".SH \"$section\"\n";
1572 output_highlight($args{'sections'}{$section});
1573 }
1574}
1575
1576##
1577# output typedef in man
1578sub output_typedef_man(%) {
1579 my %args = %{$_[0]};
1580 my ($parameter, $section);
1581
1582 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1583
1584 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001585 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586
1587 foreach $section (@{$args{'sectionlist'}}) {
1588 print ".SH \"$section\"\n";
1589 output_highlight($args{'sections'}{$section});
1590 }
1591}
1592
Johannes Bergb112e0f2007-10-24 15:08:48 -07001593sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 my %args = %{$_[0]};
1595 my ($parameter, $section);
1596 my $count;
1597
1598 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1599
1600 foreach $section (@{$args{'sectionlist'}}) {
1601 print ".SH \"$section\"\n";
1602 output_highlight($args{'sections'}{$section});
1603 }
1604}
1605
1606##
1607# output in text
1608sub output_function_text(%) {
1609 my %args = %{$_[0]};
1610 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001611 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612
Randy Dunlapf47634b2006-07-01 04:36:36 -07001613 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001614 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001615
1616 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001617 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001618 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001619 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001620 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001621 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001623
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 my $count = 0;
1625 foreach my $parameter (@{$args{'parameterlist'}}) {
1626 $type = $args{'parametertypes'}{$parameter};
1627 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1628 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001629 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001631 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 }
1633 if ($count != $#{$args{'parameterlist'}}) {
1634 $count++;
1635 print ",\n";
1636 print " " x length($start);
1637 } else {
1638 print ");\n\n";
1639 }
1640 }
1641
1642 print "Arguments:\n\n";
1643 foreach $parameter (@{$args{'parameterlist'}}) {
1644 my $parameter_name = $parameter;
1645 $parameter_name =~ s/\[.*//;
1646
Randy Dunlapb9d973282009-06-09 08:50:38 -07001647 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 }
1649 output_section_text(@_);
1650}
1651
1652#output sections in text
1653sub output_section_text(%) {
1654 my %args = %{$_[0]};
1655 my $section;
1656
1657 print "\n";
1658 foreach $section (@{$args{'sectionlist'}}) {
1659 print "$section:\n\n";
1660 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 print "\n\n";
1663}
1664
1665# output enum in text
1666sub output_enum_text(%) {
1667 my %args = %{$_[0]};
1668 my ($parameter);
1669 my $count;
1670 print "Enum:\n\n";
1671
Randy Dunlapb9d973282009-06-09 08:50:38 -07001672 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1673 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 $count = 0;
1675 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001676 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 if ($count != $#{$args{'parameterlist'}}) {
1678 $count++;
1679 print ",";
1680 }
1681 print "\n";
1682 }
1683 print "};\n\n";
1684
1685 print "Constants:\n\n";
1686 foreach $parameter (@{$args{'parameterlist'}}) {
1687 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001688 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 }
1690
1691 output_section_text(@_);
1692}
1693
1694# output typedef in text
1695sub output_typedef_text(%) {
1696 my %args = %{$_[0]};
1697 my ($parameter);
1698 my $count;
1699 print "Typedef:\n\n";
1700
Randy Dunlapb9d973282009-06-09 08:50:38 -07001701 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 output_section_text(@_);
1703}
1704
1705# output struct as text
1706sub output_struct_text(%) {
1707 my %args = %{$_[0]};
1708 my ($parameter);
1709
Randy Dunlapb9d973282009-06-09 08:50:38 -07001710 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1711 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 foreach $parameter (@{$args{'parameterlist'}}) {
1713 if ($parameter =~ /^#/) {
1714 print "$parameter\n";
1715 next;
1716 }
1717
1718 my $parameter_name = $parameter;
1719 $parameter_name =~ s/\[.*//;
1720
Randy Dunlap3c308792007-05-08 00:24:39 -07001721 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 $type = $args{'parametertypes'}{$parameter};
1723 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1724 # pointer-to-function
1725 print "\t$1 $parameter) ($2);\n";
1726 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001727 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 print "\t$1 $parameter$2;\n";
1729 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001730 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 }
1732 }
1733 print "};\n\n";
1734
1735 print "Members:\n\n";
1736 foreach $parameter (@{$args{'parameterlist'}}) {
1737 ($parameter =~ /^#/) && next;
1738
1739 my $parameter_name = $parameter;
1740 $parameter_name =~ s/\[.*//;
1741
Randy Dunlap3c308792007-05-08 00:24:39 -07001742 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001744 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 }
1746 print "\n";
1747 output_section_text(@_);
1748}
1749
Johannes Bergb112e0f2007-10-24 15:08:48 -07001750sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 my %args = %{$_[0]};
1752 my ($parameter, $section);
1753
1754 foreach $section (@{$args{'sectionlist'}}) {
1755 print " $section:\n";
1756 print " -> ";
1757 output_highlight($args{'sections'}{$section});
1758 }
1759}
1760
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001761##
1762# output in restructured text
1763#
1764
1765#
1766# This could use some work; it's used to output the DOC: sections, and
1767# starts by putting out the name of the doc section itself, but that tends
1768# to duplicate a header already in the template file.
1769#
1770sub output_blockhead_rst(%) {
1771 my %args = %{$_[0]};
1772 my ($parameter, $section);
1773
1774 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001775 if ($output_selection != OUTPUT_INCLUDE) {
1776 print "**$section**\n\n";
1777 }
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001778 output_highlight_rst($args{'sections'}{$section});
1779 print "\n";
1780 }
1781}
1782
1783sub output_highlight_rst {
1784 my $contents = join "\n",@_;
1785 my $line;
1786
1787 # undo the evil effects of xml_escape() earlier
1788 $contents = xml_unescape($contents);
1789
1790 eval $dohighlight;
1791 die $@ if $@;
1792
1793 foreach $line (split "\n", $contents) {
Jani Nikula830066a2016-05-26 22:04:33 +03001794 print $lineprefix . $line . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001795 }
1796}
1797
1798sub output_function_rst(%) {
1799 my %args = %{$_[0]};
1800 my ($parameter, $section);
Jani Nikulac099ff62016-05-26 17:18:17 +03001801 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001802 my $start;
1803
1804 print ".. c:function:: ";
1805 if ($args{'functiontype'} ne "") {
1806 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1807 } else {
1808 $start = $args{'function'} . " (";
1809 }
1810 print $start;
1811
1812 my $count = 0;
1813 foreach my $parameter (@{$args{'parameterlist'}}) {
1814 if ($count ne 0) {
1815 print ", ";
1816 }
1817 $count++;
1818 $type = $args{'parametertypes'}{$parameter};
1819 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1820 # pointer-to-function
1821 print $1 . $parameter . ") (" . $2;
1822 } else {
1823 print $type . " " . $parameter;
1824 }
1825 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001826 print ")\n\n";
1827 $lineprefix = " ";
1828 output_highlight_rst($args{'purpose'});
1829 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001830
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001831 print "**Parameters**\n\n";
1832 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001833 foreach $parameter (@{$args{'parameterlist'}}) {
1834 my $parameter_name = $parameter;
1835 #$parameter_name =~ s/\[.*//;
1836 $type = $args{'parametertypes'}{$parameter};
1837
1838 if ($type ne "") {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001839 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001840 } else {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001841 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001842 }
Jani Nikula5e64fa92016-05-19 20:32:48 +03001843 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1844 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001845 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001846 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001847 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001848 }
1849 print "\n";
1850 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001851
1852 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001853 output_section_rst(@_);
1854}
1855
1856sub output_section_rst(%) {
1857 my %args = %{$_[0]};
1858 my $section;
1859 my $oldprefix = $lineprefix;
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001860 $lineprefix = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001861
1862 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001863 print "**$section**\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001864 output_highlight_rst($args{'sections'}{$section});
1865 print "\n";
1866 }
1867 print "\n";
1868 $lineprefix = $oldprefix;
1869}
1870
1871sub output_enum_rst(%) {
1872 my %args = %{$_[0]};
1873 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001874 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001875 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001876 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001877
1878 print "\n\n.. c:type:: " . $name . "\n\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001879 $lineprefix = " ";
1880 output_highlight_rst($args{'purpose'});
1881 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001882
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001883 print "**Constants**\n\n";
1884 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001885 foreach $parameter (@{$args{'parameterlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001886 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001887 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1888 output_highlight_rst($args{'parameterdescs'}{$parameter});
1889 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001890 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001891 }
1892 print "\n";
1893 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001894
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001895 $lineprefix = $oldprefix;
1896 output_section_rst(@_);
1897}
1898
1899sub output_typedef_rst(%) {
1900 my %args = %{$_[0]};
1901 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001902 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001903 my $name = "typedef " . $args{'typedef'};
1904
Jani Nikula62850972016-05-12 16:15:38 +03001905 print "\n\n.. c:type:: " . $name . "\n\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001906 $lineprefix = " ";
1907 output_highlight_rst($args{'purpose'});
1908 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001909
Jani Nikulac099ff62016-05-26 17:18:17 +03001910 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001911 output_section_rst(@_);
1912}
1913
1914sub output_struct_rst(%) {
1915 my %args = %{$_[0]};
1916 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001917 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001918 my $name = $args{'type'} . " " . $args{'struct'};
1919
Jani Nikula62850972016-05-12 16:15:38 +03001920 print "\n\n.. c:type:: " . $name . "\n\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001921 $lineprefix = " ";
1922 output_highlight_rst($args{'purpose'});
1923 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001924
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001925 print "**Definition**\n\n";
1926 print "::\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001927 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1928 foreach $parameter (@{$args{'parameterlist'}}) {
1929 if ($parameter =~ /^#/) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001930 print " " . "$parameter\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001931 next;
1932 }
1933
1934 my $parameter_name = $parameter;
1935 $parameter_name =~ s/\[.*//;
1936
1937 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1938 $type = $args{'parametertypes'}{$parameter};
1939 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1940 # pointer-to-function
1941 print " $1 $parameter) ($2);\n";
1942 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1943 # bitfield
1944 print " $1 $parameter$2;\n";
1945 } else {
1946 print " " . $type . " " . $parameter . ";\n";
1947 }
1948 }
1949 print " };\n\n";
1950
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001951 print "**Members**\n\n";
1952 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001953 foreach $parameter (@{$args{'parameterlist'}}) {
1954 ($parameter =~ /^#/) && next;
1955
1956 my $parameter_name = $parameter;
1957 $parameter_name =~ s/\[.*//;
1958
1959 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1960 $type = $args{'parametertypes'}{$parameter};
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001961 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001962 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001963 print "\n";
1964 }
1965 print "\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001966
1967 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001968 output_section_rst(@_);
1969}
1970
1971
Johannes Bergeda603f2010-09-11 15:55:22 -07001972## list mode output functions
1973
1974sub output_function_list(%) {
1975 my %args = %{$_[0]};
1976
1977 print $args{'function'} . "\n";
1978}
1979
1980# output enum in list
1981sub output_enum_list(%) {
1982 my %args = %{$_[0]};
1983 print $args{'enum'} . "\n";
1984}
1985
1986# output typedef in list
1987sub output_typedef_list(%) {
1988 my %args = %{$_[0]};
1989 print $args{'typedef'} . "\n";
1990}
1991
1992# output struct as list
1993sub output_struct_list(%) {
1994 my %args = %{$_[0]};
1995
1996 print $args{'struct'} . "\n";
1997}
1998
1999sub output_blockhead_list(%) {
2000 my %args = %{$_[0]};
2001 my ($parameter, $section);
2002
2003 foreach $section (@{$args{'sectionlist'}}) {
2004 print "DOC: $section\n";
2005 }
2006}
2007
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008##
Randy Dunlap27205742006-10-11 01:22:12 -07002009# generic output function for all types (function, struct/union, typedef, enum);
2010# calls the generated, variable output_ function name based on
2011# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012sub output_declaration {
2013 no strict 'refs';
2014 my $name = shift;
2015 my $functype = shift;
2016 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002017 if (($output_selection == OUTPUT_ALL) ||
2018 (($output_selection == OUTPUT_INCLUDE ||
2019 $output_selection == OUTPUT_EXPORTED) &&
2020 defined($function_table{$name})) ||
2021 (($output_selection == OUTPUT_EXCLUDE ||
2022 $output_selection == OUTPUT_INTERNAL) &&
2023 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002025 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 $section_counter++;
2027 }
2028}
2029
2030##
Randy Dunlap27205742006-10-11 01:22:12 -07002031# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002032sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002034 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 &$func(@_);
2036 $section_counter++;
2037}
2038
2039##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002040# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041# invokes the right handler. NOT called for functions.
2042sub dump_declaration($$) {
2043 no strict 'refs';
2044 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002045 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 &$func(@_);
2047}
2048
2049sub dump_union($$) {
2050 dump_struct(@_);
2051}
2052
2053sub dump_struct($$) {
2054 my $x = shift;
2055 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002056 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002058 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2059 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002060 $declaration_name = $2;
2061 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
2063 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002064 $members =~ s/({.*})//g;
2065 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066
Martin Waitzaeec46b2005-11-13 16:08:13 -08002067 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002068 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2069 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002070 # strip comments:
2071 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002072 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002073 # strip kmemcheck_bitfield_{begin,end}.*;
2074 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002075 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002076 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002077 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002078 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002079 # replace DECLARE_BITMAP
2080 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002081
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002083 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
2085 output_declaration($declaration_name,
2086 'struct',
2087 {'struct' => $declaration_name,
2088 'module' => $modulename,
2089 'parameterlist' => \@parameterlist,
2090 'parameterdescs' => \%parameterdescs,
2091 'parametertypes' => \%parametertypes,
2092 'sectionlist' => \@sectionlist,
2093 'sections' => \%sections,
2094 'purpose' => $declaration_purpose,
2095 'type' => $decl_type
2096 });
2097 }
2098 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002099 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 ++$errors;
2101 }
2102}
2103
2104sub dump_enum($$) {
2105 my $x = shift;
2106 my $file = shift;
2107
Martin Waitzaeec46b2005-11-13 16:08:13 -08002108 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002109 # strip #define macros inside enums
2110 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002111
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002113 $declaration_name = $1;
2114 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
2116 foreach my $arg (split ',', $members) {
2117 $arg =~ s/^\s*(\w+).*/$1/;
2118 push @parameterlist, $arg;
2119 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002120 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002121 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 "not described in enum '$declaration_name'\n";
2123 }
2124
2125 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002126
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 output_declaration($declaration_name,
2128 'enum',
2129 {'enum' => $declaration_name,
2130 'module' => $modulename,
2131 'parameterlist' => \@parameterlist,
2132 'parameterdescs' => \%parameterdescs,
2133 'sectionlist' => \@sectionlist,
2134 'sections' => \%sections,
2135 'purpose' => $declaration_purpose
2136 });
2137 }
2138 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002139 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 ++$errors;
2141 }
2142}
2143
2144sub dump_typedef($$) {
2145 my $x = shift;
2146 my $file = shift;
2147
Martin Waitzaeec46b2005-11-13 16:08:13 -08002148 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002149
2150 # Parse function prototypes
2151 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
2152 # Function typedefs
2153 $return_type = $1;
2154 $declaration_name = $2;
2155 my $args = $3;
2156
2157 create_parameterlist($args, ',', $file);
2158
2159 output_declaration($declaration_name,
2160 'function',
2161 {'function' => $declaration_name,
2162 'module' => $modulename,
2163 'functiontype' => $return_type,
2164 'parameterlist' => \@parameterlist,
2165 'parameterdescs' => \%parameterdescs,
2166 'parametertypes' => \%parametertypes,
2167 'sectionlist' => \@sectionlist,
2168 'sections' => \%sections,
2169 'purpose' => $declaration_purpose
2170 });
2171 return;
2172 }
2173
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002175 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 $x =~ s/\[*.\]\s*;$/;/;
2177 }
2178
2179 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002180 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
2182 output_declaration($declaration_name,
2183 'typedef',
2184 {'typedef' => $declaration_name,
2185 'module' => $modulename,
2186 'sectionlist' => \@sectionlist,
2187 'sections' => \%sections,
2188 'purpose' => $declaration_purpose
2189 });
2190 }
2191 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002192 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 ++$errors;
2194 }
2195}
2196
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002197sub save_struct_actual($) {
2198 my $actual = shift;
2199
2200 # strip all spaces from the actual param so that it looks like one string item
2201 $actual =~ s/\s*//g;
2202 $struct_actual = $struct_actual . $actual . " ";
2203}
2204
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205sub create_parameterlist($$$) {
2206 my $args = shift;
2207 my $splitter = shift;
2208 my $file = shift;
2209 my $type;
2210 my $param;
2211
Martin Waitza6d3fe72006-01-09 20:53:55 -08002212 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002214 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002216
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 foreach my $arg (split($splitter, $args)) {
2218 # strip comments
2219 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002220 # strip leading/trailing spaces
2221 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 $arg =~ s/\s*$//;
2223 $arg =~ s/\s+/ /;
2224
2225 if ($arg =~ /^#/) {
2226 # Treat preprocessor directive as a typeless variable just to fill
2227 # corresponding data structures "correctly". Catch it later in
2228 # output_* subs.
2229 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002230 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 # pointer-to-function
2232 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002233 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 $param = $1;
2235 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002236 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002237 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002239 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 $arg =~ s/\s*:\s*/:/g;
2241 $arg =~ s/\s*\[/\[/g;
2242
2243 my @args = split('\s*,\s*', $arg);
2244 if ($args[0] =~ m/\*/) {
2245 $args[0] =~ s/(\*+)\s*/ $1/;
2246 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002247
2248 my @first_arg;
2249 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2250 shift @args;
2251 push(@first_arg, split('\s+', $1));
2252 push(@first_arg, $2);
2253 } else {
2254 @first_arg = split('\s+', shift @args);
2255 }
2256
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 unshift(@args, pop @first_arg);
2258 $type = join " ", @first_arg;
2259
2260 foreach $param (@args) {
2261 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002262 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 push_parameter($2, "$type $1", $file);
2264 }
2265 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002266 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002267 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002268 push_parameter($1, "$type:$2", $file)
2269 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 }
2271 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002272 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 push_parameter($param, $type, $file);
2274 }
2275 }
2276 }
2277 }
2278}
2279
2280sub push_parameter($$$) {
2281 my $param = shift;
2282 my $type = shift;
2283 my $file = shift;
2284
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002285 if (($anon_struct_union == 1) && ($type eq "") &&
2286 ($param eq "}")) {
2287 return; # ignore the ending }; from anon. struct/union
2288 }
2289
2290 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 my $param_name = $param;
2292 $param_name =~ s/\[.*//;
2293
Martin Waitza6d3fe72006-01-09 20:53:55 -08002294 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 {
Randy Dunlapced69092008-12-01 13:14:03 -08002296 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2297 $parameterdescs{$param} = "variable arguments";
2298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 }
2300 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2301 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 $param="void";
2303 $parameterdescs{void} = "no arguments";
2304 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002305 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2306 # handle unnamed (anonymous) union or struct:
2307 {
2308 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002309 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002310 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002311 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002312 }
2313
Martin Waitza6d3fe72006-01-09 20:53:55 -08002314 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002315 # (but ignore ones starting with # as these are not parameters
2316 # but inline preprocessor statements);
2317 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002318 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002319 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2320
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 $parameterdescs{$param_name} = $undescribed;
2322
2323 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002324 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 "or member '$param' not " .
2326 "described in '$declaration_name'\n";
2327 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002328 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002329 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002331 }
2332 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002334 $param = xml_escape($param);
2335
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002336 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002337 # on @parameterlist;
2338 # this fixes a problem where check_sections() cannot find
2339 # a parameter like "addr[6 + 2]" because it actually appears
2340 # as "addr[6", "+", "2]" on the parameter list;
2341 # but it's better to maintain the param string unchanged for output,
2342 # so just weaken the string compare in check_sections() to ignore
2343 # "[blah" in a parameter string;
2344 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 push @parameterlist, $param;
2346 $parametertypes{$param} = $type;
2347}
2348
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002349sub check_sections($$$$$$) {
2350 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2351 my @sects = split ' ', $sectcheck;
2352 my @prms = split ' ', $prmscheck;
2353 my $err;
2354 my ($px, $sx);
2355 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2356
2357 foreach $sx (0 .. $#sects) {
2358 $err = 1;
2359 foreach $px (0 .. $#prms) {
2360 $prm_clean = $prms[$px];
2361 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002362 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002363 # ignore array size in a parameter string;
2364 # however, the original param string may contain
2365 # spaces, e.g.: addr[6 + 2]
2366 # and this appears in @prms as "addr[6" since the
2367 # parameter list is split at spaces;
2368 # hence just ignore "[..." for the sections check;
2369 $prm_clean =~ s/\[.*//;
2370
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002371 ##$prm_clean =~ s/^\**//;
2372 if ($prm_clean eq $sects[$sx]) {
2373 $err = 0;
2374 last;
2375 }
2376 }
2377 if ($err) {
2378 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002379 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002380 "Excess function parameter " .
2381 "'$sects[$sx]' " .
2382 "description in '$decl_name'\n";
2383 ++$warnings;
2384 } else {
2385 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002386 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002387 "Excess struct/union/enum/typedef member " .
2388 "'$sects[$sx]' " .
2389 "description in '$decl_name'\n";
2390 ++$warnings;
2391 }
2392 }
2393 }
2394 }
2395}
2396
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002398# Checks the section describing the return value of a function.
2399sub check_return_section {
2400 my $file = shift;
2401 my $declaration_name = shift;
2402 my $return_type = shift;
2403
2404 # Ignore an empty return type (It's a macro)
2405 # Ignore functions with a "void" return type. (But don't ignore "void *")
2406 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2407 return;
2408 }
2409
2410 if (!defined($sections{$section_return}) ||
2411 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002412 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002413 "No description found for return value of " .
2414 "'$declaration_name'\n";
2415 ++$warnings;
2416 }
2417}
2418
2419##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420# takes a function prototype and the name of the current file being
2421# processed and spits out all the details stored in the global
2422# arrays/hashes.
2423sub dump_function($$) {
2424 my $prototype = shift;
2425 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002426 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
2428 $prototype =~ s/^static +//;
2429 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002430 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 $prototype =~ s/^inline +//;
2432 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002433 $prototype =~ s/^__inline +//;
2434 $prototype =~ s/^__always_inline +//;
2435 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002436 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002437 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002438 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002439 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002440 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002441 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002442 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443
2444 # Yes, this truly is vile. We are looking for:
2445 # 1. Return type (may be nothing if we're looking at a macro)
2446 # 2. Function name
2447 # 3. Function parameters.
2448 #
2449 # All the while we have to watch out for function pointer parameters
2450 # (which IIRC is what the two sections are for), C types (these
2451 # regexps don't even start to express all the possibilities), and
2452 # so on.
2453 #
2454 # If you mess with these regexps, it's a good idea to check that
2455 # the following functions' documentation still comes out right:
2456 # - parport_register_device (function pointer parameters)
2457 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002458 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002460 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2461 # This is an object-like macro, it has no return type and no parameter
2462 # list.
2463 # Function-like macros are not allowed to have spaces between
2464 # declaration_name and opening parenthesis (notice the \s+).
2465 $return_type = $1;
2466 $declaration_name = $2;
2467 $noret = 1;
2468 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2470 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2471 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002472 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2474 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2475 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2476 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2477 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2478 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2479 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2480 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002481 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2482 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002483 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2484 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 $return_type = $1;
2486 $declaration_name = $2;
2487 my $args = $3;
2488
2489 create_parameterlist($args, ',', $file);
2490 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002491 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 return;
2493 }
2494
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002495 my $prms = join " ", @parameterlist;
2496 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2497
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002498 # This check emits a lot of warnings at the moment, because many
2499 # functions don't have a 'Return' doc section. So until the number
2500 # of warnings goes sufficiently down, the check is only performed in
2501 # verbose mode.
2502 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002503 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002504 check_return_section($file, $declaration_name, $return_type);
2505 }
2506
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002507 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 'function',
2509 {'function' => $declaration_name,
2510 'module' => $modulename,
2511 'functiontype' => $return_type,
2512 'parameterlist' => \@parameterlist,
2513 'parameterdescs' => \%parameterdescs,
2514 'parametertypes' => \%parametertypes,
2515 'sectionlist' => \@sectionlist,
2516 'sections' => \%sections,
2517 'purpose' => $declaration_purpose
2518 });
2519}
2520
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521sub reset_state {
2522 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 %parameterdescs = ();
2524 %parametertypes = ();
2525 @parameterlist = ();
2526 %sections = ();
2527 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002528 $sectcheck = "";
2529 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002531
Jani Nikula48af6062016-05-26 14:56:05 +03002532 $state = STATE_NORMAL;
2533 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534}
2535
Jason Baron56afb0f2009-04-30 13:29:36 -04002536sub tracepoint_munge($) {
2537 my $file = shift;
2538 my $tracepointname = 0;
2539 my $tracepointargs = 0;
2540
Jason Baron3a9089f2009-12-01 12:18:49 -05002541 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002542 $tracepointname = $1;
2543 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002544 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2545 $tracepointname = $1;
2546 }
2547 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2548 $tracepointname = $2;
2549 }
2550 $tracepointname =~ s/^\s+//; #strip leading whitespace
2551 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002552 $tracepointargs = $1;
2553 }
2554 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002555 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002556 "$prototype\n";
2557 } else {
2558 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2559 }
2560}
2561
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002562sub syscall_munge() {
2563 my $void = 0;
2564
2565 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2566## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2567 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2568 $void = 1;
2569## $prototype = "long sys_$1(void)";
2570 }
2571
2572 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2573 if ($prototype =~ m/long (sys_.*?),/) {
2574 $prototype =~ s/,/\(/;
2575 } elsif ($void) {
2576 $prototype =~ s/\)/\(void\)/;
2577 }
2578
2579 # now delete all of the odd-number commas in $prototype
2580 # so that arg types & arg names don't have a comma between them
2581 my $count = 0;
2582 my $len = length($prototype);
2583 if ($void) {
2584 $len = 0; # skip the for-loop
2585 }
2586 for (my $ix = 0; $ix < $len; $ix++) {
2587 if (substr($prototype, $ix, 1) eq ',') {
2588 $count++;
2589 if ($count % 2 == 1) {
2590 substr($prototype, $ix, 1) = ' ';
2591 }
2592 }
2593 }
2594}
2595
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002596sub process_state3_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 my $x = shift;
2598 my $file = shift;
2599
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002600 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2601
Randy Dunlap890c78c2008-10-25 17:06:43 -07002602 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 # do nothing
2604 }
2605 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002606 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002608
Randy Dunlap890c78c2008-10-25 17:06:43 -07002609 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002610 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2612 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002613 if ($prototype =~ /SYSCALL_DEFINE/) {
2614 syscall_munge();
2615 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002616 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2617 $prototype =~ /DEFINE_SINGLE_EVENT/)
2618 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002619 tracepoint_munge($file);
2620 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002621 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 reset_state();
2623 }
2624}
2625
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002626sub process_state3_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 my $x = shift;
2628 my $file = shift;
2629
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2631 $x =~ s@^\s+@@gos; # strip leading spaces
2632 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002633 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2634
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 if ($x =~ /^#/) {
2636 # To distinguish preprocessor directive from regular declaration later.
2637 $x .= ";";
2638 }
2639
2640 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002641 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 $prototype .= $1 . $2;
2643 ($2 eq '{') && $brcount++;
2644 ($2 eq '}') && $brcount--;
2645 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002646 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002648 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 }
2650 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002651 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 $prototype .= $x;
2653 last;
2654 }
2655 }
2656}
2657
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002658# xml_escape: replace <, >, and & in the text stream;
2659#
2660# however, formatting controls that are generated internally/locally in the
2661# kernel-doc script are not escaped here; instead, they begin life like
2662# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2663# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2664# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665sub xml_escape($) {
2666 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002667 if (($output_mode eq "text") || ($output_mode eq "man")) {
2668 return $text;
2669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 $text =~ s/\&/\\\\\\amp;/g;
2671 $text =~ s/\</\\\\\\lt;/g;
2672 $text =~ s/\>/\\\\\\gt;/g;
2673 return $text;
2674}
2675
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002676# xml_unescape: reverse the effects of xml_escape
2677sub xml_unescape($) {
2678 my $text = shift;
2679 if (($output_mode eq "text") || ($output_mode eq "man")) {
2680 return $text;
2681 }
2682 $text =~ s/\\\\\\amp;/\&/g;
2683 $text =~ s/\\\\\\lt;/</g;
2684 $text =~ s/\\\\\\gt;/>/g;
2685 return $text;
2686}
2687
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002688# convert local escape strings to html
2689# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2690sub local_unescape($) {
2691 my $text = shift;
2692 if (($output_mode eq "text") || ($output_mode eq "man")) {
2693 return $text;
2694 }
2695 $text =~ s/\\\\\\\\lt:/</g;
2696 $text =~ s/\\\\\\\\gt:/>/g;
2697 return $text;
2698}
2699
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002701 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 my $identifier;
2703 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002704 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002705 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002706 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002707 my ($orig_file) = @_;
Jani Nikulab7886de2016-05-28 00:41:50 +03002708 my $leading_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709
Randy Dunlap2283a112005-07-07 15:39:26 -07002710 if (defined($ENV{'SRCTREE'})) {
Ben Hutchings68f86662015-09-01 23:48:49 +01002711 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002712 }
2713 else {
Ben Hutchings68f86662015-09-01 23:48:49 +01002714 $file = $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002715 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 if (defined($source_map{$file})) {
2717 $file = $source_map{$file};
2718 }
2719
2720 if (!open(IN,"<$file")) {
2721 print STDERR "Error: Cannot open file $file\n";
2722 ++$errors;
2723 return;
2724 }
2725
Jani Nikula86ae2e32016-01-21 13:05:22 +02002726 # two passes for -export and -internal
Jani Nikulab6c3f452016-05-29 22:19:35 +03002727 if ($output_selection == OUTPUT_EXPORTED ||
2728 $output_selection == OUTPUT_INTERNAL) {
Jani Nikula86ae2e32016-01-21 13:05:22 +02002729 while (<IN>) {
2730 if (/$export_symbol/o) {
2731 $function_table{$2} = 1;
2732 }
2733 }
2734 seek(IN, 0, 0);
2735 }
2736
Ilya Dryomova9e73142010-02-26 13:05:47 -08002737 $. = 1;
2738
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 $section_counter = 0;
2740 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002741 while (s/\\\s*$//) {
2742 $_ .= <IN>;
2743 }
Jani Nikula48af6062016-05-26 14:56:05 +03002744 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002746 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002747 $in_doc_sect = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 }
Jani Nikula48af6062016-05-26 14:56:05 +03002749 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002751 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 $contents = "";
2753 if ( $1 eq "" ) {
2754 $section = $section_intro;
2755 } else {
2756 $section = $1;
2757 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002758 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 elsif (/$doc_decl/o) {
2760 $identifier = $1;
2761 if (/\s*([\w\s]+?)\s*-/) {
2762 $identifier = $1;
2763 }
2764
Jani Nikula48af6062016-05-26 14:56:05 +03002765 $state = STATE_FIELD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002767 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002768 $descr= $1;
2769 $descr =~ s/^\s*//;
2770 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002771 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002772 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002773 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 } else {
2775 $declaration_purpose = "";
2776 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002777
2778 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002779 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002780 print STDERR $_;
2781 ++$warnings;
2782 }
2783
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 if ($identifier =~ m/^struct/) {
2785 $decl_type = 'struct';
2786 } elsif ($identifier =~ m/^union/) {
2787 $decl_type = 'union';
2788 } elsif ($identifier =~ m/^enum/) {
2789 $decl_type = 'enum';
2790 } elsif ($identifier =~ m/^typedef/) {
2791 $decl_type = 'typedef';
2792 } else {
2793 $decl_type = 'function';
2794 }
2795
2796 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002797 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 }
2799 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002800 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 " - I thought it was a doc line\n";
2802 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002803 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 }
Jani Nikula48af6062016-05-26 14:56:05 +03002805 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Jani Nikulaf624ade2016-05-29 11:35:28 +03002806 if (/$doc_sect/i) { # case insensitive for supported section names
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 $newsection = $1;
2808 $newcontents = $2;
2809
Jani Nikulaf624ade2016-05-29 11:35:28 +03002810 # map the supported section names to the canonical names
2811 if ($newsection =~ m/^description$/i) {
2812 $newsection = $section_default;
2813 } elsif ($newsection =~ m/^context$/i) {
2814 $newsection = $section_context;
2815 } elsif ($newsection =~ m/^returns?$/i) {
2816 $newsection = $section_return;
2817 } elsif ($newsection =~ m/^\@return$/) {
2818 # special: @return is a section, not a param description
2819 $newsection = $section_return;
2820 }
2821
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002822 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002823 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002824 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002825 ++$warnings;
2826 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002827 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 $section = $section_default;
2829 }
2830
Randy Dunlap850622d2006-06-25 05:48:55 -07002831 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002832 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 $contents = $newcontents;
Jani Nikula0a726302016-05-28 14:50:20 +03002834 while ((substr($contents, 0, 1) eq " ") ||
2835 substr($contents, 0, 1) eq "\t") {
2836 $contents = substr($contents, 1);
2837 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 if ($contents ne "") {
2839 $contents .= "\n";
2840 }
2841 $section = $newsection;
Jani Nikulab7886de2016-05-28 00:41:50 +03002842 $leading_space = undef;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002844 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002845 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 $section = $section_default;
2847 $contents = "";
2848 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002849 # look for doc_com + <text> + doc_end:
2850 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002851 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002852 ++$warnings;
2853 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854
2855 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002856 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002858# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 } elsif (/$doc_content/) {
2860 # miguel-style comment kludge, look for blank lines after
2861 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002862 if ($1 eq "") {
2863 if ($section =~ m/^@/ || $section eq $section_context) {
2864 dump_section($file, $section, xml_escape($contents));
2865 $section = $section_default;
2866 $contents = "";
2867 } else {
2868 $contents .= "\n";
2869 }
2870 $in_purpose = 0;
2871 } elsif ($in_purpose == 1) {
2872 # Continued declaration purpose
2873 chomp($declaration_purpose);
2874 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002875 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 } else {
Jani Nikulab7886de2016-05-28 00:41:50 +03002877 my $cont = $1;
2878 if ($section =~ m/^@/ || $section eq $section_context) {
2879 if (!defined $leading_space) {
2880 if ($cont =~ m/^(\s+)/) {
2881 $leading_space = $1;
2882 } else {
2883 $leading_space = "";
2884 }
2885 }
2886
2887 $cont =~ s/^$leading_space//;
2888 }
2889 $contents .= $cont . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 }
2891 } else {
2892 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002893 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 ++$warnings;
2895 }
Jani Nikula48af6062016-05-26 14:56:05 +03002896 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002897 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03002898 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002899 $section = $1;
2900 $contents = $2;
2901 if ($contents ne "") {
2902 while ((substr($contents, 0, 1) eq " ") ||
2903 substr($contents, 0, 1) eq "\t") {
2904 $contents = substr($contents, 1);
2905 }
Jani Nikulaa0b96c22016-05-26 22:04:06 +03002906 $contents .= "\n";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002907 }
Jani Nikula48af6062016-05-26 14:56:05 +03002908 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002909 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03002910 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002911 if (($contents ne "") && ($contents ne "\n")) {
2912 dump_section($file, $section, xml_escape($contents));
2913 $section = $section_default;
2914 $contents = "";
2915 }
Jani Nikula48af6062016-05-26 14:56:05 +03002916 $state = STATE_PROTO;
2917 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002918 # Regular text
2919 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03002920 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002921 $contents .= $1 . "\n";
Jani Nikula6450c892016-05-26 22:04:42 +03002922 # nuke leading blank lines
2923 if ($contents =~ /^\s*$/) {
2924 $contents = "";
2925 }
Jani Nikula48af6062016-05-26 14:56:05 +03002926 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
2927 $inline_doc_state = STATE_INLINE_ERROR;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002928 print STDERR "Warning(${file}:$.): ";
2929 print STDERR "Incorrect use of kernel-doc format: $_";
2930 ++$warnings;
2931 }
2932 }
Jani Nikula48af6062016-05-26 14:56:05 +03002933 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
2934 if (/$doc_inline_start/) {
2935 $state = STATE_INLINE;
2936 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002937 } elsif ($decl_type eq 'function') {
Randy Dunlap3c308792007-05-08 00:24:39 -07002938 process_state3_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -07002940 process_state3_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 }
Jani Nikula48af6062016-05-26 14:56:05 +03002942 } elsif ($state == STATE_DOCBLOCK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 # Documentation block
Randy Dunlap3c308792007-05-08 00:24:39 -07002944 if (/$doc_block/) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002945 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 $contents = "";
2947 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 %parameterdescs = ();
2949 %parametertypes = ();
2950 @parameterlist = ();
2951 %sections = ();
2952 @sectionlist = ();
2953 $prototype = "";
2954 if ( $1 eq "" ) {
2955 $section = $section_intro;
2956 } else {
2957 $section = $1;
2958 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 elsif (/$doc_end/)
2961 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002962 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 $contents = "";
2964 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 %parameterdescs = ();
2966 %parametertypes = ();
2967 @parameterlist = ();
2968 %sections = ();
2969 @sectionlist = ();
2970 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002971 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 }
2973 elsif (/$doc_content/)
2974 {
2975 if ( $1 eq "" )
2976 {
2977 $contents .= $blankline;
2978 }
2979 else
2980 {
2981 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002982 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002983 }
2984 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 }
2986 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002987 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002988 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08002989 print STDERR " Was looking for '$_'.\n" for keys %function_table;
2990 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 if ($output_mode eq "xml") {
2992 # The template wants at least one RefEntry here; make one.
2993 print "<refentry>\n";
2994 print " <refnamediv>\n";
2995 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01002996 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 print " </refname>\n";
2998 print " <refpurpose>\n";
2999 print " Document generation inconsistency\n";
3000 print " </refpurpose>\n";
3001 print " </refnamediv>\n";
3002 print " <refsect1>\n";
3003 print " <title>\n";
3004 print " Oops\n";
3005 print " </title>\n";
3006 print " <warning>\n";
3007 print " <para>\n";
3008 print " The template for this document tried to insert\n";
3009 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003010 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 print " but none was found.\n";
3012 print " This dummy section is inserted to allow\n";
3013 print " generation to continue.\n";
3014 print " </para>\n";
3015 print " </warning>\n";
3016 print " </refsect1>\n";
3017 print "</refentry>\n";
3018 }
3019 }
3020}
Randy Dunlap8484baa2011-01-05 16:28:43 -08003021
3022
3023$kernelversion = get_kernel_version();
3024
3025# generate a sequence of code that will splice in highlighting information
3026# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02003027for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03003028 my $pattern = $highlights[$k][0];
3029 my $result = $highlights[$k][1];
3030# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
3031 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08003032}
3033
3034# Read the file that maps relative names to absolute names for
3035# separate source and object directories and for shadow trees.
3036if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3037 my ($relname, $absname);
3038 while(<SOURCE_MAP>) {
3039 chop();
3040 ($relname, $absname) = (split())[0..1];
3041 $relname =~ s:^/+::;
3042 $source_map{$relname} = $absname;
3043 }
3044 close(SOURCE_MAP);
3045}
3046
3047foreach (@ARGV) {
3048 chomp;
3049 process_file($_);
3050}
3051if ($verbose && $errors) {
3052 print STDERR "$errors errors\n";
3053}
3054if ($verbose && $warnings) {
3055 print STDERR "$warnings warnings\n";
3056}
3057
3058exit($errors);