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. 58*c0d1b6eeSJonathan Corbet -rst Output reStructuredText format. 59fadc0b31SJani Nikula -text Output plain text format. 60fadc0b31SJani Nikula 61fadc0b31SJani NikulaOutput selection (mutually exclusive): 62fadc0b31SJani Nikula -function NAME Only output documentation for the given function(s) 63fadc0b31SJani Nikula or DOC: section title(s). All other functions and DOC: 64fadc0b31SJani Nikula sections are ignored. May be specified multiple times. 65fadc0b31SJani Nikula -nofunction NAME Do NOT output documentation for the given function(s); 66fadc0b31SJani Nikula only output documentation for the other functions and 67fadc0b31SJani Nikula DOC: sections. May be specified multiple times. 68fadc0b31SJani Nikula 69fadc0b31SJani NikulaOutput selection modifiers: 70fadc0b31SJani Nikula -no-doc-sections Do not output DOC: sections. 71fadc0b31SJani Nikula 72fadc0b31SJani NikulaOther parameters: 73fadc0b31SJani Nikula -v Verbose output, more warnings and other information. 74fadc0b31SJani Nikula -h Print this help. 75fadc0b31SJani Nikula 76fadc0b31SJani NikulaEOF 77fadc0b31SJani Nikula print $message; 78fadc0b31SJani Nikula exit 1; 79fadc0b31SJani Nikula} 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds# 821da177e4SLinus Torvalds# format of comments. 831da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure. 841da177e4SLinus Torvalds# (...)* signifies 0 or more structure elements 851da177e4SLinus Torvalds# /** 861da177e4SLinus Torvalds# * function_name(:)? (- short description)? 871da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)* 881da177e4SLinus Torvalds# (* a blank line)? 891da177e4SLinus Torvalds# * (Description:)? (Description of function)? 901da177e4SLinus Torvalds# * (section header: (section description)? )* 911da177e4SLinus Torvalds# (*)?*/ 921da177e4SLinus Torvalds# 931da177e4SLinus Torvalds# So .. the trivial example would be: 941da177e4SLinus Torvalds# 951da177e4SLinus Torvalds# /** 961da177e4SLinus Torvalds# * my_function 97b9d97328SRandy Dunlap# */ 981da177e4SLinus Torvalds# 99891dcd2fSRandy Dunlap# If the Description: header tag is omitted, then there must be a blank line 1001da177e4SLinus Torvalds# after the last parameter specification. 1011da177e4SLinus Torvalds# e.g. 1021da177e4SLinus Torvalds# /** 1031da177e4SLinus Torvalds# * my_function - does my stuff 1041da177e4SLinus Torvalds# * @my_arg: its mine damnit 1051da177e4SLinus Torvalds# * 1061da177e4SLinus Torvalds# * Does my stuff explained. 1071da177e4SLinus Torvalds# */ 1081da177e4SLinus Torvalds# 1091da177e4SLinus Torvalds# or, could also use: 1101da177e4SLinus Torvalds# /** 1111da177e4SLinus Torvalds# * my_function - does my stuff 1121da177e4SLinus Torvalds# * @my_arg: its mine damnit 1131da177e4SLinus Torvalds# * Description: Does my stuff explained. 1141da177e4SLinus Torvalds# */ 1151da177e4SLinus Torvalds# etc. 1161da177e4SLinus Torvalds# 117b9d97328SRandy Dunlap# Besides functions you can also write documentation for structs, unions, 1181da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name 1191da177e4SLinus Torvalds# of the declaration; the struct/union/enum/typedef must always precede 1201da177e4SLinus Torvalds# the name. Nesting of declarations is not supported. 1211da177e4SLinus Torvalds# Use the argument mechanism to document members or constants. 1221da177e4SLinus Torvalds# e.g. 1231da177e4SLinus Torvalds# /** 1241da177e4SLinus Torvalds# * struct my_struct - short description 1251da177e4SLinus Torvalds# * @a: first member 1261da177e4SLinus Torvalds# * @b: second member 1271da177e4SLinus Torvalds# * 1281da177e4SLinus Torvalds# * Longer description 1291da177e4SLinus Torvalds# */ 1301da177e4SLinus Torvalds# struct my_struct { 1311da177e4SLinus Torvalds# int a; 1321da177e4SLinus Torvalds# int b; 133aeec46b9SMartin Waitz# /* private: */ 134aeec46b9SMartin Waitz# int c; 1351da177e4SLinus Torvalds# }; 1361da177e4SLinus Torvalds# 1371da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description. 1381da177e4SLinus Torvalds# 139a4c6ebedSDanilo Cesar Lemes de Paula# For really longs structs, you can also describe arguments inside the 140a4c6ebedSDanilo Cesar Lemes de Paula# body of the struct. 141a4c6ebedSDanilo Cesar Lemes de Paula# eg. 142a4c6ebedSDanilo Cesar Lemes de Paula# /** 143a4c6ebedSDanilo Cesar Lemes de Paula# * struct my_struct - short description 144a4c6ebedSDanilo Cesar Lemes de Paula# * @a: first member 145a4c6ebedSDanilo Cesar Lemes de Paula# * @b: second member 146a4c6ebedSDanilo Cesar Lemes de Paula# * 147a4c6ebedSDanilo Cesar Lemes de Paula# * Longer description 148a4c6ebedSDanilo Cesar Lemes de Paula# */ 149a4c6ebedSDanilo Cesar Lemes de Paula# struct my_struct { 150a4c6ebedSDanilo Cesar Lemes de Paula# int a; 151a4c6ebedSDanilo Cesar Lemes de Paula# int b; 152a4c6ebedSDanilo Cesar Lemes de Paula# /** 153a4c6ebedSDanilo Cesar Lemes de Paula# * @c: This is longer description of C 154a4c6ebedSDanilo Cesar Lemes de Paula# * 155a4c6ebedSDanilo Cesar Lemes de Paula# * You can use paragraphs to describe arguments 156a4c6ebedSDanilo Cesar Lemes de Paula# * using this method. 157a4c6ebedSDanilo Cesar Lemes de Paula# */ 158a4c6ebedSDanilo Cesar Lemes de Paula# int c; 159a4c6ebedSDanilo Cesar Lemes de Paula# }; 160a4c6ebedSDanilo Cesar Lemes de Paula# 161a4c6ebedSDanilo Cesar Lemes de Paula# This should be use only for struct/enum members. 162a4c6ebedSDanilo Cesar Lemes de Paula# 1631da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you 1641da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions 1651da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an 1661da177e4SLinus Torvalds# empty line. 1674092bac7SYacine Belkadi# A non-void function should have a "Return:" section describing the return 1684092bac7SYacine Belkadi# value(s). 1691da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked 1701da177e4SLinus Torvalds# appropriately in DocBook. 1711da177e4SLinus Torvalds# 1721da177e4SLinus Torvalds# Example: 1731da177e4SLinus Torvalds# /** 1741da177e4SLinus Torvalds# * user_function - function that can only be called in user context 1751da177e4SLinus Torvalds# * @a: some argument 1761da177e4SLinus Torvalds# * Context: !in_interrupt() 1771da177e4SLinus Torvalds# * 1781da177e4SLinus Torvalds# * Some description 1791da177e4SLinus Torvalds# * Example: 1801da177e4SLinus Torvalds# * user_function(22); 1811da177e4SLinus Torvalds# */ 1821da177e4SLinus Torvalds# ... 1831da177e4SLinus Torvalds# 1841da177e4SLinus Torvalds# 1851da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special 1861da177e4SLinus Torvalds# patterns, which are highlighted appropriately. 1871da177e4SLinus Torvalds# 1881da177e4SLinus Torvalds# 'funcname()' - function 1891da177e4SLinus Torvalds# '$ENVVAR' - environmental variable 1901da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct') 1911da177e4SLinus Torvalds# '@parameter' - name of a parameter 1921da177e4SLinus Torvalds# '%CONST' - name of a constant. 1931da177e4SLinus Torvalds 1948484baaaSRandy Dunlap## init lots of data 1958484baaaSRandy Dunlap 1961da177e4SLinus Torvaldsmy $errors = 0; 1971da177e4SLinus Torvaldsmy $warnings = 0; 1985f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 1991da177e4SLinus Torvalds 2001da177e4SLinus Torvalds# match expressions used to find embedded type information 2011da177e4SLinus Torvaldsmy $type_constant = '\%([-_\w]+)'; 2021da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 2031da177e4SLinus Torvaldsmy $type_param = '\@(\w+)'; 2043eb014a1SRandy Dunlapmy $type_struct = '\&((struct\s*)*[_\w]+)'; 2056b5b55f6SRandy Dunlapmy $type_struct_xml = '\\&((struct\s*)*[_\w]+)'; 2061da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 207*c0d1b6eeSJonathan Corbetmy $type_enum_full = '\&(enum)\s*([_\w]+)'; 208*c0d1b6eeSJonathan Corbetmy $type_struct_full = '\&(struct)\s*([_\w]+)'; 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvalds# Output conversion substitutions. 2111da177e4SLinus Torvalds# One for each output format 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds# these work fairly well 2144d732701SDanilo Cesar Lemes de Paulamy @highlights_html = ( 2154d732701SDanilo Cesar Lemes de Paula [$type_constant, "<i>\$1</i>"], 2164d732701SDanilo Cesar Lemes de Paula [$type_func, "<b>\$1</b>"], 2174d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<i>\$1</i>"], 2184d732701SDanilo Cesar Lemes de Paula [$type_env, "<b><i>\$1</i></b>"], 2194d732701SDanilo Cesar Lemes de Paula [$type_param, "<tt><b>\$1</b></tt>"] 2204d732701SDanilo Cesar Lemes de Paula ); 2216b5b55f6SRandy Dunlapmy $local_lt = "\\\\\\\\lt:"; 2226b5b55f6SRandy Dunlapmy $local_gt = "\\\\\\\\gt:"; 2236b5b55f6SRandy Dunlapmy $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" 2241da177e4SLinus Torvalds 2251b40c194SDan Luedtke# html version 5 2264d732701SDanilo Cesar Lemes de Paulamy @highlights_html5 = ( 2274d732701SDanilo Cesar Lemes de Paula [$type_constant, "<span class=\"const\">\$1</span>"], 2284d732701SDanilo Cesar Lemes de Paula [$type_func, "<span class=\"func\">\$1</span>"], 2294d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<span class=\"struct\">\$1</span>"], 2304d732701SDanilo Cesar Lemes de Paula [$type_env, "<span class=\"env\">\$1</span>"], 2314d732701SDanilo Cesar Lemes de Paula [$type_param, "<span class=\"param\">\$1</span>]"] 2324d732701SDanilo Cesar Lemes de Paula ); 2331b40c194SDan Luedtkemy $blankline_html5 = $local_lt . "br /" . $local_gt; 2341b40c194SDan Luedtke 2351da177e4SLinus Torvalds# XML, docbook format 2364d732701SDanilo Cesar Lemes de Paulamy @highlights_xml = ( 2374d732701SDanilo Cesar Lemes de Paula ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"], 2384d732701SDanilo Cesar Lemes de Paula [$type_constant, "<constant>\$1</constant>"], 2394d732701SDanilo Cesar Lemes de Paula [$type_struct_xml, "<structname>\$1</structname>"], 2404d732701SDanilo Cesar Lemes de Paula [$type_param, "<parameter>\$1</parameter>"], 2414d732701SDanilo Cesar Lemes de Paula [$type_func, "<function>\$1</function>"], 2424d732701SDanilo Cesar Lemes de Paula [$type_env, "<envar>\$1</envar>"] 2434d732701SDanilo Cesar Lemes de Paula ); 2445c98fc03SJohannes Bergmy $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; 2451da177e4SLinus Torvalds 2461da177e4SLinus Torvalds# gnome, docbook format 2474d732701SDanilo Cesar Lemes de Paulamy @highlights_gnome = ( 2484d732701SDanilo Cesar Lemes de Paula [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"], 2494d732701SDanilo Cesar Lemes de Paula [$type_func, "<function>\$1</function>"], 2504d732701SDanilo Cesar Lemes de Paula [$type_struct, "<structname>\$1</structname>"], 2514d732701SDanilo Cesar Lemes de Paula [$type_env, "<envar>\$1</envar>"], 2524d732701SDanilo Cesar Lemes de Paula [$type_param, "<parameter>\$1</parameter>" ] 2534d732701SDanilo Cesar Lemes de Paula ); 2541da177e4SLinus Torvaldsmy $blankline_gnome = "</para><para>\n"; 2551da177e4SLinus Torvalds 2561da177e4SLinus Torvalds# these are pretty rough 2574d732701SDanilo Cesar Lemes de Paulamy @highlights_man = ( 2584d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 2594d732701SDanilo Cesar Lemes de Paula [$type_func, "\\\\fB\$1\\\\fP"], 2604d732701SDanilo Cesar Lemes de Paula [$type_struct, "\\\\fI\$1\\\\fP"], 2614d732701SDanilo Cesar Lemes de Paula [$type_param, "\\\\fI\$1\\\\fP"] 2624d732701SDanilo Cesar Lemes de Paula ); 2631da177e4SLinus Torvaldsmy $blankline_man = ""; 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds# text-mode 2664d732701SDanilo Cesar Lemes de Paulamy @highlights_text = ( 2674d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 2684d732701SDanilo Cesar Lemes de Paula [$type_func, "\$1"], 2694d732701SDanilo Cesar Lemes de Paula [$type_struct, "\$1"], 2704d732701SDanilo Cesar Lemes de Paula [$type_param, "\$1"] 2714d732701SDanilo Cesar Lemes de Paula ); 2721da177e4SLinus Torvaldsmy $blankline_text = ""; 2731da177e4SLinus Torvalds 274*c0d1b6eeSJonathan Corbet# rst-mode 275*c0d1b6eeSJonathan Corbetmy @highlights_rst = ( 276*c0d1b6eeSJonathan Corbet [$type_constant, "``\$1``"], 277*c0d1b6eeSJonathan Corbet [$type_func, "\\:c\\:func\\:`\$1`"], 278*c0d1b6eeSJonathan Corbet [$type_struct_full, "\\:ref\\:`\$1 \$2`"], 279*c0d1b6eeSJonathan Corbet [$type_enum_full, "\\:ref\\:`\$1 \$2`"], 280*c0d1b6eeSJonathan Corbet [$type_struct, "\\:ref\\:`struct \$1`"], 281*c0d1b6eeSJonathan Corbet [$type_param, "**\$1**"] 282*c0d1b6eeSJonathan Corbet ); 283*c0d1b6eeSJonathan Corbetmy $blankline_rst = "\n"; 284*c0d1b6eeSJonathan Corbet 285eda603f6SJohannes Berg# list mode 2864d732701SDanilo Cesar Lemes de Paulamy @highlights_list = ( 2874d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 2884d732701SDanilo Cesar Lemes de Paula [$type_func, "\$1"], 2894d732701SDanilo Cesar Lemes de Paula [$type_struct, "\$1"], 2904d732701SDanilo Cesar Lemes de Paula [$type_param, "\$1"] 2914d732701SDanilo Cesar Lemes de Paula ); 292eda603f6SJohannes Bergmy $blankline_list = ""; 2931da177e4SLinus Torvalds 2941da177e4SLinus Torvalds# read arguments 2951da177e4SLinus Torvaldsif ($#ARGV == -1) { 2961da177e4SLinus Torvalds usage(); 2971da177e4SLinus Torvalds} 2981da177e4SLinus Torvalds 2998484baaaSRandy Dunlapmy $kernelversion; 3008484baaaSRandy Dunlapmy $dohighlight = ""; 3018484baaaSRandy Dunlap 3021da177e4SLinus Torvaldsmy $verbose = 0; 3031da177e4SLinus Torvaldsmy $output_mode = "man"; 304e314ba31SDaniel Santosmy $output_preformatted = 0; 3054b44595aSJohannes Bergmy $no_doc_sections = 0; 3064d732701SDanilo Cesar Lemes de Paulamy @highlights = @highlights_man; 3071da177e4SLinus Torvaldsmy $blankline = $blankline_man; 3081da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 3091da177e4SLinus Torvaldsmy $function_only = 0; 310b2c4105bSBen Hutchingsmy $show_not_found = 0; 311b2c4105bSBen Hutchings 312b2c4105bSBen Hutchingsmy @build_time; 313b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 314b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 315b2c4105bSBen Hutchings @build_time = gmtime($seconds); 316b2c4105bSBen Hutchings} else { 317b2c4105bSBen Hutchings @build_time = localtime; 318b2c4105bSBen Hutchings} 319b2c4105bSBen Hutchings 3201da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 3211da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 322b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 323b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 3241da177e4SLinus Torvalds 3258484baaaSRandy Dunlap# Essentially these are globals. 326b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 327b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 3281da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 3291da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 3301da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 3311c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 3321da177e4SLinus Torvalds 333bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 334bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 335bd0e88e5SRandy Dunlap} 336bd0e88e5SRandy Dunlap 3371da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 3381da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 3391da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 3401da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 3411da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 3421da177e4SLinus Torvalds# into html. 3431da177e4SLinus Torvaldsmy $section_counter = 0; 3441da177e4SLinus Torvalds 3451da177e4SLinus Torvaldsmy $lineprefix=""; 3461da177e4SLinus Torvalds 3471da177e4SLinus Torvalds# states 3481da177e4SLinus Torvalds# 0 - normal code 3491da177e4SLinus Torvalds# 1 - looking for function name 3501da177e4SLinus Torvalds# 2 - scanning field start. 3511da177e4SLinus Torvalds# 3 - scanning prototype. 3521da177e4SLinus Torvalds# 4 - documentation block 353a4c6ebedSDanilo Cesar Lemes de Paula# 5 - gathering documentation outside main block 3541da177e4SLinus Torvaldsmy $state; 355850622dfSRandy Dunlapmy $in_doc_sect; 3561da177e4SLinus Torvalds 357a4c6ebedSDanilo Cesar Lemes de Paula# Split Doc State 358a4c6ebedSDanilo Cesar Lemes de Paula# 0 - Invalid (Before start or after finish) 359a4c6ebedSDanilo Cesar Lemes de Paula# 1 - Is started (the /** was found inside a struct) 360a4c6ebedSDanilo Cesar Lemes de Paula# 2 - The @parameter header was found, start accepting multi paragraph text. 361a4c6ebedSDanilo Cesar Lemes de Paula# 3 - Finished (the */ was found) 362a4c6ebedSDanilo Cesar Lemes de Paula# 4 - Error - Comment without header was found. Spit a warning as it's not 363a4c6ebedSDanilo Cesar Lemes de Paula# proper kernel-doc and ignore the rest. 364a4c6ebedSDanilo Cesar Lemes de Paulamy $split_doc_state; 365a4c6ebedSDanilo Cesar Lemes de Paula 3661da177e4SLinus Torvalds#declaration types: can be 3671da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 3681da177e4SLinus Torvaldsmy $decl_type; 3691da177e4SLinus Torvalds 3701da177e4SLinus Torvaldsmy $doc_special = "\@\%\$\&"; 3711da177e4SLinus Torvalds 3721da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 3731da177e4SLinus Torvaldsmy $doc_end = '\*/'; 3741da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 37512ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 3761da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 377891dcd2fSRandy Dunlapmy $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)'; 37812ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 3791da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 380a4c6ebedSDanilo Cesar Lemes de Paulamy $doc_split_start = '^\s*/\*\*\s*$'; 381a4c6ebedSDanilo Cesar Lemes de Paulamy $doc_split_sect = '\s*\*\s*(@[\w\s]+):(.*)'; 382a4c6ebedSDanilo Cesar Lemes de Paulamy $doc_split_end = '^\s*\*/\s*$'; 3831da177e4SLinus Torvalds 3841da177e4SLinus Torvaldsmy %constants; 3851da177e4SLinus Torvaldsmy %parameterdescs; 3861da177e4SLinus Torvaldsmy @parameterlist; 3871da177e4SLinus Torvaldsmy %sections; 3881da177e4SLinus Torvaldsmy @sectionlist; 389a1d94aa5SRandy Dunlapmy $sectcheck; 390a1d94aa5SRandy Dunlapmy $struct_actual; 3911da177e4SLinus Torvalds 3921da177e4SLinus Torvaldsmy $contents = ""; 3931da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 3941da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 3951da177e4SLinus Torvaldsmy $section = $section_default; 3961da177e4SLinus Torvaldsmy $section_context = "Context"; 3974092bac7SYacine Belkadimy $section_return = "Return"; 3981da177e4SLinus Torvalds 3991da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 4001da177e4SLinus Torvalds 4011da177e4SLinus Torvaldsreset_state(); 4021da177e4SLinus Torvalds 4031da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) { 4041da177e4SLinus Torvalds my $cmd = shift @ARGV; 4051da177e4SLinus Torvalds if ($cmd eq "-html") { 4061da177e4SLinus Torvalds $output_mode = "html"; 4074d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_html; 4081da177e4SLinus Torvalds $blankline = $blankline_html; 4091b40c194SDan Luedtke } elsif ($cmd eq "-html5") { 4101b40c194SDan Luedtke $output_mode = "html5"; 4114d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_html5; 4121b40c194SDan Luedtke $blankline = $blankline_html5; 4131da177e4SLinus Torvalds } elsif ($cmd eq "-man") { 4141da177e4SLinus Torvalds $output_mode = "man"; 4154d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 4161da177e4SLinus Torvalds $blankline = $blankline_man; 4171da177e4SLinus Torvalds } elsif ($cmd eq "-text") { 4181da177e4SLinus Torvalds $output_mode = "text"; 4194d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_text; 4201da177e4SLinus Torvalds $blankline = $blankline_text; 421*c0d1b6eeSJonathan Corbet } elsif ($cmd eq "-rst") { 422*c0d1b6eeSJonathan Corbet $output_mode = "rst"; 423*c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 424*c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 4251da177e4SLinus Torvalds } elsif ($cmd eq "-docbook") { 4261da177e4SLinus Torvalds $output_mode = "xml"; 4274d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_xml; 4281da177e4SLinus Torvalds $blankline = $blankline_xml; 429eda603f6SJohannes Berg } elsif ($cmd eq "-list") { 430eda603f6SJohannes Berg $output_mode = "list"; 4314d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_list; 432eda603f6SJohannes Berg $blankline = $blankline_list; 4331da177e4SLinus Torvalds } elsif ($cmd eq "-gnome") { 4341da177e4SLinus Torvalds $output_mode = "gnome"; 4354d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_gnome; 4361da177e4SLinus Torvalds $blankline = $blankline_gnome; 4371da177e4SLinus Torvalds } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document 4381da177e4SLinus Torvalds $modulename = shift @ARGV; 4391da177e4SLinus Torvalds } elsif ($cmd eq "-function") { # to only output specific functions 4401da177e4SLinus Torvalds $function_only = 1; 4411da177e4SLinus Torvalds $function = shift @ARGV; 4421da177e4SLinus Torvalds $function_table{$function} = 1; 4431da177e4SLinus Torvalds } elsif ($cmd eq "-nofunction") { # to only output specific functions 4441da177e4SLinus Torvalds $function_only = 2; 4451da177e4SLinus Torvalds $function = shift @ARGV; 4461da177e4SLinus Torvalds $function_table{$function} = 1; 4471da177e4SLinus Torvalds } elsif ($cmd eq "-v") { 4481da177e4SLinus Torvalds $verbose = 1; 4491da177e4SLinus Torvalds } elsif (($cmd eq "-h") || ($cmd eq "--help")) { 4501da177e4SLinus Torvalds usage(); 4514b44595aSJohannes Berg } elsif ($cmd eq '-no-doc-sections') { 4524b44595aSJohannes Berg $no_doc_sections = 1; 453e946c43aSJohannes Berg } elsif ($cmd eq '-show-not-found') { 454e946c43aSJohannes Berg $show_not_found = 1; 4551da177e4SLinus Torvalds } 4561da177e4SLinus Torvalds} 4571da177e4SLinus Torvalds 4588484baaaSRandy Dunlap# continue execution near EOF; 4598484baaaSRandy Dunlap 46053f049faSBorislav Petkov# get kernel version from env 46153f049faSBorislav Petkovsub get_kernel_version() { 4621b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 46353f049faSBorislav Petkov 46453f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 46553f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 46653f049faSBorislav Petkov } 46753f049faSBorislav Petkov return $version; 46853f049faSBorislav Petkov} 4691da177e4SLinus Torvalds 4701da177e4SLinus Torvalds## 4711da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 4721da177e4SLinus Torvalds# 4731da177e4SLinus Torvaldssub dump_section { 47494dc7ad5SRandy Dunlap my $file = shift; 4751da177e4SLinus Torvalds my $name = shift; 4761da177e4SLinus Torvalds my $contents = join "\n", @_; 4771da177e4SLinus Torvalds 4781da177e4SLinus Torvalds if ($name =~ m/$type_constant/) { 4791da177e4SLinus Torvalds $name = $1; 4801da177e4SLinus Torvalds# print STDERR "constant section '$1' = '$contents'\n"; 4811da177e4SLinus Torvalds $constants{$name} = $contents; 4821da177e4SLinus Torvalds } elsif ($name =~ m/$type_param/) { 4831da177e4SLinus Torvalds# print STDERR "parameter def '$1' = '$contents'\n"; 4841da177e4SLinus Torvalds $name = $1; 4851da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 486a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 487ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 488ced69090SRandy Dunlap# print STDERR "parameter def '...' = '$contents'\n"; 489ced69090SRandy Dunlap $name = "..."; 490ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 491a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 4921da177e4SLinus Torvalds } else { 4931da177e4SLinus Torvalds# print STDERR "other section '$name' = '$contents'\n"; 49494dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 495d40e1e65SBart Van Assche print STDERR "${file}:$.: error: duplicate section name '$name'\n"; 49694dc7ad5SRandy Dunlap ++$errors; 49794dc7ad5SRandy Dunlap } 4981da177e4SLinus Torvalds $sections{$name} = $contents; 4991da177e4SLinus Torvalds push @sectionlist, $name; 5001da177e4SLinus Torvalds } 5011da177e4SLinus Torvalds} 5021da177e4SLinus Torvalds 5031da177e4SLinus Torvalds## 504b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 505b112e0f7SJohannes Berg# 506b112e0f7SJohannes Bergsub dump_doc_section { 50794dc7ad5SRandy Dunlap my $file = shift; 508b112e0f7SJohannes Berg my $name = shift; 509b112e0f7SJohannes Berg my $contents = join "\n", @_; 510b112e0f7SJohannes Berg 5114b44595aSJohannes Berg if ($no_doc_sections) { 5124b44595aSJohannes Berg return; 5134b44595aSJohannes Berg } 5144b44595aSJohannes Berg 515b112e0f7SJohannes Berg if (($function_only == 0) || 516b112e0f7SJohannes Berg ( $function_only == 1 && defined($function_table{$name})) || 517b112e0f7SJohannes Berg ( $function_only == 2 && !defined($function_table{$name}))) 518b112e0f7SJohannes Berg { 51994dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 520b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 521b112e0f7SJohannes Berg 'sections' => \%sections, 522b112e0f7SJohannes Berg 'module' => $modulename, 523b112e0f7SJohannes Berg 'content-only' => ($function_only != 0), }); 524b112e0f7SJohannes Berg } 525b112e0f7SJohannes Berg} 526b112e0f7SJohannes Berg 527b112e0f7SJohannes Berg## 5281da177e4SLinus Torvalds# output function 5291da177e4SLinus Torvalds# 5301da177e4SLinus Torvalds# parameterdescs, a hash. 5311da177e4SLinus Torvalds# function => "function name" 5321da177e4SLinus Torvalds# parameterlist => @list of parameters 5331da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 5341da177e4SLinus Torvalds# sectionlist => @list of sections 535a21217daSRandy Dunlap# sections => %section descriptions 5361da177e4SLinus Torvalds# 5371da177e4SLinus Torvalds 5381da177e4SLinus Torvaldssub output_highlight { 5391da177e4SLinus Torvalds my $contents = join "\n",@_; 5401da177e4SLinus Torvalds my $line; 5411da177e4SLinus Torvalds 5421da177e4SLinus Torvalds# DEBUG 5431da177e4SLinus Torvalds# if (!defined $contents) { 5441da177e4SLinus Torvalds# use Carp; 5451da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 5461da177e4SLinus Torvalds# } 5471da177e4SLinus Torvalds 5481b40c194SDan Luedtke if ($output_mode eq "html" || $output_mode eq "html5" || 5491b40c194SDan Luedtke $output_mode eq "xml") { 5506b5b55f6SRandy Dunlap $contents = local_unescape($contents); 5516b5b55f6SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 5522b35f4d9SRandy Dunlap $contents =~ s/\\\\\\/\&/g; 5536b5b55f6SRandy Dunlap } 5543eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 5551da177e4SLinus Torvalds eval $dohighlight; 5561da177e4SLinus Torvalds die $@ if $@; 5573eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 5583eb014a1SRandy Dunlap 5591b40c194SDan Luedtke# strip whitespaces when generating html5 5601b40c194SDan Luedtke if ($output_mode eq "html5") { 5611b40c194SDan Luedtke $contents =~ s/^\s+//; 5621b40c194SDan Luedtke $contents =~ s/\s+$//; 5631b40c194SDan Luedtke } 5641da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 56512ae6779SDaniel Santos if (! $output_preformatted) { 56612ae6779SDaniel Santos $line =~ s/^\s*//; 56712ae6779SDaniel Santos } 5681da177e4SLinus Torvalds if ($line eq ""){ 569e314ba31SDaniel Santos if (! $output_preformatted) { 5706b5b55f6SRandy Dunlap print $lineprefix, local_unescape($blankline); 571e314ba31SDaniel Santos } 5721da177e4SLinus Torvalds } else { 5731da177e4SLinus Torvalds $line =~ s/\\\\\\/\&/g; 574cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 575cdccb316SRandy Dunlap print "\\&$line"; 576cdccb316SRandy Dunlap } else { 5771da177e4SLinus Torvalds print $lineprefix, $line; 5781da177e4SLinus Torvalds } 579cdccb316SRandy Dunlap } 5801da177e4SLinus Torvalds print "\n"; 5811da177e4SLinus Torvalds } 5821da177e4SLinus Torvalds} 5831da177e4SLinus Torvalds 5841da177e4SLinus Torvalds# output sections in html 5851da177e4SLinus Torvaldssub output_section_html(%) { 5861da177e4SLinus Torvalds my %args = %{$_[0]}; 5871da177e4SLinus Torvalds my $section; 5881da177e4SLinus Torvalds 5891da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 5901da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 5911da177e4SLinus Torvalds print "<blockquote>\n"; 5921da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 5931da177e4SLinus Torvalds print "</blockquote>\n"; 5941da177e4SLinus Torvalds } 5951da177e4SLinus Torvalds} 5961da177e4SLinus Torvalds 5971da177e4SLinus Torvalds# output enum in html 5981da177e4SLinus Torvaldssub output_enum_html(%) { 5991da177e4SLinus Torvalds my %args = %{$_[0]}; 6001da177e4SLinus Torvalds my ($parameter); 6011da177e4SLinus Torvalds my $count; 6021da177e4SLinus Torvalds print "<h2>enum " . $args{'enum'} . "</h2>\n"; 6031da177e4SLinus Torvalds 6041da177e4SLinus Torvalds print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; 6051da177e4SLinus Torvalds $count = 0; 6061da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6071da177e4SLinus Torvalds print " <b>" . $parameter . "</b>"; 6081da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 6091da177e4SLinus Torvalds $count++; 6101da177e4SLinus Torvalds print ",\n"; 6111da177e4SLinus Torvalds } 6121da177e4SLinus Torvalds print "<br>"; 6131da177e4SLinus Torvalds } 6141da177e4SLinus Torvalds print "};<br>\n"; 6151da177e4SLinus Torvalds 6161da177e4SLinus Torvalds print "<h3>Constants</h3>\n"; 6171da177e4SLinus Torvalds print "<dl>\n"; 6181da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6191da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 6201da177e4SLinus Torvalds print "<dd>"; 6211da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter}); 6221da177e4SLinus Torvalds } 6231da177e4SLinus Torvalds print "</dl>\n"; 6241da177e4SLinus Torvalds output_section_html(@_); 6251da177e4SLinus Torvalds print "<hr>\n"; 6261da177e4SLinus Torvalds} 6271da177e4SLinus Torvalds 628d28bee0cSRandy Dunlap# output typedef in html 6291da177e4SLinus Torvaldssub output_typedef_html(%) { 6301da177e4SLinus Torvalds my %args = %{$_[0]}; 6311da177e4SLinus Torvalds my ($parameter); 6321da177e4SLinus Torvalds my $count; 6331da177e4SLinus Torvalds print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; 6341da177e4SLinus Torvalds 6351da177e4SLinus Torvalds print "<b>typedef " . $args{'typedef'} . "</b>\n"; 6361da177e4SLinus Torvalds output_section_html(@_); 6371da177e4SLinus Torvalds print "<hr>\n"; 6381da177e4SLinus Torvalds} 6391da177e4SLinus Torvalds 6401da177e4SLinus Torvalds# output struct in html 6411da177e4SLinus Torvaldssub output_struct_html(%) { 6421da177e4SLinus Torvalds my %args = %{$_[0]}; 6431da177e4SLinus Torvalds my ($parameter); 6441da177e4SLinus Torvalds 645262d9b01SRandy Dunlap print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; 6461da177e4SLinus Torvalds print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; 6471da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6481da177e4SLinus Torvalds if ($parameter =~ /^#/) { 6491da177e4SLinus Torvalds print "$parameter<br>\n"; 6501da177e4SLinus Torvalds next; 6511da177e4SLinus Torvalds } 6521da177e4SLinus Torvalds my $parameter_name = $parameter; 6531da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6541da177e4SLinus Torvalds 6551da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6561da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 6571da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 6581da177e4SLinus Torvalds # pointer-to-function 6593eb014a1SRandy Dunlap print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; 6601da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 6613eb014a1SRandy Dunlap # bitfield 6623eb014a1SRandy Dunlap print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; 6631da177e4SLinus Torvalds } else { 6643eb014a1SRandy Dunlap print " <i>$type</i> <b>$parameter</b>;<br>\n"; 6651da177e4SLinus Torvalds } 6661da177e4SLinus Torvalds } 6671da177e4SLinus Torvalds print "};<br>\n"; 6681da177e4SLinus Torvalds 6691da177e4SLinus Torvalds print "<h3>Members</h3>\n"; 6701da177e4SLinus Torvalds print "<dl>\n"; 6711da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6721da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 6731da177e4SLinus Torvalds 6741da177e4SLinus Torvalds my $parameter_name = $parameter; 6751da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6761da177e4SLinus Torvalds 6771da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6781da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 6791da177e4SLinus Torvalds print "<dd>"; 6801da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6811da177e4SLinus Torvalds } 6821da177e4SLinus Torvalds print "</dl>\n"; 6831da177e4SLinus Torvalds output_section_html(@_); 6841da177e4SLinus Torvalds print "<hr>\n"; 6851da177e4SLinus Torvalds} 6861da177e4SLinus Torvalds 6871da177e4SLinus Torvalds# output function in html 6881da177e4SLinus Torvaldssub output_function_html(%) { 6891da177e4SLinus Torvalds my %args = %{$_[0]}; 6901da177e4SLinus Torvalds my ($parameter, $section); 6911da177e4SLinus Torvalds my $count; 6921da177e4SLinus Torvalds 693262d9b01SRandy Dunlap print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; 6941da177e4SLinus Torvalds print "<i>" . $args{'functiontype'} . "</i>\n"; 6951da177e4SLinus Torvalds print "<b>" . $args{'function'} . "</b>\n"; 6961da177e4SLinus Torvalds print "("; 6971da177e4SLinus Torvalds $count = 0; 6981da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6991da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 7001da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 7011da177e4SLinus Torvalds # pointer-to-function 7021da177e4SLinus Torvalds print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; 7031da177e4SLinus Torvalds } else { 7041da177e4SLinus Torvalds print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; 7051da177e4SLinus Torvalds } 7061da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 7071da177e4SLinus Torvalds $count++; 7081da177e4SLinus Torvalds print ",\n"; 7091da177e4SLinus Torvalds } 7101da177e4SLinus Torvalds } 7111da177e4SLinus Torvalds print ")\n"; 7121da177e4SLinus Torvalds 7131da177e4SLinus Torvalds print "<h3>Arguments</h3>\n"; 7141da177e4SLinus Torvalds print "<dl>\n"; 7151da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7161da177e4SLinus Torvalds my $parameter_name = $parameter; 7171da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7181da177e4SLinus Torvalds 7191da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7201da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 7211da177e4SLinus Torvalds print "<dd>"; 7221da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7231da177e4SLinus Torvalds } 7241da177e4SLinus Torvalds print "</dl>\n"; 7251da177e4SLinus Torvalds output_section_html(@_); 7261da177e4SLinus Torvalds print "<hr>\n"; 7271da177e4SLinus Torvalds} 7281da177e4SLinus Torvalds 729b112e0f7SJohannes Berg# output DOC: block header in html 730b112e0f7SJohannes Bergsub output_blockhead_html(%) { 7311da177e4SLinus Torvalds my %args = %{$_[0]}; 7321da177e4SLinus Torvalds my ($parameter, $section); 7331da177e4SLinus Torvalds my $count; 7341da177e4SLinus Torvalds 7351da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7361da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 7371da177e4SLinus Torvalds print "<ul>\n"; 7381da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7391da177e4SLinus Torvalds print "</ul>\n"; 7401da177e4SLinus Torvalds } 7411da177e4SLinus Torvalds print "<hr>\n"; 7421da177e4SLinus Torvalds} 7431da177e4SLinus Torvalds 7441b40c194SDan Luedtke# output sections in html5 7451b40c194SDan Luedtkesub output_section_html5(%) { 7461b40c194SDan Luedtke my %args = %{$_[0]}; 7471b40c194SDan Luedtke my $section; 7481b40c194SDan Luedtke 7491b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 7501b40c194SDan Luedtke print "<section>\n"; 7511b40c194SDan Luedtke print "<h1>$section</h1>\n"; 7521b40c194SDan Luedtke print "<p>\n"; 7531b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 7541b40c194SDan Luedtke print "</p>\n"; 7551b40c194SDan Luedtke print "</section>\n"; 7561b40c194SDan Luedtke } 7571b40c194SDan Luedtke} 7581b40c194SDan Luedtke 7591b40c194SDan Luedtke# output enum in html5 7601b40c194SDan Luedtkesub output_enum_html5(%) { 7611b40c194SDan Luedtke my %args = %{$_[0]}; 7621b40c194SDan Luedtke my ($parameter); 7631b40c194SDan Luedtke my $count; 7641b40c194SDan Luedtke my $html5id; 7651b40c194SDan Luedtke 7661b40c194SDan Luedtke $html5id = $args{'enum'}; 7671b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 7681b40c194SDan Luedtke print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; 7691b40c194SDan Luedtke print "<h1>enum " . $args{'enum'} . "</h1>\n"; 7701b40c194SDan Luedtke print "<ol class=\"code\">\n"; 7711b40c194SDan Luedtke print "<li>"; 7721b40c194SDan Luedtke print "<span class=\"keyword\">enum</span> "; 7731b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; 7741b40c194SDan Luedtke print "</li>\n"; 7751b40c194SDan Luedtke $count = 0; 7761b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 7771b40c194SDan Luedtke print "<li class=\"indent\">"; 7781b40c194SDan Luedtke print "<span class=\"param\">" . $parameter . "</span>"; 7791b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 7801b40c194SDan Luedtke $count++; 7811b40c194SDan Luedtke print ","; 7821b40c194SDan Luedtke } 7831b40c194SDan Luedtke print "</li>\n"; 7841b40c194SDan Luedtke } 7851b40c194SDan Luedtke print "<li>};</li>\n"; 7861b40c194SDan Luedtke print "</ol>\n"; 7871b40c194SDan Luedtke 7881b40c194SDan Luedtke print "<section>\n"; 7891b40c194SDan Luedtke print "<h1>Constants</h1>\n"; 7901b40c194SDan Luedtke print "<dl>\n"; 7911b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 7921b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 7931b40c194SDan Luedtke print "<dd>"; 7941b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter}); 7951b40c194SDan Luedtke print "</dd>\n"; 7961b40c194SDan Luedtke } 7971b40c194SDan Luedtke print "</dl>\n"; 7981b40c194SDan Luedtke print "</section>\n"; 7991b40c194SDan Luedtke output_section_html5(@_); 8001b40c194SDan Luedtke print "</article>\n"; 8011b40c194SDan Luedtke} 8021b40c194SDan Luedtke 8031b40c194SDan Luedtke# output typedef in html5 8041b40c194SDan Luedtkesub output_typedef_html5(%) { 8051b40c194SDan Luedtke my %args = %{$_[0]}; 8061b40c194SDan Luedtke my ($parameter); 8071b40c194SDan Luedtke my $count; 8081b40c194SDan Luedtke my $html5id; 8091b40c194SDan Luedtke 8101b40c194SDan Luedtke $html5id = $args{'typedef'}; 8111b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8121b40c194SDan Luedtke print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; 8131b40c194SDan Luedtke print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; 8141b40c194SDan Luedtke 8151b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8161b40c194SDan Luedtke print "<li>"; 8171b40c194SDan Luedtke print "<span class=\"keyword\">typedef</span> "; 8181b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; 8191b40c194SDan Luedtke print "</li>\n"; 8201b40c194SDan Luedtke print "</ol>\n"; 8211b40c194SDan Luedtke output_section_html5(@_); 8221b40c194SDan Luedtke print "</article>\n"; 8231b40c194SDan Luedtke} 8241b40c194SDan Luedtke 8251b40c194SDan Luedtke# output struct in html5 8261b40c194SDan Luedtkesub output_struct_html5(%) { 8271b40c194SDan Luedtke my %args = %{$_[0]}; 8281b40c194SDan Luedtke my ($parameter); 8291b40c194SDan Luedtke my $html5id; 8301b40c194SDan Luedtke 8311b40c194SDan Luedtke $html5id = $args{'struct'}; 8321b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8331b40c194SDan Luedtke print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n"; 8341b40c194SDan Luedtke print "<hgroup>\n"; 8351b40c194SDan Luedtke print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>"; 8361b40c194SDan Luedtke print "<h2>". $args{'purpose'} . "</h2>\n"; 8371b40c194SDan Luedtke print "</hgroup>\n"; 8381b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8391b40c194SDan Luedtke print "<li>"; 8401b40c194SDan Luedtke print "<span class=\"type\">" . $args{'type'} . "</span> "; 8411b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'struct'} . "</span> {"; 8421b40c194SDan Luedtke print "</li>\n"; 8431b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8441b40c194SDan Luedtke print "<li class=\"indent\">"; 8451b40c194SDan Luedtke if ($parameter =~ /^#/) { 8461b40c194SDan Luedtke print "<span class=\"param\">" . $parameter ."</span>\n"; 8471b40c194SDan Luedtke print "</li>\n"; 8481b40c194SDan Luedtke next; 8491b40c194SDan Luedtke } 8501b40c194SDan Luedtke my $parameter_name = $parameter; 8511b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 8521b40c194SDan Luedtke 8531b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 8541b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 8551b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 8561b40c194SDan Luedtke # pointer-to-function 8571b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 8581b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 8591b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 8601b40c194SDan Luedtke print "(<span class=\"args\">$2</span>);"; 8611b40c194SDan Luedtke } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 8621b40c194SDan Luedtke # bitfield 8631b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 8641b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 8651b40c194SDan Luedtke print "<span class=\"bits\">$2</span>;"; 8661b40c194SDan Luedtke } else { 8671b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 8681b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>;"; 8691b40c194SDan Luedtke } 8701b40c194SDan Luedtke print "</li>\n"; 8711b40c194SDan Luedtke } 8721b40c194SDan Luedtke print "<li>};</li>\n"; 8731b40c194SDan Luedtke print "</ol>\n"; 8741b40c194SDan Luedtke 8751b40c194SDan Luedtke print "<section>\n"; 8761b40c194SDan Luedtke print "<h1>Members</h1>\n"; 8771b40c194SDan Luedtke print "<dl>\n"; 8781b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8791b40c194SDan Luedtke ($parameter =~ /^#/) && next; 8801b40c194SDan Luedtke 8811b40c194SDan Luedtke my $parameter_name = $parameter; 8821b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 8831b40c194SDan Luedtke 8841b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 8851b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 8861b40c194SDan Luedtke print "<dd>"; 8871b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 8881b40c194SDan Luedtke print "</dd>\n"; 8891b40c194SDan Luedtke } 8901b40c194SDan Luedtke print "</dl>\n"; 8911b40c194SDan Luedtke print "</section>\n"; 8921b40c194SDan Luedtke output_section_html5(@_); 8931b40c194SDan Luedtke print "</article>\n"; 8941b40c194SDan Luedtke} 8951b40c194SDan Luedtke 8961b40c194SDan Luedtke# output function in html5 8971b40c194SDan Luedtkesub output_function_html5(%) { 8981b40c194SDan Luedtke my %args = %{$_[0]}; 8991b40c194SDan Luedtke my ($parameter, $section); 9001b40c194SDan Luedtke my $count; 9011b40c194SDan Luedtke my $html5id; 9021b40c194SDan Luedtke 9031b40c194SDan Luedtke $html5id = $args{'function'}; 9041b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 9051b40c194SDan Luedtke print "<article class=\"function\" id=\"func:". $html5id . "\">\n"; 9061b40c194SDan Luedtke print "<hgroup>\n"; 9071b40c194SDan Luedtke print "<h1>" . $args{'function'} . "</h1>"; 9081b40c194SDan Luedtke print "<h2>" . $args{'purpose'} . "</h2>\n"; 9091b40c194SDan Luedtke print "</hgroup>\n"; 9101b40c194SDan Luedtke print "<ol class=\"code\">\n"; 9111b40c194SDan Luedtke print "<li>"; 9121b40c194SDan Luedtke print "<span class=\"type\">" . $args{'functiontype'} . "</span> "; 9131b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'function'} . "</span> ("; 9141b40c194SDan Luedtke print "</li>"; 9151b40c194SDan Luedtke $count = 0; 9161b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9171b40c194SDan Luedtke print "<li class=\"indent\">"; 9181b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 9191b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 9201b40c194SDan Luedtke # pointer-to-function 9211b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 9221b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9231b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 9241b40c194SDan Luedtke print "(<span class=\"args\">$2</span>)"; 9251b40c194SDan Luedtke } else { 9261b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 9271b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9281b40c194SDan Luedtke } 9291b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 9301b40c194SDan Luedtke $count++; 9311b40c194SDan Luedtke print ","; 9321b40c194SDan Luedtke } 9331b40c194SDan Luedtke print "</li>\n"; 9341b40c194SDan Luedtke } 9351b40c194SDan Luedtke print "<li>)</li>\n"; 9361b40c194SDan Luedtke print "</ol>\n"; 9371b40c194SDan Luedtke 9381b40c194SDan Luedtke print "<section>\n"; 9391b40c194SDan Luedtke print "<h1>Arguments</h1>\n"; 9401b40c194SDan Luedtke print "<p>\n"; 9411b40c194SDan Luedtke print "<dl>\n"; 9421b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9431b40c194SDan Luedtke my $parameter_name = $parameter; 9441b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 9451b40c194SDan Luedtke 9461b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 9471b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 9481b40c194SDan Luedtke print "<dd>"; 9491b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 9501b40c194SDan Luedtke print "</dd>\n"; 9511b40c194SDan Luedtke } 9521b40c194SDan Luedtke print "</dl>\n"; 9531b40c194SDan Luedtke print "</section>\n"; 9541b40c194SDan Luedtke output_section_html5(@_); 9551b40c194SDan Luedtke print "</article>\n"; 9561b40c194SDan Luedtke} 9571b40c194SDan Luedtke 9581b40c194SDan Luedtke# output DOC: block header in html5 9591b40c194SDan Luedtkesub output_blockhead_html5(%) { 9601b40c194SDan Luedtke my %args = %{$_[0]}; 9611b40c194SDan Luedtke my ($parameter, $section); 9621b40c194SDan Luedtke my $count; 9631b40c194SDan Luedtke my $html5id; 9641b40c194SDan Luedtke 9651b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 9661b40c194SDan Luedtke $html5id = $section; 9671b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 9681b40c194SDan Luedtke print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n"; 9691b40c194SDan Luedtke print "<h1>$section</h1>\n"; 9701b40c194SDan Luedtke print "<p>\n"; 9711b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 9721b40c194SDan Luedtke print "</p>\n"; 9731b40c194SDan Luedtke } 9741b40c194SDan Luedtke print "</article>\n"; 9751b40c194SDan Luedtke} 9761b40c194SDan Luedtke 9771da177e4SLinus Torvaldssub output_section_xml(%) { 9781da177e4SLinus Torvalds my %args = %{$_[0]}; 9791da177e4SLinus Torvalds my $section; 9801da177e4SLinus Torvalds # print out each section 9811da177e4SLinus Torvalds $lineprefix=" "; 9821da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 983c73894c1SRich Walker print "<refsect1>\n"; 984c73894c1SRich Walker print "<title>$section</title>\n"; 9851da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 986c73894c1SRich Walker print "<informalexample><programlisting>\n"; 987e314ba31SDaniel Santos $output_preformatted = 1; 988c73894c1SRich Walker } else { 989c73894c1SRich Walker print "<para>\n"; 9901da177e4SLinus Torvalds } 9911da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 992e314ba31SDaniel Santos $output_preformatted = 0; 9931da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 994c73894c1SRich Walker print "</programlisting></informalexample>\n"; 995c73894c1SRich Walker } else { 996c73894c1SRich Walker print "</para>\n"; 9971da177e4SLinus Torvalds } 998c73894c1SRich Walker print "</refsect1>\n"; 9991da177e4SLinus Torvalds } 10001da177e4SLinus Torvalds} 10011da177e4SLinus Torvalds 10021da177e4SLinus Torvalds# output function in XML DocBook 10031da177e4SLinus Torvaldssub output_function_xml(%) { 10041da177e4SLinus Torvalds my %args = %{$_[0]}; 10051da177e4SLinus Torvalds my ($parameter, $section); 10061da177e4SLinus Torvalds my $count; 10071da177e4SLinus Torvalds my $id; 10081da177e4SLinus Torvalds 10091da177e4SLinus Torvalds $id = "API-" . $args{'function'}; 10101da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 10111da177e4SLinus Torvalds 10125449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 10138b0c2d98SMartin Waitz print "<refentryinfo>\n"; 10148b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 10158b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 10168b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 10178b0c2d98SMartin Waitz print "</refentryinfo>\n"; 10181da177e4SLinus Torvalds print "<refmeta>\n"; 10195449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; 10208b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 10210366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 10221da177e4SLinus Torvalds print "</refmeta>\n"; 10231da177e4SLinus Torvalds print "<refnamediv>\n"; 10241da177e4SLinus Torvalds print " <refname>" . $args{'function'} . "</refname>\n"; 10251da177e4SLinus Torvalds print " <refpurpose>\n"; 10261da177e4SLinus Torvalds print " "; 10271da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 10281da177e4SLinus Torvalds print " </refpurpose>\n"; 10291da177e4SLinus Torvalds print "</refnamediv>\n"; 10301da177e4SLinus Torvalds 10311da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 10321da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 10331da177e4SLinus Torvalds print " <funcsynopsis><funcprototype>\n"; 10341da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 10351da177e4SLinus Torvalds print "<function>" . $args{'function'} . " </function></funcdef>\n"; 10361da177e4SLinus Torvalds 10371da177e4SLinus Torvalds $count = 0; 10381da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 10391da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10401da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 10411da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 10421da177e4SLinus Torvalds # pointer-to-function 10431da177e4SLinus Torvalds print " <paramdef>$1<parameter>$parameter</parameter>)\n"; 10441da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 10451da177e4SLinus Torvalds } else { 10461da177e4SLinus Torvalds print " <paramdef>" . $type; 10471da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 10481da177e4SLinus Torvalds } 10491da177e4SLinus Torvalds } 10501da177e4SLinus Torvalds } else { 10516013d544SMartin Waitz print " <void/>\n"; 10521da177e4SLinus Torvalds } 10531da177e4SLinus Torvalds print " </funcprototype></funcsynopsis>\n"; 10541da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 10551da177e4SLinus Torvalds 10561da177e4SLinus Torvalds # print parameters 10571da177e4SLinus Torvalds print "<refsect1>\n <title>Arguments</title>\n"; 10581da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 10591da177e4SLinus Torvalds print " <variablelist>\n"; 10601da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10611da177e4SLinus Torvalds my $parameter_name = $parameter; 10621da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 10631da177e4SLinus Torvalds 10641da177e4SLinus Torvalds print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; 10651da177e4SLinus Torvalds print " <listitem>\n <para>\n"; 10661da177e4SLinus Torvalds $lineprefix=" "; 10671da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 10681da177e4SLinus Torvalds print " </para>\n </listitem>\n </varlistentry>\n"; 10691da177e4SLinus Torvalds } 10701da177e4SLinus Torvalds print " </variablelist>\n"; 10711da177e4SLinus Torvalds } else { 10721da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 10731da177e4SLinus Torvalds } 10741da177e4SLinus Torvalds print "</refsect1>\n"; 10751da177e4SLinus Torvalds 10761da177e4SLinus Torvalds output_section_xml(@_); 10771da177e4SLinus Torvalds print "</refentry>\n\n"; 10781da177e4SLinus Torvalds} 10791da177e4SLinus Torvalds 10801da177e4SLinus Torvalds# output struct in XML DocBook 10811da177e4SLinus Torvaldssub output_struct_xml(%) { 10821da177e4SLinus Torvalds my %args = %{$_[0]}; 10831da177e4SLinus Torvalds my ($parameter, $section); 10841da177e4SLinus Torvalds my $id; 10851da177e4SLinus Torvalds 10861da177e4SLinus Torvalds $id = "API-struct-" . $args{'struct'}; 10871da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 10881da177e4SLinus Torvalds 10895449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 10908b0c2d98SMartin Waitz print "<refentryinfo>\n"; 10918b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 10928b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 10938b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 10948b0c2d98SMartin Waitz print "</refentryinfo>\n"; 10951da177e4SLinus Torvalds print "<refmeta>\n"; 10965449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; 10978b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 10980366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 10991da177e4SLinus Torvalds print "</refmeta>\n"; 11001da177e4SLinus Torvalds print "<refnamediv>\n"; 11011da177e4SLinus Torvalds print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; 11021da177e4SLinus Torvalds print " <refpurpose>\n"; 11031da177e4SLinus Torvalds print " "; 11041da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 11051da177e4SLinus Torvalds print " </refpurpose>\n"; 11061da177e4SLinus Torvalds print "</refnamediv>\n"; 11071da177e4SLinus Torvalds 11081da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 11091da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 11101da177e4SLinus Torvalds print " <programlisting>\n"; 11111da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 11121da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11131da177e4SLinus Torvalds if ($parameter =~ /^#/) { 11142b35f4d9SRandy Dunlap my $prm = $parameter; 11152b35f4d9SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 11162b35f4d9SRandy Dunlap # This allows us to have #define macros interspersed in a struct. 11172b35f4d9SRandy Dunlap $prm =~ s/\\\\\\/\&/g; 11182b35f4d9SRandy Dunlap print "$prm\n"; 11191da177e4SLinus Torvalds next; 11201da177e4SLinus Torvalds } 11211da177e4SLinus Torvalds 11221da177e4SLinus Torvalds my $parameter_name = $parameter; 11231da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11241da177e4SLinus Torvalds 11251da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 11261da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 11271da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 11281da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 11291da177e4SLinus Torvalds # pointer-to-function 11301da177e4SLinus Torvalds print " $1 $parameter) ($2);\n"; 11311da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 113251f5a0c8SRandy Dunlap # bitfield 11331da177e4SLinus Torvalds print " $1 $parameter$2;\n"; 11341da177e4SLinus Torvalds } else { 11351da177e4SLinus Torvalds print " " . $type . " " . $parameter . ";\n"; 11361da177e4SLinus Torvalds } 11371da177e4SLinus Torvalds } 11381da177e4SLinus Torvalds print "};"; 11391da177e4SLinus Torvalds print " </programlisting>\n"; 11401da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 11411da177e4SLinus Torvalds 11421da177e4SLinus Torvalds print " <refsect1>\n"; 11431da177e4SLinus Torvalds print " <title>Members</title>\n"; 11441da177e4SLinus Torvalds 114539f00c08SRandy Dunlap if ($#{$args{'parameterlist'}} >= 0) { 11461da177e4SLinus Torvalds print " <variablelist>\n"; 11471da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11481da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 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 print " <varlistentry>"; 11561da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 11571da177e4SLinus Torvalds print " <listitem><para>\n"; 11581da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 11591da177e4SLinus Torvalds print " </para></listitem>\n"; 11601da177e4SLinus Torvalds print " </varlistentry>\n"; 11611da177e4SLinus Torvalds } 11621da177e4SLinus Torvalds print " </variablelist>\n"; 116339f00c08SRandy Dunlap } else { 116439f00c08SRandy Dunlap print " <para>\n None\n </para>\n"; 116539f00c08SRandy Dunlap } 11661da177e4SLinus Torvalds print " </refsect1>\n"; 11671da177e4SLinus Torvalds 11681da177e4SLinus Torvalds output_section_xml(@_); 11691da177e4SLinus Torvalds 11701da177e4SLinus Torvalds print "</refentry>\n\n"; 11711da177e4SLinus Torvalds} 11721da177e4SLinus Torvalds 11731da177e4SLinus Torvalds# output enum in XML DocBook 11741da177e4SLinus Torvaldssub output_enum_xml(%) { 11751da177e4SLinus Torvalds my %args = %{$_[0]}; 11761da177e4SLinus Torvalds my ($parameter, $section); 11771da177e4SLinus Torvalds my $count; 11781da177e4SLinus Torvalds my $id; 11791da177e4SLinus Torvalds 11801da177e4SLinus Torvalds $id = "API-enum-" . $args{'enum'}; 11811da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 11821da177e4SLinus Torvalds 11835449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 11848b0c2d98SMartin Waitz print "<refentryinfo>\n"; 11858b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 11868b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 11878b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 11888b0c2d98SMartin Waitz print "</refentryinfo>\n"; 11891da177e4SLinus Torvalds print "<refmeta>\n"; 11905449bc94SPavel Pisa print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; 11918b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 11920366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 11931da177e4SLinus Torvalds print "</refmeta>\n"; 11941da177e4SLinus Torvalds print "<refnamediv>\n"; 11951da177e4SLinus Torvalds print " <refname>enum " . $args{'enum'} . "</refname>\n"; 11961da177e4SLinus Torvalds print " <refpurpose>\n"; 11971da177e4SLinus Torvalds print " "; 11981da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 11991da177e4SLinus Torvalds print " </refpurpose>\n"; 12001da177e4SLinus Torvalds print "</refnamediv>\n"; 12011da177e4SLinus Torvalds 12021da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 12031da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 12041da177e4SLinus Torvalds print " <programlisting>\n"; 12051da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 12061da177e4SLinus Torvalds $count = 0; 12071da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12081da177e4SLinus Torvalds print " $parameter"; 12091da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 12101da177e4SLinus Torvalds $count++; 12111da177e4SLinus Torvalds print ","; 12121da177e4SLinus Torvalds } 12131da177e4SLinus Torvalds print "\n"; 12141da177e4SLinus Torvalds } 12151da177e4SLinus Torvalds print "};"; 12161da177e4SLinus Torvalds print " </programlisting>\n"; 12171da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 12181da177e4SLinus Torvalds 12191da177e4SLinus Torvalds print "<refsect1>\n"; 12201da177e4SLinus Torvalds print " <title>Constants</title>\n"; 12211da177e4SLinus Torvalds print " <variablelist>\n"; 12221da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12231da177e4SLinus Torvalds my $parameter_name = $parameter; 12241da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12251da177e4SLinus Torvalds 12261da177e4SLinus Torvalds print " <varlistentry>"; 12271da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 12281da177e4SLinus Torvalds print " <listitem><para>\n"; 12291da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 12301da177e4SLinus Torvalds print " </para></listitem>\n"; 12311da177e4SLinus Torvalds print " </varlistentry>\n"; 12321da177e4SLinus Torvalds } 12331da177e4SLinus Torvalds print " </variablelist>\n"; 12341da177e4SLinus Torvalds print "</refsect1>\n"; 12351da177e4SLinus Torvalds 12361da177e4SLinus Torvalds output_section_xml(@_); 12371da177e4SLinus Torvalds 12381da177e4SLinus Torvalds print "</refentry>\n\n"; 12391da177e4SLinus Torvalds} 12401da177e4SLinus Torvalds 12411da177e4SLinus Torvalds# output typedef in XML DocBook 12421da177e4SLinus Torvaldssub output_typedef_xml(%) { 12431da177e4SLinus Torvalds my %args = %{$_[0]}; 12441da177e4SLinus Torvalds my ($parameter, $section); 12451da177e4SLinus Torvalds my $id; 12461da177e4SLinus Torvalds 12471da177e4SLinus Torvalds $id = "API-typedef-" . $args{'typedef'}; 12481da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12491da177e4SLinus Torvalds 12505449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 12518b0c2d98SMartin Waitz print "<refentryinfo>\n"; 12528b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 12538b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 12548b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 12558b0c2d98SMartin Waitz print "</refentryinfo>\n"; 12561da177e4SLinus Torvalds print "<refmeta>\n"; 12575449bc94SPavel Pisa print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; 12588b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 12591da177e4SLinus Torvalds print "</refmeta>\n"; 12601da177e4SLinus Torvalds print "<refnamediv>\n"; 12611da177e4SLinus Torvalds print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; 12621da177e4SLinus Torvalds print " <refpurpose>\n"; 12631da177e4SLinus Torvalds print " "; 12641da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 12651da177e4SLinus Torvalds print " </refpurpose>\n"; 12661da177e4SLinus Torvalds print "</refnamediv>\n"; 12671da177e4SLinus Torvalds 12681da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 12691da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 12701da177e4SLinus Torvalds print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; 12711da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 12721da177e4SLinus Torvalds 12731da177e4SLinus Torvalds output_section_xml(@_); 12741da177e4SLinus Torvalds 12751da177e4SLinus Torvalds print "</refentry>\n\n"; 12761da177e4SLinus Torvalds} 12771da177e4SLinus Torvalds 12781da177e4SLinus Torvalds# output in XML DocBook 1279b112e0f7SJohannes Bergsub output_blockhead_xml(%) { 12801da177e4SLinus Torvalds my %args = %{$_[0]}; 12811da177e4SLinus Torvalds my ($parameter, $section); 12821da177e4SLinus Torvalds my $count; 12831da177e4SLinus Torvalds 12841da177e4SLinus Torvalds my $id = $args{'module'}; 12851da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12861da177e4SLinus Torvalds 12871da177e4SLinus Torvalds # print out each section 12881da177e4SLinus Torvalds $lineprefix=" "; 12891da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1290b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1291b112e0f7SJohannes Berg print "<refsect1>\n <title>$section</title>\n"; 1292b112e0f7SJohannes Berg } 12931da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 12941da177e4SLinus Torvalds print "<example><para>\n"; 1295e314ba31SDaniel Santos $output_preformatted = 1; 1296b112e0f7SJohannes Berg } else { 1297b112e0f7SJohannes Berg print "<para>\n"; 12981da177e4SLinus Torvalds } 12991da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1300e314ba31SDaniel Santos $output_preformatted = 0; 13011da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13021da177e4SLinus Torvalds print "</para></example>\n"; 1303b112e0f7SJohannes Berg } else { 1304b112e0f7SJohannes Berg print "</para>"; 13051da177e4SLinus Torvalds } 1306b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1307b112e0f7SJohannes Berg print "\n</refsect1>\n"; 1308b112e0f7SJohannes Berg } 13091da177e4SLinus Torvalds } 13101da177e4SLinus Torvalds 13111da177e4SLinus Torvalds print "\n\n"; 13121da177e4SLinus Torvalds} 13131da177e4SLinus Torvalds 13141da177e4SLinus Torvalds# output in XML DocBook 13151da177e4SLinus Torvaldssub output_function_gnome { 13161da177e4SLinus Torvalds my %args = %{$_[0]}; 13171da177e4SLinus Torvalds my ($parameter, $section); 13181da177e4SLinus Torvalds my $count; 13191da177e4SLinus Torvalds my $id; 13201da177e4SLinus Torvalds 13211da177e4SLinus Torvalds $id = $args{'module'} . "-" . $args{'function'}; 13221da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13231da177e4SLinus Torvalds 13241da177e4SLinus Torvalds print "<sect2>\n"; 13251da177e4SLinus Torvalds print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; 13261da177e4SLinus Torvalds 13271da177e4SLinus Torvalds print " <funcsynopsis>\n"; 13281da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 13291da177e4SLinus Torvalds print "<function>" . $args{'function'} . " "; 13301da177e4SLinus Torvalds print "</function></funcdef>\n"; 13311da177e4SLinus Torvalds 13321da177e4SLinus Torvalds $count = 0; 13331da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 13341da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13351da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 13361da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 13371da177e4SLinus Torvalds # pointer-to-function 13381da177e4SLinus Torvalds print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; 13391da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 13401da177e4SLinus Torvalds } else { 13411da177e4SLinus Torvalds print " <paramdef>" . $type; 13421da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 13431da177e4SLinus Torvalds } 13441da177e4SLinus Torvalds } 13451da177e4SLinus Torvalds } else { 13461da177e4SLinus Torvalds print " <void>\n"; 13471da177e4SLinus Torvalds } 13481da177e4SLinus Torvalds print " </funcsynopsis>\n"; 13491da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 13501da177e4SLinus Torvalds print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; 13511da177e4SLinus Torvalds print "<tgroup cols=\"2\">\n"; 13521da177e4SLinus Torvalds print "<colspec colwidth=\"2*\">\n"; 13531da177e4SLinus Torvalds print "<colspec colwidth=\"8*\">\n"; 13541da177e4SLinus Torvalds print "<tbody>\n"; 13551da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13561da177e4SLinus Torvalds my $parameter_name = $parameter; 13571da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 13581da177e4SLinus Torvalds 13591da177e4SLinus Torvalds print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; 13601da177e4SLinus Torvalds print " <entry>\n"; 13611da177e4SLinus Torvalds $lineprefix=" "; 13621da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 13631da177e4SLinus Torvalds print " </entry></row>\n"; 13641da177e4SLinus Torvalds } 13651da177e4SLinus Torvalds print " </tbody></tgroup></informaltable>\n"; 13661da177e4SLinus Torvalds } else { 13671da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 13681da177e4SLinus Torvalds } 13691da177e4SLinus Torvalds 13701da177e4SLinus Torvalds # print out each section 13711da177e4SLinus Torvalds $lineprefix=" "; 13721da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 13731da177e4SLinus Torvalds print "<simplesect>\n <title>$section</title>\n"; 13741da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13751da177e4SLinus Torvalds print "<example><programlisting>\n"; 1376e314ba31SDaniel Santos $output_preformatted = 1; 13771da177e4SLinus Torvalds } else { 13781da177e4SLinus Torvalds } 13791da177e4SLinus Torvalds print "<para>\n"; 13801da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1381e314ba31SDaniel Santos $output_preformatted = 0; 13821da177e4SLinus Torvalds print "</para>\n"; 13831da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13841da177e4SLinus Torvalds print "</programlisting></example>\n"; 13851da177e4SLinus Torvalds } else { 13861da177e4SLinus Torvalds } 13871da177e4SLinus Torvalds print " </simplesect>\n"; 13881da177e4SLinus Torvalds } 13891da177e4SLinus Torvalds 13901da177e4SLinus Torvalds print "</sect2>\n\n"; 13911da177e4SLinus Torvalds} 13921da177e4SLinus Torvalds 13931da177e4SLinus Torvalds## 13941da177e4SLinus Torvalds# output function in man 13951da177e4SLinus Torvaldssub output_function_man(%) { 13961da177e4SLinus Torvalds my %args = %{$_[0]}; 13971da177e4SLinus Torvalds my ($parameter, $section); 13981da177e4SLinus Torvalds my $count; 13991da177e4SLinus Torvalds 14001da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 14011da177e4SLinus Torvalds 14021da177e4SLinus Torvalds print ".SH NAME\n"; 14031da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 14041da177e4SLinus Torvalds 14051da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 1406a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 14071da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 1408a21217daSRandy Dunlap } else { 1409a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 1410a21217daSRandy Dunlap } 14111da177e4SLinus Torvalds $count = 0; 14121da177e4SLinus Torvalds my $parenth = "("; 14131da177e4SLinus Torvalds my $post = ","; 14141da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 14151da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 14161da177e4SLinus Torvalds $post = ");"; 14171da177e4SLinus Torvalds } 14181da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 14191da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 14201da177e4SLinus Torvalds # pointer-to-function 14211da177e4SLinus Torvalds print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 14221da177e4SLinus Torvalds } else { 14231da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 14241da177e4SLinus Torvalds print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 14251da177e4SLinus Torvalds } 14261da177e4SLinus Torvalds $count++; 14271da177e4SLinus Torvalds $parenth = ""; 14281da177e4SLinus Torvalds } 14291da177e4SLinus Torvalds 14301da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 14311da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14321da177e4SLinus Torvalds my $parameter_name = $parameter; 14331da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14341da177e4SLinus Torvalds 14351da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 14361da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14371da177e4SLinus Torvalds } 14381da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14391da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 14401da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 14411da177e4SLinus Torvalds } 14421da177e4SLinus Torvalds} 14431da177e4SLinus Torvalds 14441da177e4SLinus Torvalds## 14451da177e4SLinus Torvalds# output enum in man 14461da177e4SLinus Torvaldssub output_enum_man(%) { 14471da177e4SLinus Torvalds my %args = %{$_[0]}; 14481da177e4SLinus Torvalds my ($parameter, $section); 14491da177e4SLinus Torvalds my $count; 14501da177e4SLinus Torvalds 14511da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 14521da177e4SLinus Torvalds 14531da177e4SLinus Torvalds print ".SH NAME\n"; 14541da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 14551da177e4SLinus Torvalds 14561da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 14571da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 14581da177e4SLinus Torvalds $count = 0; 14591da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 14601da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 14611da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 14621da177e4SLinus Torvalds print "\n};\n"; 14631da177e4SLinus Torvalds last; 14641da177e4SLinus Torvalds } 14651da177e4SLinus Torvalds else { 14661da177e4SLinus Torvalds print ", \n.br\n"; 14671da177e4SLinus Torvalds } 14681da177e4SLinus Torvalds $count++; 14691da177e4SLinus Torvalds } 14701da177e4SLinus Torvalds 14711da177e4SLinus Torvalds print ".SH Constants\n"; 14721da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14731da177e4SLinus Torvalds my $parameter_name = $parameter; 14741da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14751da177e4SLinus Torvalds 14761da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 14771da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14781da177e4SLinus Torvalds } 14791da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14801da177e4SLinus Torvalds print ".SH \"$section\"\n"; 14811da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 14821da177e4SLinus Torvalds } 14831da177e4SLinus Torvalds} 14841da177e4SLinus Torvalds 14851da177e4SLinus Torvalds## 14861da177e4SLinus Torvalds# output struct in man 14871da177e4SLinus Torvaldssub output_struct_man(%) { 14881da177e4SLinus Torvalds my %args = %{$_[0]}; 14891da177e4SLinus Torvalds my ($parameter, $section); 14901da177e4SLinus Torvalds 14911da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 14921da177e4SLinus Torvalds 14931da177e4SLinus Torvalds print ".SH NAME\n"; 14941da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 14951da177e4SLinus Torvalds 14961da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 14971da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 14981da177e4SLinus Torvalds 14991da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15001da177e4SLinus Torvalds if ($parameter =~ /^#/) { 15011da177e4SLinus Torvalds print ".BI \"$parameter\"\n.br\n"; 15021da177e4SLinus Torvalds next; 15031da177e4SLinus Torvalds } 15041da177e4SLinus Torvalds my $parameter_name = $parameter; 15051da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15061da177e4SLinus Torvalds 15071da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 15081da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 15091da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 15101da177e4SLinus Torvalds # pointer-to-function 15111da177e4SLinus Torvalds print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; 15121da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 15131d7e1d45SRandy.Dunlap # bitfield 15141d7e1d45SRandy.Dunlap print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; 15151da177e4SLinus Torvalds } else { 15161da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 15171da177e4SLinus Torvalds print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; 15181da177e4SLinus Torvalds } 15191da177e4SLinus Torvalds print "\n.br\n"; 15201da177e4SLinus Torvalds } 15211da177e4SLinus Torvalds print "};\n.br\n"; 15221da177e4SLinus Torvalds 1523c51d3dacSRandy Dunlap print ".SH Members\n"; 15241da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15251da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 15261da177e4SLinus Torvalds 15271da177e4SLinus Torvalds my $parameter_name = $parameter; 15281da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15291da177e4SLinus Torvalds 15301da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 15311da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 15321da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 15331da177e4SLinus Torvalds } 15341da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15351da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15361da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15371da177e4SLinus Torvalds } 15381da177e4SLinus Torvalds} 15391da177e4SLinus Torvalds 15401da177e4SLinus Torvalds## 15411da177e4SLinus Torvalds# output typedef in man 15421da177e4SLinus Torvaldssub output_typedef_man(%) { 15431da177e4SLinus Torvalds my %args = %{$_[0]}; 15441da177e4SLinus Torvalds my ($parameter, $section); 15451da177e4SLinus Torvalds 15461da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 15471da177e4SLinus Torvalds 15481da177e4SLinus Torvalds print ".SH NAME\n"; 15491da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 15501da177e4SLinus Torvalds 15511da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15521da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15531da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15541da177e4SLinus Torvalds } 15551da177e4SLinus Torvalds} 15561da177e4SLinus Torvalds 1557b112e0f7SJohannes Bergsub output_blockhead_man(%) { 15581da177e4SLinus Torvalds my %args = %{$_[0]}; 15591da177e4SLinus Torvalds my ($parameter, $section); 15601da177e4SLinus Torvalds my $count; 15611da177e4SLinus Torvalds 15621da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 15631da177e4SLinus Torvalds 15641da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15651da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15661da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15671da177e4SLinus Torvalds } 15681da177e4SLinus Torvalds} 15691da177e4SLinus Torvalds 15701da177e4SLinus Torvalds## 15711da177e4SLinus Torvalds# output in text 15721da177e4SLinus Torvaldssub output_function_text(%) { 15731da177e4SLinus Torvalds my %args = %{$_[0]}; 15741da177e4SLinus Torvalds my ($parameter, $section); 1575a21217daSRandy Dunlap my $start; 15761da177e4SLinus Torvalds 1577f47634b2SRandy Dunlap print "Name:\n\n"; 1578f47634b2SRandy Dunlap print $args{'function'} . " - " . $args{'purpose'} . "\n"; 1579f47634b2SRandy Dunlap 1580f47634b2SRandy Dunlap print "\nSynopsis:\n\n"; 1581a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 1582a21217daSRandy Dunlap $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1583a21217daSRandy Dunlap } else { 1584a21217daSRandy Dunlap $start = $args{'function'} . " ("; 1585a21217daSRandy Dunlap } 15861da177e4SLinus Torvalds print $start; 1587a21217daSRandy Dunlap 15881da177e4SLinus Torvalds my $count = 0; 15891da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15901da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 15911da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 15921da177e4SLinus Torvalds # pointer-to-function 15931da177e4SLinus Torvalds print $1 . $parameter . ") (" . $2; 15941da177e4SLinus Torvalds } else { 15951da177e4SLinus Torvalds print $type . " " . $parameter; 15961da177e4SLinus Torvalds } 15971da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 15981da177e4SLinus Torvalds $count++; 15991da177e4SLinus Torvalds print ",\n"; 16001da177e4SLinus Torvalds print " " x length($start); 16011da177e4SLinus Torvalds } else { 16021da177e4SLinus Torvalds print ");\n\n"; 16031da177e4SLinus Torvalds } 16041da177e4SLinus Torvalds } 16051da177e4SLinus Torvalds 16061da177e4SLinus Torvalds print "Arguments:\n\n"; 16071da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16081da177e4SLinus Torvalds my $parameter_name = $parameter; 16091da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16101da177e4SLinus Torvalds 16111da177e4SLinus Torvalds print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; 16121da177e4SLinus Torvalds } 16131da177e4SLinus Torvalds output_section_text(@_); 16141da177e4SLinus Torvalds} 16151da177e4SLinus Torvalds 16161da177e4SLinus Torvalds#output sections in text 16171da177e4SLinus Torvaldssub output_section_text(%) { 16181da177e4SLinus Torvalds my %args = %{$_[0]}; 16191da177e4SLinus Torvalds my $section; 16201da177e4SLinus Torvalds 16211da177e4SLinus Torvalds print "\n"; 16221da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16231da177e4SLinus Torvalds print "$section:\n\n"; 16241da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16251da177e4SLinus Torvalds } 16261da177e4SLinus Torvalds print "\n\n"; 16271da177e4SLinus Torvalds} 16281da177e4SLinus Torvalds 16291da177e4SLinus Torvalds# output enum in text 16301da177e4SLinus Torvaldssub output_enum_text(%) { 16311da177e4SLinus Torvalds my %args = %{$_[0]}; 16321da177e4SLinus Torvalds my ($parameter); 16331da177e4SLinus Torvalds my $count; 16341da177e4SLinus Torvalds print "Enum:\n\n"; 16351da177e4SLinus Torvalds 16361d7e1d45SRandy.Dunlap print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; 16371da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 16381da177e4SLinus Torvalds $count = 0; 16391da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16401da177e4SLinus Torvalds print "\t$parameter"; 16411da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 16421da177e4SLinus Torvalds $count++; 16431da177e4SLinus Torvalds print ","; 16441da177e4SLinus Torvalds } 16451da177e4SLinus Torvalds print "\n"; 16461da177e4SLinus Torvalds } 16471da177e4SLinus Torvalds print "};\n\n"; 16481da177e4SLinus Torvalds 16491da177e4SLinus Torvalds print "Constants:\n\n"; 16501da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16511da177e4SLinus Torvalds print "$parameter\n\t"; 16521da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter} . "\n"; 16531da177e4SLinus Torvalds } 16541da177e4SLinus Torvalds 16551da177e4SLinus Torvalds output_section_text(@_); 16561da177e4SLinus Torvalds} 16571da177e4SLinus Torvalds 16581da177e4SLinus Torvalds# output typedef in text 16591da177e4SLinus Torvaldssub output_typedef_text(%) { 16601da177e4SLinus Torvalds my %args = %{$_[0]}; 16611da177e4SLinus Torvalds my ($parameter); 16621da177e4SLinus Torvalds my $count; 16631da177e4SLinus Torvalds print "Typedef:\n\n"; 16641da177e4SLinus Torvalds 16651d7e1d45SRandy.Dunlap print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; 16661da177e4SLinus Torvalds output_section_text(@_); 16671da177e4SLinus Torvalds} 16681da177e4SLinus Torvalds 16691da177e4SLinus Torvalds# output struct as text 16701da177e4SLinus Torvaldssub output_struct_text(%) { 16711da177e4SLinus Torvalds my %args = %{$_[0]}; 16721da177e4SLinus Torvalds my ($parameter); 16731da177e4SLinus Torvalds 16741d7e1d45SRandy.Dunlap print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; 16751da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 16761da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16771da177e4SLinus Torvalds if ($parameter =~ /^#/) { 16781da177e4SLinus Torvalds print "$parameter\n"; 16791da177e4SLinus Torvalds next; 16801da177e4SLinus Torvalds } 16811da177e4SLinus Torvalds 16821da177e4SLinus Torvalds my $parameter_name = $parameter; 16831da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16841da177e4SLinus Torvalds 16851da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 16861da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 16871da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 16881da177e4SLinus Torvalds # pointer-to-function 16891da177e4SLinus Torvalds print "\t$1 $parameter) ($2);\n"; 16901da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 169151f5a0c8SRandy Dunlap # bitfield 16921da177e4SLinus Torvalds print "\t$1 $parameter$2;\n"; 16931da177e4SLinus Torvalds } else { 16941da177e4SLinus Torvalds print "\t" . $type . " " . $parameter . ";\n"; 16951da177e4SLinus Torvalds } 16961da177e4SLinus Torvalds } 16971da177e4SLinus Torvalds print "};\n\n"; 16981da177e4SLinus Torvalds 16991da177e4SLinus Torvalds print "Members:\n\n"; 17001da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 17011da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 17021da177e4SLinus Torvalds 17031da177e4SLinus Torvalds my $parameter_name = $parameter; 17041da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 17051da177e4SLinus Torvalds 17061da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 17071da177e4SLinus Torvalds print "$parameter\n\t"; 17081da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter_name} . "\n"; 17091da177e4SLinus Torvalds } 17101da177e4SLinus Torvalds print "\n"; 17111da177e4SLinus Torvalds output_section_text(@_); 17121da177e4SLinus Torvalds} 17131da177e4SLinus Torvalds 1714b112e0f7SJohannes Bergsub output_blockhead_text(%) { 17151da177e4SLinus Torvalds my %args = %{$_[0]}; 17161da177e4SLinus Torvalds my ($parameter, $section); 17171da177e4SLinus Torvalds 17181da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 17191da177e4SLinus Torvalds print " $section:\n"; 17201da177e4SLinus Torvalds print " -> "; 17211da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 17221da177e4SLinus Torvalds } 17231da177e4SLinus Torvalds} 17241da177e4SLinus Torvalds 1725*c0d1b6eeSJonathan Corbet## 1726*c0d1b6eeSJonathan Corbet# output in restructured text 1727*c0d1b6eeSJonathan Corbet# 1728*c0d1b6eeSJonathan Corbet 1729*c0d1b6eeSJonathan Corbet# 1730*c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 1731*c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 1732*c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 1733*c0d1b6eeSJonathan Corbet# 1734*c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 1735*c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1736*c0d1b6eeSJonathan Corbet my ($parameter, $section); 1737*c0d1b6eeSJonathan Corbet 1738*c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 1739*c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 1740*c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1741*c0d1b6eeSJonathan Corbet print "\n"; 1742*c0d1b6eeSJonathan Corbet } 1743*c0d1b6eeSJonathan Corbet} 1744*c0d1b6eeSJonathan Corbet 1745*c0d1b6eeSJonathan Corbetsub output_highlight_rst { 1746*c0d1b6eeSJonathan Corbet my $contents = join "\n",@_; 1747*c0d1b6eeSJonathan Corbet my $line; 1748*c0d1b6eeSJonathan Corbet 1749*c0d1b6eeSJonathan Corbet # undo the evil effects of xml_escape() earlier 1750*c0d1b6eeSJonathan Corbet $contents = xml_unescape($contents); 1751*c0d1b6eeSJonathan Corbet 1752*c0d1b6eeSJonathan Corbet eval $dohighlight; 1753*c0d1b6eeSJonathan Corbet die $@ if $@; 1754*c0d1b6eeSJonathan Corbet 1755*c0d1b6eeSJonathan Corbet foreach $line (split "\n", $contents) { 1756*c0d1b6eeSJonathan Corbet if ($line eq "") { 1757*c0d1b6eeSJonathan Corbet print $lineprefix, $blankline; 1758*c0d1b6eeSJonathan Corbet } else { 1759*c0d1b6eeSJonathan Corbet $line =~ s/\\\\\\/\&/g; 1760*c0d1b6eeSJonathan Corbet print $lineprefix, $line; 1761*c0d1b6eeSJonathan Corbet } 1762*c0d1b6eeSJonathan Corbet print "\n"; 1763*c0d1b6eeSJonathan Corbet } 1764*c0d1b6eeSJonathan Corbet} 1765*c0d1b6eeSJonathan Corbet 1766*c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 1767*c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1768*c0d1b6eeSJonathan Corbet my ($parameter, $section); 1769*c0d1b6eeSJonathan Corbet my $start; 1770*c0d1b6eeSJonathan Corbet 1771*c0d1b6eeSJonathan Corbet print ".. c:function:: "; 1772*c0d1b6eeSJonathan Corbet if ($args{'functiontype'} ne "") { 1773*c0d1b6eeSJonathan Corbet $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1774*c0d1b6eeSJonathan Corbet } else { 1775*c0d1b6eeSJonathan Corbet $start = $args{'function'} . " ("; 1776*c0d1b6eeSJonathan Corbet } 1777*c0d1b6eeSJonathan Corbet print $start; 1778*c0d1b6eeSJonathan Corbet 1779*c0d1b6eeSJonathan Corbet my $count = 0; 1780*c0d1b6eeSJonathan Corbet foreach my $parameter (@{$args{'parameterlist'}}) { 1781*c0d1b6eeSJonathan Corbet if ($count ne 0) { 1782*c0d1b6eeSJonathan Corbet print ", "; 1783*c0d1b6eeSJonathan Corbet } 1784*c0d1b6eeSJonathan Corbet $count++; 1785*c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1786*c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1787*c0d1b6eeSJonathan Corbet # pointer-to-function 1788*c0d1b6eeSJonathan Corbet print $1 . $parameter . ") (" . $2; 1789*c0d1b6eeSJonathan Corbet } else { 1790*c0d1b6eeSJonathan Corbet print $type . " " . $parameter; 1791*c0d1b6eeSJonathan Corbet } 1792*c0d1b6eeSJonathan Corbet } 1793*c0d1b6eeSJonathan Corbet print ")\n\n " . $args{'purpose'} . "\n\n"; 1794*c0d1b6eeSJonathan Corbet 1795*c0d1b6eeSJonathan Corbet print ":Parameters:\n\n"; 1796*c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1797*c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1798*c0d1b6eeSJonathan Corbet #$parameter_name =~ s/\[.*//; 1799*c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1800*c0d1b6eeSJonathan Corbet 1801*c0d1b6eeSJonathan Corbet if ($type ne "") { 1802*c0d1b6eeSJonathan Corbet print " ``$type $parameter``\n"; 1803*c0d1b6eeSJonathan Corbet } else { 1804*c0d1b6eeSJonathan Corbet print " ``$parameter``\n"; 1805*c0d1b6eeSJonathan Corbet } 1806*c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter_name} ne $undescribed) { 1807*c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1808*c0d1b6eeSJonathan Corbet $lineprefix = " "; 1809*c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1810*c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1811*c0d1b6eeSJonathan Corbet } else { 1812*c0d1b6eeSJonathan Corbet print "\n _undescribed_\n"; 1813*c0d1b6eeSJonathan Corbet } 1814*c0d1b6eeSJonathan Corbet print "\n"; 1815*c0d1b6eeSJonathan Corbet } 1816*c0d1b6eeSJonathan Corbet output_section_rst(@_); 1817*c0d1b6eeSJonathan Corbet} 1818*c0d1b6eeSJonathan Corbet 1819*c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 1820*c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1821*c0d1b6eeSJonathan Corbet my $section; 1822*c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1823*c0d1b6eeSJonathan Corbet $lineprefix = " "; 1824*c0d1b6eeSJonathan Corbet 1825*c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 1826*c0d1b6eeSJonathan Corbet print ":$section:\n\n"; 1827*c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1828*c0d1b6eeSJonathan Corbet print "\n"; 1829*c0d1b6eeSJonathan Corbet } 1830*c0d1b6eeSJonathan Corbet print "\n"; 1831*c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1832*c0d1b6eeSJonathan Corbet} 1833*c0d1b6eeSJonathan Corbet 1834*c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 1835*c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1836*c0d1b6eeSJonathan Corbet my ($parameter); 1837*c0d1b6eeSJonathan Corbet my $count; 1838*c0d1b6eeSJonathan Corbet 1839*c0d1b6eeSJonathan Corbet my $name = "enum " . $args{'enum'}; 1840*c0d1b6eeSJonathan Corbet print ".. _" . $name . ":\n\n"; 1841*c0d1b6eeSJonathan Corbet print "**$name**\n\n"; 1842*c0d1b6eeSJonathan Corbet print " " . $args{'purpose'} . "\n\n"; 1843*c0d1b6eeSJonathan Corbet 1844*c0d1b6eeSJonathan Corbet print "..\n\n:Constants:\n\n"; 1845*c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1846*c0d1b6eeSJonathan Corbet $lineprefix = " "; 1847*c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1848*c0d1b6eeSJonathan Corbet print " `$parameter`\n"; 1849*c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 1850*c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 1851*c0d1b6eeSJonathan Corbet } else { 1852*c0d1b6eeSJonathan Corbet print " undescribed\n"; 1853*c0d1b6eeSJonathan Corbet } 1854*c0d1b6eeSJonathan Corbet print "\n"; 1855*c0d1b6eeSJonathan Corbet } 1856*c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1857*c0d1b6eeSJonathan Corbet output_section_rst(@_); 1858*c0d1b6eeSJonathan Corbet} 1859*c0d1b6eeSJonathan Corbet 1860*c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 1861*c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1862*c0d1b6eeSJonathan Corbet my ($parameter); 1863*c0d1b6eeSJonathan Corbet my $count; 1864*c0d1b6eeSJonathan Corbet my $name = "typedef " . $args{'typedef'}; 1865*c0d1b6eeSJonathan Corbet 1866*c0d1b6eeSJonathan Corbet print "**$name**\n\n"; 1867*c0d1b6eeSJonathan Corbet print $args{'purpose'} . "\n\n"; 1868*c0d1b6eeSJonathan Corbet 1869*c0d1b6eeSJonathan Corbet output_section_rst(@_); 1870*c0d1b6eeSJonathan Corbet} 1871*c0d1b6eeSJonathan Corbet 1872*c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 1873*c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1874*c0d1b6eeSJonathan Corbet my ($parameter); 1875*c0d1b6eeSJonathan Corbet my $name = $args{'type'} . " " . $args{'struct'}; 1876*c0d1b6eeSJonathan Corbet 1877*c0d1b6eeSJonathan Corbet print ".. _" . $name . ":\n\n"; 1878*c0d1b6eeSJonathan Corbet print "**$name**\n\n"; 1879*c0d1b6eeSJonathan Corbet print " " . $args{'purpose'} . "\n\n"; 1880*c0d1b6eeSJonathan Corbet 1881*c0d1b6eeSJonathan Corbet print ":Definition:\n\n"; 1882*c0d1b6eeSJonathan Corbet print " ::\n\n"; 1883*c0d1b6eeSJonathan Corbet print " " . $args{'type'} . " " . $args{'struct'} . " {\n"; 1884*c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1885*c0d1b6eeSJonathan Corbet if ($parameter =~ /^#/) { 1886*c0d1b6eeSJonathan Corbet print " " . "$parameter\n"; 1887*c0d1b6eeSJonathan Corbet next; 1888*c0d1b6eeSJonathan Corbet } 1889*c0d1b6eeSJonathan Corbet 1890*c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1891*c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 1892*c0d1b6eeSJonathan Corbet 1893*c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1894*c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1895*c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 1896*c0d1b6eeSJonathan Corbet # pointer-to-function 1897*c0d1b6eeSJonathan Corbet print " $1 $parameter) ($2);\n"; 1898*c0d1b6eeSJonathan Corbet } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 1899*c0d1b6eeSJonathan Corbet # bitfield 1900*c0d1b6eeSJonathan Corbet print " $1 $parameter$2;\n"; 1901*c0d1b6eeSJonathan Corbet } else { 1902*c0d1b6eeSJonathan Corbet print " " . $type . " " . $parameter . ";\n"; 1903*c0d1b6eeSJonathan Corbet } 1904*c0d1b6eeSJonathan Corbet } 1905*c0d1b6eeSJonathan Corbet print " };\n\n"; 1906*c0d1b6eeSJonathan Corbet 1907*c0d1b6eeSJonathan Corbet print ":Members:\n\n"; 1908*c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1909*c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 1910*c0d1b6eeSJonathan Corbet 1911*c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1912*c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 1913*c0d1b6eeSJonathan Corbet 1914*c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1915*c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1916*c0d1b6eeSJonathan Corbet print " `$type $parameter`" . "\n"; 1917*c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1918*c0d1b6eeSJonathan Corbet $lineprefix = " "; 1919*c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1920*c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1921*c0d1b6eeSJonathan Corbet print "\n"; 1922*c0d1b6eeSJonathan Corbet } 1923*c0d1b6eeSJonathan Corbet print "\n"; 1924*c0d1b6eeSJonathan Corbet output_section_rst(@_); 1925*c0d1b6eeSJonathan Corbet} 1926*c0d1b6eeSJonathan Corbet 1927*c0d1b6eeSJonathan Corbet 1928eda603f6SJohannes Berg## list mode output functions 1929eda603f6SJohannes Berg 1930eda603f6SJohannes Bergsub output_function_list(%) { 1931eda603f6SJohannes Berg my %args = %{$_[0]}; 1932eda603f6SJohannes Berg 1933eda603f6SJohannes Berg print $args{'function'} . "\n"; 1934eda603f6SJohannes Berg} 1935eda603f6SJohannes Berg 1936eda603f6SJohannes Berg# output enum in list 1937eda603f6SJohannes Bergsub output_enum_list(%) { 1938eda603f6SJohannes Berg my %args = %{$_[0]}; 1939eda603f6SJohannes Berg print $args{'enum'} . "\n"; 1940eda603f6SJohannes Berg} 1941eda603f6SJohannes Berg 1942eda603f6SJohannes Berg# output typedef in list 1943eda603f6SJohannes Bergsub output_typedef_list(%) { 1944eda603f6SJohannes Berg my %args = %{$_[0]}; 1945eda603f6SJohannes Berg print $args{'typedef'} . "\n"; 1946eda603f6SJohannes Berg} 1947eda603f6SJohannes Berg 1948eda603f6SJohannes Berg# output struct as list 1949eda603f6SJohannes Bergsub output_struct_list(%) { 1950eda603f6SJohannes Berg my %args = %{$_[0]}; 1951eda603f6SJohannes Berg 1952eda603f6SJohannes Berg print $args{'struct'} . "\n"; 1953eda603f6SJohannes Berg} 1954eda603f6SJohannes Berg 1955eda603f6SJohannes Bergsub output_blockhead_list(%) { 1956eda603f6SJohannes Berg my %args = %{$_[0]}; 1957eda603f6SJohannes Berg my ($parameter, $section); 1958eda603f6SJohannes Berg 1959eda603f6SJohannes Berg foreach $section (@{$args{'sectionlist'}}) { 1960eda603f6SJohannes Berg print "DOC: $section\n"; 1961eda603f6SJohannes Berg } 1962eda603f6SJohannes Berg} 1963eda603f6SJohannes Berg 19641da177e4SLinus Torvalds## 196527205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 196627205744SRandy Dunlap# calls the generated, variable output_ function name based on 196727205744SRandy Dunlap# functype and output_mode 19681da177e4SLinus Torvaldssub output_declaration { 19691da177e4SLinus Torvalds no strict 'refs'; 19701da177e4SLinus Torvalds my $name = shift; 19711da177e4SLinus Torvalds my $functype = shift; 19721da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 19731da177e4SLinus Torvalds if (($function_only==0) || 19741da177e4SLinus Torvalds ( $function_only == 1 && defined($function_table{$name})) || 197523aebb3cSDanilo Cesar Lemes de Paula ( $function_only == 2 && !($functype eq "function" && defined($function_table{$name})))) 19761da177e4SLinus Torvalds { 19771da177e4SLinus Torvalds &$func(@_); 19781da177e4SLinus Torvalds $section_counter++; 19791da177e4SLinus Torvalds } 19801da177e4SLinus Torvalds} 19811da177e4SLinus Torvalds 19821da177e4SLinus Torvalds## 198327205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 1984b112e0f7SJohannes Bergsub output_blockhead { 19851da177e4SLinus Torvalds no strict 'refs'; 1986b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 19871da177e4SLinus Torvalds &$func(@_); 19881da177e4SLinus Torvalds $section_counter++; 19891da177e4SLinus Torvalds} 19901da177e4SLinus Torvalds 19911da177e4SLinus Torvalds## 19921da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 19931da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 19941da177e4SLinus Torvaldssub dump_declaration($$) { 19951da177e4SLinus Torvalds no strict 'refs'; 19961da177e4SLinus Torvalds my ($prototype, $file) = @_; 19971da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 19981da177e4SLinus Torvalds &$func(@_); 19991da177e4SLinus Torvalds} 20001da177e4SLinus Torvalds 20011da177e4SLinus Torvaldssub dump_union($$) { 20021da177e4SLinus Torvalds dump_struct(@_); 20031da177e4SLinus Torvalds} 20041da177e4SLinus Torvalds 20051da177e4SLinus Torvaldssub dump_struct($$) { 20061da177e4SLinus Torvalds my $x = shift; 20071da177e4SLinus Torvalds my $file = shift; 2008a1d94aa5SRandy Dunlap my $nested; 20091da177e4SLinus Torvalds 20101da177e4SLinus Torvalds if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 201152dc5aecSRandy Dunlap #my $decl_type = $1; 20121da177e4SLinus Torvalds $declaration_name = $2; 20131da177e4SLinus Torvalds my $members = $3; 20141da177e4SLinus Torvalds 20151da177e4SLinus Torvalds # ignore embedded structs or unions 2016a1d94aa5SRandy Dunlap $members =~ s/({.*})//g; 2017a1d94aa5SRandy Dunlap $nested = $1; 20181da177e4SLinus Torvalds 2019aeec46b9SMartin Waitz # ignore members marked private: 20200d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 20210d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 2022aeec46b9SMartin Waitz # strip comments: 2023aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 2024a1d94aa5SRandy Dunlap $nested =~ s/\/\*.*?\*\///gos; 2025d960eea9SRandy Dunlap # strip kmemcheck_bitfield_{begin,end}.*; 2026d960eea9SRandy Dunlap $members =~ s/kmemcheck_bitfield_.*?;//gos; 2027ef5da59fSRandy Dunlap # strip attributes 2028f0074929SJonathan Corbet $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 20297b990789SJohannes Berg $members =~ s/__aligned\s*\([^;]*\)//gos; 2030f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; 2031b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 2032b22b5a9eSConchúr Navid $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 2033aeec46b9SMartin Waitz 20341da177e4SLinus Torvalds create_parameterlist($members, ';', $file); 2035a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); 20361da177e4SLinus Torvalds 20371da177e4SLinus Torvalds output_declaration($declaration_name, 20381da177e4SLinus Torvalds 'struct', 20391da177e4SLinus Torvalds {'struct' => $declaration_name, 20401da177e4SLinus Torvalds 'module' => $modulename, 20411da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 20421da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 20431da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 20441da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 20451da177e4SLinus Torvalds 'sections' => \%sections, 20461da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 20471da177e4SLinus Torvalds 'type' => $decl_type 20481da177e4SLinus Torvalds }); 20491da177e4SLinus Torvalds } 20501da177e4SLinus Torvalds else { 2051d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 20521da177e4SLinus Torvalds ++$errors; 20531da177e4SLinus Torvalds } 20541da177e4SLinus Torvalds} 20551da177e4SLinus Torvalds 20561da177e4SLinus Torvaldssub dump_enum($$) { 20571da177e4SLinus Torvalds my $x = shift; 20581da177e4SLinus Torvalds my $file = shift; 20591da177e4SLinus Torvalds 2060aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 20614468e21eSConchúr Navid # strip #define macros inside enums 20624468e21eSConchúr Navid $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 2063b6d676dbSRandy Dunlap 20641da177e4SLinus Torvalds if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 20651da177e4SLinus Torvalds $declaration_name = $1; 20661da177e4SLinus Torvalds my $members = $2; 20671da177e4SLinus Torvalds 20681da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 20691da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 20701da177e4SLinus Torvalds push @parameterlist, $arg; 20711da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 20721da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 2073d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Enum value '$arg' ". 20741da177e4SLinus Torvalds "not described in enum '$declaration_name'\n"; 20751da177e4SLinus Torvalds } 20761da177e4SLinus Torvalds 20771da177e4SLinus Torvalds } 20781da177e4SLinus Torvalds 20791da177e4SLinus Torvalds output_declaration($declaration_name, 20801da177e4SLinus Torvalds 'enum', 20811da177e4SLinus Torvalds {'enum' => $declaration_name, 20821da177e4SLinus Torvalds 'module' => $modulename, 20831da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 20841da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 20851da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 20861da177e4SLinus Torvalds 'sections' => \%sections, 20871da177e4SLinus Torvalds 'purpose' => $declaration_purpose 20881da177e4SLinus Torvalds }); 20891da177e4SLinus Torvalds } 20901da177e4SLinus Torvalds else { 2091d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 20921da177e4SLinus Torvalds ++$errors; 20931da177e4SLinus Torvalds } 20941da177e4SLinus Torvalds} 20951da177e4SLinus Torvalds 20961da177e4SLinus Torvaldssub dump_typedef($$) { 20971da177e4SLinus Torvalds my $x = shift; 20981da177e4SLinus Torvalds my $file = shift; 20991da177e4SLinus Torvalds 2100aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 210183766452SMauro Carvalho Chehab 210283766452SMauro Carvalho Chehab # Parse function prototypes 210383766452SMauro Carvalho Chehab if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/) { 210483766452SMauro Carvalho Chehab # Function typedefs 210583766452SMauro Carvalho Chehab $return_type = $1; 210683766452SMauro Carvalho Chehab $declaration_name = $2; 210783766452SMauro Carvalho Chehab my $args = $3; 210883766452SMauro Carvalho Chehab 210983766452SMauro Carvalho Chehab create_parameterlist($args, ',', $file); 211083766452SMauro Carvalho Chehab 211183766452SMauro Carvalho Chehab output_declaration($declaration_name, 211283766452SMauro Carvalho Chehab 'function', 211383766452SMauro Carvalho Chehab {'function' => $declaration_name, 211483766452SMauro Carvalho Chehab 'module' => $modulename, 211583766452SMauro Carvalho Chehab 'functiontype' => $return_type, 211683766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 211783766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 211883766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 211983766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 212083766452SMauro Carvalho Chehab 'sections' => \%sections, 212183766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 212283766452SMauro Carvalho Chehab }); 212383766452SMauro Carvalho Chehab return; 212483766452SMauro Carvalho Chehab } 212583766452SMauro Carvalho Chehab 21261da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 21271da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 21281da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 21291da177e4SLinus Torvalds } 21301da177e4SLinus Torvalds 21311da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 21321da177e4SLinus Torvalds $declaration_name = $1; 21331da177e4SLinus Torvalds 21341da177e4SLinus Torvalds output_declaration($declaration_name, 21351da177e4SLinus Torvalds 'typedef', 21361da177e4SLinus Torvalds {'typedef' => $declaration_name, 21371da177e4SLinus Torvalds 'module' => $modulename, 21381da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 21391da177e4SLinus Torvalds 'sections' => \%sections, 21401da177e4SLinus Torvalds 'purpose' => $declaration_purpose 21411da177e4SLinus Torvalds }); 21421da177e4SLinus Torvalds } 21431da177e4SLinus Torvalds else { 2144d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 21451da177e4SLinus Torvalds ++$errors; 21461da177e4SLinus Torvalds } 21471da177e4SLinus Torvalds} 21481da177e4SLinus Torvalds 2149a1d94aa5SRandy Dunlapsub save_struct_actual($) { 2150a1d94aa5SRandy Dunlap my $actual = shift; 2151a1d94aa5SRandy Dunlap 2152a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 2153a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 2154a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 2155a1d94aa5SRandy Dunlap} 2156a1d94aa5SRandy Dunlap 21571da177e4SLinus Torvaldssub create_parameterlist($$$) { 21581da177e4SLinus Torvalds my $args = shift; 21591da177e4SLinus Torvalds my $splitter = shift; 21601da177e4SLinus Torvalds my $file = shift; 21611da177e4SLinus Torvalds my $type; 21621da177e4SLinus Torvalds my $param; 21631da177e4SLinus Torvalds 2164a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 21651da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 21661da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 21671da177e4SLinus Torvalds } 21681da177e4SLinus Torvalds 21691da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 21701da177e4SLinus Torvalds # strip comments 21711da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 21721da177e4SLinus Torvalds # strip leading/trailing spaces 21731da177e4SLinus Torvalds $arg =~ s/^\s*//; 21741da177e4SLinus Torvalds $arg =~ s/\s*$//; 21751da177e4SLinus Torvalds $arg =~ s/\s+/ /; 21761da177e4SLinus Torvalds 21771da177e4SLinus Torvalds if ($arg =~ /^#/) { 21781da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 21791da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 21801da177e4SLinus Torvalds # output_* subs. 21811da177e4SLinus Torvalds push_parameter($arg, "", $file); 218200d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 21831da177e4SLinus Torvalds # pointer-to-function 21841da177e4SLinus Torvalds $arg =~ tr/#/,/; 218500d62961SRichard Kennedy $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 21861da177e4SLinus Torvalds $param = $1; 21871da177e4SLinus Torvalds $type = $arg; 218800d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 2189a1d94aa5SRandy Dunlap save_struct_actual($param); 21901da177e4SLinus Torvalds push_parameter($param, $type, $file); 2191aeec46b9SMartin Waitz } elsif ($arg) { 21921da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 21931da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 21941da177e4SLinus Torvalds 21951da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 21961da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 21971da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 21981da177e4SLinus Torvalds } 2199884f2810SBorislav Petkov 2200884f2810SBorislav Petkov my @first_arg; 2201884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 2202884f2810SBorislav Petkov shift @args; 2203884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 2204884f2810SBorislav Petkov push(@first_arg, $2); 2205884f2810SBorislav Petkov } else { 2206884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 2207884f2810SBorislav Petkov } 2208884f2810SBorislav Petkov 22091da177e4SLinus Torvalds unshift(@args, pop @first_arg); 22101da177e4SLinus Torvalds $type = join " ", @first_arg; 22111da177e4SLinus Torvalds 22121da177e4SLinus Torvalds foreach $param (@args) { 22131da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 2214a1d94aa5SRandy Dunlap save_struct_actual($2); 22151da177e4SLinus Torvalds push_parameter($2, "$type $1", $file); 22161da177e4SLinus Torvalds } 22171da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 22187b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 2219a1d94aa5SRandy Dunlap save_struct_actual($1); 22201da177e4SLinus Torvalds push_parameter($1, "$type:$2", $file) 22211da177e4SLinus Torvalds } 22227b97887eSRandy Dunlap } 22231da177e4SLinus Torvalds else { 2224a1d94aa5SRandy Dunlap save_struct_actual($param); 22251da177e4SLinus Torvalds push_parameter($param, $type, $file); 22261da177e4SLinus Torvalds } 22271da177e4SLinus Torvalds } 22281da177e4SLinus Torvalds } 22291da177e4SLinus Torvalds } 22301da177e4SLinus Torvalds} 22311da177e4SLinus Torvalds 22321da177e4SLinus Torvaldssub push_parameter($$$) { 22331da177e4SLinus Torvalds my $param = shift; 22341da177e4SLinus Torvalds my $type = shift; 22351da177e4SLinus Torvalds my $file = shift; 22361da177e4SLinus Torvalds 22375f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 22385f8c7c98SRandy Dunlap ($param eq "}")) { 22395f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 22405f8c7c98SRandy Dunlap } 22415f8c7c98SRandy Dunlap 22425f8c7c98SRandy Dunlap $anon_struct_union = 0; 22431da177e4SLinus Torvalds my $param_name = $param; 22441da177e4SLinus Torvalds $param_name =~ s/\[.*//; 22451da177e4SLinus Torvalds 2246a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 22471da177e4SLinus Torvalds { 2248ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 2249a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 22501da177e4SLinus Torvalds } 2251ced69090SRandy Dunlap } 22521da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 22531da177e4SLinus Torvalds { 22541da177e4SLinus Torvalds $param="void"; 22551da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 22561da177e4SLinus Torvalds } 2257134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 2258134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 2259134fe01bSRandy Dunlap { 2260134fe01bSRandy Dunlap $type = $param; 2261134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 2262134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 22635f8c7c98SRandy Dunlap $anon_struct_union = 1; 2264134fe01bSRandy Dunlap } 2265134fe01bSRandy Dunlap 2266a6d3fe77SMartin Waitz # warn if parameter has no description 2267134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 2268134fe01bSRandy Dunlap # but inline preprocessor statements); 2269134fe01bSRandy Dunlap # also ignore unnamed structs/unions; 22705f8c7c98SRandy Dunlap if (!$anon_struct_union) { 2271a6d3fe77SMartin Waitz if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { 2272a6d3fe77SMartin Waitz 22731da177e4SLinus Torvalds $parameterdescs{$param_name} = $undescribed; 22741da177e4SLinus Torvalds 22751da177e4SLinus Torvalds if (($type eq 'function') || ($type eq 'enum')) { 2276d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Function parameter ". 22771da177e4SLinus Torvalds "or member '$param' not " . 22781da177e4SLinus Torvalds "described in '$declaration_name'\n"; 22791da177e4SLinus Torvalds } 2280d40e1e65SBart Van Assche print STDERR "${file}:$.: warning:" . 22811da177e4SLinus Torvalds " No description found for parameter '$param'\n"; 22821da177e4SLinus Torvalds ++$warnings; 22831da177e4SLinus Torvalds } 2284134fe01bSRandy Dunlap } 22851da177e4SLinus Torvalds 22862b35f4d9SRandy Dunlap $param = xml_escape($param); 22872b35f4d9SRandy Dunlap 228825985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 2289e34e7dbbSRandy Dunlap # on @parameterlist; 2290e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 2291e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 2292e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 2293e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 2294e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 2295e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 2296e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 22971da177e4SLinus Torvalds push @parameterlist, $param; 22981da177e4SLinus Torvalds $parametertypes{$param} = $type; 22991da177e4SLinus Torvalds} 23001da177e4SLinus Torvalds 2301a1d94aa5SRandy Dunlapsub check_sections($$$$$$) { 2302a1d94aa5SRandy Dunlap my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; 2303a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 2304a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 2305a1d94aa5SRandy Dunlap my $err; 2306a1d94aa5SRandy Dunlap my ($px, $sx); 2307a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 2308a1d94aa5SRandy Dunlap 2309a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 2310a1d94aa5SRandy Dunlap $err = 1; 2311a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 2312a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 2313a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 23141f3a6688SJohannes Berg $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 2315e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 2316e34e7dbbSRandy Dunlap # however, the original param string may contain 2317e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 2318e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 2319e34e7dbbSRandy Dunlap # parameter list is split at spaces; 2320e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 2321e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 2322e34e7dbbSRandy Dunlap 2323a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 2324a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 2325a1d94aa5SRandy Dunlap $err = 0; 2326a1d94aa5SRandy Dunlap last; 2327a1d94aa5SRandy Dunlap } 2328a1d94aa5SRandy Dunlap } 2329a1d94aa5SRandy Dunlap if ($err) { 2330a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 2331d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2332a1d94aa5SRandy Dunlap "Excess function parameter " . 2333a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2334a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2335a1d94aa5SRandy Dunlap ++$warnings; 2336a1d94aa5SRandy Dunlap } else { 2337a1d94aa5SRandy Dunlap if ($nested !~ m/\Q$sects[$sx]\E/) { 2338d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2339a1d94aa5SRandy Dunlap "Excess struct/union/enum/typedef member " . 2340a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2341a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2342a1d94aa5SRandy Dunlap ++$warnings; 2343a1d94aa5SRandy Dunlap } 2344a1d94aa5SRandy Dunlap } 2345a1d94aa5SRandy Dunlap } 2346a1d94aa5SRandy Dunlap } 2347a1d94aa5SRandy Dunlap} 2348a1d94aa5SRandy Dunlap 23491da177e4SLinus Torvalds## 23504092bac7SYacine Belkadi# Checks the section describing the return value of a function. 23514092bac7SYacine Belkadisub check_return_section { 23524092bac7SYacine Belkadi my $file = shift; 23534092bac7SYacine Belkadi my $declaration_name = shift; 23544092bac7SYacine Belkadi my $return_type = shift; 23554092bac7SYacine Belkadi 23564092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 23574092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 23584092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 23594092bac7SYacine Belkadi return; 23604092bac7SYacine Belkadi } 23614092bac7SYacine Belkadi 23624092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 23634092bac7SYacine Belkadi $sections{$section_return} eq "") { 2364d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 23654092bac7SYacine Belkadi "No description found for return value of " . 23664092bac7SYacine Belkadi "'$declaration_name'\n"; 23674092bac7SYacine Belkadi ++$warnings; 23684092bac7SYacine Belkadi } 23694092bac7SYacine Belkadi} 23704092bac7SYacine Belkadi 23714092bac7SYacine Belkadi## 23721da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 23731da177e4SLinus Torvalds# processed and spits out all the details stored in the global 23741da177e4SLinus Torvalds# arrays/hashes. 23751da177e4SLinus Torvaldssub dump_function($$) { 23761da177e4SLinus Torvalds my $prototype = shift; 23771da177e4SLinus Torvalds my $file = shift; 2378cbb4d3e6SHoria Geanta my $noret = 0; 23791da177e4SLinus Torvalds 23801da177e4SLinus Torvalds $prototype =~ s/^static +//; 23811da177e4SLinus Torvalds $prototype =~ s/^extern +//; 23824dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 23831da177e4SLinus Torvalds $prototype =~ s/^inline +//; 23841da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 238532e79401SRandy Dunlap $prototype =~ s/^__inline +//; 238632e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 238732e79401SRandy Dunlap $prototype =~ s/^noinline +//; 238874fc5c65SRandy Dunlap $prototype =~ s/__init +//; 238920072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 2390270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 239170c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 23920df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 2393cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 2394328d2440SRandy Dunlap $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; 23951da177e4SLinus Torvalds 23961da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 23971da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 23981da177e4SLinus Torvalds # 2. Function name 23991da177e4SLinus Torvalds # 3. Function parameters. 24001da177e4SLinus Torvalds # 24011da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 24021da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 24031da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 24041da177e4SLinus Torvalds # so on. 24051da177e4SLinus Torvalds # 24061da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 24071da177e4SLinus Torvalds # the following functions' documentation still comes out right: 24081da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 24091da177e4SLinus Torvalds # - atomic_set (macro) 24109598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 24111da177e4SLinus Torvalds 2412cbb4d3e6SHoria Geanta if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 2413cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 2414cbb4d3e6SHoria Geanta # list. 2415cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 2416cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 2417cbb4d3e6SHoria Geanta $return_type = $1; 2418cbb4d3e6SHoria Geanta $declaration_name = $2; 2419cbb4d3e6SHoria Geanta $noret = 1; 2420cbb4d3e6SHoria Geanta } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24211da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24221da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24231da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 242494b3e03cSRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24251da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24261da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 24271da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24281da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24291da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24301da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24311da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24321da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24339598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 24349598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2435412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2436412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 24371da177e4SLinus Torvalds $return_type = $1; 24381da177e4SLinus Torvalds $declaration_name = $2; 24391da177e4SLinus Torvalds my $args = $3; 24401da177e4SLinus Torvalds 24411da177e4SLinus Torvalds create_parameterlist($args, ',', $file); 24421da177e4SLinus Torvalds } else { 2443d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 24441da177e4SLinus Torvalds return; 24451da177e4SLinus Torvalds } 24461da177e4SLinus Torvalds 2447a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 2448a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); 2449a1d94aa5SRandy Dunlap 24504092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 24514092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 24524092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 24534092bac7SYacine Belkadi # verbose mode. 24544092bac7SYacine Belkadi # TODO: always perform the check. 2455cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 24564092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 24574092bac7SYacine Belkadi } 24584092bac7SYacine Belkadi 24591da177e4SLinus Torvalds output_declaration($declaration_name, 24601da177e4SLinus Torvalds 'function', 24611da177e4SLinus Torvalds {'function' => $declaration_name, 24621da177e4SLinus Torvalds 'module' => $modulename, 24631da177e4SLinus Torvalds 'functiontype' => $return_type, 24641da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 24651da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 24661da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 24671da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 24681da177e4SLinus Torvalds 'sections' => \%sections, 24691da177e4SLinus Torvalds 'purpose' => $declaration_purpose 24701da177e4SLinus Torvalds }); 24711da177e4SLinus Torvalds} 24721da177e4SLinus Torvalds 24731da177e4SLinus Torvaldssub reset_state { 24741da177e4SLinus Torvalds $function = ""; 24751da177e4SLinus Torvalds %constants = (); 24761da177e4SLinus Torvalds %parameterdescs = (); 24771da177e4SLinus Torvalds %parametertypes = (); 24781da177e4SLinus Torvalds @parameterlist = (); 24791da177e4SLinus Torvalds %sections = (); 24801da177e4SLinus Torvalds @sectionlist = (); 2481a1d94aa5SRandy Dunlap $sectcheck = ""; 2482a1d94aa5SRandy Dunlap $struct_actual = ""; 24831da177e4SLinus Torvalds $prototype = ""; 24841da177e4SLinus Torvalds 24851da177e4SLinus Torvalds $state = 0; 2486a4c6ebedSDanilo Cesar Lemes de Paula $split_doc_state = 0; 24871da177e4SLinus Torvalds} 24881da177e4SLinus Torvalds 248956afb0f8SJason Baronsub tracepoint_munge($) { 249056afb0f8SJason Baron my $file = shift; 249156afb0f8SJason Baron my $tracepointname = 0; 249256afb0f8SJason Baron my $tracepointargs = 0; 249356afb0f8SJason Baron 249456afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 249556afb0f8SJason Baron $tracepointname = $1; 249656afb0f8SJason Baron } 24973a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 24983a9089fdSJason Baron $tracepointname = $1; 24993a9089fdSJason Baron } 25003a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 25013a9089fdSJason Baron $tracepointname = $2; 25023a9089fdSJason Baron } 25033a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 250456afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 250556afb0f8SJason Baron $tracepointargs = $1; 250656afb0f8SJason Baron } 250756afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 2508d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 250956afb0f8SJason Baron "$prototype\n"; 251056afb0f8SJason Baron } else { 251156afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 251256afb0f8SJason Baron } 251356afb0f8SJason Baron} 251456afb0f8SJason Baron 2515b4870bc5SRandy Dunlapsub syscall_munge() { 2516b4870bc5SRandy Dunlap my $void = 0; 2517b4870bc5SRandy Dunlap 2518b4870bc5SRandy Dunlap $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs 2519b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 2520b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 2521b4870bc5SRandy Dunlap $void = 1; 2522b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 2523b4870bc5SRandy Dunlap } 2524b4870bc5SRandy Dunlap 2525b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 2526b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 2527b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 2528b4870bc5SRandy Dunlap } elsif ($void) { 2529b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 2530b4870bc5SRandy Dunlap } 2531b4870bc5SRandy Dunlap 2532b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 2533b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 2534b4870bc5SRandy Dunlap my $count = 0; 2535b4870bc5SRandy Dunlap my $len = length($prototype); 2536b4870bc5SRandy Dunlap if ($void) { 2537b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 2538b4870bc5SRandy Dunlap } 2539b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 2540b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 2541b4870bc5SRandy Dunlap $count++; 2542b4870bc5SRandy Dunlap if ($count % 2 == 1) { 2543b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 2544b4870bc5SRandy Dunlap } 2545b4870bc5SRandy Dunlap } 2546b4870bc5SRandy Dunlap } 2547b4870bc5SRandy Dunlap} 2548b4870bc5SRandy Dunlap 25491da177e4SLinus Torvaldssub process_state3_function($$) { 25501da177e4SLinus Torvalds my $x = shift; 25511da177e4SLinus Torvalds my $file = shift; 25521da177e4SLinus Torvalds 255351f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 255451f5a0c8SRandy Dunlap 2555890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 25561da177e4SLinus Torvalds # do nothing 25571da177e4SLinus Torvalds } 25581da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 25591da177e4SLinus Torvalds $prototype .= $1; 25601da177e4SLinus Torvalds } 2561b4870bc5SRandy Dunlap 2562890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 25631da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 25641da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 25651da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 2566b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 2567b4870bc5SRandy Dunlap syscall_munge(); 2568b4870bc5SRandy Dunlap } 25693a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 25703a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 25713a9089fdSJason Baron { 257256afb0f8SJason Baron tracepoint_munge($file); 257356afb0f8SJason Baron } 25741da177e4SLinus Torvalds dump_function($prototype, $file); 25751da177e4SLinus Torvalds reset_state(); 25761da177e4SLinus Torvalds } 25771da177e4SLinus Torvalds} 25781da177e4SLinus Torvalds 25791da177e4SLinus Torvaldssub process_state3_type($$) { 25801da177e4SLinus Torvalds my $x = shift; 25811da177e4SLinus Torvalds my $file = shift; 25821da177e4SLinus Torvalds 25831da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 25841da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 25851da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 258651f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 258751f5a0c8SRandy Dunlap 25881da177e4SLinus Torvalds if ($x =~ /^#/) { 25891da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 25901da177e4SLinus Torvalds $x .= ";"; 25911da177e4SLinus Torvalds } 25921da177e4SLinus Torvalds 25931da177e4SLinus Torvalds while (1) { 25941da177e4SLinus Torvalds if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 25951da177e4SLinus Torvalds $prototype .= $1 . $2; 25961da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 25971da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 25981da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 25991da177e4SLinus Torvalds dump_declaration($prototype, $file); 26001da177e4SLinus Torvalds reset_state(); 26011da177e4SLinus Torvalds last; 26021da177e4SLinus Torvalds } 26031da177e4SLinus Torvalds $x = $3; 26041da177e4SLinus Torvalds } else { 26051da177e4SLinus Torvalds $prototype .= $x; 26061da177e4SLinus Torvalds last; 26071da177e4SLinus Torvalds } 26081da177e4SLinus Torvalds } 26091da177e4SLinus Torvalds} 26101da177e4SLinus Torvalds 26116b5b55f6SRandy Dunlap# xml_escape: replace <, >, and & in the text stream; 26126b5b55f6SRandy Dunlap# 26136b5b55f6SRandy Dunlap# however, formatting controls that are generated internally/locally in the 26146b5b55f6SRandy Dunlap# kernel-doc script are not escaped here; instead, they begin life like 26156b5b55f6SRandy Dunlap# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings 26166b5b55f6SRandy Dunlap# are converted to their mnemonic-expected output, without the 4 * '\' & ':', 26176b5b55f6SRandy Dunlap# just before actual output; (this is done by local_unescape()) 26181da177e4SLinus Torvaldssub xml_escape($) { 26191da177e4SLinus Torvalds my $text = shift; 2620ecfb251aSRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 2621ecfb251aSRandy Dunlap return $text; 2622ecfb251aSRandy Dunlap } 26231da177e4SLinus Torvalds $text =~ s/\&/\\\\\\amp;/g; 26241da177e4SLinus Torvalds $text =~ s/\</\\\\\\lt;/g; 26251da177e4SLinus Torvalds $text =~ s/\>/\\\\\\gt;/g; 26261da177e4SLinus Torvalds return $text; 26271da177e4SLinus Torvalds} 26281da177e4SLinus Torvalds 2629*c0d1b6eeSJonathan Corbet# xml_unescape: reverse the effects of xml_escape 2630*c0d1b6eeSJonathan Corbetsub xml_unescape($) { 2631*c0d1b6eeSJonathan Corbet my $text = shift; 2632*c0d1b6eeSJonathan Corbet if (($output_mode eq "text") || ($output_mode eq "man")) { 2633*c0d1b6eeSJonathan Corbet return $text; 2634*c0d1b6eeSJonathan Corbet } 2635*c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\amp;/\&/g; 2636*c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\lt;/</g; 2637*c0d1b6eeSJonathan Corbet $text =~ s/\\\\\\gt;/>/g; 2638*c0d1b6eeSJonathan Corbet return $text; 2639*c0d1b6eeSJonathan Corbet} 2640*c0d1b6eeSJonathan Corbet 26416b5b55f6SRandy Dunlap# convert local escape strings to html 26426b5b55f6SRandy Dunlap# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) 26436b5b55f6SRandy Dunlapsub local_unescape($) { 26446b5b55f6SRandy Dunlap my $text = shift; 26456b5b55f6SRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 26466b5b55f6SRandy Dunlap return $text; 26476b5b55f6SRandy Dunlap } 26486b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\lt:/</g; 26496b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\gt:/>/g; 26506b5b55f6SRandy Dunlap return $text; 26516b5b55f6SRandy Dunlap} 26526b5b55f6SRandy Dunlap 26531da177e4SLinus Torvaldssub process_file($) { 26542283a117SRandy Dunlap my $file; 26551da177e4SLinus Torvalds my $identifier; 26561da177e4SLinus Torvalds my $func; 2657a21217daSRandy Dunlap my $descr; 26586423133bSJohannes Weiner my $in_purpose = 0; 26591da177e4SLinus Torvalds my $initial_section_counter = $section_counter; 266068f86662SBen Hutchings my ($orig_file) = @_; 26611da177e4SLinus Torvalds 26622283a117SRandy Dunlap if (defined($ENV{'SRCTREE'})) { 266368f86662SBen Hutchings $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 26642283a117SRandy Dunlap } 26652283a117SRandy Dunlap else { 266668f86662SBen Hutchings $file = $orig_file; 26672283a117SRandy Dunlap } 26681da177e4SLinus Torvalds if (defined($source_map{$file})) { 26691da177e4SLinus Torvalds $file = $source_map{$file}; 26701da177e4SLinus Torvalds } 26711da177e4SLinus Torvalds 26721da177e4SLinus Torvalds if (!open(IN,"<$file")) { 26731da177e4SLinus Torvalds print STDERR "Error: Cannot open file $file\n"; 26741da177e4SLinus Torvalds ++$errors; 26751da177e4SLinus Torvalds return; 26761da177e4SLinus Torvalds } 26771da177e4SLinus Torvalds 2678a9e7314bSIlya Dryomov $. = 1; 2679a9e7314bSIlya Dryomov 26801da177e4SLinus Torvalds $section_counter = 0; 26811da177e4SLinus Torvalds while (<IN>) { 268265478428SDaniel Santos while (s/\\\s*$//) { 268365478428SDaniel Santos $_ .= <IN>; 268465478428SDaniel Santos } 26851da177e4SLinus Torvalds if ($state == 0) { 26861da177e4SLinus Torvalds if (/$doc_start/o) { 26871da177e4SLinus Torvalds $state = 1; # next line is always the function name 2688850622dfSRandy Dunlap $in_doc_sect = 0; 26891da177e4SLinus Torvalds } 26901da177e4SLinus Torvalds } elsif ($state == 1) { # this line is the function name (always) 26911da177e4SLinus Torvalds if (/$doc_block/o) { 26921da177e4SLinus Torvalds $state = 4; 26931da177e4SLinus Torvalds $contents = ""; 26941da177e4SLinus Torvalds if ( $1 eq "" ) { 26951da177e4SLinus Torvalds $section = $section_intro; 26961da177e4SLinus Torvalds } else { 26971da177e4SLinus Torvalds $section = $1; 26981da177e4SLinus Torvalds } 26991da177e4SLinus Torvalds } 27001da177e4SLinus Torvalds elsif (/$doc_decl/o) { 27011da177e4SLinus Torvalds $identifier = $1; 27021da177e4SLinus Torvalds if (/\s*([\w\s]+?)\s*-/) { 27031da177e4SLinus Torvalds $identifier = $1; 27041da177e4SLinus Torvalds } 27051da177e4SLinus Torvalds 27061da177e4SLinus Torvalds $state = 2; 27071da177e4SLinus Torvalds if (/-(.*)/) { 270851f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2709a21217daSRandy Dunlap $descr= $1; 2710a21217daSRandy Dunlap $descr =~ s/^\s*//; 2711a21217daSRandy Dunlap $descr =~ s/\s*$//; 271212ae6779SDaniel Santos $descr =~ s/\s+/ /g; 2713a21217daSRandy Dunlap $declaration_purpose = xml_escape($descr); 27146423133bSJohannes Weiner $in_purpose = 1; 27151da177e4SLinus Torvalds } else { 27161da177e4SLinus Torvalds $declaration_purpose = ""; 27171da177e4SLinus Torvalds } 271877cc23b8SRandy Dunlap 271977cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 2720d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 272177cc23b8SRandy Dunlap print STDERR $_; 272277cc23b8SRandy Dunlap ++$warnings; 272377cc23b8SRandy Dunlap } 272477cc23b8SRandy Dunlap 27251da177e4SLinus Torvalds if ($identifier =~ m/^struct/) { 27261da177e4SLinus Torvalds $decl_type = 'struct'; 27271da177e4SLinus Torvalds } elsif ($identifier =~ m/^union/) { 27281da177e4SLinus Torvalds $decl_type = 'union'; 27291da177e4SLinus Torvalds } elsif ($identifier =~ m/^enum/) { 27301da177e4SLinus Torvalds $decl_type = 'enum'; 27311da177e4SLinus Torvalds } elsif ($identifier =~ m/^typedef/) { 27321da177e4SLinus Torvalds $decl_type = 'typedef'; 27331da177e4SLinus Torvalds } else { 27341da177e4SLinus Torvalds $decl_type = 'function'; 27351da177e4SLinus Torvalds } 27361da177e4SLinus Torvalds 27371da177e4SLinus Torvalds if ($verbose) { 2738d40e1e65SBart Van Assche print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; 27391da177e4SLinus Torvalds } 27401da177e4SLinus Torvalds } else { 2741d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 27421da177e4SLinus Torvalds " - I thought it was a doc line\n"; 27431da177e4SLinus Torvalds ++$warnings; 27441da177e4SLinus Torvalds $state = 0; 27451da177e4SLinus Torvalds } 27461da177e4SLinus Torvalds } elsif ($state == 2) { # look for head: lines, and include content 27471da177e4SLinus Torvalds if (/$doc_sect/o) { 27481da177e4SLinus Torvalds $newsection = $1; 27491da177e4SLinus Torvalds $newcontents = $2; 27501da177e4SLinus Torvalds 2751792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 2752850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 2753d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: contents before sections\n"; 2754850622dfSRandy Dunlap ++$warnings; 2755850622dfSRandy Dunlap } 275694dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 27571da177e4SLinus Torvalds $section = $section_default; 27581da177e4SLinus Torvalds } 27591da177e4SLinus Torvalds 2760850622dfSRandy Dunlap $in_doc_sect = 1; 27616423133bSJohannes Weiner $in_purpose = 0; 27621da177e4SLinus Torvalds $contents = $newcontents; 27631da177e4SLinus Torvalds if ($contents ne "") { 276427205744SRandy Dunlap while ((substr($contents, 0, 1) eq " ") || 276527205744SRandy Dunlap substr($contents, 0, 1) eq "\t") { 276605189497SRandy Dunlap $contents = substr($contents, 1); 276705189497SRandy Dunlap } 27681da177e4SLinus Torvalds $contents .= "\n"; 27691da177e4SLinus Torvalds } 27701da177e4SLinus Torvalds $section = $newsection; 27711da177e4SLinus Torvalds } elsif (/$doc_end/) { 27724c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 277394dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 27741da177e4SLinus Torvalds $section = $section_default; 27751da177e4SLinus Torvalds $contents = ""; 27761da177e4SLinus Torvalds } 277746b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 277846b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2779d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: suspicious ending line: $_"; 278046b958ebSRandy Dunlap ++$warnings; 278146b958ebSRandy Dunlap } 27821da177e4SLinus Torvalds 27831da177e4SLinus Torvalds $prototype = ""; 27841da177e4SLinus Torvalds $state = 3; 27851da177e4SLinus Torvalds $brcount = 0; 27861da177e4SLinus Torvalds# print STDERR "end of doc comment, looking for prototype\n"; 27871da177e4SLinus Torvalds } elsif (/$doc_content/) { 27881da177e4SLinus Torvalds # miguel-style comment kludge, look for blank lines after 27891da177e4SLinus Torvalds # @parameter line to signify start of description 27906423133bSJohannes Weiner if ($1 eq "") { 27916423133bSJohannes Weiner if ($section =~ m/^@/ || $section eq $section_context) { 279294dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 27931da177e4SLinus Torvalds $section = $section_default; 27941da177e4SLinus Torvalds $contents = ""; 27951da177e4SLinus Torvalds } else { 27966423133bSJohannes Weiner $contents .= "\n"; 27976423133bSJohannes Weiner } 27986423133bSJohannes Weiner $in_purpose = 0; 27996423133bSJohannes Weiner } elsif ($in_purpose == 1) { 28006423133bSJohannes Weiner # Continued declaration purpose 28016423133bSJohannes Weiner chomp($declaration_purpose); 28026423133bSJohannes Weiner $declaration_purpose .= " " . xml_escape($1); 280312ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 28046423133bSJohannes Weiner } else { 28051da177e4SLinus Torvalds $contents .= $1 . "\n"; 28061da177e4SLinus Torvalds } 28071da177e4SLinus Torvalds } else { 28081da177e4SLinus Torvalds # i dont know - bad line? ignore. 2809d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: bad line: $_"; 28101da177e4SLinus Torvalds ++$warnings; 28111da177e4SLinus Torvalds } 2812a4c6ebedSDanilo Cesar Lemes de Paula } elsif ($state == 5) { # scanning for split parameters 2813a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 2814a4c6ebedSDanilo Cesar Lemes de Paula if ($split_doc_state == 1 && /$doc_split_sect/o) { 2815a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 2816a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 2817a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 2818a4c6ebedSDanilo Cesar Lemes de Paula while ((substr($contents, 0, 1) eq " ") || 2819a4c6ebedSDanilo Cesar Lemes de Paula substr($contents, 0, 1) eq "\t") { 2820a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 2821a4c6ebedSDanilo Cesar Lemes de Paula } 2822a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 2823a4c6ebedSDanilo Cesar Lemes de Paula } 2824a4c6ebedSDanilo Cesar Lemes de Paula $split_doc_state = 2; 2825a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 2826a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_split_end/) { 2827a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 2828a4c6ebedSDanilo Cesar Lemes de Paula dump_section($file, $section, xml_escape($contents)); 2829a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 2830a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 2831a4c6ebedSDanilo Cesar Lemes de Paula } 2832a4c6ebedSDanilo Cesar Lemes de Paula $state = 3; 2833a4c6ebedSDanilo Cesar Lemes de Paula $split_doc_state = 0; 2834a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 2835a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 2836a4c6ebedSDanilo Cesar Lemes de Paula if ($split_doc_state == 2) { 2837a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 2838a4c6ebedSDanilo Cesar Lemes de Paula } elsif ($split_doc_state == 1) { 2839a4c6ebedSDanilo Cesar Lemes de Paula $split_doc_state = 4; 2840a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Warning(${file}:$.): "; 2841a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Incorrect use of kernel-doc format: $_"; 2842a4c6ebedSDanilo Cesar Lemes de Paula ++$warnings; 2843a4c6ebedSDanilo Cesar Lemes de Paula } 2844a4c6ebedSDanilo Cesar Lemes de Paula } 2845232acbcfSRandy Dunlap } elsif ($state == 3) { # scanning for function '{' (end of prototype) 2846a4c6ebedSDanilo Cesar Lemes de Paula if (/$doc_split_start/) { 2847a4c6ebedSDanilo Cesar Lemes de Paula $state = 5; 2848a4c6ebedSDanilo Cesar Lemes de Paula $split_doc_state = 1; 2849a4c6ebedSDanilo Cesar Lemes de Paula } elsif ($decl_type eq 'function') { 28501da177e4SLinus Torvalds process_state3_function($_, $file); 28511da177e4SLinus Torvalds } else { 28521da177e4SLinus Torvalds process_state3_type($_, $file); 28531da177e4SLinus Torvalds } 28541da177e4SLinus Torvalds } elsif ($state == 4) { 28551da177e4SLinus Torvalds # Documentation block 28561da177e4SLinus Torvalds if (/$doc_block/) { 285794dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 28581da177e4SLinus Torvalds $contents = ""; 28591da177e4SLinus Torvalds $function = ""; 28601da177e4SLinus Torvalds %constants = (); 28611da177e4SLinus Torvalds %parameterdescs = (); 28621da177e4SLinus Torvalds %parametertypes = (); 28631da177e4SLinus Torvalds @parameterlist = (); 28641da177e4SLinus Torvalds %sections = (); 28651da177e4SLinus Torvalds @sectionlist = (); 28661da177e4SLinus Torvalds $prototype = ""; 28671da177e4SLinus Torvalds if ( $1 eq "" ) { 28681da177e4SLinus Torvalds $section = $section_intro; 28691da177e4SLinus Torvalds } else { 28701da177e4SLinus Torvalds $section = $1; 28711da177e4SLinus Torvalds } 28721da177e4SLinus Torvalds } 28731da177e4SLinus Torvalds elsif (/$doc_end/) 28741da177e4SLinus Torvalds { 287594dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 28761da177e4SLinus Torvalds $contents = ""; 28771da177e4SLinus Torvalds $function = ""; 28781da177e4SLinus Torvalds %constants = (); 28791da177e4SLinus Torvalds %parameterdescs = (); 28801da177e4SLinus Torvalds %parametertypes = (); 28811da177e4SLinus Torvalds @parameterlist = (); 28821da177e4SLinus Torvalds %sections = (); 28831da177e4SLinus Torvalds @sectionlist = (); 28841da177e4SLinus Torvalds $prototype = ""; 28851da177e4SLinus Torvalds $state = 0; 28861da177e4SLinus Torvalds } 28871da177e4SLinus Torvalds elsif (/$doc_content/) 28881da177e4SLinus Torvalds { 28891da177e4SLinus Torvalds if ( $1 eq "" ) 28901da177e4SLinus Torvalds { 28911da177e4SLinus Torvalds $contents .= $blankline; 28921da177e4SLinus Torvalds } 28931da177e4SLinus Torvalds else 28941da177e4SLinus Torvalds { 28951da177e4SLinus Torvalds $contents .= $1 . "\n"; 28961da177e4SLinus Torvalds } 28971da177e4SLinus Torvalds } 28981da177e4SLinus Torvalds } 28991da177e4SLinus Torvalds } 29001da177e4SLinus Torvalds if ($initial_section_counter == $section_counter) { 2901d40e1e65SBart Van Assche print STDERR "${file}:1: warning: no structured comments found\n"; 2902e946c43aSJohannes Berg if (($function_only == 1) && ($show_not_found == 1)) { 2903e946c43aSJohannes Berg print STDERR " Was looking for '$_'.\n" for keys %function_table; 2904e946c43aSJohannes Berg } 29051da177e4SLinus Torvalds if ($output_mode eq "xml") { 29061da177e4SLinus Torvalds # The template wants at least one RefEntry here; make one. 29071da177e4SLinus Torvalds print "<refentry>\n"; 29081da177e4SLinus Torvalds print " <refnamediv>\n"; 29091da177e4SLinus Torvalds print " <refname>\n"; 291068f86662SBen Hutchings print " ${orig_file}\n"; 29111da177e4SLinus Torvalds print " </refname>\n"; 29121da177e4SLinus Torvalds print " <refpurpose>\n"; 29131da177e4SLinus Torvalds print " Document generation inconsistency\n"; 29141da177e4SLinus Torvalds print " </refpurpose>\n"; 29151da177e4SLinus Torvalds print " </refnamediv>\n"; 29161da177e4SLinus Torvalds print " <refsect1>\n"; 29171da177e4SLinus Torvalds print " <title>\n"; 29181da177e4SLinus Torvalds print " Oops\n"; 29191da177e4SLinus Torvalds print " </title>\n"; 29201da177e4SLinus Torvalds print " <warning>\n"; 29211da177e4SLinus Torvalds print " <para>\n"; 29221da177e4SLinus Torvalds print " The template for this document tried to insert\n"; 29231da177e4SLinus Torvalds print " the structured comment from the file\n"; 292468f86662SBen Hutchings print " <filename>${orig_file}</filename> at this point,\n"; 29251da177e4SLinus Torvalds print " but none was found.\n"; 29261da177e4SLinus Torvalds print " This dummy section is inserted to allow\n"; 29271da177e4SLinus Torvalds print " generation to continue.\n"; 29281da177e4SLinus Torvalds print " </para>\n"; 29291da177e4SLinus Torvalds print " </warning>\n"; 29301da177e4SLinus Torvalds print " </refsect1>\n"; 29311da177e4SLinus Torvalds print "</refentry>\n"; 29321da177e4SLinus Torvalds } 29331da177e4SLinus Torvalds } 29341da177e4SLinus Torvalds} 29358484baaaSRandy Dunlap 29368484baaaSRandy Dunlap 29378484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 29388484baaaSRandy Dunlap 29398484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 29408484baaaSRandy Dunlap# using the s// operator. 29411ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 29424d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 29434d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 29444d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 29454d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 29468484baaaSRandy Dunlap} 29478484baaaSRandy Dunlap 29488484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 29498484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 29508484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 29518484baaaSRandy Dunlap my ($relname, $absname); 29528484baaaSRandy Dunlap while(<SOURCE_MAP>) { 29538484baaaSRandy Dunlap chop(); 29548484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 29558484baaaSRandy Dunlap $relname =~ s:^/+::; 29568484baaaSRandy Dunlap $source_map{$relname} = $absname; 29578484baaaSRandy Dunlap } 29588484baaaSRandy Dunlap close(SOURCE_MAP); 29598484baaaSRandy Dunlap} 29608484baaaSRandy Dunlap 29618484baaaSRandy Dunlapforeach (@ARGV) { 29628484baaaSRandy Dunlap chomp; 29638484baaaSRandy Dunlap process_file($_); 29648484baaaSRandy Dunlap} 29658484baaaSRandy Dunlapif ($verbose && $errors) { 29668484baaaSRandy Dunlap print STDERR "$errors errors\n"; 29678484baaaSRandy Dunlap} 29688484baaaSRandy Dunlapif ($verbose && $warnings) { 29698484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 29708484baaaSRandy Dunlap} 29718484baaaSRandy Dunlap 29728484baaaSRandy Dunlapexit($errors); 2973