blob: 93721f3c91bff3ef62edcf98db11fd5ab7640888 [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+)';
Jonathan Corbet5219f182016-08-24 16:31:15 -0600215my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700216my $type_struct = '\&((struct\s*)*[_\w]+)';
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700217my $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218my $type_env = '(\$\w+)';
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300219my $type_enum_full = '\&(enum)\s*([_\w]+)';
220my $type_struct_full = '\&(struct)\s*([_\w]+)';
Jani Nikula47ae7ae2016-05-26 13:57:18 +0300221my $type_typedef_full = '\&(typedef)\s*([_\w]+)';
222my $type_union_full = '\&(union)\s*([_\w]+)';
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300223my $type_member = '\&([_\w]+)((\.|->)[_\w]+)';
224my $type_member_func = $type_member . '\(\)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226# Output conversion substitutions.
227# One for each output format
228
229# these work fairly well
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300230my @highlights_html = (
231 [$type_constant, "<i>\$1</i>"],
232 [$type_func, "<b>\$1</b>"],
233 [$type_struct_xml, "<i>\$1</i>"],
234 [$type_env, "<b><i>\$1</i></b>"],
235 [$type_param, "<tt><b>\$1</b></tt>"]
236 );
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700237my $local_lt = "\\\\\\\\lt:";
238my $local_gt = "\\\\\\\\gt:";
239my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Dan Luedtke1b40c192012-08-12 10:46:15 +0200241# html version 5
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300242my @highlights_html5 = (
243 [$type_constant, "<span class=\"const\">\$1</span>"],
244 [$type_func, "<span class=\"func\">\$1</span>"],
245 [$type_struct_xml, "<span class=\"struct\">\$1</span>"],
246 [$type_env, "<span class=\"env\">\$1</span>"],
247 [$type_param, "<span class=\"param\">\$1</span>]"]
248 );
Dan Luedtke1b40c192012-08-12 10:46:15 +0200249my $blankline_html5 = $local_lt . "br /" . $local_gt;
250
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251# XML, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300252my @highlights_xml = (
253 ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
254 [$type_constant, "<constant>\$1</constant>"],
255 [$type_struct_xml, "<structname>\$1</structname>"],
256 [$type_param, "<parameter>\$1</parameter>"],
257 [$type_func, "<function>\$1</function>"],
258 [$type_env, "<envar>\$1</envar>"]
259 );
Johannes Berg5c98fc02007-10-24 15:08:48 -0700260my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262# gnome, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300263my @highlights_gnome = (
264 [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
265 [$type_func, "<function>\$1</function>"],
266 [$type_struct, "<structname>\$1</structname>"],
267 [$type_env, "<envar>\$1</envar>"],
268 [$type_param, "<parameter>\$1</parameter>" ]
269 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270my $blankline_gnome = "</para><para>\n";
271
272# these are pretty rough
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300273my @highlights_man = (
274 [$type_constant, "\$1"],
275 [$type_func, "\\\\fB\$1\\\\fP"],
276 [$type_struct, "\\\\fI\$1\\\\fP"],
277 [$type_param, "\\\\fI\$1\\\\fP"]
278 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279my $blankline_man = "";
280
281# text-mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300282my @highlights_text = (
283 [$type_constant, "\$1"],
284 [$type_func, "\$1"],
285 [$type_struct, "\$1"],
286 [$type_param, "\$1"]
287 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288my $blankline_text = "";
289
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300290# rst-mode
291my @highlights_rst = (
292 [$type_constant, "``\$1``"],
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300293 # Note: need to escape () to avoid func matching later
294 [$type_member_func, "\\:c\\:type\\:`\$1\$2\\\\(\\\\) <\$1>`"],
295 [$type_member, "\\:c\\:type\\:`\$1\$2 <\$1>`"],
Jonathan Corbet5219f182016-08-24 16:31:15 -0600296 [$type_fp_param, "**\$1\\\\(\\\\)**"],
Jani Nikulaa19bce62016-05-26 11:28:16 +0300297 [$type_func, "\\:c\\:func\\:`\$1()`"],
Jani Nikula62850972016-05-12 16:15:38 +0300298 [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
299 [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
Jani Nikula47ae7ae2016-05-26 13:57:18 +0300300 [$type_typedef_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
301 [$type_union_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
Jani Nikulaa7291e72016-05-26 13:57:06 +0300302 # in rst this can refer to any type
303 [$type_struct, "\\:c\\:type\\:`\$1`"],
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300304 [$type_param, "**\$1**"]
305 );
306my $blankline_rst = "\n";
307
Johannes Bergeda603f2010-09-11 15:55:22 -0700308# list mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300309my @highlights_list = (
310 [$type_constant, "\$1"],
311 [$type_func, "\$1"],
312 [$type_struct, "\$1"],
313 [$type_param, "\$1"]
314 );
Johannes Bergeda603f2010-09-11 15:55:22 -0700315my $blankline_list = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317# read arguments
Randy Dunlapb9d973282009-06-09 08:50:38 -0700318if ($#ARGV == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 usage();
320}
321
Randy Dunlap8484baa2011-01-05 16:28:43 -0800322my $kernelversion;
323my $dohighlight = "";
324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325my $verbose = 0;
326my $output_mode = "man";
Daniel Santose314ba32012-10-04 17:15:08 -0700327my $output_preformatted = 0;
Johannes Berg4b445952007-10-24 15:08:48 -0700328my $no_doc_sections = 0;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200329my $enable_lineno = 0;
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300330my @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331my $blankline = $blankline_man;
332my $modulename = "Kernel API";
Jani Nikulab6c3f452016-05-29 22:19:35 +0300333
334use constant {
335 OUTPUT_ALL => 0, # output all symbols and doc sections
336 OUTPUT_INCLUDE => 1, # output only specified symbols
337 OUTPUT_EXCLUDE => 2, # output everything except specified symbols
338 OUTPUT_EXPORTED => 3, # output exported symbols
339 OUTPUT_INTERNAL => 4, # output non-exported symbols
340};
341my $output_selection = OUTPUT_ALL;
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100342my $show_not_found = 0;
343
Jani Nikula88c2b572016-06-07 11:00:52 +0300344my @export_file_list;
345
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100346my @build_time;
347if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
348 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
349 @build_time = gmtime($seconds);
350} else {
351 @build_time = localtime;
352}
353
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800354my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
355 'July', 'August', 'September', 'October',
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100356 'November', 'December')[$build_time[4]] .
357 " " . ($build_time[5]+1900);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Randy Dunlap8484baa2011-01-05 16:28:43 -0800359# Essentially these are globals.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700360# They probably want to be tidied up, made more localised or something.
361# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362# could cause "use of undefined value" or other bugs.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700363my ($function, %function_table, %parametertypes, $declaration_purpose);
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200364my $declaration_start_line;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700365my ($type, $declaration_name, $return_type);
Ilya Dryomov1c32fd02010-02-26 13:06:03 -0800366my ($newsection, $newcontents, $prototype, $brcount, %source_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700368if (defined($ENV{'KBUILD_VERBOSE'})) {
369 $verbose = "$ENV{'KBUILD_VERBOSE'}";
370}
371
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800372# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
374# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
375# We keep track of number of generated entries and generate a dummy
376# if needs be to ensure the expanded template can be postprocessed
377# into html.
378my $section_counter = 0;
379
380my $lineprefix="";
381
Jani Nikula48af6062016-05-26 14:56:05 +0300382# Parser states
383use constant {
384 STATE_NORMAL => 0, # normal code
385 STATE_NAME => 1, # looking for function name
386 STATE_FIELD => 2, # scanning field start
387 STATE_PROTO => 3, # scanning prototype
388 STATE_DOCBLOCK => 4, # documentation block
389 STATE_INLINE => 5, # gathering documentation outside main block
390};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700392my $in_doc_sect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Jani Nikula48af6062016-05-26 14:56:05 +0300394# Inline documentation state
395use constant {
396 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
397 STATE_INLINE_NAME => 1, # looking for member name (@foo:)
398 STATE_INLINE_TEXT => 2, # looking for member documentation
399 STATE_INLINE_END => 3, # done
400 STATE_INLINE_ERROR => 4, # error - Comment without header was found.
401 # Spit a warning as it's not
402 # proper kernel-doc and ignore the rest.
403};
404my $inline_doc_state;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406#declaration types: can be
407# 'function', 'struct', 'union', 'enum', 'typedef'
408my $decl_type;
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
411my $doc_end = '\*/';
412my $doc_com = '\s*\*\s*';
Daniel Santos12ae6772012-10-04 17:15:10 -0700413my $doc_com_body = '\s*\* ?';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700414my $doc_decl = $doc_com . '(\w+)';
Jani Nikulaf624ade2016-05-29 11:35:28 +0300415# @params and a strictly limited set of supported section names
Jonathan Corbet8569de62016-06-09 13:35:05 -0600416my $doc_sect = $doc_com .
Jonathan Corbetef000282016-08-26 07:14:08 -0600417 '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700418my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700419my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Jani Nikula48af6062016-05-26 14:56:05 +0300420my $doc_inline_start = '^\s*/\*\*\s*$';
421my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
422my $doc_inline_end = '^\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200423my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425my %parameterdescs;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200426my %parameterdesc_start_lines;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427my @parameterlist;
428my %sections;
429my @sectionlist;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200430my %section_start_lines;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800431my $sectcheck;
432my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
434my $contents = "";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200435my $new_start_line = 0;
Jani Nikulaf624ade2016-05-29 11:35:28 +0300436
437# the canonical section names. see also $doc_sect above.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438my $section_default = "Description"; # default section
439my $section_intro = "Introduction";
440my $section = $section_default;
441my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100442my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444my $undescribed = "-- undescribed --";
445
446reset_state();
447
448while ($ARGV[0] =~ m/^-(.*)/) {
449 my $cmd = shift @ARGV;
450 if ($cmd eq "-html") {
451 $output_mode = "html";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300452 @highlights = @highlights_html;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200454 } elsif ($cmd eq "-html5") {
455 $output_mode = "html5";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300456 @highlights = @highlights_html5;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200457 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 } elsif ($cmd eq "-man") {
459 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300460 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 $blankline = $blankline_man;
462 } elsif ($cmd eq "-text") {
463 $output_mode = "text";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300464 @highlights = @highlights_text;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 $blankline = $blankline_text;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300466 } elsif ($cmd eq "-rst") {
467 $output_mode = "rst";
468 @highlights = @highlights_rst;
469 $blankline = $blankline_rst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 } elsif ($cmd eq "-docbook") {
471 $output_mode = "xml";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300472 @highlights = @highlights_xml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700474 } elsif ($cmd eq "-list") {
475 $output_mode = "list";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300476 @highlights = @highlights_list;
Johannes Bergeda603f2010-09-11 15:55:22 -0700477 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 } elsif ($cmd eq "-gnome") {
479 $output_mode = "gnome";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300480 @highlights = @highlights_gnome;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 $blankline = $blankline_gnome;
482 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
483 $modulename = shift @ARGV;
484 } elsif ($cmd eq "-function") { # to only output specific functions
Jani Nikulab6c3f452016-05-29 22:19:35 +0300485 $output_selection = OUTPUT_INCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 $function = shift @ARGV;
487 $function_table{$function} = 1;
Jani Nikulab6c3f452016-05-29 22:19:35 +0300488 } elsif ($cmd eq "-nofunction") { # output all except specific functions
489 $output_selection = OUTPUT_EXCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 $function = shift @ARGV;
491 $function_table{$function} = 1;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200492 } elsif ($cmd eq "-export") { # only exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300493 $output_selection = OUTPUT_EXPORTED;
Jani Nikulada9726e2016-06-07 10:29:59 +0300494 %function_table = ();
Jani Nikula86ae2e32016-01-21 13:05:22 +0200495 } elsif ($cmd eq "-internal") { # only non-exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300496 $output_selection = OUTPUT_INTERNAL;
Jani Nikulada9726e2016-06-07 10:29:59 +0300497 %function_table = ();
Jani Nikula88c2b572016-06-07 11:00:52 +0300498 } elsif ($cmd eq "-export-file") {
499 my $file = shift @ARGV;
500 push(@export_file_list, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 } elsif ($cmd eq "-v") {
502 $verbose = 1;
503 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
504 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700505 } elsif ($cmd eq '-no-doc-sections') {
506 $no_doc_sections = 1;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200507 } elsif ($cmd eq '-enable-lineno') {
508 $enable_lineno = 1;
Johannes Berge946c43a2013-11-12 15:11:12 -0800509 } elsif ($cmd eq '-show-not-found') {
510 $show_not_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 }
512}
513
Randy Dunlap8484baa2011-01-05 16:28:43 -0800514# continue execution near EOF;
515
Borislav Petkov53f049f2007-05-08 00:30:54 -0700516# get kernel version from env
517sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700518 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700519
520 if (defined($ENV{'KERNELVERSION'})) {
521 $version = $ENV{'KERNELVERSION'};
522 }
523 return $version;
524}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200526#
527sub print_lineno {
528 my $lineno = shift;
529 if ($enable_lineno && defined($lineno)) {
530 print "#define LINENO " . $lineno . "\n";
531 }
532}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533##
534# dumps section contents to arrays/hashes intended for that purpose.
535#
536sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700537 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 my $name = shift;
539 my $contents = join "\n", @_;
540
Jani Nikula13901ef2016-05-26 08:57:29 +0300541 if ($name =~ m/$type_param/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 $name = $1;
543 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800544 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200545 $parameterdesc_start_lines{$name} = $new_start_line;
546 $new_start_line = 0;
Randy Dunlapced69092008-12-01 13:14:03 -0800547 } elsif ($name eq "@\.\.\.") {
Randy Dunlapced69092008-12-01 13:14:03 -0800548 $name = "...";
549 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800550 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200551 $parameterdesc_start_lines{$name} = $new_start_line;
552 $new_start_line = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 } else {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700554 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Jani Nikula95b6be92016-06-10 11:14:05 +0300555 # Only warn on user specified duplicate section names.
556 if ($name ne $section_default) {
557 print STDERR "${file}:$.: warning: duplicate section name '$name'\n";
558 ++$warnings;
559 }
Jani Nikula32217762016-05-29 09:40:44 +0300560 $sections{$name} .= $contents;
561 } else {
562 $sections{$name} = $contents;
563 push @sectionlist, $name;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200564 $section_start_lines{$name} = $new_start_line;
565 $new_start_line = 0;
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700566 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 }
568}
569
570##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700571# dump DOC: section after checking that it should go out
572#
573sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700574 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700575 my $name = shift;
576 my $contents = join "\n", @_;
577
Johannes Berg4b445952007-10-24 15:08:48 -0700578 if ($no_doc_sections) {
579 return;
580 }
581
Jani Nikulab6c3f452016-05-29 22:19:35 +0300582 if (($output_selection == OUTPUT_ALL) ||
583 ($output_selection == OUTPUT_INCLUDE &&
584 defined($function_table{$name})) ||
585 ($output_selection == OUTPUT_EXCLUDE &&
586 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700587 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700588 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700589 output_blockhead({'sectionlist' => \@sectionlist,
590 'sections' => \%sections,
591 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300592 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700593 }
594}
595
596##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597# output function
598#
599# parameterdescs, a hash.
600# function => "function name"
601# parameterlist => @list of parameters
602# parameterdescs => %parameter descriptions
603# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800604# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800605#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
607sub output_highlight {
608 my $contents = join "\n",@_;
609 my $line;
610
611# DEBUG
612# if (!defined $contents) {
613# use Carp;
614# confess "output_highlight got called with no args?\n";
615# }
616
Dan Luedtke1b40c192012-08-12 10:46:15 +0200617 if ($output_mode eq "html" || $output_mode eq "html5" ||
618 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700619 $contents = local_unescape($contents);
620 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800621 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700622 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700623# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 eval $dohighlight;
625 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700626# print STDERR "contents af:$contents\n";
627
Dan Luedtke1b40c192012-08-12 10:46:15 +0200628# strip whitespaces when generating html5
629 if ($output_mode eq "html5") {
630 $contents =~ s/^\s+//;
631 $contents =~ s/\s+$//;
632 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700634 if (! $output_preformatted) {
635 $line =~ s/^\s*//;
636 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700637 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700638 if (! $output_preformatted) {
639 print $lineprefix, local_unescape($blankline);
640 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700642 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700643 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
644 print "\\&$line";
645 } else {
646 print $lineprefix, $line;
647 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 }
649 print "\n";
650 }
651}
652
Dan Luedtke1b40c192012-08-12 10:46:15 +0200653# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654sub output_section_html(%) {
655 my %args = %{$_[0]};
656 my $section;
657
658 foreach $section (@{$args{'sectionlist'}}) {
659 print "<h3>$section</h3>\n";
660 print "<blockquote>\n";
661 output_highlight($args{'sections'}{$section});
662 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800663 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664}
665
666# output enum in html
667sub output_enum_html(%) {
668 my %args = %{$_[0]};
669 my ($parameter);
670 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700671 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
Randy Dunlapb9d973282009-06-09 08:50:38 -0700673 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 $count = 0;
675 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700676 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 if ($count != $#{$args{'parameterlist'}}) {
678 $count++;
679 print ",\n";
680 }
681 print "<br>";
682 }
683 print "};<br>\n";
684
685 print "<h3>Constants</h3>\n";
686 print "<dl>\n";
687 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700688 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 print "<dd>";
690 output_highlight($args{'parameterdescs'}{$parameter});
691 }
692 print "</dl>\n";
693 output_section_html(@_);
694 print "<hr>\n";
695}
696
Randy Dunlapd28bee02006-02-01 03:06:57 -0800697# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698sub output_typedef_html(%) {
699 my %args = %{$_[0]};
700 my ($parameter);
701 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700702 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703
Randy Dunlapb9d973282009-06-09 08:50:38 -0700704 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 output_section_html(@_);
706 print "<hr>\n";
707}
708
709# output struct in html
710sub output_struct_html(%) {
711 my %args = %{$_[0]};
712 my ($parameter);
713
Randy Dunlapb9d973282009-06-09 08:50:38 -0700714 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
715 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 foreach $parameter (@{$args{'parameterlist'}}) {
717 if ($parameter =~ /^#/) {
718 print "$parameter<br>\n";
719 next;
720 }
721 my $parameter_name = $parameter;
722 $parameter_name =~ s/\[.*//;
723
Randy Dunlap3c308792007-05-08 00:24:39 -0700724 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 $type = $args{'parametertypes'}{$parameter};
726 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
727 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700728 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700730 # bitfield
731 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700733 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 }
735 }
736 print "};<br>\n";
737
738 print "<h3>Members</h3>\n";
739 print "<dl>\n";
740 foreach $parameter (@{$args{'parameterlist'}}) {
741 ($parameter =~ /^#/) && next;
742
743 my $parameter_name = $parameter;
744 $parameter_name =~ s/\[.*//;
745
Randy Dunlap3c308792007-05-08 00:24:39 -0700746 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700747 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 print "<dd>";
749 output_highlight($args{'parameterdescs'}{$parameter_name});
750 }
751 print "</dl>\n";
752 output_section_html(@_);
753 print "<hr>\n";
754}
755
756# output function in html
757sub output_function_html(%) {
758 my %args = %{$_[0]};
759 my ($parameter, $section);
760 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Randy Dunlapb9d973282009-06-09 08:50:38 -0700762 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
763 print "<i>" . $args{'functiontype'} . "</i>\n";
764 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 print "(";
766 $count = 0;
767 foreach $parameter (@{$args{'parameterlist'}}) {
768 $type = $args{'parametertypes'}{$parameter};
769 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
770 # pointer-to-function
771 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
772 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700773 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 }
775 if ($count != $#{$args{'parameterlist'}}) {
776 $count++;
777 print ",\n";
778 }
779 }
780 print ")\n";
781
782 print "<h3>Arguments</h3>\n";
783 print "<dl>\n";
784 foreach $parameter (@{$args{'parameterlist'}}) {
785 my $parameter_name = $parameter;
786 $parameter_name =~ s/\[.*//;
787
Randy Dunlap3c308792007-05-08 00:24:39 -0700788 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700789 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 print "<dd>";
791 output_highlight($args{'parameterdescs'}{$parameter_name});
792 }
793 print "</dl>\n";
794 output_section_html(@_);
795 print "<hr>\n";
796}
797
Johannes Bergb112e0f2007-10-24 15:08:48 -0700798# output DOC: block header in html
799sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 my %args = %{$_[0]};
801 my ($parameter, $section);
802 my $count;
803
804 foreach $section (@{$args{'sectionlist'}}) {
805 print "<h3>$section</h3>\n";
806 print "<ul>\n";
807 output_highlight($args{'sections'}{$section});
808 print "</ul>\n";
809 }
810 print "<hr>\n";
811}
812
Dan Luedtke1b40c192012-08-12 10:46:15 +0200813# output sections in html5
814sub output_section_html5(%) {
815 my %args = %{$_[0]};
816 my $section;
817
818 foreach $section (@{$args{'sectionlist'}}) {
819 print "<section>\n";
820 print "<h1>$section</h1>\n";
821 print "<p>\n";
822 output_highlight($args{'sections'}{$section});
823 print "</p>\n";
824 print "</section>\n";
825 }
826}
827
828# output enum in html5
829sub output_enum_html5(%) {
830 my %args = %{$_[0]};
831 my ($parameter);
832 my $count;
833 my $html5id;
834
835 $html5id = $args{'enum'};
836 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
837 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
838 print "<h1>enum " . $args{'enum'} . "</h1>\n";
839 print "<ol class=\"code\">\n";
840 print "<li>";
841 print "<span class=\"keyword\">enum</span> ";
842 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
843 print "</li>\n";
844 $count = 0;
845 foreach $parameter (@{$args{'parameterlist'}}) {
846 print "<li class=\"indent\">";
847 print "<span class=\"param\">" . $parameter . "</span>";
848 if ($count != $#{$args{'parameterlist'}}) {
849 $count++;
850 print ",";
851 }
852 print "</li>\n";
853 }
854 print "<li>};</li>\n";
855 print "</ol>\n";
856
857 print "<section>\n";
858 print "<h1>Constants</h1>\n";
859 print "<dl>\n";
860 foreach $parameter (@{$args{'parameterlist'}}) {
861 print "<dt>" . $parameter . "</dt>\n";
862 print "<dd>";
863 output_highlight($args{'parameterdescs'}{$parameter});
864 print "</dd>\n";
865 }
866 print "</dl>\n";
867 print "</section>\n";
868 output_section_html5(@_);
869 print "</article>\n";
870}
871
872# output typedef in html5
873sub output_typedef_html5(%) {
874 my %args = %{$_[0]};
875 my ($parameter);
876 my $count;
877 my $html5id;
878
879 $html5id = $args{'typedef'};
880 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
881 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
882 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
883
884 print "<ol class=\"code\">\n";
885 print "<li>";
886 print "<span class=\"keyword\">typedef</span> ";
887 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
888 print "</li>\n";
889 print "</ol>\n";
890 output_section_html5(@_);
891 print "</article>\n";
892}
893
894# output struct in html5
895sub output_struct_html5(%) {
896 my %args = %{$_[0]};
897 my ($parameter);
898 my $html5id;
899
900 $html5id = $args{'struct'};
901 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
902 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
903 print "<hgroup>\n";
904 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
905 print "<h2>". $args{'purpose'} . "</h2>\n";
906 print "</hgroup>\n";
907 print "<ol class=\"code\">\n";
908 print "<li>";
909 print "<span class=\"type\">" . $args{'type'} . "</span> ";
910 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
911 print "</li>\n";
912 foreach $parameter (@{$args{'parameterlist'}}) {
913 print "<li class=\"indent\">";
914 if ($parameter =~ /^#/) {
915 print "<span class=\"param\">" . $parameter ."</span>\n";
916 print "</li>\n";
917 next;
918 }
919 my $parameter_name = $parameter;
920 $parameter_name =~ s/\[.*//;
921
922 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
923 $type = $args{'parametertypes'}{$parameter};
924 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
925 # pointer-to-function
926 print "<span class=\"type\">$1</span> ";
927 print "<span class=\"param\">$parameter</span>";
928 print "<span class=\"type\">)</span> ";
929 print "(<span class=\"args\">$2</span>);";
930 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
931 # bitfield
932 print "<span class=\"type\">$1</span> ";
933 print "<span class=\"param\">$parameter</span>";
934 print "<span class=\"bits\">$2</span>;";
935 } else {
936 print "<span class=\"type\">$type</span> ";
937 print "<span class=\"param\">$parameter</span>;";
938 }
939 print "</li>\n";
940 }
941 print "<li>};</li>\n";
942 print "</ol>\n";
943
944 print "<section>\n";
945 print "<h1>Members</h1>\n";
946 print "<dl>\n";
947 foreach $parameter (@{$args{'parameterlist'}}) {
948 ($parameter =~ /^#/) && next;
949
950 my $parameter_name = $parameter;
951 $parameter_name =~ s/\[.*//;
952
953 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
954 print "<dt>" . $parameter . "</dt>\n";
955 print "<dd>";
956 output_highlight($args{'parameterdescs'}{$parameter_name});
957 print "</dd>\n";
958 }
959 print "</dl>\n";
960 print "</section>\n";
961 output_section_html5(@_);
962 print "</article>\n";
963}
964
965# output function in html5
966sub output_function_html5(%) {
967 my %args = %{$_[0]};
968 my ($parameter, $section);
969 my $count;
970 my $html5id;
971
972 $html5id = $args{'function'};
973 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
974 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
975 print "<hgroup>\n";
976 print "<h1>" . $args{'function'} . "</h1>";
977 print "<h2>" . $args{'purpose'} . "</h2>\n";
978 print "</hgroup>\n";
979 print "<ol class=\"code\">\n";
980 print "<li>";
981 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
982 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
983 print "</li>";
984 $count = 0;
985 foreach $parameter (@{$args{'parameterlist'}}) {
986 print "<li class=\"indent\">";
987 $type = $args{'parametertypes'}{$parameter};
988 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
989 # pointer-to-function
990 print "<span class=\"type\">$1</span> ";
991 print "<span class=\"param\">$parameter</span>";
992 print "<span class=\"type\">)</span> ";
993 print "(<span class=\"args\">$2</span>)";
994 } else {
995 print "<span class=\"type\">$type</span> ";
996 print "<span class=\"param\">$parameter</span>";
997 }
998 if ($count != $#{$args{'parameterlist'}}) {
999 $count++;
1000 print ",";
1001 }
1002 print "</li>\n";
1003 }
1004 print "<li>)</li>\n";
1005 print "</ol>\n";
1006
1007 print "<section>\n";
1008 print "<h1>Arguments</h1>\n";
1009 print "<p>\n";
1010 print "<dl>\n";
1011 foreach $parameter (@{$args{'parameterlist'}}) {
1012 my $parameter_name = $parameter;
1013 $parameter_name =~ s/\[.*//;
1014
1015 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1016 print "<dt>" . $parameter . "</dt>\n";
1017 print "<dd>";
1018 output_highlight($args{'parameterdescs'}{$parameter_name});
1019 print "</dd>\n";
1020 }
1021 print "</dl>\n";
1022 print "</section>\n";
1023 output_section_html5(@_);
1024 print "</article>\n";
1025}
1026
1027# output DOC: block header in html5
1028sub output_blockhead_html5(%) {
1029 my %args = %{$_[0]};
1030 my ($parameter, $section);
1031 my $count;
1032 my $html5id;
1033
1034 foreach $section (@{$args{'sectionlist'}}) {
1035 $html5id = $section;
1036 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1037 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1038 print "<h1>$section</h1>\n";
1039 print "<p>\n";
1040 output_highlight($args{'sections'}{$section});
1041 print "</p>\n";
1042 }
1043 print "</article>\n";
1044}
1045
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046sub output_section_xml(%) {
1047 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001048 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 # print out each section
1050 $lineprefix=" ";
1051 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001052 print "<refsect1>\n";
1053 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001055 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001056 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001057 } else {
1058 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 }
1060 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001061 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001063 print "</programlisting></informalexample>\n";
1064 } else {
1065 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001067 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 }
1069}
1070
1071# output function in XML DocBook
1072sub output_function_xml(%) {
1073 my %args = %{$_[0]};
1074 my ($parameter, $section);
1075 my $count;
1076 my $id;
1077
Randy Dunlapb9d973282009-06-09 08:50:38 -07001078 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 $id =~ s/[^A-Za-z0-9]/-/g;
1080
Pavel Pisa5449bc92007-02-10 01:45:37 -08001081 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001082 print "<refentryinfo>\n";
1083 print " <title>LINUX</title>\n";
1084 print " <productname>Kernel Hackers Manual</productname>\n";
1085 print " <date>$man_date</date>\n";
1086 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001088 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001089 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001090 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 print "</refmeta>\n";
1092 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001093 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 print " <refpurpose>\n";
1095 print " ";
1096 output_highlight ($args{'purpose'});
1097 print " </refpurpose>\n";
1098 print "</refnamediv>\n";
1099
1100 print "<refsynopsisdiv>\n";
1101 print " <title>Synopsis</title>\n";
1102 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001103 print " <funcdef>" . $args{'functiontype'} . " ";
1104 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105
1106 $count = 0;
1107 if ($#{$args{'parameterlist'}} >= 0) {
1108 foreach $parameter (@{$args{'parameterlist'}}) {
1109 $type = $args{'parametertypes'}{$parameter};
1110 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1111 # pointer-to-function
1112 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1113 print " <funcparams>$2</funcparams></paramdef>\n";
1114 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001115 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 print " <parameter>$parameter</parameter></paramdef>\n";
1117 }
1118 }
1119 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001120 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 }
1122 print " </funcprototype></funcsynopsis>\n";
1123 print "</refsynopsisdiv>\n";
1124
1125 # print parameters
1126 print "<refsect1>\n <title>Arguments</title>\n";
1127 if ($#{$args{'parameterlist'}} >= 0) {
1128 print " <variablelist>\n";
1129 foreach $parameter (@{$args{'parameterlist'}}) {
1130 my $parameter_name = $parameter;
1131 $parameter_name =~ s/\[.*//;
1132
1133 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1134 print " <listitem>\n <para>\n";
1135 $lineprefix=" ";
1136 output_highlight($args{'parameterdescs'}{$parameter_name});
1137 print " </para>\n </listitem>\n </varlistentry>\n";
1138 }
1139 print " </variablelist>\n";
1140 } else {
1141 print " <para>\n None\n </para>\n";
1142 }
1143 print "</refsect1>\n";
1144
1145 output_section_xml(@_);
1146 print "</refentry>\n\n";
1147}
1148
1149# output struct in XML DocBook
1150sub output_struct_xml(%) {
1151 my %args = %{$_[0]};
1152 my ($parameter, $section);
1153 my $id;
1154
Randy Dunlapb9d973282009-06-09 08:50:38 -07001155 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 $id =~ s/[^A-Za-z0-9]/-/g;
1157
Pavel Pisa5449bc92007-02-10 01:45:37 -08001158 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001159 print "<refentryinfo>\n";
1160 print " <title>LINUX</title>\n";
1161 print " <productname>Kernel Hackers Manual</productname>\n";
1162 print " <date>$man_date</date>\n";
1163 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001165 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001166 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001167 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 print "</refmeta>\n";
1169 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001170 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 print " <refpurpose>\n";
1172 print " ";
1173 output_highlight ($args{'purpose'});
1174 print " </refpurpose>\n";
1175 print "</refnamediv>\n";
1176
1177 print "<refsynopsisdiv>\n";
1178 print " <title>Synopsis</title>\n";
1179 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001180 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 foreach $parameter (@{$args{'parameterlist'}}) {
1182 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001183 my $prm = $parameter;
1184 # convert data read & converted thru xml_escape() into &xyz; format:
1185 # This allows us to have #define macros interspersed in a struct.
1186 $prm =~ s/\\\\\\/\&/g;
1187 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 next;
1189 }
1190
1191 my $parameter_name = $parameter;
1192 $parameter_name =~ s/\[.*//;
1193
1194 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001195 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 $type = $args{'parametertypes'}{$parameter};
1197 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1198 # pointer-to-function
1199 print " $1 $parameter) ($2);\n";
1200 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001201 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 print " $1 $parameter$2;\n";
1203 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001204 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 }
1206 }
1207 print "};";
1208 print " </programlisting>\n";
1209 print "</refsynopsisdiv>\n";
1210
1211 print " <refsect1>\n";
1212 print " <title>Members</title>\n";
1213
Randy Dunlap39f00c02008-09-22 13:57:44 -07001214 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 print " <variablelist>\n";
1216 foreach $parameter (@{$args{'parameterlist'}}) {
1217 ($parameter =~ /^#/) && next;
1218
1219 my $parameter_name = $parameter;
1220 $parameter_name =~ s/\[.*//;
1221
1222 defined($args{'parameterdescs'}{$parameter_name}) || next;
1223 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1224 print " <varlistentry>";
1225 print " <term>$parameter</term>\n";
1226 print " <listitem><para>\n";
1227 output_highlight($args{'parameterdescs'}{$parameter_name});
1228 print " </para></listitem>\n";
1229 print " </varlistentry>\n";
1230 }
1231 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001232 } else {
1233 print " <para>\n None\n </para>\n";
1234 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 print " </refsect1>\n";
1236
1237 output_section_xml(@_);
1238
1239 print "</refentry>\n\n";
1240}
1241
1242# output enum in XML DocBook
1243sub output_enum_xml(%) {
1244 my %args = %{$_[0]};
1245 my ($parameter, $section);
1246 my $count;
1247 my $id;
1248
Randy Dunlapb9d973282009-06-09 08:50:38 -07001249 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 $id =~ s/[^A-Za-z0-9]/-/g;
1251
Pavel Pisa5449bc92007-02-10 01:45:37 -08001252 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001253 print "<refentryinfo>\n";
1254 print " <title>LINUX</title>\n";
1255 print " <productname>Kernel Hackers Manual</productname>\n";
1256 print " <date>$man_date</date>\n";
1257 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001259 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001260 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001261 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 print "</refmeta>\n";
1263 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001264 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 print " <refpurpose>\n";
1266 print " ";
1267 output_highlight ($args{'purpose'});
1268 print " </refpurpose>\n";
1269 print "</refnamediv>\n";
1270
1271 print "<refsynopsisdiv>\n";
1272 print " <title>Synopsis</title>\n";
1273 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001274 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 $count = 0;
1276 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001277 print " $parameter";
1278 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 $count++;
1280 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001281 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 print "\n";
1283 }
1284 print "};";
1285 print " </programlisting>\n";
1286 print "</refsynopsisdiv>\n";
1287
1288 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001289 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 print " <variablelist>\n";
1291 foreach $parameter (@{$args{'parameterlist'}}) {
1292 my $parameter_name = $parameter;
1293 $parameter_name =~ s/\[.*//;
1294
1295 print " <varlistentry>";
1296 print " <term>$parameter</term>\n";
1297 print " <listitem><para>\n";
1298 output_highlight($args{'parameterdescs'}{$parameter_name});
1299 print " </para></listitem>\n";
1300 print " </varlistentry>\n";
1301 }
1302 print " </variablelist>\n";
1303 print "</refsect1>\n";
1304
1305 output_section_xml(@_);
1306
1307 print "</refentry>\n\n";
1308}
1309
1310# output typedef in XML DocBook
1311sub output_typedef_xml(%) {
1312 my %args = %{$_[0]};
1313 my ($parameter, $section);
1314 my $id;
1315
Randy Dunlapb9d973282009-06-09 08:50:38 -07001316 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 $id =~ s/[^A-Za-z0-9]/-/g;
1318
Pavel Pisa5449bc92007-02-10 01:45:37 -08001319 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001320 print "<refentryinfo>\n";
1321 print " <title>LINUX</title>\n";
1322 print " <productname>Kernel Hackers Manual</productname>\n";
1323 print " <date>$man_date</date>\n";
1324 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001326 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001327 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 print "</refmeta>\n";
1329 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001330 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 print " <refpurpose>\n";
1332 print " ";
1333 output_highlight ($args{'purpose'});
1334 print " </refpurpose>\n";
1335 print "</refnamediv>\n";
1336
1337 print "<refsynopsisdiv>\n";
1338 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001339 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 print "</refsynopsisdiv>\n";
1341
1342 output_section_xml(@_);
1343
1344 print "</refentry>\n\n";
1345}
1346
1347# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001348sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 my %args = %{$_[0]};
1350 my ($parameter, $section);
1351 my $count;
1352
1353 my $id = $args{'module'};
1354 $id =~ s/[^A-Za-z0-9]/-/g;
1355
1356 # print out each section
1357 $lineprefix=" ";
1358 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001359 if (!$args{'content-only'}) {
1360 print "<refsect1>\n <title>$section</title>\n";
1361 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 if ($section =~ m/EXAMPLE/i) {
1363 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001364 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001365 } else {
1366 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 }
1368 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001369 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 if ($section =~ m/EXAMPLE/i) {
1371 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001372 } else {
1373 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001375 if (!$args{'content-only'}) {
1376 print "\n</refsect1>\n";
1377 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 }
1379
1380 print "\n\n";
1381}
1382
1383# output in XML DocBook
1384sub output_function_gnome {
1385 my %args = %{$_[0]};
1386 my ($parameter, $section);
1387 my $count;
1388 my $id;
1389
Randy Dunlapb9d973282009-06-09 08:50:38 -07001390 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 $id =~ s/[^A-Za-z0-9]/-/g;
1392
1393 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001394 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395
1396 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001397 print " <funcdef>" . $args{'functiontype'} . " ";
1398 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 print "</function></funcdef>\n";
1400
1401 $count = 0;
1402 if ($#{$args{'parameterlist'}} >= 0) {
1403 foreach $parameter (@{$args{'parameterlist'}}) {
1404 $type = $args{'parametertypes'}{$parameter};
1405 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1406 # pointer-to-function
1407 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1408 print " <funcparams>$2</funcparams></paramdef>\n";
1409 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001410 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 print " <parameter>$parameter</parameter></paramdef>\n";
1412 }
1413 }
1414 } else {
1415 print " <void>\n";
1416 }
1417 print " </funcsynopsis>\n";
1418 if ($#{$args{'parameterlist'}} >= 0) {
1419 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1420 print "<tgroup cols=\"2\">\n";
1421 print "<colspec colwidth=\"2*\">\n";
1422 print "<colspec colwidth=\"8*\">\n";
1423 print "<tbody>\n";
1424 foreach $parameter (@{$args{'parameterlist'}}) {
1425 my $parameter_name = $parameter;
1426 $parameter_name =~ s/\[.*//;
1427
1428 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1429 print " <entry>\n";
1430 $lineprefix=" ";
1431 output_highlight($args{'parameterdescs'}{$parameter_name});
1432 print " </entry></row>\n";
1433 }
1434 print " </tbody></tgroup></informaltable>\n";
1435 } else {
1436 print " <para>\n None\n </para>\n";
1437 }
1438
1439 # print out each section
1440 $lineprefix=" ";
1441 foreach $section (@{$args{'sectionlist'}}) {
1442 print "<simplesect>\n <title>$section</title>\n";
1443 if ($section =~ m/EXAMPLE/i) {
1444 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001445 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 } else {
1447 }
1448 print "<para>\n";
1449 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001450 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 print "</para>\n";
1452 if ($section =~ m/EXAMPLE/i) {
1453 print "</programlisting></example>\n";
1454 } else {
1455 }
1456 print " </simplesect>\n";
1457 }
1458
1459 print "</sect2>\n\n";
1460}
1461
1462##
1463# output function in man
1464sub output_function_man(%) {
1465 my %args = %{$_[0]};
1466 my ($parameter, $section);
1467 my $count;
1468
1469 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1470
1471 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001472 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
1474 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001475 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001476 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001477 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001478 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001479 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 $count = 0;
1481 my $parenth = "(";
1482 my $post = ",";
1483 foreach my $parameter (@{$args{'parameterlist'}}) {
1484 if ($count == $#{$args{'parameterlist'}}) {
1485 $post = ");";
1486 }
1487 $type = $args{'parametertypes'}{$parameter};
1488 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1489 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001490 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 } else {
1492 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001493 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 }
1495 $count++;
1496 $parenth = "";
1497 }
1498
1499 print ".SH ARGUMENTS\n";
1500 foreach $parameter (@{$args{'parameterlist'}}) {
1501 my $parameter_name = $parameter;
1502 $parameter_name =~ s/\[.*//;
1503
Randy Dunlapb9d973282009-06-09 08:50:38 -07001504 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 output_highlight($args{'parameterdescs'}{$parameter_name});
1506 }
1507 foreach $section (@{$args{'sectionlist'}}) {
1508 print ".SH \"", uc $section, "\"\n";
1509 output_highlight($args{'sections'}{$section});
1510 }
1511}
1512
1513##
1514# output enum in man
1515sub output_enum_man(%) {
1516 my %args = %{$_[0]};
1517 my ($parameter, $section);
1518 my $count;
1519
1520 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1521
1522 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001523 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524
1525 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001526 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 $count = 0;
1528 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001529 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 if ($count == $#{$args{'parameterlist'}}) {
1531 print "\n};\n";
1532 last;
1533 }
1534 else {
1535 print ", \n.br\n";
1536 }
1537 $count++;
1538 }
1539
1540 print ".SH Constants\n";
1541 foreach $parameter (@{$args{'parameterlist'}}) {
1542 my $parameter_name = $parameter;
1543 $parameter_name =~ s/\[.*//;
1544
Randy Dunlapb9d973282009-06-09 08:50:38 -07001545 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 output_highlight($args{'parameterdescs'}{$parameter_name});
1547 }
1548 foreach $section (@{$args{'sectionlist'}}) {
1549 print ".SH \"$section\"\n";
1550 output_highlight($args{'sections'}{$section});
1551 }
1552}
1553
1554##
1555# output struct in man
1556sub output_struct_man(%) {
1557 my %args = %{$_[0]};
1558 my ($parameter, $section);
1559
Randy Dunlapb9d973282009-06-09 08:50:38 -07001560 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561
1562 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001563 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
1565 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001566 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
1568 foreach my $parameter (@{$args{'parameterlist'}}) {
1569 if ($parameter =~ /^#/) {
1570 print ".BI \"$parameter\"\n.br\n";
1571 next;
1572 }
1573 my $parameter_name = $parameter;
1574 $parameter_name =~ s/\[.*//;
1575
Randy Dunlap3c308792007-05-08 00:24:39 -07001576 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 $type = $args{'parametertypes'}{$parameter};
1578 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1579 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001580 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001582 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001583 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 } else {
1585 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001586 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 }
1588 print "\n.br\n";
1589 }
1590 print "};\n.br\n";
1591
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001592 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 foreach $parameter (@{$args{'parameterlist'}}) {
1594 ($parameter =~ /^#/) && next;
1595
1596 my $parameter_name = $parameter;
1597 $parameter_name =~ s/\[.*//;
1598
Randy Dunlap3c308792007-05-08 00:24:39 -07001599 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001600 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601 output_highlight($args{'parameterdescs'}{$parameter_name});
1602 }
1603 foreach $section (@{$args{'sectionlist'}}) {
1604 print ".SH \"$section\"\n";
1605 output_highlight($args{'sections'}{$section});
1606 }
1607}
1608
1609##
1610# output typedef in man
1611sub output_typedef_man(%) {
1612 my %args = %{$_[0]};
1613 my ($parameter, $section);
1614
1615 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1616
1617 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001618 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619
1620 foreach $section (@{$args{'sectionlist'}}) {
1621 print ".SH \"$section\"\n";
1622 output_highlight($args{'sections'}{$section});
1623 }
1624}
1625
Johannes Bergb112e0f2007-10-24 15:08:48 -07001626sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 my %args = %{$_[0]};
1628 my ($parameter, $section);
1629 my $count;
1630
1631 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1632
1633 foreach $section (@{$args{'sectionlist'}}) {
1634 print ".SH \"$section\"\n";
1635 output_highlight($args{'sections'}{$section});
1636 }
1637}
1638
1639##
1640# output in text
1641sub output_function_text(%) {
1642 my %args = %{$_[0]};
1643 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001644 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
Randy Dunlapf47634b2006-07-01 04:36:36 -07001646 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001647 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001648
1649 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001650 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001651 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001652 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001653 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001654 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001656
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 my $count = 0;
1658 foreach my $parameter (@{$args{'parameterlist'}}) {
1659 $type = $args{'parametertypes'}{$parameter};
1660 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1661 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001662 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001664 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 }
1666 if ($count != $#{$args{'parameterlist'}}) {
1667 $count++;
1668 print ",\n";
1669 print " " x length($start);
1670 } else {
1671 print ");\n\n";
1672 }
1673 }
1674
1675 print "Arguments:\n\n";
1676 foreach $parameter (@{$args{'parameterlist'}}) {
1677 my $parameter_name = $parameter;
1678 $parameter_name =~ s/\[.*//;
1679
Randy Dunlapb9d973282009-06-09 08:50:38 -07001680 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 }
1682 output_section_text(@_);
1683}
1684
1685#output sections in text
1686sub output_section_text(%) {
1687 my %args = %{$_[0]};
1688 my $section;
1689
1690 print "\n";
1691 foreach $section (@{$args{'sectionlist'}}) {
1692 print "$section:\n\n";
1693 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001694 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 print "\n\n";
1696}
1697
1698# output enum in text
1699sub output_enum_text(%) {
1700 my %args = %{$_[0]};
1701 my ($parameter);
1702 my $count;
1703 print "Enum:\n\n";
1704
Randy Dunlapb9d973282009-06-09 08:50:38 -07001705 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1706 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 $count = 0;
1708 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001709 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 if ($count != $#{$args{'parameterlist'}}) {
1711 $count++;
1712 print ",";
1713 }
1714 print "\n";
1715 }
1716 print "};\n\n";
1717
1718 print "Constants:\n\n";
1719 foreach $parameter (@{$args{'parameterlist'}}) {
1720 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001721 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 }
1723
1724 output_section_text(@_);
1725}
1726
1727# output typedef in text
1728sub output_typedef_text(%) {
1729 my %args = %{$_[0]};
1730 my ($parameter);
1731 my $count;
1732 print "Typedef:\n\n";
1733
Randy Dunlapb9d973282009-06-09 08:50:38 -07001734 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 output_section_text(@_);
1736}
1737
1738# output struct as text
1739sub output_struct_text(%) {
1740 my %args = %{$_[0]};
1741 my ($parameter);
1742
Randy Dunlapb9d973282009-06-09 08:50:38 -07001743 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1744 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 foreach $parameter (@{$args{'parameterlist'}}) {
1746 if ($parameter =~ /^#/) {
1747 print "$parameter\n";
1748 next;
1749 }
1750
1751 my $parameter_name = $parameter;
1752 $parameter_name =~ s/\[.*//;
1753
Randy Dunlap3c308792007-05-08 00:24:39 -07001754 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 $type = $args{'parametertypes'}{$parameter};
1756 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1757 # pointer-to-function
1758 print "\t$1 $parameter) ($2);\n";
1759 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001760 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 print "\t$1 $parameter$2;\n";
1762 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001763 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 }
1765 }
1766 print "};\n\n";
1767
1768 print "Members:\n\n";
1769 foreach $parameter (@{$args{'parameterlist'}}) {
1770 ($parameter =~ /^#/) && next;
1771
1772 my $parameter_name = $parameter;
1773 $parameter_name =~ s/\[.*//;
1774
Randy Dunlap3c308792007-05-08 00:24:39 -07001775 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001777 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 }
1779 print "\n";
1780 output_section_text(@_);
1781}
1782
Johannes Bergb112e0f2007-10-24 15:08:48 -07001783sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 my %args = %{$_[0]};
1785 my ($parameter, $section);
1786
1787 foreach $section (@{$args{'sectionlist'}}) {
1788 print " $section:\n";
1789 print " -> ";
1790 output_highlight($args{'sections'}{$section});
1791 }
1792}
1793
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001794##
1795# output in restructured text
1796#
1797
1798#
1799# This could use some work; it's used to output the DOC: sections, and
1800# starts by putting out the name of the doc section itself, but that tends
1801# to duplicate a header already in the template file.
1802#
1803sub output_blockhead_rst(%) {
1804 my %args = %{$_[0]};
1805 my ($parameter, $section);
1806
1807 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001808 if ($output_selection != OUTPUT_INCLUDE) {
1809 print "**$section**\n\n";
1810 }
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001811 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001812 output_highlight_rst($args{'sections'}{$section});
1813 print "\n";
1814 }
1815}
1816
1817sub output_highlight_rst {
1818 my $contents = join "\n",@_;
1819 my $line;
1820
1821 # undo the evil effects of xml_escape() earlier
1822 $contents = xml_unescape($contents);
1823
1824 eval $dohighlight;
1825 die $@ if $@;
1826
1827 foreach $line (split "\n", $contents) {
Jani Nikula830066a2016-05-26 22:04:33 +03001828 print $lineprefix . $line . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001829 }
1830}
1831
1832sub output_function_rst(%) {
1833 my %args = %{$_[0]};
1834 my ($parameter, $section);
Jani Nikulac099ff62016-05-26 17:18:17 +03001835 my $oldprefix = $lineprefix;
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001836 my $start = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001837
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001838 if ($args{'typedef'}) {
1839 print ".. c:type:: ". $args{'function'} . "\n\n";
1840 print_lineno($declaration_start_line);
1841 print " **Typedef**: ";
1842 $lineprefix = "";
1843 output_highlight_rst($args{'purpose'});
1844 $start = "\n\n**Syntax**\n\n ``";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001845 } else {
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001846 print ".. c:function:: ";
1847 }
1848 if ($args{'functiontype'} ne "") {
1849 $start .= $args{'functiontype'} . " " . $args{'function'} . " (";
1850 } else {
1851 $start .= $args{'function'} . " (";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001852 }
1853 print $start;
1854
1855 my $count = 0;
1856 foreach my $parameter (@{$args{'parameterlist'}}) {
1857 if ($count ne 0) {
1858 print ", ";
1859 }
1860 $count++;
1861 $type = $args{'parametertypes'}{$parameter};
Mauro Carvalho Chehaba88b1672016-07-22 11:46:36 -03001862
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001863 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1864 # pointer-to-function
1865 print $1 . $parameter . ") (" . $2;
1866 } else {
1867 print $type . " " . $parameter;
1868 }
1869 }
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001870 if ($args{'typedef'}) {
1871 print ");``\n\n";
1872 } else {
1873 print ")\n\n";
1874 print_lineno($declaration_start_line);
1875 $lineprefix = " ";
1876 output_highlight_rst($args{'purpose'});
1877 print "\n";
1878 }
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001879
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001880 print "**Parameters**\n\n";
1881 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001882 foreach $parameter (@{$args{'parameterlist'}}) {
1883 my $parameter_name = $parameter;
1884 #$parameter_name =~ s/\[.*//;
1885 $type = $args{'parametertypes'}{$parameter};
1886
1887 if ($type ne "") {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001888 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001889 } else {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001890 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001891 }
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001892
1893 print_lineno($parameterdesc_start_lines{$parameter_name});
1894
Jani Nikula5e64fa92016-05-19 20:32:48 +03001895 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1896 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001897 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001898 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001899 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001900 }
1901 print "\n";
1902 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001903
1904 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001905 output_section_rst(@_);
1906}
1907
1908sub output_section_rst(%) {
1909 my %args = %{$_[0]};
1910 my $section;
1911 my $oldprefix = $lineprefix;
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001912 $lineprefix = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001913
1914 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001915 print "**$section**\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001916 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001917 output_highlight_rst($args{'sections'}{$section});
1918 print "\n";
1919 }
1920 print "\n";
1921 $lineprefix = $oldprefix;
1922}
1923
1924sub output_enum_rst(%) {
1925 my %args = %{$_[0]};
1926 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001927 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001928 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001929 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001930
1931 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001932 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001933 $lineprefix = " ";
1934 output_highlight_rst($args{'purpose'});
1935 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001936
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001937 print "**Constants**\n\n";
1938 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001939 foreach $parameter (@{$args{'parameterlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001940 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001941 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1942 output_highlight_rst($args{'parameterdescs'}{$parameter});
1943 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001944 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001945 }
1946 print "\n";
1947 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001948
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001949 $lineprefix = $oldprefix;
1950 output_section_rst(@_);
1951}
1952
1953sub output_typedef_rst(%) {
1954 my %args = %{$_[0]};
1955 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001956 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001957 my $name = "typedef " . $args{'typedef'};
1958
Jani Nikula62850972016-05-12 16:15:38 +03001959 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001960 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001961 $lineprefix = " ";
1962 output_highlight_rst($args{'purpose'});
1963 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001964
Jani Nikulac099ff62016-05-26 17:18:17 +03001965 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001966 output_section_rst(@_);
1967}
1968
1969sub output_struct_rst(%) {
1970 my %args = %{$_[0]};
1971 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001972 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001973 my $name = $args{'type'} . " " . $args{'struct'};
1974
Jani Nikula62850972016-05-12 16:15:38 +03001975 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001976 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001977 $lineprefix = " ";
1978 output_highlight_rst($args{'purpose'});
1979 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001980
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001981 print "**Definition**\n\n";
1982 print "::\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001983 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1984 foreach $parameter (@{$args{'parameterlist'}}) {
1985 if ($parameter =~ /^#/) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001986 print " " . "$parameter\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001987 next;
1988 }
1989
1990 my $parameter_name = $parameter;
1991 $parameter_name =~ s/\[.*//;
1992
1993 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1994 $type = $args{'parametertypes'}{$parameter};
1995 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1996 # pointer-to-function
1997 print " $1 $parameter) ($2);\n";
1998 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1999 # bitfield
2000 print " $1 $parameter$2;\n";
2001 } else {
2002 print " " . $type . " " . $parameter . ";\n";
2003 }
2004 }
2005 print " };\n\n";
2006
Jani Nikulaecbcfba2016-05-26 18:30:27 +03002007 print "**Members**\n\n";
2008 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002009 foreach $parameter (@{$args{'parameterlist'}}) {
2010 ($parameter =~ /^#/) && next;
2011
2012 my $parameter_name = $parameter;
2013 $parameter_name =~ s/\[.*//;
2014
2015 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
2016 $type = $args{'parametertypes'}{$parameter};
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002017 print_lineno($parameterdesc_start_lines{$parameter_name});
Mauro Carvalho Chehab6d232c82016-08-22 22:02:57 -03002018 print "``" . $parameter . "``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002019 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002020 print "\n";
2021 }
2022 print "\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03002023
2024 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002025 output_section_rst(@_);
2026}
2027
2028
Johannes Bergeda603f2010-09-11 15:55:22 -07002029## list mode output functions
2030
2031sub output_function_list(%) {
2032 my %args = %{$_[0]};
2033
2034 print $args{'function'} . "\n";
2035}
2036
2037# output enum in list
2038sub output_enum_list(%) {
2039 my %args = %{$_[0]};
2040 print $args{'enum'} . "\n";
2041}
2042
2043# output typedef in list
2044sub output_typedef_list(%) {
2045 my %args = %{$_[0]};
2046 print $args{'typedef'} . "\n";
2047}
2048
2049# output struct as list
2050sub output_struct_list(%) {
2051 my %args = %{$_[0]};
2052
2053 print $args{'struct'} . "\n";
2054}
2055
2056sub output_blockhead_list(%) {
2057 my %args = %{$_[0]};
2058 my ($parameter, $section);
2059
2060 foreach $section (@{$args{'sectionlist'}}) {
2061 print "DOC: $section\n";
2062 }
2063}
2064
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065##
Randy Dunlap27205742006-10-11 01:22:12 -07002066# generic output function for all types (function, struct/union, typedef, enum);
2067# calls the generated, variable output_ function name based on
2068# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069sub output_declaration {
2070 no strict 'refs';
2071 my $name = shift;
2072 my $functype = shift;
2073 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002074 if (($output_selection == OUTPUT_ALL) ||
2075 (($output_selection == OUTPUT_INCLUDE ||
2076 $output_selection == OUTPUT_EXPORTED) &&
2077 defined($function_table{$name})) ||
2078 (($output_selection == OUTPUT_EXCLUDE ||
2079 $output_selection == OUTPUT_INTERNAL) &&
2080 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002082 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 $section_counter++;
2084 }
2085}
2086
2087##
Randy Dunlap27205742006-10-11 01:22:12 -07002088# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002089sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002091 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 &$func(@_);
2093 $section_counter++;
2094}
2095
2096##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002097# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098# invokes the right handler. NOT called for functions.
2099sub dump_declaration($$) {
2100 no strict 'refs';
2101 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002102 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 &$func(@_);
2104}
2105
2106sub dump_union($$) {
2107 dump_struct(@_);
2108}
2109
2110sub dump_struct($$) {
2111 my $x = shift;
2112 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002113 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002115 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2116 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002117 $declaration_name = $2;
2118 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119
2120 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002121 $members =~ s/({.*})//g;
2122 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
Martin Waitzaeec46b2005-11-13 16:08:13 -08002124 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002125 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2126 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002127 # strip comments:
2128 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002129 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002130 # strip kmemcheck_bitfield_{begin,end}.*;
2131 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002132 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002133 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002134 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002135 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002136 # replace DECLARE_BITMAP
2137 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002138
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002140 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141
2142 output_declaration($declaration_name,
2143 'struct',
2144 {'struct' => $declaration_name,
2145 'module' => $modulename,
2146 'parameterlist' => \@parameterlist,
2147 'parameterdescs' => \%parameterdescs,
2148 'parametertypes' => \%parametertypes,
2149 'sectionlist' => \@sectionlist,
2150 'sections' => \%sections,
2151 'purpose' => $declaration_purpose,
2152 'type' => $decl_type
2153 });
2154 }
2155 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002156 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 ++$errors;
2158 }
2159}
2160
2161sub dump_enum($$) {
2162 my $x = shift;
2163 my $file = shift;
2164
Martin Waitzaeec46b2005-11-13 16:08:13 -08002165 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002166 # strip #define macros inside enums
2167 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002168
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002170 $declaration_name = $1;
2171 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
2173 foreach my $arg (split ',', $members) {
2174 $arg =~ s/^\s*(\w+).*/$1/;
2175 push @parameterlist, $arg;
2176 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002177 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002178 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 "not described in enum '$declaration_name'\n";
2180 }
2181
2182 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002183
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 output_declaration($declaration_name,
2185 'enum',
2186 {'enum' => $declaration_name,
2187 'module' => $modulename,
2188 'parameterlist' => \@parameterlist,
2189 'parameterdescs' => \%parameterdescs,
2190 'sectionlist' => \@sectionlist,
2191 'sections' => \%sections,
2192 'purpose' => $declaration_purpose
2193 });
2194 }
2195 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002196 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 ++$errors;
2198 }
2199}
2200
2201sub dump_typedef($$) {
2202 my $x = shift;
2203 my $file = shift;
2204
Martin Waitzaeec46b2005-11-13 16:08:13 -08002205 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002206
2207 # Parse function prototypes
Mauro Carvalho Chehabd37c43c2016-08-30 20:20:57 -03002208 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ ||
2209 $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) {
2210
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002211 # Function typedefs
2212 $return_type = $1;
2213 $declaration_name = $2;
2214 my $args = $3;
2215
2216 create_parameterlist($args, ',', $file);
2217
2218 output_declaration($declaration_name,
2219 'function',
2220 {'function' => $declaration_name,
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03002221 'typedef' => 1,
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002222 'module' => $modulename,
2223 'functiontype' => $return_type,
2224 'parameterlist' => \@parameterlist,
2225 'parameterdescs' => \%parameterdescs,
2226 'parametertypes' => \%parametertypes,
2227 'sectionlist' => \@sectionlist,
2228 'sections' => \%sections,
2229 'purpose' => $declaration_purpose
2230 });
2231 return;
2232 }
2233
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002235 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 $x =~ s/\[*.\]\s*;$/;/;
2237 }
2238
2239 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002240 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
2242 output_declaration($declaration_name,
2243 'typedef',
2244 {'typedef' => $declaration_name,
2245 'module' => $modulename,
2246 'sectionlist' => \@sectionlist,
2247 'sections' => \%sections,
2248 'purpose' => $declaration_purpose
2249 });
2250 }
2251 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002252 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 ++$errors;
2254 }
2255}
2256
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002257sub save_struct_actual($) {
2258 my $actual = shift;
2259
2260 # strip all spaces from the actual param so that it looks like one string item
2261 $actual =~ s/\s*//g;
2262 $struct_actual = $struct_actual . $actual . " ";
2263}
2264
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265sub create_parameterlist($$$) {
2266 my $args = shift;
2267 my $splitter = shift;
2268 my $file = shift;
2269 my $type;
2270 my $param;
2271
Martin Waitza6d3fe72006-01-09 20:53:55 -08002272 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002274 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002276
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 foreach my $arg (split($splitter, $args)) {
2278 # strip comments
2279 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002280 # strip leading/trailing spaces
2281 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 $arg =~ s/\s*$//;
2283 $arg =~ s/\s+/ /;
2284
2285 if ($arg =~ /^#/) {
2286 # Treat preprocessor directive as a typeless variable just to fill
2287 # corresponding data structures "correctly". Catch it later in
2288 # output_* subs.
2289 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002290 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 # pointer-to-function
2292 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002293 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 $param = $1;
2295 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002296 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002297 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002299 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 $arg =~ s/\s*:\s*/:/g;
2301 $arg =~ s/\s*\[/\[/g;
2302
2303 my @args = split('\s*,\s*', $arg);
2304 if ($args[0] =~ m/\*/) {
2305 $args[0] =~ s/(\*+)\s*/ $1/;
2306 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002307
2308 my @first_arg;
2309 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2310 shift @args;
2311 push(@first_arg, split('\s+', $1));
2312 push(@first_arg, $2);
2313 } else {
2314 @first_arg = split('\s+', shift @args);
2315 }
2316
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 unshift(@args, pop @first_arg);
2318 $type = join " ", @first_arg;
2319
2320 foreach $param (@args) {
2321 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002322 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 push_parameter($2, "$type $1", $file);
2324 }
2325 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002326 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002327 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002328 push_parameter($1, "$type:$2", $file)
2329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 }
2331 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002332 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 push_parameter($param, $type, $file);
2334 }
2335 }
2336 }
2337 }
2338}
2339
2340sub push_parameter($$$) {
2341 my $param = shift;
2342 my $type = shift;
2343 my $file = shift;
2344
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002345 if (($anon_struct_union == 1) && ($type eq "") &&
2346 ($param eq "}")) {
2347 return; # ignore the ending }; from anon. struct/union
2348 }
2349
2350 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 my $param_name = $param;
2352 $param_name =~ s/\[.*//;
2353
Martin Waitza6d3fe72006-01-09 20:53:55 -08002354 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 {
Jonathan Corbetef000282016-08-26 07:14:08 -06002356 $param = "...";
Randy Dunlapced69092008-12-01 13:14:03 -08002357 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2358 $parameterdescs{$param} = "variable arguments";
2359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 }
2361 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2362 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 $param="void";
2364 $parameterdescs{void} = "no arguments";
2365 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002366 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2367 # handle unnamed (anonymous) union or struct:
2368 {
2369 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002370 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002371 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002372 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002373 }
2374
Martin Waitza6d3fe72006-01-09 20:53:55 -08002375 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002376 # (but ignore ones starting with # as these are not parameters
2377 # but inline preprocessor statements);
2378 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002379 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002380 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2381
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 $parameterdescs{$param_name} = $undescribed;
2383
2384 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002385 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 "or member '$param' not " .
2387 "described in '$declaration_name'\n";
2388 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002389 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002390 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002392 }
2393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002395 $param = xml_escape($param);
2396
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002397 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002398 # on @parameterlist;
2399 # this fixes a problem where check_sections() cannot find
2400 # a parameter like "addr[6 + 2]" because it actually appears
2401 # as "addr[6", "+", "2]" on the parameter list;
2402 # but it's better to maintain the param string unchanged for output,
2403 # so just weaken the string compare in check_sections() to ignore
2404 # "[blah" in a parameter string;
2405 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 push @parameterlist, $param;
2407 $parametertypes{$param} = $type;
2408}
2409
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002410sub check_sections($$$$$$) {
2411 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2412 my @sects = split ' ', $sectcheck;
2413 my @prms = split ' ', $prmscheck;
2414 my $err;
2415 my ($px, $sx);
2416 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2417
2418 foreach $sx (0 .. $#sects) {
2419 $err = 1;
2420 foreach $px (0 .. $#prms) {
2421 $prm_clean = $prms[$px];
2422 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002423 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002424 # ignore array size in a parameter string;
2425 # however, the original param string may contain
2426 # spaces, e.g.: addr[6 + 2]
2427 # and this appears in @prms as "addr[6" since the
2428 # parameter list is split at spaces;
2429 # hence just ignore "[..." for the sections check;
2430 $prm_clean =~ s/\[.*//;
2431
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002432 ##$prm_clean =~ s/^\**//;
2433 if ($prm_clean eq $sects[$sx]) {
2434 $err = 0;
2435 last;
2436 }
2437 }
2438 if ($err) {
2439 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002440 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002441 "Excess function parameter " .
2442 "'$sects[$sx]' " .
2443 "description in '$decl_name'\n";
2444 ++$warnings;
2445 } else {
2446 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002447 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002448 "Excess struct/union/enum/typedef member " .
2449 "'$sects[$sx]' " .
2450 "description in '$decl_name'\n";
2451 ++$warnings;
2452 }
2453 }
2454 }
2455 }
2456}
2457
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002459# Checks the section describing the return value of a function.
2460sub check_return_section {
2461 my $file = shift;
2462 my $declaration_name = shift;
2463 my $return_type = shift;
2464
2465 # Ignore an empty return type (It's a macro)
2466 # Ignore functions with a "void" return type. (But don't ignore "void *")
2467 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2468 return;
2469 }
2470
2471 if (!defined($sections{$section_return}) ||
2472 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002473 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002474 "No description found for return value of " .
2475 "'$declaration_name'\n";
2476 ++$warnings;
2477 }
2478}
2479
2480##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481# takes a function prototype and the name of the current file being
2482# processed and spits out all the details stored in the global
2483# arrays/hashes.
2484sub dump_function($$) {
2485 my $prototype = shift;
2486 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002487 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488
2489 $prototype =~ s/^static +//;
2490 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002491 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 $prototype =~ s/^inline +//;
2493 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002494 $prototype =~ s/^__inline +//;
2495 $prototype =~ s/^__always_inline +//;
2496 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002497 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002498 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002499 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002500 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002501 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002502 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002503 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504
2505 # Yes, this truly is vile. We are looking for:
2506 # 1. Return type (may be nothing if we're looking at a macro)
2507 # 2. Function name
2508 # 3. Function parameters.
2509 #
2510 # All the while we have to watch out for function pointer parameters
2511 # (which IIRC is what the two sections are for), C types (these
2512 # regexps don't even start to express all the possibilities), and
2513 # so on.
2514 #
2515 # If you mess with these regexps, it's a good idea to check that
2516 # the following functions' documentation still comes out right:
2517 # - parport_register_device (function pointer parameters)
2518 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002519 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002521 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2522 # This is an object-like macro, it has no return type and no parameter
2523 # list.
2524 # Function-like macros are not allowed to have spaces between
2525 # declaration_name and opening parenthesis (notice the \s+).
2526 $return_type = $1;
2527 $declaration_name = $2;
2528 $noret = 1;
2529 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2531 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2532 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002533 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2535 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2536 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2537 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2538 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2539 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2540 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2541 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002542 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2543 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002544 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2545 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 $return_type = $1;
2547 $declaration_name = $2;
2548 my $args = $3;
2549
2550 create_parameterlist($args, ',', $file);
2551 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002552 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 return;
2554 }
2555
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002556 my $prms = join " ", @parameterlist;
2557 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2558
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002559 # This check emits a lot of warnings at the moment, because many
2560 # functions don't have a 'Return' doc section. So until the number
2561 # of warnings goes sufficiently down, the check is only performed in
2562 # verbose mode.
2563 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002564 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002565 check_return_section($file, $declaration_name, $return_type);
2566 }
2567
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002568 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 'function',
2570 {'function' => $declaration_name,
2571 'module' => $modulename,
2572 'functiontype' => $return_type,
2573 'parameterlist' => \@parameterlist,
2574 'parameterdescs' => \%parameterdescs,
2575 'parametertypes' => \%parametertypes,
2576 'sectionlist' => \@sectionlist,
2577 'sections' => \%sections,
2578 'purpose' => $declaration_purpose
2579 });
2580}
2581
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582sub reset_state {
2583 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 %parameterdescs = ();
2585 %parametertypes = ();
2586 @parameterlist = ();
2587 %sections = ();
2588 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002589 $sectcheck = "";
2590 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002592
Jani Nikula48af6062016-05-26 14:56:05 +03002593 $state = STATE_NORMAL;
2594 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595}
2596
Jason Baron56afb0f2009-04-30 13:29:36 -04002597sub tracepoint_munge($) {
2598 my $file = shift;
2599 my $tracepointname = 0;
2600 my $tracepointargs = 0;
2601
Jason Baron3a9089f2009-12-01 12:18:49 -05002602 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002603 $tracepointname = $1;
2604 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002605 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2606 $tracepointname = $1;
2607 }
2608 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2609 $tracepointname = $2;
2610 }
2611 $tracepointname =~ s/^\s+//; #strip leading whitespace
2612 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002613 $tracepointargs = $1;
2614 }
2615 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002616 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002617 "$prototype\n";
2618 } else {
2619 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2620 }
2621}
2622
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002623sub syscall_munge() {
2624 my $void = 0;
2625
2626 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2627## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2628 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2629 $void = 1;
2630## $prototype = "long sys_$1(void)";
2631 }
2632
2633 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2634 if ($prototype =~ m/long (sys_.*?),/) {
2635 $prototype =~ s/,/\(/;
2636 } elsif ($void) {
2637 $prototype =~ s/\)/\(void\)/;
2638 }
2639
2640 # now delete all of the odd-number commas in $prototype
2641 # so that arg types & arg names don't have a comma between them
2642 my $count = 0;
2643 my $len = length($prototype);
2644 if ($void) {
2645 $len = 0; # skip the for-loop
2646 }
2647 for (my $ix = 0; $ix < $len; $ix++) {
2648 if (substr($prototype, $ix, 1) eq ',') {
2649 $count++;
2650 if ($count % 2 == 1) {
2651 substr($prototype, $ix, 1) = ' ';
2652 }
2653 }
2654 }
2655}
2656
Daniel Vetterb7afa922016-06-01 23:46:24 +02002657sub process_proto_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 my $x = shift;
2659 my $file = shift;
2660
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002661 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2662
Randy Dunlap890c78c2008-10-25 17:06:43 -07002663 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 # do nothing
2665 }
2666 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002667 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002669
Randy Dunlap890c78c2008-10-25 17:06:43 -07002670 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002671 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2673 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002674 if ($prototype =~ /SYSCALL_DEFINE/) {
2675 syscall_munge();
2676 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002677 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2678 $prototype =~ /DEFINE_SINGLE_EVENT/)
2679 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002680 tracepoint_munge($file);
2681 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002682 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 reset_state();
2684 }
2685}
2686
Daniel Vetterb7afa922016-06-01 23:46:24 +02002687sub process_proto_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 my $x = shift;
2689 my $file = shift;
2690
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2692 $x =~ s@^\s+@@gos; # strip leading spaces
2693 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002694 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2695
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 if ($x =~ /^#/) {
2697 # To distinguish preprocessor directive from regular declaration later.
2698 $x .= ";";
2699 }
2700
2701 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002702 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 $prototype .= $1 . $2;
2704 ($2 eq '{') && $brcount++;
2705 ($2 eq '}') && $brcount--;
2706 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002707 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002709 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 }
2711 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002712 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 $prototype .= $x;
2714 last;
2715 }
2716 }
2717}
2718
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002719# xml_escape: replace <, >, and & in the text stream;
2720#
2721# however, formatting controls that are generated internally/locally in the
2722# kernel-doc script are not escaped here; instead, they begin life like
2723# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2724# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2725# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726sub xml_escape($) {
2727 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002728 if (($output_mode eq "text") || ($output_mode eq "man")) {
2729 return $text;
2730 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 $text =~ s/\&/\\\\\\amp;/g;
2732 $text =~ s/\</\\\\\\lt;/g;
2733 $text =~ s/\>/\\\\\\gt;/g;
2734 return $text;
2735}
2736
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002737# xml_unescape: reverse the effects of xml_escape
2738sub xml_unescape($) {
2739 my $text = shift;
2740 if (($output_mode eq "text") || ($output_mode eq "man")) {
2741 return $text;
2742 }
2743 $text =~ s/\\\\\\amp;/\&/g;
2744 $text =~ s/\\\\\\lt;/</g;
2745 $text =~ s/\\\\\\gt;/>/g;
2746 return $text;
2747}
2748
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002749# convert local escape strings to html
2750# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2751sub local_unescape($) {
2752 my $text = shift;
2753 if (($output_mode eq "text") || ($output_mode eq "man")) {
2754 return $text;
2755 }
2756 $text =~ s/\\\\\\\\lt:/</g;
2757 $text =~ s/\\\\\\\\gt:/>/g;
2758 return $text;
2759}
2760
Jani Nikula1ad560e2016-06-07 10:53:39 +03002761sub map_filename($) {
2762 my $file;
2763 my ($orig_file) = @_;
2764
2765 if (defined($ENV{'SRCTREE'})) {
2766 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
2767 } else {
2768 $file = $orig_file;
2769 }
2770
2771 if (defined($source_map{$file})) {
2772 $file = $source_map{$file};
2773 }
2774
2775 return $file;
2776}
2777
Jani Nikula88c2b572016-06-07 11:00:52 +03002778sub process_export_file($) {
2779 my ($orig_file) = @_;
2780 my $file = map_filename($orig_file);
2781
2782 if (!open(IN,"<$file")) {
2783 print STDERR "Error: Cannot open file $file\n";
2784 ++$errors;
2785 return;
2786 }
2787
2788 while (<IN>) {
2789 if (/$export_symbol/) {
2790 $function_table{$2} = 1;
2791 }
2792 }
2793
2794 close(IN);
2795}
2796
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002798 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 my $identifier;
2800 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002801 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002802 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002804 my ($orig_file) = @_;
Jani Nikulab7886de2016-05-28 00:41:50 +03002805 my $leading_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806
Jani Nikula1ad560e2016-06-07 10:53:39 +03002807 $file = map_filename($orig_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808
2809 if (!open(IN,"<$file")) {
2810 print STDERR "Error: Cannot open file $file\n";
2811 ++$errors;
2812 return;
2813 }
2814
Ilya Dryomova9e73142010-02-26 13:05:47 -08002815 $. = 1;
2816
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 $section_counter = 0;
2818 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002819 while (s/\\\s*$//) {
2820 $_ .= <IN>;
2821 }
Jani Nikula48af6062016-05-26 14:56:05 +03002822 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002824 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002825 $in_doc_sect = 0;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002826 $declaration_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 }
Jani Nikula48af6062016-05-26 14:56:05 +03002828 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002830 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 $contents = "";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002832 $new_start_line = $. + 1;
2833
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 if ( $1 eq "" ) {
2835 $section = $section_intro;
2836 } else {
2837 $section = $1;
2838 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002839 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 elsif (/$doc_decl/o) {
2841 $identifier = $1;
2842 if (/\s*([\w\s]+?)\s*-/) {
2843 $identifier = $1;
2844 }
2845
Jani Nikula48af6062016-05-26 14:56:05 +03002846 $state = STATE_FIELD;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002847 # if there's no @param blocks need to set up default section
2848 # here
Jani Nikula2f4ad402016-05-30 11:21:06 +03002849 $contents = "";
2850 $section = $section_default;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002851 $new_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002853 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002854 $descr= $1;
2855 $descr =~ s/^\s*//;
2856 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002857 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002858 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002859 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 } else {
2861 $declaration_purpose = "";
2862 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002863
2864 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002865 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002866 print STDERR $_;
2867 ++$warnings;
2868 }
2869
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 if ($identifier =~ m/^struct/) {
2871 $decl_type = 'struct';
2872 } elsif ($identifier =~ m/^union/) {
2873 $decl_type = 'union';
2874 } elsif ($identifier =~ m/^enum/) {
2875 $decl_type = 'enum';
2876 } elsif ($identifier =~ m/^typedef/) {
2877 $decl_type = 'typedef';
2878 } else {
2879 $decl_type = 'function';
2880 }
2881
2882 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002883 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 }
2885 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002886 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 " - I thought it was a doc line\n";
2888 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002889 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 }
Jani Nikula48af6062016-05-26 14:56:05 +03002891 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Jani Nikulaf624ade2016-05-29 11:35:28 +03002892 if (/$doc_sect/i) { # case insensitive for supported section names
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 $newsection = $1;
2894 $newcontents = $2;
2895
Jani Nikulaf624ade2016-05-29 11:35:28 +03002896 # map the supported section names to the canonical names
2897 if ($newsection =~ m/^description$/i) {
2898 $newsection = $section_default;
2899 } elsif ($newsection =~ m/^context$/i) {
2900 $newsection = $section_context;
2901 } elsif ($newsection =~ m/^returns?$/i) {
2902 $newsection = $section_return;
2903 } elsif ($newsection =~ m/^\@return$/) {
2904 # special: @return is a section, not a param description
2905 $newsection = $section_return;
2906 }
2907
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002908 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002909 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002910 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002911 ++$warnings;
2912 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002913 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 $section = $section_default;
2915 }
2916
Randy Dunlap850622d2006-06-25 05:48:55 -07002917 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002918 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 $contents = $newcontents;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002920 $new_start_line = $.;
Jani Nikula0a726302016-05-28 14:50:20 +03002921 while ((substr($contents, 0, 1) eq " ") ||
2922 substr($contents, 0, 1) eq "\t") {
2923 $contents = substr($contents, 1);
2924 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 if ($contents ne "") {
2926 $contents .= "\n";
2927 }
2928 $section = $newsection;
Jani Nikulab7886de2016-05-28 00:41:50 +03002929 $leading_space = undef;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002931 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002932 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 $section = $section_default;
2934 $contents = "";
2935 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002936 # look for doc_com + <text> + doc_end:
2937 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002938 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002939 ++$warnings;
2940 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941
2942 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002943 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002945# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 } elsif (/$doc_content/) {
2947 # miguel-style comment kludge, look for blank lines after
2948 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002949 if ($1 eq "") {
2950 if ($section =~ m/^@/ || $section eq $section_context) {
2951 dump_section($file, $section, xml_escape($contents));
2952 $section = $section_default;
2953 $contents = "";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002954 $new_start_line = $.;
Johannes Weiner64231332009-09-17 19:26:53 -07002955 } else {
2956 $contents .= "\n";
2957 }
2958 $in_purpose = 0;
2959 } elsif ($in_purpose == 1) {
2960 # Continued declaration purpose
2961 chomp($declaration_purpose);
2962 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002963 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 } else {
Jani Nikulab7886de2016-05-28 00:41:50 +03002965 my $cont = $1;
2966 if ($section =~ m/^@/ || $section eq $section_context) {
2967 if (!defined $leading_space) {
2968 if ($cont =~ m/^(\s+)/) {
2969 $leading_space = $1;
2970 } else {
2971 $leading_space = "";
2972 }
2973 }
2974
2975 $cont =~ s/^$leading_space//;
2976 }
2977 $contents .= $cont . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 }
2979 } else {
2980 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002981 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 ++$warnings;
2983 }
Jani Nikula48af6062016-05-26 14:56:05 +03002984 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002985 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03002986 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002987 $section = $1;
2988 $contents = $2;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002989 $new_start_line = $.;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002990 if ($contents ne "") {
2991 while ((substr($contents, 0, 1) eq " ") ||
2992 substr($contents, 0, 1) eq "\t") {
2993 $contents = substr($contents, 1);
2994 }
Jani Nikulaa0b96c22016-05-26 22:04:06 +03002995 $contents .= "\n";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002996 }
Jani Nikula48af6062016-05-26 14:56:05 +03002997 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002998 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03002999 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003000 if (($contents ne "") && ($contents ne "\n")) {
3001 dump_section($file, $section, xml_escape($contents));
3002 $section = $section_default;
3003 $contents = "";
3004 }
Jani Nikula48af6062016-05-26 14:56:05 +03003005 $state = STATE_PROTO;
3006 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003007 # Regular text
3008 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03003009 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003010 $contents .= $1 . "\n";
Jani Nikula6450c892016-05-26 22:04:42 +03003011 # nuke leading blank lines
3012 if ($contents =~ /^\s*$/) {
3013 $contents = "";
3014 }
Jani Nikula48af6062016-05-26 14:56:05 +03003015 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
3016 $inline_doc_state = STATE_INLINE_ERROR;
Daniel Vettere7ca3112016-07-15 10:19:30 +02003017 print STDERR "${file}:$.: warning: ";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003018 print STDERR "Incorrect use of kernel-doc format: $_";
3019 ++$warnings;
3020 }
3021 }
Jani Nikula48af6062016-05-26 14:56:05 +03003022 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
3023 if (/$doc_inline_start/) {
3024 $state = STATE_INLINE;
3025 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003026 } elsif ($decl_type eq 'function') {
Daniel Vetterb7afa922016-06-01 23:46:24 +02003027 process_proto_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 } else {
Daniel Vetterb7afa922016-06-01 23:46:24 +02003029 process_proto_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 }
Jani Nikula48af6062016-05-26 14:56:05 +03003031 } elsif ($state == STATE_DOCBLOCK) {
Daniel Vetterebff7f92016-06-01 23:46:23 +02003032 if (/$doc_end/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07003034 dump_doc_section($file, $section, xml_escape($contents));
Jani Nikula2f4ad402016-05-30 11:21:06 +03003035 $section = $section_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 $contents = "";
3037 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 %parameterdescs = ();
3039 %parametertypes = ();
3040 @parameterlist = ();
3041 %sections = ();
3042 @sectionlist = ();
3043 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03003044 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 }
3046 elsif (/$doc_content/)
3047 {
3048 if ( $1 eq "" )
3049 {
3050 $contents .= $blankline;
3051 }
3052 else
3053 {
3054 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08003055 }
Randy Dunlap3c308792007-05-08 00:24:39 -07003056 }
3057 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 }
3059 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07003060 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03003061 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08003062 print STDERR " Was looking for '$_'.\n" for keys %function_table;
3063 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 if ($output_mode eq "xml") {
3065 # The template wants at least one RefEntry here; make one.
3066 print "<refentry>\n";
3067 print " <refnamediv>\n";
3068 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003069 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 print " </refname>\n";
3071 print " <refpurpose>\n";
3072 print " Document generation inconsistency\n";
3073 print " </refpurpose>\n";
3074 print " </refnamediv>\n";
3075 print " <refsect1>\n";
3076 print " <title>\n";
3077 print " Oops\n";
3078 print " </title>\n";
3079 print " <warning>\n";
3080 print " <para>\n";
3081 print " The template for this document tried to insert\n";
3082 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003083 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 print " but none was found.\n";
3085 print " This dummy section is inserted to allow\n";
3086 print " generation to continue.\n";
3087 print " </para>\n";
3088 print " </warning>\n";
3089 print " </refsect1>\n";
3090 print "</refentry>\n";
3091 }
3092 }
3093}
Randy Dunlap8484baa2011-01-05 16:28:43 -08003094
3095
3096$kernelversion = get_kernel_version();
3097
3098# generate a sequence of code that will splice in highlighting information
3099# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02003100for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03003101 my $pattern = $highlights[$k][0];
3102 my $result = $highlights[$k][1];
3103# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
3104 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08003105}
3106
3107# Read the file that maps relative names to absolute names for
3108# separate source and object directories and for shadow trees.
3109if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3110 my ($relname, $absname);
3111 while(<SOURCE_MAP>) {
3112 chop();
3113 ($relname, $absname) = (split())[0..1];
3114 $relname =~ s:^/+::;
3115 $source_map{$relname} = $absname;
3116 }
3117 close(SOURCE_MAP);
3118}
3119
Jani Nikula88c2b572016-06-07 11:00:52 +03003120if ($output_selection == OUTPUT_EXPORTED ||
3121 $output_selection == OUTPUT_INTERNAL) {
Jani Nikulac9b2cfb2016-06-07 11:05:53 +03003122
3123 push(@export_file_list, @ARGV);
3124
Jani Nikula88c2b572016-06-07 11:00:52 +03003125 foreach (@export_file_list) {
3126 chomp;
3127 process_export_file($_);
3128 }
3129}
3130
Randy Dunlap8484baa2011-01-05 16:28:43 -08003131foreach (@ARGV) {
3132 chomp;
3133 process_file($_);
3134}
3135if ($verbose && $errors) {
3136 print STDERR "$errors errors\n";
3137}
3138if ($verbose && $warnings) {
3139 print STDERR "$warnings warnings\n";
3140}
3141
3142exit($errors);