blob: 29fd5cabb6576a2cfd2b028704f6a5d3842353cc [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.
58 -text Output plain text format.
59
60Output selection (mutually exclusive):
61 -function NAME Only output documentation for the given function(s)
62 or DOC: section title(s). All other functions and DOC:
63 sections are ignored. May be specified multiple times.
64 -nofunction NAME Do NOT output documentation for the given function(s);
65 only output documentation for the other functions and
66 DOC: sections. May be specified multiple times.
67
68Output selection modifiers:
69 -no-doc-sections Do not output DOC: sections.
70
71Other parameters:
72 -v Verbose output, more warnings and other information.
73 -h Print this help.
74
75EOF
76 print $message;
77 exit 1;
78}
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
80#
81# format of comments.
82# In the following table, (...)? signifies optional structure.
83# (...)* signifies 0 or more structure elements
84# /**
85# * function_name(:)? (- short description)?
86# (* @parameterx: (description of parameter x)?)*
87# (* a blank line)?
88# * (Description:)? (Description of function)?
89# * (section header: (section description)? )*
90# (*)?*/
91#
92# So .. the trivial example would be:
93#
94# /**
95# * my_function
Randy Dunlapb9d973282009-06-09 08:50:38 -070096# */
Linus Torvalds1da177e2005-04-16 15:20:36 -070097#
Randy Dunlap891dcd22007-02-10 01:45:53 -080098# If the Description: header tag is omitted, then there must be a blank line
Linus Torvalds1da177e2005-04-16 15:20:36 -070099# after the last parameter specification.
100# e.g.
101# /**
102# * my_function - does my stuff
103# * @my_arg: its mine damnit
104# *
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800105# * Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106# */
107#
108# or, could also use:
109# /**
110# * my_function - does my stuff
111# * @my_arg: its mine damnit
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800112# * Description: Does my stuff explained.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113# */
114# etc.
115#
Randy Dunlapb9d973282009-06-09 08:50:38 -0700116# Besides functions you can also write documentation for structs, unions,
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800117# enums and typedefs. Instead of the function name you must write the name
118# of the declaration; the struct/union/enum/typedef must always precede
119# the name. Nesting of declarations is not supported.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120# Use the argument mechanism to document members or constants.
121# e.g.
122# /**
123# * struct my_struct - short description
124# * @a: first member
125# * @b: second member
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800126# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127# * Longer description
128# */
129# struct my_struct {
130# int a;
131# int b;
Martin Waitzaeec46b2005-11-13 16:08:13 -0800132# /* private: */
133# int c;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134# };
135#
136# All descriptions can be multiline, except the short function description.
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800137#
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300138# For really longs structs, you can also describe arguments inside the
139# body of the struct.
140# eg.
141# /**
142# * struct my_struct - short description
143# * @a: first member
144# * @b: second member
145# *
146# * Longer description
147# */
148# struct my_struct {
149# int a;
150# int b;
151# /**
152# * @c: This is longer description of C
153# *
154# * You can use paragraphs to describe arguments
155# * using this method.
156# */
157# int c;
158# };
159#
160# This should be use only for struct/enum members.
161#
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800162# You can also add additional sections. When documenting kernel functions you
163# should document the "Context:" of the function, e.g. whether the functions
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164# can be called form interrupts. Unlike other sections you can end it with an
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800165# empty line.
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100166# A non-void function should have a "Return:" section describing the return
167# value(s).
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800168# Example-sections should contain the string EXAMPLE so that they are marked
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169# appropriately in DocBook.
170#
171# Example:
172# /**
173# * user_function - function that can only be called in user context
174# * @a: some argument
175# * Context: !in_interrupt()
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800176# *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177# * Some description
178# * Example:
179# * user_function(22);
180# */
181# ...
182#
183#
184# All descriptive text is further processed, scanning for the following special
185# patterns, which are highlighted appropriately.
186#
187# 'funcname()' - function
188# '$ENVVAR' - environmental variable
189# '&struct_name' - name of a structure (up to two words including 'struct')
190# '@parameter' - name of a parameter
191# '%CONST' - name of a constant.
192
Randy Dunlap8484baa2011-01-05 16:28:43 -0800193## init lots of data
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195my $errors = 0;
196my $warnings = 0;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -0700197my $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
199# match expressions used to find embedded type information
200my $type_constant = '\%([-_\w]+)';
201my $type_func = '(\w+)\(\)';
202my $type_param = '\@(\w+)';
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700203my $type_struct = '\&((struct\s*)*[_\w]+)';
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700204my $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205my $type_env = '(\$\w+)';
206
207# Output conversion substitutions.
208# One for each output format
209
210# these work fairly well
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300211my @highlights_html = (
212 [$type_constant, "<i>\$1</i>"],
213 [$type_func, "<b>\$1</b>"],
214 [$type_struct_xml, "<i>\$1</i>"],
215 [$type_env, "<b><i>\$1</i></b>"],
216 [$type_param, "<tt><b>\$1</b></tt>"]
217 );
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700218my $local_lt = "\\\\\\\\lt:";
219my $local_gt = "\\\\\\\\gt:";
220my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Dan Luedtke1b40c192012-08-12 10:46:15 +0200222# html version 5
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300223my @highlights_html5 = (
224 [$type_constant, "<span class=\"const\">\$1</span>"],
225 [$type_func, "<span class=\"func\">\$1</span>"],
226 [$type_struct_xml, "<span class=\"struct\">\$1</span>"],
227 [$type_env, "<span class=\"env\">\$1</span>"],
228 [$type_param, "<span class=\"param\">\$1</span>]"]
229 );
Dan Luedtke1b40c192012-08-12 10:46:15 +0200230my $blankline_html5 = $local_lt . "br /" . $local_gt;
231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232# XML, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300233my @highlights_xml = (
234 ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
235 [$type_constant, "<constant>\$1</constant>"],
236 [$type_struct_xml, "<structname>\$1</structname>"],
237 [$type_param, "<parameter>\$1</parameter>"],
238 [$type_func, "<function>\$1</function>"],
239 [$type_env, "<envar>\$1</envar>"]
240 );
Johannes Berg5c98fc02007-10-24 15:08:48 -0700241my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
243# gnome, docbook format
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300244my @highlights_gnome = (
245 [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
246 [$type_func, "<function>\$1</function>"],
247 [$type_struct, "<structname>\$1</structname>"],
248 [$type_env, "<envar>\$1</envar>"],
249 [$type_param, "<parameter>\$1</parameter>" ]
250 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251my $blankline_gnome = "</para><para>\n";
252
253# these are pretty rough
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300254my @highlights_man = (
255 [$type_constant, "\$1"],
256 [$type_func, "\\\\fB\$1\\\\fP"],
257 [$type_struct, "\\\\fI\$1\\\\fP"],
258 [$type_param, "\\\\fI\$1\\\\fP"]
259 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260my $blankline_man = "";
261
262# text-mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300263my @highlights_text = (
264 [$type_constant, "\$1"],
265 [$type_func, "\$1"],
266 [$type_struct, "\$1"],
267 [$type_param, "\$1"]
268 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269my $blankline_text = "";
270
Johannes Bergeda603f2010-09-11 15:55:22 -0700271# list mode
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300272my @highlights_list = (
273 [$type_constant, "\$1"],
274 [$type_func, "\$1"],
275 [$type_struct, "\$1"],
276 [$type_param, "\$1"]
277 );
Johannes Bergeda603f2010-09-11 15:55:22 -0700278my $blankline_list = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280# read arguments
Randy Dunlapb9d973282009-06-09 08:50:38 -0700281if ($#ARGV == -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 usage();
283}
284
Randy Dunlap8484baa2011-01-05 16:28:43 -0800285my $kernelversion;
286my $dohighlight = "";
287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288my $verbose = 0;
289my $output_mode = "man";
Daniel Santose314ba32012-10-04 17:15:08 -0700290my $output_preformatted = 0;
Johannes Berg4b445952007-10-24 15:08:48 -0700291my $no_doc_sections = 0;
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300292my @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293my $blankline = $blankline_man;
294my $modulename = "Kernel API";
295my $function_only = 0;
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100296my $show_not_found = 0;
297
298my @build_time;
299if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
300 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
301 @build_time = gmtime($seconds);
302} else {
303 @build_time = localtime;
304}
305
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800306my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
307 'July', 'August', 'September', 'October',
Ben Hutchingsb2c41052015-07-08 20:07:16 +0100308 'November', 'December')[$build_time[4]] .
309 " " . ($build_time[5]+1900);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Randy Dunlap8484baa2011-01-05 16:28:43 -0800311# Essentially these are globals.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700312# They probably want to be tidied up, made more localised or something.
313# CAVEAT EMPTOR! Some of the others I localised may not want to be, which
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314# could cause "use of undefined value" or other bugs.
Randy Dunlapb9d973282009-06-09 08:50:38 -0700315my ($function, %function_table, %parametertypes, $declaration_purpose);
316my ($type, $declaration_name, $return_type);
Ilya Dryomov1c32fd02010-02-26 13:06:03 -0800317my ($newsection, $newcontents, $prototype, $brcount, %source_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Randy Dunlapbd0e88e2008-03-13 12:32:43 -0700319if (defined($ENV{'KBUILD_VERBOSE'})) {
320 $verbose = "$ENV{'KBUILD_VERBOSE'}";
321}
322
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800323# Generated docbook code is inserted in a template at a point where
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
325# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
326# We keep track of number of generated entries and generate a dummy
327# if needs be to ensure the expanded template can be postprocessed
328# into html.
329my $section_counter = 0;
330
331my $lineprefix="";
332
333# states
334# 0 - normal code
335# 1 - looking for function name
336# 2 - scanning field start.
337# 3 - scanning prototype.
338# 4 - documentation block
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300339# 5 - gathering documentation outside main block
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340my $state;
Randy Dunlap850622d2006-06-25 05:48:55 -0700341my $in_doc_sect;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300343# Split Doc State
344# 0 - Invalid (Before start or after finish)
345# 1 - Is started (the /** was found inside a struct)
346# 2 - The @parameter header was found, start accepting multi paragraph text.
347# 3 - Finished (the */ was found)
348# 4 - Error - Comment without header was found. Spit a warning as it's not
349# proper kernel-doc and ignore the rest.
350my $split_doc_state;
351
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352#declaration types: can be
353# 'function', 'struct', 'union', 'enum', 'typedef'
354my $decl_type;
355
356my $doc_special = "\@\%\$\&";
357
358my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
359my $doc_end = '\*/';
360my $doc_com = '\s*\*\s*';
Daniel Santos12ae6772012-10-04 17:15:10 -0700361my $doc_com_body = '\s*\* ?';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700362my $doc_decl = $doc_com . '(\w+)';
363my $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
Daniel Santos12ae6772012-10-04 17:15:10 -0700364my $doc_content = $doc_com_body . '(.*)';
Randy Dunlapb9d973282009-06-09 08:50:38 -0700365my $doc_block = $doc_com . 'DOC:\s*(.*)?';
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -0300366my $doc_split_start = '^\s*/\*\*\s*$';
367my $doc_split_sect = '\s*\*\s*(@[\w\s]+):(.*)';
368my $doc_split_end = '^\s*\*/\s*$';
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
370my %constants;
371my %parameterdescs;
372my @parameterlist;
373my %sections;
374my @sectionlist;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800375my $sectcheck;
376my $struct_actual;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378my $contents = "";
379my $section_default = "Description"; # default section
380my $section_intro = "Introduction";
381my $section = $section_default;
382my $section_context = "Context";
Yacine Belkadi4092bac2012-11-26 22:22:27 +0100383my $section_return = "Return";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
385my $undescribed = "-- undescribed --";
386
387reset_state();
388
389while ($ARGV[0] =~ m/^-(.*)/) {
390 my $cmd = shift @ARGV;
391 if ($cmd eq "-html") {
392 $output_mode = "html";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300393 @highlights = @highlights_html;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 $blankline = $blankline_html;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200395 } elsif ($cmd eq "-html5") {
396 $output_mode = "html5";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300397 @highlights = @highlights_html5;
Dan Luedtke1b40c192012-08-12 10:46:15 +0200398 $blankline = $blankline_html5;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 } elsif ($cmd eq "-man") {
400 $output_mode = "man";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300401 @highlights = @highlights_man;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 $blankline = $blankline_man;
403 } elsif ($cmd eq "-text") {
404 $output_mode = "text";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300405 @highlights = @highlights_text;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 $blankline = $blankline_text;
407 } elsif ($cmd eq "-docbook") {
408 $output_mode = "xml";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300409 @highlights = @highlights_xml;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 $blankline = $blankline_xml;
Johannes Bergeda603f2010-09-11 15:55:22 -0700411 } elsif ($cmd eq "-list") {
412 $output_mode = "list";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300413 @highlights = @highlights_list;
Johannes Bergeda603f2010-09-11 15:55:22 -0700414 $blankline = $blankline_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 } elsif ($cmd eq "-gnome") {
416 $output_mode = "gnome";
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -0300417 @highlights = @highlights_gnome;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 $blankline = $blankline_gnome;
419 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
420 $modulename = shift @ARGV;
421 } elsif ($cmd eq "-function") { # to only output specific functions
422 $function_only = 1;
423 $function = shift @ARGV;
424 $function_table{$function} = 1;
425 } elsif ($cmd eq "-nofunction") { # to only output specific functions
426 $function_only = 2;
427 $function = shift @ARGV;
428 $function_table{$function} = 1;
429 } elsif ($cmd eq "-v") {
430 $verbose = 1;
431 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
432 usage();
Johannes Berg4b445952007-10-24 15:08:48 -0700433 } elsif ($cmd eq '-no-doc-sections') {
434 $no_doc_sections = 1;
Johannes Berge946c43a2013-11-12 15:11:12 -0800435 } elsif ($cmd eq '-show-not-found') {
436 $show_not_found = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 }
438}
439
Randy Dunlap8484baa2011-01-05 16:28:43 -0800440# continue execution near EOF;
441
Borislav Petkov53f049f2007-05-08 00:30:54 -0700442# get kernel version from env
443sub get_kernel_version() {
Johannes Berg1b9bc222007-10-24 15:08:48 -0700444 my $version = 'unknown kernel version';
Borislav Petkov53f049f2007-05-08 00:30:54 -0700445
446 if (defined($ENV{'KERNELVERSION'})) {
447 $version = $ENV{'KERNELVERSION'};
448 }
449 return $version;
450}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452##
453# dumps section contents to arrays/hashes intended for that purpose.
454#
455sub dump_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700456 my $file = shift;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 my $name = shift;
458 my $contents = join "\n", @_;
459
460 if ($name =~ m/$type_constant/) {
461 $name = $1;
462# print STDERR "constant section '$1' = '$contents'\n";
463 $constants{$name} = $contents;
464 } elsif ($name =~ m/$type_param/) {
465# print STDERR "parameter def '$1' = '$contents'\n";
466 $name = $1;
467 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800468 $sectcheck = $sectcheck . $name . " ";
Randy Dunlapced69092008-12-01 13:14:03 -0800469 } elsif ($name eq "@\.\.\.") {
470# print STDERR "parameter def '...' = '$contents'\n";
471 $name = "...";
472 $parameterdescs{$name} = $contents;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -0800473 $sectcheck = $sectcheck . $name . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 } else {
475# print STDERR "other section '$name' = '$contents'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700476 if (defined($sections{$name}) && ($sections{$name} ne "")) {
Bart Van Assched40e1e62015-09-04 15:43:21 -0700477 print STDERR "${file}:$.: error: duplicate section name '$name'\n";
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700478 ++$errors;
479 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 $sections{$name} = $contents;
481 push @sectionlist, $name;
482 }
483}
484
485##
Johannes Bergb112e0f2007-10-24 15:08:48 -0700486# dump DOC: section after checking that it should go out
487#
488sub dump_doc_section {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700489 my $file = shift;
Johannes Bergb112e0f2007-10-24 15:08:48 -0700490 my $name = shift;
491 my $contents = join "\n", @_;
492
Johannes Berg4b445952007-10-24 15:08:48 -0700493 if ($no_doc_sections) {
494 return;
495 }
496
Johannes Bergb112e0f2007-10-24 15:08:48 -0700497 if (($function_only == 0) ||
498 ( $function_only == 1 && defined($function_table{$name})) ||
499 ( $function_only == 2 && !defined($function_table{$name})))
500 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -0700501 dump_section($file, $name, $contents);
Johannes Bergb112e0f2007-10-24 15:08:48 -0700502 output_blockhead({'sectionlist' => \@sectionlist,
503 'sections' => \%sections,
504 'module' => $modulename,
505 'content-only' => ($function_only != 0), });
506 }
507}
508
509##
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510# output function
511#
512# parameterdescs, a hash.
513# function => "function name"
514# parameterlist => @list of parameters
515# parameterdescs => %parameter descriptions
516# sectionlist => @list of sections
Randy Dunlapa21217d2007-02-10 01:46:04 -0800517# sections => %section descriptions
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800518#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519
520sub output_highlight {
521 my $contents = join "\n",@_;
522 my $line;
523
524# DEBUG
525# if (!defined $contents) {
526# use Carp;
527# confess "output_highlight got called with no args?\n";
528# }
529
Dan Luedtke1b40c192012-08-12 10:46:15 +0200530 if ($output_mode eq "html" || $output_mode eq "html5" ||
531 $output_mode eq "xml") {
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700532 $contents = local_unescape($contents);
533 # convert data read & converted thru xml_escape() into &xyz; format:
Randy Dunlap2b35f4d2010-11-18 12:27:31 -0800534 $contents =~ s/\\\\\\/\&/g;
Randy Dunlap6b5b55f2007-10-16 23:31:20 -0700535 }
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700536# print STDERR "contents b4:$contents\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 eval $dohighlight;
538 die $@ if $@;
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700539# print STDERR "contents af:$contents\n";
540
Dan Luedtke1b40c192012-08-12 10:46:15 +0200541# strip whitespaces when generating html5
542 if ($output_mode eq "html5") {
543 $contents =~ s/^\s+//;
544 $contents =~ s/\s+$//;
545 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 foreach $line (split "\n", $contents) {
Daniel Santos12ae6772012-10-04 17:15:10 -0700547 if (! $output_preformatted) {
548 $line =~ s/^\s*//;
549 }
Randy Dunlap3c308792007-05-08 00:24:39 -0700550 if ($line eq ""){
Daniel Santose314ba32012-10-04 17:15:08 -0700551 if (! $output_preformatted) {
552 print $lineprefix, local_unescape($blankline);
553 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -0700555 $line =~ s/\\\\\\/\&/g;
Randy Dunlapcdccb312007-07-19 01:48:25 -0700556 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
557 print "\\&$line";
558 } else {
559 print $lineprefix, $line;
560 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 }
562 print "\n";
563 }
564}
565
Dan Luedtke1b40c192012-08-12 10:46:15 +0200566# output sections in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567sub output_section_html(%) {
568 my %args = %{$_[0]};
569 my $section;
570
571 foreach $section (@{$args{'sectionlist'}}) {
572 print "<h3>$section</h3>\n";
573 print "<blockquote>\n";
574 output_highlight($args{'sections'}{$section});
575 print "</blockquote>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800576 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577}
578
579# output enum in html
580sub output_enum_html(%) {
581 my %args = %{$_[0]};
582 my ($parameter);
583 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700584 print "<h2>enum " . $args{'enum'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Randy Dunlapb9d973282009-06-09 08:50:38 -0700586 print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 $count = 0;
588 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700589 print " <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 if ($count != $#{$args{'parameterlist'}}) {
591 $count++;
592 print ",\n";
593 }
594 print "<br>";
595 }
596 print "};<br>\n";
597
598 print "<h3>Constants</h3>\n";
599 print "<dl>\n";
600 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700601 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 print "<dd>";
603 output_highlight($args{'parameterdescs'}{$parameter});
604 }
605 print "</dl>\n";
606 output_section_html(@_);
607 print "<hr>\n";
608}
609
Randy Dunlapd28bee02006-02-01 03:06:57 -0800610# output typedef in html
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611sub output_typedef_html(%) {
612 my %args = %{$_[0]};
613 my ($parameter);
614 my $count;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700615 print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Randy Dunlapb9d973282009-06-09 08:50:38 -0700617 print "<b>typedef " . $args{'typedef'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 output_section_html(@_);
619 print "<hr>\n";
620}
621
622# output struct in html
623sub output_struct_html(%) {
624 my %args = %{$_[0]};
625 my ($parameter);
626
Randy Dunlapb9d973282009-06-09 08:50:38 -0700627 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
628 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 foreach $parameter (@{$args{'parameterlist'}}) {
630 if ($parameter =~ /^#/) {
631 print "$parameter<br>\n";
632 next;
633 }
634 my $parameter_name = $parameter;
635 $parameter_name =~ s/\[.*//;
636
Randy Dunlap3c308792007-05-08 00:24:39 -0700637 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 $type = $args{'parametertypes'}{$parameter};
639 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
640 # pointer-to-function
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700641 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700643 # bitfield
644 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 } else {
Randy Dunlap3eb014a2007-05-08 00:29:51 -0700646 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 }
648 }
649 print "};<br>\n";
650
651 print "<h3>Members</h3>\n";
652 print "<dl>\n";
653 foreach $parameter (@{$args{'parameterlist'}}) {
654 ($parameter =~ /^#/) && next;
655
656 my $parameter_name = $parameter;
657 $parameter_name =~ s/\[.*//;
658
Randy Dunlap3c308792007-05-08 00:24:39 -0700659 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700660 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 print "<dd>";
662 output_highlight($args{'parameterdescs'}{$parameter_name});
663 }
664 print "</dl>\n";
665 output_section_html(@_);
666 print "<hr>\n";
667}
668
669# output function in html
670sub output_function_html(%) {
671 my %args = %{$_[0]};
672 my ($parameter, $section);
673 my $count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Randy Dunlapb9d973282009-06-09 08:50:38 -0700675 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
676 print "<i>" . $args{'functiontype'} . "</i>\n";
677 print "<b>" . $args{'function'} . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 print "(";
679 $count = 0;
680 foreach $parameter (@{$args{'parameterlist'}}) {
681 $type = $args{'parametertypes'}{$parameter};
682 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
683 # pointer-to-function
684 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
685 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -0700686 print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 }
688 if ($count != $#{$args{'parameterlist'}}) {
689 $count++;
690 print ",\n";
691 }
692 }
693 print ")\n";
694
695 print "<h3>Arguments</h3>\n";
696 print "<dl>\n";
697 foreach $parameter (@{$args{'parameterlist'}}) {
698 my $parameter_name = $parameter;
699 $parameter_name =~ s/\[.*//;
700
Randy Dunlap3c308792007-05-08 00:24:39 -0700701 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -0700702 print "<dt><b>" . $parameter . "</b>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 print "<dd>";
704 output_highlight($args{'parameterdescs'}{$parameter_name});
705 }
706 print "</dl>\n";
707 output_section_html(@_);
708 print "<hr>\n";
709}
710
Johannes Bergb112e0f2007-10-24 15:08:48 -0700711# output DOC: block header in html
712sub output_blockhead_html(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 my %args = %{$_[0]};
714 my ($parameter, $section);
715 my $count;
716
717 foreach $section (@{$args{'sectionlist'}}) {
718 print "<h3>$section</h3>\n";
719 print "<ul>\n";
720 output_highlight($args{'sections'}{$section});
721 print "</ul>\n";
722 }
723 print "<hr>\n";
724}
725
Dan Luedtke1b40c192012-08-12 10:46:15 +0200726# output sections in html5
727sub output_section_html5(%) {
728 my %args = %{$_[0]};
729 my $section;
730
731 foreach $section (@{$args{'sectionlist'}}) {
732 print "<section>\n";
733 print "<h1>$section</h1>\n";
734 print "<p>\n";
735 output_highlight($args{'sections'}{$section});
736 print "</p>\n";
737 print "</section>\n";
738 }
739}
740
741# output enum in html5
742sub output_enum_html5(%) {
743 my %args = %{$_[0]};
744 my ($parameter);
745 my $count;
746 my $html5id;
747
748 $html5id = $args{'enum'};
749 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
750 print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
751 print "<h1>enum " . $args{'enum'} . "</h1>\n";
752 print "<ol class=\"code\">\n";
753 print "<li>";
754 print "<span class=\"keyword\">enum</span> ";
755 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
756 print "</li>\n";
757 $count = 0;
758 foreach $parameter (@{$args{'parameterlist'}}) {
759 print "<li class=\"indent\">";
760 print "<span class=\"param\">" . $parameter . "</span>";
761 if ($count != $#{$args{'parameterlist'}}) {
762 $count++;
763 print ",";
764 }
765 print "</li>\n";
766 }
767 print "<li>};</li>\n";
768 print "</ol>\n";
769
770 print "<section>\n";
771 print "<h1>Constants</h1>\n";
772 print "<dl>\n";
773 foreach $parameter (@{$args{'parameterlist'}}) {
774 print "<dt>" . $parameter . "</dt>\n";
775 print "<dd>";
776 output_highlight($args{'parameterdescs'}{$parameter});
777 print "</dd>\n";
778 }
779 print "</dl>\n";
780 print "</section>\n";
781 output_section_html5(@_);
782 print "</article>\n";
783}
784
785# output typedef in html5
786sub output_typedef_html5(%) {
787 my %args = %{$_[0]};
788 my ($parameter);
789 my $count;
790 my $html5id;
791
792 $html5id = $args{'typedef'};
793 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
794 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
795 print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
796
797 print "<ol class=\"code\">\n";
798 print "<li>";
799 print "<span class=\"keyword\">typedef</span> ";
800 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
801 print "</li>\n";
802 print "</ol>\n";
803 output_section_html5(@_);
804 print "</article>\n";
805}
806
807# output struct in html5
808sub output_struct_html5(%) {
809 my %args = %{$_[0]};
810 my ($parameter);
811 my $html5id;
812
813 $html5id = $args{'struct'};
814 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
815 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
816 print "<hgroup>\n";
817 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
818 print "<h2>". $args{'purpose'} . "</h2>\n";
819 print "</hgroup>\n";
820 print "<ol class=\"code\">\n";
821 print "<li>";
822 print "<span class=\"type\">" . $args{'type'} . "</span> ";
823 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
824 print "</li>\n";
825 foreach $parameter (@{$args{'parameterlist'}}) {
826 print "<li class=\"indent\">";
827 if ($parameter =~ /^#/) {
828 print "<span class=\"param\">" . $parameter ."</span>\n";
829 print "</li>\n";
830 next;
831 }
832 my $parameter_name = $parameter;
833 $parameter_name =~ s/\[.*//;
834
835 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
836 $type = $args{'parametertypes'}{$parameter};
837 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
838 # pointer-to-function
839 print "<span class=\"type\">$1</span> ";
840 print "<span class=\"param\">$parameter</span>";
841 print "<span class=\"type\">)</span> ";
842 print "(<span class=\"args\">$2</span>);";
843 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
844 # bitfield
845 print "<span class=\"type\">$1</span> ";
846 print "<span class=\"param\">$parameter</span>";
847 print "<span class=\"bits\">$2</span>;";
848 } else {
849 print "<span class=\"type\">$type</span> ";
850 print "<span class=\"param\">$parameter</span>;";
851 }
852 print "</li>\n";
853 }
854 print "<li>};</li>\n";
855 print "</ol>\n";
856
857 print "<section>\n";
858 print "<h1>Members</h1>\n";
859 print "<dl>\n";
860 foreach $parameter (@{$args{'parameterlist'}}) {
861 ($parameter =~ /^#/) && next;
862
863 my $parameter_name = $parameter;
864 $parameter_name =~ s/\[.*//;
865
866 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
867 print "<dt>" . $parameter . "</dt>\n";
868 print "<dd>";
869 output_highlight($args{'parameterdescs'}{$parameter_name});
870 print "</dd>\n";
871 }
872 print "</dl>\n";
873 print "</section>\n";
874 output_section_html5(@_);
875 print "</article>\n";
876}
877
878# output function in html5
879sub output_function_html5(%) {
880 my %args = %{$_[0]};
881 my ($parameter, $section);
882 my $count;
883 my $html5id;
884
885 $html5id = $args{'function'};
886 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
887 print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
888 print "<hgroup>\n";
889 print "<h1>" . $args{'function'} . "</h1>";
890 print "<h2>" . $args{'purpose'} . "</h2>\n";
891 print "</hgroup>\n";
892 print "<ol class=\"code\">\n";
893 print "<li>";
894 print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
895 print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
896 print "</li>";
897 $count = 0;
898 foreach $parameter (@{$args{'parameterlist'}}) {
899 print "<li class=\"indent\">";
900 $type = $args{'parametertypes'}{$parameter};
901 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
902 # pointer-to-function
903 print "<span class=\"type\">$1</span> ";
904 print "<span class=\"param\">$parameter</span>";
905 print "<span class=\"type\">)</span> ";
906 print "(<span class=\"args\">$2</span>)";
907 } else {
908 print "<span class=\"type\">$type</span> ";
909 print "<span class=\"param\">$parameter</span>";
910 }
911 if ($count != $#{$args{'parameterlist'}}) {
912 $count++;
913 print ",";
914 }
915 print "</li>\n";
916 }
917 print "<li>)</li>\n";
918 print "</ol>\n";
919
920 print "<section>\n";
921 print "<h1>Arguments</h1>\n";
922 print "<p>\n";
923 print "<dl>\n";
924 foreach $parameter (@{$args{'parameterlist'}}) {
925 my $parameter_name = $parameter;
926 $parameter_name =~ s/\[.*//;
927
928 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
929 print "<dt>" . $parameter . "</dt>\n";
930 print "<dd>";
931 output_highlight($args{'parameterdescs'}{$parameter_name});
932 print "</dd>\n";
933 }
934 print "</dl>\n";
935 print "</section>\n";
936 output_section_html5(@_);
937 print "</article>\n";
938}
939
940# output DOC: block header in html5
941sub output_blockhead_html5(%) {
942 my %args = %{$_[0]};
943 my ($parameter, $section);
944 my $count;
945 my $html5id;
946
947 foreach $section (@{$args{'sectionlist'}}) {
948 $html5id = $section;
949 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
950 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
951 print "<h1>$section</h1>\n";
952 print "<p>\n";
953 output_highlight($args{'sections'}{$section});
954 print "</p>\n";
955 }
956 print "</article>\n";
957}
958
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959sub output_section_xml(%) {
960 my %args = %{$_[0]};
Randy Dunlap3c3b8092006-02-01 03:06:58 -0800961 my $section;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 # print out each section
963 $lineprefix=" ";
964 foreach $section (@{$args{'sectionlist'}}) {
Rich Walkerc73894c2005-05-01 08:59:26 -0700965 print "<refsect1>\n";
966 print "<title>$section</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -0700968 print "<informalexample><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -0700969 $output_preformatted = 1;
Rich Walkerc73894c2005-05-01 08:59:26 -0700970 } else {
971 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 }
973 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -0700974 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 if ($section =~ m/EXAMPLE/i) {
Rich Walkerc73894c2005-05-01 08:59:26 -0700976 print "</programlisting></informalexample>\n";
977 } else {
978 print "</para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 }
Rich Walkerc73894c2005-05-01 08:59:26 -0700980 print "</refsect1>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 }
982}
983
984# output function in XML DocBook
985sub output_function_xml(%) {
986 my %args = %{$_[0]};
987 my ($parameter, $section);
988 my $count;
989 my $id;
990
Randy Dunlapb9d973282009-06-09 08:50:38 -0700991 $id = "API-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 $id =~ s/[^A-Za-z0-9]/-/g;
993
Pavel Pisa5449bc92007-02-10 01:45:37 -0800994 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -0700995 print "<refentryinfo>\n";
996 print " <title>LINUX</title>\n";
997 print " <productname>Kernel Hackers Manual</productname>\n";
998 print " <date>$man_date</date>\n";
999 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001001 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001002 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001003 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 print "</refmeta>\n";
1005 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001006 print " <refname>" . $args{'function'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 print " <refpurpose>\n";
1008 print " ";
1009 output_highlight ($args{'purpose'});
1010 print " </refpurpose>\n";
1011 print "</refnamediv>\n";
1012
1013 print "<refsynopsisdiv>\n";
1014 print " <title>Synopsis</title>\n";
1015 print " <funcsynopsis><funcprototype>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001016 print " <funcdef>" . $args{'functiontype'} . " ";
1017 print "<function>" . $args{'function'} . " </function></funcdef>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018
1019 $count = 0;
1020 if ($#{$args{'parameterlist'}} >= 0) {
1021 foreach $parameter (@{$args{'parameterlist'}}) {
1022 $type = $args{'parametertypes'}{$parameter};
1023 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1024 # pointer-to-function
1025 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
1026 print " <funcparams>$2</funcparams></paramdef>\n";
1027 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001028 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 print " <parameter>$parameter</parameter></paramdef>\n";
1030 }
1031 }
1032 } else {
Martin Waitz6013d542005-05-01 08:59:25 -07001033 print " <void/>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 }
1035 print " </funcprototype></funcsynopsis>\n";
1036 print "</refsynopsisdiv>\n";
1037
1038 # print parameters
1039 print "<refsect1>\n <title>Arguments</title>\n";
1040 if ($#{$args{'parameterlist'}} >= 0) {
1041 print " <variablelist>\n";
1042 foreach $parameter (@{$args{'parameterlist'}}) {
1043 my $parameter_name = $parameter;
1044 $parameter_name =~ s/\[.*//;
1045
1046 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
1047 print " <listitem>\n <para>\n";
1048 $lineprefix=" ";
1049 output_highlight($args{'parameterdescs'}{$parameter_name});
1050 print " </para>\n </listitem>\n </varlistentry>\n";
1051 }
1052 print " </variablelist>\n";
1053 } else {
1054 print " <para>\n None\n </para>\n";
1055 }
1056 print "</refsect1>\n";
1057
1058 output_section_xml(@_);
1059 print "</refentry>\n\n";
1060}
1061
1062# output struct in XML DocBook
1063sub output_struct_xml(%) {
1064 my %args = %{$_[0]};
1065 my ($parameter, $section);
1066 my $id;
1067
Randy Dunlapb9d973282009-06-09 08:50:38 -07001068 $id = "API-struct-" . $args{'struct'};
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{'type'} . " " . $args{'struct'} . "</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{'type'} . " " . $args{'struct'} . "</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 " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001093 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 foreach $parameter (@{$args{'parameterlist'}}) {
1095 if ($parameter =~ /^#/) {
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08001096 my $prm = $parameter;
1097 # convert data read & converted thru xml_escape() into &xyz; format:
1098 # This allows us to have #define macros interspersed in a struct.
1099 $prm =~ s/\\\\\\/\&/g;
1100 print "$prm\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 next;
1102 }
1103
1104 my $parameter_name = $parameter;
1105 $parameter_name =~ s/\[.*//;
1106
1107 defined($args{'parameterdescs'}{$parameter_name}) || next;
Randy Dunlap3c308792007-05-08 00:24:39 -07001108 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 $type = $args{'parametertypes'}{$parameter};
1110 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1111 # pointer-to-function
1112 print " $1 $parameter) ($2);\n";
1113 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001114 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 print " $1 $parameter$2;\n";
1116 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001117 print " " . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 }
1119 }
1120 print "};";
1121 print " </programlisting>\n";
1122 print "</refsynopsisdiv>\n";
1123
1124 print " <refsect1>\n";
1125 print " <title>Members</title>\n";
1126
Randy Dunlap39f00c02008-09-22 13:57:44 -07001127 if ($#{$args{'parameterlist'}} >= 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 print " <variablelist>\n";
1129 foreach $parameter (@{$args{'parameterlist'}}) {
1130 ($parameter =~ /^#/) && next;
1131
1132 my $parameter_name = $parameter;
1133 $parameter_name =~ s/\[.*//;
1134
1135 defined($args{'parameterdescs'}{$parameter_name}) || next;
1136 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1137 print " <varlistentry>";
1138 print " <term>$parameter</term>\n";
1139 print " <listitem><para>\n";
1140 output_highlight($args{'parameterdescs'}{$parameter_name});
1141 print " </para></listitem>\n";
1142 print " </varlistentry>\n";
1143 }
1144 print " </variablelist>\n";
Randy Dunlap39f00c02008-09-22 13:57:44 -07001145 } else {
1146 print " <para>\n None\n </para>\n";
1147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 print " </refsect1>\n";
1149
1150 output_section_xml(@_);
1151
1152 print "</refentry>\n\n";
1153}
1154
1155# output enum in XML DocBook
1156sub output_enum_xml(%) {
1157 my %args = %{$_[0]};
1158 my ($parameter, $section);
1159 my $count;
1160 my $id;
1161
Randy Dunlapb9d973282009-06-09 08:50:38 -07001162 $id = "API-enum-" . $args{'enum'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 $id =~ s/[^A-Za-z0-9]/-/g;
1164
Pavel Pisa5449bc92007-02-10 01:45:37 -08001165 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001166 print "<refentryinfo>\n";
1167 print " <title>LINUX</title>\n";
1168 print " <productname>Kernel Hackers Manual</productname>\n";
1169 print " <date>$man_date</date>\n";
1170 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001172 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001173 print " <manvolnum>9</manvolnum>\n";
Borislav Petkov03662992007-05-09 02:33:43 -07001174 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175 print "</refmeta>\n";
1176 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001177 print " <refname>enum " . $args{'enum'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 print " <refpurpose>\n";
1179 print " ";
1180 output_highlight ($args{'purpose'});
1181 print " </refpurpose>\n";
1182 print "</refnamediv>\n";
1183
1184 print "<refsynopsisdiv>\n";
1185 print " <title>Synopsis</title>\n";
1186 print " <programlisting>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001187 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 $count = 0;
1189 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001190 print " $parameter";
1191 if ($count != $#{$args{'parameterlist'}}) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192 $count++;
1193 print ",";
Randy Dunlap3c308792007-05-08 00:24:39 -07001194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 print "\n";
1196 }
1197 print "};";
1198 print " </programlisting>\n";
1199 print "</refsynopsisdiv>\n";
1200
1201 print "<refsect1>\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001202 print " <title>Constants</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 print " <variablelist>\n";
1204 foreach $parameter (@{$args{'parameterlist'}}) {
1205 my $parameter_name = $parameter;
1206 $parameter_name =~ s/\[.*//;
1207
1208 print " <varlistentry>";
1209 print " <term>$parameter</term>\n";
1210 print " <listitem><para>\n";
1211 output_highlight($args{'parameterdescs'}{$parameter_name});
1212 print " </para></listitem>\n";
1213 print " </varlistentry>\n";
1214 }
1215 print " </variablelist>\n";
1216 print "</refsect1>\n";
1217
1218 output_section_xml(@_);
1219
1220 print "</refentry>\n\n";
1221}
1222
1223# output typedef in XML DocBook
1224sub output_typedef_xml(%) {
1225 my %args = %{$_[0]};
1226 my ($parameter, $section);
1227 my $id;
1228
Randy Dunlapb9d973282009-06-09 08:50:38 -07001229 $id = "API-typedef-" . $args{'typedef'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 $id =~ s/[^A-Za-z0-9]/-/g;
1231
Pavel Pisa5449bc92007-02-10 01:45:37 -08001232 print "<refentry id=\"$id\">\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001233 print "<refentryinfo>\n";
1234 print " <title>LINUX</title>\n";
1235 print " <productname>Kernel Hackers Manual</productname>\n";
1236 print " <date>$man_date</date>\n";
1237 print "</refentryinfo>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 print "<refmeta>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001239 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
Martin Waitz8b0c2d92005-05-01 08:59:27 -07001240 print " <manvolnum>9</manvolnum>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 print "</refmeta>\n";
1242 print "<refnamediv>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001243 print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 print " <refpurpose>\n";
1245 print " ";
1246 output_highlight ($args{'purpose'});
1247 print " </refpurpose>\n";
1248 print "</refnamediv>\n";
1249
1250 print "<refsynopsisdiv>\n";
1251 print " <title>Synopsis</title>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001252 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 print "</refsynopsisdiv>\n";
1254
1255 output_section_xml(@_);
1256
1257 print "</refentry>\n\n";
1258}
1259
1260# output in XML DocBook
Johannes Bergb112e0f2007-10-24 15:08:48 -07001261sub output_blockhead_xml(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 my %args = %{$_[0]};
1263 my ($parameter, $section);
1264 my $count;
1265
1266 my $id = $args{'module'};
1267 $id =~ s/[^A-Za-z0-9]/-/g;
1268
1269 # print out each section
1270 $lineprefix=" ";
1271 foreach $section (@{$args{'sectionlist'}}) {
Johannes Bergb112e0f2007-10-24 15:08:48 -07001272 if (!$args{'content-only'}) {
1273 print "<refsect1>\n <title>$section</title>\n";
1274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275 if ($section =~ m/EXAMPLE/i) {
1276 print "<example><para>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001277 $output_preformatted = 1;
Johannes Bergb112e0f2007-10-24 15:08:48 -07001278 } else {
1279 print "<para>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 }
1281 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001282 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 if ($section =~ m/EXAMPLE/i) {
1284 print "</para></example>\n";
Johannes Bergb112e0f2007-10-24 15:08:48 -07001285 } else {
1286 print "</para>";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 }
Johannes Bergb112e0f2007-10-24 15:08:48 -07001288 if (!$args{'content-only'}) {
1289 print "\n</refsect1>\n";
1290 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001291 }
1292
1293 print "\n\n";
1294}
1295
1296# output in XML DocBook
1297sub output_function_gnome {
1298 my %args = %{$_[0]};
1299 my ($parameter, $section);
1300 my $count;
1301 my $id;
1302
Randy Dunlapb9d973282009-06-09 08:50:38 -07001303 $id = $args{'module'} . "-" . $args{'function'};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 $id =~ s/[^A-Za-z0-9]/-/g;
1305
1306 print "<sect2>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001307 print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
1309 print " <funcsynopsis>\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001310 print " <funcdef>" . $args{'functiontype'} . " ";
1311 print "<function>" . $args{'function'} . " ";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 print "</function></funcdef>\n";
1313
1314 $count = 0;
1315 if ($#{$args{'parameterlist'}} >= 0) {
1316 foreach $parameter (@{$args{'parameterlist'}}) {
1317 $type = $args{'parametertypes'}{$parameter};
1318 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1319 # pointer-to-function
1320 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
1321 print " <funcparams>$2</funcparams></paramdef>\n";
1322 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001323 print " <paramdef>" . $type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 print " <parameter>$parameter</parameter></paramdef>\n";
1325 }
1326 }
1327 } else {
1328 print " <void>\n";
1329 }
1330 print " </funcsynopsis>\n";
1331 if ($#{$args{'parameterlist'}} >= 0) {
1332 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
1333 print "<tgroup cols=\"2\">\n";
1334 print "<colspec colwidth=\"2*\">\n";
1335 print "<colspec colwidth=\"8*\">\n";
1336 print "<tbody>\n";
1337 foreach $parameter (@{$args{'parameterlist'}}) {
1338 my $parameter_name = $parameter;
1339 $parameter_name =~ s/\[.*//;
1340
1341 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
1342 print " <entry>\n";
1343 $lineprefix=" ";
1344 output_highlight($args{'parameterdescs'}{$parameter_name});
1345 print " </entry></row>\n";
1346 }
1347 print " </tbody></tgroup></informaltable>\n";
1348 } else {
1349 print " <para>\n None\n </para>\n";
1350 }
1351
1352 # print out each section
1353 $lineprefix=" ";
1354 foreach $section (@{$args{'sectionlist'}}) {
1355 print "<simplesect>\n <title>$section</title>\n";
1356 if ($section =~ m/EXAMPLE/i) {
1357 print "<example><programlisting>\n";
Daniel Santose314ba32012-10-04 17:15:08 -07001358 $output_preformatted = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 } else {
1360 }
1361 print "<para>\n";
1362 output_highlight($args{'sections'}{$section});
Daniel Santose314ba32012-10-04 17:15:08 -07001363 $output_preformatted = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 print "</para>\n";
1365 if ($section =~ m/EXAMPLE/i) {
1366 print "</programlisting></example>\n";
1367 } else {
1368 }
1369 print " </simplesect>\n";
1370 }
1371
1372 print "</sect2>\n\n";
1373}
1374
1375##
1376# output function in man
1377sub output_function_man(%) {
1378 my %args = %{$_[0]};
1379 my ($parameter, $section);
1380 my $count;
1381
1382 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1383
1384 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001385 print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386
1387 print ".SH SYNOPSIS\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001388 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001389 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001390 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001391 print ".B \"" . $args{'function'} . "\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001392 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 $count = 0;
1394 my $parenth = "(";
1395 my $post = ",";
1396 foreach my $parameter (@{$args{'parameterlist'}}) {
1397 if ($count == $#{$args{'parameterlist'}}) {
1398 $post = ");";
1399 }
1400 $type = $args{'parametertypes'}{$parameter};
1401 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1402 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001403 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 } else {
1405 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001406 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 }
1408 $count++;
1409 $parenth = "";
1410 }
1411
1412 print ".SH ARGUMENTS\n";
1413 foreach $parameter (@{$args{'parameterlist'}}) {
1414 my $parameter_name = $parameter;
1415 $parameter_name =~ s/\[.*//;
1416
Randy Dunlapb9d973282009-06-09 08:50:38 -07001417 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 output_highlight($args{'parameterdescs'}{$parameter_name});
1419 }
1420 foreach $section (@{$args{'sectionlist'}}) {
1421 print ".SH \"", uc $section, "\"\n";
1422 output_highlight($args{'sections'}{$section});
1423 }
1424}
1425
1426##
1427# output enum in man
1428sub output_enum_man(%) {
1429 my %args = %{$_[0]};
1430 my ($parameter, $section);
1431 my $count;
1432
1433 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1434
1435 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001436 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437
1438 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001439 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 $count = 0;
1441 foreach my $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001442 print ".br\n.BI \" $parameter\"\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 if ($count == $#{$args{'parameterlist'}}) {
1444 print "\n};\n";
1445 last;
1446 }
1447 else {
1448 print ", \n.br\n";
1449 }
1450 $count++;
1451 }
1452
1453 print ".SH Constants\n";
1454 foreach $parameter (@{$args{'parameterlist'}}) {
1455 my $parameter_name = $parameter;
1456 $parameter_name =~ s/\[.*//;
1457
Randy Dunlapb9d973282009-06-09 08:50:38 -07001458 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 output_highlight($args{'parameterdescs'}{$parameter_name});
1460 }
1461 foreach $section (@{$args{'sectionlist'}}) {
1462 print ".SH \"$section\"\n";
1463 output_highlight($args{'sections'}{$section});
1464 }
1465}
1466
1467##
1468# output struct in man
1469sub output_struct_man(%) {
1470 my %args = %{$_[0]};
1471 my ($parameter, $section);
1472
Randy Dunlapb9d973282009-06-09 08:50:38 -07001473 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
1475 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001476 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
1478 print ".SH SYNOPSIS\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001479 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
1481 foreach my $parameter (@{$args{'parameterlist'}}) {
1482 if ($parameter =~ /^#/) {
1483 print ".BI \"$parameter\"\n.br\n";
1484 next;
1485 }
1486 my $parameter_name = $parameter;
1487 $parameter_name =~ s/\[.*//;
1488
Randy Dunlap3c308792007-05-08 00:24:39 -07001489 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 $type = $args{'parametertypes'}{$parameter};
1491 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1492 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001493 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy.Dunlap1d7e1d42006-07-01 04:36:34 -07001495 # bitfield
Randy Dunlapb9d973282009-06-09 08:50:38 -07001496 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 } else {
1498 $type =~ s/([^\*])$/$1 /;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001499 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 }
1501 print "\n.br\n";
1502 }
1503 print "};\n.br\n";
1504
Randy Dunlapc51d3da2006-06-25 05:49:14 -07001505 print ".SH Members\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 foreach $parameter (@{$args{'parameterlist'}}) {
1507 ($parameter =~ /^#/) && next;
1508
1509 my $parameter_name = $parameter;
1510 $parameter_name =~ s/\[.*//;
1511
Randy Dunlap3c308792007-05-08 00:24:39 -07001512 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001513 print ".IP \"" . $parameter . "\" 12\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 output_highlight($args{'parameterdescs'}{$parameter_name});
1515 }
1516 foreach $section (@{$args{'sectionlist'}}) {
1517 print ".SH \"$section\"\n";
1518 output_highlight($args{'sections'}{$section});
1519 }
1520}
1521
1522##
1523# output typedef in man
1524sub output_typedef_man(%) {
1525 my %args = %{$_[0]};
1526 my ($parameter, $section);
1527
1528 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1529
1530 print ".SH NAME\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001531 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
1533 foreach $section (@{$args{'sectionlist'}}) {
1534 print ".SH \"$section\"\n";
1535 output_highlight($args{'sections'}{$section});
1536 }
1537}
1538
Johannes Bergb112e0f2007-10-24 15:08:48 -07001539sub output_blockhead_man(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 my %args = %{$_[0]};
1541 my ($parameter, $section);
1542 my $count;
1543
1544 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1545
1546 foreach $section (@{$args{'sectionlist'}}) {
1547 print ".SH \"$section\"\n";
1548 output_highlight($args{'sections'}{$section});
1549 }
1550}
1551
1552##
1553# output in text
1554sub output_function_text(%) {
1555 my %args = %{$_[0]};
1556 my ($parameter, $section);
Randy Dunlapa21217d2007-02-10 01:46:04 -08001557 my $start;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
Randy Dunlapf47634b2006-07-01 04:36:36 -07001559 print "Name:\n\n";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001560 print $args{'function'} . " - " . $args{'purpose'} . "\n";
Randy Dunlapf47634b2006-07-01 04:36:36 -07001561
1562 print "\nSynopsis:\n\n";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001563 if ($args{'functiontype'} ne "") {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001564 $start = $args{'functiontype'} . " " . $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001565 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001566 $start = $args{'function'} . " (";
Randy Dunlapa21217d2007-02-10 01:46:04 -08001567 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 print $start;
Randy Dunlapa21217d2007-02-10 01:46:04 -08001569
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 my $count = 0;
1571 foreach my $parameter (@{$args{'parameterlist'}}) {
1572 $type = $args{'parametertypes'}{$parameter};
1573 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1574 # pointer-to-function
Randy Dunlapb9d973282009-06-09 08:50:38 -07001575 print $1 . $parameter . ") (" . $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001577 print $type . " " . $parameter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 }
1579 if ($count != $#{$args{'parameterlist'}}) {
1580 $count++;
1581 print ",\n";
1582 print " " x length($start);
1583 } else {
1584 print ");\n\n";
1585 }
1586 }
1587
1588 print "Arguments:\n\n";
1589 foreach $parameter (@{$args{'parameterlist'}}) {
1590 my $parameter_name = $parameter;
1591 $parameter_name =~ s/\[.*//;
1592
Randy Dunlapb9d973282009-06-09 08:50:38 -07001593 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 }
1595 output_section_text(@_);
1596}
1597
1598#output sections in text
1599sub output_section_text(%) {
1600 my %args = %{$_[0]};
1601 my $section;
1602
1603 print "\n";
1604 foreach $section (@{$args{'sectionlist'}}) {
1605 print "$section:\n\n";
1606 output_highlight($args{'sections'}{$section});
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001607 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 print "\n\n";
1609}
1610
1611# output enum in text
1612sub output_enum_text(%) {
1613 my %args = %{$_[0]};
1614 my ($parameter);
1615 my $count;
1616 print "Enum:\n\n";
1617
Randy Dunlapb9d973282009-06-09 08:50:38 -07001618 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
1619 print "enum " . $args{'enum'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 $count = 0;
1621 foreach $parameter (@{$args{'parameterlist'}}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001622 print "\t$parameter";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 if ($count != $#{$args{'parameterlist'}}) {
1624 $count++;
1625 print ",";
1626 }
1627 print "\n";
1628 }
1629 print "};\n\n";
1630
1631 print "Constants:\n\n";
1632 foreach $parameter (@{$args{'parameterlist'}}) {
1633 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001634 print $args{'parameterdescs'}{$parameter} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 }
1636
1637 output_section_text(@_);
1638}
1639
1640# output typedef in text
1641sub output_typedef_text(%) {
1642 my %args = %{$_[0]};
1643 my ($parameter);
1644 my $count;
1645 print "Typedef:\n\n";
1646
Randy Dunlapb9d973282009-06-09 08:50:38 -07001647 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648 output_section_text(@_);
1649}
1650
1651# output struct as text
1652sub output_struct_text(%) {
1653 my %args = %{$_[0]};
1654 my ($parameter);
1655
Randy Dunlapb9d973282009-06-09 08:50:38 -07001656 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
1657 print $args{'type'} . " " . $args{'struct'} . " {\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 foreach $parameter (@{$args{'parameterlist'}}) {
1659 if ($parameter =~ /^#/) {
1660 print "$parameter\n";
1661 next;
1662 }
1663
1664 my $parameter_name = $parameter;
1665 $parameter_name =~ s/\[.*//;
1666
Randy Dunlap3c308792007-05-08 00:24:39 -07001667 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 $type = $args{'parametertypes'}{$parameter};
1669 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1670 # pointer-to-function
1671 print "\t$1 $parameter) ($2);\n";
1672 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07001673 # bitfield
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 print "\t$1 $parameter$2;\n";
1675 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07001676 print "\t" . $type . " " . $parameter . ";\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 }
1678 }
1679 print "};\n\n";
1680
1681 print "Members:\n\n";
1682 foreach $parameter (@{$args{'parameterlist'}}) {
1683 ($parameter =~ /^#/) && next;
1684
1685 my $parameter_name = $parameter;
1686 $parameter_name =~ s/\[.*//;
1687
Randy Dunlap3c308792007-05-08 00:24:39 -07001688 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 print "$parameter\n\t";
Randy Dunlapb9d973282009-06-09 08:50:38 -07001690 print $args{'parameterdescs'}{$parameter_name} . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 }
1692 print "\n";
1693 output_section_text(@_);
1694}
1695
Johannes Bergb112e0f2007-10-24 15:08:48 -07001696sub output_blockhead_text(%) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 my %args = %{$_[0]};
1698 my ($parameter, $section);
1699
1700 foreach $section (@{$args{'sectionlist'}}) {
1701 print " $section:\n";
1702 print " -> ";
1703 output_highlight($args{'sections'}{$section});
1704 }
1705}
1706
Johannes Bergeda603f2010-09-11 15:55:22 -07001707## list mode output functions
1708
1709sub output_function_list(%) {
1710 my %args = %{$_[0]};
1711
1712 print $args{'function'} . "\n";
1713}
1714
1715# output enum in list
1716sub output_enum_list(%) {
1717 my %args = %{$_[0]};
1718 print $args{'enum'} . "\n";
1719}
1720
1721# output typedef in list
1722sub output_typedef_list(%) {
1723 my %args = %{$_[0]};
1724 print $args{'typedef'} . "\n";
1725}
1726
1727# output struct as list
1728sub output_struct_list(%) {
1729 my %args = %{$_[0]};
1730
1731 print $args{'struct'} . "\n";
1732}
1733
1734sub output_blockhead_list(%) {
1735 my %args = %{$_[0]};
1736 my ($parameter, $section);
1737
1738 foreach $section (@{$args{'sectionlist'}}) {
1739 print "DOC: $section\n";
1740 }
1741}
1742
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743##
Randy Dunlap27205742006-10-11 01:22:12 -07001744# generic output function for all types (function, struct/union, typedef, enum);
1745# calls the generated, variable output_ function name based on
1746# functype and output_mode
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747sub output_declaration {
1748 no strict 'refs';
1749 my $name = shift;
1750 my $functype = shift;
1751 my $func = "output_${functype}_$output_mode";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001752 if (($function_only==0) ||
1753 ( $function_only == 1 && defined($function_table{$name})) ||
Danilo Cesar Lemes de Paula23aebb32015-09-01 14:44:14 -03001754 ( $function_only == 2 && !($functype eq "function" && defined($function_table{$name}))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 {
Randy Dunlap3c308792007-05-08 00:24:39 -07001756 &$func(@_);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 $section_counter++;
1758 }
1759}
1760
1761##
Randy Dunlap27205742006-10-11 01:22:12 -07001762# generic output function - calls the right one based on current output mode.
Johannes Bergb112e0f2007-10-24 15:08:48 -07001763sub output_blockhead {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 no strict 'refs';
Randy Dunlapb9d973282009-06-09 08:50:38 -07001765 my $func = "output_blockhead_" . $output_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766 &$func(@_);
1767 $section_counter++;
1768}
1769
1770##
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001771# takes a declaration (struct, union, enum, typedef) and
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772# invokes the right handler. NOT called for functions.
1773sub dump_declaration($$) {
1774 no strict 'refs';
1775 my ($prototype, $file) = @_;
Randy Dunlapb9d973282009-06-09 08:50:38 -07001776 my $func = "dump_" . $decl_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 &$func(@_);
1778}
1779
1780sub dump_union($$) {
1781 dump_struct(@_);
1782}
1783
1784sub dump_struct($$) {
1785 my $x = shift;
1786 my $file = shift;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001787 my $nested;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
Randy Dunlap52dc5ae2009-04-30 15:08:53 -07001789 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
1790 #my $decl_type = $1;
Randy Dunlap3c308792007-05-08 00:24:39 -07001791 $declaration_name = $2;
1792 my $members = $3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
1794 # ignore embedded structs or unions
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001795 $members =~ s/({.*})//g;
1796 $nested = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797
Martin Waitzaeec46b2005-11-13 16:08:13 -08001798 # ignore members marked private:
Mauro Carvalho Chehab0d8c39e2015-10-05 09:03:48 -03001799 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
1800 $members =~ s/\/\*\s*private:.*//gosi;
Martin Waitzaeec46b2005-11-13 16:08:13 -08001801 # strip comments:
1802 $members =~ s/\/\*.*?\*\///gos;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001803 $nested =~ s/\/\*.*?\*\///gos;
Randy Dunlapd960eea2009-06-29 14:54:11 -07001804 # strip kmemcheck_bitfield_{begin,end}.*;
1805 $members =~ s/kmemcheck_bitfield_.*?;//gos;
Randy Dunlapef5da592010-03-23 13:35:14 -07001806 # strip attributes
Jonathan Corbetf0074922015-08-23 13:35:23 -06001807 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Johannes Berg7b990782014-12-10 15:41:28 -08001808 $members =~ s/__aligned\s*\([^;]*\)//gos;
Jonathan Corbetf0074922015-08-23 13:35:23 -06001809 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
Conchúr Navidb22b5a92015-11-08 10:52:00 +01001810 # replace DECLARE_BITMAP
1811 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
Martin Waitzaeec46b2005-11-13 16:08:13 -08001812
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 create_parameterlist($members, ';', $file);
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001814 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815
1816 output_declaration($declaration_name,
1817 'struct',
1818 {'struct' => $declaration_name,
1819 'module' => $modulename,
1820 'parameterlist' => \@parameterlist,
1821 'parameterdescs' => \%parameterdescs,
1822 'parametertypes' => \%parametertypes,
1823 'sectionlist' => \@sectionlist,
1824 'sections' => \%sections,
1825 'purpose' => $declaration_purpose,
1826 'type' => $decl_type
1827 });
1828 }
1829 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07001830 print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 ++$errors;
1832 }
1833}
1834
1835sub dump_enum($$) {
1836 my $x = shift;
1837 my $file = shift;
1838
Martin Waitzaeec46b2005-11-13 16:08:13 -08001839 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Conchúr Navid4468e212015-11-08 10:48:05 +01001840 # strip #define macros inside enums
1841 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
Randy Dunlapb6d676d2010-08-10 18:02:50 -07001842
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001844 $declaration_name = $1;
1845 my $members = $2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846
1847 foreach my $arg (split ',', $members) {
1848 $arg =~ s/^\s*(\w+).*/$1/;
1849 push @parameterlist, $arg;
1850 if (!$parameterdescs{$arg}) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001851 $parameterdescs{$arg} = $undescribed;
Bart Van Assched40e1e62015-09-04 15:43:21 -07001852 print STDERR "${file}:$.: warning: Enum value '$arg' ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 "not described in enum '$declaration_name'\n";
1854 }
1855
1856 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001857
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 output_declaration($declaration_name,
1859 'enum',
1860 {'enum' => $declaration_name,
1861 'module' => $modulename,
1862 'parameterlist' => \@parameterlist,
1863 'parameterdescs' => \%parameterdescs,
1864 'sectionlist' => \@sectionlist,
1865 'sections' => \%sections,
1866 'purpose' => $declaration_purpose
1867 });
1868 }
1869 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07001870 print STDERR "${file}:$.: error: Cannot parse enum!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 ++$errors;
1872 }
1873}
1874
1875sub dump_typedef($$) {
1876 my $x = shift;
1877 my $file = shift;
1878
Martin Waitzaeec46b2005-11-13 16:08:13 -08001879 $x =~ s@/\*.*?\*/@@gos; # strip comments.
Mauro Carvalho Chehab83766452015-10-08 16:14:45 -03001880
1881 # Parse function prototypes
1882 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
1883 # Function typedefs
1884 $return_type = $1;
1885 $declaration_name = $2;
1886 my $args = $3;
1887
1888 create_parameterlist($args, ',', $file);
1889
1890 output_declaration($declaration_name,
1891 'function',
1892 {'function' => $declaration_name,
1893 'module' => $modulename,
1894 'functiontype' => $return_type,
1895 'parameterlist' => \@parameterlist,
1896 'parameterdescs' => \%parameterdescs,
1897 'parametertypes' => \%parametertypes,
1898 'sectionlist' => \@sectionlist,
1899 'sections' => \%sections,
1900 'purpose' => $declaration_purpose
1901 });
1902 return;
1903 }
1904
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001906 $x =~ s/\(*.\)\s*;$/;/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 $x =~ s/\[*.\]\s*;$/;/;
1908 }
1909
1910 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001911 $declaration_name = $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
1913 output_declaration($declaration_name,
1914 'typedef',
1915 {'typedef' => $declaration_name,
1916 'module' => $modulename,
1917 'sectionlist' => \@sectionlist,
1918 'sections' => \%sections,
1919 'purpose' => $declaration_purpose
1920 });
1921 }
1922 else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07001923 print STDERR "${file}:$.: error: Cannot parse typedef!\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 ++$errors;
1925 }
1926}
1927
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001928sub save_struct_actual($) {
1929 my $actual = shift;
1930
1931 # strip all spaces from the actual param so that it looks like one string item
1932 $actual =~ s/\s*//g;
1933 $struct_actual = $struct_actual . $actual . " ";
1934}
1935
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936sub create_parameterlist($$$) {
1937 my $args = shift;
1938 my $splitter = shift;
1939 my $file = shift;
1940 my $type;
1941 my $param;
1942
Martin Waitza6d3fe72006-01-09 20:53:55 -08001943 # temporarily replace commas inside function pointer definition
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 while ($args =~ /(\([^\),]+),/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07001945 $args =~ s/(\([^\),]+),/$1#/g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 }
Randy Dunlap3c3b8092006-02-01 03:06:58 -08001947
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 foreach my $arg (split($splitter, $args)) {
1949 # strip comments
1950 $arg =~ s/\/\*.*\*\///;
Randy Dunlap3c308792007-05-08 00:24:39 -07001951 # strip leading/trailing spaces
1952 $arg =~ s/^\s*//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 $arg =~ s/\s*$//;
1954 $arg =~ s/\s+/ /;
1955
1956 if ($arg =~ /^#/) {
1957 # Treat preprocessor directive as a typeless variable just to fill
1958 # corresponding data structures "correctly". Catch it later in
1959 # output_* subs.
1960 push_parameter($arg, "", $file);
Richard Kennedy00d62962008-02-23 15:24:01 -08001961 } elsif ($arg =~ m/\(.+\)\s*\(/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 # pointer-to-function
1963 $arg =~ tr/#/,/;
Richard Kennedy00d62962008-02-23 15:24:01 -08001964 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 $param = $1;
1966 $type = $arg;
Richard Kennedy00d62962008-02-23 15:24:01 -08001967 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001968 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 push_parameter($param, $type, $file);
Martin Waitzaeec46b2005-11-13 16:08:13 -08001970 } elsif ($arg) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 $arg =~ s/\s*:\s*/:/g;
1972 $arg =~ s/\s*\[/\[/g;
1973
1974 my @args = split('\s*,\s*', $arg);
1975 if ($args[0] =~ m/\*/) {
1976 $args[0] =~ s/(\*+)\s*/ $1/;
1977 }
Borislav Petkov884f2812007-05-08 00:29:05 -07001978
1979 my @first_arg;
1980 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1981 shift @args;
1982 push(@first_arg, split('\s+', $1));
1983 push(@first_arg, $2);
1984 } else {
1985 @first_arg = split('\s+', shift @args);
1986 }
1987
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 unshift(@args, pop @first_arg);
1989 $type = join " ", @first_arg;
1990
1991 foreach $param (@args) {
1992 if ($param =~ m/^(\*+)\s*(.*)/) {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001993 save_struct_actual($2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 push_parameter($2, "$type $1", $file);
1995 }
1996 elsif ($param =~ m/(.*?):(\d+)/) {
Randy Dunlap7b978872008-05-16 15:45:52 -07001997 if ($type ne "") { # skip unnamed bit-fields
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08001998 save_struct_actual($1);
Randy Dunlap7b978872008-05-16 15:45:52 -07001999 push_parameter($1, "$type:$2", $file)
2000 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 }
2002 else {
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002003 save_struct_actual($param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 push_parameter($param, $type, $file);
2005 }
2006 }
2007 }
2008 }
2009}
2010
2011sub push_parameter($$$) {
2012 my $param = shift;
2013 my $type = shift;
2014 my $file = shift;
2015
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002016 if (($anon_struct_union == 1) && ($type eq "") &&
2017 ($param eq "}")) {
2018 return; # ignore the ending }; from anon. struct/union
2019 }
2020
2021 $anon_struct_union = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 my $param_name = $param;
2023 $param_name =~ s/\[.*//;
2024
Martin Waitza6d3fe72006-01-09 20:53:55 -08002025 if ($type eq "" && $param =~ /\.\.\.$/)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 {
Randy Dunlapced69092008-12-01 13:14:03 -08002027 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2028 $parameterdescs{$param} = "variable arguments";
2029 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 }
2031 elsif ($type eq "" && ($param eq "" or $param eq "void"))
2032 {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 $param="void";
2034 $parameterdescs{void} = "no arguments";
2035 }
Randy Dunlap134fe012006-12-22 01:10:50 -08002036 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2037 # handle unnamed (anonymous) union or struct:
2038 {
2039 $type = $param;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002040 $param = "{unnamed_" . $param . "}";
Randy Dunlap134fe012006-12-22 01:10:50 -08002041 $parameterdescs{$param} = "anonymous\n";
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002042 $anon_struct_union = 1;
Randy Dunlap134fe012006-12-22 01:10:50 -08002043 }
2044
Martin Waitza6d3fe72006-01-09 20:53:55 -08002045 # warn if parameter has no description
Randy Dunlap134fe012006-12-22 01:10:50 -08002046 # (but ignore ones starting with # as these are not parameters
2047 # but inline preprocessor statements);
2048 # also ignore unnamed structs/unions;
Randy Dunlap5f8c7c92007-07-19 01:48:24 -07002049 if (!$anon_struct_union) {
Martin Waitza6d3fe72006-01-09 20:53:55 -08002050 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2051
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 $parameterdescs{$param_name} = $undescribed;
2053
2054 if (($type eq 'function') || ($type eq 'enum')) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002055 print STDERR "${file}:$.: warning: Function parameter ".
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 "or member '$param' not " .
2057 "described in '$declaration_name'\n";
2058 }
Bart Van Assched40e1e62015-09-04 15:43:21 -07002059 print STDERR "${file}:$.: warning:" .
Randy Dunlap3c308792007-05-08 00:24:39 -07002060 " No description found for parameter '$param'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 ++$warnings;
Randy Dunlap3c308792007-05-08 00:24:39 -07002062 }
2063 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
Randy Dunlap2b35f4d2010-11-18 12:27:31 -08002065 $param = xml_escape($param);
2066
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002067 # strip spaces from $param so that it is one continuous string
Randy Dunlape34e7db2009-06-17 17:37:47 -07002068 # on @parameterlist;
2069 # this fixes a problem where check_sections() cannot find
2070 # a parameter like "addr[6 + 2]" because it actually appears
2071 # as "addr[6", "+", "2]" on the parameter list;
2072 # but it's better to maintain the param string unchanged for output,
2073 # so just weaken the string compare in check_sections() to ignore
2074 # "[blah" in a parameter string;
2075 ###$param =~ s/\s*//g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 push @parameterlist, $param;
2077 $parametertypes{$param} = $type;
2078}
2079
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002080sub check_sections($$$$$$) {
2081 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2082 my @sects = split ' ', $sectcheck;
2083 my @prms = split ' ', $prmscheck;
2084 my $err;
2085 my ($px, $sx);
2086 my $prm_clean; # strip trailing "[array size]" and/or beginning "*"
2087
2088 foreach $sx (0 .. $#sects) {
2089 $err = 1;
2090 foreach $px (0 .. $#prms) {
2091 $prm_clean = $prms[$px];
2092 $prm_clean =~ s/\[.*\]//;
Johannes Berg1f3a6682010-09-11 15:55:12 -07002093 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
Randy Dunlape34e7db2009-06-17 17:37:47 -07002094 # ignore array size in a parameter string;
2095 # however, the original param string may contain
2096 # spaces, e.g.: addr[6 + 2]
2097 # and this appears in @prms as "addr[6" since the
2098 # parameter list is split at spaces;
2099 # hence just ignore "[..." for the sections check;
2100 $prm_clean =~ s/\[.*//;
2101
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002102 ##$prm_clean =~ s/^\**//;
2103 if ($prm_clean eq $sects[$sx]) {
2104 $err = 0;
2105 last;
2106 }
2107 }
2108 if ($err) {
2109 if ($decl_type eq "function") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002110 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002111 "Excess function parameter " .
2112 "'$sects[$sx]' " .
2113 "description in '$decl_name'\n";
2114 ++$warnings;
2115 } else {
2116 if ($nested !~ m/\Q$sects[$sx]\E/) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002117 print STDERR "${file}:$.: warning: " .
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002118 "Excess struct/union/enum/typedef member " .
2119 "'$sects[$sx]' " .
2120 "description in '$decl_name'\n";
2121 ++$warnings;
2122 }
2123 }
2124 }
2125 }
2126}
2127
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128##
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002129# Checks the section describing the return value of a function.
2130sub check_return_section {
2131 my $file = shift;
2132 my $declaration_name = shift;
2133 my $return_type = shift;
2134
2135 # Ignore an empty return type (It's a macro)
2136 # Ignore functions with a "void" return type. (But don't ignore "void *")
2137 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
2138 return;
2139 }
2140
2141 if (!defined($sections{$section_return}) ||
2142 $sections{$section_return} eq "") {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002143 print STDERR "${file}:$.: warning: " .
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002144 "No description found for return value of " .
2145 "'$declaration_name'\n";
2146 ++$warnings;
2147 }
2148}
2149
2150##
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151# takes a function prototype and the name of the current file being
2152# processed and spits out all the details stored in the global
2153# arrays/hashes.
2154sub dump_function($$) {
2155 my $prototype = shift;
2156 my $file = shift;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002157 my $noret = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
2159 $prototype =~ s/^static +//;
2160 $prototype =~ s/^extern +//;
Pavel Pisa4dc3b162005-05-01 08:59:25 -07002161 $prototype =~ s/^asmlinkage +//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 $prototype =~ s/^inline +//;
2163 $prototype =~ s/^__inline__ +//;
Randy Dunlap32e79402006-10-11 01:22:10 -07002164 $prototype =~ s/^__inline +//;
2165 $prototype =~ s/^__always_inline +//;
2166 $prototype =~ s/^noinline +//;
Randy Dunlap74fc5c62008-06-19 16:03:29 -07002167 $prototype =~ s/__init +//;
Randy Dunlap20072202010-03-23 13:35:24 -07002168 $prototype =~ s/__init_or_module +//;
Randy Dunlap270a0092014-08-24 18:17:17 -07002169 $prototype =~ s/__meminit +//;
Randy Dunlap70c95b02012-01-21 10:31:54 -08002170 $prototype =~ s/__must_check +//;
Randy Dunlap0df7c0e2012-08-16 16:23:20 -07002171 $prototype =~ s/__weak +//;
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002172 my $define = $prototype =~ s/^#\s*define\s+//; #ak added
Randy Dunlap328d2442007-02-28 20:12:10 -08002173 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
2175 # Yes, this truly is vile. We are looking for:
2176 # 1. Return type (may be nothing if we're looking at a macro)
2177 # 2. Function name
2178 # 3. Function parameters.
2179 #
2180 # All the while we have to watch out for function pointer parameters
2181 # (which IIRC is what the two sections are for), C types (these
2182 # regexps don't even start to express all the possibilities), and
2183 # so on.
2184 #
2185 # If you mess with these regexps, it's a good idea to check that
2186 # the following functions' documentation still comes out right:
2187 # - parport_register_device (function pointer parameters)
2188 # - atomic_set (macro)
Martin Waitz9598f912006-02-01 03:06:55 -08002189 # - pci_match_device, __copy_to_user (long return type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002191 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2192 # This is an object-like macro, it has no return type and no parameter
2193 # list.
2194 # Function-like macros are not allowed to have spaces between
2195 # declaration_name and opening parenthesis (notice the \s+).
2196 $return_type = $1;
2197 $declaration_name = $2;
2198 $noret = 1;
2199 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2201 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2202 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Randy Dunlap94b3e032008-02-07 00:13:26 -08002203 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2205 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
2206 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2207 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2208 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2209 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2210 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2211 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Martin Waitz9598f912006-02-01 03:06:55 -08002212 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2213 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
Randy Dunlap412ecd772007-02-10 22:47:33 -08002214 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2215 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 $return_type = $1;
2217 $declaration_name = $2;
2218 my $args = $3;
2219
2220 create_parameterlist($args, ',', $file);
2221 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002222 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 return;
2224 }
2225
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002226 my $prms = join " ", @parameterlist;
2227 check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2228
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002229 # This check emits a lot of warnings at the moment, because many
2230 # functions don't have a 'Return' doc section. So until the number
2231 # of warnings goes sufficiently down, the check is only performed in
2232 # verbose mode.
2233 # TODO: always perform the check.
Horia Geantacbb4d3e2014-07-12 09:55:03 -07002234 if ($verbose && !$noret) {
Yacine Belkadi4092bac2012-11-26 22:22:27 +01002235 check_return_section($file, $declaration_name, $return_type);
2236 }
2237
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002238 output_declaration($declaration_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 'function',
2240 {'function' => $declaration_name,
2241 'module' => $modulename,
2242 'functiontype' => $return_type,
2243 'parameterlist' => \@parameterlist,
2244 'parameterdescs' => \%parameterdescs,
2245 'parametertypes' => \%parametertypes,
2246 'sectionlist' => \@sectionlist,
2247 'sections' => \%sections,
2248 'purpose' => $declaration_purpose
2249 });
2250}
2251
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252sub reset_state {
2253 $function = "";
2254 %constants = ();
2255 %parameterdescs = ();
2256 %parametertypes = ();
2257 @parameterlist = ();
2258 %sections = ();
2259 @sectionlist = ();
Randy Dunlapa1d94aa2008-12-19 08:49:30 -08002260 $sectcheck = "";
2261 $struct_actual = "";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 $prototype = "";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002263
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 $state = 0;
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002265 $split_doc_state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266}
2267
Jason Baron56afb0f2009-04-30 13:29:36 -04002268sub tracepoint_munge($) {
2269 my $file = shift;
2270 my $tracepointname = 0;
2271 my $tracepointargs = 0;
2272
Jason Baron3a9089f2009-12-01 12:18:49 -05002273 if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002274 $tracepointname = $1;
2275 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002276 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
2277 $tracepointname = $1;
2278 }
2279 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
2280 $tracepointname = $2;
2281 }
2282 $tracepointname =~ s/^\s+//; #strip leading whitespace
2283 if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
Jason Baron56afb0f2009-04-30 13:29:36 -04002284 $tracepointargs = $1;
2285 }
2286 if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002287 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
Jason Baron56afb0f2009-04-30 13:29:36 -04002288 "$prototype\n";
2289 } else {
2290 $prototype = "static inline void trace_$tracepointname($tracepointargs)";
2291 }
2292}
2293
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002294sub syscall_munge() {
2295 my $void = 0;
2296
2297 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2298## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2299 if ($prototype =~ m/SYSCALL_DEFINE0/) {
2300 $void = 1;
2301## $prototype = "long sys_$1(void)";
2302 }
2303
2304 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2305 if ($prototype =~ m/long (sys_.*?),/) {
2306 $prototype =~ s/,/\(/;
2307 } elsif ($void) {
2308 $prototype =~ s/\)/\(void\)/;
2309 }
2310
2311 # now delete all of the odd-number commas in $prototype
2312 # so that arg types & arg names don't have a comma between them
2313 my $count = 0;
2314 my $len = length($prototype);
2315 if ($void) {
2316 $len = 0; # skip the for-loop
2317 }
2318 for (my $ix = 0; $ix < $len; $ix++) {
2319 if (substr($prototype, $ix, 1) eq ',') {
2320 $count++;
2321 if ($count % 2 == 1) {
2322 substr($prototype, $ix, 1) = ' ';
2323 }
2324 }
2325 }
2326}
2327
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002328sub process_state3_function($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 my $x = shift;
2330 my $file = shift;
2331
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002332 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2333
Randy Dunlap890c78c2008-10-25 17:06:43 -07002334 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 # do nothing
2336 }
2337 elsif ($x =~ /([^\{]*)/) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002338 $prototype .= $1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002340
Randy Dunlap890c78c2008-10-25 17:06:43 -07002341 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002342 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2344 $prototype =~ s@^\s+@@gos; # strip leading spaces
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002345 if ($prototype =~ /SYSCALL_DEFINE/) {
2346 syscall_munge();
2347 }
Jason Baron3a9089f2009-12-01 12:18:49 -05002348 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
2349 $prototype =~ /DEFINE_SINGLE_EVENT/)
2350 {
Jason Baron56afb0f2009-04-30 13:29:36 -04002351 tracepoint_munge($file);
2352 }
Randy Dunlapb4870bc2009-02-11 13:04:33 -08002353 dump_function($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 reset_state();
2355 }
2356}
2357
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002358sub process_state3_type($$) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 my $x = shift;
2360 my $file = shift;
2361
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
2363 $x =~ s@^\s+@@gos; # strip leading spaces
2364 $x =~ s@\s+$@@gos; # strip trailing spaces
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002365 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
2366
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 if ($x =~ /^#/) {
2368 # To distinguish preprocessor directive from regular declaration later.
2369 $x .= ";";
2370 }
2371
2372 while (1) {
Randy Dunlap3c308792007-05-08 00:24:39 -07002373 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 $prototype .= $1 . $2;
2375 ($2 eq '{') && $brcount++;
2376 ($2 eq '}') && $brcount--;
2377 if (($2 eq ';') && ($brcount == 0)) {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002378 dump_declaration($prototype, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 reset_state();
Randy Dunlap3c308792007-05-08 00:24:39 -07002380 last;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 }
2382 $x = $3;
Randy Dunlap3c308792007-05-08 00:24:39 -07002383 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 $prototype .= $x;
2385 last;
2386 }
2387 }
2388}
2389
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002390# xml_escape: replace <, >, and & in the text stream;
2391#
2392# however, formatting controls that are generated internally/locally in the
2393# kernel-doc script are not escaped here; instead, they begin life like
2394# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
2395# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
2396# just before actual output; (this is done by local_unescape())
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397sub xml_escape($) {
2398 my $text = shift;
Randy Dunlapecfb2512006-06-25 05:49:13 -07002399 if (($output_mode eq "text") || ($output_mode eq "man")) {
2400 return $text;
2401 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 $text =~ s/\&/\\\\\\amp;/g;
2403 $text =~ s/\</\\\\\\lt;/g;
2404 $text =~ s/\>/\\\\\\gt;/g;
2405 return $text;
2406}
2407
Randy Dunlap6b5b55f2007-10-16 23:31:20 -07002408# convert local escape strings to html
2409# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
2410sub local_unescape($) {
2411 my $text = shift;
2412 if (($output_mode eq "text") || ($output_mode eq "man")) {
2413 return $text;
2414 }
2415 $text =~ s/\\\\\\\\lt:/</g;
2416 $text =~ s/\\\\\\\\gt:/>/g;
2417 return $text;
2418}
2419
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420sub process_file($) {
Randy Dunlap2283a112005-07-07 15:39:26 -07002421 my $file;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 my $identifier;
2423 my $func;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002424 my $descr;
Johannes Weiner64231332009-09-17 19:26:53 -07002425 my $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 my $initial_section_counter = $section_counter;
Ben Hutchings68f86662015-09-01 23:48:49 +01002427 my ($orig_file) = @_;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428
Randy Dunlap2283a112005-07-07 15:39:26 -07002429 if (defined($ENV{'SRCTREE'})) {
Ben Hutchings68f86662015-09-01 23:48:49 +01002430 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002431 }
2432 else {
Ben Hutchings68f86662015-09-01 23:48:49 +01002433 $file = $orig_file;
Randy Dunlap2283a112005-07-07 15:39:26 -07002434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 if (defined($source_map{$file})) {
2436 $file = $source_map{$file};
2437 }
2438
2439 if (!open(IN,"<$file")) {
2440 print STDERR "Error: Cannot open file $file\n";
2441 ++$errors;
2442 return;
2443 }
2444
Ilya Dryomova9e73142010-02-26 13:05:47 -08002445 $. = 1;
2446
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 $section_counter = 0;
2448 while (<IN>) {
Daniel Santos65478422012-10-04 17:15:05 -07002449 while (s/\\\s*$//) {
2450 $_ .= <IN>;
2451 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 if ($state == 0) {
2453 if (/$doc_start/o) {
2454 $state = 1; # next line is always the function name
Randy Dunlap850622d2006-06-25 05:48:55 -07002455 $in_doc_sect = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 }
2457 } elsif ($state == 1) { # this line is the function name (always)
2458 if (/$doc_block/o) {
2459 $state = 4;
2460 $contents = "";
2461 if ( $1 eq "" ) {
2462 $section = $section_intro;
2463 } else {
2464 $section = $1;
2465 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002466 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 elsif (/$doc_decl/o) {
2468 $identifier = $1;
2469 if (/\s*([\w\s]+?)\s*-/) {
2470 $identifier = $1;
2471 }
2472
2473 $state = 2;
2474 if (/-(.*)/) {
Randy Dunlap51f5a0c2007-07-19 01:48:24 -07002475 # strip leading/trailing/multiple spaces
Randy Dunlapa21217d2007-02-10 01:46:04 -08002476 $descr= $1;
2477 $descr =~ s/^\s*//;
2478 $descr =~ s/\s*$//;
Daniel Santos12ae6772012-10-04 17:15:10 -07002479 $descr =~ s/\s+/ /g;
Randy Dunlapa21217d2007-02-10 01:46:04 -08002480 $declaration_purpose = xml_escape($descr);
Johannes Weiner64231332009-09-17 19:26:53 -07002481 $in_purpose = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 } else {
2483 $declaration_purpose = "";
2484 }
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002485
2486 if (($declaration_purpose eq "") && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002487 print STDERR "${file}:$.: warning: missing initial short description on line:\n";
Randy Dunlap77cc23b2008-02-07 00:13:42 -08002488 print STDERR $_;
2489 ++$warnings;
2490 }
2491
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 if ($identifier =~ m/^struct/) {
2493 $decl_type = 'struct';
2494 } elsif ($identifier =~ m/^union/) {
2495 $decl_type = 'union';
2496 } elsif ($identifier =~ m/^enum/) {
2497 $decl_type = 'enum';
2498 } elsif ($identifier =~ m/^typedef/) {
2499 $decl_type = 'typedef';
2500 } else {
2501 $decl_type = 'function';
2502 }
2503
2504 if ($verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002505 print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 }
2507 } else {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002508 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 " - I thought it was a doc line\n";
2510 ++$warnings;
2511 $state = 0;
2512 }
2513 } elsif ($state == 2) { # look for head: lines, and include content
2514 if (/$doc_sect/o) {
2515 $newsection = $1;
2516 $newcontents = $2;
2517
Randy Dunlap792aa2f2008-02-07 00:13:41 -08002518 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap850622d2006-06-25 05:48:55 -07002519 if (!$in_doc_sect && $verbose) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002520 print STDERR "${file}:$.: warning: contents before sections\n";
Randy Dunlap850622d2006-06-25 05:48:55 -07002521 ++$warnings;
2522 }
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002523 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 $section = $section_default;
2525 }
2526
Randy Dunlap850622d2006-06-25 05:48:55 -07002527 $in_doc_sect = 1;
Johannes Weiner64231332009-09-17 19:26:53 -07002528 $in_purpose = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 $contents = $newcontents;
2530 if ($contents ne "") {
Randy Dunlap27205742006-10-11 01:22:12 -07002531 while ((substr($contents, 0, 1) eq " ") ||
2532 substr($contents, 0, 1) eq "\t") {
2533 $contents = substr($contents, 1);
Randy Dunlap05189492006-06-25 05:47:47 -07002534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 $contents .= "\n";
2536 }
2537 $section = $newsection;
2538 } elsif (/$doc_end/) {
Randy Dunlap4c98eca2010-03-10 15:22:02 -08002539 if (($contents ne "") && ($contents ne "\n")) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002540 dump_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 $section = $section_default;
2542 $contents = "";
2543 }
Randy Dunlap46b958e2008-04-28 02:16:35 -07002544 # look for doc_com + <text> + doc_end:
2545 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002546 print STDERR "${file}:$.: warning: suspicious ending line: $_";
Randy Dunlap46b958e2008-04-28 02:16:35 -07002547 ++$warnings;
2548 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549
2550 $prototype = "";
2551 $state = 3;
2552 $brcount = 0;
Randy Dunlap232acbc2006-06-25 05:47:48 -07002553# print STDERR "end of doc comment, looking for prototype\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 } elsif (/$doc_content/) {
2555 # miguel-style comment kludge, look for blank lines after
2556 # @parameter line to signify start of description
Johannes Weiner64231332009-09-17 19:26:53 -07002557 if ($1 eq "") {
2558 if ($section =~ m/^@/ || $section eq $section_context) {
2559 dump_section($file, $section, xml_escape($contents));
2560 $section = $section_default;
2561 $contents = "";
2562 } else {
2563 $contents .= "\n";
2564 }
2565 $in_purpose = 0;
2566 } elsif ($in_purpose == 1) {
2567 # Continued declaration purpose
2568 chomp($declaration_purpose);
2569 $declaration_purpose .= " " . xml_escape($1);
Daniel Santos12ae6772012-10-04 17:15:10 -07002570 $declaration_purpose =~ s/\s+/ /g;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 } else {
Randy Dunlapb9d973282009-06-09 08:50:38 -07002572 $contents .= $1 . "\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 }
2574 } else {
2575 # i dont know - bad line? ignore.
Bart Van Assched40e1e62015-09-04 15:43:21 -07002576 print STDERR "${file}:$.: warning: bad line: $_";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 ++$warnings;
2578 }
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002579 } elsif ($state == 5) { # scanning for split parameters
2580 # First line (state 1) needs to be a @parameter
2581 if ($split_doc_state == 1 && /$doc_split_sect/o) {
2582 $section = $1;
2583 $contents = $2;
2584 if ($contents ne "") {
2585 while ((substr($contents, 0, 1) eq " ") ||
2586 substr($contents, 0, 1) eq "\t") {
2587 $contents = substr($contents, 1);
2588 }
2589 $contents .= "\n";
2590 }
2591 $split_doc_state = 2;
2592 # Documentation block end */
2593 } elsif (/$doc_split_end/) {
2594 if (($contents ne "") && ($contents ne "\n")) {
2595 dump_section($file, $section, xml_escape($contents));
2596 $section = $section_default;
2597 $contents = "";
2598 }
2599 $state = 3;
2600 $split_doc_state = 0;
2601 # Regular text
2602 } elsif (/$doc_content/) {
2603 if ($split_doc_state == 2) {
2604 $contents .= $1 . "\n";
2605 } elsif ($split_doc_state == 1) {
2606 $split_doc_state = 4;
2607 print STDERR "Warning(${file}:$.): ";
2608 print STDERR "Incorrect use of kernel-doc format: $_";
2609 ++$warnings;
2610 }
2611 }
Randy Dunlap232acbc2006-06-25 05:47:48 -07002612 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
Danilo Cesar Lemes de Paulaa4c6ebe2015-08-04 09:04:08 -03002613 if (/$doc_split_start/) {
2614 $state = 5;
2615 $split_doc_state = 1;
2616 } elsif ($decl_type eq 'function') {
Randy Dunlap3c308792007-05-08 00:24:39 -07002617 process_state3_function($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 } else {
Randy Dunlap3c308792007-05-08 00:24:39 -07002619 process_state3_type($_, $file);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 }
2621 } elsif ($state == 4) {
2622 # Documentation block
Randy Dunlap3c308792007-05-08 00:24:39 -07002623 if (/$doc_block/) {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002624 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 $contents = "";
2626 $function = "";
2627 %constants = ();
2628 %parameterdescs = ();
2629 %parametertypes = ();
2630 @parameterlist = ();
2631 %sections = ();
2632 @sectionlist = ();
2633 $prototype = "";
2634 if ( $1 eq "" ) {
2635 $section = $section_intro;
2636 } else {
2637 $section = $1;
2638 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002639 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 elsif (/$doc_end/)
2641 {
Randy Dunlap94dc7ad2008-04-28 02:16:34 -07002642 dump_doc_section($file, $section, xml_escape($contents));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 $contents = "";
2644 $function = "";
2645 %constants = ();
2646 %parameterdescs = ();
2647 %parametertypes = ();
2648 @parameterlist = ();
2649 %sections = ();
2650 @sectionlist = ();
2651 $prototype = "";
2652 $state = 0;
2653 }
2654 elsif (/$doc_content/)
2655 {
2656 if ( $1 eq "" )
2657 {
2658 $contents .= $blankline;
2659 }
2660 else
2661 {
2662 $contents .= $1 . "\n";
Randy Dunlap3c3b8092006-02-01 03:06:58 -08002663 }
Randy Dunlap3c308792007-05-08 00:24:39 -07002664 }
2665 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666 }
2667 if ($initial_section_counter == $section_counter) {
Bart Van Assched40e1e62015-09-04 15:43:21 -07002668 print STDERR "${file}:1: warning: no structured comments found\n";
Johannes Berge946c43a2013-11-12 15:11:12 -08002669 if (($function_only == 1) && ($show_not_found == 1)) {
2670 print STDERR " Was looking for '$_'.\n" for keys %function_table;
2671 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 if ($output_mode eq "xml") {
2673 # The template wants at least one RefEntry here; make one.
2674 print "<refentry>\n";
2675 print " <refnamediv>\n";
2676 print " <refname>\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01002677 print " ${orig_file}\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678 print " </refname>\n";
2679 print " <refpurpose>\n";
2680 print " Document generation inconsistency\n";
2681 print " </refpurpose>\n";
2682 print " </refnamediv>\n";
2683 print " <refsect1>\n";
2684 print " <title>\n";
2685 print " Oops\n";
2686 print " </title>\n";
2687 print " <warning>\n";
2688 print " <para>\n";
2689 print " The template for this document tried to insert\n";
2690 print " the structured comment from the file\n";
Ben Hutchings68f86662015-09-01 23:48:49 +01002691 print " <filename>${orig_file}</filename> at this point,\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 print " but none was found.\n";
2693 print " This dummy section is inserted to allow\n";
2694 print " generation to continue.\n";
2695 print " </para>\n";
2696 print " </warning>\n";
2697 print " </refsect1>\n";
2698 print "</refentry>\n";
2699 }
2700 }
2701}
Randy Dunlap8484baa2011-01-05 16:28:43 -08002702
2703
2704$kernelversion = get_kernel_version();
2705
2706# generate a sequence of code that will splice in highlighting information
2707# using the s// operator.
Mauro Carvalho Chehab1ef06232015-11-17 13:29:49 -02002708for (my $k = 0; $k < @highlights; $k++) {
Danilo Cesar Lemes de Paula4d732702015-09-07 17:01:59 -03002709 my $pattern = $highlights[$k][0];
2710 my $result = $highlights[$k][1];
2711# print STDERR "scanning pattern:$pattern, highlight:($result)\n";
2712 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n";
Randy Dunlap8484baa2011-01-05 16:28:43 -08002713}
2714
2715# Read the file that maps relative names to absolute names for
2716# separate source and object directories and for shadow trees.
2717if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
2718 my ($relname, $absname);
2719 while(<SOURCE_MAP>) {
2720 chop();
2721 ($relname, $absname) = (split())[0..1];
2722 $relname =~ s:^/+::;
2723 $source_map{$relname} = $absname;
2724 }
2725 close(SOURCE_MAP);
2726}
2727
2728foreach (@ARGV) {
2729 chomp;
2730 process_file($_);
2731}
2732if ($verbose && $errors) {
2733 print STDERR "$errors errors\n";
2734}
2735if ($verbose && $warnings) {
2736 print STDERR "$warnings warnings\n";
2737}
2738
2739exit($errors);