blob: 5476cf4f4673f807fcc4e6c30fa20428c9944c73 [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 Nikula0c9aa202016-11-16 17:26:16 +0200424my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200425my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427my %parameterdescs;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200428my %parameterdesc_start_lines;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429my @parameterlist;
430my %sections;
431my @sectionlist;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200432my %section_start_lines;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800433my $sectcheck;
434my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
436my $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200437my $new_start_line = 0;
Jani Nikulaf624ade2016-05-29 11:35:28 +0300438
439# the canonical section names. see also $doc_sect above.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440my $section_default = "Description"; # default section
441my $section_intro = "Introduction";
442my $section = $section_default;
443my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100444my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
446my $undescribed = "-- undescribed --";
447
448reset_state();
449
450while ($ARGV[0] =~ m/^-(.*)/) {
451 my $cmd = shift @ARGV;
452 if ($cmd eq "-html") {
453 $output_mode = "html";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300454 @highlights = @highlights_html;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200456 } elsif ($cmd eq "-html5") {
457 $output_mode = "html5";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300458 @highlights = @highlights_html5;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200459 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 } elsif ($cmd eq "-man") {
461 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300462 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 $blankline = $blankline_man;
464 } elsif ($cmd eq "-text") {
465 $output_mode = "text";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300466 @highlights = @highlights_text;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 $blankline = $blankline_text;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300468 } elsif ($cmd eq "-rst") {
469 $output_mode = "rst";
470 @highlights = @highlights_rst;
471 $blankline = $blankline_rst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 } elsif ($cmd eq "-docbook") {
473 $output_mode = "xml";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300474 @highlights = @highlights_xml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700476 } elsif ($cmd eq "-list") {
477 $output_mode = "list";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300478 @highlights = @highlights_list;
Johannes Bergeda603f2010-09-11 15:55:22 -0700479 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 } elsif ($cmd eq "-gnome") {
481 $output_mode = "gnome";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300482 @highlights = @highlights_gnome;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 $blankline = $blankline_gnome;
484 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
485 $modulename = shift @ARGV;
486 } elsif ($cmd eq "-function") { # to only output specific functions
Jani Nikulab6c3f452016-05-29 22:19:35 +0300487 $output_selection = OUTPUT_INCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 $function = shift @ARGV;
489 $function_table{$function} = 1;
Jani Nikulab6c3f452016-05-29 22:19:35 +0300490 } elsif ($cmd eq "-nofunction") { # output all except specific functions
491 $output_selection = OUTPUT_EXCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 $function = shift @ARGV;
493 $function_table{$function} = 1;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200494 } elsif ($cmd eq "-export") { # only exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300495 $output_selection = OUTPUT_EXPORTED;
Jani Nikulada9726e2016-06-07 10:29:59 +0300496 %function_table = ();
Jani Nikula86ae2e32016-01-21 13:05:22 +0200497 } elsif ($cmd eq "-internal") { # only non-exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300498 $output_selection = OUTPUT_INTERNAL;
Jani Nikulada9726e2016-06-07 10:29:59 +0300499 %function_table = ();
Jani Nikula88c2b572016-06-07 11:00:52 +0300500 } elsif ($cmd eq "-export-file") {
501 my $file = shift @ARGV;
502 push(@export_file_list, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 } elsif ($cmd eq "-v") {
504 $verbose = 1;
505 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
506 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700507 } elsif ($cmd eq '-no-doc-sections') {
508 $no_doc_sections = 1;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200509 } elsif ($cmd eq '-enable-lineno') {
510 $enable_lineno = 1;
Johannes Berge946c43a2013-11-12 15:11:12 -0800511 } elsif ($cmd eq '-show-not-found') {
512 $show_not_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
514}
515
Randy Dunlap8484baa2011-01-05 16:28:43 -0800516# continue execution near EOF;
517
Borislav Petkov53f049f2007-05-08 00:30:54 -0700518# get kernel version from env
519sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700520 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700521
522 if (defined($ENV{'KERNELVERSION'})) {
523 $version = $ENV{'KERNELVERSION'};
524 }
525 return $version;
526}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200528#
529sub print_lineno {
530 my $lineno = shift;
531 if ($enable_lineno && defined($lineno)) {
532 print "#define LINENO " . $lineno . "\n";
533 }
534}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535##
536# dumps section contents to arrays/hashes intended for that purpose.
537#
538sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700539 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 my $name = shift;
541 my $contents = join "\n", @_;
542
Jani Nikula13901ef2016-05-26 08:57:29 +0300543 if ($name =~ m/$type_param/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 $name = $1;
545 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800546 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200547 $parameterdesc_start_lines{$name} = $new_start_line;
548 $new_start_line = 0;
Randy Dunlapced69092008-12-01 13:14:03 -0800549 } elsif ($name eq "@\.\.\.") {
Randy Dunlapced69092008-12-01 13:14:03 -0800550 $name = "...";
551 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800552 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200553 $parameterdesc_start_lines{$name} = $new_start_line;
554 $new_start_line = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 } else {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700556 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Jani Nikula95b6be92016-06-10 11:14:05 +0300557 # Only warn on user specified duplicate section names.
558 if ($name ne $section_default) {
559 print STDERR "${file}:$.: warning: duplicate section name '$name'\n";
560 ++$warnings;
561 }
Jani Nikula32217762016-05-29 09:40:44 +0300562 $sections{$name} .= $contents;
563 } else {
564 $sections{$name} = $contents;
565 push @sectionlist, $name;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200566 $section_start_lines{$name} = $new_start_line;
567 $new_start_line = 0;
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700568 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 }
570}
571
572##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700573# dump DOC: section after checking that it should go out
574#
575sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700576 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700577 my $name = shift;
578 my $contents = join "\n", @_;
579
Johannes Berg4b445952007-10-24 15:08:48 -0700580 if ($no_doc_sections) {
581 return;
582 }
583
Jani Nikulab6c3f452016-05-29 22:19:35 +0300584 if (($output_selection == OUTPUT_ALL) ||
585 ($output_selection == OUTPUT_INCLUDE &&
586 defined($function_table{$name})) ||
587 ($output_selection == OUTPUT_EXCLUDE &&
588 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700589 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700590 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700591 output_blockhead({'sectionlist' => \@sectionlist,
592 'sections' => \%sections,
593 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300594 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700595 }
596}
597
598##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599# output function
600#
601# parameterdescs, a hash.
602# function => "function name"
603# parameterlist => @list of parameters
604# parameterdescs => %parameter descriptions
605# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800606# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800607#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609sub output_highlight {
610 my $contents = join "\n",@_;
611 my $line;
612
613# DEBUG
614# if (!defined $contents) {
615# use Carp;
616# confess "output_highlight got called with no args?\n";
617# }
618
Dan Luedtke1b40c192012-08-12 10:46:15 +0200619 if ($output_mode eq "html" || $output_mode eq "html5" ||
620 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700621 $contents = local_unescape($contents);
622 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800623 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700624 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700625# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 eval $dohighlight;
627 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700628# print STDERR "contents af:$contents\n";
629
Dan Luedtke1b40c192012-08-12 10:46:15 +0200630# strip whitespaces when generating html5
631 if ($output_mode eq "html5") {
632 $contents =~ s/^\s+//;
633 $contents =~ s/\s+$//;
634 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700636 if (! $output_preformatted) {
637 $line =~ s/^\s*//;
638 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700639 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700640 if (! $output_preformatted) {
641 print $lineprefix, local_unescape($blankline);
642 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700644 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700645 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
646 print "\\&$line";
647 } else {
648 print $lineprefix, $line;
649 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 }
651 print "\n";
652 }
653}
654
Dan Luedtke1b40c192012-08-12 10:46:15 +0200655# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656sub output_section_html(%) {
657 my %args = %{$_[0]};
658 my $section;
659
660 foreach $section (@{$args{'sectionlist'}}) {
661 print "<h3>$section</h3>\n";
662 print "<blockquote>\n";
663 output_highlight($args{'sections'}{$section});
664 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800665 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667
668# output enum in html
669sub output_enum_html(%) {
670 my %args = %{$_[0]};
671 my ($parameter);
672 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700673 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Randy Dunlapb9d973282009-06-09 08:50:38 -0700675 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 $count = 0;
677 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700678 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 if ($count != $#{$args{'parameterlist'}}) {
680 $count++;
681 print ",\n";
682 }
683 print "<br>";
684 }
685 print "};<br>\n";
686
687 print "<h3>Constants</h3>\n";
688 print "<dl>\n";
689 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700690 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 print "<dd>";
692 output_highlight($args{'parameterdescs'}{$parameter});
693 }
694 print "</dl>\n";
695 output_section_html(@_);
696 print "<hr>\n";
697}
698
Randy Dunlapd28bee02006-02-01 03:06:57 -0800699# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700sub output_typedef_html(%) {
701 my %args = %{$_[0]};
702 my ($parameter);
703 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700704 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Randy Dunlapb9d973282009-06-09 08:50:38 -0700706 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 output_section_html(@_);
708 print "<hr>\n";
709}
710
711# output struct in html
712sub output_struct_html(%) {
713 my %args = %{$_[0]};
714 my ($parameter);
715
Randy Dunlapb9d973282009-06-09 08:50:38 -0700716 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
717 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 foreach $parameter (@{$args{'parameterlist'}}) {
719 if ($parameter =~ /^#/) {
720 print "$parameter<br>\n";
721 next;
722 }
723 my $parameter_name = $parameter;
724 $parameter_name =~ s/\[.*//;
725
Randy Dunlap3c308792007-05-08 00:24:39 -0700726 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 $type = $args{'parametertypes'}{$parameter};
728 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
729 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700730 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700732 # bitfield
733 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700735 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 }
737 }
738 print "};<br>\n";
739
740 print "<h3>Members</h3>\n";
741 print "<dl>\n";
742 foreach $parameter (@{$args{'parameterlist'}}) {
743 ($parameter =~ /^#/) && next;
744
745 my $parameter_name = $parameter;
746 $parameter_name =~ s/\[.*//;
747
Randy Dunlap3c308792007-05-08 00:24:39 -0700748 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700749 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 print "<dd>";
751 output_highlight($args{'parameterdescs'}{$parameter_name});
752 }
753 print "</dl>\n";
754 output_section_html(@_);
755 print "<hr>\n";
756}
757
758# output function in html
759sub output_function_html(%) {
760 my %args = %{$_[0]};
761 my ($parameter, $section);
762 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763
Randy Dunlapb9d973282009-06-09 08:50:38 -0700764 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
765 print "<i>" . $args{'functiontype'} . "</i>\n";
766 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 print "(";
768 $count = 0;
769 foreach $parameter (@{$args{'parameterlist'}}) {
770 $type = $args{'parametertypes'}{$parameter};
771 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
772 # pointer-to-function
773 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
774 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700775 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 }
777 if ($count != $#{$args{'parameterlist'}}) {
778 $count++;
779 print ",\n";
780 }
781 }
782 print ")\n";
783
784 print "<h3>Arguments</h3>\n";
785 print "<dl>\n";
786 foreach $parameter (@{$args{'parameterlist'}}) {
787 my $parameter_name = $parameter;
788 $parameter_name =~ s/\[.*//;
789
Randy Dunlap3c308792007-05-08 00:24:39 -0700790 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700791 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 print "<dd>";
793 output_highlight($args{'parameterdescs'}{$parameter_name});
794 }
795 print "</dl>\n";
796 output_section_html(@_);
797 print "<hr>\n";
798}
799
Johannes Bergb112e0f2007-10-24 15:08:48 -0700800# output DOC: block header in html
801sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 my %args = %{$_[0]};
803 my ($parameter, $section);
804 my $count;
805
806 foreach $section (@{$args{'sectionlist'}}) {
807 print "<h3>$section</h3>\n";
808 print "<ul>\n";
809 output_highlight($args{'sections'}{$section});
810 print "</ul>\n";
811 }
812 print "<hr>\n";
813}
814
Dan Luedtke1b40c192012-08-12 10:46:15 +0200815# output sections in html5
816sub output_section_html5(%) {
817 my %args = %{$_[0]};
818 my $section;
819
820 foreach $section (@{$args{'sectionlist'}}) {
821 print "<section>\n";
822 print "<h1>$section</h1>\n";
823 print "<p>\n";
824 output_highlight($args{'sections'}{$section});
825 print "</p>\n";
826 print "</section>\n";
827 }
828}
829
830# output enum in html5
831sub output_enum_html5(%) {
832 my %args = %{$_[0]};
833 my ($parameter);
834 my $count;
835 my $html5id;
836
837 $html5id = $args{'enum'};
838 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
839 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
840 print "<h1>enum " . $args{'enum'} . "</h1>\n";
841 print "<ol class=\"code\">\n";
842 print "<li>";
843 print "<span class=\"keyword\">enum</span> ";
844 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
845 print "</li>\n";
846 $count = 0;
847 foreach $parameter (@{$args{'parameterlist'}}) {
848 print "<li class=\"indent\">";
849 print "<span class=\"param\">" . $parameter . "</span>";
850 if ($count != $#{$args{'parameterlist'}}) {
851 $count++;
852 print ",";
853 }
854 print "</li>\n";
855 }
856 print "<li>};</li>\n";
857 print "</ol>\n";
858
859 print "<section>\n";
860 print "<h1>Constants</h1>\n";
861 print "<dl>\n";
862 foreach $parameter (@{$args{'parameterlist'}}) {
863 print "<dt>" . $parameter . "</dt>\n";
864 print "<dd>";
865 output_highlight($args{'parameterdescs'}{$parameter});
866 print "</dd>\n";
867 }
868 print "</dl>\n";
869 print "</section>\n";
870 output_section_html5(@_);
871 print "</article>\n";
872}
873
874# output typedef in html5
875sub output_typedef_html5(%) {
876 my %args = %{$_[0]};
877 my ($parameter);
878 my $count;
879 my $html5id;
880
881 $html5id = $args{'typedef'};
882 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
883 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
884 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
885
886 print "<ol class=\"code\">\n";
887 print "<li>";
888 print "<span class=\"keyword\">typedef</span> ";
889 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
890 print "</li>\n";
891 print "</ol>\n";
892 output_section_html5(@_);
893 print "</article>\n";
894}
895
896# output struct in html5
897sub output_struct_html5(%) {
898 my %args = %{$_[0]};
899 my ($parameter);
900 my $html5id;
901
902 $html5id = $args{'struct'};
903 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
904 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
905 print "<hgroup>\n";
906 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
907 print "<h2>". $args{'purpose'} . "</h2>\n";
908 print "</hgroup>\n";
909 print "<ol class=\"code\">\n";
910 print "<li>";
911 print "<span class=\"type\">" . $args{'type'} . "</span> ";
912 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
913 print "</li>\n";
914 foreach $parameter (@{$args{'parameterlist'}}) {
915 print "<li class=\"indent\">";
916 if ($parameter =~ /^#/) {
917 print "<span class=\"param\">" . $parameter ."</span>\n";
918 print "</li>\n";
919 next;
920 }
921 my $parameter_name = $parameter;
922 $parameter_name =~ s/\[.*//;
923
924 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
925 $type = $args{'parametertypes'}{$parameter};
926 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
927 # pointer-to-function
928 print "<span class=\"type\">$1</span> ";
929 print "<span class=\"param\">$parameter</span>";
930 print "<span class=\"type\">)</span> ";
931 print "(<span class=\"args\">$2</span>);";
932 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
933 # bitfield
934 print "<span class=\"type\">$1</span> ";
935 print "<span class=\"param\">$parameter</span>";
936 print "<span class=\"bits\">$2</span>;";
937 } else {
938 print "<span class=\"type\">$type</span> ";
939 print "<span class=\"param\">$parameter</span>;";
940 }
941 print "</li>\n";
942 }
943 print "<li>};</li>\n";
944 print "</ol>\n";
945
946 print "<section>\n";
947 print "<h1>Members</h1>\n";
948 print "<dl>\n";
949 foreach $parameter (@{$args{'parameterlist'}}) {
950 ($parameter =~ /^#/) && next;
951
952 my $parameter_name = $parameter;
953 $parameter_name =~ s/\[.*//;
954
955 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
956 print "<dt>" . $parameter . "</dt>\n";
957 print "<dd>";
958 output_highlight($args{'parameterdescs'}{$parameter_name});
959 print "</dd>\n";
960 }
961 print "</dl>\n";
962 print "</section>\n";
963 output_section_html5(@_);
964 print "</article>\n";
965}
966
967# output function in html5
968sub output_function_html5(%) {
969 my %args = %{$_[0]};
970 my ($parameter, $section);
971 my $count;
972 my $html5id;
973
974 $html5id = $args{'function'};
975 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
976 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
977 print "<hgroup>\n";
978 print "<h1>" . $args{'function'} . "</h1>";
979 print "<h2>" . $args{'purpose'} . "</h2>\n";
980 print "</hgroup>\n";
981 print "<ol class=\"code\">\n";
982 print "<li>";
983 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
984 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
985 print "</li>";
986 $count = 0;
987 foreach $parameter (@{$args{'parameterlist'}}) {
988 print "<li class=\"indent\">";
989 $type = $args{'parametertypes'}{$parameter};
990 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
991 # pointer-to-function
992 print "<span class=\"type\">$1</span> ";
993 print "<span class=\"param\">$parameter</span>";
994 print "<span class=\"type\">)</span> ";
995 print "(<span class=\"args\">$2</span>)";
996 } else {
997 print "<span class=\"type\">$type</span> ";
998 print "<span class=\"param\">$parameter</span>";
999 }
1000 if ($count != $#{$args{'parameterlist'}}) {
1001 $count++;
1002 print ",";
1003 }
1004 print "</li>\n";
1005 }
1006 print "<li>)</li>\n";
1007 print "</ol>\n";
1008
1009 print "<section>\n";
1010 print "<h1>Arguments</h1>\n";
1011 print "<p>\n";
1012 print "<dl>\n";
1013 foreach $parameter (@{$args{'parameterlist'}}) {
1014 my $parameter_name = $parameter;
1015 $parameter_name =~ s/\[.*//;
1016
1017 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1018 print "<dt>" . $parameter . "</dt>\n";
1019 print "<dd>";
1020 output_highlight($args{'parameterdescs'}{$parameter_name});
1021 print "</dd>\n";
1022 }
1023 print "</dl>\n";
1024 print "</section>\n";
1025 output_section_html5(@_);
1026 print "</article>\n";
1027}
1028
1029# output DOC: block header in html5
1030sub output_blockhead_html5(%) {
1031 my %args = %{$_[0]};
1032 my ($parameter, $section);
1033 my $count;
1034 my $html5id;
1035
1036 foreach $section (@{$args{'sectionlist'}}) {
1037 $html5id = $section;
1038 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1039 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1040 print "<h1>$section</h1>\n";
1041 print "<p>\n";
1042 output_highlight($args{'sections'}{$section});
1043 print "</p>\n";
1044 }
1045 print "</article>\n";
1046}
1047
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048sub output_section_xml(%) {
1049 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001050 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 # print out each section
1052 $lineprefix=" ";
1053 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001054 print "<refsect1>\n";
1055 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001057 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001058 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001059 } else {
1060 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061 }
1062 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001063 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001065 print "</programlisting></informalexample>\n";
1066 } else {
1067 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001069 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 }
1071}
1072
1073# output function in XML DocBook
1074sub output_function_xml(%) {
1075 my %args = %{$_[0]};
1076 my ($parameter, $section);
1077 my $count;
1078 my $id;
1079
Randy Dunlapb9d973282009-06-09 08:50:38 -07001080 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 $id =~ s/[^A-Za-z0-9]/-/g;
1082
Pavel Pisa5449bc92007-02-10 01:45:37 -08001083 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001084 print "<refentryinfo>\n";
1085 print " <title>LINUX</title>\n";
1086 print " <productname>Kernel Hackers Manual</productname>\n";
1087 print " <date>$man_date</date>\n";
1088 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001090 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001091 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001092 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 print "</refmeta>\n";
1094 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001095 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 print " <refpurpose>\n";
1097 print " ";
1098 output_highlight ($args{'purpose'});
1099 print " </refpurpose>\n";
1100 print "</refnamediv>\n";
1101
1102 print "<refsynopsisdiv>\n";
1103 print " <title>Synopsis</title>\n";
1104 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001105 print " <funcdef>" . $args{'functiontype'} . " ";
1106 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
1108 $count = 0;
1109 if ($#{$args{'parameterlist'}} >= 0) {
1110 foreach $parameter (@{$args{'parameterlist'}}) {
1111 $type = $args{'parametertypes'}{$parameter};
1112 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1113 # pointer-to-function
1114 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1115 print " <funcparams>$2</funcparams></paramdef>\n";
1116 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001117 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 print " <parameter>$parameter</parameter></paramdef>\n";
1119 }
1120 }
1121 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001122 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 }
1124 print " </funcprototype></funcsynopsis>\n";
1125 print "</refsynopsisdiv>\n";
1126
1127 # print parameters
1128 print "<refsect1>\n <title>Arguments</title>\n";
1129 if ($#{$args{'parameterlist'}} >= 0) {
1130 print " <variablelist>\n";
1131 foreach $parameter (@{$args{'parameterlist'}}) {
1132 my $parameter_name = $parameter;
1133 $parameter_name =~ s/\[.*//;
Paolo Bonzinifc6d7af2017-01-02 16:22:25 +01001134 $type = $args{'parametertypes'}{$parameter};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Paolo Bonzinifc6d7af2017-01-02 16:22:25 +01001136 print " <varlistentry>\n <term><parameter>$type $parameter</parameter></term>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137 print " <listitem>\n <para>\n";
1138 $lineprefix=" ";
1139 output_highlight($args{'parameterdescs'}{$parameter_name});
1140 print " </para>\n </listitem>\n </varlistentry>\n";
1141 }
1142 print " </variablelist>\n";
1143 } else {
1144 print " <para>\n None\n </para>\n";
1145 }
1146 print "</refsect1>\n";
1147
1148 output_section_xml(@_);
1149 print "</refentry>\n\n";
1150}
1151
1152# output struct in XML DocBook
1153sub output_struct_xml(%) {
1154 my %args = %{$_[0]};
1155 my ($parameter, $section);
1156 my $id;
1157
Randy Dunlapb9d973282009-06-09 08:50:38 -07001158 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 $id =~ s/[^A-Za-z0-9]/-/g;
1160
Pavel Pisa5449bc92007-02-10 01:45:37 -08001161 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001162 print "<refentryinfo>\n";
1163 print " <title>LINUX</title>\n";
1164 print " <productname>Kernel Hackers Manual</productname>\n";
1165 print " <date>$man_date</date>\n";
1166 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001168 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001169 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001170 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 print "</refmeta>\n";
1172 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001173 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 print " <refpurpose>\n";
1175 print " ";
1176 output_highlight ($args{'purpose'});
1177 print " </refpurpose>\n";
1178 print "</refnamediv>\n";
1179
1180 print "<refsynopsisdiv>\n";
1181 print " <title>Synopsis</title>\n";
1182 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001183 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 foreach $parameter (@{$args{'parameterlist'}}) {
1185 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001186 my $prm = $parameter;
1187 # convert data read & converted thru xml_escape() into &xyz; format:
1188 # This allows us to have #define macros interspersed in a struct.
1189 $prm =~ s/\\\\\\/\&/g;
1190 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 next;
1192 }
1193
1194 my $parameter_name = $parameter;
1195 $parameter_name =~ s/\[.*//;
1196
1197 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001198 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 $type = $args{'parametertypes'}{$parameter};
1200 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1201 # pointer-to-function
1202 print " $1 $parameter) ($2);\n";
1203 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001204 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 print " $1 $parameter$2;\n";
1206 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001207 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208 }
1209 }
1210 print "};";
1211 print " </programlisting>\n";
1212 print "</refsynopsisdiv>\n";
1213
1214 print " <refsect1>\n";
1215 print " <title>Members</title>\n";
1216
Randy Dunlap39f00c02008-09-22 13:57:44 -07001217 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218 print " <variablelist>\n";
1219 foreach $parameter (@{$args{'parameterlist'}}) {
1220 ($parameter =~ /^#/) && next;
1221
1222 my $parameter_name = $parameter;
1223 $parameter_name =~ s/\[.*//;
1224
1225 defined($args{'parameterdescs'}{$parameter_name}) || next;
1226 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Paolo Bonzinifc6d7af2017-01-02 16:22:25 +01001227 $type = $args{'parametertypes'}{$parameter};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 print " <varlistentry>";
Paolo Bonzinifc6d7af2017-01-02 16:22:25 +01001229 print " <term><literal>$type $parameter</literal></term>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 print " <listitem><para>\n";
1231 output_highlight($args{'parameterdescs'}{$parameter_name});
1232 print " </para></listitem>\n";
1233 print " </varlistentry>\n";
1234 }
1235 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001236 } else {
1237 print " <para>\n None\n </para>\n";
1238 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 print " </refsect1>\n";
1240
1241 output_section_xml(@_);
1242
1243 print "</refentry>\n\n";
1244}
1245
1246# output enum in XML DocBook
1247sub output_enum_xml(%) {
1248 my %args = %{$_[0]};
1249 my ($parameter, $section);
1250 my $count;
1251 my $id;
1252
Randy Dunlapb9d973282009-06-09 08:50:38 -07001253 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 $id =~ s/[^A-Za-z0-9]/-/g;
1255
Pavel Pisa5449bc92007-02-10 01:45:37 -08001256 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001257 print "<refentryinfo>\n";
1258 print " <title>LINUX</title>\n";
1259 print " <productname>Kernel Hackers Manual</productname>\n";
1260 print " <date>$man_date</date>\n";
1261 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001263 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001264 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001265 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 print "</refmeta>\n";
1267 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001268 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 print " <refpurpose>\n";
1270 print " ";
1271 output_highlight ($args{'purpose'});
1272 print " </refpurpose>\n";
1273 print "</refnamediv>\n";
1274
1275 print "<refsynopsisdiv>\n";
1276 print " <title>Synopsis</title>\n";
1277 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001278 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 $count = 0;
1280 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001281 print " $parameter";
1282 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 $count++;
1284 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001285 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 print "\n";
1287 }
1288 print "};";
1289 print " </programlisting>\n";
1290 print "</refsynopsisdiv>\n";
1291
1292 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001293 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 print " <variablelist>\n";
1295 foreach $parameter (@{$args{'parameterlist'}}) {
1296 my $parameter_name = $parameter;
1297 $parameter_name =~ s/\[.*//;
1298
1299 print " <varlistentry>";
1300 print " <term>$parameter</term>\n";
1301 print " <listitem><para>\n";
1302 output_highlight($args{'parameterdescs'}{$parameter_name});
1303 print " </para></listitem>\n";
1304 print " </varlistentry>\n";
1305 }
1306 print " </variablelist>\n";
1307 print "</refsect1>\n";
1308
1309 output_section_xml(@_);
1310
1311 print "</refentry>\n\n";
1312}
1313
1314# output typedef in XML DocBook
1315sub output_typedef_xml(%) {
1316 my %args = %{$_[0]};
1317 my ($parameter, $section);
1318 my $id;
1319
Randy Dunlapb9d973282009-06-09 08:50:38 -07001320 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 $id =~ s/[^A-Za-z0-9]/-/g;
1322
Pavel Pisa5449bc92007-02-10 01:45:37 -08001323 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001324 print "<refentryinfo>\n";
1325 print " <title>LINUX</title>\n";
1326 print " <productname>Kernel Hackers Manual</productname>\n";
1327 print " <date>$man_date</date>\n";
1328 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001330 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001331 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 print "</refmeta>\n";
1333 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001334 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 print " <refpurpose>\n";
1336 print " ";
1337 output_highlight ($args{'purpose'});
1338 print " </refpurpose>\n";
1339 print "</refnamediv>\n";
1340
1341 print "<refsynopsisdiv>\n";
1342 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001343 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 print "</refsynopsisdiv>\n";
1345
1346 output_section_xml(@_);
1347
1348 print "</refentry>\n\n";
1349}
1350
1351# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001352sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 my %args = %{$_[0]};
1354 my ($parameter, $section);
1355 my $count;
1356
1357 my $id = $args{'module'};
1358 $id =~ s/[^A-Za-z0-9]/-/g;
1359
1360 # print out each section
1361 $lineprefix=" ";
1362 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001363 if (!$args{'content-only'}) {
1364 print "<refsect1>\n <title>$section</title>\n";
1365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 if ($section =~ m/EXAMPLE/i) {
1367 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001368 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001369 } else {
1370 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 }
1372 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001373 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374 if ($section =~ m/EXAMPLE/i) {
1375 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001376 } else {
1377 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001379 if (!$args{'content-only'}) {
1380 print "\n</refsect1>\n";
1381 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 }
1383
1384 print "\n\n";
1385}
1386
1387# output in XML DocBook
1388sub output_function_gnome {
1389 my %args = %{$_[0]};
1390 my ($parameter, $section);
1391 my $count;
1392 my $id;
1393
Randy Dunlapb9d973282009-06-09 08:50:38 -07001394 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 $id =~ s/[^A-Za-z0-9]/-/g;
1396
1397 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001398 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399
1400 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001401 print " <funcdef>" . $args{'functiontype'} . " ";
1402 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 print "</function></funcdef>\n";
1404
1405 $count = 0;
1406 if ($#{$args{'parameterlist'}} >= 0) {
1407 foreach $parameter (@{$args{'parameterlist'}}) {
1408 $type = $args{'parametertypes'}{$parameter};
1409 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1410 # pointer-to-function
1411 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1412 print " <funcparams>$2</funcparams></paramdef>\n";
1413 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001414 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415 print " <parameter>$parameter</parameter></paramdef>\n";
1416 }
1417 }
1418 } else {
1419 print " <void>\n";
1420 }
1421 print " </funcsynopsis>\n";
1422 if ($#{$args{'parameterlist'}} >= 0) {
1423 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1424 print "<tgroup cols=\"2\">\n";
1425 print "<colspec colwidth=\"2*\">\n";
1426 print "<colspec colwidth=\"8*\">\n";
1427 print "<tbody>\n";
1428 foreach $parameter (@{$args{'parameterlist'}}) {
1429 my $parameter_name = $parameter;
1430 $parameter_name =~ s/\[.*//;
1431
1432 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1433 print " <entry>\n";
1434 $lineprefix=" ";
1435 output_highlight($args{'parameterdescs'}{$parameter_name});
1436 print " </entry></row>\n";
1437 }
1438 print " </tbody></tgroup></informaltable>\n";
1439 } else {
1440 print " <para>\n None\n </para>\n";
1441 }
1442
1443 # print out each section
1444 $lineprefix=" ";
1445 foreach $section (@{$args{'sectionlist'}}) {
1446 print "<simplesect>\n <title>$section</title>\n";
1447 if ($section =~ m/EXAMPLE/i) {
1448 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001449 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 } else {
1451 }
1452 print "<para>\n";
1453 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001454 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 print "</para>\n";
1456 if ($section =~ m/EXAMPLE/i) {
1457 print "</programlisting></example>\n";
1458 } else {
1459 }
1460 print " </simplesect>\n";
1461 }
1462
1463 print "</sect2>\n\n";
1464}
1465
1466##
1467# output function in man
1468sub output_function_man(%) {
1469 my %args = %{$_[0]};
1470 my ($parameter, $section);
1471 my $count;
1472
1473 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1474
1475 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001476 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
1478 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001479 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001480 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001481 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001482 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001483 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 $count = 0;
1485 my $parenth = "(";
1486 my $post = ",";
1487 foreach my $parameter (@{$args{'parameterlist'}}) {
1488 if ($count == $#{$args{'parameterlist'}}) {
1489 $post = ");";
1490 }
1491 $type = $args{'parametertypes'}{$parameter};
1492 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1493 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001494 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 } else {
1496 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001497 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 }
1499 $count++;
1500 $parenth = "";
1501 }
1502
1503 print ".SH ARGUMENTS\n";
1504 foreach $parameter (@{$args{'parameterlist'}}) {
1505 my $parameter_name = $parameter;
1506 $parameter_name =~ s/\[.*//;
1507
Randy Dunlapb9d973282009-06-09 08:50:38 -07001508 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 output_highlight($args{'parameterdescs'}{$parameter_name});
1510 }
1511 foreach $section (@{$args{'sectionlist'}}) {
1512 print ".SH \"", uc $section, "\"\n";
1513 output_highlight($args{'sections'}{$section});
1514 }
1515}
1516
1517##
1518# output enum in man
1519sub output_enum_man(%) {
1520 my %args = %{$_[0]};
1521 my ($parameter, $section);
1522 my $count;
1523
1524 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1525
1526 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001527 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
1529 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001530 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 $count = 0;
1532 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001533 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 if ($count == $#{$args{'parameterlist'}}) {
1535 print "\n};\n";
1536 last;
1537 }
1538 else {
1539 print ", \n.br\n";
1540 }
1541 $count++;
1542 }
1543
1544 print ".SH Constants\n";
1545 foreach $parameter (@{$args{'parameterlist'}}) {
1546 my $parameter_name = $parameter;
1547 $parameter_name =~ s/\[.*//;
1548
Randy Dunlapb9d973282009-06-09 08:50:38 -07001549 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 output_highlight($args{'parameterdescs'}{$parameter_name});
1551 }
1552 foreach $section (@{$args{'sectionlist'}}) {
1553 print ".SH \"$section\"\n";
1554 output_highlight($args{'sections'}{$section});
1555 }
1556}
1557
1558##
1559# output struct in man
1560sub output_struct_man(%) {
1561 my %args = %{$_[0]};
1562 my ($parameter, $section);
1563
Randy Dunlapb9d973282009-06-09 08:50:38 -07001564 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
1566 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001567 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
1569 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001570 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571
1572 foreach my $parameter (@{$args{'parameterlist'}}) {
1573 if ($parameter =~ /^#/) {
1574 print ".BI \"$parameter\"\n.br\n";
1575 next;
1576 }
1577 my $parameter_name = $parameter;
1578 $parameter_name =~ s/\[.*//;
1579
Randy Dunlap3c308792007-05-08 00:24:39 -07001580 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 $type = $args{'parametertypes'}{$parameter};
1582 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1583 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001584 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001586 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001587 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 } else {
1589 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001590 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 }
1592 print "\n.br\n";
1593 }
1594 print "};\n.br\n";
1595
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001596 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 foreach $parameter (@{$args{'parameterlist'}}) {
1598 ($parameter =~ /^#/) && next;
1599
1600 my $parameter_name = $parameter;
1601 $parameter_name =~ s/\[.*//;
1602
Randy Dunlap3c308792007-05-08 00:24:39 -07001603 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001604 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 output_highlight($args{'parameterdescs'}{$parameter_name});
1606 }
1607 foreach $section (@{$args{'sectionlist'}}) {
1608 print ".SH \"$section\"\n";
1609 output_highlight($args{'sections'}{$section});
1610 }
1611}
1612
1613##
1614# output typedef in man
1615sub output_typedef_man(%) {
1616 my %args = %{$_[0]};
1617 my ($parameter, $section);
1618
1619 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1620
1621 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001622 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623
1624 foreach $section (@{$args{'sectionlist'}}) {
1625 print ".SH \"$section\"\n";
1626 output_highlight($args{'sections'}{$section});
1627 }
1628}
1629
Johannes Bergb112e0f2007-10-24 15:08:48 -07001630sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 my %args = %{$_[0]};
1632 my ($parameter, $section);
1633 my $count;
1634
1635 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1636
1637 foreach $section (@{$args{'sectionlist'}}) {
1638 print ".SH \"$section\"\n";
1639 output_highlight($args{'sections'}{$section});
1640 }
1641}
1642
1643##
1644# output in text
1645sub output_function_text(%) {
1646 my %args = %{$_[0]};
1647 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001648 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
Randy Dunlapf47634b2006-07-01 04:36:36 -07001650 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001651 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001652
1653 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001654 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001655 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001656 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001657 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001658 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001660
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 my $count = 0;
1662 foreach my $parameter (@{$args{'parameterlist'}}) {
1663 $type = $args{'parametertypes'}{$parameter};
1664 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1665 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001666 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001668 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 }
1670 if ($count != $#{$args{'parameterlist'}}) {
1671 $count++;
1672 print ",\n";
1673 print " " x length($start);
1674 } else {
1675 print ");\n\n";
1676 }
1677 }
1678
1679 print "Arguments:\n\n";
1680 foreach $parameter (@{$args{'parameterlist'}}) {
1681 my $parameter_name = $parameter;
1682 $parameter_name =~ s/\[.*//;
1683
Randy Dunlapb9d973282009-06-09 08:50:38 -07001684 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 }
1686 output_section_text(@_);
1687}
1688
1689#output sections in text
1690sub output_section_text(%) {
1691 my %args = %{$_[0]};
1692 my $section;
1693
1694 print "\n";
1695 foreach $section (@{$args{'sectionlist'}}) {
1696 print "$section:\n\n";
1697 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001698 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 print "\n\n";
1700}
1701
1702# output enum in text
1703sub output_enum_text(%) {
1704 my %args = %{$_[0]};
1705 my ($parameter);
1706 my $count;
1707 print "Enum:\n\n";
1708
Randy Dunlapb9d973282009-06-09 08:50:38 -07001709 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1710 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 $count = 0;
1712 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001713 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 if ($count != $#{$args{'parameterlist'}}) {
1715 $count++;
1716 print ",";
1717 }
1718 print "\n";
1719 }
1720 print "};\n\n";
1721
1722 print "Constants:\n\n";
1723 foreach $parameter (@{$args{'parameterlist'}}) {
1724 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001725 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 }
1727
1728 output_section_text(@_);
1729}
1730
1731# output typedef in text
1732sub output_typedef_text(%) {
1733 my %args = %{$_[0]};
1734 my ($parameter);
1735 my $count;
1736 print "Typedef:\n\n";
1737
Randy Dunlapb9d973282009-06-09 08:50:38 -07001738 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 output_section_text(@_);
1740}
1741
1742# output struct as text
1743sub output_struct_text(%) {
1744 my %args = %{$_[0]};
1745 my ($parameter);
1746
Randy Dunlapb9d973282009-06-09 08:50:38 -07001747 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1748 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 foreach $parameter (@{$args{'parameterlist'}}) {
1750 if ($parameter =~ /^#/) {
1751 print "$parameter\n";
1752 next;
1753 }
1754
1755 my $parameter_name = $parameter;
1756 $parameter_name =~ s/\[.*//;
1757
Randy Dunlap3c308792007-05-08 00:24:39 -07001758 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 $type = $args{'parametertypes'}{$parameter};
1760 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1761 # pointer-to-function
1762 print "\t$1 $parameter) ($2);\n";
1763 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001764 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 print "\t$1 $parameter$2;\n";
1766 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001767 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 }
1769 }
1770 print "};\n\n";
1771
1772 print "Members:\n\n";
1773 foreach $parameter (@{$args{'parameterlist'}}) {
1774 ($parameter =~ /^#/) && next;
1775
1776 my $parameter_name = $parameter;
1777 $parameter_name =~ s/\[.*//;
1778
Randy Dunlap3c308792007-05-08 00:24:39 -07001779 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001781 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 }
1783 print "\n";
1784 output_section_text(@_);
1785}
1786
Johannes Bergb112e0f2007-10-24 15:08:48 -07001787sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 my %args = %{$_[0]};
1789 my ($parameter, $section);
1790
1791 foreach $section (@{$args{'sectionlist'}}) {
1792 print " $section:\n";
1793 print " -> ";
1794 output_highlight($args{'sections'}{$section});
1795 }
1796}
1797
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001798##
1799# output in restructured text
1800#
1801
1802#
1803# This could use some work; it's used to output the DOC: sections, and
1804# starts by putting out the name of the doc section itself, but that tends
1805# to duplicate a header already in the template file.
1806#
1807sub output_blockhead_rst(%) {
1808 my %args = %{$_[0]};
1809 my ($parameter, $section);
1810
1811 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001812 if ($output_selection != OUTPUT_INCLUDE) {
1813 print "**$section**\n\n";
1814 }
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001815 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001816 output_highlight_rst($args{'sections'}{$section});
1817 print "\n";
1818 }
1819}
1820
1821sub output_highlight_rst {
1822 my $contents = join "\n",@_;
1823 my $line;
1824
1825 # undo the evil effects of xml_escape() earlier
1826 $contents = xml_unescape($contents);
1827
1828 eval $dohighlight;
1829 die $@ if $@;
1830
1831 foreach $line (split "\n", $contents) {
Jani Nikula830066a2016-05-26 22:04:33 +03001832 print $lineprefix . $line . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001833 }
1834}
1835
1836sub output_function_rst(%) {
1837 my %args = %{$_[0]};
1838 my ($parameter, $section);
Jani Nikulac099ff62016-05-26 17:18:17 +03001839 my $oldprefix = $lineprefix;
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001840 my $start = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001841
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001842 if ($args{'typedef'}) {
1843 print ".. c:type:: ". $args{'function'} . "\n\n";
1844 print_lineno($declaration_start_line);
1845 print " **Typedef**: ";
1846 $lineprefix = "";
1847 output_highlight_rst($args{'purpose'});
1848 $start = "\n\n**Syntax**\n\n ``";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001849 } else {
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001850 print ".. c:function:: ";
1851 }
1852 if ($args{'functiontype'} ne "") {
1853 $start .= $args{'functiontype'} . " " . $args{'function'} . " (";
1854 } else {
1855 $start .= $args{'function'} . " (";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001856 }
1857 print $start;
1858
1859 my $count = 0;
1860 foreach my $parameter (@{$args{'parameterlist'}}) {
1861 if ($count ne 0) {
1862 print ", ";
1863 }
1864 $count++;
1865 $type = $args{'parametertypes'}{$parameter};
Mauro Carvalho Chehaba88b1672016-07-22 11:46:36 -03001866
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001867 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1868 # pointer-to-function
1869 print $1 . $parameter . ") (" . $2;
1870 } else {
1871 print $type . " " . $parameter;
1872 }
1873 }
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001874 if ($args{'typedef'}) {
1875 print ");``\n\n";
1876 } else {
1877 print ")\n\n";
1878 print_lineno($declaration_start_line);
1879 $lineprefix = " ";
1880 output_highlight_rst($args{'purpose'});
1881 print "\n";
1882 }
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001883
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001884 print "**Parameters**\n\n";
1885 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001886 foreach $parameter (@{$args{'parameterlist'}}) {
1887 my $parameter_name = $parameter;
1888 #$parameter_name =~ s/\[.*//;
1889 $type = $args{'parametertypes'}{$parameter};
1890
1891 if ($type ne "") {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001892 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001893 } else {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001894 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001895 }
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001896
1897 print_lineno($parameterdesc_start_lines{$parameter_name});
1898
Jani Nikula5e64fa92016-05-19 20:32:48 +03001899 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1900 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001901 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001902 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001903 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001904 }
1905 print "\n";
1906 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001907
1908 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001909 output_section_rst(@_);
1910}
1911
1912sub output_section_rst(%) {
1913 my %args = %{$_[0]};
1914 my $section;
1915 my $oldprefix = $lineprefix;
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001916 $lineprefix = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001917
1918 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001919 print "**$section**\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001920 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001921 output_highlight_rst($args{'sections'}{$section});
1922 print "\n";
1923 }
1924 print "\n";
1925 $lineprefix = $oldprefix;
1926}
1927
1928sub output_enum_rst(%) {
1929 my %args = %{$_[0]};
1930 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001931 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001932 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001933 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001934
1935 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001936 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001937 $lineprefix = " ";
1938 output_highlight_rst($args{'purpose'});
1939 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001940
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001941 print "**Constants**\n\n";
1942 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001943 foreach $parameter (@{$args{'parameterlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001944 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001945 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1946 output_highlight_rst($args{'parameterdescs'}{$parameter});
1947 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001948 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001949 }
1950 print "\n";
1951 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001952
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001953 $lineprefix = $oldprefix;
1954 output_section_rst(@_);
1955}
1956
1957sub output_typedef_rst(%) {
1958 my %args = %{$_[0]};
1959 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001960 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001961 my $name = "typedef " . $args{'typedef'};
1962
Jani Nikula62850972016-05-12 16:15:38 +03001963 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001964 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001965 $lineprefix = " ";
1966 output_highlight_rst($args{'purpose'});
1967 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001968
Jani Nikulac099ff62016-05-26 17:18:17 +03001969 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001970 output_section_rst(@_);
1971}
1972
1973sub output_struct_rst(%) {
1974 my %args = %{$_[0]};
1975 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001976 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001977 my $name = $args{'type'} . " " . $args{'struct'};
1978
Jani Nikula62850972016-05-12 16:15:38 +03001979 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001980 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001981 $lineprefix = " ";
1982 output_highlight_rst($args{'purpose'});
1983 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001984
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001985 print "**Definition**\n\n";
1986 print "::\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001987 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1988 foreach $parameter (@{$args{'parameterlist'}}) {
1989 if ($parameter =~ /^#/) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001990 print " " . "$parameter\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001991 next;
1992 }
1993
1994 my $parameter_name = $parameter;
1995 $parameter_name =~ s/\[.*//;
1996
1997 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1998 $type = $args{'parametertypes'}{$parameter};
1999 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
2000 # pointer-to-function
2001 print " $1 $parameter) ($2);\n";
2002 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
2003 # bitfield
2004 print " $1 $parameter$2;\n";
2005 } else {
2006 print " " . $type . " " . $parameter . ";\n";
2007 }
2008 }
2009 print " };\n\n";
2010
Jani Nikulaecbcfba2016-05-26 18:30:27 +03002011 print "**Members**\n\n";
2012 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002013 foreach $parameter (@{$args{'parameterlist'}}) {
2014 ($parameter =~ /^#/) && next;
2015
2016 my $parameter_name = $parameter;
2017 $parameter_name =~ s/\[.*//;
2018
2019 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
2020 $type = $args{'parametertypes'}{$parameter};
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002021 print_lineno($parameterdesc_start_lines{$parameter_name});
Mauro Carvalho Chehab6d232c82016-08-22 22:02:57 -03002022 print "``" . $parameter . "``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002023 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002024 print "\n";
2025 }
2026 print "\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03002027
2028 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002029 output_section_rst(@_);
2030}
2031
2032
Johannes Bergeda603f2010-09-11 15:55:22 -07002033## list mode output functions
2034
2035sub output_function_list(%) {
2036 my %args = %{$_[0]};
2037
2038 print $args{'function'} . "\n";
2039}
2040
2041# output enum in list
2042sub output_enum_list(%) {
2043 my %args = %{$_[0]};
2044 print $args{'enum'} . "\n";
2045}
2046
2047# output typedef in list
2048sub output_typedef_list(%) {
2049 my %args = %{$_[0]};
2050 print $args{'typedef'} . "\n";
2051}
2052
2053# output struct as list
2054sub output_struct_list(%) {
2055 my %args = %{$_[0]};
2056
2057 print $args{'struct'} . "\n";
2058}
2059
2060sub output_blockhead_list(%) {
2061 my %args = %{$_[0]};
2062 my ($parameter, $section);
2063
2064 foreach $section (@{$args{'sectionlist'}}) {
2065 print "DOC: $section\n";
2066 }
2067}
2068
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069##
Randy Dunlap27205742006-10-11 01:22:12 -07002070# generic output function for all types (function, struct/union, typedef, enum);
2071# calls the generated, variable output_ function name based on
2072# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073sub output_declaration {
2074 no strict 'refs';
2075 my $name = shift;
2076 my $functype = shift;
2077 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002078 if (($output_selection == OUTPUT_ALL) ||
2079 (($output_selection == OUTPUT_INCLUDE ||
2080 $output_selection == OUTPUT_EXPORTED) &&
2081 defined($function_table{$name})) ||
2082 (($output_selection == OUTPUT_EXCLUDE ||
2083 $output_selection == OUTPUT_INTERNAL) &&
2084 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002086 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087 $section_counter++;
2088 }
2089}
2090
2091##
Randy Dunlap27205742006-10-11 01:22:12 -07002092# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002093sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002095 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 &$func(@_);
2097 $section_counter++;
2098}
2099
2100##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002101# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102# invokes the right handler. NOT called for functions.
2103sub dump_declaration($$) {
2104 no strict 'refs';
2105 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002106 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 &$func(@_);
2108}
2109
2110sub dump_union($$) {
2111 dump_struct(@_);
2112}
2113
2114sub dump_struct($$) {
2115 my $x = shift;
2116 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002117 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002119 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2120 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002121 $declaration_name = $2;
2122 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123
2124 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002125 $members =~ s/({.*})//g;
2126 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127
Martin Waitzaeec46b2005-11-13 16:08:13 -08002128 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002129 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2130 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002131 # strip comments:
2132 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002133 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002134 # strip kmemcheck_bitfield_{begin,end}.*;
2135 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002136 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002137 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002138 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002139 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002140 # replace DECLARE_BITMAP
2141 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002142
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002144 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145
2146 output_declaration($declaration_name,
2147 'struct',
2148 {'struct' => $declaration_name,
2149 'module' => $modulename,
2150 'parameterlist' => \@parameterlist,
2151 'parameterdescs' => \%parameterdescs,
2152 'parametertypes' => \%parametertypes,
2153 'sectionlist' => \@sectionlist,
2154 'sections' => \%sections,
2155 'purpose' => $declaration_purpose,
2156 'type' => $decl_type
2157 });
2158 }
2159 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002160 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 ++$errors;
2162 }
2163}
2164
2165sub dump_enum($$) {
2166 my $x = shift;
2167 my $file = shift;
2168
Martin Waitzaeec46b2005-11-13 16:08:13 -08002169 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002170 # strip #define macros inside enums
2171 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002172
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002174 $declaration_name = $1;
2175 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
2177 foreach my $arg (split ',', $members) {
2178 $arg =~ s/^\s*(\w+).*/$1/;
2179 push @parameterlist, $arg;
2180 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002181 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002182 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 "not described in enum '$declaration_name'\n";
2184 }
2185
2186 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002187
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 output_declaration($declaration_name,
2189 'enum',
2190 {'enum' => $declaration_name,
2191 'module' => $modulename,
2192 'parameterlist' => \@parameterlist,
2193 'parameterdescs' => \%parameterdescs,
2194 'sectionlist' => \@sectionlist,
2195 'sections' => \%sections,
2196 'purpose' => $declaration_purpose
2197 });
2198 }
2199 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002200 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 ++$errors;
2202 }
2203}
2204
2205sub dump_typedef($$) {
2206 my $x = shift;
2207 my $file = shift;
2208
Martin Waitzaeec46b2005-11-13 16:08:13 -08002209 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002210
2211 # Parse function prototypes
Mauro Carvalho Chehabd37c43c2016-08-30 20:20:57 -03002212 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ ||
2213 $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) {
2214
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002215 # Function typedefs
2216 $return_type = $1;
2217 $declaration_name = $2;
2218 my $args = $3;
2219
2220 create_parameterlist($args, ',', $file);
2221
2222 output_declaration($declaration_name,
2223 'function',
2224 {'function' => $declaration_name,
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03002225 'typedef' => 1,
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002226 'module' => $modulename,
2227 'functiontype' => $return_type,
2228 'parameterlist' => \@parameterlist,
2229 'parameterdescs' => \%parameterdescs,
2230 'parametertypes' => \%parametertypes,
2231 'sectionlist' => \@sectionlist,
2232 'sections' => \%sections,
2233 'purpose' => $declaration_purpose
2234 });
2235 return;
2236 }
2237
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002239 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 $x =~ s/\[*.\]\s*;$/;/;
2241 }
2242
2243 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002244 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
2246 output_declaration($declaration_name,
2247 'typedef',
2248 {'typedef' => $declaration_name,
2249 'module' => $modulename,
2250 'sectionlist' => \@sectionlist,
2251 'sections' => \%sections,
2252 'purpose' => $declaration_purpose
2253 });
2254 }
2255 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002256 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 ++$errors;
2258 }
2259}
2260
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002261sub save_struct_actual($) {
2262 my $actual = shift;
2263
2264 # strip all spaces from the actual param so that it looks like one string item
2265 $actual =~ s/\s*//g;
2266 $struct_actual = $struct_actual . $actual . " ";
2267}
2268
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269sub create_parameterlist($$$) {
2270 my $args = shift;
2271 my $splitter = shift;
2272 my $file = shift;
2273 my $type;
2274 my $param;
2275
Martin Waitza6d3fe72006-01-09 20:53:55 -08002276 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002278 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002280
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 foreach my $arg (split($splitter, $args)) {
2282 # strip comments
2283 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002284 # strip leading/trailing spaces
2285 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 $arg =~ s/\s*$//;
2287 $arg =~ s/\s+/ /;
2288
2289 if ($arg =~ /^#/) {
2290 # Treat preprocessor directive as a typeless variable just to fill
2291 # corresponding data structures "correctly". Catch it later in
2292 # output_* subs.
2293 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002294 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 # pointer-to-function
2296 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002297 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 $param = $1;
2299 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002300 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002301 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002303 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 $arg =~ s/\s*:\s*/:/g;
2305 $arg =~ s/\s*\[/\[/g;
2306
2307 my @args = split('\s*,\s*', $arg);
2308 if ($args[0] =~ m/\*/) {
2309 $args[0] =~ s/(\*+)\s*/ $1/;
2310 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002311
2312 my @first_arg;
2313 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2314 shift @args;
2315 push(@first_arg, split('\s+', $1));
2316 push(@first_arg, $2);
2317 } else {
2318 @first_arg = split('\s+', shift @args);
2319 }
2320
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 unshift(@args, pop @first_arg);
2322 $type = join " ", @first_arg;
2323
2324 foreach $param (@args) {
2325 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002326 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 push_parameter($2, "$type $1", $file);
2328 }
2329 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002330 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002331 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002332 push_parameter($1, "$type:$2", $file)
2333 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 }
2335 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002336 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 push_parameter($param, $type, $file);
2338 }
2339 }
2340 }
2341 }
2342}
2343
2344sub push_parameter($$$) {
2345 my $param = shift;
2346 my $type = shift;
2347 my $file = shift;
2348
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002349 if (($anon_struct_union == 1) && ($type eq "") &&
2350 ($param eq "}")) {
2351 return; # ignore the ending }; from anon. struct/union
2352 }
2353
2354 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 my $param_name = $param;
2356 $param_name =~ s/\[.*//;
2357
Martin Waitza6d3fe72006-01-09 20:53:55 -08002358 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 {
Silvio Frickec950a172016-10-28 10:14:08 +02002360 if (!$param =~ /\w\.\.\.$/) {
2361 # handles unnamed variable parameters
2362 $param = "...";
2363 }
Randy Dunlapced69092008-12-01 13:14:03 -08002364 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2365 $parameterdescs{$param} = "variable arguments";
2366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 }
2368 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2369 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 $param="void";
2371 $parameterdescs{void} = "no arguments";
2372 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002373 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2374 # handle unnamed (anonymous) union or struct:
2375 {
2376 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002377 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002378 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002379 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002380 }
2381
Martin Waitza6d3fe72006-01-09 20:53:55 -08002382 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002383 # (but ignore ones starting with # as these are not parameters
2384 # but inline preprocessor statements);
2385 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002386 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002387 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2388
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389 $parameterdescs{$param_name} = $undescribed;
2390
2391 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002392 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 "or member '$param' not " .
2394 "described in '$declaration_name'\n";
2395 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002396 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002397 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002399 }
2400 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002402 $param = xml_escape($param);
2403
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002404 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002405 # on @parameterlist;
2406 # this fixes a problem where check_sections() cannot find
2407 # a parameter like "addr[6 + 2]" because it actually appears
2408 # as "addr[6", "+", "2]" on the parameter list;
2409 # but it's better to maintain the param string unchanged for output,
2410 # so just weaken the string compare in check_sections() to ignore
2411 # "[blah" in a parameter string;
2412 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 push @parameterlist, $param;
Paolo Bonzini02a4f4f2017-01-02 16:22:23 +01002414 $type =~ s/\s\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 $parametertypes{$param} = $type;
2416}
2417
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002418sub check_sections($$$$$$) {
2419 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2420 my @sects = split ' ', $sectcheck;
2421 my @prms = split ' ', $prmscheck;
2422 my $err;
2423 my ($px, $sx);
2424 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2425
2426 foreach $sx (0 .. $#sects) {
2427 $err = 1;
2428 foreach $px (0 .. $#prms) {
2429 $prm_clean = $prms[$px];
2430 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002431 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002432 # ignore array size in a parameter string;
2433 # however, the original param string may contain
2434 # spaces, e.g.: addr[6 + 2]
2435 # and this appears in @prms as "addr[6" since the
2436 # parameter list is split at spaces;
2437 # hence just ignore "[..." for the sections check;
2438 $prm_clean =~ s/\[.*//;
2439
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002440 ##$prm_clean =~ s/^\**//;
2441 if ($prm_clean eq $sects[$sx]) {
2442 $err = 0;
2443 last;
2444 }
2445 }
2446 if ($err) {
2447 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002448 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002449 "Excess function parameter " .
2450 "'$sects[$sx]' " .
2451 "description in '$decl_name'\n";
2452 ++$warnings;
2453 } else {
2454 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002455 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002456 "Excess struct/union/enum/typedef member " .
2457 "'$sects[$sx]' " .
2458 "description in '$decl_name'\n";
2459 ++$warnings;
2460 }
2461 }
2462 }
2463 }
2464}
2465
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002467# Checks the section describing the return value of a function.
2468sub check_return_section {
2469 my $file = shift;
2470 my $declaration_name = shift;
2471 my $return_type = shift;
2472
2473 # Ignore an empty return type (It's a macro)
2474 # Ignore functions with a "void" return type. (But don't ignore "void *")
2475 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2476 return;
2477 }
2478
2479 if (!defined($sections{$section_return}) ||
2480 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002481 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002482 "No description found for return value of " .
2483 "'$declaration_name'\n";
2484 ++$warnings;
2485 }
2486}
2487
2488##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489# takes a function prototype and the name of the current file being
2490# processed and spits out all the details stored in the global
2491# arrays/hashes.
2492sub dump_function($$) {
2493 my $prototype = shift;
2494 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002495 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496
2497 $prototype =~ s/^static +//;
2498 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002499 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 $prototype =~ s/^inline +//;
2501 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002502 $prototype =~ s/^__inline +//;
2503 $prototype =~ s/^__always_inline +//;
2504 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002505 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002506 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002507 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002508 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002509 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002510 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Paolo Bonzinib1aaa542017-01-02 16:22:24 +01002511 $prototype =~ s/__attribute__\s*\(\(
2512 (?:
2513 [\w\s]++ # attribute name
2514 (?:\([^)]*+\))? # attribute arguments
2515 \s*+,? # optional comma at the end
2516 )+
2517 \)\)\s+//x;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
2519 # Yes, this truly is vile. We are looking for:
2520 # 1. Return type (may be nothing if we're looking at a macro)
2521 # 2. Function name
2522 # 3. Function parameters.
2523 #
2524 # All the while we have to watch out for function pointer parameters
2525 # (which IIRC is what the two sections are for), C types (these
2526 # regexps don't even start to express all the possibilities), and
2527 # so on.
2528 #
2529 # If you mess with these regexps, it's a good idea to check that
2530 # the following functions' documentation still comes out right:
2531 # - parport_register_device (function pointer parameters)
2532 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002533 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002535 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2536 # This is an object-like macro, it has no return type and no parameter
2537 # list.
2538 # Function-like macros are not allowed to have spaces between
2539 # declaration_name and opening parenthesis (notice the \s+).
2540 $return_type = $1;
2541 $declaration_name = $2;
2542 $noret = 1;
2543 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2545 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2546 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002547 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2549 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2550 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2551 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2552 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2553 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2554 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2555 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002556 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2557 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002558 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2559 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 $return_type = $1;
2561 $declaration_name = $2;
2562 my $args = $3;
2563
2564 create_parameterlist($args, ',', $file);
2565 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002566 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 return;
2568 }
2569
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002570 my $prms = join " ", @parameterlist;
2571 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2572
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002573 # This check emits a lot of warnings at the moment, because many
2574 # functions don't have a 'Return' doc section. So until the number
2575 # of warnings goes sufficiently down, the check is only performed in
2576 # verbose mode.
2577 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002578 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002579 check_return_section($file, $declaration_name, $return_type);
2580 }
2581
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002582 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 'function',
2584 {'function' => $declaration_name,
2585 'module' => $modulename,
2586 'functiontype' => $return_type,
2587 'parameterlist' => \@parameterlist,
2588 'parameterdescs' => \%parameterdescs,
2589 'parametertypes' => \%parametertypes,
2590 'sectionlist' => \@sectionlist,
2591 'sections' => \%sections,
2592 'purpose' => $declaration_purpose
2593 });
2594}
2595
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596sub reset_state {
2597 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 %parameterdescs = ();
2599 %parametertypes = ();
2600 @parameterlist = ();
2601 %sections = ();
2602 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002603 $sectcheck = "";
2604 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002606
Jani Nikula48af6062016-05-26 14:56:05 +03002607 $state = STATE_NORMAL;
2608 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609}
2610
Jason Baron56afb0f2009-04-30 13:29:36 -04002611sub tracepoint_munge($) {
2612 my $file = shift;
2613 my $tracepointname = 0;
2614 my $tracepointargs = 0;
2615
Jason Baron3a9089f2009-12-01 12:18:49 -05002616 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002617 $tracepointname = $1;
2618 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002619 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2620 $tracepointname = $1;
2621 }
2622 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2623 $tracepointname = $2;
2624 }
2625 $tracepointname =~ s/^\s+//; #strip leading whitespace
2626 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002627 $tracepointargs = $1;
2628 }
2629 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002630 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002631 "$prototype\n";
2632 } else {
2633 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2634 }
2635}
2636
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002637sub syscall_munge() {
2638 my $void = 0;
2639
2640 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2641## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2642 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2643 $void = 1;
2644## $prototype = "long sys_$1(void)";
2645 }
2646
2647 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2648 if ($prototype =~ m/long (sys_.*?),/) {
2649 $prototype =~ s/,/\(/;
2650 } elsif ($void) {
2651 $prototype =~ s/\)/\(void\)/;
2652 }
2653
2654 # now delete all of the odd-number commas in $prototype
2655 # so that arg types & arg names don't have a comma between them
2656 my $count = 0;
2657 my $len = length($prototype);
2658 if ($void) {
2659 $len = 0; # skip the for-loop
2660 }
2661 for (my $ix = 0; $ix < $len; $ix++) {
2662 if (substr($prototype, $ix, 1) eq ',') {
2663 $count++;
2664 if ($count % 2 == 1) {
2665 substr($prototype, $ix, 1) = ' ';
2666 }
2667 }
2668 }
2669}
2670
Daniel Vetterb7afa922016-06-01 23:46:24 +02002671sub process_proto_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 my $x = shift;
2673 my $file = shift;
2674
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002675 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2676
Randy Dunlap890c78c2008-10-25 17:06:43 -07002677 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 # do nothing
2679 }
2680 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002681 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002683
Randy Dunlap890c78c2008-10-25 17:06:43 -07002684 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002685 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2687 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002688 if ($prototype =~ /SYSCALL_DEFINE/) {
2689 syscall_munge();
2690 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002691 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2692 $prototype =~ /DEFINE_SINGLE_EVENT/)
2693 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002694 tracepoint_munge($file);
2695 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002696 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 reset_state();
2698 }
2699}
2700
Daniel Vetterb7afa922016-06-01 23:46:24 +02002701sub process_proto_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 my $x = shift;
2703 my $file = shift;
2704
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2706 $x =~ s@^\s+@@gos; # strip leading spaces
2707 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002708 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2709
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 if ($x =~ /^#/) {
2711 # To distinguish preprocessor directive from regular declaration later.
2712 $x .= ";";
2713 }
2714
2715 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002716 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717 $prototype .= $1 . $2;
2718 ($2 eq '{') && $brcount++;
2719 ($2 eq '}') && $brcount--;
2720 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002721 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002723 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 }
2725 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002726 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 $prototype .= $x;
2728 last;
2729 }
2730 }
2731}
2732
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002733# xml_escape: replace <, >, and & in the text stream;
2734#
2735# however, formatting controls that are generated internally/locally in the
2736# kernel-doc script are not escaped here; instead, they begin life like
2737# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2738# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2739# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740sub xml_escape($) {
2741 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002742 if (($output_mode eq "text") || ($output_mode eq "man")) {
2743 return $text;
2744 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 $text =~ s/\&/\\\\\\amp;/g;
2746 $text =~ s/\</\\\\\\lt;/g;
2747 $text =~ s/\>/\\\\\\gt;/g;
2748 return $text;
2749}
2750
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002751# xml_unescape: reverse the effects of xml_escape
2752sub xml_unescape($) {
2753 my $text = shift;
2754 if (($output_mode eq "text") || ($output_mode eq "man")) {
2755 return $text;
2756 }
2757 $text =~ s/\\\\\\amp;/\&/g;
2758 $text =~ s/\\\\\\lt;/</g;
2759 $text =~ s/\\\\\\gt;/>/g;
2760 return $text;
2761}
2762
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002763# convert local escape strings to html
2764# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2765sub local_unescape($) {
2766 my $text = shift;
2767 if (($output_mode eq "text") || ($output_mode eq "man")) {
2768 return $text;
2769 }
2770 $text =~ s/\\\\\\\\lt:/</g;
2771 $text =~ s/\\\\\\\\gt:/>/g;
2772 return $text;
2773}
2774
Jani Nikula1ad560e2016-06-07 10:53:39 +03002775sub map_filename($) {
2776 my $file;
2777 my ($orig_file) = @_;
2778
2779 if (defined($ENV{'SRCTREE'})) {
2780 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
2781 } else {
2782 $file = $orig_file;
2783 }
2784
2785 if (defined($source_map{$file})) {
2786 $file = $source_map{$file};
2787 }
2788
2789 return $file;
2790}
2791
Jani Nikula88c2b572016-06-07 11:00:52 +03002792sub process_export_file($) {
2793 my ($orig_file) = @_;
2794 my $file = map_filename($orig_file);
2795
2796 if (!open(IN,"<$file")) {
2797 print STDERR "Error: Cannot open file $file\n";
2798 ++$errors;
2799 return;
2800 }
2801
2802 while (<IN>) {
2803 if (/$export_symbol/) {
2804 $function_table{$2} = 1;
2805 }
2806 }
2807
2808 close(IN);
2809}
2810
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002812 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 my $identifier;
2814 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002815 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002816 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002818 my ($orig_file) = @_;
Jani Nikulab7886de2016-05-28 00:41:50 +03002819 my $leading_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820
Jani Nikula1ad560e2016-06-07 10:53:39 +03002821 $file = map_filename($orig_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822
2823 if (!open(IN,"<$file")) {
2824 print STDERR "Error: Cannot open file $file\n";
2825 ++$errors;
2826 return;
2827 }
2828
Ilya Dryomova9e73142010-02-26 13:05:47 -08002829 $. = 1;
2830
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 $section_counter = 0;
2832 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002833 while (s/\\\s*$//) {
2834 $_ .= <IN>;
2835 }
Jani Nikula48af6062016-05-26 14:56:05 +03002836 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002838 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002839 $in_doc_sect = 0;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002840 $declaration_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 }
Jani Nikula48af6062016-05-26 14:56:05 +03002842 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002844 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002846 $new_start_line = $. + 1;
2847
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 if ( $1 eq "" ) {
2849 $section = $section_intro;
2850 } else {
2851 $section = $1;
2852 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002853 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 elsif (/$doc_decl/o) {
2855 $identifier = $1;
2856 if (/\s*([\w\s]+?)\s*-/) {
2857 $identifier = $1;
2858 }
2859
Jani Nikula48af6062016-05-26 14:56:05 +03002860 $state = STATE_FIELD;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002861 # if there's no @param blocks need to set up default section
2862 # here
Jani Nikula2f4ad402016-05-30 11:21:06 +03002863 $contents = "";
2864 $section = $section_default;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002865 $new_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002867 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002868 $descr= $1;
2869 $descr =~ s/^\s*//;
2870 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002871 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002872 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002873 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 } else {
2875 $declaration_purpose = "";
2876 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002877
2878 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002879 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002880 print STDERR $_;
2881 ++$warnings;
2882 }
2883
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 if ($identifier =~ m/^struct/) {
2885 $decl_type = 'struct';
2886 } elsif ($identifier =~ m/^union/) {
2887 $decl_type = 'union';
2888 } elsif ($identifier =~ m/^enum/) {
2889 $decl_type = 'enum';
2890 } elsif ($identifier =~ m/^typedef/) {
2891 $decl_type = 'typedef';
2892 } else {
2893 $decl_type = 'function';
2894 }
2895
2896 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002897 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 }
2899 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002900 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 " - I thought it was a doc line\n";
2902 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002903 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 }
Jani Nikula48af6062016-05-26 14:56:05 +03002905 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Jani Nikulaf624ade2016-05-29 11:35:28 +03002906 if (/$doc_sect/i) { # case insensitive for supported section names
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 $newsection = $1;
2908 $newcontents = $2;
2909
Jani Nikulaf624ade2016-05-29 11:35:28 +03002910 # map the supported section names to the canonical names
2911 if ($newsection =~ m/^description$/i) {
2912 $newsection = $section_default;
2913 } elsif ($newsection =~ m/^context$/i) {
2914 $newsection = $section_context;
2915 } elsif ($newsection =~ m/^returns?$/i) {
2916 $newsection = $section_return;
2917 } elsif ($newsection =~ m/^\@return$/) {
2918 # special: @return is a section, not a param description
2919 $newsection = $section_return;
2920 }
2921
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002922 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002923 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002924 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002925 ++$warnings;
2926 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002927 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 $section = $section_default;
2929 }
2930
Randy Dunlap850622d2006-06-25 05:48:55 -07002931 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002932 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 $contents = $newcontents;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002934 $new_start_line = $.;
Jani Nikula0a726302016-05-28 14:50:20 +03002935 while ((substr($contents, 0, 1) eq " ") ||
2936 substr($contents, 0, 1) eq "\t") {
2937 $contents = substr($contents, 1);
2938 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 if ($contents ne "") {
2940 $contents .= "\n";
2941 }
2942 $section = $newsection;
Jani Nikulab7886de2016-05-28 00:41:50 +03002943 $leading_space = undef;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002945 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002946 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 $section = $section_default;
2948 $contents = "";
2949 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002950 # look for doc_com + <text> + doc_end:
2951 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002952 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002953 ++$warnings;
2954 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955
2956 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002957 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002959# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 } elsif (/$doc_content/) {
2961 # miguel-style comment kludge, look for blank lines after
2962 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002963 if ($1 eq "") {
2964 if ($section =~ m/^@/ || $section eq $section_context) {
2965 dump_section($file, $section, xml_escape($contents));
2966 $section = $section_default;
2967 $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002968 $new_start_line = $.;
Johannes Weiner64231332009-09-17 19:26:53 -07002969 } else {
2970 $contents .= "\n";
2971 }
2972 $in_purpose = 0;
2973 } elsif ($in_purpose == 1) {
2974 # Continued declaration purpose
2975 chomp($declaration_purpose);
2976 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002977 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 } else {
Jani Nikulab7886de2016-05-28 00:41:50 +03002979 my $cont = $1;
2980 if ($section =~ m/^@/ || $section eq $section_context) {
2981 if (!defined $leading_space) {
2982 if ($cont =~ m/^(\s+)/) {
2983 $leading_space = $1;
2984 } else {
2985 $leading_space = "";
2986 }
2987 }
2988
2989 $cont =~ s/^$leading_space//;
2990 }
2991 $contents .= $cont . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 }
2993 } else {
2994 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002995 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 ++$warnings;
2997 }
Jani Nikula48af6062016-05-26 14:56:05 +03002998 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002999 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03003000 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003001 $section = $1;
3002 $contents = $2;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02003003 $new_start_line = $.;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003004 if ($contents ne "") {
3005 while ((substr($contents, 0, 1) eq " ") ||
3006 substr($contents, 0, 1) eq "\t") {
3007 $contents = substr($contents, 1);
3008 }
Jani Nikulaa0b96c22016-05-26 22:04:06 +03003009 $contents .= "\n";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003010 }
Jani Nikula48af6062016-05-26 14:56:05 +03003011 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003012 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03003013 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003014 if (($contents ne "") && ($contents ne "\n")) {
3015 dump_section($file, $section, xml_escape($contents));
3016 $section = $section_default;
3017 $contents = "";
3018 }
Jani Nikula48af6062016-05-26 14:56:05 +03003019 $state = STATE_PROTO;
3020 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003021 # Regular text
3022 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03003023 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003024 $contents .= $1 . "\n";
Jani Nikula6450c892016-05-26 22:04:42 +03003025 # nuke leading blank lines
3026 if ($contents =~ /^\s*$/) {
3027 $contents = "";
3028 }
Jani Nikula48af6062016-05-26 14:56:05 +03003029 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
3030 $inline_doc_state = STATE_INLINE_ERROR;
Daniel Vettere7ca3112016-07-15 10:19:30 +02003031 print STDERR "${file}:$.: warning: ";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003032 print STDERR "Incorrect use of kernel-doc format: $_";
3033 ++$warnings;
3034 }
3035 }
Jani Nikula48af6062016-05-26 14:56:05 +03003036 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
Jani Nikula0c9aa202016-11-16 17:26:16 +02003037 if (/$doc_inline_oneline/) {
3038 $section = $1;
3039 $contents = $2;
3040 if ($contents ne "") {
3041 $contents .= "\n";
3042 dump_section($file, $section, xml_escape($contents));
3043 $section = $section_default;
3044 $contents = "";
3045 }
3046 } elsif (/$doc_inline_start/) {
Jani Nikula48af6062016-05-26 14:56:05 +03003047 $state = STATE_INLINE;
3048 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003049 } elsif ($decl_type eq 'function') {
Daniel Vetterb7afa922016-06-01 23:46:24 +02003050 process_proto_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 } else {
Daniel Vetterb7afa922016-06-01 23:46:24 +02003052 process_proto_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 }
Jani Nikula48af6062016-05-26 14:56:05 +03003054 } elsif ($state == STATE_DOCBLOCK) {
Daniel Vetterebff7f92016-06-01 23:46:23 +02003055 if (/$doc_end/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07003057 dump_doc_section($file, $section, xml_escape($contents));
Jani Nikula2f4ad402016-05-30 11:21:06 +03003058 $section = $section_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 $contents = "";
3060 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 %parameterdescs = ();
3062 %parametertypes = ();
3063 @parameterlist = ();
3064 %sections = ();
3065 @sectionlist = ();
3066 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03003067 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 }
3069 elsif (/$doc_content/)
3070 {
3071 if ( $1 eq "" )
3072 {
3073 $contents .= $blankline;
3074 }
3075 else
3076 {
3077 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08003078 }
Randy Dunlap3c308792007-05-08 00:24:39 -07003079 }
3080 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 }
3082 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07003083 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03003084 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08003085 print STDERR " Was looking for '$_'.\n" for keys %function_table;
3086 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 if ($output_mode eq "xml") {
3088 # The template wants at least one RefEntry here; make one.
3089 print "<refentry>\n";
3090 print " <refnamediv>\n";
3091 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003092 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 print " </refname>\n";
3094 print " <refpurpose>\n";
3095 print " Document generation inconsistency\n";
3096 print " </refpurpose>\n";
3097 print " </refnamediv>\n";
3098 print " <refsect1>\n";
3099 print " <title>\n";
3100 print " Oops\n";
3101 print " </title>\n";
3102 print " <warning>\n";
3103 print " <para>\n";
3104 print " The template for this document tried to insert\n";
3105 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003106 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107 print " but none was found.\n";
3108 print " This dummy section is inserted to allow\n";
3109 print " generation to continue.\n";
3110 print " </para>\n";
3111 print " </warning>\n";
3112 print " </refsect1>\n";
3113 print "</refentry>\n";
3114 }
3115 }
3116}
Randy Dunlap8484baa2011-01-05 16:28:43 -08003117
3118
3119$kernelversion = get_kernel_version();
3120
3121# generate a sequence of code that will splice in highlighting information
3122# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02003123for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03003124 my $pattern = $highlights[$k][0];
3125 my $result = $highlights[$k][1];
3126# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
3127 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08003128}
3129
3130# Read the file that maps relative names to absolute names for
3131# separate source and object directories and for shadow trees.
3132if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3133 my ($relname, $absname);
3134 while(<SOURCE_MAP>) {
3135 chop();
3136 ($relname, $absname) = (split())[0..1];
3137 $relname =~ s:^/+::;
3138 $source_map{$relname} = $absname;
3139 }
3140 close(SOURCE_MAP);
3141}
3142
Jani Nikula88c2b572016-06-07 11:00:52 +03003143if ($output_selection == OUTPUT_EXPORTED ||
3144 $output_selection == OUTPUT_INTERNAL) {
Jani Nikulac9b2cfb2016-06-07 11:05:53 +03003145
3146 push(@export_file_list, @ARGV);
3147
Jani Nikula88c2b572016-06-07 11:00:52 +03003148 foreach (@export_file_list) {
3149 chomp;
3150 process_export_file($_);
3151 }
3152}
3153
Randy Dunlap8484baa2011-01-05 16:28:43 -08003154foreach (@ARGV) {
3155 chomp;
3156 process_file($_);
3157}
3158if ($verbose && $errors) {
3159 print STDERR "$errors errors\n";
3160}
3161if ($verbose && $warnings) {
3162 print STDERR "$warnings warnings\n";
3163}
3164
3165exit($errors);