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]+)'; 2151da177e4SLinus Torvalds 2161da177e4SLinus Torvalds# Output conversion substitutions. 2171da177e4SLinus Torvalds# One for each output format 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds# these work fairly well 2204d732701SDanilo Cesar Lemes de Paulamy @highlights_html = ( 2214d732701SDanilo Cesar Lemes de Paula [$type_constant, "<i>\$1</i>"], 2224d732701SDanilo Cesar Lemes de Paula [$type_func, "<b>\$1</b>"], 2234d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<i>\$1</i>"], 2244d732701SDanilo Cesar Lemes de Paula [$type_env, "<b><i>\$1</i></b>"], 2254d732701SDanilo Cesar Lemes de Paula [$type_param, "<tt><b>\$1</b></tt>"] 2264d732701SDanilo Cesar Lemes de Paula ); 2276b5b55f6SRandy Dunlapmy $local_lt = "\\\\\\\\lt:"; 2286b5b55f6SRandy Dunlapmy $local_gt = "\\\\\\\\gt:"; 2296b5b55f6SRandy Dunlapmy $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" 2301da177e4SLinus Torvalds 2311b40c194SDan Luedtke# html version 5 2324d732701SDanilo Cesar Lemes de Paulamy @highlights_html5 = ( 2334d732701SDanilo Cesar Lemes de Paula [$type_constant, "<span class=\"const\">\$1</span>"], 2344d732701SDanilo Cesar Lemes de Paula [$type_func, "<span class=\"func\">\$1</span>"], 2354d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<span class=\"struct\">\$1</span>"], 2364d732701SDanilo Cesar Lemes de Paula [$type_env, "<span class=\"env\">\$1</span>"], 2374d732701SDanilo Cesar Lemes de Paula [$type_param, "<span class=\"param\">\$1</span>]"] 2384d732701SDanilo Cesar Lemes de Paula ); 2391b40c194SDan Luedtkemy $blankline_html5 = $local_lt . "br /" . $local_gt; 2401b40c194SDan Luedtke 2411da177e4SLinus Torvalds# XML, docbook format 2424d732701SDanilo Cesar Lemes de Paulamy @highlights_xml = ( 2434d732701SDanilo Cesar Lemes de Paula ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"], 2444d732701SDanilo Cesar Lemes de Paula [$type_constant, "<constant>\$1</constant>"], 2454d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<structname>\$1</structname>"], 2464d732701SDanilo Cesar Lemes de Paula [$type_param, "<parameter>\$1</parameter>"], 2474d732701SDanilo Cesar Lemes de Paula [$type_func, "<function>\$1</function>"], 2484d732701SDanilo Cesar Lemes de Paula [$type_env, "<envar>\$1</envar>"] 2494d732701SDanilo Cesar Lemes de Paula ); 2505c98fc03SJohannes Bergmy $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; 2511da177e4SLinus Torvalds 2521da177e4SLinus Torvalds# gnome, docbook format 2534d732701SDanilo Cesar Lemes de Paulamy @highlights_gnome = ( 2544d732701SDanilo Cesar Lemes de Paula [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"], 2554d732701SDanilo Cesar Lemes de Paula [$type_func, "<function>\$1</function>"], 2564d732701SDanilo Cesar Lemes de Paula [$type_struct, "<structname>\$1</structname>"], 2574d732701SDanilo Cesar Lemes de Paula [$type_env, "<envar>\$1</envar>"], 2584d732701SDanilo Cesar Lemes de Paula [$type_param, "<parameter>\$1</parameter>" ] 2594d732701SDanilo Cesar Lemes de Paula ); 2601da177e4SLinus Torvaldsmy $blankline_gnome = "</para><para>\n"; 2611da177e4SLinus Torvalds 2621da177e4SLinus Torvalds# these are pretty rough 2634d732701SDanilo Cesar Lemes de Paulamy @highlights_man = ( 2644d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 2654d732701SDanilo Cesar Lemes de Paula [$type_func, "\\\\fB\$1\\\\fP"], 2664d732701SDanilo Cesar Lemes de Paula [$type_struct, "\\\\fI\$1\\\\fP"], 2674d732701SDanilo Cesar Lemes de Paula [$type_param, "\\\\fI\$1\\\\fP"] 2684d732701SDanilo Cesar Lemes de Paula ); 2691da177e4SLinus Torvaldsmy $blankline_man = ""; 2701da177e4SLinus Torvalds 2711da177e4SLinus Torvalds# text-mode 2724d732701SDanilo Cesar Lemes de Paulamy @highlights_text = ( 2734d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 2744d732701SDanilo Cesar Lemes de Paula [$type_func, "\$1"], 2754d732701SDanilo Cesar Lemes de Paula [$type_struct, "\$1"], 2764d732701SDanilo Cesar Lemes de Paula [$type_param, "\$1"] 2774d732701SDanilo Cesar Lemes de Paula ); 2781da177e4SLinus Torvaldsmy $blankline_text = ""; 2791da177e4SLinus Torvalds 280c0d1b6eeSJonathan Corbet# rst-mode 281c0d1b6eeSJonathan Corbetmy @highlights_rst = ( 282c0d1b6eeSJonathan Corbet [$type_constant, "``\$1``"], 283*a19bce64SJani Nikula [$type_func, "\\:c\\:func\\:`\$1()`"], 28462850976SJani Nikula [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 28562850976SJani Nikula [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 28662850976SJani Nikula [$type_struct, "\\:c\\:type\\:`struct \$1 <\$1>`"], 287c0d1b6eeSJonathan Corbet [$type_param, "**\$1**"] 288c0d1b6eeSJonathan Corbet ); 289c0d1b6eeSJonathan Corbetmy $blankline_rst = "\n"; 290c0d1b6eeSJonathan Corbet 291eda603f6SJohannes Berg# list mode 2924d732701SDanilo Cesar Lemes de Paulamy @highlights_list = ( 2934d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 2944d732701SDanilo Cesar Lemes de Paula [$type_func, "\$1"], 2954d732701SDanilo Cesar Lemes de Paula [$type_struct, "\$1"], 2964d732701SDanilo Cesar Lemes de Paula [$type_param, "\$1"] 2974d732701SDanilo Cesar Lemes de Paula ); 298eda603f6SJohannes Bergmy $blankline_list = ""; 2991da177e4SLinus Torvalds 3001da177e4SLinus Torvalds# read arguments 3011da177e4SLinus Torvaldsif ($#ARGV == -1) { 3021da177e4SLinus Torvalds usage(); 3031da177e4SLinus Torvalds} 3041da177e4SLinus Torvalds 3058484baaaSRandy Dunlapmy $kernelversion; 3068484baaaSRandy Dunlapmy $dohighlight = ""; 3078484baaaSRandy Dunlap 3081da177e4SLinus Torvaldsmy $verbose = 0; 3091da177e4SLinus Torvaldsmy $output_mode = "man"; 310e314ba31SDaniel Santosmy $output_preformatted = 0; 3114b44595aSJohannes Bergmy $no_doc_sections = 0; 3124d732701SDanilo Cesar Lemes de Paulamy @highlights = @highlights_man; 3131da177e4SLinus Torvaldsmy $blankline = $blankline_man; 3141da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 315b6c3f456SJani Nikula 316b6c3f456SJani Nikulause constant { 317b6c3f456SJani Nikula OUTPUT_ALL => 0, # output all symbols and doc sections 318b6c3f456SJani Nikula OUTPUT_INCLUDE => 1, # output only specified symbols 319b6c3f456SJani Nikula OUTPUT_EXCLUDE => 2, # output everything except specified symbols 320b6c3f456SJani Nikula OUTPUT_EXPORTED => 3, # output exported symbols 321b6c3f456SJani Nikula OUTPUT_INTERNAL => 4, # output non-exported symbols 322b6c3f456SJani Nikula}; 323b6c3f456SJani Nikulamy $output_selection = OUTPUT_ALL; 324b2c4105bSBen Hutchingsmy $show_not_found = 0; 325b2c4105bSBen Hutchings 326b2c4105bSBen Hutchingsmy @build_time; 327b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 328b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 329b2c4105bSBen Hutchings @build_time = gmtime($seconds); 330b2c4105bSBen Hutchings} else { 331b2c4105bSBen Hutchings @build_time = localtime; 332b2c4105bSBen Hutchings} 333b2c4105bSBen Hutchings 3341da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 3351da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 336b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 337b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 3381da177e4SLinus Torvalds 3398484baaaSRandy Dunlap# Essentially these are globals. 340b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 341b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 3421da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 3431da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 3441da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 3451c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 3461da177e4SLinus Torvalds 347bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 348bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 349bd0e88e5SRandy Dunlap} 350bd0e88e5SRandy Dunlap 3511da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 3521da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 3531da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 3541da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 3551da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 3561da177e4SLinus Torvalds# into html. 3571da177e4SLinus Torvaldsmy $section_counter = 0; 3581da177e4SLinus Torvalds 3591da177e4SLinus Torvaldsmy $lineprefix=""; 3601da177e4SLinus Torvalds 36148af606aSJani Nikula# Parser states 36248af606aSJani Nikulause constant { 36348af606aSJani Nikula STATE_NORMAL => 0, # normal code 36448af606aSJani Nikula STATE_NAME => 1, # looking for function name 36548af606aSJani Nikula STATE_FIELD => 2, # scanning field start 36648af606aSJani Nikula STATE_PROTO => 3, # scanning prototype 36748af606aSJani Nikula STATE_DOCBLOCK => 4, # documentation block 36848af606aSJani Nikula STATE_INLINE => 5, # gathering documentation outside main block 36948af606aSJani Nikula}; 3701da177e4SLinus Torvaldsmy $state; 371850622dfSRandy Dunlapmy $in_doc_sect; 3721da177e4SLinus Torvalds 37348af606aSJani Nikula# Inline documentation state 37448af606aSJani Nikulause constant { 37548af606aSJani Nikula STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 37648af606aSJani Nikula STATE_INLINE_NAME => 1, # looking for member name (@foo:) 37748af606aSJani Nikula STATE_INLINE_TEXT => 2, # looking for member documentation 37848af606aSJani Nikula STATE_INLINE_END => 3, # done 37948af606aSJani Nikula STATE_INLINE_ERROR => 4, # error - Comment without header was found. 38048af606aSJani Nikula # Spit a warning as it's not 381a4c6ebedSDanilo Cesar Lemes de Paula # proper kernel-doc and ignore the rest. 38248af606aSJani Nikula}; 38348af606aSJani Nikulamy $inline_doc_state; 384a4c6ebedSDanilo Cesar Lemes de Paula 3851da177e4SLinus Torvalds#declaration types: can be 3861da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 3871da177e4SLinus Torvaldsmy $decl_type; 3881da177e4SLinus Torvalds 3891da177e4SLinus Torvaldsmy $doc_special = "\@\%\$\&"; 3901da177e4SLinus Torvalds 3911da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 3921da177e4SLinus Torvaldsmy $doc_end = '\*/'; 3931da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 39412ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 3951da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 396891dcd2fSRandy Dunlapmy $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)'; 39712ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 3981da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 39948af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$'; 40048af606aSJani Nikulamy $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)'; 40148af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$'; 40286ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 4031da177e4SLinus Torvalds 4041da177e4SLinus Torvaldsmy %constants; 4051da177e4SLinus Torvaldsmy %parameterdescs; 4061da177e4SLinus Torvaldsmy @parameterlist; 4071da177e4SLinus Torvaldsmy %sections; 4081da177e4SLinus Torvaldsmy @sectionlist; 409a1d94aa5SRandy Dunlapmy $sectcheck; 410a1d94aa5SRandy Dunlapmy $struct_actual; 4111da177e4SLinus Torvalds 4121da177e4SLinus Torvaldsmy $contents = ""; 4131da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 4141da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 4151da177e4SLinus Torvaldsmy $section = $section_default; 4161da177e4SLinus Torvaldsmy $section_context = "Context"; 4174092bac7SYacine Belkadimy $section_return = "Return"; 4181da177e4SLinus Torvalds 4191da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 4201da177e4SLinus Torvalds 4211da177e4SLinus Torvaldsreset_state(); 4221da177e4SLinus Torvalds 4231da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) { 4241da177e4SLinus Torvalds my $cmd = shift @ARGV; 4251da177e4SLinus Torvalds if ($cmd eq "-html") { 4261da177e4SLinus Torvalds $output_mode = "html"; 4274d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_html; 4281da177e4SLinus Torvalds $blankline = $blankline_html; 4291b40c194SDan Luedtke } elsif ($cmd eq "-html5") { 4301b40c194SDan Luedtke $output_mode = "html5"; 4314d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_html5; 4321b40c194SDan Luedtke $blankline = $blankline_html5; 4331da177e4SLinus Torvalds } elsif ($cmd eq "-man") { 4341da177e4SLinus Torvalds $output_mode = "man"; 4354d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 4361da177e4SLinus Torvalds $blankline = $blankline_man; 4371da177e4SLinus Torvalds } elsif ($cmd eq "-text") { 4381da177e4SLinus Torvalds $output_mode = "text"; 4394d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_text; 4401da177e4SLinus Torvalds $blankline = $blankline_text; 441c0d1b6eeSJonathan Corbet } elsif ($cmd eq "-rst") { 442c0d1b6eeSJonathan Corbet $output_mode = "rst"; 443c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 444c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 4451da177e4SLinus Torvalds } elsif ($cmd eq "-docbook") { 4461da177e4SLinus Torvalds $output_mode = "xml"; 4474d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_xml; 4481da177e4SLinus Torvalds $blankline = $blankline_xml; 449eda603f6SJohannes Berg } elsif ($cmd eq "-list") { 450eda603f6SJohannes Berg $output_mode = "list"; 4514d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_list; 452eda603f6SJohannes Berg $blankline = $blankline_list; 4531da177e4SLinus Torvalds } elsif ($cmd eq "-gnome") { 4541da177e4SLinus Torvalds $output_mode = "gnome"; 4554d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_gnome; 4561da177e4SLinus Torvalds $blankline = $blankline_gnome; 4571da177e4SLinus Torvalds } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document 4581da177e4SLinus Torvalds $modulename = shift @ARGV; 4591da177e4SLinus Torvalds } elsif ($cmd eq "-function") { # to only output specific functions 460b6c3f456SJani Nikula $output_selection = OUTPUT_INCLUDE; 4611da177e4SLinus Torvalds $function = shift @ARGV; 4621da177e4SLinus Torvalds $function_table{$function} = 1; 463b6c3f456SJani Nikula } elsif ($cmd eq "-nofunction") { # output all except specific functions 464b6c3f456SJani Nikula $output_selection = OUTPUT_EXCLUDE; 4651da177e4SLinus Torvalds $function = shift @ARGV; 4661da177e4SLinus Torvalds $function_table{$function} = 1; 46786ae2e38SJani Nikula } elsif ($cmd eq "-export") { # only exported symbols 468b6c3f456SJani Nikula $output_selection = OUTPUT_EXPORTED; 46986ae2e38SJani Nikula %function_table = () 47086ae2e38SJani Nikula } elsif ($cmd eq "-internal") { # only non-exported symbols 471b6c3f456SJani Nikula $output_selection = OUTPUT_INTERNAL; 47286ae2e38SJani Nikula %function_table = () 4731da177e4SLinus Torvalds } elsif ($cmd eq "-v") { 4741da177e4SLinus Torvalds $verbose = 1; 4751da177e4SLinus Torvalds } elsif (($cmd eq "-h") || ($cmd eq "--help")) { 4761da177e4SLinus Torvalds usage(); 4774b44595aSJohannes Berg } elsif ($cmd eq '-no-doc-sections') { 4784b44595aSJohannes Berg $no_doc_sections = 1; 479e946c43aSJohannes Berg } elsif ($cmd eq '-show-not-found') { 480e946c43aSJohannes Berg $show_not_found = 1; 4811da177e4SLinus Torvalds } 4821da177e4SLinus Torvalds} 4831da177e4SLinus Torvalds 4848484baaaSRandy Dunlap# continue execution near EOF; 4858484baaaSRandy Dunlap 48653f049faSBorislav Petkov# get kernel version from env 48753f049faSBorislav Petkovsub get_kernel_version() { 4881b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 48953f049faSBorislav Petkov 49053f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 49153f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 49253f049faSBorislav Petkov } 49353f049faSBorislav Petkov return $version; 49453f049faSBorislav Petkov} 4951da177e4SLinus Torvalds 4961da177e4SLinus Torvalds## 4971da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 4981da177e4SLinus Torvalds# 4991da177e4SLinus Torvaldssub dump_section { 50094dc7ad5SRandy Dunlap my $file = shift; 5011da177e4SLinus Torvalds my $name = shift; 5021da177e4SLinus Torvalds my $contents = join "\n", @_; 5031da177e4SLinus Torvalds 5041da177e4SLinus Torvalds if ($name =~ m/$type_constant/) { 5051da177e4SLinus Torvalds $name = $1; 5061da177e4SLinus Torvalds# print STDERR "constant section '$1' = '$contents'\n"; 5071da177e4SLinus Torvalds $constants{$name} = $contents; 5081da177e4SLinus Torvalds } elsif ($name =~ m/$type_param/) { 5091da177e4SLinus Torvalds# print STDERR "parameter def '$1' = '$contents'\n"; 5101da177e4SLinus Torvalds $name = $1; 5111da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 512a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 513ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 514ced69090SRandy Dunlap# print STDERR "parameter def '...' = '$contents'\n"; 515ced69090SRandy Dunlap $name = "..."; 516ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 517a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 5181da177e4SLinus Torvalds } else { 5191da177e4SLinus Torvalds# print STDERR "other section '$name' = '$contents'\n"; 52094dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 521d40e1e65SBart Van Assche print STDERR "${file}:$.: error: duplicate section name '$name'\n"; 52294dc7ad5SRandy Dunlap ++$errors; 52394dc7ad5SRandy Dunlap } 5241da177e4SLinus Torvalds $sections{$name} = $contents; 5251da177e4SLinus Torvalds push @sectionlist, $name; 5261da177e4SLinus Torvalds } 5271da177e4SLinus Torvalds} 5281da177e4SLinus Torvalds 5291da177e4SLinus Torvalds## 530b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 531b112e0f7SJohannes Berg# 532b112e0f7SJohannes Bergsub dump_doc_section { 53394dc7ad5SRandy Dunlap my $file = shift; 534b112e0f7SJohannes Berg my $name = shift; 535b112e0f7SJohannes Berg my $contents = join "\n", @_; 536b112e0f7SJohannes Berg 5374b44595aSJohannes Berg if ($no_doc_sections) { 5384b44595aSJohannes Berg return; 5394b44595aSJohannes Berg } 5404b44595aSJohannes Berg 541b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 542b6c3f456SJani Nikula ($output_selection == OUTPUT_INCLUDE && 543b6c3f456SJani Nikula defined($function_table{$name})) || 544b6c3f456SJani Nikula ($output_selection == OUTPUT_EXCLUDE && 545b6c3f456SJani Nikula !defined($function_table{$name}))) 546b112e0f7SJohannes Berg { 54794dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 548b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 549b112e0f7SJohannes Berg 'sections' => \%sections, 550b112e0f7SJohannes Berg 'module' => $modulename, 551b6c3f456SJani Nikula 'content-only' => ($output_selection != OUTPUT_ALL), }); 552b112e0f7SJohannes Berg } 553b112e0f7SJohannes Berg} 554b112e0f7SJohannes Berg 555b112e0f7SJohannes Berg## 5561da177e4SLinus Torvalds# output function 5571da177e4SLinus Torvalds# 5581da177e4SLinus Torvalds# parameterdescs, a hash. 5591da177e4SLinus Torvalds# function => "function name" 5601da177e4SLinus Torvalds# parameterlist => @list of parameters 5611da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 5621da177e4SLinus Torvalds# sectionlist => @list of sections 563a21217daSRandy Dunlap# sections => %section descriptions 5641da177e4SLinus Torvalds# 5651da177e4SLinus Torvalds 5661da177e4SLinus Torvaldssub output_highlight { 5671da177e4SLinus Torvalds my $contents = join "\n",@_; 5681da177e4SLinus Torvalds my $line; 5691da177e4SLinus Torvalds 5701da177e4SLinus Torvalds# DEBUG 5711da177e4SLinus Torvalds# if (!defined $contents) { 5721da177e4SLinus Torvalds# use Carp; 5731da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 5741da177e4SLinus Torvalds# } 5751da177e4SLinus Torvalds 5761b40c194SDan Luedtke if ($output_mode eq "html" || $output_mode eq "html5" || 5771b40c194SDan Luedtke $output_mode eq "xml") { 5786b5b55f6SRandy Dunlap $contents = local_unescape($contents); 5796b5b55f6SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 5802b35f4d9SRandy Dunlap $contents =~ s/\\\\\\/\&/g; 5816b5b55f6SRandy Dunlap } 5823eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 5831da177e4SLinus Torvalds eval $dohighlight; 5841da177e4SLinus Torvalds die $@ if $@; 5853eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 5863eb014a1SRandy Dunlap 5871b40c194SDan Luedtke# strip whitespaces when generating html5 5881b40c194SDan Luedtke if ($output_mode eq "html5") { 5891b40c194SDan Luedtke $contents =~ s/^\s+//; 5901b40c194SDan Luedtke $contents =~ s/\s+$//; 5911b40c194SDan Luedtke } 5921da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 59312ae6779SDaniel Santos if (! $output_preformatted) { 59412ae6779SDaniel Santos $line =~ s/^\s*//; 59512ae6779SDaniel Santos } 5961da177e4SLinus Torvalds if ($line eq ""){ 597e314ba31SDaniel Santos if (! $output_preformatted) { 5986b5b55f6SRandy Dunlap print $lineprefix, local_unescape($blankline); 599e314ba31SDaniel Santos } 6001da177e4SLinus Torvalds } else { 6011da177e4SLinus Torvalds $line =~ s/\\\\\\/\&/g; 602cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 603cdccb316SRandy Dunlap print "\\&$line"; 604cdccb316SRandy Dunlap } else { 6051da177e4SLinus Torvalds print $lineprefix, $line; 6061da177e4SLinus Torvalds } 607cdccb316SRandy Dunlap } 6081da177e4SLinus Torvalds print "\n"; 6091da177e4SLinus Torvalds } 6101da177e4SLinus Torvalds} 6111da177e4SLinus Torvalds 6121da177e4SLinus Torvalds# output sections in html 6131da177e4SLinus Torvaldssub output_section_html(%) { 6141da177e4SLinus Torvalds my %args = %{$_[0]}; 6151da177e4SLinus Torvalds my $section; 6161da177e4SLinus Torvalds 6171da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6181da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 6191da177e4SLinus Torvalds print "<blockquote>\n"; 6201da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6211da177e4SLinus Torvalds print "</blockquote>\n"; 6221da177e4SLinus Torvalds } 6231da177e4SLinus Torvalds} 6241da177e4SLinus Torvalds 6251da177e4SLinus Torvalds# output enum in html 6261da177e4SLinus Torvaldssub output_enum_html(%) { 6271da177e4SLinus Torvalds my %args = %{$_[0]}; 6281da177e4SLinus Torvalds my ($parameter); 6291da177e4SLinus Torvalds my $count; 6301da177e4SLinus Torvalds print "<h2>enum " . $args{'enum'} . "</h2>\n"; 6311da177e4SLinus Torvalds 6321da177e4SLinus Torvalds print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; 6331da177e4SLinus Torvalds $count = 0; 6341da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6351da177e4SLinus Torvalds print " <b>" . $parameter . "</b>"; 6361da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 6371da177e4SLinus Torvalds $count++; 6381da177e4SLinus Torvalds print ",\n"; 6391da177e4SLinus Torvalds } 6401da177e4SLinus Torvalds print "<br>"; 6411da177e4SLinus Torvalds } 6421da177e4SLinus Torvalds print "};<br>\n"; 6431da177e4SLinus Torvalds 6441da177e4SLinus Torvalds print "<h3>Constants</h3>\n"; 6451da177e4SLinus Torvalds print "<dl>\n"; 6461da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6471da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 6481da177e4SLinus Torvalds print "<dd>"; 6491da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter}); 6501da177e4SLinus Torvalds } 6511da177e4SLinus Torvalds print "</dl>\n"; 6521da177e4SLinus Torvalds output_section_html(@_); 6531da177e4SLinus Torvalds print "<hr>\n"; 6541da177e4SLinus Torvalds} 6551da177e4SLinus Torvalds 656d28bee0cSRandy Dunlap# output typedef in html 6571da177e4SLinus Torvaldssub output_typedef_html(%) { 6581da177e4SLinus Torvalds my %args = %{$_[0]}; 6591da177e4SLinus Torvalds my ($parameter); 6601da177e4SLinus Torvalds my $count; 6611da177e4SLinus Torvalds print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; 6621da177e4SLinus Torvalds 6631da177e4SLinus Torvalds print "<b>typedef " . $args{'typedef'} . "</b>\n"; 6641da177e4SLinus Torvalds output_section_html(@_); 6651da177e4SLinus Torvalds print "<hr>\n"; 6661da177e4SLinus Torvalds} 6671da177e4SLinus Torvalds 6681da177e4SLinus Torvalds# output struct in html 6691da177e4SLinus Torvaldssub output_struct_html(%) { 6701da177e4SLinus Torvalds my %args = %{$_[0]}; 6711da177e4SLinus Torvalds my ($parameter); 6721da177e4SLinus Torvalds 673262d9b01SRandy Dunlap print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; 6741da177e4SLinus Torvalds print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; 6751da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6761da177e4SLinus Torvalds if ($parameter =~ /^#/) { 6771da177e4SLinus Torvalds print "$parameter<br>\n"; 6781da177e4SLinus Torvalds next; 6791da177e4SLinus Torvalds } 6801da177e4SLinus Torvalds my $parameter_name = $parameter; 6811da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6821da177e4SLinus Torvalds 6831da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6841da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 6851da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 6861da177e4SLinus Torvalds # pointer-to-function 6873eb014a1SRandy Dunlap print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; 6881da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 6893eb014a1SRandy Dunlap # bitfield 6903eb014a1SRandy Dunlap print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; 6911da177e4SLinus Torvalds } else { 6923eb014a1SRandy Dunlap print " <i>$type</i> <b>$parameter</b>;<br>\n"; 6931da177e4SLinus Torvalds } 6941da177e4SLinus Torvalds } 6951da177e4SLinus Torvalds print "};<br>\n"; 6961da177e4SLinus Torvalds 6971da177e4SLinus Torvalds print "<h3>Members</h3>\n"; 6981da177e4SLinus Torvalds print "<dl>\n"; 6991da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7001da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 7011da177e4SLinus Torvalds 7021da177e4SLinus Torvalds my $parameter_name = $parameter; 7031da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7041da177e4SLinus Torvalds 7051da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7061da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 7071da177e4SLinus Torvalds print "<dd>"; 7081da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7091da177e4SLinus Torvalds } 7101da177e4SLinus Torvalds print "</dl>\n"; 7111da177e4SLinus Torvalds output_section_html(@_); 7121da177e4SLinus Torvalds print "<hr>\n"; 7131da177e4SLinus Torvalds} 7141da177e4SLinus Torvalds 7151da177e4SLinus Torvalds# output function in html 7161da177e4SLinus Torvaldssub output_function_html(%) { 7171da177e4SLinus Torvalds my %args = %{$_[0]}; 7181da177e4SLinus Torvalds my ($parameter, $section); 7191da177e4SLinus Torvalds my $count; 7201da177e4SLinus Torvalds 721262d9b01SRandy Dunlap print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; 7221da177e4SLinus Torvalds print "<i>" . $args{'functiontype'} . "</i>\n"; 7231da177e4SLinus Torvalds print "<b>" . $args{'function'} . "</b>\n"; 7241da177e4SLinus Torvalds print "("; 7251da177e4SLinus Torvalds $count = 0; 7261da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7271da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 7281da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 7291da177e4SLinus Torvalds # pointer-to-function 7301da177e4SLinus Torvalds print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; 7311da177e4SLinus Torvalds } else { 7321da177e4SLinus Torvalds print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; 7331da177e4SLinus Torvalds } 7341da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 7351da177e4SLinus Torvalds $count++; 7361da177e4SLinus Torvalds print ",\n"; 7371da177e4SLinus Torvalds } 7381da177e4SLinus Torvalds } 7391da177e4SLinus Torvalds print ")\n"; 7401da177e4SLinus Torvalds 7411da177e4SLinus Torvalds print "<h3>Arguments</h3>\n"; 7421da177e4SLinus Torvalds print "<dl>\n"; 7431da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7441da177e4SLinus Torvalds my $parameter_name = $parameter; 7451da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7461da177e4SLinus Torvalds 7471da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7481da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 7491da177e4SLinus Torvalds print "<dd>"; 7501da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7511da177e4SLinus Torvalds } 7521da177e4SLinus Torvalds print "</dl>\n"; 7531da177e4SLinus Torvalds output_section_html(@_); 7541da177e4SLinus Torvalds print "<hr>\n"; 7551da177e4SLinus Torvalds} 7561da177e4SLinus Torvalds 757b112e0f7SJohannes Berg# output DOC: block header in html 758b112e0f7SJohannes Bergsub output_blockhead_html(%) { 7591da177e4SLinus Torvalds my %args = %{$_[0]}; 7601da177e4SLinus Torvalds my ($parameter, $section); 7611da177e4SLinus Torvalds my $count; 7621da177e4SLinus Torvalds 7631da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7641da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 7651da177e4SLinus Torvalds print "<ul>\n"; 7661da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7671da177e4SLinus Torvalds print "</ul>\n"; 7681da177e4SLinus Torvalds } 7691da177e4SLinus Torvalds print "<hr>\n"; 7701da177e4SLinus Torvalds} 7711da177e4SLinus Torvalds 7721b40c194SDan Luedtke# output sections in html5 7731b40c194SDan Luedtkesub output_section_html5(%) { 7741b40c194SDan Luedtke my %args = %{$_[0]}; 7751b40c194SDan Luedtke my $section; 7761b40c194SDan Luedtke 7771b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 7781b40c194SDan Luedtke print "<section>\n"; 7791b40c194SDan Luedtke print "<h1>$section</h1>\n"; 7801b40c194SDan Luedtke print "<p>\n"; 7811b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 7821b40c194SDan Luedtke print "</p>\n"; 7831b40c194SDan Luedtke print "</section>\n"; 7841b40c194SDan Luedtke } 7851b40c194SDan Luedtke} 7861b40c194SDan Luedtke 7871b40c194SDan Luedtke# output enum in html5 7881b40c194SDan Luedtkesub output_enum_html5(%) { 7891b40c194SDan Luedtke my %args = %{$_[0]}; 7901b40c194SDan Luedtke my ($parameter); 7911b40c194SDan Luedtke my $count; 7921b40c194SDan Luedtke my $html5id; 7931b40c194SDan Luedtke 7941b40c194SDan Luedtke $html5id = $args{'enum'}; 7951b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 7961b40c194SDan Luedtke print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; 7971b40c194SDan Luedtke print "<h1>enum " . $args{'enum'} . "</h1>\n"; 7981b40c194SDan Luedtke print "<ol class=\"code\">\n"; 7991b40c194SDan Luedtke print "<li>"; 8001b40c194SDan Luedtke print "<span class=\"keyword\">enum</span> "; 8011b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; 8021b40c194SDan Luedtke print "</li>\n"; 8031b40c194SDan Luedtke $count = 0; 8041b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8051b40c194SDan Luedtke print "<li class=\"indent\">"; 8061b40c194SDan Luedtke print "<span class=\"param\">" . $parameter . "</span>"; 8071b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 8081b40c194SDan Luedtke $count++; 8091b40c194SDan Luedtke print ","; 8101b40c194SDan Luedtke } 8111b40c194SDan Luedtke print "</li>\n"; 8121b40c194SDan Luedtke } 8131b40c194SDan Luedtke print "<li>};</li>\n"; 8141b40c194SDan Luedtke print "</ol>\n"; 8151b40c194SDan Luedtke 8161b40c194SDan Luedtke print "<section>\n"; 8171b40c194SDan Luedtke print "<h1>Constants</h1>\n"; 8181b40c194SDan Luedtke print "<dl>\n"; 8191b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8201b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 8211b40c194SDan Luedtke print "<dd>"; 8221b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter}); 8231b40c194SDan Luedtke print "</dd>\n"; 8241b40c194SDan Luedtke } 8251b40c194SDan Luedtke print "</dl>\n"; 8261b40c194SDan Luedtke print "</section>\n"; 8271b40c194SDan Luedtke output_section_html5(@_); 8281b40c194SDan Luedtke print "</article>\n"; 8291b40c194SDan Luedtke} 8301b40c194SDan Luedtke 8311b40c194SDan Luedtke# output typedef in html5 8321b40c194SDan Luedtkesub output_typedef_html5(%) { 8331b40c194SDan Luedtke my %args = %{$_[0]}; 8341b40c194SDan Luedtke my ($parameter); 8351b40c194SDan Luedtke my $count; 8361b40c194SDan Luedtke my $html5id; 8371b40c194SDan Luedtke 8381b40c194SDan Luedtke $html5id = $args{'typedef'}; 8391b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8401b40c194SDan Luedtke print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; 8411b40c194SDan Luedtke print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; 8421b40c194SDan Luedtke 8431b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8441b40c194SDan Luedtke print "<li>"; 8451b40c194SDan Luedtke print "<span class=\"keyword\">typedef</span> "; 8461b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; 8471b40c194SDan Luedtke print "</li>\n"; 8481b40c194SDan Luedtke print "</ol>\n"; 8491b40c194SDan Luedtke output_section_html5(@_); 8501b40c194SDan Luedtke print "</article>\n"; 8511b40c194SDan Luedtke} 8521b40c194SDan Luedtke 8531b40c194SDan Luedtke# output struct in html5 8541b40c194SDan Luedtkesub output_struct_html5(%) { 8551b40c194SDan Luedtke my %args = %{$_[0]}; 8561b40c194SDan Luedtke my ($parameter); 8571b40c194SDan Luedtke my $html5id; 8581b40c194SDan Luedtke 8591b40c194SDan Luedtke $html5id = $args{'struct'}; 8601b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8611b40c194SDan Luedtke print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n"; 8621b40c194SDan Luedtke print "<hgroup>\n"; 8631b40c194SDan Luedtke print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>"; 8641b40c194SDan Luedtke print "<h2>". $args{'purpose'} . "</h2>\n"; 8651b40c194SDan Luedtke print "</hgroup>\n"; 8661b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8671b40c194SDan Luedtke print "<li>"; 8681b40c194SDan Luedtke print "<span class=\"type\">" . $args{'type'} . "</span> "; 8691b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'struct'} . "</span> {"; 8701b40c194SDan Luedtke print "</li>\n"; 8711b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8721b40c194SDan Luedtke print "<li class=\"indent\">"; 8731b40c194SDan Luedtke if ($parameter =~ /^#/) { 8741b40c194SDan Luedtke print "<span class=\"param\">" . $parameter ."</span>\n"; 8751b40c194SDan Luedtke print "</li>\n"; 8761b40c194SDan Luedtke next; 8771b40c194SDan Luedtke } 8781b40c194SDan Luedtke my $parameter_name = $parameter; 8791b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 8801b40c194SDan Luedtke 8811b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 8821b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 8831b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 8841b40c194SDan Luedtke # pointer-to-function 8851b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 8861b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 8871b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 8881b40c194SDan Luedtke print "(<span class=\"args\">$2</span>);"; 8891b40c194SDan Luedtke } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 8901b40c194SDan Luedtke # bitfield 8911b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 8921b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 8931b40c194SDan Luedtke print "<span class=\"bits\">$2</span>;"; 8941b40c194SDan Luedtke } else { 8951b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 8961b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>;"; 8971b40c194SDan Luedtke } 8981b40c194SDan Luedtke print "</li>\n"; 8991b40c194SDan Luedtke } 9001b40c194SDan Luedtke print "<li>};</li>\n"; 9011b40c194SDan Luedtke print "</ol>\n"; 9021b40c194SDan Luedtke 9031b40c194SDan Luedtke print "<section>\n"; 9041b40c194SDan Luedtke print "<h1>Members</h1>\n"; 9051b40c194SDan Luedtke print "<dl>\n"; 9061b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9071b40c194SDan Luedtke ($parameter =~ /^#/) && next; 9081b40c194SDan Luedtke 9091b40c194SDan Luedtke my $parameter_name = $parameter; 9101b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 9111b40c194SDan Luedtke 9121b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 9131b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 9141b40c194SDan Luedtke print "<dd>"; 9151b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 9161b40c194SDan Luedtke print "</dd>\n"; 9171b40c194SDan Luedtke } 9181b40c194SDan Luedtke print "</dl>\n"; 9191b40c194SDan Luedtke print "</section>\n"; 9201b40c194SDan Luedtke output_section_html5(@_); 9211b40c194SDan Luedtke print "</article>\n"; 9221b40c194SDan Luedtke} 9231b40c194SDan Luedtke 9241b40c194SDan Luedtke# output function in html5 9251b40c194SDan Luedtkesub output_function_html5(%) { 9261b40c194SDan Luedtke my %args = %{$_[0]}; 9271b40c194SDan Luedtke my ($parameter, $section); 9281b40c194SDan Luedtke my $count; 9291b40c194SDan Luedtke my $html5id; 9301b40c194SDan Luedtke 9311b40c194SDan Luedtke $html5id = $args{'function'}; 9321b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 9331b40c194SDan Luedtke print "<article class=\"function\" id=\"func:". $html5id . "\">\n"; 9341b40c194SDan Luedtke print "<hgroup>\n"; 9351b40c194SDan Luedtke print "<h1>" . $args{'function'} . "</h1>"; 9361b40c194SDan Luedtke print "<h2>" . $args{'purpose'} . "</h2>\n"; 9371b40c194SDan Luedtke print "</hgroup>\n"; 9381b40c194SDan Luedtke print "<ol class=\"code\">\n"; 9391b40c194SDan Luedtke print "<li>"; 9401b40c194SDan Luedtke print "<span class=\"type\">" . $args{'functiontype'} . "</span> "; 9411b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'function'} . "</span> ("; 9421b40c194SDan Luedtke print "</li>"; 9431b40c194SDan Luedtke $count = 0; 9441b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9451b40c194SDan Luedtke print "<li class=\"indent\">"; 9461b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 9471b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 9481b40c194SDan Luedtke # pointer-to-function 9491b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 9501b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9511b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 9521b40c194SDan Luedtke print "(<span class=\"args\">$2</span>)"; 9531b40c194SDan Luedtke } else { 9541b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 9551b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9561b40c194SDan Luedtke } 9571b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 9581b40c194SDan Luedtke $count++; 9591b40c194SDan Luedtke print ","; 9601b40c194SDan Luedtke } 9611b40c194SDan Luedtke print "</li>\n"; 9621b40c194SDan Luedtke } 9631b40c194SDan Luedtke print "<li>)</li>\n"; 9641b40c194SDan Luedtke print "</ol>\n"; 9651b40c194SDan Luedtke 9661b40c194SDan Luedtke print "<section>\n"; 9671b40c194SDan Luedtke print "<h1>Arguments</h1>\n"; 9681b40c194SDan Luedtke print "<p>\n"; 9691b40c194SDan Luedtke print "<dl>\n"; 9701b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9711b40c194SDan Luedtke my $parameter_name = $parameter; 9721b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 9731b40c194SDan Luedtke 9741b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 9751b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 9761b40c194SDan Luedtke print "<dd>"; 9771b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 9781b40c194SDan Luedtke print "</dd>\n"; 9791b40c194SDan Luedtke } 9801b40c194SDan Luedtke print "</dl>\n"; 9811b40c194SDan Luedtke print "</section>\n"; 9821b40c194SDan Luedtke output_section_html5(@_); 9831b40c194SDan Luedtke print "</article>\n"; 9841b40c194SDan Luedtke} 9851b40c194SDan Luedtke 9861b40c194SDan Luedtke# output DOC: block header in html5 9871b40c194SDan Luedtkesub output_blockhead_html5(%) { 9881b40c194SDan Luedtke my %args = %{$_[0]}; 9891b40c194SDan Luedtke my ($parameter, $section); 9901b40c194SDan Luedtke my $count; 9911b40c194SDan Luedtke my $html5id; 9921b40c194SDan Luedtke 9931b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 9941b40c194SDan Luedtke $html5id = $section; 9951b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 9961b40c194SDan Luedtke print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n"; 9971b40c194SDan Luedtke print "<h1>$section</h1>\n"; 9981b40c194SDan Luedtke print "<p>\n"; 9991b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 10001b40c194SDan Luedtke print "</p>\n"; 10011b40c194SDan Luedtke } 10021b40c194SDan Luedtke print "</article>\n"; 10031b40c194SDan Luedtke} 10041b40c194SDan Luedtke 10051da177e4SLinus Torvaldssub output_section_xml(%) { 10061da177e4SLinus Torvalds my %args = %{$_[0]}; 10071da177e4SLinus Torvalds my $section; 10081da177e4SLinus Torvalds # print out each section 10091da177e4SLinus Torvalds $lineprefix=" "; 10101da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1011c73894c1SRich Walker print "<refsect1>\n"; 1012c73894c1SRich Walker print "<title>$section</title>\n"; 10131da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 1014c73894c1SRich Walker print "<informalexample><programlisting>\n"; 1015e314ba31SDaniel Santos $output_preformatted = 1; 1016c73894c1SRich Walker } else { 1017c73894c1SRich Walker print "<para>\n"; 10181da177e4SLinus Torvalds } 10191da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1020e314ba31SDaniel Santos $output_preformatted = 0; 10211da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 1022c73894c1SRich Walker print "</programlisting></informalexample>\n"; 1023c73894c1SRich Walker } else { 1024c73894c1SRich Walker print "</para>\n"; 10251da177e4SLinus Torvalds } 1026c73894c1SRich Walker print "</refsect1>\n"; 10271da177e4SLinus Torvalds } 10281da177e4SLinus Torvalds} 10291da177e4SLinus Torvalds 10301da177e4SLinus Torvalds# output function in XML DocBook 10311da177e4SLinus Torvaldssub output_function_xml(%) { 10321da177e4SLinus Torvalds my %args = %{$_[0]}; 10331da177e4SLinus Torvalds my ($parameter, $section); 10341da177e4SLinus Torvalds my $count; 10351da177e4SLinus Torvalds my $id; 10361da177e4SLinus Torvalds 10371da177e4SLinus Torvalds $id = "API-" . $args{'function'}; 10381da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 10391da177e4SLinus Torvalds 10405449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 10418b0c2d98SMartin Waitz print "<refentryinfo>\n"; 10428b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 10438b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 10448b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 10458b0c2d98SMartin Waitz print "</refentryinfo>\n"; 10461da177e4SLinus Torvalds print "<refmeta>\n"; 10475449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; 10488b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 10490366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 10501da177e4SLinus Torvalds print "</refmeta>\n"; 10511da177e4SLinus Torvalds print "<refnamediv>\n"; 10521da177e4SLinus Torvalds print " <refname>" . $args{'function'} . "</refname>\n"; 10531da177e4SLinus Torvalds print " <refpurpose>\n"; 10541da177e4SLinus Torvalds print " "; 10551da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 10561da177e4SLinus Torvalds print " </refpurpose>\n"; 10571da177e4SLinus Torvalds print "</refnamediv>\n"; 10581da177e4SLinus Torvalds 10591da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 10601da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 10611da177e4SLinus Torvalds print " <funcsynopsis><funcprototype>\n"; 10621da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 10631da177e4SLinus Torvalds print "<function>" . $args{'function'} . " </function></funcdef>\n"; 10641da177e4SLinus Torvalds 10651da177e4SLinus Torvalds $count = 0; 10661da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 10671da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10681da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 10691da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 10701da177e4SLinus Torvalds # pointer-to-function 10711da177e4SLinus Torvalds print " <paramdef>$1<parameter>$parameter</parameter>)\n"; 10721da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 10731da177e4SLinus Torvalds } else { 10741da177e4SLinus Torvalds print " <paramdef>" . $type; 10751da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 10761da177e4SLinus Torvalds } 10771da177e4SLinus Torvalds } 10781da177e4SLinus Torvalds } else { 10796013d544SMartin Waitz print " <void/>\n"; 10801da177e4SLinus Torvalds } 10811da177e4SLinus Torvalds print " </funcprototype></funcsynopsis>\n"; 10821da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 10831da177e4SLinus Torvalds 10841da177e4SLinus Torvalds # print parameters 10851da177e4SLinus Torvalds print "<refsect1>\n <title>Arguments</title>\n"; 10861da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 10871da177e4SLinus Torvalds print " <variablelist>\n"; 10881da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10891da177e4SLinus Torvalds my $parameter_name = $parameter; 10901da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 10911da177e4SLinus Torvalds 10921da177e4SLinus Torvalds print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; 10931da177e4SLinus Torvalds print " <listitem>\n <para>\n"; 10941da177e4SLinus Torvalds $lineprefix=" "; 10951da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 10961da177e4SLinus Torvalds print " </para>\n </listitem>\n </varlistentry>\n"; 10971da177e4SLinus Torvalds } 10981da177e4SLinus Torvalds print " </variablelist>\n"; 10991da177e4SLinus Torvalds } else { 11001da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 11011da177e4SLinus Torvalds } 11021da177e4SLinus Torvalds print "</refsect1>\n"; 11031da177e4SLinus Torvalds 11041da177e4SLinus Torvalds output_section_xml(@_); 11051da177e4SLinus Torvalds print "</refentry>\n\n"; 11061da177e4SLinus Torvalds} 11071da177e4SLinus Torvalds 11081da177e4SLinus Torvalds# output struct in XML DocBook 11091da177e4SLinus Torvaldssub output_struct_xml(%) { 11101da177e4SLinus Torvalds my %args = %{$_[0]}; 11111da177e4SLinus Torvalds my ($parameter, $section); 11121da177e4SLinus Torvalds my $id; 11131da177e4SLinus Torvalds 11141da177e4SLinus Torvalds $id = "API-struct-" . $args{'struct'}; 11151da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 11161da177e4SLinus Torvalds 11175449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 11188b0c2d98SMartin Waitz print "<refentryinfo>\n"; 11198b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 11208b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 11218b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 11228b0c2d98SMartin Waitz print "</refentryinfo>\n"; 11231da177e4SLinus Torvalds print "<refmeta>\n"; 11245449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; 11258b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 11260366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 11271da177e4SLinus Torvalds print "</refmeta>\n"; 11281da177e4SLinus Torvalds print "<refnamediv>\n"; 11291da177e4SLinus Torvalds print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; 11301da177e4SLinus Torvalds print " <refpurpose>\n"; 11311da177e4SLinus Torvalds print " "; 11321da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 11331da177e4SLinus Torvalds print " </refpurpose>\n"; 11341da177e4SLinus Torvalds print "</refnamediv>\n"; 11351da177e4SLinus Torvalds 11361da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 11371da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 11381da177e4SLinus Torvalds print " <programlisting>\n"; 11391da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 11401da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11411da177e4SLinus Torvalds if ($parameter =~ /^#/) { 11422b35f4d9SRandy Dunlap my $prm = $parameter; 11432b35f4d9SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 11442b35f4d9SRandy Dunlap # This allows us to have #define macros interspersed in a struct. 11452b35f4d9SRandy Dunlap $prm =~ s/\\\\\\/\&/g; 11462b35f4d9SRandy Dunlap print "$prm\n"; 11471da177e4SLinus Torvalds next; 11481da177e4SLinus Torvalds } 11491da177e4SLinus Torvalds 11501da177e4SLinus Torvalds my $parameter_name = $parameter; 11511da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11521da177e4SLinus Torvalds 11531da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 11541da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 11551da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 11561da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 11571da177e4SLinus Torvalds # pointer-to-function 11581da177e4SLinus Torvalds print " $1 $parameter) ($2);\n"; 11591da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 116051f5a0c8SRandy Dunlap # bitfield 11611da177e4SLinus Torvalds print " $1 $parameter$2;\n"; 11621da177e4SLinus Torvalds } else { 11631da177e4SLinus Torvalds print " " . $type . " " . $parameter . ";\n"; 11641da177e4SLinus Torvalds } 11651da177e4SLinus Torvalds } 11661da177e4SLinus Torvalds print "};"; 11671da177e4SLinus Torvalds print " </programlisting>\n"; 11681da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 11691da177e4SLinus Torvalds 11701da177e4SLinus Torvalds print " <refsect1>\n"; 11711da177e4SLinus Torvalds print " <title>Members</title>\n"; 11721da177e4SLinus Torvalds 117339f00c08SRandy Dunlap if ($#{$args{'parameterlist'}} >= 0) { 11741da177e4SLinus Torvalds print " <variablelist>\n"; 11751da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11761da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 11771da177e4SLinus Torvalds 11781da177e4SLinus Torvalds my $parameter_name = $parameter; 11791da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11801da177e4SLinus Torvalds 11811da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 11821da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 11831da177e4SLinus Torvalds print " <varlistentry>"; 11841da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 11851da177e4SLinus Torvalds print " <listitem><para>\n"; 11861da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 11871da177e4SLinus Torvalds print " </para></listitem>\n"; 11881da177e4SLinus Torvalds print " </varlistentry>\n"; 11891da177e4SLinus Torvalds } 11901da177e4SLinus Torvalds print " </variablelist>\n"; 119139f00c08SRandy Dunlap } else { 119239f00c08SRandy Dunlap print " <para>\n None\n </para>\n"; 119339f00c08SRandy Dunlap } 11941da177e4SLinus Torvalds print " </refsect1>\n"; 11951da177e4SLinus Torvalds 11961da177e4SLinus Torvalds output_section_xml(@_); 11971da177e4SLinus Torvalds 11981da177e4SLinus Torvalds print "</refentry>\n\n"; 11991da177e4SLinus Torvalds} 12001da177e4SLinus Torvalds 12011da177e4SLinus Torvalds# output enum in XML DocBook 12021da177e4SLinus Torvaldssub output_enum_xml(%) { 12031da177e4SLinus Torvalds my %args = %{$_[0]}; 12041da177e4SLinus Torvalds my ($parameter, $section); 12051da177e4SLinus Torvalds my $count; 12061da177e4SLinus Torvalds my $id; 12071da177e4SLinus Torvalds 12081da177e4SLinus Torvalds $id = "API-enum-" . $args{'enum'}; 12091da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12101da177e4SLinus Torvalds 12115449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 12128b0c2d98SMartin Waitz print "<refentryinfo>\n"; 12138b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 12148b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 12158b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 12168b0c2d98SMartin Waitz print "</refentryinfo>\n"; 12171da177e4SLinus Torvalds print "<refmeta>\n"; 12185449bc94SPavel Pisa print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; 12198b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 12200366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 12211da177e4SLinus Torvalds print "</refmeta>\n"; 12221da177e4SLinus Torvalds print "<refnamediv>\n"; 12231da177e4SLinus Torvalds print " <refname>enum " . $args{'enum'} . "</refname>\n"; 12241da177e4SLinus Torvalds print " <refpurpose>\n"; 12251da177e4SLinus Torvalds print " "; 12261da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 12271da177e4SLinus Torvalds print " </refpurpose>\n"; 12281da177e4SLinus Torvalds print "</refnamediv>\n"; 12291da177e4SLinus Torvalds 12301da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 12311da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 12321da177e4SLinus Torvalds print " <programlisting>\n"; 12331da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 12341da177e4SLinus Torvalds $count = 0; 12351da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12361da177e4SLinus Torvalds print " $parameter"; 12371da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 12381da177e4SLinus Torvalds $count++; 12391da177e4SLinus Torvalds print ","; 12401da177e4SLinus Torvalds } 12411da177e4SLinus Torvalds print "\n"; 12421da177e4SLinus Torvalds } 12431da177e4SLinus Torvalds print "};"; 12441da177e4SLinus Torvalds print " </programlisting>\n"; 12451da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 12461da177e4SLinus Torvalds 12471da177e4SLinus Torvalds print "<refsect1>\n"; 12481da177e4SLinus Torvalds print " <title>Constants</title>\n"; 12491da177e4SLinus Torvalds print " <variablelist>\n"; 12501da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12511da177e4SLinus Torvalds my $parameter_name = $parameter; 12521da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12531da177e4SLinus Torvalds 12541da177e4SLinus Torvalds print " <varlistentry>"; 12551da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 12561da177e4SLinus Torvalds print " <listitem><para>\n"; 12571da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 12581da177e4SLinus Torvalds print " </para></listitem>\n"; 12591da177e4SLinus Torvalds print " </varlistentry>\n"; 12601da177e4SLinus Torvalds } 12611da177e4SLinus Torvalds print " </variablelist>\n"; 12621da177e4SLinus Torvalds print "</refsect1>\n"; 12631da177e4SLinus Torvalds 12641da177e4SLinus Torvalds output_section_xml(@_); 12651da177e4SLinus Torvalds 12661da177e4SLinus Torvalds print "</refentry>\n\n"; 12671da177e4SLinus Torvalds} 12681da177e4SLinus Torvalds 12691da177e4SLinus Torvalds# output typedef in XML DocBook 12701da177e4SLinus Torvaldssub output_typedef_xml(%) { 12711da177e4SLinus Torvalds my %args = %{$_[0]}; 12721da177e4SLinus Torvalds my ($parameter, $section); 12731da177e4SLinus Torvalds my $id; 12741da177e4SLinus Torvalds 12751da177e4SLinus Torvalds $id = "API-typedef-" . $args{'typedef'}; 12761da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12771da177e4SLinus Torvalds 12785449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 12798b0c2d98SMartin Waitz print "<refentryinfo>\n"; 12808b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 12818b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 12828b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 12838b0c2d98SMartin Waitz print "</refentryinfo>\n"; 12841da177e4SLinus Torvalds print "<refmeta>\n"; 12855449bc94SPavel Pisa print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; 12868b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 12871da177e4SLinus Torvalds print "</refmeta>\n"; 12881da177e4SLinus Torvalds print "<refnamediv>\n"; 12891da177e4SLinus Torvalds print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; 12901da177e4SLinus Torvalds print " <refpurpose>\n"; 12911da177e4SLinus Torvalds print " "; 12921da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 12931da177e4SLinus Torvalds print " </refpurpose>\n"; 12941da177e4SLinus Torvalds print "</refnamediv>\n"; 12951da177e4SLinus Torvalds 12961da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 12971da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 12981da177e4SLinus Torvalds print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; 12991da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 13001da177e4SLinus Torvalds 13011da177e4SLinus Torvalds output_section_xml(@_); 13021da177e4SLinus Torvalds 13031da177e4SLinus Torvalds print "</refentry>\n\n"; 13041da177e4SLinus Torvalds} 13051da177e4SLinus Torvalds 13061da177e4SLinus Torvalds# output in XML DocBook 1307b112e0f7SJohannes Bergsub output_blockhead_xml(%) { 13081da177e4SLinus Torvalds my %args = %{$_[0]}; 13091da177e4SLinus Torvalds my ($parameter, $section); 13101da177e4SLinus Torvalds my $count; 13111da177e4SLinus Torvalds 13121da177e4SLinus Torvalds my $id = $args{'module'}; 13131da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13141da177e4SLinus Torvalds 13151da177e4SLinus Torvalds # print out each section 13161da177e4SLinus Torvalds $lineprefix=" "; 13171da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1318b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1319b112e0f7SJohannes Berg print "<refsect1>\n <title>$section</title>\n"; 1320b112e0f7SJohannes Berg } 13211da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13221da177e4SLinus Torvalds print "<example><para>\n"; 1323e314ba31SDaniel Santos $output_preformatted = 1; 1324b112e0f7SJohannes Berg } else { 1325b112e0f7SJohannes Berg print "<para>\n"; 13261da177e4SLinus Torvalds } 13271da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1328e314ba31SDaniel Santos $output_preformatted = 0; 13291da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13301da177e4SLinus Torvalds print "</para></example>\n"; 1331b112e0f7SJohannes Berg } else { 1332b112e0f7SJohannes Berg print "</para>"; 13331da177e4SLinus Torvalds } 1334b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1335b112e0f7SJohannes Berg print "\n</refsect1>\n"; 1336b112e0f7SJohannes Berg } 13371da177e4SLinus Torvalds } 13381da177e4SLinus Torvalds 13391da177e4SLinus Torvalds print "\n\n"; 13401da177e4SLinus Torvalds} 13411da177e4SLinus Torvalds 13421da177e4SLinus Torvalds# output in XML DocBook 13431da177e4SLinus Torvaldssub output_function_gnome { 13441da177e4SLinus Torvalds my %args = %{$_[0]}; 13451da177e4SLinus Torvalds my ($parameter, $section); 13461da177e4SLinus Torvalds my $count; 13471da177e4SLinus Torvalds my $id; 13481da177e4SLinus Torvalds 13491da177e4SLinus Torvalds $id = $args{'module'} . "-" . $args{'function'}; 13501da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13511da177e4SLinus Torvalds 13521da177e4SLinus Torvalds print "<sect2>\n"; 13531da177e4SLinus Torvalds print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; 13541da177e4SLinus Torvalds 13551da177e4SLinus Torvalds print " <funcsynopsis>\n"; 13561da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 13571da177e4SLinus Torvalds print "<function>" . $args{'function'} . " "; 13581da177e4SLinus Torvalds print "</function></funcdef>\n"; 13591da177e4SLinus Torvalds 13601da177e4SLinus Torvalds $count = 0; 13611da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 13621da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13631da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 13641da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 13651da177e4SLinus Torvalds # pointer-to-function 13661da177e4SLinus Torvalds print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; 13671da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 13681da177e4SLinus Torvalds } else { 13691da177e4SLinus Torvalds print " <paramdef>" . $type; 13701da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 13711da177e4SLinus Torvalds } 13721da177e4SLinus Torvalds } 13731da177e4SLinus Torvalds } else { 13741da177e4SLinus Torvalds print " <void>\n"; 13751da177e4SLinus Torvalds } 13761da177e4SLinus Torvalds print " </funcsynopsis>\n"; 13771da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 13781da177e4SLinus Torvalds print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; 13791da177e4SLinus Torvalds print "<tgroup cols=\"2\">\n"; 13801da177e4SLinus Torvalds print "<colspec colwidth=\"2*\">\n"; 13811da177e4SLinus Torvalds print "<colspec colwidth=\"8*\">\n"; 13821da177e4SLinus Torvalds print "<tbody>\n"; 13831da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13841da177e4SLinus Torvalds my $parameter_name = $parameter; 13851da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 13861da177e4SLinus Torvalds 13871da177e4SLinus Torvalds print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; 13881da177e4SLinus Torvalds print " <entry>\n"; 13891da177e4SLinus Torvalds $lineprefix=" "; 13901da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 13911da177e4SLinus Torvalds print " </entry></row>\n"; 13921da177e4SLinus Torvalds } 13931da177e4SLinus Torvalds print " </tbody></tgroup></informaltable>\n"; 13941da177e4SLinus Torvalds } else { 13951da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 13961da177e4SLinus Torvalds } 13971da177e4SLinus Torvalds 13981da177e4SLinus Torvalds # print out each section 13991da177e4SLinus Torvalds $lineprefix=" "; 14001da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14011da177e4SLinus Torvalds print "<simplesect>\n <title>$section</title>\n"; 14021da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 14031da177e4SLinus Torvalds print "<example><programlisting>\n"; 1404e314ba31SDaniel Santos $output_preformatted = 1; 14051da177e4SLinus Torvalds } else { 14061da177e4SLinus Torvalds } 14071da177e4SLinus Torvalds print "<para>\n"; 14081da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1409e314ba31SDaniel Santos $output_preformatted = 0; 14101da177e4SLinus Torvalds print "</para>\n"; 14111da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 14121da177e4SLinus Torvalds print "</programlisting></example>\n"; 14131da177e4SLinus Torvalds } else { 14141da177e4SLinus Torvalds } 14151da177e4SLinus Torvalds print " </simplesect>\n"; 14161da177e4SLinus Torvalds } 14171da177e4SLinus Torvalds 14181da177e4SLinus Torvalds print "</sect2>\n\n"; 14191da177e4SLinus Torvalds} 14201da177e4SLinus Torvalds 14211da177e4SLinus Torvalds## 14221da177e4SLinus Torvalds# output function in man 14231da177e4SLinus Torvaldssub output_function_man(%) { 14241da177e4SLinus Torvalds my %args = %{$_[0]}; 14251da177e4SLinus Torvalds my ($parameter, $section); 14261da177e4SLinus Torvalds my $count; 14271da177e4SLinus Torvalds 14281da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 14291da177e4SLinus Torvalds 14301da177e4SLinus Torvalds print ".SH NAME\n"; 14311da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 14321da177e4SLinus Torvalds 14331da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 1434a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 14351da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 1436a21217daSRandy Dunlap } else { 1437a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 1438a21217daSRandy Dunlap } 14391da177e4SLinus Torvalds $count = 0; 14401da177e4SLinus Torvalds my $parenth = "("; 14411da177e4SLinus Torvalds my $post = ","; 14421da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 14431da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 14441da177e4SLinus Torvalds $post = ");"; 14451da177e4SLinus Torvalds } 14461da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 14471da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 14481da177e4SLinus Torvalds # pointer-to-function 14491da177e4SLinus Torvalds print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 14501da177e4SLinus Torvalds } else { 14511da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 14521da177e4SLinus Torvalds print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 14531da177e4SLinus Torvalds } 14541da177e4SLinus Torvalds $count++; 14551da177e4SLinus Torvalds $parenth = ""; 14561da177e4SLinus Torvalds } 14571da177e4SLinus Torvalds 14581da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 14591da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14601da177e4SLinus Torvalds my $parameter_name = $parameter; 14611da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14621da177e4SLinus Torvalds 14631da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 14641da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14651da177e4SLinus Torvalds } 14661da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14671da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 14681da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 14691da177e4SLinus Torvalds } 14701da177e4SLinus Torvalds} 14711da177e4SLinus Torvalds 14721da177e4SLinus Torvalds## 14731da177e4SLinus Torvalds# output enum in man 14741da177e4SLinus Torvaldssub output_enum_man(%) { 14751da177e4SLinus Torvalds my %args = %{$_[0]}; 14761da177e4SLinus Torvalds my ($parameter, $section); 14771da177e4SLinus Torvalds my $count; 14781da177e4SLinus Torvalds 14791da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 14801da177e4SLinus Torvalds 14811da177e4SLinus Torvalds print ".SH NAME\n"; 14821da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 14831da177e4SLinus Torvalds 14841da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 14851da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 14861da177e4SLinus Torvalds $count = 0; 14871da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 14881da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 14891da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 14901da177e4SLinus Torvalds print "\n};\n"; 14911da177e4SLinus Torvalds last; 14921da177e4SLinus Torvalds } 14931da177e4SLinus Torvalds else { 14941da177e4SLinus Torvalds print ", \n.br\n"; 14951da177e4SLinus Torvalds } 14961da177e4SLinus Torvalds $count++; 14971da177e4SLinus Torvalds } 14981da177e4SLinus Torvalds 14991da177e4SLinus Torvalds print ".SH Constants\n"; 15001da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15011da177e4SLinus Torvalds my $parameter_name = $parameter; 15021da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15031da177e4SLinus Torvalds 15041da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 15051da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 15061da177e4SLinus Torvalds } 15071da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15081da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15091da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15101da177e4SLinus Torvalds } 15111da177e4SLinus Torvalds} 15121da177e4SLinus Torvalds 15131da177e4SLinus Torvalds## 15141da177e4SLinus Torvalds# output struct in man 15151da177e4SLinus Torvaldssub output_struct_man(%) { 15161da177e4SLinus Torvalds my %args = %{$_[0]}; 15171da177e4SLinus Torvalds my ($parameter, $section); 15181da177e4SLinus Torvalds 15191da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 15201da177e4SLinus Torvalds 15211da177e4SLinus Torvalds print ".SH NAME\n"; 15221da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 15231da177e4SLinus Torvalds 15241da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 15251da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 15261da177e4SLinus Torvalds 15271da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15281da177e4SLinus Torvalds if ($parameter =~ /^#/) { 15291da177e4SLinus Torvalds print ".BI \"$parameter\"\n.br\n"; 15301da177e4SLinus Torvalds next; 15311da177e4SLinus Torvalds } 15321da177e4SLinus Torvalds my $parameter_name = $parameter; 15331da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15341da177e4SLinus Torvalds 15351da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 15361da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 15371da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 15381da177e4SLinus Torvalds # pointer-to-function 15391da177e4SLinus Torvalds print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; 15401da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 15411d7e1d45SRandy.Dunlap # bitfield 15421d7e1d45SRandy.Dunlap print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; 15431da177e4SLinus Torvalds } else { 15441da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 15451da177e4SLinus Torvalds print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; 15461da177e4SLinus Torvalds } 15471da177e4SLinus Torvalds print "\n.br\n"; 15481da177e4SLinus Torvalds } 15491da177e4SLinus Torvalds print "};\n.br\n"; 15501da177e4SLinus Torvalds 1551c51d3dacSRandy Dunlap print ".SH Members\n"; 15521da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15531da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 15541da177e4SLinus Torvalds 15551da177e4SLinus Torvalds my $parameter_name = $parameter; 15561da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15571da177e4SLinus Torvalds 15581da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 15591da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 15601da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 15611da177e4SLinus Torvalds } 15621da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15631da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15641da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15651da177e4SLinus Torvalds } 15661da177e4SLinus Torvalds} 15671da177e4SLinus Torvalds 15681da177e4SLinus Torvalds## 15691da177e4SLinus Torvalds# output typedef in man 15701da177e4SLinus Torvaldssub output_typedef_man(%) { 15711da177e4SLinus Torvalds my %args = %{$_[0]}; 15721da177e4SLinus Torvalds my ($parameter, $section); 15731da177e4SLinus Torvalds 15741da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 15751da177e4SLinus Torvalds 15761da177e4SLinus Torvalds print ".SH NAME\n"; 15771da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 15781da177e4SLinus Torvalds 15791da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15801da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15811da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15821da177e4SLinus Torvalds } 15831da177e4SLinus Torvalds} 15841da177e4SLinus Torvalds 1585b112e0f7SJohannes Bergsub output_blockhead_man(%) { 15861da177e4SLinus Torvalds my %args = %{$_[0]}; 15871da177e4SLinus Torvalds my ($parameter, $section); 15881da177e4SLinus Torvalds my $count; 15891da177e4SLinus Torvalds 15901da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 15911da177e4SLinus Torvalds 15921da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15931da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15941da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15951da177e4SLinus Torvalds } 15961da177e4SLinus Torvalds} 15971da177e4SLinus Torvalds 15981da177e4SLinus Torvalds## 15991da177e4SLinus Torvalds# output in text 16001da177e4SLinus Torvaldssub output_function_text(%) { 16011da177e4SLinus Torvalds my %args = %{$_[0]}; 16021da177e4SLinus Torvalds my ($parameter, $section); 1603a21217daSRandy Dunlap my $start; 16041da177e4SLinus Torvalds 1605f47634b2SRandy Dunlap print "Name:\n\n"; 1606f47634b2SRandy Dunlap print $args{'function'} . " - " . $args{'purpose'} . "\n"; 1607f47634b2SRandy Dunlap 1608f47634b2SRandy Dunlap print "\nSynopsis:\n\n"; 1609a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 1610a21217daSRandy Dunlap $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1611a21217daSRandy Dunlap } else { 1612a21217daSRandy Dunlap $start = $args{'function'} . " ("; 1613a21217daSRandy Dunlap } 16141da177e4SLinus Torvalds print $start; 1615a21217daSRandy Dunlap 16161da177e4SLinus Torvalds my $count = 0; 16171da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 16181da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 16191da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 16201da177e4SLinus Torvalds # pointer-to-function 16211da177e4SLinus Torvalds print $1 . $parameter . ") (" . $2; 16221da177e4SLinus Torvalds } else { 16231da177e4SLinus Torvalds print $type . " " . $parameter; 16241da177e4SLinus Torvalds } 16251da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 16261da177e4SLinus Torvalds $count++; 16271da177e4SLinus Torvalds print ",\n"; 16281da177e4SLinus Torvalds print " " x length($start); 16291da177e4SLinus Torvalds } else { 16301da177e4SLinus Torvalds print ");\n\n"; 16311da177e4SLinus Torvalds } 16321da177e4SLinus Torvalds } 16331da177e4SLinus Torvalds 16341da177e4SLinus Torvalds print "Arguments:\n\n"; 16351da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16361da177e4SLinus Torvalds my $parameter_name = $parameter; 16371da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16381da177e4SLinus Torvalds 16391da177e4SLinus Torvalds print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; 16401da177e4SLinus Torvalds } 16411da177e4SLinus Torvalds output_section_text(@_); 16421da177e4SLinus Torvalds} 16431da177e4SLinus Torvalds 16441da177e4SLinus Torvalds#output sections in text 16451da177e4SLinus Torvaldssub output_section_text(%) { 16461da177e4SLinus Torvalds my %args = %{$_[0]}; 16471da177e4SLinus Torvalds my $section; 16481da177e4SLinus Torvalds 16491da177e4SLinus Torvalds print "\n"; 16501da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16511da177e4SLinus Torvalds print "$section:\n\n"; 16521da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16531da177e4SLinus Torvalds } 16541da177e4SLinus Torvalds print "\n\n"; 16551da177e4SLinus Torvalds} 16561da177e4SLinus Torvalds 16571da177e4SLinus Torvalds# output enum in text 16581da177e4SLinus Torvaldssub output_enum_text(%) { 16591da177e4SLinus Torvalds my %args = %{$_[0]}; 16601da177e4SLinus Torvalds my ($parameter); 16611da177e4SLinus Torvalds my $count; 16621da177e4SLinus Torvalds print "Enum:\n\n"; 16631da177e4SLinus Torvalds 16641d7e1d45SRandy.Dunlap print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; 16651da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 16661da177e4SLinus Torvalds $count = 0; 16671da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16681da177e4SLinus Torvalds print "\t$parameter"; 16691da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 16701da177e4SLinus Torvalds $count++; 16711da177e4SLinus Torvalds print ","; 16721da177e4SLinus Torvalds } 16731da177e4SLinus Torvalds print "\n"; 16741da177e4SLinus Torvalds } 16751da177e4SLinus Torvalds print "};\n\n"; 16761da177e4SLinus Torvalds 16771da177e4SLinus Torvalds print "Constants:\n\n"; 16781da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16791da177e4SLinus Torvalds print "$parameter\n\t"; 16801da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter} . "\n"; 16811da177e4SLinus Torvalds } 16821da177e4SLinus Torvalds 16831da177e4SLinus Torvalds output_section_text(@_); 16841da177e4SLinus Torvalds} 16851da177e4SLinus Torvalds 16861da177e4SLinus Torvalds# output typedef in text 16871da177e4SLinus Torvaldssub output_typedef_text(%) { 16881da177e4SLinus Torvalds my %args = %{$_[0]}; 16891da177e4SLinus Torvalds my ($parameter); 16901da177e4SLinus Torvalds my $count; 16911da177e4SLinus Torvalds print "Typedef:\n\n"; 16921da177e4SLinus Torvalds 16931d7e1d45SRandy.Dunlap print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; 16941da177e4SLinus Torvalds output_section_text(@_); 16951da177e4SLinus Torvalds} 16961da177e4SLinus Torvalds 16971da177e4SLinus Torvalds# output struct as text 16981da177e4SLinus Torvaldssub output_struct_text(%) { 16991da177e4SLinus Torvalds my %args = %{$_[0]}; 17001da177e4SLinus Torvalds my ($parameter); 17011da177e4SLinus Torvalds 17021d7e1d45SRandy.Dunlap print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; 17031da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 17041da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17051da177e4SLinus Torvalds if ($parameter =~ /^#/) { 17061da177e4SLinus Torvalds print "$parameter\n"; 17071da177e4SLinus Torvalds next; 17081da177e4SLinus Torvalds } 17091da177e4SLinus Torvalds 17101da177e4SLinus Torvalds my $parameter_name = $parameter; 17111da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 17121da177e4SLinus Torvalds 17131da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 17141da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 17151da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 17161da177e4SLinus Torvalds # pointer-to-function 17171da177e4SLinus Torvalds print "\t$1 $parameter) ($2);\n"; 17181da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 171951f5a0c8SRandy Dunlap # bitfield 17201da177e4SLinus Torvalds print "\t$1 $parameter$2;\n"; 17211da177e4SLinus Torvalds } else { 17221da177e4SLinus Torvalds print "\t" . $type . " " . $parameter . ";\n"; 17231da177e4SLinus Torvalds } 17241da177e4SLinus Torvalds } 17251da177e4SLinus Torvalds print "};\n\n"; 17261da177e4SLinus Torvalds 17271da177e4SLinus Torvalds print "Members:\n\n"; 17281da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17291da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 17301da177e4SLinus Torvalds 17311da177e4SLinus Torvalds my $parameter_name = $parameter; 17321da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 17331da177e4SLinus Torvalds 17341da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 17351da177e4SLinus Torvalds print "$parameter\n\t"; 17361da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter_name} . "\n"; 17371da177e4SLinus Torvalds } 17381da177e4SLinus Torvalds print "\n"; 17391da177e4SLinus Torvalds output_section_text(@_); 17401da177e4SLinus Torvalds} 17411da177e4SLinus Torvalds 1742b112e0f7SJohannes Bergsub output_blockhead_text(%) { 17431da177e4SLinus Torvalds my %args = %{$_[0]}; 17441da177e4SLinus Torvalds my ($parameter, $section); 17451da177e4SLinus Torvalds 17461da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 17471da177e4SLinus Torvalds print " $section:\n"; 17481da177e4SLinus Torvalds print " -> "; 17491da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 17501da177e4SLinus Torvalds } 17511da177e4SLinus Torvalds} 17521da177e4SLinus Torvalds 1753c0d1b6eeSJonathan Corbet## 1754c0d1b6eeSJonathan Corbet# output in restructured text 1755c0d1b6eeSJonathan Corbet# 1756c0d1b6eeSJonathan Corbet 1757c0d1b6eeSJonathan Corbet# 1758c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 1759c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 1760c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 1761c0d1b6eeSJonathan Corbet# 1762c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 1763c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1764c0d1b6eeSJonathan Corbet my ($parameter, $section); 1765c0d1b6eeSJonathan Corbet 1766c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 17679e72184bSJani Nikula if ($output_selection != OUTPUT_INCLUDE) { 1768c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 17699e72184bSJani Nikula } 1770c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1771c0d1b6eeSJonathan Corbet print "\n"; 1772c0d1b6eeSJonathan Corbet } 1773c0d1b6eeSJonathan Corbet} 1774c0d1b6eeSJonathan Corbet 1775c0d1b6eeSJonathan Corbetsub output_highlight_rst { 1776c0d1b6eeSJonathan Corbet my $contents = join "\n",@_; 1777c0d1b6eeSJonathan Corbet my $line; 1778c0d1b6eeSJonathan Corbet 1779c0d1b6eeSJonathan Corbet # undo the evil effects of xml_escape() earlier 1780c0d1b6eeSJonathan Corbet $contents = xml_unescape($contents); 1781c0d1b6eeSJonathan Corbet 1782c0d1b6eeSJonathan Corbet eval $dohighlight; 1783c0d1b6eeSJonathan Corbet die $@ if $@; 1784c0d1b6eeSJonathan Corbet 1785c0d1b6eeSJonathan Corbet foreach $line (split "\n", $contents) { 1786c0d1b6eeSJonathan Corbet if ($line eq "") { 1787c0d1b6eeSJonathan Corbet print $lineprefix, $blankline; 1788c0d1b6eeSJonathan Corbet } else { 1789c0d1b6eeSJonathan Corbet $line =~ s/\\\\\\/\&/g; 1790c0d1b6eeSJonathan Corbet print $lineprefix, $line; 1791c0d1b6eeSJonathan Corbet } 1792c0d1b6eeSJonathan Corbet print "\n"; 1793c0d1b6eeSJonathan Corbet } 1794c0d1b6eeSJonathan Corbet} 1795c0d1b6eeSJonathan Corbet 1796c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 1797c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1798c0d1b6eeSJonathan Corbet my ($parameter, $section); 1799c0d1b6eeSJonathan Corbet my $start; 1800c0d1b6eeSJonathan Corbet 1801c0d1b6eeSJonathan Corbet print ".. c:function:: "; 1802c0d1b6eeSJonathan Corbet if ($args{'functiontype'} ne "") { 1803c0d1b6eeSJonathan Corbet $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1804c0d1b6eeSJonathan Corbet } else { 1805c0d1b6eeSJonathan Corbet $start = $args{'function'} . " ("; 1806c0d1b6eeSJonathan Corbet } 1807c0d1b6eeSJonathan Corbet print $start; 1808c0d1b6eeSJonathan Corbet 1809c0d1b6eeSJonathan Corbet my $count = 0; 1810c0d1b6eeSJonathan Corbet foreach my $parameter (@{$args{'parameterlist'}}) { 1811c0d1b6eeSJonathan Corbet if ($count ne 0) { 1812c0d1b6eeSJonathan Corbet print ", "; 1813c0d1b6eeSJonathan Corbet } 1814c0d1b6eeSJonathan Corbet $count++; 1815c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1816c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1817c0d1b6eeSJonathan Corbet # pointer-to-function 1818c0d1b6eeSJonathan Corbet print $1 . $parameter . ") (" . $2; 1819c0d1b6eeSJonathan Corbet } else { 1820c0d1b6eeSJonathan Corbet print $type . " " . $parameter; 1821c0d1b6eeSJonathan Corbet } 1822c0d1b6eeSJonathan Corbet } 1823c0d1b6eeSJonathan Corbet print ")\n\n " . $args{'purpose'} . "\n\n"; 1824c0d1b6eeSJonathan Corbet 1825c0d1b6eeSJonathan Corbet print ":Parameters:\n\n"; 1826c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1827c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1828c0d1b6eeSJonathan Corbet #$parameter_name =~ s/\[.*//; 1829c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1830c0d1b6eeSJonathan Corbet 1831c0d1b6eeSJonathan Corbet if ($type ne "") { 1832c0d1b6eeSJonathan Corbet print " ``$type $parameter``\n"; 1833c0d1b6eeSJonathan Corbet } else { 1834c0d1b6eeSJonathan Corbet print " ``$parameter``\n"; 1835c0d1b6eeSJonathan Corbet } 18365e64fa9cSJani Nikula if (defined($args{'parameterdescs'}{$parameter_name}) && 18375e64fa9cSJani Nikula $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 1838c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1839c0d1b6eeSJonathan Corbet $lineprefix = " "; 1840c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1841c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1842c0d1b6eeSJonathan Corbet } else { 1843c0d1b6eeSJonathan Corbet print "\n _undescribed_\n"; 1844c0d1b6eeSJonathan Corbet } 1845c0d1b6eeSJonathan Corbet print "\n"; 1846c0d1b6eeSJonathan Corbet } 1847c0d1b6eeSJonathan Corbet output_section_rst(@_); 1848c0d1b6eeSJonathan Corbet} 1849c0d1b6eeSJonathan Corbet 1850c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 1851c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1852c0d1b6eeSJonathan Corbet my $section; 1853c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1854c0d1b6eeSJonathan Corbet $lineprefix = " "; 1855c0d1b6eeSJonathan Corbet 1856c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 1857c0d1b6eeSJonathan Corbet print ":$section:\n\n"; 1858c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1859c0d1b6eeSJonathan Corbet print "\n"; 1860c0d1b6eeSJonathan Corbet } 1861c0d1b6eeSJonathan Corbet print "\n"; 1862c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1863c0d1b6eeSJonathan Corbet} 1864c0d1b6eeSJonathan Corbet 1865c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 1866c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1867c0d1b6eeSJonathan Corbet my ($parameter); 1868c0d1b6eeSJonathan Corbet my $count; 1869c0d1b6eeSJonathan Corbet my $name = "enum " . $args{'enum'}; 187062850976SJani Nikula 187162850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1872c0d1b6eeSJonathan Corbet print " " . $args{'purpose'} . "\n\n"; 1873c0d1b6eeSJonathan Corbet 1874c0d1b6eeSJonathan Corbet print "..\n\n:Constants:\n\n"; 1875c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1876c0d1b6eeSJonathan Corbet $lineprefix = " "; 1877c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1878c0d1b6eeSJonathan Corbet print " `$parameter`\n"; 1879c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 1880c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 1881c0d1b6eeSJonathan Corbet } else { 1882c0d1b6eeSJonathan Corbet print " undescribed\n"; 1883c0d1b6eeSJonathan Corbet } 1884c0d1b6eeSJonathan Corbet print "\n"; 1885c0d1b6eeSJonathan Corbet } 1886c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1887c0d1b6eeSJonathan Corbet output_section_rst(@_); 1888c0d1b6eeSJonathan Corbet} 1889c0d1b6eeSJonathan Corbet 1890c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 1891c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1892c0d1b6eeSJonathan Corbet my ($parameter); 1893c0d1b6eeSJonathan Corbet my $count; 1894c0d1b6eeSJonathan Corbet my $name = "typedef " . $args{'typedef'}; 1895c0d1b6eeSJonathan Corbet 189662850976SJani Nikula ### FIXME: should the name below contain "typedef" or not? 189762850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 189862850976SJani Nikula print " " . $args{'purpose'} . "\n\n"; 1899c0d1b6eeSJonathan Corbet 1900c0d1b6eeSJonathan Corbet output_section_rst(@_); 1901c0d1b6eeSJonathan Corbet} 1902c0d1b6eeSJonathan Corbet 1903c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 1904c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1905c0d1b6eeSJonathan Corbet my ($parameter); 1906c0d1b6eeSJonathan Corbet my $name = $args{'type'} . " " . $args{'struct'}; 1907c0d1b6eeSJonathan Corbet 190862850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1909c0d1b6eeSJonathan Corbet print " " . $args{'purpose'} . "\n\n"; 1910c0d1b6eeSJonathan Corbet 1911c0d1b6eeSJonathan Corbet print ":Definition:\n\n"; 1912c0d1b6eeSJonathan Corbet print " ::\n\n"; 1913c0d1b6eeSJonathan Corbet print " " . $args{'type'} . " " . $args{'struct'} . " {\n"; 1914c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1915c0d1b6eeSJonathan Corbet if ($parameter =~ /^#/) { 1916c0d1b6eeSJonathan Corbet print " " . "$parameter\n"; 1917c0d1b6eeSJonathan Corbet next; 1918c0d1b6eeSJonathan Corbet } 1919c0d1b6eeSJonathan Corbet 1920c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1921c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 1922c0d1b6eeSJonathan Corbet 1923c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1924c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1925c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1926c0d1b6eeSJonathan Corbet # pointer-to-function 1927c0d1b6eeSJonathan Corbet print " $1 $parameter) ($2);\n"; 1928c0d1b6eeSJonathan Corbet } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 1929c0d1b6eeSJonathan Corbet # bitfield 1930c0d1b6eeSJonathan Corbet print " $1 $parameter$2;\n"; 1931c0d1b6eeSJonathan Corbet } else { 1932c0d1b6eeSJonathan Corbet print " " . $type . " " . $parameter . ";\n"; 1933c0d1b6eeSJonathan Corbet } 1934c0d1b6eeSJonathan Corbet } 1935c0d1b6eeSJonathan Corbet print " };\n\n"; 1936c0d1b6eeSJonathan Corbet 1937c0d1b6eeSJonathan Corbet print ":Members:\n\n"; 1938c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1939c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 1940c0d1b6eeSJonathan Corbet 1941c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1942c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 1943c0d1b6eeSJonathan Corbet 1944c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1945c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1946c0d1b6eeSJonathan Corbet print " `$type $parameter`" . "\n"; 1947c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1948c0d1b6eeSJonathan Corbet $lineprefix = " "; 1949c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1950c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1951c0d1b6eeSJonathan Corbet print "\n"; 1952c0d1b6eeSJonathan Corbet } 1953c0d1b6eeSJonathan Corbet print "\n"; 1954c0d1b6eeSJonathan Corbet output_section_rst(@_); 1955c0d1b6eeSJonathan Corbet} 1956c0d1b6eeSJonathan Corbet 1957c0d1b6eeSJonathan Corbet 1958eda603f6SJohannes Berg## list mode output functions 1959eda603f6SJohannes Berg 1960eda603f6SJohannes Bergsub output_function_list(%) { 1961eda603f6SJohannes Berg my %args = %{$_[0]}; 1962eda603f6SJohannes Berg 1963eda603f6SJohannes Berg print $args{'function'} . "\n"; 1964eda603f6SJohannes Berg} 1965eda603f6SJohannes Berg 1966eda603f6SJohannes Berg# output enum in list 1967eda603f6SJohannes Bergsub output_enum_list(%) { 1968eda603f6SJohannes Berg my %args = %{$_[0]}; 1969eda603f6SJohannes Berg print $args{'enum'} . "\n"; 1970eda603f6SJohannes Berg} 1971eda603f6SJohannes Berg 1972eda603f6SJohannes Berg# output typedef in list 1973eda603f6SJohannes Bergsub output_typedef_list(%) { 1974eda603f6SJohannes Berg my %args = %{$_[0]}; 1975eda603f6SJohannes Berg print $args{'typedef'} . "\n"; 1976eda603f6SJohannes Berg} 1977eda603f6SJohannes Berg 1978eda603f6SJohannes Berg# output struct as list 1979eda603f6SJohannes Bergsub output_struct_list(%) { 1980eda603f6SJohannes Berg my %args = %{$_[0]}; 1981eda603f6SJohannes Berg 1982eda603f6SJohannes Berg print $args{'struct'} . "\n"; 1983eda603f6SJohannes Berg} 1984eda603f6SJohannes Berg 1985eda603f6SJohannes Bergsub output_blockhead_list(%) { 1986eda603f6SJohannes Berg my %args = %{$_[0]}; 1987eda603f6SJohannes Berg my ($parameter, $section); 1988eda603f6SJohannes Berg 1989eda603f6SJohannes Berg foreach $section (@{$args{'sectionlist'}}) { 1990eda603f6SJohannes Berg print "DOC: $section\n"; 1991eda603f6SJohannes Berg } 1992eda603f6SJohannes Berg} 1993eda603f6SJohannes Berg 19941da177e4SLinus Torvalds## 199527205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 199627205744SRandy Dunlap# calls the generated, variable output_ function name based on 199727205744SRandy Dunlap# functype and output_mode 19981da177e4SLinus Torvaldssub output_declaration { 19991da177e4SLinus Torvalds no strict 'refs'; 20001da177e4SLinus Torvalds my $name = shift; 20011da177e4SLinus Torvalds my $functype = shift; 20021da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 2003b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 2004b6c3f456SJani Nikula (($output_selection == OUTPUT_INCLUDE || 2005b6c3f456SJani Nikula $output_selection == OUTPUT_EXPORTED) && 200686ae2e38SJani Nikula defined($function_table{$name})) || 2007b6c3f456SJani Nikula (($output_selection == OUTPUT_EXCLUDE || 2008b6c3f456SJani Nikula $output_selection == OUTPUT_INTERNAL) && 200986ae2e38SJani Nikula !($functype eq "function" && defined($function_table{$name})))) 20101da177e4SLinus Torvalds { 20111da177e4SLinus Torvalds &$func(@_); 20121da177e4SLinus Torvalds $section_counter++; 20131da177e4SLinus Torvalds } 20141da177e4SLinus Torvalds} 20151da177e4SLinus Torvalds 20161da177e4SLinus Torvalds## 201727205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 2018b112e0f7SJohannes Bergsub output_blockhead { 20191da177e4SLinus Torvalds no strict 'refs'; 2020b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 20211da177e4SLinus Torvalds &$func(@_); 20221da177e4SLinus Torvalds $section_counter++; 20231da177e4SLinus Torvalds} 20241da177e4SLinus Torvalds 20251da177e4SLinus Torvalds## 20261da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 20271da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 20281da177e4SLinus Torvaldssub dump_declaration($$) { 20291da177e4SLinus Torvalds no strict 'refs'; 20301da177e4SLinus Torvalds my ($prototype, $file) = @_; 20311da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 20321da177e4SLinus Torvalds &$func(@_); 20331da177e4SLinus Torvalds} 20341da177e4SLinus Torvalds 20351da177e4SLinus Torvaldssub dump_union($$) { 20361da177e4SLinus Torvalds dump_struct(@_); 20371da177e4SLinus Torvalds} 20381da177e4SLinus Torvalds 20391da177e4SLinus Torvaldssub dump_struct($$) { 20401da177e4SLinus Torvalds my $x = shift; 20411da177e4SLinus Torvalds my $file = shift; 2042a1d94aa5SRandy Dunlap my $nested; 20431da177e4SLinus Torvalds 20441da177e4SLinus Torvalds if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 204552dc5aecSRandy Dunlap #my $decl_type = $1; 20461da177e4SLinus Torvalds $declaration_name = $2; 20471da177e4SLinus Torvalds my $members = $3; 20481da177e4SLinus Torvalds 20491da177e4SLinus Torvalds # ignore embedded structs or unions 2050a1d94aa5SRandy Dunlap $members =~ s/({.*})//g; 2051a1d94aa5SRandy Dunlap $nested = $1; 20521da177e4SLinus Torvalds 2053aeec46b9SMartin Waitz # ignore members marked private: 20540d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 20550d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 2056aeec46b9SMartin Waitz # strip comments: 2057aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 2058a1d94aa5SRandy Dunlap $nested =~ s/\/\*.*?\*\///gos; 2059d960eea9SRandy Dunlap # strip kmemcheck_bitfield_{begin,end}.*; 2060d960eea9SRandy Dunlap $members =~ s/kmemcheck_bitfield_.*?;//gos; 2061ef5da59fSRandy Dunlap # strip attributes 2062f0074929SJonathan Corbet $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 20637b990789SJohannes Berg $members =~ s/__aligned\s*\([^;]*\)//gos; 2064f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; 2065b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 2066b22b5a9eSConchúr Navid $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 2067aeec46b9SMartin Waitz 20681da177e4SLinus Torvalds create_parameterlist($members, ';', $file); 2069a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); 20701da177e4SLinus Torvalds 20711da177e4SLinus Torvalds output_declaration($declaration_name, 20721da177e4SLinus Torvalds 'struct', 20731da177e4SLinus Torvalds {'struct' => $declaration_name, 20741da177e4SLinus Torvalds 'module' => $modulename, 20751da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 20761da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 20771da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 20781da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 20791da177e4SLinus Torvalds 'sections' => \%sections, 20801da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 20811da177e4SLinus Torvalds 'type' => $decl_type 20821da177e4SLinus Torvalds }); 20831da177e4SLinus Torvalds } 20841da177e4SLinus Torvalds else { 2085d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 20861da177e4SLinus Torvalds ++$errors; 20871da177e4SLinus Torvalds } 20881da177e4SLinus Torvalds} 20891da177e4SLinus Torvalds 20901da177e4SLinus Torvaldssub dump_enum($$) { 20911da177e4SLinus Torvalds my $x = shift; 20921da177e4SLinus Torvalds my $file = shift; 20931da177e4SLinus Torvalds 2094aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 20954468e21eSConchúr Navid # strip #define macros inside enums 20964468e21eSConchúr Navid $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 2097b6d676dbSRandy Dunlap 20981da177e4SLinus Torvalds if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 20991da177e4SLinus Torvalds $declaration_name = $1; 21001da177e4SLinus Torvalds my $members = $2; 21011da177e4SLinus Torvalds 21021da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 21031da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 21041da177e4SLinus Torvalds push @parameterlist, $arg; 21051da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 21061da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 2107d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Enum value '$arg' ". 21081da177e4SLinus Torvalds "not described in enum '$declaration_name'\n"; 21091da177e4SLinus Torvalds } 21101da177e4SLinus Torvalds 21111da177e4SLinus Torvalds } 21121da177e4SLinus Torvalds 21131da177e4SLinus Torvalds output_declaration($declaration_name, 21141da177e4SLinus Torvalds 'enum', 21151da177e4SLinus Torvalds {'enum' => $declaration_name, 21161da177e4SLinus Torvalds 'module' => $modulename, 21171da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 21181da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 21191da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 21201da177e4SLinus Torvalds 'sections' => \%sections, 21211da177e4SLinus Torvalds 'purpose' => $declaration_purpose 21221da177e4SLinus Torvalds }); 21231da177e4SLinus Torvalds } 21241da177e4SLinus Torvalds else { 2125d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 21261da177e4SLinus Torvalds ++$errors; 21271da177e4SLinus Torvalds } 21281da177e4SLinus Torvalds} 21291da177e4SLinus Torvalds 21301da177e4SLinus Torvaldssub dump_typedef($$) { 21311da177e4SLinus Torvalds my $x = shift; 21321da177e4SLinus Torvalds my $file = shift; 21331da177e4SLinus Torvalds 2134aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 213583766452SMauro Carvalho Chehab 213683766452SMauro Carvalho Chehab # Parse function prototypes 213783766452SMauro Carvalho Chehab if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) { 213883766452SMauro Carvalho Chehab # Function typedefs 213983766452SMauro Carvalho Chehab $return_type = $1; 214083766452SMauro Carvalho Chehab $declaration_name = $2; 214183766452SMauro Carvalho Chehab my $args = $3; 214283766452SMauro Carvalho Chehab 214383766452SMauro Carvalho Chehab create_parameterlist($args, ',', $file); 214483766452SMauro Carvalho Chehab 214583766452SMauro Carvalho Chehab output_declaration($declaration_name, 214683766452SMauro Carvalho Chehab 'function', 214783766452SMauro Carvalho Chehab {'function' => $declaration_name, 214883766452SMauro Carvalho Chehab 'module' => $modulename, 214983766452SMauro Carvalho Chehab 'functiontype' => $return_type, 215083766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 215183766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 215283766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 215383766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 215483766452SMauro Carvalho Chehab 'sections' => \%sections, 215583766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 215683766452SMauro Carvalho Chehab }); 215783766452SMauro Carvalho Chehab return; 215883766452SMauro Carvalho Chehab } 215983766452SMauro Carvalho Chehab 21601da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 21611da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 21621da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 21631da177e4SLinus Torvalds } 21641da177e4SLinus Torvalds 21651da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 21661da177e4SLinus Torvalds $declaration_name = $1; 21671da177e4SLinus Torvalds 21681da177e4SLinus Torvalds output_declaration($declaration_name, 21691da177e4SLinus Torvalds 'typedef', 21701da177e4SLinus Torvalds {'typedef' => $declaration_name, 21711da177e4SLinus Torvalds 'module' => $modulename, 21721da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 21731da177e4SLinus Torvalds 'sections' => \%sections, 21741da177e4SLinus Torvalds 'purpose' => $declaration_purpose 21751da177e4SLinus Torvalds }); 21761da177e4SLinus Torvalds } 21771da177e4SLinus Torvalds else { 2178d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 21791da177e4SLinus Torvalds ++$errors; 21801da177e4SLinus Torvalds } 21811da177e4SLinus Torvalds} 21821da177e4SLinus Torvalds 2183a1d94aa5SRandy Dunlapsub save_struct_actual($) { 2184a1d94aa5SRandy Dunlap my $actual = shift; 2185a1d94aa5SRandy Dunlap 2186a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 2187a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 2188a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 2189a1d94aa5SRandy Dunlap} 2190a1d94aa5SRandy Dunlap 21911da177e4SLinus Torvaldssub create_parameterlist($$$) { 21921da177e4SLinus Torvalds my $args = shift; 21931da177e4SLinus Torvalds my $splitter = shift; 21941da177e4SLinus Torvalds my $file = shift; 21951da177e4SLinus Torvalds my $type; 21961da177e4SLinus Torvalds my $param; 21971da177e4SLinus Torvalds 2198a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 21991da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 22001da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 22011da177e4SLinus Torvalds } 22021da177e4SLinus Torvalds 22031da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 22041da177e4SLinus Torvalds # strip comments 22051da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 22061da177e4SLinus Torvalds # strip leading/trailing spaces 22071da177e4SLinus Torvalds $arg =~ s/^\s*//; 22081da177e4SLinus Torvalds $arg =~ s/\s*$//; 22091da177e4SLinus Torvalds $arg =~ s/\s+/ /; 22101da177e4SLinus Torvalds 22111da177e4SLinus Torvalds if ($arg =~ /^#/) { 22121da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 22131da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 22141da177e4SLinus Torvalds # output_* subs. 22151da177e4SLinus Torvalds push_parameter($arg, "", $file); 221600d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 22171da177e4SLinus Torvalds # pointer-to-function 22181da177e4SLinus Torvalds $arg =~ tr/#/,/; 221900d62961SRichard Kennedy $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 22201da177e4SLinus Torvalds $param = $1; 22211da177e4SLinus Torvalds $type = $arg; 222200d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 2223a1d94aa5SRandy Dunlap save_struct_actual($param); 22241da177e4SLinus Torvalds push_parameter($param, $type, $file); 2225aeec46b9SMartin Waitz } elsif ($arg) { 22261da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 22271da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 22281da177e4SLinus Torvalds 22291da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 22301da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 22311da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 22321da177e4SLinus Torvalds } 2233884f2810SBorislav Petkov 2234884f2810SBorislav Petkov my @first_arg; 2235884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 2236884f2810SBorislav Petkov shift @args; 2237884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 2238884f2810SBorislav Petkov push(@first_arg, $2); 2239884f2810SBorislav Petkov } else { 2240884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 2241884f2810SBorislav Petkov } 2242884f2810SBorislav Petkov 22431da177e4SLinus Torvalds unshift(@args, pop @first_arg); 22441da177e4SLinus Torvalds $type = join " ", @first_arg; 22451da177e4SLinus Torvalds 22461da177e4SLinus Torvalds foreach $param (@args) { 22471da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 2248a1d94aa5SRandy Dunlap save_struct_actual($2); 22491da177e4SLinus Torvalds push_parameter($2, "$type $1", $file); 22501da177e4SLinus Torvalds } 22511da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 22527b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 2253a1d94aa5SRandy Dunlap save_struct_actual($1); 22541da177e4SLinus Torvalds push_parameter($1, "$type:$2", $file) 22551da177e4SLinus Torvalds } 22567b97887eSRandy Dunlap } 22571da177e4SLinus Torvalds else { 2258a1d94aa5SRandy Dunlap save_struct_actual($param); 22591da177e4SLinus Torvalds push_parameter($param, $type, $file); 22601da177e4SLinus Torvalds } 22611da177e4SLinus Torvalds } 22621da177e4SLinus Torvalds } 22631da177e4SLinus Torvalds } 22641da177e4SLinus Torvalds} 22651da177e4SLinus Torvalds 22661da177e4SLinus Torvaldssub push_parameter($$$) { 22671da177e4SLinus Torvalds my $param = shift; 22681da177e4SLinus Torvalds my $type = shift; 22691da177e4SLinus Torvalds my $file = shift; 22701da177e4SLinus Torvalds 22715f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 22725f8c7c98SRandy Dunlap ($param eq "}")) { 22735f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 22745f8c7c98SRandy Dunlap } 22755f8c7c98SRandy Dunlap 22765f8c7c98SRandy Dunlap $anon_struct_union = 0; 22771da177e4SLinus Torvalds my $param_name = $param; 22781da177e4SLinus Torvalds $param_name =~ s/\[.*//; 22791da177e4SLinus Torvalds 2280a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 22811da177e4SLinus Torvalds { 2282ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 2283a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 22841da177e4SLinus Torvalds } 2285ced69090SRandy Dunlap } 22861da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 22871da177e4SLinus Torvalds { 22881da177e4SLinus Torvalds $param="void"; 22891da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 22901da177e4SLinus Torvalds } 2291134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 2292134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 2293134fe01bSRandy Dunlap { 2294134fe01bSRandy Dunlap $type = $param; 2295134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 2296134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 22975f8c7c98SRandy Dunlap $anon_struct_union = 1; 2298134fe01bSRandy Dunlap } 2299134fe01bSRandy Dunlap 2300a6d3fe77SMartin Waitz # warn if parameter has no description 2301134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 2302134fe01bSRandy Dunlap # but inline preprocessor statements); 2303134fe01bSRandy Dunlap # also ignore unnamed structs/unions; 23045f8c7c98SRandy Dunlap if (!$anon_struct_union) { 2305a6d3fe77SMartin Waitz if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { 2306a6d3fe77SMartin Waitz 23071da177e4SLinus Torvalds $parameterdescs{$param_name} = $undescribed; 23081da177e4SLinus Torvalds 23091da177e4SLinus Torvalds if (($type eq 'function') || ($type eq 'enum')) { 2310d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Function parameter ". 23111da177e4SLinus Torvalds "or member '$param' not " . 23121da177e4SLinus Torvalds "described in '$declaration_name'\n"; 23131da177e4SLinus Torvalds } 2314d40e1e65SBart Van Assche print STDERR "${file}:$.: warning:" . 23151da177e4SLinus Torvalds " No description found for parameter '$param'\n"; 23161da177e4SLinus Torvalds ++$warnings; 23171da177e4SLinus Torvalds } 2318134fe01bSRandy Dunlap } 23191da177e4SLinus Torvalds 23202b35f4d9SRandy Dunlap $param = xml_escape($param); 23212b35f4d9SRandy Dunlap 232225985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 2323e34e7dbbSRandy Dunlap # on @parameterlist; 2324e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 2325e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 2326e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 2327e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 2328e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 2329e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 2330e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 23311da177e4SLinus Torvalds push @parameterlist, $param; 23321da177e4SLinus Torvalds $parametertypes{$param} = $type; 23331da177e4SLinus Torvalds} 23341da177e4SLinus Torvalds 2335a1d94aa5SRandy Dunlapsub check_sections($$$$$$) { 2336a1d94aa5SRandy Dunlap my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; 2337a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 2338a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 2339a1d94aa5SRandy Dunlap my $err; 2340a1d94aa5SRandy Dunlap my ($px, $sx); 2341a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 2342a1d94aa5SRandy Dunlap 2343a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 2344a1d94aa5SRandy Dunlap $err = 1; 2345a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 2346a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 2347a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 23481f3a6688SJohannes Berg $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 2349e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 2350e34e7dbbSRandy Dunlap # however, the original param string may contain 2351e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 2352e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 2353e34e7dbbSRandy Dunlap # parameter list is split at spaces; 2354e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 2355e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 2356e34e7dbbSRandy Dunlap 2357a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 2358a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 2359a1d94aa5SRandy Dunlap $err = 0; 2360a1d94aa5SRandy Dunlap last; 2361a1d94aa5SRandy Dunlap } 2362a1d94aa5SRandy Dunlap } 2363a1d94aa5SRandy Dunlap if ($err) { 2364a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 2365d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2366a1d94aa5SRandy Dunlap "Excess function parameter " . 2367a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2368a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2369a1d94aa5SRandy Dunlap ++$warnings; 2370a1d94aa5SRandy Dunlap } else { 2371a1d94aa5SRandy Dunlap if ($nested !~ m/\Q$sects[$sx]\E/) { 2372d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2373a1d94aa5SRandy Dunlap "Excess struct/union/enum/typedef member " . 2374a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2375a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2376a1d94aa5SRandy Dunlap ++$warnings; 2377a1d94aa5SRandy Dunlap } 2378a1d94aa5SRandy Dunlap } 2379a1d94aa5SRandy Dunlap } 2380a1d94aa5SRandy Dunlap } 2381a1d94aa5SRandy Dunlap} 2382a1d94aa5SRandy Dunlap 23831da177e4SLinus Torvalds## 23844092bac7SYacine Belkadi# Checks the section describing the return value of a function. 23854092bac7SYacine Belkadisub check_return_section { 23864092bac7SYacine Belkadi my $file = shift; 23874092bac7SYacine Belkadi my $declaration_name = shift; 23884092bac7SYacine Belkadi my $return_type = shift; 23894092bac7SYacine Belkadi 23904092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 23914092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 23924092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 23934092bac7SYacine Belkadi return; 23944092bac7SYacine Belkadi } 23954092bac7SYacine Belkadi 23964092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 23974092bac7SYacine Belkadi $sections{$section_return} eq "") { 2398d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 23994092bac7SYacine Belkadi "No description found for return value of " . 24004092bac7SYacine Belkadi "'$declaration_name'\n"; 24014092bac7SYacine Belkadi ++$warnings; 24024092bac7SYacine Belkadi } 24034092bac7SYacine Belkadi} 24044092bac7SYacine Belkadi 24054092bac7SYacine Belkadi## 24061da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 24071da177e4SLinus Torvalds# processed and spits out all the details stored in the global 24081da177e4SLinus Torvalds# arrays/hashes. 24091da177e4SLinus Torvaldssub dump_function($$) { 24101da177e4SLinus Torvalds my $prototype = shift; 24111da177e4SLinus Torvalds my $file = shift; 2412cbb4d3e6SHoria Geanta my $noret = 0; 24131da177e4SLinus Torvalds 24141da177e4SLinus Torvalds $prototype =~ s/^static +//; 24151da177e4SLinus Torvalds $prototype =~ s/^extern +//; 24164dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 24171da177e4SLinus Torvalds $prototype =~ s/^inline +//; 24181da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 241932e79401SRandy Dunlap $prototype =~ s/^__inline +//; 242032e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 242132e79401SRandy Dunlap $prototype =~ s/^noinline +//; 242274fc5c65SRandy Dunlap $prototype =~ s/__init +//; 242320072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 2424270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 242570c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 24260df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 2427cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 2428328d2440SRandy Dunlap $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; 24291da177e4SLinus Torvalds 24301da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 24311da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 24321da177e4SLinus Torvalds # 2. Function name 24331da177e4SLinus Torvalds # 3. Function parameters. 24341da177e4SLinus Torvalds # 24351da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 24361da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 24371da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 24381da177e4SLinus Torvalds # so on. 24391da177e4SLinus Torvalds # 24401da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 24411da177e4SLinus Torvalds # the following functions' documentation still comes out right: 24421da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 24431da177e4SLinus Torvalds # - atomic_set (macro) 24449598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 24451da177e4SLinus Torvalds 2446cbb4d3e6SHoria Geanta if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 2447cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 2448cbb4d3e6SHoria Geanta # list. 2449cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 2450cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 2451cbb4d3e6SHoria Geanta $return_type = $1; 2452cbb4d3e6SHoria Geanta $declaration_name = $2; 2453cbb4d3e6SHoria Geanta $noret = 1; 2454cbb4d3e6SHoria Geanta } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24551da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24561da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24571da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 245894b3e03cSRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24591da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24601da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24611da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24621da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24631da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24641da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24651da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24661da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24679598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24689598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2469412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2470412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 24711da177e4SLinus Torvalds $return_type = $1; 24721da177e4SLinus Torvalds $declaration_name = $2; 24731da177e4SLinus Torvalds my $args = $3; 24741da177e4SLinus Torvalds 24751da177e4SLinus Torvalds create_parameterlist($args, ',', $file); 24761da177e4SLinus Torvalds } else { 2477d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 24781da177e4SLinus Torvalds return; 24791da177e4SLinus Torvalds } 24801da177e4SLinus Torvalds 2481a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 2482a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); 2483a1d94aa5SRandy Dunlap 24844092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 24854092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 24864092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 24874092bac7SYacine Belkadi # verbose mode. 24884092bac7SYacine Belkadi # TODO: always perform the check. 2489cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 24904092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 24914092bac7SYacine Belkadi } 24924092bac7SYacine Belkadi 24931da177e4SLinus Torvalds output_declaration($declaration_name, 24941da177e4SLinus Torvalds 'function', 24951da177e4SLinus Torvalds {'function' => $declaration_name, 24961da177e4SLinus Torvalds 'module' => $modulename, 24971da177e4SLinus Torvalds 'functiontype' => $return_type, 24981da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 24991da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 25001da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 25011da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 25021da177e4SLinus Torvalds 'sections' => \%sections, 25031da177e4SLinus Torvalds 'purpose' => $declaration_purpose 25041da177e4SLinus Torvalds }); 25051da177e4SLinus Torvalds} 25061da177e4SLinus Torvalds 25071da177e4SLinus Torvaldssub reset_state { 25081da177e4SLinus Torvalds $function = ""; 25091da177e4SLinus Torvalds %constants = (); 25101da177e4SLinus Torvalds %parameterdescs = (); 25111da177e4SLinus Torvalds %parametertypes = (); 25121da177e4SLinus Torvalds @parameterlist = (); 25131da177e4SLinus Torvalds %sections = (); 25141da177e4SLinus Torvalds @sectionlist = (); 2515a1d94aa5SRandy Dunlap $sectcheck = ""; 2516a1d94aa5SRandy Dunlap $struct_actual = ""; 25171da177e4SLinus Torvalds $prototype = ""; 25181da177e4SLinus Torvalds 251948af606aSJani Nikula $state = STATE_NORMAL; 252048af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 25211da177e4SLinus Torvalds} 25221da177e4SLinus Torvalds 252356afb0f8SJason Baronsub tracepoint_munge($) { 252456afb0f8SJason Baron my $file = shift; 252556afb0f8SJason Baron my $tracepointname = 0; 252656afb0f8SJason Baron my $tracepointargs = 0; 252756afb0f8SJason Baron 252856afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 252956afb0f8SJason Baron $tracepointname = $1; 253056afb0f8SJason Baron } 25313a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 25323a9089fdSJason Baron $tracepointname = $1; 25333a9089fdSJason Baron } 25343a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 25353a9089fdSJason Baron $tracepointname = $2; 25363a9089fdSJason Baron } 25373a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 253856afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 253956afb0f8SJason Baron $tracepointargs = $1; 254056afb0f8SJason Baron } 254156afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 2542d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 254356afb0f8SJason Baron "$prototype\n"; 254456afb0f8SJason Baron } else { 254556afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 254656afb0f8SJason Baron } 254756afb0f8SJason Baron} 254856afb0f8SJason Baron 2549b4870bc5SRandy Dunlapsub syscall_munge() { 2550b4870bc5SRandy Dunlap my $void = 0; 2551b4870bc5SRandy Dunlap 2552b4870bc5SRandy Dunlap $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs 2553b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 2554b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 2555b4870bc5SRandy Dunlap $void = 1; 2556b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 2557b4870bc5SRandy Dunlap } 2558b4870bc5SRandy Dunlap 2559b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 2560b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 2561b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 2562b4870bc5SRandy Dunlap } elsif ($void) { 2563b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 2564b4870bc5SRandy Dunlap } 2565b4870bc5SRandy Dunlap 2566b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 2567b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 2568b4870bc5SRandy Dunlap my $count = 0; 2569b4870bc5SRandy Dunlap my $len = length($prototype); 2570b4870bc5SRandy Dunlap if ($void) { 2571b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 2572b4870bc5SRandy Dunlap } 2573b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 2574b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 2575b4870bc5SRandy Dunlap $count++; 2576b4870bc5SRandy Dunlap if ($count % 2 == 1) { 2577b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 2578b4870bc5SRandy Dunlap } 2579b4870bc5SRandy Dunlap } 2580b4870bc5SRandy Dunlap } 2581b4870bc5SRandy Dunlap} 2582b4870bc5SRandy Dunlap 25831da177e4SLinus Torvaldssub process_state3_function($$) { 25841da177e4SLinus Torvalds my $x = shift; 25851da177e4SLinus Torvalds my $file = shift; 25861da177e4SLinus Torvalds 258751f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 258851f5a0c8SRandy Dunlap 2589890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 25901da177e4SLinus Torvalds # do nothing 25911da177e4SLinus Torvalds } 25921da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 25931da177e4SLinus Torvalds $prototype .= $1; 25941da177e4SLinus Torvalds } 2595b4870bc5SRandy Dunlap 2596890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 25971da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 25981da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 25991da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 2600b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 2601b4870bc5SRandy Dunlap syscall_munge(); 2602b4870bc5SRandy Dunlap } 26033a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 26043a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 26053a9089fdSJason Baron { 260656afb0f8SJason Baron tracepoint_munge($file); 260756afb0f8SJason Baron } 26081da177e4SLinus Torvalds dump_function($prototype, $file); 26091da177e4SLinus Torvalds reset_state(); 26101da177e4SLinus Torvalds } 26111da177e4SLinus Torvalds} 26121da177e4SLinus Torvalds 26131da177e4SLinus Torvaldssub process_state3_type($$) { 26141da177e4SLinus Torvalds my $x = shift; 26151da177e4SLinus Torvalds my $file = shift; 26161da177e4SLinus Torvalds 26171da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 26181da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 26191da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 262051f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 262151f5a0c8SRandy Dunlap 26221da177e4SLinus Torvalds if ($x =~ /^#/) { 26231da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 26241da177e4SLinus Torvalds $x .= ";"; 26251da177e4SLinus Torvalds } 26261da177e4SLinus Torvalds 26271da177e4SLinus Torvalds while (1) { 26281da177e4SLinus Torvalds if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 26291da177e4SLinus Torvalds $prototype .= $1 . $2; 26301da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 26311da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 26321da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 26331da177e4SLinus Torvalds dump_declaration($prototype, $file); 26341da177e4SLinus Torvalds reset_state(); 26351da177e4SLinus Torvalds last; 26361da177e4SLinus Torvalds } 26371da177e4SLinus Torvalds $x = $3; 26381da177e4SLinus Torvalds } else { 26391da177e4SLinus Torvalds $prototype .= $x; 26401da177e4SLinus Torvalds last; 26411da177e4SLinus Torvalds } 26421da177e4SLinus Torvalds } 26431da177e4SLinus Torvalds} 26441da177e4SLinus Torvalds 26456b5b55f6SRandy Dunlap# xml_escape: replace <, >, and & in the text stream; 26466b5b55f6SRandy Dunlap# 26476b5b55f6SRandy Dunlap# however, formatting controls that are generated internally/locally in the 26486b5b55f6SRandy Dunlap# kernel-doc script are not escaped here; instead, they begin life like 26496b5b55f6SRandy Dunlap# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings 26506b5b55f6SRandy Dunlap# are converted to their mnemonic-expected output, without the 4 * '\' & ':', 26516b5b55f6SRandy Dunlap# just before actual output; (this is done by local_unescape()) 26521da177e4SLinus Torvaldssub xml_escape($) { 26531da177e4SLinus Torvalds my $text = shift; 2654ecfb251aSRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 2655ecfb251aSRandy Dunlap return $text; 2656ecfb251aSRandy Dunlap } 26571da177e4SLinus Torvalds $text =~ s/\&/\\\\\\amp;/g; 26581da177e4SLinus Torvalds $text =~ s/\</\\\\\\lt;/g; 26591da177e4SLinus Torvalds $text =~ s/\>/\\\\\\gt;/g; 26601da177e4SLinus Torvalds return $text; 26611da177e4SLinus Torvalds} 26621da177e4SLinus Torvalds 2663c0d1b6eeSJonathan Corbet# xml_unescape: reverse the effects of xml_escape 2664c0d1b6eeSJonathan Corbetsub xml_unescape($) { 2665c0d1b6eeSJonathan Corbet my $text = shift; 2666c0d1b6eeSJonathan Corbet if (($output_mode eq "text") || ($output_mode eq "man")) { 2667c0d1b6eeSJonathan Corbet return $text; 2668c0d1b6eeSJonathan Corbet } 2669c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\amp;/\&/g; 2670c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\lt;/</g; 2671c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\gt;/>/g; 2672c0d1b6eeSJonathan Corbet return $text; 2673c0d1b6eeSJonathan Corbet} 2674c0d1b6eeSJonathan Corbet 26756b5b55f6SRandy Dunlap# convert local escape strings to html 26766b5b55f6SRandy Dunlap# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) 26776b5b55f6SRandy Dunlapsub local_unescape($) { 26786b5b55f6SRandy Dunlap my $text = shift; 26796b5b55f6SRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 26806b5b55f6SRandy Dunlap return $text; 26816b5b55f6SRandy Dunlap } 26826b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\lt:/</g; 26836b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\gt:/>/g; 26846b5b55f6SRandy Dunlap return $text; 26856b5b55f6SRandy Dunlap} 26866b5b55f6SRandy Dunlap 26871da177e4SLinus Torvaldssub process_file($) { 26882283a117SRandy Dunlap my $file; 26891da177e4SLinus Torvalds my $identifier; 26901da177e4SLinus Torvalds my $func; 2691a21217daSRandy Dunlap my $descr; 26926423133bSJohannes Weiner my $in_purpose = 0; 26931da177e4SLinus Torvalds my $initial_section_counter = $section_counter; 269468f86662SBen Hutchings my ($orig_file) = @_; 26951da177e4SLinus Torvalds 26962283a117SRandy Dunlap if (defined($ENV{'SRCTREE'})) { 269768f86662SBen Hutchings $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 26982283a117SRandy Dunlap } 26992283a117SRandy Dunlap else { 270068f86662SBen Hutchings $file = $orig_file; 27012283a117SRandy Dunlap } 27021da177e4SLinus Torvalds if (defined($source_map{$file})) { 27031da177e4SLinus Torvalds $file = $source_map{$file}; 27041da177e4SLinus Torvalds } 27051da177e4SLinus Torvalds 27061da177e4SLinus Torvalds if (!open(IN,"<$file")) { 27071da177e4SLinus Torvalds print STDERR "Error: Cannot open file $file\n"; 27081da177e4SLinus Torvalds ++$errors; 27091da177e4SLinus Torvalds return; 27101da177e4SLinus Torvalds } 27111da177e4SLinus Torvalds 271286ae2e38SJani Nikula # two passes for -export and -internal 2713b6c3f456SJani Nikula if ($output_selection == OUTPUT_EXPORTED || 2714b6c3f456SJani Nikula $output_selection == OUTPUT_INTERNAL) { 271586ae2e38SJani Nikula while (<IN>) { 271686ae2e38SJani Nikula if (/$export_symbol/o) { 271786ae2e38SJani Nikula $function_table{$2} = 1; 271886ae2e38SJani Nikula } 271986ae2e38SJani Nikula } 272086ae2e38SJani Nikula seek(IN, 0, 0); 272186ae2e38SJani Nikula } 272286ae2e38SJani Nikula 2723a9e7314bSIlya Dryomov $. = 1; 2724a9e7314bSIlya Dryomov 27251da177e4SLinus Torvalds $section_counter = 0; 27261da177e4SLinus Torvalds while (<IN>) { 272765478428SDaniel Santos while (s/\\\s*$//) { 272865478428SDaniel Santos $_ .= <IN>; 272965478428SDaniel Santos } 273048af606aSJani Nikula if ($state == STATE_NORMAL) { 27311da177e4SLinus Torvalds if (/$doc_start/o) { 273248af606aSJani Nikula $state = STATE_NAME; # next line is always the function name 2733850622dfSRandy Dunlap $in_doc_sect = 0; 27341da177e4SLinus Torvalds } 273548af606aSJani Nikula } elsif ($state == STATE_NAME) {# this line is the function name (always) 27361da177e4SLinus Torvalds if (/$doc_block/o) { 273748af606aSJani Nikula $state = STATE_DOCBLOCK; 27381da177e4SLinus Torvalds $contents = ""; 27391da177e4SLinus Torvalds if ( $1 eq "" ) { 27401da177e4SLinus Torvalds $section = $section_intro; 27411da177e4SLinus Torvalds } else { 27421da177e4SLinus Torvalds $section = $1; 27431da177e4SLinus Torvalds } 27441da177e4SLinus Torvalds } 27451da177e4SLinus Torvalds elsif (/$doc_decl/o) { 27461da177e4SLinus Torvalds $identifier = $1; 27471da177e4SLinus Torvalds if (/\s*([\w\s]+?)\s*-/) { 27481da177e4SLinus Torvalds $identifier = $1; 27491da177e4SLinus Torvalds } 27501da177e4SLinus Torvalds 275148af606aSJani Nikula $state = STATE_FIELD; 27521da177e4SLinus Torvalds if (/-(.*)/) { 275351f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2754a21217daSRandy Dunlap $descr= $1; 2755a21217daSRandy Dunlap $descr =~ s/^\s*//; 2756a21217daSRandy Dunlap $descr =~ s/\s*$//; 275712ae6779SDaniel Santos $descr =~ s/\s+/ /g; 2758a21217daSRandy Dunlap $declaration_purpose = xml_escape($descr); 27596423133bSJohannes Weiner $in_purpose = 1; 27601da177e4SLinus Torvalds } else { 27611da177e4SLinus Torvalds $declaration_purpose = ""; 27621da177e4SLinus Torvalds } 276377cc23b8SRandy Dunlap 276477cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 2765d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 276677cc23b8SRandy Dunlap print STDERR $_; 276777cc23b8SRandy Dunlap ++$warnings; 276877cc23b8SRandy Dunlap } 276977cc23b8SRandy Dunlap 27701da177e4SLinus Torvalds if ($identifier =~ m/^struct/) { 27711da177e4SLinus Torvalds $decl_type = 'struct'; 27721da177e4SLinus Torvalds } elsif ($identifier =~ m/^union/) { 27731da177e4SLinus Torvalds $decl_type = 'union'; 27741da177e4SLinus Torvalds } elsif ($identifier =~ m/^enum/) { 27751da177e4SLinus Torvalds $decl_type = 'enum'; 27761da177e4SLinus Torvalds } elsif ($identifier =~ m/^typedef/) { 27771da177e4SLinus Torvalds $decl_type = 'typedef'; 27781da177e4SLinus Torvalds } else { 27791da177e4SLinus Torvalds $decl_type = 'function'; 27801da177e4SLinus Torvalds } 27811da177e4SLinus Torvalds 27821da177e4SLinus Torvalds if ($verbose) { 2783d40e1e65SBart Van Assche print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; 27841da177e4SLinus Torvalds } 27851da177e4SLinus Torvalds } else { 2786d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 27871da177e4SLinus Torvalds " - I thought it was a doc line\n"; 27881da177e4SLinus Torvalds ++$warnings; 278948af606aSJani Nikula $state = STATE_NORMAL; 27901da177e4SLinus Torvalds } 279148af606aSJani Nikula } elsif ($state == STATE_FIELD) { # look for head: lines, and include content 27921da177e4SLinus Torvalds if (/$doc_sect/o) { 27931da177e4SLinus Torvalds $newsection = $1; 27941da177e4SLinus Torvalds $newcontents = $2; 27951da177e4SLinus Torvalds 2796792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 2797850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 2798d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: contents before sections\n"; 2799850622dfSRandy Dunlap ++$warnings; 2800850622dfSRandy Dunlap } 280194dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 28021da177e4SLinus Torvalds $section = $section_default; 28031da177e4SLinus Torvalds } 28041da177e4SLinus Torvalds 2805850622dfSRandy Dunlap $in_doc_sect = 1; 28066423133bSJohannes Weiner $in_purpose = 0; 28071da177e4SLinus Torvalds $contents = $newcontents; 28081da177e4SLinus Torvalds if ($contents ne "") { 280927205744SRandy Dunlap while ((substr($contents, 0, 1) eq " ") || 281027205744SRandy Dunlap substr($contents, 0, 1) eq "\t") { 281105189497SRandy Dunlap $contents = substr($contents, 1); 281205189497SRandy Dunlap } 28131da177e4SLinus Torvalds $contents .= "\n"; 28141da177e4SLinus Torvalds } 28151da177e4SLinus Torvalds $section = $newsection; 28161da177e4SLinus Torvalds } elsif (/$doc_end/) { 28174c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 281894dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 28191da177e4SLinus Torvalds $section = $section_default; 28201da177e4SLinus Torvalds $contents = ""; 28211da177e4SLinus Torvalds } 282246b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 282346b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2824d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: suspicious ending line: $_"; 282546b958ebSRandy Dunlap ++$warnings; 282646b958ebSRandy Dunlap } 28271da177e4SLinus Torvalds 28281da177e4SLinus Torvalds $prototype = ""; 282948af606aSJani Nikula $state = STATE_PROTO; 28301da177e4SLinus Torvalds $brcount = 0; 28311da177e4SLinus Torvalds# print STDERR "end of doc comment, looking for prototype\n"; 28321da177e4SLinus Torvalds } elsif (/$doc_content/) { 28331da177e4SLinus Torvalds # miguel-style comment kludge, look for blank lines after 28341da177e4SLinus Torvalds # @parameter line to signify start of description 28356423133bSJohannes Weiner if ($1 eq "") { 28366423133bSJohannes Weiner if ($section =~ m/^@/ || $section eq $section_context) { 283794dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 28381da177e4SLinus Torvalds $section = $section_default; 28391da177e4SLinus Torvalds $contents = ""; 28401da177e4SLinus Torvalds } else { 28416423133bSJohannes Weiner $contents .= "\n"; 28426423133bSJohannes Weiner } 28436423133bSJohannes Weiner $in_purpose = 0; 28446423133bSJohannes Weiner } elsif ($in_purpose == 1) { 28456423133bSJohannes Weiner # Continued declaration purpose 28466423133bSJohannes Weiner chomp($declaration_purpose); 28476423133bSJohannes Weiner $declaration_purpose .= " " . xml_escape($1); 284812ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 28496423133bSJohannes Weiner } else { 28501da177e4SLinus Torvalds $contents .= $1 . "\n"; 28511da177e4SLinus Torvalds } 28521da177e4SLinus Torvalds } else { 28531da177e4SLinus Torvalds # i dont know - bad line? ignore. 2854d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: bad line: $_"; 28551da177e4SLinus Torvalds ++$warnings; 28561da177e4SLinus Torvalds } 285748af606aSJani Nikula } elsif ($state == STATE_INLINE) { # scanning for inline parameters 2858a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 285948af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 2860a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 2861a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 2862a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 2863a4c6ebedSDanilo Cesar Lemes de Paula while ((substr($contents, 0, 1) eq " ") || 2864a4c6ebedSDanilo Cesar Lemes de Paula substr($contents, 0, 1) eq "\t") { 2865a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 2866a4c6ebedSDanilo Cesar Lemes de Paula } 2867a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 2868a4c6ebedSDanilo Cesar Lemes de Paula } 286948af606aSJani Nikula $inline_doc_state = STATE_INLINE_TEXT; 2870a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 287148af606aSJani Nikula } elsif (/$doc_inline_end/) { 2872a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 2873a4c6ebedSDanilo Cesar Lemes de Paula dump_section($file, $section, xml_escape($contents)); 2874a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 2875a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 2876a4c6ebedSDanilo Cesar Lemes de Paula } 287748af606aSJani Nikula $state = STATE_PROTO; 287848af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 2879a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 2880a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 288148af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_TEXT) { 2882a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 288348af606aSJani Nikula } elsif ($inline_doc_state == STATE_INLINE_NAME) { 288448af606aSJani Nikula $inline_doc_state = STATE_INLINE_ERROR; 2885a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Warning(${file}:$.): "; 2886a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Incorrect use of kernel-doc format: $_"; 2887a4c6ebedSDanilo Cesar Lemes de Paula ++$warnings; 2888a4c6ebedSDanilo Cesar Lemes de Paula } 2889a4c6ebedSDanilo Cesar Lemes de Paula } 289048af606aSJani Nikula } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype) 289148af606aSJani Nikula if (/$doc_inline_start/) { 289248af606aSJani Nikula $state = STATE_INLINE; 289348af606aSJani Nikula $inline_doc_state = STATE_INLINE_NAME; 2894a4c6ebedSDanilo Cesar Lemes de Paula } elsif ($decl_type eq 'function') { 28951da177e4SLinus Torvalds process_state3_function($_, $file); 28961da177e4SLinus Torvalds } else { 28971da177e4SLinus Torvalds process_state3_type($_, $file); 28981da177e4SLinus Torvalds } 289948af606aSJani Nikula } elsif ($state == STATE_DOCBLOCK) { 29001da177e4SLinus Torvalds # Documentation block 29011da177e4SLinus Torvalds if (/$doc_block/) { 290294dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 29031da177e4SLinus Torvalds $contents = ""; 29041da177e4SLinus Torvalds $function = ""; 29051da177e4SLinus Torvalds %constants = (); 29061da177e4SLinus Torvalds %parameterdescs = (); 29071da177e4SLinus Torvalds %parametertypes = (); 29081da177e4SLinus Torvalds @parameterlist = (); 29091da177e4SLinus Torvalds %sections = (); 29101da177e4SLinus Torvalds @sectionlist = (); 29111da177e4SLinus Torvalds $prototype = ""; 29121da177e4SLinus Torvalds if ( $1 eq "" ) { 29131da177e4SLinus Torvalds $section = $section_intro; 29141da177e4SLinus Torvalds } else { 29151da177e4SLinus Torvalds $section = $1; 29161da177e4SLinus Torvalds } 29171da177e4SLinus Torvalds } 29181da177e4SLinus Torvalds elsif (/$doc_end/) 29191da177e4SLinus Torvalds { 292094dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 29211da177e4SLinus Torvalds $contents = ""; 29221da177e4SLinus Torvalds $function = ""; 29231da177e4SLinus Torvalds %constants = (); 29241da177e4SLinus Torvalds %parameterdescs = (); 29251da177e4SLinus Torvalds %parametertypes = (); 29261da177e4SLinus Torvalds @parameterlist = (); 29271da177e4SLinus Torvalds %sections = (); 29281da177e4SLinus Torvalds @sectionlist = (); 29291da177e4SLinus Torvalds $prototype = ""; 293048af606aSJani Nikula $state = STATE_NORMAL; 29311da177e4SLinus Torvalds } 29321da177e4SLinus Torvalds elsif (/$doc_content/) 29331da177e4SLinus Torvalds { 29341da177e4SLinus Torvalds if ( $1 eq "" ) 29351da177e4SLinus Torvalds { 29361da177e4SLinus Torvalds $contents .= $blankline; 29371da177e4SLinus Torvalds } 29381da177e4SLinus Torvalds else 29391da177e4SLinus Torvalds { 29401da177e4SLinus Torvalds $contents .= $1 . "\n"; 29411da177e4SLinus Torvalds } 29421da177e4SLinus Torvalds } 29431da177e4SLinus Torvalds } 29441da177e4SLinus Torvalds } 29451da177e4SLinus Torvalds if ($initial_section_counter == $section_counter) { 2946d40e1e65SBart Van Assche print STDERR "${file}:1: warning: no structured comments found\n"; 2947b6c3f456SJani Nikula if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) { 2948e946c43aSJohannes Berg print STDERR " Was looking for '$_'.\n" for keys %function_table; 2949e946c43aSJohannes Berg } 29501da177e4SLinus Torvalds if ($output_mode eq "xml") { 29511da177e4SLinus Torvalds # The template wants at least one RefEntry here; make one. 29521da177e4SLinus Torvalds print "<refentry>\n"; 29531da177e4SLinus Torvalds print " <refnamediv>\n"; 29541da177e4SLinus Torvalds print " <refname>\n"; 295568f86662SBen Hutchings print " ${orig_file}\n"; 29561da177e4SLinus Torvalds print " </refname>\n"; 29571da177e4SLinus Torvalds print " <refpurpose>\n"; 29581da177e4SLinus Torvalds print " Document generation inconsistency\n"; 29591da177e4SLinus Torvalds print " </refpurpose>\n"; 29601da177e4SLinus Torvalds print " </refnamediv>\n"; 29611da177e4SLinus Torvalds print " <refsect1>\n"; 29621da177e4SLinus Torvalds print " <title>\n"; 29631da177e4SLinus Torvalds print " Oops\n"; 29641da177e4SLinus Torvalds print " </title>\n"; 29651da177e4SLinus Torvalds print " <warning>\n"; 29661da177e4SLinus Torvalds print " <para>\n"; 29671da177e4SLinus Torvalds print " The template for this document tried to insert\n"; 29681da177e4SLinus Torvalds print " the structured comment from the file\n"; 296968f86662SBen Hutchings print " <filename>${orig_file}</filename> at this point,\n"; 29701da177e4SLinus Torvalds print " but none was found.\n"; 29711da177e4SLinus Torvalds print " This dummy section is inserted to allow\n"; 29721da177e4SLinus Torvalds print " generation to continue.\n"; 29731da177e4SLinus Torvalds print " </para>\n"; 29741da177e4SLinus Torvalds print " </warning>\n"; 29751da177e4SLinus Torvalds print " </refsect1>\n"; 29761da177e4SLinus Torvalds print "</refentry>\n"; 29771da177e4SLinus Torvalds } 29781da177e4SLinus Torvalds } 29791da177e4SLinus Torvalds} 29808484baaaSRandy Dunlap 29818484baaaSRandy Dunlap 29828484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 29838484baaaSRandy Dunlap 29848484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 29858484baaaSRandy Dunlap# using the s// operator. 29861ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 29874d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 29884d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 29894d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 29904d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 29918484baaaSRandy Dunlap} 29928484baaaSRandy Dunlap 29938484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 29948484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 29958484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 29968484baaaSRandy Dunlap my ($relname, $absname); 29978484baaaSRandy Dunlap while(<SOURCE_MAP>) { 29988484baaaSRandy Dunlap chop(); 29998484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 30008484baaaSRandy Dunlap $relname =~ s:^/+::; 30018484baaaSRandy Dunlap $source_map{$relname} = $absname; 30028484baaaSRandy Dunlap } 30038484baaaSRandy Dunlap close(SOURCE_MAP); 30048484baaaSRandy Dunlap} 30058484baaaSRandy Dunlap 30068484baaaSRandy Dunlapforeach (@ARGV) { 30078484baaaSRandy Dunlap chomp; 30088484baaaSRandy Dunlap process_file($_); 30098484baaaSRandy Dunlap} 30108484baaaSRandy Dunlapif ($verbose && $errors) { 30118484baaaSRandy Dunlap print STDERR "$errors errors\n"; 30128484baaaSRandy Dunlap} 30138484baaaSRandy Dunlapif ($verbose && $warnings) { 30148484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 30158484baaaSRandy Dunlap} 30168484baaaSRandy Dunlap 30178484baaaSRandy Dunlapexit($errors); 3018