11da177e4SLinus Torvalds#!/usr/bin/perl -w 21da177e4SLinus Torvalds 31da177e4SLinus Torvaldsuse strict; 41da177e4SLinus Torvalds 51da177e4SLinus Torvalds## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## 61da177e4SLinus Torvalds## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## 71da177e4SLinus Torvalds## Copyright (C) 2001 Simon Huggins ## 870c95b00SRandy Dunlap## Copyright (C) 2005-2012 Randy Dunlap ## 91b40c194SDan Luedtke## Copyright (C) 2012 Dan Luedtke ## 101da177e4SLinus Torvalds## ## 111da177e4SLinus Torvalds## #define enhancements by Armin Kuster <akuster@mvista.com> ## 121da177e4SLinus Torvalds## Copyright (c) 2000 MontaVista Software, Inc. ## 131da177e4SLinus Torvalds## ## 141da177e4SLinus Torvalds## This software falls under the GNU General Public License. ## 151da177e4SLinus Torvalds## Please read the COPYING file for more information ## 161da177e4SLinus Torvalds 171da177e4SLinus Torvalds# 18/01/2001 - Cleanups 181da177e4SLinus Torvalds# Functions prototyped as foo(void) same as foo() 191da177e4SLinus Torvalds# Stop eval'ing where we don't need to. 201da177e4SLinus Torvalds# -- huggie@earth.li 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds# 27/06/2001 - Allowed whitespace after initial "/**" and 231da177e4SLinus Torvalds# allowed comments before function declarations. 241da177e4SLinus Torvalds# -- Christian Kreibich <ck@whoop.org> 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds# Still to do: 271da177e4SLinus Torvalds# - add perldoc documentation 281da177e4SLinus Torvalds# - Look more closely at some of the scarier bits :) 291da177e4SLinus Torvalds 301da177e4SLinus Torvalds# 26/05/2001 - Support for separate source and object trees. 311da177e4SLinus Torvalds# Return error code. 321da177e4SLinus Torvalds# Keith Owens <kaos@ocs.com.au> 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds# 23/09/2001 - Added support for typedefs, structs, enums and unions 351da177e4SLinus Torvalds# Support for Context section; can be terminated using empty line 361da177e4SLinus Torvalds# Small fixes (like spaces vs. \s in regex) 371da177e4SLinus Torvalds# -- Tim Jansen <tim@tjansen.de> 381da177e4SLinus Torvalds 391b40c194SDan Luedtke# 25/07/2012 - Added support for HTML5 401b40c194SDan Luedtke# -- Dan Luedtke <mail@danrl.de> 411da177e4SLinus Torvalds 42fadc0b31SJani Nikulasub usage { 43fadc0b31SJani Nikula my $message = <<"EOF"; 44fadc0b31SJani NikulaUsage: $0 [OPTION ...] FILE ... 451da177e4SLinus Torvalds 46fadc0b31SJani NikulaRead C language source or header FILEs, extract embedded documentation comments, 47fadc0b31SJani Nikulaand print formatted documentation to standard output. 481da177e4SLinus Torvalds 49fadc0b31SJani NikulaThe documentation comments are identified by "/**" opening comment mark. See 50fadc0b31SJani NikulaDocumentation/kernel-doc-nano-HOWTO.txt for the documentation comment syntax. 51fadc0b31SJani Nikula 52fadc0b31SJani NikulaOutput format selection (mutually exclusive): 53fadc0b31SJani Nikula -docbook Output DocBook format. 54fadc0b31SJani Nikula -html Output HTML format. 55fadc0b31SJani Nikula -html5 Output HTML5 format. 56fadc0b31SJani Nikula -list Output symbol list format. This is for use by docproc. 57fadc0b31SJani Nikula -man Output troff manual page format. This is the default. 58c0d1b6eeSJonathan Corbet -rst Output reStructuredText format. 59fadc0b31SJani Nikula -text Output plain text format. 60fadc0b31SJani Nikula 61fadc0b31SJani NikulaOutput selection (mutually exclusive): 6286ae2e38SJani Nikula -export Only output documentation for symbols that have been 6386ae2e38SJani Nikula exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 6486ae2e38SJani Nikula in the same FILE. 6586ae2e38SJani Nikula -internal Only output documentation for symbols that have NOT been 6686ae2e38SJani Nikula exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 6786ae2e38SJani Nikula in the same FILE. 68fadc0b31SJani Nikula -function NAME Only output documentation for the given function(s) 69fadc0b31SJani Nikula or DOC: section title(s). All other functions and DOC: 70fadc0b31SJani Nikula sections are ignored. May be specified multiple times. 71fadc0b31SJani Nikula -nofunction NAME Do NOT output documentation for the given function(s); 72fadc0b31SJani Nikula only output documentation for the other functions and 73fadc0b31SJani Nikula DOC: sections. May be specified multiple times. 74fadc0b31SJani Nikula 75fadc0b31SJani NikulaOutput selection modifiers: 76fadc0b31SJani Nikula -no-doc-sections Do not output DOC: sections. 77*0b0f5f29SDaniel Vetter -enable-lineno Enable output of #define LINENO lines. Only works with 78*0b0f5f29SDaniel Vetter reStructuredText format. 79fadc0b31SJani Nikula 80fadc0b31SJani NikulaOther parameters: 81fadc0b31SJani Nikula -v Verbose output, more warnings and other information. 82fadc0b31SJani Nikula -h Print this help. 83fadc0b31SJani Nikula 84fadc0b31SJani NikulaEOF 85fadc0b31SJani Nikula print $message; 86fadc0b31SJani Nikula exit 1; 87fadc0b31SJani Nikula} 881da177e4SLinus Torvalds 891da177e4SLinus Torvalds# 901da177e4SLinus Torvalds# format of comments. 911da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure. 921da177e4SLinus Torvalds# (...)* signifies 0 or more structure elements 931da177e4SLinus Torvalds# /** 941da177e4SLinus Torvalds# * function_name(:)? (- short description)? 951da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)* 961da177e4SLinus Torvalds# (* a blank line)? 971da177e4SLinus Torvalds# * (Description:)? (Description of function)? 981da177e4SLinus Torvalds# * (section header: (section description)? )* 991da177e4SLinus Torvalds# (*)?*/ 1001da177e4SLinus Torvalds# 1011da177e4SLinus Torvalds# So .. the trivial example would be: 1021da177e4SLinus Torvalds# 1031da177e4SLinus Torvalds# /** 1041da177e4SLinus Torvalds# * my_function 105b9d97328SRandy Dunlap# */ 1061da177e4SLinus Torvalds# 107891dcd2fSRandy Dunlap# If the Description: header tag is omitted, then there must be a blank line 1081da177e4SLinus Torvalds# after the last parameter specification. 1091da177e4SLinus Torvalds# e.g. 1101da177e4SLinus Torvalds# /** 1111da177e4SLinus Torvalds# * my_function - does my stuff 1121da177e4SLinus Torvalds# * @my_arg: its mine damnit 1131da177e4SLinus Torvalds# * 1141da177e4SLinus Torvalds# * Does my stuff explained. 1151da177e4SLinus Torvalds# */ 1161da177e4SLinus Torvalds# 1171da177e4SLinus Torvalds# or, could also use: 1181da177e4SLinus Torvalds# /** 1191da177e4SLinus Torvalds# * my_function - does my stuff 1201da177e4SLinus Torvalds# * @my_arg: its mine damnit 1211da177e4SLinus Torvalds# * Description: Does my stuff explained. 1221da177e4SLinus Torvalds# */ 1231da177e4SLinus Torvalds# etc. 1241da177e4SLinus Torvalds# 125b9d97328SRandy Dunlap# Besides functions you can also write documentation for structs, unions, 1261da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name 1271da177e4SLinus Torvalds# of the declaration; the struct/union/enum/typedef must always precede 1281da177e4SLinus Torvalds# the name. Nesting of declarations is not supported. 1291da177e4SLinus Torvalds# Use the argument mechanism to document members or constants. 1301da177e4SLinus Torvalds# e.g. 1311da177e4SLinus Torvalds# /** 1321da177e4SLinus Torvalds# * struct my_struct - short description 1331da177e4SLinus Torvalds# * @a: first member 1341da177e4SLinus Torvalds# * @b: second member 1351da177e4SLinus Torvalds# * 1361da177e4SLinus Torvalds# * Longer description 1371da177e4SLinus Torvalds# */ 1381da177e4SLinus Torvalds# struct my_struct { 1391da177e4SLinus Torvalds# int a; 1401da177e4SLinus Torvalds# int b; 141aeec46b9SMartin Waitz# /* private: */ 142aeec46b9SMartin Waitz# int c; 1431da177e4SLinus Torvalds# }; 1441da177e4SLinus Torvalds# 1451da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description. 1461da177e4SLinus Torvalds# 147a4c6ebedSDanilo Cesar Lemes de Paula# For really longs structs, you can also describe arguments inside the 148a4c6ebedSDanilo Cesar Lemes de Paula# body of the struct. 149a4c6ebedSDanilo Cesar Lemes de Paula# eg. 150a4c6ebedSDanilo Cesar Lemes de Paula# /** 151a4c6ebedSDanilo Cesar Lemes de Paula# * struct my_struct - short description 152a4c6ebedSDanilo Cesar Lemes de Paula# * @a: first member 153a4c6ebedSDanilo Cesar Lemes de Paula# * @b: second member 154a4c6ebedSDanilo Cesar Lemes de Paula# * 155a4c6ebedSDanilo Cesar Lemes de Paula# * Longer description 156a4c6ebedSDanilo Cesar Lemes de Paula# */ 157a4c6ebedSDanilo Cesar Lemes de Paula# struct my_struct { 158a4c6ebedSDanilo Cesar Lemes de Paula# int a; 159a4c6ebedSDanilo Cesar Lemes de Paula# int b; 160a4c6ebedSDanilo Cesar Lemes de Paula# /** 161a4c6ebedSDanilo Cesar Lemes de Paula# * @c: This is longer description of C 162a4c6ebedSDanilo Cesar Lemes de Paula# * 163a4c6ebedSDanilo Cesar Lemes de Paula# * You can use paragraphs to describe arguments 164a4c6ebedSDanilo Cesar Lemes de Paula# * using this method. 165a4c6ebedSDanilo Cesar Lemes de Paula# */ 166a4c6ebedSDanilo Cesar Lemes de Paula# int c; 167a4c6ebedSDanilo Cesar Lemes de Paula# }; 168a4c6ebedSDanilo Cesar Lemes de Paula# 169a4c6ebedSDanilo Cesar Lemes de Paula# This should be use only for struct/enum members. 170a4c6ebedSDanilo Cesar Lemes de Paula# 1711da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you 1721da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions 1731da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an 1741da177e4SLinus Torvalds# empty line. 1754092bac7SYacine Belkadi# A non-void function should have a "Return:" section describing the return 1764092bac7SYacine Belkadi# value(s). 1771da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked 1781da177e4SLinus Torvalds# appropriately in DocBook. 1791da177e4SLinus Torvalds# 1801da177e4SLinus Torvalds# Example: 1811da177e4SLinus Torvalds# /** 1821da177e4SLinus Torvalds# * user_function - function that can only be called in user context 1831da177e4SLinus Torvalds# * @a: some argument 1841da177e4SLinus Torvalds# * Context: !in_interrupt() 1851da177e4SLinus Torvalds# * 1861da177e4SLinus Torvalds# * Some description 1871da177e4SLinus Torvalds# * Example: 1881da177e4SLinus Torvalds# * user_function(22); 1891da177e4SLinus Torvalds# */ 1901da177e4SLinus Torvalds# ... 1911da177e4SLinus Torvalds# 1921da177e4SLinus Torvalds# 1931da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special 1941da177e4SLinus Torvalds# patterns, which are highlighted appropriately. 1951da177e4SLinus Torvalds# 1961da177e4SLinus Torvalds# 'funcname()' - function 1971da177e4SLinus Torvalds# '$ENVVAR' - environmental variable 1981da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct') 1991da177e4SLinus Torvalds# '@parameter' - name of a parameter 2001da177e4SLinus Torvalds# '%CONST' - name of a constant. 2011da177e4SLinus Torvalds 2028484baaaSRandy Dunlap## init lots of data 2038484baaaSRandy Dunlap 2041da177e4SLinus Torvaldsmy $errors = 0; 2051da177e4SLinus Torvaldsmy $warnings = 0; 2065f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds# match expressions used to find embedded type information 2091da177e4SLinus Torvaldsmy $type_constant = '\%([-_\w]+)'; 2101da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 2111da177e4SLinus Torvaldsmy $type_param = '\@(\w+)'; 2123eb014a1SRandy Dunlapmy $type_struct = '\&((struct\s*)*[_\w]+)'; 2136b5b55f6SRandy Dunlapmy $type_struct_xml = '\\&((struct\s*)*[_\w]+)'; 2141da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 215c0d1b6eeSJonathan Corbetmy $type_enum_full = '\&(enum)\s*([_\w]+)'; 216c0d1b6eeSJonathan Corbetmy $type_struct_full = '\&(struct)\s*([_\w]+)'; 21747ae7aedSJani Nikulamy $type_typedef_full = '\&(typedef)\s*([_\w]+)'; 21847ae7aedSJani Nikulamy $type_union_full = '\&(union)\s*([_\w]+)'; 219f3341dcfSJani Nikulamy $type_member = '\&([_\w]+)((\.|->)[_\w]+)'; 220f3341dcfSJani Nikulamy $type_member_func = $type_member . '\(\)'; 2211da177e4SLinus Torvalds 2221da177e4SLinus Torvalds# Output conversion substitutions. 2231da177e4SLinus Torvalds# One for each output format 2241da177e4SLinus Torvalds 2251da177e4SLinus Torvalds# these work fairly well 2264d732701SDanilo Cesar Lemes de Paulamy @highlights_html = ( 2274d732701SDanilo Cesar Lemes de Paula [$type_constant, "<i>\$1</i>"], 2284d732701SDanilo Cesar Lemes de Paula [$type_func, "<b>\$1</b>"], 2294d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<i>\$1</i>"], 2304d732701SDanilo Cesar Lemes de Paula [$type_env, "<b><i>\$1</i></b>"], 2314d732701SDanilo Cesar Lemes de Paula [$type_param, "<tt><b>\$1</b></tt>"] 2324d732701SDanilo Cesar Lemes de Paula ); 2336b5b55f6SRandy Dunlapmy $local_lt = "\\\\\\\\lt:"; 2346b5b55f6SRandy Dunlapmy $local_gt = "\\\\\\\\gt:"; 2356b5b55f6SRandy Dunlapmy $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" 2361da177e4SLinus Torvalds 2371b40c194SDan Luedtke# html version 5 2384d732701SDanilo Cesar Lemes de Paulamy @highlights_html5 = ( 2394d732701SDanilo Cesar Lemes de Paula [$type_constant, "<span class=\"const\">\$1</span>"], 2404d732701SDanilo Cesar Lemes de Paula [$type_func, "<span class=\"func\">\$1</span>"], 2414d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<span class=\"struct\">\$1</span>"], 2424d732701SDanilo Cesar Lemes de Paula [$type_env, "<span class=\"env\">\$1</span>"], 2434d732701SDanilo Cesar Lemes de Paula [$type_param, "<span class=\"param\">\$1</span>]"] 2444d732701SDanilo Cesar Lemes de Paula ); 2451b40c194SDan Luedtkemy $blankline_html5 = $local_lt . "br /" . $local_gt; 2461b40c194SDan Luedtke 2471da177e4SLinus Torvalds# XML, docbook format 2484d732701SDanilo Cesar Lemes de Paulamy @highlights_xml = ( 2494d732701SDanilo Cesar Lemes de Paula ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"], 2504d732701SDanilo Cesar Lemes de Paula [$type_constant, "<constant>\$1</constant>"], 2514d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<structname>\$1</structname>"], 2524d732701SDanilo Cesar Lemes de Paula [$type_param, "<parameter>\$1</parameter>"], 2534d732701SDanilo Cesar Lemes de Paula [$type_func, "<function>\$1</function>"], 2544d732701SDanilo Cesar Lemes de Paula [$type_env, "<envar>\$1</envar>"] 2554d732701SDanilo Cesar Lemes de Paula ); 2565c98fc03SJohannes Bergmy $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; 2571da177e4SLinus Torvalds 2581da177e4SLinus Torvalds# gnome, docbook format 2594d732701SDanilo Cesar Lemes de Paulamy @highlights_gnome = ( 2604d732701SDanilo Cesar Lemes de Paula [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"], 2614d732701SDanilo Cesar Lemes de Paula [$type_func, "<function>\$1</function>"], 2624d732701SDanilo Cesar Lemes de Paula [$type_struct, "<structname>\$1</structname>"], 2634d732701SDanilo Cesar Lemes de Paula [$type_env, "<envar>\$1</envar>"], 2644d732701SDanilo Cesar Lemes de Paula [$type_param, "<parameter>\$1</parameter>" ] 2654d732701SDanilo Cesar Lemes de Paula ); 2661da177e4SLinus Torvaldsmy $blankline_gnome = "</para><para>\n"; 2671da177e4SLinus Torvalds 2681da177e4SLinus Torvalds# these are pretty rough 2694d732701SDanilo Cesar Lemes de Paulamy @highlights_man = ( 2704d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 2714d732701SDanilo Cesar Lemes de Paula [$type_func, "\\\\fB\$1\\\\fP"], 2724d732701SDanilo Cesar Lemes de Paula [$type_struct, "\\\\fI\$1\\\\fP"], 2734d732701SDanilo Cesar Lemes de Paula [$type_param, "\\\\fI\$1\\\\fP"] 2744d732701SDanilo Cesar Lemes de Paula ); 2751da177e4SLinus Torvaldsmy $blankline_man = ""; 2761da177e4SLinus Torvalds 2771da177e4SLinus Torvalds# text-mode 2784d732701SDanilo Cesar Lemes de Paulamy @highlights_text = ( 2794d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 2804d732701SDanilo Cesar Lemes de Paula [$type_func, "\$1"], 2814d732701SDanilo Cesar Lemes de Paula [$type_struct, "\$1"], 2824d732701SDanilo Cesar Lemes de Paula [$type_param, "\$1"] 2834d732701SDanilo Cesar Lemes de Paula ); 2841da177e4SLinus Torvaldsmy $blankline_text = ""; 2851da177e4SLinus Torvalds 286c0d1b6eeSJonathan Corbet# rst-mode 287c0d1b6eeSJonathan Corbetmy @highlights_rst = ( 288c0d1b6eeSJonathan Corbet [$type_constant, "``\$1``"], 289f3341dcfSJani Nikula # Note: need to escape () to avoid func matching later 290f3341dcfSJani Nikula [$type_member_func, "\\:c\\:type\\:`\$1\$2\\\\(\\\\) <\$1>`"], 291f3341dcfSJani Nikula [$type_member, "\\:c\\:type\\:`\$1\$2 <\$1>`"], 292a19bce64SJani Nikula [$type_func, "\\:c\\:func\\:`\$1()`"], 29362850976SJani Nikula [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 29462850976SJani Nikula [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 29547ae7aedSJani Nikula [$type_typedef_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 29647ae7aedSJani Nikula [$type_union_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 297a7291e7eSJani Nikula # in rst this can refer to any type 298a7291e7eSJani Nikula [$type_struct, "\\:c\\:type\\:`\$1`"], 299c0d1b6eeSJonathan Corbet [$type_param, "**\$1**"] 300c0d1b6eeSJonathan Corbet ); 301c0d1b6eeSJonathan Corbetmy $blankline_rst = "\n"; 302c0d1b6eeSJonathan Corbet 303eda603f6SJohannes Berg# list mode 3044d732701SDanilo Cesar Lemes de Paulamy @highlights_list = ( 3054d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 3064d732701SDanilo Cesar Lemes de Paula [$type_func, "\$1"], 3074d732701SDanilo Cesar Lemes de Paula [$type_struct, "\$1"], 3084d732701SDanilo Cesar Lemes de Paula [$type_param, "\$1"] 3094d732701SDanilo Cesar Lemes de Paula ); 310eda603f6SJohannes Bergmy $blankline_list = ""; 3111da177e4SLinus Torvalds 3121da177e4SLinus Torvalds# read arguments 3131da177e4SLinus Torvaldsif ($#ARGV == -1) { 3141da177e4SLinus Torvalds usage(); 3151da177e4SLinus Torvalds} 3161da177e4SLinus Torvalds 3178484baaaSRandy Dunlapmy $kernelversion; 3188484baaaSRandy Dunlapmy $dohighlight = ""; 3198484baaaSRandy Dunlap 3201da177e4SLinus Torvaldsmy $verbose = 0; 3211da177e4SLinus Torvaldsmy $output_mode = "man"; 322e314ba31SDaniel Santosmy $output_preformatted = 0; 3234b44595aSJohannes Bergmy $no_doc_sections = 0; 324*0b0f5f29SDaniel Vettermy $enable_lineno = 0; 3254d732701SDanilo Cesar Lemes de Paulamy @highlights = @highlights_man; 3261da177e4SLinus Torvaldsmy $blankline = $blankline_man; 3271da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 328b6c3f456SJani Nikula 329b6c3f456SJani Nikulause constant { 330b6c3f456SJani Nikula OUTPUT_ALL => 0, # output all symbols and doc sections 331b6c3f456SJani Nikula OUTPUT_INCLUDE => 1, # output only specified symbols 332b6c3f456SJani Nikula OUTPUT_EXCLUDE => 2, # output everything except specified symbols 333b6c3f456SJani Nikula OUTPUT_EXPORTED => 3, # output exported symbols 334b6c3f456SJani Nikula OUTPUT_INTERNAL => 4, # output non-exported symbols 335b6c3f456SJani Nikula}; 336b6c3f456SJani Nikulamy $output_selection = OUTPUT_ALL; 337b2c4105bSBen Hutchingsmy $show_not_found = 0; 338b2c4105bSBen Hutchings 339b2c4105bSBen Hutchingsmy @build_time; 340b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 341b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 342b2c4105bSBen Hutchings @build_time = gmtime($seconds); 343b2c4105bSBen Hutchings} else { 344b2c4105bSBen Hutchings @build_time = localtime; 345b2c4105bSBen Hutchings} 346b2c4105bSBen Hutchings 3471da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 3481da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 349b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 350b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 3511da177e4SLinus Torvalds 3528484baaaSRandy Dunlap# Essentially these are globals. 353b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 354b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 3551da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 3561da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 357*0b0f5f29SDaniel Vettermy $declaration_start_line; 3581da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 3591c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 3601da177e4SLinus Torvalds 361bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 362bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 363bd0e88e5SRandy Dunlap} 364bd0e88e5SRandy Dunlap 3651da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 3661da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 3671da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 3681da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 3691da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 3701da177e4SLinus Torvalds# into html. 3711da177e4SLinus Torvaldsmy $section_counter = 0; 3721da177e4SLinus Torvalds 3731da177e4SLinus Torvaldsmy $lineprefix=""; 3741da177e4SLinus Torvalds 37548af606aSJani Nikula# Parser states 37648af606aSJani Nikulause constant { 37748af606aSJani Nikula STATE_NORMAL => 0, # normal code 37848af606aSJani Nikula STATE_NAME => 1, # looking for function name 37948af606aSJani Nikula STATE_FIELD => 2, # scanning field start 38048af606aSJani Nikula STATE_PROTO => 3, # scanning prototype 38148af606aSJani Nikula STATE_DOCBLOCK => 4, # documentation block 38248af606aSJani Nikula STATE_INLINE => 5, # gathering documentation outside main block 38348af606aSJani Nikula}; 3841da177e4SLinus Torvaldsmy $state; 385850622dfSRandy Dunlapmy $in_doc_sect; 3861da177e4SLinus Torvalds 38748af606aSJani Nikula# Inline documentation state 38848af606aSJani Nikulause constant { 38948af606aSJani Nikula STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 39048af606aSJani Nikula STATE_INLINE_NAME => 1, # looking for member name (@foo:) 39148af606aSJani Nikula STATE_INLINE_TEXT => 2, # looking for member documentation 39248af606aSJani Nikula STATE_INLINE_END => 3, # done 39348af606aSJani Nikula STATE_INLINE_ERROR => 4, # error - Comment without header was found. 39448af606aSJani Nikula # Spit a warning as it's not 395a4c6ebedSDanilo Cesar Lemes de Paula # proper kernel-doc and ignore the rest. 39648af606aSJani Nikula}; 39748af606aSJani Nikulamy $inline_doc_state; 398a4c6ebedSDanilo Cesar Lemes de Paula 3991da177e4SLinus Torvalds#declaration types: can be 4001da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 4011da177e4SLinus Torvaldsmy $decl_type; 4021da177e4SLinus Torvalds 4031da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 4041da177e4SLinus Torvaldsmy $doc_end = '\*/'; 4051da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 40612ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 4071da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 408f624adefSJani Nikula# @params and a strictly limited set of supported section names 409f624adefSJani Nikulamy $doc_sect = $doc_com . '\s*(\@\w+|description|context|returns?)\s*:(.*)'; 41012ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 4111da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 41248af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$'; 41348af606aSJani Nikulamy $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)'; 41448af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$'; 41586ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 4161da177e4SLinus Torvalds 4171da177e4SLinus Torvaldsmy %parameterdescs; 418*0b0f5f29SDaniel Vettermy %parameterdesc_start_lines; 4191da177e4SLinus Torvaldsmy @parameterlist; 4201da177e4SLinus Torvaldsmy %sections; 4211da177e4SLinus Torvaldsmy @sectionlist; 422*0b0f5f29SDaniel Vettermy %section_start_lines; 423a1d94aa5SRandy Dunlapmy $sectcheck; 424a1d94aa5SRandy Dunlapmy $struct_actual; 4251da177e4SLinus Torvalds 4261da177e4SLinus Torvaldsmy $contents = ""; 427*0b0f5f29SDaniel Vettermy $new_start_line = 0; 428f624adefSJani Nikula 429f624adefSJani Nikula# the canonical section names. see also $doc_sect above. 4301da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 4311da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 4321da177e4SLinus Torvaldsmy $section = $section_default; 4331da177e4SLinus Torvaldsmy $section_context = "Context"; 4344092bac7SYacine Belkadimy $section_return = "Return"; 4351da177e4SLinus Torvalds 4361da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvaldsreset_state(); 4391da177e4SLinus Torvalds 4401da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) { 4411da177e4SLinus Torvalds my $cmd = shift @ARGV; 4421da177e4SLinus Torvalds if ($cmd eq "-html") { 4431da177e4SLinus Torvalds $output_mode = "html"; 4444d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_html; 4451da177e4SLinus Torvalds $blankline = $blankline_html; 4461b40c194SDan Luedtke } elsif ($cmd eq "-html5") { 4471b40c194SDan Luedtke $output_mode = "html5"; 4484d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_html5; 4491b40c194SDan Luedtke $blankline = $blankline_html5; 4501da177e4SLinus Torvalds } elsif ($cmd eq "-man") { 4511da177e4SLinus Torvalds $output_mode = "man"; 4524d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 4531da177e4SLinus Torvalds $blankline = $blankline_man; 4541da177e4SLinus Torvalds } elsif ($cmd eq "-text") { 4551da177e4SLinus Torvalds $output_mode = "text"; 4564d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_text; 4571da177e4SLinus Torvalds $blankline = $blankline_text; 458c0d1b6eeSJonathan Corbet } elsif ($cmd eq "-rst") { 459c0d1b6eeSJonathan Corbet $output_mode = "rst"; 460c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 461c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 4621da177e4SLinus Torvalds } elsif ($cmd eq "-docbook") { 4631da177e4SLinus Torvalds $output_mode = "xml"; 4644d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_xml; 4651da177e4SLinus Torvalds $blankline = $blankline_xml; 466eda603f6SJohannes Berg } elsif ($cmd eq "-list") { 467eda603f6SJohannes Berg $output_mode = "list"; 4684d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_list; 469eda603f6SJohannes Berg $blankline = $blankline_list; 4701da177e4SLinus Torvalds } elsif ($cmd eq "-gnome") { 4711da177e4SLinus Torvalds $output_mode = "gnome"; 4724d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_gnome; 4731da177e4SLinus Torvalds $blankline = $blankline_gnome; 4741da177e4SLinus Torvalds } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document 4751da177e4SLinus Torvalds $modulename = shift @ARGV; 4761da177e4SLinus Torvalds } elsif ($cmd eq "-function") { # to only output specific functions 477b6c3f456SJani Nikula $output_selection = OUTPUT_INCLUDE; 4781da177e4SLinus Torvalds $function = shift @ARGV; 4791da177e4SLinus Torvalds $function_table{$function} = 1; 480b6c3f456SJani Nikula } elsif ($cmd eq "-nofunction") { # output all except specific functions 481b6c3f456SJani Nikula $output_selection = OUTPUT_EXCLUDE; 4821da177e4SLinus Torvalds $function = shift @ARGV; 4831da177e4SLinus Torvalds $function_table{$function} = 1; 48486ae2e38SJani Nikula } elsif ($cmd eq "-export") { # only exported symbols 485b6c3f456SJani Nikula $output_selection = OUTPUT_EXPORTED; 48686ae2e38SJani Nikula %function_table = () 48786ae2e38SJani Nikula } elsif ($cmd eq "-internal") { # only non-exported symbols 488b6c3f456SJani Nikula $output_selection = OUTPUT_INTERNAL; 48986ae2e38SJani Nikula %function_table = () 4901da177e4SLinus Torvalds } elsif ($cmd eq "-v") { 4911da177e4SLinus Torvalds $verbose = 1; 4921da177e4SLinus Torvalds } elsif (($cmd eq "-h") || ($cmd eq "--help")) { 4931da177e4SLinus Torvalds usage(); 4944b44595aSJohannes Berg } elsif ($cmd eq '-no-doc-sections') { 4954b44595aSJohannes Berg $no_doc_sections = 1; 496*0b0f5f29SDaniel Vetter } elsif ($cmd eq '-enable-lineno') { 497*0b0f5f29SDaniel Vetter $enable_lineno = 1; 498e946c43aSJohannes Berg } elsif ($cmd eq '-show-not-found') { 499e946c43aSJohannes Berg $show_not_found = 1; 5001da177e4SLinus Torvalds } 5011da177e4SLinus Torvalds} 5021da177e4SLinus Torvalds 5038484baaaSRandy Dunlap# continue execution near EOF; 5048484baaaSRandy Dunlap 50553f049faSBorislav Petkov# get kernel version from env 50653f049faSBorislav Petkovsub get_kernel_version() { 5071b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 50853f049faSBorislav Petkov 50953f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 51053f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 51153f049faSBorislav Petkov } 51253f049faSBorislav Petkov return $version; 51353f049faSBorislav Petkov} 5141da177e4SLinus Torvalds 515*0b0f5f29SDaniel Vetter# 516*0b0f5f29SDaniel Vettersub print_lineno { 517*0b0f5f29SDaniel Vetter my $lineno = shift; 518*0b0f5f29SDaniel Vetter if ($enable_lineno && defined($lineno)) { 519*0b0f5f29SDaniel Vetter print "#define LINENO " . $lineno . "\n"; 520*0b0f5f29SDaniel Vetter } 521*0b0f5f29SDaniel Vetter} 5221da177e4SLinus Torvalds## 5231da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 5241da177e4SLinus Torvalds# 5251da177e4SLinus Torvaldssub dump_section { 52694dc7ad5SRandy Dunlap my $file = shift; 5271da177e4SLinus Torvalds my $name = shift; 5281da177e4SLinus Torvalds my $contents = join "\n", @_; 5291da177e4SLinus Torvalds 53013901ef2SJani Nikula if ($name =~ m/$type_param/) { 5311da177e4SLinus Torvalds# print STDERR "parameter def '$1' = '$contents'\n"; 5321da177e4SLinus Torvalds $name = $1; 5331da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 534a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 535*0b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 536*0b0f5f29SDaniel Vetter $new_start_line = 0; 537ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 538ced69090SRandy Dunlap# print STDERR "parameter def '...' = '$contents'\n"; 539ced69090SRandy Dunlap $name = "..."; 540ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 541a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 542*0b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 543*0b0f5f29SDaniel Vetter $new_start_line = 0; 5441da177e4SLinus Torvalds } else { 5451da177e4SLinus Torvalds# print STDERR "other section '$name' = '$contents'\n"; 54694dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 54732217761SJani Nikula print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; 54832217761SJani Nikula ++$warnings; 54932217761SJani Nikula $sections{$name} .= $contents; 55032217761SJani Nikula } else { 5511da177e4SLinus Torvalds $sections{$name} = $contents; 5521da177e4SLinus Torvalds push @sectionlist, $name; 553*0b0f5f29SDaniel Vetter $section_start_lines{$name} = $new_start_line; 554*0b0f5f29SDaniel Vetter $new_start_line = 0; 5551da177e4SLinus Torvalds } 5561da177e4SLinus Torvalds } 55732217761SJani Nikula} 5581da177e4SLinus Torvalds 5591da177e4SLinus Torvalds## 560b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 561b112e0f7SJohannes Berg# 562b112e0f7SJohannes Bergsub dump_doc_section { 56394dc7ad5SRandy Dunlap my $file = shift; 564b112e0f7SJohannes Berg my $name = shift; 565b112e0f7SJohannes Berg my $contents = join "\n", @_; 566b112e0f7SJohannes Berg 5674b44595aSJohannes Berg if ($no_doc_sections) { 5684b44595aSJohannes Berg return; 5694b44595aSJohannes Berg } 5704b44595aSJohannes Berg 571b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 572b6c3f456SJani Nikula ($output_selection == OUTPUT_INCLUDE && 573b6c3f456SJani Nikula defined($function_table{$name})) || 574b6c3f456SJani Nikula ($output_selection == OUTPUT_EXCLUDE && 575b6c3f456SJani Nikula !defined($function_table{$name}))) 576b112e0f7SJohannes Berg { 57794dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 578b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 579b112e0f7SJohannes Berg 'sections' => \%sections, 580b112e0f7SJohannes Berg 'module' => $modulename, 581b6c3f456SJani Nikula 'content-only' => ($output_selection != OUTPUT_ALL), }); 582b112e0f7SJohannes Berg } 583b112e0f7SJohannes Berg} 584b112e0f7SJohannes Berg 585b112e0f7SJohannes Berg## 5861da177e4SLinus Torvalds# output function 5871da177e4SLinus Torvalds# 5881da177e4SLinus Torvalds# parameterdescs, a hash. 5891da177e4SLinus Torvalds# function => "function name" 5901da177e4SLinus Torvalds# parameterlist => @list of parameters 5911da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 5921da177e4SLinus Torvalds# sectionlist => @list of sections 593a21217daSRandy Dunlap# sections => %section descriptions 5941da177e4SLinus Torvalds# 5951da177e4SLinus Torvalds 5961da177e4SLinus Torvaldssub output_highlight { 5971da177e4SLinus Torvalds my $contents = join "\n",@_; 5981da177e4SLinus Torvalds my $line; 5991da177e4SLinus Torvalds 6001da177e4SLinus Torvalds# DEBUG 6011da177e4SLinus Torvalds# if (!defined $contents) { 6021da177e4SLinus Torvalds# use Carp; 6031da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 6041da177e4SLinus Torvalds# } 6051da177e4SLinus Torvalds 6061b40c194SDan Luedtke if ($output_mode eq "html" || $output_mode eq "html5" || 6071b40c194SDan Luedtke $output_mode eq "xml") { 6086b5b55f6SRandy Dunlap $contents = local_unescape($contents); 6096b5b55f6SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 6102b35f4d9SRandy Dunlap $contents =~ s/\\\\\\/\&/g; 6116b5b55f6SRandy Dunlap } 6123eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 6131da177e4SLinus Torvalds eval $dohighlight; 6141da177e4SLinus Torvalds die $@ if $@; 6153eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 6163eb014a1SRandy Dunlap 6171b40c194SDan Luedtke# strip whitespaces when generating html5 6181b40c194SDan Luedtke if ($output_mode eq "html5") { 6191b40c194SDan Luedtke $contents =~ s/^\s+//; 6201b40c194SDan Luedtke $contents =~ s/\s+$//; 6211b40c194SDan Luedtke } 6221da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 62312ae6779SDaniel Santos if (! $output_preformatted) { 62412ae6779SDaniel Santos $line =~ s/^\s*//; 62512ae6779SDaniel Santos } 6261da177e4SLinus Torvalds if ($line eq ""){ 627e314ba31SDaniel Santos if (! $output_preformatted) { 6286b5b55f6SRandy Dunlap print $lineprefix, local_unescape($blankline); 629e314ba31SDaniel Santos } 6301da177e4SLinus Torvalds } else { 6311da177e4SLinus Torvalds $line =~ s/\\\\\\/\&/g; 632cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 633cdccb316SRandy Dunlap print "\\&$line"; 634cdccb316SRandy Dunlap } else { 6351da177e4SLinus Torvalds print $lineprefix, $line; 6361da177e4SLinus Torvalds } 637cdccb316SRandy Dunlap } 6381da177e4SLinus Torvalds print "\n"; 6391da177e4SLinus Torvalds } 6401da177e4SLinus Torvalds} 6411da177e4SLinus Torvalds 6421da177e4SLinus Torvalds# output sections in html 6431da177e4SLinus Torvaldssub output_section_html(%) { 6441da177e4SLinus Torvalds my %args = %{$_[0]}; 6451da177e4SLinus Torvalds my $section; 6461da177e4SLinus Torvalds 6471da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6481da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 6491da177e4SLinus Torvalds print "<blockquote>\n"; 6501da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6511da177e4SLinus Torvalds print "</blockquote>\n"; 6521da177e4SLinus Torvalds } 6531da177e4SLinus Torvalds} 6541da177e4SLinus Torvalds 6551da177e4SLinus Torvalds# output enum in html 6561da177e4SLinus Torvaldssub output_enum_html(%) { 6571da177e4SLinus Torvalds my %args = %{$_[0]}; 6581da177e4SLinus Torvalds my ($parameter); 6591da177e4SLinus Torvalds my $count; 6601da177e4SLinus Torvalds print "<h2>enum " . $args{'enum'} . "</h2>\n"; 6611da177e4SLinus Torvalds 6621da177e4SLinus Torvalds print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; 6631da177e4SLinus Torvalds $count = 0; 6641da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6651da177e4SLinus Torvalds print " <b>" . $parameter . "</b>"; 6661da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 6671da177e4SLinus Torvalds $count++; 6681da177e4SLinus Torvalds print ",\n"; 6691da177e4SLinus Torvalds } 6701da177e4SLinus Torvalds print "<br>"; 6711da177e4SLinus Torvalds } 6721da177e4SLinus Torvalds print "};<br>\n"; 6731da177e4SLinus Torvalds 6741da177e4SLinus Torvalds print "<h3>Constants</h3>\n"; 6751da177e4SLinus Torvalds print "<dl>\n"; 6761da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6771da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 6781da177e4SLinus Torvalds print "<dd>"; 6791da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter}); 6801da177e4SLinus Torvalds } 6811da177e4SLinus Torvalds print "</dl>\n"; 6821da177e4SLinus Torvalds output_section_html(@_); 6831da177e4SLinus Torvalds print "<hr>\n"; 6841da177e4SLinus Torvalds} 6851da177e4SLinus Torvalds 686d28bee0cSRandy Dunlap# output typedef in html 6871da177e4SLinus Torvaldssub output_typedef_html(%) { 6881da177e4SLinus Torvalds my %args = %{$_[0]}; 6891da177e4SLinus Torvalds my ($parameter); 6901da177e4SLinus Torvalds my $count; 6911da177e4SLinus Torvalds print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; 6921da177e4SLinus Torvalds 6931da177e4SLinus Torvalds print "<b>typedef " . $args{'typedef'} . "</b>\n"; 6941da177e4SLinus Torvalds output_section_html(@_); 6951da177e4SLinus Torvalds print "<hr>\n"; 6961da177e4SLinus Torvalds} 6971da177e4SLinus Torvalds 6981da177e4SLinus Torvalds# output struct in html 6991da177e4SLinus Torvaldssub output_struct_html(%) { 7001da177e4SLinus Torvalds my %args = %{$_[0]}; 7011da177e4SLinus Torvalds my ($parameter); 7021da177e4SLinus Torvalds 703262d9b01SRandy Dunlap print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; 7041da177e4SLinus Torvalds print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; 7051da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7061da177e4SLinus Torvalds if ($parameter =~ /^#/) { 7071da177e4SLinus Torvalds print "$parameter<br>\n"; 7081da177e4SLinus Torvalds next; 7091da177e4SLinus Torvalds } 7101da177e4SLinus Torvalds my $parameter_name = $parameter; 7111da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7121da177e4SLinus Torvalds 7131da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7141da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 7151da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 7161da177e4SLinus Torvalds # pointer-to-function 7173eb014a1SRandy Dunlap print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; 7181da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 7193eb014a1SRandy Dunlap # bitfield 7203eb014a1SRandy Dunlap print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; 7211da177e4SLinus Torvalds } else { 7223eb014a1SRandy Dunlap print " <i>$type</i> <b>$parameter</b>;<br>\n"; 7231da177e4SLinus Torvalds } 7241da177e4SLinus Torvalds } 7251da177e4SLinus Torvalds print "};<br>\n"; 7261da177e4SLinus Torvalds 7271da177e4SLinus Torvalds print "<h3>Members</h3>\n"; 7281da177e4SLinus Torvalds print "<dl>\n"; 7291da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7301da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 7311da177e4SLinus Torvalds 7321da177e4SLinus Torvalds my $parameter_name = $parameter; 7331da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7341da177e4SLinus Torvalds 7351da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7361da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 7371da177e4SLinus Torvalds print "<dd>"; 7381da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7391da177e4SLinus Torvalds } 7401da177e4SLinus Torvalds print "</dl>\n"; 7411da177e4SLinus Torvalds output_section_html(@_); 7421da177e4SLinus Torvalds print "<hr>\n"; 7431da177e4SLinus Torvalds} 7441da177e4SLinus Torvalds 7451da177e4SLinus Torvalds# output function in html 7461da177e4SLinus Torvaldssub output_function_html(%) { 7471da177e4SLinus Torvalds my %args = %{$_[0]}; 7481da177e4SLinus Torvalds my ($parameter, $section); 7491da177e4SLinus Torvalds my $count; 7501da177e4SLinus Torvalds 751262d9b01SRandy Dunlap print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; 7521da177e4SLinus Torvalds print "<i>" . $args{'functiontype'} . "</i>\n"; 7531da177e4SLinus Torvalds print "<b>" . $args{'function'} . "</b>\n"; 7541da177e4SLinus Torvalds print "("; 7551da177e4SLinus Torvalds $count = 0; 7561da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7571da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 7581da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 7591da177e4SLinus Torvalds # pointer-to-function 7601da177e4SLinus Torvalds print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; 7611da177e4SLinus Torvalds } else { 7621da177e4SLinus Torvalds print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; 7631da177e4SLinus Torvalds } 7641da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 7651da177e4SLinus Torvalds $count++; 7661da177e4SLinus Torvalds print ",\n"; 7671da177e4SLinus Torvalds } 7681da177e4SLinus Torvalds } 7691da177e4SLinus Torvalds print ")\n"; 7701da177e4SLinus Torvalds 7711da177e4SLinus Torvalds print "<h3>Arguments</h3>\n"; 7721da177e4SLinus Torvalds print "<dl>\n"; 7731da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7741da177e4SLinus Torvalds my $parameter_name = $parameter; 7751da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7761da177e4SLinus Torvalds 7771da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7781da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 7791da177e4SLinus Torvalds print "<dd>"; 7801da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7811da177e4SLinus Torvalds } 7821da177e4SLinus Torvalds print "</dl>\n"; 7831da177e4SLinus Torvalds output_section_html(@_); 7841da177e4SLinus Torvalds print "<hr>\n"; 7851da177e4SLinus Torvalds} 7861da177e4SLinus Torvalds 787b112e0f7SJohannes Berg# output DOC: block header in html 788b112e0f7SJohannes Bergsub output_blockhead_html(%) { 7891da177e4SLinus Torvalds my %args = %{$_[0]}; 7901da177e4SLinus Torvalds my ($parameter, $section); 7911da177e4SLinus Torvalds my $count; 7921da177e4SLinus Torvalds 7931da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7941da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 7951da177e4SLinus Torvalds print "<ul>\n"; 7961da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7971da177e4SLinus Torvalds print "</ul>\n"; 7981da177e4SLinus Torvalds } 7991da177e4SLinus Torvalds print "<hr>\n"; 8001da177e4SLinus Torvalds} 8011da177e4SLinus Torvalds 8021b40c194SDan Luedtke# output sections in html5 8031b40c194SDan Luedtkesub output_section_html5(%) { 8041b40c194SDan Luedtke my %args = %{$_[0]}; 8051b40c194SDan Luedtke my $section; 8061b40c194SDan Luedtke 8071b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 8081b40c194SDan Luedtke print "<section>\n"; 8091b40c194SDan Luedtke print "<h1>$section</h1>\n"; 8101b40c194SDan Luedtke print "<p>\n"; 8111b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 8121b40c194SDan Luedtke print "</p>\n"; 8131b40c194SDan Luedtke print "</section>\n"; 8141b40c194SDan Luedtke } 8151b40c194SDan Luedtke} 8161b40c194SDan Luedtke 8171b40c194SDan Luedtke# output enum in html5 8181b40c194SDan Luedtkesub output_enum_html5(%) { 8191b40c194SDan Luedtke my %args = %{$_[0]}; 8201b40c194SDan Luedtke my ($parameter); 8211b40c194SDan Luedtke my $count; 8221b40c194SDan Luedtke my $html5id; 8231b40c194SDan Luedtke 8241b40c194SDan Luedtke $html5id = $args{'enum'}; 8251b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8261b40c194SDan Luedtke print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; 8271b40c194SDan Luedtke print "<h1>enum " . $args{'enum'} . "</h1>\n"; 8281b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8291b40c194SDan Luedtke print "<li>"; 8301b40c194SDan Luedtke print "<span class=\"keyword\">enum</span> "; 8311b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; 8321b40c194SDan Luedtke print "</li>\n"; 8331b40c194SDan Luedtke $count = 0; 8341b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8351b40c194SDan Luedtke print "<li class=\"indent\">"; 8361b40c194SDan Luedtke print "<span class=\"param\">" . $parameter . "</span>"; 8371b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 8381b40c194SDan Luedtke $count++; 8391b40c194SDan Luedtke print ","; 8401b40c194SDan Luedtke } 8411b40c194SDan Luedtke print "</li>\n"; 8421b40c194SDan Luedtke } 8431b40c194SDan Luedtke print "<li>};</li>\n"; 8441b40c194SDan Luedtke print "</ol>\n"; 8451b40c194SDan Luedtke 8461b40c194SDan Luedtke print "<section>\n"; 8471b40c194SDan Luedtke print "<h1>Constants</h1>\n"; 8481b40c194SDan Luedtke print "<dl>\n"; 8491b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8501b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 8511b40c194SDan Luedtke print "<dd>"; 8521b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter}); 8531b40c194SDan Luedtke print "</dd>\n"; 8541b40c194SDan Luedtke } 8551b40c194SDan Luedtke print "</dl>\n"; 8561b40c194SDan Luedtke print "</section>\n"; 8571b40c194SDan Luedtke output_section_html5(@_); 8581b40c194SDan Luedtke print "</article>\n"; 8591b40c194SDan Luedtke} 8601b40c194SDan Luedtke 8611b40c194SDan Luedtke# output typedef in html5 8621b40c194SDan Luedtkesub output_typedef_html5(%) { 8631b40c194SDan Luedtke my %args = %{$_[0]}; 8641b40c194SDan Luedtke my ($parameter); 8651b40c194SDan Luedtke my $count; 8661b40c194SDan Luedtke my $html5id; 8671b40c194SDan Luedtke 8681b40c194SDan Luedtke $html5id = $args{'typedef'}; 8691b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8701b40c194SDan Luedtke print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; 8711b40c194SDan Luedtke print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; 8721b40c194SDan Luedtke 8731b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8741b40c194SDan Luedtke print "<li>"; 8751b40c194SDan Luedtke print "<span class=\"keyword\">typedef</span> "; 8761b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; 8771b40c194SDan Luedtke print "</li>\n"; 8781b40c194SDan Luedtke print "</ol>\n"; 8791b40c194SDan Luedtke output_section_html5(@_); 8801b40c194SDan Luedtke print "</article>\n"; 8811b40c194SDan Luedtke} 8821b40c194SDan Luedtke 8831b40c194SDan Luedtke# output struct in html5 8841b40c194SDan Luedtkesub output_struct_html5(%) { 8851b40c194SDan Luedtke my %args = %{$_[0]}; 8861b40c194SDan Luedtke my ($parameter); 8871b40c194SDan Luedtke my $html5id; 8881b40c194SDan Luedtke 8891b40c194SDan Luedtke $html5id = $args{'struct'}; 8901b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8911b40c194SDan Luedtke print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n"; 8921b40c194SDan Luedtke print "<hgroup>\n"; 8931b40c194SDan Luedtke print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>"; 8941b40c194SDan Luedtke print "<h2>". $args{'purpose'} . "</h2>\n"; 8951b40c194SDan Luedtke print "</hgroup>\n"; 8961b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8971b40c194SDan Luedtke print "<li>"; 8981b40c194SDan Luedtke print "<span class=\"type\">" . $args{'type'} . "</span> "; 8991b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'struct'} . "</span> {"; 9001b40c194SDan Luedtke print "</li>\n"; 9011b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9021b40c194SDan Luedtke print "<li class=\"indent\">"; 9031b40c194SDan Luedtke if ($parameter =~ /^#/) { 9041b40c194SDan Luedtke print "<span class=\"param\">" . $parameter ."</span>\n"; 9051b40c194SDan Luedtke print "</li>\n"; 9061b40c194SDan Luedtke next; 9071b40c194SDan Luedtke } 9081b40c194SDan Luedtke my $parameter_name = $parameter; 9091b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 9101b40c194SDan Luedtke 9111b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 9121b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 9131b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 9141b40c194SDan Luedtke # pointer-to-function 9151b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 9161b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9171b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 9181b40c194SDan Luedtke print "(<span class=\"args\">$2</span>);"; 9191b40c194SDan Luedtke } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 9201b40c194SDan Luedtke # bitfield 9211b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 9221b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9231b40c194SDan Luedtke print "<span class=\"bits\">$2</span>;"; 9241b40c194SDan Luedtke } else { 9251b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 9261b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>;"; 9271b40c194SDan Luedtke } 9281b40c194SDan Luedtke print "</li>\n"; 9291b40c194SDan Luedtke } 9301b40c194SDan Luedtke print "<li>};</li>\n"; 9311b40c194SDan Luedtke print "</ol>\n"; 9321b40c194SDan Luedtke 9331b40c194SDan Luedtke print "<section>\n"; 9341b40c194SDan Luedtke print "<h1>Members</h1>\n"; 9351b40c194SDan Luedtke print "<dl>\n"; 9361b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9371b40c194SDan Luedtke ($parameter =~ /^#/) && next; 9381b40c194SDan Luedtke 9391b40c194SDan Luedtke my $parameter_name = $parameter; 9401b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 9411b40c194SDan Luedtke 9421b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 9431b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 9441b40c194SDan Luedtke print "<dd>"; 9451b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 9461b40c194SDan Luedtke print "</dd>\n"; 9471b40c194SDan Luedtke } 9481b40c194SDan Luedtke print "</dl>\n"; 9491b40c194SDan Luedtke print "</section>\n"; 9501b40c194SDan Luedtke output_section_html5(@_); 9511b40c194SDan Luedtke print "</article>\n"; 9521b40c194SDan Luedtke} 9531b40c194SDan Luedtke 9541b40c194SDan Luedtke# output function in html5 9551b40c194SDan Luedtkesub output_function_html5(%) { 9561b40c194SDan Luedtke my %args = %{$_[0]}; 9571b40c194SDan Luedtke my ($parameter, $section); 9581b40c194SDan Luedtke my $count; 9591b40c194SDan Luedtke my $html5id; 9601b40c194SDan Luedtke 9611b40c194SDan Luedtke $html5id = $args{'function'}; 9621b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 9631b40c194SDan Luedtke print "<article class=\"function\" id=\"func:". $html5id . "\">\n"; 9641b40c194SDan Luedtke print "<hgroup>\n"; 9651b40c194SDan Luedtke print "<h1>" . $args{'function'} . "</h1>"; 9661b40c194SDan Luedtke print "<h2>" . $args{'purpose'} . "</h2>\n"; 9671b40c194SDan Luedtke print "</hgroup>\n"; 9681b40c194SDan Luedtke print "<ol class=\"code\">\n"; 9691b40c194SDan Luedtke print "<li>"; 9701b40c194SDan Luedtke print "<span class=\"type\">" . $args{'functiontype'} . "</span> "; 9711b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'function'} . "</span> ("; 9721b40c194SDan Luedtke print "</li>"; 9731b40c194SDan Luedtke $count = 0; 9741b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9751b40c194SDan Luedtke print "<li class=\"indent\">"; 9761b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 9771b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 9781b40c194SDan Luedtke # pointer-to-function 9791b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 9801b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9811b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 9821b40c194SDan Luedtke print "(<span class=\"args\">$2</span>)"; 9831b40c194SDan Luedtke } else { 9841b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 9851b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9861b40c194SDan Luedtke } 9871b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 9881b40c194SDan Luedtke $count++; 9891b40c194SDan Luedtke print ","; 9901b40c194SDan Luedtke } 9911b40c194SDan Luedtke print "</li>\n"; 9921b40c194SDan Luedtke } 9931b40c194SDan Luedtke print "<li>)</li>\n"; 9941b40c194SDan Luedtke print "</ol>\n"; 9951b40c194SDan Luedtke 9961b40c194SDan Luedtke print "<section>\n"; 9971b40c194SDan Luedtke print "<h1>Arguments</h1>\n"; 9981b40c194SDan Luedtke print "<p>\n"; 9991b40c194SDan Luedtke print "<dl>\n"; 10001b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 10011b40c194SDan Luedtke my $parameter_name = $parameter; 10021b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 10031b40c194SDan Luedtke 10041b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 10051b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 10061b40c194SDan Luedtke print "<dd>"; 10071b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 10081b40c194SDan Luedtke print "</dd>\n"; 10091b40c194SDan Luedtke } 10101b40c194SDan Luedtke print "</dl>\n"; 10111b40c194SDan Luedtke print "</section>\n"; 10121b40c194SDan Luedtke output_section_html5(@_); 10131b40c194SDan Luedtke print "</article>\n"; 10141b40c194SDan Luedtke} 10151b40c194SDan Luedtke 10161b40c194SDan Luedtke# output DOC: block header in html5 10171b40c194SDan Luedtkesub output_blockhead_html5(%) { 10181b40c194SDan Luedtke my %args = %{$_[0]}; 10191b40c194SDan Luedtke my ($parameter, $section); 10201b40c194SDan Luedtke my $count; 10211b40c194SDan Luedtke my $html5id; 10221b40c194SDan Luedtke 10231b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 10241b40c194SDan Luedtke $html5id = $section; 10251b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 10261b40c194SDan Luedtke print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n"; 10271b40c194SDan Luedtke print "<h1>$section</h1>\n"; 10281b40c194SDan Luedtke print "<p>\n"; 10291b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 10301b40c194SDan Luedtke print "</p>\n"; 10311b40c194SDan Luedtke } 10321b40c194SDan Luedtke print "</article>\n"; 10331b40c194SDan Luedtke} 10341b40c194SDan Luedtke 10351da177e4SLinus Torvaldssub output_section_xml(%) { 10361da177e4SLinus Torvalds my %args = %{$_[0]}; 10371da177e4SLinus Torvalds my $section; 10381da177e4SLinus Torvalds # print out each section 10391da177e4SLinus Torvalds $lineprefix=" "; 10401da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1041c73894c1SRich Walker print "<refsect1>\n"; 1042c73894c1SRich Walker print "<title>$section</title>\n"; 10431da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 1044c73894c1SRich Walker print "<informalexample><programlisting>\n"; 1045e314ba31SDaniel Santos $output_preformatted = 1; 1046c73894c1SRich Walker } else { 1047c73894c1SRich Walker print "<para>\n"; 10481da177e4SLinus Torvalds } 10491da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1050e314ba31SDaniel Santos $output_preformatted = 0; 10511da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 1052c73894c1SRich Walker print "</programlisting></informalexample>\n"; 1053c73894c1SRich Walker } else { 1054c73894c1SRich Walker print "</para>\n"; 10551da177e4SLinus Torvalds } 1056c73894c1SRich Walker print "</refsect1>\n"; 10571da177e4SLinus Torvalds } 10581da177e4SLinus Torvalds} 10591da177e4SLinus Torvalds 10601da177e4SLinus Torvalds# output function in XML DocBook 10611da177e4SLinus Torvaldssub output_function_xml(%) { 10621da177e4SLinus Torvalds my %args = %{$_[0]}; 10631da177e4SLinus Torvalds my ($parameter, $section); 10641da177e4SLinus Torvalds my $count; 10651da177e4SLinus Torvalds my $id; 10661da177e4SLinus Torvalds 10671da177e4SLinus Torvalds $id = "API-" . $args{'function'}; 10681da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 10691da177e4SLinus Torvalds 10705449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 10718b0c2d98SMartin Waitz print "<refentryinfo>\n"; 10728b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 10738b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 10748b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 10758b0c2d98SMartin Waitz print "</refentryinfo>\n"; 10761da177e4SLinus Torvalds print "<refmeta>\n"; 10775449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; 10788b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 10790366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 10801da177e4SLinus Torvalds print "</refmeta>\n"; 10811da177e4SLinus Torvalds print "<refnamediv>\n"; 10821da177e4SLinus Torvalds print " <refname>" . $args{'function'} . "</refname>\n"; 10831da177e4SLinus Torvalds print " <refpurpose>\n"; 10841da177e4SLinus Torvalds print " "; 10851da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 10861da177e4SLinus Torvalds print " </refpurpose>\n"; 10871da177e4SLinus Torvalds print "</refnamediv>\n"; 10881da177e4SLinus Torvalds 10891da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 10901da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 10911da177e4SLinus Torvalds print " <funcsynopsis><funcprototype>\n"; 10921da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 10931da177e4SLinus Torvalds print "<function>" . $args{'function'} . " </function></funcdef>\n"; 10941da177e4SLinus Torvalds 10951da177e4SLinus Torvalds $count = 0; 10961da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 10971da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10981da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 10991da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 11001da177e4SLinus Torvalds # pointer-to-function 11011da177e4SLinus Torvalds print " <paramdef>$1<parameter>$parameter</parameter>)\n"; 11021da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 11031da177e4SLinus Torvalds } else { 11041da177e4SLinus Torvalds print " <paramdef>" . $type; 11051da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 11061da177e4SLinus Torvalds } 11071da177e4SLinus Torvalds } 11081da177e4SLinus Torvalds } else { 11096013d544SMartin Waitz print " <void/>\n"; 11101da177e4SLinus Torvalds } 11111da177e4SLinus Torvalds print " </funcprototype></funcsynopsis>\n"; 11121da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 11131da177e4SLinus Torvalds 11141da177e4SLinus Torvalds # print parameters 11151da177e4SLinus Torvalds print "<refsect1>\n <title>Arguments</title>\n"; 11161da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 11171da177e4SLinus Torvalds print " <variablelist>\n"; 11181da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11191da177e4SLinus Torvalds my $parameter_name = $parameter; 11201da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11211da177e4SLinus Torvalds 11221da177e4SLinus Torvalds print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; 11231da177e4SLinus Torvalds print " <listitem>\n <para>\n"; 11241da177e4SLinus Torvalds $lineprefix=" "; 11251da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 11261da177e4SLinus Torvalds print " </para>\n </listitem>\n </varlistentry>\n"; 11271da177e4SLinus Torvalds } 11281da177e4SLinus Torvalds print " </variablelist>\n"; 11291da177e4SLinus Torvalds } else { 11301da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 11311da177e4SLinus Torvalds } 11321da177e4SLinus Torvalds print "</refsect1>\n"; 11331da177e4SLinus Torvalds 11341da177e4SLinus Torvalds output_section_xml(@_); 11351da177e4SLinus Torvalds print "</refentry>\n\n"; 11361da177e4SLinus Torvalds} 11371da177e4SLinus Torvalds 11381da177e4SLinus Torvalds# output struct in XML DocBook 11391da177e4SLinus Torvaldssub output_struct_xml(%) { 11401da177e4SLinus Torvalds my %args = %{$_[0]}; 11411da177e4SLinus Torvalds my ($parameter, $section); 11421da177e4SLinus Torvalds my $id; 11431da177e4SLinus Torvalds 11441da177e4SLinus Torvalds $id = "API-struct-" . $args{'struct'}; 11451da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 11461da177e4SLinus Torvalds 11475449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 11488b0c2d98SMartin Waitz print "<refentryinfo>\n"; 11498b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 11508b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 11518b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 11528b0c2d98SMartin Waitz print "</refentryinfo>\n"; 11531da177e4SLinus Torvalds print "<refmeta>\n"; 11545449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; 11558b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 11560366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 11571da177e4SLinus Torvalds print "</refmeta>\n"; 11581da177e4SLinus Torvalds print "<refnamediv>\n"; 11591da177e4SLinus Torvalds print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; 11601da177e4SLinus Torvalds print " <refpurpose>\n"; 11611da177e4SLinus Torvalds print " "; 11621da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 11631da177e4SLinus Torvalds print " </refpurpose>\n"; 11641da177e4SLinus Torvalds print "</refnamediv>\n"; 11651da177e4SLinus Torvalds 11661da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 11671da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 11681da177e4SLinus Torvalds print " <programlisting>\n"; 11691da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 11701da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11711da177e4SLinus Torvalds if ($parameter =~ /^#/) { 11722b35f4d9SRandy Dunlap my $prm = $parameter; 11732b35f4d9SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 11742b35f4d9SRandy Dunlap # This allows us to have #define macros interspersed in a struct. 11752b35f4d9SRandy Dunlap $prm =~ s/\\\\\\/\&/g; 11762b35f4d9SRandy Dunlap print "$prm\n"; 11771da177e4SLinus Torvalds next; 11781da177e4SLinus Torvalds } 11791da177e4SLinus Torvalds 11801da177e4SLinus Torvalds my $parameter_name = $parameter; 11811da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11821da177e4SLinus Torvalds 11831da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 11841da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 11851da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 11861da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 11871da177e4SLinus Torvalds # pointer-to-function 11881da177e4SLinus Torvalds print " $1 $parameter) ($2);\n"; 11891da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 119051f5a0c8SRandy Dunlap # bitfield 11911da177e4SLinus Torvalds print " $1 $parameter$2;\n"; 11921da177e4SLinus Torvalds } else { 11931da177e4SLinus Torvalds print " " . $type . " " . $parameter . ";\n"; 11941da177e4SLinus Torvalds } 11951da177e4SLinus Torvalds } 11961da177e4SLinus Torvalds print "};"; 11971da177e4SLinus Torvalds print " </programlisting>\n"; 11981da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 11991da177e4SLinus Torvalds 12001da177e4SLinus Torvalds print " <refsect1>\n"; 12011da177e4SLinus Torvalds print " <title>Members</title>\n"; 12021da177e4SLinus Torvalds 120339f00c08SRandy Dunlap if ($#{$args{'parameterlist'}} >= 0) { 12041da177e4SLinus Torvalds print " <variablelist>\n"; 12051da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12061da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 12071da177e4SLinus Torvalds 12081da177e4SLinus Torvalds my $parameter_name = $parameter; 12091da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12101da177e4SLinus Torvalds 12111da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 12121da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 12131da177e4SLinus Torvalds print " <varlistentry>"; 12141da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 12151da177e4SLinus Torvalds print " <listitem><para>\n"; 12161da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 12171da177e4SLinus Torvalds print " </para></listitem>\n"; 12181da177e4SLinus Torvalds print " </varlistentry>\n"; 12191da177e4SLinus Torvalds } 12201da177e4SLinus Torvalds print " </variablelist>\n"; 122139f00c08SRandy Dunlap } else { 122239f00c08SRandy Dunlap print " <para>\n None\n </para>\n"; 122339f00c08SRandy Dunlap } 12241da177e4SLinus Torvalds print " </refsect1>\n"; 12251da177e4SLinus Torvalds 12261da177e4SLinus Torvalds output_section_xml(@_); 12271da177e4SLinus Torvalds 12281da177e4SLinus Torvalds print "</refentry>\n\n"; 12291da177e4SLinus Torvalds} 12301da177e4SLinus Torvalds 12311da177e4SLinus Torvalds# output enum in XML DocBook 12321da177e4SLinus Torvaldssub output_enum_xml(%) { 12331da177e4SLinus Torvalds my %args = %{$_[0]}; 12341da177e4SLinus Torvalds my ($parameter, $section); 12351da177e4SLinus Torvalds my $count; 12361da177e4SLinus Torvalds my $id; 12371da177e4SLinus Torvalds 12381da177e4SLinus Torvalds $id = "API-enum-" . $args{'enum'}; 12391da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12401da177e4SLinus Torvalds 12415449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 12428b0c2d98SMartin Waitz print "<refentryinfo>\n"; 12438b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 12448b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 12458b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 12468b0c2d98SMartin Waitz print "</refentryinfo>\n"; 12471da177e4SLinus Torvalds print "<refmeta>\n"; 12485449bc94SPavel Pisa print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; 12498b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 12500366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 12511da177e4SLinus Torvalds print "</refmeta>\n"; 12521da177e4SLinus Torvalds print "<refnamediv>\n"; 12531da177e4SLinus Torvalds print " <refname>enum " . $args{'enum'} . "</refname>\n"; 12541da177e4SLinus Torvalds print " <refpurpose>\n"; 12551da177e4SLinus Torvalds print " "; 12561da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 12571da177e4SLinus Torvalds print " </refpurpose>\n"; 12581da177e4SLinus Torvalds print "</refnamediv>\n"; 12591da177e4SLinus Torvalds 12601da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 12611da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 12621da177e4SLinus Torvalds print " <programlisting>\n"; 12631da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 12641da177e4SLinus Torvalds $count = 0; 12651da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12661da177e4SLinus Torvalds print " $parameter"; 12671da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 12681da177e4SLinus Torvalds $count++; 12691da177e4SLinus Torvalds print ","; 12701da177e4SLinus Torvalds } 12711da177e4SLinus Torvalds print "\n"; 12721da177e4SLinus Torvalds } 12731da177e4SLinus Torvalds print "};"; 12741da177e4SLinus Torvalds print " </programlisting>\n"; 12751da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 12761da177e4SLinus Torvalds 12771da177e4SLinus Torvalds print "<refsect1>\n"; 12781da177e4SLinus Torvalds print " <title>Constants</title>\n"; 12791da177e4SLinus Torvalds print " <variablelist>\n"; 12801da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12811da177e4SLinus Torvalds my $parameter_name = $parameter; 12821da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12831da177e4SLinus Torvalds 12841da177e4SLinus Torvalds print " <varlistentry>"; 12851da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 12861da177e4SLinus Torvalds print " <listitem><para>\n"; 12871da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 12881da177e4SLinus Torvalds print " </para></listitem>\n"; 12891da177e4SLinus Torvalds print " </varlistentry>\n"; 12901da177e4SLinus Torvalds } 12911da177e4SLinus Torvalds print " </variablelist>\n"; 12921da177e4SLinus Torvalds print "</refsect1>\n"; 12931da177e4SLinus Torvalds 12941da177e4SLinus Torvalds output_section_xml(@_); 12951da177e4SLinus Torvalds 12961da177e4SLinus Torvalds print "</refentry>\n\n"; 12971da177e4SLinus Torvalds} 12981da177e4SLinus Torvalds 12991da177e4SLinus Torvalds# output typedef in XML DocBook 13001da177e4SLinus Torvaldssub output_typedef_xml(%) { 13011da177e4SLinus Torvalds my %args = %{$_[0]}; 13021da177e4SLinus Torvalds my ($parameter, $section); 13031da177e4SLinus Torvalds my $id; 13041da177e4SLinus Torvalds 13051da177e4SLinus Torvalds $id = "API-typedef-" . $args{'typedef'}; 13061da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13071da177e4SLinus Torvalds 13085449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 13098b0c2d98SMartin Waitz print "<refentryinfo>\n"; 13108b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 13118b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 13128b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 13138b0c2d98SMartin Waitz print "</refentryinfo>\n"; 13141da177e4SLinus Torvalds print "<refmeta>\n"; 13155449bc94SPavel Pisa print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; 13168b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 13171da177e4SLinus Torvalds print "</refmeta>\n"; 13181da177e4SLinus Torvalds print "<refnamediv>\n"; 13191da177e4SLinus Torvalds print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; 13201da177e4SLinus Torvalds print " <refpurpose>\n"; 13211da177e4SLinus Torvalds print " "; 13221da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 13231da177e4SLinus Torvalds print " </refpurpose>\n"; 13241da177e4SLinus Torvalds print "</refnamediv>\n"; 13251da177e4SLinus Torvalds 13261da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 13271da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 13281da177e4SLinus Torvalds print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; 13291da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 13301da177e4SLinus Torvalds 13311da177e4SLinus Torvalds output_section_xml(@_); 13321da177e4SLinus Torvalds 13331da177e4SLinus Torvalds print "</refentry>\n\n"; 13341da177e4SLinus Torvalds} 13351da177e4SLinus Torvalds 13361da177e4SLinus Torvalds# output in XML DocBook 1337b112e0f7SJohannes Bergsub output_blockhead_xml(%) { 13381da177e4SLinus Torvalds my %args = %{$_[0]}; 13391da177e4SLinus Torvalds my ($parameter, $section); 13401da177e4SLinus Torvalds my $count; 13411da177e4SLinus Torvalds 13421da177e4SLinus Torvalds my $id = $args{'module'}; 13431da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13441da177e4SLinus Torvalds 13451da177e4SLinus Torvalds # print out each section 13461da177e4SLinus Torvalds $lineprefix=" "; 13471da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1348b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1349b112e0f7SJohannes Berg print "<refsect1>\n <title>$section</title>\n"; 1350b112e0f7SJohannes Berg } 13511da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13521da177e4SLinus Torvalds print "<example><para>\n"; 1353e314ba31SDaniel Santos $output_preformatted = 1; 1354b112e0f7SJohannes Berg } else { 1355b112e0f7SJohannes Berg print "<para>\n"; 13561da177e4SLinus Torvalds } 13571da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1358e314ba31SDaniel Santos $output_preformatted = 0; 13591da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13601da177e4SLinus Torvalds print "</para></example>\n"; 1361b112e0f7SJohannes Berg } else { 1362b112e0f7SJohannes Berg print "</para>"; 13631da177e4SLinus Torvalds } 1364b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1365b112e0f7SJohannes Berg print "\n</refsect1>\n"; 1366b112e0f7SJohannes Berg } 13671da177e4SLinus Torvalds } 13681da177e4SLinus Torvalds 13691da177e4SLinus Torvalds print "\n\n"; 13701da177e4SLinus Torvalds} 13711da177e4SLinus Torvalds 13721da177e4SLinus Torvalds# output in XML DocBook 13731da177e4SLinus Torvaldssub output_function_gnome { 13741da177e4SLinus Torvalds my %args = %{$_[0]}; 13751da177e4SLinus Torvalds my ($parameter, $section); 13761da177e4SLinus Torvalds my $count; 13771da177e4SLinus Torvalds my $id; 13781da177e4SLinus Torvalds 13791da177e4SLinus Torvalds $id = $args{'module'} . "-" . $args{'function'}; 13801da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13811da177e4SLinus Torvalds 13821da177e4SLinus Torvalds print "<sect2>\n"; 13831da177e4SLinus Torvalds print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; 13841da177e4SLinus Torvalds 13851da177e4SLinus Torvalds print " <funcsynopsis>\n"; 13861da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 13871da177e4SLinus Torvalds print "<function>" . $args{'function'} . " "; 13881da177e4SLinus Torvalds print "</function></funcdef>\n"; 13891da177e4SLinus Torvalds 13901da177e4SLinus Torvalds $count = 0; 13911da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 13921da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13931da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 13941da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 13951da177e4SLinus Torvalds # pointer-to-function 13961da177e4SLinus Torvalds print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; 13971da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 13981da177e4SLinus Torvalds } else { 13991da177e4SLinus Torvalds print " <paramdef>" . $type; 14001da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 14011da177e4SLinus Torvalds } 14021da177e4SLinus Torvalds } 14031da177e4SLinus Torvalds } else { 14041da177e4SLinus Torvalds print " <void>\n"; 14051da177e4SLinus Torvalds } 14061da177e4SLinus Torvalds print " </funcsynopsis>\n"; 14071da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 14081da177e4SLinus Torvalds print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; 14091da177e4SLinus Torvalds print "<tgroup cols=\"2\">\n"; 14101da177e4SLinus Torvalds print "<colspec colwidth=\"2*\">\n"; 14111da177e4SLinus Torvalds print "<colspec colwidth=\"8*\">\n"; 14121da177e4SLinus Torvalds print "<tbody>\n"; 14131da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14141da177e4SLinus Torvalds my $parameter_name = $parameter; 14151da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14161da177e4SLinus Torvalds 14171da177e4SLinus Torvalds print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; 14181da177e4SLinus Torvalds print " <entry>\n"; 14191da177e4SLinus Torvalds $lineprefix=" "; 14201da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14211da177e4SLinus Torvalds print " </entry></row>\n"; 14221da177e4SLinus Torvalds } 14231da177e4SLinus Torvalds print " </tbody></tgroup></informaltable>\n"; 14241da177e4SLinus Torvalds } else { 14251da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 14261da177e4SLinus Torvalds } 14271da177e4SLinus Torvalds 14281da177e4SLinus Torvalds # print out each section 14291da177e4SLinus Torvalds $lineprefix=" "; 14301da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14311da177e4SLinus Torvalds print "<simplesect>\n <title>$section</title>\n"; 14321da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 14331da177e4SLinus Torvalds print "<example><programlisting>\n"; 1434e314ba31SDaniel Santos $output_preformatted = 1; 14351da177e4SLinus Torvalds } else { 14361da177e4SLinus Torvalds } 14371da177e4SLinus Torvalds print "<para>\n"; 14381da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1439e314ba31SDaniel Santos $output_preformatted = 0; 14401da177e4SLinus Torvalds print "</para>\n"; 14411da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 14421da177e4SLinus Torvalds print "</programlisting></example>\n"; 14431da177e4SLinus Torvalds } else { 14441da177e4SLinus Torvalds } 14451da177e4SLinus Torvalds print " </simplesect>\n"; 14461da177e4SLinus Torvalds } 14471da177e4SLinus Torvalds 14481da177e4SLinus Torvalds print "</sect2>\n\n"; 14491da177e4SLinus Torvalds} 14501da177e4SLinus Torvalds 14511da177e4SLinus Torvalds## 14521da177e4SLinus Torvalds# output function in man 14531da177e4SLinus Torvaldssub output_function_man(%) { 14541da177e4SLinus Torvalds my %args = %{$_[0]}; 14551da177e4SLinus Torvalds my ($parameter, $section); 14561da177e4SLinus Torvalds my $count; 14571da177e4SLinus Torvalds 14581da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 14591da177e4SLinus Torvalds 14601da177e4SLinus Torvalds print ".SH NAME\n"; 14611da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 14621da177e4SLinus Torvalds 14631da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 1464a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 14651da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 1466a21217daSRandy Dunlap } else { 1467a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 1468a21217daSRandy Dunlap } 14691da177e4SLinus Torvalds $count = 0; 14701da177e4SLinus Torvalds my $parenth = "("; 14711da177e4SLinus Torvalds my $post = ","; 14721da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 14731da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 14741da177e4SLinus Torvalds $post = ");"; 14751da177e4SLinus Torvalds } 14761da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 14771da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 14781da177e4SLinus Torvalds # pointer-to-function 14791da177e4SLinus Torvalds print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 14801da177e4SLinus Torvalds } else { 14811da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 14821da177e4SLinus Torvalds print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 14831da177e4SLinus Torvalds } 14841da177e4SLinus Torvalds $count++; 14851da177e4SLinus Torvalds $parenth = ""; 14861da177e4SLinus Torvalds } 14871da177e4SLinus Torvalds 14881da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 14891da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14901da177e4SLinus Torvalds my $parameter_name = $parameter; 14911da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14921da177e4SLinus Torvalds 14931da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 14941da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14951da177e4SLinus Torvalds } 14961da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14971da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 14981da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 14991da177e4SLinus Torvalds } 15001da177e4SLinus Torvalds} 15011da177e4SLinus Torvalds 15021da177e4SLinus Torvalds## 15031da177e4SLinus Torvalds# output enum in man 15041da177e4SLinus Torvaldssub output_enum_man(%) { 15051da177e4SLinus Torvalds my %args = %{$_[0]}; 15061da177e4SLinus Torvalds my ($parameter, $section); 15071da177e4SLinus Torvalds my $count; 15081da177e4SLinus Torvalds 15091da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 15101da177e4SLinus Torvalds 15111da177e4SLinus Torvalds print ".SH NAME\n"; 15121da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 15131da177e4SLinus Torvalds 15141da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 15151da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 15161da177e4SLinus Torvalds $count = 0; 15171da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15181da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 15191da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 15201da177e4SLinus Torvalds print "\n};\n"; 15211da177e4SLinus Torvalds last; 15221da177e4SLinus Torvalds } 15231da177e4SLinus Torvalds else { 15241da177e4SLinus Torvalds print ", \n.br\n"; 15251da177e4SLinus Torvalds } 15261da177e4SLinus Torvalds $count++; 15271da177e4SLinus Torvalds } 15281da177e4SLinus Torvalds 15291da177e4SLinus Torvalds print ".SH Constants\n"; 15301da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15311da177e4SLinus Torvalds my $parameter_name = $parameter; 15321da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15331da177e4SLinus Torvalds 15341da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 15351da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 15361da177e4SLinus Torvalds } 15371da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15381da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15391da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15401da177e4SLinus Torvalds } 15411da177e4SLinus Torvalds} 15421da177e4SLinus Torvalds 15431da177e4SLinus Torvalds## 15441da177e4SLinus Torvalds# output struct in man 15451da177e4SLinus Torvaldssub output_struct_man(%) { 15461da177e4SLinus Torvalds my %args = %{$_[0]}; 15471da177e4SLinus Torvalds my ($parameter, $section); 15481da177e4SLinus Torvalds 15491da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 15501da177e4SLinus Torvalds 15511da177e4SLinus Torvalds print ".SH NAME\n"; 15521da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 15531da177e4SLinus Torvalds 15541da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 15551da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 15561da177e4SLinus Torvalds 15571da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15581da177e4SLinus Torvalds if ($parameter =~ /^#/) { 15591da177e4SLinus Torvalds print ".BI \"$parameter\"\n.br\n"; 15601da177e4SLinus Torvalds next; 15611da177e4SLinus Torvalds } 15621da177e4SLinus Torvalds my $parameter_name = $parameter; 15631da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15641da177e4SLinus Torvalds 15651da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 15661da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 15671da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 15681da177e4SLinus Torvalds # pointer-to-function 15691da177e4SLinus Torvalds print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; 15701da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 15711d7e1d45SRandy.Dunlap # bitfield 15721d7e1d45SRandy.Dunlap print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; 15731da177e4SLinus Torvalds } else { 15741da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 15751da177e4SLinus Torvalds print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; 15761da177e4SLinus Torvalds } 15771da177e4SLinus Torvalds print "\n.br\n"; 15781da177e4SLinus Torvalds } 15791da177e4SLinus Torvalds print "};\n.br\n"; 15801da177e4SLinus Torvalds 1581c51d3dacSRandy Dunlap print ".SH Members\n"; 15821da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15831da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 15841da177e4SLinus Torvalds 15851da177e4SLinus Torvalds my $parameter_name = $parameter; 15861da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15871da177e4SLinus Torvalds 15881da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 15891da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 15901da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 15911da177e4SLinus Torvalds } 15921da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15931da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15941da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15951da177e4SLinus Torvalds } 15961da177e4SLinus Torvalds} 15971da177e4SLinus Torvalds 15981da177e4SLinus Torvalds## 15991da177e4SLinus Torvalds# output typedef in man 16001da177e4SLinus Torvaldssub output_typedef_man(%) { 16011da177e4SLinus Torvalds my %args = %{$_[0]}; 16021da177e4SLinus Torvalds my ($parameter, $section); 16031da177e4SLinus Torvalds 16041da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 16051da177e4SLinus Torvalds 16061da177e4SLinus Torvalds print ".SH NAME\n"; 16071da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 16081da177e4SLinus Torvalds 16091da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16101da177e4SLinus Torvalds print ".SH \"$section\"\n"; 16111da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16121da177e4SLinus Torvalds } 16131da177e4SLinus Torvalds} 16141da177e4SLinus Torvalds 1615b112e0f7SJohannes Bergsub output_blockhead_man(%) { 16161da177e4SLinus Torvalds my %args = %{$_[0]}; 16171da177e4SLinus Torvalds my ($parameter, $section); 16181da177e4SLinus Torvalds my $count; 16191da177e4SLinus Torvalds 16201da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 16211da177e4SLinus Torvalds 16221da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16231da177e4SLinus Torvalds print ".SH \"$section\"\n"; 16241da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16251da177e4SLinus Torvalds } 16261da177e4SLinus Torvalds} 16271da177e4SLinus Torvalds 16281da177e4SLinus Torvalds## 16291da177e4SLinus Torvalds# output in text 16301da177e4SLinus Torvaldssub output_function_text(%) { 16311da177e4SLinus Torvalds my %args = %{$_[0]}; 16321da177e4SLinus Torvalds my ($parameter, $section); 1633a21217daSRandy Dunlap my $start; 16341da177e4SLinus Torvalds 1635f47634b2SRandy Dunlap print "Name:\n\n"; 1636f47634b2SRandy Dunlap print $args{'function'} . " - " . $args{'purpose'} . "\n"; 1637f47634b2SRandy Dunlap 1638f47634b2SRandy Dunlap print "\nSynopsis:\n\n"; 1639a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 1640a21217daSRandy Dunlap $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1641a21217daSRandy Dunlap } else { 1642a21217daSRandy Dunlap $start = $args{'function'} . " ("; 1643a21217daSRandy Dunlap } 16441da177e4SLinus Torvalds print $start; 1645a21217daSRandy Dunlap 16461da177e4SLinus Torvalds my $count = 0; 16471da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 16481da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 16491da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 16501da177e4SLinus Torvalds # pointer-to-function 16511da177e4SLinus Torvalds print $1 . $parameter . ") (" . $2; 16521da177e4SLinus Torvalds } else { 16531da177e4SLinus Torvalds print $type . " " . $parameter; 16541da177e4SLinus Torvalds } 16551da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 16561da177e4SLinus Torvalds $count++; 16571da177e4SLinus Torvalds print ",\n"; 16581da177e4SLinus Torvalds print " " x length($start); 16591da177e4SLinus Torvalds } else { 16601da177e4SLinus Torvalds print ");\n\n"; 16611da177e4SLinus Torvalds } 16621da177e4SLinus Torvalds } 16631da177e4SLinus Torvalds 16641da177e4SLinus Torvalds print "Arguments:\n\n"; 16651da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16661da177e4SLinus Torvalds my $parameter_name = $parameter; 16671da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16681da177e4SLinus Torvalds 16691da177e4SLinus Torvalds print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; 16701da177e4SLinus Torvalds } 16711da177e4SLinus Torvalds output_section_text(@_); 16721da177e4SLinus Torvalds} 16731da177e4SLinus Torvalds 16741da177e4SLinus Torvalds#output sections in text 16751da177e4SLinus Torvaldssub output_section_text(%) { 16761da177e4SLinus Torvalds my %args = %{$_[0]}; 16771da177e4SLinus Torvalds my $section; 16781da177e4SLinus Torvalds 16791da177e4SLinus Torvalds print "\n"; 16801da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16811da177e4SLinus Torvalds print "$section:\n\n"; 16821da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16831da177e4SLinus Torvalds } 16841da177e4SLinus Torvalds print "\n\n"; 16851da177e4SLinus Torvalds} 16861da177e4SLinus Torvalds 16871da177e4SLinus Torvalds# output enum in text 16881da177e4SLinus Torvaldssub output_enum_text(%) { 16891da177e4SLinus Torvalds my %args = %{$_[0]}; 16901da177e4SLinus Torvalds my ($parameter); 16911da177e4SLinus Torvalds my $count; 16921da177e4SLinus Torvalds print "Enum:\n\n"; 16931da177e4SLinus Torvalds 16941d7e1d45SRandy.Dunlap print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; 16951da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 16961da177e4SLinus Torvalds $count = 0; 16971da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16981da177e4SLinus Torvalds print "\t$parameter"; 16991da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 17001da177e4SLinus Torvalds $count++; 17011da177e4SLinus Torvalds print ","; 17021da177e4SLinus Torvalds } 17031da177e4SLinus Torvalds print "\n"; 17041da177e4SLinus Torvalds } 17051da177e4SLinus Torvalds print "};\n\n"; 17061da177e4SLinus Torvalds 17071da177e4SLinus Torvalds print "Constants:\n\n"; 17081da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17091da177e4SLinus Torvalds print "$parameter\n\t"; 17101da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter} . "\n"; 17111da177e4SLinus Torvalds } 17121da177e4SLinus Torvalds 17131da177e4SLinus Torvalds output_section_text(@_); 17141da177e4SLinus Torvalds} 17151da177e4SLinus Torvalds 17161da177e4SLinus Torvalds# output typedef in text 17171da177e4SLinus Torvaldssub output_typedef_text(%) { 17181da177e4SLinus Torvalds my %args = %{$_[0]}; 17191da177e4SLinus Torvalds my ($parameter); 17201da177e4SLinus Torvalds my $count; 17211da177e4SLinus Torvalds print "Typedef:\n\n"; 17221da177e4SLinus Torvalds 17231d7e1d45SRandy.Dunlap print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; 17241da177e4SLinus Torvalds output_section_text(@_); 17251da177e4SLinus Torvalds} 17261da177e4SLinus Torvalds 17271da177e4SLinus Torvalds# output struct as text 17281da177e4SLinus Torvaldssub output_struct_text(%) { 17291da177e4SLinus Torvalds my %args = %{$_[0]}; 17301da177e4SLinus Torvalds my ($parameter); 17311da177e4SLinus Torvalds 17321d7e1d45SRandy.Dunlap print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; 17331da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 17341da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17351da177e4SLinus Torvalds if ($parameter =~ /^#/) { 17361da177e4SLinus Torvalds print "$parameter\n"; 17371da177e4SLinus Torvalds next; 17381da177e4SLinus Torvalds } 17391da177e4SLinus Torvalds 17401da177e4SLinus Torvalds my $parameter_name = $parameter; 17411da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 17421da177e4SLinus Torvalds 17431da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 17441da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 17451da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 17461da177e4SLinus Torvalds # pointer-to-function 17471da177e4SLinus Torvalds print "\t$1 $parameter) ($2);\n"; 17481da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 174951f5a0c8SRandy Dunlap # bitfield 17501da177e4SLinus Torvalds print "\t$1 $parameter$2;\n"; 17511da177e4SLinus Torvalds } else { 17521da177e4SLinus Torvalds print "\t" . $type . " " . $parameter . ";\n"; 17531da177e4SLinus Torvalds } 17541da177e4SLinus Torvalds } 17551da177e4SLinus Torvalds print "};\n\n"; 17561da177e4SLinus Torvalds 17571da177e4SLinus Torvalds print "Members:\n\n"; 17581da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17591da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 17601da177e4SLinus Torvalds 17611da177e4SLinus Torvalds my $parameter_name = $parameter; 17621da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 17631da177e4SLinus Torvalds 17641da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 17651da177e4SLinus Torvalds print "$parameter\n\t"; 17661da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter_name} . "\n"; 17671da177e4SLinus Torvalds } 17681da177e4SLinus Torvalds print "\n"; 17691da177e4SLinus Torvalds output_section_text(@_); 17701da177e4SLinus Torvalds} 17711da177e4SLinus Torvalds 1772b112e0f7SJohannes Bergsub output_blockhead_text(%) { 17731da177e4SLinus Torvalds my %args = %{$_[0]}; 17741da177e4SLinus Torvalds my ($parameter, $section); 17751da177e4SLinus Torvalds 17761da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 17771da177e4SLinus Torvalds print " $section:\n"; 17781da177e4SLinus Torvalds print " -> "; 17791da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 17801da177e4SLinus Torvalds } 17811da177e4SLinus Torvalds} 17821da177e4SLinus Torvalds 1783c0d1b6eeSJonathan Corbet## 1784c0d1b6eeSJonathan Corbet# output in restructured text 1785c0d1b6eeSJonathan Corbet# 1786c0d1b6eeSJonathan Corbet 1787c0d1b6eeSJonathan Corbet# 1788c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 1789c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 1790c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 1791c0d1b6eeSJonathan Corbet# 1792c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 1793c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1794c0d1b6eeSJonathan Corbet my ($parameter, $section); 1795c0d1b6eeSJonathan Corbet 1796c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 17979e72184bSJani Nikula if ($output_selection != OUTPUT_INCLUDE) { 1798c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 17999e72184bSJani Nikula } 1800*0b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 1801c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1802c0d1b6eeSJonathan Corbet print "\n"; 1803c0d1b6eeSJonathan Corbet } 1804c0d1b6eeSJonathan Corbet} 1805c0d1b6eeSJonathan Corbet 1806c0d1b6eeSJonathan Corbetsub output_highlight_rst { 1807c0d1b6eeSJonathan Corbet my $contents = join "\n",@_; 1808c0d1b6eeSJonathan Corbet my $line; 1809c0d1b6eeSJonathan Corbet 1810c0d1b6eeSJonathan Corbet # undo the evil effects of xml_escape() earlier 1811c0d1b6eeSJonathan Corbet $contents = xml_unescape($contents); 1812c0d1b6eeSJonathan Corbet 1813c0d1b6eeSJonathan Corbet eval $dohighlight; 1814c0d1b6eeSJonathan Corbet die $@ if $@; 1815c0d1b6eeSJonathan Corbet 1816c0d1b6eeSJonathan Corbet foreach $line (split "\n", $contents) { 1817830066a7SJani Nikula print $lineprefix . $line . "\n"; 1818c0d1b6eeSJonathan Corbet } 1819c0d1b6eeSJonathan Corbet} 1820c0d1b6eeSJonathan Corbet 1821c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 1822c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1823c0d1b6eeSJonathan Corbet my ($parameter, $section); 1824c099ff69SJani Nikula my $oldprefix = $lineprefix; 1825c0d1b6eeSJonathan Corbet my $start; 1826c0d1b6eeSJonathan Corbet 1827c0d1b6eeSJonathan Corbet print ".. c:function:: "; 1828c0d1b6eeSJonathan Corbet if ($args{'functiontype'} ne "") { 1829c0d1b6eeSJonathan Corbet $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1830c0d1b6eeSJonathan Corbet } else { 1831c0d1b6eeSJonathan Corbet $start = $args{'function'} . " ("; 1832c0d1b6eeSJonathan Corbet } 1833c0d1b6eeSJonathan Corbet print $start; 1834c0d1b6eeSJonathan Corbet 1835c0d1b6eeSJonathan Corbet my $count = 0; 1836c0d1b6eeSJonathan Corbet foreach my $parameter (@{$args{'parameterlist'}}) { 1837c0d1b6eeSJonathan Corbet if ($count ne 0) { 1838c0d1b6eeSJonathan Corbet print ", "; 1839c0d1b6eeSJonathan Corbet } 1840c0d1b6eeSJonathan Corbet $count++; 1841c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1842c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1843c0d1b6eeSJonathan Corbet # pointer-to-function 1844c0d1b6eeSJonathan Corbet print $1 . $parameter . ") (" . $2; 1845c0d1b6eeSJonathan Corbet } else { 1846c0d1b6eeSJonathan Corbet print $type . " " . $parameter; 1847c0d1b6eeSJonathan Corbet } 1848c0d1b6eeSJonathan Corbet } 1849c099ff69SJani Nikula print ")\n\n"; 1850*0b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1851c099ff69SJani Nikula $lineprefix = " "; 1852c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1853c099ff69SJani Nikula print "\n"; 1854c0d1b6eeSJonathan Corbet 1855ecbcfba1SJani Nikula print "**Parameters**\n\n"; 1856c099ff69SJani Nikula $lineprefix = " "; 1857c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1858c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1859c0d1b6eeSJonathan Corbet #$parameter_name =~ s/\[.*//; 1860c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1861c0d1b6eeSJonathan Corbet 1862c0d1b6eeSJonathan Corbet if ($type ne "") { 1863c0d1b6eeSJonathan Corbet print "``$type $parameter``\n"; 1864c0d1b6eeSJonathan Corbet } else { 1865c0d1b6eeSJonathan Corbet print "``$parameter``\n"; 1866c0d1b6eeSJonathan Corbet } 1867*0b0f5f29SDaniel Vetter 1868*0b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 1869*0b0f5f29SDaniel Vetter 18705e64fa9cSJani Nikula if (defined($args{'parameterdescs'}{$parameter_name}) && 18715e64fa9cSJani Nikula $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 1872c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1873c0d1b6eeSJonathan Corbet } else { 1874d4b08e0cSJani Nikula print " *undescribed*\n"; 1875c0d1b6eeSJonathan Corbet } 1876c0d1b6eeSJonathan Corbet print "\n"; 1877c0d1b6eeSJonathan Corbet } 1878c099ff69SJani Nikula 1879c099ff69SJani Nikula $lineprefix = $oldprefix; 1880c0d1b6eeSJonathan Corbet output_section_rst(@_); 1881c0d1b6eeSJonathan Corbet} 1882c0d1b6eeSJonathan Corbet 1883c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 1884c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1885c0d1b6eeSJonathan Corbet my $section; 1886c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1887c0d1b6eeSJonathan Corbet $lineprefix = ""; 1888c0d1b6eeSJonathan Corbet 1889c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 1890ecbcfba1SJani Nikula print "**$section**\n\n"; 1891*0b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 1892c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1893c0d1b6eeSJonathan Corbet print "\n"; 1894c0d1b6eeSJonathan Corbet } 1895c0d1b6eeSJonathan Corbet print "\n"; 1896c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1897c0d1b6eeSJonathan Corbet} 1898c0d1b6eeSJonathan Corbet 1899c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 1900c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1901c0d1b6eeSJonathan Corbet my ($parameter); 1902c099ff69SJani Nikula my $oldprefix = $lineprefix; 1903c0d1b6eeSJonathan Corbet my $count; 1904c0d1b6eeSJonathan Corbet my $name = "enum " . $args{'enum'}; 190562850976SJani Nikula 190662850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1907*0b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1908c099ff69SJani Nikula $lineprefix = " "; 1909c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1910c099ff69SJani Nikula print "\n"; 1911c0d1b6eeSJonathan Corbet 1912ecbcfba1SJani Nikula print "**Constants**\n\n"; 1913c0d1b6eeSJonathan Corbet $lineprefix = " "; 1914c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1915ecbcfba1SJani Nikula print "``$parameter``\n"; 1916c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 1917c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 1918c0d1b6eeSJonathan Corbet } else { 1919d4b08e0cSJani Nikula print " *undescribed*\n"; 1920c0d1b6eeSJonathan Corbet } 1921c0d1b6eeSJonathan Corbet print "\n"; 1922c0d1b6eeSJonathan Corbet } 1923c099ff69SJani Nikula 1924c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1925c0d1b6eeSJonathan Corbet output_section_rst(@_); 1926c0d1b6eeSJonathan Corbet} 1927c0d1b6eeSJonathan Corbet 1928c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 1929c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1930c0d1b6eeSJonathan Corbet my ($parameter); 1931c099ff69SJani Nikula my $oldprefix = $lineprefix; 1932c0d1b6eeSJonathan Corbet my $name = "typedef " . $args{'typedef'}; 1933c0d1b6eeSJonathan Corbet 193462850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1935*0b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1936c099ff69SJani Nikula $lineprefix = " "; 1937c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1938c099ff69SJani Nikula print "\n"; 1939c0d1b6eeSJonathan Corbet 1940c099ff69SJani Nikula $lineprefix = $oldprefix; 1941c0d1b6eeSJonathan Corbet output_section_rst(@_); 1942c0d1b6eeSJonathan Corbet} 1943c0d1b6eeSJonathan Corbet 1944c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 1945c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1946c0d1b6eeSJonathan Corbet my ($parameter); 1947c099ff69SJani Nikula my $oldprefix = $lineprefix; 1948c0d1b6eeSJonathan Corbet my $name = $args{'type'} . " " . $args{'struct'}; 1949c0d1b6eeSJonathan Corbet 195062850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1951*0b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1952c099ff69SJani Nikula $lineprefix = " "; 1953c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1954c099ff69SJani Nikula print "\n"; 1955c0d1b6eeSJonathan Corbet 1956ecbcfba1SJani Nikula print "**Definition**\n\n"; 1957c0d1b6eeSJonathan Corbet print "::\n\n"; 1958c0d1b6eeSJonathan Corbet print " " . $args{'type'} . " " . $args{'struct'} . " {\n"; 1959c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1960c0d1b6eeSJonathan Corbet if ($parameter =~ /^#/) { 1961c0d1b6eeSJonathan Corbet print " " . "$parameter\n"; 1962c0d1b6eeSJonathan Corbet next; 1963c0d1b6eeSJonathan Corbet } 1964c0d1b6eeSJonathan Corbet 1965c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1966c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 1967c0d1b6eeSJonathan Corbet 1968c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1969c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1970c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1971c0d1b6eeSJonathan Corbet # pointer-to-function 1972c0d1b6eeSJonathan Corbet print " $1 $parameter) ($2);\n"; 1973c0d1b6eeSJonathan Corbet } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 1974c0d1b6eeSJonathan Corbet # bitfield 1975c0d1b6eeSJonathan Corbet print " $1 $parameter$2;\n"; 1976c0d1b6eeSJonathan Corbet } else { 1977c0d1b6eeSJonathan Corbet print " " . $type . " " . $parameter . ";\n"; 1978c0d1b6eeSJonathan Corbet } 1979c0d1b6eeSJonathan Corbet } 1980c0d1b6eeSJonathan Corbet print " };\n\n"; 1981c0d1b6eeSJonathan Corbet 1982ecbcfba1SJani Nikula print "**Members**\n\n"; 1983c099ff69SJani Nikula $lineprefix = " "; 1984c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1985c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 1986c0d1b6eeSJonathan Corbet 1987c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1988c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 1989c0d1b6eeSJonathan Corbet 1990c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1991c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1992*0b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 1993ecbcfba1SJani Nikula print "``$type $parameter``\n"; 1994c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1995c0d1b6eeSJonathan Corbet print "\n"; 1996c0d1b6eeSJonathan Corbet } 1997c0d1b6eeSJonathan Corbet print "\n"; 1998c099ff69SJani Nikula 1999c099ff69SJani Nikula $lineprefix = $oldprefix; 2000c0d1b6eeSJonathan Corbet output_section_rst(@_); 2001c0d1b6eeSJonathan Corbet} 2002c0d1b6eeSJonathan Corbet 2003c0d1b6eeSJonathan Corbet 2004eda603f6SJohannes Berg## list mode output functions 2005eda603f6SJohannes Berg 2006eda603f6SJohannes Bergsub output_function_list(%) { 2007eda603f6SJohannes Berg my %args = %{$_[0]}; 2008eda603f6SJohannes Berg 2009eda603f6SJohannes Berg print $args{'function'} . "\n"; 2010eda603f6SJohannes Berg} 2011eda603f6SJohannes Berg 2012eda603f6SJohannes Berg# output enum in list 2013eda603f6SJohannes Bergsub output_enum_list(%) { 2014eda603f6SJohannes Berg my %args = %{$_[0]}; 2015eda603f6SJohannes Berg print $args{'enum'} . "\n"; 2016eda603f6SJohannes Berg} 2017eda603f6SJohannes Berg 2018eda603f6SJohannes Berg# output typedef in list 2019eda603f6SJohannes Bergsub output_typedef_list(%) { 2020eda603f6SJohannes Berg my %args = %{$_[0]}; 2021eda603f6SJohannes Berg print $args{'typedef'} . "\n"; 2022eda603f6SJohannes Berg} 2023eda603f6SJohannes Berg 2024eda603f6SJohannes Berg# output struct as list 2025eda603f6SJohannes Bergsub output_struct_list(%) { 2026eda603f6SJohannes Berg my %args = %{$_[0]}; 2027eda603f6SJohannes Berg 2028eda603f6SJohannes Berg print $args{'struct'} . "\n"; 2029eda603f6SJohannes Berg} 2030eda603f6SJohannes Berg 2031eda603f6SJohannes Bergsub output_blockhead_list(%) { 2032eda603f6SJohannes Berg my %args = %{$_[0]}; 2033eda603f6SJohannes Berg my ($parameter, $section); 2034eda603f6SJohannes Berg 2035eda603f6SJohannes Berg foreach $section (@{$args{'sectionlist'}}) { 2036eda603f6SJohannes Berg print "DOC: $section\n"; 2037eda603f6SJohannes Berg } 2038eda603f6SJohannes Berg} 2039eda603f6SJohannes Berg 20401da177e4SLinus Torvalds## 204127205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 204227205744SRandy Dunlap# calls the generated, variable output_ function name based on 204327205744SRandy Dunlap# functype and output_mode 20441da177e4SLinus Torvaldssub output_declaration { 20451da177e4SLinus Torvalds no strict 'refs'; 20461da177e4SLinus Torvalds my $name = shift; 20471da177e4SLinus Torvalds my $functype = shift; 20481da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 2049b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 2050b6c3f456SJani Nikula (($output_selection == OUTPUT_INCLUDE || 2051b6c3f456SJani Nikula $output_selection == OUTPUT_EXPORTED) && 205286ae2e38SJani Nikula defined($function_table{$name})) || 2053b6c3f456SJani Nikula (($output_selection == OUTPUT_EXCLUDE || 2054b6c3f456SJani Nikula $output_selection == OUTPUT_INTERNAL) && 205586ae2e38SJani Nikula !($functype eq "function" && defined($function_table{$name})))) 20561da177e4SLinus Torvalds { 20571da177e4SLinus Torvalds &$func(@_); 20581da177e4SLinus Torvalds $section_counter++; 20591da177e4SLinus Torvalds } 20601da177e4SLinus Torvalds} 20611da177e4SLinus Torvalds 20621da177e4SLinus Torvalds## 206327205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 2064b112e0f7SJohannes Bergsub output_blockhead { 20651da177e4SLinus Torvalds no strict 'refs'; 2066b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 20671da177e4SLinus Torvalds &$func(@_); 20681da177e4SLinus Torvalds $section_counter++; 20691da177e4SLinus Torvalds} 20701da177e4SLinus Torvalds 20711da177e4SLinus Torvalds## 20721da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 20731da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 20741da177e4SLinus Torvaldssub dump_declaration($$) { 20751da177e4SLinus Torvalds no strict 'refs'; 20761da177e4SLinus Torvalds my ($prototype, $file) = @_; 20771da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 20781da177e4SLinus Torvalds &$func(@_); 20791da177e4SLinus Torvalds} 20801da177e4SLinus Torvalds 20811da177e4SLinus Torvaldssub dump_union($$) { 20821da177e4SLinus Torvalds dump_struct(@_); 20831da177e4SLinus Torvalds} 20841da177e4SLinus Torvalds 20851da177e4SLinus Torvaldssub dump_struct($$) { 20861da177e4SLinus Torvalds my $x = shift; 20871da177e4SLinus Torvalds my $file = shift; 2088a1d94aa5SRandy Dunlap my $nested; 20891da177e4SLinus Torvalds 20901da177e4SLinus Torvalds if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 209152dc5aecSRandy Dunlap #my $decl_type = $1; 20921da177e4SLinus Torvalds $declaration_name = $2; 20931da177e4SLinus Torvalds my $members = $3; 20941da177e4SLinus Torvalds 20951da177e4SLinus Torvalds # ignore embedded structs or unions 2096a1d94aa5SRandy Dunlap $members =~ s/({.*})//g; 2097a1d94aa5SRandy Dunlap $nested = $1; 20981da177e4SLinus Torvalds 2099aeec46b9SMartin Waitz # ignore members marked private: 21000d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 21010d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 2102aeec46b9SMartin Waitz # strip comments: 2103aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 2104a1d94aa5SRandy Dunlap $nested =~ s/\/\*.*?\*\///gos; 2105d960eea9SRandy Dunlap # strip kmemcheck_bitfield_{begin,end}.*; 2106d960eea9SRandy Dunlap $members =~ s/kmemcheck_bitfield_.*?;//gos; 2107ef5da59fSRandy Dunlap # strip attributes 2108f0074929SJonathan Corbet $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 21097b990789SJohannes Berg $members =~ s/__aligned\s*\([^;]*\)//gos; 2110f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; 2111b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 2112b22b5a9eSConchúr Navid $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 2113aeec46b9SMartin Waitz 21141da177e4SLinus Torvalds create_parameterlist($members, ';', $file); 2115a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); 21161da177e4SLinus Torvalds 21171da177e4SLinus Torvalds output_declaration($declaration_name, 21181da177e4SLinus Torvalds 'struct', 21191da177e4SLinus Torvalds {'struct' => $declaration_name, 21201da177e4SLinus Torvalds 'module' => $modulename, 21211da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 21221da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 21231da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 21241da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 21251da177e4SLinus Torvalds 'sections' => \%sections, 21261da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 21271da177e4SLinus Torvalds 'type' => $decl_type 21281da177e4SLinus Torvalds }); 21291da177e4SLinus Torvalds } 21301da177e4SLinus Torvalds else { 2131d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 21321da177e4SLinus Torvalds ++$errors; 21331da177e4SLinus Torvalds } 21341da177e4SLinus Torvalds} 21351da177e4SLinus Torvalds 21361da177e4SLinus Torvaldssub dump_enum($$) { 21371da177e4SLinus Torvalds my $x = shift; 21381da177e4SLinus Torvalds my $file = shift; 21391da177e4SLinus Torvalds 2140aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 21414468e21eSConchúr Navid # strip #define macros inside enums 21424468e21eSConchúr Navid $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 2143b6d676dbSRandy Dunlap 21441da177e4SLinus Torvalds if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 21451da177e4SLinus Torvalds $declaration_name = $1; 21461da177e4SLinus Torvalds my $members = $2; 21471da177e4SLinus Torvalds 21481da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 21491da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 21501da177e4SLinus Torvalds push @parameterlist, $arg; 21511da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 21521da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 2153d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Enum value '$arg' ". 21541da177e4SLinus Torvalds "not described in enum '$declaration_name'\n"; 21551da177e4SLinus Torvalds } 21561da177e4SLinus Torvalds 21571da177e4SLinus Torvalds } 21581da177e4SLinus Torvalds 21591da177e4SLinus Torvalds output_declaration($declaration_name, 21601da177e4SLinus Torvalds 'enum', 21611da177e4SLinus Torvalds {'enum' => $declaration_name, 21621da177e4SLinus Torvalds 'module' => $modulename, 21631da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 21641da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 21651da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 21661da177e4SLinus Torvalds 'sections' => \%sections, 21671da177e4SLinus Torvalds 'purpose' => $declaration_purpose 21681da177e4SLinus Torvalds }); 21691da177e4SLinus Torvalds } 21701da177e4SLinus Torvalds else { 2171d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 21721da177e4SLinus Torvalds ++$errors; 21731da177e4SLinus Torvalds } 21741da177e4SLinus Torvalds} 21751da177e4SLinus Torvalds 21761da177e4SLinus Torvaldssub dump_typedef($$) { 21771da177e4SLinus Torvalds my $x = shift; 21781da177e4SLinus Torvalds my $file = shift; 21791da177e4SLinus Torvalds 2180aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 218183766452SMauro Carvalho Chehab 218283766452SMauro Carvalho Chehab # Parse function prototypes 218383766452SMauro Carvalho Chehab if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) { 218483766452SMauro Carvalho Chehab # Function typedefs 218583766452SMauro Carvalho Chehab $return_type = $1; 218683766452SMauro Carvalho Chehab $declaration_name = $2; 218783766452SMauro Carvalho Chehab my $args = $3; 218883766452SMauro Carvalho Chehab 218983766452SMauro Carvalho Chehab create_parameterlist($args, ',', $file); 219083766452SMauro Carvalho Chehab 219183766452SMauro Carvalho Chehab output_declaration($declaration_name, 219283766452SMauro Carvalho Chehab 'function', 219383766452SMauro Carvalho Chehab {'function' => $declaration_name, 219483766452SMauro Carvalho Chehab 'module' => $modulename, 219583766452SMauro Carvalho Chehab 'functiontype' => $return_type, 219683766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 219783766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 219883766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 219983766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 220083766452SMauro Carvalho Chehab 'sections' => \%sections, 220183766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 220283766452SMauro Carvalho Chehab }); 220383766452SMauro Carvalho Chehab return; 220483766452SMauro Carvalho Chehab } 220583766452SMauro Carvalho Chehab 22061da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 22071da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 22081da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 22091da177e4SLinus Torvalds } 22101da177e4SLinus Torvalds 22111da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 22121da177e4SLinus Torvalds $declaration_name = $1; 22131da177e4SLinus Torvalds 22141da177e4SLinus Torvalds output_declaration($declaration_name, 22151da177e4SLinus Torvalds 'typedef', 22161da177e4SLinus Torvalds {'typedef' => $declaration_name, 22171da177e4SLinus Torvalds 'module' => $modulename, 22181da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 22191da177e4SLinus Torvalds 'sections' => \%sections, 22201da177e4SLinus Torvalds 'purpose' => $declaration_purpose 22211da177e4SLinus Torvalds }); 22221da177e4SLinus Torvalds } 22231da177e4SLinus Torvalds else { 2224d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 22251da177e4SLinus Torvalds ++$errors; 22261da177e4SLinus Torvalds } 22271da177e4SLinus Torvalds} 22281da177e4SLinus Torvalds 2229a1d94aa5SRandy Dunlapsub save_struct_actual($) { 2230a1d94aa5SRandy Dunlap my $actual = shift; 2231a1d94aa5SRandy Dunlap 2232a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 2233a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 2234a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 2235a1d94aa5SRandy Dunlap} 2236a1d94aa5SRandy Dunlap 22371da177e4SLinus Torvaldssub create_parameterlist($$$) { 22381da177e4SLinus Torvalds my $args = shift; 22391da177e4SLinus Torvalds my $splitter = shift; 22401da177e4SLinus Torvalds my $file = shift; 22411da177e4SLinus Torvalds my $type; 22421da177e4SLinus Torvalds my $param; 22431da177e4SLinus Torvalds 2244a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 22451da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 22461da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 22471da177e4SLinus Torvalds } 22481da177e4SLinus Torvalds 22491da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 22501da177e4SLinus Torvalds # strip comments 22511da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 22521da177e4SLinus Torvalds # strip leading/trailing spaces 22531da177e4SLinus Torvalds $arg =~ s/^\s*//; 22541da177e4SLinus Torvalds $arg =~ s/\s*$//; 22551da177e4SLinus Torvalds $arg =~ s/\s+/ /; 22561da177e4SLinus Torvalds 22571da177e4SLinus Torvalds if ($arg =~ /^#/) { 22581da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 22591da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 22601da177e4SLinus Torvalds # output_* subs. 22611da177e4SLinus Torvalds push_parameter($arg, "", $file); 226200d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 22631da177e4SLinus Torvalds # pointer-to-function 22641da177e4SLinus Torvalds $arg =~ tr/#/,/; 226500d62961SRichard Kennedy $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 22661da177e4SLinus Torvalds $param = $1; 22671da177e4SLinus Torvalds $type = $arg; 226800d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 2269a1d94aa5SRandy Dunlap save_struct_actual($param); 22701da177e4SLinus Torvalds push_parameter($param, $type, $file); 2271aeec46b9SMartin Waitz } elsif ($arg) { 22721da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 22731da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 22741da177e4SLinus Torvalds 22751da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 22761da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 22771da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 22781da177e4SLinus Torvalds } 2279884f2810SBorislav Petkov 2280884f2810SBorislav Petkov my @first_arg; 2281884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 2282884f2810SBorislav Petkov shift @args; 2283884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 2284884f2810SBorislav Petkov push(@first_arg, $2); 2285884f2810SBorislav Petkov } else { 2286884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 2287884f2810SBorislav Petkov } 2288884f2810SBorislav Petkov 22891da177e4SLinus Torvalds unshift(@args, pop @first_arg); 22901da177e4SLinus Torvalds $type = join " ", @first_arg; 22911da177e4SLinus Torvalds 22921da177e4SLinus Torvalds foreach $param (@args) { 22931da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 2294a1d94aa5SRandy Dunlap save_struct_actual($2); 22951da177e4SLinus Torvalds push_parameter($2, "$type $1", $file); 22961da177e4SLinus Torvalds } 22971da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 22987b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 2299a1d94aa5SRandy Dunlap save_struct_actual($1); 23001da177e4SLinus Torvalds push_parameter($1, "$type:$2", $file) 23011da177e4SLinus Torvalds } 23027b97887eSRandy Dunlap } 23031da177e4SLinus Torvalds else { 2304a1d94aa5SRandy Dunlap save_struct_actual($param); 23051da177e4SLinus Torvalds push_parameter($param, $type, $file); 23061da177e4SLinus Torvalds } 23071da177e4SLinus Torvalds } 23081da177e4SLinus Torvalds } 23091da177e4SLinus Torvalds } 23101da177e4SLinus Torvalds} 23111da177e4SLinus Torvalds 23121da177e4SLinus Torvaldssub push_parameter($$$) { 23131da177e4SLinus Torvalds my $param = shift; 23141da177e4SLinus Torvalds my $type = shift; 23151da177e4SLinus Torvalds my $file = shift; 23161da177e4SLinus Torvalds 23175f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 23185f8c7c98SRandy Dunlap ($param eq "}")) { 23195f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 23205f8c7c98SRandy Dunlap } 23215f8c7c98SRandy Dunlap 23225f8c7c98SRandy Dunlap $anon_struct_union = 0; 23231da177e4SLinus Torvalds my $param_name = $param; 23241da177e4SLinus Torvalds $param_name =~ s/\[.*//; 23251da177e4SLinus Torvalds 2326a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 23271da177e4SLinus Torvalds { 2328ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 2329a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 23301da177e4SLinus Torvalds } 2331ced69090SRandy Dunlap } 23321da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 23331da177e4SLinus Torvalds { 23341da177e4SLinus Torvalds $param="void"; 23351da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 23361da177e4SLinus Torvalds } 2337134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 2338134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 2339134fe01bSRandy Dunlap { 2340134fe01bSRandy Dunlap $type = $param; 2341134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 2342134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 23435f8c7c98SRandy Dunlap $anon_struct_union = 1; 2344134fe01bSRandy Dunlap } 2345134fe01bSRandy Dunlap 2346a6d3fe77SMartin Waitz # warn if parameter has no description 2347134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 2348134fe01bSRandy Dunlap # but inline preprocessor statements); 2349134fe01bSRandy Dunlap # also ignore unnamed structs/unions; 23505f8c7c98SRandy Dunlap if (!$anon_struct_union) { 2351a6d3fe77SMartin Waitz if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { 2352a6d3fe77SMartin Waitz 23531da177e4SLinus Torvalds $parameterdescs{$param_name} = $undescribed; 23541da177e4SLinus Torvalds 23551da177e4SLinus Torvalds if (($type eq 'function') || ($type eq 'enum')) { 2356d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Function parameter ". 23571da177e4SLinus Torvalds "or member '$param' not " . 23581da177e4SLinus Torvalds "described in '$declaration_name'\n"; 23591da177e4SLinus Torvalds } 2360d40e1e65SBart Van Assche print STDERR "${file}:$.: warning:" . 23611da177e4SLinus Torvalds " No description found for parameter '$param'\n"; 23621da177e4SLinus Torvalds ++$warnings; 23631da177e4SLinus Torvalds } 2364134fe01bSRandy Dunlap } 23651da177e4SLinus Torvalds 23662b35f4d9SRandy Dunlap $param = xml_escape($param); 23672b35f4d9SRandy Dunlap 236825985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 2369e34e7dbbSRandy Dunlap # on @parameterlist; 2370e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 2371e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 2372e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 2373e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 2374e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 2375e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 2376e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 23771da177e4SLinus Torvalds push @parameterlist, $param; 23781da177e4SLinus Torvalds $parametertypes{$param} = $type; 23791da177e4SLinus Torvalds} 23801da177e4SLinus Torvalds 2381a1d94aa5SRandy Dunlapsub check_sections($$$$$$) { 2382a1d94aa5SRandy Dunlap my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; 2383a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 2384a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 2385a1d94aa5SRandy Dunlap my $err; 2386a1d94aa5SRandy Dunlap my ($px, $sx); 2387a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 2388a1d94aa5SRandy Dunlap 2389a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 2390a1d94aa5SRandy Dunlap $err = 1; 2391a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 2392a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 2393a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 23941f3a6688SJohannes Berg $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 2395e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 2396e34e7dbbSRandy Dunlap # however, the original param string may contain 2397e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 2398e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 2399e34e7dbbSRandy Dunlap # parameter list is split at spaces; 2400e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 2401e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 2402e34e7dbbSRandy Dunlap 2403a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 2404a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 2405a1d94aa5SRandy Dunlap $err = 0; 2406a1d94aa5SRandy Dunlap last; 2407a1d94aa5SRandy Dunlap } 2408a1d94aa5SRandy Dunlap } 2409a1d94aa5SRandy Dunlap if ($err) { 2410a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 2411d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2412a1d94aa5SRandy Dunlap "Excess function parameter " . 2413a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2414a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2415a1d94aa5SRandy Dunlap ++$warnings; 2416a1d94aa5SRandy Dunlap } else { 2417a1d94aa5SRandy Dunlap if ($nested !~ m/\Q$sects[$sx]\E/) { 2418d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2419a1d94aa5SRandy Dunlap "Excess struct/union/enum/typedef member " . 2420a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2421a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2422a1d94aa5SRandy Dunlap ++$warnings; 2423a1d94aa5SRandy Dunlap } 2424a1d94aa5SRandy Dunlap } 2425a1d94aa5SRandy Dunlap } 2426a1d94aa5SRandy Dunlap } 2427a1d94aa5SRandy Dunlap} 2428a1d94aa5SRandy Dunlap 24291da177e4SLinus Torvalds## 24304092bac7SYacine Belkadi# Checks the section describing the return value of a function. 24314092bac7SYacine Belkadisub check_return_section { 24324092bac7SYacine Belkadi my $file = shift; 24334092bac7SYacine Belkadi my $declaration_name = shift; 24344092bac7SYacine Belkadi my $return_type = shift; 24354092bac7SYacine Belkadi 24364092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 24374092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 24384092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 24394092bac7SYacine Belkadi return; 24404092bac7SYacine Belkadi } 24414092bac7SYacine Belkadi 24424092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 24434092bac7SYacine Belkadi $sections{$section_return} eq "") { 2444d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 24454092bac7SYacine Belkadi "No description found for return value of " . 24464092bac7SYacine Belkadi "'$declaration_name'\n"; 24474092bac7SYacine Belkadi ++$warnings; 24484092bac7SYacine Belkadi } 24494092bac7SYacine Belkadi} 24504092bac7SYacine Belkadi 24514092bac7SYacine Belkadi## 24521da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 24531da177e4SLinus Torvalds# processed and spits out all the details stored in the global 24541da177e4SLinus Torvalds# arrays/hashes. 24551da177e4SLinus Torvaldssub dump_function($$) { 24561da177e4SLinus Torvalds my $prototype = shift; 24571da177e4SLinus Torvalds my $file = shift; 2458cbb4d3e6SHoria Geanta my $noret = 0; 24591da177e4SLinus Torvalds 24601da177e4SLinus Torvalds $prototype =~ s/^static +//; 24611da177e4SLinus Torvalds $prototype =~ s/^extern +//; 24624dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 24631da177e4SLinus Torvalds $prototype =~ s/^inline +//; 24641da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 246532e79401SRandy Dunlap $prototype =~ s/^__inline +//; 246632e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 246732e79401SRandy Dunlap $prototype =~ s/^noinline +//; 246874fc5c65SRandy Dunlap $prototype =~ s/__init +//; 246920072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 2470270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 247170c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 24720df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 2473cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 2474328d2440SRandy Dunlap $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; 24751da177e4SLinus Torvalds 24761da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 24771da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 24781da177e4SLinus Torvalds # 2. Function name 24791da177e4SLinus Torvalds # 3. Function parameters. 24801da177e4SLinus Torvalds # 24811da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 24821da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 24831da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 24841da177e4SLinus Torvalds # so on. 24851da177e4SLinus Torvalds # 24861da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 24871da177e4SLinus Torvalds # the following functions' documentation still comes out right: 24881da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 24891da177e4SLinus Torvalds # - atomic_set (macro) 24909598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 24911da177e4SLinus Torvalds 2492cbb4d3e6SHoria Geanta if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 2493cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 2494cbb4d3e6SHoria Geanta # list. 2495cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 2496cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 2497cbb4d3e6SHoria Geanta $return_type = $1; 2498cbb4d3e6SHoria Geanta $declaration_name = $2; 2499cbb4d3e6SHoria Geanta $noret = 1; 2500cbb4d3e6SHoria Geanta } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25011da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25021da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25031da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 250494b3e03cSRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25051da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25061da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25071da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25081da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25091da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25101da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25111da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25121da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25139598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25149598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2515412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2516412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 25171da177e4SLinus Torvalds $return_type = $1; 25181da177e4SLinus Torvalds $declaration_name = $2; 25191da177e4SLinus Torvalds my $args = $3; 25201da177e4SLinus Torvalds 25211da177e4SLinus Torvalds create_parameterlist($args, ',', $file); 25221da177e4SLinus Torvalds } else { 2523d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 25241da177e4SLinus Torvalds return; 25251da177e4SLinus Torvalds } 25261da177e4SLinus Torvalds 2527a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 2528a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); 2529a1d94aa5SRandy Dunlap 25304092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 25314092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 25324092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 25334092bac7SYacine Belkadi # verbose mode. 25344092bac7SYacine Belkadi # TODO: always perform the check. 2535cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 25364092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 25374092bac7SYacine Belkadi } 25384092bac7SYacine Belkadi 25391da177e4SLinus Torvalds output_declaration($declaration_name, 25401da177e4SLinus Torvalds 'function', 25411da177e4SLinus Torvalds {'function' => $declaration_name, 25421da177e4SLinus Torvalds 'module' => $modulename, 25431da177e4SLinus Torvalds 'functiontype' => $return_type, 25441da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 25451da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 25461da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 25471da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 25481da177e4SLinus Torvalds 'sections' => \%sections, 25491da177e4SLinus Torvalds 'purpose' => $declaration_purpose 25501da177e4SLinus Torvalds }); 25511da177e4SLinus Torvalds} 25521da177e4SLinus Torvalds 25531da177e4SLinus Torvaldssub reset_state { 25541da177e4SLinus Torvalds $function = ""; 25551da177e4SLinus Torvalds %parameterdescs = (); 25561da177e4SLinus Torvalds %parametertypes = (); 25571da177e4SLinus Torvalds @parameterlist = (); 25581da177e4SLinus Torvalds %sections = (); 25591da177e4SLinus Torvalds @sectionlist = (); 2560a1d94aa5SRandy Dunlap $sectcheck = ""; 2561a1d94aa5SRandy Dunlap $struct_actual = ""; 25621da177e4SLinus Torvalds $prototype = ""; 25631da177e4SLinus Torvalds 256448af606aSJani Nikula $state = STATE_NORMAL; 256548af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 25661da177e4SLinus Torvalds} 25671da177e4SLinus Torvalds 256856afb0f8SJason Baronsub tracepoint_munge($) { 256956afb0f8SJason Baron my $file = shift; 257056afb0f8SJason Baron my $tracepointname = 0; 257156afb0f8SJason Baron my $tracepointargs = 0; 257256afb0f8SJason Baron 257356afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 257456afb0f8SJason Baron $tracepointname = $1; 257556afb0f8SJason Baron } 25763a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 25773a9089fdSJason Baron $tracepointname = $1; 25783a9089fdSJason Baron } 25793a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 25803a9089fdSJason Baron $tracepointname = $2; 25813a9089fdSJason Baron } 25823a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 258356afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 258456afb0f8SJason Baron $tracepointargs = $1; 258556afb0f8SJason Baron } 258656afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 2587d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 258856afb0f8SJason Baron "$prototype\n"; 258956afb0f8SJason Baron } else { 259056afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 259156afb0f8SJason Baron } 259256afb0f8SJason Baron} 259356afb0f8SJason Baron 2594b4870bc5SRandy Dunlapsub syscall_munge() { 2595b4870bc5SRandy Dunlap my $void = 0; 2596b4870bc5SRandy Dunlap 2597b4870bc5SRandy Dunlap $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs 2598b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 2599b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 2600b4870bc5SRandy Dunlap $void = 1; 2601b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 2602b4870bc5SRandy Dunlap } 2603b4870bc5SRandy Dunlap 2604b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 2605b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 2606b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 2607b4870bc5SRandy Dunlap } elsif ($void) { 2608b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 2609b4870bc5SRandy Dunlap } 2610b4870bc5SRandy Dunlap 2611b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 2612b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 2613b4870bc5SRandy Dunlap my $count = 0; 2614b4870bc5SRandy Dunlap my $len = length($prototype); 2615b4870bc5SRandy Dunlap if ($void) { 2616b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 2617b4870bc5SRandy Dunlap } 2618b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 2619b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 2620b4870bc5SRandy Dunlap $count++; 2621b4870bc5SRandy Dunlap if ($count % 2 == 1) { 2622b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 2623b4870bc5SRandy Dunlap } 2624b4870bc5SRandy Dunlap } 2625b4870bc5SRandy Dunlap } 2626b4870bc5SRandy Dunlap} 2627b4870bc5SRandy Dunlap 2628b7afa92bSDaniel Vettersub process_proto_function($$) { 26291da177e4SLinus Torvalds my $x = shift; 26301da177e4SLinus Torvalds my $file = shift; 26311da177e4SLinus Torvalds 263251f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 263351f5a0c8SRandy Dunlap 2634890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 26351da177e4SLinus Torvalds # do nothing 26361da177e4SLinus Torvalds } 26371da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 26381da177e4SLinus Torvalds $prototype .= $1; 26391da177e4SLinus Torvalds } 2640b4870bc5SRandy Dunlap 2641890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 26421da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 26431da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 26441da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 2645b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 2646b4870bc5SRandy Dunlap syscall_munge(); 2647b4870bc5SRandy Dunlap } 26483a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 26493a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 26503a9089fdSJason Baron { 265156afb0f8SJason Baron tracepoint_munge($file); 265256afb0f8SJason Baron } 26531da177e4SLinus Torvalds dump_function($prototype, $file); 26541da177e4SLinus Torvalds reset_state(); 26551da177e4SLinus Torvalds } 26561da177e4SLinus Torvalds} 26571da177e4SLinus Torvalds 2658b7afa92bSDaniel Vettersub process_proto_type($$) { 26591da177e4SLinus Torvalds my $x = shift; 26601da177e4SLinus Torvalds my $file = shift; 26611da177e4SLinus Torvalds 26621da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 26631da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 26641da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 266551f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 266651f5a0c8SRandy Dunlap 26671da177e4SLinus Torvalds if ($x =~ /^#/) { 26681da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 26691da177e4SLinus Torvalds $x .= ";"; 26701da177e4SLinus Torvalds } 26711da177e4SLinus Torvalds 26721da177e4SLinus Torvalds while (1) { 26731da177e4SLinus Torvalds if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 26741da177e4SLinus Torvalds $prototype .= $1 . $2; 26751da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 26761da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 26771da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 26781da177e4SLinus Torvalds dump_declaration($prototype, $file); 26791da177e4SLinus Torvalds reset_state(); 26801da177e4SLinus Torvalds last; 26811da177e4SLinus Torvalds } 26821da177e4SLinus Torvalds $x = $3; 26831da177e4SLinus Torvalds } else { 26841da177e4SLinus Torvalds $prototype .= $x; 26851da177e4SLinus Torvalds last; 26861da177e4SLinus Torvalds } 26871da177e4SLinus Torvalds } 26881da177e4SLinus Torvalds} 26891da177e4SLinus Torvalds 26906b5b55f6SRandy Dunlap# xml_escape: replace <, >, and & in the text stream; 26916b5b55f6SRandy Dunlap# 26926b5b55f6SRandy Dunlap# however, formatting controls that are generated internally/locally in the 26936b5b55f6SRandy Dunlap# kernel-doc script are not escaped here; instead, they begin life like 26946b5b55f6SRandy Dunlap# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings 26956b5b55f6SRandy Dunlap# are converted to their mnemonic-expected output, without the 4 * '\' & ':', 26966b5b55f6SRandy Dunlap# just before actual output; (this is done by local_unescape()) 26971da177e4SLinus Torvaldssub xml_escape($) { 26981da177e4SLinus Torvalds my $text = shift; 2699ecfb251aSRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 2700ecfb251aSRandy Dunlap return $text; 2701ecfb251aSRandy Dunlap } 27021da177e4SLinus Torvalds $text =~ s/\&/\\\\\\amp;/g; 27031da177e4SLinus Torvalds $text =~ s/\</\\\\\\lt;/g; 27041da177e4SLinus Torvalds $text =~ s/\>/\\\\\\gt;/g; 27051da177e4SLinus Torvalds return $text; 27061da177e4SLinus Torvalds} 27071da177e4SLinus Torvalds 2708c0d1b6eeSJonathan Corbet# xml_unescape: reverse the effects of xml_escape 2709c0d1b6eeSJonathan Corbetsub xml_unescape($) { 2710c0d1b6eeSJonathan Corbet my $text = shift; 2711c0d1b6eeSJonathan Corbet if (($output_mode eq "text") || ($output_mode eq "man")) { 2712c0d1b6eeSJonathan Corbet return $text; 2713c0d1b6eeSJonathan Corbet } 2714c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\amp;/\&/g; 2715c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\lt;/</g; 2716c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\gt;/>/g; 2717c0d1b6eeSJonathan Corbet return $text; 2718c0d1b6eeSJonathan Corbet} 2719c0d1b6eeSJonathan Corbet 27206b5b55f6SRandy Dunlap# convert local escape strings to html 27216b5b55f6SRandy Dunlap# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) 27226b5b55f6SRandy Dunlapsub local_unescape($) { 27236b5b55f6SRandy Dunlap my $text = shift; 27246b5b55f6SRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 27256b5b55f6SRandy Dunlap return $text; 27266b5b55f6SRandy Dunlap } 27276b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\lt:/</g; 27286b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\gt:/>/g; 27296b5b55f6SRandy Dunlap return $text; 27306b5b55f6SRandy Dunlap} 27316b5b55f6SRandy Dunlap 27321da177e4SLinus Torvaldssub process_file($) { 27332283a117SRandy Dunlap my $file; 27341da177e4SLinus Torvalds my $identifier; 27351da177e4SLinus Torvalds my $func; 2736a21217daSRandy Dunlap my $descr; 27376423133bSJohannes Weiner my $in_purpose = 0; 27381da177e4SLinus Torvalds my $initial_section_counter = $section_counter; 273968f86662SBen Hutchings my ($orig_file) = @_; 2740b7886de4SJani Nikula my $leading_space; 27411da177e4SLinus Torvalds 27422283a117SRandy Dunlap if (defined($ENV{'SRCTREE'})) { 274368f86662SBen Hutchings $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 27442283a117SRandy Dunlap } 27452283a117SRandy Dunlap else { 274668f86662SBen Hutchings $file = $orig_file; 27472283a117SRandy Dunlap } 27481da177e4SLinus Torvalds if (defined($source_map{$file})) { 27491da177e4SLinus Torvalds $file = $source_map{$file}; 27501da177e4SLinus Torvalds } 27511da177e4SLinus Torvalds 27521da177e4SLinus Torvalds if (!open(IN,"<$file")) { 27531da177e4SLinus Torvalds print STDERR "Error: Cannot open file $file\n"; 27541da177e4SLinus Torvalds ++$errors; 27551da177e4SLinus Torvalds return; 27561da177e4SLinus Torvalds } 27571da177e4SLinus Torvalds 275886ae2e38SJani Nikula # two passes for -export and -internal 2759b6c3f456SJani Nikula if ($output_selection == OUTPUT_EXPORTED || 2760b6c3f456SJani Nikula $output_selection == OUTPUT_INTERNAL) { 276186ae2e38SJani Nikula while (<IN>) { 276286ae2e38SJani Nikula if (/$export_symbol/o) { 276386ae2e38SJani Nikula $function_table{$2} = 1; 276486ae2e38SJani Nikula } 276586ae2e38SJani Nikula } 276686ae2e38SJani Nikula seek(IN, 0, 0); 276786ae2e38SJani Nikula } 276886ae2e38SJani Nikula 2769a9e7314bSIlya Dryomov $. = 1; 2770a9e7314bSIlya Dryomov 27711da177e4SLinus Torvalds $section_counter = 0; 27721da177e4SLinus Torvalds while (<IN>) { 277365478428SDaniel Santos while (s/\\\s*$//) { 277465478428SDaniel Santos $_ .= <IN>; 277565478428SDaniel Santos } 277648af606aSJani Nikula if ($state == STATE_NORMAL) { 27771da177e4SLinus Torvalds if (/$doc_start/o) { 277848af606aSJani Nikula $state = STATE_NAME; # next line is always the function name 2779850622dfSRandy Dunlap $in_doc_sect = 0; 2780*0b0f5f29SDaniel Vetter $declaration_start_line = $. + 1; 27811da177e4SLinus Torvalds } 278248af606aSJani Nikula } elsif ($state == STATE_NAME) {# this line is the function name (always) 27831da177e4SLinus Torvalds if (/$doc_block/o) { 278448af606aSJani Nikula $state = STATE_DOCBLOCK; 27851da177e4SLinus Torvalds $contents = ""; 2786*0b0f5f29SDaniel Vetter $new_start_line = $. + 1; 2787*0b0f5f29SDaniel Vetter 27881da177e4SLinus Torvalds if ( $1 eq "" ) { 27891da177e4SLinus Torvalds $section = $section_intro; 27901da177e4SLinus Torvalds } else { 27911da177e4SLinus Torvalds $section = $1; 27921da177e4SLinus Torvalds } 27931da177e4SLinus Torvalds } 27941da177e4SLinus Torvalds elsif (/$doc_decl/o) { 27951da177e4SLinus Torvalds $identifier = $1; 27961da177e4SLinus Torvalds if (/\s*([\w\s]+?)\s*-/) { 27971da177e4SLinus Torvalds $identifier = $1; 27981da177e4SLinus Torvalds } 27991da177e4SLinus Torvalds 280048af606aSJani Nikula $state = STATE_FIELD; 2801*0b0f5f29SDaniel Vetter # if there's no @param blocks need to set up default section 2802*0b0f5f29SDaniel Vetter # here 28032f4ad40aSJani Nikula $contents = ""; 28042f4ad40aSJani Nikula $section = $section_default; 2805*0b0f5f29SDaniel Vetter $new_start_line = $. + 1; 28061da177e4SLinus Torvalds if (/-(.*)/) { 280751f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2808a21217daSRandy Dunlap $descr= $1; 2809a21217daSRandy Dunlap $descr =~ s/^\s*//; 2810a21217daSRandy Dunlap $descr =~ s/\s*$//; 281112ae6779SDaniel Santos $descr =~ s/\s+/ /g; 2812a21217daSRandy Dunlap $declaration_purpose = xml_escape($descr); 28136423133bSJohannes Weiner $in_purpose = 1; 28141da177e4SLinus Torvalds } else { 28151da177e4SLinus Torvalds $declaration_purpose = ""; 28161da177e4SLinus Torvalds } 281777cc23b8SRandy Dunlap 281877cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 2819d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 282077cc23b8SRandy Dunlap print STDERR $_; 282177cc23b8SRandy Dunlap ++$warnings; 282277cc23b8SRandy Dunlap } 282377cc23b8SRandy Dunlap 28241da177e4SLinus Torvalds if ($identifier =~ m/^struct/) { 28251da177e4SLinus Torvalds $decl_type = 'struct'; 28261da177e4SLinus Torvalds } elsif ($identifier =~ m/^union/) { 28271da177e4SLinus Torvalds $decl_type = 'union'; 28281da177e4SLinus Torvalds } elsif ($identifier =~ m/^enum/) { 28291da177e4SLinus Torvalds $decl_type = 'enum'; 28301da177e4SLinus Torvalds } elsif ($identifier =~ m/^typedef/) { 28311da177e4SLinus Torvalds $decl_type = 'typedef'; 28321da177e4SLinus Torvalds } else { 28331da177e4SLinus Torvalds $decl_type = 'function'; 28341da177e4SLinus Torvalds } 28351da177e4SLinus Torvalds 28361da177e4SLinus Torvalds if ($verbose) { 2837d40e1e65SBart Van Assche print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; 28381da177e4SLinus Torvalds } 28391da177e4SLinus Torvalds } else { 2840d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 28411da177e4SLinus Torvalds " - I thought it was a doc line\n"; 28421da177e4SLinus Torvalds ++$warnings; 284348af606aSJani Nikula $state = STATE_NORMAL; 28441da177e4SLinus Torvalds } 284548af606aSJani Nikula } elsif ($state == STATE_FIELD) { # look for head: lines, and include content 2846f624adefSJani Nikula if (/$doc_sect/i) { # case insensitive for supported section names 28471da177e4SLinus Torvalds $newsection = $1; 28481da177e4SLinus Torvalds $newcontents = $2; 28491da177e4SLinus Torvalds 2850f624adefSJani Nikula # map the supported section names to the canonical names 2851f624adefSJani Nikula if ($newsection =~ m/^description$/i) { 2852f624adefSJani Nikula $newsection = $section_default; 2853f624adefSJani Nikula } elsif ($newsection =~ m/^context$/i) { 2854f624adefSJani Nikula $newsection = $section_context; 2855f624adefSJani Nikula } elsif ($newsection =~ m/^returns?$/i) { 2856f624adefSJani Nikula $newsection = $section_return; 2857f624adefSJani Nikula } elsif ($newsection =~ m/^\@return$/) { 2858f624adefSJani Nikula # special: @return is a section, not a param description 2859f624adefSJani Nikula $newsection = $section_return; 2860f624adefSJani Nikula } 2861f624adefSJani Nikula 2862792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 2863850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 2864d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: contents before sections\n"; 2865850622dfSRandy Dunlap ++$warnings; 2866850622dfSRandy Dunlap } 286794dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 28681da177e4SLinus Torvalds $section = $section_default; 28691da177e4SLinus Torvalds } 28701da177e4SLinus Torvalds 2871850622dfSRandy Dunlap $in_doc_sect = 1; 28726423133bSJohannes Weiner $in_purpose = 0; 28731da177e4SLinus Torvalds $contents = $newcontents; 2874*0b0f5f29SDaniel Vetter $new_start_line = $.; 287527205744SRandy Dunlap while ((substr($contents, 0, 1) eq " ") || 287627205744SRandy Dunlap substr($contents, 0, 1) eq "\t") { 287705189497SRandy Dunlap $contents = substr($contents, 1); 287805189497SRandy Dunlap } 28790a726301SJani Nikula if ($contents ne "") { 28801da177e4SLinus Torvalds $contents .= "\n"; 28811da177e4SLinus Torvalds } 28821da177e4SLinus Torvalds $section = $newsection; 2883b7886de4SJani Nikula $leading_space = undef; 28841da177e4SLinus Torvalds } elsif (/$doc_end/) { 28854c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 288694dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 28871da177e4SLinus Torvalds $section = $section_default; 28881da177e4SLinus Torvalds $contents = ""; 28891da177e4SLinus Torvalds } 289046b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 289146b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2892d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: suspicious ending line: $_"; 289346b958ebSRandy Dunlap ++$warnings; 289446b958ebSRandy Dunlap } 28951da177e4SLinus Torvalds 28961da177e4SLinus Torvalds $prototype = ""; 289748af606aSJani Nikula $state = STATE_PROTO; 28981da177e4SLinus Torvalds $brcount = 0; 28991da177e4SLinus Torvalds# print STDERR "end of doc comment, looking for prototype\n"; 29001da177e4SLinus Torvalds } elsif (/$doc_content/) { 29011da177e4SLinus Torvalds # miguel-style comment kludge, look for blank lines after 29021da177e4SLinus Torvalds # @parameter line to signify start of description 29036423133bSJohannes Weiner if ($1 eq "") { 29046423133bSJohannes Weiner if ($section =~ m/^@/ || $section eq $section_context) { 290594dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 29061da177e4SLinus Torvalds $section = $section_default; 29071da177e4SLinus Torvalds $contents = ""; 2908*0b0f5f29SDaniel Vetter $new_start_line = $.; 29091da177e4SLinus Torvalds } else { 29106423133bSJohannes Weiner $contents .= "\n"; 29116423133bSJohannes Weiner } 29126423133bSJohannes Weiner $in_purpose = 0; 29136423133bSJohannes Weiner } elsif ($in_purpose == 1) { 29146423133bSJohannes Weiner # Continued declaration purpose 29156423133bSJohannes Weiner chomp($declaration_purpose); 29166423133bSJohannes Weiner $declaration_purpose .= " " . xml_escape($1); 291712ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 29186423133bSJohannes Weiner } else { 2919b7886de4SJani Nikula my $cont = $1; 2920b7886de4SJani Nikula if ($section =~ m/^@/ || $section eq $section_context) { 2921b7886de4SJani Nikula if (!defined $leading_space) { 2922b7886de4SJani Nikula if ($cont =~ m/^(\s+)/) { 2923b7886de4SJani Nikula $leading_space = $1; 2924b7886de4SJani Nikula } else { 2925b7886de4SJani Nikula $leading_space = ""; 2926b7886de4SJani Nikula } 2927b7886de4SJani Nikula } 2928b7886de4SJani Nikula 2929b7886de4SJani Nikula $cont =~ s/^$leading_space//; 2930b7886de4SJani Nikula } 2931b7886de4SJani Nikula $contents .= $cont . "\n"; 29321da177e4SLinus Torvalds } 29331da177e4SLinus Torvalds } else { 29341da177e4SLinus Torvalds # i dont know - bad line? ignore. 2935d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: bad line: $_"; 29361da177e4SLinus Torvalds ++$warnings; 29371da177e4SLinus Torvalds } 293848af606aSJani Nikula } elsif ($state == STATE_INLINE) { # scanning for inline parameters 2939a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 294048af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 2941a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 2942a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 2943*0b0f5f29SDaniel Vetter $new_start_line = $.; 2944a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 2945a4c6ebedSDanilo Cesar Lemes de Paula while ((substr($contents, 0, 1) eq " ") || 2946a4c6ebedSDanilo Cesar Lemes de Paula substr($contents, 0, 1) eq "\t") { 2947a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 2948a4c6ebedSDanilo Cesar Lemes de Paula } 2949a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 2950a4c6ebedSDanilo Cesar Lemes de Paula } 295148af606aSJani Nikula $inline_doc_state = STATE_INLINE_TEXT; 2952a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 295348af606aSJani Nikula } elsif (/$doc_inline_end/) { 2954a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 2955a4c6ebedSDanilo Cesar Lemes de Paula dump_section($file, $section, xml_escape($contents)); 2956a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 2957a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 2958a4c6ebedSDanilo Cesar Lemes de Paula } 295948af606aSJani Nikula $state = STATE_PROTO; 296048af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 2961a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 2962a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 296348af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_TEXT) { 2964a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 29656450c895SJani Nikula # nuke leading blank lines 29666450c895SJani Nikula if ($contents =~ /^\s*$/) { 29676450c895SJani Nikula $contents = ""; 29686450c895SJani Nikula } 296948af606aSJani Nikula } elsif ($inline_doc_state == STATE_INLINE_NAME) { 297048af606aSJani Nikula $inline_doc_state = STATE_INLINE_ERROR; 2971a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Warning(${file}:$.): "; 2972a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Incorrect use of kernel-doc format: $_"; 2973a4c6ebedSDanilo Cesar Lemes de Paula ++$warnings; 2974a4c6ebedSDanilo Cesar Lemes de Paula } 2975a4c6ebedSDanilo Cesar Lemes de Paula } 297648af606aSJani Nikula } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype) 297748af606aSJani Nikula if (/$doc_inline_start/) { 297848af606aSJani Nikula $state = STATE_INLINE; 297948af606aSJani Nikula $inline_doc_state = STATE_INLINE_NAME; 2980a4c6ebedSDanilo Cesar Lemes de Paula } elsif ($decl_type eq 'function') { 2981b7afa92bSDaniel Vetter process_proto_function($_, $file); 29821da177e4SLinus Torvalds } else { 2983b7afa92bSDaniel Vetter process_proto_type($_, $file); 29841da177e4SLinus Torvalds } 298548af606aSJani Nikula } elsif ($state == STATE_DOCBLOCK) { 2986ebff7f92SDaniel Vetter if (/$doc_end/) 29871da177e4SLinus Torvalds { 298894dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 29892f4ad40aSJani Nikula $section = $section_default; 29901da177e4SLinus Torvalds $contents = ""; 29911da177e4SLinus Torvalds $function = ""; 29921da177e4SLinus Torvalds %parameterdescs = (); 29931da177e4SLinus Torvalds %parametertypes = (); 29941da177e4SLinus Torvalds @parameterlist = (); 29951da177e4SLinus Torvalds %sections = (); 29961da177e4SLinus Torvalds @sectionlist = (); 29971da177e4SLinus Torvalds $prototype = ""; 299848af606aSJani Nikula $state = STATE_NORMAL; 29991da177e4SLinus Torvalds } 30001da177e4SLinus Torvalds elsif (/$doc_content/) 30011da177e4SLinus Torvalds { 30021da177e4SLinus Torvalds if ( $1 eq "" ) 30031da177e4SLinus Torvalds { 30041da177e4SLinus Torvalds $contents .= $blankline; 30051da177e4SLinus Torvalds } 30061da177e4SLinus Torvalds else 30071da177e4SLinus Torvalds { 30081da177e4SLinus Torvalds $contents .= $1 . "\n"; 30091da177e4SLinus Torvalds } 30101da177e4SLinus Torvalds } 30111da177e4SLinus Torvalds } 30121da177e4SLinus Torvalds } 30131da177e4SLinus Torvalds if ($initial_section_counter == $section_counter) { 3014d40e1e65SBart Van Assche print STDERR "${file}:1: warning: no structured comments found\n"; 3015b6c3f456SJani Nikula if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) { 3016e946c43aSJohannes Berg print STDERR " Was looking for '$_'.\n" for keys %function_table; 3017e946c43aSJohannes Berg } 30181da177e4SLinus Torvalds if ($output_mode eq "xml") { 30191da177e4SLinus Torvalds # The template wants at least one RefEntry here; make one. 30201da177e4SLinus Torvalds print "<refentry>\n"; 30211da177e4SLinus Torvalds print " <refnamediv>\n"; 30221da177e4SLinus Torvalds print " <refname>\n"; 302368f86662SBen Hutchings print " ${orig_file}\n"; 30241da177e4SLinus Torvalds print " </refname>\n"; 30251da177e4SLinus Torvalds print " <refpurpose>\n"; 30261da177e4SLinus Torvalds print " Document generation inconsistency\n"; 30271da177e4SLinus Torvalds print " </refpurpose>\n"; 30281da177e4SLinus Torvalds print " </refnamediv>\n"; 30291da177e4SLinus Torvalds print " <refsect1>\n"; 30301da177e4SLinus Torvalds print " <title>\n"; 30311da177e4SLinus Torvalds print " Oops\n"; 30321da177e4SLinus Torvalds print " </title>\n"; 30331da177e4SLinus Torvalds print " <warning>\n"; 30341da177e4SLinus Torvalds print " <para>\n"; 30351da177e4SLinus Torvalds print " The template for this document tried to insert\n"; 30361da177e4SLinus Torvalds print " the structured comment from the file\n"; 303768f86662SBen Hutchings print " <filename>${orig_file}</filename> at this point,\n"; 30381da177e4SLinus Torvalds print " but none was found.\n"; 30391da177e4SLinus Torvalds print " This dummy section is inserted to allow\n"; 30401da177e4SLinus Torvalds print " generation to continue.\n"; 30411da177e4SLinus Torvalds print " </para>\n"; 30421da177e4SLinus Torvalds print " </warning>\n"; 30431da177e4SLinus Torvalds print " </refsect1>\n"; 30441da177e4SLinus Torvalds print "</refentry>\n"; 30451da177e4SLinus Torvalds } 30461da177e4SLinus Torvalds } 30471da177e4SLinus Torvalds} 30488484baaaSRandy Dunlap 30498484baaaSRandy Dunlap 30508484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 30518484baaaSRandy Dunlap 30528484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 30538484baaaSRandy Dunlap# using the s// operator. 30541ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 30554d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 30564d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 30574d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 30584d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 30598484baaaSRandy Dunlap} 30608484baaaSRandy Dunlap 30618484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 30628484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 30638484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 30648484baaaSRandy Dunlap my ($relname, $absname); 30658484baaaSRandy Dunlap while(<SOURCE_MAP>) { 30668484baaaSRandy Dunlap chop(); 30678484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 30688484baaaSRandy Dunlap $relname =~ s:^/+::; 30698484baaaSRandy Dunlap $source_map{$relname} = $absname; 30708484baaaSRandy Dunlap } 30718484baaaSRandy Dunlap close(SOURCE_MAP); 30728484baaaSRandy Dunlap} 30738484baaaSRandy Dunlap 30748484baaaSRandy Dunlapforeach (@ARGV) { 30758484baaaSRandy Dunlap chomp; 30768484baaaSRandy Dunlap process_file($_); 30778484baaaSRandy Dunlap} 30788484baaaSRandy Dunlapif ($verbose && $errors) { 30798484baaaSRandy Dunlap print STDERR "$errors errors\n"; 30808484baaaSRandy Dunlap} 30818484baaaSRandy Dunlapif ($verbose && $warnings) { 30828484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 30838484baaaSRandy Dunlap} 30848484baaaSRandy Dunlap 30858484baaaSRandy Dunlapexit($errors); 3086