blob: dd08944b0a6f744f7d34707a510de143686cb5df [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``"],
283 [$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>`"],
286 [$type_struct, "\\:c\\:type\\:`struct \$1 <\$1>`"],
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300287 [$type_param, "**\$1**"]
288 );
289my $blankline_rst = "\n";
290
Johannes Bergeda603f2010-09-11 15:55:22 -0700291# list mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300292my @highlights_list = (
293 [$type_constant, "\$1"],
294 [$type_func, "\$1"],
295 [$type_struct, "\$1"],
296 [$type_param, "\$1"]
297 );
Johannes Bergeda603f2010-09-11 15:55:22 -0700298my $blankline_list = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300# read arguments
Randy Dunlapb9d973282009-06-09 08:50:38 -0700301if ($#ARGV == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 usage();
303}
304
Randy Dunlap8484baa2011-01-05 16:28:43 -0800305my $kernelversion;
306my $dohighlight = "";
307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308my $verbose = 0;
309my $output_mode = "man";
Daniel Santose314ba32012-10-04 17:15:08 -0700310my $output_preformatted = 0;
Johannes Berg4b445952007-10-24 15:08:48 -0700311my $no_doc_sections = 0;
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300312my @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313my $blankline = $blankline_man;
314my $modulename = "Kernel API";
Jani Nikulab6c3f452016-05-29 22:19:35 +0300315
316use constant {
317 OUTPUT_ALL => 0, # output all symbols and doc sections
318 OUTPUT_INCLUDE => 1, # output only specified symbols
319 OUTPUT_EXCLUDE => 2, # output everything except specified symbols
320 OUTPUT_EXPORTED => 3, # output exported symbols
321 OUTPUT_INTERNAL => 4, # output non-exported symbols
322};
323my $output_selection = OUTPUT_ALL;
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100324my $show_not_found = 0;
325
326my @build_time;
327if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
328 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
329 @build_time = gmtime($seconds);
330} else {
331 @build_time = localtime;
332}
333
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800334my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
335 'July', 'August', 'September', 'October',
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100336 'November', 'December')[$build_time[4]] .
337 " " . ($build_time[5]+1900);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Randy Dunlap8484baa2011-01-05 16:28:43 -0800339# Essentially these are globals.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700340# They probably want to be tidied up, made more localised or something.
341# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342# could cause "use of undefined value" or other bugs.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700343my ($function, %function_table, %parametertypes, $declaration_purpose);
344my ($type, $declaration_name, $return_type);
Ilya Dryomov1c32fd02010-02-26 13:06:03 -0800345my ($newsection, $newcontents, $prototype, $brcount, %source_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700347if (defined($ENV{'KBUILD_VERBOSE'})) {
348 $verbose = "$ENV{'KBUILD_VERBOSE'}";
349}
350
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800351# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
353# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
354# We keep track of number of generated entries and generate a dummy
355# if needs be to ensure the expanded template can be postprocessed
356# into html.
357my $section_counter = 0;
358
359my $lineprefix="";
360
Jani Nikula48af6062016-05-26 14:56:05 +0300361# Parser states
362use constant {
363 STATE_NORMAL => 0, # normal code
364 STATE_NAME => 1, # looking for function name
365 STATE_FIELD => 2, # scanning field start
366 STATE_PROTO => 3, # scanning prototype
367 STATE_DOCBLOCK => 4, # documentation block
368 STATE_INLINE => 5, # gathering documentation outside main block
369};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700371my $in_doc_sect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
Jani Nikula48af6062016-05-26 14:56:05 +0300373# Inline documentation state
374use constant {
375 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
376 STATE_INLINE_NAME => 1, # looking for member name (@foo:)
377 STATE_INLINE_TEXT => 2, # looking for member documentation
378 STATE_INLINE_END => 3, # done
379 STATE_INLINE_ERROR => 4, # error - Comment without header was found.
380 # Spit a warning as it's not
381 # proper kernel-doc and ignore the rest.
382};
383my $inline_doc_state;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385#declaration types: can be
386# 'function', 'struct', 'union', 'enum', 'typedef'
387my $decl_type;
388
389my $doc_special = "\@\%\$\&";
390
391my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
392my $doc_end = '\*/';
393my $doc_com = '\s*\*\s*';
Daniel Santos12ae6772012-10-04 17:15:10 -0700394my $doc_com_body = '\s*\* ?';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700395my $doc_decl = $doc_com . '(\w+)';
396my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700397my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700398my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Jani Nikula48af6062016-05-26 14:56:05 +0300399my $doc_inline_start = '^\s*/\*\*\s*$';
400my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
401my $doc_inline_end = '^\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200402my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
404my %constants;
405my %parameterdescs;
406my @parameterlist;
407my %sections;
408my @sectionlist;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800409my $sectcheck;
410my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412my $contents = "";
413my $section_default = "Description"; # default section
414my $section_intro = "Introduction";
415my $section = $section_default;
416my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100417my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
419my $undescribed = "-- undescribed --";
420
421reset_state();
422
423while ($ARGV[0] =~ m/^-(.*)/) {
424 my $cmd = shift @ARGV;
425 if ($cmd eq "-html") {
426 $output_mode = "html";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300427 @highlights = @highlights_html;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200429 } elsif ($cmd eq "-html5") {
430 $output_mode = "html5";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300431 @highlights = @highlights_html5;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200432 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 } elsif ($cmd eq "-man") {
434 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300435 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 $blankline = $blankline_man;
437 } elsif ($cmd eq "-text") {
438 $output_mode = "text";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300439 @highlights = @highlights_text;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 $blankline = $blankline_text;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300441 } elsif ($cmd eq "-rst") {
442 $output_mode = "rst";
443 @highlights = @highlights_rst;
444 $blankline = $blankline_rst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 } elsif ($cmd eq "-docbook") {
446 $output_mode = "xml";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300447 @highlights = @highlights_xml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700449 } elsif ($cmd eq "-list") {
450 $output_mode = "list";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300451 @highlights = @highlights_list;
Johannes Bergeda603f2010-09-11 15:55:22 -0700452 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 } elsif ($cmd eq "-gnome") {
454 $output_mode = "gnome";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300455 @highlights = @highlights_gnome;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 $blankline = $blankline_gnome;
457 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
458 $modulename = shift @ARGV;
459 } elsif ($cmd eq "-function") { # to only output specific functions
Jani Nikulab6c3f452016-05-29 22:19:35 +0300460 $output_selection = OUTPUT_INCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 $function = shift @ARGV;
462 $function_table{$function} = 1;
Jani Nikulab6c3f452016-05-29 22:19:35 +0300463 } elsif ($cmd eq "-nofunction") { # output all except specific functions
464 $output_selection = OUTPUT_EXCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 $function = shift @ARGV;
466 $function_table{$function} = 1;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200467 } elsif ($cmd eq "-export") { # only exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300468 $output_selection = OUTPUT_EXPORTED;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200469 %function_table = ()
470 } elsif ($cmd eq "-internal") { # only non-exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300471 $output_selection = OUTPUT_INTERNAL;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200472 %function_table = ()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 } elsif ($cmd eq "-v") {
474 $verbose = 1;
475 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
476 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700477 } elsif ($cmd eq '-no-doc-sections') {
478 $no_doc_sections = 1;
Johannes Berge946c43a2013-11-12 15:11:12 -0800479 } elsif ($cmd eq '-show-not-found') {
480 $show_not_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 }
482}
483
Randy Dunlap8484baa2011-01-05 16:28:43 -0800484# continue execution near EOF;
485
Borislav Petkov53f049f2007-05-08 00:30:54 -0700486# get kernel version from env
487sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700488 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700489
490 if (defined($ENV{'KERNELVERSION'})) {
491 $version = $ENV{'KERNELVERSION'};
492 }
493 return $version;
494}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
496##
497# dumps section contents to arrays/hashes intended for that purpose.
498#
499sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700500 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 my $name = shift;
502 my $contents = join "\n", @_;
503
504 if ($name =~ m/$type_constant/) {
505 $name = $1;
506# print STDERR "constant section '$1' = '$contents'\n";
507 $constants{$name} = $contents;
508 } elsif ($name =~ m/$type_param/) {
509# print STDERR "parameter def '$1' = '$contents'\n";
510 $name = $1;
511 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800512 $sectcheck = $sectcheck . $name . " ";
Randy Dunlapced69092008-12-01 13:14:03 -0800513 } elsif ($name eq "@\.\.\.") {
514# print STDERR "parameter def '...' = '$contents'\n";
515 $name = "...";
516 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800517 $sectcheck = $sectcheck . $name . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 } else {
519# print STDERR "other section '$name' = '$contents'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700520 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Bart Van Assched40e1e62015-09-04 15:43:21 -0700521 print STDERR "${file}:$.: error: duplicate section name '$name'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700522 ++$errors;
523 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 $sections{$name} = $contents;
525 push @sectionlist, $name;
526 }
527}
528
529##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700530# dump DOC: section after checking that it should go out
531#
532sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700533 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700534 my $name = shift;
535 my $contents = join "\n", @_;
536
Johannes Berg4b445952007-10-24 15:08:48 -0700537 if ($no_doc_sections) {
538 return;
539 }
540
Jani Nikulab6c3f452016-05-29 22:19:35 +0300541 if (($output_selection == OUTPUT_ALL) ||
542 ($output_selection == OUTPUT_INCLUDE &&
543 defined($function_table{$name})) ||
544 ($output_selection == OUTPUT_EXCLUDE &&
545 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700546 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700547 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700548 output_blockhead({'sectionlist' => \@sectionlist,
549 'sections' => \%sections,
550 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300551 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700552 }
553}
554
555##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556# output function
557#
558# parameterdescs, a hash.
559# function => "function name"
560# parameterlist => @list of parameters
561# parameterdescs => %parameter descriptions
562# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800563# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800564#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
566sub output_highlight {
567 my $contents = join "\n",@_;
568 my $line;
569
570# DEBUG
571# if (!defined $contents) {
572# use Carp;
573# confess "output_highlight got called with no args?\n";
574# }
575
Dan Luedtke1b40c192012-08-12 10:46:15 +0200576 if ($output_mode eq "html" || $output_mode eq "html5" ||
577 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700578 $contents = local_unescape($contents);
579 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800580 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700581 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700582# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 eval $dohighlight;
584 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700585# print STDERR "contents af:$contents\n";
586
Dan Luedtke1b40c192012-08-12 10:46:15 +0200587# strip whitespaces when generating html5
588 if ($output_mode eq "html5") {
589 $contents =~ s/^\s+//;
590 $contents =~ s/\s+$//;
591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700593 if (! $output_preformatted) {
594 $line =~ s/^\s*//;
595 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700596 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700597 if (! $output_preformatted) {
598 print $lineprefix, local_unescape($blankline);
599 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700601 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700602 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
603 print "\\&$line";
604 } else {
605 print $lineprefix, $line;
606 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 }
608 print "\n";
609 }
610}
611
Dan Luedtke1b40c192012-08-12 10:46:15 +0200612# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613sub output_section_html(%) {
614 my %args = %{$_[0]};
615 my $section;
616
617 foreach $section (@{$args{'sectionlist'}}) {
618 print "<h3>$section</h3>\n";
619 print "<blockquote>\n";
620 output_highlight($args{'sections'}{$section});
621 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800622 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623}
624
625# output enum in html
626sub output_enum_html(%) {
627 my %args = %{$_[0]};
628 my ($parameter);
629 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700630 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
Randy Dunlapb9d973282009-06-09 08:50:38 -0700632 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 $count = 0;
634 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700635 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 if ($count != $#{$args{'parameterlist'}}) {
637 $count++;
638 print ",\n";
639 }
640 print "<br>";
641 }
642 print "};<br>\n";
643
644 print "<h3>Constants</h3>\n";
645 print "<dl>\n";
646 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700647 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 print "<dd>";
649 output_highlight($args{'parameterdescs'}{$parameter});
650 }
651 print "</dl>\n";
652 output_section_html(@_);
653 print "<hr>\n";
654}
655
Randy Dunlapd28bee02006-02-01 03:06:57 -0800656# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657sub output_typedef_html(%) {
658 my %args = %{$_[0]};
659 my ($parameter);
660 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700661 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Randy Dunlapb9d973282009-06-09 08:50:38 -0700663 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 output_section_html(@_);
665 print "<hr>\n";
666}
667
668# output struct in html
669sub output_struct_html(%) {
670 my %args = %{$_[0]};
671 my ($parameter);
672
Randy Dunlapb9d973282009-06-09 08:50:38 -0700673 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
674 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 foreach $parameter (@{$args{'parameterlist'}}) {
676 if ($parameter =~ /^#/) {
677 print "$parameter<br>\n";
678 next;
679 }
680 my $parameter_name = $parameter;
681 $parameter_name =~ s/\[.*//;
682
Randy Dunlap3c308792007-05-08 00:24:39 -0700683 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 $type = $args{'parametertypes'}{$parameter};
685 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
686 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700687 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700689 # bitfield
690 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700692 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 }
694 }
695 print "};<br>\n";
696
697 print "<h3>Members</h3>\n";
698 print "<dl>\n";
699 foreach $parameter (@{$args{'parameterlist'}}) {
700 ($parameter =~ /^#/) && next;
701
702 my $parameter_name = $parameter;
703 $parameter_name =~ s/\[.*//;
704
Randy Dunlap3c308792007-05-08 00:24:39 -0700705 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700706 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 print "<dd>";
708 output_highlight($args{'parameterdescs'}{$parameter_name});
709 }
710 print "</dl>\n";
711 output_section_html(@_);
712 print "<hr>\n";
713}
714
715# output function in html
716sub output_function_html(%) {
717 my %args = %{$_[0]};
718 my ($parameter, $section);
719 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Randy Dunlapb9d973282009-06-09 08:50:38 -0700721 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
722 print "<i>" . $args{'functiontype'} . "</i>\n";
723 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 print "(";
725 $count = 0;
726 foreach $parameter (@{$args{'parameterlist'}}) {
727 $type = $args{'parametertypes'}{$parameter};
728 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
729 # pointer-to-function
730 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
731 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700732 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 }
734 if ($count != $#{$args{'parameterlist'}}) {
735 $count++;
736 print ",\n";
737 }
738 }
739 print ")\n";
740
741 print "<h3>Arguments</h3>\n";
742 print "<dl>\n";
743 foreach $parameter (@{$args{'parameterlist'}}) {
744 my $parameter_name = $parameter;
745 $parameter_name =~ s/\[.*//;
746
Randy Dunlap3c308792007-05-08 00:24:39 -0700747 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700748 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 print "<dd>";
750 output_highlight($args{'parameterdescs'}{$parameter_name});
751 }
752 print "</dl>\n";
753 output_section_html(@_);
754 print "<hr>\n";
755}
756
Johannes Bergb112e0f2007-10-24 15:08:48 -0700757# output DOC: block header in html
758sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 my %args = %{$_[0]};
760 my ($parameter, $section);
761 my $count;
762
763 foreach $section (@{$args{'sectionlist'}}) {
764 print "<h3>$section</h3>\n";
765 print "<ul>\n";
766 output_highlight($args{'sections'}{$section});
767 print "</ul>\n";
768 }
769 print "<hr>\n";
770}
771
Dan Luedtke1b40c192012-08-12 10:46:15 +0200772# output sections in html5
773sub output_section_html5(%) {
774 my %args = %{$_[0]};
775 my $section;
776
777 foreach $section (@{$args{'sectionlist'}}) {
778 print "<section>\n";
779 print "<h1>$section</h1>\n";
780 print "<p>\n";
781 output_highlight($args{'sections'}{$section});
782 print "</p>\n";
783 print "</section>\n";
784 }
785}
786
787# output enum in html5
788sub output_enum_html5(%) {
789 my %args = %{$_[0]};
790 my ($parameter);
791 my $count;
792 my $html5id;
793
794 $html5id = $args{'enum'};
795 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
796 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
797 print "<h1>enum " . $args{'enum'} . "</h1>\n";
798 print "<ol class=\"code\">\n";
799 print "<li>";
800 print "<span class=\"keyword\">enum</span> ";
801 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
802 print "</li>\n";
803 $count = 0;
804 foreach $parameter (@{$args{'parameterlist'}}) {
805 print "<li class=\"indent\">";
806 print "<span class=\"param\">" . $parameter . "</span>";
807 if ($count != $#{$args{'parameterlist'}}) {
808 $count++;
809 print ",";
810 }
811 print "</li>\n";
812 }
813 print "<li>};</li>\n";
814 print "</ol>\n";
815
816 print "<section>\n";
817 print "<h1>Constants</h1>\n";
818 print "<dl>\n";
819 foreach $parameter (@{$args{'parameterlist'}}) {
820 print "<dt>" . $parameter . "</dt>\n";
821 print "<dd>";
822 output_highlight($args{'parameterdescs'}{$parameter});
823 print "</dd>\n";
824 }
825 print "</dl>\n";
826 print "</section>\n";
827 output_section_html5(@_);
828 print "</article>\n";
829}
830
831# output typedef in html5
832sub output_typedef_html5(%) {
833 my %args = %{$_[0]};
834 my ($parameter);
835 my $count;
836 my $html5id;
837
838 $html5id = $args{'typedef'};
839 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
840 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
841 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
842
843 print "<ol class=\"code\">\n";
844 print "<li>";
845 print "<span class=\"keyword\">typedef</span> ";
846 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
847 print "</li>\n";
848 print "</ol>\n";
849 output_section_html5(@_);
850 print "</article>\n";
851}
852
853# output struct in html5
854sub output_struct_html5(%) {
855 my %args = %{$_[0]};
856 my ($parameter);
857 my $html5id;
858
859 $html5id = $args{'struct'};
860 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
861 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
862 print "<hgroup>\n";
863 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
864 print "<h2>". $args{'purpose'} . "</h2>\n";
865 print "</hgroup>\n";
866 print "<ol class=\"code\">\n";
867 print "<li>";
868 print "<span class=\"type\">" . $args{'type'} . "</span> ";
869 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
870 print "</li>\n";
871 foreach $parameter (@{$args{'parameterlist'}}) {
872 print "<li class=\"indent\">";
873 if ($parameter =~ /^#/) {
874 print "<span class=\"param\">" . $parameter ."</span>\n";
875 print "</li>\n";
876 next;
877 }
878 my $parameter_name = $parameter;
879 $parameter_name =~ s/\[.*//;
880
881 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
882 $type = $args{'parametertypes'}{$parameter};
883 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
884 # pointer-to-function
885 print "<span class=\"type\">$1</span> ";
886 print "<span class=\"param\">$parameter</span>";
887 print "<span class=\"type\">)</span> ";
888 print "(<span class=\"args\">$2</span>);";
889 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
890 # bitfield
891 print "<span class=\"type\">$1</span> ";
892 print "<span class=\"param\">$parameter</span>";
893 print "<span class=\"bits\">$2</span>;";
894 } else {
895 print "<span class=\"type\">$type</span> ";
896 print "<span class=\"param\">$parameter</span>;";
897 }
898 print "</li>\n";
899 }
900 print "<li>};</li>\n";
901 print "</ol>\n";
902
903 print "<section>\n";
904 print "<h1>Members</h1>\n";
905 print "<dl>\n";
906 foreach $parameter (@{$args{'parameterlist'}}) {
907 ($parameter =~ /^#/) && next;
908
909 my $parameter_name = $parameter;
910 $parameter_name =~ s/\[.*//;
911
912 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
913 print "<dt>" . $parameter . "</dt>\n";
914 print "<dd>";
915 output_highlight($args{'parameterdescs'}{$parameter_name});
916 print "</dd>\n";
917 }
918 print "</dl>\n";
919 print "</section>\n";
920 output_section_html5(@_);
921 print "</article>\n";
922}
923
924# output function in html5
925sub output_function_html5(%) {
926 my %args = %{$_[0]};
927 my ($parameter, $section);
928 my $count;
929 my $html5id;
930
931 $html5id = $args{'function'};
932 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
933 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
934 print "<hgroup>\n";
935 print "<h1>" . $args{'function'} . "</h1>";
936 print "<h2>" . $args{'purpose'} . "</h2>\n";
937 print "</hgroup>\n";
938 print "<ol class=\"code\">\n";
939 print "<li>";
940 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
941 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
942 print "</li>";
943 $count = 0;
944 foreach $parameter (@{$args{'parameterlist'}}) {
945 print "<li class=\"indent\">";
946 $type = $args{'parametertypes'}{$parameter};
947 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
948 # pointer-to-function
949 print "<span class=\"type\">$1</span> ";
950 print "<span class=\"param\">$parameter</span>";
951 print "<span class=\"type\">)</span> ";
952 print "(<span class=\"args\">$2</span>)";
953 } else {
954 print "<span class=\"type\">$type</span> ";
955 print "<span class=\"param\">$parameter</span>";
956 }
957 if ($count != $#{$args{'parameterlist'}}) {
958 $count++;
959 print ",";
960 }
961 print "</li>\n";
962 }
963 print "<li>)</li>\n";
964 print "</ol>\n";
965
966 print "<section>\n";
967 print "<h1>Arguments</h1>\n";
968 print "<p>\n";
969 print "<dl>\n";
970 foreach $parameter (@{$args{'parameterlist'}}) {
971 my $parameter_name = $parameter;
972 $parameter_name =~ s/\[.*//;
973
974 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
975 print "<dt>" . $parameter . "</dt>\n";
976 print "<dd>";
977 output_highlight($args{'parameterdescs'}{$parameter_name});
978 print "</dd>\n";
979 }
980 print "</dl>\n";
981 print "</section>\n";
982 output_section_html5(@_);
983 print "</article>\n";
984}
985
986# output DOC: block header in html5
987sub output_blockhead_html5(%) {
988 my %args = %{$_[0]};
989 my ($parameter, $section);
990 my $count;
991 my $html5id;
992
993 foreach $section (@{$args{'sectionlist'}}) {
994 $html5id = $section;
995 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
996 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
997 print "<h1>$section</h1>\n";
998 print "<p>\n";
999 output_highlight($args{'sections'}{$section});
1000 print "</p>\n";
1001 }
1002 print "</article>\n";
1003}
1004
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005sub output_section_xml(%) {
1006 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001007 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 # print out each section
1009 $lineprefix=" ";
1010 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001011 print "<refsect1>\n";
1012 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001014 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001015 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001016 } else {
1017 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 }
1019 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001020 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001022 print "</programlisting></informalexample>\n";
1023 } else {
1024 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001026 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 }
1028}
1029
1030# output function in XML DocBook
1031sub output_function_xml(%) {
1032 my %args = %{$_[0]};
1033 my ($parameter, $section);
1034 my $count;
1035 my $id;
1036
Randy Dunlapb9d973282009-06-09 08:50:38 -07001037 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 $id =~ s/[^A-Za-z0-9]/-/g;
1039
Pavel Pisa5449bc92007-02-10 01:45:37 -08001040 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001041 print "<refentryinfo>\n";
1042 print " <title>LINUX</title>\n";
1043 print " <productname>Kernel Hackers Manual</productname>\n";
1044 print " <date>$man_date</date>\n";
1045 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001047 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001048 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001049 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 print "</refmeta>\n";
1051 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001052 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 print " <refpurpose>\n";
1054 print " ";
1055 output_highlight ($args{'purpose'});
1056 print " </refpurpose>\n";
1057 print "</refnamediv>\n";
1058
1059 print "<refsynopsisdiv>\n";
1060 print " <title>Synopsis</title>\n";
1061 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001062 print " <funcdef>" . $args{'functiontype'} . " ";
1063 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
1065 $count = 0;
1066 if ($#{$args{'parameterlist'}} >= 0) {
1067 foreach $parameter (@{$args{'parameterlist'}}) {
1068 $type = $args{'parametertypes'}{$parameter};
1069 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1070 # pointer-to-function
1071 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1072 print " <funcparams>$2</funcparams></paramdef>\n";
1073 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001074 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075 print " <parameter>$parameter</parameter></paramdef>\n";
1076 }
1077 }
1078 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001079 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 }
1081 print " </funcprototype></funcsynopsis>\n";
1082 print "</refsynopsisdiv>\n";
1083
1084 # print parameters
1085 print "<refsect1>\n <title>Arguments</title>\n";
1086 if ($#{$args{'parameterlist'}} >= 0) {
1087 print " <variablelist>\n";
1088 foreach $parameter (@{$args{'parameterlist'}}) {
1089 my $parameter_name = $parameter;
1090 $parameter_name =~ s/\[.*//;
1091
1092 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1093 print " <listitem>\n <para>\n";
1094 $lineprefix=" ";
1095 output_highlight($args{'parameterdescs'}{$parameter_name});
1096 print " </para>\n </listitem>\n </varlistentry>\n";
1097 }
1098 print " </variablelist>\n";
1099 } else {
1100 print " <para>\n None\n </para>\n";
1101 }
1102 print "</refsect1>\n";
1103
1104 output_section_xml(@_);
1105 print "</refentry>\n\n";
1106}
1107
1108# output struct in XML DocBook
1109sub output_struct_xml(%) {
1110 my %args = %{$_[0]};
1111 my ($parameter, $section);
1112 my $id;
1113
Randy Dunlapb9d973282009-06-09 08:50:38 -07001114 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 $id =~ s/[^A-Za-z0-9]/-/g;
1116
Pavel Pisa5449bc92007-02-10 01:45:37 -08001117 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001118 print "<refentryinfo>\n";
1119 print " <title>LINUX</title>\n";
1120 print " <productname>Kernel Hackers Manual</productname>\n";
1121 print " <date>$man_date</date>\n";
1122 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001124 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001125 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001126 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 print "</refmeta>\n";
1128 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001129 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 print " <refpurpose>\n";
1131 print " ";
1132 output_highlight ($args{'purpose'});
1133 print " </refpurpose>\n";
1134 print "</refnamediv>\n";
1135
1136 print "<refsynopsisdiv>\n";
1137 print " <title>Synopsis</title>\n";
1138 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001139 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 foreach $parameter (@{$args{'parameterlist'}}) {
1141 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001142 my $prm = $parameter;
1143 # convert data read & converted thru xml_escape() into &xyz; format:
1144 # This allows us to have #define macros interspersed in a struct.
1145 $prm =~ s/\\\\\\/\&/g;
1146 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 next;
1148 }
1149
1150 my $parameter_name = $parameter;
1151 $parameter_name =~ s/\[.*//;
1152
1153 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001154 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 $type = $args{'parametertypes'}{$parameter};
1156 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1157 # pointer-to-function
1158 print " $1 $parameter) ($2);\n";
1159 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001160 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 print " $1 $parameter$2;\n";
1162 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001163 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 }
1165 }
1166 print "};";
1167 print " </programlisting>\n";
1168 print "</refsynopsisdiv>\n";
1169
1170 print " <refsect1>\n";
1171 print " <title>Members</title>\n";
1172
Randy Dunlap39f00c02008-09-22 13:57:44 -07001173 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 print " <variablelist>\n";
1175 foreach $parameter (@{$args{'parameterlist'}}) {
1176 ($parameter =~ /^#/) && next;
1177
1178 my $parameter_name = $parameter;
1179 $parameter_name =~ s/\[.*//;
1180
1181 defined($args{'parameterdescs'}{$parameter_name}) || next;
1182 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1183 print " <varlistentry>";
1184 print " <term>$parameter</term>\n";
1185 print " <listitem><para>\n";
1186 output_highlight($args{'parameterdescs'}{$parameter_name});
1187 print " </para></listitem>\n";
1188 print " </varlistentry>\n";
1189 }
1190 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001191 } else {
1192 print " <para>\n None\n </para>\n";
1193 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 print " </refsect1>\n";
1195
1196 output_section_xml(@_);
1197
1198 print "</refentry>\n\n";
1199}
1200
1201# output enum in XML DocBook
1202sub output_enum_xml(%) {
1203 my %args = %{$_[0]};
1204 my ($parameter, $section);
1205 my $count;
1206 my $id;
1207
Randy Dunlapb9d973282009-06-09 08:50:38 -07001208 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 $id =~ s/[^A-Za-z0-9]/-/g;
1210
Pavel Pisa5449bc92007-02-10 01:45:37 -08001211 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001212 print "<refentryinfo>\n";
1213 print " <title>LINUX</title>\n";
1214 print " <productname>Kernel Hackers Manual</productname>\n";
1215 print " <date>$man_date</date>\n";
1216 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001218 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001219 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001220 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 print "</refmeta>\n";
1222 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001223 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 print " <refpurpose>\n";
1225 print " ";
1226 output_highlight ($args{'purpose'});
1227 print " </refpurpose>\n";
1228 print "</refnamediv>\n";
1229
1230 print "<refsynopsisdiv>\n";
1231 print " <title>Synopsis</title>\n";
1232 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001233 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 $count = 0;
1235 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001236 print " $parameter";
1237 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 $count++;
1239 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001240 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 print "\n";
1242 }
1243 print "};";
1244 print " </programlisting>\n";
1245 print "</refsynopsisdiv>\n";
1246
1247 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001248 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 print " <variablelist>\n";
1250 foreach $parameter (@{$args{'parameterlist'}}) {
1251 my $parameter_name = $parameter;
1252 $parameter_name =~ s/\[.*//;
1253
1254 print " <varlistentry>";
1255 print " <term>$parameter</term>\n";
1256 print " <listitem><para>\n";
1257 output_highlight($args{'parameterdescs'}{$parameter_name});
1258 print " </para></listitem>\n";
1259 print " </varlistentry>\n";
1260 }
1261 print " </variablelist>\n";
1262 print "</refsect1>\n";
1263
1264 output_section_xml(@_);
1265
1266 print "</refentry>\n\n";
1267}
1268
1269# output typedef in XML DocBook
1270sub output_typedef_xml(%) {
1271 my %args = %{$_[0]};
1272 my ($parameter, $section);
1273 my $id;
1274
Randy Dunlapb9d973282009-06-09 08:50:38 -07001275 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 $id =~ s/[^A-Za-z0-9]/-/g;
1277
Pavel Pisa5449bc92007-02-10 01:45:37 -08001278 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001279 print "<refentryinfo>\n";
1280 print " <title>LINUX</title>\n";
1281 print " <productname>Kernel Hackers Manual</productname>\n";
1282 print " <date>$man_date</date>\n";
1283 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001285 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001286 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 print "</refmeta>\n";
1288 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001289 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 print " <refpurpose>\n";
1291 print " ";
1292 output_highlight ($args{'purpose'});
1293 print " </refpurpose>\n";
1294 print "</refnamediv>\n";
1295
1296 print "<refsynopsisdiv>\n";
1297 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001298 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 print "</refsynopsisdiv>\n";
1300
1301 output_section_xml(@_);
1302
1303 print "</refentry>\n\n";
1304}
1305
1306# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001307sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 my %args = %{$_[0]};
1309 my ($parameter, $section);
1310 my $count;
1311
1312 my $id = $args{'module'};
1313 $id =~ s/[^A-Za-z0-9]/-/g;
1314
1315 # print out each section
1316 $lineprefix=" ";
1317 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001318 if (!$args{'content-only'}) {
1319 print "<refsect1>\n <title>$section</title>\n";
1320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 if ($section =~ m/EXAMPLE/i) {
1322 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001323 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001324 } else {
1325 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 }
1327 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001328 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 if ($section =~ m/EXAMPLE/i) {
1330 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001331 } else {
1332 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001334 if (!$args{'content-only'}) {
1335 print "\n</refsect1>\n";
1336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 }
1338
1339 print "\n\n";
1340}
1341
1342# output in XML DocBook
1343sub output_function_gnome {
1344 my %args = %{$_[0]};
1345 my ($parameter, $section);
1346 my $count;
1347 my $id;
1348
Randy Dunlapb9d973282009-06-09 08:50:38 -07001349 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 $id =~ s/[^A-Za-z0-9]/-/g;
1351
1352 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001353 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
1355 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001356 print " <funcdef>" . $args{'functiontype'} . " ";
1357 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 print "</function></funcdef>\n";
1359
1360 $count = 0;
1361 if ($#{$args{'parameterlist'}} >= 0) {
1362 foreach $parameter (@{$args{'parameterlist'}}) {
1363 $type = $args{'parametertypes'}{$parameter};
1364 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1365 # pointer-to-function
1366 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1367 print " <funcparams>$2</funcparams></paramdef>\n";
1368 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001369 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 print " <parameter>$parameter</parameter></paramdef>\n";
1371 }
1372 }
1373 } else {
1374 print " <void>\n";
1375 }
1376 print " </funcsynopsis>\n";
1377 if ($#{$args{'parameterlist'}} >= 0) {
1378 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1379 print "<tgroup cols=\"2\">\n";
1380 print "<colspec colwidth=\"2*\">\n";
1381 print "<colspec colwidth=\"8*\">\n";
1382 print "<tbody>\n";
1383 foreach $parameter (@{$args{'parameterlist'}}) {
1384 my $parameter_name = $parameter;
1385 $parameter_name =~ s/\[.*//;
1386
1387 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1388 print " <entry>\n";
1389 $lineprefix=" ";
1390 output_highlight($args{'parameterdescs'}{$parameter_name});
1391 print " </entry></row>\n";
1392 }
1393 print " </tbody></tgroup></informaltable>\n";
1394 } else {
1395 print " <para>\n None\n </para>\n";
1396 }
1397
1398 # print out each section
1399 $lineprefix=" ";
1400 foreach $section (@{$args{'sectionlist'}}) {
1401 print "<simplesect>\n <title>$section</title>\n";
1402 if ($section =~ m/EXAMPLE/i) {
1403 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001404 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 } else {
1406 }
1407 print "<para>\n";
1408 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001409 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 print "</para>\n";
1411 if ($section =~ m/EXAMPLE/i) {
1412 print "</programlisting></example>\n";
1413 } else {
1414 }
1415 print " </simplesect>\n";
1416 }
1417
1418 print "</sect2>\n\n";
1419}
1420
1421##
1422# output function in man
1423sub output_function_man(%) {
1424 my %args = %{$_[0]};
1425 my ($parameter, $section);
1426 my $count;
1427
1428 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1429
1430 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001431 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432
1433 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001434 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001435 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001436 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001437 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 $count = 0;
1440 my $parenth = "(";
1441 my $post = ",";
1442 foreach my $parameter (@{$args{'parameterlist'}}) {
1443 if ($count == $#{$args{'parameterlist'}}) {
1444 $post = ");";
1445 }
1446 $type = $args{'parametertypes'}{$parameter};
1447 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1448 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001449 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 } else {
1451 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001452 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 }
1454 $count++;
1455 $parenth = "";
1456 }
1457
1458 print ".SH ARGUMENTS\n";
1459 foreach $parameter (@{$args{'parameterlist'}}) {
1460 my $parameter_name = $parameter;
1461 $parameter_name =~ s/\[.*//;
1462
Randy Dunlapb9d973282009-06-09 08:50:38 -07001463 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 output_highlight($args{'parameterdescs'}{$parameter_name});
1465 }
1466 foreach $section (@{$args{'sectionlist'}}) {
1467 print ".SH \"", uc $section, "\"\n";
1468 output_highlight($args{'sections'}{$section});
1469 }
1470}
1471
1472##
1473# output enum in man
1474sub output_enum_man(%) {
1475 my %args = %{$_[0]};
1476 my ($parameter, $section);
1477 my $count;
1478
1479 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1480
1481 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001482 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
1484 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001485 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 $count = 0;
1487 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001488 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 if ($count == $#{$args{'parameterlist'}}) {
1490 print "\n};\n";
1491 last;
1492 }
1493 else {
1494 print ", \n.br\n";
1495 }
1496 $count++;
1497 }
1498
1499 print ".SH Constants\n";
1500 foreach $parameter (@{$args{'parameterlist'}}) {
1501 my $parameter_name = $parameter;
1502 $parameter_name =~ s/\[.*//;
1503
Randy Dunlapb9d973282009-06-09 08:50:38 -07001504 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 output_highlight($args{'parameterdescs'}{$parameter_name});
1506 }
1507 foreach $section (@{$args{'sectionlist'}}) {
1508 print ".SH \"$section\"\n";
1509 output_highlight($args{'sections'}{$section});
1510 }
1511}
1512
1513##
1514# output struct in man
1515sub output_struct_man(%) {
1516 my %args = %{$_[0]};
1517 my ($parameter, $section);
1518
Randy Dunlapb9d973282009-06-09 08:50:38 -07001519 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
1521 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001522 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523
1524 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001525 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
1527 foreach my $parameter (@{$args{'parameterlist'}}) {
1528 if ($parameter =~ /^#/) {
1529 print ".BI \"$parameter\"\n.br\n";
1530 next;
1531 }
1532 my $parameter_name = $parameter;
1533 $parameter_name =~ s/\[.*//;
1534
Randy Dunlap3c308792007-05-08 00:24:39 -07001535 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 $type = $args{'parametertypes'}{$parameter};
1537 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1538 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001539 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001541 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001542 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 } else {
1544 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001545 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 }
1547 print "\n.br\n";
1548 }
1549 print "};\n.br\n";
1550
Randy Dunlapc51d3dac2006-06-25 05:49:14 -07001551 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 foreach $parameter (@{$args{'parameterlist'}}) {
1553 ($parameter =~ /^#/) && next;
1554
1555 my $parameter_name = $parameter;
1556 $parameter_name =~ s/\[.*//;
1557
Randy Dunlap3c308792007-05-08 00:24:39 -07001558 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001559 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 output_highlight($args{'parameterdescs'}{$parameter_name});
1561 }
1562 foreach $section (@{$args{'sectionlist'}}) {
1563 print ".SH \"$section\"\n";
1564 output_highlight($args{'sections'}{$section});
1565 }
1566}
1567
1568##
1569# output typedef in man
1570sub output_typedef_man(%) {
1571 my %args = %{$_[0]};
1572 my ($parameter, $section);
1573
1574 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1575
1576 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001577 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
1579 foreach $section (@{$args{'sectionlist'}}) {
1580 print ".SH \"$section\"\n";
1581 output_highlight($args{'sections'}{$section});
1582 }
1583}
1584
Johannes Bergb112e0f2007-10-24 15:08:48 -07001585sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 my %args = %{$_[0]};
1587 my ($parameter, $section);
1588 my $count;
1589
1590 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1591
1592 foreach $section (@{$args{'sectionlist'}}) {
1593 print ".SH \"$section\"\n";
1594 output_highlight($args{'sections'}{$section});
1595 }
1596}
1597
1598##
1599# output in text
1600sub output_function_text(%) {
1601 my %args = %{$_[0]};
1602 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001603 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604
Randy Dunlapf47634b2006-07-01 04:36:36 -07001605 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001606 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001607
1608 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001609 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001610 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001611 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001612 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001613 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001615
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 my $count = 0;
1617 foreach my $parameter (@{$args{'parameterlist'}}) {
1618 $type = $args{'parametertypes'}{$parameter};
1619 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1620 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001621 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001623 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 }
1625 if ($count != $#{$args{'parameterlist'}}) {
1626 $count++;
1627 print ",\n";
1628 print " " x length($start);
1629 } else {
1630 print ");\n\n";
1631 }
1632 }
1633
1634 print "Arguments:\n\n";
1635 foreach $parameter (@{$args{'parameterlist'}}) {
1636 my $parameter_name = $parameter;
1637 $parameter_name =~ s/\[.*//;
1638
Randy Dunlapb9d973282009-06-09 08:50:38 -07001639 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 }
1641 output_section_text(@_);
1642}
1643
1644#output sections in text
1645sub output_section_text(%) {
1646 my %args = %{$_[0]};
1647 my $section;
1648
1649 print "\n";
1650 foreach $section (@{$args{'sectionlist'}}) {
1651 print "$section:\n\n";
1652 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001653 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 print "\n\n";
1655}
1656
1657# output enum in text
1658sub output_enum_text(%) {
1659 my %args = %{$_[0]};
1660 my ($parameter);
1661 my $count;
1662 print "Enum:\n\n";
1663
Randy Dunlapb9d973282009-06-09 08:50:38 -07001664 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1665 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 $count = 0;
1667 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001668 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 if ($count != $#{$args{'parameterlist'}}) {
1670 $count++;
1671 print ",";
1672 }
1673 print "\n";
1674 }
1675 print "};\n\n";
1676
1677 print "Constants:\n\n";
1678 foreach $parameter (@{$args{'parameterlist'}}) {
1679 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001680 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 }
1682
1683 output_section_text(@_);
1684}
1685
1686# output typedef in text
1687sub output_typedef_text(%) {
1688 my %args = %{$_[0]};
1689 my ($parameter);
1690 my $count;
1691 print "Typedef:\n\n";
1692
Randy Dunlapb9d973282009-06-09 08:50:38 -07001693 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 output_section_text(@_);
1695}
1696
1697# output struct as text
1698sub output_struct_text(%) {
1699 my %args = %{$_[0]};
1700 my ($parameter);
1701
Randy Dunlapb9d973282009-06-09 08:50:38 -07001702 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1703 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 foreach $parameter (@{$args{'parameterlist'}}) {
1705 if ($parameter =~ /^#/) {
1706 print "$parameter\n";
1707 next;
1708 }
1709
1710 my $parameter_name = $parameter;
1711 $parameter_name =~ s/\[.*//;
1712
Randy Dunlap3c308792007-05-08 00:24:39 -07001713 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 $type = $args{'parametertypes'}{$parameter};
1715 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1716 # pointer-to-function
1717 print "\t$1 $parameter) ($2);\n";
1718 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001719 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 print "\t$1 $parameter$2;\n";
1721 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001722 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 }
1724 }
1725 print "};\n\n";
1726
1727 print "Members:\n\n";
1728 foreach $parameter (@{$args{'parameterlist'}}) {
1729 ($parameter =~ /^#/) && next;
1730
1731 my $parameter_name = $parameter;
1732 $parameter_name =~ s/\[.*//;
1733
Randy Dunlap3c308792007-05-08 00:24:39 -07001734 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001736 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 }
1738 print "\n";
1739 output_section_text(@_);
1740}
1741
Johannes Bergb112e0f2007-10-24 15:08:48 -07001742sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 my %args = %{$_[0]};
1744 my ($parameter, $section);
1745
1746 foreach $section (@{$args{'sectionlist'}}) {
1747 print " $section:\n";
1748 print " -> ";
1749 output_highlight($args{'sections'}{$section});
1750 }
1751}
1752
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001753##
1754# output in restructured text
1755#
1756
1757#
1758# This could use some work; it's used to output the DOC: sections, and
1759# starts by putting out the name of the doc section itself, but that tends
1760# to duplicate a header already in the template file.
1761#
1762sub output_blockhead_rst(%) {
1763 my %args = %{$_[0]};
1764 my ($parameter, $section);
1765
1766 foreach $section (@{$args{'sectionlist'}}) {
1767 print "**$section**\n\n";
1768 output_highlight_rst($args{'sections'}{$section});
1769 print "\n";
1770 }
1771}
1772
1773sub output_highlight_rst {
1774 my $contents = join "\n",@_;
1775 my $line;
1776
1777 # undo the evil effects of xml_escape() earlier
1778 $contents = xml_unescape($contents);
1779
1780 eval $dohighlight;
1781 die $@ if $@;
1782
1783 foreach $line (split "\n", $contents) {
1784 if ($line eq "") {
1785 print $lineprefix, $blankline;
1786 } else {
1787 $line =~ s/\\\\\\/\&/g;
1788 print $lineprefix, $line;
1789 }
1790 print "\n";
1791 }
1792}
1793
1794sub output_function_rst(%) {
1795 my %args = %{$_[0]};
1796 my ($parameter, $section);
1797 my $start;
1798
1799 print ".. c:function:: ";
1800 if ($args{'functiontype'} ne "") {
1801 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1802 } else {
1803 $start = $args{'function'} . " (";
1804 }
1805 print $start;
1806
1807 my $count = 0;
1808 foreach my $parameter (@{$args{'parameterlist'}}) {
1809 if ($count ne 0) {
1810 print ", ";
1811 }
1812 $count++;
1813 $type = $args{'parametertypes'}{$parameter};
1814 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1815 # pointer-to-function
1816 print $1 . $parameter . ") (" . $2;
1817 } else {
1818 print $type . " " . $parameter;
1819 }
1820 }
1821 print ")\n\n " . $args{'purpose'} . "\n\n";
1822
1823 print ":Parameters:\n\n";
1824 foreach $parameter (@{$args{'parameterlist'}}) {
1825 my $parameter_name = $parameter;
1826 #$parameter_name =~ s/\[.*//;
1827 $type = $args{'parametertypes'}{$parameter};
1828
1829 if ($type ne "") {
1830 print " ``$type $parameter``\n";
1831 } else {
1832 print " ``$parameter``\n";
1833 }
Jani Nikula5e64fa92016-05-19 20:32:48 +03001834 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1835 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001836 my $oldprefix = $lineprefix;
1837 $lineprefix = " ";
1838 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
1839 $lineprefix = $oldprefix;
1840 } else {
1841 print "\n _undescribed_\n";
1842 }
1843 print "\n";
1844 }
1845 output_section_rst(@_);
1846}
1847
1848sub output_section_rst(%) {
1849 my %args = %{$_[0]};
1850 my $section;
1851 my $oldprefix = $lineprefix;
1852 $lineprefix = " ";
1853
1854 foreach $section (@{$args{'sectionlist'}}) {
1855 print ":$section:\n\n";
1856 output_highlight_rst($args{'sections'}{$section});
1857 print "\n";
1858 }
1859 print "\n";
1860 $lineprefix = $oldprefix;
1861}
1862
1863sub output_enum_rst(%) {
1864 my %args = %{$_[0]};
1865 my ($parameter);
1866 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001867 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001868
1869 print "\n\n.. c:type:: " . $name . "\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001870 print " " . $args{'purpose'} . "\n\n";
1871
1872 print "..\n\n:Constants:\n\n";
1873 my $oldprefix = $lineprefix;
1874 $lineprefix = " ";
1875 foreach $parameter (@{$args{'parameterlist'}}) {
1876 print " `$parameter`\n";
1877 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1878 output_highlight_rst($args{'parameterdescs'}{$parameter});
1879 } else {
1880 print " undescribed\n";
1881 }
1882 print "\n";
1883 }
1884 $lineprefix = $oldprefix;
1885 output_section_rst(@_);
1886}
1887
1888sub output_typedef_rst(%) {
1889 my %args = %{$_[0]};
1890 my ($parameter);
1891 my $count;
1892 my $name = "typedef " . $args{'typedef'};
1893
Jani Nikula62850972016-05-12 16:15:38 +03001894 ### FIXME: should the name below contain "typedef" or not?
1895 print "\n\n.. c:type:: " . $name . "\n\n";
1896 print " " . $args{'purpose'} . "\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001897
1898 output_section_rst(@_);
1899}
1900
1901sub output_struct_rst(%) {
1902 my %args = %{$_[0]};
1903 my ($parameter);
1904 my $name = $args{'type'} . " " . $args{'struct'};
1905
Jani Nikula62850972016-05-12 16:15:38 +03001906 print "\n\n.. c:type:: " . $name . "\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001907 print " " . $args{'purpose'} . "\n\n";
1908
1909 print ":Definition:\n\n";
1910 print " ::\n\n";
1911 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1912 foreach $parameter (@{$args{'parameterlist'}}) {
1913 if ($parameter =~ /^#/) {
1914 print " " . "$parameter\n";
1915 next;
1916 }
1917
1918 my $parameter_name = $parameter;
1919 $parameter_name =~ s/\[.*//;
1920
1921 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1922 $type = $args{'parametertypes'}{$parameter};
1923 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1924 # pointer-to-function
1925 print " $1 $parameter) ($2);\n";
1926 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1927 # bitfield
1928 print " $1 $parameter$2;\n";
1929 } else {
1930 print " " . $type . " " . $parameter . ";\n";
1931 }
1932 }
1933 print " };\n\n";
1934
1935 print ":Members:\n\n";
1936 foreach $parameter (@{$args{'parameterlist'}}) {
1937 ($parameter =~ /^#/) && next;
1938
1939 my $parameter_name = $parameter;
1940 $parameter_name =~ s/\[.*//;
1941
1942 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1943 $type = $args{'parametertypes'}{$parameter};
1944 print " `$type $parameter`" . "\n";
1945 my $oldprefix = $lineprefix;
1946 $lineprefix = " ";
1947 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
1948 $lineprefix = $oldprefix;
1949 print "\n";
1950 }
1951 print "\n";
1952 output_section_rst(@_);
1953}
1954
1955
Johannes Bergeda603f2010-09-11 15:55:22 -07001956## list mode output functions
1957
1958sub output_function_list(%) {
1959 my %args = %{$_[0]};
1960
1961 print $args{'function'} . "\n";
1962}
1963
1964# output enum in list
1965sub output_enum_list(%) {
1966 my %args = %{$_[0]};
1967 print $args{'enum'} . "\n";
1968}
1969
1970# output typedef in list
1971sub output_typedef_list(%) {
1972 my %args = %{$_[0]};
1973 print $args{'typedef'} . "\n";
1974}
1975
1976# output struct as list
1977sub output_struct_list(%) {
1978 my %args = %{$_[0]};
1979
1980 print $args{'struct'} . "\n";
1981}
1982
1983sub output_blockhead_list(%) {
1984 my %args = %{$_[0]};
1985 my ($parameter, $section);
1986
1987 foreach $section (@{$args{'sectionlist'}}) {
1988 print "DOC: $section\n";
1989 }
1990}
1991
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992##
Randy Dunlap27205742006-10-11 01:22:12 -07001993# generic output function for all types (function, struct/union, typedef, enum);
1994# calls the generated, variable output_ function name based on
1995# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996sub output_declaration {
1997 no strict 'refs';
1998 my $name = shift;
1999 my $functype = shift;
2000 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002001 if (($output_selection == OUTPUT_ALL) ||
2002 (($output_selection == OUTPUT_INCLUDE ||
2003 $output_selection == OUTPUT_EXPORTED) &&
2004 defined($function_table{$name})) ||
2005 (($output_selection == OUTPUT_EXCLUDE ||
2006 $output_selection == OUTPUT_INTERNAL) &&
2007 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002009 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 $section_counter++;
2011 }
2012}
2013
2014##
Randy Dunlap27205742006-10-11 01:22:12 -07002015# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002016sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002018 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 &$func(@_);
2020 $section_counter++;
2021}
2022
2023##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002024# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025# invokes the right handler. NOT called for functions.
2026sub dump_declaration($$) {
2027 no strict 'refs';
2028 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002029 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 &$func(@_);
2031}
2032
2033sub dump_union($$) {
2034 dump_struct(@_);
2035}
2036
2037sub dump_struct($$) {
2038 my $x = shift;
2039 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002040 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002042 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2043 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002044 $declaration_name = $2;
2045 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046
2047 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002048 $members =~ s/({.*})//g;
2049 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
Martin Waitzaeec46b2005-11-13 16:08:13 -08002051 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002052 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2053 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002054 # strip comments:
2055 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002056 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002057 # strip kmemcheck_bitfield_{begin,end}.*;
2058 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002059 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002060 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002061 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002062 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002063 # replace DECLARE_BITMAP
2064 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002065
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002067 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
2069 output_declaration($declaration_name,
2070 'struct',
2071 {'struct' => $declaration_name,
2072 'module' => $modulename,
2073 'parameterlist' => \@parameterlist,
2074 'parameterdescs' => \%parameterdescs,
2075 'parametertypes' => \%parametertypes,
2076 'sectionlist' => \@sectionlist,
2077 'sections' => \%sections,
2078 'purpose' => $declaration_purpose,
2079 'type' => $decl_type
2080 });
2081 }
2082 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002083 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 ++$errors;
2085 }
2086}
2087
2088sub dump_enum($$) {
2089 my $x = shift;
2090 my $file = shift;
2091
Martin Waitzaeec46b2005-11-13 16:08:13 -08002092 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002093 # strip #define macros inside enums
2094 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002095
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002097 $declaration_name = $1;
2098 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
2100 foreach my $arg (split ',', $members) {
2101 $arg =~ s/^\s*(\w+).*/$1/;
2102 push @parameterlist, $arg;
2103 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002104 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002105 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 "not described in enum '$declaration_name'\n";
2107 }
2108
2109 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002110
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 output_declaration($declaration_name,
2112 'enum',
2113 {'enum' => $declaration_name,
2114 'module' => $modulename,
2115 'parameterlist' => \@parameterlist,
2116 'parameterdescs' => \%parameterdescs,
2117 'sectionlist' => \@sectionlist,
2118 'sections' => \%sections,
2119 'purpose' => $declaration_purpose
2120 });
2121 }
2122 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002123 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 ++$errors;
2125 }
2126}
2127
2128sub dump_typedef($$) {
2129 my $x = shift;
2130 my $file = shift;
2131
Martin Waitzaeec46b2005-11-13 16:08:13 -08002132 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002133
2134 # Parse function prototypes
2135 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
2136 # Function typedefs
2137 $return_type = $1;
2138 $declaration_name = $2;
2139 my $args = $3;
2140
2141 create_parameterlist($args, ',', $file);
2142
2143 output_declaration($declaration_name,
2144 'function',
2145 {'function' => $declaration_name,
2146 'module' => $modulename,
2147 'functiontype' => $return_type,
2148 'parameterlist' => \@parameterlist,
2149 'parameterdescs' => \%parameterdescs,
2150 'parametertypes' => \%parametertypes,
2151 'sectionlist' => \@sectionlist,
2152 'sections' => \%sections,
2153 'purpose' => $declaration_purpose
2154 });
2155 return;
2156 }
2157
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002159 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 $x =~ s/\[*.\]\s*;$/;/;
2161 }
2162
2163 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002164 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165
2166 output_declaration($declaration_name,
2167 'typedef',
2168 {'typedef' => $declaration_name,
2169 'module' => $modulename,
2170 'sectionlist' => \@sectionlist,
2171 'sections' => \%sections,
2172 'purpose' => $declaration_purpose
2173 });
2174 }
2175 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002176 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 ++$errors;
2178 }
2179}
2180
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002181sub save_struct_actual($) {
2182 my $actual = shift;
2183
2184 # strip all spaces from the actual param so that it looks like one string item
2185 $actual =~ s/\s*//g;
2186 $struct_actual = $struct_actual . $actual . " ";
2187}
2188
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189sub create_parameterlist($$$) {
2190 my $args = shift;
2191 my $splitter = shift;
2192 my $file = shift;
2193 my $type;
2194 my $param;
2195
Martin Waitza6d3fe72006-01-09 20:53:55 -08002196 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002198 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002200
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 foreach my $arg (split($splitter, $args)) {
2202 # strip comments
2203 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002204 # strip leading/trailing spaces
2205 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 $arg =~ s/\s*$//;
2207 $arg =~ s/\s+/ /;
2208
2209 if ($arg =~ /^#/) {
2210 # Treat preprocessor directive as a typeless variable just to fill
2211 # corresponding data structures "correctly". Catch it later in
2212 # output_* subs.
2213 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002214 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 # pointer-to-function
2216 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002217 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 $param = $1;
2219 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002220 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002221 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002223 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 $arg =~ s/\s*:\s*/:/g;
2225 $arg =~ s/\s*\[/\[/g;
2226
2227 my @args = split('\s*,\s*', $arg);
2228 if ($args[0] =~ m/\*/) {
2229 $args[0] =~ s/(\*+)\s*/ $1/;
2230 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002231
2232 my @first_arg;
2233 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2234 shift @args;
2235 push(@first_arg, split('\s+', $1));
2236 push(@first_arg, $2);
2237 } else {
2238 @first_arg = split('\s+', shift @args);
2239 }
2240
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 unshift(@args, pop @first_arg);
2242 $type = join " ", @first_arg;
2243
2244 foreach $param (@args) {
2245 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002246 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 push_parameter($2, "$type $1", $file);
2248 }
2249 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002250 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002251 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002252 push_parameter($1, "$type:$2", $file)
2253 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 }
2255 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002256 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 push_parameter($param, $type, $file);
2258 }
2259 }
2260 }
2261 }
2262}
2263
2264sub push_parameter($$$) {
2265 my $param = shift;
2266 my $type = shift;
2267 my $file = shift;
2268
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002269 if (($anon_struct_union == 1) && ($type eq "") &&
2270 ($param eq "}")) {
2271 return; # ignore the ending }; from anon. struct/union
2272 }
2273
2274 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 my $param_name = $param;
2276 $param_name =~ s/\[.*//;
2277
Martin Waitza6d3fe72006-01-09 20:53:55 -08002278 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 {
Randy Dunlapced69092008-12-01 13:14:03 -08002280 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2281 $parameterdescs{$param} = "variable arguments";
2282 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 }
2284 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2285 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 $param="void";
2287 $parameterdescs{void} = "no arguments";
2288 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002289 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2290 # handle unnamed (anonymous) union or struct:
2291 {
2292 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002293 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002294 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002295 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002296 }
2297
Martin Waitza6d3fe72006-01-09 20:53:55 -08002298 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002299 # (but ignore ones starting with # as these are not parameters
2300 # but inline preprocessor statements);
2301 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002302 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002303 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2304
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 $parameterdescs{$param_name} = $undescribed;
2306
2307 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002308 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 "or member '$param' not " .
2310 "described in '$declaration_name'\n";
2311 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002312 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002313 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002315 }
2316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002318 $param = xml_escape($param);
2319
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002320 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002321 # on @parameterlist;
2322 # this fixes a problem where check_sections() cannot find
2323 # a parameter like "addr[6 + 2]" because it actually appears
2324 # as "addr[6", "+", "2]" on the parameter list;
2325 # but it's better to maintain the param string unchanged for output,
2326 # so just weaken the string compare in check_sections() to ignore
2327 # "[blah" in a parameter string;
2328 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 push @parameterlist, $param;
2330 $parametertypes{$param} = $type;
2331}
2332
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002333sub check_sections($$$$$$) {
2334 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2335 my @sects = split ' ', $sectcheck;
2336 my @prms = split ' ', $prmscheck;
2337 my $err;
2338 my ($px, $sx);
2339 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2340
2341 foreach $sx (0 .. $#sects) {
2342 $err = 1;
2343 foreach $px (0 .. $#prms) {
2344 $prm_clean = $prms[$px];
2345 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002346 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002347 # ignore array size in a parameter string;
2348 # however, the original param string may contain
2349 # spaces, e.g.: addr[6 + 2]
2350 # and this appears in @prms as "addr[6" since the
2351 # parameter list is split at spaces;
2352 # hence just ignore "[..." for the sections check;
2353 $prm_clean =~ s/\[.*//;
2354
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002355 ##$prm_clean =~ s/^\**//;
2356 if ($prm_clean eq $sects[$sx]) {
2357 $err = 0;
2358 last;
2359 }
2360 }
2361 if ($err) {
2362 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002363 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002364 "Excess function parameter " .
2365 "'$sects[$sx]' " .
2366 "description in '$decl_name'\n";
2367 ++$warnings;
2368 } else {
2369 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002370 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002371 "Excess struct/union/enum/typedef member " .
2372 "'$sects[$sx]' " .
2373 "description in '$decl_name'\n";
2374 ++$warnings;
2375 }
2376 }
2377 }
2378 }
2379}
2380
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002382# Checks the section describing the return value of a function.
2383sub check_return_section {
2384 my $file = shift;
2385 my $declaration_name = shift;
2386 my $return_type = shift;
2387
2388 # Ignore an empty return type (It's a macro)
2389 # Ignore functions with a "void" return type. (But don't ignore "void *")
2390 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2391 return;
2392 }
2393
2394 if (!defined($sections{$section_return}) ||
2395 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002396 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002397 "No description found for return value of " .
2398 "'$declaration_name'\n";
2399 ++$warnings;
2400 }
2401}
2402
2403##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404# takes a function prototype and the name of the current file being
2405# processed and spits out all the details stored in the global
2406# arrays/hashes.
2407sub dump_function($$) {
2408 my $prototype = shift;
2409 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002410 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411
2412 $prototype =~ s/^static +//;
2413 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002414 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 $prototype =~ s/^inline +//;
2416 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002417 $prototype =~ s/^__inline +//;
2418 $prototype =~ s/^__always_inline +//;
2419 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002420 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002421 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002422 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002423 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002424 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002425 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002426 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
2428 # Yes, this truly is vile. We are looking for:
2429 # 1. Return type (may be nothing if we're looking at a macro)
2430 # 2. Function name
2431 # 3. Function parameters.
2432 #
2433 # All the while we have to watch out for function pointer parameters
2434 # (which IIRC is what the two sections are for), C types (these
2435 # regexps don't even start to express all the possibilities), and
2436 # so on.
2437 #
2438 # If you mess with these regexps, it's a good idea to check that
2439 # the following functions' documentation still comes out right:
2440 # - parport_register_device (function pointer parameters)
2441 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002442 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002444 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2445 # This is an object-like macro, it has no return type and no parameter
2446 # list.
2447 # Function-like macros are not allowed to have spaces between
2448 # declaration_name and opening parenthesis (notice the \s+).
2449 $return_type = $1;
2450 $declaration_name = $2;
2451 $noret = 1;
2452 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2454 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2455 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002456 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2458 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2459 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2460 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2461 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2462 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2463 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2464 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002465 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2466 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002467 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2468 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 $return_type = $1;
2470 $declaration_name = $2;
2471 my $args = $3;
2472
2473 create_parameterlist($args, ',', $file);
2474 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002475 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 return;
2477 }
2478
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002479 my $prms = join " ", @parameterlist;
2480 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2481
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002482 # This check emits a lot of warnings at the moment, because many
2483 # functions don't have a 'Return' doc section. So until the number
2484 # of warnings goes sufficiently down, the check is only performed in
2485 # verbose mode.
2486 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002487 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002488 check_return_section($file, $declaration_name, $return_type);
2489 }
2490
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002491 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 'function',
2493 {'function' => $declaration_name,
2494 'module' => $modulename,
2495 'functiontype' => $return_type,
2496 'parameterlist' => \@parameterlist,
2497 'parameterdescs' => \%parameterdescs,
2498 'parametertypes' => \%parametertypes,
2499 'sectionlist' => \@sectionlist,
2500 'sections' => \%sections,
2501 'purpose' => $declaration_purpose
2502 });
2503}
2504
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505sub reset_state {
2506 $function = "";
2507 %constants = ();
2508 %parameterdescs = ();
2509 %parametertypes = ();
2510 @parameterlist = ();
2511 %sections = ();
2512 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002513 $sectcheck = "";
2514 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002516
Jani Nikula48af6062016-05-26 14:56:05 +03002517 $state = STATE_NORMAL;
2518 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519}
2520
Jason Baron56afb0f2009-04-30 13:29:36 -04002521sub tracepoint_munge($) {
2522 my $file = shift;
2523 my $tracepointname = 0;
2524 my $tracepointargs = 0;
2525
Jason Baron3a9089f2009-12-01 12:18:49 -05002526 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002527 $tracepointname = $1;
2528 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002529 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2530 $tracepointname = $1;
2531 }
2532 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2533 $tracepointname = $2;
2534 }
2535 $tracepointname =~ s/^\s+//; #strip leading whitespace
2536 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002537 $tracepointargs = $1;
2538 }
2539 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002540 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002541 "$prototype\n";
2542 } else {
2543 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2544 }
2545}
2546
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002547sub syscall_munge() {
2548 my $void = 0;
2549
2550 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2551## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2552 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2553 $void = 1;
2554## $prototype = "long sys_$1(void)";
2555 }
2556
2557 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2558 if ($prototype =~ m/long (sys_.*?),/) {
2559 $prototype =~ s/,/\(/;
2560 } elsif ($void) {
2561 $prototype =~ s/\)/\(void\)/;
2562 }
2563
2564 # now delete all of the odd-number commas in $prototype
2565 # so that arg types & arg names don't have a comma between them
2566 my $count = 0;
2567 my $len = length($prototype);
2568 if ($void) {
2569 $len = 0; # skip the for-loop
2570 }
2571 for (my $ix = 0; $ix < $len; $ix++) {
2572 if (substr($prototype, $ix, 1) eq ',') {
2573 $count++;
2574 if ($count % 2 == 1) {
2575 substr($prototype, $ix, 1) = ' ';
2576 }
2577 }
2578 }
2579}
2580
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002581sub process_state3_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 my $x = shift;
2583 my $file = shift;
2584
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002585 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2586
Randy Dunlap890c78c2008-10-25 17:06:43 -07002587 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 # do nothing
2589 }
2590 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002591 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002593
Randy Dunlap890c78c2008-10-25 17:06:43 -07002594 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002595 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2597 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002598 if ($prototype =~ /SYSCALL_DEFINE/) {
2599 syscall_munge();
2600 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002601 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2602 $prototype =~ /DEFINE_SINGLE_EVENT/)
2603 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002604 tracepoint_munge($file);
2605 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002606 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002607 reset_state();
2608 }
2609}
2610
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002611sub process_state3_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 my $x = shift;
2613 my $file = shift;
2614
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2616 $x =~ s@^\s+@@gos; # strip leading spaces
2617 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002618 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2619
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 if ($x =~ /^#/) {
2621 # To distinguish preprocessor directive from regular declaration later.
2622 $x .= ";";
2623 }
2624
2625 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002626 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 $prototype .= $1 . $2;
2628 ($2 eq '{') && $brcount++;
2629 ($2 eq '}') && $brcount--;
2630 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002631 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002633 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 }
2635 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002636 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 $prototype .= $x;
2638 last;
2639 }
2640 }
2641}
2642
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002643# xml_escape: replace <, >, and & in the text stream;
2644#
2645# however, formatting controls that are generated internally/locally in the
2646# kernel-doc script are not escaped here; instead, they begin life like
2647# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2648# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2649# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650sub xml_escape($) {
2651 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002652 if (($output_mode eq "text") || ($output_mode eq "man")) {
2653 return $text;
2654 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 $text =~ s/\&/\\\\\\amp;/g;
2656 $text =~ s/\</\\\\\\lt;/g;
2657 $text =~ s/\>/\\\\\\gt;/g;
2658 return $text;
2659}
2660
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002661# xml_unescape: reverse the effects of xml_escape
2662sub xml_unescape($) {
2663 my $text = shift;
2664 if (($output_mode eq "text") || ($output_mode eq "man")) {
2665 return $text;
2666 }
2667 $text =~ s/\\\\\\amp;/\&/g;
2668 $text =~ s/\\\\\\lt;/</g;
2669 $text =~ s/\\\\\\gt;/>/g;
2670 return $text;
2671}
2672
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002673# convert local escape strings to html
2674# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2675sub local_unescape($) {
2676 my $text = shift;
2677 if (($output_mode eq "text") || ($output_mode eq "man")) {
2678 return $text;
2679 }
2680 $text =~ s/\\\\\\\\lt:/</g;
2681 $text =~ s/\\\\\\\\gt:/>/g;
2682 return $text;
2683}
2684
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002686 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 my $identifier;
2688 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002689 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002690 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002692 my ($orig_file) = @_;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693
Randy Dunlap2283a112005-07-07 15:39:26 -07002694 if (defined($ENV{'SRCTREE'})) {
Ben Hutchings68f86662015-09-01 23:48:49 +01002695 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002696 }
2697 else {
Ben Hutchings68f86662015-09-01 23:48:49 +01002698 $file = $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002699 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 if (defined($source_map{$file})) {
2701 $file = $source_map{$file};
2702 }
2703
2704 if (!open(IN,"<$file")) {
2705 print STDERR "Error: Cannot open file $file\n";
2706 ++$errors;
2707 return;
2708 }
2709
Jani Nikula86ae2e32016-01-21 13:05:22 +02002710 # two passes for -export and -internal
Jani Nikulab6c3f452016-05-29 22:19:35 +03002711 if ($output_selection == OUTPUT_EXPORTED ||
2712 $output_selection == OUTPUT_INTERNAL) {
Jani Nikula86ae2e32016-01-21 13:05:22 +02002713 while (<IN>) {
2714 if (/$export_symbol/o) {
2715 $function_table{$2} = 1;
2716 }
2717 }
2718 seek(IN, 0, 0);
2719 }
2720
Ilya Dryomova9e73142010-02-26 13:05:47 -08002721 $. = 1;
2722
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 $section_counter = 0;
2724 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002725 while (s/\\\s*$//) {
2726 $_ .= <IN>;
2727 }
Jani Nikula48af6062016-05-26 14:56:05 +03002728 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002730 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002731 $in_doc_sect = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 }
Jani Nikula48af6062016-05-26 14:56:05 +03002733 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002735 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 $contents = "";
2737 if ( $1 eq "" ) {
2738 $section = $section_intro;
2739 } else {
2740 $section = $1;
2741 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002742 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 elsif (/$doc_decl/o) {
2744 $identifier = $1;
2745 if (/\s*([\w\s]+?)\s*-/) {
2746 $identifier = $1;
2747 }
2748
Jani Nikula48af6062016-05-26 14:56:05 +03002749 $state = STATE_FIELD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002751 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002752 $descr= $1;
2753 $descr =~ s/^\s*//;
2754 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002755 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002756 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002757 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 } else {
2759 $declaration_purpose = "";
2760 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002761
2762 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002763 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002764 print STDERR $_;
2765 ++$warnings;
2766 }
2767
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 if ($identifier =~ m/^struct/) {
2769 $decl_type = 'struct';
2770 } elsif ($identifier =~ m/^union/) {
2771 $decl_type = 'union';
2772 } elsif ($identifier =~ m/^enum/) {
2773 $decl_type = 'enum';
2774 } elsif ($identifier =~ m/^typedef/) {
2775 $decl_type = 'typedef';
2776 } else {
2777 $decl_type = 'function';
2778 }
2779
2780 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002781 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 }
2783 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002784 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 " - I thought it was a doc line\n";
2786 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002787 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 }
Jani Nikula48af6062016-05-26 14:56:05 +03002789 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 if (/$doc_sect/o) {
2791 $newsection = $1;
2792 $newcontents = $2;
2793
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002794 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002795 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002796 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002797 ++$warnings;
2798 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002799 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 $section = $section_default;
2801 }
2802
Randy Dunlap850622d2006-06-25 05:48:55 -07002803 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002804 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 $contents = $newcontents;
2806 if ($contents ne "") {
Randy Dunlap27205742006-10-11 01:22:12 -07002807 while ((substr($contents, 0, 1) eq " ") ||
2808 substr($contents, 0, 1) eq "\t") {
2809 $contents = substr($contents, 1);
Randy Dunlap05189492006-06-25 05:47:47 -07002810 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 $contents .= "\n";
2812 }
2813 $section = $newsection;
2814 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002815 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002816 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 $section = $section_default;
2818 $contents = "";
2819 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002820 # look for doc_com + <text> + doc_end:
2821 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002822 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002823 ++$warnings;
2824 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825
2826 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002827 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002829# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 } elsif (/$doc_content/) {
2831 # miguel-style comment kludge, look for blank lines after
2832 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002833 if ($1 eq "") {
2834 if ($section =~ m/^@/ || $section eq $section_context) {
2835 dump_section($file, $section, xml_escape($contents));
2836 $section = $section_default;
2837 $contents = "";
2838 } else {
2839 $contents .= "\n";
2840 }
2841 $in_purpose = 0;
2842 } elsif ($in_purpose == 1) {
2843 # Continued declaration purpose
2844 chomp($declaration_purpose);
2845 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002846 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002848 $contents .= $1 . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 }
2850 } else {
2851 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002852 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 ++$warnings;
2854 }
Jani Nikula48af6062016-05-26 14:56:05 +03002855 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002856 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03002857 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002858 $section = $1;
2859 $contents = $2;
2860 if ($contents ne "") {
2861 while ((substr($contents, 0, 1) eq " ") ||
2862 substr($contents, 0, 1) eq "\t") {
2863 $contents = substr($contents, 1);
2864 }
2865 $contents .= "\n";
2866 }
Jani Nikula48af6062016-05-26 14:56:05 +03002867 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002868 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03002869 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002870 if (($contents ne "") && ($contents ne "\n")) {
2871 dump_section($file, $section, xml_escape($contents));
2872 $section = $section_default;
2873 $contents = "";
2874 }
Jani Nikula48af6062016-05-26 14:56:05 +03002875 $state = STATE_PROTO;
2876 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002877 # Regular text
2878 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03002879 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002880 $contents .= $1 . "\n";
Jani Nikula48af6062016-05-26 14:56:05 +03002881 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
2882 $inline_doc_state = STATE_INLINE_ERROR;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002883 print STDERR "Warning(${file}:$.): ";
2884 print STDERR "Incorrect use of kernel-doc format: $_";
2885 ++$warnings;
2886 }
2887 }
Jani Nikula48af6062016-05-26 14:56:05 +03002888 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
2889 if (/$doc_inline_start/) {
2890 $state = STATE_INLINE;
2891 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002892 } elsif ($decl_type eq 'function') {
Randy Dunlap3c308792007-05-08 00:24:39 -07002893 process_state3_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -07002895 process_state3_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 }
Jani Nikula48af6062016-05-26 14:56:05 +03002897 } elsif ($state == STATE_DOCBLOCK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 # Documentation block
Randy Dunlap3c308792007-05-08 00:24:39 -07002899 if (/$doc_block/) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002900 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 $contents = "";
2902 $function = "";
2903 %constants = ();
2904 %parameterdescs = ();
2905 %parametertypes = ();
2906 @parameterlist = ();
2907 %sections = ();
2908 @sectionlist = ();
2909 $prototype = "";
2910 if ( $1 eq "" ) {
2911 $section = $section_intro;
2912 } else {
2913 $section = $1;
2914 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002915 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 elsif (/$doc_end/)
2917 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002918 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 $contents = "";
2920 $function = "";
2921 %constants = ();
2922 %parameterdescs = ();
2923 %parametertypes = ();
2924 @parameterlist = ();
2925 %sections = ();
2926 @sectionlist = ();
2927 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002928 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 }
2930 elsif (/$doc_content/)
2931 {
2932 if ( $1 eq "" )
2933 {
2934 $contents .= $blankline;
2935 }
2936 else
2937 {
2938 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002939 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002940 }
2941 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002942 }
2943 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002944 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002945 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08002946 print STDERR " Was looking for '$_'.\n" for keys %function_table;
2947 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 if ($output_mode eq "xml") {
2949 # The template wants at least one RefEntry here; make one.
2950 print "<refentry>\n";
2951 print " <refnamediv>\n";
2952 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01002953 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 print " </refname>\n";
2955 print " <refpurpose>\n";
2956 print " Document generation inconsistency\n";
2957 print " </refpurpose>\n";
2958 print " </refnamediv>\n";
2959 print " <refsect1>\n";
2960 print " <title>\n";
2961 print " Oops\n";
2962 print " </title>\n";
2963 print " <warning>\n";
2964 print " <para>\n";
2965 print " The template for this document tried to insert\n";
2966 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01002967 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 print " but none was found.\n";
2969 print " This dummy section is inserted to allow\n";
2970 print " generation to continue.\n";
2971 print " </para>\n";
2972 print " </warning>\n";
2973 print " </refsect1>\n";
2974 print "</refentry>\n";
2975 }
2976 }
2977}
Randy Dunlap8484baa2011-01-05 16:28:43 -08002978
2979
2980$kernelversion = get_kernel_version();
2981
2982# generate a sequence of code that will splice in highlighting information
2983# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02002984for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03002985 my $pattern = $highlights[$k][0];
2986 my $result = $highlights[$k][1];
2987# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
2988 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08002989}
2990
2991# Read the file that maps relative names to absolute names for
2992# separate source and object directories and for shadow trees.
2993if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
2994 my ($relname, $absname);
2995 while(<SOURCE_MAP>) {
2996 chop();
2997 ($relname, $absname) = (split())[0..1];
2998 $relname =~ s:^/+::;
2999 $source_map{$relname} = $absname;
3000 }
3001 close(SOURCE_MAP);
3002}
3003
3004foreach (@ARGV) {
3005 chomp;
3006 process_file($_);
3007}
3008if ($verbose && $errors) {
3009 print STDERR "$errors errors\n";
3010}
3011if ($verbose && $warnings) {
3012 print STDERR "$warnings warnings\n";
3013}
3014
3015exit($errors);