blob: 5192213c5005ae073766ee6f972769e040824148 [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()
64 in the same FILE.
65 -internal Only output documentation for symbols that have NOT been
66 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL()
67 in the same FILE.
Jani Nikulafadc0b32016-05-12 16:15:36 +030068 -function NAME Only output documentation for the given function(s)
69 or DOC: section title(s). All other functions and DOC:
70 sections are ignored. May be specified multiple times.
71 -nofunction NAME Do NOT output documentation for the given function(s);
72 only output documentation for the other functions and
73 DOC: sections. May be specified multiple times.
74
75Output selection modifiers:
76 -no-doc-sections Do not output DOC: sections.
Daniel Vetter0b0f5f22016-06-03 22:21:34 +020077 -enable-lineno Enable output of #define LINENO lines. Only works with
78 reStructuredText format.
Jani Nikulafadc0b32016-05-12 16:15:36 +030079
80Other parameters:
81 -v Verbose output, more warnings and other information.
82 -h Print this help.
83
84EOF
85 print $message;
86 exit 1;
87}
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89#
90# format of comments.
91# In the following table, (...)? signifies optional structure.
92# (...)* signifies 0 or more structure elements
93# /**
94# * function_name(:)? (- short description)?
95# (* @parameterx: (description of parameter x)?)*
96# (* a blank line)?
97# * (Description:)? (Description of function)?
98# * (section header: (section description)? )*
99# (*)?*/
100#
101# So .. the trivial example would be:
102#
103# /**
104# * my_function
Randy Dunlapb9d973282009-06-09 08:50:38 -0700105# */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#
Randy Dunlap891dcd22007-02-10 01:45:53 -0800107# If the Description: header tag is omitted, then there must be a blank line
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108# after the last parameter specification.
109# e.g.
110# /**
111# * my_function - does my stuff
112# * @my_arg: its mine damnit
113# *
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800114# * Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115# */
116#
117# or, could also use:
118# /**
119# * my_function - does my stuff
120# * @my_arg: its mine damnit
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800121# * Description: Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122# */
123# etc.
124#
Randy Dunlapb9d973282009-06-09 08:50:38 -0700125# Besides functions you can also write documentation for structs, unions,
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800126# enums and typedefs. Instead of the function name you must write the name
127# of the declaration; the struct/union/enum/typedef must always precede
128# the name. Nesting of declarations is not supported.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129# Use the argument mechanism to document members or constants.
130# e.g.
131# /**
132# * struct my_struct - short description
133# * @a: first member
134# * @b: second member
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800135# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136# * Longer description
137# */
138# struct my_struct {
139# int a;
140# int b;
Martin Waitzaeec46b2005-11-13 16:08:13 -0800141# /* private: */
142# int c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143# };
144#
145# All descriptions can be multiline, except the short function description.
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800146#
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300147# For really longs structs, you can also describe arguments inside the
148# body of the struct.
149# eg.
150# /**
151# * struct my_struct - short description
152# * @a: first member
153# * @b: second member
154# *
155# * Longer description
156# */
157# struct my_struct {
158# int a;
159# int b;
160# /**
161# * @c: This is longer description of C
162# *
163# * You can use paragraphs to describe arguments
164# * using this method.
165# */
166# int c;
167# };
168#
169# This should be use only for struct/enum members.
170#
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800171# You can also add additional sections. When documenting kernel functions you
172# should document the "Context:" of the function, e.g. whether the functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173# can be called form interrupts. Unlike other sections you can end it with an
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800174# empty line.
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100175# A non-void function should have a "Return:" section describing the return
176# value(s).
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800177# Example-sections should contain the string EXAMPLE so that they are marked
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178# appropriately in DocBook.
179#
180# Example:
181# /**
182# * user_function - function that can only be called in user context
183# * @a: some argument
184# * Context: !in_interrupt()
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800185# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186# * Some description
187# * Example:
188# * user_function(22);
189# */
190# ...
191#
192#
193# All descriptive text is further processed, scanning for the following special
194# patterns, which are highlighted appropriately.
195#
196# 'funcname()' - function
197# '$ENVVAR' - environmental variable
198# '&struct_name' - name of a structure (up to two words including 'struct')
199# '@parameter' - name of a parameter
200# '%CONST' - name of a constant.
201
Randy Dunlap8484baa2011-01-05 16:28:43 -0800202## init lots of data
203
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204my $errors = 0;
205my $warnings = 0;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -0700206my $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208# match expressions used to find embedded type information
209my $type_constant = '\%([-_\w]+)';
210my $type_func = '(\w+)\(\)';
211my $type_param = '\@(\w+)';
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700212my $type_struct = '\&((struct\s*)*[_\w]+)';
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700213my $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214my $type_env = '(\$\w+)';
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300215my $type_enum_full = '\&(enum)\s*([_\w]+)';
216my $type_struct_full = '\&(struct)\s*([_\w]+)';
Jani Nikula47ae7ae2016-05-26 13:57:18 +0300217my $type_typedef_full = '\&(typedef)\s*([_\w]+)';
218my $type_union_full = '\&(union)\s*([_\w]+)';
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300219my $type_member = '\&([_\w]+)((\.|->)[_\w]+)';
220my $type_member_func = $type_member . '\(\)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222# Output conversion substitutions.
223# One for each output format
224
225# these work fairly well
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300226my @highlights_html = (
227 [$type_constant, "<i>\$1</i>"],
228 [$type_func, "<b>\$1</b>"],
229 [$type_struct_xml, "<i>\$1</i>"],
230 [$type_env, "<b><i>\$1</i></b>"],
231 [$type_param, "<tt><b>\$1</b></tt>"]
232 );
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700233my $local_lt = "\\\\\\\\lt:";
234my $local_gt = "\\\\\\\\gt:";
235my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Dan Luedtke1b40c192012-08-12 10:46:15 +0200237# html version 5
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300238my @highlights_html5 = (
239 [$type_constant, "<span class=\"const\">\$1</span>"],
240 [$type_func, "<span class=\"func\">\$1</span>"],
241 [$type_struct_xml, "<span class=\"struct\">\$1</span>"],
242 [$type_env, "<span class=\"env\">\$1</span>"],
243 [$type_param, "<span class=\"param\">\$1</span>]"]
244 );
Dan Luedtke1b40c192012-08-12 10:46:15 +0200245my $blankline_html5 = $local_lt . "br /" . $local_gt;
246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247# XML, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300248my @highlights_xml = (
249 ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
250 [$type_constant, "<constant>\$1</constant>"],
251 [$type_struct_xml, "<structname>\$1</structname>"],
252 [$type_param, "<parameter>\$1</parameter>"],
253 [$type_func, "<function>\$1</function>"],
254 [$type_env, "<envar>\$1</envar>"]
255 );
Johannes Berg5c98fc02007-10-24 15:08:48 -0700256my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
258# gnome, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300259my @highlights_gnome = (
260 [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
261 [$type_func, "<function>\$1</function>"],
262 [$type_struct, "<structname>\$1</structname>"],
263 [$type_env, "<envar>\$1</envar>"],
264 [$type_param, "<parameter>\$1</parameter>" ]
265 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266my $blankline_gnome = "</para><para>\n";
267
268# these are pretty rough
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300269my @highlights_man = (
270 [$type_constant, "\$1"],
271 [$type_func, "\\\\fB\$1\\\\fP"],
272 [$type_struct, "\\\\fI\$1\\\\fP"],
273 [$type_param, "\\\\fI\$1\\\\fP"]
274 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275my $blankline_man = "";
276
277# text-mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300278my @highlights_text = (
279 [$type_constant, "\$1"],
280 [$type_func, "\$1"],
281 [$type_struct, "\$1"],
282 [$type_param, "\$1"]
283 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284my $blankline_text = "";
285
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300286# rst-mode
287my @highlights_rst = (
288 [$type_constant, "``\$1``"],
Jani Nikulaf3341dc2016-05-26 16:35:02 +0300289 # Note: need to escape () to avoid func matching later
290 [$type_member_func, "\\:c\\:type\\:`\$1\$2\\\\(\\\\) <\$1>`"],
291 [$type_member, "\\:c\\:type\\:`\$1\$2 <\$1>`"],
Jani Nikulaa19bce62016-05-26 11:28:16 +0300292 [$type_func, "\\:c\\:func\\:`\$1()`"],
Jani Nikula62850972016-05-12 16:15:38 +0300293 [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
294 [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
Jani Nikula47ae7ae2016-05-26 13:57:18 +0300295 [$type_typedef_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
296 [$type_union_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"],
Jani Nikulaa7291e72016-05-26 13:57:06 +0300297 # in rst this can refer to any type
298 [$type_struct, "\\:c\\:type\\:`\$1`"],
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300299 [$type_param, "**\$1**"]
300 );
301my $blankline_rst = "\n";
302
Johannes Bergeda603f2010-09-11 15:55:22 -0700303# list mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300304my @highlights_list = (
305 [$type_constant, "\$1"],
306 [$type_func, "\$1"],
307 [$type_struct, "\$1"],
308 [$type_param, "\$1"]
309 );
Johannes Bergeda603f2010-09-11 15:55:22 -0700310my $blankline_list = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312# read arguments
Randy Dunlapb9d973282009-06-09 08:50:38 -0700313if ($#ARGV == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 usage();
315}
316
Randy Dunlap8484baa2011-01-05 16:28:43 -0800317my $kernelversion;
318my $dohighlight = "";
319
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320my $verbose = 0;
321my $output_mode = "man";
Daniel Santose314ba32012-10-04 17:15:08 -0700322my $output_preformatted = 0;
Johannes Berg4b445952007-10-24 15:08:48 -0700323my $no_doc_sections = 0;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200324my $enable_lineno = 0;
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300325my @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326my $blankline = $blankline_man;
327my $modulename = "Kernel API";
Jani Nikulab6c3f452016-05-29 22:19:35 +0300328
329use constant {
330 OUTPUT_ALL => 0, # output all symbols and doc sections
331 OUTPUT_INCLUDE => 1, # output only specified symbols
332 OUTPUT_EXCLUDE => 2, # output everything except specified symbols
333 OUTPUT_EXPORTED => 3, # output exported symbols
334 OUTPUT_INTERNAL => 4, # output non-exported symbols
335};
336my $output_selection = OUTPUT_ALL;
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100337my $show_not_found = 0;
338
339my @build_time;
340if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
341 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
342 @build_time = gmtime($seconds);
343} else {
344 @build_time = localtime;
345}
346
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800347my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
348 'July', 'August', 'September', 'October',
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100349 'November', 'December')[$build_time[4]] .
350 " " . ($build_time[5]+1900);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Randy Dunlap8484baa2011-01-05 16:28:43 -0800352# Essentially these are globals.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700353# They probably want to be tidied up, made more localised or something.
354# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355# could cause "use of undefined value" or other bugs.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700356my ($function, %function_table, %parametertypes, $declaration_purpose);
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200357my $declaration_start_line;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700358my ($type, $declaration_name, $return_type);
Ilya Dryomov1c32fd02010-02-26 13:06:03 -0800359my ($newsection, $newcontents, $prototype, $brcount, %source_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700361if (defined($ENV{'KBUILD_VERBOSE'})) {
362 $verbose = "$ENV{'KBUILD_VERBOSE'}";
363}
364
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800365# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
367# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
368# We keep track of number of generated entries and generate a dummy
369# if needs be to ensure the expanded template can be postprocessed
370# into html.
371my $section_counter = 0;
372
373my $lineprefix="";
374
Jani Nikula48af6062016-05-26 14:56:05 +0300375# Parser states
376use constant {
377 STATE_NORMAL => 0, # normal code
378 STATE_NAME => 1, # looking for function name
379 STATE_FIELD => 2, # scanning field start
380 STATE_PROTO => 3, # scanning prototype
381 STATE_DOCBLOCK => 4, # documentation block
382 STATE_INLINE => 5, # gathering documentation outside main block
383};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700385my $in_doc_sect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386
Jani Nikula48af6062016-05-26 14:56:05 +0300387# Inline documentation state
388use constant {
389 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE)
390 STATE_INLINE_NAME => 1, # looking for member name (@foo:)
391 STATE_INLINE_TEXT => 2, # looking for member documentation
392 STATE_INLINE_END => 3, # done
393 STATE_INLINE_ERROR => 4, # error - Comment without header was found.
394 # Spit a warning as it's not
395 # proper kernel-doc and ignore the rest.
396};
397my $inline_doc_state;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399#declaration types: can be
400# 'function', 'struct', 'union', 'enum', 'typedef'
401my $decl_type;
402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
404my $doc_end = '\*/';
405my $doc_com = '\s*\*\s*';
Daniel Santos12ae6772012-10-04 17:15:10 -0700406my $doc_com_body = '\s*\* ?';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700407my $doc_decl = $doc_com . '(\w+)';
Jani Nikulaf624ade2016-05-29 11:35:28 +0300408# @params and a strictly limited set of supported section names
409my $doc_sect = $doc_com . '\s*(\@\w+|description|context|returns?)\s*:(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700410my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700411my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Jani Nikula48af6062016-05-26 14:56:05 +0300412my $doc_inline_start = '^\s*/\*\*\s*$';
413my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
414my $doc_inline_end = '^\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200415my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417my %parameterdescs;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200418my %parameterdesc_start_lines;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419my @parameterlist;
420my %sections;
421my @sectionlist;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200422my %section_start_lines;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800423my $sectcheck;
424my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
426my $contents = "";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200427my $new_start_line = 0;
Jani Nikulaf624ade2016-05-29 11:35:28 +0300428
429# the canonical section names. see also $doc_sect above.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430my $section_default = "Description"; # default section
431my $section_intro = "Introduction";
432my $section = $section_default;
433my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100434my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
436my $undescribed = "-- undescribed --";
437
438reset_state();
439
440while ($ARGV[0] =~ m/^-(.*)/) {
441 my $cmd = shift @ARGV;
442 if ($cmd eq "-html") {
443 $output_mode = "html";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300444 @highlights = @highlights_html;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200446 } elsif ($cmd eq "-html5") {
447 $output_mode = "html5";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300448 @highlights = @highlights_html5;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200449 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450 } elsif ($cmd eq "-man") {
451 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300452 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 $blankline = $blankline_man;
454 } elsif ($cmd eq "-text") {
455 $output_mode = "text";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300456 @highlights = @highlights_text;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 $blankline = $blankline_text;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300458 } elsif ($cmd eq "-rst") {
459 $output_mode = "rst";
460 @highlights = @highlights_rst;
461 $blankline = $blankline_rst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 } elsif ($cmd eq "-docbook") {
463 $output_mode = "xml";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300464 @highlights = @highlights_xml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700466 } elsif ($cmd eq "-list") {
467 $output_mode = "list";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300468 @highlights = @highlights_list;
Johannes Bergeda603f2010-09-11 15:55:22 -0700469 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 } elsif ($cmd eq "-gnome") {
471 $output_mode = "gnome";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300472 @highlights = @highlights_gnome;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 $blankline = $blankline_gnome;
474 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
475 $modulename = shift @ARGV;
476 } elsif ($cmd eq "-function") { # to only output specific functions
Jani Nikulab6c3f452016-05-29 22:19:35 +0300477 $output_selection = OUTPUT_INCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 $function = shift @ARGV;
479 $function_table{$function} = 1;
Jani Nikulab6c3f452016-05-29 22:19:35 +0300480 } elsif ($cmd eq "-nofunction") { # output all except specific functions
481 $output_selection = OUTPUT_EXCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 $function = shift @ARGV;
483 $function_table{$function} = 1;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200484 } elsif ($cmd eq "-export") { # only exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300485 $output_selection = OUTPUT_EXPORTED;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200486 %function_table = ()
487 } elsif ($cmd eq "-internal") { # only non-exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300488 $output_selection = OUTPUT_INTERNAL;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200489 %function_table = ()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 } elsif ($cmd eq "-v") {
491 $verbose = 1;
492 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
493 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700494 } elsif ($cmd eq '-no-doc-sections') {
495 $no_doc_sections = 1;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200496 } elsif ($cmd eq '-enable-lineno') {
497 $enable_lineno = 1;
Johannes Berge946c43a2013-11-12 15:11:12 -0800498 } elsif ($cmd eq '-show-not-found') {
499 $show_not_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 }
501}
502
Randy Dunlap8484baa2011-01-05 16:28:43 -0800503# continue execution near EOF;
504
Borislav Petkov53f049f2007-05-08 00:30:54 -0700505# get kernel version from env
506sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700507 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700508
509 if (defined($ENV{'KERNELVERSION'})) {
510 $version = $ENV{'KERNELVERSION'};
511 }
512 return $version;
513}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200515#
516sub print_lineno {
517 my $lineno = shift;
518 if ($enable_lineno && defined($lineno)) {
519 print "#define LINENO " . $lineno . "\n";
520 }
521}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522##
523# dumps section contents to arrays/hashes intended for that purpose.
524#
525sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700526 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 my $name = shift;
528 my $contents = join "\n", @_;
529
Jani Nikula13901ef2016-05-26 08:57:29 +0300530 if ($name =~ m/$type_param/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531# print STDERR "parameter def '$1' = '$contents'\n";
532 $name = $1;
533 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800534 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200535 $parameterdesc_start_lines{$name} = $new_start_line;
536 $new_start_line = 0;
Randy Dunlapced69092008-12-01 13:14:03 -0800537 } elsif ($name eq "@\.\.\.") {
538# print STDERR "parameter def '...' = '$contents'\n";
539 $name = "...";
540 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800541 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200542 $parameterdesc_start_lines{$name} = $new_start_line;
543 $new_start_line = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 } else {
545# print STDERR "other section '$name' = '$contents'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700546 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Jani Nikula32217762016-05-29 09:40:44 +0300547 print STDERR "${file}:$.: warning: duplicate section name '$name'\n";
548 ++$warnings;
549 $sections{$name} .= $contents;
550 } else {
551 $sections{$name} = $contents;
552 push @sectionlist, $name;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200553 $section_start_lines{$name} = $new_start_line;
554 $new_start_line = 0;
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700555 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 }
557}
558
559##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700560# dump DOC: section after checking that it should go out
561#
562sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700563 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700564 my $name = shift;
565 my $contents = join "\n", @_;
566
Johannes Berg4b445952007-10-24 15:08:48 -0700567 if ($no_doc_sections) {
568 return;
569 }
570
Jani Nikulab6c3f452016-05-29 22:19:35 +0300571 if (($output_selection == OUTPUT_ALL) ||
572 ($output_selection == OUTPUT_INCLUDE &&
573 defined($function_table{$name})) ||
574 ($output_selection == OUTPUT_EXCLUDE &&
575 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700576 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700577 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700578 output_blockhead({'sectionlist' => \@sectionlist,
579 'sections' => \%sections,
580 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300581 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700582 }
583}
584
585##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586# output function
587#
588# parameterdescs, a hash.
589# function => "function name"
590# parameterlist => @list of parameters
591# parameterdescs => %parameter descriptions
592# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800593# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800594#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596sub output_highlight {
597 my $contents = join "\n",@_;
598 my $line;
599
600# DEBUG
601# if (!defined $contents) {
602# use Carp;
603# confess "output_highlight got called with no args?\n";
604# }
605
Dan Luedtke1b40c192012-08-12 10:46:15 +0200606 if ($output_mode eq "html" || $output_mode eq "html5" ||
607 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700608 $contents = local_unescape($contents);
609 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800610 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700611 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700612# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 eval $dohighlight;
614 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700615# print STDERR "contents af:$contents\n";
616
Dan Luedtke1b40c192012-08-12 10:46:15 +0200617# strip whitespaces when generating html5
618 if ($output_mode eq "html5") {
619 $contents =~ s/^\s+//;
620 $contents =~ s/\s+$//;
621 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700623 if (! $output_preformatted) {
624 $line =~ s/^\s*//;
625 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700626 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700627 if (! $output_preformatted) {
628 print $lineprefix, local_unescape($blankline);
629 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700631 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700632 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
633 print "\\&$line";
634 } else {
635 print $lineprefix, $line;
636 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 }
638 print "\n";
639 }
640}
641
Dan Luedtke1b40c192012-08-12 10:46:15 +0200642# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643sub output_section_html(%) {
644 my %args = %{$_[0]};
645 my $section;
646
647 foreach $section (@{$args{'sectionlist'}}) {
648 print "<h3>$section</h3>\n";
649 print "<blockquote>\n";
650 output_highlight($args{'sections'}{$section});
651 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800652 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653}
654
655# output enum in html
656sub output_enum_html(%) {
657 my %args = %{$_[0]};
658 my ($parameter);
659 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700660 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Randy Dunlapb9d973282009-06-09 08:50:38 -0700662 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 $count = 0;
664 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700665 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 if ($count != $#{$args{'parameterlist'}}) {
667 $count++;
668 print ",\n";
669 }
670 print "<br>";
671 }
672 print "};<br>\n";
673
674 print "<h3>Constants</h3>\n";
675 print "<dl>\n";
676 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700677 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 print "<dd>";
679 output_highlight($args{'parameterdescs'}{$parameter});
680 }
681 print "</dl>\n";
682 output_section_html(@_);
683 print "<hr>\n";
684}
685
Randy Dunlapd28bee02006-02-01 03:06:57 -0800686# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687sub output_typedef_html(%) {
688 my %args = %{$_[0]};
689 my ($parameter);
690 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700691 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
Randy Dunlapb9d973282009-06-09 08:50:38 -0700693 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 output_section_html(@_);
695 print "<hr>\n";
696}
697
698# output struct in html
699sub output_struct_html(%) {
700 my %args = %{$_[0]};
701 my ($parameter);
702
Randy Dunlapb9d973282009-06-09 08:50:38 -0700703 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
704 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 foreach $parameter (@{$args{'parameterlist'}}) {
706 if ($parameter =~ /^#/) {
707 print "$parameter<br>\n";
708 next;
709 }
710 my $parameter_name = $parameter;
711 $parameter_name =~ s/\[.*//;
712
Randy Dunlap3c308792007-05-08 00:24:39 -0700713 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 $type = $args{'parametertypes'}{$parameter};
715 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
716 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700717 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700719 # bitfield
720 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700722 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 }
724 }
725 print "};<br>\n";
726
727 print "<h3>Members</h3>\n";
728 print "<dl>\n";
729 foreach $parameter (@{$args{'parameterlist'}}) {
730 ($parameter =~ /^#/) && next;
731
732 my $parameter_name = $parameter;
733 $parameter_name =~ s/\[.*//;
734
Randy Dunlap3c308792007-05-08 00:24:39 -0700735 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700736 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 print "<dd>";
738 output_highlight($args{'parameterdescs'}{$parameter_name});
739 }
740 print "</dl>\n";
741 output_section_html(@_);
742 print "<hr>\n";
743}
744
745# output function in html
746sub output_function_html(%) {
747 my %args = %{$_[0]};
748 my ($parameter, $section);
749 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
Randy Dunlapb9d973282009-06-09 08:50:38 -0700751 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
752 print "<i>" . $args{'functiontype'} . "</i>\n";
753 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 print "(";
755 $count = 0;
756 foreach $parameter (@{$args{'parameterlist'}}) {
757 $type = $args{'parametertypes'}{$parameter};
758 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
759 # pointer-to-function
760 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
761 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700762 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 }
764 if ($count != $#{$args{'parameterlist'}}) {
765 $count++;
766 print ",\n";
767 }
768 }
769 print ")\n";
770
771 print "<h3>Arguments</h3>\n";
772 print "<dl>\n";
773 foreach $parameter (@{$args{'parameterlist'}}) {
774 my $parameter_name = $parameter;
775 $parameter_name =~ s/\[.*//;
776
Randy Dunlap3c308792007-05-08 00:24:39 -0700777 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700778 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 print "<dd>";
780 output_highlight($args{'parameterdescs'}{$parameter_name});
781 }
782 print "</dl>\n";
783 output_section_html(@_);
784 print "<hr>\n";
785}
786
Johannes Bergb112e0f2007-10-24 15:08:48 -0700787# output DOC: block header in html
788sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 my %args = %{$_[0]};
790 my ($parameter, $section);
791 my $count;
792
793 foreach $section (@{$args{'sectionlist'}}) {
794 print "<h3>$section</h3>\n";
795 print "<ul>\n";
796 output_highlight($args{'sections'}{$section});
797 print "</ul>\n";
798 }
799 print "<hr>\n";
800}
801
Dan Luedtke1b40c192012-08-12 10:46:15 +0200802# output sections in html5
803sub output_section_html5(%) {
804 my %args = %{$_[0]};
805 my $section;
806
807 foreach $section (@{$args{'sectionlist'}}) {
808 print "<section>\n";
809 print "<h1>$section</h1>\n";
810 print "<p>\n";
811 output_highlight($args{'sections'}{$section});
812 print "</p>\n";
813 print "</section>\n";
814 }
815}
816
817# output enum in html5
818sub output_enum_html5(%) {
819 my %args = %{$_[0]};
820 my ($parameter);
821 my $count;
822 my $html5id;
823
824 $html5id = $args{'enum'};
825 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
826 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
827 print "<h1>enum " . $args{'enum'} . "</h1>\n";
828 print "<ol class=\"code\">\n";
829 print "<li>";
830 print "<span class=\"keyword\">enum</span> ";
831 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
832 print "</li>\n";
833 $count = 0;
834 foreach $parameter (@{$args{'parameterlist'}}) {
835 print "<li class=\"indent\">";
836 print "<span class=\"param\">" . $parameter . "</span>";
837 if ($count != $#{$args{'parameterlist'}}) {
838 $count++;
839 print ",";
840 }
841 print "</li>\n";
842 }
843 print "<li>};</li>\n";
844 print "</ol>\n";
845
846 print "<section>\n";
847 print "<h1>Constants</h1>\n";
848 print "<dl>\n";
849 foreach $parameter (@{$args{'parameterlist'}}) {
850 print "<dt>" . $parameter . "</dt>\n";
851 print "<dd>";
852 output_highlight($args{'parameterdescs'}{$parameter});
853 print "</dd>\n";
854 }
855 print "</dl>\n";
856 print "</section>\n";
857 output_section_html5(@_);
858 print "</article>\n";
859}
860
861# output typedef in html5
862sub output_typedef_html5(%) {
863 my %args = %{$_[0]};
864 my ($parameter);
865 my $count;
866 my $html5id;
867
868 $html5id = $args{'typedef'};
869 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
870 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
871 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
872
873 print "<ol class=\"code\">\n";
874 print "<li>";
875 print "<span class=\"keyword\">typedef</span> ";
876 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
877 print "</li>\n";
878 print "</ol>\n";
879 output_section_html5(@_);
880 print "</article>\n";
881}
882
883# output struct in html5
884sub output_struct_html5(%) {
885 my %args = %{$_[0]};
886 my ($parameter);
887 my $html5id;
888
889 $html5id = $args{'struct'};
890 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
891 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
892 print "<hgroup>\n";
893 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
894 print "<h2>". $args{'purpose'} . "</h2>\n";
895 print "</hgroup>\n";
896 print "<ol class=\"code\">\n";
897 print "<li>";
898 print "<span class=\"type\">" . $args{'type'} . "</span> ";
899 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
900 print "</li>\n";
901 foreach $parameter (@{$args{'parameterlist'}}) {
902 print "<li class=\"indent\">";
903 if ($parameter =~ /^#/) {
904 print "<span class=\"param\">" . $parameter ."</span>\n";
905 print "</li>\n";
906 next;
907 }
908 my $parameter_name = $parameter;
909 $parameter_name =~ s/\[.*//;
910
911 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
912 $type = $args{'parametertypes'}{$parameter};
913 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
914 # pointer-to-function
915 print "<span class=\"type\">$1</span> ";
916 print "<span class=\"param\">$parameter</span>";
917 print "<span class=\"type\">)</span> ";
918 print "(<span class=\"args\">$2</span>);";
919 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
920 # bitfield
921 print "<span class=\"type\">$1</span> ";
922 print "<span class=\"param\">$parameter</span>";
923 print "<span class=\"bits\">$2</span>;";
924 } else {
925 print "<span class=\"type\">$type</span> ";
926 print "<span class=\"param\">$parameter</span>;";
927 }
928 print "</li>\n";
929 }
930 print "<li>};</li>\n";
931 print "</ol>\n";
932
933 print "<section>\n";
934 print "<h1>Members</h1>\n";
935 print "<dl>\n";
936 foreach $parameter (@{$args{'parameterlist'}}) {
937 ($parameter =~ /^#/) && next;
938
939 my $parameter_name = $parameter;
940 $parameter_name =~ s/\[.*//;
941
942 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
943 print "<dt>" . $parameter . "</dt>\n";
944 print "<dd>";
945 output_highlight($args{'parameterdescs'}{$parameter_name});
946 print "</dd>\n";
947 }
948 print "</dl>\n";
949 print "</section>\n";
950 output_section_html5(@_);
951 print "</article>\n";
952}
953
954# output function in html5
955sub output_function_html5(%) {
956 my %args = %{$_[0]};
957 my ($parameter, $section);
958 my $count;
959 my $html5id;
960
961 $html5id = $args{'function'};
962 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
963 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
964 print "<hgroup>\n";
965 print "<h1>" . $args{'function'} . "</h1>";
966 print "<h2>" . $args{'purpose'} . "</h2>\n";
967 print "</hgroup>\n";
968 print "<ol class=\"code\">\n";
969 print "<li>";
970 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
971 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
972 print "</li>";
973 $count = 0;
974 foreach $parameter (@{$args{'parameterlist'}}) {
975 print "<li class=\"indent\">";
976 $type = $args{'parametertypes'}{$parameter};
977 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
978 # pointer-to-function
979 print "<span class=\"type\">$1</span> ";
980 print "<span class=\"param\">$parameter</span>";
981 print "<span class=\"type\">)</span> ";
982 print "(<span class=\"args\">$2</span>)";
983 } else {
984 print "<span class=\"type\">$type</span> ";
985 print "<span class=\"param\">$parameter</span>";
986 }
987 if ($count != $#{$args{'parameterlist'}}) {
988 $count++;
989 print ",";
990 }
991 print "</li>\n";
992 }
993 print "<li>)</li>\n";
994 print "</ol>\n";
995
996 print "<section>\n";
997 print "<h1>Arguments</h1>\n";
998 print "<p>\n";
999 print "<dl>\n";
1000 foreach $parameter (@{$args{'parameterlist'}}) {
1001 my $parameter_name = $parameter;
1002 $parameter_name =~ s/\[.*//;
1003
1004 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1005 print "<dt>" . $parameter . "</dt>\n";
1006 print "<dd>";
1007 output_highlight($args{'parameterdescs'}{$parameter_name});
1008 print "</dd>\n";
1009 }
1010 print "</dl>\n";
1011 print "</section>\n";
1012 output_section_html5(@_);
1013 print "</article>\n";
1014}
1015
1016# output DOC: block header in html5
1017sub output_blockhead_html5(%) {
1018 my %args = %{$_[0]};
1019 my ($parameter, $section);
1020 my $count;
1021 my $html5id;
1022
1023 foreach $section (@{$args{'sectionlist'}}) {
1024 $html5id = $section;
1025 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1026 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1027 print "<h1>$section</h1>\n";
1028 print "<p>\n";
1029 output_highlight($args{'sections'}{$section});
1030 print "</p>\n";
1031 }
1032 print "</article>\n";
1033}
1034
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035sub output_section_xml(%) {
1036 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001037 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038 # print out each section
1039 $lineprefix=" ";
1040 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001041 print "<refsect1>\n";
1042 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001044 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001045 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001046 } else {
1047 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 }
1049 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001050 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001052 print "</programlisting></informalexample>\n";
1053 } else {
1054 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001056 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 }
1058}
1059
1060# output function in XML DocBook
1061sub output_function_xml(%) {
1062 my %args = %{$_[0]};
1063 my ($parameter, $section);
1064 my $count;
1065 my $id;
1066
Randy Dunlapb9d973282009-06-09 08:50:38 -07001067 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 $id =~ s/[^A-Za-z0-9]/-/g;
1069
Pavel Pisa5449bc92007-02-10 01:45:37 -08001070 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001071 print "<refentryinfo>\n";
1072 print " <title>LINUX</title>\n";
1073 print " <productname>Kernel Hackers Manual</productname>\n";
1074 print " <date>$man_date</date>\n";
1075 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001077 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001078 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001079 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001080 print "</refmeta>\n";
1081 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001082 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 print " <refpurpose>\n";
1084 print " ";
1085 output_highlight ($args{'purpose'});
1086 print " </refpurpose>\n";
1087 print "</refnamediv>\n";
1088
1089 print "<refsynopsisdiv>\n";
1090 print " <title>Synopsis</title>\n";
1091 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001092 print " <funcdef>" . $args{'functiontype'} . " ";
1093 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094
1095 $count = 0;
1096 if ($#{$args{'parameterlist'}} >= 0) {
1097 foreach $parameter (@{$args{'parameterlist'}}) {
1098 $type = $args{'parametertypes'}{$parameter};
1099 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1100 # pointer-to-function
1101 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1102 print " <funcparams>$2</funcparams></paramdef>\n";
1103 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001104 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 print " <parameter>$parameter</parameter></paramdef>\n";
1106 }
1107 }
1108 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001109 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 }
1111 print " </funcprototype></funcsynopsis>\n";
1112 print "</refsynopsisdiv>\n";
1113
1114 # print parameters
1115 print "<refsect1>\n <title>Arguments</title>\n";
1116 if ($#{$args{'parameterlist'}} >= 0) {
1117 print " <variablelist>\n";
1118 foreach $parameter (@{$args{'parameterlist'}}) {
1119 my $parameter_name = $parameter;
1120 $parameter_name =~ s/\[.*//;
1121
1122 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1123 print " <listitem>\n <para>\n";
1124 $lineprefix=" ";
1125 output_highlight($args{'parameterdescs'}{$parameter_name});
1126 print " </para>\n </listitem>\n </varlistentry>\n";
1127 }
1128 print " </variablelist>\n";
1129 } else {
1130 print " <para>\n None\n </para>\n";
1131 }
1132 print "</refsect1>\n";
1133
1134 output_section_xml(@_);
1135 print "</refentry>\n\n";
1136}
1137
1138# output struct in XML DocBook
1139sub output_struct_xml(%) {
1140 my %args = %{$_[0]};
1141 my ($parameter, $section);
1142 my $id;
1143
Randy Dunlapb9d973282009-06-09 08:50:38 -07001144 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 $id =~ s/[^A-Za-z0-9]/-/g;
1146
Pavel Pisa5449bc92007-02-10 01:45:37 -08001147 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001148 print "<refentryinfo>\n";
1149 print " <title>LINUX</title>\n";
1150 print " <productname>Kernel Hackers Manual</productname>\n";
1151 print " <date>$man_date</date>\n";
1152 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001154 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001155 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001156 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 print "</refmeta>\n";
1158 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001159 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 print " <refpurpose>\n";
1161 print " ";
1162 output_highlight ($args{'purpose'});
1163 print " </refpurpose>\n";
1164 print "</refnamediv>\n";
1165
1166 print "<refsynopsisdiv>\n";
1167 print " <title>Synopsis</title>\n";
1168 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001169 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 foreach $parameter (@{$args{'parameterlist'}}) {
1171 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001172 my $prm = $parameter;
1173 # convert data read & converted thru xml_escape() into &xyz; format:
1174 # This allows us to have #define macros interspersed in a struct.
1175 $prm =~ s/\\\\\\/\&/g;
1176 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 next;
1178 }
1179
1180 my $parameter_name = $parameter;
1181 $parameter_name =~ s/\[.*//;
1182
1183 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001184 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 $type = $args{'parametertypes'}{$parameter};
1186 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1187 # pointer-to-function
1188 print " $1 $parameter) ($2);\n";
1189 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001190 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 print " $1 $parameter$2;\n";
1192 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001193 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 }
1195 }
1196 print "};";
1197 print " </programlisting>\n";
1198 print "</refsynopsisdiv>\n";
1199
1200 print " <refsect1>\n";
1201 print " <title>Members</title>\n";
1202
Randy Dunlap39f00c02008-09-22 13:57:44 -07001203 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 print " <variablelist>\n";
1205 foreach $parameter (@{$args{'parameterlist'}}) {
1206 ($parameter =~ /^#/) && next;
1207
1208 my $parameter_name = $parameter;
1209 $parameter_name =~ s/\[.*//;
1210
1211 defined($args{'parameterdescs'}{$parameter_name}) || next;
1212 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1213 print " <varlistentry>";
1214 print " <term>$parameter</term>\n";
1215 print " <listitem><para>\n";
1216 output_highlight($args{'parameterdescs'}{$parameter_name});
1217 print " </para></listitem>\n";
1218 print " </varlistentry>\n";
1219 }
1220 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001221 } else {
1222 print " <para>\n None\n </para>\n";
1223 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 print " </refsect1>\n";
1225
1226 output_section_xml(@_);
1227
1228 print "</refentry>\n\n";
1229}
1230
1231# output enum in XML DocBook
1232sub output_enum_xml(%) {
1233 my %args = %{$_[0]};
1234 my ($parameter, $section);
1235 my $count;
1236 my $id;
1237
Randy Dunlapb9d973282009-06-09 08:50:38 -07001238 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 $id =~ s/[^A-Za-z0-9]/-/g;
1240
Pavel Pisa5449bc92007-02-10 01:45:37 -08001241 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001242 print "<refentryinfo>\n";
1243 print " <title>LINUX</title>\n";
1244 print " <productname>Kernel Hackers Manual</productname>\n";
1245 print " <date>$man_date</date>\n";
1246 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001248 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001249 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001250 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 print "</refmeta>\n";
1252 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001253 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 print " <refpurpose>\n";
1255 print " ";
1256 output_highlight ($args{'purpose'});
1257 print " </refpurpose>\n";
1258 print "</refnamediv>\n";
1259
1260 print "<refsynopsisdiv>\n";
1261 print " <title>Synopsis</title>\n";
1262 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001263 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 $count = 0;
1265 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001266 print " $parameter";
1267 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 $count++;
1269 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001270 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 print "\n";
1272 }
1273 print "};";
1274 print " </programlisting>\n";
1275 print "</refsynopsisdiv>\n";
1276
1277 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001278 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 print " <variablelist>\n";
1280 foreach $parameter (@{$args{'parameterlist'}}) {
1281 my $parameter_name = $parameter;
1282 $parameter_name =~ s/\[.*//;
1283
1284 print " <varlistentry>";
1285 print " <term>$parameter</term>\n";
1286 print " <listitem><para>\n";
1287 output_highlight($args{'parameterdescs'}{$parameter_name});
1288 print " </para></listitem>\n";
1289 print " </varlistentry>\n";
1290 }
1291 print " </variablelist>\n";
1292 print "</refsect1>\n";
1293
1294 output_section_xml(@_);
1295
1296 print "</refentry>\n\n";
1297}
1298
1299# output typedef in XML DocBook
1300sub output_typedef_xml(%) {
1301 my %args = %{$_[0]};
1302 my ($parameter, $section);
1303 my $id;
1304
Randy Dunlapb9d973282009-06-09 08:50:38 -07001305 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306 $id =~ s/[^A-Za-z0-9]/-/g;
1307
Pavel Pisa5449bc92007-02-10 01:45:37 -08001308 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001309 print "<refentryinfo>\n";
1310 print " <title>LINUX</title>\n";
1311 print " <productname>Kernel Hackers Manual</productname>\n";
1312 print " <date>$man_date</date>\n";
1313 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001315 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001316 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 print "</refmeta>\n";
1318 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001319 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 print " <refpurpose>\n";
1321 print " ";
1322 output_highlight ($args{'purpose'});
1323 print " </refpurpose>\n";
1324 print "</refnamediv>\n";
1325
1326 print "<refsynopsisdiv>\n";
1327 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001328 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 print "</refsynopsisdiv>\n";
1330
1331 output_section_xml(@_);
1332
1333 print "</refentry>\n\n";
1334}
1335
1336# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001337sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 my %args = %{$_[0]};
1339 my ($parameter, $section);
1340 my $count;
1341
1342 my $id = $args{'module'};
1343 $id =~ s/[^A-Za-z0-9]/-/g;
1344
1345 # print out each section
1346 $lineprefix=" ";
1347 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001348 if (!$args{'content-only'}) {
1349 print "<refsect1>\n <title>$section</title>\n";
1350 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 if ($section =~ m/EXAMPLE/i) {
1352 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001353 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001354 } else {
1355 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 }
1357 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001358 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 if ($section =~ m/EXAMPLE/i) {
1360 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001361 } else {
1362 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001364 if (!$args{'content-only'}) {
1365 print "\n</refsect1>\n";
1366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367 }
1368
1369 print "\n\n";
1370}
1371
1372# output in XML DocBook
1373sub output_function_gnome {
1374 my %args = %{$_[0]};
1375 my ($parameter, $section);
1376 my $count;
1377 my $id;
1378
Randy Dunlapb9d973282009-06-09 08:50:38 -07001379 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 $id =~ s/[^A-Za-z0-9]/-/g;
1381
1382 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001383 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
1385 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001386 print " <funcdef>" . $args{'functiontype'} . " ";
1387 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 print "</function></funcdef>\n";
1389
1390 $count = 0;
1391 if ($#{$args{'parameterlist'}} >= 0) {
1392 foreach $parameter (@{$args{'parameterlist'}}) {
1393 $type = $args{'parametertypes'}{$parameter};
1394 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1395 # pointer-to-function
1396 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1397 print " <funcparams>$2</funcparams></paramdef>\n";
1398 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001399 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 print " <parameter>$parameter</parameter></paramdef>\n";
1401 }
1402 }
1403 } else {
1404 print " <void>\n";
1405 }
1406 print " </funcsynopsis>\n";
1407 if ($#{$args{'parameterlist'}} >= 0) {
1408 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1409 print "<tgroup cols=\"2\">\n";
1410 print "<colspec colwidth=\"2*\">\n";
1411 print "<colspec colwidth=\"8*\">\n";
1412 print "<tbody>\n";
1413 foreach $parameter (@{$args{'parameterlist'}}) {
1414 my $parameter_name = $parameter;
1415 $parameter_name =~ s/\[.*//;
1416
1417 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1418 print " <entry>\n";
1419 $lineprefix=" ";
1420 output_highlight($args{'parameterdescs'}{$parameter_name});
1421 print " </entry></row>\n";
1422 }
1423 print " </tbody></tgroup></informaltable>\n";
1424 } else {
1425 print " <para>\n None\n </para>\n";
1426 }
1427
1428 # print out each section
1429 $lineprefix=" ";
1430 foreach $section (@{$args{'sectionlist'}}) {
1431 print "<simplesect>\n <title>$section</title>\n";
1432 if ($section =~ m/EXAMPLE/i) {
1433 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001434 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 } else {
1436 }
1437 print "<para>\n";
1438 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001439 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 print "</para>\n";
1441 if ($section =~ m/EXAMPLE/i) {
1442 print "</programlisting></example>\n";
1443 } else {
1444 }
1445 print " </simplesect>\n";
1446 }
1447
1448 print "</sect2>\n\n";
1449}
1450
1451##
1452# output function in man
1453sub output_function_man(%) {
1454 my %args = %{$_[0]};
1455 my ($parameter, $section);
1456 my $count;
1457
1458 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1459
1460 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001461 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
1463 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001464 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001465 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001466 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001467 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001468 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 $count = 0;
1470 my $parenth = "(";
1471 my $post = ",";
1472 foreach my $parameter (@{$args{'parameterlist'}}) {
1473 if ($count == $#{$args{'parameterlist'}}) {
1474 $post = ");";
1475 }
1476 $type = $args{'parametertypes'}{$parameter};
1477 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1478 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001479 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 } else {
1481 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001482 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 }
1484 $count++;
1485 $parenth = "";
1486 }
1487
1488 print ".SH ARGUMENTS\n";
1489 foreach $parameter (@{$args{'parameterlist'}}) {
1490 my $parameter_name = $parameter;
1491 $parameter_name =~ s/\[.*//;
1492
Randy Dunlapb9d973282009-06-09 08:50:38 -07001493 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 output_highlight($args{'parameterdescs'}{$parameter_name});
1495 }
1496 foreach $section (@{$args{'sectionlist'}}) {
1497 print ".SH \"", uc $section, "\"\n";
1498 output_highlight($args{'sections'}{$section});
1499 }
1500}
1501
1502##
1503# output enum in man
1504sub output_enum_man(%) {
1505 my %args = %{$_[0]};
1506 my ($parameter, $section);
1507 my $count;
1508
1509 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1510
1511 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001512 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513
1514 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001515 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 $count = 0;
1517 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001518 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 if ($count == $#{$args{'parameterlist'}}) {
1520 print "\n};\n";
1521 last;
1522 }
1523 else {
1524 print ", \n.br\n";
1525 }
1526 $count++;
1527 }
1528
1529 print ".SH Constants\n";
1530 foreach $parameter (@{$args{'parameterlist'}}) {
1531 my $parameter_name = $parameter;
1532 $parameter_name =~ s/\[.*//;
1533
Randy Dunlapb9d973282009-06-09 08:50:38 -07001534 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 output_highlight($args{'parameterdescs'}{$parameter_name});
1536 }
1537 foreach $section (@{$args{'sectionlist'}}) {
1538 print ".SH \"$section\"\n";
1539 output_highlight($args{'sections'}{$section});
1540 }
1541}
1542
1543##
1544# output struct in man
1545sub output_struct_man(%) {
1546 my %args = %{$_[0]};
1547 my ($parameter, $section);
1548
Randy Dunlapb9d973282009-06-09 08:50:38 -07001549 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550
1551 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001552 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
1554 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001555 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
1557 foreach my $parameter (@{$args{'parameterlist'}}) {
1558 if ($parameter =~ /^#/) {
1559 print ".BI \"$parameter\"\n.br\n";
1560 next;
1561 }
1562 my $parameter_name = $parameter;
1563 $parameter_name =~ s/\[.*//;
1564
Randy Dunlap3c308792007-05-08 00:24:39 -07001565 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 $type = $args{'parametertypes'}{$parameter};
1567 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1568 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001569 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001571 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001572 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 } else {
1574 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001575 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 }
1577 print "\n.br\n";
1578 }
1579 print "};\n.br\n";
1580
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001581 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 foreach $parameter (@{$args{'parameterlist'}}) {
1583 ($parameter =~ /^#/) && next;
1584
1585 my $parameter_name = $parameter;
1586 $parameter_name =~ s/\[.*//;
1587
Randy Dunlap3c308792007-05-08 00:24:39 -07001588 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001589 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 output_highlight($args{'parameterdescs'}{$parameter_name});
1591 }
1592 foreach $section (@{$args{'sectionlist'}}) {
1593 print ".SH \"$section\"\n";
1594 output_highlight($args{'sections'}{$section});
1595 }
1596}
1597
1598##
1599# output typedef in man
1600sub output_typedef_man(%) {
1601 my %args = %{$_[0]};
1602 my ($parameter, $section);
1603
1604 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1605
1606 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001607 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
1609 foreach $section (@{$args{'sectionlist'}}) {
1610 print ".SH \"$section\"\n";
1611 output_highlight($args{'sections'}{$section});
1612 }
1613}
1614
Johannes Bergb112e0f2007-10-24 15:08:48 -07001615sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 my %args = %{$_[0]};
1617 my ($parameter, $section);
1618 my $count;
1619
1620 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1621
1622 foreach $section (@{$args{'sectionlist'}}) {
1623 print ".SH \"$section\"\n";
1624 output_highlight($args{'sections'}{$section});
1625 }
1626}
1627
1628##
1629# output in text
1630sub output_function_text(%) {
1631 my %args = %{$_[0]};
1632 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001633 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
Randy Dunlapf47634b2006-07-01 04:36:36 -07001635 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001636 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001637
1638 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001639 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001640 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001641 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001642 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001645
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 my $count = 0;
1647 foreach my $parameter (@{$args{'parameterlist'}}) {
1648 $type = $args{'parametertypes'}{$parameter};
1649 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1650 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001651 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001653 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 }
1655 if ($count != $#{$args{'parameterlist'}}) {
1656 $count++;
1657 print ",\n";
1658 print " " x length($start);
1659 } else {
1660 print ");\n\n";
1661 }
1662 }
1663
1664 print "Arguments:\n\n";
1665 foreach $parameter (@{$args{'parameterlist'}}) {
1666 my $parameter_name = $parameter;
1667 $parameter_name =~ s/\[.*//;
1668
Randy Dunlapb9d973282009-06-09 08:50:38 -07001669 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 }
1671 output_section_text(@_);
1672}
1673
1674#output sections in text
1675sub output_section_text(%) {
1676 my %args = %{$_[0]};
1677 my $section;
1678
1679 print "\n";
1680 foreach $section (@{$args{'sectionlist'}}) {
1681 print "$section:\n\n";
1682 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001683 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 print "\n\n";
1685}
1686
1687# output enum in text
1688sub output_enum_text(%) {
1689 my %args = %{$_[0]};
1690 my ($parameter);
1691 my $count;
1692 print "Enum:\n\n";
1693
Randy Dunlapb9d973282009-06-09 08:50:38 -07001694 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1695 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 $count = 0;
1697 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001698 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 if ($count != $#{$args{'parameterlist'}}) {
1700 $count++;
1701 print ",";
1702 }
1703 print "\n";
1704 }
1705 print "};\n\n";
1706
1707 print "Constants:\n\n";
1708 foreach $parameter (@{$args{'parameterlist'}}) {
1709 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001710 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 }
1712
1713 output_section_text(@_);
1714}
1715
1716# output typedef in text
1717sub output_typedef_text(%) {
1718 my %args = %{$_[0]};
1719 my ($parameter);
1720 my $count;
1721 print "Typedef:\n\n";
1722
Randy Dunlapb9d973282009-06-09 08:50:38 -07001723 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724 output_section_text(@_);
1725}
1726
1727# output struct as text
1728sub output_struct_text(%) {
1729 my %args = %{$_[0]};
1730 my ($parameter);
1731
Randy Dunlapb9d973282009-06-09 08:50:38 -07001732 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1733 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 foreach $parameter (@{$args{'parameterlist'}}) {
1735 if ($parameter =~ /^#/) {
1736 print "$parameter\n";
1737 next;
1738 }
1739
1740 my $parameter_name = $parameter;
1741 $parameter_name =~ s/\[.*//;
1742
Randy Dunlap3c308792007-05-08 00:24:39 -07001743 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 $type = $args{'parametertypes'}{$parameter};
1745 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1746 # pointer-to-function
1747 print "\t$1 $parameter) ($2);\n";
1748 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001749 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 print "\t$1 $parameter$2;\n";
1751 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001752 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 }
1754 }
1755 print "};\n\n";
1756
1757 print "Members:\n\n";
1758 foreach $parameter (@{$args{'parameterlist'}}) {
1759 ($parameter =~ /^#/) && next;
1760
1761 my $parameter_name = $parameter;
1762 $parameter_name =~ s/\[.*//;
1763
Randy Dunlap3c308792007-05-08 00:24:39 -07001764 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001766 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 }
1768 print "\n";
1769 output_section_text(@_);
1770}
1771
Johannes Bergb112e0f2007-10-24 15:08:48 -07001772sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 my %args = %{$_[0]};
1774 my ($parameter, $section);
1775
1776 foreach $section (@{$args{'sectionlist'}}) {
1777 print " $section:\n";
1778 print " -> ";
1779 output_highlight($args{'sections'}{$section});
1780 }
1781}
1782
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001783##
1784# output in restructured text
1785#
1786
1787#
1788# This could use some work; it's used to output the DOC: sections, and
1789# starts by putting out the name of the doc section itself, but that tends
1790# to duplicate a header already in the template file.
1791#
1792sub output_blockhead_rst(%) {
1793 my %args = %{$_[0]};
1794 my ($parameter, $section);
1795
1796 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001797 if ($output_selection != OUTPUT_INCLUDE) {
1798 print "**$section**\n\n";
1799 }
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001800 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001801 output_highlight_rst($args{'sections'}{$section});
1802 print "\n";
1803 }
1804}
1805
1806sub output_highlight_rst {
1807 my $contents = join "\n",@_;
1808 my $line;
1809
1810 # undo the evil effects of xml_escape() earlier
1811 $contents = xml_unescape($contents);
1812
1813 eval $dohighlight;
1814 die $@ if $@;
1815
1816 foreach $line (split "\n", $contents) {
Jani Nikula830066a2016-05-26 22:04:33 +03001817 print $lineprefix . $line . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001818 }
1819}
1820
1821sub output_function_rst(%) {
1822 my %args = %{$_[0]};
1823 my ($parameter, $section);
Jani Nikulac099ff62016-05-26 17:18:17 +03001824 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001825 my $start;
1826
1827 print ".. c:function:: ";
1828 if ($args{'functiontype'} ne "") {
1829 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1830 } else {
1831 $start = $args{'function'} . " (";
1832 }
1833 print $start;
1834
1835 my $count = 0;
1836 foreach my $parameter (@{$args{'parameterlist'}}) {
1837 if ($count ne 0) {
1838 print ", ";
1839 }
1840 $count++;
1841 $type = $args{'parametertypes'}{$parameter};
1842 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1843 # pointer-to-function
1844 print $1 . $parameter . ") (" . $2;
1845 } else {
1846 print $type . " " . $parameter;
1847 }
1848 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001849 print ")\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001850 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001851 $lineprefix = " ";
1852 output_highlight_rst($args{'purpose'});
1853 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001854
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001855 print "**Parameters**\n\n";
1856 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001857 foreach $parameter (@{$args{'parameterlist'}}) {
1858 my $parameter_name = $parameter;
1859 #$parameter_name =~ s/\[.*//;
1860 $type = $args{'parametertypes'}{$parameter};
1861
1862 if ($type ne "") {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001863 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001864 } else {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001865 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001866 }
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001867
1868 print_lineno($parameterdesc_start_lines{$parameter_name});
1869
Jani Nikula5e64fa92016-05-19 20:32:48 +03001870 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1871 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001872 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001873 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001874 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001875 }
1876 print "\n";
1877 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001878
1879 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001880 output_section_rst(@_);
1881}
1882
1883sub output_section_rst(%) {
1884 my %args = %{$_[0]};
1885 my $section;
1886 my $oldprefix = $lineprefix;
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001887 $lineprefix = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001888
1889 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001890 print "**$section**\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001891 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001892 output_highlight_rst($args{'sections'}{$section});
1893 print "\n";
1894 }
1895 print "\n";
1896 $lineprefix = $oldprefix;
1897}
1898
1899sub output_enum_rst(%) {
1900 my %args = %{$_[0]};
1901 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001902 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001903 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001904 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001905
1906 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001907 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001908 $lineprefix = " ";
1909 output_highlight_rst($args{'purpose'});
1910 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001911
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001912 print "**Constants**\n\n";
1913 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001914 foreach $parameter (@{$args{'parameterlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001915 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001916 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1917 output_highlight_rst($args{'parameterdescs'}{$parameter});
1918 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001919 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001920 }
1921 print "\n";
1922 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001923
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001924 $lineprefix = $oldprefix;
1925 output_section_rst(@_);
1926}
1927
1928sub output_typedef_rst(%) {
1929 my %args = %{$_[0]};
1930 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001931 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001932 my $name = "typedef " . $args{'typedef'};
1933
Jani Nikula62850972016-05-12 16:15:38 +03001934 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001935 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001936 $lineprefix = " ";
1937 output_highlight_rst($args{'purpose'});
1938 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001939
Jani Nikulac099ff62016-05-26 17:18:17 +03001940 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001941 output_section_rst(@_);
1942}
1943
1944sub output_struct_rst(%) {
1945 my %args = %{$_[0]};
1946 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001947 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001948 my $name = $args{'type'} . " " . $args{'struct'};
1949
Jani Nikula62850972016-05-12 16:15:38 +03001950 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001951 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001952 $lineprefix = " ";
1953 output_highlight_rst($args{'purpose'});
1954 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001955
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001956 print "**Definition**\n\n";
1957 print "::\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001958 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1959 foreach $parameter (@{$args{'parameterlist'}}) {
1960 if ($parameter =~ /^#/) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001961 print " " . "$parameter\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001962 next;
1963 }
1964
1965 my $parameter_name = $parameter;
1966 $parameter_name =~ s/\[.*//;
1967
1968 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1969 $type = $args{'parametertypes'}{$parameter};
1970 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1971 # pointer-to-function
1972 print " $1 $parameter) ($2);\n";
1973 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1974 # bitfield
1975 print " $1 $parameter$2;\n";
1976 } else {
1977 print " " . $type . " " . $parameter . ";\n";
1978 }
1979 }
1980 print " };\n\n";
1981
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001982 print "**Members**\n\n";
1983 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001984 foreach $parameter (@{$args{'parameterlist'}}) {
1985 ($parameter =~ /^#/) && next;
1986
1987 my $parameter_name = $parameter;
1988 $parameter_name =~ s/\[.*//;
1989
1990 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1991 $type = $args{'parametertypes'}{$parameter};
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001992 print_lineno($parameterdesc_start_lines{$parameter_name});
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001993 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001994 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001995 print "\n";
1996 }
1997 print "\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001998
1999 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002000 output_section_rst(@_);
2001}
2002
2003
Johannes Bergeda603f2010-09-11 15:55:22 -07002004## list mode output functions
2005
2006sub output_function_list(%) {
2007 my %args = %{$_[0]};
2008
2009 print $args{'function'} . "\n";
2010}
2011
2012# output enum in list
2013sub output_enum_list(%) {
2014 my %args = %{$_[0]};
2015 print $args{'enum'} . "\n";
2016}
2017
2018# output typedef in list
2019sub output_typedef_list(%) {
2020 my %args = %{$_[0]};
2021 print $args{'typedef'} . "\n";
2022}
2023
2024# output struct as list
2025sub output_struct_list(%) {
2026 my %args = %{$_[0]};
2027
2028 print $args{'struct'} . "\n";
2029}
2030
2031sub output_blockhead_list(%) {
2032 my %args = %{$_[0]};
2033 my ($parameter, $section);
2034
2035 foreach $section (@{$args{'sectionlist'}}) {
2036 print "DOC: $section\n";
2037 }
2038}
2039
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040##
Randy Dunlap27205742006-10-11 01:22:12 -07002041# generic output function for all types (function, struct/union, typedef, enum);
2042# calls the generated, variable output_ function name based on
2043# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044sub output_declaration {
2045 no strict 'refs';
2046 my $name = shift;
2047 my $functype = shift;
2048 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002049 if (($output_selection == OUTPUT_ALL) ||
2050 (($output_selection == OUTPUT_INCLUDE ||
2051 $output_selection == OUTPUT_EXPORTED) &&
2052 defined($function_table{$name})) ||
2053 (($output_selection == OUTPUT_EXCLUDE ||
2054 $output_selection == OUTPUT_INTERNAL) &&
2055 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002057 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 $section_counter++;
2059 }
2060}
2061
2062##
Randy Dunlap27205742006-10-11 01:22:12 -07002063# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002064sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002066 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 &$func(@_);
2068 $section_counter++;
2069}
2070
2071##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002072# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073# invokes the right handler. NOT called for functions.
2074sub dump_declaration($$) {
2075 no strict 'refs';
2076 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002077 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 &$func(@_);
2079}
2080
2081sub dump_union($$) {
2082 dump_struct(@_);
2083}
2084
2085sub dump_struct($$) {
2086 my $x = shift;
2087 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002088 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002090 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2091 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002092 $declaration_name = $2;
2093 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094
2095 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002096 $members =~ s/({.*})//g;
2097 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
Martin Waitzaeec46b2005-11-13 16:08:13 -08002099 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002100 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2101 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002102 # strip comments:
2103 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002104 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002105 # strip kmemcheck_bitfield_{begin,end}.*;
2106 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002107 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002108 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002109 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002110 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002111 # replace DECLARE_BITMAP
2112 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002113
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002115 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116
2117 output_declaration($declaration_name,
2118 'struct',
2119 {'struct' => $declaration_name,
2120 'module' => $modulename,
2121 'parameterlist' => \@parameterlist,
2122 'parameterdescs' => \%parameterdescs,
2123 'parametertypes' => \%parametertypes,
2124 'sectionlist' => \@sectionlist,
2125 'sections' => \%sections,
2126 'purpose' => $declaration_purpose,
2127 'type' => $decl_type
2128 });
2129 }
2130 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002131 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 ++$errors;
2133 }
2134}
2135
2136sub dump_enum($$) {
2137 my $x = shift;
2138 my $file = shift;
2139
Martin Waitzaeec46b2005-11-13 16:08:13 -08002140 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002141 # strip #define macros inside enums
2142 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002143
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002145 $declaration_name = $1;
2146 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147
2148 foreach my $arg (split ',', $members) {
2149 $arg =~ s/^\s*(\w+).*/$1/;
2150 push @parameterlist, $arg;
2151 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002152 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002153 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 "not described in enum '$declaration_name'\n";
2155 }
2156
2157 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002158
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 output_declaration($declaration_name,
2160 'enum',
2161 {'enum' => $declaration_name,
2162 'module' => $modulename,
2163 'parameterlist' => \@parameterlist,
2164 'parameterdescs' => \%parameterdescs,
2165 'sectionlist' => \@sectionlist,
2166 'sections' => \%sections,
2167 'purpose' => $declaration_purpose
2168 });
2169 }
2170 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002171 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 ++$errors;
2173 }
2174}
2175
2176sub dump_typedef($$) {
2177 my $x = shift;
2178 my $file = shift;
2179
Martin Waitzaeec46b2005-11-13 16:08:13 -08002180 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002181
2182 # Parse function prototypes
2183 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
2184 # Function typedefs
2185 $return_type = $1;
2186 $declaration_name = $2;
2187 my $args = $3;
2188
2189 create_parameterlist($args, ',', $file);
2190
2191 output_declaration($declaration_name,
2192 'function',
2193 {'function' => $declaration_name,
2194 'module' => $modulename,
2195 'functiontype' => $return_type,
2196 'parameterlist' => \@parameterlist,
2197 'parameterdescs' => \%parameterdescs,
2198 'parametertypes' => \%parametertypes,
2199 'sectionlist' => \@sectionlist,
2200 'sections' => \%sections,
2201 'purpose' => $declaration_purpose
2202 });
2203 return;
2204 }
2205
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002207 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 $x =~ s/\[*.\]\s*;$/;/;
2209 }
2210
2211 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002212 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
2214 output_declaration($declaration_name,
2215 'typedef',
2216 {'typedef' => $declaration_name,
2217 'module' => $modulename,
2218 'sectionlist' => \@sectionlist,
2219 'sections' => \%sections,
2220 'purpose' => $declaration_purpose
2221 });
2222 }
2223 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002224 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 ++$errors;
2226 }
2227}
2228
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002229sub save_struct_actual($) {
2230 my $actual = shift;
2231
2232 # strip all spaces from the actual param so that it looks like one string item
2233 $actual =~ s/\s*//g;
2234 $struct_actual = $struct_actual . $actual . " ";
2235}
2236
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237sub create_parameterlist($$$) {
2238 my $args = shift;
2239 my $splitter = shift;
2240 my $file = shift;
2241 my $type;
2242 my $param;
2243
Martin Waitza6d3fe72006-01-09 20:53:55 -08002244 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002246 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002248
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 foreach my $arg (split($splitter, $args)) {
2250 # strip comments
2251 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002252 # strip leading/trailing spaces
2253 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 $arg =~ s/\s*$//;
2255 $arg =~ s/\s+/ /;
2256
2257 if ($arg =~ /^#/) {
2258 # Treat preprocessor directive as a typeless variable just to fill
2259 # corresponding data structures "correctly". Catch it later in
2260 # output_* subs.
2261 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002262 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 # pointer-to-function
2264 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002265 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 $param = $1;
2267 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002268 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002269 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002271 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 $arg =~ s/\s*:\s*/:/g;
2273 $arg =~ s/\s*\[/\[/g;
2274
2275 my @args = split('\s*,\s*', $arg);
2276 if ($args[0] =~ m/\*/) {
2277 $args[0] =~ s/(\*+)\s*/ $1/;
2278 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002279
2280 my @first_arg;
2281 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2282 shift @args;
2283 push(@first_arg, split('\s+', $1));
2284 push(@first_arg, $2);
2285 } else {
2286 @first_arg = split('\s+', shift @args);
2287 }
2288
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 unshift(@args, pop @first_arg);
2290 $type = join " ", @first_arg;
2291
2292 foreach $param (@args) {
2293 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002294 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 push_parameter($2, "$type $1", $file);
2296 }
2297 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002298 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002299 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002300 push_parameter($1, "$type:$2", $file)
2301 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 }
2303 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002304 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 push_parameter($param, $type, $file);
2306 }
2307 }
2308 }
2309 }
2310}
2311
2312sub push_parameter($$$) {
2313 my $param = shift;
2314 my $type = shift;
2315 my $file = shift;
2316
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002317 if (($anon_struct_union == 1) && ($type eq "") &&
2318 ($param eq "}")) {
2319 return; # ignore the ending }; from anon. struct/union
2320 }
2321
2322 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 my $param_name = $param;
2324 $param_name =~ s/\[.*//;
2325
Martin Waitza6d3fe72006-01-09 20:53:55 -08002326 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 {
Randy Dunlapced69092008-12-01 13:14:03 -08002328 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2329 $parameterdescs{$param} = "variable arguments";
2330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 }
2332 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2333 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 $param="void";
2335 $parameterdescs{void} = "no arguments";
2336 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002337 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2338 # handle unnamed (anonymous) union or struct:
2339 {
2340 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002341 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002342 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002343 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002344 }
2345
Martin Waitza6d3fe72006-01-09 20:53:55 -08002346 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002347 # (but ignore ones starting with # as these are not parameters
2348 # but inline preprocessor statements);
2349 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002350 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002351 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2352
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 $parameterdescs{$param_name} = $undescribed;
2354
2355 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002356 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 "or member '$param' not " .
2358 "described in '$declaration_name'\n";
2359 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002360 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002361 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002363 }
2364 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002366 $param = xml_escape($param);
2367
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002368 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002369 # on @parameterlist;
2370 # this fixes a problem where check_sections() cannot find
2371 # a parameter like "addr[6 + 2]" because it actually appears
2372 # as "addr[6", "+", "2]" on the parameter list;
2373 # but it's better to maintain the param string unchanged for output,
2374 # so just weaken the string compare in check_sections() to ignore
2375 # "[blah" in a parameter string;
2376 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 push @parameterlist, $param;
2378 $parametertypes{$param} = $type;
2379}
2380
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002381sub check_sections($$$$$$) {
2382 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2383 my @sects = split ' ', $sectcheck;
2384 my @prms = split ' ', $prmscheck;
2385 my $err;
2386 my ($px, $sx);
2387 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2388
2389 foreach $sx (0 .. $#sects) {
2390 $err = 1;
2391 foreach $px (0 .. $#prms) {
2392 $prm_clean = $prms[$px];
2393 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002394 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002395 # ignore array size in a parameter string;
2396 # however, the original param string may contain
2397 # spaces, e.g.: addr[6 + 2]
2398 # and this appears in @prms as "addr[6" since the
2399 # parameter list is split at spaces;
2400 # hence just ignore "[..." for the sections check;
2401 $prm_clean =~ s/\[.*//;
2402
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002403 ##$prm_clean =~ s/^\**//;
2404 if ($prm_clean eq $sects[$sx]) {
2405 $err = 0;
2406 last;
2407 }
2408 }
2409 if ($err) {
2410 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002411 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002412 "Excess function parameter " .
2413 "'$sects[$sx]' " .
2414 "description in '$decl_name'\n";
2415 ++$warnings;
2416 } else {
2417 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002418 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002419 "Excess struct/union/enum/typedef member " .
2420 "'$sects[$sx]' " .
2421 "description in '$decl_name'\n";
2422 ++$warnings;
2423 }
2424 }
2425 }
2426 }
2427}
2428
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002430# Checks the section describing the return value of a function.
2431sub check_return_section {
2432 my $file = shift;
2433 my $declaration_name = shift;
2434 my $return_type = shift;
2435
2436 # Ignore an empty return type (It's a macro)
2437 # Ignore functions with a "void" return type. (But don't ignore "void *")
2438 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2439 return;
2440 }
2441
2442 if (!defined($sections{$section_return}) ||
2443 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002444 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002445 "No description found for return value of " .
2446 "'$declaration_name'\n";
2447 ++$warnings;
2448 }
2449}
2450
2451##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452# takes a function prototype and the name of the current file being
2453# processed and spits out all the details stored in the global
2454# arrays/hashes.
2455sub dump_function($$) {
2456 my $prototype = shift;
2457 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002458 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459
2460 $prototype =~ s/^static +//;
2461 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002462 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 $prototype =~ s/^inline +//;
2464 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002465 $prototype =~ s/^__inline +//;
2466 $prototype =~ s/^__always_inline +//;
2467 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002468 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002469 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002470 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002471 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002472 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002473 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002474 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
2476 # Yes, this truly is vile. We are looking for:
2477 # 1. Return type (may be nothing if we're looking at a macro)
2478 # 2. Function name
2479 # 3. Function parameters.
2480 #
2481 # All the while we have to watch out for function pointer parameters
2482 # (which IIRC is what the two sections are for), C types (these
2483 # regexps don't even start to express all the possibilities), and
2484 # so on.
2485 #
2486 # If you mess with these regexps, it's a good idea to check that
2487 # the following functions' documentation still comes out right:
2488 # - parport_register_device (function pointer parameters)
2489 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002490 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002492 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2493 # This is an object-like macro, it has no return type and no parameter
2494 # list.
2495 # Function-like macros are not allowed to have spaces between
2496 # declaration_name and opening parenthesis (notice the \s+).
2497 $return_type = $1;
2498 $declaration_name = $2;
2499 $noret = 1;
2500 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2502 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2503 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002504 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2506 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2507 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2508 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2509 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2510 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2511 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2512 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002513 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2514 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002515 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2516 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 $return_type = $1;
2518 $declaration_name = $2;
2519 my $args = $3;
2520
2521 create_parameterlist($args, ',', $file);
2522 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002523 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 return;
2525 }
2526
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002527 my $prms = join " ", @parameterlist;
2528 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2529
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002530 # This check emits a lot of warnings at the moment, because many
2531 # functions don't have a 'Return' doc section. So until the number
2532 # of warnings goes sufficiently down, the check is only performed in
2533 # verbose mode.
2534 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002535 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002536 check_return_section($file, $declaration_name, $return_type);
2537 }
2538
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002539 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 'function',
2541 {'function' => $declaration_name,
2542 'module' => $modulename,
2543 'functiontype' => $return_type,
2544 'parameterlist' => \@parameterlist,
2545 'parameterdescs' => \%parameterdescs,
2546 'parametertypes' => \%parametertypes,
2547 'sectionlist' => \@sectionlist,
2548 'sections' => \%sections,
2549 'purpose' => $declaration_purpose
2550 });
2551}
2552
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553sub reset_state {
2554 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 %parameterdescs = ();
2556 %parametertypes = ();
2557 @parameterlist = ();
2558 %sections = ();
2559 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002560 $sectcheck = "";
2561 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002563
Jani Nikula48af6062016-05-26 14:56:05 +03002564 $state = STATE_NORMAL;
2565 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566}
2567
Jason Baron56afb0f2009-04-30 13:29:36 -04002568sub tracepoint_munge($) {
2569 my $file = shift;
2570 my $tracepointname = 0;
2571 my $tracepointargs = 0;
2572
Jason Baron3a9089f2009-12-01 12:18:49 -05002573 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002574 $tracepointname = $1;
2575 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002576 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2577 $tracepointname = $1;
2578 }
2579 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2580 $tracepointname = $2;
2581 }
2582 $tracepointname =~ s/^\s+//; #strip leading whitespace
2583 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002584 $tracepointargs = $1;
2585 }
2586 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002587 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002588 "$prototype\n";
2589 } else {
2590 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2591 }
2592}
2593
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002594sub syscall_munge() {
2595 my $void = 0;
2596
2597 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2598## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2599 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2600 $void = 1;
2601## $prototype = "long sys_$1(void)";
2602 }
2603
2604 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2605 if ($prototype =~ m/long (sys_.*?),/) {
2606 $prototype =~ s/,/\(/;
2607 } elsif ($void) {
2608 $prototype =~ s/\)/\(void\)/;
2609 }
2610
2611 # now delete all of the odd-number commas in $prototype
2612 # so that arg types & arg names don't have a comma between them
2613 my $count = 0;
2614 my $len = length($prototype);
2615 if ($void) {
2616 $len = 0; # skip the for-loop
2617 }
2618 for (my $ix = 0; $ix < $len; $ix++) {
2619 if (substr($prototype, $ix, 1) eq ',') {
2620 $count++;
2621 if ($count % 2 == 1) {
2622 substr($prototype, $ix, 1) = ' ';
2623 }
2624 }
2625 }
2626}
2627
Daniel Vetterb7afa922016-06-01 23:46:24 +02002628sub process_proto_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629 my $x = shift;
2630 my $file = shift;
2631
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002632 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2633
Randy Dunlap890c78c2008-10-25 17:06:43 -07002634 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 # do nothing
2636 }
2637 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002638 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002640
Randy Dunlap890c78c2008-10-25 17:06:43 -07002641 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002642 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2644 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002645 if ($prototype =~ /SYSCALL_DEFINE/) {
2646 syscall_munge();
2647 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002648 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2649 $prototype =~ /DEFINE_SINGLE_EVENT/)
2650 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002651 tracepoint_munge($file);
2652 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002653 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 reset_state();
2655 }
2656}
2657
Daniel Vetterb7afa922016-06-01 23:46:24 +02002658sub process_proto_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 my $x = shift;
2660 my $file = shift;
2661
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2663 $x =~ s@^\s+@@gos; # strip leading spaces
2664 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002665 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2666
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 if ($x =~ /^#/) {
2668 # To distinguish preprocessor directive from regular declaration later.
2669 $x .= ";";
2670 }
2671
2672 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002673 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 $prototype .= $1 . $2;
2675 ($2 eq '{') && $brcount++;
2676 ($2 eq '}') && $brcount--;
2677 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002678 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002680 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 }
2682 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002683 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 $prototype .= $x;
2685 last;
2686 }
2687 }
2688}
2689
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002690# xml_escape: replace <, >, and & in the text stream;
2691#
2692# however, formatting controls that are generated internally/locally in the
2693# kernel-doc script are not escaped here; instead, they begin life like
2694# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2695# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2696# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697sub xml_escape($) {
2698 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002699 if (($output_mode eq "text") || ($output_mode eq "man")) {
2700 return $text;
2701 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 $text =~ s/\&/\\\\\\amp;/g;
2703 $text =~ s/\</\\\\\\lt;/g;
2704 $text =~ s/\>/\\\\\\gt;/g;
2705 return $text;
2706}
2707
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002708# xml_unescape: reverse the effects of xml_escape
2709sub xml_unescape($) {
2710 my $text = shift;
2711 if (($output_mode eq "text") || ($output_mode eq "man")) {
2712 return $text;
2713 }
2714 $text =~ s/\\\\\\amp;/\&/g;
2715 $text =~ s/\\\\\\lt;/</g;
2716 $text =~ s/\\\\\\gt;/>/g;
2717 return $text;
2718}
2719
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002720# convert local escape strings to html
2721# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2722sub local_unescape($) {
2723 my $text = shift;
2724 if (($output_mode eq "text") || ($output_mode eq "man")) {
2725 return $text;
2726 }
2727 $text =~ s/\\\\\\\\lt:/</g;
2728 $text =~ s/\\\\\\\\gt:/>/g;
2729 return $text;
2730}
2731
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002733 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734 my $identifier;
2735 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002736 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002737 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002739 my ($orig_file) = @_;
Jani Nikulab7886de2016-05-28 00:41:50 +03002740 my $leading_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002741
Randy Dunlap2283a112005-07-07 15:39:26 -07002742 if (defined($ENV{'SRCTREE'})) {
Ben Hutchings68f86662015-09-01 23:48:49 +01002743 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002744 }
2745 else {
Ben Hutchings68f86662015-09-01 23:48:49 +01002746 $file = $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002747 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002748 if (defined($source_map{$file})) {
2749 $file = $source_map{$file};
2750 }
2751
2752 if (!open(IN,"<$file")) {
2753 print STDERR "Error: Cannot open file $file\n";
2754 ++$errors;
2755 return;
2756 }
2757
Jani Nikula86ae2e32016-01-21 13:05:22 +02002758 # two passes for -export and -internal
Jani Nikulab6c3f452016-05-29 22:19:35 +03002759 if ($output_selection == OUTPUT_EXPORTED ||
2760 $output_selection == OUTPUT_INTERNAL) {
Jani Nikula86ae2e32016-01-21 13:05:22 +02002761 while (<IN>) {
2762 if (/$export_symbol/o) {
2763 $function_table{$2} = 1;
2764 }
2765 }
2766 seek(IN, 0, 0);
2767 }
2768
Ilya Dryomova9e73142010-02-26 13:05:47 -08002769 $. = 1;
2770
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 $section_counter = 0;
2772 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002773 while (s/\\\s*$//) {
2774 $_ .= <IN>;
2775 }
Jani Nikula48af6062016-05-26 14:56:05 +03002776 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002778 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002779 $in_doc_sect = 0;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002780 $declaration_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 }
Jani Nikula48af6062016-05-26 14:56:05 +03002782 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002784 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 $contents = "";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002786 $new_start_line = $. + 1;
2787
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 if ( $1 eq "" ) {
2789 $section = $section_intro;
2790 } else {
2791 $section = $1;
2792 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002793 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 elsif (/$doc_decl/o) {
2795 $identifier = $1;
2796 if (/\s*([\w\s]+?)\s*-/) {
2797 $identifier = $1;
2798 }
2799
Jani Nikula48af6062016-05-26 14:56:05 +03002800 $state = STATE_FIELD;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002801 # if there's no @param blocks need to set up default section
2802 # here
Jani Nikula2f4ad402016-05-30 11:21:06 +03002803 $contents = "";
2804 $section = $section_default;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002805 $new_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002807 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002808 $descr= $1;
2809 $descr =~ s/^\s*//;
2810 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002811 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002812 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002813 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 } else {
2815 $declaration_purpose = "";
2816 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002817
2818 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002819 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002820 print STDERR $_;
2821 ++$warnings;
2822 }
2823
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 if ($identifier =~ m/^struct/) {
2825 $decl_type = 'struct';
2826 } elsif ($identifier =~ m/^union/) {
2827 $decl_type = 'union';
2828 } elsif ($identifier =~ m/^enum/) {
2829 $decl_type = 'enum';
2830 } elsif ($identifier =~ m/^typedef/) {
2831 $decl_type = 'typedef';
2832 } else {
2833 $decl_type = 'function';
2834 }
2835
2836 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002837 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 }
2839 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002840 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 " - I thought it was a doc line\n";
2842 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002843 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 }
Jani Nikula48af6062016-05-26 14:56:05 +03002845 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Jani Nikulaf624ade2016-05-29 11:35:28 +03002846 if (/$doc_sect/i) { # case insensitive for supported section names
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 $newsection = $1;
2848 $newcontents = $2;
2849
Jani Nikulaf624ade2016-05-29 11:35:28 +03002850 # map the supported section names to the canonical names
2851 if ($newsection =~ m/^description$/i) {
2852 $newsection = $section_default;
2853 } elsif ($newsection =~ m/^context$/i) {
2854 $newsection = $section_context;
2855 } elsif ($newsection =~ m/^returns?$/i) {
2856 $newsection = $section_return;
2857 } elsif ($newsection =~ m/^\@return$/) {
2858 # special: @return is a section, not a param description
2859 $newsection = $section_return;
2860 }
2861
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002862 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002863 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002864 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002865 ++$warnings;
2866 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002867 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 $section = $section_default;
2869 }
2870
Randy Dunlap850622d2006-06-25 05:48:55 -07002871 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002872 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 $contents = $newcontents;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002874 $new_start_line = $.;
Jani Nikula0a726302016-05-28 14:50:20 +03002875 while ((substr($contents, 0, 1) eq " ") ||
2876 substr($contents, 0, 1) eq "\t") {
2877 $contents = substr($contents, 1);
2878 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 if ($contents ne "") {
2880 $contents .= "\n";
2881 }
2882 $section = $newsection;
Jani Nikulab7886de2016-05-28 00:41:50 +03002883 $leading_space = undef;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002885 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002886 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887 $section = $section_default;
2888 $contents = "";
2889 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002890 # look for doc_com + <text> + doc_end:
2891 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002892 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002893 ++$warnings;
2894 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895
2896 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002897 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002899# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 } elsif (/$doc_content/) {
2901 # miguel-style comment kludge, look for blank lines after
2902 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002903 if ($1 eq "") {
2904 if ($section =~ m/^@/ || $section eq $section_context) {
2905 dump_section($file, $section, xml_escape($contents));
2906 $section = $section_default;
2907 $contents = "";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002908 $new_start_line = $.;
Johannes Weiner64231332009-09-17 19:26:53 -07002909 } else {
2910 $contents .= "\n";
2911 }
2912 $in_purpose = 0;
2913 } elsif ($in_purpose == 1) {
2914 # Continued declaration purpose
2915 chomp($declaration_purpose);
2916 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002917 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 } else {
Jani Nikulab7886de2016-05-28 00:41:50 +03002919 my $cont = $1;
2920 if ($section =~ m/^@/ || $section eq $section_context) {
2921 if (!defined $leading_space) {
2922 if ($cont =~ m/^(\s+)/) {
2923 $leading_space = $1;
2924 } else {
2925 $leading_space = "";
2926 }
2927 }
2928
2929 $cont =~ s/^$leading_space//;
2930 }
2931 $contents .= $cont . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 }
2933 } else {
2934 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002935 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 ++$warnings;
2937 }
Jani Nikula48af6062016-05-26 14:56:05 +03002938 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002939 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03002940 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002941 $section = $1;
2942 $contents = $2;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002943 $new_start_line = $.;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002944 if ($contents ne "") {
2945 while ((substr($contents, 0, 1) eq " ") ||
2946 substr($contents, 0, 1) eq "\t") {
2947 $contents = substr($contents, 1);
2948 }
Jani Nikulaa0b96c22016-05-26 22:04:06 +03002949 $contents .= "\n";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002950 }
Jani Nikula48af6062016-05-26 14:56:05 +03002951 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002952 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03002953 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002954 if (($contents ne "") && ($contents ne "\n")) {
2955 dump_section($file, $section, xml_escape($contents));
2956 $section = $section_default;
2957 $contents = "";
2958 }
Jani Nikula48af6062016-05-26 14:56:05 +03002959 $state = STATE_PROTO;
2960 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002961 # Regular text
2962 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03002963 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002964 $contents .= $1 . "\n";
Jani Nikula6450c892016-05-26 22:04:42 +03002965 # nuke leading blank lines
2966 if ($contents =~ /^\s*$/) {
2967 $contents = "";
2968 }
Jani Nikula48af6062016-05-26 14:56:05 +03002969 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
2970 $inline_doc_state = STATE_INLINE_ERROR;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002971 print STDERR "Warning(${file}:$.): ";
2972 print STDERR "Incorrect use of kernel-doc format: $_";
2973 ++$warnings;
2974 }
2975 }
Jani Nikula48af6062016-05-26 14:56:05 +03002976 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
2977 if (/$doc_inline_start/) {
2978 $state = STATE_INLINE;
2979 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002980 } elsif ($decl_type eq 'function') {
Daniel Vetterb7afa922016-06-01 23:46:24 +02002981 process_proto_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 } else {
Daniel Vetterb7afa922016-06-01 23:46:24 +02002983 process_proto_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 }
Jani Nikula48af6062016-05-26 14:56:05 +03002985 } elsif ($state == STATE_DOCBLOCK) {
Daniel Vetterebff7f92016-06-01 23:46:23 +02002986 if (/$doc_end/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002988 dump_doc_section($file, $section, xml_escape($contents));
Jani Nikula2f4ad402016-05-30 11:21:06 +03002989 $section = $section_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 $contents = "";
2991 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 %parameterdescs = ();
2993 %parametertypes = ();
2994 @parameterlist = ();
2995 %sections = ();
2996 @sectionlist = ();
2997 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002998 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 }
3000 elsif (/$doc_content/)
3001 {
3002 if ( $1 eq "" )
3003 {
3004 $contents .= $blankline;
3005 }
3006 else
3007 {
3008 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08003009 }
Randy Dunlap3c308792007-05-08 00:24:39 -07003010 }
3011 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 }
3013 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07003014 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03003015 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08003016 print STDERR " Was looking for '$_'.\n" for keys %function_table;
3017 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 if ($output_mode eq "xml") {
3019 # The template wants at least one RefEntry here; make one.
3020 print "<refentry>\n";
3021 print " <refnamediv>\n";
3022 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003023 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024 print " </refname>\n";
3025 print " <refpurpose>\n";
3026 print " Document generation inconsistency\n";
3027 print " </refpurpose>\n";
3028 print " </refnamediv>\n";
3029 print " <refsect1>\n";
3030 print " <title>\n";
3031 print " Oops\n";
3032 print " </title>\n";
3033 print " <warning>\n";
3034 print " <para>\n";
3035 print " The template for this document tried to insert\n";
3036 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003037 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 print " but none was found.\n";
3039 print " This dummy section is inserted to allow\n";
3040 print " generation to continue.\n";
3041 print " </para>\n";
3042 print " </warning>\n";
3043 print " </refsect1>\n";
3044 print "</refentry>\n";
3045 }
3046 }
3047}
Randy Dunlap8484baa2011-01-05 16:28:43 -08003048
3049
3050$kernelversion = get_kernel_version();
3051
3052# generate a sequence of code that will splice in highlighting information
3053# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02003054for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03003055 my $pattern = $highlights[$k][0];
3056 my $result = $highlights[$k][1];
3057# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
3058 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08003059}
3060
3061# Read the file that maps relative names to absolute names for
3062# separate source and object directories and for shadow trees.
3063if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3064 my ($relname, $absname);
3065 while(<SOURCE_MAP>) {
3066 chop();
3067 ($relname, $absname) = (split())[0..1];
3068 $relname =~ s:^/+::;
3069 $source_map{$relname} = $absname;
3070 }
3071 close(SOURCE_MAP);
3072}
3073
3074foreach (@ARGV) {
3075 chomp;
3076 process_file($_);
3077}
3078if ($verbose && $errors) {
3079 print STDERR "$errors errors\n";
3080}
3081if ($verbose && $warnings) {
3082 print STDERR "$warnings warnings\n";
3083}
3084
3085exit($errors);