blob: 76bad55c031ec3440462f7a59adfc27b2368f1b2 [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
399my $doc_special = "\@\%\$\&";
400
401my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
402my $doc_end = '\*/';
403my $doc_com = '\s*\*\s*';
Daniel Santos12ae6772012-10-04 17:15:10 -0700404my $doc_com_body = '\s*\* ?';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700405my $doc_decl = $doc_com . '(\w+)';
406my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700407my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700408my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Jani Nikula48af6062016-05-26 14:56:05 +0300409my $doc_inline_start = '^\s*/\*\*\s*$';
410my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
411my $doc_inline_end = '^\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200412my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
414my %constants;
415my %parameterdescs;
416my @parameterlist;
417my %sections;
418my @sectionlist;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800419my $sectcheck;
420my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
422my $contents = "";
423my $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
514 if ($name =~ m/$type_constant/) {
515 $name = $1;
516# print STDERR "constant section '$1' = '$contents'\n";
517 $constants{$name} = $contents;
518 } elsif ($name =~ m/$type_param/) {
519# print STDERR "parameter def '$1' = '$contents'\n";
520 $name = $1;
521 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800522 $sectcheck = $sectcheck . $name . " ";
Randy Dunlapced69092008-12-01 13:14:03 -0800523 } elsif ($name eq "@\.\.\.") {
524# print STDERR "parameter def '...' = '$contents'\n";
525 $name = "...";
526 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800527 $sectcheck = $sectcheck . $name . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 } else {
529# print STDERR "other section '$name' = '$contents'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700530 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Bart Van Assched40e1e62015-09-04 15:43:21 -0700531 print STDERR "${file}:$.: error: duplicate section name '$name'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700532 ++$errors;
533 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 $sections{$name} = $contents;
535 push @sectionlist, $name;
536 }
537}
538
539##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700540# dump DOC: section after checking that it should go out
541#
542sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700543 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700544 my $name = shift;
545 my $contents = join "\n", @_;
546
Johannes Berg4b445952007-10-24 15:08:48 -0700547 if ($no_doc_sections) {
548 return;
549 }
550
Jani Nikulab6c3f452016-05-29 22:19:35 +0300551 if (($output_selection == OUTPUT_ALL) ||
552 ($output_selection == OUTPUT_INCLUDE &&
553 defined($function_table{$name})) ||
554 ($output_selection == OUTPUT_EXCLUDE &&
555 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700556 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700557 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700558 output_blockhead({'sectionlist' => \@sectionlist,
559 'sections' => \%sections,
560 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300561 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700562 }
563}
564
565##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566# output function
567#
568# parameterdescs, a hash.
569# function => "function name"
570# parameterlist => @list of parameters
571# parameterdescs => %parameter descriptions
572# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800573# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800574#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576sub output_highlight {
577 my $contents = join "\n",@_;
578 my $line;
579
580# DEBUG
581# if (!defined $contents) {
582# use Carp;
583# confess "output_highlight got called with no args?\n";
584# }
585
Dan Luedtke1b40c192012-08-12 10:46:15 +0200586 if ($output_mode eq "html" || $output_mode eq "html5" ||
587 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700588 $contents = local_unescape($contents);
589 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800590 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700591 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700592# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 eval $dohighlight;
594 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700595# print STDERR "contents af:$contents\n";
596
Dan Luedtke1b40c192012-08-12 10:46:15 +0200597# strip whitespaces when generating html5
598 if ($output_mode eq "html5") {
599 $contents =~ s/^\s+//;
600 $contents =~ s/\s+$//;
601 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700603 if (! $output_preformatted) {
604 $line =~ s/^\s*//;
605 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700606 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700607 if (! $output_preformatted) {
608 print $lineprefix, local_unescape($blankline);
609 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700611 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700612 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
613 print "\\&$line";
614 } else {
615 print $lineprefix, $line;
616 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 }
618 print "\n";
619 }
620}
621
Dan Luedtke1b40c192012-08-12 10:46:15 +0200622# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623sub output_section_html(%) {
624 my %args = %{$_[0]};
625 my $section;
626
627 foreach $section (@{$args{'sectionlist'}}) {
628 print "<h3>$section</h3>\n";
629 print "<blockquote>\n";
630 output_highlight($args{'sections'}{$section});
631 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800632 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633}
634
635# output enum in html
636sub output_enum_html(%) {
637 my %args = %{$_[0]};
638 my ($parameter);
639 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700640 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Randy Dunlapb9d973282009-06-09 08:50:38 -0700642 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 $count = 0;
644 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700645 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 if ($count != $#{$args{'parameterlist'}}) {
647 $count++;
648 print ",\n";
649 }
650 print "<br>";
651 }
652 print "};<br>\n";
653
654 print "<h3>Constants</h3>\n";
655 print "<dl>\n";
656 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700657 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 print "<dd>";
659 output_highlight($args{'parameterdescs'}{$parameter});
660 }
661 print "</dl>\n";
662 output_section_html(@_);
663 print "<hr>\n";
664}
665
Randy Dunlapd28bee02006-02-01 03:06:57 -0800666# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667sub output_typedef_html(%) {
668 my %args = %{$_[0]};
669 my ($parameter);
670 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700671 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Randy Dunlapb9d973282009-06-09 08:50:38 -0700673 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 output_section_html(@_);
675 print "<hr>\n";
676}
677
678# output struct in html
679sub output_struct_html(%) {
680 my %args = %{$_[0]};
681 my ($parameter);
682
Randy Dunlapb9d973282009-06-09 08:50:38 -0700683 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
684 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 foreach $parameter (@{$args{'parameterlist'}}) {
686 if ($parameter =~ /^#/) {
687 print "$parameter<br>\n";
688 next;
689 }
690 my $parameter_name = $parameter;
691 $parameter_name =~ s/\[.*//;
692
Randy Dunlap3c308792007-05-08 00:24:39 -0700693 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 $type = $args{'parametertypes'}{$parameter};
695 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
696 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700697 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700699 # bitfield
700 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700702 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 }
704 }
705 print "};<br>\n";
706
707 print "<h3>Members</h3>\n";
708 print "<dl>\n";
709 foreach $parameter (@{$args{'parameterlist'}}) {
710 ($parameter =~ /^#/) && next;
711
712 my $parameter_name = $parameter;
713 $parameter_name =~ s/\[.*//;
714
Randy Dunlap3c308792007-05-08 00:24:39 -0700715 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700716 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 print "<dd>";
718 output_highlight($args{'parameterdescs'}{$parameter_name});
719 }
720 print "</dl>\n";
721 output_section_html(@_);
722 print "<hr>\n";
723}
724
725# output function in html
726sub output_function_html(%) {
727 my %args = %{$_[0]};
728 my ($parameter, $section);
729 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
Randy Dunlapb9d973282009-06-09 08:50:38 -0700731 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
732 print "<i>" . $args{'functiontype'} . "</i>\n";
733 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 print "(";
735 $count = 0;
736 foreach $parameter (@{$args{'parameterlist'}}) {
737 $type = $args{'parametertypes'}{$parameter};
738 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
739 # pointer-to-function
740 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
741 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700742 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 }
744 if ($count != $#{$args{'parameterlist'}}) {
745 $count++;
746 print ",\n";
747 }
748 }
749 print ")\n";
750
751 print "<h3>Arguments</h3>\n";
752 print "<dl>\n";
753 foreach $parameter (@{$args{'parameterlist'}}) {
754 my $parameter_name = $parameter;
755 $parameter_name =~ s/\[.*//;
756
Randy Dunlap3c308792007-05-08 00:24:39 -0700757 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700758 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 print "<dd>";
760 output_highlight($args{'parameterdescs'}{$parameter_name});
761 }
762 print "</dl>\n";
763 output_section_html(@_);
764 print "<hr>\n";
765}
766
Johannes Bergb112e0f2007-10-24 15:08:48 -0700767# output DOC: block header in html
768sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 my %args = %{$_[0]};
770 my ($parameter, $section);
771 my $count;
772
773 foreach $section (@{$args{'sectionlist'}}) {
774 print "<h3>$section</h3>\n";
775 print "<ul>\n";
776 output_highlight($args{'sections'}{$section});
777 print "</ul>\n";
778 }
779 print "<hr>\n";
780}
781
Dan Luedtke1b40c192012-08-12 10:46:15 +0200782# output sections in html5
783sub output_section_html5(%) {
784 my %args = %{$_[0]};
785 my $section;
786
787 foreach $section (@{$args{'sectionlist'}}) {
788 print "<section>\n";
789 print "<h1>$section</h1>\n";
790 print "<p>\n";
791 output_highlight($args{'sections'}{$section});
792 print "</p>\n";
793 print "</section>\n";
794 }
795}
796
797# output enum in html5
798sub output_enum_html5(%) {
799 my %args = %{$_[0]};
800 my ($parameter);
801 my $count;
802 my $html5id;
803
804 $html5id = $args{'enum'};
805 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
806 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
807 print "<h1>enum " . $args{'enum'} . "</h1>\n";
808 print "<ol class=\"code\">\n";
809 print "<li>";
810 print "<span class=\"keyword\">enum</span> ";
811 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
812 print "</li>\n";
813 $count = 0;
814 foreach $parameter (@{$args{'parameterlist'}}) {
815 print "<li class=\"indent\">";
816 print "<span class=\"param\">" . $parameter . "</span>";
817 if ($count != $#{$args{'parameterlist'}}) {
818 $count++;
819 print ",";
820 }
821 print "</li>\n";
822 }
823 print "<li>};</li>\n";
824 print "</ol>\n";
825
826 print "<section>\n";
827 print "<h1>Constants</h1>\n";
828 print "<dl>\n";
829 foreach $parameter (@{$args{'parameterlist'}}) {
830 print "<dt>" . $parameter . "</dt>\n";
831 print "<dd>";
832 output_highlight($args{'parameterdescs'}{$parameter});
833 print "</dd>\n";
834 }
835 print "</dl>\n";
836 print "</section>\n";
837 output_section_html5(@_);
838 print "</article>\n";
839}
840
841# output typedef in html5
842sub output_typedef_html5(%) {
843 my %args = %{$_[0]};
844 my ($parameter);
845 my $count;
846 my $html5id;
847
848 $html5id = $args{'typedef'};
849 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
850 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
851 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
852
853 print "<ol class=\"code\">\n";
854 print "<li>";
855 print "<span class=\"keyword\">typedef</span> ";
856 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
857 print "</li>\n";
858 print "</ol>\n";
859 output_section_html5(@_);
860 print "</article>\n";
861}
862
863# output struct in html5
864sub output_struct_html5(%) {
865 my %args = %{$_[0]};
866 my ($parameter);
867 my $html5id;
868
869 $html5id = $args{'struct'};
870 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
871 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
872 print "<hgroup>\n";
873 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
874 print "<h2>". $args{'purpose'} . "</h2>\n";
875 print "</hgroup>\n";
876 print "<ol class=\"code\">\n";
877 print "<li>";
878 print "<span class=\"type\">" . $args{'type'} . "</span> ";
879 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
880 print "</li>\n";
881 foreach $parameter (@{$args{'parameterlist'}}) {
882 print "<li class=\"indent\">";
883 if ($parameter =~ /^#/) {
884 print "<span class=\"param\">" . $parameter ."</span>\n";
885 print "</li>\n";
886 next;
887 }
888 my $parameter_name = $parameter;
889 $parameter_name =~ s/\[.*//;
890
891 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
892 $type = $args{'parametertypes'}{$parameter};
893 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
894 # pointer-to-function
895 print "<span class=\"type\">$1</span> ";
896 print "<span class=\"param\">$parameter</span>";
897 print "<span class=\"type\">)</span> ";
898 print "(<span class=\"args\">$2</span>);";
899 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
900 # bitfield
901 print "<span class=\"type\">$1</span> ";
902 print "<span class=\"param\">$parameter</span>";
903 print "<span class=\"bits\">$2</span>;";
904 } else {
905 print "<span class=\"type\">$type</span> ";
906 print "<span class=\"param\">$parameter</span>;";
907 }
908 print "</li>\n";
909 }
910 print "<li>};</li>\n";
911 print "</ol>\n";
912
913 print "<section>\n";
914 print "<h1>Members</h1>\n";
915 print "<dl>\n";
916 foreach $parameter (@{$args{'parameterlist'}}) {
917 ($parameter =~ /^#/) && next;
918
919 my $parameter_name = $parameter;
920 $parameter_name =~ s/\[.*//;
921
922 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
923 print "<dt>" . $parameter . "</dt>\n";
924 print "<dd>";
925 output_highlight($args{'parameterdescs'}{$parameter_name});
926 print "</dd>\n";
927 }
928 print "</dl>\n";
929 print "</section>\n";
930 output_section_html5(@_);
931 print "</article>\n";
932}
933
934# output function in html5
935sub output_function_html5(%) {
936 my %args = %{$_[0]};
937 my ($parameter, $section);
938 my $count;
939 my $html5id;
940
941 $html5id = $args{'function'};
942 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
943 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
944 print "<hgroup>\n";
945 print "<h1>" . $args{'function'} . "</h1>";
946 print "<h2>" . $args{'purpose'} . "</h2>\n";
947 print "</hgroup>\n";
948 print "<ol class=\"code\">\n";
949 print "<li>";
950 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
951 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
952 print "</li>";
953 $count = 0;
954 foreach $parameter (@{$args{'parameterlist'}}) {
955 print "<li class=\"indent\">";
956 $type = $args{'parametertypes'}{$parameter};
957 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
958 # pointer-to-function
959 print "<span class=\"type\">$1</span> ";
960 print "<span class=\"param\">$parameter</span>";
961 print "<span class=\"type\">)</span> ";
962 print "(<span class=\"args\">$2</span>)";
963 } else {
964 print "<span class=\"type\">$type</span> ";
965 print "<span class=\"param\">$parameter</span>";
966 }
967 if ($count != $#{$args{'parameterlist'}}) {
968 $count++;
969 print ",";
970 }
971 print "</li>\n";
972 }
973 print "<li>)</li>\n";
974 print "</ol>\n";
975
976 print "<section>\n";
977 print "<h1>Arguments</h1>\n";
978 print "<p>\n";
979 print "<dl>\n";
980 foreach $parameter (@{$args{'parameterlist'}}) {
981 my $parameter_name = $parameter;
982 $parameter_name =~ s/\[.*//;
983
984 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
985 print "<dt>" . $parameter . "</dt>\n";
986 print "<dd>";
987 output_highlight($args{'parameterdescs'}{$parameter_name});
988 print "</dd>\n";
989 }
990 print "</dl>\n";
991 print "</section>\n";
992 output_section_html5(@_);
993 print "</article>\n";
994}
995
996# output DOC: block header in html5
997sub output_blockhead_html5(%) {
998 my %args = %{$_[0]};
999 my ($parameter, $section);
1000 my $count;
1001 my $html5id;
1002
1003 foreach $section (@{$args{'sectionlist'}}) {
1004 $html5id = $section;
1005 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1006 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1007 print "<h1>$section</h1>\n";
1008 print "<p>\n";
1009 output_highlight($args{'sections'}{$section});
1010 print "</p>\n";
1011 }
1012 print "</article>\n";
1013}
1014
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015sub output_section_xml(%) {
1016 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001017 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 # print out each section
1019 $lineprefix=" ";
1020 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001021 print "<refsect1>\n";
1022 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001024 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001025 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001026 } else {
1027 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 }
1029 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001030 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001032 print "</programlisting></informalexample>\n";
1033 } else {
1034 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001036 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 }
1038}
1039
1040# output function in XML DocBook
1041sub output_function_xml(%) {
1042 my %args = %{$_[0]};
1043 my ($parameter, $section);
1044 my $count;
1045 my $id;
1046
Randy Dunlapb9d973282009-06-09 08:50:38 -07001047 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 $id =~ s/[^A-Za-z0-9]/-/g;
1049
Pavel Pisa5449bc92007-02-10 01:45:37 -08001050 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001051 print "<refentryinfo>\n";
1052 print " <title>LINUX</title>\n";
1053 print " <productname>Kernel Hackers Manual</productname>\n";
1054 print " <date>$man_date</date>\n";
1055 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001057 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001058 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001059 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 print "</refmeta>\n";
1061 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001062 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 print " <refpurpose>\n";
1064 print " ";
1065 output_highlight ($args{'purpose'});
1066 print " </refpurpose>\n";
1067 print "</refnamediv>\n";
1068
1069 print "<refsynopsisdiv>\n";
1070 print " <title>Synopsis</title>\n";
1071 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001072 print " <funcdef>" . $args{'functiontype'} . " ";
1073 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
1075 $count = 0;
1076 if ($#{$args{'parameterlist'}} >= 0) {
1077 foreach $parameter (@{$args{'parameterlist'}}) {
1078 $type = $args{'parametertypes'}{$parameter};
1079 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1080 # pointer-to-function
1081 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1082 print " <funcparams>$2</funcparams></paramdef>\n";
1083 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001084 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 print " <parameter>$parameter</parameter></paramdef>\n";
1086 }
1087 }
1088 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001089 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 }
1091 print " </funcprototype></funcsynopsis>\n";
1092 print "</refsynopsisdiv>\n";
1093
1094 # print parameters
1095 print "<refsect1>\n <title>Arguments</title>\n";
1096 if ($#{$args{'parameterlist'}} >= 0) {
1097 print " <variablelist>\n";
1098 foreach $parameter (@{$args{'parameterlist'}}) {
1099 my $parameter_name = $parameter;
1100 $parameter_name =~ s/\[.*//;
1101
1102 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1103 print " <listitem>\n <para>\n";
1104 $lineprefix=" ";
1105 output_highlight($args{'parameterdescs'}{$parameter_name});
1106 print " </para>\n </listitem>\n </varlistentry>\n";
1107 }
1108 print " </variablelist>\n";
1109 } else {
1110 print " <para>\n None\n </para>\n";
1111 }
1112 print "</refsect1>\n";
1113
1114 output_section_xml(@_);
1115 print "</refentry>\n\n";
1116}
1117
1118# output struct in XML DocBook
1119sub output_struct_xml(%) {
1120 my %args = %{$_[0]};
1121 my ($parameter, $section);
1122 my $id;
1123
Randy Dunlapb9d973282009-06-09 08:50:38 -07001124 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 $id =~ s/[^A-Za-z0-9]/-/g;
1126
Pavel Pisa5449bc92007-02-10 01:45:37 -08001127 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001128 print "<refentryinfo>\n";
1129 print " <title>LINUX</title>\n";
1130 print " <productname>Kernel Hackers Manual</productname>\n";
1131 print " <date>$man_date</date>\n";
1132 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001134 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001135 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001136 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 print "</refmeta>\n";
1138 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001139 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 print " <refpurpose>\n";
1141 print " ";
1142 output_highlight ($args{'purpose'});
1143 print " </refpurpose>\n";
1144 print "</refnamediv>\n";
1145
1146 print "<refsynopsisdiv>\n";
1147 print " <title>Synopsis</title>\n";
1148 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001149 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 foreach $parameter (@{$args{'parameterlist'}}) {
1151 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001152 my $prm = $parameter;
1153 # convert data read & converted thru xml_escape() into &xyz; format:
1154 # This allows us to have #define macros interspersed in a struct.
1155 $prm =~ s/\\\\\\/\&/g;
1156 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 next;
1158 }
1159
1160 my $parameter_name = $parameter;
1161 $parameter_name =~ s/\[.*//;
1162
1163 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001164 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 $type = $args{'parametertypes'}{$parameter};
1166 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1167 # pointer-to-function
1168 print " $1 $parameter) ($2);\n";
1169 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001170 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 print " $1 $parameter$2;\n";
1172 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001173 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 }
1175 }
1176 print "};";
1177 print " </programlisting>\n";
1178 print "</refsynopsisdiv>\n";
1179
1180 print " <refsect1>\n";
1181 print " <title>Members</title>\n";
1182
Randy Dunlap39f00c02008-09-22 13:57:44 -07001183 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 print " <variablelist>\n";
1185 foreach $parameter (@{$args{'parameterlist'}}) {
1186 ($parameter =~ /^#/) && next;
1187
1188 my $parameter_name = $parameter;
1189 $parameter_name =~ s/\[.*//;
1190
1191 defined($args{'parameterdescs'}{$parameter_name}) || next;
1192 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1193 print " <varlistentry>";
1194 print " <term>$parameter</term>\n";
1195 print " <listitem><para>\n";
1196 output_highlight($args{'parameterdescs'}{$parameter_name});
1197 print " </para></listitem>\n";
1198 print " </varlistentry>\n";
1199 }
1200 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001201 } else {
1202 print " <para>\n None\n </para>\n";
1203 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 print " </refsect1>\n";
1205
1206 output_section_xml(@_);
1207
1208 print "</refentry>\n\n";
1209}
1210
1211# output enum in XML DocBook
1212sub output_enum_xml(%) {
1213 my %args = %{$_[0]};
1214 my ($parameter, $section);
1215 my $count;
1216 my $id;
1217
Randy Dunlapb9d973282009-06-09 08:50:38 -07001218 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 $id =~ s/[^A-Za-z0-9]/-/g;
1220
Pavel Pisa5449bc92007-02-10 01:45:37 -08001221 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001222 print "<refentryinfo>\n";
1223 print " <title>LINUX</title>\n";
1224 print " <productname>Kernel Hackers Manual</productname>\n";
1225 print " <date>$man_date</date>\n";
1226 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001228 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001229 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001230 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 print "</refmeta>\n";
1232 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001233 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 print " <refpurpose>\n";
1235 print " ";
1236 output_highlight ($args{'purpose'});
1237 print " </refpurpose>\n";
1238 print "</refnamediv>\n";
1239
1240 print "<refsynopsisdiv>\n";
1241 print " <title>Synopsis</title>\n";
1242 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001243 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 $count = 0;
1245 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001246 print " $parameter";
1247 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 $count++;
1249 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 print "\n";
1252 }
1253 print "};";
1254 print " </programlisting>\n";
1255 print "</refsynopsisdiv>\n";
1256
1257 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001258 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 print " <variablelist>\n";
1260 foreach $parameter (@{$args{'parameterlist'}}) {
1261 my $parameter_name = $parameter;
1262 $parameter_name =~ s/\[.*//;
1263
1264 print " <varlistentry>";
1265 print " <term>$parameter</term>\n";
1266 print " <listitem><para>\n";
1267 output_highlight($args{'parameterdescs'}{$parameter_name});
1268 print " </para></listitem>\n";
1269 print " </varlistentry>\n";
1270 }
1271 print " </variablelist>\n";
1272 print "</refsect1>\n";
1273
1274 output_section_xml(@_);
1275
1276 print "</refentry>\n\n";
1277}
1278
1279# output typedef in XML DocBook
1280sub output_typedef_xml(%) {
1281 my %args = %{$_[0]};
1282 my ($parameter, $section);
1283 my $id;
1284
Randy Dunlapb9d973282009-06-09 08:50:38 -07001285 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 $id =~ s/[^A-Za-z0-9]/-/g;
1287
Pavel Pisa5449bc92007-02-10 01:45:37 -08001288 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001289 print "<refentryinfo>\n";
1290 print " <title>LINUX</title>\n";
1291 print " <productname>Kernel Hackers Manual</productname>\n";
1292 print " <date>$man_date</date>\n";
1293 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001295 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001296 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 print "</refmeta>\n";
1298 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001299 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 print " <refpurpose>\n";
1301 print " ";
1302 output_highlight ($args{'purpose'});
1303 print " </refpurpose>\n";
1304 print "</refnamediv>\n";
1305
1306 print "<refsynopsisdiv>\n";
1307 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001308 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 print "</refsynopsisdiv>\n";
1310
1311 output_section_xml(@_);
1312
1313 print "</refentry>\n\n";
1314}
1315
1316# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001317sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 my %args = %{$_[0]};
1319 my ($parameter, $section);
1320 my $count;
1321
1322 my $id = $args{'module'};
1323 $id =~ s/[^A-Za-z0-9]/-/g;
1324
1325 # print out each section
1326 $lineprefix=" ";
1327 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001328 if (!$args{'content-only'}) {
1329 print "<refsect1>\n <title>$section</title>\n";
1330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 if ($section =~ m/EXAMPLE/i) {
1332 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001333 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001334 } else {
1335 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 }
1337 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001338 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 if ($section =~ m/EXAMPLE/i) {
1340 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001341 } else {
1342 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001344 if (!$args{'content-only'}) {
1345 print "\n</refsect1>\n";
1346 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 }
1348
1349 print "\n\n";
1350}
1351
1352# output in XML DocBook
1353sub output_function_gnome {
1354 my %args = %{$_[0]};
1355 my ($parameter, $section);
1356 my $count;
1357 my $id;
1358
Randy Dunlapb9d973282009-06-09 08:50:38 -07001359 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 $id =~ s/[^A-Za-z0-9]/-/g;
1361
1362 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001363 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364
1365 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001366 print " <funcdef>" . $args{'functiontype'} . " ";
1367 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 print "</function></funcdef>\n";
1369
1370 $count = 0;
1371 if ($#{$args{'parameterlist'}} >= 0) {
1372 foreach $parameter (@{$args{'parameterlist'}}) {
1373 $type = $args{'parametertypes'}{$parameter};
1374 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1375 # pointer-to-function
1376 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1377 print " <funcparams>$2</funcparams></paramdef>\n";
1378 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001379 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 print " <parameter>$parameter</parameter></paramdef>\n";
1381 }
1382 }
1383 } else {
1384 print " <void>\n";
1385 }
1386 print " </funcsynopsis>\n";
1387 if ($#{$args{'parameterlist'}} >= 0) {
1388 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1389 print "<tgroup cols=\"2\">\n";
1390 print "<colspec colwidth=\"2*\">\n";
1391 print "<colspec colwidth=\"8*\">\n";
1392 print "<tbody>\n";
1393 foreach $parameter (@{$args{'parameterlist'}}) {
1394 my $parameter_name = $parameter;
1395 $parameter_name =~ s/\[.*//;
1396
1397 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1398 print " <entry>\n";
1399 $lineprefix=" ";
1400 output_highlight($args{'parameterdescs'}{$parameter_name});
1401 print " </entry></row>\n";
1402 }
1403 print " </tbody></tgroup></informaltable>\n";
1404 } else {
1405 print " <para>\n None\n </para>\n";
1406 }
1407
1408 # print out each section
1409 $lineprefix=" ";
1410 foreach $section (@{$args{'sectionlist'}}) {
1411 print "<simplesect>\n <title>$section</title>\n";
1412 if ($section =~ m/EXAMPLE/i) {
1413 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001414 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 } else {
1416 }
1417 print "<para>\n";
1418 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001419 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 print "</para>\n";
1421 if ($section =~ m/EXAMPLE/i) {
1422 print "</programlisting></example>\n";
1423 } else {
1424 }
1425 print " </simplesect>\n";
1426 }
1427
1428 print "</sect2>\n\n";
1429}
1430
1431##
1432# output function in man
1433sub output_function_man(%) {
1434 my %args = %{$_[0]};
1435 my ($parameter, $section);
1436 my $count;
1437
1438 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1439
1440 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001441 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
1443 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001444 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001445 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001446 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001447 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 $count = 0;
1450 my $parenth = "(";
1451 my $post = ",";
1452 foreach my $parameter (@{$args{'parameterlist'}}) {
1453 if ($count == $#{$args{'parameterlist'}}) {
1454 $post = ");";
1455 }
1456 $type = $args{'parametertypes'}{$parameter};
1457 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1458 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001459 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 } else {
1461 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001462 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463 }
1464 $count++;
1465 $parenth = "";
1466 }
1467
1468 print ".SH ARGUMENTS\n";
1469 foreach $parameter (@{$args{'parameterlist'}}) {
1470 my $parameter_name = $parameter;
1471 $parameter_name =~ s/\[.*//;
1472
Randy Dunlapb9d973282009-06-09 08:50:38 -07001473 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 output_highlight($args{'parameterdescs'}{$parameter_name});
1475 }
1476 foreach $section (@{$args{'sectionlist'}}) {
1477 print ".SH \"", uc $section, "\"\n";
1478 output_highlight($args{'sections'}{$section});
1479 }
1480}
1481
1482##
1483# output enum in man
1484sub output_enum_man(%) {
1485 my %args = %{$_[0]};
1486 my ($parameter, $section);
1487 my $count;
1488
1489 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1490
1491 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001492 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
1494 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001495 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 $count = 0;
1497 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001498 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 if ($count == $#{$args{'parameterlist'}}) {
1500 print "\n};\n";
1501 last;
1502 }
1503 else {
1504 print ", \n.br\n";
1505 }
1506 $count++;
1507 }
1508
1509 print ".SH Constants\n";
1510 foreach $parameter (@{$args{'parameterlist'}}) {
1511 my $parameter_name = $parameter;
1512 $parameter_name =~ s/\[.*//;
1513
Randy Dunlapb9d973282009-06-09 08:50:38 -07001514 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 output_highlight($args{'parameterdescs'}{$parameter_name});
1516 }
1517 foreach $section (@{$args{'sectionlist'}}) {
1518 print ".SH \"$section\"\n";
1519 output_highlight($args{'sections'}{$section});
1520 }
1521}
1522
1523##
1524# output struct in man
1525sub output_struct_man(%) {
1526 my %args = %{$_[0]};
1527 my ($parameter, $section);
1528
Randy Dunlapb9d973282009-06-09 08:50:38 -07001529 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530
1531 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001532 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533
1534 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001535 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
1537 foreach my $parameter (@{$args{'parameterlist'}}) {
1538 if ($parameter =~ /^#/) {
1539 print ".BI \"$parameter\"\n.br\n";
1540 next;
1541 }
1542 my $parameter_name = $parameter;
1543 $parameter_name =~ s/\[.*//;
1544
Randy Dunlap3c308792007-05-08 00:24:39 -07001545 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 $type = $args{'parametertypes'}{$parameter};
1547 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1548 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001549 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001551 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001552 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 } else {
1554 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001555 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 }
1557 print "\n.br\n";
1558 }
1559 print "};\n.br\n";
1560
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001561 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 foreach $parameter (@{$args{'parameterlist'}}) {
1563 ($parameter =~ /^#/) && next;
1564
1565 my $parameter_name = $parameter;
1566 $parameter_name =~ s/\[.*//;
1567
Randy Dunlap3c308792007-05-08 00:24:39 -07001568 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001569 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 output_highlight($args{'parameterdescs'}{$parameter_name});
1571 }
1572 foreach $section (@{$args{'sectionlist'}}) {
1573 print ".SH \"$section\"\n";
1574 output_highlight($args{'sections'}{$section});
1575 }
1576}
1577
1578##
1579# output typedef in man
1580sub output_typedef_man(%) {
1581 my %args = %{$_[0]};
1582 my ($parameter, $section);
1583
1584 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1585
1586 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001587 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
1589 foreach $section (@{$args{'sectionlist'}}) {
1590 print ".SH \"$section\"\n";
1591 output_highlight($args{'sections'}{$section});
1592 }
1593}
1594
Johannes Bergb112e0f2007-10-24 15:08:48 -07001595sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 my %args = %{$_[0]};
1597 my ($parameter, $section);
1598 my $count;
1599
1600 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1601
1602 foreach $section (@{$args{'sectionlist'}}) {
1603 print ".SH \"$section\"\n";
1604 output_highlight($args{'sections'}{$section});
1605 }
1606}
1607
1608##
1609# output in text
1610sub output_function_text(%) {
1611 my %args = %{$_[0]};
1612 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001613 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614
Randy Dunlapf47634b2006-07-01 04:36:36 -07001615 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001616 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001617
1618 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001619 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001620 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001621 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001622 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001623 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001625
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 my $count = 0;
1627 foreach my $parameter (@{$args{'parameterlist'}}) {
1628 $type = $args{'parametertypes'}{$parameter};
1629 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1630 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001631 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001633 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 }
1635 if ($count != $#{$args{'parameterlist'}}) {
1636 $count++;
1637 print ",\n";
1638 print " " x length($start);
1639 } else {
1640 print ");\n\n";
1641 }
1642 }
1643
1644 print "Arguments:\n\n";
1645 foreach $parameter (@{$args{'parameterlist'}}) {
1646 my $parameter_name = $parameter;
1647 $parameter_name =~ s/\[.*//;
1648
Randy Dunlapb9d973282009-06-09 08:50:38 -07001649 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 }
1651 output_section_text(@_);
1652}
1653
1654#output sections in text
1655sub output_section_text(%) {
1656 my %args = %{$_[0]};
1657 my $section;
1658
1659 print "\n";
1660 foreach $section (@{$args{'sectionlist'}}) {
1661 print "$section:\n\n";
1662 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001663 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 print "\n\n";
1665}
1666
1667# output enum in text
1668sub output_enum_text(%) {
1669 my %args = %{$_[0]};
1670 my ($parameter);
1671 my $count;
1672 print "Enum:\n\n";
1673
Randy Dunlapb9d973282009-06-09 08:50:38 -07001674 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1675 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001676 $count = 0;
1677 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001678 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 if ($count != $#{$args{'parameterlist'}}) {
1680 $count++;
1681 print ",";
1682 }
1683 print "\n";
1684 }
1685 print "};\n\n";
1686
1687 print "Constants:\n\n";
1688 foreach $parameter (@{$args{'parameterlist'}}) {
1689 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001690 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 }
1692
1693 output_section_text(@_);
1694}
1695
1696# output typedef in text
1697sub output_typedef_text(%) {
1698 my %args = %{$_[0]};
1699 my ($parameter);
1700 my $count;
1701 print "Typedef:\n\n";
1702
Randy Dunlapb9d973282009-06-09 08:50:38 -07001703 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 output_section_text(@_);
1705}
1706
1707# output struct as text
1708sub output_struct_text(%) {
1709 my %args = %{$_[0]};
1710 my ($parameter);
1711
Randy Dunlapb9d973282009-06-09 08:50:38 -07001712 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1713 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 foreach $parameter (@{$args{'parameterlist'}}) {
1715 if ($parameter =~ /^#/) {
1716 print "$parameter\n";
1717 next;
1718 }
1719
1720 my $parameter_name = $parameter;
1721 $parameter_name =~ s/\[.*//;
1722
Randy Dunlap3c308792007-05-08 00:24:39 -07001723 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 $type = $args{'parametertypes'}{$parameter};
1725 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1726 # pointer-to-function
1727 print "\t$1 $parameter) ($2);\n";
1728 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001729 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 print "\t$1 $parameter$2;\n";
1731 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001732 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 }
1734 }
1735 print "};\n\n";
1736
1737 print "Members:\n\n";
1738 foreach $parameter (@{$args{'parameterlist'}}) {
1739 ($parameter =~ /^#/) && next;
1740
1741 my $parameter_name = $parameter;
1742 $parameter_name =~ s/\[.*//;
1743
Randy Dunlap3c308792007-05-08 00:24:39 -07001744 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001746 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 }
1748 print "\n";
1749 output_section_text(@_);
1750}
1751
Johannes Bergb112e0f2007-10-24 15:08:48 -07001752sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 my %args = %{$_[0]};
1754 my ($parameter, $section);
1755
1756 foreach $section (@{$args{'sectionlist'}}) {
1757 print " $section:\n";
1758 print " -> ";
1759 output_highlight($args{'sections'}{$section});
1760 }
1761}
1762
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001763##
1764# output in restructured text
1765#
1766
1767#
1768# This could use some work; it's used to output the DOC: sections, and
1769# starts by putting out the name of the doc section itself, but that tends
1770# to duplicate a header already in the template file.
1771#
1772sub output_blockhead_rst(%) {
1773 my %args = %{$_[0]};
1774 my ($parameter, $section);
1775
1776 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001777 if ($output_selection != OUTPUT_INCLUDE) {
1778 print "**$section**\n\n";
1779 }
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001780 output_highlight_rst($args{'sections'}{$section});
1781 print "\n";
1782 }
1783}
1784
1785sub output_highlight_rst {
1786 my $contents = join "\n",@_;
1787 my $line;
1788
1789 # undo the evil effects of xml_escape() earlier
1790 $contents = xml_unescape($contents);
1791
1792 eval $dohighlight;
1793 die $@ if $@;
1794
1795 foreach $line (split "\n", $contents) {
1796 if ($line eq "") {
1797 print $lineprefix, $blankline;
1798 } else {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001799 print $lineprefix, $line;
1800 }
1801 print "\n";
1802 }
1803}
1804
1805sub output_function_rst(%) {
1806 my %args = %{$_[0]};
1807 my ($parameter, $section);
Jani Nikulac099ff62016-05-26 17:18:17 +03001808 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001809 my $start;
1810
1811 print ".. c:function:: ";
1812 if ($args{'functiontype'} ne "") {
1813 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1814 } else {
1815 $start = $args{'function'} . " (";
1816 }
1817 print $start;
1818
1819 my $count = 0;
1820 foreach my $parameter (@{$args{'parameterlist'}}) {
1821 if ($count ne 0) {
1822 print ", ";
1823 }
1824 $count++;
1825 $type = $args{'parametertypes'}{$parameter};
1826 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1827 # pointer-to-function
1828 print $1 . $parameter . ") (" . $2;
1829 } else {
1830 print $type . " " . $parameter;
1831 }
1832 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001833 print ")\n\n";
1834 $lineprefix = " ";
1835 output_highlight_rst($args{'purpose'});
1836 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001837
1838 print ":Parameters:\n\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001839 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001840 foreach $parameter (@{$args{'parameterlist'}}) {
1841 my $parameter_name = $parameter;
1842 #$parameter_name =~ s/\[.*//;
1843 $type = $args{'parametertypes'}{$parameter};
1844
1845 if ($type ne "") {
1846 print " ``$type $parameter``\n";
1847 } else {
1848 print " ``$parameter``\n";
1849 }
Jani Nikula5e64fa92016-05-19 20:32:48 +03001850 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1851 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001852 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001853 } else {
1854 print "\n _undescribed_\n";
1855 }
1856 print "\n";
1857 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001858
1859 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001860 output_section_rst(@_);
1861}
1862
1863sub output_section_rst(%) {
1864 my %args = %{$_[0]};
1865 my $section;
1866 my $oldprefix = $lineprefix;
1867 $lineprefix = " ";
1868
1869 foreach $section (@{$args{'sectionlist'}}) {
1870 print ":$section:\n\n";
1871 output_highlight_rst($args{'sections'}{$section});
1872 print "\n";
1873 }
1874 print "\n";
1875 $lineprefix = $oldprefix;
1876}
1877
1878sub output_enum_rst(%) {
1879 my %args = %{$_[0]};
1880 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001881 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001882 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001883 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001884
1885 print "\n\n.. c:type:: " . $name . "\n\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001886 $lineprefix = " ";
1887 output_highlight_rst($args{'purpose'});
1888 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001889
1890 print "..\n\n:Constants:\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001891 $lineprefix = " ";
1892 foreach $parameter (@{$args{'parameterlist'}}) {
1893 print " `$parameter`\n";
1894 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1895 output_highlight_rst($args{'parameterdescs'}{$parameter});
1896 } else {
1897 print " undescribed\n";
1898 }
1899 print "\n";
1900 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001901
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001902 $lineprefix = $oldprefix;
1903 output_section_rst(@_);
1904}
1905
1906sub output_typedef_rst(%) {
1907 my %args = %{$_[0]};
1908 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001909 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001910 my $name = "typedef " . $args{'typedef'};
1911
Jani Nikula62850972016-05-12 16:15:38 +03001912 ### FIXME: should the name below contain "typedef" or not?
1913 print "\n\n.. c:type:: " . $name . "\n\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001914 $lineprefix = " ";
1915 output_highlight_rst($args{'purpose'});
1916 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001917
Jani Nikulac099ff62016-05-26 17:18:17 +03001918 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001919 output_section_rst(@_);
1920}
1921
1922sub output_struct_rst(%) {
1923 my %args = %{$_[0]};
1924 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001925 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001926 my $name = $args{'type'} . " " . $args{'struct'};
1927
Jani Nikula62850972016-05-12 16:15:38 +03001928 print "\n\n.. c:type:: " . $name . "\n\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001929 $lineprefix = " ";
1930 output_highlight_rst($args{'purpose'});
1931 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001932
1933 print ":Definition:\n\n";
1934 print " ::\n\n";
1935 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1936 foreach $parameter (@{$args{'parameterlist'}}) {
1937 if ($parameter =~ /^#/) {
1938 print " " . "$parameter\n";
1939 next;
1940 }
1941
1942 my $parameter_name = $parameter;
1943 $parameter_name =~ s/\[.*//;
1944
1945 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1946 $type = $args{'parametertypes'}{$parameter};
1947 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1948 # pointer-to-function
1949 print " $1 $parameter) ($2);\n";
1950 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1951 # bitfield
1952 print " $1 $parameter$2;\n";
1953 } else {
1954 print " " . $type . " " . $parameter . ";\n";
1955 }
1956 }
1957 print " };\n\n";
1958
1959 print ":Members:\n\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001960 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001961 foreach $parameter (@{$args{'parameterlist'}}) {
1962 ($parameter =~ /^#/) && next;
1963
1964 my $parameter_name = $parameter;
1965 $parameter_name =~ s/\[.*//;
1966
1967 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1968 $type = $args{'parametertypes'}{$parameter};
1969 print " `$type $parameter`" . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001970 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001971 print "\n";
1972 }
1973 print "\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001974
1975 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001976 output_section_rst(@_);
1977}
1978
1979
Johannes Bergeda603f2010-09-11 15:55:22 -07001980## list mode output functions
1981
1982sub output_function_list(%) {
1983 my %args = %{$_[0]};
1984
1985 print $args{'function'} . "\n";
1986}
1987
1988# output enum in list
1989sub output_enum_list(%) {
1990 my %args = %{$_[0]};
1991 print $args{'enum'} . "\n";
1992}
1993
1994# output typedef in list
1995sub output_typedef_list(%) {
1996 my %args = %{$_[0]};
1997 print $args{'typedef'} . "\n";
1998}
1999
2000# output struct as list
2001sub output_struct_list(%) {
2002 my %args = %{$_[0]};
2003
2004 print $args{'struct'} . "\n";
2005}
2006
2007sub output_blockhead_list(%) {
2008 my %args = %{$_[0]};
2009 my ($parameter, $section);
2010
2011 foreach $section (@{$args{'sectionlist'}}) {
2012 print "DOC: $section\n";
2013 }
2014}
2015
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016##
Randy Dunlap27205742006-10-11 01:22:12 -07002017# generic output function for all types (function, struct/union, typedef, enum);
2018# calls the generated, variable output_ function name based on
2019# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020sub output_declaration {
2021 no strict 'refs';
2022 my $name = shift;
2023 my $functype = shift;
2024 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002025 if (($output_selection == OUTPUT_ALL) ||
2026 (($output_selection == OUTPUT_INCLUDE ||
2027 $output_selection == OUTPUT_EXPORTED) &&
2028 defined($function_table{$name})) ||
2029 (($output_selection == OUTPUT_EXCLUDE ||
2030 $output_selection == OUTPUT_INTERNAL) &&
2031 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002033 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 $section_counter++;
2035 }
2036}
2037
2038##
Randy Dunlap27205742006-10-11 01:22:12 -07002039# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002040sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002042 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 &$func(@_);
2044 $section_counter++;
2045}
2046
2047##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002048# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049# invokes the right handler. NOT called for functions.
2050sub dump_declaration($$) {
2051 no strict 'refs';
2052 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002053 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 &$func(@_);
2055}
2056
2057sub dump_union($$) {
2058 dump_struct(@_);
2059}
2060
2061sub dump_struct($$) {
2062 my $x = shift;
2063 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002064 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002066 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2067 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002068 $declaration_name = $2;
2069 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070
2071 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002072 $members =~ s/({.*})//g;
2073 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074
Martin Waitzaeec46b2005-11-13 16:08:13 -08002075 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002076 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2077 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002078 # strip comments:
2079 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002080 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002081 # strip kmemcheck_bitfield_{begin,end}.*;
2082 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002083 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002084 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002085 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002086 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002087 # replace DECLARE_BITMAP
2088 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002089
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002091 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092
2093 output_declaration($declaration_name,
2094 'struct',
2095 {'struct' => $declaration_name,
2096 'module' => $modulename,
2097 'parameterlist' => \@parameterlist,
2098 'parameterdescs' => \%parameterdescs,
2099 'parametertypes' => \%parametertypes,
2100 'sectionlist' => \@sectionlist,
2101 'sections' => \%sections,
2102 'purpose' => $declaration_purpose,
2103 'type' => $decl_type
2104 });
2105 }
2106 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002107 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 ++$errors;
2109 }
2110}
2111
2112sub dump_enum($$) {
2113 my $x = shift;
2114 my $file = shift;
2115
Martin Waitzaeec46b2005-11-13 16:08:13 -08002116 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002117 # strip #define macros inside enums
2118 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002119
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002121 $declaration_name = $1;
2122 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
2124 foreach my $arg (split ',', $members) {
2125 $arg =~ s/^\s*(\w+).*/$1/;
2126 push @parameterlist, $arg;
2127 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002128 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002129 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 "not described in enum '$declaration_name'\n";
2131 }
2132
2133 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002134
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 output_declaration($declaration_name,
2136 'enum',
2137 {'enum' => $declaration_name,
2138 'module' => $modulename,
2139 'parameterlist' => \@parameterlist,
2140 'parameterdescs' => \%parameterdescs,
2141 'sectionlist' => \@sectionlist,
2142 'sections' => \%sections,
2143 'purpose' => $declaration_purpose
2144 });
2145 }
2146 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002147 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 ++$errors;
2149 }
2150}
2151
2152sub dump_typedef($$) {
2153 my $x = shift;
2154 my $file = shift;
2155
Martin Waitzaeec46b2005-11-13 16:08:13 -08002156 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002157
2158 # Parse function prototypes
2159 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
2160 # Function typedefs
2161 $return_type = $1;
2162 $declaration_name = $2;
2163 my $args = $3;
2164
2165 create_parameterlist($args, ',', $file);
2166
2167 output_declaration($declaration_name,
2168 'function',
2169 {'function' => $declaration_name,
2170 'module' => $modulename,
2171 'functiontype' => $return_type,
2172 'parameterlist' => \@parameterlist,
2173 'parameterdescs' => \%parameterdescs,
2174 'parametertypes' => \%parametertypes,
2175 'sectionlist' => \@sectionlist,
2176 'sections' => \%sections,
2177 'purpose' => $declaration_purpose
2178 });
2179 return;
2180 }
2181
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002183 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 $x =~ s/\[*.\]\s*;$/;/;
2185 }
2186
2187 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002188 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189
2190 output_declaration($declaration_name,
2191 'typedef',
2192 {'typedef' => $declaration_name,
2193 'module' => $modulename,
2194 'sectionlist' => \@sectionlist,
2195 'sections' => \%sections,
2196 'purpose' => $declaration_purpose
2197 });
2198 }
2199 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002200 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 ++$errors;
2202 }
2203}
2204
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002205sub save_struct_actual($) {
2206 my $actual = shift;
2207
2208 # strip all spaces from the actual param so that it looks like one string item
2209 $actual =~ s/\s*//g;
2210 $struct_actual = $struct_actual . $actual . " ";
2211}
2212
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213sub create_parameterlist($$$) {
2214 my $args = shift;
2215 my $splitter = shift;
2216 my $file = shift;
2217 my $type;
2218 my $param;
2219
Martin Waitza6d3fe72006-01-09 20:53:55 -08002220 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002222 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002224
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 foreach my $arg (split($splitter, $args)) {
2226 # strip comments
2227 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002228 # strip leading/trailing spaces
2229 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 $arg =~ s/\s*$//;
2231 $arg =~ s/\s+/ /;
2232
2233 if ($arg =~ /^#/) {
2234 # Treat preprocessor directive as a typeless variable just to fill
2235 # corresponding data structures "correctly". Catch it later in
2236 # output_* subs.
2237 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002238 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 # pointer-to-function
2240 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002241 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 $param = $1;
2243 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002244 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002245 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002247 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 $arg =~ s/\s*:\s*/:/g;
2249 $arg =~ s/\s*\[/\[/g;
2250
2251 my @args = split('\s*,\s*', $arg);
2252 if ($args[0] =~ m/\*/) {
2253 $args[0] =~ s/(\*+)\s*/ $1/;
2254 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002255
2256 my @first_arg;
2257 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2258 shift @args;
2259 push(@first_arg, split('\s+', $1));
2260 push(@first_arg, $2);
2261 } else {
2262 @first_arg = split('\s+', shift @args);
2263 }
2264
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 unshift(@args, pop @first_arg);
2266 $type = join " ", @first_arg;
2267
2268 foreach $param (@args) {
2269 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002270 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 push_parameter($2, "$type $1", $file);
2272 }
2273 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002274 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002275 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002276 push_parameter($1, "$type:$2", $file)
2277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 }
2279 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002280 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 push_parameter($param, $type, $file);
2282 }
2283 }
2284 }
2285 }
2286}
2287
2288sub push_parameter($$$) {
2289 my $param = shift;
2290 my $type = shift;
2291 my $file = shift;
2292
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002293 if (($anon_struct_union == 1) && ($type eq "") &&
2294 ($param eq "}")) {
2295 return; # ignore the ending }; from anon. struct/union
2296 }
2297
2298 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 my $param_name = $param;
2300 $param_name =~ s/\[.*//;
2301
Martin Waitza6d3fe72006-01-09 20:53:55 -08002302 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 {
Randy Dunlapced69092008-12-01 13:14:03 -08002304 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2305 $parameterdescs{$param} = "variable arguments";
2306 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 }
2308 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2309 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 $param="void";
2311 $parameterdescs{void} = "no arguments";
2312 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002313 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2314 # handle unnamed (anonymous) union or struct:
2315 {
2316 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002317 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002318 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002319 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002320 }
2321
Martin Waitza6d3fe72006-01-09 20:53:55 -08002322 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002323 # (but ignore ones starting with # as these are not parameters
2324 # but inline preprocessor statements);
2325 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002326 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002327 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2328
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 $parameterdescs{$param_name} = $undescribed;
2330
2331 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002332 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 "or member '$param' not " .
2334 "described in '$declaration_name'\n";
2335 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002336 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002337 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002339 }
2340 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002342 $param = xml_escape($param);
2343
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002344 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002345 # on @parameterlist;
2346 # this fixes a problem where check_sections() cannot find
2347 # a parameter like "addr[6 + 2]" because it actually appears
2348 # as "addr[6", "+", "2]" on the parameter list;
2349 # but it's better to maintain the param string unchanged for output,
2350 # so just weaken the string compare in check_sections() to ignore
2351 # "[blah" in a parameter string;
2352 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 push @parameterlist, $param;
2354 $parametertypes{$param} = $type;
2355}
2356
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002357sub check_sections($$$$$$) {
2358 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2359 my @sects = split ' ', $sectcheck;
2360 my @prms = split ' ', $prmscheck;
2361 my $err;
2362 my ($px, $sx);
2363 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2364
2365 foreach $sx (0 .. $#sects) {
2366 $err = 1;
2367 foreach $px (0 .. $#prms) {
2368 $prm_clean = $prms[$px];
2369 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002370 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002371 # ignore array size in a parameter string;
2372 # however, the original param string may contain
2373 # spaces, e.g.: addr[6 + 2]
2374 # and this appears in @prms as "addr[6" since the
2375 # parameter list is split at spaces;
2376 # hence just ignore "[..." for the sections check;
2377 $prm_clean =~ s/\[.*//;
2378
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002379 ##$prm_clean =~ s/^\**//;
2380 if ($prm_clean eq $sects[$sx]) {
2381 $err = 0;
2382 last;
2383 }
2384 }
2385 if ($err) {
2386 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002387 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002388 "Excess function parameter " .
2389 "'$sects[$sx]' " .
2390 "description in '$decl_name'\n";
2391 ++$warnings;
2392 } else {
2393 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002394 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002395 "Excess struct/union/enum/typedef member " .
2396 "'$sects[$sx]' " .
2397 "description in '$decl_name'\n";
2398 ++$warnings;
2399 }
2400 }
2401 }
2402 }
2403}
2404
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002406# Checks the section describing the return value of a function.
2407sub check_return_section {
2408 my $file = shift;
2409 my $declaration_name = shift;
2410 my $return_type = shift;
2411
2412 # Ignore an empty return type (It's a macro)
2413 # Ignore functions with a "void" return type. (But don't ignore "void *")
2414 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2415 return;
2416 }
2417
2418 if (!defined($sections{$section_return}) ||
2419 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002420 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002421 "No description found for return value of " .
2422 "'$declaration_name'\n";
2423 ++$warnings;
2424 }
2425}
2426
2427##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428# takes a function prototype and the name of the current file being
2429# processed and spits out all the details stored in the global
2430# arrays/hashes.
2431sub dump_function($$) {
2432 my $prototype = shift;
2433 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002434 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435
2436 $prototype =~ s/^static +//;
2437 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002438 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 $prototype =~ s/^inline +//;
2440 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002441 $prototype =~ s/^__inline +//;
2442 $prototype =~ s/^__always_inline +//;
2443 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002444 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002445 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002446 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002447 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002448 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002449 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002450 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451
2452 # Yes, this truly is vile. We are looking for:
2453 # 1. Return type (may be nothing if we're looking at a macro)
2454 # 2. Function name
2455 # 3. Function parameters.
2456 #
2457 # All the while we have to watch out for function pointer parameters
2458 # (which IIRC is what the two sections are for), C types (these
2459 # regexps don't even start to express all the possibilities), and
2460 # so on.
2461 #
2462 # If you mess with these regexps, it's a good idea to check that
2463 # the following functions' documentation still comes out right:
2464 # - parport_register_device (function pointer parameters)
2465 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002466 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002468 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2469 # This is an object-like macro, it has no return type and no parameter
2470 # list.
2471 # Function-like macros are not allowed to have spaces between
2472 # declaration_name and opening parenthesis (notice the \s+).
2473 $return_type = $1;
2474 $declaration_name = $2;
2475 $noret = 1;
2476 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2478 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2479 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002480 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2482 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2483 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2484 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2485 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2486 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2487 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2488 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002489 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2490 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002491 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2492 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 $return_type = $1;
2494 $declaration_name = $2;
2495 my $args = $3;
2496
2497 create_parameterlist($args, ',', $file);
2498 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002499 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 return;
2501 }
2502
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002503 my $prms = join " ", @parameterlist;
2504 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2505
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002506 # This check emits a lot of warnings at the moment, because many
2507 # functions don't have a 'Return' doc section. So until the number
2508 # of warnings goes sufficiently down, the check is only performed in
2509 # verbose mode.
2510 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002511 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002512 check_return_section($file, $declaration_name, $return_type);
2513 }
2514
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002515 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 'function',
2517 {'function' => $declaration_name,
2518 'module' => $modulename,
2519 'functiontype' => $return_type,
2520 'parameterlist' => \@parameterlist,
2521 'parameterdescs' => \%parameterdescs,
2522 'parametertypes' => \%parametertypes,
2523 'sectionlist' => \@sectionlist,
2524 'sections' => \%sections,
2525 'purpose' => $declaration_purpose
2526 });
2527}
2528
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529sub reset_state {
2530 $function = "";
2531 %constants = ();
2532 %parameterdescs = ();
2533 %parametertypes = ();
2534 @parameterlist = ();
2535 %sections = ();
2536 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002537 $sectcheck = "";
2538 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002540
Jani Nikula48af6062016-05-26 14:56:05 +03002541 $state = STATE_NORMAL;
2542 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543}
2544
Jason Baron56afb0f2009-04-30 13:29:36 -04002545sub tracepoint_munge($) {
2546 my $file = shift;
2547 my $tracepointname = 0;
2548 my $tracepointargs = 0;
2549
Jason Baron3a9089f2009-12-01 12:18:49 -05002550 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002551 $tracepointname = $1;
2552 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002553 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2554 $tracepointname = $1;
2555 }
2556 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2557 $tracepointname = $2;
2558 }
2559 $tracepointname =~ s/^\s+//; #strip leading whitespace
2560 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002561 $tracepointargs = $1;
2562 }
2563 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002564 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002565 "$prototype\n";
2566 } else {
2567 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2568 }
2569}
2570
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002571sub syscall_munge() {
2572 my $void = 0;
2573
2574 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2575## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2576 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2577 $void = 1;
2578## $prototype = "long sys_$1(void)";
2579 }
2580
2581 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2582 if ($prototype =~ m/long (sys_.*?),/) {
2583 $prototype =~ s/,/\(/;
2584 } elsif ($void) {
2585 $prototype =~ s/\)/\(void\)/;
2586 }
2587
2588 # now delete all of the odd-number commas in $prototype
2589 # so that arg types & arg names don't have a comma between them
2590 my $count = 0;
2591 my $len = length($prototype);
2592 if ($void) {
2593 $len = 0; # skip the for-loop
2594 }
2595 for (my $ix = 0; $ix < $len; $ix++) {
2596 if (substr($prototype, $ix, 1) eq ',') {
2597 $count++;
2598 if ($count % 2 == 1) {
2599 substr($prototype, $ix, 1) = ' ';
2600 }
2601 }
2602 }
2603}
2604
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002605sub process_state3_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 my $x = shift;
2607 my $file = shift;
2608
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002609 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2610
Randy Dunlap890c78c2008-10-25 17:06:43 -07002611 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 # do nothing
2613 }
2614 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002615 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002617
Randy Dunlap890c78c2008-10-25 17:06:43 -07002618 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002619 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2621 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002622 if ($prototype =~ /SYSCALL_DEFINE/) {
2623 syscall_munge();
2624 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002625 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2626 $prototype =~ /DEFINE_SINGLE_EVENT/)
2627 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002628 tracepoint_munge($file);
2629 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002630 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 reset_state();
2632 }
2633}
2634
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002635sub process_state3_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 my $x = shift;
2637 my $file = shift;
2638
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2640 $x =~ s@^\s+@@gos; # strip leading spaces
2641 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002642 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2643
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 if ($x =~ /^#/) {
2645 # To distinguish preprocessor directive from regular declaration later.
2646 $x .= ";";
2647 }
2648
2649 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002650 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 $prototype .= $1 . $2;
2652 ($2 eq '{') && $brcount++;
2653 ($2 eq '}') && $brcount--;
2654 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002655 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002657 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 }
2659 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002660 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 $prototype .= $x;
2662 last;
2663 }
2664 }
2665}
2666
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002667# xml_escape: replace <, >, and & in the text stream;
2668#
2669# however, formatting controls that are generated internally/locally in the
2670# kernel-doc script are not escaped here; instead, they begin life like
2671# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2672# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2673# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674sub xml_escape($) {
2675 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002676 if (($output_mode eq "text") || ($output_mode eq "man")) {
2677 return $text;
2678 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 $text =~ s/\&/\\\\\\amp;/g;
2680 $text =~ s/\</\\\\\\lt;/g;
2681 $text =~ s/\>/\\\\\\gt;/g;
2682 return $text;
2683}
2684
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002685# xml_unescape: reverse the effects of xml_escape
2686sub xml_unescape($) {
2687 my $text = shift;
2688 if (($output_mode eq "text") || ($output_mode eq "man")) {
2689 return $text;
2690 }
2691 $text =~ s/\\\\\\amp;/\&/g;
2692 $text =~ s/\\\\\\lt;/</g;
2693 $text =~ s/\\\\\\gt;/>/g;
2694 return $text;
2695}
2696
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002697# convert local escape strings to html
2698# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2699sub local_unescape($) {
2700 my $text = shift;
2701 if (($output_mode eq "text") || ($output_mode eq "man")) {
2702 return $text;
2703 }
2704 $text =~ s/\\\\\\\\lt:/</g;
2705 $text =~ s/\\\\\\\\gt:/>/g;
2706 return $text;
2707}
2708
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002710 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 my $identifier;
2712 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002713 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002714 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002716 my ($orig_file) = @_;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717
Randy Dunlap2283a112005-07-07 15:39:26 -07002718 if (defined($ENV{'SRCTREE'})) {
Ben Hutchings68f86662015-09-01 23:48:49 +01002719 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002720 }
2721 else {
Ben Hutchings68f86662015-09-01 23:48:49 +01002722 $file = $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002723 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 if (defined($source_map{$file})) {
2725 $file = $source_map{$file};
2726 }
2727
2728 if (!open(IN,"<$file")) {
2729 print STDERR "Error: Cannot open file $file\n";
2730 ++$errors;
2731 return;
2732 }
2733
Jani Nikula86ae2e32016-01-21 13:05:22 +02002734 # two passes for -export and -internal
Jani Nikulab6c3f452016-05-29 22:19:35 +03002735 if ($output_selection == OUTPUT_EXPORTED ||
2736 $output_selection == OUTPUT_INTERNAL) {
Jani Nikula86ae2e32016-01-21 13:05:22 +02002737 while (<IN>) {
2738 if (/$export_symbol/o) {
2739 $function_table{$2} = 1;
2740 }
2741 }
2742 seek(IN, 0, 0);
2743 }
2744
Ilya Dryomova9e73142010-02-26 13:05:47 -08002745 $. = 1;
2746
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 $section_counter = 0;
2748 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002749 while (s/\\\s*$//) {
2750 $_ .= <IN>;
2751 }
Jani Nikula48af6062016-05-26 14:56:05 +03002752 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002754 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002755 $in_doc_sect = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756 }
Jani Nikula48af6062016-05-26 14:56:05 +03002757 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002759 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 $contents = "";
2761 if ( $1 eq "" ) {
2762 $section = $section_intro;
2763 } else {
2764 $section = $1;
2765 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002766 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 elsif (/$doc_decl/o) {
2768 $identifier = $1;
2769 if (/\s*([\w\s]+?)\s*-/) {
2770 $identifier = $1;
2771 }
2772
Jani Nikula48af6062016-05-26 14:56:05 +03002773 $state = STATE_FIELD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002775 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002776 $descr= $1;
2777 $descr =~ s/^\s*//;
2778 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002779 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002780 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002781 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 } else {
2783 $declaration_purpose = "";
2784 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002785
2786 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002787 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002788 print STDERR $_;
2789 ++$warnings;
2790 }
2791
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 if ($identifier =~ m/^struct/) {
2793 $decl_type = 'struct';
2794 } elsif ($identifier =~ m/^union/) {
2795 $decl_type = 'union';
2796 } elsif ($identifier =~ m/^enum/) {
2797 $decl_type = 'enum';
2798 } elsif ($identifier =~ m/^typedef/) {
2799 $decl_type = 'typedef';
2800 } else {
2801 $decl_type = 'function';
2802 }
2803
2804 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002805 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 }
2807 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002808 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809 " - I thought it was a doc line\n";
2810 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002811 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 }
Jani Nikula48af6062016-05-26 14:56:05 +03002813 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 if (/$doc_sect/o) {
2815 $newsection = $1;
2816 $newcontents = $2;
2817
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002818 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002819 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002820 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002821 ++$warnings;
2822 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002823 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 $section = $section_default;
2825 }
2826
Randy Dunlap850622d2006-06-25 05:48:55 -07002827 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002828 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 $contents = $newcontents;
2830 if ($contents ne "") {
Randy Dunlap27205742006-10-11 01:22:12 -07002831 while ((substr($contents, 0, 1) eq " ") ||
2832 substr($contents, 0, 1) eq "\t") {
2833 $contents = substr($contents, 1);
Randy Dunlap05189492006-06-25 05:47:47 -07002834 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 $contents .= "\n";
2836 }
2837 $section = $newsection;
2838 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002839 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002840 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 $section = $section_default;
2842 $contents = "";
2843 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002844 # look for doc_com + <text> + doc_end:
2845 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002846 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002847 ++$warnings;
2848 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849
2850 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002851 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002853# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 } elsif (/$doc_content/) {
2855 # miguel-style comment kludge, look for blank lines after
2856 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002857 if ($1 eq "") {
2858 if ($section =~ m/^@/ || $section eq $section_context) {
2859 dump_section($file, $section, xml_escape($contents));
2860 $section = $section_default;
2861 $contents = "";
2862 } else {
2863 $contents .= "\n";
2864 }
2865 $in_purpose = 0;
2866 } elsif ($in_purpose == 1) {
2867 # Continued declaration purpose
2868 chomp($declaration_purpose);
2869 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002870 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002872 $contents .= $1 . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 }
2874 } else {
2875 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002876 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 ++$warnings;
2878 }
Jani Nikula48af6062016-05-26 14:56:05 +03002879 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002880 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03002881 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002882 $section = $1;
2883 $contents = $2;
2884 if ($contents ne "") {
2885 while ((substr($contents, 0, 1) eq " ") ||
2886 substr($contents, 0, 1) eq "\t") {
2887 $contents = substr($contents, 1);
2888 }
2889 $contents .= "\n";
2890 }
Jani Nikula48af6062016-05-26 14:56:05 +03002891 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002892 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03002893 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002894 if (($contents ne "") && ($contents ne "\n")) {
2895 dump_section($file, $section, xml_escape($contents));
2896 $section = $section_default;
2897 $contents = "";
2898 }
Jani Nikula48af6062016-05-26 14:56:05 +03002899 $state = STATE_PROTO;
2900 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002901 # Regular text
2902 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03002903 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002904 $contents .= $1 . "\n";
Jani Nikula48af6062016-05-26 14:56:05 +03002905 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
2906 $inline_doc_state = STATE_INLINE_ERROR;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002907 print STDERR "Warning(${file}:$.): ";
2908 print STDERR "Incorrect use of kernel-doc format: $_";
2909 ++$warnings;
2910 }
2911 }
Jani Nikula48af6062016-05-26 14:56:05 +03002912 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
2913 if (/$doc_inline_start/) {
2914 $state = STATE_INLINE;
2915 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002916 } elsif ($decl_type eq 'function') {
Randy Dunlap3c308792007-05-08 00:24:39 -07002917 process_state3_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -07002919 process_state3_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 }
Jani Nikula48af6062016-05-26 14:56:05 +03002921 } elsif ($state == STATE_DOCBLOCK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 # Documentation block
Randy Dunlap3c308792007-05-08 00:24:39 -07002923 if (/$doc_block/) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002924 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 $contents = "";
2926 $function = "";
2927 %constants = ();
2928 %parameterdescs = ();
2929 %parametertypes = ();
2930 @parameterlist = ();
2931 %sections = ();
2932 @sectionlist = ();
2933 $prototype = "";
2934 if ( $1 eq "" ) {
2935 $section = $section_intro;
2936 } else {
2937 $section = $1;
2938 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002939 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 elsif (/$doc_end/)
2941 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002942 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 $contents = "";
2944 $function = "";
2945 %constants = ();
2946 %parameterdescs = ();
2947 %parametertypes = ();
2948 @parameterlist = ();
2949 %sections = ();
2950 @sectionlist = ();
2951 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002952 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 }
2954 elsif (/$doc_content/)
2955 {
2956 if ( $1 eq "" )
2957 {
2958 $contents .= $blankline;
2959 }
2960 else
2961 {
2962 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002963 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002964 }
2965 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 }
2967 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002968 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002969 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08002970 print STDERR " Was looking for '$_'.\n" for keys %function_table;
2971 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 if ($output_mode eq "xml") {
2973 # The template wants at least one RefEntry here; make one.
2974 print "<refentry>\n";
2975 print " <refnamediv>\n";
2976 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01002977 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 print " </refname>\n";
2979 print " <refpurpose>\n";
2980 print " Document generation inconsistency\n";
2981 print " </refpurpose>\n";
2982 print " </refnamediv>\n";
2983 print " <refsect1>\n";
2984 print " <title>\n";
2985 print " Oops\n";
2986 print " </title>\n";
2987 print " <warning>\n";
2988 print " <para>\n";
2989 print " The template for this document tried to insert\n";
2990 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01002991 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 print " but none was found.\n";
2993 print " This dummy section is inserted to allow\n";
2994 print " generation to continue.\n";
2995 print " </para>\n";
2996 print " </warning>\n";
2997 print " </refsect1>\n";
2998 print "</refentry>\n";
2999 }
3000 }
3001}
Randy Dunlap8484baa2011-01-05 16:28:43 -08003002
3003
3004$kernelversion = get_kernel_version();
3005
3006# generate a sequence of code that will splice in highlighting information
3007# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02003008for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03003009 my $pattern = $highlights[$k][0];
3010 my $result = $highlights[$k][1];
3011# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
3012 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08003013}
3014
3015# Read the file that maps relative names to absolute names for
3016# separate source and object directories and for shadow trees.
3017if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3018 my ($relname, $absname);
3019 while(<SOURCE_MAP>) {
3020 chop();
3021 ($relname, $absname) = (split())[0..1];
3022 $relname =~ s:^/+::;
3023 $source_map{$relname} = $absname;
3024 }
3025 close(SOURCE_MAP);
3026}
3027
3028foreach (@ARGV) {
3029 chomp;
3030 process_file($_);
3031}
3032if ($verbose && $errors) {
3033 print STDERR "$errors errors\n";
3034}
3035if ($verbose && $warnings) {
3036 print STDERR "$warnings warnings\n";
3037}
3038
3039exit($errors);