xref: /linux/scripts/kernel-doc (revision 1b40c1944db445c1de1c47ffd8cd426167f488e8)
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                         ##
9*1b40c194SDan 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
39*1b40c194SDan Luedtke# 25/07/2012 - Added support for HTML5
40*1b40c194SDan Luedtke# -- Dan Luedtke <mail@danrl.de>
411da177e4SLinus Torvalds
421da177e4SLinus Torvalds#
431da177e4SLinus Torvalds# This will read a 'c' file and scan for embedded comments in the
441da177e4SLinus Torvalds# style of gnome comments (+minor extensions - see below).
451da177e4SLinus Torvalds#
461da177e4SLinus Torvalds
471da177e4SLinus Torvalds# Note: This only supports 'c'.
481da177e4SLinus Torvalds
491da177e4SLinus Torvalds# usage:
50*1b40c194SDan Luedtke# kernel-doc [ -docbook | -html | -html5 | -text | -man | -list ]
51*1b40c194SDan Luedtke#            [ -no-doc-sections ]
52*1b40c194SDan Luedtke#            [ -function funcname [ -function funcname ...] ]
53*1b40c194SDan Luedtke#            c file(s)s > outputfile
541da177e4SLinus Torvalds# or
55*1b40c194SDan Luedtke#            [ -nofunction funcname [ -function funcname ...] ]
56*1b40c194SDan Luedtke#            c file(s)s > outputfile
571da177e4SLinus Torvalds#
58*1b40c194SDan Luedtke#  Set output format using one of -docbook -html -html5 -text or -man.
59*1b40c194SDan Luedtke#  Default is man.
60eda603f6SJohannes Berg#  The -list format is for internal use by docproc.
611da177e4SLinus Torvalds#
624b44595aSJohannes Berg#  -no-doc-sections
634b44595aSJohannes Berg#	Do not output DOC: sections
644b44595aSJohannes Berg#
651da177e4SLinus Torvalds#  -function funcname
66b112e0f7SJohannes Berg#	If set, then only generate documentation for the given function(s) or
67b112e0f7SJohannes Berg#	DOC: section titles.  All other functions and DOC: sections are ignored.
681da177e4SLinus Torvalds#
691da177e4SLinus Torvalds#  -nofunction funcname
70b112e0f7SJohannes Berg#	If set, then only generate documentation for the other function(s)/DOC:
71b112e0f7SJohannes Berg#	sections. Cannot be used together with -function (yes, that's a bug --
72b112e0f7SJohannes Berg#	perl hackers can fix it 8))
731da177e4SLinus Torvalds#
741da177e4SLinus Torvalds#  c files - list of 'c' files to process
751da177e4SLinus Torvalds#
761da177e4SLinus Torvalds#  All output goes to stdout, with errors to stderr.
771da177e4SLinus Torvalds
781da177e4SLinus Torvalds#
791da177e4SLinus Torvalds# format of comments.
801da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure.
811da177e4SLinus Torvalds#                         (...)* signifies 0 or more structure elements
821da177e4SLinus Torvalds# /**
831da177e4SLinus Torvalds#  * function_name(:)? (- short description)?
841da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)*
851da177e4SLinus Torvalds# (* a blank line)?
861da177e4SLinus Torvalds#  * (Description:)? (Description of function)?
871da177e4SLinus Torvalds#  * (section header: (section description)? )*
881da177e4SLinus Torvalds#  (*)?*/
891da177e4SLinus Torvalds#
901da177e4SLinus Torvalds# So .. the trivial example would be:
911da177e4SLinus Torvalds#
921da177e4SLinus Torvalds# /**
931da177e4SLinus Torvalds#  * my_function
94b9d97328SRandy Dunlap#  */
951da177e4SLinus Torvalds#
96891dcd2fSRandy Dunlap# If the Description: header tag is omitted, then there must be a blank line
971da177e4SLinus Torvalds# after the last parameter specification.
981da177e4SLinus Torvalds# e.g.
991da177e4SLinus Torvalds# /**
1001da177e4SLinus Torvalds#  * my_function - does my stuff
1011da177e4SLinus Torvalds#  * @my_arg: its mine damnit
1021da177e4SLinus Torvalds#  *
1031da177e4SLinus Torvalds#  * Does my stuff explained.
1041da177e4SLinus Torvalds#  */
1051da177e4SLinus Torvalds#
1061da177e4SLinus Torvalds#  or, could also use:
1071da177e4SLinus Torvalds# /**
1081da177e4SLinus Torvalds#  * my_function - does my stuff
1091da177e4SLinus Torvalds#  * @my_arg: its mine damnit
1101da177e4SLinus Torvalds#  * Description: Does my stuff explained.
1111da177e4SLinus Torvalds#  */
1121da177e4SLinus Torvalds# etc.
1131da177e4SLinus Torvalds#
114b9d97328SRandy Dunlap# Besides functions you can also write documentation for structs, unions,
1151da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name
1161da177e4SLinus Torvalds# of the declaration;  the struct/union/enum/typedef must always precede
1171da177e4SLinus Torvalds# the name. Nesting of declarations is not supported.
1181da177e4SLinus Torvalds# Use the argument mechanism to document members or constants.
1191da177e4SLinus Torvalds# e.g.
1201da177e4SLinus Torvalds# /**
1211da177e4SLinus Torvalds#  * struct my_struct - short description
1221da177e4SLinus Torvalds#  * @a: first member
1231da177e4SLinus Torvalds#  * @b: second member
1241da177e4SLinus Torvalds#  *
1251da177e4SLinus Torvalds#  * Longer description
1261da177e4SLinus Torvalds#  */
1271da177e4SLinus Torvalds# struct my_struct {
1281da177e4SLinus Torvalds#     int a;
1291da177e4SLinus Torvalds#     int b;
130aeec46b9SMartin Waitz# /* private: */
131aeec46b9SMartin Waitz#     int c;
1321da177e4SLinus Torvalds# };
1331da177e4SLinus Torvalds#
1341da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description.
1351da177e4SLinus Torvalds#
1361da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you
1371da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions
1381da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an
1391da177e4SLinus Torvalds# empty line.
1401da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked
1411da177e4SLinus Torvalds# appropriately in DocBook.
1421da177e4SLinus Torvalds#
1431da177e4SLinus Torvalds# Example:
1441da177e4SLinus Torvalds# /**
1451da177e4SLinus Torvalds#  * user_function - function that can only be called in user context
1461da177e4SLinus Torvalds#  * @a: some argument
1471da177e4SLinus Torvalds#  * Context: !in_interrupt()
1481da177e4SLinus Torvalds#  *
1491da177e4SLinus Torvalds#  * Some description
1501da177e4SLinus Torvalds#  * Example:
1511da177e4SLinus Torvalds#  *    user_function(22);
1521da177e4SLinus Torvalds#  */
1531da177e4SLinus Torvalds# ...
1541da177e4SLinus Torvalds#
1551da177e4SLinus Torvalds#
1561da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special
1571da177e4SLinus Torvalds# patterns, which are highlighted appropriately.
1581da177e4SLinus Torvalds#
1591da177e4SLinus Torvalds# 'funcname()' - function
1601da177e4SLinus Torvalds# '$ENVVAR' - environmental variable
1611da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct')
1621da177e4SLinus Torvalds# '@parameter' - name of a parameter
1631da177e4SLinus Torvalds# '%CONST' - name of a constant.
1641da177e4SLinus Torvalds
1658484baaaSRandy Dunlap## init lots of data
1668484baaaSRandy Dunlap
1671da177e4SLinus Torvaldsmy $errors = 0;
1681da177e4SLinus Torvaldsmy $warnings = 0;
1695f8c7c98SRandy Dunlapmy $anon_struct_union = 0;
1701da177e4SLinus Torvalds
1711da177e4SLinus Torvalds# match expressions used to find embedded type information
1721da177e4SLinus Torvaldsmy $type_constant = '\%([-_\w]+)';
1731da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)';
1741da177e4SLinus Torvaldsmy $type_param = '\@(\w+)';
1753eb014a1SRandy Dunlapmy $type_struct = '\&((struct\s*)*[_\w]+)';
1766b5b55f6SRandy Dunlapmy $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
1771da177e4SLinus Torvaldsmy $type_env = '(\$\w+)';
1781da177e4SLinus Torvalds
1791da177e4SLinus Torvalds# Output conversion substitutions.
1801da177e4SLinus Torvalds#  One for each output format
1811da177e4SLinus Torvalds
1821da177e4SLinus Torvalds# these work fairly well
1831da177e4SLinus Torvaldsmy %highlights_html = ( $type_constant, "<i>\$1</i>",
1841da177e4SLinus Torvalds			$type_func, "<b>\$1</b>",
1853eb014a1SRandy Dunlap			$type_struct_xml, "<i>\$1</i>",
1863eb014a1SRandy Dunlap			$type_env, "<b><i>\$1</i></b>",
1871da177e4SLinus Torvalds			$type_param, "<tt><b>\$1</b></tt>" );
1886b5b55f6SRandy Dunlapmy $local_lt = "\\\\\\\\lt:";
1896b5b55f6SRandy Dunlapmy $local_gt = "\\\\\\\\gt:";
1906b5b55f6SRandy Dunlapmy $blankline_html = $local_lt . "p" . $local_gt;	# was "<p>"
1911da177e4SLinus Torvalds
192*1b40c194SDan Luedtke# html version 5
193*1b40c194SDan Luedtkemy %highlights_html5 = ( $type_constant, "<span class=\"const\">\$1</span>",
194*1b40c194SDan Luedtke			$type_func, "<span class=\"func\">\$1</span>",
195*1b40c194SDan Luedtke			$type_struct_xml, "<span class=\"struct\">\$1</span>",
196*1b40c194SDan Luedtke			$type_env, "<span class=\"env\">\$1</span>",
197*1b40c194SDan Luedtke			$type_param, "<span class=\"param\">\$1</span>" );
198*1b40c194SDan Luedtkemy $blankline_html5 = $local_lt . "br /" . $local_gt;
199*1b40c194SDan Luedtke
2001da177e4SLinus Torvalds# XML, docbook format
2011da177e4SLinus Torvaldsmy %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
2021da177e4SLinus Torvalds			$type_constant, "<constant>\$1</constant>",
2031da177e4SLinus Torvalds			$type_func, "<function>\$1</function>",
2045c98fc03SJohannes Berg			$type_struct_xml, "<structname>\$1</structname>",
2051da177e4SLinus Torvalds			$type_env, "<envar>\$1</envar>",
2061da177e4SLinus Torvalds			$type_param, "<parameter>\$1</parameter>" );
2075c98fc03SJohannes Bergmy $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
2081da177e4SLinus Torvalds
2091da177e4SLinus Torvalds# gnome, docbook format
2101da177e4SLinus Torvaldsmy %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
2111da177e4SLinus Torvalds			 $type_func, "<function>\$1</function>",
2121da177e4SLinus Torvalds			 $type_struct, "<structname>\$1</structname>",
2131da177e4SLinus Torvalds			 $type_env, "<envar>\$1</envar>",
2141da177e4SLinus Torvalds			 $type_param, "<parameter>\$1</parameter>" );
2151da177e4SLinus Torvaldsmy $blankline_gnome = "</para><para>\n";
2161da177e4SLinus Torvalds
2171da177e4SLinus Torvalds# these are pretty rough
2181da177e4SLinus Torvaldsmy %highlights_man = ( $type_constant, "\$1",
2191da177e4SLinus Torvalds		       $type_func, "\\\\fB\$1\\\\fP",
2201da177e4SLinus Torvalds		       $type_struct, "\\\\fI\$1\\\\fP",
2211da177e4SLinus Torvalds		       $type_param, "\\\\fI\$1\\\\fP" );
2221da177e4SLinus Torvaldsmy $blankline_man = "";
2231da177e4SLinus Torvalds
2241da177e4SLinus Torvalds# text-mode
2251da177e4SLinus Torvaldsmy %highlights_text = ( $type_constant, "\$1",
2261da177e4SLinus Torvalds			$type_func, "\$1",
2271da177e4SLinus Torvalds			$type_struct, "\$1",
2281da177e4SLinus Torvalds			$type_param, "\$1" );
2291da177e4SLinus Torvaldsmy $blankline_text = "";
2301da177e4SLinus Torvalds
231eda603f6SJohannes Berg# list mode
232eda603f6SJohannes Bergmy %highlights_list = ( $type_constant, "\$1",
233eda603f6SJohannes Berg			$type_func, "\$1",
234eda603f6SJohannes Berg			$type_struct, "\$1",
235eda603f6SJohannes Berg			$type_param, "\$1" );
236eda603f6SJohannes Bergmy $blankline_list = "";
2371da177e4SLinus Torvalds
2381da177e4SLinus Torvalds# read arguments
2391da177e4SLinus Torvaldsif ($#ARGV == -1) {
2401da177e4SLinus Torvalds    usage();
2411da177e4SLinus Torvalds}
2421da177e4SLinus Torvalds
2438484baaaSRandy Dunlapmy $kernelversion;
2448484baaaSRandy Dunlapmy $dohighlight = "";
2458484baaaSRandy Dunlap
2461da177e4SLinus Torvaldsmy $verbose = 0;
2471da177e4SLinus Torvaldsmy $output_mode = "man";
2484b44595aSJohannes Bergmy $no_doc_sections = 0;
2491da177e4SLinus Torvaldsmy %highlights = %highlights_man;
2501da177e4SLinus Torvaldsmy $blankline = $blankline_man;
2511da177e4SLinus Torvaldsmy $modulename = "Kernel API";
2521da177e4SLinus Torvaldsmy $function_only = 0;
2531da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
2541da177e4SLinus Torvalds		'July', 'August', 'September', 'October',
2551da177e4SLinus Torvalds		'November', 'December')[(localtime)[4]] .
2561da177e4SLinus Torvalds  " " . ((localtime)[5]+1900);
2571da177e4SLinus Torvalds
2588484baaaSRandy Dunlap# Essentially these are globals.
259b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something.
260b9d97328SRandy Dunlap# CAVEAT EMPTOR!  Some of the others I localised may not want to be, which
2611da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs.
2621da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose);
2631da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type);
2641c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map);
2651da177e4SLinus Torvalds
266bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) {
267bd0e88e5SRandy Dunlap	$verbose = "$ENV{'KBUILD_VERBOSE'}";
268bd0e88e5SRandy Dunlap}
269bd0e88e5SRandy Dunlap
2701da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where
2711da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
2721da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
2731da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy
2741da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed
2751da177e4SLinus Torvalds# into html.
2761da177e4SLinus Torvaldsmy $section_counter = 0;
2771da177e4SLinus Torvalds
2781da177e4SLinus Torvaldsmy $lineprefix="";
2791da177e4SLinus Torvalds
2801da177e4SLinus Torvalds# states
2811da177e4SLinus Torvalds# 0 - normal code
2821da177e4SLinus Torvalds# 1 - looking for function name
2831da177e4SLinus Torvalds# 2 - scanning field start.
2841da177e4SLinus Torvalds# 3 - scanning prototype.
2851da177e4SLinus Torvalds# 4 - documentation block
2861da177e4SLinus Torvaldsmy $state;
287850622dfSRandy Dunlapmy $in_doc_sect;
2881da177e4SLinus Torvalds
2891da177e4SLinus Torvalds#declaration types: can be
2901da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef'
2911da177e4SLinus Torvaldsmy $decl_type;
2921da177e4SLinus Torvalds
2931da177e4SLinus Torvaldsmy $doc_special = "\@\%\$\&";
2941da177e4SLinus Torvalds
2951da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
2961da177e4SLinus Torvaldsmy $doc_end = '\*/';
2971da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*';
2981da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)';
299891dcd2fSRandy Dunlapmy $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)';
3001da177e4SLinus Torvaldsmy $doc_content = $doc_com . '(.*)';
3011da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?';
3021da177e4SLinus Torvalds
3031da177e4SLinus Torvaldsmy %constants;
3041da177e4SLinus Torvaldsmy %parameterdescs;
3051da177e4SLinus Torvaldsmy @parameterlist;
3061da177e4SLinus Torvaldsmy %sections;
3071da177e4SLinus Torvaldsmy @sectionlist;
308a1d94aa5SRandy Dunlapmy $sectcheck;
309a1d94aa5SRandy Dunlapmy $struct_actual;
3101da177e4SLinus Torvalds
3111da177e4SLinus Torvaldsmy $contents = "";
3121da177e4SLinus Torvaldsmy $section_default = "Description";	# default section
3131da177e4SLinus Torvaldsmy $section_intro = "Introduction";
3141da177e4SLinus Torvaldsmy $section = $section_default;
3151da177e4SLinus Torvaldsmy $section_context = "Context";
3161da177e4SLinus Torvalds
3171da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --";
3181da177e4SLinus Torvalds
3191da177e4SLinus Torvaldsreset_state();
3201da177e4SLinus Torvalds
3211da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) {
3221da177e4SLinus Torvalds    my $cmd = shift @ARGV;
3231da177e4SLinus Torvalds    if ($cmd eq "-html") {
3241da177e4SLinus Torvalds	$output_mode = "html";
3251da177e4SLinus Torvalds	%highlights = %highlights_html;
3261da177e4SLinus Torvalds	$blankline = $blankline_html;
327*1b40c194SDan Luedtke    } elsif ($cmd eq "-html5") {
328*1b40c194SDan Luedtke	$output_mode = "html5";
329*1b40c194SDan Luedtke	%highlights = %highlights_html5;
330*1b40c194SDan Luedtke	$blankline = $blankline_html5;
3311da177e4SLinus Torvalds    } elsif ($cmd eq "-man") {
3321da177e4SLinus Torvalds	$output_mode = "man";
3331da177e4SLinus Torvalds	%highlights = %highlights_man;
3341da177e4SLinus Torvalds	$blankline = $blankline_man;
3351da177e4SLinus Torvalds    } elsif ($cmd eq "-text") {
3361da177e4SLinus Torvalds	$output_mode = "text";
3371da177e4SLinus Torvalds	%highlights = %highlights_text;
3381da177e4SLinus Torvalds	$blankline = $blankline_text;
3391da177e4SLinus Torvalds    } elsif ($cmd eq "-docbook") {
3401da177e4SLinus Torvalds	$output_mode = "xml";
3411da177e4SLinus Torvalds	%highlights = %highlights_xml;
3421da177e4SLinus Torvalds	$blankline = $blankline_xml;
343eda603f6SJohannes Berg    } elsif ($cmd eq "-list") {
344eda603f6SJohannes Berg	$output_mode = "list";
345eda603f6SJohannes Berg	%highlights = %highlights_list;
346eda603f6SJohannes Berg	$blankline = $blankline_list;
3471da177e4SLinus Torvalds    } elsif ($cmd eq "-gnome") {
3481da177e4SLinus Torvalds	$output_mode = "gnome";
3491da177e4SLinus Torvalds	%highlights = %highlights_gnome;
3501da177e4SLinus Torvalds	$blankline = $blankline_gnome;
3511da177e4SLinus Torvalds    } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
3521da177e4SLinus Torvalds	$modulename = shift @ARGV;
3531da177e4SLinus Torvalds    } elsif ($cmd eq "-function") { # to only output specific functions
3541da177e4SLinus Torvalds	$function_only = 1;
3551da177e4SLinus Torvalds	$function = shift @ARGV;
3561da177e4SLinus Torvalds	$function_table{$function} = 1;
3571da177e4SLinus Torvalds    } elsif ($cmd eq "-nofunction") { # to only output specific functions
3581da177e4SLinus Torvalds	$function_only = 2;
3591da177e4SLinus Torvalds	$function = shift @ARGV;
3601da177e4SLinus Torvalds	$function_table{$function} = 1;
3611da177e4SLinus Torvalds    } elsif ($cmd eq "-v") {
3621da177e4SLinus Torvalds	$verbose = 1;
3631da177e4SLinus Torvalds    } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
3641da177e4SLinus Torvalds	usage();
3654b44595aSJohannes Berg    } elsif ($cmd eq '-no-doc-sections') {
3664b44595aSJohannes Berg	    $no_doc_sections = 1;
3671da177e4SLinus Torvalds    }
3681da177e4SLinus Torvalds}
3691da177e4SLinus Torvalds
3708484baaaSRandy Dunlap# continue execution near EOF;
3718484baaaSRandy Dunlap
3728484baaaSRandy Dunlapsub usage {
373*1b40c194SDan Luedtke    print "Usage: $0 [ -docbook | -html | -html5 | -text | -man | -list ]\n";
3748484baaaSRandy Dunlap    print "         [ -no-doc-sections ]\n";
3758484baaaSRandy Dunlap    print "         [ -function funcname [ -function funcname ...] ]\n";
3768484baaaSRandy Dunlap    print "         [ -nofunction funcname [ -nofunction funcname ...] ]\n";
377*1b40c194SDan Luedtke    print "         [ -v ]\n";
3788484baaaSRandy Dunlap    print "         c source file(s) > outputfile\n";
3798484baaaSRandy Dunlap    print "         -v : verbose output, more warnings & other info listed\n";
3808484baaaSRandy Dunlap    exit 1;
3818484baaaSRandy Dunlap}
3828484baaaSRandy Dunlap
38353f049faSBorislav Petkov# get kernel version from env
38453f049faSBorislav Petkovsub get_kernel_version() {
3851b9bc22dSJohannes Berg    my $version = 'unknown kernel version';
38653f049faSBorislav Petkov
38753f049faSBorislav Petkov    if (defined($ENV{'KERNELVERSION'})) {
38853f049faSBorislav Petkov	$version = $ENV{'KERNELVERSION'};
38953f049faSBorislav Petkov    }
39053f049faSBorislav Petkov    return $version;
39153f049faSBorislav Petkov}
3921da177e4SLinus Torvalds
3931da177e4SLinus Torvalds##
3941da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose.
3951da177e4SLinus Torvalds#
3961da177e4SLinus Torvaldssub dump_section {
39794dc7ad5SRandy Dunlap    my $file = shift;
3981da177e4SLinus Torvalds    my $name = shift;
3991da177e4SLinus Torvalds    my $contents = join "\n", @_;
4001da177e4SLinus Torvalds
4011da177e4SLinus Torvalds    if ($name =~ m/$type_constant/) {
4021da177e4SLinus Torvalds	$name = $1;
4031da177e4SLinus Torvalds#	print STDERR "constant section '$1' = '$contents'\n";
4041da177e4SLinus Torvalds	$constants{$name} = $contents;
4051da177e4SLinus Torvalds    } elsif ($name =~ m/$type_param/) {
4061da177e4SLinus Torvalds#	print STDERR "parameter def '$1' = '$contents'\n";
4071da177e4SLinus Torvalds	$name = $1;
4081da177e4SLinus Torvalds	$parameterdescs{$name} = $contents;
409a1d94aa5SRandy Dunlap	$sectcheck = $sectcheck . $name . " ";
410ced69090SRandy Dunlap    } elsif ($name eq "@\.\.\.") {
411ced69090SRandy Dunlap#	print STDERR "parameter def '...' = '$contents'\n";
412ced69090SRandy Dunlap	$name = "...";
413ced69090SRandy Dunlap	$parameterdescs{$name} = $contents;
414a1d94aa5SRandy Dunlap	$sectcheck = $sectcheck . $name . " ";
4151da177e4SLinus Torvalds    } else {
4161da177e4SLinus Torvalds#	print STDERR "other section '$name' = '$contents'\n";
41794dc7ad5SRandy Dunlap	if (defined($sections{$name}) && ($sections{$name} ne "")) {
41894dc7ad5SRandy Dunlap		print STDERR "Error(${file}:$.): duplicate section name '$name'\n";
41994dc7ad5SRandy Dunlap		++$errors;
42094dc7ad5SRandy Dunlap	}
4211da177e4SLinus Torvalds	$sections{$name} = $contents;
4221da177e4SLinus Torvalds	push @sectionlist, $name;
4231da177e4SLinus Torvalds    }
4241da177e4SLinus Torvalds}
4251da177e4SLinus Torvalds
4261da177e4SLinus Torvalds##
427b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out
428b112e0f7SJohannes Berg#
429b112e0f7SJohannes Bergsub dump_doc_section {
43094dc7ad5SRandy Dunlap    my $file = shift;
431b112e0f7SJohannes Berg    my $name = shift;
432b112e0f7SJohannes Berg    my $contents = join "\n", @_;
433b112e0f7SJohannes Berg
4344b44595aSJohannes Berg    if ($no_doc_sections) {
4354b44595aSJohannes Berg        return;
4364b44595aSJohannes Berg    }
4374b44595aSJohannes Berg
438b112e0f7SJohannes Berg    if (($function_only == 0) ||
439b112e0f7SJohannes Berg	( $function_only == 1 && defined($function_table{$name})) ||
440b112e0f7SJohannes Berg	( $function_only == 2 && !defined($function_table{$name})))
441b112e0f7SJohannes Berg    {
44294dc7ad5SRandy Dunlap	dump_section($file, $name, $contents);
443b112e0f7SJohannes Berg	output_blockhead({'sectionlist' => \@sectionlist,
444b112e0f7SJohannes Berg			  'sections' => \%sections,
445b112e0f7SJohannes Berg			  'module' => $modulename,
446b112e0f7SJohannes Berg			  'content-only' => ($function_only != 0), });
447b112e0f7SJohannes Berg    }
448b112e0f7SJohannes Berg}
449b112e0f7SJohannes Berg
450b112e0f7SJohannes Berg##
4511da177e4SLinus Torvalds# output function
4521da177e4SLinus Torvalds#
4531da177e4SLinus Torvalds# parameterdescs, a hash.
4541da177e4SLinus Torvalds#  function => "function name"
4551da177e4SLinus Torvalds#  parameterlist => @list of parameters
4561da177e4SLinus Torvalds#  parameterdescs => %parameter descriptions
4571da177e4SLinus Torvalds#  sectionlist => @list of sections
458a21217daSRandy Dunlap#  sections => %section descriptions
4591da177e4SLinus Torvalds#
4601da177e4SLinus Torvalds
4611da177e4SLinus Torvaldssub output_highlight {
4621da177e4SLinus Torvalds    my $contents = join "\n",@_;
4631da177e4SLinus Torvalds    my $line;
4641da177e4SLinus Torvalds
4651da177e4SLinus Torvalds#   DEBUG
4661da177e4SLinus Torvalds#   if (!defined $contents) {
4671da177e4SLinus Torvalds#	use Carp;
4681da177e4SLinus Torvalds#	confess "output_highlight got called with no args?\n";
4691da177e4SLinus Torvalds#   }
4701da177e4SLinus Torvalds
471*1b40c194SDan Luedtke    if ($output_mode eq "html" || $output_mode eq "html5" ||
472*1b40c194SDan Luedtke	$output_mode eq "xml") {
4736b5b55f6SRandy Dunlap	$contents = local_unescape($contents);
4746b5b55f6SRandy Dunlap	# convert data read & converted thru xml_escape() into &xyz; format:
4752b35f4d9SRandy Dunlap	$contents =~ s/\\\\\\/\&/g;
4766b5b55f6SRandy Dunlap    }
4773eb014a1SRandy Dunlap#   print STDERR "contents b4:$contents\n";
4781da177e4SLinus Torvalds    eval $dohighlight;
4791da177e4SLinus Torvalds    die $@ if $@;
4803eb014a1SRandy Dunlap#   print STDERR "contents af:$contents\n";
4813eb014a1SRandy Dunlap
482*1b40c194SDan Luedtke#   strip whitespaces when generating html5
483*1b40c194SDan Luedtke    if ($output_mode eq "html5") {
484*1b40c194SDan Luedtke	$contents =~ s/^\s+//;
485*1b40c194SDan Luedtke	$contents =~ s/\s+$//;
486*1b40c194SDan Luedtke    }
4871da177e4SLinus Torvalds    foreach $line (split "\n", $contents) {
4881da177e4SLinus Torvalds	if ($line eq ""){
4896b5b55f6SRandy Dunlap	    print $lineprefix, local_unescape($blankline);
4901da177e4SLinus Torvalds	} else {
4911da177e4SLinus Torvalds	    $line =~ s/\\\\\\/\&/g;
492cdccb316SRandy Dunlap	    if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
493cdccb316SRandy Dunlap		print "\\&$line";
494cdccb316SRandy Dunlap	    } else {
4951da177e4SLinus Torvalds		print $lineprefix, $line;
4961da177e4SLinus Torvalds	    }
497cdccb316SRandy Dunlap	}
4981da177e4SLinus Torvalds	print "\n";
4991da177e4SLinus Torvalds    }
5001da177e4SLinus Torvalds}
5011da177e4SLinus Torvalds
5021da177e4SLinus Torvalds# output sections in html
5031da177e4SLinus Torvaldssub output_section_html(%) {
5041da177e4SLinus Torvalds    my %args = %{$_[0]};
5051da177e4SLinus Torvalds    my $section;
5061da177e4SLinus Torvalds
5071da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
5081da177e4SLinus Torvalds	print "<h3>$section</h3>\n";
5091da177e4SLinus Torvalds	print "<blockquote>\n";
5101da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
5111da177e4SLinus Torvalds	print "</blockquote>\n";
5121da177e4SLinus Torvalds    }
5131da177e4SLinus Torvalds}
5141da177e4SLinus Torvalds
5151da177e4SLinus Torvalds# output enum in html
5161da177e4SLinus Torvaldssub output_enum_html(%) {
5171da177e4SLinus Torvalds    my %args = %{$_[0]};
5181da177e4SLinus Torvalds    my ($parameter);
5191da177e4SLinus Torvalds    my $count;
5201da177e4SLinus Torvalds    print "<h2>enum " . $args{'enum'} . "</h2>\n";
5211da177e4SLinus Torvalds
5221da177e4SLinus Torvalds    print "<b>enum " . $args{'enum'} . "</b> {<br>\n";
5231da177e4SLinus Torvalds    $count = 0;
5241da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
5251da177e4SLinus Torvalds	print " <b>" . $parameter . "</b>";
5261da177e4SLinus Torvalds	if ($count != $#{$args{'parameterlist'}}) {
5271da177e4SLinus Torvalds	    $count++;
5281da177e4SLinus Torvalds	    print ",\n";
5291da177e4SLinus Torvalds	}
5301da177e4SLinus Torvalds	print "<br>";
5311da177e4SLinus Torvalds    }
5321da177e4SLinus Torvalds    print "};<br>\n";
5331da177e4SLinus Torvalds
5341da177e4SLinus Torvalds    print "<h3>Constants</h3>\n";
5351da177e4SLinus Torvalds    print "<dl>\n";
5361da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
5371da177e4SLinus Torvalds	print "<dt><b>" . $parameter . "</b>\n";
5381da177e4SLinus Torvalds	print "<dd>";
5391da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter});
5401da177e4SLinus Torvalds    }
5411da177e4SLinus Torvalds    print "</dl>\n";
5421da177e4SLinus Torvalds    output_section_html(@_);
5431da177e4SLinus Torvalds    print "<hr>\n";
5441da177e4SLinus Torvalds}
5451da177e4SLinus Torvalds
546d28bee0cSRandy Dunlap# output typedef in html
5471da177e4SLinus Torvaldssub output_typedef_html(%) {
5481da177e4SLinus Torvalds    my %args = %{$_[0]};
5491da177e4SLinus Torvalds    my ($parameter);
5501da177e4SLinus Torvalds    my $count;
5511da177e4SLinus Torvalds    print "<h2>typedef " . $args{'typedef'} . "</h2>\n";
5521da177e4SLinus Torvalds
5531da177e4SLinus Torvalds    print "<b>typedef " . $args{'typedef'} . "</b>\n";
5541da177e4SLinus Torvalds    output_section_html(@_);
5551da177e4SLinus Torvalds    print "<hr>\n";
5561da177e4SLinus Torvalds}
5571da177e4SLinus Torvalds
5581da177e4SLinus Torvalds# output struct in html
5591da177e4SLinus Torvaldssub output_struct_html(%) {
5601da177e4SLinus Torvalds    my %args = %{$_[0]};
5611da177e4SLinus Torvalds    my ($parameter);
5621da177e4SLinus Torvalds
563262d9b01SRandy Dunlap    print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n";
5641da177e4SLinus Torvalds    print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n";
5651da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
5661da177e4SLinus Torvalds	if ($parameter =~ /^#/) {
5671da177e4SLinus Torvalds		print "$parameter<br>\n";
5681da177e4SLinus Torvalds		next;
5691da177e4SLinus Torvalds	}
5701da177e4SLinus Torvalds	my $parameter_name = $parameter;
5711da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
5721da177e4SLinus Torvalds
5731da177e4SLinus Torvalds	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
5741da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
5751da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
5761da177e4SLinus Torvalds	    # pointer-to-function
5773eb014a1SRandy Dunlap	    print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
5781da177e4SLinus Torvalds	} elsif ($type =~ m/^(.*?)\s*(:.*)/) {
5793eb014a1SRandy Dunlap	    # bitfield
5803eb014a1SRandy Dunlap	    print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
5811da177e4SLinus Torvalds	} else {
5823eb014a1SRandy Dunlap	    print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
5831da177e4SLinus Torvalds	}
5841da177e4SLinus Torvalds    }
5851da177e4SLinus Torvalds    print "};<br>\n";
5861da177e4SLinus Torvalds
5871da177e4SLinus Torvalds    print "<h3>Members</h3>\n";
5881da177e4SLinus Torvalds    print "<dl>\n";
5891da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
5901da177e4SLinus Torvalds	($parameter =~ /^#/) && next;
5911da177e4SLinus Torvalds
5921da177e4SLinus Torvalds	my $parameter_name = $parameter;
5931da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
5941da177e4SLinus Torvalds
5951da177e4SLinus Torvalds	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
5961da177e4SLinus Torvalds	print "<dt><b>" . $parameter . "</b>\n";
5971da177e4SLinus Torvalds	print "<dd>";
5981da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter_name});
5991da177e4SLinus Torvalds    }
6001da177e4SLinus Torvalds    print "</dl>\n";
6011da177e4SLinus Torvalds    output_section_html(@_);
6021da177e4SLinus Torvalds    print "<hr>\n";
6031da177e4SLinus Torvalds}
6041da177e4SLinus Torvalds
6051da177e4SLinus Torvalds# output function in html
6061da177e4SLinus Torvaldssub output_function_html(%) {
6071da177e4SLinus Torvalds    my %args = %{$_[0]};
6081da177e4SLinus Torvalds    my ($parameter, $section);
6091da177e4SLinus Torvalds    my $count;
6101da177e4SLinus Torvalds
611262d9b01SRandy Dunlap    print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n";
6121da177e4SLinus Torvalds    print "<i>" . $args{'functiontype'} . "</i>\n";
6131da177e4SLinus Torvalds    print "<b>" . $args{'function'} . "</b>\n";
6141da177e4SLinus Torvalds    print "(";
6151da177e4SLinus Torvalds    $count = 0;
6161da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
6171da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
6181da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
6191da177e4SLinus Torvalds	    # pointer-to-function
6201da177e4SLinus Torvalds	    print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
6211da177e4SLinus Torvalds	} else {
6221da177e4SLinus Torvalds	    print "<i>" . $type . "</i> <b>" . $parameter . "</b>";
6231da177e4SLinus Torvalds	}
6241da177e4SLinus Torvalds	if ($count != $#{$args{'parameterlist'}}) {
6251da177e4SLinus Torvalds	    $count++;
6261da177e4SLinus Torvalds	    print ",\n";
6271da177e4SLinus Torvalds	}
6281da177e4SLinus Torvalds    }
6291da177e4SLinus Torvalds    print ")\n";
6301da177e4SLinus Torvalds
6311da177e4SLinus Torvalds    print "<h3>Arguments</h3>\n";
6321da177e4SLinus Torvalds    print "<dl>\n";
6331da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
6341da177e4SLinus Torvalds	my $parameter_name = $parameter;
6351da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
6361da177e4SLinus Torvalds
6371da177e4SLinus Torvalds	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
6381da177e4SLinus Torvalds	print "<dt><b>" . $parameter . "</b>\n";
6391da177e4SLinus Torvalds	print "<dd>";
6401da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter_name});
6411da177e4SLinus Torvalds    }
6421da177e4SLinus Torvalds    print "</dl>\n";
6431da177e4SLinus Torvalds    output_section_html(@_);
6441da177e4SLinus Torvalds    print "<hr>\n";
6451da177e4SLinus Torvalds}
6461da177e4SLinus Torvalds
647b112e0f7SJohannes Berg# output DOC: block header in html
648b112e0f7SJohannes Bergsub output_blockhead_html(%) {
6491da177e4SLinus Torvalds    my %args = %{$_[0]};
6501da177e4SLinus Torvalds    my ($parameter, $section);
6511da177e4SLinus Torvalds    my $count;
6521da177e4SLinus Torvalds
6531da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
6541da177e4SLinus Torvalds	print "<h3>$section</h3>\n";
6551da177e4SLinus Torvalds	print "<ul>\n";
6561da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
6571da177e4SLinus Torvalds	print "</ul>\n";
6581da177e4SLinus Torvalds    }
6591da177e4SLinus Torvalds    print "<hr>\n";
6601da177e4SLinus Torvalds}
6611da177e4SLinus Torvalds
662*1b40c194SDan Luedtke# output sections in html5
663*1b40c194SDan Luedtkesub output_section_html5(%) {
664*1b40c194SDan Luedtke    my %args = %{$_[0]};
665*1b40c194SDan Luedtke    my $section;
666*1b40c194SDan Luedtke
667*1b40c194SDan Luedtke    foreach $section (@{$args{'sectionlist'}}) {
668*1b40c194SDan Luedtke	print "<section>\n";
669*1b40c194SDan Luedtke	print "<h1>$section</h1>\n";
670*1b40c194SDan Luedtke	print "<p>\n";
671*1b40c194SDan Luedtke	output_highlight($args{'sections'}{$section});
672*1b40c194SDan Luedtke	print "</p>\n";
673*1b40c194SDan Luedtke	print "</section>\n";
674*1b40c194SDan Luedtke    }
675*1b40c194SDan Luedtke}
676*1b40c194SDan Luedtke
677*1b40c194SDan Luedtke# output enum in html5
678*1b40c194SDan Luedtkesub output_enum_html5(%) {
679*1b40c194SDan Luedtke    my %args = %{$_[0]};
680*1b40c194SDan Luedtke    my ($parameter);
681*1b40c194SDan Luedtke    my $count;
682*1b40c194SDan Luedtke    my $html5id;
683*1b40c194SDan Luedtke
684*1b40c194SDan Luedtke    $html5id = $args{'enum'};
685*1b40c194SDan Luedtke    $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
686*1b40c194SDan Luedtke    print "<article class=\"enum\" id=\"enum:". $html5id . "\">";
687*1b40c194SDan Luedtke    print "<h1>enum " . $args{'enum'} . "</h1>\n";
688*1b40c194SDan Luedtke    print "<ol class=\"code\">\n";
689*1b40c194SDan Luedtke    print "<li>";
690*1b40c194SDan Luedtke    print "<span class=\"keyword\">enum</span> ";
691*1b40c194SDan Luedtke    print "<span class=\"identifier\">" . $args{'enum'} . "</span> {";
692*1b40c194SDan Luedtke    print "</li>\n";
693*1b40c194SDan Luedtke    $count = 0;
694*1b40c194SDan Luedtke    foreach $parameter (@{$args{'parameterlist'}}) {
695*1b40c194SDan Luedtke	print "<li class=\"indent\">";
696*1b40c194SDan Luedtke	print "<span class=\"param\">" . $parameter . "</span>";
697*1b40c194SDan Luedtke	if ($count != $#{$args{'parameterlist'}}) {
698*1b40c194SDan Luedtke	    $count++;
699*1b40c194SDan Luedtke	    print ",";
700*1b40c194SDan Luedtke	}
701*1b40c194SDan Luedtke	print "</li>\n";
702*1b40c194SDan Luedtke    }
703*1b40c194SDan Luedtke    print "<li>};</li>\n";
704*1b40c194SDan Luedtke    print "</ol>\n";
705*1b40c194SDan Luedtke
706*1b40c194SDan Luedtke    print "<section>\n";
707*1b40c194SDan Luedtke    print "<h1>Constants</h1>\n";
708*1b40c194SDan Luedtke    print "<dl>\n";
709*1b40c194SDan Luedtke    foreach $parameter (@{$args{'parameterlist'}}) {
710*1b40c194SDan Luedtke	print "<dt>" . $parameter . "</dt>\n";
711*1b40c194SDan Luedtke	print "<dd>";
712*1b40c194SDan Luedtke	output_highlight($args{'parameterdescs'}{$parameter});
713*1b40c194SDan Luedtke	print "</dd>\n";
714*1b40c194SDan Luedtke    }
715*1b40c194SDan Luedtke    print "</dl>\n";
716*1b40c194SDan Luedtke    print "</section>\n";
717*1b40c194SDan Luedtke    output_section_html5(@_);
718*1b40c194SDan Luedtke    print "</article>\n";
719*1b40c194SDan Luedtke}
720*1b40c194SDan Luedtke
721*1b40c194SDan Luedtke# output typedef in html5
722*1b40c194SDan Luedtkesub output_typedef_html5(%) {
723*1b40c194SDan Luedtke    my %args = %{$_[0]};
724*1b40c194SDan Luedtke    my ($parameter);
725*1b40c194SDan Luedtke    my $count;
726*1b40c194SDan Luedtke    my $html5id;
727*1b40c194SDan Luedtke
728*1b40c194SDan Luedtke    $html5id = $args{'typedef'};
729*1b40c194SDan Luedtke    $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
730*1b40c194SDan Luedtke    print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n";
731*1b40c194SDan Luedtke    print "<h1>typedef " . $args{'typedef'} . "</h1>\n";
732*1b40c194SDan Luedtke
733*1b40c194SDan Luedtke    print "<ol class=\"code\">\n";
734*1b40c194SDan Luedtke    print "<li>";
735*1b40c194SDan Luedtke    print "<span class=\"keyword\">typedef</span> ";
736*1b40c194SDan Luedtke    print "<span class=\"identifier\">" . $args{'typedef'} . "</span>";
737*1b40c194SDan Luedtke    print "</li>\n";
738*1b40c194SDan Luedtke    print "</ol>\n";
739*1b40c194SDan Luedtke    output_section_html5(@_);
740*1b40c194SDan Luedtke    print "</article>\n";
741*1b40c194SDan Luedtke}
742*1b40c194SDan Luedtke
743*1b40c194SDan Luedtke# output struct in html5
744*1b40c194SDan Luedtkesub output_struct_html5(%) {
745*1b40c194SDan Luedtke    my %args = %{$_[0]};
746*1b40c194SDan Luedtke    my ($parameter);
747*1b40c194SDan Luedtke    my $html5id;
748*1b40c194SDan Luedtke
749*1b40c194SDan Luedtke    $html5id = $args{'struct'};
750*1b40c194SDan Luedtke    $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
751*1b40c194SDan Luedtke    print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n";
752*1b40c194SDan Luedtke    print "<hgroup>\n";
753*1b40c194SDan Luedtke    print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>";
754*1b40c194SDan Luedtke    print "<h2>". $args{'purpose'} . "</h2>\n";
755*1b40c194SDan Luedtke    print "</hgroup>\n";
756*1b40c194SDan Luedtke    print "<ol class=\"code\">\n";
757*1b40c194SDan Luedtke    print "<li>";
758*1b40c194SDan Luedtke    print "<span class=\"type\">" . $args{'type'} . "</span> ";
759*1b40c194SDan Luedtke    print "<span class=\"identifier\">" . $args{'struct'} . "</span> {";
760*1b40c194SDan Luedtke    print "</li>\n";
761*1b40c194SDan Luedtke    foreach $parameter (@{$args{'parameterlist'}}) {
762*1b40c194SDan Luedtke	print "<li class=\"indent\">";
763*1b40c194SDan Luedtke	if ($parameter =~ /^#/) {
764*1b40c194SDan Luedtke		print "<span class=\"param\">" . $parameter ."</span>\n";
765*1b40c194SDan Luedtke		print "</li>\n";
766*1b40c194SDan Luedtke		next;
767*1b40c194SDan Luedtke	}
768*1b40c194SDan Luedtke	my $parameter_name = $parameter;
769*1b40c194SDan Luedtke	$parameter_name =~ s/\[.*//;
770*1b40c194SDan Luedtke
771*1b40c194SDan Luedtke	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
772*1b40c194SDan Luedtke	$type = $args{'parametertypes'}{$parameter};
773*1b40c194SDan Luedtke	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
774*1b40c194SDan Luedtke	    # pointer-to-function
775*1b40c194SDan Luedtke	    print "<span class=\"type\">$1</span> ";
776*1b40c194SDan Luedtke	    print "<span class=\"param\">$parameter</span>";
777*1b40c194SDan Luedtke	    print "<span class=\"type\">)</span> ";
778*1b40c194SDan Luedtke	    print "(<span class=\"args\">$2</span>);";
779*1b40c194SDan Luedtke	} elsif ($type =~ m/^(.*?)\s*(:.*)/) {
780*1b40c194SDan Luedtke	    # bitfield
781*1b40c194SDan Luedtke	    print "<span class=\"type\">$1</span> ";
782*1b40c194SDan Luedtke	    print "<span class=\"param\">$parameter</span>";
783*1b40c194SDan Luedtke	    print "<span class=\"bits\">$2</span>;";
784*1b40c194SDan Luedtke	} else {
785*1b40c194SDan Luedtke	    print "<span class=\"type\">$type</span> ";
786*1b40c194SDan Luedtke	    print "<span class=\"param\">$parameter</span>;";
787*1b40c194SDan Luedtke	}
788*1b40c194SDan Luedtke	print "</li>\n";
789*1b40c194SDan Luedtke    }
790*1b40c194SDan Luedtke    print "<li>};</li>\n";
791*1b40c194SDan Luedtke    print "</ol>\n";
792*1b40c194SDan Luedtke
793*1b40c194SDan Luedtke    print "<section>\n";
794*1b40c194SDan Luedtke    print "<h1>Members</h1>\n";
795*1b40c194SDan Luedtke    print "<dl>\n";
796*1b40c194SDan Luedtke    foreach $parameter (@{$args{'parameterlist'}}) {
797*1b40c194SDan Luedtke	($parameter =~ /^#/) && next;
798*1b40c194SDan Luedtke
799*1b40c194SDan Luedtke	my $parameter_name = $parameter;
800*1b40c194SDan Luedtke	$parameter_name =~ s/\[.*//;
801*1b40c194SDan Luedtke
802*1b40c194SDan Luedtke	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
803*1b40c194SDan Luedtke	print "<dt>" . $parameter . "</dt>\n";
804*1b40c194SDan Luedtke	print "<dd>";
805*1b40c194SDan Luedtke	output_highlight($args{'parameterdescs'}{$parameter_name});
806*1b40c194SDan Luedtke	print "</dd>\n";
807*1b40c194SDan Luedtke    }
808*1b40c194SDan Luedtke    print "</dl>\n";
809*1b40c194SDan Luedtke    print "</section>\n";
810*1b40c194SDan Luedtke    output_section_html5(@_);
811*1b40c194SDan Luedtke    print "</article>\n";
812*1b40c194SDan Luedtke}
813*1b40c194SDan Luedtke
814*1b40c194SDan Luedtke# output function in html5
815*1b40c194SDan Luedtkesub output_function_html5(%) {
816*1b40c194SDan Luedtke    my %args = %{$_[0]};
817*1b40c194SDan Luedtke    my ($parameter, $section);
818*1b40c194SDan Luedtke    my $count;
819*1b40c194SDan Luedtke    my $html5id;
820*1b40c194SDan Luedtke
821*1b40c194SDan Luedtke    $html5id = $args{'function'};
822*1b40c194SDan Luedtke    $html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
823*1b40c194SDan Luedtke    print "<article class=\"function\" id=\"func:". $html5id . "\">\n";
824*1b40c194SDan Luedtke    print "<hgroup>\n";
825*1b40c194SDan Luedtke    print "<h1>" . $args{'function'} . "</h1>";
826*1b40c194SDan Luedtke    print "<h2>" . $args{'purpose'} . "</h2>\n";
827*1b40c194SDan Luedtke    print "</hgroup>\n";
828*1b40c194SDan Luedtke    print "<ol class=\"code\">\n";
829*1b40c194SDan Luedtke    print "<li>";
830*1b40c194SDan Luedtke    print "<span class=\"type\">" . $args{'functiontype'} . "</span> ";
831*1b40c194SDan Luedtke    print "<span class=\"identifier\">" . $args{'function'} . "</span> (";
832*1b40c194SDan Luedtke    print "</li>";
833*1b40c194SDan Luedtke    $count = 0;
834*1b40c194SDan Luedtke    foreach $parameter (@{$args{'parameterlist'}}) {
835*1b40c194SDan Luedtke	print "<li class=\"indent\">";
836*1b40c194SDan Luedtke	$type = $args{'parametertypes'}{$parameter};
837*1b40c194SDan Luedtke	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
838*1b40c194SDan Luedtke	    # pointer-to-function
839*1b40c194SDan Luedtke	    print "<span class=\"type\">$1</span> ";
840*1b40c194SDan Luedtke	    print "<span class=\"param\">$parameter</span>";
841*1b40c194SDan Luedtke	    print "<span class=\"type\">)</span> ";
842*1b40c194SDan Luedtke	    print "(<span class=\"args\">$2</span>)";
843*1b40c194SDan Luedtke	} else {
844*1b40c194SDan Luedtke	    print "<span class=\"type\">$type</span> ";
845*1b40c194SDan Luedtke	    print "<span class=\"param\">$parameter</span>";
846*1b40c194SDan Luedtke	}
847*1b40c194SDan Luedtke	if ($count != $#{$args{'parameterlist'}}) {
848*1b40c194SDan Luedtke	    $count++;
849*1b40c194SDan Luedtke	    print ",";
850*1b40c194SDan Luedtke	}
851*1b40c194SDan Luedtke	print "</li>\n";
852*1b40c194SDan Luedtke    }
853*1b40c194SDan Luedtke    print "<li>)</li>\n";
854*1b40c194SDan Luedtke    print "</ol>\n";
855*1b40c194SDan Luedtke
856*1b40c194SDan Luedtke    print "<section>\n";
857*1b40c194SDan Luedtke    print "<h1>Arguments</h1>\n";
858*1b40c194SDan Luedtke    print "<p>\n";
859*1b40c194SDan Luedtke    print "<dl>\n";
860*1b40c194SDan Luedtke    foreach $parameter (@{$args{'parameterlist'}}) {
861*1b40c194SDan Luedtke	my $parameter_name = $parameter;
862*1b40c194SDan Luedtke	$parameter_name =~ s/\[.*//;
863*1b40c194SDan Luedtke
864*1b40c194SDan Luedtke	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
865*1b40c194SDan Luedtke	print "<dt>" . $parameter . "</dt>\n";
866*1b40c194SDan Luedtke	print "<dd>";
867*1b40c194SDan Luedtke	output_highlight($args{'parameterdescs'}{$parameter_name});
868*1b40c194SDan Luedtke	print "</dd>\n";
869*1b40c194SDan Luedtke    }
870*1b40c194SDan Luedtke    print "</dl>\n";
871*1b40c194SDan Luedtke    print "</section>\n";
872*1b40c194SDan Luedtke    output_section_html5(@_);
873*1b40c194SDan Luedtke    print "</article>\n";
874*1b40c194SDan Luedtke}
875*1b40c194SDan Luedtke
876*1b40c194SDan Luedtke# output DOC: block header in html5
877*1b40c194SDan Luedtkesub output_blockhead_html5(%) {
878*1b40c194SDan Luedtke    my %args = %{$_[0]};
879*1b40c194SDan Luedtke    my ($parameter, $section);
880*1b40c194SDan Luedtke    my $count;
881*1b40c194SDan Luedtke    my $html5id;
882*1b40c194SDan Luedtke
883*1b40c194SDan Luedtke    foreach $section (@{$args{'sectionlist'}}) {
884*1b40c194SDan Luedtke	$html5id = $section;
885*1b40c194SDan Luedtke	$html5id =~ s/[^a-zA-Z0-9\-]+/_/g;
886*1b40c194SDan Luedtke	print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n";
887*1b40c194SDan Luedtke	print "<h1>$section</h1>\n";
888*1b40c194SDan Luedtke	print "<p>\n";
889*1b40c194SDan Luedtke	output_highlight($args{'sections'}{$section});
890*1b40c194SDan Luedtke	print "</p>\n";
891*1b40c194SDan Luedtke    }
892*1b40c194SDan Luedtke    print "</article>\n";
893*1b40c194SDan Luedtke}
894*1b40c194SDan Luedtke
8951da177e4SLinus Torvaldssub output_section_xml(%) {
8961da177e4SLinus Torvalds    my %args = %{$_[0]};
8971da177e4SLinus Torvalds    my $section;
8981da177e4SLinus Torvalds    # print out each section
8991da177e4SLinus Torvalds    $lineprefix="   ";
9001da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
901c73894c1SRich Walker	print "<refsect1>\n";
902c73894c1SRich Walker	print "<title>$section</title>\n";
9031da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
904c73894c1SRich Walker	    print "<informalexample><programlisting>\n";
905c73894c1SRich Walker	} else {
906c73894c1SRich Walker	    print "<para>\n";
9071da177e4SLinus Torvalds	}
9081da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
9091da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
910c73894c1SRich Walker	    print "</programlisting></informalexample>\n";
911c73894c1SRich Walker	} else {
912c73894c1SRich Walker	    print "</para>\n";
9131da177e4SLinus Torvalds	}
914c73894c1SRich Walker	print "</refsect1>\n";
9151da177e4SLinus Torvalds    }
9161da177e4SLinus Torvalds}
9171da177e4SLinus Torvalds
9181da177e4SLinus Torvalds# output function in XML DocBook
9191da177e4SLinus Torvaldssub output_function_xml(%) {
9201da177e4SLinus Torvalds    my %args = %{$_[0]};
9211da177e4SLinus Torvalds    my ($parameter, $section);
9221da177e4SLinus Torvalds    my $count;
9231da177e4SLinus Torvalds    my $id;
9241da177e4SLinus Torvalds
9251da177e4SLinus Torvalds    $id = "API-" . $args{'function'};
9261da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
9271da177e4SLinus Torvalds
9285449bc94SPavel Pisa    print "<refentry id=\"$id\">\n";
9298b0c2d98SMartin Waitz    print "<refentryinfo>\n";
9308b0c2d98SMartin Waitz    print " <title>LINUX</title>\n";
9318b0c2d98SMartin Waitz    print " <productname>Kernel Hackers Manual</productname>\n";
9328b0c2d98SMartin Waitz    print " <date>$man_date</date>\n";
9338b0c2d98SMartin Waitz    print "</refentryinfo>\n";
9341da177e4SLinus Torvalds    print "<refmeta>\n";
9355449bc94SPavel Pisa    print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n";
9368b0c2d98SMartin Waitz    print " <manvolnum>9</manvolnum>\n";
9370366299bSBorislav Petkov    print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
9381da177e4SLinus Torvalds    print "</refmeta>\n";
9391da177e4SLinus Torvalds    print "<refnamediv>\n";
9401da177e4SLinus Torvalds    print " <refname>" . $args{'function'} . "</refname>\n";
9411da177e4SLinus Torvalds    print " <refpurpose>\n";
9421da177e4SLinus Torvalds    print "  ";
9431da177e4SLinus Torvalds    output_highlight ($args{'purpose'});
9441da177e4SLinus Torvalds    print " </refpurpose>\n";
9451da177e4SLinus Torvalds    print "</refnamediv>\n";
9461da177e4SLinus Torvalds
9471da177e4SLinus Torvalds    print "<refsynopsisdiv>\n";
9481da177e4SLinus Torvalds    print " <title>Synopsis</title>\n";
9491da177e4SLinus Torvalds    print "  <funcsynopsis><funcprototype>\n";
9501da177e4SLinus Torvalds    print "   <funcdef>" . $args{'functiontype'} . " ";
9511da177e4SLinus Torvalds    print "<function>" . $args{'function'} . " </function></funcdef>\n";
9521da177e4SLinus Torvalds
9531da177e4SLinus Torvalds    $count = 0;
9541da177e4SLinus Torvalds    if ($#{$args{'parameterlist'}} >= 0) {
9551da177e4SLinus Torvalds	foreach $parameter (@{$args{'parameterlist'}}) {
9561da177e4SLinus Torvalds	    $type = $args{'parametertypes'}{$parameter};
9571da177e4SLinus Torvalds	    if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
9581da177e4SLinus Torvalds		# pointer-to-function
9591da177e4SLinus Torvalds		print "   <paramdef>$1<parameter>$parameter</parameter>)\n";
9601da177e4SLinus Torvalds		print "     <funcparams>$2</funcparams></paramdef>\n";
9611da177e4SLinus Torvalds	    } else {
9621da177e4SLinus Torvalds		print "   <paramdef>" . $type;
9631da177e4SLinus Torvalds		print " <parameter>$parameter</parameter></paramdef>\n";
9641da177e4SLinus Torvalds	    }
9651da177e4SLinus Torvalds	}
9661da177e4SLinus Torvalds    } else {
9676013d544SMartin Waitz	print "  <void/>\n";
9681da177e4SLinus Torvalds    }
9691da177e4SLinus Torvalds    print "  </funcprototype></funcsynopsis>\n";
9701da177e4SLinus Torvalds    print "</refsynopsisdiv>\n";
9711da177e4SLinus Torvalds
9721da177e4SLinus Torvalds    # print parameters
9731da177e4SLinus Torvalds    print "<refsect1>\n <title>Arguments</title>\n";
9741da177e4SLinus Torvalds    if ($#{$args{'parameterlist'}} >= 0) {
9751da177e4SLinus Torvalds	print " <variablelist>\n";
9761da177e4SLinus Torvalds	foreach $parameter (@{$args{'parameterlist'}}) {
9771da177e4SLinus Torvalds	    my $parameter_name = $parameter;
9781da177e4SLinus Torvalds	    $parameter_name =~ s/\[.*//;
9791da177e4SLinus Torvalds
9801da177e4SLinus Torvalds	    print "  <varlistentry>\n   <term><parameter>$parameter</parameter></term>\n";
9811da177e4SLinus Torvalds	    print "   <listitem>\n    <para>\n";
9821da177e4SLinus Torvalds	    $lineprefix="     ";
9831da177e4SLinus Torvalds	    output_highlight($args{'parameterdescs'}{$parameter_name});
9841da177e4SLinus Torvalds	    print "    </para>\n   </listitem>\n  </varlistentry>\n";
9851da177e4SLinus Torvalds	}
9861da177e4SLinus Torvalds	print " </variablelist>\n";
9871da177e4SLinus Torvalds    } else {
9881da177e4SLinus Torvalds	print " <para>\n  None\n </para>\n";
9891da177e4SLinus Torvalds    }
9901da177e4SLinus Torvalds    print "</refsect1>\n";
9911da177e4SLinus Torvalds
9921da177e4SLinus Torvalds    output_section_xml(@_);
9931da177e4SLinus Torvalds    print "</refentry>\n\n";
9941da177e4SLinus Torvalds}
9951da177e4SLinus Torvalds
9961da177e4SLinus Torvalds# output struct in XML DocBook
9971da177e4SLinus Torvaldssub output_struct_xml(%) {
9981da177e4SLinus Torvalds    my %args = %{$_[0]};
9991da177e4SLinus Torvalds    my ($parameter, $section);
10001da177e4SLinus Torvalds    my $id;
10011da177e4SLinus Torvalds
10021da177e4SLinus Torvalds    $id = "API-struct-" . $args{'struct'};
10031da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
10041da177e4SLinus Torvalds
10055449bc94SPavel Pisa    print "<refentry id=\"$id\">\n";
10068b0c2d98SMartin Waitz    print "<refentryinfo>\n";
10078b0c2d98SMartin Waitz    print " <title>LINUX</title>\n";
10088b0c2d98SMartin Waitz    print " <productname>Kernel Hackers Manual</productname>\n";
10098b0c2d98SMartin Waitz    print " <date>$man_date</date>\n";
10108b0c2d98SMartin Waitz    print "</refentryinfo>\n";
10111da177e4SLinus Torvalds    print "<refmeta>\n";
10125449bc94SPavel Pisa    print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n";
10138b0c2d98SMartin Waitz    print " <manvolnum>9</manvolnum>\n";
10140366299bSBorislav Petkov    print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
10151da177e4SLinus Torvalds    print "</refmeta>\n";
10161da177e4SLinus Torvalds    print "<refnamediv>\n";
10171da177e4SLinus Torvalds    print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n";
10181da177e4SLinus Torvalds    print " <refpurpose>\n";
10191da177e4SLinus Torvalds    print "  ";
10201da177e4SLinus Torvalds    output_highlight ($args{'purpose'});
10211da177e4SLinus Torvalds    print " </refpurpose>\n";
10221da177e4SLinus Torvalds    print "</refnamediv>\n";
10231da177e4SLinus Torvalds
10241da177e4SLinus Torvalds    print "<refsynopsisdiv>\n";
10251da177e4SLinus Torvalds    print " <title>Synopsis</title>\n";
10261da177e4SLinus Torvalds    print "  <programlisting>\n";
10271da177e4SLinus Torvalds    print $args{'type'} . " " . $args{'struct'} . " {\n";
10281da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
10291da177e4SLinus Torvalds	if ($parameter =~ /^#/) {
10302b35f4d9SRandy Dunlap	    my $prm = $parameter;
10312b35f4d9SRandy Dunlap	    # convert data read & converted thru xml_escape() into &xyz; format:
10322b35f4d9SRandy Dunlap	    # This allows us to have #define macros interspersed in a struct.
10332b35f4d9SRandy Dunlap	    $prm =~ s/\\\\\\/\&/g;
10342b35f4d9SRandy Dunlap	    print "$prm\n";
10351da177e4SLinus Torvalds	    next;
10361da177e4SLinus Torvalds	}
10371da177e4SLinus Torvalds
10381da177e4SLinus Torvalds	my $parameter_name = $parameter;
10391da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
10401da177e4SLinus Torvalds
10411da177e4SLinus Torvalds	defined($args{'parameterdescs'}{$parameter_name}) || next;
10421da177e4SLinus Torvalds	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
10431da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
10441da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
10451da177e4SLinus Torvalds	    # pointer-to-function
10461da177e4SLinus Torvalds	    print "  $1 $parameter) ($2);\n";
10471da177e4SLinus Torvalds	} elsif ($type =~ m/^(.*?)\s*(:.*)/) {
104851f5a0c8SRandy Dunlap	    # bitfield
10491da177e4SLinus Torvalds	    print "  $1 $parameter$2;\n";
10501da177e4SLinus Torvalds	} else {
10511da177e4SLinus Torvalds	    print "  " . $type . " " . $parameter . ";\n";
10521da177e4SLinus Torvalds	}
10531da177e4SLinus Torvalds    }
10541da177e4SLinus Torvalds    print "};";
10551da177e4SLinus Torvalds    print "  </programlisting>\n";
10561da177e4SLinus Torvalds    print "</refsynopsisdiv>\n";
10571da177e4SLinus Torvalds
10581da177e4SLinus Torvalds    print " <refsect1>\n";
10591da177e4SLinus Torvalds    print "  <title>Members</title>\n";
10601da177e4SLinus Torvalds
106139f00c08SRandy Dunlap    if ($#{$args{'parameterlist'}} >= 0) {
10621da177e4SLinus Torvalds    print "  <variablelist>\n";
10631da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
10641da177e4SLinus Torvalds      ($parameter =~ /^#/) && next;
10651da177e4SLinus Torvalds
10661da177e4SLinus Torvalds      my $parameter_name = $parameter;
10671da177e4SLinus Torvalds      $parameter_name =~ s/\[.*//;
10681da177e4SLinus Torvalds
10691da177e4SLinus Torvalds      defined($args{'parameterdescs'}{$parameter_name}) || next;
10701da177e4SLinus Torvalds      ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
10711da177e4SLinus Torvalds      print "    <varlistentry>";
10721da177e4SLinus Torvalds      print "      <term>$parameter</term>\n";
10731da177e4SLinus Torvalds      print "      <listitem><para>\n";
10741da177e4SLinus Torvalds      output_highlight($args{'parameterdescs'}{$parameter_name});
10751da177e4SLinus Torvalds      print "      </para></listitem>\n";
10761da177e4SLinus Torvalds      print "    </varlistentry>\n";
10771da177e4SLinus Torvalds    }
10781da177e4SLinus Torvalds    print "  </variablelist>\n";
107939f00c08SRandy Dunlap    } else {
108039f00c08SRandy Dunlap	print " <para>\n  None\n </para>\n";
108139f00c08SRandy Dunlap    }
10821da177e4SLinus Torvalds    print " </refsect1>\n";
10831da177e4SLinus Torvalds
10841da177e4SLinus Torvalds    output_section_xml(@_);
10851da177e4SLinus Torvalds
10861da177e4SLinus Torvalds    print "</refentry>\n\n";
10871da177e4SLinus Torvalds}
10881da177e4SLinus Torvalds
10891da177e4SLinus Torvalds# output enum in XML DocBook
10901da177e4SLinus Torvaldssub output_enum_xml(%) {
10911da177e4SLinus Torvalds    my %args = %{$_[0]};
10921da177e4SLinus Torvalds    my ($parameter, $section);
10931da177e4SLinus Torvalds    my $count;
10941da177e4SLinus Torvalds    my $id;
10951da177e4SLinus Torvalds
10961da177e4SLinus Torvalds    $id = "API-enum-" . $args{'enum'};
10971da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
10981da177e4SLinus Torvalds
10995449bc94SPavel Pisa    print "<refentry id=\"$id\">\n";
11008b0c2d98SMartin Waitz    print "<refentryinfo>\n";
11018b0c2d98SMartin Waitz    print " <title>LINUX</title>\n";
11028b0c2d98SMartin Waitz    print " <productname>Kernel Hackers Manual</productname>\n";
11038b0c2d98SMartin Waitz    print " <date>$man_date</date>\n";
11048b0c2d98SMartin Waitz    print "</refentryinfo>\n";
11051da177e4SLinus Torvalds    print "<refmeta>\n";
11065449bc94SPavel Pisa    print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n";
11078b0c2d98SMartin Waitz    print " <manvolnum>9</manvolnum>\n";
11080366299bSBorislav Petkov    print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
11091da177e4SLinus Torvalds    print "</refmeta>\n";
11101da177e4SLinus Torvalds    print "<refnamediv>\n";
11111da177e4SLinus Torvalds    print " <refname>enum " . $args{'enum'} . "</refname>\n";
11121da177e4SLinus Torvalds    print " <refpurpose>\n";
11131da177e4SLinus Torvalds    print "  ";
11141da177e4SLinus Torvalds    output_highlight ($args{'purpose'});
11151da177e4SLinus Torvalds    print " </refpurpose>\n";
11161da177e4SLinus Torvalds    print "</refnamediv>\n";
11171da177e4SLinus Torvalds
11181da177e4SLinus Torvalds    print "<refsynopsisdiv>\n";
11191da177e4SLinus Torvalds    print " <title>Synopsis</title>\n";
11201da177e4SLinus Torvalds    print "  <programlisting>\n";
11211da177e4SLinus Torvalds    print "enum " . $args{'enum'} . " {\n";
11221da177e4SLinus Torvalds    $count = 0;
11231da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
11241da177e4SLinus Torvalds	print "  $parameter";
11251da177e4SLinus Torvalds	if ($count != $#{$args{'parameterlist'}}) {
11261da177e4SLinus Torvalds	    $count++;
11271da177e4SLinus Torvalds	    print ",";
11281da177e4SLinus Torvalds	}
11291da177e4SLinus Torvalds	print "\n";
11301da177e4SLinus Torvalds    }
11311da177e4SLinus Torvalds    print "};";
11321da177e4SLinus Torvalds    print "  </programlisting>\n";
11331da177e4SLinus Torvalds    print "</refsynopsisdiv>\n";
11341da177e4SLinus Torvalds
11351da177e4SLinus Torvalds    print "<refsect1>\n";
11361da177e4SLinus Torvalds    print " <title>Constants</title>\n";
11371da177e4SLinus Torvalds    print "  <variablelist>\n";
11381da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
11391da177e4SLinus Torvalds      my $parameter_name = $parameter;
11401da177e4SLinus Torvalds      $parameter_name =~ s/\[.*//;
11411da177e4SLinus Torvalds
11421da177e4SLinus Torvalds      print "    <varlistentry>";
11431da177e4SLinus Torvalds      print "      <term>$parameter</term>\n";
11441da177e4SLinus Torvalds      print "      <listitem><para>\n";
11451da177e4SLinus Torvalds      output_highlight($args{'parameterdescs'}{$parameter_name});
11461da177e4SLinus Torvalds      print "      </para></listitem>\n";
11471da177e4SLinus Torvalds      print "    </varlistentry>\n";
11481da177e4SLinus Torvalds    }
11491da177e4SLinus Torvalds    print "  </variablelist>\n";
11501da177e4SLinus Torvalds    print "</refsect1>\n";
11511da177e4SLinus Torvalds
11521da177e4SLinus Torvalds    output_section_xml(@_);
11531da177e4SLinus Torvalds
11541da177e4SLinus Torvalds    print "</refentry>\n\n";
11551da177e4SLinus Torvalds}
11561da177e4SLinus Torvalds
11571da177e4SLinus Torvalds# output typedef in XML DocBook
11581da177e4SLinus Torvaldssub output_typedef_xml(%) {
11591da177e4SLinus Torvalds    my %args = %{$_[0]};
11601da177e4SLinus Torvalds    my ($parameter, $section);
11611da177e4SLinus Torvalds    my $id;
11621da177e4SLinus Torvalds
11631da177e4SLinus Torvalds    $id = "API-typedef-" . $args{'typedef'};
11641da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
11651da177e4SLinus Torvalds
11665449bc94SPavel Pisa    print "<refentry id=\"$id\">\n";
11678b0c2d98SMartin Waitz    print "<refentryinfo>\n";
11688b0c2d98SMartin Waitz    print " <title>LINUX</title>\n";
11698b0c2d98SMartin Waitz    print " <productname>Kernel Hackers Manual</productname>\n";
11708b0c2d98SMartin Waitz    print " <date>$man_date</date>\n";
11718b0c2d98SMartin Waitz    print "</refentryinfo>\n";
11721da177e4SLinus Torvalds    print "<refmeta>\n";
11735449bc94SPavel Pisa    print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n";
11748b0c2d98SMartin Waitz    print " <manvolnum>9</manvolnum>\n";
11751da177e4SLinus Torvalds    print "</refmeta>\n";
11761da177e4SLinus Torvalds    print "<refnamediv>\n";
11771da177e4SLinus Torvalds    print " <refname>typedef " . $args{'typedef'} . "</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 "  <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n";
11871da177e4SLinus Torvalds    print "</refsynopsisdiv>\n";
11881da177e4SLinus Torvalds
11891da177e4SLinus Torvalds    output_section_xml(@_);
11901da177e4SLinus Torvalds
11911da177e4SLinus Torvalds    print "</refentry>\n\n";
11921da177e4SLinus Torvalds}
11931da177e4SLinus Torvalds
11941da177e4SLinus Torvalds# output in XML DocBook
1195b112e0f7SJohannes Bergsub output_blockhead_xml(%) {
11961da177e4SLinus Torvalds    my %args = %{$_[0]};
11971da177e4SLinus Torvalds    my ($parameter, $section);
11981da177e4SLinus Torvalds    my $count;
11991da177e4SLinus Torvalds
12001da177e4SLinus Torvalds    my $id = $args{'module'};
12011da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
12021da177e4SLinus Torvalds
12031da177e4SLinus Torvalds    # print out each section
12041da177e4SLinus Torvalds    $lineprefix="   ";
12051da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
1206b112e0f7SJohannes Berg	if (!$args{'content-only'}) {
1207b112e0f7SJohannes Berg		print "<refsect1>\n <title>$section</title>\n";
1208b112e0f7SJohannes Berg	}
12091da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
12101da177e4SLinus Torvalds	    print "<example><para>\n";
1211b112e0f7SJohannes Berg	} else {
1212b112e0f7SJohannes Berg	    print "<para>\n";
12131da177e4SLinus Torvalds	}
12141da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
12151da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
12161da177e4SLinus Torvalds	    print "</para></example>\n";
1217b112e0f7SJohannes Berg	} else {
1218b112e0f7SJohannes Berg	    print "</para>";
12191da177e4SLinus Torvalds	}
1220b112e0f7SJohannes Berg	if (!$args{'content-only'}) {
1221b112e0f7SJohannes Berg		print "\n</refsect1>\n";
1222b112e0f7SJohannes Berg	}
12231da177e4SLinus Torvalds    }
12241da177e4SLinus Torvalds
12251da177e4SLinus Torvalds    print "\n\n";
12261da177e4SLinus Torvalds}
12271da177e4SLinus Torvalds
12281da177e4SLinus Torvalds# output in XML DocBook
12291da177e4SLinus Torvaldssub output_function_gnome {
12301da177e4SLinus Torvalds    my %args = %{$_[0]};
12311da177e4SLinus Torvalds    my ($parameter, $section);
12321da177e4SLinus Torvalds    my $count;
12331da177e4SLinus Torvalds    my $id;
12341da177e4SLinus Torvalds
12351da177e4SLinus Torvalds    $id = $args{'module'} . "-" . $args{'function'};
12361da177e4SLinus Torvalds    $id =~ s/[^A-Za-z0-9]/-/g;
12371da177e4SLinus Torvalds
12381da177e4SLinus Torvalds    print "<sect2>\n";
12391da177e4SLinus Torvalds    print " <title id=\"$id\">" . $args{'function'} . "</title>\n";
12401da177e4SLinus Torvalds
12411da177e4SLinus Torvalds    print "  <funcsynopsis>\n";
12421da177e4SLinus Torvalds    print "   <funcdef>" . $args{'functiontype'} . " ";
12431da177e4SLinus Torvalds    print "<function>" . $args{'function'} . " ";
12441da177e4SLinus Torvalds    print "</function></funcdef>\n";
12451da177e4SLinus Torvalds
12461da177e4SLinus Torvalds    $count = 0;
12471da177e4SLinus Torvalds    if ($#{$args{'parameterlist'}} >= 0) {
12481da177e4SLinus Torvalds	foreach $parameter (@{$args{'parameterlist'}}) {
12491da177e4SLinus Torvalds	    $type = $args{'parametertypes'}{$parameter};
12501da177e4SLinus Torvalds	    if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
12511da177e4SLinus Torvalds		# pointer-to-function
12521da177e4SLinus Torvalds		print "   <paramdef>$1 <parameter>$parameter</parameter>)\n";
12531da177e4SLinus Torvalds		print "     <funcparams>$2</funcparams></paramdef>\n";
12541da177e4SLinus Torvalds	    } else {
12551da177e4SLinus Torvalds		print "   <paramdef>" . $type;
12561da177e4SLinus Torvalds		print " <parameter>$parameter</parameter></paramdef>\n";
12571da177e4SLinus Torvalds	    }
12581da177e4SLinus Torvalds	}
12591da177e4SLinus Torvalds    } else {
12601da177e4SLinus Torvalds	print "  <void>\n";
12611da177e4SLinus Torvalds    }
12621da177e4SLinus Torvalds    print "  </funcsynopsis>\n";
12631da177e4SLinus Torvalds    if ($#{$args{'parameterlist'}} >= 0) {
12641da177e4SLinus Torvalds	print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
12651da177e4SLinus Torvalds	print "<tgroup cols=\"2\">\n";
12661da177e4SLinus Torvalds	print "<colspec colwidth=\"2*\">\n";
12671da177e4SLinus Torvalds	print "<colspec colwidth=\"8*\">\n";
12681da177e4SLinus Torvalds	print "<tbody>\n";
12691da177e4SLinus Torvalds	foreach $parameter (@{$args{'parameterlist'}}) {
12701da177e4SLinus Torvalds	    my $parameter_name = $parameter;
12711da177e4SLinus Torvalds	    $parameter_name =~ s/\[.*//;
12721da177e4SLinus Torvalds
12731da177e4SLinus Torvalds	    print "  <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
12741da177e4SLinus Torvalds	    print "   <entry>\n";
12751da177e4SLinus Torvalds	    $lineprefix="     ";
12761da177e4SLinus Torvalds	    output_highlight($args{'parameterdescs'}{$parameter_name});
12771da177e4SLinus Torvalds	    print "    </entry></row>\n";
12781da177e4SLinus Torvalds	}
12791da177e4SLinus Torvalds	print " </tbody></tgroup></informaltable>\n";
12801da177e4SLinus Torvalds    } else {
12811da177e4SLinus Torvalds	print " <para>\n  None\n </para>\n";
12821da177e4SLinus Torvalds    }
12831da177e4SLinus Torvalds
12841da177e4SLinus Torvalds    # print out each section
12851da177e4SLinus Torvalds    $lineprefix="   ";
12861da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
12871da177e4SLinus Torvalds	print "<simplesect>\n <title>$section</title>\n";
12881da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
12891da177e4SLinus Torvalds	    print "<example><programlisting>\n";
12901da177e4SLinus Torvalds	} else {
12911da177e4SLinus Torvalds	}
12921da177e4SLinus Torvalds	print "<para>\n";
12931da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
12941da177e4SLinus Torvalds	print "</para>\n";
12951da177e4SLinus Torvalds	if ($section =~ m/EXAMPLE/i) {
12961da177e4SLinus Torvalds	    print "</programlisting></example>\n";
12971da177e4SLinus Torvalds	} else {
12981da177e4SLinus Torvalds	}
12991da177e4SLinus Torvalds	print " </simplesect>\n";
13001da177e4SLinus Torvalds    }
13011da177e4SLinus Torvalds
13021da177e4SLinus Torvalds    print "</sect2>\n\n";
13031da177e4SLinus Torvalds}
13041da177e4SLinus Torvalds
13051da177e4SLinus Torvalds##
13061da177e4SLinus Torvalds# output function in man
13071da177e4SLinus Torvaldssub output_function_man(%) {
13081da177e4SLinus Torvalds    my %args = %{$_[0]};
13091da177e4SLinus Torvalds    my ($parameter, $section);
13101da177e4SLinus Torvalds    my $count;
13111da177e4SLinus Torvalds
13121da177e4SLinus Torvalds    print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
13131da177e4SLinus Torvalds
13141da177e4SLinus Torvalds    print ".SH NAME\n";
13151da177e4SLinus Torvalds    print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
13161da177e4SLinus Torvalds
13171da177e4SLinus Torvalds    print ".SH SYNOPSIS\n";
1318a21217daSRandy Dunlap    if ($args{'functiontype'} ne "") {
13191da177e4SLinus Torvalds	print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
1320a21217daSRandy Dunlap    } else {
1321a21217daSRandy Dunlap	print ".B \"" . $args{'function'} . "\n";
1322a21217daSRandy Dunlap    }
13231da177e4SLinus Torvalds    $count = 0;
13241da177e4SLinus Torvalds    my $parenth = "(";
13251da177e4SLinus Torvalds    my $post = ",";
13261da177e4SLinus Torvalds    foreach my $parameter (@{$args{'parameterlist'}}) {
13271da177e4SLinus Torvalds	if ($count == $#{$args{'parameterlist'}}) {
13281da177e4SLinus Torvalds	    $post = ");";
13291da177e4SLinus Torvalds	}
13301da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
13311da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
13321da177e4SLinus Torvalds	    # pointer-to-function
13331da177e4SLinus Torvalds	    print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n";
13341da177e4SLinus Torvalds	} else {
13351da177e4SLinus Torvalds	    $type =~ s/([^\*])$/$1 /;
13361da177e4SLinus Torvalds	    print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n";
13371da177e4SLinus Torvalds	}
13381da177e4SLinus Torvalds	$count++;
13391da177e4SLinus Torvalds	$parenth = "";
13401da177e4SLinus Torvalds    }
13411da177e4SLinus Torvalds
13421da177e4SLinus Torvalds    print ".SH ARGUMENTS\n";
13431da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
13441da177e4SLinus Torvalds	my $parameter_name = $parameter;
13451da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
13461da177e4SLinus Torvalds
13471da177e4SLinus Torvalds	print ".IP \"" . $parameter . "\" 12\n";
13481da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter_name});
13491da177e4SLinus Torvalds    }
13501da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
13511da177e4SLinus Torvalds	print ".SH \"", uc $section, "\"\n";
13521da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
13531da177e4SLinus Torvalds    }
13541da177e4SLinus Torvalds}
13551da177e4SLinus Torvalds
13561da177e4SLinus Torvalds##
13571da177e4SLinus Torvalds# output enum in man
13581da177e4SLinus Torvaldssub output_enum_man(%) {
13591da177e4SLinus Torvalds    my %args = %{$_[0]};
13601da177e4SLinus Torvalds    my ($parameter, $section);
13611da177e4SLinus Torvalds    my $count;
13621da177e4SLinus Torvalds
13631da177e4SLinus Torvalds    print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
13641da177e4SLinus Torvalds
13651da177e4SLinus Torvalds    print ".SH NAME\n";
13661da177e4SLinus Torvalds    print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
13671da177e4SLinus Torvalds
13681da177e4SLinus Torvalds    print ".SH SYNOPSIS\n";
13691da177e4SLinus Torvalds    print "enum " . $args{'enum'} . " {\n";
13701da177e4SLinus Torvalds    $count = 0;
13711da177e4SLinus Torvalds    foreach my $parameter (@{$args{'parameterlist'}}) {
13721da177e4SLinus Torvalds	print ".br\n.BI \"    $parameter\"\n";
13731da177e4SLinus Torvalds	if ($count == $#{$args{'parameterlist'}}) {
13741da177e4SLinus Torvalds	    print "\n};\n";
13751da177e4SLinus Torvalds	    last;
13761da177e4SLinus Torvalds	}
13771da177e4SLinus Torvalds	else {
13781da177e4SLinus Torvalds	    print ", \n.br\n";
13791da177e4SLinus Torvalds	}
13801da177e4SLinus Torvalds	$count++;
13811da177e4SLinus Torvalds    }
13821da177e4SLinus Torvalds
13831da177e4SLinus Torvalds    print ".SH Constants\n";
13841da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
13851da177e4SLinus Torvalds	my $parameter_name = $parameter;
13861da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
13871da177e4SLinus Torvalds
13881da177e4SLinus Torvalds	print ".IP \"" . $parameter . "\" 12\n";
13891da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter_name});
13901da177e4SLinus Torvalds    }
13911da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
13921da177e4SLinus Torvalds	print ".SH \"$section\"\n";
13931da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
13941da177e4SLinus Torvalds    }
13951da177e4SLinus Torvalds}
13961da177e4SLinus Torvalds
13971da177e4SLinus Torvalds##
13981da177e4SLinus Torvalds# output struct in man
13991da177e4SLinus Torvaldssub output_struct_man(%) {
14001da177e4SLinus Torvalds    my %args = %{$_[0]};
14011da177e4SLinus Torvalds    my ($parameter, $section);
14021da177e4SLinus Torvalds
14031da177e4SLinus Torvalds    print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
14041da177e4SLinus Torvalds
14051da177e4SLinus Torvalds    print ".SH NAME\n";
14061da177e4SLinus Torvalds    print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
14071da177e4SLinus Torvalds
14081da177e4SLinus Torvalds    print ".SH SYNOPSIS\n";
14091da177e4SLinus Torvalds    print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
14101da177e4SLinus Torvalds
14111da177e4SLinus Torvalds    foreach my $parameter (@{$args{'parameterlist'}}) {
14121da177e4SLinus Torvalds	if ($parameter =~ /^#/) {
14131da177e4SLinus Torvalds	    print ".BI \"$parameter\"\n.br\n";
14141da177e4SLinus Torvalds	    next;
14151da177e4SLinus Torvalds	}
14161da177e4SLinus Torvalds	my $parameter_name = $parameter;
14171da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
14181da177e4SLinus Torvalds
14191da177e4SLinus Torvalds	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
14201da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
14211da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
14221da177e4SLinus Torvalds	    # pointer-to-function
14231da177e4SLinus Torvalds	    print ".BI \"    " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n";
14241da177e4SLinus Torvalds	} elsif ($type =~ m/^(.*?)\s*(:.*)/) {
14251d7e1d45SRandy.Dunlap	    # bitfield
14261d7e1d45SRandy.Dunlap	    print ".BI \"    " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n";
14271da177e4SLinus Torvalds	} else {
14281da177e4SLinus Torvalds	    $type =~ s/([^\*])$/$1 /;
14291da177e4SLinus Torvalds	    print ".BI \"    " . $type . "\" " . $parameter . " \"" . "\"\n;\n";
14301da177e4SLinus Torvalds	}
14311da177e4SLinus Torvalds	print "\n.br\n";
14321da177e4SLinus Torvalds    }
14331da177e4SLinus Torvalds    print "};\n.br\n";
14341da177e4SLinus Torvalds
1435c51d3dacSRandy Dunlap    print ".SH Members\n";
14361da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
14371da177e4SLinus Torvalds	($parameter =~ /^#/) && next;
14381da177e4SLinus Torvalds
14391da177e4SLinus Torvalds	my $parameter_name = $parameter;
14401da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
14411da177e4SLinus Torvalds
14421da177e4SLinus Torvalds	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
14431da177e4SLinus Torvalds	print ".IP \"" . $parameter . "\" 12\n";
14441da177e4SLinus Torvalds	output_highlight($args{'parameterdescs'}{$parameter_name});
14451da177e4SLinus Torvalds    }
14461da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
14471da177e4SLinus Torvalds	print ".SH \"$section\"\n";
14481da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
14491da177e4SLinus Torvalds    }
14501da177e4SLinus Torvalds}
14511da177e4SLinus Torvalds
14521da177e4SLinus Torvalds##
14531da177e4SLinus Torvalds# output typedef in man
14541da177e4SLinus Torvaldssub output_typedef_man(%) {
14551da177e4SLinus Torvalds    my %args = %{$_[0]};
14561da177e4SLinus Torvalds    my ($parameter, $section);
14571da177e4SLinus Torvalds
14581da177e4SLinus Torvalds    print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
14591da177e4SLinus Torvalds
14601da177e4SLinus Torvalds    print ".SH NAME\n";
14611da177e4SLinus Torvalds    print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
14621da177e4SLinus Torvalds
14631da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
14641da177e4SLinus Torvalds	print ".SH \"$section\"\n";
14651da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
14661da177e4SLinus Torvalds    }
14671da177e4SLinus Torvalds}
14681da177e4SLinus Torvalds
1469b112e0f7SJohannes Bergsub output_blockhead_man(%) {
14701da177e4SLinus Torvalds    my %args = %{$_[0]};
14711da177e4SLinus Torvalds    my ($parameter, $section);
14721da177e4SLinus Torvalds    my $count;
14731da177e4SLinus Torvalds
14741da177e4SLinus Torvalds    print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
14751da177e4SLinus Torvalds
14761da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
14771da177e4SLinus Torvalds	print ".SH \"$section\"\n";
14781da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
14791da177e4SLinus Torvalds    }
14801da177e4SLinus Torvalds}
14811da177e4SLinus Torvalds
14821da177e4SLinus Torvalds##
14831da177e4SLinus Torvalds# output in text
14841da177e4SLinus Torvaldssub output_function_text(%) {
14851da177e4SLinus Torvalds    my %args = %{$_[0]};
14861da177e4SLinus Torvalds    my ($parameter, $section);
1487a21217daSRandy Dunlap    my $start;
14881da177e4SLinus Torvalds
1489f47634b2SRandy Dunlap    print "Name:\n\n";
1490f47634b2SRandy Dunlap    print $args{'function'} . " - " . $args{'purpose'} . "\n";
1491f47634b2SRandy Dunlap
1492f47634b2SRandy Dunlap    print "\nSynopsis:\n\n";
1493a21217daSRandy Dunlap    if ($args{'functiontype'} ne "") {
1494a21217daSRandy Dunlap	$start = $args{'functiontype'} . " " . $args{'function'} . " (";
1495a21217daSRandy Dunlap    } else {
1496a21217daSRandy Dunlap	$start = $args{'function'} . " (";
1497a21217daSRandy Dunlap    }
14981da177e4SLinus Torvalds    print $start;
1499a21217daSRandy Dunlap
15001da177e4SLinus Torvalds    my $count = 0;
15011da177e4SLinus Torvalds    foreach my $parameter (@{$args{'parameterlist'}}) {
15021da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
15031da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
15041da177e4SLinus Torvalds	    # pointer-to-function
15051da177e4SLinus Torvalds	    print $1 . $parameter . ") (" . $2;
15061da177e4SLinus Torvalds	} else {
15071da177e4SLinus Torvalds	    print $type . " " . $parameter;
15081da177e4SLinus Torvalds	}
15091da177e4SLinus Torvalds	if ($count != $#{$args{'parameterlist'}}) {
15101da177e4SLinus Torvalds	    $count++;
15111da177e4SLinus Torvalds	    print ",\n";
15121da177e4SLinus Torvalds	    print " " x length($start);
15131da177e4SLinus Torvalds	} else {
15141da177e4SLinus Torvalds	    print ");\n\n";
15151da177e4SLinus Torvalds	}
15161da177e4SLinus Torvalds    }
15171da177e4SLinus Torvalds
15181da177e4SLinus Torvalds    print "Arguments:\n\n";
15191da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
15201da177e4SLinus Torvalds	my $parameter_name = $parameter;
15211da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
15221da177e4SLinus Torvalds
15231da177e4SLinus Torvalds	print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n";
15241da177e4SLinus Torvalds    }
15251da177e4SLinus Torvalds    output_section_text(@_);
15261da177e4SLinus Torvalds}
15271da177e4SLinus Torvalds
15281da177e4SLinus Torvalds#output sections in text
15291da177e4SLinus Torvaldssub output_section_text(%) {
15301da177e4SLinus Torvalds    my %args = %{$_[0]};
15311da177e4SLinus Torvalds    my $section;
15321da177e4SLinus Torvalds
15331da177e4SLinus Torvalds    print "\n";
15341da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
15351da177e4SLinus Torvalds	print "$section:\n\n";
15361da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
15371da177e4SLinus Torvalds    }
15381da177e4SLinus Torvalds    print "\n\n";
15391da177e4SLinus Torvalds}
15401da177e4SLinus Torvalds
15411da177e4SLinus Torvalds# output enum in text
15421da177e4SLinus Torvaldssub output_enum_text(%) {
15431da177e4SLinus Torvalds    my %args = %{$_[0]};
15441da177e4SLinus Torvalds    my ($parameter);
15451da177e4SLinus Torvalds    my $count;
15461da177e4SLinus Torvalds    print "Enum:\n\n";
15471da177e4SLinus Torvalds
15481d7e1d45SRandy.Dunlap    print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n";
15491da177e4SLinus Torvalds    print "enum " . $args{'enum'} . " {\n";
15501da177e4SLinus Torvalds    $count = 0;
15511da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
15521da177e4SLinus Torvalds	print "\t$parameter";
15531da177e4SLinus Torvalds	if ($count != $#{$args{'parameterlist'}}) {
15541da177e4SLinus Torvalds	    $count++;
15551da177e4SLinus Torvalds	    print ",";
15561da177e4SLinus Torvalds	}
15571da177e4SLinus Torvalds	print "\n";
15581da177e4SLinus Torvalds    }
15591da177e4SLinus Torvalds    print "};\n\n";
15601da177e4SLinus Torvalds
15611da177e4SLinus Torvalds    print "Constants:\n\n";
15621da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
15631da177e4SLinus Torvalds	print "$parameter\n\t";
15641da177e4SLinus Torvalds	print $args{'parameterdescs'}{$parameter} . "\n";
15651da177e4SLinus Torvalds    }
15661da177e4SLinus Torvalds
15671da177e4SLinus Torvalds    output_section_text(@_);
15681da177e4SLinus Torvalds}
15691da177e4SLinus Torvalds
15701da177e4SLinus Torvalds# output typedef in text
15711da177e4SLinus Torvaldssub output_typedef_text(%) {
15721da177e4SLinus Torvalds    my %args = %{$_[0]};
15731da177e4SLinus Torvalds    my ($parameter);
15741da177e4SLinus Torvalds    my $count;
15751da177e4SLinus Torvalds    print "Typedef:\n\n";
15761da177e4SLinus Torvalds
15771d7e1d45SRandy.Dunlap    print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n";
15781da177e4SLinus Torvalds    output_section_text(@_);
15791da177e4SLinus Torvalds}
15801da177e4SLinus Torvalds
15811da177e4SLinus Torvalds# output struct as text
15821da177e4SLinus Torvaldssub output_struct_text(%) {
15831da177e4SLinus Torvalds    my %args = %{$_[0]};
15841da177e4SLinus Torvalds    my ($parameter);
15851da177e4SLinus Torvalds
15861d7e1d45SRandy.Dunlap    print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n";
15871da177e4SLinus Torvalds    print $args{'type'} . " " . $args{'struct'} . " {\n";
15881da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
15891da177e4SLinus Torvalds	if ($parameter =~ /^#/) {
15901da177e4SLinus Torvalds	    print "$parameter\n";
15911da177e4SLinus Torvalds	    next;
15921da177e4SLinus Torvalds	}
15931da177e4SLinus Torvalds
15941da177e4SLinus Torvalds	my $parameter_name = $parameter;
15951da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
15961da177e4SLinus Torvalds
15971da177e4SLinus Torvalds	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
15981da177e4SLinus Torvalds	$type = $args{'parametertypes'}{$parameter};
15991da177e4SLinus Torvalds	if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
16001da177e4SLinus Torvalds	    # pointer-to-function
16011da177e4SLinus Torvalds	    print "\t$1 $parameter) ($2);\n";
16021da177e4SLinus Torvalds	} elsif ($type =~ m/^(.*?)\s*(:.*)/) {
160351f5a0c8SRandy Dunlap	    # bitfield
16041da177e4SLinus Torvalds	    print "\t$1 $parameter$2;\n";
16051da177e4SLinus Torvalds	} else {
16061da177e4SLinus Torvalds	    print "\t" . $type . " " . $parameter . ";\n";
16071da177e4SLinus Torvalds	}
16081da177e4SLinus Torvalds    }
16091da177e4SLinus Torvalds    print "};\n\n";
16101da177e4SLinus Torvalds
16111da177e4SLinus Torvalds    print "Members:\n\n";
16121da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
16131da177e4SLinus Torvalds	($parameter =~ /^#/) && next;
16141da177e4SLinus Torvalds
16151da177e4SLinus Torvalds	my $parameter_name = $parameter;
16161da177e4SLinus Torvalds	$parameter_name =~ s/\[.*//;
16171da177e4SLinus Torvalds
16181da177e4SLinus Torvalds	($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
16191da177e4SLinus Torvalds	print "$parameter\n\t";
16201da177e4SLinus Torvalds	print $args{'parameterdescs'}{$parameter_name} . "\n";
16211da177e4SLinus Torvalds    }
16221da177e4SLinus Torvalds    print "\n";
16231da177e4SLinus Torvalds    output_section_text(@_);
16241da177e4SLinus Torvalds}
16251da177e4SLinus Torvalds
1626b112e0f7SJohannes Bergsub output_blockhead_text(%) {
16271da177e4SLinus Torvalds    my %args = %{$_[0]};
16281da177e4SLinus Torvalds    my ($parameter, $section);
16291da177e4SLinus Torvalds
16301da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
16311da177e4SLinus Torvalds	print " $section:\n";
16321da177e4SLinus Torvalds	print "    -> ";
16331da177e4SLinus Torvalds	output_highlight($args{'sections'}{$section});
16341da177e4SLinus Torvalds    }
16351da177e4SLinus Torvalds}
16361da177e4SLinus Torvalds
1637eda603f6SJohannes Berg## list mode output functions
1638eda603f6SJohannes Berg
1639eda603f6SJohannes Bergsub output_function_list(%) {
1640eda603f6SJohannes Berg    my %args = %{$_[0]};
1641eda603f6SJohannes Berg
1642eda603f6SJohannes Berg    print $args{'function'} . "\n";
1643eda603f6SJohannes Berg}
1644eda603f6SJohannes Berg
1645eda603f6SJohannes Berg# output enum in list
1646eda603f6SJohannes Bergsub output_enum_list(%) {
1647eda603f6SJohannes Berg    my %args = %{$_[0]};
1648eda603f6SJohannes Berg    print $args{'enum'} . "\n";
1649eda603f6SJohannes Berg}
1650eda603f6SJohannes Berg
1651eda603f6SJohannes Berg# output typedef in list
1652eda603f6SJohannes Bergsub output_typedef_list(%) {
1653eda603f6SJohannes Berg    my %args = %{$_[0]};
1654eda603f6SJohannes Berg    print $args{'typedef'} . "\n";
1655eda603f6SJohannes Berg}
1656eda603f6SJohannes Berg
1657eda603f6SJohannes Berg# output struct as list
1658eda603f6SJohannes Bergsub output_struct_list(%) {
1659eda603f6SJohannes Berg    my %args = %{$_[0]};
1660eda603f6SJohannes Berg
1661eda603f6SJohannes Berg    print $args{'struct'} . "\n";
1662eda603f6SJohannes Berg}
1663eda603f6SJohannes Berg
1664eda603f6SJohannes Bergsub output_blockhead_list(%) {
1665eda603f6SJohannes Berg    my %args = %{$_[0]};
1666eda603f6SJohannes Berg    my ($parameter, $section);
1667eda603f6SJohannes Berg
1668eda603f6SJohannes Berg    foreach $section (@{$args{'sectionlist'}}) {
1669eda603f6SJohannes Berg	print "DOC: $section\n";
1670eda603f6SJohannes Berg    }
1671eda603f6SJohannes Berg}
1672eda603f6SJohannes Berg
16731da177e4SLinus Torvalds##
167427205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum);
167527205744SRandy Dunlap# calls the generated, variable output_ function name based on
167627205744SRandy Dunlap# functype and output_mode
16771da177e4SLinus Torvaldssub output_declaration {
16781da177e4SLinus Torvalds    no strict 'refs';
16791da177e4SLinus Torvalds    my $name = shift;
16801da177e4SLinus Torvalds    my $functype = shift;
16811da177e4SLinus Torvalds    my $func = "output_${functype}_$output_mode";
16821da177e4SLinus Torvalds    if (($function_only==0) ||
16831da177e4SLinus Torvalds	( $function_only == 1 && defined($function_table{$name})) ||
16841da177e4SLinus Torvalds	( $function_only == 2 && !defined($function_table{$name})))
16851da177e4SLinus Torvalds    {
16861da177e4SLinus Torvalds	&$func(@_);
16871da177e4SLinus Torvalds	$section_counter++;
16881da177e4SLinus Torvalds    }
16891da177e4SLinus Torvalds}
16901da177e4SLinus Torvalds
16911da177e4SLinus Torvalds##
169227205744SRandy Dunlap# generic output function - calls the right one based on current output mode.
1693b112e0f7SJohannes Bergsub output_blockhead {
16941da177e4SLinus Torvalds    no strict 'refs';
1695b112e0f7SJohannes Berg    my $func = "output_blockhead_" . $output_mode;
16961da177e4SLinus Torvalds    &$func(@_);
16971da177e4SLinus Torvalds    $section_counter++;
16981da177e4SLinus Torvalds}
16991da177e4SLinus Torvalds
17001da177e4SLinus Torvalds##
17011da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and
17021da177e4SLinus Torvalds# invokes the right handler. NOT called for functions.
17031da177e4SLinus Torvaldssub dump_declaration($$) {
17041da177e4SLinus Torvalds    no strict 'refs';
17051da177e4SLinus Torvalds    my ($prototype, $file) = @_;
17061da177e4SLinus Torvalds    my $func = "dump_" . $decl_type;
17071da177e4SLinus Torvalds    &$func(@_);
17081da177e4SLinus Torvalds}
17091da177e4SLinus Torvalds
17101da177e4SLinus Torvaldssub dump_union($$) {
17111da177e4SLinus Torvalds    dump_struct(@_);
17121da177e4SLinus Torvalds}
17131da177e4SLinus Torvalds
17141da177e4SLinus Torvaldssub dump_struct($$) {
17151da177e4SLinus Torvalds    my $x = shift;
17161da177e4SLinus Torvalds    my $file = shift;
1717a1d94aa5SRandy Dunlap    my $nested;
17181da177e4SLinus Torvalds
17191da177e4SLinus Torvalds    if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) {
172052dc5aecSRandy Dunlap	#my $decl_type = $1;
17211da177e4SLinus Torvalds	$declaration_name = $2;
17221da177e4SLinus Torvalds	my $members = $3;
17231da177e4SLinus Torvalds
17241da177e4SLinus Torvalds	# ignore embedded structs or unions
1725a1d94aa5SRandy Dunlap	$members =~ s/({.*})//g;
1726a1d94aa5SRandy Dunlap	$nested = $1;
17271da177e4SLinus Torvalds
1728aeec46b9SMartin Waitz	# ignore members marked private:
172952dc5aecSRandy Dunlap	$members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gos;
173052dc5aecSRandy Dunlap	$members =~ s/\/\*\s*private:.*//gos;
1731aeec46b9SMartin Waitz	# strip comments:
1732aeec46b9SMartin Waitz	$members =~ s/\/\*.*?\*\///gos;
1733a1d94aa5SRandy Dunlap	$nested =~ s/\/\*.*?\*\///gos;
1734d960eea9SRandy Dunlap	# strip kmemcheck_bitfield_{begin,end}.*;
1735d960eea9SRandy Dunlap	$members =~ s/kmemcheck_bitfield_.*?;//gos;
1736ef5da59fSRandy Dunlap	# strip attributes
1737ef5da59fSRandy Dunlap	$members =~ s/__aligned\s*\(\d+\)//gos;
1738aeec46b9SMartin Waitz
17391da177e4SLinus Torvalds	create_parameterlist($members, ';', $file);
1740a1d94aa5SRandy Dunlap	check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested);
17411da177e4SLinus Torvalds
17421da177e4SLinus Torvalds	output_declaration($declaration_name,
17431da177e4SLinus Torvalds			   'struct',
17441da177e4SLinus Torvalds			   {'struct' => $declaration_name,
17451da177e4SLinus Torvalds			    'module' => $modulename,
17461da177e4SLinus Torvalds			    'parameterlist' => \@parameterlist,
17471da177e4SLinus Torvalds			    'parameterdescs' => \%parameterdescs,
17481da177e4SLinus Torvalds			    'parametertypes' => \%parametertypes,
17491da177e4SLinus Torvalds			    'sectionlist' => \@sectionlist,
17501da177e4SLinus Torvalds			    'sections' => \%sections,
17511da177e4SLinus Torvalds			    'purpose' => $declaration_purpose,
17521da177e4SLinus Torvalds			    'type' => $decl_type
17531da177e4SLinus Torvalds			   });
17541da177e4SLinus Torvalds    }
17551da177e4SLinus Torvalds    else {
17561da177e4SLinus Torvalds	print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
17571da177e4SLinus Torvalds	++$errors;
17581da177e4SLinus Torvalds    }
17591da177e4SLinus Torvalds}
17601da177e4SLinus Torvalds
17611da177e4SLinus Torvaldssub dump_enum($$) {
17621da177e4SLinus Torvalds    my $x = shift;
17631da177e4SLinus Torvalds    my $file = shift;
17641da177e4SLinus Torvalds
1765aeec46b9SMartin Waitz    $x =~ s@/\*.*?\*/@@gos;	# strip comments.
1766b6d676dbSRandy Dunlap    $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums
1767b6d676dbSRandy Dunlap
17681da177e4SLinus Torvalds    if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
17691da177e4SLinus Torvalds	$declaration_name = $1;
17701da177e4SLinus Torvalds	my $members = $2;
17711da177e4SLinus Torvalds
17721da177e4SLinus Torvalds	foreach my $arg (split ',', $members) {
17731da177e4SLinus Torvalds	    $arg =~ s/^\s*(\w+).*/$1/;
17741da177e4SLinus Torvalds	    push @parameterlist, $arg;
17751da177e4SLinus Torvalds	    if (!$parameterdescs{$arg}) {
17761da177e4SLinus Torvalds		$parameterdescs{$arg} = $undescribed;
17771da177e4SLinus Torvalds		print STDERR "Warning(${file}:$.): Enum value '$arg' ".
17781da177e4SLinus Torvalds		    "not described in enum '$declaration_name'\n";
17791da177e4SLinus Torvalds	    }
17801da177e4SLinus Torvalds
17811da177e4SLinus Torvalds	}
17821da177e4SLinus Torvalds
17831da177e4SLinus Torvalds	output_declaration($declaration_name,
17841da177e4SLinus Torvalds			   'enum',
17851da177e4SLinus Torvalds			   {'enum' => $declaration_name,
17861da177e4SLinus Torvalds			    'module' => $modulename,
17871da177e4SLinus Torvalds			    'parameterlist' => \@parameterlist,
17881da177e4SLinus Torvalds			    'parameterdescs' => \%parameterdescs,
17891da177e4SLinus Torvalds			    'sectionlist' => \@sectionlist,
17901da177e4SLinus Torvalds			    'sections' => \%sections,
17911da177e4SLinus Torvalds			    'purpose' => $declaration_purpose
17921da177e4SLinus Torvalds			   });
17931da177e4SLinus Torvalds    }
17941da177e4SLinus Torvalds    else {
17951da177e4SLinus Torvalds	print STDERR "Error(${file}:$.): Cannot parse enum!\n";
17961da177e4SLinus Torvalds	++$errors;
17971da177e4SLinus Torvalds    }
17981da177e4SLinus Torvalds}
17991da177e4SLinus Torvalds
18001da177e4SLinus Torvaldssub dump_typedef($$) {
18011da177e4SLinus Torvalds    my $x = shift;
18021da177e4SLinus Torvalds    my $file = shift;
18031da177e4SLinus Torvalds
1804aeec46b9SMartin Waitz    $x =~ s@/\*.*?\*/@@gos;	# strip comments.
18051da177e4SLinus Torvalds    while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
18061da177e4SLinus Torvalds	$x =~ s/\(*.\)\s*;$/;/;
18071da177e4SLinus Torvalds	$x =~ s/\[*.\]\s*;$/;/;
18081da177e4SLinus Torvalds    }
18091da177e4SLinus Torvalds
18101da177e4SLinus Torvalds    if ($x =~ /typedef.*\s+(\w+)\s*;/) {
18111da177e4SLinus Torvalds	$declaration_name = $1;
18121da177e4SLinus Torvalds
18131da177e4SLinus Torvalds	output_declaration($declaration_name,
18141da177e4SLinus Torvalds			   'typedef',
18151da177e4SLinus Torvalds			   {'typedef' => $declaration_name,
18161da177e4SLinus Torvalds			    'module' => $modulename,
18171da177e4SLinus Torvalds			    'sectionlist' => \@sectionlist,
18181da177e4SLinus Torvalds			    'sections' => \%sections,
18191da177e4SLinus Torvalds			    'purpose' => $declaration_purpose
18201da177e4SLinus Torvalds			   });
18211da177e4SLinus Torvalds    }
18221da177e4SLinus Torvalds    else {
18231da177e4SLinus Torvalds	print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
18241da177e4SLinus Torvalds	++$errors;
18251da177e4SLinus Torvalds    }
18261da177e4SLinus Torvalds}
18271da177e4SLinus Torvalds
1828a1d94aa5SRandy Dunlapsub save_struct_actual($) {
1829a1d94aa5SRandy Dunlap    my $actual = shift;
1830a1d94aa5SRandy Dunlap
1831a1d94aa5SRandy Dunlap    # strip all spaces from the actual param so that it looks like one string item
1832a1d94aa5SRandy Dunlap    $actual =~ s/\s*//g;
1833a1d94aa5SRandy Dunlap    $struct_actual = $struct_actual . $actual . " ";
1834a1d94aa5SRandy Dunlap}
1835a1d94aa5SRandy Dunlap
18361da177e4SLinus Torvaldssub create_parameterlist($$$) {
18371da177e4SLinus Torvalds    my $args = shift;
18381da177e4SLinus Torvalds    my $splitter = shift;
18391da177e4SLinus Torvalds    my $file = shift;
18401da177e4SLinus Torvalds    my $type;
18411da177e4SLinus Torvalds    my $param;
18421da177e4SLinus Torvalds
1843a6d3fe77SMartin Waitz    # temporarily replace commas inside function pointer definition
18441da177e4SLinus Torvalds    while ($args =~ /(\([^\),]+),/) {
18451da177e4SLinus Torvalds	$args =~ s/(\([^\),]+),/$1#/g;
18461da177e4SLinus Torvalds    }
18471da177e4SLinus Torvalds
18481da177e4SLinus Torvalds    foreach my $arg (split($splitter, $args)) {
18491da177e4SLinus Torvalds	# strip comments
18501da177e4SLinus Torvalds	$arg =~ s/\/\*.*\*\///;
18511da177e4SLinus Torvalds	# strip leading/trailing spaces
18521da177e4SLinus Torvalds	$arg =~ s/^\s*//;
18531da177e4SLinus Torvalds	$arg =~ s/\s*$//;
18541da177e4SLinus Torvalds	$arg =~ s/\s+/ /;
18551da177e4SLinus Torvalds
18561da177e4SLinus Torvalds	if ($arg =~ /^#/) {
18571da177e4SLinus Torvalds	    # Treat preprocessor directive as a typeless variable just to fill
18581da177e4SLinus Torvalds	    # corresponding data structures "correctly". Catch it later in
18591da177e4SLinus Torvalds	    # output_* subs.
18601da177e4SLinus Torvalds	    push_parameter($arg, "", $file);
186100d62961SRichard Kennedy	} elsif ($arg =~ m/\(.+\)\s*\(/) {
18621da177e4SLinus Torvalds	    # pointer-to-function
18631da177e4SLinus Torvalds	    $arg =~ tr/#/,/;
186400d62961SRichard Kennedy	    $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
18651da177e4SLinus Torvalds	    $param = $1;
18661da177e4SLinus Torvalds	    $type = $arg;
186700d62961SRichard Kennedy	    $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
1868a1d94aa5SRandy Dunlap	    save_struct_actual($param);
18691da177e4SLinus Torvalds	    push_parameter($param, $type, $file);
1870aeec46b9SMartin Waitz	} elsif ($arg) {
18711da177e4SLinus Torvalds	    $arg =~ s/\s*:\s*/:/g;
18721da177e4SLinus Torvalds	    $arg =~ s/\s*\[/\[/g;
18731da177e4SLinus Torvalds
18741da177e4SLinus Torvalds	    my @args = split('\s*,\s*', $arg);
18751da177e4SLinus Torvalds	    if ($args[0] =~ m/\*/) {
18761da177e4SLinus Torvalds		$args[0] =~ s/(\*+)\s*/ $1/;
18771da177e4SLinus Torvalds	    }
1878884f2810SBorislav Petkov
1879884f2810SBorislav Petkov	    my @first_arg;
1880884f2810SBorislav Petkov	    if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1881884f2810SBorislav Petkov		    shift @args;
1882884f2810SBorislav Petkov		    push(@first_arg, split('\s+', $1));
1883884f2810SBorislav Petkov		    push(@first_arg, $2);
1884884f2810SBorislav Petkov	    } else {
1885884f2810SBorislav Petkov		    @first_arg = split('\s+', shift @args);
1886884f2810SBorislav Petkov	    }
1887884f2810SBorislav Petkov
18881da177e4SLinus Torvalds	    unshift(@args, pop @first_arg);
18891da177e4SLinus Torvalds	    $type = join " ", @first_arg;
18901da177e4SLinus Torvalds
18911da177e4SLinus Torvalds	    foreach $param (@args) {
18921da177e4SLinus Torvalds		if ($param =~ m/^(\*+)\s*(.*)/) {
1893a1d94aa5SRandy Dunlap		    save_struct_actual($2);
18941da177e4SLinus Torvalds		    push_parameter($2, "$type $1", $file);
18951da177e4SLinus Torvalds		}
18961da177e4SLinus Torvalds		elsif ($param =~ m/(.*?):(\d+)/) {
18977b97887eSRandy Dunlap		    if ($type ne "") { # skip unnamed bit-fields
1898a1d94aa5SRandy Dunlap			save_struct_actual($1);
18991da177e4SLinus Torvalds			push_parameter($1, "$type:$2", $file)
19001da177e4SLinus Torvalds		    }
19017b97887eSRandy Dunlap		}
19021da177e4SLinus Torvalds		else {
1903a1d94aa5SRandy Dunlap		    save_struct_actual($param);
19041da177e4SLinus Torvalds		    push_parameter($param, $type, $file);
19051da177e4SLinus Torvalds		}
19061da177e4SLinus Torvalds	    }
19071da177e4SLinus Torvalds	}
19081da177e4SLinus Torvalds    }
19091da177e4SLinus Torvalds}
19101da177e4SLinus Torvalds
19111da177e4SLinus Torvaldssub push_parameter($$$) {
19121da177e4SLinus Torvalds	my $param = shift;
19131da177e4SLinus Torvalds	my $type = shift;
19141da177e4SLinus Torvalds	my $file = shift;
19151da177e4SLinus Torvalds
19165f8c7c98SRandy Dunlap	if (($anon_struct_union == 1) && ($type eq "") &&
19175f8c7c98SRandy Dunlap	    ($param eq "}")) {
19185f8c7c98SRandy Dunlap		return;		# ignore the ending }; from anon. struct/union
19195f8c7c98SRandy Dunlap	}
19205f8c7c98SRandy Dunlap
19215f8c7c98SRandy Dunlap	$anon_struct_union = 0;
19221da177e4SLinus Torvalds	my $param_name = $param;
19231da177e4SLinus Torvalds	$param_name =~ s/\[.*//;
19241da177e4SLinus Torvalds
1925a6d3fe77SMartin Waitz	if ($type eq "" && $param =~ /\.\.\.$/)
19261da177e4SLinus Torvalds	{
1927ced69090SRandy Dunlap	    if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
1928a6d3fe77SMartin Waitz		$parameterdescs{$param} = "variable arguments";
19291da177e4SLinus Torvalds	    }
1930ced69090SRandy Dunlap	}
19311da177e4SLinus Torvalds	elsif ($type eq "" && ($param eq "" or $param eq "void"))
19321da177e4SLinus Torvalds	{
19331da177e4SLinus Torvalds	    $param="void";
19341da177e4SLinus Torvalds	    $parameterdescs{void} = "no arguments";
19351da177e4SLinus Torvalds	}
1936134fe01bSRandy Dunlap	elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1937134fe01bSRandy Dunlap	# handle unnamed (anonymous) union or struct:
1938134fe01bSRandy Dunlap	{
1939134fe01bSRandy Dunlap		$type = $param;
1940134fe01bSRandy Dunlap		$param = "{unnamed_" . $param . "}";
1941134fe01bSRandy Dunlap		$parameterdescs{$param} = "anonymous\n";
19425f8c7c98SRandy Dunlap		$anon_struct_union = 1;
1943134fe01bSRandy Dunlap	}
1944134fe01bSRandy Dunlap
1945a6d3fe77SMartin Waitz	# warn if parameter has no description
1946134fe01bSRandy Dunlap	# (but ignore ones starting with # as these are not parameters
1947134fe01bSRandy Dunlap	# but inline preprocessor statements);
1948134fe01bSRandy Dunlap	# also ignore unnamed structs/unions;
19495f8c7c98SRandy Dunlap	if (!$anon_struct_union) {
1950a6d3fe77SMartin Waitz	if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1951a6d3fe77SMartin Waitz
19521da177e4SLinus Torvalds	    $parameterdescs{$param_name} = $undescribed;
19531da177e4SLinus Torvalds
19541da177e4SLinus Torvalds	    if (($type eq 'function') || ($type eq 'enum')) {
19551da177e4SLinus Torvalds		print STDERR "Warning(${file}:$.): Function parameter ".
19561da177e4SLinus Torvalds		    "or member '$param' not " .
19571da177e4SLinus Torvalds		    "described in '$declaration_name'\n";
19581da177e4SLinus Torvalds	    }
19591da177e4SLinus Torvalds	    print STDERR "Warning(${file}:$.):" .
19601da177e4SLinus Torvalds			 " No description found for parameter '$param'\n";
19611da177e4SLinus Torvalds	    ++$warnings;
19621da177e4SLinus Torvalds	}
1963134fe01bSRandy Dunlap	}
19641da177e4SLinus Torvalds
19652b35f4d9SRandy Dunlap	$param = xml_escape($param);
19662b35f4d9SRandy Dunlap
196725985edcSLucas De Marchi	# strip spaces from $param so that it is one continuous string
1968e34e7dbbSRandy Dunlap	# on @parameterlist;
1969e34e7dbbSRandy Dunlap	# this fixes a problem where check_sections() cannot find
1970e34e7dbbSRandy Dunlap	# a parameter like "addr[6 + 2]" because it actually appears
1971e34e7dbbSRandy Dunlap	# as "addr[6", "+", "2]" on the parameter list;
1972e34e7dbbSRandy Dunlap	# but it's better to maintain the param string unchanged for output,
1973e34e7dbbSRandy Dunlap	# so just weaken the string compare in check_sections() to ignore
1974e34e7dbbSRandy Dunlap	# "[blah" in a parameter string;
1975e34e7dbbSRandy Dunlap	###$param =~ s/\s*//g;
19761da177e4SLinus Torvalds	push @parameterlist, $param;
19771da177e4SLinus Torvalds	$parametertypes{$param} = $type;
19781da177e4SLinus Torvalds}
19791da177e4SLinus Torvalds
1980a1d94aa5SRandy Dunlapsub check_sections($$$$$$) {
1981a1d94aa5SRandy Dunlap	my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_;
1982a1d94aa5SRandy Dunlap	my @sects = split ' ', $sectcheck;
1983a1d94aa5SRandy Dunlap	my @prms = split ' ', $prmscheck;
1984a1d94aa5SRandy Dunlap	my $err;
1985a1d94aa5SRandy Dunlap	my ($px, $sx);
1986a1d94aa5SRandy Dunlap	my $prm_clean;		# strip trailing "[array size]" and/or beginning "*"
1987a1d94aa5SRandy Dunlap
1988a1d94aa5SRandy Dunlap	foreach $sx (0 .. $#sects) {
1989a1d94aa5SRandy Dunlap		$err = 1;
1990a1d94aa5SRandy Dunlap		foreach $px (0 .. $#prms) {
1991a1d94aa5SRandy Dunlap			$prm_clean = $prms[$px];
1992a1d94aa5SRandy Dunlap			$prm_clean =~ s/\[.*\]//;
19931f3a6688SJohannes Berg			$prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i;
1994e34e7dbbSRandy Dunlap			# ignore array size in a parameter string;
1995e34e7dbbSRandy Dunlap			# however, the original param string may contain
1996e34e7dbbSRandy Dunlap			# spaces, e.g.:  addr[6 + 2]
1997e34e7dbbSRandy Dunlap			# and this appears in @prms as "addr[6" since the
1998e34e7dbbSRandy Dunlap			# parameter list is split at spaces;
1999e34e7dbbSRandy Dunlap			# hence just ignore "[..." for the sections check;
2000e34e7dbbSRandy Dunlap			$prm_clean =~ s/\[.*//;
2001e34e7dbbSRandy Dunlap
2002a1d94aa5SRandy Dunlap			##$prm_clean =~ s/^\**//;
2003a1d94aa5SRandy Dunlap			if ($prm_clean eq $sects[$sx]) {
2004a1d94aa5SRandy Dunlap				$err = 0;
2005a1d94aa5SRandy Dunlap				last;
2006a1d94aa5SRandy Dunlap			}
2007a1d94aa5SRandy Dunlap		}
2008a1d94aa5SRandy Dunlap		if ($err) {
2009a1d94aa5SRandy Dunlap			if ($decl_type eq "function") {
2010a1d94aa5SRandy Dunlap				print STDERR "Warning(${file}:$.): " .
2011a1d94aa5SRandy Dunlap					"Excess function parameter " .
2012a1d94aa5SRandy Dunlap					"'$sects[$sx]' " .
2013a1d94aa5SRandy Dunlap					"description in '$decl_name'\n";
2014a1d94aa5SRandy Dunlap				++$warnings;
2015a1d94aa5SRandy Dunlap			} else {
2016a1d94aa5SRandy Dunlap				if ($nested !~ m/\Q$sects[$sx]\E/) {
2017a1d94aa5SRandy Dunlap				    print STDERR "Warning(${file}:$.): " .
2018a1d94aa5SRandy Dunlap					"Excess struct/union/enum/typedef member " .
2019a1d94aa5SRandy Dunlap					"'$sects[$sx]' " .
2020a1d94aa5SRandy Dunlap					"description in '$decl_name'\n";
2021a1d94aa5SRandy Dunlap				    ++$warnings;
2022a1d94aa5SRandy Dunlap				}
2023a1d94aa5SRandy Dunlap			}
2024a1d94aa5SRandy Dunlap		}
2025a1d94aa5SRandy Dunlap	}
2026a1d94aa5SRandy Dunlap}
2027a1d94aa5SRandy Dunlap
20281da177e4SLinus Torvalds##
20291da177e4SLinus Torvalds# takes a function prototype and the name of the current file being
20301da177e4SLinus Torvalds# processed and spits out all the details stored in the global
20311da177e4SLinus Torvalds# arrays/hashes.
20321da177e4SLinus Torvaldssub dump_function($$) {
20331da177e4SLinus Torvalds    my $prototype = shift;
20341da177e4SLinus Torvalds    my $file = shift;
20351da177e4SLinus Torvalds
20361da177e4SLinus Torvalds    $prototype =~ s/^static +//;
20371da177e4SLinus Torvalds    $prototype =~ s/^extern +//;
20384dc3b16bSPavel Pisa    $prototype =~ s/^asmlinkage +//;
20391da177e4SLinus Torvalds    $prototype =~ s/^inline +//;
20401da177e4SLinus Torvalds    $prototype =~ s/^__inline__ +//;
204132e79401SRandy Dunlap    $prototype =~ s/^__inline +//;
204232e79401SRandy Dunlap    $prototype =~ s/^__always_inline +//;
204332e79401SRandy Dunlap    $prototype =~ s/^noinline +//;
20440129a057SRandy Dunlap    $prototype =~ s/__devinit +//;
204574fc5c65SRandy Dunlap    $prototype =~ s/__init +//;
204620072205SRandy Dunlap    $prototype =~ s/__init_or_module +//;
204770c95b00SRandy Dunlap    $prototype =~ s/__must_check +//;
2048890c78c2SRandy Dunlap    $prototype =~ s/^#\s*define\s+//; #ak added
2049328d2440SRandy Dunlap    $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
20501da177e4SLinus Torvalds
20511da177e4SLinus Torvalds    # Yes, this truly is vile.  We are looking for:
20521da177e4SLinus Torvalds    # 1. Return type (may be nothing if we're looking at a macro)
20531da177e4SLinus Torvalds    # 2. Function name
20541da177e4SLinus Torvalds    # 3. Function parameters.
20551da177e4SLinus Torvalds    #
20561da177e4SLinus Torvalds    # All the while we have to watch out for function pointer parameters
20571da177e4SLinus Torvalds    # (which IIRC is what the two sections are for), C types (these
20581da177e4SLinus Torvalds    # regexps don't even start to express all the possibilities), and
20591da177e4SLinus Torvalds    # so on.
20601da177e4SLinus Torvalds    #
20611da177e4SLinus Torvalds    # If you mess with these regexps, it's a good idea to check that
20621da177e4SLinus Torvalds    # the following functions' documentation still comes out right:
20631da177e4SLinus Torvalds    # - parport_register_device (function pointer parameters)
20641da177e4SLinus Torvalds    # - atomic_set (macro)
20659598f91fSMartin Waitz    # - pci_match_device, __copy_to_user (long return type)
20661da177e4SLinus Torvalds
20671da177e4SLinus Torvalds    if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
20681da177e4SLinus Torvalds	$prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
20691da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
20701da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
207194b3e03cSRandy Dunlap	$prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
20721da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
20731da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
20741da177e4SLinus Torvalds	$prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
20751da177e4SLinus Torvalds	$prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
20761da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
20771da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
20781da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
20791da177e4SLinus Torvalds	$prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
20809598f91fSMartin Waitz	$prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
20819598f91fSMartin Waitz	$prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2082412ecd77SRandy Dunlap	$prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
2083412ecd77SRandy Dunlap	$prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/)  {
20841da177e4SLinus Torvalds	$return_type = $1;
20851da177e4SLinus Torvalds	$declaration_name = $2;
20861da177e4SLinus Torvalds	my $args = $3;
20871da177e4SLinus Torvalds
20881da177e4SLinus Torvalds	create_parameterlist($args, ',', $file);
20891da177e4SLinus Torvalds    } else {
20901da177e4SLinus Torvalds	print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
20911da177e4SLinus Torvalds	++$errors;
20921da177e4SLinus Torvalds	return;
20931da177e4SLinus Torvalds    }
20941da177e4SLinus Torvalds
2095a1d94aa5SRandy Dunlap	my $prms = join " ", @parameterlist;
2096a1d94aa5SRandy Dunlap	check_sections($file, $declaration_name, "function", $sectcheck, $prms, "");
2097a1d94aa5SRandy Dunlap
20981da177e4SLinus Torvalds    output_declaration($declaration_name,
20991da177e4SLinus Torvalds		       'function',
21001da177e4SLinus Torvalds		       {'function' => $declaration_name,
21011da177e4SLinus Torvalds			'module' => $modulename,
21021da177e4SLinus Torvalds			'functiontype' => $return_type,
21031da177e4SLinus Torvalds			'parameterlist' => \@parameterlist,
21041da177e4SLinus Torvalds			'parameterdescs' => \%parameterdescs,
21051da177e4SLinus Torvalds			'parametertypes' => \%parametertypes,
21061da177e4SLinus Torvalds			'sectionlist' => \@sectionlist,
21071da177e4SLinus Torvalds			'sections' => \%sections,
21081da177e4SLinus Torvalds			'purpose' => $declaration_purpose
21091da177e4SLinus Torvalds		       });
21101da177e4SLinus Torvalds}
21111da177e4SLinus Torvalds
21121da177e4SLinus Torvaldssub reset_state {
21131da177e4SLinus Torvalds    $function = "";
21141da177e4SLinus Torvalds    %constants = ();
21151da177e4SLinus Torvalds    %parameterdescs = ();
21161da177e4SLinus Torvalds    %parametertypes = ();
21171da177e4SLinus Torvalds    @parameterlist = ();
21181da177e4SLinus Torvalds    %sections = ();
21191da177e4SLinus Torvalds    @sectionlist = ();
2120a1d94aa5SRandy Dunlap    $sectcheck = "";
2121a1d94aa5SRandy Dunlap    $struct_actual = "";
21221da177e4SLinus Torvalds    $prototype = "";
21231da177e4SLinus Torvalds
21241da177e4SLinus Torvalds    $state = 0;
21251da177e4SLinus Torvalds}
21261da177e4SLinus Torvalds
212756afb0f8SJason Baronsub tracepoint_munge($) {
212856afb0f8SJason Baron	my $file = shift;
212956afb0f8SJason Baron	my $tracepointname = 0;
213056afb0f8SJason Baron	my $tracepointargs = 0;
213156afb0f8SJason Baron
213256afb0f8SJason Baron	if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
213356afb0f8SJason Baron		$tracepointname = $1;
213456afb0f8SJason Baron	}
21353a9089fdSJason Baron	if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
21363a9089fdSJason Baron		$tracepointname = $1;
21373a9089fdSJason Baron	}
21383a9089fdSJason Baron	if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
21393a9089fdSJason Baron		$tracepointname = $2;
21403a9089fdSJason Baron	}
21413a9089fdSJason Baron	$tracepointname =~ s/^\s+//; #strip leading whitespace
214256afb0f8SJason Baron	if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
214356afb0f8SJason Baron		$tracepointargs = $1;
214456afb0f8SJason Baron	}
214556afb0f8SJason Baron	if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
214656afb0f8SJason Baron		print STDERR "Warning(${file}:$.): Unrecognized tracepoint format: \n".
214756afb0f8SJason Baron			     "$prototype\n";
214856afb0f8SJason Baron	} else {
214956afb0f8SJason Baron		$prototype = "static inline void trace_$tracepointname($tracepointargs)";
215056afb0f8SJason Baron	}
215156afb0f8SJason Baron}
215256afb0f8SJason Baron
2153b4870bc5SRandy Dunlapsub syscall_munge() {
2154b4870bc5SRandy Dunlap	my $void = 0;
2155b4870bc5SRandy Dunlap
2156b4870bc5SRandy Dunlap	$prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs
2157b4870bc5SRandy Dunlap##	if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
2158b4870bc5SRandy Dunlap	if ($prototype =~ m/SYSCALL_DEFINE0/) {
2159b4870bc5SRandy Dunlap		$void = 1;
2160b4870bc5SRandy Dunlap##		$prototype = "long sys_$1(void)";
2161b4870bc5SRandy Dunlap	}
2162b4870bc5SRandy Dunlap
2163b4870bc5SRandy Dunlap	$prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
2164b4870bc5SRandy Dunlap	if ($prototype =~ m/long (sys_.*?),/) {
2165b4870bc5SRandy Dunlap		$prototype =~ s/,/\(/;
2166b4870bc5SRandy Dunlap	} elsif ($void) {
2167b4870bc5SRandy Dunlap		$prototype =~ s/\)/\(void\)/;
2168b4870bc5SRandy Dunlap	}
2169b4870bc5SRandy Dunlap
2170b4870bc5SRandy Dunlap	# now delete all of the odd-number commas in $prototype
2171b4870bc5SRandy Dunlap	# so that arg types & arg names don't have a comma between them
2172b4870bc5SRandy Dunlap	my $count = 0;
2173b4870bc5SRandy Dunlap	my $len = length($prototype);
2174b4870bc5SRandy Dunlap	if ($void) {
2175b4870bc5SRandy Dunlap		$len = 0;	# skip the for-loop
2176b4870bc5SRandy Dunlap	}
2177b4870bc5SRandy Dunlap	for (my $ix = 0; $ix < $len; $ix++) {
2178b4870bc5SRandy Dunlap		if (substr($prototype, $ix, 1) eq ',') {
2179b4870bc5SRandy Dunlap			$count++;
2180b4870bc5SRandy Dunlap			if ($count % 2 == 1) {
2181b4870bc5SRandy Dunlap				substr($prototype, $ix, 1) = ' ';
2182b4870bc5SRandy Dunlap			}
2183b4870bc5SRandy Dunlap		}
2184b4870bc5SRandy Dunlap	}
2185b4870bc5SRandy Dunlap}
2186b4870bc5SRandy Dunlap
21871da177e4SLinus Torvaldssub process_state3_function($$) {
21881da177e4SLinus Torvalds    my $x = shift;
21891da177e4SLinus Torvalds    my $file = shift;
21901da177e4SLinus Torvalds
219151f5a0c8SRandy Dunlap    $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
219251f5a0c8SRandy Dunlap
2193890c78c2SRandy Dunlap    if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) {
21941da177e4SLinus Torvalds	# do nothing
21951da177e4SLinus Torvalds    }
21961da177e4SLinus Torvalds    elsif ($x =~ /([^\{]*)/) {
21971da177e4SLinus Torvalds	$prototype .= $1;
21981da177e4SLinus Torvalds    }
2199b4870bc5SRandy Dunlap
2200890c78c2SRandy Dunlap    if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
22011da177e4SLinus Torvalds	$prototype =~ s@/\*.*?\*/@@gos;	# strip comments.
22021da177e4SLinus Torvalds	$prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
22031da177e4SLinus Torvalds	$prototype =~ s@^\s+@@gos; # strip leading spaces
2204b4870bc5SRandy Dunlap	if ($prototype =~ /SYSCALL_DEFINE/) {
2205b4870bc5SRandy Dunlap		syscall_munge();
2206b4870bc5SRandy Dunlap	}
22073a9089fdSJason Baron	if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
22083a9089fdSJason Baron	    $prototype =~ /DEFINE_SINGLE_EVENT/)
22093a9089fdSJason Baron	{
221056afb0f8SJason Baron		tracepoint_munge($file);
221156afb0f8SJason Baron	}
22121da177e4SLinus Torvalds	dump_function($prototype, $file);
22131da177e4SLinus Torvalds	reset_state();
22141da177e4SLinus Torvalds    }
22151da177e4SLinus Torvalds}
22161da177e4SLinus Torvalds
22171da177e4SLinus Torvaldssub process_state3_type($$) {
22181da177e4SLinus Torvalds    my $x = shift;
22191da177e4SLinus Torvalds    my $file = shift;
22201da177e4SLinus Torvalds
22211da177e4SLinus Torvalds    $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
22221da177e4SLinus Torvalds    $x =~ s@^\s+@@gos; # strip leading spaces
22231da177e4SLinus Torvalds    $x =~ s@\s+$@@gos; # strip trailing spaces
222451f5a0c8SRandy Dunlap    $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
222551f5a0c8SRandy Dunlap
22261da177e4SLinus Torvalds    if ($x =~ /^#/) {
22271da177e4SLinus Torvalds	# To distinguish preprocessor directive from regular declaration later.
22281da177e4SLinus Torvalds	$x .= ";";
22291da177e4SLinus Torvalds    }
22301da177e4SLinus Torvalds
22311da177e4SLinus Torvalds    while (1) {
22321da177e4SLinus Torvalds	if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
22331da177e4SLinus Torvalds	    $prototype .= $1 . $2;
22341da177e4SLinus Torvalds	    ($2 eq '{') && $brcount++;
22351da177e4SLinus Torvalds	    ($2 eq '}') && $brcount--;
22361da177e4SLinus Torvalds	    if (($2 eq ';') && ($brcount == 0)) {
22371da177e4SLinus Torvalds		dump_declaration($prototype, $file);
22381da177e4SLinus Torvalds		reset_state();
22391da177e4SLinus Torvalds		last;
22401da177e4SLinus Torvalds	    }
22411da177e4SLinus Torvalds	    $x = $3;
22421da177e4SLinus Torvalds	} else {
22431da177e4SLinus Torvalds	    $prototype .= $x;
22441da177e4SLinus Torvalds	    last;
22451da177e4SLinus Torvalds	}
22461da177e4SLinus Torvalds    }
22471da177e4SLinus Torvalds}
22481da177e4SLinus Torvalds
22496b5b55f6SRandy Dunlap# xml_escape: replace <, >, and & in the text stream;
22506b5b55f6SRandy Dunlap#
22516b5b55f6SRandy Dunlap# however, formatting controls that are generated internally/locally in the
22526b5b55f6SRandy Dunlap# kernel-doc script are not escaped here; instead, they begin life like
22536b5b55f6SRandy Dunlap# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
22546b5b55f6SRandy Dunlap# are converted to their mnemonic-expected output, without the 4 * '\' & ':',
22556b5b55f6SRandy Dunlap# just before actual output; (this is done by local_unescape())
22561da177e4SLinus Torvaldssub xml_escape($) {
22571da177e4SLinus Torvalds	my $text = shift;
2258ecfb251aSRandy Dunlap	if (($output_mode eq "text") || ($output_mode eq "man")) {
2259ecfb251aSRandy Dunlap		return $text;
2260ecfb251aSRandy Dunlap	}
22611da177e4SLinus Torvalds	$text =~ s/\&/\\\\\\amp;/g;
22621da177e4SLinus Torvalds	$text =~ s/\</\\\\\\lt;/g;
22631da177e4SLinus Torvalds	$text =~ s/\>/\\\\\\gt;/g;
22641da177e4SLinus Torvalds	return $text;
22651da177e4SLinus Torvalds}
22661da177e4SLinus Torvalds
22676b5b55f6SRandy Dunlap# convert local escape strings to html
22686b5b55f6SRandy Dunlap# local escape strings look like:  '\\\\menmonic:' (that's 4 backslashes)
22696b5b55f6SRandy Dunlapsub local_unescape($) {
22706b5b55f6SRandy Dunlap	my $text = shift;
22716b5b55f6SRandy Dunlap	if (($output_mode eq "text") || ($output_mode eq "man")) {
22726b5b55f6SRandy Dunlap		return $text;
22736b5b55f6SRandy Dunlap	}
22746b5b55f6SRandy Dunlap	$text =~ s/\\\\\\\\lt:/</g;
22756b5b55f6SRandy Dunlap	$text =~ s/\\\\\\\\gt:/>/g;
22766b5b55f6SRandy Dunlap	return $text;
22776b5b55f6SRandy Dunlap}
22786b5b55f6SRandy Dunlap
22791da177e4SLinus Torvaldssub process_file($) {
22802283a117SRandy Dunlap    my $file;
22811da177e4SLinus Torvalds    my $identifier;
22821da177e4SLinus Torvalds    my $func;
2283a21217daSRandy Dunlap    my $descr;
22846423133bSJohannes Weiner    my $in_purpose = 0;
22851da177e4SLinus Torvalds    my $initial_section_counter = $section_counter;
22861da177e4SLinus Torvalds
22872283a117SRandy Dunlap    if (defined($ENV{'SRCTREE'})) {
22882283a117SRandy Dunlap	$file = "$ENV{'SRCTREE'}" . "/" . "@_";
22892283a117SRandy Dunlap    }
22902283a117SRandy Dunlap    else {
22912283a117SRandy Dunlap	$file = "@_";
22922283a117SRandy Dunlap    }
22931da177e4SLinus Torvalds    if (defined($source_map{$file})) {
22941da177e4SLinus Torvalds	$file = $source_map{$file};
22951da177e4SLinus Torvalds    }
22961da177e4SLinus Torvalds
22971da177e4SLinus Torvalds    if (!open(IN,"<$file")) {
22981da177e4SLinus Torvalds	print STDERR "Error: Cannot open file $file\n";
22991da177e4SLinus Torvalds	++$errors;
23001da177e4SLinus Torvalds	return;
23011da177e4SLinus Torvalds    }
23021da177e4SLinus Torvalds
2303a9e7314bSIlya Dryomov    $. = 1;
2304a9e7314bSIlya Dryomov
23051da177e4SLinus Torvalds    $section_counter = 0;
23061da177e4SLinus Torvalds    while (<IN>) {
23071da177e4SLinus Torvalds	if ($state == 0) {
23081da177e4SLinus Torvalds	    if (/$doc_start/o) {
23091da177e4SLinus Torvalds		$state = 1;		# next line is always the function name
2310850622dfSRandy Dunlap		$in_doc_sect = 0;
23111da177e4SLinus Torvalds	    }
23121da177e4SLinus Torvalds	} elsif ($state == 1) {	# this line is the function name (always)
23131da177e4SLinus Torvalds	    if (/$doc_block/o) {
23141da177e4SLinus Torvalds		$state = 4;
23151da177e4SLinus Torvalds		$contents = "";
23161da177e4SLinus Torvalds		if ( $1 eq "" ) {
23171da177e4SLinus Torvalds			$section = $section_intro;
23181da177e4SLinus Torvalds		} else {
23191da177e4SLinus Torvalds			$section = $1;
23201da177e4SLinus Torvalds		}
23211da177e4SLinus Torvalds	    }
23221da177e4SLinus Torvalds	    elsif (/$doc_decl/o) {
23231da177e4SLinus Torvalds		$identifier = $1;
23241da177e4SLinus Torvalds		if (/\s*([\w\s]+?)\s*-/) {
23251da177e4SLinus Torvalds		    $identifier = $1;
23261da177e4SLinus Torvalds		}
23271da177e4SLinus Torvalds
23281da177e4SLinus Torvalds		$state = 2;
23291da177e4SLinus Torvalds		if (/-(.*)/) {
233051f5a0c8SRandy Dunlap		    # strip leading/trailing/multiple spaces
2331a21217daSRandy Dunlap		    $descr= $1;
2332a21217daSRandy Dunlap		    $descr =~ s/^\s*//;
2333a21217daSRandy Dunlap		    $descr =~ s/\s*$//;
2334a21217daSRandy Dunlap		    $descr =~ s/\s+/ /;
2335a21217daSRandy Dunlap		    $declaration_purpose = xml_escape($descr);
23366423133bSJohannes Weiner		    $in_purpose = 1;
23371da177e4SLinus Torvalds		} else {
23381da177e4SLinus Torvalds		    $declaration_purpose = "";
23391da177e4SLinus Torvalds		}
234077cc23b8SRandy Dunlap
234177cc23b8SRandy Dunlap		if (($declaration_purpose eq "") && $verbose) {
234277cc23b8SRandy Dunlap			print STDERR "Warning(${file}:$.): missing initial short description on line:\n";
234377cc23b8SRandy Dunlap			print STDERR $_;
234477cc23b8SRandy Dunlap			++$warnings;
234577cc23b8SRandy Dunlap		}
234677cc23b8SRandy Dunlap
23471da177e4SLinus Torvalds		if ($identifier =~ m/^struct/) {
23481da177e4SLinus Torvalds		    $decl_type = 'struct';
23491da177e4SLinus Torvalds		} elsif ($identifier =~ m/^union/) {
23501da177e4SLinus Torvalds		    $decl_type = 'union';
23511da177e4SLinus Torvalds		} elsif ($identifier =~ m/^enum/) {
23521da177e4SLinus Torvalds		    $decl_type = 'enum';
23531da177e4SLinus Torvalds		} elsif ($identifier =~ m/^typedef/) {
23541da177e4SLinus Torvalds		    $decl_type = 'typedef';
23551da177e4SLinus Torvalds		} else {
23561da177e4SLinus Torvalds		    $decl_type = 'function';
23571da177e4SLinus Torvalds		}
23581da177e4SLinus Torvalds
23591da177e4SLinus Torvalds		if ($verbose) {
23601da177e4SLinus Torvalds		    print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
23611da177e4SLinus Torvalds		}
23621da177e4SLinus Torvalds	    } else {
23631da177e4SLinus Torvalds		print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
23641da177e4SLinus Torvalds		" - I thought it was a doc line\n";
23651da177e4SLinus Torvalds		++$warnings;
23661da177e4SLinus Torvalds		$state = 0;
23671da177e4SLinus Torvalds	    }
23681da177e4SLinus Torvalds	} elsif ($state == 2) {	# look for head: lines, and include content
23691da177e4SLinus Torvalds	    if (/$doc_sect/o) {
23701da177e4SLinus Torvalds		$newsection = $1;
23711da177e4SLinus Torvalds		$newcontents = $2;
23721da177e4SLinus Torvalds
2373792aa2f2SRandy Dunlap		if (($contents ne "") && ($contents ne "\n")) {
2374850622dfSRandy Dunlap		    if (!$in_doc_sect && $verbose) {
2375850622dfSRandy Dunlap			print STDERR "Warning(${file}:$.): contents before sections\n";
2376850622dfSRandy Dunlap			++$warnings;
2377850622dfSRandy Dunlap		    }
237894dc7ad5SRandy Dunlap		    dump_section($file, $section, xml_escape($contents));
23791da177e4SLinus Torvalds		    $section = $section_default;
23801da177e4SLinus Torvalds		}
23811da177e4SLinus Torvalds
2382850622dfSRandy Dunlap		$in_doc_sect = 1;
23836423133bSJohannes Weiner		$in_purpose = 0;
23841da177e4SLinus Torvalds		$contents = $newcontents;
23851da177e4SLinus Torvalds		if ($contents ne "") {
238627205744SRandy Dunlap		    while ((substr($contents, 0, 1) eq " ") ||
238727205744SRandy Dunlap			substr($contents, 0, 1) eq "\t") {
238805189497SRandy Dunlap			    $contents = substr($contents, 1);
238905189497SRandy Dunlap		    }
23901da177e4SLinus Torvalds		    $contents .= "\n";
23911da177e4SLinus Torvalds		}
23921da177e4SLinus Torvalds		$section = $newsection;
23931da177e4SLinus Torvalds	    } elsif (/$doc_end/) {
23941da177e4SLinus Torvalds
23954c98ecafSRandy Dunlap		if (($contents ne "") && ($contents ne "\n")) {
239694dc7ad5SRandy Dunlap		    dump_section($file, $section, xml_escape($contents));
23971da177e4SLinus Torvalds		    $section = $section_default;
23981da177e4SLinus Torvalds		    $contents = "";
23991da177e4SLinus Torvalds		}
240046b958ebSRandy Dunlap		# look for doc_com + <text> + doc_end:
240146b958ebSRandy Dunlap		if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
240246b958ebSRandy Dunlap		    print STDERR "Warning(${file}:$.): suspicious ending line: $_";
240346b958ebSRandy Dunlap		    ++$warnings;
240446b958ebSRandy Dunlap		}
24051da177e4SLinus Torvalds
24061da177e4SLinus Torvalds		$prototype = "";
24071da177e4SLinus Torvalds		$state = 3;
24081da177e4SLinus Torvalds		$brcount = 0;
24091da177e4SLinus Torvalds#		print STDERR "end of doc comment, looking for prototype\n";
24101da177e4SLinus Torvalds	    } elsif (/$doc_content/) {
24111da177e4SLinus Torvalds		# miguel-style comment kludge, look for blank lines after
24121da177e4SLinus Torvalds		# @parameter line to signify start of description
24136423133bSJohannes Weiner		if ($1 eq "") {
24146423133bSJohannes Weiner		    if ($section =~ m/^@/ || $section eq $section_context) {
241594dc7ad5SRandy Dunlap			dump_section($file, $section, xml_escape($contents));
24161da177e4SLinus Torvalds			$section = $section_default;
24171da177e4SLinus Torvalds			$contents = "";
24181da177e4SLinus Torvalds		    } else {
24196423133bSJohannes Weiner			$contents .= "\n";
24206423133bSJohannes Weiner		    }
24216423133bSJohannes Weiner		    $in_purpose = 0;
24226423133bSJohannes Weiner		} elsif ($in_purpose == 1) {
24236423133bSJohannes Weiner		    # Continued declaration purpose
24246423133bSJohannes Weiner		    chomp($declaration_purpose);
24256423133bSJohannes Weiner		    $declaration_purpose .= " " . xml_escape($1);
24266423133bSJohannes Weiner		} else {
24271da177e4SLinus Torvalds		    $contents .= $1 . "\n";
24281da177e4SLinus Torvalds		}
24291da177e4SLinus Torvalds	    } else {
24301da177e4SLinus Torvalds		# i dont know - bad line?  ignore.
24311da177e4SLinus Torvalds		print STDERR "Warning(${file}:$.): bad line: $_";
24321da177e4SLinus Torvalds		++$warnings;
24331da177e4SLinus Torvalds	    }
2434232acbcfSRandy Dunlap	} elsif ($state == 3) {	# scanning for function '{' (end of prototype)
24351da177e4SLinus Torvalds	    if ($decl_type eq 'function') {
24361da177e4SLinus Torvalds		process_state3_function($_, $file);
24371da177e4SLinus Torvalds	    } else {
24381da177e4SLinus Torvalds		process_state3_type($_, $file);
24391da177e4SLinus Torvalds	    }
24401da177e4SLinus Torvalds	} elsif ($state == 4) {
24411da177e4SLinus Torvalds		# Documentation block
24421da177e4SLinus Torvalds		if (/$doc_block/) {
244394dc7ad5SRandy Dunlap			dump_doc_section($file, $section, xml_escape($contents));
24441da177e4SLinus Torvalds			$contents = "";
24451da177e4SLinus Torvalds			$function = "";
24461da177e4SLinus Torvalds			%constants = ();
24471da177e4SLinus Torvalds			%parameterdescs = ();
24481da177e4SLinus Torvalds			%parametertypes = ();
24491da177e4SLinus Torvalds			@parameterlist = ();
24501da177e4SLinus Torvalds			%sections = ();
24511da177e4SLinus Torvalds			@sectionlist = ();
24521da177e4SLinus Torvalds			$prototype = "";
24531da177e4SLinus Torvalds			if ( $1 eq "" ) {
24541da177e4SLinus Torvalds				$section = $section_intro;
24551da177e4SLinus Torvalds			} else {
24561da177e4SLinus Torvalds				$section = $1;
24571da177e4SLinus Torvalds			}
24581da177e4SLinus Torvalds		}
24591da177e4SLinus Torvalds		elsif (/$doc_end/)
24601da177e4SLinus Torvalds		{
246194dc7ad5SRandy Dunlap			dump_doc_section($file, $section, xml_escape($contents));
24621da177e4SLinus Torvalds			$contents = "";
24631da177e4SLinus Torvalds			$function = "";
24641da177e4SLinus Torvalds			%constants = ();
24651da177e4SLinus Torvalds			%parameterdescs = ();
24661da177e4SLinus Torvalds			%parametertypes = ();
24671da177e4SLinus Torvalds			@parameterlist = ();
24681da177e4SLinus Torvalds			%sections = ();
24691da177e4SLinus Torvalds			@sectionlist = ();
24701da177e4SLinus Torvalds			$prototype = "";
24711da177e4SLinus Torvalds			$state = 0;
24721da177e4SLinus Torvalds		}
24731da177e4SLinus Torvalds		elsif (/$doc_content/)
24741da177e4SLinus Torvalds		{
24751da177e4SLinus Torvalds			if ( $1 eq "" )
24761da177e4SLinus Torvalds			{
24771da177e4SLinus Torvalds				$contents .= $blankline;
24781da177e4SLinus Torvalds			}
24791da177e4SLinus Torvalds			else
24801da177e4SLinus Torvalds			{
24811da177e4SLinus Torvalds				$contents .= $1 . "\n";
24821da177e4SLinus Torvalds			}
24831da177e4SLinus Torvalds		}
24841da177e4SLinus Torvalds	}
24851da177e4SLinus Torvalds    }
24861da177e4SLinus Torvalds    if ($initial_section_counter == $section_counter) {
24871da177e4SLinus Torvalds	print STDERR "Warning(${file}): no structured comments found\n";
24881da177e4SLinus Torvalds	if ($output_mode eq "xml") {
24891da177e4SLinus Torvalds	    # The template wants at least one RefEntry here; make one.
24901da177e4SLinus Torvalds	    print "<refentry>\n";
24911da177e4SLinus Torvalds	    print " <refnamediv>\n";
24921da177e4SLinus Torvalds	    print "  <refname>\n";
24931da177e4SLinus Torvalds	    print "   ${file}\n";
24941da177e4SLinus Torvalds	    print "  </refname>\n";
24951da177e4SLinus Torvalds	    print "  <refpurpose>\n";
24961da177e4SLinus Torvalds	    print "   Document generation inconsistency\n";
24971da177e4SLinus Torvalds	    print "  </refpurpose>\n";
24981da177e4SLinus Torvalds	    print " </refnamediv>\n";
24991da177e4SLinus Torvalds	    print " <refsect1>\n";
25001da177e4SLinus Torvalds	    print "  <title>\n";
25011da177e4SLinus Torvalds	    print "   Oops\n";
25021da177e4SLinus Torvalds	    print "  </title>\n";
25031da177e4SLinus Torvalds	    print "  <warning>\n";
25041da177e4SLinus Torvalds	    print "   <para>\n";
25051da177e4SLinus Torvalds	    print "    The template for this document tried to insert\n";
25061da177e4SLinus Torvalds	    print "    the structured comment from the file\n";
25071da177e4SLinus Torvalds	    print "    <filename>${file}</filename> at this point,\n";
25081da177e4SLinus Torvalds	    print "    but none was found.\n";
25091da177e4SLinus Torvalds	    print "    This dummy section is inserted to allow\n";
25101da177e4SLinus Torvalds	    print "    generation to continue.\n";
25111da177e4SLinus Torvalds	    print "   </para>\n";
25121da177e4SLinus Torvalds	    print "  </warning>\n";
25131da177e4SLinus Torvalds	    print " </refsect1>\n";
25141da177e4SLinus Torvalds	    print "</refentry>\n";
25151da177e4SLinus Torvalds	}
25161da177e4SLinus Torvalds    }
25171da177e4SLinus Torvalds}
25188484baaaSRandy Dunlap
25198484baaaSRandy Dunlap
25208484baaaSRandy Dunlap$kernelversion = get_kernel_version();
25218484baaaSRandy Dunlap
25228484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information
25238484baaaSRandy Dunlap# using the s// operator.
25248484baaaSRandy Dunlapforeach my $pattern (keys %highlights) {
25258484baaaSRandy Dunlap#   print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
25268484baaaSRandy Dunlap    $dohighlight .=  "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
25278484baaaSRandy Dunlap}
25288484baaaSRandy Dunlap
25298484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for
25308484baaaSRandy Dunlap# separate source and object directories and for shadow trees.
25318484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
25328484baaaSRandy Dunlap	my ($relname, $absname);
25338484baaaSRandy Dunlap	while(<SOURCE_MAP>) {
25348484baaaSRandy Dunlap		chop();
25358484baaaSRandy Dunlap		($relname, $absname) = (split())[0..1];
25368484baaaSRandy Dunlap		$relname =~ s:^/+::;
25378484baaaSRandy Dunlap		$source_map{$relname} = $absname;
25388484baaaSRandy Dunlap	}
25398484baaaSRandy Dunlap	close(SOURCE_MAP);
25408484baaaSRandy Dunlap}
25418484baaaSRandy Dunlap
25428484baaaSRandy Dunlapforeach (@ARGV) {
25438484baaaSRandy Dunlap    chomp;
25448484baaaSRandy Dunlap    process_file($_);
25458484baaaSRandy Dunlap}
25468484baaaSRandy Dunlapif ($verbose && $errors) {
25478484baaaSRandy Dunlap  print STDERR "$errors errors\n";
25488484baaaSRandy Dunlap}
25498484baaaSRandy Dunlapif ($verbose && $warnings) {
25508484baaaSRandy Dunlap  print STDERR "$warnings warnings\n";
25518484baaaSRandy Dunlap}
25528484baaaSRandy Dunlap
25538484baaaSRandy Dunlapexit($errors);
2554