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 421da177e4SLinus Torvalds# 431da177e4SLinus Torvalds# This will read a 'c' file and scan for embedded comments in the 441da177e4SLinus Torvalds# style of gnome comments (+minor extensions - see below). 451da177e4SLinus Torvalds# 461da177e4SLinus Torvalds 471da177e4SLinus Torvalds# Note: This only supports 'c'. 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds# usage: 501b40c194SDan Luedtke# kernel-doc [ -docbook | -html | -html5 | -text | -man | -list ] 511b40c194SDan Luedtke# [ -no-doc-sections ] 521b40c194SDan Luedtke# [ -function funcname [ -function funcname ...] ] 531b40c194SDan Luedtke# c file(s)s > outputfile 541da177e4SLinus Torvalds# or 551b40c194SDan Luedtke# [ -nofunction funcname [ -function funcname ...] ] 561b40c194SDan Luedtke# c file(s)s > outputfile 571da177e4SLinus Torvalds# 581b40c194SDan Luedtke# Set output format using one of -docbook -html -html5 -text or -man. 591b40c194SDan Luedtke# Default is man. 60eda603f6SJohannes Berg# The -list format is for internal use by docproc. 611da177e4SLinus Torvalds# 624b44595aSJohannes Berg# -no-doc-sections 634b44595aSJohannes Berg# Do not output DOC: sections 644b44595aSJohannes Berg# 651da177e4SLinus Torvalds# -function funcname 66b112e0f7SJohannes Berg# If set, then only generate documentation for the given function(s) or 67b112e0f7SJohannes Berg# DOC: section titles. All other functions and DOC: sections are ignored. 681da177e4SLinus Torvalds# 691da177e4SLinus Torvalds# -nofunction funcname 70b112e0f7SJohannes Berg# If set, then only generate documentation for the other function(s)/DOC: 71b112e0f7SJohannes Berg# sections. Cannot be used together with -function (yes, that's a bug -- 72b112e0f7SJohannes Berg# perl hackers can fix it 8)) 731da177e4SLinus Torvalds# 741da177e4SLinus Torvalds# c files - list of 'c' files to process 751da177e4SLinus Torvalds# 761da177e4SLinus Torvalds# All output goes to stdout, with errors to stderr. 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds# 791da177e4SLinus Torvalds# format of comments. 801da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure. 811da177e4SLinus Torvalds# (...)* signifies 0 or more structure elements 821da177e4SLinus Torvalds# /** 831da177e4SLinus Torvalds# * function_name(:)? (- short description)? 841da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)* 851da177e4SLinus Torvalds# (* a blank line)? 861da177e4SLinus Torvalds# * (Description:)? (Description of function)? 871da177e4SLinus Torvalds# * (section header: (section description)? )* 881da177e4SLinus Torvalds# (*)?*/ 891da177e4SLinus Torvalds# 901da177e4SLinus Torvalds# So .. the trivial example would be: 911da177e4SLinus Torvalds# 921da177e4SLinus Torvalds# /** 931da177e4SLinus Torvalds# * my_function 94b9d97328SRandy Dunlap# */ 951da177e4SLinus Torvalds# 96891dcd2fSRandy Dunlap# If the Description: header tag is omitted, then there must be a blank line 971da177e4SLinus Torvalds# after the last parameter specification. 981da177e4SLinus Torvalds# e.g. 991da177e4SLinus Torvalds# /** 1001da177e4SLinus Torvalds# * my_function - does my stuff 1011da177e4SLinus Torvalds# * @my_arg: its mine damnit 1021da177e4SLinus Torvalds# * 1031da177e4SLinus Torvalds# * Does my stuff explained. 1041da177e4SLinus Torvalds# */ 1051da177e4SLinus Torvalds# 1061da177e4SLinus Torvalds# or, could also use: 1071da177e4SLinus Torvalds# /** 1081da177e4SLinus Torvalds# * my_function - does my stuff 1091da177e4SLinus Torvalds# * @my_arg: its mine damnit 1101da177e4SLinus Torvalds# * Description: Does my stuff explained. 1111da177e4SLinus Torvalds# */ 1121da177e4SLinus Torvalds# etc. 1131da177e4SLinus Torvalds# 114b9d97328SRandy Dunlap# Besides functions you can also write documentation for structs, unions, 1151da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name 1161da177e4SLinus Torvalds# of the declaration; the struct/union/enum/typedef must always precede 1171da177e4SLinus Torvalds# the name. Nesting of declarations is not supported. 1181da177e4SLinus Torvalds# Use the argument mechanism to document members or constants. 1191da177e4SLinus Torvalds# e.g. 1201da177e4SLinus Torvalds# /** 1211da177e4SLinus Torvalds# * struct my_struct - short description 1221da177e4SLinus Torvalds# * @a: first member 1231da177e4SLinus Torvalds# * @b: second member 1241da177e4SLinus Torvalds# * 1251da177e4SLinus Torvalds# * Longer description 1261da177e4SLinus Torvalds# */ 1271da177e4SLinus Torvalds# struct my_struct { 1281da177e4SLinus Torvalds# int a; 1291da177e4SLinus Torvalds# int b; 130aeec46b9SMartin Waitz# /* private: */ 131aeec46b9SMartin Waitz# int c; 1321da177e4SLinus Torvalds# }; 1331da177e4SLinus Torvalds# 1341da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description. 1351da177e4SLinus Torvalds# 136a4c6ebedSDanilo Cesar Lemes de Paula# For really longs structs, you can also describe arguments inside the 137a4c6ebedSDanilo Cesar Lemes de Paula# body of the struct. 138a4c6ebedSDanilo Cesar Lemes de Paula# eg. 139a4c6ebedSDanilo Cesar Lemes de Paula# /** 140a4c6ebedSDanilo Cesar Lemes de Paula# * struct my_struct - short description 141a4c6ebedSDanilo Cesar Lemes de Paula# * @a: first member 142a4c6ebedSDanilo Cesar Lemes de Paula# * @b: second member 143a4c6ebedSDanilo Cesar Lemes de Paula# * 144a4c6ebedSDanilo Cesar Lemes de Paula# * Longer description 145a4c6ebedSDanilo Cesar Lemes de Paula# */ 146a4c6ebedSDanilo Cesar Lemes de Paula# struct my_struct { 147a4c6ebedSDanilo Cesar Lemes de Paula# int a; 148a4c6ebedSDanilo Cesar Lemes de Paula# int b; 149a4c6ebedSDanilo Cesar Lemes de Paula# /** 150a4c6ebedSDanilo Cesar Lemes de Paula# * @c: This is longer description of C 151a4c6ebedSDanilo Cesar Lemes de Paula# * 152a4c6ebedSDanilo Cesar Lemes de Paula# * You can use paragraphs to describe arguments 153a4c6ebedSDanilo Cesar Lemes de Paula# * using this method. 154a4c6ebedSDanilo Cesar Lemes de Paula# */ 155a4c6ebedSDanilo Cesar Lemes de Paula# int c; 156a4c6ebedSDanilo Cesar Lemes de Paula# }; 157a4c6ebedSDanilo Cesar Lemes de Paula# 158a4c6ebedSDanilo Cesar Lemes de Paula# This should be use only for struct/enum members. 159a4c6ebedSDanilo Cesar Lemes de Paula# 1601da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you 1611da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions 1621da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an 1631da177e4SLinus Torvalds# empty line. 1644092bac7SYacine Belkadi# A non-void function should have a "Return:" section describing the return 1654092bac7SYacine Belkadi# value(s). 1661da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked 1671da177e4SLinus Torvalds# appropriately in DocBook. 1681da177e4SLinus Torvalds# 1691da177e4SLinus Torvalds# Example: 1701da177e4SLinus Torvalds# /** 1711da177e4SLinus Torvalds# * user_function - function that can only be called in user context 1721da177e4SLinus Torvalds# * @a: some argument 1731da177e4SLinus Torvalds# * Context: !in_interrupt() 1741da177e4SLinus Torvalds# * 1751da177e4SLinus Torvalds# * Some description 1761da177e4SLinus Torvalds# * Example: 1771da177e4SLinus Torvalds# * user_function(22); 1781da177e4SLinus Torvalds# */ 1791da177e4SLinus Torvalds# ... 1801da177e4SLinus Torvalds# 1811da177e4SLinus Torvalds# 1821da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special 1831da177e4SLinus Torvalds# patterns, which are highlighted appropriately. 1841da177e4SLinus Torvalds# 1851da177e4SLinus Torvalds# 'funcname()' - function 1861da177e4SLinus Torvalds# '$ENVVAR' - environmental variable 1871da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct') 1881da177e4SLinus Torvalds# '@parameter' - name of a parameter 1891da177e4SLinus Torvalds# '%CONST' - name of a constant. 1901da177e4SLinus Torvalds 1918484baaaSRandy Dunlap## init lots of data 1928484baaaSRandy Dunlap 1931da177e4SLinus Torvaldsmy $errors = 0; 1941da177e4SLinus Torvaldsmy $warnings = 0; 1955f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 1961da177e4SLinus Torvalds 1971da177e4SLinus Torvalds# match expressions used to find embedded type information 1981da177e4SLinus Torvaldsmy $type_constant = '\%([-_\w]+)'; 1991da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 2001da177e4SLinus Torvaldsmy $type_param = '\@(\w+)'; 2013eb014a1SRandy Dunlapmy $type_struct = '\&((struct\s*)*[_\w]+)'; 2026b5b55f6SRandy Dunlapmy $type_struct_xml = '\\&((struct\s*)*[_\w]+)'; 2031da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 2041da177e4SLinus Torvalds 2051da177e4SLinus Torvalds# Output conversion substitutions. 2061da177e4SLinus Torvalds# One for each output format 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds# these work fairly well 2091da177e4SLinus Torvaldsmy %highlights_html = ( $type_constant, "<i>\$1</i>", 2101da177e4SLinus Torvalds $type_func, "<b>\$1</b>", 2113eb014a1SRandy Dunlap $type_struct_xml, "<i>\$1</i>", 2123eb014a1SRandy Dunlap $type_env, "<b><i>\$1</i></b>", 2131da177e4SLinus Torvalds $type_param, "<tt><b>\$1</b></tt>" ); 2146b5b55f6SRandy Dunlapmy $local_lt = "\\\\\\\\lt:"; 2156b5b55f6SRandy Dunlapmy $local_gt = "\\\\\\\\gt:"; 2166b5b55f6SRandy Dunlapmy $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" 2171da177e4SLinus Torvalds 2181b40c194SDan Luedtke# html version 5 2191b40c194SDan Luedtkemy %highlights_html5 = ( $type_constant, "<span class=\"const\">\$1</span>", 2201b40c194SDan Luedtke $type_func, "<span class=\"func\">\$1</span>", 2211b40c194SDan Luedtke $type_struct_xml, "<span class=\"struct\">\$1</span>", 2221b40c194SDan Luedtke $type_env, "<span class=\"env\">\$1</span>", 2231b40c194SDan Luedtke $type_param, "<span class=\"param\">\$1</span>" ); 2241b40c194SDan Luedtkemy $blankline_html5 = $local_lt . "br /" . $local_gt; 2251b40c194SDan Luedtke 2261da177e4SLinus Torvalds# XML, docbook format 2271da177e4SLinus Torvaldsmy %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>", 2281da177e4SLinus Torvalds $type_constant, "<constant>\$1</constant>", 2291da177e4SLinus Torvalds $type_func, "<function>\$1</function>", 2305c98fc03SJohannes Berg $type_struct_xml, "<structname>\$1</structname>", 2311da177e4SLinus Torvalds $type_env, "<envar>\$1</envar>", 2321da177e4SLinus Torvalds $type_param, "<parameter>\$1</parameter>" ); 2335c98fc03SJohannes Bergmy $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds# gnome, docbook format 2361da177e4SLinus Torvaldsmy %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>", 2371da177e4SLinus Torvalds $type_func, "<function>\$1</function>", 2381da177e4SLinus Torvalds $type_struct, "<structname>\$1</structname>", 2391da177e4SLinus Torvalds $type_env, "<envar>\$1</envar>", 2401da177e4SLinus Torvalds $type_param, "<parameter>\$1</parameter>" ); 2411da177e4SLinus Torvaldsmy $blankline_gnome = "</para><para>\n"; 2421da177e4SLinus Torvalds 2431da177e4SLinus Torvalds# these are pretty rough 2441da177e4SLinus Torvaldsmy %highlights_man = ( $type_constant, "\$1", 2451da177e4SLinus Torvalds $type_func, "\\\\fB\$1\\\\fP", 2461da177e4SLinus Torvalds $type_struct, "\\\\fI\$1\\\\fP", 2471da177e4SLinus Torvalds $type_param, "\\\\fI\$1\\\\fP" ); 2481da177e4SLinus Torvaldsmy $blankline_man = ""; 2491da177e4SLinus Torvalds 2501da177e4SLinus Torvalds# text-mode 2511da177e4SLinus Torvaldsmy %highlights_text = ( $type_constant, "\$1", 2521da177e4SLinus Torvalds $type_func, "\$1", 2531da177e4SLinus Torvalds $type_struct, "\$1", 2541da177e4SLinus Torvalds $type_param, "\$1" ); 2551da177e4SLinus Torvaldsmy $blankline_text = ""; 2561da177e4SLinus Torvalds 257eda603f6SJohannes Berg# list mode 258eda603f6SJohannes Bergmy %highlights_list = ( $type_constant, "\$1", 259eda603f6SJohannes Berg $type_func, "\$1", 260eda603f6SJohannes Berg $type_struct, "\$1", 261eda603f6SJohannes Berg $type_param, "\$1" ); 262eda603f6SJohannes Bergmy $blankline_list = ""; 2631da177e4SLinus Torvalds 2641da177e4SLinus Torvalds# read arguments 2651da177e4SLinus Torvaldsif ($#ARGV == -1) { 2661da177e4SLinus Torvalds usage(); 2671da177e4SLinus Torvalds} 2681da177e4SLinus Torvalds 2698484baaaSRandy Dunlapmy $kernelversion; 2708484baaaSRandy Dunlapmy $dohighlight = ""; 2718484baaaSRandy Dunlap 2721da177e4SLinus Torvaldsmy $verbose = 0; 2731da177e4SLinus Torvaldsmy $output_mode = "man"; 274e314ba31SDaniel Santosmy $output_preformatted = 0; 2754b44595aSJohannes Bergmy $no_doc_sections = 0; 2761da177e4SLinus Torvaldsmy %highlights = %highlights_man; 2771da177e4SLinus Torvaldsmy $blankline = $blankline_man; 2781da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 2791da177e4SLinus Torvaldsmy $function_only = 0; 280b2c4105bSBen Hutchingsmy $show_not_found = 0; 281b2c4105bSBen Hutchings 282b2c4105bSBen Hutchingsmy @build_time; 283b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 284b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 285b2c4105bSBen Hutchings @build_time = gmtime($seconds); 286b2c4105bSBen Hutchings} else { 287b2c4105bSBen Hutchings @build_time = localtime; 288b2c4105bSBen Hutchings} 289b2c4105bSBen Hutchings 2901da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 2911da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 292b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 293b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 2941da177e4SLinus Torvalds 2958484baaaSRandy Dunlap# Essentially these are globals. 296b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 297b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 2981da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 2991da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 3001da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 3011c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 3021da177e4SLinus Torvalds 303bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 304bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 305bd0e88e5SRandy Dunlap} 306bd0e88e5SRandy Dunlap 3071da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 3081da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 3091da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 3101da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 3111da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 3121da177e4SLinus Torvalds# into html. 3131da177e4SLinus Torvaldsmy $section_counter = 0; 3141da177e4SLinus Torvalds 3151da177e4SLinus Torvaldsmy $lineprefix=""; 3161da177e4SLinus Torvalds 3171da177e4SLinus Torvalds# states 3181da177e4SLinus Torvalds# 0 - normal code 3191da177e4SLinus Torvalds# 1 - looking for function name 3201da177e4SLinus Torvalds# 2 - scanning field start. 3211da177e4SLinus Torvalds# 3 - scanning prototype. 3221da177e4SLinus Torvalds# 4 - documentation block 323a4c6ebedSDanilo Cesar Lemes de Paula# 5 - gathering documentation outside main block 3241da177e4SLinus Torvaldsmy $state; 325850622dfSRandy Dunlapmy $in_doc_sect; 3261da177e4SLinus Torvalds 327a4c6ebedSDanilo Cesar Lemes de Paula# Split Doc State 328a4c6ebedSDanilo Cesar Lemes de Paula# 0 - Invalid (Before start or after finish) 329a4c6ebedSDanilo Cesar Lemes de Paula# 1 - Is started (the /** was found inside a struct) 330a4c6ebedSDanilo Cesar Lemes de Paula# 2 - The @parameter header was found, start accepting multi paragraph text. 331a4c6ebedSDanilo Cesar Lemes de Paula# 3 - Finished (the */ was found) 332a4c6ebedSDanilo Cesar Lemes de Paula# 4 - Error - Comment without header was found. Spit a warning as it's not 333a4c6ebedSDanilo Cesar Lemes de Paula# proper kernel-doc and ignore the rest. 334a4c6ebedSDanilo Cesar Lemes de Paulamy $split_doc_state; 335a4c6ebedSDanilo Cesar Lemes de Paula 3361da177e4SLinus Torvalds#declaration types: can be 3371da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 3381da177e4SLinus Torvaldsmy $decl_type; 3391da177e4SLinus Torvalds 3401da177e4SLinus Torvaldsmy $doc_special = "\@\%\$\&"; 3411da177e4SLinus Torvalds 3421da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 3431da177e4SLinus Torvaldsmy $doc_end = '\*/'; 3441da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 34512ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 3461da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 347891dcd2fSRandy Dunlapmy $doc_sect = $doc_com . '([' . $doc_special . ']?[\w\s]+):(.*)'; 34812ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 3491da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 350a4c6ebedSDanilo Cesar Lemes de Paulamy $doc_split_start = '^\s*/\*\*\s*$'; 351a4c6ebedSDanilo Cesar Lemes de Paulamy $doc_split_sect = '\s*\*\s*(@[\w\s]+):(.*)'; 352a4c6ebedSDanilo Cesar Lemes de Paulamy $doc_split_end = '^\s*\*/\s*$'; 3531da177e4SLinus Torvalds 3541da177e4SLinus Torvaldsmy %constants; 3551da177e4SLinus Torvaldsmy %parameterdescs; 3561da177e4SLinus Torvaldsmy @parameterlist; 3571da177e4SLinus Torvaldsmy %sections; 3581da177e4SLinus Torvaldsmy @sectionlist; 359a1d94aa5SRandy Dunlapmy $sectcheck; 360a1d94aa5SRandy Dunlapmy $struct_actual; 3611da177e4SLinus Torvalds 3621da177e4SLinus Torvaldsmy $contents = ""; 3631da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 3641da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 3651da177e4SLinus Torvaldsmy $section = $section_default; 3661da177e4SLinus Torvaldsmy $section_context = "Context"; 3674092bac7SYacine Belkadimy $section_return = "Return"; 3681da177e4SLinus Torvalds 3691da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 3701da177e4SLinus Torvalds 3711da177e4SLinus Torvaldsreset_state(); 3721da177e4SLinus Torvalds 3731da177e4SLinus Torvaldswhile ($ARGV[0] =~ m/^-(.*)/) { 3741da177e4SLinus Torvalds my $cmd = shift @ARGV; 3751da177e4SLinus Torvalds if ($cmd eq "-html") { 3761da177e4SLinus Torvalds $output_mode = "html"; 3771da177e4SLinus Torvalds %highlights = %highlights_html; 3781da177e4SLinus Torvalds $blankline = $blankline_html; 3791b40c194SDan Luedtke } elsif ($cmd eq "-html5") { 3801b40c194SDan Luedtke $output_mode = "html5"; 3811b40c194SDan Luedtke %highlights = %highlights_html5; 3821b40c194SDan Luedtke $blankline = $blankline_html5; 3831da177e4SLinus Torvalds } elsif ($cmd eq "-man") { 3841da177e4SLinus Torvalds $output_mode = "man"; 3851da177e4SLinus Torvalds %highlights = %highlights_man; 3861da177e4SLinus Torvalds $blankline = $blankline_man; 3871da177e4SLinus Torvalds } elsif ($cmd eq "-text") { 3881da177e4SLinus Torvalds $output_mode = "text"; 3891da177e4SLinus Torvalds %highlights = %highlights_text; 3901da177e4SLinus Torvalds $blankline = $blankline_text; 3911da177e4SLinus Torvalds } elsif ($cmd eq "-docbook") { 3921da177e4SLinus Torvalds $output_mode = "xml"; 3931da177e4SLinus Torvalds %highlights = %highlights_xml; 3941da177e4SLinus Torvalds $blankline = $blankline_xml; 395eda603f6SJohannes Berg } elsif ($cmd eq "-list") { 396eda603f6SJohannes Berg $output_mode = "list"; 397eda603f6SJohannes Berg %highlights = %highlights_list; 398eda603f6SJohannes Berg $blankline = $blankline_list; 3991da177e4SLinus Torvalds } elsif ($cmd eq "-gnome") { 4001da177e4SLinus Torvalds $output_mode = "gnome"; 4011da177e4SLinus Torvalds %highlights = %highlights_gnome; 4021da177e4SLinus Torvalds $blankline = $blankline_gnome; 4031da177e4SLinus Torvalds } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document 4041da177e4SLinus Torvalds $modulename = shift @ARGV; 4051da177e4SLinus Torvalds } elsif ($cmd eq "-function") { # to only output specific functions 4061da177e4SLinus Torvalds $function_only = 1; 4071da177e4SLinus Torvalds $function = shift @ARGV; 4081da177e4SLinus Torvalds $function_table{$function} = 1; 4091da177e4SLinus Torvalds } elsif ($cmd eq "-nofunction") { # to only output specific functions 4101da177e4SLinus Torvalds $function_only = 2; 4111da177e4SLinus Torvalds $function = shift @ARGV; 4121da177e4SLinus Torvalds $function_table{$function} = 1; 4131da177e4SLinus Torvalds } elsif ($cmd eq "-v") { 4141da177e4SLinus Torvalds $verbose = 1; 4151da177e4SLinus Torvalds } elsif (($cmd eq "-h") || ($cmd eq "--help")) { 4161da177e4SLinus Torvalds usage(); 4174b44595aSJohannes Berg } elsif ($cmd eq '-no-doc-sections') { 4184b44595aSJohannes Berg $no_doc_sections = 1; 419e946c43aSJohannes Berg } elsif ($cmd eq '-show-not-found') { 420e946c43aSJohannes Berg $show_not_found = 1; 4211da177e4SLinus Torvalds } 4221da177e4SLinus Torvalds} 4231da177e4SLinus Torvalds 4248484baaaSRandy Dunlap# continue execution near EOF; 4258484baaaSRandy Dunlap 4268484baaaSRandy Dunlapsub usage { 4271b40c194SDan Luedtke print "Usage: $0 [ -docbook | -html | -html5 | -text | -man | -list ]\n"; 4288484baaaSRandy Dunlap print " [ -no-doc-sections ]\n"; 4298484baaaSRandy Dunlap print " [ -function funcname [ -function funcname ...] ]\n"; 4308484baaaSRandy Dunlap print " [ -nofunction funcname [ -nofunction funcname ...] ]\n"; 4311b40c194SDan Luedtke print " [ -v ]\n"; 4328484baaaSRandy Dunlap print " c source file(s) > outputfile\n"; 4338484baaaSRandy Dunlap print " -v : verbose output, more warnings & other info listed\n"; 4348484baaaSRandy Dunlap exit 1; 4358484baaaSRandy Dunlap} 4368484baaaSRandy Dunlap 43753f049faSBorislav Petkov# get kernel version from env 43853f049faSBorislav Petkovsub get_kernel_version() { 4391b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 44053f049faSBorislav Petkov 44153f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 44253f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 44353f049faSBorislav Petkov } 44453f049faSBorislav Petkov return $version; 44553f049faSBorislav Petkov} 4461da177e4SLinus Torvalds 4471da177e4SLinus Torvalds## 4481da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 4491da177e4SLinus Torvalds# 4501da177e4SLinus Torvaldssub dump_section { 45194dc7ad5SRandy Dunlap my $file = shift; 4521da177e4SLinus Torvalds my $name = shift; 4531da177e4SLinus Torvalds my $contents = join "\n", @_; 4541da177e4SLinus Torvalds 4551da177e4SLinus Torvalds if ($name =~ m/$type_constant/) { 4561da177e4SLinus Torvalds $name = $1; 4571da177e4SLinus Torvalds# print STDERR "constant section '$1' = '$contents'\n"; 4581da177e4SLinus Torvalds $constants{$name} = $contents; 4591da177e4SLinus Torvalds } elsif ($name =~ m/$type_param/) { 4601da177e4SLinus Torvalds# print STDERR "parameter def '$1' = '$contents'\n"; 4611da177e4SLinus Torvalds $name = $1; 4621da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 463a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 464ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 465ced69090SRandy Dunlap# print STDERR "parameter def '...' = '$contents'\n"; 466ced69090SRandy Dunlap $name = "..."; 467ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 468a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 4691da177e4SLinus Torvalds } else { 4701da177e4SLinus Torvalds# print STDERR "other section '$name' = '$contents'\n"; 47194dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 472d40e1e65SBart Van Assche print STDERR "${file}:$.: error: duplicate section name '$name'\n"; 47394dc7ad5SRandy Dunlap ++$errors; 47494dc7ad5SRandy Dunlap } 4751da177e4SLinus Torvalds $sections{$name} = $contents; 4761da177e4SLinus Torvalds push @sectionlist, $name; 4771da177e4SLinus Torvalds } 4781da177e4SLinus Torvalds} 4791da177e4SLinus Torvalds 4801da177e4SLinus Torvalds## 481b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 482b112e0f7SJohannes Berg# 483b112e0f7SJohannes Bergsub dump_doc_section { 48494dc7ad5SRandy Dunlap my $file = shift; 485b112e0f7SJohannes Berg my $name = shift; 486b112e0f7SJohannes Berg my $contents = join "\n", @_; 487b112e0f7SJohannes Berg 4884b44595aSJohannes Berg if ($no_doc_sections) { 4894b44595aSJohannes Berg return; 4904b44595aSJohannes Berg } 4914b44595aSJohannes Berg 492b112e0f7SJohannes Berg if (($function_only == 0) || 493b112e0f7SJohannes Berg ( $function_only == 1 && defined($function_table{$name})) || 494b112e0f7SJohannes Berg ( $function_only == 2 && !defined($function_table{$name}))) 495b112e0f7SJohannes Berg { 49694dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 497b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 498b112e0f7SJohannes Berg 'sections' => \%sections, 499b112e0f7SJohannes Berg 'module' => $modulename, 500b112e0f7SJohannes Berg 'content-only' => ($function_only != 0), }); 501b112e0f7SJohannes Berg } 502b112e0f7SJohannes Berg} 503b112e0f7SJohannes Berg 504b112e0f7SJohannes Berg## 5051da177e4SLinus Torvalds# output function 5061da177e4SLinus Torvalds# 5071da177e4SLinus Torvalds# parameterdescs, a hash. 5081da177e4SLinus Torvalds# function => "function name" 5091da177e4SLinus Torvalds# parameterlist => @list of parameters 5101da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 5111da177e4SLinus Torvalds# sectionlist => @list of sections 512a21217daSRandy Dunlap# sections => %section descriptions 5131da177e4SLinus Torvalds# 5141da177e4SLinus Torvalds 5151da177e4SLinus Torvaldssub output_highlight { 5161da177e4SLinus Torvalds my $contents = join "\n",@_; 5171da177e4SLinus Torvalds my $line; 5181da177e4SLinus Torvalds 5191da177e4SLinus Torvalds# DEBUG 5201da177e4SLinus Torvalds# if (!defined $contents) { 5211da177e4SLinus Torvalds# use Carp; 5221da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 5231da177e4SLinus Torvalds# } 5241da177e4SLinus Torvalds 5251b40c194SDan Luedtke if ($output_mode eq "html" || $output_mode eq "html5" || 5261b40c194SDan Luedtke $output_mode eq "xml") { 5276b5b55f6SRandy Dunlap $contents = local_unescape($contents); 5286b5b55f6SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 5292b35f4d9SRandy Dunlap $contents =~ s/\\\\\\/\&/g; 5306b5b55f6SRandy Dunlap } 5313eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 5321da177e4SLinus Torvalds eval $dohighlight; 5331da177e4SLinus Torvalds die $@ if $@; 5343eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 5353eb014a1SRandy Dunlap 5361b40c194SDan Luedtke# strip whitespaces when generating html5 5371b40c194SDan Luedtke if ($output_mode eq "html5") { 5381b40c194SDan Luedtke $contents =~ s/^\s+//; 5391b40c194SDan Luedtke $contents =~ s/\s+$//; 5401b40c194SDan Luedtke } 5411da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 54212ae6779SDaniel Santos if (! $output_preformatted) { 54312ae6779SDaniel Santos $line =~ s/^\s*//; 54412ae6779SDaniel Santos } 5451da177e4SLinus Torvalds if ($line eq ""){ 546e314ba31SDaniel Santos if (! $output_preformatted) { 5476b5b55f6SRandy Dunlap print $lineprefix, local_unescape($blankline); 548e314ba31SDaniel Santos } 5491da177e4SLinus Torvalds } else { 5501da177e4SLinus Torvalds $line =~ s/\\\\\\/\&/g; 551cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 552cdccb316SRandy Dunlap print "\\&$line"; 553cdccb316SRandy Dunlap } else { 5541da177e4SLinus Torvalds print $lineprefix, $line; 5551da177e4SLinus Torvalds } 556cdccb316SRandy Dunlap } 5571da177e4SLinus Torvalds print "\n"; 5581da177e4SLinus Torvalds } 5591da177e4SLinus Torvalds} 5601da177e4SLinus Torvalds 5611da177e4SLinus Torvalds# output sections in html 5621da177e4SLinus Torvaldssub output_section_html(%) { 5631da177e4SLinus Torvalds my %args = %{$_[0]}; 5641da177e4SLinus Torvalds my $section; 5651da177e4SLinus Torvalds 5661da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 5671da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 5681da177e4SLinus Torvalds print "<blockquote>\n"; 5691da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 5701da177e4SLinus Torvalds print "</blockquote>\n"; 5711da177e4SLinus Torvalds } 5721da177e4SLinus Torvalds} 5731da177e4SLinus Torvalds 5741da177e4SLinus Torvalds# output enum in html 5751da177e4SLinus Torvaldssub output_enum_html(%) { 5761da177e4SLinus Torvalds my %args = %{$_[0]}; 5771da177e4SLinus Torvalds my ($parameter); 5781da177e4SLinus Torvalds my $count; 5791da177e4SLinus Torvalds print "<h2>enum " . $args{'enum'} . "</h2>\n"; 5801da177e4SLinus Torvalds 5811da177e4SLinus Torvalds print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; 5821da177e4SLinus Torvalds $count = 0; 5831da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5841da177e4SLinus Torvalds print " <b>" . $parameter . "</b>"; 5851da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 5861da177e4SLinus Torvalds $count++; 5871da177e4SLinus Torvalds print ",\n"; 5881da177e4SLinus Torvalds } 5891da177e4SLinus Torvalds print "<br>"; 5901da177e4SLinus Torvalds } 5911da177e4SLinus Torvalds print "};<br>\n"; 5921da177e4SLinus Torvalds 5931da177e4SLinus Torvalds print "<h3>Constants</h3>\n"; 5941da177e4SLinus Torvalds print "<dl>\n"; 5951da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5961da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 5971da177e4SLinus Torvalds print "<dd>"; 5981da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter}); 5991da177e4SLinus Torvalds } 6001da177e4SLinus Torvalds print "</dl>\n"; 6011da177e4SLinus Torvalds output_section_html(@_); 6021da177e4SLinus Torvalds print "<hr>\n"; 6031da177e4SLinus Torvalds} 6041da177e4SLinus Torvalds 605d28bee0cSRandy Dunlap# output typedef in html 6061da177e4SLinus Torvaldssub output_typedef_html(%) { 6071da177e4SLinus Torvalds my %args = %{$_[0]}; 6081da177e4SLinus Torvalds my ($parameter); 6091da177e4SLinus Torvalds my $count; 6101da177e4SLinus Torvalds print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; 6111da177e4SLinus Torvalds 6121da177e4SLinus Torvalds print "<b>typedef " . $args{'typedef'} . "</b>\n"; 6131da177e4SLinus Torvalds output_section_html(@_); 6141da177e4SLinus Torvalds print "<hr>\n"; 6151da177e4SLinus Torvalds} 6161da177e4SLinus Torvalds 6171da177e4SLinus Torvalds# output struct in html 6181da177e4SLinus Torvaldssub output_struct_html(%) { 6191da177e4SLinus Torvalds my %args = %{$_[0]}; 6201da177e4SLinus Torvalds my ($parameter); 6211da177e4SLinus Torvalds 622262d9b01SRandy Dunlap print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; 6231da177e4SLinus Torvalds print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; 6241da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6251da177e4SLinus Torvalds if ($parameter =~ /^#/) { 6261da177e4SLinus Torvalds print "$parameter<br>\n"; 6271da177e4SLinus Torvalds next; 6281da177e4SLinus Torvalds } 6291da177e4SLinus Torvalds my $parameter_name = $parameter; 6301da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6311da177e4SLinus Torvalds 6321da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6331da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 6341da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 6351da177e4SLinus Torvalds # pointer-to-function 6363eb014a1SRandy Dunlap print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; 6371da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 6383eb014a1SRandy Dunlap # bitfield 6393eb014a1SRandy Dunlap print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; 6401da177e4SLinus Torvalds } else { 6413eb014a1SRandy Dunlap print " <i>$type</i> <b>$parameter</b>;<br>\n"; 6421da177e4SLinus Torvalds } 6431da177e4SLinus Torvalds } 6441da177e4SLinus Torvalds print "};<br>\n"; 6451da177e4SLinus Torvalds 6461da177e4SLinus Torvalds print "<h3>Members</h3>\n"; 6471da177e4SLinus Torvalds print "<dl>\n"; 6481da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6491da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 6501da177e4SLinus Torvalds 6511da177e4SLinus Torvalds my $parameter_name = $parameter; 6521da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6531da177e4SLinus Torvalds 6541da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6551da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 6561da177e4SLinus Torvalds print "<dd>"; 6571da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6581da177e4SLinus Torvalds } 6591da177e4SLinus Torvalds print "</dl>\n"; 6601da177e4SLinus Torvalds output_section_html(@_); 6611da177e4SLinus Torvalds print "<hr>\n"; 6621da177e4SLinus Torvalds} 6631da177e4SLinus Torvalds 6641da177e4SLinus Torvalds# output function in html 6651da177e4SLinus Torvaldssub output_function_html(%) { 6661da177e4SLinus Torvalds my %args = %{$_[0]}; 6671da177e4SLinus Torvalds my ($parameter, $section); 6681da177e4SLinus Torvalds my $count; 6691da177e4SLinus Torvalds 670262d9b01SRandy Dunlap print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; 6711da177e4SLinus Torvalds print "<i>" . $args{'functiontype'} . "</i>\n"; 6721da177e4SLinus Torvalds print "<b>" . $args{'function'} . "</b>\n"; 6731da177e4SLinus Torvalds print "("; 6741da177e4SLinus Torvalds $count = 0; 6751da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6761da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 6771da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 6781da177e4SLinus Torvalds # pointer-to-function 6791da177e4SLinus Torvalds print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; 6801da177e4SLinus Torvalds } else { 6811da177e4SLinus Torvalds print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; 6821da177e4SLinus Torvalds } 6831da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 6841da177e4SLinus Torvalds $count++; 6851da177e4SLinus Torvalds print ",\n"; 6861da177e4SLinus Torvalds } 6871da177e4SLinus Torvalds } 6881da177e4SLinus Torvalds print ")\n"; 6891da177e4SLinus Torvalds 6901da177e4SLinus Torvalds print "<h3>Arguments</h3>\n"; 6911da177e4SLinus Torvalds print "<dl>\n"; 6921da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6931da177e4SLinus Torvalds my $parameter_name = $parameter; 6941da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6951da177e4SLinus Torvalds 6961da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6971da177e4SLinus Torvalds print "<dt><b>" . $parameter . "</b>\n"; 6981da177e4SLinus Torvalds print "<dd>"; 6991da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7001da177e4SLinus Torvalds } 7011da177e4SLinus Torvalds print "</dl>\n"; 7021da177e4SLinus Torvalds output_section_html(@_); 7031da177e4SLinus Torvalds print "<hr>\n"; 7041da177e4SLinus Torvalds} 7051da177e4SLinus Torvalds 706b112e0f7SJohannes Berg# output DOC: block header in html 707b112e0f7SJohannes Bergsub output_blockhead_html(%) { 7081da177e4SLinus Torvalds my %args = %{$_[0]}; 7091da177e4SLinus Torvalds my ($parameter, $section); 7101da177e4SLinus Torvalds my $count; 7111da177e4SLinus Torvalds 7121da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7131da177e4SLinus Torvalds print "<h3>$section</h3>\n"; 7141da177e4SLinus Torvalds print "<ul>\n"; 7151da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7161da177e4SLinus Torvalds print "</ul>\n"; 7171da177e4SLinus Torvalds } 7181da177e4SLinus Torvalds print "<hr>\n"; 7191da177e4SLinus Torvalds} 7201da177e4SLinus Torvalds 7211b40c194SDan Luedtke# output sections in html5 7221b40c194SDan Luedtkesub output_section_html5(%) { 7231b40c194SDan Luedtke my %args = %{$_[0]}; 7241b40c194SDan Luedtke my $section; 7251b40c194SDan Luedtke 7261b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 7271b40c194SDan Luedtke print "<section>\n"; 7281b40c194SDan Luedtke print "<h1>$section</h1>\n"; 7291b40c194SDan Luedtke print "<p>\n"; 7301b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 7311b40c194SDan Luedtke print "</p>\n"; 7321b40c194SDan Luedtke print "</section>\n"; 7331b40c194SDan Luedtke } 7341b40c194SDan Luedtke} 7351b40c194SDan Luedtke 7361b40c194SDan Luedtke# output enum in html5 7371b40c194SDan Luedtkesub output_enum_html5(%) { 7381b40c194SDan Luedtke my %args = %{$_[0]}; 7391b40c194SDan Luedtke my ($parameter); 7401b40c194SDan Luedtke my $count; 7411b40c194SDan Luedtke my $html5id; 7421b40c194SDan Luedtke 7431b40c194SDan Luedtke $html5id = $args{'enum'}; 7441b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 7451b40c194SDan Luedtke print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; 7461b40c194SDan Luedtke print "<h1>enum " . $args{'enum'} . "</h1>\n"; 7471b40c194SDan Luedtke print "<ol class=\"code\">\n"; 7481b40c194SDan Luedtke print "<li>"; 7491b40c194SDan Luedtke print "<span class=\"keyword\">enum</span> "; 7501b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; 7511b40c194SDan Luedtke print "</li>\n"; 7521b40c194SDan Luedtke $count = 0; 7531b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 7541b40c194SDan Luedtke print "<li class=\"indent\">"; 7551b40c194SDan Luedtke print "<span class=\"param\">" . $parameter . "</span>"; 7561b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 7571b40c194SDan Luedtke $count++; 7581b40c194SDan Luedtke print ","; 7591b40c194SDan Luedtke } 7601b40c194SDan Luedtke print "</li>\n"; 7611b40c194SDan Luedtke } 7621b40c194SDan Luedtke print "<li>};</li>\n"; 7631b40c194SDan Luedtke print "</ol>\n"; 7641b40c194SDan Luedtke 7651b40c194SDan Luedtke print "<section>\n"; 7661b40c194SDan Luedtke print "<h1>Constants</h1>\n"; 7671b40c194SDan Luedtke print "<dl>\n"; 7681b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 7691b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 7701b40c194SDan Luedtke print "<dd>"; 7711b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter}); 7721b40c194SDan Luedtke print "</dd>\n"; 7731b40c194SDan Luedtke } 7741b40c194SDan Luedtke print "</dl>\n"; 7751b40c194SDan Luedtke print "</section>\n"; 7761b40c194SDan Luedtke output_section_html5(@_); 7771b40c194SDan Luedtke print "</article>\n"; 7781b40c194SDan Luedtke} 7791b40c194SDan Luedtke 7801b40c194SDan Luedtke# output typedef in html5 7811b40c194SDan Luedtkesub output_typedef_html5(%) { 7821b40c194SDan Luedtke my %args = %{$_[0]}; 7831b40c194SDan Luedtke my ($parameter); 7841b40c194SDan Luedtke my $count; 7851b40c194SDan Luedtke my $html5id; 7861b40c194SDan Luedtke 7871b40c194SDan Luedtke $html5id = $args{'typedef'}; 7881b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 7891b40c194SDan Luedtke print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; 7901b40c194SDan Luedtke print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; 7911b40c194SDan Luedtke 7921b40c194SDan Luedtke print "<ol class=\"code\">\n"; 7931b40c194SDan Luedtke print "<li>"; 7941b40c194SDan Luedtke print "<span class=\"keyword\">typedef</span> "; 7951b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; 7961b40c194SDan Luedtke print "</li>\n"; 7971b40c194SDan Luedtke print "</ol>\n"; 7981b40c194SDan Luedtke output_section_html5(@_); 7991b40c194SDan Luedtke print "</article>\n"; 8001b40c194SDan Luedtke} 8011b40c194SDan Luedtke 8021b40c194SDan Luedtke# output struct in html5 8031b40c194SDan Luedtkesub output_struct_html5(%) { 8041b40c194SDan Luedtke my %args = %{$_[0]}; 8051b40c194SDan Luedtke my ($parameter); 8061b40c194SDan Luedtke my $html5id; 8071b40c194SDan Luedtke 8081b40c194SDan Luedtke $html5id = $args{'struct'}; 8091b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8101b40c194SDan Luedtke print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n"; 8111b40c194SDan Luedtke print "<hgroup>\n"; 8121b40c194SDan Luedtke print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>"; 8131b40c194SDan Luedtke print "<h2>". $args{'purpose'} . "</h2>\n"; 8141b40c194SDan Luedtke print "</hgroup>\n"; 8151b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8161b40c194SDan Luedtke print "<li>"; 8171b40c194SDan Luedtke print "<span class=\"type\">" . $args{'type'} . "</span> "; 8181b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'struct'} . "</span> {"; 8191b40c194SDan Luedtke print "</li>\n"; 8201b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8211b40c194SDan Luedtke print "<li class=\"indent\">"; 8221b40c194SDan Luedtke if ($parameter =~ /^#/) { 8231b40c194SDan Luedtke print "<span class=\"param\">" . $parameter ."</span>\n"; 8241b40c194SDan Luedtke print "</li>\n"; 8251b40c194SDan Luedtke next; 8261b40c194SDan Luedtke } 8271b40c194SDan Luedtke my $parameter_name = $parameter; 8281b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 8291b40c194SDan Luedtke 8301b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 8311b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 8321b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 8331b40c194SDan Luedtke # pointer-to-function 8341b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 8351b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 8361b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 8371b40c194SDan Luedtke print "(<span class=\"args\">$2</span>);"; 8381b40c194SDan Luedtke } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 8391b40c194SDan Luedtke # bitfield 8401b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 8411b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 8421b40c194SDan Luedtke print "<span class=\"bits\">$2</span>;"; 8431b40c194SDan Luedtke } else { 8441b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 8451b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>;"; 8461b40c194SDan Luedtke } 8471b40c194SDan Luedtke print "</li>\n"; 8481b40c194SDan Luedtke } 8491b40c194SDan Luedtke print "<li>};</li>\n"; 8501b40c194SDan Luedtke print "</ol>\n"; 8511b40c194SDan Luedtke 8521b40c194SDan Luedtke print "<section>\n"; 8531b40c194SDan Luedtke print "<h1>Members</h1>\n"; 8541b40c194SDan Luedtke print "<dl>\n"; 8551b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8561b40c194SDan Luedtke ($parameter =~ /^#/) && next; 8571b40c194SDan Luedtke 8581b40c194SDan Luedtke my $parameter_name = $parameter; 8591b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 8601b40c194SDan Luedtke 8611b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 8621b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 8631b40c194SDan Luedtke print "<dd>"; 8641b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 8651b40c194SDan Luedtke print "</dd>\n"; 8661b40c194SDan Luedtke } 8671b40c194SDan Luedtke print "</dl>\n"; 8681b40c194SDan Luedtke print "</section>\n"; 8691b40c194SDan Luedtke output_section_html5(@_); 8701b40c194SDan Luedtke print "</article>\n"; 8711b40c194SDan Luedtke} 8721b40c194SDan Luedtke 8731b40c194SDan Luedtke# output function in html5 8741b40c194SDan Luedtkesub output_function_html5(%) { 8751b40c194SDan Luedtke my %args = %{$_[0]}; 8761b40c194SDan Luedtke my ($parameter, $section); 8771b40c194SDan Luedtke my $count; 8781b40c194SDan Luedtke my $html5id; 8791b40c194SDan Luedtke 8801b40c194SDan Luedtke $html5id = $args{'function'}; 8811b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 8821b40c194SDan Luedtke print "<article class=\"function\" id=\"func:". $html5id . "\">\n"; 8831b40c194SDan Luedtke print "<hgroup>\n"; 8841b40c194SDan Luedtke print "<h1>" . $args{'function'} . "</h1>"; 8851b40c194SDan Luedtke print "<h2>" . $args{'purpose'} . "</h2>\n"; 8861b40c194SDan Luedtke print "</hgroup>\n"; 8871b40c194SDan Luedtke print "<ol class=\"code\">\n"; 8881b40c194SDan Luedtke print "<li>"; 8891b40c194SDan Luedtke print "<span class=\"type\">" . $args{'functiontype'} . "</span> "; 8901b40c194SDan Luedtke print "<span class=\"identifier\">" . $args{'function'} . "</span> ("; 8911b40c194SDan Luedtke print "</li>"; 8921b40c194SDan Luedtke $count = 0; 8931b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 8941b40c194SDan Luedtke print "<li class=\"indent\">"; 8951b40c194SDan Luedtke $type = $args{'parametertypes'}{$parameter}; 8961b40c194SDan Luedtke if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 8971b40c194SDan Luedtke # pointer-to-function 8981b40c194SDan Luedtke print "<span class=\"type\">$1</span> "; 8991b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9001b40c194SDan Luedtke print "<span class=\"type\">)</span> "; 9011b40c194SDan Luedtke print "(<span class=\"args\">$2</span>)"; 9021b40c194SDan Luedtke } else { 9031b40c194SDan Luedtke print "<span class=\"type\">$type</span> "; 9041b40c194SDan Luedtke print "<span class=\"param\">$parameter</span>"; 9051b40c194SDan Luedtke } 9061b40c194SDan Luedtke if ($count != $#{$args{'parameterlist'}}) { 9071b40c194SDan Luedtke $count++; 9081b40c194SDan Luedtke print ","; 9091b40c194SDan Luedtke } 9101b40c194SDan Luedtke print "</li>\n"; 9111b40c194SDan Luedtke } 9121b40c194SDan Luedtke print "<li>)</li>\n"; 9131b40c194SDan Luedtke print "</ol>\n"; 9141b40c194SDan Luedtke 9151b40c194SDan Luedtke print "<section>\n"; 9161b40c194SDan Luedtke print "<h1>Arguments</h1>\n"; 9171b40c194SDan Luedtke print "<p>\n"; 9181b40c194SDan Luedtke print "<dl>\n"; 9191b40c194SDan Luedtke foreach $parameter (@{$args{'parameterlist'}}) { 9201b40c194SDan Luedtke my $parameter_name = $parameter; 9211b40c194SDan Luedtke $parameter_name =~ s/\[.*//; 9221b40c194SDan Luedtke 9231b40c194SDan Luedtke ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 9241b40c194SDan Luedtke print "<dt>" . $parameter . "</dt>\n"; 9251b40c194SDan Luedtke print "<dd>"; 9261b40c194SDan Luedtke output_highlight($args{'parameterdescs'}{$parameter_name}); 9271b40c194SDan Luedtke print "</dd>\n"; 9281b40c194SDan Luedtke } 9291b40c194SDan Luedtke print "</dl>\n"; 9301b40c194SDan Luedtke print "</section>\n"; 9311b40c194SDan Luedtke output_section_html5(@_); 9321b40c194SDan Luedtke print "</article>\n"; 9331b40c194SDan Luedtke} 9341b40c194SDan Luedtke 9351b40c194SDan Luedtke# output DOC: block header in html5 9361b40c194SDan Luedtkesub output_blockhead_html5(%) { 9371b40c194SDan Luedtke my %args = %{$_[0]}; 9381b40c194SDan Luedtke my ($parameter, $section); 9391b40c194SDan Luedtke my $count; 9401b40c194SDan Luedtke my $html5id; 9411b40c194SDan Luedtke 9421b40c194SDan Luedtke foreach $section (@{$args{'sectionlist'}}) { 9431b40c194SDan Luedtke $html5id = $section; 9441b40c194SDan Luedtke $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; 9451b40c194SDan Luedtke print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n"; 9461b40c194SDan Luedtke print "<h1>$section</h1>\n"; 9471b40c194SDan Luedtke print "<p>\n"; 9481b40c194SDan Luedtke output_highlight($args{'sections'}{$section}); 9491b40c194SDan Luedtke print "</p>\n"; 9501b40c194SDan Luedtke } 9511b40c194SDan Luedtke print "</article>\n"; 9521b40c194SDan Luedtke} 9531b40c194SDan Luedtke 9541da177e4SLinus Torvaldssub output_section_xml(%) { 9551da177e4SLinus Torvalds my %args = %{$_[0]}; 9561da177e4SLinus Torvalds my $section; 9571da177e4SLinus Torvalds # print out each section 9581da177e4SLinus Torvalds $lineprefix=" "; 9591da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 960c73894c1SRich Walker print "<refsect1>\n"; 961c73894c1SRich Walker print "<title>$section</title>\n"; 9621da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 963c73894c1SRich Walker print "<informalexample><programlisting>\n"; 964e314ba31SDaniel Santos $output_preformatted = 1; 965c73894c1SRich Walker } else { 966c73894c1SRich Walker print "<para>\n"; 9671da177e4SLinus Torvalds } 9681da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 969e314ba31SDaniel Santos $output_preformatted = 0; 9701da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 971c73894c1SRich Walker print "</programlisting></informalexample>\n"; 972c73894c1SRich Walker } else { 973c73894c1SRich Walker print "</para>\n"; 9741da177e4SLinus Torvalds } 975c73894c1SRich Walker print "</refsect1>\n"; 9761da177e4SLinus Torvalds } 9771da177e4SLinus Torvalds} 9781da177e4SLinus Torvalds 9791da177e4SLinus Torvalds# output function in XML DocBook 9801da177e4SLinus Torvaldssub output_function_xml(%) { 9811da177e4SLinus Torvalds my %args = %{$_[0]}; 9821da177e4SLinus Torvalds my ($parameter, $section); 9831da177e4SLinus Torvalds my $count; 9841da177e4SLinus Torvalds my $id; 9851da177e4SLinus Torvalds 9861da177e4SLinus Torvalds $id = "API-" . $args{'function'}; 9871da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 9881da177e4SLinus Torvalds 9895449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 9908b0c2d98SMartin Waitz print "<refentryinfo>\n"; 9918b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 9928b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 9938b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 9948b0c2d98SMartin Waitz print "</refentryinfo>\n"; 9951da177e4SLinus Torvalds print "<refmeta>\n"; 9965449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; 9978b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 9980366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 9991da177e4SLinus Torvalds print "</refmeta>\n"; 10001da177e4SLinus Torvalds print "<refnamediv>\n"; 10011da177e4SLinus Torvalds print " <refname>" . $args{'function'} . "</refname>\n"; 10021da177e4SLinus Torvalds print " <refpurpose>\n"; 10031da177e4SLinus Torvalds print " "; 10041da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 10051da177e4SLinus Torvalds print " </refpurpose>\n"; 10061da177e4SLinus Torvalds print "</refnamediv>\n"; 10071da177e4SLinus Torvalds 10081da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 10091da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 10101da177e4SLinus Torvalds print " <funcsynopsis><funcprototype>\n"; 10111da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 10121da177e4SLinus Torvalds print "<function>" . $args{'function'} . " </function></funcdef>\n"; 10131da177e4SLinus Torvalds 10141da177e4SLinus Torvalds $count = 0; 10151da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 10161da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10171da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 10181da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 10191da177e4SLinus Torvalds # pointer-to-function 10201da177e4SLinus Torvalds print " <paramdef>$1<parameter>$parameter</parameter>)\n"; 10211da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 10221da177e4SLinus Torvalds } else { 10231da177e4SLinus Torvalds print " <paramdef>" . $type; 10241da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 10251da177e4SLinus Torvalds } 10261da177e4SLinus Torvalds } 10271da177e4SLinus Torvalds } else { 10286013d544SMartin Waitz print " <void/>\n"; 10291da177e4SLinus Torvalds } 10301da177e4SLinus Torvalds print " </funcprototype></funcsynopsis>\n"; 10311da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 10321da177e4SLinus Torvalds 10331da177e4SLinus Torvalds # print parameters 10341da177e4SLinus Torvalds print "<refsect1>\n <title>Arguments</title>\n"; 10351da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 10361da177e4SLinus Torvalds print " <variablelist>\n"; 10371da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10381da177e4SLinus Torvalds my $parameter_name = $parameter; 10391da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 10401da177e4SLinus Torvalds 10411da177e4SLinus Torvalds print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; 10421da177e4SLinus Torvalds print " <listitem>\n <para>\n"; 10431da177e4SLinus Torvalds $lineprefix=" "; 10441da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 10451da177e4SLinus Torvalds print " </para>\n </listitem>\n </varlistentry>\n"; 10461da177e4SLinus Torvalds } 10471da177e4SLinus Torvalds print " </variablelist>\n"; 10481da177e4SLinus Torvalds } else { 10491da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 10501da177e4SLinus Torvalds } 10511da177e4SLinus Torvalds print "</refsect1>\n"; 10521da177e4SLinus Torvalds 10531da177e4SLinus Torvalds output_section_xml(@_); 10541da177e4SLinus Torvalds print "</refentry>\n\n"; 10551da177e4SLinus Torvalds} 10561da177e4SLinus Torvalds 10571da177e4SLinus Torvalds# output struct in XML DocBook 10581da177e4SLinus Torvaldssub output_struct_xml(%) { 10591da177e4SLinus Torvalds my %args = %{$_[0]}; 10601da177e4SLinus Torvalds my ($parameter, $section); 10611da177e4SLinus Torvalds my $id; 10621da177e4SLinus Torvalds 10631da177e4SLinus Torvalds $id = "API-struct-" . $args{'struct'}; 10641da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 10651da177e4SLinus Torvalds 10665449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 10678b0c2d98SMartin Waitz print "<refentryinfo>\n"; 10688b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 10698b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 10708b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 10718b0c2d98SMartin Waitz print "</refentryinfo>\n"; 10721da177e4SLinus Torvalds print "<refmeta>\n"; 10735449bc94SPavel Pisa print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; 10748b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 10750366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 10761da177e4SLinus Torvalds print "</refmeta>\n"; 10771da177e4SLinus Torvalds print "<refnamediv>\n"; 10781da177e4SLinus Torvalds print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; 10791da177e4SLinus Torvalds print " <refpurpose>\n"; 10801da177e4SLinus Torvalds print " "; 10811da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 10821da177e4SLinus Torvalds print " </refpurpose>\n"; 10831da177e4SLinus Torvalds print "</refnamediv>\n"; 10841da177e4SLinus Torvalds 10851da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 10861da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 10871da177e4SLinus Torvalds print " <programlisting>\n"; 10881da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 10891da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 10901da177e4SLinus Torvalds if ($parameter =~ /^#/) { 10912b35f4d9SRandy Dunlap my $prm = $parameter; 10922b35f4d9SRandy Dunlap # convert data read & converted thru xml_escape() into &xyz; format: 10932b35f4d9SRandy Dunlap # This allows us to have #define macros interspersed in a struct. 10942b35f4d9SRandy Dunlap $prm =~ s/\\\\\\/\&/g; 10952b35f4d9SRandy Dunlap print "$prm\n"; 10961da177e4SLinus Torvalds next; 10971da177e4SLinus Torvalds } 10981da177e4SLinus Torvalds 10991da177e4SLinus Torvalds my $parameter_name = $parameter; 11001da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11011da177e4SLinus Torvalds 11021da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 11031da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 11041da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 11051da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 11061da177e4SLinus Torvalds # pointer-to-function 11071da177e4SLinus Torvalds print " $1 $parameter) ($2);\n"; 11081da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 110951f5a0c8SRandy Dunlap # bitfield 11101da177e4SLinus Torvalds print " $1 $parameter$2;\n"; 11111da177e4SLinus Torvalds } else { 11121da177e4SLinus Torvalds print " " . $type . " " . $parameter . ";\n"; 11131da177e4SLinus Torvalds } 11141da177e4SLinus Torvalds } 11151da177e4SLinus Torvalds print "};"; 11161da177e4SLinus Torvalds print " </programlisting>\n"; 11171da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 11181da177e4SLinus Torvalds 11191da177e4SLinus Torvalds print " <refsect1>\n"; 11201da177e4SLinus Torvalds print " <title>Members</title>\n"; 11211da177e4SLinus Torvalds 112239f00c08SRandy Dunlap if ($#{$args{'parameterlist'}} >= 0) { 11231da177e4SLinus Torvalds print " <variablelist>\n"; 11241da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11251da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 11261da177e4SLinus Torvalds 11271da177e4SLinus Torvalds my $parameter_name = $parameter; 11281da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 11291da177e4SLinus Torvalds 11301da177e4SLinus Torvalds defined($args{'parameterdescs'}{$parameter_name}) || next; 11311da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 11321da177e4SLinus Torvalds print " <varlistentry>"; 11331da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 11341da177e4SLinus Torvalds print " <listitem><para>\n"; 11351da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 11361da177e4SLinus Torvalds print " </para></listitem>\n"; 11371da177e4SLinus Torvalds print " </varlistentry>\n"; 11381da177e4SLinus Torvalds } 11391da177e4SLinus Torvalds print " </variablelist>\n"; 114039f00c08SRandy Dunlap } else { 114139f00c08SRandy Dunlap print " <para>\n None\n </para>\n"; 114239f00c08SRandy Dunlap } 11431da177e4SLinus Torvalds print " </refsect1>\n"; 11441da177e4SLinus Torvalds 11451da177e4SLinus Torvalds output_section_xml(@_); 11461da177e4SLinus Torvalds 11471da177e4SLinus Torvalds print "</refentry>\n\n"; 11481da177e4SLinus Torvalds} 11491da177e4SLinus Torvalds 11501da177e4SLinus Torvalds# output enum in XML DocBook 11511da177e4SLinus Torvaldssub output_enum_xml(%) { 11521da177e4SLinus Torvalds my %args = %{$_[0]}; 11531da177e4SLinus Torvalds my ($parameter, $section); 11541da177e4SLinus Torvalds my $count; 11551da177e4SLinus Torvalds my $id; 11561da177e4SLinus Torvalds 11571da177e4SLinus Torvalds $id = "API-enum-" . $args{'enum'}; 11581da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 11591da177e4SLinus Torvalds 11605449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 11618b0c2d98SMartin Waitz print "<refentryinfo>\n"; 11628b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 11638b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 11648b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 11658b0c2d98SMartin Waitz print "</refentryinfo>\n"; 11661da177e4SLinus Torvalds print "<refmeta>\n"; 11675449bc94SPavel Pisa print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; 11688b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 11690366299bSBorislav Petkov print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; 11701da177e4SLinus Torvalds print "</refmeta>\n"; 11711da177e4SLinus Torvalds print "<refnamediv>\n"; 11721da177e4SLinus Torvalds print " <refname>enum " . $args{'enum'} . "</refname>\n"; 11731da177e4SLinus Torvalds print " <refpurpose>\n"; 11741da177e4SLinus Torvalds print " "; 11751da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 11761da177e4SLinus Torvalds print " </refpurpose>\n"; 11771da177e4SLinus Torvalds print "</refnamediv>\n"; 11781da177e4SLinus Torvalds 11791da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 11801da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 11811da177e4SLinus Torvalds print " <programlisting>\n"; 11821da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 11831da177e4SLinus Torvalds $count = 0; 11841da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 11851da177e4SLinus Torvalds print " $parameter"; 11861da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 11871da177e4SLinus Torvalds $count++; 11881da177e4SLinus Torvalds print ","; 11891da177e4SLinus Torvalds } 11901da177e4SLinus Torvalds print "\n"; 11911da177e4SLinus Torvalds } 11921da177e4SLinus Torvalds print "};"; 11931da177e4SLinus Torvalds print " </programlisting>\n"; 11941da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 11951da177e4SLinus Torvalds 11961da177e4SLinus Torvalds print "<refsect1>\n"; 11971da177e4SLinus Torvalds print " <title>Constants</title>\n"; 11981da177e4SLinus Torvalds print " <variablelist>\n"; 11991da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 12001da177e4SLinus Torvalds my $parameter_name = $parameter; 12011da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 12021da177e4SLinus Torvalds 12031da177e4SLinus Torvalds print " <varlistentry>"; 12041da177e4SLinus Torvalds print " <term>$parameter</term>\n"; 12051da177e4SLinus Torvalds print " <listitem><para>\n"; 12061da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 12071da177e4SLinus Torvalds print " </para></listitem>\n"; 12081da177e4SLinus Torvalds print " </varlistentry>\n"; 12091da177e4SLinus Torvalds } 12101da177e4SLinus Torvalds print " </variablelist>\n"; 12111da177e4SLinus Torvalds print "</refsect1>\n"; 12121da177e4SLinus Torvalds 12131da177e4SLinus Torvalds output_section_xml(@_); 12141da177e4SLinus Torvalds 12151da177e4SLinus Torvalds print "</refentry>\n\n"; 12161da177e4SLinus Torvalds} 12171da177e4SLinus Torvalds 12181da177e4SLinus Torvalds# output typedef in XML DocBook 12191da177e4SLinus Torvaldssub output_typedef_xml(%) { 12201da177e4SLinus Torvalds my %args = %{$_[0]}; 12211da177e4SLinus Torvalds my ($parameter, $section); 12221da177e4SLinus Torvalds my $id; 12231da177e4SLinus Torvalds 12241da177e4SLinus Torvalds $id = "API-typedef-" . $args{'typedef'}; 12251da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12261da177e4SLinus Torvalds 12275449bc94SPavel Pisa print "<refentry id=\"$id\">\n"; 12288b0c2d98SMartin Waitz print "<refentryinfo>\n"; 12298b0c2d98SMartin Waitz print " <title>LINUX</title>\n"; 12308b0c2d98SMartin Waitz print " <productname>Kernel Hackers Manual</productname>\n"; 12318b0c2d98SMartin Waitz print " <date>$man_date</date>\n"; 12328b0c2d98SMartin Waitz print "</refentryinfo>\n"; 12331da177e4SLinus Torvalds print "<refmeta>\n"; 12345449bc94SPavel Pisa print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; 12358b0c2d98SMartin Waitz print " <manvolnum>9</manvolnum>\n"; 12361da177e4SLinus Torvalds print "</refmeta>\n"; 12371da177e4SLinus Torvalds print "<refnamediv>\n"; 12381da177e4SLinus Torvalds print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; 12391da177e4SLinus Torvalds print " <refpurpose>\n"; 12401da177e4SLinus Torvalds print " "; 12411da177e4SLinus Torvalds output_highlight ($args{'purpose'}); 12421da177e4SLinus Torvalds print " </refpurpose>\n"; 12431da177e4SLinus Torvalds print "</refnamediv>\n"; 12441da177e4SLinus Torvalds 12451da177e4SLinus Torvalds print "<refsynopsisdiv>\n"; 12461da177e4SLinus Torvalds print " <title>Synopsis</title>\n"; 12471da177e4SLinus Torvalds print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; 12481da177e4SLinus Torvalds print "</refsynopsisdiv>\n"; 12491da177e4SLinus Torvalds 12501da177e4SLinus Torvalds output_section_xml(@_); 12511da177e4SLinus Torvalds 12521da177e4SLinus Torvalds print "</refentry>\n\n"; 12531da177e4SLinus Torvalds} 12541da177e4SLinus Torvalds 12551da177e4SLinus Torvalds# output in XML DocBook 1256b112e0f7SJohannes Bergsub output_blockhead_xml(%) { 12571da177e4SLinus Torvalds my %args = %{$_[0]}; 12581da177e4SLinus Torvalds my ($parameter, $section); 12591da177e4SLinus Torvalds my $count; 12601da177e4SLinus Torvalds 12611da177e4SLinus Torvalds my $id = $args{'module'}; 12621da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 12631da177e4SLinus Torvalds 12641da177e4SLinus Torvalds # print out each section 12651da177e4SLinus Torvalds $lineprefix=" "; 12661da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 1267b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1268b112e0f7SJohannes Berg print "<refsect1>\n <title>$section</title>\n"; 1269b112e0f7SJohannes Berg } 12701da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 12711da177e4SLinus Torvalds print "<example><para>\n"; 1272e314ba31SDaniel Santos $output_preformatted = 1; 1273b112e0f7SJohannes Berg } else { 1274b112e0f7SJohannes Berg print "<para>\n"; 12751da177e4SLinus Torvalds } 12761da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1277e314ba31SDaniel Santos $output_preformatted = 0; 12781da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 12791da177e4SLinus Torvalds print "</para></example>\n"; 1280b112e0f7SJohannes Berg } else { 1281b112e0f7SJohannes Berg print "</para>"; 12821da177e4SLinus Torvalds } 1283b112e0f7SJohannes Berg if (!$args{'content-only'}) { 1284b112e0f7SJohannes Berg print "\n</refsect1>\n"; 1285b112e0f7SJohannes Berg } 12861da177e4SLinus Torvalds } 12871da177e4SLinus Torvalds 12881da177e4SLinus Torvalds print "\n\n"; 12891da177e4SLinus Torvalds} 12901da177e4SLinus Torvalds 12911da177e4SLinus Torvalds# output in XML DocBook 12921da177e4SLinus Torvaldssub output_function_gnome { 12931da177e4SLinus Torvalds my %args = %{$_[0]}; 12941da177e4SLinus Torvalds my ($parameter, $section); 12951da177e4SLinus Torvalds my $count; 12961da177e4SLinus Torvalds my $id; 12971da177e4SLinus Torvalds 12981da177e4SLinus Torvalds $id = $args{'module'} . "-" . $args{'function'}; 12991da177e4SLinus Torvalds $id =~ s/[^A-Za-z0-9]/-/g; 13001da177e4SLinus Torvalds 13011da177e4SLinus Torvalds print "<sect2>\n"; 13021da177e4SLinus Torvalds print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; 13031da177e4SLinus Torvalds 13041da177e4SLinus Torvalds print " <funcsynopsis>\n"; 13051da177e4SLinus Torvalds print " <funcdef>" . $args{'functiontype'} . " "; 13061da177e4SLinus Torvalds print "<function>" . $args{'function'} . " "; 13071da177e4SLinus Torvalds print "</function></funcdef>\n"; 13081da177e4SLinus Torvalds 13091da177e4SLinus Torvalds $count = 0; 13101da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 13111da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13121da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 13131da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 13141da177e4SLinus Torvalds # pointer-to-function 13151da177e4SLinus Torvalds print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; 13161da177e4SLinus Torvalds print " <funcparams>$2</funcparams></paramdef>\n"; 13171da177e4SLinus Torvalds } else { 13181da177e4SLinus Torvalds print " <paramdef>" . $type; 13191da177e4SLinus Torvalds print " <parameter>$parameter</parameter></paramdef>\n"; 13201da177e4SLinus Torvalds } 13211da177e4SLinus Torvalds } 13221da177e4SLinus Torvalds } else { 13231da177e4SLinus Torvalds print " <void>\n"; 13241da177e4SLinus Torvalds } 13251da177e4SLinus Torvalds print " </funcsynopsis>\n"; 13261da177e4SLinus Torvalds if ($#{$args{'parameterlist'}} >= 0) { 13271da177e4SLinus Torvalds print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; 13281da177e4SLinus Torvalds print "<tgroup cols=\"2\">\n"; 13291da177e4SLinus Torvalds print "<colspec colwidth=\"2*\">\n"; 13301da177e4SLinus Torvalds print "<colspec colwidth=\"8*\">\n"; 13311da177e4SLinus Torvalds print "<tbody>\n"; 13321da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 13331da177e4SLinus Torvalds my $parameter_name = $parameter; 13341da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 13351da177e4SLinus Torvalds 13361da177e4SLinus Torvalds print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; 13371da177e4SLinus Torvalds print " <entry>\n"; 13381da177e4SLinus Torvalds $lineprefix=" "; 13391da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 13401da177e4SLinus Torvalds print " </entry></row>\n"; 13411da177e4SLinus Torvalds } 13421da177e4SLinus Torvalds print " </tbody></tgroup></informaltable>\n"; 13431da177e4SLinus Torvalds } else { 13441da177e4SLinus Torvalds print " <para>\n None\n </para>\n"; 13451da177e4SLinus Torvalds } 13461da177e4SLinus Torvalds 13471da177e4SLinus Torvalds # print out each section 13481da177e4SLinus Torvalds $lineprefix=" "; 13491da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 13501da177e4SLinus Torvalds print "<simplesect>\n <title>$section</title>\n"; 13511da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13521da177e4SLinus Torvalds print "<example><programlisting>\n"; 1353e314ba31SDaniel Santos $output_preformatted = 1; 13541da177e4SLinus Torvalds } else { 13551da177e4SLinus Torvalds } 13561da177e4SLinus Torvalds print "<para>\n"; 13571da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 1358e314ba31SDaniel Santos $output_preformatted = 0; 13591da177e4SLinus Torvalds print "</para>\n"; 13601da177e4SLinus Torvalds if ($section =~ m/EXAMPLE/i) { 13611da177e4SLinus Torvalds print "</programlisting></example>\n"; 13621da177e4SLinus Torvalds } else { 13631da177e4SLinus Torvalds } 13641da177e4SLinus Torvalds print " </simplesect>\n"; 13651da177e4SLinus Torvalds } 13661da177e4SLinus Torvalds 13671da177e4SLinus Torvalds print "</sect2>\n\n"; 13681da177e4SLinus Torvalds} 13691da177e4SLinus Torvalds 13701da177e4SLinus Torvalds## 13711da177e4SLinus Torvalds# output function in man 13721da177e4SLinus Torvaldssub output_function_man(%) { 13731da177e4SLinus Torvalds my %args = %{$_[0]}; 13741da177e4SLinus Torvalds my ($parameter, $section); 13751da177e4SLinus Torvalds my $count; 13761da177e4SLinus Torvalds 13771da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 13781da177e4SLinus Torvalds 13791da177e4SLinus Torvalds print ".SH NAME\n"; 13801da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 13811da177e4SLinus Torvalds 13821da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 1383a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 13841da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 1385a21217daSRandy Dunlap } else { 1386a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 1387a21217daSRandy Dunlap } 13881da177e4SLinus Torvalds $count = 0; 13891da177e4SLinus Torvalds my $parenth = "("; 13901da177e4SLinus Torvalds my $post = ","; 13911da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 13921da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 13931da177e4SLinus Torvalds $post = ");"; 13941da177e4SLinus Torvalds } 13951da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 13961da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 13971da177e4SLinus Torvalds # pointer-to-function 13981da177e4SLinus Torvalds print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 13991da177e4SLinus Torvalds } else { 14001da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 14011da177e4SLinus Torvalds print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 14021da177e4SLinus Torvalds } 14031da177e4SLinus Torvalds $count++; 14041da177e4SLinus Torvalds $parenth = ""; 14051da177e4SLinus Torvalds } 14061da177e4SLinus Torvalds 14071da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 14081da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14091da177e4SLinus Torvalds my $parameter_name = $parameter; 14101da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14111da177e4SLinus Torvalds 14121da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 14131da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14141da177e4SLinus Torvalds } 14151da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14161da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 14171da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 14181da177e4SLinus Torvalds } 14191da177e4SLinus Torvalds} 14201da177e4SLinus Torvalds 14211da177e4SLinus Torvalds## 14221da177e4SLinus Torvalds# output enum in man 14231da177e4SLinus Torvaldssub output_enum_man(%) { 14241da177e4SLinus Torvalds my %args = %{$_[0]}; 14251da177e4SLinus Torvalds my ($parameter, $section); 14261da177e4SLinus Torvalds my $count; 14271da177e4SLinus Torvalds 14281da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 14291da177e4SLinus Torvalds 14301da177e4SLinus Torvalds print ".SH NAME\n"; 14311da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 14321da177e4SLinus Torvalds 14331da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 14341da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 14351da177e4SLinus Torvalds $count = 0; 14361da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 14371da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 14381da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 14391da177e4SLinus Torvalds print "\n};\n"; 14401da177e4SLinus Torvalds last; 14411da177e4SLinus Torvalds } 14421da177e4SLinus Torvalds else { 14431da177e4SLinus Torvalds print ", \n.br\n"; 14441da177e4SLinus Torvalds } 14451da177e4SLinus Torvalds $count++; 14461da177e4SLinus Torvalds } 14471da177e4SLinus Torvalds 14481da177e4SLinus Torvalds print ".SH Constants\n"; 14491da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 14501da177e4SLinus Torvalds my $parameter_name = $parameter; 14511da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14521da177e4SLinus Torvalds 14531da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 14541da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 14551da177e4SLinus Torvalds } 14561da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 14571da177e4SLinus Torvalds print ".SH \"$section\"\n"; 14581da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 14591da177e4SLinus Torvalds } 14601da177e4SLinus Torvalds} 14611da177e4SLinus Torvalds 14621da177e4SLinus Torvalds## 14631da177e4SLinus Torvalds# output struct in man 14641da177e4SLinus Torvaldssub output_struct_man(%) { 14651da177e4SLinus Torvalds my %args = %{$_[0]}; 14661da177e4SLinus Torvalds my ($parameter, $section); 14671da177e4SLinus Torvalds 14681da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 14691da177e4SLinus Torvalds 14701da177e4SLinus Torvalds print ".SH NAME\n"; 14711da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 14721da177e4SLinus Torvalds 14731da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 14741da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 14751da177e4SLinus Torvalds 14761da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 14771da177e4SLinus Torvalds if ($parameter =~ /^#/) { 14781da177e4SLinus Torvalds print ".BI \"$parameter\"\n.br\n"; 14791da177e4SLinus Torvalds next; 14801da177e4SLinus Torvalds } 14811da177e4SLinus Torvalds my $parameter_name = $parameter; 14821da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 14831da177e4SLinus Torvalds 14841da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 14851da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 14861da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 14871da177e4SLinus Torvalds # pointer-to-function 14881da177e4SLinus Torvalds print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; 14891da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 14901d7e1d45SRandy.Dunlap # bitfield 14911d7e1d45SRandy.Dunlap print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; 14921da177e4SLinus Torvalds } else { 14931da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 14941da177e4SLinus Torvalds print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; 14951da177e4SLinus Torvalds } 14961da177e4SLinus Torvalds print "\n.br\n"; 14971da177e4SLinus Torvalds } 14981da177e4SLinus Torvalds print "};\n.br\n"; 14991da177e4SLinus Torvalds 1500c51d3dacSRandy Dunlap print ".SH Members\n"; 15011da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15021da177e4SLinus Torvalds ($parameter =~ /^#/) && 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 print ".IP \"" . $parameter . "\" 12\n"; 15091da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 15101da177e4SLinus Torvalds } 15111da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15121da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15131da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15141da177e4SLinus Torvalds } 15151da177e4SLinus Torvalds} 15161da177e4SLinus Torvalds 15171da177e4SLinus Torvalds## 15181da177e4SLinus Torvalds# output typedef in man 15191da177e4SLinus Torvaldssub output_typedef_man(%) { 15201da177e4SLinus Torvalds my %args = %{$_[0]}; 15211da177e4SLinus Torvalds my ($parameter, $section); 15221da177e4SLinus Torvalds 15231da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 15241da177e4SLinus Torvalds 15251da177e4SLinus Torvalds print ".SH NAME\n"; 15261da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 15271da177e4SLinus Torvalds 15281da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15291da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15301da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15311da177e4SLinus Torvalds } 15321da177e4SLinus Torvalds} 15331da177e4SLinus Torvalds 1534b112e0f7SJohannes Bergsub output_blockhead_man(%) { 15351da177e4SLinus Torvalds my %args = %{$_[0]}; 15361da177e4SLinus Torvalds my ($parameter, $section); 15371da177e4SLinus Torvalds my $count; 15381da177e4SLinus Torvalds 15391da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 15401da177e4SLinus Torvalds 15411da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 15421da177e4SLinus Torvalds print ".SH \"$section\"\n"; 15431da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 15441da177e4SLinus Torvalds } 15451da177e4SLinus Torvalds} 15461da177e4SLinus Torvalds 15471da177e4SLinus Torvalds## 15481da177e4SLinus Torvalds# output in text 15491da177e4SLinus Torvaldssub output_function_text(%) { 15501da177e4SLinus Torvalds my %args = %{$_[0]}; 15511da177e4SLinus Torvalds my ($parameter, $section); 1552a21217daSRandy Dunlap my $start; 15531da177e4SLinus Torvalds 1554f47634b2SRandy Dunlap print "Name:\n\n"; 1555f47634b2SRandy Dunlap print $args{'function'} . " - " . $args{'purpose'} . "\n"; 1556f47634b2SRandy Dunlap 1557f47634b2SRandy Dunlap print "\nSynopsis:\n\n"; 1558a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 1559a21217daSRandy Dunlap $start = $args{'functiontype'} . " " . $args{'function'} . " ("; 1560a21217daSRandy Dunlap } else { 1561a21217daSRandy Dunlap $start = $args{'function'} . " ("; 1562a21217daSRandy Dunlap } 15631da177e4SLinus Torvalds print $start; 1564a21217daSRandy Dunlap 15651da177e4SLinus Torvalds my $count = 0; 15661da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 15671da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 15681da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 15691da177e4SLinus Torvalds # pointer-to-function 15701da177e4SLinus Torvalds print $1 . $parameter . ") (" . $2; 15711da177e4SLinus Torvalds } else { 15721da177e4SLinus Torvalds print $type . " " . $parameter; 15731da177e4SLinus Torvalds } 15741da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 15751da177e4SLinus Torvalds $count++; 15761da177e4SLinus Torvalds print ",\n"; 15771da177e4SLinus Torvalds print " " x length($start); 15781da177e4SLinus Torvalds } else { 15791da177e4SLinus Torvalds print ");\n\n"; 15801da177e4SLinus Torvalds } 15811da177e4SLinus Torvalds } 15821da177e4SLinus Torvalds 15831da177e4SLinus Torvalds print "Arguments:\n\n"; 15841da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 15851da177e4SLinus Torvalds my $parameter_name = $parameter; 15861da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 15871da177e4SLinus Torvalds 15881da177e4SLinus Torvalds print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; 15891da177e4SLinus Torvalds } 15901da177e4SLinus Torvalds output_section_text(@_); 15911da177e4SLinus Torvalds} 15921da177e4SLinus Torvalds 15931da177e4SLinus Torvalds#output sections in text 15941da177e4SLinus Torvaldssub output_section_text(%) { 15951da177e4SLinus Torvalds my %args = %{$_[0]}; 15961da177e4SLinus Torvalds my $section; 15971da177e4SLinus Torvalds 15981da177e4SLinus Torvalds print "\n"; 15991da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16001da177e4SLinus Torvalds print "$section:\n\n"; 16011da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16021da177e4SLinus Torvalds } 16031da177e4SLinus Torvalds print "\n\n"; 16041da177e4SLinus Torvalds} 16051da177e4SLinus Torvalds 16061da177e4SLinus Torvalds# output enum in text 16071da177e4SLinus Torvaldssub output_enum_text(%) { 16081da177e4SLinus Torvalds my %args = %{$_[0]}; 16091da177e4SLinus Torvalds my ($parameter); 16101da177e4SLinus Torvalds my $count; 16111da177e4SLinus Torvalds print "Enum:\n\n"; 16121da177e4SLinus Torvalds 16131d7e1d45SRandy.Dunlap print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; 16141da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 16151da177e4SLinus Torvalds $count = 0; 16161da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16171da177e4SLinus Torvalds print "\t$parameter"; 16181da177e4SLinus Torvalds if ($count != $#{$args{'parameterlist'}}) { 16191da177e4SLinus Torvalds $count++; 16201da177e4SLinus Torvalds print ","; 16211da177e4SLinus Torvalds } 16221da177e4SLinus Torvalds print "\n"; 16231da177e4SLinus Torvalds } 16241da177e4SLinus Torvalds print "};\n\n"; 16251da177e4SLinus Torvalds 16261da177e4SLinus Torvalds print "Constants:\n\n"; 16271da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16281da177e4SLinus Torvalds print "$parameter\n\t"; 16291da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter} . "\n"; 16301da177e4SLinus Torvalds } 16311da177e4SLinus Torvalds 16321da177e4SLinus Torvalds output_section_text(@_); 16331da177e4SLinus Torvalds} 16341da177e4SLinus Torvalds 16351da177e4SLinus Torvalds# output typedef in text 16361da177e4SLinus Torvaldssub output_typedef_text(%) { 16371da177e4SLinus Torvalds my %args = %{$_[0]}; 16381da177e4SLinus Torvalds my ($parameter); 16391da177e4SLinus Torvalds my $count; 16401da177e4SLinus Torvalds print "Typedef:\n\n"; 16411da177e4SLinus Torvalds 16421d7e1d45SRandy.Dunlap print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; 16431da177e4SLinus Torvalds output_section_text(@_); 16441da177e4SLinus Torvalds} 16451da177e4SLinus Torvalds 16461da177e4SLinus Torvalds# output struct as text 16471da177e4SLinus Torvaldssub output_struct_text(%) { 16481da177e4SLinus Torvalds my %args = %{$_[0]}; 16491da177e4SLinus Torvalds my ($parameter); 16501da177e4SLinus Torvalds 16511d7e1d45SRandy.Dunlap print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; 16521da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n"; 16531da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16541da177e4SLinus Torvalds if ($parameter =~ /^#/) { 16551da177e4SLinus Torvalds print "$parameter\n"; 16561da177e4SLinus Torvalds next; 16571da177e4SLinus Torvalds } 16581da177e4SLinus Torvalds 16591da177e4SLinus Torvalds my $parameter_name = $parameter; 16601da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16611da177e4SLinus Torvalds 16621da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 16631da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 16641da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 16651da177e4SLinus Torvalds # pointer-to-function 16661da177e4SLinus Torvalds print "\t$1 $parameter) ($2);\n"; 16671da177e4SLinus Torvalds } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 166851f5a0c8SRandy Dunlap # bitfield 16691da177e4SLinus Torvalds print "\t$1 $parameter$2;\n"; 16701da177e4SLinus Torvalds } else { 16711da177e4SLinus Torvalds print "\t" . $type . " " . $parameter . ";\n"; 16721da177e4SLinus Torvalds } 16731da177e4SLinus Torvalds } 16741da177e4SLinus Torvalds print "};\n\n"; 16751da177e4SLinus Torvalds 16761da177e4SLinus Torvalds print "Members:\n\n"; 16771da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 16781da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 16791da177e4SLinus Torvalds 16801da177e4SLinus Torvalds my $parameter_name = $parameter; 16811da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 16821da177e4SLinus Torvalds 16831da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 16841da177e4SLinus Torvalds print "$parameter\n\t"; 16851da177e4SLinus Torvalds print $args{'parameterdescs'}{$parameter_name} . "\n"; 16861da177e4SLinus Torvalds } 16871da177e4SLinus Torvalds print "\n"; 16881da177e4SLinus Torvalds output_section_text(@_); 16891da177e4SLinus Torvalds} 16901da177e4SLinus Torvalds 1691b112e0f7SJohannes Bergsub output_blockhead_text(%) { 16921da177e4SLinus Torvalds my %args = %{$_[0]}; 16931da177e4SLinus Torvalds my ($parameter, $section); 16941da177e4SLinus Torvalds 16951da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 16961da177e4SLinus Torvalds print " $section:\n"; 16971da177e4SLinus Torvalds print " -> "; 16981da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 16991da177e4SLinus Torvalds } 17001da177e4SLinus Torvalds} 17011da177e4SLinus Torvalds 1702eda603f6SJohannes Berg## list mode output functions 1703eda603f6SJohannes Berg 1704eda603f6SJohannes Bergsub output_function_list(%) { 1705eda603f6SJohannes Berg my %args = %{$_[0]}; 1706eda603f6SJohannes Berg 1707eda603f6SJohannes Berg print $args{'function'} . "\n"; 1708eda603f6SJohannes Berg} 1709eda603f6SJohannes Berg 1710eda603f6SJohannes Berg# output enum in list 1711eda603f6SJohannes Bergsub output_enum_list(%) { 1712eda603f6SJohannes Berg my %args = %{$_[0]}; 1713eda603f6SJohannes Berg print $args{'enum'} . "\n"; 1714eda603f6SJohannes Berg} 1715eda603f6SJohannes Berg 1716eda603f6SJohannes Berg# output typedef in list 1717eda603f6SJohannes Bergsub output_typedef_list(%) { 1718eda603f6SJohannes Berg my %args = %{$_[0]}; 1719eda603f6SJohannes Berg print $args{'typedef'} . "\n"; 1720eda603f6SJohannes Berg} 1721eda603f6SJohannes Berg 1722eda603f6SJohannes Berg# output struct as list 1723eda603f6SJohannes Bergsub output_struct_list(%) { 1724eda603f6SJohannes Berg my %args = %{$_[0]}; 1725eda603f6SJohannes Berg 1726eda603f6SJohannes Berg print $args{'struct'} . "\n"; 1727eda603f6SJohannes Berg} 1728eda603f6SJohannes Berg 1729eda603f6SJohannes Bergsub output_blockhead_list(%) { 1730eda603f6SJohannes Berg my %args = %{$_[0]}; 1731eda603f6SJohannes Berg my ($parameter, $section); 1732eda603f6SJohannes Berg 1733eda603f6SJohannes Berg foreach $section (@{$args{'sectionlist'}}) { 1734eda603f6SJohannes Berg print "DOC: $section\n"; 1735eda603f6SJohannes Berg } 1736eda603f6SJohannes Berg} 1737eda603f6SJohannes Berg 17381da177e4SLinus Torvalds## 173927205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 174027205744SRandy Dunlap# calls the generated, variable output_ function name based on 174127205744SRandy Dunlap# functype and output_mode 17421da177e4SLinus Torvaldssub output_declaration { 17431da177e4SLinus Torvalds no strict 'refs'; 17441da177e4SLinus Torvalds my $name = shift; 17451da177e4SLinus Torvalds my $functype = shift; 17461da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 17471da177e4SLinus Torvalds if (($function_only==0) || 17481da177e4SLinus Torvalds ( $function_only == 1 && defined($function_table{$name})) || 174923aebb3cSDanilo Cesar Lemes de Paula ( $function_only == 2 && !($functype eq "function" && defined($function_table{$name})))) 17501da177e4SLinus Torvalds { 17511da177e4SLinus Torvalds &$func(@_); 17521da177e4SLinus Torvalds $section_counter++; 17531da177e4SLinus Torvalds } 17541da177e4SLinus Torvalds} 17551da177e4SLinus Torvalds 17561da177e4SLinus Torvalds## 175727205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 1758b112e0f7SJohannes Bergsub output_blockhead { 17591da177e4SLinus Torvalds no strict 'refs'; 1760b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 17611da177e4SLinus Torvalds &$func(@_); 17621da177e4SLinus Torvalds $section_counter++; 17631da177e4SLinus Torvalds} 17641da177e4SLinus Torvalds 17651da177e4SLinus Torvalds## 17661da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 17671da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 17681da177e4SLinus Torvaldssub dump_declaration($$) { 17691da177e4SLinus Torvalds no strict 'refs'; 17701da177e4SLinus Torvalds my ($prototype, $file) = @_; 17711da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 17721da177e4SLinus Torvalds &$func(@_); 17731da177e4SLinus Torvalds} 17741da177e4SLinus Torvalds 17751da177e4SLinus Torvaldssub dump_union($$) { 17761da177e4SLinus Torvalds dump_struct(@_); 17771da177e4SLinus Torvalds} 17781da177e4SLinus Torvalds 17791da177e4SLinus Torvaldssub dump_struct($$) { 17801da177e4SLinus Torvalds my $x = shift; 17811da177e4SLinus Torvalds my $file = shift; 1782a1d94aa5SRandy Dunlap my $nested; 17831da177e4SLinus Torvalds 17841da177e4SLinus Torvalds if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 178552dc5aecSRandy Dunlap #my $decl_type = $1; 17861da177e4SLinus Torvalds $declaration_name = $2; 17871da177e4SLinus Torvalds my $members = $3; 17881da177e4SLinus Torvalds 17891da177e4SLinus Torvalds # ignore embedded structs or unions 1790a1d94aa5SRandy Dunlap $members =~ s/({.*})//g; 1791a1d94aa5SRandy Dunlap $nested = $1; 17921da177e4SLinus Torvalds 1793aeec46b9SMartin Waitz # ignore members marked private: 179452dc5aecSRandy Dunlap $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gos; 179552dc5aecSRandy Dunlap $members =~ s/\/\*\s*private:.*//gos; 1796aeec46b9SMartin Waitz # strip comments: 1797aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 1798a1d94aa5SRandy Dunlap $nested =~ s/\/\*.*?\*\///gos; 1799d960eea9SRandy Dunlap # strip kmemcheck_bitfield_{begin,end}.*; 1800d960eea9SRandy Dunlap $members =~ s/kmemcheck_bitfield_.*?;//gos; 1801ef5da59fSRandy Dunlap # strip attributes 1802f0074929SJonathan Corbet $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 18037b990789SJohannes Berg $members =~ s/__aligned\s*\([^;]*\)//gos; 1804f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; 1805aeec46b9SMartin Waitz 18061da177e4SLinus Torvalds create_parameterlist($members, ';', $file); 1807a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); 18081da177e4SLinus Torvalds 18091da177e4SLinus Torvalds output_declaration($declaration_name, 18101da177e4SLinus Torvalds 'struct', 18111da177e4SLinus Torvalds {'struct' => $declaration_name, 18121da177e4SLinus Torvalds 'module' => $modulename, 18131da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 18141da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 18151da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 18161da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 18171da177e4SLinus Torvalds 'sections' => \%sections, 18181da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 18191da177e4SLinus Torvalds 'type' => $decl_type 18201da177e4SLinus Torvalds }); 18211da177e4SLinus Torvalds } 18221da177e4SLinus Torvalds else { 1823d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 18241da177e4SLinus Torvalds ++$errors; 18251da177e4SLinus Torvalds } 18261da177e4SLinus Torvalds} 18271da177e4SLinus Torvalds 18281da177e4SLinus Torvaldssub dump_enum($$) { 18291da177e4SLinus Torvalds my $x = shift; 18301da177e4SLinus Torvalds my $file = shift; 18311da177e4SLinus Torvalds 1832aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 1833b6d676dbSRandy Dunlap $x =~ s/^#\s*define\s+.*$//; # strip #define macros inside enums 1834b6d676dbSRandy Dunlap 18351da177e4SLinus Torvalds if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 18361da177e4SLinus Torvalds $declaration_name = $1; 18371da177e4SLinus Torvalds my $members = $2; 18381da177e4SLinus Torvalds 18391da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 18401da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 18411da177e4SLinus Torvalds push @parameterlist, $arg; 18421da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 18431da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 1844d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Enum value '$arg' ". 18451da177e4SLinus Torvalds "not described in enum '$declaration_name'\n"; 18461da177e4SLinus Torvalds } 18471da177e4SLinus Torvalds 18481da177e4SLinus Torvalds } 18491da177e4SLinus Torvalds 18501da177e4SLinus Torvalds output_declaration($declaration_name, 18511da177e4SLinus Torvalds 'enum', 18521da177e4SLinus Torvalds {'enum' => $declaration_name, 18531da177e4SLinus Torvalds 'module' => $modulename, 18541da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 18551da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 18561da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 18571da177e4SLinus Torvalds 'sections' => \%sections, 18581da177e4SLinus Torvalds 'purpose' => $declaration_purpose 18591da177e4SLinus Torvalds }); 18601da177e4SLinus Torvalds } 18611da177e4SLinus Torvalds else { 1862d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 18631da177e4SLinus Torvalds ++$errors; 18641da177e4SLinus Torvalds } 18651da177e4SLinus Torvalds} 18661da177e4SLinus Torvalds 18671da177e4SLinus Torvaldssub dump_typedef($$) { 18681da177e4SLinus Torvalds my $x = shift; 18691da177e4SLinus Torvalds my $file = shift; 18701da177e4SLinus Torvalds 1871aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 18721da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 18731da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 18741da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 18751da177e4SLinus Torvalds } 18761da177e4SLinus Torvalds 18771da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 18781da177e4SLinus Torvalds $declaration_name = $1; 18791da177e4SLinus Torvalds 18801da177e4SLinus Torvalds output_declaration($declaration_name, 18811da177e4SLinus Torvalds 'typedef', 18821da177e4SLinus Torvalds {'typedef' => $declaration_name, 18831da177e4SLinus Torvalds 'module' => $modulename, 18841da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 18851da177e4SLinus Torvalds 'sections' => \%sections, 18861da177e4SLinus Torvalds 'purpose' => $declaration_purpose 18871da177e4SLinus Torvalds }); 18881da177e4SLinus Torvalds } 18891da177e4SLinus Torvalds else { 1890d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 18911da177e4SLinus Torvalds ++$errors; 18921da177e4SLinus Torvalds } 18931da177e4SLinus Torvalds} 18941da177e4SLinus Torvalds 1895a1d94aa5SRandy Dunlapsub save_struct_actual($) { 1896a1d94aa5SRandy Dunlap my $actual = shift; 1897a1d94aa5SRandy Dunlap 1898a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 1899a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 1900a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 1901a1d94aa5SRandy Dunlap} 1902a1d94aa5SRandy Dunlap 19031da177e4SLinus Torvaldssub create_parameterlist($$$) { 19041da177e4SLinus Torvalds my $args = shift; 19051da177e4SLinus Torvalds my $splitter = shift; 19061da177e4SLinus Torvalds my $file = shift; 19071da177e4SLinus Torvalds my $type; 19081da177e4SLinus Torvalds my $param; 19091da177e4SLinus Torvalds 1910a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 19111da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 19121da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 19131da177e4SLinus Torvalds } 19141da177e4SLinus Torvalds 19151da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 19161da177e4SLinus Torvalds # strip comments 19171da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 19181da177e4SLinus Torvalds # strip leading/trailing spaces 19191da177e4SLinus Torvalds $arg =~ s/^\s*//; 19201da177e4SLinus Torvalds $arg =~ s/\s*$//; 19211da177e4SLinus Torvalds $arg =~ s/\s+/ /; 19221da177e4SLinus Torvalds 19231da177e4SLinus Torvalds if ($arg =~ /^#/) { 19241da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 19251da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 19261da177e4SLinus Torvalds # output_* subs. 19271da177e4SLinus Torvalds push_parameter($arg, "", $file); 192800d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 19291da177e4SLinus Torvalds # pointer-to-function 19301da177e4SLinus Torvalds $arg =~ tr/#/,/; 193100d62961SRichard Kennedy $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 19321da177e4SLinus Torvalds $param = $1; 19331da177e4SLinus Torvalds $type = $arg; 193400d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1935a1d94aa5SRandy Dunlap save_struct_actual($param); 19361da177e4SLinus Torvalds push_parameter($param, $type, $file); 1937aeec46b9SMartin Waitz } elsif ($arg) { 19381da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 19391da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 19401da177e4SLinus Torvalds 19411da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 19421da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 19431da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 19441da177e4SLinus Torvalds } 1945884f2810SBorislav Petkov 1946884f2810SBorislav Petkov my @first_arg; 1947884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1948884f2810SBorislav Petkov shift @args; 1949884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 1950884f2810SBorislav Petkov push(@first_arg, $2); 1951884f2810SBorislav Petkov } else { 1952884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 1953884f2810SBorislav Petkov } 1954884f2810SBorislav Petkov 19551da177e4SLinus Torvalds unshift(@args, pop @first_arg); 19561da177e4SLinus Torvalds $type = join " ", @first_arg; 19571da177e4SLinus Torvalds 19581da177e4SLinus Torvalds foreach $param (@args) { 19591da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 1960a1d94aa5SRandy Dunlap save_struct_actual($2); 19611da177e4SLinus Torvalds push_parameter($2, "$type $1", $file); 19621da177e4SLinus Torvalds } 19631da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 19647b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 1965a1d94aa5SRandy Dunlap save_struct_actual($1); 19661da177e4SLinus Torvalds push_parameter($1, "$type:$2", $file) 19671da177e4SLinus Torvalds } 19687b97887eSRandy Dunlap } 19691da177e4SLinus Torvalds else { 1970a1d94aa5SRandy Dunlap save_struct_actual($param); 19711da177e4SLinus Torvalds push_parameter($param, $type, $file); 19721da177e4SLinus Torvalds } 19731da177e4SLinus Torvalds } 19741da177e4SLinus Torvalds } 19751da177e4SLinus Torvalds } 19761da177e4SLinus Torvalds} 19771da177e4SLinus Torvalds 19781da177e4SLinus Torvaldssub push_parameter($$$) { 19791da177e4SLinus Torvalds my $param = shift; 19801da177e4SLinus Torvalds my $type = shift; 19811da177e4SLinus Torvalds my $file = shift; 19821da177e4SLinus Torvalds 19835f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 19845f8c7c98SRandy Dunlap ($param eq "}")) { 19855f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 19865f8c7c98SRandy Dunlap } 19875f8c7c98SRandy Dunlap 19885f8c7c98SRandy Dunlap $anon_struct_union = 0; 19891da177e4SLinus Torvalds my $param_name = $param; 19901da177e4SLinus Torvalds $param_name =~ s/\[.*//; 19911da177e4SLinus Torvalds 1992a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 19931da177e4SLinus Torvalds { 1994ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1995a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 19961da177e4SLinus Torvalds } 1997ced69090SRandy Dunlap } 19981da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 19991da177e4SLinus Torvalds { 20001da177e4SLinus Torvalds $param="void"; 20011da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 20021da177e4SLinus Torvalds } 2003134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 2004134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 2005134fe01bSRandy Dunlap { 2006134fe01bSRandy Dunlap $type = $param; 2007134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 2008134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 20095f8c7c98SRandy Dunlap $anon_struct_union = 1; 2010134fe01bSRandy Dunlap } 2011134fe01bSRandy Dunlap 2012a6d3fe77SMartin Waitz # warn if parameter has no description 2013134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 2014134fe01bSRandy Dunlap # but inline preprocessor statements); 2015134fe01bSRandy Dunlap # also ignore unnamed structs/unions; 20165f8c7c98SRandy Dunlap if (!$anon_struct_union) { 2017a6d3fe77SMartin Waitz if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { 2018a6d3fe77SMartin Waitz 20191da177e4SLinus Torvalds $parameterdescs{$param_name} = $undescribed; 20201da177e4SLinus Torvalds 20211da177e4SLinus Torvalds if (($type eq 'function') || ($type eq 'enum')) { 2022d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Function parameter ". 20231da177e4SLinus Torvalds "or member '$param' not " . 20241da177e4SLinus Torvalds "described in '$declaration_name'\n"; 20251da177e4SLinus Torvalds } 2026d40e1e65SBart Van Assche print STDERR "${file}:$.: warning:" . 20271da177e4SLinus Torvalds " No description found for parameter '$param'\n"; 20281da177e4SLinus Torvalds ++$warnings; 20291da177e4SLinus Torvalds } 2030134fe01bSRandy Dunlap } 20311da177e4SLinus Torvalds 20322b35f4d9SRandy Dunlap $param = xml_escape($param); 20332b35f4d9SRandy Dunlap 203425985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 2035e34e7dbbSRandy Dunlap # on @parameterlist; 2036e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 2037e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 2038e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 2039e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 2040e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 2041e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 2042e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 20431da177e4SLinus Torvalds push @parameterlist, $param; 20441da177e4SLinus Torvalds $parametertypes{$param} = $type; 20451da177e4SLinus Torvalds} 20461da177e4SLinus Torvalds 2047a1d94aa5SRandy Dunlapsub check_sections($$$$$$) { 2048a1d94aa5SRandy Dunlap my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; 2049a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 2050a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 2051a1d94aa5SRandy Dunlap my $err; 2052a1d94aa5SRandy Dunlap my ($px, $sx); 2053a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 2054a1d94aa5SRandy Dunlap 2055a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 2056a1d94aa5SRandy Dunlap $err = 1; 2057a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 2058a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 2059a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 20601f3a6688SJohannes Berg $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 2061e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 2062e34e7dbbSRandy Dunlap # however, the original param string may contain 2063e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 2064e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 2065e34e7dbbSRandy Dunlap # parameter list is split at spaces; 2066e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 2067e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 2068e34e7dbbSRandy Dunlap 2069a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 2070a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 2071a1d94aa5SRandy Dunlap $err = 0; 2072a1d94aa5SRandy Dunlap last; 2073a1d94aa5SRandy Dunlap } 2074a1d94aa5SRandy Dunlap } 2075a1d94aa5SRandy Dunlap if ($err) { 2076a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 2077d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2078a1d94aa5SRandy Dunlap "Excess function parameter " . 2079a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2080a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2081a1d94aa5SRandy Dunlap ++$warnings; 2082a1d94aa5SRandy Dunlap } else { 2083a1d94aa5SRandy Dunlap if ($nested !~ m/\Q$sects[$sx]\E/) { 2084d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 2085a1d94aa5SRandy Dunlap "Excess struct/union/enum/typedef member " . 2086a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 2087a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 2088a1d94aa5SRandy Dunlap ++$warnings; 2089a1d94aa5SRandy Dunlap } 2090a1d94aa5SRandy Dunlap } 2091a1d94aa5SRandy Dunlap } 2092a1d94aa5SRandy Dunlap } 2093a1d94aa5SRandy Dunlap} 2094a1d94aa5SRandy Dunlap 20951da177e4SLinus Torvalds## 20964092bac7SYacine Belkadi# Checks the section describing the return value of a function. 20974092bac7SYacine Belkadisub check_return_section { 20984092bac7SYacine Belkadi my $file = shift; 20994092bac7SYacine Belkadi my $declaration_name = shift; 21004092bac7SYacine Belkadi my $return_type = shift; 21014092bac7SYacine Belkadi 21024092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 21034092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 21044092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 21054092bac7SYacine Belkadi return; 21064092bac7SYacine Belkadi } 21074092bac7SYacine Belkadi 21084092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 21094092bac7SYacine Belkadi $sections{$section_return} eq "") { 2110d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 21114092bac7SYacine Belkadi "No description found for return value of " . 21124092bac7SYacine Belkadi "'$declaration_name'\n"; 21134092bac7SYacine Belkadi ++$warnings; 21144092bac7SYacine Belkadi } 21154092bac7SYacine Belkadi} 21164092bac7SYacine Belkadi 21174092bac7SYacine Belkadi## 21181da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 21191da177e4SLinus Torvalds# processed and spits out all the details stored in the global 21201da177e4SLinus Torvalds# arrays/hashes. 21211da177e4SLinus Torvaldssub dump_function($$) { 21221da177e4SLinus Torvalds my $prototype = shift; 21231da177e4SLinus Torvalds my $file = shift; 2124cbb4d3e6SHoria Geanta my $noret = 0; 21251da177e4SLinus Torvalds 21261da177e4SLinus Torvalds $prototype =~ s/^static +//; 21271da177e4SLinus Torvalds $prototype =~ s/^extern +//; 21284dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 21291da177e4SLinus Torvalds $prototype =~ s/^inline +//; 21301da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 213132e79401SRandy Dunlap $prototype =~ s/^__inline +//; 213232e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 213332e79401SRandy Dunlap $prototype =~ s/^noinline +//; 213474fc5c65SRandy Dunlap $prototype =~ s/__init +//; 213520072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 2136270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 213770c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 21380df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 2139cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 2140328d2440SRandy Dunlap $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; 21411da177e4SLinus Torvalds 21421da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 21431da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 21441da177e4SLinus Torvalds # 2. Function name 21451da177e4SLinus Torvalds # 3. Function parameters. 21461da177e4SLinus Torvalds # 21471da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 21481da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 21491da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 21501da177e4SLinus Torvalds # so on. 21511da177e4SLinus Torvalds # 21521da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 21531da177e4SLinus Torvalds # the following functions' documentation still comes out right: 21541da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 21551da177e4SLinus Torvalds # - atomic_set (macro) 21569598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 21571da177e4SLinus Torvalds 2158cbb4d3e6SHoria Geanta if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 2159cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 2160cbb4d3e6SHoria Geanta # list. 2161cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 2162cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 2163cbb4d3e6SHoria Geanta $return_type = $1; 2164cbb4d3e6SHoria Geanta $declaration_name = $2; 2165cbb4d3e6SHoria Geanta $noret = 1; 2166cbb4d3e6SHoria Geanta } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21671da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21681da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21691da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 217094b3e03cSRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21711da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21721da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 21731da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21741da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21751da177e4SLinus Torvalds $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21761da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21771da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21781da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21799598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 21809598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2181412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 2182412ecd77SRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 21831da177e4SLinus Torvalds $return_type = $1; 21841da177e4SLinus Torvalds $declaration_name = $2; 21851da177e4SLinus Torvalds my $args = $3; 21861da177e4SLinus Torvalds 21871da177e4SLinus Torvalds create_parameterlist($args, ',', $file); 21881da177e4SLinus Torvalds } else { 2189d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 21901da177e4SLinus Torvalds return; 21911da177e4SLinus Torvalds } 21921da177e4SLinus Torvalds 2193a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 2194a1d94aa5SRandy Dunlap check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); 2195a1d94aa5SRandy Dunlap 21964092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 21974092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 21984092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 21994092bac7SYacine Belkadi # verbose mode. 22004092bac7SYacine Belkadi # TODO: always perform the check. 2201cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 22024092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 22034092bac7SYacine Belkadi } 22044092bac7SYacine Belkadi 22051da177e4SLinus Torvalds output_declaration($declaration_name, 22061da177e4SLinus Torvalds 'function', 22071da177e4SLinus Torvalds {'function' => $declaration_name, 22081da177e4SLinus Torvalds 'module' => $modulename, 22091da177e4SLinus Torvalds 'functiontype' => $return_type, 22101da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 22111da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 22121da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 22131da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 22141da177e4SLinus Torvalds 'sections' => \%sections, 22151da177e4SLinus Torvalds 'purpose' => $declaration_purpose 22161da177e4SLinus Torvalds }); 22171da177e4SLinus Torvalds} 22181da177e4SLinus Torvalds 22191da177e4SLinus Torvaldssub reset_state { 22201da177e4SLinus Torvalds $function = ""; 22211da177e4SLinus Torvalds %constants = (); 22221da177e4SLinus Torvalds %parameterdescs = (); 22231da177e4SLinus Torvalds %parametertypes = (); 22241da177e4SLinus Torvalds @parameterlist = (); 22251da177e4SLinus Torvalds %sections = (); 22261da177e4SLinus Torvalds @sectionlist = (); 2227a1d94aa5SRandy Dunlap $sectcheck = ""; 2228a1d94aa5SRandy Dunlap $struct_actual = ""; 22291da177e4SLinus Torvalds $prototype = ""; 22301da177e4SLinus Torvalds 22311da177e4SLinus Torvalds $state = 0; 2232a4c6ebedSDanilo Cesar Lemes de Paula $split_doc_state = 0; 22331da177e4SLinus Torvalds} 22341da177e4SLinus Torvalds 223556afb0f8SJason Baronsub tracepoint_munge($) { 223656afb0f8SJason Baron my $file = shift; 223756afb0f8SJason Baron my $tracepointname = 0; 223856afb0f8SJason Baron my $tracepointargs = 0; 223956afb0f8SJason Baron 224056afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 224156afb0f8SJason Baron $tracepointname = $1; 224256afb0f8SJason Baron } 22433a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 22443a9089fdSJason Baron $tracepointname = $1; 22453a9089fdSJason Baron } 22463a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 22473a9089fdSJason Baron $tracepointname = $2; 22483a9089fdSJason Baron } 22493a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 225056afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 225156afb0f8SJason Baron $tracepointargs = $1; 225256afb0f8SJason Baron } 225356afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 2254d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 225556afb0f8SJason Baron "$prototype\n"; 225656afb0f8SJason Baron } else { 225756afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 225856afb0f8SJason Baron } 225956afb0f8SJason Baron} 226056afb0f8SJason Baron 2261b4870bc5SRandy Dunlapsub syscall_munge() { 2262b4870bc5SRandy Dunlap my $void = 0; 2263b4870bc5SRandy Dunlap 2264b4870bc5SRandy Dunlap $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs 2265b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 2266b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 2267b4870bc5SRandy Dunlap $void = 1; 2268b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 2269b4870bc5SRandy Dunlap } 2270b4870bc5SRandy Dunlap 2271b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 2272b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 2273b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 2274b4870bc5SRandy Dunlap } elsif ($void) { 2275b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 2276b4870bc5SRandy Dunlap } 2277b4870bc5SRandy Dunlap 2278b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 2279b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 2280b4870bc5SRandy Dunlap my $count = 0; 2281b4870bc5SRandy Dunlap my $len = length($prototype); 2282b4870bc5SRandy Dunlap if ($void) { 2283b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 2284b4870bc5SRandy Dunlap } 2285b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 2286b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 2287b4870bc5SRandy Dunlap $count++; 2288b4870bc5SRandy Dunlap if ($count % 2 == 1) { 2289b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 2290b4870bc5SRandy Dunlap } 2291b4870bc5SRandy Dunlap } 2292b4870bc5SRandy Dunlap } 2293b4870bc5SRandy Dunlap} 2294b4870bc5SRandy Dunlap 22951da177e4SLinus Torvaldssub process_state3_function($$) { 22961da177e4SLinus Torvalds my $x = shift; 22971da177e4SLinus Torvalds my $file = shift; 22981da177e4SLinus Torvalds 229951f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 230051f5a0c8SRandy Dunlap 2301890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 23021da177e4SLinus Torvalds # do nothing 23031da177e4SLinus Torvalds } 23041da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 23051da177e4SLinus Torvalds $prototype .= $1; 23061da177e4SLinus Torvalds } 2307b4870bc5SRandy Dunlap 2308890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 23091da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 23101da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 23111da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 2312b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 2313b4870bc5SRandy Dunlap syscall_munge(); 2314b4870bc5SRandy Dunlap } 23153a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 23163a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 23173a9089fdSJason Baron { 231856afb0f8SJason Baron tracepoint_munge($file); 231956afb0f8SJason Baron } 23201da177e4SLinus Torvalds dump_function($prototype, $file); 23211da177e4SLinus Torvalds reset_state(); 23221da177e4SLinus Torvalds } 23231da177e4SLinus Torvalds} 23241da177e4SLinus Torvalds 23251da177e4SLinus Torvaldssub process_state3_type($$) { 23261da177e4SLinus Torvalds my $x = shift; 23271da177e4SLinus Torvalds my $file = shift; 23281da177e4SLinus Torvalds 23291da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 23301da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 23311da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 233251f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 233351f5a0c8SRandy Dunlap 23341da177e4SLinus Torvalds if ($x =~ /^#/) { 23351da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 23361da177e4SLinus Torvalds $x .= ";"; 23371da177e4SLinus Torvalds } 23381da177e4SLinus Torvalds 23391da177e4SLinus Torvalds while (1) { 23401da177e4SLinus Torvalds if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 23411da177e4SLinus Torvalds $prototype .= $1 . $2; 23421da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 23431da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 23441da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 23451da177e4SLinus Torvalds dump_declaration($prototype, $file); 23461da177e4SLinus Torvalds reset_state(); 23471da177e4SLinus Torvalds last; 23481da177e4SLinus Torvalds } 23491da177e4SLinus Torvalds $x = $3; 23501da177e4SLinus Torvalds } else { 23511da177e4SLinus Torvalds $prototype .= $x; 23521da177e4SLinus Torvalds last; 23531da177e4SLinus Torvalds } 23541da177e4SLinus Torvalds } 23551da177e4SLinus Torvalds} 23561da177e4SLinus Torvalds 23576b5b55f6SRandy Dunlap# xml_escape: replace <, >, and & in the text stream; 23586b5b55f6SRandy Dunlap# 23596b5b55f6SRandy Dunlap# however, formatting controls that are generated internally/locally in the 23606b5b55f6SRandy Dunlap# kernel-doc script are not escaped here; instead, they begin life like 23616b5b55f6SRandy Dunlap# $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings 23626b5b55f6SRandy Dunlap# are converted to their mnemonic-expected output, without the 4 * '\' & ':', 23636b5b55f6SRandy Dunlap# just before actual output; (this is done by local_unescape()) 23641da177e4SLinus Torvaldssub xml_escape($) { 23651da177e4SLinus Torvalds my $text = shift; 2366ecfb251aSRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 2367ecfb251aSRandy Dunlap return $text; 2368ecfb251aSRandy Dunlap } 23691da177e4SLinus Torvalds $text =~ s/\&/\\\\\\amp;/g; 23701da177e4SLinus Torvalds $text =~ s/\</\\\\\\lt;/g; 23711da177e4SLinus Torvalds $text =~ s/\>/\\\\\\gt;/g; 23721da177e4SLinus Torvalds return $text; 23731da177e4SLinus Torvalds} 23741da177e4SLinus Torvalds 23756b5b55f6SRandy Dunlap# convert local escape strings to html 23766b5b55f6SRandy Dunlap# local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) 23776b5b55f6SRandy Dunlapsub local_unescape($) { 23786b5b55f6SRandy Dunlap my $text = shift; 23796b5b55f6SRandy Dunlap if (($output_mode eq "text") || ($output_mode eq "man")) { 23806b5b55f6SRandy Dunlap return $text; 23816b5b55f6SRandy Dunlap } 23826b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\lt:/</g; 23836b5b55f6SRandy Dunlap $text =~ s/\\\\\\\\gt:/>/g; 23846b5b55f6SRandy Dunlap return $text; 23856b5b55f6SRandy Dunlap} 23866b5b55f6SRandy Dunlap 23871da177e4SLinus Torvaldssub process_file($) { 23882283a117SRandy Dunlap my $file; 23891da177e4SLinus Torvalds my $identifier; 23901da177e4SLinus Torvalds my $func; 2391a21217daSRandy Dunlap my $descr; 23926423133bSJohannes Weiner my $in_purpose = 0; 23931da177e4SLinus Torvalds my $initial_section_counter = $section_counter; 2394*68f86662SBen Hutchings my ($orig_file) = @_; 23951da177e4SLinus Torvalds 23962283a117SRandy Dunlap if (defined($ENV{'SRCTREE'})) { 2397*68f86662SBen Hutchings $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 23982283a117SRandy Dunlap } 23992283a117SRandy Dunlap else { 2400*68f86662SBen Hutchings $file = $orig_file; 24012283a117SRandy Dunlap } 24021da177e4SLinus Torvalds if (defined($source_map{$file})) { 24031da177e4SLinus Torvalds $file = $source_map{$file}; 24041da177e4SLinus Torvalds } 24051da177e4SLinus Torvalds 24061da177e4SLinus Torvalds if (!open(IN,"<$file")) { 24071da177e4SLinus Torvalds print STDERR "Error: Cannot open file $file\n"; 24081da177e4SLinus Torvalds ++$errors; 24091da177e4SLinus Torvalds return; 24101da177e4SLinus Torvalds } 24111da177e4SLinus Torvalds 2412a9e7314bSIlya Dryomov $. = 1; 2413a9e7314bSIlya Dryomov 24141da177e4SLinus Torvalds $section_counter = 0; 24151da177e4SLinus Torvalds while (<IN>) { 241665478428SDaniel Santos while (s/\\\s*$//) { 241765478428SDaniel Santos $_ .= <IN>; 241865478428SDaniel Santos } 24191da177e4SLinus Torvalds if ($state == 0) { 24201da177e4SLinus Torvalds if (/$doc_start/o) { 24211da177e4SLinus Torvalds $state = 1; # next line is always the function name 2422850622dfSRandy Dunlap $in_doc_sect = 0; 24231da177e4SLinus Torvalds } 24241da177e4SLinus Torvalds } elsif ($state == 1) { # this line is the function name (always) 24251da177e4SLinus Torvalds if (/$doc_block/o) { 24261da177e4SLinus Torvalds $state = 4; 24271da177e4SLinus Torvalds $contents = ""; 24281da177e4SLinus Torvalds if ( $1 eq "" ) { 24291da177e4SLinus Torvalds $section = $section_intro; 24301da177e4SLinus Torvalds } else { 24311da177e4SLinus Torvalds $section = $1; 24321da177e4SLinus Torvalds } 24331da177e4SLinus Torvalds } 24341da177e4SLinus Torvalds elsif (/$doc_decl/o) { 24351da177e4SLinus Torvalds $identifier = $1; 24361da177e4SLinus Torvalds if (/\s*([\w\s]+?)\s*-/) { 24371da177e4SLinus Torvalds $identifier = $1; 24381da177e4SLinus Torvalds } 24391da177e4SLinus Torvalds 24401da177e4SLinus Torvalds $state = 2; 24411da177e4SLinus Torvalds if (/-(.*)/) { 244251f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2443a21217daSRandy Dunlap $descr= $1; 2444a21217daSRandy Dunlap $descr =~ s/^\s*//; 2445a21217daSRandy Dunlap $descr =~ s/\s*$//; 244612ae6779SDaniel Santos $descr =~ s/\s+/ /g; 2447a21217daSRandy Dunlap $declaration_purpose = xml_escape($descr); 24486423133bSJohannes Weiner $in_purpose = 1; 24491da177e4SLinus Torvalds } else { 24501da177e4SLinus Torvalds $declaration_purpose = ""; 24511da177e4SLinus Torvalds } 245277cc23b8SRandy Dunlap 245377cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 2454d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 245577cc23b8SRandy Dunlap print STDERR $_; 245677cc23b8SRandy Dunlap ++$warnings; 245777cc23b8SRandy Dunlap } 245877cc23b8SRandy Dunlap 24591da177e4SLinus Torvalds if ($identifier =~ m/^struct/) { 24601da177e4SLinus Torvalds $decl_type = 'struct'; 24611da177e4SLinus Torvalds } elsif ($identifier =~ m/^union/) { 24621da177e4SLinus Torvalds $decl_type = 'union'; 24631da177e4SLinus Torvalds } elsif ($identifier =~ m/^enum/) { 24641da177e4SLinus Torvalds $decl_type = 'enum'; 24651da177e4SLinus Torvalds } elsif ($identifier =~ m/^typedef/) { 24661da177e4SLinus Torvalds $decl_type = 'typedef'; 24671da177e4SLinus Torvalds } else { 24681da177e4SLinus Torvalds $decl_type = 'function'; 24691da177e4SLinus Torvalds } 24701da177e4SLinus Torvalds 24711da177e4SLinus Torvalds if ($verbose) { 2472d40e1e65SBart Van Assche print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; 24731da177e4SLinus Torvalds } 24741da177e4SLinus Torvalds } else { 2475d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 24761da177e4SLinus Torvalds " - I thought it was a doc line\n"; 24771da177e4SLinus Torvalds ++$warnings; 24781da177e4SLinus Torvalds $state = 0; 24791da177e4SLinus Torvalds } 24801da177e4SLinus Torvalds } elsif ($state == 2) { # look for head: lines, and include content 24811da177e4SLinus Torvalds if (/$doc_sect/o) { 24821da177e4SLinus Torvalds $newsection = $1; 24831da177e4SLinus Torvalds $newcontents = $2; 24841da177e4SLinus Torvalds 2485792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 2486850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 2487d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: contents before sections\n"; 2488850622dfSRandy Dunlap ++$warnings; 2489850622dfSRandy Dunlap } 249094dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 24911da177e4SLinus Torvalds $section = $section_default; 24921da177e4SLinus Torvalds } 24931da177e4SLinus Torvalds 2494850622dfSRandy Dunlap $in_doc_sect = 1; 24956423133bSJohannes Weiner $in_purpose = 0; 24961da177e4SLinus Torvalds $contents = $newcontents; 24971da177e4SLinus Torvalds if ($contents ne "") { 249827205744SRandy Dunlap while ((substr($contents, 0, 1) eq " ") || 249927205744SRandy Dunlap substr($contents, 0, 1) eq "\t") { 250005189497SRandy Dunlap $contents = substr($contents, 1); 250105189497SRandy Dunlap } 25021da177e4SLinus Torvalds $contents .= "\n"; 25031da177e4SLinus Torvalds } 25041da177e4SLinus Torvalds $section = $newsection; 25051da177e4SLinus Torvalds } elsif (/$doc_end/) { 25064c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 250794dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 25081da177e4SLinus Torvalds $section = $section_default; 25091da177e4SLinus Torvalds $contents = ""; 25101da177e4SLinus Torvalds } 251146b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 251246b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2513d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: suspicious ending line: $_"; 251446b958ebSRandy Dunlap ++$warnings; 251546b958ebSRandy Dunlap } 25161da177e4SLinus Torvalds 25171da177e4SLinus Torvalds $prototype = ""; 25181da177e4SLinus Torvalds $state = 3; 25191da177e4SLinus Torvalds $brcount = 0; 25201da177e4SLinus Torvalds# print STDERR "end of doc comment, looking for prototype\n"; 25211da177e4SLinus Torvalds } elsif (/$doc_content/) { 25221da177e4SLinus Torvalds # miguel-style comment kludge, look for blank lines after 25231da177e4SLinus Torvalds # @parameter line to signify start of description 25246423133bSJohannes Weiner if ($1 eq "") { 25256423133bSJohannes Weiner if ($section =~ m/^@/ || $section eq $section_context) { 252694dc7ad5SRandy Dunlap dump_section($file, $section, xml_escape($contents)); 25271da177e4SLinus Torvalds $section = $section_default; 25281da177e4SLinus Torvalds $contents = ""; 25291da177e4SLinus Torvalds } else { 25306423133bSJohannes Weiner $contents .= "\n"; 25316423133bSJohannes Weiner } 25326423133bSJohannes Weiner $in_purpose = 0; 25336423133bSJohannes Weiner } elsif ($in_purpose == 1) { 25346423133bSJohannes Weiner # Continued declaration purpose 25356423133bSJohannes Weiner chomp($declaration_purpose); 25366423133bSJohannes Weiner $declaration_purpose .= " " . xml_escape($1); 253712ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 25386423133bSJohannes Weiner } else { 25391da177e4SLinus Torvalds $contents .= $1 . "\n"; 25401da177e4SLinus Torvalds } 25411da177e4SLinus Torvalds } else { 25421da177e4SLinus Torvalds # i dont know - bad line? ignore. 2543d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: bad line: $_"; 25441da177e4SLinus Torvalds ++$warnings; 25451da177e4SLinus Torvalds } 2546a4c6ebedSDanilo Cesar Lemes de Paula } elsif ($state == 5) { # scanning for split parameters 2547a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 2548a4c6ebedSDanilo Cesar Lemes de Paula if ($split_doc_state == 1 && /$doc_split_sect/o) { 2549a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 2550a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 2551a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 2552a4c6ebedSDanilo Cesar Lemes de Paula while ((substr($contents, 0, 1) eq " ") || 2553a4c6ebedSDanilo Cesar Lemes de Paula substr($contents, 0, 1) eq "\t") { 2554a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 2555a4c6ebedSDanilo Cesar Lemes de Paula } 2556a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 2557a4c6ebedSDanilo Cesar Lemes de Paula } 2558a4c6ebedSDanilo Cesar Lemes de Paula $split_doc_state = 2; 2559a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 2560a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_split_end/) { 2561a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 2562a4c6ebedSDanilo Cesar Lemes de Paula dump_section($file, $section, xml_escape($contents)); 2563a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 2564a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 2565a4c6ebedSDanilo Cesar Lemes de Paula } 2566a4c6ebedSDanilo Cesar Lemes de Paula $state = 3; 2567a4c6ebedSDanilo Cesar Lemes de Paula $split_doc_state = 0; 2568a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 2569a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 2570a4c6ebedSDanilo Cesar Lemes de Paula if ($split_doc_state == 2) { 2571a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 2572a4c6ebedSDanilo Cesar Lemes de Paula } elsif ($split_doc_state == 1) { 2573a4c6ebedSDanilo Cesar Lemes de Paula $split_doc_state = 4; 2574a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Warning(${file}:$.): "; 2575a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Incorrect use of kernel-doc format: $_"; 2576a4c6ebedSDanilo Cesar Lemes de Paula ++$warnings; 2577a4c6ebedSDanilo Cesar Lemes de Paula } 2578a4c6ebedSDanilo Cesar Lemes de Paula } 2579232acbcfSRandy Dunlap } elsif ($state == 3) { # scanning for function '{' (end of prototype) 2580a4c6ebedSDanilo Cesar Lemes de Paula if (/$doc_split_start/) { 2581a4c6ebedSDanilo Cesar Lemes de Paula $state = 5; 2582a4c6ebedSDanilo Cesar Lemes de Paula $split_doc_state = 1; 2583a4c6ebedSDanilo Cesar Lemes de Paula } elsif ($decl_type eq 'function') { 25841da177e4SLinus Torvalds process_state3_function($_, $file); 25851da177e4SLinus Torvalds } else { 25861da177e4SLinus Torvalds process_state3_type($_, $file); 25871da177e4SLinus Torvalds } 25881da177e4SLinus Torvalds } elsif ($state == 4) { 25891da177e4SLinus Torvalds # Documentation block 25901da177e4SLinus Torvalds if (/$doc_block/) { 259194dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 25921da177e4SLinus Torvalds $contents = ""; 25931da177e4SLinus Torvalds $function = ""; 25941da177e4SLinus Torvalds %constants = (); 25951da177e4SLinus Torvalds %parameterdescs = (); 25961da177e4SLinus Torvalds %parametertypes = (); 25971da177e4SLinus Torvalds @parameterlist = (); 25981da177e4SLinus Torvalds %sections = (); 25991da177e4SLinus Torvalds @sectionlist = (); 26001da177e4SLinus Torvalds $prototype = ""; 26011da177e4SLinus Torvalds if ( $1 eq "" ) { 26021da177e4SLinus Torvalds $section = $section_intro; 26031da177e4SLinus Torvalds } else { 26041da177e4SLinus Torvalds $section = $1; 26051da177e4SLinus Torvalds } 26061da177e4SLinus Torvalds } 26071da177e4SLinus Torvalds elsif (/$doc_end/) 26081da177e4SLinus Torvalds { 260994dc7ad5SRandy Dunlap dump_doc_section($file, $section, xml_escape($contents)); 26101da177e4SLinus Torvalds $contents = ""; 26111da177e4SLinus Torvalds $function = ""; 26121da177e4SLinus Torvalds %constants = (); 26131da177e4SLinus Torvalds %parameterdescs = (); 26141da177e4SLinus Torvalds %parametertypes = (); 26151da177e4SLinus Torvalds @parameterlist = (); 26161da177e4SLinus Torvalds %sections = (); 26171da177e4SLinus Torvalds @sectionlist = (); 26181da177e4SLinus Torvalds $prototype = ""; 26191da177e4SLinus Torvalds $state = 0; 26201da177e4SLinus Torvalds } 26211da177e4SLinus Torvalds elsif (/$doc_content/) 26221da177e4SLinus Torvalds { 26231da177e4SLinus Torvalds if ( $1 eq "" ) 26241da177e4SLinus Torvalds { 26251da177e4SLinus Torvalds $contents .= $blankline; 26261da177e4SLinus Torvalds } 26271da177e4SLinus Torvalds else 26281da177e4SLinus Torvalds { 26291da177e4SLinus Torvalds $contents .= $1 . "\n"; 26301da177e4SLinus Torvalds } 26311da177e4SLinus Torvalds } 26321da177e4SLinus Torvalds } 26331da177e4SLinus Torvalds } 26341da177e4SLinus Torvalds if ($initial_section_counter == $section_counter) { 2635d40e1e65SBart Van Assche print STDERR "${file}:1: warning: no structured comments found\n"; 2636e946c43aSJohannes Berg if (($function_only == 1) && ($show_not_found == 1)) { 2637e946c43aSJohannes Berg print STDERR " Was looking for '$_'.\n" for keys %function_table; 2638e946c43aSJohannes Berg } 26391da177e4SLinus Torvalds if ($output_mode eq "xml") { 26401da177e4SLinus Torvalds # The template wants at least one RefEntry here; make one. 26411da177e4SLinus Torvalds print "<refentry>\n"; 26421da177e4SLinus Torvalds print " <refnamediv>\n"; 26431da177e4SLinus Torvalds print " <refname>\n"; 2644*68f86662SBen Hutchings print " ${orig_file}\n"; 26451da177e4SLinus Torvalds print " </refname>\n"; 26461da177e4SLinus Torvalds print " <refpurpose>\n"; 26471da177e4SLinus Torvalds print " Document generation inconsistency\n"; 26481da177e4SLinus Torvalds print " </refpurpose>\n"; 26491da177e4SLinus Torvalds print " </refnamediv>\n"; 26501da177e4SLinus Torvalds print " <refsect1>\n"; 26511da177e4SLinus Torvalds print " <title>\n"; 26521da177e4SLinus Torvalds print " Oops\n"; 26531da177e4SLinus Torvalds print " </title>\n"; 26541da177e4SLinus Torvalds print " <warning>\n"; 26551da177e4SLinus Torvalds print " <para>\n"; 26561da177e4SLinus Torvalds print " The template for this document tried to insert\n"; 26571da177e4SLinus Torvalds print " the structured comment from the file\n"; 2658*68f86662SBen Hutchings print " <filename>${orig_file}</filename> at this point,\n"; 26591da177e4SLinus Torvalds print " but none was found.\n"; 26601da177e4SLinus Torvalds print " This dummy section is inserted to allow\n"; 26611da177e4SLinus Torvalds print " generation to continue.\n"; 26621da177e4SLinus Torvalds print " </para>\n"; 26631da177e4SLinus Torvalds print " </warning>\n"; 26641da177e4SLinus Torvalds print " </refsect1>\n"; 26651da177e4SLinus Torvalds print "</refentry>\n"; 26661da177e4SLinus Torvalds } 26671da177e4SLinus Torvalds } 26681da177e4SLinus Torvalds} 26698484baaaSRandy Dunlap 26708484baaaSRandy Dunlap 26718484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 26728484baaaSRandy Dunlap 26738484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 26748484baaaSRandy Dunlap# using the s// operator. 26752e106e4dSJérémy Bobbioforeach my $pattern (sort keys %highlights) { 26768484baaaSRandy Dunlap# print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n"; 26778484baaaSRandy Dunlap $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n"; 26788484baaaSRandy Dunlap} 26798484baaaSRandy Dunlap 26808484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 26818484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 26828484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 26838484baaaSRandy Dunlap my ($relname, $absname); 26848484baaaSRandy Dunlap while(<SOURCE_MAP>) { 26858484baaaSRandy Dunlap chop(); 26868484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 26878484baaaSRandy Dunlap $relname =~ s:^/+::; 26888484baaaSRandy Dunlap $source_map{$relname} = $absname; 26898484baaaSRandy Dunlap } 26908484baaaSRandy Dunlap close(SOURCE_MAP); 26918484baaaSRandy Dunlap} 26928484baaaSRandy Dunlap 26938484baaaSRandy Dunlapforeach (@ARGV) { 26948484baaaSRandy Dunlap chomp; 26958484baaaSRandy Dunlap process_file($_); 26968484baaaSRandy Dunlap} 26978484baaaSRandy Dunlapif ($verbose && $errors) { 26988484baaaSRandy Dunlap print STDERR "$errors errors\n"; 26998484baaaSRandy Dunlap} 27008484baaaSRandy Dunlapif ($verbose && $warnings) { 27018484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 27028484baaaSRandy Dunlap} 27038484baaaSRandy Dunlap 27048484baaaSRandy Dunlapexit($errors); 2705