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') 2021da177e4SLinus Torvalds# '@parameter' - name of a parameter 2031da177e4SLinus Torvalds# '%CONST' - name of a constant. 2041da177e4SLinus Torvalds 2058484baaaSRandy Dunlap## init lots of data 2068484baaaSRandy Dunlap 2071da177e4SLinus Torvaldsmy $errors = 0; 2081da177e4SLinus Torvaldsmy $warnings = 0; 2095f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds# match expressions used to find embedded type information 2121da177e4SLinus Torvaldsmy $type_constant = '\%([-_\w]+)'; 2131da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 2141da177e4SLinus Torvaldsmy $type_param = '\@(\w+)'; 215*5219f18aSJonathan Corbetmy $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params 2163eb014a1SRandy Dunlapmy $type_struct = '\&((struct\s*)*[_\w]+)'; 2176b5b55f6SRandy Dunlapmy $type_struct_xml = '\\&((struct\s*)*[_\w]+)'; 2181da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 219c0d1b6eeSJonathan Corbetmy $type_enum_full = '\&(enum)\s*([_\w]+)'; 220c0d1b6eeSJonathan Corbetmy $type_struct_full = '\&(struct)\s*([_\w]+)'; 22147ae7aedSJani Nikulamy $type_typedef_full = '\&(typedef)\s*([_\w]+)'; 22247ae7aedSJani Nikulamy $type_union_full = '\&(union)\s*([_\w]+)'; 223f3341dcfSJani Nikulamy $type_member = '\&([_\w]+)((\.|->)[_\w]+)'; 224f3341dcfSJani Nikulamy $type_member_func = $type_member . '\(\)'; 2251da177e4SLinus Torvalds 2261da177e4SLinus Torvalds# Output conversion substitutions. 2271da177e4SLinus Torvalds# One for each output format 2281da177e4SLinus Torvalds 2291da177e4SLinus Torvalds# these work fairly well 2304d732701SDanilo Cesar Lemes de Paulamy @highlights_html = ( 2314d732701SDanilo Cesar Lemes de Paula [$type_constant, "<i>\$1</i>"], 2324d732701SDanilo Cesar Lemes de Paula [$type_func, "<b>\$1</b>"], 2334d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<i>\$1</i>"], 2344d732701SDanilo Cesar Lemes de Paula [$type_env, "<b><i>\$1</i></b>"], 2354d732701SDanilo Cesar Lemes de Paula [$type_param, "<tt><b>\$1</b></tt>"] 2364d732701SDanilo Cesar Lemes de Paula ); 2376b5b55f6SRandy Dunlapmy $local_lt = "\\\\\\\\lt:"; 2386b5b55f6SRandy Dunlapmy $local_gt = "\\\\\\\\gt:"; 2396b5b55f6SRandy Dunlapmy $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" 2401da177e4SLinus Torvalds 2411b40c194SDan Luedtke# html version 5 2424d732701SDanilo Cesar Lemes de Paulamy @highlights_html5 = ( 2434d732701SDanilo Cesar Lemes de Paula [$type_constant, "<span class=\"const\">\$1</span>"], 2444d732701SDanilo Cesar Lemes de Paula [$type_func, "<span class=\"func\">\$1</span>"], 2454d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<span class=\"struct\">\$1</span>"], 2464d732701SDanilo Cesar Lemes de Paula [$type_env, "<span class=\"env\">\$1</span>"], 2474d732701SDanilo Cesar Lemes de Paula [$type_param, "<span class=\"param\">\$1</span>]"] 2484d732701SDanilo Cesar Lemes de Paula ); 2491b40c194SDan Luedtkemy $blankline_html5 = $local_lt . "br /" . $local_gt; 2501b40c194SDan Luedtke 2511da177e4SLinus Torvalds# XML, docbook format 2524d732701SDanilo Cesar Lemes de Paulamy @highlights_xml = ( 2534d732701SDanilo Cesar Lemes de Paula ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"], 2544d732701SDanilo Cesar Lemes de Paula [$type_constant, "<constant>\$1</constant>"], 2554d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<structname>\$1</structname>"], 2564d732701SDanilo Cesar Lemes de Paula [$type_param, "<parameter>\$1</parameter>"], 2574d732701SDanilo Cesar Lemes de Paula [$type_func, "<function>\$1</function>"], 2584d732701SDanilo Cesar Lemes de Paula [$type_env, "<envar>\$1</envar>"] 2594d732701SDanilo Cesar Lemes de Paula ); 2605c98fc03SJohannes Bergmy $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; 2611da177e4SLinus Torvalds 2621da177e4SLinus Torvalds# gnome, docbook format 2634d732701SDanilo Cesar Lemes de Paulamy @highlights_gnome = ( 2644d732701SDanilo Cesar Lemes de Paula [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"], 2654d732701SDanilo Cesar Lemes de Paula [$type_func, "<function>\$1</function>"], 2664d732701SDanilo Cesar Lemes de Paula [$type_struct, "<structname>\$1</structname>"], 2674d732701SDanilo Cesar Lemes de Paula [$type_env, "<envar>\$1</envar>"], 2684d732701SDanilo Cesar Lemes de Paula [$type_param, "<parameter>\$1</parameter>" ] 2694d732701SDanilo Cesar Lemes de Paula ); 2701da177e4SLinus Torvaldsmy $blankline_gnome = "</para><para>\n"; 2711da177e4SLinus Torvalds 2721da177e4SLinus Torvalds# these are pretty rough 2734d732701SDanilo Cesar Lemes de Paulamy @highlights_man = ( 2744d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 2754d732701SDanilo Cesar Lemes de Paula [$type_func, "\\\\fB\$1\\\\fP"], 2764d732701SDanilo Cesar Lemes de Paula [$type_struct, "\\\\fI\$1\\\\fP"], 2774d732701SDanilo Cesar Lemes de Paula [$type_param, "\\\\fI\$1\\\\fP"] 2784d732701SDanilo Cesar Lemes de Paula ); 2791da177e4SLinus Torvaldsmy $blankline_man = ""; 2801da177e4SLinus Torvalds 2811da177e4SLinus Torvalds# text-mode 2824d732701SDanilo Cesar Lemes de Paulamy @highlights_text = ( 2834d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 2844d732701SDanilo Cesar Lemes de Paula [$type_func, "\$1"], 2854d732701SDanilo Cesar Lemes de Paula [$type_struct, "\$1"], 2864d732701SDanilo Cesar Lemes de Paula [$type_param, "\$1"] 2874d732701SDanilo Cesar Lemes de Paula ); 2881da177e4SLinus Torvaldsmy $blankline_text = ""; 2891da177e4SLinus Torvalds 290c0d1b6eeSJonathan Corbet# rst-mode 291c0d1b6eeSJonathan Corbetmy @highlights_rst = ( 292c0d1b6eeSJonathan Corbet [$type_constant, "``\$1``"], 293f3341dcfSJani Nikula # Note: need to escape () to avoid func matching later 294f3341dcfSJani Nikula [$type_member_func, "\\:c\\:type\\:`\$1\$2\\\\(\\\\) <\$1>`"], 295f3341dcfSJani Nikula [$type_member, "\\:c\\:type\\:`\$1\$2 <\$1>`"], 296*5219f18aSJonathan Corbet [$type_fp_param, "**\$1\\\\(\\\\)**"], 297a19bce64SJani Nikula [$type_func, "\\:c\\:func\\:`\$1()`"], 29862850976SJani Nikula [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 29962850976SJani Nikula [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 30047ae7aedSJani Nikula [$type_typedef_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 30147ae7aedSJani Nikula [$type_union_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 302a7291e7eSJani Nikula # in rst this can refer to any type 303a7291e7eSJani Nikula [$type_struct, "\\:c\\:type\\:`\$1`"], 304c0d1b6eeSJonathan Corbet [$type_param, "**\$1**"] 305c0d1b6eeSJonathan Corbet ); 306c0d1b6eeSJonathan Corbetmy $blankline_rst = "\n"; 307c0d1b6eeSJonathan Corbet 308eda603f6SJohannes Berg# list mode 3094d732701SDanilo Cesar Lemes de Paulamy @highlights_list = ( 3104d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 3114d732701SDanilo Cesar Lemes de Paula [$type_func, "\$1"], 3124d732701SDanilo Cesar Lemes de Paula [$type_struct, "\$1"], 3134d732701SDanilo Cesar Lemes de Paula [$type_param, "\$1"] 3144d732701SDanilo Cesar Lemes de Paula ); 315eda603f6SJohannes Bergmy $blankline_list = ""; 3161da177e4SLinus Torvalds 3171da177e4SLinus Torvalds# read arguments 3181da177e4SLinus Torvaldsif ($#ARGV == -1) { 3191da177e4SLinus Torvalds usage(); 3201da177e4SLinus Torvalds} 3211da177e4SLinus Torvalds 3228484baaaSRandy Dunlapmy $kernelversion; 3238484baaaSRandy Dunlapmy $dohighlight = ""; 3248484baaaSRandy Dunlap 3251da177e4SLinus Torvaldsmy $verbose = 0; 3261da177e4SLinus Torvaldsmy $output_mode = "man"; 327e314ba31SDaniel Santosmy $output_preformatted = 0; 3284b44595aSJohannes Bergmy $no_doc_sections = 0; 3290b0f5f29SDaniel Vettermy $enable_lineno = 0; 3304d732701SDanilo Cesar Lemes de Paulamy @highlights = @highlights_man; 3311da177e4SLinus Torvaldsmy $blankline = $blankline_man; 3321da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 333b6c3f456SJani Nikula 334b6c3f456SJani Nikulause constant { 335b6c3f456SJani Nikula OUTPUT_ALL => 0, # output all symbols and doc sections 336b6c3f456SJani Nikula OUTPUT_INCLUDE => 1, # output only specified symbols 337b6c3f456SJani Nikula OUTPUT_EXCLUDE => 2, # output everything except specified symbols 338b6c3f456SJani Nikula OUTPUT_EXPORTED => 3, # output exported symbols 339b6c3f456SJani Nikula OUTPUT_INTERNAL => 4, # output non-exported symbols 340b6c3f456SJani Nikula}; 341b6c3f456SJani Nikulamy $output_selection = OUTPUT_ALL; 342b2c4105bSBen Hutchingsmy $show_not_found = 0; 343b2c4105bSBen Hutchings 34488c2b57dSJani Nikulamy @export_file_list; 34588c2b57dSJani Nikula 346b2c4105bSBen Hutchingsmy @build_time; 347b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 348b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 349b2c4105bSBen Hutchings @build_time = gmtime($seconds); 350b2c4105bSBen Hutchings} else { 351b2c4105bSBen Hutchings @build_time = localtime; 352b2c4105bSBen Hutchings} 353b2c4105bSBen Hutchings 3541da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 3551da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 356b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 357b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 3581da177e4SLinus Torvalds 3598484baaaSRandy Dunlap# Essentially these are globals. 360b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 361b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 3621da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 3631da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 3640b0f5f29SDaniel Vettermy $declaration_start_line; 3651da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 3661c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 3671da177e4SLinus Torvalds 368bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 369bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 370bd0e88e5SRandy Dunlap} 371bd0e88e5SRandy Dunlap 3721da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 3731da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 3741da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 3751da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 3761da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 3771da177e4SLinus Torvalds# into html. 3781da177e4SLinus Torvaldsmy $section_counter = 0; 3791da177e4SLinus Torvalds 3801da177e4SLinus Torvaldsmy $lineprefix=""; 3811da177e4SLinus Torvalds 38248af606aSJani Nikula# Parser states 38348af606aSJani Nikulause constant { 38448af606aSJani Nikula STATE_NORMAL => 0, # normal code 38548af606aSJani Nikula STATE_NAME => 1, # looking for function name 38648af606aSJani Nikula STATE_FIELD => 2, # scanning field start 38748af606aSJani Nikula STATE_PROTO => 3, # scanning prototype 38848af606aSJani Nikula STATE_DOCBLOCK => 4, # documentation block 38948af606aSJani Nikula STATE_INLINE => 5, # gathering documentation outside main block 39048af606aSJani Nikula}; 3911da177e4SLinus Torvaldsmy $state; 392850622dfSRandy Dunlapmy $in_doc_sect; 3931da177e4SLinus Torvalds 39448af606aSJani Nikula# Inline documentation state 39548af606aSJani Nikulause constant { 39648af606aSJani Nikula STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 39748af606aSJani Nikula STATE_INLINE_NAME => 1, # looking for member name (@foo:) 39848af606aSJani Nikula STATE_INLINE_TEXT => 2, # looking for member documentation 39948af606aSJani Nikula STATE_INLINE_END => 3, # done 40048af606aSJani Nikula STATE_INLINE_ERROR => 4, # error - Comment without header was found. 40148af606aSJani Nikula # Spit a warning as it's not 402a4c6ebedSDanilo Cesar Lemes de Paula # proper kernel-doc and ignore the rest. 40348af606aSJani Nikula}; 40448af606aSJani Nikulamy $inline_doc_state; 405a4c6ebedSDanilo Cesar Lemes de Paula 4061da177e4SLinus Torvalds#declaration types: can be 4071da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 4081da177e4SLinus Torvaldsmy $decl_type; 4091da177e4SLinus Torvalds 4101da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 4111da177e4SLinus Torvaldsmy $doc_end = '\*/'; 4121da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 41312ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 4141da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 415f624adefSJani Nikula# @params and a strictly limited set of supported section names 4168569de68SJonathan Corbetmy $doc_sect = $doc_com . 417ef00028bSJonathan Corbet '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)'; 41812ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 4191da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 42048af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$'; 42148af606aSJani Nikulamy $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)'; 42248af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$'; 42386ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 4241da177e4SLinus Torvalds 4251da177e4SLinus Torvaldsmy %parameterdescs; 4260b0f5f29SDaniel Vettermy %parameterdesc_start_lines; 4271da177e4SLinus Torvaldsmy @parameterlist; 4281da177e4SLinus Torvaldsmy %sections; 4291da177e4SLinus Torvaldsmy @sectionlist; 4300b0f5f29SDaniel Vettermy %section_start_lines; 431a1d94aa5SRandy Dunlapmy $sectcheck; 432a1d94aa5SRandy Dunlapmy $struct_actual; 4331da177e4SLinus Torvalds 4341da177e4SLinus Torvaldsmy $contents = ""; 4350b0f5f29SDaniel Vettermy $new_start_line = 0; 436f624adefSJani Nikula 437f624adefSJani Nikula# the canonical section names. see also $doc_sect above. 4381da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 4391da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 4401da177e4SLinus Torvaldsmy $section = $section_default; 4411da177e4SLinus Torvaldsmy $section_context = "Context"; 4424092bac7SYacine Belkadimy $section_return = "Return"; 4431da177e4SLinus Torvalds 4441da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 4451da177e4SLinus Torvalds 4461da177e4SLinus Torvaldsreset_state(); 4471da177e4SLinus Torvalds 4481da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) { 4491da177e4SLinus Torvalds my $cmd = shift @ARGV; 4501da177e4SLinus Torvalds if ($cmd eq "-html") { 4511da177e4SLinus Torvalds $output_mode = "html"; 4524d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_html; 4531da177e4SLinus Torvalds $blankline = $blankline_html; 4541b40c194SDan Luedtke } elsif ($cmd eq "-html5") { 4551b40c194SDan Luedtke $output_mode = "html5"; 4564d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_html5; 4571b40c194SDan Luedtke $blankline = $blankline_html5; 4581da177e4SLinus Torvalds } elsif ($cmd eq "-man") { 4591da177e4SLinus Torvalds $output_mode = "man"; 4604d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 4611da177e4SLinus Torvalds $blankline = $blankline_man; 4621da177e4SLinus Torvalds } elsif ($cmd eq "-text") { 4631da177e4SLinus Torvalds $output_mode = "text"; 4644d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_text; 4651da177e4SLinus Torvalds $blankline = $blankline_text; 466c0d1b6eeSJonathan Corbet } elsif ($cmd eq "-rst") { 467c0d1b6eeSJonathan Corbet $output_mode = "rst"; 468c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 469c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 4701da177e4SLinus Torvalds } elsif ($cmd eq "-docbook") { 4711da177e4SLinus Torvalds $output_mode = "xml"; 4724d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_xml; 4731da177e4SLinus Torvalds $blankline = $blankline_xml; 474eda603f6SJohannes Berg } elsif ($cmd eq "-list") { 475eda603f6SJohannes Berg $output_mode = "list"; 4764d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_list; 477eda603f6SJohannes Berg $blankline = $blankline_list; 4781da177e4SLinus Torvalds } elsif ($cmd eq "-gnome") { 4791da177e4SLinus Torvalds $output_mode = "gnome"; 4804d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_gnome; 4811da177e4SLinus Torvalds $blankline = $blankline_gnome; 4821da177e4SLinus Torvalds } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document 4831da177e4SLinus Torvalds $modulename = shift @ARGV; 4841da177e4SLinus Torvalds } elsif ($cmd eq "-function") { # to only output specific functions 485b6c3f456SJani Nikula $output_selection = OUTPUT_INCLUDE; 4861da177e4SLinus Torvalds $function = shift @ARGV; 4871da177e4SLinus Torvalds $function_table{$function} = 1; 488b6c3f456SJani Nikula } elsif ($cmd eq "-nofunction") { # output all except specific functions 489b6c3f456SJani Nikula $output_selection = OUTPUT_EXCLUDE; 4901da177e4SLinus Torvalds $function = shift @ARGV; 4911da177e4SLinus Torvalds $function_table{$function} = 1; 49286ae2e38SJani Nikula } elsif ($cmd eq "-export") { # only exported symbols 493b6c3f456SJani Nikula $output_selection = OUTPUT_EXPORTED; 494da9726ecSJani Nikula %function_table = (); 49586ae2e38SJani Nikula } elsif ($cmd eq "-internal") { # only non-exported symbols 496b6c3f456SJani Nikula $output_selection = OUTPUT_INTERNAL; 497da9726ecSJani Nikula %function_table = (); 49888c2b57dSJani Nikula } elsif ($cmd eq "-export-file") { 49988c2b57dSJani Nikula my $file = shift @ARGV; 50088c2b57dSJani Nikula push(@export_file_list, $file); 5011da177e4SLinus Torvalds } elsif ($cmd eq "-v") { 5021da177e4SLinus Torvalds $verbose = 1; 5031da177e4SLinus Torvalds } elsif (($cmd eq "-h") || ($cmd eq "--help")) { 5041da177e4SLinus Torvalds usage(); 5054b44595aSJohannes Berg } elsif ($cmd eq '-no-doc-sections') { 5064b44595aSJohannes Berg $no_doc_sections = 1; 5070b0f5f29SDaniel Vetter } elsif ($cmd eq '-enable-lineno') { 5080b0f5f29SDaniel Vetter $enable_lineno = 1; 509e946c43aSJohannes Berg } elsif ($cmd eq '-show-not-found') { 510e946c43aSJohannes Berg $show_not_found = 1; 5111da177e4SLinus Torvalds } 5121da177e4SLinus Torvalds} 5131da177e4SLinus Torvalds 5148484baaaSRandy Dunlap# continue execution near EOF; 5158484baaaSRandy Dunlap 51653f049faSBorislav Petkov# get kernel version from env 51753f049faSBorislav Petkovsub get_kernel_version() { 5181b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 51953f049faSBorislav Petkov 52053f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 52153f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 52253f049faSBorislav Petkov } 52353f049faSBorislav Petkov return $version; 52453f049faSBorislav Petkov} 5251da177e4SLinus Torvalds 5260b0f5f29SDaniel Vetter# 5270b0f5f29SDaniel Vettersub print_lineno { 5280b0f5f29SDaniel Vetter my $lineno = shift; 5290b0f5f29SDaniel Vetter if ($enable_lineno && defined($lineno)) { 5300b0f5f29SDaniel Vetter print "#define LINENO " . $lineno . "\n"; 5310b0f5f29SDaniel Vetter } 5320b0f5f29SDaniel Vetter} 5331da177e4SLinus Torvalds## 5341da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 5351da177e4SLinus Torvalds# 5361da177e4SLinus Torvaldssub dump_section { 53794dc7ad5SRandy Dunlap my $file = shift; 5381da177e4SLinus Torvalds my $name = shift; 5391da177e4SLinus Torvalds my $contents = join "\n", @_; 5401da177e4SLinus Torvalds 54113901ef2SJani Nikula if ($name =~ m/$type_param/) { 5421da177e4SLinus Torvalds $name = $1; 5431da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 544a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 5450b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 5460b0f5f29SDaniel Vetter $new_start_line = 0; 547ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 548ced69090SRandy Dunlap $name = "..."; 549ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 550a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 5510b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 5520b0f5f29SDaniel Vetter $new_start_line = 0; 5531da177e4SLinus Torvalds } else { 55494dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 55595b6be9dSJani Nikula # Only warn on user specified duplicate section names. 55695b6be9dSJani Nikula if ($name ne $section_default) { 55732217761SJani Nikula print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; 55832217761SJani Nikula ++$warnings; 55995b6be9dSJani Nikula } 56032217761SJani Nikula $sections{$name} .= $contents; 56132217761SJani Nikula } else { 5621da177e4SLinus Torvalds $sections{$name} = $contents; 5631da177e4SLinus Torvalds push @sectionlist, $name; 5640b0f5f29SDaniel Vetter $section_start_lines{$name} = $new_start_line; 5650b0f5f29SDaniel Vetter $new_start_line = 0; 5661da177e4SLinus Torvalds } 5671da177e4SLinus Torvalds } 56832217761SJani Nikula} 5691da177e4SLinus Torvalds 5701da177e4SLinus Torvalds## 571b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 572b112e0f7SJohannes Berg# 573b112e0f7SJohannes Bergsub dump_doc_section { 57494dc7ad5SRandy Dunlap my $file = shift; 575b112e0f7SJohannes Berg my $name = shift; 576b112e0f7SJohannes Berg my $contents = join "\n", @_; 577b112e0f7SJohannes Berg 5784b44595aSJohannes Berg if ($no_doc_sections) { 5794b44595aSJohannes Berg return; 5804b44595aSJohannes Berg } 5814b44595aSJohannes Berg 582b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 583b6c3f456SJani Nikula ($output_selection == OUTPUT_INCLUDE && 584b6c3f456SJani Nikula defined($function_table{$name})) || 585b6c3f456SJani Nikula ($output_selection == OUTPUT_EXCLUDE && 586b6c3f456SJani Nikula !defined($function_table{$name}))) 587b112e0f7SJohannes Berg { 58894dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 589b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 590b112e0f7SJohannes Berg 'sections' => \%sections, 591b112e0f7SJohannes Berg 'module' => $modulename, 592b6c3f456SJani Nikula 'content-only' => ($output_selection != OUTPUT_ALL), }); 593b112e0f7SJohannes Berg } 594b112e0f7SJohannes Berg} 595b112e0f7SJohannes Berg 596b112e0f7SJohannes Berg## 5971da177e4SLinus Torvalds# output function 5981da177e4SLinus Torvalds# 5991da177e4SLinus Torvalds# parameterdescs, a hash. 6001da177e4SLinus Torvalds# function => "function name" 6011da177e4SLinus Torvalds# parameterlist => @list of parameters 6021da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 6031da177e4SLinus Torvalds# sectionlist => @list of sections 604a21217daSRandy Dunlap# sections => %section descriptions 6051da177e4SLinus Torvalds# 6061da177e4SLinus Torvalds 6071da177e4SLinus Torvaldssub output_highlight { 6081da177e4SLinus Torvalds my $contents = join "\n",@_; 6091da177e4SLinus Torvalds my $line; 6101da177e4SLinus Torvalds 6111da177e4SLinus Torvalds# DEBUG 6121da177e4SLinus Torvalds# if (!defined $contents) { 6131da177e4SLinus Torvalds# use Carp; 6141da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 6151da177e4SLinus Torvalds# } 6161da177e4SLinus Torvalds 6171b40c194SDan Luedtke if ($output_mode eq "html" || $output_mode eq "html5" || 6181b40c194SDan Luedtke $output_mode eq "xml") { 6196b5b55f6SRandy Dunlap $contents = local_unescape($contents); 6206b5b55f6SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 6212b35f4d9SRandy Dunlap $contents =~ s/\\\\\\/\&/g; 6226b5b55f6SRandy Dunlap } 6233eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 6241da177e4SLinus Torvalds eval $dohighlight; 6251da177e4SLinus Torvalds die $@ if $@; 6263eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 6273eb014a1SRandy Dunlap 6281b40c194SDan Luedtke# strip whitespaces when generating html5 6291b40c194SDan Luedtke if ($output_mode eq "html5") { 6301b40c194SDan Luedtke $contents =~ s/^\s+//; 6311b40c194SDan Luedtke $contents =~ s/\s+$//; 6321b40c194SDan Luedtke } 6331da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 63412ae6779SDaniel Santos if (! $output_preformatted) { 63512ae6779SDaniel Santos $line =~ s/^\s*//; 63612ae6779SDaniel Santos } 6371da177e4SLinus Torvalds if ($line eq ""){ 638e314ba31SDaniel Santos if (! $output_preformatted) { 6396b5b55f6SRandy Dunlap print $lineprefix, local_unescape($blankline); 640e314ba31SDaniel Santos } 6411da177e4SLinus Torvalds } else { 6421da177e4SLinus Torvalds $line =~ s/\\\\\\/\&/g; 643cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 644cdccb316SRandy Dunlap print "\\&$line"; 645cdccb316SRandy Dunlap } else { 6461da177e4SLinus Torvalds print $lineprefix, $line; 6471da177e4SLinus Torvalds } 648cdccb316SRandy Dunlap } 6491da177e4SLinus Torvalds print "\n"; 6501da177e4SLinus Torvalds } 6511da177e4SLinus Torvalds} 6521da177e4SLinus Torvalds 6531da177e4SLinus Torvalds# output sections in html 6541da177e4SLinus Torvaldssub output_section_html(%) { 6551da177e4SLinus Torvalds my %args = %{$_[0]}; 6561da177e4SLinus Torvalds my $section; 6571da177e4SLinus Torvalds 6581da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6591da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 6601da177e4SLinus Torvalds print "<blockquote>\n"; 6611da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6621da177e4SLinus Torvalds print "</blockquote>\n"; 6631da177e4SLinus Torvalds } 6641da177e4SLinus Torvalds} 6651da177e4SLinus Torvalds 6661da177e4SLinus Torvalds# output enum in html 6671da177e4SLinus Torvaldssub output_enum_html(%) { 6681da177e4SLinus Torvalds my %args = %{$_[0]}; 6691da177e4SLinus Torvalds my ($parameter); 6701da177e4SLinus Torvalds my $count; 6711da177e4SLinus Torvalds print "<h2>enum " . $args{'enum'} . "</h2>\n"; 6721da177e4SLinus Torvalds 6731da177e4SLinus Torvalds print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; 6741da177e4SLinus Torvalds $count = 0; 6751da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6761da177e4SLinus Torvalds print " <b>" . $parameter . "</b>"; 6771da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 6781da177e4SLinus Torvalds $count++; 6791da177e4SLinus Torvalds print ",\n"; 6801da177e4SLinus Torvalds } 6811da177e4SLinus Torvalds print "<br>"; 6821da177e4SLinus Torvalds } 6831da177e4SLinus Torvalds print "};<br>\n"; 6841da177e4SLinus Torvalds 6851da177e4SLinus Torvalds print "<h3>Constants</h3>\n"; 6861da177e4SLinus Torvalds print "<dl>\n"; 6871da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6881da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 6891da177e4SLinus Torvalds print "<dd>"; 6901da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter}); 6911da177e4SLinus Torvalds } 6921da177e4SLinus Torvalds print "</dl>\n"; 6931da177e4SLinus Torvalds output_section_html(@_); 6941da177e4SLinus Torvalds print "<hr>\n"; 6951da177e4SLinus Torvalds} 6961da177e4SLinus Torvalds 697d28bee0cSRandy Dunlap# output typedef in html 6981da177e4SLinus Torvaldssub output_typedef_html(%) { 6991da177e4SLinus Torvalds my %args = %{$_[0]}; 7001da177e4SLinus Torvalds my ($parameter); 7011da177e4SLinus Torvalds my $count; 7021da177e4SLinus Torvalds print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; 7031da177e4SLinus Torvalds 7041da177e4SLinus Torvalds print "<b>typedef " . $args{'typedef'} . "</b>\n"; 7051da177e4SLinus Torvalds output_section_html(@_); 7061da177e4SLinus Torvalds print "<hr>\n"; 7071da177e4SLinus Torvalds} 7081da177e4SLinus Torvalds 7091da177e4SLinus Torvalds# output struct in html 7101da177e4SLinus Torvaldssub output_struct_html(%) { 7111da177e4SLinus Torvalds my %args = %{$_[0]}; 7121da177e4SLinus Torvalds my ($parameter); 7131da177e4SLinus Torvalds 714262d9b01SRandy Dunlap print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; 7151da177e4SLinus Torvalds print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; 7161da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7171da177e4SLinus Torvalds if ($parameter =~ /^#/) { 7181da177e4SLinus Torvalds print "$parameter<br>\n"; 7191da177e4SLinus Torvalds next; 7201da177e4SLinus Torvalds } 7211da177e4SLinus Torvalds my $parameter_name = $parameter; 7221da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7231da177e4SLinus Torvalds 7241da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7251da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 7261da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 7271da177e4SLinus Torvalds # pointer-to-function 7283eb014a1SRandy Dunlap print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; 7291da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 7303eb014a1SRandy Dunlap # bitfield 7313eb014a1SRandy Dunlap print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; 7321da177e4SLinus Torvalds } else { 7333eb014a1SRandy Dunlap print " <i>$type</i> <b>$parameter</b>;<br>\n"; 7341da177e4SLinus Torvalds } 7351da177e4SLinus Torvalds } 7361da177e4SLinus Torvalds print "};<br>\n"; 7371da177e4SLinus Torvalds 7381da177e4SLinus Torvalds print "<h3>Members</h3>\n"; 7391da177e4SLinus Torvalds print "<dl>\n"; 7401da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7411da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 7421da177e4SLinus Torvalds 7431da177e4SLinus Torvalds my $parameter_name = $parameter; 7441da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7451da177e4SLinus Torvalds 7461da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7471da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 7481da177e4SLinus Torvalds print "<dd>"; 7491da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7501da177e4SLinus Torvalds } 7511da177e4SLinus Torvalds print "</dl>\n"; 7521da177e4SLinus Torvalds output_section_html(@_); 7531da177e4SLinus Torvalds print "<hr>\n"; 7541da177e4SLinus Torvalds} 7551da177e4SLinus Torvalds 7561da177e4SLinus Torvalds# output function in html 7571da177e4SLinus Torvaldssub output_function_html(%) { 7581da177e4SLinus Torvalds my %args = %{$_[0]}; 7591da177e4SLinus Torvalds my ($parameter, $section); 7601da177e4SLinus Torvalds my $count; 7611da177e4SLinus Torvalds 762262d9b01SRandy Dunlap print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; 7631da177e4SLinus Torvalds print "<i>" . $args{'functiontype'} . "</i>\n"; 7641da177e4SLinus Torvalds print "<b>" . $args{'function'} . "</b>\n"; 7651da177e4SLinus Torvalds print "("; 7661da177e4SLinus Torvalds $count = 0; 7671da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7681da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 7691da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 7701da177e4SLinus Torvalds # pointer-to-function 7711da177e4SLinus Torvalds print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; 7721da177e4SLinus Torvalds } else { 7731da177e4SLinus Torvalds print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; 7741da177e4SLinus Torvalds } 7751da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 7761da177e4SLinus Torvalds $count++; 7771da177e4SLinus Torvalds print ",\n"; 7781da177e4SLinus Torvalds } 7791da177e4SLinus Torvalds } 7801da177e4SLinus Torvalds print ")\n"; 7811da177e4SLinus Torvalds 7821da177e4SLinus Torvalds print "<h3>Arguments</h3>\n"; 7831da177e4SLinus Torvalds print "<dl>\n"; 7841da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7851da177e4SLinus Torvalds my $parameter_name = $parameter; 7861da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7871da177e4SLinus Torvalds 7881da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7891da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 7901da177e4SLinus Torvalds print "<dd>"; 7911da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7921da177e4SLinus Torvalds } 7931da177e4SLinus Torvalds print "</dl>\n"; 7941da177e4SLinus Torvalds output_section_html(@_); 7951da177e4SLinus Torvalds print "<hr>\n"; 7961da177e4SLinus Torvalds} 7971da177e4SLinus Torvalds 798b112e0f7SJohannes Berg# output DOC: block header in html 799b112e0f7SJohannes Bergsub output_blockhead_html(%) { 8001da177e4SLinus Torvalds my %args = %{$_[0]}; 8011da177e4SLinus Torvalds my ($parameter, $section); 8021da177e4SLinus Torvalds my $count; 8031da177e4SLinus Torvalds 8041da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 8051da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 8061da177e4SLinus Torvalds print "<ul>\n"; 8071da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 8081da177e4SLinus Torvalds print "</ul>\n"; 8091da177e4SLinus Torvalds } 8101da177e4SLinus Torvalds print "<hr>\n"; 8111da177e4SLinus Torvalds} 8121da177e4SLinus Torvalds 8131b40c194SDan Luedtke# output sections in html5 8141b40c194SDan Luedtkesub output_section_html5(%) { 8151b40c194SDan Luedtke my %args = %{$_[0]}; 8161b40c194SDan Luedtke my $section; 8171b40c194SDan Luedtke 8181b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 8191b40c194SDan Luedtke print "<section>\n"; 8201b40c194SDan Luedtke print "<h1>$section</h1>\n"; 8211b40c194SDan Luedtke print "<p>\n"; 8221b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 8231b40c194SDan Luedtke print "</p>\n"; 8241b40c194SDan Luedtke print "</section>\n"; 8251b40c194SDan Luedtke } 8261b40c194SDan Luedtke} 8271b40c194SDan Luedtke 8281b40c194SDan Luedtke# output enum in html5 8291b40c194SDan Luedtkesub output_enum_html5(%) { 8301b40c194SDan Luedtke my %args = %{$_[0]}; 8311b40c194SDan Luedtke my ($parameter); 8321b40c194SDan Luedtke my $count; 8331b40c194SDan Luedtke my $html5id; 8341b40c194SDan Luedtke 8351b40c194SDan Luedtke $html5id = $args{'enum'}; 8361b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8371b40c194SDan Luedtke print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; 8381b40c194SDan Luedtke print "<h1>enum " . $args{'enum'} . "</h1>\n"; 8391b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8401b40c194SDan Luedtke print "<li>"; 8411b40c194SDan Luedtke print "<span class=\"keyword\">enum</span> "; 8421b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; 8431b40c194SDan Luedtke print "</li>\n"; 8441b40c194SDan Luedtke $count = 0; 8451b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8461b40c194SDan Luedtke print "<li class=\"indent\">"; 8471b40c194SDan Luedtke print "<span class=\"param\">" . $parameter . "</span>"; 8481b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 8491b40c194SDan Luedtke $count++; 8501b40c194SDan Luedtke print ","; 8511b40c194SDan Luedtke } 8521b40c194SDan Luedtke print "</li>\n"; 8531b40c194SDan Luedtke } 8541b40c194SDan Luedtke print "<li>};</li>\n"; 8551b40c194SDan Luedtke print "</ol>\n"; 8561b40c194SDan Luedtke 8571b40c194SDan Luedtke print "<section>\n"; 8581b40c194SDan Luedtke print "<h1>Constants</h1>\n"; 8591b40c194SDan Luedtke print "<dl>\n"; 8601b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8611b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 8621b40c194SDan Luedtke print "<dd>"; 8631b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter}); 8641b40c194SDan Luedtke print "</dd>\n"; 8651b40c194SDan Luedtke } 8661b40c194SDan Luedtke print "</dl>\n"; 8671b40c194SDan Luedtke print "</section>\n"; 8681b40c194SDan Luedtke output_section_html5(@_); 8691b40c194SDan Luedtke print "</article>\n"; 8701b40c194SDan Luedtke} 8711b40c194SDan Luedtke 8721b40c194SDan Luedtke# output typedef in html5 8731b40c194SDan Luedtkesub output_typedef_html5(%) { 8741b40c194SDan Luedtke my %args = %{$_[0]}; 8751b40c194SDan Luedtke my ($parameter); 8761b40c194SDan Luedtke my $count; 8771b40c194SDan Luedtke my $html5id; 8781b40c194SDan Luedtke 8791b40c194SDan Luedtke $html5id = $args{'typedef'}; 8801b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8811b40c194SDan Luedtke print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; 8821b40c194SDan Luedtke print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; 8831b40c194SDan Luedtke 8841b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8851b40c194SDan Luedtke print "<li>"; 8861b40c194SDan Luedtke print "<span class=\"keyword\">typedef</span> "; 8871b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; 8881b40c194SDan Luedtke print "</li>\n"; 8891b40c194SDan Luedtke print "</ol>\n"; 8901b40c194SDan Luedtke output_section_html5(@_); 8911b40c194SDan Luedtke print "</article>\n"; 8921b40c194SDan Luedtke} 8931b40c194SDan Luedtke 8941b40c194SDan Luedtke# output struct in html5 8951b40c194SDan Luedtkesub output_struct_html5(%) { 8961b40c194SDan Luedtke my %args = %{$_[0]}; 8971b40c194SDan Luedtke my ($parameter); 8981b40c194SDan Luedtke my $html5id; 8991b40c194SDan Luedtke 9001b40c194SDan Luedtke $html5id = $args{'struct'}; 9011b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 9021b40c194SDan Luedtke print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n"; 9031b40c194SDan Luedtke print "<hgroup>\n"; 9041b40c194SDan Luedtke print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>"; 9051b40c194SDan Luedtke print "<h2>". $args{'purpose'} . "</h2>\n"; 9061b40c194SDan Luedtke print "</hgroup>\n"; 9071b40c194SDan Luedtke print "<ol class=\"code\">\n"; 9081b40c194SDan Luedtke print "<li>"; 9091b40c194SDan Luedtke print "<span class=\"type\">" . $args{'type'} . "</span> "; 9101b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'struct'} . "</span> {"; 9111b40c194SDan Luedtke print "</li>\n"; 9121b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9131b40c194SDan Luedtke print "<li class=\"indent\">"; 9141b40c194SDan Luedtke if ($parameter =~ /^#/) { 9151b40c194SDan Luedtke print "<span class=\"param\">" . $parameter ."</span>\n"; 9161b40c194SDan Luedtke print "</li>\n"; 9171b40c194SDan Luedtke next; 9181b40c194SDan Luedtke } 9191b40c194SDan Luedtke my $parameter_name = $parameter; 9201b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 9211b40c194SDan Luedtke 9221b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 9231b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 9241b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 9251b40c194SDan Luedtke # pointer-to-function 9261b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 9271b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9281b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 9291b40c194SDan Luedtke print "(<span class=\"args\">$2</span>);"; 9301b40c194SDan Luedtke } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 9311b40c194SDan Luedtke # bitfield 9321b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 9331b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9341b40c194SDan Luedtke print "<span class=\"bits\">$2</span>;"; 9351b40c194SDan Luedtke } else { 9361b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 9371b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>;"; 9381b40c194SDan Luedtke } 9391b40c194SDan Luedtke print "</li>\n"; 9401b40c194SDan Luedtke } 9411b40c194SDan Luedtke print "<li>};</li>\n"; 9421b40c194SDan Luedtke print "</ol>\n"; 9431b40c194SDan Luedtke 9441b40c194SDan Luedtke print "<section>\n"; 9451b40c194SDan Luedtke print "<h1>Members</h1>\n"; 9461b40c194SDan Luedtke print "<dl>\n"; 9471b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9481b40c194SDan Luedtke ($parameter =~ /^#/) && next; 9491b40c194SDan Luedtke 9501b40c194SDan Luedtke my $parameter_name = $parameter; 9511b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 9521b40c194SDan Luedtke 9531b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 9541b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 9551b40c194SDan Luedtke print "<dd>"; 9561b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 9571b40c194SDan Luedtke print "</dd>\n"; 9581b40c194SDan Luedtke } 9591b40c194SDan Luedtke print "</dl>\n"; 9601b40c194SDan Luedtke print "</section>\n"; 9611b40c194SDan Luedtke output_section_html5(@_); 9621b40c194SDan Luedtke print "</article>\n"; 9631b40c194SDan Luedtke} 9641b40c194SDan Luedtke 9651b40c194SDan Luedtke# output function in html5 9661b40c194SDan Luedtkesub output_function_html5(%) { 9671b40c194SDan Luedtke my %args = %{$_[0]}; 9681b40c194SDan Luedtke my ($parameter, $section); 9691b40c194SDan Luedtke my $count; 9701b40c194SDan Luedtke my $html5id; 9711b40c194SDan Luedtke 9721b40c194SDan Luedtke $html5id = $args{'function'}; 9731b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 9741b40c194SDan Luedtke print "<article class=\"function\" id=\"func:". $html5id . "\">\n"; 9751b40c194SDan Luedtke print "<hgroup>\n"; 9761b40c194SDan Luedtke print "<h1>" . $args{'function'} . "</h1>"; 9771b40c194SDan Luedtke print "<h2>" . $args{'purpose'} . "</h2>\n"; 9781b40c194SDan Luedtke print "</hgroup>\n"; 9791b40c194SDan Luedtke print "<ol class=\"code\">\n"; 9801b40c194SDan Luedtke print "<li>"; 9811b40c194SDan Luedtke print "<span class=\"type\">" . $args{'functiontype'} . "</span> "; 9821b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'function'} . "</span> ("; 9831b40c194SDan Luedtke print "</li>"; 9841b40c194SDan Luedtke $count = 0; 9851b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9861b40c194SDan Luedtke print "<li class=\"indent\">"; 9871b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 9881b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 9891b40c194SDan Luedtke # pointer-to-function 9901b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 9911b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9921b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 9931b40c194SDan Luedtke print "(<span class=\"args\">$2</span>)"; 9941b40c194SDan Luedtke } else { 9951b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 9961b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9971b40c194SDan Luedtke } 9981b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 9991b40c194SDan Luedtke $count++; 10001b40c194SDan Luedtke print ","; 10011b40c194SDan Luedtke } 10021b40c194SDan Luedtke print "</li>\n"; 10031b40c194SDan Luedtke } 10041b40c194SDan Luedtke print "<li>)</li>\n"; 10051b40c194SDan Luedtke print "</ol>\n"; 10061b40c194SDan Luedtke 10071b40c194SDan Luedtke print "<section>\n"; 10081b40c194SDan Luedtke print "<h1>Arguments</h1>\n"; 10091b40c194SDan Luedtke print "<p>\n"; 10101b40c194SDan Luedtke print "<dl>\n"; 10111b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 10121b40c194SDan Luedtke my $parameter_name = $parameter; 10131b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 10141b40c194SDan Luedtke 10151b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 10161b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 10171b40c194SDan Luedtke print "<dd>"; 10181b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 10191b40c194SDan Luedtke print "</dd>\n"; 10201b40c194SDan Luedtke } 10211b40c194SDan Luedtke print "</dl>\n"; 10221b40c194SDan Luedtke print "</section>\n"; 10231b40c194SDan Luedtke output_section_html5(@_); 10241b40c194SDan Luedtke print "</article>\n"; 10251b40c194SDan Luedtke} 10261b40c194SDan Luedtke 10271b40c194SDan Luedtke# output DOC: block header in html5 10281b40c194SDan Luedtkesub output_blockhead_html5(%) { 10291b40c194SDan Luedtke my %args = %{$_[0]}; 10301b40c194SDan Luedtke my ($parameter, $section); 10311b40c194SDan Luedtke my $count; 10321b40c194SDan Luedtke my $html5id; 10331b40c194SDan Luedtke 10341b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 10351b40c194SDan Luedtke $html5id = $section; 10361b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 10371b40c194SDan Luedtke print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n"; 10381b40c194SDan Luedtke print "<h1>$section</h1>\n"; 10391b40c194SDan Luedtke print "<p>\n"; 10401b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 10411b40c194SDan Luedtke print "</p>\n"; 10421b40c194SDan Luedtke } 10431b40c194SDan Luedtke print "</article>\n"; 10441b40c194SDan Luedtke} 10451b40c194SDan Luedtke 10461da177e4SLinus Torvaldssub output_section_xml(%) { 10471da177e4SLinus Torvalds my %args = %{$_[0]}; 10481da177e4SLinus Torvalds my $section; 10491da177e4SLinus Torvalds # print out each section 10501da177e4SLinus Torvalds $lineprefix=" "; 10511da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1052c73894c1SRich Walker print "<refsect1>\n"; 1053c73894c1SRich Walker print "<title>$section</title>\n"; 10541da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 1055c73894c1SRich Walker print "<informalexample><programlisting>\n"; 1056e314ba31SDaniel Santos $output_preformatted = 1; 1057c73894c1SRich Walker } else { 1058c73894c1SRich Walker print "<para>\n"; 10591da177e4SLinus Torvalds } 10601da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1061e314ba31SDaniel Santos $output_preformatted = 0; 10621da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 1063c73894c1SRich Walker print "</programlisting></informalexample>\n"; 1064c73894c1SRich Walker } else { 1065c73894c1SRich Walker print "</para>\n"; 10661da177e4SLinus Torvalds } 1067c73894c1SRich Walker print "</refsect1>\n"; 10681da177e4SLinus Torvalds } 10691da177e4SLinus Torvalds} 10701da177e4SLinus Torvalds 10711da177e4SLinus Torvalds# output function in XML DocBook 10721da177e4SLinus Torvaldssub output_function_xml(%) { 10731da177e4SLinus Torvalds my %args = %{$_[0]}; 10741da177e4SLinus Torvalds my ($parameter, $section); 10751da177e4SLinus Torvalds my $count; 10761da177e4SLinus Torvalds my $id; 10771da177e4SLinus Torvalds 10781da177e4SLinus Torvalds $id = "API-" . $args{'function'}; 10791da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 10801da177e4SLinus Torvalds 10815449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 10828b0c2d98SMartin Waitz print "<refentryinfo>\n"; 10838b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 10848b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 10858b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 10868b0c2d98SMartin Waitz print "</refentryinfo>\n"; 10871da177e4SLinus Torvalds print "<refmeta>\n"; 10885449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; 10898b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 10900366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 10911da177e4SLinus Torvalds print "</refmeta>\n"; 10921da177e4SLinus Torvalds print "<refnamediv>\n"; 10931da177e4SLinus Torvalds print " <refname>" . $args{'function'} . "</refname>\n"; 10941da177e4SLinus Torvalds print " <refpurpose>\n"; 10951da177e4SLinus Torvalds print " "; 10961da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 10971da177e4SLinus Torvalds print " </refpurpose>\n"; 10981da177e4SLinus Torvalds print "</refnamediv>\n"; 10991da177e4SLinus Torvalds 11001da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 11011da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 11021da177e4SLinus Torvalds print " <funcsynopsis><funcprototype>\n"; 11031da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 11041da177e4SLinus Torvalds print "<function>" . $args{'function'} . " </function></funcdef>\n"; 11051da177e4SLinus Torvalds 11061da177e4SLinus Torvalds $count = 0; 11071da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 11081da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11091da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 11101da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 11111da177e4SLinus Torvalds # pointer-to-function 11121da177e4SLinus Torvalds print " <paramdef>$1<parameter>$parameter</parameter>)\n"; 11131da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 11141da177e4SLinus Torvalds } else { 11151da177e4SLinus Torvalds print " <paramdef>" . $type; 11161da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 11171da177e4SLinus Torvalds } 11181da177e4SLinus Torvalds } 11191da177e4SLinus Torvalds } else { 11206013d544SMartin Waitz print " <void/>\n"; 11211da177e4SLinus Torvalds } 11221da177e4SLinus Torvalds print " </funcprototype></funcsynopsis>\n"; 11231da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 11241da177e4SLinus Torvalds 11251da177e4SLinus Torvalds # print parameters 11261da177e4SLinus Torvalds print "<refsect1>\n <title>Arguments</title>\n"; 11271da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 11281da177e4SLinus Torvalds print " <variablelist>\n"; 11291da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11301da177e4SLinus Torvalds my $parameter_name = $parameter; 11311da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11321da177e4SLinus Torvalds 11331da177e4SLinus Torvalds print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; 11341da177e4SLinus Torvalds print " <listitem>\n <para>\n"; 11351da177e4SLinus Torvalds $lineprefix=" "; 11361da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 11371da177e4SLinus Torvalds print " </para>\n </listitem>\n </varlistentry>\n"; 11381da177e4SLinus Torvalds } 11391da177e4SLinus Torvalds print " </variablelist>\n"; 11401da177e4SLinus Torvalds } else { 11411da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 11421da177e4SLinus Torvalds } 11431da177e4SLinus Torvalds print "</refsect1>\n"; 11441da177e4SLinus Torvalds 11451da177e4SLinus Torvalds output_section_xml(@_); 11461da177e4SLinus Torvalds print "</refentry>\n\n"; 11471da177e4SLinus Torvalds} 11481da177e4SLinus Torvalds 11491da177e4SLinus Torvalds# output struct in XML DocBook 11501da177e4SLinus Torvaldssub output_struct_xml(%) { 11511da177e4SLinus Torvalds my %args = %{$_[0]}; 11521da177e4SLinus Torvalds my ($parameter, $section); 11531da177e4SLinus Torvalds my $id; 11541da177e4SLinus Torvalds 11551da177e4SLinus Torvalds $id = "API-struct-" . $args{'struct'}; 11561da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 11571da177e4SLinus Torvalds 11585449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 11598b0c2d98SMartin Waitz print "<refentryinfo>\n"; 11608b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 11618b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 11628b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 11638b0c2d98SMartin Waitz print "</refentryinfo>\n"; 11641da177e4SLinus Torvalds print "<refmeta>\n"; 11655449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; 11668b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 11670366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 11681da177e4SLinus Torvalds print "</refmeta>\n"; 11691da177e4SLinus Torvalds print "<refnamediv>\n"; 11701da177e4SLinus Torvalds print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; 11711da177e4SLinus Torvalds print " <refpurpose>\n"; 11721da177e4SLinus Torvalds print " "; 11731da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 11741da177e4SLinus Torvalds print " </refpurpose>\n"; 11751da177e4SLinus Torvalds print "</refnamediv>\n"; 11761da177e4SLinus Torvalds 11771da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 11781da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 11791da177e4SLinus Torvalds print " <programlisting>\n"; 11801da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 11811da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11821da177e4SLinus Torvalds if ($parameter =~ /^#/) { 11832b35f4d9SRandy Dunlap my $prm = $parameter; 11842b35f4d9SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 11852b35f4d9SRandy Dunlap # This allows us to have #define macros interspersed in a struct. 11862b35f4d9SRandy Dunlap $prm =~ s/\\\\\\/\&/g; 11872b35f4d9SRandy Dunlap print "$prm\n"; 11881da177e4SLinus Torvalds next; 11891da177e4SLinus Torvalds } 11901da177e4SLinus Torvalds 11911da177e4SLinus Torvalds my $parameter_name = $parameter; 11921da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11931da177e4SLinus Torvalds 11941da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 11951da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 11961da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 11971da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 11981da177e4SLinus Torvalds # pointer-to-function 11991da177e4SLinus Torvalds print " $1 $parameter) ($2);\n"; 12001da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 120151f5a0c8SRandy Dunlap # bitfield 12021da177e4SLinus Torvalds print " $1 $parameter$2;\n"; 12031da177e4SLinus Torvalds } else { 12041da177e4SLinus Torvalds print " " . $type . " " . $parameter . ";\n"; 12051da177e4SLinus Torvalds } 12061da177e4SLinus Torvalds } 12071da177e4SLinus Torvalds print "};"; 12081da177e4SLinus Torvalds print " </programlisting>\n"; 12091da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 12101da177e4SLinus Torvalds 12111da177e4SLinus Torvalds print " <refsect1>\n"; 12121da177e4SLinus Torvalds print " <title>Members</title>\n"; 12131da177e4SLinus Torvalds 121439f00c08SRandy Dunlap if ($#{$args{'parameterlist'}} >= 0) { 12151da177e4SLinus Torvalds print " <variablelist>\n"; 12161da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12171da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 12181da177e4SLinus Torvalds 12191da177e4SLinus Torvalds my $parameter_name = $parameter; 12201da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12211da177e4SLinus Torvalds 12221da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 12231da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 12241da177e4SLinus Torvalds print " <varlistentry>"; 12251da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 12261da177e4SLinus Torvalds print " <listitem><para>\n"; 12271da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 12281da177e4SLinus Torvalds print " </para></listitem>\n"; 12291da177e4SLinus Torvalds print " </varlistentry>\n"; 12301da177e4SLinus Torvalds } 12311da177e4SLinus Torvalds print " </variablelist>\n"; 123239f00c08SRandy Dunlap } else { 123339f00c08SRandy Dunlap print " <para>\n None\n </para>\n"; 123439f00c08SRandy Dunlap } 12351da177e4SLinus Torvalds print " </refsect1>\n"; 12361da177e4SLinus Torvalds 12371da177e4SLinus Torvalds output_section_xml(@_); 12381da177e4SLinus Torvalds 12391da177e4SLinus Torvalds print "</refentry>\n\n"; 12401da177e4SLinus Torvalds} 12411da177e4SLinus Torvalds 12421da177e4SLinus Torvalds# output enum in XML DocBook 12431da177e4SLinus Torvaldssub output_enum_xml(%) { 12441da177e4SLinus Torvalds my %args = %{$_[0]}; 12451da177e4SLinus Torvalds my ($parameter, $section); 12461da177e4SLinus Torvalds my $count; 12471da177e4SLinus Torvalds my $id; 12481da177e4SLinus Torvalds 12491da177e4SLinus Torvalds $id = "API-enum-" . $args{'enum'}; 12501da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12511da177e4SLinus Torvalds 12525449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 12538b0c2d98SMartin Waitz print "<refentryinfo>\n"; 12548b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 12558b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 12568b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 12578b0c2d98SMartin Waitz print "</refentryinfo>\n"; 12581da177e4SLinus Torvalds print "<refmeta>\n"; 12595449bc94SPavel Pisa print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; 12608b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 12610366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 12621da177e4SLinus Torvalds print "</refmeta>\n"; 12631da177e4SLinus Torvalds print "<refnamediv>\n"; 12641da177e4SLinus Torvalds print " <refname>enum " . $args{'enum'} . "</refname>\n"; 12651da177e4SLinus Torvalds print " <refpurpose>\n"; 12661da177e4SLinus Torvalds print " "; 12671da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 12681da177e4SLinus Torvalds print " </refpurpose>\n"; 12691da177e4SLinus Torvalds print "</refnamediv>\n"; 12701da177e4SLinus Torvalds 12711da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 12721da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 12731da177e4SLinus Torvalds print " <programlisting>\n"; 12741da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 12751da177e4SLinus Torvalds $count = 0; 12761da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12771da177e4SLinus Torvalds print " $parameter"; 12781da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 12791da177e4SLinus Torvalds $count++; 12801da177e4SLinus Torvalds print ","; 12811da177e4SLinus Torvalds } 12821da177e4SLinus Torvalds print "\n"; 12831da177e4SLinus Torvalds } 12841da177e4SLinus Torvalds print "};"; 12851da177e4SLinus Torvalds print " </programlisting>\n"; 12861da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 12871da177e4SLinus Torvalds 12881da177e4SLinus Torvalds print "<refsect1>\n"; 12891da177e4SLinus Torvalds print " <title>Constants</title>\n"; 12901da177e4SLinus Torvalds print " <variablelist>\n"; 12911da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12921da177e4SLinus Torvalds my $parameter_name = $parameter; 12931da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12941da177e4SLinus Torvalds 12951da177e4SLinus Torvalds print " <varlistentry>"; 12961da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 12971da177e4SLinus Torvalds print " <listitem><para>\n"; 12981da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 12991da177e4SLinus Torvalds print " </para></listitem>\n"; 13001da177e4SLinus Torvalds print " </varlistentry>\n"; 13011da177e4SLinus Torvalds } 13021da177e4SLinus Torvalds print " </variablelist>\n"; 13031da177e4SLinus Torvalds print "</refsect1>\n"; 13041da177e4SLinus Torvalds 13051da177e4SLinus Torvalds output_section_xml(@_); 13061da177e4SLinus Torvalds 13071da177e4SLinus Torvalds print "</refentry>\n\n"; 13081da177e4SLinus Torvalds} 13091da177e4SLinus Torvalds 13101da177e4SLinus Torvalds# output typedef in XML DocBook 13111da177e4SLinus Torvaldssub output_typedef_xml(%) { 13121da177e4SLinus Torvalds my %args = %{$_[0]}; 13131da177e4SLinus Torvalds my ($parameter, $section); 13141da177e4SLinus Torvalds my $id; 13151da177e4SLinus Torvalds 13161da177e4SLinus Torvalds $id = "API-typedef-" . $args{'typedef'}; 13171da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13181da177e4SLinus Torvalds 13195449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 13208b0c2d98SMartin Waitz print "<refentryinfo>\n"; 13218b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 13228b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 13238b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 13248b0c2d98SMartin Waitz print "</refentryinfo>\n"; 13251da177e4SLinus Torvalds print "<refmeta>\n"; 13265449bc94SPavel Pisa print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; 13278b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 13281da177e4SLinus Torvalds print "</refmeta>\n"; 13291da177e4SLinus Torvalds print "<refnamediv>\n"; 13301da177e4SLinus Torvalds print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; 13311da177e4SLinus Torvalds print " <refpurpose>\n"; 13321da177e4SLinus Torvalds print " "; 13331da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 13341da177e4SLinus Torvalds print " </refpurpose>\n"; 13351da177e4SLinus Torvalds print "</refnamediv>\n"; 13361da177e4SLinus Torvalds 13371da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 13381da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 13391da177e4SLinus Torvalds print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; 13401da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 13411da177e4SLinus Torvalds 13421da177e4SLinus Torvalds output_section_xml(@_); 13431da177e4SLinus Torvalds 13441da177e4SLinus Torvalds print "</refentry>\n\n"; 13451da177e4SLinus Torvalds} 13461da177e4SLinus Torvalds 13471da177e4SLinus Torvalds# output in XML DocBook 1348b112e0f7SJohannes Bergsub output_blockhead_xml(%) { 13491da177e4SLinus Torvalds my %args = %{$_[0]}; 13501da177e4SLinus Torvalds my ($parameter, $section); 13511da177e4SLinus Torvalds my $count; 13521da177e4SLinus Torvalds 13531da177e4SLinus Torvalds my $id = $args{'module'}; 13541da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13551da177e4SLinus Torvalds 13561da177e4SLinus Torvalds # print out each section 13571da177e4SLinus Torvalds $lineprefix=" "; 13581da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1359b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1360b112e0f7SJohannes Berg print "<refsect1>\n <title>$section</title>\n"; 1361b112e0f7SJohannes Berg } 13621da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13631da177e4SLinus Torvalds print "<example><para>\n"; 1364e314ba31SDaniel Santos $output_preformatted = 1; 1365b112e0f7SJohannes Berg } else { 1366b112e0f7SJohannes Berg print "<para>\n"; 13671da177e4SLinus Torvalds } 13681da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1369e314ba31SDaniel Santos $output_preformatted = 0; 13701da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13711da177e4SLinus Torvalds print "</para></example>\n"; 1372b112e0f7SJohannes Berg } else { 1373b112e0f7SJohannes Berg print "</para>"; 13741da177e4SLinus Torvalds } 1375b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1376b112e0f7SJohannes Berg print "\n</refsect1>\n"; 1377b112e0f7SJohannes Berg } 13781da177e4SLinus Torvalds } 13791da177e4SLinus Torvalds 13801da177e4SLinus Torvalds print "\n\n"; 13811da177e4SLinus Torvalds} 13821da177e4SLinus Torvalds 13831da177e4SLinus Torvalds# output in XML DocBook 13841da177e4SLinus Torvaldssub output_function_gnome { 13851da177e4SLinus Torvalds my %args = %{$_[0]}; 13861da177e4SLinus Torvalds my ($parameter, $section); 13871da177e4SLinus Torvalds my $count; 13881da177e4SLinus Torvalds my $id; 13891da177e4SLinus Torvalds 13901da177e4SLinus Torvalds $id = $args{'module'} . "-" . $args{'function'}; 13911da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13921da177e4SLinus Torvalds 13931da177e4SLinus Torvalds print "<sect2>\n"; 13941da177e4SLinus Torvalds print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; 13951da177e4SLinus Torvalds 13961da177e4SLinus Torvalds print " <funcsynopsis>\n"; 13971da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 13981da177e4SLinus Torvalds print "<function>" . $args{'function'} . " "; 13991da177e4SLinus Torvalds print "</function></funcdef>\n"; 14001da177e4SLinus Torvalds 14011da177e4SLinus Torvalds $count = 0; 14021da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 14031da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14041da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 14051da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 14061da177e4SLinus Torvalds # pointer-to-function 14071da177e4SLinus Torvalds print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; 14081da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 14091da177e4SLinus Torvalds } else { 14101da177e4SLinus Torvalds print " <paramdef>" . $type; 14111da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 14121da177e4SLinus Torvalds } 14131da177e4SLinus Torvalds } 14141da177e4SLinus Torvalds } else { 14151da177e4SLinus Torvalds print " <void>\n"; 14161da177e4SLinus Torvalds } 14171da177e4SLinus Torvalds print " </funcsynopsis>\n"; 14181da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 14191da177e4SLinus Torvalds print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; 14201da177e4SLinus Torvalds print "<tgroup cols=\"2\">\n"; 14211da177e4SLinus Torvalds print "<colspec colwidth=\"2*\">\n"; 14221da177e4SLinus Torvalds print "<colspec colwidth=\"8*\">\n"; 14231da177e4SLinus Torvalds print "<tbody>\n"; 14241da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14251da177e4SLinus Torvalds my $parameter_name = $parameter; 14261da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14271da177e4SLinus Torvalds 14281da177e4SLinus Torvalds print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; 14291da177e4SLinus Torvalds print " <entry>\n"; 14301da177e4SLinus Torvalds $lineprefix=" "; 14311da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14321da177e4SLinus Torvalds print " </entry></row>\n"; 14331da177e4SLinus Torvalds } 14341da177e4SLinus Torvalds print " </tbody></tgroup></informaltable>\n"; 14351da177e4SLinus Torvalds } else { 14361da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 14371da177e4SLinus Torvalds } 14381da177e4SLinus Torvalds 14391da177e4SLinus Torvalds # print out each section 14401da177e4SLinus Torvalds $lineprefix=" "; 14411da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14421da177e4SLinus Torvalds print "<simplesect>\n <title>$section</title>\n"; 14431da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 14441da177e4SLinus Torvalds print "<example><programlisting>\n"; 1445e314ba31SDaniel Santos $output_preformatted = 1; 14461da177e4SLinus Torvalds } else { 14471da177e4SLinus Torvalds } 14481da177e4SLinus Torvalds print "<para>\n"; 14491da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1450e314ba31SDaniel Santos $output_preformatted = 0; 14511da177e4SLinus Torvalds print "</para>\n"; 14521da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 14531da177e4SLinus Torvalds print "</programlisting></example>\n"; 14541da177e4SLinus Torvalds } else { 14551da177e4SLinus Torvalds } 14561da177e4SLinus Torvalds print " </simplesect>\n"; 14571da177e4SLinus Torvalds } 14581da177e4SLinus Torvalds 14591da177e4SLinus Torvalds print "</sect2>\n\n"; 14601da177e4SLinus Torvalds} 14611da177e4SLinus Torvalds 14621da177e4SLinus Torvalds## 14631da177e4SLinus Torvalds# output function in man 14641da177e4SLinus Torvaldssub output_function_man(%) { 14651da177e4SLinus Torvalds my %args = %{$_[0]}; 14661da177e4SLinus Torvalds my ($parameter, $section); 14671da177e4SLinus Torvalds my $count; 14681da177e4SLinus Torvalds 14691da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 14701da177e4SLinus Torvalds 14711da177e4SLinus Torvalds print ".SH NAME\n"; 14721da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 14731da177e4SLinus Torvalds 14741da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 1475a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 14761da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 1477a21217daSRandy Dunlap } else { 1478a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 1479a21217daSRandy Dunlap } 14801da177e4SLinus Torvalds $count = 0; 14811da177e4SLinus Torvalds my $parenth = "("; 14821da177e4SLinus Torvalds my $post = ","; 14831da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 14841da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 14851da177e4SLinus Torvalds $post = ");"; 14861da177e4SLinus Torvalds } 14871da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 14881da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 14891da177e4SLinus Torvalds # pointer-to-function 14901da177e4SLinus Torvalds print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 14911da177e4SLinus Torvalds } else { 14921da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 14931da177e4SLinus Torvalds print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 14941da177e4SLinus Torvalds } 14951da177e4SLinus Torvalds $count++; 14961da177e4SLinus Torvalds $parenth = ""; 14971da177e4SLinus Torvalds } 14981da177e4SLinus Torvalds 14991da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 15001da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15011da177e4SLinus Torvalds my $parameter_name = $parameter; 15021da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15031da177e4SLinus Torvalds 15041da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 15051da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 15061da177e4SLinus Torvalds } 15071da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15081da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 15091da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15101da177e4SLinus Torvalds } 15111da177e4SLinus Torvalds} 15121da177e4SLinus Torvalds 15131da177e4SLinus Torvalds## 15141da177e4SLinus Torvalds# output enum in man 15151da177e4SLinus Torvaldssub output_enum_man(%) { 15161da177e4SLinus Torvalds my %args = %{$_[0]}; 15171da177e4SLinus Torvalds my ($parameter, $section); 15181da177e4SLinus Torvalds my $count; 15191da177e4SLinus Torvalds 15201da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 15211da177e4SLinus Torvalds 15221da177e4SLinus Torvalds print ".SH NAME\n"; 15231da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 15241da177e4SLinus Torvalds 15251da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 15261da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 15271da177e4SLinus Torvalds $count = 0; 15281da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15291da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 15301da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 15311da177e4SLinus Torvalds print "\n};\n"; 15321da177e4SLinus Torvalds last; 15331da177e4SLinus Torvalds } 15341da177e4SLinus Torvalds else { 15351da177e4SLinus Torvalds print ", \n.br\n"; 15361da177e4SLinus Torvalds } 15371da177e4SLinus Torvalds $count++; 15381da177e4SLinus Torvalds } 15391da177e4SLinus Torvalds 15401da177e4SLinus Torvalds print ".SH Constants\n"; 15411da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15421da177e4SLinus Torvalds my $parameter_name = $parameter; 15431da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15441da177e4SLinus Torvalds 15451da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 15461da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 15471da177e4SLinus Torvalds } 15481da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15491da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15501da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15511da177e4SLinus Torvalds } 15521da177e4SLinus Torvalds} 15531da177e4SLinus Torvalds 15541da177e4SLinus Torvalds## 15551da177e4SLinus Torvalds# output struct in man 15561da177e4SLinus Torvaldssub output_struct_man(%) { 15571da177e4SLinus Torvalds my %args = %{$_[0]}; 15581da177e4SLinus Torvalds my ($parameter, $section); 15591da177e4SLinus Torvalds 15601da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 15611da177e4SLinus Torvalds 15621da177e4SLinus Torvalds print ".SH NAME\n"; 15631da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 15641da177e4SLinus Torvalds 15651da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 15661da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 15671da177e4SLinus Torvalds 15681da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15691da177e4SLinus Torvalds if ($parameter =~ /^#/) { 15701da177e4SLinus Torvalds print ".BI \"$parameter\"\n.br\n"; 15711da177e4SLinus Torvalds next; 15721da177e4SLinus Torvalds } 15731da177e4SLinus Torvalds my $parameter_name = $parameter; 15741da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15751da177e4SLinus Torvalds 15761da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 15771da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 15781da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 15791da177e4SLinus Torvalds # pointer-to-function 15801da177e4SLinus Torvalds print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; 15811da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 15821d7e1d45SRandy.Dunlap # bitfield 15831d7e1d45SRandy.Dunlap print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; 15841da177e4SLinus Torvalds } else { 15851da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 15861da177e4SLinus Torvalds print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; 15871da177e4SLinus Torvalds } 15881da177e4SLinus Torvalds print "\n.br\n"; 15891da177e4SLinus Torvalds } 15901da177e4SLinus Torvalds print "};\n.br\n"; 15911da177e4SLinus Torvalds 1592c51d3dacSRandy Dunlap print ".SH Members\n"; 15931da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15941da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 15951da177e4SLinus Torvalds 15961da177e4SLinus Torvalds my $parameter_name = $parameter; 15971da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15981da177e4SLinus Torvalds 15991da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 16001da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 16011da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 16021da177e4SLinus Torvalds } 16031da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16041da177e4SLinus Torvalds print ".SH \"$section\"\n"; 16051da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16061da177e4SLinus Torvalds } 16071da177e4SLinus Torvalds} 16081da177e4SLinus Torvalds 16091da177e4SLinus Torvalds## 16101da177e4SLinus Torvalds# output typedef in man 16111da177e4SLinus Torvaldssub output_typedef_man(%) { 16121da177e4SLinus Torvalds my %args = %{$_[0]}; 16131da177e4SLinus Torvalds my ($parameter, $section); 16141da177e4SLinus Torvalds 16151da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 16161da177e4SLinus Torvalds 16171da177e4SLinus Torvalds print ".SH NAME\n"; 16181da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 16191da177e4SLinus Torvalds 16201da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16211da177e4SLinus Torvalds print ".SH \"$section\"\n"; 16221da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16231da177e4SLinus Torvalds } 16241da177e4SLinus Torvalds} 16251da177e4SLinus Torvalds 1626b112e0f7SJohannes Bergsub output_blockhead_man(%) { 16271da177e4SLinus Torvalds my %args = %{$_[0]}; 16281da177e4SLinus Torvalds my ($parameter, $section); 16291da177e4SLinus Torvalds my $count; 16301da177e4SLinus Torvalds 16311da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 16321da177e4SLinus Torvalds 16331da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16341da177e4SLinus Torvalds print ".SH \"$section\"\n"; 16351da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16361da177e4SLinus Torvalds } 16371da177e4SLinus Torvalds} 16381da177e4SLinus Torvalds 16391da177e4SLinus Torvalds## 16401da177e4SLinus Torvalds# output in text 16411da177e4SLinus Torvaldssub output_function_text(%) { 16421da177e4SLinus Torvalds my %args = %{$_[0]}; 16431da177e4SLinus Torvalds my ($parameter, $section); 1644a21217daSRandy Dunlap my $start; 16451da177e4SLinus Torvalds 1646f47634b2SRandy Dunlap print "Name:\n\n"; 1647f47634b2SRandy Dunlap print $args{'function'} . " - " . $args{'purpose'} . "\n"; 1648f47634b2SRandy Dunlap 1649f47634b2SRandy Dunlap print "\nSynopsis:\n\n"; 1650a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 1651a21217daSRandy Dunlap $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1652a21217daSRandy Dunlap } else { 1653a21217daSRandy Dunlap $start = $args{'function'} . " ("; 1654a21217daSRandy Dunlap } 16551da177e4SLinus Torvalds print $start; 1656a21217daSRandy Dunlap 16571da177e4SLinus Torvalds my $count = 0; 16581da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 16591da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 16601da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 16611da177e4SLinus Torvalds # pointer-to-function 16621da177e4SLinus Torvalds print $1 . $parameter . ") (" . $2; 16631da177e4SLinus Torvalds } else { 16641da177e4SLinus Torvalds print $type . " " . $parameter; 16651da177e4SLinus Torvalds } 16661da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 16671da177e4SLinus Torvalds $count++; 16681da177e4SLinus Torvalds print ",\n"; 16691da177e4SLinus Torvalds print " " x length($start); 16701da177e4SLinus Torvalds } else { 16711da177e4SLinus Torvalds print ");\n\n"; 16721da177e4SLinus Torvalds } 16731da177e4SLinus Torvalds } 16741da177e4SLinus Torvalds 16751da177e4SLinus Torvalds print "Arguments:\n\n"; 16761da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16771da177e4SLinus Torvalds my $parameter_name = $parameter; 16781da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16791da177e4SLinus Torvalds 16801da177e4SLinus Torvalds print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; 16811da177e4SLinus Torvalds } 16821da177e4SLinus Torvalds output_section_text(@_); 16831da177e4SLinus Torvalds} 16841da177e4SLinus Torvalds 16851da177e4SLinus Torvalds#output sections in text 16861da177e4SLinus Torvaldssub output_section_text(%) { 16871da177e4SLinus Torvalds my %args = %{$_[0]}; 16881da177e4SLinus Torvalds my $section; 16891da177e4SLinus Torvalds 16901da177e4SLinus Torvalds print "\n"; 16911da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16921da177e4SLinus Torvalds print "$section:\n\n"; 16931da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16941da177e4SLinus Torvalds } 16951da177e4SLinus Torvalds print "\n\n"; 16961da177e4SLinus Torvalds} 16971da177e4SLinus Torvalds 16981da177e4SLinus Torvalds# output enum in text 16991da177e4SLinus Torvaldssub output_enum_text(%) { 17001da177e4SLinus Torvalds my %args = %{$_[0]}; 17011da177e4SLinus Torvalds my ($parameter); 17021da177e4SLinus Torvalds my $count; 17031da177e4SLinus Torvalds print "Enum:\n\n"; 17041da177e4SLinus Torvalds 17051d7e1d45SRandy.Dunlap print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; 17061da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 17071da177e4SLinus Torvalds $count = 0; 17081da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17091da177e4SLinus Torvalds print "\t$parameter"; 17101da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 17111da177e4SLinus Torvalds $count++; 17121da177e4SLinus Torvalds print ","; 17131da177e4SLinus Torvalds } 17141da177e4SLinus Torvalds print "\n"; 17151da177e4SLinus Torvalds } 17161da177e4SLinus Torvalds print "};\n\n"; 17171da177e4SLinus Torvalds 17181da177e4SLinus Torvalds print "Constants:\n\n"; 17191da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17201da177e4SLinus Torvalds print "$parameter\n\t"; 17211da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter} . "\n"; 17221da177e4SLinus Torvalds } 17231da177e4SLinus Torvalds 17241da177e4SLinus Torvalds output_section_text(@_); 17251da177e4SLinus Torvalds} 17261da177e4SLinus Torvalds 17271da177e4SLinus Torvalds# output typedef in text 17281da177e4SLinus Torvaldssub output_typedef_text(%) { 17291da177e4SLinus Torvalds my %args = %{$_[0]}; 17301da177e4SLinus Torvalds my ($parameter); 17311da177e4SLinus Torvalds my $count; 17321da177e4SLinus Torvalds print "Typedef:\n\n"; 17331da177e4SLinus Torvalds 17341d7e1d45SRandy.Dunlap print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; 17351da177e4SLinus Torvalds output_section_text(@_); 17361da177e4SLinus Torvalds} 17371da177e4SLinus Torvalds 17381da177e4SLinus Torvalds# output struct as text 17391da177e4SLinus Torvaldssub output_struct_text(%) { 17401da177e4SLinus Torvalds my %args = %{$_[0]}; 17411da177e4SLinus Torvalds my ($parameter); 17421da177e4SLinus Torvalds 17431d7e1d45SRandy.Dunlap print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; 17441da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 17451da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17461da177e4SLinus Torvalds if ($parameter =~ /^#/) { 17471da177e4SLinus Torvalds print "$parameter\n"; 17481da177e4SLinus Torvalds next; 17491da177e4SLinus Torvalds } 17501da177e4SLinus Torvalds 17511da177e4SLinus Torvalds my $parameter_name = $parameter; 17521da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 17531da177e4SLinus Torvalds 17541da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 17551da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 17561da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 17571da177e4SLinus Torvalds # pointer-to-function 17581da177e4SLinus Torvalds print "\t$1 $parameter) ($2);\n"; 17591da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 176051f5a0c8SRandy Dunlap # bitfield 17611da177e4SLinus Torvalds print "\t$1 $parameter$2;\n"; 17621da177e4SLinus Torvalds } else { 17631da177e4SLinus Torvalds print "\t" . $type . " " . $parameter . ";\n"; 17641da177e4SLinus Torvalds } 17651da177e4SLinus Torvalds } 17661da177e4SLinus Torvalds print "};\n\n"; 17671da177e4SLinus Torvalds 17681da177e4SLinus Torvalds print "Members:\n\n"; 17691da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17701da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 17711da177e4SLinus Torvalds 17721da177e4SLinus Torvalds my $parameter_name = $parameter; 17731da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 17741da177e4SLinus Torvalds 17751da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 17761da177e4SLinus Torvalds print "$parameter\n\t"; 17771da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter_name} . "\n"; 17781da177e4SLinus Torvalds } 17791da177e4SLinus Torvalds print "\n"; 17801da177e4SLinus Torvalds output_section_text(@_); 17811da177e4SLinus Torvalds} 17821da177e4SLinus Torvalds 1783b112e0f7SJohannes Bergsub output_blockhead_text(%) { 17841da177e4SLinus Torvalds my %args = %{$_[0]}; 17851da177e4SLinus Torvalds my ($parameter, $section); 17861da177e4SLinus Torvalds 17871da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 17881da177e4SLinus Torvalds print " $section:\n"; 17891da177e4SLinus Torvalds print " -> "; 17901da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 17911da177e4SLinus Torvalds } 17921da177e4SLinus Torvalds} 17931da177e4SLinus Torvalds 1794c0d1b6eeSJonathan Corbet## 1795c0d1b6eeSJonathan Corbet# output in restructured text 1796c0d1b6eeSJonathan Corbet# 1797c0d1b6eeSJonathan Corbet 1798c0d1b6eeSJonathan Corbet# 1799c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 1800c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 1801c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 1802c0d1b6eeSJonathan Corbet# 1803c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 1804c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1805c0d1b6eeSJonathan Corbet my ($parameter, $section); 1806c0d1b6eeSJonathan Corbet 1807c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 18089e72184bSJani Nikula if ($output_selection != OUTPUT_INCLUDE) { 1809c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 18109e72184bSJani Nikula } 18110b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 1812c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1813c0d1b6eeSJonathan Corbet print "\n"; 1814c0d1b6eeSJonathan Corbet } 1815c0d1b6eeSJonathan Corbet} 1816c0d1b6eeSJonathan Corbet 1817c0d1b6eeSJonathan Corbetsub output_highlight_rst { 1818c0d1b6eeSJonathan Corbet my $contents = join "\n",@_; 1819c0d1b6eeSJonathan Corbet my $line; 1820c0d1b6eeSJonathan Corbet 1821c0d1b6eeSJonathan Corbet # undo the evil effects of xml_escape() earlier 1822c0d1b6eeSJonathan Corbet $contents = xml_unescape($contents); 1823c0d1b6eeSJonathan Corbet 1824c0d1b6eeSJonathan Corbet eval $dohighlight; 1825c0d1b6eeSJonathan Corbet die $@ if $@; 1826c0d1b6eeSJonathan Corbet 1827c0d1b6eeSJonathan Corbet foreach $line (split "\n", $contents) { 1828830066a7SJani Nikula print $lineprefix . $line . "\n"; 1829c0d1b6eeSJonathan Corbet } 1830c0d1b6eeSJonathan Corbet} 1831c0d1b6eeSJonathan Corbet 1832c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 1833c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1834c0d1b6eeSJonathan Corbet my ($parameter, $section); 1835c099ff69SJani Nikula my $oldprefix = $lineprefix; 183682801d06SMauro Carvalho Chehab my $start = ""; 1837c0d1b6eeSJonathan Corbet 183882801d06SMauro Carvalho Chehab if ($args{'typedef'}) { 183982801d06SMauro Carvalho Chehab print ".. c:type:: ". $args{'function'} . "\n\n"; 184082801d06SMauro Carvalho Chehab print_lineno($declaration_start_line); 184182801d06SMauro Carvalho Chehab print " **Typedef**: "; 184282801d06SMauro Carvalho Chehab $lineprefix = ""; 184382801d06SMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 184482801d06SMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 1845c0d1b6eeSJonathan Corbet } else { 184682801d06SMauro Carvalho Chehab print ".. c:function:: "; 184782801d06SMauro Carvalho Chehab } 184882801d06SMauro Carvalho Chehab if ($args{'functiontype'} ne "") { 184982801d06SMauro Carvalho Chehab $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; 185082801d06SMauro Carvalho Chehab } else { 185182801d06SMauro Carvalho Chehab $start .= $args{'function'} . " ("; 1852c0d1b6eeSJonathan Corbet } 1853c0d1b6eeSJonathan Corbet print $start; 1854c0d1b6eeSJonathan Corbet 1855c0d1b6eeSJonathan Corbet my $count = 0; 1856c0d1b6eeSJonathan Corbet foreach my $parameter (@{$args{'parameterlist'}}) { 1857c0d1b6eeSJonathan Corbet if ($count ne 0) { 1858c0d1b6eeSJonathan Corbet print ", "; 1859c0d1b6eeSJonathan Corbet } 1860c0d1b6eeSJonathan Corbet $count++; 1861c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1862a88b1672SMauro Carvalho Chehab 1863c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1864c0d1b6eeSJonathan Corbet # pointer-to-function 1865c0d1b6eeSJonathan Corbet print $1 . $parameter . ") (" . $2; 1866c0d1b6eeSJonathan Corbet } else { 1867c0d1b6eeSJonathan Corbet print $type . " " . $parameter; 1868c0d1b6eeSJonathan Corbet } 1869c0d1b6eeSJonathan Corbet } 187082801d06SMauro Carvalho Chehab if ($args{'typedef'}) { 187182801d06SMauro Carvalho Chehab print ");``\n\n"; 187282801d06SMauro Carvalho Chehab } else { 1873c099ff69SJani Nikula print ")\n\n"; 18740b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1875c099ff69SJani Nikula $lineprefix = " "; 1876c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1877c099ff69SJani Nikula print "\n"; 187882801d06SMauro Carvalho Chehab } 1879c0d1b6eeSJonathan Corbet 1880ecbcfba1SJani Nikula print "**Parameters**\n\n"; 1881c099ff69SJani Nikula $lineprefix = " "; 1882c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1883c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1884c0d1b6eeSJonathan Corbet #$parameter_name =~ s/\[.*//; 1885c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1886c0d1b6eeSJonathan Corbet 1887c0d1b6eeSJonathan Corbet if ($type ne "") { 1888c0d1b6eeSJonathan Corbet print "``$type $parameter``\n"; 1889c0d1b6eeSJonathan Corbet } else { 1890c0d1b6eeSJonathan Corbet print "``$parameter``\n"; 1891c0d1b6eeSJonathan Corbet } 18920b0f5f29SDaniel Vetter 18930b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 18940b0f5f29SDaniel Vetter 18955e64fa9cSJani Nikula if (defined($args{'parameterdescs'}{$parameter_name}) && 18965e64fa9cSJani Nikula $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 1897c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1898c0d1b6eeSJonathan Corbet } else { 1899d4b08e0cSJani Nikula print " *undescribed*\n"; 1900c0d1b6eeSJonathan Corbet } 1901c0d1b6eeSJonathan Corbet print "\n"; 1902c0d1b6eeSJonathan Corbet } 1903c099ff69SJani Nikula 1904c099ff69SJani Nikula $lineprefix = $oldprefix; 1905c0d1b6eeSJonathan Corbet output_section_rst(@_); 1906c0d1b6eeSJonathan Corbet} 1907c0d1b6eeSJonathan Corbet 1908c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 1909c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1910c0d1b6eeSJonathan Corbet my $section; 1911c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1912c0d1b6eeSJonathan Corbet $lineprefix = ""; 1913c0d1b6eeSJonathan Corbet 1914c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 1915ecbcfba1SJani Nikula print "**$section**\n\n"; 19160b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 1917c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1918c0d1b6eeSJonathan Corbet print "\n"; 1919c0d1b6eeSJonathan Corbet } 1920c0d1b6eeSJonathan Corbet print "\n"; 1921c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1922c0d1b6eeSJonathan Corbet} 1923c0d1b6eeSJonathan Corbet 1924c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 1925c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1926c0d1b6eeSJonathan Corbet my ($parameter); 1927c099ff69SJani Nikula my $oldprefix = $lineprefix; 1928c0d1b6eeSJonathan Corbet my $count; 1929c0d1b6eeSJonathan Corbet my $name = "enum " . $args{'enum'}; 193062850976SJani Nikula 193162850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 19320b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1933c099ff69SJani Nikula $lineprefix = " "; 1934c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1935c099ff69SJani Nikula print "\n"; 1936c0d1b6eeSJonathan Corbet 1937ecbcfba1SJani Nikula print "**Constants**\n\n"; 1938c0d1b6eeSJonathan Corbet $lineprefix = " "; 1939c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1940ecbcfba1SJani Nikula print "``$parameter``\n"; 1941c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 1942c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 1943c0d1b6eeSJonathan Corbet } else { 1944d4b08e0cSJani Nikula print " *undescribed*\n"; 1945c0d1b6eeSJonathan Corbet } 1946c0d1b6eeSJonathan Corbet print "\n"; 1947c0d1b6eeSJonathan Corbet } 1948c099ff69SJani Nikula 1949c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1950c0d1b6eeSJonathan Corbet output_section_rst(@_); 1951c0d1b6eeSJonathan Corbet} 1952c0d1b6eeSJonathan Corbet 1953c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 1954c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1955c0d1b6eeSJonathan Corbet my ($parameter); 1956c099ff69SJani Nikula my $oldprefix = $lineprefix; 1957c0d1b6eeSJonathan Corbet my $name = "typedef " . $args{'typedef'}; 1958c0d1b6eeSJonathan Corbet 195962850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 19600b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1961c099ff69SJani Nikula $lineprefix = " "; 1962c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1963c099ff69SJani Nikula print "\n"; 1964c0d1b6eeSJonathan Corbet 1965c099ff69SJani Nikula $lineprefix = $oldprefix; 1966c0d1b6eeSJonathan Corbet output_section_rst(@_); 1967c0d1b6eeSJonathan Corbet} 1968c0d1b6eeSJonathan Corbet 1969c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 1970c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1971c0d1b6eeSJonathan Corbet my ($parameter); 1972c099ff69SJani Nikula my $oldprefix = $lineprefix; 1973c0d1b6eeSJonathan Corbet my $name = $args{'type'} . " " . $args{'struct'}; 1974c0d1b6eeSJonathan Corbet 197562850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 19760b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1977c099ff69SJani Nikula $lineprefix = " "; 1978c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1979c099ff69SJani Nikula print "\n"; 1980c0d1b6eeSJonathan Corbet 1981ecbcfba1SJani Nikula print "**Definition**\n\n"; 1982c0d1b6eeSJonathan Corbet print "::\n\n"; 1983c0d1b6eeSJonathan Corbet print " " . $args{'type'} . " " . $args{'struct'} . " {\n"; 1984c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1985c0d1b6eeSJonathan Corbet if ($parameter =~ /^#/) { 1986c0d1b6eeSJonathan Corbet print " " . "$parameter\n"; 1987c0d1b6eeSJonathan Corbet next; 1988c0d1b6eeSJonathan Corbet } 1989c0d1b6eeSJonathan Corbet 1990c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1991c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 1992c0d1b6eeSJonathan Corbet 1993c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1994c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1995c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1996c0d1b6eeSJonathan Corbet # pointer-to-function 1997c0d1b6eeSJonathan Corbet print " $1 $parameter) ($2);\n"; 1998c0d1b6eeSJonathan Corbet } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 1999c0d1b6eeSJonathan Corbet # bitfield 2000c0d1b6eeSJonathan Corbet print " $1 $parameter$2;\n"; 2001c0d1b6eeSJonathan Corbet } else { 2002c0d1b6eeSJonathan Corbet print " " . $type . " " . $parameter . ";\n"; 2003c0d1b6eeSJonathan Corbet } 2004c0d1b6eeSJonathan Corbet } 2005c0d1b6eeSJonathan Corbet print " };\n\n"; 2006c0d1b6eeSJonathan Corbet 2007ecbcfba1SJani Nikula print "**Members**\n\n"; 2008c099ff69SJani Nikula $lineprefix = " "; 2009c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 2010c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 2011c0d1b6eeSJonathan Corbet 2012c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 2013c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 2014c0d1b6eeSJonathan Corbet 2015c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 2016c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 20170b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 20186d232c80SMauro Carvalho Chehab print "``" . $parameter . "``\n"; 2019c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 2020c0d1b6eeSJonathan Corbet print "\n"; 2021c0d1b6eeSJonathan Corbet } 2022c0d1b6eeSJonathan Corbet print "\n"; 2023c099ff69SJani Nikula 2024c099ff69SJani Nikula $lineprefix = $oldprefix; 2025c0d1b6eeSJonathan Corbet output_section_rst(@_); 2026c0d1b6eeSJonathan Corbet} 2027c0d1b6eeSJonathan Corbet 2028c0d1b6eeSJonathan Corbet 2029eda603f6SJohannes Berg## list mode output functions 2030eda603f6SJohannes Berg 2031eda603f6SJohannes Bergsub output_function_list(%) { 2032eda603f6SJohannes Berg my %args = %{$_[0]}; 2033eda603f6SJohannes Berg 2034eda603f6SJohannes Berg print $args{'function'} . "\n"; 2035eda603f6SJohannes Berg} 2036eda603f6SJohannes Berg 2037eda603f6SJohannes Berg# output enum in list 2038eda603f6SJohannes Bergsub output_enum_list(%) { 2039eda603f6SJohannes Berg my %args = %{$_[0]}; 2040eda603f6SJohannes Berg print $args{'enum'} . "\n"; 2041eda603f6SJohannes Berg} 2042eda603f6SJohannes Berg 2043eda603f6SJohannes Berg# output typedef in list 2044eda603f6SJohannes Bergsub output_typedef_list(%) { 2045eda603f6SJohannes Berg my %args = %{$_[0]}; 2046eda603f6SJohannes Berg print $args{'typedef'} . "\n"; 2047eda603f6SJohannes Berg} 2048eda603f6SJohannes Berg 2049eda603f6SJohannes Berg# output struct as list 2050eda603f6SJohannes Bergsub output_struct_list(%) { 2051eda603f6SJohannes Berg my %args = %{$_[0]}; 2052eda603f6SJohannes Berg 2053eda603f6SJohannes Berg print $args{'struct'} . "\n"; 2054eda603f6SJohannes Berg} 2055eda603f6SJohannes Berg 2056eda603f6SJohannes Bergsub output_blockhead_list(%) { 2057eda603f6SJohannes Berg my %args = %{$_[0]}; 2058eda603f6SJohannes Berg my ($parameter, $section); 2059eda603f6SJohannes Berg 2060eda603f6SJohannes Berg foreach $section (@{$args{'sectionlist'}}) { 2061eda603f6SJohannes Berg print "DOC: $section\n"; 2062eda603f6SJohannes Berg } 2063eda603f6SJohannes Berg} 2064eda603f6SJohannes Berg 20651da177e4SLinus Torvalds## 206627205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 206727205744SRandy Dunlap# calls the generated, variable output_ function name based on 206827205744SRandy Dunlap# functype and output_mode 20691da177e4SLinus Torvaldssub output_declaration { 20701da177e4SLinus Torvalds no strict 'refs'; 20711da177e4SLinus Torvalds my $name = shift; 20721da177e4SLinus Torvalds my $functype = shift; 20731da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 2074b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 2075b6c3f456SJani Nikula (($output_selection == OUTPUT_INCLUDE || 2076b6c3f456SJani Nikula $output_selection == OUTPUT_EXPORTED) && 207786ae2e38SJani Nikula defined($function_table{$name})) || 2078b6c3f456SJani Nikula (($output_selection == OUTPUT_EXCLUDE || 2079b6c3f456SJani Nikula $output_selection == OUTPUT_INTERNAL) && 208086ae2e38SJani Nikula !($functype eq "function" && defined($function_table{$name})))) 20811da177e4SLinus Torvalds { 20821da177e4SLinus Torvalds &$func(@_); 20831da177e4SLinus Torvalds $section_counter++; 20841da177e4SLinus Torvalds } 20851da177e4SLinus Torvalds} 20861da177e4SLinus Torvalds 20871da177e4SLinus Torvalds## 208827205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 2089b112e0f7SJohannes Bergsub output_blockhead { 20901da177e4SLinus Torvalds no strict 'refs'; 2091b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 20921da177e4SLinus Torvalds &$func(@_); 20931da177e4SLinus Torvalds $section_counter++; 20941da177e4SLinus Torvalds} 20951da177e4SLinus Torvalds 20961da177e4SLinus Torvalds## 20971da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 20981da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 20991da177e4SLinus Torvaldssub dump_declaration($$) { 21001da177e4SLinus Torvalds no strict 'refs'; 21011da177e4SLinus Torvalds my ($prototype, $file) = @_; 21021da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 21031da177e4SLinus Torvalds &$func(@_); 21041da177e4SLinus Torvalds} 21051da177e4SLinus Torvalds 21061da177e4SLinus Torvaldssub dump_union($$) { 21071da177e4SLinus Torvalds dump_struct(@_); 21081da177e4SLinus Torvalds} 21091da177e4SLinus Torvalds 21101da177e4SLinus Torvaldssub dump_struct($$) { 21111da177e4SLinus Torvalds my $x = shift; 21121da177e4SLinus Torvalds my $file = shift; 2113a1d94aa5SRandy Dunlap my $nested; 21141da177e4SLinus Torvalds 21151da177e4SLinus Torvalds if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 211652dc5aecSRandy Dunlap #my $decl_type = $1; 21171da177e4SLinus Torvalds $declaration_name = $2; 21181da177e4SLinus Torvalds my $members = $3; 21191da177e4SLinus Torvalds 21201da177e4SLinus Torvalds # ignore embedded structs or unions 2121a1d94aa5SRandy Dunlap $members =~ s/({.*})//g; 2122a1d94aa5SRandy Dunlap $nested = $1; 21231da177e4SLinus Torvalds 2124aeec46b9SMartin Waitz # ignore members marked private: 21250d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 21260d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 2127aeec46b9SMartin Waitz # strip comments: 2128aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 2129a1d94aa5SRandy Dunlap $nested =~ s/\/\*.*?\*\///gos; 2130d960eea9SRandy Dunlap # strip kmemcheck_bitfield_{begin,end}.*; 2131d960eea9SRandy Dunlap $members =~ s/kmemcheck_bitfield_.*?;//gos; 2132ef5da59fSRandy Dunlap # strip attributes 2133f0074929SJonathan Corbet $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 21347b990789SJohannes Berg $members =~ s/__aligned\s*\([^;]*\)//gos; 2135f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; 2136b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 2137b22b5a9eSConchúr Navid $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 2138aeec46b9SMartin Waitz 21391da177e4SLinus Torvalds create_parameterlist($members, ';', $file); 2140a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); 21411da177e4SLinus Torvalds 21421da177e4SLinus Torvalds output_declaration($declaration_name, 21431da177e4SLinus Torvalds 'struct', 21441da177e4SLinus Torvalds {'struct' => $declaration_name, 21451da177e4SLinus Torvalds 'module' => $modulename, 21461da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 21471da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 21481da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 21491da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 21501da177e4SLinus Torvalds 'sections' => \%sections, 21511da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 21521da177e4SLinus Torvalds 'type' => $decl_type 21531da177e4SLinus Torvalds }); 21541da177e4SLinus Torvalds } 21551da177e4SLinus Torvalds else { 2156d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 21571da177e4SLinus Torvalds ++$errors; 21581da177e4SLinus Torvalds } 21591da177e4SLinus Torvalds} 21601da177e4SLinus Torvalds 21611da177e4SLinus Torvaldssub dump_enum($$) { 21621da177e4SLinus Torvalds my $x = shift; 21631da177e4SLinus Torvalds my $file = shift; 21641da177e4SLinus Torvalds 2165aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 21664468e21eSConchúr Navid # strip #define macros inside enums 21674468e21eSConchúr Navid $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 2168b6d676dbSRandy Dunlap 21691da177e4SLinus Torvalds if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 21701da177e4SLinus Torvalds $declaration_name = $1; 21711da177e4SLinus Torvalds my $members = $2; 21721da177e4SLinus Torvalds 21731da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 21741da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 21751da177e4SLinus Torvalds push @parameterlist, $arg; 21761da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 21771da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 2178d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Enum value '$arg' ". 21791da177e4SLinus Torvalds "not described in enum '$declaration_name'\n"; 21801da177e4SLinus Torvalds } 21811da177e4SLinus Torvalds 21821da177e4SLinus Torvalds } 21831da177e4SLinus Torvalds 21841da177e4SLinus Torvalds output_declaration($declaration_name, 21851da177e4SLinus Torvalds 'enum', 21861da177e4SLinus Torvalds {'enum' => $declaration_name, 21871da177e4SLinus Torvalds 'module' => $modulename, 21881da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 21891da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 21901da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 21911da177e4SLinus Torvalds 'sections' => \%sections, 21921da177e4SLinus Torvalds 'purpose' => $declaration_purpose 21931da177e4SLinus Torvalds }); 21941da177e4SLinus Torvalds } 21951da177e4SLinus Torvalds else { 2196d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 21971da177e4SLinus Torvalds ++$errors; 21981da177e4SLinus Torvalds } 21991da177e4SLinus Torvalds} 22001da177e4SLinus Torvalds 22011da177e4SLinus Torvaldssub dump_typedef($$) { 22021da177e4SLinus Torvalds my $x = shift; 22031da177e4SLinus Torvalds my $file = shift; 22041da177e4SLinus Torvalds 2205aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 220683766452SMauro Carvalho Chehab 220783766452SMauro Carvalho Chehab # Parse function prototypes 2208d37c43ceSMauro Carvalho Chehab if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ || 2209d37c43ceSMauro Carvalho Chehab $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) { 2210d37c43ceSMauro Carvalho Chehab 221183766452SMauro Carvalho Chehab # Function typedefs 221283766452SMauro Carvalho Chehab $return_type = $1; 221383766452SMauro Carvalho Chehab $declaration_name = $2; 221483766452SMauro Carvalho Chehab my $args = $3; 221583766452SMauro Carvalho Chehab 221683766452SMauro Carvalho Chehab create_parameterlist($args, ',', $file); 221783766452SMauro Carvalho Chehab 221883766452SMauro Carvalho Chehab output_declaration($declaration_name, 221983766452SMauro Carvalho Chehab 'function', 222083766452SMauro Carvalho Chehab {'function' => $declaration_name, 222182801d06SMauro Carvalho Chehab 'typedef' => 1, 222283766452SMauro Carvalho Chehab 'module' => $modulename, 222383766452SMauro Carvalho Chehab 'functiontype' => $return_type, 222483766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 222583766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 222683766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 222783766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 222883766452SMauro Carvalho Chehab 'sections' => \%sections, 222983766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 223083766452SMauro Carvalho Chehab }); 223183766452SMauro Carvalho Chehab return; 223283766452SMauro Carvalho Chehab } 223383766452SMauro Carvalho Chehab 22341da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 22351da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 22361da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 22371da177e4SLinus Torvalds } 22381da177e4SLinus Torvalds 22391da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 22401da177e4SLinus Torvalds $declaration_name = $1; 22411da177e4SLinus Torvalds 22421da177e4SLinus Torvalds output_declaration($declaration_name, 22431da177e4SLinus Torvalds 'typedef', 22441da177e4SLinus Torvalds {'typedef' => $declaration_name, 22451da177e4SLinus Torvalds 'module' => $modulename, 22461da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 22471da177e4SLinus Torvalds 'sections' => \%sections, 22481da177e4SLinus Torvalds 'purpose' => $declaration_purpose 22491da177e4SLinus Torvalds }); 22501da177e4SLinus Torvalds } 22511da177e4SLinus Torvalds else { 2252d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 22531da177e4SLinus Torvalds ++$errors; 22541da177e4SLinus Torvalds } 22551da177e4SLinus Torvalds} 22561da177e4SLinus Torvalds 2257a1d94aa5SRandy Dunlapsub save_struct_actual($) { 2258a1d94aa5SRandy Dunlap my $actual = shift; 2259a1d94aa5SRandy Dunlap 2260a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 2261a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 2262a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 2263a1d94aa5SRandy Dunlap} 2264a1d94aa5SRandy Dunlap 22651da177e4SLinus Torvaldssub create_parameterlist($$$) { 22661da177e4SLinus Torvalds my $args = shift; 22671da177e4SLinus Torvalds my $splitter = shift; 22681da177e4SLinus Torvalds my $file = shift; 22691da177e4SLinus Torvalds my $type; 22701da177e4SLinus Torvalds my $param; 22711da177e4SLinus Torvalds 2272a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 22731da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 22741da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 22751da177e4SLinus Torvalds } 22761da177e4SLinus Torvalds 22771da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 22781da177e4SLinus Torvalds # strip comments 22791da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 22801da177e4SLinus Torvalds # strip leading/trailing spaces 22811da177e4SLinus Torvalds $arg =~ s/^\s*//; 22821da177e4SLinus Torvalds $arg =~ s/\s*$//; 22831da177e4SLinus Torvalds $arg =~ s/\s+/ /; 22841da177e4SLinus Torvalds 22851da177e4SLinus Torvalds if ($arg =~ /^#/) { 22861da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 22871da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 22881da177e4SLinus Torvalds # output_* subs. 22891da177e4SLinus Torvalds push_parameter($arg, "", $file); 229000d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 22911da177e4SLinus Torvalds # pointer-to-function 22921da177e4SLinus Torvalds $arg =~ tr/#/,/; 229300d62961SRichard Kennedy $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 22941da177e4SLinus Torvalds $param = $1; 22951da177e4SLinus Torvalds $type = $arg; 229600d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 2297a1d94aa5SRandy Dunlap save_struct_actual($param); 22981da177e4SLinus Torvalds push_parameter($param, $type, $file); 2299aeec46b9SMartin Waitz } elsif ($arg) { 23001da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 23011da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 23021da177e4SLinus Torvalds 23031da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 23041da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 23051da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 23061da177e4SLinus Torvalds } 2307884f2810SBorislav Petkov 2308884f2810SBorislav Petkov my @first_arg; 2309884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 2310884f2810SBorislav Petkov shift @args; 2311884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 2312884f2810SBorislav Petkov push(@first_arg, $2); 2313884f2810SBorislav Petkov } else { 2314884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 2315884f2810SBorislav Petkov } 2316884f2810SBorislav Petkov 23171da177e4SLinus Torvalds unshift(@args, pop @first_arg); 23181da177e4SLinus Torvalds $type = join " ", @first_arg; 23191da177e4SLinus Torvalds 23201da177e4SLinus Torvalds foreach $param (@args) { 23211da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 2322a1d94aa5SRandy Dunlap save_struct_actual($2); 23231da177e4SLinus Torvalds push_parameter($2, "$type $1", $file); 23241da177e4SLinus Torvalds } 23251da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 23267b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 2327a1d94aa5SRandy Dunlap save_struct_actual($1); 23281da177e4SLinus Torvalds push_parameter($1, "$type:$2", $file) 23291da177e4SLinus Torvalds } 23307b97887eSRandy Dunlap } 23311da177e4SLinus Torvalds else { 2332a1d94aa5SRandy Dunlap save_struct_actual($param); 23331da177e4SLinus Torvalds push_parameter($param, $type, $file); 23341da177e4SLinus Torvalds } 23351da177e4SLinus Torvalds } 23361da177e4SLinus Torvalds } 23371da177e4SLinus Torvalds } 23381da177e4SLinus Torvalds} 23391da177e4SLinus Torvalds 23401da177e4SLinus Torvaldssub push_parameter($$$) { 23411da177e4SLinus Torvalds my $param = shift; 23421da177e4SLinus Torvalds my $type = shift; 23431da177e4SLinus Torvalds my $file = shift; 23441da177e4SLinus Torvalds 23455f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 23465f8c7c98SRandy Dunlap ($param eq "}")) { 23475f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 23485f8c7c98SRandy Dunlap } 23495f8c7c98SRandy Dunlap 23505f8c7c98SRandy Dunlap $anon_struct_union = 0; 23511da177e4SLinus Torvalds my $param_name = $param; 23521da177e4SLinus Torvalds $param_name =~ s/\[.*//; 23531da177e4SLinus Torvalds 2354a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 23551da177e4SLinus Torvalds { 2356ef00028bSJonathan Corbet $param = "..."; 2357ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 2358a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 23591da177e4SLinus Torvalds } 2360ced69090SRandy Dunlap } 23611da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 23621da177e4SLinus Torvalds { 23631da177e4SLinus Torvalds $param="void"; 23641da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 23651da177e4SLinus Torvalds } 2366134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 2367134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 2368134fe01bSRandy Dunlap { 2369134fe01bSRandy Dunlap $type = $param; 2370134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 2371134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 23725f8c7c98SRandy Dunlap $anon_struct_union = 1; 2373134fe01bSRandy Dunlap } 2374134fe01bSRandy Dunlap 2375a6d3fe77SMartin Waitz # warn if parameter has no description 2376134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 2377134fe01bSRandy Dunlap # but inline preprocessor statements); 2378134fe01bSRandy Dunlap # also ignore unnamed structs/unions; 23795f8c7c98SRandy Dunlap if (!$anon_struct_union) { 2380a6d3fe77SMartin Waitz if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { 2381a6d3fe77SMartin Waitz 23821da177e4SLinus Torvalds $parameterdescs{$param_name} = $undescribed; 23831da177e4SLinus Torvalds 23841da177e4SLinus Torvalds if (($type eq 'function') || ($type eq 'enum')) { 2385d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Function parameter ". 23861da177e4SLinus Torvalds "or member '$param' not " . 23871da177e4SLinus Torvalds "described in '$declaration_name'\n"; 23881da177e4SLinus Torvalds } 2389d40e1e65SBart Van Assche print STDERR "${file}:$.: warning:" . 23901da177e4SLinus Torvalds " No description found for parameter '$param'\n"; 23911da177e4SLinus Torvalds ++$warnings; 23921da177e4SLinus Torvalds } 2393134fe01bSRandy Dunlap } 23941da177e4SLinus Torvalds 23952b35f4d9SRandy Dunlap $param = xml_escape($param); 23962b35f4d9SRandy Dunlap 239725985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 2398e34e7dbbSRandy Dunlap # on @parameterlist; 2399e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 2400e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 2401e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 2402e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 2403e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 2404e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 2405e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 24061da177e4SLinus Torvalds push @parameterlist, $param; 24071da177e4SLinus Torvalds $parametertypes{$param} = $type; 24081da177e4SLinus Torvalds} 24091da177e4SLinus Torvalds 2410a1d94aa5SRandy Dunlapsub check_sections($$$$$$) { 2411a1d94aa5SRandy Dunlap my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; 2412a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 2413a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 2414a1d94aa5SRandy Dunlap my $err; 2415a1d94aa5SRandy Dunlap my ($px, $sx); 2416a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 2417a1d94aa5SRandy Dunlap 2418a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 2419a1d94aa5SRandy Dunlap $err = 1; 2420a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 2421a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 2422a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 24231f3a6688SJohannes Berg $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 2424e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 2425e34e7dbbSRandy Dunlap # however, the original param string may contain 2426e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 2427e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 2428e34e7dbbSRandy Dunlap # parameter list is split at spaces; 2429e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 2430e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 2431e34e7dbbSRandy Dunlap 2432a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 2433a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 2434a1d94aa5SRandy Dunlap $err = 0; 2435a1d94aa5SRandy Dunlap last; 2436a1d94aa5SRandy Dunlap } 2437a1d94aa5SRandy Dunlap } 2438a1d94aa5SRandy Dunlap if ($err) { 2439a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 2440d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2441a1d94aa5SRandy Dunlap "Excess function parameter " . 2442a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2443a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2444a1d94aa5SRandy Dunlap ++$warnings; 2445a1d94aa5SRandy Dunlap } else { 2446a1d94aa5SRandy Dunlap if ($nested !~ m/\Q$sects[$sx]\E/) { 2447d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2448a1d94aa5SRandy Dunlap "Excess struct/union/enum/typedef member " . 2449a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2450a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2451a1d94aa5SRandy Dunlap ++$warnings; 2452a1d94aa5SRandy Dunlap } 2453a1d94aa5SRandy Dunlap } 2454a1d94aa5SRandy Dunlap } 2455a1d94aa5SRandy Dunlap } 2456a1d94aa5SRandy Dunlap} 2457a1d94aa5SRandy Dunlap 24581da177e4SLinus Torvalds## 24594092bac7SYacine Belkadi# Checks the section describing the return value of a function. 24604092bac7SYacine Belkadisub check_return_section { 24614092bac7SYacine Belkadi my $file = shift; 24624092bac7SYacine Belkadi my $declaration_name = shift; 24634092bac7SYacine Belkadi my $return_type = shift; 24644092bac7SYacine Belkadi 24654092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 24664092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 24674092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 24684092bac7SYacine Belkadi return; 24694092bac7SYacine Belkadi } 24704092bac7SYacine Belkadi 24714092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 24724092bac7SYacine Belkadi $sections{$section_return} eq "") { 2473d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 24744092bac7SYacine Belkadi "No description found for return value of " . 24754092bac7SYacine Belkadi "'$declaration_name'\n"; 24764092bac7SYacine Belkadi ++$warnings; 24774092bac7SYacine Belkadi } 24784092bac7SYacine Belkadi} 24794092bac7SYacine Belkadi 24804092bac7SYacine Belkadi## 24811da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 24821da177e4SLinus Torvalds# processed and spits out all the details stored in the global 24831da177e4SLinus Torvalds# arrays/hashes. 24841da177e4SLinus Torvaldssub dump_function($$) { 24851da177e4SLinus Torvalds my $prototype = shift; 24861da177e4SLinus Torvalds my $file = shift; 2487cbb4d3e6SHoria Geanta my $noret = 0; 24881da177e4SLinus Torvalds 24891da177e4SLinus Torvalds $prototype =~ s/^static +//; 24901da177e4SLinus Torvalds $prototype =~ s/^extern +//; 24914dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 24921da177e4SLinus Torvalds $prototype =~ s/^inline +//; 24931da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 249432e79401SRandy Dunlap $prototype =~ s/^__inline +//; 249532e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 249632e79401SRandy Dunlap $prototype =~ s/^noinline +//; 249774fc5c65SRandy Dunlap $prototype =~ s/__init +//; 249820072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 2499270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 250070c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 25010df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 2502cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 2503328d2440SRandy Dunlap $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; 25041da177e4SLinus Torvalds 25051da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 25061da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 25071da177e4SLinus Torvalds # 2. Function name 25081da177e4SLinus Torvalds # 3. Function parameters. 25091da177e4SLinus Torvalds # 25101da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 25111da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 25121da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 25131da177e4SLinus Torvalds # so on. 25141da177e4SLinus Torvalds # 25151da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 25161da177e4SLinus Torvalds # the following functions' documentation still comes out right: 25171da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 25181da177e4SLinus Torvalds # - atomic_set (macro) 25199598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 25201da177e4SLinus Torvalds 2521cbb4d3e6SHoria Geanta if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 2522cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 2523cbb4d3e6SHoria Geanta # list. 2524cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 2525cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 2526cbb4d3e6SHoria Geanta $return_type = $1; 2527cbb4d3e6SHoria Geanta $declaration_name = $2; 2528cbb4d3e6SHoria Geanta $noret = 1; 2529cbb4d3e6SHoria Geanta } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25301da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25311da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25321da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 253394b3e03cSRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25341da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25351da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25361da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25371da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25381da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25391da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25401da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25411da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25429598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25439598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2544412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2545412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 25461da177e4SLinus Torvalds $return_type = $1; 25471da177e4SLinus Torvalds $declaration_name = $2; 25481da177e4SLinus Torvalds my $args = $3; 25491da177e4SLinus Torvalds 25501da177e4SLinus Torvalds create_parameterlist($args, ',', $file); 25511da177e4SLinus Torvalds } else { 2552d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 25531da177e4SLinus Torvalds return; 25541da177e4SLinus Torvalds } 25551da177e4SLinus Torvalds 2556a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 2557a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); 2558a1d94aa5SRandy Dunlap 25594092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 25604092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 25614092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 25624092bac7SYacine Belkadi # verbose mode. 25634092bac7SYacine Belkadi # TODO: always perform the check. 2564cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 25654092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 25664092bac7SYacine Belkadi } 25674092bac7SYacine Belkadi 25681da177e4SLinus Torvalds output_declaration($declaration_name, 25691da177e4SLinus Torvalds 'function', 25701da177e4SLinus Torvalds {'function' => $declaration_name, 25711da177e4SLinus Torvalds 'module' => $modulename, 25721da177e4SLinus Torvalds 'functiontype' => $return_type, 25731da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 25741da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 25751da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 25761da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 25771da177e4SLinus Torvalds 'sections' => \%sections, 25781da177e4SLinus Torvalds 'purpose' => $declaration_purpose 25791da177e4SLinus Torvalds }); 25801da177e4SLinus Torvalds} 25811da177e4SLinus Torvalds 25821da177e4SLinus Torvaldssub reset_state { 25831da177e4SLinus Torvalds $function = ""; 25841da177e4SLinus Torvalds %parameterdescs = (); 25851da177e4SLinus Torvalds %parametertypes = (); 25861da177e4SLinus Torvalds @parameterlist = (); 25871da177e4SLinus Torvalds %sections = (); 25881da177e4SLinus Torvalds @sectionlist = (); 2589a1d94aa5SRandy Dunlap $sectcheck = ""; 2590a1d94aa5SRandy Dunlap $struct_actual = ""; 25911da177e4SLinus Torvalds $prototype = ""; 25921da177e4SLinus Torvalds 259348af606aSJani Nikula $state = STATE_NORMAL; 259448af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 25951da177e4SLinus Torvalds} 25961da177e4SLinus Torvalds 259756afb0f8SJason Baronsub tracepoint_munge($) { 259856afb0f8SJason Baron my $file = shift; 259956afb0f8SJason Baron my $tracepointname = 0; 260056afb0f8SJason Baron my $tracepointargs = 0; 260156afb0f8SJason Baron 260256afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 260356afb0f8SJason Baron $tracepointname = $1; 260456afb0f8SJason Baron } 26053a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 26063a9089fdSJason Baron $tracepointname = $1; 26073a9089fdSJason Baron } 26083a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 26093a9089fdSJason Baron $tracepointname = $2; 26103a9089fdSJason Baron } 26113a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 261256afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 261356afb0f8SJason Baron $tracepointargs = $1; 261456afb0f8SJason Baron } 261556afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 2616d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 261756afb0f8SJason Baron "$prototype\n"; 261856afb0f8SJason Baron } else { 261956afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 262056afb0f8SJason Baron } 262156afb0f8SJason Baron} 262256afb0f8SJason Baron 2623b4870bc5SRandy Dunlapsub syscall_munge() { 2624b4870bc5SRandy Dunlap my $void = 0; 2625b4870bc5SRandy Dunlap 2626b4870bc5SRandy Dunlap $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs 2627b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 2628b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 2629b4870bc5SRandy Dunlap $void = 1; 2630b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 2631b4870bc5SRandy Dunlap } 2632b4870bc5SRandy Dunlap 2633b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 2634b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 2635b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 2636b4870bc5SRandy Dunlap } elsif ($void) { 2637b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 2638b4870bc5SRandy Dunlap } 2639b4870bc5SRandy Dunlap 2640b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 2641b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 2642b4870bc5SRandy Dunlap my $count = 0; 2643b4870bc5SRandy Dunlap my $len = length($prototype); 2644b4870bc5SRandy Dunlap if ($void) { 2645b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 2646b4870bc5SRandy Dunlap } 2647b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 2648b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 2649b4870bc5SRandy Dunlap $count++; 2650b4870bc5SRandy Dunlap if ($count % 2 == 1) { 2651b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 2652b4870bc5SRandy Dunlap } 2653b4870bc5SRandy Dunlap } 2654b4870bc5SRandy Dunlap } 2655b4870bc5SRandy Dunlap} 2656b4870bc5SRandy Dunlap 2657b7afa92bSDaniel Vettersub process_proto_function($$) { 26581da177e4SLinus Torvalds my $x = shift; 26591da177e4SLinus Torvalds my $file = shift; 26601da177e4SLinus Torvalds 266151f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 266251f5a0c8SRandy Dunlap 2663890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 26641da177e4SLinus Torvalds # do nothing 26651da177e4SLinus Torvalds } 26661da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 26671da177e4SLinus Torvalds $prototype .= $1; 26681da177e4SLinus Torvalds } 2669b4870bc5SRandy Dunlap 2670890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 26711da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 26721da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 26731da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 2674b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 2675b4870bc5SRandy Dunlap syscall_munge(); 2676b4870bc5SRandy Dunlap } 26773a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 26783a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 26793a9089fdSJason Baron { 268056afb0f8SJason Baron tracepoint_munge($file); 268156afb0f8SJason Baron } 26821da177e4SLinus Torvalds dump_function($prototype, $file); 26831da177e4SLinus Torvalds reset_state(); 26841da177e4SLinus Torvalds } 26851da177e4SLinus Torvalds} 26861da177e4SLinus Torvalds 2687b7afa92bSDaniel Vettersub process_proto_type($$) { 26881da177e4SLinus Torvalds my $x = shift; 26891da177e4SLinus Torvalds my $file = shift; 26901da177e4SLinus Torvalds 26911da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 26921da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 26931da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 269451f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 269551f5a0c8SRandy Dunlap 26961da177e4SLinus Torvalds if ($x =~ /^#/) { 26971da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 26981da177e4SLinus Torvalds $x .= ";"; 26991da177e4SLinus Torvalds } 27001da177e4SLinus Torvalds 27011da177e4SLinus Torvalds while (1) { 27021da177e4SLinus Torvalds if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 27031da177e4SLinus Torvalds $prototype .= $1 . $2; 27041da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 27051da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 27061da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 27071da177e4SLinus Torvalds dump_declaration($prototype, $file); 27081da177e4SLinus Torvalds reset_state(); 27091da177e4SLinus Torvalds last; 27101da177e4SLinus Torvalds } 27111da177e4SLinus Torvalds $x = $3; 27121da177e4SLinus Torvalds } else { 27131da177e4SLinus Torvalds $prototype .= $x; 27141da177e4SLinus Torvalds last; 27151da177e4SLinus Torvalds } 27161da177e4SLinus Torvalds } 27171da177e4SLinus Torvalds} 27181da177e4SLinus Torvalds 27196b5b55f6SRandy Dunlap# xml_escape: replace <, >, and & in the text stream; 27206b5b55f6SRandy Dunlap# 27216b5b55f6SRandy Dunlap# however, formatting controls that are generated internally/locally in the 27226b5b55f6SRandy Dunlap# kernel-doc script are not escaped here; instead, they begin life like 27236b5b55f6SRandy Dunlap# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings 27246b5b55f6SRandy Dunlap# are converted to their mnemonic-expected output, without the 4 * '\' & ':', 27256b5b55f6SRandy Dunlap# just before actual output; (this is done by local_unescape()) 27261da177e4SLinus Torvaldssub xml_escape($) { 27271da177e4SLinus Torvalds my $text = shift; 2728ecfb251aSRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 2729ecfb251aSRandy Dunlap return $text; 2730ecfb251aSRandy Dunlap } 27311da177e4SLinus Torvalds $text =~ s/\&/\\\\\\amp;/g; 27321da177e4SLinus Torvalds $text =~ s/\</\\\\\\lt;/g; 27331da177e4SLinus Torvalds $text =~ s/\>/\\\\\\gt;/g; 27341da177e4SLinus Torvalds return $text; 27351da177e4SLinus Torvalds} 27361da177e4SLinus Torvalds 2737c0d1b6eeSJonathan Corbet# xml_unescape: reverse the effects of xml_escape 2738c0d1b6eeSJonathan Corbetsub xml_unescape($) { 2739c0d1b6eeSJonathan Corbet my $text = shift; 2740c0d1b6eeSJonathan Corbet if (($output_mode eq "text") || ($output_mode eq "man")) { 2741c0d1b6eeSJonathan Corbet return $text; 2742c0d1b6eeSJonathan Corbet } 2743c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\amp;/\&/g; 2744c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\lt;/</g; 2745c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\gt;/>/g; 2746c0d1b6eeSJonathan Corbet return $text; 2747c0d1b6eeSJonathan Corbet} 2748c0d1b6eeSJonathan Corbet 27496b5b55f6SRandy Dunlap# convert local escape strings to html 27506b5b55f6SRandy Dunlap# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) 27516b5b55f6SRandy Dunlapsub local_unescape($) { 27526b5b55f6SRandy Dunlap my $text = shift; 27536b5b55f6SRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 27546b5b55f6SRandy Dunlap return $text; 27556b5b55f6SRandy Dunlap } 27566b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\lt:/</g; 27576b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\gt:/>/g; 27586b5b55f6SRandy Dunlap return $text; 27596b5b55f6SRandy Dunlap} 27606b5b55f6SRandy Dunlap 27611ad560e4SJani Nikulasub map_filename($) { 27621ad560e4SJani Nikula my $file; 27631ad560e4SJani Nikula my ($orig_file) = @_; 27641ad560e4SJani Nikula 27651ad560e4SJani Nikula if (defined($ENV{'SRCTREE'})) { 27661ad560e4SJani Nikula $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 27671ad560e4SJani Nikula } else { 27681ad560e4SJani Nikula $file = $orig_file; 27691ad560e4SJani Nikula } 27701ad560e4SJani Nikula 27711ad560e4SJani Nikula if (defined($source_map{$file})) { 27721ad560e4SJani Nikula $file = $source_map{$file}; 27731ad560e4SJani Nikula } 27741ad560e4SJani Nikula 27751ad560e4SJani Nikula return $file; 27761ad560e4SJani Nikula} 27771ad560e4SJani Nikula 277888c2b57dSJani Nikulasub process_export_file($) { 277988c2b57dSJani Nikula my ($orig_file) = @_; 278088c2b57dSJani Nikula my $file = map_filename($orig_file); 278188c2b57dSJani Nikula 278288c2b57dSJani Nikula if (!open(IN,"<$file")) { 278388c2b57dSJani Nikula print STDERR "Error: Cannot open file $file\n"; 278488c2b57dSJani Nikula ++$errors; 278588c2b57dSJani Nikula return; 278688c2b57dSJani Nikula } 278788c2b57dSJani Nikula 278888c2b57dSJani Nikula while (<IN>) { 278988c2b57dSJani Nikula if (/$export_symbol/) { 279088c2b57dSJani Nikula $function_table{$2} = 1; 279188c2b57dSJani Nikula } 279288c2b57dSJani Nikula } 279388c2b57dSJani Nikula 279488c2b57dSJani Nikula close(IN); 279588c2b57dSJani Nikula} 279688c2b57dSJani Nikula 27971da177e4SLinus Torvaldssub process_file($) { 27982283a117SRandy Dunlap my $file; 27991da177e4SLinus Torvalds my $identifier; 28001da177e4SLinus Torvalds my $func; 2801a21217daSRandy Dunlap my $descr; 28026423133bSJohannes Weiner my $in_purpose = 0; 28031da177e4SLinus Torvalds my $initial_section_counter = $section_counter; 280468f86662SBen Hutchings my ($orig_file) = @_; 2805b7886de4SJani Nikula my $leading_space; 28061da177e4SLinus Torvalds 28071ad560e4SJani Nikula $file = map_filename($orig_file); 28081da177e4SLinus Torvalds 28091da177e4SLinus Torvalds if (!open(IN,"<$file")) { 28101da177e4SLinus Torvalds print STDERR "Error: Cannot open file $file\n"; 28111da177e4SLinus Torvalds ++$errors; 28121da177e4SLinus Torvalds return; 28131da177e4SLinus Torvalds } 28141da177e4SLinus Torvalds 2815a9e7314bSIlya Dryomov $. = 1; 2816a9e7314bSIlya Dryomov 28171da177e4SLinus Torvalds $section_counter = 0; 28181da177e4SLinus Torvalds while (<IN>) { 281965478428SDaniel Santos while (s/\\\s*$//) { 282065478428SDaniel Santos $_ .= <IN>; 282165478428SDaniel Santos } 282248af606aSJani Nikula if ($state == STATE_NORMAL) { 28231da177e4SLinus Torvalds if (/$doc_start/o) { 282448af606aSJani Nikula $state = STATE_NAME; # next line is always the function name 2825850622dfSRandy Dunlap $in_doc_sect = 0; 28260b0f5f29SDaniel Vetter $declaration_start_line = $. + 1; 28271da177e4SLinus Torvalds } 282848af606aSJani Nikula } elsif ($state == STATE_NAME) {# this line is the function name (always) 28291da177e4SLinus Torvalds if (/$doc_block/o) { 283048af606aSJani Nikula $state = STATE_DOCBLOCK; 28311da177e4SLinus Torvalds $contents = ""; 28320b0f5f29SDaniel Vetter $new_start_line = $. + 1; 28330b0f5f29SDaniel Vetter 28341da177e4SLinus Torvalds if ( $1 eq "" ) { 28351da177e4SLinus Torvalds $section = $section_intro; 28361da177e4SLinus Torvalds } else { 28371da177e4SLinus Torvalds $section = $1; 28381da177e4SLinus Torvalds } 28391da177e4SLinus Torvalds } 28401da177e4SLinus Torvalds elsif (/$doc_decl/o) { 28411da177e4SLinus Torvalds $identifier = $1; 28421da177e4SLinus Torvalds if (/\s*([\w\s]+?)\s*-/) { 28431da177e4SLinus Torvalds $identifier = $1; 28441da177e4SLinus Torvalds } 28451da177e4SLinus Torvalds 284648af606aSJani Nikula $state = STATE_FIELD; 28470b0f5f29SDaniel Vetter # if there's no @param blocks need to set up default section 28480b0f5f29SDaniel Vetter # here 28492f4ad40aSJani Nikula $contents = ""; 28502f4ad40aSJani Nikula $section = $section_default; 28510b0f5f29SDaniel Vetter $new_start_line = $. + 1; 28521da177e4SLinus Torvalds if (/-(.*)/) { 285351f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2854a21217daSRandy Dunlap $descr= $1; 2855a21217daSRandy Dunlap $descr =~ s/^\s*//; 2856a21217daSRandy Dunlap $descr =~ s/\s*$//; 285712ae6779SDaniel Santos $descr =~ s/\s+/ /g; 2858a21217daSRandy Dunlap $declaration_purpose = xml_escape($descr); 28596423133bSJohannes Weiner $in_purpose = 1; 28601da177e4SLinus Torvalds } else { 28611da177e4SLinus Torvalds $declaration_purpose = ""; 28621da177e4SLinus Torvalds } 286377cc23b8SRandy Dunlap 286477cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 2865d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 286677cc23b8SRandy Dunlap print STDERR $_; 286777cc23b8SRandy Dunlap ++$warnings; 286877cc23b8SRandy Dunlap } 286977cc23b8SRandy Dunlap 28701da177e4SLinus Torvalds if ($identifier =~ m/^struct/) { 28711da177e4SLinus Torvalds $decl_type = 'struct'; 28721da177e4SLinus Torvalds } elsif ($identifier =~ m/^union/) { 28731da177e4SLinus Torvalds $decl_type = 'union'; 28741da177e4SLinus Torvalds } elsif ($identifier =~ m/^enum/) { 28751da177e4SLinus Torvalds $decl_type = 'enum'; 28761da177e4SLinus Torvalds } elsif ($identifier =~ m/^typedef/) { 28771da177e4SLinus Torvalds $decl_type = 'typedef'; 28781da177e4SLinus Torvalds } else { 28791da177e4SLinus Torvalds $decl_type = 'function'; 28801da177e4SLinus Torvalds } 28811da177e4SLinus Torvalds 28821da177e4SLinus Torvalds if ($verbose) { 2883d40e1e65SBart Van Assche print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; 28841da177e4SLinus Torvalds } 28851da177e4SLinus Torvalds } else { 2886d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 28871da177e4SLinus Torvalds " - I thought it was a doc line\n"; 28881da177e4SLinus Torvalds ++$warnings; 288948af606aSJani Nikula $state = STATE_NORMAL; 28901da177e4SLinus Torvalds } 289148af606aSJani Nikula } elsif ($state == STATE_FIELD) { # look for head: lines, and include content 2892f624adefSJani Nikula if (/$doc_sect/i) { # case insensitive for supported section names 28931da177e4SLinus Torvalds $newsection = $1; 28941da177e4SLinus Torvalds $newcontents = $2; 28951da177e4SLinus Torvalds 2896f624adefSJani Nikula # map the supported section names to the canonical names 2897f624adefSJani Nikula if ($newsection =~ m/^description$/i) { 2898f624adefSJani Nikula $newsection = $section_default; 2899f624adefSJani Nikula } elsif ($newsection =~ m/^context$/i) { 2900f624adefSJani Nikula $newsection = $section_context; 2901f624adefSJani Nikula } elsif ($newsection =~ m/^returns?$/i) { 2902f624adefSJani Nikula $newsection = $section_return; 2903f624adefSJani Nikula } elsif ($newsection =~ m/^\@return$/) { 2904f624adefSJani Nikula # special: @return is a section, not a param description 2905f624adefSJani Nikula $newsection = $section_return; 2906f624adefSJani Nikula } 2907f624adefSJani Nikula 2908792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 2909850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 2910d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: contents before sections\n"; 2911850622dfSRandy Dunlap ++$warnings; 2912850622dfSRandy Dunlap } 291394dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 29141da177e4SLinus Torvalds $section = $section_default; 29151da177e4SLinus Torvalds } 29161da177e4SLinus Torvalds 2917850622dfSRandy Dunlap $in_doc_sect = 1; 29186423133bSJohannes Weiner $in_purpose = 0; 29191da177e4SLinus Torvalds $contents = $newcontents; 29200b0f5f29SDaniel Vetter $new_start_line = $.; 292127205744SRandy Dunlap while ((substr($contents, 0, 1) eq " ") || 292227205744SRandy Dunlap substr($contents, 0, 1) eq "\t") { 292305189497SRandy Dunlap $contents = substr($contents, 1); 292405189497SRandy Dunlap } 29250a726301SJani Nikula if ($contents ne "") { 29261da177e4SLinus Torvalds $contents .= "\n"; 29271da177e4SLinus Torvalds } 29281da177e4SLinus Torvalds $section = $newsection; 2929b7886de4SJani Nikula $leading_space = undef; 29301da177e4SLinus Torvalds } elsif (/$doc_end/) { 29314c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 293294dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 29331da177e4SLinus Torvalds $section = $section_default; 29341da177e4SLinus Torvalds $contents = ""; 29351da177e4SLinus Torvalds } 293646b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 293746b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2938d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: suspicious ending line: $_"; 293946b958ebSRandy Dunlap ++$warnings; 294046b958ebSRandy Dunlap } 29411da177e4SLinus Torvalds 29421da177e4SLinus Torvalds $prototype = ""; 294348af606aSJani Nikula $state = STATE_PROTO; 29441da177e4SLinus Torvalds $brcount = 0; 29451da177e4SLinus Torvalds# print STDERR "end of doc comment, looking for prototype\n"; 29461da177e4SLinus Torvalds } elsif (/$doc_content/) { 29471da177e4SLinus Torvalds # miguel-style comment kludge, look for blank lines after 29481da177e4SLinus Torvalds # @parameter line to signify start of description 29496423133bSJohannes Weiner if ($1 eq "") { 29506423133bSJohannes Weiner if ($section =~ m/^@/ || $section eq $section_context) { 295194dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 29521da177e4SLinus Torvalds $section = $section_default; 29531da177e4SLinus Torvalds $contents = ""; 29540b0f5f29SDaniel Vetter $new_start_line = $.; 29551da177e4SLinus Torvalds } else { 29566423133bSJohannes Weiner $contents .= "\n"; 29576423133bSJohannes Weiner } 29586423133bSJohannes Weiner $in_purpose = 0; 29596423133bSJohannes Weiner } elsif ($in_purpose == 1) { 29606423133bSJohannes Weiner # Continued declaration purpose 29616423133bSJohannes Weiner chomp($declaration_purpose); 29626423133bSJohannes Weiner $declaration_purpose .= " " . xml_escape($1); 296312ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 29646423133bSJohannes Weiner } else { 2965b7886de4SJani Nikula my $cont = $1; 2966b7886de4SJani Nikula if ($section =~ m/^@/ || $section eq $section_context) { 2967b7886de4SJani Nikula if (!defined $leading_space) { 2968b7886de4SJani Nikula if ($cont =~ m/^(\s+)/) { 2969b7886de4SJani Nikula $leading_space = $1; 2970b7886de4SJani Nikula } else { 2971b7886de4SJani Nikula $leading_space = ""; 2972b7886de4SJani Nikula } 2973b7886de4SJani Nikula } 2974b7886de4SJani Nikula 2975b7886de4SJani Nikula $cont =~ s/^$leading_space//; 2976b7886de4SJani Nikula } 2977b7886de4SJani Nikula $contents .= $cont . "\n"; 29781da177e4SLinus Torvalds } 29791da177e4SLinus Torvalds } else { 29801da177e4SLinus Torvalds # i dont know - bad line? ignore. 2981d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: bad line: $_"; 29821da177e4SLinus Torvalds ++$warnings; 29831da177e4SLinus Torvalds } 298448af606aSJani Nikula } elsif ($state == STATE_INLINE) { # scanning for inline parameters 2985a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 298648af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 2987a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 2988a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 29890b0f5f29SDaniel Vetter $new_start_line = $.; 2990a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 2991a4c6ebedSDanilo Cesar Lemes de Paula while ((substr($contents, 0, 1) eq " ") || 2992a4c6ebedSDanilo Cesar Lemes de Paula substr($contents, 0, 1) eq "\t") { 2993a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 2994a4c6ebedSDanilo Cesar Lemes de Paula } 2995a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 2996a4c6ebedSDanilo Cesar Lemes de Paula } 299748af606aSJani Nikula $inline_doc_state = STATE_INLINE_TEXT; 2998a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 299948af606aSJani Nikula } elsif (/$doc_inline_end/) { 3000a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 3001a4c6ebedSDanilo Cesar Lemes de Paula dump_section($file, $section, xml_escape($contents)); 3002a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 3003a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 3004a4c6ebedSDanilo Cesar Lemes de Paula } 300548af606aSJani Nikula $state = STATE_PROTO; 300648af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 3007a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 3008a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 300948af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_TEXT) { 3010a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 30116450c895SJani Nikula # nuke leading blank lines 30126450c895SJani Nikula if ($contents =~ /^\s*$/) { 30136450c895SJani Nikula $contents = ""; 30146450c895SJani Nikula } 301548af606aSJani Nikula } elsif ($inline_doc_state == STATE_INLINE_NAME) { 301648af606aSJani Nikula $inline_doc_state = STATE_INLINE_ERROR; 3017e7ca311eSDaniel Vetter print STDERR "${file}:$.: warning: "; 3018a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Incorrect use of kernel-doc format: $_"; 3019a4c6ebedSDanilo Cesar Lemes de Paula ++$warnings; 3020a4c6ebedSDanilo Cesar Lemes de Paula } 3021a4c6ebedSDanilo Cesar Lemes de Paula } 302248af606aSJani Nikula } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype) 302348af606aSJani Nikula if (/$doc_inline_start/) { 302448af606aSJani Nikula $state = STATE_INLINE; 302548af606aSJani Nikula $inline_doc_state = STATE_INLINE_NAME; 3026a4c6ebedSDanilo Cesar Lemes de Paula } elsif ($decl_type eq 'function') { 3027b7afa92bSDaniel Vetter process_proto_function($_, $file); 30281da177e4SLinus Torvalds } else { 3029b7afa92bSDaniel Vetter process_proto_type($_, $file); 30301da177e4SLinus Torvalds } 303148af606aSJani Nikula } elsif ($state == STATE_DOCBLOCK) { 3032ebff7f92SDaniel Vetter if (/$doc_end/) 30331da177e4SLinus Torvalds { 303494dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 30352f4ad40aSJani Nikula $section = $section_default; 30361da177e4SLinus Torvalds $contents = ""; 30371da177e4SLinus Torvalds $function = ""; 30381da177e4SLinus Torvalds %parameterdescs = (); 30391da177e4SLinus Torvalds %parametertypes = (); 30401da177e4SLinus Torvalds @parameterlist = (); 30411da177e4SLinus Torvalds %sections = (); 30421da177e4SLinus Torvalds @sectionlist = (); 30431da177e4SLinus Torvalds $prototype = ""; 304448af606aSJani Nikula $state = STATE_NORMAL; 30451da177e4SLinus Torvalds } 30461da177e4SLinus Torvalds elsif (/$doc_content/) 30471da177e4SLinus Torvalds { 30481da177e4SLinus Torvalds if ( $1 eq "" ) 30491da177e4SLinus Torvalds { 30501da177e4SLinus Torvalds $contents .= $blankline; 30511da177e4SLinus Torvalds } 30521da177e4SLinus Torvalds else 30531da177e4SLinus Torvalds { 30541da177e4SLinus Torvalds $contents .= $1 . "\n"; 30551da177e4SLinus Torvalds } 30561da177e4SLinus Torvalds } 30571da177e4SLinus Torvalds } 30581da177e4SLinus Torvalds } 30591da177e4SLinus Torvalds if ($initial_section_counter == $section_counter) { 3060d40e1e65SBart Van Assche print STDERR "${file}:1: warning: no structured comments found\n"; 3061b6c3f456SJani Nikula if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) { 3062e946c43aSJohannes Berg print STDERR " Was looking for '$_'.\n" for keys %function_table; 3063e946c43aSJohannes Berg } 30641da177e4SLinus Torvalds if ($output_mode eq "xml") { 30651da177e4SLinus Torvalds # The template wants at least one RefEntry here; make one. 30661da177e4SLinus Torvalds print "<refentry>\n"; 30671da177e4SLinus Torvalds print " <refnamediv>\n"; 30681da177e4SLinus Torvalds print " <refname>\n"; 306968f86662SBen Hutchings print " ${orig_file}\n"; 30701da177e4SLinus Torvalds print " </refname>\n"; 30711da177e4SLinus Torvalds print " <refpurpose>\n"; 30721da177e4SLinus Torvalds print " Document generation inconsistency\n"; 30731da177e4SLinus Torvalds print " </refpurpose>\n"; 30741da177e4SLinus Torvalds print " </refnamediv>\n"; 30751da177e4SLinus Torvalds print " <refsect1>\n"; 30761da177e4SLinus Torvalds print " <title>\n"; 30771da177e4SLinus Torvalds print " Oops\n"; 30781da177e4SLinus Torvalds print " </title>\n"; 30791da177e4SLinus Torvalds print " <warning>\n"; 30801da177e4SLinus Torvalds print " <para>\n"; 30811da177e4SLinus Torvalds print " The template for this document tried to insert\n"; 30821da177e4SLinus Torvalds print " the structured comment from the file\n"; 308368f86662SBen Hutchings print " <filename>${orig_file}</filename> at this point,\n"; 30841da177e4SLinus Torvalds print " but none was found.\n"; 30851da177e4SLinus Torvalds print " This dummy section is inserted to allow\n"; 30861da177e4SLinus Torvalds print " generation to continue.\n"; 30871da177e4SLinus Torvalds print " </para>\n"; 30881da177e4SLinus Torvalds print " </warning>\n"; 30891da177e4SLinus Torvalds print " </refsect1>\n"; 30901da177e4SLinus Torvalds print "</refentry>\n"; 30911da177e4SLinus Torvalds } 30921da177e4SLinus Torvalds } 30931da177e4SLinus Torvalds} 30948484baaaSRandy Dunlap 30958484baaaSRandy Dunlap 30968484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 30978484baaaSRandy Dunlap 30988484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 30998484baaaSRandy Dunlap# using the s// operator. 31001ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 31014d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 31024d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 31034d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 31044d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 31058484baaaSRandy Dunlap} 31068484baaaSRandy Dunlap 31078484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 31088484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 31098484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 31108484baaaSRandy Dunlap my ($relname, $absname); 31118484baaaSRandy Dunlap while(<SOURCE_MAP>) { 31128484baaaSRandy Dunlap chop(); 31138484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 31148484baaaSRandy Dunlap $relname =~ s:^/+::; 31158484baaaSRandy Dunlap $source_map{$relname} = $absname; 31168484baaaSRandy Dunlap } 31178484baaaSRandy Dunlap close(SOURCE_MAP); 31188484baaaSRandy Dunlap} 31198484baaaSRandy Dunlap 312088c2b57dSJani Nikulaif ($output_selection == OUTPUT_EXPORTED || 312188c2b57dSJani Nikula $output_selection == OUTPUT_INTERNAL) { 3122c9b2cfb3SJani Nikula 3123c9b2cfb3SJani Nikula push(@export_file_list, @ARGV); 3124c9b2cfb3SJani Nikula 312588c2b57dSJani Nikula foreach (@export_file_list) { 312688c2b57dSJani Nikula chomp; 312788c2b57dSJani Nikula process_export_file($_); 312888c2b57dSJani Nikula } 312988c2b57dSJani Nikula} 313088c2b57dSJani Nikula 31318484baaaSRandy Dunlapforeach (@ARGV) { 31328484baaaSRandy Dunlap chomp; 31338484baaaSRandy Dunlap process_file($_); 31348484baaaSRandy Dunlap} 31358484baaaSRandy Dunlapif ($verbose && $errors) { 31368484baaaSRandy Dunlap print STDERR "$errors errors\n"; 31378484baaaSRandy Dunlap} 31388484baaaSRandy Dunlapif ($verbose && $warnings) { 31398484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 31408484baaaSRandy Dunlap} 31418484baaaSRandy Dunlap 31428484baaaSRandy Dunlapexit($errors); 3143