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() 64c9b2cfb3SJani Nikula in any input FILE or -export-file FILE. 6586ae2e38SJani Nikula -internal Only output documentation for symbols that have NOT been 6686ae2e38SJani Nikula exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 67c9b2cfb3SJani Nikula in any input FILE or -export-file 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. 770b0f5f29SDaniel Vetter -enable-lineno Enable output of #define LINENO lines. Only works with 780b0f5f29SDaniel Vetter reStructuredText format. 7988c2b57dSJani Nikula -export-file FILE Specify an additional FILE in which to look for 8088c2b57dSJani Nikula EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with 8188c2b57dSJani Nikula -export or -internal. May be specified multiple times. 82fadc0b31SJani Nikula 83fadc0b31SJani NikulaOther parameters: 84fadc0b31SJani Nikula -v Verbose output, more warnings and other information. 85fadc0b31SJani Nikula -h Print this help. 86fadc0b31SJani Nikula 87fadc0b31SJani NikulaEOF 88fadc0b31SJani Nikula print $message; 89fadc0b31SJani Nikula exit 1; 90fadc0b31SJani Nikula} 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds# 931da177e4SLinus Torvalds# format of comments. 941da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure. 951da177e4SLinus Torvalds# (...)* signifies 0 or more structure elements 961da177e4SLinus Torvalds# /** 971da177e4SLinus Torvalds# * function_name(:)? (- short description)? 981da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)* 991da177e4SLinus Torvalds# (* a blank line)? 1001da177e4SLinus Torvalds# * (Description:)? (Description of function)? 1011da177e4SLinus Torvalds# * (section header: (section description)? )* 1021da177e4SLinus Torvalds# (*)?*/ 1031da177e4SLinus Torvalds# 1041da177e4SLinus Torvalds# So .. the trivial example would be: 1051da177e4SLinus Torvalds# 1061da177e4SLinus Torvalds# /** 1071da177e4SLinus Torvalds# * my_function 108b9d97328SRandy Dunlap# */ 1091da177e4SLinus Torvalds# 110891dcd2fSRandy Dunlap# If the Description: header tag is omitted, then there must be a blank line 1111da177e4SLinus Torvalds# after the last parameter specification. 1121da177e4SLinus Torvalds# e.g. 1131da177e4SLinus Torvalds# /** 1141da177e4SLinus Torvalds# * my_function - does my stuff 1151da177e4SLinus Torvalds# * @my_arg: its mine damnit 1161da177e4SLinus Torvalds# * 1171da177e4SLinus Torvalds# * Does my stuff explained. 1181da177e4SLinus Torvalds# */ 1191da177e4SLinus Torvalds# 1201da177e4SLinus Torvalds# or, could also use: 1211da177e4SLinus Torvalds# /** 1221da177e4SLinus Torvalds# * my_function - does my stuff 1231da177e4SLinus Torvalds# * @my_arg: its mine damnit 1241da177e4SLinus Torvalds# * Description: Does my stuff explained. 1251da177e4SLinus Torvalds# */ 1261da177e4SLinus Torvalds# etc. 1271da177e4SLinus Torvalds# 128b9d97328SRandy Dunlap# Besides functions you can also write documentation for structs, unions, 1291da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name 1301da177e4SLinus Torvalds# of the declaration; the struct/union/enum/typedef must always precede 1311da177e4SLinus Torvalds# the name. Nesting of declarations is not supported. 1321da177e4SLinus Torvalds# Use the argument mechanism to document members or constants. 1331da177e4SLinus Torvalds# e.g. 1341da177e4SLinus Torvalds# /** 1351da177e4SLinus Torvalds# * struct my_struct - short description 1361da177e4SLinus Torvalds# * @a: first member 1371da177e4SLinus Torvalds# * @b: second member 1381da177e4SLinus Torvalds# * 1391da177e4SLinus Torvalds# * Longer description 1401da177e4SLinus Torvalds# */ 1411da177e4SLinus Torvalds# struct my_struct { 1421da177e4SLinus Torvalds# int a; 1431da177e4SLinus Torvalds# int b; 144aeec46b9SMartin Waitz# /* private: */ 145aeec46b9SMartin Waitz# int c; 1461da177e4SLinus Torvalds# }; 1471da177e4SLinus Torvalds# 1481da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description. 1491da177e4SLinus Torvalds# 150a4c6ebedSDanilo Cesar Lemes de Paula# For really longs structs, you can also describe arguments inside the 151a4c6ebedSDanilo Cesar Lemes de Paula# body of the struct. 152a4c6ebedSDanilo Cesar Lemes de Paula# eg. 153a4c6ebedSDanilo Cesar Lemes de Paula# /** 154a4c6ebedSDanilo Cesar Lemes de Paula# * struct my_struct - short description 155a4c6ebedSDanilo Cesar Lemes de Paula# * @a: first member 156a4c6ebedSDanilo Cesar Lemes de Paula# * @b: second member 157a4c6ebedSDanilo Cesar Lemes de Paula# * 158a4c6ebedSDanilo Cesar Lemes de Paula# * Longer description 159a4c6ebedSDanilo Cesar Lemes de Paula# */ 160a4c6ebedSDanilo Cesar Lemes de Paula# struct my_struct { 161a4c6ebedSDanilo Cesar Lemes de Paula# int a; 162a4c6ebedSDanilo Cesar Lemes de Paula# int b; 163a4c6ebedSDanilo Cesar Lemes de Paula# /** 164a4c6ebedSDanilo Cesar Lemes de Paula# * @c: This is longer description of C 165a4c6ebedSDanilo Cesar Lemes de Paula# * 166a4c6ebedSDanilo Cesar Lemes de Paula# * You can use paragraphs to describe arguments 167a4c6ebedSDanilo Cesar Lemes de Paula# * using this method. 168a4c6ebedSDanilo Cesar Lemes de Paula# */ 169a4c6ebedSDanilo Cesar Lemes de Paula# int c; 170a4c6ebedSDanilo Cesar Lemes de Paula# }; 171a4c6ebedSDanilo Cesar Lemes de Paula# 172a4c6ebedSDanilo Cesar Lemes de Paula# This should be use only for struct/enum members. 173a4c6ebedSDanilo Cesar Lemes de Paula# 1741da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you 1751da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions 1761da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an 1771da177e4SLinus Torvalds# empty line. 1784092bac7SYacine Belkadi# A non-void function should have a "Return:" section describing the return 1794092bac7SYacine Belkadi# value(s). 1801da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked 1811da177e4SLinus Torvalds# appropriately in DocBook. 1821da177e4SLinus Torvalds# 1831da177e4SLinus Torvalds# Example: 1841da177e4SLinus Torvalds# /** 1851da177e4SLinus Torvalds# * user_function - function that can only be called in user context 1861da177e4SLinus Torvalds# * @a: some argument 1871da177e4SLinus Torvalds# * Context: !in_interrupt() 1881da177e4SLinus Torvalds# * 1891da177e4SLinus Torvalds# * Some description 1901da177e4SLinus Torvalds# * Example: 1911da177e4SLinus Torvalds# * user_function(22); 1921da177e4SLinus Torvalds# */ 1931da177e4SLinus Torvalds# ... 1941da177e4SLinus Torvalds# 1951da177e4SLinus Torvalds# 1961da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special 1971da177e4SLinus Torvalds# patterns, which are highlighted appropriately. 1981da177e4SLinus Torvalds# 1991da177e4SLinus Torvalds# 'funcname()' - function 2001da177e4SLinus Torvalds# '$ENVVAR' - environmental variable 2011da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct') 202*5267dd35SPaolo Bonzini# '&struct_name.member' - name of a structure member 2031da177e4SLinus Torvalds# '@parameter' - name of a parameter 2041da177e4SLinus Torvalds# '%CONST' - name of a constant. 2051da177e4SLinus Torvalds 2068484baaaSRandy Dunlap## init lots of data 2078484baaaSRandy Dunlap 2081da177e4SLinus Torvaldsmy $errors = 0; 2091da177e4SLinus Torvaldsmy $warnings = 0; 2105f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvalds# match expressions used to find embedded type information 2131da177e4SLinus Torvaldsmy $type_constant = '\%([-_\w]+)'; 2141da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 215c950a173SSilvio Frickemy $type_param = '\@(\w+(\.\.\.)?)'; 2165219f18aSJonathan Corbetmy $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params 2173eb014a1SRandy Dunlapmy $type_struct = '\&((struct\s*)*[_\w]+)'; 2186b5b55f6SRandy Dunlapmy $type_struct_xml = '\\&((struct\s*)*[_\w]+)'; 2191da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 220c0d1b6eeSJonathan Corbetmy $type_enum_full = '\&(enum)\s*([_\w]+)'; 221c0d1b6eeSJonathan Corbetmy $type_struct_full = '\&(struct)\s*([_\w]+)'; 22247ae7aedSJani Nikulamy $type_typedef_full = '\&(typedef)\s*([_\w]+)'; 22347ae7aedSJani Nikulamy $type_union_full = '\&(union)\s*([_\w]+)'; 224*5267dd35SPaolo Bonzinimy $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; 225*5267dd35SPaolo Bonzinimy $type_member_xml = '\&([_\w]+)(\.|-\>)([_\w]+)'; 226f3341dcfSJani Nikulamy $type_member_func = $type_member . '\(\)'; 2271da177e4SLinus Torvalds 2281da177e4SLinus Torvalds# Output conversion substitutions. 2291da177e4SLinus Torvalds# One for each output format 2301da177e4SLinus Torvalds 2311da177e4SLinus Torvalds# these work fairly well 2324d732701SDanilo Cesar Lemes de Paulamy @highlights_html = ( 2334d732701SDanilo Cesar Lemes de Paula [$type_constant, "<i>\$1</i>"], 2344d732701SDanilo Cesar Lemes de Paula [$type_func, "<b>\$1</b>"], 2354d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<i>\$1</i>"], 2364d732701SDanilo Cesar Lemes de Paula [$type_env, "<b><i>\$1</i></b>"], 237*5267dd35SPaolo Bonzini [$type_param, "<tt><b>\$1</b></tt>"], 238*5267dd35SPaolo Bonzini [$type_member_xml, "<tt><i>\$1</i>\$2\$3</tt>"] 2394d732701SDanilo Cesar Lemes de Paula ); 2406b5b55f6SRandy Dunlapmy $local_lt = "\\\\\\\\lt:"; 2416b5b55f6SRandy Dunlapmy $local_gt = "\\\\\\\\gt:"; 2426b5b55f6SRandy Dunlapmy $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" 2431da177e4SLinus Torvalds 2441b40c194SDan Luedtke# html version 5 2454d732701SDanilo Cesar Lemes de Paulamy @highlights_html5 = ( 2464d732701SDanilo Cesar Lemes de Paula [$type_constant, "<span class=\"const\">\$1</span>"], 2474d732701SDanilo Cesar Lemes de Paula [$type_func, "<span class=\"func\">\$1</span>"], 2484d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<span class=\"struct\">\$1</span>"], 2494d732701SDanilo Cesar Lemes de Paula [$type_env, "<span class=\"env\">\$1</span>"], 250*5267dd35SPaolo Bonzini [$type_param, "<span class=\"param\">\$1</span>]"], 251*5267dd35SPaolo Bonzini [$type_member_xml, "<span class=\"literal\"><span class=\"struct\">\$1</span>\$2<span class=\"member\">\$3</span></span>"] 2524d732701SDanilo Cesar Lemes de Paula ); 2531b40c194SDan Luedtkemy $blankline_html5 = $local_lt . "br /" . $local_gt; 2541b40c194SDan Luedtke 2551da177e4SLinus Torvalds# XML, docbook format 2564d732701SDanilo Cesar Lemes de Paulamy @highlights_xml = ( 2574d732701SDanilo Cesar Lemes de Paula ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"], 2584d732701SDanilo Cesar Lemes de Paula [$type_constant, "<constant>\$1</constant>"], 2594d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<structname>\$1</structname>"], 2604d732701SDanilo Cesar Lemes de Paula [$type_param, "<parameter>\$1</parameter>"], 2614d732701SDanilo Cesar Lemes de Paula [$type_func, "<function>\$1</function>"], 262*5267dd35SPaolo Bonzini [$type_env, "<envar>\$1</envar>"], 263*5267dd35SPaolo Bonzini [$type_member_xml, "<literal><structname>\$1</structname>\$2<structfield>\$3</structfield></literal>"] 2644d732701SDanilo Cesar Lemes de Paula ); 2655c98fc03SJohannes Bergmy $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; 2661da177e4SLinus Torvalds 2671da177e4SLinus Torvalds# gnome, docbook format 2684d732701SDanilo Cesar Lemes de Paulamy @highlights_gnome = ( 2694d732701SDanilo Cesar Lemes de Paula [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"], 2704d732701SDanilo Cesar Lemes de Paula [$type_func, "<function>\$1</function>"], 2714d732701SDanilo Cesar Lemes de Paula [$type_struct, "<structname>\$1</structname>"], 2724d732701SDanilo Cesar Lemes de Paula [$type_env, "<envar>\$1</envar>"], 273*5267dd35SPaolo Bonzini [$type_param, "<parameter>\$1</parameter>" ], 274*5267dd35SPaolo Bonzini [$type_member, "<literal><structname>\$1</structname>\$2<structfield>\$3</structfield></literal>"] 2754d732701SDanilo Cesar Lemes de Paula ); 2761da177e4SLinus Torvaldsmy $blankline_gnome = "</para><para>\n"; 2771da177e4SLinus Torvalds 2781da177e4SLinus Torvalds# these are pretty rough 2794d732701SDanilo Cesar Lemes de Paulamy @highlights_man = ( 2804d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 2814d732701SDanilo Cesar Lemes de Paula [$type_func, "\\\\fB\$1\\\\fP"], 2824d732701SDanilo Cesar Lemes de Paula [$type_struct, "\\\\fI\$1\\\\fP"], 283*5267dd35SPaolo Bonzini [$type_param, "\\\\fI\$1\\\\fP"], 284*5267dd35SPaolo Bonzini [$type_member, "\\\\fI\$1\$2\$3\\\\fP"] 2854d732701SDanilo Cesar Lemes de Paula ); 2861da177e4SLinus Torvaldsmy $blankline_man = ""; 2871da177e4SLinus Torvalds 2881da177e4SLinus Torvalds# text-mode 2894d732701SDanilo Cesar Lemes de Paulamy @highlights_text = ( 2904d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 2914d732701SDanilo Cesar Lemes de Paula [$type_func, "\$1"], 2924d732701SDanilo Cesar Lemes de Paula [$type_struct, "\$1"], 293*5267dd35SPaolo Bonzini [$type_param, "\$1"], 294*5267dd35SPaolo Bonzini [$type_member, "\$1\$2\$3"] 2954d732701SDanilo Cesar Lemes de Paula ); 2961da177e4SLinus Torvaldsmy $blankline_text = ""; 2971da177e4SLinus Torvalds 298c0d1b6eeSJonathan Corbet# rst-mode 299c0d1b6eeSJonathan Corbetmy @highlights_rst = ( 300c0d1b6eeSJonathan Corbet [$type_constant, "``\$1``"], 301f3341dcfSJani Nikula # Note: need to escape () to avoid func matching later 302*5267dd35SPaolo Bonzini [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], 303*5267dd35SPaolo Bonzini [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], 3045219f18aSJonathan Corbet [$type_fp_param, "**\$1\\\\(\\\\)**"], 305a19bce64SJani Nikula [$type_func, "\\:c\\:func\\:`\$1()`"], 30662850976SJani Nikula [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 30762850976SJani Nikula [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 30847ae7aedSJani Nikula [$type_typedef_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 30947ae7aedSJani Nikula [$type_union_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 310a7291e7eSJani Nikula # in rst this can refer to any type 311a7291e7eSJani Nikula [$type_struct, "\\:c\\:type\\:`\$1`"], 312c0d1b6eeSJonathan Corbet [$type_param, "**\$1**"] 313c0d1b6eeSJonathan Corbet ); 314c0d1b6eeSJonathan Corbetmy $blankline_rst = "\n"; 315c0d1b6eeSJonathan Corbet 316eda603f6SJohannes Berg# list mode 3174d732701SDanilo Cesar Lemes de Paulamy @highlights_list = ( 3184d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 3194d732701SDanilo Cesar Lemes de Paula [$type_func, "\$1"], 3204d732701SDanilo Cesar Lemes de Paula [$type_struct, "\$1"], 321*5267dd35SPaolo Bonzini [$type_param, "\$1"], 322*5267dd35SPaolo Bonzini [$type_member, "\$1"] 3234d732701SDanilo Cesar Lemes de Paula ); 324eda603f6SJohannes Bergmy $blankline_list = ""; 3251da177e4SLinus Torvalds 3261da177e4SLinus Torvalds# read arguments 3271da177e4SLinus Torvaldsif ($#ARGV == -1) { 3281da177e4SLinus Torvalds usage(); 3291da177e4SLinus Torvalds} 3301da177e4SLinus Torvalds 3318484baaaSRandy Dunlapmy $kernelversion; 3328484baaaSRandy Dunlapmy $dohighlight = ""; 3338484baaaSRandy Dunlap 3341da177e4SLinus Torvaldsmy $verbose = 0; 3351da177e4SLinus Torvaldsmy $output_mode = "man"; 336e314ba31SDaniel Santosmy $output_preformatted = 0; 3374b44595aSJohannes Bergmy $no_doc_sections = 0; 3380b0f5f29SDaniel Vettermy $enable_lineno = 0; 3394d732701SDanilo Cesar Lemes de Paulamy @highlights = @highlights_man; 3401da177e4SLinus Torvaldsmy $blankline = $blankline_man; 3411da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 342b6c3f456SJani Nikula 343b6c3f456SJani Nikulause constant { 344b6c3f456SJani Nikula OUTPUT_ALL => 0, # output all symbols and doc sections 345b6c3f456SJani Nikula OUTPUT_INCLUDE => 1, # output only specified symbols 346b6c3f456SJani Nikula OUTPUT_EXCLUDE => 2, # output everything except specified symbols 347b6c3f456SJani Nikula OUTPUT_EXPORTED => 3, # output exported symbols 348b6c3f456SJani Nikula OUTPUT_INTERNAL => 4, # output non-exported symbols 349b6c3f456SJani Nikula}; 350b6c3f456SJani Nikulamy $output_selection = OUTPUT_ALL; 351b2c4105bSBen Hutchingsmy $show_not_found = 0; 352b2c4105bSBen Hutchings 35388c2b57dSJani Nikulamy @export_file_list; 35488c2b57dSJani Nikula 355b2c4105bSBen Hutchingsmy @build_time; 356b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 357b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 358b2c4105bSBen Hutchings @build_time = gmtime($seconds); 359b2c4105bSBen Hutchings} else { 360b2c4105bSBen Hutchings @build_time = localtime; 361b2c4105bSBen Hutchings} 362b2c4105bSBen Hutchings 3631da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 3641da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 365b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 366b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 3671da177e4SLinus Torvalds 3688484baaaSRandy Dunlap# Essentially these are globals. 369b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 370b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 3711da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 3721da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 3730b0f5f29SDaniel Vettermy $declaration_start_line; 3741da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 3751c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 3761da177e4SLinus Torvalds 377bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 378bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 379bd0e88e5SRandy Dunlap} 380bd0e88e5SRandy Dunlap 3811da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 3821da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 3831da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 3841da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 3851da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 3861da177e4SLinus Torvalds# into html. 3871da177e4SLinus Torvaldsmy $section_counter = 0; 3881da177e4SLinus Torvalds 3891da177e4SLinus Torvaldsmy $lineprefix=""; 3901da177e4SLinus Torvalds 39148af606aSJani Nikula# Parser states 39248af606aSJani Nikulause constant { 39348af606aSJani Nikula STATE_NORMAL => 0, # normal code 39448af606aSJani Nikula STATE_NAME => 1, # looking for function name 39548af606aSJani Nikula STATE_FIELD => 2, # scanning field start 39648af606aSJani Nikula STATE_PROTO => 3, # scanning prototype 39748af606aSJani Nikula STATE_DOCBLOCK => 4, # documentation block 39848af606aSJani Nikula STATE_INLINE => 5, # gathering documentation outside main block 39948af606aSJani Nikula}; 4001da177e4SLinus Torvaldsmy $state; 401850622dfSRandy Dunlapmy $in_doc_sect; 4021da177e4SLinus Torvalds 40348af606aSJani Nikula# Inline documentation state 40448af606aSJani Nikulause constant { 40548af606aSJani Nikula STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 40648af606aSJani Nikula STATE_INLINE_NAME => 1, # looking for member name (@foo:) 40748af606aSJani Nikula STATE_INLINE_TEXT => 2, # looking for member documentation 40848af606aSJani Nikula STATE_INLINE_END => 3, # done 40948af606aSJani Nikula STATE_INLINE_ERROR => 4, # error - Comment without header was found. 41048af606aSJani Nikula # Spit a warning as it's not 411a4c6ebedSDanilo Cesar Lemes de Paula # proper kernel-doc and ignore the rest. 41248af606aSJani Nikula}; 41348af606aSJani Nikulamy $inline_doc_state; 414a4c6ebedSDanilo Cesar Lemes de Paula 4151da177e4SLinus Torvalds#declaration types: can be 4161da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 4171da177e4SLinus Torvaldsmy $decl_type; 4181da177e4SLinus Torvalds 4191da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 4201da177e4SLinus Torvaldsmy $doc_end = '\*/'; 4211da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 42212ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 4231da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 424f624adefSJani Nikula# @params and a strictly limited set of supported section names 4258569de68SJonathan Corbetmy $doc_sect = $doc_com . 426ef00028bSJonathan Corbet '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)'; 42712ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 4281da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 42948af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$'; 43048af606aSJani Nikulamy $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)'; 43148af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$'; 4320c9aa209SJani Nikulamy $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; 43386ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 4341da177e4SLinus Torvalds 4351da177e4SLinus Torvaldsmy %parameterdescs; 4360b0f5f29SDaniel Vettermy %parameterdesc_start_lines; 4371da177e4SLinus Torvaldsmy @parameterlist; 4381da177e4SLinus Torvaldsmy %sections; 4391da177e4SLinus Torvaldsmy @sectionlist; 4400b0f5f29SDaniel Vettermy %section_start_lines; 441a1d94aa5SRandy Dunlapmy $sectcheck; 442a1d94aa5SRandy Dunlapmy $struct_actual; 4431da177e4SLinus Torvalds 4441da177e4SLinus Torvaldsmy $contents = ""; 4450b0f5f29SDaniel Vettermy $new_start_line = 0; 446f624adefSJani Nikula 447f624adefSJani Nikula# the canonical section names. see also $doc_sect above. 4481da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 4491da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 4501da177e4SLinus Torvaldsmy $section = $section_default; 4511da177e4SLinus Torvaldsmy $section_context = "Context"; 4524092bac7SYacine Belkadimy $section_return = "Return"; 4531da177e4SLinus Torvalds 4541da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 4551da177e4SLinus Torvalds 4561da177e4SLinus Torvaldsreset_state(); 4571da177e4SLinus Torvalds 4581da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) { 4591da177e4SLinus Torvalds my $cmd = shift @ARGV; 4601da177e4SLinus Torvalds if ($cmd eq "-html") { 4611da177e4SLinus Torvalds $output_mode = "html"; 4624d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_html; 4631da177e4SLinus Torvalds $blankline = $blankline_html; 4641b40c194SDan Luedtke } elsif ($cmd eq "-html5") { 4651b40c194SDan Luedtke $output_mode = "html5"; 4664d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_html5; 4671b40c194SDan Luedtke $blankline = $blankline_html5; 4681da177e4SLinus Torvalds } elsif ($cmd eq "-man") { 4691da177e4SLinus Torvalds $output_mode = "man"; 4704d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 4711da177e4SLinus Torvalds $blankline = $blankline_man; 4721da177e4SLinus Torvalds } elsif ($cmd eq "-text") { 4731da177e4SLinus Torvalds $output_mode = "text"; 4744d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_text; 4751da177e4SLinus Torvalds $blankline = $blankline_text; 476c0d1b6eeSJonathan Corbet } elsif ($cmd eq "-rst") { 477c0d1b6eeSJonathan Corbet $output_mode = "rst"; 478c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 479c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 4801da177e4SLinus Torvalds } elsif ($cmd eq "-docbook") { 4811da177e4SLinus Torvalds $output_mode = "xml"; 4824d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_xml; 4831da177e4SLinus Torvalds $blankline = $blankline_xml; 484eda603f6SJohannes Berg } elsif ($cmd eq "-list") { 485eda603f6SJohannes Berg $output_mode = "list"; 4864d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_list; 487eda603f6SJohannes Berg $blankline = $blankline_list; 4881da177e4SLinus Torvalds } elsif ($cmd eq "-gnome") { 4891da177e4SLinus Torvalds $output_mode = "gnome"; 4904d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_gnome; 4911da177e4SLinus Torvalds $blankline = $blankline_gnome; 4921da177e4SLinus Torvalds } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document 4931da177e4SLinus Torvalds $modulename = shift @ARGV; 4941da177e4SLinus Torvalds } elsif ($cmd eq "-function") { # to only output specific functions 495b6c3f456SJani Nikula $output_selection = OUTPUT_INCLUDE; 4961da177e4SLinus Torvalds $function = shift @ARGV; 4971da177e4SLinus Torvalds $function_table{$function} = 1; 498b6c3f456SJani Nikula } elsif ($cmd eq "-nofunction") { # output all except specific functions 499b6c3f456SJani Nikula $output_selection = OUTPUT_EXCLUDE; 5001da177e4SLinus Torvalds $function = shift @ARGV; 5011da177e4SLinus Torvalds $function_table{$function} = 1; 50286ae2e38SJani Nikula } elsif ($cmd eq "-export") { # only exported symbols 503b6c3f456SJani Nikula $output_selection = OUTPUT_EXPORTED; 504da9726ecSJani Nikula %function_table = (); 50586ae2e38SJani Nikula } elsif ($cmd eq "-internal") { # only non-exported symbols 506b6c3f456SJani Nikula $output_selection = OUTPUT_INTERNAL; 507da9726ecSJani Nikula %function_table = (); 50888c2b57dSJani Nikula } elsif ($cmd eq "-export-file") { 50988c2b57dSJani Nikula my $file = shift @ARGV; 51088c2b57dSJani Nikula push(@export_file_list, $file); 5111da177e4SLinus Torvalds } elsif ($cmd eq "-v") { 5121da177e4SLinus Torvalds $verbose = 1; 5131da177e4SLinus Torvalds } elsif (($cmd eq "-h") || ($cmd eq "--help")) { 5141da177e4SLinus Torvalds usage(); 5154b44595aSJohannes Berg } elsif ($cmd eq '-no-doc-sections') { 5164b44595aSJohannes Berg $no_doc_sections = 1; 5170b0f5f29SDaniel Vetter } elsif ($cmd eq '-enable-lineno') { 5180b0f5f29SDaniel Vetter $enable_lineno = 1; 519e946c43aSJohannes Berg } elsif ($cmd eq '-show-not-found') { 520e946c43aSJohannes Berg $show_not_found = 1; 5211da177e4SLinus Torvalds } 5221da177e4SLinus Torvalds} 5231da177e4SLinus Torvalds 5248484baaaSRandy Dunlap# continue execution near EOF; 5258484baaaSRandy Dunlap 52653f049faSBorislav Petkov# get kernel version from env 52753f049faSBorislav Petkovsub get_kernel_version() { 5281b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 52953f049faSBorislav Petkov 53053f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 53153f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 53253f049faSBorislav Petkov } 53353f049faSBorislav Petkov return $version; 53453f049faSBorislav Petkov} 5351da177e4SLinus Torvalds 5360b0f5f29SDaniel Vetter# 5370b0f5f29SDaniel Vettersub print_lineno { 5380b0f5f29SDaniel Vetter my $lineno = shift; 5390b0f5f29SDaniel Vetter if ($enable_lineno && defined($lineno)) { 5400b0f5f29SDaniel Vetter print "#define LINENO " . $lineno . "\n"; 5410b0f5f29SDaniel Vetter } 5420b0f5f29SDaniel Vetter} 5431da177e4SLinus Torvalds## 5441da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 5451da177e4SLinus Torvalds# 5461da177e4SLinus Torvaldssub dump_section { 54794dc7ad5SRandy Dunlap my $file = shift; 5481da177e4SLinus Torvalds my $name = shift; 5491da177e4SLinus Torvalds my $contents = join "\n", @_; 5501da177e4SLinus Torvalds 55113901ef2SJani Nikula if ($name =~ m/$type_param/) { 5521da177e4SLinus Torvalds $name = $1; 5531da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 554a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 5550b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 5560b0f5f29SDaniel Vetter $new_start_line = 0; 557ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 558ced69090SRandy Dunlap $name = "..."; 559ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 560a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 5610b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 5620b0f5f29SDaniel Vetter $new_start_line = 0; 5631da177e4SLinus Torvalds } else { 56494dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 56595b6be9dSJani Nikula # Only warn on user specified duplicate section names. 56695b6be9dSJani Nikula if ($name ne $section_default) { 56732217761SJani Nikula print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; 56832217761SJani Nikula ++$warnings; 56995b6be9dSJani Nikula } 57032217761SJani Nikula $sections{$name} .= $contents; 57132217761SJani Nikula } else { 5721da177e4SLinus Torvalds $sections{$name} = $contents; 5731da177e4SLinus Torvalds push @sectionlist, $name; 5740b0f5f29SDaniel Vetter $section_start_lines{$name} = $new_start_line; 5750b0f5f29SDaniel Vetter $new_start_line = 0; 5761da177e4SLinus Torvalds } 5771da177e4SLinus Torvalds } 57832217761SJani Nikula} 5791da177e4SLinus Torvalds 5801da177e4SLinus Torvalds## 581b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 582b112e0f7SJohannes Berg# 583b112e0f7SJohannes Bergsub dump_doc_section { 58494dc7ad5SRandy Dunlap my $file = shift; 585b112e0f7SJohannes Berg my $name = shift; 586b112e0f7SJohannes Berg my $contents = join "\n", @_; 587b112e0f7SJohannes Berg 5884b44595aSJohannes Berg if ($no_doc_sections) { 5894b44595aSJohannes Berg return; 5904b44595aSJohannes Berg } 5914b44595aSJohannes Berg 592b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 593b6c3f456SJani Nikula ($output_selection == OUTPUT_INCLUDE && 594b6c3f456SJani Nikula defined($function_table{$name})) || 595b6c3f456SJani Nikula ($output_selection == OUTPUT_EXCLUDE && 596b6c3f456SJani Nikula !defined($function_table{$name}))) 597b112e0f7SJohannes Berg { 59894dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 599b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 600b112e0f7SJohannes Berg 'sections' => \%sections, 601b112e0f7SJohannes Berg 'module' => $modulename, 602b6c3f456SJani Nikula 'content-only' => ($output_selection != OUTPUT_ALL), }); 603b112e0f7SJohannes Berg } 604b112e0f7SJohannes Berg} 605b112e0f7SJohannes Berg 606b112e0f7SJohannes Berg## 6071da177e4SLinus Torvalds# output function 6081da177e4SLinus Torvalds# 6091da177e4SLinus Torvalds# parameterdescs, a hash. 6101da177e4SLinus Torvalds# function => "function name" 6111da177e4SLinus Torvalds# parameterlist => @list of parameters 6121da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 6131da177e4SLinus Torvalds# sectionlist => @list of sections 614a21217daSRandy Dunlap# sections => %section descriptions 6151da177e4SLinus Torvalds# 6161da177e4SLinus Torvalds 6171da177e4SLinus Torvaldssub output_highlight { 6181da177e4SLinus Torvalds my $contents = join "\n",@_; 6191da177e4SLinus Torvalds my $line; 6201da177e4SLinus Torvalds 6211da177e4SLinus Torvalds# DEBUG 6221da177e4SLinus Torvalds# if (!defined $contents) { 6231da177e4SLinus Torvalds# use Carp; 6241da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 6251da177e4SLinus Torvalds# } 6261da177e4SLinus Torvalds 6271b40c194SDan Luedtke if ($output_mode eq "html" || $output_mode eq "html5" || 6281b40c194SDan Luedtke $output_mode eq "xml") { 6296b5b55f6SRandy Dunlap $contents = local_unescape($contents); 6306b5b55f6SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 6312b35f4d9SRandy Dunlap $contents =~ s/\\\\\\/\&/g; 6326b5b55f6SRandy Dunlap } 6333eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 6341da177e4SLinus Torvalds eval $dohighlight; 6351da177e4SLinus Torvalds die $@ if $@; 6363eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 6373eb014a1SRandy Dunlap 6381b40c194SDan Luedtke# strip whitespaces when generating html5 6391b40c194SDan Luedtke if ($output_mode eq "html5") { 6401b40c194SDan Luedtke $contents =~ s/^\s+//; 6411b40c194SDan Luedtke $contents =~ s/\s+$//; 6421b40c194SDan Luedtke } 6431da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 64412ae6779SDaniel Santos if (! $output_preformatted) { 64512ae6779SDaniel Santos $line =~ s/^\s*//; 64612ae6779SDaniel Santos } 6471da177e4SLinus Torvalds if ($line eq ""){ 648e314ba31SDaniel Santos if (! $output_preformatted) { 6496b5b55f6SRandy Dunlap print $lineprefix, local_unescape($blankline); 650e314ba31SDaniel Santos } 6511da177e4SLinus Torvalds } else { 6521da177e4SLinus Torvalds $line =~ s/\\\\\\/\&/g; 653cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 654cdccb316SRandy Dunlap print "\\&$line"; 655cdccb316SRandy Dunlap } else { 6561da177e4SLinus Torvalds print $lineprefix, $line; 6571da177e4SLinus Torvalds } 658cdccb316SRandy Dunlap } 6591da177e4SLinus Torvalds print "\n"; 6601da177e4SLinus Torvalds } 6611da177e4SLinus Torvalds} 6621da177e4SLinus Torvalds 6631da177e4SLinus Torvalds# output sections in html 6641da177e4SLinus Torvaldssub output_section_html(%) { 6651da177e4SLinus Torvalds my %args = %{$_[0]}; 6661da177e4SLinus Torvalds my $section; 6671da177e4SLinus Torvalds 6681da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6691da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 6701da177e4SLinus Torvalds print "<blockquote>\n"; 6711da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6721da177e4SLinus Torvalds print "</blockquote>\n"; 6731da177e4SLinus Torvalds } 6741da177e4SLinus Torvalds} 6751da177e4SLinus Torvalds 6761da177e4SLinus Torvalds# output enum in html 6771da177e4SLinus Torvaldssub output_enum_html(%) { 6781da177e4SLinus Torvalds my %args = %{$_[0]}; 6791da177e4SLinus Torvalds my ($parameter); 6801da177e4SLinus Torvalds my $count; 6811da177e4SLinus Torvalds print "<h2>enum " . $args{'enum'} . "</h2>\n"; 6821da177e4SLinus Torvalds 6831da177e4SLinus Torvalds print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; 6841da177e4SLinus Torvalds $count = 0; 6851da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6861da177e4SLinus Torvalds print " <b>" . $parameter . "</b>"; 6871da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 6881da177e4SLinus Torvalds $count++; 6891da177e4SLinus Torvalds print ",\n"; 6901da177e4SLinus Torvalds } 6911da177e4SLinus Torvalds print "<br>"; 6921da177e4SLinus Torvalds } 6931da177e4SLinus Torvalds print "};<br>\n"; 6941da177e4SLinus Torvalds 6951da177e4SLinus Torvalds print "<h3>Constants</h3>\n"; 6961da177e4SLinus Torvalds print "<dl>\n"; 6971da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6981da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 6991da177e4SLinus Torvalds print "<dd>"; 7001da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter}); 7011da177e4SLinus Torvalds } 7021da177e4SLinus Torvalds print "</dl>\n"; 7031da177e4SLinus Torvalds output_section_html(@_); 7041da177e4SLinus Torvalds print "<hr>\n"; 7051da177e4SLinus Torvalds} 7061da177e4SLinus Torvalds 707d28bee0cSRandy Dunlap# output typedef in html 7081da177e4SLinus Torvaldssub output_typedef_html(%) { 7091da177e4SLinus Torvalds my %args = %{$_[0]}; 7101da177e4SLinus Torvalds my ($parameter); 7111da177e4SLinus Torvalds my $count; 7121da177e4SLinus Torvalds print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; 7131da177e4SLinus Torvalds 7141da177e4SLinus Torvalds print "<b>typedef " . $args{'typedef'} . "</b>\n"; 7151da177e4SLinus Torvalds output_section_html(@_); 7161da177e4SLinus Torvalds print "<hr>\n"; 7171da177e4SLinus Torvalds} 7181da177e4SLinus Torvalds 7191da177e4SLinus Torvalds# output struct in html 7201da177e4SLinus Torvaldssub output_struct_html(%) { 7211da177e4SLinus Torvalds my %args = %{$_[0]}; 7221da177e4SLinus Torvalds my ($parameter); 7231da177e4SLinus Torvalds 724262d9b01SRandy Dunlap print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; 7251da177e4SLinus Torvalds print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; 7261da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7271da177e4SLinus Torvalds if ($parameter =~ /^#/) { 7281da177e4SLinus Torvalds print "$parameter<br>\n"; 7291da177e4SLinus Torvalds next; 7301da177e4SLinus Torvalds } 7311da177e4SLinus Torvalds my $parameter_name = $parameter; 7321da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7331da177e4SLinus Torvalds 7341da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7351da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 7361da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 7371da177e4SLinus Torvalds # pointer-to-function 7383eb014a1SRandy Dunlap print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; 7391da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 7403eb014a1SRandy Dunlap # bitfield 7413eb014a1SRandy Dunlap print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; 7421da177e4SLinus Torvalds } else { 7433eb014a1SRandy Dunlap print " <i>$type</i> <b>$parameter</b>;<br>\n"; 7441da177e4SLinus Torvalds } 7451da177e4SLinus Torvalds } 7461da177e4SLinus Torvalds print "};<br>\n"; 7471da177e4SLinus Torvalds 7481da177e4SLinus Torvalds print "<h3>Members</h3>\n"; 7491da177e4SLinus Torvalds print "<dl>\n"; 7501da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7511da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 7521da177e4SLinus Torvalds 7531da177e4SLinus Torvalds my $parameter_name = $parameter; 7541da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7551da177e4SLinus Torvalds 7561da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7571da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 7581da177e4SLinus Torvalds print "<dd>"; 7591da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7601da177e4SLinus Torvalds } 7611da177e4SLinus Torvalds print "</dl>\n"; 7621da177e4SLinus Torvalds output_section_html(@_); 7631da177e4SLinus Torvalds print "<hr>\n"; 7641da177e4SLinus Torvalds} 7651da177e4SLinus Torvalds 7661da177e4SLinus Torvalds# output function in html 7671da177e4SLinus Torvaldssub output_function_html(%) { 7681da177e4SLinus Torvalds my %args = %{$_[0]}; 7691da177e4SLinus Torvalds my ($parameter, $section); 7701da177e4SLinus Torvalds my $count; 7711da177e4SLinus Torvalds 772262d9b01SRandy Dunlap print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; 7731da177e4SLinus Torvalds print "<i>" . $args{'functiontype'} . "</i>\n"; 7741da177e4SLinus Torvalds print "<b>" . $args{'function'} . "</b>\n"; 7751da177e4SLinus Torvalds print "("; 7761da177e4SLinus Torvalds $count = 0; 7771da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7781da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 7791da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 7801da177e4SLinus Torvalds # pointer-to-function 7811da177e4SLinus Torvalds print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; 7821da177e4SLinus Torvalds } else { 7831da177e4SLinus Torvalds print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; 7841da177e4SLinus Torvalds } 7851da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 7861da177e4SLinus Torvalds $count++; 7871da177e4SLinus Torvalds print ",\n"; 7881da177e4SLinus Torvalds } 7891da177e4SLinus Torvalds } 7901da177e4SLinus Torvalds print ")\n"; 7911da177e4SLinus Torvalds 7921da177e4SLinus Torvalds print "<h3>Arguments</h3>\n"; 7931da177e4SLinus Torvalds print "<dl>\n"; 7941da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7951da177e4SLinus Torvalds my $parameter_name = $parameter; 7961da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7971da177e4SLinus Torvalds 7981da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7991da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 8001da177e4SLinus Torvalds print "<dd>"; 8011da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 8021da177e4SLinus Torvalds } 8031da177e4SLinus Torvalds print "</dl>\n"; 8041da177e4SLinus Torvalds output_section_html(@_); 8051da177e4SLinus Torvalds print "<hr>\n"; 8061da177e4SLinus Torvalds} 8071da177e4SLinus Torvalds 808b112e0f7SJohannes Berg# output DOC: block header in html 809b112e0f7SJohannes Bergsub output_blockhead_html(%) { 8101da177e4SLinus Torvalds my %args = %{$_[0]}; 8111da177e4SLinus Torvalds my ($parameter, $section); 8121da177e4SLinus Torvalds my $count; 8131da177e4SLinus Torvalds 8141da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 8151da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 8161da177e4SLinus Torvalds print "<ul>\n"; 8171da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 8181da177e4SLinus Torvalds print "</ul>\n"; 8191da177e4SLinus Torvalds } 8201da177e4SLinus Torvalds print "<hr>\n"; 8211da177e4SLinus Torvalds} 8221da177e4SLinus Torvalds 8231b40c194SDan Luedtke# output sections in html5 8241b40c194SDan Luedtkesub output_section_html5(%) { 8251b40c194SDan Luedtke my %args = %{$_[0]}; 8261b40c194SDan Luedtke my $section; 8271b40c194SDan Luedtke 8281b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 8291b40c194SDan Luedtke print "<section>\n"; 8301b40c194SDan Luedtke print "<h1>$section</h1>\n"; 8311b40c194SDan Luedtke print "<p>\n"; 8321b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 8331b40c194SDan Luedtke print "</p>\n"; 8341b40c194SDan Luedtke print "</section>\n"; 8351b40c194SDan Luedtke } 8361b40c194SDan Luedtke} 8371b40c194SDan Luedtke 8381b40c194SDan Luedtke# output enum in html5 8391b40c194SDan Luedtkesub output_enum_html5(%) { 8401b40c194SDan Luedtke my %args = %{$_[0]}; 8411b40c194SDan Luedtke my ($parameter); 8421b40c194SDan Luedtke my $count; 8431b40c194SDan Luedtke my $html5id; 8441b40c194SDan Luedtke 8451b40c194SDan Luedtke $html5id = $args{'enum'}; 8461b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8471b40c194SDan Luedtke print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; 8481b40c194SDan Luedtke print "<h1>enum " . $args{'enum'} . "</h1>\n"; 8491b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8501b40c194SDan Luedtke print "<li>"; 8511b40c194SDan Luedtke print "<span class=\"keyword\">enum</span> "; 8521b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; 8531b40c194SDan Luedtke print "</li>\n"; 8541b40c194SDan Luedtke $count = 0; 8551b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8561b40c194SDan Luedtke print "<li class=\"indent\">"; 8571b40c194SDan Luedtke print "<span class=\"param\">" . $parameter . "</span>"; 8581b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 8591b40c194SDan Luedtke $count++; 8601b40c194SDan Luedtke print ","; 8611b40c194SDan Luedtke } 8621b40c194SDan Luedtke print "</li>\n"; 8631b40c194SDan Luedtke } 8641b40c194SDan Luedtke print "<li>};</li>\n"; 8651b40c194SDan Luedtke print "</ol>\n"; 8661b40c194SDan Luedtke 8671b40c194SDan Luedtke print "<section>\n"; 8681b40c194SDan Luedtke print "<h1>Constants</h1>\n"; 8691b40c194SDan Luedtke print "<dl>\n"; 8701b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8711b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 8721b40c194SDan Luedtke print "<dd>"; 8731b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter}); 8741b40c194SDan Luedtke print "</dd>\n"; 8751b40c194SDan Luedtke } 8761b40c194SDan Luedtke print "</dl>\n"; 8771b40c194SDan Luedtke print "</section>\n"; 8781b40c194SDan Luedtke output_section_html5(@_); 8791b40c194SDan Luedtke print "</article>\n"; 8801b40c194SDan Luedtke} 8811b40c194SDan Luedtke 8821b40c194SDan Luedtke# output typedef in html5 8831b40c194SDan Luedtkesub output_typedef_html5(%) { 8841b40c194SDan Luedtke my %args = %{$_[0]}; 8851b40c194SDan Luedtke my ($parameter); 8861b40c194SDan Luedtke my $count; 8871b40c194SDan Luedtke my $html5id; 8881b40c194SDan Luedtke 8891b40c194SDan Luedtke $html5id = $args{'typedef'}; 8901b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8911b40c194SDan Luedtke print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; 8921b40c194SDan Luedtke print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; 8931b40c194SDan Luedtke 8941b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8951b40c194SDan Luedtke print "<li>"; 8961b40c194SDan Luedtke print "<span class=\"keyword\">typedef</span> "; 8971b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; 8981b40c194SDan Luedtke print "</li>\n"; 8991b40c194SDan Luedtke print "</ol>\n"; 9001b40c194SDan Luedtke output_section_html5(@_); 9011b40c194SDan Luedtke print "</article>\n"; 9021b40c194SDan Luedtke} 9031b40c194SDan Luedtke 9041b40c194SDan Luedtke# output struct in html5 9051b40c194SDan Luedtkesub output_struct_html5(%) { 9061b40c194SDan Luedtke my %args = %{$_[0]}; 9071b40c194SDan Luedtke my ($parameter); 9081b40c194SDan Luedtke my $html5id; 9091b40c194SDan Luedtke 9101b40c194SDan Luedtke $html5id = $args{'struct'}; 9111b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 9121b40c194SDan Luedtke print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n"; 9131b40c194SDan Luedtke print "<hgroup>\n"; 9141b40c194SDan Luedtke print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>"; 9151b40c194SDan Luedtke print "<h2>". $args{'purpose'} . "</h2>\n"; 9161b40c194SDan Luedtke print "</hgroup>\n"; 9171b40c194SDan Luedtke print "<ol class=\"code\">\n"; 9181b40c194SDan Luedtke print "<li>"; 9191b40c194SDan Luedtke print "<span class=\"type\">" . $args{'type'} . "</span> "; 9201b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'struct'} . "</span> {"; 9211b40c194SDan Luedtke print "</li>\n"; 9221b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9231b40c194SDan Luedtke print "<li class=\"indent\">"; 9241b40c194SDan Luedtke if ($parameter =~ /^#/) { 9251b40c194SDan Luedtke print "<span class=\"param\">" . $parameter ."</span>\n"; 9261b40c194SDan Luedtke print "</li>\n"; 9271b40c194SDan Luedtke next; 9281b40c194SDan Luedtke } 9291b40c194SDan Luedtke my $parameter_name = $parameter; 9301b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 9311b40c194SDan Luedtke 9321b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 9331b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 9341b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 9351b40c194SDan Luedtke # pointer-to-function 9361b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 9371b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9381b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 9391b40c194SDan Luedtke print "(<span class=\"args\">$2</span>);"; 9401b40c194SDan Luedtke } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 9411b40c194SDan Luedtke # bitfield 9421b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 9431b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9441b40c194SDan Luedtke print "<span class=\"bits\">$2</span>;"; 9451b40c194SDan Luedtke } else { 9461b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 9471b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>;"; 9481b40c194SDan Luedtke } 9491b40c194SDan Luedtke print "</li>\n"; 9501b40c194SDan Luedtke } 9511b40c194SDan Luedtke print "<li>};</li>\n"; 9521b40c194SDan Luedtke print "</ol>\n"; 9531b40c194SDan Luedtke 9541b40c194SDan Luedtke print "<section>\n"; 9551b40c194SDan Luedtke print "<h1>Members</h1>\n"; 9561b40c194SDan Luedtke print "<dl>\n"; 9571b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9581b40c194SDan Luedtke ($parameter =~ /^#/) && next; 9591b40c194SDan Luedtke 9601b40c194SDan Luedtke my $parameter_name = $parameter; 9611b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 9621b40c194SDan Luedtke 9631b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 9641b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 9651b40c194SDan Luedtke print "<dd>"; 9661b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 9671b40c194SDan Luedtke print "</dd>\n"; 9681b40c194SDan Luedtke } 9691b40c194SDan Luedtke print "</dl>\n"; 9701b40c194SDan Luedtke print "</section>\n"; 9711b40c194SDan Luedtke output_section_html5(@_); 9721b40c194SDan Luedtke print "</article>\n"; 9731b40c194SDan Luedtke} 9741b40c194SDan Luedtke 9751b40c194SDan Luedtke# output function in html5 9761b40c194SDan Luedtkesub output_function_html5(%) { 9771b40c194SDan Luedtke my %args = %{$_[0]}; 9781b40c194SDan Luedtke my ($parameter, $section); 9791b40c194SDan Luedtke my $count; 9801b40c194SDan Luedtke my $html5id; 9811b40c194SDan Luedtke 9821b40c194SDan Luedtke $html5id = $args{'function'}; 9831b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 9841b40c194SDan Luedtke print "<article class=\"function\" id=\"func:". $html5id . "\">\n"; 9851b40c194SDan Luedtke print "<hgroup>\n"; 9861b40c194SDan Luedtke print "<h1>" . $args{'function'} . "</h1>"; 9871b40c194SDan Luedtke print "<h2>" . $args{'purpose'} . "</h2>\n"; 9881b40c194SDan Luedtke print "</hgroup>\n"; 9891b40c194SDan Luedtke print "<ol class=\"code\">\n"; 9901b40c194SDan Luedtke print "<li>"; 9911b40c194SDan Luedtke print "<span class=\"type\">" . $args{'functiontype'} . "</span> "; 9921b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'function'} . "</span> ("; 9931b40c194SDan Luedtke print "</li>"; 9941b40c194SDan Luedtke $count = 0; 9951b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9961b40c194SDan Luedtke print "<li class=\"indent\">"; 9971b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 9981b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 9991b40c194SDan Luedtke # pointer-to-function 10001b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 10011b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 10021b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 10031b40c194SDan Luedtke print "(<span class=\"args\">$2</span>)"; 10041b40c194SDan Luedtke } else { 10051b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 10061b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 10071b40c194SDan Luedtke } 10081b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 10091b40c194SDan Luedtke $count++; 10101b40c194SDan Luedtke print ","; 10111b40c194SDan Luedtke } 10121b40c194SDan Luedtke print "</li>\n"; 10131b40c194SDan Luedtke } 10141b40c194SDan Luedtke print "<li>)</li>\n"; 10151b40c194SDan Luedtke print "</ol>\n"; 10161b40c194SDan Luedtke 10171b40c194SDan Luedtke print "<section>\n"; 10181b40c194SDan Luedtke print "<h1>Arguments</h1>\n"; 10191b40c194SDan Luedtke print "<p>\n"; 10201b40c194SDan Luedtke print "<dl>\n"; 10211b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 10221b40c194SDan Luedtke my $parameter_name = $parameter; 10231b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 10241b40c194SDan Luedtke 10251b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 10261b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 10271b40c194SDan Luedtke print "<dd>"; 10281b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 10291b40c194SDan Luedtke print "</dd>\n"; 10301b40c194SDan Luedtke } 10311b40c194SDan Luedtke print "</dl>\n"; 10321b40c194SDan Luedtke print "</section>\n"; 10331b40c194SDan Luedtke output_section_html5(@_); 10341b40c194SDan Luedtke print "</article>\n"; 10351b40c194SDan Luedtke} 10361b40c194SDan Luedtke 10371b40c194SDan Luedtke# output DOC: block header in html5 10381b40c194SDan Luedtkesub output_blockhead_html5(%) { 10391b40c194SDan Luedtke my %args = %{$_[0]}; 10401b40c194SDan Luedtke my ($parameter, $section); 10411b40c194SDan Luedtke my $count; 10421b40c194SDan Luedtke my $html5id; 10431b40c194SDan Luedtke 10441b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 10451b40c194SDan Luedtke $html5id = $section; 10461b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 10471b40c194SDan Luedtke print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n"; 10481b40c194SDan Luedtke print "<h1>$section</h1>\n"; 10491b40c194SDan Luedtke print "<p>\n"; 10501b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 10511b40c194SDan Luedtke print "</p>\n"; 10521b40c194SDan Luedtke } 10531b40c194SDan Luedtke print "</article>\n"; 10541b40c194SDan Luedtke} 10551b40c194SDan Luedtke 10561da177e4SLinus Torvaldssub output_section_xml(%) { 10571da177e4SLinus Torvalds my %args = %{$_[0]}; 10581da177e4SLinus Torvalds my $section; 10591da177e4SLinus Torvalds # print out each section 10601da177e4SLinus Torvalds $lineprefix=" "; 10611da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1062c73894c1SRich Walker print "<refsect1>\n"; 1063c73894c1SRich Walker print "<title>$section</title>\n"; 10641da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 1065c73894c1SRich Walker print "<informalexample><programlisting>\n"; 1066e314ba31SDaniel Santos $output_preformatted = 1; 1067c73894c1SRich Walker } else { 1068c73894c1SRich Walker print "<para>\n"; 10691da177e4SLinus Torvalds } 10701da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1071e314ba31SDaniel Santos $output_preformatted = 0; 10721da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 1073c73894c1SRich Walker print "</programlisting></informalexample>\n"; 1074c73894c1SRich Walker } else { 1075c73894c1SRich Walker print "</para>\n"; 10761da177e4SLinus Torvalds } 1077c73894c1SRich Walker print "</refsect1>\n"; 10781da177e4SLinus Torvalds } 10791da177e4SLinus Torvalds} 10801da177e4SLinus Torvalds 10811da177e4SLinus Torvalds# output function in XML DocBook 10821da177e4SLinus Torvaldssub output_function_xml(%) { 10831da177e4SLinus Torvalds my %args = %{$_[0]}; 10841da177e4SLinus Torvalds my ($parameter, $section); 10851da177e4SLinus Torvalds my $count; 10861da177e4SLinus Torvalds my $id; 10871da177e4SLinus Torvalds 10881da177e4SLinus Torvalds $id = "API-" . $args{'function'}; 10891da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 10901da177e4SLinus Torvalds 10915449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 10928b0c2d98SMartin Waitz print "<refentryinfo>\n"; 10938b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 10948b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 10958b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 10968b0c2d98SMartin Waitz print "</refentryinfo>\n"; 10971da177e4SLinus Torvalds print "<refmeta>\n"; 10985449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; 10998b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 11000366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 11011da177e4SLinus Torvalds print "</refmeta>\n"; 11021da177e4SLinus Torvalds print "<refnamediv>\n"; 11031da177e4SLinus Torvalds print " <refname>" . $args{'function'} . "</refname>\n"; 11041da177e4SLinus Torvalds print " <refpurpose>\n"; 11051da177e4SLinus Torvalds print " "; 11061da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 11071da177e4SLinus Torvalds print " </refpurpose>\n"; 11081da177e4SLinus Torvalds print "</refnamediv>\n"; 11091da177e4SLinus Torvalds 11101da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 11111da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 11121da177e4SLinus Torvalds print " <funcsynopsis><funcprototype>\n"; 11131da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 11141da177e4SLinus Torvalds print "<function>" . $args{'function'} . " </function></funcdef>\n"; 11151da177e4SLinus Torvalds 11161da177e4SLinus Torvalds $count = 0; 11171da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 11181da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11191da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 11201da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 11211da177e4SLinus Torvalds # pointer-to-function 11221da177e4SLinus Torvalds print " <paramdef>$1<parameter>$parameter</parameter>)\n"; 11231da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 11241da177e4SLinus Torvalds } else { 11251da177e4SLinus Torvalds print " <paramdef>" . $type; 11261da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 11271da177e4SLinus Torvalds } 11281da177e4SLinus Torvalds } 11291da177e4SLinus Torvalds } else { 11306013d544SMartin Waitz print " <void/>\n"; 11311da177e4SLinus Torvalds } 11321da177e4SLinus Torvalds print " </funcprototype></funcsynopsis>\n"; 11331da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 11341da177e4SLinus Torvalds 11351da177e4SLinus Torvalds # print parameters 11361da177e4SLinus Torvalds print "<refsect1>\n <title>Arguments</title>\n"; 11371da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 11381da177e4SLinus Torvalds print " <variablelist>\n"; 11391da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11401da177e4SLinus Torvalds my $parameter_name = $parameter; 11411da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 1142fc6d7af8SPaolo Bonzini $type = $args{'parametertypes'}{$parameter}; 11431da177e4SLinus Torvalds 1144fc6d7af8SPaolo Bonzini print " <varlistentry>\n <term><parameter>$type $parameter</parameter></term>\n"; 11451da177e4SLinus Torvalds print " <listitem>\n <para>\n"; 11461da177e4SLinus Torvalds $lineprefix=" "; 11471da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 11481da177e4SLinus Torvalds print " </para>\n </listitem>\n </varlistentry>\n"; 11491da177e4SLinus Torvalds } 11501da177e4SLinus Torvalds print " </variablelist>\n"; 11511da177e4SLinus Torvalds } else { 11521da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 11531da177e4SLinus Torvalds } 11541da177e4SLinus Torvalds print "</refsect1>\n"; 11551da177e4SLinus Torvalds 11561da177e4SLinus Torvalds output_section_xml(@_); 11571da177e4SLinus Torvalds print "</refentry>\n\n"; 11581da177e4SLinus Torvalds} 11591da177e4SLinus Torvalds 11601da177e4SLinus Torvalds# output struct in XML DocBook 11611da177e4SLinus Torvaldssub output_struct_xml(%) { 11621da177e4SLinus Torvalds my %args = %{$_[0]}; 11631da177e4SLinus Torvalds my ($parameter, $section); 11641da177e4SLinus Torvalds my $id; 11651da177e4SLinus Torvalds 11661da177e4SLinus Torvalds $id = "API-struct-" . $args{'struct'}; 11671da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 11681da177e4SLinus Torvalds 11695449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 11708b0c2d98SMartin Waitz print "<refentryinfo>\n"; 11718b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 11728b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 11738b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 11748b0c2d98SMartin Waitz print "</refentryinfo>\n"; 11751da177e4SLinus Torvalds print "<refmeta>\n"; 11765449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; 11778b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 11780366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 11791da177e4SLinus Torvalds print "</refmeta>\n"; 11801da177e4SLinus Torvalds print "<refnamediv>\n"; 11811da177e4SLinus Torvalds print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; 11821da177e4SLinus Torvalds print " <refpurpose>\n"; 11831da177e4SLinus Torvalds print " "; 11841da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 11851da177e4SLinus Torvalds print " </refpurpose>\n"; 11861da177e4SLinus Torvalds print "</refnamediv>\n"; 11871da177e4SLinus Torvalds 11881da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 11891da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 11901da177e4SLinus Torvalds print " <programlisting>\n"; 11911da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 11921da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11931da177e4SLinus Torvalds if ($parameter =~ /^#/) { 11942b35f4d9SRandy Dunlap my $prm = $parameter; 11952b35f4d9SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 11962b35f4d9SRandy Dunlap # This allows us to have #define macros interspersed in a struct. 11972b35f4d9SRandy Dunlap $prm =~ s/\\\\\\/\&/g; 11982b35f4d9SRandy Dunlap print "$prm\n"; 11991da177e4SLinus Torvalds next; 12001da177e4SLinus Torvalds } 12011da177e4SLinus Torvalds 12021da177e4SLinus Torvalds my $parameter_name = $parameter; 12031da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12041da177e4SLinus Torvalds 12051da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 12061da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 12071da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 12081da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 12091da177e4SLinus Torvalds # pointer-to-function 12101da177e4SLinus Torvalds print " $1 $parameter) ($2);\n"; 12111da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 121251f5a0c8SRandy Dunlap # bitfield 12131da177e4SLinus Torvalds print " $1 $parameter$2;\n"; 12141da177e4SLinus Torvalds } else { 12151da177e4SLinus Torvalds print " " . $type . " " . $parameter . ";\n"; 12161da177e4SLinus Torvalds } 12171da177e4SLinus Torvalds } 12181da177e4SLinus Torvalds print "};"; 12191da177e4SLinus Torvalds print " </programlisting>\n"; 12201da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 12211da177e4SLinus Torvalds 12221da177e4SLinus Torvalds print " <refsect1>\n"; 12231da177e4SLinus Torvalds print " <title>Members</title>\n"; 12241da177e4SLinus Torvalds 122539f00c08SRandy Dunlap if ($#{$args{'parameterlist'}} >= 0) { 12261da177e4SLinus Torvalds print " <variablelist>\n"; 12271da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12281da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 12291da177e4SLinus Torvalds 12301da177e4SLinus Torvalds my $parameter_name = $parameter; 12311da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12321da177e4SLinus Torvalds 12331da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 12341da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1235fc6d7af8SPaolo Bonzini $type = $args{'parametertypes'}{$parameter}; 12361da177e4SLinus Torvalds print " <varlistentry>"; 1237fc6d7af8SPaolo Bonzini print " <term><literal>$type $parameter</literal></term>\n"; 12381da177e4SLinus Torvalds print " <listitem><para>\n"; 12391da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 12401da177e4SLinus Torvalds print " </para></listitem>\n"; 12411da177e4SLinus Torvalds print " </varlistentry>\n"; 12421da177e4SLinus Torvalds } 12431da177e4SLinus Torvalds print " </variablelist>\n"; 124439f00c08SRandy Dunlap } else { 124539f00c08SRandy Dunlap print " <para>\n None\n </para>\n"; 124639f00c08SRandy Dunlap } 12471da177e4SLinus Torvalds print " </refsect1>\n"; 12481da177e4SLinus Torvalds 12491da177e4SLinus Torvalds output_section_xml(@_); 12501da177e4SLinus Torvalds 12511da177e4SLinus Torvalds print "</refentry>\n\n"; 12521da177e4SLinus Torvalds} 12531da177e4SLinus Torvalds 12541da177e4SLinus Torvalds# output enum in XML DocBook 12551da177e4SLinus Torvaldssub output_enum_xml(%) { 12561da177e4SLinus Torvalds my %args = %{$_[0]}; 12571da177e4SLinus Torvalds my ($parameter, $section); 12581da177e4SLinus Torvalds my $count; 12591da177e4SLinus Torvalds my $id; 12601da177e4SLinus Torvalds 12611da177e4SLinus Torvalds $id = "API-enum-" . $args{'enum'}; 12621da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12631da177e4SLinus Torvalds 12645449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 12658b0c2d98SMartin Waitz print "<refentryinfo>\n"; 12668b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 12678b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 12688b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 12698b0c2d98SMartin Waitz print "</refentryinfo>\n"; 12701da177e4SLinus Torvalds print "<refmeta>\n"; 12715449bc94SPavel Pisa print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; 12728b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 12730366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 12741da177e4SLinus Torvalds print "</refmeta>\n"; 12751da177e4SLinus Torvalds print "<refnamediv>\n"; 12761da177e4SLinus Torvalds print " <refname>enum " . $args{'enum'} . "</refname>\n"; 12771da177e4SLinus Torvalds print " <refpurpose>\n"; 12781da177e4SLinus Torvalds print " "; 12791da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 12801da177e4SLinus Torvalds print " </refpurpose>\n"; 12811da177e4SLinus Torvalds print "</refnamediv>\n"; 12821da177e4SLinus Torvalds 12831da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 12841da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 12851da177e4SLinus Torvalds print " <programlisting>\n"; 12861da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 12871da177e4SLinus Torvalds $count = 0; 12881da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12891da177e4SLinus Torvalds print " $parameter"; 12901da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 12911da177e4SLinus Torvalds $count++; 12921da177e4SLinus Torvalds print ","; 12931da177e4SLinus Torvalds } 12941da177e4SLinus Torvalds print "\n"; 12951da177e4SLinus Torvalds } 12961da177e4SLinus Torvalds print "};"; 12971da177e4SLinus Torvalds print " </programlisting>\n"; 12981da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 12991da177e4SLinus Torvalds 13001da177e4SLinus Torvalds print "<refsect1>\n"; 13011da177e4SLinus Torvalds print " <title>Constants</title>\n"; 13021da177e4SLinus Torvalds print " <variablelist>\n"; 13031da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13041da177e4SLinus Torvalds my $parameter_name = $parameter; 13051da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 13061da177e4SLinus Torvalds 13071da177e4SLinus Torvalds print " <varlistentry>"; 13081da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 13091da177e4SLinus Torvalds print " <listitem><para>\n"; 13101da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 13111da177e4SLinus Torvalds print " </para></listitem>\n"; 13121da177e4SLinus Torvalds print " </varlistentry>\n"; 13131da177e4SLinus Torvalds } 13141da177e4SLinus Torvalds print " </variablelist>\n"; 13151da177e4SLinus Torvalds print "</refsect1>\n"; 13161da177e4SLinus Torvalds 13171da177e4SLinus Torvalds output_section_xml(@_); 13181da177e4SLinus Torvalds 13191da177e4SLinus Torvalds print "</refentry>\n\n"; 13201da177e4SLinus Torvalds} 13211da177e4SLinus Torvalds 13221da177e4SLinus Torvalds# output typedef in XML DocBook 13231da177e4SLinus Torvaldssub output_typedef_xml(%) { 13241da177e4SLinus Torvalds my %args = %{$_[0]}; 13251da177e4SLinus Torvalds my ($parameter, $section); 13261da177e4SLinus Torvalds my $id; 13271da177e4SLinus Torvalds 13281da177e4SLinus Torvalds $id = "API-typedef-" . $args{'typedef'}; 13291da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13301da177e4SLinus Torvalds 13315449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 13328b0c2d98SMartin Waitz print "<refentryinfo>\n"; 13338b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 13348b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 13358b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 13368b0c2d98SMartin Waitz print "</refentryinfo>\n"; 13371da177e4SLinus Torvalds print "<refmeta>\n"; 13385449bc94SPavel Pisa print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; 13398b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 13401da177e4SLinus Torvalds print "</refmeta>\n"; 13411da177e4SLinus Torvalds print "<refnamediv>\n"; 13421da177e4SLinus Torvalds print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; 13431da177e4SLinus Torvalds print " <refpurpose>\n"; 13441da177e4SLinus Torvalds print " "; 13451da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 13461da177e4SLinus Torvalds print " </refpurpose>\n"; 13471da177e4SLinus Torvalds print "</refnamediv>\n"; 13481da177e4SLinus Torvalds 13491da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 13501da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 13511da177e4SLinus Torvalds print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; 13521da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 13531da177e4SLinus Torvalds 13541da177e4SLinus Torvalds output_section_xml(@_); 13551da177e4SLinus Torvalds 13561da177e4SLinus Torvalds print "</refentry>\n\n"; 13571da177e4SLinus Torvalds} 13581da177e4SLinus Torvalds 13591da177e4SLinus Torvalds# output in XML DocBook 1360b112e0f7SJohannes Bergsub output_blockhead_xml(%) { 13611da177e4SLinus Torvalds my %args = %{$_[0]}; 13621da177e4SLinus Torvalds my ($parameter, $section); 13631da177e4SLinus Torvalds my $count; 13641da177e4SLinus Torvalds 13651da177e4SLinus Torvalds my $id = $args{'module'}; 13661da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13671da177e4SLinus Torvalds 13681da177e4SLinus Torvalds # print out each section 13691da177e4SLinus Torvalds $lineprefix=" "; 13701da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1371b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1372b112e0f7SJohannes Berg print "<refsect1>\n <title>$section</title>\n"; 1373b112e0f7SJohannes Berg } 13741da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13751da177e4SLinus Torvalds print "<example><para>\n"; 1376e314ba31SDaniel Santos $output_preformatted = 1; 1377b112e0f7SJohannes Berg } else { 1378b112e0f7SJohannes Berg print "<para>\n"; 13791da177e4SLinus Torvalds } 13801da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1381e314ba31SDaniel Santos $output_preformatted = 0; 13821da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13831da177e4SLinus Torvalds print "</para></example>\n"; 1384b112e0f7SJohannes Berg } else { 1385b112e0f7SJohannes Berg print "</para>"; 13861da177e4SLinus Torvalds } 1387b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1388b112e0f7SJohannes Berg print "\n</refsect1>\n"; 1389b112e0f7SJohannes Berg } 13901da177e4SLinus Torvalds } 13911da177e4SLinus Torvalds 13921da177e4SLinus Torvalds print "\n\n"; 13931da177e4SLinus Torvalds} 13941da177e4SLinus Torvalds 13951da177e4SLinus Torvalds# output in XML DocBook 13961da177e4SLinus Torvaldssub output_function_gnome { 13971da177e4SLinus Torvalds my %args = %{$_[0]}; 13981da177e4SLinus Torvalds my ($parameter, $section); 13991da177e4SLinus Torvalds my $count; 14001da177e4SLinus Torvalds my $id; 14011da177e4SLinus Torvalds 14021da177e4SLinus Torvalds $id = $args{'module'} . "-" . $args{'function'}; 14031da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 14041da177e4SLinus Torvalds 14051da177e4SLinus Torvalds print "<sect2>\n"; 14061da177e4SLinus Torvalds print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; 14071da177e4SLinus Torvalds 14081da177e4SLinus Torvalds print " <funcsynopsis>\n"; 14091da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 14101da177e4SLinus Torvalds print "<function>" . $args{'function'} . " "; 14111da177e4SLinus Torvalds print "</function></funcdef>\n"; 14121da177e4SLinus Torvalds 14131da177e4SLinus Torvalds $count = 0; 14141da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 14151da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14161da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 14171da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 14181da177e4SLinus Torvalds # pointer-to-function 14191da177e4SLinus Torvalds print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; 14201da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 14211da177e4SLinus Torvalds } else { 14221da177e4SLinus Torvalds print " <paramdef>" . $type; 14231da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 14241da177e4SLinus Torvalds } 14251da177e4SLinus Torvalds } 14261da177e4SLinus Torvalds } else { 14271da177e4SLinus Torvalds print " <void>\n"; 14281da177e4SLinus Torvalds } 14291da177e4SLinus Torvalds print " </funcsynopsis>\n"; 14301da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 14311da177e4SLinus Torvalds print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; 14321da177e4SLinus Torvalds print "<tgroup cols=\"2\">\n"; 14331da177e4SLinus Torvalds print "<colspec colwidth=\"2*\">\n"; 14341da177e4SLinus Torvalds print "<colspec colwidth=\"8*\">\n"; 14351da177e4SLinus Torvalds print "<tbody>\n"; 14361da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14371da177e4SLinus Torvalds my $parameter_name = $parameter; 14381da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14391da177e4SLinus Torvalds 14401da177e4SLinus Torvalds print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; 14411da177e4SLinus Torvalds print " <entry>\n"; 14421da177e4SLinus Torvalds $lineprefix=" "; 14431da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14441da177e4SLinus Torvalds print " </entry></row>\n"; 14451da177e4SLinus Torvalds } 14461da177e4SLinus Torvalds print " </tbody></tgroup></informaltable>\n"; 14471da177e4SLinus Torvalds } else { 14481da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 14491da177e4SLinus Torvalds } 14501da177e4SLinus Torvalds 14511da177e4SLinus Torvalds # print out each section 14521da177e4SLinus Torvalds $lineprefix=" "; 14531da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14541da177e4SLinus Torvalds print "<simplesect>\n <title>$section</title>\n"; 14551da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 14561da177e4SLinus Torvalds print "<example><programlisting>\n"; 1457e314ba31SDaniel Santos $output_preformatted = 1; 14581da177e4SLinus Torvalds } else { 14591da177e4SLinus Torvalds } 14601da177e4SLinus Torvalds print "<para>\n"; 14611da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1462e314ba31SDaniel Santos $output_preformatted = 0; 14631da177e4SLinus Torvalds print "</para>\n"; 14641da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 14651da177e4SLinus Torvalds print "</programlisting></example>\n"; 14661da177e4SLinus Torvalds } else { 14671da177e4SLinus Torvalds } 14681da177e4SLinus Torvalds print " </simplesect>\n"; 14691da177e4SLinus Torvalds } 14701da177e4SLinus Torvalds 14711da177e4SLinus Torvalds print "</sect2>\n\n"; 14721da177e4SLinus Torvalds} 14731da177e4SLinus Torvalds 14741da177e4SLinus Torvalds## 14751da177e4SLinus Torvalds# output function in man 14761da177e4SLinus Torvaldssub output_function_man(%) { 14771da177e4SLinus Torvalds my %args = %{$_[0]}; 14781da177e4SLinus Torvalds my ($parameter, $section); 14791da177e4SLinus Torvalds my $count; 14801da177e4SLinus Torvalds 14811da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 14821da177e4SLinus Torvalds 14831da177e4SLinus Torvalds print ".SH NAME\n"; 14841da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 14851da177e4SLinus Torvalds 14861da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 1487a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 14881da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 1489a21217daSRandy Dunlap } else { 1490a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 1491a21217daSRandy Dunlap } 14921da177e4SLinus Torvalds $count = 0; 14931da177e4SLinus Torvalds my $parenth = "("; 14941da177e4SLinus Torvalds my $post = ","; 14951da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 14961da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 14971da177e4SLinus Torvalds $post = ");"; 14981da177e4SLinus Torvalds } 14991da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 15001da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 15011da177e4SLinus Torvalds # pointer-to-function 15021da177e4SLinus Torvalds print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 15031da177e4SLinus Torvalds } else { 15041da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 15051da177e4SLinus Torvalds print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 15061da177e4SLinus Torvalds } 15071da177e4SLinus Torvalds $count++; 15081da177e4SLinus Torvalds $parenth = ""; 15091da177e4SLinus Torvalds } 15101da177e4SLinus Torvalds 15111da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 15121da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15131da177e4SLinus Torvalds my $parameter_name = $parameter; 15141da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15151da177e4SLinus Torvalds 15161da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 15171da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 15181da177e4SLinus Torvalds } 15191da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15201da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 15211da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15221da177e4SLinus Torvalds } 15231da177e4SLinus Torvalds} 15241da177e4SLinus Torvalds 15251da177e4SLinus Torvalds## 15261da177e4SLinus Torvalds# output enum in man 15271da177e4SLinus Torvaldssub output_enum_man(%) { 15281da177e4SLinus Torvalds my %args = %{$_[0]}; 15291da177e4SLinus Torvalds my ($parameter, $section); 15301da177e4SLinus Torvalds my $count; 15311da177e4SLinus Torvalds 15321da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 15331da177e4SLinus Torvalds 15341da177e4SLinus Torvalds print ".SH NAME\n"; 15351da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 15361da177e4SLinus Torvalds 15371da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 15381da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 15391da177e4SLinus Torvalds $count = 0; 15401da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15411da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 15421da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 15431da177e4SLinus Torvalds print "\n};\n"; 15441da177e4SLinus Torvalds last; 15451da177e4SLinus Torvalds } 15461da177e4SLinus Torvalds else { 15471da177e4SLinus Torvalds print ", \n.br\n"; 15481da177e4SLinus Torvalds } 15491da177e4SLinus Torvalds $count++; 15501da177e4SLinus Torvalds } 15511da177e4SLinus Torvalds 15521da177e4SLinus Torvalds print ".SH Constants\n"; 15531da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15541da177e4SLinus Torvalds my $parameter_name = $parameter; 15551da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15561da177e4SLinus Torvalds 15571da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 15581da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 15591da177e4SLinus Torvalds } 15601da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15611da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15621da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15631da177e4SLinus Torvalds } 15641da177e4SLinus Torvalds} 15651da177e4SLinus Torvalds 15661da177e4SLinus Torvalds## 15671da177e4SLinus Torvalds# output struct in man 15681da177e4SLinus Torvaldssub output_struct_man(%) { 15691da177e4SLinus Torvalds my %args = %{$_[0]}; 15701da177e4SLinus Torvalds my ($parameter, $section); 15711da177e4SLinus Torvalds 15721da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 15731da177e4SLinus Torvalds 15741da177e4SLinus Torvalds print ".SH NAME\n"; 15751da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 15761da177e4SLinus Torvalds 15771da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 15781da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 15791da177e4SLinus Torvalds 15801da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15811da177e4SLinus Torvalds if ($parameter =~ /^#/) { 15821da177e4SLinus Torvalds print ".BI \"$parameter\"\n.br\n"; 15831da177e4SLinus Torvalds 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 $type = $args{'parametertypes'}{$parameter}; 15901da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 15911da177e4SLinus Torvalds # pointer-to-function 15921da177e4SLinus Torvalds print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; 15931da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 15941d7e1d45SRandy.Dunlap # bitfield 15951d7e1d45SRandy.Dunlap print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; 15961da177e4SLinus Torvalds } else { 15971da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 15981da177e4SLinus Torvalds print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; 15991da177e4SLinus Torvalds } 16001da177e4SLinus Torvalds print "\n.br\n"; 16011da177e4SLinus Torvalds } 16021da177e4SLinus Torvalds print "};\n.br\n"; 16031da177e4SLinus Torvalds 1604c51d3dacSRandy Dunlap print ".SH Members\n"; 16051da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16061da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 16071da177e4SLinus Torvalds 16081da177e4SLinus Torvalds my $parameter_name = $parameter; 16091da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16101da177e4SLinus Torvalds 16111da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 16121da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 16131da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 16141da177e4SLinus Torvalds } 16151da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16161da177e4SLinus Torvalds print ".SH \"$section\"\n"; 16171da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16181da177e4SLinus Torvalds } 16191da177e4SLinus Torvalds} 16201da177e4SLinus Torvalds 16211da177e4SLinus Torvalds## 16221da177e4SLinus Torvalds# output typedef in man 16231da177e4SLinus Torvaldssub output_typedef_man(%) { 16241da177e4SLinus Torvalds my %args = %{$_[0]}; 16251da177e4SLinus Torvalds my ($parameter, $section); 16261da177e4SLinus Torvalds 16271da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 16281da177e4SLinus Torvalds 16291da177e4SLinus Torvalds print ".SH NAME\n"; 16301da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 16311da177e4SLinus Torvalds 16321da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16331da177e4SLinus Torvalds print ".SH \"$section\"\n"; 16341da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16351da177e4SLinus Torvalds } 16361da177e4SLinus Torvalds} 16371da177e4SLinus Torvalds 1638b112e0f7SJohannes Bergsub output_blockhead_man(%) { 16391da177e4SLinus Torvalds my %args = %{$_[0]}; 16401da177e4SLinus Torvalds my ($parameter, $section); 16411da177e4SLinus Torvalds my $count; 16421da177e4SLinus Torvalds 16431da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 16441da177e4SLinus Torvalds 16451da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16461da177e4SLinus Torvalds print ".SH \"$section\"\n"; 16471da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16481da177e4SLinus Torvalds } 16491da177e4SLinus Torvalds} 16501da177e4SLinus Torvalds 16511da177e4SLinus Torvalds## 16521da177e4SLinus Torvalds# output in text 16531da177e4SLinus Torvaldssub output_function_text(%) { 16541da177e4SLinus Torvalds my %args = %{$_[0]}; 16551da177e4SLinus Torvalds my ($parameter, $section); 1656a21217daSRandy Dunlap my $start; 16571da177e4SLinus Torvalds 1658f47634b2SRandy Dunlap print "Name:\n\n"; 1659f47634b2SRandy Dunlap print $args{'function'} . " - " . $args{'purpose'} . "\n"; 1660f47634b2SRandy Dunlap 1661f47634b2SRandy Dunlap print "\nSynopsis:\n\n"; 1662a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 1663a21217daSRandy Dunlap $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1664a21217daSRandy Dunlap } else { 1665a21217daSRandy Dunlap $start = $args{'function'} . " ("; 1666a21217daSRandy Dunlap } 16671da177e4SLinus Torvalds print $start; 1668a21217daSRandy Dunlap 16691da177e4SLinus Torvalds my $count = 0; 16701da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 16711da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 16721da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 16731da177e4SLinus Torvalds # pointer-to-function 16741da177e4SLinus Torvalds print $1 . $parameter . ") (" . $2; 16751da177e4SLinus Torvalds } else { 16761da177e4SLinus Torvalds print $type . " " . $parameter; 16771da177e4SLinus Torvalds } 16781da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 16791da177e4SLinus Torvalds $count++; 16801da177e4SLinus Torvalds print ",\n"; 16811da177e4SLinus Torvalds print " " x length($start); 16821da177e4SLinus Torvalds } else { 16831da177e4SLinus Torvalds print ");\n\n"; 16841da177e4SLinus Torvalds } 16851da177e4SLinus Torvalds } 16861da177e4SLinus Torvalds 16871da177e4SLinus Torvalds print "Arguments:\n\n"; 16881da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16891da177e4SLinus Torvalds my $parameter_name = $parameter; 16901da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16911da177e4SLinus Torvalds 16921da177e4SLinus Torvalds print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; 16931da177e4SLinus Torvalds } 16941da177e4SLinus Torvalds output_section_text(@_); 16951da177e4SLinus Torvalds} 16961da177e4SLinus Torvalds 16971da177e4SLinus Torvalds#output sections in text 16981da177e4SLinus Torvaldssub output_section_text(%) { 16991da177e4SLinus Torvalds my %args = %{$_[0]}; 17001da177e4SLinus Torvalds my $section; 17011da177e4SLinus Torvalds 17021da177e4SLinus Torvalds print "\n"; 17031da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 17041da177e4SLinus Torvalds print "$section:\n\n"; 17051da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 17061da177e4SLinus Torvalds } 17071da177e4SLinus Torvalds print "\n\n"; 17081da177e4SLinus Torvalds} 17091da177e4SLinus Torvalds 17101da177e4SLinus Torvalds# output enum in text 17111da177e4SLinus Torvaldssub output_enum_text(%) { 17121da177e4SLinus Torvalds my %args = %{$_[0]}; 17131da177e4SLinus Torvalds my ($parameter); 17141da177e4SLinus Torvalds my $count; 17151da177e4SLinus Torvalds print "Enum:\n\n"; 17161da177e4SLinus Torvalds 17171d7e1d45SRandy.Dunlap print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; 17181da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 17191da177e4SLinus Torvalds $count = 0; 17201da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17211da177e4SLinus Torvalds print "\t$parameter"; 17221da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 17231da177e4SLinus Torvalds $count++; 17241da177e4SLinus Torvalds print ","; 17251da177e4SLinus Torvalds } 17261da177e4SLinus Torvalds print "\n"; 17271da177e4SLinus Torvalds } 17281da177e4SLinus Torvalds print "};\n\n"; 17291da177e4SLinus Torvalds 17301da177e4SLinus Torvalds print "Constants:\n\n"; 17311da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17321da177e4SLinus Torvalds print "$parameter\n\t"; 17331da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter} . "\n"; 17341da177e4SLinus Torvalds } 17351da177e4SLinus Torvalds 17361da177e4SLinus Torvalds output_section_text(@_); 17371da177e4SLinus Torvalds} 17381da177e4SLinus Torvalds 17391da177e4SLinus Torvalds# output typedef in text 17401da177e4SLinus Torvaldssub output_typedef_text(%) { 17411da177e4SLinus Torvalds my %args = %{$_[0]}; 17421da177e4SLinus Torvalds my ($parameter); 17431da177e4SLinus Torvalds my $count; 17441da177e4SLinus Torvalds print "Typedef:\n\n"; 17451da177e4SLinus Torvalds 17461d7e1d45SRandy.Dunlap print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; 17471da177e4SLinus Torvalds output_section_text(@_); 17481da177e4SLinus Torvalds} 17491da177e4SLinus Torvalds 17501da177e4SLinus Torvalds# output struct as text 17511da177e4SLinus Torvaldssub output_struct_text(%) { 17521da177e4SLinus Torvalds my %args = %{$_[0]}; 17531da177e4SLinus Torvalds my ($parameter); 17541da177e4SLinus Torvalds 17551d7e1d45SRandy.Dunlap print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; 17561da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 17571da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17581da177e4SLinus Torvalds if ($parameter =~ /^#/) { 17591da177e4SLinus Torvalds print "$parameter\n"; 17601da177e4SLinus Torvalds next; 17611da177e4SLinus Torvalds } 17621da177e4SLinus Torvalds 17631da177e4SLinus Torvalds my $parameter_name = $parameter; 17641da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 17651da177e4SLinus Torvalds 17661da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 17671da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 17681da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 17691da177e4SLinus Torvalds # pointer-to-function 17701da177e4SLinus Torvalds print "\t$1 $parameter) ($2);\n"; 17711da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 177251f5a0c8SRandy Dunlap # bitfield 17731da177e4SLinus Torvalds print "\t$1 $parameter$2;\n"; 17741da177e4SLinus Torvalds } else { 17751da177e4SLinus Torvalds print "\t" . $type . " " . $parameter . ";\n"; 17761da177e4SLinus Torvalds } 17771da177e4SLinus Torvalds } 17781da177e4SLinus Torvalds print "};\n\n"; 17791da177e4SLinus Torvalds 17801da177e4SLinus Torvalds print "Members:\n\n"; 17811da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17821da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 17831da177e4SLinus Torvalds 17841da177e4SLinus Torvalds my $parameter_name = $parameter; 17851da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 17861da177e4SLinus Torvalds 17871da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 17881da177e4SLinus Torvalds print "$parameter\n\t"; 17891da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter_name} . "\n"; 17901da177e4SLinus Torvalds } 17911da177e4SLinus Torvalds print "\n"; 17921da177e4SLinus Torvalds output_section_text(@_); 17931da177e4SLinus Torvalds} 17941da177e4SLinus Torvalds 1795b112e0f7SJohannes Bergsub output_blockhead_text(%) { 17961da177e4SLinus Torvalds my %args = %{$_[0]}; 17971da177e4SLinus Torvalds my ($parameter, $section); 17981da177e4SLinus Torvalds 17991da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 18001da177e4SLinus Torvalds print " $section:\n"; 18011da177e4SLinus Torvalds print " -> "; 18021da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 18031da177e4SLinus Torvalds } 18041da177e4SLinus Torvalds} 18051da177e4SLinus Torvalds 1806c0d1b6eeSJonathan Corbet## 1807c0d1b6eeSJonathan Corbet# output in restructured text 1808c0d1b6eeSJonathan Corbet# 1809c0d1b6eeSJonathan Corbet 1810c0d1b6eeSJonathan Corbet# 1811c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 1812c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 1813c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 1814c0d1b6eeSJonathan Corbet# 1815c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 1816c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1817c0d1b6eeSJonathan Corbet my ($parameter, $section); 1818c0d1b6eeSJonathan Corbet 1819c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 18209e72184bSJani Nikula if ($output_selection != OUTPUT_INCLUDE) { 1821c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 18229e72184bSJani Nikula } 18230b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 1824c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1825c0d1b6eeSJonathan Corbet print "\n"; 1826c0d1b6eeSJonathan Corbet } 1827c0d1b6eeSJonathan Corbet} 1828c0d1b6eeSJonathan Corbet 1829c0d1b6eeSJonathan Corbetsub output_highlight_rst { 1830c0d1b6eeSJonathan Corbet my $contents = join "\n",@_; 1831c0d1b6eeSJonathan Corbet my $line; 1832c0d1b6eeSJonathan Corbet 1833c0d1b6eeSJonathan Corbet # undo the evil effects of xml_escape() earlier 1834c0d1b6eeSJonathan Corbet $contents = xml_unescape($contents); 1835c0d1b6eeSJonathan Corbet 1836c0d1b6eeSJonathan Corbet eval $dohighlight; 1837c0d1b6eeSJonathan Corbet die $@ if $@; 1838c0d1b6eeSJonathan Corbet 1839c0d1b6eeSJonathan Corbet foreach $line (split "\n", $contents) { 1840830066a7SJani Nikula print $lineprefix . $line . "\n"; 1841c0d1b6eeSJonathan Corbet } 1842c0d1b6eeSJonathan Corbet} 1843c0d1b6eeSJonathan Corbet 1844c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 1845c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1846c0d1b6eeSJonathan Corbet my ($parameter, $section); 1847c099ff69SJani Nikula my $oldprefix = $lineprefix; 184882801d06SMauro Carvalho Chehab my $start = ""; 1849c0d1b6eeSJonathan Corbet 185082801d06SMauro Carvalho Chehab if ($args{'typedef'}) { 185182801d06SMauro Carvalho Chehab print ".. c:type:: ". $args{'function'} . "\n\n"; 185282801d06SMauro Carvalho Chehab print_lineno($declaration_start_line); 185382801d06SMauro Carvalho Chehab print " **Typedef**: "; 185482801d06SMauro Carvalho Chehab $lineprefix = ""; 185582801d06SMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 185682801d06SMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 1857c0d1b6eeSJonathan Corbet } else { 185882801d06SMauro Carvalho Chehab print ".. c:function:: "; 185982801d06SMauro Carvalho Chehab } 186082801d06SMauro Carvalho Chehab if ($args{'functiontype'} ne "") { 186182801d06SMauro Carvalho Chehab $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; 186282801d06SMauro Carvalho Chehab } else { 186382801d06SMauro Carvalho Chehab $start .= $args{'function'} . " ("; 1864c0d1b6eeSJonathan Corbet } 1865c0d1b6eeSJonathan Corbet print $start; 1866c0d1b6eeSJonathan Corbet 1867c0d1b6eeSJonathan Corbet my $count = 0; 1868c0d1b6eeSJonathan Corbet foreach my $parameter (@{$args{'parameterlist'}}) { 1869c0d1b6eeSJonathan Corbet if ($count ne 0) { 1870c0d1b6eeSJonathan Corbet print ", "; 1871c0d1b6eeSJonathan Corbet } 1872c0d1b6eeSJonathan Corbet $count++; 1873c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1874a88b1672SMauro Carvalho Chehab 1875c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1876c0d1b6eeSJonathan Corbet # pointer-to-function 1877c0d1b6eeSJonathan Corbet print $1 . $parameter . ") (" . $2; 1878c0d1b6eeSJonathan Corbet } else { 1879c0d1b6eeSJonathan Corbet print $type . " " . $parameter; 1880c0d1b6eeSJonathan Corbet } 1881c0d1b6eeSJonathan Corbet } 188282801d06SMauro Carvalho Chehab if ($args{'typedef'}) { 188382801d06SMauro Carvalho Chehab print ");``\n\n"; 188482801d06SMauro Carvalho Chehab } else { 1885c099ff69SJani Nikula print ")\n\n"; 18860b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1887c099ff69SJani Nikula $lineprefix = " "; 1888c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1889c099ff69SJani Nikula print "\n"; 189082801d06SMauro Carvalho Chehab } 1891c0d1b6eeSJonathan Corbet 1892ecbcfba1SJani Nikula print "**Parameters**\n\n"; 1893c099ff69SJani Nikula $lineprefix = " "; 1894c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1895c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1896c0d1b6eeSJonathan Corbet #$parameter_name =~ s/\[.*//; 1897c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1898c0d1b6eeSJonathan Corbet 1899c0d1b6eeSJonathan Corbet if ($type ne "") { 1900c0d1b6eeSJonathan Corbet print "``$type $parameter``\n"; 1901c0d1b6eeSJonathan Corbet } else { 1902c0d1b6eeSJonathan Corbet print "``$parameter``\n"; 1903c0d1b6eeSJonathan Corbet } 19040b0f5f29SDaniel Vetter 19050b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 19060b0f5f29SDaniel Vetter 19075e64fa9cSJani Nikula if (defined($args{'parameterdescs'}{$parameter_name}) && 19085e64fa9cSJani Nikula $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 1909c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1910c0d1b6eeSJonathan Corbet } else { 1911d4b08e0cSJani Nikula print " *undescribed*\n"; 1912c0d1b6eeSJonathan Corbet } 1913c0d1b6eeSJonathan Corbet print "\n"; 1914c0d1b6eeSJonathan Corbet } 1915c099ff69SJani Nikula 1916c099ff69SJani Nikula $lineprefix = $oldprefix; 1917c0d1b6eeSJonathan Corbet output_section_rst(@_); 1918c0d1b6eeSJonathan Corbet} 1919c0d1b6eeSJonathan Corbet 1920c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 1921c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1922c0d1b6eeSJonathan Corbet my $section; 1923c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1924c0d1b6eeSJonathan Corbet $lineprefix = ""; 1925c0d1b6eeSJonathan Corbet 1926c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 1927ecbcfba1SJani Nikula print "**$section**\n\n"; 19280b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 1929c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1930c0d1b6eeSJonathan Corbet print "\n"; 1931c0d1b6eeSJonathan Corbet } 1932c0d1b6eeSJonathan Corbet print "\n"; 1933c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1934c0d1b6eeSJonathan Corbet} 1935c0d1b6eeSJonathan Corbet 1936c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 1937c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1938c0d1b6eeSJonathan Corbet my ($parameter); 1939c099ff69SJani Nikula my $oldprefix = $lineprefix; 1940c0d1b6eeSJonathan Corbet my $count; 1941c0d1b6eeSJonathan Corbet my $name = "enum " . $args{'enum'}; 194262850976SJani Nikula 194362850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 19440b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1945c099ff69SJani Nikula $lineprefix = " "; 1946c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1947c099ff69SJani Nikula print "\n"; 1948c0d1b6eeSJonathan Corbet 1949ecbcfba1SJani Nikula print "**Constants**\n\n"; 1950c0d1b6eeSJonathan Corbet $lineprefix = " "; 1951c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1952ecbcfba1SJani Nikula print "``$parameter``\n"; 1953c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 1954c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 1955c0d1b6eeSJonathan Corbet } else { 1956d4b08e0cSJani Nikula print " *undescribed*\n"; 1957c0d1b6eeSJonathan Corbet } 1958c0d1b6eeSJonathan Corbet print "\n"; 1959c0d1b6eeSJonathan Corbet } 1960c099ff69SJani Nikula 1961c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1962c0d1b6eeSJonathan Corbet output_section_rst(@_); 1963c0d1b6eeSJonathan Corbet} 1964c0d1b6eeSJonathan Corbet 1965c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 1966c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1967c0d1b6eeSJonathan Corbet my ($parameter); 1968c099ff69SJani Nikula my $oldprefix = $lineprefix; 1969c0d1b6eeSJonathan Corbet my $name = "typedef " . $args{'typedef'}; 1970c0d1b6eeSJonathan Corbet 197162850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 19720b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1973c099ff69SJani Nikula $lineprefix = " "; 1974c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1975c099ff69SJani Nikula print "\n"; 1976c0d1b6eeSJonathan Corbet 1977c099ff69SJani Nikula $lineprefix = $oldprefix; 1978c0d1b6eeSJonathan Corbet output_section_rst(@_); 1979c0d1b6eeSJonathan Corbet} 1980c0d1b6eeSJonathan Corbet 1981c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 1982c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1983c0d1b6eeSJonathan Corbet my ($parameter); 1984c099ff69SJani Nikula my $oldprefix = $lineprefix; 1985c0d1b6eeSJonathan Corbet my $name = $args{'type'} . " " . $args{'struct'}; 1986c0d1b6eeSJonathan Corbet 198762850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 19880b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1989c099ff69SJani Nikula $lineprefix = " "; 1990c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1991c099ff69SJani Nikula print "\n"; 1992c0d1b6eeSJonathan Corbet 1993ecbcfba1SJani Nikula print "**Definition**\n\n"; 1994c0d1b6eeSJonathan Corbet print "::\n\n"; 1995c0d1b6eeSJonathan Corbet print " " . $args{'type'} . " " . $args{'struct'} . " {\n"; 1996c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1997c0d1b6eeSJonathan Corbet if ($parameter =~ /^#/) { 1998c0d1b6eeSJonathan Corbet print " " . "$parameter\n"; 1999c0d1b6eeSJonathan Corbet next; 2000c0d1b6eeSJonathan Corbet } 2001c0d1b6eeSJonathan Corbet 2002c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 2003c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 2004c0d1b6eeSJonathan Corbet 2005c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 2006c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 2007c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 2008c0d1b6eeSJonathan Corbet # pointer-to-function 2009c0d1b6eeSJonathan Corbet print " $1 $parameter) ($2);\n"; 2010c0d1b6eeSJonathan Corbet } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 2011c0d1b6eeSJonathan Corbet # bitfield 2012c0d1b6eeSJonathan Corbet print " $1 $parameter$2;\n"; 2013c0d1b6eeSJonathan Corbet } else { 2014c0d1b6eeSJonathan Corbet print " " . $type . " " . $parameter . ";\n"; 2015c0d1b6eeSJonathan Corbet } 2016c0d1b6eeSJonathan Corbet } 2017c0d1b6eeSJonathan Corbet print " };\n\n"; 2018c0d1b6eeSJonathan Corbet 2019ecbcfba1SJani Nikula print "**Members**\n\n"; 2020c099ff69SJani Nikula $lineprefix = " "; 2021c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 2022c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 2023c0d1b6eeSJonathan Corbet 2024c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 2025c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 2026c0d1b6eeSJonathan Corbet 2027c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 2028c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 20290b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 20306d232c80SMauro Carvalho Chehab print "``" . $parameter . "``\n"; 2031c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 2032c0d1b6eeSJonathan Corbet print "\n"; 2033c0d1b6eeSJonathan Corbet } 2034c0d1b6eeSJonathan Corbet print "\n"; 2035c099ff69SJani Nikula 2036c099ff69SJani Nikula $lineprefix = $oldprefix; 2037c0d1b6eeSJonathan Corbet output_section_rst(@_); 2038c0d1b6eeSJonathan Corbet} 2039c0d1b6eeSJonathan Corbet 2040c0d1b6eeSJonathan Corbet 2041eda603f6SJohannes Berg## list mode output functions 2042eda603f6SJohannes Berg 2043eda603f6SJohannes Bergsub output_function_list(%) { 2044eda603f6SJohannes Berg my %args = %{$_[0]}; 2045eda603f6SJohannes Berg 2046eda603f6SJohannes Berg print $args{'function'} . "\n"; 2047eda603f6SJohannes Berg} 2048eda603f6SJohannes Berg 2049eda603f6SJohannes Berg# output enum in list 2050eda603f6SJohannes Bergsub output_enum_list(%) { 2051eda603f6SJohannes Berg my %args = %{$_[0]}; 2052eda603f6SJohannes Berg print $args{'enum'} . "\n"; 2053eda603f6SJohannes Berg} 2054eda603f6SJohannes Berg 2055eda603f6SJohannes Berg# output typedef in list 2056eda603f6SJohannes Bergsub output_typedef_list(%) { 2057eda603f6SJohannes Berg my %args = %{$_[0]}; 2058eda603f6SJohannes Berg print $args{'typedef'} . "\n"; 2059eda603f6SJohannes Berg} 2060eda603f6SJohannes Berg 2061eda603f6SJohannes Berg# output struct as list 2062eda603f6SJohannes Bergsub output_struct_list(%) { 2063eda603f6SJohannes Berg my %args = %{$_[0]}; 2064eda603f6SJohannes Berg 2065eda603f6SJohannes Berg print $args{'struct'} . "\n"; 2066eda603f6SJohannes Berg} 2067eda603f6SJohannes Berg 2068eda603f6SJohannes Bergsub output_blockhead_list(%) { 2069eda603f6SJohannes Berg my %args = %{$_[0]}; 2070eda603f6SJohannes Berg my ($parameter, $section); 2071eda603f6SJohannes Berg 2072eda603f6SJohannes Berg foreach $section (@{$args{'sectionlist'}}) { 2073eda603f6SJohannes Berg print "DOC: $section\n"; 2074eda603f6SJohannes Berg } 2075eda603f6SJohannes Berg} 2076eda603f6SJohannes Berg 20771da177e4SLinus Torvalds## 207827205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 207927205744SRandy Dunlap# calls the generated, variable output_ function name based on 208027205744SRandy Dunlap# functype and output_mode 20811da177e4SLinus Torvaldssub output_declaration { 20821da177e4SLinus Torvalds no strict 'refs'; 20831da177e4SLinus Torvalds my $name = shift; 20841da177e4SLinus Torvalds my $functype = shift; 20851da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 2086b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 2087b6c3f456SJani Nikula (($output_selection == OUTPUT_INCLUDE || 2088b6c3f456SJani Nikula $output_selection == OUTPUT_EXPORTED) && 208986ae2e38SJani Nikula defined($function_table{$name})) || 2090b6c3f456SJani Nikula (($output_selection == OUTPUT_EXCLUDE || 2091b6c3f456SJani Nikula $output_selection == OUTPUT_INTERNAL) && 209286ae2e38SJani Nikula !($functype eq "function" && defined($function_table{$name})))) 20931da177e4SLinus Torvalds { 20941da177e4SLinus Torvalds &$func(@_); 20951da177e4SLinus Torvalds $section_counter++; 20961da177e4SLinus Torvalds } 20971da177e4SLinus Torvalds} 20981da177e4SLinus Torvalds 20991da177e4SLinus Torvalds## 210027205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 2101b112e0f7SJohannes Bergsub output_blockhead { 21021da177e4SLinus Torvalds no strict 'refs'; 2103b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 21041da177e4SLinus Torvalds &$func(@_); 21051da177e4SLinus Torvalds $section_counter++; 21061da177e4SLinus Torvalds} 21071da177e4SLinus Torvalds 21081da177e4SLinus Torvalds## 21091da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 21101da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 21111da177e4SLinus Torvaldssub dump_declaration($$) { 21121da177e4SLinus Torvalds no strict 'refs'; 21131da177e4SLinus Torvalds my ($prototype, $file) = @_; 21141da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 21151da177e4SLinus Torvalds &$func(@_); 21161da177e4SLinus Torvalds} 21171da177e4SLinus Torvalds 21181da177e4SLinus Torvaldssub dump_union($$) { 21191da177e4SLinus Torvalds dump_struct(@_); 21201da177e4SLinus Torvalds} 21211da177e4SLinus Torvalds 21221da177e4SLinus Torvaldssub dump_struct($$) { 21231da177e4SLinus Torvalds my $x = shift; 21241da177e4SLinus Torvalds my $file = shift; 2125a1d94aa5SRandy Dunlap my $nested; 21261da177e4SLinus Torvalds 21271da177e4SLinus Torvalds if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 212852dc5aecSRandy Dunlap #my $decl_type = $1; 21291da177e4SLinus Torvalds $declaration_name = $2; 21301da177e4SLinus Torvalds my $members = $3; 21311da177e4SLinus Torvalds 21321da177e4SLinus Torvalds # ignore embedded structs or unions 2133a1d94aa5SRandy Dunlap $members =~ s/({.*})//g; 2134a1d94aa5SRandy Dunlap $nested = $1; 21351da177e4SLinus Torvalds 2136aeec46b9SMartin Waitz # ignore members marked private: 21370d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 21380d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 2139aeec46b9SMartin Waitz # strip comments: 2140aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 2141a1d94aa5SRandy Dunlap $nested =~ s/\/\*.*?\*\///gos; 2142d960eea9SRandy Dunlap # strip kmemcheck_bitfield_{begin,end}.*; 2143d960eea9SRandy Dunlap $members =~ s/kmemcheck_bitfield_.*?;//gos; 2144ef5da59fSRandy Dunlap # strip attributes 2145f0074929SJonathan Corbet $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 21467b990789SJohannes Berg $members =~ s/__aligned\s*\([^;]*\)//gos; 2147f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; 2148b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 2149b22b5a9eSConchúr Navid $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 2150aeec46b9SMartin Waitz 21511da177e4SLinus Torvalds create_parameterlist($members, ';', $file); 2152a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); 21531da177e4SLinus Torvalds 21541da177e4SLinus Torvalds output_declaration($declaration_name, 21551da177e4SLinus Torvalds 'struct', 21561da177e4SLinus Torvalds {'struct' => $declaration_name, 21571da177e4SLinus Torvalds 'module' => $modulename, 21581da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 21591da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 21601da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 21611da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 21621da177e4SLinus Torvalds 'sections' => \%sections, 21631da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 21641da177e4SLinus Torvalds 'type' => $decl_type 21651da177e4SLinus Torvalds }); 21661da177e4SLinus Torvalds } 21671da177e4SLinus Torvalds else { 2168d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 21691da177e4SLinus Torvalds ++$errors; 21701da177e4SLinus Torvalds } 21711da177e4SLinus Torvalds} 21721da177e4SLinus Torvalds 21731da177e4SLinus Torvaldssub dump_enum($$) { 21741da177e4SLinus Torvalds my $x = shift; 21751da177e4SLinus Torvalds my $file = shift; 21761da177e4SLinus Torvalds 2177aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 21784468e21eSConchúr Navid # strip #define macros inside enums 21794468e21eSConchúr Navid $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 2180b6d676dbSRandy Dunlap 21811da177e4SLinus Torvalds if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 21821da177e4SLinus Torvalds $declaration_name = $1; 21831da177e4SLinus Torvalds my $members = $2; 21841da177e4SLinus Torvalds 21851da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 21861da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 21871da177e4SLinus Torvalds push @parameterlist, $arg; 21881da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 21891da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 2190d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Enum value '$arg' ". 21911da177e4SLinus Torvalds "not described in enum '$declaration_name'\n"; 21921da177e4SLinus Torvalds } 21931da177e4SLinus Torvalds 21941da177e4SLinus Torvalds } 21951da177e4SLinus Torvalds 21961da177e4SLinus Torvalds output_declaration($declaration_name, 21971da177e4SLinus Torvalds 'enum', 21981da177e4SLinus Torvalds {'enum' => $declaration_name, 21991da177e4SLinus Torvalds 'module' => $modulename, 22001da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 22011da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 22021da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 22031da177e4SLinus Torvalds 'sections' => \%sections, 22041da177e4SLinus Torvalds 'purpose' => $declaration_purpose 22051da177e4SLinus Torvalds }); 22061da177e4SLinus Torvalds } 22071da177e4SLinus Torvalds else { 2208d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 22091da177e4SLinus Torvalds ++$errors; 22101da177e4SLinus Torvalds } 22111da177e4SLinus Torvalds} 22121da177e4SLinus Torvalds 22131da177e4SLinus Torvaldssub dump_typedef($$) { 22141da177e4SLinus Torvalds my $x = shift; 22151da177e4SLinus Torvalds my $file = shift; 22161da177e4SLinus Torvalds 2217aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 221883766452SMauro Carvalho Chehab 221983766452SMauro Carvalho Chehab # Parse function prototypes 2220d37c43ceSMauro Carvalho Chehab if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ || 2221d37c43ceSMauro Carvalho Chehab $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) { 2222d37c43ceSMauro Carvalho Chehab 222383766452SMauro Carvalho Chehab # Function typedefs 222483766452SMauro Carvalho Chehab $return_type = $1; 222583766452SMauro Carvalho Chehab $declaration_name = $2; 222683766452SMauro Carvalho Chehab my $args = $3; 222783766452SMauro Carvalho Chehab 222883766452SMauro Carvalho Chehab create_parameterlist($args, ',', $file); 222983766452SMauro Carvalho Chehab 223083766452SMauro Carvalho Chehab output_declaration($declaration_name, 223183766452SMauro Carvalho Chehab 'function', 223283766452SMauro Carvalho Chehab {'function' => $declaration_name, 223382801d06SMauro Carvalho Chehab 'typedef' => 1, 223483766452SMauro Carvalho Chehab 'module' => $modulename, 223583766452SMauro Carvalho Chehab 'functiontype' => $return_type, 223683766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 223783766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 223883766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 223983766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 224083766452SMauro Carvalho Chehab 'sections' => \%sections, 224183766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 224283766452SMauro Carvalho Chehab }); 224383766452SMauro Carvalho Chehab return; 224483766452SMauro Carvalho Chehab } 224583766452SMauro Carvalho Chehab 22461da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 22471da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 22481da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 22491da177e4SLinus Torvalds } 22501da177e4SLinus Torvalds 22511da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 22521da177e4SLinus Torvalds $declaration_name = $1; 22531da177e4SLinus Torvalds 22541da177e4SLinus Torvalds output_declaration($declaration_name, 22551da177e4SLinus Torvalds 'typedef', 22561da177e4SLinus Torvalds {'typedef' => $declaration_name, 22571da177e4SLinus Torvalds 'module' => $modulename, 22581da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 22591da177e4SLinus Torvalds 'sections' => \%sections, 22601da177e4SLinus Torvalds 'purpose' => $declaration_purpose 22611da177e4SLinus Torvalds }); 22621da177e4SLinus Torvalds } 22631da177e4SLinus Torvalds else { 2264d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 22651da177e4SLinus Torvalds ++$errors; 22661da177e4SLinus Torvalds } 22671da177e4SLinus Torvalds} 22681da177e4SLinus Torvalds 2269a1d94aa5SRandy Dunlapsub save_struct_actual($) { 2270a1d94aa5SRandy Dunlap my $actual = shift; 2271a1d94aa5SRandy Dunlap 2272a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 2273a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 2274a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 2275a1d94aa5SRandy Dunlap} 2276a1d94aa5SRandy Dunlap 22771da177e4SLinus Torvaldssub create_parameterlist($$$) { 22781da177e4SLinus Torvalds my $args = shift; 22791da177e4SLinus Torvalds my $splitter = shift; 22801da177e4SLinus Torvalds my $file = shift; 22811da177e4SLinus Torvalds my $type; 22821da177e4SLinus Torvalds my $param; 22831da177e4SLinus Torvalds 2284a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 22851da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 22861da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 22871da177e4SLinus Torvalds } 22881da177e4SLinus Torvalds 22891da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 22901da177e4SLinus Torvalds # strip comments 22911da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 22921da177e4SLinus Torvalds # strip leading/trailing spaces 22931da177e4SLinus Torvalds $arg =~ s/^\s*//; 22941da177e4SLinus Torvalds $arg =~ s/\s*$//; 22951da177e4SLinus Torvalds $arg =~ s/\s+/ /; 22961da177e4SLinus Torvalds 22971da177e4SLinus Torvalds if ($arg =~ /^#/) { 22981da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 22991da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 23001da177e4SLinus Torvalds # output_* subs. 23011da177e4SLinus Torvalds push_parameter($arg, "", $file); 230200d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 23031da177e4SLinus Torvalds # pointer-to-function 23041da177e4SLinus Torvalds $arg =~ tr/#/,/; 230500d62961SRichard Kennedy $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 23061da177e4SLinus Torvalds $param = $1; 23071da177e4SLinus Torvalds $type = $arg; 230800d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 2309a1d94aa5SRandy Dunlap save_struct_actual($param); 23101da177e4SLinus Torvalds push_parameter($param, $type, $file); 2311aeec46b9SMartin Waitz } elsif ($arg) { 23121da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 23131da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 23141da177e4SLinus Torvalds 23151da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 23161da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 23171da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 23181da177e4SLinus Torvalds } 2319884f2810SBorislav Petkov 2320884f2810SBorislav Petkov my @first_arg; 2321884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 2322884f2810SBorislav Petkov shift @args; 2323884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 2324884f2810SBorislav Petkov push(@first_arg, $2); 2325884f2810SBorislav Petkov } else { 2326884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 2327884f2810SBorislav Petkov } 2328884f2810SBorislav Petkov 23291da177e4SLinus Torvalds unshift(@args, pop @first_arg); 23301da177e4SLinus Torvalds $type = join " ", @first_arg; 23311da177e4SLinus Torvalds 23321da177e4SLinus Torvalds foreach $param (@args) { 23331da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 2334a1d94aa5SRandy Dunlap save_struct_actual($2); 23351da177e4SLinus Torvalds push_parameter($2, "$type $1", $file); 23361da177e4SLinus Torvalds } 23371da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 23387b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 2339a1d94aa5SRandy Dunlap save_struct_actual($1); 23401da177e4SLinus Torvalds push_parameter($1, "$type:$2", $file) 23411da177e4SLinus Torvalds } 23427b97887eSRandy Dunlap } 23431da177e4SLinus Torvalds else { 2344a1d94aa5SRandy Dunlap save_struct_actual($param); 23451da177e4SLinus Torvalds push_parameter($param, $type, $file); 23461da177e4SLinus Torvalds } 23471da177e4SLinus Torvalds } 23481da177e4SLinus Torvalds } 23491da177e4SLinus Torvalds } 23501da177e4SLinus Torvalds} 23511da177e4SLinus Torvalds 23521da177e4SLinus Torvaldssub push_parameter($$$) { 23531da177e4SLinus Torvalds my $param = shift; 23541da177e4SLinus Torvalds my $type = shift; 23551da177e4SLinus Torvalds my $file = shift; 23561da177e4SLinus Torvalds 23575f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 23585f8c7c98SRandy Dunlap ($param eq "}")) { 23595f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 23605f8c7c98SRandy Dunlap } 23615f8c7c98SRandy Dunlap 23625f8c7c98SRandy Dunlap $anon_struct_union = 0; 23631da177e4SLinus Torvalds my $param_name = $param; 23641da177e4SLinus Torvalds $param_name =~ s/\[.*//; 23651da177e4SLinus Torvalds 2366a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 23671da177e4SLinus Torvalds { 2368c950a173SSilvio Fricke if (!$param =~ /\w\.\.\.$/) { 2369c950a173SSilvio Fricke # handles unnamed variable parameters 2370ef00028bSJonathan Corbet $param = "..."; 2371c950a173SSilvio Fricke } 2372ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 2373a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 23741da177e4SLinus Torvalds } 2375ced69090SRandy Dunlap } 23761da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 23771da177e4SLinus Torvalds { 23781da177e4SLinus Torvalds $param="void"; 23791da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 23801da177e4SLinus Torvalds } 2381134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 2382134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 2383134fe01bSRandy Dunlap { 2384134fe01bSRandy Dunlap $type = $param; 2385134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 2386134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 23875f8c7c98SRandy Dunlap $anon_struct_union = 1; 2388134fe01bSRandy Dunlap } 2389134fe01bSRandy Dunlap 2390a6d3fe77SMartin Waitz # warn if parameter has no description 2391134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 2392134fe01bSRandy Dunlap # but inline preprocessor statements); 2393134fe01bSRandy Dunlap # also ignore unnamed structs/unions; 23945f8c7c98SRandy Dunlap if (!$anon_struct_union) { 2395a6d3fe77SMartin Waitz if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { 2396a6d3fe77SMartin Waitz 23971da177e4SLinus Torvalds $parameterdescs{$param_name} = $undescribed; 23981da177e4SLinus Torvalds 23991da177e4SLinus Torvalds if (($type eq 'function') || ($type eq 'enum')) { 2400d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Function parameter ". 24011da177e4SLinus Torvalds "or member '$param' not " . 24021da177e4SLinus Torvalds "described in '$declaration_name'\n"; 24031da177e4SLinus Torvalds } 2404d40e1e65SBart Van Assche print STDERR "${file}:$.: warning:" . 24051da177e4SLinus Torvalds " No description found for parameter '$param'\n"; 24061da177e4SLinus Torvalds ++$warnings; 24071da177e4SLinus Torvalds } 2408134fe01bSRandy Dunlap } 24091da177e4SLinus Torvalds 24102b35f4d9SRandy Dunlap $param = xml_escape($param); 24112b35f4d9SRandy Dunlap 241225985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 2413e34e7dbbSRandy Dunlap # on @parameterlist; 2414e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 2415e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 2416e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 2417e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 2418e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 2419e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 2420e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 24211da177e4SLinus Torvalds push @parameterlist, $param; 242202a4f4feSPaolo Bonzini $type =~ s/\s\s+/ /g; 24231da177e4SLinus Torvalds $parametertypes{$param} = $type; 24241da177e4SLinus Torvalds} 24251da177e4SLinus Torvalds 2426a1d94aa5SRandy Dunlapsub check_sections($$$$$$) { 2427a1d94aa5SRandy Dunlap my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; 2428a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 2429a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 2430a1d94aa5SRandy Dunlap my $err; 2431a1d94aa5SRandy Dunlap my ($px, $sx); 2432a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 2433a1d94aa5SRandy Dunlap 2434a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 2435a1d94aa5SRandy Dunlap $err = 1; 2436a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 2437a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 2438a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 24391f3a6688SJohannes Berg $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 2440e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 2441e34e7dbbSRandy Dunlap # however, the original param string may contain 2442e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 2443e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 2444e34e7dbbSRandy Dunlap # parameter list is split at spaces; 2445e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 2446e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 2447e34e7dbbSRandy Dunlap 2448a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 2449a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 2450a1d94aa5SRandy Dunlap $err = 0; 2451a1d94aa5SRandy Dunlap last; 2452a1d94aa5SRandy Dunlap } 2453a1d94aa5SRandy Dunlap } 2454a1d94aa5SRandy Dunlap if ($err) { 2455a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 2456d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2457a1d94aa5SRandy Dunlap "Excess function parameter " . 2458a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2459a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2460a1d94aa5SRandy Dunlap ++$warnings; 2461a1d94aa5SRandy Dunlap } else { 2462a1d94aa5SRandy Dunlap if ($nested !~ m/\Q$sects[$sx]\E/) { 2463d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2464a1d94aa5SRandy Dunlap "Excess struct/union/enum/typedef member " . 2465a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2466a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2467a1d94aa5SRandy Dunlap ++$warnings; 2468a1d94aa5SRandy Dunlap } 2469a1d94aa5SRandy Dunlap } 2470a1d94aa5SRandy Dunlap } 2471a1d94aa5SRandy Dunlap } 2472a1d94aa5SRandy Dunlap} 2473a1d94aa5SRandy Dunlap 24741da177e4SLinus Torvalds## 24754092bac7SYacine Belkadi# Checks the section describing the return value of a function. 24764092bac7SYacine Belkadisub check_return_section { 24774092bac7SYacine Belkadi my $file = shift; 24784092bac7SYacine Belkadi my $declaration_name = shift; 24794092bac7SYacine Belkadi my $return_type = shift; 24804092bac7SYacine Belkadi 24814092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 24824092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 24834092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 24844092bac7SYacine Belkadi return; 24854092bac7SYacine Belkadi } 24864092bac7SYacine Belkadi 24874092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 24884092bac7SYacine Belkadi $sections{$section_return} eq "") { 2489d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 24904092bac7SYacine Belkadi "No description found for return value of " . 24914092bac7SYacine Belkadi "'$declaration_name'\n"; 24924092bac7SYacine Belkadi ++$warnings; 24934092bac7SYacine Belkadi } 24944092bac7SYacine Belkadi} 24954092bac7SYacine Belkadi 24964092bac7SYacine Belkadi## 24971da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 24981da177e4SLinus Torvalds# processed and spits out all the details stored in the global 24991da177e4SLinus Torvalds# arrays/hashes. 25001da177e4SLinus Torvaldssub dump_function($$) { 25011da177e4SLinus Torvalds my $prototype = shift; 25021da177e4SLinus Torvalds my $file = shift; 2503cbb4d3e6SHoria Geanta my $noret = 0; 25041da177e4SLinus Torvalds 25051da177e4SLinus Torvalds $prototype =~ s/^static +//; 25061da177e4SLinus Torvalds $prototype =~ s/^extern +//; 25074dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 25081da177e4SLinus Torvalds $prototype =~ s/^inline +//; 25091da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 251032e79401SRandy Dunlap $prototype =~ s/^__inline +//; 251132e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 251232e79401SRandy Dunlap $prototype =~ s/^noinline +//; 251374fc5c65SRandy Dunlap $prototype =~ s/__init +//; 251420072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 2515270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 251670c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 25170df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 2518cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 2519b1aaa546SPaolo Bonzini $prototype =~ s/__attribute__\s*\(\( 2520b1aaa546SPaolo Bonzini (?: 2521b1aaa546SPaolo Bonzini [\w\s]++ # attribute name 2522b1aaa546SPaolo Bonzini (?:\([^)]*+\))? # attribute arguments 2523b1aaa546SPaolo Bonzini \s*+,? # optional comma at the end 2524b1aaa546SPaolo Bonzini )+ 2525b1aaa546SPaolo Bonzini \)\)\s+//x; 25261da177e4SLinus Torvalds 25271da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 25281da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 25291da177e4SLinus Torvalds # 2. Function name 25301da177e4SLinus Torvalds # 3. Function parameters. 25311da177e4SLinus Torvalds # 25321da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 25331da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 25341da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 25351da177e4SLinus Torvalds # so on. 25361da177e4SLinus Torvalds # 25371da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 25381da177e4SLinus Torvalds # the following functions' documentation still comes out right: 25391da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 25401da177e4SLinus Torvalds # - atomic_set (macro) 25419598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 25421da177e4SLinus Torvalds 2543cbb4d3e6SHoria Geanta if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 2544cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 2545cbb4d3e6SHoria Geanta # list. 2546cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 2547cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 2548cbb4d3e6SHoria Geanta $return_type = $1; 2549cbb4d3e6SHoria Geanta $declaration_name = $2; 2550cbb4d3e6SHoria Geanta $noret = 1; 2551cbb4d3e6SHoria Geanta } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25521da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25531da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25541da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 255594b3e03cSRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25561da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25571da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25581da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25591da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25601da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25611da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25621da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25631da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25649598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25659598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2566412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2567412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 25681da177e4SLinus Torvalds $return_type = $1; 25691da177e4SLinus Torvalds $declaration_name = $2; 25701da177e4SLinus Torvalds my $args = $3; 25711da177e4SLinus Torvalds 25721da177e4SLinus Torvalds create_parameterlist($args, ',', $file); 25731da177e4SLinus Torvalds } else { 2574d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 25751da177e4SLinus Torvalds return; 25761da177e4SLinus Torvalds } 25771da177e4SLinus Torvalds 2578a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 2579a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); 2580a1d94aa5SRandy Dunlap 25814092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 25824092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 25834092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 25844092bac7SYacine Belkadi # verbose mode. 25854092bac7SYacine Belkadi # TODO: always perform the check. 2586cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 25874092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 25884092bac7SYacine Belkadi } 25894092bac7SYacine Belkadi 25901da177e4SLinus Torvalds output_declaration($declaration_name, 25911da177e4SLinus Torvalds 'function', 25921da177e4SLinus Torvalds {'function' => $declaration_name, 25931da177e4SLinus Torvalds 'module' => $modulename, 25941da177e4SLinus Torvalds 'functiontype' => $return_type, 25951da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 25961da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 25971da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 25981da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 25991da177e4SLinus Torvalds 'sections' => \%sections, 26001da177e4SLinus Torvalds 'purpose' => $declaration_purpose 26011da177e4SLinus Torvalds }); 26021da177e4SLinus Torvalds} 26031da177e4SLinus Torvalds 26041da177e4SLinus Torvaldssub reset_state { 26051da177e4SLinus Torvalds $function = ""; 26061da177e4SLinus Torvalds %parameterdescs = (); 26071da177e4SLinus Torvalds %parametertypes = (); 26081da177e4SLinus Torvalds @parameterlist = (); 26091da177e4SLinus Torvalds %sections = (); 26101da177e4SLinus Torvalds @sectionlist = (); 2611a1d94aa5SRandy Dunlap $sectcheck = ""; 2612a1d94aa5SRandy Dunlap $struct_actual = ""; 26131da177e4SLinus Torvalds $prototype = ""; 26141da177e4SLinus Torvalds 261548af606aSJani Nikula $state = STATE_NORMAL; 261648af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 26171da177e4SLinus Torvalds} 26181da177e4SLinus Torvalds 261956afb0f8SJason Baronsub tracepoint_munge($) { 262056afb0f8SJason Baron my $file = shift; 262156afb0f8SJason Baron my $tracepointname = 0; 262256afb0f8SJason Baron my $tracepointargs = 0; 262356afb0f8SJason Baron 262456afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 262556afb0f8SJason Baron $tracepointname = $1; 262656afb0f8SJason Baron } 26273a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 26283a9089fdSJason Baron $tracepointname = $1; 26293a9089fdSJason Baron } 26303a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 26313a9089fdSJason Baron $tracepointname = $2; 26323a9089fdSJason Baron } 26333a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 263456afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 263556afb0f8SJason Baron $tracepointargs = $1; 263656afb0f8SJason Baron } 263756afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 2638d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 263956afb0f8SJason Baron "$prototype\n"; 264056afb0f8SJason Baron } else { 264156afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 264256afb0f8SJason Baron } 264356afb0f8SJason Baron} 264456afb0f8SJason Baron 2645b4870bc5SRandy Dunlapsub syscall_munge() { 2646b4870bc5SRandy Dunlap my $void = 0; 2647b4870bc5SRandy Dunlap 2648b4870bc5SRandy Dunlap $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs 2649b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 2650b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 2651b4870bc5SRandy Dunlap $void = 1; 2652b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 2653b4870bc5SRandy Dunlap } 2654b4870bc5SRandy Dunlap 2655b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 2656b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 2657b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 2658b4870bc5SRandy Dunlap } elsif ($void) { 2659b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 2660b4870bc5SRandy Dunlap } 2661b4870bc5SRandy Dunlap 2662b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 2663b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 2664b4870bc5SRandy Dunlap my $count = 0; 2665b4870bc5SRandy Dunlap my $len = length($prototype); 2666b4870bc5SRandy Dunlap if ($void) { 2667b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 2668b4870bc5SRandy Dunlap } 2669b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 2670b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 2671b4870bc5SRandy Dunlap $count++; 2672b4870bc5SRandy Dunlap if ($count % 2 == 1) { 2673b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 2674b4870bc5SRandy Dunlap } 2675b4870bc5SRandy Dunlap } 2676b4870bc5SRandy Dunlap } 2677b4870bc5SRandy Dunlap} 2678b4870bc5SRandy Dunlap 2679b7afa92bSDaniel Vettersub process_proto_function($$) { 26801da177e4SLinus Torvalds my $x = shift; 26811da177e4SLinus Torvalds my $file = shift; 26821da177e4SLinus Torvalds 268351f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 268451f5a0c8SRandy Dunlap 2685890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 26861da177e4SLinus Torvalds # do nothing 26871da177e4SLinus Torvalds } 26881da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 26891da177e4SLinus Torvalds $prototype .= $1; 26901da177e4SLinus Torvalds } 2691b4870bc5SRandy Dunlap 2692890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 26931da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 26941da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 26951da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 2696b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 2697b4870bc5SRandy Dunlap syscall_munge(); 2698b4870bc5SRandy Dunlap } 26993a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 27003a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 27013a9089fdSJason Baron { 270256afb0f8SJason Baron tracepoint_munge($file); 270356afb0f8SJason Baron } 27041da177e4SLinus Torvalds dump_function($prototype, $file); 27051da177e4SLinus Torvalds reset_state(); 27061da177e4SLinus Torvalds } 27071da177e4SLinus Torvalds} 27081da177e4SLinus Torvalds 2709b7afa92bSDaniel Vettersub process_proto_type($$) { 27101da177e4SLinus Torvalds my $x = shift; 27111da177e4SLinus Torvalds my $file = shift; 27121da177e4SLinus Torvalds 27131da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 27141da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 27151da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 271651f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 271751f5a0c8SRandy Dunlap 27181da177e4SLinus Torvalds if ($x =~ /^#/) { 27191da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 27201da177e4SLinus Torvalds $x .= ";"; 27211da177e4SLinus Torvalds } 27221da177e4SLinus Torvalds 27231da177e4SLinus Torvalds while (1) { 27241da177e4SLinus Torvalds if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 27251da177e4SLinus Torvalds $prototype .= $1 . $2; 27261da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 27271da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 27281da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 27291da177e4SLinus Torvalds dump_declaration($prototype, $file); 27301da177e4SLinus Torvalds reset_state(); 27311da177e4SLinus Torvalds last; 27321da177e4SLinus Torvalds } 27331da177e4SLinus Torvalds $x = $3; 27341da177e4SLinus Torvalds } else { 27351da177e4SLinus Torvalds $prototype .= $x; 27361da177e4SLinus Torvalds last; 27371da177e4SLinus Torvalds } 27381da177e4SLinus Torvalds } 27391da177e4SLinus Torvalds} 27401da177e4SLinus Torvalds 27416b5b55f6SRandy Dunlap# xml_escape: replace <, >, and & in the text stream; 27426b5b55f6SRandy Dunlap# 27436b5b55f6SRandy Dunlap# however, formatting controls that are generated internally/locally in the 27446b5b55f6SRandy Dunlap# kernel-doc script are not escaped here; instead, they begin life like 27456b5b55f6SRandy Dunlap# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings 27466b5b55f6SRandy Dunlap# are converted to their mnemonic-expected output, without the 4 * '\' & ':', 27476b5b55f6SRandy Dunlap# just before actual output; (this is done by local_unescape()) 27481da177e4SLinus Torvaldssub xml_escape($) { 27491da177e4SLinus Torvalds my $text = shift; 2750ecfb251aSRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 2751ecfb251aSRandy Dunlap return $text; 2752ecfb251aSRandy Dunlap } 27531da177e4SLinus Torvalds $text =~ s/\&/\\\\\\amp;/g; 27541da177e4SLinus Torvalds $text =~ s/\</\\\\\\lt;/g; 27551da177e4SLinus Torvalds $text =~ s/\>/\\\\\\gt;/g; 27561da177e4SLinus Torvalds return $text; 27571da177e4SLinus Torvalds} 27581da177e4SLinus Torvalds 2759c0d1b6eeSJonathan Corbet# xml_unescape: reverse the effects of xml_escape 2760c0d1b6eeSJonathan Corbetsub xml_unescape($) { 2761c0d1b6eeSJonathan Corbet my $text = shift; 2762c0d1b6eeSJonathan Corbet if (($output_mode eq "text") || ($output_mode eq "man")) { 2763c0d1b6eeSJonathan Corbet return $text; 2764c0d1b6eeSJonathan Corbet } 2765c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\amp;/\&/g; 2766c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\lt;/</g; 2767c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\gt;/>/g; 2768c0d1b6eeSJonathan Corbet return $text; 2769c0d1b6eeSJonathan Corbet} 2770c0d1b6eeSJonathan Corbet 27716b5b55f6SRandy Dunlap# convert local escape strings to html 27726b5b55f6SRandy Dunlap# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) 27736b5b55f6SRandy Dunlapsub local_unescape($) { 27746b5b55f6SRandy Dunlap my $text = shift; 27756b5b55f6SRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 27766b5b55f6SRandy Dunlap return $text; 27776b5b55f6SRandy Dunlap } 27786b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\lt:/</g; 27796b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\gt:/>/g; 27806b5b55f6SRandy Dunlap return $text; 27816b5b55f6SRandy Dunlap} 27826b5b55f6SRandy Dunlap 27831ad560e4SJani Nikulasub map_filename($) { 27841ad560e4SJani Nikula my $file; 27851ad560e4SJani Nikula my ($orig_file) = @_; 27861ad560e4SJani Nikula 27871ad560e4SJani Nikula if (defined($ENV{'SRCTREE'})) { 27881ad560e4SJani Nikula $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 27891ad560e4SJani Nikula } else { 27901ad560e4SJani Nikula $file = $orig_file; 27911ad560e4SJani Nikula } 27921ad560e4SJani Nikula 27931ad560e4SJani Nikula if (defined($source_map{$file})) { 27941ad560e4SJani Nikula $file = $source_map{$file}; 27951ad560e4SJani Nikula } 27961ad560e4SJani Nikula 27971ad560e4SJani Nikula return $file; 27981ad560e4SJani Nikula} 27991ad560e4SJani Nikula 280088c2b57dSJani Nikulasub process_export_file($) { 280188c2b57dSJani Nikula my ($orig_file) = @_; 280288c2b57dSJani Nikula my $file = map_filename($orig_file); 280388c2b57dSJani Nikula 280488c2b57dSJani Nikula if (!open(IN,"<$file")) { 280588c2b57dSJani Nikula print STDERR "Error: Cannot open file $file\n"; 280688c2b57dSJani Nikula ++$errors; 280788c2b57dSJani Nikula return; 280888c2b57dSJani Nikula } 280988c2b57dSJani Nikula 281088c2b57dSJani Nikula while (<IN>) { 281188c2b57dSJani Nikula if (/$export_symbol/) { 281288c2b57dSJani Nikula $function_table{$2} = 1; 281388c2b57dSJani Nikula } 281488c2b57dSJani Nikula } 281588c2b57dSJani Nikula 281688c2b57dSJani Nikula close(IN); 281788c2b57dSJani Nikula} 281888c2b57dSJani Nikula 28191da177e4SLinus Torvaldssub process_file($) { 28202283a117SRandy Dunlap my $file; 28211da177e4SLinus Torvalds my $identifier; 28221da177e4SLinus Torvalds my $func; 2823a21217daSRandy Dunlap my $descr; 28246423133bSJohannes Weiner my $in_purpose = 0; 28251da177e4SLinus Torvalds my $initial_section_counter = $section_counter; 282668f86662SBen Hutchings my ($orig_file) = @_; 2827b7886de4SJani Nikula my $leading_space; 28281da177e4SLinus Torvalds 28291ad560e4SJani Nikula $file = map_filename($orig_file); 28301da177e4SLinus Torvalds 28311da177e4SLinus Torvalds if (!open(IN,"<$file")) { 28321da177e4SLinus Torvalds print STDERR "Error: Cannot open file $file\n"; 28331da177e4SLinus Torvalds ++$errors; 28341da177e4SLinus Torvalds return; 28351da177e4SLinus Torvalds } 28361da177e4SLinus Torvalds 2837a9e7314bSIlya Dryomov $. = 1; 2838a9e7314bSIlya Dryomov 28391da177e4SLinus Torvalds $section_counter = 0; 28401da177e4SLinus Torvalds while (<IN>) { 284165478428SDaniel Santos while (s/\\\s*$//) { 284265478428SDaniel Santos $_ .= <IN>; 284365478428SDaniel Santos } 284448af606aSJani Nikula if ($state == STATE_NORMAL) { 28451da177e4SLinus Torvalds if (/$doc_start/o) { 284648af606aSJani Nikula $state = STATE_NAME; # next line is always the function name 2847850622dfSRandy Dunlap $in_doc_sect = 0; 28480b0f5f29SDaniel Vetter $declaration_start_line = $. + 1; 28491da177e4SLinus Torvalds } 285048af606aSJani Nikula } elsif ($state == STATE_NAME) {# this line is the function name (always) 28511da177e4SLinus Torvalds if (/$doc_block/o) { 285248af606aSJani Nikula $state = STATE_DOCBLOCK; 28531da177e4SLinus Torvalds $contents = ""; 28540b0f5f29SDaniel Vetter $new_start_line = $. + 1; 28550b0f5f29SDaniel Vetter 28561da177e4SLinus Torvalds if ( $1 eq "" ) { 28571da177e4SLinus Torvalds $section = $section_intro; 28581da177e4SLinus Torvalds } else { 28591da177e4SLinus Torvalds $section = $1; 28601da177e4SLinus Torvalds } 28611da177e4SLinus Torvalds } 28621da177e4SLinus Torvalds elsif (/$doc_decl/o) { 28631da177e4SLinus Torvalds $identifier = $1; 28641da177e4SLinus Torvalds if (/\s*([\w\s]+?)\s*-/) { 28651da177e4SLinus Torvalds $identifier = $1; 28661da177e4SLinus Torvalds } 28671da177e4SLinus Torvalds 286848af606aSJani Nikula $state = STATE_FIELD; 28690b0f5f29SDaniel Vetter # if there's no @param blocks need to set up default section 28700b0f5f29SDaniel Vetter # here 28712f4ad40aSJani Nikula $contents = ""; 28722f4ad40aSJani Nikula $section = $section_default; 28730b0f5f29SDaniel Vetter $new_start_line = $. + 1; 28741da177e4SLinus Torvalds if (/-(.*)/) { 287551f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2876a21217daSRandy Dunlap $descr= $1; 2877a21217daSRandy Dunlap $descr =~ s/^\s*//; 2878a21217daSRandy Dunlap $descr =~ s/\s*$//; 287912ae6779SDaniel Santos $descr =~ s/\s+/ /g; 2880a21217daSRandy Dunlap $declaration_purpose = xml_escape($descr); 28816423133bSJohannes Weiner $in_purpose = 1; 28821da177e4SLinus Torvalds } else { 28831da177e4SLinus Torvalds $declaration_purpose = ""; 28841da177e4SLinus Torvalds } 288577cc23b8SRandy Dunlap 288677cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 2887d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 288877cc23b8SRandy Dunlap print STDERR $_; 288977cc23b8SRandy Dunlap ++$warnings; 289077cc23b8SRandy Dunlap } 289177cc23b8SRandy Dunlap 28921da177e4SLinus Torvalds if ($identifier =~ m/^struct/) { 28931da177e4SLinus Torvalds $decl_type = 'struct'; 28941da177e4SLinus Torvalds } elsif ($identifier =~ m/^union/) { 28951da177e4SLinus Torvalds $decl_type = 'union'; 28961da177e4SLinus Torvalds } elsif ($identifier =~ m/^enum/) { 28971da177e4SLinus Torvalds $decl_type = 'enum'; 28981da177e4SLinus Torvalds } elsif ($identifier =~ m/^typedef/) { 28991da177e4SLinus Torvalds $decl_type = 'typedef'; 29001da177e4SLinus Torvalds } else { 29011da177e4SLinus Torvalds $decl_type = 'function'; 29021da177e4SLinus Torvalds } 29031da177e4SLinus Torvalds 29041da177e4SLinus Torvalds if ($verbose) { 2905d40e1e65SBart Van Assche print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; 29061da177e4SLinus Torvalds } 29071da177e4SLinus Torvalds } else { 2908d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 29091da177e4SLinus Torvalds " - I thought it was a doc line\n"; 29101da177e4SLinus Torvalds ++$warnings; 291148af606aSJani Nikula $state = STATE_NORMAL; 29121da177e4SLinus Torvalds } 291348af606aSJani Nikula } elsif ($state == STATE_FIELD) { # look for head: lines, and include content 2914f624adefSJani Nikula if (/$doc_sect/i) { # case insensitive for supported section names 29151da177e4SLinus Torvalds $newsection = $1; 29161da177e4SLinus Torvalds $newcontents = $2; 29171da177e4SLinus Torvalds 2918f624adefSJani Nikula # map the supported section names to the canonical names 2919f624adefSJani Nikula if ($newsection =~ m/^description$/i) { 2920f624adefSJani Nikula $newsection = $section_default; 2921f624adefSJani Nikula } elsif ($newsection =~ m/^context$/i) { 2922f624adefSJani Nikula $newsection = $section_context; 2923f624adefSJani Nikula } elsif ($newsection =~ m/^returns?$/i) { 2924f624adefSJani Nikula $newsection = $section_return; 2925f624adefSJani Nikula } elsif ($newsection =~ m/^\@return$/) { 2926f624adefSJani Nikula # special: @return is a section, not a param description 2927f624adefSJani Nikula $newsection = $section_return; 2928f624adefSJani Nikula } 2929f624adefSJani Nikula 2930792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 2931850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 2932d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: contents before sections\n"; 2933850622dfSRandy Dunlap ++$warnings; 2934850622dfSRandy Dunlap } 293594dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 29361da177e4SLinus Torvalds $section = $section_default; 29371da177e4SLinus Torvalds } 29381da177e4SLinus Torvalds 2939850622dfSRandy Dunlap $in_doc_sect = 1; 29406423133bSJohannes Weiner $in_purpose = 0; 29411da177e4SLinus Torvalds $contents = $newcontents; 29420b0f5f29SDaniel Vetter $new_start_line = $.; 294327205744SRandy Dunlap while ((substr($contents, 0, 1) eq " ") || 294427205744SRandy Dunlap substr($contents, 0, 1) eq "\t") { 294505189497SRandy Dunlap $contents = substr($contents, 1); 294605189497SRandy Dunlap } 29470a726301SJani Nikula if ($contents ne "") { 29481da177e4SLinus Torvalds $contents .= "\n"; 29491da177e4SLinus Torvalds } 29501da177e4SLinus Torvalds $section = $newsection; 2951b7886de4SJani Nikula $leading_space = undef; 29521da177e4SLinus Torvalds } elsif (/$doc_end/) { 29534c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 295494dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 29551da177e4SLinus Torvalds $section = $section_default; 29561da177e4SLinus Torvalds $contents = ""; 29571da177e4SLinus Torvalds } 295846b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 295946b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2960d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: suspicious ending line: $_"; 296146b958ebSRandy Dunlap ++$warnings; 296246b958ebSRandy Dunlap } 29631da177e4SLinus Torvalds 29641da177e4SLinus Torvalds $prototype = ""; 296548af606aSJani Nikula $state = STATE_PROTO; 29661da177e4SLinus Torvalds $brcount = 0; 29671da177e4SLinus Torvalds# print STDERR "end of doc comment, looking for prototype\n"; 29681da177e4SLinus Torvalds } elsif (/$doc_content/) { 29691da177e4SLinus Torvalds # miguel-style comment kludge, look for blank lines after 29701da177e4SLinus Torvalds # @parameter line to signify start of description 29716423133bSJohannes Weiner if ($1 eq "") { 29726423133bSJohannes Weiner if ($section =~ m/^@/ || $section eq $section_context) { 297394dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 29741da177e4SLinus Torvalds $section = $section_default; 29751da177e4SLinus Torvalds $contents = ""; 29760b0f5f29SDaniel Vetter $new_start_line = $.; 29771da177e4SLinus Torvalds } else { 29786423133bSJohannes Weiner $contents .= "\n"; 29796423133bSJohannes Weiner } 29806423133bSJohannes Weiner $in_purpose = 0; 29816423133bSJohannes Weiner } elsif ($in_purpose == 1) { 29826423133bSJohannes Weiner # Continued declaration purpose 29836423133bSJohannes Weiner chomp($declaration_purpose); 29846423133bSJohannes Weiner $declaration_purpose .= " " . xml_escape($1); 298512ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 29866423133bSJohannes Weiner } else { 2987b7886de4SJani Nikula my $cont = $1; 2988b7886de4SJani Nikula if ($section =~ m/^@/ || $section eq $section_context) { 2989b7886de4SJani Nikula if (!defined $leading_space) { 2990b7886de4SJani Nikula if ($cont =~ m/^(\s+)/) { 2991b7886de4SJani Nikula $leading_space = $1; 2992b7886de4SJani Nikula } else { 2993b7886de4SJani Nikula $leading_space = ""; 2994b7886de4SJani Nikula } 2995b7886de4SJani Nikula } 2996b7886de4SJani Nikula 2997b7886de4SJani Nikula $cont =~ s/^$leading_space//; 2998b7886de4SJani Nikula } 2999b7886de4SJani Nikula $contents .= $cont . "\n"; 30001da177e4SLinus Torvalds } 30011da177e4SLinus Torvalds } else { 30021da177e4SLinus Torvalds # i dont know - bad line? ignore. 3003d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: bad line: $_"; 30041da177e4SLinus Torvalds ++$warnings; 30051da177e4SLinus Torvalds } 300648af606aSJani Nikula } elsif ($state == STATE_INLINE) { # scanning for inline parameters 3007a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 300848af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 3009a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 3010a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 30110b0f5f29SDaniel Vetter $new_start_line = $.; 3012a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 3013a4c6ebedSDanilo Cesar Lemes de Paula while ((substr($contents, 0, 1) eq " ") || 3014a4c6ebedSDanilo Cesar Lemes de Paula substr($contents, 0, 1) eq "\t") { 3015a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 3016a4c6ebedSDanilo Cesar Lemes de Paula } 3017a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 3018a4c6ebedSDanilo Cesar Lemes de Paula } 301948af606aSJani Nikula $inline_doc_state = STATE_INLINE_TEXT; 3020a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 302148af606aSJani Nikula } elsif (/$doc_inline_end/) { 3022a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 3023a4c6ebedSDanilo Cesar Lemes de Paula dump_section($file, $section, xml_escape($contents)); 3024a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 3025a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 3026a4c6ebedSDanilo Cesar Lemes de Paula } 302748af606aSJani Nikula $state = STATE_PROTO; 302848af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 3029a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 3030a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 303148af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_TEXT) { 3032a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 30336450c895SJani Nikula # nuke leading blank lines 30346450c895SJani Nikula if ($contents =~ /^\s*$/) { 30356450c895SJani Nikula $contents = ""; 30366450c895SJani Nikula } 303748af606aSJani Nikula } elsif ($inline_doc_state == STATE_INLINE_NAME) { 303848af606aSJani Nikula $inline_doc_state = STATE_INLINE_ERROR; 3039e7ca311eSDaniel Vetter print STDERR "${file}:$.: warning: "; 3040a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Incorrect use of kernel-doc format: $_"; 3041a4c6ebedSDanilo Cesar Lemes de Paula ++$warnings; 3042a4c6ebedSDanilo Cesar Lemes de Paula } 3043a4c6ebedSDanilo Cesar Lemes de Paula } 304448af606aSJani Nikula } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype) 30450c9aa209SJani Nikula if (/$doc_inline_oneline/) { 30460c9aa209SJani Nikula $section = $1; 30470c9aa209SJani Nikula $contents = $2; 30480c9aa209SJani Nikula if ($contents ne "") { 30490c9aa209SJani Nikula $contents .= "\n"; 30500c9aa209SJani Nikula dump_section($file, $section, xml_escape($contents)); 30510c9aa209SJani Nikula $section = $section_default; 30520c9aa209SJani Nikula $contents = ""; 30530c9aa209SJani Nikula } 30540c9aa209SJani Nikula } elsif (/$doc_inline_start/) { 305548af606aSJani Nikula $state = STATE_INLINE; 305648af606aSJani Nikula $inline_doc_state = STATE_INLINE_NAME; 3057a4c6ebedSDanilo Cesar Lemes de Paula } elsif ($decl_type eq 'function') { 3058b7afa92bSDaniel Vetter process_proto_function($_, $file); 30591da177e4SLinus Torvalds } else { 3060b7afa92bSDaniel Vetter process_proto_type($_, $file); 30611da177e4SLinus Torvalds } 306248af606aSJani Nikula } elsif ($state == STATE_DOCBLOCK) { 3063ebff7f92SDaniel Vetter if (/$doc_end/) 30641da177e4SLinus Torvalds { 306594dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 30662f4ad40aSJani Nikula $section = $section_default; 30671da177e4SLinus Torvalds $contents = ""; 30681da177e4SLinus Torvalds $function = ""; 30691da177e4SLinus Torvalds %parameterdescs = (); 30701da177e4SLinus Torvalds %parametertypes = (); 30711da177e4SLinus Torvalds @parameterlist = (); 30721da177e4SLinus Torvalds %sections = (); 30731da177e4SLinus Torvalds @sectionlist = (); 30741da177e4SLinus Torvalds $prototype = ""; 307548af606aSJani Nikula $state = STATE_NORMAL; 30761da177e4SLinus Torvalds } 30771da177e4SLinus Torvalds elsif (/$doc_content/) 30781da177e4SLinus Torvalds { 30791da177e4SLinus Torvalds if ( $1 eq "" ) 30801da177e4SLinus Torvalds { 30811da177e4SLinus Torvalds $contents .= $blankline; 30821da177e4SLinus Torvalds } 30831da177e4SLinus Torvalds else 30841da177e4SLinus Torvalds { 30851da177e4SLinus Torvalds $contents .= $1 . "\n"; 30861da177e4SLinus Torvalds } 30871da177e4SLinus Torvalds } 30881da177e4SLinus Torvalds } 30891da177e4SLinus Torvalds } 30901da177e4SLinus Torvalds if ($initial_section_counter == $section_counter) { 3091d40e1e65SBart Van Assche print STDERR "${file}:1: warning: no structured comments found\n"; 3092b6c3f456SJani Nikula if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) { 3093e946c43aSJohannes Berg print STDERR " Was looking for '$_'.\n" for keys %function_table; 3094e946c43aSJohannes Berg } 30951da177e4SLinus Torvalds if ($output_mode eq "xml") { 30961da177e4SLinus Torvalds # The template wants at least one RefEntry here; make one. 30971da177e4SLinus Torvalds print "<refentry>\n"; 30981da177e4SLinus Torvalds print " <refnamediv>\n"; 30991da177e4SLinus Torvalds print " <refname>\n"; 310068f86662SBen Hutchings print " ${orig_file}\n"; 31011da177e4SLinus Torvalds print " </refname>\n"; 31021da177e4SLinus Torvalds print " <refpurpose>\n"; 31031da177e4SLinus Torvalds print " Document generation inconsistency\n"; 31041da177e4SLinus Torvalds print " </refpurpose>\n"; 31051da177e4SLinus Torvalds print " </refnamediv>\n"; 31061da177e4SLinus Torvalds print " <refsect1>\n"; 31071da177e4SLinus Torvalds print " <title>\n"; 31081da177e4SLinus Torvalds print " Oops\n"; 31091da177e4SLinus Torvalds print " </title>\n"; 31101da177e4SLinus Torvalds print " <warning>\n"; 31111da177e4SLinus Torvalds print " <para>\n"; 31121da177e4SLinus Torvalds print " The template for this document tried to insert\n"; 31131da177e4SLinus Torvalds print " the structured comment from the file\n"; 311468f86662SBen Hutchings print " <filename>${orig_file}</filename> at this point,\n"; 31151da177e4SLinus Torvalds print " but none was found.\n"; 31161da177e4SLinus Torvalds print " This dummy section is inserted to allow\n"; 31171da177e4SLinus Torvalds print " generation to continue.\n"; 31181da177e4SLinus Torvalds print " </para>\n"; 31191da177e4SLinus Torvalds print " </warning>\n"; 31201da177e4SLinus Torvalds print " </refsect1>\n"; 31211da177e4SLinus Torvalds print "</refentry>\n"; 31221da177e4SLinus Torvalds } 31231da177e4SLinus Torvalds } 31241da177e4SLinus Torvalds} 31258484baaaSRandy Dunlap 31268484baaaSRandy Dunlap 31278484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 31288484baaaSRandy Dunlap 31298484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 31308484baaaSRandy Dunlap# using the s// operator. 31311ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 31324d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 31334d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 31344d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 31354d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 31368484baaaSRandy Dunlap} 31378484baaaSRandy Dunlap 31388484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 31398484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 31408484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 31418484baaaSRandy Dunlap my ($relname, $absname); 31428484baaaSRandy Dunlap while(<SOURCE_MAP>) { 31438484baaaSRandy Dunlap chop(); 31448484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 31458484baaaSRandy Dunlap $relname =~ s:^/+::; 31468484baaaSRandy Dunlap $source_map{$relname} = $absname; 31478484baaaSRandy Dunlap } 31488484baaaSRandy Dunlap close(SOURCE_MAP); 31498484baaaSRandy Dunlap} 31508484baaaSRandy Dunlap 315188c2b57dSJani Nikulaif ($output_selection == OUTPUT_EXPORTED || 315288c2b57dSJani Nikula $output_selection == OUTPUT_INTERNAL) { 3153c9b2cfb3SJani Nikula 3154c9b2cfb3SJani Nikula push(@export_file_list, @ARGV); 3155c9b2cfb3SJani Nikula 315688c2b57dSJani Nikula foreach (@export_file_list) { 315788c2b57dSJani Nikula chomp; 315888c2b57dSJani Nikula process_export_file($_); 315988c2b57dSJani Nikula } 316088c2b57dSJani Nikula} 316188c2b57dSJani Nikula 31628484baaaSRandy Dunlapforeach (@ARGV) { 31638484baaaSRandy Dunlap chomp; 31648484baaaSRandy Dunlap process_file($_); 31658484baaaSRandy Dunlap} 31668484baaaSRandy Dunlapif ($verbose && $errors) { 31678484baaaSRandy Dunlap print STDERR "$errors errors\n"; 31688484baaaSRandy Dunlap} 31698484baaaSRandy Dunlapif ($verbose && $warnings) { 31708484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 31718484baaaSRandy Dunlap} 31728484baaaSRandy Dunlap 31738484baaaSRandy Dunlapexit($errors); 3174