blob: 3ad54abe09899636d66254e383b3403ef2446697 [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";
315my $function_only = 0;
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100316my $show_not_found = 0;
317
318my @build_time;
319if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
320 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
321 @build_time = gmtime($seconds);
322} else {
323 @build_time = localtime;
324}
325
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800326my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
327 'July', 'August', 'September', 'October',
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100328 'November', 'December')[$build_time[4]] .
329 " " . ($build_time[5]+1900);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330
Randy Dunlap8484baa2011-01-05 16:28:43 -0800331# Essentially these are globals.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700332# They probably want to be tidied up, made more localised or something.
333# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334# could cause "use of undefined value" or other bugs.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700335my ($function, %function_table, %parametertypes, $declaration_purpose);
336my ($type, $declaration_name, $return_type);
Ilya Dryomov1c32fd02010-02-26 13:06:03 -0800337my ($newsection, $newcontents, $prototype, $brcount, %source_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700339if (defined($ENV{'KBUILD_VERBOSE'})) {
340 $verbose = "$ENV{'KBUILD_VERBOSE'}";
341}
342
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800343# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
345# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
346# We keep track of number of generated entries and generate a dummy
347# if needs be to ensure the expanded template can be postprocessed
348# into html.
349my $section_counter = 0;
350
351my $lineprefix="";
352
353# states
354# 0 - normal code
355# 1 - looking for function name
356# 2 - scanning field start.
357# 3 - scanning prototype.
358# 4 - documentation block
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300359# 5 - gathering documentation outside main block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700361my $in_doc_sect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300363# Split Doc State
364# 0 - Invalid (Before start or after finish)
365# 1 - Is started (the /** was found inside a struct)
366# 2 - The @parameter header was found, start accepting multi paragraph text.
367# 3 - Finished (the */ was found)
368# 4 - Error - Comment without header was found. Spit a warning as it's not
369# proper kernel-doc and ignore the rest.
370my $split_doc_state;
371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372#declaration types: can be
373# 'function', 'struct', 'union', 'enum', 'typedef'
374my $decl_type;
375
376my $doc_special = "\@\%\$\&";
377
378my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
379my $doc_end = '\*/';
380my $doc_com = '\s*\*\s*';
Daniel Santos12ae6772012-10-04 17:15:10 -0700381my $doc_com_body = '\s*\* ?';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700382my $doc_decl = $doc_com . '(\w+)';
383my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700384my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700385my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300386my $doc_split_start = '^\s*/\*\*\s*$';
387my $doc_split_sect = '\s*\*\s*(@[\w\s]+):(.*)';
388my $doc_split_end = '^\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200389my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
391my %constants;
392my %parameterdescs;
393my @parameterlist;
394my %sections;
395my @sectionlist;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800396my $sectcheck;
397my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399my $contents = "";
400my $section_default = "Description"; # default section
401my $section_intro = "Introduction";
402my $section = $section_default;
403my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100404my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405
406my $undescribed = "-- undescribed --";
407
408reset_state();
409
410while ($ARGV[0] =~ m/^-(.*)/) {
411 my $cmd = shift @ARGV;
412 if ($cmd eq "-html") {
413 $output_mode = "html";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300414 @highlights = @highlights_html;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200416 } elsif ($cmd eq "-html5") {
417 $output_mode = "html5";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300418 @highlights = @highlights_html5;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200419 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 } elsif ($cmd eq "-man") {
421 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300422 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 $blankline = $blankline_man;
424 } elsif ($cmd eq "-text") {
425 $output_mode = "text";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300426 @highlights = @highlights_text;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 $blankline = $blankline_text;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300428 } elsif ($cmd eq "-rst") {
429 $output_mode = "rst";
430 @highlights = @highlights_rst;
431 $blankline = $blankline_rst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 } elsif ($cmd eq "-docbook") {
433 $output_mode = "xml";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300434 @highlights = @highlights_xml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700436 } elsif ($cmd eq "-list") {
437 $output_mode = "list";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300438 @highlights = @highlights_list;
Johannes Bergeda603f2010-09-11 15:55:22 -0700439 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 } elsif ($cmd eq "-gnome") {
441 $output_mode = "gnome";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300442 @highlights = @highlights_gnome;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 $blankline = $blankline_gnome;
444 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
445 $modulename = shift @ARGV;
446 } elsif ($cmd eq "-function") { # to only output specific functions
447 $function_only = 1;
448 $function = shift @ARGV;
449 $function_table{$function} = 1;
450 } elsif ($cmd eq "-nofunction") { # to only output specific functions
451 $function_only = 2;
452 $function = shift @ARGV;
453 $function_table{$function} = 1;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200454 } elsif ($cmd eq "-export") { # only exported symbols
455 $function_only = 3;
456 %function_table = ()
457 } elsif ($cmd eq "-internal") { # only non-exported symbols
458 $function_only = 4;
459 %function_table = ()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 } elsif ($cmd eq "-v") {
461 $verbose = 1;
462 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
463 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700464 } elsif ($cmd eq '-no-doc-sections') {
465 $no_doc_sections = 1;
Johannes Berge946c43a2013-11-12 15:11:12 -0800466 } elsif ($cmd eq '-show-not-found') {
467 $show_not_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 }
469}
470
Randy Dunlap8484baa2011-01-05 16:28:43 -0800471# continue execution near EOF;
472
Borislav Petkov53f049f2007-05-08 00:30:54 -0700473# get kernel version from env
474sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700475 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700476
477 if (defined($ENV{'KERNELVERSION'})) {
478 $version = $ENV{'KERNELVERSION'};
479 }
480 return $version;
481}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483##
484# dumps section contents to arrays/hashes intended for that purpose.
485#
486sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700487 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 my $name = shift;
489 my $contents = join "\n", @_;
490
491 if ($name =~ m/$type_constant/) {
492 $name = $1;
493# print STDERR "constant section '$1' = '$contents'\n";
494 $constants{$name} = $contents;
495 } elsif ($name =~ m/$type_param/) {
496# print STDERR "parameter def '$1' = '$contents'\n";
497 $name = $1;
498 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800499 $sectcheck = $sectcheck . $name . " ";
Randy Dunlapced69092008-12-01 13:14:03 -0800500 } elsif ($name eq "@\.\.\.") {
501# print STDERR "parameter def '...' = '$contents'\n";
502 $name = "...";
503 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800504 $sectcheck = $sectcheck . $name . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 } else {
506# print STDERR "other section '$name' = '$contents'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700507 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Bart Van Assched40e1e62015-09-04 15:43:21 -0700508 print STDERR "${file}:$.: error: duplicate section name '$name'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700509 ++$errors;
510 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 $sections{$name} = $contents;
512 push @sectionlist, $name;
513 }
514}
515
516##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700517# dump DOC: section after checking that it should go out
518#
519sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700520 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700521 my $name = shift;
522 my $contents = join "\n", @_;
523
Johannes Berg4b445952007-10-24 15:08:48 -0700524 if ($no_doc_sections) {
525 return;
526 }
527
Johannes Bergb112e0f2007-10-24 15:08:48 -0700528 if (($function_only == 0) ||
529 ( $function_only == 1 && defined($function_table{$name})) ||
530 ( $function_only == 2 && !defined($function_table{$name})))
531 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700532 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700533 output_blockhead({'sectionlist' => \@sectionlist,
534 'sections' => \%sections,
535 'module' => $modulename,
536 'content-only' => ($function_only != 0), });
537 }
538}
539
540##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541# output function
542#
543# parameterdescs, a hash.
544# function => "function name"
545# parameterlist => @list of parameters
546# parameterdescs => %parameter descriptions
547# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800548# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800549#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551sub output_highlight {
552 my $contents = join "\n",@_;
553 my $line;
554
555# DEBUG
556# if (!defined $contents) {
557# use Carp;
558# confess "output_highlight got called with no args?\n";
559# }
560
Dan Luedtke1b40c192012-08-12 10:46:15 +0200561 if ($output_mode eq "html" || $output_mode eq "html5" ||
562 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700563 $contents = local_unescape($contents);
564 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800565 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700566 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700567# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 eval $dohighlight;
569 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700570# print STDERR "contents af:$contents\n";
571
Dan Luedtke1b40c192012-08-12 10:46:15 +0200572# strip whitespaces when generating html5
573 if ($output_mode eq "html5") {
574 $contents =~ s/^\s+//;
575 $contents =~ s/\s+$//;
576 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700578 if (! $output_preformatted) {
579 $line =~ s/^\s*//;
580 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700581 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700582 if (! $output_preformatted) {
583 print $lineprefix, local_unescape($blankline);
584 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700586 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700587 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
588 print "\\&$line";
589 } else {
590 print $lineprefix, $line;
591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 }
593 print "\n";
594 }
595}
596
Dan Luedtke1b40c192012-08-12 10:46:15 +0200597# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598sub output_section_html(%) {
599 my %args = %{$_[0]};
600 my $section;
601
602 foreach $section (@{$args{'sectionlist'}}) {
603 print "<h3>$section</h3>\n";
604 print "<blockquote>\n";
605 output_highlight($args{'sections'}{$section});
606 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608}
609
610# output enum in html
611sub output_enum_html(%) {
612 my %args = %{$_[0]};
613 my ($parameter);
614 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700615 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Randy Dunlapb9d973282009-06-09 08:50:38 -0700617 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 $count = 0;
619 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700620 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 if ($count != $#{$args{'parameterlist'}}) {
622 $count++;
623 print ",\n";
624 }
625 print "<br>";
626 }
627 print "};<br>\n";
628
629 print "<h3>Constants</h3>\n";
630 print "<dl>\n";
631 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700632 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 print "<dd>";
634 output_highlight($args{'parameterdescs'}{$parameter});
635 }
636 print "</dl>\n";
637 output_section_html(@_);
638 print "<hr>\n";
639}
640
Randy Dunlapd28bee02006-02-01 03:06:57 -0800641# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642sub output_typedef_html(%) {
643 my %args = %{$_[0]};
644 my ($parameter);
645 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700646 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Randy Dunlapb9d973282009-06-09 08:50:38 -0700648 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 output_section_html(@_);
650 print "<hr>\n";
651}
652
653# output struct in html
654sub output_struct_html(%) {
655 my %args = %{$_[0]};
656 my ($parameter);
657
Randy Dunlapb9d973282009-06-09 08:50:38 -0700658 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
659 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 foreach $parameter (@{$args{'parameterlist'}}) {
661 if ($parameter =~ /^#/) {
662 print "$parameter<br>\n";
663 next;
664 }
665 my $parameter_name = $parameter;
666 $parameter_name =~ s/\[.*//;
667
Randy Dunlap3c308792007-05-08 00:24:39 -0700668 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 $type = $args{'parametertypes'}{$parameter};
670 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
671 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700672 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700674 # bitfield
675 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700677 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 }
679 }
680 print "};<br>\n";
681
682 print "<h3>Members</h3>\n";
683 print "<dl>\n";
684 foreach $parameter (@{$args{'parameterlist'}}) {
685 ($parameter =~ /^#/) && next;
686
687 my $parameter_name = $parameter;
688 $parameter_name =~ s/\[.*//;
689
Randy Dunlap3c308792007-05-08 00:24:39 -0700690 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700691 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 print "<dd>";
693 output_highlight($args{'parameterdescs'}{$parameter_name});
694 }
695 print "</dl>\n";
696 output_section_html(@_);
697 print "<hr>\n";
698}
699
700# output function in html
701sub output_function_html(%) {
702 my %args = %{$_[0]};
703 my ($parameter, $section);
704 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Randy Dunlapb9d973282009-06-09 08:50:38 -0700706 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
707 print "<i>" . $args{'functiontype'} . "</i>\n";
708 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709 print "(";
710 $count = 0;
711 foreach $parameter (@{$args{'parameterlist'}}) {
712 $type = $args{'parametertypes'}{$parameter};
713 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
714 # pointer-to-function
715 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
716 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700717 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 }
719 if ($count != $#{$args{'parameterlist'}}) {
720 $count++;
721 print ",\n";
722 }
723 }
724 print ")\n";
725
726 print "<h3>Arguments</h3>\n";
727 print "<dl>\n";
728 foreach $parameter (@{$args{'parameterlist'}}) {
729 my $parameter_name = $parameter;
730 $parameter_name =~ s/\[.*//;
731
Randy Dunlap3c308792007-05-08 00:24:39 -0700732 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700733 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 print "<dd>";
735 output_highlight($args{'parameterdescs'}{$parameter_name});
736 }
737 print "</dl>\n";
738 output_section_html(@_);
739 print "<hr>\n";
740}
741
Johannes Bergb112e0f2007-10-24 15:08:48 -0700742# output DOC: block header in html
743sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744 my %args = %{$_[0]};
745 my ($parameter, $section);
746 my $count;
747
748 foreach $section (@{$args{'sectionlist'}}) {
749 print "<h3>$section</h3>\n";
750 print "<ul>\n";
751 output_highlight($args{'sections'}{$section});
752 print "</ul>\n";
753 }
754 print "<hr>\n";
755}
756
Dan Luedtke1b40c192012-08-12 10:46:15 +0200757# output sections in html5
758sub output_section_html5(%) {
759 my %args = %{$_[0]};
760 my $section;
761
762 foreach $section (@{$args{'sectionlist'}}) {
763 print "<section>\n";
764 print "<h1>$section</h1>\n";
765 print "<p>\n";
766 output_highlight($args{'sections'}{$section});
767 print "</p>\n";
768 print "</section>\n";
769 }
770}
771
772# output enum in html5
773sub output_enum_html5(%) {
774 my %args = %{$_[0]};
775 my ($parameter);
776 my $count;
777 my $html5id;
778
779 $html5id = $args{'enum'};
780 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
781 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
782 print "<h1>enum " . $args{'enum'} . "</h1>\n";
783 print "<ol class=\"code\">\n";
784 print "<li>";
785 print "<span class=\"keyword\">enum</span> ";
786 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
787 print "</li>\n";
788 $count = 0;
789 foreach $parameter (@{$args{'parameterlist'}}) {
790 print "<li class=\"indent\">";
791 print "<span class=\"param\">" . $parameter . "</span>";
792 if ($count != $#{$args{'parameterlist'}}) {
793 $count++;
794 print ",";
795 }
796 print "</li>\n";
797 }
798 print "<li>};</li>\n";
799 print "</ol>\n";
800
801 print "<section>\n";
802 print "<h1>Constants</h1>\n";
803 print "<dl>\n";
804 foreach $parameter (@{$args{'parameterlist'}}) {
805 print "<dt>" . $parameter . "</dt>\n";
806 print "<dd>";
807 output_highlight($args{'parameterdescs'}{$parameter});
808 print "</dd>\n";
809 }
810 print "</dl>\n";
811 print "</section>\n";
812 output_section_html5(@_);
813 print "</article>\n";
814}
815
816# output typedef in html5
817sub output_typedef_html5(%) {
818 my %args = %{$_[0]};
819 my ($parameter);
820 my $count;
821 my $html5id;
822
823 $html5id = $args{'typedef'};
824 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
825 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
826 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
827
828 print "<ol class=\"code\">\n";
829 print "<li>";
830 print "<span class=\"keyword\">typedef</span> ";
831 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
832 print "</li>\n";
833 print "</ol>\n";
834 output_section_html5(@_);
835 print "</article>\n";
836}
837
838# output struct in html5
839sub output_struct_html5(%) {
840 my %args = %{$_[0]};
841 my ($parameter);
842 my $html5id;
843
844 $html5id = $args{'struct'};
845 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
846 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
847 print "<hgroup>\n";
848 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
849 print "<h2>". $args{'purpose'} . "</h2>\n";
850 print "</hgroup>\n";
851 print "<ol class=\"code\">\n";
852 print "<li>";
853 print "<span class=\"type\">" . $args{'type'} . "</span> ";
854 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
855 print "</li>\n";
856 foreach $parameter (@{$args{'parameterlist'}}) {
857 print "<li class=\"indent\">";
858 if ($parameter =~ /^#/) {
859 print "<span class=\"param\">" . $parameter ."</span>\n";
860 print "</li>\n";
861 next;
862 }
863 my $parameter_name = $parameter;
864 $parameter_name =~ s/\[.*//;
865
866 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
867 $type = $args{'parametertypes'}{$parameter};
868 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
869 # pointer-to-function
870 print "<span class=\"type\">$1</span> ";
871 print "<span class=\"param\">$parameter</span>";
872 print "<span class=\"type\">)</span> ";
873 print "(<span class=\"args\">$2</span>);";
874 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
875 # bitfield
876 print "<span class=\"type\">$1</span> ";
877 print "<span class=\"param\">$parameter</span>";
878 print "<span class=\"bits\">$2</span>;";
879 } else {
880 print "<span class=\"type\">$type</span> ";
881 print "<span class=\"param\">$parameter</span>;";
882 }
883 print "</li>\n";
884 }
885 print "<li>};</li>\n";
886 print "</ol>\n";
887
888 print "<section>\n";
889 print "<h1>Members</h1>\n";
890 print "<dl>\n";
891 foreach $parameter (@{$args{'parameterlist'}}) {
892 ($parameter =~ /^#/) && next;
893
894 my $parameter_name = $parameter;
895 $parameter_name =~ s/\[.*//;
896
897 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
898 print "<dt>" . $parameter . "</dt>\n";
899 print "<dd>";
900 output_highlight($args{'parameterdescs'}{$parameter_name});
901 print "</dd>\n";
902 }
903 print "</dl>\n";
904 print "</section>\n";
905 output_section_html5(@_);
906 print "</article>\n";
907}
908
909# output function in html5
910sub output_function_html5(%) {
911 my %args = %{$_[0]};
912 my ($parameter, $section);
913 my $count;
914 my $html5id;
915
916 $html5id = $args{'function'};
917 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
918 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
919 print "<hgroup>\n";
920 print "<h1>" . $args{'function'} . "</h1>";
921 print "<h2>" . $args{'purpose'} . "</h2>\n";
922 print "</hgroup>\n";
923 print "<ol class=\"code\">\n";
924 print "<li>";
925 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
926 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
927 print "</li>";
928 $count = 0;
929 foreach $parameter (@{$args{'parameterlist'}}) {
930 print "<li class=\"indent\">";
931 $type = $args{'parametertypes'}{$parameter};
932 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
933 # pointer-to-function
934 print "<span class=\"type\">$1</span> ";
935 print "<span class=\"param\">$parameter</span>";
936 print "<span class=\"type\">)</span> ";
937 print "(<span class=\"args\">$2</span>)";
938 } else {
939 print "<span class=\"type\">$type</span> ";
940 print "<span class=\"param\">$parameter</span>";
941 }
942 if ($count != $#{$args{'parameterlist'}}) {
943 $count++;
944 print ",";
945 }
946 print "</li>\n";
947 }
948 print "<li>)</li>\n";
949 print "</ol>\n";
950
951 print "<section>\n";
952 print "<h1>Arguments</h1>\n";
953 print "<p>\n";
954 print "<dl>\n";
955 foreach $parameter (@{$args{'parameterlist'}}) {
956 my $parameter_name = $parameter;
957 $parameter_name =~ s/\[.*//;
958
959 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
960 print "<dt>" . $parameter . "</dt>\n";
961 print "<dd>";
962 output_highlight($args{'parameterdescs'}{$parameter_name});
963 print "</dd>\n";
964 }
965 print "</dl>\n";
966 print "</section>\n";
967 output_section_html5(@_);
968 print "</article>\n";
969}
970
971# output DOC: block header in html5
972sub output_blockhead_html5(%) {
973 my %args = %{$_[0]};
974 my ($parameter, $section);
975 my $count;
976 my $html5id;
977
978 foreach $section (@{$args{'sectionlist'}}) {
979 $html5id = $section;
980 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
981 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
982 print "<h1>$section</h1>\n";
983 print "<p>\n";
984 output_highlight($args{'sections'}{$section});
985 print "</p>\n";
986 }
987 print "</article>\n";
988}
989
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990sub output_section_xml(%) {
991 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800992 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 # print out each section
994 $lineprefix=" ";
995 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -0700996 print "<refsect1>\n";
997 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -0700999 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001000 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001001 } else {
1002 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 }
1004 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001005 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001007 print "</programlisting></informalexample>\n";
1008 } else {
1009 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001011 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 }
1013}
1014
1015# output function in XML DocBook
1016sub output_function_xml(%) {
1017 my %args = %{$_[0]};
1018 my ($parameter, $section);
1019 my $count;
1020 my $id;
1021
Randy Dunlapb9d973282009-06-09 08:50:38 -07001022 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 $id =~ s/[^A-Za-z0-9]/-/g;
1024
Pavel Pisa5449bc92007-02-10 01:45:37 -08001025 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001026 print "<refentryinfo>\n";
1027 print " <title>LINUX</title>\n";
1028 print " <productname>Kernel Hackers Manual</productname>\n";
1029 print " <date>$man_date</date>\n";
1030 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001032 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001033 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001034 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 print "</refmeta>\n";
1036 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001037 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 print " <refpurpose>\n";
1039 print " ";
1040 output_highlight ($args{'purpose'});
1041 print " </refpurpose>\n";
1042 print "</refnamediv>\n";
1043
1044 print "<refsynopsisdiv>\n";
1045 print " <title>Synopsis</title>\n";
1046 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001047 print " <funcdef>" . $args{'functiontype'} . " ";
1048 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049
1050 $count = 0;
1051 if ($#{$args{'parameterlist'}} >= 0) {
1052 foreach $parameter (@{$args{'parameterlist'}}) {
1053 $type = $args{'parametertypes'}{$parameter};
1054 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1055 # pointer-to-function
1056 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1057 print " <funcparams>$2</funcparams></paramdef>\n";
1058 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001059 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 print " <parameter>$parameter</parameter></paramdef>\n";
1061 }
1062 }
1063 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001064 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 }
1066 print " </funcprototype></funcsynopsis>\n";
1067 print "</refsynopsisdiv>\n";
1068
1069 # print parameters
1070 print "<refsect1>\n <title>Arguments</title>\n";
1071 if ($#{$args{'parameterlist'}} >= 0) {
1072 print " <variablelist>\n";
1073 foreach $parameter (@{$args{'parameterlist'}}) {
1074 my $parameter_name = $parameter;
1075 $parameter_name =~ s/\[.*//;
1076
1077 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1078 print " <listitem>\n <para>\n";
1079 $lineprefix=" ";
1080 output_highlight($args{'parameterdescs'}{$parameter_name});
1081 print " </para>\n </listitem>\n </varlistentry>\n";
1082 }
1083 print " </variablelist>\n";
1084 } else {
1085 print " <para>\n None\n </para>\n";
1086 }
1087 print "</refsect1>\n";
1088
1089 output_section_xml(@_);
1090 print "</refentry>\n\n";
1091}
1092
1093# output struct in XML DocBook
1094sub output_struct_xml(%) {
1095 my %args = %{$_[0]};
1096 my ($parameter, $section);
1097 my $id;
1098
Randy Dunlapb9d973282009-06-09 08:50:38 -07001099 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 $id =~ s/[^A-Za-z0-9]/-/g;
1101
Pavel Pisa5449bc92007-02-10 01:45:37 -08001102 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001103 print "<refentryinfo>\n";
1104 print " <title>LINUX</title>\n";
1105 print " <productname>Kernel Hackers Manual</productname>\n";
1106 print " <date>$man_date</date>\n";
1107 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001109 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001110 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001111 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 print "</refmeta>\n";
1113 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001114 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 print " <refpurpose>\n";
1116 print " ";
1117 output_highlight ($args{'purpose'});
1118 print " </refpurpose>\n";
1119 print "</refnamediv>\n";
1120
1121 print "<refsynopsisdiv>\n";
1122 print " <title>Synopsis</title>\n";
1123 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001124 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 foreach $parameter (@{$args{'parameterlist'}}) {
1126 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001127 my $prm = $parameter;
1128 # convert data read & converted thru xml_escape() into &xyz; format:
1129 # This allows us to have #define macros interspersed in a struct.
1130 $prm =~ s/\\\\\\/\&/g;
1131 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 next;
1133 }
1134
1135 my $parameter_name = $parameter;
1136 $parameter_name =~ s/\[.*//;
1137
1138 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001139 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140 $type = $args{'parametertypes'}{$parameter};
1141 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1142 # pointer-to-function
1143 print " $1 $parameter) ($2);\n";
1144 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001145 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 print " $1 $parameter$2;\n";
1147 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001148 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 }
1150 }
1151 print "};";
1152 print " </programlisting>\n";
1153 print "</refsynopsisdiv>\n";
1154
1155 print " <refsect1>\n";
1156 print " <title>Members</title>\n";
1157
Randy Dunlap39f00c02008-09-22 13:57:44 -07001158 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 print " <variablelist>\n";
1160 foreach $parameter (@{$args{'parameterlist'}}) {
1161 ($parameter =~ /^#/) && next;
1162
1163 my $parameter_name = $parameter;
1164 $parameter_name =~ s/\[.*//;
1165
1166 defined($args{'parameterdescs'}{$parameter_name}) || next;
1167 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1168 print " <varlistentry>";
1169 print " <term>$parameter</term>\n";
1170 print " <listitem><para>\n";
1171 output_highlight($args{'parameterdescs'}{$parameter_name});
1172 print " </para></listitem>\n";
1173 print " </varlistentry>\n";
1174 }
1175 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001176 } else {
1177 print " <para>\n None\n </para>\n";
1178 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 print " </refsect1>\n";
1180
1181 output_section_xml(@_);
1182
1183 print "</refentry>\n\n";
1184}
1185
1186# output enum in XML DocBook
1187sub output_enum_xml(%) {
1188 my %args = %{$_[0]};
1189 my ($parameter, $section);
1190 my $count;
1191 my $id;
1192
Randy Dunlapb9d973282009-06-09 08:50:38 -07001193 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 $id =~ s/[^A-Za-z0-9]/-/g;
1195
Pavel Pisa5449bc92007-02-10 01:45:37 -08001196 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001197 print "<refentryinfo>\n";
1198 print " <title>LINUX</title>\n";
1199 print " <productname>Kernel Hackers Manual</productname>\n";
1200 print " <date>$man_date</date>\n";
1201 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001203 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001204 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001205 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 print "</refmeta>\n";
1207 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001208 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209 print " <refpurpose>\n";
1210 print " ";
1211 output_highlight ($args{'purpose'});
1212 print " </refpurpose>\n";
1213 print "</refnamediv>\n";
1214
1215 print "<refsynopsisdiv>\n";
1216 print " <title>Synopsis</title>\n";
1217 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001218 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 $count = 0;
1220 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001221 print " $parameter";
1222 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 $count++;
1224 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 print "\n";
1227 }
1228 print "};";
1229 print " </programlisting>\n";
1230 print "</refsynopsisdiv>\n";
1231
1232 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001233 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 print " <variablelist>\n";
1235 foreach $parameter (@{$args{'parameterlist'}}) {
1236 my $parameter_name = $parameter;
1237 $parameter_name =~ s/\[.*//;
1238
1239 print " <varlistentry>";
1240 print " <term>$parameter</term>\n";
1241 print " <listitem><para>\n";
1242 output_highlight($args{'parameterdescs'}{$parameter_name});
1243 print " </para></listitem>\n";
1244 print " </varlistentry>\n";
1245 }
1246 print " </variablelist>\n";
1247 print "</refsect1>\n";
1248
1249 output_section_xml(@_);
1250
1251 print "</refentry>\n\n";
1252}
1253
1254# output typedef in XML DocBook
1255sub output_typedef_xml(%) {
1256 my %args = %{$_[0]};
1257 my ($parameter, $section);
1258 my $id;
1259
Randy Dunlapb9d973282009-06-09 08:50:38 -07001260 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 $id =~ s/[^A-Za-z0-9]/-/g;
1262
Pavel Pisa5449bc92007-02-10 01:45:37 -08001263 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001264 print "<refentryinfo>\n";
1265 print " <title>LINUX</title>\n";
1266 print " <productname>Kernel Hackers Manual</productname>\n";
1267 print " <date>$man_date</date>\n";
1268 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001270 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001271 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 print "</refmeta>\n";
1273 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001274 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 print " <refpurpose>\n";
1276 print " ";
1277 output_highlight ($args{'purpose'});
1278 print " </refpurpose>\n";
1279 print "</refnamediv>\n";
1280
1281 print "<refsynopsisdiv>\n";
1282 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001283 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 print "</refsynopsisdiv>\n";
1285
1286 output_section_xml(@_);
1287
1288 print "</refentry>\n\n";
1289}
1290
1291# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001292sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 my %args = %{$_[0]};
1294 my ($parameter, $section);
1295 my $count;
1296
1297 my $id = $args{'module'};
1298 $id =~ s/[^A-Za-z0-9]/-/g;
1299
1300 # print out each section
1301 $lineprefix=" ";
1302 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001303 if (!$args{'content-only'}) {
1304 print "<refsect1>\n <title>$section</title>\n";
1305 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 if ($section =~ m/EXAMPLE/i) {
1307 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001308 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001309 } else {
1310 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 }
1312 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001313 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 if ($section =~ m/EXAMPLE/i) {
1315 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001316 } else {
1317 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001319 if (!$args{'content-only'}) {
1320 print "\n</refsect1>\n";
1321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 }
1323
1324 print "\n\n";
1325}
1326
1327# output in XML DocBook
1328sub output_function_gnome {
1329 my %args = %{$_[0]};
1330 my ($parameter, $section);
1331 my $count;
1332 my $id;
1333
Randy Dunlapb9d973282009-06-09 08:50:38 -07001334 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 $id =~ s/[^A-Za-z0-9]/-/g;
1336
1337 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001338 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339
1340 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001341 print " <funcdef>" . $args{'functiontype'} . " ";
1342 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 print "</function></funcdef>\n";
1344
1345 $count = 0;
1346 if ($#{$args{'parameterlist'}} >= 0) {
1347 foreach $parameter (@{$args{'parameterlist'}}) {
1348 $type = $args{'parametertypes'}{$parameter};
1349 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1350 # pointer-to-function
1351 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1352 print " <funcparams>$2</funcparams></paramdef>\n";
1353 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001354 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 print " <parameter>$parameter</parameter></paramdef>\n";
1356 }
1357 }
1358 } else {
1359 print " <void>\n";
1360 }
1361 print " </funcsynopsis>\n";
1362 if ($#{$args{'parameterlist'}} >= 0) {
1363 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1364 print "<tgroup cols=\"2\">\n";
1365 print "<colspec colwidth=\"2*\">\n";
1366 print "<colspec colwidth=\"8*\">\n";
1367 print "<tbody>\n";
1368 foreach $parameter (@{$args{'parameterlist'}}) {
1369 my $parameter_name = $parameter;
1370 $parameter_name =~ s/\[.*//;
1371
1372 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1373 print " <entry>\n";
1374 $lineprefix=" ";
1375 output_highlight($args{'parameterdescs'}{$parameter_name});
1376 print " </entry></row>\n";
1377 }
1378 print " </tbody></tgroup></informaltable>\n";
1379 } else {
1380 print " <para>\n None\n </para>\n";
1381 }
1382
1383 # print out each section
1384 $lineprefix=" ";
1385 foreach $section (@{$args{'sectionlist'}}) {
1386 print "<simplesect>\n <title>$section</title>\n";
1387 if ($section =~ m/EXAMPLE/i) {
1388 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001389 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 } else {
1391 }
1392 print "<para>\n";
1393 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001394 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 print "</para>\n";
1396 if ($section =~ m/EXAMPLE/i) {
1397 print "</programlisting></example>\n";
1398 } else {
1399 }
1400 print " </simplesect>\n";
1401 }
1402
1403 print "</sect2>\n\n";
1404}
1405
1406##
1407# output function in man
1408sub output_function_man(%) {
1409 my %args = %{$_[0]};
1410 my ($parameter, $section);
1411 my $count;
1412
1413 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1414
1415 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001416 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417
1418 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001419 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001420 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001421 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001422 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001423 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 $count = 0;
1425 my $parenth = "(";
1426 my $post = ",";
1427 foreach my $parameter (@{$args{'parameterlist'}}) {
1428 if ($count == $#{$args{'parameterlist'}}) {
1429 $post = ");";
1430 }
1431 $type = $args{'parametertypes'}{$parameter};
1432 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1433 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001434 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 } else {
1436 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001437 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 }
1439 $count++;
1440 $parenth = "";
1441 }
1442
1443 print ".SH ARGUMENTS\n";
1444 foreach $parameter (@{$args{'parameterlist'}}) {
1445 my $parameter_name = $parameter;
1446 $parameter_name =~ s/\[.*//;
1447
Randy Dunlapb9d973282009-06-09 08:50:38 -07001448 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 output_highlight($args{'parameterdescs'}{$parameter_name});
1450 }
1451 foreach $section (@{$args{'sectionlist'}}) {
1452 print ".SH \"", uc $section, "\"\n";
1453 output_highlight($args{'sections'}{$section});
1454 }
1455}
1456
1457##
1458# output enum in man
1459sub output_enum_man(%) {
1460 my %args = %{$_[0]};
1461 my ($parameter, $section);
1462 my $count;
1463
1464 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1465
1466 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001467 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
1469 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001470 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 $count = 0;
1472 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001473 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 if ($count == $#{$args{'parameterlist'}}) {
1475 print "\n};\n";
1476 last;
1477 }
1478 else {
1479 print ", \n.br\n";
1480 }
1481 $count++;
1482 }
1483
1484 print ".SH Constants\n";
1485 foreach $parameter (@{$args{'parameterlist'}}) {
1486 my $parameter_name = $parameter;
1487 $parameter_name =~ s/\[.*//;
1488
Randy Dunlapb9d973282009-06-09 08:50:38 -07001489 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 output_highlight($args{'parameterdescs'}{$parameter_name});
1491 }
1492 foreach $section (@{$args{'sectionlist'}}) {
1493 print ".SH \"$section\"\n";
1494 output_highlight($args{'sections'}{$section});
1495 }
1496}
1497
1498##
1499# output struct in man
1500sub output_struct_man(%) {
1501 my %args = %{$_[0]};
1502 my ($parameter, $section);
1503
Randy Dunlapb9d973282009-06-09 08:50:38 -07001504 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
1506 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001507 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
1509 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001510 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
1512 foreach my $parameter (@{$args{'parameterlist'}}) {
1513 if ($parameter =~ /^#/) {
1514 print ".BI \"$parameter\"\n.br\n";
1515 next;
1516 }
1517 my $parameter_name = $parameter;
1518 $parameter_name =~ s/\[.*//;
1519
Randy Dunlap3c308792007-05-08 00:24:39 -07001520 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 $type = $args{'parametertypes'}{$parameter};
1522 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1523 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001524 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001526 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001527 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 } else {
1529 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001530 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 }
1532 print "\n.br\n";
1533 }
1534 print "};\n.br\n";
1535
Randy Dunlapc51d3dac2006-06-25 05:49:14 -07001536 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 foreach $parameter (@{$args{'parameterlist'}}) {
1538 ($parameter =~ /^#/) && next;
1539
1540 my $parameter_name = $parameter;
1541 $parameter_name =~ s/\[.*//;
1542
Randy Dunlap3c308792007-05-08 00:24:39 -07001543 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001544 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 output_highlight($args{'parameterdescs'}{$parameter_name});
1546 }
1547 foreach $section (@{$args{'sectionlist'}}) {
1548 print ".SH \"$section\"\n";
1549 output_highlight($args{'sections'}{$section});
1550 }
1551}
1552
1553##
1554# output typedef in man
1555sub output_typedef_man(%) {
1556 my %args = %{$_[0]};
1557 my ($parameter, $section);
1558
1559 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1560
1561 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001562 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
1564 foreach $section (@{$args{'sectionlist'}}) {
1565 print ".SH \"$section\"\n";
1566 output_highlight($args{'sections'}{$section});
1567 }
1568}
1569
Johannes Bergb112e0f2007-10-24 15:08:48 -07001570sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 my %args = %{$_[0]};
1572 my ($parameter, $section);
1573 my $count;
1574
1575 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1576
1577 foreach $section (@{$args{'sectionlist'}}) {
1578 print ".SH \"$section\"\n";
1579 output_highlight($args{'sections'}{$section});
1580 }
1581}
1582
1583##
1584# output in text
1585sub output_function_text(%) {
1586 my %args = %{$_[0]};
1587 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001588 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589
Randy Dunlapf47634b2006-07-01 04:36:36 -07001590 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001591 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001592
1593 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001594 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001595 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001596 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001597 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001598 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001600
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 my $count = 0;
1602 foreach my $parameter (@{$args{'parameterlist'}}) {
1603 $type = $args{'parametertypes'}{$parameter};
1604 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1605 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001606 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001608 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609 }
1610 if ($count != $#{$args{'parameterlist'}}) {
1611 $count++;
1612 print ",\n";
1613 print " " x length($start);
1614 } else {
1615 print ");\n\n";
1616 }
1617 }
1618
1619 print "Arguments:\n\n";
1620 foreach $parameter (@{$args{'parameterlist'}}) {
1621 my $parameter_name = $parameter;
1622 $parameter_name =~ s/\[.*//;
1623
Randy Dunlapb9d973282009-06-09 08:50:38 -07001624 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 }
1626 output_section_text(@_);
1627}
1628
1629#output sections in text
1630sub output_section_text(%) {
1631 my %args = %{$_[0]};
1632 my $section;
1633
1634 print "\n";
1635 foreach $section (@{$args{'sectionlist'}}) {
1636 print "$section:\n\n";
1637 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 print "\n\n";
1640}
1641
1642# output enum in text
1643sub output_enum_text(%) {
1644 my %args = %{$_[0]};
1645 my ($parameter);
1646 my $count;
1647 print "Enum:\n\n";
1648
Randy Dunlapb9d973282009-06-09 08:50:38 -07001649 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1650 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 $count = 0;
1652 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001653 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 if ($count != $#{$args{'parameterlist'}}) {
1655 $count++;
1656 print ",";
1657 }
1658 print "\n";
1659 }
1660 print "};\n\n";
1661
1662 print "Constants:\n\n";
1663 foreach $parameter (@{$args{'parameterlist'}}) {
1664 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001665 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 }
1667
1668 output_section_text(@_);
1669}
1670
1671# output typedef in text
1672sub output_typedef_text(%) {
1673 my %args = %{$_[0]};
1674 my ($parameter);
1675 my $count;
1676 print "Typedef:\n\n";
1677
Randy Dunlapb9d973282009-06-09 08:50:38 -07001678 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 output_section_text(@_);
1680}
1681
1682# output struct as text
1683sub output_struct_text(%) {
1684 my %args = %{$_[0]};
1685 my ($parameter);
1686
Randy Dunlapb9d973282009-06-09 08:50:38 -07001687 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1688 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 foreach $parameter (@{$args{'parameterlist'}}) {
1690 if ($parameter =~ /^#/) {
1691 print "$parameter\n";
1692 next;
1693 }
1694
1695 my $parameter_name = $parameter;
1696 $parameter_name =~ s/\[.*//;
1697
Randy Dunlap3c308792007-05-08 00:24:39 -07001698 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 $type = $args{'parametertypes'}{$parameter};
1700 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1701 # pointer-to-function
1702 print "\t$1 $parameter) ($2);\n";
1703 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001704 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 print "\t$1 $parameter$2;\n";
1706 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001707 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 }
1709 }
1710 print "};\n\n";
1711
1712 print "Members:\n\n";
1713 foreach $parameter (@{$args{'parameterlist'}}) {
1714 ($parameter =~ /^#/) && next;
1715
1716 my $parameter_name = $parameter;
1717 $parameter_name =~ s/\[.*//;
1718
Randy Dunlap3c308792007-05-08 00:24:39 -07001719 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001721 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 }
1723 print "\n";
1724 output_section_text(@_);
1725}
1726
Johannes Bergb112e0f2007-10-24 15:08:48 -07001727sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 my %args = %{$_[0]};
1729 my ($parameter, $section);
1730
1731 foreach $section (@{$args{'sectionlist'}}) {
1732 print " $section:\n";
1733 print " -> ";
1734 output_highlight($args{'sections'}{$section});
1735 }
1736}
1737
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001738##
1739# output in restructured text
1740#
1741
1742#
1743# This could use some work; it's used to output the DOC: sections, and
1744# starts by putting out the name of the doc section itself, but that tends
1745# to duplicate a header already in the template file.
1746#
1747sub output_blockhead_rst(%) {
1748 my %args = %{$_[0]};
1749 my ($parameter, $section);
1750
1751 foreach $section (@{$args{'sectionlist'}}) {
1752 print "**$section**\n\n";
1753 output_highlight_rst($args{'sections'}{$section});
1754 print "\n";
1755 }
1756}
1757
1758sub output_highlight_rst {
1759 my $contents = join "\n",@_;
1760 my $line;
1761
1762 # undo the evil effects of xml_escape() earlier
1763 $contents = xml_unescape($contents);
1764
1765 eval $dohighlight;
1766 die $@ if $@;
1767
1768 foreach $line (split "\n", $contents) {
1769 if ($line eq "") {
1770 print $lineprefix, $blankline;
1771 } else {
1772 $line =~ s/\\\\\\/\&/g;
1773 print $lineprefix, $line;
1774 }
1775 print "\n";
1776 }
1777}
1778
1779sub output_function_rst(%) {
1780 my %args = %{$_[0]};
1781 my ($parameter, $section);
1782 my $start;
1783
1784 print ".. c:function:: ";
1785 if ($args{'functiontype'} ne "") {
1786 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1787 } else {
1788 $start = $args{'function'} . " (";
1789 }
1790 print $start;
1791
1792 my $count = 0;
1793 foreach my $parameter (@{$args{'parameterlist'}}) {
1794 if ($count ne 0) {
1795 print ", ";
1796 }
1797 $count++;
1798 $type = $args{'parametertypes'}{$parameter};
1799 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1800 # pointer-to-function
1801 print $1 . $parameter . ") (" . $2;
1802 } else {
1803 print $type . " " . $parameter;
1804 }
1805 }
1806 print ")\n\n " . $args{'purpose'} . "\n\n";
1807
1808 print ":Parameters:\n\n";
1809 foreach $parameter (@{$args{'parameterlist'}}) {
1810 my $parameter_name = $parameter;
1811 #$parameter_name =~ s/\[.*//;
1812 $type = $args{'parametertypes'}{$parameter};
1813
1814 if ($type ne "") {
1815 print " ``$type $parameter``\n";
1816 } else {
1817 print " ``$parameter``\n";
1818 }
Jani Nikula5e64fa92016-05-19 20:32:48 +03001819 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1820 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001821 my $oldprefix = $lineprefix;
1822 $lineprefix = " ";
1823 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
1824 $lineprefix = $oldprefix;
1825 } else {
1826 print "\n _undescribed_\n";
1827 }
1828 print "\n";
1829 }
1830 output_section_rst(@_);
1831}
1832
1833sub output_section_rst(%) {
1834 my %args = %{$_[0]};
1835 my $section;
1836 my $oldprefix = $lineprefix;
1837 $lineprefix = " ";
1838
1839 foreach $section (@{$args{'sectionlist'}}) {
1840 print ":$section:\n\n";
1841 output_highlight_rst($args{'sections'}{$section});
1842 print "\n";
1843 }
1844 print "\n";
1845 $lineprefix = $oldprefix;
1846}
1847
1848sub output_enum_rst(%) {
1849 my %args = %{$_[0]};
1850 my ($parameter);
1851 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001852 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001853
1854 print "\n\n.. c:type:: " . $name . "\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001855 print " " . $args{'purpose'} . "\n\n";
1856
1857 print "..\n\n:Constants:\n\n";
1858 my $oldprefix = $lineprefix;
1859 $lineprefix = " ";
1860 foreach $parameter (@{$args{'parameterlist'}}) {
1861 print " `$parameter`\n";
1862 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1863 output_highlight_rst($args{'parameterdescs'}{$parameter});
1864 } else {
1865 print " undescribed\n";
1866 }
1867 print "\n";
1868 }
1869 $lineprefix = $oldprefix;
1870 output_section_rst(@_);
1871}
1872
1873sub output_typedef_rst(%) {
1874 my %args = %{$_[0]};
1875 my ($parameter);
1876 my $count;
1877 my $name = "typedef " . $args{'typedef'};
1878
Jani Nikula62850972016-05-12 16:15:38 +03001879 ### FIXME: should the name below contain "typedef" or not?
1880 print "\n\n.. c:type:: " . $name . "\n\n";
1881 print " " . $args{'purpose'} . "\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001882
1883 output_section_rst(@_);
1884}
1885
1886sub output_struct_rst(%) {
1887 my %args = %{$_[0]};
1888 my ($parameter);
1889 my $name = $args{'type'} . " " . $args{'struct'};
1890
Jani Nikula62850972016-05-12 16:15:38 +03001891 print "\n\n.. c:type:: " . $name . "\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001892 print " " . $args{'purpose'} . "\n\n";
1893
1894 print ":Definition:\n\n";
1895 print " ::\n\n";
1896 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1897 foreach $parameter (@{$args{'parameterlist'}}) {
1898 if ($parameter =~ /^#/) {
1899 print " " . "$parameter\n";
1900 next;
1901 }
1902
1903 my $parameter_name = $parameter;
1904 $parameter_name =~ s/\[.*//;
1905
1906 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1907 $type = $args{'parametertypes'}{$parameter};
1908 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1909 # pointer-to-function
1910 print " $1 $parameter) ($2);\n";
1911 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1912 # bitfield
1913 print " $1 $parameter$2;\n";
1914 } else {
1915 print " " . $type . " " . $parameter . ";\n";
1916 }
1917 }
1918 print " };\n\n";
1919
1920 print ":Members:\n\n";
1921 foreach $parameter (@{$args{'parameterlist'}}) {
1922 ($parameter =~ /^#/) && next;
1923
1924 my $parameter_name = $parameter;
1925 $parameter_name =~ s/\[.*//;
1926
1927 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1928 $type = $args{'parametertypes'}{$parameter};
1929 print " `$type $parameter`" . "\n";
1930 my $oldprefix = $lineprefix;
1931 $lineprefix = " ";
1932 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
1933 $lineprefix = $oldprefix;
1934 print "\n";
1935 }
1936 print "\n";
1937 output_section_rst(@_);
1938}
1939
1940
Johannes Bergeda603f2010-09-11 15:55:22 -07001941## list mode output functions
1942
1943sub output_function_list(%) {
1944 my %args = %{$_[0]};
1945
1946 print $args{'function'} . "\n";
1947}
1948
1949# output enum in list
1950sub output_enum_list(%) {
1951 my %args = %{$_[0]};
1952 print $args{'enum'} . "\n";
1953}
1954
1955# output typedef in list
1956sub output_typedef_list(%) {
1957 my %args = %{$_[0]};
1958 print $args{'typedef'} . "\n";
1959}
1960
1961# output struct as list
1962sub output_struct_list(%) {
1963 my %args = %{$_[0]};
1964
1965 print $args{'struct'} . "\n";
1966}
1967
1968sub output_blockhead_list(%) {
1969 my %args = %{$_[0]};
1970 my ($parameter, $section);
1971
1972 foreach $section (@{$args{'sectionlist'}}) {
1973 print "DOC: $section\n";
1974 }
1975}
1976
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977##
Randy Dunlap27205742006-10-11 01:22:12 -07001978# generic output function for all types (function, struct/union, typedef, enum);
1979# calls the generated, variable output_ function name based on
1980# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981sub output_declaration {
1982 no strict 'refs';
1983 my $name = shift;
1984 my $functype = shift;
1985 my $func = "output_${functype}_$output_mode";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001986 if (($function_only==0) ||
Jani Nikula86ae2e32016-01-21 13:05:22 +02001987 ( ($function_only == 1 || $function_only == 3) &&
1988 defined($function_table{$name})) ||
1989 ( ($function_only == 2 || $function_only == 4) &&
1990 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 {
Randy Dunlap3c308792007-05-08 00:24:39 -07001992 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993 $section_counter++;
1994 }
1995}
1996
1997##
Randy Dunlap27205742006-10-11 01:22:12 -07001998# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07001999sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002001 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 &$func(@_);
2003 $section_counter++;
2004}
2005
2006##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002007# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008# invokes the right handler. NOT called for functions.
2009sub dump_declaration($$) {
2010 no strict 'refs';
2011 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002012 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 &$func(@_);
2014}
2015
2016sub dump_union($$) {
2017 dump_struct(@_);
2018}
2019
2020sub dump_struct($$) {
2021 my $x = shift;
2022 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002023 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002025 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2026 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002027 $declaration_name = $2;
2028 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
2030 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002031 $members =~ s/({.*})//g;
2032 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033
Martin Waitzaeec46b2005-11-13 16:08:13 -08002034 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002035 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2036 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002037 # strip comments:
2038 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002039 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002040 # strip kmemcheck_bitfield_{begin,end}.*;
2041 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002042 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002043 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002044 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002045 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002046 # replace DECLARE_BITMAP
2047 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002048
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002050 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051
2052 output_declaration($declaration_name,
2053 'struct',
2054 {'struct' => $declaration_name,
2055 'module' => $modulename,
2056 'parameterlist' => \@parameterlist,
2057 'parameterdescs' => \%parameterdescs,
2058 'parametertypes' => \%parametertypes,
2059 'sectionlist' => \@sectionlist,
2060 'sections' => \%sections,
2061 'purpose' => $declaration_purpose,
2062 'type' => $decl_type
2063 });
2064 }
2065 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002066 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 ++$errors;
2068 }
2069}
2070
2071sub dump_enum($$) {
2072 my $x = shift;
2073 my $file = shift;
2074
Martin Waitzaeec46b2005-11-13 16:08:13 -08002075 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002076 # strip #define macros inside enums
2077 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002078
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002080 $declaration_name = $1;
2081 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082
2083 foreach my $arg (split ',', $members) {
2084 $arg =~ s/^\s*(\w+).*/$1/;
2085 push @parameterlist, $arg;
2086 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002087 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002088 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 "not described in enum '$declaration_name'\n";
2090 }
2091
2092 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002093
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 output_declaration($declaration_name,
2095 'enum',
2096 {'enum' => $declaration_name,
2097 'module' => $modulename,
2098 'parameterlist' => \@parameterlist,
2099 'parameterdescs' => \%parameterdescs,
2100 'sectionlist' => \@sectionlist,
2101 'sections' => \%sections,
2102 'purpose' => $declaration_purpose
2103 });
2104 }
2105 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002106 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 ++$errors;
2108 }
2109}
2110
2111sub dump_typedef($$) {
2112 my $x = shift;
2113 my $file = shift;
2114
Martin Waitzaeec46b2005-11-13 16:08:13 -08002115 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002116
2117 # Parse function prototypes
2118 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
2119 # Function typedefs
2120 $return_type = $1;
2121 $declaration_name = $2;
2122 my $args = $3;
2123
2124 create_parameterlist($args, ',', $file);
2125
2126 output_declaration($declaration_name,
2127 'function',
2128 {'function' => $declaration_name,
2129 'module' => $modulename,
2130 'functiontype' => $return_type,
2131 'parameterlist' => \@parameterlist,
2132 'parameterdescs' => \%parameterdescs,
2133 'parametertypes' => \%parametertypes,
2134 'sectionlist' => \@sectionlist,
2135 'sections' => \%sections,
2136 'purpose' => $declaration_purpose
2137 });
2138 return;
2139 }
2140
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002142 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 $x =~ s/\[*.\]\s*;$/;/;
2144 }
2145
2146 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002147 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148
2149 output_declaration($declaration_name,
2150 'typedef',
2151 {'typedef' => $declaration_name,
2152 'module' => $modulename,
2153 'sectionlist' => \@sectionlist,
2154 'sections' => \%sections,
2155 'purpose' => $declaration_purpose
2156 });
2157 }
2158 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002159 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 ++$errors;
2161 }
2162}
2163
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002164sub save_struct_actual($) {
2165 my $actual = shift;
2166
2167 # strip all spaces from the actual param so that it looks like one string item
2168 $actual =~ s/\s*//g;
2169 $struct_actual = $struct_actual . $actual . " ";
2170}
2171
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172sub create_parameterlist($$$) {
2173 my $args = shift;
2174 my $splitter = shift;
2175 my $file = shift;
2176 my $type;
2177 my $param;
2178
Martin Waitza6d3fe72006-01-09 20:53:55 -08002179 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002181 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002183
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 foreach my $arg (split($splitter, $args)) {
2185 # strip comments
2186 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002187 # strip leading/trailing spaces
2188 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 $arg =~ s/\s*$//;
2190 $arg =~ s/\s+/ /;
2191
2192 if ($arg =~ /^#/) {
2193 # Treat preprocessor directive as a typeless variable just to fill
2194 # corresponding data structures "correctly". Catch it later in
2195 # output_* subs.
2196 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002197 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 # pointer-to-function
2199 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002200 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 $param = $1;
2202 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002203 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002204 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002206 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 $arg =~ s/\s*:\s*/:/g;
2208 $arg =~ s/\s*\[/\[/g;
2209
2210 my @args = split('\s*,\s*', $arg);
2211 if ($args[0] =~ m/\*/) {
2212 $args[0] =~ s/(\*+)\s*/ $1/;
2213 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002214
2215 my @first_arg;
2216 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2217 shift @args;
2218 push(@first_arg, split('\s+', $1));
2219 push(@first_arg, $2);
2220 } else {
2221 @first_arg = split('\s+', shift @args);
2222 }
2223
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 unshift(@args, pop @first_arg);
2225 $type = join " ", @first_arg;
2226
2227 foreach $param (@args) {
2228 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002229 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 push_parameter($2, "$type $1", $file);
2231 }
2232 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002233 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002234 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002235 push_parameter($1, "$type:$2", $file)
2236 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 }
2238 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002239 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 push_parameter($param, $type, $file);
2241 }
2242 }
2243 }
2244 }
2245}
2246
2247sub push_parameter($$$) {
2248 my $param = shift;
2249 my $type = shift;
2250 my $file = shift;
2251
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002252 if (($anon_struct_union == 1) && ($type eq "") &&
2253 ($param eq "}")) {
2254 return; # ignore the ending }; from anon. struct/union
2255 }
2256
2257 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 my $param_name = $param;
2259 $param_name =~ s/\[.*//;
2260
Martin Waitza6d3fe72006-01-09 20:53:55 -08002261 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 {
Randy Dunlapced69092008-12-01 13:14:03 -08002263 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2264 $parameterdescs{$param} = "variable arguments";
2265 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 }
2267 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2268 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 $param="void";
2270 $parameterdescs{void} = "no arguments";
2271 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002272 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2273 # handle unnamed (anonymous) union or struct:
2274 {
2275 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002276 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002277 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002278 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002279 }
2280
Martin Waitza6d3fe72006-01-09 20:53:55 -08002281 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002282 # (but ignore ones starting with # as these are not parameters
2283 # but inline preprocessor statements);
2284 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002285 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002286 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2287
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 $parameterdescs{$param_name} = $undescribed;
2289
2290 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002291 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 "or member '$param' not " .
2293 "described in '$declaration_name'\n";
2294 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002295 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002296 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002298 }
2299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002301 $param = xml_escape($param);
2302
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002303 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002304 # on @parameterlist;
2305 # this fixes a problem where check_sections() cannot find
2306 # a parameter like "addr[6 + 2]" because it actually appears
2307 # as "addr[6", "+", "2]" on the parameter list;
2308 # but it's better to maintain the param string unchanged for output,
2309 # so just weaken the string compare in check_sections() to ignore
2310 # "[blah" in a parameter string;
2311 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 push @parameterlist, $param;
2313 $parametertypes{$param} = $type;
2314}
2315
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002316sub check_sections($$$$$$) {
2317 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2318 my @sects = split ' ', $sectcheck;
2319 my @prms = split ' ', $prmscheck;
2320 my $err;
2321 my ($px, $sx);
2322 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2323
2324 foreach $sx (0 .. $#sects) {
2325 $err = 1;
2326 foreach $px (0 .. $#prms) {
2327 $prm_clean = $prms[$px];
2328 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002329 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002330 # ignore array size in a parameter string;
2331 # however, the original param string may contain
2332 # spaces, e.g.: addr[6 + 2]
2333 # and this appears in @prms as "addr[6" since the
2334 # parameter list is split at spaces;
2335 # hence just ignore "[..." for the sections check;
2336 $prm_clean =~ s/\[.*//;
2337
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002338 ##$prm_clean =~ s/^\**//;
2339 if ($prm_clean eq $sects[$sx]) {
2340 $err = 0;
2341 last;
2342 }
2343 }
2344 if ($err) {
2345 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002346 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002347 "Excess function parameter " .
2348 "'$sects[$sx]' " .
2349 "description in '$decl_name'\n";
2350 ++$warnings;
2351 } else {
2352 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002353 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002354 "Excess struct/union/enum/typedef member " .
2355 "'$sects[$sx]' " .
2356 "description in '$decl_name'\n";
2357 ++$warnings;
2358 }
2359 }
2360 }
2361 }
2362}
2363
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002365# Checks the section describing the return value of a function.
2366sub check_return_section {
2367 my $file = shift;
2368 my $declaration_name = shift;
2369 my $return_type = shift;
2370
2371 # Ignore an empty return type (It's a macro)
2372 # Ignore functions with a "void" return type. (But don't ignore "void *")
2373 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2374 return;
2375 }
2376
2377 if (!defined($sections{$section_return}) ||
2378 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002379 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002380 "No description found for return value of " .
2381 "'$declaration_name'\n";
2382 ++$warnings;
2383 }
2384}
2385
2386##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387# takes a function prototype and the name of the current file being
2388# processed and spits out all the details stored in the global
2389# arrays/hashes.
2390sub dump_function($$) {
2391 my $prototype = shift;
2392 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002393 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
2395 $prototype =~ s/^static +//;
2396 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002397 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 $prototype =~ s/^inline +//;
2399 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002400 $prototype =~ s/^__inline +//;
2401 $prototype =~ s/^__always_inline +//;
2402 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002403 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002404 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002405 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002406 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002407 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002408 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002409 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410
2411 # Yes, this truly is vile. We are looking for:
2412 # 1. Return type (may be nothing if we're looking at a macro)
2413 # 2. Function name
2414 # 3. Function parameters.
2415 #
2416 # All the while we have to watch out for function pointer parameters
2417 # (which IIRC is what the two sections are for), C types (these
2418 # regexps don't even start to express all the possibilities), and
2419 # so on.
2420 #
2421 # If you mess with these regexps, it's a good idea to check that
2422 # the following functions' documentation still comes out right:
2423 # - parport_register_device (function pointer parameters)
2424 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002425 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002427 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2428 # This is an object-like macro, it has no return type and no parameter
2429 # list.
2430 # Function-like macros are not allowed to have spaces between
2431 # declaration_name and opening parenthesis (notice the \s+).
2432 $return_type = $1;
2433 $declaration_name = $2;
2434 $noret = 1;
2435 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2437 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2438 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002439 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2441 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2442 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2443 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2444 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2445 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2446 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2447 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002448 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2449 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002450 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2451 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 $return_type = $1;
2453 $declaration_name = $2;
2454 my $args = $3;
2455
2456 create_parameterlist($args, ',', $file);
2457 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002458 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459 return;
2460 }
2461
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002462 my $prms = join " ", @parameterlist;
2463 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2464
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002465 # This check emits a lot of warnings at the moment, because many
2466 # functions don't have a 'Return' doc section. So until the number
2467 # of warnings goes sufficiently down, the check is only performed in
2468 # verbose mode.
2469 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002470 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002471 check_return_section($file, $declaration_name, $return_type);
2472 }
2473
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002474 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 'function',
2476 {'function' => $declaration_name,
2477 'module' => $modulename,
2478 'functiontype' => $return_type,
2479 'parameterlist' => \@parameterlist,
2480 'parameterdescs' => \%parameterdescs,
2481 'parametertypes' => \%parametertypes,
2482 'sectionlist' => \@sectionlist,
2483 'sections' => \%sections,
2484 'purpose' => $declaration_purpose
2485 });
2486}
2487
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488sub reset_state {
2489 $function = "";
2490 %constants = ();
2491 %parameterdescs = ();
2492 %parametertypes = ();
2493 @parameterlist = ();
2494 %sections = ();
2495 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002496 $sectcheck = "";
2497 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002499
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 $state = 0;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002501 $split_doc_state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502}
2503
Jason Baron56afb0f2009-04-30 13:29:36 -04002504sub tracepoint_munge($) {
2505 my $file = shift;
2506 my $tracepointname = 0;
2507 my $tracepointargs = 0;
2508
Jason Baron3a9089f2009-12-01 12:18:49 -05002509 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002510 $tracepointname = $1;
2511 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002512 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2513 $tracepointname = $1;
2514 }
2515 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2516 $tracepointname = $2;
2517 }
2518 $tracepointname =~ s/^\s+//; #strip leading whitespace
2519 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002520 $tracepointargs = $1;
2521 }
2522 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002523 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002524 "$prototype\n";
2525 } else {
2526 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2527 }
2528}
2529
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002530sub syscall_munge() {
2531 my $void = 0;
2532
2533 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2534## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2535 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2536 $void = 1;
2537## $prototype = "long sys_$1(void)";
2538 }
2539
2540 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2541 if ($prototype =~ m/long (sys_.*?),/) {
2542 $prototype =~ s/,/\(/;
2543 } elsif ($void) {
2544 $prototype =~ s/\)/\(void\)/;
2545 }
2546
2547 # now delete all of the odd-number commas in $prototype
2548 # so that arg types & arg names don't have a comma between them
2549 my $count = 0;
2550 my $len = length($prototype);
2551 if ($void) {
2552 $len = 0; # skip the for-loop
2553 }
2554 for (my $ix = 0; $ix < $len; $ix++) {
2555 if (substr($prototype, $ix, 1) eq ',') {
2556 $count++;
2557 if ($count % 2 == 1) {
2558 substr($prototype, $ix, 1) = ' ';
2559 }
2560 }
2561 }
2562}
2563
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002564sub process_state3_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 my $x = shift;
2566 my $file = shift;
2567
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002568 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2569
Randy Dunlap890c78c2008-10-25 17:06:43 -07002570 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 # do nothing
2572 }
2573 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002574 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002576
Randy Dunlap890c78c2008-10-25 17:06:43 -07002577 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002578 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2580 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002581 if ($prototype =~ /SYSCALL_DEFINE/) {
2582 syscall_munge();
2583 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002584 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2585 $prototype =~ /DEFINE_SINGLE_EVENT/)
2586 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002587 tracepoint_munge($file);
2588 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002589 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 reset_state();
2591 }
2592}
2593
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002594sub process_state3_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 my $x = shift;
2596 my $file = shift;
2597
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2599 $x =~ s@^\s+@@gos; # strip leading spaces
2600 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002601 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2602
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 if ($x =~ /^#/) {
2604 # To distinguish preprocessor directive from regular declaration later.
2605 $x .= ";";
2606 }
2607
2608 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002609 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002610 $prototype .= $1 . $2;
2611 ($2 eq '{') && $brcount++;
2612 ($2 eq '}') && $brcount--;
2613 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002614 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002616 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617 }
2618 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002619 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 $prototype .= $x;
2621 last;
2622 }
2623 }
2624}
2625
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002626# xml_escape: replace <, >, and & in the text stream;
2627#
2628# however, formatting controls that are generated internally/locally in the
2629# kernel-doc script are not escaped here; instead, they begin life like
2630# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2631# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2632# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633sub xml_escape($) {
2634 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002635 if (($output_mode eq "text") || ($output_mode eq "man")) {
2636 return $text;
2637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 $text =~ s/\&/\\\\\\amp;/g;
2639 $text =~ s/\</\\\\\\lt;/g;
2640 $text =~ s/\>/\\\\\\gt;/g;
2641 return $text;
2642}
2643
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002644# xml_unescape: reverse the effects of xml_escape
2645sub xml_unescape($) {
2646 my $text = shift;
2647 if (($output_mode eq "text") || ($output_mode eq "man")) {
2648 return $text;
2649 }
2650 $text =~ s/\\\\\\amp;/\&/g;
2651 $text =~ s/\\\\\\lt;/</g;
2652 $text =~ s/\\\\\\gt;/>/g;
2653 return $text;
2654}
2655
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002656# convert local escape strings to html
2657# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2658sub local_unescape($) {
2659 my $text = shift;
2660 if (($output_mode eq "text") || ($output_mode eq "man")) {
2661 return $text;
2662 }
2663 $text =~ s/\\\\\\\\lt:/</g;
2664 $text =~ s/\\\\\\\\gt:/>/g;
2665 return $text;
2666}
2667
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002669 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 my $identifier;
2671 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002672 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002673 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002675 my ($orig_file) = @_;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676
Randy Dunlap2283a112005-07-07 15:39:26 -07002677 if (defined($ENV{'SRCTREE'})) {
Ben Hutchings68f86662015-09-01 23:48:49 +01002678 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002679 }
2680 else {
Ben Hutchings68f86662015-09-01 23:48:49 +01002681 $file = $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002682 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 if (defined($source_map{$file})) {
2684 $file = $source_map{$file};
2685 }
2686
2687 if (!open(IN,"<$file")) {
2688 print STDERR "Error: Cannot open file $file\n";
2689 ++$errors;
2690 return;
2691 }
2692
Jani Nikula86ae2e32016-01-21 13:05:22 +02002693 # two passes for -export and -internal
2694 if ($function_only == 3 || $function_only == 4) {
2695 while (<IN>) {
2696 if (/$export_symbol/o) {
2697 $function_table{$2} = 1;
2698 }
2699 }
2700 seek(IN, 0, 0);
2701 }
2702
Ilya Dryomova9e73142010-02-26 13:05:47 -08002703 $. = 1;
2704
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 $section_counter = 0;
2706 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002707 while (s/\\\s*$//) {
2708 $_ .= <IN>;
2709 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 if ($state == 0) {
2711 if (/$doc_start/o) {
2712 $state = 1; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002713 $in_doc_sect = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 }
2715 } elsif ($state == 1) { # this line is the function name (always)
2716 if (/$doc_block/o) {
2717 $state = 4;
2718 $contents = "";
2719 if ( $1 eq "" ) {
2720 $section = $section_intro;
2721 } else {
2722 $section = $1;
2723 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002724 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 elsif (/$doc_decl/o) {
2726 $identifier = $1;
2727 if (/\s*([\w\s]+?)\s*-/) {
2728 $identifier = $1;
2729 }
2730
2731 $state = 2;
2732 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002733 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002734 $descr= $1;
2735 $descr =~ s/^\s*//;
2736 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002737 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002738 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002739 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 } else {
2741 $declaration_purpose = "";
2742 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002743
2744 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002745 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002746 print STDERR $_;
2747 ++$warnings;
2748 }
2749
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 if ($identifier =~ m/^struct/) {
2751 $decl_type = 'struct';
2752 } elsif ($identifier =~ m/^union/) {
2753 $decl_type = 'union';
2754 } elsif ($identifier =~ m/^enum/) {
2755 $decl_type = 'enum';
2756 } elsif ($identifier =~ m/^typedef/) {
2757 $decl_type = 'typedef';
2758 } else {
2759 $decl_type = 'function';
2760 }
2761
2762 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002763 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 }
2765 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002766 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 " - I thought it was a doc line\n";
2768 ++$warnings;
2769 $state = 0;
2770 }
2771 } elsif ($state == 2) { # look for head: lines, and include content
2772 if (/$doc_sect/o) {
2773 $newsection = $1;
2774 $newcontents = $2;
2775
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002776 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002777 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002778 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002779 ++$warnings;
2780 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002781 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 $section = $section_default;
2783 }
2784
Randy Dunlap850622d2006-06-25 05:48:55 -07002785 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002786 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 $contents = $newcontents;
2788 if ($contents ne "") {
Randy Dunlap27205742006-10-11 01:22:12 -07002789 while ((substr($contents, 0, 1) eq " ") ||
2790 substr($contents, 0, 1) eq "\t") {
2791 $contents = substr($contents, 1);
Randy Dunlap05189492006-06-25 05:47:47 -07002792 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 $contents .= "\n";
2794 }
2795 $section = $newsection;
2796 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002797 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002798 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 $section = $section_default;
2800 $contents = "";
2801 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002802 # look for doc_com + <text> + doc_end:
2803 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002804 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002805 ++$warnings;
2806 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807
2808 $prototype = "";
2809 $state = 3;
2810 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002811# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 } elsif (/$doc_content/) {
2813 # miguel-style comment kludge, look for blank lines after
2814 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002815 if ($1 eq "") {
2816 if ($section =~ m/^@/ || $section eq $section_context) {
2817 dump_section($file, $section, xml_escape($contents));
2818 $section = $section_default;
2819 $contents = "";
2820 } else {
2821 $contents .= "\n";
2822 }
2823 $in_purpose = 0;
2824 } elsif ($in_purpose == 1) {
2825 # Continued declaration purpose
2826 chomp($declaration_purpose);
2827 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002828 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002830 $contents .= $1 . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 }
2832 } else {
2833 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002834 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 ++$warnings;
2836 }
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002837 } elsif ($state == 5) { # scanning for split parameters
2838 # First line (state 1) needs to be a @parameter
2839 if ($split_doc_state == 1 && /$doc_split_sect/o) {
2840 $section = $1;
2841 $contents = $2;
2842 if ($contents ne "") {
2843 while ((substr($contents, 0, 1) eq " ") ||
2844 substr($contents, 0, 1) eq "\t") {
2845 $contents = substr($contents, 1);
2846 }
2847 $contents .= "\n";
2848 }
2849 $split_doc_state = 2;
2850 # Documentation block end */
2851 } elsif (/$doc_split_end/) {
2852 if (($contents ne "") && ($contents ne "\n")) {
2853 dump_section($file, $section, xml_escape($contents));
2854 $section = $section_default;
2855 $contents = "";
2856 }
2857 $state = 3;
2858 $split_doc_state = 0;
2859 # Regular text
2860 } elsif (/$doc_content/) {
2861 if ($split_doc_state == 2) {
2862 $contents .= $1 . "\n";
2863 } elsif ($split_doc_state == 1) {
2864 $split_doc_state = 4;
2865 print STDERR "Warning(${file}:$.): ";
2866 print STDERR "Incorrect use of kernel-doc format: $_";
2867 ++$warnings;
2868 }
2869 }
Randy Dunlap232acbc2006-06-25 05:47:48 -07002870 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002871 if (/$doc_split_start/) {
2872 $state = 5;
2873 $split_doc_state = 1;
2874 } elsif ($decl_type eq 'function') {
Randy Dunlap3c308792007-05-08 00:24:39 -07002875 process_state3_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -07002877 process_state3_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 }
2879 } elsif ($state == 4) {
2880 # Documentation block
Randy Dunlap3c308792007-05-08 00:24:39 -07002881 if (/$doc_block/) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002882 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 $contents = "";
2884 $function = "";
2885 %constants = ();
2886 %parameterdescs = ();
2887 %parametertypes = ();
2888 @parameterlist = ();
2889 %sections = ();
2890 @sectionlist = ();
2891 $prototype = "";
2892 if ( $1 eq "" ) {
2893 $section = $section_intro;
2894 } else {
2895 $section = $1;
2896 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 elsif (/$doc_end/)
2899 {
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 $state = 0;
2911 }
2912 elsif (/$doc_content/)
2913 {
2914 if ( $1 eq "" )
2915 {
2916 $contents .= $blankline;
2917 }
2918 else
2919 {
2920 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002921 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002922 }
2923 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 }
2925 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002926 print STDERR "${file}:1: warning: no structured comments found\n";
Johannes Berge946c43a2013-11-12 15:11:12 -08002927 if (($function_only == 1) && ($show_not_found == 1)) {
2928 print STDERR " Was looking for '$_'.\n" for keys %function_table;
2929 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 if ($output_mode eq "xml") {
2931 # The template wants at least one RefEntry here; make one.
2932 print "<refentry>\n";
2933 print " <refnamediv>\n";
2934 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01002935 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 print " </refname>\n";
2937 print " <refpurpose>\n";
2938 print " Document generation inconsistency\n";
2939 print " </refpurpose>\n";
2940 print " </refnamediv>\n";
2941 print " <refsect1>\n";
2942 print " <title>\n";
2943 print " Oops\n";
2944 print " </title>\n";
2945 print " <warning>\n";
2946 print " <para>\n";
2947 print " The template for this document tried to insert\n";
2948 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01002949 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 print " but none was found.\n";
2951 print " This dummy section is inserted to allow\n";
2952 print " generation to continue.\n";
2953 print " </para>\n";
2954 print " </warning>\n";
2955 print " </refsect1>\n";
2956 print "</refentry>\n";
2957 }
2958 }
2959}
Randy Dunlap8484baa2011-01-05 16:28:43 -08002960
2961
2962$kernelversion = get_kernel_version();
2963
2964# generate a sequence of code that will splice in highlighting information
2965# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02002966for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03002967 my $pattern = $highlights[$k][0];
2968 my $result = $highlights[$k][1];
2969# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
2970 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08002971}
2972
2973# Read the file that maps relative names to absolute names for
2974# separate source and object directories and for shadow trees.
2975if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
2976 my ($relname, $absname);
2977 while(<SOURCE_MAP>) {
2978 chop();
2979 ($relname, $absname) = (split())[0..1];
2980 $relname =~ s:^/+::;
2981 $source_map{$relname} = $absname;
2982 }
2983 close(SOURCE_MAP);
2984}
2985
2986foreach (@ARGV) {
2987 chomp;
2988 process_file($_);
2989}
2990if ($verbose && $errors) {
2991 print STDERR "$errors errors\n";
2992}
2993if ($verbose && $warnings) {
2994 print STDERR "$warnings warnings\n";
2995}
2996
2997exit($errors);