blob: ac18eb5ed7767053a730dcd2bb6e5bb722b3b134 [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
Jonathan Corbet8569de62016-06-09 13:35:05 -0600409my $doc_sect = $doc_com .
410 '\s*(\@\w+|description|context|returns?|notes?|examples?)\s*:(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700411my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700412my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Jani Nikula48af6062016-05-26 14:56:05 +0300413my $doc_inline_start = '^\s*/\*\*\s*$';
414my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)';
415my $doc_inline_end = '^\s*\*/\s*$';
Jani Nikula86ae2e32016-01-21 13:05:22 +0200416my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418my %parameterdescs;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200419my %parameterdesc_start_lines;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420my @parameterlist;
421my %sections;
422my @sectionlist;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200423my %section_start_lines;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800424my $sectcheck;
425my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427my $contents = "";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200428my $new_start_line = 0;
Jani Nikulaf624ade2016-05-29 11:35:28 +0300429
430# the canonical section names. see also $doc_sect above.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431my $section_default = "Description"; # default section
432my $section_intro = "Introduction";
433my $section = $section_default;
434my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100435my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
437my $undescribed = "-- undescribed --";
438
439reset_state();
440
441while ($ARGV[0] =~ m/^-(.*)/) {
442 my $cmd = shift @ARGV;
443 if ($cmd eq "-html") {
444 $output_mode = "html";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300445 @highlights = @highlights_html;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200447 } elsif ($cmd eq "-html5") {
448 $output_mode = "html5";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300449 @highlights = @highlights_html5;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200450 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 } elsif ($cmd eq "-man") {
452 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300453 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 $blankline = $blankline_man;
455 } elsif ($cmd eq "-text") {
456 $output_mode = "text";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300457 @highlights = @highlights_text;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 $blankline = $blankline_text;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +0300459 } elsif ($cmd eq "-rst") {
460 $output_mode = "rst";
461 @highlights = @highlights_rst;
462 $blankline = $blankline_rst;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 } elsif ($cmd eq "-docbook") {
464 $output_mode = "xml";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300465 @highlights = @highlights_xml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700467 } elsif ($cmd eq "-list") {
468 $output_mode = "list";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300469 @highlights = @highlights_list;
Johannes Bergeda603f2010-09-11 15:55:22 -0700470 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 } elsif ($cmd eq "-gnome") {
472 $output_mode = "gnome";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300473 @highlights = @highlights_gnome;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 $blankline = $blankline_gnome;
475 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
476 $modulename = shift @ARGV;
477 } elsif ($cmd eq "-function") { # to only output specific functions
Jani Nikulab6c3f452016-05-29 22:19:35 +0300478 $output_selection = OUTPUT_INCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 $function = shift @ARGV;
480 $function_table{$function} = 1;
Jani Nikulab6c3f452016-05-29 22:19:35 +0300481 } elsif ($cmd eq "-nofunction") { # output all except specific functions
482 $output_selection = OUTPUT_EXCLUDE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 $function = shift @ARGV;
484 $function_table{$function} = 1;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200485 } elsif ($cmd eq "-export") { # only exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300486 $output_selection = OUTPUT_EXPORTED;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200487 %function_table = ()
488 } elsif ($cmd eq "-internal") { # only non-exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300489 $output_selection = OUTPUT_INTERNAL;
Jani Nikula86ae2e32016-01-21 13:05:22 +0200490 %function_table = ()
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 } elsif ($cmd eq "-v") {
492 $verbose = 1;
493 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
494 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700495 } elsif ($cmd eq '-no-doc-sections') {
496 $no_doc_sections = 1;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200497 } elsif ($cmd eq '-enable-lineno') {
498 $enable_lineno = 1;
Johannes Berge946c43a2013-11-12 15:11:12 -0800499 } elsif ($cmd eq '-show-not-found') {
500 $show_not_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 }
502}
503
Randy Dunlap8484baa2011-01-05 16:28:43 -0800504# continue execution near EOF;
505
Borislav Petkov53f049f2007-05-08 00:30:54 -0700506# get kernel version from env
507sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700508 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700509
510 if (defined($ENV{'KERNELVERSION'})) {
511 $version = $ENV{'KERNELVERSION'};
512 }
513 return $version;
514}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200516#
517sub print_lineno {
518 my $lineno = shift;
519 if ($enable_lineno && defined($lineno)) {
520 print "#define LINENO " . $lineno . "\n";
521 }
522}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523##
524# dumps section contents to arrays/hashes intended for that purpose.
525#
526sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700527 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 my $name = shift;
529 my $contents = join "\n", @_;
530
Jani Nikula13901ef2016-05-26 08:57:29 +0300531 if ($name =~ m/$type_param/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 $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 "@\.\.\.") {
Randy Dunlapced69092008-12-01 13:14:03 -0800538 $name = "...";
539 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800540 $sectcheck = $sectcheck . $name . " ";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200541 $parameterdesc_start_lines{$name} = $new_start_line;
542 $new_start_line = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 } else {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700544 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Jani Nikula32217762016-05-29 09:40:44 +0300545 print STDERR "${file}:$.: warning: duplicate section name '$name'\n";
546 ++$warnings;
547 $sections{$name} .= $contents;
548 } else {
549 $sections{$name} = $contents;
550 push @sectionlist, $name;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +0200551 $section_start_lines{$name} = $new_start_line;
552 $new_start_line = 0;
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700553 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 }
555}
556
557##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700558# dump DOC: section after checking that it should go out
559#
560sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700561 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700562 my $name = shift;
563 my $contents = join "\n", @_;
564
Johannes Berg4b445952007-10-24 15:08:48 -0700565 if ($no_doc_sections) {
566 return;
567 }
568
Jani Nikulab6c3f452016-05-29 22:19:35 +0300569 if (($output_selection == OUTPUT_ALL) ||
570 ($output_selection == OUTPUT_INCLUDE &&
571 defined($function_table{$name})) ||
572 ($output_selection == OUTPUT_EXCLUDE &&
573 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700574 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700575 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700576 output_blockhead({'sectionlist' => \@sectionlist,
577 'sections' => \%sections,
578 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300579 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700580 }
581}
582
583##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584# output function
585#
586# parameterdescs, a hash.
587# function => "function name"
588# parameterlist => @list of parameters
589# parameterdescs => %parameter descriptions
590# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800591# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800592#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
594sub output_highlight {
595 my $contents = join "\n",@_;
596 my $line;
597
598# DEBUG
599# if (!defined $contents) {
600# use Carp;
601# confess "output_highlight got called with no args?\n";
602# }
603
Dan Luedtke1b40c192012-08-12 10:46:15 +0200604 if ($output_mode eq "html" || $output_mode eq "html5" ||
605 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700606 $contents = local_unescape($contents);
607 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800608 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700609 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700610# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 eval $dohighlight;
612 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700613# print STDERR "contents af:$contents\n";
614
Dan Luedtke1b40c192012-08-12 10:46:15 +0200615# strip whitespaces when generating html5
616 if ($output_mode eq "html5") {
617 $contents =~ s/^\s+//;
618 $contents =~ s/\s+$//;
619 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700621 if (! $output_preformatted) {
622 $line =~ s/^\s*//;
623 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700624 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700625 if (! $output_preformatted) {
626 print $lineprefix, local_unescape($blankline);
627 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700629 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700630 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
631 print "\\&$line";
632 } else {
633 print $lineprefix, $line;
634 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 }
636 print "\n";
637 }
638}
639
Dan Luedtke1b40c192012-08-12 10:46:15 +0200640# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641sub output_section_html(%) {
642 my %args = %{$_[0]};
643 my $section;
644
645 foreach $section (@{$args{'sectionlist'}}) {
646 print "<h3>$section</h3>\n";
647 print "<blockquote>\n";
648 output_highlight($args{'sections'}{$section});
649 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800650 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651}
652
653# output enum in html
654sub output_enum_html(%) {
655 my %args = %{$_[0]};
656 my ($parameter);
657 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700658 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
Randy Dunlapb9d973282009-06-09 08:50:38 -0700660 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 $count = 0;
662 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700663 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 if ($count != $#{$args{'parameterlist'}}) {
665 $count++;
666 print ",\n";
667 }
668 print "<br>";
669 }
670 print "};<br>\n";
671
672 print "<h3>Constants</h3>\n";
673 print "<dl>\n";
674 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700675 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 print "<dd>";
677 output_highlight($args{'parameterdescs'}{$parameter});
678 }
679 print "</dl>\n";
680 output_section_html(@_);
681 print "<hr>\n";
682}
683
Randy Dunlapd28bee02006-02-01 03:06:57 -0800684# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685sub output_typedef_html(%) {
686 my %args = %{$_[0]};
687 my ($parameter);
688 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700689 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Randy Dunlapb9d973282009-06-09 08:50:38 -0700691 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 output_section_html(@_);
693 print "<hr>\n";
694}
695
696# output struct in html
697sub output_struct_html(%) {
698 my %args = %{$_[0]};
699 my ($parameter);
700
Randy Dunlapb9d973282009-06-09 08:50:38 -0700701 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
702 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 foreach $parameter (@{$args{'parameterlist'}}) {
704 if ($parameter =~ /^#/) {
705 print "$parameter<br>\n";
706 next;
707 }
708 my $parameter_name = $parameter;
709 $parameter_name =~ s/\[.*//;
710
Randy Dunlap3c308792007-05-08 00:24:39 -0700711 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 $type = $args{'parametertypes'}{$parameter};
713 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
714 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700715 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700717 # bitfield
718 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700720 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 }
722 }
723 print "};<br>\n";
724
725 print "<h3>Members</h3>\n";
726 print "<dl>\n";
727 foreach $parameter (@{$args{'parameterlist'}}) {
728 ($parameter =~ /^#/) && next;
729
730 my $parameter_name = $parameter;
731 $parameter_name =~ s/\[.*//;
732
Randy Dunlap3c308792007-05-08 00:24:39 -0700733 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700734 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 print "<dd>";
736 output_highlight($args{'parameterdescs'}{$parameter_name});
737 }
738 print "</dl>\n";
739 output_section_html(@_);
740 print "<hr>\n";
741}
742
743# output function in html
744sub output_function_html(%) {
745 my %args = %{$_[0]};
746 my ($parameter, $section);
747 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748
Randy Dunlapb9d973282009-06-09 08:50:38 -0700749 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
750 print "<i>" . $args{'functiontype'} . "</i>\n";
751 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 print "(";
753 $count = 0;
754 foreach $parameter (@{$args{'parameterlist'}}) {
755 $type = $args{'parametertypes'}{$parameter};
756 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
757 # pointer-to-function
758 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
759 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700760 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761 }
762 if ($count != $#{$args{'parameterlist'}}) {
763 $count++;
764 print ",\n";
765 }
766 }
767 print ")\n";
768
769 print "<h3>Arguments</h3>\n";
770 print "<dl>\n";
771 foreach $parameter (@{$args{'parameterlist'}}) {
772 my $parameter_name = $parameter;
773 $parameter_name =~ s/\[.*//;
774
Randy Dunlap3c308792007-05-08 00:24:39 -0700775 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700776 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 print "<dd>";
778 output_highlight($args{'parameterdescs'}{$parameter_name});
779 }
780 print "</dl>\n";
781 output_section_html(@_);
782 print "<hr>\n";
783}
784
Johannes Bergb112e0f2007-10-24 15:08:48 -0700785# output DOC: block header in html
786sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 my %args = %{$_[0]};
788 my ($parameter, $section);
789 my $count;
790
791 foreach $section (@{$args{'sectionlist'}}) {
792 print "<h3>$section</h3>\n";
793 print "<ul>\n";
794 output_highlight($args{'sections'}{$section});
795 print "</ul>\n";
796 }
797 print "<hr>\n";
798}
799
Dan Luedtke1b40c192012-08-12 10:46:15 +0200800# output sections in html5
801sub output_section_html5(%) {
802 my %args = %{$_[0]};
803 my $section;
804
805 foreach $section (@{$args{'sectionlist'}}) {
806 print "<section>\n";
807 print "<h1>$section</h1>\n";
808 print "<p>\n";
809 output_highlight($args{'sections'}{$section});
810 print "</p>\n";
811 print "</section>\n";
812 }
813}
814
815# output enum in html5
816sub output_enum_html5(%) {
817 my %args = %{$_[0]};
818 my ($parameter);
819 my $count;
820 my $html5id;
821
822 $html5id = $args{'enum'};
823 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
824 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
825 print "<h1>enum " . $args{'enum'} . "</h1>\n";
826 print "<ol class=\"code\">\n";
827 print "<li>";
828 print "<span class=\"keyword\">enum</span> ";
829 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
830 print "</li>\n";
831 $count = 0;
832 foreach $parameter (@{$args{'parameterlist'}}) {
833 print "<li class=\"indent\">";
834 print "<span class=\"param\">" . $parameter . "</span>";
835 if ($count != $#{$args{'parameterlist'}}) {
836 $count++;
837 print ",";
838 }
839 print "</li>\n";
840 }
841 print "<li>};</li>\n";
842 print "</ol>\n";
843
844 print "<section>\n";
845 print "<h1>Constants</h1>\n";
846 print "<dl>\n";
847 foreach $parameter (@{$args{'parameterlist'}}) {
848 print "<dt>" . $parameter . "</dt>\n";
849 print "<dd>";
850 output_highlight($args{'parameterdescs'}{$parameter});
851 print "</dd>\n";
852 }
853 print "</dl>\n";
854 print "</section>\n";
855 output_section_html5(@_);
856 print "</article>\n";
857}
858
859# output typedef in html5
860sub output_typedef_html5(%) {
861 my %args = %{$_[0]};
862 my ($parameter);
863 my $count;
864 my $html5id;
865
866 $html5id = $args{'typedef'};
867 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
868 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
869 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
870
871 print "<ol class=\"code\">\n";
872 print "<li>";
873 print "<span class=\"keyword\">typedef</span> ";
874 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
875 print "</li>\n";
876 print "</ol>\n";
877 output_section_html5(@_);
878 print "</article>\n";
879}
880
881# output struct in html5
882sub output_struct_html5(%) {
883 my %args = %{$_[0]};
884 my ($parameter);
885 my $html5id;
886
887 $html5id = $args{'struct'};
888 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
889 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
890 print "<hgroup>\n";
891 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
892 print "<h2>". $args{'purpose'} . "</h2>\n";
893 print "</hgroup>\n";
894 print "<ol class=\"code\">\n";
895 print "<li>";
896 print "<span class=\"type\">" . $args{'type'} . "</span> ";
897 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
898 print "</li>\n";
899 foreach $parameter (@{$args{'parameterlist'}}) {
900 print "<li class=\"indent\">";
901 if ($parameter =~ /^#/) {
902 print "<span class=\"param\">" . $parameter ."</span>\n";
903 print "</li>\n";
904 next;
905 }
906 my $parameter_name = $parameter;
907 $parameter_name =~ s/\[.*//;
908
909 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
910 $type = $args{'parametertypes'}{$parameter};
911 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
912 # pointer-to-function
913 print "<span class=\"type\">$1</span> ";
914 print "<span class=\"param\">$parameter</span>";
915 print "<span class=\"type\">)</span> ";
916 print "(<span class=\"args\">$2</span>);";
917 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
918 # bitfield
919 print "<span class=\"type\">$1</span> ";
920 print "<span class=\"param\">$parameter</span>";
921 print "<span class=\"bits\">$2</span>;";
922 } else {
923 print "<span class=\"type\">$type</span> ";
924 print "<span class=\"param\">$parameter</span>;";
925 }
926 print "</li>\n";
927 }
928 print "<li>};</li>\n";
929 print "</ol>\n";
930
931 print "<section>\n";
932 print "<h1>Members</h1>\n";
933 print "<dl>\n";
934 foreach $parameter (@{$args{'parameterlist'}}) {
935 ($parameter =~ /^#/) && next;
936
937 my $parameter_name = $parameter;
938 $parameter_name =~ s/\[.*//;
939
940 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
941 print "<dt>" . $parameter . "</dt>\n";
942 print "<dd>";
943 output_highlight($args{'parameterdescs'}{$parameter_name});
944 print "</dd>\n";
945 }
946 print "</dl>\n";
947 print "</section>\n";
948 output_section_html5(@_);
949 print "</article>\n";
950}
951
952# output function in html5
953sub output_function_html5(%) {
954 my %args = %{$_[0]};
955 my ($parameter, $section);
956 my $count;
957 my $html5id;
958
959 $html5id = $args{'function'};
960 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
961 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
962 print "<hgroup>\n";
963 print "<h1>" . $args{'function'} . "</h1>";
964 print "<h2>" . $args{'purpose'} . "</h2>\n";
965 print "</hgroup>\n";
966 print "<ol class=\"code\">\n";
967 print "<li>";
968 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
969 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
970 print "</li>";
971 $count = 0;
972 foreach $parameter (@{$args{'parameterlist'}}) {
973 print "<li class=\"indent\">";
974 $type = $args{'parametertypes'}{$parameter};
975 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
976 # pointer-to-function
977 print "<span class=\"type\">$1</span> ";
978 print "<span class=\"param\">$parameter</span>";
979 print "<span class=\"type\">)</span> ";
980 print "(<span class=\"args\">$2</span>)";
981 } else {
982 print "<span class=\"type\">$type</span> ";
983 print "<span class=\"param\">$parameter</span>";
984 }
985 if ($count != $#{$args{'parameterlist'}}) {
986 $count++;
987 print ",";
988 }
989 print "</li>\n";
990 }
991 print "<li>)</li>\n";
992 print "</ol>\n";
993
994 print "<section>\n";
995 print "<h1>Arguments</h1>\n";
996 print "<p>\n";
997 print "<dl>\n";
998 foreach $parameter (@{$args{'parameterlist'}}) {
999 my $parameter_name = $parameter;
1000 $parameter_name =~ s/\[.*//;
1001
1002 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1003 print "<dt>" . $parameter . "</dt>\n";
1004 print "<dd>";
1005 output_highlight($args{'parameterdescs'}{$parameter_name});
1006 print "</dd>\n";
1007 }
1008 print "</dl>\n";
1009 print "</section>\n";
1010 output_section_html5(@_);
1011 print "</article>\n";
1012}
1013
1014# output DOC: block header in html5
1015sub output_blockhead_html5(%) {
1016 my %args = %{$_[0]};
1017 my ($parameter, $section);
1018 my $count;
1019 my $html5id;
1020
1021 foreach $section (@{$args{'sectionlist'}}) {
1022 $html5id = $section;
1023 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1024 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1025 print "<h1>$section</h1>\n";
1026 print "<p>\n";
1027 output_highlight($args{'sections'}{$section});
1028 print "</p>\n";
1029 }
1030 print "</article>\n";
1031}
1032
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033sub output_section_xml(%) {
1034 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001035 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 # print out each section
1037 $lineprefix=" ";
1038 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001039 print "<refsect1>\n";
1040 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001042 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001043 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001044 } else {
1045 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 }
1047 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001048 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001050 print "</programlisting></informalexample>\n";
1051 } else {
1052 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001054 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 }
1056}
1057
1058# output function in XML DocBook
1059sub output_function_xml(%) {
1060 my %args = %{$_[0]};
1061 my ($parameter, $section);
1062 my $count;
1063 my $id;
1064
Randy Dunlapb9d973282009-06-09 08:50:38 -07001065 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 $id =~ s/[^A-Za-z0-9]/-/g;
1067
Pavel Pisa5449bc92007-02-10 01:45:37 -08001068 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001069 print "<refentryinfo>\n";
1070 print " <title>LINUX</title>\n";
1071 print " <productname>Kernel Hackers Manual</productname>\n";
1072 print " <date>$man_date</date>\n";
1073 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001075 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001076 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001077 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 print "</refmeta>\n";
1079 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001080 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 print " <refpurpose>\n";
1082 print " ";
1083 output_highlight ($args{'purpose'});
1084 print " </refpurpose>\n";
1085 print "</refnamediv>\n";
1086
1087 print "<refsynopsisdiv>\n";
1088 print " <title>Synopsis</title>\n";
1089 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001090 print " <funcdef>" . $args{'functiontype'} . " ";
1091 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093 $count = 0;
1094 if ($#{$args{'parameterlist'}} >= 0) {
1095 foreach $parameter (@{$args{'parameterlist'}}) {
1096 $type = $args{'parametertypes'}{$parameter};
1097 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1098 # pointer-to-function
1099 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1100 print " <funcparams>$2</funcparams></paramdef>\n";
1101 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001102 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103 print " <parameter>$parameter</parameter></paramdef>\n";
1104 }
1105 }
1106 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001107 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 }
1109 print " </funcprototype></funcsynopsis>\n";
1110 print "</refsynopsisdiv>\n";
1111
1112 # print parameters
1113 print "<refsect1>\n <title>Arguments</title>\n";
1114 if ($#{$args{'parameterlist'}} >= 0) {
1115 print " <variablelist>\n";
1116 foreach $parameter (@{$args{'parameterlist'}}) {
1117 my $parameter_name = $parameter;
1118 $parameter_name =~ s/\[.*//;
1119
1120 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1121 print " <listitem>\n <para>\n";
1122 $lineprefix=" ";
1123 output_highlight($args{'parameterdescs'}{$parameter_name});
1124 print " </para>\n </listitem>\n </varlistentry>\n";
1125 }
1126 print " </variablelist>\n";
1127 } else {
1128 print " <para>\n None\n </para>\n";
1129 }
1130 print "</refsect1>\n";
1131
1132 output_section_xml(@_);
1133 print "</refentry>\n\n";
1134}
1135
1136# output struct in XML DocBook
1137sub output_struct_xml(%) {
1138 my %args = %{$_[0]};
1139 my ($parameter, $section);
1140 my $id;
1141
Randy Dunlapb9d973282009-06-09 08:50:38 -07001142 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 $id =~ s/[^A-Za-z0-9]/-/g;
1144
Pavel Pisa5449bc92007-02-10 01:45:37 -08001145 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001146 print "<refentryinfo>\n";
1147 print " <title>LINUX</title>\n";
1148 print " <productname>Kernel Hackers Manual</productname>\n";
1149 print " <date>$man_date</date>\n";
1150 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001152 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001153 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001154 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 print "</refmeta>\n";
1156 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001157 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 print " <refpurpose>\n";
1159 print " ";
1160 output_highlight ($args{'purpose'});
1161 print " </refpurpose>\n";
1162 print "</refnamediv>\n";
1163
1164 print "<refsynopsisdiv>\n";
1165 print " <title>Synopsis</title>\n";
1166 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001167 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 foreach $parameter (@{$args{'parameterlist'}}) {
1169 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001170 my $prm = $parameter;
1171 # convert data read & converted thru xml_escape() into &xyz; format:
1172 # This allows us to have #define macros interspersed in a struct.
1173 $prm =~ s/\\\\\\/\&/g;
1174 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 next;
1176 }
1177
1178 my $parameter_name = $parameter;
1179 $parameter_name =~ s/\[.*//;
1180
1181 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001182 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 $type = $args{'parametertypes'}{$parameter};
1184 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1185 # pointer-to-function
1186 print " $1 $parameter) ($2);\n";
1187 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001188 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 print " $1 $parameter$2;\n";
1190 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001191 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 }
1193 }
1194 print "};";
1195 print " </programlisting>\n";
1196 print "</refsynopsisdiv>\n";
1197
1198 print " <refsect1>\n";
1199 print " <title>Members</title>\n";
1200
Randy Dunlap39f00c02008-09-22 13:57:44 -07001201 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 print " <variablelist>\n";
1203 foreach $parameter (@{$args{'parameterlist'}}) {
1204 ($parameter =~ /^#/) && next;
1205
1206 my $parameter_name = $parameter;
1207 $parameter_name =~ s/\[.*//;
1208
1209 defined($args{'parameterdescs'}{$parameter_name}) || next;
1210 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1211 print " <varlistentry>";
1212 print " <term>$parameter</term>\n";
1213 print " <listitem><para>\n";
1214 output_highlight($args{'parameterdescs'}{$parameter_name});
1215 print " </para></listitem>\n";
1216 print " </varlistentry>\n";
1217 }
1218 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001219 } else {
1220 print " <para>\n None\n </para>\n";
1221 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 print " </refsect1>\n";
1223
1224 output_section_xml(@_);
1225
1226 print "</refentry>\n\n";
1227}
1228
1229# output enum in XML DocBook
1230sub output_enum_xml(%) {
1231 my %args = %{$_[0]};
1232 my ($parameter, $section);
1233 my $count;
1234 my $id;
1235
Randy Dunlapb9d973282009-06-09 08:50:38 -07001236 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 $id =~ s/[^A-Za-z0-9]/-/g;
1238
Pavel Pisa5449bc92007-02-10 01:45:37 -08001239 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001240 print "<refentryinfo>\n";
1241 print " <title>LINUX</title>\n";
1242 print " <productname>Kernel Hackers Manual</productname>\n";
1243 print " <date>$man_date</date>\n";
1244 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001246 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001247 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001248 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 print "</refmeta>\n";
1250 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001251 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 print " <refpurpose>\n";
1253 print " ";
1254 output_highlight ($args{'purpose'});
1255 print " </refpurpose>\n";
1256 print "</refnamediv>\n";
1257
1258 print "<refsynopsisdiv>\n";
1259 print " <title>Synopsis</title>\n";
1260 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001261 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 $count = 0;
1263 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001264 print " $parameter";
1265 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 $count++;
1267 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001268 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 print "\n";
1270 }
1271 print "};";
1272 print " </programlisting>\n";
1273 print "</refsynopsisdiv>\n";
1274
1275 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001276 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 print " <variablelist>\n";
1278 foreach $parameter (@{$args{'parameterlist'}}) {
1279 my $parameter_name = $parameter;
1280 $parameter_name =~ s/\[.*//;
1281
1282 print " <varlistentry>";
1283 print " <term>$parameter</term>\n";
1284 print " <listitem><para>\n";
1285 output_highlight($args{'parameterdescs'}{$parameter_name});
1286 print " </para></listitem>\n";
1287 print " </varlistentry>\n";
1288 }
1289 print " </variablelist>\n";
1290 print "</refsect1>\n";
1291
1292 output_section_xml(@_);
1293
1294 print "</refentry>\n\n";
1295}
1296
1297# output typedef in XML DocBook
1298sub output_typedef_xml(%) {
1299 my %args = %{$_[0]};
1300 my ($parameter, $section);
1301 my $id;
1302
Randy Dunlapb9d973282009-06-09 08:50:38 -07001303 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 $id =~ s/[^A-Za-z0-9]/-/g;
1305
Pavel Pisa5449bc92007-02-10 01:45:37 -08001306 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001307 print "<refentryinfo>\n";
1308 print " <title>LINUX</title>\n";
1309 print " <productname>Kernel Hackers Manual</productname>\n";
1310 print " <date>$man_date</date>\n";
1311 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001313 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001314 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 print "</refmeta>\n";
1316 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001317 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 print " <refpurpose>\n";
1319 print " ";
1320 output_highlight ($args{'purpose'});
1321 print " </refpurpose>\n";
1322 print "</refnamediv>\n";
1323
1324 print "<refsynopsisdiv>\n";
1325 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001326 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 print "</refsynopsisdiv>\n";
1328
1329 output_section_xml(@_);
1330
1331 print "</refentry>\n\n";
1332}
1333
1334# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001335sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 my %args = %{$_[0]};
1337 my ($parameter, $section);
1338 my $count;
1339
1340 my $id = $args{'module'};
1341 $id =~ s/[^A-Za-z0-9]/-/g;
1342
1343 # print out each section
1344 $lineprefix=" ";
1345 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001346 if (!$args{'content-only'}) {
1347 print "<refsect1>\n <title>$section</title>\n";
1348 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 if ($section =~ m/EXAMPLE/i) {
1350 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001351 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001352 } else {
1353 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 }
1355 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001356 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 if ($section =~ m/EXAMPLE/i) {
1358 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001359 } else {
1360 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001362 if (!$args{'content-only'}) {
1363 print "\n</refsect1>\n";
1364 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 }
1366
1367 print "\n\n";
1368}
1369
1370# output in XML DocBook
1371sub output_function_gnome {
1372 my %args = %{$_[0]};
1373 my ($parameter, $section);
1374 my $count;
1375 my $id;
1376
Randy Dunlapb9d973282009-06-09 08:50:38 -07001377 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 $id =~ s/[^A-Za-z0-9]/-/g;
1379
1380 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001381 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382
1383 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001384 print " <funcdef>" . $args{'functiontype'} . " ";
1385 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386 print "</function></funcdef>\n";
1387
1388 $count = 0;
1389 if ($#{$args{'parameterlist'}} >= 0) {
1390 foreach $parameter (@{$args{'parameterlist'}}) {
1391 $type = $args{'parametertypes'}{$parameter};
1392 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1393 # pointer-to-function
1394 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1395 print " <funcparams>$2</funcparams></paramdef>\n";
1396 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001397 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 print " <parameter>$parameter</parameter></paramdef>\n";
1399 }
1400 }
1401 } else {
1402 print " <void>\n";
1403 }
1404 print " </funcsynopsis>\n";
1405 if ($#{$args{'parameterlist'}} >= 0) {
1406 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1407 print "<tgroup cols=\"2\">\n";
1408 print "<colspec colwidth=\"2*\">\n";
1409 print "<colspec colwidth=\"8*\">\n";
1410 print "<tbody>\n";
1411 foreach $parameter (@{$args{'parameterlist'}}) {
1412 my $parameter_name = $parameter;
1413 $parameter_name =~ s/\[.*//;
1414
1415 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1416 print " <entry>\n";
1417 $lineprefix=" ";
1418 output_highlight($args{'parameterdescs'}{$parameter_name});
1419 print " </entry></row>\n";
1420 }
1421 print " </tbody></tgroup></informaltable>\n";
1422 } else {
1423 print " <para>\n None\n </para>\n";
1424 }
1425
1426 # print out each section
1427 $lineprefix=" ";
1428 foreach $section (@{$args{'sectionlist'}}) {
1429 print "<simplesect>\n <title>$section</title>\n";
1430 if ($section =~ m/EXAMPLE/i) {
1431 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001432 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 } else {
1434 }
1435 print "<para>\n";
1436 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001437 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 print "</para>\n";
1439 if ($section =~ m/EXAMPLE/i) {
1440 print "</programlisting></example>\n";
1441 } else {
1442 }
1443 print " </simplesect>\n";
1444 }
1445
1446 print "</sect2>\n\n";
1447}
1448
1449##
1450# output function in man
1451sub output_function_man(%) {
1452 my %args = %{$_[0]};
1453 my ($parameter, $section);
1454 my $count;
1455
1456 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1457
1458 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001459 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
1461 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001462 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001463 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001464 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001465 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 $count = 0;
1468 my $parenth = "(";
1469 my $post = ",";
1470 foreach my $parameter (@{$args{'parameterlist'}}) {
1471 if ($count == $#{$args{'parameterlist'}}) {
1472 $post = ");";
1473 }
1474 $type = $args{'parametertypes'}{$parameter};
1475 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1476 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001477 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 } else {
1479 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001480 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 }
1482 $count++;
1483 $parenth = "";
1484 }
1485
1486 print ".SH ARGUMENTS\n";
1487 foreach $parameter (@{$args{'parameterlist'}}) {
1488 my $parameter_name = $parameter;
1489 $parameter_name =~ s/\[.*//;
1490
Randy Dunlapb9d973282009-06-09 08:50:38 -07001491 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 output_highlight($args{'parameterdescs'}{$parameter_name});
1493 }
1494 foreach $section (@{$args{'sectionlist'}}) {
1495 print ".SH \"", uc $section, "\"\n";
1496 output_highlight($args{'sections'}{$section});
1497 }
1498}
1499
1500##
1501# output enum in man
1502sub output_enum_man(%) {
1503 my %args = %{$_[0]};
1504 my ($parameter, $section);
1505 my $count;
1506
1507 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1508
1509 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001510 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511
1512 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001513 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 $count = 0;
1515 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001516 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 if ($count == $#{$args{'parameterlist'}}) {
1518 print "\n};\n";
1519 last;
1520 }
1521 else {
1522 print ", \n.br\n";
1523 }
1524 $count++;
1525 }
1526
1527 print ".SH Constants\n";
1528 foreach $parameter (@{$args{'parameterlist'}}) {
1529 my $parameter_name = $parameter;
1530 $parameter_name =~ s/\[.*//;
1531
Randy Dunlapb9d973282009-06-09 08:50:38 -07001532 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 output_highlight($args{'parameterdescs'}{$parameter_name});
1534 }
1535 foreach $section (@{$args{'sectionlist'}}) {
1536 print ".SH \"$section\"\n";
1537 output_highlight($args{'sections'}{$section});
1538 }
1539}
1540
1541##
1542# output struct in man
1543sub output_struct_man(%) {
1544 my %args = %{$_[0]};
1545 my ($parameter, $section);
1546
Randy Dunlapb9d973282009-06-09 08:50:38 -07001547 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
1549 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001550 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
1552 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001553 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
1555 foreach my $parameter (@{$args{'parameterlist'}}) {
1556 if ($parameter =~ /^#/) {
1557 print ".BI \"$parameter\"\n.br\n";
1558 next;
1559 }
1560 my $parameter_name = $parameter;
1561 $parameter_name =~ s/\[.*//;
1562
Randy Dunlap3c308792007-05-08 00:24:39 -07001563 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 $type = $args{'parametertypes'}{$parameter};
1565 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1566 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001567 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001569 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001570 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 } else {
1572 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001573 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 }
1575 print "\n.br\n";
1576 }
1577 print "};\n.br\n";
1578
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001579 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 foreach $parameter (@{$args{'parameterlist'}}) {
1581 ($parameter =~ /^#/) && next;
1582
1583 my $parameter_name = $parameter;
1584 $parameter_name =~ s/\[.*//;
1585
Randy Dunlap3c308792007-05-08 00:24:39 -07001586 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001587 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 output_highlight($args{'parameterdescs'}{$parameter_name});
1589 }
1590 foreach $section (@{$args{'sectionlist'}}) {
1591 print ".SH \"$section\"\n";
1592 output_highlight($args{'sections'}{$section});
1593 }
1594}
1595
1596##
1597# output typedef in man
1598sub output_typedef_man(%) {
1599 my %args = %{$_[0]};
1600 my ($parameter, $section);
1601
1602 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1603
1604 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001605 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606
1607 foreach $section (@{$args{'sectionlist'}}) {
1608 print ".SH \"$section\"\n";
1609 output_highlight($args{'sections'}{$section});
1610 }
1611}
1612
Johannes Bergb112e0f2007-10-24 15:08:48 -07001613sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 my %args = %{$_[0]};
1615 my ($parameter, $section);
1616 my $count;
1617
1618 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1619
1620 foreach $section (@{$args{'sectionlist'}}) {
1621 print ".SH \"$section\"\n";
1622 output_highlight($args{'sections'}{$section});
1623 }
1624}
1625
1626##
1627# output in text
1628sub output_function_text(%) {
1629 my %args = %{$_[0]};
1630 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001631 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632
Randy Dunlapf47634b2006-07-01 04:36:36 -07001633 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001634 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001635
1636 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001637 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001638 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001639 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001640 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001641 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001643
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 my $count = 0;
1645 foreach my $parameter (@{$args{'parameterlist'}}) {
1646 $type = $args{'parametertypes'}{$parameter};
1647 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1648 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001649 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001651 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 }
1653 if ($count != $#{$args{'parameterlist'}}) {
1654 $count++;
1655 print ",\n";
1656 print " " x length($start);
1657 } else {
1658 print ");\n\n";
1659 }
1660 }
1661
1662 print "Arguments:\n\n";
1663 foreach $parameter (@{$args{'parameterlist'}}) {
1664 my $parameter_name = $parameter;
1665 $parameter_name =~ s/\[.*//;
1666
Randy Dunlapb9d973282009-06-09 08:50:38 -07001667 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 }
1669 output_section_text(@_);
1670}
1671
1672#output sections in text
1673sub output_section_text(%) {
1674 my %args = %{$_[0]};
1675 my $section;
1676
1677 print "\n";
1678 foreach $section (@{$args{'sectionlist'}}) {
1679 print "$section:\n\n";
1680 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001681 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 print "\n\n";
1683}
1684
1685# output enum in text
1686sub output_enum_text(%) {
1687 my %args = %{$_[0]};
1688 my ($parameter);
1689 my $count;
1690 print "Enum:\n\n";
1691
Randy Dunlapb9d973282009-06-09 08:50:38 -07001692 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1693 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 $count = 0;
1695 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001696 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 if ($count != $#{$args{'parameterlist'}}) {
1698 $count++;
1699 print ",";
1700 }
1701 print "\n";
1702 }
1703 print "};\n\n";
1704
1705 print "Constants:\n\n";
1706 foreach $parameter (@{$args{'parameterlist'}}) {
1707 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001708 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 }
1710
1711 output_section_text(@_);
1712}
1713
1714# output typedef in text
1715sub output_typedef_text(%) {
1716 my %args = %{$_[0]};
1717 my ($parameter);
1718 my $count;
1719 print "Typedef:\n\n";
1720
Randy Dunlapb9d973282009-06-09 08:50:38 -07001721 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 output_section_text(@_);
1723}
1724
1725# output struct as text
1726sub output_struct_text(%) {
1727 my %args = %{$_[0]};
1728 my ($parameter);
1729
Randy Dunlapb9d973282009-06-09 08:50:38 -07001730 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1731 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 foreach $parameter (@{$args{'parameterlist'}}) {
1733 if ($parameter =~ /^#/) {
1734 print "$parameter\n";
1735 next;
1736 }
1737
1738 my $parameter_name = $parameter;
1739 $parameter_name =~ s/\[.*//;
1740
Randy Dunlap3c308792007-05-08 00:24:39 -07001741 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 $type = $args{'parametertypes'}{$parameter};
1743 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1744 # pointer-to-function
1745 print "\t$1 $parameter) ($2);\n";
1746 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001747 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 print "\t$1 $parameter$2;\n";
1749 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001750 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 }
1752 }
1753 print "};\n\n";
1754
1755 print "Members:\n\n";
1756 foreach $parameter (@{$args{'parameterlist'}}) {
1757 ($parameter =~ /^#/) && next;
1758
1759 my $parameter_name = $parameter;
1760 $parameter_name =~ s/\[.*//;
1761
Randy Dunlap3c308792007-05-08 00:24:39 -07001762 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001763 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001764 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 }
1766 print "\n";
1767 output_section_text(@_);
1768}
1769
Johannes Bergb112e0f2007-10-24 15:08:48 -07001770sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 my %args = %{$_[0]};
1772 my ($parameter, $section);
1773
1774 foreach $section (@{$args{'sectionlist'}}) {
1775 print " $section:\n";
1776 print " -> ";
1777 output_highlight($args{'sections'}{$section});
1778 }
1779}
1780
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001781##
1782# output in restructured text
1783#
1784
1785#
1786# This could use some work; it's used to output the DOC: sections, and
1787# starts by putting out the name of the doc section itself, but that tends
1788# to duplicate a header already in the template file.
1789#
1790sub output_blockhead_rst(%) {
1791 my %args = %{$_[0]};
1792 my ($parameter, $section);
1793
1794 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001795 if ($output_selection != OUTPUT_INCLUDE) {
1796 print "**$section**\n\n";
1797 }
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001798 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001799 output_highlight_rst($args{'sections'}{$section});
1800 print "\n";
1801 }
1802}
1803
1804sub output_highlight_rst {
1805 my $contents = join "\n",@_;
1806 my $line;
1807
1808 # undo the evil effects of xml_escape() earlier
1809 $contents = xml_unescape($contents);
1810
1811 eval $dohighlight;
1812 die $@ if $@;
1813
1814 foreach $line (split "\n", $contents) {
Jani Nikula830066a2016-05-26 22:04:33 +03001815 print $lineprefix . $line . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001816 }
1817}
1818
1819sub output_function_rst(%) {
1820 my %args = %{$_[0]};
1821 my ($parameter, $section);
Jani Nikulac099ff62016-05-26 17:18:17 +03001822 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001823 my $start;
1824
1825 print ".. c:function:: ";
1826 if ($args{'functiontype'} ne "") {
1827 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1828 } else {
1829 $start = $args{'function'} . " (";
1830 }
1831 print $start;
1832
1833 my $count = 0;
1834 foreach my $parameter (@{$args{'parameterlist'}}) {
1835 if ($count ne 0) {
1836 print ", ";
1837 }
1838 $count++;
1839 $type = $args{'parametertypes'}{$parameter};
1840 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1841 # pointer-to-function
1842 print $1 . $parameter . ") (" . $2;
1843 } else {
1844 print $type . " " . $parameter;
1845 }
1846 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001847 print ")\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001848 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001849 $lineprefix = " ";
1850 output_highlight_rst($args{'purpose'});
1851 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001852
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001853 print "**Parameters**\n\n";
1854 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001855 foreach $parameter (@{$args{'parameterlist'}}) {
1856 my $parameter_name = $parameter;
1857 #$parameter_name =~ s/\[.*//;
1858 $type = $args{'parametertypes'}{$parameter};
1859
1860 if ($type ne "") {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001861 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001862 } else {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001863 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001864 }
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001865
1866 print_lineno($parameterdesc_start_lines{$parameter_name});
1867
Jani Nikula5e64fa92016-05-19 20:32:48 +03001868 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1869 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001870 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001871 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001872 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001873 }
1874 print "\n";
1875 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001876
1877 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001878 output_section_rst(@_);
1879}
1880
1881sub output_section_rst(%) {
1882 my %args = %{$_[0]};
1883 my $section;
1884 my $oldprefix = $lineprefix;
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001885 $lineprefix = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001886
1887 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001888 print "**$section**\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001889 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001890 output_highlight_rst($args{'sections'}{$section});
1891 print "\n";
1892 }
1893 print "\n";
1894 $lineprefix = $oldprefix;
1895}
1896
1897sub output_enum_rst(%) {
1898 my %args = %{$_[0]};
1899 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001900 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001901 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001902 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001903
1904 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001905 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001906 $lineprefix = " ";
1907 output_highlight_rst($args{'purpose'});
1908 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001909
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001910 print "**Constants**\n\n";
1911 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001912 foreach $parameter (@{$args{'parameterlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001913 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001914 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1915 output_highlight_rst($args{'parameterdescs'}{$parameter});
1916 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001917 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001918 }
1919 print "\n";
1920 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001921
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001922 $lineprefix = $oldprefix;
1923 output_section_rst(@_);
1924}
1925
1926sub output_typedef_rst(%) {
1927 my %args = %{$_[0]};
1928 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001929 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001930 my $name = "typedef " . $args{'typedef'};
1931
Jani Nikula62850972016-05-12 16:15:38 +03001932 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001933 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001934 $lineprefix = " ";
1935 output_highlight_rst($args{'purpose'});
1936 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001937
Jani Nikulac099ff62016-05-26 17:18:17 +03001938 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001939 output_section_rst(@_);
1940}
1941
1942sub output_struct_rst(%) {
1943 my %args = %{$_[0]};
1944 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001945 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001946 my $name = $args{'type'} . " " . $args{'struct'};
1947
Jani Nikula62850972016-05-12 16:15:38 +03001948 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001949 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001950 $lineprefix = " ";
1951 output_highlight_rst($args{'purpose'});
1952 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001953
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001954 print "**Definition**\n\n";
1955 print "::\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001956 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1957 foreach $parameter (@{$args{'parameterlist'}}) {
1958 if ($parameter =~ /^#/) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001959 print " " . "$parameter\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001960 next;
1961 }
1962
1963 my $parameter_name = $parameter;
1964 $parameter_name =~ s/\[.*//;
1965
1966 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1967 $type = $args{'parametertypes'}{$parameter};
1968 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1969 # pointer-to-function
1970 print " $1 $parameter) ($2);\n";
1971 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1972 # bitfield
1973 print " $1 $parameter$2;\n";
1974 } else {
1975 print " " . $type . " " . $parameter . ";\n";
1976 }
1977 }
1978 print " };\n\n";
1979
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001980 print "**Members**\n\n";
1981 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001982 foreach $parameter (@{$args{'parameterlist'}}) {
1983 ($parameter =~ /^#/) && next;
1984
1985 my $parameter_name = $parameter;
1986 $parameter_name =~ s/\[.*//;
1987
1988 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1989 $type = $args{'parametertypes'}{$parameter};
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02001990 print_lineno($parameterdesc_start_lines{$parameter_name});
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001991 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001992 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001993 print "\n";
1994 }
1995 print "\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001996
1997 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001998 output_section_rst(@_);
1999}
2000
2001
Johannes Bergeda603f2010-09-11 15:55:22 -07002002## list mode output functions
2003
2004sub output_function_list(%) {
2005 my %args = %{$_[0]};
2006
2007 print $args{'function'} . "\n";
2008}
2009
2010# output enum in list
2011sub output_enum_list(%) {
2012 my %args = %{$_[0]};
2013 print $args{'enum'} . "\n";
2014}
2015
2016# output typedef in list
2017sub output_typedef_list(%) {
2018 my %args = %{$_[0]};
2019 print $args{'typedef'} . "\n";
2020}
2021
2022# output struct as list
2023sub output_struct_list(%) {
2024 my %args = %{$_[0]};
2025
2026 print $args{'struct'} . "\n";
2027}
2028
2029sub output_blockhead_list(%) {
2030 my %args = %{$_[0]};
2031 my ($parameter, $section);
2032
2033 foreach $section (@{$args{'sectionlist'}}) {
2034 print "DOC: $section\n";
2035 }
2036}
2037
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038##
Randy Dunlap27205742006-10-11 01:22:12 -07002039# generic output function for all types (function, struct/union, typedef, enum);
2040# calls the generated, variable output_ function name based on
2041# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042sub output_declaration {
2043 no strict 'refs';
2044 my $name = shift;
2045 my $functype = shift;
2046 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002047 if (($output_selection == OUTPUT_ALL) ||
2048 (($output_selection == OUTPUT_INCLUDE ||
2049 $output_selection == OUTPUT_EXPORTED) &&
2050 defined($function_table{$name})) ||
2051 (($output_selection == OUTPUT_EXCLUDE ||
2052 $output_selection == OUTPUT_INTERNAL) &&
2053 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002055 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 $section_counter++;
2057 }
2058}
2059
2060##
Randy Dunlap27205742006-10-11 01:22:12 -07002061# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002062sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002064 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 &$func(@_);
2066 $section_counter++;
2067}
2068
2069##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002070# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071# invokes the right handler. NOT called for functions.
2072sub dump_declaration($$) {
2073 no strict 'refs';
2074 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002075 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 &$func(@_);
2077}
2078
2079sub dump_union($$) {
2080 dump_struct(@_);
2081}
2082
2083sub dump_struct($$) {
2084 my $x = shift;
2085 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002086 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002088 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2089 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002090 $declaration_name = $2;
2091 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092
2093 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002094 $members =~ s/({.*})//g;
2095 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096
Martin Waitzaeec46b2005-11-13 16:08:13 -08002097 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002098 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2099 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002100 # strip comments:
2101 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002102 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002103 # strip kmemcheck_bitfield_{begin,end}.*;
2104 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002105 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002106 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002107 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002108 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002109 # replace DECLARE_BITMAP
2110 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002111
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002113 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114
2115 output_declaration($declaration_name,
2116 'struct',
2117 {'struct' => $declaration_name,
2118 'module' => $modulename,
2119 'parameterlist' => \@parameterlist,
2120 'parameterdescs' => \%parameterdescs,
2121 'parametertypes' => \%parametertypes,
2122 'sectionlist' => \@sectionlist,
2123 'sections' => \%sections,
2124 'purpose' => $declaration_purpose,
2125 'type' => $decl_type
2126 });
2127 }
2128 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002129 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 ++$errors;
2131 }
2132}
2133
2134sub dump_enum($$) {
2135 my $x = shift;
2136 my $file = shift;
2137
Martin Waitzaeec46b2005-11-13 16:08:13 -08002138 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002139 # strip #define macros inside enums
2140 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002141
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002143 $declaration_name = $1;
2144 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145
2146 foreach my $arg (split ',', $members) {
2147 $arg =~ s/^\s*(\w+).*/$1/;
2148 push @parameterlist, $arg;
2149 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002150 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002151 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 "not described in enum '$declaration_name'\n";
2153 }
2154
2155 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002156
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 output_declaration($declaration_name,
2158 'enum',
2159 {'enum' => $declaration_name,
2160 'module' => $modulename,
2161 'parameterlist' => \@parameterlist,
2162 'parameterdescs' => \%parameterdescs,
2163 'sectionlist' => \@sectionlist,
2164 'sections' => \%sections,
2165 'purpose' => $declaration_purpose
2166 });
2167 }
2168 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002169 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 ++$errors;
2171 }
2172}
2173
2174sub dump_typedef($$) {
2175 my $x = shift;
2176 my $file = shift;
2177
Martin Waitzaeec46b2005-11-13 16:08:13 -08002178 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002179
2180 # Parse function prototypes
2181 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
2182 # Function typedefs
2183 $return_type = $1;
2184 $declaration_name = $2;
2185 my $args = $3;
2186
2187 create_parameterlist($args, ',', $file);
2188
2189 output_declaration($declaration_name,
2190 'function',
2191 {'function' => $declaration_name,
2192 'module' => $modulename,
2193 'functiontype' => $return_type,
2194 'parameterlist' => \@parameterlist,
2195 'parameterdescs' => \%parameterdescs,
2196 'parametertypes' => \%parametertypes,
2197 'sectionlist' => \@sectionlist,
2198 'sections' => \%sections,
2199 'purpose' => $declaration_purpose
2200 });
2201 return;
2202 }
2203
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002205 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 $x =~ s/\[*.\]\s*;$/;/;
2207 }
2208
2209 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002210 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211
2212 output_declaration($declaration_name,
2213 'typedef',
2214 {'typedef' => $declaration_name,
2215 'module' => $modulename,
2216 'sectionlist' => \@sectionlist,
2217 'sections' => \%sections,
2218 'purpose' => $declaration_purpose
2219 });
2220 }
2221 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002222 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 ++$errors;
2224 }
2225}
2226
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002227sub save_struct_actual($) {
2228 my $actual = shift;
2229
2230 # strip all spaces from the actual param so that it looks like one string item
2231 $actual =~ s/\s*//g;
2232 $struct_actual = $struct_actual . $actual . " ";
2233}
2234
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235sub create_parameterlist($$$) {
2236 my $args = shift;
2237 my $splitter = shift;
2238 my $file = shift;
2239 my $type;
2240 my $param;
2241
Martin Waitza6d3fe72006-01-09 20:53:55 -08002242 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002244 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002246
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 foreach my $arg (split($splitter, $args)) {
2248 # strip comments
2249 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002250 # strip leading/trailing spaces
2251 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 $arg =~ s/\s*$//;
2253 $arg =~ s/\s+/ /;
2254
2255 if ($arg =~ /^#/) {
2256 # Treat preprocessor directive as a typeless variable just to fill
2257 # corresponding data structures "correctly". Catch it later in
2258 # output_* subs.
2259 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002260 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 # pointer-to-function
2262 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002263 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 $param = $1;
2265 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002266 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002267 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002269 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 $arg =~ s/\s*:\s*/:/g;
2271 $arg =~ s/\s*\[/\[/g;
2272
2273 my @args = split('\s*,\s*', $arg);
2274 if ($args[0] =~ m/\*/) {
2275 $args[0] =~ s/(\*+)\s*/ $1/;
2276 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002277
2278 my @first_arg;
2279 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2280 shift @args;
2281 push(@first_arg, split('\s+', $1));
2282 push(@first_arg, $2);
2283 } else {
2284 @first_arg = split('\s+', shift @args);
2285 }
2286
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 unshift(@args, pop @first_arg);
2288 $type = join " ", @first_arg;
2289
2290 foreach $param (@args) {
2291 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002292 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 push_parameter($2, "$type $1", $file);
2294 }
2295 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002296 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002297 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002298 push_parameter($1, "$type:$2", $file)
2299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 }
2301 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002302 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 push_parameter($param, $type, $file);
2304 }
2305 }
2306 }
2307 }
2308}
2309
2310sub push_parameter($$$) {
2311 my $param = shift;
2312 my $type = shift;
2313 my $file = shift;
2314
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002315 if (($anon_struct_union == 1) && ($type eq "") &&
2316 ($param eq "}")) {
2317 return; # ignore the ending }; from anon. struct/union
2318 }
2319
2320 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 my $param_name = $param;
2322 $param_name =~ s/\[.*//;
2323
Martin Waitza6d3fe72006-01-09 20:53:55 -08002324 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 {
Randy Dunlapced69092008-12-01 13:14:03 -08002326 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2327 $parameterdescs{$param} = "variable arguments";
2328 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 }
2330 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2331 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 $param="void";
2333 $parameterdescs{void} = "no arguments";
2334 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002335 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2336 # handle unnamed (anonymous) union or struct:
2337 {
2338 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002339 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002340 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002341 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002342 }
2343
Martin Waitza6d3fe72006-01-09 20:53:55 -08002344 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002345 # (but ignore ones starting with # as these are not parameters
2346 # but inline preprocessor statements);
2347 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002348 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002349 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2350
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 $parameterdescs{$param_name} = $undescribed;
2352
2353 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002354 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 "or member '$param' not " .
2356 "described in '$declaration_name'\n";
2357 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002358 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002359 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002361 }
2362 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002364 $param = xml_escape($param);
2365
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002366 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002367 # on @parameterlist;
2368 # this fixes a problem where check_sections() cannot find
2369 # a parameter like "addr[6 + 2]" because it actually appears
2370 # as "addr[6", "+", "2]" on the parameter list;
2371 # but it's better to maintain the param string unchanged for output,
2372 # so just weaken the string compare in check_sections() to ignore
2373 # "[blah" in a parameter string;
2374 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 push @parameterlist, $param;
2376 $parametertypes{$param} = $type;
2377}
2378
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002379sub check_sections($$$$$$) {
2380 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2381 my @sects = split ' ', $sectcheck;
2382 my @prms = split ' ', $prmscheck;
2383 my $err;
2384 my ($px, $sx);
2385 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2386
2387 foreach $sx (0 .. $#sects) {
2388 $err = 1;
2389 foreach $px (0 .. $#prms) {
2390 $prm_clean = $prms[$px];
2391 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002392 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002393 # ignore array size in a parameter string;
2394 # however, the original param string may contain
2395 # spaces, e.g.: addr[6 + 2]
2396 # and this appears in @prms as "addr[6" since the
2397 # parameter list is split at spaces;
2398 # hence just ignore "[..." for the sections check;
2399 $prm_clean =~ s/\[.*//;
2400
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002401 ##$prm_clean =~ s/^\**//;
2402 if ($prm_clean eq $sects[$sx]) {
2403 $err = 0;
2404 last;
2405 }
2406 }
2407 if ($err) {
2408 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002409 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002410 "Excess function parameter " .
2411 "'$sects[$sx]' " .
2412 "description in '$decl_name'\n";
2413 ++$warnings;
2414 } else {
2415 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002416 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002417 "Excess struct/union/enum/typedef member " .
2418 "'$sects[$sx]' " .
2419 "description in '$decl_name'\n";
2420 ++$warnings;
2421 }
2422 }
2423 }
2424 }
2425}
2426
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002428# Checks the section describing the return value of a function.
2429sub check_return_section {
2430 my $file = shift;
2431 my $declaration_name = shift;
2432 my $return_type = shift;
2433
2434 # Ignore an empty return type (It's a macro)
2435 # Ignore functions with a "void" return type. (But don't ignore "void *")
2436 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2437 return;
2438 }
2439
2440 if (!defined($sections{$section_return}) ||
2441 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002442 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002443 "No description found for return value of " .
2444 "'$declaration_name'\n";
2445 ++$warnings;
2446 }
2447}
2448
2449##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450# takes a function prototype and the name of the current file being
2451# processed and spits out all the details stored in the global
2452# arrays/hashes.
2453sub dump_function($$) {
2454 my $prototype = shift;
2455 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002456 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457
2458 $prototype =~ s/^static +//;
2459 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002460 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 $prototype =~ s/^inline +//;
2462 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002463 $prototype =~ s/^__inline +//;
2464 $prototype =~ s/^__always_inline +//;
2465 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002466 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002467 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002468 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002469 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002470 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002471 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002472 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473
2474 # Yes, this truly is vile. We are looking for:
2475 # 1. Return type (may be nothing if we're looking at a macro)
2476 # 2. Function name
2477 # 3. Function parameters.
2478 #
2479 # All the while we have to watch out for function pointer parameters
2480 # (which IIRC is what the two sections are for), C types (these
2481 # regexps don't even start to express all the possibilities), and
2482 # so on.
2483 #
2484 # If you mess with these regexps, it's a good idea to check that
2485 # the following functions' documentation still comes out right:
2486 # - parport_register_device (function pointer parameters)
2487 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002488 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002489
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002490 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2491 # This is an object-like macro, it has no return type and no parameter
2492 # list.
2493 # Function-like macros are not allowed to have spaces between
2494 # declaration_name and opening parenthesis (notice the \s+).
2495 $return_type = $1;
2496 $declaration_name = $2;
2497 $noret = 1;
2498 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2500 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2501 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002502 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2504 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2505 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2506 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2507 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2508 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2509 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2510 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002511 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2512 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002513 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2514 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 $return_type = $1;
2516 $declaration_name = $2;
2517 my $args = $3;
2518
2519 create_parameterlist($args, ',', $file);
2520 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002521 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522 return;
2523 }
2524
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002525 my $prms = join " ", @parameterlist;
2526 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2527
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002528 # This check emits a lot of warnings at the moment, because many
2529 # functions don't have a 'Return' doc section. So until the number
2530 # of warnings goes sufficiently down, the check is only performed in
2531 # verbose mode.
2532 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002533 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002534 check_return_section($file, $declaration_name, $return_type);
2535 }
2536
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002537 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 'function',
2539 {'function' => $declaration_name,
2540 'module' => $modulename,
2541 'functiontype' => $return_type,
2542 'parameterlist' => \@parameterlist,
2543 'parameterdescs' => \%parameterdescs,
2544 'parametertypes' => \%parametertypes,
2545 'sectionlist' => \@sectionlist,
2546 'sections' => \%sections,
2547 'purpose' => $declaration_purpose
2548 });
2549}
2550
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551sub reset_state {
2552 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 %parameterdescs = ();
2554 %parametertypes = ();
2555 @parameterlist = ();
2556 %sections = ();
2557 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002558 $sectcheck = "";
2559 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002561
Jani Nikula48af6062016-05-26 14:56:05 +03002562 $state = STATE_NORMAL;
2563 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564}
2565
Jason Baron56afb0f2009-04-30 13:29:36 -04002566sub tracepoint_munge($) {
2567 my $file = shift;
2568 my $tracepointname = 0;
2569 my $tracepointargs = 0;
2570
Jason Baron3a9089f2009-12-01 12:18:49 -05002571 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002572 $tracepointname = $1;
2573 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002574 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2575 $tracepointname = $1;
2576 }
2577 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2578 $tracepointname = $2;
2579 }
2580 $tracepointname =~ s/^\s+//; #strip leading whitespace
2581 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002582 $tracepointargs = $1;
2583 }
2584 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002585 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002586 "$prototype\n";
2587 } else {
2588 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2589 }
2590}
2591
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002592sub syscall_munge() {
2593 my $void = 0;
2594
2595 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2596## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2597 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2598 $void = 1;
2599## $prototype = "long sys_$1(void)";
2600 }
2601
2602 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2603 if ($prototype =~ m/long (sys_.*?),/) {
2604 $prototype =~ s/,/\(/;
2605 } elsif ($void) {
2606 $prototype =~ s/\)/\(void\)/;
2607 }
2608
2609 # now delete all of the odd-number commas in $prototype
2610 # so that arg types & arg names don't have a comma between them
2611 my $count = 0;
2612 my $len = length($prototype);
2613 if ($void) {
2614 $len = 0; # skip the for-loop
2615 }
2616 for (my $ix = 0; $ix < $len; $ix++) {
2617 if (substr($prototype, $ix, 1) eq ',') {
2618 $count++;
2619 if ($count % 2 == 1) {
2620 substr($prototype, $ix, 1) = ' ';
2621 }
2622 }
2623 }
2624}
2625
Daniel Vetterb7afa922016-06-01 23:46:24 +02002626sub process_proto_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 my $x = shift;
2628 my $file = shift;
2629
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002630 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2631
Randy Dunlap890c78c2008-10-25 17:06:43 -07002632 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 # do nothing
2634 }
2635 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002636 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002637 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002638
Randy Dunlap890c78c2008-10-25 17:06:43 -07002639 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002640 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2642 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002643 if ($prototype =~ /SYSCALL_DEFINE/) {
2644 syscall_munge();
2645 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002646 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2647 $prototype =~ /DEFINE_SINGLE_EVENT/)
2648 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002649 tracepoint_munge($file);
2650 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002651 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 reset_state();
2653 }
2654}
2655
Daniel Vetterb7afa922016-06-01 23:46:24 +02002656sub process_proto_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 my $x = shift;
2658 my $file = shift;
2659
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2661 $x =~ s@^\s+@@gos; # strip leading spaces
2662 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002663 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2664
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 if ($x =~ /^#/) {
2666 # To distinguish preprocessor directive from regular declaration later.
2667 $x .= ";";
2668 }
2669
2670 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002671 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 $prototype .= $1 . $2;
2673 ($2 eq '{') && $brcount++;
2674 ($2 eq '}') && $brcount--;
2675 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002676 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002678 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 }
2680 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002681 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 $prototype .= $x;
2683 last;
2684 }
2685 }
2686}
2687
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002688# xml_escape: replace <, >, and & in the text stream;
2689#
2690# however, formatting controls that are generated internally/locally in the
2691# kernel-doc script are not escaped here; instead, they begin life like
2692# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2693# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2694# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695sub xml_escape($) {
2696 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002697 if (($output_mode eq "text") || ($output_mode eq "man")) {
2698 return $text;
2699 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700 $text =~ s/\&/\\\\\\amp;/g;
2701 $text =~ s/\</\\\\\\lt;/g;
2702 $text =~ s/\>/\\\\\\gt;/g;
2703 return $text;
2704}
2705
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002706# xml_unescape: reverse the effects of xml_escape
2707sub xml_unescape($) {
2708 my $text = shift;
2709 if (($output_mode eq "text") || ($output_mode eq "man")) {
2710 return $text;
2711 }
2712 $text =~ s/\\\\\\amp;/\&/g;
2713 $text =~ s/\\\\\\lt;/</g;
2714 $text =~ s/\\\\\\gt;/>/g;
2715 return $text;
2716}
2717
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002718# convert local escape strings to html
2719# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2720sub local_unescape($) {
2721 my $text = shift;
2722 if (($output_mode eq "text") || ($output_mode eq "man")) {
2723 return $text;
2724 }
2725 $text =~ s/\\\\\\\\lt:/</g;
2726 $text =~ s/\\\\\\\\gt:/>/g;
2727 return $text;
2728}
2729
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002731 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 my $identifier;
2733 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002734 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002735 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002737 my ($orig_file) = @_;
Jani Nikulab7886de2016-05-28 00:41:50 +03002738 my $leading_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739
Randy Dunlap2283a112005-07-07 15:39:26 -07002740 if (defined($ENV{'SRCTREE'})) {
Ben Hutchings68f86662015-09-01 23:48:49 +01002741 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002742 }
2743 else {
Ben Hutchings68f86662015-09-01 23:48:49 +01002744 $file = $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002745 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 if (defined($source_map{$file})) {
2747 $file = $source_map{$file};
2748 }
2749
2750 if (!open(IN,"<$file")) {
2751 print STDERR "Error: Cannot open file $file\n";
2752 ++$errors;
2753 return;
2754 }
2755
Jani Nikula86ae2e32016-01-21 13:05:22 +02002756 # two passes for -export and -internal
Jani Nikulab6c3f452016-05-29 22:19:35 +03002757 if ($output_selection == OUTPUT_EXPORTED ||
2758 $output_selection == OUTPUT_INTERNAL) {
Jani Nikula86ae2e32016-01-21 13:05:22 +02002759 while (<IN>) {
2760 if (/$export_symbol/o) {
2761 $function_table{$2} = 1;
2762 }
2763 }
2764 seek(IN, 0, 0);
2765 }
2766
Ilya Dryomova9e73142010-02-26 13:05:47 -08002767 $. = 1;
2768
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 $section_counter = 0;
2770 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002771 while (s/\\\s*$//) {
2772 $_ .= <IN>;
2773 }
Jani Nikula48af6062016-05-26 14:56:05 +03002774 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002776 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002777 $in_doc_sect = 0;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002778 $declaration_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 }
Jani Nikula48af6062016-05-26 14:56:05 +03002780 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002782 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 $contents = "";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002784 $new_start_line = $. + 1;
2785
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 if ( $1 eq "" ) {
2787 $section = $section_intro;
2788 } else {
2789 $section = $1;
2790 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002791 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 elsif (/$doc_decl/o) {
2793 $identifier = $1;
2794 if (/\s*([\w\s]+?)\s*-/) {
2795 $identifier = $1;
2796 }
2797
Jani Nikula48af6062016-05-26 14:56:05 +03002798 $state = STATE_FIELD;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002799 # if there's no @param blocks need to set up default section
2800 # here
Jani Nikula2f4ad402016-05-30 11:21:06 +03002801 $contents = "";
2802 $section = $section_default;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002803 $new_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002805 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002806 $descr= $1;
2807 $descr =~ s/^\s*//;
2808 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002809 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002810 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002811 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 } else {
2813 $declaration_purpose = "";
2814 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002815
2816 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002817 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002818 print STDERR $_;
2819 ++$warnings;
2820 }
2821
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 if ($identifier =~ m/^struct/) {
2823 $decl_type = 'struct';
2824 } elsif ($identifier =~ m/^union/) {
2825 $decl_type = 'union';
2826 } elsif ($identifier =~ m/^enum/) {
2827 $decl_type = 'enum';
2828 } elsif ($identifier =~ m/^typedef/) {
2829 $decl_type = 'typedef';
2830 } else {
2831 $decl_type = 'function';
2832 }
2833
2834 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002835 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 }
2837 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002838 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 " - I thought it was a doc line\n";
2840 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002841 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 }
Jani Nikula48af6062016-05-26 14:56:05 +03002843 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Jani Nikulaf624ade2016-05-29 11:35:28 +03002844 if (/$doc_sect/i) { # case insensitive for supported section names
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 $newsection = $1;
2846 $newcontents = $2;
2847
Jani Nikulaf624ade2016-05-29 11:35:28 +03002848 # map the supported section names to the canonical names
2849 if ($newsection =~ m/^description$/i) {
2850 $newsection = $section_default;
2851 } elsif ($newsection =~ m/^context$/i) {
2852 $newsection = $section_context;
2853 } elsif ($newsection =~ m/^returns?$/i) {
2854 $newsection = $section_return;
2855 } elsif ($newsection =~ m/^\@return$/) {
2856 # special: @return is a section, not a param description
2857 $newsection = $section_return;
2858 }
2859
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002860 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002861 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002862 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002863 ++$warnings;
2864 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002865 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 $section = $section_default;
2867 }
2868
Randy Dunlap850622d2006-06-25 05:48:55 -07002869 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002870 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 $contents = $newcontents;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002872 $new_start_line = $.;
Jani Nikula0a726302016-05-28 14:50:20 +03002873 while ((substr($contents, 0, 1) eq " ") ||
2874 substr($contents, 0, 1) eq "\t") {
2875 $contents = substr($contents, 1);
2876 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 if ($contents ne "") {
2878 $contents .= "\n";
2879 }
2880 $section = $newsection;
Jani Nikulab7886de2016-05-28 00:41:50 +03002881 $leading_space = undef;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002883 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002884 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 $section = $section_default;
2886 $contents = "";
2887 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002888 # look for doc_com + <text> + doc_end:
2889 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002890 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002891 ++$warnings;
2892 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893
2894 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002895 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002897# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898 } elsif (/$doc_content/) {
2899 # miguel-style comment kludge, look for blank lines after
2900 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002901 if ($1 eq "") {
2902 if ($section =~ m/^@/ || $section eq $section_context) {
2903 dump_section($file, $section, xml_escape($contents));
2904 $section = $section_default;
2905 $contents = "";
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002906 $new_start_line = $.;
Johannes Weiner64231332009-09-17 19:26:53 -07002907 } else {
2908 $contents .= "\n";
2909 }
2910 $in_purpose = 0;
2911 } elsif ($in_purpose == 1) {
2912 # Continued declaration purpose
2913 chomp($declaration_purpose);
2914 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002915 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 } else {
Jani Nikulab7886de2016-05-28 00:41:50 +03002917 my $cont = $1;
2918 if ($section =~ m/^@/ || $section eq $section_context) {
2919 if (!defined $leading_space) {
2920 if ($cont =~ m/^(\s+)/) {
2921 $leading_space = $1;
2922 } else {
2923 $leading_space = "";
2924 }
2925 }
2926
2927 $cont =~ s/^$leading_space//;
2928 }
2929 $contents .= $cont . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 }
2931 } else {
2932 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002933 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 ++$warnings;
2935 }
Jani Nikula48af6062016-05-26 14:56:05 +03002936 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002937 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03002938 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002939 $section = $1;
2940 $contents = $2;
Daniel Vetter0b0f5f22016-06-03 22:21:34 +02002941 $new_start_line = $.;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002942 if ($contents ne "") {
2943 while ((substr($contents, 0, 1) eq " ") ||
2944 substr($contents, 0, 1) eq "\t") {
2945 $contents = substr($contents, 1);
2946 }
Jani Nikulaa0b96c22016-05-26 22:04:06 +03002947 $contents .= "\n";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002948 }
Jani Nikula48af6062016-05-26 14:56:05 +03002949 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002950 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03002951 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002952 if (($contents ne "") && ($contents ne "\n")) {
2953 dump_section($file, $section, xml_escape($contents));
2954 $section = $section_default;
2955 $contents = "";
2956 }
Jani Nikula48af6062016-05-26 14:56:05 +03002957 $state = STATE_PROTO;
2958 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002959 # Regular text
2960 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03002961 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002962 $contents .= $1 . "\n";
Jani Nikula6450c892016-05-26 22:04:42 +03002963 # nuke leading blank lines
2964 if ($contents =~ /^\s*$/) {
2965 $contents = "";
2966 }
Jani Nikula48af6062016-05-26 14:56:05 +03002967 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
2968 $inline_doc_state = STATE_INLINE_ERROR;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002969 print STDERR "Warning(${file}:$.): ";
2970 print STDERR "Incorrect use of kernel-doc format: $_";
2971 ++$warnings;
2972 }
2973 }
Jani Nikula48af6062016-05-26 14:56:05 +03002974 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
2975 if (/$doc_inline_start/) {
2976 $state = STATE_INLINE;
2977 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002978 } elsif ($decl_type eq 'function') {
Daniel Vetterb7afa922016-06-01 23:46:24 +02002979 process_proto_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 } else {
Daniel Vetterb7afa922016-06-01 23:46:24 +02002981 process_proto_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 }
Jani Nikula48af6062016-05-26 14:56:05 +03002983 } elsif ($state == STATE_DOCBLOCK) {
Daniel Vetterebff7f92016-06-01 23:46:23 +02002984 if (/$doc_end/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002986 dump_doc_section($file, $section, xml_escape($contents));
Jani Nikula2f4ad402016-05-30 11:21:06 +03002987 $section = $section_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 $contents = "";
2989 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 %parameterdescs = ();
2991 %parametertypes = ();
2992 @parameterlist = ();
2993 %sections = ();
2994 @sectionlist = ();
2995 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002996 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 }
2998 elsif (/$doc_content/)
2999 {
3000 if ( $1 eq "" )
3001 {
3002 $contents .= $blankline;
3003 }
3004 else
3005 {
3006 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08003007 }
Randy Dunlap3c308792007-05-08 00:24:39 -07003008 }
3009 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 }
3011 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07003012 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03003013 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08003014 print STDERR " Was looking for '$_'.\n" for keys %function_table;
3015 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 if ($output_mode eq "xml") {
3017 # The template wants at least one RefEntry here; make one.
3018 print "<refentry>\n";
3019 print " <refnamediv>\n";
3020 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003021 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 print " </refname>\n";
3023 print " <refpurpose>\n";
3024 print " Document generation inconsistency\n";
3025 print " </refpurpose>\n";
3026 print " </refnamediv>\n";
3027 print " <refsect1>\n";
3028 print " <title>\n";
3029 print " Oops\n";
3030 print " </title>\n";
3031 print " <warning>\n";
3032 print " <para>\n";
3033 print " The template for this document tried to insert\n";
3034 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003035 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 print " but none was found.\n";
3037 print " This dummy section is inserted to allow\n";
3038 print " generation to continue.\n";
3039 print " </para>\n";
3040 print " </warning>\n";
3041 print " </refsect1>\n";
3042 print "</refentry>\n";
3043 }
3044 }
3045}
Randy Dunlap8484baa2011-01-05 16:28:43 -08003046
3047
3048$kernelversion = get_kernel_version();
3049
3050# generate a sequence of code that will splice in highlighting information
3051# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02003052for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03003053 my $pattern = $highlights[$k][0];
3054 my $result = $highlights[$k][1];
3055# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
3056 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08003057}
3058
3059# Read the file that maps relative names to absolute names for
3060# separate source and object directories and for shadow trees.
3061if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3062 my ($relname, $absname);
3063 while(<SOURCE_MAP>) {
3064 chop();
3065 ($relname, $absname) = (split())[0..1];
3066 $relname =~ s:^/+::;
3067 $source_map{$relname} = $absname;
3068 }
3069 close(SOURCE_MAP);
3070}
3071
3072foreach (@ARGV) {
3073 chomp;
3074 process_file($_);
3075}
3076if ($verbose && $errors) {
3077 print STDERR "$errors errors\n";
3078}
3079if ($verbose && $warnings) {
3080 print STDERR "$warnings warnings\n";
3081}
3082
3083exit($errors);