1cb77f0d6SKamil Rytarowski#!/usr/bin/env perl 21da177e4SLinus Torvalds 3cb77f0d6SKamil Rytarowskiuse warnings; 41da177e4SLinus Torvaldsuse strict; 51da177e4SLinus Torvalds 61da177e4SLinus Torvalds## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## 71da177e4SLinus Torvalds## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## 81da177e4SLinus Torvalds## Copyright (C) 2001 Simon Huggins ## 970c95b00SRandy Dunlap## Copyright (C) 2005-2012 Randy Dunlap ## 101b40c194SDan Luedtke## Copyright (C) 2012 Dan Luedtke ## 111da177e4SLinus Torvalds## ## 121da177e4SLinus Torvalds## #define enhancements by Armin Kuster <akuster@mvista.com> ## 131da177e4SLinus Torvalds## Copyright (c) 2000 MontaVista Software, Inc. ## 141da177e4SLinus Torvalds## ## 151da177e4SLinus Torvalds## This software falls under the GNU General Public License. ## 161da177e4SLinus Torvalds## Please read the COPYING file for more information ## 171da177e4SLinus Torvalds 181da177e4SLinus Torvalds# 18/01/2001 - Cleanups 191da177e4SLinus Torvalds# Functions prototyped as foo(void) same as foo() 201da177e4SLinus Torvalds# Stop eval'ing where we don't need to. 211da177e4SLinus Torvalds# -- huggie@earth.li 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds# 27/06/2001 - Allowed whitespace after initial "/**" and 241da177e4SLinus Torvalds# allowed comments before function declarations. 251da177e4SLinus Torvalds# -- Christian Kreibich <ck@whoop.org> 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds# Still to do: 281da177e4SLinus Torvalds# - add perldoc documentation 291da177e4SLinus Torvalds# - Look more closely at some of the scarier bits :) 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds# 26/05/2001 - Support for separate source and object trees. 321da177e4SLinus Torvalds# Return error code. 331da177e4SLinus Torvalds# Keith Owens <kaos@ocs.com.au> 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds# 23/09/2001 - Added support for typedefs, structs, enums and unions 361da177e4SLinus Torvalds# Support for Context section; can be terminated using empty line 371da177e4SLinus Torvalds# Small fixes (like spaces vs. \s in regex) 381da177e4SLinus Torvalds# -- Tim Jansen <tim@tjansen.de> 391da177e4SLinus Torvalds 401b40c194SDan Luedtke# 25/07/2012 - Added support for HTML5 411b40c194SDan Luedtke# -- Dan Luedtke <mail@danrl.de> 421da177e4SLinus Torvalds 43fadc0b31SJani Nikulasub usage { 44fadc0b31SJani Nikula my $message = <<"EOF"; 45fadc0b31SJani NikulaUsage: $0 [OPTION ...] FILE ... 461da177e4SLinus Torvalds 47fadc0b31SJani NikulaRead C language source or header FILEs, extract embedded documentation comments, 48fadc0b31SJani Nikulaand print formatted documentation to standard output. 491da177e4SLinus Torvalds 50fadc0b31SJani NikulaThe documentation comments are identified by "/**" opening comment mark. See 51fadc0b31SJani NikulaDocumentation/kernel-doc-nano-HOWTO.txt for the documentation comment syntax. 52fadc0b31SJani Nikula 53fadc0b31SJani NikulaOutput format selection (mutually exclusive): 54fadc0b31SJani Nikula -docbook Output DocBook format. 55fadc0b31SJani Nikula -html Output HTML format. 56fadc0b31SJani Nikula -html5 Output HTML5 format. 57fadc0b31SJani Nikula -list Output symbol list format. This is for use by docproc. 58fadc0b31SJani Nikula -man Output troff manual page format. This is the default. 59c0d1b6eeSJonathan Corbet -rst Output reStructuredText format. 60fadc0b31SJani Nikula -text Output plain text format. 613a025e1dSMatthew Wilcox -none Do not output documentation, only warnings. 62fadc0b31SJani Nikula 63fadc0b31SJani NikulaOutput selection (mutually exclusive): 6486ae2e38SJani Nikula -export Only output documentation for symbols that have been 6586ae2e38SJani Nikula exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 66c9b2cfb3SJani Nikula in any input FILE or -export-file FILE. 6786ae2e38SJani Nikula -internal Only output documentation for symbols that have NOT been 6886ae2e38SJani Nikula exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 69c9b2cfb3SJani Nikula in any input FILE or -export-file FILE. 70fadc0b31SJani Nikula -function NAME Only output documentation for the given function(s) 71fadc0b31SJani Nikula or DOC: section title(s). All other functions and DOC: 72fadc0b31SJani Nikula sections are ignored. May be specified multiple times. 73fadc0b31SJani Nikula -nofunction NAME Do NOT output documentation for the given function(s); 74fadc0b31SJani Nikula only output documentation for the other functions and 75fadc0b31SJani Nikula DOC: sections. May be specified multiple times. 76fadc0b31SJani Nikula 77fadc0b31SJani NikulaOutput selection modifiers: 78fadc0b31SJani Nikula -no-doc-sections Do not output DOC: sections. 790b0f5f29SDaniel Vetter -enable-lineno Enable output of #define LINENO lines. Only works with 800b0f5f29SDaniel Vetter reStructuredText format. 8188c2b57dSJani Nikula -export-file FILE Specify an additional FILE in which to look for 8288c2b57dSJani Nikula EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with 8388c2b57dSJani Nikula -export or -internal. May be specified multiple times. 84fadc0b31SJani Nikula 85fadc0b31SJani NikulaOther parameters: 86fadc0b31SJani Nikula -v Verbose output, more warnings and other information. 87fadc0b31SJani Nikula -h Print this help. 88fadc0b31SJani Nikula 89fadc0b31SJani NikulaEOF 90fadc0b31SJani Nikula print $message; 91fadc0b31SJani Nikula exit 1; 92fadc0b31SJani Nikula} 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds# 951da177e4SLinus Torvalds# format of comments. 961da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure. 971da177e4SLinus Torvalds# (...)* signifies 0 or more structure elements 981da177e4SLinus Torvalds# /** 991da177e4SLinus Torvalds# * function_name(:)? (- short description)? 1001da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)* 1011da177e4SLinus Torvalds# (* a blank line)? 1021da177e4SLinus Torvalds# * (Description:)? (Description of function)? 1031da177e4SLinus Torvalds# * (section header: (section description)? )* 1041da177e4SLinus Torvalds# (*)?*/ 1051da177e4SLinus Torvalds# 1061da177e4SLinus Torvalds# So .. the trivial example would be: 1071da177e4SLinus Torvalds# 1081da177e4SLinus Torvalds# /** 1091da177e4SLinus Torvalds# * my_function 110b9d97328SRandy Dunlap# */ 1111da177e4SLinus Torvalds# 112891dcd2fSRandy Dunlap# If the Description: header tag is omitted, then there must be a blank line 1131da177e4SLinus Torvalds# after the last parameter specification. 1141da177e4SLinus Torvalds# e.g. 1151da177e4SLinus Torvalds# /** 1161da177e4SLinus Torvalds# * my_function - does my stuff 1171da177e4SLinus Torvalds# * @my_arg: its mine damnit 1181da177e4SLinus Torvalds# * 1191da177e4SLinus Torvalds# * Does my stuff explained. 1201da177e4SLinus Torvalds# */ 1211da177e4SLinus Torvalds# 1221da177e4SLinus Torvalds# or, could also use: 1231da177e4SLinus Torvalds# /** 1241da177e4SLinus Torvalds# * my_function - does my stuff 1251da177e4SLinus Torvalds# * @my_arg: its mine damnit 1261da177e4SLinus Torvalds# * Description: Does my stuff explained. 1271da177e4SLinus Torvalds# */ 1281da177e4SLinus Torvalds# etc. 1291da177e4SLinus Torvalds# 130b9d97328SRandy Dunlap# Besides functions you can also write documentation for structs, unions, 1311da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name 1321da177e4SLinus Torvalds# of the declaration; the struct/union/enum/typedef must always precede 1331da177e4SLinus Torvalds# the name. Nesting of declarations is not supported. 1341da177e4SLinus Torvalds# Use the argument mechanism to document members or constants. 1351da177e4SLinus Torvalds# e.g. 1361da177e4SLinus Torvalds# /** 1371da177e4SLinus Torvalds# * struct my_struct - short description 1381da177e4SLinus Torvalds# * @a: first member 1391da177e4SLinus Torvalds# * @b: second member 1401da177e4SLinus Torvalds# * 1411da177e4SLinus Torvalds# * Longer description 1421da177e4SLinus Torvalds# */ 1431da177e4SLinus Torvalds# struct my_struct { 1441da177e4SLinus Torvalds# int a; 1451da177e4SLinus Torvalds# int b; 146aeec46b9SMartin Waitz# /* private: */ 147aeec46b9SMartin Waitz# int c; 1481da177e4SLinus Torvalds# }; 1491da177e4SLinus Torvalds# 1501da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description. 1511da177e4SLinus Torvalds# 152a4c6ebedSDanilo Cesar Lemes de Paula# For really longs structs, you can also describe arguments inside the 153a4c6ebedSDanilo Cesar Lemes de Paula# body of the struct. 154a4c6ebedSDanilo Cesar Lemes de Paula# eg. 155a4c6ebedSDanilo Cesar Lemes de Paula# /** 156a4c6ebedSDanilo Cesar Lemes de Paula# * struct my_struct - short description 157a4c6ebedSDanilo Cesar Lemes de Paula# * @a: first member 158a4c6ebedSDanilo Cesar Lemes de Paula# * @b: second member 159a4c6ebedSDanilo Cesar Lemes de Paula# * 160a4c6ebedSDanilo Cesar Lemes de Paula# * Longer description 161a4c6ebedSDanilo Cesar Lemes de Paula# */ 162a4c6ebedSDanilo Cesar Lemes de Paula# struct my_struct { 163a4c6ebedSDanilo Cesar Lemes de Paula# int a; 164a4c6ebedSDanilo Cesar Lemes de Paula# int b; 165a4c6ebedSDanilo Cesar Lemes de Paula# /** 166a4c6ebedSDanilo Cesar Lemes de Paula# * @c: This is longer description of C 167a4c6ebedSDanilo Cesar Lemes de Paula# * 168a4c6ebedSDanilo Cesar Lemes de Paula# * You can use paragraphs to describe arguments 169a4c6ebedSDanilo Cesar Lemes de Paula# * using this method. 170a4c6ebedSDanilo Cesar Lemes de Paula# */ 171a4c6ebedSDanilo Cesar Lemes de Paula# int c; 172a4c6ebedSDanilo Cesar Lemes de Paula# }; 173a4c6ebedSDanilo Cesar Lemes de Paula# 174a4c6ebedSDanilo Cesar Lemes de Paula# This should be use only for struct/enum members. 175a4c6ebedSDanilo Cesar Lemes de Paula# 1761da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you 1771da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions 1781da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an 1791da177e4SLinus Torvalds# empty line. 1804092bac7SYacine Belkadi# A non-void function should have a "Return:" section describing the return 1814092bac7SYacine Belkadi# value(s). 1821da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked 1831da177e4SLinus Torvalds# appropriately in DocBook. 1841da177e4SLinus Torvalds# 1851da177e4SLinus Torvalds# Example: 1861da177e4SLinus Torvalds# /** 1871da177e4SLinus Torvalds# * user_function - function that can only be called in user context 1881da177e4SLinus Torvalds# * @a: some argument 1891da177e4SLinus Torvalds# * Context: !in_interrupt() 1901da177e4SLinus Torvalds# * 1911da177e4SLinus Torvalds# * Some description 1921da177e4SLinus Torvalds# * Example: 1931da177e4SLinus Torvalds# * user_function(22); 1941da177e4SLinus Torvalds# */ 1951da177e4SLinus Torvalds# ... 1961da177e4SLinus Torvalds# 1971da177e4SLinus Torvalds# 1981da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special 1991da177e4SLinus Torvalds# patterns, which are highlighted appropriately. 2001da177e4SLinus Torvalds# 2011da177e4SLinus Torvalds# 'funcname()' - function 2021da177e4SLinus Torvalds# '$ENVVAR' - environmental variable 2031da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct') 2045267dd35SPaolo Bonzini# '&struct_name.member' - name of a structure member 2051da177e4SLinus Torvalds# '@parameter' - name of a parameter 2061da177e4SLinus Torvalds# '%CONST' - name of a constant. 207b97f193aSMauro Carvalho Chehab# '``LITERAL``' - literal string without any spaces on it. 2081da177e4SLinus Torvalds 2098484baaaSRandy Dunlap## init lots of data 2108484baaaSRandy Dunlap 2111da177e4SLinus Torvaldsmy $errors = 0; 2121da177e4SLinus Torvaldsmy $warnings = 0; 2135f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 2141da177e4SLinus Torvalds 2151da177e4SLinus Torvalds# match expressions used to find embedded type information 216b97f193aSMauro Carvalho Chehabmy $type_constant = '\b``([^\`]+)``\b'; 217b97f193aSMauro Carvalho Chehabmy $type_constant2 = '\%([-_\w]+)'; 2181da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 219c950a173SSilvio Frickemy $type_param = '\@(\w+(\.\.\.)?)'; 2205219f18aSJonathan Corbetmy $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params 2211da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 222df31175bSPaolo Bonzinimy $type_enum = '\&(enum\s*([_\w]+))'; 223df31175bSPaolo Bonzinimy $type_struct = '\&(struct\s*([_\w]+))'; 224df31175bSPaolo Bonzinimy $type_typedef = '\&(typedef\s*([_\w]+))'; 225df31175bSPaolo Bonzinimy $type_union = '\&(union\s*([_\w]+))'; 2265267dd35SPaolo Bonzinimy $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; 227df31175bSPaolo Bonzinimy $type_fallback = '\&([_\w]+)'; 228df31175bSPaolo Bonzinimy $type_enum_xml = '\&(enum\s*([_\w]+))'; 229df31175bSPaolo Bonzinimy $type_struct_xml = '\&(struct\s*([_\w]+))'; 230df31175bSPaolo Bonzinimy $type_typedef_xml = '\&(typedef\s*([_\w]+))'; 231df31175bSPaolo Bonzinimy $type_union_xml = '\&(union\s*([_\w]+))'; 2325267dd35SPaolo Bonzinimy $type_member_xml = '\&([_\w]+)(\.|-\>)([_\w]+)'; 233df31175bSPaolo Bonzinimy $type_fallback_xml = '\&([_\w]+)'; 234f3341dcfSJani Nikulamy $type_member_func = $type_member . '\(\)'; 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds# Output conversion substitutions. 2371da177e4SLinus Torvalds# One for each output format 2381da177e4SLinus Torvalds 2391da177e4SLinus Torvalds# these work fairly well 2404d732701SDanilo Cesar Lemes de Paulamy @highlights_html = ( 2414d732701SDanilo Cesar Lemes de Paula [$type_constant, "<i>\$1</i>"], 242b97f193aSMauro Carvalho Chehab [$type_constant2, "<i>\$1</i>"], 2434d732701SDanilo Cesar Lemes de Paula [$type_func, "<b>\$1</b>"], 244df31175bSPaolo Bonzini [$type_enum_xml, "<i>\$1</i>"], 2454d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<i>\$1</i>"], 246df31175bSPaolo Bonzini [$type_typedef_xml, "<i>\$1</i>"], 247df31175bSPaolo Bonzini [$type_union_xml, "<i>\$1</i>"], 2484d732701SDanilo Cesar Lemes de Paula [$type_env, "<b><i>\$1</i></b>"], 2495267dd35SPaolo Bonzini [$type_param, "<tt><b>\$1</b></tt>"], 250df31175bSPaolo Bonzini [$type_member_xml, "<tt><i>\$1</i>\$2\$3</tt>"], 251df31175bSPaolo Bonzini [$type_fallback_xml, "<i>\$1</i>"] 2524d732701SDanilo Cesar Lemes de Paula ); 2536b5b55f6SRandy Dunlapmy $local_lt = "\\\\\\\\lt:"; 2546b5b55f6SRandy Dunlapmy $local_gt = "\\\\\\\\gt:"; 2556b5b55f6SRandy Dunlapmy $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" 2561da177e4SLinus Torvalds 2571b40c194SDan Luedtke# html version 5 2584d732701SDanilo Cesar Lemes de Paulamy @highlights_html5 = ( 2594d732701SDanilo Cesar Lemes de Paula [$type_constant, "<span class=\"const\">\$1</span>"], 260b97f193aSMauro Carvalho Chehab [$type_constant2, "<span class=\"const\">\$1</span>"], 2614d732701SDanilo Cesar Lemes de Paula [$type_func, "<span class=\"func\">\$1</span>"], 262df31175bSPaolo Bonzini [$type_enum_xml, "<span class=\"enum\">\$1</span>"], 2634d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<span class=\"struct\">\$1</span>"], 264df31175bSPaolo Bonzini [$type_typedef_xml, "<span class=\"typedef\">\$1</span>"], 265df31175bSPaolo Bonzini [$type_union_xml, "<span class=\"union\">\$1</span>"], 2664d732701SDanilo Cesar Lemes de Paula [$type_env, "<span class=\"env\">\$1</span>"], 2675267dd35SPaolo Bonzini [$type_param, "<span class=\"param\">\$1</span>]"], 268df31175bSPaolo Bonzini [$type_member_xml, "<span class=\"literal\"><span class=\"struct\">\$1</span>\$2<span class=\"member\">\$3</span></span>"], 269df31175bSPaolo Bonzini [$type_fallback_xml, "<span class=\"struct\">\$1</span>"] 2704d732701SDanilo Cesar Lemes de Paula ); 2711b40c194SDan Luedtkemy $blankline_html5 = $local_lt . "br /" . $local_gt; 2721b40c194SDan Luedtke 2731da177e4SLinus Torvalds# XML, docbook format 2744d732701SDanilo Cesar Lemes de Paulamy @highlights_xml = ( 2754d732701SDanilo Cesar Lemes de Paula ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"], 2764d732701SDanilo Cesar Lemes de Paula [$type_constant, "<constant>\$1</constant>"], 277b97f193aSMauro Carvalho Chehab [$type_constant2, "<constant>\$1</constant>"], 278df31175bSPaolo Bonzini [$type_enum_xml, "<type>\$1</type>"], 2794d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<structname>\$1</structname>"], 280df31175bSPaolo Bonzini [$type_typedef_xml, "<type>\$1</type>"], 281df31175bSPaolo Bonzini [$type_union_xml, "<structname>\$1</structname>"], 2824d732701SDanilo Cesar Lemes de Paula [$type_param, "<parameter>\$1</parameter>"], 2834d732701SDanilo Cesar Lemes de Paula [$type_func, "<function>\$1</function>"], 2845267dd35SPaolo Bonzini [$type_env, "<envar>\$1</envar>"], 285df31175bSPaolo Bonzini [$type_member_xml, "<literal><structname>\$1</structname>\$2<structfield>\$3</structfield></literal>"], 286df31175bSPaolo Bonzini [$type_fallback_xml, "<structname>\$1</structname>"] 2874d732701SDanilo Cesar Lemes de Paula ); 2885c98fc03SJohannes Bergmy $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds# gnome, docbook format 2914d732701SDanilo Cesar Lemes de Paulamy @highlights_gnome = ( 2924d732701SDanilo Cesar Lemes de Paula [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"], 293b97f193aSMauro Carvalho Chehab [$type_constant2, "<replaceable class=\"option\">\$1</replaceable>"], 2944d732701SDanilo Cesar Lemes de Paula [$type_func, "<function>\$1</function>"], 295df31175bSPaolo Bonzini [$type_enum, "<type>\$1</type>"], 2964d732701SDanilo Cesar Lemes de Paula [$type_struct, "<structname>\$1</structname>"], 297df31175bSPaolo Bonzini [$type_typedef, "<type>\$1</type>"], 298df31175bSPaolo Bonzini [$type_union, "<structname>\$1</structname>"], 2994d732701SDanilo Cesar Lemes de Paula [$type_env, "<envar>\$1</envar>"], 3005267dd35SPaolo Bonzini [$type_param, "<parameter>\$1</parameter>" ], 301df31175bSPaolo Bonzini [$type_member, "<literal><structname>\$1</structname>\$2<structfield>\$3</structfield></literal>"], 302df31175bSPaolo Bonzini [$type_fallback, "<structname>\$1</structname>"] 3034d732701SDanilo Cesar Lemes de Paula ); 3041da177e4SLinus Torvaldsmy $blankline_gnome = "</para><para>\n"; 3051da177e4SLinus Torvalds 3061da177e4SLinus Torvalds# these are pretty rough 3074d732701SDanilo Cesar Lemes de Paulamy @highlights_man = ( 3084d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 309b97f193aSMauro Carvalho Chehab [$type_constant2, "\$1"], 3104d732701SDanilo Cesar Lemes de Paula [$type_func, "\\\\fB\$1\\\\fP"], 311df31175bSPaolo Bonzini [$type_enum, "\\\\fI\$1\\\\fP"], 3124d732701SDanilo Cesar Lemes de Paula [$type_struct, "\\\\fI\$1\\\\fP"], 313df31175bSPaolo Bonzini [$type_typedef, "\\\\fI\$1\\\\fP"], 314df31175bSPaolo Bonzini [$type_union, "\\\\fI\$1\\\\fP"], 3155267dd35SPaolo Bonzini [$type_param, "\\\\fI\$1\\\\fP"], 316df31175bSPaolo Bonzini [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], 317df31175bSPaolo Bonzini [$type_fallback, "\\\\fI\$1\\\\fP"] 3184d732701SDanilo Cesar Lemes de Paula ); 3191da177e4SLinus Torvaldsmy $blankline_man = ""; 3201da177e4SLinus Torvalds 3211da177e4SLinus Torvalds# text-mode 3224d732701SDanilo Cesar Lemes de Paulamy @highlights_text = ( 3234d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 324b97f193aSMauro Carvalho Chehab [$type_constant2, "\$1"], 3254d732701SDanilo Cesar Lemes de Paula [$type_func, "\$1"], 326df31175bSPaolo Bonzini [$type_enum, "\$1"], 3274d732701SDanilo Cesar Lemes de Paula [$type_struct, "\$1"], 328df31175bSPaolo Bonzini [$type_typedef, "\$1"], 329df31175bSPaolo Bonzini [$type_union, "\$1"], 3305267dd35SPaolo Bonzini [$type_param, "\$1"], 331df31175bSPaolo Bonzini [$type_member, "\$1\$2\$3"], 332df31175bSPaolo Bonzini [$type_fallback, "\$1"] 3334d732701SDanilo Cesar Lemes de Paula ); 3341da177e4SLinus Torvaldsmy $blankline_text = ""; 3351da177e4SLinus Torvalds 336c0d1b6eeSJonathan Corbet# rst-mode 337c0d1b6eeSJonathan Corbetmy @highlights_rst = ( 338c0d1b6eeSJonathan Corbet [$type_constant, "``\$1``"], 339b97f193aSMauro Carvalho Chehab [$type_constant2, "``\$1``"], 340f3341dcfSJani Nikula # Note: need to escape () to avoid func matching later 3415267dd35SPaolo Bonzini [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], 3425267dd35SPaolo Bonzini [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], 3435219f18aSJonathan Corbet [$type_fp_param, "**\$1\\\\(\\\\)**"], 344a19bce64SJani Nikula [$type_func, "\\:c\\:func\\:`\$1()`"], 345df31175bSPaolo Bonzini [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], 346df31175bSPaolo Bonzini [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], 347df31175bSPaolo Bonzini [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], 348df31175bSPaolo Bonzini [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], 349a7291e7eSJani Nikula # in rst this can refer to any type 350df31175bSPaolo Bonzini [$type_fallback, "\\:c\\:type\\:`\$1`"], 351c0d1b6eeSJonathan Corbet [$type_param, "**\$1**"] 352c0d1b6eeSJonathan Corbet ); 353c0d1b6eeSJonathan Corbetmy $blankline_rst = "\n"; 354c0d1b6eeSJonathan Corbet 355eda603f6SJohannes Berg# list mode 3564d732701SDanilo Cesar Lemes de Paulamy @highlights_list = ( 3574d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 358b97f193aSMauro Carvalho Chehab [$type_constant2, "\$1"], 3594d732701SDanilo Cesar Lemes de Paula [$type_func, "\$1"], 360df31175bSPaolo Bonzini [$type_enum, "\$1"], 3614d732701SDanilo Cesar Lemes de Paula [$type_struct, "\$1"], 362df31175bSPaolo Bonzini [$type_typedef, "\$1"], 363df31175bSPaolo Bonzini [$type_union, "\$1"], 3645267dd35SPaolo Bonzini [$type_param, "\$1"], 365df31175bSPaolo Bonzini [$type_member, "\$1"], 366df31175bSPaolo Bonzini [$type_fallback, "\$1"] 3674d732701SDanilo Cesar Lemes de Paula ); 368eda603f6SJohannes Bergmy $blankline_list = ""; 3691da177e4SLinus Torvalds 3701da177e4SLinus Torvalds# read arguments 3711da177e4SLinus Torvaldsif ($#ARGV == -1) { 3721da177e4SLinus Torvalds usage(); 3731da177e4SLinus Torvalds} 3741da177e4SLinus Torvalds 3758484baaaSRandy Dunlapmy $kernelversion; 3768484baaaSRandy Dunlapmy $dohighlight = ""; 3778484baaaSRandy Dunlap 3781da177e4SLinus Torvaldsmy $verbose = 0; 3791da177e4SLinus Torvaldsmy $output_mode = "man"; 380e314ba31SDaniel Santosmy $output_preformatted = 0; 3814b44595aSJohannes Bergmy $no_doc_sections = 0; 3820b0f5f29SDaniel Vettermy $enable_lineno = 0; 3834d732701SDanilo Cesar Lemes de Paulamy @highlights = @highlights_man; 3841da177e4SLinus Torvaldsmy $blankline = $blankline_man; 3851da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 386b6c3f456SJani Nikula 387b6c3f456SJani Nikulause constant { 388b6c3f456SJani Nikula OUTPUT_ALL => 0, # output all symbols and doc sections 389b6c3f456SJani Nikula OUTPUT_INCLUDE => 1, # output only specified symbols 390b6c3f456SJani Nikula OUTPUT_EXCLUDE => 2, # output everything except specified symbols 391b6c3f456SJani Nikula OUTPUT_EXPORTED => 3, # output exported symbols 392b6c3f456SJani Nikula OUTPUT_INTERNAL => 4, # output non-exported symbols 393b6c3f456SJani Nikula}; 394b6c3f456SJani Nikulamy $output_selection = OUTPUT_ALL; 395b2c4105bSBen Hutchingsmy $show_not_found = 0; 396b2c4105bSBen Hutchings 39788c2b57dSJani Nikulamy @export_file_list; 39888c2b57dSJani Nikula 399b2c4105bSBen Hutchingsmy @build_time; 400b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 401b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 402b2c4105bSBen Hutchings @build_time = gmtime($seconds); 403b2c4105bSBen Hutchings} else { 404b2c4105bSBen Hutchings @build_time = localtime; 405b2c4105bSBen Hutchings} 406b2c4105bSBen Hutchings 4071da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 4081da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 409b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 410b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 4111da177e4SLinus Torvalds 4128484baaaSRandy Dunlap# Essentially these are globals. 413b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 414b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 4151da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 4161da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 4170b0f5f29SDaniel Vettermy $declaration_start_line; 4181da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 4191c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 4201da177e4SLinus Torvalds 421bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 422bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 423bd0e88e5SRandy Dunlap} 424bd0e88e5SRandy Dunlap 4251da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 4261da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 4271da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 4281da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 4291da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 4301da177e4SLinus Torvalds# into html. 4311da177e4SLinus Torvaldsmy $section_counter = 0; 4321da177e4SLinus Torvalds 4331da177e4SLinus Torvaldsmy $lineprefix=""; 4341da177e4SLinus Torvalds 43548af606aSJani Nikula# Parser states 43648af606aSJani Nikulause constant { 43748af606aSJani Nikula STATE_NORMAL => 0, # normal code 43848af606aSJani Nikula STATE_NAME => 1, # looking for function name 43948af606aSJani Nikula STATE_FIELD => 2, # scanning field start 44048af606aSJani Nikula STATE_PROTO => 3, # scanning prototype 44148af606aSJani Nikula STATE_DOCBLOCK => 4, # documentation block 44248af606aSJani Nikula STATE_INLINE => 5, # gathering documentation outside main block 44348af606aSJani Nikula}; 4441da177e4SLinus Torvaldsmy $state; 445850622dfSRandy Dunlapmy $in_doc_sect; 4461da177e4SLinus Torvalds 44748af606aSJani Nikula# Inline documentation state 44848af606aSJani Nikulause constant { 44948af606aSJani Nikula STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 45048af606aSJani Nikula STATE_INLINE_NAME => 1, # looking for member name (@foo:) 45148af606aSJani Nikula STATE_INLINE_TEXT => 2, # looking for member documentation 45248af606aSJani Nikula STATE_INLINE_END => 3, # done 45348af606aSJani Nikula STATE_INLINE_ERROR => 4, # error - Comment without header was found. 45448af606aSJani Nikula # Spit a warning as it's not 455a4c6ebedSDanilo Cesar Lemes de Paula # proper kernel-doc and ignore the rest. 45648af606aSJani Nikula}; 45748af606aSJani Nikulamy $inline_doc_state; 458a4c6ebedSDanilo Cesar Lemes de Paula 4591da177e4SLinus Torvalds#declaration types: can be 4601da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 4611da177e4SLinus Torvaldsmy $decl_type; 4621da177e4SLinus Torvalds 4631da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 4641da177e4SLinus Torvaldsmy $doc_end = '\*/'; 4651da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 46612ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 4671da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 468f624adefSJani Nikula# @params and a strictly limited set of supported section names 4698569de68SJonathan Corbetmy $doc_sect = $doc_com . 470ef00028bSJonathan Corbet '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)'; 47112ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 4721da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 47348af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$'; 47448af606aSJani Nikulamy $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)'; 47548af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$'; 4760c9aa209SJani Nikulamy $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; 47786ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 4781da177e4SLinus Torvalds 4791da177e4SLinus Torvaldsmy %parameterdescs; 4800b0f5f29SDaniel Vettermy %parameterdesc_start_lines; 4811da177e4SLinus Torvaldsmy @parameterlist; 4821da177e4SLinus Torvaldsmy %sections; 4831da177e4SLinus Torvaldsmy @sectionlist; 4840b0f5f29SDaniel Vettermy %section_start_lines; 485a1d94aa5SRandy Dunlapmy $sectcheck; 486a1d94aa5SRandy Dunlapmy $struct_actual; 4871da177e4SLinus Torvalds 4881da177e4SLinus Torvaldsmy $contents = ""; 4890b0f5f29SDaniel Vettermy $new_start_line = 0; 490f624adefSJani Nikula 491f624adefSJani Nikula# the canonical section names. see also $doc_sect above. 4921da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 4931da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 4941da177e4SLinus Torvaldsmy $section = $section_default; 4951da177e4SLinus Torvaldsmy $section_context = "Context"; 4964092bac7SYacine Belkadimy $section_return = "Return"; 4971da177e4SLinus Torvalds 4981da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 4991da177e4SLinus Torvalds 5001da177e4SLinus Torvaldsreset_state(); 5011da177e4SLinus Torvalds 5021da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) { 5031da177e4SLinus Torvalds my $cmd = shift @ARGV; 5041da177e4SLinus Torvalds if ($cmd eq "-html") { 5051da177e4SLinus Torvalds $output_mode = "html"; 5064d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_html; 5071da177e4SLinus Torvalds $blankline = $blankline_html; 5081b40c194SDan Luedtke } elsif ($cmd eq "-html5") { 5091b40c194SDan Luedtke $output_mode = "html5"; 5104d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_html5; 5111b40c194SDan Luedtke $blankline = $blankline_html5; 5121da177e4SLinus Torvalds } elsif ($cmd eq "-man") { 5131da177e4SLinus Torvalds $output_mode = "man"; 5144d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 5151da177e4SLinus Torvalds $blankline = $blankline_man; 5161da177e4SLinus Torvalds } elsif ($cmd eq "-text") { 5171da177e4SLinus Torvalds $output_mode = "text"; 5184d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_text; 5191da177e4SLinus Torvalds $blankline = $blankline_text; 520c0d1b6eeSJonathan Corbet } elsif ($cmd eq "-rst") { 521c0d1b6eeSJonathan Corbet $output_mode = "rst"; 522c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 523c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 5241da177e4SLinus Torvalds } elsif ($cmd eq "-docbook") { 5251da177e4SLinus Torvalds $output_mode = "xml"; 5264d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_xml; 5271da177e4SLinus Torvalds $blankline = $blankline_xml; 528eda603f6SJohannes Berg } elsif ($cmd eq "-list") { 529eda603f6SJohannes Berg $output_mode = "list"; 5304d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_list; 531eda603f6SJohannes Berg $blankline = $blankline_list; 5321da177e4SLinus Torvalds } elsif ($cmd eq "-gnome") { 5331da177e4SLinus Torvalds $output_mode = "gnome"; 5344d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_gnome; 5351da177e4SLinus Torvalds $blankline = $blankline_gnome; 5363a025e1dSMatthew Wilcox } elsif ($cmd eq "-none") { 5373a025e1dSMatthew Wilcox $output_mode = "none"; 5381da177e4SLinus Torvalds } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document 5391da177e4SLinus Torvalds $modulename = shift @ARGV; 5401da177e4SLinus Torvalds } elsif ($cmd eq "-function") { # to only output specific functions 541b6c3f456SJani Nikula $output_selection = OUTPUT_INCLUDE; 5421da177e4SLinus Torvalds $function = shift @ARGV; 5431da177e4SLinus Torvalds $function_table{$function} = 1; 544b6c3f456SJani Nikula } elsif ($cmd eq "-nofunction") { # output all except specific functions 545b6c3f456SJani Nikula $output_selection = OUTPUT_EXCLUDE; 5461da177e4SLinus Torvalds $function = shift @ARGV; 5471da177e4SLinus Torvalds $function_table{$function} = 1; 54886ae2e38SJani Nikula } elsif ($cmd eq "-export") { # only exported symbols 549b6c3f456SJani Nikula $output_selection = OUTPUT_EXPORTED; 550da9726ecSJani Nikula %function_table = (); 55186ae2e38SJani Nikula } elsif ($cmd eq "-internal") { # only non-exported symbols 552b6c3f456SJani Nikula $output_selection = OUTPUT_INTERNAL; 553da9726ecSJani Nikula %function_table = (); 55488c2b57dSJani Nikula } elsif ($cmd eq "-export-file") { 55588c2b57dSJani Nikula my $file = shift @ARGV; 55688c2b57dSJani Nikula push(@export_file_list, $file); 5571da177e4SLinus Torvalds } elsif ($cmd eq "-v") { 5581da177e4SLinus Torvalds $verbose = 1; 5591da177e4SLinus Torvalds } elsif (($cmd eq "-h") || ($cmd eq "--help")) { 5601da177e4SLinus Torvalds usage(); 5614b44595aSJohannes Berg } elsif ($cmd eq '-no-doc-sections') { 5624b44595aSJohannes Berg $no_doc_sections = 1; 5630b0f5f29SDaniel Vetter } elsif ($cmd eq '-enable-lineno') { 5640b0f5f29SDaniel Vetter $enable_lineno = 1; 565e946c43aSJohannes Berg } elsif ($cmd eq '-show-not-found') { 566e946c43aSJohannes Berg $show_not_found = 1; 5671da177e4SLinus Torvalds } 5681da177e4SLinus Torvalds} 5691da177e4SLinus Torvalds 5708484baaaSRandy Dunlap# continue execution near EOF; 5718484baaaSRandy Dunlap 57253f049faSBorislav Petkov# get kernel version from env 57353f049faSBorislav Petkovsub get_kernel_version() { 5741b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 57553f049faSBorislav Petkov 57653f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 57753f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 57853f049faSBorislav Petkov } 57953f049faSBorislav Petkov return $version; 58053f049faSBorislav Petkov} 5811da177e4SLinus Torvalds 5820b0f5f29SDaniel Vetter# 5830b0f5f29SDaniel Vettersub print_lineno { 5840b0f5f29SDaniel Vetter my $lineno = shift; 5850b0f5f29SDaniel Vetter if ($enable_lineno && defined($lineno)) { 5860b0f5f29SDaniel Vetter print "#define LINENO " . $lineno . "\n"; 5870b0f5f29SDaniel Vetter } 5880b0f5f29SDaniel Vetter} 5891da177e4SLinus Torvalds## 5901da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 5911da177e4SLinus Torvalds# 5921da177e4SLinus Torvaldssub dump_section { 59394dc7ad5SRandy Dunlap my $file = shift; 5941da177e4SLinus Torvalds my $name = shift; 5951da177e4SLinus Torvalds my $contents = join "\n", @_; 5961da177e4SLinus Torvalds 59713901ef2SJani Nikula if ($name =~ m/$type_param/) { 5981da177e4SLinus Torvalds $name = $1; 5991da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 600a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 6010b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 6020b0f5f29SDaniel Vetter $new_start_line = 0; 603ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 604ced69090SRandy Dunlap $name = "..."; 605ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 606a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 6070b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 6080b0f5f29SDaniel Vetter $new_start_line = 0; 6091da177e4SLinus Torvalds } else { 61094dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 61195b6be9dSJani Nikula # Only warn on user specified duplicate section names. 61295b6be9dSJani Nikula if ($name ne $section_default) { 61332217761SJani Nikula print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; 61432217761SJani Nikula ++$warnings; 61595b6be9dSJani Nikula } 61632217761SJani Nikula $sections{$name} .= $contents; 61732217761SJani Nikula } else { 6181da177e4SLinus Torvalds $sections{$name} = $contents; 6191da177e4SLinus Torvalds push @sectionlist, $name; 6200b0f5f29SDaniel Vetter $section_start_lines{$name} = $new_start_line; 6210b0f5f29SDaniel Vetter $new_start_line = 0; 6221da177e4SLinus Torvalds } 6231da177e4SLinus Torvalds } 62432217761SJani Nikula} 6251da177e4SLinus Torvalds 6261da177e4SLinus Torvalds## 627b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 628b112e0f7SJohannes Berg# 629b112e0f7SJohannes Bergsub dump_doc_section { 63094dc7ad5SRandy Dunlap my $file = shift; 631b112e0f7SJohannes Berg my $name = shift; 632b112e0f7SJohannes Berg my $contents = join "\n", @_; 633b112e0f7SJohannes Berg 6344b44595aSJohannes Berg if ($no_doc_sections) { 6354b44595aSJohannes Berg return; 6364b44595aSJohannes Berg } 6374b44595aSJohannes Berg 638b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 639b6c3f456SJani Nikula ($output_selection == OUTPUT_INCLUDE && 640b6c3f456SJani Nikula defined($function_table{$name})) || 641b6c3f456SJani Nikula ($output_selection == OUTPUT_EXCLUDE && 642b6c3f456SJani Nikula !defined($function_table{$name}))) 643b112e0f7SJohannes Berg { 64494dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 645b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 646b112e0f7SJohannes Berg 'sections' => \%sections, 647b112e0f7SJohannes Berg 'module' => $modulename, 648b6c3f456SJani Nikula 'content-only' => ($output_selection != OUTPUT_ALL), }); 649b112e0f7SJohannes Berg } 650b112e0f7SJohannes Berg} 651b112e0f7SJohannes Berg 652b112e0f7SJohannes Berg## 6531da177e4SLinus Torvalds# output function 6541da177e4SLinus Torvalds# 6551da177e4SLinus Torvalds# parameterdescs, a hash. 6561da177e4SLinus Torvalds# function => "function name" 6571da177e4SLinus Torvalds# parameterlist => @list of parameters 6581da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 6591da177e4SLinus Torvalds# sectionlist => @list of sections 660a21217daSRandy Dunlap# sections => %section descriptions 6611da177e4SLinus Torvalds# 6621da177e4SLinus Torvalds 6631da177e4SLinus Torvaldssub output_highlight { 6641da177e4SLinus Torvalds my $contents = join "\n",@_; 6651da177e4SLinus Torvalds my $line; 6661da177e4SLinus Torvalds 6671da177e4SLinus Torvalds# DEBUG 6681da177e4SLinus Torvalds# if (!defined $contents) { 6691da177e4SLinus Torvalds# use Carp; 6701da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 6711da177e4SLinus Torvalds# } 6721da177e4SLinus Torvalds 6731b40c194SDan Luedtke if ($output_mode eq "html" || $output_mode eq "html5" || 6741b40c194SDan Luedtke $output_mode eq "xml") { 6756b5b55f6SRandy Dunlap $contents = local_unescape($contents); 6766b5b55f6SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 6772b35f4d9SRandy Dunlap $contents =~ s/\\\\\\/\&/g; 6786b5b55f6SRandy Dunlap } 6793eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 6801da177e4SLinus Torvalds eval $dohighlight; 6811da177e4SLinus Torvalds die $@ if $@; 6823eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 6833eb014a1SRandy Dunlap 6841b40c194SDan Luedtke# strip whitespaces when generating html5 6851b40c194SDan Luedtke if ($output_mode eq "html5") { 6861b40c194SDan Luedtke $contents =~ s/^\s+//; 6871b40c194SDan Luedtke $contents =~ s/\s+$//; 6881b40c194SDan Luedtke } 6891da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 69012ae6779SDaniel Santos if (! $output_preformatted) { 69112ae6779SDaniel Santos $line =~ s/^\s*//; 69212ae6779SDaniel Santos } 6931da177e4SLinus Torvalds if ($line eq ""){ 694e314ba31SDaniel Santos if (! $output_preformatted) { 6956b5b55f6SRandy Dunlap print $lineprefix, local_unescape($blankline); 696e314ba31SDaniel Santos } 6971da177e4SLinus Torvalds } else { 6981da177e4SLinus Torvalds $line =~ s/\\\\\\/\&/g; 699cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 700cdccb316SRandy Dunlap print "\\&$line"; 701cdccb316SRandy Dunlap } else { 7021da177e4SLinus Torvalds print $lineprefix, $line; 7031da177e4SLinus Torvalds } 704cdccb316SRandy Dunlap } 7051da177e4SLinus Torvalds print "\n"; 7061da177e4SLinus Torvalds } 7071da177e4SLinus Torvalds} 7081da177e4SLinus Torvalds 7091da177e4SLinus Torvalds# output sections in html 7101da177e4SLinus Torvaldssub output_section_html(%) { 7111da177e4SLinus Torvalds my %args = %{$_[0]}; 7121da177e4SLinus Torvalds my $section; 7131da177e4SLinus Torvalds 7141da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7151da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 7161da177e4SLinus Torvalds print "<blockquote>\n"; 7171da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7181da177e4SLinus Torvalds print "</blockquote>\n"; 7191da177e4SLinus Torvalds } 7201da177e4SLinus Torvalds} 7211da177e4SLinus Torvalds 7221da177e4SLinus Torvalds# output enum in html 7231da177e4SLinus Torvaldssub output_enum_html(%) { 7241da177e4SLinus Torvalds my %args = %{$_[0]}; 7251da177e4SLinus Torvalds my ($parameter); 7261da177e4SLinus Torvalds my $count; 7271da177e4SLinus Torvalds print "<h2>enum " . $args{'enum'} . "</h2>\n"; 7281da177e4SLinus Torvalds 7291da177e4SLinus Torvalds print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; 7301da177e4SLinus Torvalds $count = 0; 7311da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7321da177e4SLinus Torvalds print " <b>" . $parameter . "</b>"; 7331da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 7341da177e4SLinus Torvalds $count++; 7351da177e4SLinus Torvalds print ",\n"; 7361da177e4SLinus Torvalds } 7371da177e4SLinus Torvalds print "<br>"; 7381da177e4SLinus Torvalds } 7391da177e4SLinus Torvalds print "};<br>\n"; 7401da177e4SLinus Torvalds 7411da177e4SLinus Torvalds print "<h3>Constants</h3>\n"; 7421da177e4SLinus Torvalds print "<dl>\n"; 7431da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7441da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 7451da177e4SLinus Torvalds print "<dd>"; 7461da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter}); 7471da177e4SLinus Torvalds } 7481da177e4SLinus Torvalds print "</dl>\n"; 7491da177e4SLinus Torvalds output_section_html(@_); 7501da177e4SLinus Torvalds print "<hr>\n"; 7511da177e4SLinus Torvalds} 7521da177e4SLinus Torvalds 753d28bee0cSRandy Dunlap# output typedef in html 7541da177e4SLinus Torvaldssub output_typedef_html(%) { 7551da177e4SLinus Torvalds my %args = %{$_[0]}; 7561da177e4SLinus Torvalds my ($parameter); 7571da177e4SLinus Torvalds my $count; 7581da177e4SLinus Torvalds print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; 7591da177e4SLinus Torvalds 7601da177e4SLinus Torvalds print "<b>typedef " . $args{'typedef'} . "</b>\n"; 7611da177e4SLinus Torvalds output_section_html(@_); 7621da177e4SLinus Torvalds print "<hr>\n"; 7631da177e4SLinus Torvalds} 7641da177e4SLinus Torvalds 7651da177e4SLinus Torvalds# output struct in html 7661da177e4SLinus Torvaldssub output_struct_html(%) { 7671da177e4SLinus Torvalds my %args = %{$_[0]}; 7681da177e4SLinus Torvalds my ($parameter); 7691da177e4SLinus Torvalds 770262d9b01SRandy Dunlap print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; 7711da177e4SLinus Torvalds print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; 7721da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7731da177e4SLinus Torvalds if ($parameter =~ /^#/) { 7741da177e4SLinus Torvalds print "$parameter<br>\n"; 7751da177e4SLinus Torvalds next; 7761da177e4SLinus Torvalds } 7771da177e4SLinus Torvalds my $parameter_name = $parameter; 7781da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7791da177e4SLinus Torvalds 7801da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7811da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 7821da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 7831da177e4SLinus Torvalds # pointer-to-function 7843eb014a1SRandy Dunlap print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; 7851da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 7863eb014a1SRandy Dunlap # bitfield 7873eb014a1SRandy Dunlap print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; 7881da177e4SLinus Torvalds } else { 7893eb014a1SRandy Dunlap print " <i>$type</i> <b>$parameter</b>;<br>\n"; 7901da177e4SLinus Torvalds } 7911da177e4SLinus Torvalds } 7921da177e4SLinus Torvalds print "};<br>\n"; 7931da177e4SLinus Torvalds 7941da177e4SLinus Torvalds print "<h3>Members</h3>\n"; 7951da177e4SLinus Torvalds print "<dl>\n"; 7961da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7971da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 7981da177e4SLinus Torvalds 7991da177e4SLinus Torvalds my $parameter_name = $parameter; 8001da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 8011da177e4SLinus Torvalds 8021da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 8031da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 8041da177e4SLinus Torvalds print "<dd>"; 8051da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 8061da177e4SLinus Torvalds } 8071da177e4SLinus Torvalds print "</dl>\n"; 8081da177e4SLinus Torvalds output_section_html(@_); 8091da177e4SLinus Torvalds print "<hr>\n"; 8101da177e4SLinus Torvalds} 8111da177e4SLinus Torvalds 8121da177e4SLinus Torvalds# output function in html 8131da177e4SLinus Torvaldssub output_function_html(%) { 8141da177e4SLinus Torvalds my %args = %{$_[0]}; 8151da177e4SLinus Torvalds my ($parameter, $section); 8161da177e4SLinus Torvalds my $count; 8171da177e4SLinus Torvalds 818262d9b01SRandy Dunlap print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; 8191da177e4SLinus Torvalds print "<i>" . $args{'functiontype'} . "</i>\n"; 8201da177e4SLinus Torvalds print "<b>" . $args{'function'} . "</b>\n"; 8211da177e4SLinus Torvalds print "("; 8221da177e4SLinus Torvalds $count = 0; 8231da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 8241da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 8251da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 8261da177e4SLinus Torvalds # pointer-to-function 8271da177e4SLinus Torvalds print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; 8281da177e4SLinus Torvalds } else { 8291da177e4SLinus Torvalds print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; 8301da177e4SLinus Torvalds } 8311da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 8321da177e4SLinus Torvalds $count++; 8331da177e4SLinus Torvalds print ",\n"; 8341da177e4SLinus Torvalds } 8351da177e4SLinus Torvalds } 8361da177e4SLinus Torvalds print ")\n"; 8371da177e4SLinus Torvalds 8381da177e4SLinus Torvalds print "<h3>Arguments</h3>\n"; 8391da177e4SLinus Torvalds print "<dl>\n"; 8401da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 8411da177e4SLinus Torvalds my $parameter_name = $parameter; 8421da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 8431da177e4SLinus Torvalds 8441da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 8451da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 8461da177e4SLinus Torvalds print "<dd>"; 8471da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 8481da177e4SLinus Torvalds } 8491da177e4SLinus Torvalds print "</dl>\n"; 8501da177e4SLinus Torvalds output_section_html(@_); 8511da177e4SLinus Torvalds print "<hr>\n"; 8521da177e4SLinus Torvalds} 8531da177e4SLinus Torvalds 854b112e0f7SJohannes Berg# output DOC: block header in html 855b112e0f7SJohannes Bergsub output_blockhead_html(%) { 8561da177e4SLinus Torvalds my %args = %{$_[0]}; 8571da177e4SLinus Torvalds my ($parameter, $section); 8581da177e4SLinus Torvalds my $count; 8591da177e4SLinus Torvalds 8601da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 8611da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 8621da177e4SLinus Torvalds print "<ul>\n"; 8631da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 8641da177e4SLinus Torvalds print "</ul>\n"; 8651da177e4SLinus Torvalds } 8661da177e4SLinus Torvalds print "<hr>\n"; 8671da177e4SLinus Torvalds} 8681da177e4SLinus Torvalds 8691b40c194SDan Luedtke# output sections in html5 8701b40c194SDan Luedtkesub output_section_html5(%) { 8711b40c194SDan Luedtke my %args = %{$_[0]}; 8721b40c194SDan Luedtke my $section; 8731b40c194SDan Luedtke 8741b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 8751b40c194SDan Luedtke print "<section>\n"; 8761b40c194SDan Luedtke print "<h1>$section</h1>\n"; 8771b40c194SDan Luedtke print "<p>\n"; 8781b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 8791b40c194SDan Luedtke print "</p>\n"; 8801b40c194SDan Luedtke print "</section>\n"; 8811b40c194SDan Luedtke } 8821b40c194SDan Luedtke} 8831b40c194SDan Luedtke 8841b40c194SDan Luedtke# output enum in html5 8851b40c194SDan Luedtkesub output_enum_html5(%) { 8861b40c194SDan Luedtke my %args = %{$_[0]}; 8871b40c194SDan Luedtke my ($parameter); 8881b40c194SDan Luedtke my $count; 8891b40c194SDan Luedtke my $html5id; 8901b40c194SDan Luedtke 8911b40c194SDan Luedtke $html5id = $args{'enum'}; 8921b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8931b40c194SDan Luedtke print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; 8941b40c194SDan Luedtke print "<h1>enum " . $args{'enum'} . "</h1>\n"; 8951b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8961b40c194SDan Luedtke print "<li>"; 8971b40c194SDan Luedtke print "<span class=\"keyword\">enum</span> "; 8981b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; 8991b40c194SDan Luedtke print "</li>\n"; 9001b40c194SDan Luedtke $count = 0; 9011b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9021b40c194SDan Luedtke print "<li class=\"indent\">"; 9031b40c194SDan Luedtke print "<span class=\"param\">" . $parameter . "</span>"; 9041b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 9051b40c194SDan Luedtke $count++; 9061b40c194SDan Luedtke print ","; 9071b40c194SDan Luedtke } 9081b40c194SDan Luedtke print "</li>\n"; 9091b40c194SDan Luedtke } 9101b40c194SDan Luedtke print "<li>};</li>\n"; 9111b40c194SDan Luedtke print "</ol>\n"; 9121b40c194SDan Luedtke 9131b40c194SDan Luedtke print "<section>\n"; 9141b40c194SDan Luedtke print "<h1>Constants</h1>\n"; 9151b40c194SDan Luedtke print "<dl>\n"; 9161b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9171b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 9181b40c194SDan Luedtke print "<dd>"; 9191b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter}); 9201b40c194SDan Luedtke print "</dd>\n"; 9211b40c194SDan Luedtke } 9221b40c194SDan Luedtke print "</dl>\n"; 9231b40c194SDan Luedtke print "</section>\n"; 9241b40c194SDan Luedtke output_section_html5(@_); 9251b40c194SDan Luedtke print "</article>\n"; 9261b40c194SDan Luedtke} 9271b40c194SDan Luedtke 9281b40c194SDan Luedtke# output typedef in html5 9291b40c194SDan Luedtkesub output_typedef_html5(%) { 9301b40c194SDan Luedtke my %args = %{$_[0]}; 9311b40c194SDan Luedtke my ($parameter); 9321b40c194SDan Luedtke my $count; 9331b40c194SDan Luedtke my $html5id; 9341b40c194SDan Luedtke 9351b40c194SDan Luedtke $html5id = $args{'typedef'}; 9361b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 9371b40c194SDan Luedtke print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; 9381b40c194SDan Luedtke print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; 9391b40c194SDan Luedtke 9401b40c194SDan Luedtke print "<ol class=\"code\">\n"; 9411b40c194SDan Luedtke print "<li>"; 9421b40c194SDan Luedtke print "<span class=\"keyword\">typedef</span> "; 9431b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; 9441b40c194SDan Luedtke print "</li>\n"; 9451b40c194SDan Luedtke print "</ol>\n"; 9461b40c194SDan Luedtke output_section_html5(@_); 9471b40c194SDan Luedtke print "</article>\n"; 9481b40c194SDan Luedtke} 9491b40c194SDan Luedtke 9501b40c194SDan Luedtke# output struct in html5 9511b40c194SDan Luedtkesub output_struct_html5(%) { 9521b40c194SDan Luedtke my %args = %{$_[0]}; 9531b40c194SDan Luedtke my ($parameter); 9541b40c194SDan Luedtke my $html5id; 9551b40c194SDan Luedtke 9561b40c194SDan Luedtke $html5id = $args{'struct'}; 9571b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 9581b40c194SDan Luedtke print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n"; 9591b40c194SDan Luedtke print "<hgroup>\n"; 9601b40c194SDan Luedtke print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>"; 9611b40c194SDan Luedtke print "<h2>". $args{'purpose'} . "</h2>\n"; 9621b40c194SDan Luedtke print "</hgroup>\n"; 9631b40c194SDan Luedtke print "<ol class=\"code\">\n"; 9641b40c194SDan Luedtke print "<li>"; 9651b40c194SDan Luedtke print "<span class=\"type\">" . $args{'type'} . "</span> "; 9661b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'struct'} . "</span> {"; 9671b40c194SDan Luedtke print "</li>\n"; 9681b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9691b40c194SDan Luedtke print "<li class=\"indent\">"; 9701b40c194SDan Luedtke if ($parameter =~ /^#/) { 9711b40c194SDan Luedtke print "<span class=\"param\">" . $parameter ."</span>\n"; 9721b40c194SDan Luedtke print "</li>\n"; 9731b40c194SDan Luedtke next; 9741b40c194SDan Luedtke } 9751b40c194SDan Luedtke my $parameter_name = $parameter; 9761b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 9771b40c194SDan Luedtke 9781b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 9791b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 9801b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 9811b40c194SDan Luedtke # pointer-to-function 9821b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 9831b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9841b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 9851b40c194SDan Luedtke print "(<span class=\"args\">$2</span>);"; 9861b40c194SDan Luedtke } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 9871b40c194SDan Luedtke # bitfield 9881b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 9891b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9901b40c194SDan Luedtke print "<span class=\"bits\">$2</span>;"; 9911b40c194SDan Luedtke } else { 9921b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 9931b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>;"; 9941b40c194SDan Luedtke } 9951b40c194SDan Luedtke print "</li>\n"; 9961b40c194SDan Luedtke } 9971b40c194SDan Luedtke print "<li>};</li>\n"; 9981b40c194SDan Luedtke print "</ol>\n"; 9991b40c194SDan Luedtke 10001b40c194SDan Luedtke print "<section>\n"; 10011b40c194SDan Luedtke print "<h1>Members</h1>\n"; 10021b40c194SDan Luedtke print "<dl>\n"; 10031b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 10041b40c194SDan Luedtke ($parameter =~ /^#/) && next; 10051b40c194SDan Luedtke 10061b40c194SDan Luedtke my $parameter_name = $parameter; 10071b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 10081b40c194SDan Luedtke 10091b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 10101b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 10111b40c194SDan Luedtke print "<dd>"; 10121b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 10131b40c194SDan Luedtke print "</dd>\n"; 10141b40c194SDan Luedtke } 10151b40c194SDan Luedtke print "</dl>\n"; 10161b40c194SDan Luedtke print "</section>\n"; 10171b40c194SDan Luedtke output_section_html5(@_); 10181b40c194SDan Luedtke print "</article>\n"; 10191b40c194SDan Luedtke} 10201b40c194SDan Luedtke 10211b40c194SDan Luedtke# output function in html5 10221b40c194SDan Luedtkesub output_function_html5(%) { 10231b40c194SDan Luedtke my %args = %{$_[0]}; 10241b40c194SDan Luedtke my ($parameter, $section); 10251b40c194SDan Luedtke my $count; 10261b40c194SDan Luedtke my $html5id; 10271b40c194SDan Luedtke 10281b40c194SDan Luedtke $html5id = $args{'function'}; 10291b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 10301b40c194SDan Luedtke print "<article class=\"function\" id=\"func:". $html5id . "\">\n"; 10311b40c194SDan Luedtke print "<hgroup>\n"; 10321b40c194SDan Luedtke print "<h1>" . $args{'function'} . "</h1>"; 10331b40c194SDan Luedtke print "<h2>" . $args{'purpose'} . "</h2>\n"; 10341b40c194SDan Luedtke print "</hgroup>\n"; 10351b40c194SDan Luedtke print "<ol class=\"code\">\n"; 10361b40c194SDan Luedtke print "<li>"; 10371b40c194SDan Luedtke print "<span class=\"type\">" . $args{'functiontype'} . "</span> "; 10381b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'function'} . "</span> ("; 10391b40c194SDan Luedtke print "</li>"; 10401b40c194SDan Luedtke $count = 0; 10411b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 10421b40c194SDan Luedtke print "<li class=\"indent\">"; 10431b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 10441b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 10451b40c194SDan Luedtke # pointer-to-function 10461b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 10471b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 10481b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 10491b40c194SDan Luedtke print "(<span class=\"args\">$2</span>)"; 10501b40c194SDan Luedtke } else { 10511b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 10521b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 10531b40c194SDan Luedtke } 10541b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 10551b40c194SDan Luedtke $count++; 10561b40c194SDan Luedtke print ","; 10571b40c194SDan Luedtke } 10581b40c194SDan Luedtke print "</li>\n"; 10591b40c194SDan Luedtke } 10601b40c194SDan Luedtke print "<li>)</li>\n"; 10611b40c194SDan Luedtke print "</ol>\n"; 10621b40c194SDan Luedtke 10631b40c194SDan Luedtke print "<section>\n"; 10641b40c194SDan Luedtke print "<h1>Arguments</h1>\n"; 10651b40c194SDan Luedtke print "<p>\n"; 10661b40c194SDan Luedtke print "<dl>\n"; 10671b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 10681b40c194SDan Luedtke my $parameter_name = $parameter; 10691b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 10701b40c194SDan Luedtke 10711b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 10721b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 10731b40c194SDan Luedtke print "<dd>"; 10741b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 10751b40c194SDan Luedtke print "</dd>\n"; 10761b40c194SDan Luedtke } 10771b40c194SDan Luedtke print "</dl>\n"; 10781b40c194SDan Luedtke print "</section>\n"; 10791b40c194SDan Luedtke output_section_html5(@_); 10801b40c194SDan Luedtke print "</article>\n"; 10811b40c194SDan Luedtke} 10821b40c194SDan Luedtke 10831b40c194SDan Luedtke# output DOC: block header in html5 10841b40c194SDan Luedtkesub output_blockhead_html5(%) { 10851b40c194SDan Luedtke my %args = %{$_[0]}; 10861b40c194SDan Luedtke my ($parameter, $section); 10871b40c194SDan Luedtke my $count; 10881b40c194SDan Luedtke my $html5id; 10891b40c194SDan Luedtke 10901b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 10911b40c194SDan Luedtke $html5id = $section; 10921b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 10931b40c194SDan Luedtke print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n"; 10941b40c194SDan Luedtke print "<h1>$section</h1>\n"; 10951b40c194SDan Luedtke print "<p>\n"; 10961b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 10971b40c194SDan Luedtke print "</p>\n"; 10981b40c194SDan Luedtke } 10991b40c194SDan Luedtke print "</article>\n"; 11001b40c194SDan Luedtke} 11011b40c194SDan Luedtke 11021da177e4SLinus Torvaldssub output_section_xml(%) { 11031da177e4SLinus Torvalds my %args = %{$_[0]}; 11041da177e4SLinus Torvalds my $section; 11051da177e4SLinus Torvalds # print out each section 11061da177e4SLinus Torvalds $lineprefix=" "; 11071da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1108c73894c1SRich Walker print "<refsect1>\n"; 1109c73894c1SRich Walker print "<title>$section</title>\n"; 11101da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 1111c73894c1SRich Walker print "<informalexample><programlisting>\n"; 1112e314ba31SDaniel Santos $output_preformatted = 1; 1113c73894c1SRich Walker } else { 1114c73894c1SRich Walker print "<para>\n"; 11151da177e4SLinus Torvalds } 11161da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1117e314ba31SDaniel Santos $output_preformatted = 0; 11181da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 1119c73894c1SRich Walker print "</programlisting></informalexample>\n"; 1120c73894c1SRich Walker } else { 1121c73894c1SRich Walker print "</para>\n"; 11221da177e4SLinus Torvalds } 1123c73894c1SRich Walker print "</refsect1>\n"; 11241da177e4SLinus Torvalds } 11251da177e4SLinus Torvalds} 11261da177e4SLinus Torvalds 11271da177e4SLinus Torvalds# output function in XML DocBook 11281da177e4SLinus Torvaldssub output_function_xml(%) { 11291da177e4SLinus Torvalds my %args = %{$_[0]}; 11301da177e4SLinus Torvalds my ($parameter, $section); 11311da177e4SLinus Torvalds my $count; 11321da177e4SLinus Torvalds my $id; 11331da177e4SLinus Torvalds 11341da177e4SLinus Torvalds $id = "API-" . $args{'function'}; 11351da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 11361da177e4SLinus Torvalds 11375449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 11388b0c2d98SMartin Waitz print "<refentryinfo>\n"; 11398b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 11408b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 11418b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 11428b0c2d98SMartin Waitz print "</refentryinfo>\n"; 11431da177e4SLinus Torvalds print "<refmeta>\n"; 11445449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; 11458b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 11460366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 11471da177e4SLinus Torvalds print "</refmeta>\n"; 11481da177e4SLinus Torvalds print "<refnamediv>\n"; 11491da177e4SLinus Torvalds print " <refname>" . $args{'function'} . "</refname>\n"; 11501da177e4SLinus Torvalds print " <refpurpose>\n"; 11511da177e4SLinus Torvalds print " "; 11521da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 11531da177e4SLinus Torvalds print " </refpurpose>\n"; 11541da177e4SLinus Torvalds print "</refnamediv>\n"; 11551da177e4SLinus Torvalds 11561da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 11571da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 11581da177e4SLinus Torvalds print " <funcsynopsis><funcprototype>\n"; 11591da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 11601da177e4SLinus Torvalds print "<function>" . $args{'function'} . " </function></funcdef>\n"; 11611da177e4SLinus Torvalds 11621da177e4SLinus Torvalds $count = 0; 11631da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 11641da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11651da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 11661da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 11671da177e4SLinus Torvalds # pointer-to-function 11681da177e4SLinus Torvalds print " <paramdef>$1<parameter>$parameter</parameter>)\n"; 11691da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 11701da177e4SLinus Torvalds } else { 11711da177e4SLinus Torvalds print " <paramdef>" . $type; 11721da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 11731da177e4SLinus Torvalds } 11741da177e4SLinus Torvalds } 11751da177e4SLinus Torvalds } else { 11766013d544SMartin Waitz print " <void/>\n"; 11771da177e4SLinus Torvalds } 11781da177e4SLinus Torvalds print " </funcprototype></funcsynopsis>\n"; 11791da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 11801da177e4SLinus Torvalds 11811da177e4SLinus Torvalds # print parameters 11821da177e4SLinus Torvalds print "<refsect1>\n <title>Arguments</title>\n"; 11831da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 11841da177e4SLinus Torvalds print " <variablelist>\n"; 11851da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11861da177e4SLinus Torvalds my $parameter_name = $parameter; 11871da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 1188fc6d7af8SPaolo Bonzini $type = $args{'parametertypes'}{$parameter}; 11891da177e4SLinus Torvalds 1190fc6d7af8SPaolo Bonzini print " <varlistentry>\n <term><parameter>$type $parameter</parameter></term>\n"; 11911da177e4SLinus Torvalds print " <listitem>\n <para>\n"; 11921da177e4SLinus Torvalds $lineprefix=" "; 11931da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 11941da177e4SLinus Torvalds print " </para>\n </listitem>\n </varlistentry>\n"; 11951da177e4SLinus Torvalds } 11961da177e4SLinus Torvalds print " </variablelist>\n"; 11971da177e4SLinus Torvalds } else { 11981da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 11991da177e4SLinus Torvalds } 12001da177e4SLinus Torvalds print "</refsect1>\n"; 12011da177e4SLinus Torvalds 12021da177e4SLinus Torvalds output_section_xml(@_); 12031da177e4SLinus Torvalds print "</refentry>\n\n"; 12041da177e4SLinus Torvalds} 12051da177e4SLinus Torvalds 12061da177e4SLinus Torvalds# output struct in XML DocBook 12071da177e4SLinus Torvaldssub output_struct_xml(%) { 12081da177e4SLinus Torvalds my %args = %{$_[0]}; 12091da177e4SLinus Torvalds my ($parameter, $section); 12101da177e4SLinus Torvalds my $id; 12111da177e4SLinus Torvalds 12121da177e4SLinus Torvalds $id = "API-struct-" . $args{'struct'}; 12131da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12141da177e4SLinus Torvalds 12155449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 12168b0c2d98SMartin Waitz print "<refentryinfo>\n"; 12178b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 12188b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 12198b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 12208b0c2d98SMartin Waitz print "</refentryinfo>\n"; 12211da177e4SLinus Torvalds print "<refmeta>\n"; 12225449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; 12238b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 12240366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 12251da177e4SLinus Torvalds print "</refmeta>\n"; 12261da177e4SLinus Torvalds print "<refnamediv>\n"; 12271da177e4SLinus Torvalds print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; 12281da177e4SLinus Torvalds print " <refpurpose>\n"; 12291da177e4SLinus Torvalds print " "; 12301da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 12311da177e4SLinus Torvalds print " </refpurpose>\n"; 12321da177e4SLinus Torvalds print "</refnamediv>\n"; 12331da177e4SLinus Torvalds 12341da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 12351da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 12361da177e4SLinus Torvalds print " <programlisting>\n"; 12371da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 12381da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12391da177e4SLinus Torvalds if ($parameter =~ /^#/) { 12402b35f4d9SRandy Dunlap my $prm = $parameter; 12412b35f4d9SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 12422b35f4d9SRandy Dunlap # This allows us to have #define macros interspersed in a struct. 12432b35f4d9SRandy Dunlap $prm =~ s/\\\\\\/\&/g; 12442b35f4d9SRandy Dunlap print "$prm\n"; 12451da177e4SLinus Torvalds next; 12461da177e4SLinus Torvalds } 12471da177e4SLinus Torvalds 12481da177e4SLinus Torvalds my $parameter_name = $parameter; 12491da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12501da177e4SLinus Torvalds 12511da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 12521da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 12531da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 12541da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 12551da177e4SLinus Torvalds # pointer-to-function 12561da177e4SLinus Torvalds print " $1 $parameter) ($2);\n"; 12571da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 125851f5a0c8SRandy Dunlap # bitfield 12591da177e4SLinus Torvalds print " $1 $parameter$2;\n"; 12601da177e4SLinus Torvalds } else { 12611da177e4SLinus Torvalds print " " . $type . " " . $parameter . ";\n"; 12621da177e4SLinus Torvalds } 12631da177e4SLinus Torvalds } 12641da177e4SLinus Torvalds print "};"; 12651da177e4SLinus Torvalds print " </programlisting>\n"; 12661da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 12671da177e4SLinus Torvalds 12681da177e4SLinus Torvalds print " <refsect1>\n"; 12691da177e4SLinus Torvalds print " <title>Members</title>\n"; 12701da177e4SLinus Torvalds 127139f00c08SRandy Dunlap if ($#{$args{'parameterlist'}} >= 0) { 12721da177e4SLinus Torvalds print " <variablelist>\n"; 12731da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12741da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 12751da177e4SLinus Torvalds 12761da177e4SLinus Torvalds my $parameter_name = $parameter; 12771da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12781da177e4SLinus Torvalds 12791da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 12801da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1281fc6d7af8SPaolo Bonzini $type = $args{'parametertypes'}{$parameter}; 12821da177e4SLinus Torvalds print " <varlistentry>"; 1283fc6d7af8SPaolo Bonzini print " <term><literal>$type $parameter</literal></term>\n"; 12841da177e4SLinus Torvalds print " <listitem><para>\n"; 12851da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 12861da177e4SLinus Torvalds print " </para></listitem>\n"; 12871da177e4SLinus Torvalds print " </varlistentry>\n"; 12881da177e4SLinus Torvalds } 12891da177e4SLinus Torvalds print " </variablelist>\n"; 129039f00c08SRandy Dunlap } else { 129139f00c08SRandy Dunlap print " <para>\n None\n </para>\n"; 129239f00c08SRandy Dunlap } 12931da177e4SLinus Torvalds print " </refsect1>\n"; 12941da177e4SLinus Torvalds 12951da177e4SLinus Torvalds output_section_xml(@_); 12961da177e4SLinus Torvalds 12971da177e4SLinus Torvalds print "</refentry>\n\n"; 12981da177e4SLinus Torvalds} 12991da177e4SLinus Torvalds 13001da177e4SLinus Torvalds# output enum in XML DocBook 13011da177e4SLinus Torvaldssub output_enum_xml(%) { 13021da177e4SLinus Torvalds my %args = %{$_[0]}; 13031da177e4SLinus Torvalds my ($parameter, $section); 13041da177e4SLinus Torvalds my $count; 13051da177e4SLinus Torvalds my $id; 13061da177e4SLinus Torvalds 13071da177e4SLinus Torvalds $id = "API-enum-" . $args{'enum'}; 13081da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13091da177e4SLinus Torvalds 13105449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 13118b0c2d98SMartin Waitz print "<refentryinfo>\n"; 13128b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 13138b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 13148b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 13158b0c2d98SMartin Waitz print "</refentryinfo>\n"; 13161da177e4SLinus Torvalds print "<refmeta>\n"; 13175449bc94SPavel Pisa print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; 13188b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 13190366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 13201da177e4SLinus Torvalds print "</refmeta>\n"; 13211da177e4SLinus Torvalds print "<refnamediv>\n"; 13221da177e4SLinus Torvalds print " <refname>enum " . $args{'enum'} . "</refname>\n"; 13231da177e4SLinus Torvalds print " <refpurpose>\n"; 13241da177e4SLinus Torvalds print " "; 13251da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 13261da177e4SLinus Torvalds print " </refpurpose>\n"; 13271da177e4SLinus Torvalds print "</refnamediv>\n"; 13281da177e4SLinus Torvalds 13291da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 13301da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 13311da177e4SLinus Torvalds print " <programlisting>\n"; 13321da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 13331da177e4SLinus Torvalds $count = 0; 13341da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13351da177e4SLinus Torvalds print " $parameter"; 13361da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 13371da177e4SLinus Torvalds $count++; 13381da177e4SLinus Torvalds print ","; 13391da177e4SLinus Torvalds } 13401da177e4SLinus Torvalds print "\n"; 13411da177e4SLinus Torvalds } 13421da177e4SLinus Torvalds print "};"; 13431da177e4SLinus Torvalds print " </programlisting>\n"; 13441da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 13451da177e4SLinus Torvalds 13461da177e4SLinus Torvalds print "<refsect1>\n"; 13471da177e4SLinus Torvalds print " <title>Constants</title>\n"; 13481da177e4SLinus Torvalds print " <variablelist>\n"; 13491da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13501da177e4SLinus Torvalds my $parameter_name = $parameter; 13511da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 13521da177e4SLinus Torvalds 13531da177e4SLinus Torvalds print " <varlistentry>"; 13541da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 13551da177e4SLinus Torvalds print " <listitem><para>\n"; 13561da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 13571da177e4SLinus Torvalds print " </para></listitem>\n"; 13581da177e4SLinus Torvalds print " </varlistentry>\n"; 13591da177e4SLinus Torvalds } 13601da177e4SLinus Torvalds print " </variablelist>\n"; 13611da177e4SLinus Torvalds print "</refsect1>\n"; 13621da177e4SLinus Torvalds 13631da177e4SLinus Torvalds output_section_xml(@_); 13641da177e4SLinus Torvalds 13651da177e4SLinus Torvalds print "</refentry>\n\n"; 13661da177e4SLinus Torvalds} 13671da177e4SLinus Torvalds 13681da177e4SLinus Torvalds# output typedef in XML DocBook 13691da177e4SLinus Torvaldssub output_typedef_xml(%) { 13701da177e4SLinus Torvalds my %args = %{$_[0]}; 13711da177e4SLinus Torvalds my ($parameter, $section); 13721da177e4SLinus Torvalds my $id; 13731da177e4SLinus Torvalds 13741da177e4SLinus Torvalds $id = "API-typedef-" . $args{'typedef'}; 13751da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13761da177e4SLinus Torvalds 13775449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 13788b0c2d98SMartin Waitz print "<refentryinfo>\n"; 13798b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 13808b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 13818b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 13828b0c2d98SMartin Waitz print "</refentryinfo>\n"; 13831da177e4SLinus Torvalds print "<refmeta>\n"; 13845449bc94SPavel Pisa print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; 13858b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 13861da177e4SLinus Torvalds print "</refmeta>\n"; 13871da177e4SLinus Torvalds print "<refnamediv>\n"; 13881da177e4SLinus Torvalds print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; 13891da177e4SLinus Torvalds print " <refpurpose>\n"; 13901da177e4SLinus Torvalds print " "; 13911da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 13921da177e4SLinus Torvalds print " </refpurpose>\n"; 13931da177e4SLinus Torvalds print "</refnamediv>\n"; 13941da177e4SLinus Torvalds 13951da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 13961da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 13971da177e4SLinus Torvalds print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; 13981da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 13991da177e4SLinus Torvalds 14001da177e4SLinus Torvalds output_section_xml(@_); 14011da177e4SLinus Torvalds 14021da177e4SLinus Torvalds print "</refentry>\n\n"; 14031da177e4SLinus Torvalds} 14041da177e4SLinus Torvalds 14051da177e4SLinus Torvalds# output in XML DocBook 1406b112e0f7SJohannes Bergsub output_blockhead_xml(%) { 14071da177e4SLinus Torvalds my %args = %{$_[0]}; 14081da177e4SLinus Torvalds my ($parameter, $section); 14091da177e4SLinus Torvalds my $count; 14101da177e4SLinus Torvalds 14111da177e4SLinus Torvalds my $id = $args{'module'}; 14121da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 14131da177e4SLinus Torvalds 14141da177e4SLinus Torvalds # print out each section 14151da177e4SLinus Torvalds $lineprefix=" "; 14161da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1417b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1418b112e0f7SJohannes Berg print "<refsect1>\n <title>$section</title>\n"; 1419b112e0f7SJohannes Berg } 14201da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 14211da177e4SLinus Torvalds print "<example><para>\n"; 1422e314ba31SDaniel Santos $output_preformatted = 1; 1423b112e0f7SJohannes Berg } else { 1424b112e0f7SJohannes Berg print "<para>\n"; 14251da177e4SLinus Torvalds } 14261da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1427e314ba31SDaniel Santos $output_preformatted = 0; 14281da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 14291da177e4SLinus Torvalds print "</para></example>\n"; 1430b112e0f7SJohannes Berg } else { 1431b112e0f7SJohannes Berg print "</para>"; 14321da177e4SLinus Torvalds } 1433b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1434b112e0f7SJohannes Berg print "\n</refsect1>\n"; 1435b112e0f7SJohannes Berg } 14361da177e4SLinus Torvalds } 14371da177e4SLinus Torvalds 14381da177e4SLinus Torvalds print "\n\n"; 14391da177e4SLinus Torvalds} 14401da177e4SLinus Torvalds 14411da177e4SLinus Torvalds# output in XML DocBook 14421da177e4SLinus Torvaldssub output_function_gnome { 14431da177e4SLinus Torvalds my %args = %{$_[0]}; 14441da177e4SLinus Torvalds my ($parameter, $section); 14451da177e4SLinus Torvalds my $count; 14461da177e4SLinus Torvalds my $id; 14471da177e4SLinus Torvalds 14481da177e4SLinus Torvalds $id = $args{'module'} . "-" . $args{'function'}; 14491da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 14501da177e4SLinus Torvalds 14511da177e4SLinus Torvalds print "<sect2>\n"; 14521da177e4SLinus Torvalds print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; 14531da177e4SLinus Torvalds 14541da177e4SLinus Torvalds print " <funcsynopsis>\n"; 14551da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 14561da177e4SLinus Torvalds print "<function>" . $args{'function'} . " "; 14571da177e4SLinus Torvalds print "</function></funcdef>\n"; 14581da177e4SLinus Torvalds 14591da177e4SLinus Torvalds $count = 0; 14601da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 14611da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14621da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 14631da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 14641da177e4SLinus Torvalds # pointer-to-function 14651da177e4SLinus Torvalds print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; 14661da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 14671da177e4SLinus Torvalds } else { 14681da177e4SLinus Torvalds print " <paramdef>" . $type; 14691da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 14701da177e4SLinus Torvalds } 14711da177e4SLinus Torvalds } 14721da177e4SLinus Torvalds } else { 14731da177e4SLinus Torvalds print " <void>\n"; 14741da177e4SLinus Torvalds } 14751da177e4SLinus Torvalds print " </funcsynopsis>\n"; 14761da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 14771da177e4SLinus Torvalds print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; 14781da177e4SLinus Torvalds print "<tgroup cols=\"2\">\n"; 14791da177e4SLinus Torvalds print "<colspec colwidth=\"2*\">\n"; 14801da177e4SLinus Torvalds print "<colspec colwidth=\"8*\">\n"; 14811da177e4SLinus Torvalds print "<tbody>\n"; 14821da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14831da177e4SLinus Torvalds my $parameter_name = $parameter; 14841da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14851da177e4SLinus Torvalds 14861da177e4SLinus Torvalds print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; 14871da177e4SLinus Torvalds print " <entry>\n"; 14881da177e4SLinus Torvalds $lineprefix=" "; 14891da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14901da177e4SLinus Torvalds print " </entry></row>\n"; 14911da177e4SLinus Torvalds } 14921da177e4SLinus Torvalds print " </tbody></tgroup></informaltable>\n"; 14931da177e4SLinus Torvalds } else { 14941da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 14951da177e4SLinus Torvalds } 14961da177e4SLinus Torvalds 14971da177e4SLinus Torvalds # print out each section 14981da177e4SLinus Torvalds $lineprefix=" "; 14991da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15001da177e4SLinus Torvalds print "<simplesect>\n <title>$section</title>\n"; 15011da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 15021da177e4SLinus Torvalds print "<example><programlisting>\n"; 1503e314ba31SDaniel Santos $output_preformatted = 1; 15041da177e4SLinus Torvalds } else { 15051da177e4SLinus Torvalds } 15061da177e4SLinus Torvalds print "<para>\n"; 15071da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1508e314ba31SDaniel Santos $output_preformatted = 0; 15091da177e4SLinus Torvalds print "</para>\n"; 15101da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 15111da177e4SLinus Torvalds print "</programlisting></example>\n"; 15121da177e4SLinus Torvalds } else { 15131da177e4SLinus Torvalds } 15141da177e4SLinus Torvalds print " </simplesect>\n"; 15151da177e4SLinus Torvalds } 15161da177e4SLinus Torvalds 15171da177e4SLinus Torvalds print "</sect2>\n\n"; 15181da177e4SLinus Torvalds} 15191da177e4SLinus Torvalds 15201da177e4SLinus Torvalds## 15211da177e4SLinus Torvalds# output function in man 15221da177e4SLinus Torvaldssub output_function_man(%) { 15231da177e4SLinus Torvalds my %args = %{$_[0]}; 15241da177e4SLinus Torvalds my ($parameter, $section); 15251da177e4SLinus Torvalds my $count; 15261da177e4SLinus Torvalds 15271da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 15281da177e4SLinus Torvalds 15291da177e4SLinus Torvalds print ".SH NAME\n"; 15301da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 15311da177e4SLinus Torvalds 15321da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 1533a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 15341da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 1535a21217daSRandy Dunlap } else { 1536a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 1537a21217daSRandy Dunlap } 15381da177e4SLinus Torvalds $count = 0; 15391da177e4SLinus Torvalds my $parenth = "("; 15401da177e4SLinus Torvalds my $post = ","; 15411da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15421da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 15431da177e4SLinus Torvalds $post = ");"; 15441da177e4SLinus Torvalds } 15451da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 15461da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 15471da177e4SLinus Torvalds # pointer-to-function 15481da177e4SLinus Torvalds print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 15491da177e4SLinus Torvalds } else { 15501da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 15511da177e4SLinus Torvalds print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 15521da177e4SLinus Torvalds } 15531da177e4SLinus Torvalds $count++; 15541da177e4SLinus Torvalds $parenth = ""; 15551da177e4SLinus Torvalds } 15561da177e4SLinus Torvalds 15571da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 15581da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15591da177e4SLinus Torvalds my $parameter_name = $parameter; 15601da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15611da177e4SLinus Torvalds 15621da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 15631da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 15641da177e4SLinus Torvalds } 15651da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15661da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 15671da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15681da177e4SLinus Torvalds } 15691da177e4SLinus Torvalds} 15701da177e4SLinus Torvalds 15711da177e4SLinus Torvalds## 15721da177e4SLinus Torvalds# output enum in man 15731da177e4SLinus Torvaldssub output_enum_man(%) { 15741da177e4SLinus Torvalds my %args = %{$_[0]}; 15751da177e4SLinus Torvalds my ($parameter, $section); 15761da177e4SLinus Torvalds my $count; 15771da177e4SLinus Torvalds 15781da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 15791da177e4SLinus Torvalds 15801da177e4SLinus Torvalds print ".SH NAME\n"; 15811da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 15821da177e4SLinus Torvalds 15831da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 15841da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 15851da177e4SLinus Torvalds $count = 0; 15861da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15871da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 15881da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 15891da177e4SLinus Torvalds print "\n};\n"; 15901da177e4SLinus Torvalds last; 15911da177e4SLinus Torvalds } 15921da177e4SLinus Torvalds else { 15931da177e4SLinus Torvalds print ", \n.br\n"; 15941da177e4SLinus Torvalds } 15951da177e4SLinus Torvalds $count++; 15961da177e4SLinus Torvalds } 15971da177e4SLinus Torvalds 15981da177e4SLinus Torvalds print ".SH Constants\n"; 15991da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16001da177e4SLinus Torvalds my $parameter_name = $parameter; 16011da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16021da177e4SLinus Torvalds 16031da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 16041da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 16051da177e4SLinus Torvalds } 16061da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16071da177e4SLinus Torvalds print ".SH \"$section\"\n"; 16081da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16091da177e4SLinus Torvalds } 16101da177e4SLinus Torvalds} 16111da177e4SLinus Torvalds 16121da177e4SLinus Torvalds## 16131da177e4SLinus Torvalds# output struct in man 16141da177e4SLinus Torvaldssub output_struct_man(%) { 16151da177e4SLinus Torvalds my %args = %{$_[0]}; 16161da177e4SLinus Torvalds my ($parameter, $section); 16171da177e4SLinus Torvalds 16181da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 16191da177e4SLinus Torvalds 16201da177e4SLinus Torvalds print ".SH NAME\n"; 16211da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 16221da177e4SLinus Torvalds 16231da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 16241da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 16251da177e4SLinus Torvalds 16261da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 16271da177e4SLinus Torvalds if ($parameter =~ /^#/) { 16281da177e4SLinus Torvalds print ".BI \"$parameter\"\n.br\n"; 16291da177e4SLinus Torvalds next; 16301da177e4SLinus Torvalds } 16311da177e4SLinus Torvalds my $parameter_name = $parameter; 16321da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16331da177e4SLinus Torvalds 16341da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 16351da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 16361da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 16371da177e4SLinus Torvalds # pointer-to-function 16381da177e4SLinus Torvalds print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; 16391da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 16401d7e1d45SRandy.Dunlap # bitfield 16411d7e1d45SRandy.Dunlap print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; 16421da177e4SLinus Torvalds } else { 16431da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 16441da177e4SLinus Torvalds print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; 16451da177e4SLinus Torvalds } 16461da177e4SLinus Torvalds print "\n.br\n"; 16471da177e4SLinus Torvalds } 16481da177e4SLinus Torvalds print "};\n.br\n"; 16491da177e4SLinus Torvalds 1650c51d3dacSRandy Dunlap print ".SH Members\n"; 16511da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16521da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 16531da177e4SLinus Torvalds 16541da177e4SLinus Torvalds my $parameter_name = $parameter; 16551da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16561da177e4SLinus Torvalds 16571da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 16581da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 16591da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 16601da177e4SLinus Torvalds } 16611da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16621da177e4SLinus Torvalds print ".SH \"$section\"\n"; 16631da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16641da177e4SLinus Torvalds } 16651da177e4SLinus Torvalds} 16661da177e4SLinus Torvalds 16671da177e4SLinus Torvalds## 16681da177e4SLinus Torvalds# output typedef in man 16691da177e4SLinus Torvaldssub output_typedef_man(%) { 16701da177e4SLinus Torvalds my %args = %{$_[0]}; 16711da177e4SLinus Torvalds my ($parameter, $section); 16721da177e4SLinus Torvalds 16731da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 16741da177e4SLinus Torvalds 16751da177e4SLinus Torvalds print ".SH NAME\n"; 16761da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 16771da177e4SLinus Torvalds 16781da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16791da177e4SLinus Torvalds print ".SH \"$section\"\n"; 16801da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16811da177e4SLinus Torvalds } 16821da177e4SLinus Torvalds} 16831da177e4SLinus Torvalds 1684b112e0f7SJohannes Bergsub output_blockhead_man(%) { 16851da177e4SLinus Torvalds my %args = %{$_[0]}; 16861da177e4SLinus Torvalds my ($parameter, $section); 16871da177e4SLinus Torvalds my $count; 16881da177e4SLinus Torvalds 16891da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 16901da177e4SLinus Torvalds 16911da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16921da177e4SLinus Torvalds print ".SH \"$section\"\n"; 16931da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16941da177e4SLinus Torvalds } 16951da177e4SLinus Torvalds} 16961da177e4SLinus Torvalds 16971da177e4SLinus Torvalds## 16981da177e4SLinus Torvalds# output in text 16991da177e4SLinus Torvaldssub output_function_text(%) { 17001da177e4SLinus Torvalds my %args = %{$_[0]}; 17011da177e4SLinus Torvalds my ($parameter, $section); 1702a21217daSRandy Dunlap my $start; 17031da177e4SLinus Torvalds 1704f47634b2SRandy Dunlap print "Name:\n\n"; 1705f47634b2SRandy Dunlap print $args{'function'} . " - " . $args{'purpose'} . "\n"; 1706f47634b2SRandy Dunlap 1707f47634b2SRandy Dunlap print "\nSynopsis:\n\n"; 1708a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 1709a21217daSRandy Dunlap $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1710a21217daSRandy Dunlap } else { 1711a21217daSRandy Dunlap $start = $args{'function'} . " ("; 1712a21217daSRandy Dunlap } 17131da177e4SLinus Torvalds print $start; 1714a21217daSRandy Dunlap 17151da177e4SLinus Torvalds my $count = 0; 17161da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 17171da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 17181da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 17191da177e4SLinus Torvalds # pointer-to-function 17201da177e4SLinus Torvalds print $1 . $parameter . ") (" . $2; 17211da177e4SLinus Torvalds } else { 17221da177e4SLinus Torvalds print $type . " " . $parameter; 17231da177e4SLinus Torvalds } 17241da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 17251da177e4SLinus Torvalds $count++; 17261da177e4SLinus Torvalds print ",\n"; 17271da177e4SLinus Torvalds print " " x length($start); 17281da177e4SLinus Torvalds } else { 17291da177e4SLinus Torvalds print ");\n\n"; 17301da177e4SLinus Torvalds } 17311da177e4SLinus Torvalds } 17321da177e4SLinus Torvalds 17331da177e4SLinus Torvalds print "Arguments:\n\n"; 17341da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17351da177e4SLinus Torvalds my $parameter_name = $parameter; 17361da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 17371da177e4SLinus Torvalds 17381da177e4SLinus Torvalds print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; 17391da177e4SLinus Torvalds } 17401da177e4SLinus Torvalds output_section_text(@_); 17411da177e4SLinus Torvalds} 17421da177e4SLinus Torvalds 17431da177e4SLinus Torvalds#output sections in text 17441da177e4SLinus Torvaldssub output_section_text(%) { 17451da177e4SLinus Torvalds my %args = %{$_[0]}; 17461da177e4SLinus Torvalds my $section; 17471da177e4SLinus Torvalds 17481da177e4SLinus Torvalds print "\n"; 17491da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 17501da177e4SLinus Torvalds print "$section:\n\n"; 17511da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 17521da177e4SLinus Torvalds } 17531da177e4SLinus Torvalds print "\n\n"; 17541da177e4SLinus Torvalds} 17551da177e4SLinus Torvalds 17561da177e4SLinus Torvalds# output enum in text 17571da177e4SLinus Torvaldssub output_enum_text(%) { 17581da177e4SLinus Torvalds my %args = %{$_[0]}; 17591da177e4SLinus Torvalds my ($parameter); 17601da177e4SLinus Torvalds my $count; 17611da177e4SLinus Torvalds print "Enum:\n\n"; 17621da177e4SLinus Torvalds 17631d7e1d45SRandy.Dunlap print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; 17641da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 17651da177e4SLinus Torvalds $count = 0; 17661da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17671da177e4SLinus Torvalds print "\t$parameter"; 17681da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 17691da177e4SLinus Torvalds $count++; 17701da177e4SLinus Torvalds print ","; 17711da177e4SLinus Torvalds } 17721da177e4SLinus Torvalds print "\n"; 17731da177e4SLinus Torvalds } 17741da177e4SLinus Torvalds print "};\n\n"; 17751da177e4SLinus Torvalds 17761da177e4SLinus Torvalds print "Constants:\n\n"; 17771da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17781da177e4SLinus Torvalds print "$parameter\n\t"; 17791da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter} . "\n"; 17801da177e4SLinus Torvalds } 17811da177e4SLinus Torvalds 17821da177e4SLinus Torvalds output_section_text(@_); 17831da177e4SLinus Torvalds} 17841da177e4SLinus Torvalds 17851da177e4SLinus Torvalds# output typedef in text 17861da177e4SLinus Torvaldssub output_typedef_text(%) { 17871da177e4SLinus Torvalds my %args = %{$_[0]}; 17881da177e4SLinus Torvalds my ($parameter); 17891da177e4SLinus Torvalds my $count; 17901da177e4SLinus Torvalds print "Typedef:\n\n"; 17911da177e4SLinus Torvalds 17921d7e1d45SRandy.Dunlap print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; 17931da177e4SLinus Torvalds output_section_text(@_); 17941da177e4SLinus Torvalds} 17951da177e4SLinus Torvalds 17961da177e4SLinus Torvalds# output struct as text 17971da177e4SLinus Torvaldssub output_struct_text(%) { 17981da177e4SLinus Torvalds my %args = %{$_[0]}; 17991da177e4SLinus Torvalds my ($parameter); 18001da177e4SLinus Torvalds 18011d7e1d45SRandy.Dunlap print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; 18021da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 18031da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 18041da177e4SLinus Torvalds if ($parameter =~ /^#/) { 18051da177e4SLinus Torvalds print "$parameter\n"; 18061da177e4SLinus Torvalds next; 18071da177e4SLinus Torvalds } 18081da177e4SLinus Torvalds 18091da177e4SLinus Torvalds my $parameter_name = $parameter; 18101da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 18111da177e4SLinus Torvalds 18121da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 18131da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 18141da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 18151da177e4SLinus Torvalds # pointer-to-function 18161da177e4SLinus Torvalds print "\t$1 $parameter) ($2);\n"; 18171da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 181851f5a0c8SRandy Dunlap # bitfield 18191da177e4SLinus Torvalds print "\t$1 $parameter$2;\n"; 18201da177e4SLinus Torvalds } else { 18211da177e4SLinus Torvalds print "\t" . $type . " " . $parameter . ";\n"; 18221da177e4SLinus Torvalds } 18231da177e4SLinus Torvalds } 18241da177e4SLinus Torvalds print "};\n\n"; 18251da177e4SLinus Torvalds 18261da177e4SLinus Torvalds print "Members:\n\n"; 18271da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 18281da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 18291da177e4SLinus Torvalds 18301da177e4SLinus Torvalds my $parameter_name = $parameter; 18311da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 18321da177e4SLinus Torvalds 18331da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 18341da177e4SLinus Torvalds print "$parameter\n\t"; 18351da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter_name} . "\n"; 18361da177e4SLinus Torvalds } 18371da177e4SLinus Torvalds print "\n"; 18381da177e4SLinus Torvalds output_section_text(@_); 18391da177e4SLinus Torvalds} 18401da177e4SLinus Torvalds 1841b112e0f7SJohannes Bergsub output_blockhead_text(%) { 18421da177e4SLinus Torvalds my %args = %{$_[0]}; 18431da177e4SLinus Torvalds my ($parameter, $section); 18441da177e4SLinus Torvalds 18451da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 18461da177e4SLinus Torvalds print " $section:\n"; 18471da177e4SLinus Torvalds print " -> "; 18481da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 18491da177e4SLinus Torvalds } 18501da177e4SLinus Torvalds} 18511da177e4SLinus Torvalds 1852c0d1b6eeSJonathan Corbet## 1853c0d1b6eeSJonathan Corbet# output in restructured text 1854c0d1b6eeSJonathan Corbet# 1855c0d1b6eeSJonathan Corbet 1856c0d1b6eeSJonathan Corbet# 1857c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 1858c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 1859c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 1860c0d1b6eeSJonathan Corbet# 1861c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 1862c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1863c0d1b6eeSJonathan Corbet my ($parameter, $section); 1864c0d1b6eeSJonathan Corbet 1865c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 18669e72184bSJani Nikula if ($output_selection != OUTPUT_INCLUDE) { 1867c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 18689e72184bSJani Nikula } 18690b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 1870c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1871c0d1b6eeSJonathan Corbet print "\n"; 1872c0d1b6eeSJonathan Corbet } 1873c0d1b6eeSJonathan Corbet} 1874c0d1b6eeSJonathan Corbet 1875c0d1b6eeSJonathan Corbetsub output_highlight_rst { 1876c0d1b6eeSJonathan Corbet my $contents = join "\n",@_; 1877c0d1b6eeSJonathan Corbet my $line; 1878c0d1b6eeSJonathan Corbet 1879c0d1b6eeSJonathan Corbet # undo the evil effects of xml_escape() earlier 1880c0d1b6eeSJonathan Corbet $contents = xml_unescape($contents); 1881c0d1b6eeSJonathan Corbet 1882c0d1b6eeSJonathan Corbet eval $dohighlight; 1883c0d1b6eeSJonathan Corbet die $@ if $@; 1884c0d1b6eeSJonathan Corbet 1885c0d1b6eeSJonathan Corbet foreach $line (split "\n", $contents) { 1886830066a7SJani Nikula print $lineprefix . $line . "\n"; 1887c0d1b6eeSJonathan Corbet } 1888c0d1b6eeSJonathan Corbet} 1889c0d1b6eeSJonathan Corbet 1890c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 1891c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1892c0d1b6eeSJonathan Corbet my ($parameter, $section); 1893c099ff69SJani Nikula my $oldprefix = $lineprefix; 189482801d06SMauro Carvalho Chehab my $start = ""; 1895c0d1b6eeSJonathan Corbet 189682801d06SMauro Carvalho Chehab if ($args{'typedef'}) { 189782801d06SMauro Carvalho Chehab print ".. c:type:: ". $args{'function'} . "\n\n"; 189882801d06SMauro Carvalho Chehab print_lineno($declaration_start_line); 189982801d06SMauro Carvalho Chehab print " **Typedef**: "; 190082801d06SMauro Carvalho Chehab $lineprefix = ""; 190182801d06SMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 190282801d06SMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 1903c0d1b6eeSJonathan Corbet } else { 190482801d06SMauro Carvalho Chehab print ".. c:function:: "; 190582801d06SMauro Carvalho Chehab } 190682801d06SMauro Carvalho Chehab if ($args{'functiontype'} ne "") { 190782801d06SMauro Carvalho Chehab $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; 190882801d06SMauro Carvalho Chehab } else { 190982801d06SMauro Carvalho Chehab $start .= $args{'function'} . " ("; 1910c0d1b6eeSJonathan Corbet } 1911c0d1b6eeSJonathan Corbet print $start; 1912c0d1b6eeSJonathan Corbet 1913c0d1b6eeSJonathan Corbet my $count = 0; 1914c0d1b6eeSJonathan Corbet foreach my $parameter (@{$args{'parameterlist'}}) { 1915c0d1b6eeSJonathan Corbet if ($count ne 0) { 1916c0d1b6eeSJonathan Corbet print ", "; 1917c0d1b6eeSJonathan Corbet } 1918c0d1b6eeSJonathan Corbet $count++; 1919c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1920a88b1672SMauro Carvalho Chehab 1921c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1922c0d1b6eeSJonathan Corbet # pointer-to-function 1923c0d1b6eeSJonathan Corbet print $1 . $parameter . ") (" . $2; 1924c0d1b6eeSJonathan Corbet } else { 1925c0d1b6eeSJonathan Corbet print $type . " " . $parameter; 1926c0d1b6eeSJonathan Corbet } 1927c0d1b6eeSJonathan Corbet } 192882801d06SMauro Carvalho Chehab if ($args{'typedef'}) { 192982801d06SMauro Carvalho Chehab print ");``\n\n"; 193082801d06SMauro Carvalho Chehab } else { 1931c099ff69SJani Nikula print ")\n\n"; 19320b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1933c099ff69SJani Nikula $lineprefix = " "; 1934c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1935c099ff69SJani Nikula print "\n"; 193682801d06SMauro Carvalho Chehab } 1937c0d1b6eeSJonathan Corbet 1938ecbcfba1SJani Nikula print "**Parameters**\n\n"; 1939c099ff69SJani Nikula $lineprefix = " "; 1940c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1941c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1942ada5f446SGabriel Krisman Bertazi $parameter_name =~ s/\[.*//; 1943c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1944c0d1b6eeSJonathan Corbet 1945c0d1b6eeSJonathan Corbet if ($type ne "") { 1946c0d1b6eeSJonathan Corbet print "``$type $parameter``\n"; 1947c0d1b6eeSJonathan Corbet } else { 1948c0d1b6eeSJonathan Corbet print "``$parameter``\n"; 1949c0d1b6eeSJonathan Corbet } 19500b0f5f29SDaniel Vetter 19510b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 19520b0f5f29SDaniel Vetter 19535e64fa9cSJani Nikula if (defined($args{'parameterdescs'}{$parameter_name}) && 19545e64fa9cSJani Nikula $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 1955c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1956c0d1b6eeSJonathan Corbet } else { 1957d4b08e0cSJani Nikula print " *undescribed*\n"; 1958c0d1b6eeSJonathan Corbet } 1959c0d1b6eeSJonathan Corbet print "\n"; 1960c0d1b6eeSJonathan Corbet } 1961c099ff69SJani Nikula 1962c099ff69SJani Nikula $lineprefix = $oldprefix; 1963c0d1b6eeSJonathan Corbet output_section_rst(@_); 1964c0d1b6eeSJonathan Corbet} 1965c0d1b6eeSJonathan Corbet 1966c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 1967c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1968c0d1b6eeSJonathan Corbet my $section; 1969c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1970c0d1b6eeSJonathan Corbet $lineprefix = ""; 1971c0d1b6eeSJonathan Corbet 1972c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 1973ecbcfba1SJani Nikula print "**$section**\n\n"; 19740b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 1975c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1976c0d1b6eeSJonathan Corbet print "\n"; 1977c0d1b6eeSJonathan Corbet } 1978c0d1b6eeSJonathan Corbet print "\n"; 1979c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1980c0d1b6eeSJonathan Corbet} 1981c0d1b6eeSJonathan Corbet 1982c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 1983c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1984c0d1b6eeSJonathan Corbet my ($parameter); 1985c099ff69SJani Nikula my $oldprefix = $lineprefix; 1986c0d1b6eeSJonathan Corbet my $count; 1987c0d1b6eeSJonathan Corbet my $name = "enum " . $args{'enum'}; 198862850976SJani Nikula 198962850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 19900b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1991c099ff69SJani Nikula $lineprefix = " "; 1992c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1993c099ff69SJani Nikula print "\n"; 1994c0d1b6eeSJonathan Corbet 1995ecbcfba1SJani Nikula print "**Constants**\n\n"; 1996c0d1b6eeSJonathan Corbet $lineprefix = " "; 1997c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1998ecbcfba1SJani Nikula print "``$parameter``\n"; 1999c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 2000c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 2001c0d1b6eeSJonathan Corbet } else { 2002d4b08e0cSJani Nikula print " *undescribed*\n"; 2003c0d1b6eeSJonathan Corbet } 2004c0d1b6eeSJonathan Corbet print "\n"; 2005c0d1b6eeSJonathan Corbet } 2006c099ff69SJani Nikula 2007c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 2008c0d1b6eeSJonathan Corbet output_section_rst(@_); 2009c0d1b6eeSJonathan Corbet} 2010c0d1b6eeSJonathan Corbet 2011c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 2012c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 2013c0d1b6eeSJonathan Corbet my ($parameter); 2014c099ff69SJani Nikula my $oldprefix = $lineprefix; 2015c0d1b6eeSJonathan Corbet my $name = "typedef " . $args{'typedef'}; 2016c0d1b6eeSJonathan Corbet 201762850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 20180b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 2019c099ff69SJani Nikula $lineprefix = " "; 2020c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 2021c099ff69SJani Nikula print "\n"; 2022c0d1b6eeSJonathan Corbet 2023c099ff69SJani Nikula $lineprefix = $oldprefix; 2024c0d1b6eeSJonathan Corbet output_section_rst(@_); 2025c0d1b6eeSJonathan Corbet} 2026c0d1b6eeSJonathan Corbet 2027c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 2028c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 2029c0d1b6eeSJonathan Corbet my ($parameter); 2030c099ff69SJani Nikula my $oldprefix = $lineprefix; 2031c0d1b6eeSJonathan Corbet my $name = $args{'type'} . " " . $args{'struct'}; 2032c0d1b6eeSJonathan Corbet 203362850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 20340b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 2035c099ff69SJani Nikula $lineprefix = " "; 2036c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 2037c099ff69SJani Nikula print "\n"; 2038c0d1b6eeSJonathan Corbet 2039ecbcfba1SJani Nikula print "**Definition**\n\n"; 2040c0d1b6eeSJonathan Corbet print "::\n\n"; 2041c0d1b6eeSJonathan Corbet print " " . $args{'type'} . " " . $args{'struct'} . " {\n"; 2042c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 2043c0d1b6eeSJonathan Corbet if ($parameter =~ /^#/) { 2044c0d1b6eeSJonathan Corbet print " " . "$parameter\n"; 2045c0d1b6eeSJonathan Corbet next; 2046c0d1b6eeSJonathan Corbet } 2047c0d1b6eeSJonathan Corbet 2048c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 2049c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 2050c0d1b6eeSJonathan Corbet 2051c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 2052c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 2053c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 2054c0d1b6eeSJonathan Corbet # pointer-to-function 2055c0d1b6eeSJonathan Corbet print " $1 $parameter) ($2);\n"; 2056c0d1b6eeSJonathan Corbet } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 2057c0d1b6eeSJonathan Corbet # bitfield 2058c0d1b6eeSJonathan Corbet print " $1 $parameter$2;\n"; 2059c0d1b6eeSJonathan Corbet } else { 2060c0d1b6eeSJonathan Corbet print " " . $type . " " . $parameter . ";\n"; 2061c0d1b6eeSJonathan Corbet } 2062c0d1b6eeSJonathan Corbet } 2063c0d1b6eeSJonathan Corbet print " };\n\n"; 2064c0d1b6eeSJonathan Corbet 2065ecbcfba1SJani Nikula print "**Members**\n\n"; 2066c099ff69SJani Nikula $lineprefix = " "; 2067c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 2068c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 2069c0d1b6eeSJonathan Corbet 2070c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 2071c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 2072c0d1b6eeSJonathan Corbet 2073c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 2074c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 20750b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 20766d232c80SMauro Carvalho Chehab print "``" . $parameter . "``\n"; 2077c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 2078c0d1b6eeSJonathan Corbet print "\n"; 2079c0d1b6eeSJonathan Corbet } 2080c0d1b6eeSJonathan Corbet print "\n"; 2081c099ff69SJani Nikula 2082c099ff69SJani Nikula $lineprefix = $oldprefix; 2083c0d1b6eeSJonathan Corbet output_section_rst(@_); 2084c0d1b6eeSJonathan Corbet} 2085c0d1b6eeSJonathan Corbet 2086c0d1b6eeSJonathan Corbet 2087eda603f6SJohannes Berg## list mode output functions 2088eda603f6SJohannes Berg 2089eda603f6SJohannes Bergsub output_function_list(%) { 2090eda603f6SJohannes Berg my %args = %{$_[0]}; 2091eda603f6SJohannes Berg 2092eda603f6SJohannes Berg print $args{'function'} . "\n"; 2093eda603f6SJohannes Berg} 2094eda603f6SJohannes Berg 2095eda603f6SJohannes Berg# output enum in list 2096eda603f6SJohannes Bergsub output_enum_list(%) { 2097eda603f6SJohannes Berg my %args = %{$_[0]}; 2098eda603f6SJohannes Berg print $args{'enum'} . "\n"; 2099eda603f6SJohannes Berg} 2100eda603f6SJohannes Berg 2101eda603f6SJohannes Berg# output typedef in list 2102eda603f6SJohannes Bergsub output_typedef_list(%) { 2103eda603f6SJohannes Berg my %args = %{$_[0]}; 2104eda603f6SJohannes Berg print $args{'typedef'} . "\n"; 2105eda603f6SJohannes Berg} 2106eda603f6SJohannes Berg 2107eda603f6SJohannes Berg# output struct as list 2108eda603f6SJohannes Bergsub output_struct_list(%) { 2109eda603f6SJohannes Berg my %args = %{$_[0]}; 2110eda603f6SJohannes Berg 2111eda603f6SJohannes Berg print $args{'struct'} . "\n"; 2112eda603f6SJohannes Berg} 2113eda603f6SJohannes Berg 2114eda603f6SJohannes Bergsub output_blockhead_list(%) { 2115eda603f6SJohannes Berg my %args = %{$_[0]}; 2116eda603f6SJohannes Berg my ($parameter, $section); 2117eda603f6SJohannes Berg 2118eda603f6SJohannes Berg foreach $section (@{$args{'sectionlist'}}) { 2119eda603f6SJohannes Berg print "DOC: $section\n"; 2120eda603f6SJohannes Berg } 2121eda603f6SJohannes Berg} 2122eda603f6SJohannes Berg 21233a025e1dSMatthew Wilcox 21243a025e1dSMatthew Wilcox## none mode output functions 21253a025e1dSMatthew Wilcox 21263a025e1dSMatthew Wilcoxsub output_function_none(%) { 21273a025e1dSMatthew Wilcox} 21283a025e1dSMatthew Wilcox 21293a025e1dSMatthew Wilcoxsub output_enum_none(%) { 21303a025e1dSMatthew Wilcox} 21313a025e1dSMatthew Wilcox 21323a025e1dSMatthew Wilcoxsub output_typedef_none(%) { 21333a025e1dSMatthew Wilcox} 21343a025e1dSMatthew Wilcox 21353a025e1dSMatthew Wilcoxsub output_struct_none(%) { 21363a025e1dSMatthew Wilcox} 21373a025e1dSMatthew Wilcox 21383a025e1dSMatthew Wilcoxsub output_blockhead_none(%) { 21393a025e1dSMatthew Wilcox} 21403a025e1dSMatthew Wilcox 21411da177e4SLinus Torvalds## 214227205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 214327205744SRandy Dunlap# calls the generated, variable output_ function name based on 214427205744SRandy Dunlap# functype and output_mode 21451da177e4SLinus Torvaldssub output_declaration { 21461da177e4SLinus Torvalds no strict 'refs'; 21471da177e4SLinus Torvalds my $name = shift; 21481da177e4SLinus Torvalds my $functype = shift; 21491da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 2150b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 2151b6c3f456SJani Nikula (($output_selection == OUTPUT_INCLUDE || 2152b6c3f456SJani Nikula $output_selection == OUTPUT_EXPORTED) && 215386ae2e38SJani Nikula defined($function_table{$name})) || 2154b6c3f456SJani Nikula (($output_selection == OUTPUT_EXCLUDE || 2155b6c3f456SJani Nikula $output_selection == OUTPUT_INTERNAL) && 215686ae2e38SJani Nikula !($functype eq "function" && defined($function_table{$name})))) 21571da177e4SLinus Torvalds { 21581da177e4SLinus Torvalds &$func(@_); 21591da177e4SLinus Torvalds $section_counter++; 21601da177e4SLinus Torvalds } 21611da177e4SLinus Torvalds} 21621da177e4SLinus Torvalds 21631da177e4SLinus Torvalds## 216427205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 2165b112e0f7SJohannes Bergsub output_blockhead { 21661da177e4SLinus Torvalds no strict 'refs'; 2167b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 21681da177e4SLinus Torvalds &$func(@_); 21691da177e4SLinus Torvalds $section_counter++; 21701da177e4SLinus Torvalds} 21711da177e4SLinus Torvalds 21721da177e4SLinus Torvalds## 21731da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 21741da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 21751da177e4SLinus Torvaldssub dump_declaration($$) { 21761da177e4SLinus Torvalds no strict 'refs'; 21771da177e4SLinus Torvalds my ($prototype, $file) = @_; 21781da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 21791da177e4SLinus Torvalds &$func(@_); 21801da177e4SLinus Torvalds} 21811da177e4SLinus Torvalds 21821da177e4SLinus Torvaldssub dump_union($$) { 21831da177e4SLinus Torvalds dump_struct(@_); 21841da177e4SLinus Torvalds} 21851da177e4SLinus Torvalds 21861da177e4SLinus Torvaldssub dump_struct($$) { 21871da177e4SLinus Torvalds my $x = shift; 21881da177e4SLinus Torvalds my $file = shift; 2189a1d94aa5SRandy Dunlap my $nested; 21901da177e4SLinus Torvalds 21911da177e4SLinus Torvalds if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 21925cb5c31cSJohannes Berg my $decl_type = $1; 21931da177e4SLinus Torvalds $declaration_name = $2; 21941da177e4SLinus Torvalds my $members = $3; 21951da177e4SLinus Torvalds 21961da177e4SLinus Torvalds # ignore embedded structs or unions 2197a1d94aa5SRandy Dunlap $members =~ s/({.*})//g; 2198a1d94aa5SRandy Dunlap $nested = $1; 21991da177e4SLinus Torvalds 2200aeec46b9SMartin Waitz # ignore members marked private: 22010d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 22020d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 2203aeec46b9SMartin Waitz # strip comments: 2204aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 2205a1d94aa5SRandy Dunlap $nested =~ s/\/\*.*?\*\///gos; 2206ef5da59fSRandy Dunlap # strip attributes 2207f0074929SJonathan Corbet $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 22087b990789SJohannes Berg $members =~ s/__aligned\s*\([^;]*\)//gos; 2209f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; 2210b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 2211*45005b27SMauro Carvalho Chehab $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 22121cb566baSJakub Kicinski # replace DECLARE_HASHTABLE 2213*45005b27SMauro Carvalho Chehab $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos; 2214*45005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO 2215*45005b27SMauro Carvalho Chehab $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; 2216*45005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO_PTR 2217*45005b27SMauro Carvalho Chehab $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; 2218aeec46b9SMartin Waitz 22191da177e4SLinus Torvalds create_parameterlist($members, ';', $file); 22205cb5c31cSJohannes Berg check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual, $nested); 22211da177e4SLinus Torvalds 22221da177e4SLinus Torvalds output_declaration($declaration_name, 22231da177e4SLinus Torvalds 'struct', 22241da177e4SLinus Torvalds {'struct' => $declaration_name, 22251da177e4SLinus Torvalds 'module' => $modulename, 22261da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 22271da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 22281da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 22291da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 22301da177e4SLinus Torvalds 'sections' => \%sections, 22311da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 22321da177e4SLinus Torvalds 'type' => $decl_type 22331da177e4SLinus Torvalds }); 22341da177e4SLinus Torvalds } 22351da177e4SLinus Torvalds else { 2236d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 22371da177e4SLinus Torvalds ++$errors; 22381da177e4SLinus Torvalds } 22391da177e4SLinus Torvalds} 22401da177e4SLinus Torvalds 22411da177e4SLinus Torvaldssub dump_enum($$) { 22421da177e4SLinus Torvalds my $x = shift; 22431da177e4SLinus Torvalds my $file = shift; 22441da177e4SLinus Torvalds 2245aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 22464468e21eSConchúr Navid # strip #define macros inside enums 22474468e21eSConchúr Navid $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 2248b6d676dbSRandy Dunlap 22491da177e4SLinus Torvalds if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 22501da177e4SLinus Torvalds $declaration_name = $1; 22511da177e4SLinus Torvalds my $members = $2; 22525cb5c31cSJohannes Berg my %_members; 22535cb5c31cSJohannes Berg 2254463a0fdcSMarkus Heiser $members =~ s/\s+$//; 22551da177e4SLinus Torvalds 22561da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 22571da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 22581da177e4SLinus Torvalds push @parameterlist, $arg; 22591da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 22601da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 2261d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Enum value '$arg' ". 22621da177e4SLinus Torvalds "not described in enum '$declaration_name'\n"; 22631da177e4SLinus Torvalds } 22645cb5c31cSJohannes Berg $_members{$arg} = 1; 22655cb5c31cSJohannes Berg } 22661da177e4SLinus Torvalds 22675cb5c31cSJohannes Berg while (my ($k, $v) = each %parameterdescs) { 22685cb5c31cSJohannes Berg if (!exists($_members{$k})) { 22695cb5c31cSJohannes Berg print STDERR "${file}:$.: warning: Excess enum value " . 22705cb5c31cSJohannes Berg "'$k' description in '$declaration_name'\n"; 22715cb5c31cSJohannes Berg } 22721da177e4SLinus Torvalds } 22731da177e4SLinus Torvalds 22741da177e4SLinus Torvalds output_declaration($declaration_name, 22751da177e4SLinus Torvalds 'enum', 22761da177e4SLinus Torvalds {'enum' => $declaration_name, 22771da177e4SLinus Torvalds 'module' => $modulename, 22781da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 22791da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 22801da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 22811da177e4SLinus Torvalds 'sections' => \%sections, 22821da177e4SLinus Torvalds 'purpose' => $declaration_purpose 22831da177e4SLinus Torvalds }); 22841da177e4SLinus Torvalds } 22851da177e4SLinus Torvalds else { 2286d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 22871da177e4SLinus Torvalds ++$errors; 22881da177e4SLinus Torvalds } 22891da177e4SLinus Torvalds} 22901da177e4SLinus Torvalds 22911da177e4SLinus Torvaldssub dump_typedef($$) { 22921da177e4SLinus Torvalds my $x = shift; 22931da177e4SLinus Torvalds my $file = shift; 22941da177e4SLinus Torvalds 2295aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 229683766452SMauro Carvalho Chehab 229783766452SMauro Carvalho Chehab # Parse function prototypes 2298d37c43ceSMauro Carvalho Chehab if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ || 2299d37c43ceSMauro Carvalho Chehab $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) { 2300d37c43ceSMauro Carvalho Chehab 230183766452SMauro Carvalho Chehab # Function typedefs 230283766452SMauro Carvalho Chehab $return_type = $1; 230383766452SMauro Carvalho Chehab $declaration_name = $2; 230483766452SMauro Carvalho Chehab my $args = $3; 230583766452SMauro Carvalho Chehab 230683766452SMauro Carvalho Chehab create_parameterlist($args, ',', $file); 230783766452SMauro Carvalho Chehab 230883766452SMauro Carvalho Chehab output_declaration($declaration_name, 230983766452SMauro Carvalho Chehab 'function', 231083766452SMauro Carvalho Chehab {'function' => $declaration_name, 231182801d06SMauro Carvalho Chehab 'typedef' => 1, 231283766452SMauro Carvalho Chehab 'module' => $modulename, 231383766452SMauro Carvalho Chehab 'functiontype' => $return_type, 231483766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 231583766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 231683766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 231783766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 231883766452SMauro Carvalho Chehab 'sections' => \%sections, 231983766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 232083766452SMauro Carvalho Chehab }); 232183766452SMauro Carvalho Chehab return; 232283766452SMauro Carvalho Chehab } 232383766452SMauro Carvalho Chehab 23241da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 23251da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 23261da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 23271da177e4SLinus Torvalds } 23281da177e4SLinus Torvalds 23291da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 23301da177e4SLinus Torvalds $declaration_name = $1; 23311da177e4SLinus Torvalds 23321da177e4SLinus Torvalds output_declaration($declaration_name, 23331da177e4SLinus Torvalds 'typedef', 23341da177e4SLinus Torvalds {'typedef' => $declaration_name, 23351da177e4SLinus Torvalds 'module' => $modulename, 23361da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 23371da177e4SLinus Torvalds 'sections' => \%sections, 23381da177e4SLinus Torvalds 'purpose' => $declaration_purpose 23391da177e4SLinus Torvalds }); 23401da177e4SLinus Torvalds } 23411da177e4SLinus Torvalds else { 2342d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 23431da177e4SLinus Torvalds ++$errors; 23441da177e4SLinus Torvalds } 23451da177e4SLinus Torvalds} 23461da177e4SLinus Torvalds 2347a1d94aa5SRandy Dunlapsub save_struct_actual($) { 2348a1d94aa5SRandy Dunlap my $actual = shift; 2349a1d94aa5SRandy Dunlap 2350a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 2351a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 2352a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 2353a1d94aa5SRandy Dunlap} 2354a1d94aa5SRandy Dunlap 23551da177e4SLinus Torvaldssub create_parameterlist($$$) { 23561da177e4SLinus Torvalds my $args = shift; 23571da177e4SLinus Torvalds my $splitter = shift; 23581da177e4SLinus Torvalds my $file = shift; 23591da177e4SLinus Torvalds my $type; 23601da177e4SLinus Torvalds my $param; 23611da177e4SLinus Torvalds 2362a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 23631da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 23641da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 23651da177e4SLinus Torvalds } 23661da177e4SLinus Torvalds 23671da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 23681da177e4SLinus Torvalds # strip comments 23691da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 23701da177e4SLinus Torvalds # strip leading/trailing spaces 23711da177e4SLinus Torvalds $arg =~ s/^\s*//; 23721da177e4SLinus Torvalds $arg =~ s/\s*$//; 23731da177e4SLinus Torvalds $arg =~ s/\s+/ /; 23741da177e4SLinus Torvalds 23751da177e4SLinus Torvalds if ($arg =~ /^#/) { 23761da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 23771da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 23781da177e4SLinus Torvalds # output_* subs. 23791da177e4SLinus Torvalds push_parameter($arg, "", $file); 238000d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 23811da177e4SLinus Torvalds # pointer-to-function 23821da177e4SLinus Torvalds $arg =~ tr/#/,/; 238300d62961SRichard Kennedy $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 23841da177e4SLinus Torvalds $param = $1; 23851da177e4SLinus Torvalds $type = $arg; 238600d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 2387a1d94aa5SRandy Dunlap save_struct_actual($param); 23881da177e4SLinus Torvalds push_parameter($param, $type, $file); 2389aeec46b9SMartin Waitz } elsif ($arg) { 23901da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 23911da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 23921da177e4SLinus Torvalds 23931da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 23941da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 23951da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 23961da177e4SLinus Torvalds } 2397884f2810SBorislav Petkov 2398884f2810SBorislav Petkov my @first_arg; 2399884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 2400884f2810SBorislav Petkov shift @args; 2401884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 2402884f2810SBorislav Petkov push(@first_arg, $2); 2403884f2810SBorislav Petkov } else { 2404884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 2405884f2810SBorislav Petkov } 2406884f2810SBorislav Petkov 24071da177e4SLinus Torvalds unshift(@args, pop @first_arg); 24081da177e4SLinus Torvalds $type = join " ", @first_arg; 24091da177e4SLinus Torvalds 24101da177e4SLinus Torvalds foreach $param (@args) { 24111da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 2412a1d94aa5SRandy Dunlap save_struct_actual($2); 24131da177e4SLinus Torvalds push_parameter($2, "$type $1", $file); 24141da177e4SLinus Torvalds } 24151da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 24167b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 2417a1d94aa5SRandy Dunlap save_struct_actual($1); 24181da177e4SLinus Torvalds push_parameter($1, "$type:$2", $file) 24191da177e4SLinus Torvalds } 24207b97887eSRandy Dunlap } 24211da177e4SLinus Torvalds else { 2422a1d94aa5SRandy Dunlap save_struct_actual($param); 24231da177e4SLinus Torvalds push_parameter($param, $type, $file); 24241da177e4SLinus Torvalds } 24251da177e4SLinus Torvalds } 24261da177e4SLinus Torvalds } 24271da177e4SLinus Torvalds } 24281da177e4SLinus Torvalds} 24291da177e4SLinus Torvalds 24301da177e4SLinus Torvaldssub push_parameter($$$) { 24311da177e4SLinus Torvalds my $param = shift; 24321da177e4SLinus Torvalds my $type = shift; 24331da177e4SLinus Torvalds my $file = shift; 24341da177e4SLinus Torvalds 24355f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 24365f8c7c98SRandy Dunlap ($param eq "}")) { 24375f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 24385f8c7c98SRandy Dunlap } 24395f8c7c98SRandy Dunlap 24405f8c7c98SRandy Dunlap $anon_struct_union = 0; 2441f9b5c530SMauro Carvalho Chehab $param =~ s/[\[\)].*//; 24421da177e4SLinus Torvalds 2443a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 24441da177e4SLinus Torvalds { 2445c950a173SSilvio Fricke if (!$param =~ /\w\.\.\.$/) { 2446c950a173SSilvio Fricke # handles unnamed variable parameters 2447ef00028bSJonathan Corbet $param = "..."; 2448c950a173SSilvio Fricke } 2449ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 2450a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 24511da177e4SLinus Torvalds } 2452ced69090SRandy Dunlap } 24531da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 24541da177e4SLinus Torvalds { 24551da177e4SLinus Torvalds $param="void"; 24561da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 24571da177e4SLinus Torvalds } 2458134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 2459134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 2460134fe01bSRandy Dunlap { 2461134fe01bSRandy Dunlap $type = $param; 2462134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 2463134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 24645f8c7c98SRandy Dunlap $anon_struct_union = 1; 2465134fe01bSRandy Dunlap } 2466134fe01bSRandy Dunlap 2467a6d3fe77SMartin Waitz # warn if parameter has no description 2468134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 2469134fe01bSRandy Dunlap # but inline preprocessor statements); 2470134fe01bSRandy Dunlap # also ignore unnamed structs/unions; 24715f8c7c98SRandy Dunlap if (!$anon_struct_union) { 2472f9b5c530SMauro Carvalho Chehab if (!defined $parameterdescs{$param} && $param !~ /^#/) { 2473a6d3fe77SMartin Waitz 2474f9b5c530SMauro Carvalho Chehab $parameterdescs{$param} = $undescribed; 24751da177e4SLinus Torvalds 24761da177e4SLinus Torvalds if (($type eq 'function') || ($type eq 'enum')) { 2477d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Function parameter ". 24781da177e4SLinus Torvalds "or member '$param' not " . 24791da177e4SLinus Torvalds "described in '$declaration_name'\n"; 24801da177e4SLinus Torvalds } 2481d40e1e65SBart Van Assche print STDERR "${file}:$.: warning:" . 24821da177e4SLinus Torvalds " No description found for parameter '$param'\n"; 24831da177e4SLinus Torvalds ++$warnings; 24841da177e4SLinus Torvalds } 2485134fe01bSRandy Dunlap } 24861da177e4SLinus Torvalds 24872b35f4d9SRandy Dunlap $param = xml_escape($param); 24882b35f4d9SRandy Dunlap 248925985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 2490e34e7dbbSRandy Dunlap # on @parameterlist; 2491e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 2492e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 2493e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 2494e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 2495e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 2496e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 2497e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 24981da177e4SLinus Torvalds push @parameterlist, $param; 249902a4f4feSPaolo Bonzini $type =~ s/\s\s+/ /g; 25001da177e4SLinus Torvalds $parametertypes{$param} = $type; 25011da177e4SLinus Torvalds} 25021da177e4SLinus Torvalds 2503a1d94aa5SRandy Dunlapsub check_sections($$$$$$) { 2504a1d94aa5SRandy Dunlap my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; 2505a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 2506a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 2507a1d94aa5SRandy Dunlap my $err; 2508a1d94aa5SRandy Dunlap my ($px, $sx); 2509a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 2510a1d94aa5SRandy Dunlap 2511a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 2512a1d94aa5SRandy Dunlap $err = 1; 2513a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 2514a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 2515a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 25161f3a6688SJohannes Berg $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 2517e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 2518e34e7dbbSRandy Dunlap # however, the original param string may contain 2519e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 2520e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 2521e34e7dbbSRandy Dunlap # parameter list is split at spaces; 2522e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 2523e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 2524e34e7dbbSRandy Dunlap 2525a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 2526a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 2527a1d94aa5SRandy Dunlap $err = 0; 2528a1d94aa5SRandy Dunlap last; 2529a1d94aa5SRandy Dunlap } 2530a1d94aa5SRandy Dunlap } 2531a1d94aa5SRandy Dunlap if ($err) { 2532a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 2533d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2534a1d94aa5SRandy Dunlap "Excess function parameter " . 2535a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2536a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2537a1d94aa5SRandy Dunlap ++$warnings; 2538a1d94aa5SRandy Dunlap } else { 2539a1d94aa5SRandy Dunlap if ($nested !~ m/\Q$sects[$sx]\E/) { 2540d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 25415cb5c31cSJohannes Berg "Excess $decl_type member " . 2542a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2543a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2544a1d94aa5SRandy Dunlap ++$warnings; 2545a1d94aa5SRandy Dunlap } 2546a1d94aa5SRandy Dunlap } 2547a1d94aa5SRandy Dunlap } 2548a1d94aa5SRandy Dunlap } 2549a1d94aa5SRandy Dunlap} 2550a1d94aa5SRandy Dunlap 25511da177e4SLinus Torvalds## 25524092bac7SYacine Belkadi# Checks the section describing the return value of a function. 25534092bac7SYacine Belkadisub check_return_section { 25544092bac7SYacine Belkadi my $file = shift; 25554092bac7SYacine Belkadi my $declaration_name = shift; 25564092bac7SYacine Belkadi my $return_type = shift; 25574092bac7SYacine Belkadi 25584092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 25594092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 25604092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 25614092bac7SYacine Belkadi return; 25624092bac7SYacine Belkadi } 25634092bac7SYacine Belkadi 25644092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 25654092bac7SYacine Belkadi $sections{$section_return} eq "") { 2566d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 25674092bac7SYacine Belkadi "No description found for return value of " . 25684092bac7SYacine Belkadi "'$declaration_name'\n"; 25694092bac7SYacine Belkadi ++$warnings; 25704092bac7SYacine Belkadi } 25714092bac7SYacine Belkadi} 25724092bac7SYacine Belkadi 25734092bac7SYacine Belkadi## 25741da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 25751da177e4SLinus Torvalds# processed and spits out all the details stored in the global 25761da177e4SLinus Torvalds# arrays/hashes. 25771da177e4SLinus Torvaldssub dump_function($$) { 25781da177e4SLinus Torvalds my $prototype = shift; 25791da177e4SLinus Torvalds my $file = shift; 2580cbb4d3e6SHoria Geanta my $noret = 0; 25811da177e4SLinus Torvalds 25821da177e4SLinus Torvalds $prototype =~ s/^static +//; 25831da177e4SLinus Torvalds $prototype =~ s/^extern +//; 25844dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 25851da177e4SLinus Torvalds $prototype =~ s/^inline +//; 25861da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 258732e79401SRandy Dunlap $prototype =~ s/^__inline +//; 258832e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 258932e79401SRandy Dunlap $prototype =~ s/^noinline +//; 259074fc5c65SRandy Dunlap $prototype =~ s/__init +//; 259120072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 2592270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 259370c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 25940df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 2595cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 2596b1aaa546SPaolo Bonzini $prototype =~ s/__attribute__\s*\(\( 2597b1aaa546SPaolo Bonzini (?: 2598b1aaa546SPaolo Bonzini [\w\s]++ # attribute name 2599b1aaa546SPaolo Bonzini (?:\([^)]*+\))? # attribute arguments 2600b1aaa546SPaolo Bonzini \s*+,? # optional comma at the end 2601b1aaa546SPaolo Bonzini )+ 2602b1aaa546SPaolo Bonzini \)\)\s+//x; 26031da177e4SLinus Torvalds 26041da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 26051da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 26061da177e4SLinus Torvalds # 2. Function name 26071da177e4SLinus Torvalds # 3. Function parameters. 26081da177e4SLinus Torvalds # 26091da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 26101da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 26111da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 26121da177e4SLinus Torvalds # so on. 26131da177e4SLinus Torvalds # 26141da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 26151da177e4SLinus Torvalds # the following functions' documentation still comes out right: 26161da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 26171da177e4SLinus Torvalds # - atomic_set (macro) 26189598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 26191da177e4SLinus Torvalds 2620cbb4d3e6SHoria Geanta if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 2621cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 2622cbb4d3e6SHoria Geanta # list. 2623cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 2624cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 2625cbb4d3e6SHoria Geanta $return_type = $1; 2626cbb4d3e6SHoria Geanta $declaration_name = $2; 2627cbb4d3e6SHoria Geanta $noret = 1; 2628cbb4d3e6SHoria Geanta } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 26291da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 26305a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 26311da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 263294b3e03cSRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 26331da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 26345a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 26351da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 26361da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 26375a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 26381da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 26395a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 26401da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 26415a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 26429598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 26435a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 26445a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 26451da177e4SLinus Torvalds $return_type = $1; 26461da177e4SLinus Torvalds $declaration_name = $2; 26471da177e4SLinus Torvalds my $args = $3; 26481da177e4SLinus Torvalds 26491da177e4SLinus Torvalds create_parameterlist($args, ',', $file); 26501da177e4SLinus Torvalds } else { 2651d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 26521da177e4SLinus Torvalds return; 26531da177e4SLinus Torvalds } 26541da177e4SLinus Torvalds 2655a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 2656a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); 2657a1d94aa5SRandy Dunlap 26584092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 26594092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 26604092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 26614092bac7SYacine Belkadi # verbose mode. 26624092bac7SYacine Belkadi # TODO: always perform the check. 2663cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 26644092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 26654092bac7SYacine Belkadi } 26664092bac7SYacine Belkadi 26671da177e4SLinus Torvalds output_declaration($declaration_name, 26681da177e4SLinus Torvalds 'function', 26691da177e4SLinus Torvalds {'function' => $declaration_name, 26701da177e4SLinus Torvalds 'module' => $modulename, 26711da177e4SLinus Torvalds 'functiontype' => $return_type, 26721da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 26731da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 26741da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 26751da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 26761da177e4SLinus Torvalds 'sections' => \%sections, 26771da177e4SLinus Torvalds 'purpose' => $declaration_purpose 26781da177e4SLinus Torvalds }); 26791da177e4SLinus Torvalds} 26801da177e4SLinus Torvalds 26811da177e4SLinus Torvaldssub reset_state { 26821da177e4SLinus Torvalds $function = ""; 26831da177e4SLinus Torvalds %parameterdescs = (); 26841da177e4SLinus Torvalds %parametertypes = (); 26851da177e4SLinus Torvalds @parameterlist = (); 26861da177e4SLinus Torvalds %sections = (); 26871da177e4SLinus Torvalds @sectionlist = (); 2688a1d94aa5SRandy Dunlap $sectcheck = ""; 2689a1d94aa5SRandy Dunlap $struct_actual = ""; 26901da177e4SLinus Torvalds $prototype = ""; 26911da177e4SLinus Torvalds 269248af606aSJani Nikula $state = STATE_NORMAL; 269348af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 26941da177e4SLinus Torvalds} 26951da177e4SLinus Torvalds 269656afb0f8SJason Baronsub tracepoint_munge($) { 269756afb0f8SJason Baron my $file = shift; 269856afb0f8SJason Baron my $tracepointname = 0; 269956afb0f8SJason Baron my $tracepointargs = 0; 270056afb0f8SJason Baron 270156afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 270256afb0f8SJason Baron $tracepointname = $1; 270356afb0f8SJason Baron } 27043a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 27053a9089fdSJason Baron $tracepointname = $1; 27063a9089fdSJason Baron } 27073a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 27083a9089fdSJason Baron $tracepointname = $2; 27093a9089fdSJason Baron } 27103a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 271156afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 271256afb0f8SJason Baron $tracepointargs = $1; 271356afb0f8SJason Baron } 271456afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 2715d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 271656afb0f8SJason Baron "$prototype\n"; 271756afb0f8SJason Baron } else { 271856afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 271956afb0f8SJason Baron } 272056afb0f8SJason Baron} 272156afb0f8SJason Baron 2722b4870bc5SRandy Dunlapsub syscall_munge() { 2723b4870bc5SRandy Dunlap my $void = 0; 2724b4870bc5SRandy Dunlap 2725b4870bc5SRandy Dunlap $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs 2726b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 2727b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 2728b4870bc5SRandy Dunlap $void = 1; 2729b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 2730b4870bc5SRandy Dunlap } 2731b4870bc5SRandy Dunlap 2732b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 2733b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 2734b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 2735b4870bc5SRandy Dunlap } elsif ($void) { 2736b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 2737b4870bc5SRandy Dunlap } 2738b4870bc5SRandy Dunlap 2739b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 2740b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 2741b4870bc5SRandy Dunlap my $count = 0; 2742b4870bc5SRandy Dunlap my $len = length($prototype); 2743b4870bc5SRandy Dunlap if ($void) { 2744b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 2745b4870bc5SRandy Dunlap } 2746b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 2747b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 2748b4870bc5SRandy Dunlap $count++; 2749b4870bc5SRandy Dunlap if ($count % 2 == 1) { 2750b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 2751b4870bc5SRandy Dunlap } 2752b4870bc5SRandy Dunlap } 2753b4870bc5SRandy Dunlap } 2754b4870bc5SRandy Dunlap} 2755b4870bc5SRandy Dunlap 2756b7afa92bSDaniel Vettersub process_proto_function($$) { 27571da177e4SLinus Torvalds my $x = shift; 27581da177e4SLinus Torvalds my $file = shift; 27591da177e4SLinus Torvalds 276051f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 276151f5a0c8SRandy Dunlap 2762890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 27631da177e4SLinus Torvalds # do nothing 27641da177e4SLinus Torvalds } 27651da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 27661da177e4SLinus Torvalds $prototype .= $1; 27671da177e4SLinus Torvalds } 2768b4870bc5SRandy Dunlap 2769890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 27701da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 27711da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 27721da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 2773b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 2774b4870bc5SRandy Dunlap syscall_munge(); 2775b4870bc5SRandy Dunlap } 27763a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 27773a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 27783a9089fdSJason Baron { 277956afb0f8SJason Baron tracepoint_munge($file); 278056afb0f8SJason Baron } 27811da177e4SLinus Torvalds dump_function($prototype, $file); 27821da177e4SLinus Torvalds reset_state(); 27831da177e4SLinus Torvalds } 27841da177e4SLinus Torvalds} 27851da177e4SLinus Torvalds 2786b7afa92bSDaniel Vettersub process_proto_type($$) { 27871da177e4SLinus Torvalds my $x = shift; 27881da177e4SLinus Torvalds my $file = shift; 27891da177e4SLinus Torvalds 27901da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 27911da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 27921da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 279351f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 279451f5a0c8SRandy Dunlap 27951da177e4SLinus Torvalds if ($x =~ /^#/) { 27961da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 27971da177e4SLinus Torvalds $x .= ";"; 27981da177e4SLinus Torvalds } 27991da177e4SLinus Torvalds 28001da177e4SLinus Torvalds while (1) { 28011da177e4SLinus Torvalds if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 2802463a0fdcSMarkus Heiser if( length $prototype ) { 2803463a0fdcSMarkus Heiser $prototype .= " " 2804463a0fdcSMarkus Heiser } 28051da177e4SLinus Torvalds $prototype .= $1 . $2; 28061da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 28071da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 28081da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 28091da177e4SLinus Torvalds dump_declaration($prototype, $file); 28101da177e4SLinus Torvalds reset_state(); 28111da177e4SLinus Torvalds last; 28121da177e4SLinus Torvalds } 28131da177e4SLinus Torvalds $x = $3; 28141da177e4SLinus Torvalds } else { 28151da177e4SLinus Torvalds $prototype .= $x; 28161da177e4SLinus Torvalds last; 28171da177e4SLinus Torvalds } 28181da177e4SLinus Torvalds } 28191da177e4SLinus Torvalds} 28201da177e4SLinus Torvalds 28216b5b55f6SRandy Dunlap# xml_escape: replace <, >, and & in the text stream; 28226b5b55f6SRandy Dunlap# 28236b5b55f6SRandy Dunlap# however, formatting controls that are generated internally/locally in the 28246b5b55f6SRandy Dunlap# kernel-doc script are not escaped here; instead, they begin life like 28256b5b55f6SRandy Dunlap# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings 28266b5b55f6SRandy Dunlap# are converted to their mnemonic-expected output, without the 4 * '\' & ':', 28276b5b55f6SRandy Dunlap# just before actual output; (this is done by local_unescape()) 28281da177e4SLinus Torvaldssub xml_escape($) { 28291da177e4SLinus Torvalds my $text = shift; 2830ecfb251aSRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 2831ecfb251aSRandy Dunlap return $text; 2832ecfb251aSRandy Dunlap } 28331da177e4SLinus Torvalds $text =~ s/\&/\\\\\\amp;/g; 28341da177e4SLinus Torvalds $text =~ s/\</\\\\\\lt;/g; 28351da177e4SLinus Torvalds $text =~ s/\>/\\\\\\gt;/g; 28361da177e4SLinus Torvalds return $text; 28371da177e4SLinus Torvalds} 28381da177e4SLinus Torvalds 2839c0d1b6eeSJonathan Corbet# xml_unescape: reverse the effects of xml_escape 2840c0d1b6eeSJonathan Corbetsub xml_unescape($) { 2841c0d1b6eeSJonathan Corbet my $text = shift; 2842c0d1b6eeSJonathan Corbet if (($output_mode eq "text") || ($output_mode eq "man")) { 2843c0d1b6eeSJonathan Corbet return $text; 2844c0d1b6eeSJonathan Corbet } 2845c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\amp;/\&/g; 2846c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\lt;/</g; 2847c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\gt;/>/g; 2848c0d1b6eeSJonathan Corbet return $text; 2849c0d1b6eeSJonathan Corbet} 2850c0d1b6eeSJonathan Corbet 28516b5b55f6SRandy Dunlap# convert local escape strings to html 28526b5b55f6SRandy Dunlap# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) 28536b5b55f6SRandy Dunlapsub local_unescape($) { 28546b5b55f6SRandy Dunlap my $text = shift; 28556b5b55f6SRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 28566b5b55f6SRandy Dunlap return $text; 28576b5b55f6SRandy Dunlap } 28586b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\lt:/</g; 28596b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\gt:/>/g; 28606b5b55f6SRandy Dunlap return $text; 28616b5b55f6SRandy Dunlap} 28626b5b55f6SRandy Dunlap 28631ad560e4SJani Nikulasub map_filename($) { 28641ad560e4SJani Nikula my $file; 28651ad560e4SJani Nikula my ($orig_file) = @_; 28661ad560e4SJani Nikula 28671ad560e4SJani Nikula if (defined($ENV{'SRCTREE'})) { 28681ad560e4SJani Nikula $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 28691ad560e4SJani Nikula } else { 28701ad560e4SJani Nikula $file = $orig_file; 28711ad560e4SJani Nikula } 28721ad560e4SJani Nikula 28731ad560e4SJani Nikula if (defined($source_map{$file})) { 28741ad560e4SJani Nikula $file = $source_map{$file}; 28751ad560e4SJani Nikula } 28761ad560e4SJani Nikula 28771ad560e4SJani Nikula return $file; 28781ad560e4SJani Nikula} 28791ad560e4SJani Nikula 288088c2b57dSJani Nikulasub process_export_file($) { 288188c2b57dSJani Nikula my ($orig_file) = @_; 288288c2b57dSJani Nikula my $file = map_filename($orig_file); 288388c2b57dSJani Nikula 288488c2b57dSJani Nikula if (!open(IN,"<$file")) { 288588c2b57dSJani Nikula print STDERR "Error: Cannot open file $file\n"; 288688c2b57dSJani Nikula ++$errors; 288788c2b57dSJani Nikula return; 288888c2b57dSJani Nikula } 288988c2b57dSJani Nikula 289088c2b57dSJani Nikula while (<IN>) { 289188c2b57dSJani Nikula if (/$export_symbol/) { 289288c2b57dSJani Nikula $function_table{$2} = 1; 289388c2b57dSJani Nikula } 289488c2b57dSJani Nikula } 289588c2b57dSJani Nikula 289688c2b57dSJani Nikula close(IN); 289788c2b57dSJani Nikula} 289888c2b57dSJani Nikula 28991da177e4SLinus Torvaldssub process_file($) { 29002283a117SRandy Dunlap my $file; 29011da177e4SLinus Torvalds my $identifier; 29021da177e4SLinus Torvalds my $func; 2903a21217daSRandy Dunlap my $descr; 29046423133bSJohannes Weiner my $in_purpose = 0; 29051da177e4SLinus Torvalds my $initial_section_counter = $section_counter; 290668f86662SBen Hutchings my ($orig_file) = @_; 2907b7886de4SJani Nikula my $leading_space; 29081da177e4SLinus Torvalds 29091ad560e4SJani Nikula $file = map_filename($orig_file); 29101da177e4SLinus Torvalds 29111da177e4SLinus Torvalds if (!open(IN,"<$file")) { 29121da177e4SLinus Torvalds print STDERR "Error: Cannot open file $file\n"; 29131da177e4SLinus Torvalds ++$errors; 29141da177e4SLinus Torvalds return; 29151da177e4SLinus Torvalds } 29161da177e4SLinus Torvalds 2917a9e7314bSIlya Dryomov $. = 1; 2918a9e7314bSIlya Dryomov 29191da177e4SLinus Torvalds $section_counter = 0; 29201da177e4SLinus Torvalds while (<IN>) { 292165478428SDaniel Santos while (s/\\\s*$//) { 292265478428SDaniel Santos $_ .= <IN>; 292365478428SDaniel Santos } 292448af606aSJani Nikula if ($state == STATE_NORMAL) { 29251da177e4SLinus Torvalds if (/$doc_start/o) { 292648af606aSJani Nikula $state = STATE_NAME; # next line is always the function name 2927850622dfSRandy Dunlap $in_doc_sect = 0; 29280b0f5f29SDaniel Vetter $declaration_start_line = $. + 1; 29291da177e4SLinus Torvalds } 293048af606aSJani Nikula } elsif ($state == STATE_NAME) {# this line is the function name (always) 29311da177e4SLinus Torvalds if (/$doc_block/o) { 293248af606aSJani Nikula $state = STATE_DOCBLOCK; 29331da177e4SLinus Torvalds $contents = ""; 29340b0f5f29SDaniel Vetter $new_start_line = $. + 1; 29350b0f5f29SDaniel Vetter 29361da177e4SLinus Torvalds if ( $1 eq "" ) { 29371da177e4SLinus Torvalds $section = $section_intro; 29381da177e4SLinus Torvalds } else { 29391da177e4SLinus Torvalds $section = $1; 29401da177e4SLinus Torvalds } 29411da177e4SLinus Torvalds } 29421da177e4SLinus Torvalds elsif (/$doc_decl/o) { 29431da177e4SLinus Torvalds $identifier = $1; 29441da177e4SLinus Torvalds if (/\s*([\w\s]+?)\s*-/) { 29451da177e4SLinus Torvalds $identifier = $1; 29461da177e4SLinus Torvalds } 29471da177e4SLinus Torvalds 294848af606aSJani Nikula $state = STATE_FIELD; 29490b0f5f29SDaniel Vetter # if there's no @param blocks need to set up default section 29500b0f5f29SDaniel Vetter # here 29512f4ad40aSJani Nikula $contents = ""; 29522f4ad40aSJani Nikula $section = $section_default; 29530b0f5f29SDaniel Vetter $new_start_line = $. + 1; 29541da177e4SLinus Torvalds if (/-(.*)/) { 295551f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2956a21217daSRandy Dunlap $descr= $1; 2957a21217daSRandy Dunlap $descr =~ s/^\s*//; 2958a21217daSRandy Dunlap $descr =~ s/\s*$//; 295912ae6779SDaniel Santos $descr =~ s/\s+/ /g; 2960a21217daSRandy Dunlap $declaration_purpose = xml_escape($descr); 29616423133bSJohannes Weiner $in_purpose = 1; 29621da177e4SLinus Torvalds } else { 29631da177e4SLinus Torvalds $declaration_purpose = ""; 29641da177e4SLinus Torvalds } 296577cc23b8SRandy Dunlap 296677cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 2967d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 296877cc23b8SRandy Dunlap print STDERR $_; 296977cc23b8SRandy Dunlap ++$warnings; 297077cc23b8SRandy Dunlap } 297177cc23b8SRandy Dunlap 29721da177e4SLinus Torvalds if ($identifier =~ m/^struct/) { 29731da177e4SLinus Torvalds $decl_type = 'struct'; 29741da177e4SLinus Torvalds } elsif ($identifier =~ m/^union/) { 29751da177e4SLinus Torvalds $decl_type = 'union'; 29761da177e4SLinus Torvalds } elsif ($identifier =~ m/^enum/) { 29771da177e4SLinus Torvalds $decl_type = 'enum'; 29781da177e4SLinus Torvalds } elsif ($identifier =~ m/^typedef/) { 29791da177e4SLinus Torvalds $decl_type = 'typedef'; 29801da177e4SLinus Torvalds } else { 29811da177e4SLinus Torvalds $decl_type = 'function'; 29821da177e4SLinus Torvalds } 29831da177e4SLinus Torvalds 29841da177e4SLinus Torvalds if ($verbose) { 2985d40e1e65SBart Van Assche print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; 29861da177e4SLinus Torvalds } 29871da177e4SLinus Torvalds } else { 2988d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 29891da177e4SLinus Torvalds " - I thought it was a doc line\n"; 29901da177e4SLinus Torvalds ++$warnings; 299148af606aSJani Nikula $state = STATE_NORMAL; 29921da177e4SLinus Torvalds } 299348af606aSJani Nikula } elsif ($state == STATE_FIELD) { # look for head: lines, and include content 2994f624adefSJani Nikula if (/$doc_sect/i) { # case insensitive for supported section names 29951da177e4SLinus Torvalds $newsection = $1; 29961da177e4SLinus Torvalds $newcontents = $2; 29971da177e4SLinus Torvalds 2998f624adefSJani Nikula # map the supported section names to the canonical names 2999f624adefSJani Nikula if ($newsection =~ m/^description$/i) { 3000f624adefSJani Nikula $newsection = $section_default; 3001f624adefSJani Nikula } elsif ($newsection =~ m/^context$/i) { 3002f624adefSJani Nikula $newsection = $section_context; 3003f624adefSJani Nikula } elsif ($newsection =~ m/^returns?$/i) { 3004f624adefSJani Nikula $newsection = $section_return; 3005f624adefSJani Nikula } elsif ($newsection =~ m/^\@return$/) { 3006f624adefSJani Nikula # special: @return is a section, not a param description 3007f624adefSJani Nikula $newsection = $section_return; 3008f624adefSJani Nikula } 3009f624adefSJani Nikula 3010792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 3011850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 3012d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: contents before sections\n"; 3013850622dfSRandy Dunlap ++$warnings; 3014850622dfSRandy Dunlap } 301594dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 30161da177e4SLinus Torvalds $section = $section_default; 30171da177e4SLinus Torvalds } 30181da177e4SLinus Torvalds 3019850622dfSRandy Dunlap $in_doc_sect = 1; 30206423133bSJohannes Weiner $in_purpose = 0; 30211da177e4SLinus Torvalds $contents = $newcontents; 30220b0f5f29SDaniel Vetter $new_start_line = $.; 302327205744SRandy Dunlap while ((substr($contents, 0, 1) eq " ") || 302427205744SRandy Dunlap substr($contents, 0, 1) eq "\t") { 302505189497SRandy Dunlap $contents = substr($contents, 1); 302605189497SRandy Dunlap } 30270a726301SJani Nikula if ($contents ne "") { 30281da177e4SLinus Torvalds $contents .= "\n"; 30291da177e4SLinus Torvalds } 30301da177e4SLinus Torvalds $section = $newsection; 3031b7886de4SJani Nikula $leading_space = undef; 30321da177e4SLinus Torvalds } elsif (/$doc_end/) { 30334c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 303494dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 30351da177e4SLinus Torvalds $section = $section_default; 30361da177e4SLinus Torvalds $contents = ""; 30371da177e4SLinus Torvalds } 303846b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 303946b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 3040d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: suspicious ending line: $_"; 304146b958ebSRandy Dunlap ++$warnings; 304246b958ebSRandy Dunlap } 30431da177e4SLinus Torvalds 30441da177e4SLinus Torvalds $prototype = ""; 304548af606aSJani Nikula $state = STATE_PROTO; 30461da177e4SLinus Torvalds $brcount = 0; 30471da177e4SLinus Torvalds# print STDERR "end of doc comment, looking for prototype\n"; 30481da177e4SLinus Torvalds } elsif (/$doc_content/) { 30491da177e4SLinus Torvalds # miguel-style comment kludge, look for blank lines after 30501da177e4SLinus Torvalds # @parameter line to signify start of description 30516423133bSJohannes Weiner if ($1 eq "") { 30526423133bSJohannes Weiner if ($section =~ m/^@/ || $section eq $section_context) { 305394dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 30541da177e4SLinus Torvalds $section = $section_default; 30551da177e4SLinus Torvalds $contents = ""; 30560b0f5f29SDaniel Vetter $new_start_line = $.; 30571da177e4SLinus Torvalds } else { 30586423133bSJohannes Weiner $contents .= "\n"; 30596423133bSJohannes Weiner } 30606423133bSJohannes Weiner $in_purpose = 0; 30616423133bSJohannes Weiner } elsif ($in_purpose == 1) { 30626423133bSJohannes Weiner # Continued declaration purpose 30636423133bSJohannes Weiner chomp($declaration_purpose); 30646423133bSJohannes Weiner $declaration_purpose .= " " . xml_escape($1); 306512ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 30666423133bSJohannes Weiner } else { 3067b7886de4SJani Nikula my $cont = $1; 3068b7886de4SJani Nikula if ($section =~ m/^@/ || $section eq $section_context) { 3069b7886de4SJani Nikula if (!defined $leading_space) { 3070b7886de4SJani Nikula if ($cont =~ m/^(\s+)/) { 3071b7886de4SJani Nikula $leading_space = $1; 3072b7886de4SJani Nikula } else { 3073b7886de4SJani Nikula $leading_space = ""; 3074b7886de4SJani Nikula } 3075b7886de4SJani Nikula } 3076b7886de4SJani Nikula 3077b7886de4SJani Nikula $cont =~ s/^$leading_space//; 3078b7886de4SJani Nikula } 3079b7886de4SJani Nikula $contents .= $cont . "\n"; 30801da177e4SLinus Torvalds } 30811da177e4SLinus Torvalds } else { 30821da177e4SLinus Torvalds # i dont know - bad line? ignore. 3083d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: bad line: $_"; 30841da177e4SLinus Torvalds ++$warnings; 30851da177e4SLinus Torvalds } 308648af606aSJani Nikula } elsif ($state == STATE_INLINE) { # scanning for inline parameters 3087a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 308848af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 3089a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 3090a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 30910b0f5f29SDaniel Vetter $new_start_line = $.; 3092a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 3093a4c6ebedSDanilo Cesar Lemes de Paula while ((substr($contents, 0, 1) eq " ") || 3094a4c6ebedSDanilo Cesar Lemes de Paula substr($contents, 0, 1) eq "\t") { 3095a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 3096a4c6ebedSDanilo Cesar Lemes de Paula } 3097a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 3098a4c6ebedSDanilo Cesar Lemes de Paula } 309948af606aSJani Nikula $inline_doc_state = STATE_INLINE_TEXT; 3100a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 310148af606aSJani Nikula } elsif (/$doc_inline_end/) { 3102a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 3103a4c6ebedSDanilo Cesar Lemes de Paula dump_section($file, $section, xml_escape($contents)); 3104a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 3105a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 3106a4c6ebedSDanilo Cesar Lemes de Paula } 310748af606aSJani Nikula $state = STATE_PROTO; 310848af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 3109a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 3110a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 311148af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_TEXT) { 3112a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 31136450c895SJani Nikula # nuke leading blank lines 31146450c895SJani Nikula if ($contents =~ /^\s*$/) { 31156450c895SJani Nikula $contents = ""; 31166450c895SJani Nikula } 311748af606aSJani Nikula } elsif ($inline_doc_state == STATE_INLINE_NAME) { 311848af606aSJani Nikula $inline_doc_state = STATE_INLINE_ERROR; 3119e7ca311eSDaniel Vetter print STDERR "${file}:$.: warning: "; 3120a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Incorrect use of kernel-doc format: $_"; 3121a4c6ebedSDanilo Cesar Lemes de Paula ++$warnings; 3122a4c6ebedSDanilo Cesar Lemes de Paula } 3123a4c6ebedSDanilo Cesar Lemes de Paula } 312448af606aSJani Nikula } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype) 31250c9aa209SJani Nikula if (/$doc_inline_oneline/) { 31260c9aa209SJani Nikula $section = $1; 31270c9aa209SJani Nikula $contents = $2; 31280c9aa209SJani Nikula if ($contents ne "") { 31290c9aa209SJani Nikula $contents .= "\n"; 31300c9aa209SJani Nikula dump_section($file, $section, xml_escape($contents)); 31310c9aa209SJani Nikula $section = $section_default; 31320c9aa209SJani Nikula $contents = ""; 31330c9aa209SJani Nikula } 31340c9aa209SJani Nikula } elsif (/$doc_inline_start/) { 313548af606aSJani Nikula $state = STATE_INLINE; 313648af606aSJani Nikula $inline_doc_state = STATE_INLINE_NAME; 3137a4c6ebedSDanilo Cesar Lemes de Paula } elsif ($decl_type eq 'function') { 3138b7afa92bSDaniel Vetter process_proto_function($_, $file); 31391da177e4SLinus Torvalds } else { 3140b7afa92bSDaniel Vetter process_proto_type($_, $file); 31411da177e4SLinus Torvalds } 314248af606aSJani Nikula } elsif ($state == STATE_DOCBLOCK) { 3143ebff7f92SDaniel Vetter if (/$doc_end/) 31441da177e4SLinus Torvalds { 314594dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 31462f4ad40aSJani Nikula $section = $section_default; 31471da177e4SLinus Torvalds $contents = ""; 31481da177e4SLinus Torvalds $function = ""; 31491da177e4SLinus Torvalds %parameterdescs = (); 31501da177e4SLinus Torvalds %parametertypes = (); 31511da177e4SLinus Torvalds @parameterlist = (); 31521da177e4SLinus Torvalds %sections = (); 31531da177e4SLinus Torvalds @sectionlist = (); 31541da177e4SLinus Torvalds $prototype = ""; 315548af606aSJani Nikula $state = STATE_NORMAL; 31561da177e4SLinus Torvalds } 31571da177e4SLinus Torvalds elsif (/$doc_content/) 31581da177e4SLinus Torvalds { 31591da177e4SLinus Torvalds if ( $1 eq "" ) 31601da177e4SLinus Torvalds { 31611da177e4SLinus Torvalds $contents .= $blankline; 31621da177e4SLinus Torvalds } 31631da177e4SLinus Torvalds else 31641da177e4SLinus Torvalds { 31651da177e4SLinus Torvalds $contents .= $1 . "\n"; 31661da177e4SLinus Torvalds } 31671da177e4SLinus Torvalds } 31681da177e4SLinus Torvalds } 31691da177e4SLinus Torvalds } 31701da177e4SLinus Torvalds if ($initial_section_counter == $section_counter) { 31713a025e1dSMatthew Wilcox if ($output_mode ne "none") { 3172d40e1e65SBart Van Assche print STDERR "${file}:1: warning: no structured comments found\n"; 31733a025e1dSMatthew Wilcox } 3174b6c3f456SJani Nikula if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) { 3175e946c43aSJohannes Berg print STDERR " Was looking for '$_'.\n" for keys %function_table; 3176e946c43aSJohannes Berg } 31771da177e4SLinus Torvalds if ($output_mode eq "xml") { 31781da177e4SLinus Torvalds # The template wants at least one RefEntry here; make one. 31791da177e4SLinus Torvalds print "<refentry>\n"; 31801da177e4SLinus Torvalds print " <refnamediv>\n"; 31811da177e4SLinus Torvalds print " <refname>\n"; 318268f86662SBen Hutchings print " ${orig_file}\n"; 31831da177e4SLinus Torvalds print " </refname>\n"; 31841da177e4SLinus Torvalds print " <refpurpose>\n"; 31851da177e4SLinus Torvalds print " Document generation inconsistency\n"; 31861da177e4SLinus Torvalds print " </refpurpose>\n"; 31871da177e4SLinus Torvalds print " </refnamediv>\n"; 31881da177e4SLinus Torvalds print " <refsect1>\n"; 31891da177e4SLinus Torvalds print " <title>\n"; 31901da177e4SLinus Torvalds print " Oops\n"; 31911da177e4SLinus Torvalds print " </title>\n"; 31921da177e4SLinus Torvalds print " <warning>\n"; 31931da177e4SLinus Torvalds print " <para>\n"; 31941da177e4SLinus Torvalds print " The template for this document tried to insert\n"; 31951da177e4SLinus Torvalds print " the structured comment from the file\n"; 319668f86662SBen Hutchings print " <filename>${orig_file}</filename> at this point,\n"; 31971da177e4SLinus Torvalds print " but none was found.\n"; 31981da177e4SLinus Torvalds print " This dummy section is inserted to allow\n"; 31991da177e4SLinus Torvalds print " generation to continue.\n"; 32001da177e4SLinus Torvalds print " </para>\n"; 32011da177e4SLinus Torvalds print " </warning>\n"; 32021da177e4SLinus Torvalds print " </refsect1>\n"; 32031da177e4SLinus Torvalds print "</refentry>\n"; 32041da177e4SLinus Torvalds } 32051da177e4SLinus Torvalds } 32061da177e4SLinus Torvalds} 32078484baaaSRandy Dunlap 32088484baaaSRandy Dunlap 32098484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 32108484baaaSRandy Dunlap 32118484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 32128484baaaSRandy Dunlap# using the s// operator. 32131ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 32144d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 32154d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 32164d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 32174d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 32188484baaaSRandy Dunlap} 32198484baaaSRandy Dunlap 32208484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 32218484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 32228484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 32238484baaaSRandy Dunlap my ($relname, $absname); 32248484baaaSRandy Dunlap while(<SOURCE_MAP>) { 32258484baaaSRandy Dunlap chop(); 32268484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 32278484baaaSRandy Dunlap $relname =~ s:^/+::; 32288484baaaSRandy Dunlap $source_map{$relname} = $absname; 32298484baaaSRandy Dunlap } 32308484baaaSRandy Dunlap close(SOURCE_MAP); 32318484baaaSRandy Dunlap} 32328484baaaSRandy Dunlap 323388c2b57dSJani Nikulaif ($output_selection == OUTPUT_EXPORTED || 323488c2b57dSJani Nikula $output_selection == OUTPUT_INTERNAL) { 3235c9b2cfb3SJani Nikula 3236c9b2cfb3SJani Nikula push(@export_file_list, @ARGV); 3237c9b2cfb3SJani Nikula 323888c2b57dSJani Nikula foreach (@export_file_list) { 323988c2b57dSJani Nikula chomp; 324088c2b57dSJani Nikula process_export_file($_); 324188c2b57dSJani Nikula } 324288c2b57dSJani Nikula} 324388c2b57dSJani Nikula 32448484baaaSRandy Dunlapforeach (@ARGV) { 32458484baaaSRandy Dunlap chomp; 32468484baaaSRandy Dunlap process_file($_); 32478484baaaSRandy Dunlap} 32488484baaaSRandy Dunlapif ($verbose && $errors) { 32498484baaaSRandy Dunlap print STDERR "$errors errors\n"; 32508484baaaSRandy Dunlap} 32518484baaaSRandy Dunlapif ($verbose && $warnings) { 32528484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 32538484baaaSRandy Dunlap} 32548484baaaSRandy Dunlap 3255e814bccbSWill Deaconexit($output_mode eq "none" ? 0 : $errors); 3256