xref: /linux/scripts/kernel-doc (revision fadc0b31cba0bb56bce1a3259cc60e4d7ee67333)
11da177e4SLinus Torvalds#!/usr/bin/perl -w
21da177e4SLinus Torvalds
31da177e4SLinus Torvaldsuse strict;
41da177e4SLinus Torvalds
51da177e4SLinus Torvalds## Copyright (c) 1998 Michael Zucchi, All Rights Reserved        ##
61da177e4SLinus Torvalds## Copyright (C) 2000, 1  Tim Waugh <twaugh@redhat.com>          ##
71da177e4SLinus Torvalds## Copyright (C) 2001  Simon Huggins                             ##
870c95b00SRandy Dunlap## Copyright (C) 2005-2012  Randy Dunlap                         ##
91b40c194SDan Luedtke## Copyright (C) 2012  Dan Luedtke                               ##
101da177e4SLinus Torvalds## 								 ##
111da177e4SLinus Torvalds## #define enhancements by Armin Kuster <akuster@mvista.com>	 ##
121da177e4SLinus Torvalds## Copyright (c) 2000 MontaVista Software, Inc.			 ##
131da177e4SLinus Torvalds## 								 ##
141da177e4SLinus Torvalds## This software falls under the GNU General Public License.     ##
151da177e4SLinus Torvalds## Please read the COPYING file for more information             ##
161da177e4SLinus Torvalds
171da177e4SLinus Torvalds# 18/01/2001 - 	Cleanups
181da177e4SLinus Torvalds# 		Functions prototyped as foo(void) same as foo()
191da177e4SLinus Torvalds# 		Stop eval'ing where we don't need to.
201da177e4SLinus Torvalds# -- huggie@earth.li
211da177e4SLinus Torvalds
221da177e4SLinus Torvalds# 27/06/2001 -  Allowed whitespace after initial "/**" and
231da177e4SLinus Torvalds#               allowed comments before function declarations.
241da177e4SLinus Torvalds# -- Christian Kreibich <ck@whoop.org>
251da177e4SLinus Torvalds
261da177e4SLinus Torvalds# Still to do:
271da177e4SLinus Torvalds# 	- add perldoc documentation
281da177e4SLinus Torvalds# 	- Look more closely at some of the scarier bits :)
291da177e4SLinus Torvalds
301da177e4SLinus Torvalds# 26/05/2001 - 	Support for separate source and object trees.
311da177e4SLinus Torvalds#		Return error code.
321da177e4SLinus Torvalds# 		Keith Owens <kaos@ocs.com.au>
331da177e4SLinus Torvalds
341da177e4SLinus Torvalds# 23/09/2001 - Added support for typedefs, structs, enums and unions
351da177e4SLinus Torvalds#              Support for Context section; can be terminated using empty line
361da177e4SLinus Torvalds#              Small fixes (like spaces vs. \s in regex)
371da177e4SLinus Torvalds# -- Tim Jansen <tim@tjansen.de>
381da177e4SLinus Torvalds
391b40c194SDan Luedtke# 25/07/2012 - Added support for HTML5
401b40c194SDan Luedtke# -- Dan Luedtke <mail@danrl.de>
411da177e4SLinus Torvalds
42*fadc0b31SJani Nikulasub usage {
43*fadc0b31SJani Nikula    my $message = <<"EOF";
44*fadc0b31SJani NikulaUsage: $0 [OPTION ...] FILE ...
451da177e4SLinus Torvalds
46*fadc0b31SJani NikulaRead C language source or header FILEs, extract embedded documentation comments,
47*fadc0b31SJani Nikulaand print formatted documentation to standard output.
481da177e4SLinus Torvalds
49*fadc0b31SJani NikulaThe documentation comments are identified by "/**" opening comment mark. See
50*fadc0b31SJani NikulaDocumentation/kernel-doc-nano-HOWTO.txt for the documentation comment syntax.
51*fadc0b31SJani Nikula
52*fadc0b31SJani NikulaOutput format selection (mutually exclusive):
53*fadc0b31SJani Nikula  -docbook		Output DocBook format.
54*fadc0b31SJani Nikula  -html			Output HTML format.
55*fadc0b31SJani Nikula  -html5		Output HTML5 format.
56*fadc0b31SJani Nikula  -list			Output symbol list format. This is for use by docproc.
57*fadc0b31SJani Nikula  -man			Output troff manual page format. This is the default.
58*fadc0b31SJani Nikula  -text			Output plain text format.
59*fadc0b31SJani Nikula
60*fadc0b31SJani NikulaOutput selection (mutually exclusive):
61*fadc0b31SJani Nikula  -function NAME	Only output documentation for the given function(s)
62*fadc0b31SJani Nikula			or DOC: section title(s). All other functions and DOC:
63*fadc0b31SJani Nikula			sections are ignored. May be specified multiple times.
64*fadc0b31SJani Nikula  -nofunction NAME	Do NOT output documentation for the given function(s);
65*fadc0b31SJani Nikula			only output documentation for the other functions and
66*fadc0b31SJani Nikula			DOC: sections. May be specified multiple times.
67*fadc0b31SJani Nikula
68*fadc0b31SJani NikulaOutput selection modifiers:
69*fadc0b31SJani Nikula  -no-doc-sections	Do not output DOC: sections.
70*fadc0b31SJani Nikula
71*fadc0b31SJani NikulaOther parameters:
72*fadc0b31SJani Nikula  -v			Verbose output, more warnings and other information.
73*fadc0b31SJani Nikula  -h			Print this help.
74*fadc0b31SJani Nikula
75*fadc0b31SJani NikulaEOF
76*fadc0b31SJani Nikula    print $message;
77*fadc0b31SJani Nikula    exit 1;
78*fadc0b31SJani Nikula}
791da177e4SLinus Torvalds
801da177e4SLinus Torvalds#
811da177e4SLinus Torvalds# format of comments.
821da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure.
831da177e4SLinus Torvalds#                         (...)* signifies 0 or more structure elements
841da177e4SLinus Torvalds# /**
851da177e4SLinus Torvalds#  * function_name(:)? (- short description)?
861da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)*
871da177e4SLinus Torvalds# (* a blank line)?
881da177e4SLinus Torvalds#  * (Description:)? (Description of function)?
891da177e4SLinus Torvalds#  * (section header: (section description)? )*
901da177e4SLinus Torvalds#  (*)?*/
911da177e4SLinus Torvalds#
921da177e4SLinus Torvalds# So .. the trivial example would be:
931da177e4SLinus Torvalds#
941da177e4SLinus Torvalds# /**
951da177e4SLinus Torvalds#  * my_function
96b9d97328SRandy Dunlap#  */
971da177e4SLinus Torvalds#
98891dcd2fSRandy Dunlap# If the Description: header tag is omitted, then there must be a blank line
991da177e4SLinus Torvalds# after the last parameter specification.
1001da177e4SLinus Torvalds# e.g.
1011da177e4SLinus Torvalds# /**
1021da177e4SLinus Torvalds#  * my_function - does my stuff
1031da177e4SLinus Torvalds#  * @my_arg: its mine damnit
1041da177e4SLinus Torvalds#  *
1051da177e4SLinus Torvalds#  * Does my stuff explained.
1061da177e4SLinus Torvalds#  */
1071da177e4SLinus Torvalds#
1081da177e4SLinus Torvalds#  or, could also use:
1091da177e4SLinus Torvalds# /**
1101da177e4SLinus Torvalds#  * my_function - does my stuff
1111da177e4SLinus Torvalds#  * @my_arg: its mine damnit
1121da177e4SLinus Torvalds#  * Description: Does my stuff explained.
1131da177e4SLinus Torvalds#  */
1141da177e4SLinus Torvalds# etc.
1151da177e4SLinus Torvalds#
116b9d97328SRandy Dunlap# Besides functions you can also write documentation for structs, unions,
1171da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name
1181da177e4SLinus Torvalds# of the declaration;  the struct/union/enum/typedef must always precede
1191da177e4SLinus Torvalds# the name. Nesting of declarations is not supported.
1201da177e4SLinus Torvalds# Use the argument mechanism to document members or constants.
1211da177e4SLinus Torvalds# e.g.
1221da177e4SLinus Torvalds# /**
1231da177e4SLinus Torvalds#  * struct my_struct - short description
1241da177e4SLinus Torvalds#  * @a: first member
1251da177e4SLinus Torvalds#  * @b: second member
1261da177e4SLinus Torvalds#  *
1271da177e4SLinus Torvalds#  * Longer description
1281da177e4SLinus Torvalds#  */
1291da177e4SLinus Torvalds# struct my_struct {
1301da177e4SLinus Torvalds#     int a;
1311da177e4SLinus Torvalds#     int b;
132aeec46b9SMartin Waitz# /* private: */
133aeec46b9SMartin Waitz#     int c;
1341da177e4SLinus Torvalds# };
1351da177e4SLinus Torvalds#
1361da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description.
1371da177e4SLinus Torvalds#
138a4c6ebedSDanilo Cesar Lemes de Paula# For really longs structs, you can also describe arguments inside the
139a4c6ebedSDanilo Cesar Lemes de Paula# body of the struct.
140a4c6ebedSDanilo Cesar Lemes de Paula# eg.
141a4c6ebedSDanilo Cesar Lemes de Paula# /**
142a4c6ebedSDanilo Cesar Lemes de Paula#  * struct my_struct - short description
143a4c6ebedSDanilo Cesar Lemes de Paula#  * @a: first member
144a4c6ebedSDanilo Cesar Lemes de Paula#  * @b: second member
145a4c6ebedSDanilo Cesar Lemes de Paula#  *
146a4c6ebedSDanilo Cesar Lemes de Paula#  * Longer description
147a4c6ebedSDanilo Cesar Lemes de Paula#  */
148a4c6ebedSDanilo Cesar Lemes de Paula# struct my_struct {
149a4c6ebedSDanilo Cesar Lemes de Paula#     int a;
150a4c6ebedSDanilo Cesar Lemes de Paula#     int b;
151a4c6ebedSDanilo Cesar Lemes de Paula#     /**
152a4c6ebedSDanilo Cesar Lemes de Paula#      * @c: This is longer description of C
153a4c6ebedSDanilo Cesar Lemes de Paula#      *
154a4c6ebedSDanilo Cesar Lemes de Paula#      * You can use paragraphs to describe arguments
155a4c6ebedSDanilo Cesar Lemes de Paula#      * using this method.
156a4c6ebedSDanilo Cesar Lemes de Paula#      */
157a4c6ebedSDanilo Cesar Lemes de Paula#     int c;
158a4c6ebedSDanilo Cesar Lemes de Paula# };
159a4c6ebedSDanilo Cesar Lemes de Paula#
160a4c6ebedSDanilo Cesar Lemes de Paula# This should be use only for struct/enum members.
161a4c6ebedSDanilo Cesar Lemes de Paula#
1621da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you
1631da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions
1641da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an
1651da177e4SLinus Torvalds# empty line.
1664092bac7SYacine Belkadi# A non-void function should have a "Return:" section describing the return
1674092bac7SYacine Belkadi# value(s).
1681da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked
1691da177e4SLinus Torvalds# appropriately in DocBook.
1701da177e4SLinus Torvalds#
1711da177e4SLinus Torvalds# Example:
1721da177e4SLinus Torvalds# /**
1731da177e4SLinus Torvalds#  * user_function - function that can only be called in user context
1741da177e4SLinus Torvalds#  * @a: some argument
1751da177e4SLinus Torvalds#  * Context: !in_interrupt()
1761da177e4SLinus Torvalds#  *
1771da177e4SLinus Torvalds#  * Some description
1781da177e4SLinus Torvalds#  * Example:
1791da177e4SLinus Torvalds#  *    user_function(22);
1801da177e4SLinus Torvalds#  */
1811da177e4SLinus Torvalds# ...
1821da177e4SLinus Torvalds#
1831da177e4SLinus Torvalds#
1841da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special
1851da177e4SLinus Torvalds# patterns, which are highlighted appropriately.
1861da177e4SLinus Torvalds#
1871da177e4SLinus Torvalds# 'funcname()' - function
1881da177e4SLinus Torvalds# '$ENVVAR' - environmental variable
1891da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct')
1901da177e4SLinus Torvalds# '@parameter' - name of a parameter
1911da177e4SLinus Torvalds# '%CONST' - name of a constant.
1921da177e4SLinus Torvalds
1938484baaaSRandy Dunlap## init lots of data
1948484baaaSRandy Dunlap
1951da177e4SLinus Torvaldsmy $errors = 0;
1961da177e4SLinus Torvaldsmy $warnings = 0;
1975f8c7c98SRandy Dunlapmy $anon_struct_union = 0;
1981da177e4SLinus Torvalds
1991da177e4SLinus Torvalds# match expressions used to find embedded type information
2001da177e4SLinus Torvaldsmy $type_constant = '\%([-_\w]+)';
2011da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)';
2021da177e4SLinus Torvaldsmy $type_param = '\@(\w+)';
2033eb014a1SRandy Dunlapmy $type_struct = '\&((struct\s*)*[_\w]+)';
2046b5b55f6SRandy Dunlapmy $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
2051da177e4SLinus Torvaldsmy $type_env = '(\$\w+)';
2061da177e4SLinus Torvalds
2071da177e4SLinus Torvalds# Output conversion substitutions.
2081da177e4SLinus Torvalds#  One for each output format
2091da177e4SLinus Torvalds
2101da177e4SLinus Torvalds# these work fairly well
2114d732701SDanilo Cesar Lemes de Paulamy @highlights_html = (
2124d732701SDanilo Cesar Lemes de Paula                       [$type_constant, "<i>\$1</i>"],
2134d732701SDanilo Cesar Lemes de Paula                       [$type_func, "<b>\$1</b>"],
2144d732701SDanilo Cesar Lemes de Paula                       [$type_struct_xml, "<i>\$1</i>"],
2154d732701SDanilo Cesar Lemes de Paula                       [$type_env, "<b><i>\$1</i></b>"],
2164d732701SDanilo Cesar Lemes de Paula                       [$type_param, "<tt><b>\$1</b></tt>"]
2174d732701SDanilo Cesar Lemes de Paula                      );
2186b5b55f6SRandy Dunlapmy $local_lt = "\\\\\\\\lt:";
2196b5b55f6SRandy Dunlapmy $local_gt = "\\\\\\\\gt:";
2206b5b55f6SRandy Dunlapmy $blankline_html = $local_lt . "p" . $local_gt;	# was "<p>"
2211da177e4SLinus Torvalds
2221b40c194SDan Luedtke# html version 5
2234d732701SDanilo Cesar Lemes de Paulamy @highlights_html5 = (
2244d732701SDanilo Cesar Lemes de Paula                        [$type_constant, "<span class=\"const\">\$1</span>"],
2254d732701SDanilo Cesar Lemes de Paula                        [$type_func, "<span class=\"func\">\$1</span>"],
2264d732701SDanilo Cesar Lemes de Paula                        [$type_struct_xml, "<span class=\"struct\">\$1</span>"],
2274d732701SDanilo Cesar Lemes de Paula                        [$type_env, "<span class=\"env\">\$1</span>"],
2284d732701SDanilo Cesar Lemes de Paula                        [$type_param, "<span class=\"param\">\$1</span>]"]
2294d732701SDanilo Cesar Lemes de Paula		       );
2301b40c194SDan Luedtkemy $blankline_html5 = $local_lt . "br /" . $local_gt;
2311b40c194SDan Luedtke
2321da177e4SLinus Torvalds# XML, docbook format
2334d732701SDanilo Cesar Lemes de Paulamy @highlights_xml = (
2344d732701SDanilo Cesar Lemes de Paula                      ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"],
2354d732701SDanilo Cesar Lemes de Paula                      [$type_constant, "<constant>\$1</constant>"],
2364d732701SDanilo Cesar Lemes de Paula                      [$type_struct_xml, "<structname>\$1</structname>"],
2374d732701SDanilo Cesar Lemes de Paula                      [$type_param, "<parameter>\$1</parameter>"],
2384d732701SDanilo Cesar Lemes de Paula                      [$type_func, "<function>\$1</function>"],
2394d732701SDanilo Cesar Lemes de Paula                      [$type_env, "<envar>\$1</envar>"]
2404d732701SDanilo Cesar Lemes de Paula		     );
2415c98fc03SJohannes Bergmy $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
2421da177e4SLinus Torvalds
2431da177e4SLinus Torvalds# gnome, docbook format
2444d732701SDanilo Cesar Lemes de Paulamy @highlights_gnome = (
2454d732701SDanilo Cesar Lemes de Paula                        [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"],
2464d732701SDanilo Cesar Lemes de Paula                        [$type_func, "<function>\$1</function>"],
2474d732701SDanilo Cesar Lemes de Paula                        [$type_struct, "<structname>\$1</structname>"],
2484d732701SDanilo Cesar Lemes de Paula                        [$type_env, "<envar>\$1</envar>"],
2494d732701SDanilo Cesar Lemes de Paula                        [$type_param, "<parameter>\$1</parameter>" ]
2504d732701SDanilo Cesar Lemes de Paula		       );
2511da177e4SLinus Torvaldsmy $blankline_gnome = "</para><para>\n";
2521da177e4SLinus Torvalds
2531da177e4SLinus Torvalds# these are pretty rough
2544d732701SDanilo Cesar Lemes de Paulamy @highlights_man = (
2554d732701SDanilo Cesar Lemes de Paula                      [$type_constant, "\$1"],
2564d732701SDanilo Cesar Lemes de Paula                      [$type_func, "\\\\fB\$1\\\\fP"],
2574d732701SDanilo Cesar Lemes de Paula                      [$type_struct, "\\\\fI\$1\\\\fP"],
2584d732701SDanilo Cesar Lemes de Paula                      [$type_param, "\\\\fI\$1\\\\fP"]
2594d732701SDanilo Cesar Lemes de Paula		     );
2601da177e4SLinus Torvaldsmy $blankline_man = "";
2611da177e4SLinus Torvalds
2621da177e4SLinus Torvalds# text-mode
2634d732701SDanilo Cesar Lemes de Paulamy @highlights_text = (
2644d732701SDanilo Cesar Lemes de Paula                       [$type_constant, "\$1"],
2654d732701SDanilo Cesar Lemes de Paula                       [$type_func, "\$1"],
2664d732701SDanilo Cesar Lemes de Paula                       [$type_struct, "\$1"],
2674d732701SDanilo Cesar Lemes de Paula                       [$type_param, "\$1"]
2684d732701SDanilo Cesar Lemes de Paula		      );
2691da177e4SLinus Torvaldsmy $blankline_text = "";
2701da177e4SLinus Torvalds
271eda603f6SJohannes Berg# list mode
2724d732701SDanilo Cesar Lemes de Paulamy @highlights_list = (
2734d732701SDanilo Cesar Lemes de Paula                       [$type_constant, "\$1"],
2744d732701SDanilo Cesar Lemes de Paula                       [$type_func, "\$1"],
2754d732701SDanilo Cesar Lemes de Paula                       [$type_struct, "\$1"],
2764d732701SDanilo Cesar Lemes de Paula                       [$type_param, "\$1"]
2774d732701SDanilo Cesar Lemes de Paula		      );
278eda603f6SJohannes Bergmy $blankline_list = "";
2791da177e4SLinus Torvalds
2801da177e4SLinus Torvalds# read arguments
2811da177e4SLinus Torvaldsif ($#ARGV == -1) {
2821da177e4SLinus Torvalds    usage();
2831da177e4SLinus Torvalds}
2841da177e4SLinus Torvalds
2858484baaaSRandy Dunlapmy $kernelversion;
2868484baaaSRandy Dunlapmy $dohighlight = "";
2878484baaaSRandy Dunlap
2881da177e4SLinus Torvaldsmy $verbose = 0;
2891da177e4SLinus Torvaldsmy $output_mode = "man";
290e314ba31SDaniel Santosmy $output_preformatted = 0;
2914b44595aSJohannes Bergmy $no_doc_sections = 0;
2924d732701SDanilo Cesar Lemes de Paulamy @highlights = @highlights_man;
2931da177e4SLinus Torvaldsmy $blankline = $blankline_man;
2941da177e4SLinus Torvaldsmy $modulename = "Kernel API";
2951da177e4SLinus Torvaldsmy $function_only = 0;
296b2c4105bSBen Hutchingsmy $show_not_found = 0;
297b2c4105bSBen Hutchings
298b2c4105bSBen Hutchingsmy @build_time;
299b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
300b2c4105bSBen Hutchings    (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
301b2c4105bSBen Hutchings    @build_time = gmtime($seconds);
302b2c4105bSBen Hutchings} else {
303b2c4105bSBen Hutchings    @build_time = localtime;
304b2c4105bSBen Hutchings}
305b2c4105bSBen Hutchings
3061da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
3071da177e4SLinus Torvalds		'July', 'August', 'September', 'October',
308b2c4105bSBen Hutchings		'November', 'December')[$build_time[4]] .
309b2c4105bSBen Hutchings  " " . ($build_time[5]+1900);
3101da177e4SLinus Torvalds
3118484baaaSRandy Dunlap# Essentially these are globals.
312b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something.
313b9d97328SRandy Dunlap# CAVEAT EMPTOR!  Some of the others I localised may not want to be, which
3141da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs.
3151da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose);
3161da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type);
3171c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map);
3181da177e4SLinus Torvalds
319bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) {
320bd0e88e5SRandy Dunlap	$verbose = "$ENV{'KBUILD_VERBOSE'}";
321bd0e88e5SRandy Dunlap}
322bd0e88e5SRandy Dunlap
3231da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where
3241da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
3251da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
3261da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy
3271da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed
3281da177e4SLinus Torvalds# into html.
3291da177e4SLinus Torvaldsmy $section_counter = 0;
3301da177e4SLinus Torvalds
3311da177e4SLinus Torvaldsmy $lineprefix="";
3321da177e4SLinus Torvalds
3331da177e4SLinus Torvalds# states
3341da177e4SLinus Torvalds# 0 - normal code
3351da177e4SLinus Torvalds# 1 - looking for function name
3361da177e4SLinus Torvalds# 2 - scanning field start.
3371da177e4SLinus Torvalds# 3 - scanning prototype.
3381da177e4SLinus Torvalds# 4 - documentation block
339a4c6ebedSDanilo Cesar Lemes de Paula# 5 - gathering documentation outside main block
3401da177e4SLinus Torvaldsmy $state;
341850622dfSRandy Dunlapmy $in_doc_sect;
3421da177e4SLinus Torvalds
343a4c6ebedSDanilo Cesar Lemes de Paula# Split Doc State
344a4c6ebedSDanilo Cesar Lemes de Paula# 0 - Invalid (Before start or after finish)
345a4c6ebedSDanilo Cesar Lemes de Paula# 1 - Is started (the /** was found inside a struct)
346a4c6ebedSDanilo Cesar Lemes de Paula# 2 - The @parameter header was found, start accepting multi paragraph text.
347a4c6ebedSDanilo Cesar Lemes de Paula# 3 - Finished (the */ was found)
348a4c6ebedSDanilo Cesar Lemes de Paula# 4 - Error - Comment without header was found. Spit a warning as it's not
349a4c6ebedSDanilo Cesar Lemes de Paula#     proper kernel-doc and ignore the rest.
350a4c6ebedSDanilo Cesar Lemes de Paulamy $split_doc_state;
351a4c6ebedSDanilo Cesar Lemes de Paula
3521da177e4SLinus Torvalds#declaration types: can be
3531da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef'
3541da177e4SLinus Torvaldsmy $decl_type;
3551da177e4SLinus Torvalds
3561da177e4SLinus Torvaldsmy $doc_special = "\@\%\$\&";
3571da177e4SLinus Torvalds
3581da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
3591da177e4SLinus Torvaldsmy $doc_end = '\*/';
3601da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*';
36112ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?';
3621da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)';
363891dcd2fSRandy Dunlapmy $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
36412ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)';
3651da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?';
366a4c6ebedSDanilo Cesar Lemes de Paulamy $doc_split_start = '^\s*/\*\*\s*$';
367a4c6ebedSDanilo Cesar Lemes de Paulamy $doc_split_sect = '\s*\*\s*(@[\w\s]+):(.*)';
368a4c6ebedSDanilo Cesar Lemes de Paulamy $doc_split_end = '^\s*\*/\s*$';
3691da177e4SLinus Torvalds
3701da177e4SLinus Torvaldsmy %constants;
3711da177e4SLinus Torvaldsmy %parameterdescs;
3721da177e4SLinus Torvaldsmy @parameterlist;
3731da177e4SLinus Torvaldsmy %sections;
3741da177e4SLinus Torvaldsmy @sectionlist;
375a1d94aa5SRandy Dunlapmy $sectcheck;
376a1d94aa5SRandy Dunlapmy $struct_actual;
3771da177e4SLinus Torvalds
3781da177e4SLinus Torvaldsmy $contents = "";
3791da177e4SLinus Torvaldsmy $section_default = "Description";	# default section
3801da177e4SLinus Torvaldsmy $section_intro = "Introduction";
3811da177e4SLinus Torvaldsmy $section = $section_default;
3821da177e4SLinus Torvaldsmy $section_context = "Context";
3834092bac7SYacine Belkadimy $section_return = "Return";
3841da177e4SLinus Torvalds
3851da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --";
3861da177e4SLinus Torvalds
3871da177e4SLinus Torvaldsreset_state();
3881da177e4SLinus Torvalds
3891da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) {
3901da177e4SLinus Torvalds    my $cmd = shift @ARGV;
3911da177e4SLinus Torvalds    if ($cmd eq "-html") {
3921da177e4SLinus Torvalds	$output_mode = "html";
3934d732701SDanilo Cesar Lemes de Paula	@highlights = @highlights_html;
3941da177e4SLinus Torvalds	$blankline = $blankline_html;
3951b40c194SDan Luedtke    } elsif ($cmd eq "-html5") {
3961b40c194SDan Luedtke	$output_mode = "html5";
3974d732701SDanilo Cesar Lemes de Paula	@highlights = @highlights_html5;
3981b40c194SDan Luedtke	$blankline = $blankline_html5;
3991da177e4SLinus Torvalds    } elsif ($cmd eq "-man") {
4001da177e4SLinus Torvalds	$output_mode = "man";
4014d732701SDanilo Cesar Lemes de Paula	@highlights = @highlights_man;
4021da177e4SLinus Torvalds	$blankline = $blankline_man;
4031da177e4SLinus Torvalds    } elsif ($cmd eq "-text") {
4041da177e4SLinus Torvalds	$output_mode = "text";
4054d732701SDanilo Cesar Lemes de Paula	@highlights = @highlights_text;
4061da177e4SLinus Torvalds	$blankline = $blankline_text;
4071da177e4SLinus Torvalds    } elsif ($cmd eq "-docbook") {
4081da177e4SLinus Torvalds	$output_mode = "xml";
4094d732701SDanilo Cesar Lemes de Paula	@highlights = @highlights_xml;
4101da177e4SLinus Torvalds	$blankline = $blankline_xml;
411eda603f6SJohannes Berg    } elsif ($cmd eq "-list") {
412eda603f6SJohannes Berg	$output_mode = "list";
4134d732701SDanilo Cesar Lemes de Paula	@highlights = @highlights_list;
414eda603f6SJohannes Berg	$blankline = $blankline_list;
4151da177e4SLinus Torvalds    } elsif ($cmd eq "-gnome") {
4161da177e4SLinus Torvalds	$output_mode = "gnome";
4174d732701SDanilo Cesar Lemes de Paula	@highlights = @highlights_gnome;
4181da177e4SLinus Torvalds	$blankline = $blankline_gnome;
4191da177e4SLinus Torvalds    } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
4201da177e4SLinus Torvalds	$modulename = shift @ARGV;
4211da177e4SLinus Torvalds    } elsif ($cmd eq "-function") { # to only output specific functions
4221da177e4SLinus Torvalds	$function_only = 1;
4231da177e4SLinus Torvalds	$function = shift @ARGV;
4241da177e4SLinus Torvalds	$function_table{$function} = 1;
4251da177e4SLinus Torvalds    } elsif ($cmd eq "-nofunction") { # to only output specific functions
4261da177e4SLinus Torvalds	$function_only = 2;
4271da177e4SLinus Torvalds	$function = shift @ARGV;
4281da177e4SLinus Torvalds	$function_table{$function} = 1;
4291da177e4SLinus Torvalds    } elsif ($cmd eq "-v") {
4301da177e4SLinus Torvalds	$verbose = 1;
4311da177e4SLinus Torvalds    } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
4321da177e4SLinus Torvalds	usage();
4334b44595aSJohannes Berg    } elsif ($cmd eq '-no-doc-sections') {
4344b44595aSJohannes Berg	    $no_doc_sections = 1;
435e946c43aSJohannes Berg    } elsif ($cmd eq '-show-not-found') {
436e946c43aSJohannes Berg	$show_not_found = 1;
4371da177e4SLinus Torvalds    }
4381da177e4SLinus Torvalds}
4391da177e4SLinus Torvalds
4408484baaaSRandy Dunlap# continue execution near EOF;
4418484baaaSRandy Dunlap
44253f049faSBorislav Petkov# get kernel version from env
44353f049faSBorislav Petkovsub get_kernel_version() {
4441b9bc22dSJohannes Berg    my $version = 'unknown kernel version';
44553f049faSBorislav Petkov
44653f049faSBorislav Petkov    if (defined($ENV{'KERNELVERSION'})) {
44753f049faSBorislav Petkov	$version = $ENV{'KERNELVERSION'};
44853f049faSBorislav Petkov    }
44953f049faSBorislav Petkov    return $version;
45053f049faSBorislav Petkov}
4511da177e4SLinus Torvalds
4521da177e4SLinus Torvalds##
4531da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose.
4541da177e4SLinus Torvalds#
4551da177e4SLinus Torvaldssub dump_section {
45694dc7ad5SRandy Dunlap    my $file = shift;
4571da177e4SLinus Torvalds    my $name = shift;
4581da177e4SLinus Torvalds    my $contents = join "\n", @_;
4591da177e4SLinus Torvalds
4601da177e4SLinus Torvalds    if ($name =~ m/$type_constant/) {
4611da177e4SLinus Torvalds	$name = $1;
4621da177e4SLinus Torvalds#	print STDERR "constant section '$1' = '$contents'\n";
4631da177e4SLinus Torvalds	$constants{$name} = $contents;
4641da177e4SLinus Torvalds    } elsif ($name =~ m/$type_param/) {
4651da177e4SLinus Torvalds#	print STDERR "parameter def '$1' = '$contents'\n";
4661da177e4SLinus Torvalds	$name = $1;
4671da177e4SLinus Torvalds	$parameterdescs{$name} = $contents;
468a1d94aa5SRandy Dunlap	$sectcheck = $sectcheck . $name . " ";
469ced69090SRandy Dunlap    } elsif ($name eq "@\.\.\.") {
470ced69090SRandy Dunlap#	print STDERR "parameter def '...' = '$contents'\n";
471ced69090SRandy Dunlap	$name = "...";
472ced69090SRandy Dunlap	$parameterdescs{$name} = $contents;
473a1d94aa5SRandy Dunlap	$sectcheck = $sectcheck . $name . " ";
4741da177e4SLinus Torvalds    } else {
4751da177e4SLinus Torvalds#	print STDERR "other section '$name' = '$contents'\n";
47694dc7ad5SRandy Dunlap	if (defined($sections{$name}) && ($sections{$name} ne "")) {
477d40e1e65SBart Van Assche		print STDERR "${file}:$.: error: duplicate section name '$name'\n";
47894dc7ad5SRandy Dunlap		++$errors;
47994dc7ad5SRandy Dunlap	}
4801da177e4SLinus Torvalds	$sections{$name} = $contents;
4811da177e4SLinus Torvalds	push @sectionlist, $name;
4821da177e4SLinus Torvalds    }
4831da177e4SLinus Torvalds}
4841da177e4SLinus Torvalds
4851da177e4SLinus Torvalds##
486b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out
487b112e0f7SJohannes Berg#
488b112e0f7SJohannes Bergsub dump_doc_section {
48994dc7ad5SRandy Dunlap    my $file = shift;
490b112e0f7SJohannes Berg    my $name = shift;
491b112e0f7SJohannes Berg    my $contents = join "\n", @_;
492b112e0f7SJohannes Berg
4934b44595aSJohannes Berg    if ($no_doc_sections) {
4944b44595aSJohannes Berg        return;
4954b44595aSJohannes Berg    }
4964b44595aSJohannes Berg
497b112e0f7SJohannes Berg    if (($function_only == 0) ||
498b112e0f7SJohannes Berg	( $function_only == 1 && defined($function_table{$name})) ||
499b112e0f7SJohannes Berg	( $function_only == 2 && !defined($function_table{$name})))
500b112e0f7SJohannes Berg    {
50194dc7ad5SRandy Dunlap	dump_section($file, $name, $contents);
502b112e0f7SJohannes Berg	output_blockhead({'sectionlist' => \@sectionlist,
503b112e0f7SJohannes Berg			  'sections' => \%sections,
504b112e0f7SJohannes Berg			  'module' => $modulename,
505b112e0f7SJohannes Berg			  'content-only' => ($function_only != 0), });
506b112e0f7SJohannes Berg    }
507b112e0f7SJohannes Berg}
508b112e0f7SJohannes Berg
509b112e0f7SJohannes Berg##
5101da177e4SLinus Torvalds# output function
5111da177e4SLinus Torvalds#
5121da177e4SLinus Torvalds# parameterdescs, a hash.
5131da177e4SLinus Torvalds#  function => "function name"
5141da177e4SLinus Torvalds#  parameterlist => @list of parameters
5151da177e4SLinus Torvalds#  parameterdescs => %parameter descriptions
5161da177e4SLinus Torvalds#  sectionlist => @list of sections
517a21217daSRandy Dunlap#  sections => %section descriptions
5181da177e4SLinus Torvalds#
5191da177e4SLinus Torvalds
5201da177e4SLinus Torvaldssub output_highlight {
5211da177e4SLinus Torvalds    my $contents = join "\n",@_;
5221da177e4SLinus Torvalds    my $line;
5231da177e4SLinus Torvalds
5241da177e4SLinus Torvalds#   DEBUG
5251da177e4SLinus Torvalds#   if (!defined $contents) {
5261da177e4SLinus Torvalds#	use Carp;
5271da177e4SLinus Torvalds#	confess "output_highlight got called with no args?\n";
5281da177e4SLinus Torvalds#   }
5291da177e4SLinus Torvalds
5301b40c194SDan Luedtke    if ($output_mode eq "html" || $output_mode eq "html5" ||
5311b40c194SDan Luedtke	$output_mode eq "xml") {
5326b5b55f6SRandy Dunlap	$contents = local_unescape($contents);
5336b5b55f6SRandy Dunlap	# convert data read & converted thru xml_escape() into &xyz; format:
5342b35f4d9SRandy Dunlap	$contents =~ s/\\\\\\/\&/g;
5356b5b55f6SRandy Dunlap    }
5363eb014a1SRandy Dunlap#   print STDERR "contents b4:$contents\n";
5371da177e4SLinus Torvalds    eval $dohighlight;
5381da177e4SLinus Torvalds    die $@ if $@;
5393eb014a1SRandy Dunlap#   print STDERR "contents af:$contents\n";
5403eb014a1SRandy Dunlap
5411b40c194SDan Luedtke#   strip whitespaces when generating html5
5421b40c194SDan Luedtke    if ($output_mode eq "html5") {
5431b40c194SDan Luedtke	$contents =~ s/^\s+//;
5441b40c194SDan Luedtke	$contents =~ s/\s+$//;
5451b40c194SDan Luedtke    }
5461da177e4SLinus Torvalds    foreach $line (split "\n", $contents) {
54712ae6779SDaniel Santos	if (! $output_preformatted) {
54812ae6779SDaniel Santos	    $line =~ s/^\s*//;
54912ae6779SDaniel Santos	}
5501da177e4SLinus Torvalds	if ($line eq ""){
551e314ba31SDaniel Santos	    if (! $output_preformatted) {
5526b5b55f6SRandy Dunlap		print $lineprefix, local_unescape($blankline);
553e314ba31SDaniel Santos	    }
5541da177e4SLinus Torvalds	} else {
5551da177e4SLinus Torvalds	    $line =~ s/\\\\\\/\&/g;
556cdccb316SRandy Dunlap	    if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
557cdccb316SRandy Dunlap		print "\\&$line";
558cdccb316SRandy Dunlap	    } else {
5591da177e4SLinus Torvalds		print $lineprefix, $line;
5601da177e4SLinus Torvalds	    }
561cdccb316SRandy Dunlap	}
5621da177e4SLinus Torvalds	print "\n";
5631da177e4SLinus Torvalds    }
5641da177e4SLinus Torvalds}
5651da177e4SLinus Torvalds
5661da177e4SLinus Torvalds# output sections in html
5671da177e4SLinus Torvaldssub output_section_html(%) {
5681da177e4SLinus Torvalds    my %args = %{$_[0]};
5691da177e4SLinus Torvalds    my $section;
5701da177e4SLinus Torvalds
5711da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
5721da177e4SLinus Torvalds	print "<h3>$section</h3>\n";
5731da177e4SLinus Torvalds	print "<blockquote>\n";
5741da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
5751da177e4SLinus Torvalds	print "</blockquote>\n";
5761da177e4SLinus Torvalds    }
5771da177e4SLinus Torvalds}
5781da177e4SLinus Torvalds
5791da177e4SLinus Torvalds# output enum in html
5801da177e4SLinus Torvaldssub output_enum_html(%) {
5811da177e4SLinus Torvalds    my %args = %{$_[0]};
5821da177e4SLinus Torvalds    my ($parameter);
5831da177e4SLinus Torvalds    my $count;
5841da177e4SLinus Torvalds    print "<h2>enum " . $args{'enum'} . "</h2>\n";
5851da177e4SLinus Torvalds
5861da177e4SLinus Torvalds    print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
5871da177e4SLinus Torvalds    $count = 0;
5881da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
5891da177e4SLinus Torvalds	print " <b>" . $parameter . "</b>";
5901da177e4SLinus Torvalds	if ($count != $#{$args{'parameterlist'}}) {
5911da177e4SLinus Torvalds	    $count++;
5921da177e4SLinus Torvalds	    print ",\n";
5931da177e4SLinus Torvalds	}
5941da177e4SLinus Torvalds	print "<br>";
5951da177e4SLinus Torvalds    }
5961da177e4SLinus Torvalds    print "};<br>\n";
5971da177e4SLinus Torvalds
5981da177e4SLinus Torvalds    print "<h3>Constants</h3>\n";
5991da177e4SLinus Torvalds    print "<dl>\n";
6001da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
6011da177e4SLinus Torvalds	print "<dt><b>" . $parameter . "</b>\n";
6021da177e4SLinus Torvalds	print "<dd>";
6031da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter});
6041da177e4SLinus Torvalds    }
6051da177e4SLinus Torvalds    print "</dl>\n";
6061da177e4SLinus Torvalds    output_section_html(@_);
6071da177e4SLinus Torvalds    print "<hr>\n";
6081da177e4SLinus Torvalds}
6091da177e4SLinus Torvalds
610d28bee0cSRandy Dunlap# output typedef in html
6111da177e4SLinus Torvaldssub output_typedef_html(%) {
6121da177e4SLinus Torvalds    my %args = %{$_[0]};
6131da177e4SLinus Torvalds    my ($parameter);
6141da177e4SLinus Torvalds    my $count;
6151da177e4SLinus Torvalds    print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
6161da177e4SLinus Torvalds
6171da177e4SLinus Torvalds    print "<b>typedef " . $args{'typedef'} . "</b>\n";
6181da177e4SLinus Torvalds    output_section_html(@_);
6191da177e4SLinus Torvalds    print "<hr>\n";
6201da177e4SLinus Torvalds}
6211da177e4SLinus Torvalds
6221da177e4SLinus Torvalds# output struct in html
6231da177e4SLinus Torvaldssub output_struct_html(%) {
6241da177e4SLinus Torvalds    my %args = %{$_[0]};
6251da177e4SLinus Torvalds    my ($parameter);
6261da177e4SLinus Torvalds
627262d9b01SRandy Dunlap    print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
6281da177e4SLinus Torvalds    print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
6291da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
6301da177e4SLinus Torvalds	if ($parameter =~ /^#/) {
6311da177e4SLinus Torvalds		print "$parameter<br>\n";
6321da177e4SLinus Torvalds		next;
6331da177e4SLinus Torvalds	}
6341da177e4SLinus Torvalds	my $parameter_name = $parameter;
6351da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
6361da177e4SLinus Torvalds
6371da177e4SLinus Torvalds	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
6381da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
6391da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
6401da177e4SLinus Torvalds	    # pointer-to-function
6413eb014a1SRandy Dunlap	    print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
6421da177e4SLinus Torvalds	} elsif ($type =~ m/^(.*?)\s*(:.*)/) {
6433eb014a1SRandy Dunlap	    # bitfield
6443eb014a1SRandy Dunlap	    print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
6451da177e4SLinus Torvalds	} else {
6463eb014a1SRandy Dunlap	    print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
6471da177e4SLinus Torvalds	}
6481da177e4SLinus Torvalds    }
6491da177e4SLinus Torvalds    print "};<br>\n";
6501da177e4SLinus Torvalds
6511da177e4SLinus Torvalds    print "<h3>Members</h3>\n";
6521da177e4SLinus Torvalds    print "<dl>\n";
6531da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
6541da177e4SLinus Torvalds	($parameter =~ /^#/) && next;
6551da177e4SLinus Torvalds
6561da177e4SLinus Torvalds	my $parameter_name = $parameter;
6571da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
6581da177e4SLinus Torvalds
6591da177e4SLinus Torvalds	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
6601da177e4SLinus Torvalds	print "<dt><b>" . $parameter . "</b>\n";
6611da177e4SLinus Torvalds	print "<dd>";
6621da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter_name});
6631da177e4SLinus Torvalds    }
6641da177e4SLinus Torvalds    print "</dl>\n";
6651da177e4SLinus Torvalds    output_section_html(@_);
6661da177e4SLinus Torvalds    print "<hr>\n";
6671da177e4SLinus Torvalds}
6681da177e4SLinus Torvalds
6691da177e4SLinus Torvalds# output function in html
6701da177e4SLinus Torvaldssub output_function_html(%) {
6711da177e4SLinus Torvalds    my %args = %{$_[0]};
6721da177e4SLinus Torvalds    my ($parameter, $section);
6731da177e4SLinus Torvalds    my $count;
6741da177e4SLinus Torvalds
675262d9b01SRandy Dunlap    print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
6761da177e4SLinus Torvalds    print "<i>" . $args{'functiontype'} . "</i>\n";
6771da177e4SLinus Torvalds    print "<b>" . $args{'function'} . "</b>\n";
6781da177e4SLinus Torvalds    print "(";
6791da177e4SLinus Torvalds    $count = 0;
6801da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
6811da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
6821da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
6831da177e4SLinus Torvalds	    # pointer-to-function
6841da177e4SLinus Torvalds	    print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
6851da177e4SLinus Torvalds	} else {
6861da177e4SLinus Torvalds	    print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
6871da177e4SLinus Torvalds	}
6881da177e4SLinus Torvalds	if ($count != $#{$args{'parameterlist'}}) {
6891da177e4SLinus Torvalds	    $count++;
6901da177e4SLinus Torvalds	    print ",\n";
6911da177e4SLinus Torvalds	}
6921da177e4SLinus Torvalds    }
6931da177e4SLinus Torvalds    print ")\n";
6941da177e4SLinus Torvalds
6951da177e4SLinus Torvalds    print "<h3>Arguments</h3>\n";
6961da177e4SLinus Torvalds    print "<dl>\n";
6971da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
6981da177e4SLinus Torvalds	my $parameter_name = $parameter;
6991da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
7001da177e4SLinus Torvalds
7011da177e4SLinus Torvalds	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
7021da177e4SLinus Torvalds	print "<dt><b>" . $parameter . "</b>\n";
7031da177e4SLinus Torvalds	print "<dd>";
7041da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter_name});
7051da177e4SLinus Torvalds    }
7061da177e4SLinus Torvalds    print "</dl>\n";
7071da177e4SLinus Torvalds    output_section_html(@_);
7081da177e4SLinus Torvalds    print "<hr>\n";
7091da177e4SLinus Torvalds}
7101da177e4SLinus Torvalds
711b112e0f7SJohannes Berg# output DOC: block header in html
712b112e0f7SJohannes Bergsub output_blockhead_html(%) {
7131da177e4SLinus Torvalds    my %args = %{$_[0]};
7141da177e4SLinus Torvalds    my ($parameter, $section);
7151da177e4SLinus Torvalds    my $count;
7161da177e4SLinus Torvalds
7171da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
7181da177e4SLinus Torvalds	print "<h3>$section</h3>\n";
7191da177e4SLinus Torvalds	print "<ul>\n";
7201da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
7211da177e4SLinus Torvalds	print "</ul>\n";
7221da177e4SLinus Torvalds    }
7231da177e4SLinus Torvalds    print "<hr>\n";
7241da177e4SLinus Torvalds}
7251da177e4SLinus Torvalds
7261b40c194SDan Luedtke# output sections in html5
7271b40c194SDan Luedtkesub output_section_html5(%) {
7281b40c194SDan Luedtke    my %args = %{$_[0]};
7291b40c194SDan Luedtke    my $section;
7301b40c194SDan Luedtke
7311b40c194SDan Luedtke    foreach $section (@{$args{'sectionlist'}}) {
7321b40c194SDan Luedtke	print "<section>\n";
7331b40c194SDan Luedtke	print "<h1>$section</h1>\n";
7341b40c194SDan Luedtke	print "<p>\n";
7351b40c194SDan Luedtke	output_highlight($args{'sections'}{$section});
7361b40c194SDan Luedtke	print "</p>\n";
7371b40c194SDan Luedtke	print "</section>\n";
7381b40c194SDan Luedtke    }
7391b40c194SDan Luedtke}
7401b40c194SDan Luedtke
7411b40c194SDan Luedtke# output enum in html5
7421b40c194SDan Luedtkesub output_enum_html5(%) {
7431b40c194SDan Luedtke    my %args = %{$_[0]};
7441b40c194SDan Luedtke    my ($parameter);
7451b40c194SDan Luedtke    my $count;
7461b40c194SDan Luedtke    my $html5id;
7471b40c194SDan Luedtke
7481b40c194SDan Luedtke    $html5id = $args{'enum'};
7491b40c194SDan Luedtke    $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
7501b40c194SDan Luedtke    print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
7511b40c194SDan Luedtke    print "<h1>enum " . $args{'enum'} . "</h1>\n";
7521b40c194SDan Luedtke    print "<ol class=\"code\">\n";
7531b40c194SDan Luedtke    print "<li>";
7541b40c194SDan Luedtke    print "<span class=\"keyword\">enum</span> ";
7551b40c194SDan Luedtke    print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
7561b40c194SDan Luedtke    print "</li>\n";
7571b40c194SDan Luedtke    $count = 0;
7581b40c194SDan Luedtke    foreach $parameter (@{$args{'parameterlist'}}) {
7591b40c194SDan Luedtke	print "<li class=\"indent\">";
7601b40c194SDan Luedtke	print "<span class=\"param\">" . $parameter . "</span>";
7611b40c194SDan Luedtke	if ($count != $#{$args{'parameterlist'}}) {
7621b40c194SDan Luedtke	    $count++;
7631b40c194SDan Luedtke	    print ",";
7641b40c194SDan Luedtke	}
7651b40c194SDan Luedtke	print "</li>\n";
7661b40c194SDan Luedtke    }
7671b40c194SDan Luedtke    print "<li>};</li>\n";
7681b40c194SDan Luedtke    print "</ol>\n";
7691b40c194SDan Luedtke
7701b40c194SDan Luedtke    print "<section>\n";
7711b40c194SDan Luedtke    print "<h1>Constants</h1>\n";
7721b40c194SDan Luedtke    print "<dl>\n";
7731b40c194SDan Luedtke    foreach $parameter (@{$args{'parameterlist'}}) {
7741b40c194SDan Luedtke	print "<dt>" . $parameter . "</dt>\n";
7751b40c194SDan Luedtke	print "<dd>";
7761b40c194SDan Luedtke	output_highlight($args{'parameterdescs'}{$parameter});
7771b40c194SDan Luedtke	print "</dd>\n";
7781b40c194SDan Luedtke    }
7791b40c194SDan Luedtke    print "</dl>\n";
7801b40c194SDan Luedtke    print "</section>\n";
7811b40c194SDan Luedtke    output_section_html5(@_);
7821b40c194SDan Luedtke    print "</article>\n";
7831b40c194SDan Luedtke}
7841b40c194SDan Luedtke
7851b40c194SDan Luedtke# output typedef in html5
7861b40c194SDan Luedtkesub output_typedef_html5(%) {
7871b40c194SDan Luedtke    my %args = %{$_[0]};
7881b40c194SDan Luedtke    my ($parameter);
7891b40c194SDan Luedtke    my $count;
7901b40c194SDan Luedtke    my $html5id;
7911b40c194SDan Luedtke
7921b40c194SDan Luedtke    $html5id = $args{'typedef'};
7931b40c194SDan Luedtke    $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
7941b40c194SDan Luedtke    print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
7951b40c194SDan Luedtke    print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
7961b40c194SDan Luedtke
7971b40c194SDan Luedtke    print "<ol class=\"code\">\n";
7981b40c194SDan Luedtke    print "<li>";
7991b40c194SDan Luedtke    print "<span class=\"keyword\">typedef</span> ";
8001b40c194SDan Luedtke    print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
8011b40c194SDan Luedtke    print "</li>\n";
8021b40c194SDan Luedtke    print "</ol>\n";
8031b40c194SDan Luedtke    output_section_html5(@_);
8041b40c194SDan Luedtke    print "</article>\n";
8051b40c194SDan Luedtke}
8061b40c194SDan Luedtke
8071b40c194SDan Luedtke# output struct in html5
8081b40c194SDan Luedtkesub output_struct_html5(%) {
8091b40c194SDan Luedtke    my %args = %{$_[0]};
8101b40c194SDan Luedtke    my ($parameter);
8111b40c194SDan Luedtke    my $html5id;
8121b40c194SDan Luedtke
8131b40c194SDan Luedtke    $html5id = $args{'struct'};
8141b40c194SDan Luedtke    $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
8151b40c194SDan Luedtke    print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
8161b40c194SDan Luedtke    print "<hgroup>\n";
8171b40c194SDan Luedtke    print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
8181b40c194SDan Luedtke    print "<h2>". $args{'purpose'} . "</h2>\n";
8191b40c194SDan Luedtke    print "</hgroup>\n";
8201b40c194SDan Luedtke    print "<ol class=\"code\">\n";
8211b40c194SDan Luedtke    print "<li>";
8221b40c194SDan Luedtke    print "<span class=\"type\">" . $args{'type'} . "</span> ";
8231b40c194SDan Luedtke    print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
8241b40c194SDan Luedtke    print "</li>\n";
8251b40c194SDan Luedtke    foreach $parameter (@{$args{'parameterlist'}}) {
8261b40c194SDan Luedtke	print "<li class=\"indent\">";
8271b40c194SDan Luedtke	if ($parameter =~ /^#/) {
8281b40c194SDan Luedtke		print "<span class=\"param\">" . $parameter ."</span>\n";
8291b40c194SDan Luedtke		print "</li>\n";
8301b40c194SDan Luedtke		next;
8311b40c194SDan Luedtke	}
8321b40c194SDan Luedtke	my $parameter_name = $parameter;
8331b40c194SDan Luedtke	$parameter_name =~ s/\[.*//;
8341b40c194SDan Luedtke
8351b40c194SDan Luedtke	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
8361b40c194SDan Luedtke	$type = $args{'parametertypes'}{$parameter};
8371b40c194SDan Luedtke	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
8381b40c194SDan Luedtke	    # pointer-to-function
8391b40c194SDan Luedtke	    print "<span class=\"type\">$1</span> ";
8401b40c194SDan Luedtke	    print "<span class=\"param\">$parameter</span>";
8411b40c194SDan Luedtke	    print "<span class=\"type\">)</span> ";
8421b40c194SDan Luedtke	    print "(<span class=\"args\">$2</span>);";
8431b40c194SDan Luedtke	} elsif ($type =~ m/^(.*?)\s*(:.*)/) {
8441b40c194SDan Luedtke	    # bitfield
8451b40c194SDan Luedtke	    print "<span class=\"type\">$1</span> ";
8461b40c194SDan Luedtke	    print "<span class=\"param\">$parameter</span>";
8471b40c194SDan Luedtke	    print "<span class=\"bits\">$2</span>;";
8481b40c194SDan Luedtke	} else {
8491b40c194SDan Luedtke	    print "<span class=\"type\">$type</span> ";
8501b40c194SDan Luedtke	    print "<span class=\"param\">$parameter</span>;";
8511b40c194SDan Luedtke	}
8521b40c194SDan Luedtke	print "</li>\n";
8531b40c194SDan Luedtke    }
8541b40c194SDan Luedtke    print "<li>};</li>\n";
8551b40c194SDan Luedtke    print "</ol>\n";
8561b40c194SDan Luedtke
8571b40c194SDan Luedtke    print "<section>\n";
8581b40c194SDan Luedtke    print "<h1>Members</h1>\n";
8591b40c194SDan Luedtke    print "<dl>\n";
8601b40c194SDan Luedtke    foreach $parameter (@{$args{'parameterlist'}}) {
8611b40c194SDan Luedtke	($parameter =~ /^#/) && next;
8621b40c194SDan Luedtke
8631b40c194SDan Luedtke	my $parameter_name = $parameter;
8641b40c194SDan Luedtke	$parameter_name =~ s/\[.*//;
8651b40c194SDan Luedtke
8661b40c194SDan Luedtke	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
8671b40c194SDan Luedtke	print "<dt>" . $parameter . "</dt>\n";
8681b40c194SDan Luedtke	print "<dd>";
8691b40c194SDan Luedtke	output_highlight($args{'parameterdescs'}{$parameter_name});
8701b40c194SDan Luedtke	print "</dd>\n";
8711b40c194SDan Luedtke    }
8721b40c194SDan Luedtke    print "</dl>\n";
8731b40c194SDan Luedtke    print "</section>\n";
8741b40c194SDan Luedtke    output_section_html5(@_);
8751b40c194SDan Luedtke    print "</article>\n";
8761b40c194SDan Luedtke}
8771b40c194SDan Luedtke
8781b40c194SDan Luedtke# output function in html5
8791b40c194SDan Luedtkesub output_function_html5(%) {
8801b40c194SDan Luedtke    my %args = %{$_[0]};
8811b40c194SDan Luedtke    my ($parameter, $section);
8821b40c194SDan Luedtke    my $count;
8831b40c194SDan Luedtke    my $html5id;
8841b40c194SDan Luedtke
8851b40c194SDan Luedtke    $html5id = $args{'function'};
8861b40c194SDan Luedtke    $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
8871b40c194SDan Luedtke    print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
8881b40c194SDan Luedtke    print "<hgroup>\n";
8891b40c194SDan Luedtke    print "<h1>" . $args{'function'} . "</h1>";
8901b40c194SDan Luedtke    print "<h2>" . $args{'purpose'} . "</h2>\n";
8911b40c194SDan Luedtke    print "</hgroup>\n";
8921b40c194SDan Luedtke    print "<ol class=\"code\">\n";
8931b40c194SDan Luedtke    print "<li>";
8941b40c194SDan Luedtke    print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
8951b40c194SDan Luedtke    print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
8961b40c194SDan Luedtke    print "</li>";
8971b40c194SDan Luedtke    $count = 0;
8981b40c194SDan Luedtke    foreach $parameter (@{$args{'parameterlist'}}) {
8991b40c194SDan Luedtke	print "<li class=\"indent\">";
9001b40c194SDan Luedtke	$type = $args{'parametertypes'}{$parameter};
9011b40c194SDan Luedtke	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
9021b40c194SDan Luedtke	    # pointer-to-function
9031b40c194SDan Luedtke	    print "<span class=\"type\">$1</span> ";
9041b40c194SDan Luedtke	    print "<span class=\"param\">$parameter</span>";
9051b40c194SDan Luedtke	    print "<span class=\"type\">)</span> ";
9061b40c194SDan Luedtke	    print "(<span class=\"args\">$2</span>)";
9071b40c194SDan Luedtke	} else {
9081b40c194SDan Luedtke	    print "<span class=\"type\">$type</span> ";
9091b40c194SDan Luedtke	    print "<span class=\"param\">$parameter</span>";
9101b40c194SDan Luedtke	}
9111b40c194SDan Luedtke	if ($count != $#{$args{'parameterlist'}}) {
9121b40c194SDan Luedtke	    $count++;
9131b40c194SDan Luedtke	    print ",";
9141b40c194SDan Luedtke	}
9151b40c194SDan Luedtke	print "</li>\n";
9161b40c194SDan Luedtke    }
9171b40c194SDan Luedtke    print "<li>)</li>\n";
9181b40c194SDan Luedtke    print "</ol>\n";
9191b40c194SDan Luedtke
9201b40c194SDan Luedtke    print "<section>\n";
9211b40c194SDan Luedtke    print "<h1>Arguments</h1>\n";
9221b40c194SDan Luedtke    print "<p>\n";
9231b40c194SDan Luedtke    print "<dl>\n";
9241b40c194SDan Luedtke    foreach $parameter (@{$args{'parameterlist'}}) {
9251b40c194SDan Luedtke	my $parameter_name = $parameter;
9261b40c194SDan Luedtke	$parameter_name =~ s/\[.*//;
9271b40c194SDan Luedtke
9281b40c194SDan Luedtke	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
9291b40c194SDan Luedtke	print "<dt>" . $parameter . "</dt>\n";
9301b40c194SDan Luedtke	print "<dd>";
9311b40c194SDan Luedtke	output_highlight($args{'parameterdescs'}{$parameter_name});
9321b40c194SDan Luedtke	print "</dd>\n";
9331b40c194SDan Luedtke    }
9341b40c194SDan Luedtke    print "</dl>\n";
9351b40c194SDan Luedtke    print "</section>\n";
9361b40c194SDan Luedtke    output_section_html5(@_);
9371b40c194SDan Luedtke    print "</article>\n";
9381b40c194SDan Luedtke}
9391b40c194SDan Luedtke
9401b40c194SDan Luedtke# output DOC: block header in html5
9411b40c194SDan Luedtkesub output_blockhead_html5(%) {
9421b40c194SDan Luedtke    my %args = %{$_[0]};
9431b40c194SDan Luedtke    my ($parameter, $section);
9441b40c194SDan Luedtke    my $count;
9451b40c194SDan Luedtke    my $html5id;
9461b40c194SDan Luedtke
9471b40c194SDan Luedtke    foreach $section (@{$args{'sectionlist'}}) {
9481b40c194SDan Luedtke	$html5id = $section;
9491b40c194SDan Luedtke	$html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
9501b40c194SDan Luedtke	print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
9511b40c194SDan Luedtke	print "<h1>$section</h1>\n";
9521b40c194SDan Luedtke	print "<p>\n";
9531b40c194SDan Luedtke	output_highlight($args{'sections'}{$section});
9541b40c194SDan Luedtke	print "</p>\n";
9551b40c194SDan Luedtke    }
9561b40c194SDan Luedtke    print "</article>\n";
9571b40c194SDan Luedtke}
9581b40c194SDan Luedtke
9591da177e4SLinus Torvaldssub output_section_xml(%) {
9601da177e4SLinus Torvalds    my %args = %{$_[0]};
9611da177e4SLinus Torvalds    my $section;
9621da177e4SLinus Torvalds    # print out each section
9631da177e4SLinus Torvalds    $lineprefix="   ";
9641da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
965c73894c1SRich Walker	print "<refsect1>\n";
966c73894c1SRich Walker	print "<title>$section</title>\n";
9671da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
968c73894c1SRich Walker	    print "<informalexample><programlisting>\n";
969e314ba31SDaniel Santos	    $output_preformatted = 1;
970c73894c1SRich Walker	} else {
971c73894c1SRich Walker	    print "<para>\n";
9721da177e4SLinus Torvalds	}
9731da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
974e314ba31SDaniel Santos	$output_preformatted = 0;
9751da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
976c73894c1SRich Walker	    print "</programlisting></informalexample>\n";
977c73894c1SRich Walker	} else {
978c73894c1SRich Walker	    print "</para>\n";
9791da177e4SLinus Torvalds	}
980c73894c1SRich Walker	print "</refsect1>\n";
9811da177e4SLinus Torvalds    }
9821da177e4SLinus Torvalds}
9831da177e4SLinus Torvalds
9841da177e4SLinus Torvalds# output function in XML DocBook
9851da177e4SLinus Torvaldssub output_function_xml(%) {
9861da177e4SLinus Torvalds    my %args = %{$_[0]};
9871da177e4SLinus Torvalds    my ($parameter, $section);
9881da177e4SLinus Torvalds    my $count;
9891da177e4SLinus Torvalds    my $id;
9901da177e4SLinus Torvalds
9911da177e4SLinus Torvalds    $id = "API-" . $args{'function'};
9921da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
9931da177e4SLinus Torvalds
9945449bc94SPavel Pisa    print "<refentry id=\"$id\">\n";
9958b0c2d98SMartin Waitz    print "<refentryinfo>\n";
9968b0c2d98SMartin Waitz    print " <title>LINUX</title>\n";
9978b0c2d98SMartin Waitz    print " <productname>Kernel Hackers Manual</productname>\n";
9988b0c2d98SMartin Waitz    print " <date>$man_date</date>\n";
9998b0c2d98SMartin Waitz    print "</refentryinfo>\n";
10001da177e4SLinus Torvalds    print "<refmeta>\n";
10015449bc94SPavel Pisa    print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
10028b0c2d98SMartin Waitz    print " <manvolnum>9</manvolnum>\n";
10030366299bSBorislav Petkov    print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
10041da177e4SLinus Torvalds    print "</refmeta>\n";
10051da177e4SLinus Torvalds    print "<refnamediv>\n";
10061da177e4SLinus Torvalds    print " <refname>" . $args{'function'} . "</refname>\n";
10071da177e4SLinus Torvalds    print " <refpurpose>\n";
10081da177e4SLinus Torvalds    print "  ";
10091da177e4SLinus Torvalds    output_highlight ($args{'purpose'});
10101da177e4SLinus Torvalds    print " </refpurpose>\n";
10111da177e4SLinus Torvalds    print "</refnamediv>\n";
10121da177e4SLinus Torvalds
10131da177e4SLinus Torvalds    print "<refsynopsisdiv>\n";
10141da177e4SLinus Torvalds    print " <title>Synopsis</title>\n";
10151da177e4SLinus Torvalds    print "  <funcsynopsis><funcprototype>\n";
10161da177e4SLinus Torvalds    print "   <funcdef>" . $args{'functiontype'} . " ";
10171da177e4SLinus Torvalds    print "<function>" . $args{'function'} . " </function></funcdef>\n";
10181da177e4SLinus Torvalds
10191da177e4SLinus Torvalds    $count = 0;
10201da177e4SLinus Torvalds    if ($#{$args{'parameterlist'}} >= 0) {
10211da177e4SLinus Torvalds	foreach $parameter (@{$args{'parameterlist'}}) {
10221da177e4SLinus Torvalds	    $type = $args{'parametertypes'}{$parameter};
10231da177e4SLinus Torvalds	    if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
10241da177e4SLinus Torvalds		# pointer-to-function
10251da177e4SLinus Torvalds		print "   <paramdef>$1<parameter>$parameter</parameter>)\n";
10261da177e4SLinus Torvalds		print "     <funcparams>$2</funcparams></paramdef>\n";
10271da177e4SLinus Torvalds	    } else {
10281da177e4SLinus Torvalds		print "   <paramdef>" . $type;
10291da177e4SLinus Torvalds		print " <parameter>$parameter</parameter></paramdef>\n";
10301da177e4SLinus Torvalds	    }
10311da177e4SLinus Torvalds	}
10321da177e4SLinus Torvalds    } else {
10336013d544SMartin Waitz	print "  <void/>\n";
10341da177e4SLinus Torvalds    }
10351da177e4SLinus Torvalds    print "  </funcprototype></funcsynopsis>\n";
10361da177e4SLinus Torvalds    print "</refsynopsisdiv>\n";
10371da177e4SLinus Torvalds
10381da177e4SLinus Torvalds    # print parameters
10391da177e4SLinus Torvalds    print "<refsect1>\n <title>Arguments</title>\n";
10401da177e4SLinus Torvalds    if ($#{$args{'parameterlist'}} >= 0) {
10411da177e4SLinus Torvalds	print " <variablelist>\n";
10421da177e4SLinus Torvalds	foreach $parameter (@{$args{'parameterlist'}}) {
10431da177e4SLinus Torvalds	    my $parameter_name = $parameter;
10441da177e4SLinus Torvalds	    $parameter_name =~ s/\[.*//;
10451da177e4SLinus Torvalds
10461da177e4SLinus Torvalds	    print "  <varlistentry>\n   <term><parameter>$parameter</parameter></term>\n";
10471da177e4SLinus Torvalds	    print "   <listitem>\n    <para>\n";
10481da177e4SLinus Torvalds	    $lineprefix="     ";
10491da177e4SLinus Torvalds	    output_highlight($args{'parameterdescs'}{$parameter_name});
10501da177e4SLinus Torvalds	    print "    </para>\n   </listitem>\n  </varlistentry>\n";
10511da177e4SLinus Torvalds	}
10521da177e4SLinus Torvalds	print " </variablelist>\n";
10531da177e4SLinus Torvalds    } else {
10541da177e4SLinus Torvalds	print " <para>\n  None\n </para>\n";
10551da177e4SLinus Torvalds    }
10561da177e4SLinus Torvalds    print "</refsect1>\n";
10571da177e4SLinus Torvalds
10581da177e4SLinus Torvalds    output_section_xml(@_);
10591da177e4SLinus Torvalds    print "</refentry>\n\n";
10601da177e4SLinus Torvalds}
10611da177e4SLinus Torvalds
10621da177e4SLinus Torvalds# output struct in XML DocBook
10631da177e4SLinus Torvaldssub output_struct_xml(%) {
10641da177e4SLinus Torvalds    my %args = %{$_[0]};
10651da177e4SLinus Torvalds    my ($parameter, $section);
10661da177e4SLinus Torvalds    my $id;
10671da177e4SLinus Torvalds
10681da177e4SLinus Torvalds    $id = "API-struct-" . $args{'struct'};
10691da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
10701da177e4SLinus Torvalds
10715449bc94SPavel Pisa    print "<refentry id=\"$id\">\n";
10728b0c2d98SMartin Waitz    print "<refentryinfo>\n";
10738b0c2d98SMartin Waitz    print " <title>LINUX</title>\n";
10748b0c2d98SMartin Waitz    print " <productname>Kernel Hackers Manual</productname>\n";
10758b0c2d98SMartin Waitz    print " <date>$man_date</date>\n";
10768b0c2d98SMartin Waitz    print "</refentryinfo>\n";
10771da177e4SLinus Torvalds    print "<refmeta>\n";
10785449bc94SPavel Pisa    print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
10798b0c2d98SMartin Waitz    print " <manvolnum>9</manvolnum>\n";
10800366299bSBorislav Petkov    print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
10811da177e4SLinus Torvalds    print "</refmeta>\n";
10821da177e4SLinus Torvalds    print "<refnamediv>\n";
10831da177e4SLinus Torvalds    print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
10841da177e4SLinus Torvalds    print " <refpurpose>\n";
10851da177e4SLinus Torvalds    print "  ";
10861da177e4SLinus Torvalds    output_highlight ($args{'purpose'});
10871da177e4SLinus Torvalds    print " </refpurpose>\n";
10881da177e4SLinus Torvalds    print "</refnamediv>\n";
10891da177e4SLinus Torvalds
10901da177e4SLinus Torvalds    print "<refsynopsisdiv>\n";
10911da177e4SLinus Torvalds    print " <title>Synopsis</title>\n";
10921da177e4SLinus Torvalds    print "  <programlisting>\n";
10931da177e4SLinus Torvalds    print $args{'type'} . " " . $args{'struct'} . " {\n";
10941da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
10951da177e4SLinus Torvalds	if ($parameter =~ /^#/) {
10962b35f4d9SRandy Dunlap	    my $prm = $parameter;
10972b35f4d9SRandy Dunlap	    # convert data read & converted thru xml_escape() into &xyz; format:
10982b35f4d9SRandy Dunlap	    # This allows us to have #define macros interspersed in a struct.
10992b35f4d9SRandy Dunlap	    $prm =~ s/\\\\\\/\&/g;
11002b35f4d9SRandy Dunlap	    print "$prm\n";
11011da177e4SLinus Torvalds	    next;
11021da177e4SLinus Torvalds	}
11031da177e4SLinus Torvalds
11041da177e4SLinus Torvalds	my $parameter_name = $parameter;
11051da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
11061da177e4SLinus Torvalds
11071da177e4SLinus Torvalds	defined($args{'parameterdescs'}{$parameter_name}) || next;
11081da177e4SLinus Torvalds	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
11091da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
11101da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
11111da177e4SLinus Torvalds	    # pointer-to-function
11121da177e4SLinus Torvalds	    print "  $1 $parameter) ($2);\n";
11131da177e4SLinus Torvalds	} elsif ($type =~ m/^(.*?)\s*(:.*)/) {
111451f5a0c8SRandy Dunlap	    # bitfield
11151da177e4SLinus Torvalds	    print "  $1 $parameter$2;\n";
11161da177e4SLinus Torvalds	} else {
11171da177e4SLinus Torvalds	    print "  " . $type . " " . $parameter . ";\n";
11181da177e4SLinus Torvalds	}
11191da177e4SLinus Torvalds    }
11201da177e4SLinus Torvalds    print "};";
11211da177e4SLinus Torvalds    print "  </programlisting>\n";
11221da177e4SLinus Torvalds    print "</refsynopsisdiv>\n";
11231da177e4SLinus Torvalds
11241da177e4SLinus Torvalds    print " <refsect1>\n";
11251da177e4SLinus Torvalds    print "  <title>Members</title>\n";
11261da177e4SLinus Torvalds
112739f00c08SRandy Dunlap    if ($#{$args{'parameterlist'}} >= 0) {
11281da177e4SLinus Torvalds    print "  <variablelist>\n";
11291da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
11301da177e4SLinus Torvalds      ($parameter =~ /^#/) && next;
11311da177e4SLinus Torvalds
11321da177e4SLinus Torvalds      my $parameter_name = $parameter;
11331da177e4SLinus Torvalds      $parameter_name =~ s/\[.*//;
11341da177e4SLinus Torvalds
11351da177e4SLinus Torvalds      defined($args{'parameterdescs'}{$parameter_name}) || next;
11361da177e4SLinus Torvalds      ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
11371da177e4SLinus Torvalds      print "    <varlistentry>";
11381da177e4SLinus Torvalds      print "      <term>$parameter</term>\n";
11391da177e4SLinus Torvalds      print "      <listitem><para>\n";
11401da177e4SLinus Torvalds      output_highlight($args{'parameterdescs'}{$parameter_name});
11411da177e4SLinus Torvalds      print "      </para></listitem>\n";
11421da177e4SLinus Torvalds      print "    </varlistentry>\n";
11431da177e4SLinus Torvalds    }
11441da177e4SLinus Torvalds    print "  </variablelist>\n";
114539f00c08SRandy Dunlap    } else {
114639f00c08SRandy Dunlap	print " <para>\n  None\n </para>\n";
114739f00c08SRandy Dunlap    }
11481da177e4SLinus Torvalds    print " </refsect1>\n";
11491da177e4SLinus Torvalds
11501da177e4SLinus Torvalds    output_section_xml(@_);
11511da177e4SLinus Torvalds
11521da177e4SLinus Torvalds    print "</refentry>\n\n";
11531da177e4SLinus Torvalds}
11541da177e4SLinus Torvalds
11551da177e4SLinus Torvalds# output enum in XML DocBook
11561da177e4SLinus Torvaldssub output_enum_xml(%) {
11571da177e4SLinus Torvalds    my %args = %{$_[0]};
11581da177e4SLinus Torvalds    my ($parameter, $section);
11591da177e4SLinus Torvalds    my $count;
11601da177e4SLinus Torvalds    my $id;
11611da177e4SLinus Torvalds
11621da177e4SLinus Torvalds    $id = "API-enum-" . $args{'enum'};
11631da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
11641da177e4SLinus Torvalds
11655449bc94SPavel Pisa    print "<refentry id=\"$id\">\n";
11668b0c2d98SMartin Waitz    print "<refentryinfo>\n";
11678b0c2d98SMartin Waitz    print " <title>LINUX</title>\n";
11688b0c2d98SMartin Waitz    print " <productname>Kernel Hackers Manual</productname>\n";
11698b0c2d98SMartin Waitz    print " <date>$man_date</date>\n";
11708b0c2d98SMartin Waitz    print "</refentryinfo>\n";
11711da177e4SLinus Torvalds    print "<refmeta>\n";
11725449bc94SPavel Pisa    print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
11738b0c2d98SMartin Waitz    print " <manvolnum>9</manvolnum>\n";
11740366299bSBorislav Petkov    print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
11751da177e4SLinus Torvalds    print "</refmeta>\n";
11761da177e4SLinus Torvalds    print "<refnamediv>\n";
11771da177e4SLinus Torvalds    print " <refname>enum " . $args{'enum'} . "</refname>\n";
11781da177e4SLinus Torvalds    print " <refpurpose>\n";
11791da177e4SLinus Torvalds    print "  ";
11801da177e4SLinus Torvalds    output_highlight ($args{'purpose'});
11811da177e4SLinus Torvalds    print " </refpurpose>\n";
11821da177e4SLinus Torvalds    print "</refnamediv>\n";
11831da177e4SLinus Torvalds
11841da177e4SLinus Torvalds    print "<refsynopsisdiv>\n";
11851da177e4SLinus Torvalds    print " <title>Synopsis</title>\n";
11861da177e4SLinus Torvalds    print "  <programlisting>\n";
11871da177e4SLinus Torvalds    print "enum " . $args{'enum'} . " {\n";
11881da177e4SLinus Torvalds    $count = 0;
11891da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
11901da177e4SLinus Torvalds	print "  $parameter";
11911da177e4SLinus Torvalds	if ($count != $#{$args{'parameterlist'}}) {
11921da177e4SLinus Torvalds	    $count++;
11931da177e4SLinus Torvalds	    print ",";
11941da177e4SLinus Torvalds	}
11951da177e4SLinus Torvalds	print "\n";
11961da177e4SLinus Torvalds    }
11971da177e4SLinus Torvalds    print "};";
11981da177e4SLinus Torvalds    print "  </programlisting>\n";
11991da177e4SLinus Torvalds    print "</refsynopsisdiv>\n";
12001da177e4SLinus Torvalds
12011da177e4SLinus Torvalds    print "<refsect1>\n";
12021da177e4SLinus Torvalds    print " <title>Constants</title>\n";
12031da177e4SLinus Torvalds    print "  <variablelist>\n";
12041da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
12051da177e4SLinus Torvalds      my $parameter_name = $parameter;
12061da177e4SLinus Torvalds      $parameter_name =~ s/\[.*//;
12071da177e4SLinus Torvalds
12081da177e4SLinus Torvalds      print "    <varlistentry>";
12091da177e4SLinus Torvalds      print "      <term>$parameter</term>\n";
12101da177e4SLinus Torvalds      print "      <listitem><para>\n";
12111da177e4SLinus Torvalds      output_highlight($args{'parameterdescs'}{$parameter_name});
12121da177e4SLinus Torvalds      print "      </para></listitem>\n";
12131da177e4SLinus Torvalds      print "    </varlistentry>\n";
12141da177e4SLinus Torvalds    }
12151da177e4SLinus Torvalds    print "  </variablelist>\n";
12161da177e4SLinus Torvalds    print "</refsect1>\n";
12171da177e4SLinus Torvalds
12181da177e4SLinus Torvalds    output_section_xml(@_);
12191da177e4SLinus Torvalds
12201da177e4SLinus Torvalds    print "</refentry>\n\n";
12211da177e4SLinus Torvalds}
12221da177e4SLinus Torvalds
12231da177e4SLinus Torvalds# output typedef in XML DocBook
12241da177e4SLinus Torvaldssub output_typedef_xml(%) {
12251da177e4SLinus Torvalds    my %args = %{$_[0]};
12261da177e4SLinus Torvalds    my ($parameter, $section);
12271da177e4SLinus Torvalds    my $id;
12281da177e4SLinus Torvalds
12291da177e4SLinus Torvalds    $id = "API-typedef-" . $args{'typedef'};
12301da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
12311da177e4SLinus Torvalds
12325449bc94SPavel Pisa    print "<refentry id=\"$id\">\n";
12338b0c2d98SMartin Waitz    print "<refentryinfo>\n";
12348b0c2d98SMartin Waitz    print " <title>LINUX</title>\n";
12358b0c2d98SMartin Waitz    print " <productname>Kernel Hackers Manual</productname>\n";
12368b0c2d98SMartin Waitz    print " <date>$man_date</date>\n";
12378b0c2d98SMartin Waitz    print "</refentryinfo>\n";
12381da177e4SLinus Torvalds    print "<refmeta>\n";
12395449bc94SPavel Pisa    print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
12408b0c2d98SMartin Waitz    print " <manvolnum>9</manvolnum>\n";
12411da177e4SLinus Torvalds    print "</refmeta>\n";
12421da177e4SLinus Torvalds    print "<refnamediv>\n";
12431da177e4SLinus Torvalds    print " <refname>typedef " . $args{'typedef'} . "</refname>\n";
12441da177e4SLinus Torvalds    print " <refpurpose>\n";
12451da177e4SLinus Torvalds    print "  ";
12461da177e4SLinus Torvalds    output_highlight ($args{'purpose'});
12471da177e4SLinus Torvalds    print " </refpurpose>\n";
12481da177e4SLinus Torvalds    print "</refnamediv>\n";
12491da177e4SLinus Torvalds
12501da177e4SLinus Torvalds    print "<refsynopsisdiv>\n";
12511da177e4SLinus Torvalds    print " <title>Synopsis</title>\n";
12521da177e4SLinus Torvalds    print "  <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
12531da177e4SLinus Torvalds    print "</refsynopsisdiv>\n";
12541da177e4SLinus Torvalds
12551da177e4SLinus Torvalds    output_section_xml(@_);
12561da177e4SLinus Torvalds
12571da177e4SLinus Torvalds    print "</refentry>\n\n";
12581da177e4SLinus Torvalds}
12591da177e4SLinus Torvalds
12601da177e4SLinus Torvalds# output in XML DocBook
1261b112e0f7SJohannes Bergsub output_blockhead_xml(%) {
12621da177e4SLinus Torvalds    my %args = %{$_[0]};
12631da177e4SLinus Torvalds    my ($parameter, $section);
12641da177e4SLinus Torvalds    my $count;
12651da177e4SLinus Torvalds
12661da177e4SLinus Torvalds    my $id = $args{'module'};
12671da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
12681da177e4SLinus Torvalds
12691da177e4SLinus Torvalds    # print out each section
12701da177e4SLinus Torvalds    $lineprefix="   ";
12711da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
1272b112e0f7SJohannes Berg	if (!$args{'content-only'}) {
1273b112e0f7SJohannes Berg		print "<refsect1>\n <title>$section</title>\n";
1274b112e0f7SJohannes Berg	}
12751da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
12761da177e4SLinus Torvalds	    print "<example><para>\n";
1277e314ba31SDaniel Santos	    $output_preformatted = 1;
1278b112e0f7SJohannes Berg	} else {
1279b112e0f7SJohannes Berg	    print "<para>\n";
12801da177e4SLinus Torvalds	}
12811da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
1282e314ba31SDaniel Santos	$output_preformatted = 0;
12831da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
12841da177e4SLinus Torvalds	    print "</para></example>\n";
1285b112e0f7SJohannes Berg	} else {
1286b112e0f7SJohannes Berg	    print "</para>";
12871da177e4SLinus Torvalds	}
1288b112e0f7SJohannes Berg	if (!$args{'content-only'}) {
1289b112e0f7SJohannes Berg		print "\n</refsect1>\n";
1290b112e0f7SJohannes Berg	}
12911da177e4SLinus Torvalds    }
12921da177e4SLinus Torvalds
12931da177e4SLinus Torvalds    print "\n\n";
12941da177e4SLinus Torvalds}
12951da177e4SLinus Torvalds
12961da177e4SLinus Torvalds# output in XML DocBook
12971da177e4SLinus Torvaldssub output_function_gnome {
12981da177e4SLinus Torvalds    my %args = %{$_[0]};
12991da177e4SLinus Torvalds    my ($parameter, $section);
13001da177e4SLinus Torvalds    my $count;
13011da177e4SLinus Torvalds    my $id;
13021da177e4SLinus Torvalds
13031da177e4SLinus Torvalds    $id = $args{'module'} . "-" . $args{'function'};
13041da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
13051da177e4SLinus Torvalds
13061da177e4SLinus Torvalds    print "<sect2>\n";
13071da177e4SLinus Torvalds    print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
13081da177e4SLinus Torvalds
13091da177e4SLinus Torvalds    print "  <funcsynopsis>\n";
13101da177e4SLinus Torvalds    print "   <funcdef>" . $args{'functiontype'} . " ";
13111da177e4SLinus Torvalds    print "<function>" . $args{'function'} . " ";
13121da177e4SLinus Torvalds    print "</function></funcdef>\n";
13131da177e4SLinus Torvalds
13141da177e4SLinus Torvalds    $count = 0;
13151da177e4SLinus Torvalds    if ($#{$args{'parameterlist'}} >= 0) {
13161da177e4SLinus Torvalds	foreach $parameter (@{$args{'parameterlist'}}) {
13171da177e4SLinus Torvalds	    $type = $args{'parametertypes'}{$parameter};
13181da177e4SLinus Torvalds	    if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
13191da177e4SLinus Torvalds		# pointer-to-function
13201da177e4SLinus Torvalds		print "   <paramdef>$1 <parameter>$parameter</parameter>)\n";
13211da177e4SLinus Torvalds		print "     <funcparams>$2</funcparams></paramdef>\n";
13221da177e4SLinus Torvalds	    } else {
13231da177e4SLinus Torvalds		print "   <paramdef>" . $type;
13241da177e4SLinus Torvalds		print " <parameter>$parameter</parameter></paramdef>\n";
13251da177e4SLinus Torvalds	    }
13261da177e4SLinus Torvalds	}
13271da177e4SLinus Torvalds    } else {
13281da177e4SLinus Torvalds	print "  <void>\n";
13291da177e4SLinus Torvalds    }
13301da177e4SLinus Torvalds    print "  </funcsynopsis>\n";
13311da177e4SLinus Torvalds    if ($#{$args{'parameterlist'}} >= 0) {
13321da177e4SLinus Torvalds	print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
13331da177e4SLinus Torvalds	print "<tgroup cols=\"2\">\n";
13341da177e4SLinus Torvalds	print "<colspec colwidth=\"2*\">\n";
13351da177e4SLinus Torvalds	print "<colspec colwidth=\"8*\">\n";
13361da177e4SLinus Torvalds	print "<tbody>\n";
13371da177e4SLinus Torvalds	foreach $parameter (@{$args{'parameterlist'}}) {
13381da177e4SLinus Torvalds	    my $parameter_name = $parameter;
13391da177e4SLinus Torvalds	    $parameter_name =~ s/\[.*//;
13401da177e4SLinus Torvalds
13411da177e4SLinus Torvalds	    print "  <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
13421da177e4SLinus Torvalds	    print "   <entry>\n";
13431da177e4SLinus Torvalds	    $lineprefix="     ";
13441da177e4SLinus Torvalds	    output_highlight($args{'parameterdescs'}{$parameter_name});
13451da177e4SLinus Torvalds	    print "    </entry></row>\n";
13461da177e4SLinus Torvalds	}
13471da177e4SLinus Torvalds	print " </tbody></tgroup></informaltable>\n";
13481da177e4SLinus Torvalds    } else {
13491da177e4SLinus Torvalds	print " <para>\n  None\n </para>\n";
13501da177e4SLinus Torvalds    }
13511da177e4SLinus Torvalds
13521da177e4SLinus Torvalds    # print out each section
13531da177e4SLinus Torvalds    $lineprefix="   ";
13541da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
13551da177e4SLinus Torvalds	print "<simplesect>\n <title>$section</title>\n";
13561da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
13571da177e4SLinus Torvalds	    print "<example><programlisting>\n";
1358e314ba31SDaniel Santos	    $output_preformatted = 1;
13591da177e4SLinus Torvalds	} else {
13601da177e4SLinus Torvalds	}
13611da177e4SLinus Torvalds	print "<para>\n";
13621da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
1363e314ba31SDaniel Santos	$output_preformatted = 0;
13641da177e4SLinus Torvalds	print "</para>\n";
13651da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
13661da177e4SLinus Torvalds	    print "</programlisting></example>\n";
13671da177e4SLinus Torvalds	} else {
13681da177e4SLinus Torvalds	}
13691da177e4SLinus Torvalds	print " </simplesect>\n";
13701da177e4SLinus Torvalds    }
13711da177e4SLinus Torvalds
13721da177e4SLinus Torvalds    print "</sect2>\n\n";
13731da177e4SLinus Torvalds}
13741da177e4SLinus Torvalds
13751da177e4SLinus Torvalds##
13761da177e4SLinus Torvalds# output function in man
13771da177e4SLinus Torvaldssub output_function_man(%) {
13781da177e4SLinus Torvalds    my %args = %{$_[0]};
13791da177e4SLinus Torvalds    my ($parameter, $section);
13801da177e4SLinus Torvalds    my $count;
13811da177e4SLinus Torvalds
13821da177e4SLinus Torvalds    print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
13831da177e4SLinus Torvalds
13841da177e4SLinus Torvalds    print ".SH NAME\n";
13851da177e4SLinus Torvalds    print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
13861da177e4SLinus Torvalds
13871da177e4SLinus Torvalds    print ".SH SYNOPSIS\n";
1388a21217daSRandy Dunlap    if ($args{'functiontype'} ne "") {
13891da177e4SLinus Torvalds	print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
1390a21217daSRandy Dunlap    } else {
1391a21217daSRandy Dunlap	print ".B \"" . $args{'function'} . "\n";
1392a21217daSRandy Dunlap    }
13931da177e4SLinus Torvalds    $count = 0;
13941da177e4SLinus Torvalds    my $parenth = "(";
13951da177e4SLinus Torvalds    my $post = ",";
13961da177e4SLinus Torvalds    foreach my $parameter (@{$args{'parameterlist'}}) {
13971da177e4SLinus Torvalds	if ($count == $#{$args{'parameterlist'}}) {
13981da177e4SLinus Torvalds	    $post = ");";
13991da177e4SLinus Torvalds	}
14001da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
14011da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
14021da177e4SLinus Torvalds	    # pointer-to-function
14031da177e4SLinus Torvalds	    print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
14041da177e4SLinus Torvalds	} else {
14051da177e4SLinus Torvalds	    $type =~ s/([^\*])$/$1 /;
14061da177e4SLinus Torvalds	    print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
14071da177e4SLinus Torvalds	}
14081da177e4SLinus Torvalds	$count++;
14091da177e4SLinus Torvalds	$parenth = "";
14101da177e4SLinus Torvalds    }
14111da177e4SLinus Torvalds
14121da177e4SLinus Torvalds    print ".SH ARGUMENTS\n";
14131da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
14141da177e4SLinus Torvalds	my $parameter_name = $parameter;
14151da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
14161da177e4SLinus Torvalds
14171da177e4SLinus Torvalds	print ".IP \"" . $parameter . "\" 12\n";
14181da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter_name});
14191da177e4SLinus Torvalds    }
14201da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
14211da177e4SLinus Torvalds	print ".SH \"", uc $section, "\"\n";
14221da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
14231da177e4SLinus Torvalds    }
14241da177e4SLinus Torvalds}
14251da177e4SLinus Torvalds
14261da177e4SLinus Torvalds##
14271da177e4SLinus Torvalds# output enum in man
14281da177e4SLinus Torvaldssub output_enum_man(%) {
14291da177e4SLinus Torvalds    my %args = %{$_[0]};
14301da177e4SLinus Torvalds    my ($parameter, $section);
14311da177e4SLinus Torvalds    my $count;
14321da177e4SLinus Torvalds
14331da177e4SLinus Torvalds    print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
14341da177e4SLinus Torvalds
14351da177e4SLinus Torvalds    print ".SH NAME\n";
14361da177e4SLinus Torvalds    print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
14371da177e4SLinus Torvalds
14381da177e4SLinus Torvalds    print ".SH SYNOPSIS\n";
14391da177e4SLinus Torvalds    print "enum " . $args{'enum'} . " {\n";
14401da177e4SLinus Torvalds    $count = 0;
14411da177e4SLinus Torvalds    foreach my $parameter (@{$args{'parameterlist'}}) {
14421da177e4SLinus Torvalds	print ".br\n.BI \"    $parameter\"\n";
14431da177e4SLinus Torvalds	if ($count == $#{$args{'parameterlist'}}) {
14441da177e4SLinus Torvalds	    print "\n};\n";
14451da177e4SLinus Torvalds	    last;
14461da177e4SLinus Torvalds	}
14471da177e4SLinus Torvalds	else {
14481da177e4SLinus Torvalds	    print ", \n.br\n";
14491da177e4SLinus Torvalds	}
14501da177e4SLinus Torvalds	$count++;
14511da177e4SLinus Torvalds    }
14521da177e4SLinus Torvalds
14531da177e4SLinus Torvalds    print ".SH Constants\n";
14541da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
14551da177e4SLinus Torvalds	my $parameter_name = $parameter;
14561da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
14571da177e4SLinus Torvalds
14581da177e4SLinus Torvalds	print ".IP \"" . $parameter . "\" 12\n";
14591da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter_name});
14601da177e4SLinus Torvalds    }
14611da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
14621da177e4SLinus Torvalds	print ".SH \"$section\"\n";
14631da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
14641da177e4SLinus Torvalds    }
14651da177e4SLinus Torvalds}
14661da177e4SLinus Torvalds
14671da177e4SLinus Torvalds##
14681da177e4SLinus Torvalds# output struct in man
14691da177e4SLinus Torvaldssub output_struct_man(%) {
14701da177e4SLinus Torvalds    my %args = %{$_[0]};
14711da177e4SLinus Torvalds    my ($parameter, $section);
14721da177e4SLinus Torvalds
14731da177e4SLinus Torvalds    print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
14741da177e4SLinus Torvalds
14751da177e4SLinus Torvalds    print ".SH NAME\n";
14761da177e4SLinus Torvalds    print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
14771da177e4SLinus Torvalds
14781da177e4SLinus Torvalds    print ".SH SYNOPSIS\n";
14791da177e4SLinus Torvalds    print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
14801da177e4SLinus Torvalds
14811da177e4SLinus Torvalds    foreach my $parameter (@{$args{'parameterlist'}}) {
14821da177e4SLinus Torvalds	if ($parameter =~ /^#/) {
14831da177e4SLinus Torvalds	    print ".BI \"$parameter\"\n.br\n";
14841da177e4SLinus Torvalds	    next;
14851da177e4SLinus Torvalds	}
14861da177e4SLinus Torvalds	my $parameter_name = $parameter;
14871da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
14881da177e4SLinus Torvalds
14891da177e4SLinus Torvalds	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
14901da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
14911da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
14921da177e4SLinus Torvalds	    # pointer-to-function
14931da177e4SLinus Torvalds	    print ".BI \"    " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
14941da177e4SLinus Torvalds	} elsif ($type =~ m/^(.*?)\s*(:.*)/) {
14951d7e1d45SRandy.Dunlap	    # bitfield
14961d7e1d45SRandy.Dunlap	    print ".BI \"    " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
14971da177e4SLinus Torvalds	} else {
14981da177e4SLinus Torvalds	    $type =~ s/([^\*])$/$1 /;
14991da177e4SLinus Torvalds	    print ".BI \"    " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
15001da177e4SLinus Torvalds	}
15011da177e4SLinus Torvalds	print "\n.br\n";
15021da177e4SLinus Torvalds    }
15031da177e4SLinus Torvalds    print "};\n.br\n";
15041da177e4SLinus Torvalds
1505c51d3dacSRandy Dunlap    print ".SH Members\n";
15061da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
15071da177e4SLinus Torvalds	($parameter =~ /^#/) && next;
15081da177e4SLinus Torvalds
15091da177e4SLinus Torvalds	my $parameter_name = $parameter;
15101da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
15111da177e4SLinus Torvalds
15121da177e4SLinus Torvalds	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
15131da177e4SLinus Torvalds	print ".IP \"" . $parameter . "\" 12\n";
15141da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter_name});
15151da177e4SLinus Torvalds    }
15161da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
15171da177e4SLinus Torvalds	print ".SH \"$section\"\n";
15181da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
15191da177e4SLinus Torvalds    }
15201da177e4SLinus Torvalds}
15211da177e4SLinus Torvalds
15221da177e4SLinus Torvalds##
15231da177e4SLinus Torvalds# output typedef in man
15241da177e4SLinus Torvaldssub output_typedef_man(%) {
15251da177e4SLinus Torvalds    my %args = %{$_[0]};
15261da177e4SLinus Torvalds    my ($parameter, $section);
15271da177e4SLinus Torvalds
15281da177e4SLinus Torvalds    print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
15291da177e4SLinus Torvalds
15301da177e4SLinus Torvalds    print ".SH NAME\n";
15311da177e4SLinus Torvalds    print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
15321da177e4SLinus Torvalds
15331da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
15341da177e4SLinus Torvalds	print ".SH \"$section\"\n";
15351da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
15361da177e4SLinus Torvalds    }
15371da177e4SLinus Torvalds}
15381da177e4SLinus Torvalds
1539b112e0f7SJohannes Bergsub output_blockhead_man(%) {
15401da177e4SLinus Torvalds    my %args = %{$_[0]};
15411da177e4SLinus Torvalds    my ($parameter, $section);
15421da177e4SLinus Torvalds    my $count;
15431da177e4SLinus Torvalds
15441da177e4SLinus Torvalds    print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
15451da177e4SLinus Torvalds
15461da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
15471da177e4SLinus Torvalds	print ".SH \"$section\"\n";
15481da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
15491da177e4SLinus Torvalds    }
15501da177e4SLinus Torvalds}
15511da177e4SLinus Torvalds
15521da177e4SLinus Torvalds##
15531da177e4SLinus Torvalds# output in text
15541da177e4SLinus Torvaldssub output_function_text(%) {
15551da177e4SLinus Torvalds    my %args = %{$_[0]};
15561da177e4SLinus Torvalds    my ($parameter, $section);
1557a21217daSRandy Dunlap    my $start;
15581da177e4SLinus Torvalds
1559f47634b2SRandy Dunlap    print "Name:\n\n";
1560f47634b2SRandy Dunlap    print $args{'function'} . " - " . $args{'purpose'} . "\n";
1561f47634b2SRandy Dunlap
1562f47634b2SRandy Dunlap    print "\nSynopsis:\n\n";
1563a21217daSRandy Dunlap    if ($args{'functiontype'} ne "") {
1564a21217daSRandy Dunlap	$start = $args{'functiontype'} . " " . $args{'function'} . " (";
1565a21217daSRandy Dunlap    } else {
1566a21217daSRandy Dunlap	$start = $args{'function'} . " (";
1567a21217daSRandy Dunlap    }
15681da177e4SLinus Torvalds    print $start;
1569a21217daSRandy Dunlap
15701da177e4SLinus Torvalds    my $count = 0;
15711da177e4SLinus Torvalds    foreach my $parameter (@{$args{'parameterlist'}}) {
15721da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
15731da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
15741da177e4SLinus Torvalds	    # pointer-to-function
15751da177e4SLinus Torvalds	    print $1 . $parameter . ") (" . $2;
15761da177e4SLinus Torvalds	} else {
15771da177e4SLinus Torvalds	    print $type . " " . $parameter;
15781da177e4SLinus Torvalds	}
15791da177e4SLinus Torvalds	if ($count != $#{$args{'parameterlist'}}) {
15801da177e4SLinus Torvalds	    $count++;
15811da177e4SLinus Torvalds	    print ",\n";
15821da177e4SLinus Torvalds	    print " " x length($start);
15831da177e4SLinus Torvalds	} else {
15841da177e4SLinus Torvalds	    print ");\n\n";
15851da177e4SLinus Torvalds	}
15861da177e4SLinus Torvalds    }
15871da177e4SLinus Torvalds
15881da177e4SLinus Torvalds    print "Arguments:\n\n";
15891da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
15901da177e4SLinus Torvalds	my $parameter_name = $parameter;
15911da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
15921da177e4SLinus Torvalds
15931da177e4SLinus Torvalds	print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
15941da177e4SLinus Torvalds    }
15951da177e4SLinus Torvalds    output_section_text(@_);
15961da177e4SLinus Torvalds}
15971da177e4SLinus Torvalds
15981da177e4SLinus Torvalds#output sections in text
15991da177e4SLinus Torvaldssub output_section_text(%) {
16001da177e4SLinus Torvalds    my %args = %{$_[0]};
16011da177e4SLinus Torvalds    my $section;
16021da177e4SLinus Torvalds
16031da177e4SLinus Torvalds    print "\n";
16041da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
16051da177e4SLinus Torvalds	print "$section:\n\n";
16061da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
16071da177e4SLinus Torvalds    }
16081da177e4SLinus Torvalds    print "\n\n";
16091da177e4SLinus Torvalds}
16101da177e4SLinus Torvalds
16111da177e4SLinus Torvalds# output enum in text
16121da177e4SLinus Torvaldssub output_enum_text(%) {
16131da177e4SLinus Torvalds    my %args = %{$_[0]};
16141da177e4SLinus Torvalds    my ($parameter);
16151da177e4SLinus Torvalds    my $count;
16161da177e4SLinus Torvalds    print "Enum:\n\n";
16171da177e4SLinus Torvalds
16181d7e1d45SRandy.Dunlap    print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
16191da177e4SLinus Torvalds    print "enum " . $args{'enum'} . " {\n";
16201da177e4SLinus Torvalds    $count = 0;
16211da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
16221da177e4SLinus Torvalds	print "\t$parameter";
16231da177e4SLinus Torvalds	if ($count != $#{$args{'parameterlist'}}) {
16241da177e4SLinus Torvalds	    $count++;
16251da177e4SLinus Torvalds	    print ",";
16261da177e4SLinus Torvalds	}
16271da177e4SLinus Torvalds	print "\n";
16281da177e4SLinus Torvalds    }
16291da177e4SLinus Torvalds    print "};\n\n";
16301da177e4SLinus Torvalds
16311da177e4SLinus Torvalds    print "Constants:\n\n";
16321da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
16331da177e4SLinus Torvalds	print "$parameter\n\t";
16341da177e4SLinus Torvalds	print $args{'parameterdescs'}{$parameter} . "\n";
16351da177e4SLinus Torvalds    }
16361da177e4SLinus Torvalds
16371da177e4SLinus Torvalds    output_section_text(@_);
16381da177e4SLinus Torvalds}
16391da177e4SLinus Torvalds
16401da177e4SLinus Torvalds# output typedef in text
16411da177e4SLinus Torvaldssub output_typedef_text(%) {
16421da177e4SLinus Torvalds    my %args = %{$_[0]};
16431da177e4SLinus Torvalds    my ($parameter);
16441da177e4SLinus Torvalds    my $count;
16451da177e4SLinus Torvalds    print "Typedef:\n\n";
16461da177e4SLinus Torvalds
16471d7e1d45SRandy.Dunlap    print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
16481da177e4SLinus Torvalds    output_section_text(@_);
16491da177e4SLinus Torvalds}
16501da177e4SLinus Torvalds
16511da177e4SLinus Torvalds# output struct as text
16521da177e4SLinus Torvaldssub output_struct_text(%) {
16531da177e4SLinus Torvalds    my %args = %{$_[0]};
16541da177e4SLinus Torvalds    my ($parameter);
16551da177e4SLinus Torvalds
16561d7e1d45SRandy.Dunlap    print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
16571da177e4SLinus Torvalds    print $args{'type'} . " " . $args{'struct'} . " {\n";
16581da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
16591da177e4SLinus Torvalds	if ($parameter =~ /^#/) {
16601da177e4SLinus Torvalds	    print "$parameter\n";
16611da177e4SLinus Torvalds	    next;
16621da177e4SLinus Torvalds	}
16631da177e4SLinus Torvalds
16641da177e4SLinus Torvalds	my $parameter_name = $parameter;
16651da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
16661da177e4SLinus Torvalds
16671da177e4SLinus Torvalds	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
16681da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
16691da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
16701da177e4SLinus Torvalds	    # pointer-to-function
16711da177e4SLinus Torvalds	    print "\t$1 $parameter) ($2);\n";
16721da177e4SLinus Torvalds	} elsif ($type =~ m/^(.*?)\s*(:.*)/) {
167351f5a0c8SRandy Dunlap	    # bitfield
16741da177e4SLinus Torvalds	    print "\t$1 $parameter$2;\n";
16751da177e4SLinus Torvalds	} else {
16761da177e4SLinus Torvalds	    print "\t" . $type . " " . $parameter . ";\n";
16771da177e4SLinus Torvalds	}
16781da177e4SLinus Torvalds    }
16791da177e4SLinus Torvalds    print "};\n\n";
16801da177e4SLinus Torvalds
16811da177e4SLinus Torvalds    print "Members:\n\n";
16821da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
16831da177e4SLinus Torvalds	($parameter =~ /^#/) && next;
16841da177e4SLinus Torvalds
16851da177e4SLinus Torvalds	my $parameter_name = $parameter;
16861da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
16871da177e4SLinus Torvalds
16881da177e4SLinus Torvalds	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
16891da177e4SLinus Torvalds	print "$parameter\n\t";
16901da177e4SLinus Torvalds	print $args{'parameterdescs'}{$parameter_name} . "\n";
16911da177e4SLinus Torvalds    }
16921da177e4SLinus Torvalds    print "\n";
16931da177e4SLinus Torvalds    output_section_text(@_);
16941da177e4SLinus Torvalds}
16951da177e4SLinus Torvalds
1696b112e0f7SJohannes Bergsub output_blockhead_text(%) {
16971da177e4SLinus Torvalds    my %args = %{$_[0]};
16981da177e4SLinus Torvalds    my ($parameter, $section);
16991da177e4SLinus Torvalds
17001da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
17011da177e4SLinus Torvalds	print " $section:\n";
17021da177e4SLinus Torvalds	print "    -> ";
17031da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
17041da177e4SLinus Torvalds    }
17051da177e4SLinus Torvalds}
17061da177e4SLinus Torvalds
1707eda603f6SJohannes Berg## list mode output functions
1708eda603f6SJohannes Berg
1709eda603f6SJohannes Bergsub output_function_list(%) {
1710eda603f6SJohannes Berg    my %args = %{$_[0]};
1711eda603f6SJohannes Berg
1712eda603f6SJohannes Berg    print $args{'function'} . "\n";
1713eda603f6SJohannes Berg}
1714eda603f6SJohannes Berg
1715eda603f6SJohannes Berg# output enum in list
1716eda603f6SJohannes Bergsub output_enum_list(%) {
1717eda603f6SJohannes Berg    my %args = %{$_[0]};
1718eda603f6SJohannes Berg    print $args{'enum'} . "\n";
1719eda603f6SJohannes Berg}
1720eda603f6SJohannes Berg
1721eda603f6SJohannes Berg# output typedef in list
1722eda603f6SJohannes Bergsub output_typedef_list(%) {
1723eda603f6SJohannes Berg    my %args = %{$_[0]};
1724eda603f6SJohannes Berg    print $args{'typedef'} . "\n";
1725eda603f6SJohannes Berg}
1726eda603f6SJohannes Berg
1727eda603f6SJohannes Berg# output struct as list
1728eda603f6SJohannes Bergsub output_struct_list(%) {
1729eda603f6SJohannes Berg    my %args = %{$_[0]};
1730eda603f6SJohannes Berg
1731eda603f6SJohannes Berg    print $args{'struct'} . "\n";
1732eda603f6SJohannes Berg}
1733eda603f6SJohannes Berg
1734eda603f6SJohannes Bergsub output_blockhead_list(%) {
1735eda603f6SJohannes Berg    my %args = %{$_[0]};
1736eda603f6SJohannes Berg    my ($parameter, $section);
1737eda603f6SJohannes Berg
1738eda603f6SJohannes Berg    foreach $section (@{$args{'sectionlist'}}) {
1739eda603f6SJohannes Berg	print "DOC: $section\n";
1740eda603f6SJohannes Berg    }
1741eda603f6SJohannes Berg}
1742eda603f6SJohannes Berg
17431da177e4SLinus Torvalds##
174427205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum);
174527205744SRandy Dunlap# calls the generated, variable output_ function name based on
174627205744SRandy Dunlap# functype and output_mode
17471da177e4SLinus Torvaldssub output_declaration {
17481da177e4SLinus Torvalds    no strict 'refs';
17491da177e4SLinus Torvalds    my $name = shift;
17501da177e4SLinus Torvalds    my $functype = shift;
17511da177e4SLinus Torvalds    my $func = "output_${functype}_$output_mode";
17521da177e4SLinus Torvalds    if (($function_only==0) ||
17531da177e4SLinus Torvalds	( $function_only == 1 && defined($function_table{$name})) ||
175423aebb3cSDanilo Cesar Lemes de Paula	( $function_only == 2 && !($functype eq "function" && defined($function_table{$name}))))
17551da177e4SLinus Torvalds    {
17561da177e4SLinus Torvalds	&$func(@_);
17571da177e4SLinus Torvalds	$section_counter++;
17581da177e4SLinus Torvalds    }
17591da177e4SLinus Torvalds}
17601da177e4SLinus Torvalds
17611da177e4SLinus Torvalds##
176227205744SRandy Dunlap# generic output function - calls the right one based on current output mode.
1763b112e0f7SJohannes Bergsub output_blockhead {
17641da177e4SLinus Torvalds    no strict 'refs';
1765b112e0f7SJohannes Berg    my $func = "output_blockhead_" . $output_mode;
17661da177e4SLinus Torvalds    &$func(@_);
17671da177e4SLinus Torvalds    $section_counter++;
17681da177e4SLinus Torvalds}
17691da177e4SLinus Torvalds
17701da177e4SLinus Torvalds##
17711da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and
17721da177e4SLinus Torvalds# invokes the right handler. NOT called for functions.
17731da177e4SLinus Torvaldssub dump_declaration($$) {
17741da177e4SLinus Torvalds    no strict 'refs';
17751da177e4SLinus Torvalds    my ($prototype, $file) = @_;
17761da177e4SLinus Torvalds    my $func = "dump_" . $decl_type;
17771da177e4SLinus Torvalds    &$func(@_);
17781da177e4SLinus Torvalds}
17791da177e4SLinus Torvalds
17801da177e4SLinus Torvaldssub dump_union($$) {
17811da177e4SLinus Torvalds    dump_struct(@_);
17821da177e4SLinus Torvalds}
17831da177e4SLinus Torvalds
17841da177e4SLinus Torvaldssub dump_struct($$) {
17851da177e4SLinus Torvalds    my $x = shift;
17861da177e4SLinus Torvalds    my $file = shift;
1787a1d94aa5SRandy Dunlap    my $nested;
17881da177e4SLinus Torvalds
17891da177e4SLinus Torvalds    if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
179052dc5aecSRandy Dunlap	#my $decl_type = $1;
17911da177e4SLinus Torvalds	$declaration_name = $2;
17921da177e4SLinus Torvalds	my $members = $3;
17931da177e4SLinus Torvalds
17941da177e4SLinus Torvalds	# ignore embedded structs or unions
1795a1d94aa5SRandy Dunlap	$members =~ s/({.*})//g;
1796a1d94aa5SRandy Dunlap	$nested = $1;
17971da177e4SLinus Torvalds
1798aeec46b9SMartin Waitz	# ignore members marked private:
17990d8c39e6SMauro Carvalho Chehab	$members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
18000d8c39e6SMauro Carvalho Chehab	$members =~ s/\/\*\s*private:.*//gosi;
1801aeec46b9SMartin Waitz	# strip comments:
1802aeec46b9SMartin Waitz	$members =~ s/\/\*.*?\*\///gos;
1803a1d94aa5SRandy Dunlap	$nested =~ s/\/\*.*?\*\///gos;
1804d960eea9SRandy Dunlap	# strip kmemcheck_bitfield_{begin,end}.*;
1805d960eea9SRandy Dunlap	$members =~ s/kmemcheck_bitfield_.*?;//gos;
1806ef5da59fSRandy Dunlap	# strip attributes
1807f0074929SJonathan Corbet	$members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
18087b990789SJohannes Berg	$members =~ s/__aligned\s*\([^;]*\)//gos;
1809f0074929SJonathan Corbet	$members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos;
1810b22b5a9eSConchúr Navid	# replace DECLARE_BITMAP
1811b22b5a9eSConchúr Navid	$members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
1812aeec46b9SMartin Waitz
18131da177e4SLinus Torvalds	create_parameterlist($members, ';', $file);
1814a1d94aa5SRandy Dunlap	check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
18151da177e4SLinus Torvalds
18161da177e4SLinus Torvalds	output_declaration($declaration_name,
18171da177e4SLinus Torvalds			   'struct',
18181da177e4SLinus Torvalds			   {'struct' => $declaration_name,
18191da177e4SLinus Torvalds			    'module' => $modulename,
18201da177e4SLinus Torvalds			    'parameterlist' => \@parameterlist,
18211da177e4SLinus Torvalds			    'parameterdescs' => \%parameterdescs,
18221da177e4SLinus Torvalds			    'parametertypes' => \%parametertypes,
18231da177e4SLinus Torvalds			    'sectionlist' => \@sectionlist,
18241da177e4SLinus Torvalds			    'sections' => \%sections,
18251da177e4SLinus Torvalds			    'purpose' => $declaration_purpose,
18261da177e4SLinus Torvalds			    'type' => $decl_type
18271da177e4SLinus Torvalds			   });
18281da177e4SLinus Torvalds    }
18291da177e4SLinus Torvalds    else {
1830d40e1e65SBart Van Assche	print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
18311da177e4SLinus Torvalds	++$errors;
18321da177e4SLinus Torvalds    }
18331da177e4SLinus Torvalds}
18341da177e4SLinus Torvalds
18351da177e4SLinus Torvaldssub dump_enum($$) {
18361da177e4SLinus Torvalds    my $x = shift;
18371da177e4SLinus Torvalds    my $file = shift;
18381da177e4SLinus Torvalds
1839aeec46b9SMartin Waitz    $x =~ s@/\*.*?\*/@@gos;	# strip comments.
18404468e21eSConchúr Navid    # strip #define macros inside enums
18414468e21eSConchúr Navid    $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos;
1842b6d676dbSRandy Dunlap
18431da177e4SLinus Torvalds    if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
18441da177e4SLinus Torvalds	$declaration_name = $1;
18451da177e4SLinus Torvalds	my $members = $2;
18461da177e4SLinus Torvalds
18471da177e4SLinus Torvalds	foreach my $arg (split ',', $members) {
18481da177e4SLinus Torvalds	    $arg =~ s/^\s*(\w+).*/$1/;
18491da177e4SLinus Torvalds	    push @parameterlist, $arg;
18501da177e4SLinus Torvalds	    if (!$parameterdescs{$arg}) {
18511da177e4SLinus Torvalds		$parameterdescs{$arg} = $undescribed;
1852d40e1e65SBart Van Assche		print STDERR "${file}:$.: warning: Enum value '$arg' ".
18531da177e4SLinus Torvalds		    "not described in enum '$declaration_name'\n";
18541da177e4SLinus Torvalds	    }
18551da177e4SLinus Torvalds
18561da177e4SLinus Torvalds	}
18571da177e4SLinus Torvalds
18581da177e4SLinus Torvalds	output_declaration($declaration_name,
18591da177e4SLinus Torvalds			   'enum',
18601da177e4SLinus Torvalds			   {'enum' => $declaration_name,
18611da177e4SLinus Torvalds			    'module' => $modulename,
18621da177e4SLinus Torvalds			    'parameterlist' => \@parameterlist,
18631da177e4SLinus Torvalds			    'parameterdescs' => \%parameterdescs,
18641da177e4SLinus Torvalds			    'sectionlist' => \@sectionlist,
18651da177e4SLinus Torvalds			    'sections' => \%sections,
18661da177e4SLinus Torvalds			    'purpose' => $declaration_purpose
18671da177e4SLinus Torvalds			   });
18681da177e4SLinus Torvalds    }
18691da177e4SLinus Torvalds    else {
1870d40e1e65SBart Van Assche	print STDERR "${file}:$.: error: Cannot parse enum!\n";
18711da177e4SLinus Torvalds	++$errors;
18721da177e4SLinus Torvalds    }
18731da177e4SLinus Torvalds}
18741da177e4SLinus Torvalds
18751da177e4SLinus Torvaldssub dump_typedef($$) {
18761da177e4SLinus Torvalds    my $x = shift;
18771da177e4SLinus Torvalds    my $file = shift;
18781da177e4SLinus Torvalds
1879aeec46b9SMartin Waitz    $x =~ s@/\*.*?\*/@@gos;	# strip comments.
188083766452SMauro Carvalho Chehab
188183766452SMauro Carvalho Chehab    # Parse function prototypes
188283766452SMauro Carvalho Chehab    if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) {
188383766452SMauro Carvalho Chehab	# Function typedefs
188483766452SMauro Carvalho Chehab	$return_type = $1;
188583766452SMauro Carvalho Chehab	$declaration_name = $2;
188683766452SMauro Carvalho Chehab	my $args = $3;
188783766452SMauro Carvalho Chehab
188883766452SMauro Carvalho Chehab	create_parameterlist($args, ',', $file);
188983766452SMauro Carvalho Chehab
189083766452SMauro Carvalho Chehab	output_declaration($declaration_name,
189183766452SMauro Carvalho Chehab			   'function',
189283766452SMauro Carvalho Chehab			   {'function' => $declaration_name,
189383766452SMauro Carvalho Chehab			    'module' => $modulename,
189483766452SMauro Carvalho Chehab			    'functiontype' => $return_type,
189583766452SMauro Carvalho Chehab			    'parameterlist' => \@parameterlist,
189683766452SMauro Carvalho Chehab			    'parameterdescs' => \%parameterdescs,
189783766452SMauro Carvalho Chehab			    'parametertypes' => \%parametertypes,
189883766452SMauro Carvalho Chehab			    'sectionlist' => \@sectionlist,
189983766452SMauro Carvalho Chehab			    'sections' => \%sections,
190083766452SMauro Carvalho Chehab			    'purpose' => $declaration_purpose
190183766452SMauro Carvalho Chehab			   });
190283766452SMauro Carvalho Chehab	return;
190383766452SMauro Carvalho Chehab    }
190483766452SMauro Carvalho Chehab
19051da177e4SLinus Torvalds    while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
19061da177e4SLinus Torvalds	$x =~ s/\(*.\)\s*;$/;/;
19071da177e4SLinus Torvalds	$x =~ s/\[*.\]\s*;$/;/;
19081da177e4SLinus Torvalds    }
19091da177e4SLinus Torvalds
19101da177e4SLinus Torvalds    if ($x =~ /typedef.*\s+(\w+)\s*;/) {
19111da177e4SLinus Torvalds	$declaration_name = $1;
19121da177e4SLinus Torvalds
19131da177e4SLinus Torvalds	output_declaration($declaration_name,
19141da177e4SLinus Torvalds			   'typedef',
19151da177e4SLinus Torvalds			   {'typedef' => $declaration_name,
19161da177e4SLinus Torvalds			    'module' => $modulename,
19171da177e4SLinus Torvalds			    'sectionlist' => \@sectionlist,
19181da177e4SLinus Torvalds			    'sections' => \%sections,
19191da177e4SLinus Torvalds			    'purpose' => $declaration_purpose
19201da177e4SLinus Torvalds			   });
19211da177e4SLinus Torvalds    }
19221da177e4SLinus Torvalds    else {
1923d40e1e65SBart Van Assche	print STDERR "${file}:$.: error: Cannot parse typedef!\n";
19241da177e4SLinus Torvalds	++$errors;
19251da177e4SLinus Torvalds    }
19261da177e4SLinus Torvalds}
19271da177e4SLinus Torvalds
1928a1d94aa5SRandy Dunlapsub save_struct_actual($) {
1929a1d94aa5SRandy Dunlap    my $actual = shift;
1930a1d94aa5SRandy Dunlap
1931a1d94aa5SRandy Dunlap    # strip all spaces from the actual param so that it looks like one string item
1932a1d94aa5SRandy Dunlap    $actual =~ s/\s*//g;
1933a1d94aa5SRandy Dunlap    $struct_actual = $struct_actual . $actual . " ";
1934a1d94aa5SRandy Dunlap}
1935a1d94aa5SRandy Dunlap
19361da177e4SLinus Torvaldssub create_parameterlist($$$) {
19371da177e4SLinus Torvalds    my $args = shift;
19381da177e4SLinus Torvalds    my $splitter = shift;
19391da177e4SLinus Torvalds    my $file = shift;
19401da177e4SLinus Torvalds    my $type;
19411da177e4SLinus Torvalds    my $param;
19421da177e4SLinus Torvalds
1943a6d3fe77SMartin Waitz    # temporarily replace commas inside function pointer definition
19441da177e4SLinus Torvalds    while ($args =~ /(\([^\),]+),/) {
19451da177e4SLinus Torvalds	$args =~ s/(\([^\),]+),/$1#/g;
19461da177e4SLinus Torvalds    }
19471da177e4SLinus Torvalds
19481da177e4SLinus Torvalds    foreach my $arg (split($splitter, $args)) {
19491da177e4SLinus Torvalds	# strip comments
19501da177e4SLinus Torvalds	$arg =~ s/\/\*.*\*\///;
19511da177e4SLinus Torvalds	# strip leading/trailing spaces
19521da177e4SLinus Torvalds	$arg =~ s/^\s*//;
19531da177e4SLinus Torvalds	$arg =~ s/\s*$//;
19541da177e4SLinus Torvalds	$arg =~ s/\s+/ /;
19551da177e4SLinus Torvalds
19561da177e4SLinus Torvalds	if ($arg =~ /^#/) {
19571da177e4SLinus Torvalds	    # Treat preprocessor directive as a typeless variable just to fill
19581da177e4SLinus Torvalds	    # corresponding data structures "correctly". Catch it later in
19591da177e4SLinus Torvalds	    # output_* subs.
19601da177e4SLinus Torvalds	    push_parameter($arg, "", $file);
196100d62961SRichard Kennedy	} elsif ($arg =~ m/\(.+\)\s*\(/) {
19621da177e4SLinus Torvalds	    # pointer-to-function
19631da177e4SLinus Torvalds	    $arg =~ tr/#/,/;
196400d62961SRichard Kennedy	    $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
19651da177e4SLinus Torvalds	    $param = $1;
19661da177e4SLinus Torvalds	    $type = $arg;
196700d62961SRichard Kennedy	    $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
1968a1d94aa5SRandy Dunlap	    save_struct_actual($param);
19691da177e4SLinus Torvalds	    push_parameter($param, $type, $file);
1970aeec46b9SMartin Waitz	} elsif ($arg) {
19711da177e4SLinus Torvalds	    $arg =~ s/\s*:\s*/:/g;
19721da177e4SLinus Torvalds	    $arg =~ s/\s*\[/\[/g;
19731da177e4SLinus Torvalds
19741da177e4SLinus Torvalds	    my @args = split('\s*,\s*', $arg);
19751da177e4SLinus Torvalds	    if ($args[0] =~ m/\*/) {
19761da177e4SLinus Torvalds		$args[0] =~ s/(\*+)\s*/ $1/;
19771da177e4SLinus Torvalds	    }
1978884f2810SBorislav Petkov
1979884f2810SBorislav Petkov	    my @first_arg;
1980884f2810SBorislav Petkov	    if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1981884f2810SBorislav Petkov		    shift @args;
1982884f2810SBorislav Petkov		    push(@first_arg, split('\s+', $1));
1983884f2810SBorislav Petkov		    push(@first_arg, $2);
1984884f2810SBorislav Petkov	    } else {
1985884f2810SBorislav Petkov		    @first_arg = split('\s+', shift @args);
1986884f2810SBorislav Petkov	    }
1987884f2810SBorislav Petkov
19881da177e4SLinus Torvalds	    unshift(@args, pop @first_arg);
19891da177e4SLinus Torvalds	    $type = join " ", @first_arg;
19901da177e4SLinus Torvalds
19911da177e4SLinus Torvalds	    foreach $param (@args) {
19921da177e4SLinus Torvalds		if ($param =~ m/^(\*+)\s*(.*)/) {
1993a1d94aa5SRandy Dunlap		    save_struct_actual($2);
19941da177e4SLinus Torvalds		    push_parameter($2, "$type $1", $file);
19951da177e4SLinus Torvalds		}
19961da177e4SLinus Torvalds		elsif ($param =~ m/(.*?):(\d+)/) {
19977b97887eSRandy Dunlap		    if ($type ne "") { # skip unnamed bit-fields
1998a1d94aa5SRandy Dunlap			save_struct_actual($1);
19991da177e4SLinus Torvalds			push_parameter($1, "$type:$2", $file)
20001da177e4SLinus Torvalds		    }
20017b97887eSRandy Dunlap		}
20021da177e4SLinus Torvalds		else {
2003a1d94aa5SRandy Dunlap		    save_struct_actual($param);
20041da177e4SLinus Torvalds		    push_parameter($param, $type, $file);
20051da177e4SLinus Torvalds		}
20061da177e4SLinus Torvalds	    }
20071da177e4SLinus Torvalds	}
20081da177e4SLinus Torvalds    }
20091da177e4SLinus Torvalds}
20101da177e4SLinus Torvalds
20111da177e4SLinus Torvaldssub push_parameter($$$) {
20121da177e4SLinus Torvalds	my $param = shift;
20131da177e4SLinus Torvalds	my $type = shift;
20141da177e4SLinus Torvalds	my $file = shift;
20151da177e4SLinus Torvalds
20165f8c7c98SRandy Dunlap	if (($anon_struct_union == 1) && ($type eq "") &&
20175f8c7c98SRandy Dunlap	    ($param eq "}")) {
20185f8c7c98SRandy Dunlap		return;		# ignore the ending }; from anon. struct/union
20195f8c7c98SRandy Dunlap	}
20205f8c7c98SRandy Dunlap
20215f8c7c98SRandy Dunlap	$anon_struct_union = 0;
20221da177e4SLinus Torvalds	my $param_name = $param;
20231da177e4SLinus Torvalds	$param_name =~ s/\[.*//;
20241da177e4SLinus Torvalds
2025a6d3fe77SMartin Waitz	if ($type eq "" && $param =~ /\.\.\.$/)
20261da177e4SLinus Torvalds	{
2027ced69090SRandy Dunlap	    if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
2028a6d3fe77SMartin Waitz		$parameterdescs{$param} = "variable arguments";
20291da177e4SLinus Torvalds	    }
2030ced69090SRandy Dunlap	}
20311da177e4SLinus Torvalds	elsif ($type eq "" && ($param eq "" or $param eq "void"))
20321da177e4SLinus Torvalds	{
20331da177e4SLinus Torvalds	    $param="void";
20341da177e4SLinus Torvalds	    $parameterdescs{void} = "no arguments";
20351da177e4SLinus Torvalds	}
2036134fe01bSRandy Dunlap	elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
2037134fe01bSRandy Dunlap	# handle unnamed (anonymous) union or struct:
2038134fe01bSRandy Dunlap	{
2039134fe01bSRandy Dunlap		$type = $param;
2040134fe01bSRandy Dunlap		$param = "{unnamed_" . $param . "}";
2041134fe01bSRandy Dunlap		$parameterdescs{$param} = "anonymous\n";
20425f8c7c98SRandy Dunlap		$anon_struct_union = 1;
2043134fe01bSRandy Dunlap	}
2044134fe01bSRandy Dunlap
2045a6d3fe77SMartin Waitz	# warn if parameter has no description
2046134fe01bSRandy Dunlap	# (but ignore ones starting with # as these are not parameters
2047134fe01bSRandy Dunlap	# but inline preprocessor statements);
2048134fe01bSRandy Dunlap	# also ignore unnamed structs/unions;
20495f8c7c98SRandy Dunlap	if (!$anon_struct_union) {
2050a6d3fe77SMartin Waitz	if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
2051a6d3fe77SMartin Waitz
20521da177e4SLinus Torvalds	    $parameterdescs{$param_name} = $undescribed;
20531da177e4SLinus Torvalds
20541da177e4SLinus Torvalds	    if (($type eq 'function') || ($type eq 'enum')) {
2055d40e1e65SBart Van Assche		print STDERR "${file}:$.: warning: Function parameter ".
20561da177e4SLinus Torvalds		    "or member '$param' not " .
20571da177e4SLinus Torvalds		    "described in '$declaration_name'\n";
20581da177e4SLinus Torvalds	    }
2059d40e1e65SBart Van Assche	    print STDERR "${file}:$.: warning:" .
20601da177e4SLinus Torvalds			 " No description found for parameter '$param'\n";
20611da177e4SLinus Torvalds	    ++$warnings;
20621da177e4SLinus Torvalds	}
2063134fe01bSRandy Dunlap	}
20641da177e4SLinus Torvalds
20652b35f4d9SRandy Dunlap	$param = xml_escape($param);
20662b35f4d9SRandy Dunlap
206725985edcSLucas De Marchi	# strip spaces from $param so that it is one continuous string
2068e34e7dbbSRandy Dunlap	# on @parameterlist;
2069e34e7dbbSRandy Dunlap	# this fixes a problem where check_sections() cannot find
2070e34e7dbbSRandy Dunlap	# a parameter like "addr[6 + 2]" because it actually appears
2071e34e7dbbSRandy Dunlap	# as "addr[6", "+", "2]" on the parameter list;
2072e34e7dbbSRandy Dunlap	# but it's better to maintain the param string unchanged for output,
2073e34e7dbbSRandy Dunlap	# so just weaken the string compare in check_sections() to ignore
2074e34e7dbbSRandy Dunlap	# "[blah" in a parameter string;
2075e34e7dbbSRandy Dunlap	###$param =~ s/\s*//g;
20761da177e4SLinus Torvalds	push @parameterlist, $param;
20771da177e4SLinus Torvalds	$parametertypes{$param} = $type;
20781da177e4SLinus Torvalds}
20791da177e4SLinus Torvalds
2080a1d94aa5SRandy Dunlapsub check_sections($$$$$$) {
2081a1d94aa5SRandy Dunlap	my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
2082a1d94aa5SRandy Dunlap	my @sects = split ' ', $sectcheck;
2083a1d94aa5SRandy Dunlap	my @prms = split ' ', $prmscheck;
2084a1d94aa5SRandy Dunlap	my $err;
2085a1d94aa5SRandy Dunlap	my ($px, $sx);
2086a1d94aa5SRandy Dunlap	my $prm_clean;		# strip trailing "[array size]" and/or beginning "*"
2087a1d94aa5SRandy Dunlap
2088a1d94aa5SRandy Dunlap	foreach $sx (0 .. $#sects) {
2089a1d94aa5SRandy Dunlap		$err = 1;
2090a1d94aa5SRandy Dunlap		foreach $px (0 .. $#prms) {
2091a1d94aa5SRandy Dunlap			$prm_clean = $prms[$px];
2092a1d94aa5SRandy Dunlap			$prm_clean =~ s/\[.*\]//;
20931f3a6688SJohannes Berg			$prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
2094e34e7dbbSRandy Dunlap			# ignore array size in a parameter string;
2095e34e7dbbSRandy Dunlap			# however, the original param string may contain
2096e34e7dbbSRandy Dunlap			# spaces, e.g.:  addr[6 + 2]
2097e34e7dbbSRandy Dunlap			# and this appears in @prms as "addr[6" since the
2098e34e7dbbSRandy Dunlap			# parameter list is split at spaces;
2099e34e7dbbSRandy Dunlap			# hence just ignore "[..." for the sections check;
2100e34e7dbbSRandy Dunlap			$prm_clean =~ s/\[.*//;
2101e34e7dbbSRandy Dunlap
2102a1d94aa5SRandy Dunlap			##$prm_clean =~ s/^\**//;
2103a1d94aa5SRandy Dunlap			if ($prm_clean eq $sects[$sx]) {
2104a1d94aa5SRandy Dunlap				$err = 0;
2105a1d94aa5SRandy Dunlap				last;
2106a1d94aa5SRandy Dunlap			}
2107a1d94aa5SRandy Dunlap		}
2108a1d94aa5SRandy Dunlap		if ($err) {
2109a1d94aa5SRandy Dunlap			if ($decl_type eq "function") {
2110d40e1e65SBart Van Assche				print STDERR "${file}:$.: warning: " .
2111a1d94aa5SRandy Dunlap					"Excess function parameter " .
2112a1d94aa5SRandy Dunlap					"'$sects[$sx]' " .
2113a1d94aa5SRandy Dunlap					"description in '$decl_name'\n";
2114a1d94aa5SRandy Dunlap				++$warnings;
2115a1d94aa5SRandy Dunlap			} else {
2116a1d94aa5SRandy Dunlap				if ($nested !~ m/\Q$sects[$sx]\E/) {
2117d40e1e65SBart Van Assche				    print STDERR "${file}:$.: warning: " .
2118a1d94aa5SRandy Dunlap					"Excess struct/union/enum/typedef member " .
2119a1d94aa5SRandy Dunlap					"'$sects[$sx]' " .
2120a1d94aa5SRandy Dunlap					"description in '$decl_name'\n";
2121a1d94aa5SRandy Dunlap				    ++$warnings;
2122a1d94aa5SRandy Dunlap				}
2123a1d94aa5SRandy Dunlap			}
2124a1d94aa5SRandy Dunlap		}
2125a1d94aa5SRandy Dunlap	}
2126a1d94aa5SRandy Dunlap}
2127a1d94aa5SRandy Dunlap
21281da177e4SLinus Torvalds##
21294092bac7SYacine Belkadi# Checks the section describing the return value of a function.
21304092bac7SYacine Belkadisub check_return_section {
21314092bac7SYacine Belkadi        my $file = shift;
21324092bac7SYacine Belkadi        my $declaration_name = shift;
21334092bac7SYacine Belkadi        my $return_type = shift;
21344092bac7SYacine Belkadi
21354092bac7SYacine Belkadi        # Ignore an empty return type (It's a macro)
21364092bac7SYacine Belkadi        # Ignore functions with a "void" return type. (But don't ignore "void *")
21374092bac7SYacine Belkadi        if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
21384092bac7SYacine Belkadi                return;
21394092bac7SYacine Belkadi        }
21404092bac7SYacine Belkadi
21414092bac7SYacine Belkadi        if (!defined($sections{$section_return}) ||
21424092bac7SYacine Belkadi            $sections{$section_return} eq "") {
2143d40e1e65SBart Van Assche                print STDERR "${file}:$.: warning: " .
21444092bac7SYacine Belkadi                        "No description found for return value of " .
21454092bac7SYacine Belkadi                        "'$declaration_name'\n";
21464092bac7SYacine Belkadi                ++$warnings;
21474092bac7SYacine Belkadi        }
21484092bac7SYacine Belkadi}
21494092bac7SYacine Belkadi
21504092bac7SYacine Belkadi##
21511da177e4SLinus Torvalds# takes a function prototype and the name of the current file being
21521da177e4SLinus Torvalds# processed and spits out all the details stored in the global
21531da177e4SLinus Torvalds# arrays/hashes.
21541da177e4SLinus Torvaldssub dump_function($$) {
21551da177e4SLinus Torvalds    my $prototype = shift;
21561da177e4SLinus Torvalds    my $file = shift;
2157cbb4d3e6SHoria Geanta    my $noret = 0;
21581da177e4SLinus Torvalds
21591da177e4SLinus Torvalds    $prototype =~ s/^static +//;
21601da177e4SLinus Torvalds    $prototype =~ s/^extern +//;
21614dc3b16bSPavel Pisa    $prototype =~ s/^asmlinkage +//;
21621da177e4SLinus Torvalds    $prototype =~ s/^inline +//;
21631da177e4SLinus Torvalds    $prototype =~ s/^__inline__ +//;
216432e79401SRandy Dunlap    $prototype =~ s/^__inline +//;
216532e79401SRandy Dunlap    $prototype =~ s/^__always_inline +//;
216632e79401SRandy Dunlap    $prototype =~ s/^noinline +//;
216774fc5c65SRandy Dunlap    $prototype =~ s/__init +//;
216820072205SRandy Dunlap    $prototype =~ s/__init_or_module +//;
2169270a0096SRandy Dunlap    $prototype =~ s/__meminit +//;
217070c95b00SRandy Dunlap    $prototype =~ s/__must_check +//;
21710df7c0e3SRandy Dunlap    $prototype =~ s/__weak +//;
2172cbb4d3e6SHoria Geanta    my $define = $prototype =~ s/^#\s*define\s+//; #ak added
2173328d2440SRandy Dunlap    $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
21741da177e4SLinus Torvalds
21751da177e4SLinus Torvalds    # Yes, this truly is vile.  We are looking for:
21761da177e4SLinus Torvalds    # 1. Return type (may be nothing if we're looking at a macro)
21771da177e4SLinus Torvalds    # 2. Function name
21781da177e4SLinus Torvalds    # 3. Function parameters.
21791da177e4SLinus Torvalds    #
21801da177e4SLinus Torvalds    # All the while we have to watch out for function pointer parameters
21811da177e4SLinus Torvalds    # (which IIRC is what the two sections are for), C types (these
21821da177e4SLinus Torvalds    # regexps don't even start to express all the possibilities), and
21831da177e4SLinus Torvalds    # so on.
21841da177e4SLinus Torvalds    #
21851da177e4SLinus Torvalds    # If you mess with these regexps, it's a good idea to check that
21861da177e4SLinus Torvalds    # the following functions' documentation still comes out right:
21871da177e4SLinus Torvalds    # - parport_register_device (function pointer parameters)
21881da177e4SLinus Torvalds    # - atomic_set (macro)
21899598f91fSMartin Waitz    # - pci_match_device, __copy_to_user (long return type)
21901da177e4SLinus Torvalds
2191cbb4d3e6SHoria Geanta    if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) {
2192cbb4d3e6SHoria Geanta        # This is an object-like macro, it has no return type and no parameter
2193cbb4d3e6SHoria Geanta        # list.
2194cbb4d3e6SHoria Geanta        # Function-like macros are not allowed to have spaces between
2195cbb4d3e6SHoria Geanta        # declaration_name and opening parenthesis (notice the \s+).
2196cbb4d3e6SHoria Geanta        $return_type = $1;
2197cbb4d3e6SHoria Geanta        $declaration_name = $2;
2198cbb4d3e6SHoria Geanta        $noret = 1;
2199cbb4d3e6SHoria Geanta    } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
22001da177e4SLinus Torvalds	$prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
22011da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
22021da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
220394b3e03cSRandy Dunlap	$prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
22041da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
22051da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
22061da177e4SLinus Torvalds	$prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
22071da177e4SLinus Torvalds	$prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
22081da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
22091da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
22101da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
22111da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
22129598f91fSMartin Waitz	$prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
22139598f91fSMartin Waitz	$prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2214412ecd77SRandy Dunlap	$prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2215412ecd77SRandy Dunlap	$prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/)  {
22161da177e4SLinus Torvalds	$return_type = $1;
22171da177e4SLinus Torvalds	$declaration_name = $2;
22181da177e4SLinus Torvalds	my $args = $3;
22191da177e4SLinus Torvalds
22201da177e4SLinus Torvalds	create_parameterlist($args, ',', $file);
22211da177e4SLinus Torvalds    } else {
2222d40e1e65SBart Van Assche	print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n";
22231da177e4SLinus Torvalds	return;
22241da177e4SLinus Torvalds    }
22251da177e4SLinus Torvalds
2226a1d94aa5SRandy Dunlap	my $prms = join " ", @parameterlist;
2227a1d94aa5SRandy Dunlap	check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2228a1d94aa5SRandy Dunlap
22294092bac7SYacine Belkadi        # This check emits a lot of warnings at the moment, because many
22304092bac7SYacine Belkadi        # functions don't have a 'Return' doc section. So until the number
22314092bac7SYacine Belkadi        # of warnings goes sufficiently down, the check is only performed in
22324092bac7SYacine Belkadi        # verbose mode.
22334092bac7SYacine Belkadi        # TODO: always perform the check.
2234cbb4d3e6SHoria Geanta        if ($verbose && !$noret) {
22354092bac7SYacine Belkadi                check_return_section($file, $declaration_name, $return_type);
22364092bac7SYacine Belkadi        }
22374092bac7SYacine Belkadi
22381da177e4SLinus Torvalds    output_declaration($declaration_name,
22391da177e4SLinus Torvalds		       'function',
22401da177e4SLinus Torvalds		       {'function' => $declaration_name,
22411da177e4SLinus Torvalds			'module' => $modulename,
22421da177e4SLinus Torvalds			'functiontype' => $return_type,
22431da177e4SLinus Torvalds			'parameterlist' => \@parameterlist,
22441da177e4SLinus Torvalds			'parameterdescs' => \%parameterdescs,
22451da177e4SLinus Torvalds			'parametertypes' => \%parametertypes,
22461da177e4SLinus Torvalds			'sectionlist' => \@sectionlist,
22471da177e4SLinus Torvalds			'sections' => \%sections,
22481da177e4SLinus Torvalds			'purpose' => $declaration_purpose
22491da177e4SLinus Torvalds		       });
22501da177e4SLinus Torvalds}
22511da177e4SLinus Torvalds
22521da177e4SLinus Torvaldssub reset_state {
22531da177e4SLinus Torvalds    $function = "";
22541da177e4SLinus Torvalds    %constants = ();
22551da177e4SLinus Torvalds    %parameterdescs = ();
22561da177e4SLinus Torvalds    %parametertypes = ();
22571da177e4SLinus Torvalds    @parameterlist = ();
22581da177e4SLinus Torvalds    %sections = ();
22591da177e4SLinus Torvalds    @sectionlist = ();
2260a1d94aa5SRandy Dunlap    $sectcheck = "";
2261a1d94aa5SRandy Dunlap    $struct_actual = "";
22621da177e4SLinus Torvalds    $prototype = "";
22631da177e4SLinus Torvalds
22641da177e4SLinus Torvalds    $state = 0;
2265a4c6ebedSDanilo Cesar Lemes de Paula    $split_doc_state = 0;
22661da177e4SLinus Torvalds}
22671da177e4SLinus Torvalds
226856afb0f8SJason Baronsub tracepoint_munge($) {
226956afb0f8SJason Baron	my $file = shift;
227056afb0f8SJason Baron	my $tracepointname = 0;
227156afb0f8SJason Baron	my $tracepointargs = 0;
227256afb0f8SJason Baron
227356afb0f8SJason Baron	if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
227456afb0f8SJason Baron		$tracepointname = $1;
227556afb0f8SJason Baron	}
22763a9089fdSJason Baron	if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
22773a9089fdSJason Baron		$tracepointname = $1;
22783a9089fdSJason Baron	}
22793a9089fdSJason Baron	if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
22803a9089fdSJason Baron		$tracepointname = $2;
22813a9089fdSJason Baron	}
22823a9089fdSJason Baron	$tracepointname =~ s/^\s+//; #strip leading whitespace
228356afb0f8SJason Baron	if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
228456afb0f8SJason Baron		$tracepointargs = $1;
228556afb0f8SJason Baron	}
228656afb0f8SJason Baron	if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
2287d40e1e65SBart Van Assche		print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n".
228856afb0f8SJason Baron			     "$prototype\n";
228956afb0f8SJason Baron	} else {
229056afb0f8SJason Baron		$prototype = "static inline void trace_$tracepointname($tracepointargs)";
229156afb0f8SJason Baron	}
229256afb0f8SJason Baron}
229356afb0f8SJason Baron
2294b4870bc5SRandy Dunlapsub syscall_munge() {
2295b4870bc5SRandy Dunlap	my $void = 0;
2296b4870bc5SRandy Dunlap
2297b4870bc5SRandy Dunlap	$prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2298b4870bc5SRandy Dunlap##	if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2299b4870bc5SRandy Dunlap	if ($prototype =~ m/SYSCALL_DEFINE0/) {
2300b4870bc5SRandy Dunlap		$void = 1;
2301b4870bc5SRandy Dunlap##		$prototype = "long sys_$1(void)";
2302b4870bc5SRandy Dunlap	}
2303b4870bc5SRandy Dunlap
2304b4870bc5SRandy Dunlap	$prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2305b4870bc5SRandy Dunlap	if ($prototype =~ m/long (sys_.*?),/) {
2306b4870bc5SRandy Dunlap		$prototype =~ s/,/\(/;
2307b4870bc5SRandy Dunlap	} elsif ($void) {
2308b4870bc5SRandy Dunlap		$prototype =~ s/\)/\(void\)/;
2309b4870bc5SRandy Dunlap	}
2310b4870bc5SRandy Dunlap
2311b4870bc5SRandy Dunlap	# now delete all of the odd-number commas in $prototype
2312b4870bc5SRandy Dunlap	# so that arg types & arg names don't have a comma between them
2313b4870bc5SRandy Dunlap	my $count = 0;
2314b4870bc5SRandy Dunlap	my $len = length($prototype);
2315b4870bc5SRandy Dunlap	if ($void) {
2316b4870bc5SRandy Dunlap		$len = 0;	# skip the for-loop
2317b4870bc5SRandy Dunlap	}
2318b4870bc5SRandy Dunlap	for (my $ix = 0; $ix < $len; $ix++) {
2319b4870bc5SRandy Dunlap		if (substr($prototype, $ix, 1) eq ',') {
2320b4870bc5SRandy Dunlap			$count++;
2321b4870bc5SRandy Dunlap			if ($count % 2 == 1) {
2322b4870bc5SRandy Dunlap				substr($prototype, $ix, 1) = ' ';
2323b4870bc5SRandy Dunlap			}
2324b4870bc5SRandy Dunlap		}
2325b4870bc5SRandy Dunlap	}
2326b4870bc5SRandy Dunlap}
2327b4870bc5SRandy Dunlap
23281da177e4SLinus Torvaldssub process_state3_function($$) {
23291da177e4SLinus Torvalds    my $x = shift;
23301da177e4SLinus Torvalds    my $file = shift;
23311da177e4SLinus Torvalds
233251f5a0c8SRandy Dunlap    $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
233351f5a0c8SRandy Dunlap
2334890c78c2SRandy Dunlap    if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
23351da177e4SLinus Torvalds	# do nothing
23361da177e4SLinus Torvalds    }
23371da177e4SLinus Torvalds    elsif ($x =~ /([^\{]*)/) {
23381da177e4SLinus Torvalds	$prototype .= $1;
23391da177e4SLinus Torvalds    }
2340b4870bc5SRandy Dunlap
2341890c78c2SRandy Dunlap    if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
23421da177e4SLinus Torvalds	$prototype =~ s@/\*.*?\*/@@gos;	# strip comments.
23431da177e4SLinus Torvalds	$prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
23441da177e4SLinus Torvalds	$prototype =~ s@^\s+@@gos; # strip leading spaces
2345b4870bc5SRandy Dunlap	if ($prototype =~ /SYSCALL_DEFINE/) {
2346b4870bc5SRandy Dunlap		syscall_munge();
2347b4870bc5SRandy Dunlap	}
23483a9089fdSJason Baron	if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
23493a9089fdSJason Baron	    $prototype =~ /DEFINE_SINGLE_EVENT/)
23503a9089fdSJason Baron	{
235156afb0f8SJason Baron		tracepoint_munge($file);
235256afb0f8SJason Baron	}
23531da177e4SLinus Torvalds	dump_function($prototype, $file);
23541da177e4SLinus Torvalds	reset_state();
23551da177e4SLinus Torvalds    }
23561da177e4SLinus Torvalds}
23571da177e4SLinus Torvalds
23581da177e4SLinus Torvaldssub process_state3_type($$) {
23591da177e4SLinus Torvalds    my $x = shift;
23601da177e4SLinus Torvalds    my $file = shift;
23611da177e4SLinus Torvalds
23621da177e4SLinus Torvalds    $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
23631da177e4SLinus Torvalds    $x =~ s@^\s+@@gos; # strip leading spaces
23641da177e4SLinus Torvalds    $x =~ s@\s+$@@gos; # strip trailing spaces
236551f5a0c8SRandy Dunlap    $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
236651f5a0c8SRandy Dunlap
23671da177e4SLinus Torvalds    if ($x =~ /^#/) {
23681da177e4SLinus Torvalds	# To distinguish preprocessor directive from regular declaration later.
23691da177e4SLinus Torvalds	$x .= ";";
23701da177e4SLinus Torvalds    }
23711da177e4SLinus Torvalds
23721da177e4SLinus Torvalds    while (1) {
23731da177e4SLinus Torvalds	if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
23741da177e4SLinus Torvalds	    $prototype .= $1 . $2;
23751da177e4SLinus Torvalds	    ($2 eq '{') && $brcount++;
23761da177e4SLinus Torvalds	    ($2 eq '}') && $brcount--;
23771da177e4SLinus Torvalds	    if (($2 eq ';') && ($brcount == 0)) {
23781da177e4SLinus Torvalds		dump_declaration($prototype, $file);
23791da177e4SLinus Torvalds		reset_state();
23801da177e4SLinus Torvalds		last;
23811da177e4SLinus Torvalds	    }
23821da177e4SLinus Torvalds	    $x = $3;
23831da177e4SLinus Torvalds	} else {
23841da177e4SLinus Torvalds	    $prototype .= $x;
23851da177e4SLinus Torvalds	    last;
23861da177e4SLinus Torvalds	}
23871da177e4SLinus Torvalds    }
23881da177e4SLinus Torvalds}
23891da177e4SLinus Torvalds
23906b5b55f6SRandy Dunlap# xml_escape: replace <, >, and & in the text stream;
23916b5b55f6SRandy Dunlap#
23926b5b55f6SRandy Dunlap# however, formatting controls that are generated internally/locally in the
23936b5b55f6SRandy Dunlap# kernel-doc script are not escaped here; instead, they begin life like
23946b5b55f6SRandy Dunlap# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
23956b5b55f6SRandy Dunlap# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
23966b5b55f6SRandy Dunlap# just before actual output; (this is done by local_unescape())
23971da177e4SLinus Torvaldssub xml_escape($) {
23981da177e4SLinus Torvalds	my $text = shift;
2399ecfb251aSRandy Dunlap	if (($output_mode eq "text") || ($output_mode eq "man")) {
2400ecfb251aSRandy Dunlap		return $text;
2401ecfb251aSRandy Dunlap	}
24021da177e4SLinus Torvalds	$text =~ s/\&/\\\\\\amp;/g;
24031da177e4SLinus Torvalds	$text =~ s/\</\\\\\\lt;/g;
24041da177e4SLinus Torvalds	$text =~ s/\>/\\\\\\gt;/g;
24051da177e4SLinus Torvalds	return $text;
24061da177e4SLinus Torvalds}
24071da177e4SLinus Torvalds
24086b5b55f6SRandy Dunlap# convert local escape strings to html
24096b5b55f6SRandy Dunlap# local escape strings look like:  '\\\\menmonic:' (that's 4 backslashes)
24106b5b55f6SRandy Dunlapsub local_unescape($) {
24116b5b55f6SRandy Dunlap	my $text = shift;
24126b5b55f6SRandy Dunlap	if (($output_mode eq "text") || ($output_mode eq "man")) {
24136b5b55f6SRandy Dunlap		return $text;
24146b5b55f6SRandy Dunlap	}
24156b5b55f6SRandy Dunlap	$text =~ s/\\\\\\\\lt:/</g;
24166b5b55f6SRandy Dunlap	$text =~ s/\\\\\\\\gt:/>/g;
24176b5b55f6SRandy Dunlap	return $text;
24186b5b55f6SRandy Dunlap}
24196b5b55f6SRandy Dunlap
24201da177e4SLinus Torvaldssub process_file($) {
24212283a117SRandy Dunlap    my $file;
24221da177e4SLinus Torvalds    my $identifier;
24231da177e4SLinus Torvalds    my $func;
2424a21217daSRandy Dunlap    my $descr;
24256423133bSJohannes Weiner    my $in_purpose = 0;
24261da177e4SLinus Torvalds    my $initial_section_counter = $section_counter;
242768f86662SBen Hutchings    my ($orig_file) = @_;
24281da177e4SLinus Torvalds
24292283a117SRandy Dunlap    if (defined($ENV{'SRCTREE'})) {
243068f86662SBen Hutchings	$file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
24312283a117SRandy Dunlap    }
24322283a117SRandy Dunlap    else {
243368f86662SBen Hutchings	$file = $orig_file;
24342283a117SRandy Dunlap    }
24351da177e4SLinus Torvalds    if (defined($source_map{$file})) {
24361da177e4SLinus Torvalds	$file = $source_map{$file};
24371da177e4SLinus Torvalds    }
24381da177e4SLinus Torvalds
24391da177e4SLinus Torvalds    if (!open(IN,"<$file")) {
24401da177e4SLinus Torvalds	print STDERR "Error: Cannot open file $file\n";
24411da177e4SLinus Torvalds	++$errors;
24421da177e4SLinus Torvalds	return;
24431da177e4SLinus Torvalds    }
24441da177e4SLinus Torvalds
2445a9e7314bSIlya Dryomov    $. = 1;
2446a9e7314bSIlya Dryomov
24471da177e4SLinus Torvalds    $section_counter = 0;
24481da177e4SLinus Torvalds    while (<IN>) {
244965478428SDaniel Santos	while (s/\\\s*$//) {
245065478428SDaniel Santos	    $_ .= <IN>;
245165478428SDaniel Santos	}
24521da177e4SLinus Torvalds	if ($state == 0) {
24531da177e4SLinus Torvalds	    if (/$doc_start/o) {
24541da177e4SLinus Torvalds		$state = 1;		# next line is always the function name
2455850622dfSRandy Dunlap		$in_doc_sect = 0;
24561da177e4SLinus Torvalds	    }
24571da177e4SLinus Torvalds	} elsif ($state == 1) {	# this line is the function name (always)
24581da177e4SLinus Torvalds	    if (/$doc_block/o) {
24591da177e4SLinus Torvalds		$state = 4;
24601da177e4SLinus Torvalds		$contents = "";
24611da177e4SLinus Torvalds		if ( $1 eq "" ) {
24621da177e4SLinus Torvalds			$section = $section_intro;
24631da177e4SLinus Torvalds		} else {
24641da177e4SLinus Torvalds			$section = $1;
24651da177e4SLinus Torvalds		}
24661da177e4SLinus Torvalds	    }
24671da177e4SLinus Torvalds	    elsif (/$doc_decl/o) {
24681da177e4SLinus Torvalds		$identifier = $1;
24691da177e4SLinus Torvalds		if (/\s*([\w\s]+?)\s*-/) {
24701da177e4SLinus Torvalds		    $identifier = $1;
24711da177e4SLinus Torvalds		}
24721da177e4SLinus Torvalds
24731da177e4SLinus Torvalds		$state = 2;
24741da177e4SLinus Torvalds		if (/-(.*)/) {
247551f5a0c8SRandy Dunlap		    # strip leading/trailing/multiple spaces
2476a21217daSRandy Dunlap		    $descr= $1;
2477a21217daSRandy Dunlap		    $descr =~ s/^\s*//;
2478a21217daSRandy Dunlap		    $descr =~ s/\s*$//;
247912ae6779SDaniel Santos		    $descr =~ s/\s+/ /g;
2480a21217daSRandy Dunlap		    $declaration_purpose = xml_escape($descr);
24816423133bSJohannes Weiner		    $in_purpose = 1;
24821da177e4SLinus Torvalds		} else {
24831da177e4SLinus Torvalds		    $declaration_purpose = "";
24841da177e4SLinus Torvalds		}
248577cc23b8SRandy Dunlap
248677cc23b8SRandy Dunlap		if (($declaration_purpose eq "") && $verbose) {
2487d40e1e65SBart Van Assche			print STDERR "${file}:$.: warning: missing initial short description on line:\n";
248877cc23b8SRandy Dunlap			print STDERR $_;
248977cc23b8SRandy Dunlap			++$warnings;
249077cc23b8SRandy Dunlap		}
249177cc23b8SRandy Dunlap
24921da177e4SLinus Torvalds		if ($identifier =~ m/^struct/) {
24931da177e4SLinus Torvalds		    $decl_type = 'struct';
24941da177e4SLinus Torvalds		} elsif ($identifier =~ m/^union/) {
24951da177e4SLinus Torvalds		    $decl_type = 'union';
24961da177e4SLinus Torvalds		} elsif ($identifier =~ m/^enum/) {
24971da177e4SLinus Torvalds		    $decl_type = 'enum';
24981da177e4SLinus Torvalds		} elsif ($identifier =~ m/^typedef/) {
24991da177e4SLinus Torvalds		    $decl_type = 'typedef';
25001da177e4SLinus Torvalds		} else {
25011da177e4SLinus Torvalds		    $decl_type = 'function';
25021da177e4SLinus Torvalds		}
25031da177e4SLinus Torvalds
25041da177e4SLinus Torvalds		if ($verbose) {
2505d40e1e65SBart Van Assche		    print STDERR "${file}:$.: info: Scanning doc for $identifier\n";
25061da177e4SLinus Torvalds		}
25071da177e4SLinus Torvalds	    } else {
2508d40e1e65SBart Van Assche		print STDERR "${file}:$.: warning: Cannot understand $_ on line $.",
25091da177e4SLinus Torvalds		" - I thought it was a doc line\n";
25101da177e4SLinus Torvalds		++$warnings;
25111da177e4SLinus Torvalds		$state = 0;
25121da177e4SLinus Torvalds	    }
25131da177e4SLinus Torvalds	} elsif ($state == 2) {	# look for head: lines, and include content
25141da177e4SLinus Torvalds	    if (/$doc_sect/o) {
25151da177e4SLinus Torvalds		$newsection = $1;
25161da177e4SLinus Torvalds		$newcontents = $2;
25171da177e4SLinus Torvalds
2518792aa2f2SRandy Dunlap		if (($contents ne "") && ($contents ne "\n")) {
2519850622dfSRandy Dunlap		    if (!$in_doc_sect && $verbose) {
2520d40e1e65SBart Van Assche			print STDERR "${file}:$.: warning: contents before sections\n";
2521850622dfSRandy Dunlap			++$warnings;
2522850622dfSRandy Dunlap		    }
252394dc7ad5SRandy Dunlap		    dump_section($file, $section, xml_escape($contents));
25241da177e4SLinus Torvalds		    $section = $section_default;
25251da177e4SLinus Torvalds		}
25261da177e4SLinus Torvalds
2527850622dfSRandy Dunlap		$in_doc_sect = 1;
25286423133bSJohannes Weiner		$in_purpose = 0;
25291da177e4SLinus Torvalds		$contents = $newcontents;
25301da177e4SLinus Torvalds		if ($contents ne "") {
253127205744SRandy Dunlap		    while ((substr($contents, 0, 1) eq " ") ||
253227205744SRandy Dunlap			substr($contents, 0, 1) eq "\t") {
253305189497SRandy Dunlap			    $contents = substr($contents, 1);
253405189497SRandy Dunlap		    }
25351da177e4SLinus Torvalds		    $contents .= "\n";
25361da177e4SLinus Torvalds		}
25371da177e4SLinus Torvalds		$section = $newsection;
25381da177e4SLinus Torvalds	    } elsif (/$doc_end/) {
25394c98ecafSRandy Dunlap		if (($contents ne "") && ($contents ne "\n")) {
254094dc7ad5SRandy Dunlap		    dump_section($file, $section, xml_escape($contents));
25411da177e4SLinus Torvalds		    $section = $section_default;
25421da177e4SLinus Torvalds		    $contents = "";
25431da177e4SLinus Torvalds		}
254446b958ebSRandy Dunlap		# look for doc_com + <text> + doc_end:
254546b958ebSRandy Dunlap		if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
2546d40e1e65SBart Van Assche		    print STDERR "${file}:$.: warning: suspicious ending line: $_";
254746b958ebSRandy Dunlap		    ++$warnings;
254846b958ebSRandy Dunlap		}
25491da177e4SLinus Torvalds
25501da177e4SLinus Torvalds		$prototype = "";
25511da177e4SLinus Torvalds		$state = 3;
25521da177e4SLinus Torvalds		$brcount = 0;
25531da177e4SLinus Torvalds#		print STDERR "end of doc comment, looking for prototype\n";
25541da177e4SLinus Torvalds	    } elsif (/$doc_content/) {
25551da177e4SLinus Torvalds		# miguel-style comment kludge, look for blank lines after
25561da177e4SLinus Torvalds		# @parameter line to signify start of description
25576423133bSJohannes Weiner		if ($1 eq "") {
25586423133bSJohannes Weiner		    if ($section =~ m/^@/ || $section eq $section_context) {
255994dc7ad5SRandy Dunlap			dump_section($file, $section, xml_escape($contents));
25601da177e4SLinus Torvalds			$section = $section_default;
25611da177e4SLinus Torvalds			$contents = "";
25621da177e4SLinus Torvalds		    } else {
25636423133bSJohannes Weiner			$contents .= "\n";
25646423133bSJohannes Weiner		    }
25656423133bSJohannes Weiner		    $in_purpose = 0;
25666423133bSJohannes Weiner		} elsif ($in_purpose == 1) {
25676423133bSJohannes Weiner		    # Continued declaration purpose
25686423133bSJohannes Weiner		    chomp($declaration_purpose);
25696423133bSJohannes Weiner		    $declaration_purpose .= " " . xml_escape($1);
257012ae6779SDaniel Santos		    $declaration_purpose =~ s/\s+/ /g;
25716423133bSJohannes Weiner		} else {
25721da177e4SLinus Torvalds		    $contents .= $1 . "\n";
25731da177e4SLinus Torvalds		}
25741da177e4SLinus Torvalds	    } else {
25751da177e4SLinus Torvalds		# i dont know - bad line?  ignore.
2576d40e1e65SBart Van Assche		print STDERR "${file}:$.: warning: bad line: $_";
25771da177e4SLinus Torvalds		++$warnings;
25781da177e4SLinus Torvalds	    }
2579a4c6ebedSDanilo Cesar Lemes de Paula	} elsif ($state == 5) { # scanning for split parameters
2580a4c6ebedSDanilo Cesar Lemes de Paula	    # First line (state 1) needs to be a @parameter
2581a4c6ebedSDanilo Cesar Lemes de Paula	    if ($split_doc_state == 1 && /$doc_split_sect/o) {
2582a4c6ebedSDanilo Cesar Lemes de Paula		$section = $1;
2583a4c6ebedSDanilo Cesar Lemes de Paula		$contents = $2;
2584a4c6ebedSDanilo Cesar Lemes de Paula		if ($contents ne "") {
2585a4c6ebedSDanilo Cesar Lemes de Paula		    while ((substr($contents, 0, 1) eq " ") ||
2586a4c6ebedSDanilo Cesar Lemes de Paula		           substr($contents, 0, 1) eq "\t") {
2587a4c6ebedSDanilo Cesar Lemes de Paula			$contents = substr($contents, 1);
2588a4c6ebedSDanilo Cesar Lemes de Paula		    }
2589a4c6ebedSDanilo Cesar Lemes de Paula		$contents .= "\n";
2590a4c6ebedSDanilo Cesar Lemes de Paula		}
2591a4c6ebedSDanilo Cesar Lemes de Paula		$split_doc_state = 2;
2592a4c6ebedSDanilo Cesar Lemes de Paula	    # Documentation block end */
2593a4c6ebedSDanilo Cesar Lemes de Paula	    } elsif (/$doc_split_end/) {
2594a4c6ebedSDanilo Cesar Lemes de Paula		if (($contents ne "") && ($contents ne "\n")) {
2595a4c6ebedSDanilo Cesar Lemes de Paula		    dump_section($file, $section, xml_escape($contents));
2596a4c6ebedSDanilo Cesar Lemes de Paula		    $section = $section_default;
2597a4c6ebedSDanilo Cesar Lemes de Paula		    $contents = "";
2598a4c6ebedSDanilo Cesar Lemes de Paula		}
2599a4c6ebedSDanilo Cesar Lemes de Paula		$state = 3;
2600a4c6ebedSDanilo Cesar Lemes de Paula		$split_doc_state = 0;
2601a4c6ebedSDanilo Cesar Lemes de Paula	    # Regular text
2602a4c6ebedSDanilo Cesar Lemes de Paula	    } elsif (/$doc_content/) {
2603a4c6ebedSDanilo Cesar Lemes de Paula		if ($split_doc_state == 2) {
2604a4c6ebedSDanilo Cesar Lemes de Paula		    $contents .= $1 . "\n";
2605a4c6ebedSDanilo Cesar Lemes de Paula		} elsif ($split_doc_state == 1) {
2606a4c6ebedSDanilo Cesar Lemes de Paula		    $split_doc_state = 4;
2607a4c6ebedSDanilo Cesar Lemes de Paula		    print STDERR "Warning(${file}:$.): ";
2608a4c6ebedSDanilo Cesar Lemes de Paula		    print STDERR "Incorrect use of kernel-doc format: $_";
2609a4c6ebedSDanilo Cesar Lemes de Paula		    ++$warnings;
2610a4c6ebedSDanilo Cesar Lemes de Paula		}
2611a4c6ebedSDanilo Cesar Lemes de Paula	    }
2612232acbcfSRandy Dunlap	} elsif ($state == 3) {	# scanning for function '{' (end of prototype)
2613a4c6ebedSDanilo Cesar Lemes de Paula	    if (/$doc_split_start/) {
2614a4c6ebedSDanilo Cesar Lemes de Paula		$state = 5;
2615a4c6ebedSDanilo Cesar Lemes de Paula		$split_doc_state = 1;
2616a4c6ebedSDanilo Cesar Lemes de Paula	    } elsif ($decl_type eq 'function') {
26171da177e4SLinus Torvalds		process_state3_function($_, $file);
26181da177e4SLinus Torvalds	    } else {
26191da177e4SLinus Torvalds		process_state3_type($_, $file);
26201da177e4SLinus Torvalds	    }
26211da177e4SLinus Torvalds	} elsif ($state == 4) {
26221da177e4SLinus Torvalds		# Documentation block
26231da177e4SLinus Torvalds		if (/$doc_block/) {
262494dc7ad5SRandy Dunlap			dump_doc_section($file, $section, xml_escape($contents));
26251da177e4SLinus Torvalds			$contents = "";
26261da177e4SLinus Torvalds			$function = "";
26271da177e4SLinus Torvalds			%constants = ();
26281da177e4SLinus Torvalds			%parameterdescs = ();
26291da177e4SLinus Torvalds			%parametertypes = ();
26301da177e4SLinus Torvalds			@parameterlist = ();
26311da177e4SLinus Torvalds			%sections = ();
26321da177e4SLinus Torvalds			@sectionlist = ();
26331da177e4SLinus Torvalds			$prototype = "";
26341da177e4SLinus Torvalds			if ( $1 eq "" ) {
26351da177e4SLinus Torvalds				$section = $section_intro;
26361da177e4SLinus Torvalds			} else {
26371da177e4SLinus Torvalds				$section = $1;
26381da177e4SLinus Torvalds			}
26391da177e4SLinus Torvalds		}
26401da177e4SLinus Torvalds		elsif (/$doc_end/)
26411da177e4SLinus Torvalds		{
264294dc7ad5SRandy Dunlap			dump_doc_section($file, $section, xml_escape($contents));
26431da177e4SLinus Torvalds			$contents = "";
26441da177e4SLinus Torvalds			$function = "";
26451da177e4SLinus Torvalds			%constants = ();
26461da177e4SLinus Torvalds			%parameterdescs = ();
26471da177e4SLinus Torvalds			%parametertypes = ();
26481da177e4SLinus Torvalds			@parameterlist = ();
26491da177e4SLinus Torvalds			%sections = ();
26501da177e4SLinus Torvalds			@sectionlist = ();
26511da177e4SLinus Torvalds			$prototype = "";
26521da177e4SLinus Torvalds			$state = 0;
26531da177e4SLinus Torvalds		}
26541da177e4SLinus Torvalds		elsif (/$doc_content/)
26551da177e4SLinus Torvalds		{
26561da177e4SLinus Torvalds			if ( $1 eq "" )
26571da177e4SLinus Torvalds			{
26581da177e4SLinus Torvalds				$contents .= $blankline;
26591da177e4SLinus Torvalds			}
26601da177e4SLinus Torvalds			else
26611da177e4SLinus Torvalds			{
26621da177e4SLinus Torvalds				$contents .= $1 . "\n";
26631da177e4SLinus Torvalds			}
26641da177e4SLinus Torvalds		}
26651da177e4SLinus Torvalds	}
26661da177e4SLinus Torvalds    }
26671da177e4SLinus Torvalds    if ($initial_section_counter == $section_counter) {
2668d40e1e65SBart Van Assche	print STDERR "${file}:1: warning: no structured comments found\n";
2669e946c43aSJohannes Berg	if (($function_only == 1) && ($show_not_found == 1)) {
2670e946c43aSJohannes Berg	    print STDERR "    Was looking for '$_'.\n" for keys %function_table;
2671e946c43aSJohannes Berg	}
26721da177e4SLinus Torvalds	if ($output_mode eq "xml") {
26731da177e4SLinus Torvalds	    # The template wants at least one RefEntry here; make one.
26741da177e4SLinus Torvalds	    print "<refentry>\n";
26751da177e4SLinus Torvalds	    print " <refnamediv>\n";
26761da177e4SLinus Torvalds	    print "  <refname>\n";
267768f86662SBen Hutchings	    print "   ${orig_file}\n";
26781da177e4SLinus Torvalds	    print "  </refname>\n";
26791da177e4SLinus Torvalds	    print "  <refpurpose>\n";
26801da177e4SLinus Torvalds	    print "   Document generation inconsistency\n";
26811da177e4SLinus Torvalds	    print "  </refpurpose>\n";
26821da177e4SLinus Torvalds	    print " </refnamediv>\n";
26831da177e4SLinus Torvalds	    print " <refsect1>\n";
26841da177e4SLinus Torvalds	    print "  <title>\n";
26851da177e4SLinus Torvalds	    print "   Oops\n";
26861da177e4SLinus Torvalds	    print "  </title>\n";
26871da177e4SLinus Torvalds	    print "  <warning>\n";
26881da177e4SLinus Torvalds	    print "   <para>\n";
26891da177e4SLinus Torvalds	    print "    The template for this document tried to insert\n";
26901da177e4SLinus Torvalds	    print "    the structured comment from the file\n";
269168f86662SBen Hutchings	    print "    <filename>${orig_file}</filename> at this point,\n";
26921da177e4SLinus Torvalds	    print "    but none was found.\n";
26931da177e4SLinus Torvalds	    print "    This dummy section is inserted to allow\n";
26941da177e4SLinus Torvalds	    print "    generation to continue.\n";
26951da177e4SLinus Torvalds	    print "   </para>\n";
26961da177e4SLinus Torvalds	    print "  </warning>\n";
26971da177e4SLinus Torvalds	    print " </refsect1>\n";
26981da177e4SLinus Torvalds	    print "</refentry>\n";
26991da177e4SLinus Torvalds	}
27001da177e4SLinus Torvalds    }
27011da177e4SLinus Torvalds}
27028484baaaSRandy Dunlap
27038484baaaSRandy Dunlap
27048484baaaSRandy Dunlap$kernelversion = get_kernel_version();
27058484baaaSRandy Dunlap
27068484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information
27078484baaaSRandy Dunlap# using the s// operator.
27081ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) {
27094d732701SDanilo Cesar Lemes de Paula    my $pattern = $highlights[$k][0];
27104d732701SDanilo Cesar Lemes de Paula    my $result = $highlights[$k][1];
27114d732701SDanilo Cesar Lemes de Paula#   print STDERR "scanning pattern:$pattern, highlight:($result)\n";
27124d732701SDanilo Cesar Lemes de Paula    $dohighlight .=  "\$contents =~ s:$pattern:$result:gs;\n";
27138484baaaSRandy Dunlap}
27148484baaaSRandy Dunlap
27158484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for
27168484baaaSRandy Dunlap# separate source and object directories and for shadow trees.
27178484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
27188484baaaSRandy Dunlap	my ($relname, $absname);
27198484baaaSRandy Dunlap	while(<SOURCE_MAP>) {
27208484baaaSRandy Dunlap		chop();
27218484baaaSRandy Dunlap		($relname, $absname) = (split())[0..1];
27228484baaaSRandy Dunlap		$relname =~ s:^/+::;
27238484baaaSRandy Dunlap		$source_map{$relname} = $absname;
27248484baaaSRandy Dunlap	}
27258484baaaSRandy Dunlap	close(SOURCE_MAP);
27268484baaaSRandy Dunlap}
27278484baaaSRandy Dunlap
27288484baaaSRandy Dunlapforeach (@ARGV) {
27298484baaaSRandy Dunlap    chomp;
27308484baaaSRandy Dunlap    process_file($_);
27318484baaaSRandy Dunlap}
27328484baaaSRandy Dunlapif ($verbose && $errors) {
27338484baaaSRandy Dunlap  print STDERR "$errors errors\n";
27348484baaaSRandy Dunlap}
27358484baaaSRandy Dunlapif ($verbose && $warnings) {
27368484baaaSRandy Dunlap  print STDERR "$warnings warnings\n";
27378484baaaSRandy Dunlap}
27388484baaaSRandy Dunlap
27398484baaaSRandy Dunlapexit($errors);
2740