11da177e4SLinus Torvalds#!/usr/bin/perl -w 21da177e4SLinus Torvalds 31da177e4SLinus Torvaldsuse strict; 41da177e4SLinus Torvalds 51da177e4SLinus Torvalds## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## 61da177e4SLinus Torvalds## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## 71da177e4SLinus Torvalds## Copyright (C) 2001 Simon Huggins ## 870c95b00SRandy Dunlap## Copyright (C) 2005-2012 Randy Dunlap ## 91b40c194SDan Luedtke## Copyright (C) 2012 Dan Luedtke ## 101da177e4SLinus Torvalds## ## 111da177e4SLinus Torvalds## #define enhancements by Armin Kuster <akuster@mvista.com> ## 121da177e4SLinus Torvalds## Copyright (c) 2000 MontaVista Software, Inc. ## 131da177e4SLinus Torvalds## ## 141da177e4SLinus Torvalds## This software falls under the GNU General Public License. ## 151da177e4SLinus Torvalds## Please read the COPYING file for more information ## 161da177e4SLinus Torvalds 171da177e4SLinus Torvalds# 18/01/2001 - Cleanups 181da177e4SLinus Torvalds# Functions prototyped as foo(void) same as foo() 191da177e4SLinus Torvalds# Stop eval'ing where we don't need to. 201da177e4SLinus Torvalds# -- huggie@earth.li 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds# 27/06/2001 - Allowed whitespace after initial "/**" and 231da177e4SLinus Torvalds# allowed comments before function declarations. 241da177e4SLinus Torvalds# -- Christian Kreibich <ck@whoop.org> 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds# Still to do: 271da177e4SLinus Torvalds# - add perldoc documentation 281da177e4SLinus Torvalds# - Look more closely at some of the scarier bits :) 291da177e4SLinus Torvalds 301da177e4SLinus Torvalds# 26/05/2001 - Support for separate source and object trees. 311da177e4SLinus Torvalds# Return error code. 321da177e4SLinus Torvalds# Keith Owens <kaos@ocs.com.au> 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds# 23/09/2001 - Added support for typedefs, structs, enums and unions 351da177e4SLinus Torvalds# Support for Context section; can be terminated using empty line 361da177e4SLinus Torvalds# Small fixes (like spaces vs. \s in regex) 371da177e4SLinus Torvalds# -- Tim Jansen <tim@tjansen.de> 381da177e4SLinus Torvalds 391b40c194SDan Luedtke# 25/07/2012 - Added support for HTML5 401b40c194SDan Luedtke# -- Dan Luedtke <mail@danrl.de> 411da177e4SLinus Torvalds 42fadc0b31SJani Nikulasub usage { 43fadc0b31SJani Nikula my $message = <<"EOF"; 44fadc0b31SJani NikulaUsage: $0 [OPTION ...] FILE ... 451da177e4SLinus Torvalds 46fadc0b31SJani NikulaRead C language source or header FILEs, extract embedded documentation comments, 47fadc0b31SJani Nikulaand print formatted documentation to standard output. 481da177e4SLinus Torvalds 49fadc0b31SJani NikulaThe documentation comments are identified by "/**" opening comment mark. See 50fadc0b31SJani NikulaDocumentation/kernel-doc-nano-HOWTO.txt for the documentation comment syntax. 51fadc0b31SJani Nikula 52fadc0b31SJani NikulaOutput format selection (mutually exclusive): 53fadc0b31SJani Nikula -docbook Output DocBook format. 54fadc0b31SJani Nikula -html Output HTML format. 55fadc0b31SJani Nikula -html5 Output HTML5 format. 56fadc0b31SJani Nikula -list Output symbol list format. This is for use by docproc. 57fadc0b31SJani Nikula -man Output troff manual page format. This is the default. 58c0d1b6eeSJonathan Corbet -rst Output reStructuredText format. 59fadc0b31SJani Nikula -text Output plain text format. 60fadc0b31SJani Nikula 61fadc0b31SJani NikulaOutput selection (mutually exclusive): 6286ae2e38SJani Nikula -export Only output documentation for symbols that have been 6386ae2e38SJani Nikula exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 6486ae2e38SJani Nikula in the same FILE. 6586ae2e38SJani Nikula -internal Only output documentation for symbols that have NOT been 6686ae2e38SJani Nikula exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 6786ae2e38SJani Nikula in the same FILE. 68fadc0b31SJani Nikula -function NAME Only output documentation for the given function(s) 69fadc0b31SJani Nikula or DOC: section title(s). All other functions and DOC: 70fadc0b31SJani Nikula sections are ignored. May be specified multiple times. 71fadc0b31SJani Nikula -nofunction NAME Do NOT output documentation for the given function(s); 72fadc0b31SJani Nikula only output documentation for the other functions and 73fadc0b31SJani Nikula DOC: sections. May be specified multiple times. 74fadc0b31SJani Nikula 75fadc0b31SJani NikulaOutput selection modifiers: 76fadc0b31SJani Nikula -no-doc-sections Do not output DOC: sections. 77fadc0b31SJani Nikula 78fadc0b31SJani NikulaOther parameters: 79fadc0b31SJani Nikula -v Verbose output, more warnings and other information. 80fadc0b31SJani Nikula -h Print this help. 81fadc0b31SJani Nikula 82fadc0b31SJani NikulaEOF 83fadc0b31SJani Nikula print $message; 84fadc0b31SJani Nikula exit 1; 85fadc0b31SJani Nikula} 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds# 881da177e4SLinus Torvalds# format of comments. 891da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure. 901da177e4SLinus Torvalds# (...)* signifies 0 or more structure elements 911da177e4SLinus Torvalds# /** 921da177e4SLinus Torvalds# * function_name(:)? (- short description)? 931da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)* 941da177e4SLinus Torvalds# (* a blank line)? 951da177e4SLinus Torvalds# * (Description:)? (Description of function)? 961da177e4SLinus Torvalds# * (section header: (section description)? )* 971da177e4SLinus Torvalds# (*)?*/ 981da177e4SLinus Torvalds# 991da177e4SLinus Torvalds# So .. the trivial example would be: 1001da177e4SLinus Torvalds# 1011da177e4SLinus Torvalds# /** 1021da177e4SLinus Torvalds# * my_function 103b9d97328SRandy Dunlap# */ 1041da177e4SLinus Torvalds# 105891dcd2fSRandy Dunlap# If the Description: header tag is omitted, then there must be a blank line 1061da177e4SLinus Torvalds# after the last parameter specification. 1071da177e4SLinus Torvalds# e.g. 1081da177e4SLinus Torvalds# /** 1091da177e4SLinus Torvalds# * my_function - does my stuff 1101da177e4SLinus Torvalds# * @my_arg: its mine damnit 1111da177e4SLinus Torvalds# * 1121da177e4SLinus Torvalds# * Does my stuff explained. 1131da177e4SLinus Torvalds# */ 1141da177e4SLinus Torvalds# 1151da177e4SLinus Torvalds# or, could also use: 1161da177e4SLinus Torvalds# /** 1171da177e4SLinus Torvalds# * my_function - does my stuff 1181da177e4SLinus Torvalds# * @my_arg: its mine damnit 1191da177e4SLinus Torvalds# * Description: Does my stuff explained. 1201da177e4SLinus Torvalds# */ 1211da177e4SLinus Torvalds# etc. 1221da177e4SLinus Torvalds# 123b9d97328SRandy Dunlap# Besides functions you can also write documentation for structs, unions, 1241da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name 1251da177e4SLinus Torvalds# of the declaration; the struct/union/enum/typedef must always precede 1261da177e4SLinus Torvalds# the name. Nesting of declarations is not supported. 1271da177e4SLinus Torvalds# Use the argument mechanism to document members or constants. 1281da177e4SLinus Torvalds# e.g. 1291da177e4SLinus Torvalds# /** 1301da177e4SLinus Torvalds# * struct my_struct - short description 1311da177e4SLinus Torvalds# * @a: first member 1321da177e4SLinus Torvalds# * @b: second member 1331da177e4SLinus Torvalds# * 1341da177e4SLinus Torvalds# * Longer description 1351da177e4SLinus Torvalds# */ 1361da177e4SLinus Torvalds# struct my_struct { 1371da177e4SLinus Torvalds# int a; 1381da177e4SLinus Torvalds# int b; 139aeec46b9SMartin Waitz# /* private: */ 140aeec46b9SMartin Waitz# int c; 1411da177e4SLinus Torvalds# }; 1421da177e4SLinus Torvalds# 1431da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description. 1441da177e4SLinus Torvalds# 145a4c6ebedSDanilo Cesar Lemes de Paula# For really longs structs, you can also describe arguments inside the 146a4c6ebedSDanilo Cesar Lemes de Paula# body of the struct. 147a4c6ebedSDanilo Cesar Lemes de Paula# eg. 148a4c6ebedSDanilo Cesar Lemes de Paula# /** 149a4c6ebedSDanilo Cesar Lemes de Paula# * struct my_struct - short description 150a4c6ebedSDanilo Cesar Lemes de Paula# * @a: first member 151a4c6ebedSDanilo Cesar Lemes de Paula# * @b: second member 152a4c6ebedSDanilo Cesar Lemes de Paula# * 153a4c6ebedSDanilo Cesar Lemes de Paula# * Longer description 154a4c6ebedSDanilo Cesar Lemes de Paula# */ 155a4c6ebedSDanilo Cesar Lemes de Paula# struct my_struct { 156a4c6ebedSDanilo Cesar Lemes de Paula# int a; 157a4c6ebedSDanilo Cesar Lemes de Paula# int b; 158a4c6ebedSDanilo Cesar Lemes de Paula# /** 159a4c6ebedSDanilo Cesar Lemes de Paula# * @c: This is longer description of C 160a4c6ebedSDanilo Cesar Lemes de Paula# * 161a4c6ebedSDanilo Cesar Lemes de Paula# * You can use paragraphs to describe arguments 162a4c6ebedSDanilo Cesar Lemes de Paula# * using this method. 163a4c6ebedSDanilo Cesar Lemes de Paula# */ 164a4c6ebedSDanilo Cesar Lemes de Paula# int c; 165a4c6ebedSDanilo Cesar Lemes de Paula# }; 166a4c6ebedSDanilo Cesar Lemes de Paula# 167a4c6ebedSDanilo Cesar Lemes de Paula# This should be use only for struct/enum members. 168a4c6ebedSDanilo Cesar Lemes de Paula# 1691da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you 1701da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions 1711da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an 1721da177e4SLinus Torvalds# empty line. 1734092bac7SYacine Belkadi# A non-void function should have a "Return:" section describing the return 1744092bac7SYacine Belkadi# value(s). 1751da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked 1761da177e4SLinus Torvalds# appropriately in DocBook. 1771da177e4SLinus Torvalds# 1781da177e4SLinus Torvalds# Example: 1791da177e4SLinus Torvalds# /** 1801da177e4SLinus Torvalds# * user_function - function that can only be called in user context 1811da177e4SLinus Torvalds# * @a: some argument 1821da177e4SLinus Torvalds# * Context: !in_interrupt() 1831da177e4SLinus Torvalds# * 1841da177e4SLinus Torvalds# * Some description 1851da177e4SLinus Torvalds# * Example: 1861da177e4SLinus Torvalds# * user_function(22); 1871da177e4SLinus Torvalds# */ 1881da177e4SLinus Torvalds# ... 1891da177e4SLinus Torvalds# 1901da177e4SLinus Torvalds# 1911da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special 1921da177e4SLinus Torvalds# patterns, which are highlighted appropriately. 1931da177e4SLinus Torvalds# 1941da177e4SLinus Torvalds# 'funcname()' - function 1951da177e4SLinus Torvalds# '$ENVVAR' - environmental variable 1961da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct') 1971da177e4SLinus Torvalds# '@parameter' - name of a parameter 1981da177e4SLinus Torvalds# '%CONST' - name of a constant. 1991da177e4SLinus Torvalds 2008484baaaSRandy Dunlap## init lots of data 2018484baaaSRandy Dunlap 2021da177e4SLinus Torvaldsmy $errors = 0; 2031da177e4SLinus Torvaldsmy $warnings = 0; 2045f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 2051da177e4SLinus Torvalds 2061da177e4SLinus Torvalds# match expressions used to find embedded type information 2071da177e4SLinus Torvaldsmy $type_constant = '\%([-_\w]+)'; 2081da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 2091da177e4SLinus Torvaldsmy $type_param = '\@(\w+)'; 2103eb014a1SRandy Dunlapmy $type_struct = '\&((struct\s*)*[_\w]+)'; 2116b5b55f6SRandy Dunlapmy $type_struct_xml = '\\&((struct\s*)*[_\w]+)'; 2121da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 213c0d1b6eeSJonathan Corbetmy $type_enum_full = '\&(enum)\s*([_\w]+)'; 214c0d1b6eeSJonathan Corbetmy $type_struct_full = '\&(struct)\s*([_\w]+)'; 21547ae7aedSJani Nikulamy $type_typedef_full = '\&(typedef)\s*([_\w]+)'; 21647ae7aedSJani Nikulamy $type_union_full = '\&(union)\s*([_\w]+)'; 217f3341dcfSJani Nikulamy $type_member = '\&([_\w]+)((\.|->)[_\w]+)'; 218f3341dcfSJani Nikulamy $type_member_func = $type_member . '\(\)'; 2191da177e4SLinus Torvalds 2201da177e4SLinus Torvalds# Output conversion substitutions. 2211da177e4SLinus Torvalds# One for each output format 2221da177e4SLinus Torvalds 2231da177e4SLinus Torvalds# these work fairly well 2244d732701SDanilo Cesar Lemes de Paulamy @highlights_html = ( 2254d732701SDanilo Cesar Lemes de Paula [$type_constant, "<i>\$1</i>"], 2264d732701SDanilo Cesar Lemes de Paula [$type_func, "<b>\$1</b>"], 2274d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<i>\$1</i>"], 2284d732701SDanilo Cesar Lemes de Paula [$type_env, "<b><i>\$1</i></b>"], 2294d732701SDanilo Cesar Lemes de Paula [$type_param, "<tt><b>\$1</b></tt>"] 2304d732701SDanilo Cesar Lemes de Paula ); 2316b5b55f6SRandy Dunlapmy $local_lt = "\\\\\\\\lt:"; 2326b5b55f6SRandy Dunlapmy $local_gt = "\\\\\\\\gt:"; 2336b5b55f6SRandy Dunlapmy $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" 2341da177e4SLinus Torvalds 2351b40c194SDan Luedtke# html version 5 2364d732701SDanilo Cesar Lemes de Paulamy @highlights_html5 = ( 2374d732701SDanilo Cesar Lemes de Paula [$type_constant, "<span class=\"const\">\$1</span>"], 2384d732701SDanilo Cesar Lemes de Paula [$type_func, "<span class=\"func\">\$1</span>"], 2394d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<span class=\"struct\">\$1</span>"], 2404d732701SDanilo Cesar Lemes de Paula [$type_env, "<span class=\"env\">\$1</span>"], 2414d732701SDanilo Cesar Lemes de Paula [$type_param, "<span class=\"param\">\$1</span>]"] 2424d732701SDanilo Cesar Lemes de Paula ); 2431b40c194SDan Luedtkemy $blankline_html5 = $local_lt . "br /" . $local_gt; 2441b40c194SDan Luedtke 2451da177e4SLinus Torvalds# XML, docbook format 2464d732701SDanilo Cesar Lemes de Paulamy @highlights_xml = ( 2474d732701SDanilo Cesar Lemes de Paula ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"], 2484d732701SDanilo Cesar Lemes de Paula [$type_constant, "<constant>\$1</constant>"], 2494d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<structname>\$1</structname>"], 2504d732701SDanilo Cesar Lemes de Paula [$type_param, "<parameter>\$1</parameter>"], 2514d732701SDanilo Cesar Lemes de Paula [$type_func, "<function>\$1</function>"], 2524d732701SDanilo Cesar Lemes de Paula [$type_env, "<envar>\$1</envar>"] 2534d732701SDanilo Cesar Lemes de Paula ); 2545c98fc03SJohannes Bergmy $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; 2551da177e4SLinus Torvalds 2561da177e4SLinus Torvalds# gnome, docbook format 2574d732701SDanilo Cesar Lemes de Paulamy @highlights_gnome = ( 2584d732701SDanilo Cesar Lemes de Paula [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"], 2594d732701SDanilo Cesar Lemes de Paula [$type_func, "<function>\$1</function>"], 2604d732701SDanilo Cesar Lemes de Paula [$type_struct, "<structname>\$1</structname>"], 2614d732701SDanilo Cesar Lemes de Paula [$type_env, "<envar>\$1</envar>"], 2624d732701SDanilo Cesar Lemes de Paula [$type_param, "<parameter>\$1</parameter>" ] 2634d732701SDanilo Cesar Lemes de Paula ); 2641da177e4SLinus Torvaldsmy $blankline_gnome = "</para><para>\n"; 2651da177e4SLinus Torvalds 2661da177e4SLinus Torvalds# these are pretty rough 2674d732701SDanilo Cesar Lemes de Paulamy @highlights_man = ( 2684d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 2694d732701SDanilo Cesar Lemes de Paula [$type_func, "\\\\fB\$1\\\\fP"], 2704d732701SDanilo Cesar Lemes de Paula [$type_struct, "\\\\fI\$1\\\\fP"], 2714d732701SDanilo Cesar Lemes de Paula [$type_param, "\\\\fI\$1\\\\fP"] 2724d732701SDanilo Cesar Lemes de Paula ); 2731da177e4SLinus Torvaldsmy $blankline_man = ""; 2741da177e4SLinus Torvalds 2751da177e4SLinus Torvalds# text-mode 2764d732701SDanilo Cesar Lemes de Paulamy @highlights_text = ( 2774d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 2784d732701SDanilo Cesar Lemes de Paula [$type_func, "\$1"], 2794d732701SDanilo Cesar Lemes de Paula [$type_struct, "\$1"], 2804d732701SDanilo Cesar Lemes de Paula [$type_param, "\$1"] 2814d732701SDanilo Cesar Lemes de Paula ); 2821da177e4SLinus Torvaldsmy $blankline_text = ""; 2831da177e4SLinus Torvalds 284c0d1b6eeSJonathan Corbet# rst-mode 285c0d1b6eeSJonathan Corbetmy @highlights_rst = ( 286c0d1b6eeSJonathan Corbet [$type_constant, "``\$1``"], 287f3341dcfSJani Nikula # Note: need to escape () to avoid func matching later 288f3341dcfSJani Nikula [$type_member_func, "\\:c\\:type\\:`\$1\$2\\\\(\\\\) <\$1>`"], 289f3341dcfSJani Nikula [$type_member, "\\:c\\:type\\:`\$1\$2 <\$1>`"], 290a19bce64SJani Nikula [$type_func, "\\:c\\:func\\:`\$1()`"], 29162850976SJani Nikula [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 29262850976SJani Nikula [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 29347ae7aedSJani Nikula [$type_typedef_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 29447ae7aedSJani Nikula [$type_union_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 295a7291e7eSJani Nikula # in rst this can refer to any type 296a7291e7eSJani Nikula [$type_struct, "\\:c\\:type\\:`\$1`"], 297c0d1b6eeSJonathan Corbet [$type_param, "**\$1**"] 298c0d1b6eeSJonathan Corbet ); 299c0d1b6eeSJonathan Corbetmy $blankline_rst = "\n"; 300c0d1b6eeSJonathan Corbet 301eda603f6SJohannes Berg# list mode 3024d732701SDanilo Cesar Lemes de Paulamy @highlights_list = ( 3034d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 3044d732701SDanilo Cesar Lemes de Paula [$type_func, "\$1"], 3054d732701SDanilo Cesar Lemes de Paula [$type_struct, "\$1"], 3064d732701SDanilo Cesar Lemes de Paula [$type_param, "\$1"] 3074d732701SDanilo Cesar Lemes de Paula ); 308eda603f6SJohannes Bergmy $blankline_list = ""; 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds# read arguments 3111da177e4SLinus Torvaldsif ($#ARGV == -1) { 3121da177e4SLinus Torvalds usage(); 3131da177e4SLinus Torvalds} 3141da177e4SLinus Torvalds 3158484baaaSRandy Dunlapmy $kernelversion; 3168484baaaSRandy Dunlapmy $dohighlight = ""; 3178484baaaSRandy Dunlap 3181da177e4SLinus Torvaldsmy $verbose = 0; 3191da177e4SLinus Torvaldsmy $output_mode = "man"; 320e314ba31SDaniel Santosmy $output_preformatted = 0; 3214b44595aSJohannes Bergmy $no_doc_sections = 0; 3224d732701SDanilo Cesar Lemes de Paulamy @highlights = @highlights_man; 3231da177e4SLinus Torvaldsmy $blankline = $blankline_man; 3241da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 325b6c3f456SJani Nikula 326b6c3f456SJani Nikulause constant { 327b6c3f456SJani Nikula OUTPUT_ALL => 0, # output all symbols and doc sections 328b6c3f456SJani Nikula OUTPUT_INCLUDE => 1, # output only specified symbols 329b6c3f456SJani Nikula OUTPUT_EXCLUDE => 2, # output everything except specified symbols 330b6c3f456SJani Nikula OUTPUT_EXPORTED => 3, # output exported symbols 331b6c3f456SJani Nikula OUTPUT_INTERNAL => 4, # output non-exported symbols 332b6c3f456SJani Nikula}; 333b6c3f456SJani Nikulamy $output_selection = OUTPUT_ALL; 334b2c4105bSBen Hutchingsmy $show_not_found = 0; 335b2c4105bSBen Hutchings 336b2c4105bSBen Hutchingsmy @build_time; 337b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 338b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 339b2c4105bSBen Hutchings @build_time = gmtime($seconds); 340b2c4105bSBen Hutchings} else { 341b2c4105bSBen Hutchings @build_time = localtime; 342b2c4105bSBen Hutchings} 343b2c4105bSBen Hutchings 3441da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 3451da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 346b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 347b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 3481da177e4SLinus Torvalds 3498484baaaSRandy Dunlap# Essentially these are globals. 350b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 351b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 3521da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 3531da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 3541da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 3551c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 3561da177e4SLinus Torvalds 357bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 358bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 359bd0e88e5SRandy Dunlap} 360bd0e88e5SRandy Dunlap 3611da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 3621da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 3631da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 3641da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 3651da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 3661da177e4SLinus Torvalds# into html. 3671da177e4SLinus Torvaldsmy $section_counter = 0; 3681da177e4SLinus Torvalds 3691da177e4SLinus Torvaldsmy $lineprefix=""; 3701da177e4SLinus Torvalds 37148af606aSJani Nikula# Parser states 37248af606aSJani Nikulause constant { 37348af606aSJani Nikula STATE_NORMAL => 0, # normal code 37448af606aSJani Nikula STATE_NAME => 1, # looking for function name 37548af606aSJani Nikula STATE_FIELD => 2, # scanning field start 37648af606aSJani Nikula STATE_PROTO => 3, # scanning prototype 37748af606aSJani Nikula STATE_DOCBLOCK => 4, # documentation block 37848af606aSJani Nikula STATE_INLINE => 5, # gathering documentation outside main block 37948af606aSJani Nikula}; 3801da177e4SLinus Torvaldsmy $state; 381850622dfSRandy Dunlapmy $in_doc_sect; 3821da177e4SLinus Torvalds 38348af606aSJani Nikula# Inline documentation state 38448af606aSJani Nikulause constant { 38548af606aSJani Nikula STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 38648af606aSJani Nikula STATE_INLINE_NAME => 1, # looking for member name (@foo:) 38748af606aSJani Nikula STATE_INLINE_TEXT => 2, # looking for member documentation 38848af606aSJani Nikula STATE_INLINE_END => 3, # done 38948af606aSJani Nikula STATE_INLINE_ERROR => 4, # error - Comment without header was found. 39048af606aSJani Nikula # Spit a warning as it's not 391a4c6ebedSDanilo Cesar Lemes de Paula # proper kernel-doc and ignore the rest. 39248af606aSJani Nikula}; 39348af606aSJani Nikulamy $inline_doc_state; 394a4c6ebedSDanilo Cesar Lemes de Paula 3951da177e4SLinus Torvalds#declaration types: can be 3961da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 3971da177e4SLinus Torvaldsmy $decl_type; 3981da177e4SLinus Torvalds 3991da177e4SLinus Torvaldsmy $doc_special = "\@\%\$\&"; 4001da177e4SLinus Torvalds 4011da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 4021da177e4SLinus Torvaldsmy $doc_end = '\*/'; 4031da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 40412ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 4051da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 406891dcd2fSRandy Dunlapmy $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)'; 40712ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 4081da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 40948af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$'; 41048af606aSJani Nikulamy $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)'; 41148af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$'; 41286ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 4131da177e4SLinus Torvalds 4141da177e4SLinus Torvaldsmy %constants; 4151da177e4SLinus Torvaldsmy %parameterdescs; 4161da177e4SLinus Torvaldsmy @parameterlist; 4171da177e4SLinus Torvaldsmy %sections; 4181da177e4SLinus Torvaldsmy @sectionlist; 419a1d94aa5SRandy Dunlapmy $sectcheck; 420a1d94aa5SRandy Dunlapmy $struct_actual; 4211da177e4SLinus Torvalds 4221da177e4SLinus Torvaldsmy $contents = ""; 4231da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 4241da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 4251da177e4SLinus Torvaldsmy $section = $section_default; 4261da177e4SLinus Torvaldsmy $section_context = "Context"; 4274092bac7SYacine Belkadimy $section_return = "Return"; 4281da177e4SLinus Torvalds 4291da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 4301da177e4SLinus Torvalds 4311da177e4SLinus Torvaldsreset_state(); 4321da177e4SLinus Torvalds 4331da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) { 4341da177e4SLinus Torvalds my $cmd = shift @ARGV; 4351da177e4SLinus Torvalds if ($cmd eq "-html") { 4361da177e4SLinus Torvalds $output_mode = "html"; 4374d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_html; 4381da177e4SLinus Torvalds $blankline = $blankline_html; 4391b40c194SDan Luedtke } elsif ($cmd eq "-html5") { 4401b40c194SDan Luedtke $output_mode = "html5"; 4414d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_html5; 4421b40c194SDan Luedtke $blankline = $blankline_html5; 4431da177e4SLinus Torvalds } elsif ($cmd eq "-man") { 4441da177e4SLinus Torvalds $output_mode = "man"; 4454d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 4461da177e4SLinus Torvalds $blankline = $blankline_man; 4471da177e4SLinus Torvalds } elsif ($cmd eq "-text") { 4481da177e4SLinus Torvalds $output_mode = "text"; 4494d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_text; 4501da177e4SLinus Torvalds $blankline = $blankline_text; 451c0d1b6eeSJonathan Corbet } elsif ($cmd eq "-rst") { 452c0d1b6eeSJonathan Corbet $output_mode = "rst"; 453c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 454c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 4551da177e4SLinus Torvalds } elsif ($cmd eq "-docbook") { 4561da177e4SLinus Torvalds $output_mode = "xml"; 4574d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_xml; 4581da177e4SLinus Torvalds $blankline = $blankline_xml; 459eda603f6SJohannes Berg } elsif ($cmd eq "-list") { 460eda603f6SJohannes Berg $output_mode = "list"; 4614d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_list; 462eda603f6SJohannes Berg $blankline = $blankline_list; 4631da177e4SLinus Torvalds } elsif ($cmd eq "-gnome") { 4641da177e4SLinus Torvalds $output_mode = "gnome"; 4654d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_gnome; 4661da177e4SLinus Torvalds $blankline = $blankline_gnome; 4671da177e4SLinus Torvalds } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document 4681da177e4SLinus Torvalds $modulename = shift @ARGV; 4691da177e4SLinus Torvalds } elsif ($cmd eq "-function") { # to only output specific functions 470b6c3f456SJani Nikula $output_selection = OUTPUT_INCLUDE; 4711da177e4SLinus Torvalds $function = shift @ARGV; 4721da177e4SLinus Torvalds $function_table{$function} = 1; 473b6c3f456SJani Nikula } elsif ($cmd eq "-nofunction") { # output all except specific functions 474b6c3f456SJani Nikula $output_selection = OUTPUT_EXCLUDE; 4751da177e4SLinus Torvalds $function = shift @ARGV; 4761da177e4SLinus Torvalds $function_table{$function} = 1; 47786ae2e38SJani Nikula } elsif ($cmd eq "-export") { # only exported symbols 478b6c3f456SJani Nikula $output_selection = OUTPUT_EXPORTED; 47986ae2e38SJani Nikula %function_table = () 48086ae2e38SJani Nikula } elsif ($cmd eq "-internal") { # only non-exported symbols 481b6c3f456SJani Nikula $output_selection = OUTPUT_INTERNAL; 48286ae2e38SJani Nikula %function_table = () 4831da177e4SLinus Torvalds } elsif ($cmd eq "-v") { 4841da177e4SLinus Torvalds $verbose = 1; 4851da177e4SLinus Torvalds } elsif (($cmd eq "-h") || ($cmd eq "--help")) { 4861da177e4SLinus Torvalds usage(); 4874b44595aSJohannes Berg } elsif ($cmd eq '-no-doc-sections') { 4884b44595aSJohannes Berg $no_doc_sections = 1; 489e946c43aSJohannes Berg } elsif ($cmd eq '-show-not-found') { 490e946c43aSJohannes Berg $show_not_found = 1; 4911da177e4SLinus Torvalds } 4921da177e4SLinus Torvalds} 4931da177e4SLinus Torvalds 4948484baaaSRandy Dunlap# continue execution near EOF; 4958484baaaSRandy Dunlap 49653f049faSBorislav Petkov# get kernel version from env 49753f049faSBorislav Petkovsub get_kernel_version() { 4981b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 49953f049faSBorislav Petkov 50053f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 50153f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 50253f049faSBorislav Petkov } 50353f049faSBorislav Petkov return $version; 50453f049faSBorislav Petkov} 5051da177e4SLinus Torvalds 5061da177e4SLinus Torvalds## 5071da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 5081da177e4SLinus Torvalds# 5091da177e4SLinus Torvaldssub dump_section { 51094dc7ad5SRandy Dunlap my $file = shift; 5111da177e4SLinus Torvalds my $name = shift; 5121da177e4SLinus Torvalds my $contents = join "\n", @_; 5131da177e4SLinus Torvalds 5141da177e4SLinus Torvalds if ($name =~ m/$type_constant/) { 5151da177e4SLinus Torvalds $name = $1; 5161da177e4SLinus Torvalds# print STDERR "constant section '$1' = '$contents'\n"; 5171da177e4SLinus Torvalds $constants{$name} = $contents; 5181da177e4SLinus Torvalds } elsif ($name =~ m/$type_param/) { 5191da177e4SLinus Torvalds# print STDERR "parameter def '$1' = '$contents'\n"; 5201da177e4SLinus Torvalds $name = $1; 5211da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 522a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 523ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 524ced69090SRandy Dunlap# print STDERR "parameter def '...' = '$contents'\n"; 525ced69090SRandy Dunlap $name = "..."; 526ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 527a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 5281da177e4SLinus Torvalds } else { 5291da177e4SLinus Torvalds# print STDERR "other section '$name' = '$contents'\n"; 53094dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 531d40e1e65SBart Van Assche print STDERR "${file}:$.: error: duplicate section name '$name'\n"; 53294dc7ad5SRandy Dunlap ++$errors; 53394dc7ad5SRandy Dunlap } 5341da177e4SLinus Torvalds $sections{$name} = $contents; 5351da177e4SLinus Torvalds push @sectionlist, $name; 5361da177e4SLinus Torvalds } 5371da177e4SLinus Torvalds} 5381da177e4SLinus Torvalds 5391da177e4SLinus Torvalds## 540b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 541b112e0f7SJohannes Berg# 542b112e0f7SJohannes Bergsub dump_doc_section { 54394dc7ad5SRandy Dunlap my $file = shift; 544b112e0f7SJohannes Berg my $name = shift; 545b112e0f7SJohannes Berg my $contents = join "\n", @_; 546b112e0f7SJohannes Berg 5474b44595aSJohannes Berg if ($no_doc_sections) { 5484b44595aSJohannes Berg return; 5494b44595aSJohannes Berg } 5504b44595aSJohannes Berg 551b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 552b6c3f456SJani Nikula ($output_selection == OUTPUT_INCLUDE && 553b6c3f456SJani Nikula defined($function_table{$name})) || 554b6c3f456SJani Nikula ($output_selection == OUTPUT_EXCLUDE && 555b6c3f456SJani Nikula !defined($function_table{$name}))) 556b112e0f7SJohannes Berg { 55794dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 558b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 559b112e0f7SJohannes Berg 'sections' => \%sections, 560b112e0f7SJohannes Berg 'module' => $modulename, 561b6c3f456SJani Nikula 'content-only' => ($output_selection != OUTPUT_ALL), }); 562b112e0f7SJohannes Berg } 563b112e0f7SJohannes Berg} 564b112e0f7SJohannes Berg 565b112e0f7SJohannes Berg## 5661da177e4SLinus Torvalds# output function 5671da177e4SLinus Torvalds# 5681da177e4SLinus Torvalds# parameterdescs, a hash. 5691da177e4SLinus Torvalds# function => "function name" 5701da177e4SLinus Torvalds# parameterlist => @list of parameters 5711da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 5721da177e4SLinus Torvalds# sectionlist => @list of sections 573a21217daSRandy Dunlap# sections => %section descriptions 5741da177e4SLinus Torvalds# 5751da177e4SLinus Torvalds 5761da177e4SLinus Torvaldssub output_highlight { 5771da177e4SLinus Torvalds my $contents = join "\n",@_; 5781da177e4SLinus Torvalds my $line; 5791da177e4SLinus Torvalds 5801da177e4SLinus Torvalds# DEBUG 5811da177e4SLinus Torvalds# if (!defined $contents) { 5821da177e4SLinus Torvalds# use Carp; 5831da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 5841da177e4SLinus Torvalds# } 5851da177e4SLinus Torvalds 5861b40c194SDan Luedtke if ($output_mode eq "html" || $output_mode eq "html5" || 5871b40c194SDan Luedtke $output_mode eq "xml") { 5886b5b55f6SRandy Dunlap $contents = local_unescape($contents); 5896b5b55f6SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 5902b35f4d9SRandy Dunlap $contents =~ s/\\\\\\/\&/g; 5916b5b55f6SRandy Dunlap } 5923eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 5931da177e4SLinus Torvalds eval $dohighlight; 5941da177e4SLinus Torvalds die $@ if $@; 5953eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 5963eb014a1SRandy Dunlap 5971b40c194SDan Luedtke# strip whitespaces when generating html5 5981b40c194SDan Luedtke if ($output_mode eq "html5") { 5991b40c194SDan Luedtke $contents =~ s/^\s+//; 6001b40c194SDan Luedtke $contents =~ s/\s+$//; 6011b40c194SDan Luedtke } 6021da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 60312ae6779SDaniel Santos if (! $output_preformatted) { 60412ae6779SDaniel Santos $line =~ s/^\s*//; 60512ae6779SDaniel Santos } 6061da177e4SLinus Torvalds if ($line eq ""){ 607e314ba31SDaniel Santos if (! $output_preformatted) { 6086b5b55f6SRandy Dunlap print $lineprefix, local_unescape($blankline); 609e314ba31SDaniel Santos } 6101da177e4SLinus Torvalds } else { 6111da177e4SLinus Torvalds $line =~ s/\\\\\\/\&/g; 612cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 613cdccb316SRandy Dunlap print "\\&$line"; 614cdccb316SRandy Dunlap } else { 6151da177e4SLinus Torvalds print $lineprefix, $line; 6161da177e4SLinus Torvalds } 617cdccb316SRandy Dunlap } 6181da177e4SLinus Torvalds print "\n"; 6191da177e4SLinus Torvalds } 6201da177e4SLinus Torvalds} 6211da177e4SLinus Torvalds 6221da177e4SLinus Torvalds# output sections in html 6231da177e4SLinus Torvaldssub output_section_html(%) { 6241da177e4SLinus Torvalds my %args = %{$_[0]}; 6251da177e4SLinus Torvalds my $section; 6261da177e4SLinus Torvalds 6271da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6281da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 6291da177e4SLinus Torvalds print "<blockquote>\n"; 6301da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6311da177e4SLinus Torvalds print "</blockquote>\n"; 6321da177e4SLinus Torvalds } 6331da177e4SLinus Torvalds} 6341da177e4SLinus Torvalds 6351da177e4SLinus Torvalds# output enum in html 6361da177e4SLinus Torvaldssub output_enum_html(%) { 6371da177e4SLinus Torvalds my %args = %{$_[0]}; 6381da177e4SLinus Torvalds my ($parameter); 6391da177e4SLinus Torvalds my $count; 6401da177e4SLinus Torvalds print "<h2>enum " . $args{'enum'} . "</h2>\n"; 6411da177e4SLinus Torvalds 6421da177e4SLinus Torvalds print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; 6431da177e4SLinus Torvalds $count = 0; 6441da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6451da177e4SLinus Torvalds print " <b>" . $parameter . "</b>"; 6461da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 6471da177e4SLinus Torvalds $count++; 6481da177e4SLinus Torvalds print ",\n"; 6491da177e4SLinus Torvalds } 6501da177e4SLinus Torvalds print "<br>"; 6511da177e4SLinus Torvalds } 6521da177e4SLinus Torvalds print "};<br>\n"; 6531da177e4SLinus Torvalds 6541da177e4SLinus Torvalds print "<h3>Constants</h3>\n"; 6551da177e4SLinus Torvalds print "<dl>\n"; 6561da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6571da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 6581da177e4SLinus Torvalds print "<dd>"; 6591da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter}); 6601da177e4SLinus Torvalds } 6611da177e4SLinus Torvalds print "</dl>\n"; 6621da177e4SLinus Torvalds output_section_html(@_); 6631da177e4SLinus Torvalds print "<hr>\n"; 6641da177e4SLinus Torvalds} 6651da177e4SLinus Torvalds 666d28bee0cSRandy Dunlap# output typedef in html 6671da177e4SLinus Torvaldssub output_typedef_html(%) { 6681da177e4SLinus Torvalds my %args = %{$_[0]}; 6691da177e4SLinus Torvalds my ($parameter); 6701da177e4SLinus Torvalds my $count; 6711da177e4SLinus Torvalds print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; 6721da177e4SLinus Torvalds 6731da177e4SLinus Torvalds print "<b>typedef " . $args{'typedef'} . "</b>\n"; 6741da177e4SLinus Torvalds output_section_html(@_); 6751da177e4SLinus Torvalds print "<hr>\n"; 6761da177e4SLinus Torvalds} 6771da177e4SLinus Torvalds 6781da177e4SLinus Torvalds# output struct in html 6791da177e4SLinus Torvaldssub output_struct_html(%) { 6801da177e4SLinus Torvalds my %args = %{$_[0]}; 6811da177e4SLinus Torvalds my ($parameter); 6821da177e4SLinus Torvalds 683262d9b01SRandy Dunlap print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; 6841da177e4SLinus Torvalds print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; 6851da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6861da177e4SLinus Torvalds if ($parameter =~ /^#/) { 6871da177e4SLinus Torvalds print "$parameter<br>\n"; 6881da177e4SLinus Torvalds next; 6891da177e4SLinus Torvalds } 6901da177e4SLinus Torvalds my $parameter_name = $parameter; 6911da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6921da177e4SLinus Torvalds 6931da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6941da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 6951da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 6961da177e4SLinus Torvalds # pointer-to-function 6973eb014a1SRandy Dunlap print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; 6981da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 6993eb014a1SRandy Dunlap # bitfield 7003eb014a1SRandy Dunlap print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; 7011da177e4SLinus Torvalds } else { 7023eb014a1SRandy Dunlap print " <i>$type</i> <b>$parameter</b>;<br>\n"; 7031da177e4SLinus Torvalds } 7041da177e4SLinus Torvalds } 7051da177e4SLinus Torvalds print "};<br>\n"; 7061da177e4SLinus Torvalds 7071da177e4SLinus Torvalds print "<h3>Members</h3>\n"; 7081da177e4SLinus Torvalds print "<dl>\n"; 7091da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7101da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 7111da177e4SLinus Torvalds 7121da177e4SLinus Torvalds my $parameter_name = $parameter; 7131da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7141da177e4SLinus Torvalds 7151da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7161da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 7171da177e4SLinus Torvalds print "<dd>"; 7181da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7191da177e4SLinus Torvalds } 7201da177e4SLinus Torvalds print "</dl>\n"; 7211da177e4SLinus Torvalds output_section_html(@_); 7221da177e4SLinus Torvalds print "<hr>\n"; 7231da177e4SLinus Torvalds} 7241da177e4SLinus Torvalds 7251da177e4SLinus Torvalds# output function in html 7261da177e4SLinus Torvaldssub output_function_html(%) { 7271da177e4SLinus Torvalds my %args = %{$_[0]}; 7281da177e4SLinus Torvalds my ($parameter, $section); 7291da177e4SLinus Torvalds my $count; 7301da177e4SLinus Torvalds 731262d9b01SRandy Dunlap print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; 7321da177e4SLinus Torvalds print "<i>" . $args{'functiontype'} . "</i>\n"; 7331da177e4SLinus Torvalds print "<b>" . $args{'function'} . "</b>\n"; 7341da177e4SLinus Torvalds print "("; 7351da177e4SLinus Torvalds $count = 0; 7361da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7371da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 7381da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 7391da177e4SLinus Torvalds # pointer-to-function 7401da177e4SLinus Torvalds print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; 7411da177e4SLinus Torvalds } else { 7421da177e4SLinus Torvalds print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; 7431da177e4SLinus Torvalds } 7441da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 7451da177e4SLinus Torvalds $count++; 7461da177e4SLinus Torvalds print ",\n"; 7471da177e4SLinus Torvalds } 7481da177e4SLinus Torvalds } 7491da177e4SLinus Torvalds print ")\n"; 7501da177e4SLinus Torvalds 7511da177e4SLinus Torvalds print "<h3>Arguments</h3>\n"; 7521da177e4SLinus Torvalds print "<dl>\n"; 7531da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7541da177e4SLinus Torvalds my $parameter_name = $parameter; 7551da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7561da177e4SLinus Torvalds 7571da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7581da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 7591da177e4SLinus Torvalds print "<dd>"; 7601da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7611da177e4SLinus Torvalds } 7621da177e4SLinus Torvalds print "</dl>\n"; 7631da177e4SLinus Torvalds output_section_html(@_); 7641da177e4SLinus Torvalds print "<hr>\n"; 7651da177e4SLinus Torvalds} 7661da177e4SLinus Torvalds 767b112e0f7SJohannes Berg# output DOC: block header in html 768b112e0f7SJohannes Bergsub output_blockhead_html(%) { 7691da177e4SLinus Torvalds my %args = %{$_[0]}; 7701da177e4SLinus Torvalds my ($parameter, $section); 7711da177e4SLinus Torvalds my $count; 7721da177e4SLinus Torvalds 7731da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7741da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 7751da177e4SLinus Torvalds print "<ul>\n"; 7761da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7771da177e4SLinus Torvalds print "</ul>\n"; 7781da177e4SLinus Torvalds } 7791da177e4SLinus Torvalds print "<hr>\n"; 7801da177e4SLinus Torvalds} 7811da177e4SLinus Torvalds 7821b40c194SDan Luedtke# output sections in html5 7831b40c194SDan Luedtkesub output_section_html5(%) { 7841b40c194SDan Luedtke my %args = %{$_[0]}; 7851b40c194SDan Luedtke my $section; 7861b40c194SDan Luedtke 7871b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 7881b40c194SDan Luedtke print "<section>\n"; 7891b40c194SDan Luedtke print "<h1>$section</h1>\n"; 7901b40c194SDan Luedtke print "<p>\n"; 7911b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 7921b40c194SDan Luedtke print "</p>\n"; 7931b40c194SDan Luedtke print "</section>\n"; 7941b40c194SDan Luedtke } 7951b40c194SDan Luedtke} 7961b40c194SDan Luedtke 7971b40c194SDan Luedtke# output enum in html5 7981b40c194SDan Luedtkesub output_enum_html5(%) { 7991b40c194SDan Luedtke my %args = %{$_[0]}; 8001b40c194SDan Luedtke my ($parameter); 8011b40c194SDan Luedtke my $count; 8021b40c194SDan Luedtke my $html5id; 8031b40c194SDan Luedtke 8041b40c194SDan Luedtke $html5id = $args{'enum'}; 8051b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8061b40c194SDan Luedtke print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; 8071b40c194SDan Luedtke print "<h1>enum " . $args{'enum'} . "</h1>\n"; 8081b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8091b40c194SDan Luedtke print "<li>"; 8101b40c194SDan Luedtke print "<span class=\"keyword\">enum</span> "; 8111b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; 8121b40c194SDan Luedtke print "</li>\n"; 8131b40c194SDan Luedtke $count = 0; 8141b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8151b40c194SDan Luedtke print "<li class=\"indent\">"; 8161b40c194SDan Luedtke print "<span class=\"param\">" . $parameter . "</span>"; 8171b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 8181b40c194SDan Luedtke $count++; 8191b40c194SDan Luedtke print ","; 8201b40c194SDan Luedtke } 8211b40c194SDan Luedtke print "</li>\n"; 8221b40c194SDan Luedtke } 8231b40c194SDan Luedtke print "<li>};</li>\n"; 8241b40c194SDan Luedtke print "</ol>\n"; 8251b40c194SDan Luedtke 8261b40c194SDan Luedtke print "<section>\n"; 8271b40c194SDan Luedtke print "<h1>Constants</h1>\n"; 8281b40c194SDan Luedtke print "<dl>\n"; 8291b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8301b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 8311b40c194SDan Luedtke print "<dd>"; 8321b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter}); 8331b40c194SDan Luedtke print "</dd>\n"; 8341b40c194SDan Luedtke } 8351b40c194SDan Luedtke print "</dl>\n"; 8361b40c194SDan Luedtke print "</section>\n"; 8371b40c194SDan Luedtke output_section_html5(@_); 8381b40c194SDan Luedtke print "</article>\n"; 8391b40c194SDan Luedtke} 8401b40c194SDan Luedtke 8411b40c194SDan Luedtke# output typedef in html5 8421b40c194SDan Luedtkesub output_typedef_html5(%) { 8431b40c194SDan Luedtke my %args = %{$_[0]}; 8441b40c194SDan Luedtke my ($parameter); 8451b40c194SDan Luedtke my $count; 8461b40c194SDan Luedtke my $html5id; 8471b40c194SDan Luedtke 8481b40c194SDan Luedtke $html5id = $args{'typedef'}; 8491b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8501b40c194SDan Luedtke print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; 8511b40c194SDan Luedtke print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; 8521b40c194SDan Luedtke 8531b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8541b40c194SDan Luedtke print "<li>"; 8551b40c194SDan Luedtke print "<span class=\"keyword\">typedef</span> "; 8561b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; 8571b40c194SDan Luedtke print "</li>\n"; 8581b40c194SDan Luedtke print "</ol>\n"; 8591b40c194SDan Luedtke output_section_html5(@_); 8601b40c194SDan Luedtke print "</article>\n"; 8611b40c194SDan Luedtke} 8621b40c194SDan Luedtke 8631b40c194SDan Luedtke# output struct in html5 8641b40c194SDan Luedtkesub output_struct_html5(%) { 8651b40c194SDan Luedtke my %args = %{$_[0]}; 8661b40c194SDan Luedtke my ($parameter); 8671b40c194SDan Luedtke my $html5id; 8681b40c194SDan Luedtke 8691b40c194SDan Luedtke $html5id = $args{'struct'}; 8701b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8711b40c194SDan Luedtke print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n"; 8721b40c194SDan Luedtke print "<hgroup>\n"; 8731b40c194SDan Luedtke print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>"; 8741b40c194SDan Luedtke print "<h2>". $args{'purpose'} . "</h2>\n"; 8751b40c194SDan Luedtke print "</hgroup>\n"; 8761b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8771b40c194SDan Luedtke print "<li>"; 8781b40c194SDan Luedtke print "<span class=\"type\">" . $args{'type'} . "</span> "; 8791b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'struct'} . "</span> {"; 8801b40c194SDan Luedtke print "</li>\n"; 8811b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8821b40c194SDan Luedtke print "<li class=\"indent\">"; 8831b40c194SDan Luedtke if ($parameter =~ /^#/) { 8841b40c194SDan Luedtke print "<span class=\"param\">" . $parameter ."</span>\n"; 8851b40c194SDan Luedtke print "</li>\n"; 8861b40c194SDan Luedtke next; 8871b40c194SDan Luedtke } 8881b40c194SDan Luedtke my $parameter_name = $parameter; 8891b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 8901b40c194SDan Luedtke 8911b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 8921b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 8931b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 8941b40c194SDan Luedtke # pointer-to-function 8951b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 8961b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 8971b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 8981b40c194SDan Luedtke print "(<span class=\"args\">$2</span>);"; 8991b40c194SDan Luedtke } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 9001b40c194SDan Luedtke # bitfield 9011b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 9021b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9031b40c194SDan Luedtke print "<span class=\"bits\">$2</span>;"; 9041b40c194SDan Luedtke } else { 9051b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 9061b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>;"; 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>Members</h1>\n"; 9151b40c194SDan Luedtke print "<dl>\n"; 9161b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9171b40c194SDan Luedtke ($parameter =~ /^#/) && next; 9181b40c194SDan Luedtke 9191b40c194SDan Luedtke my $parameter_name = $parameter; 9201b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 9211b40c194SDan Luedtke 9221b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 9231b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 9241b40c194SDan Luedtke print "<dd>"; 9251b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 9261b40c194SDan Luedtke print "</dd>\n"; 9271b40c194SDan Luedtke } 9281b40c194SDan Luedtke print "</dl>\n"; 9291b40c194SDan Luedtke print "</section>\n"; 9301b40c194SDan Luedtke output_section_html5(@_); 9311b40c194SDan Luedtke print "</article>\n"; 9321b40c194SDan Luedtke} 9331b40c194SDan Luedtke 9341b40c194SDan Luedtke# output function in html5 9351b40c194SDan Luedtkesub output_function_html5(%) { 9361b40c194SDan Luedtke my %args = %{$_[0]}; 9371b40c194SDan Luedtke my ($parameter, $section); 9381b40c194SDan Luedtke my $count; 9391b40c194SDan Luedtke my $html5id; 9401b40c194SDan Luedtke 9411b40c194SDan Luedtke $html5id = $args{'function'}; 9421b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 9431b40c194SDan Luedtke print "<article class=\"function\" id=\"func:". $html5id . "\">\n"; 9441b40c194SDan Luedtke print "<hgroup>\n"; 9451b40c194SDan Luedtke print "<h1>" . $args{'function'} . "</h1>"; 9461b40c194SDan Luedtke print "<h2>" . $args{'purpose'} . "</h2>\n"; 9471b40c194SDan Luedtke print "</hgroup>\n"; 9481b40c194SDan Luedtke print "<ol class=\"code\">\n"; 9491b40c194SDan Luedtke print "<li>"; 9501b40c194SDan Luedtke print "<span class=\"type\">" . $args{'functiontype'} . "</span> "; 9511b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'function'} . "</span> ("; 9521b40c194SDan Luedtke print "</li>"; 9531b40c194SDan Luedtke $count = 0; 9541b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9551b40c194SDan Luedtke print "<li class=\"indent\">"; 9561b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 9571b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 9581b40c194SDan Luedtke # pointer-to-function 9591b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 9601b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9611b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 9621b40c194SDan Luedtke print "(<span class=\"args\">$2</span>)"; 9631b40c194SDan Luedtke } else { 9641b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 9651b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9661b40c194SDan Luedtke } 9671b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 9681b40c194SDan Luedtke $count++; 9691b40c194SDan Luedtke print ","; 9701b40c194SDan Luedtke } 9711b40c194SDan Luedtke print "</li>\n"; 9721b40c194SDan Luedtke } 9731b40c194SDan Luedtke print "<li>)</li>\n"; 9741b40c194SDan Luedtke print "</ol>\n"; 9751b40c194SDan Luedtke 9761b40c194SDan Luedtke print "<section>\n"; 9771b40c194SDan Luedtke print "<h1>Arguments</h1>\n"; 9781b40c194SDan Luedtke print "<p>\n"; 9791b40c194SDan Luedtke print "<dl>\n"; 9801b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9811b40c194SDan Luedtke my $parameter_name = $parameter; 9821b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 9831b40c194SDan Luedtke 9841b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 9851b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 9861b40c194SDan Luedtke print "<dd>"; 9871b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 9881b40c194SDan Luedtke print "</dd>\n"; 9891b40c194SDan Luedtke } 9901b40c194SDan Luedtke print "</dl>\n"; 9911b40c194SDan Luedtke print "</section>\n"; 9921b40c194SDan Luedtke output_section_html5(@_); 9931b40c194SDan Luedtke print "</article>\n"; 9941b40c194SDan Luedtke} 9951b40c194SDan Luedtke 9961b40c194SDan Luedtke# output DOC: block header in html5 9971b40c194SDan Luedtkesub output_blockhead_html5(%) { 9981b40c194SDan Luedtke my %args = %{$_[0]}; 9991b40c194SDan Luedtke my ($parameter, $section); 10001b40c194SDan Luedtke my $count; 10011b40c194SDan Luedtke my $html5id; 10021b40c194SDan Luedtke 10031b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 10041b40c194SDan Luedtke $html5id = $section; 10051b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 10061b40c194SDan Luedtke print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n"; 10071b40c194SDan Luedtke print "<h1>$section</h1>\n"; 10081b40c194SDan Luedtke print "<p>\n"; 10091b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 10101b40c194SDan Luedtke print "</p>\n"; 10111b40c194SDan Luedtke } 10121b40c194SDan Luedtke print "</article>\n"; 10131b40c194SDan Luedtke} 10141b40c194SDan Luedtke 10151da177e4SLinus Torvaldssub output_section_xml(%) { 10161da177e4SLinus Torvalds my %args = %{$_[0]}; 10171da177e4SLinus Torvalds my $section; 10181da177e4SLinus Torvalds # print out each section 10191da177e4SLinus Torvalds $lineprefix=" "; 10201da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1021c73894c1SRich Walker print "<refsect1>\n"; 1022c73894c1SRich Walker print "<title>$section</title>\n"; 10231da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 1024c73894c1SRich Walker print "<informalexample><programlisting>\n"; 1025e314ba31SDaniel Santos $output_preformatted = 1; 1026c73894c1SRich Walker } else { 1027c73894c1SRich Walker print "<para>\n"; 10281da177e4SLinus Torvalds } 10291da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1030e314ba31SDaniel Santos $output_preformatted = 0; 10311da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 1032c73894c1SRich Walker print "</programlisting></informalexample>\n"; 1033c73894c1SRich Walker } else { 1034c73894c1SRich Walker print "</para>\n"; 10351da177e4SLinus Torvalds } 1036c73894c1SRich Walker print "</refsect1>\n"; 10371da177e4SLinus Torvalds } 10381da177e4SLinus Torvalds} 10391da177e4SLinus Torvalds 10401da177e4SLinus Torvalds# output function in XML DocBook 10411da177e4SLinus Torvaldssub output_function_xml(%) { 10421da177e4SLinus Torvalds my %args = %{$_[0]}; 10431da177e4SLinus Torvalds my ($parameter, $section); 10441da177e4SLinus Torvalds my $count; 10451da177e4SLinus Torvalds my $id; 10461da177e4SLinus Torvalds 10471da177e4SLinus Torvalds $id = "API-" . $args{'function'}; 10481da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 10491da177e4SLinus Torvalds 10505449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 10518b0c2d98SMartin Waitz print "<refentryinfo>\n"; 10528b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 10538b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 10548b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 10558b0c2d98SMartin Waitz print "</refentryinfo>\n"; 10561da177e4SLinus Torvalds print "<refmeta>\n"; 10575449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; 10588b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 10590366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 10601da177e4SLinus Torvalds print "</refmeta>\n"; 10611da177e4SLinus Torvalds print "<refnamediv>\n"; 10621da177e4SLinus Torvalds print " <refname>" . $args{'function'} . "</refname>\n"; 10631da177e4SLinus Torvalds print " <refpurpose>\n"; 10641da177e4SLinus Torvalds print " "; 10651da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 10661da177e4SLinus Torvalds print " </refpurpose>\n"; 10671da177e4SLinus Torvalds print "</refnamediv>\n"; 10681da177e4SLinus Torvalds 10691da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 10701da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 10711da177e4SLinus Torvalds print " <funcsynopsis><funcprototype>\n"; 10721da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 10731da177e4SLinus Torvalds print "<function>" . $args{'function'} . " </function></funcdef>\n"; 10741da177e4SLinus Torvalds 10751da177e4SLinus Torvalds $count = 0; 10761da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 10771da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10781da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 10791da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 10801da177e4SLinus Torvalds # pointer-to-function 10811da177e4SLinus Torvalds print " <paramdef>$1<parameter>$parameter</parameter>)\n"; 10821da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 10831da177e4SLinus Torvalds } else { 10841da177e4SLinus Torvalds print " <paramdef>" . $type; 10851da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 10861da177e4SLinus Torvalds } 10871da177e4SLinus Torvalds } 10881da177e4SLinus Torvalds } else { 10896013d544SMartin Waitz print " <void/>\n"; 10901da177e4SLinus Torvalds } 10911da177e4SLinus Torvalds print " </funcprototype></funcsynopsis>\n"; 10921da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 10931da177e4SLinus Torvalds 10941da177e4SLinus Torvalds # print parameters 10951da177e4SLinus Torvalds print "<refsect1>\n <title>Arguments</title>\n"; 10961da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 10971da177e4SLinus Torvalds print " <variablelist>\n"; 10981da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10991da177e4SLinus Torvalds my $parameter_name = $parameter; 11001da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11011da177e4SLinus Torvalds 11021da177e4SLinus Torvalds print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; 11031da177e4SLinus Torvalds print " <listitem>\n <para>\n"; 11041da177e4SLinus Torvalds $lineprefix=" "; 11051da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 11061da177e4SLinus Torvalds print " </para>\n </listitem>\n </varlistentry>\n"; 11071da177e4SLinus Torvalds } 11081da177e4SLinus Torvalds print " </variablelist>\n"; 11091da177e4SLinus Torvalds } else { 11101da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 11111da177e4SLinus Torvalds } 11121da177e4SLinus Torvalds print "</refsect1>\n"; 11131da177e4SLinus Torvalds 11141da177e4SLinus Torvalds output_section_xml(@_); 11151da177e4SLinus Torvalds print "</refentry>\n\n"; 11161da177e4SLinus Torvalds} 11171da177e4SLinus Torvalds 11181da177e4SLinus Torvalds# output struct in XML DocBook 11191da177e4SLinus Torvaldssub output_struct_xml(%) { 11201da177e4SLinus Torvalds my %args = %{$_[0]}; 11211da177e4SLinus Torvalds my ($parameter, $section); 11221da177e4SLinus Torvalds my $id; 11231da177e4SLinus Torvalds 11241da177e4SLinus Torvalds $id = "API-struct-" . $args{'struct'}; 11251da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 11261da177e4SLinus Torvalds 11275449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 11288b0c2d98SMartin Waitz print "<refentryinfo>\n"; 11298b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 11308b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 11318b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 11328b0c2d98SMartin Waitz print "</refentryinfo>\n"; 11331da177e4SLinus Torvalds print "<refmeta>\n"; 11345449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; 11358b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 11360366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 11371da177e4SLinus Torvalds print "</refmeta>\n"; 11381da177e4SLinus Torvalds print "<refnamediv>\n"; 11391da177e4SLinus Torvalds print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; 11401da177e4SLinus Torvalds print " <refpurpose>\n"; 11411da177e4SLinus Torvalds print " "; 11421da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 11431da177e4SLinus Torvalds print " </refpurpose>\n"; 11441da177e4SLinus Torvalds print "</refnamediv>\n"; 11451da177e4SLinus Torvalds 11461da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 11471da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 11481da177e4SLinus Torvalds print " <programlisting>\n"; 11491da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 11501da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11511da177e4SLinus Torvalds if ($parameter =~ /^#/) { 11522b35f4d9SRandy Dunlap my $prm = $parameter; 11532b35f4d9SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 11542b35f4d9SRandy Dunlap # This allows us to have #define macros interspersed in a struct. 11552b35f4d9SRandy Dunlap $prm =~ s/\\\\\\/\&/g; 11562b35f4d9SRandy Dunlap print "$prm\n"; 11571da177e4SLinus Torvalds next; 11581da177e4SLinus Torvalds } 11591da177e4SLinus Torvalds 11601da177e4SLinus Torvalds my $parameter_name = $parameter; 11611da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11621da177e4SLinus Torvalds 11631da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 11641da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 11651da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 11661da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 11671da177e4SLinus Torvalds # pointer-to-function 11681da177e4SLinus Torvalds print " $1 $parameter) ($2);\n"; 11691da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 117051f5a0c8SRandy Dunlap # bitfield 11711da177e4SLinus Torvalds print " $1 $parameter$2;\n"; 11721da177e4SLinus Torvalds } else { 11731da177e4SLinus Torvalds print " " . $type . " " . $parameter . ";\n"; 11741da177e4SLinus Torvalds } 11751da177e4SLinus Torvalds } 11761da177e4SLinus Torvalds print "};"; 11771da177e4SLinus Torvalds print " </programlisting>\n"; 11781da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 11791da177e4SLinus Torvalds 11801da177e4SLinus Torvalds print " <refsect1>\n"; 11811da177e4SLinus Torvalds print " <title>Members</title>\n"; 11821da177e4SLinus Torvalds 118339f00c08SRandy Dunlap if ($#{$args{'parameterlist'}} >= 0) { 11841da177e4SLinus Torvalds print " <variablelist>\n"; 11851da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11861da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 11871da177e4SLinus Torvalds 11881da177e4SLinus Torvalds my $parameter_name = $parameter; 11891da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11901da177e4SLinus Torvalds 11911da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 11921da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 11931da177e4SLinus Torvalds print " <varlistentry>"; 11941da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 11951da177e4SLinus Torvalds print " <listitem><para>\n"; 11961da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 11971da177e4SLinus Torvalds print " </para></listitem>\n"; 11981da177e4SLinus Torvalds print " </varlistentry>\n"; 11991da177e4SLinus Torvalds } 12001da177e4SLinus Torvalds print " </variablelist>\n"; 120139f00c08SRandy Dunlap } else { 120239f00c08SRandy Dunlap print " <para>\n None\n </para>\n"; 120339f00c08SRandy Dunlap } 12041da177e4SLinus Torvalds print " </refsect1>\n"; 12051da177e4SLinus Torvalds 12061da177e4SLinus Torvalds output_section_xml(@_); 12071da177e4SLinus Torvalds 12081da177e4SLinus Torvalds print "</refentry>\n\n"; 12091da177e4SLinus Torvalds} 12101da177e4SLinus Torvalds 12111da177e4SLinus Torvalds# output enum in XML DocBook 12121da177e4SLinus Torvaldssub output_enum_xml(%) { 12131da177e4SLinus Torvalds my %args = %{$_[0]}; 12141da177e4SLinus Torvalds my ($parameter, $section); 12151da177e4SLinus Torvalds my $count; 12161da177e4SLinus Torvalds my $id; 12171da177e4SLinus Torvalds 12181da177e4SLinus Torvalds $id = "API-enum-" . $args{'enum'}; 12191da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12201da177e4SLinus Torvalds 12215449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 12228b0c2d98SMartin Waitz print "<refentryinfo>\n"; 12238b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 12248b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 12258b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 12268b0c2d98SMartin Waitz print "</refentryinfo>\n"; 12271da177e4SLinus Torvalds print "<refmeta>\n"; 12285449bc94SPavel Pisa print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; 12298b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 12300366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 12311da177e4SLinus Torvalds print "</refmeta>\n"; 12321da177e4SLinus Torvalds print "<refnamediv>\n"; 12331da177e4SLinus Torvalds print " <refname>enum " . $args{'enum'} . "</refname>\n"; 12341da177e4SLinus Torvalds print " <refpurpose>\n"; 12351da177e4SLinus Torvalds print " "; 12361da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 12371da177e4SLinus Torvalds print " </refpurpose>\n"; 12381da177e4SLinus Torvalds print "</refnamediv>\n"; 12391da177e4SLinus Torvalds 12401da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 12411da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 12421da177e4SLinus Torvalds print " <programlisting>\n"; 12431da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 12441da177e4SLinus Torvalds $count = 0; 12451da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12461da177e4SLinus Torvalds print " $parameter"; 12471da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 12481da177e4SLinus Torvalds $count++; 12491da177e4SLinus Torvalds print ","; 12501da177e4SLinus Torvalds } 12511da177e4SLinus Torvalds print "\n"; 12521da177e4SLinus Torvalds } 12531da177e4SLinus Torvalds print "};"; 12541da177e4SLinus Torvalds print " </programlisting>\n"; 12551da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 12561da177e4SLinus Torvalds 12571da177e4SLinus Torvalds print "<refsect1>\n"; 12581da177e4SLinus Torvalds print " <title>Constants</title>\n"; 12591da177e4SLinus Torvalds print " <variablelist>\n"; 12601da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12611da177e4SLinus Torvalds my $parameter_name = $parameter; 12621da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12631da177e4SLinus Torvalds 12641da177e4SLinus Torvalds print " <varlistentry>"; 12651da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 12661da177e4SLinus Torvalds print " <listitem><para>\n"; 12671da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 12681da177e4SLinus Torvalds print " </para></listitem>\n"; 12691da177e4SLinus Torvalds print " </varlistentry>\n"; 12701da177e4SLinus Torvalds } 12711da177e4SLinus Torvalds print " </variablelist>\n"; 12721da177e4SLinus Torvalds print "</refsect1>\n"; 12731da177e4SLinus Torvalds 12741da177e4SLinus Torvalds output_section_xml(@_); 12751da177e4SLinus Torvalds 12761da177e4SLinus Torvalds print "</refentry>\n\n"; 12771da177e4SLinus Torvalds} 12781da177e4SLinus Torvalds 12791da177e4SLinus Torvalds# output typedef in XML DocBook 12801da177e4SLinus Torvaldssub output_typedef_xml(%) { 12811da177e4SLinus Torvalds my %args = %{$_[0]}; 12821da177e4SLinus Torvalds my ($parameter, $section); 12831da177e4SLinus Torvalds my $id; 12841da177e4SLinus Torvalds 12851da177e4SLinus Torvalds $id = "API-typedef-" . $args{'typedef'}; 12861da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12871da177e4SLinus Torvalds 12885449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 12898b0c2d98SMartin Waitz print "<refentryinfo>\n"; 12908b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 12918b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 12928b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 12938b0c2d98SMartin Waitz print "</refentryinfo>\n"; 12941da177e4SLinus Torvalds print "<refmeta>\n"; 12955449bc94SPavel Pisa print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; 12968b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 12971da177e4SLinus Torvalds print "</refmeta>\n"; 12981da177e4SLinus Torvalds print "<refnamediv>\n"; 12991da177e4SLinus Torvalds print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; 13001da177e4SLinus Torvalds print " <refpurpose>\n"; 13011da177e4SLinus Torvalds print " "; 13021da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 13031da177e4SLinus Torvalds print " </refpurpose>\n"; 13041da177e4SLinus Torvalds print "</refnamediv>\n"; 13051da177e4SLinus Torvalds 13061da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 13071da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 13081da177e4SLinus Torvalds print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; 13091da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 13101da177e4SLinus Torvalds 13111da177e4SLinus Torvalds output_section_xml(@_); 13121da177e4SLinus Torvalds 13131da177e4SLinus Torvalds print "</refentry>\n\n"; 13141da177e4SLinus Torvalds} 13151da177e4SLinus Torvalds 13161da177e4SLinus Torvalds# output in XML DocBook 1317b112e0f7SJohannes Bergsub output_blockhead_xml(%) { 13181da177e4SLinus Torvalds my %args = %{$_[0]}; 13191da177e4SLinus Torvalds my ($parameter, $section); 13201da177e4SLinus Torvalds my $count; 13211da177e4SLinus Torvalds 13221da177e4SLinus Torvalds my $id = $args{'module'}; 13231da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13241da177e4SLinus Torvalds 13251da177e4SLinus Torvalds # print out each section 13261da177e4SLinus Torvalds $lineprefix=" "; 13271da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1328b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1329b112e0f7SJohannes Berg print "<refsect1>\n <title>$section</title>\n"; 1330b112e0f7SJohannes Berg } 13311da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13321da177e4SLinus Torvalds print "<example><para>\n"; 1333e314ba31SDaniel Santos $output_preformatted = 1; 1334b112e0f7SJohannes Berg } else { 1335b112e0f7SJohannes Berg print "<para>\n"; 13361da177e4SLinus Torvalds } 13371da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1338e314ba31SDaniel Santos $output_preformatted = 0; 13391da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13401da177e4SLinus Torvalds print "</para></example>\n"; 1341b112e0f7SJohannes Berg } else { 1342b112e0f7SJohannes Berg print "</para>"; 13431da177e4SLinus Torvalds } 1344b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1345b112e0f7SJohannes Berg print "\n</refsect1>\n"; 1346b112e0f7SJohannes Berg } 13471da177e4SLinus Torvalds } 13481da177e4SLinus Torvalds 13491da177e4SLinus Torvalds print "\n\n"; 13501da177e4SLinus Torvalds} 13511da177e4SLinus Torvalds 13521da177e4SLinus Torvalds# output in XML DocBook 13531da177e4SLinus Torvaldssub output_function_gnome { 13541da177e4SLinus Torvalds my %args = %{$_[0]}; 13551da177e4SLinus Torvalds my ($parameter, $section); 13561da177e4SLinus Torvalds my $count; 13571da177e4SLinus Torvalds my $id; 13581da177e4SLinus Torvalds 13591da177e4SLinus Torvalds $id = $args{'module'} . "-" . $args{'function'}; 13601da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13611da177e4SLinus Torvalds 13621da177e4SLinus Torvalds print "<sect2>\n"; 13631da177e4SLinus Torvalds print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; 13641da177e4SLinus Torvalds 13651da177e4SLinus Torvalds print " <funcsynopsis>\n"; 13661da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 13671da177e4SLinus Torvalds print "<function>" . $args{'function'} . " "; 13681da177e4SLinus Torvalds print "</function></funcdef>\n"; 13691da177e4SLinus Torvalds 13701da177e4SLinus Torvalds $count = 0; 13711da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 13721da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13731da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 13741da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 13751da177e4SLinus Torvalds # pointer-to-function 13761da177e4SLinus Torvalds print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; 13771da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 13781da177e4SLinus Torvalds } else { 13791da177e4SLinus Torvalds print " <paramdef>" . $type; 13801da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 13811da177e4SLinus Torvalds } 13821da177e4SLinus Torvalds } 13831da177e4SLinus Torvalds } else { 13841da177e4SLinus Torvalds print " <void>\n"; 13851da177e4SLinus Torvalds } 13861da177e4SLinus Torvalds print " </funcsynopsis>\n"; 13871da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 13881da177e4SLinus Torvalds print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; 13891da177e4SLinus Torvalds print "<tgroup cols=\"2\">\n"; 13901da177e4SLinus Torvalds print "<colspec colwidth=\"2*\">\n"; 13911da177e4SLinus Torvalds print "<colspec colwidth=\"8*\">\n"; 13921da177e4SLinus Torvalds print "<tbody>\n"; 13931da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13941da177e4SLinus Torvalds my $parameter_name = $parameter; 13951da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 13961da177e4SLinus Torvalds 13971da177e4SLinus Torvalds print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; 13981da177e4SLinus Torvalds print " <entry>\n"; 13991da177e4SLinus Torvalds $lineprefix=" "; 14001da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14011da177e4SLinus Torvalds print " </entry></row>\n"; 14021da177e4SLinus Torvalds } 14031da177e4SLinus Torvalds print " </tbody></tgroup></informaltable>\n"; 14041da177e4SLinus Torvalds } else { 14051da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 14061da177e4SLinus Torvalds } 14071da177e4SLinus Torvalds 14081da177e4SLinus Torvalds # print out each section 14091da177e4SLinus Torvalds $lineprefix=" "; 14101da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14111da177e4SLinus Torvalds print "<simplesect>\n <title>$section</title>\n"; 14121da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 14131da177e4SLinus Torvalds print "<example><programlisting>\n"; 1414e314ba31SDaniel Santos $output_preformatted = 1; 14151da177e4SLinus Torvalds } else { 14161da177e4SLinus Torvalds } 14171da177e4SLinus Torvalds print "<para>\n"; 14181da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1419e314ba31SDaniel Santos $output_preformatted = 0; 14201da177e4SLinus Torvalds print "</para>\n"; 14211da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 14221da177e4SLinus Torvalds print "</programlisting></example>\n"; 14231da177e4SLinus Torvalds } else { 14241da177e4SLinus Torvalds } 14251da177e4SLinus Torvalds print " </simplesect>\n"; 14261da177e4SLinus Torvalds } 14271da177e4SLinus Torvalds 14281da177e4SLinus Torvalds print "</sect2>\n\n"; 14291da177e4SLinus Torvalds} 14301da177e4SLinus Torvalds 14311da177e4SLinus Torvalds## 14321da177e4SLinus Torvalds# output function in man 14331da177e4SLinus Torvaldssub output_function_man(%) { 14341da177e4SLinus Torvalds my %args = %{$_[0]}; 14351da177e4SLinus Torvalds my ($parameter, $section); 14361da177e4SLinus Torvalds my $count; 14371da177e4SLinus Torvalds 14381da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 14391da177e4SLinus Torvalds 14401da177e4SLinus Torvalds print ".SH NAME\n"; 14411da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 14421da177e4SLinus Torvalds 14431da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 1444a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 14451da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 1446a21217daSRandy Dunlap } else { 1447a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 1448a21217daSRandy Dunlap } 14491da177e4SLinus Torvalds $count = 0; 14501da177e4SLinus Torvalds my $parenth = "("; 14511da177e4SLinus Torvalds my $post = ","; 14521da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 14531da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 14541da177e4SLinus Torvalds $post = ");"; 14551da177e4SLinus Torvalds } 14561da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 14571da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 14581da177e4SLinus Torvalds # pointer-to-function 14591da177e4SLinus Torvalds print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 14601da177e4SLinus Torvalds } else { 14611da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 14621da177e4SLinus Torvalds print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 14631da177e4SLinus Torvalds } 14641da177e4SLinus Torvalds $count++; 14651da177e4SLinus Torvalds $parenth = ""; 14661da177e4SLinus Torvalds } 14671da177e4SLinus Torvalds 14681da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 14691da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14701da177e4SLinus Torvalds my $parameter_name = $parameter; 14711da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14721da177e4SLinus Torvalds 14731da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 14741da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14751da177e4SLinus Torvalds } 14761da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14771da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 14781da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 14791da177e4SLinus Torvalds } 14801da177e4SLinus Torvalds} 14811da177e4SLinus Torvalds 14821da177e4SLinus Torvalds## 14831da177e4SLinus Torvalds# output enum in man 14841da177e4SLinus Torvaldssub output_enum_man(%) { 14851da177e4SLinus Torvalds my %args = %{$_[0]}; 14861da177e4SLinus Torvalds my ($parameter, $section); 14871da177e4SLinus Torvalds my $count; 14881da177e4SLinus Torvalds 14891da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 14901da177e4SLinus Torvalds 14911da177e4SLinus Torvalds print ".SH NAME\n"; 14921da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 14931da177e4SLinus Torvalds 14941da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 14951da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 14961da177e4SLinus Torvalds $count = 0; 14971da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 14981da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 14991da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 15001da177e4SLinus Torvalds print "\n};\n"; 15011da177e4SLinus Torvalds last; 15021da177e4SLinus Torvalds } 15031da177e4SLinus Torvalds else { 15041da177e4SLinus Torvalds print ", \n.br\n"; 15051da177e4SLinus Torvalds } 15061da177e4SLinus Torvalds $count++; 15071da177e4SLinus Torvalds } 15081da177e4SLinus Torvalds 15091da177e4SLinus Torvalds print ".SH Constants\n"; 15101da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15111da177e4SLinus Torvalds my $parameter_name = $parameter; 15121da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15131da177e4SLinus Torvalds 15141da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 15151da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 15161da177e4SLinus Torvalds } 15171da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15181da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15191da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15201da177e4SLinus Torvalds } 15211da177e4SLinus Torvalds} 15221da177e4SLinus Torvalds 15231da177e4SLinus Torvalds## 15241da177e4SLinus Torvalds# output struct in man 15251da177e4SLinus Torvaldssub output_struct_man(%) { 15261da177e4SLinus Torvalds my %args = %{$_[0]}; 15271da177e4SLinus Torvalds my ($parameter, $section); 15281da177e4SLinus Torvalds 15291da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 15301da177e4SLinus Torvalds 15311da177e4SLinus Torvalds print ".SH NAME\n"; 15321da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 15331da177e4SLinus Torvalds 15341da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 15351da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 15361da177e4SLinus Torvalds 15371da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15381da177e4SLinus Torvalds if ($parameter =~ /^#/) { 15391da177e4SLinus Torvalds print ".BI \"$parameter\"\n.br\n"; 15401da177e4SLinus Torvalds next; 15411da177e4SLinus Torvalds } 15421da177e4SLinus Torvalds my $parameter_name = $parameter; 15431da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15441da177e4SLinus Torvalds 15451da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 15461da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 15471da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 15481da177e4SLinus Torvalds # pointer-to-function 15491da177e4SLinus Torvalds print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; 15501da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 15511d7e1d45SRandy.Dunlap # bitfield 15521d7e1d45SRandy.Dunlap print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; 15531da177e4SLinus Torvalds } else { 15541da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 15551da177e4SLinus Torvalds print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; 15561da177e4SLinus Torvalds } 15571da177e4SLinus Torvalds print "\n.br\n"; 15581da177e4SLinus Torvalds } 15591da177e4SLinus Torvalds print "};\n.br\n"; 15601da177e4SLinus Torvalds 1561c51d3dacSRandy Dunlap print ".SH Members\n"; 15621da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15631da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 15641da177e4SLinus Torvalds 15651da177e4SLinus Torvalds my $parameter_name = $parameter; 15661da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15671da177e4SLinus Torvalds 15681da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 15691da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 15701da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 15711da177e4SLinus Torvalds } 15721da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15731da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15741da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15751da177e4SLinus Torvalds } 15761da177e4SLinus Torvalds} 15771da177e4SLinus Torvalds 15781da177e4SLinus Torvalds## 15791da177e4SLinus Torvalds# output typedef in man 15801da177e4SLinus Torvaldssub output_typedef_man(%) { 15811da177e4SLinus Torvalds my %args = %{$_[0]}; 15821da177e4SLinus Torvalds my ($parameter, $section); 15831da177e4SLinus Torvalds 15841da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 15851da177e4SLinus Torvalds 15861da177e4SLinus Torvalds print ".SH NAME\n"; 15871da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 15881da177e4SLinus Torvalds 15891da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15901da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15911da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15921da177e4SLinus Torvalds } 15931da177e4SLinus Torvalds} 15941da177e4SLinus Torvalds 1595b112e0f7SJohannes Bergsub output_blockhead_man(%) { 15961da177e4SLinus Torvalds my %args = %{$_[0]}; 15971da177e4SLinus Torvalds my ($parameter, $section); 15981da177e4SLinus Torvalds my $count; 15991da177e4SLinus Torvalds 16001da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 16011da177e4SLinus Torvalds 16021da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16031da177e4SLinus Torvalds print ".SH \"$section\"\n"; 16041da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16051da177e4SLinus Torvalds } 16061da177e4SLinus Torvalds} 16071da177e4SLinus Torvalds 16081da177e4SLinus Torvalds## 16091da177e4SLinus Torvalds# output in text 16101da177e4SLinus Torvaldssub output_function_text(%) { 16111da177e4SLinus Torvalds my %args = %{$_[0]}; 16121da177e4SLinus Torvalds my ($parameter, $section); 1613a21217daSRandy Dunlap my $start; 16141da177e4SLinus Torvalds 1615f47634b2SRandy Dunlap print "Name:\n\n"; 1616f47634b2SRandy Dunlap print $args{'function'} . " - " . $args{'purpose'} . "\n"; 1617f47634b2SRandy Dunlap 1618f47634b2SRandy Dunlap print "\nSynopsis:\n\n"; 1619a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 1620a21217daSRandy Dunlap $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1621a21217daSRandy Dunlap } else { 1622a21217daSRandy Dunlap $start = $args{'function'} . " ("; 1623a21217daSRandy Dunlap } 16241da177e4SLinus Torvalds print $start; 1625a21217daSRandy Dunlap 16261da177e4SLinus Torvalds my $count = 0; 16271da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 16281da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 16291da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 16301da177e4SLinus Torvalds # pointer-to-function 16311da177e4SLinus Torvalds print $1 . $parameter . ") (" . $2; 16321da177e4SLinus Torvalds } else { 16331da177e4SLinus Torvalds print $type . " " . $parameter; 16341da177e4SLinus Torvalds } 16351da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 16361da177e4SLinus Torvalds $count++; 16371da177e4SLinus Torvalds print ",\n"; 16381da177e4SLinus Torvalds print " " x length($start); 16391da177e4SLinus Torvalds } else { 16401da177e4SLinus Torvalds print ");\n\n"; 16411da177e4SLinus Torvalds } 16421da177e4SLinus Torvalds } 16431da177e4SLinus Torvalds 16441da177e4SLinus Torvalds print "Arguments:\n\n"; 16451da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16461da177e4SLinus Torvalds my $parameter_name = $parameter; 16471da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16481da177e4SLinus Torvalds 16491da177e4SLinus Torvalds print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; 16501da177e4SLinus Torvalds } 16511da177e4SLinus Torvalds output_section_text(@_); 16521da177e4SLinus Torvalds} 16531da177e4SLinus Torvalds 16541da177e4SLinus Torvalds#output sections in text 16551da177e4SLinus Torvaldssub output_section_text(%) { 16561da177e4SLinus Torvalds my %args = %{$_[0]}; 16571da177e4SLinus Torvalds my $section; 16581da177e4SLinus Torvalds 16591da177e4SLinus Torvalds print "\n"; 16601da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16611da177e4SLinus Torvalds print "$section:\n\n"; 16621da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16631da177e4SLinus Torvalds } 16641da177e4SLinus Torvalds print "\n\n"; 16651da177e4SLinus Torvalds} 16661da177e4SLinus Torvalds 16671da177e4SLinus Torvalds# output enum in text 16681da177e4SLinus Torvaldssub output_enum_text(%) { 16691da177e4SLinus Torvalds my %args = %{$_[0]}; 16701da177e4SLinus Torvalds my ($parameter); 16711da177e4SLinus Torvalds my $count; 16721da177e4SLinus Torvalds print "Enum:\n\n"; 16731da177e4SLinus Torvalds 16741d7e1d45SRandy.Dunlap print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; 16751da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 16761da177e4SLinus Torvalds $count = 0; 16771da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16781da177e4SLinus Torvalds print "\t$parameter"; 16791da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 16801da177e4SLinus Torvalds $count++; 16811da177e4SLinus Torvalds print ","; 16821da177e4SLinus Torvalds } 16831da177e4SLinus Torvalds print "\n"; 16841da177e4SLinus Torvalds } 16851da177e4SLinus Torvalds print "};\n\n"; 16861da177e4SLinus Torvalds 16871da177e4SLinus Torvalds print "Constants:\n\n"; 16881da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16891da177e4SLinus Torvalds print "$parameter\n\t"; 16901da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter} . "\n"; 16911da177e4SLinus Torvalds } 16921da177e4SLinus Torvalds 16931da177e4SLinus Torvalds output_section_text(@_); 16941da177e4SLinus Torvalds} 16951da177e4SLinus Torvalds 16961da177e4SLinus Torvalds# output typedef in text 16971da177e4SLinus Torvaldssub output_typedef_text(%) { 16981da177e4SLinus Torvalds my %args = %{$_[0]}; 16991da177e4SLinus Torvalds my ($parameter); 17001da177e4SLinus Torvalds my $count; 17011da177e4SLinus Torvalds print "Typedef:\n\n"; 17021da177e4SLinus Torvalds 17031d7e1d45SRandy.Dunlap print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; 17041da177e4SLinus Torvalds output_section_text(@_); 17051da177e4SLinus Torvalds} 17061da177e4SLinus Torvalds 17071da177e4SLinus Torvalds# output struct as text 17081da177e4SLinus Torvaldssub output_struct_text(%) { 17091da177e4SLinus Torvalds my %args = %{$_[0]}; 17101da177e4SLinus Torvalds my ($parameter); 17111da177e4SLinus Torvalds 17121d7e1d45SRandy.Dunlap print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; 17131da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 17141da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17151da177e4SLinus Torvalds if ($parameter =~ /^#/) { 17161da177e4SLinus Torvalds print "$parameter\n"; 17171da177e4SLinus Torvalds next; 17181da177e4SLinus Torvalds } 17191da177e4SLinus Torvalds 17201da177e4SLinus Torvalds my $parameter_name = $parameter; 17211da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 17221da177e4SLinus Torvalds 17231da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 17241da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 17251da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 17261da177e4SLinus Torvalds # pointer-to-function 17271da177e4SLinus Torvalds print "\t$1 $parameter) ($2);\n"; 17281da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 172951f5a0c8SRandy Dunlap # bitfield 17301da177e4SLinus Torvalds print "\t$1 $parameter$2;\n"; 17311da177e4SLinus Torvalds } else { 17321da177e4SLinus Torvalds print "\t" . $type . " " . $parameter . ";\n"; 17331da177e4SLinus Torvalds } 17341da177e4SLinus Torvalds } 17351da177e4SLinus Torvalds print "};\n\n"; 17361da177e4SLinus Torvalds 17371da177e4SLinus Torvalds print "Members:\n\n"; 17381da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17391da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 17401da177e4SLinus Torvalds 17411da177e4SLinus Torvalds my $parameter_name = $parameter; 17421da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 17431da177e4SLinus Torvalds 17441da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 17451da177e4SLinus Torvalds print "$parameter\n\t"; 17461da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter_name} . "\n"; 17471da177e4SLinus Torvalds } 17481da177e4SLinus Torvalds print "\n"; 17491da177e4SLinus Torvalds output_section_text(@_); 17501da177e4SLinus Torvalds} 17511da177e4SLinus Torvalds 1752b112e0f7SJohannes Bergsub output_blockhead_text(%) { 17531da177e4SLinus Torvalds my %args = %{$_[0]}; 17541da177e4SLinus Torvalds my ($parameter, $section); 17551da177e4SLinus Torvalds 17561da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 17571da177e4SLinus Torvalds print " $section:\n"; 17581da177e4SLinus Torvalds print " -> "; 17591da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 17601da177e4SLinus Torvalds } 17611da177e4SLinus Torvalds} 17621da177e4SLinus Torvalds 1763c0d1b6eeSJonathan Corbet## 1764c0d1b6eeSJonathan Corbet# output in restructured text 1765c0d1b6eeSJonathan Corbet# 1766c0d1b6eeSJonathan Corbet 1767c0d1b6eeSJonathan Corbet# 1768c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 1769c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 1770c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 1771c0d1b6eeSJonathan Corbet# 1772c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 1773c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1774c0d1b6eeSJonathan Corbet my ($parameter, $section); 1775c0d1b6eeSJonathan Corbet 1776c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 17779e72184bSJani Nikula if ($output_selection != OUTPUT_INCLUDE) { 1778c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 17799e72184bSJani Nikula } 1780c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1781c0d1b6eeSJonathan Corbet print "\n"; 1782c0d1b6eeSJonathan Corbet } 1783c0d1b6eeSJonathan Corbet} 1784c0d1b6eeSJonathan Corbet 1785c0d1b6eeSJonathan Corbetsub output_highlight_rst { 1786c0d1b6eeSJonathan Corbet my $contents = join "\n",@_; 1787c0d1b6eeSJonathan Corbet my $line; 1788c0d1b6eeSJonathan Corbet 1789c0d1b6eeSJonathan Corbet # undo the evil effects of xml_escape() earlier 1790c0d1b6eeSJonathan Corbet $contents = xml_unescape($contents); 1791c0d1b6eeSJonathan Corbet 1792c0d1b6eeSJonathan Corbet eval $dohighlight; 1793c0d1b6eeSJonathan Corbet die $@ if $@; 1794c0d1b6eeSJonathan Corbet 1795c0d1b6eeSJonathan Corbet foreach $line (split "\n", $contents) { 1796c0d1b6eeSJonathan Corbet if ($line eq "") { 1797c0d1b6eeSJonathan Corbet print $lineprefix, $blankline; 1798c0d1b6eeSJonathan Corbet } else { 1799c0d1b6eeSJonathan Corbet print $lineprefix, $line; 1800c0d1b6eeSJonathan Corbet } 1801c0d1b6eeSJonathan Corbet print "\n"; 1802c0d1b6eeSJonathan Corbet } 1803c0d1b6eeSJonathan Corbet} 1804c0d1b6eeSJonathan Corbet 1805c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 1806c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1807c0d1b6eeSJonathan Corbet my ($parameter, $section); 1808*c099ff69SJani Nikula my $oldprefix = $lineprefix; 1809c0d1b6eeSJonathan Corbet my $start; 1810c0d1b6eeSJonathan Corbet 1811c0d1b6eeSJonathan Corbet print ".. c:function:: "; 1812c0d1b6eeSJonathan Corbet if ($args{'functiontype'} ne "") { 1813c0d1b6eeSJonathan Corbet $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1814c0d1b6eeSJonathan Corbet } else { 1815c0d1b6eeSJonathan Corbet $start = $args{'function'} . " ("; 1816c0d1b6eeSJonathan Corbet } 1817c0d1b6eeSJonathan Corbet print $start; 1818c0d1b6eeSJonathan Corbet 1819c0d1b6eeSJonathan Corbet my $count = 0; 1820c0d1b6eeSJonathan Corbet foreach my $parameter (@{$args{'parameterlist'}}) { 1821c0d1b6eeSJonathan Corbet if ($count ne 0) { 1822c0d1b6eeSJonathan Corbet print ", "; 1823c0d1b6eeSJonathan Corbet } 1824c0d1b6eeSJonathan Corbet $count++; 1825c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1826c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1827c0d1b6eeSJonathan Corbet # pointer-to-function 1828c0d1b6eeSJonathan Corbet print $1 . $parameter . ") (" . $2; 1829c0d1b6eeSJonathan Corbet } else { 1830c0d1b6eeSJonathan Corbet print $type . " " . $parameter; 1831c0d1b6eeSJonathan Corbet } 1832c0d1b6eeSJonathan Corbet } 1833*c099ff69SJani Nikula print ")\n\n"; 1834*c099ff69SJani Nikula $lineprefix = " "; 1835*c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1836*c099ff69SJani Nikula print "\n"; 1837c0d1b6eeSJonathan Corbet 1838c0d1b6eeSJonathan Corbet print ":Parameters:\n\n"; 1839*c099ff69SJani Nikula $lineprefix = " "; 1840c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1841c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1842c0d1b6eeSJonathan Corbet #$parameter_name =~ s/\[.*//; 1843c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1844c0d1b6eeSJonathan Corbet 1845c0d1b6eeSJonathan Corbet if ($type ne "") { 1846c0d1b6eeSJonathan Corbet print " ``$type $parameter``\n"; 1847c0d1b6eeSJonathan Corbet } else { 1848c0d1b6eeSJonathan Corbet print " ``$parameter``\n"; 1849c0d1b6eeSJonathan Corbet } 18505e64fa9cSJani Nikula if (defined($args{'parameterdescs'}{$parameter_name}) && 18515e64fa9cSJani Nikula $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 1852c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1853c0d1b6eeSJonathan Corbet } else { 1854c0d1b6eeSJonathan Corbet print "\n _undescribed_\n"; 1855c0d1b6eeSJonathan Corbet } 1856c0d1b6eeSJonathan Corbet print "\n"; 1857c0d1b6eeSJonathan Corbet } 1858*c099ff69SJani Nikula 1859*c099ff69SJani Nikula $lineprefix = $oldprefix; 1860c0d1b6eeSJonathan Corbet output_section_rst(@_); 1861c0d1b6eeSJonathan Corbet} 1862c0d1b6eeSJonathan Corbet 1863c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 1864c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1865c0d1b6eeSJonathan Corbet my $section; 1866c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1867c0d1b6eeSJonathan Corbet $lineprefix = " "; 1868c0d1b6eeSJonathan Corbet 1869c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 1870c0d1b6eeSJonathan Corbet print ":$section:\n\n"; 1871c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1872c0d1b6eeSJonathan Corbet print "\n"; 1873c0d1b6eeSJonathan Corbet } 1874c0d1b6eeSJonathan Corbet print "\n"; 1875c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1876c0d1b6eeSJonathan Corbet} 1877c0d1b6eeSJonathan Corbet 1878c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 1879c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1880c0d1b6eeSJonathan Corbet my ($parameter); 1881*c099ff69SJani Nikula my $oldprefix = $lineprefix; 1882c0d1b6eeSJonathan Corbet my $count; 1883c0d1b6eeSJonathan Corbet my $name = "enum " . $args{'enum'}; 188462850976SJani Nikula 188562850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1886*c099ff69SJani Nikula $lineprefix = " "; 1887*c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1888*c099ff69SJani Nikula print "\n"; 1889c0d1b6eeSJonathan Corbet 1890c0d1b6eeSJonathan Corbet print "..\n\n:Constants:\n\n"; 1891c0d1b6eeSJonathan Corbet $lineprefix = " "; 1892c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1893c0d1b6eeSJonathan Corbet print " `$parameter`\n"; 1894c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 1895c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 1896c0d1b6eeSJonathan Corbet } else { 1897c0d1b6eeSJonathan Corbet print " undescribed\n"; 1898c0d1b6eeSJonathan Corbet } 1899c0d1b6eeSJonathan Corbet print "\n"; 1900c0d1b6eeSJonathan Corbet } 1901*c099ff69SJani Nikula 1902c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1903c0d1b6eeSJonathan Corbet output_section_rst(@_); 1904c0d1b6eeSJonathan Corbet} 1905c0d1b6eeSJonathan Corbet 1906c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 1907c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1908c0d1b6eeSJonathan Corbet my ($parameter); 1909*c099ff69SJani Nikula my $oldprefix = $lineprefix; 1910c0d1b6eeSJonathan Corbet my $name = "typedef " . $args{'typedef'}; 1911c0d1b6eeSJonathan Corbet 191262850976SJani Nikula ### FIXME: should the name below contain "typedef" or not? 191362850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1914*c099ff69SJani Nikula $lineprefix = " "; 1915*c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1916*c099ff69SJani Nikula print "\n"; 1917c0d1b6eeSJonathan Corbet 1918*c099ff69SJani Nikula $lineprefix = $oldprefix; 1919c0d1b6eeSJonathan Corbet output_section_rst(@_); 1920c0d1b6eeSJonathan Corbet} 1921c0d1b6eeSJonathan Corbet 1922c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 1923c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1924c0d1b6eeSJonathan Corbet my ($parameter); 1925*c099ff69SJani Nikula my $oldprefix = $lineprefix; 1926c0d1b6eeSJonathan Corbet my $name = $args{'type'} . " " . $args{'struct'}; 1927c0d1b6eeSJonathan Corbet 192862850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1929*c099ff69SJani Nikula $lineprefix = " "; 1930*c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1931*c099ff69SJani Nikula print "\n"; 1932c0d1b6eeSJonathan Corbet 1933c0d1b6eeSJonathan Corbet print ":Definition:\n\n"; 1934c0d1b6eeSJonathan Corbet print " ::\n\n"; 1935c0d1b6eeSJonathan Corbet print " " . $args{'type'} . " " . $args{'struct'} . " {\n"; 1936c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1937c0d1b6eeSJonathan Corbet if ($parameter =~ /^#/) { 1938c0d1b6eeSJonathan Corbet print " " . "$parameter\n"; 1939c0d1b6eeSJonathan Corbet next; 1940c0d1b6eeSJonathan Corbet } 1941c0d1b6eeSJonathan Corbet 1942c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1943c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 1944c0d1b6eeSJonathan Corbet 1945c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1946c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1947c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1948c0d1b6eeSJonathan Corbet # pointer-to-function 1949c0d1b6eeSJonathan Corbet print " $1 $parameter) ($2);\n"; 1950c0d1b6eeSJonathan Corbet } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 1951c0d1b6eeSJonathan Corbet # bitfield 1952c0d1b6eeSJonathan Corbet print " $1 $parameter$2;\n"; 1953c0d1b6eeSJonathan Corbet } else { 1954c0d1b6eeSJonathan Corbet print " " . $type . " " . $parameter . ";\n"; 1955c0d1b6eeSJonathan Corbet } 1956c0d1b6eeSJonathan Corbet } 1957c0d1b6eeSJonathan Corbet print " };\n\n"; 1958c0d1b6eeSJonathan Corbet 1959c0d1b6eeSJonathan Corbet print ":Members:\n\n"; 1960*c099ff69SJani Nikula $lineprefix = " "; 1961c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1962c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 1963c0d1b6eeSJonathan Corbet 1964c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1965c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 1966c0d1b6eeSJonathan Corbet 1967c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1968c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1969c0d1b6eeSJonathan Corbet print " `$type $parameter`" . "\n"; 1970c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1971c0d1b6eeSJonathan Corbet print "\n"; 1972c0d1b6eeSJonathan Corbet } 1973c0d1b6eeSJonathan Corbet print "\n"; 1974*c099ff69SJani Nikula 1975*c099ff69SJani Nikula $lineprefix = $oldprefix; 1976c0d1b6eeSJonathan Corbet output_section_rst(@_); 1977c0d1b6eeSJonathan Corbet} 1978c0d1b6eeSJonathan Corbet 1979c0d1b6eeSJonathan Corbet 1980eda603f6SJohannes Berg## list mode output functions 1981eda603f6SJohannes Berg 1982eda603f6SJohannes Bergsub output_function_list(%) { 1983eda603f6SJohannes Berg my %args = %{$_[0]}; 1984eda603f6SJohannes Berg 1985eda603f6SJohannes Berg print $args{'function'} . "\n"; 1986eda603f6SJohannes Berg} 1987eda603f6SJohannes Berg 1988eda603f6SJohannes Berg# output enum in list 1989eda603f6SJohannes Bergsub output_enum_list(%) { 1990eda603f6SJohannes Berg my %args = %{$_[0]}; 1991eda603f6SJohannes Berg print $args{'enum'} . "\n"; 1992eda603f6SJohannes Berg} 1993eda603f6SJohannes Berg 1994eda603f6SJohannes Berg# output typedef in list 1995eda603f6SJohannes Bergsub output_typedef_list(%) { 1996eda603f6SJohannes Berg my %args = %{$_[0]}; 1997eda603f6SJohannes Berg print $args{'typedef'} . "\n"; 1998eda603f6SJohannes Berg} 1999eda603f6SJohannes Berg 2000eda603f6SJohannes Berg# output struct as list 2001eda603f6SJohannes Bergsub output_struct_list(%) { 2002eda603f6SJohannes Berg my %args = %{$_[0]}; 2003eda603f6SJohannes Berg 2004eda603f6SJohannes Berg print $args{'struct'} . "\n"; 2005eda603f6SJohannes Berg} 2006eda603f6SJohannes Berg 2007eda603f6SJohannes Bergsub output_blockhead_list(%) { 2008eda603f6SJohannes Berg my %args = %{$_[0]}; 2009eda603f6SJohannes Berg my ($parameter, $section); 2010eda603f6SJohannes Berg 2011eda603f6SJohannes Berg foreach $section (@{$args{'sectionlist'}}) { 2012eda603f6SJohannes Berg print "DOC: $section\n"; 2013eda603f6SJohannes Berg } 2014eda603f6SJohannes Berg} 2015eda603f6SJohannes Berg 20161da177e4SLinus Torvalds## 201727205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 201827205744SRandy Dunlap# calls the generated, variable output_ function name based on 201927205744SRandy Dunlap# functype and output_mode 20201da177e4SLinus Torvaldssub output_declaration { 20211da177e4SLinus Torvalds no strict 'refs'; 20221da177e4SLinus Torvalds my $name = shift; 20231da177e4SLinus Torvalds my $functype = shift; 20241da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 2025b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 2026b6c3f456SJani Nikula (($output_selection == OUTPUT_INCLUDE || 2027b6c3f456SJani Nikula $output_selection == OUTPUT_EXPORTED) && 202886ae2e38SJani Nikula defined($function_table{$name})) || 2029b6c3f456SJani Nikula (($output_selection == OUTPUT_EXCLUDE || 2030b6c3f456SJani Nikula $output_selection == OUTPUT_INTERNAL) && 203186ae2e38SJani Nikula !($functype eq "function" && defined($function_table{$name})))) 20321da177e4SLinus Torvalds { 20331da177e4SLinus Torvalds &$func(@_); 20341da177e4SLinus Torvalds $section_counter++; 20351da177e4SLinus Torvalds } 20361da177e4SLinus Torvalds} 20371da177e4SLinus Torvalds 20381da177e4SLinus Torvalds## 203927205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 2040b112e0f7SJohannes Bergsub output_blockhead { 20411da177e4SLinus Torvalds no strict 'refs'; 2042b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 20431da177e4SLinus Torvalds &$func(@_); 20441da177e4SLinus Torvalds $section_counter++; 20451da177e4SLinus Torvalds} 20461da177e4SLinus Torvalds 20471da177e4SLinus Torvalds## 20481da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 20491da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 20501da177e4SLinus Torvaldssub dump_declaration($$) { 20511da177e4SLinus Torvalds no strict 'refs'; 20521da177e4SLinus Torvalds my ($prototype, $file) = @_; 20531da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 20541da177e4SLinus Torvalds &$func(@_); 20551da177e4SLinus Torvalds} 20561da177e4SLinus Torvalds 20571da177e4SLinus Torvaldssub dump_union($$) { 20581da177e4SLinus Torvalds dump_struct(@_); 20591da177e4SLinus Torvalds} 20601da177e4SLinus Torvalds 20611da177e4SLinus Torvaldssub dump_struct($$) { 20621da177e4SLinus Torvalds my $x = shift; 20631da177e4SLinus Torvalds my $file = shift; 2064a1d94aa5SRandy Dunlap my $nested; 20651da177e4SLinus Torvalds 20661da177e4SLinus Torvalds if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 206752dc5aecSRandy Dunlap #my $decl_type = $1; 20681da177e4SLinus Torvalds $declaration_name = $2; 20691da177e4SLinus Torvalds my $members = $3; 20701da177e4SLinus Torvalds 20711da177e4SLinus Torvalds # ignore embedded structs or unions 2072a1d94aa5SRandy Dunlap $members =~ s/({.*})//g; 2073a1d94aa5SRandy Dunlap $nested = $1; 20741da177e4SLinus Torvalds 2075aeec46b9SMartin Waitz # ignore members marked private: 20760d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 20770d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 2078aeec46b9SMartin Waitz # strip comments: 2079aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 2080a1d94aa5SRandy Dunlap $nested =~ s/\/\*.*?\*\///gos; 2081d960eea9SRandy Dunlap # strip kmemcheck_bitfield_{begin,end}.*; 2082d960eea9SRandy Dunlap $members =~ s/kmemcheck_bitfield_.*?;//gos; 2083ef5da59fSRandy Dunlap # strip attributes 2084f0074929SJonathan Corbet $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 20857b990789SJohannes Berg $members =~ s/__aligned\s*\([^;]*\)//gos; 2086f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; 2087b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 2088b22b5a9eSConchúr Navid $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 2089aeec46b9SMartin Waitz 20901da177e4SLinus Torvalds create_parameterlist($members, ';', $file); 2091a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); 20921da177e4SLinus Torvalds 20931da177e4SLinus Torvalds output_declaration($declaration_name, 20941da177e4SLinus Torvalds 'struct', 20951da177e4SLinus Torvalds {'struct' => $declaration_name, 20961da177e4SLinus Torvalds 'module' => $modulename, 20971da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 20981da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 20991da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 21001da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 21011da177e4SLinus Torvalds 'sections' => \%sections, 21021da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 21031da177e4SLinus Torvalds 'type' => $decl_type 21041da177e4SLinus Torvalds }); 21051da177e4SLinus Torvalds } 21061da177e4SLinus Torvalds else { 2107d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 21081da177e4SLinus Torvalds ++$errors; 21091da177e4SLinus Torvalds } 21101da177e4SLinus Torvalds} 21111da177e4SLinus Torvalds 21121da177e4SLinus Torvaldssub dump_enum($$) { 21131da177e4SLinus Torvalds my $x = shift; 21141da177e4SLinus Torvalds my $file = shift; 21151da177e4SLinus Torvalds 2116aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 21174468e21eSConchúr Navid # strip #define macros inside enums 21184468e21eSConchúr Navid $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 2119b6d676dbSRandy Dunlap 21201da177e4SLinus Torvalds if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 21211da177e4SLinus Torvalds $declaration_name = $1; 21221da177e4SLinus Torvalds my $members = $2; 21231da177e4SLinus Torvalds 21241da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 21251da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 21261da177e4SLinus Torvalds push @parameterlist, $arg; 21271da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 21281da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 2129d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Enum value '$arg' ". 21301da177e4SLinus Torvalds "not described in enum '$declaration_name'\n"; 21311da177e4SLinus Torvalds } 21321da177e4SLinus Torvalds 21331da177e4SLinus Torvalds } 21341da177e4SLinus Torvalds 21351da177e4SLinus Torvalds output_declaration($declaration_name, 21361da177e4SLinus Torvalds 'enum', 21371da177e4SLinus Torvalds {'enum' => $declaration_name, 21381da177e4SLinus Torvalds 'module' => $modulename, 21391da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 21401da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 21411da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 21421da177e4SLinus Torvalds 'sections' => \%sections, 21431da177e4SLinus Torvalds 'purpose' => $declaration_purpose 21441da177e4SLinus Torvalds }); 21451da177e4SLinus Torvalds } 21461da177e4SLinus Torvalds else { 2147d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 21481da177e4SLinus Torvalds ++$errors; 21491da177e4SLinus Torvalds } 21501da177e4SLinus Torvalds} 21511da177e4SLinus Torvalds 21521da177e4SLinus Torvaldssub dump_typedef($$) { 21531da177e4SLinus Torvalds my $x = shift; 21541da177e4SLinus Torvalds my $file = shift; 21551da177e4SLinus Torvalds 2156aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 215783766452SMauro Carvalho Chehab 215883766452SMauro Carvalho Chehab # Parse function prototypes 215983766452SMauro Carvalho Chehab if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) { 216083766452SMauro Carvalho Chehab # Function typedefs 216183766452SMauro Carvalho Chehab $return_type = $1; 216283766452SMauro Carvalho Chehab $declaration_name = $2; 216383766452SMauro Carvalho Chehab my $args = $3; 216483766452SMauro Carvalho Chehab 216583766452SMauro Carvalho Chehab create_parameterlist($args, ',', $file); 216683766452SMauro Carvalho Chehab 216783766452SMauro Carvalho Chehab output_declaration($declaration_name, 216883766452SMauro Carvalho Chehab 'function', 216983766452SMauro Carvalho Chehab {'function' => $declaration_name, 217083766452SMauro Carvalho Chehab 'module' => $modulename, 217183766452SMauro Carvalho Chehab 'functiontype' => $return_type, 217283766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 217383766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 217483766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 217583766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 217683766452SMauro Carvalho Chehab 'sections' => \%sections, 217783766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 217883766452SMauro Carvalho Chehab }); 217983766452SMauro Carvalho Chehab return; 218083766452SMauro Carvalho Chehab } 218183766452SMauro Carvalho Chehab 21821da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 21831da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 21841da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 21851da177e4SLinus Torvalds } 21861da177e4SLinus Torvalds 21871da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 21881da177e4SLinus Torvalds $declaration_name = $1; 21891da177e4SLinus Torvalds 21901da177e4SLinus Torvalds output_declaration($declaration_name, 21911da177e4SLinus Torvalds 'typedef', 21921da177e4SLinus Torvalds {'typedef' => $declaration_name, 21931da177e4SLinus Torvalds 'module' => $modulename, 21941da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 21951da177e4SLinus Torvalds 'sections' => \%sections, 21961da177e4SLinus Torvalds 'purpose' => $declaration_purpose 21971da177e4SLinus Torvalds }); 21981da177e4SLinus Torvalds } 21991da177e4SLinus Torvalds else { 2200d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 22011da177e4SLinus Torvalds ++$errors; 22021da177e4SLinus Torvalds } 22031da177e4SLinus Torvalds} 22041da177e4SLinus Torvalds 2205a1d94aa5SRandy Dunlapsub save_struct_actual($) { 2206a1d94aa5SRandy Dunlap my $actual = shift; 2207a1d94aa5SRandy Dunlap 2208a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 2209a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 2210a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 2211a1d94aa5SRandy Dunlap} 2212a1d94aa5SRandy Dunlap 22131da177e4SLinus Torvaldssub create_parameterlist($$$) { 22141da177e4SLinus Torvalds my $args = shift; 22151da177e4SLinus Torvalds my $splitter = shift; 22161da177e4SLinus Torvalds my $file = shift; 22171da177e4SLinus Torvalds my $type; 22181da177e4SLinus Torvalds my $param; 22191da177e4SLinus Torvalds 2220a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 22211da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 22221da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 22231da177e4SLinus Torvalds } 22241da177e4SLinus Torvalds 22251da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 22261da177e4SLinus Torvalds # strip comments 22271da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 22281da177e4SLinus Torvalds # strip leading/trailing spaces 22291da177e4SLinus Torvalds $arg =~ s/^\s*//; 22301da177e4SLinus Torvalds $arg =~ s/\s*$//; 22311da177e4SLinus Torvalds $arg =~ s/\s+/ /; 22321da177e4SLinus Torvalds 22331da177e4SLinus Torvalds if ($arg =~ /^#/) { 22341da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 22351da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 22361da177e4SLinus Torvalds # output_* subs. 22371da177e4SLinus Torvalds push_parameter($arg, "", $file); 223800d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 22391da177e4SLinus Torvalds # pointer-to-function 22401da177e4SLinus Torvalds $arg =~ tr/#/,/; 224100d62961SRichard Kennedy $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 22421da177e4SLinus Torvalds $param = $1; 22431da177e4SLinus Torvalds $type = $arg; 224400d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 2245a1d94aa5SRandy Dunlap save_struct_actual($param); 22461da177e4SLinus Torvalds push_parameter($param, $type, $file); 2247aeec46b9SMartin Waitz } elsif ($arg) { 22481da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 22491da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 22501da177e4SLinus Torvalds 22511da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 22521da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 22531da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 22541da177e4SLinus Torvalds } 2255884f2810SBorislav Petkov 2256884f2810SBorislav Petkov my @first_arg; 2257884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 2258884f2810SBorislav Petkov shift @args; 2259884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 2260884f2810SBorislav Petkov push(@first_arg, $2); 2261884f2810SBorislav Petkov } else { 2262884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 2263884f2810SBorislav Petkov } 2264884f2810SBorislav Petkov 22651da177e4SLinus Torvalds unshift(@args, pop @first_arg); 22661da177e4SLinus Torvalds $type = join " ", @first_arg; 22671da177e4SLinus Torvalds 22681da177e4SLinus Torvalds foreach $param (@args) { 22691da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 2270a1d94aa5SRandy Dunlap save_struct_actual($2); 22711da177e4SLinus Torvalds push_parameter($2, "$type $1", $file); 22721da177e4SLinus Torvalds } 22731da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 22747b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 2275a1d94aa5SRandy Dunlap save_struct_actual($1); 22761da177e4SLinus Torvalds push_parameter($1, "$type:$2", $file) 22771da177e4SLinus Torvalds } 22787b97887eSRandy Dunlap } 22791da177e4SLinus Torvalds else { 2280a1d94aa5SRandy Dunlap save_struct_actual($param); 22811da177e4SLinus Torvalds push_parameter($param, $type, $file); 22821da177e4SLinus Torvalds } 22831da177e4SLinus Torvalds } 22841da177e4SLinus Torvalds } 22851da177e4SLinus Torvalds } 22861da177e4SLinus Torvalds} 22871da177e4SLinus Torvalds 22881da177e4SLinus Torvaldssub push_parameter($$$) { 22891da177e4SLinus Torvalds my $param = shift; 22901da177e4SLinus Torvalds my $type = shift; 22911da177e4SLinus Torvalds my $file = shift; 22921da177e4SLinus Torvalds 22935f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 22945f8c7c98SRandy Dunlap ($param eq "}")) { 22955f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 22965f8c7c98SRandy Dunlap } 22975f8c7c98SRandy Dunlap 22985f8c7c98SRandy Dunlap $anon_struct_union = 0; 22991da177e4SLinus Torvalds my $param_name = $param; 23001da177e4SLinus Torvalds $param_name =~ s/\[.*//; 23011da177e4SLinus Torvalds 2302a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 23031da177e4SLinus Torvalds { 2304ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 2305a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 23061da177e4SLinus Torvalds } 2307ced69090SRandy Dunlap } 23081da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 23091da177e4SLinus Torvalds { 23101da177e4SLinus Torvalds $param="void"; 23111da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 23121da177e4SLinus Torvalds } 2313134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 2314134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 2315134fe01bSRandy Dunlap { 2316134fe01bSRandy Dunlap $type = $param; 2317134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 2318134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 23195f8c7c98SRandy Dunlap $anon_struct_union = 1; 2320134fe01bSRandy Dunlap } 2321134fe01bSRandy Dunlap 2322a6d3fe77SMartin Waitz # warn if parameter has no description 2323134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 2324134fe01bSRandy Dunlap # but inline preprocessor statements); 2325134fe01bSRandy Dunlap # also ignore unnamed structs/unions; 23265f8c7c98SRandy Dunlap if (!$anon_struct_union) { 2327a6d3fe77SMartin Waitz if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { 2328a6d3fe77SMartin Waitz 23291da177e4SLinus Torvalds $parameterdescs{$param_name} = $undescribed; 23301da177e4SLinus Torvalds 23311da177e4SLinus Torvalds if (($type eq 'function') || ($type eq 'enum')) { 2332d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Function parameter ". 23331da177e4SLinus Torvalds "or member '$param' not " . 23341da177e4SLinus Torvalds "described in '$declaration_name'\n"; 23351da177e4SLinus Torvalds } 2336d40e1e65SBart Van Assche print STDERR "${file}:$.: warning:" . 23371da177e4SLinus Torvalds " No description found for parameter '$param'\n"; 23381da177e4SLinus Torvalds ++$warnings; 23391da177e4SLinus Torvalds } 2340134fe01bSRandy Dunlap } 23411da177e4SLinus Torvalds 23422b35f4d9SRandy Dunlap $param = xml_escape($param); 23432b35f4d9SRandy Dunlap 234425985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 2345e34e7dbbSRandy Dunlap # on @parameterlist; 2346e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 2347e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 2348e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 2349e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 2350e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 2351e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 2352e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 23531da177e4SLinus Torvalds push @parameterlist, $param; 23541da177e4SLinus Torvalds $parametertypes{$param} = $type; 23551da177e4SLinus Torvalds} 23561da177e4SLinus Torvalds 2357a1d94aa5SRandy Dunlapsub check_sections($$$$$$) { 2358a1d94aa5SRandy Dunlap my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; 2359a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 2360a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 2361a1d94aa5SRandy Dunlap my $err; 2362a1d94aa5SRandy Dunlap my ($px, $sx); 2363a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 2364a1d94aa5SRandy Dunlap 2365a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 2366a1d94aa5SRandy Dunlap $err = 1; 2367a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 2368a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 2369a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 23701f3a6688SJohannes Berg $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 2371e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 2372e34e7dbbSRandy Dunlap # however, the original param string may contain 2373e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 2374e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 2375e34e7dbbSRandy Dunlap # parameter list is split at spaces; 2376e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 2377e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 2378e34e7dbbSRandy Dunlap 2379a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 2380a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 2381a1d94aa5SRandy Dunlap $err = 0; 2382a1d94aa5SRandy Dunlap last; 2383a1d94aa5SRandy Dunlap } 2384a1d94aa5SRandy Dunlap } 2385a1d94aa5SRandy Dunlap if ($err) { 2386a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 2387d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2388a1d94aa5SRandy Dunlap "Excess function parameter " . 2389a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2390a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2391a1d94aa5SRandy Dunlap ++$warnings; 2392a1d94aa5SRandy Dunlap } else { 2393a1d94aa5SRandy Dunlap if ($nested !~ m/\Q$sects[$sx]\E/) { 2394d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2395a1d94aa5SRandy Dunlap "Excess struct/union/enum/typedef member " . 2396a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2397a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2398a1d94aa5SRandy Dunlap ++$warnings; 2399a1d94aa5SRandy Dunlap } 2400a1d94aa5SRandy Dunlap } 2401a1d94aa5SRandy Dunlap } 2402a1d94aa5SRandy Dunlap } 2403a1d94aa5SRandy Dunlap} 2404a1d94aa5SRandy Dunlap 24051da177e4SLinus Torvalds## 24064092bac7SYacine Belkadi# Checks the section describing the return value of a function. 24074092bac7SYacine Belkadisub check_return_section { 24084092bac7SYacine Belkadi my $file = shift; 24094092bac7SYacine Belkadi my $declaration_name = shift; 24104092bac7SYacine Belkadi my $return_type = shift; 24114092bac7SYacine Belkadi 24124092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 24134092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 24144092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 24154092bac7SYacine Belkadi return; 24164092bac7SYacine Belkadi } 24174092bac7SYacine Belkadi 24184092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 24194092bac7SYacine Belkadi $sections{$section_return} eq "") { 2420d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 24214092bac7SYacine Belkadi "No description found for return value of " . 24224092bac7SYacine Belkadi "'$declaration_name'\n"; 24234092bac7SYacine Belkadi ++$warnings; 24244092bac7SYacine Belkadi } 24254092bac7SYacine Belkadi} 24264092bac7SYacine Belkadi 24274092bac7SYacine Belkadi## 24281da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 24291da177e4SLinus Torvalds# processed and spits out all the details stored in the global 24301da177e4SLinus Torvalds# arrays/hashes. 24311da177e4SLinus Torvaldssub dump_function($$) { 24321da177e4SLinus Torvalds my $prototype = shift; 24331da177e4SLinus Torvalds my $file = shift; 2434cbb4d3e6SHoria Geanta my $noret = 0; 24351da177e4SLinus Torvalds 24361da177e4SLinus Torvalds $prototype =~ s/^static +//; 24371da177e4SLinus Torvalds $prototype =~ s/^extern +//; 24384dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 24391da177e4SLinus Torvalds $prototype =~ s/^inline +//; 24401da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 244132e79401SRandy Dunlap $prototype =~ s/^__inline +//; 244232e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 244332e79401SRandy Dunlap $prototype =~ s/^noinline +//; 244474fc5c65SRandy Dunlap $prototype =~ s/__init +//; 244520072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 2446270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 244770c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 24480df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 2449cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 2450328d2440SRandy Dunlap $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; 24511da177e4SLinus Torvalds 24521da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 24531da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 24541da177e4SLinus Torvalds # 2. Function name 24551da177e4SLinus Torvalds # 3. Function parameters. 24561da177e4SLinus Torvalds # 24571da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 24581da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 24591da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 24601da177e4SLinus Torvalds # so on. 24611da177e4SLinus Torvalds # 24621da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 24631da177e4SLinus Torvalds # the following functions' documentation still comes out right: 24641da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 24651da177e4SLinus Torvalds # - atomic_set (macro) 24669598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 24671da177e4SLinus Torvalds 2468cbb4d3e6SHoria Geanta if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 2469cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 2470cbb4d3e6SHoria Geanta # list. 2471cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 2472cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 2473cbb4d3e6SHoria Geanta $return_type = $1; 2474cbb4d3e6SHoria Geanta $declaration_name = $2; 2475cbb4d3e6SHoria Geanta $noret = 1; 2476cbb4d3e6SHoria Geanta } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24771da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24781da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24791da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 248094b3e03cSRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24811da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24821da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24831da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24841da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24851da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24861da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24871da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24881da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24899598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24909598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2491412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2492412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 24931da177e4SLinus Torvalds $return_type = $1; 24941da177e4SLinus Torvalds $declaration_name = $2; 24951da177e4SLinus Torvalds my $args = $3; 24961da177e4SLinus Torvalds 24971da177e4SLinus Torvalds create_parameterlist($args, ',', $file); 24981da177e4SLinus Torvalds } else { 2499d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 25001da177e4SLinus Torvalds return; 25011da177e4SLinus Torvalds } 25021da177e4SLinus Torvalds 2503a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 2504a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); 2505a1d94aa5SRandy Dunlap 25064092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 25074092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 25084092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 25094092bac7SYacine Belkadi # verbose mode. 25104092bac7SYacine Belkadi # TODO: always perform the check. 2511cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 25124092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 25134092bac7SYacine Belkadi } 25144092bac7SYacine Belkadi 25151da177e4SLinus Torvalds output_declaration($declaration_name, 25161da177e4SLinus Torvalds 'function', 25171da177e4SLinus Torvalds {'function' => $declaration_name, 25181da177e4SLinus Torvalds 'module' => $modulename, 25191da177e4SLinus Torvalds 'functiontype' => $return_type, 25201da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 25211da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 25221da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 25231da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 25241da177e4SLinus Torvalds 'sections' => \%sections, 25251da177e4SLinus Torvalds 'purpose' => $declaration_purpose 25261da177e4SLinus Torvalds }); 25271da177e4SLinus Torvalds} 25281da177e4SLinus Torvalds 25291da177e4SLinus Torvaldssub reset_state { 25301da177e4SLinus Torvalds $function = ""; 25311da177e4SLinus Torvalds %constants = (); 25321da177e4SLinus Torvalds %parameterdescs = (); 25331da177e4SLinus Torvalds %parametertypes = (); 25341da177e4SLinus Torvalds @parameterlist = (); 25351da177e4SLinus Torvalds %sections = (); 25361da177e4SLinus Torvalds @sectionlist = (); 2537a1d94aa5SRandy Dunlap $sectcheck = ""; 2538a1d94aa5SRandy Dunlap $struct_actual = ""; 25391da177e4SLinus Torvalds $prototype = ""; 25401da177e4SLinus Torvalds 254148af606aSJani Nikula $state = STATE_NORMAL; 254248af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 25431da177e4SLinus Torvalds} 25441da177e4SLinus Torvalds 254556afb0f8SJason Baronsub tracepoint_munge($) { 254656afb0f8SJason Baron my $file = shift; 254756afb0f8SJason Baron my $tracepointname = 0; 254856afb0f8SJason Baron my $tracepointargs = 0; 254956afb0f8SJason Baron 255056afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 255156afb0f8SJason Baron $tracepointname = $1; 255256afb0f8SJason Baron } 25533a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 25543a9089fdSJason Baron $tracepointname = $1; 25553a9089fdSJason Baron } 25563a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 25573a9089fdSJason Baron $tracepointname = $2; 25583a9089fdSJason Baron } 25593a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 256056afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 256156afb0f8SJason Baron $tracepointargs = $1; 256256afb0f8SJason Baron } 256356afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 2564d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 256556afb0f8SJason Baron "$prototype\n"; 256656afb0f8SJason Baron } else { 256756afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 256856afb0f8SJason Baron } 256956afb0f8SJason Baron} 257056afb0f8SJason Baron 2571b4870bc5SRandy Dunlapsub syscall_munge() { 2572b4870bc5SRandy Dunlap my $void = 0; 2573b4870bc5SRandy Dunlap 2574b4870bc5SRandy Dunlap $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs 2575b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 2576b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 2577b4870bc5SRandy Dunlap $void = 1; 2578b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 2579b4870bc5SRandy Dunlap } 2580b4870bc5SRandy Dunlap 2581b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 2582b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 2583b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 2584b4870bc5SRandy Dunlap } elsif ($void) { 2585b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 2586b4870bc5SRandy Dunlap } 2587b4870bc5SRandy Dunlap 2588b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 2589b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 2590b4870bc5SRandy Dunlap my $count = 0; 2591b4870bc5SRandy Dunlap my $len = length($prototype); 2592b4870bc5SRandy Dunlap if ($void) { 2593b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 2594b4870bc5SRandy Dunlap } 2595b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 2596b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 2597b4870bc5SRandy Dunlap $count++; 2598b4870bc5SRandy Dunlap if ($count % 2 == 1) { 2599b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 2600b4870bc5SRandy Dunlap } 2601b4870bc5SRandy Dunlap } 2602b4870bc5SRandy Dunlap } 2603b4870bc5SRandy Dunlap} 2604b4870bc5SRandy Dunlap 26051da177e4SLinus Torvaldssub process_state3_function($$) { 26061da177e4SLinus Torvalds my $x = shift; 26071da177e4SLinus Torvalds my $file = shift; 26081da177e4SLinus Torvalds 260951f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 261051f5a0c8SRandy Dunlap 2611890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 26121da177e4SLinus Torvalds # do nothing 26131da177e4SLinus Torvalds } 26141da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 26151da177e4SLinus Torvalds $prototype .= $1; 26161da177e4SLinus Torvalds } 2617b4870bc5SRandy Dunlap 2618890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 26191da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 26201da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 26211da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 2622b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 2623b4870bc5SRandy Dunlap syscall_munge(); 2624b4870bc5SRandy Dunlap } 26253a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 26263a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 26273a9089fdSJason Baron { 262856afb0f8SJason Baron tracepoint_munge($file); 262956afb0f8SJason Baron } 26301da177e4SLinus Torvalds dump_function($prototype, $file); 26311da177e4SLinus Torvalds reset_state(); 26321da177e4SLinus Torvalds } 26331da177e4SLinus Torvalds} 26341da177e4SLinus Torvalds 26351da177e4SLinus Torvaldssub process_state3_type($$) { 26361da177e4SLinus Torvalds my $x = shift; 26371da177e4SLinus Torvalds my $file = shift; 26381da177e4SLinus Torvalds 26391da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 26401da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 26411da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 264251f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 264351f5a0c8SRandy Dunlap 26441da177e4SLinus Torvalds if ($x =~ /^#/) { 26451da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 26461da177e4SLinus Torvalds $x .= ";"; 26471da177e4SLinus Torvalds } 26481da177e4SLinus Torvalds 26491da177e4SLinus Torvalds while (1) { 26501da177e4SLinus Torvalds if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 26511da177e4SLinus Torvalds $prototype .= $1 . $2; 26521da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 26531da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 26541da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 26551da177e4SLinus Torvalds dump_declaration($prototype, $file); 26561da177e4SLinus Torvalds reset_state(); 26571da177e4SLinus Torvalds last; 26581da177e4SLinus Torvalds } 26591da177e4SLinus Torvalds $x = $3; 26601da177e4SLinus Torvalds } else { 26611da177e4SLinus Torvalds $prototype .= $x; 26621da177e4SLinus Torvalds last; 26631da177e4SLinus Torvalds } 26641da177e4SLinus Torvalds } 26651da177e4SLinus Torvalds} 26661da177e4SLinus Torvalds 26676b5b55f6SRandy Dunlap# xml_escape: replace <, >, and & in the text stream; 26686b5b55f6SRandy Dunlap# 26696b5b55f6SRandy Dunlap# however, formatting controls that are generated internally/locally in the 26706b5b55f6SRandy Dunlap# kernel-doc script are not escaped here; instead, they begin life like 26716b5b55f6SRandy Dunlap# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings 26726b5b55f6SRandy Dunlap# are converted to their mnemonic-expected output, without the 4 * '\' & ':', 26736b5b55f6SRandy Dunlap# just before actual output; (this is done by local_unescape()) 26741da177e4SLinus Torvaldssub xml_escape($) { 26751da177e4SLinus Torvalds my $text = shift; 2676ecfb251aSRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 2677ecfb251aSRandy Dunlap return $text; 2678ecfb251aSRandy Dunlap } 26791da177e4SLinus Torvalds $text =~ s/\&/\\\\\\amp;/g; 26801da177e4SLinus Torvalds $text =~ s/\</\\\\\\lt;/g; 26811da177e4SLinus Torvalds $text =~ s/\>/\\\\\\gt;/g; 26821da177e4SLinus Torvalds return $text; 26831da177e4SLinus Torvalds} 26841da177e4SLinus Torvalds 2685c0d1b6eeSJonathan Corbet# xml_unescape: reverse the effects of xml_escape 2686c0d1b6eeSJonathan Corbetsub xml_unescape($) { 2687c0d1b6eeSJonathan Corbet my $text = shift; 2688c0d1b6eeSJonathan Corbet if (($output_mode eq "text") || ($output_mode eq "man")) { 2689c0d1b6eeSJonathan Corbet return $text; 2690c0d1b6eeSJonathan Corbet } 2691c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\amp;/\&/g; 2692c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\lt;/</g; 2693c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\gt;/>/g; 2694c0d1b6eeSJonathan Corbet return $text; 2695c0d1b6eeSJonathan Corbet} 2696c0d1b6eeSJonathan Corbet 26976b5b55f6SRandy Dunlap# convert local escape strings to html 26986b5b55f6SRandy Dunlap# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) 26996b5b55f6SRandy Dunlapsub local_unescape($) { 27006b5b55f6SRandy Dunlap my $text = shift; 27016b5b55f6SRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 27026b5b55f6SRandy Dunlap return $text; 27036b5b55f6SRandy Dunlap } 27046b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\lt:/</g; 27056b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\gt:/>/g; 27066b5b55f6SRandy Dunlap return $text; 27076b5b55f6SRandy Dunlap} 27086b5b55f6SRandy Dunlap 27091da177e4SLinus Torvaldssub process_file($) { 27102283a117SRandy Dunlap my $file; 27111da177e4SLinus Torvalds my $identifier; 27121da177e4SLinus Torvalds my $func; 2713a21217daSRandy Dunlap my $descr; 27146423133bSJohannes Weiner my $in_purpose = 0; 27151da177e4SLinus Torvalds my $initial_section_counter = $section_counter; 271668f86662SBen Hutchings my ($orig_file) = @_; 27171da177e4SLinus Torvalds 27182283a117SRandy Dunlap if (defined($ENV{'SRCTREE'})) { 271968f86662SBen Hutchings $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 27202283a117SRandy Dunlap } 27212283a117SRandy Dunlap else { 272268f86662SBen Hutchings $file = $orig_file; 27232283a117SRandy Dunlap } 27241da177e4SLinus Torvalds if (defined($source_map{$file})) { 27251da177e4SLinus Torvalds $file = $source_map{$file}; 27261da177e4SLinus Torvalds } 27271da177e4SLinus Torvalds 27281da177e4SLinus Torvalds if (!open(IN,"<$file")) { 27291da177e4SLinus Torvalds print STDERR "Error: Cannot open file $file\n"; 27301da177e4SLinus Torvalds ++$errors; 27311da177e4SLinus Torvalds return; 27321da177e4SLinus Torvalds } 27331da177e4SLinus Torvalds 273486ae2e38SJani Nikula # two passes for -export and -internal 2735b6c3f456SJani Nikula if ($output_selection == OUTPUT_EXPORTED || 2736b6c3f456SJani Nikula $output_selection == OUTPUT_INTERNAL) { 273786ae2e38SJani Nikula while (<IN>) { 273886ae2e38SJani Nikula if (/$export_symbol/o) { 273986ae2e38SJani Nikula $function_table{$2} = 1; 274086ae2e38SJani Nikula } 274186ae2e38SJani Nikula } 274286ae2e38SJani Nikula seek(IN, 0, 0); 274386ae2e38SJani Nikula } 274486ae2e38SJani Nikula 2745a9e7314bSIlya Dryomov $. = 1; 2746a9e7314bSIlya Dryomov 27471da177e4SLinus Torvalds $section_counter = 0; 27481da177e4SLinus Torvalds while (<IN>) { 274965478428SDaniel Santos while (s/\\\s*$//) { 275065478428SDaniel Santos $_ .= <IN>; 275165478428SDaniel Santos } 275248af606aSJani Nikula if ($state == STATE_NORMAL) { 27531da177e4SLinus Torvalds if (/$doc_start/o) { 275448af606aSJani Nikula $state = STATE_NAME; # next line is always the function name 2755850622dfSRandy Dunlap $in_doc_sect = 0; 27561da177e4SLinus Torvalds } 275748af606aSJani Nikula } elsif ($state == STATE_NAME) {# this line is the function name (always) 27581da177e4SLinus Torvalds if (/$doc_block/o) { 275948af606aSJani Nikula $state = STATE_DOCBLOCK; 27601da177e4SLinus Torvalds $contents = ""; 27611da177e4SLinus Torvalds if ( $1 eq "" ) { 27621da177e4SLinus Torvalds $section = $section_intro; 27631da177e4SLinus Torvalds } else { 27641da177e4SLinus Torvalds $section = $1; 27651da177e4SLinus Torvalds } 27661da177e4SLinus Torvalds } 27671da177e4SLinus Torvalds elsif (/$doc_decl/o) { 27681da177e4SLinus Torvalds $identifier = $1; 27691da177e4SLinus Torvalds if (/\s*([\w\s]+?)\s*-/) { 27701da177e4SLinus Torvalds $identifier = $1; 27711da177e4SLinus Torvalds } 27721da177e4SLinus Torvalds 277348af606aSJani Nikula $state = STATE_FIELD; 27741da177e4SLinus Torvalds if (/-(.*)/) { 277551f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2776a21217daSRandy Dunlap $descr= $1; 2777a21217daSRandy Dunlap $descr =~ s/^\s*//; 2778a21217daSRandy Dunlap $descr =~ s/\s*$//; 277912ae6779SDaniel Santos $descr =~ s/\s+/ /g; 2780a21217daSRandy Dunlap $declaration_purpose = xml_escape($descr); 27816423133bSJohannes Weiner $in_purpose = 1; 27821da177e4SLinus Torvalds } else { 27831da177e4SLinus Torvalds $declaration_purpose = ""; 27841da177e4SLinus Torvalds } 278577cc23b8SRandy Dunlap 278677cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 2787d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 278877cc23b8SRandy Dunlap print STDERR $_; 278977cc23b8SRandy Dunlap ++$warnings; 279077cc23b8SRandy Dunlap } 279177cc23b8SRandy Dunlap 27921da177e4SLinus Torvalds if ($identifier =~ m/^struct/) { 27931da177e4SLinus Torvalds $decl_type = 'struct'; 27941da177e4SLinus Torvalds } elsif ($identifier =~ m/^union/) { 27951da177e4SLinus Torvalds $decl_type = 'union'; 27961da177e4SLinus Torvalds } elsif ($identifier =~ m/^enum/) { 27971da177e4SLinus Torvalds $decl_type = 'enum'; 27981da177e4SLinus Torvalds } elsif ($identifier =~ m/^typedef/) { 27991da177e4SLinus Torvalds $decl_type = 'typedef'; 28001da177e4SLinus Torvalds } else { 28011da177e4SLinus Torvalds $decl_type = 'function'; 28021da177e4SLinus Torvalds } 28031da177e4SLinus Torvalds 28041da177e4SLinus Torvalds if ($verbose) { 2805d40e1e65SBart Van Assche print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; 28061da177e4SLinus Torvalds } 28071da177e4SLinus Torvalds } else { 2808d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 28091da177e4SLinus Torvalds " - I thought it was a doc line\n"; 28101da177e4SLinus Torvalds ++$warnings; 281148af606aSJani Nikula $state = STATE_NORMAL; 28121da177e4SLinus Torvalds } 281348af606aSJani Nikula } elsif ($state == STATE_FIELD) { # look for head: lines, and include content 28141da177e4SLinus Torvalds if (/$doc_sect/o) { 28151da177e4SLinus Torvalds $newsection = $1; 28161da177e4SLinus Torvalds $newcontents = $2; 28171da177e4SLinus Torvalds 2818792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 2819850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 2820d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: contents before sections\n"; 2821850622dfSRandy Dunlap ++$warnings; 2822850622dfSRandy Dunlap } 282394dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 28241da177e4SLinus Torvalds $section = $section_default; 28251da177e4SLinus Torvalds } 28261da177e4SLinus Torvalds 2827850622dfSRandy Dunlap $in_doc_sect = 1; 28286423133bSJohannes Weiner $in_purpose = 0; 28291da177e4SLinus Torvalds $contents = $newcontents; 28301da177e4SLinus Torvalds if ($contents ne "") { 283127205744SRandy Dunlap while ((substr($contents, 0, 1) eq " ") || 283227205744SRandy Dunlap substr($contents, 0, 1) eq "\t") { 283305189497SRandy Dunlap $contents = substr($contents, 1); 283405189497SRandy Dunlap } 28351da177e4SLinus Torvalds $contents .= "\n"; 28361da177e4SLinus Torvalds } 28371da177e4SLinus Torvalds $section = $newsection; 28381da177e4SLinus Torvalds } elsif (/$doc_end/) { 28394c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 284094dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 28411da177e4SLinus Torvalds $section = $section_default; 28421da177e4SLinus Torvalds $contents = ""; 28431da177e4SLinus Torvalds } 284446b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 284546b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2846d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: suspicious ending line: $_"; 284746b958ebSRandy Dunlap ++$warnings; 284846b958ebSRandy Dunlap } 28491da177e4SLinus Torvalds 28501da177e4SLinus Torvalds $prototype = ""; 285148af606aSJani Nikula $state = STATE_PROTO; 28521da177e4SLinus Torvalds $brcount = 0; 28531da177e4SLinus Torvalds# print STDERR "end of doc comment, looking for prototype\n"; 28541da177e4SLinus Torvalds } elsif (/$doc_content/) { 28551da177e4SLinus Torvalds # miguel-style comment kludge, look for blank lines after 28561da177e4SLinus Torvalds # @parameter line to signify start of description 28576423133bSJohannes Weiner if ($1 eq "") { 28586423133bSJohannes Weiner if ($section =~ m/^@/ || $section eq $section_context) { 285994dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 28601da177e4SLinus Torvalds $section = $section_default; 28611da177e4SLinus Torvalds $contents = ""; 28621da177e4SLinus Torvalds } else { 28636423133bSJohannes Weiner $contents .= "\n"; 28646423133bSJohannes Weiner } 28656423133bSJohannes Weiner $in_purpose = 0; 28666423133bSJohannes Weiner } elsif ($in_purpose == 1) { 28676423133bSJohannes Weiner # Continued declaration purpose 28686423133bSJohannes Weiner chomp($declaration_purpose); 28696423133bSJohannes Weiner $declaration_purpose .= " " . xml_escape($1); 287012ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 28716423133bSJohannes Weiner } else { 28721da177e4SLinus Torvalds $contents .= $1 . "\n"; 28731da177e4SLinus Torvalds } 28741da177e4SLinus Torvalds } else { 28751da177e4SLinus Torvalds # i dont know - bad line? ignore. 2876d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: bad line: $_"; 28771da177e4SLinus Torvalds ++$warnings; 28781da177e4SLinus Torvalds } 287948af606aSJani Nikula } elsif ($state == STATE_INLINE) { # scanning for inline parameters 2880a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 288148af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 2882a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 2883a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 2884a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 2885a4c6ebedSDanilo Cesar Lemes de Paula while ((substr($contents, 0, 1) eq " ") || 2886a4c6ebedSDanilo Cesar Lemes de Paula substr($contents, 0, 1) eq "\t") { 2887a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 2888a4c6ebedSDanilo Cesar Lemes de Paula } 2889a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 2890a4c6ebedSDanilo Cesar Lemes de Paula } 289148af606aSJani Nikula $inline_doc_state = STATE_INLINE_TEXT; 2892a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 289348af606aSJani Nikula } elsif (/$doc_inline_end/) { 2894a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 2895a4c6ebedSDanilo Cesar Lemes de Paula dump_section($file, $section, xml_escape($contents)); 2896a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 2897a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 2898a4c6ebedSDanilo Cesar Lemes de Paula } 289948af606aSJani Nikula $state = STATE_PROTO; 290048af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 2901a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 2902a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 290348af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_TEXT) { 2904a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 290548af606aSJani Nikula } elsif ($inline_doc_state == STATE_INLINE_NAME) { 290648af606aSJani Nikula $inline_doc_state = STATE_INLINE_ERROR; 2907a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Warning(${file}:$.): "; 2908a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Incorrect use of kernel-doc format: $_"; 2909a4c6ebedSDanilo Cesar Lemes de Paula ++$warnings; 2910a4c6ebedSDanilo Cesar Lemes de Paula } 2911a4c6ebedSDanilo Cesar Lemes de Paula } 291248af606aSJani Nikula } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype) 291348af606aSJani Nikula if (/$doc_inline_start/) { 291448af606aSJani Nikula $state = STATE_INLINE; 291548af606aSJani Nikula $inline_doc_state = STATE_INLINE_NAME; 2916a4c6ebedSDanilo Cesar Lemes de Paula } elsif ($decl_type eq 'function') { 29171da177e4SLinus Torvalds process_state3_function($_, $file); 29181da177e4SLinus Torvalds } else { 29191da177e4SLinus Torvalds process_state3_type($_, $file); 29201da177e4SLinus Torvalds } 292148af606aSJani Nikula } elsif ($state == STATE_DOCBLOCK) { 29221da177e4SLinus Torvalds # Documentation block 29231da177e4SLinus Torvalds if (/$doc_block/) { 292494dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 29251da177e4SLinus Torvalds $contents = ""; 29261da177e4SLinus Torvalds $function = ""; 29271da177e4SLinus Torvalds %constants = (); 29281da177e4SLinus Torvalds %parameterdescs = (); 29291da177e4SLinus Torvalds %parametertypes = (); 29301da177e4SLinus Torvalds @parameterlist = (); 29311da177e4SLinus Torvalds %sections = (); 29321da177e4SLinus Torvalds @sectionlist = (); 29331da177e4SLinus Torvalds $prototype = ""; 29341da177e4SLinus Torvalds if ( $1 eq "" ) { 29351da177e4SLinus Torvalds $section = $section_intro; 29361da177e4SLinus Torvalds } else { 29371da177e4SLinus Torvalds $section = $1; 29381da177e4SLinus Torvalds } 29391da177e4SLinus Torvalds } 29401da177e4SLinus Torvalds elsif (/$doc_end/) 29411da177e4SLinus Torvalds { 294294dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 29431da177e4SLinus Torvalds $contents = ""; 29441da177e4SLinus Torvalds $function = ""; 29451da177e4SLinus Torvalds %constants = (); 29461da177e4SLinus Torvalds %parameterdescs = (); 29471da177e4SLinus Torvalds %parametertypes = (); 29481da177e4SLinus Torvalds @parameterlist = (); 29491da177e4SLinus Torvalds %sections = (); 29501da177e4SLinus Torvalds @sectionlist = (); 29511da177e4SLinus Torvalds $prototype = ""; 295248af606aSJani Nikula $state = STATE_NORMAL; 29531da177e4SLinus Torvalds } 29541da177e4SLinus Torvalds elsif (/$doc_content/) 29551da177e4SLinus Torvalds { 29561da177e4SLinus Torvalds if ( $1 eq "" ) 29571da177e4SLinus Torvalds { 29581da177e4SLinus Torvalds $contents .= $blankline; 29591da177e4SLinus Torvalds } 29601da177e4SLinus Torvalds else 29611da177e4SLinus Torvalds { 29621da177e4SLinus Torvalds $contents .= $1 . "\n"; 29631da177e4SLinus Torvalds } 29641da177e4SLinus Torvalds } 29651da177e4SLinus Torvalds } 29661da177e4SLinus Torvalds } 29671da177e4SLinus Torvalds if ($initial_section_counter == $section_counter) { 2968d40e1e65SBart Van Assche print STDERR "${file}:1: warning: no structured comments found\n"; 2969b6c3f456SJani Nikula if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) { 2970e946c43aSJohannes Berg print STDERR " Was looking for '$_'.\n" for keys %function_table; 2971e946c43aSJohannes Berg } 29721da177e4SLinus Torvalds if ($output_mode eq "xml") { 29731da177e4SLinus Torvalds # The template wants at least one RefEntry here; make one. 29741da177e4SLinus Torvalds print "<refentry>\n"; 29751da177e4SLinus Torvalds print " <refnamediv>\n"; 29761da177e4SLinus Torvalds print " <refname>\n"; 297768f86662SBen Hutchings print " ${orig_file}\n"; 29781da177e4SLinus Torvalds print " </refname>\n"; 29791da177e4SLinus Torvalds print " <refpurpose>\n"; 29801da177e4SLinus Torvalds print " Document generation inconsistency\n"; 29811da177e4SLinus Torvalds print " </refpurpose>\n"; 29821da177e4SLinus Torvalds print " </refnamediv>\n"; 29831da177e4SLinus Torvalds print " <refsect1>\n"; 29841da177e4SLinus Torvalds print " <title>\n"; 29851da177e4SLinus Torvalds print " Oops\n"; 29861da177e4SLinus Torvalds print " </title>\n"; 29871da177e4SLinus Torvalds print " <warning>\n"; 29881da177e4SLinus Torvalds print " <para>\n"; 29891da177e4SLinus Torvalds print " The template for this document tried to insert\n"; 29901da177e4SLinus Torvalds print " the structured comment from the file\n"; 299168f86662SBen Hutchings print " <filename>${orig_file}</filename> at this point,\n"; 29921da177e4SLinus Torvalds print " but none was found.\n"; 29931da177e4SLinus Torvalds print " This dummy section is inserted to allow\n"; 29941da177e4SLinus Torvalds print " generation to continue.\n"; 29951da177e4SLinus Torvalds print " </para>\n"; 29961da177e4SLinus Torvalds print " </warning>\n"; 29971da177e4SLinus Torvalds print " </refsect1>\n"; 29981da177e4SLinus Torvalds print "</refentry>\n"; 29991da177e4SLinus Torvalds } 30001da177e4SLinus Torvalds } 30011da177e4SLinus Torvalds} 30028484baaaSRandy Dunlap 30038484baaaSRandy Dunlap 30048484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 30058484baaaSRandy Dunlap 30068484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 30078484baaaSRandy Dunlap# using the s// operator. 30081ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 30094d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 30104d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 30114d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 30124d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 30138484baaaSRandy Dunlap} 30148484baaaSRandy Dunlap 30158484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 30168484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 30178484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 30188484baaaSRandy Dunlap my ($relname, $absname); 30198484baaaSRandy Dunlap while(<SOURCE_MAP>) { 30208484baaaSRandy Dunlap chop(); 30218484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 30228484baaaSRandy Dunlap $relname =~ s:^/+::; 30238484baaaSRandy Dunlap $source_map{$relname} = $absname; 30248484baaaSRandy Dunlap } 30258484baaaSRandy Dunlap close(SOURCE_MAP); 30268484baaaSRandy Dunlap} 30278484baaaSRandy Dunlap 30288484baaaSRandy Dunlapforeach (@ARGV) { 30298484baaaSRandy Dunlap chomp; 30308484baaaSRandy Dunlap process_file($_); 30318484baaaSRandy Dunlap} 30328484baaaSRandy Dunlapif ($verbose && $errors) { 30338484baaaSRandy Dunlap print STDERR "$errors errors\n"; 30348484baaaSRandy Dunlap} 30358484baaaSRandy Dunlapif ($verbose && $warnings) { 30368484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 30378484baaaSRandy Dunlap} 30388484baaaSRandy Dunlap 30398484baaaSRandy Dunlapexit($errors); 3040