blob: 030fc633acd4ab11c7b12ff942601a820fe1fab8 [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/\[.*//;
1134
1135 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1136 print " <listitem>\n <para>\n";
1137 $lineprefix=" ";
1138 output_highlight($args{'parameterdescs'}{$parameter_name});
1139 print " </para>\n </listitem>\n </varlistentry>\n";
1140 }
1141 print " </variablelist>\n";
1142 } else {
1143 print " <para>\n None\n </para>\n";
1144 }
1145 print "</refsect1>\n";
1146
1147 output_section_xml(@_);
1148 print "</refentry>\n\n";
1149}
1150
1151# output struct in XML DocBook
1152sub output_struct_xml(%) {
1153 my %args = %{$_[0]};
1154 my ($parameter, $section);
1155 my $id;
1156
Randy Dunlapb9d973282009-06-09 08:50:38 -07001157 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 $id =~ s/[^A-Za-z0-9]/-/g;
1159
Pavel Pisa5449bc92007-02-10 01:45:37 -08001160 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001161 print "<refentryinfo>\n";
1162 print " <title>LINUX</title>\n";
1163 print " <productname>Kernel Hackers Manual</productname>\n";
1164 print " <date>$man_date</date>\n";
1165 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001167 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001168 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001169 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 print "</refmeta>\n";
1171 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001172 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 print " <refpurpose>\n";
1174 print " ";
1175 output_highlight ($args{'purpose'});
1176 print " </refpurpose>\n";
1177 print "</refnamediv>\n";
1178
1179 print "<refsynopsisdiv>\n";
1180 print " <title>Synopsis</title>\n";
1181 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001182 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 foreach $parameter (@{$args{'parameterlist'}}) {
1184 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001185 my $prm = $parameter;
1186 # convert data read & converted thru xml_escape() into &xyz; format:
1187 # This allows us to have #define macros interspersed in a struct.
1188 $prm =~ s/\\\\\\/\&/g;
1189 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 next;
1191 }
1192
1193 my $parameter_name = $parameter;
1194 $parameter_name =~ s/\[.*//;
1195
1196 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001197 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 $type = $args{'parametertypes'}{$parameter};
1199 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1200 # pointer-to-function
1201 print " $1 $parameter) ($2);\n";
1202 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001203 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 print " $1 $parameter$2;\n";
1205 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001206 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 }
1208 }
1209 print "};";
1210 print " </programlisting>\n";
1211 print "</refsynopsisdiv>\n";
1212
1213 print " <refsect1>\n";
1214 print " <title>Members</title>\n";
1215
Randy Dunlap39f00c02008-09-22 13:57:44 -07001216 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 print " <variablelist>\n";
1218 foreach $parameter (@{$args{'parameterlist'}}) {
1219 ($parameter =~ /^#/) && next;
1220
1221 my $parameter_name = $parameter;
1222 $parameter_name =~ s/\[.*//;
1223
1224 defined($args{'parameterdescs'}{$parameter_name}) || next;
1225 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1226 print " <varlistentry>";
1227 print " <term>$parameter</term>\n";
1228 print " <listitem><para>\n";
1229 output_highlight($args{'parameterdescs'}{$parameter_name});
1230 print " </para></listitem>\n";
1231 print " </varlistentry>\n";
1232 }
1233 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001234 } else {
1235 print " <para>\n None\n </para>\n";
1236 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 print " </refsect1>\n";
1238
1239 output_section_xml(@_);
1240
1241 print "</refentry>\n\n";
1242}
1243
1244# output enum in XML DocBook
1245sub output_enum_xml(%) {
1246 my %args = %{$_[0]};
1247 my ($parameter, $section);
1248 my $count;
1249 my $id;
1250
Randy Dunlapb9d973282009-06-09 08:50:38 -07001251 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 $id =~ s/[^A-Za-z0-9]/-/g;
1253
Pavel Pisa5449bc92007-02-10 01:45:37 -08001254 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001255 print "<refentryinfo>\n";
1256 print " <title>LINUX</title>\n";
1257 print " <productname>Kernel Hackers Manual</productname>\n";
1258 print " <date>$man_date</date>\n";
1259 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001261 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001262 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001263 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 print "</refmeta>\n";
1265 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001266 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 print " <refpurpose>\n";
1268 print " ";
1269 output_highlight ($args{'purpose'});
1270 print " </refpurpose>\n";
1271 print "</refnamediv>\n";
1272
1273 print "<refsynopsisdiv>\n";
1274 print " <title>Synopsis</title>\n";
1275 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001276 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 $count = 0;
1278 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001279 print " $parameter";
1280 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 $count++;
1282 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001283 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 print "\n";
1285 }
1286 print "};";
1287 print " </programlisting>\n";
1288 print "</refsynopsisdiv>\n";
1289
1290 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001291 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 print " <variablelist>\n";
1293 foreach $parameter (@{$args{'parameterlist'}}) {
1294 my $parameter_name = $parameter;
1295 $parameter_name =~ s/\[.*//;
1296
1297 print " <varlistentry>";
1298 print " <term>$parameter</term>\n";
1299 print " <listitem><para>\n";
1300 output_highlight($args{'parameterdescs'}{$parameter_name});
1301 print " </para></listitem>\n";
1302 print " </varlistentry>\n";
1303 }
1304 print " </variablelist>\n";
1305 print "</refsect1>\n";
1306
1307 output_section_xml(@_);
1308
1309 print "</refentry>\n\n";
1310}
1311
1312# output typedef in XML DocBook
1313sub output_typedef_xml(%) {
1314 my %args = %{$_[0]};
1315 my ($parameter, $section);
1316 my $id;
1317
Randy Dunlapb9d973282009-06-09 08:50:38 -07001318 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 $id =~ s/[^A-Za-z0-9]/-/g;
1320
Pavel Pisa5449bc92007-02-10 01:45:37 -08001321 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001322 print "<refentryinfo>\n";
1323 print " <title>LINUX</title>\n";
1324 print " <productname>Kernel Hackers Manual</productname>\n";
1325 print " <date>$man_date</date>\n";
1326 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001328 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001329 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 print "</refmeta>\n";
1331 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001332 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333 print " <refpurpose>\n";
1334 print " ";
1335 output_highlight ($args{'purpose'});
1336 print " </refpurpose>\n";
1337 print "</refnamediv>\n";
1338
1339 print "<refsynopsisdiv>\n";
1340 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001341 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 print "</refsynopsisdiv>\n";
1343
1344 output_section_xml(@_);
1345
1346 print "</refentry>\n\n";
1347}
1348
1349# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001350sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 my %args = %{$_[0]};
1352 my ($parameter, $section);
1353 my $count;
1354
1355 my $id = $args{'module'};
1356 $id =~ s/[^A-Za-z0-9]/-/g;
1357
1358 # print out each section
1359 $lineprefix=" ";
1360 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001361 if (!$args{'content-only'}) {
1362 print "<refsect1>\n <title>$section</title>\n";
1363 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 if ($section =~ m/EXAMPLE/i) {
1365 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001366 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001367 } else {
1368 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 }
1370 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001371 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 if ($section =~ m/EXAMPLE/i) {
1373 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001374 } else {
1375 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001377 if (!$args{'content-only'}) {
1378 print "\n</refsect1>\n";
1379 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 }
1381
1382 print "\n\n";
1383}
1384
1385# output in XML DocBook
1386sub output_function_gnome {
1387 my %args = %{$_[0]};
1388 my ($parameter, $section);
1389 my $count;
1390 my $id;
1391
Randy Dunlapb9d973282009-06-09 08:50:38 -07001392 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 $id =~ s/[^A-Za-z0-9]/-/g;
1394
1395 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001396 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
1398 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001399 print " <funcdef>" . $args{'functiontype'} . " ";
1400 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 print "</function></funcdef>\n";
1402
1403 $count = 0;
1404 if ($#{$args{'parameterlist'}} >= 0) {
1405 foreach $parameter (@{$args{'parameterlist'}}) {
1406 $type = $args{'parametertypes'}{$parameter};
1407 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1408 # pointer-to-function
1409 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1410 print " <funcparams>$2</funcparams></paramdef>\n";
1411 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001412 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 print " <parameter>$parameter</parameter></paramdef>\n";
1414 }
1415 }
1416 } else {
1417 print " <void>\n";
1418 }
1419 print " </funcsynopsis>\n";
1420 if ($#{$args{'parameterlist'}} >= 0) {
1421 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1422 print "<tgroup cols=\"2\">\n";
1423 print "<colspec colwidth=\"2*\">\n";
1424 print "<colspec colwidth=\"8*\">\n";
1425 print "<tbody>\n";
1426 foreach $parameter (@{$args{'parameterlist'}}) {
1427 my $parameter_name = $parameter;
1428 $parameter_name =~ s/\[.*//;
1429
1430 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1431 print " <entry>\n";
1432 $lineprefix=" ";
1433 output_highlight($args{'parameterdescs'}{$parameter_name});
1434 print " </entry></row>\n";
1435 }
1436 print " </tbody></tgroup></informaltable>\n";
1437 } else {
1438 print " <para>\n None\n </para>\n";
1439 }
1440
1441 # print out each section
1442 $lineprefix=" ";
1443 foreach $section (@{$args{'sectionlist'}}) {
1444 print "<simplesect>\n <title>$section</title>\n";
1445 if ($section =~ m/EXAMPLE/i) {
1446 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001447 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 } else {
1449 }
1450 print "<para>\n";
1451 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001452 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 print "</para>\n";
1454 if ($section =~ m/EXAMPLE/i) {
1455 print "</programlisting></example>\n";
1456 } else {
1457 }
1458 print " </simplesect>\n";
1459 }
1460
1461 print "</sect2>\n\n";
1462}
1463
1464##
1465# output function in man
1466sub output_function_man(%) {
1467 my %args = %{$_[0]};
1468 my ($parameter, $section);
1469 my $count;
1470
1471 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1472
1473 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001474 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
1476 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001477 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001478 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001479 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001480 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001481 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 $count = 0;
1483 my $parenth = "(";
1484 my $post = ",";
1485 foreach my $parameter (@{$args{'parameterlist'}}) {
1486 if ($count == $#{$args{'parameterlist'}}) {
1487 $post = ");";
1488 }
1489 $type = $args{'parametertypes'}{$parameter};
1490 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1491 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001492 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493 } else {
1494 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001495 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 }
1497 $count++;
1498 $parenth = "";
1499 }
1500
1501 print ".SH ARGUMENTS\n";
1502 foreach $parameter (@{$args{'parameterlist'}}) {
1503 my $parameter_name = $parameter;
1504 $parameter_name =~ s/\[.*//;
1505
Randy Dunlapb9d973282009-06-09 08:50:38 -07001506 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 output_highlight($args{'parameterdescs'}{$parameter_name});
1508 }
1509 foreach $section (@{$args{'sectionlist'}}) {
1510 print ".SH \"", uc $section, "\"\n";
1511 output_highlight($args{'sections'}{$section});
1512 }
1513}
1514
1515##
1516# output enum in man
1517sub output_enum_man(%) {
1518 my %args = %{$_[0]};
1519 my ($parameter, $section);
1520 my $count;
1521
1522 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1523
1524 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001525 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
1527 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001528 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 $count = 0;
1530 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001531 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 if ($count == $#{$args{'parameterlist'}}) {
1533 print "\n};\n";
1534 last;
1535 }
1536 else {
1537 print ", \n.br\n";
1538 }
1539 $count++;
1540 }
1541
1542 print ".SH Constants\n";
1543 foreach $parameter (@{$args{'parameterlist'}}) {
1544 my $parameter_name = $parameter;
1545 $parameter_name =~ s/\[.*//;
1546
Randy Dunlapb9d973282009-06-09 08:50:38 -07001547 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 output_highlight($args{'parameterdescs'}{$parameter_name});
1549 }
1550 foreach $section (@{$args{'sectionlist'}}) {
1551 print ".SH \"$section\"\n";
1552 output_highlight($args{'sections'}{$section});
1553 }
1554}
1555
1556##
1557# output struct in man
1558sub output_struct_man(%) {
1559 my %args = %{$_[0]};
1560 my ($parameter, $section);
1561
Randy Dunlapb9d973282009-06-09 08:50:38 -07001562 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563
1564 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001565 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
1567 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001568 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
1570 foreach my $parameter (@{$args{'parameterlist'}}) {
1571 if ($parameter =~ /^#/) {
1572 print ".BI \"$parameter\"\n.br\n";
1573 next;
1574 }
1575 my $parameter_name = $parameter;
1576 $parameter_name =~ s/\[.*//;
1577
Randy Dunlap3c308792007-05-08 00:24:39 -07001578 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 $type = $args{'parametertypes'}{$parameter};
1580 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1581 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001582 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001584 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001585 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 } else {
1587 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001588 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 }
1590 print "\n.br\n";
1591 }
1592 print "};\n.br\n";
1593
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001594 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 foreach $parameter (@{$args{'parameterlist'}}) {
1596 ($parameter =~ /^#/) && next;
1597
1598 my $parameter_name = $parameter;
1599 $parameter_name =~ s/\[.*//;
1600
Randy Dunlap3c308792007-05-08 00:24:39 -07001601 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001602 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 output_highlight($args{'parameterdescs'}{$parameter_name});
1604 }
1605 foreach $section (@{$args{'sectionlist'}}) {
1606 print ".SH \"$section\"\n";
1607 output_highlight($args{'sections'}{$section});
1608 }
1609}
1610
1611##
1612# output typedef in man
1613sub output_typedef_man(%) {
1614 my %args = %{$_[0]};
1615 my ($parameter, $section);
1616
1617 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1618
1619 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001620 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621
1622 foreach $section (@{$args{'sectionlist'}}) {
1623 print ".SH \"$section\"\n";
1624 output_highlight($args{'sections'}{$section});
1625 }
1626}
1627
Johannes Bergb112e0f2007-10-24 15:08:48 -07001628sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 my %args = %{$_[0]};
1630 my ($parameter, $section);
1631 my $count;
1632
1633 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1634
1635 foreach $section (@{$args{'sectionlist'}}) {
1636 print ".SH \"$section\"\n";
1637 output_highlight($args{'sections'}{$section});
1638 }
1639}
1640
1641##
1642# output in text
1643sub output_function_text(%) {
1644 my %args = %{$_[0]};
1645 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001646 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
Randy Dunlapf47634b2006-07-01 04:36:36 -07001648 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001649 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001650
1651 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001652 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001653 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001654 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001655 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001658
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 my $count = 0;
1660 foreach my $parameter (@{$args{'parameterlist'}}) {
1661 $type = $args{'parametertypes'}{$parameter};
1662 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1663 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001664 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001666 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 }
1668 if ($count != $#{$args{'parameterlist'}}) {
1669 $count++;
1670 print ",\n";
1671 print " " x length($start);
1672 } else {
1673 print ");\n\n";
1674 }
1675 }
1676
1677 print "Arguments:\n\n";
1678 foreach $parameter (@{$args{'parameterlist'}}) {
1679 my $parameter_name = $parameter;
1680 $parameter_name =~ s/\[.*//;
1681
Randy Dunlapb9d973282009-06-09 08:50:38 -07001682 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 }
1684 output_section_text(@_);
1685}
1686
1687#output sections in text
1688sub output_section_text(%) {
1689 my %args = %{$_[0]};
1690 my $section;
1691
1692 print "\n";
1693 foreach $section (@{$args{'sectionlist'}}) {
1694 print "$section:\n\n";
1695 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001696 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 print "\n\n";
1698}
1699
1700# output enum in text
1701sub output_enum_text(%) {
1702 my %args = %{$_[0]};
1703 my ($parameter);
1704 my $count;
1705 print "Enum:\n\n";
1706
Randy Dunlapb9d973282009-06-09 08:50:38 -07001707 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1708 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 $count = 0;
1710 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001711 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 if ($count != $#{$args{'parameterlist'}}) {
1713 $count++;
1714 print ",";
1715 }
1716 print "\n";
1717 }
1718 print "};\n\n";
1719
1720 print "Constants:\n\n";
1721 foreach $parameter (@{$args{'parameterlist'}}) {
1722 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001723 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 }
1725
1726 output_section_text(@_);
1727}
1728
1729# output typedef in text
1730sub output_typedef_text(%) {
1731 my %args = %{$_[0]};
1732 my ($parameter);
1733 my $count;
1734 print "Typedef:\n\n";
1735
Randy Dunlapb9d973282009-06-09 08:50:38 -07001736 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 output_section_text(@_);
1738}
1739
1740# output struct as text
1741sub output_struct_text(%) {
1742 my %args = %{$_[0]};
1743 my ($parameter);
1744
Randy Dunlapb9d973282009-06-09 08:50:38 -07001745 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1746 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 foreach $parameter (@{$args{'parameterlist'}}) {
1748 if ($parameter =~ /^#/) {
1749 print "$parameter\n";
1750 next;
1751 }
1752
1753 my $parameter_name = $parameter;
1754 $parameter_name =~ s/\[.*//;
1755
Randy Dunlap3c308792007-05-08 00:24:39 -07001756 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 $type = $args{'parametertypes'}{$parameter};
1758 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1759 # pointer-to-function
1760 print "\t$1 $parameter) ($2);\n";
1761 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001762 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 print "\t$1 $parameter$2;\n";
1764 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001765 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 }
1767 }
1768 print "};\n\n";
1769
1770 print "Members:\n\n";
1771 foreach $parameter (@{$args{'parameterlist'}}) {
1772 ($parameter =~ /^#/) && next;
1773
1774 my $parameter_name = $parameter;
1775 $parameter_name =~ s/\[.*//;
1776
Randy Dunlap3c308792007-05-08 00:24:39 -07001777 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001779 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780 }
1781 print "\n";
1782 output_section_text(@_);
1783}
1784
Johannes Bergb112e0f2007-10-24 15:08:48 -07001785sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 my %args = %{$_[0]};
1787 my ($parameter, $section);
1788
1789 foreach $section (@{$args{'sectionlist'}}) {
1790 print " $section:\n";
1791 print " -> ";
1792 output_highlight($args{'sections'}{$section});
1793 }
1794}
1795
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001796##
1797# output in restructured text
1798#
1799
1800#
1801# This could use some work; it's used to output the DOC: sections, and
1802# starts by putting out the name of the doc section itself, but that tends
1803# to duplicate a header already in the template file.
1804#
1805sub output_blockhead_rst(%) {
1806 my %args = %{$_[0]};
1807 my ($parameter, $section);
1808
1809 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001810 if ($output_selection != OUTPUT_INCLUDE) {
1811 print "**$section**\n\n";
1812 }
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001813 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001814 output_highlight_rst($args{'sections'}{$section});
1815 print "\n";
1816 }
1817}
1818
1819sub output_highlight_rst {
1820 my $contents = join "\n",@_;
1821 my $line;
1822
1823 # undo the evil effects of xml_escape() earlier
1824 $contents = xml_unescape($contents);
1825
1826 eval $dohighlight;
1827 die $@ if $@;
1828
1829 foreach $line (split "\n", $contents) {
Jani Nikula830066a2016-05-26 22:04:33 +03001830 print $lineprefix . $line . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001831 }
1832}
1833
1834sub output_function_rst(%) {
1835 my %args = %{$_[0]};
1836 my ($parameter, $section);
Jani Nikulac099ff62016-05-26 17:18:17 +03001837 my $oldprefix = $lineprefix;
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001838 my $start = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001839
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001840 if ($args{'typedef'}) {
1841 print ".. c:type:: ". $args{'function'} . "\n\n";
1842 print_lineno($declaration_start_line);
1843 print " **Typedef**: ";
1844 $lineprefix = "";
1845 output_highlight_rst($args{'purpose'});
1846 $start = "\n\n**Syntax**\n\n ``";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001847 } else {
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001848 print ".. c:function:: ";
1849 }
1850 if ($args{'functiontype'} ne "") {
1851 $start .= $args{'functiontype'} . " " . $args{'function'} . " (";
1852 } else {
1853 $start .= $args{'function'} . " (";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001854 }
1855 print $start;
1856
1857 my $count = 0;
1858 foreach my $parameter (@{$args{'parameterlist'}}) {
1859 if ($count ne 0) {
1860 print ", ";
1861 }
1862 $count++;
1863 $type = $args{'parametertypes'}{$parameter};
Mauro Carvalho Chehaba88b1672016-07-22 11:46:36 -03001864
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001865 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1866 # pointer-to-function
1867 print $1 . $parameter . ") (" . $2;
1868 } else {
1869 print $type . " " . $parameter;
1870 }
1871 }
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03001872 if ($args{'typedef'}) {
1873 print ");``\n\n";
1874 } else {
1875 print ")\n\n";
1876 print_lineno($declaration_start_line);
1877 $lineprefix = " ";
1878 output_highlight_rst($args{'purpose'});
1879 print "\n";
1880 }
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001881
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001882 print "**Parameters**\n\n";
1883 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001884 foreach $parameter (@{$args{'parameterlist'}}) {
1885 my $parameter_name = $parameter;
1886 #$parameter_name =~ s/\[.*//;
1887 $type = $args{'parametertypes'}{$parameter};
1888
1889 if ($type ne "") {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001890 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001891 } else {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001892 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001893 }
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001894
1895 print_lineno($parameterdesc_start_lines{$parameter_name});
1896
Jani Nikula5e64fa92016-05-19 20:32:48 +03001897 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1898 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001899 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001900 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001901 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001902 }
1903 print "\n";
1904 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001905
1906 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001907 output_section_rst(@_);
1908}
1909
1910sub output_section_rst(%) {
1911 my %args = %{$_[0]};
1912 my $section;
1913 my $oldprefix = $lineprefix;
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001914 $lineprefix = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001915
1916 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001917 print "**$section**\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001918 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001919 output_highlight_rst($args{'sections'}{$section});
1920 print "\n";
1921 }
1922 print "\n";
1923 $lineprefix = $oldprefix;
1924}
1925
1926sub output_enum_rst(%) {
1927 my %args = %{$_[0]};
1928 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001929 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001930 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001931 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001932
1933 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001934 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001935 $lineprefix = " ";
1936 output_highlight_rst($args{'purpose'});
1937 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001938
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001939 print "**Constants**\n\n";
1940 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001941 foreach $parameter (@{$args{'parameterlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001942 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001943 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1944 output_highlight_rst($args{'parameterdescs'}{$parameter});
1945 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001946 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001947 }
1948 print "\n";
1949 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001950
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001951 $lineprefix = $oldprefix;
1952 output_section_rst(@_);
1953}
1954
1955sub output_typedef_rst(%) {
1956 my %args = %{$_[0]};
1957 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001958 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001959 my $name = "typedef " . $args{'typedef'};
1960
Jani Nikula62850972016-05-12 16:15:38 +03001961 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001962 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001963 $lineprefix = " ";
1964 output_highlight_rst($args{'purpose'});
1965 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001966
Jani Nikulac099ff62016-05-26 17:18:17 +03001967 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001968 output_section_rst(@_);
1969}
1970
1971sub output_struct_rst(%) {
1972 my %args = %{$_[0]};
1973 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001974 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001975 my $name = $args{'type'} . " " . $args{'struct'};
1976
Jani Nikula62850972016-05-12 16:15:38 +03001977 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001978 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001979 $lineprefix = " ";
1980 output_highlight_rst($args{'purpose'});
1981 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001982
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001983 print "**Definition**\n\n";
1984 print "::\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001985 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1986 foreach $parameter (@{$args{'parameterlist'}}) {
1987 if ($parameter =~ /^#/) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001988 print " " . "$parameter\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001989 next;
1990 }
1991
1992 my $parameter_name = $parameter;
1993 $parameter_name =~ s/\[.*//;
1994
1995 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1996 $type = $args{'parametertypes'}{$parameter};
1997 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1998 # pointer-to-function
1999 print " $1 $parameter) ($2);\n";
2000 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
2001 # bitfield
2002 print " $1 $parameter$2;\n";
2003 } else {
2004 print " " . $type . " " . $parameter . ";\n";
2005 }
2006 }
2007 print " };\n\n";
2008
Jani Nikulaecbcfba2016-05-26 18:30:27 +03002009 print "**Members**\n\n";
2010 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002011 foreach $parameter (@{$args{'parameterlist'}}) {
2012 ($parameter =~ /^#/) && next;
2013
2014 my $parameter_name = $parameter;
2015 $parameter_name =~ s/\[.*//;
2016
2017 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
2018 $type = $args{'parametertypes'}{$parameter};
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002019 print_lineno($parameterdesc_start_lines{$parameter_name});
Mauro Carvalho Chehab6d232c82016-08-22 22:02:57 -03002020 print "``" . $parameter . "``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002021 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002022 print "\n";
2023 }
2024 print "\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03002025
2026 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002027 output_section_rst(@_);
2028}
2029
2030
Johannes Bergeda603f2010-09-11 15:55:22 -07002031## list mode output functions
2032
2033sub output_function_list(%) {
2034 my %args = %{$_[0]};
2035
2036 print $args{'function'} . "\n";
2037}
2038
2039# output enum in list
2040sub output_enum_list(%) {
2041 my %args = %{$_[0]};
2042 print $args{'enum'} . "\n";
2043}
2044
2045# output typedef in list
2046sub output_typedef_list(%) {
2047 my %args = %{$_[0]};
2048 print $args{'typedef'} . "\n";
2049}
2050
2051# output struct as list
2052sub output_struct_list(%) {
2053 my %args = %{$_[0]};
2054
2055 print $args{'struct'} . "\n";
2056}
2057
2058sub output_blockhead_list(%) {
2059 my %args = %{$_[0]};
2060 my ($parameter, $section);
2061
2062 foreach $section (@{$args{'sectionlist'}}) {
2063 print "DOC: $section\n";
2064 }
2065}
2066
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067##
Randy Dunlap27205742006-10-11 01:22:12 -07002068# generic output function for all types (function, struct/union, typedef, enum);
2069# calls the generated, variable output_ function name based on
2070# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071sub output_declaration {
2072 no strict 'refs';
2073 my $name = shift;
2074 my $functype = shift;
2075 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002076 if (($output_selection == OUTPUT_ALL) ||
2077 (($output_selection == OUTPUT_INCLUDE ||
2078 $output_selection == OUTPUT_EXPORTED) &&
2079 defined($function_table{$name})) ||
2080 (($output_selection == OUTPUT_EXCLUDE ||
2081 $output_selection == OUTPUT_INTERNAL) &&
2082 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002084 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 $section_counter++;
2086 }
2087}
2088
2089##
Randy Dunlap27205742006-10-11 01:22:12 -07002090# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002091sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002093 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 &$func(@_);
2095 $section_counter++;
2096}
2097
2098##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002099# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100# invokes the right handler. NOT called for functions.
2101sub dump_declaration($$) {
2102 no strict 'refs';
2103 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002104 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 &$func(@_);
2106}
2107
2108sub dump_union($$) {
2109 dump_struct(@_);
2110}
2111
2112sub dump_struct($$) {
2113 my $x = shift;
2114 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002115 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002117 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2118 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002119 $declaration_name = $2;
2120 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121
2122 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002123 $members =~ s/({.*})//g;
2124 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125
Martin Waitzaeec46b2005-11-13 16:08:13 -08002126 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002127 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2128 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002129 # strip comments:
2130 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002131 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002132 # strip kmemcheck_bitfield_{begin,end}.*;
2133 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002134 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002135 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002136 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002137 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002138 # replace DECLARE_BITMAP
2139 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002140
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002142 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
2144 output_declaration($declaration_name,
2145 'struct',
2146 {'struct' => $declaration_name,
2147 'module' => $modulename,
2148 'parameterlist' => \@parameterlist,
2149 'parameterdescs' => \%parameterdescs,
2150 'parametertypes' => \%parametertypes,
2151 'sectionlist' => \@sectionlist,
2152 'sections' => \%sections,
2153 'purpose' => $declaration_purpose,
2154 'type' => $decl_type
2155 });
2156 }
2157 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002158 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 ++$errors;
2160 }
2161}
2162
2163sub dump_enum($$) {
2164 my $x = shift;
2165 my $file = shift;
2166
Martin Waitzaeec46b2005-11-13 16:08:13 -08002167 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002168 # strip #define macros inside enums
2169 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002170
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002172 $declaration_name = $1;
2173 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
2175 foreach my $arg (split ',', $members) {
2176 $arg =~ s/^\s*(\w+).*/$1/;
2177 push @parameterlist, $arg;
2178 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002179 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002180 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 "not described in enum '$declaration_name'\n";
2182 }
2183
2184 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002185
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 output_declaration($declaration_name,
2187 'enum',
2188 {'enum' => $declaration_name,
2189 'module' => $modulename,
2190 'parameterlist' => \@parameterlist,
2191 'parameterdescs' => \%parameterdescs,
2192 'sectionlist' => \@sectionlist,
2193 'sections' => \%sections,
2194 'purpose' => $declaration_purpose
2195 });
2196 }
2197 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002198 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 ++$errors;
2200 }
2201}
2202
2203sub dump_typedef($$) {
2204 my $x = shift;
2205 my $file = shift;
2206
Martin Waitzaeec46b2005-11-13 16:08:13 -08002207 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002208
2209 # Parse function prototypes
Mauro Carvalho Chehabd37c43c2016-08-30 20:20:57 -03002210 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ ||
2211 $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) {
2212
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002213 # Function typedefs
2214 $return_type = $1;
2215 $declaration_name = $2;
2216 my $args = $3;
2217
2218 create_parameterlist($args, ',', $file);
2219
2220 output_declaration($declaration_name,
2221 'function',
2222 {'function' => $declaration_name,
Mauro Carvalho Chehab82801d02016-08-30 20:20:58 -03002223 'typedef' => 1,
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002224 'module' => $modulename,
2225 'functiontype' => $return_type,
2226 'parameterlist' => \@parameterlist,
2227 'parameterdescs' => \%parameterdescs,
2228 'parametertypes' => \%parametertypes,
2229 'sectionlist' => \@sectionlist,
2230 'sections' => \%sections,
2231 'purpose' => $declaration_purpose
2232 });
2233 return;
2234 }
2235
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002237 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 $x =~ s/\[*.\]\s*;$/;/;
2239 }
2240
2241 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002242 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243
2244 output_declaration($declaration_name,
2245 'typedef',
2246 {'typedef' => $declaration_name,
2247 'module' => $modulename,
2248 'sectionlist' => \@sectionlist,
2249 'sections' => \%sections,
2250 'purpose' => $declaration_purpose
2251 });
2252 }
2253 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002254 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 ++$errors;
2256 }
2257}
2258
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002259sub save_struct_actual($) {
2260 my $actual = shift;
2261
2262 # strip all spaces from the actual param so that it looks like one string item
2263 $actual =~ s/\s*//g;
2264 $struct_actual = $struct_actual . $actual . " ";
2265}
2266
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267sub create_parameterlist($$$) {
2268 my $args = shift;
2269 my $splitter = shift;
2270 my $file = shift;
2271 my $type;
2272 my $param;
2273
Martin Waitza6d3fe72006-01-09 20:53:55 -08002274 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002276 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002278
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 foreach my $arg (split($splitter, $args)) {
2280 # strip comments
2281 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002282 # strip leading/trailing spaces
2283 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 $arg =~ s/\s*$//;
2285 $arg =~ s/\s+/ /;
2286
2287 if ($arg =~ /^#/) {
2288 # Treat preprocessor directive as a typeless variable just to fill
2289 # corresponding data structures "correctly". Catch it later in
2290 # output_* subs.
2291 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002292 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 # pointer-to-function
2294 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002295 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 $param = $1;
2297 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002298 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002299 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002301 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 $arg =~ s/\s*:\s*/:/g;
2303 $arg =~ s/\s*\[/\[/g;
2304
2305 my @args = split('\s*,\s*', $arg);
2306 if ($args[0] =~ m/\*/) {
2307 $args[0] =~ s/(\*+)\s*/ $1/;
2308 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002309
2310 my @first_arg;
2311 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2312 shift @args;
2313 push(@first_arg, split('\s+', $1));
2314 push(@first_arg, $2);
2315 } else {
2316 @first_arg = split('\s+', shift @args);
2317 }
2318
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 unshift(@args, pop @first_arg);
2320 $type = join " ", @first_arg;
2321
2322 foreach $param (@args) {
2323 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002324 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 push_parameter($2, "$type $1", $file);
2326 }
2327 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002328 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002329 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002330 push_parameter($1, "$type:$2", $file)
2331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 }
2333 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002334 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 push_parameter($param, $type, $file);
2336 }
2337 }
2338 }
2339 }
2340}
2341
2342sub push_parameter($$$) {
2343 my $param = shift;
2344 my $type = shift;
2345 my $file = shift;
2346
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002347 if (($anon_struct_union == 1) && ($type eq "") &&
2348 ($param eq "}")) {
2349 return; # ignore the ending }; from anon. struct/union
2350 }
2351
2352 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 my $param_name = $param;
2354 $param_name =~ s/\[.*//;
2355
Martin Waitza6d3fe72006-01-09 20:53:55 -08002356 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 {
Silvio Frickec950a172016-10-28 10:14:08 +02002358 if (!$param =~ /\w\.\.\.$/) {
2359 # handles unnamed variable parameters
2360 $param = "...";
2361 }
Randy Dunlapced69092008-12-01 13:14:03 -08002362 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2363 $parameterdescs{$param} = "variable arguments";
2364 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 }
2366 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2367 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 $param="void";
2369 $parameterdescs{void} = "no arguments";
2370 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002371 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2372 # handle unnamed (anonymous) union or struct:
2373 {
2374 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002375 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002376 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002377 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002378 }
2379
Martin Waitza6d3fe72006-01-09 20:53:55 -08002380 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002381 # (but ignore ones starting with # as these are not parameters
2382 # but inline preprocessor statements);
2383 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002384 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002385 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2386
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 $parameterdescs{$param_name} = $undescribed;
2388
2389 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002390 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 "or member '$param' not " .
2392 "described in '$declaration_name'\n";
2393 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002394 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002395 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002397 }
2398 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002400 $param = xml_escape($param);
2401
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002402 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002403 # on @parameterlist;
2404 # this fixes a problem where check_sections() cannot find
2405 # a parameter like "addr[6 + 2]" because it actually appears
2406 # as "addr[6", "+", "2]" on the parameter list;
2407 # but it's better to maintain the param string unchanged for output,
2408 # so just weaken the string compare in check_sections() to ignore
2409 # "[blah" in a parameter string;
2410 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 push @parameterlist, $param;
2412 $parametertypes{$param} = $type;
2413}
2414
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002415sub check_sections($$$$$$) {
2416 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2417 my @sects = split ' ', $sectcheck;
2418 my @prms = split ' ', $prmscheck;
2419 my $err;
2420 my ($px, $sx);
2421 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2422
2423 foreach $sx (0 .. $#sects) {
2424 $err = 1;
2425 foreach $px (0 .. $#prms) {
2426 $prm_clean = $prms[$px];
2427 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002428 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002429 # ignore array size in a parameter string;
2430 # however, the original param string may contain
2431 # spaces, e.g.: addr[6 + 2]
2432 # and this appears in @prms as "addr[6" since the
2433 # parameter list is split at spaces;
2434 # hence just ignore "[..." for the sections check;
2435 $prm_clean =~ s/\[.*//;
2436
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002437 ##$prm_clean =~ s/^\**//;
2438 if ($prm_clean eq $sects[$sx]) {
2439 $err = 0;
2440 last;
2441 }
2442 }
2443 if ($err) {
2444 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002445 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002446 "Excess function parameter " .
2447 "'$sects[$sx]' " .
2448 "description in '$decl_name'\n";
2449 ++$warnings;
2450 } else {
2451 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002452 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002453 "Excess struct/union/enum/typedef member " .
2454 "'$sects[$sx]' " .
2455 "description in '$decl_name'\n";
2456 ++$warnings;
2457 }
2458 }
2459 }
2460 }
2461}
2462
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002464# Checks the section describing the return value of a function.
2465sub check_return_section {
2466 my $file = shift;
2467 my $declaration_name = shift;
2468 my $return_type = shift;
2469
2470 # Ignore an empty return type (It's a macro)
2471 # Ignore functions with a "void" return type. (But don't ignore "void *")
2472 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2473 return;
2474 }
2475
2476 if (!defined($sections{$section_return}) ||
2477 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002478 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002479 "No description found for return value of " .
2480 "'$declaration_name'\n";
2481 ++$warnings;
2482 }
2483}
2484
2485##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486# takes a function prototype and the name of the current file being
2487# processed and spits out all the details stored in the global
2488# arrays/hashes.
2489sub dump_function($$) {
2490 my $prototype = shift;
2491 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002492 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493
2494 $prototype =~ s/^static +//;
2495 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002496 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 $prototype =~ s/^inline +//;
2498 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002499 $prototype =~ s/^__inline +//;
2500 $prototype =~ s/^__always_inline +//;
2501 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002502 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002503 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002504 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002505 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002506 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002507 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002508 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509
2510 # Yes, this truly is vile. We are looking for:
2511 # 1. Return type (may be nothing if we're looking at a macro)
2512 # 2. Function name
2513 # 3. Function parameters.
2514 #
2515 # All the while we have to watch out for function pointer parameters
2516 # (which IIRC is what the two sections are for), C types (these
2517 # regexps don't even start to express all the possibilities), and
2518 # so on.
2519 #
2520 # If you mess with these regexps, it's a good idea to check that
2521 # the following functions' documentation still comes out right:
2522 # - parport_register_device (function pointer parameters)
2523 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002524 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002526 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2527 # This is an object-like macro, it has no return type and no parameter
2528 # list.
2529 # Function-like macros are not allowed to have spaces between
2530 # declaration_name and opening parenthesis (notice the \s+).
2531 $return_type = $1;
2532 $declaration_name = $2;
2533 $noret = 1;
2534 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2536 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2537 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002538 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002539 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2540 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2541 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2542 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2543 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2544 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2545 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2546 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002547 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2548 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002549 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2550 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 $return_type = $1;
2552 $declaration_name = $2;
2553 my $args = $3;
2554
2555 create_parameterlist($args, ',', $file);
2556 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002557 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 return;
2559 }
2560
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002561 my $prms = join " ", @parameterlist;
2562 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2563
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002564 # This check emits a lot of warnings at the moment, because many
2565 # functions don't have a 'Return' doc section. So until the number
2566 # of warnings goes sufficiently down, the check is only performed in
2567 # verbose mode.
2568 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002569 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002570 check_return_section($file, $declaration_name, $return_type);
2571 }
2572
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002573 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 'function',
2575 {'function' => $declaration_name,
2576 'module' => $modulename,
2577 'functiontype' => $return_type,
2578 'parameterlist' => \@parameterlist,
2579 'parameterdescs' => \%parameterdescs,
2580 'parametertypes' => \%parametertypes,
2581 'sectionlist' => \@sectionlist,
2582 'sections' => \%sections,
2583 'purpose' => $declaration_purpose
2584 });
2585}
2586
Linus Torvalds1da177e2005-04-16 15:20:36 -07002587sub reset_state {
2588 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 %parameterdescs = ();
2590 %parametertypes = ();
2591 @parameterlist = ();
2592 %sections = ();
2593 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002594 $sectcheck = "";
2595 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002597
Jani Nikula48af6062016-05-26 14:56:05 +03002598 $state = STATE_NORMAL;
2599 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600}
2601
Jason Baron56afb0f2009-04-30 13:29:36 -04002602sub tracepoint_munge($) {
2603 my $file = shift;
2604 my $tracepointname = 0;
2605 my $tracepointargs = 0;
2606
Jason Baron3a9089f2009-12-01 12:18:49 -05002607 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002608 $tracepointname = $1;
2609 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002610 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2611 $tracepointname = $1;
2612 }
2613 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2614 $tracepointname = $2;
2615 }
2616 $tracepointname =~ s/^\s+//; #strip leading whitespace
2617 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002618 $tracepointargs = $1;
2619 }
2620 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002621 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002622 "$prototype\n";
2623 } else {
2624 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2625 }
2626}
2627
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002628sub syscall_munge() {
2629 my $void = 0;
2630
2631 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2632## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2633 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2634 $void = 1;
2635## $prototype = "long sys_$1(void)";
2636 }
2637
2638 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2639 if ($prototype =~ m/long (sys_.*?),/) {
2640 $prototype =~ s/,/\(/;
2641 } elsif ($void) {
2642 $prototype =~ s/\)/\(void\)/;
2643 }
2644
2645 # now delete all of the odd-number commas in $prototype
2646 # so that arg types & arg names don't have a comma between them
2647 my $count = 0;
2648 my $len = length($prototype);
2649 if ($void) {
2650 $len = 0; # skip the for-loop
2651 }
2652 for (my $ix = 0; $ix < $len; $ix++) {
2653 if (substr($prototype, $ix, 1) eq ',') {
2654 $count++;
2655 if ($count % 2 == 1) {
2656 substr($prototype, $ix, 1) = ' ';
2657 }
2658 }
2659 }
2660}
2661
Daniel Vetterb7afa922016-06-01 23:46:24 +02002662sub process_proto_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 my $x = shift;
2664 my $file = shift;
2665
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002666 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2667
Randy Dunlap890c78c2008-10-25 17:06:43 -07002668 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 # do nothing
2670 }
2671 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002672 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002674
Randy Dunlap890c78c2008-10-25 17:06:43 -07002675 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002676 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2678 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002679 if ($prototype =~ /SYSCALL_DEFINE/) {
2680 syscall_munge();
2681 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002682 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2683 $prototype =~ /DEFINE_SINGLE_EVENT/)
2684 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002685 tracepoint_munge($file);
2686 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002687 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 reset_state();
2689 }
2690}
2691
Daniel Vetterb7afa922016-06-01 23:46:24 +02002692sub process_proto_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 my $x = shift;
2694 my $file = shift;
2695
Linus Torvalds1da177e2005-04-16 15:20:36 -07002696 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2697 $x =~ s@^\s+@@gos; # strip leading spaces
2698 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002699 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2700
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 if ($x =~ /^#/) {
2702 # To distinguish preprocessor directive from regular declaration later.
2703 $x .= ";";
2704 }
2705
2706 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002707 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 $prototype .= $1 . $2;
2709 ($2 eq '{') && $brcount++;
2710 ($2 eq '}') && $brcount--;
2711 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002712 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002713 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002714 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 }
2716 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002717 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 $prototype .= $x;
2719 last;
2720 }
2721 }
2722}
2723
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002724# xml_escape: replace <, >, and & in the text stream;
2725#
2726# however, formatting controls that are generated internally/locally in the
2727# kernel-doc script are not escaped here; instead, they begin life like
2728# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2729# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2730# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731sub xml_escape($) {
2732 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002733 if (($output_mode eq "text") || ($output_mode eq "man")) {
2734 return $text;
2735 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 $text =~ s/\&/\\\\\\amp;/g;
2737 $text =~ s/\</\\\\\\lt;/g;
2738 $text =~ s/\>/\\\\\\gt;/g;
2739 return $text;
2740}
2741
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002742# xml_unescape: reverse the effects of xml_escape
2743sub xml_unescape($) {
2744 my $text = shift;
2745 if (($output_mode eq "text") || ($output_mode eq "man")) {
2746 return $text;
2747 }
2748 $text =~ s/\\\\\\amp;/\&/g;
2749 $text =~ s/\\\\\\lt;/</g;
2750 $text =~ s/\\\\\\gt;/>/g;
2751 return $text;
2752}
2753
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002754# convert local escape strings to html
2755# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2756sub local_unescape($) {
2757 my $text = shift;
2758 if (($output_mode eq "text") || ($output_mode eq "man")) {
2759 return $text;
2760 }
2761 $text =~ s/\\\\\\\\lt:/</g;
2762 $text =~ s/\\\\\\\\gt:/>/g;
2763 return $text;
2764}
2765
Jani Nikula1ad560e2016-06-07 10:53:39 +03002766sub map_filename($) {
2767 my $file;
2768 my ($orig_file) = @_;
2769
2770 if (defined($ENV{'SRCTREE'})) {
2771 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
2772 } else {
2773 $file = $orig_file;
2774 }
2775
2776 if (defined($source_map{$file})) {
2777 $file = $source_map{$file};
2778 }
2779
2780 return $file;
2781}
2782
Jani Nikula88c2b572016-06-07 11:00:52 +03002783sub process_export_file($) {
2784 my ($orig_file) = @_;
2785 my $file = map_filename($orig_file);
2786
2787 if (!open(IN,"<$file")) {
2788 print STDERR "Error: Cannot open file $file\n";
2789 ++$errors;
2790 return;
2791 }
2792
2793 while (<IN>) {
2794 if (/$export_symbol/) {
2795 $function_table{$2} = 1;
2796 }
2797 }
2798
2799 close(IN);
2800}
2801
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002803 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 my $identifier;
2805 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002806 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002807 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002809 my ($orig_file) = @_;
Jani Nikulab7886de2016-05-28 00:41:50 +03002810 my $leading_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811
Jani Nikula1ad560e2016-06-07 10:53:39 +03002812 $file = map_filename($orig_file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813
2814 if (!open(IN,"<$file")) {
2815 print STDERR "Error: Cannot open file $file\n";
2816 ++$errors;
2817 return;
2818 }
2819
Ilya Dryomova9e73142010-02-26 13:05:47 -08002820 $. = 1;
2821
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 $section_counter = 0;
2823 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002824 while (s/\\\s*$//) {
2825 $_ .= <IN>;
2826 }
Jani Nikula48af6062016-05-26 14:56:05 +03002827 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002829 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002830 $in_doc_sect = 0;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002831 $declaration_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 }
Jani Nikula48af6062016-05-26 14:56:05 +03002833 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002835 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002837 $new_start_line = $. + 1;
2838
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 if ( $1 eq "" ) {
2840 $section = $section_intro;
2841 } else {
2842 $section = $1;
2843 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002844 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 elsif (/$doc_decl/o) {
2846 $identifier = $1;
2847 if (/\s*([\w\s]+?)\s*-/) {
2848 $identifier = $1;
2849 }
2850
Jani Nikula48af6062016-05-26 14:56:05 +03002851 $state = STATE_FIELD;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002852 # if there's no @param blocks need to set up default section
2853 # here
Jani Nikula2f4ad402016-05-30 11:21:06 +03002854 $contents = "";
2855 $section = $section_default;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002856 $new_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002858 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002859 $descr= $1;
2860 $descr =~ s/^\s*//;
2861 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002862 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002863 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002864 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 } else {
2866 $declaration_purpose = "";
2867 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002868
2869 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002870 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002871 print STDERR $_;
2872 ++$warnings;
2873 }
2874
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 if ($identifier =~ m/^struct/) {
2876 $decl_type = 'struct';
2877 } elsif ($identifier =~ m/^union/) {
2878 $decl_type = 'union';
2879 } elsif ($identifier =~ m/^enum/) {
2880 $decl_type = 'enum';
2881 } elsif ($identifier =~ m/^typedef/) {
2882 $decl_type = 'typedef';
2883 } else {
2884 $decl_type = 'function';
2885 }
2886
2887 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002888 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 }
2890 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002891 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 " - I thought it was a doc line\n";
2893 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002894 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 }
Jani Nikula48af6062016-05-26 14:56:05 +03002896 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Jani Nikulaf624ade2016-05-29 11:35:28 +03002897 if (/$doc_sect/i) { # case insensitive for supported section names
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 $newsection = $1;
2899 $newcontents = $2;
2900
Jani Nikulaf624ade2016-05-29 11:35:28 +03002901 # map the supported section names to the canonical names
2902 if ($newsection =~ m/^description$/i) {
2903 $newsection = $section_default;
2904 } elsif ($newsection =~ m/^context$/i) {
2905 $newsection = $section_context;
2906 } elsif ($newsection =~ m/^returns?$/i) {
2907 $newsection = $section_return;
2908 } elsif ($newsection =~ m/^\@return$/) {
2909 # special: @return is a section, not a param description
2910 $newsection = $section_return;
2911 }
2912
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002913 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002914 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002915 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002916 ++$warnings;
2917 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002918 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 $section = $section_default;
2920 }
2921
Randy Dunlap850622d2006-06-25 05:48:55 -07002922 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002923 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 $contents = $newcontents;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002925 $new_start_line = $.;
Jani Nikula0a726302016-05-28 14:50:20 +03002926 while ((substr($contents, 0, 1) eq " ") ||
2927 substr($contents, 0, 1) eq "\t") {
2928 $contents = substr($contents, 1);
2929 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 if ($contents ne "") {
2931 $contents .= "\n";
2932 }
2933 $section = $newsection;
Jani Nikulab7886de2016-05-28 00:41:50 +03002934 $leading_space = undef;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002936 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002937 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 $section = $section_default;
2939 $contents = "";
2940 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002941 # look for doc_com + <text> + doc_end:
2942 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002943 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002944 ++$warnings;
2945 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946
2947 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002948 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002950# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 } elsif (/$doc_content/) {
2952 # miguel-style comment kludge, look for blank lines after
2953 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002954 if ($1 eq "") {
2955 if ($section =~ m/^@/ || $section eq $section_context) {
2956 dump_section($file, $section, xml_escape($contents));
2957 $section = $section_default;
2958 $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002959 $new_start_line = $.;
Johannes Weiner64231332009-09-17 19:26:53 -07002960 } else {
2961 $contents .= "\n";
2962 }
2963 $in_purpose = 0;
2964 } elsif ($in_purpose == 1) {
2965 # Continued declaration purpose
2966 chomp($declaration_purpose);
2967 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002968 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 } else {
Jani Nikulab7886de2016-05-28 00:41:50 +03002970 my $cont = $1;
2971 if ($section =~ m/^@/ || $section eq $section_context) {
2972 if (!defined $leading_space) {
2973 if ($cont =~ m/^(\s+)/) {
2974 $leading_space = $1;
2975 } else {
2976 $leading_space = "";
2977 }
2978 }
2979
2980 $cont =~ s/^$leading_space//;
2981 }
2982 $contents .= $cont . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 }
2984 } else {
2985 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002986 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 ++$warnings;
2988 }
Jani Nikula48af6062016-05-26 14:56:05 +03002989 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002990 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03002991 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002992 $section = $1;
2993 $contents = $2;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002994 $new_start_line = $.;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002995 if ($contents ne "") {
2996 while ((substr($contents, 0, 1) eq " ") ||
2997 substr($contents, 0, 1) eq "\t") {
2998 $contents = substr($contents, 1);
2999 }
Jani Nikulaa0b96c22016-05-26 22:04:06 +03003000 $contents .= "\n";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003001 }
Jani Nikula48af6062016-05-26 14:56:05 +03003002 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003003 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03003004 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003005 if (($contents ne "") && ($contents ne "\n")) {
3006 dump_section($file, $section, xml_escape($contents));
3007 $section = $section_default;
3008 $contents = "";
3009 }
Jani Nikula48af6062016-05-26 14:56:05 +03003010 $state = STATE_PROTO;
3011 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003012 # Regular text
3013 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03003014 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003015 $contents .= $1 . "\n";
Jani Nikula6450c892016-05-26 22:04:42 +03003016 # nuke leading blank lines
3017 if ($contents =~ /^\s*$/) {
3018 $contents = "";
3019 }
Jani Nikula48af6062016-05-26 14:56:05 +03003020 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
3021 $inline_doc_state = STATE_INLINE_ERROR;
Daniel Vettere7ca3112016-07-15 10:19:30 +02003022 print STDERR "${file}:$.: warning: ";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003023 print STDERR "Incorrect use of kernel-doc format: $_";
3024 ++$warnings;
3025 }
3026 }
Jani Nikula48af6062016-05-26 14:56:05 +03003027 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
Jani Nikula0c9aa202016-11-16 17:26:16 +02003028 if (/$doc_inline_oneline/) {
3029 $section = $1;
3030 $contents = $2;
3031 if ($contents ne "") {
3032 $contents .= "\n";
3033 dump_section($file, $section, xml_escape($contents));
3034 $section = $section_default;
3035 $contents = "";
3036 }
3037 } elsif (/$doc_inline_start/) {
Jani Nikula48af6062016-05-26 14:56:05 +03003038 $state = STATE_INLINE;
3039 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03003040 } elsif ($decl_type eq 'function') {
Daniel Vetterb7afa922016-06-01 23:46:24 +02003041 process_proto_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 } else {
Daniel Vetterb7afa922016-06-01 23:46:24 +02003043 process_proto_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 }
Jani Nikula48af6062016-05-26 14:56:05 +03003045 } elsif ($state == STATE_DOCBLOCK) {
Daniel Vetterebff7f92016-06-01 23:46:23 +02003046 if (/$doc_end/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07003048 dump_doc_section($file, $section, xml_escape($contents));
Jani Nikula2f4ad402016-05-30 11:21:06 +03003049 $section = $section_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 $contents = "";
3051 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052 %parameterdescs = ();
3053 %parametertypes = ();
3054 @parameterlist = ();
3055 %sections = ();
3056 @sectionlist = ();
3057 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03003058 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 }
3060 elsif (/$doc_content/)
3061 {
3062 if ( $1 eq "" )
3063 {
3064 $contents .= $blankline;
3065 }
3066 else
3067 {
3068 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08003069 }
Randy Dunlap3c308792007-05-08 00:24:39 -07003070 }
3071 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 }
3073 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07003074 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03003075 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08003076 print STDERR " Was looking for '$_'.\n" for keys %function_table;
3077 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003078 if ($output_mode eq "xml") {
3079 # The template wants at least one RefEntry here; make one.
3080 print "<refentry>\n";
3081 print " <refnamediv>\n";
3082 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003083 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 print " </refname>\n";
3085 print " <refpurpose>\n";
3086 print " Document generation inconsistency\n";
3087 print " </refpurpose>\n";
3088 print " </refnamediv>\n";
3089 print " <refsect1>\n";
3090 print " <title>\n";
3091 print " Oops\n";
3092 print " </title>\n";
3093 print " <warning>\n";
3094 print " <para>\n";
3095 print " The template for this document tried to insert\n";
3096 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003097 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098 print " but none was found.\n";
3099 print " This dummy section is inserted to allow\n";
3100 print " generation to continue.\n";
3101 print " </para>\n";
3102 print " </warning>\n";
3103 print " </refsect1>\n";
3104 print "</refentry>\n";
3105 }
3106 }
3107}
Randy Dunlap8484baa2011-01-05 16:28:43 -08003108
3109
3110$kernelversion = get_kernel_version();
3111
3112# generate a sequence of code that will splice in highlighting information
3113# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02003114for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03003115 my $pattern = $highlights[$k][0];
3116 my $result = $highlights[$k][1];
3117# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
3118 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08003119}
3120
3121# Read the file that maps relative names to absolute names for
3122# separate source and object directories and for shadow trees.
3123if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3124 my ($relname, $absname);
3125 while(<SOURCE_MAP>) {
3126 chop();
3127 ($relname, $absname) = (split())[0..1];
3128 $relname =~ s:^/+::;
3129 $source_map{$relname} = $absname;
3130 }
3131 close(SOURCE_MAP);
3132}
3133
Jani Nikula88c2b572016-06-07 11:00:52 +03003134if ($output_selection == OUTPUT_EXPORTED ||
3135 $output_selection == OUTPUT_INTERNAL) {
Jani Nikulac9b2cfb2016-06-07 11:05:53 +03003136
3137 push(@export_file_list, @ARGV);
3138
Jani Nikula88c2b572016-06-07 11:00:52 +03003139 foreach (@export_file_list) {
3140 chomp;
3141 process_export_file($_);
3142 }
3143}
3144
Randy Dunlap8484baa2011-01-05 16:28:43 -08003145foreach (@ARGV) {
3146 chomp;
3147 process_file($_);
3148}
3149if ($verbose && $errors) {
3150 print STDERR "$errors errors\n";
3151}
3152if ($verbose && $warnings) {
3153 print STDERR "$warnings warnings\n";
3154}
3155
3156exit($errors);