blob: e7aa792e7f1b29362b72ac45aaa0719efe1449e8 [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]+)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
216# Output conversion substitutions.
217# One for each output format
218
219# these work fairly well
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300220my @highlights_html = (
221 [$type_constant, "<i>\$1</i>"],
222 [$type_func, "<b>\$1</b>"],
223 [$type_struct_xml, "<i>\$1</i>"],
224 [$type_env, "<b><i>\$1</i></b>"],
225 [$type_param, "<tt><b>\$1</b></tt>"]
226 );
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700227my $local_lt = "\\\\\\\\lt:";
228my $local_gt = "\\\\\\\\gt:";
229my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
Dan Luedtke1b40c192012-08-12 10:46:15 +0200231# html version 5
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300232my @highlights_html5 = (
233 [$type_constant, "<span class=\"const\">\$1</span>"],
234 [$type_func, "<span class=\"func\">\$1</span>"],
235 [$type_struct_xml, "<span class=\"struct\">\$1</span>"],
236 [$type_env, "<span class=\"env\">\$1</span>"],
237 [$type_param, "<span class=\"param\">\$1</span>]"]
238 );
Dan Luedtke1b40c192012-08-12 10:46:15 +0200239my $blankline_html5 = $local_lt . "br /" . $local_gt;
240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241# XML, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300242my @highlights_xml = (
243 ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
244 [$type_constant, "<constant>\$1</constant>"],
245 [$type_struct_xml, "<structname>\$1</structname>"],
246 [$type_param, "<parameter>\$1</parameter>"],
247 [$type_func, "<function>\$1</function>"],
248 [$type_env, "<envar>\$1</envar>"]
249 );
Johannes Berg5c98fc02007-10-24 15:08:48 -0700250my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
252# gnome, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300253my @highlights_gnome = (
254 [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
255 [$type_func, "<function>\$1</function>"],
256 [$type_struct, "<structname>\$1</structname>"],
257 [$type_env, "<envar>\$1</envar>"],
258 [$type_param, "<parameter>\$1</parameter>" ]
259 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260my $blankline_gnome = "</para><para>\n";
261
262# these are pretty rough
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300263my @highlights_man = (
264 [$type_constant, "\$1"],
265 [$type_func, "\\\\fB\$1\\\\fP"],
266 [$type_struct, "\\\\fI\$1\\\\fP"],
267 [$type_param, "\\\\fI\$1\\\\fP"]
268 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269my $blankline_man = "";
270
271# text-mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300272my @highlights_text = (
273 [$type_constant, "\$1"],
274 [$type_func, "\$1"],
275 [$type_struct, "\$1"],
276 [$type_param, "\$1"]
277 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278my $blankline_text = "";
279
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300280# rst-mode
281my @highlights_rst = (
282 [$type_constant, "``\$1``"],
Jani Nikulaa19bce62016-05-26 11:28:16 +0300283 [$type_func, "\\:c\\:func\\:`\$1()`"],
Jani Nikula62850972016-05-12 16:15:38 +0300284 [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
285 [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
Jani Nikulaa7291e72016-05-26 13:57:06 +0300286 # in rst this can refer to any type
287 [$type_struct, "\\:c\\:type\\:`\$1`"],
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300288 [$type_param, "**\$1**"]
289 );
290my $blankline_rst = "\n";
291
Johannes Bergeda603f2010-09-11 15:55:22 -0700292# list mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300293my @highlights_list = (
294 [$type_constant, "\$1"],
295 [$type_func, "\$1"],
296 [$type_struct, "\$1"],
297 [$type_param, "\$1"]
298 );
Johannes Bergeda603f2010-09-11 15:55:22 -0700299my $blankline_list = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301# read arguments
Randy Dunlapb9d973282009-06-09 08:50:38 -0700302if ($#ARGV == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 usage();
304}
305
Randy Dunlap8484baa2011-01-05 16:28:43 -0800306my $kernelversion;
307my $dohighlight = "";
308
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309my $verbose = 0;
310my $output_mode = "man";
Daniel Santose314ba32012-10-04 17:15:08 -0700311my $output_preformatted = 0;
Johannes Berg4b445952007-10-24 15:08:48 -0700312my $no_doc_sections = 0;
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300313my @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314my $blankline = $blankline_man;
315my $modulename = "Kernel API";
Jani Nikulab6c3f452016-05-29 22:19:35 +0300316
317use constant {
318 OUTPUT_ALL => 0, # output all symbols and doc sections
319 OUTPUT_INCLUDE => 1, # output only specified symbols
320 OUTPUT_EXCLUDE => 2, # output everything except specified symbols
321 OUTPUT_EXPORTED => 3, # output exported symbols
322 OUTPUT_INTERNAL => 4, # output non-exported symbols
323};
324my $output_selection = OUTPUT_ALL;
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100325my $show_not_found = 0;
326
327my @build_time;
328if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
329 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
330 @build_time = gmtime($seconds);
331} else {
332 @build_time = localtime;
333}
334
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800335my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
336 'July', 'August', 'September', 'October',
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100337 'November', 'December')[$build_time[4]] .
338 " " . ($build_time[5]+1900);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Randy Dunlap8484baa2011-01-05 16:28:43 -0800340# Essentially these are globals.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700341# They probably want to be tidied up, made more localised or something.
342# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343# could cause "use of undefined value" or other bugs.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700344my ($function, %function_table, %parametertypes, $declaration_purpose);
345my ($type, $declaration_name, $return_type);
Ilya Dryomov1c32fd02010-02-26 13:06:03 -0800346my ($newsection, $newcontents, $prototype, $brcount, %source_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700348if (defined($ENV{'KBUILD_VERBOSE'})) {
349 $verbose = "$ENV{'KBUILD_VERBOSE'}";
350}
351
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800352# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
354# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
355# We keep track of number of generated entries and generate a dummy
356# if needs be to ensure the expanded template can be postprocessed
357# into html.
358my $section_counter = 0;
359
360my $lineprefix="";
361
Jani Nikula48af6062016-05-26 14:56:05 +0300362# Parser states
363use constant {
364 STATE_NORMAL => 0, # normal code
365 STATE_NAME => 1, # looking for function name
366 STATE_FIELD => 2, # scanning field start
367 STATE_PROTO => 3, # scanning prototype
368 STATE_DOCBLOCK => 4, # documentation block
369 STATE_INLINE => 5, # gathering documentation outside main block
370};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700372my $in_doc_sect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Jani Nikula48af6062016-05-26 14:56:05 +0300374# Inline documentation state
375use constant {
376 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
377 STATE_INLINE_NAME => 1, # looking for member name (@foo:)
378 STATE_INLINE_TEXT => 2, # looking for member documentation
379 STATE_INLINE_END => 3, # done
380 STATE_INLINE_ERROR => 4, # error - Comment without header was found.
381 # Spit a warning as it's not
382 # proper kernel-doc and ignore the rest.
383};
384my $inline_doc_state;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300385
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386#declaration types: can be
387# 'function', 'struct', 'union', 'enum', 'typedef'
388my $decl_type;
389
390my $doc_special = "\@\%\$\&";
391
392my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
393my $doc_end = '\*/';
394my $doc_com = '\s*\*\s*';
Daniel Santos12ae6772012-10-04 17:15:10 -0700395my $doc_com_body = '\s*\* ?';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700396my $doc_decl = $doc_com . '(\w+)';
397my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700398my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700399my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Jani Nikula48af6062016-05-26 14:56:05 +0300400my $doc_inline_start = '^\s*/\*\*\s*$';
401my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
402my $doc_inline_end = '^\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200403my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404
405my %constants;
406my %parameterdescs;
407my @parameterlist;
408my %sections;
409my @sectionlist;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800410my $sectcheck;
411my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413my $contents = "";
414my $section_default = "Description"; # default section
415my $section_intro = "Introduction";
416my $section = $section_default;
417my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100418my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
420my $undescribed = "-- undescribed --";
421
422reset_state();
423
424while ($ARGV[0] =~ m/^-(.*)/) {
425 my $cmd = shift @ARGV;
426 if ($cmd eq "-html") {
427 $output_mode = "html";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300428 @highlights = @highlights_html;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200430 } elsif ($cmd eq "-html5") {
431 $output_mode = "html5";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300432 @highlights = @highlights_html5;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200433 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 } elsif ($cmd eq "-man") {
435 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300436 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 $blankline = $blankline_man;
438 } elsif ($cmd eq "-text") {
439 $output_mode = "text";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300440 @highlights = @highlights_text;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 $blankline = $blankline_text;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300442 } elsif ($cmd eq "-rst") {
443 $output_mode = "rst";
444 @highlights = @highlights_rst;
445 $blankline = $blankline_rst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 } elsif ($cmd eq "-docbook") {
447 $output_mode = "xml";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300448 @highlights = @highlights_xml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700450 } elsif ($cmd eq "-list") {
451 $output_mode = "list";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300452 @highlights = @highlights_list;
Johannes Bergeda603f2010-09-11 15:55:22 -0700453 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 } elsif ($cmd eq "-gnome") {
455 $output_mode = "gnome";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300456 @highlights = @highlights_gnome;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 $blankline = $blankline_gnome;
458 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
459 $modulename = shift @ARGV;
460 } elsif ($cmd eq "-function") { # to only output specific functions
Jani Nikulab6c3f452016-05-29 22:19:35 +0300461 $output_selection = OUTPUT_INCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 $function = shift @ARGV;
463 $function_table{$function} = 1;
Jani Nikulab6c3f452016-05-29 22:19:35 +0300464 } elsif ($cmd eq "-nofunction") { # output all except specific functions
465 $output_selection = OUTPUT_EXCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 $function = shift @ARGV;
467 $function_table{$function} = 1;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200468 } elsif ($cmd eq "-export") { # only exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300469 $output_selection = OUTPUT_EXPORTED;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200470 %function_table = ()
471 } elsif ($cmd eq "-internal") { # only non-exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300472 $output_selection = OUTPUT_INTERNAL;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200473 %function_table = ()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 } elsif ($cmd eq "-v") {
475 $verbose = 1;
476 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
477 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700478 } elsif ($cmd eq '-no-doc-sections') {
479 $no_doc_sections = 1;
Johannes Berge946c43a2013-11-12 15:11:12 -0800480 } elsif ($cmd eq '-show-not-found') {
481 $show_not_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 }
483}
484
Randy Dunlap8484baa2011-01-05 16:28:43 -0800485# continue execution near EOF;
486
Borislav Petkov53f049f2007-05-08 00:30:54 -0700487# get kernel version from env
488sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700489 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700490
491 if (defined($ENV{'KERNELVERSION'})) {
492 $version = $ENV{'KERNELVERSION'};
493 }
494 return $version;
495}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497##
498# dumps section contents to arrays/hashes intended for that purpose.
499#
500sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700501 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 my $name = shift;
503 my $contents = join "\n", @_;
504
505 if ($name =~ m/$type_constant/) {
506 $name = $1;
507# print STDERR "constant section '$1' = '$contents'\n";
508 $constants{$name} = $contents;
509 } elsif ($name =~ m/$type_param/) {
510# print STDERR "parameter def '$1' = '$contents'\n";
511 $name = $1;
512 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800513 $sectcheck = $sectcheck . $name . " ";
Randy Dunlapced69092008-12-01 13:14:03 -0800514 } elsif ($name eq "@\.\.\.") {
515# print STDERR "parameter def '...' = '$contents'\n";
516 $name = "...";
517 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800518 $sectcheck = $sectcheck . $name . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 } else {
520# print STDERR "other section '$name' = '$contents'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700521 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Bart Van Assched40e1e62015-09-04 15:43:21 -0700522 print STDERR "${file}:$.: error: duplicate section name '$name'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700523 ++$errors;
524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 $sections{$name} = $contents;
526 push @sectionlist, $name;
527 }
528}
529
530##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700531# dump DOC: section after checking that it should go out
532#
533sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700534 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700535 my $name = shift;
536 my $contents = join "\n", @_;
537
Johannes Berg4b445952007-10-24 15:08:48 -0700538 if ($no_doc_sections) {
539 return;
540 }
541
Jani Nikulab6c3f452016-05-29 22:19:35 +0300542 if (($output_selection == OUTPUT_ALL) ||
543 ($output_selection == OUTPUT_INCLUDE &&
544 defined($function_table{$name})) ||
545 ($output_selection == OUTPUT_EXCLUDE &&
546 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700547 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700548 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700549 output_blockhead({'sectionlist' => \@sectionlist,
550 'sections' => \%sections,
551 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300552 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700553 }
554}
555
556##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557# output function
558#
559# parameterdescs, a hash.
560# function => "function name"
561# parameterlist => @list of parameters
562# parameterdescs => %parameter descriptions
563# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800564# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800565#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
567sub output_highlight {
568 my $contents = join "\n",@_;
569 my $line;
570
571# DEBUG
572# if (!defined $contents) {
573# use Carp;
574# confess "output_highlight got called with no args?\n";
575# }
576
Dan Luedtke1b40c192012-08-12 10:46:15 +0200577 if ($output_mode eq "html" || $output_mode eq "html5" ||
578 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700579 $contents = local_unescape($contents);
580 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800581 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700582 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700583# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 eval $dohighlight;
585 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700586# print STDERR "contents af:$contents\n";
587
Dan Luedtke1b40c192012-08-12 10:46:15 +0200588# strip whitespaces when generating html5
589 if ($output_mode eq "html5") {
590 $contents =~ s/^\s+//;
591 $contents =~ s/\s+$//;
592 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700594 if (! $output_preformatted) {
595 $line =~ s/^\s*//;
596 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700597 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700598 if (! $output_preformatted) {
599 print $lineprefix, local_unescape($blankline);
600 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700602 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700603 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
604 print "\\&$line";
605 } else {
606 print $lineprefix, $line;
607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 }
609 print "\n";
610 }
611}
612
Dan Luedtke1b40c192012-08-12 10:46:15 +0200613# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614sub output_section_html(%) {
615 my %args = %{$_[0]};
616 my $section;
617
618 foreach $section (@{$args{'sectionlist'}}) {
619 print "<h3>$section</h3>\n";
620 print "<blockquote>\n";
621 output_highlight($args{'sections'}{$section});
622 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800623 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624}
625
626# output enum in html
627sub output_enum_html(%) {
628 my %args = %{$_[0]};
629 my ($parameter);
630 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700631 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632
Randy Dunlapb9d973282009-06-09 08:50:38 -0700633 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 $count = 0;
635 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700636 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 if ($count != $#{$args{'parameterlist'}}) {
638 $count++;
639 print ",\n";
640 }
641 print "<br>";
642 }
643 print "};<br>\n";
644
645 print "<h3>Constants</h3>\n";
646 print "<dl>\n";
647 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700648 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 print "<dd>";
650 output_highlight($args{'parameterdescs'}{$parameter});
651 }
652 print "</dl>\n";
653 output_section_html(@_);
654 print "<hr>\n";
655}
656
Randy Dunlapd28bee02006-02-01 03:06:57 -0800657# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658sub output_typedef_html(%) {
659 my %args = %{$_[0]};
660 my ($parameter);
661 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700662 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Randy Dunlapb9d973282009-06-09 08:50:38 -0700664 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 output_section_html(@_);
666 print "<hr>\n";
667}
668
669# output struct in html
670sub output_struct_html(%) {
671 my %args = %{$_[0]};
672 my ($parameter);
673
Randy Dunlapb9d973282009-06-09 08:50:38 -0700674 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
675 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 foreach $parameter (@{$args{'parameterlist'}}) {
677 if ($parameter =~ /^#/) {
678 print "$parameter<br>\n";
679 next;
680 }
681 my $parameter_name = $parameter;
682 $parameter_name =~ s/\[.*//;
683
Randy Dunlap3c308792007-05-08 00:24:39 -0700684 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 $type = $args{'parametertypes'}{$parameter};
686 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
687 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700688 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700690 # bitfield
691 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700693 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 }
695 }
696 print "};<br>\n";
697
698 print "<h3>Members</h3>\n";
699 print "<dl>\n";
700 foreach $parameter (@{$args{'parameterlist'}}) {
701 ($parameter =~ /^#/) && next;
702
703 my $parameter_name = $parameter;
704 $parameter_name =~ s/\[.*//;
705
Randy Dunlap3c308792007-05-08 00:24:39 -0700706 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700707 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 print "<dd>";
709 output_highlight($args{'parameterdescs'}{$parameter_name});
710 }
711 print "</dl>\n";
712 output_section_html(@_);
713 print "<hr>\n";
714}
715
716# output function in html
717sub output_function_html(%) {
718 my %args = %{$_[0]};
719 my ($parameter, $section);
720 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Randy Dunlapb9d973282009-06-09 08:50:38 -0700722 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
723 print "<i>" . $args{'functiontype'} . "</i>\n";
724 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 print "(";
726 $count = 0;
727 foreach $parameter (@{$args{'parameterlist'}}) {
728 $type = $args{'parametertypes'}{$parameter};
729 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
730 # pointer-to-function
731 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
732 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700733 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 }
735 if ($count != $#{$args{'parameterlist'}}) {
736 $count++;
737 print ",\n";
738 }
739 }
740 print ")\n";
741
742 print "<h3>Arguments</h3>\n";
743 print "<dl>\n";
744 foreach $parameter (@{$args{'parameterlist'}}) {
745 my $parameter_name = $parameter;
746 $parameter_name =~ s/\[.*//;
747
Randy Dunlap3c308792007-05-08 00:24:39 -0700748 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700749 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 print "<dd>";
751 output_highlight($args{'parameterdescs'}{$parameter_name});
752 }
753 print "</dl>\n";
754 output_section_html(@_);
755 print "<hr>\n";
756}
757
Johannes Bergb112e0f2007-10-24 15:08:48 -0700758# output DOC: block header in html
759sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 my %args = %{$_[0]};
761 my ($parameter, $section);
762 my $count;
763
764 foreach $section (@{$args{'sectionlist'}}) {
765 print "<h3>$section</h3>\n";
766 print "<ul>\n";
767 output_highlight($args{'sections'}{$section});
768 print "</ul>\n";
769 }
770 print "<hr>\n";
771}
772
Dan Luedtke1b40c192012-08-12 10:46:15 +0200773# output sections in html5
774sub output_section_html5(%) {
775 my %args = %{$_[0]};
776 my $section;
777
778 foreach $section (@{$args{'sectionlist'}}) {
779 print "<section>\n";
780 print "<h1>$section</h1>\n";
781 print "<p>\n";
782 output_highlight($args{'sections'}{$section});
783 print "</p>\n";
784 print "</section>\n";
785 }
786}
787
788# output enum in html5
789sub output_enum_html5(%) {
790 my %args = %{$_[0]};
791 my ($parameter);
792 my $count;
793 my $html5id;
794
795 $html5id = $args{'enum'};
796 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
797 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
798 print "<h1>enum " . $args{'enum'} . "</h1>\n";
799 print "<ol class=\"code\">\n";
800 print "<li>";
801 print "<span class=\"keyword\">enum</span> ";
802 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
803 print "</li>\n";
804 $count = 0;
805 foreach $parameter (@{$args{'parameterlist'}}) {
806 print "<li class=\"indent\">";
807 print "<span class=\"param\">" . $parameter . "</span>";
808 if ($count != $#{$args{'parameterlist'}}) {
809 $count++;
810 print ",";
811 }
812 print "</li>\n";
813 }
814 print "<li>};</li>\n";
815 print "</ol>\n";
816
817 print "<section>\n";
818 print "<h1>Constants</h1>\n";
819 print "<dl>\n";
820 foreach $parameter (@{$args{'parameterlist'}}) {
821 print "<dt>" . $parameter . "</dt>\n";
822 print "<dd>";
823 output_highlight($args{'parameterdescs'}{$parameter});
824 print "</dd>\n";
825 }
826 print "</dl>\n";
827 print "</section>\n";
828 output_section_html5(@_);
829 print "</article>\n";
830}
831
832# output typedef in html5
833sub output_typedef_html5(%) {
834 my %args = %{$_[0]};
835 my ($parameter);
836 my $count;
837 my $html5id;
838
839 $html5id = $args{'typedef'};
840 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
841 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
842 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
843
844 print "<ol class=\"code\">\n";
845 print "<li>";
846 print "<span class=\"keyword\">typedef</span> ";
847 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
848 print "</li>\n";
849 print "</ol>\n";
850 output_section_html5(@_);
851 print "</article>\n";
852}
853
854# output struct in html5
855sub output_struct_html5(%) {
856 my %args = %{$_[0]};
857 my ($parameter);
858 my $html5id;
859
860 $html5id = $args{'struct'};
861 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
862 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
863 print "<hgroup>\n";
864 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
865 print "<h2>". $args{'purpose'} . "</h2>\n";
866 print "</hgroup>\n";
867 print "<ol class=\"code\">\n";
868 print "<li>";
869 print "<span class=\"type\">" . $args{'type'} . "</span> ";
870 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
871 print "</li>\n";
872 foreach $parameter (@{$args{'parameterlist'}}) {
873 print "<li class=\"indent\">";
874 if ($parameter =~ /^#/) {
875 print "<span class=\"param\">" . $parameter ."</span>\n";
876 print "</li>\n";
877 next;
878 }
879 my $parameter_name = $parameter;
880 $parameter_name =~ s/\[.*//;
881
882 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
883 $type = $args{'parametertypes'}{$parameter};
884 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
885 # pointer-to-function
886 print "<span class=\"type\">$1</span> ";
887 print "<span class=\"param\">$parameter</span>";
888 print "<span class=\"type\">)</span> ";
889 print "(<span class=\"args\">$2</span>);";
890 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
891 # bitfield
892 print "<span class=\"type\">$1</span> ";
893 print "<span class=\"param\">$parameter</span>";
894 print "<span class=\"bits\">$2</span>;";
895 } else {
896 print "<span class=\"type\">$type</span> ";
897 print "<span class=\"param\">$parameter</span>;";
898 }
899 print "</li>\n";
900 }
901 print "<li>};</li>\n";
902 print "</ol>\n";
903
904 print "<section>\n";
905 print "<h1>Members</h1>\n";
906 print "<dl>\n";
907 foreach $parameter (@{$args{'parameterlist'}}) {
908 ($parameter =~ /^#/) && next;
909
910 my $parameter_name = $parameter;
911 $parameter_name =~ s/\[.*//;
912
913 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
914 print "<dt>" . $parameter . "</dt>\n";
915 print "<dd>";
916 output_highlight($args{'parameterdescs'}{$parameter_name});
917 print "</dd>\n";
918 }
919 print "</dl>\n";
920 print "</section>\n";
921 output_section_html5(@_);
922 print "</article>\n";
923}
924
925# output function in html5
926sub output_function_html5(%) {
927 my %args = %{$_[0]};
928 my ($parameter, $section);
929 my $count;
930 my $html5id;
931
932 $html5id = $args{'function'};
933 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
934 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
935 print "<hgroup>\n";
936 print "<h1>" . $args{'function'} . "</h1>";
937 print "<h2>" . $args{'purpose'} . "</h2>\n";
938 print "</hgroup>\n";
939 print "<ol class=\"code\">\n";
940 print "<li>";
941 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
942 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
943 print "</li>";
944 $count = 0;
945 foreach $parameter (@{$args{'parameterlist'}}) {
946 print "<li class=\"indent\">";
947 $type = $args{'parametertypes'}{$parameter};
948 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
949 # pointer-to-function
950 print "<span class=\"type\">$1</span> ";
951 print "<span class=\"param\">$parameter</span>";
952 print "<span class=\"type\">)</span> ";
953 print "(<span class=\"args\">$2</span>)";
954 } else {
955 print "<span class=\"type\">$type</span> ";
956 print "<span class=\"param\">$parameter</span>";
957 }
958 if ($count != $#{$args{'parameterlist'}}) {
959 $count++;
960 print ",";
961 }
962 print "</li>\n";
963 }
964 print "<li>)</li>\n";
965 print "</ol>\n";
966
967 print "<section>\n";
968 print "<h1>Arguments</h1>\n";
969 print "<p>\n";
970 print "<dl>\n";
971 foreach $parameter (@{$args{'parameterlist'}}) {
972 my $parameter_name = $parameter;
973 $parameter_name =~ s/\[.*//;
974
975 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
976 print "<dt>" . $parameter . "</dt>\n";
977 print "<dd>";
978 output_highlight($args{'parameterdescs'}{$parameter_name});
979 print "</dd>\n";
980 }
981 print "</dl>\n";
982 print "</section>\n";
983 output_section_html5(@_);
984 print "</article>\n";
985}
986
987# output DOC: block header in html5
988sub output_blockhead_html5(%) {
989 my %args = %{$_[0]};
990 my ($parameter, $section);
991 my $count;
992 my $html5id;
993
994 foreach $section (@{$args{'sectionlist'}}) {
995 $html5id = $section;
996 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
997 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
998 print "<h1>$section</h1>\n";
999 print "<p>\n";
1000 output_highlight($args{'sections'}{$section});
1001 print "</p>\n";
1002 }
1003 print "</article>\n";
1004}
1005
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006sub output_section_xml(%) {
1007 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001008 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 # print out each section
1010 $lineprefix=" ";
1011 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001012 print "<refsect1>\n";
1013 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001015 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001016 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001017 } else {
1018 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 }
1020 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001021 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001023 print "</programlisting></informalexample>\n";
1024 } else {
1025 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001027 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 }
1029}
1030
1031# output function in XML DocBook
1032sub output_function_xml(%) {
1033 my %args = %{$_[0]};
1034 my ($parameter, $section);
1035 my $count;
1036 my $id;
1037
Randy Dunlapb9d973282009-06-09 08:50:38 -07001038 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 $id =~ s/[^A-Za-z0-9]/-/g;
1040
Pavel Pisa5449bc92007-02-10 01:45:37 -08001041 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001042 print "<refentryinfo>\n";
1043 print " <title>LINUX</title>\n";
1044 print " <productname>Kernel Hackers Manual</productname>\n";
1045 print " <date>$man_date</date>\n";
1046 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001048 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001049 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001050 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 print "</refmeta>\n";
1052 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001053 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 print " <refpurpose>\n";
1055 print " ";
1056 output_highlight ($args{'purpose'});
1057 print " </refpurpose>\n";
1058 print "</refnamediv>\n";
1059
1060 print "<refsynopsisdiv>\n";
1061 print " <title>Synopsis</title>\n";
1062 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001063 print " <funcdef>" . $args{'functiontype'} . " ";
1064 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
1066 $count = 0;
1067 if ($#{$args{'parameterlist'}} >= 0) {
1068 foreach $parameter (@{$args{'parameterlist'}}) {
1069 $type = $args{'parametertypes'}{$parameter};
1070 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1071 # pointer-to-function
1072 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1073 print " <funcparams>$2</funcparams></paramdef>\n";
1074 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001075 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 print " <parameter>$parameter</parameter></paramdef>\n";
1077 }
1078 }
1079 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001080 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 }
1082 print " </funcprototype></funcsynopsis>\n";
1083 print "</refsynopsisdiv>\n";
1084
1085 # print parameters
1086 print "<refsect1>\n <title>Arguments</title>\n";
1087 if ($#{$args{'parameterlist'}} >= 0) {
1088 print " <variablelist>\n";
1089 foreach $parameter (@{$args{'parameterlist'}}) {
1090 my $parameter_name = $parameter;
1091 $parameter_name =~ s/\[.*//;
1092
1093 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1094 print " <listitem>\n <para>\n";
1095 $lineprefix=" ";
1096 output_highlight($args{'parameterdescs'}{$parameter_name});
1097 print " </para>\n </listitem>\n </varlistentry>\n";
1098 }
1099 print " </variablelist>\n";
1100 } else {
1101 print " <para>\n None\n </para>\n";
1102 }
1103 print "</refsect1>\n";
1104
1105 output_section_xml(@_);
1106 print "</refentry>\n\n";
1107}
1108
1109# output struct in XML DocBook
1110sub output_struct_xml(%) {
1111 my %args = %{$_[0]};
1112 my ($parameter, $section);
1113 my $id;
1114
Randy Dunlapb9d973282009-06-09 08:50:38 -07001115 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 $id =~ s/[^A-Za-z0-9]/-/g;
1117
Pavel Pisa5449bc92007-02-10 01:45:37 -08001118 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001119 print "<refentryinfo>\n";
1120 print " <title>LINUX</title>\n";
1121 print " <productname>Kernel Hackers Manual</productname>\n";
1122 print " <date>$man_date</date>\n";
1123 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001125 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001126 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001127 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 print "</refmeta>\n";
1129 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001130 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 print " <refpurpose>\n";
1132 print " ";
1133 output_highlight ($args{'purpose'});
1134 print " </refpurpose>\n";
1135 print "</refnamediv>\n";
1136
1137 print "<refsynopsisdiv>\n";
1138 print " <title>Synopsis</title>\n";
1139 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001140 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 foreach $parameter (@{$args{'parameterlist'}}) {
1142 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001143 my $prm = $parameter;
1144 # convert data read & converted thru xml_escape() into &xyz; format:
1145 # This allows us to have #define macros interspersed in a struct.
1146 $prm =~ s/\\\\\\/\&/g;
1147 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 next;
1149 }
1150
1151 my $parameter_name = $parameter;
1152 $parameter_name =~ s/\[.*//;
1153
1154 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001155 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 $type = $args{'parametertypes'}{$parameter};
1157 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1158 # pointer-to-function
1159 print " $1 $parameter) ($2);\n";
1160 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001161 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 print " $1 $parameter$2;\n";
1163 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001164 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 }
1166 }
1167 print "};";
1168 print " </programlisting>\n";
1169 print "</refsynopsisdiv>\n";
1170
1171 print " <refsect1>\n";
1172 print " <title>Members</title>\n";
1173
Randy Dunlap39f00c02008-09-22 13:57:44 -07001174 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 print " <variablelist>\n";
1176 foreach $parameter (@{$args{'parameterlist'}}) {
1177 ($parameter =~ /^#/) && next;
1178
1179 my $parameter_name = $parameter;
1180 $parameter_name =~ s/\[.*//;
1181
1182 defined($args{'parameterdescs'}{$parameter_name}) || next;
1183 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1184 print " <varlistentry>";
1185 print " <term>$parameter</term>\n";
1186 print " <listitem><para>\n";
1187 output_highlight($args{'parameterdescs'}{$parameter_name});
1188 print " </para></listitem>\n";
1189 print " </varlistentry>\n";
1190 }
1191 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001192 } else {
1193 print " <para>\n None\n </para>\n";
1194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 print " </refsect1>\n";
1196
1197 output_section_xml(@_);
1198
1199 print "</refentry>\n\n";
1200}
1201
1202# output enum in XML DocBook
1203sub output_enum_xml(%) {
1204 my %args = %{$_[0]};
1205 my ($parameter, $section);
1206 my $count;
1207 my $id;
1208
Randy Dunlapb9d973282009-06-09 08:50:38 -07001209 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 $id =~ s/[^A-Za-z0-9]/-/g;
1211
Pavel Pisa5449bc92007-02-10 01:45:37 -08001212 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001213 print "<refentryinfo>\n";
1214 print " <title>LINUX</title>\n";
1215 print " <productname>Kernel Hackers Manual</productname>\n";
1216 print " <date>$man_date</date>\n";
1217 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001219 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001220 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001221 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 print "</refmeta>\n";
1223 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001224 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 print " <refpurpose>\n";
1226 print " ";
1227 output_highlight ($args{'purpose'});
1228 print " </refpurpose>\n";
1229 print "</refnamediv>\n";
1230
1231 print "<refsynopsisdiv>\n";
1232 print " <title>Synopsis</title>\n";
1233 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001234 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 $count = 0;
1236 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001237 print " $parameter";
1238 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 $count++;
1240 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001241 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 print "\n";
1243 }
1244 print "};";
1245 print " </programlisting>\n";
1246 print "</refsynopsisdiv>\n";
1247
1248 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001249 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 print " <variablelist>\n";
1251 foreach $parameter (@{$args{'parameterlist'}}) {
1252 my $parameter_name = $parameter;
1253 $parameter_name =~ s/\[.*//;
1254
1255 print " <varlistentry>";
1256 print " <term>$parameter</term>\n";
1257 print " <listitem><para>\n";
1258 output_highlight($args{'parameterdescs'}{$parameter_name});
1259 print " </para></listitem>\n";
1260 print " </varlistentry>\n";
1261 }
1262 print " </variablelist>\n";
1263 print "</refsect1>\n";
1264
1265 output_section_xml(@_);
1266
1267 print "</refentry>\n\n";
1268}
1269
1270# output typedef in XML DocBook
1271sub output_typedef_xml(%) {
1272 my %args = %{$_[0]};
1273 my ($parameter, $section);
1274 my $id;
1275
Randy Dunlapb9d973282009-06-09 08:50:38 -07001276 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 $id =~ s/[^A-Za-z0-9]/-/g;
1278
Pavel Pisa5449bc92007-02-10 01:45:37 -08001279 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001280 print "<refentryinfo>\n";
1281 print " <title>LINUX</title>\n";
1282 print " <productname>Kernel Hackers Manual</productname>\n";
1283 print " <date>$man_date</date>\n";
1284 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001286 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001287 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 print "</refmeta>\n";
1289 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001290 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 print " <refpurpose>\n";
1292 print " ";
1293 output_highlight ($args{'purpose'});
1294 print " </refpurpose>\n";
1295 print "</refnamediv>\n";
1296
1297 print "<refsynopsisdiv>\n";
1298 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001299 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 print "</refsynopsisdiv>\n";
1301
1302 output_section_xml(@_);
1303
1304 print "</refentry>\n\n";
1305}
1306
1307# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001308sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 my %args = %{$_[0]};
1310 my ($parameter, $section);
1311 my $count;
1312
1313 my $id = $args{'module'};
1314 $id =~ s/[^A-Za-z0-9]/-/g;
1315
1316 # print out each section
1317 $lineprefix=" ";
1318 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001319 if (!$args{'content-only'}) {
1320 print "<refsect1>\n <title>$section</title>\n";
1321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 if ($section =~ m/EXAMPLE/i) {
1323 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001324 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001325 } else {
1326 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 }
1328 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001329 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 if ($section =~ m/EXAMPLE/i) {
1331 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001332 } else {
1333 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001335 if (!$args{'content-only'}) {
1336 print "\n</refsect1>\n";
1337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 }
1339
1340 print "\n\n";
1341}
1342
1343# output in XML DocBook
1344sub output_function_gnome {
1345 my %args = %{$_[0]};
1346 my ($parameter, $section);
1347 my $count;
1348 my $id;
1349
Randy Dunlapb9d973282009-06-09 08:50:38 -07001350 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 $id =~ s/[^A-Za-z0-9]/-/g;
1352
1353 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001354 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
1356 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001357 print " <funcdef>" . $args{'functiontype'} . " ";
1358 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 print "</function></funcdef>\n";
1360
1361 $count = 0;
1362 if ($#{$args{'parameterlist'}} >= 0) {
1363 foreach $parameter (@{$args{'parameterlist'}}) {
1364 $type = $args{'parametertypes'}{$parameter};
1365 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1366 # pointer-to-function
1367 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1368 print " <funcparams>$2</funcparams></paramdef>\n";
1369 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001370 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 print " <parameter>$parameter</parameter></paramdef>\n";
1372 }
1373 }
1374 } else {
1375 print " <void>\n";
1376 }
1377 print " </funcsynopsis>\n";
1378 if ($#{$args{'parameterlist'}} >= 0) {
1379 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1380 print "<tgroup cols=\"2\">\n";
1381 print "<colspec colwidth=\"2*\">\n";
1382 print "<colspec colwidth=\"8*\">\n";
1383 print "<tbody>\n";
1384 foreach $parameter (@{$args{'parameterlist'}}) {
1385 my $parameter_name = $parameter;
1386 $parameter_name =~ s/\[.*//;
1387
1388 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1389 print " <entry>\n";
1390 $lineprefix=" ";
1391 output_highlight($args{'parameterdescs'}{$parameter_name});
1392 print " </entry></row>\n";
1393 }
1394 print " </tbody></tgroup></informaltable>\n";
1395 } else {
1396 print " <para>\n None\n </para>\n";
1397 }
1398
1399 # print out each section
1400 $lineprefix=" ";
1401 foreach $section (@{$args{'sectionlist'}}) {
1402 print "<simplesect>\n <title>$section</title>\n";
1403 if ($section =~ m/EXAMPLE/i) {
1404 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001405 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 } else {
1407 }
1408 print "<para>\n";
1409 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001410 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 print "</para>\n";
1412 if ($section =~ m/EXAMPLE/i) {
1413 print "</programlisting></example>\n";
1414 } else {
1415 }
1416 print " </simplesect>\n";
1417 }
1418
1419 print "</sect2>\n\n";
1420}
1421
1422##
1423# output function in man
1424sub output_function_man(%) {
1425 my %args = %{$_[0]};
1426 my ($parameter, $section);
1427 my $count;
1428
1429 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1430
1431 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001432 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433
1434 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001435 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001436 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001437 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001438 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001439 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 $count = 0;
1441 my $parenth = "(";
1442 my $post = ",";
1443 foreach my $parameter (@{$args{'parameterlist'}}) {
1444 if ($count == $#{$args{'parameterlist'}}) {
1445 $post = ");";
1446 }
1447 $type = $args{'parametertypes'}{$parameter};
1448 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1449 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001450 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 } else {
1452 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001453 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 }
1455 $count++;
1456 $parenth = "";
1457 }
1458
1459 print ".SH ARGUMENTS\n";
1460 foreach $parameter (@{$args{'parameterlist'}}) {
1461 my $parameter_name = $parameter;
1462 $parameter_name =~ s/\[.*//;
1463
Randy Dunlapb9d973282009-06-09 08:50:38 -07001464 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 output_highlight($args{'parameterdescs'}{$parameter_name});
1466 }
1467 foreach $section (@{$args{'sectionlist'}}) {
1468 print ".SH \"", uc $section, "\"\n";
1469 output_highlight($args{'sections'}{$section});
1470 }
1471}
1472
1473##
1474# output enum in man
1475sub output_enum_man(%) {
1476 my %args = %{$_[0]};
1477 my ($parameter, $section);
1478 my $count;
1479
1480 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1481
1482 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001483 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
1485 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001486 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 $count = 0;
1488 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001489 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 if ($count == $#{$args{'parameterlist'}}) {
1491 print "\n};\n";
1492 last;
1493 }
1494 else {
1495 print ", \n.br\n";
1496 }
1497 $count++;
1498 }
1499
1500 print ".SH Constants\n";
1501 foreach $parameter (@{$args{'parameterlist'}}) {
1502 my $parameter_name = $parameter;
1503 $parameter_name =~ s/\[.*//;
1504
Randy Dunlapb9d973282009-06-09 08:50:38 -07001505 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 output_highlight($args{'parameterdescs'}{$parameter_name});
1507 }
1508 foreach $section (@{$args{'sectionlist'}}) {
1509 print ".SH \"$section\"\n";
1510 output_highlight($args{'sections'}{$section});
1511 }
1512}
1513
1514##
1515# output struct in man
1516sub output_struct_man(%) {
1517 my %args = %{$_[0]};
1518 my ($parameter, $section);
1519
Randy Dunlapb9d973282009-06-09 08:50:38 -07001520 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
1522 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001523 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524
1525 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001526 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
1528 foreach my $parameter (@{$args{'parameterlist'}}) {
1529 if ($parameter =~ /^#/) {
1530 print ".BI \"$parameter\"\n.br\n";
1531 next;
1532 }
1533 my $parameter_name = $parameter;
1534 $parameter_name =~ s/\[.*//;
1535
Randy Dunlap3c308792007-05-08 00:24:39 -07001536 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 $type = $args{'parametertypes'}{$parameter};
1538 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1539 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001540 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001542 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001543 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 } else {
1545 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001546 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 }
1548 print "\n.br\n";
1549 }
1550 print "};\n.br\n";
1551
Randy Dunlapc51d3dac2006-06-25 05:49:14 -07001552 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 foreach $parameter (@{$args{'parameterlist'}}) {
1554 ($parameter =~ /^#/) && next;
1555
1556 my $parameter_name = $parameter;
1557 $parameter_name =~ s/\[.*//;
1558
Randy Dunlap3c308792007-05-08 00:24:39 -07001559 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001560 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 output_highlight($args{'parameterdescs'}{$parameter_name});
1562 }
1563 foreach $section (@{$args{'sectionlist'}}) {
1564 print ".SH \"$section\"\n";
1565 output_highlight($args{'sections'}{$section});
1566 }
1567}
1568
1569##
1570# output typedef in man
1571sub output_typedef_man(%) {
1572 my %args = %{$_[0]};
1573 my ($parameter, $section);
1574
1575 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1576
1577 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001578 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579
1580 foreach $section (@{$args{'sectionlist'}}) {
1581 print ".SH \"$section\"\n";
1582 output_highlight($args{'sections'}{$section});
1583 }
1584}
1585
Johannes Bergb112e0f2007-10-24 15:08:48 -07001586sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 my %args = %{$_[0]};
1588 my ($parameter, $section);
1589 my $count;
1590
1591 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1592
1593 foreach $section (@{$args{'sectionlist'}}) {
1594 print ".SH \"$section\"\n";
1595 output_highlight($args{'sections'}{$section});
1596 }
1597}
1598
1599##
1600# output in text
1601sub output_function_text(%) {
1602 my %args = %{$_[0]};
1603 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001604 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605
Randy Dunlapf47634b2006-07-01 04:36:36 -07001606 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001607 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001608
1609 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001610 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001611 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001612 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001613 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001614 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001616
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 my $count = 0;
1618 foreach my $parameter (@{$args{'parameterlist'}}) {
1619 $type = $args{'parametertypes'}{$parameter};
1620 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1621 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001622 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001624 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 }
1626 if ($count != $#{$args{'parameterlist'}}) {
1627 $count++;
1628 print ",\n";
1629 print " " x length($start);
1630 } else {
1631 print ");\n\n";
1632 }
1633 }
1634
1635 print "Arguments:\n\n";
1636 foreach $parameter (@{$args{'parameterlist'}}) {
1637 my $parameter_name = $parameter;
1638 $parameter_name =~ s/\[.*//;
1639
Randy Dunlapb9d973282009-06-09 08:50:38 -07001640 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 }
1642 output_section_text(@_);
1643}
1644
1645#output sections in text
1646sub output_section_text(%) {
1647 my %args = %{$_[0]};
1648 my $section;
1649
1650 print "\n";
1651 foreach $section (@{$args{'sectionlist'}}) {
1652 print "$section:\n\n";
1653 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001654 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 print "\n\n";
1656}
1657
1658# output enum in text
1659sub output_enum_text(%) {
1660 my %args = %{$_[0]};
1661 my ($parameter);
1662 my $count;
1663 print "Enum:\n\n";
1664
Randy Dunlapb9d973282009-06-09 08:50:38 -07001665 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1666 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 $count = 0;
1668 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001669 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 if ($count != $#{$args{'parameterlist'}}) {
1671 $count++;
1672 print ",";
1673 }
1674 print "\n";
1675 }
1676 print "};\n\n";
1677
1678 print "Constants:\n\n";
1679 foreach $parameter (@{$args{'parameterlist'}}) {
1680 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001681 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 }
1683
1684 output_section_text(@_);
1685}
1686
1687# output typedef in text
1688sub output_typedef_text(%) {
1689 my %args = %{$_[0]};
1690 my ($parameter);
1691 my $count;
1692 print "Typedef:\n\n";
1693
Randy Dunlapb9d973282009-06-09 08:50:38 -07001694 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 output_section_text(@_);
1696}
1697
1698# output struct as text
1699sub output_struct_text(%) {
1700 my %args = %{$_[0]};
1701 my ($parameter);
1702
Randy Dunlapb9d973282009-06-09 08:50:38 -07001703 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1704 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 foreach $parameter (@{$args{'parameterlist'}}) {
1706 if ($parameter =~ /^#/) {
1707 print "$parameter\n";
1708 next;
1709 }
1710
1711 my $parameter_name = $parameter;
1712 $parameter_name =~ s/\[.*//;
1713
Randy Dunlap3c308792007-05-08 00:24:39 -07001714 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 $type = $args{'parametertypes'}{$parameter};
1716 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1717 # pointer-to-function
1718 print "\t$1 $parameter) ($2);\n";
1719 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001720 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 print "\t$1 $parameter$2;\n";
1722 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001723 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 }
1725 }
1726 print "};\n\n";
1727
1728 print "Members:\n\n";
1729 foreach $parameter (@{$args{'parameterlist'}}) {
1730 ($parameter =~ /^#/) && next;
1731
1732 my $parameter_name = $parameter;
1733 $parameter_name =~ s/\[.*//;
1734
Randy Dunlap3c308792007-05-08 00:24:39 -07001735 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001737 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 }
1739 print "\n";
1740 output_section_text(@_);
1741}
1742
Johannes Bergb112e0f2007-10-24 15:08:48 -07001743sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 my %args = %{$_[0]};
1745 my ($parameter, $section);
1746
1747 foreach $section (@{$args{'sectionlist'}}) {
1748 print " $section:\n";
1749 print " -> ";
1750 output_highlight($args{'sections'}{$section});
1751 }
1752}
1753
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001754##
1755# output in restructured text
1756#
1757
1758#
1759# This could use some work; it's used to output the DOC: sections, and
1760# starts by putting out the name of the doc section itself, but that tends
1761# to duplicate a header already in the template file.
1762#
1763sub output_blockhead_rst(%) {
1764 my %args = %{$_[0]};
1765 my ($parameter, $section);
1766
1767 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001768 if ($output_selection != OUTPUT_INCLUDE) {
1769 print "**$section**\n\n";
1770 }
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001771 output_highlight_rst($args{'sections'}{$section});
1772 print "\n";
1773 }
1774}
1775
1776sub output_highlight_rst {
1777 my $contents = join "\n",@_;
1778 my $line;
1779
1780 # undo the evil effects of xml_escape() earlier
1781 $contents = xml_unescape($contents);
1782
1783 eval $dohighlight;
1784 die $@ if $@;
1785
1786 foreach $line (split "\n", $contents) {
1787 if ($line eq "") {
1788 print $lineprefix, $blankline;
1789 } else {
1790 $line =~ s/\\\\\\/\&/g;
1791 print $lineprefix, $line;
1792 }
1793 print "\n";
1794 }
1795}
1796
1797sub output_function_rst(%) {
1798 my %args = %{$_[0]};
1799 my ($parameter, $section);
1800 my $start;
1801
1802 print ".. c:function:: ";
1803 if ($args{'functiontype'} ne "") {
1804 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1805 } else {
1806 $start = $args{'function'} . " (";
1807 }
1808 print $start;
1809
1810 my $count = 0;
1811 foreach my $parameter (@{$args{'parameterlist'}}) {
1812 if ($count ne 0) {
1813 print ", ";
1814 }
1815 $count++;
1816 $type = $args{'parametertypes'}{$parameter};
1817 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1818 # pointer-to-function
1819 print $1 . $parameter . ") (" . $2;
1820 } else {
1821 print $type . " " . $parameter;
1822 }
1823 }
1824 print ")\n\n " . $args{'purpose'} . "\n\n";
1825
1826 print ":Parameters:\n\n";
1827 foreach $parameter (@{$args{'parameterlist'}}) {
1828 my $parameter_name = $parameter;
1829 #$parameter_name =~ s/\[.*//;
1830 $type = $args{'parametertypes'}{$parameter};
1831
1832 if ($type ne "") {
1833 print " ``$type $parameter``\n";
1834 } else {
1835 print " ``$parameter``\n";
1836 }
Jani Nikula5e64fa92016-05-19 20:32:48 +03001837 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1838 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001839 my $oldprefix = $lineprefix;
1840 $lineprefix = " ";
1841 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
1842 $lineprefix = $oldprefix;
1843 } else {
1844 print "\n _undescribed_\n";
1845 }
1846 print "\n";
1847 }
1848 output_section_rst(@_);
1849}
1850
1851sub output_section_rst(%) {
1852 my %args = %{$_[0]};
1853 my $section;
1854 my $oldprefix = $lineprefix;
1855 $lineprefix = " ";
1856
1857 foreach $section (@{$args{'sectionlist'}}) {
1858 print ":$section:\n\n";
1859 output_highlight_rst($args{'sections'}{$section});
1860 print "\n";
1861 }
1862 print "\n";
1863 $lineprefix = $oldprefix;
1864}
1865
1866sub output_enum_rst(%) {
1867 my %args = %{$_[0]};
1868 my ($parameter);
1869 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001870 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001871
1872 print "\n\n.. c:type:: " . $name . "\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001873 print " " . $args{'purpose'} . "\n\n";
1874
1875 print "..\n\n:Constants:\n\n";
1876 my $oldprefix = $lineprefix;
1877 $lineprefix = " ";
1878 foreach $parameter (@{$args{'parameterlist'}}) {
1879 print " `$parameter`\n";
1880 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1881 output_highlight_rst($args{'parameterdescs'}{$parameter});
1882 } else {
1883 print " undescribed\n";
1884 }
1885 print "\n";
1886 }
1887 $lineprefix = $oldprefix;
1888 output_section_rst(@_);
1889}
1890
1891sub output_typedef_rst(%) {
1892 my %args = %{$_[0]};
1893 my ($parameter);
1894 my $count;
1895 my $name = "typedef " . $args{'typedef'};
1896
Jani Nikula62850972016-05-12 16:15:38 +03001897 ### FIXME: should the name below contain "typedef" or not?
1898 print "\n\n.. c:type:: " . $name . "\n\n";
1899 print " " . $args{'purpose'} . "\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001900
1901 output_section_rst(@_);
1902}
1903
1904sub output_struct_rst(%) {
1905 my %args = %{$_[0]};
1906 my ($parameter);
1907 my $name = $args{'type'} . " " . $args{'struct'};
1908
Jani Nikula62850972016-05-12 16:15:38 +03001909 print "\n\n.. c:type:: " . $name . "\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001910 print " " . $args{'purpose'} . "\n\n";
1911
1912 print ":Definition:\n\n";
1913 print " ::\n\n";
1914 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1915 foreach $parameter (@{$args{'parameterlist'}}) {
1916 if ($parameter =~ /^#/) {
1917 print " " . "$parameter\n";
1918 next;
1919 }
1920
1921 my $parameter_name = $parameter;
1922 $parameter_name =~ s/\[.*//;
1923
1924 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1925 $type = $args{'parametertypes'}{$parameter};
1926 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1927 # pointer-to-function
1928 print " $1 $parameter) ($2);\n";
1929 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1930 # bitfield
1931 print " $1 $parameter$2;\n";
1932 } else {
1933 print " " . $type . " " . $parameter . ";\n";
1934 }
1935 }
1936 print " };\n\n";
1937
1938 print ":Members:\n\n";
1939 foreach $parameter (@{$args{'parameterlist'}}) {
1940 ($parameter =~ /^#/) && next;
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 print " `$type $parameter`" . "\n";
1948 my $oldprefix = $lineprefix;
1949 $lineprefix = " ";
1950 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
1951 $lineprefix = $oldprefix;
1952 print "\n";
1953 }
1954 print "\n";
1955 output_section_rst(@_);
1956}
1957
1958
Johannes Bergeda603f2010-09-11 15:55:22 -07001959## list mode output functions
1960
1961sub output_function_list(%) {
1962 my %args = %{$_[0]};
1963
1964 print $args{'function'} . "\n";
1965}
1966
1967# output enum in list
1968sub output_enum_list(%) {
1969 my %args = %{$_[0]};
1970 print $args{'enum'} . "\n";
1971}
1972
1973# output typedef in list
1974sub output_typedef_list(%) {
1975 my %args = %{$_[0]};
1976 print $args{'typedef'} . "\n";
1977}
1978
1979# output struct as list
1980sub output_struct_list(%) {
1981 my %args = %{$_[0]};
1982
1983 print $args{'struct'} . "\n";
1984}
1985
1986sub output_blockhead_list(%) {
1987 my %args = %{$_[0]};
1988 my ($parameter, $section);
1989
1990 foreach $section (@{$args{'sectionlist'}}) {
1991 print "DOC: $section\n";
1992 }
1993}
1994
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995##
Randy Dunlap27205742006-10-11 01:22:12 -07001996# generic output function for all types (function, struct/union, typedef, enum);
1997# calls the generated, variable output_ function name based on
1998# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999sub output_declaration {
2000 no strict 'refs';
2001 my $name = shift;
2002 my $functype = shift;
2003 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002004 if (($output_selection == OUTPUT_ALL) ||
2005 (($output_selection == OUTPUT_INCLUDE ||
2006 $output_selection == OUTPUT_EXPORTED) &&
2007 defined($function_table{$name})) ||
2008 (($output_selection == OUTPUT_EXCLUDE ||
2009 $output_selection == OUTPUT_INTERNAL) &&
2010 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002012 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 $section_counter++;
2014 }
2015}
2016
2017##
Randy Dunlap27205742006-10-11 01:22:12 -07002018# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002019sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002021 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 &$func(@_);
2023 $section_counter++;
2024}
2025
2026##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002027# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028# invokes the right handler. NOT called for functions.
2029sub dump_declaration($$) {
2030 no strict 'refs';
2031 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002032 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 &$func(@_);
2034}
2035
2036sub dump_union($$) {
2037 dump_struct(@_);
2038}
2039
2040sub dump_struct($$) {
2041 my $x = shift;
2042 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002043 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002045 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2046 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002047 $declaration_name = $2;
2048 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
2050 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002051 $members =~ s/({.*})//g;
2052 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
Martin Waitzaeec46b2005-11-13 16:08:13 -08002054 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002055 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2056 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002057 # strip comments:
2058 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002059 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002060 # strip kmemcheck_bitfield_{begin,end}.*;
2061 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002062 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002063 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002064 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002065 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002066 # replace DECLARE_BITMAP
2067 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002068
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002070 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
2072 output_declaration($declaration_name,
2073 'struct',
2074 {'struct' => $declaration_name,
2075 'module' => $modulename,
2076 'parameterlist' => \@parameterlist,
2077 'parameterdescs' => \%parameterdescs,
2078 'parametertypes' => \%parametertypes,
2079 'sectionlist' => \@sectionlist,
2080 'sections' => \%sections,
2081 'purpose' => $declaration_purpose,
2082 'type' => $decl_type
2083 });
2084 }
2085 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002086 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 ++$errors;
2088 }
2089}
2090
2091sub dump_enum($$) {
2092 my $x = shift;
2093 my $file = shift;
2094
Martin Waitzaeec46b2005-11-13 16:08:13 -08002095 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002096 # strip #define macros inside enums
2097 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002098
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002100 $declaration_name = $1;
2101 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102
2103 foreach my $arg (split ',', $members) {
2104 $arg =~ s/^\s*(\w+).*/$1/;
2105 push @parameterlist, $arg;
2106 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002107 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002108 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 "not described in enum '$declaration_name'\n";
2110 }
2111
2112 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002113
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 output_declaration($declaration_name,
2115 'enum',
2116 {'enum' => $declaration_name,
2117 'module' => $modulename,
2118 'parameterlist' => \@parameterlist,
2119 'parameterdescs' => \%parameterdescs,
2120 'sectionlist' => \@sectionlist,
2121 'sections' => \%sections,
2122 'purpose' => $declaration_purpose
2123 });
2124 }
2125 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002126 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 ++$errors;
2128 }
2129}
2130
2131sub dump_typedef($$) {
2132 my $x = shift;
2133 my $file = shift;
2134
Martin Waitzaeec46b2005-11-13 16:08:13 -08002135 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002136
2137 # Parse function prototypes
2138 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
2139 # Function typedefs
2140 $return_type = $1;
2141 $declaration_name = $2;
2142 my $args = $3;
2143
2144 create_parameterlist($args, ',', $file);
2145
2146 output_declaration($declaration_name,
2147 'function',
2148 {'function' => $declaration_name,
2149 'module' => $modulename,
2150 'functiontype' => $return_type,
2151 'parameterlist' => \@parameterlist,
2152 'parameterdescs' => \%parameterdescs,
2153 'parametertypes' => \%parametertypes,
2154 'sectionlist' => \@sectionlist,
2155 'sections' => \%sections,
2156 'purpose' => $declaration_purpose
2157 });
2158 return;
2159 }
2160
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002162 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 $x =~ s/\[*.\]\s*;$/;/;
2164 }
2165
2166 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002167 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
2169 output_declaration($declaration_name,
2170 'typedef',
2171 {'typedef' => $declaration_name,
2172 'module' => $modulename,
2173 'sectionlist' => \@sectionlist,
2174 'sections' => \%sections,
2175 'purpose' => $declaration_purpose
2176 });
2177 }
2178 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002179 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 ++$errors;
2181 }
2182}
2183
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002184sub save_struct_actual($) {
2185 my $actual = shift;
2186
2187 # strip all spaces from the actual param so that it looks like one string item
2188 $actual =~ s/\s*//g;
2189 $struct_actual = $struct_actual . $actual . " ";
2190}
2191
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192sub create_parameterlist($$$) {
2193 my $args = shift;
2194 my $splitter = shift;
2195 my $file = shift;
2196 my $type;
2197 my $param;
2198
Martin Waitza6d3fe72006-01-09 20:53:55 -08002199 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002201 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002203
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 foreach my $arg (split($splitter, $args)) {
2205 # strip comments
2206 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002207 # strip leading/trailing spaces
2208 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 $arg =~ s/\s*$//;
2210 $arg =~ s/\s+/ /;
2211
2212 if ($arg =~ /^#/) {
2213 # Treat preprocessor directive as a typeless variable just to fill
2214 # corresponding data structures "correctly". Catch it later in
2215 # output_* subs.
2216 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002217 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 # pointer-to-function
2219 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002220 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 $param = $1;
2222 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002223 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002224 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002226 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227 $arg =~ s/\s*:\s*/:/g;
2228 $arg =~ s/\s*\[/\[/g;
2229
2230 my @args = split('\s*,\s*', $arg);
2231 if ($args[0] =~ m/\*/) {
2232 $args[0] =~ s/(\*+)\s*/ $1/;
2233 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002234
2235 my @first_arg;
2236 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2237 shift @args;
2238 push(@first_arg, split('\s+', $1));
2239 push(@first_arg, $2);
2240 } else {
2241 @first_arg = split('\s+', shift @args);
2242 }
2243
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 unshift(@args, pop @first_arg);
2245 $type = join " ", @first_arg;
2246
2247 foreach $param (@args) {
2248 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002249 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 push_parameter($2, "$type $1", $file);
2251 }
2252 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002253 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002254 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002255 push_parameter($1, "$type:$2", $file)
2256 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 }
2258 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002259 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 push_parameter($param, $type, $file);
2261 }
2262 }
2263 }
2264 }
2265}
2266
2267sub push_parameter($$$) {
2268 my $param = shift;
2269 my $type = shift;
2270 my $file = shift;
2271
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002272 if (($anon_struct_union == 1) && ($type eq "") &&
2273 ($param eq "}")) {
2274 return; # ignore the ending }; from anon. struct/union
2275 }
2276
2277 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 my $param_name = $param;
2279 $param_name =~ s/\[.*//;
2280
Martin Waitza6d3fe72006-01-09 20:53:55 -08002281 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 {
Randy Dunlapced69092008-12-01 13:14:03 -08002283 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2284 $parameterdescs{$param} = "variable arguments";
2285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 }
2287 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2288 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 $param="void";
2290 $parameterdescs{void} = "no arguments";
2291 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002292 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2293 # handle unnamed (anonymous) union or struct:
2294 {
2295 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002296 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002297 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002298 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002299 }
2300
Martin Waitza6d3fe72006-01-09 20:53:55 -08002301 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002302 # (but ignore ones starting with # as these are not parameters
2303 # but inline preprocessor statements);
2304 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002305 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002306 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2307
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 $parameterdescs{$param_name} = $undescribed;
2309
2310 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002311 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 "or member '$param' not " .
2313 "described in '$declaration_name'\n";
2314 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002315 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002316 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002318 }
2319 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002321 $param = xml_escape($param);
2322
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002323 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002324 # on @parameterlist;
2325 # this fixes a problem where check_sections() cannot find
2326 # a parameter like "addr[6 + 2]" because it actually appears
2327 # as "addr[6", "+", "2]" on the parameter list;
2328 # but it's better to maintain the param string unchanged for output,
2329 # so just weaken the string compare in check_sections() to ignore
2330 # "[blah" in a parameter string;
2331 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 push @parameterlist, $param;
2333 $parametertypes{$param} = $type;
2334}
2335
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002336sub check_sections($$$$$$) {
2337 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2338 my @sects = split ' ', $sectcheck;
2339 my @prms = split ' ', $prmscheck;
2340 my $err;
2341 my ($px, $sx);
2342 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2343
2344 foreach $sx (0 .. $#sects) {
2345 $err = 1;
2346 foreach $px (0 .. $#prms) {
2347 $prm_clean = $prms[$px];
2348 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002349 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002350 # ignore array size in a parameter string;
2351 # however, the original param string may contain
2352 # spaces, e.g.: addr[6 + 2]
2353 # and this appears in @prms as "addr[6" since the
2354 # parameter list is split at spaces;
2355 # hence just ignore "[..." for the sections check;
2356 $prm_clean =~ s/\[.*//;
2357
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002358 ##$prm_clean =~ s/^\**//;
2359 if ($prm_clean eq $sects[$sx]) {
2360 $err = 0;
2361 last;
2362 }
2363 }
2364 if ($err) {
2365 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002366 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002367 "Excess function parameter " .
2368 "'$sects[$sx]' " .
2369 "description in '$decl_name'\n";
2370 ++$warnings;
2371 } else {
2372 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002373 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002374 "Excess struct/union/enum/typedef member " .
2375 "'$sects[$sx]' " .
2376 "description in '$decl_name'\n";
2377 ++$warnings;
2378 }
2379 }
2380 }
2381 }
2382}
2383
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002385# Checks the section describing the return value of a function.
2386sub check_return_section {
2387 my $file = shift;
2388 my $declaration_name = shift;
2389 my $return_type = shift;
2390
2391 # Ignore an empty return type (It's a macro)
2392 # Ignore functions with a "void" return type. (But don't ignore "void *")
2393 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2394 return;
2395 }
2396
2397 if (!defined($sections{$section_return}) ||
2398 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002399 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002400 "No description found for return value of " .
2401 "'$declaration_name'\n";
2402 ++$warnings;
2403 }
2404}
2405
2406##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407# takes a function prototype and the name of the current file being
2408# processed and spits out all the details stored in the global
2409# arrays/hashes.
2410sub dump_function($$) {
2411 my $prototype = shift;
2412 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002413 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414
2415 $prototype =~ s/^static +//;
2416 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002417 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 $prototype =~ s/^inline +//;
2419 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002420 $prototype =~ s/^__inline +//;
2421 $prototype =~ s/^__always_inline +//;
2422 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002423 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002424 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002425 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002426 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002427 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002428 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002429 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430
2431 # Yes, this truly is vile. We are looking for:
2432 # 1. Return type (may be nothing if we're looking at a macro)
2433 # 2. Function name
2434 # 3. Function parameters.
2435 #
2436 # All the while we have to watch out for function pointer parameters
2437 # (which IIRC is what the two sections are for), C types (these
2438 # regexps don't even start to express all the possibilities), and
2439 # so on.
2440 #
2441 # If you mess with these regexps, it's a good idea to check that
2442 # the following functions' documentation still comes out right:
2443 # - parport_register_device (function pointer parameters)
2444 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002445 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002447 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2448 # This is an object-like macro, it has no return type and no parameter
2449 # list.
2450 # Function-like macros are not allowed to have spaces between
2451 # declaration_name and opening parenthesis (notice the \s+).
2452 $return_type = $1;
2453 $declaration_name = $2;
2454 $noret = 1;
2455 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2457 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2458 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002459 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2461 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2462 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2463 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2464 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2465 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2466 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2467 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002468 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2469 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002470 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2471 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 $return_type = $1;
2473 $declaration_name = $2;
2474 my $args = $3;
2475
2476 create_parameterlist($args, ',', $file);
2477 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002478 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 return;
2480 }
2481
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002482 my $prms = join " ", @parameterlist;
2483 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2484
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002485 # This check emits a lot of warnings at the moment, because many
2486 # functions don't have a 'Return' doc section. So until the number
2487 # of warnings goes sufficiently down, the check is only performed in
2488 # verbose mode.
2489 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002490 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002491 check_return_section($file, $declaration_name, $return_type);
2492 }
2493
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002494 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 'function',
2496 {'function' => $declaration_name,
2497 'module' => $modulename,
2498 'functiontype' => $return_type,
2499 'parameterlist' => \@parameterlist,
2500 'parameterdescs' => \%parameterdescs,
2501 'parametertypes' => \%parametertypes,
2502 'sectionlist' => \@sectionlist,
2503 'sections' => \%sections,
2504 'purpose' => $declaration_purpose
2505 });
2506}
2507
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508sub reset_state {
2509 $function = "";
2510 %constants = ();
2511 %parameterdescs = ();
2512 %parametertypes = ();
2513 @parameterlist = ();
2514 %sections = ();
2515 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002516 $sectcheck = "";
2517 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002519
Jani Nikula48af6062016-05-26 14:56:05 +03002520 $state = STATE_NORMAL;
2521 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522}
2523
Jason Baron56afb0f2009-04-30 13:29:36 -04002524sub tracepoint_munge($) {
2525 my $file = shift;
2526 my $tracepointname = 0;
2527 my $tracepointargs = 0;
2528
Jason Baron3a9089f2009-12-01 12:18:49 -05002529 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002530 $tracepointname = $1;
2531 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002532 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2533 $tracepointname = $1;
2534 }
2535 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2536 $tracepointname = $2;
2537 }
2538 $tracepointname =~ s/^\s+//; #strip leading whitespace
2539 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002540 $tracepointargs = $1;
2541 }
2542 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002543 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002544 "$prototype\n";
2545 } else {
2546 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2547 }
2548}
2549
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002550sub syscall_munge() {
2551 my $void = 0;
2552
2553 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2554## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2555 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2556 $void = 1;
2557## $prototype = "long sys_$1(void)";
2558 }
2559
2560 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2561 if ($prototype =~ m/long (sys_.*?),/) {
2562 $prototype =~ s/,/\(/;
2563 } elsif ($void) {
2564 $prototype =~ s/\)/\(void\)/;
2565 }
2566
2567 # now delete all of the odd-number commas in $prototype
2568 # so that arg types & arg names don't have a comma between them
2569 my $count = 0;
2570 my $len = length($prototype);
2571 if ($void) {
2572 $len = 0; # skip the for-loop
2573 }
2574 for (my $ix = 0; $ix < $len; $ix++) {
2575 if (substr($prototype, $ix, 1) eq ',') {
2576 $count++;
2577 if ($count % 2 == 1) {
2578 substr($prototype, $ix, 1) = ' ';
2579 }
2580 }
2581 }
2582}
2583
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002584sub process_state3_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 my $x = shift;
2586 my $file = shift;
2587
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002588 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2589
Randy Dunlap890c78c2008-10-25 17:06:43 -07002590 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 # do nothing
2592 }
2593 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002594 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002596
Randy Dunlap890c78c2008-10-25 17:06:43 -07002597 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002598 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2600 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002601 if ($prototype =~ /SYSCALL_DEFINE/) {
2602 syscall_munge();
2603 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002604 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2605 $prototype =~ /DEFINE_SINGLE_EVENT/)
2606 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002607 tracepoint_munge($file);
2608 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002609 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 reset_state();
2611 }
2612}
2613
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002614sub process_state3_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 my $x = shift;
2616 my $file = shift;
2617
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2619 $x =~ s@^\s+@@gos; # strip leading spaces
2620 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002621 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2622
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 if ($x =~ /^#/) {
2624 # To distinguish preprocessor directive from regular declaration later.
2625 $x .= ";";
2626 }
2627
2628 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002629 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 $prototype .= $1 . $2;
2631 ($2 eq '{') && $brcount++;
2632 ($2 eq '}') && $brcount--;
2633 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002634 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002636 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 }
2638 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002639 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 $prototype .= $x;
2641 last;
2642 }
2643 }
2644}
2645
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002646# xml_escape: replace <, >, and & in the text stream;
2647#
2648# however, formatting controls that are generated internally/locally in the
2649# kernel-doc script are not escaped here; instead, they begin life like
2650# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2651# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2652# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653sub xml_escape($) {
2654 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002655 if (($output_mode eq "text") || ($output_mode eq "man")) {
2656 return $text;
2657 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 $text =~ s/\&/\\\\\\amp;/g;
2659 $text =~ s/\</\\\\\\lt;/g;
2660 $text =~ s/\>/\\\\\\gt;/g;
2661 return $text;
2662}
2663
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002664# xml_unescape: reverse the effects of xml_escape
2665sub xml_unescape($) {
2666 my $text = shift;
2667 if (($output_mode eq "text") || ($output_mode eq "man")) {
2668 return $text;
2669 }
2670 $text =~ s/\\\\\\amp;/\&/g;
2671 $text =~ s/\\\\\\lt;/</g;
2672 $text =~ s/\\\\\\gt;/>/g;
2673 return $text;
2674}
2675
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002676# convert local escape strings to html
2677# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2678sub local_unescape($) {
2679 my $text = shift;
2680 if (($output_mode eq "text") || ($output_mode eq "man")) {
2681 return $text;
2682 }
2683 $text =~ s/\\\\\\\\lt:/</g;
2684 $text =~ s/\\\\\\\\gt:/>/g;
2685 return $text;
2686}
2687
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002689 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 my $identifier;
2691 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002692 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002693 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002695 my ($orig_file) = @_;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696
Randy Dunlap2283a112005-07-07 15:39:26 -07002697 if (defined($ENV{'SRCTREE'})) {
Ben Hutchings68f86662015-09-01 23:48:49 +01002698 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002699 }
2700 else {
Ben Hutchings68f86662015-09-01 23:48:49 +01002701 $file = $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002702 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 if (defined($source_map{$file})) {
2704 $file = $source_map{$file};
2705 }
2706
2707 if (!open(IN,"<$file")) {
2708 print STDERR "Error: Cannot open file $file\n";
2709 ++$errors;
2710 return;
2711 }
2712
Jani Nikula86ae2e32016-01-21 13:05:22 +02002713 # two passes for -export and -internal
Jani Nikulab6c3f452016-05-29 22:19:35 +03002714 if ($output_selection == OUTPUT_EXPORTED ||
2715 $output_selection == OUTPUT_INTERNAL) {
Jani Nikula86ae2e32016-01-21 13:05:22 +02002716 while (<IN>) {
2717 if (/$export_symbol/o) {
2718 $function_table{$2} = 1;
2719 }
2720 }
2721 seek(IN, 0, 0);
2722 }
2723
Ilya Dryomova9e73142010-02-26 13:05:47 -08002724 $. = 1;
2725
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 $section_counter = 0;
2727 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002728 while (s/\\\s*$//) {
2729 $_ .= <IN>;
2730 }
Jani Nikula48af6062016-05-26 14:56:05 +03002731 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002733 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002734 $in_doc_sect = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 }
Jani Nikula48af6062016-05-26 14:56:05 +03002736 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002738 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 $contents = "";
2740 if ( $1 eq "" ) {
2741 $section = $section_intro;
2742 } else {
2743 $section = $1;
2744 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002745 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 elsif (/$doc_decl/o) {
2747 $identifier = $1;
2748 if (/\s*([\w\s]+?)\s*-/) {
2749 $identifier = $1;
2750 }
2751
Jani Nikula48af6062016-05-26 14:56:05 +03002752 $state = STATE_FIELD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002754 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002755 $descr= $1;
2756 $descr =~ s/^\s*//;
2757 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002758 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002759 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002760 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 } else {
2762 $declaration_purpose = "";
2763 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002764
2765 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002766 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002767 print STDERR $_;
2768 ++$warnings;
2769 }
2770
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 if ($identifier =~ m/^struct/) {
2772 $decl_type = 'struct';
2773 } elsif ($identifier =~ m/^union/) {
2774 $decl_type = 'union';
2775 } elsif ($identifier =~ m/^enum/) {
2776 $decl_type = 'enum';
2777 } elsif ($identifier =~ m/^typedef/) {
2778 $decl_type = 'typedef';
2779 } else {
2780 $decl_type = 'function';
2781 }
2782
2783 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002784 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 }
2786 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002787 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 " - I thought it was a doc line\n";
2789 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002790 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 }
Jani Nikula48af6062016-05-26 14:56:05 +03002792 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 if (/$doc_sect/o) {
2794 $newsection = $1;
2795 $newcontents = $2;
2796
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002797 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002798 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002799 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002800 ++$warnings;
2801 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002802 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 $section = $section_default;
2804 }
2805
Randy Dunlap850622d2006-06-25 05:48:55 -07002806 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002807 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 $contents = $newcontents;
2809 if ($contents ne "") {
Randy Dunlap27205742006-10-11 01:22:12 -07002810 while ((substr($contents, 0, 1) eq " ") ||
2811 substr($contents, 0, 1) eq "\t") {
2812 $contents = substr($contents, 1);
Randy Dunlap05189492006-06-25 05:47:47 -07002813 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 $contents .= "\n";
2815 }
2816 $section = $newsection;
2817 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002818 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002819 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 $section = $section_default;
2821 $contents = "";
2822 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002823 # look for doc_com + <text> + doc_end:
2824 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002825 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002826 ++$warnings;
2827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828
2829 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002830 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002832# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 } elsif (/$doc_content/) {
2834 # miguel-style comment kludge, look for blank lines after
2835 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002836 if ($1 eq "") {
2837 if ($section =~ m/^@/ || $section eq $section_context) {
2838 dump_section($file, $section, xml_escape($contents));
2839 $section = $section_default;
2840 $contents = "";
2841 } else {
2842 $contents .= "\n";
2843 }
2844 $in_purpose = 0;
2845 } elsif ($in_purpose == 1) {
2846 # Continued declaration purpose
2847 chomp($declaration_purpose);
2848 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002849 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002851 $contents .= $1 . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 }
2853 } else {
2854 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002855 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 ++$warnings;
2857 }
Jani Nikula48af6062016-05-26 14:56:05 +03002858 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002859 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03002860 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002861 $section = $1;
2862 $contents = $2;
2863 if ($contents ne "") {
2864 while ((substr($contents, 0, 1) eq " ") ||
2865 substr($contents, 0, 1) eq "\t") {
2866 $contents = substr($contents, 1);
2867 }
2868 $contents .= "\n";
2869 }
Jani Nikula48af6062016-05-26 14:56:05 +03002870 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002871 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03002872 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002873 if (($contents ne "") && ($contents ne "\n")) {
2874 dump_section($file, $section, xml_escape($contents));
2875 $section = $section_default;
2876 $contents = "";
2877 }
Jani Nikula48af6062016-05-26 14:56:05 +03002878 $state = STATE_PROTO;
2879 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002880 # Regular text
2881 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03002882 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002883 $contents .= $1 . "\n";
Jani Nikula48af6062016-05-26 14:56:05 +03002884 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
2885 $inline_doc_state = STATE_INLINE_ERROR;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002886 print STDERR "Warning(${file}:$.): ";
2887 print STDERR "Incorrect use of kernel-doc format: $_";
2888 ++$warnings;
2889 }
2890 }
Jani Nikula48af6062016-05-26 14:56:05 +03002891 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
2892 if (/$doc_inline_start/) {
2893 $state = STATE_INLINE;
2894 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002895 } elsif ($decl_type eq 'function') {
Randy Dunlap3c308792007-05-08 00:24:39 -07002896 process_state3_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -07002898 process_state3_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 }
Jani Nikula48af6062016-05-26 14:56:05 +03002900 } elsif ($state == STATE_DOCBLOCK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 # Documentation block
Randy Dunlap3c308792007-05-08 00:24:39 -07002902 if (/$doc_block/) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002903 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 $contents = "";
2905 $function = "";
2906 %constants = ();
2907 %parameterdescs = ();
2908 %parametertypes = ();
2909 @parameterlist = ();
2910 %sections = ();
2911 @sectionlist = ();
2912 $prototype = "";
2913 if ( $1 eq "" ) {
2914 $section = $section_intro;
2915 } else {
2916 $section = $1;
2917 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002918 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 elsif (/$doc_end/)
2920 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002921 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 $contents = "";
2923 $function = "";
2924 %constants = ();
2925 %parameterdescs = ();
2926 %parametertypes = ();
2927 @parameterlist = ();
2928 %sections = ();
2929 @sectionlist = ();
2930 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002931 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 }
2933 elsif (/$doc_content/)
2934 {
2935 if ( $1 eq "" )
2936 {
2937 $contents .= $blankline;
2938 }
2939 else
2940 {
2941 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002942 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002943 }
2944 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 }
2946 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002947 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002948 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08002949 print STDERR " Was looking for '$_'.\n" for keys %function_table;
2950 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 if ($output_mode eq "xml") {
2952 # The template wants at least one RefEntry here; make one.
2953 print "<refentry>\n";
2954 print " <refnamediv>\n";
2955 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01002956 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 print " </refname>\n";
2958 print " <refpurpose>\n";
2959 print " Document generation inconsistency\n";
2960 print " </refpurpose>\n";
2961 print " </refnamediv>\n";
2962 print " <refsect1>\n";
2963 print " <title>\n";
2964 print " Oops\n";
2965 print " </title>\n";
2966 print " <warning>\n";
2967 print " <para>\n";
2968 print " The template for this document tried to insert\n";
2969 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01002970 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 print " but none was found.\n";
2972 print " This dummy section is inserted to allow\n";
2973 print " generation to continue.\n";
2974 print " </para>\n";
2975 print " </warning>\n";
2976 print " </refsect1>\n";
2977 print "</refentry>\n";
2978 }
2979 }
2980}
Randy Dunlap8484baa2011-01-05 16:28:43 -08002981
2982
2983$kernelversion = get_kernel_version();
2984
2985# generate a sequence of code that will splice in highlighting information
2986# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02002987for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03002988 my $pattern = $highlights[$k][0];
2989 my $result = $highlights[$k][1];
2990# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
2991 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08002992}
2993
2994# Read the file that maps relative names to absolute names for
2995# separate source and object directories and for shadow trees.
2996if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
2997 my ($relname, $absname);
2998 while(<SOURCE_MAP>) {
2999 chop();
3000 ($relname, $absname) = (split())[0..1];
3001 $relname =~ s:^/+::;
3002 $source_map{$relname} = $absname;
3003 }
3004 close(SOURCE_MAP);
3005}
3006
3007foreach (@ARGV) {
3008 chomp;
3009 process_file($_);
3010}
3011if ($verbose && $errors) {
3012 print STDERR "$errors errors\n";
3013}
3014if ($verbose && $warnings) {
3015 print STDERR "$warnings warnings\n";
3016}
3017
3018exit($errors);