blob: e10378f769f9e235db0b7f0bb53236fa368f1c62 [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 Vetter0b0f5f292016-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
Silvio Frickec950a172016-10-28 10:14:08 +0200207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208my $errors = 0;
209my $warnings = 0;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -0700210my $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212# match expressions used to find embedded type information
213my $type_constant = '\%([-_\w]+)';
214my $type_func = '(\w+)\(\)';
Silvio Frickec950a172016-10-28 10:14:08 +0200215my $type_param = '\@(\w+(\.\.\.)?)';
Jonathan Corbet5219f182016-08-24 16:31:15 -0600216my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700217my $type_struct = '\&((struct\s*)*[_\w]+)';
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700218my $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219my $type_env = '(\$\w+)';
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300220my $type_enum_full = '\&(enum)\s*([_\w]+)';
221my $type_struct_full = '\&(struct)\s*([_\w]+)';
Jani Nikula47ae7ae2016-05-26 13:57:18 +0300222my $type_typedef_full = '\&(typedef)\s*([_\w]+)';
223my $type_union_full = '\&(union)\s*([_\w]+)';
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300224my $type_member = '\&([_\w]+)((\.|->)[_\w]+)';
225my $type_member_func = $type_member . '\(\)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227# Output conversion substitutions.
228# One for each output format
229
230# these work fairly well
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300231my @highlights_html = (
232 [$type_constant, "<i>\$1</i>"],
233 [$type_func, "<b>\$1</b>"],
234 [$type_struct_xml, "<i>\$1</i>"],
235 [$type_env, "<b><i>\$1</i></b>"],
236 [$type_param, "<tt><b>\$1</b></tt>"]
237 );
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700238my $local_lt = "\\\\\\\\lt:";
239my $local_gt = "\\\\\\\\gt:";
240my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
Dan Luedtke1b40c192012-08-12 10:46:15 +0200242# html version 5
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300243my @highlights_html5 = (
244 [$type_constant, "<span class=\"const\">\$1</span>"],
245 [$type_func, "<span class=\"func\">\$1</span>"],
246 [$type_struct_xml, "<span class=\"struct\">\$1</span>"],
247 [$type_env, "<span class=\"env\">\$1</span>"],
248 [$type_param, "<span class=\"param\">\$1</span>]"]
249 );
Dan Luedtke1b40c192012-08-12 10:46:15 +0200250my $blankline_html5 = $local_lt . "br /" . $local_gt;
251
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252# XML, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300253my @highlights_xml = (
254 ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
255 [$type_constant, "<constant>\$1</constant>"],
256 [$type_struct_xml, "<structname>\$1</structname>"],
257 [$type_param, "<parameter>\$1</parameter>"],
258 [$type_func, "<function>\$1</function>"],
259 [$type_env, "<envar>\$1</envar>"]
260 );
Johannes Berg5c98fc02007-10-24 15:08:48 -0700261my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263# gnome, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300264my @highlights_gnome = (
265 [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
266 [$type_func, "<function>\$1</function>"],
267 [$type_struct, "<structname>\$1</structname>"],
268 [$type_env, "<envar>\$1</envar>"],
269 [$type_param, "<parameter>\$1</parameter>" ]
270 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271my $blankline_gnome = "</para><para>\n";
272
273# these are pretty rough
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300274my @highlights_man = (
275 [$type_constant, "\$1"],
276 [$type_func, "\\\\fB\$1\\\\fP"],
277 [$type_struct, "\\\\fI\$1\\\\fP"],
278 [$type_param, "\\\\fI\$1\\\\fP"]
279 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280my $blankline_man = "";
281
282# text-mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300283my @highlights_text = (
284 [$type_constant, "\$1"],
285 [$type_func, "\$1"],
286 [$type_struct, "\$1"],
287 [$type_param, "\$1"]
288 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289my $blankline_text = "";
290
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300291# rst-mode
292my @highlights_rst = (
293 [$type_constant, "``\$1``"],
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300294 # Note: need to escape () to avoid func matching later
295 [$type_member_func, "\\:c\\:type\\:`\$1\$2\\\\(\\\\) <\$1>`"],
296 [$type_member, "\\:c\\:type\\:`\$1\$2 <\$1>`"],
Jonathan Corbet5219f182016-08-24 16:31:15 -0600297 [$type_fp_param, "**\$1\\\\(\\\\)**"],
Jani Nikulaa19bce62016-05-26 11:28:16 +0300298 [$type_func, "\\:c\\:func\\:`\$1()`"],
Jani Nikula62850972016-05-12 16:15:38 +0300299 [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
300 [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
Jani Nikula47ae7ae2016-05-26 13:57:18 +0300301 [$type_typedef_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
302 [$type_union_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
Jani Nikulaa7291e72016-05-26 13:57:06 +0300303 # in rst this can refer to any type
304 [$type_struct, "\\:c\\:type\\:`\$1`"],
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300305 [$type_param, "**\$1**"]
306 );
307my $blankline_rst = "\n";
308
Johannes Bergeda603f2010-09-11 15:55:22 -0700309# list mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300310my @highlights_list = (
311 [$type_constant, "\$1"],
312 [$type_func, "\$1"],
313 [$type_struct, "\$1"],
314 [$type_param, "\$1"]
315 );
Johannes Bergeda603f2010-09-11 15:55:22 -0700316my $blankline_list = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318# read arguments
Randy Dunlapb9d973282009-06-09 08:50:38 -0700319if ($#ARGV == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 usage();
321}
322
Randy Dunlap8484baa2011-01-05 16:28:43 -0800323my $kernelversion;
324my $dohighlight = "";
325
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326my $verbose = 0;
327my $output_mode = "man";
Daniel Santose314ba32012-10-04 17:15:08 -0700328my $output_preformatted = 0;
Johannes Berg4b445952007-10-24 15:08:48 -0700329my $no_doc_sections = 0;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200330my $enable_lineno = 0;
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300331my @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332my $blankline = $blankline_man;
333my $modulename = "Kernel API";
Jani Nikulab6c3f452016-05-29 22:19:35 +0300334
335use constant {
336 OUTPUT_ALL => 0, # output all symbols and doc sections
337 OUTPUT_INCLUDE => 1, # output only specified symbols
338 OUTPUT_EXCLUDE => 2, # output everything except specified symbols
339 OUTPUT_EXPORTED => 3, # output exported symbols
340 OUTPUT_INTERNAL => 4, # output non-exported symbols
341};
342my $output_selection = OUTPUT_ALL;
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100343my $show_not_found = 0;
344
Jani Nikula88c2b572016-06-07 11:00:52 +0300345my @export_file_list;
346
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100347my @build_time;
348if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
349 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
350 @build_time = gmtime($seconds);
351} else {
352 @build_time = localtime;
353}
354
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800355my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
356 'July', 'August', 'September', 'October',
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100357 'November', 'December')[$build_time[4]] .
358 " " . ($build_time[5]+1900);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Randy Dunlap8484baa2011-01-05 16:28:43 -0800360# Essentially these are globals.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700361# They probably want to be tidied up, made more localised or something.
362# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363# could cause "use of undefined value" or other bugs.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700364my ($function, %function_table, %parametertypes, $declaration_purpose);
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200365my $declaration_start_line;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700366my ($type, $declaration_name, $return_type);
Ilya Dryomov1c32fd02010-02-26 13:06:03 -0800367my ($newsection, $newcontents, $prototype, $brcount, %source_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700369if (defined($ENV{'KBUILD_VERBOSE'})) {
370 $verbose = "$ENV{'KBUILD_VERBOSE'}";
371}
372
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800373# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
375# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
376# We keep track of number of generated entries and generate a dummy
377# if needs be to ensure the expanded template can be postprocessed
378# into html.
379my $section_counter = 0;
380
381my $lineprefix="";
382
Jani Nikula48af6062016-05-26 14:56:05 +0300383# Parser states
384use constant {
385 STATE_NORMAL => 0, # normal code
386 STATE_NAME => 1, # looking for function name
387 STATE_FIELD => 2, # scanning field start
388 STATE_PROTO => 3, # scanning prototype
389 STATE_DOCBLOCK => 4, # documentation block
390 STATE_INLINE => 5, # gathering documentation outside main block
391};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700393my $in_doc_sect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Jani Nikula48af6062016-05-26 14:56:05 +0300395# Inline documentation state
396use constant {
397 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
398 STATE_INLINE_NAME => 1, # looking for member name (@foo:)
399 STATE_INLINE_TEXT => 2, # looking for member documentation
400 STATE_INLINE_END => 3, # done
401 STATE_INLINE_ERROR => 4, # error - Comment without header was found.
402 # Spit a warning as it's not
403 # proper kernel-doc and ignore the rest.
404};
405my $inline_doc_state;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407#declaration types: can be
408# 'function', 'struct', 'union', 'enum', 'typedef'
409my $decl_type;
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
412my $doc_end = '\*/';
413my $doc_com = '\s*\*\s*';
Daniel Santos12ae6772012-10-04 17:15:10 -0700414my $doc_com_body = '\s*\* ?';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700415my $doc_decl = $doc_com . '(\w+)';
Jani Nikulaf624ade2016-05-29 11:35:28 +0300416# @params and a strictly limited set of supported section names
Jonathan Corbet8569de62016-06-09 13:35:05 -0600417my $doc_sect = $doc_com .
Jonathan Corbetef000282016-08-26 07:14:08 -0600418 '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700419my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700420my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Jani Nikula48af6062016-05-26 14:56:05 +0300421my $doc_inline_start = '^\s*/\*\*\s*$';
422my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
423my $doc_inline_end = '^\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200424my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426my %parameterdescs;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200427my %parameterdesc_start_lines;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428my @parameterlist;
429my %sections;
430my @sectionlist;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200431my %section_start_lines;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800432my $sectcheck;
433my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
435my $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200436my $new_start_line = 0;
Jani Nikulaf624ade2016-05-29 11:35:28 +0300437
438# the canonical section names. see also $doc_sect above.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439my $section_default = "Description"; # default section
440my $section_intro = "Introduction";
441my $section = $section_default;
442my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100443my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
445my $undescribed = "-- undescribed --";
446
447reset_state();
448
449while ($ARGV[0] =~ m/^-(.*)/) {
450 my $cmd = shift @ARGV;
451 if ($cmd eq "-html") {
452 $output_mode = "html";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300453 @highlights = @highlights_html;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200455 } elsif ($cmd eq "-html5") {
456 $output_mode = "html5";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300457 @highlights = @highlights_html5;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200458 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 } elsif ($cmd eq "-man") {
460 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300461 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 $blankline = $blankline_man;
463 } elsif ($cmd eq "-text") {
464 $output_mode = "text";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300465 @highlights = @highlights_text;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 $blankline = $blankline_text;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300467 } elsif ($cmd eq "-rst") {
468 $output_mode = "rst";
469 @highlights = @highlights_rst;
470 $blankline = $blankline_rst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 } elsif ($cmd eq "-docbook") {
472 $output_mode = "xml";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300473 @highlights = @highlights_xml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700475 } elsif ($cmd eq "-list") {
476 $output_mode = "list";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300477 @highlights = @highlights_list;
Johannes Bergeda603f2010-09-11 15:55:22 -0700478 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 } elsif ($cmd eq "-gnome") {
480 $output_mode = "gnome";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300481 @highlights = @highlights_gnome;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 $blankline = $blankline_gnome;
483 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
484 $modulename = shift @ARGV;
485 } elsif ($cmd eq "-function") { # to only output specific functions
Jani Nikulab6c3f452016-05-29 22:19:35 +0300486 $output_selection = OUTPUT_INCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 $function = shift @ARGV;
488 $function_table{$function} = 1;
Jani Nikulab6c3f452016-05-29 22:19:35 +0300489 } elsif ($cmd eq "-nofunction") { # output all except specific functions
490 $output_selection = OUTPUT_EXCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 $function = shift @ARGV;
492 $function_table{$function} = 1;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200493 } elsif ($cmd eq "-export") { # only exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300494 $output_selection = OUTPUT_EXPORTED;
Jani Nikulada9726e2016-06-07 10:29:59 +0300495 %function_table = ();
Jani Nikula86ae2e32016-01-21 13:05:22 +0200496 } elsif ($cmd eq "-internal") { # only non-exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300497 $output_selection = OUTPUT_INTERNAL;
Jani Nikulada9726e2016-06-07 10:29:59 +0300498 %function_table = ();
Jani Nikula88c2b572016-06-07 11:00:52 +0300499 } elsif ($cmd eq "-export-file") {
500 my $file = shift @ARGV;
501 push(@export_file_list, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 } elsif ($cmd eq "-v") {
503 $verbose = 1;
504 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
505 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700506 } elsif ($cmd eq '-no-doc-sections') {
507 $no_doc_sections = 1;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200508 } elsif ($cmd eq '-enable-lineno') {
509 $enable_lineno = 1;
Johannes Berge946c43a2013-11-12 15:11:12 -0800510 } elsif ($cmd eq '-show-not-found') {
511 $show_not_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 }
513}
514
Randy Dunlap8484baa2011-01-05 16:28:43 -0800515# continue execution near EOF;
516
Borislav Petkov53f049f2007-05-08 00:30:54 -0700517# get kernel version from env
518sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700519 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700520
521 if (defined($ENV{'KERNELVERSION'})) {
522 $version = $ENV{'KERNELVERSION'};
523 }
524 return $version;
525}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200527#
528sub print_lineno {
529 my $lineno = shift;
530 if ($enable_lineno && defined($lineno)) {
531 print "#define LINENO " . $lineno . "\n";
532 }
533}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534##
535# dumps section contents to arrays/hashes intended for that purpose.
536#
537sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700538 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 my $name = shift;
540 my $contents = join "\n", @_;
541
Jani Nikula13901ef2016-05-26 08:57:29 +0300542 if ($name =~ m/$type_param/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 $name = $1;
544 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800545 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200546 $parameterdesc_start_lines{$name} = $new_start_line;
547 $new_start_line = 0;
Randy Dunlapced69092008-12-01 13:14:03 -0800548 } elsif ($name eq "@\.\.\.") {
Randy Dunlapced69092008-12-01 13:14:03 -0800549 $name = "...";
550 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800551 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200552 $parameterdesc_start_lines{$name} = $new_start_line;
553 $new_start_line = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 } else {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700555 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Jani Nikula95b6be92016-06-10 11:14:05 +0300556 # Only warn on user specified duplicate section names.
557 if ($name ne $section_default) {
558 print STDERR "${file}:$.: warning: duplicate section name '$name'\n";
559 ++$warnings;
560 }
Jani Nikula32217762016-05-29 09:40:44 +0300561 $sections{$name} .= $contents;
562 } else {
563 $sections{$name} = $contents;
564 push @sectionlist, $name;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200565 $section_start_lines{$name} = $new_start_line;
566 $new_start_line = 0;
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700567 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 }
569}
570
571##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700572# dump DOC: section after checking that it should go out
573#
574sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700575 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700576 my $name = shift;
577 my $contents = join "\n", @_;
578
Johannes Berg4b445952007-10-24 15:08:48 -0700579 if ($no_doc_sections) {
580 return;
581 }
582
Jani Nikulab6c3f452016-05-29 22:19:35 +0300583 if (($output_selection == OUTPUT_ALL) ||
584 ($output_selection == OUTPUT_INCLUDE &&
585 defined($function_table{$name})) ||
586 ($output_selection == OUTPUT_EXCLUDE &&
587 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700588 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700589 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700590 output_blockhead({'sectionlist' => \@sectionlist,
591 'sections' => \%sections,
592 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300593 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700594 }
595}
596
597##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598# output function
599#
600# parameterdescs, a hash.
601# function => "function name"
602# parameterlist => @list of parameters
603# parameterdescs => %parameter descriptions
604# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800605# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800606#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
608sub output_highlight {
609 my $contents = join "\n",@_;
610 my $line;
611
612# DEBUG
613# if (!defined $contents) {
614# use Carp;
615# confess "output_highlight got called with no args?\n";
616# }
617
Dan Luedtke1b40c192012-08-12 10:46:15 +0200618 if ($output_mode eq "html" || $output_mode eq "html5" ||
619 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700620 $contents = local_unescape($contents);
621 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800622 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700623 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700624# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 eval $dohighlight;
626 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700627# print STDERR "contents af:$contents\n";
628
Dan Luedtke1b40c192012-08-12 10:46:15 +0200629# strip whitespaces when generating html5
630 if ($output_mode eq "html5") {
631 $contents =~ s/^\s+//;
632 $contents =~ s/\s+$//;
633 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700635 if (! $output_preformatted) {
636 $line =~ s/^\s*//;
637 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700638 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700639 if (! $output_preformatted) {
640 print $lineprefix, local_unescape($blankline);
641 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700643 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700644 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
645 print "\\&$line";
646 } else {
647 print $lineprefix, $line;
648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
650 print "\n";
651 }
652}
653
Dan Luedtke1b40c192012-08-12 10:46:15 +0200654# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655sub output_section_html(%) {
656 my %args = %{$_[0]};
657 my $section;
658
659 foreach $section (@{$args{'sectionlist'}}) {
660 print "<h3>$section</h3>\n";
661 print "<blockquote>\n";
662 output_highlight($args{'sections'}{$section});
663 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800664 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665}
666
667# output enum in html
668sub output_enum_html(%) {
669 my %args = %{$_[0]};
670 my ($parameter);
671 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700672 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Randy Dunlapb9d973282009-06-09 08:50:38 -0700674 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 $count = 0;
676 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700677 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 if ($count != $#{$args{'parameterlist'}}) {
679 $count++;
680 print ",\n";
681 }
682 print "<br>";
683 }
684 print "};<br>\n";
685
686 print "<h3>Constants</h3>\n";
687 print "<dl>\n";
688 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700689 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 print "<dd>";
691 output_highlight($args{'parameterdescs'}{$parameter});
692 }
693 print "</dl>\n";
694 output_section_html(@_);
695 print "<hr>\n";
696}
697
Randy Dunlapd28bee02006-02-01 03:06:57 -0800698# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699sub output_typedef_html(%) {
700 my %args = %{$_[0]};
701 my ($parameter);
702 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700703 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Randy Dunlapb9d973282009-06-09 08:50:38 -0700705 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 output_section_html(@_);
707 print "<hr>\n";
708}
709
710# output struct in html
711sub output_struct_html(%) {
712 my %args = %{$_[0]};
713 my ($parameter);
714
Randy Dunlapb9d973282009-06-09 08:50:38 -0700715 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
716 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 foreach $parameter (@{$args{'parameterlist'}}) {
718 if ($parameter =~ /^#/) {
719 print "$parameter<br>\n";
720 next;
721 }
722 my $parameter_name = $parameter;
723 $parameter_name =~ s/\[.*//;
724
Randy Dunlap3c308792007-05-08 00:24:39 -0700725 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 $type = $args{'parametertypes'}{$parameter};
727 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
728 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700729 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700731 # bitfield
732 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700734 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 }
736 }
737 print "};<br>\n";
738
739 print "<h3>Members</h3>\n";
740 print "<dl>\n";
741 foreach $parameter (@{$args{'parameterlist'}}) {
742 ($parameter =~ /^#/) && next;
743
744 my $parameter_name = $parameter;
745 $parameter_name =~ s/\[.*//;
746
Randy Dunlap3c308792007-05-08 00:24:39 -0700747 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700748 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 print "<dd>";
750 output_highlight($args{'parameterdescs'}{$parameter_name});
751 }
752 print "</dl>\n";
753 output_section_html(@_);
754 print "<hr>\n";
755}
756
757# output function in html
758sub output_function_html(%) {
759 my %args = %{$_[0]};
760 my ($parameter, $section);
761 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
Randy Dunlapb9d973282009-06-09 08:50:38 -0700763 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
764 print "<i>" . $args{'functiontype'} . "</i>\n";
765 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766 print "(";
767 $count = 0;
768 foreach $parameter (@{$args{'parameterlist'}}) {
769 $type = $args{'parametertypes'}{$parameter};
770 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
771 # pointer-to-function
772 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
773 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700774 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 }
776 if ($count != $#{$args{'parameterlist'}}) {
777 $count++;
778 print ",\n";
779 }
780 }
781 print ")\n";
782
783 print "<h3>Arguments</h3>\n";
784 print "<dl>\n";
785 foreach $parameter (@{$args{'parameterlist'}}) {
786 my $parameter_name = $parameter;
787 $parameter_name =~ s/\[.*//;
788
Randy Dunlap3c308792007-05-08 00:24:39 -0700789 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700790 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 print "<dd>";
792 output_highlight($args{'parameterdescs'}{$parameter_name});
793 }
794 print "</dl>\n";
795 output_section_html(@_);
796 print "<hr>\n";
797}
798
Johannes Bergb112e0f2007-10-24 15:08:48 -0700799# output DOC: block header in html
800sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801 my %args = %{$_[0]};
802 my ($parameter, $section);
803 my $count;
804
805 foreach $section (@{$args{'sectionlist'}}) {
806 print "<h3>$section</h3>\n";
807 print "<ul>\n";
808 output_highlight($args{'sections'}{$section});
809 print "</ul>\n";
810 }
811 print "<hr>\n";
812}
813
Dan Luedtke1b40c192012-08-12 10:46:15 +0200814# output sections in html5
815sub output_section_html5(%) {
816 my %args = %{$_[0]};
817 my $section;
818
819 foreach $section (@{$args{'sectionlist'}}) {
820 print "<section>\n";
821 print "<h1>$section</h1>\n";
822 print "<p>\n";
823 output_highlight($args{'sections'}{$section});
824 print "</p>\n";
825 print "</section>\n";
826 }
827}
828
829# output enum in html5
830sub output_enum_html5(%) {
831 my %args = %{$_[0]};
832 my ($parameter);
833 my $count;
834 my $html5id;
835
836 $html5id = $args{'enum'};
837 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
838 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
839 print "<h1>enum " . $args{'enum'} . "</h1>\n";
840 print "<ol class=\"code\">\n";
841 print "<li>";
842 print "<span class=\"keyword\">enum</span> ";
843 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
844 print "</li>\n";
845 $count = 0;
846 foreach $parameter (@{$args{'parameterlist'}}) {
847 print "<li class=\"indent\">";
848 print "<span class=\"param\">" . $parameter . "</span>";
849 if ($count != $#{$args{'parameterlist'}}) {
850 $count++;
851 print ",";
852 }
853 print "</li>\n";
854 }
855 print "<li>};</li>\n";
856 print "</ol>\n";
857
858 print "<section>\n";
859 print "<h1>Constants</h1>\n";
860 print "<dl>\n";
861 foreach $parameter (@{$args{'parameterlist'}}) {
862 print "<dt>" . $parameter . "</dt>\n";
863 print "<dd>";
864 output_highlight($args{'parameterdescs'}{$parameter});
865 print "</dd>\n";
866 }
867 print "</dl>\n";
868 print "</section>\n";
869 output_section_html5(@_);
870 print "</article>\n";
871}
872
873# output typedef in html5
874sub output_typedef_html5(%) {
875 my %args = %{$_[0]};
876 my ($parameter);
877 my $count;
878 my $html5id;
879
880 $html5id = $args{'typedef'};
881 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
882 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
883 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
884
885 print "<ol class=\"code\">\n";
886 print "<li>";
887 print "<span class=\"keyword\">typedef</span> ";
888 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
889 print "</li>\n";
890 print "</ol>\n";
891 output_section_html5(@_);
892 print "</article>\n";
893}
894
895# output struct in html5
896sub output_struct_html5(%) {
897 my %args = %{$_[0]};
898 my ($parameter);
899 my $html5id;
900
901 $html5id = $args{'struct'};
902 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
903 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
904 print "<hgroup>\n";
905 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
906 print "<h2>". $args{'purpose'} . "</h2>\n";
907 print "</hgroup>\n";
908 print "<ol class=\"code\">\n";
909 print "<li>";
910 print "<span class=\"type\">" . $args{'type'} . "</span> ";
911 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
912 print "</li>\n";
913 foreach $parameter (@{$args{'parameterlist'}}) {
914 print "<li class=\"indent\">";
915 if ($parameter =~ /^#/) {
916 print "<span class=\"param\">" . $parameter ."</span>\n";
917 print "</li>\n";
918 next;
919 }
920 my $parameter_name = $parameter;
921 $parameter_name =~ s/\[.*//;
922
923 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
924 $type = $args{'parametertypes'}{$parameter};
925 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
926 # pointer-to-function
927 print "<span class=\"type\">$1</span> ";
928 print "<span class=\"param\">$parameter</span>";
929 print "<span class=\"type\">)</span> ";
930 print "(<span class=\"args\">$2</span>);";
931 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
932 # bitfield
933 print "<span class=\"type\">$1</span> ";
934 print "<span class=\"param\">$parameter</span>";
935 print "<span class=\"bits\">$2</span>;";
936 } else {
937 print "<span class=\"type\">$type</span> ";
938 print "<span class=\"param\">$parameter</span>;";
939 }
940 print "</li>\n";
941 }
942 print "<li>};</li>\n";
943 print "</ol>\n";
944
945 print "<section>\n";
946 print "<h1>Members</h1>\n";
947 print "<dl>\n";
948 foreach $parameter (@{$args{'parameterlist'}}) {
949 ($parameter =~ /^#/) && next;
950
951 my $parameter_name = $parameter;
952 $parameter_name =~ s/\[.*//;
953
954 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
955 print "<dt>" . $parameter . "</dt>\n";
956 print "<dd>";
957 output_highlight($args{'parameterdescs'}{$parameter_name});
958 print "</dd>\n";
959 }
960 print "</dl>\n";
961 print "</section>\n";
962 output_section_html5(@_);
963 print "</article>\n";
964}
965
966# output function in html5
967sub output_function_html5(%) {
968 my %args = %{$_[0]};
969 my ($parameter, $section);
970 my $count;
971 my $html5id;
972
973 $html5id = $args{'function'};
974 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
975 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
976 print "<hgroup>\n";
977 print "<h1>" . $args{'function'} . "</h1>";
978 print "<h2>" . $args{'purpose'} . "</h2>\n";
979 print "</hgroup>\n";
980 print "<ol class=\"code\">\n";
981 print "<li>";
982 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
983 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
984 print "</li>";
985 $count = 0;
986 foreach $parameter (@{$args{'parameterlist'}}) {
987 print "<li class=\"indent\">";
988 $type = $args{'parametertypes'}{$parameter};
989 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
990 # pointer-to-function
991 print "<span class=\"type\">$1</span> ";
992 print "<span class=\"param\">$parameter</span>";
993 print "<span class=\"type\">)</span> ";
994 print "(<span class=\"args\">$2</span>)";
995 } else {
996 print "<span class=\"type\">$type</span> ";
997 print "<span class=\"param\">$parameter</span>";
998 }
999 if ($count != $#{$args{'parameterlist'}}) {
1000 $count++;
1001 print ",";
1002 }
1003 print "</li>\n";
1004 }
1005 print "<li>)</li>\n";
1006 print "</ol>\n";
1007
1008 print "<section>\n";
1009 print "<h1>Arguments</h1>\n";
1010 print "<p>\n";
1011 print "<dl>\n";
1012 foreach $parameter (@{$args{'parameterlist'}}) {
1013 my $parameter_name = $parameter;
1014 $parameter_name =~ s/\[.*//;
1015
1016 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1017 print "<dt>" . $parameter . "</dt>\n";
1018 print "<dd>";
1019 output_highlight($args{'parameterdescs'}{$parameter_name});
1020 print "</dd>\n";
1021 }
1022 print "</dl>\n";
1023 print "</section>\n";
1024 output_section_html5(@_);
1025 print "</article>\n";
1026}
1027
1028# output DOC: block header in html5
1029sub output_blockhead_html5(%) {
1030 my %args = %{$_[0]};
1031 my ($parameter, $section);
1032 my $count;
1033 my $html5id;
1034
1035 foreach $section (@{$args{'sectionlist'}}) {
1036 $html5id = $section;
1037 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1038 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1039 print "<h1>$section</h1>\n";
1040 print "<p>\n";
1041 output_highlight($args{'sections'}{$section});
1042 print "</p>\n";
1043 }
1044 print "</article>\n";
1045}
1046
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047sub output_section_xml(%) {
1048 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001049 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 # print out each section
1051 $lineprefix=" ";
1052 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001053 print "<refsect1>\n";
1054 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001056 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001057 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001058 } else {
1059 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060 }
1061 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001062 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001064 print "</programlisting></informalexample>\n";
1065 } else {
1066 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001068 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 }
1070}
1071
1072# output function in XML DocBook
1073sub output_function_xml(%) {
1074 my %args = %{$_[0]};
1075 my ($parameter, $section);
1076 my $count;
1077 my $id;
1078
Randy Dunlapb9d973282009-06-09 08:50:38 -07001079 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 $id =~ s/[^A-Za-z0-9]/-/g;
1081
Pavel Pisa5449bc92007-02-10 01:45:37 -08001082 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001083 print "<refentryinfo>\n";
1084 print " <title>LINUX</title>\n";
1085 print " <productname>Kernel Hackers Manual</productname>\n";
1086 print " <date>$man_date</date>\n";
1087 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001089 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001090 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001091 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 print "</refmeta>\n";
1093 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001094 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 print " <refpurpose>\n";
1096 print " ";
1097 output_highlight ($args{'purpose'});
1098 print " </refpurpose>\n";
1099 print "</refnamediv>\n";
1100
1101 print "<refsynopsisdiv>\n";
1102 print " <title>Synopsis</title>\n";
1103 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001104 print " <funcdef>" . $args{'functiontype'} . " ";
1105 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
1107 $count = 0;
1108 if ($#{$args{'parameterlist'}} >= 0) {
1109 foreach $parameter (@{$args{'parameterlist'}}) {
1110 $type = $args{'parametertypes'}{$parameter};
1111 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1112 # pointer-to-function
1113 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1114 print " <funcparams>$2</funcparams></paramdef>\n";
1115 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001116 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 print " <parameter>$parameter</parameter></paramdef>\n";
1118 }
1119 }
1120 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001121 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122 }
1123 print " </funcprototype></funcsynopsis>\n";
1124 print "</refsynopsisdiv>\n";
1125
1126 # print parameters
1127 print "<refsect1>\n <title>Arguments</title>\n";
1128 if ($#{$args{'parameterlist'}} >= 0) {
1129 print " <variablelist>\n";
1130 foreach $parameter (@{$args{'parameterlist'}}) {
1131 my $parameter_name = $parameter;
1132 $parameter_name =~ s/\[.*//;
1133
1134 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1135 print " <listitem>\n <para>\n";
1136 $lineprefix=" ";
1137 output_highlight($args{'parameterdescs'}{$parameter_name});
1138 print " </para>\n </listitem>\n </varlistentry>\n";
1139 }
1140 print " </variablelist>\n";
1141 } else {
1142 print " <para>\n None\n </para>\n";
1143 }
1144 print "</refsect1>\n";
1145
1146 output_section_xml(@_);
1147 print "</refentry>\n\n";
1148}
1149
1150# output struct in XML DocBook
1151sub output_struct_xml(%) {
1152 my %args = %{$_[0]};
1153 my ($parameter, $section);
1154 my $id;
1155
Randy Dunlapb9d973282009-06-09 08:50:38 -07001156 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 $id =~ s/[^A-Za-z0-9]/-/g;
1158
Pavel Pisa5449bc92007-02-10 01:45:37 -08001159 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001160 print "<refentryinfo>\n";
1161 print " <title>LINUX</title>\n";
1162 print " <productname>Kernel Hackers Manual</productname>\n";
1163 print " <date>$man_date</date>\n";
1164 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001166 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001167 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001168 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 print "</refmeta>\n";
1170 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001171 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 print " <refpurpose>\n";
1173 print " ";
1174 output_highlight ($args{'purpose'});
1175 print " </refpurpose>\n";
1176 print "</refnamediv>\n";
1177
1178 print "<refsynopsisdiv>\n";
1179 print " <title>Synopsis</title>\n";
1180 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001181 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 foreach $parameter (@{$args{'parameterlist'}}) {
1183 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001184 my $prm = $parameter;
1185 # convert data read & converted thru xml_escape() into &xyz; format:
1186 # This allows us to have #define macros interspersed in a struct.
1187 $prm =~ s/\\\\\\/\&/g;
1188 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 next;
1190 }
1191
1192 my $parameter_name = $parameter;
1193 $parameter_name =~ s/\[.*//;
1194
1195 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001196 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 $type = $args{'parametertypes'}{$parameter};
1198 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1199 # pointer-to-function
1200 print " $1 $parameter) ($2);\n";
1201 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001202 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 print " $1 $parameter$2;\n";
1204 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001205 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 }
1207 }
1208 print "};";
1209 print " </programlisting>\n";
1210 print "</refsynopsisdiv>\n";
1211
1212 print " <refsect1>\n";
1213 print " <title>Members</title>\n";
1214
Randy Dunlap39f00c02008-09-22 13:57:44 -07001215 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 print " <variablelist>\n";
1217 foreach $parameter (@{$args{'parameterlist'}}) {
1218 ($parameter =~ /^#/) && next;
1219
1220 my $parameter_name = $parameter;
1221 $parameter_name =~ s/\[.*//;
1222
1223 defined($args{'parameterdescs'}{$parameter_name}) || next;
1224 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1225 print " <varlistentry>";
1226 print " <term>$parameter</term>\n";
1227 print " <listitem><para>\n";
1228 output_highlight($args{'parameterdescs'}{$parameter_name});
1229 print " </para></listitem>\n";
1230 print " </varlistentry>\n";
1231 }
1232 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001233 } else {
1234 print " <para>\n None\n </para>\n";
1235 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 print " </refsect1>\n";
1237
1238 output_section_xml(@_);
1239
1240 print "</refentry>\n\n";
1241}
1242
1243# output enum in XML DocBook
1244sub output_enum_xml(%) {
1245 my %args = %{$_[0]};
1246 my ($parameter, $section);
1247 my $count;
1248 my $id;
1249
Randy Dunlapb9d973282009-06-09 08:50:38 -07001250 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 $id =~ s/[^A-Za-z0-9]/-/g;
1252
Pavel Pisa5449bc92007-02-10 01:45:37 -08001253 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001254 print "<refentryinfo>\n";
1255 print " <title>LINUX</title>\n";
1256 print " <productname>Kernel Hackers Manual</productname>\n";
1257 print " <date>$man_date</date>\n";
1258 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001260 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001261 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001262 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 print "</refmeta>\n";
1264 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001265 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 print " <refpurpose>\n";
1267 print " ";
1268 output_highlight ($args{'purpose'});
1269 print " </refpurpose>\n";
1270 print "</refnamediv>\n";
1271
1272 print "<refsynopsisdiv>\n";
1273 print " <title>Synopsis</title>\n";
1274 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001275 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 $count = 0;
1277 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001278 print " $parameter";
1279 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 $count++;
1281 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001282 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 print "\n";
1284 }
1285 print "};";
1286 print " </programlisting>\n";
1287 print "</refsynopsisdiv>\n";
1288
1289 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001290 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 print " <variablelist>\n";
1292 foreach $parameter (@{$args{'parameterlist'}}) {
1293 my $parameter_name = $parameter;
1294 $parameter_name =~ s/\[.*//;
1295
1296 print " <varlistentry>";
1297 print " <term>$parameter</term>\n";
1298 print " <listitem><para>\n";
1299 output_highlight($args{'parameterdescs'}{$parameter_name});
1300 print " </para></listitem>\n";
1301 print " </varlistentry>\n";
1302 }
1303 print " </variablelist>\n";
1304 print "</refsect1>\n";
1305
1306 output_section_xml(@_);
1307
1308 print "</refentry>\n\n";
1309}
1310
1311# output typedef in XML DocBook
1312sub output_typedef_xml(%) {
1313 my %args = %{$_[0]};
1314 my ($parameter, $section);
1315 my $id;
1316
Randy Dunlapb9d973282009-06-09 08:50:38 -07001317 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 $id =~ s/[^A-Za-z0-9]/-/g;
1319
Pavel Pisa5449bc92007-02-10 01:45:37 -08001320 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001321 print "<refentryinfo>\n";
1322 print " <title>LINUX</title>\n";
1323 print " <productname>Kernel Hackers Manual</productname>\n";
1324 print " <date>$man_date</date>\n";
1325 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001327 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001328 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 print "</refmeta>\n";
1330 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001331 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 print " <refpurpose>\n";
1333 print " ";
1334 output_highlight ($args{'purpose'});
1335 print " </refpurpose>\n";
1336 print "</refnamediv>\n";
1337
1338 print "<refsynopsisdiv>\n";
1339 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001340 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 print "</refsynopsisdiv>\n";
1342
1343 output_section_xml(@_);
1344
1345 print "</refentry>\n\n";
1346}
1347
1348# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001349sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 my %args = %{$_[0]};
1351 my ($parameter, $section);
1352 my $count;
1353
1354 my $id = $args{'module'};
1355 $id =~ s/[^A-Za-z0-9]/-/g;
1356
1357 # print out each section
1358 $lineprefix=" ";
1359 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001360 if (!$args{'content-only'}) {
1361 print "<refsect1>\n <title>$section</title>\n";
1362 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 if ($section =~ m/EXAMPLE/i) {
1364 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001365 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001366 } else {
1367 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 }
1369 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001370 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 if ($section =~ m/EXAMPLE/i) {
1372 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001373 } else {
1374 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001376 if (!$args{'content-only'}) {
1377 print "\n</refsect1>\n";
1378 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 }
1380
1381 print "\n\n";
1382}
1383
1384# output in XML DocBook
1385sub output_function_gnome {
1386 my %args = %{$_[0]};
1387 my ($parameter, $section);
1388 my $count;
1389 my $id;
1390
Randy Dunlapb9d973282009-06-09 08:50:38 -07001391 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 $id =~ s/[^A-Za-z0-9]/-/g;
1393
1394 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001395 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
1397 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001398 print " <funcdef>" . $args{'functiontype'} . " ";
1399 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 print "</function></funcdef>\n";
1401
1402 $count = 0;
1403 if ($#{$args{'parameterlist'}} >= 0) {
1404 foreach $parameter (@{$args{'parameterlist'}}) {
1405 $type = $args{'parametertypes'}{$parameter};
1406 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1407 # pointer-to-function
1408 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1409 print " <funcparams>$2</funcparams></paramdef>\n";
1410 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001411 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 print " <parameter>$parameter</parameter></paramdef>\n";
1413 }
1414 }
1415 } else {
1416 print " <void>\n";
1417 }
1418 print " </funcsynopsis>\n";
1419 if ($#{$args{'parameterlist'}} >= 0) {
1420 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1421 print "<tgroup cols=\"2\">\n";
1422 print "<colspec colwidth=\"2*\">\n";
1423 print "<colspec colwidth=\"8*\">\n";
1424 print "<tbody>\n";
1425 foreach $parameter (@{$args{'parameterlist'}}) {
1426 my $parameter_name = $parameter;
1427 $parameter_name =~ s/\[.*//;
1428
1429 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1430 print " <entry>\n";
1431 $lineprefix=" ";
1432 output_highlight($args{'parameterdescs'}{$parameter_name});
1433 print " </entry></row>\n";
1434 }
1435 print " </tbody></tgroup></informaltable>\n";
1436 } else {
1437 print " <para>\n None\n </para>\n";
1438 }
1439
1440 # print out each section
1441 $lineprefix=" ";
1442 foreach $section (@{$args{'sectionlist'}}) {
1443 print "<simplesect>\n <title>$section</title>\n";
1444 if ($section =~ m/EXAMPLE/i) {
1445 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001446 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 } else {
1448 }
1449 print "<para>\n";
1450 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001451 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 print "</para>\n";
1453 if ($section =~ m/EXAMPLE/i) {
1454 print "</programlisting></example>\n";
1455 } else {
1456 }
1457 print " </simplesect>\n";
1458 }
1459
1460 print "</sect2>\n\n";
1461}
1462
1463##
1464# output function in man
1465sub output_function_man(%) {
1466 my %args = %{$_[0]};
1467 my ($parameter, $section);
1468 my $count;
1469
1470 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1471
1472 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001473 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
1475 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001476 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001477 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001478 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001479 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001480 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 $count = 0;
1482 my $parenth = "(";
1483 my $post = ",";
1484 foreach my $parameter (@{$args{'parameterlist'}}) {
1485 if ($count == $#{$args{'parameterlist'}}) {
1486 $post = ");";
1487 }
1488 $type = $args{'parametertypes'}{$parameter};
1489 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1490 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001491 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 } else {
1493 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001494 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 }
1496 $count++;
1497 $parenth = "";
1498 }
1499
1500 print ".SH ARGUMENTS\n";
1501 foreach $parameter (@{$args{'parameterlist'}}) {
1502 my $parameter_name = $parameter;
1503 $parameter_name =~ s/\[.*//;
1504
Randy Dunlapb9d973282009-06-09 08:50:38 -07001505 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 output_highlight($args{'parameterdescs'}{$parameter_name});
1507 }
1508 foreach $section (@{$args{'sectionlist'}}) {
1509 print ".SH \"", uc $section, "\"\n";
1510 output_highlight($args{'sections'}{$section});
1511 }
1512}
1513
1514##
1515# output enum in man
1516sub output_enum_man(%) {
1517 my %args = %{$_[0]};
1518 my ($parameter, $section);
1519 my $count;
1520
1521 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1522
1523 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001524 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
1526 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001527 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 $count = 0;
1529 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001530 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 if ($count == $#{$args{'parameterlist'}}) {
1532 print "\n};\n";
1533 last;
1534 }
1535 else {
1536 print ", \n.br\n";
1537 }
1538 $count++;
1539 }
1540
1541 print ".SH Constants\n";
1542 foreach $parameter (@{$args{'parameterlist'}}) {
1543 my $parameter_name = $parameter;
1544 $parameter_name =~ s/\[.*//;
1545
Randy Dunlapb9d973282009-06-09 08:50:38 -07001546 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 output_highlight($args{'parameterdescs'}{$parameter_name});
1548 }
1549 foreach $section (@{$args{'sectionlist'}}) {
1550 print ".SH \"$section\"\n";
1551 output_highlight($args{'sections'}{$section});
1552 }
1553}
1554
1555##
1556# output struct in man
1557sub output_struct_man(%) {
1558 my %args = %{$_[0]};
1559 my ($parameter, $section);
1560
Randy Dunlapb9d973282009-06-09 08:50:38 -07001561 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562
1563 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001564 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
1566 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001567 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
1569 foreach my $parameter (@{$args{'parameterlist'}}) {
1570 if ($parameter =~ /^#/) {
1571 print ".BI \"$parameter\"\n.br\n";
1572 next;
1573 }
1574 my $parameter_name = $parameter;
1575 $parameter_name =~ s/\[.*//;
1576
Randy Dunlap3c308792007-05-08 00:24:39 -07001577 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 $type = $args{'parametertypes'}{$parameter};
1579 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1580 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001581 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001583 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001584 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 } else {
1586 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001587 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 }
1589 print "\n.br\n";
1590 }
1591 print "};\n.br\n";
1592
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001593 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 foreach $parameter (@{$args{'parameterlist'}}) {
1595 ($parameter =~ /^#/) && next;
1596
1597 my $parameter_name = $parameter;
1598 $parameter_name =~ s/\[.*//;
1599
Randy Dunlap3c308792007-05-08 00:24:39 -07001600 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001601 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 output_highlight($args{'parameterdescs'}{$parameter_name});
1603 }
1604 foreach $section (@{$args{'sectionlist'}}) {
1605 print ".SH \"$section\"\n";
1606 output_highlight($args{'sections'}{$section});
1607 }
1608}
1609
1610##
1611# output typedef in man
1612sub output_typedef_man(%) {
1613 my %args = %{$_[0]};
1614 my ($parameter, $section);
1615
1616 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1617
1618 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001619 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620
1621 foreach $section (@{$args{'sectionlist'}}) {
1622 print ".SH \"$section\"\n";
1623 output_highlight($args{'sections'}{$section});
1624 }
1625}
1626
Johannes Bergb112e0f2007-10-24 15:08:48 -07001627sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 my %args = %{$_[0]};
1629 my ($parameter, $section);
1630 my $count;
1631
1632 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1633
1634 foreach $section (@{$args{'sectionlist'}}) {
1635 print ".SH \"$section\"\n";
1636 output_highlight($args{'sections'}{$section});
1637 }
1638}
1639
1640##
1641# output in text
1642sub output_function_text(%) {
1643 my %args = %{$_[0]};
1644 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001645 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646
Randy Dunlapf47634b2006-07-01 04:36:36 -07001647 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001648 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001649
1650 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001651 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001652 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001653 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001654 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001655 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001657
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 my $count = 0;
1659 foreach my $parameter (@{$args{'parameterlist'}}) {
1660 $type = $args{'parametertypes'}{$parameter};
1661 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1662 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001663 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001665 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666 }
1667 if ($count != $#{$args{'parameterlist'}}) {
1668 $count++;
1669 print ",\n";
1670 print " " x length($start);
1671 } else {
1672 print ");\n\n";
1673 }
1674 }
1675
1676 print "Arguments:\n\n";
1677 foreach $parameter (@{$args{'parameterlist'}}) {
1678 my $parameter_name = $parameter;
1679 $parameter_name =~ s/\[.*//;
1680
Randy Dunlapb9d973282009-06-09 08:50:38 -07001681 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 }
1683 output_section_text(@_);
1684}
1685
1686#output sections in text
1687sub output_section_text(%) {
1688 my %args = %{$_[0]};
1689 my $section;
1690
1691 print "\n";
1692 foreach $section (@{$args{'sectionlist'}}) {
1693 print "$section:\n\n";
1694 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001695 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 print "\n\n";
1697}
1698
1699# output enum in text
1700sub output_enum_text(%) {
1701 my %args = %{$_[0]};
1702 my ($parameter);
1703 my $count;
1704 print "Enum:\n\n";
1705
Randy Dunlapb9d973282009-06-09 08:50:38 -07001706 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1707 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 $count = 0;
1709 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001710 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 if ($count != $#{$args{'parameterlist'}}) {
1712 $count++;
1713 print ",";
1714 }
1715 print "\n";
1716 }
1717 print "};\n\n";
1718
1719 print "Constants:\n\n";
1720 foreach $parameter (@{$args{'parameterlist'}}) {
1721 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001722 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 }
1724
1725 output_section_text(@_);
1726}
1727
1728# output typedef in text
1729sub output_typedef_text(%) {
1730 my %args = %{$_[0]};
1731 my ($parameter);
1732 my $count;
1733 print "Typedef:\n\n";
1734
Randy Dunlapb9d973282009-06-09 08:50:38 -07001735 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 output_section_text(@_);
1737}
1738
1739# output struct as text
1740sub output_struct_text(%) {
1741 my %args = %{$_[0]};
1742 my ($parameter);
1743
Randy Dunlapb9d973282009-06-09 08:50:38 -07001744 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1745 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 foreach $parameter (@{$args{'parameterlist'}}) {
1747 if ($parameter =~ /^#/) {
1748 print "$parameter\n";
1749 next;
1750 }
1751
1752 my $parameter_name = $parameter;
1753 $parameter_name =~ s/\[.*//;
1754
Randy Dunlap3c308792007-05-08 00:24:39 -07001755 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 $type = $args{'parametertypes'}{$parameter};
1757 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1758 # pointer-to-function
1759 print "\t$1 $parameter) ($2);\n";
1760 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001761 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 print "\t$1 $parameter$2;\n";
1763 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001764 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 }
1766 }
1767 print "};\n\n";
1768
1769 print "Members:\n\n";
1770 foreach $parameter (@{$args{'parameterlist'}}) {
1771 ($parameter =~ /^#/) && next;
1772
1773 my $parameter_name = $parameter;
1774 $parameter_name =~ s/\[.*//;
1775
Randy Dunlap3c308792007-05-08 00:24:39 -07001776 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001778 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 }
1780 print "\n";
1781 output_section_text(@_);
1782}
1783
Johannes Bergb112e0f2007-10-24 15:08:48 -07001784sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 my %args = %{$_[0]};
1786 my ($parameter, $section);
1787
1788 foreach $section (@{$args{'sectionlist'}}) {
1789 print " $section:\n";
1790 print " -> ";
1791 output_highlight($args{'sections'}{$section});
1792 }
1793}
1794
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001795##
1796# output in restructured text
1797#
1798
1799#
1800# This could use some work; it's used to output the DOC: sections, and
1801# starts by putting out the name of the doc section itself, but that tends
1802# to duplicate a header already in the template file.
1803#
1804sub output_blockhead_rst(%) {
1805 my %args = %{$_[0]};
1806 my ($parameter, $section);
1807
1808 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001809 if ($output_selection != OUTPUT_INCLUDE) {
1810 print "**$section**\n\n";
1811 }
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001812 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001813 output_highlight_rst($args{'sections'}{$section});
1814 print "\n";
1815 }
1816}
1817
1818sub output_highlight_rst {
1819 my $contents = join "\n",@_;
1820 my $line;
1821
1822 # undo the evil effects of xml_escape() earlier
1823 $contents = xml_unescape($contents);
1824
1825 eval $dohighlight;
1826 die $@ if $@;
1827
1828 foreach $line (split "\n", $contents) {
Jani Nikula830066a2016-05-26 22:04:33 +03001829 print $lineprefix . $line . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001830 }
1831}
1832
1833sub output_function_rst(%) {
1834 my %args = %{$_[0]};
1835 my ($parameter, $section);
Jani Nikulac099ff62016-05-26 17:18:17 +03001836 my $oldprefix = $lineprefix;
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001837 my $start = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001838
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001839 if ($args{'typedef'}) {
1840 print ".. c:type:: ". $args{'function'} . "\n\n";
1841 print_lineno($declaration_start_line);
1842 print " **Typedef**: ";
1843 $lineprefix = "";
1844 output_highlight_rst($args{'purpose'});
1845 $start = "\n\n**Syntax**\n\n ``";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001846 } else {
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001847 print ".. c:function:: ";
1848 }
1849 if ($args{'functiontype'} ne "") {
1850 $start .= $args{'functiontype'} . " " . $args{'function'} . " (";
1851 } else {
1852 $start .= $args{'function'} . " (";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001853 }
1854 print $start;
1855
1856 my $count = 0;
1857 foreach my $parameter (@{$args{'parameterlist'}}) {
1858 if ($count ne 0) {
1859 print ", ";
1860 }
1861 $count++;
1862 $type = $args{'parametertypes'}{$parameter};
Mauro Carvalho Chehaba88b1672016-07-22 11:46:36 -03001863
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001864 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1865 # pointer-to-function
1866 print $1 . $parameter . ") (" . $2;
1867 } else {
1868 print $type . " " . $parameter;
1869 }
1870 }
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001871 if ($args{'typedef'}) {
1872 print ");``\n\n";
1873 } else {
1874 print ")\n\n";
1875 print_lineno($declaration_start_line);
1876 $lineprefix = " ";
1877 output_highlight_rst($args{'purpose'});
1878 print "\n";
1879 }
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001880
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001881 print "**Parameters**\n\n";
1882 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001883 foreach $parameter (@{$args{'parameterlist'}}) {
1884 my $parameter_name = $parameter;
1885 #$parameter_name =~ s/\[.*//;
1886 $type = $args{'parametertypes'}{$parameter};
1887
1888 if ($type ne "") {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001889 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001890 } else {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001891 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001892 }
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001893
1894 print_lineno($parameterdesc_start_lines{$parameter_name});
1895
Jani Nikula5e64fa92016-05-19 20:32:48 +03001896 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1897 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001898 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001899 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001900 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001901 }
1902 print "\n";
1903 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001904
1905 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001906 output_section_rst(@_);
1907}
1908
1909sub output_section_rst(%) {
1910 my %args = %{$_[0]};
1911 my $section;
1912 my $oldprefix = $lineprefix;
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001913 $lineprefix = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001914
1915 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001916 print "**$section**\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001917 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001918 output_highlight_rst($args{'sections'}{$section});
1919 print "\n";
1920 }
1921 print "\n";
1922 $lineprefix = $oldprefix;
1923}
1924
1925sub output_enum_rst(%) {
1926 my %args = %{$_[0]};
1927 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001928 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001929 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001930 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001931
1932 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001933 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001934 $lineprefix = " ";
1935 output_highlight_rst($args{'purpose'});
1936 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001937
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001938 print "**Constants**\n\n";
1939 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001940 foreach $parameter (@{$args{'parameterlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001941 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001942 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1943 output_highlight_rst($args{'parameterdescs'}{$parameter});
1944 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001945 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001946 }
1947 print "\n";
1948 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001949
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001950 $lineprefix = $oldprefix;
1951 output_section_rst(@_);
1952}
1953
1954sub output_typedef_rst(%) {
1955 my %args = %{$_[0]};
1956 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001957 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001958 my $name = "typedef " . $args{'typedef'};
1959
Jani Nikula62850972016-05-12 16:15:38 +03001960 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001961 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001962 $lineprefix = " ";
1963 output_highlight_rst($args{'purpose'});
1964 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001965
Jani Nikulac099ff62016-05-26 17:18:17 +03001966 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001967 output_section_rst(@_);
1968}
1969
1970sub output_struct_rst(%) {
1971 my %args = %{$_[0]};
1972 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001973 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001974 my $name = $args{'type'} . " " . $args{'struct'};
1975
Jani Nikula62850972016-05-12 16:15:38 +03001976 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001977 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001978 $lineprefix = " ";
1979 output_highlight_rst($args{'purpose'});
1980 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001981
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001982 print "**Definition**\n\n";
1983 print "::\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001984 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1985 foreach $parameter (@{$args{'parameterlist'}}) {
1986 if ($parameter =~ /^#/) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001987 print " " . "$parameter\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001988 next;
1989 }
1990
1991 my $parameter_name = $parameter;
1992 $parameter_name =~ s/\[.*//;
1993
1994 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1995 $type = $args{'parametertypes'}{$parameter};
1996 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1997 # pointer-to-function
1998 print " $1 $parameter) ($2);\n";
1999 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
2000 # bitfield
2001 print " $1 $parameter$2;\n";
2002 } else {
2003 print " " . $type . " " . $parameter . ";\n";
2004 }
2005 }
2006 print " };\n\n";
2007
Jani Nikulaecbcfba2016-05-26 18:30:27 +03002008 print "**Members**\n\n";
2009 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002010 foreach $parameter (@{$args{'parameterlist'}}) {
2011 ($parameter =~ /^#/) && next;
2012
2013 my $parameter_name = $parameter;
2014 $parameter_name =~ s/\[.*//;
2015
2016 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
2017 $type = $args{'parametertypes'}{$parameter};
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002018 print_lineno($parameterdesc_start_lines{$parameter_name});
Mauro Carvalho Chehab6d232c82016-08-22 22:02:57 -03002019 print "``" . $parameter . "``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002020 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002021 print "\n";
2022 }
2023 print "\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03002024
2025 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002026 output_section_rst(@_);
2027}
2028
2029
Johannes Bergeda603f2010-09-11 15:55:22 -07002030## list mode output functions
2031
2032sub output_function_list(%) {
2033 my %args = %{$_[0]};
2034
2035 print $args{'function'} . "\n";
2036}
2037
2038# output enum in list
2039sub output_enum_list(%) {
2040 my %args = %{$_[0]};
2041 print $args{'enum'} . "\n";
2042}
2043
2044# output typedef in list
2045sub output_typedef_list(%) {
2046 my %args = %{$_[0]};
2047 print $args{'typedef'} . "\n";
2048}
2049
2050# output struct as list
2051sub output_struct_list(%) {
2052 my %args = %{$_[0]};
2053
2054 print $args{'struct'} . "\n";
2055}
2056
2057sub output_blockhead_list(%) {
2058 my %args = %{$_[0]};
2059 my ($parameter, $section);
2060
2061 foreach $section (@{$args{'sectionlist'}}) {
2062 print "DOC: $section\n";
2063 }
2064}
2065
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066##
Randy Dunlap27205742006-10-11 01:22:12 -07002067# generic output function for all types (function, struct/union, typedef, enum);
2068# calls the generated, variable output_ function name based on
2069# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070sub output_declaration {
2071 no strict 'refs';
2072 my $name = shift;
2073 my $functype = shift;
2074 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002075 if (($output_selection == OUTPUT_ALL) ||
2076 (($output_selection == OUTPUT_INCLUDE ||
2077 $output_selection == OUTPUT_EXPORTED) &&
2078 defined($function_table{$name})) ||
2079 (($output_selection == OUTPUT_EXCLUDE ||
2080 $output_selection == OUTPUT_INTERNAL) &&
2081 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002083 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 $section_counter++;
2085 }
2086}
2087
2088##
Randy Dunlap27205742006-10-11 01:22:12 -07002089# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002090sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002092 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 &$func(@_);
2094 $section_counter++;
2095}
2096
2097##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002098# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099# invokes the right handler. NOT called for functions.
2100sub dump_declaration($$) {
2101 no strict 'refs';
2102 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002103 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 &$func(@_);
2105}
2106
2107sub dump_union($$) {
2108 dump_struct(@_);
2109}
2110
2111sub dump_struct($$) {
2112 my $x = shift;
2113 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002114 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002116 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2117 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002118 $declaration_name = $2;
2119 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120
2121 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002122 $members =~ s/({.*})//g;
2123 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
Martin Waitzaeec46b2005-11-13 16:08:13 -08002125 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002126 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2127 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002128 # strip comments:
2129 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002130 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002131 # strip kmemcheck_bitfield_{begin,end}.*;
2132 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002133 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002134 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002135 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002136 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002137 # replace DECLARE_BITMAP
2138 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002139
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002141 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142
2143 output_declaration($declaration_name,
2144 'struct',
2145 {'struct' => $declaration_name,
2146 'module' => $modulename,
2147 'parameterlist' => \@parameterlist,
2148 'parameterdescs' => \%parameterdescs,
2149 'parametertypes' => \%parametertypes,
2150 'sectionlist' => \@sectionlist,
2151 'sections' => \%sections,
2152 'purpose' => $declaration_purpose,
2153 'type' => $decl_type
2154 });
2155 }
2156 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002157 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 ++$errors;
2159 }
2160}
2161
2162sub dump_enum($$) {
2163 my $x = shift;
2164 my $file = shift;
2165
Martin Waitzaeec46b2005-11-13 16:08:13 -08002166 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002167 # strip #define macros inside enums
2168 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002169
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002171 $declaration_name = $1;
2172 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173
2174 foreach my $arg (split ',', $members) {
2175 $arg =~ s/^\s*(\w+).*/$1/;
2176 push @parameterlist, $arg;
2177 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002178 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002179 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 "not described in enum '$declaration_name'\n";
2181 }
2182
2183 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002184
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 output_declaration($declaration_name,
2186 'enum',
2187 {'enum' => $declaration_name,
2188 'module' => $modulename,
2189 'parameterlist' => \@parameterlist,
2190 'parameterdescs' => \%parameterdescs,
2191 'sectionlist' => \@sectionlist,
2192 'sections' => \%sections,
2193 'purpose' => $declaration_purpose
2194 });
2195 }
2196 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002197 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 ++$errors;
2199 }
2200}
2201
2202sub dump_typedef($$) {
2203 my $x = shift;
2204 my $file = shift;
2205
Martin Waitzaeec46b2005-11-13 16:08:13 -08002206 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002207
2208 # Parse function prototypes
Mauro Carvalho Chehabd37c43c2016-08-30 20:20:57 -03002209 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ ||
2210 $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) {
2211
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002212 # Function typedefs
2213 $return_type = $1;
2214 $declaration_name = $2;
2215 my $args = $3;
2216
2217 create_parameterlist($args, ',', $file);
2218
2219 output_declaration($declaration_name,
2220 'function',
2221 {'function' => $declaration_name,
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03002222 'typedef' => 1,
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002223 'module' => $modulename,
2224 'functiontype' => $return_type,
2225 'parameterlist' => \@parameterlist,
2226 'parameterdescs' => \%parameterdescs,
2227 'parametertypes' => \%parametertypes,
2228 'sectionlist' => \@sectionlist,
2229 'sections' => \%sections,
2230 'purpose' => $declaration_purpose
2231 });
2232 return;
2233 }
2234
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002236 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 $x =~ s/\[*.\]\s*;$/;/;
2238 }
2239
2240 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002241 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
2243 output_declaration($declaration_name,
2244 'typedef',
2245 {'typedef' => $declaration_name,
2246 'module' => $modulename,
2247 'sectionlist' => \@sectionlist,
2248 'sections' => \%sections,
2249 'purpose' => $declaration_purpose
2250 });
2251 }
2252 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002253 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 ++$errors;
2255 }
2256}
2257
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002258sub save_struct_actual($) {
2259 my $actual = shift;
2260
2261 # strip all spaces from the actual param so that it looks like one string item
2262 $actual =~ s/\s*//g;
2263 $struct_actual = $struct_actual . $actual . " ";
2264}
2265
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266sub create_parameterlist($$$) {
2267 my $args = shift;
2268 my $splitter = shift;
2269 my $file = shift;
2270 my $type;
2271 my $param;
2272
Martin Waitza6d3fe72006-01-09 20:53:55 -08002273 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002275 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002277
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 foreach my $arg (split($splitter, $args)) {
2279 # strip comments
2280 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002281 # strip leading/trailing spaces
2282 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 $arg =~ s/\s*$//;
2284 $arg =~ s/\s+/ /;
2285
2286 if ($arg =~ /^#/) {
2287 # Treat preprocessor directive as a typeless variable just to fill
2288 # corresponding data structures "correctly". Catch it later in
2289 # output_* subs.
2290 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002291 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 # pointer-to-function
2293 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002294 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 $param = $1;
2296 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002297 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002298 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002300 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 $arg =~ s/\s*:\s*/:/g;
2302 $arg =~ s/\s*\[/\[/g;
2303
2304 my @args = split('\s*,\s*', $arg);
2305 if ($args[0] =~ m/\*/) {
2306 $args[0] =~ s/(\*+)\s*/ $1/;
2307 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002308
2309 my @first_arg;
2310 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2311 shift @args;
2312 push(@first_arg, split('\s+', $1));
2313 push(@first_arg, $2);
2314 } else {
2315 @first_arg = split('\s+', shift @args);
2316 }
2317
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 unshift(@args, pop @first_arg);
2319 $type = join " ", @first_arg;
2320
2321 foreach $param (@args) {
2322 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002323 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 push_parameter($2, "$type $1", $file);
2325 }
2326 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002327 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002328 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002329 push_parameter($1, "$type:$2", $file)
2330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 }
2332 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002333 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 push_parameter($param, $type, $file);
2335 }
2336 }
2337 }
2338 }
2339}
2340
2341sub push_parameter($$$) {
2342 my $param = shift;
2343 my $type = shift;
2344 my $file = shift;
2345
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002346 if (($anon_struct_union == 1) && ($type eq "") &&
2347 ($param eq "}")) {
2348 return; # ignore the ending }; from anon. struct/union
2349 }
2350
2351 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 my $param_name = $param;
2353 $param_name =~ s/\[.*//;
2354
Martin Waitza6d3fe72006-01-09 20:53:55 -08002355 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 {
Silvio Frickec950a172016-10-28 10:14:08 +02002357 if (!$param =~ /\w\.\.\.$/) {
2358 # handles unnamed variable parameters
2359 $param = "...";
2360 }
Randy Dunlapced69092008-12-01 13:14:03 -08002361 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2362 $parameterdescs{$param} = "variable arguments";
2363 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 }
2365 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2366 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 $param="void";
2368 $parameterdescs{void} = "no arguments";
2369 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002370 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2371 # handle unnamed (anonymous) union or struct:
2372 {
2373 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002374 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002375 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002376 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002377 }
2378
Martin Waitza6d3fe72006-01-09 20:53:55 -08002379 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002380 # (but ignore ones starting with # as these are not parameters
2381 # but inline preprocessor statements);
2382 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002383 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002384 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2385
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 $parameterdescs{$param_name} = $undescribed;
2387
2388 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002389 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 "or member '$param' not " .
2391 "described in '$declaration_name'\n";
2392 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002393 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002394 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002396 }
2397 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002399 $param = xml_escape($param);
2400
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002401 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002402 # on @parameterlist;
2403 # this fixes a problem where check_sections() cannot find
2404 # a parameter like "addr[6 + 2]" because it actually appears
2405 # as "addr[6", "+", "2]" on the parameter list;
2406 # but it's better to maintain the param string unchanged for output,
2407 # so just weaken the string compare in check_sections() to ignore
2408 # "[blah" in a parameter string;
2409 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 push @parameterlist, $param;
2411 $parametertypes{$param} = $type;
2412}
2413
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002414sub check_sections($$$$$$) {
2415 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2416 my @sects = split ' ', $sectcheck;
2417 my @prms = split ' ', $prmscheck;
2418 my $err;
2419 my ($px, $sx);
2420 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2421
2422 foreach $sx (0 .. $#sects) {
2423 $err = 1;
2424 foreach $px (0 .. $#prms) {
2425 $prm_clean = $prms[$px];
2426 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002427 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002428 # ignore array size in a parameter string;
2429 # however, the original param string may contain
2430 # spaces, e.g.: addr[6 + 2]
2431 # and this appears in @prms as "addr[6" since the
2432 # parameter list is split at spaces;
2433 # hence just ignore "[..." for the sections check;
2434 $prm_clean =~ s/\[.*//;
2435
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002436 ##$prm_clean =~ s/^\**//;
2437 if ($prm_clean eq $sects[$sx]) {
2438 $err = 0;
2439 last;
2440 }
2441 }
2442 if ($err) {
2443 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002444 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002445 "Excess function parameter " .
2446 "'$sects[$sx]' " .
2447 "description in '$decl_name'\n";
2448 ++$warnings;
2449 } else {
2450 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002451 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002452 "Excess struct/union/enum/typedef member " .
2453 "'$sects[$sx]' " .
2454 "description in '$decl_name'\n";
2455 ++$warnings;
2456 }
2457 }
2458 }
2459 }
2460}
2461
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002463# Checks the section describing the return value of a function.
2464sub check_return_section {
2465 my $file = shift;
2466 my $declaration_name = shift;
2467 my $return_type = shift;
2468
2469 # Ignore an empty return type (It's a macro)
2470 # Ignore functions with a "void" return type. (But don't ignore "void *")
2471 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2472 return;
2473 }
2474
2475 if (!defined($sections{$section_return}) ||
2476 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002477 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002478 "No description found for return value of " .
2479 "'$declaration_name'\n";
2480 ++$warnings;
2481 }
2482}
2483
2484##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485# takes a function prototype and the name of the current file being
2486# processed and spits out all the details stored in the global
2487# arrays/hashes.
2488sub dump_function($$) {
2489 my $prototype = shift;
2490 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002491 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492
2493 $prototype =~ s/^static +//;
2494 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002495 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 $prototype =~ s/^inline +//;
2497 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002498 $prototype =~ s/^__inline +//;
2499 $prototype =~ s/^__always_inline +//;
2500 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002501 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002502 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002503 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002504 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002505 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002506 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002507 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508
2509 # Yes, this truly is vile. We are looking for:
2510 # 1. Return type (may be nothing if we're looking at a macro)
2511 # 2. Function name
2512 # 3. Function parameters.
2513 #
2514 # All the while we have to watch out for function pointer parameters
2515 # (which IIRC is what the two sections are for), C types (these
2516 # regexps don't even start to express all the possibilities), and
2517 # so on.
2518 #
2519 # If you mess with these regexps, it's a good idea to check that
2520 # the following functions' documentation still comes out right:
2521 # - parport_register_device (function pointer parameters)
2522 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002523 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002525 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2526 # This is an object-like macro, it has no return type and no parameter
2527 # list.
2528 # Function-like macros are not allowed to have spaces between
2529 # declaration_name and opening parenthesis (notice the \s+).
2530 $return_type = $1;
2531 $declaration_name = $2;
2532 $noret = 1;
2533 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2535 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2536 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002537 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2539 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2540 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2541 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2542 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2543 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2544 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2545 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002546 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2547 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002548 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2549 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 $return_type = $1;
2551 $declaration_name = $2;
2552 my $args = $3;
2553
2554 create_parameterlist($args, ',', $file);
2555 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002556 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 return;
2558 }
2559
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002560 my $prms = join " ", @parameterlist;
2561 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2562
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002563 # This check emits a lot of warnings at the moment, because many
2564 # functions don't have a 'Return' doc section. So until the number
2565 # of warnings goes sufficiently down, the check is only performed in
2566 # verbose mode.
2567 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002568 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002569 check_return_section($file, $declaration_name, $return_type);
2570 }
2571
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002572 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 'function',
2574 {'function' => $declaration_name,
2575 'module' => $modulename,
2576 'functiontype' => $return_type,
2577 'parameterlist' => \@parameterlist,
2578 'parameterdescs' => \%parameterdescs,
2579 'parametertypes' => \%parametertypes,
2580 'sectionlist' => \@sectionlist,
2581 'sections' => \%sections,
2582 'purpose' => $declaration_purpose
2583 });
2584}
2585
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586sub reset_state {
2587 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 %parameterdescs = ();
2589 %parametertypes = ();
2590 @parameterlist = ();
2591 %sections = ();
2592 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002593 $sectcheck = "";
2594 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002595 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002596
Jani Nikula48af6062016-05-26 14:56:05 +03002597 $state = STATE_NORMAL;
2598 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599}
2600
Jason Baron56afb0f2009-04-30 13:29:36 -04002601sub tracepoint_munge($) {
2602 my $file = shift;
2603 my $tracepointname = 0;
2604 my $tracepointargs = 0;
2605
Jason Baron3a9089f2009-12-01 12:18:49 -05002606 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002607 $tracepointname = $1;
2608 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002609 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2610 $tracepointname = $1;
2611 }
2612 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2613 $tracepointname = $2;
2614 }
2615 $tracepointname =~ s/^\s+//; #strip leading whitespace
2616 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002617 $tracepointargs = $1;
2618 }
2619 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002620 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002621 "$prototype\n";
2622 } else {
2623 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2624 }
2625}
2626
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002627sub syscall_munge() {
2628 my $void = 0;
2629
2630 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2631## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2632 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2633 $void = 1;
2634## $prototype = "long sys_$1(void)";
2635 }
2636
2637 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2638 if ($prototype =~ m/long (sys_.*?),/) {
2639 $prototype =~ s/,/\(/;
2640 } elsif ($void) {
2641 $prototype =~ s/\)/\(void\)/;
2642 }
2643
2644 # now delete all of the odd-number commas in $prototype
2645 # so that arg types & arg names don't have a comma between them
2646 my $count = 0;
2647 my $len = length($prototype);
2648 if ($void) {
2649 $len = 0; # skip the for-loop
2650 }
2651 for (my $ix = 0; $ix < $len; $ix++) {
2652 if (substr($prototype, $ix, 1) eq ',') {
2653 $count++;
2654 if ($count % 2 == 1) {
2655 substr($prototype, $ix, 1) = ' ';
2656 }
2657 }
2658 }
2659}
2660
Daniel Vetterb7afa922016-06-01 23:46:24 +02002661sub process_proto_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 my $x = shift;
2663 my $file = shift;
2664
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002665 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2666
Randy Dunlap890c78c2008-10-25 17:06:43 -07002667 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 # do nothing
2669 }
2670 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002671 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002673
Randy Dunlap890c78c2008-10-25 17:06:43 -07002674 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002675 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2677 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002678 if ($prototype =~ /SYSCALL_DEFINE/) {
2679 syscall_munge();
2680 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002681 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2682 $prototype =~ /DEFINE_SINGLE_EVENT/)
2683 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002684 tracepoint_munge($file);
2685 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002686 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002687 reset_state();
2688 }
2689}
2690
Daniel Vetterb7afa922016-06-01 23:46:24 +02002691sub process_proto_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 my $x = shift;
2693 my $file = shift;
2694
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2696 $x =~ s@^\s+@@gos; # strip leading spaces
2697 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002698 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2699
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 if ($x =~ /^#/) {
2701 # To distinguish preprocessor directive from regular declaration later.
2702 $x .= ";";
2703 }
2704
2705 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002706 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 $prototype .= $1 . $2;
2708 ($2 eq '{') && $brcount++;
2709 ($2 eq '}') && $brcount--;
2710 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002711 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002713 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 }
2715 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002716 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 $prototype .= $x;
2718 last;
2719 }
2720 }
2721}
2722
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002723# xml_escape: replace <, >, and & in the text stream;
2724#
2725# however, formatting controls that are generated internally/locally in the
2726# kernel-doc script are not escaped here; instead, they begin life like
2727# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2728# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2729# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730sub xml_escape($) {
2731 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002732 if (($output_mode eq "text") || ($output_mode eq "man")) {
2733 return $text;
2734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 $text =~ s/\&/\\\\\\amp;/g;
2736 $text =~ s/\</\\\\\\lt;/g;
2737 $text =~ s/\>/\\\\\\gt;/g;
2738 return $text;
2739}
2740
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002741# xml_unescape: reverse the effects of xml_escape
2742sub xml_unescape($) {
2743 my $text = shift;
2744 if (($output_mode eq "text") || ($output_mode eq "man")) {
2745 return $text;
2746 }
2747 $text =~ s/\\\\\\amp;/\&/g;
2748 $text =~ s/\\\\\\lt;/</g;
2749 $text =~ s/\\\\\\gt;/>/g;
2750 return $text;
2751}
2752
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002753# convert local escape strings to html
2754# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2755sub local_unescape($) {
2756 my $text = shift;
2757 if (($output_mode eq "text") || ($output_mode eq "man")) {
2758 return $text;
2759 }
2760 $text =~ s/\\\\\\\\lt:/</g;
2761 $text =~ s/\\\\\\\\gt:/>/g;
2762 return $text;
2763}
2764
Jani Nikula1ad560e2016-06-07 10:53:39 +03002765sub map_filename($) {
2766 my $file;
2767 my ($orig_file) = @_;
2768
2769 if (defined($ENV{'SRCTREE'})) {
2770 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
2771 } else {
2772 $file = $orig_file;
2773 }
2774
2775 if (defined($source_map{$file})) {
2776 $file = $source_map{$file};
2777 }
2778
2779 return $file;
2780}
2781
Jani Nikula88c2b572016-06-07 11:00:52 +03002782sub process_export_file($) {
2783 my ($orig_file) = @_;
2784 my $file = map_filename($orig_file);
2785
2786 if (!open(IN,"<$file")) {
2787 print STDERR "Error: Cannot open file $file\n";
2788 ++$errors;
2789 return;
2790 }
2791
2792 while (<IN>) {
2793 if (/$export_symbol/) {
2794 $function_table{$2} = 1;
2795 }
2796 }
2797
2798 close(IN);
2799}
2800
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002802 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 my $identifier;
2804 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002805 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002806 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002808 my ($orig_file) = @_;
Jani Nikulab7886de2016-05-28 00:41:50 +03002809 my $leading_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810
Jani Nikula1ad560e2016-06-07 10:53:39 +03002811 $file = map_filename($orig_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812
2813 if (!open(IN,"<$file")) {
2814 print STDERR "Error: Cannot open file $file\n";
2815 ++$errors;
2816 return;
2817 }
2818
Ilya Dryomova9e73142010-02-26 13:05:47 -08002819 $. = 1;
2820
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 $section_counter = 0;
2822 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002823 while (s/\\\s*$//) {
2824 $_ .= <IN>;
2825 }
Jani Nikula48af6062016-05-26 14:56:05 +03002826 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002828 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002829 $in_doc_sect = 0;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002830 $declaration_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 }
Jani Nikula48af6062016-05-26 14:56:05 +03002832 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002834 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002836 $new_start_line = $. + 1;
2837
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 if ( $1 eq "" ) {
2839 $section = $section_intro;
2840 } else {
2841 $section = $1;
2842 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002843 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 elsif (/$doc_decl/o) {
2845 $identifier = $1;
2846 if (/\s*([\w\s]+?)\s*-/) {
2847 $identifier = $1;
2848 }
2849
Jani Nikula48af6062016-05-26 14:56:05 +03002850 $state = STATE_FIELD;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002851 # if there's no @param blocks need to set up default section
2852 # here
Jani Nikula2f4ad402016-05-30 11:21:06 +03002853 $contents = "";
2854 $section = $section_default;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002855 $new_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002857 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002858 $descr= $1;
2859 $descr =~ s/^\s*//;
2860 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002861 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002862 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002863 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 } else {
2865 $declaration_purpose = "";
2866 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002867
2868 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002869 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002870 print STDERR $_;
2871 ++$warnings;
2872 }
2873
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 if ($identifier =~ m/^struct/) {
2875 $decl_type = 'struct';
2876 } elsif ($identifier =~ m/^union/) {
2877 $decl_type = 'union';
2878 } elsif ($identifier =~ m/^enum/) {
2879 $decl_type = 'enum';
2880 } elsif ($identifier =~ m/^typedef/) {
2881 $decl_type = 'typedef';
2882 } else {
2883 $decl_type = 'function';
2884 }
2885
2886 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002887 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 }
2889 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002890 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 " - I thought it was a doc line\n";
2892 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002893 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 }
Jani Nikula48af6062016-05-26 14:56:05 +03002895 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Jani Nikulaf624ade2016-05-29 11:35:28 +03002896 if (/$doc_sect/i) { # case insensitive for supported section names
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 $newsection = $1;
2898 $newcontents = $2;
2899
Jani Nikulaf624ade2016-05-29 11:35:28 +03002900 # map the supported section names to the canonical names
2901 if ($newsection =~ m/^description$/i) {
2902 $newsection = $section_default;
2903 } elsif ($newsection =~ m/^context$/i) {
2904 $newsection = $section_context;
2905 } elsif ($newsection =~ m/^returns?$/i) {
2906 $newsection = $section_return;
2907 } elsif ($newsection =~ m/^\@return$/) {
2908 # special: @return is a section, not a param description
2909 $newsection = $section_return;
2910 }
2911
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002912 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002913 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002914 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002915 ++$warnings;
2916 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002917 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 $section = $section_default;
2919 }
2920
Randy Dunlap850622d2006-06-25 05:48:55 -07002921 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002922 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 $contents = $newcontents;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002924 $new_start_line = $.;
Jani Nikula0a726302016-05-28 14:50:20 +03002925 while ((substr($contents, 0, 1) eq " ") ||
2926 substr($contents, 0, 1) eq "\t") {
2927 $contents = substr($contents, 1);
2928 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 if ($contents ne "") {
2930 $contents .= "\n";
2931 }
2932 $section = $newsection;
Jani Nikulab7886de2016-05-28 00:41:50 +03002933 $leading_space = undef;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002935 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002936 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 $section = $section_default;
2938 $contents = "";
2939 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002940 # look for doc_com + <text> + doc_end:
2941 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002942 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002943 ++$warnings;
2944 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945
2946 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002947 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002949# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 } elsif (/$doc_content/) {
2951 # miguel-style comment kludge, look for blank lines after
2952 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002953 if ($1 eq "") {
2954 if ($section =~ m/^@/ || $section eq $section_context) {
2955 dump_section($file, $section, xml_escape($contents));
2956 $section = $section_default;
2957 $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002958 $new_start_line = $.;
Johannes Weiner64231332009-09-17 19:26:53 -07002959 } else {
2960 $contents .= "\n";
2961 }
2962 $in_purpose = 0;
2963 } elsif ($in_purpose == 1) {
2964 # Continued declaration purpose
2965 chomp($declaration_purpose);
2966 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002967 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 } else {
Jani Nikulab7886de2016-05-28 00:41:50 +03002969 my $cont = $1;
2970 if ($section =~ m/^@/ || $section eq $section_context) {
2971 if (!defined $leading_space) {
2972 if ($cont =~ m/^(\s+)/) {
2973 $leading_space = $1;
2974 } else {
2975 $leading_space = "";
2976 }
2977 }
2978
2979 $cont =~ s/^$leading_space//;
2980 }
2981 $contents .= $cont . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 }
2983 } else {
2984 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002985 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 ++$warnings;
2987 }
Jani Nikula48af6062016-05-26 14:56:05 +03002988 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002989 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03002990 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002991 $section = $1;
2992 $contents = $2;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002993 $new_start_line = $.;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002994 if ($contents ne "") {
2995 while ((substr($contents, 0, 1) eq " ") ||
2996 substr($contents, 0, 1) eq "\t") {
2997 $contents = substr($contents, 1);
2998 }
Jani Nikulaa0b96c22016-05-26 22:04:06 +03002999 $contents .= "\n";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003000 }
Jani Nikula48af6062016-05-26 14:56:05 +03003001 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003002 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03003003 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003004 if (($contents ne "") && ($contents ne "\n")) {
3005 dump_section($file, $section, xml_escape($contents));
3006 $section = $section_default;
3007 $contents = "";
3008 }
Jani Nikula48af6062016-05-26 14:56:05 +03003009 $state = STATE_PROTO;
3010 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003011 # Regular text
3012 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03003013 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003014 $contents .= $1 . "\n";
Jani Nikula6450c892016-05-26 22:04:42 +03003015 # nuke leading blank lines
3016 if ($contents =~ /^\s*$/) {
3017 $contents = "";
3018 }
Jani Nikula48af6062016-05-26 14:56:05 +03003019 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
3020 $inline_doc_state = STATE_INLINE_ERROR;
Daniel Vettere7ca3112016-07-15 10:19:30 +02003021 print STDERR "${file}:$.: warning: ";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003022 print STDERR "Incorrect use of kernel-doc format: $_";
3023 ++$warnings;
3024 }
3025 }
Jani Nikula48af6062016-05-26 14:56:05 +03003026 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
3027 if (/$doc_inline_start/) {
3028 $state = STATE_INLINE;
3029 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003030 } elsif ($decl_type eq 'function') {
Daniel Vetterb7afa922016-06-01 23:46:24 +02003031 process_proto_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 } else {
Daniel Vetterb7afa922016-06-01 23:46:24 +02003033 process_proto_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 }
Jani Nikula48af6062016-05-26 14:56:05 +03003035 } elsif ($state == STATE_DOCBLOCK) {
Daniel Vetterebff7f92016-06-01 23:46:23 +02003036 if (/$doc_end/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07003038 dump_doc_section($file, $section, xml_escape($contents));
Jani Nikula2f4ad402016-05-30 11:21:06 +03003039 $section = $section_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 $contents = "";
3041 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 %parameterdescs = ();
3043 %parametertypes = ();
3044 @parameterlist = ();
3045 %sections = ();
3046 @sectionlist = ();
3047 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03003048 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 }
3050 elsif (/$doc_content/)
3051 {
3052 if ( $1 eq "" )
3053 {
3054 $contents .= $blankline;
3055 }
3056 else
3057 {
3058 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08003059 }
Randy Dunlap3c308792007-05-08 00:24:39 -07003060 }
3061 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 }
3063 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07003064 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03003065 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08003066 print STDERR " Was looking for '$_'.\n" for keys %function_table;
3067 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 if ($output_mode eq "xml") {
3069 # The template wants at least one RefEntry here; make one.
3070 print "<refentry>\n";
3071 print " <refnamediv>\n";
3072 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003073 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 print " </refname>\n";
3075 print " <refpurpose>\n";
3076 print " Document generation inconsistency\n";
3077 print " </refpurpose>\n";
3078 print " </refnamediv>\n";
3079 print " <refsect1>\n";
3080 print " <title>\n";
3081 print " Oops\n";
3082 print " </title>\n";
3083 print " <warning>\n";
3084 print " <para>\n";
3085 print " The template for this document tried to insert\n";
3086 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003087 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 print " but none was found.\n";
3089 print " This dummy section is inserted to allow\n";
3090 print " generation to continue.\n";
3091 print " </para>\n";
3092 print " </warning>\n";
3093 print " </refsect1>\n";
3094 print "</refentry>\n";
3095 }
3096 }
3097}
Randy Dunlap8484baa2011-01-05 16:28:43 -08003098
3099
3100$kernelversion = get_kernel_version();
3101
3102# generate a sequence of code that will splice in highlighting information
3103# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02003104for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03003105 my $pattern = $highlights[$k][0];
3106 my $result = $highlights[$k][1];
3107# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
3108 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08003109}
3110
3111# Read the file that maps relative names to absolute names for
3112# separate source and object directories and for shadow trees.
3113if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3114 my ($relname, $absname);
3115 while(<SOURCE_MAP>) {
3116 chop();
3117 ($relname, $absname) = (split())[0..1];
3118 $relname =~ s:^/+::;
3119 $source_map{$relname} = $absname;
3120 }
3121 close(SOURCE_MAP);
3122}
3123
Jani Nikula88c2b572016-06-07 11:00:52 +03003124if ($output_selection == OUTPUT_EXPORTED ||
3125 $output_selection == OUTPUT_INTERNAL) {
Jani Nikulac9b2cfb2016-06-07 11:05:53 +03003126
3127 push(@export_file_list, @ARGV);
3128
Jani Nikula88c2b572016-06-07 11:00:52 +03003129 foreach (@export_file_list) {
3130 chomp;
3131 process_export_file($_);
3132 }
3133}
3134
Randy Dunlap8484baa2011-01-05 16:28:43 -08003135foreach (@ARGV) {
3136 chomp;
3137 process_file($_);
3138}
3139if ($verbose && $errors) {
3140 print STDERR "$errors errors\n";
3141}
3142if ($verbose && $warnings) {
3143 print STDERR "$warnings warnings\n";
3144}
3145
3146exit($errors);