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') 2025267dd35SPaolo Bonzini# '&struct_name.member' - name of a structure member 2031da177e4SLinus Torvalds# '@parameter' - name of a parameter 2041da177e4SLinus Torvalds# '%CONST' - name of a constant. 2051da177e4SLinus Torvalds 2068484baaaSRandy Dunlap## init lots of data 2078484baaaSRandy Dunlap 2081da177e4SLinus Torvaldsmy $errors = 0; 2091da177e4SLinus Torvaldsmy $warnings = 0; 2105f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvalds# match expressions used to find embedded type information 2131da177e4SLinus Torvaldsmy $type_constant = '\%([-_\w]+)'; 2141da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 215c950a173SSilvio Frickemy $type_param = '\@(\w+(\.\.\.)?)'; 2165219f18aSJonathan Corbetmy $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params 2171da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 218*df31175bSPaolo Bonzinimy $type_enum = '\&(enum\s*([_\w]+))'; 219*df31175bSPaolo Bonzinimy $type_struct = '\&(struct\s*([_\w]+))'; 220*df31175bSPaolo Bonzinimy $type_typedef = '\&(typedef\s*([_\w]+))'; 221*df31175bSPaolo Bonzinimy $type_union = '\&(union\s*([_\w]+))'; 2225267dd35SPaolo Bonzinimy $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; 223*df31175bSPaolo Bonzinimy $type_fallback = '\&([_\w]+)'; 224*df31175bSPaolo Bonzinimy $type_enum_xml = '\&(enum\s*([_\w]+))'; 225*df31175bSPaolo Bonzinimy $type_struct_xml = '\&(struct\s*([_\w]+))'; 226*df31175bSPaolo Bonzinimy $type_typedef_xml = '\&(typedef\s*([_\w]+))'; 227*df31175bSPaolo Bonzinimy $type_union_xml = '\&(union\s*([_\w]+))'; 2285267dd35SPaolo Bonzinimy $type_member_xml = '\&([_\w]+)(\.|-\>)([_\w]+)'; 229*df31175bSPaolo Bonzinimy $type_fallback_xml = '\&([_\w]+)'; 230f3341dcfSJani Nikulamy $type_member_func = $type_member . '\(\)'; 2311da177e4SLinus Torvalds 2321da177e4SLinus Torvalds# Output conversion substitutions. 2331da177e4SLinus Torvalds# One for each output format 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds# these work fairly well 2364d732701SDanilo Cesar Lemes de Paulamy @highlights_html = ( 2374d732701SDanilo Cesar Lemes de Paula [$type_constant, "<i>\$1</i>"], 2384d732701SDanilo Cesar Lemes de Paula [$type_func, "<b>\$1</b>"], 239*df31175bSPaolo Bonzini [$type_enum_xml, "<i>\$1</i>"], 2404d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<i>\$1</i>"], 241*df31175bSPaolo Bonzini [$type_typedef_xml, "<i>\$1</i>"], 242*df31175bSPaolo Bonzini [$type_union_xml, "<i>\$1</i>"], 2434d732701SDanilo Cesar Lemes de Paula [$type_env, "<b><i>\$1</i></b>"], 2445267dd35SPaolo Bonzini [$type_param, "<tt><b>\$1</b></tt>"], 245*df31175bSPaolo Bonzini [$type_member_xml, "<tt><i>\$1</i>\$2\$3</tt>"], 246*df31175bSPaolo Bonzini [$type_fallback_xml, "<i>\$1</i>"] 2474d732701SDanilo Cesar Lemes de Paula ); 2486b5b55f6SRandy Dunlapmy $local_lt = "\\\\\\\\lt:"; 2496b5b55f6SRandy Dunlapmy $local_gt = "\\\\\\\\gt:"; 2506b5b55f6SRandy Dunlapmy $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" 2511da177e4SLinus Torvalds 2521b40c194SDan Luedtke# html version 5 2534d732701SDanilo Cesar Lemes de Paulamy @highlights_html5 = ( 2544d732701SDanilo Cesar Lemes de Paula [$type_constant, "<span class=\"const\">\$1</span>"], 2554d732701SDanilo Cesar Lemes de Paula [$type_func, "<span class=\"func\">\$1</span>"], 256*df31175bSPaolo Bonzini [$type_enum_xml, "<span class=\"enum\">\$1</span>"], 2574d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<span class=\"struct\">\$1</span>"], 258*df31175bSPaolo Bonzini [$type_typedef_xml, "<span class=\"typedef\">\$1</span>"], 259*df31175bSPaolo Bonzini [$type_union_xml, "<span class=\"union\">\$1</span>"], 2604d732701SDanilo Cesar Lemes de Paula [$type_env, "<span class=\"env\">\$1</span>"], 2615267dd35SPaolo Bonzini [$type_param, "<span class=\"param\">\$1</span>]"], 262*df31175bSPaolo Bonzini [$type_member_xml, "<span class=\"literal\"><span class=\"struct\">\$1</span>\$2<span class=\"member\">\$3</span></span>"], 263*df31175bSPaolo Bonzini [$type_fallback_xml, "<span class=\"struct\">\$1</span>"] 2644d732701SDanilo Cesar Lemes de Paula ); 2651b40c194SDan Luedtkemy $blankline_html5 = $local_lt . "br /" . $local_gt; 2661b40c194SDan Luedtke 2671da177e4SLinus Torvalds# XML, docbook format 2684d732701SDanilo Cesar Lemes de Paulamy @highlights_xml = ( 2694d732701SDanilo Cesar Lemes de Paula ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"], 2704d732701SDanilo Cesar Lemes de Paula [$type_constant, "<constant>\$1</constant>"], 271*df31175bSPaolo Bonzini [$type_enum_xml, "<type>\$1</type>"], 2724d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<structname>\$1</structname>"], 273*df31175bSPaolo Bonzini [$type_typedef_xml, "<type>\$1</type>"], 274*df31175bSPaolo Bonzini [$type_union_xml, "<structname>\$1</structname>"], 2754d732701SDanilo Cesar Lemes de Paula [$type_param, "<parameter>\$1</parameter>"], 2764d732701SDanilo Cesar Lemes de Paula [$type_func, "<function>\$1</function>"], 2775267dd35SPaolo Bonzini [$type_env, "<envar>\$1</envar>"], 278*df31175bSPaolo Bonzini [$type_member_xml, "<literal><structname>\$1</structname>\$2<structfield>\$3</structfield></literal>"], 279*df31175bSPaolo Bonzini [$type_fallback_xml, "<structname>\$1</structname>"] 2804d732701SDanilo Cesar Lemes de Paula ); 2815c98fc03SJohannes Bergmy $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvalds# gnome, docbook format 2844d732701SDanilo Cesar Lemes de Paulamy @highlights_gnome = ( 2854d732701SDanilo Cesar Lemes de Paula [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"], 2864d732701SDanilo Cesar Lemes de Paula [$type_func, "<function>\$1</function>"], 287*df31175bSPaolo Bonzini [$type_enum, "<type>\$1</type>"], 2884d732701SDanilo Cesar Lemes de Paula [$type_struct, "<structname>\$1</structname>"], 289*df31175bSPaolo Bonzini [$type_typedef, "<type>\$1</type>"], 290*df31175bSPaolo Bonzini [$type_union, "<structname>\$1</structname>"], 2914d732701SDanilo Cesar Lemes de Paula [$type_env, "<envar>\$1</envar>"], 2925267dd35SPaolo Bonzini [$type_param, "<parameter>\$1</parameter>" ], 293*df31175bSPaolo Bonzini [$type_member, "<literal><structname>\$1</structname>\$2<structfield>\$3</structfield></literal>"], 294*df31175bSPaolo Bonzini [$type_fallback, "<structname>\$1</structname>"] 2954d732701SDanilo Cesar Lemes de Paula ); 2961da177e4SLinus Torvaldsmy $blankline_gnome = "</para><para>\n"; 2971da177e4SLinus Torvalds 2981da177e4SLinus Torvalds# these are pretty rough 2994d732701SDanilo Cesar Lemes de Paulamy @highlights_man = ( 3004d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 3014d732701SDanilo Cesar Lemes de Paula [$type_func, "\\\\fB\$1\\\\fP"], 302*df31175bSPaolo Bonzini [$type_enum, "\\\\fI\$1\\\\fP"], 3034d732701SDanilo Cesar Lemes de Paula [$type_struct, "\\\\fI\$1\\\\fP"], 304*df31175bSPaolo Bonzini [$type_typedef, "\\\\fI\$1\\\\fP"], 305*df31175bSPaolo Bonzini [$type_union, "\\\\fI\$1\\\\fP"], 3065267dd35SPaolo Bonzini [$type_param, "\\\\fI\$1\\\\fP"], 307*df31175bSPaolo Bonzini [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], 308*df31175bSPaolo Bonzini [$type_fallback, "\\\\fI\$1\\\\fP"] 3094d732701SDanilo Cesar Lemes de Paula ); 3101da177e4SLinus Torvaldsmy $blankline_man = ""; 3111da177e4SLinus Torvalds 3121da177e4SLinus Torvalds# text-mode 3134d732701SDanilo Cesar Lemes de Paulamy @highlights_text = ( 3144d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 3154d732701SDanilo Cesar Lemes de Paula [$type_func, "\$1"], 316*df31175bSPaolo Bonzini [$type_enum, "\$1"], 3174d732701SDanilo Cesar Lemes de Paula [$type_struct, "\$1"], 318*df31175bSPaolo Bonzini [$type_typedef, "\$1"], 319*df31175bSPaolo Bonzini [$type_union, "\$1"], 3205267dd35SPaolo Bonzini [$type_param, "\$1"], 321*df31175bSPaolo Bonzini [$type_member, "\$1\$2\$3"], 322*df31175bSPaolo Bonzini [$type_fallback, "\$1"] 3234d732701SDanilo Cesar Lemes de Paula ); 3241da177e4SLinus Torvaldsmy $blankline_text = ""; 3251da177e4SLinus Torvalds 326c0d1b6eeSJonathan Corbet# rst-mode 327c0d1b6eeSJonathan Corbetmy @highlights_rst = ( 328c0d1b6eeSJonathan Corbet [$type_constant, "``\$1``"], 329f3341dcfSJani Nikula # Note: need to escape () to avoid func matching later 3305267dd35SPaolo Bonzini [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], 3315267dd35SPaolo Bonzini [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], 3325219f18aSJonathan Corbet [$type_fp_param, "**\$1\\\\(\\\\)**"], 333a19bce64SJani Nikula [$type_func, "\\:c\\:func\\:`\$1()`"], 334*df31175bSPaolo Bonzini [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], 335*df31175bSPaolo Bonzini [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], 336*df31175bSPaolo Bonzini [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], 337*df31175bSPaolo Bonzini [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], 338a7291e7eSJani Nikula # in rst this can refer to any type 339*df31175bSPaolo Bonzini [$type_fallback, "\\:c\\:type\\:`\$1`"], 340c0d1b6eeSJonathan Corbet [$type_param, "**\$1**"] 341c0d1b6eeSJonathan Corbet ); 342c0d1b6eeSJonathan Corbetmy $blankline_rst = "\n"; 343c0d1b6eeSJonathan Corbet 344eda603f6SJohannes Berg# list mode 3454d732701SDanilo Cesar Lemes de Paulamy @highlights_list = ( 3464d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 3474d732701SDanilo Cesar Lemes de Paula [$type_func, "\$1"], 348*df31175bSPaolo Bonzini [$type_enum, "\$1"], 3494d732701SDanilo Cesar Lemes de Paula [$type_struct, "\$1"], 350*df31175bSPaolo Bonzini [$type_typedef, "\$1"], 351*df31175bSPaolo Bonzini [$type_union, "\$1"], 3525267dd35SPaolo Bonzini [$type_param, "\$1"], 353*df31175bSPaolo Bonzini [$type_member, "\$1"], 354*df31175bSPaolo Bonzini [$type_fallback, "\$1"] 3554d732701SDanilo Cesar Lemes de Paula ); 356eda603f6SJohannes Bergmy $blankline_list = ""; 3571da177e4SLinus Torvalds 3581da177e4SLinus Torvalds# read arguments 3591da177e4SLinus Torvaldsif ($#ARGV == -1) { 3601da177e4SLinus Torvalds usage(); 3611da177e4SLinus Torvalds} 3621da177e4SLinus Torvalds 3638484baaaSRandy Dunlapmy $kernelversion; 3648484baaaSRandy Dunlapmy $dohighlight = ""; 3658484baaaSRandy Dunlap 3661da177e4SLinus Torvaldsmy $verbose = 0; 3671da177e4SLinus Torvaldsmy $output_mode = "man"; 368e314ba31SDaniel Santosmy $output_preformatted = 0; 3694b44595aSJohannes Bergmy $no_doc_sections = 0; 3700b0f5f29SDaniel Vettermy $enable_lineno = 0; 3714d732701SDanilo Cesar Lemes de Paulamy @highlights = @highlights_man; 3721da177e4SLinus Torvaldsmy $blankline = $blankline_man; 3731da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 374b6c3f456SJani Nikula 375b6c3f456SJani Nikulause constant { 376b6c3f456SJani Nikula OUTPUT_ALL => 0, # output all symbols and doc sections 377b6c3f456SJani Nikula OUTPUT_INCLUDE => 1, # output only specified symbols 378b6c3f456SJani Nikula OUTPUT_EXCLUDE => 2, # output everything except specified symbols 379b6c3f456SJani Nikula OUTPUT_EXPORTED => 3, # output exported symbols 380b6c3f456SJani Nikula OUTPUT_INTERNAL => 4, # output non-exported symbols 381b6c3f456SJani Nikula}; 382b6c3f456SJani Nikulamy $output_selection = OUTPUT_ALL; 383b2c4105bSBen Hutchingsmy $show_not_found = 0; 384b2c4105bSBen Hutchings 38588c2b57dSJani Nikulamy @export_file_list; 38688c2b57dSJani Nikula 387b2c4105bSBen Hutchingsmy @build_time; 388b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 389b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 390b2c4105bSBen Hutchings @build_time = gmtime($seconds); 391b2c4105bSBen Hutchings} else { 392b2c4105bSBen Hutchings @build_time = localtime; 393b2c4105bSBen Hutchings} 394b2c4105bSBen Hutchings 3951da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 3961da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 397b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 398b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 3991da177e4SLinus Torvalds 4008484baaaSRandy Dunlap# Essentially these are globals. 401b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 402b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 4031da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 4041da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 4050b0f5f29SDaniel Vettermy $declaration_start_line; 4061da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 4071c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 4081da177e4SLinus Torvalds 409bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 410bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 411bd0e88e5SRandy Dunlap} 412bd0e88e5SRandy Dunlap 4131da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 4141da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 4151da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 4161da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 4171da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 4181da177e4SLinus Torvalds# into html. 4191da177e4SLinus Torvaldsmy $section_counter = 0; 4201da177e4SLinus Torvalds 4211da177e4SLinus Torvaldsmy $lineprefix=""; 4221da177e4SLinus Torvalds 42348af606aSJani Nikula# Parser states 42448af606aSJani Nikulause constant { 42548af606aSJani Nikula STATE_NORMAL => 0, # normal code 42648af606aSJani Nikula STATE_NAME => 1, # looking for function name 42748af606aSJani Nikula STATE_FIELD => 2, # scanning field start 42848af606aSJani Nikula STATE_PROTO => 3, # scanning prototype 42948af606aSJani Nikula STATE_DOCBLOCK => 4, # documentation block 43048af606aSJani Nikula STATE_INLINE => 5, # gathering documentation outside main block 43148af606aSJani Nikula}; 4321da177e4SLinus Torvaldsmy $state; 433850622dfSRandy Dunlapmy $in_doc_sect; 4341da177e4SLinus Torvalds 43548af606aSJani Nikula# Inline documentation state 43648af606aSJani Nikulause constant { 43748af606aSJani Nikula STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 43848af606aSJani Nikula STATE_INLINE_NAME => 1, # looking for member name (@foo:) 43948af606aSJani Nikula STATE_INLINE_TEXT => 2, # looking for member documentation 44048af606aSJani Nikula STATE_INLINE_END => 3, # done 44148af606aSJani Nikula STATE_INLINE_ERROR => 4, # error - Comment without header was found. 44248af606aSJani Nikula # Spit a warning as it's not 443a4c6ebedSDanilo Cesar Lemes de Paula # proper kernel-doc and ignore the rest. 44448af606aSJani Nikula}; 44548af606aSJani Nikulamy $inline_doc_state; 446a4c6ebedSDanilo Cesar Lemes de Paula 4471da177e4SLinus Torvalds#declaration types: can be 4481da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 4491da177e4SLinus Torvaldsmy $decl_type; 4501da177e4SLinus Torvalds 4511da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 4521da177e4SLinus Torvaldsmy $doc_end = '\*/'; 4531da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 45412ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 4551da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 456f624adefSJani Nikula# @params and a strictly limited set of supported section names 4578569de68SJonathan Corbetmy $doc_sect = $doc_com . 458ef00028bSJonathan Corbet '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)'; 45912ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 4601da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 46148af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$'; 46248af606aSJani Nikulamy $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)'; 46348af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$'; 4640c9aa209SJani Nikulamy $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; 46586ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 4661da177e4SLinus Torvalds 4671da177e4SLinus Torvaldsmy %parameterdescs; 4680b0f5f29SDaniel Vettermy %parameterdesc_start_lines; 4691da177e4SLinus Torvaldsmy @parameterlist; 4701da177e4SLinus Torvaldsmy %sections; 4711da177e4SLinus Torvaldsmy @sectionlist; 4720b0f5f29SDaniel Vettermy %section_start_lines; 473a1d94aa5SRandy Dunlapmy $sectcheck; 474a1d94aa5SRandy Dunlapmy $struct_actual; 4751da177e4SLinus Torvalds 4761da177e4SLinus Torvaldsmy $contents = ""; 4770b0f5f29SDaniel Vettermy $new_start_line = 0; 478f624adefSJani Nikula 479f624adefSJani Nikula# the canonical section names. see also $doc_sect above. 4801da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 4811da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 4821da177e4SLinus Torvaldsmy $section = $section_default; 4831da177e4SLinus Torvaldsmy $section_context = "Context"; 4844092bac7SYacine Belkadimy $section_return = "Return"; 4851da177e4SLinus Torvalds 4861da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 4871da177e4SLinus Torvalds 4881da177e4SLinus Torvaldsreset_state(); 4891da177e4SLinus Torvalds 4901da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) { 4911da177e4SLinus Torvalds my $cmd = shift @ARGV; 4921da177e4SLinus Torvalds if ($cmd eq "-html") { 4931da177e4SLinus Torvalds $output_mode = "html"; 4944d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_html; 4951da177e4SLinus Torvalds $blankline = $blankline_html; 4961b40c194SDan Luedtke } elsif ($cmd eq "-html5") { 4971b40c194SDan Luedtke $output_mode = "html5"; 4984d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_html5; 4991b40c194SDan Luedtke $blankline = $blankline_html5; 5001da177e4SLinus Torvalds } elsif ($cmd eq "-man") { 5011da177e4SLinus Torvalds $output_mode = "man"; 5024d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 5031da177e4SLinus Torvalds $blankline = $blankline_man; 5041da177e4SLinus Torvalds } elsif ($cmd eq "-text") { 5051da177e4SLinus Torvalds $output_mode = "text"; 5064d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_text; 5071da177e4SLinus Torvalds $blankline = $blankline_text; 508c0d1b6eeSJonathan Corbet } elsif ($cmd eq "-rst") { 509c0d1b6eeSJonathan Corbet $output_mode = "rst"; 510c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 511c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 5121da177e4SLinus Torvalds } elsif ($cmd eq "-docbook") { 5131da177e4SLinus Torvalds $output_mode = "xml"; 5144d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_xml; 5151da177e4SLinus Torvalds $blankline = $blankline_xml; 516eda603f6SJohannes Berg } elsif ($cmd eq "-list") { 517eda603f6SJohannes Berg $output_mode = "list"; 5184d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_list; 519eda603f6SJohannes Berg $blankline = $blankline_list; 5201da177e4SLinus Torvalds } elsif ($cmd eq "-gnome") { 5211da177e4SLinus Torvalds $output_mode = "gnome"; 5224d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_gnome; 5231da177e4SLinus Torvalds $blankline = $blankline_gnome; 5241da177e4SLinus Torvalds } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document 5251da177e4SLinus Torvalds $modulename = shift @ARGV; 5261da177e4SLinus Torvalds } elsif ($cmd eq "-function") { # to only output specific functions 527b6c3f456SJani Nikula $output_selection = OUTPUT_INCLUDE; 5281da177e4SLinus Torvalds $function = shift @ARGV; 5291da177e4SLinus Torvalds $function_table{$function} = 1; 530b6c3f456SJani Nikula } elsif ($cmd eq "-nofunction") { # output all except specific functions 531b6c3f456SJani Nikula $output_selection = OUTPUT_EXCLUDE; 5321da177e4SLinus Torvalds $function = shift @ARGV; 5331da177e4SLinus Torvalds $function_table{$function} = 1; 53486ae2e38SJani Nikula } elsif ($cmd eq "-export") { # only exported symbols 535b6c3f456SJani Nikula $output_selection = OUTPUT_EXPORTED; 536da9726ecSJani Nikula %function_table = (); 53786ae2e38SJani Nikula } elsif ($cmd eq "-internal") { # only non-exported symbols 538b6c3f456SJani Nikula $output_selection = OUTPUT_INTERNAL; 539da9726ecSJani Nikula %function_table = (); 54088c2b57dSJani Nikula } elsif ($cmd eq "-export-file") { 54188c2b57dSJani Nikula my $file = shift @ARGV; 54288c2b57dSJani Nikula push(@export_file_list, $file); 5431da177e4SLinus Torvalds } elsif ($cmd eq "-v") { 5441da177e4SLinus Torvalds $verbose = 1; 5451da177e4SLinus Torvalds } elsif (($cmd eq "-h") || ($cmd eq "--help")) { 5461da177e4SLinus Torvalds usage(); 5474b44595aSJohannes Berg } elsif ($cmd eq '-no-doc-sections') { 5484b44595aSJohannes Berg $no_doc_sections = 1; 5490b0f5f29SDaniel Vetter } elsif ($cmd eq '-enable-lineno') { 5500b0f5f29SDaniel Vetter $enable_lineno = 1; 551e946c43aSJohannes Berg } elsif ($cmd eq '-show-not-found') { 552e946c43aSJohannes Berg $show_not_found = 1; 5531da177e4SLinus Torvalds } 5541da177e4SLinus Torvalds} 5551da177e4SLinus Torvalds 5568484baaaSRandy Dunlap# continue execution near EOF; 5578484baaaSRandy Dunlap 55853f049faSBorislav Petkov# get kernel version from env 55953f049faSBorislav Petkovsub get_kernel_version() { 5601b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 56153f049faSBorislav Petkov 56253f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 56353f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 56453f049faSBorislav Petkov } 56553f049faSBorislav Petkov return $version; 56653f049faSBorislav Petkov} 5671da177e4SLinus Torvalds 5680b0f5f29SDaniel Vetter# 5690b0f5f29SDaniel Vettersub print_lineno { 5700b0f5f29SDaniel Vetter my $lineno = shift; 5710b0f5f29SDaniel Vetter if ($enable_lineno && defined($lineno)) { 5720b0f5f29SDaniel Vetter print "#define LINENO " . $lineno . "\n"; 5730b0f5f29SDaniel Vetter } 5740b0f5f29SDaniel Vetter} 5751da177e4SLinus Torvalds## 5761da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 5771da177e4SLinus Torvalds# 5781da177e4SLinus Torvaldssub dump_section { 57994dc7ad5SRandy Dunlap my $file = shift; 5801da177e4SLinus Torvalds my $name = shift; 5811da177e4SLinus Torvalds my $contents = join "\n", @_; 5821da177e4SLinus Torvalds 58313901ef2SJani Nikula if ($name =~ m/$type_param/) { 5841da177e4SLinus Torvalds $name = $1; 5851da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 586a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 5870b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 5880b0f5f29SDaniel Vetter $new_start_line = 0; 589ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 590ced69090SRandy Dunlap $name = "..."; 591ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 592a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 5930b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 5940b0f5f29SDaniel Vetter $new_start_line = 0; 5951da177e4SLinus Torvalds } else { 59694dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 59795b6be9dSJani Nikula # Only warn on user specified duplicate section names. 59895b6be9dSJani Nikula if ($name ne $section_default) { 59932217761SJani Nikula print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; 60032217761SJani Nikula ++$warnings; 60195b6be9dSJani Nikula } 60232217761SJani Nikula $sections{$name} .= $contents; 60332217761SJani Nikula } else { 6041da177e4SLinus Torvalds $sections{$name} = $contents; 6051da177e4SLinus Torvalds push @sectionlist, $name; 6060b0f5f29SDaniel Vetter $section_start_lines{$name} = $new_start_line; 6070b0f5f29SDaniel Vetter $new_start_line = 0; 6081da177e4SLinus Torvalds } 6091da177e4SLinus Torvalds } 61032217761SJani Nikula} 6111da177e4SLinus Torvalds 6121da177e4SLinus Torvalds## 613b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 614b112e0f7SJohannes Berg# 615b112e0f7SJohannes Bergsub dump_doc_section { 61694dc7ad5SRandy Dunlap my $file = shift; 617b112e0f7SJohannes Berg my $name = shift; 618b112e0f7SJohannes Berg my $contents = join "\n", @_; 619b112e0f7SJohannes Berg 6204b44595aSJohannes Berg if ($no_doc_sections) { 6214b44595aSJohannes Berg return; 6224b44595aSJohannes Berg } 6234b44595aSJohannes Berg 624b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 625b6c3f456SJani Nikula ($output_selection == OUTPUT_INCLUDE && 626b6c3f456SJani Nikula defined($function_table{$name})) || 627b6c3f456SJani Nikula ($output_selection == OUTPUT_EXCLUDE && 628b6c3f456SJani Nikula !defined($function_table{$name}))) 629b112e0f7SJohannes Berg { 63094dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 631b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 632b112e0f7SJohannes Berg 'sections' => \%sections, 633b112e0f7SJohannes Berg 'module' => $modulename, 634b6c3f456SJani Nikula 'content-only' => ($output_selection != OUTPUT_ALL), }); 635b112e0f7SJohannes Berg } 636b112e0f7SJohannes Berg} 637b112e0f7SJohannes Berg 638b112e0f7SJohannes Berg## 6391da177e4SLinus Torvalds# output function 6401da177e4SLinus Torvalds# 6411da177e4SLinus Torvalds# parameterdescs, a hash. 6421da177e4SLinus Torvalds# function => "function name" 6431da177e4SLinus Torvalds# parameterlist => @list of parameters 6441da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 6451da177e4SLinus Torvalds# sectionlist => @list of sections 646a21217daSRandy Dunlap# sections => %section descriptions 6471da177e4SLinus Torvalds# 6481da177e4SLinus Torvalds 6491da177e4SLinus Torvaldssub output_highlight { 6501da177e4SLinus Torvalds my $contents = join "\n",@_; 6511da177e4SLinus Torvalds my $line; 6521da177e4SLinus Torvalds 6531da177e4SLinus Torvalds# DEBUG 6541da177e4SLinus Torvalds# if (!defined $contents) { 6551da177e4SLinus Torvalds# use Carp; 6561da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 6571da177e4SLinus Torvalds# } 6581da177e4SLinus Torvalds 6591b40c194SDan Luedtke if ($output_mode eq "html" || $output_mode eq "html5" || 6601b40c194SDan Luedtke $output_mode eq "xml") { 6616b5b55f6SRandy Dunlap $contents = local_unescape($contents); 6626b5b55f6SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 6632b35f4d9SRandy Dunlap $contents =~ s/\\\\\\/\&/g; 6646b5b55f6SRandy Dunlap } 6653eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 6661da177e4SLinus Torvalds eval $dohighlight; 6671da177e4SLinus Torvalds die $@ if $@; 6683eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 6693eb014a1SRandy Dunlap 6701b40c194SDan Luedtke# strip whitespaces when generating html5 6711b40c194SDan Luedtke if ($output_mode eq "html5") { 6721b40c194SDan Luedtke $contents =~ s/^\s+//; 6731b40c194SDan Luedtke $contents =~ s/\s+$//; 6741b40c194SDan Luedtke } 6751da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 67612ae6779SDaniel Santos if (! $output_preformatted) { 67712ae6779SDaniel Santos $line =~ s/^\s*//; 67812ae6779SDaniel Santos } 6791da177e4SLinus Torvalds if ($line eq ""){ 680e314ba31SDaniel Santos if (! $output_preformatted) { 6816b5b55f6SRandy Dunlap print $lineprefix, local_unescape($blankline); 682e314ba31SDaniel Santos } 6831da177e4SLinus Torvalds } else { 6841da177e4SLinus Torvalds $line =~ s/\\\\\\/\&/g; 685cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 686cdccb316SRandy Dunlap print "\\&$line"; 687cdccb316SRandy Dunlap } else { 6881da177e4SLinus Torvalds print $lineprefix, $line; 6891da177e4SLinus Torvalds } 690cdccb316SRandy Dunlap } 6911da177e4SLinus Torvalds print "\n"; 6921da177e4SLinus Torvalds } 6931da177e4SLinus Torvalds} 6941da177e4SLinus Torvalds 6951da177e4SLinus Torvalds# output sections in html 6961da177e4SLinus Torvaldssub output_section_html(%) { 6971da177e4SLinus Torvalds my %args = %{$_[0]}; 6981da177e4SLinus Torvalds my $section; 6991da177e4SLinus Torvalds 7001da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7011da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 7021da177e4SLinus Torvalds print "<blockquote>\n"; 7031da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7041da177e4SLinus Torvalds print "</blockquote>\n"; 7051da177e4SLinus Torvalds } 7061da177e4SLinus Torvalds} 7071da177e4SLinus Torvalds 7081da177e4SLinus Torvalds# output enum in html 7091da177e4SLinus Torvaldssub output_enum_html(%) { 7101da177e4SLinus Torvalds my %args = %{$_[0]}; 7111da177e4SLinus Torvalds my ($parameter); 7121da177e4SLinus Torvalds my $count; 7131da177e4SLinus Torvalds print "<h2>enum " . $args{'enum'} . "</h2>\n"; 7141da177e4SLinus Torvalds 7151da177e4SLinus Torvalds print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; 7161da177e4SLinus Torvalds $count = 0; 7171da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7181da177e4SLinus Torvalds print " <b>" . $parameter . "</b>"; 7191da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 7201da177e4SLinus Torvalds $count++; 7211da177e4SLinus Torvalds print ",\n"; 7221da177e4SLinus Torvalds } 7231da177e4SLinus Torvalds print "<br>"; 7241da177e4SLinus Torvalds } 7251da177e4SLinus Torvalds print "};<br>\n"; 7261da177e4SLinus Torvalds 7271da177e4SLinus Torvalds print "<h3>Constants</h3>\n"; 7281da177e4SLinus Torvalds print "<dl>\n"; 7291da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7301da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 7311da177e4SLinus Torvalds print "<dd>"; 7321da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter}); 7331da177e4SLinus Torvalds } 7341da177e4SLinus Torvalds print "</dl>\n"; 7351da177e4SLinus Torvalds output_section_html(@_); 7361da177e4SLinus Torvalds print "<hr>\n"; 7371da177e4SLinus Torvalds} 7381da177e4SLinus Torvalds 739d28bee0cSRandy Dunlap# output typedef in html 7401da177e4SLinus Torvaldssub output_typedef_html(%) { 7411da177e4SLinus Torvalds my %args = %{$_[0]}; 7421da177e4SLinus Torvalds my ($parameter); 7431da177e4SLinus Torvalds my $count; 7441da177e4SLinus Torvalds print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; 7451da177e4SLinus Torvalds 7461da177e4SLinus Torvalds print "<b>typedef " . $args{'typedef'} . "</b>\n"; 7471da177e4SLinus Torvalds output_section_html(@_); 7481da177e4SLinus Torvalds print "<hr>\n"; 7491da177e4SLinus Torvalds} 7501da177e4SLinus Torvalds 7511da177e4SLinus Torvalds# output struct in html 7521da177e4SLinus Torvaldssub output_struct_html(%) { 7531da177e4SLinus Torvalds my %args = %{$_[0]}; 7541da177e4SLinus Torvalds my ($parameter); 7551da177e4SLinus Torvalds 756262d9b01SRandy Dunlap print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; 7571da177e4SLinus Torvalds print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; 7581da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7591da177e4SLinus Torvalds if ($parameter =~ /^#/) { 7601da177e4SLinus Torvalds print "$parameter<br>\n"; 7611da177e4SLinus Torvalds next; 7621da177e4SLinus Torvalds } 7631da177e4SLinus Torvalds my $parameter_name = $parameter; 7641da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7651da177e4SLinus Torvalds 7661da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7671da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 7681da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 7691da177e4SLinus Torvalds # pointer-to-function 7703eb014a1SRandy Dunlap print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; 7711da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 7723eb014a1SRandy Dunlap # bitfield 7733eb014a1SRandy Dunlap print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; 7741da177e4SLinus Torvalds } else { 7753eb014a1SRandy Dunlap print " <i>$type</i> <b>$parameter</b>;<br>\n"; 7761da177e4SLinus Torvalds } 7771da177e4SLinus Torvalds } 7781da177e4SLinus Torvalds print "};<br>\n"; 7791da177e4SLinus Torvalds 7801da177e4SLinus Torvalds print "<h3>Members</h3>\n"; 7811da177e4SLinus Torvalds print "<dl>\n"; 7821da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7831da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 7841da177e4SLinus Torvalds 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 7981da177e4SLinus Torvalds# output function in html 7991da177e4SLinus Torvaldssub output_function_html(%) { 8001da177e4SLinus Torvalds my %args = %{$_[0]}; 8011da177e4SLinus Torvalds my ($parameter, $section); 8021da177e4SLinus Torvalds my $count; 8031da177e4SLinus Torvalds 804262d9b01SRandy Dunlap print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; 8051da177e4SLinus Torvalds print "<i>" . $args{'functiontype'} . "</i>\n"; 8061da177e4SLinus Torvalds print "<b>" . $args{'function'} . "</b>\n"; 8071da177e4SLinus Torvalds print "("; 8081da177e4SLinus Torvalds $count = 0; 8091da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 8101da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 8111da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 8121da177e4SLinus Torvalds # pointer-to-function 8131da177e4SLinus Torvalds print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; 8141da177e4SLinus Torvalds } else { 8151da177e4SLinus Torvalds print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; 8161da177e4SLinus Torvalds } 8171da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 8181da177e4SLinus Torvalds $count++; 8191da177e4SLinus Torvalds print ",\n"; 8201da177e4SLinus Torvalds } 8211da177e4SLinus Torvalds } 8221da177e4SLinus Torvalds print ")\n"; 8231da177e4SLinus Torvalds 8241da177e4SLinus Torvalds print "<h3>Arguments</h3>\n"; 8251da177e4SLinus Torvalds print "<dl>\n"; 8261da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 8271da177e4SLinus Torvalds my $parameter_name = $parameter; 8281da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 8291da177e4SLinus Torvalds 8301da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 8311da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 8321da177e4SLinus Torvalds print "<dd>"; 8331da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 8341da177e4SLinus Torvalds } 8351da177e4SLinus Torvalds print "</dl>\n"; 8361da177e4SLinus Torvalds output_section_html(@_); 8371da177e4SLinus Torvalds print "<hr>\n"; 8381da177e4SLinus Torvalds} 8391da177e4SLinus Torvalds 840b112e0f7SJohannes Berg# output DOC: block header in html 841b112e0f7SJohannes Bergsub output_blockhead_html(%) { 8421da177e4SLinus Torvalds my %args = %{$_[0]}; 8431da177e4SLinus Torvalds my ($parameter, $section); 8441da177e4SLinus Torvalds my $count; 8451da177e4SLinus Torvalds 8461da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 8471da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 8481da177e4SLinus Torvalds print "<ul>\n"; 8491da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 8501da177e4SLinus Torvalds print "</ul>\n"; 8511da177e4SLinus Torvalds } 8521da177e4SLinus Torvalds print "<hr>\n"; 8531da177e4SLinus Torvalds} 8541da177e4SLinus Torvalds 8551b40c194SDan Luedtke# output sections in html5 8561b40c194SDan Luedtkesub output_section_html5(%) { 8571b40c194SDan Luedtke my %args = %{$_[0]}; 8581b40c194SDan Luedtke my $section; 8591b40c194SDan Luedtke 8601b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 8611b40c194SDan Luedtke print "<section>\n"; 8621b40c194SDan Luedtke print "<h1>$section</h1>\n"; 8631b40c194SDan Luedtke print "<p>\n"; 8641b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 8651b40c194SDan Luedtke print "</p>\n"; 8661b40c194SDan Luedtke print "</section>\n"; 8671b40c194SDan Luedtke } 8681b40c194SDan Luedtke} 8691b40c194SDan Luedtke 8701b40c194SDan Luedtke# output enum in html5 8711b40c194SDan Luedtkesub output_enum_html5(%) { 8721b40c194SDan Luedtke my %args = %{$_[0]}; 8731b40c194SDan Luedtke my ($parameter); 8741b40c194SDan Luedtke my $count; 8751b40c194SDan Luedtke my $html5id; 8761b40c194SDan Luedtke 8771b40c194SDan Luedtke $html5id = $args{'enum'}; 8781b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8791b40c194SDan Luedtke print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; 8801b40c194SDan Luedtke print "<h1>enum " . $args{'enum'} . "</h1>\n"; 8811b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8821b40c194SDan Luedtke print "<li>"; 8831b40c194SDan Luedtke print "<span class=\"keyword\">enum</span> "; 8841b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; 8851b40c194SDan Luedtke print "</li>\n"; 8861b40c194SDan Luedtke $count = 0; 8871b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8881b40c194SDan Luedtke print "<li class=\"indent\">"; 8891b40c194SDan Luedtke print "<span class=\"param\">" . $parameter . "</span>"; 8901b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 8911b40c194SDan Luedtke $count++; 8921b40c194SDan Luedtke print ","; 8931b40c194SDan Luedtke } 8941b40c194SDan Luedtke print "</li>\n"; 8951b40c194SDan Luedtke } 8961b40c194SDan Luedtke print "<li>};</li>\n"; 8971b40c194SDan Luedtke print "</ol>\n"; 8981b40c194SDan Luedtke 8991b40c194SDan Luedtke print "<section>\n"; 9001b40c194SDan Luedtke print "<h1>Constants</h1>\n"; 9011b40c194SDan Luedtke print "<dl>\n"; 9021b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9031b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 9041b40c194SDan Luedtke print "<dd>"; 9051b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter}); 9061b40c194SDan Luedtke print "</dd>\n"; 9071b40c194SDan Luedtke } 9081b40c194SDan Luedtke print "</dl>\n"; 9091b40c194SDan Luedtke print "</section>\n"; 9101b40c194SDan Luedtke output_section_html5(@_); 9111b40c194SDan Luedtke print "</article>\n"; 9121b40c194SDan Luedtke} 9131b40c194SDan Luedtke 9141b40c194SDan Luedtke# output typedef in html5 9151b40c194SDan Luedtkesub output_typedef_html5(%) { 9161b40c194SDan Luedtke my %args = %{$_[0]}; 9171b40c194SDan Luedtke my ($parameter); 9181b40c194SDan Luedtke my $count; 9191b40c194SDan Luedtke my $html5id; 9201b40c194SDan Luedtke 9211b40c194SDan Luedtke $html5id = $args{'typedef'}; 9221b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 9231b40c194SDan Luedtke print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; 9241b40c194SDan Luedtke print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; 9251b40c194SDan Luedtke 9261b40c194SDan Luedtke print "<ol class=\"code\">\n"; 9271b40c194SDan Luedtke print "<li>"; 9281b40c194SDan Luedtke print "<span class=\"keyword\">typedef</span> "; 9291b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; 9301b40c194SDan Luedtke print "</li>\n"; 9311b40c194SDan Luedtke print "</ol>\n"; 9321b40c194SDan Luedtke output_section_html5(@_); 9331b40c194SDan Luedtke print "</article>\n"; 9341b40c194SDan Luedtke} 9351b40c194SDan Luedtke 9361b40c194SDan Luedtke# output struct in html5 9371b40c194SDan Luedtkesub output_struct_html5(%) { 9381b40c194SDan Luedtke my %args = %{$_[0]}; 9391b40c194SDan Luedtke my ($parameter); 9401b40c194SDan Luedtke my $html5id; 9411b40c194SDan Luedtke 9421b40c194SDan Luedtke $html5id = $args{'struct'}; 9431b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 9441b40c194SDan Luedtke print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n"; 9451b40c194SDan Luedtke print "<hgroup>\n"; 9461b40c194SDan Luedtke print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>"; 9471b40c194SDan Luedtke print "<h2>". $args{'purpose'} . "</h2>\n"; 9481b40c194SDan Luedtke print "</hgroup>\n"; 9491b40c194SDan Luedtke print "<ol class=\"code\">\n"; 9501b40c194SDan Luedtke print "<li>"; 9511b40c194SDan Luedtke print "<span class=\"type\">" . $args{'type'} . "</span> "; 9521b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'struct'} . "</span> {"; 9531b40c194SDan Luedtke print "</li>\n"; 9541b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9551b40c194SDan Luedtke print "<li class=\"indent\">"; 9561b40c194SDan Luedtke if ($parameter =~ /^#/) { 9571b40c194SDan Luedtke print "<span class=\"param\">" . $parameter ."</span>\n"; 9581b40c194SDan Luedtke print "</li>\n"; 9591b40c194SDan Luedtke next; 9601b40c194SDan Luedtke } 9611b40c194SDan Luedtke my $parameter_name = $parameter; 9621b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 9631b40c194SDan Luedtke 9641b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 9651b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 9661b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 9671b40c194SDan Luedtke # pointer-to-function 9681b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 9691b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9701b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 9711b40c194SDan Luedtke print "(<span class=\"args\">$2</span>);"; 9721b40c194SDan Luedtke } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 9731b40c194SDan Luedtke # bitfield 9741b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 9751b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9761b40c194SDan Luedtke print "<span class=\"bits\">$2</span>;"; 9771b40c194SDan Luedtke } else { 9781b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 9791b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>;"; 9801b40c194SDan Luedtke } 9811b40c194SDan Luedtke print "</li>\n"; 9821b40c194SDan Luedtke } 9831b40c194SDan Luedtke print "<li>};</li>\n"; 9841b40c194SDan Luedtke print "</ol>\n"; 9851b40c194SDan Luedtke 9861b40c194SDan Luedtke print "<section>\n"; 9871b40c194SDan Luedtke print "<h1>Members</h1>\n"; 9881b40c194SDan Luedtke print "<dl>\n"; 9891b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9901b40c194SDan Luedtke ($parameter =~ /^#/) && next; 9911b40c194SDan Luedtke 9921b40c194SDan Luedtke my $parameter_name = $parameter; 9931b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 9941b40c194SDan Luedtke 9951b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 9961b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 9971b40c194SDan Luedtke print "<dd>"; 9981b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 9991b40c194SDan Luedtke print "</dd>\n"; 10001b40c194SDan Luedtke } 10011b40c194SDan Luedtke print "</dl>\n"; 10021b40c194SDan Luedtke print "</section>\n"; 10031b40c194SDan Luedtke output_section_html5(@_); 10041b40c194SDan Luedtke print "</article>\n"; 10051b40c194SDan Luedtke} 10061b40c194SDan Luedtke 10071b40c194SDan Luedtke# output function in html5 10081b40c194SDan Luedtkesub output_function_html5(%) { 10091b40c194SDan Luedtke my %args = %{$_[0]}; 10101b40c194SDan Luedtke my ($parameter, $section); 10111b40c194SDan Luedtke my $count; 10121b40c194SDan Luedtke my $html5id; 10131b40c194SDan Luedtke 10141b40c194SDan Luedtke $html5id = $args{'function'}; 10151b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 10161b40c194SDan Luedtke print "<article class=\"function\" id=\"func:". $html5id . "\">\n"; 10171b40c194SDan Luedtke print "<hgroup>\n"; 10181b40c194SDan Luedtke print "<h1>" . $args{'function'} . "</h1>"; 10191b40c194SDan Luedtke print "<h2>" . $args{'purpose'} . "</h2>\n"; 10201b40c194SDan Luedtke print "</hgroup>\n"; 10211b40c194SDan Luedtke print "<ol class=\"code\">\n"; 10221b40c194SDan Luedtke print "<li>"; 10231b40c194SDan Luedtke print "<span class=\"type\">" . $args{'functiontype'} . "</span> "; 10241b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'function'} . "</span> ("; 10251b40c194SDan Luedtke print "</li>"; 10261b40c194SDan Luedtke $count = 0; 10271b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 10281b40c194SDan Luedtke print "<li class=\"indent\">"; 10291b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 10301b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 10311b40c194SDan Luedtke # pointer-to-function 10321b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 10331b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 10341b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 10351b40c194SDan Luedtke print "(<span class=\"args\">$2</span>)"; 10361b40c194SDan Luedtke } else { 10371b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 10381b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 10391b40c194SDan Luedtke } 10401b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 10411b40c194SDan Luedtke $count++; 10421b40c194SDan Luedtke print ","; 10431b40c194SDan Luedtke } 10441b40c194SDan Luedtke print "</li>\n"; 10451b40c194SDan Luedtke } 10461b40c194SDan Luedtke print "<li>)</li>\n"; 10471b40c194SDan Luedtke print "</ol>\n"; 10481b40c194SDan Luedtke 10491b40c194SDan Luedtke print "<section>\n"; 10501b40c194SDan Luedtke print "<h1>Arguments</h1>\n"; 10511b40c194SDan Luedtke print "<p>\n"; 10521b40c194SDan Luedtke print "<dl>\n"; 10531b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 10541b40c194SDan Luedtke my $parameter_name = $parameter; 10551b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 10561b40c194SDan Luedtke 10571b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 10581b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 10591b40c194SDan Luedtke print "<dd>"; 10601b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 10611b40c194SDan Luedtke print "</dd>\n"; 10621b40c194SDan Luedtke } 10631b40c194SDan Luedtke print "</dl>\n"; 10641b40c194SDan Luedtke print "</section>\n"; 10651b40c194SDan Luedtke output_section_html5(@_); 10661b40c194SDan Luedtke print "</article>\n"; 10671b40c194SDan Luedtke} 10681b40c194SDan Luedtke 10691b40c194SDan Luedtke# output DOC: block header in html5 10701b40c194SDan Luedtkesub output_blockhead_html5(%) { 10711b40c194SDan Luedtke my %args = %{$_[0]}; 10721b40c194SDan Luedtke my ($parameter, $section); 10731b40c194SDan Luedtke my $count; 10741b40c194SDan Luedtke my $html5id; 10751b40c194SDan Luedtke 10761b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 10771b40c194SDan Luedtke $html5id = $section; 10781b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 10791b40c194SDan Luedtke print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n"; 10801b40c194SDan Luedtke print "<h1>$section</h1>\n"; 10811b40c194SDan Luedtke print "<p>\n"; 10821b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 10831b40c194SDan Luedtke print "</p>\n"; 10841b40c194SDan Luedtke } 10851b40c194SDan Luedtke print "</article>\n"; 10861b40c194SDan Luedtke} 10871b40c194SDan Luedtke 10881da177e4SLinus Torvaldssub output_section_xml(%) { 10891da177e4SLinus Torvalds my %args = %{$_[0]}; 10901da177e4SLinus Torvalds my $section; 10911da177e4SLinus Torvalds # print out each section 10921da177e4SLinus Torvalds $lineprefix=" "; 10931da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1094c73894c1SRich Walker print "<refsect1>\n"; 1095c73894c1SRich Walker print "<title>$section</title>\n"; 10961da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 1097c73894c1SRich Walker print "<informalexample><programlisting>\n"; 1098e314ba31SDaniel Santos $output_preformatted = 1; 1099c73894c1SRich Walker } else { 1100c73894c1SRich Walker print "<para>\n"; 11011da177e4SLinus Torvalds } 11021da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1103e314ba31SDaniel Santos $output_preformatted = 0; 11041da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 1105c73894c1SRich Walker print "</programlisting></informalexample>\n"; 1106c73894c1SRich Walker } else { 1107c73894c1SRich Walker print "</para>\n"; 11081da177e4SLinus Torvalds } 1109c73894c1SRich Walker print "</refsect1>\n"; 11101da177e4SLinus Torvalds } 11111da177e4SLinus Torvalds} 11121da177e4SLinus Torvalds 11131da177e4SLinus Torvalds# output function in XML DocBook 11141da177e4SLinus Torvaldssub output_function_xml(%) { 11151da177e4SLinus Torvalds my %args = %{$_[0]}; 11161da177e4SLinus Torvalds my ($parameter, $section); 11171da177e4SLinus Torvalds my $count; 11181da177e4SLinus Torvalds my $id; 11191da177e4SLinus Torvalds 11201da177e4SLinus Torvalds $id = "API-" . $args{'function'}; 11211da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 11221da177e4SLinus Torvalds 11235449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 11248b0c2d98SMartin Waitz print "<refentryinfo>\n"; 11258b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 11268b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 11278b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 11288b0c2d98SMartin Waitz print "</refentryinfo>\n"; 11291da177e4SLinus Torvalds print "<refmeta>\n"; 11305449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; 11318b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 11320366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 11331da177e4SLinus Torvalds print "</refmeta>\n"; 11341da177e4SLinus Torvalds print "<refnamediv>\n"; 11351da177e4SLinus Torvalds print " <refname>" . $args{'function'} . "</refname>\n"; 11361da177e4SLinus Torvalds print " <refpurpose>\n"; 11371da177e4SLinus Torvalds print " "; 11381da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 11391da177e4SLinus Torvalds print " </refpurpose>\n"; 11401da177e4SLinus Torvalds print "</refnamediv>\n"; 11411da177e4SLinus Torvalds 11421da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 11431da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 11441da177e4SLinus Torvalds print " <funcsynopsis><funcprototype>\n"; 11451da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 11461da177e4SLinus Torvalds print "<function>" . $args{'function'} . " </function></funcdef>\n"; 11471da177e4SLinus Torvalds 11481da177e4SLinus Torvalds $count = 0; 11491da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 11501da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11511da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 11521da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 11531da177e4SLinus Torvalds # pointer-to-function 11541da177e4SLinus Torvalds print " <paramdef>$1<parameter>$parameter</parameter>)\n"; 11551da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 11561da177e4SLinus Torvalds } else { 11571da177e4SLinus Torvalds print " <paramdef>" . $type; 11581da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 11591da177e4SLinus Torvalds } 11601da177e4SLinus Torvalds } 11611da177e4SLinus Torvalds } else { 11626013d544SMartin Waitz print " <void/>\n"; 11631da177e4SLinus Torvalds } 11641da177e4SLinus Torvalds print " </funcprototype></funcsynopsis>\n"; 11651da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 11661da177e4SLinus Torvalds 11671da177e4SLinus Torvalds # print parameters 11681da177e4SLinus Torvalds print "<refsect1>\n <title>Arguments</title>\n"; 11691da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 11701da177e4SLinus Torvalds print " <variablelist>\n"; 11711da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11721da177e4SLinus Torvalds my $parameter_name = $parameter; 11731da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 1174fc6d7af8SPaolo Bonzini $type = $args{'parametertypes'}{$parameter}; 11751da177e4SLinus Torvalds 1176fc6d7af8SPaolo Bonzini print " <varlistentry>\n <term><parameter>$type $parameter</parameter></term>\n"; 11771da177e4SLinus Torvalds print " <listitem>\n <para>\n"; 11781da177e4SLinus Torvalds $lineprefix=" "; 11791da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 11801da177e4SLinus Torvalds print " </para>\n </listitem>\n </varlistentry>\n"; 11811da177e4SLinus Torvalds } 11821da177e4SLinus Torvalds print " </variablelist>\n"; 11831da177e4SLinus Torvalds } else { 11841da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 11851da177e4SLinus Torvalds } 11861da177e4SLinus Torvalds print "</refsect1>\n"; 11871da177e4SLinus Torvalds 11881da177e4SLinus Torvalds output_section_xml(@_); 11891da177e4SLinus Torvalds print "</refentry>\n\n"; 11901da177e4SLinus Torvalds} 11911da177e4SLinus Torvalds 11921da177e4SLinus Torvalds# output struct in XML DocBook 11931da177e4SLinus Torvaldssub output_struct_xml(%) { 11941da177e4SLinus Torvalds my %args = %{$_[0]}; 11951da177e4SLinus Torvalds my ($parameter, $section); 11961da177e4SLinus Torvalds my $id; 11971da177e4SLinus Torvalds 11981da177e4SLinus Torvalds $id = "API-struct-" . $args{'struct'}; 11991da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12001da177e4SLinus Torvalds 12015449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 12028b0c2d98SMartin Waitz print "<refentryinfo>\n"; 12038b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 12048b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 12058b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 12068b0c2d98SMartin Waitz print "</refentryinfo>\n"; 12071da177e4SLinus Torvalds print "<refmeta>\n"; 12085449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; 12098b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 12100366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 12111da177e4SLinus Torvalds print "</refmeta>\n"; 12121da177e4SLinus Torvalds print "<refnamediv>\n"; 12131da177e4SLinus Torvalds print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; 12141da177e4SLinus Torvalds print " <refpurpose>\n"; 12151da177e4SLinus Torvalds print " "; 12161da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 12171da177e4SLinus Torvalds print " </refpurpose>\n"; 12181da177e4SLinus Torvalds print "</refnamediv>\n"; 12191da177e4SLinus Torvalds 12201da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 12211da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 12221da177e4SLinus Torvalds print " <programlisting>\n"; 12231da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 12241da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12251da177e4SLinus Torvalds if ($parameter =~ /^#/) { 12262b35f4d9SRandy Dunlap my $prm = $parameter; 12272b35f4d9SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 12282b35f4d9SRandy Dunlap # This allows us to have #define macros interspersed in a struct. 12292b35f4d9SRandy Dunlap $prm =~ s/\\\\\\/\&/g; 12302b35f4d9SRandy Dunlap print "$prm\n"; 12311da177e4SLinus Torvalds next; 12321da177e4SLinus Torvalds } 12331da177e4SLinus Torvalds 12341da177e4SLinus Torvalds my $parameter_name = $parameter; 12351da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12361da177e4SLinus Torvalds 12371da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 12381da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 12391da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 12401da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 12411da177e4SLinus Torvalds # pointer-to-function 12421da177e4SLinus Torvalds print " $1 $parameter) ($2);\n"; 12431da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 124451f5a0c8SRandy Dunlap # bitfield 12451da177e4SLinus Torvalds print " $1 $parameter$2;\n"; 12461da177e4SLinus Torvalds } else { 12471da177e4SLinus Torvalds print " " . $type . " " . $parameter . ";\n"; 12481da177e4SLinus Torvalds } 12491da177e4SLinus Torvalds } 12501da177e4SLinus Torvalds print "};"; 12511da177e4SLinus Torvalds print " </programlisting>\n"; 12521da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 12531da177e4SLinus Torvalds 12541da177e4SLinus Torvalds print " <refsect1>\n"; 12551da177e4SLinus Torvalds print " <title>Members</title>\n"; 12561da177e4SLinus Torvalds 125739f00c08SRandy Dunlap if ($#{$args{'parameterlist'}} >= 0) { 12581da177e4SLinus Torvalds print " <variablelist>\n"; 12591da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12601da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 12611da177e4SLinus Torvalds 12621da177e4SLinus Torvalds my $parameter_name = $parameter; 12631da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12641da177e4SLinus Torvalds 12651da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 12661da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1267fc6d7af8SPaolo Bonzini $type = $args{'parametertypes'}{$parameter}; 12681da177e4SLinus Torvalds print " <varlistentry>"; 1269fc6d7af8SPaolo Bonzini print " <term><literal>$type $parameter</literal></term>\n"; 12701da177e4SLinus Torvalds print " <listitem><para>\n"; 12711da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 12721da177e4SLinus Torvalds print " </para></listitem>\n"; 12731da177e4SLinus Torvalds print " </varlistentry>\n"; 12741da177e4SLinus Torvalds } 12751da177e4SLinus Torvalds print " </variablelist>\n"; 127639f00c08SRandy Dunlap } else { 127739f00c08SRandy Dunlap print " <para>\n None\n </para>\n"; 127839f00c08SRandy Dunlap } 12791da177e4SLinus Torvalds print " </refsect1>\n"; 12801da177e4SLinus Torvalds 12811da177e4SLinus Torvalds output_section_xml(@_); 12821da177e4SLinus Torvalds 12831da177e4SLinus Torvalds print "</refentry>\n\n"; 12841da177e4SLinus Torvalds} 12851da177e4SLinus Torvalds 12861da177e4SLinus Torvalds# output enum in XML DocBook 12871da177e4SLinus Torvaldssub output_enum_xml(%) { 12881da177e4SLinus Torvalds my %args = %{$_[0]}; 12891da177e4SLinus Torvalds my ($parameter, $section); 12901da177e4SLinus Torvalds my $count; 12911da177e4SLinus Torvalds my $id; 12921da177e4SLinus Torvalds 12931da177e4SLinus Torvalds $id = "API-enum-" . $args{'enum'}; 12941da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12951da177e4SLinus Torvalds 12965449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 12978b0c2d98SMartin Waitz print "<refentryinfo>\n"; 12988b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 12998b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 13008b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 13018b0c2d98SMartin Waitz print "</refentryinfo>\n"; 13021da177e4SLinus Torvalds print "<refmeta>\n"; 13035449bc94SPavel Pisa print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; 13048b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 13050366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 13061da177e4SLinus Torvalds print "</refmeta>\n"; 13071da177e4SLinus Torvalds print "<refnamediv>\n"; 13081da177e4SLinus Torvalds print " <refname>enum " . $args{'enum'} . "</refname>\n"; 13091da177e4SLinus Torvalds print " <refpurpose>\n"; 13101da177e4SLinus Torvalds print " "; 13111da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 13121da177e4SLinus Torvalds print " </refpurpose>\n"; 13131da177e4SLinus Torvalds print "</refnamediv>\n"; 13141da177e4SLinus Torvalds 13151da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 13161da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 13171da177e4SLinus Torvalds print " <programlisting>\n"; 13181da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 13191da177e4SLinus Torvalds $count = 0; 13201da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13211da177e4SLinus Torvalds print " $parameter"; 13221da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 13231da177e4SLinus Torvalds $count++; 13241da177e4SLinus Torvalds print ","; 13251da177e4SLinus Torvalds } 13261da177e4SLinus Torvalds print "\n"; 13271da177e4SLinus Torvalds } 13281da177e4SLinus Torvalds print "};"; 13291da177e4SLinus Torvalds print " </programlisting>\n"; 13301da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 13311da177e4SLinus Torvalds 13321da177e4SLinus Torvalds print "<refsect1>\n"; 13331da177e4SLinus Torvalds print " <title>Constants</title>\n"; 13341da177e4SLinus Torvalds print " <variablelist>\n"; 13351da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13361da177e4SLinus Torvalds my $parameter_name = $parameter; 13371da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 13381da177e4SLinus Torvalds 13391da177e4SLinus Torvalds print " <varlistentry>"; 13401da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 13411da177e4SLinus Torvalds print " <listitem><para>\n"; 13421da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 13431da177e4SLinus Torvalds print " </para></listitem>\n"; 13441da177e4SLinus Torvalds print " </varlistentry>\n"; 13451da177e4SLinus Torvalds } 13461da177e4SLinus Torvalds print " </variablelist>\n"; 13471da177e4SLinus Torvalds print "</refsect1>\n"; 13481da177e4SLinus Torvalds 13491da177e4SLinus Torvalds output_section_xml(@_); 13501da177e4SLinus Torvalds 13511da177e4SLinus Torvalds print "</refentry>\n\n"; 13521da177e4SLinus Torvalds} 13531da177e4SLinus Torvalds 13541da177e4SLinus Torvalds# output typedef in XML DocBook 13551da177e4SLinus Torvaldssub output_typedef_xml(%) { 13561da177e4SLinus Torvalds my %args = %{$_[0]}; 13571da177e4SLinus Torvalds my ($parameter, $section); 13581da177e4SLinus Torvalds my $id; 13591da177e4SLinus Torvalds 13601da177e4SLinus Torvalds $id = "API-typedef-" . $args{'typedef'}; 13611da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13621da177e4SLinus Torvalds 13635449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 13648b0c2d98SMartin Waitz print "<refentryinfo>\n"; 13658b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 13668b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 13678b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 13688b0c2d98SMartin Waitz print "</refentryinfo>\n"; 13691da177e4SLinus Torvalds print "<refmeta>\n"; 13705449bc94SPavel Pisa print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; 13718b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 13721da177e4SLinus Torvalds print "</refmeta>\n"; 13731da177e4SLinus Torvalds print "<refnamediv>\n"; 13741da177e4SLinus Torvalds print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; 13751da177e4SLinus Torvalds print " <refpurpose>\n"; 13761da177e4SLinus Torvalds print " "; 13771da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 13781da177e4SLinus Torvalds print " </refpurpose>\n"; 13791da177e4SLinus Torvalds print "</refnamediv>\n"; 13801da177e4SLinus Torvalds 13811da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 13821da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 13831da177e4SLinus Torvalds print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; 13841da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 13851da177e4SLinus Torvalds 13861da177e4SLinus Torvalds output_section_xml(@_); 13871da177e4SLinus Torvalds 13881da177e4SLinus Torvalds print "</refentry>\n\n"; 13891da177e4SLinus Torvalds} 13901da177e4SLinus Torvalds 13911da177e4SLinus Torvalds# output in XML DocBook 1392b112e0f7SJohannes Bergsub output_blockhead_xml(%) { 13931da177e4SLinus Torvalds my %args = %{$_[0]}; 13941da177e4SLinus Torvalds my ($parameter, $section); 13951da177e4SLinus Torvalds my $count; 13961da177e4SLinus Torvalds 13971da177e4SLinus Torvalds my $id = $args{'module'}; 13981da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13991da177e4SLinus Torvalds 14001da177e4SLinus Torvalds # print out each section 14011da177e4SLinus Torvalds $lineprefix=" "; 14021da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1403b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1404b112e0f7SJohannes Berg print "<refsect1>\n <title>$section</title>\n"; 1405b112e0f7SJohannes Berg } 14061da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 14071da177e4SLinus Torvalds print "<example><para>\n"; 1408e314ba31SDaniel Santos $output_preformatted = 1; 1409b112e0f7SJohannes Berg } else { 1410b112e0f7SJohannes Berg print "<para>\n"; 14111da177e4SLinus Torvalds } 14121da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1413e314ba31SDaniel Santos $output_preformatted = 0; 14141da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 14151da177e4SLinus Torvalds print "</para></example>\n"; 1416b112e0f7SJohannes Berg } else { 1417b112e0f7SJohannes Berg print "</para>"; 14181da177e4SLinus Torvalds } 1419b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1420b112e0f7SJohannes Berg print "\n</refsect1>\n"; 1421b112e0f7SJohannes Berg } 14221da177e4SLinus Torvalds } 14231da177e4SLinus Torvalds 14241da177e4SLinus Torvalds print "\n\n"; 14251da177e4SLinus Torvalds} 14261da177e4SLinus Torvalds 14271da177e4SLinus Torvalds# output in XML DocBook 14281da177e4SLinus Torvaldssub output_function_gnome { 14291da177e4SLinus Torvalds my %args = %{$_[0]}; 14301da177e4SLinus Torvalds my ($parameter, $section); 14311da177e4SLinus Torvalds my $count; 14321da177e4SLinus Torvalds my $id; 14331da177e4SLinus Torvalds 14341da177e4SLinus Torvalds $id = $args{'module'} . "-" . $args{'function'}; 14351da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 14361da177e4SLinus Torvalds 14371da177e4SLinus Torvalds print "<sect2>\n"; 14381da177e4SLinus Torvalds print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; 14391da177e4SLinus Torvalds 14401da177e4SLinus Torvalds print " <funcsynopsis>\n"; 14411da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 14421da177e4SLinus Torvalds print "<function>" . $args{'function'} . " "; 14431da177e4SLinus Torvalds print "</function></funcdef>\n"; 14441da177e4SLinus Torvalds 14451da177e4SLinus Torvalds $count = 0; 14461da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 14471da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14481da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 14491da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 14501da177e4SLinus Torvalds # pointer-to-function 14511da177e4SLinus Torvalds print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; 14521da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 14531da177e4SLinus Torvalds } else { 14541da177e4SLinus Torvalds print " <paramdef>" . $type; 14551da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 14561da177e4SLinus Torvalds } 14571da177e4SLinus Torvalds } 14581da177e4SLinus Torvalds } else { 14591da177e4SLinus Torvalds print " <void>\n"; 14601da177e4SLinus Torvalds } 14611da177e4SLinus Torvalds print " </funcsynopsis>\n"; 14621da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 14631da177e4SLinus Torvalds print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; 14641da177e4SLinus Torvalds print "<tgroup cols=\"2\">\n"; 14651da177e4SLinus Torvalds print "<colspec colwidth=\"2*\">\n"; 14661da177e4SLinus Torvalds print "<colspec colwidth=\"8*\">\n"; 14671da177e4SLinus Torvalds print "<tbody>\n"; 14681da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14691da177e4SLinus Torvalds my $parameter_name = $parameter; 14701da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14711da177e4SLinus Torvalds 14721da177e4SLinus Torvalds print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; 14731da177e4SLinus Torvalds print " <entry>\n"; 14741da177e4SLinus Torvalds $lineprefix=" "; 14751da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14761da177e4SLinus Torvalds print " </entry></row>\n"; 14771da177e4SLinus Torvalds } 14781da177e4SLinus Torvalds print " </tbody></tgroup></informaltable>\n"; 14791da177e4SLinus Torvalds } else { 14801da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 14811da177e4SLinus Torvalds } 14821da177e4SLinus Torvalds 14831da177e4SLinus Torvalds # print out each section 14841da177e4SLinus Torvalds $lineprefix=" "; 14851da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14861da177e4SLinus Torvalds print "<simplesect>\n <title>$section</title>\n"; 14871da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 14881da177e4SLinus Torvalds print "<example><programlisting>\n"; 1489e314ba31SDaniel Santos $output_preformatted = 1; 14901da177e4SLinus Torvalds } else { 14911da177e4SLinus Torvalds } 14921da177e4SLinus Torvalds print "<para>\n"; 14931da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1494e314ba31SDaniel Santos $output_preformatted = 0; 14951da177e4SLinus Torvalds print "</para>\n"; 14961da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 14971da177e4SLinus Torvalds print "</programlisting></example>\n"; 14981da177e4SLinus Torvalds } else { 14991da177e4SLinus Torvalds } 15001da177e4SLinus Torvalds print " </simplesect>\n"; 15011da177e4SLinus Torvalds } 15021da177e4SLinus Torvalds 15031da177e4SLinus Torvalds print "</sect2>\n\n"; 15041da177e4SLinus Torvalds} 15051da177e4SLinus Torvalds 15061da177e4SLinus Torvalds## 15071da177e4SLinus Torvalds# output function in man 15081da177e4SLinus Torvaldssub output_function_man(%) { 15091da177e4SLinus Torvalds my %args = %{$_[0]}; 15101da177e4SLinus Torvalds my ($parameter, $section); 15111da177e4SLinus Torvalds my $count; 15121da177e4SLinus Torvalds 15131da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 15141da177e4SLinus Torvalds 15151da177e4SLinus Torvalds print ".SH NAME\n"; 15161da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 15171da177e4SLinus Torvalds 15181da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 1519a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 15201da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 1521a21217daSRandy Dunlap } else { 1522a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 1523a21217daSRandy Dunlap } 15241da177e4SLinus Torvalds $count = 0; 15251da177e4SLinus Torvalds my $parenth = "("; 15261da177e4SLinus Torvalds my $post = ","; 15271da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15281da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 15291da177e4SLinus Torvalds $post = ");"; 15301da177e4SLinus Torvalds } 15311da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 15321da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 15331da177e4SLinus Torvalds # pointer-to-function 15341da177e4SLinus Torvalds print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 15351da177e4SLinus Torvalds } else { 15361da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 15371da177e4SLinus Torvalds print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 15381da177e4SLinus Torvalds } 15391da177e4SLinus Torvalds $count++; 15401da177e4SLinus Torvalds $parenth = ""; 15411da177e4SLinus Torvalds } 15421da177e4SLinus Torvalds 15431da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 15441da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15451da177e4SLinus Torvalds my $parameter_name = $parameter; 15461da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15471da177e4SLinus Torvalds 15481da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 15491da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 15501da177e4SLinus Torvalds } 15511da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15521da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 15531da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15541da177e4SLinus Torvalds } 15551da177e4SLinus Torvalds} 15561da177e4SLinus Torvalds 15571da177e4SLinus Torvalds## 15581da177e4SLinus Torvalds# output enum in man 15591da177e4SLinus Torvaldssub output_enum_man(%) { 15601da177e4SLinus Torvalds my %args = %{$_[0]}; 15611da177e4SLinus Torvalds my ($parameter, $section); 15621da177e4SLinus Torvalds my $count; 15631da177e4SLinus Torvalds 15641da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 15651da177e4SLinus Torvalds 15661da177e4SLinus Torvalds print ".SH NAME\n"; 15671da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 15681da177e4SLinus Torvalds 15691da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 15701da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 15711da177e4SLinus Torvalds $count = 0; 15721da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15731da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 15741da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 15751da177e4SLinus Torvalds print "\n};\n"; 15761da177e4SLinus Torvalds last; 15771da177e4SLinus Torvalds } 15781da177e4SLinus Torvalds else { 15791da177e4SLinus Torvalds print ", \n.br\n"; 15801da177e4SLinus Torvalds } 15811da177e4SLinus Torvalds $count++; 15821da177e4SLinus Torvalds } 15831da177e4SLinus Torvalds 15841da177e4SLinus Torvalds print ".SH Constants\n"; 15851da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15861da177e4SLinus Torvalds my $parameter_name = $parameter; 15871da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15881da177e4SLinus Torvalds 15891da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 15901da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 15911da177e4SLinus Torvalds } 15921da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15931da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15941da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15951da177e4SLinus Torvalds } 15961da177e4SLinus Torvalds} 15971da177e4SLinus Torvalds 15981da177e4SLinus Torvalds## 15991da177e4SLinus Torvalds# output struct in man 16001da177e4SLinus Torvaldssub output_struct_man(%) { 16011da177e4SLinus Torvalds my %args = %{$_[0]}; 16021da177e4SLinus Torvalds my ($parameter, $section); 16031da177e4SLinus Torvalds 16041da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 16051da177e4SLinus Torvalds 16061da177e4SLinus Torvalds print ".SH NAME\n"; 16071da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 16081da177e4SLinus Torvalds 16091da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 16101da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 16111da177e4SLinus Torvalds 16121da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 16131da177e4SLinus Torvalds if ($parameter =~ /^#/) { 16141da177e4SLinus Torvalds print ".BI \"$parameter\"\n.br\n"; 16151da177e4SLinus Torvalds next; 16161da177e4SLinus Torvalds } 16171da177e4SLinus Torvalds my $parameter_name = $parameter; 16181da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16191da177e4SLinus Torvalds 16201da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 16211da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 16221da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 16231da177e4SLinus Torvalds # pointer-to-function 16241da177e4SLinus Torvalds print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; 16251da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 16261d7e1d45SRandy.Dunlap # bitfield 16271d7e1d45SRandy.Dunlap print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; 16281da177e4SLinus Torvalds } else { 16291da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 16301da177e4SLinus Torvalds print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; 16311da177e4SLinus Torvalds } 16321da177e4SLinus Torvalds print "\n.br\n"; 16331da177e4SLinus Torvalds } 16341da177e4SLinus Torvalds print "};\n.br\n"; 16351da177e4SLinus Torvalds 1636c51d3dacSRandy Dunlap print ".SH Members\n"; 16371da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16381da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 16391da177e4SLinus Torvalds 16401da177e4SLinus Torvalds my $parameter_name = $parameter; 16411da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16421da177e4SLinus Torvalds 16431da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 16441da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 16451da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 16461da177e4SLinus Torvalds } 16471da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16481da177e4SLinus Torvalds print ".SH \"$section\"\n"; 16491da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16501da177e4SLinus Torvalds } 16511da177e4SLinus Torvalds} 16521da177e4SLinus Torvalds 16531da177e4SLinus Torvalds## 16541da177e4SLinus Torvalds# output typedef in man 16551da177e4SLinus Torvaldssub output_typedef_man(%) { 16561da177e4SLinus Torvalds my %args = %{$_[0]}; 16571da177e4SLinus Torvalds my ($parameter, $section); 16581da177e4SLinus Torvalds 16591da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 16601da177e4SLinus Torvalds 16611da177e4SLinus Torvalds print ".SH NAME\n"; 16621da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 16631da177e4SLinus Torvalds 16641da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16651da177e4SLinus Torvalds print ".SH \"$section\"\n"; 16661da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16671da177e4SLinus Torvalds } 16681da177e4SLinus Torvalds} 16691da177e4SLinus Torvalds 1670b112e0f7SJohannes Bergsub output_blockhead_man(%) { 16711da177e4SLinus Torvalds my %args = %{$_[0]}; 16721da177e4SLinus Torvalds my ($parameter, $section); 16731da177e4SLinus Torvalds my $count; 16741da177e4SLinus Torvalds 16751da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 16761da177e4SLinus Torvalds 16771da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16781da177e4SLinus Torvalds print ".SH \"$section\"\n"; 16791da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16801da177e4SLinus Torvalds } 16811da177e4SLinus Torvalds} 16821da177e4SLinus Torvalds 16831da177e4SLinus Torvalds## 16841da177e4SLinus Torvalds# output in text 16851da177e4SLinus Torvaldssub output_function_text(%) { 16861da177e4SLinus Torvalds my %args = %{$_[0]}; 16871da177e4SLinus Torvalds my ($parameter, $section); 1688a21217daSRandy Dunlap my $start; 16891da177e4SLinus Torvalds 1690f47634b2SRandy Dunlap print "Name:\n\n"; 1691f47634b2SRandy Dunlap print $args{'function'} . " - " . $args{'purpose'} . "\n"; 1692f47634b2SRandy Dunlap 1693f47634b2SRandy Dunlap print "\nSynopsis:\n\n"; 1694a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 1695a21217daSRandy Dunlap $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1696a21217daSRandy Dunlap } else { 1697a21217daSRandy Dunlap $start = $args{'function'} . " ("; 1698a21217daSRandy Dunlap } 16991da177e4SLinus Torvalds print $start; 1700a21217daSRandy Dunlap 17011da177e4SLinus Torvalds my $count = 0; 17021da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 17031da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 17041da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 17051da177e4SLinus Torvalds # pointer-to-function 17061da177e4SLinus Torvalds print $1 . $parameter . ") (" . $2; 17071da177e4SLinus Torvalds } else { 17081da177e4SLinus Torvalds print $type . " " . $parameter; 17091da177e4SLinus Torvalds } 17101da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 17111da177e4SLinus Torvalds $count++; 17121da177e4SLinus Torvalds print ",\n"; 17131da177e4SLinus Torvalds print " " x length($start); 17141da177e4SLinus Torvalds } else { 17151da177e4SLinus Torvalds print ");\n\n"; 17161da177e4SLinus Torvalds } 17171da177e4SLinus Torvalds } 17181da177e4SLinus Torvalds 17191da177e4SLinus Torvalds print "Arguments:\n\n"; 17201da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17211da177e4SLinus Torvalds my $parameter_name = $parameter; 17221da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 17231da177e4SLinus Torvalds 17241da177e4SLinus Torvalds print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; 17251da177e4SLinus Torvalds } 17261da177e4SLinus Torvalds output_section_text(@_); 17271da177e4SLinus Torvalds} 17281da177e4SLinus Torvalds 17291da177e4SLinus Torvalds#output sections in text 17301da177e4SLinus Torvaldssub output_section_text(%) { 17311da177e4SLinus Torvalds my %args = %{$_[0]}; 17321da177e4SLinus Torvalds my $section; 17331da177e4SLinus Torvalds 17341da177e4SLinus Torvalds print "\n"; 17351da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 17361da177e4SLinus Torvalds print "$section:\n\n"; 17371da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 17381da177e4SLinus Torvalds } 17391da177e4SLinus Torvalds print "\n\n"; 17401da177e4SLinus Torvalds} 17411da177e4SLinus Torvalds 17421da177e4SLinus Torvalds# output enum in text 17431da177e4SLinus Torvaldssub output_enum_text(%) { 17441da177e4SLinus Torvalds my %args = %{$_[0]}; 17451da177e4SLinus Torvalds my ($parameter); 17461da177e4SLinus Torvalds my $count; 17471da177e4SLinus Torvalds print "Enum:\n\n"; 17481da177e4SLinus Torvalds 17491d7e1d45SRandy.Dunlap print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; 17501da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 17511da177e4SLinus Torvalds $count = 0; 17521da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17531da177e4SLinus Torvalds print "\t$parameter"; 17541da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 17551da177e4SLinus Torvalds $count++; 17561da177e4SLinus Torvalds print ","; 17571da177e4SLinus Torvalds } 17581da177e4SLinus Torvalds print "\n"; 17591da177e4SLinus Torvalds } 17601da177e4SLinus Torvalds print "};\n\n"; 17611da177e4SLinus Torvalds 17621da177e4SLinus Torvalds print "Constants:\n\n"; 17631da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17641da177e4SLinus Torvalds print "$parameter\n\t"; 17651da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter} . "\n"; 17661da177e4SLinus Torvalds } 17671da177e4SLinus Torvalds 17681da177e4SLinus Torvalds output_section_text(@_); 17691da177e4SLinus Torvalds} 17701da177e4SLinus Torvalds 17711da177e4SLinus Torvalds# output typedef in text 17721da177e4SLinus Torvaldssub output_typedef_text(%) { 17731da177e4SLinus Torvalds my %args = %{$_[0]}; 17741da177e4SLinus Torvalds my ($parameter); 17751da177e4SLinus Torvalds my $count; 17761da177e4SLinus Torvalds print "Typedef:\n\n"; 17771da177e4SLinus Torvalds 17781d7e1d45SRandy.Dunlap print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; 17791da177e4SLinus Torvalds output_section_text(@_); 17801da177e4SLinus Torvalds} 17811da177e4SLinus Torvalds 17821da177e4SLinus Torvalds# output struct as text 17831da177e4SLinus Torvaldssub output_struct_text(%) { 17841da177e4SLinus Torvalds my %args = %{$_[0]}; 17851da177e4SLinus Torvalds my ($parameter); 17861da177e4SLinus Torvalds 17871d7e1d45SRandy.Dunlap print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; 17881da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 17891da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17901da177e4SLinus Torvalds if ($parameter =~ /^#/) { 17911da177e4SLinus Torvalds print "$parameter\n"; 17921da177e4SLinus Torvalds next; 17931da177e4SLinus Torvalds } 17941da177e4SLinus Torvalds 17951da177e4SLinus Torvalds my $parameter_name = $parameter; 17961da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 17971da177e4SLinus Torvalds 17981da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 17991da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 18001da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 18011da177e4SLinus Torvalds # pointer-to-function 18021da177e4SLinus Torvalds print "\t$1 $parameter) ($2);\n"; 18031da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 180451f5a0c8SRandy Dunlap # bitfield 18051da177e4SLinus Torvalds print "\t$1 $parameter$2;\n"; 18061da177e4SLinus Torvalds } else { 18071da177e4SLinus Torvalds print "\t" . $type . " " . $parameter . ";\n"; 18081da177e4SLinus Torvalds } 18091da177e4SLinus Torvalds } 18101da177e4SLinus Torvalds print "};\n\n"; 18111da177e4SLinus Torvalds 18121da177e4SLinus Torvalds print "Members:\n\n"; 18131da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 18141da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 18151da177e4SLinus Torvalds 18161da177e4SLinus Torvalds my $parameter_name = $parameter; 18171da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 18181da177e4SLinus Torvalds 18191da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 18201da177e4SLinus Torvalds print "$parameter\n\t"; 18211da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter_name} . "\n"; 18221da177e4SLinus Torvalds } 18231da177e4SLinus Torvalds print "\n"; 18241da177e4SLinus Torvalds output_section_text(@_); 18251da177e4SLinus Torvalds} 18261da177e4SLinus Torvalds 1827b112e0f7SJohannes Bergsub output_blockhead_text(%) { 18281da177e4SLinus Torvalds my %args = %{$_[0]}; 18291da177e4SLinus Torvalds my ($parameter, $section); 18301da177e4SLinus Torvalds 18311da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 18321da177e4SLinus Torvalds print " $section:\n"; 18331da177e4SLinus Torvalds print " -> "; 18341da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 18351da177e4SLinus Torvalds } 18361da177e4SLinus Torvalds} 18371da177e4SLinus Torvalds 1838c0d1b6eeSJonathan Corbet## 1839c0d1b6eeSJonathan Corbet# output in restructured text 1840c0d1b6eeSJonathan Corbet# 1841c0d1b6eeSJonathan Corbet 1842c0d1b6eeSJonathan Corbet# 1843c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 1844c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 1845c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 1846c0d1b6eeSJonathan Corbet# 1847c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 1848c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1849c0d1b6eeSJonathan Corbet my ($parameter, $section); 1850c0d1b6eeSJonathan Corbet 1851c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 18529e72184bSJani Nikula if ($output_selection != OUTPUT_INCLUDE) { 1853c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 18549e72184bSJani Nikula } 18550b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 1856c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1857c0d1b6eeSJonathan Corbet print "\n"; 1858c0d1b6eeSJonathan Corbet } 1859c0d1b6eeSJonathan Corbet} 1860c0d1b6eeSJonathan Corbet 1861c0d1b6eeSJonathan Corbetsub output_highlight_rst { 1862c0d1b6eeSJonathan Corbet my $contents = join "\n",@_; 1863c0d1b6eeSJonathan Corbet my $line; 1864c0d1b6eeSJonathan Corbet 1865c0d1b6eeSJonathan Corbet # undo the evil effects of xml_escape() earlier 1866c0d1b6eeSJonathan Corbet $contents = xml_unescape($contents); 1867c0d1b6eeSJonathan Corbet 1868c0d1b6eeSJonathan Corbet eval $dohighlight; 1869c0d1b6eeSJonathan Corbet die $@ if $@; 1870c0d1b6eeSJonathan Corbet 1871c0d1b6eeSJonathan Corbet foreach $line (split "\n", $contents) { 1872830066a7SJani Nikula print $lineprefix . $line . "\n"; 1873c0d1b6eeSJonathan Corbet } 1874c0d1b6eeSJonathan Corbet} 1875c0d1b6eeSJonathan Corbet 1876c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 1877c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1878c0d1b6eeSJonathan Corbet my ($parameter, $section); 1879c099ff69SJani Nikula my $oldprefix = $lineprefix; 188082801d06SMauro Carvalho Chehab my $start = ""; 1881c0d1b6eeSJonathan Corbet 188282801d06SMauro Carvalho Chehab if ($args{'typedef'}) { 188382801d06SMauro Carvalho Chehab print ".. c:type:: ". $args{'function'} . "\n\n"; 188482801d06SMauro Carvalho Chehab print_lineno($declaration_start_line); 188582801d06SMauro Carvalho Chehab print " **Typedef**: "; 188682801d06SMauro Carvalho Chehab $lineprefix = ""; 188782801d06SMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 188882801d06SMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 1889c0d1b6eeSJonathan Corbet } else { 189082801d06SMauro Carvalho Chehab print ".. c:function:: "; 189182801d06SMauro Carvalho Chehab } 189282801d06SMauro Carvalho Chehab if ($args{'functiontype'} ne "") { 189382801d06SMauro Carvalho Chehab $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; 189482801d06SMauro Carvalho Chehab } else { 189582801d06SMauro Carvalho Chehab $start .= $args{'function'} . " ("; 1896c0d1b6eeSJonathan Corbet } 1897c0d1b6eeSJonathan Corbet print $start; 1898c0d1b6eeSJonathan Corbet 1899c0d1b6eeSJonathan Corbet my $count = 0; 1900c0d1b6eeSJonathan Corbet foreach my $parameter (@{$args{'parameterlist'}}) { 1901c0d1b6eeSJonathan Corbet if ($count ne 0) { 1902c0d1b6eeSJonathan Corbet print ", "; 1903c0d1b6eeSJonathan Corbet } 1904c0d1b6eeSJonathan Corbet $count++; 1905c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1906a88b1672SMauro Carvalho Chehab 1907c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1908c0d1b6eeSJonathan Corbet # pointer-to-function 1909c0d1b6eeSJonathan Corbet print $1 . $parameter . ") (" . $2; 1910c0d1b6eeSJonathan Corbet } else { 1911c0d1b6eeSJonathan Corbet print $type . " " . $parameter; 1912c0d1b6eeSJonathan Corbet } 1913c0d1b6eeSJonathan Corbet } 191482801d06SMauro Carvalho Chehab if ($args{'typedef'}) { 191582801d06SMauro Carvalho Chehab print ");``\n\n"; 191682801d06SMauro Carvalho Chehab } else { 1917c099ff69SJani Nikula print ")\n\n"; 19180b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1919c099ff69SJani Nikula $lineprefix = " "; 1920c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1921c099ff69SJani Nikula print "\n"; 192282801d06SMauro Carvalho Chehab } 1923c0d1b6eeSJonathan Corbet 1924ecbcfba1SJani Nikula print "**Parameters**\n\n"; 1925c099ff69SJani Nikula $lineprefix = " "; 1926c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1927c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1928c0d1b6eeSJonathan Corbet #$parameter_name =~ s/\[.*//; 1929c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1930c0d1b6eeSJonathan Corbet 1931c0d1b6eeSJonathan Corbet if ($type ne "") { 1932c0d1b6eeSJonathan Corbet print "``$type $parameter``\n"; 1933c0d1b6eeSJonathan Corbet } else { 1934c0d1b6eeSJonathan Corbet print "``$parameter``\n"; 1935c0d1b6eeSJonathan Corbet } 19360b0f5f29SDaniel Vetter 19370b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 19380b0f5f29SDaniel Vetter 19395e64fa9cSJani Nikula if (defined($args{'parameterdescs'}{$parameter_name}) && 19405e64fa9cSJani Nikula $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 1941c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1942c0d1b6eeSJonathan Corbet } else { 1943d4b08e0cSJani Nikula print " *undescribed*\n"; 1944c0d1b6eeSJonathan Corbet } 1945c0d1b6eeSJonathan Corbet print "\n"; 1946c0d1b6eeSJonathan Corbet } 1947c099ff69SJani Nikula 1948c099ff69SJani Nikula $lineprefix = $oldprefix; 1949c0d1b6eeSJonathan Corbet output_section_rst(@_); 1950c0d1b6eeSJonathan Corbet} 1951c0d1b6eeSJonathan Corbet 1952c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 1953c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1954c0d1b6eeSJonathan Corbet my $section; 1955c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1956c0d1b6eeSJonathan Corbet $lineprefix = ""; 1957c0d1b6eeSJonathan Corbet 1958c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 1959ecbcfba1SJani Nikula print "**$section**\n\n"; 19600b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 1961c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1962c0d1b6eeSJonathan Corbet print "\n"; 1963c0d1b6eeSJonathan Corbet } 1964c0d1b6eeSJonathan Corbet print "\n"; 1965c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1966c0d1b6eeSJonathan Corbet} 1967c0d1b6eeSJonathan Corbet 1968c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 1969c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1970c0d1b6eeSJonathan Corbet my ($parameter); 1971c099ff69SJani Nikula my $oldprefix = $lineprefix; 1972c0d1b6eeSJonathan Corbet my $count; 1973c0d1b6eeSJonathan Corbet my $name = "enum " . $args{'enum'}; 197462850976SJani Nikula 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 "**Constants**\n\n"; 1982c0d1b6eeSJonathan Corbet $lineprefix = " "; 1983c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1984ecbcfba1SJani Nikula print "``$parameter``\n"; 1985c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 1986c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 1987c0d1b6eeSJonathan Corbet } else { 1988d4b08e0cSJani Nikula print " *undescribed*\n"; 1989c0d1b6eeSJonathan Corbet } 1990c0d1b6eeSJonathan Corbet print "\n"; 1991c0d1b6eeSJonathan Corbet } 1992c099ff69SJani Nikula 1993c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1994c0d1b6eeSJonathan Corbet output_section_rst(@_); 1995c0d1b6eeSJonathan Corbet} 1996c0d1b6eeSJonathan Corbet 1997c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 1998c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1999c0d1b6eeSJonathan Corbet my ($parameter); 2000c099ff69SJani Nikula my $oldprefix = $lineprefix; 2001c0d1b6eeSJonathan Corbet my $name = "typedef " . $args{'typedef'}; 2002c0d1b6eeSJonathan Corbet 200362850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 20040b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 2005c099ff69SJani Nikula $lineprefix = " "; 2006c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 2007c099ff69SJani Nikula print "\n"; 2008c0d1b6eeSJonathan Corbet 2009c099ff69SJani Nikula $lineprefix = $oldprefix; 2010c0d1b6eeSJonathan Corbet output_section_rst(@_); 2011c0d1b6eeSJonathan Corbet} 2012c0d1b6eeSJonathan Corbet 2013c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 2014c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 2015c0d1b6eeSJonathan Corbet my ($parameter); 2016c099ff69SJani Nikula my $oldprefix = $lineprefix; 2017c0d1b6eeSJonathan Corbet my $name = $args{'type'} . " " . $args{'struct'}; 2018c0d1b6eeSJonathan Corbet 201962850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 20200b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 2021c099ff69SJani Nikula $lineprefix = " "; 2022c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 2023c099ff69SJani Nikula print "\n"; 2024c0d1b6eeSJonathan Corbet 2025ecbcfba1SJani Nikula print "**Definition**\n\n"; 2026c0d1b6eeSJonathan Corbet print "::\n\n"; 2027c0d1b6eeSJonathan Corbet print " " . $args{'type'} . " " . $args{'struct'} . " {\n"; 2028c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 2029c0d1b6eeSJonathan Corbet if ($parameter =~ /^#/) { 2030c0d1b6eeSJonathan Corbet print " " . "$parameter\n"; 2031c0d1b6eeSJonathan Corbet next; 2032c0d1b6eeSJonathan Corbet } 2033c0d1b6eeSJonathan Corbet 2034c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 2035c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 2036c0d1b6eeSJonathan Corbet 2037c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 2038c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 2039c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 2040c0d1b6eeSJonathan Corbet # pointer-to-function 2041c0d1b6eeSJonathan Corbet print " $1 $parameter) ($2);\n"; 2042c0d1b6eeSJonathan Corbet } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 2043c0d1b6eeSJonathan Corbet # bitfield 2044c0d1b6eeSJonathan Corbet print " $1 $parameter$2;\n"; 2045c0d1b6eeSJonathan Corbet } else { 2046c0d1b6eeSJonathan Corbet print " " . $type . " " . $parameter . ";\n"; 2047c0d1b6eeSJonathan Corbet } 2048c0d1b6eeSJonathan Corbet } 2049c0d1b6eeSJonathan Corbet print " };\n\n"; 2050c0d1b6eeSJonathan Corbet 2051ecbcfba1SJani Nikula print "**Members**\n\n"; 2052c099ff69SJani Nikula $lineprefix = " "; 2053c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 2054c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 2055c0d1b6eeSJonathan Corbet 2056c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 2057c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 2058c0d1b6eeSJonathan Corbet 2059c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 2060c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 20610b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 20626d232c80SMauro Carvalho Chehab print "``" . $parameter . "``\n"; 2063c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 2064c0d1b6eeSJonathan Corbet print "\n"; 2065c0d1b6eeSJonathan Corbet } 2066c0d1b6eeSJonathan Corbet print "\n"; 2067c099ff69SJani Nikula 2068c099ff69SJani Nikula $lineprefix = $oldprefix; 2069c0d1b6eeSJonathan Corbet output_section_rst(@_); 2070c0d1b6eeSJonathan Corbet} 2071c0d1b6eeSJonathan Corbet 2072c0d1b6eeSJonathan Corbet 2073eda603f6SJohannes Berg## list mode output functions 2074eda603f6SJohannes Berg 2075eda603f6SJohannes Bergsub output_function_list(%) { 2076eda603f6SJohannes Berg my %args = %{$_[0]}; 2077eda603f6SJohannes Berg 2078eda603f6SJohannes Berg print $args{'function'} . "\n"; 2079eda603f6SJohannes Berg} 2080eda603f6SJohannes Berg 2081eda603f6SJohannes Berg# output enum in list 2082eda603f6SJohannes Bergsub output_enum_list(%) { 2083eda603f6SJohannes Berg my %args = %{$_[0]}; 2084eda603f6SJohannes Berg print $args{'enum'} . "\n"; 2085eda603f6SJohannes Berg} 2086eda603f6SJohannes Berg 2087eda603f6SJohannes Berg# output typedef in list 2088eda603f6SJohannes Bergsub output_typedef_list(%) { 2089eda603f6SJohannes Berg my %args = %{$_[0]}; 2090eda603f6SJohannes Berg print $args{'typedef'} . "\n"; 2091eda603f6SJohannes Berg} 2092eda603f6SJohannes Berg 2093eda603f6SJohannes Berg# output struct as list 2094eda603f6SJohannes Bergsub output_struct_list(%) { 2095eda603f6SJohannes Berg my %args = %{$_[0]}; 2096eda603f6SJohannes Berg 2097eda603f6SJohannes Berg print $args{'struct'} . "\n"; 2098eda603f6SJohannes Berg} 2099eda603f6SJohannes Berg 2100eda603f6SJohannes Bergsub output_blockhead_list(%) { 2101eda603f6SJohannes Berg my %args = %{$_[0]}; 2102eda603f6SJohannes Berg my ($parameter, $section); 2103eda603f6SJohannes Berg 2104eda603f6SJohannes Berg foreach $section (@{$args{'sectionlist'}}) { 2105eda603f6SJohannes Berg print "DOC: $section\n"; 2106eda603f6SJohannes Berg } 2107eda603f6SJohannes Berg} 2108eda603f6SJohannes Berg 21091da177e4SLinus Torvalds## 211027205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 211127205744SRandy Dunlap# calls the generated, variable output_ function name based on 211227205744SRandy Dunlap# functype and output_mode 21131da177e4SLinus Torvaldssub output_declaration { 21141da177e4SLinus Torvalds no strict 'refs'; 21151da177e4SLinus Torvalds my $name = shift; 21161da177e4SLinus Torvalds my $functype = shift; 21171da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 2118b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 2119b6c3f456SJani Nikula (($output_selection == OUTPUT_INCLUDE || 2120b6c3f456SJani Nikula $output_selection == OUTPUT_EXPORTED) && 212186ae2e38SJani Nikula defined($function_table{$name})) || 2122b6c3f456SJani Nikula (($output_selection == OUTPUT_EXCLUDE || 2123b6c3f456SJani Nikula $output_selection == OUTPUT_INTERNAL) && 212486ae2e38SJani Nikula !($functype eq "function" && defined($function_table{$name})))) 21251da177e4SLinus Torvalds { 21261da177e4SLinus Torvalds &$func(@_); 21271da177e4SLinus Torvalds $section_counter++; 21281da177e4SLinus Torvalds } 21291da177e4SLinus Torvalds} 21301da177e4SLinus Torvalds 21311da177e4SLinus Torvalds## 213227205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 2133b112e0f7SJohannes Bergsub output_blockhead { 21341da177e4SLinus Torvalds no strict 'refs'; 2135b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 21361da177e4SLinus Torvalds &$func(@_); 21371da177e4SLinus Torvalds $section_counter++; 21381da177e4SLinus Torvalds} 21391da177e4SLinus Torvalds 21401da177e4SLinus Torvalds## 21411da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 21421da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 21431da177e4SLinus Torvaldssub dump_declaration($$) { 21441da177e4SLinus Torvalds no strict 'refs'; 21451da177e4SLinus Torvalds my ($prototype, $file) = @_; 21461da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 21471da177e4SLinus Torvalds &$func(@_); 21481da177e4SLinus Torvalds} 21491da177e4SLinus Torvalds 21501da177e4SLinus Torvaldssub dump_union($$) { 21511da177e4SLinus Torvalds dump_struct(@_); 21521da177e4SLinus Torvalds} 21531da177e4SLinus Torvalds 21541da177e4SLinus Torvaldssub dump_struct($$) { 21551da177e4SLinus Torvalds my $x = shift; 21561da177e4SLinus Torvalds my $file = shift; 2157a1d94aa5SRandy Dunlap my $nested; 21581da177e4SLinus Torvalds 21591da177e4SLinus Torvalds if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 216052dc5aecSRandy Dunlap #my $decl_type = $1; 21611da177e4SLinus Torvalds $declaration_name = $2; 21621da177e4SLinus Torvalds my $members = $3; 21631da177e4SLinus Torvalds 21641da177e4SLinus Torvalds # ignore embedded structs or unions 2165a1d94aa5SRandy Dunlap $members =~ s/({.*})//g; 2166a1d94aa5SRandy Dunlap $nested = $1; 21671da177e4SLinus Torvalds 2168aeec46b9SMartin Waitz # ignore members marked private: 21690d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 21700d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 2171aeec46b9SMartin Waitz # strip comments: 2172aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 2173a1d94aa5SRandy Dunlap $nested =~ s/\/\*.*?\*\///gos; 2174d960eea9SRandy Dunlap # strip kmemcheck_bitfield_{begin,end}.*; 2175d960eea9SRandy Dunlap $members =~ s/kmemcheck_bitfield_.*?;//gos; 2176ef5da59fSRandy Dunlap # strip attributes 2177f0074929SJonathan Corbet $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 21787b990789SJohannes Berg $members =~ s/__aligned\s*\([^;]*\)//gos; 2179f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; 2180b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 2181b22b5a9eSConchúr Navid $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 2182aeec46b9SMartin Waitz 21831da177e4SLinus Torvalds create_parameterlist($members, ';', $file); 2184a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); 21851da177e4SLinus Torvalds 21861da177e4SLinus Torvalds output_declaration($declaration_name, 21871da177e4SLinus Torvalds 'struct', 21881da177e4SLinus Torvalds {'struct' => $declaration_name, 21891da177e4SLinus Torvalds 'module' => $modulename, 21901da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 21911da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 21921da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 21931da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 21941da177e4SLinus Torvalds 'sections' => \%sections, 21951da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 21961da177e4SLinus Torvalds 'type' => $decl_type 21971da177e4SLinus Torvalds }); 21981da177e4SLinus Torvalds } 21991da177e4SLinus Torvalds else { 2200d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 22011da177e4SLinus Torvalds ++$errors; 22021da177e4SLinus Torvalds } 22031da177e4SLinus Torvalds} 22041da177e4SLinus Torvalds 22051da177e4SLinus Torvaldssub dump_enum($$) { 22061da177e4SLinus Torvalds my $x = shift; 22071da177e4SLinus Torvalds my $file = shift; 22081da177e4SLinus Torvalds 2209aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 22104468e21eSConchúr Navid # strip #define macros inside enums 22114468e21eSConchúr Navid $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 2212b6d676dbSRandy Dunlap 22131da177e4SLinus Torvalds if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 22141da177e4SLinus Torvalds $declaration_name = $1; 22151da177e4SLinus Torvalds my $members = $2; 22161da177e4SLinus Torvalds 22171da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 22181da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 22191da177e4SLinus Torvalds push @parameterlist, $arg; 22201da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 22211da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 2222d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Enum value '$arg' ". 22231da177e4SLinus Torvalds "not described in enum '$declaration_name'\n"; 22241da177e4SLinus Torvalds } 22251da177e4SLinus Torvalds 22261da177e4SLinus Torvalds } 22271da177e4SLinus Torvalds 22281da177e4SLinus Torvalds output_declaration($declaration_name, 22291da177e4SLinus Torvalds 'enum', 22301da177e4SLinus Torvalds {'enum' => $declaration_name, 22311da177e4SLinus Torvalds 'module' => $modulename, 22321da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 22331da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 22341da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 22351da177e4SLinus Torvalds 'sections' => \%sections, 22361da177e4SLinus Torvalds 'purpose' => $declaration_purpose 22371da177e4SLinus Torvalds }); 22381da177e4SLinus Torvalds } 22391da177e4SLinus Torvalds else { 2240d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 22411da177e4SLinus Torvalds ++$errors; 22421da177e4SLinus Torvalds } 22431da177e4SLinus Torvalds} 22441da177e4SLinus Torvalds 22451da177e4SLinus Torvaldssub dump_typedef($$) { 22461da177e4SLinus Torvalds my $x = shift; 22471da177e4SLinus Torvalds my $file = shift; 22481da177e4SLinus Torvalds 2249aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 225083766452SMauro Carvalho Chehab 225183766452SMauro Carvalho Chehab # Parse function prototypes 2252d37c43ceSMauro Carvalho Chehab if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ || 2253d37c43ceSMauro Carvalho Chehab $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) { 2254d37c43ceSMauro Carvalho Chehab 225583766452SMauro Carvalho Chehab # Function typedefs 225683766452SMauro Carvalho Chehab $return_type = $1; 225783766452SMauro Carvalho Chehab $declaration_name = $2; 225883766452SMauro Carvalho Chehab my $args = $3; 225983766452SMauro Carvalho Chehab 226083766452SMauro Carvalho Chehab create_parameterlist($args, ',', $file); 226183766452SMauro Carvalho Chehab 226283766452SMauro Carvalho Chehab output_declaration($declaration_name, 226383766452SMauro Carvalho Chehab 'function', 226483766452SMauro Carvalho Chehab {'function' => $declaration_name, 226582801d06SMauro Carvalho Chehab 'typedef' => 1, 226683766452SMauro Carvalho Chehab 'module' => $modulename, 226783766452SMauro Carvalho Chehab 'functiontype' => $return_type, 226883766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 226983766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 227083766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 227183766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 227283766452SMauro Carvalho Chehab 'sections' => \%sections, 227383766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 227483766452SMauro Carvalho Chehab }); 227583766452SMauro Carvalho Chehab return; 227683766452SMauro Carvalho Chehab } 227783766452SMauro Carvalho Chehab 22781da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 22791da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 22801da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 22811da177e4SLinus Torvalds } 22821da177e4SLinus Torvalds 22831da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 22841da177e4SLinus Torvalds $declaration_name = $1; 22851da177e4SLinus Torvalds 22861da177e4SLinus Torvalds output_declaration($declaration_name, 22871da177e4SLinus Torvalds 'typedef', 22881da177e4SLinus Torvalds {'typedef' => $declaration_name, 22891da177e4SLinus Torvalds 'module' => $modulename, 22901da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 22911da177e4SLinus Torvalds 'sections' => \%sections, 22921da177e4SLinus Torvalds 'purpose' => $declaration_purpose 22931da177e4SLinus Torvalds }); 22941da177e4SLinus Torvalds } 22951da177e4SLinus Torvalds else { 2296d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 22971da177e4SLinus Torvalds ++$errors; 22981da177e4SLinus Torvalds } 22991da177e4SLinus Torvalds} 23001da177e4SLinus Torvalds 2301a1d94aa5SRandy Dunlapsub save_struct_actual($) { 2302a1d94aa5SRandy Dunlap my $actual = shift; 2303a1d94aa5SRandy Dunlap 2304a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 2305a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 2306a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 2307a1d94aa5SRandy Dunlap} 2308a1d94aa5SRandy Dunlap 23091da177e4SLinus Torvaldssub create_parameterlist($$$) { 23101da177e4SLinus Torvalds my $args = shift; 23111da177e4SLinus Torvalds my $splitter = shift; 23121da177e4SLinus Torvalds my $file = shift; 23131da177e4SLinus Torvalds my $type; 23141da177e4SLinus Torvalds my $param; 23151da177e4SLinus Torvalds 2316a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 23171da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 23181da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 23191da177e4SLinus Torvalds } 23201da177e4SLinus Torvalds 23211da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 23221da177e4SLinus Torvalds # strip comments 23231da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 23241da177e4SLinus Torvalds # strip leading/trailing spaces 23251da177e4SLinus Torvalds $arg =~ s/^\s*//; 23261da177e4SLinus Torvalds $arg =~ s/\s*$//; 23271da177e4SLinus Torvalds $arg =~ s/\s+/ /; 23281da177e4SLinus Torvalds 23291da177e4SLinus Torvalds if ($arg =~ /^#/) { 23301da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 23311da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 23321da177e4SLinus Torvalds # output_* subs. 23331da177e4SLinus Torvalds push_parameter($arg, "", $file); 233400d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 23351da177e4SLinus Torvalds # pointer-to-function 23361da177e4SLinus Torvalds $arg =~ tr/#/,/; 233700d62961SRichard Kennedy $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 23381da177e4SLinus Torvalds $param = $1; 23391da177e4SLinus Torvalds $type = $arg; 234000d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 2341a1d94aa5SRandy Dunlap save_struct_actual($param); 23421da177e4SLinus Torvalds push_parameter($param, $type, $file); 2343aeec46b9SMartin Waitz } elsif ($arg) { 23441da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 23451da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 23461da177e4SLinus Torvalds 23471da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 23481da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 23491da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 23501da177e4SLinus Torvalds } 2351884f2810SBorislav Petkov 2352884f2810SBorislav Petkov my @first_arg; 2353884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 2354884f2810SBorislav Petkov shift @args; 2355884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 2356884f2810SBorislav Petkov push(@first_arg, $2); 2357884f2810SBorislav Petkov } else { 2358884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 2359884f2810SBorislav Petkov } 2360884f2810SBorislav Petkov 23611da177e4SLinus Torvalds unshift(@args, pop @first_arg); 23621da177e4SLinus Torvalds $type = join " ", @first_arg; 23631da177e4SLinus Torvalds 23641da177e4SLinus Torvalds foreach $param (@args) { 23651da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 2366a1d94aa5SRandy Dunlap save_struct_actual($2); 23671da177e4SLinus Torvalds push_parameter($2, "$type $1", $file); 23681da177e4SLinus Torvalds } 23691da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 23707b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 2371a1d94aa5SRandy Dunlap save_struct_actual($1); 23721da177e4SLinus Torvalds push_parameter($1, "$type:$2", $file) 23731da177e4SLinus Torvalds } 23747b97887eSRandy Dunlap } 23751da177e4SLinus Torvalds else { 2376a1d94aa5SRandy Dunlap save_struct_actual($param); 23771da177e4SLinus Torvalds push_parameter($param, $type, $file); 23781da177e4SLinus Torvalds } 23791da177e4SLinus Torvalds } 23801da177e4SLinus Torvalds } 23811da177e4SLinus Torvalds } 23821da177e4SLinus Torvalds} 23831da177e4SLinus Torvalds 23841da177e4SLinus Torvaldssub push_parameter($$$) { 23851da177e4SLinus Torvalds my $param = shift; 23861da177e4SLinus Torvalds my $type = shift; 23871da177e4SLinus Torvalds my $file = shift; 23881da177e4SLinus Torvalds 23895f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 23905f8c7c98SRandy Dunlap ($param eq "}")) { 23915f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 23925f8c7c98SRandy Dunlap } 23935f8c7c98SRandy Dunlap 23945f8c7c98SRandy Dunlap $anon_struct_union = 0; 23951da177e4SLinus Torvalds my $param_name = $param; 23961da177e4SLinus Torvalds $param_name =~ s/\[.*//; 23971da177e4SLinus Torvalds 2398a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 23991da177e4SLinus Torvalds { 2400c950a173SSilvio Fricke if (!$param =~ /\w\.\.\.$/) { 2401c950a173SSilvio Fricke # handles unnamed variable parameters 2402ef00028bSJonathan Corbet $param = "..."; 2403c950a173SSilvio Fricke } 2404ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 2405a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 24061da177e4SLinus Torvalds } 2407ced69090SRandy Dunlap } 24081da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 24091da177e4SLinus Torvalds { 24101da177e4SLinus Torvalds $param="void"; 24111da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 24121da177e4SLinus Torvalds } 2413134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 2414134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 2415134fe01bSRandy Dunlap { 2416134fe01bSRandy Dunlap $type = $param; 2417134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 2418134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 24195f8c7c98SRandy Dunlap $anon_struct_union = 1; 2420134fe01bSRandy Dunlap } 2421134fe01bSRandy Dunlap 2422a6d3fe77SMartin Waitz # warn if parameter has no description 2423134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 2424134fe01bSRandy Dunlap # but inline preprocessor statements); 2425134fe01bSRandy Dunlap # also ignore unnamed structs/unions; 24265f8c7c98SRandy Dunlap if (!$anon_struct_union) { 2427a6d3fe77SMartin Waitz if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { 2428a6d3fe77SMartin Waitz 24291da177e4SLinus Torvalds $parameterdescs{$param_name} = $undescribed; 24301da177e4SLinus Torvalds 24311da177e4SLinus Torvalds if (($type eq 'function') || ($type eq 'enum')) { 2432d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Function parameter ". 24331da177e4SLinus Torvalds "or member '$param' not " . 24341da177e4SLinus Torvalds "described in '$declaration_name'\n"; 24351da177e4SLinus Torvalds } 2436d40e1e65SBart Van Assche print STDERR "${file}:$.: warning:" . 24371da177e4SLinus Torvalds " No description found for parameter '$param'\n"; 24381da177e4SLinus Torvalds ++$warnings; 24391da177e4SLinus Torvalds } 2440134fe01bSRandy Dunlap } 24411da177e4SLinus Torvalds 24422b35f4d9SRandy Dunlap $param = xml_escape($param); 24432b35f4d9SRandy Dunlap 244425985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 2445e34e7dbbSRandy Dunlap # on @parameterlist; 2446e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 2447e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 2448e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 2449e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 2450e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 2451e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 2452e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 24531da177e4SLinus Torvalds push @parameterlist, $param; 245402a4f4feSPaolo Bonzini $type =~ s/\s\s+/ /g; 24551da177e4SLinus Torvalds $parametertypes{$param} = $type; 24561da177e4SLinus Torvalds} 24571da177e4SLinus Torvalds 2458a1d94aa5SRandy Dunlapsub check_sections($$$$$$) { 2459a1d94aa5SRandy Dunlap my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; 2460a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 2461a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 2462a1d94aa5SRandy Dunlap my $err; 2463a1d94aa5SRandy Dunlap my ($px, $sx); 2464a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 2465a1d94aa5SRandy Dunlap 2466a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 2467a1d94aa5SRandy Dunlap $err = 1; 2468a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 2469a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 2470a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 24711f3a6688SJohannes Berg $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 2472e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 2473e34e7dbbSRandy Dunlap # however, the original param string may contain 2474e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 2475e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 2476e34e7dbbSRandy Dunlap # parameter list is split at spaces; 2477e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 2478e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 2479e34e7dbbSRandy Dunlap 2480a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 2481a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 2482a1d94aa5SRandy Dunlap $err = 0; 2483a1d94aa5SRandy Dunlap last; 2484a1d94aa5SRandy Dunlap } 2485a1d94aa5SRandy Dunlap } 2486a1d94aa5SRandy Dunlap if ($err) { 2487a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 2488d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2489a1d94aa5SRandy Dunlap "Excess function parameter " . 2490a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2491a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2492a1d94aa5SRandy Dunlap ++$warnings; 2493a1d94aa5SRandy Dunlap } else { 2494a1d94aa5SRandy Dunlap if ($nested !~ m/\Q$sects[$sx]\E/) { 2495d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2496a1d94aa5SRandy Dunlap "Excess struct/union/enum/typedef member " . 2497a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2498a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2499a1d94aa5SRandy Dunlap ++$warnings; 2500a1d94aa5SRandy Dunlap } 2501a1d94aa5SRandy Dunlap } 2502a1d94aa5SRandy Dunlap } 2503a1d94aa5SRandy Dunlap } 2504a1d94aa5SRandy Dunlap} 2505a1d94aa5SRandy Dunlap 25061da177e4SLinus Torvalds## 25074092bac7SYacine Belkadi# Checks the section describing the return value of a function. 25084092bac7SYacine Belkadisub check_return_section { 25094092bac7SYacine Belkadi my $file = shift; 25104092bac7SYacine Belkadi my $declaration_name = shift; 25114092bac7SYacine Belkadi my $return_type = shift; 25124092bac7SYacine Belkadi 25134092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 25144092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 25154092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 25164092bac7SYacine Belkadi return; 25174092bac7SYacine Belkadi } 25184092bac7SYacine Belkadi 25194092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 25204092bac7SYacine Belkadi $sections{$section_return} eq "") { 2521d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 25224092bac7SYacine Belkadi "No description found for return value of " . 25234092bac7SYacine Belkadi "'$declaration_name'\n"; 25244092bac7SYacine Belkadi ++$warnings; 25254092bac7SYacine Belkadi } 25264092bac7SYacine Belkadi} 25274092bac7SYacine Belkadi 25284092bac7SYacine Belkadi## 25291da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 25301da177e4SLinus Torvalds# processed and spits out all the details stored in the global 25311da177e4SLinus Torvalds# arrays/hashes. 25321da177e4SLinus Torvaldssub dump_function($$) { 25331da177e4SLinus Torvalds my $prototype = shift; 25341da177e4SLinus Torvalds my $file = shift; 2535cbb4d3e6SHoria Geanta my $noret = 0; 25361da177e4SLinus Torvalds 25371da177e4SLinus Torvalds $prototype =~ s/^static +//; 25381da177e4SLinus Torvalds $prototype =~ s/^extern +//; 25394dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 25401da177e4SLinus Torvalds $prototype =~ s/^inline +//; 25411da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 254232e79401SRandy Dunlap $prototype =~ s/^__inline +//; 254332e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 254432e79401SRandy Dunlap $prototype =~ s/^noinline +//; 254574fc5c65SRandy Dunlap $prototype =~ s/__init +//; 254620072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 2547270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 254870c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 25490df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 2550cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 2551b1aaa546SPaolo Bonzini $prototype =~ s/__attribute__\s*\(\( 2552b1aaa546SPaolo Bonzini (?: 2553b1aaa546SPaolo Bonzini [\w\s]++ # attribute name 2554b1aaa546SPaolo Bonzini (?:\([^)]*+\))? # attribute arguments 2555b1aaa546SPaolo Bonzini \s*+,? # optional comma at the end 2556b1aaa546SPaolo Bonzini )+ 2557b1aaa546SPaolo Bonzini \)\)\s+//x; 25581da177e4SLinus Torvalds 25591da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 25601da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 25611da177e4SLinus Torvalds # 2. Function name 25621da177e4SLinus Torvalds # 3. Function parameters. 25631da177e4SLinus Torvalds # 25641da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 25651da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 25661da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 25671da177e4SLinus Torvalds # so on. 25681da177e4SLinus Torvalds # 25691da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 25701da177e4SLinus Torvalds # the following functions' documentation still comes out right: 25711da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 25721da177e4SLinus Torvalds # - atomic_set (macro) 25739598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 25741da177e4SLinus Torvalds 2575cbb4d3e6SHoria Geanta if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 2576cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 2577cbb4d3e6SHoria Geanta # list. 2578cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 2579cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 2580cbb4d3e6SHoria Geanta $return_type = $1; 2581cbb4d3e6SHoria Geanta $declaration_name = $2; 2582cbb4d3e6SHoria Geanta $noret = 1; 2583cbb4d3e6SHoria Geanta } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25841da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25851da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25861da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 258794b3e03cSRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25881da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25891da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 25901da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25911da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25921da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25931da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25941da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25951da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25969598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 25979598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2598412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2599412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 26001da177e4SLinus Torvalds $return_type = $1; 26011da177e4SLinus Torvalds $declaration_name = $2; 26021da177e4SLinus Torvalds my $args = $3; 26031da177e4SLinus Torvalds 26041da177e4SLinus Torvalds create_parameterlist($args, ',', $file); 26051da177e4SLinus Torvalds } else { 2606d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 26071da177e4SLinus Torvalds return; 26081da177e4SLinus Torvalds } 26091da177e4SLinus Torvalds 2610a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 2611a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); 2612a1d94aa5SRandy Dunlap 26134092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 26144092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 26154092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 26164092bac7SYacine Belkadi # verbose mode. 26174092bac7SYacine Belkadi # TODO: always perform the check. 2618cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 26194092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 26204092bac7SYacine Belkadi } 26214092bac7SYacine Belkadi 26221da177e4SLinus Torvalds output_declaration($declaration_name, 26231da177e4SLinus Torvalds 'function', 26241da177e4SLinus Torvalds {'function' => $declaration_name, 26251da177e4SLinus Torvalds 'module' => $modulename, 26261da177e4SLinus Torvalds 'functiontype' => $return_type, 26271da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 26281da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 26291da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 26301da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 26311da177e4SLinus Torvalds 'sections' => \%sections, 26321da177e4SLinus Torvalds 'purpose' => $declaration_purpose 26331da177e4SLinus Torvalds }); 26341da177e4SLinus Torvalds} 26351da177e4SLinus Torvalds 26361da177e4SLinus Torvaldssub reset_state { 26371da177e4SLinus Torvalds $function = ""; 26381da177e4SLinus Torvalds %parameterdescs = (); 26391da177e4SLinus Torvalds %parametertypes = (); 26401da177e4SLinus Torvalds @parameterlist = (); 26411da177e4SLinus Torvalds %sections = (); 26421da177e4SLinus Torvalds @sectionlist = (); 2643a1d94aa5SRandy Dunlap $sectcheck = ""; 2644a1d94aa5SRandy Dunlap $struct_actual = ""; 26451da177e4SLinus Torvalds $prototype = ""; 26461da177e4SLinus Torvalds 264748af606aSJani Nikula $state = STATE_NORMAL; 264848af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 26491da177e4SLinus Torvalds} 26501da177e4SLinus Torvalds 265156afb0f8SJason Baronsub tracepoint_munge($) { 265256afb0f8SJason Baron my $file = shift; 265356afb0f8SJason Baron my $tracepointname = 0; 265456afb0f8SJason Baron my $tracepointargs = 0; 265556afb0f8SJason Baron 265656afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 265756afb0f8SJason Baron $tracepointname = $1; 265856afb0f8SJason Baron } 26593a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 26603a9089fdSJason Baron $tracepointname = $1; 26613a9089fdSJason Baron } 26623a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 26633a9089fdSJason Baron $tracepointname = $2; 26643a9089fdSJason Baron } 26653a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 266656afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 266756afb0f8SJason Baron $tracepointargs = $1; 266856afb0f8SJason Baron } 266956afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 2670d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 267156afb0f8SJason Baron "$prototype\n"; 267256afb0f8SJason Baron } else { 267356afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 267456afb0f8SJason Baron } 267556afb0f8SJason Baron} 267656afb0f8SJason Baron 2677b4870bc5SRandy Dunlapsub syscall_munge() { 2678b4870bc5SRandy Dunlap my $void = 0; 2679b4870bc5SRandy Dunlap 2680b4870bc5SRandy Dunlap $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs 2681b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 2682b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 2683b4870bc5SRandy Dunlap $void = 1; 2684b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 2685b4870bc5SRandy Dunlap } 2686b4870bc5SRandy Dunlap 2687b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 2688b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 2689b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 2690b4870bc5SRandy Dunlap } elsif ($void) { 2691b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 2692b4870bc5SRandy Dunlap } 2693b4870bc5SRandy Dunlap 2694b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 2695b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 2696b4870bc5SRandy Dunlap my $count = 0; 2697b4870bc5SRandy Dunlap my $len = length($prototype); 2698b4870bc5SRandy Dunlap if ($void) { 2699b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 2700b4870bc5SRandy Dunlap } 2701b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 2702b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 2703b4870bc5SRandy Dunlap $count++; 2704b4870bc5SRandy Dunlap if ($count % 2 == 1) { 2705b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 2706b4870bc5SRandy Dunlap } 2707b4870bc5SRandy Dunlap } 2708b4870bc5SRandy Dunlap } 2709b4870bc5SRandy Dunlap} 2710b4870bc5SRandy Dunlap 2711b7afa92bSDaniel Vettersub process_proto_function($$) { 27121da177e4SLinus Torvalds my $x = shift; 27131da177e4SLinus Torvalds my $file = shift; 27141da177e4SLinus Torvalds 271551f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 271651f5a0c8SRandy Dunlap 2717890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 27181da177e4SLinus Torvalds # do nothing 27191da177e4SLinus Torvalds } 27201da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 27211da177e4SLinus Torvalds $prototype .= $1; 27221da177e4SLinus Torvalds } 2723b4870bc5SRandy Dunlap 2724890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 27251da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 27261da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 27271da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 2728b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 2729b4870bc5SRandy Dunlap syscall_munge(); 2730b4870bc5SRandy Dunlap } 27313a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 27323a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 27333a9089fdSJason Baron { 273456afb0f8SJason Baron tracepoint_munge($file); 273556afb0f8SJason Baron } 27361da177e4SLinus Torvalds dump_function($prototype, $file); 27371da177e4SLinus Torvalds reset_state(); 27381da177e4SLinus Torvalds } 27391da177e4SLinus Torvalds} 27401da177e4SLinus Torvalds 2741b7afa92bSDaniel Vettersub process_proto_type($$) { 27421da177e4SLinus Torvalds my $x = shift; 27431da177e4SLinus Torvalds my $file = shift; 27441da177e4SLinus Torvalds 27451da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 27461da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 27471da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 274851f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 274951f5a0c8SRandy Dunlap 27501da177e4SLinus Torvalds if ($x =~ /^#/) { 27511da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 27521da177e4SLinus Torvalds $x .= ";"; 27531da177e4SLinus Torvalds } 27541da177e4SLinus Torvalds 27551da177e4SLinus Torvalds while (1) { 27561da177e4SLinus Torvalds if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 27571da177e4SLinus Torvalds $prototype .= $1 . $2; 27581da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 27591da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 27601da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 27611da177e4SLinus Torvalds dump_declaration($prototype, $file); 27621da177e4SLinus Torvalds reset_state(); 27631da177e4SLinus Torvalds last; 27641da177e4SLinus Torvalds } 27651da177e4SLinus Torvalds $x = $3; 27661da177e4SLinus Torvalds } else { 27671da177e4SLinus Torvalds $prototype .= $x; 27681da177e4SLinus Torvalds last; 27691da177e4SLinus Torvalds } 27701da177e4SLinus Torvalds } 27711da177e4SLinus Torvalds} 27721da177e4SLinus Torvalds 27736b5b55f6SRandy Dunlap# xml_escape: replace <, >, and & in the text stream; 27746b5b55f6SRandy Dunlap# 27756b5b55f6SRandy Dunlap# however, formatting controls that are generated internally/locally in the 27766b5b55f6SRandy Dunlap# kernel-doc script are not escaped here; instead, they begin life like 27776b5b55f6SRandy Dunlap# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings 27786b5b55f6SRandy Dunlap# are converted to their mnemonic-expected output, without the 4 * '\' & ':', 27796b5b55f6SRandy Dunlap# just before actual output; (this is done by local_unescape()) 27801da177e4SLinus Torvaldssub xml_escape($) { 27811da177e4SLinus Torvalds my $text = shift; 2782ecfb251aSRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 2783ecfb251aSRandy Dunlap return $text; 2784ecfb251aSRandy Dunlap } 27851da177e4SLinus Torvalds $text =~ s/\&/\\\\\\amp;/g; 27861da177e4SLinus Torvalds $text =~ s/\</\\\\\\lt;/g; 27871da177e4SLinus Torvalds $text =~ s/\>/\\\\\\gt;/g; 27881da177e4SLinus Torvalds return $text; 27891da177e4SLinus Torvalds} 27901da177e4SLinus Torvalds 2791c0d1b6eeSJonathan Corbet# xml_unescape: reverse the effects of xml_escape 2792c0d1b6eeSJonathan Corbetsub xml_unescape($) { 2793c0d1b6eeSJonathan Corbet my $text = shift; 2794c0d1b6eeSJonathan Corbet if (($output_mode eq "text") || ($output_mode eq "man")) { 2795c0d1b6eeSJonathan Corbet return $text; 2796c0d1b6eeSJonathan Corbet } 2797c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\amp;/\&/g; 2798c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\lt;/</g; 2799c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\gt;/>/g; 2800c0d1b6eeSJonathan Corbet return $text; 2801c0d1b6eeSJonathan Corbet} 2802c0d1b6eeSJonathan Corbet 28036b5b55f6SRandy Dunlap# convert local escape strings to html 28046b5b55f6SRandy Dunlap# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) 28056b5b55f6SRandy Dunlapsub local_unescape($) { 28066b5b55f6SRandy Dunlap my $text = shift; 28076b5b55f6SRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 28086b5b55f6SRandy Dunlap return $text; 28096b5b55f6SRandy Dunlap } 28106b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\lt:/</g; 28116b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\gt:/>/g; 28126b5b55f6SRandy Dunlap return $text; 28136b5b55f6SRandy Dunlap} 28146b5b55f6SRandy Dunlap 28151ad560e4SJani Nikulasub map_filename($) { 28161ad560e4SJani Nikula my $file; 28171ad560e4SJani Nikula my ($orig_file) = @_; 28181ad560e4SJani Nikula 28191ad560e4SJani Nikula if (defined($ENV{'SRCTREE'})) { 28201ad560e4SJani Nikula $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 28211ad560e4SJani Nikula } else { 28221ad560e4SJani Nikula $file = $orig_file; 28231ad560e4SJani Nikula } 28241ad560e4SJani Nikula 28251ad560e4SJani Nikula if (defined($source_map{$file})) { 28261ad560e4SJani Nikula $file = $source_map{$file}; 28271ad560e4SJani Nikula } 28281ad560e4SJani Nikula 28291ad560e4SJani Nikula return $file; 28301ad560e4SJani Nikula} 28311ad560e4SJani Nikula 283288c2b57dSJani Nikulasub process_export_file($) { 283388c2b57dSJani Nikula my ($orig_file) = @_; 283488c2b57dSJani Nikula my $file = map_filename($orig_file); 283588c2b57dSJani Nikula 283688c2b57dSJani Nikula if (!open(IN,"<$file")) { 283788c2b57dSJani Nikula print STDERR "Error: Cannot open file $file\n"; 283888c2b57dSJani Nikula ++$errors; 283988c2b57dSJani Nikula return; 284088c2b57dSJani Nikula } 284188c2b57dSJani Nikula 284288c2b57dSJani Nikula while (<IN>) { 284388c2b57dSJani Nikula if (/$export_symbol/) { 284488c2b57dSJani Nikula $function_table{$2} = 1; 284588c2b57dSJani Nikula } 284688c2b57dSJani Nikula } 284788c2b57dSJani Nikula 284888c2b57dSJani Nikula close(IN); 284988c2b57dSJani Nikula} 285088c2b57dSJani Nikula 28511da177e4SLinus Torvaldssub process_file($) { 28522283a117SRandy Dunlap my $file; 28531da177e4SLinus Torvalds my $identifier; 28541da177e4SLinus Torvalds my $func; 2855a21217daSRandy Dunlap my $descr; 28566423133bSJohannes Weiner my $in_purpose = 0; 28571da177e4SLinus Torvalds my $initial_section_counter = $section_counter; 285868f86662SBen Hutchings my ($orig_file) = @_; 2859b7886de4SJani Nikula my $leading_space; 28601da177e4SLinus Torvalds 28611ad560e4SJani Nikula $file = map_filename($orig_file); 28621da177e4SLinus Torvalds 28631da177e4SLinus Torvalds if (!open(IN,"<$file")) { 28641da177e4SLinus Torvalds print STDERR "Error: Cannot open file $file\n"; 28651da177e4SLinus Torvalds ++$errors; 28661da177e4SLinus Torvalds return; 28671da177e4SLinus Torvalds } 28681da177e4SLinus Torvalds 2869a9e7314bSIlya Dryomov $. = 1; 2870a9e7314bSIlya Dryomov 28711da177e4SLinus Torvalds $section_counter = 0; 28721da177e4SLinus Torvalds while (<IN>) { 287365478428SDaniel Santos while (s/\\\s*$//) { 287465478428SDaniel Santos $_ .= <IN>; 287565478428SDaniel Santos } 287648af606aSJani Nikula if ($state == STATE_NORMAL) { 28771da177e4SLinus Torvalds if (/$doc_start/o) { 287848af606aSJani Nikula $state = STATE_NAME; # next line is always the function name 2879850622dfSRandy Dunlap $in_doc_sect = 0; 28800b0f5f29SDaniel Vetter $declaration_start_line = $. + 1; 28811da177e4SLinus Torvalds } 288248af606aSJani Nikula } elsif ($state == STATE_NAME) {# this line is the function name (always) 28831da177e4SLinus Torvalds if (/$doc_block/o) { 288448af606aSJani Nikula $state = STATE_DOCBLOCK; 28851da177e4SLinus Torvalds $contents = ""; 28860b0f5f29SDaniel Vetter $new_start_line = $. + 1; 28870b0f5f29SDaniel Vetter 28881da177e4SLinus Torvalds if ( $1 eq "" ) { 28891da177e4SLinus Torvalds $section = $section_intro; 28901da177e4SLinus Torvalds } else { 28911da177e4SLinus Torvalds $section = $1; 28921da177e4SLinus Torvalds } 28931da177e4SLinus Torvalds } 28941da177e4SLinus Torvalds elsif (/$doc_decl/o) { 28951da177e4SLinus Torvalds $identifier = $1; 28961da177e4SLinus Torvalds if (/\s*([\w\s]+?)\s*-/) { 28971da177e4SLinus Torvalds $identifier = $1; 28981da177e4SLinus Torvalds } 28991da177e4SLinus Torvalds 290048af606aSJani Nikula $state = STATE_FIELD; 29010b0f5f29SDaniel Vetter # if there's no @param blocks need to set up default section 29020b0f5f29SDaniel Vetter # here 29032f4ad40aSJani Nikula $contents = ""; 29042f4ad40aSJani Nikula $section = $section_default; 29050b0f5f29SDaniel Vetter $new_start_line = $. + 1; 29061da177e4SLinus Torvalds if (/-(.*)/) { 290751f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2908a21217daSRandy Dunlap $descr= $1; 2909a21217daSRandy Dunlap $descr =~ s/^\s*//; 2910a21217daSRandy Dunlap $descr =~ s/\s*$//; 291112ae6779SDaniel Santos $descr =~ s/\s+/ /g; 2912a21217daSRandy Dunlap $declaration_purpose = xml_escape($descr); 29136423133bSJohannes Weiner $in_purpose = 1; 29141da177e4SLinus Torvalds } else { 29151da177e4SLinus Torvalds $declaration_purpose = ""; 29161da177e4SLinus Torvalds } 291777cc23b8SRandy Dunlap 291877cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 2919d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 292077cc23b8SRandy Dunlap print STDERR $_; 292177cc23b8SRandy Dunlap ++$warnings; 292277cc23b8SRandy Dunlap } 292377cc23b8SRandy Dunlap 29241da177e4SLinus Torvalds if ($identifier =~ m/^struct/) { 29251da177e4SLinus Torvalds $decl_type = 'struct'; 29261da177e4SLinus Torvalds } elsif ($identifier =~ m/^union/) { 29271da177e4SLinus Torvalds $decl_type = 'union'; 29281da177e4SLinus Torvalds } elsif ($identifier =~ m/^enum/) { 29291da177e4SLinus Torvalds $decl_type = 'enum'; 29301da177e4SLinus Torvalds } elsif ($identifier =~ m/^typedef/) { 29311da177e4SLinus Torvalds $decl_type = 'typedef'; 29321da177e4SLinus Torvalds } else { 29331da177e4SLinus Torvalds $decl_type = 'function'; 29341da177e4SLinus Torvalds } 29351da177e4SLinus Torvalds 29361da177e4SLinus Torvalds if ($verbose) { 2937d40e1e65SBart Van Assche print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; 29381da177e4SLinus Torvalds } 29391da177e4SLinus Torvalds } else { 2940d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 29411da177e4SLinus Torvalds " - I thought it was a doc line\n"; 29421da177e4SLinus Torvalds ++$warnings; 294348af606aSJani Nikula $state = STATE_NORMAL; 29441da177e4SLinus Torvalds } 294548af606aSJani Nikula } elsif ($state == STATE_FIELD) { # look for head: lines, and include content 2946f624adefSJani Nikula if (/$doc_sect/i) { # case insensitive for supported section names 29471da177e4SLinus Torvalds $newsection = $1; 29481da177e4SLinus Torvalds $newcontents = $2; 29491da177e4SLinus Torvalds 2950f624adefSJani Nikula # map the supported section names to the canonical names 2951f624adefSJani Nikula if ($newsection =~ m/^description$/i) { 2952f624adefSJani Nikula $newsection = $section_default; 2953f624adefSJani Nikula } elsif ($newsection =~ m/^context$/i) { 2954f624adefSJani Nikula $newsection = $section_context; 2955f624adefSJani Nikula } elsif ($newsection =~ m/^returns?$/i) { 2956f624adefSJani Nikula $newsection = $section_return; 2957f624adefSJani Nikula } elsif ($newsection =~ m/^\@return$/) { 2958f624adefSJani Nikula # special: @return is a section, not a param description 2959f624adefSJani Nikula $newsection = $section_return; 2960f624adefSJani Nikula } 2961f624adefSJani Nikula 2962792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 2963850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 2964d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: contents before sections\n"; 2965850622dfSRandy Dunlap ++$warnings; 2966850622dfSRandy Dunlap } 296794dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 29681da177e4SLinus Torvalds $section = $section_default; 29691da177e4SLinus Torvalds } 29701da177e4SLinus Torvalds 2971850622dfSRandy Dunlap $in_doc_sect = 1; 29726423133bSJohannes Weiner $in_purpose = 0; 29731da177e4SLinus Torvalds $contents = $newcontents; 29740b0f5f29SDaniel Vetter $new_start_line = $.; 297527205744SRandy Dunlap while ((substr($contents, 0, 1) eq " ") || 297627205744SRandy Dunlap substr($contents, 0, 1) eq "\t") { 297705189497SRandy Dunlap $contents = substr($contents, 1); 297805189497SRandy Dunlap } 29790a726301SJani Nikula if ($contents ne "") { 29801da177e4SLinus Torvalds $contents .= "\n"; 29811da177e4SLinus Torvalds } 29821da177e4SLinus Torvalds $section = $newsection; 2983b7886de4SJani Nikula $leading_space = undef; 29841da177e4SLinus Torvalds } elsif (/$doc_end/) { 29854c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 298694dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 29871da177e4SLinus Torvalds $section = $section_default; 29881da177e4SLinus Torvalds $contents = ""; 29891da177e4SLinus Torvalds } 299046b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 299146b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2992d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: suspicious ending line: $_"; 299346b958ebSRandy Dunlap ++$warnings; 299446b958ebSRandy Dunlap } 29951da177e4SLinus Torvalds 29961da177e4SLinus Torvalds $prototype = ""; 299748af606aSJani Nikula $state = STATE_PROTO; 29981da177e4SLinus Torvalds $brcount = 0; 29991da177e4SLinus Torvalds# print STDERR "end of doc comment, looking for prototype\n"; 30001da177e4SLinus Torvalds } elsif (/$doc_content/) { 30011da177e4SLinus Torvalds # miguel-style comment kludge, look for blank lines after 30021da177e4SLinus Torvalds # @parameter line to signify start of description 30036423133bSJohannes Weiner if ($1 eq "") { 30046423133bSJohannes Weiner if ($section =~ m/^@/ || $section eq $section_context) { 300594dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 30061da177e4SLinus Torvalds $section = $section_default; 30071da177e4SLinus Torvalds $contents = ""; 30080b0f5f29SDaniel Vetter $new_start_line = $.; 30091da177e4SLinus Torvalds } else { 30106423133bSJohannes Weiner $contents .= "\n"; 30116423133bSJohannes Weiner } 30126423133bSJohannes Weiner $in_purpose = 0; 30136423133bSJohannes Weiner } elsif ($in_purpose == 1) { 30146423133bSJohannes Weiner # Continued declaration purpose 30156423133bSJohannes Weiner chomp($declaration_purpose); 30166423133bSJohannes Weiner $declaration_purpose .= " " . xml_escape($1); 301712ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 30186423133bSJohannes Weiner } else { 3019b7886de4SJani Nikula my $cont = $1; 3020b7886de4SJani Nikula if ($section =~ m/^@/ || $section eq $section_context) { 3021b7886de4SJani Nikula if (!defined $leading_space) { 3022b7886de4SJani Nikula if ($cont =~ m/^(\s+)/) { 3023b7886de4SJani Nikula $leading_space = $1; 3024b7886de4SJani Nikula } else { 3025b7886de4SJani Nikula $leading_space = ""; 3026b7886de4SJani Nikula } 3027b7886de4SJani Nikula } 3028b7886de4SJani Nikula 3029b7886de4SJani Nikula $cont =~ s/^$leading_space//; 3030b7886de4SJani Nikula } 3031b7886de4SJani Nikula $contents .= $cont . "\n"; 30321da177e4SLinus Torvalds } 30331da177e4SLinus Torvalds } else { 30341da177e4SLinus Torvalds # i dont know - bad line? ignore. 3035d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: bad line: $_"; 30361da177e4SLinus Torvalds ++$warnings; 30371da177e4SLinus Torvalds } 303848af606aSJani Nikula } elsif ($state == STATE_INLINE) { # scanning for inline parameters 3039a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 304048af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 3041a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 3042a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 30430b0f5f29SDaniel Vetter $new_start_line = $.; 3044a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 3045a4c6ebedSDanilo Cesar Lemes de Paula while ((substr($contents, 0, 1) eq " ") || 3046a4c6ebedSDanilo Cesar Lemes de Paula substr($contents, 0, 1) eq "\t") { 3047a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 3048a4c6ebedSDanilo Cesar Lemes de Paula } 3049a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 3050a4c6ebedSDanilo Cesar Lemes de Paula } 305148af606aSJani Nikula $inline_doc_state = STATE_INLINE_TEXT; 3052a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 305348af606aSJani Nikula } elsif (/$doc_inline_end/) { 3054a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 3055a4c6ebedSDanilo Cesar Lemes de Paula dump_section($file, $section, xml_escape($contents)); 3056a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 3057a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 3058a4c6ebedSDanilo Cesar Lemes de Paula } 305948af606aSJani Nikula $state = STATE_PROTO; 306048af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 3061a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 3062a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 306348af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_TEXT) { 3064a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 30656450c895SJani Nikula # nuke leading blank lines 30666450c895SJani Nikula if ($contents =~ /^\s*$/) { 30676450c895SJani Nikula $contents = ""; 30686450c895SJani Nikula } 306948af606aSJani Nikula } elsif ($inline_doc_state == STATE_INLINE_NAME) { 307048af606aSJani Nikula $inline_doc_state = STATE_INLINE_ERROR; 3071e7ca311eSDaniel Vetter print STDERR "${file}:$.: warning: "; 3072a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Incorrect use of kernel-doc format: $_"; 3073a4c6ebedSDanilo Cesar Lemes de Paula ++$warnings; 3074a4c6ebedSDanilo Cesar Lemes de Paula } 3075a4c6ebedSDanilo Cesar Lemes de Paula } 307648af606aSJani Nikula } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype) 30770c9aa209SJani Nikula if (/$doc_inline_oneline/) { 30780c9aa209SJani Nikula $section = $1; 30790c9aa209SJani Nikula $contents = $2; 30800c9aa209SJani Nikula if ($contents ne "") { 30810c9aa209SJani Nikula $contents .= "\n"; 30820c9aa209SJani Nikula dump_section($file, $section, xml_escape($contents)); 30830c9aa209SJani Nikula $section = $section_default; 30840c9aa209SJani Nikula $contents = ""; 30850c9aa209SJani Nikula } 30860c9aa209SJani Nikula } elsif (/$doc_inline_start/) { 308748af606aSJani Nikula $state = STATE_INLINE; 308848af606aSJani Nikula $inline_doc_state = STATE_INLINE_NAME; 3089a4c6ebedSDanilo Cesar Lemes de Paula } elsif ($decl_type eq 'function') { 3090b7afa92bSDaniel Vetter process_proto_function($_, $file); 30911da177e4SLinus Torvalds } else { 3092b7afa92bSDaniel Vetter process_proto_type($_, $file); 30931da177e4SLinus Torvalds } 309448af606aSJani Nikula } elsif ($state == STATE_DOCBLOCK) { 3095ebff7f92SDaniel Vetter if (/$doc_end/) 30961da177e4SLinus Torvalds { 309794dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 30982f4ad40aSJani Nikula $section = $section_default; 30991da177e4SLinus Torvalds $contents = ""; 31001da177e4SLinus Torvalds $function = ""; 31011da177e4SLinus Torvalds %parameterdescs = (); 31021da177e4SLinus Torvalds %parametertypes = (); 31031da177e4SLinus Torvalds @parameterlist = (); 31041da177e4SLinus Torvalds %sections = (); 31051da177e4SLinus Torvalds @sectionlist = (); 31061da177e4SLinus Torvalds $prototype = ""; 310748af606aSJani Nikula $state = STATE_NORMAL; 31081da177e4SLinus Torvalds } 31091da177e4SLinus Torvalds elsif (/$doc_content/) 31101da177e4SLinus Torvalds { 31111da177e4SLinus Torvalds if ( $1 eq "" ) 31121da177e4SLinus Torvalds { 31131da177e4SLinus Torvalds $contents .= $blankline; 31141da177e4SLinus Torvalds } 31151da177e4SLinus Torvalds else 31161da177e4SLinus Torvalds { 31171da177e4SLinus Torvalds $contents .= $1 . "\n"; 31181da177e4SLinus Torvalds } 31191da177e4SLinus Torvalds } 31201da177e4SLinus Torvalds } 31211da177e4SLinus Torvalds } 31221da177e4SLinus Torvalds if ($initial_section_counter == $section_counter) { 3123d40e1e65SBart Van Assche print STDERR "${file}:1: warning: no structured comments found\n"; 3124b6c3f456SJani Nikula if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) { 3125e946c43aSJohannes Berg print STDERR " Was looking for '$_'.\n" for keys %function_table; 3126e946c43aSJohannes Berg } 31271da177e4SLinus Torvalds if ($output_mode eq "xml") { 31281da177e4SLinus Torvalds # The template wants at least one RefEntry here; make one. 31291da177e4SLinus Torvalds print "<refentry>\n"; 31301da177e4SLinus Torvalds print " <refnamediv>\n"; 31311da177e4SLinus Torvalds print " <refname>\n"; 313268f86662SBen Hutchings print " ${orig_file}\n"; 31331da177e4SLinus Torvalds print " </refname>\n"; 31341da177e4SLinus Torvalds print " <refpurpose>\n"; 31351da177e4SLinus Torvalds print " Document generation inconsistency\n"; 31361da177e4SLinus Torvalds print " </refpurpose>\n"; 31371da177e4SLinus Torvalds print " </refnamediv>\n"; 31381da177e4SLinus Torvalds print " <refsect1>\n"; 31391da177e4SLinus Torvalds print " <title>\n"; 31401da177e4SLinus Torvalds print " Oops\n"; 31411da177e4SLinus Torvalds print " </title>\n"; 31421da177e4SLinus Torvalds print " <warning>\n"; 31431da177e4SLinus Torvalds print " <para>\n"; 31441da177e4SLinus Torvalds print " The template for this document tried to insert\n"; 31451da177e4SLinus Torvalds print " the structured comment from the file\n"; 314668f86662SBen Hutchings print " <filename>${orig_file}</filename> at this point,\n"; 31471da177e4SLinus Torvalds print " but none was found.\n"; 31481da177e4SLinus Torvalds print " This dummy section is inserted to allow\n"; 31491da177e4SLinus Torvalds print " generation to continue.\n"; 31501da177e4SLinus Torvalds print " </para>\n"; 31511da177e4SLinus Torvalds print " </warning>\n"; 31521da177e4SLinus Torvalds print " </refsect1>\n"; 31531da177e4SLinus Torvalds print "</refentry>\n"; 31541da177e4SLinus Torvalds } 31551da177e4SLinus Torvalds } 31561da177e4SLinus Torvalds} 31578484baaaSRandy Dunlap 31588484baaaSRandy Dunlap 31598484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 31608484baaaSRandy Dunlap 31618484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 31628484baaaSRandy Dunlap# using the s// operator. 31631ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 31644d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 31654d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 31664d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 31674d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 31688484baaaSRandy Dunlap} 31698484baaaSRandy Dunlap 31708484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 31718484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 31728484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 31738484baaaSRandy Dunlap my ($relname, $absname); 31748484baaaSRandy Dunlap while(<SOURCE_MAP>) { 31758484baaaSRandy Dunlap chop(); 31768484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 31778484baaaSRandy Dunlap $relname =~ s:^/+::; 31788484baaaSRandy Dunlap $source_map{$relname} = $absname; 31798484baaaSRandy Dunlap } 31808484baaaSRandy Dunlap close(SOURCE_MAP); 31818484baaaSRandy Dunlap} 31828484baaaSRandy Dunlap 318388c2b57dSJani Nikulaif ($output_selection == OUTPUT_EXPORTED || 318488c2b57dSJani Nikula $output_selection == OUTPUT_INTERNAL) { 3185c9b2cfb3SJani Nikula 3186c9b2cfb3SJani Nikula push(@export_file_list, @ARGV); 3187c9b2cfb3SJani Nikula 318888c2b57dSJani Nikula foreach (@export_file_list) { 318988c2b57dSJani Nikula chomp; 319088c2b57dSJani Nikula process_export_file($_); 319188c2b57dSJani Nikula } 319288c2b57dSJani Nikula} 319388c2b57dSJani Nikula 31948484baaaSRandy Dunlapforeach (@ARGV) { 31958484baaaSRandy Dunlap chomp; 31968484baaaSRandy Dunlap process_file($_); 31978484baaaSRandy Dunlap} 31988484baaaSRandy Dunlapif ($verbose && $errors) { 31998484baaaSRandy Dunlap print STDERR "$errors errors\n"; 32008484baaaSRandy Dunlap} 32018484baaaSRandy Dunlapif ($verbose && $warnings) { 32028484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 32038484baaaSRandy Dunlap} 32048484baaaSRandy Dunlap 32058484baaaSRandy Dunlapexit($errors); 3206