blob: a6f82c812c1551980e2834d3c7ce1364d57ad5db [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 Vetter0b0f5f292016-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 Vetter0b0f5f292016-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 Vetter0b0f5f292016-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 Vetter0b0f5f292016-06-03 22:21:34 +0200419my %parameterdesc_start_lines;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420my @parameterlist;
421my %sections;
422my @sectionlist;
Daniel Vetter0b0f5f292016-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 Vetter0b0f5f292016-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 Nikulada9726e2016-06-07 10:29:59 +0300487 %function_table = ();
Jani Nikula86ae2e32016-01-21 13:05:22 +0200488 } elsif ($cmd eq "-internal") { # only non-exported symbols
Jani Nikulab6c3f452016-05-29 22:19:35 +0300489 $output_selection = OUTPUT_INTERNAL;
Jani Nikulada9726e2016-06-07 10:29:59 +0300490 %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 Vetter0b0f5f292016-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 Vetter0b0f5f292016-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 Vetter0b0f5f292016-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 Vetter0b0f5f292016-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 Nikula95b6be92016-06-10 11:14:05 +0300545 # Only warn on user specified duplicate section names.
546 if ($name ne $section_default) {
547 print STDERR "${file}:$.: warning: duplicate section name '$name'\n";
548 ++$warnings;
549 }
Jani Nikula32217762016-05-29 09:40:44 +0300550 $sections{$name} .= $contents;
551 } else {
552 $sections{$name} = $contents;
553 push @sectionlist, $name;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +0200554 $section_start_lines{$name} = $new_start_line;
555 $new_start_line = 0;
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700556 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 }
558}
559
560##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700561# dump DOC: section after checking that it should go out
562#
563sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700564 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700565 my $name = shift;
566 my $contents = join "\n", @_;
567
Johannes Berg4b445952007-10-24 15:08:48 -0700568 if ($no_doc_sections) {
569 return;
570 }
571
Jani Nikulab6c3f452016-05-29 22:19:35 +0300572 if (($output_selection == OUTPUT_ALL) ||
573 ($output_selection == OUTPUT_INCLUDE &&
574 defined($function_table{$name})) ||
575 ($output_selection == OUTPUT_EXCLUDE &&
576 !defined($function_table{$name})))
Johannes Bergb112e0f2007-10-24 15:08:48 -0700577 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700578 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700579 output_blockhead({'sectionlist' => \@sectionlist,
580 'sections' => \%sections,
581 'module' => $modulename,
Jani Nikulab6c3f452016-05-29 22:19:35 +0300582 'content-only' => ($output_selection != OUTPUT_ALL), });
Johannes Bergb112e0f2007-10-24 15:08:48 -0700583 }
584}
585
586##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587# output function
588#
589# parameterdescs, a hash.
590# function => "function name"
591# parameterlist => @list of parameters
592# parameterdescs => %parameter descriptions
593# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800594# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800595#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597sub output_highlight {
598 my $contents = join "\n",@_;
599 my $line;
600
601# DEBUG
602# if (!defined $contents) {
603# use Carp;
604# confess "output_highlight got called with no args?\n";
605# }
606
Dan Luedtke1b40c192012-08-12 10:46:15 +0200607 if ($output_mode eq "html" || $output_mode eq "html5" ||
608 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700609 $contents = local_unescape($contents);
610 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800611 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700612 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700613# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 eval $dohighlight;
615 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700616# print STDERR "contents af:$contents\n";
617
Dan Luedtke1b40c192012-08-12 10:46:15 +0200618# strip whitespaces when generating html5
619 if ($output_mode eq "html5") {
620 $contents =~ s/^\s+//;
621 $contents =~ s/\s+$//;
622 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700624 if (! $output_preformatted) {
625 $line =~ s/^\s*//;
626 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700627 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700628 if (! $output_preformatted) {
629 print $lineprefix, local_unescape($blankline);
630 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700632 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700633 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
634 print "\\&$line";
635 } else {
636 print $lineprefix, $line;
637 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 }
639 print "\n";
640 }
641}
642
Dan Luedtke1b40c192012-08-12 10:46:15 +0200643# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644sub output_section_html(%) {
645 my %args = %{$_[0]};
646 my $section;
647
648 foreach $section (@{$args{'sectionlist'}}) {
649 print "<h3>$section</h3>\n";
650 print "<blockquote>\n";
651 output_highlight($args{'sections'}{$section});
652 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800653 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654}
655
656# output enum in html
657sub output_enum_html(%) {
658 my %args = %{$_[0]};
659 my ($parameter);
660 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700661 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Randy Dunlapb9d973282009-06-09 08:50:38 -0700663 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 $count = 0;
665 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700666 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 if ($count != $#{$args{'parameterlist'}}) {
668 $count++;
669 print ",\n";
670 }
671 print "<br>";
672 }
673 print "};<br>\n";
674
675 print "<h3>Constants</h3>\n";
676 print "<dl>\n";
677 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700678 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 print "<dd>";
680 output_highlight($args{'parameterdescs'}{$parameter});
681 }
682 print "</dl>\n";
683 output_section_html(@_);
684 print "<hr>\n";
685}
686
Randy Dunlapd28bee02006-02-01 03:06:57 -0800687# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688sub output_typedef_html(%) {
689 my %args = %{$_[0]};
690 my ($parameter);
691 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700692 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693
Randy Dunlapb9d973282009-06-09 08:50:38 -0700694 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 output_section_html(@_);
696 print "<hr>\n";
697}
698
699# output struct in html
700sub output_struct_html(%) {
701 my %args = %{$_[0]};
702 my ($parameter);
703
Randy Dunlapb9d973282009-06-09 08:50:38 -0700704 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
705 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 foreach $parameter (@{$args{'parameterlist'}}) {
707 if ($parameter =~ /^#/) {
708 print "$parameter<br>\n";
709 next;
710 }
711 my $parameter_name = $parameter;
712 $parameter_name =~ s/\[.*//;
713
Randy Dunlap3c308792007-05-08 00:24:39 -0700714 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 $type = $args{'parametertypes'}{$parameter};
716 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
717 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700718 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700720 # bitfield
721 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700723 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 }
725 }
726 print "};<br>\n";
727
728 print "<h3>Members</h3>\n";
729 print "<dl>\n";
730 foreach $parameter (@{$args{'parameterlist'}}) {
731 ($parameter =~ /^#/) && next;
732
733 my $parameter_name = $parameter;
734 $parameter_name =~ s/\[.*//;
735
Randy Dunlap3c308792007-05-08 00:24:39 -0700736 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700737 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 print "<dd>";
739 output_highlight($args{'parameterdescs'}{$parameter_name});
740 }
741 print "</dl>\n";
742 output_section_html(@_);
743 print "<hr>\n";
744}
745
746# output function in html
747sub output_function_html(%) {
748 my %args = %{$_[0]};
749 my ($parameter, $section);
750 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
Randy Dunlapb9d973282009-06-09 08:50:38 -0700752 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
753 print "<i>" . $args{'functiontype'} . "</i>\n";
754 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755 print "(";
756 $count = 0;
757 foreach $parameter (@{$args{'parameterlist'}}) {
758 $type = $args{'parametertypes'}{$parameter};
759 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
760 # pointer-to-function
761 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
762 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700763 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764 }
765 if ($count != $#{$args{'parameterlist'}}) {
766 $count++;
767 print ",\n";
768 }
769 }
770 print ")\n";
771
772 print "<h3>Arguments</h3>\n";
773 print "<dl>\n";
774 foreach $parameter (@{$args{'parameterlist'}}) {
775 my $parameter_name = $parameter;
776 $parameter_name =~ s/\[.*//;
777
Randy Dunlap3c308792007-05-08 00:24:39 -0700778 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700779 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 print "<dd>";
781 output_highlight($args{'parameterdescs'}{$parameter_name});
782 }
783 print "</dl>\n";
784 output_section_html(@_);
785 print "<hr>\n";
786}
787
Johannes Bergb112e0f2007-10-24 15:08:48 -0700788# output DOC: block header in html
789sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 my %args = %{$_[0]};
791 my ($parameter, $section);
792 my $count;
793
794 foreach $section (@{$args{'sectionlist'}}) {
795 print "<h3>$section</h3>\n";
796 print "<ul>\n";
797 output_highlight($args{'sections'}{$section});
798 print "</ul>\n";
799 }
800 print "<hr>\n";
801}
802
Dan Luedtke1b40c192012-08-12 10:46:15 +0200803# output sections in html5
804sub output_section_html5(%) {
805 my %args = %{$_[0]};
806 my $section;
807
808 foreach $section (@{$args{'sectionlist'}}) {
809 print "<section>\n";
810 print "<h1>$section</h1>\n";
811 print "<p>\n";
812 output_highlight($args{'sections'}{$section});
813 print "</p>\n";
814 print "</section>\n";
815 }
816}
817
818# output enum in html5
819sub output_enum_html5(%) {
820 my %args = %{$_[0]};
821 my ($parameter);
822 my $count;
823 my $html5id;
824
825 $html5id = $args{'enum'};
826 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
827 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
828 print "<h1>enum " . $args{'enum'} . "</h1>\n";
829 print "<ol class=\"code\">\n";
830 print "<li>";
831 print "<span class=\"keyword\">enum</span> ";
832 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
833 print "</li>\n";
834 $count = 0;
835 foreach $parameter (@{$args{'parameterlist'}}) {
836 print "<li class=\"indent\">";
837 print "<span class=\"param\">" . $parameter . "</span>";
838 if ($count != $#{$args{'parameterlist'}}) {
839 $count++;
840 print ",";
841 }
842 print "</li>\n";
843 }
844 print "<li>};</li>\n";
845 print "</ol>\n";
846
847 print "<section>\n";
848 print "<h1>Constants</h1>\n";
849 print "<dl>\n";
850 foreach $parameter (@{$args{'parameterlist'}}) {
851 print "<dt>" . $parameter . "</dt>\n";
852 print "<dd>";
853 output_highlight($args{'parameterdescs'}{$parameter});
854 print "</dd>\n";
855 }
856 print "</dl>\n";
857 print "</section>\n";
858 output_section_html5(@_);
859 print "</article>\n";
860}
861
862# output typedef in html5
863sub output_typedef_html5(%) {
864 my %args = %{$_[0]};
865 my ($parameter);
866 my $count;
867 my $html5id;
868
869 $html5id = $args{'typedef'};
870 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
871 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
872 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
873
874 print "<ol class=\"code\">\n";
875 print "<li>";
876 print "<span class=\"keyword\">typedef</span> ";
877 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
878 print "</li>\n";
879 print "</ol>\n";
880 output_section_html5(@_);
881 print "</article>\n";
882}
883
884# output struct in html5
885sub output_struct_html5(%) {
886 my %args = %{$_[0]};
887 my ($parameter);
888 my $html5id;
889
890 $html5id = $args{'struct'};
891 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
892 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
893 print "<hgroup>\n";
894 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
895 print "<h2>". $args{'purpose'} . "</h2>\n";
896 print "</hgroup>\n";
897 print "<ol class=\"code\">\n";
898 print "<li>";
899 print "<span class=\"type\">" . $args{'type'} . "</span> ";
900 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
901 print "</li>\n";
902 foreach $parameter (@{$args{'parameterlist'}}) {
903 print "<li class=\"indent\">";
904 if ($parameter =~ /^#/) {
905 print "<span class=\"param\">" . $parameter ."</span>\n";
906 print "</li>\n";
907 next;
908 }
909 my $parameter_name = $parameter;
910 $parameter_name =~ s/\[.*//;
911
912 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
913 $type = $args{'parametertypes'}{$parameter};
914 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
915 # pointer-to-function
916 print "<span class=\"type\">$1</span> ";
917 print "<span class=\"param\">$parameter</span>";
918 print "<span class=\"type\">)</span> ";
919 print "(<span class=\"args\">$2</span>);";
920 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
921 # bitfield
922 print "<span class=\"type\">$1</span> ";
923 print "<span class=\"param\">$parameter</span>";
924 print "<span class=\"bits\">$2</span>;";
925 } else {
926 print "<span class=\"type\">$type</span> ";
927 print "<span class=\"param\">$parameter</span>;";
928 }
929 print "</li>\n";
930 }
931 print "<li>};</li>\n";
932 print "</ol>\n";
933
934 print "<section>\n";
935 print "<h1>Members</h1>\n";
936 print "<dl>\n";
937 foreach $parameter (@{$args{'parameterlist'}}) {
938 ($parameter =~ /^#/) && next;
939
940 my $parameter_name = $parameter;
941 $parameter_name =~ s/\[.*//;
942
943 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
944 print "<dt>" . $parameter . "</dt>\n";
945 print "<dd>";
946 output_highlight($args{'parameterdescs'}{$parameter_name});
947 print "</dd>\n";
948 }
949 print "</dl>\n";
950 print "</section>\n";
951 output_section_html5(@_);
952 print "</article>\n";
953}
954
955# output function in html5
956sub output_function_html5(%) {
957 my %args = %{$_[0]};
958 my ($parameter, $section);
959 my $count;
960 my $html5id;
961
962 $html5id = $args{'function'};
963 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
964 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
965 print "<hgroup>\n";
966 print "<h1>" . $args{'function'} . "</h1>";
967 print "<h2>" . $args{'purpose'} . "</h2>\n";
968 print "</hgroup>\n";
969 print "<ol class=\"code\">\n";
970 print "<li>";
971 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
972 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
973 print "</li>";
974 $count = 0;
975 foreach $parameter (@{$args{'parameterlist'}}) {
976 print "<li class=\"indent\">";
977 $type = $args{'parametertypes'}{$parameter};
978 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
979 # pointer-to-function
980 print "<span class=\"type\">$1</span> ";
981 print "<span class=\"param\">$parameter</span>";
982 print "<span class=\"type\">)</span> ";
983 print "(<span class=\"args\">$2</span>)";
984 } else {
985 print "<span class=\"type\">$type</span> ";
986 print "<span class=\"param\">$parameter</span>";
987 }
988 if ($count != $#{$args{'parameterlist'}}) {
989 $count++;
990 print ",";
991 }
992 print "</li>\n";
993 }
994 print "<li>)</li>\n";
995 print "</ol>\n";
996
997 print "<section>\n";
998 print "<h1>Arguments</h1>\n";
999 print "<p>\n";
1000 print "<dl>\n";
1001 foreach $parameter (@{$args{'parameterlist'}}) {
1002 my $parameter_name = $parameter;
1003 $parameter_name =~ s/\[.*//;
1004
1005 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1006 print "<dt>" . $parameter . "</dt>\n";
1007 print "<dd>";
1008 output_highlight($args{'parameterdescs'}{$parameter_name});
1009 print "</dd>\n";
1010 }
1011 print "</dl>\n";
1012 print "</section>\n";
1013 output_section_html5(@_);
1014 print "</article>\n";
1015}
1016
1017# output DOC: block header in html5
1018sub output_blockhead_html5(%) {
1019 my %args = %{$_[0]};
1020 my ($parameter, $section);
1021 my $count;
1022 my $html5id;
1023
1024 foreach $section (@{$args{'sectionlist'}}) {
1025 $html5id = $section;
1026 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
1027 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
1028 print "<h1>$section</h1>\n";
1029 print "<p>\n";
1030 output_highlight($args{'sections'}{$section});
1031 print "</p>\n";
1032 }
1033 print "</article>\n";
1034}
1035
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036sub output_section_xml(%) {
1037 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001038 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 # print out each section
1040 $lineprefix=" ";
1041 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001042 print "<refsect1>\n";
1043 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001045 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001046 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -07001047 } else {
1048 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 }
1050 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001051 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -07001053 print "</programlisting></informalexample>\n";
1054 } else {
1055 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 }
Rich Walkerc73894c2005-05-01 08:59:26 -07001057 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 }
1059}
1060
1061# output function in XML DocBook
1062sub output_function_xml(%) {
1063 my %args = %{$_[0]};
1064 my ($parameter, $section);
1065 my $count;
1066 my $id;
1067
Randy Dunlapb9d973282009-06-09 08:50:38 -07001068 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 $id =~ s/[^A-Za-z0-9]/-/g;
1070
Pavel Pisa5449bc92007-02-10 01:45:37 -08001071 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001072 print "<refentryinfo>\n";
1073 print " <title>LINUX</title>\n";
1074 print " <productname>Kernel Hackers Manual</productname>\n";
1075 print " <date>$man_date</date>\n";
1076 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001078 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001079 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001080 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 print "</refmeta>\n";
1082 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001083 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 print " <refpurpose>\n";
1085 print " ";
1086 output_highlight ($args{'purpose'});
1087 print " </refpurpose>\n";
1088 print "</refnamediv>\n";
1089
1090 print "<refsynopsisdiv>\n";
1091 print " <title>Synopsis</title>\n";
1092 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001093 print " <funcdef>" . $args{'functiontype'} . " ";
1094 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
1096 $count = 0;
1097 if ($#{$args{'parameterlist'}} >= 0) {
1098 foreach $parameter (@{$args{'parameterlist'}}) {
1099 $type = $args{'parametertypes'}{$parameter};
1100 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1101 # pointer-to-function
1102 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1103 print " <funcparams>$2</funcparams></paramdef>\n";
1104 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001105 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 print " <parameter>$parameter</parameter></paramdef>\n";
1107 }
1108 }
1109 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001110 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 }
1112 print " </funcprototype></funcsynopsis>\n";
1113 print "</refsynopsisdiv>\n";
1114
1115 # print parameters
1116 print "<refsect1>\n <title>Arguments</title>\n";
1117 if ($#{$args{'parameterlist'}} >= 0) {
1118 print " <variablelist>\n";
1119 foreach $parameter (@{$args{'parameterlist'}}) {
1120 my $parameter_name = $parameter;
1121 $parameter_name =~ s/\[.*//;
1122
1123 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1124 print " <listitem>\n <para>\n";
1125 $lineprefix=" ";
1126 output_highlight($args{'parameterdescs'}{$parameter_name});
1127 print " </para>\n </listitem>\n </varlistentry>\n";
1128 }
1129 print " </variablelist>\n";
1130 } else {
1131 print " <para>\n None\n </para>\n";
1132 }
1133 print "</refsect1>\n";
1134
1135 output_section_xml(@_);
1136 print "</refentry>\n\n";
1137}
1138
1139# output struct in XML DocBook
1140sub output_struct_xml(%) {
1141 my %args = %{$_[0]};
1142 my ($parameter, $section);
1143 my $id;
1144
Randy Dunlapb9d973282009-06-09 08:50:38 -07001145 $id = "API-struct-" . $args{'struct'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 $id =~ s/[^A-Za-z0-9]/-/g;
1147
Pavel Pisa5449bc92007-02-10 01:45:37 -08001148 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001149 print "<refentryinfo>\n";
1150 print " <title>LINUX</title>\n";
1151 print " <productname>Kernel Hackers Manual</productname>\n";
1152 print " <date>$man_date</date>\n";
1153 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001155 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001156 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001157 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 print "</refmeta>\n";
1159 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001160 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 print " <refpurpose>\n";
1162 print " ";
1163 output_highlight ($args{'purpose'});
1164 print " </refpurpose>\n";
1165 print "</refnamediv>\n";
1166
1167 print "<refsynopsisdiv>\n";
1168 print " <title>Synopsis</title>\n";
1169 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001170 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 foreach $parameter (@{$args{'parameterlist'}}) {
1172 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001173 my $prm = $parameter;
1174 # convert data read & converted thru xml_escape() into &xyz; format:
1175 # This allows us to have #define macros interspersed in a struct.
1176 $prm =~ s/\\\\\\/\&/g;
1177 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 next;
1179 }
1180
1181 my $parameter_name = $parameter;
1182 $parameter_name =~ s/\[.*//;
1183
1184 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001185 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 $type = $args{'parametertypes'}{$parameter};
1187 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1188 # pointer-to-function
1189 print " $1 $parameter) ($2);\n";
1190 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001191 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 print " $1 $parameter$2;\n";
1193 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001194 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 }
1196 }
1197 print "};";
1198 print " </programlisting>\n";
1199 print "</refsynopsisdiv>\n";
1200
1201 print " <refsect1>\n";
1202 print " <title>Members</title>\n";
1203
Randy Dunlap39f00c02008-09-22 13:57:44 -07001204 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 print " <variablelist>\n";
1206 foreach $parameter (@{$args{'parameterlist'}}) {
1207 ($parameter =~ /^#/) && next;
1208
1209 my $parameter_name = $parameter;
1210 $parameter_name =~ s/\[.*//;
1211
1212 defined($args{'parameterdescs'}{$parameter_name}) || next;
1213 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1214 print " <varlistentry>";
1215 print " <term>$parameter</term>\n";
1216 print " <listitem><para>\n";
1217 output_highlight($args{'parameterdescs'}{$parameter_name});
1218 print " </para></listitem>\n";
1219 print " </varlistentry>\n";
1220 }
1221 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001222 } else {
1223 print " <para>\n None\n </para>\n";
1224 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 print " </refsect1>\n";
1226
1227 output_section_xml(@_);
1228
1229 print "</refentry>\n\n";
1230}
1231
1232# output enum in XML DocBook
1233sub output_enum_xml(%) {
1234 my %args = %{$_[0]};
1235 my ($parameter, $section);
1236 my $count;
1237 my $id;
1238
Randy Dunlapb9d973282009-06-09 08:50:38 -07001239 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 $id =~ s/[^A-Za-z0-9]/-/g;
1241
Pavel Pisa5449bc92007-02-10 01:45:37 -08001242 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001243 print "<refentryinfo>\n";
1244 print " <title>LINUX</title>\n";
1245 print " <productname>Kernel Hackers Manual</productname>\n";
1246 print " <date>$man_date</date>\n";
1247 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001249 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001250 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001251 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252 print "</refmeta>\n";
1253 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001254 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 print " <refpurpose>\n";
1256 print " ";
1257 output_highlight ($args{'purpose'});
1258 print " </refpurpose>\n";
1259 print "</refnamediv>\n";
1260
1261 print "<refsynopsisdiv>\n";
1262 print " <title>Synopsis</title>\n";
1263 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001264 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 $count = 0;
1266 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001267 print " $parameter";
1268 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 $count++;
1270 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001271 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 print "\n";
1273 }
1274 print "};";
1275 print " </programlisting>\n";
1276 print "</refsynopsisdiv>\n";
1277
1278 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001279 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 print " <variablelist>\n";
1281 foreach $parameter (@{$args{'parameterlist'}}) {
1282 my $parameter_name = $parameter;
1283 $parameter_name =~ s/\[.*//;
1284
1285 print " <varlistentry>";
1286 print " <term>$parameter</term>\n";
1287 print " <listitem><para>\n";
1288 output_highlight($args{'parameterdescs'}{$parameter_name});
1289 print " </para></listitem>\n";
1290 print " </varlistentry>\n";
1291 }
1292 print " </variablelist>\n";
1293 print "</refsect1>\n";
1294
1295 output_section_xml(@_);
1296
1297 print "</refentry>\n\n";
1298}
1299
1300# output typedef in XML DocBook
1301sub output_typedef_xml(%) {
1302 my %args = %{$_[0]};
1303 my ($parameter, $section);
1304 my $id;
1305
Randy Dunlapb9d973282009-06-09 08:50:38 -07001306 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 $id =~ s/[^A-Za-z0-9]/-/g;
1308
Pavel Pisa5449bc92007-02-10 01:45:37 -08001309 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001310 print "<refentryinfo>\n";
1311 print " <title>LINUX</title>\n";
1312 print " <productname>Kernel Hackers Manual</productname>\n";
1313 print " <date>$man_date</date>\n";
1314 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001316 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001317 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 print "</refmeta>\n";
1319 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001320 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 print " <refpurpose>\n";
1322 print " ";
1323 output_highlight ($args{'purpose'});
1324 print " </refpurpose>\n";
1325 print "</refnamediv>\n";
1326
1327 print "<refsynopsisdiv>\n";
1328 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001329 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 print "</refsynopsisdiv>\n";
1331
1332 output_section_xml(@_);
1333
1334 print "</refentry>\n\n";
1335}
1336
1337# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001338sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 my %args = %{$_[0]};
1340 my ($parameter, $section);
1341 my $count;
1342
1343 my $id = $args{'module'};
1344 $id =~ s/[^A-Za-z0-9]/-/g;
1345
1346 # print out each section
1347 $lineprefix=" ";
1348 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001349 if (!$args{'content-only'}) {
1350 print "<refsect1>\n <title>$section</title>\n";
1351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 if ($section =~ m/EXAMPLE/i) {
1353 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001354 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001355 } else {
1356 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 }
1358 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001359 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 if ($section =~ m/EXAMPLE/i) {
1361 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001362 } else {
1363 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001365 if (!$args{'content-only'}) {
1366 print "\n</refsect1>\n";
1367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 }
1369
1370 print "\n\n";
1371}
1372
1373# output in XML DocBook
1374sub output_function_gnome {
1375 my %args = %{$_[0]};
1376 my ($parameter, $section);
1377 my $count;
1378 my $id;
1379
Randy Dunlapb9d973282009-06-09 08:50:38 -07001380 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 $id =~ s/[^A-Za-z0-9]/-/g;
1382
1383 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001384 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
1386 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001387 print " <funcdef>" . $args{'functiontype'} . " ";
1388 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 print "</function></funcdef>\n";
1390
1391 $count = 0;
1392 if ($#{$args{'parameterlist'}} >= 0) {
1393 foreach $parameter (@{$args{'parameterlist'}}) {
1394 $type = $args{'parametertypes'}{$parameter};
1395 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1396 # pointer-to-function
1397 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1398 print " <funcparams>$2</funcparams></paramdef>\n";
1399 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001400 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 print " <parameter>$parameter</parameter></paramdef>\n";
1402 }
1403 }
1404 } else {
1405 print " <void>\n";
1406 }
1407 print " </funcsynopsis>\n";
1408 if ($#{$args{'parameterlist'}} >= 0) {
1409 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1410 print "<tgroup cols=\"2\">\n";
1411 print "<colspec colwidth=\"2*\">\n";
1412 print "<colspec colwidth=\"8*\">\n";
1413 print "<tbody>\n";
1414 foreach $parameter (@{$args{'parameterlist'}}) {
1415 my $parameter_name = $parameter;
1416 $parameter_name =~ s/\[.*//;
1417
1418 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1419 print " <entry>\n";
1420 $lineprefix=" ";
1421 output_highlight($args{'parameterdescs'}{$parameter_name});
1422 print " </entry></row>\n";
1423 }
1424 print " </tbody></tgroup></informaltable>\n";
1425 } else {
1426 print " <para>\n None\n </para>\n";
1427 }
1428
1429 # print out each section
1430 $lineprefix=" ";
1431 foreach $section (@{$args{'sectionlist'}}) {
1432 print "<simplesect>\n <title>$section</title>\n";
1433 if ($section =~ m/EXAMPLE/i) {
1434 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001435 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 } else {
1437 }
1438 print "<para>\n";
1439 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001440 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 print "</para>\n";
1442 if ($section =~ m/EXAMPLE/i) {
1443 print "</programlisting></example>\n";
1444 } else {
1445 }
1446 print " </simplesect>\n";
1447 }
1448
1449 print "</sect2>\n\n";
1450}
1451
1452##
1453# output function in man
1454sub output_function_man(%) {
1455 my %args = %{$_[0]};
1456 my ($parameter, $section);
1457 my $count;
1458
1459 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1460
1461 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001462 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
1464 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001465 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001466 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001467 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001468 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001469 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 $count = 0;
1471 my $parenth = "(";
1472 my $post = ",";
1473 foreach my $parameter (@{$args{'parameterlist'}}) {
1474 if ($count == $#{$args{'parameterlist'}}) {
1475 $post = ");";
1476 }
1477 $type = $args{'parametertypes'}{$parameter};
1478 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1479 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001480 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 } else {
1482 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001483 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 }
1485 $count++;
1486 $parenth = "";
1487 }
1488
1489 print ".SH ARGUMENTS\n";
1490 foreach $parameter (@{$args{'parameterlist'}}) {
1491 my $parameter_name = $parameter;
1492 $parameter_name =~ s/\[.*//;
1493
Randy Dunlapb9d973282009-06-09 08:50:38 -07001494 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 output_highlight($args{'parameterdescs'}{$parameter_name});
1496 }
1497 foreach $section (@{$args{'sectionlist'}}) {
1498 print ".SH \"", uc $section, "\"\n";
1499 output_highlight($args{'sections'}{$section});
1500 }
1501}
1502
1503##
1504# output enum in man
1505sub output_enum_man(%) {
1506 my %args = %{$_[0]};
1507 my ($parameter, $section);
1508 my $count;
1509
1510 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1511
1512 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001513 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
1515 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001516 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 $count = 0;
1518 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001519 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 if ($count == $#{$args{'parameterlist'}}) {
1521 print "\n};\n";
1522 last;
1523 }
1524 else {
1525 print ", \n.br\n";
1526 }
1527 $count++;
1528 }
1529
1530 print ".SH Constants\n";
1531 foreach $parameter (@{$args{'parameterlist'}}) {
1532 my $parameter_name = $parameter;
1533 $parameter_name =~ s/\[.*//;
1534
Randy Dunlapb9d973282009-06-09 08:50:38 -07001535 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536 output_highlight($args{'parameterdescs'}{$parameter_name});
1537 }
1538 foreach $section (@{$args{'sectionlist'}}) {
1539 print ".SH \"$section\"\n";
1540 output_highlight($args{'sections'}{$section});
1541 }
1542}
1543
1544##
1545# output struct in man
1546sub output_struct_man(%) {
1547 my %args = %{$_[0]};
1548 my ($parameter, $section);
1549
Randy Dunlapb9d973282009-06-09 08:50:38 -07001550 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
1552 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001553 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
1555 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001556 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
1558 foreach my $parameter (@{$args{'parameterlist'}}) {
1559 if ($parameter =~ /^#/) {
1560 print ".BI \"$parameter\"\n.br\n";
1561 next;
1562 }
1563 my $parameter_name = $parameter;
1564 $parameter_name =~ s/\[.*//;
1565
Randy Dunlap3c308792007-05-08 00:24:39 -07001566 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 $type = $args{'parametertypes'}{$parameter};
1568 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1569 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001570 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001572 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001573 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 } else {
1575 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001576 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 }
1578 print "\n.br\n";
1579 }
1580 print "};\n.br\n";
1581
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001582 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 foreach $parameter (@{$args{'parameterlist'}}) {
1584 ($parameter =~ /^#/) && next;
1585
1586 my $parameter_name = $parameter;
1587 $parameter_name =~ s/\[.*//;
1588
Randy Dunlap3c308792007-05-08 00:24:39 -07001589 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001590 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 output_highlight($args{'parameterdescs'}{$parameter_name});
1592 }
1593 foreach $section (@{$args{'sectionlist'}}) {
1594 print ".SH \"$section\"\n";
1595 output_highlight($args{'sections'}{$section});
1596 }
1597}
1598
1599##
1600# output typedef in man
1601sub output_typedef_man(%) {
1602 my %args = %{$_[0]};
1603 my ($parameter, $section);
1604
1605 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1606
1607 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001608 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001609
1610 foreach $section (@{$args{'sectionlist'}}) {
1611 print ".SH \"$section\"\n";
1612 output_highlight($args{'sections'}{$section});
1613 }
1614}
1615
Johannes Bergb112e0f2007-10-24 15:08:48 -07001616sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 my %args = %{$_[0]};
1618 my ($parameter, $section);
1619 my $count;
1620
1621 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1622
1623 foreach $section (@{$args{'sectionlist'}}) {
1624 print ".SH \"$section\"\n";
1625 output_highlight($args{'sections'}{$section});
1626 }
1627}
1628
1629##
1630# output in text
1631sub output_function_text(%) {
1632 my %args = %{$_[0]};
1633 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001634 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635
Randy Dunlapf47634b2006-07-01 04:36:36 -07001636 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001637 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001638
1639 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001640 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001641 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001642 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001643 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001644 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001646
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 my $count = 0;
1648 foreach my $parameter (@{$args{'parameterlist'}}) {
1649 $type = $args{'parametertypes'}{$parameter};
1650 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1651 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001652 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001654 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655 }
1656 if ($count != $#{$args{'parameterlist'}}) {
1657 $count++;
1658 print ",\n";
1659 print " " x length($start);
1660 } else {
1661 print ");\n\n";
1662 }
1663 }
1664
1665 print "Arguments:\n\n";
1666 foreach $parameter (@{$args{'parameterlist'}}) {
1667 my $parameter_name = $parameter;
1668 $parameter_name =~ s/\[.*//;
1669
Randy Dunlapb9d973282009-06-09 08:50:38 -07001670 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 }
1672 output_section_text(@_);
1673}
1674
1675#output sections in text
1676sub output_section_text(%) {
1677 my %args = %{$_[0]};
1678 my $section;
1679
1680 print "\n";
1681 foreach $section (@{$args{'sectionlist'}}) {
1682 print "$section:\n\n";
1683 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001684 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 print "\n\n";
1686}
1687
1688# output enum in text
1689sub output_enum_text(%) {
1690 my %args = %{$_[0]};
1691 my ($parameter);
1692 my $count;
1693 print "Enum:\n\n";
1694
Randy Dunlapb9d973282009-06-09 08:50:38 -07001695 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1696 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 $count = 0;
1698 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001699 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 if ($count != $#{$args{'parameterlist'}}) {
1701 $count++;
1702 print ",";
1703 }
1704 print "\n";
1705 }
1706 print "};\n\n";
1707
1708 print "Constants:\n\n";
1709 foreach $parameter (@{$args{'parameterlist'}}) {
1710 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001711 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 }
1713
1714 output_section_text(@_);
1715}
1716
1717# output typedef in text
1718sub output_typedef_text(%) {
1719 my %args = %{$_[0]};
1720 my ($parameter);
1721 my $count;
1722 print "Typedef:\n\n";
1723
Randy Dunlapb9d973282009-06-09 08:50:38 -07001724 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 output_section_text(@_);
1726}
1727
1728# output struct as text
1729sub output_struct_text(%) {
1730 my %args = %{$_[0]};
1731 my ($parameter);
1732
Randy Dunlapb9d973282009-06-09 08:50:38 -07001733 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1734 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 foreach $parameter (@{$args{'parameterlist'}}) {
1736 if ($parameter =~ /^#/) {
1737 print "$parameter\n";
1738 next;
1739 }
1740
1741 my $parameter_name = $parameter;
1742 $parameter_name =~ s/\[.*//;
1743
Randy Dunlap3c308792007-05-08 00:24:39 -07001744 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745 $type = $args{'parametertypes'}{$parameter};
1746 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1747 # pointer-to-function
1748 print "\t$1 $parameter) ($2);\n";
1749 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001750 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 print "\t$1 $parameter$2;\n";
1752 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001753 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 }
1755 }
1756 print "};\n\n";
1757
1758 print "Members:\n\n";
1759 foreach $parameter (@{$args{'parameterlist'}}) {
1760 ($parameter =~ /^#/) && next;
1761
1762 my $parameter_name = $parameter;
1763 $parameter_name =~ s/\[.*//;
1764
Randy Dunlap3c308792007-05-08 00:24:39 -07001765 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001767 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 }
1769 print "\n";
1770 output_section_text(@_);
1771}
1772
Johannes Bergb112e0f2007-10-24 15:08:48 -07001773sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 my %args = %{$_[0]};
1775 my ($parameter, $section);
1776
1777 foreach $section (@{$args{'sectionlist'}}) {
1778 print " $section:\n";
1779 print " -> ";
1780 output_highlight($args{'sections'}{$section});
1781 }
1782}
1783
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001784##
1785# output in restructured text
1786#
1787
1788#
1789# This could use some work; it's used to output the DOC: sections, and
1790# starts by putting out the name of the doc section itself, but that tends
1791# to duplicate a header already in the template file.
1792#
1793sub output_blockhead_rst(%) {
1794 my %args = %{$_[0]};
1795 my ($parameter, $section);
1796
1797 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikula9e721842016-05-29 22:27:35 +03001798 if ($output_selection != OUTPUT_INCLUDE) {
1799 print "**$section**\n\n";
1800 }
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001801 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001802 output_highlight_rst($args{'sections'}{$section});
1803 print "\n";
1804 }
1805}
1806
1807sub output_highlight_rst {
1808 my $contents = join "\n",@_;
1809 my $line;
1810
1811 # undo the evil effects of xml_escape() earlier
1812 $contents = xml_unescape($contents);
1813
1814 eval $dohighlight;
1815 die $@ if $@;
1816
1817 foreach $line (split "\n", $contents) {
Jani Nikula830066a2016-05-26 22:04:33 +03001818 print $lineprefix . $line . "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001819 }
1820}
1821
1822sub output_function_rst(%) {
1823 my %args = %{$_[0]};
1824 my ($parameter, $section);
Jani Nikulac099ff62016-05-26 17:18:17 +03001825 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001826 my $start;
1827
1828 print ".. c:function:: ";
1829 if ($args{'functiontype'} ne "") {
1830 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
1831 } else {
1832 $start = $args{'function'} . " (";
1833 }
1834 print $start;
1835
1836 my $count = 0;
1837 foreach my $parameter (@{$args{'parameterlist'}}) {
1838 if ($count ne 0) {
1839 print ", ";
1840 }
1841 $count++;
1842 $type = $args{'parametertypes'}{$parameter};
1843 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1844 # pointer-to-function
1845 print $1 . $parameter . ") (" . $2;
1846 } else {
1847 print $type . " " . $parameter;
1848 }
1849 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001850 print ")\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001851 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001852 $lineprefix = " ";
1853 output_highlight_rst($args{'purpose'});
1854 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001855
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001856 print "**Parameters**\n\n";
1857 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001858 foreach $parameter (@{$args{'parameterlist'}}) {
1859 my $parameter_name = $parameter;
1860 #$parameter_name =~ s/\[.*//;
1861 $type = $args{'parametertypes'}{$parameter};
1862
1863 if ($type ne "") {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001864 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001865 } else {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001866 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001867 }
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001868
1869 print_lineno($parameterdesc_start_lines{$parameter_name});
1870
Jani Nikula5e64fa92016-05-19 20:32:48 +03001871 if (defined($args{'parameterdescs'}{$parameter_name}) &&
1872 $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001873 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001874 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001875 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001876 }
1877 print "\n";
1878 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001879
1880 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001881 output_section_rst(@_);
1882}
1883
1884sub output_section_rst(%) {
1885 my %args = %{$_[0]};
1886 my $section;
1887 my $oldprefix = $lineprefix;
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001888 $lineprefix = "";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001889
1890 foreach $section (@{$args{'sectionlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001891 print "**$section**\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001892 print_lineno($section_start_lines{$section});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001893 output_highlight_rst($args{'sections'}{$section});
1894 print "\n";
1895 }
1896 print "\n";
1897 $lineprefix = $oldprefix;
1898}
1899
1900sub output_enum_rst(%) {
1901 my %args = %{$_[0]};
1902 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001903 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001904 my $count;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001905 my $name = "enum " . $args{'enum'};
Jani Nikula62850972016-05-12 16:15:38 +03001906
1907 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001908 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001909 $lineprefix = " ";
1910 output_highlight_rst($args{'purpose'});
1911 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001912
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001913 print "**Constants**\n\n";
1914 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001915 foreach $parameter (@{$args{'parameterlist'}}) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001916 print "``$parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001917 if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
1918 output_highlight_rst($args{'parameterdescs'}{$parameter});
1919 } else {
Jani Nikulad4b08e02016-05-28 00:48:17 +03001920 print " *undescribed*\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001921 }
1922 print "\n";
1923 }
Jani Nikulac099ff62016-05-26 17:18:17 +03001924
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001925 $lineprefix = $oldprefix;
1926 output_section_rst(@_);
1927}
1928
1929sub output_typedef_rst(%) {
1930 my %args = %{$_[0]};
1931 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001932 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001933 my $name = "typedef " . $args{'typedef'};
1934
Jani Nikula62850972016-05-12 16:15:38 +03001935 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001936 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001937 $lineprefix = " ";
1938 output_highlight_rst($args{'purpose'});
1939 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001940
Jani Nikulac099ff62016-05-26 17:18:17 +03001941 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001942 output_section_rst(@_);
1943}
1944
1945sub output_struct_rst(%) {
1946 my %args = %{$_[0]};
1947 my ($parameter);
Jani Nikulac099ff62016-05-26 17:18:17 +03001948 my $oldprefix = $lineprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001949 my $name = $args{'type'} . " " . $args{'struct'};
1950
Jani Nikula62850972016-05-12 16:15:38 +03001951 print "\n\n.. c:type:: " . $name . "\n\n";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001952 print_lineno($declaration_start_line);
Jani Nikulac099ff62016-05-26 17:18:17 +03001953 $lineprefix = " ";
1954 output_highlight_rst($args{'purpose'});
1955 print "\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001956
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001957 print "**Definition**\n\n";
1958 print "::\n\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001959 print " " . $args{'type'} . " " . $args{'struct'} . " {\n";
1960 foreach $parameter (@{$args{'parameterlist'}}) {
1961 if ($parameter =~ /^#/) {
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001962 print " " . "$parameter\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001963 next;
1964 }
1965
1966 my $parameter_name = $parameter;
1967 $parameter_name =~ s/\[.*//;
1968
1969 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1970 $type = $args{'parametertypes'}{$parameter};
1971 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1972 # pointer-to-function
1973 print " $1 $parameter) ($2);\n";
1974 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1975 # bitfield
1976 print " $1 $parameter$2;\n";
1977 } else {
1978 print " " . $type . " " . $parameter . ";\n";
1979 }
1980 }
1981 print " };\n\n";
1982
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001983 print "**Members**\n\n";
1984 $lineprefix = " ";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001985 foreach $parameter (@{$args{'parameterlist'}}) {
1986 ($parameter =~ /^#/) && next;
1987
1988 my $parameter_name = $parameter;
1989 $parameter_name =~ s/\[.*//;
1990
1991 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1992 $type = $args{'parametertypes'}{$parameter};
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02001993 print_lineno($parameterdesc_start_lines{$parameter_name});
Jani Nikulaecbcfba2016-05-26 18:30:27 +03001994 print "``$type $parameter``\n";
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001995 output_highlight_rst($args{'parameterdescs'}{$parameter_name});
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03001996 print "\n";
1997 }
1998 print "\n";
Jani Nikulac099ff62016-05-26 17:18:17 +03001999
2000 $lineprefix = $oldprefix;
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002001 output_section_rst(@_);
2002}
2003
2004
Johannes Bergeda603f2010-09-11 15:55:22 -07002005## list mode output functions
2006
2007sub output_function_list(%) {
2008 my %args = %{$_[0]};
2009
2010 print $args{'function'} . "\n";
2011}
2012
2013# output enum in list
2014sub output_enum_list(%) {
2015 my %args = %{$_[0]};
2016 print $args{'enum'} . "\n";
2017}
2018
2019# output typedef in list
2020sub output_typedef_list(%) {
2021 my %args = %{$_[0]};
2022 print $args{'typedef'} . "\n";
2023}
2024
2025# output struct as list
2026sub output_struct_list(%) {
2027 my %args = %{$_[0]};
2028
2029 print $args{'struct'} . "\n";
2030}
2031
2032sub output_blockhead_list(%) {
2033 my %args = %{$_[0]};
2034 my ($parameter, $section);
2035
2036 foreach $section (@{$args{'sectionlist'}}) {
2037 print "DOC: $section\n";
2038 }
2039}
2040
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041##
Randy Dunlap27205742006-10-11 01:22:12 -07002042# generic output function for all types (function, struct/union, typedef, enum);
2043# calls the generated, variable output_ function name based on
2044# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045sub output_declaration {
2046 no strict 'refs';
2047 my $name = shift;
2048 my $functype = shift;
2049 my $func = "output_${functype}_$output_mode";
Jani Nikulab6c3f452016-05-29 22:19:35 +03002050 if (($output_selection == OUTPUT_ALL) ||
2051 (($output_selection == OUTPUT_INCLUDE ||
2052 $output_selection == OUTPUT_EXPORTED) &&
2053 defined($function_table{$name})) ||
2054 (($output_selection == OUTPUT_EXCLUDE ||
2055 $output_selection == OUTPUT_INTERNAL) &&
2056 !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 {
Randy Dunlap3c308792007-05-08 00:24:39 -07002058 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 $section_counter++;
2060 }
2061}
2062
2063##
Randy Dunlap27205742006-10-11 01:22:12 -07002064# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07002065sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07002067 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 &$func(@_);
2069 $section_counter++;
2070}
2071
2072##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002073# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074# invokes the right handler. NOT called for functions.
2075sub dump_declaration($$) {
2076 no strict 'refs';
2077 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07002078 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 &$func(@_);
2080}
2081
2082sub dump_union($$) {
2083 dump_struct(@_);
2084}
2085
2086sub dump_struct($$) {
2087 my $x = shift;
2088 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002089 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07002091 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
2092 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07002093 $declaration_name = $2;
2094 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095
2096 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002097 $members =~ s/({.*})//g;
2098 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
Martin Waitzaeec46b2005-11-13 16:08:13 -08002100 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03002101 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
2102 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002103 # strip comments:
2104 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002105 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07002106 # strip kmemcheck_bitfield_{begin,end}.*;
2107 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07002108 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06002109 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08002110 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06002111 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01002112 # replace DECLARE_BITMAP
2113 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08002114
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002116 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
2118 output_declaration($declaration_name,
2119 'struct',
2120 {'struct' => $declaration_name,
2121 'module' => $modulename,
2122 'parameterlist' => \@parameterlist,
2123 'parameterdescs' => \%parameterdescs,
2124 'parametertypes' => \%parametertypes,
2125 'sectionlist' => \@sectionlist,
2126 'sections' => \%sections,
2127 'purpose' => $declaration_purpose,
2128 'type' => $decl_type
2129 });
2130 }
2131 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002132 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 ++$errors;
2134 }
2135}
2136
2137sub dump_enum($$) {
2138 my $x = shift;
2139 my $file = shift;
2140
Martin Waitzaeec46b2005-11-13 16:08:13 -08002141 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01002142 # strip #define macros inside enums
2143 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07002144
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002146 $declaration_name = $1;
2147 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148
2149 foreach my $arg (split ',', $members) {
2150 $arg =~ s/^\s*(\w+).*/$1/;
2151 push @parameterlist, $arg;
2152 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002153 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07002154 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 "not described in enum '$declaration_name'\n";
2156 }
2157
2158 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002159
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 output_declaration($declaration_name,
2161 'enum',
2162 {'enum' => $declaration_name,
2163 'module' => $modulename,
2164 'parameterlist' => \@parameterlist,
2165 'parameterdescs' => \%parameterdescs,
2166 'sectionlist' => \@sectionlist,
2167 'sections' => \%sections,
2168 'purpose' => $declaration_purpose
2169 });
2170 }
2171 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002172 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 ++$errors;
2174 }
2175}
2176
2177sub dump_typedef($$) {
2178 my $x = shift;
2179 my $file = shift;
2180
Martin Waitzaeec46b2005-11-13 16:08:13 -08002181 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03002182
2183 # Parse function prototypes
2184 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
2185 # Function typedefs
2186 $return_type = $1;
2187 $declaration_name = $2;
2188 my $args = $3;
2189
2190 create_parameterlist($args, ',', $file);
2191
2192 output_declaration($declaration_name,
2193 'function',
2194 {'function' => $declaration_name,
2195 'module' => $modulename,
2196 'functiontype' => $return_type,
2197 'parameterlist' => \@parameterlist,
2198 'parameterdescs' => \%parameterdescs,
2199 'parametertypes' => \%parametertypes,
2200 'sectionlist' => \@sectionlist,
2201 'sections' => \%sections,
2202 'purpose' => $declaration_purpose
2203 });
2204 return;
2205 }
2206
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002208 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 $x =~ s/\[*.\]\s*;$/;/;
2210 }
2211
2212 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002213 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214
2215 output_declaration($declaration_name,
2216 'typedef',
2217 {'typedef' => $declaration_name,
2218 'module' => $modulename,
2219 'sectionlist' => \@sectionlist,
2220 'sections' => \%sections,
2221 'purpose' => $declaration_purpose
2222 });
2223 }
2224 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002225 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226 ++$errors;
2227 }
2228}
2229
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002230sub save_struct_actual($) {
2231 my $actual = shift;
2232
2233 # strip all spaces from the actual param so that it looks like one string item
2234 $actual =~ s/\s*//g;
2235 $struct_actual = $struct_actual . $actual . " ";
2236}
2237
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238sub create_parameterlist($$$) {
2239 my $args = shift;
2240 my $splitter = shift;
2241 my $file = shift;
2242 my $type;
2243 my $param;
2244
Martin Waitza6d3fe72006-01-09 20:53:55 -08002245 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002247 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002249
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 foreach my $arg (split($splitter, $args)) {
2251 # strip comments
2252 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07002253 # strip leading/trailing spaces
2254 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 $arg =~ s/\s*$//;
2256 $arg =~ s/\s+/ /;
2257
2258 if ($arg =~ /^#/) {
2259 # Treat preprocessor directive as a typeless variable just to fill
2260 # corresponding data structures "correctly". Catch it later in
2261 # output_* subs.
2262 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08002263 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 # pointer-to-function
2265 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08002266 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 $param = $1;
2268 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08002269 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002270 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08002272 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 $arg =~ s/\s*:\s*/:/g;
2274 $arg =~ s/\s*\[/\[/g;
2275
2276 my @args = split('\s*,\s*', $arg);
2277 if ($args[0] =~ m/\*/) {
2278 $args[0] =~ s/(\*+)\s*/ $1/;
2279 }
Borislav Petkov884f2812007-05-08 00:29:05 -07002280
2281 my @first_arg;
2282 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
2283 shift @args;
2284 push(@first_arg, split('\s+', $1));
2285 push(@first_arg, $2);
2286 } else {
2287 @first_arg = split('\s+', shift @args);
2288 }
2289
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 unshift(@args, pop @first_arg);
2291 $type = join " ", @first_arg;
2292
2293 foreach $param (@args) {
2294 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002295 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 push_parameter($2, "$type $1", $file);
2297 }
2298 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07002299 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002300 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07002301 push_parameter($1, "$type:$2", $file)
2302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 }
2304 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002305 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 push_parameter($param, $type, $file);
2307 }
2308 }
2309 }
2310 }
2311}
2312
2313sub push_parameter($$$) {
2314 my $param = shift;
2315 my $type = shift;
2316 my $file = shift;
2317
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002318 if (($anon_struct_union == 1) && ($type eq "") &&
2319 ($param eq "}")) {
2320 return; # ignore the ending }; from anon. struct/union
2321 }
2322
2323 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 my $param_name = $param;
2325 $param_name =~ s/\[.*//;
2326
Martin Waitza6d3fe72006-01-09 20:53:55 -08002327 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 {
Randy Dunlapced69092008-12-01 13:14:03 -08002329 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2330 $parameterdescs{$param} = "variable arguments";
2331 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332 }
2333 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2334 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 $param="void";
2336 $parameterdescs{void} = "no arguments";
2337 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002338 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2339 # handle unnamed (anonymous) union or struct:
2340 {
2341 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002342 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002343 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002344 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002345 }
2346
Martin Waitza6d3fe72006-01-09 20:53:55 -08002347 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002348 # (but ignore ones starting with # as these are not parameters
2349 # but inline preprocessor statements);
2350 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002351 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002352 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2353
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 $parameterdescs{$param_name} = $undescribed;
2355
2356 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002357 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 "or member '$param' not " .
2359 "described in '$declaration_name'\n";
2360 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002361 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002362 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002364 }
2365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002367 $param = xml_escape($param);
2368
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002369 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002370 # on @parameterlist;
2371 # this fixes a problem where check_sections() cannot find
2372 # a parameter like "addr[6 + 2]" because it actually appears
2373 # as "addr[6", "+", "2]" on the parameter list;
2374 # but it's better to maintain the param string unchanged for output,
2375 # so just weaken the string compare in check_sections() to ignore
2376 # "[blah" in a parameter string;
2377 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 push @parameterlist, $param;
2379 $parametertypes{$param} = $type;
2380}
2381
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002382sub check_sections($$$$$$) {
2383 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2384 my @sects = split ' ', $sectcheck;
2385 my @prms = split ' ', $prmscheck;
2386 my $err;
2387 my ($px, $sx);
2388 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2389
2390 foreach $sx (0 .. $#sects) {
2391 $err = 1;
2392 foreach $px (0 .. $#prms) {
2393 $prm_clean = $prms[$px];
2394 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002395 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002396 # ignore array size in a parameter string;
2397 # however, the original param string may contain
2398 # spaces, e.g.: addr[6 + 2]
2399 # and this appears in @prms as "addr[6" since the
2400 # parameter list is split at spaces;
2401 # hence just ignore "[..." for the sections check;
2402 $prm_clean =~ s/\[.*//;
2403
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002404 ##$prm_clean =~ s/^\**//;
2405 if ($prm_clean eq $sects[$sx]) {
2406 $err = 0;
2407 last;
2408 }
2409 }
2410 if ($err) {
2411 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002412 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002413 "Excess function parameter " .
2414 "'$sects[$sx]' " .
2415 "description in '$decl_name'\n";
2416 ++$warnings;
2417 } else {
2418 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002419 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002420 "Excess struct/union/enum/typedef member " .
2421 "'$sects[$sx]' " .
2422 "description in '$decl_name'\n";
2423 ++$warnings;
2424 }
2425 }
2426 }
2427 }
2428}
2429
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002431# Checks the section describing the return value of a function.
2432sub check_return_section {
2433 my $file = shift;
2434 my $declaration_name = shift;
2435 my $return_type = shift;
2436
2437 # Ignore an empty return type (It's a macro)
2438 # Ignore functions with a "void" return type. (But don't ignore "void *")
2439 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2440 return;
2441 }
2442
2443 if (!defined($sections{$section_return}) ||
2444 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002445 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002446 "No description found for return value of " .
2447 "'$declaration_name'\n";
2448 ++$warnings;
2449 }
2450}
2451
2452##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453# takes a function prototype and the name of the current file being
2454# processed and spits out all the details stored in the global
2455# arrays/hashes.
2456sub dump_function($$) {
2457 my $prototype = shift;
2458 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002459 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460
2461 $prototype =~ s/^static +//;
2462 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002463 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 $prototype =~ s/^inline +//;
2465 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002466 $prototype =~ s/^__inline +//;
2467 $prototype =~ s/^__always_inline +//;
2468 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002469 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002470 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002471 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002472 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002473 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002474 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002475 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476
2477 # Yes, this truly is vile. We are looking for:
2478 # 1. Return type (may be nothing if we're looking at a macro)
2479 # 2. Function name
2480 # 3. Function parameters.
2481 #
2482 # All the while we have to watch out for function pointer parameters
2483 # (which IIRC is what the two sections are for), C types (these
2484 # regexps don't even start to express all the possibilities), and
2485 # so on.
2486 #
2487 # If you mess with these regexps, it's a good idea to check that
2488 # the following functions' documentation still comes out right:
2489 # - parport_register_device (function pointer parameters)
2490 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002491 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002493 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2494 # This is an object-like macro, it has no return type and no parameter
2495 # list.
2496 # Function-like macros are not allowed to have spaces between
2497 # declaration_name and opening parenthesis (notice the \s+).
2498 $return_type = $1;
2499 $declaration_name = $2;
2500 $noret = 1;
2501 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2503 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2504 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002505 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2507 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2508 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2509 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2510 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2511 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2512 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2513 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002514 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2515 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002516 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2517 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 $return_type = $1;
2519 $declaration_name = $2;
2520 my $args = $3;
2521
2522 create_parameterlist($args, ',', $file);
2523 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002524 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 return;
2526 }
2527
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002528 my $prms = join " ", @parameterlist;
2529 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2530
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002531 # This check emits a lot of warnings at the moment, because many
2532 # functions don't have a 'Return' doc section. So until the number
2533 # of warnings goes sufficiently down, the check is only performed in
2534 # verbose mode.
2535 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002536 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002537 check_return_section($file, $declaration_name, $return_type);
2538 }
2539
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002540 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 'function',
2542 {'function' => $declaration_name,
2543 'module' => $modulename,
2544 'functiontype' => $return_type,
2545 'parameterlist' => \@parameterlist,
2546 'parameterdescs' => \%parameterdescs,
2547 'parametertypes' => \%parametertypes,
2548 'sectionlist' => \@sectionlist,
2549 'sections' => \%sections,
2550 'purpose' => $declaration_purpose
2551 });
2552}
2553
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554sub reset_state {
2555 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 %parameterdescs = ();
2557 %parametertypes = ();
2558 @parameterlist = ();
2559 %sections = ();
2560 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002561 $sectcheck = "";
2562 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002564
Jani Nikula48af6062016-05-26 14:56:05 +03002565 $state = STATE_NORMAL;
2566 $inline_doc_state = STATE_INLINE_NA;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567}
2568
Jason Baron56afb0f2009-04-30 13:29:36 -04002569sub tracepoint_munge($) {
2570 my $file = shift;
2571 my $tracepointname = 0;
2572 my $tracepointargs = 0;
2573
Jason Baron3a9089f2009-12-01 12:18:49 -05002574 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002575 $tracepointname = $1;
2576 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002577 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2578 $tracepointname = $1;
2579 }
2580 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2581 $tracepointname = $2;
2582 }
2583 $tracepointname =~ s/^\s+//; #strip leading whitespace
2584 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002585 $tracepointargs = $1;
2586 }
2587 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002588 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002589 "$prototype\n";
2590 } else {
2591 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2592 }
2593}
2594
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002595sub syscall_munge() {
2596 my $void = 0;
2597
2598 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2599## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2600 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2601 $void = 1;
2602## $prototype = "long sys_$1(void)";
2603 }
2604
2605 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2606 if ($prototype =~ m/long (sys_.*?),/) {
2607 $prototype =~ s/,/\(/;
2608 } elsif ($void) {
2609 $prototype =~ s/\)/\(void\)/;
2610 }
2611
2612 # now delete all of the odd-number commas in $prototype
2613 # so that arg types & arg names don't have a comma between them
2614 my $count = 0;
2615 my $len = length($prototype);
2616 if ($void) {
2617 $len = 0; # skip the for-loop
2618 }
2619 for (my $ix = 0; $ix < $len; $ix++) {
2620 if (substr($prototype, $ix, 1) eq ',') {
2621 $count++;
2622 if ($count % 2 == 1) {
2623 substr($prototype, $ix, 1) = ' ';
2624 }
2625 }
2626 }
2627}
2628
Daniel Vetterb7afa922016-06-01 23:46:24 +02002629sub process_proto_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 my $x = shift;
2631 my $file = shift;
2632
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002633 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2634
Randy Dunlap890c78c2008-10-25 17:06:43 -07002635 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 # do nothing
2637 }
2638 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002639 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002641
Randy Dunlap890c78c2008-10-25 17:06:43 -07002642 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002643 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2645 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002646 if ($prototype =~ /SYSCALL_DEFINE/) {
2647 syscall_munge();
2648 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002649 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2650 $prototype =~ /DEFINE_SINGLE_EVENT/)
2651 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002652 tracepoint_munge($file);
2653 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002654 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 reset_state();
2656 }
2657}
2658
Daniel Vetterb7afa922016-06-01 23:46:24 +02002659sub process_proto_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 my $x = shift;
2661 my $file = shift;
2662
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2664 $x =~ s@^\s+@@gos; # strip leading spaces
2665 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002666 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2667
Linus Torvalds1da177e2005-04-16 15:20:36 -07002668 if ($x =~ /^#/) {
2669 # To distinguish preprocessor directive from regular declaration later.
2670 $x .= ";";
2671 }
2672
2673 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002674 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 $prototype .= $1 . $2;
2676 ($2 eq '{') && $brcount++;
2677 ($2 eq '}') && $brcount--;
2678 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002679 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002681 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 }
2683 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002684 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 $prototype .= $x;
2686 last;
2687 }
2688 }
2689}
2690
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002691# xml_escape: replace <, >, and & in the text stream;
2692#
2693# however, formatting controls that are generated internally/locally in the
2694# kernel-doc script are not escaped here; instead, they begin life like
2695# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2696# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2697# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698sub xml_escape($) {
2699 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002700 if (($output_mode eq "text") || ($output_mode eq "man")) {
2701 return $text;
2702 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703 $text =~ s/\&/\\\\\\amp;/g;
2704 $text =~ s/\</\\\\\\lt;/g;
2705 $text =~ s/\>/\\\\\\gt;/g;
2706 return $text;
2707}
2708
Jonathan Corbetc0d1b6e2016-05-12 16:15:37 +03002709# xml_unescape: reverse the effects of xml_escape
2710sub xml_unescape($) {
2711 my $text = shift;
2712 if (($output_mode eq "text") || ($output_mode eq "man")) {
2713 return $text;
2714 }
2715 $text =~ s/\\\\\\amp;/\&/g;
2716 $text =~ s/\\\\\\lt;/</g;
2717 $text =~ s/\\\\\\gt;/>/g;
2718 return $text;
2719}
2720
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002721# convert local escape strings to html
2722# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2723sub local_unescape($) {
2724 my $text = shift;
2725 if (($output_mode eq "text") || ($output_mode eq "man")) {
2726 return $text;
2727 }
2728 $text =~ s/\\\\\\\\lt:/</g;
2729 $text =~ s/\\\\\\\\gt:/>/g;
2730 return $text;
2731}
2732
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002734 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 my $identifier;
2736 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002737 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002738 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002740 my ($orig_file) = @_;
Jani Nikulab7886de2016-05-28 00:41:50 +03002741 my $leading_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742
Randy Dunlap2283a112005-07-07 15:39:26 -07002743 if (defined($ENV{'SRCTREE'})) {
Ben Hutchings68f86662015-09-01 23:48:49 +01002744 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002745 }
2746 else {
Ben Hutchings68f86662015-09-01 23:48:49 +01002747 $file = $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002748 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 if (defined($source_map{$file})) {
2750 $file = $source_map{$file};
2751 }
2752
2753 if (!open(IN,"<$file")) {
2754 print STDERR "Error: Cannot open file $file\n";
2755 ++$errors;
2756 return;
2757 }
2758
Jani Nikula86ae2e32016-01-21 13:05:22 +02002759 # two passes for -export and -internal
Jani Nikulab6c3f452016-05-29 22:19:35 +03002760 if ($output_selection == OUTPUT_EXPORTED ||
2761 $output_selection == OUTPUT_INTERNAL) {
Jani Nikula86ae2e32016-01-21 13:05:22 +02002762 while (<IN>) {
2763 if (/$export_symbol/o) {
2764 $function_table{$2} = 1;
2765 }
2766 }
2767 seek(IN, 0, 0);
2768 }
2769
Ilya Dryomova9e73142010-02-26 13:05:47 -08002770 $. = 1;
2771
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 $section_counter = 0;
2773 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002774 while (s/\\\s*$//) {
2775 $_ .= <IN>;
2776 }
Jani Nikula48af6062016-05-26 14:56:05 +03002777 if ($state == STATE_NORMAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 if (/$doc_start/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002779 $state = STATE_NAME; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002780 $in_doc_sect = 0;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002781 $declaration_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 }
Jani Nikula48af6062016-05-26 14:56:05 +03002783 } elsif ($state == STATE_NAME) {# this line is the function name (always)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 if (/$doc_block/o) {
Jani Nikula48af6062016-05-26 14:56:05 +03002785 $state = STATE_DOCBLOCK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002787 $new_start_line = $. + 1;
2788
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 if ( $1 eq "" ) {
2790 $section = $section_intro;
2791 } else {
2792 $section = $1;
2793 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002794 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 elsif (/$doc_decl/o) {
2796 $identifier = $1;
2797 if (/\s*([\w\s]+?)\s*-/) {
2798 $identifier = $1;
2799 }
2800
Jani Nikula48af6062016-05-26 14:56:05 +03002801 $state = STATE_FIELD;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002802 # if there's no @param blocks need to set up default section
2803 # here
Jani Nikula2f4ad402016-05-30 11:21:06 +03002804 $contents = "";
2805 $section = $section_default;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002806 $new_start_line = $. + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002808 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002809 $descr= $1;
2810 $descr =~ s/^\s*//;
2811 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002812 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002813 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002814 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 } else {
2816 $declaration_purpose = "";
2817 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002818
2819 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002820 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002821 print STDERR $_;
2822 ++$warnings;
2823 }
2824
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 if ($identifier =~ m/^struct/) {
2826 $decl_type = 'struct';
2827 } elsif ($identifier =~ m/^union/) {
2828 $decl_type = 'union';
2829 } elsif ($identifier =~ m/^enum/) {
2830 $decl_type = 'enum';
2831 } elsif ($identifier =~ m/^typedef/) {
2832 $decl_type = 'typedef';
2833 } else {
2834 $decl_type = 'function';
2835 }
2836
2837 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002838 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 }
2840 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002841 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 " - I thought it was a doc line\n";
2843 ++$warnings;
Jani Nikula48af6062016-05-26 14:56:05 +03002844 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 }
Jani Nikula48af6062016-05-26 14:56:05 +03002846 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content
Jani Nikulaf624ade2016-05-29 11:35:28 +03002847 if (/$doc_sect/i) { # case insensitive for supported section names
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 $newsection = $1;
2849 $newcontents = $2;
2850
Jani Nikulaf624ade2016-05-29 11:35:28 +03002851 # map the supported section names to the canonical names
2852 if ($newsection =~ m/^description$/i) {
2853 $newsection = $section_default;
2854 } elsif ($newsection =~ m/^context$/i) {
2855 $newsection = $section_context;
2856 } elsif ($newsection =~ m/^returns?$/i) {
2857 $newsection = $section_return;
2858 } elsif ($newsection =~ m/^\@return$/) {
2859 # special: @return is a section, not a param description
2860 $newsection = $section_return;
2861 }
2862
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002863 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002864 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002865 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002866 ++$warnings;
2867 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002868 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 $section = $section_default;
2870 }
2871
Randy Dunlap850622d2006-06-25 05:48:55 -07002872 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002873 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 $contents = $newcontents;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002875 $new_start_line = $.;
Jani Nikula0a726302016-05-28 14:50:20 +03002876 while ((substr($contents, 0, 1) eq " ") ||
2877 substr($contents, 0, 1) eq "\t") {
2878 $contents = substr($contents, 1);
2879 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002880 if ($contents ne "") {
2881 $contents .= "\n";
2882 }
2883 $section = $newsection;
Jani Nikulab7886de2016-05-28 00:41:50 +03002884 $leading_space = undef;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002886 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002887 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 $section = $section_default;
2889 $contents = "";
2890 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002891 # look for doc_com + <text> + doc_end:
2892 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002893 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002894 ++$warnings;
2895 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896
2897 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002898 $state = STATE_PROTO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002900# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901 } elsif (/$doc_content/) {
2902 # miguel-style comment kludge, look for blank lines after
2903 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002904 if ($1 eq "") {
2905 if ($section =~ m/^@/ || $section eq $section_context) {
2906 dump_section($file, $section, xml_escape($contents));
2907 $section = $section_default;
2908 $contents = "";
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002909 $new_start_line = $.;
Johannes Weiner64231332009-09-17 19:26:53 -07002910 } else {
2911 $contents .= "\n";
2912 }
2913 $in_purpose = 0;
2914 } elsif ($in_purpose == 1) {
2915 # Continued declaration purpose
2916 chomp($declaration_purpose);
2917 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002918 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 } else {
Jani Nikulab7886de2016-05-28 00:41:50 +03002920 my $cont = $1;
2921 if ($section =~ m/^@/ || $section eq $section_context) {
2922 if (!defined $leading_space) {
2923 if ($cont =~ m/^(\s+)/) {
2924 $leading_space = $1;
2925 } else {
2926 $leading_space = "";
2927 }
2928 }
2929
2930 $cont =~ s/^$leading_space//;
2931 }
2932 $contents .= $cont . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 }
2934 } else {
2935 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002936 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 ++$warnings;
2938 }
Jani Nikula48af6062016-05-26 14:56:05 +03002939 } elsif ($state == STATE_INLINE) { # scanning for inline parameters
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002940 # First line (state 1) needs to be a @parameter
Jani Nikula48af6062016-05-26 14:56:05 +03002941 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002942 $section = $1;
2943 $contents = $2;
Daniel Vetter0b0f5f292016-06-03 22:21:34 +02002944 $new_start_line = $.;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002945 if ($contents ne "") {
2946 while ((substr($contents, 0, 1) eq " ") ||
2947 substr($contents, 0, 1) eq "\t") {
2948 $contents = substr($contents, 1);
2949 }
Jani Nikulaa0b96c22016-05-26 22:04:06 +03002950 $contents .= "\n";
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002951 }
Jani Nikula48af6062016-05-26 14:56:05 +03002952 $inline_doc_state = STATE_INLINE_TEXT;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002953 # Documentation block end */
Jani Nikula48af6062016-05-26 14:56:05 +03002954 } elsif (/$doc_inline_end/) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002955 if (($contents ne "") && ($contents ne "\n")) {
2956 dump_section($file, $section, xml_escape($contents));
2957 $section = $section_default;
2958 $contents = "";
2959 }
Jani Nikula48af6062016-05-26 14:56:05 +03002960 $state = STATE_PROTO;
2961 $inline_doc_state = STATE_INLINE_NA;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002962 # Regular text
2963 } elsif (/$doc_content/) {
Jani Nikula48af6062016-05-26 14:56:05 +03002964 if ($inline_doc_state == STATE_INLINE_TEXT) {
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002965 $contents .= $1 . "\n";
Jani Nikula6450c892016-05-26 22:04:42 +03002966 # nuke leading blank lines
2967 if ($contents =~ /^\s*$/) {
2968 $contents = "";
2969 }
Jani Nikula48af6062016-05-26 14:56:05 +03002970 } elsif ($inline_doc_state == STATE_INLINE_NAME) {
2971 $inline_doc_state = STATE_INLINE_ERROR;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002972 print STDERR "Warning(${file}:$.): ";
2973 print STDERR "Incorrect use of kernel-doc format: $_";
2974 ++$warnings;
2975 }
2976 }
Jani Nikula48af6062016-05-26 14:56:05 +03002977 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype)
2978 if (/$doc_inline_start/) {
2979 $state = STATE_INLINE;
2980 $inline_doc_state = STATE_INLINE_NAME;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002981 } elsif ($decl_type eq 'function') {
Daniel Vetterb7afa922016-06-01 23:46:24 +02002982 process_proto_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 } else {
Daniel Vetterb7afa922016-06-01 23:46:24 +02002984 process_proto_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 }
Jani Nikula48af6062016-05-26 14:56:05 +03002986 } elsif ($state == STATE_DOCBLOCK) {
Daniel Vetterebff7f92016-06-01 23:46:23 +02002987 if (/$doc_end/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002989 dump_doc_section($file, $section, xml_escape($contents));
Jani Nikula2f4ad402016-05-30 11:21:06 +03002990 $section = $section_default;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 $contents = "";
2992 $function = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 %parameterdescs = ();
2994 %parametertypes = ();
2995 @parameterlist = ();
2996 %sections = ();
2997 @sectionlist = ();
2998 $prototype = "";
Jani Nikula48af6062016-05-26 14:56:05 +03002999 $state = STATE_NORMAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 }
3001 elsif (/$doc_content/)
3002 {
3003 if ( $1 eq "" )
3004 {
3005 $contents .= $blankline;
3006 }
3007 else
3008 {
3009 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08003010 }
Randy Dunlap3c308792007-05-08 00:24:39 -07003011 }
3012 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 }
3014 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07003015 print STDERR "${file}:1: warning: no structured comments found\n";
Jani Nikulab6c3f452016-05-29 22:19:35 +03003016 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) {
Johannes Berge946c43a2013-11-12 15:11:12 -08003017 print STDERR " Was looking for '$_'.\n" for keys %function_table;
3018 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 if ($output_mode eq "xml") {
3020 # The template wants at least one RefEntry here; make one.
3021 print "<refentry>\n";
3022 print " <refnamediv>\n";
3023 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003024 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 print " </refname>\n";
3026 print " <refpurpose>\n";
3027 print " Document generation inconsistency\n";
3028 print " </refpurpose>\n";
3029 print " </refnamediv>\n";
3030 print " <refsect1>\n";
3031 print " <title>\n";
3032 print " Oops\n";
3033 print " </title>\n";
3034 print " <warning>\n";
3035 print " <para>\n";
3036 print " The template for this document tried to insert\n";
3037 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01003038 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 print " but none was found.\n";
3040 print " This dummy section is inserted to allow\n";
3041 print " generation to continue.\n";
3042 print " </para>\n";
3043 print " </warning>\n";
3044 print " </refsect1>\n";
3045 print "</refentry>\n";
3046 }
3047 }
3048}
Randy Dunlap8484baa2011-01-05 16:28:43 -08003049
3050
3051$kernelversion = get_kernel_version();
3052
3053# generate a sequence of code that will splice in highlighting information
3054# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02003055for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03003056 my $pattern = $highlights[$k][0];
3057 my $result = $highlights[$k][1];
3058# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
3059 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08003060}
3061
3062# Read the file that maps relative names to absolute names for
3063# separate source and object directories and for shadow trees.
3064if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
3065 my ($relname, $absname);
3066 while(<SOURCE_MAP>) {
3067 chop();
3068 ($relname, $absname) = (split())[0..1];
3069 $relname =~ s:^/+::;
3070 $source_map{$relname} = $absname;
3071 }
3072 close(SOURCE_MAP);
3073}
3074
3075foreach (@ARGV) {
3076 chomp;
3077 process_file($_);
3078}
3079if ($verbose && $errors) {
3080 print STDERR "$errors errors\n";
3081}
3082if ($verbose && $warnings) {
3083 print STDERR "$warnings warnings\n";
3084}
3085
3086exit($errors);