blob: 301bf874cac8ccb62d33bd2b811bc4c52c173b68 [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()
Jani Nikulac9b2cfb2016-06-07 11:05:53 +030064 in any input FILE or -export-file FILE.
Jani Nikula86ae2e32016-01-21 13:05:22 +020065 -internal Only output documentation for symbols that have NOT been
66 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
Jani Nikulac9b2cfb2016-06-07 11:05:53 +030067 in any input FILE or -export-file 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.
Daniel Vetter0b0f5f22016-06-03 22:21:34 +020077 -enable-lineno Enable output of #define LINENO lines. Only works with
78 reStructuredText format.
Jani Nikula88c2b572016-06-07 11:00:52 +030079 -export-file FILE Specify an additional FILE in which to look for
80 EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with
81 -export or -internal. May be specified multiple times.
Jani Nikulafadc0b32016-05-12 16:15:36 +030082
83Other parameters:
84 -v Verbose output, more warnings and other information.
85 -h Print this help.
86
87EOF
88 print $message;
89 exit 1;
90}
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92#
93# format of comments.
94# In the following table, (...)? signifies optional structure.
95# (...)* signifies 0 or more structure elements
96# /**
97# * function_name(:)? (- short description)?
98# (* @parameterx: (description of parameter x)?)*
99# (* a blank line)?
100# * (Description:)? (Description of function)?
101# * (section header: (section description)? )*
102# (*)?*/
103#
104# So .. the trivial example would be:
105#
106# /**
107# * my_function
Randy Dunlapb9d973282009-06-09 08:50:38 -0700108# */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109#
Randy Dunlap891dcd22007-02-10 01:45:53 -0800110# If the Description: header tag is omitted, then there must be a blank line
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111# after the last parameter specification.
112# e.g.
113# /**
114# * my_function - does my stuff
115# * @my_arg: its mine damnit
116# *
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800117# * Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118# */
119#
120# or, could also use:
121# /**
122# * my_function - does my stuff
123# * @my_arg: its mine damnit
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800124# * Description: Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125# */
126# etc.
127#
Randy Dunlapb9d973282009-06-09 08:50:38 -0700128# Besides functions you can also write documentation for structs, unions,
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800129# enums and typedefs. Instead of the function name you must write the name
130# of the declaration; the struct/union/enum/typedef must always precede
131# the name. Nesting of declarations is not supported.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132# Use the argument mechanism to document members or constants.
133# e.g.
134# /**
135# * struct my_struct - short description
136# * @a: first member
137# * @b: second member
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800138# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139# * Longer description
140# */
141# struct my_struct {
142# int a;
143# int b;
Martin Waitzaeec46b2005-11-13 16:08:13 -0800144# /* private: */
145# int c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146# };
147#
148# All descriptions can be multiline, except the short function description.
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800149#
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300150# For really longs structs, you can also describe arguments inside the
151# body of the struct.
152# eg.
153# /**
154# * struct my_struct - short description
155# * @a: first member
156# * @b: second member
157# *
158# * Longer description
159# */
160# struct my_struct {
161# int a;
162# int b;
163# /**
164# * @c: This is longer description of C
165# *
166# * You can use paragraphs to describe arguments
167# * using this method.
168# */
169# int c;
170# };
171#
172# This should be use only for struct/enum members.
173#
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800174# You can also add additional sections. When documenting kernel functions you
175# should document the "Context:" of the function, e.g. whether the functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176# can be called form interrupts. Unlike other sections you can end it with an
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800177# empty line.
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100178# A non-void function should have a "Return:" section describing the return
179# value(s).
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800180# Example-sections should contain the string EXAMPLE so that they are marked
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181# appropriately in DocBook.
182#
183# Example:
184# /**
185# * user_function - function that can only be called in user context
186# * @a: some argument
187# * Context: !in_interrupt()
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800188# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189# * Some description
190# * Example:
191# * user_function(22);
192# */
193# ...
194#
195#
196# All descriptive text is further processed, scanning for the following special
197# patterns, which are highlighted appropriately.
198#
199# 'funcname()' - function
200# '$ENVVAR' - environmental variable
201# '&struct_name' - name of a structure (up to two words including 'struct')
202# '@parameter' - name of a parameter
203# '%CONST' - name of a constant.
204
Randy Dunlap8484baa2011-01-05 16:28:43 -0800205## init lots of data
206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207my $errors = 0;
208my $warnings = 0;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -0700209my $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211# match expressions used to find embedded type information
212my $type_constant = '\%([-_\w]+)';
213my $type_func = '(\w+)\(\)';
214my $type_param = '\@(\w+)';
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700215my $type_struct = '\&((struct\s*)*[_\w]+)';
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700216my $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217my $type_env = '(\$\w+)';
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300218my $type_enum_full = '\&(enum)\s*([_\w]+)';
219my $type_struct_full = '\&(struct)\s*([_\w]+)';
Jani Nikula47ae7ae2016-05-26 13:57:18 +0300220my $type_typedef_full = '\&(typedef)\s*([_\w]+)';
221my $type_union_full = '\&(union)\s*([_\w]+)';
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300222my $type_member = '\&([_\w]+)((\.|->)[_\w]+)';
223my $type_member_func = $type_member . '\(\)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225# Output conversion substitutions.
226# One for each output format
227
228# these work fairly well
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300229my @highlights_html = (
230 [$type_constant, "<i>\$1</i>"],
231 [$type_func, "<b>\$1</b>"],
232 [$type_struct_xml, "<i>\$1</i>"],
233 [$type_env, "<b><i>\$1</i></b>"],
234 [$type_param, "<tt><b>\$1</b></tt>"]
235 );
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700236my $local_lt = "\\\\\\\\lt:";
237my $local_gt = "\\\\\\\\gt:";
238my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Dan Luedtke1b40c192012-08-12 10:46:15 +0200240# html version 5
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300241my @highlights_html5 = (
242 [$type_constant, "<span class=\"const\">\$1</span>"],
243 [$type_func, "<span class=\"func\">\$1</span>"],
244 [$type_struct_xml, "<span class=\"struct\">\$1</span>"],
245 [$type_env, "<span class=\"env\">\$1</span>"],
246 [$type_param, "<span class=\"param\">\$1</span>]"]
247 );
Dan Luedtke1b40c192012-08-12 10:46:15 +0200248my $blankline_html5 = $local_lt . "br /" . $local_gt;
249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250# XML, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300251my @highlights_xml = (
252 ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
253 [$type_constant, "<constant>\$1</constant>"],
254 [$type_struct_xml, "<structname>\$1</structname>"],
255 [$type_param, "<parameter>\$1</parameter>"],
256 [$type_func, "<function>\$1</function>"],
257 [$type_env, "<envar>\$1</envar>"]
258 );
Johannes Berg5c98fc02007-10-24 15:08:48 -0700259my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261# gnome, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300262my @highlights_gnome = (
263 [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
264 [$type_func, "<function>\$1</function>"],
265 [$type_struct, "<structname>\$1</structname>"],
266 [$type_env, "<envar>\$1</envar>"],
267 [$type_param, "<parameter>\$1</parameter>" ]
268 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269my $blankline_gnome = "</para><para>\n";
270
271# these are pretty rough
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300272my @highlights_man = (
273 [$type_constant, "\$1"],
274 [$type_func, "\\\\fB\$1\\\\fP"],
275 [$type_struct, "\\\\fI\$1\\\\fP"],
276 [$type_param, "\\\\fI\$1\\\\fP"]
277 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278my $blankline_man = "";
279
280# text-mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300281my @highlights_text = (
282 [$type_constant, "\$1"],
283 [$type_func, "\$1"],
284 [$type_struct, "\$1"],
285 [$type_param, "\$1"]
286 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287my $blankline_text = "";
288
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300289# rst-mode
290my @highlights_rst = (
291 [$type_constant, "``\$1``"],
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300292 # Note: need to escape () to avoid func matching later
293 [$type_member_func, "\\:c\\:type\\:`\$1\$2\\\\(\\\\) <\$1>`"],
294 [$type_member, "\\:c\\:type\\:`\$1\$2 <\$1>`"],
Jani Nikulaa19bce62016-05-26 11:28:16 +0300295 [$type_func, "\\:c\\:func\\:`\$1()`"],
Jani Nikula62850972016-05-12 16:15:38 +0300296 [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
297 [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
Jani Nikula47ae7ae2016-05-26 13:57:18 +0300298 [$type_typedef_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
299 [$type_union_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
Jani Nikulaa7291e72016-05-26 13:57:06 +0300300 # in rst this can refer to any type
301 [$type_struct, "\\:c\\:type\\:`\$1`"],
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300302 [$type_param, "**\$1**"]
303 );
304my $blankline_rst = "\n";
305
Johannes Bergeda603f2010-09-11 15:55:22 -0700306# list mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300307my @highlights_list = (
308 [$type_constant, "\$1"],
309 [$type_func, "\$1"],
310 [$type_struct, "\$1"],
311 [$type_param, "\$1"]
312 );
Johannes Bergeda603f2010-09-11 15:55:22 -0700313my $blankline_list = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315# read arguments
Randy Dunlapb9d973282009-06-09 08:50:38 -0700316if ($#ARGV == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 usage();
318}
319
Randy Dunlap8484baa2011-01-05 16:28:43 -0800320my $kernelversion;
321my $dohighlight = "";
322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323my $verbose = 0;
324my $output_mode = "man";
Daniel Santose314ba32012-10-04 17:15:08 -0700325my $output_preformatted = 0;
Johannes Berg4b445952007-10-24 15:08:48 -0700326my $no_doc_sections = 0;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200327my $enable_lineno = 0;
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300328my @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329my $blankline = $blankline_man;
330my $modulename = "Kernel API";
Jani Nikulab6c3f452016-05-29 22:19:35 +0300331
332use constant {
333 OUTPUT_ALL => 0, # output all symbols and doc sections
334 OUTPUT_INCLUDE => 1, # output only specified symbols
335 OUTPUT_EXCLUDE => 2, # output everything except specified symbols
336 OUTPUT_EXPORTED => 3, # output exported symbols
337 OUTPUT_INTERNAL => 4, # output non-exported symbols
338};
339my $output_selection = OUTPUT_ALL;
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100340my $show_not_found = 0;
341
Jani Nikula88c2b572016-06-07 11:00:52 +0300342my @export_file_list;
343
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100344my @build_time;
345if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
346 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
347 @build_time = gmtime($seconds);
348} else {
349 @build_time = localtime;
350}
351
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800352my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
353 'July', 'August', 'September', 'October',
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100354 'November', 'December')[$build_time[4]] .
355 " " . ($build_time[5]+1900);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Randy Dunlap8484baa2011-01-05 16:28:43 -0800357# Essentially these are globals.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700358# They probably want to be tidied up, made more localised or something.
359# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360# could cause "use of undefined value" or other bugs.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700361my ($function, %function_table, %parametertypes, $declaration_purpose);
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200362my $declaration_start_line;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700363my ($type, $declaration_name, $return_type);
Ilya Dryomov1c32fd02010-02-26 13:06:03 -0800364my ($newsection, $newcontents, $prototype, $brcount, %source_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700366if (defined($ENV{'KBUILD_VERBOSE'})) {
367 $verbose = "$ENV{'KBUILD_VERBOSE'}";
368}
369
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800370# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
372# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
373# We keep track of number of generated entries and generate a dummy
374# if needs be to ensure the expanded template can be postprocessed
375# into html.
376my $section_counter = 0;
377
378my $lineprefix="";
379
Jani Nikula48af6062016-05-26 14:56:05 +0300380# Parser states
381use constant {
382 STATE_NORMAL => 0, # normal code
383 STATE_NAME => 1, # looking for function name
384 STATE_FIELD => 2, # scanning field start
385 STATE_PROTO => 3, # scanning prototype
386 STATE_DOCBLOCK => 4, # documentation block
387 STATE_INLINE => 5, # gathering documentation outside main block
388};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700390my $in_doc_sect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Jani Nikula48af6062016-05-26 14:56:05 +0300392# Inline documentation state
393use constant {
394 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
395 STATE_INLINE_NAME => 1, # looking for member name (@foo:)
396 STATE_INLINE_TEXT => 2, # looking for member documentation
397 STATE_INLINE_END => 3, # done
398 STATE_INLINE_ERROR => 4, # error - Comment without header was found.
399 # Spit a warning as it's not
400 # proper kernel-doc and ignore the rest.
401};
402my $inline_doc_state;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404#declaration types: can be
405# 'function', 'struct', 'union', 'enum', 'typedef'
406my $decl_type;
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
409my $doc_end = '\*/';
410my $doc_com = '\s*\*\s*';
Daniel Santos12ae6772012-10-04 17:15:10 -0700411my $doc_com_body = '\s*\* ?';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700412my $doc_decl = $doc_com . '(\w+)';
Jani Nikulaf624ade2016-05-29 11:35:28 +0300413# @params and a strictly limited set of supported section names
Jonathan Corbet8569de62016-06-09 13:35:05 -0600414my $doc_sect = $doc_com .
415 '\s*(\@\w+|description|context|returns?|notes?|examples?)\s*:(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700416my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700417my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Jani Nikula48af6062016-05-26 14:56:05 +0300418my $doc_inline_start = '^\s*/\*\*\s*$';
419my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
420my $doc_inline_end = '^\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200421my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423my %parameterdescs;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200424my %parameterdesc_start_lines;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425my @parameterlist;
426my %sections;
427my @sectionlist;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200428my %section_start_lines;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800429my $sectcheck;
430my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432my $contents = "";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200433my $new_start_line = 0;
Jani Nikulaf624ade2016-05-29 11:35:28 +0300434
435# the canonical section names. see also $doc_sect above.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436my $section_default = "Description"; # default section
437my $section_intro = "Introduction";
438my $section = $section_default;
439my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100440my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
442my $undescribed = "-- undescribed --";
443
444reset_state();
445
446while ($ARGV[0] =~ m/^-(.*)/) {
447 my $cmd = shift @ARGV;
448 if ($cmd eq "-html") {
449 $output_mode = "html";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300450 @highlights = @highlights_html;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200452 } elsif ($cmd eq "-html5") {
453 $output_mode = "html5";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300454 @highlights = @highlights_html5;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200455 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 } elsif ($cmd eq "-man") {
457 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300458 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 $blankline = $blankline_man;
460 } elsif ($cmd eq "-text") {
461 $output_mode = "text";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300462 @highlights = @highlights_text;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 $blankline = $blankline_text;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300464 } elsif ($cmd eq "-rst") {
465 $output_mode = "rst";
466 @highlights = @highlights_rst;
467 $blankline = $blankline_rst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 } elsif ($cmd eq "-docbook") {
469 $output_mode = "xml";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300470 @highlights = @highlights_xml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700472 } elsif ($cmd eq "-list") {
473 $output_mode = "list";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300474 @highlights = @highlights_list;
Johannes Bergeda603f2010-09-11 15:55:22 -0700475 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 } elsif ($cmd eq "-gnome") {
477 $output_mode = "gnome";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300478 @highlights = @highlights_gnome;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 $blankline = $blankline_gnome;
480 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
481 $modulename = shift @ARGV;
482 } elsif ($cmd eq "-function") { # to only output specific functions
Jani Nikulab6c3f452016-05-29 22:19:35 +0300483 $output_selection = OUTPUT_INCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 $function = shift @ARGV;
485 $function_table{$function} = 1;
Jani Nikulab6c3f452016-05-29 22:19:35 +0300486 } elsif ($cmd eq "-nofunction") { # output all except specific functions
487 $output_selection = OUTPUT_EXCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 $function = shift @ARGV;
489 $function_table{$function} = 1;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200490 } elsif ($cmd eq "-export") { # only exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300491 $output_selection = OUTPUT_EXPORTED;
Jani Nikulada9726e2016-06-07 10:29:59 +0300492 %function_table = ();
Jani Nikula86ae2e32016-01-21 13:05:22 +0200493 } elsif ($cmd eq "-internal") { # only non-exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300494 $output_selection = OUTPUT_INTERNAL;
Jani Nikulada9726e2016-06-07 10:29:59 +0300495 %function_table = ();
Jani Nikula88c2b572016-06-07 11:00:52 +0300496 } elsif ($cmd eq "-export-file") {
497 my $file = shift @ARGV;
498 push(@export_file_list, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499 } elsif ($cmd eq "-v") {
500 $verbose = 1;
501 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
502 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700503 } elsif ($cmd eq '-no-doc-sections') {
504 $no_doc_sections = 1;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200505 } elsif ($cmd eq '-enable-lineno') {
506 $enable_lineno = 1;
Johannes Berge946c43a2013-11-12 15:11:12 -0800507 } elsif ($cmd eq '-show-not-found') {
508 $show_not_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 }
510}
511
Randy Dunlap8484baa2011-01-05 16:28:43 -0800512# continue execution near EOF;
513
Borislav Petkov53f049f2007-05-08 00:30:54 -0700514# get kernel version from env
515sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700516 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700517
518 if (defined($ENV{'KERNELVERSION'})) {
519 $version = $ENV{'KERNELVERSION'};
520 }
521 return $version;
522}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200524#
525sub print_lineno {
526 my $lineno = shift;
527 if ($enable_lineno && defined($lineno)) {
528 print "#define LINENO " . $lineno . "\n";
529 }
530}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531##
532# dumps section contents to arrays/hashes intended for that purpose.
533#
534sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700535 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 my $name = shift;
537 my $contents = join "\n", @_;
538
Jani Nikula13901ef2016-05-26 08:57:29 +0300539 if ($name =~ m/$type_param/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 $name = $1;
541 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800542 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200543 $parameterdesc_start_lines{$name} = $new_start_line;
544 $new_start_line = 0;
Randy Dunlapced69092008-12-01 13:14:03 -0800545 } elsif ($name eq "@\.\.\.") {
Randy Dunlapced69092008-12-01 13:14:03 -0800546 $name = "...";
547 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800548 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200549 $parameterdesc_start_lines{$name} = $new_start_line;
550 $new_start_line = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 } else {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700552 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Jani Nikula95b6be92016-06-10 11:14:05 +0300553 # Only warn on user specified duplicate section names.
554 if ($name ne $section_default) {
555 print STDERR "${file}:$.: warning: duplicate section name '$name'\n";
556 ++$warnings;
557 }
Jani Nikula32217762016-05-29 09:40:44 +0300558 $sections{$name} .= $contents;
559 } else {
560 $sections{$name} = $contents;
561 push @sectionlist, $name;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200562 $section_start_lines{$name} = $new_start_line;
563 $new_start_line = 0;
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700564 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 }
566}
567
568##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700569# dump DOC: section after checking that it should go out
570#
571sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700572 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700573 my $name = shift;
574 my $contents = join "\n", @_;
575
Johannes Berg4b445952007-10-24 15:08:48 -0700576 if ($no_doc_sections) {
577 return;
578 }
579
Jani Nikulab6c3f452016-05-29 22:19:35 +0300580 if (($output_selection == OUTPUT_ALL) ||
581 ($output_selection == OUTPUT_INCLUDE &&
582 defined($function_table{$name})) ||
583 ($output_selection == OUTPUT_EXCLUDE &&
584 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700585 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700586 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700587 output_blockhead({'sectionlist' => \@sectionlist,
588 'sections' => \%sections,
589 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300590 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700591 }
592}
593
594##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595# output function
596#
597# parameterdescs, a hash.
598# function => "function name"
599# parameterlist => @list of parameters
600# parameterdescs => %parameter descriptions
601# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800602# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800603#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605sub output_highlight {
606 my $contents = join "\n",@_;
607 my $line;
608
609# DEBUG
610# if (!defined $contents) {
611# use Carp;
612# confess "output_highlight got called with no args?\n";
613# }
614
Dan Luedtke1b40c192012-08-12 10:46:15 +0200615 if ($output_mode eq "html" || $output_mode eq "html5" ||
616 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700617 $contents = local_unescape($contents);
618 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800619 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700620 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700621# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 eval $dohighlight;
623 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700624# print STDERR "contents af:$contents\n";
625
Dan Luedtke1b40c192012-08-12 10:46:15 +0200626# strip whitespaces when generating html5
627 if ($output_mode eq "html5") {
628 $contents =~ s/^\s+//;
629 $contents =~ s/\s+$//;
630 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700632 if (! $output_preformatted) {
633 $line =~ s/^\s*//;
634 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700635 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700636 if (! $output_preformatted) {
637 print $lineprefix, local_unescape($blankline);
638 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700640 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700641 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
642 print "\\&$line";
643 } else {
644 print $lineprefix, $line;
645 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 }
647 print "\n";
648 }
649}
650
Dan Luedtke1b40c192012-08-12 10:46:15 +0200651# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652sub output_section_html(%) {
653 my %args = %{$_[0]};
654 my $section;
655
656 foreach $section (@{$args{'sectionlist'}}) {
657 print "<h3>$section</h3>\n";
658 print "<blockquote>\n";
659 output_highlight($args{'sections'}{$section});
660 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662}
663
664# output enum in html
665sub output_enum_html(%) {
666 my %args = %{$_[0]};
667 my ($parameter);
668 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700669 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670
Randy Dunlapb9d973282009-06-09 08:50:38 -0700671 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672 $count = 0;
673 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700674 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 if ($count != $#{$args{'parameterlist'}}) {
676 $count++;
677 print ",\n";
678 }
679 print "<br>";
680 }
681 print "};<br>\n";
682
683 print "<h3>Constants</h3>\n";
684 print "<dl>\n";
685 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700686 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 print "<dd>";
688 output_highlight($args{'parameterdescs'}{$parameter});
689 }
690 print "</dl>\n";
691 output_section_html(@_);
692 print "<hr>\n";
693}
694
Randy Dunlapd28bee02006-02-01 03:06:57 -0800695# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696sub output_typedef_html(%) {
697 my %args = %{$_[0]};
698 my ($parameter);
699 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700700 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Randy Dunlapb9d973282009-06-09 08:50:38 -0700702 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 output_section_html(@_);
704 print "<hr>\n";
705}
706
707# output struct in html
708sub output_struct_html(%) {
709 my %args = %{$_[0]};
710 my ($parameter);
711
Randy Dunlapb9d973282009-06-09 08:50:38 -0700712 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
713 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 foreach $parameter (@{$args{'parameterlist'}}) {
715 if ($parameter =~ /^#/) {
716 print "$parameter<br>\n";
717 next;
718 }
719 my $parameter_name = $parameter;
720 $parameter_name =~ s/\[.*//;
721
Randy Dunlap3c308792007-05-08 00:24:39 -0700722 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 $type = $args{'parametertypes'}{$parameter};
724 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
725 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700726 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700728 # bitfield
729 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700731 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 }
733 }
734 print "};<br>\n";
735
736 print "<h3>Members</h3>\n";
737 print "<dl>\n";
738 foreach $parameter (@{$args{'parameterlist'}}) {
739 ($parameter =~ /^#/) && next;
740
741 my $parameter_name = $parameter;
742 $parameter_name =~ s/\[.*//;
743
Randy Dunlap3c308792007-05-08 00:24:39 -0700744 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700745 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 print "<dd>";
747 output_highlight($args{'parameterdescs'}{$parameter_name});
748 }
749 print "</dl>\n";
750 output_section_html(@_);
751 print "<hr>\n";
752}
753
754# output function in html
755sub output_function_html(%) {
756 my %args = %{$_[0]};
757 my ($parameter, $section);
758 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
Randy Dunlapb9d973282009-06-09 08:50:38 -0700760 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
761 print "<i>" . $args{'functiontype'} . "</i>\n";
762 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 print "(";
764 $count = 0;
765 foreach $parameter (@{$args{'parameterlist'}}) {
766 $type = $args{'parametertypes'}{$parameter};
767 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
768 # pointer-to-function
769 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
770 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700771 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 }
773 if ($count != $#{$args{'parameterlist'}}) {
774 $count++;
775 print ",\n";
776 }
777 }
778 print ")\n";
779
780 print "<h3>Arguments</h3>\n";
781 print "<dl>\n";
782 foreach $parameter (@{$args{'parameterlist'}}) {
783 my $parameter_name = $parameter;
784 $parameter_name =~ s/\[.*//;
785
Randy Dunlap3c308792007-05-08 00:24:39 -0700786 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700787 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 print "<dd>";
789 output_highlight($args{'parameterdescs'}{$parameter_name});
790 }
791 print "</dl>\n";
792 output_section_html(@_);
793 print "<hr>\n";
794}
795
Johannes Bergb112e0f2007-10-24 15:08:48 -0700796# output DOC: block header in html
797sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 my %args = %{$_[0]};
799 my ($parameter, $section);
800 my $count;
801
802 foreach $section (@{$args{'sectionlist'}}) {
803 print "<h3>$section</h3>\n";
804 print "<ul>\n";
805 output_highlight($args{'sections'}{$section});
806 print "</ul>\n";
807 }
808 print "<hr>\n";
809}
810
Dan Luedtke1b40c192012-08-12 10:46:15 +0200811# output sections in html5
812sub output_section_html5(%) {
813 my %args = %{$_[0]};
814 my $section;
815
816 foreach $section (@{$args{'sectionlist'}}) {
817 print "<section>\n";
818 print "<h1>$section</h1>\n";
819 print "<p>\n";
820 output_highlight($args{'sections'}{$section});
821 print "</p>\n";
822 print "</section>\n";
823 }
824}
825
826# output enum in html5
827sub output_enum_html5(%) {
828 my %args = %{$_[0]};
829 my ($parameter);
830 my $count;
831 my $html5id;
832
833 $html5id = $args{'enum'};
834 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
835 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
836 print "<h1>enum " . $args{'enum'} . "</h1>\n";
837 print "<ol class=\"code\">\n";
838 print "<li>";
839 print "<span class=\"keyword\">enum</span> ";
840 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
841 print "</li>\n";
842 $count = 0;
843 foreach $parameter (@{$args{'parameterlist'}}) {
844 print "<li class=\"indent\">";
845 print "<span class=\"param\">" . $parameter . "</span>";
846 if ($count != $#{$args{'parameterlist'}}) {
847 $count++;
848 print ",";
849 }
850 print "</li>\n";
851 }
852 print "<li>};</li>\n";
853 print "</ol>\n";
854
855 print "<section>\n";
856 print "<h1>Constants</h1>\n";
857 print "<dl>\n";
858 foreach $parameter (@{$args{'parameterlist'}}) {
859 print "<dt>" . $parameter . "</dt>\n";
860 print "<dd>";
861 output_highlight($args{'parameterdescs'}{$parameter});
862 print "</dd>\n";
863 }
864 print "</dl>\n";
865 print "</section>\n";
866 output_section_html5(@_);
867 print "</article>\n";
868}
869
870# output typedef in html5
871sub output_typedef_html5(%) {
872 my %args = %{$_[0]};
873 my ($parameter);
874 my $count;
875 my $html5id;
876
877 $html5id = $args{'typedef'};
878 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
879 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
880 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
881
882 print "<ol class=\"code\">\n";
883 print "<li>";
884 print "<span class=\"keyword\">typedef</span> ";
885 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
886 print "</li>\n";
887 print "</ol>\n";
888 output_section_html5(@_);
889 print "</article>\n";
890}
891
892# output struct in html5
893sub output_struct_html5(%) {
894 my %args = %{$_[0]};
895 my ($parameter);
896 my $html5id;
897
898 $html5id = $args{'struct'};
899 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
900 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
901 print "<hgroup>\n";
902 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
903 print "<h2>". $args{'purpose'} . "</h2>\n";
904 print "</hgroup>\n";
905 print "<ol class=\"code\">\n";
906 print "<li>";
907 print "<span class=\"type\">" . $args{'type'} . "</span> ";
908 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
909 print "</li>\n";
910 foreach $parameter (@{$args{'parameterlist'}}) {
911 print "<li class=\"indent\">";
912 if ($parameter =~ /^#/) {
913 print "<span class=\"param\">" . $parameter ."</span>\n";
914 print "</li>\n";
915 next;
916 }
917 my $parameter_name = $parameter;
918 $parameter_name =~ s/\[.*//;
919
920 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
921 $type = $args{'parametertypes'}{$parameter};
922 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
923 # pointer-to-function
924 print "<span class=\"type\">$1</span> ";
925 print "<span class=\"param\">$parameter</span>";
926 print "<span class=\"type\">)</span> ";
927 print "(<span class=\"args\">$2</span>);";
928 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
929 # bitfield
930 print "<span class=\"type\">$1</span> ";
931 print "<span class=\"param\">$parameter</span>";
932 print "<span class=\"bits\">$2</span>;";
933 } else {
934 print "<span class=\"type\">$type</span> ";
935 print "<span class=\"param\">$parameter</span>;";
936 }
937 print "</li>\n";
938 }
939 print "<li>};</li>\n";
940 print "</ol>\n";
941
942 print "<section>\n";
943 print "<h1>Members</h1>\n";
944 print "<dl>\n";
945 foreach $parameter (@{$args{'parameterlist'}}) {
946 ($parameter =~ /^#/) && next;
947
948 my $parameter_name = $parameter;
949 $parameter_name =~ s/\[.*//;
950
951 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
952 print "<dt>" . $parameter . "</dt>\n";
953 print "<dd>";
954 output_highlight($args{'parameterdescs'}{$parameter_name});
955 print "</dd>\n";
956 }
957 print "</dl>\n";
958 print "</section>\n";
959 output_section_html5(@_);
960 print "</article>\n";
961}
962
963# output function in html5
964sub output_function_html5(%) {
965 my %args = %{$_[0]};
966 my ($parameter, $section);
967 my $count;
968 my $html5id;
969
970 $html5id = $args{'function'};
971 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
972 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
973 print "<hgroup>\n";
974 print "<h1>" . $args{'function'} . "</h1>";
975 print "<h2>" . $args{'purpose'} . "</h2>\n";
976 print "</hgroup>\n";
977 print "<ol class=\"code\">\n";
978 print "<li>";
979 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
980 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
981 print "</li>";
982 $count = 0;
983 foreach $parameter (@{$args{'parameterlist'}}) {
984 print "<li class=\"indent\">";
985 $type = $args{'parametertypes'}{$parameter};
986 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
987 # pointer-to-function
988 print "<span class=\"type\">$1</span> ";
989 print "<span class=\"param\">$parameter</span>";
990 print "<span class=\"type\">)</span> ";
991 print "(<span class=\"args\">$2</span>)";
992 } else {
993 print "<span class=\"type\">$type</span> ";
994 print "<span class=\"param\">$parameter</span>";
995 }
996 if ($count != $#{$args{'parameterlist'}}) {
997 $count++;
998 print ",";
999 }
1000 print "</li>\n";
1001 }
1002 print "<li>)</li>\n";
1003 print "</ol>\n";
1004
1005 print "<section>\n";
1006 print "<h1>Arguments</h1>\n";
1007 print "<p>\n";
1008 print "<dl>\n";
1009 foreach $parameter (@{$args{'parameterlist'}}) {
1010 my $parameter_name = $parameter;
1011 $parameter_name =~ s/\[.*//;
1012
1013 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1014 print "<dt>" . $parameter . "</dt>\n";
1015 print "<dd>";
1016 output_highlight($args{'parameterdescs'}{$parameter_name});
1017 print "</dd>\n";
1018 }
1019 print "</dl>\n";
1020 print "</section>\n";
1021 output_section_html5(@_);
1022 print "</article>\n";
1023}
1024
1025# output DOC: block header in html5
1026sub output_blockhead_html5(%) {
1027 my %args = %{$_[0]};
1028 my ($parameter, $section);
1029 my $count;
1030 my $html5id;
1031
1032 foreach $section (@{$args{'sectionlist'}}) {
1033 $html5id = $section;
1034 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1035 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1036 print "<h1>$section</h1>\n";
1037 print "<p>\n";
1038 output_highlight($args{'sections'}{$section});
1039 print "</p>\n";
1040 }
1041 print "</article>\n";
1042}
1043
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044sub output_section_xml(%) {
1045 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001046 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 # print out each section
1048 $lineprefix=" ";
1049 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001050 print "<refsect1>\n";
1051 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001053 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001054 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001055 } else {
1056 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 }
1058 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001059 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001061 print "</programlisting></informalexample>\n";
1062 } else {
1063 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001065 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 }
1067}
1068
1069# output function in XML DocBook
1070sub output_function_xml(%) {
1071 my %args = %{$_[0]};
1072 my ($parameter, $section);
1073 my $count;
1074 my $id;
1075
Randy Dunlapb9d973282009-06-09 08:50:38 -07001076 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 $id =~ s/[^A-Za-z0-9]/-/g;
1078
Pavel Pisa5449bc92007-02-10 01:45:37 -08001079 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001080 print "<refentryinfo>\n";
1081 print " <title>LINUX</title>\n";
1082 print " <productname>Kernel Hackers Manual</productname>\n";
1083 print " <date>$man_date</date>\n";
1084 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001086 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001087 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001088 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 print "</refmeta>\n";
1090 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001091 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 print " <refpurpose>\n";
1093 print " ";
1094 output_highlight ($args{'purpose'});
1095 print " </refpurpose>\n";
1096 print "</refnamediv>\n";
1097
1098 print "<refsynopsisdiv>\n";
1099 print " <title>Synopsis</title>\n";
1100 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001101 print " <funcdef>" . $args{'functiontype'} . " ";
1102 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103
1104 $count = 0;
1105 if ($#{$args{'parameterlist'}} >= 0) {
1106 foreach $parameter (@{$args{'parameterlist'}}) {
1107 $type = $args{'parametertypes'}{$parameter};
1108 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1109 # pointer-to-function
1110 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1111 print " <funcparams>$2</funcparams></paramdef>\n";
1112 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001113 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 print " <parameter>$parameter</parameter></paramdef>\n";
1115 }
1116 }
1117 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001118 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 }
1120 print " </funcprototype></funcsynopsis>\n";
1121 print "</refsynopsisdiv>\n";
1122
1123 # print parameters
1124 print "<refsect1>\n <title>Arguments</title>\n";
1125 if ($#{$args{'parameterlist'}} >= 0) {
1126 print " <variablelist>\n";
1127 foreach $parameter (@{$args{'parameterlist'}}) {
1128 my $parameter_name = $parameter;
1129 $parameter_name =~ s/\[.*//;
1130
1131 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1132 print " <listitem>\n <para>\n";
1133 $lineprefix=" ";
1134 output_highlight($args{'parameterdescs'}{$parameter_name});
1135 print " </para>\n </listitem>\n </varlistentry>\n";
1136 }
1137 print " </variablelist>\n";
1138 } else {
1139 print " <para>\n None\n </para>\n";
1140 }
1141 print "</refsect1>\n";
1142
1143 output_section_xml(@_);
1144 print "</refentry>\n\n";
1145}
1146
1147# output struct in XML DocBook
1148sub output_struct_xml(%) {
1149 my %args = %{$_[0]};
1150 my ($parameter, $section);
1151 my $id;
1152
Randy Dunlapb9d973282009-06-09 08:50:38 -07001153 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 $id =~ s/[^A-Za-z0-9]/-/g;
1155
Pavel Pisa5449bc92007-02-10 01:45:37 -08001156 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001157 print "<refentryinfo>\n";
1158 print " <title>LINUX</title>\n";
1159 print " <productname>Kernel Hackers Manual</productname>\n";
1160 print " <date>$man_date</date>\n";
1161 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001163 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001164 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001165 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 print "</refmeta>\n";
1167 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001168 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 print " <refpurpose>\n";
1170 print " ";
1171 output_highlight ($args{'purpose'});
1172 print " </refpurpose>\n";
1173 print "</refnamediv>\n";
1174
1175 print "<refsynopsisdiv>\n";
1176 print " <title>Synopsis</title>\n";
1177 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001178 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179 foreach $parameter (@{$args{'parameterlist'}}) {
1180 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001181 my $prm = $parameter;
1182 # convert data read & converted thru xml_escape() into &xyz; format:
1183 # This allows us to have #define macros interspersed in a struct.
1184 $prm =~ s/\\\\\\/\&/g;
1185 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 next;
1187 }
1188
1189 my $parameter_name = $parameter;
1190 $parameter_name =~ s/\[.*//;
1191
1192 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001193 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 $type = $args{'parametertypes'}{$parameter};
1195 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1196 # pointer-to-function
1197 print " $1 $parameter) ($2);\n";
1198 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001199 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 print " $1 $parameter$2;\n";
1201 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001202 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 }
1204 }
1205 print "};";
1206 print " </programlisting>\n";
1207 print "</refsynopsisdiv>\n";
1208
1209 print " <refsect1>\n";
1210 print " <title>Members</title>\n";
1211
Randy Dunlap39f00c02008-09-22 13:57:44 -07001212 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 print " <variablelist>\n";
1214 foreach $parameter (@{$args{'parameterlist'}}) {
1215 ($parameter =~ /^#/) && next;
1216
1217 my $parameter_name = $parameter;
1218 $parameter_name =~ s/\[.*//;
1219
1220 defined($args{'parameterdescs'}{$parameter_name}) || next;
1221 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1222 print " <varlistentry>";
1223 print " <term>$parameter</term>\n";
1224 print " <listitem><para>\n";
1225 output_highlight($args{'parameterdescs'}{$parameter_name});
1226 print " </para></listitem>\n";
1227 print " </varlistentry>\n";
1228 }
1229 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001230 } else {
1231 print " <para>\n None\n </para>\n";
1232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 print " </refsect1>\n";
1234
1235 output_section_xml(@_);
1236
1237 print "</refentry>\n\n";
1238}
1239
1240# output enum in XML DocBook
1241sub output_enum_xml(%) {
1242 my %args = %{$_[0]};
1243 my ($parameter, $section);
1244 my $count;
1245 my $id;
1246
Randy Dunlapb9d973282009-06-09 08:50:38 -07001247 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 $id =~ s/[^A-Za-z0-9]/-/g;
1249
Pavel Pisa5449bc92007-02-10 01:45:37 -08001250 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001251 print "<refentryinfo>\n";
1252 print " <title>LINUX</title>\n";
1253 print " <productname>Kernel Hackers Manual</productname>\n";
1254 print " <date>$man_date</date>\n";
1255 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001257 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001258 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001259 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 print "</refmeta>\n";
1261 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001262 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 print " <refpurpose>\n";
1264 print " ";
1265 output_highlight ($args{'purpose'});
1266 print " </refpurpose>\n";
1267 print "</refnamediv>\n";
1268
1269 print "<refsynopsisdiv>\n";
1270 print " <title>Synopsis</title>\n";
1271 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001272 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 $count = 0;
1274 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001275 print " $parameter";
1276 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 $count++;
1278 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001279 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 print "\n";
1281 }
1282 print "};";
1283 print " </programlisting>\n";
1284 print "</refsynopsisdiv>\n";
1285
1286 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001287 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288 print " <variablelist>\n";
1289 foreach $parameter (@{$args{'parameterlist'}}) {
1290 my $parameter_name = $parameter;
1291 $parameter_name =~ s/\[.*//;
1292
1293 print " <varlistentry>";
1294 print " <term>$parameter</term>\n";
1295 print " <listitem><para>\n";
1296 output_highlight($args{'parameterdescs'}{$parameter_name});
1297 print " </para></listitem>\n";
1298 print " </varlistentry>\n";
1299 }
1300 print " </variablelist>\n";
1301 print "</refsect1>\n";
1302
1303 output_section_xml(@_);
1304
1305 print "</refentry>\n\n";
1306}
1307
1308# output typedef in XML DocBook
1309sub output_typedef_xml(%) {
1310 my %args = %{$_[0]};
1311 my ($parameter, $section);
1312 my $id;
1313
Randy Dunlapb9d973282009-06-09 08:50:38 -07001314 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 $id =~ s/[^A-Za-z0-9]/-/g;
1316
Pavel Pisa5449bc92007-02-10 01:45:37 -08001317 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001318 print "<refentryinfo>\n";
1319 print " <title>LINUX</title>\n";
1320 print " <productname>Kernel Hackers Manual</productname>\n";
1321 print " <date>$man_date</date>\n";
1322 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001324 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001325 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 print "</refmeta>\n";
1327 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001328 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 print " <refpurpose>\n";
1330 print " ";
1331 output_highlight ($args{'purpose'});
1332 print " </refpurpose>\n";
1333 print "</refnamediv>\n";
1334
1335 print "<refsynopsisdiv>\n";
1336 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001337 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 print "</refsynopsisdiv>\n";
1339
1340 output_section_xml(@_);
1341
1342 print "</refentry>\n\n";
1343}
1344
1345# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001346sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 my %args = %{$_[0]};
1348 my ($parameter, $section);
1349 my $count;
1350
1351 my $id = $args{'module'};
1352 $id =~ s/[^A-Za-z0-9]/-/g;
1353
1354 # print out each section
1355 $lineprefix=" ";
1356 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001357 if (!$args{'content-only'}) {
1358 print "<refsect1>\n <title>$section</title>\n";
1359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 if ($section =~ m/EXAMPLE/i) {
1361 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001362 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001363 } else {
1364 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 }
1366 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001367 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 if ($section =~ m/EXAMPLE/i) {
1369 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001370 } else {
1371 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001373 if (!$args{'content-only'}) {
1374 print "\n</refsect1>\n";
1375 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 }
1377
1378 print "\n\n";
1379}
1380
1381# output in XML DocBook
1382sub output_function_gnome {
1383 my %args = %{$_[0]};
1384 my ($parameter, $section);
1385 my $count;
1386 my $id;
1387
Randy Dunlapb9d973282009-06-09 08:50:38 -07001388 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 $id =~ s/[^A-Za-z0-9]/-/g;
1390
1391 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001392 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
1394 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001395 print " <funcdef>" . $args{'functiontype'} . " ";
1396 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 print "</function></funcdef>\n";
1398
1399 $count = 0;
1400 if ($#{$args{'parameterlist'}} >= 0) {
1401 foreach $parameter (@{$args{'parameterlist'}}) {
1402 $type = $args{'parametertypes'}{$parameter};
1403 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1404 # pointer-to-function
1405 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1406 print " <funcparams>$2</funcparams></paramdef>\n";
1407 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001408 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 print " <parameter>$parameter</parameter></paramdef>\n";
1410 }
1411 }
1412 } else {
1413 print " <void>\n";
1414 }
1415 print " </funcsynopsis>\n";
1416 if ($#{$args{'parameterlist'}} >= 0) {
1417 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1418 print "<tgroup cols=\"2\">\n";
1419 print "<colspec colwidth=\"2*\">\n";
1420 print "<colspec colwidth=\"8*\">\n";
1421 print "<tbody>\n";
1422 foreach $parameter (@{$args{'parameterlist'}}) {
1423 my $parameter_name = $parameter;
1424 $parameter_name =~ s/\[.*//;
1425
1426 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1427 print " <entry>\n";
1428 $lineprefix=" ";
1429 output_highlight($args{'parameterdescs'}{$parameter_name});
1430 print " </entry></row>\n";
1431 }
1432 print " </tbody></tgroup></informaltable>\n";
1433 } else {
1434 print " <para>\n None\n </para>\n";
1435 }
1436
1437 # print out each section
1438 $lineprefix=" ";
1439 foreach $section (@{$args{'sectionlist'}}) {
1440 print "<simplesect>\n <title>$section</title>\n";
1441 if ($section =~ m/EXAMPLE/i) {
1442 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001443 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 } else {
1445 }
1446 print "<para>\n";
1447 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001448 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449 print "</para>\n";
1450 if ($section =~ m/EXAMPLE/i) {
1451 print "</programlisting></example>\n";
1452 } else {
1453 }
1454 print " </simplesect>\n";
1455 }
1456
1457 print "</sect2>\n\n";
1458}
1459
1460##
1461# output function in man
1462sub output_function_man(%) {
1463 my %args = %{$_[0]};
1464 my ($parameter, $section);
1465 my $count;
1466
1467 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1468
1469 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001470 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
1472 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001473 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001474 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001475 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001476 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 $count = 0;
1479 my $parenth = "(";
1480 my $post = ",";
1481 foreach my $parameter (@{$args{'parameterlist'}}) {
1482 if ($count == $#{$args{'parameterlist'}}) {
1483 $post = ");";
1484 }
1485 $type = $args{'parametertypes'}{$parameter};
1486 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1487 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001488 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 } else {
1490 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001491 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 }
1493 $count++;
1494 $parenth = "";
1495 }
1496
1497 print ".SH ARGUMENTS\n";
1498 foreach $parameter (@{$args{'parameterlist'}}) {
1499 my $parameter_name = $parameter;
1500 $parameter_name =~ s/\[.*//;
1501
Randy Dunlapb9d973282009-06-09 08:50:38 -07001502 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 output_highlight($args{'parameterdescs'}{$parameter_name});
1504 }
1505 foreach $section (@{$args{'sectionlist'}}) {
1506 print ".SH \"", uc $section, "\"\n";
1507 output_highlight($args{'sections'}{$section});
1508 }
1509}
1510
1511##
1512# output enum in man
1513sub output_enum_man(%) {
1514 my %args = %{$_[0]};
1515 my ($parameter, $section);
1516 my $count;
1517
1518 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1519
1520 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001521 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
1523 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001524 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 $count = 0;
1526 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001527 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 if ($count == $#{$args{'parameterlist'}}) {
1529 print "\n};\n";
1530 last;
1531 }
1532 else {
1533 print ", \n.br\n";
1534 }
1535 $count++;
1536 }
1537
1538 print ".SH Constants\n";
1539 foreach $parameter (@{$args{'parameterlist'}}) {
1540 my $parameter_name = $parameter;
1541 $parameter_name =~ s/\[.*//;
1542
Randy Dunlapb9d973282009-06-09 08:50:38 -07001543 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 output_highlight($args{'parameterdescs'}{$parameter_name});
1545 }
1546 foreach $section (@{$args{'sectionlist'}}) {
1547 print ".SH \"$section\"\n";
1548 output_highlight($args{'sections'}{$section});
1549 }
1550}
1551
1552##
1553# output struct in man
1554sub output_struct_man(%) {
1555 my %args = %{$_[0]};
1556 my ($parameter, $section);
1557
Randy Dunlapb9d973282009-06-09 08:50:38 -07001558 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
1560 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001561 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
1563 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001564 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
1566 foreach my $parameter (@{$args{'parameterlist'}}) {
1567 if ($parameter =~ /^#/) {
1568 print ".BI \"$parameter\"\n.br\n";
1569 next;
1570 }
1571 my $parameter_name = $parameter;
1572 $parameter_name =~ s/\[.*//;
1573
Randy Dunlap3c308792007-05-08 00:24:39 -07001574 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 $type = $args{'parametertypes'}{$parameter};
1576 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1577 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001578 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001580 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001581 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 } else {
1583 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001584 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 }
1586 print "\n.br\n";
1587 }
1588 print "};\n.br\n";
1589
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001590 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 foreach $parameter (@{$args{'parameterlist'}}) {
1592 ($parameter =~ /^#/) && next;
1593
1594 my $parameter_name = $parameter;
1595 $parameter_name =~ s/\[.*//;
1596
Randy Dunlap3c308792007-05-08 00:24:39 -07001597 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001598 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 output_highlight($args{'parameterdescs'}{$parameter_name});
1600 }
1601 foreach $section (@{$args{'sectionlist'}}) {
1602 print ".SH \"$section\"\n";
1603 output_highlight($args{'sections'}{$section});
1604 }
1605}
1606
1607##
1608# output typedef in man
1609sub output_typedef_man(%) {
1610 my %args = %{$_[0]};
1611 my ($parameter, $section);
1612
1613 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1614
1615 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001616 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617
1618 foreach $section (@{$args{'sectionlist'}}) {
1619 print ".SH \"$section\"\n";
1620 output_highlight($args{'sections'}{$section});
1621 }
1622}
1623
Johannes Bergb112e0f2007-10-24 15:08:48 -07001624sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 my %args = %{$_[0]};
1626 my ($parameter, $section);
1627 my $count;
1628
1629 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1630
1631 foreach $section (@{$args{'sectionlist'}}) {
1632 print ".SH \"$section\"\n";
1633 output_highlight($args{'sections'}{$section});
1634 }
1635}
1636
1637##
1638# output in text
1639sub output_function_text(%) {
1640 my %args = %{$_[0]};
1641 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001642 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
Randy Dunlapf47634b2006-07-01 04:36:36 -07001644 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001645 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001646
1647 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001648 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001649 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001650 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001651 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001652 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001654
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 my $count = 0;
1656 foreach my $parameter (@{$args{'parameterlist'}}) {
1657 $type = $args{'parametertypes'}{$parameter};
1658 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1659 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001660 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001662 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 }
1664 if ($count != $#{$args{'parameterlist'}}) {
1665 $count++;
1666 print ",\n";
1667 print " " x length($start);
1668 } else {
1669 print ");\n\n";
1670 }
1671 }
1672
1673 print "Arguments:\n\n";
1674 foreach $parameter (@{$args{'parameterlist'}}) {
1675 my $parameter_name = $parameter;
1676 $parameter_name =~ s/\[.*//;
1677
Randy Dunlapb9d973282009-06-09 08:50:38 -07001678 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 }
1680 output_section_text(@_);
1681}
1682
1683#output sections in text
1684sub output_section_text(%) {
1685 my %args = %{$_[0]};
1686 my $section;
1687
1688 print "\n";
1689 foreach $section (@{$args{'sectionlist'}}) {
1690 print "$section:\n\n";
1691 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001692 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 print "\n\n";
1694}
1695
1696# output enum in text
1697sub output_enum_text(%) {
1698 my %args = %{$_[0]};
1699 my ($parameter);
1700 my $count;
1701 print "Enum:\n\n";
1702
Randy Dunlapb9d973282009-06-09 08:50:38 -07001703 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1704 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 $count = 0;
1706 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001707 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 if ($count != $#{$args{'parameterlist'}}) {
1709 $count++;
1710 print ",";
1711 }
1712 print "\n";
1713 }
1714 print "};\n\n";
1715
1716 print "Constants:\n\n";
1717 foreach $parameter (@{$args{'parameterlist'}}) {
1718 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001719 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 }
1721
1722 output_section_text(@_);
1723}
1724
1725# output typedef in text
1726sub output_typedef_text(%) {
1727 my %args = %{$_[0]};
1728 my ($parameter);
1729 my $count;
1730 print "Typedef:\n\n";
1731
Randy Dunlapb9d973282009-06-09 08:50:38 -07001732 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 output_section_text(@_);
1734}
1735
1736# output struct as text
1737sub output_struct_text(%) {
1738 my %args = %{$_[0]};
1739 my ($parameter);
1740
Randy Dunlapb9d973282009-06-09 08:50:38 -07001741 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1742 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 foreach $parameter (@{$args{'parameterlist'}}) {
1744 if ($parameter =~ /^#/) {
1745 print "$parameter\n";
1746 next;
1747 }
1748
1749 my $parameter_name = $parameter;
1750 $parameter_name =~ s/\[.*//;
1751
Randy Dunlap3c308792007-05-08 00:24:39 -07001752 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 $type = $args{'parametertypes'}{$parameter};
1754 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1755 # pointer-to-function
1756 print "\t$1 $parameter) ($2);\n";
1757 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001758 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 print "\t$1 $parameter$2;\n";
1760 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001761 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 }
1763 }
1764 print "};\n\n";
1765
1766 print "Members:\n\n";
1767 foreach $parameter (@{$args{'parameterlist'}}) {
1768 ($parameter =~ /^#/) && next;
1769
1770 my $parameter_name = $parameter;
1771 $parameter_name =~ s/\[.*//;
1772
Randy Dunlap3c308792007-05-08 00:24:39 -07001773 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001775 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 }
1777 print "\n";
1778 output_section_text(@_);
1779}
1780
Johannes Bergb112e0f2007-10-24 15:08:48 -07001781sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 my %args = %{$_[0]};
1783 my ($parameter, $section);
1784
1785 foreach $section (@{$args{'sectionlist'}}) {
1786 print " $section:\n";
1787 print " -> ";
1788 output_highlight($args{'sections'}{$section});
1789 }
1790}
1791
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001792##
1793# output in restructured text
1794#
1795
1796#
1797# This could use some work; it's used to output the DOC: sections, and
1798# starts by putting out the name of the doc section itself, but that tends
1799# to duplicate a header already in the template file.
1800#
1801sub output_blockhead_rst(%) {
1802 my %args = %{$_[0]};
1803 my ($parameter, $section);
1804
1805 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001806 if ($output_selection != OUTPUT_INCLUDE) {
1807 print "**$section**\n\n";
1808 }
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001809 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001810 output_highlight_rst($args{'sections'}{$section});
1811 print "\n";
1812 }
1813}
1814
1815sub output_highlight_rst {
1816 my $contents = join "\n",@_;
1817 my $line;
1818
1819 # undo the evil effects of xml_escape() earlier
1820 $contents = xml_unescape($contents);
1821
1822 eval $dohighlight;
1823 die $@ if $@;
1824
1825 foreach $line (split "\n", $contents) {
Jani Nikula830066a2016-05-26 22:04:33 +03001826 print $lineprefix . $line . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001827 }
1828}
1829
1830sub output_function_rst(%) {
1831 my %args = %{$_[0]};
1832 my ($parameter, $section);
Jani Nikulac099ff62016-05-26 17:18:17 +03001833 my $oldprefix = $lineprefix;
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001834 my $start = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001835
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001836 if ($args{'typedef'}) {
1837 print ".. c:type:: ". $args{'function'} . "\n\n";
1838 print_lineno($declaration_start_line);
1839 print " **Typedef**: ";
1840 $lineprefix = "";
1841 output_highlight_rst($args{'purpose'});
1842 $start = "\n\n**Syntax**\n\n ``";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001843 } else {
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001844 print ".. c:function:: ";
1845 }
1846 if ($args{'functiontype'} ne "") {
1847 $start .= $args{'functiontype'} . " " . $args{'function'} . " (";
1848 } else {
1849 $start .= $args{'function'} . " (";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001850 }
1851 print $start;
1852
1853 my $count = 0;
1854 foreach my $parameter (@{$args{'parameterlist'}}) {
1855 if ($count ne 0) {
1856 print ", ";
1857 }
1858 $count++;
1859 $type = $args{'parametertypes'}{$parameter};
Mauro Carvalho Chehaba88b1672016-07-22 11:46:36 -03001860
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001861 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1862 # pointer-to-function
1863 print $1 . $parameter . ") (" . $2;
1864 } else {
1865 print $type . " " . $parameter;
1866 }
1867 }
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001868 if ($args{'typedef'}) {
1869 print ");``\n\n";
1870 } else {
1871 print ")\n\n";
1872 print_lineno($declaration_start_line);
1873 $lineprefix = " ";
1874 output_highlight_rst($args{'purpose'});
1875 print "\n";
1876 }
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001877
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001878 print "**Parameters**\n\n";
1879 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001880 foreach $parameter (@{$args{'parameterlist'}}) {
1881 my $parameter_name = $parameter;
1882 #$parameter_name =~ s/\[.*//;
1883 $type = $args{'parametertypes'}{$parameter};
1884
1885 if ($type ne "") {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001886 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001887 } else {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001888 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001889 }
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001890
1891 print_lineno($parameterdesc_start_lines{$parameter_name});
1892
Jani Nikula5e64fa92016-05-19 20:32:48 +03001893 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1894 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001895 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001896 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001897 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001898 }
1899 print "\n";
1900 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001901
1902 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001903 output_section_rst(@_);
1904}
1905
1906sub output_section_rst(%) {
1907 my %args = %{$_[0]};
1908 my $section;
1909 my $oldprefix = $lineprefix;
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001910 $lineprefix = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001911
1912 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001913 print "**$section**\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001914 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001915 output_highlight_rst($args{'sections'}{$section});
1916 print "\n";
1917 }
1918 print "\n";
1919 $lineprefix = $oldprefix;
1920}
1921
1922sub output_enum_rst(%) {
1923 my %args = %{$_[0]};
1924 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001925 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001926 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001927 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001928
1929 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001930 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001931 $lineprefix = " ";
1932 output_highlight_rst($args{'purpose'});
1933 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001934
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001935 print "**Constants**\n\n";
1936 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001937 foreach $parameter (@{$args{'parameterlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001938 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001939 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1940 output_highlight_rst($args{'parameterdescs'}{$parameter});
1941 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001942 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001943 }
1944 print "\n";
1945 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001946
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001947 $lineprefix = $oldprefix;
1948 output_section_rst(@_);
1949}
1950
1951sub output_typedef_rst(%) {
1952 my %args = %{$_[0]};
1953 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001954 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001955 my $name = "typedef " . $args{'typedef'};
1956
Jani Nikula62850972016-05-12 16:15:38 +03001957 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001958 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001959 $lineprefix = " ";
1960 output_highlight_rst($args{'purpose'});
1961 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001962
Jani Nikulac099ff62016-05-26 17:18:17 +03001963 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001964 output_section_rst(@_);
1965}
1966
1967sub output_struct_rst(%) {
1968 my %args = %{$_[0]};
1969 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001970 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001971 my $name = $args{'type'} . " " . $args{'struct'};
1972
Jani Nikula62850972016-05-12 16:15:38 +03001973 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001974 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001975 $lineprefix = " ";
1976 output_highlight_rst($args{'purpose'});
1977 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001978
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001979 print "**Definition**\n\n";
1980 print "::\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001981 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1982 foreach $parameter (@{$args{'parameterlist'}}) {
1983 if ($parameter =~ /^#/) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001984 print " " . "$parameter\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001985 next;
1986 }
1987
1988 my $parameter_name = $parameter;
1989 $parameter_name =~ s/\[.*//;
1990
1991 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1992 $type = $args{'parametertypes'}{$parameter};
1993 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1994 # pointer-to-function
1995 print " $1 $parameter) ($2);\n";
1996 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1997 # bitfield
1998 print " $1 $parameter$2;\n";
1999 } else {
2000 print " " . $type . " " . $parameter . ";\n";
2001 }
2002 }
2003 print " };\n\n";
2004
Jani Nikulaecbcfba2016-05-26 18:30:27 +03002005 print "**Members**\n\n";
2006 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002007 foreach $parameter (@{$args{'parameterlist'}}) {
2008 ($parameter =~ /^#/) && next;
2009
2010 my $parameter_name = $parameter;
2011 $parameter_name =~ s/\[.*//;
2012
2013 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
2014 $type = $args{'parametertypes'}{$parameter};
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002015 print_lineno($parameterdesc_start_lines{$parameter_name});
Mauro Carvalho Chehab6d232c82016-08-22 22:02:57 -03002016 print "``" . $parameter . "``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002017 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002018 print "\n";
2019 }
2020 print "\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03002021
2022 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002023 output_section_rst(@_);
2024}
2025
2026
Johannes Bergeda603f2010-09-11 15:55:22 -07002027## list mode output functions
2028
2029sub output_function_list(%) {
2030 my %args = %{$_[0]};
2031
2032 print $args{'function'} . "\n";
2033}
2034
2035# output enum in list
2036sub output_enum_list(%) {
2037 my %args = %{$_[0]};
2038 print $args{'enum'} . "\n";
2039}
2040
2041# output typedef in list
2042sub output_typedef_list(%) {
2043 my %args = %{$_[0]};
2044 print $args{'typedef'} . "\n";
2045}
2046
2047# output struct as list
2048sub output_struct_list(%) {
2049 my %args = %{$_[0]};
2050
2051 print $args{'struct'} . "\n";
2052}
2053
2054sub output_blockhead_list(%) {
2055 my %args = %{$_[0]};
2056 my ($parameter, $section);
2057
2058 foreach $section (@{$args{'sectionlist'}}) {
2059 print "DOC: $section\n";
2060 }
2061}
2062
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063##
Randy Dunlap27205742006-10-11 01:22:12 -07002064# generic output function for all types (function, struct/union, typedef, enum);
2065# calls the generated, variable output_ function name based on
2066# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067sub output_declaration {
2068 no strict 'refs';
2069 my $name = shift;
2070 my $functype = shift;
2071 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002072 if (($output_selection == OUTPUT_ALL) ||
2073 (($output_selection == OUTPUT_INCLUDE ||
2074 $output_selection == OUTPUT_EXPORTED) &&
2075 defined($function_table{$name})) ||
2076 (($output_selection == OUTPUT_EXCLUDE ||
2077 $output_selection == OUTPUT_INTERNAL) &&
2078 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002080 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 $section_counter++;
2082 }
2083}
2084
2085##
Randy Dunlap27205742006-10-11 01:22:12 -07002086# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002087sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002089 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 &$func(@_);
2091 $section_counter++;
2092}
2093
2094##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002095# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096# invokes the right handler. NOT called for functions.
2097sub dump_declaration($$) {
2098 no strict 'refs';
2099 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002100 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 &$func(@_);
2102}
2103
2104sub dump_union($$) {
2105 dump_struct(@_);
2106}
2107
2108sub dump_struct($$) {
2109 my $x = shift;
2110 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002111 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002113 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2114 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002115 $declaration_name = $2;
2116 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
2118 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002119 $members =~ s/({.*})//g;
2120 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121
Martin Waitzaeec46b2005-11-13 16:08:13 -08002122 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002123 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2124 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002125 # strip comments:
2126 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002127 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002128 # strip kmemcheck_bitfield_{begin,end}.*;
2129 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002130 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002131 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002132 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002133 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002134 # replace DECLARE_BITMAP
2135 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002136
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002138 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
2140 output_declaration($declaration_name,
2141 'struct',
2142 {'struct' => $declaration_name,
2143 'module' => $modulename,
2144 'parameterlist' => \@parameterlist,
2145 'parameterdescs' => \%parameterdescs,
2146 'parametertypes' => \%parametertypes,
2147 'sectionlist' => \@sectionlist,
2148 'sections' => \%sections,
2149 'purpose' => $declaration_purpose,
2150 'type' => $decl_type
2151 });
2152 }
2153 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002154 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 ++$errors;
2156 }
2157}
2158
2159sub dump_enum($$) {
2160 my $x = shift;
2161 my $file = shift;
2162
Martin Waitzaeec46b2005-11-13 16:08:13 -08002163 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002164 # strip #define macros inside enums
2165 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002166
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002168 $declaration_name = $1;
2169 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170
2171 foreach my $arg (split ',', $members) {
2172 $arg =~ s/^\s*(\w+).*/$1/;
2173 push @parameterlist, $arg;
2174 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002175 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002176 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 "not described in enum '$declaration_name'\n";
2178 }
2179
2180 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002181
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 output_declaration($declaration_name,
2183 'enum',
2184 {'enum' => $declaration_name,
2185 'module' => $modulename,
2186 'parameterlist' => \@parameterlist,
2187 'parameterdescs' => \%parameterdescs,
2188 'sectionlist' => \@sectionlist,
2189 'sections' => \%sections,
2190 'purpose' => $declaration_purpose
2191 });
2192 }
2193 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002194 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 ++$errors;
2196 }
2197}
2198
2199sub dump_typedef($$) {
2200 my $x = shift;
2201 my $file = shift;
2202
Martin Waitzaeec46b2005-11-13 16:08:13 -08002203 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002204
2205 # Parse function prototypes
Mauro Carvalho Chehabd37c43c2016-08-30 20:20:57 -03002206 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ ||
2207 $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) {
2208
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002209 # Function typedefs
2210 $return_type = $1;
2211 $declaration_name = $2;
2212 my $args = $3;
2213
2214 create_parameterlist($args, ',', $file);
2215
2216 output_declaration($declaration_name,
2217 'function',
2218 {'function' => $declaration_name,
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03002219 'typedef' => 1,
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002220 'module' => $modulename,
2221 'functiontype' => $return_type,
2222 'parameterlist' => \@parameterlist,
2223 'parameterdescs' => \%parameterdescs,
2224 'parametertypes' => \%parametertypes,
2225 'sectionlist' => \@sectionlist,
2226 'sections' => \%sections,
2227 'purpose' => $declaration_purpose
2228 });
2229 return;
2230 }
2231
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002233 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 $x =~ s/\[*.\]\s*;$/;/;
2235 }
2236
2237 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002238 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239
2240 output_declaration($declaration_name,
2241 'typedef',
2242 {'typedef' => $declaration_name,
2243 'module' => $modulename,
2244 'sectionlist' => \@sectionlist,
2245 'sections' => \%sections,
2246 'purpose' => $declaration_purpose
2247 });
2248 }
2249 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002250 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 ++$errors;
2252 }
2253}
2254
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002255sub save_struct_actual($) {
2256 my $actual = shift;
2257
2258 # strip all spaces from the actual param so that it looks like one string item
2259 $actual =~ s/\s*//g;
2260 $struct_actual = $struct_actual . $actual . " ";
2261}
2262
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263sub create_parameterlist($$$) {
2264 my $args = shift;
2265 my $splitter = shift;
2266 my $file = shift;
2267 my $type;
2268 my $param;
2269
Martin Waitza6d3fe72006-01-09 20:53:55 -08002270 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002272 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002274
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 foreach my $arg (split($splitter, $args)) {
2276 # strip comments
2277 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002278 # strip leading/trailing spaces
2279 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 $arg =~ s/\s*$//;
2281 $arg =~ s/\s+/ /;
2282
2283 if ($arg =~ /^#/) {
2284 # Treat preprocessor directive as a typeless variable just to fill
2285 # corresponding data structures "correctly". Catch it later in
2286 # output_* subs.
2287 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002288 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 # pointer-to-function
2290 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002291 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 $param = $1;
2293 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002294 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002295 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002297 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 $arg =~ s/\s*:\s*/:/g;
2299 $arg =~ s/\s*\[/\[/g;
2300
2301 my @args = split('\s*,\s*', $arg);
2302 if ($args[0] =~ m/\*/) {
2303 $args[0] =~ s/(\*+)\s*/ $1/;
2304 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002305
2306 my @first_arg;
2307 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2308 shift @args;
2309 push(@first_arg, split('\s+', $1));
2310 push(@first_arg, $2);
2311 } else {
2312 @first_arg = split('\s+', shift @args);
2313 }
2314
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 unshift(@args, pop @first_arg);
2316 $type = join " ", @first_arg;
2317
2318 foreach $param (@args) {
2319 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002320 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 push_parameter($2, "$type $1", $file);
2322 }
2323 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002324 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002325 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002326 push_parameter($1, "$type:$2", $file)
2327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 }
2329 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002330 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 push_parameter($param, $type, $file);
2332 }
2333 }
2334 }
2335 }
2336}
2337
2338sub push_parameter($$$) {
2339 my $param = shift;
2340 my $type = shift;
2341 my $file = shift;
2342
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002343 if (($anon_struct_union == 1) && ($type eq "") &&
2344 ($param eq "}")) {
2345 return; # ignore the ending }; from anon. struct/union
2346 }
2347
2348 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 my $param_name = $param;
2350 $param_name =~ s/\[.*//;
2351
Martin Waitza6d3fe72006-01-09 20:53:55 -08002352 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 {
Randy Dunlapced69092008-12-01 13:14:03 -08002354 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2355 $parameterdescs{$param} = "variable arguments";
2356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 }
2358 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2359 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 $param="void";
2361 $parameterdescs{void} = "no arguments";
2362 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002363 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2364 # handle unnamed (anonymous) union or struct:
2365 {
2366 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002367 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002368 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002369 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002370 }
2371
Martin Waitza6d3fe72006-01-09 20:53:55 -08002372 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002373 # (but ignore ones starting with # as these are not parameters
2374 # but inline preprocessor statements);
2375 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002376 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002377 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2378
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 $parameterdescs{$param_name} = $undescribed;
2380
2381 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002382 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 "or member '$param' not " .
2384 "described in '$declaration_name'\n";
2385 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002386 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002387 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002389 }
2390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002392 $param = xml_escape($param);
2393
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002394 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002395 # on @parameterlist;
2396 # this fixes a problem where check_sections() cannot find
2397 # a parameter like "addr[6 + 2]" because it actually appears
2398 # as "addr[6", "+", "2]" on the parameter list;
2399 # but it's better to maintain the param string unchanged for output,
2400 # so just weaken the string compare in check_sections() to ignore
2401 # "[blah" in a parameter string;
2402 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 push @parameterlist, $param;
2404 $parametertypes{$param} = $type;
2405}
2406
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002407sub check_sections($$$$$$) {
2408 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2409 my @sects = split ' ', $sectcheck;
2410 my @prms = split ' ', $prmscheck;
2411 my $err;
2412 my ($px, $sx);
2413 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2414
2415 foreach $sx (0 .. $#sects) {
2416 $err = 1;
2417 foreach $px (0 .. $#prms) {
2418 $prm_clean = $prms[$px];
2419 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002420 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002421 # ignore array size in a parameter string;
2422 # however, the original param string may contain
2423 # spaces, e.g.: addr[6 + 2]
2424 # and this appears in @prms as "addr[6" since the
2425 # parameter list is split at spaces;
2426 # hence just ignore "[..." for the sections check;
2427 $prm_clean =~ s/\[.*//;
2428
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002429 ##$prm_clean =~ s/^\**//;
2430 if ($prm_clean eq $sects[$sx]) {
2431 $err = 0;
2432 last;
2433 }
2434 }
2435 if ($err) {
2436 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002437 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002438 "Excess function parameter " .
2439 "'$sects[$sx]' " .
2440 "description in '$decl_name'\n";
2441 ++$warnings;
2442 } else {
2443 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002444 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002445 "Excess struct/union/enum/typedef member " .
2446 "'$sects[$sx]' " .
2447 "description in '$decl_name'\n";
2448 ++$warnings;
2449 }
2450 }
2451 }
2452 }
2453}
2454
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002456# Checks the section describing the return value of a function.
2457sub check_return_section {
2458 my $file = shift;
2459 my $declaration_name = shift;
2460 my $return_type = shift;
2461
2462 # Ignore an empty return type (It's a macro)
2463 # Ignore functions with a "void" return type. (But don't ignore "void *")
2464 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2465 return;
2466 }
2467
2468 if (!defined($sections{$section_return}) ||
2469 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002470 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002471 "No description found for return value of " .
2472 "'$declaration_name'\n";
2473 ++$warnings;
2474 }
2475}
2476
2477##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478# takes a function prototype and the name of the current file being
2479# processed and spits out all the details stored in the global
2480# arrays/hashes.
2481sub dump_function($$) {
2482 my $prototype = shift;
2483 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002484 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485
2486 $prototype =~ s/^static +//;
2487 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002488 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489 $prototype =~ s/^inline +//;
2490 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002491 $prototype =~ s/^__inline +//;
2492 $prototype =~ s/^__always_inline +//;
2493 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002494 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002495 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002496 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002497 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002498 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002499 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002500 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501
2502 # Yes, this truly is vile. We are looking for:
2503 # 1. Return type (may be nothing if we're looking at a macro)
2504 # 2. Function name
2505 # 3. Function parameters.
2506 #
2507 # All the while we have to watch out for function pointer parameters
2508 # (which IIRC is what the two sections are for), C types (these
2509 # regexps don't even start to express all the possibilities), and
2510 # so on.
2511 #
2512 # If you mess with these regexps, it's a good idea to check that
2513 # the following functions' documentation still comes out right:
2514 # - parport_register_device (function pointer parameters)
2515 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002516 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002518 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2519 # This is an object-like macro, it has no return type and no parameter
2520 # list.
2521 # Function-like macros are not allowed to have spaces between
2522 # declaration_name and opening parenthesis (notice the \s+).
2523 $return_type = $1;
2524 $declaration_name = $2;
2525 $noret = 1;
2526 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2528 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2529 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002530 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2532 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2533 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2534 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2535 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2536 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2537 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2538 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002539 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2540 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002541 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2542 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 $return_type = $1;
2544 $declaration_name = $2;
2545 my $args = $3;
2546
2547 create_parameterlist($args, ',', $file);
2548 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002549 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 return;
2551 }
2552
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002553 my $prms = join " ", @parameterlist;
2554 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2555
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002556 # This check emits a lot of warnings at the moment, because many
2557 # functions don't have a 'Return' doc section. So until the number
2558 # of warnings goes sufficiently down, the check is only performed in
2559 # verbose mode.
2560 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002561 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002562 check_return_section($file, $declaration_name, $return_type);
2563 }
2564
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002565 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 'function',
2567 {'function' => $declaration_name,
2568 'module' => $modulename,
2569 'functiontype' => $return_type,
2570 'parameterlist' => \@parameterlist,
2571 'parameterdescs' => \%parameterdescs,
2572 'parametertypes' => \%parametertypes,
2573 'sectionlist' => \@sectionlist,
2574 'sections' => \%sections,
2575 'purpose' => $declaration_purpose
2576 });
2577}
2578
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579sub reset_state {
2580 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 %parameterdescs = ();
2582 %parametertypes = ();
2583 @parameterlist = ();
2584 %sections = ();
2585 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002586 $sectcheck = "";
2587 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002589
Jani Nikula48af6062016-05-26 14:56:05 +03002590 $state = STATE_NORMAL;
2591 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592}
2593
Jason Baron56afb0f2009-04-30 13:29:36 -04002594sub tracepoint_munge($) {
2595 my $file = shift;
2596 my $tracepointname = 0;
2597 my $tracepointargs = 0;
2598
Jason Baron3a9089f2009-12-01 12:18:49 -05002599 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002600 $tracepointname = $1;
2601 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002602 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2603 $tracepointname = $1;
2604 }
2605 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2606 $tracepointname = $2;
2607 }
2608 $tracepointname =~ s/^\s+//; #strip leading whitespace
2609 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002610 $tracepointargs = $1;
2611 }
2612 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002613 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002614 "$prototype\n";
2615 } else {
2616 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2617 }
2618}
2619
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002620sub syscall_munge() {
2621 my $void = 0;
2622
2623 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2624## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2625 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2626 $void = 1;
2627## $prototype = "long sys_$1(void)";
2628 }
2629
2630 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2631 if ($prototype =~ m/long (sys_.*?),/) {
2632 $prototype =~ s/,/\(/;
2633 } elsif ($void) {
2634 $prototype =~ s/\)/\(void\)/;
2635 }
2636
2637 # now delete all of the odd-number commas in $prototype
2638 # so that arg types & arg names don't have a comma between them
2639 my $count = 0;
2640 my $len = length($prototype);
2641 if ($void) {
2642 $len = 0; # skip the for-loop
2643 }
2644 for (my $ix = 0; $ix < $len; $ix++) {
2645 if (substr($prototype, $ix, 1) eq ',') {
2646 $count++;
2647 if ($count % 2 == 1) {
2648 substr($prototype, $ix, 1) = ' ';
2649 }
2650 }
2651 }
2652}
2653
Daniel Vetterb7afa922016-06-01 23:46:24 +02002654sub process_proto_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 my $x = shift;
2656 my $file = shift;
2657
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002658 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2659
Randy Dunlap890c78c2008-10-25 17:06:43 -07002660 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 # do nothing
2662 }
2663 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002664 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002666
Randy Dunlap890c78c2008-10-25 17:06:43 -07002667 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002668 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2670 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002671 if ($prototype =~ /SYSCALL_DEFINE/) {
2672 syscall_munge();
2673 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002674 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2675 $prototype =~ /DEFINE_SINGLE_EVENT/)
2676 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002677 tracepoint_munge($file);
2678 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002679 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 reset_state();
2681 }
2682}
2683
Daniel Vetterb7afa922016-06-01 23:46:24 +02002684sub process_proto_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 my $x = shift;
2686 my $file = shift;
2687
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2689 $x =~ s@^\s+@@gos; # strip leading spaces
2690 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002691 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2692
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 if ($x =~ /^#/) {
2694 # To distinguish preprocessor directive from regular declaration later.
2695 $x .= ";";
2696 }
2697
2698 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002699 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 $prototype .= $1 . $2;
2701 ($2 eq '{') && $brcount++;
2702 ($2 eq '}') && $brcount--;
2703 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002704 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002706 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 }
2708 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002709 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 $prototype .= $x;
2711 last;
2712 }
2713 }
2714}
2715
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002716# xml_escape: replace <, >, and & in the text stream;
2717#
2718# however, formatting controls that are generated internally/locally in the
2719# kernel-doc script are not escaped here; instead, they begin life like
2720# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2721# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2722# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723sub xml_escape($) {
2724 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002725 if (($output_mode eq "text") || ($output_mode eq "man")) {
2726 return $text;
2727 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 $text =~ s/\&/\\\\\\amp;/g;
2729 $text =~ s/\</\\\\\\lt;/g;
2730 $text =~ s/\>/\\\\\\gt;/g;
2731 return $text;
2732}
2733
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002734# xml_unescape: reverse the effects of xml_escape
2735sub xml_unescape($) {
2736 my $text = shift;
2737 if (($output_mode eq "text") || ($output_mode eq "man")) {
2738 return $text;
2739 }
2740 $text =~ s/\\\\\\amp;/\&/g;
2741 $text =~ s/\\\\\\lt;/</g;
2742 $text =~ s/\\\\\\gt;/>/g;
2743 return $text;
2744}
2745
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002746# convert local escape strings to html
2747# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2748sub local_unescape($) {
2749 my $text = shift;
2750 if (($output_mode eq "text") || ($output_mode eq "man")) {
2751 return $text;
2752 }
2753 $text =~ s/\\\\\\\\lt:/</g;
2754 $text =~ s/\\\\\\\\gt:/>/g;
2755 return $text;
2756}
2757
Jani Nikula1ad560e2016-06-07 10:53:39 +03002758sub map_filename($) {
2759 my $file;
2760 my ($orig_file) = @_;
2761
2762 if (defined($ENV{'SRCTREE'})) {
2763 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
2764 } else {
2765 $file = $orig_file;
2766 }
2767
2768 if (defined($source_map{$file})) {
2769 $file = $source_map{$file};
2770 }
2771
2772 return $file;
2773}
2774
Jani Nikula88c2b572016-06-07 11:00:52 +03002775sub process_export_file($) {
2776 my ($orig_file) = @_;
2777 my $file = map_filename($orig_file);
2778
2779 if (!open(IN,"<$file")) {
2780 print STDERR "Error: Cannot open file $file\n";
2781 ++$errors;
2782 return;
2783 }
2784
2785 while (<IN>) {
2786 if (/$export_symbol/) {
2787 $function_table{$2} = 1;
2788 }
2789 }
2790
2791 close(IN);
2792}
2793
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002795 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 my $identifier;
2797 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002798 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002799 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002801 my ($orig_file) = @_;
Jani Nikulab7886de2016-05-28 00:41:50 +03002802 my $leading_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803
Jani Nikula1ad560e2016-06-07 10:53:39 +03002804 $file = map_filename($orig_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
2806 if (!open(IN,"<$file")) {
2807 print STDERR "Error: Cannot open file $file\n";
2808 ++$errors;
2809 return;
2810 }
2811
Ilya Dryomova9e73142010-02-26 13:05:47 -08002812 $. = 1;
2813
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 $section_counter = 0;
2815 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002816 while (s/\\\s*$//) {
2817 $_ .= <IN>;
2818 }
Jani Nikula48af6062016-05-26 14:56:05 +03002819 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002821 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002822 $in_doc_sect = 0;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002823 $declaration_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 }
Jani Nikula48af6062016-05-26 14:56:05 +03002825 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002827 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 $contents = "";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002829 $new_start_line = $. + 1;
2830
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 if ( $1 eq "" ) {
2832 $section = $section_intro;
2833 } else {
2834 $section = $1;
2835 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002836 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 elsif (/$doc_decl/o) {
2838 $identifier = $1;
2839 if (/\s*([\w\s]+?)\s*-/) {
2840 $identifier = $1;
2841 }
2842
Jani Nikula48af6062016-05-26 14:56:05 +03002843 $state = STATE_FIELD;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002844 # if there's no @param blocks need to set up default section
2845 # here
Jani Nikula2f4ad402016-05-30 11:21:06 +03002846 $contents = "";
2847 $section = $section_default;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002848 $new_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002850 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002851 $descr= $1;
2852 $descr =~ s/^\s*//;
2853 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002854 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002855 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002856 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 } else {
2858 $declaration_purpose = "";
2859 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002860
2861 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002862 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002863 print STDERR $_;
2864 ++$warnings;
2865 }
2866
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 if ($identifier =~ m/^struct/) {
2868 $decl_type = 'struct';
2869 } elsif ($identifier =~ m/^union/) {
2870 $decl_type = 'union';
2871 } elsif ($identifier =~ m/^enum/) {
2872 $decl_type = 'enum';
2873 } elsif ($identifier =~ m/^typedef/) {
2874 $decl_type = 'typedef';
2875 } else {
2876 $decl_type = 'function';
2877 }
2878
2879 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002880 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 }
2882 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002883 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 " - I thought it was a doc line\n";
2885 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002886 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 }
Jani Nikula48af6062016-05-26 14:56:05 +03002888 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Jani Nikulaf624ade2016-05-29 11:35:28 +03002889 if (/$doc_sect/i) { # case insensitive for supported section names
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 $newsection = $1;
2891 $newcontents = $2;
2892
Jani Nikulaf624ade2016-05-29 11:35:28 +03002893 # map the supported section names to the canonical names
2894 if ($newsection =~ m/^description$/i) {
2895 $newsection = $section_default;
2896 } elsif ($newsection =~ m/^context$/i) {
2897 $newsection = $section_context;
2898 } elsif ($newsection =~ m/^returns?$/i) {
2899 $newsection = $section_return;
2900 } elsif ($newsection =~ m/^\@return$/) {
2901 # special: @return is a section, not a param description
2902 $newsection = $section_return;
2903 }
2904
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002905 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002906 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002907 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002908 ++$warnings;
2909 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002910 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 $section = $section_default;
2912 }
2913
Randy Dunlap850622d2006-06-25 05:48:55 -07002914 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002915 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 $contents = $newcontents;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002917 $new_start_line = $.;
Jani Nikula0a726302016-05-28 14:50:20 +03002918 while ((substr($contents, 0, 1) eq " ") ||
2919 substr($contents, 0, 1) eq "\t") {
2920 $contents = substr($contents, 1);
2921 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 if ($contents ne "") {
2923 $contents .= "\n";
2924 }
2925 $section = $newsection;
Jani Nikulab7886de2016-05-28 00:41:50 +03002926 $leading_space = undef;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002928 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002929 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 $section = $section_default;
2931 $contents = "";
2932 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002933 # look for doc_com + <text> + doc_end:
2934 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002935 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002936 ++$warnings;
2937 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938
2939 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002940 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002942# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 } elsif (/$doc_content/) {
2944 # miguel-style comment kludge, look for blank lines after
2945 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002946 if ($1 eq "") {
2947 if ($section =~ m/^@/ || $section eq $section_context) {
2948 dump_section($file, $section, xml_escape($contents));
2949 $section = $section_default;
2950 $contents = "";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002951 $new_start_line = $.;
Johannes Weiner64231332009-09-17 19:26:53 -07002952 } else {
2953 $contents .= "\n";
2954 }
2955 $in_purpose = 0;
2956 } elsif ($in_purpose == 1) {
2957 # Continued declaration purpose
2958 chomp($declaration_purpose);
2959 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002960 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 } else {
Jani Nikulab7886de2016-05-28 00:41:50 +03002962 my $cont = $1;
2963 if ($section =~ m/^@/ || $section eq $section_context) {
2964 if (!defined $leading_space) {
2965 if ($cont =~ m/^(\s+)/) {
2966 $leading_space = $1;
2967 } else {
2968 $leading_space = "";
2969 }
2970 }
2971
2972 $cont =~ s/^$leading_space//;
2973 }
2974 $contents .= $cont . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 }
2976 } else {
2977 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002978 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 ++$warnings;
2980 }
Jani Nikula48af6062016-05-26 14:56:05 +03002981 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002982 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03002983 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002984 $section = $1;
2985 $contents = $2;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002986 $new_start_line = $.;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002987 if ($contents ne "") {
2988 while ((substr($contents, 0, 1) eq " ") ||
2989 substr($contents, 0, 1) eq "\t") {
2990 $contents = substr($contents, 1);
2991 }
Jani Nikulaa0b96c22016-05-26 22:04:06 +03002992 $contents .= "\n";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002993 }
Jani Nikula48af6062016-05-26 14:56:05 +03002994 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002995 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03002996 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002997 if (($contents ne "") && ($contents ne "\n")) {
2998 dump_section($file, $section, xml_escape($contents));
2999 $section = $section_default;
3000 $contents = "";
3001 }
Jani Nikula48af6062016-05-26 14:56:05 +03003002 $state = STATE_PROTO;
3003 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003004 # Regular text
3005 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03003006 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003007 $contents .= $1 . "\n";
Jani Nikula6450c892016-05-26 22:04:42 +03003008 # nuke leading blank lines
3009 if ($contents =~ /^\s*$/) {
3010 $contents = "";
3011 }
Jani Nikula48af6062016-05-26 14:56:05 +03003012 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
3013 $inline_doc_state = STATE_INLINE_ERROR;
Daniel Vettere7ca3112016-07-15 10:19:30 +02003014 print STDERR "${file}:$.: warning: ";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003015 print STDERR "Incorrect use of kernel-doc format: $_";
3016 ++$warnings;
3017 }
3018 }
Jani Nikula48af6062016-05-26 14:56:05 +03003019 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
3020 if (/$doc_inline_start/) {
3021 $state = STATE_INLINE;
3022 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003023 } elsif ($decl_type eq 'function') {
Daniel Vetterb7afa922016-06-01 23:46:24 +02003024 process_proto_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 } else {
Daniel Vetterb7afa922016-06-01 23:46:24 +02003026 process_proto_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 }
Jani Nikula48af6062016-05-26 14:56:05 +03003028 } elsif ($state == STATE_DOCBLOCK) {
Daniel Vetterebff7f92016-06-01 23:46:23 +02003029 if (/$doc_end/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07003031 dump_doc_section($file, $section, xml_escape($contents));
Jani Nikula2f4ad402016-05-30 11:21:06 +03003032 $section = $section_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 $contents = "";
3034 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035 %parameterdescs = ();
3036 %parametertypes = ();
3037 @parameterlist = ();
3038 %sections = ();
3039 @sectionlist = ();
3040 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03003041 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 }
3043 elsif (/$doc_content/)
3044 {
3045 if ( $1 eq "" )
3046 {
3047 $contents .= $blankline;
3048 }
3049 else
3050 {
3051 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08003052 }
Randy Dunlap3c308792007-05-08 00:24:39 -07003053 }
3054 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 }
3056 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07003057 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03003058 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08003059 print STDERR " Was looking for '$_'.\n" for keys %function_table;
3060 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 if ($output_mode eq "xml") {
3062 # The template wants at least one RefEntry here; make one.
3063 print "<refentry>\n";
3064 print " <refnamediv>\n";
3065 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003066 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 print " </refname>\n";
3068 print " <refpurpose>\n";
3069 print " Document generation inconsistency\n";
3070 print " </refpurpose>\n";
3071 print " </refnamediv>\n";
3072 print " <refsect1>\n";
3073 print " <title>\n";
3074 print " Oops\n";
3075 print " </title>\n";
3076 print " <warning>\n";
3077 print " <para>\n";
3078 print " The template for this document tried to insert\n";
3079 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003080 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 print " but none was found.\n";
3082 print " This dummy section is inserted to allow\n";
3083 print " generation to continue.\n";
3084 print " </para>\n";
3085 print " </warning>\n";
3086 print " </refsect1>\n";
3087 print "</refentry>\n";
3088 }
3089 }
3090}
Randy Dunlap8484baa2011-01-05 16:28:43 -08003091
3092
3093$kernelversion = get_kernel_version();
3094
3095# generate a sequence of code that will splice in highlighting information
3096# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02003097for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03003098 my $pattern = $highlights[$k][0];
3099 my $result = $highlights[$k][1];
3100# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
3101 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08003102}
3103
3104# Read the file that maps relative names to absolute names for
3105# separate source and object directories and for shadow trees.
3106if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3107 my ($relname, $absname);
3108 while(<SOURCE_MAP>) {
3109 chop();
3110 ($relname, $absname) = (split())[0..1];
3111 $relname =~ s:^/+::;
3112 $source_map{$relname} = $absname;
3113 }
3114 close(SOURCE_MAP);
3115}
3116
Jani Nikula88c2b572016-06-07 11:00:52 +03003117if ($output_selection == OUTPUT_EXPORTED ||
3118 $output_selection == OUTPUT_INTERNAL) {
Jani Nikulac9b2cfb2016-06-07 11:05:53 +03003119
3120 push(@export_file_list, @ARGV);
3121
Jani Nikula88c2b572016-06-07 11:00:52 +03003122 foreach (@export_file_list) {
3123 chomp;
3124 process_export_file($_);
3125 }
3126}
3127
Randy Dunlap8484baa2011-01-05 16:28:43 -08003128foreach (@ARGV) {
3129 chomp;
3130 process_file($_);
3131}
3132if ($verbose && $errors) {
3133 print STDERR "$errors errors\n";
3134}
3135if ($verbose && $warnings) {
3136 print STDERR "$warnings warnings\n";
3137}
3138
3139exit($errors);