1cb77f0d6SKamil Rytarowski#!/usr/bin/env perl 238476378SJonathan Corbet# SPDX-License-Identifier: GPL-2.0 31da177e4SLinus Torvalds 4cb77f0d6SKamil Rytarowskiuse warnings; 51da177e4SLinus Torvaldsuse strict; 61da177e4SLinus Torvalds 71da177e4SLinus Torvalds## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## 81da177e4SLinus Torvalds## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## 91da177e4SLinus Torvalds## Copyright (C) 2001 Simon Huggins ## 1070c95b00SRandy Dunlap## Copyright (C) 2005-2012 Randy Dunlap ## 111b40c194SDan Luedtke## Copyright (C) 2012 Dan Luedtke ## 121da177e4SLinus Torvalds## ## 131da177e4SLinus Torvalds## #define enhancements by Armin Kuster <akuster@mvista.com> ## 141da177e4SLinus Torvalds## Copyright (c) 2000 MontaVista Software, Inc. ## 151da177e4SLinus Torvalds## ## 161da177e4SLinus Torvalds## This software falls under the GNU General Public License. ## 171da177e4SLinus Torvalds## Please read the COPYING file for more information ## 181da177e4SLinus Torvalds 19*a5cdaea5STomasz Warniełło=head1 NAME 20*a5cdaea5STomasz Warniełło 21*a5cdaea5STomasz Warniełłokernel-doc - Print formatted kernel documentation to stdout 22*a5cdaea5STomasz Warniełło 23*a5cdaea5STomasz Warniełło=head1 SYNOPSIS 24*a5cdaea5STomasz Warniełło 25*a5cdaea5STomasz Warniełło kernel-doc [-h] [-v] [-Werror] 26*a5cdaea5STomasz Warniełło [ -man | 27*a5cdaea5STomasz Warniełło -rst [-sphinx-version VERSION] [-enable-lineno] | 28*a5cdaea5STomasz Warniełło -none 29*a5cdaea5STomasz Warniełło ] 30*a5cdaea5STomasz Warniełło [ 31*a5cdaea5STomasz Warniełło -export | 32*a5cdaea5STomasz Warniełło -internal | 33*a5cdaea5STomasz Warniełło [-function NAME] ... | 34*a5cdaea5STomasz Warniełło [-nosymbol NAME] ... 35*a5cdaea5STomasz Warniełło ] 36*a5cdaea5STomasz Warniełło [-no-doc-sections] 37*a5cdaea5STomasz Warniełło [-export-file FILE] ... 38*a5cdaea5STomasz Warniełło FILE ... 39*a5cdaea5STomasz Warniełło 40*a5cdaea5STomasz WarniełłoRun `kernel-doc -h` for details. 41*a5cdaea5STomasz Warniełło 42*a5cdaea5STomasz Warniełło=cut 43*a5cdaea5STomasz Warniełło 441da177e4SLinus Torvalds# 18/01/2001 - Cleanups 451da177e4SLinus Torvalds# Functions prototyped as foo(void) same as foo() 461da177e4SLinus Torvalds# Stop eval'ing where we don't need to. 471da177e4SLinus Torvalds# -- huggie@earth.li 481da177e4SLinus Torvalds 491da177e4SLinus Torvalds# 27/06/2001 - Allowed whitespace after initial "/**" and 501da177e4SLinus Torvalds# allowed comments before function declarations. 511da177e4SLinus Torvalds# -- Christian Kreibich <ck@whoop.org> 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds# Still to do: 541da177e4SLinus Torvalds# - add perldoc documentation 551da177e4SLinus Torvalds# - Look more closely at some of the scarier bits :) 561da177e4SLinus Torvalds 571da177e4SLinus Torvalds# 26/05/2001 - Support for separate source and object trees. 581da177e4SLinus Torvalds# Return error code. 591da177e4SLinus Torvalds# Keith Owens <kaos@ocs.com.au> 601da177e4SLinus Torvalds 611da177e4SLinus Torvalds# 23/09/2001 - Added support for typedefs, structs, enums and unions 621da177e4SLinus Torvalds# Support for Context section; can be terminated using empty line 631da177e4SLinus Torvalds# Small fixes (like spaces vs. \s in regex) 641da177e4SLinus Torvalds# -- Tim Jansen <tim@tjansen.de> 651da177e4SLinus Torvalds 661b40c194SDan Luedtke# 25/07/2012 - Added support for HTML5 671b40c194SDan Luedtke# -- Dan Luedtke <mail@danrl.de> 681da177e4SLinus Torvalds 69fadc0b31SJani Nikulasub usage { 70fadc0b31SJani Nikula my $message = <<"EOF"; 71fadc0b31SJani NikulaUsage: $0 [OPTION ...] FILE ... 721da177e4SLinus Torvalds 73fadc0b31SJani NikulaRead C language source or header FILEs, extract embedded documentation comments, 74fadc0b31SJani Nikulaand print formatted documentation to standard output. 751da177e4SLinus Torvalds 76fadc0b31SJani NikulaThe documentation comments are identified by "/**" opening comment mark. See 77857af3b7SMauro Carvalho ChehabDocumentation/doc-guide/kernel-doc.rst for the documentation comment syntax. 78fadc0b31SJani Nikula 79fadc0b31SJani NikulaOutput format selection (mutually exclusive): 80fadc0b31SJani Nikula -man Output troff manual page format. This is the default. 81c0d1b6eeSJonathan Corbet -rst Output reStructuredText format. 823a025e1dSMatthew Wilcox -none Do not output documentation, only warnings. 83fadc0b31SJani Nikula 8493351d41SMauro Carvalho ChehabOutput format selection modifier (affects only ReST output): 8593351d41SMauro Carvalho Chehab 8693351d41SMauro Carvalho Chehab -sphinx-version Use the ReST C domain dialect compatible with an 8793351d41SMauro Carvalho Chehab specific Sphinx Version. 8893351d41SMauro Carvalho Chehab If not specified, kernel-doc will auto-detect using 8993351d41SMauro Carvalho Chehab the sphinx-build version found on PATH. 9093351d41SMauro Carvalho Chehab 91fadc0b31SJani NikulaOutput selection (mutually exclusive): 9286ae2e38SJani Nikula -export Only output documentation for symbols that have been 9386ae2e38SJani Nikula exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 94c9b2cfb3SJani Nikula in any input FILE or -export-file FILE. 9586ae2e38SJani Nikula -internal Only output documentation for symbols that have NOT been 9686ae2e38SJani Nikula exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 97c9b2cfb3SJani Nikula in any input FILE or -export-file FILE. 98fadc0b31SJani Nikula -function NAME Only output documentation for the given function(s) 99fadc0b31SJani Nikula or DOC: section title(s). All other functions and DOC: 100fadc0b31SJani Nikula sections are ignored. May be specified multiple times. 101eab795ddSMauro Carvalho Chehab -nosymbol NAME Exclude the specified symbols from the output 102eab795ddSMauro Carvalho Chehab documentation. May be specified multiple times. 103fadc0b31SJani Nikula 104fadc0b31SJani NikulaOutput selection modifiers: 105fadc0b31SJani Nikula -no-doc-sections Do not output DOC: sections. 1060b0f5f29SDaniel Vetter -enable-lineno Enable output of #define LINENO lines. Only works with 1070b0f5f29SDaniel Vetter reStructuredText format. 10888c2b57dSJani Nikula -export-file FILE Specify an additional FILE in which to look for 10988c2b57dSJani Nikula EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with 11088c2b57dSJani Nikula -export or -internal. May be specified multiple times. 111fadc0b31SJani Nikula 112fadc0b31SJani NikulaOther parameters: 113fadc0b31SJani Nikula -v Verbose output, more warnings and other information. 114fadc0b31SJani Nikula -h Print this help. 1152c12c810SPierre-Louis Bossart -Werror Treat warnings as errors. 116fadc0b31SJani Nikula 117fadc0b31SJani NikulaEOF 118fadc0b31SJani Nikula print $message; 119fadc0b31SJani Nikula exit 1; 120fadc0b31SJani Nikula} 1211da177e4SLinus Torvalds 1221da177e4SLinus Torvalds# 1231da177e4SLinus Torvalds# format of comments. 1241da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure. 1251da177e4SLinus Torvalds# (...)* signifies 0 or more structure elements 1261da177e4SLinus Torvalds# /** 1271da177e4SLinus Torvalds# * function_name(:)? (- short description)? 1281da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)* 1291da177e4SLinus Torvalds# (* a blank line)? 1301da177e4SLinus Torvalds# * (Description:)? (Description of function)? 1311da177e4SLinus Torvalds# * (section header: (section description)? )* 1321da177e4SLinus Torvalds# (*)?*/ 1331da177e4SLinus Torvalds# 1341da177e4SLinus Torvalds# So .. the trivial example would be: 1351da177e4SLinus Torvalds# 1361da177e4SLinus Torvalds# /** 1371da177e4SLinus Torvalds# * my_function 138b9d97328SRandy Dunlap# */ 1391da177e4SLinus Torvalds# 140891dcd2fSRandy Dunlap# If the Description: header tag is omitted, then there must be a blank line 1411da177e4SLinus Torvalds# after the last parameter specification. 1421da177e4SLinus Torvalds# e.g. 1431da177e4SLinus Torvalds# /** 1441da177e4SLinus Torvalds# * my_function - does my stuff 1451da177e4SLinus Torvalds# * @my_arg: its mine damnit 1461da177e4SLinus Torvalds# * 1471da177e4SLinus Torvalds# * Does my stuff explained. 1481da177e4SLinus Torvalds# */ 1491da177e4SLinus Torvalds# 1501da177e4SLinus Torvalds# or, could also use: 1511da177e4SLinus Torvalds# /** 1521da177e4SLinus Torvalds# * my_function - does my stuff 1531da177e4SLinus Torvalds# * @my_arg: its mine damnit 1541da177e4SLinus Torvalds# * Description: Does my stuff explained. 1551da177e4SLinus Torvalds# */ 1561da177e4SLinus Torvalds# etc. 1571da177e4SLinus Torvalds# 158b9d97328SRandy Dunlap# Besides functions you can also write documentation for structs, unions, 1591da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name 1601da177e4SLinus Torvalds# of the declaration; the struct/union/enum/typedef must always precede 1611da177e4SLinus Torvalds# the name. Nesting of declarations is not supported. 1621da177e4SLinus Torvalds# Use the argument mechanism to document members or constants. 1631da177e4SLinus Torvalds# e.g. 1641da177e4SLinus Torvalds# /** 1651da177e4SLinus Torvalds# * struct my_struct - short description 1661da177e4SLinus Torvalds# * @a: first member 1671da177e4SLinus Torvalds# * @b: second member 1681da177e4SLinus Torvalds# * 1691da177e4SLinus Torvalds# * Longer description 1701da177e4SLinus Torvalds# */ 1711da177e4SLinus Torvalds# struct my_struct { 1721da177e4SLinus Torvalds# int a; 1731da177e4SLinus Torvalds# int b; 174aeec46b9SMartin Waitz# /* private: */ 175aeec46b9SMartin Waitz# int c; 1761da177e4SLinus Torvalds# }; 1771da177e4SLinus Torvalds# 1781da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description. 1791da177e4SLinus Torvalds# 180a4c6ebedSDanilo Cesar Lemes de Paula# For really longs structs, you can also describe arguments inside the 181a4c6ebedSDanilo Cesar Lemes de Paula# body of the struct. 182a4c6ebedSDanilo Cesar Lemes de Paula# eg. 183a4c6ebedSDanilo Cesar Lemes de Paula# /** 184a4c6ebedSDanilo Cesar Lemes de Paula# * struct my_struct - short description 185a4c6ebedSDanilo Cesar Lemes de Paula# * @a: first member 186a4c6ebedSDanilo Cesar Lemes de Paula# * @b: second member 187a4c6ebedSDanilo Cesar Lemes de Paula# * 188a4c6ebedSDanilo Cesar Lemes de Paula# * Longer description 189a4c6ebedSDanilo Cesar Lemes de Paula# */ 190a4c6ebedSDanilo Cesar Lemes de Paula# struct my_struct { 191a4c6ebedSDanilo Cesar Lemes de Paula# int a; 192a4c6ebedSDanilo Cesar Lemes de Paula# int b; 193a4c6ebedSDanilo Cesar Lemes de Paula# /** 194a4c6ebedSDanilo Cesar Lemes de Paula# * @c: This is longer description of C 195a4c6ebedSDanilo Cesar Lemes de Paula# * 196a4c6ebedSDanilo Cesar Lemes de Paula# * You can use paragraphs to describe arguments 197a4c6ebedSDanilo Cesar Lemes de Paula# * using this method. 198a4c6ebedSDanilo Cesar Lemes de Paula# */ 199a4c6ebedSDanilo Cesar Lemes de Paula# int c; 200a4c6ebedSDanilo Cesar Lemes de Paula# }; 201a4c6ebedSDanilo Cesar Lemes de Paula# 202a4c6ebedSDanilo Cesar Lemes de Paula# This should be use only for struct/enum members. 203a4c6ebedSDanilo Cesar Lemes de Paula# 2041da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you 2051da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions 2061da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an 2071da177e4SLinus Torvalds# empty line. 2084092bac7SYacine Belkadi# A non-void function should have a "Return:" section describing the return 2094092bac7SYacine Belkadi# value(s). 2101da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked 2111da177e4SLinus Torvalds# appropriately in DocBook. 2121da177e4SLinus Torvalds# 2131da177e4SLinus Torvalds# Example: 2141da177e4SLinus Torvalds# /** 2151da177e4SLinus Torvalds# * user_function - function that can only be called in user context 2161da177e4SLinus Torvalds# * @a: some argument 2171da177e4SLinus Torvalds# * Context: !in_interrupt() 2181da177e4SLinus Torvalds# * 2191da177e4SLinus Torvalds# * Some description 2201da177e4SLinus Torvalds# * Example: 2211da177e4SLinus Torvalds# * user_function(22); 2221da177e4SLinus Torvalds# */ 2231da177e4SLinus Torvalds# ... 2241da177e4SLinus Torvalds# 2251da177e4SLinus Torvalds# 2261da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special 2271da177e4SLinus Torvalds# patterns, which are highlighted appropriately. 2281da177e4SLinus Torvalds# 2291da177e4SLinus Torvalds# 'funcname()' - function 2301da177e4SLinus Torvalds# '$ENVVAR' - environmental variable 2311da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct') 2325267dd35SPaolo Bonzini# '&struct_name.member' - name of a structure member 2331da177e4SLinus Torvalds# '@parameter' - name of a parameter 2341da177e4SLinus Torvalds# '%CONST' - name of a constant. 235b97f193aSMauro Carvalho Chehab# '``LITERAL``' - literal string without any spaces on it. 2361da177e4SLinus Torvalds 2378484baaaSRandy Dunlap## init lots of data 2388484baaaSRandy Dunlap 2391da177e4SLinus Torvaldsmy $errors = 0; 2401da177e4SLinus Torvaldsmy $warnings = 0; 2415f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 2421da177e4SLinus Torvalds 2431da177e4SLinus Torvalds# match expressions used to find embedded type information 244b97f193aSMauro Carvalho Chehabmy $type_constant = '\b``([^\`]+)``\b'; 245b97f193aSMauro Carvalho Chehabmy $type_constant2 = '\%([-_\w]+)'; 2461da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 247bfd228c7SMike Rapoportmy $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; 248ee2aa759SMauro Carvalho Chehabmy $type_param_ref = '([\!]?)\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; 2495219f18aSJonathan Corbetmy $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params 250346282dbSMauro Carvalho Chehabmy $type_fp_param2 = '\@(\w+->\S+)\(\)'; # Special RST handling for structs with func ptr params 2511da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 252df31175bSPaolo Bonzinimy $type_enum = '\&(enum\s*([_\w]+))'; 253df31175bSPaolo Bonzinimy $type_struct = '\&(struct\s*([_\w]+))'; 254df31175bSPaolo Bonzinimy $type_typedef = '\&(typedef\s*([_\w]+))'; 255df31175bSPaolo Bonzinimy $type_union = '\&(union\s*([_\w]+))'; 2565267dd35SPaolo Bonzinimy $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; 257df31175bSPaolo Bonzinimy $type_fallback = '\&([_\w]+)'; 258f3341dcfSJani Nikulamy $type_member_func = $type_member . '\(\)'; 2591da177e4SLinus Torvalds 2601da177e4SLinus Torvalds# Output conversion substitutions. 2611da177e4SLinus Torvalds# One for each output format 2621da177e4SLinus Torvalds 2631da177e4SLinus Torvalds# these are pretty rough 2644d732701SDanilo Cesar Lemes de Paulamy @highlights_man = ( 2654d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 266b97f193aSMauro Carvalho Chehab [$type_constant2, "\$1"], 2674d732701SDanilo Cesar Lemes de Paula [$type_func, "\\\\fB\$1\\\\fP"], 268df31175bSPaolo Bonzini [$type_enum, "\\\\fI\$1\\\\fP"], 2694d732701SDanilo Cesar Lemes de Paula [$type_struct, "\\\\fI\$1\\\\fP"], 270df31175bSPaolo Bonzini [$type_typedef, "\\\\fI\$1\\\\fP"], 271df31175bSPaolo Bonzini [$type_union, "\\\\fI\$1\\\\fP"], 2725267dd35SPaolo Bonzini [$type_param, "\\\\fI\$1\\\\fP"], 273ee2aa759SMauro Carvalho Chehab [$type_param_ref, "\\\\fI\$1\$2\\\\fP"], 274df31175bSPaolo Bonzini [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], 275df31175bSPaolo Bonzini [$type_fallback, "\\\\fI\$1\\\\fP"] 2764d732701SDanilo Cesar Lemes de Paula ); 2771da177e4SLinus Torvaldsmy $blankline_man = ""; 2781da177e4SLinus Torvalds 279c0d1b6eeSJonathan Corbet# rst-mode 280c0d1b6eeSJonathan Corbetmy @highlights_rst = ( 281c0d1b6eeSJonathan Corbet [$type_constant, "``\$1``"], 282b97f193aSMauro Carvalho Chehab [$type_constant2, "``\$1``"], 283f3341dcfSJani Nikula # Note: need to escape () to avoid func matching later 2845267dd35SPaolo Bonzini [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], 2855267dd35SPaolo Bonzini [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], 2865219f18aSJonathan Corbet [$type_fp_param, "**\$1\\\\(\\\\)**"], 287346282dbSMauro Carvalho Chehab [$type_fp_param2, "**\$1\\\\(\\\\)**"], 288344fdb28SJonathan Corbet [$type_func, "\$1()"], 289df31175bSPaolo Bonzini [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], 290df31175bSPaolo Bonzini [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], 291df31175bSPaolo Bonzini [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], 292df31175bSPaolo Bonzini [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], 293a7291e7eSJani Nikula # in rst this can refer to any type 294df31175bSPaolo Bonzini [$type_fallback, "\\:c\\:type\\:`\$1`"], 295ee2aa759SMauro Carvalho Chehab [$type_param_ref, "**\$1\$2**"] 296c0d1b6eeSJonathan Corbet ); 297c0d1b6eeSJonathan Corbetmy $blankline_rst = "\n"; 298c0d1b6eeSJonathan Corbet 2991da177e4SLinus Torvalds# read arguments 3001da177e4SLinus Torvaldsif ($#ARGV == -1) { 3011da177e4SLinus Torvalds usage(); 3021da177e4SLinus Torvalds} 3031da177e4SLinus Torvalds 3048484baaaSRandy Dunlapmy $kernelversion; 30593351d41SMauro Carvalho Chehabmy ($sphinx_major, $sphinx_minor, $sphinx_patch); 306efa44475SMauro Carvalho Chehab 3078484baaaSRandy Dunlapmy $dohighlight = ""; 3088484baaaSRandy Dunlap 3091da177e4SLinus Torvaldsmy $verbose = 0; 3102c12c810SPierre-Louis Bossartmy $Werror = 0; 311bdfe2be3SMauro Carvalho Chehabmy $output_mode = "rst"; 312e314ba31SDaniel Santosmy $output_preformatted = 0; 3134b44595aSJohannes Bergmy $no_doc_sections = 0; 3140b0f5f29SDaniel Vettermy $enable_lineno = 0; 315bdfe2be3SMauro Carvalho Chehabmy @highlights = @highlights_rst; 316bdfe2be3SMauro Carvalho Chehabmy $blankline = $blankline_rst; 3171da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 318b6c3f456SJani Nikula 319b6c3f456SJani Nikulause constant { 320b6c3f456SJani Nikula OUTPUT_ALL => 0, # output all symbols and doc sections 321b6c3f456SJani Nikula OUTPUT_INCLUDE => 1, # output only specified symbols 322eab795ddSMauro Carvalho Chehab OUTPUT_EXPORTED => 2, # output exported symbols 323eab795ddSMauro Carvalho Chehab OUTPUT_INTERNAL => 3, # output non-exported symbols 324b6c3f456SJani Nikula}; 325b6c3f456SJani Nikulamy $output_selection = OUTPUT_ALL; 326b0d60bfbSJonathan Corbetmy $show_not_found = 0; # No longer used 327b2c4105bSBen Hutchings 32888c2b57dSJani Nikulamy @export_file_list; 32988c2b57dSJani Nikula 330b2c4105bSBen Hutchingsmy @build_time; 331b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 332b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 333b2c4105bSBen Hutchings @build_time = gmtime($seconds); 334b2c4105bSBen Hutchings} else { 335b2c4105bSBen Hutchings @build_time = localtime; 336b2c4105bSBen Hutchings} 337b2c4105bSBen Hutchings 3381da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 3391da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 340b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 341b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 3421da177e4SLinus Torvalds 3438484baaaSRandy Dunlap# Essentially these are globals. 344b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 345b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 3461da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 3471da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 348eab795ddSMauro Carvalho Chehabmy %nosymbol_table = (); 3490b0f5f29SDaniel Vettermy $declaration_start_line; 3501da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 3511c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 3521da177e4SLinus Torvalds 353bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 354bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 355bd0e88e5SRandy Dunlap} 356bd0e88e5SRandy Dunlap 3572c12c810SPierre-Louis Bossartif (defined($ENV{'KCFLAGS'})) { 3582c12c810SPierre-Louis Bossart my $kcflags = "$ENV{'KCFLAGS'}"; 3592c12c810SPierre-Louis Bossart 3602c12c810SPierre-Louis Bossart if ($kcflags =~ /Werror/) { 3612c12c810SPierre-Louis Bossart $Werror = 1; 3622c12c810SPierre-Louis Bossart } 3632c12c810SPierre-Louis Bossart} 3642c12c810SPierre-Louis Bossart 365bed4ed30SLaurent Pinchartif (defined($ENV{'KDOC_WERROR'})) { 366bed4ed30SLaurent Pinchart $Werror = "$ENV{'KDOC_WERROR'}"; 367bed4ed30SLaurent Pinchart} 368bed4ed30SLaurent Pinchart 3691da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 3701da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 37193431e06SAlexander A. Klimov# https://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 3721da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 3731da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 3741da177e4SLinus Torvalds# into html. 3751da177e4SLinus Torvaldsmy $section_counter = 0; 3761da177e4SLinus Torvalds 3771da177e4SLinus Torvaldsmy $lineprefix=""; 3781da177e4SLinus Torvalds 37948af606aSJani Nikula# Parser states 38048af606aSJani Nikulause constant { 38148af606aSJani Nikula STATE_NORMAL => 0, # normal code 38248af606aSJani Nikula STATE_NAME => 1, # looking for function name 38317b78717SJonathan Corbet STATE_BODY_MAYBE => 2, # body - or maybe more description 38417b78717SJonathan Corbet STATE_BODY => 3, # the body of the comment 3850d55d48bSMauro Carvalho Chehab STATE_BODY_WITH_BLANK_LINE => 4, # the body, which has a blank line 3860d55d48bSMauro Carvalho Chehab STATE_PROTO => 5, # scanning prototype 3870d55d48bSMauro Carvalho Chehab STATE_DOCBLOCK => 6, # documentation block 3880d55d48bSMauro Carvalho Chehab STATE_INLINE => 7, # gathering doc outside main block 38948af606aSJani Nikula}; 3901da177e4SLinus Torvaldsmy $state; 391850622dfSRandy Dunlapmy $in_doc_sect; 392d742f24dSJonathan Corbetmy $leading_space; 3931da177e4SLinus Torvalds 39448af606aSJani Nikula# Inline documentation state 39548af606aSJani Nikulause constant { 39648af606aSJani Nikula STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 39748af606aSJani Nikula STATE_INLINE_NAME => 1, # looking for member name (@foo:) 39848af606aSJani Nikula STATE_INLINE_TEXT => 2, # looking for member documentation 39948af606aSJani Nikula STATE_INLINE_END => 3, # done 40048af606aSJani Nikula STATE_INLINE_ERROR => 4, # error - Comment without header was found. 40148af606aSJani Nikula # Spit a warning as it's not 402a4c6ebedSDanilo Cesar Lemes de Paula # proper kernel-doc and ignore the rest. 40348af606aSJani Nikula}; 40448af606aSJani Nikulamy $inline_doc_state; 405a4c6ebedSDanilo Cesar Lemes de Paula 4061da177e4SLinus Torvalds#declaration types: can be 4071da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 4081da177e4SLinus Torvaldsmy $decl_type; 4091da177e4SLinus Torvalds 41052042e2dSMauro Carvalho Chehab# Name of the kernel-doc identifier for non-DOC markups 41152042e2dSMauro Carvalho Chehabmy $identifier; 41252042e2dSMauro Carvalho Chehab 4131da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 4141da177e4SLinus Torvaldsmy $doc_end = '\*/'; 4151da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 41612ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 4171da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 418f624adefSJani Nikula# @params and a strictly limited set of supported section names 419212209cfSJonathan Corbet# Specifically: 420212209cfSJonathan Corbet# Match @word: 421212209cfSJonathan Corbet# @...: 422212209cfSJonathan Corbet# @{section-name}: 423212209cfSJonathan Corbet# while trying to not match literal block starts like "example::" 424212209cfSJonathan Corbet# 4258569de68SJonathan Corbetmy $doc_sect = $doc_com . 426212209cfSJonathan Corbet '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:([^:].*)?$'; 42712ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 4281da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 42948af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$'; 430fe7bc493SMauro Carvalho Chehabmy $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)'; 43148af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$'; 4320c9aa209SJani Nikulamy $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; 43386ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 434e86bdb24SAditya Srivastavamy $function_pointer = qr{([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)}; 435e86bdb24SAditya Srivastavamy $attribute = qr{__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)}i; 4361da177e4SLinus Torvalds 4371da177e4SLinus Torvaldsmy %parameterdescs; 4380b0f5f29SDaniel Vettermy %parameterdesc_start_lines; 4391da177e4SLinus Torvaldsmy @parameterlist; 4401da177e4SLinus Torvaldsmy %sections; 4411da177e4SLinus Torvaldsmy @sectionlist; 4420b0f5f29SDaniel Vettermy %section_start_lines; 443a1d94aa5SRandy Dunlapmy $sectcheck; 444a1d94aa5SRandy Dunlapmy $struct_actual; 4451da177e4SLinus Torvalds 4461da177e4SLinus Torvaldsmy $contents = ""; 4470b0f5f29SDaniel Vettermy $new_start_line = 0; 448f624adefSJani Nikula 449f624adefSJani Nikula# the canonical section names. see also $doc_sect above. 4501da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 4511da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 4521da177e4SLinus Torvaldsmy $section = $section_default; 4531da177e4SLinus Torvaldsmy $section_context = "Context"; 4544092bac7SYacine Belkadimy $section_return = "Return"; 4551da177e4SLinus Torvalds 4561da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 4571da177e4SLinus Torvalds 4581da177e4SLinus Torvaldsreset_state(); 4591da177e4SLinus Torvalds 460b031ac4eSMauro Carvalho Chehabwhile ($ARGV[0] =~ m/^--?(.*)/) { 461b031ac4eSMauro Carvalho Chehab my $cmd = $1; 462b031ac4eSMauro Carvalho Chehab shift @ARGV; 463b031ac4eSMauro Carvalho Chehab if ($cmd eq "man") { 4641da177e4SLinus Torvalds $output_mode = "man"; 4654d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 4661da177e4SLinus Torvalds $blankline = $blankline_man; 467b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "rst") { 468c0d1b6eeSJonathan Corbet $output_mode = "rst"; 469c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 470c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 471b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "none") { 4723a025e1dSMatthew Wilcox $output_mode = "none"; 473b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document 4741da177e4SLinus Torvalds $modulename = shift @ARGV; 475b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "function") { # to only output specific functions 476b6c3f456SJani Nikula $output_selection = OUTPUT_INCLUDE; 4771da177e4SLinus Torvalds $function = shift @ARGV; 4781da177e4SLinus Torvalds $function_table{$function} = 1; 479eab795ddSMauro Carvalho Chehab } elsif ($cmd eq "nosymbol") { # Exclude specific symbols 480eab795ddSMauro Carvalho Chehab my $symbol = shift @ARGV; 481eab795ddSMauro Carvalho Chehab $nosymbol_table{$symbol} = 1; 482b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export") { # only exported symbols 483b6c3f456SJani Nikula $output_selection = OUTPUT_EXPORTED; 484da9726ecSJani Nikula %function_table = (); 485b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "internal") { # only non-exported symbols 486b6c3f456SJani Nikula $output_selection = OUTPUT_INTERNAL; 487da9726ecSJani Nikula %function_table = (); 488b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export-file") { 48988c2b57dSJani Nikula my $file = shift @ARGV; 49088c2b57dSJani Nikula push(@export_file_list, $file); 491b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "v") { 4921da177e4SLinus Torvalds $verbose = 1; 4932c12c810SPierre-Louis Bossart } elsif ($cmd eq "Werror") { 4942c12c810SPierre-Louis Bossart $Werror = 1; 495b031ac4eSMauro Carvalho Chehab } elsif (($cmd eq "h") || ($cmd eq "help")) { 4961da177e4SLinus Torvalds usage(); 497b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'no-doc-sections') { 4984b44595aSJohannes Berg $no_doc_sections = 1; 499b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'enable-lineno') { 5000b0f5f29SDaniel Vetter $enable_lineno = 1; 501b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'show-not-found') { 502b0d60bfbSJonathan Corbet $show_not_found = 1; # A no-op but don't fail 50393351d41SMauro Carvalho Chehab } elsif ($cmd eq "sphinx-version") { 50493351d41SMauro Carvalho Chehab my $ver_string = shift @ARGV; 50593351d41SMauro Carvalho Chehab if ($ver_string =~ m/^(\d+)(\.\d+)?(\.\d+)?/) { 50693351d41SMauro Carvalho Chehab $sphinx_major = $1; 50793351d41SMauro Carvalho Chehab if (defined($2)) { 50893351d41SMauro Carvalho Chehab $sphinx_minor = substr($2,1); 50993351d41SMauro Carvalho Chehab } else { 51093351d41SMauro Carvalho Chehab $sphinx_minor = 0; 51193351d41SMauro Carvalho Chehab } 51293351d41SMauro Carvalho Chehab if (defined($3)) { 51393351d41SMauro Carvalho Chehab $sphinx_patch = substr($3,1) 51493351d41SMauro Carvalho Chehab } else { 51593351d41SMauro Carvalho Chehab $sphinx_patch = 0; 51693351d41SMauro Carvalho Chehab } 51793351d41SMauro Carvalho Chehab } else { 51893351d41SMauro Carvalho Chehab die "Sphinx version should either major.minor or major.minor.patch format\n"; 51993351d41SMauro Carvalho Chehab } 520b031ac4eSMauro Carvalho Chehab } else { 521b031ac4eSMauro Carvalho Chehab # Unknown argument 522b031ac4eSMauro Carvalho Chehab usage(); 5231da177e4SLinus Torvalds } 5241da177e4SLinus Torvalds} 5251da177e4SLinus Torvalds 5268484baaaSRandy Dunlap# continue execution near EOF; 5278484baaaSRandy Dunlap 528efa44475SMauro Carvalho Chehab# The C domain dialect changed on Sphinx 3. So, we need to check the 529efa44475SMauro Carvalho Chehab# version in order to produce the right tags. 530efa44475SMauro Carvalho Chehabsub findprog($) 531efa44475SMauro Carvalho Chehab{ 532efa44475SMauro Carvalho Chehab foreach(split(/:/, $ENV{PATH})) { 533efa44475SMauro Carvalho Chehab return "$_/$_[0]" if(-x "$_/$_[0]"); 534efa44475SMauro Carvalho Chehab } 535efa44475SMauro Carvalho Chehab} 536efa44475SMauro Carvalho Chehab 537efa44475SMauro Carvalho Chehabsub get_sphinx_version() 538efa44475SMauro Carvalho Chehab{ 539efa44475SMauro Carvalho Chehab my $ver; 540efa44475SMauro Carvalho Chehab 541efa44475SMauro Carvalho Chehab my $cmd = "sphinx-build"; 542efa44475SMauro Carvalho Chehab if (!findprog($cmd)) { 543efa44475SMauro Carvalho Chehab my $cmd = "sphinx-build3"; 54493351d41SMauro Carvalho Chehab if (!findprog($cmd)) { 54593351d41SMauro Carvalho Chehab $sphinx_major = 1; 54693351d41SMauro Carvalho Chehab $sphinx_minor = 2; 54793351d41SMauro Carvalho Chehab $sphinx_patch = 0; 54893351d41SMauro Carvalho Chehab printf STDERR "Warning: Sphinx version not found. Using default (Sphinx version %d.%d.%d)\n", 54993351d41SMauro Carvalho Chehab $sphinx_major, $sphinx_minor, $sphinx_patch; 55093351d41SMauro Carvalho Chehab return; 55193351d41SMauro Carvalho Chehab } 552efa44475SMauro Carvalho Chehab } 553efa44475SMauro Carvalho Chehab 554efa44475SMauro Carvalho Chehab open IN, "$cmd --version 2>&1 |"; 555efa44475SMauro Carvalho Chehab while (<IN>) { 556efa44475SMauro Carvalho Chehab if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) { 55793351d41SMauro Carvalho Chehab $sphinx_major = $1; 55893351d41SMauro Carvalho Chehab $sphinx_minor = $2; 55993351d41SMauro Carvalho Chehab $sphinx_patch = $3; 560efa44475SMauro Carvalho Chehab last; 561efa44475SMauro Carvalho Chehab } 562efa44475SMauro Carvalho Chehab # Sphinx 1.2.x uses a different format 563efa44475SMauro Carvalho Chehab if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+)$/) { 56493351d41SMauro Carvalho Chehab $sphinx_major = $1; 56593351d41SMauro Carvalho Chehab $sphinx_minor = $2; 56693351d41SMauro Carvalho Chehab $sphinx_patch = $3; 567efa44475SMauro Carvalho Chehab last; 568efa44475SMauro Carvalho Chehab } 569efa44475SMauro Carvalho Chehab } 570efa44475SMauro Carvalho Chehab close IN; 571efa44475SMauro Carvalho Chehab} 572efa44475SMauro Carvalho Chehab 57353f049faSBorislav Petkov# get kernel version from env 57453f049faSBorislav Petkovsub get_kernel_version() { 5751b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 57653f049faSBorislav Petkov 57753f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 57853f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 57953f049faSBorislav Petkov } 58053f049faSBorislav Petkov return $version; 58153f049faSBorislav Petkov} 5821da177e4SLinus Torvalds 5830b0f5f29SDaniel Vetter# 5840b0f5f29SDaniel Vettersub print_lineno { 5850b0f5f29SDaniel Vetter my $lineno = shift; 5860b0f5f29SDaniel Vetter if ($enable_lineno && defined($lineno)) { 5870b0f5f29SDaniel Vetter print "#define LINENO " . $lineno . "\n"; 5880b0f5f29SDaniel Vetter } 5890b0f5f29SDaniel Vetter} 5901da177e4SLinus Torvalds## 5911da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 5921da177e4SLinus Torvalds# 5931da177e4SLinus Torvaldssub dump_section { 59494dc7ad5SRandy Dunlap my $file = shift; 5951da177e4SLinus Torvalds my $name = shift; 5961da177e4SLinus Torvalds my $contents = join "\n", @_; 5971da177e4SLinus Torvalds 59813901ef2SJani Nikula if ($name =~ m/$type_param/) { 5991da177e4SLinus Torvalds $name = $1; 6001da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 601a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 6020b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 6030b0f5f29SDaniel Vetter $new_start_line = 0; 604ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 605ced69090SRandy Dunlap $name = "..."; 606ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 607a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 6080b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 6090b0f5f29SDaniel Vetter $new_start_line = 0; 6101da177e4SLinus Torvalds } else { 61194dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 61295b6be9dSJani Nikula # Only warn on user specified duplicate section names. 61395b6be9dSJani Nikula if ($name ne $section_default) { 61432217761SJani Nikula print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; 61532217761SJani Nikula ++$warnings; 61695b6be9dSJani Nikula } 61732217761SJani Nikula $sections{$name} .= $contents; 61832217761SJani Nikula } else { 6191da177e4SLinus Torvalds $sections{$name} = $contents; 6201da177e4SLinus Torvalds push @sectionlist, $name; 6210b0f5f29SDaniel Vetter $section_start_lines{$name} = $new_start_line; 6220b0f5f29SDaniel Vetter $new_start_line = 0; 6231da177e4SLinus Torvalds } 6241da177e4SLinus Torvalds } 62532217761SJani Nikula} 6261da177e4SLinus Torvalds 6271da177e4SLinus Torvalds## 628b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 629b112e0f7SJohannes Berg# 630b112e0f7SJohannes Bergsub dump_doc_section { 63194dc7ad5SRandy Dunlap my $file = shift; 632b112e0f7SJohannes Berg my $name = shift; 633b112e0f7SJohannes Berg my $contents = join "\n", @_; 634b112e0f7SJohannes Berg 6354b44595aSJohannes Berg if ($no_doc_sections) { 6364b44595aSJohannes Berg return; 6374b44595aSJohannes Berg } 6384b44595aSJohannes Berg 639eab795ddSMauro Carvalho Chehab return if (defined($nosymbol_table{$name})); 640eab795ddSMauro Carvalho Chehab 641b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 642eab795ddSMauro Carvalho Chehab (($output_selection == OUTPUT_INCLUDE) && 643eab795ddSMauro Carvalho Chehab defined($function_table{$name}))) 644b112e0f7SJohannes Berg { 64594dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 646b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 647b112e0f7SJohannes Berg 'sections' => \%sections, 648b112e0f7SJohannes Berg 'module' => $modulename, 649b6c3f456SJani Nikula 'content-only' => ($output_selection != OUTPUT_ALL), }); 650b112e0f7SJohannes Berg } 651b112e0f7SJohannes Berg} 652b112e0f7SJohannes Berg 653b112e0f7SJohannes Berg## 6541da177e4SLinus Torvalds# output function 6551da177e4SLinus Torvalds# 6561da177e4SLinus Torvalds# parameterdescs, a hash. 6571da177e4SLinus Torvalds# function => "function name" 6581da177e4SLinus Torvalds# parameterlist => @list of parameters 6591da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 6601da177e4SLinus Torvalds# sectionlist => @list of sections 661a21217daSRandy Dunlap# sections => %section descriptions 6621da177e4SLinus Torvalds# 6631da177e4SLinus Torvalds 6641da177e4SLinus Torvaldssub output_highlight { 6651da177e4SLinus Torvalds my $contents = join "\n",@_; 6661da177e4SLinus Torvalds my $line; 6671da177e4SLinus Torvalds 6681da177e4SLinus Torvalds# DEBUG 6691da177e4SLinus Torvalds# if (!defined $contents) { 6701da177e4SLinus Torvalds# use Carp; 6711da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 6721da177e4SLinus Torvalds# } 6731da177e4SLinus Torvalds 6743eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 6751da177e4SLinus Torvalds eval $dohighlight; 6761da177e4SLinus Torvalds die $@ if $@; 6773eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 6783eb014a1SRandy Dunlap 6791da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 68012ae6779SDaniel Santos if (! $output_preformatted) { 68112ae6779SDaniel Santos $line =~ s/^\s*//; 68212ae6779SDaniel Santos } 6831da177e4SLinus Torvalds if ($line eq ""){ 684e314ba31SDaniel Santos if (! $output_preformatted) { 6850bba924cSJonathan Corbet print $lineprefix, $blankline; 686e314ba31SDaniel Santos } 6871da177e4SLinus Torvalds } else { 688cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 689cdccb316SRandy Dunlap print "\\&$line"; 690cdccb316SRandy Dunlap } else { 6911da177e4SLinus Torvalds print $lineprefix, $line; 6921da177e4SLinus Torvalds } 693cdccb316SRandy Dunlap } 6941da177e4SLinus Torvalds print "\n"; 6951da177e4SLinus Torvalds } 6961da177e4SLinus Torvalds} 6971da177e4SLinus Torvalds 6981da177e4SLinus Torvalds## 6991da177e4SLinus Torvalds# output function in man 7001da177e4SLinus Torvaldssub output_function_man(%) { 7011da177e4SLinus Torvalds my %args = %{$_[0]}; 7021da177e4SLinus Torvalds my ($parameter, $section); 7031da177e4SLinus Torvalds my $count; 7041da177e4SLinus Torvalds 7051da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 7061da177e4SLinus Torvalds 7071da177e4SLinus Torvalds print ".SH NAME\n"; 7081da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 7091da177e4SLinus Torvalds 7101da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 711a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 7121da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 713a21217daSRandy Dunlap } else { 714a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 715a21217daSRandy Dunlap } 7161da177e4SLinus Torvalds $count = 0; 7171da177e4SLinus Torvalds my $parenth = "("; 7181da177e4SLinus Torvalds my $post = ","; 7191da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 7201da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 7211da177e4SLinus Torvalds $post = ");"; 7221da177e4SLinus Torvalds } 7231da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 724e86bdb24SAditya Srivastava if ($type =~ m/$function_pointer/) { 7251da177e4SLinus Torvalds # pointer-to-function 726ed8348e2SMauro Carvalho Chehab print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n"; 7271da177e4SLinus Torvalds } else { 7281da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 729ed8348e2SMauro Carvalho Chehab print ".BI \"" . $parenth . $type . "\" " . " \"" . $post . "\"\n"; 7301da177e4SLinus Torvalds } 7311da177e4SLinus Torvalds $count++; 7321da177e4SLinus Torvalds $parenth = ""; 7331da177e4SLinus Torvalds } 7341da177e4SLinus Torvalds 7351da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 7361da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7371da177e4SLinus Torvalds my $parameter_name = $parameter; 7381da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7391da177e4SLinus Torvalds 7401da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 7411da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7421da177e4SLinus Torvalds } 7431da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7441da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 7451da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7461da177e4SLinus Torvalds } 7471da177e4SLinus Torvalds} 7481da177e4SLinus Torvalds 7491da177e4SLinus Torvalds## 7501da177e4SLinus Torvalds# output enum in man 7511da177e4SLinus Torvaldssub output_enum_man(%) { 7521da177e4SLinus Torvalds my %args = %{$_[0]}; 7531da177e4SLinus Torvalds my ($parameter, $section); 7541da177e4SLinus Torvalds my $count; 7551da177e4SLinus Torvalds 7561da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 7571da177e4SLinus Torvalds 7581da177e4SLinus Torvalds print ".SH NAME\n"; 7591da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 7601da177e4SLinus Torvalds 7611da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 7621da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 7631da177e4SLinus Torvalds $count = 0; 7641da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 7651da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 7661da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 7671da177e4SLinus Torvalds print "\n};\n"; 7681da177e4SLinus Torvalds last; 7691da177e4SLinus Torvalds } 7701da177e4SLinus Torvalds else { 7711da177e4SLinus Torvalds print ", \n.br\n"; 7721da177e4SLinus Torvalds } 7731da177e4SLinus Torvalds $count++; 7741da177e4SLinus Torvalds } 7751da177e4SLinus Torvalds 7761da177e4SLinus Torvalds print ".SH Constants\n"; 7771da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7781da177e4SLinus Torvalds my $parameter_name = $parameter; 7791da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7801da177e4SLinus Torvalds 7811da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 7821da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7831da177e4SLinus Torvalds } 7841da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7851da177e4SLinus Torvalds print ".SH \"$section\"\n"; 7861da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7871da177e4SLinus Torvalds } 7881da177e4SLinus Torvalds} 7891da177e4SLinus Torvalds 7901da177e4SLinus Torvalds## 7911da177e4SLinus Torvalds# output struct in man 7921da177e4SLinus Torvaldssub output_struct_man(%) { 7931da177e4SLinus Torvalds my %args = %{$_[0]}; 7941da177e4SLinus Torvalds my ($parameter, $section); 7951da177e4SLinus Torvalds 7961da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 7971da177e4SLinus Torvalds 7981da177e4SLinus Torvalds print ".SH NAME\n"; 7991da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 8001da177e4SLinus Torvalds 8018ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 8028ad72163SMauro Carvalho Chehab $declaration =~ s/\t/ /g; 8038ad72163SMauro Carvalho Chehab $declaration =~ s/\n/"\n.br\n.BI \"/g; 8041da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 8051da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 8068ad72163SMauro Carvalho Chehab print ".BI \"$declaration\n};\n.br\n\n"; 8071da177e4SLinus Torvalds 808c51d3dacSRandy Dunlap print ".SH Members\n"; 8091da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 8101da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 8111da177e4SLinus Torvalds 8121da177e4SLinus Torvalds my $parameter_name = $parameter; 8131da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 8141da177e4SLinus Torvalds 8151da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 8161da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 8171da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 8181da177e4SLinus Torvalds } 8191da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 8201da177e4SLinus Torvalds print ".SH \"$section\"\n"; 8211da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 8221da177e4SLinus Torvalds } 8231da177e4SLinus Torvalds} 8241da177e4SLinus Torvalds 8251da177e4SLinus Torvalds## 8261da177e4SLinus Torvalds# output typedef in man 8271da177e4SLinus Torvaldssub output_typedef_man(%) { 8281da177e4SLinus Torvalds my %args = %{$_[0]}; 8291da177e4SLinus Torvalds my ($parameter, $section); 8301da177e4SLinus Torvalds 8311da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 8321da177e4SLinus Torvalds 8331da177e4SLinus Torvalds print ".SH NAME\n"; 8341da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 8351da177e4SLinus Torvalds 8361da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 8371da177e4SLinus Torvalds print ".SH \"$section\"\n"; 8381da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 8391da177e4SLinus Torvalds } 8401da177e4SLinus Torvalds} 8411da177e4SLinus Torvalds 842b112e0f7SJohannes Bergsub output_blockhead_man(%) { 8431da177e4SLinus Torvalds my %args = %{$_[0]}; 8441da177e4SLinus Torvalds my ($parameter, $section); 8451da177e4SLinus Torvalds my $count; 8461da177e4SLinus Torvalds 8471da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 8481da177e4SLinus Torvalds 8491da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 8501da177e4SLinus Torvalds print ".SH \"$section\"\n"; 8511da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 8521da177e4SLinus Torvalds } 8531da177e4SLinus Torvalds} 8541da177e4SLinus Torvalds 8551da177e4SLinus Torvalds## 856c0d1b6eeSJonathan Corbet# output in restructured text 857c0d1b6eeSJonathan Corbet# 858c0d1b6eeSJonathan Corbet 859c0d1b6eeSJonathan Corbet# 860c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 861c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 862c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 863c0d1b6eeSJonathan Corbet# 864c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 865c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 866c0d1b6eeSJonathan Corbet my ($parameter, $section); 867c0d1b6eeSJonathan Corbet 868c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 869eab795ddSMauro Carvalho Chehab next if (defined($nosymbol_table{$section})); 870eab795ddSMauro Carvalho Chehab 8719e72184bSJani Nikula if ($output_selection != OUTPUT_INCLUDE) { 87206a755d6SMichal Wajdeczko print ".. _$section:\n\n"; 873c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 8749e72184bSJani Nikula } 8750b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 876c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 877c0d1b6eeSJonathan Corbet print "\n"; 878c0d1b6eeSJonathan Corbet } 879c0d1b6eeSJonathan Corbet} 880c0d1b6eeSJonathan Corbet 881af250290SJonathan Corbet# 882af250290SJonathan Corbet# Apply the RST highlights to a sub-block of text. 883af250290SJonathan Corbet# 884af250290SJonathan Corbetsub highlight_block($) { 885af250290SJonathan Corbet # The dohighlight kludge requires the text be called $contents 886af250290SJonathan Corbet my $contents = shift; 887c0d1b6eeSJonathan Corbet eval $dohighlight; 888c0d1b6eeSJonathan Corbet die $@ if $@; 889af250290SJonathan Corbet return $contents; 890af250290SJonathan Corbet} 891c0d1b6eeSJonathan Corbet 892af250290SJonathan Corbet# 893af250290SJonathan Corbet# Regexes used only here. 894af250290SJonathan Corbet# 895af250290SJonathan Corbetmy $sphinx_literal = '^[^.].*::$'; 896af250290SJonathan Corbetmy $sphinx_cblock = '^\.\.\ +code-block::'; 897af250290SJonathan Corbet 898af250290SJonathan Corbetsub output_highlight_rst { 899af250290SJonathan Corbet my $input = join "\n",@_; 900af250290SJonathan Corbet my $output = ""; 901af250290SJonathan Corbet my $line; 902af250290SJonathan Corbet my $in_literal = 0; 903af250290SJonathan Corbet my $litprefix; 904af250290SJonathan Corbet my $block = ""; 905af250290SJonathan Corbet 906af250290SJonathan Corbet foreach $line (split "\n",$input) { 907af250290SJonathan Corbet # 908af250290SJonathan Corbet # If we're in a literal block, see if we should drop out 909af250290SJonathan Corbet # of it. Otherwise pass the line straight through unmunged. 910af250290SJonathan Corbet # 911af250290SJonathan Corbet if ($in_literal) { 912af250290SJonathan Corbet if (! ($line =~ /^\s*$/)) { 913af250290SJonathan Corbet # 914af250290SJonathan Corbet # If this is the first non-blank line in a literal 915af250290SJonathan Corbet # block we need to figure out what the proper indent is. 916af250290SJonathan Corbet # 917af250290SJonathan Corbet if ($litprefix eq "") { 918af250290SJonathan Corbet $line =~ /^(\s*)/; 919af250290SJonathan Corbet $litprefix = '^' . $1; 920af250290SJonathan Corbet $output .= $line . "\n"; 921af250290SJonathan Corbet } elsif (! ($line =~ /$litprefix/)) { 922af250290SJonathan Corbet $in_literal = 0; 923af250290SJonathan Corbet } else { 924af250290SJonathan Corbet $output .= $line . "\n"; 925af250290SJonathan Corbet } 926af250290SJonathan Corbet } else { 927af250290SJonathan Corbet $output .= $line . "\n"; 928af250290SJonathan Corbet } 929af250290SJonathan Corbet } 930af250290SJonathan Corbet # 931af250290SJonathan Corbet # Not in a literal block (or just dropped out) 932af250290SJonathan Corbet # 933af250290SJonathan Corbet if (! $in_literal) { 934af250290SJonathan Corbet $block .= $line . "\n"; 935af250290SJonathan Corbet if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) { 936af250290SJonathan Corbet $in_literal = 1; 937af250290SJonathan Corbet $litprefix = ""; 938af250290SJonathan Corbet $output .= highlight_block($block); 939af250290SJonathan Corbet $block = "" 940af250290SJonathan Corbet } 941af250290SJonathan Corbet } 942af250290SJonathan Corbet } 943af250290SJonathan Corbet 944af250290SJonathan Corbet if ($block) { 945af250290SJonathan Corbet $output .= highlight_block($block); 946af250290SJonathan Corbet } 947af250290SJonathan Corbet foreach $line (split "\n", $output) { 948830066a7SJani Nikula print $lineprefix . $line . "\n"; 949c0d1b6eeSJonathan Corbet } 950c0d1b6eeSJonathan Corbet} 951c0d1b6eeSJonathan Corbet 952c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 953c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 954c0d1b6eeSJonathan Corbet my ($parameter, $section); 955c099ff69SJani Nikula my $oldprefix = $lineprefix; 95682801d06SMauro Carvalho Chehab my $start = ""; 9576e9e4158SMauro Carvalho Chehab my $is_macro = 0; 958c0d1b6eeSJonathan Corbet 959efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 960e3ad05feSMauro Carvalho Chehab if ($args{'typedef'}) { 96182801d06SMauro Carvalho Chehab print ".. c:type:: ". $args{'function'} . "\n\n"; 96282801d06SMauro Carvalho Chehab print_lineno($declaration_start_line); 96382801d06SMauro Carvalho Chehab print " **Typedef**: "; 96482801d06SMauro Carvalho Chehab $lineprefix = ""; 96582801d06SMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 96682801d06SMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 9676e9e4158SMauro Carvalho Chehab $is_macro = 1; 968c0d1b6eeSJonathan Corbet } else { 96982801d06SMauro Carvalho Chehab print ".. c:function:: "; 97082801d06SMauro Carvalho Chehab } 971e3ad05feSMauro Carvalho Chehab } else { 9726e9e4158SMauro Carvalho Chehab if ($args{'typedef'} || $args{'functiontype'} eq "") { 9736e9e4158SMauro Carvalho Chehab $is_macro = 1; 974e3ad05feSMauro Carvalho Chehab print ".. c:macro:: ". $args{'function'} . "\n\n"; 9756e9e4158SMauro Carvalho Chehab } else { 9766e9e4158SMauro Carvalho Chehab print ".. c:function:: "; 9776e9e4158SMauro Carvalho Chehab } 978e3ad05feSMauro Carvalho Chehab 979e3ad05feSMauro Carvalho Chehab if ($args{'typedef'}) { 980e3ad05feSMauro Carvalho Chehab print_lineno($declaration_start_line); 981e3ad05feSMauro Carvalho Chehab print " **Typedef**: "; 982e3ad05feSMauro Carvalho Chehab $lineprefix = ""; 983e3ad05feSMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 984e3ad05feSMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 985e3ad05feSMauro Carvalho Chehab } else { 9866e9e4158SMauro Carvalho Chehab print "``" if ($is_macro); 987e3ad05feSMauro Carvalho Chehab } 988e3ad05feSMauro Carvalho Chehab } 98982801d06SMauro Carvalho Chehab if ($args{'functiontype'} ne "") { 99082801d06SMauro Carvalho Chehab $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; 99182801d06SMauro Carvalho Chehab } else { 99282801d06SMauro Carvalho Chehab $start .= $args{'function'} . " ("; 993c0d1b6eeSJonathan Corbet } 994c0d1b6eeSJonathan Corbet print $start; 995c0d1b6eeSJonathan Corbet 996c0d1b6eeSJonathan Corbet my $count = 0; 997c0d1b6eeSJonathan Corbet foreach my $parameter (@{$args{'parameterlist'}}) { 998c0d1b6eeSJonathan Corbet if ($count ne 0) { 999c0d1b6eeSJonathan Corbet print ", "; 1000c0d1b6eeSJonathan Corbet } 1001c0d1b6eeSJonathan Corbet $count++; 1002c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1003a88b1672SMauro Carvalho Chehab 1004e86bdb24SAditya Srivastava if ($type =~ m/$function_pointer/) { 1005c0d1b6eeSJonathan Corbet # pointer-to-function 1006e8f4ba83SPeter Maydell print $1 . $parameter . ") (" . $2 . ")"; 1007c0d1b6eeSJonathan Corbet } else { 1008ed8348e2SMauro Carvalho Chehab print $type; 1009c0d1b6eeSJonathan Corbet } 1010c0d1b6eeSJonathan Corbet } 10116e9e4158SMauro Carvalho Chehab if ($is_macro) { 10126e9e4158SMauro Carvalho Chehab print ")``\n\n"; 101382801d06SMauro Carvalho Chehab } else { 1014c099ff69SJani Nikula print ")\n\n"; 1015e3ad05feSMauro Carvalho Chehab } 10166e9e4158SMauro Carvalho Chehab if (!$args{'typedef'}) { 10170b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1018c099ff69SJani Nikula $lineprefix = " "; 1019c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1020c099ff69SJani Nikula print "\n"; 102182801d06SMauro Carvalho Chehab } 1022c0d1b6eeSJonathan Corbet 1023ecbcfba1SJani Nikula print "**Parameters**\n\n"; 1024c099ff69SJani Nikula $lineprefix = " "; 1025c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1026c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1027ada5f446SGabriel Krisman Bertazi $parameter_name =~ s/\[.*//; 1028c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1029c0d1b6eeSJonathan Corbet 1030c0d1b6eeSJonathan Corbet if ($type ne "") { 1031ed8348e2SMauro Carvalho Chehab print "``$type``\n"; 1032c0d1b6eeSJonathan Corbet } else { 1033c0d1b6eeSJonathan Corbet print "``$parameter``\n"; 1034c0d1b6eeSJonathan Corbet } 10350b0f5f29SDaniel Vetter 10360b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 10370b0f5f29SDaniel Vetter 10385e64fa9cSJani Nikula if (defined($args{'parameterdescs'}{$parameter_name}) && 10395e64fa9cSJani Nikula $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 1040c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1041c0d1b6eeSJonathan Corbet } else { 1042d4b08e0cSJani Nikula print " *undescribed*\n"; 1043c0d1b6eeSJonathan Corbet } 1044c0d1b6eeSJonathan Corbet print "\n"; 1045c0d1b6eeSJonathan Corbet } 1046c099ff69SJani Nikula 1047c099ff69SJani Nikula $lineprefix = $oldprefix; 1048c0d1b6eeSJonathan Corbet output_section_rst(@_); 1049c0d1b6eeSJonathan Corbet} 1050c0d1b6eeSJonathan Corbet 1051c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 1052c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1053c0d1b6eeSJonathan Corbet my $section; 1054c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1055c0d1b6eeSJonathan Corbet $lineprefix = ""; 1056c0d1b6eeSJonathan Corbet 1057c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 1058ecbcfba1SJani Nikula print "**$section**\n\n"; 10590b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 1060c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1061c0d1b6eeSJonathan Corbet print "\n"; 1062c0d1b6eeSJonathan Corbet } 1063c0d1b6eeSJonathan Corbet print "\n"; 1064c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1065c0d1b6eeSJonathan Corbet} 1066c0d1b6eeSJonathan Corbet 1067c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 1068c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1069c0d1b6eeSJonathan Corbet my ($parameter); 1070c099ff69SJani Nikula my $oldprefix = $lineprefix; 1071c0d1b6eeSJonathan Corbet my $count; 107262850976SJani Nikula 1073efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 1074efa44475SMauro Carvalho Chehab my $name = "enum " . $args{'enum'}; 107562850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1076efa44475SMauro Carvalho Chehab } else { 1077efa44475SMauro Carvalho Chehab my $name = $args{'enum'}; 1078efa44475SMauro Carvalho Chehab print "\n\n.. c:enum:: " . $name . "\n\n"; 1079efa44475SMauro Carvalho Chehab } 10800b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1081c099ff69SJani Nikula $lineprefix = " "; 1082c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1083c099ff69SJani Nikula print "\n"; 1084c0d1b6eeSJonathan Corbet 1085ecbcfba1SJani Nikula print "**Constants**\n\n"; 1086c0d1b6eeSJonathan Corbet $lineprefix = " "; 1087c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1088ecbcfba1SJani Nikula print "``$parameter``\n"; 1089c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 1090c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 1091c0d1b6eeSJonathan Corbet } else { 1092d4b08e0cSJani Nikula print " *undescribed*\n"; 1093c0d1b6eeSJonathan Corbet } 1094c0d1b6eeSJonathan Corbet print "\n"; 1095c0d1b6eeSJonathan Corbet } 1096c099ff69SJani Nikula 1097c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1098c0d1b6eeSJonathan Corbet output_section_rst(@_); 1099c0d1b6eeSJonathan Corbet} 1100c0d1b6eeSJonathan Corbet 1101c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 1102c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1103c0d1b6eeSJonathan Corbet my ($parameter); 1104c099ff69SJani Nikula my $oldprefix = $lineprefix; 1105efa44475SMauro Carvalho Chehab my $name; 1106c0d1b6eeSJonathan Corbet 1107efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 1108efa44475SMauro Carvalho Chehab $name = "typedef " . $args{'typedef'}; 1109efa44475SMauro Carvalho Chehab } else { 1110efa44475SMauro Carvalho Chehab $name = $args{'typedef'}; 1111efa44475SMauro Carvalho Chehab } 111262850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 11130b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1114c099ff69SJani Nikula $lineprefix = " "; 1115c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1116c099ff69SJani Nikula print "\n"; 1117c0d1b6eeSJonathan Corbet 1118c099ff69SJani Nikula $lineprefix = $oldprefix; 1119c0d1b6eeSJonathan Corbet output_section_rst(@_); 1120c0d1b6eeSJonathan Corbet} 1121c0d1b6eeSJonathan Corbet 1122c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 1123c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1124c0d1b6eeSJonathan Corbet my ($parameter); 1125c099ff69SJani Nikula my $oldprefix = $lineprefix; 1126c0d1b6eeSJonathan Corbet 1127efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 1128efa44475SMauro Carvalho Chehab my $name = $args{'type'} . " " . $args{'struct'}; 112962850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1130efa44475SMauro Carvalho Chehab } else { 1131efa44475SMauro Carvalho Chehab my $name = $args{'struct'}; 113272b97d0bSMauro Carvalho Chehab if ($args{'type'} eq 'union') { 113372b97d0bSMauro Carvalho Chehab print "\n\n.. c:union:: " . $name . "\n\n"; 113472b97d0bSMauro Carvalho Chehab } else { 1135efa44475SMauro Carvalho Chehab print "\n\n.. c:struct:: " . $name . "\n\n"; 1136efa44475SMauro Carvalho Chehab } 113772b97d0bSMauro Carvalho Chehab } 11380b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1139c099ff69SJani Nikula $lineprefix = " "; 1140c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1141c099ff69SJani Nikula print "\n"; 1142c0d1b6eeSJonathan Corbet 1143ecbcfba1SJani Nikula print "**Definition**\n\n"; 1144c0d1b6eeSJonathan Corbet print "::\n\n"; 11458ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 11468ad72163SMauro Carvalho Chehab $declaration =~ s/\t/ /g; 11478ad72163SMauro Carvalho Chehab print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n"; 1148c0d1b6eeSJonathan Corbet 1149ecbcfba1SJani Nikula print "**Members**\n\n"; 1150c099ff69SJani Nikula $lineprefix = " "; 1151c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1152c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 1153c0d1b6eeSJonathan Corbet 1154c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1155c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 1156c0d1b6eeSJonathan Corbet 1157c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1158c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 11590b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 11606d232c80SMauro Carvalho Chehab print "``" . $parameter . "``\n"; 1161c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1162c0d1b6eeSJonathan Corbet print "\n"; 1163c0d1b6eeSJonathan Corbet } 1164c0d1b6eeSJonathan Corbet print "\n"; 1165c099ff69SJani Nikula 1166c099ff69SJani Nikula $lineprefix = $oldprefix; 1167c0d1b6eeSJonathan Corbet output_section_rst(@_); 1168c0d1b6eeSJonathan Corbet} 1169c0d1b6eeSJonathan Corbet 11703a025e1dSMatthew Wilcox## none mode output functions 11713a025e1dSMatthew Wilcox 11723a025e1dSMatthew Wilcoxsub output_function_none(%) { 11733a025e1dSMatthew Wilcox} 11743a025e1dSMatthew Wilcox 11753a025e1dSMatthew Wilcoxsub output_enum_none(%) { 11763a025e1dSMatthew Wilcox} 11773a025e1dSMatthew Wilcox 11783a025e1dSMatthew Wilcoxsub output_typedef_none(%) { 11793a025e1dSMatthew Wilcox} 11803a025e1dSMatthew Wilcox 11813a025e1dSMatthew Wilcoxsub output_struct_none(%) { 11823a025e1dSMatthew Wilcox} 11833a025e1dSMatthew Wilcox 11843a025e1dSMatthew Wilcoxsub output_blockhead_none(%) { 11853a025e1dSMatthew Wilcox} 11863a025e1dSMatthew Wilcox 11871da177e4SLinus Torvalds## 118827205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 118927205744SRandy Dunlap# calls the generated, variable output_ function name based on 119027205744SRandy Dunlap# functype and output_mode 11911da177e4SLinus Torvaldssub output_declaration { 11921da177e4SLinus Torvalds no strict 'refs'; 11931da177e4SLinus Torvalds my $name = shift; 11941da177e4SLinus Torvalds my $functype = shift; 11951da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 1196eab795ddSMauro Carvalho Chehab 1197eab795ddSMauro Carvalho Chehab return if (defined($nosymbol_table{$name})); 1198eab795ddSMauro Carvalho Chehab 1199b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 1200b6c3f456SJani Nikula (($output_selection == OUTPUT_INCLUDE || 1201b6c3f456SJani Nikula $output_selection == OUTPUT_EXPORTED) && 120286ae2e38SJani Nikula defined($function_table{$name})) || 1203eab795ddSMauro Carvalho Chehab ($output_selection == OUTPUT_INTERNAL && 120486ae2e38SJani Nikula !($functype eq "function" && defined($function_table{$name})))) 12051da177e4SLinus Torvalds { 12061da177e4SLinus Torvalds &$func(@_); 12071da177e4SLinus Torvalds $section_counter++; 12081da177e4SLinus Torvalds } 12091da177e4SLinus Torvalds} 12101da177e4SLinus Torvalds 12111da177e4SLinus Torvalds## 121227205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 1213b112e0f7SJohannes Bergsub output_blockhead { 12141da177e4SLinus Torvalds no strict 'refs'; 1215b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 12161da177e4SLinus Torvalds &$func(@_); 12171da177e4SLinus Torvalds $section_counter++; 12181da177e4SLinus Torvalds} 12191da177e4SLinus Torvalds 12201da177e4SLinus Torvalds## 12211da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 12221da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 12231da177e4SLinus Torvaldssub dump_declaration($$) { 12241da177e4SLinus Torvalds no strict 'refs'; 12251da177e4SLinus Torvalds my ($prototype, $file) = @_; 12261da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 12271da177e4SLinus Torvalds &$func(@_); 12281da177e4SLinus Torvalds} 12291da177e4SLinus Torvalds 12301da177e4SLinus Torvaldssub dump_union($$) { 12311da177e4SLinus Torvalds dump_struct(@_); 12321da177e4SLinus Torvalds} 12331da177e4SLinus Torvalds 12341da177e4SLinus Torvaldssub dump_struct($$) { 12351da177e4SLinus Torvalds my $x = shift; 12361da177e4SLinus Torvalds my $file = shift; 1237a746fe32SAditya Srivastava my $decl_type; 1238a746fe32SAditya Srivastava my $members; 1239a746fe32SAditya Srivastava my $type = qr{struct|union}; 1240a746fe32SAditya Srivastava # For capturing struct/union definition body, i.e. "{members*}qualifiers*" 1241e86bdb24SAditya Srivastava my $qualifiers = qr{$attribute|__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned}; 1242e86bdb24SAditya Srivastava my $definition_body = qr{\{(.*)\}\s*$qualifiers*}; 1243e86bdb24SAditya Srivastava my $struct_members = qr{($type)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;}; 12441da177e4SLinus Torvalds 1245a746fe32SAditya Srivastava if ($x =~ /($type)\s+(\w+)\s*$definition_body/) { 1246a746fe32SAditya Srivastava $decl_type = $1; 12471da177e4SLinus Torvalds $declaration_name = $2; 1248a746fe32SAditya Srivastava $members = $3; 1249a746fe32SAditya Srivastava } elsif ($x =~ /typedef\s+($type)\s*$definition_body\s*(\w+)\s*;/) { 1250a746fe32SAditya Srivastava $decl_type = $1; 1251a746fe32SAditya Srivastava $declaration_name = $3; 1252a746fe32SAditya Srivastava $members = $2; 1253a746fe32SAditya Srivastava } 12541da177e4SLinus Torvalds 1255a746fe32SAditya Srivastava if ($members) { 125652042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 125752042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: expecting prototype for $decl_type $identifier. Prototype was for $decl_type $declaration_name instead\n"; 125852042e2dSMauro Carvalho Chehab return; 125952042e2dSMauro Carvalho Chehab } 126052042e2dSMauro Carvalho Chehab 1261aeec46b9SMartin Waitz # ignore members marked private: 12620d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 12630d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 1264aeec46b9SMartin Waitz # strip comments: 1265aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 1266ef5da59fSRandy Dunlap # strip attributes 1267e86bdb24SAditya Srivastava $members =~ s/\s*$attribute/ /gi; 12683d9bfb19SSakari Ailus $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos; 12693d9bfb19SSakari Ailus $members =~ s/\s*__packed\s*/ /gos; 1270f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos; 1271f861537dSAndré Almeida $members =~ s/\s*____cacheline_aligned_in_smp/ /gos; 1272a070991fSJonathan Cameron $members =~ s/\s*____cacheline_aligned/ /gos; 127350d7bd38SKees Cook # unwrap struct_group(): 127450d7bd38SKees Cook # - first eat non-declaration parameters and rewrite for final match 127550d7bd38SKees Cook # - then remove macro, outer parens, and trailing semicolon 127650d7bd38SKees Cook $members =~ s/\bstruct_group\s*\(([^,]*,)/STRUCT_GROUP(/gos; 127750d7bd38SKees Cook $members =~ s/\bstruct_group_(attr|tagged)\s*\(([^,]*,){2}/STRUCT_GROUP(/gos; 127850d7bd38SKees Cook $members =~ s/\b__struct_group\s*\(([^,]*,){3}/STRUCT_GROUP(/gos; 127950d7bd38SKees Cook $members =~ s/\bSTRUCT_GROUP(\(((?:(?>[^)(]+)|(?1))*)\))[^;]*;/$2/gos; 12803556108eSMauro Carvalho Chehab 1281e86bdb24SAditya Srivastava my $args = qr{([^,)]+)}; 1282b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 12833556108eSMauro Carvalho Chehab $members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos; 1284603bdf5dSRandy Dunlap $members =~ s/DECLARE_PHY_INTERFACE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, PHY_INTERFACE_MODE_MAX)/gos; 1285e86bdb24SAditya Srivastava $members =~ s/DECLARE_BITMAP\s*\($args,\s*$args\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 12861cb566baSJakub Kicinski # replace DECLARE_HASHTABLE 1287e86bdb24SAditya Srivastava $members =~ s/DECLARE_HASHTABLE\s*\($args,\s*$args\)/unsigned long $1\[1 << (($2) - 1)\]/gos; 128845005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO 1289e86bdb24SAditya Srivastava $members =~ s/DECLARE_KFIFO\s*\($args,\s*$args,\s*$args\)/$2 \*$1/gos; 129045005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO_PTR 1291e86bdb24SAditya Srivastava $members =~ s/DECLARE_KFIFO_PTR\s*\($args,\s*$args\)/$2 \*$1/gos; 12923080ea55SKees Cook # replace DECLARE_FLEX_ARRAY 12933080ea55SKees Cook $members =~ s/(?:__)?DECLARE_FLEX_ARRAY\s*\($args,\s*$args\)/$1 $2\[\]/gos; 12948ad72163SMauro Carvalho Chehab my $declaration = $members; 12958ad72163SMauro Carvalho Chehab 12968ad72163SMauro Carvalho Chehab # Split nested struct/union elements as newer ones 1297e86bdb24SAditya Srivastava while ($members =~ m/$struct_members/) { 129884ce5b98SMauro Carvalho Chehab my $newmember; 129984ce5b98SMauro Carvalho Chehab my $maintype = $1; 130084ce5b98SMauro Carvalho Chehab my $ids = $4; 13018ad72163SMauro Carvalho Chehab my $content = $3; 130284ce5b98SMauro Carvalho Chehab foreach my $id(split /,/, $ids) { 130384ce5b98SMauro Carvalho Chehab $newmember .= "$maintype $id; "; 130484ce5b98SMauro Carvalho Chehab 13058ad72163SMauro Carvalho Chehab $id =~ s/[:\[].*//; 130684ce5b98SMauro Carvalho Chehab $id =~ s/^\s*\**(\S+)\s*/$1/; 13078ad72163SMauro Carvalho Chehab foreach my $arg (split /;/, $content) { 13088ad72163SMauro Carvalho Chehab next if ($arg =~ m/^\s*$/); 13097c0d7e87SMauro Carvalho Chehab if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) { 13107c0d7e87SMauro Carvalho Chehab # pointer-to-function 13117c0d7e87SMauro Carvalho Chehab my $type = $1; 13127c0d7e87SMauro Carvalho Chehab my $name = $2; 13137c0d7e87SMauro Carvalho Chehab my $extra = $3; 13147c0d7e87SMauro Carvalho Chehab next if (!$name); 13157c0d7e87SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 13167c0d7e87SMauro Carvalho Chehab # anonymous struct/union 13177c0d7e87SMauro Carvalho Chehab $newmember .= "$type$name$extra; "; 13187c0d7e87SMauro Carvalho Chehab } else { 13197c0d7e87SMauro Carvalho Chehab $newmember .= "$type$id.$name$extra; "; 13207c0d7e87SMauro Carvalho Chehab } 13217c0d7e87SMauro Carvalho Chehab } else { 132284ce5b98SMauro Carvalho Chehab my $type; 132384ce5b98SMauro Carvalho Chehab my $names; 132484ce5b98SMauro Carvalho Chehab $arg =~ s/^\s+//; 132584ce5b98SMauro Carvalho Chehab $arg =~ s/\s+$//; 132684ce5b98SMauro Carvalho Chehab # Handle bitmaps 132784ce5b98SMauro Carvalho Chehab $arg =~ s/:\s*\d+\s*//g; 132884ce5b98SMauro Carvalho Chehab # Handle arrays 1329d404d579SMauro Carvalho Chehab $arg =~ s/\[.*\]//g; 133084ce5b98SMauro Carvalho Chehab # The type may have multiple words, 133184ce5b98SMauro Carvalho Chehab # and multiple IDs can be defined, like: 133284ce5b98SMauro Carvalho Chehab # const struct foo, *bar, foobar 133384ce5b98SMauro Carvalho Chehab # So, we remove spaces when parsing the 133484ce5b98SMauro Carvalho Chehab # names, in order to match just names 133584ce5b98SMauro Carvalho Chehab # and commas for the names 133684ce5b98SMauro Carvalho Chehab $arg =~ s/\s*,\s*/,/g; 133784ce5b98SMauro Carvalho Chehab if ($arg =~ m/(.*)\s+([\S+,]+)/) { 133884ce5b98SMauro Carvalho Chehab $type = $1; 133984ce5b98SMauro Carvalho Chehab $names = $2; 134084ce5b98SMauro Carvalho Chehab } else { 134184ce5b98SMauro Carvalho Chehab $newmember .= "$arg; "; 134284ce5b98SMauro Carvalho Chehab next; 134384ce5b98SMauro Carvalho Chehab } 134484ce5b98SMauro Carvalho Chehab foreach my $name (split /,/, $names) { 134584ce5b98SMauro Carvalho Chehab $name =~ s/^\s*\**(\S+)\s*/$1/; 13468ad72163SMauro Carvalho Chehab next if (($name =~ m/^\s*$/)); 13478ad72163SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 13488ad72163SMauro Carvalho Chehab # anonymous struct/union 13498ad72163SMauro Carvalho Chehab $newmember .= "$type $name; "; 13508ad72163SMauro Carvalho Chehab } else { 13518ad72163SMauro Carvalho Chehab $newmember .= "$type $id.$name; "; 13528ad72163SMauro Carvalho Chehab } 13538ad72163SMauro Carvalho Chehab } 13547c0d7e87SMauro Carvalho Chehab } 135584ce5b98SMauro Carvalho Chehab } 135684ce5b98SMauro Carvalho Chehab } 1357e86bdb24SAditya Srivastava $members =~ s/$struct_members/$newmember/; 135884ce5b98SMauro Carvalho Chehab } 13598ad72163SMauro Carvalho Chehab 13608ad72163SMauro Carvalho Chehab # Ignore other nested elements, like enums 1361673bb2dfSBen Hutchings $members =~ s/(\{[^\{\}]*\})//g; 13628ad72163SMauro Carvalho Chehab 1363151c468bSMauro Carvalho Chehab create_parameterlist($members, ';', $file, $declaration_name); 13641081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual); 13651da177e4SLinus Torvalds 13668ad72163SMauro Carvalho Chehab # Adjust declaration for better display 1367673bb2dfSBen Hutchings $declaration =~ s/([\{;])/$1\n/g; 1368673bb2dfSBen Hutchings $declaration =~ s/\}\s+;/};/g; 13698ad72163SMauro Carvalho Chehab # Better handle inlined enums 1370673bb2dfSBen Hutchings do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/); 13718ad72163SMauro Carvalho Chehab 13728ad72163SMauro Carvalho Chehab my @def_args = split /\n/, $declaration; 13738ad72163SMauro Carvalho Chehab my $level = 1; 13748ad72163SMauro Carvalho Chehab $declaration = ""; 13758ad72163SMauro Carvalho Chehab foreach my $clause (@def_args) { 13768ad72163SMauro Carvalho Chehab $clause =~ s/^\s+//; 13778ad72163SMauro Carvalho Chehab $clause =~ s/\s+$//; 13788ad72163SMauro Carvalho Chehab $clause =~ s/\s+/ /; 13798ad72163SMauro Carvalho Chehab next if (!$clause); 1380673bb2dfSBen Hutchings $level-- if ($clause =~ m/(\})/ && $level > 1); 13818ad72163SMauro Carvalho Chehab if (!($clause =~ m/^\s*#/)) { 13828ad72163SMauro Carvalho Chehab $declaration .= "\t" x $level; 13838ad72163SMauro Carvalho Chehab } 13848ad72163SMauro Carvalho Chehab $declaration .= "\t" . $clause . "\n"; 1385673bb2dfSBen Hutchings $level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/)); 13868ad72163SMauro Carvalho Chehab } 13871da177e4SLinus Torvalds output_declaration($declaration_name, 13881da177e4SLinus Torvalds 'struct', 13891da177e4SLinus Torvalds {'struct' => $declaration_name, 13901da177e4SLinus Torvalds 'module' => $modulename, 13918ad72163SMauro Carvalho Chehab 'definition' => $declaration, 13921da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 13931da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 13941da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 13951da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 13961da177e4SLinus Torvalds 'sections' => \%sections, 13971da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 13981da177e4SLinus Torvalds 'type' => $decl_type 13991da177e4SLinus Torvalds }); 14001da177e4SLinus Torvalds } 14011da177e4SLinus Torvalds else { 1402d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 14031da177e4SLinus Torvalds ++$errors; 14041da177e4SLinus Torvalds } 14051da177e4SLinus Torvalds} 14061da177e4SLinus Torvalds 140785afe608SMauro Carvalho Chehab 140885afe608SMauro Carvalho Chehabsub show_warnings($$) { 140985afe608SMauro Carvalho Chehab my $functype = shift; 141085afe608SMauro Carvalho Chehab my $name = shift; 141185afe608SMauro Carvalho Chehab 1412eab795ddSMauro Carvalho Chehab return 0 if (defined($nosymbol_table{$name})); 1413eab795ddSMauro Carvalho Chehab 141485afe608SMauro Carvalho Chehab return 1 if ($output_selection == OUTPUT_ALL); 141585afe608SMauro Carvalho Chehab 141685afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_EXPORTED) { 141785afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 141885afe608SMauro Carvalho Chehab return 1; 141985afe608SMauro Carvalho Chehab } else { 142085afe608SMauro Carvalho Chehab return 0; 142185afe608SMauro Carvalho Chehab } 142285afe608SMauro Carvalho Chehab } 142385afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_INTERNAL) { 142485afe608SMauro Carvalho Chehab if (!($functype eq "function" && defined($function_table{$name}))) { 142585afe608SMauro Carvalho Chehab return 1; 142685afe608SMauro Carvalho Chehab } else { 142785afe608SMauro Carvalho Chehab return 0; 142885afe608SMauro Carvalho Chehab } 142985afe608SMauro Carvalho Chehab } 143085afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_INCLUDE) { 143185afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 143285afe608SMauro Carvalho Chehab return 1; 143385afe608SMauro Carvalho Chehab } else { 143485afe608SMauro Carvalho Chehab return 0; 143585afe608SMauro Carvalho Chehab } 143685afe608SMauro Carvalho Chehab } 143785afe608SMauro Carvalho Chehab die("Please add the new output type at show_warnings()"); 143885afe608SMauro Carvalho Chehab} 143985afe608SMauro Carvalho Chehab 14401da177e4SLinus Torvaldssub dump_enum($$) { 14411da177e4SLinus Torvalds my $x = shift; 14421da177e4SLinus Torvalds my $file = shift; 1443d38c8cfbSMauro Carvalho Chehab my $members; 1444d38c8cfbSMauro Carvalho Chehab 14451da177e4SLinus Torvalds 1446aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 14474468e21eSConchúr Navid # strip #define macros inside enums 14484468e21eSConchúr Navid $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 1449b6d676dbSRandy Dunlap 1450d38c8cfbSMauro Carvalho Chehab if ($x =~ /typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;/) { 1451d38c8cfbSMauro Carvalho Chehab $declaration_name = $2; 1452d38c8cfbSMauro Carvalho Chehab $members = $1; 1453d38c8cfbSMauro Carvalho Chehab } elsif ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) { 14541da177e4SLinus Torvalds $declaration_name = $1; 1455d38c8cfbSMauro Carvalho Chehab $members = $2; 1456d38c8cfbSMauro Carvalho Chehab } 1457d38c8cfbSMauro Carvalho Chehab 1458ae5b17e4SAndy Shevchenko if ($members) { 145952042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 14600b54c2e3SMauro Carvalho Chehab if ($identifier eq "") { 14610b54c2e3SMauro Carvalho Chehab print STDERR "${file}:$.: warning: wrong kernel-doc identifier on line:\n"; 14620b54c2e3SMauro Carvalho Chehab } else { 146352042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: expecting prototype for enum $identifier. Prototype was for enum $declaration_name instead\n"; 14640b54c2e3SMauro Carvalho Chehab } 146552042e2dSMauro Carvalho Chehab return; 146652042e2dSMauro Carvalho Chehab } 14670b54c2e3SMauro Carvalho Chehab $declaration_name = "(anonymous)" if ($declaration_name eq ""); 146852042e2dSMauro Carvalho Chehab 14695cb5c31cSJohannes Berg my %_members; 14705cb5c31cSJohannes Berg 1471463a0fdcSMarkus Heiser $members =~ s/\s+$//; 14721da177e4SLinus Torvalds 14731da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 14741da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 14751da177e4SLinus Torvalds push @parameterlist, $arg; 14761da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 14771da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 147885afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 14792defb272SMauro Carvalho Chehab print STDERR "${file}:$.: warning: Enum value '$arg' not described in enum '$declaration_name'\n"; 14802defb272SMauro Carvalho Chehab } 14811da177e4SLinus Torvalds } 14825cb5c31cSJohannes Berg $_members{$arg} = 1; 14835cb5c31cSJohannes Berg } 14841da177e4SLinus Torvalds 14855cb5c31cSJohannes Berg while (my ($k, $v) = each %parameterdescs) { 14865cb5c31cSJohannes Berg if (!exists($_members{$k})) { 148785afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 14882defb272SMauro Carvalho Chehab print STDERR "${file}:$.: warning: Excess enum value '$k' description in '$declaration_name'\n"; 14892defb272SMauro Carvalho Chehab } 14905cb5c31cSJohannes Berg } 14911da177e4SLinus Torvalds } 14921da177e4SLinus Torvalds 14931da177e4SLinus Torvalds output_declaration($declaration_name, 14941da177e4SLinus Torvalds 'enum', 14951da177e4SLinus Torvalds {'enum' => $declaration_name, 14961da177e4SLinus Torvalds 'module' => $modulename, 14971da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 14981da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 14991da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 15001da177e4SLinus Torvalds 'sections' => \%sections, 15011da177e4SLinus Torvalds 'purpose' => $declaration_purpose 15021da177e4SLinus Torvalds }); 1503d38c8cfbSMauro Carvalho Chehab } else { 1504d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 15051da177e4SLinus Torvalds ++$errors; 15061da177e4SLinus Torvalds } 15071da177e4SLinus Torvalds} 15081da177e4SLinus Torvalds 15097d2c6b1eSMauro Carvalho Chehabmy $typedef_type = qr { ((?:\s+[\w\*]+\b){1,8})\s* }x; 15107efc6c42SMauro Carvalho Chehabmy $typedef_ident = qr { \*?\s*(\w\S+)\s* }x; 15117efc6c42SMauro Carvalho Chehabmy $typedef_args = qr { \s*\((.*)\); }x; 15127efc6c42SMauro Carvalho Chehab 15137efc6c42SMauro Carvalho Chehabmy $typedef1 = qr { typedef$typedef_type\($typedef_ident\)$typedef_args }x; 15147efc6c42SMauro Carvalho Chehabmy $typedef2 = qr { typedef$typedef_type$typedef_ident$typedef_args }x; 15157efc6c42SMauro Carvalho Chehab 15161da177e4SLinus Torvaldssub dump_typedef($$) { 15171da177e4SLinus Torvalds my $x = shift; 15181da177e4SLinus Torvalds my $file = shift; 15191da177e4SLinus Torvalds 1520aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 152183766452SMauro Carvalho Chehab 15227efc6c42SMauro Carvalho Chehab # Parse function typedef prototypes 15237efc6c42SMauro Carvalho Chehab if ($x =~ $typedef1 || $x =~ $typedef2) { 152483766452SMauro Carvalho Chehab $return_type = $1; 152583766452SMauro Carvalho Chehab $declaration_name = $2; 152683766452SMauro Carvalho Chehab my $args = $3; 15276b80975cSMauro Carvalho Chehab $return_type =~ s/^\s+//; 152883766452SMauro Carvalho Chehab 152952042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 153052042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n"; 153152042e2dSMauro Carvalho Chehab return; 153252042e2dSMauro Carvalho Chehab } 153352042e2dSMauro Carvalho Chehab 1534151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 153583766452SMauro Carvalho Chehab 153683766452SMauro Carvalho Chehab output_declaration($declaration_name, 153783766452SMauro Carvalho Chehab 'function', 153883766452SMauro Carvalho Chehab {'function' => $declaration_name, 153982801d06SMauro Carvalho Chehab 'typedef' => 1, 154083766452SMauro Carvalho Chehab 'module' => $modulename, 154183766452SMauro Carvalho Chehab 'functiontype' => $return_type, 154283766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 154383766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 154483766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 154583766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 154683766452SMauro Carvalho Chehab 'sections' => \%sections, 154783766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 154883766452SMauro Carvalho Chehab }); 154983766452SMauro Carvalho Chehab return; 155083766452SMauro Carvalho Chehab } 155183766452SMauro Carvalho Chehab 15521da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 15531da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 15541da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 15551da177e4SLinus Torvalds } 15561da177e4SLinus Torvalds 15571da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 15581da177e4SLinus Torvalds $declaration_name = $1; 15591da177e4SLinus Torvalds 156052042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 156152042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n"; 156252042e2dSMauro Carvalho Chehab return; 156352042e2dSMauro Carvalho Chehab } 156452042e2dSMauro Carvalho Chehab 15651da177e4SLinus Torvalds output_declaration($declaration_name, 15661da177e4SLinus Torvalds 'typedef', 15671da177e4SLinus Torvalds {'typedef' => $declaration_name, 15681da177e4SLinus Torvalds 'module' => $modulename, 15691da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 15701da177e4SLinus Torvalds 'sections' => \%sections, 15711da177e4SLinus Torvalds 'purpose' => $declaration_purpose 15721da177e4SLinus Torvalds }); 15731da177e4SLinus Torvalds } 15741da177e4SLinus Torvalds else { 1575d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 15761da177e4SLinus Torvalds ++$errors; 15771da177e4SLinus Torvalds } 15781da177e4SLinus Torvalds} 15791da177e4SLinus Torvalds 1580a1d94aa5SRandy Dunlapsub save_struct_actual($) { 1581a1d94aa5SRandy Dunlap my $actual = shift; 1582a1d94aa5SRandy Dunlap 1583a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 1584a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 1585a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 1586a1d94aa5SRandy Dunlap} 1587a1d94aa5SRandy Dunlap 1588151c468bSMauro Carvalho Chehabsub create_parameterlist($$$$) { 15891da177e4SLinus Torvalds my $args = shift; 15901da177e4SLinus Torvalds my $splitter = shift; 15911da177e4SLinus Torvalds my $file = shift; 1592151c468bSMauro Carvalho Chehab my $declaration_name = shift; 15931da177e4SLinus Torvalds my $type; 15941da177e4SLinus Torvalds my $param; 15951da177e4SLinus Torvalds 1596a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 1597e86bdb24SAditya Srivastava my $arg_expr = qr{\([^\),]+}; 1598e86bdb24SAditya Srivastava while ($args =~ /$arg_expr,/) { 1599e86bdb24SAditya Srivastava $args =~ s/($arg_expr),/$1#/g; 16001da177e4SLinus Torvalds } 16011da177e4SLinus Torvalds 16021da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 16031da177e4SLinus Torvalds # strip comments 16041da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 16051da177e4SLinus Torvalds # strip leading/trailing spaces 16061da177e4SLinus Torvalds $arg =~ s/^\s*//; 16071da177e4SLinus Torvalds $arg =~ s/\s*$//; 16081da177e4SLinus Torvalds $arg =~ s/\s+/ /; 16091da177e4SLinus Torvalds 16101da177e4SLinus Torvalds if ($arg =~ /^#/) { 16111da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 16121da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 16131da177e4SLinus Torvalds # output_* subs. 1614ed8348e2SMauro Carvalho Chehab push_parameter($arg, "", "", $file); 161500d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 16161da177e4SLinus Torvalds # pointer-to-function 16171da177e4SLinus Torvalds $arg =~ tr/#/,/; 1618336ced2dSAditya Srivastava $arg =~ m/[^\(]+\(\*?\s*([\w\[\]\.]*)\s*\)/; 16191da177e4SLinus Torvalds $param = $1; 16201da177e4SLinus Torvalds $type = $arg; 162100d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1622a1d94aa5SRandy Dunlap save_struct_actual($param); 1623ed8348e2SMauro Carvalho Chehab push_parameter($param, $type, $arg, $file, $declaration_name); 1624aeec46b9SMartin Waitz } elsif ($arg) { 16251da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 16261da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 16271da177e4SLinus Torvalds 16281da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 16291da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 16301da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 16311da177e4SLinus Torvalds } 1632884f2810SBorislav Petkov 1633884f2810SBorislav Petkov my @first_arg; 1634884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1635884f2810SBorislav Petkov shift @args; 1636884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 1637884f2810SBorislav Petkov push(@first_arg, $2); 1638884f2810SBorislav Petkov } else { 1639884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 1640884f2810SBorislav Petkov } 1641884f2810SBorislav Petkov 16421da177e4SLinus Torvalds unshift(@args, pop @first_arg); 16431da177e4SLinus Torvalds $type = join " ", @first_arg; 16441da177e4SLinus Torvalds 16451da177e4SLinus Torvalds foreach $param (@args) { 16461da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 1647a1d94aa5SRandy Dunlap save_struct_actual($2); 1648ed8348e2SMauro Carvalho Chehab 1649ed8348e2SMauro Carvalho Chehab push_parameter($2, "$type $1", $arg, $file, $declaration_name); 16501da177e4SLinus Torvalds } 16511da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 16527b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 1653a1d94aa5SRandy Dunlap save_struct_actual($1); 1654ed8348e2SMauro Carvalho Chehab push_parameter($1, "$type:$2", $arg, $file, $declaration_name) 16551da177e4SLinus Torvalds } 16567b97887eSRandy Dunlap } 16571da177e4SLinus Torvalds else { 1658a1d94aa5SRandy Dunlap save_struct_actual($param); 1659ed8348e2SMauro Carvalho Chehab push_parameter($param, $type, $arg, $file, $declaration_name); 16601da177e4SLinus Torvalds } 16611da177e4SLinus Torvalds } 16621da177e4SLinus Torvalds } 16631da177e4SLinus Torvalds } 16641da177e4SLinus Torvalds} 16651da177e4SLinus Torvalds 1666ed8348e2SMauro Carvalho Chehabsub push_parameter($$$$$) { 16671da177e4SLinus Torvalds my $param = shift; 16681da177e4SLinus Torvalds my $type = shift; 1669ed8348e2SMauro Carvalho Chehab my $org_arg = shift; 16701da177e4SLinus Torvalds my $file = shift; 1671151c468bSMauro Carvalho Chehab my $declaration_name = shift; 16721da177e4SLinus Torvalds 16735f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 16745f8c7c98SRandy Dunlap ($param eq "}")) { 16755f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 16765f8c7c98SRandy Dunlap } 16775f8c7c98SRandy Dunlap 16785f8c7c98SRandy Dunlap $anon_struct_union = 0; 1679f9b5c530SMauro Carvalho Chehab $param =~ s/[\[\)].*//; 16801da177e4SLinus Torvalds 1681a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 16821da177e4SLinus Torvalds { 1683c950a173SSilvio Fricke if (!$param =~ /\w\.\.\.$/) { 1684c950a173SSilvio Fricke # handles unnamed variable parameters 1685ef00028bSJonathan Corbet $param = "..."; 1686c950a173SSilvio Fricke } 168743756e34SJonathan Neuschäfer elsif ($param =~ /\w\.\.\.$/) { 168843756e34SJonathan Neuschäfer # for named variable parameters of the form `x...`, remove the dots 168943756e34SJonathan Neuschäfer $param =~ s/\.\.\.$//; 169043756e34SJonathan Neuschäfer } 1691ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1692a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 16931da177e4SLinus Torvalds } 1694ced69090SRandy Dunlap } 16951da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 16961da177e4SLinus Torvalds { 16971da177e4SLinus Torvalds $param="void"; 16981da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 16991da177e4SLinus Torvalds } 1700134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1701134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 1702134fe01bSRandy Dunlap { 1703134fe01bSRandy Dunlap $type = $param; 1704134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 1705134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 17065f8c7c98SRandy Dunlap $anon_struct_union = 1; 1707134fe01bSRandy Dunlap } 1708134fe01bSRandy Dunlap 1709a6d3fe77SMartin Waitz # warn if parameter has no description 1710134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 1711134fe01bSRandy Dunlap # but inline preprocessor statements); 1712151c468bSMauro Carvalho Chehab # Note: It will also ignore void params and unnamed structs/unions 1713f9b5c530SMauro Carvalho Chehab if (!defined $parameterdescs{$param} && $param !~ /^#/) { 1714f9b5c530SMauro Carvalho Chehab $parameterdescs{$param} = $undescribed; 17151da177e4SLinus Torvalds 1716be5cd20cSJonathan Corbet if (show_warnings($type, $declaration_name) && $param !~ /\./) { 1717151c468bSMauro Carvalho Chehab print STDERR 1718151c468bSMauro Carvalho Chehab "${file}:$.: warning: Function parameter or member '$param' not described in '$declaration_name'\n"; 17191da177e4SLinus Torvalds ++$warnings; 17201da177e4SLinus Torvalds } 17212defb272SMauro Carvalho Chehab } 17221da177e4SLinus Torvalds 172325985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 1724e34e7dbbSRandy Dunlap # on @parameterlist; 1725e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 1726e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 1727e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 1728e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 1729e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 1730e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 1731e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 17321da177e4SLinus Torvalds push @parameterlist, $param; 1733ed8348e2SMauro Carvalho Chehab $org_arg =~ s/\s\s+/ /g; 1734ed8348e2SMauro Carvalho Chehab $parametertypes{$param} = $org_arg; 17351da177e4SLinus Torvalds} 17361da177e4SLinus Torvalds 17371081de2dSMauro Carvalho Chehabsub check_sections($$$$$) { 17381081de2dSMauro Carvalho Chehab my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_; 1739a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 1740a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 1741a1d94aa5SRandy Dunlap my $err; 1742a1d94aa5SRandy Dunlap my ($px, $sx); 1743a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 1744a1d94aa5SRandy Dunlap 1745a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 1746a1d94aa5SRandy Dunlap $err = 1; 1747a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 1748a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 1749a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 1750e86bdb24SAditya Srivastava $prm_clean =~ s/$attribute//i; 1751e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 1752e34e7dbbSRandy Dunlap # however, the original param string may contain 1753e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 1754e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 1755e34e7dbbSRandy Dunlap # parameter list is split at spaces; 1756e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 1757e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 1758e34e7dbbSRandy Dunlap 1759a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 1760a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 1761a1d94aa5SRandy Dunlap $err = 0; 1762a1d94aa5SRandy Dunlap last; 1763a1d94aa5SRandy Dunlap } 1764a1d94aa5SRandy Dunlap } 1765a1d94aa5SRandy Dunlap if ($err) { 1766a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 1767d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 1768a1d94aa5SRandy Dunlap "Excess function parameter " . 1769a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 1770a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 1771a1d94aa5SRandy Dunlap ++$warnings; 1772a1d94aa5SRandy Dunlap } 1773a1d94aa5SRandy Dunlap } 1774a1d94aa5SRandy Dunlap } 1775a1d94aa5SRandy Dunlap} 1776a1d94aa5SRandy Dunlap 17771da177e4SLinus Torvalds## 17784092bac7SYacine Belkadi# Checks the section describing the return value of a function. 17794092bac7SYacine Belkadisub check_return_section { 17804092bac7SYacine Belkadi my $file = shift; 17814092bac7SYacine Belkadi my $declaration_name = shift; 17824092bac7SYacine Belkadi my $return_type = shift; 17834092bac7SYacine Belkadi 17844092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 17854092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 17864092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 17874092bac7SYacine Belkadi return; 17884092bac7SYacine Belkadi } 17894092bac7SYacine Belkadi 17904092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 17914092bac7SYacine Belkadi $sections{$section_return} eq "") { 1792d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 17934092bac7SYacine Belkadi "No description found for return value of " . 17944092bac7SYacine Belkadi "'$declaration_name'\n"; 17954092bac7SYacine Belkadi ++$warnings; 17964092bac7SYacine Belkadi } 17974092bac7SYacine Belkadi} 17984092bac7SYacine Belkadi 17994092bac7SYacine Belkadi## 18001da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 18011da177e4SLinus Torvalds# processed and spits out all the details stored in the global 18021da177e4SLinus Torvalds# arrays/hashes. 18031da177e4SLinus Torvaldssub dump_function($$) { 18041da177e4SLinus Torvalds my $prototype = shift; 18051da177e4SLinus Torvalds my $file = shift; 1806cbb4d3e6SHoria Geanta my $noret = 0; 18071da177e4SLinus Torvalds 18085ef09c96SMauro Carvalho Chehab print_lineno($new_start_line); 18095eb6b4b3SMauro Carvalho Chehab 18101da177e4SLinus Torvalds $prototype =~ s/^static +//; 18111da177e4SLinus Torvalds $prototype =~ s/^extern +//; 18124dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 18131da177e4SLinus Torvalds $prototype =~ s/^inline +//; 18141da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 181532e79401SRandy Dunlap $prototype =~ s/^__inline +//; 181632e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 181732e79401SRandy Dunlap $prototype =~ s/^noinline +//; 181874fc5c65SRandy Dunlap $prototype =~ s/__init +//; 181920072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 182080342d48SMatthew Wilcox $prototype =~ s/__deprecated +//; 1821084aa001SAditya Srivastava $prototype =~ s/__flatten +//; 1822270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 182370c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 18240df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 18250891f959SMatthew Wilcox $prototype =~ s/__sched +//; 182695e760cbSRandy Dunlap $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//; 1827a40a8a11SKees Cook $prototype =~ s/__alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +//; 1828cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 1829084aa001SAditya Srivastava $prototype =~ s/__attribute_const__ +//; 1830b1aaa546SPaolo Bonzini $prototype =~ s/__attribute__\s*\(\( 1831b1aaa546SPaolo Bonzini (?: 1832b1aaa546SPaolo Bonzini [\w\s]++ # attribute name 1833b1aaa546SPaolo Bonzini (?:\([^)]*+\))? # attribute arguments 1834b1aaa546SPaolo Bonzini \s*+,? # optional comma at the end 1835b1aaa546SPaolo Bonzini )+ 1836b1aaa546SPaolo Bonzini \)\)\s+//x; 18371da177e4SLinus Torvalds 18381da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 18391da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 18401da177e4SLinus Torvalds # 2. Function name 18411da177e4SLinus Torvalds # 3. Function parameters. 18421da177e4SLinus Torvalds # 18431da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 18441da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 18451da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 18461da177e4SLinus Torvalds # so on. 18471da177e4SLinus Torvalds # 18481da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 18491da177e4SLinus Torvalds # the following functions' documentation still comes out right: 18501da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 18511da177e4SLinus Torvalds # - atomic_set (macro) 18529598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 1853e86bdb24SAditya Srivastava my $name = qr{[a-zA-Z0-9_~:]+}; 1854e86bdb24SAditya Srivastava my $prototype_end1 = qr{[^\(]*}; 1855e86bdb24SAditya Srivastava my $prototype_end2 = qr{[^\{]*}; 1856e86bdb24SAditya Srivastava my $prototype_end = qr{\(($prototype_end1|$prototype_end2)\)}; 1857e86bdb24SAditya Srivastava my $type1 = qr{[\w\s]+}; 1858e86bdb24SAditya Srivastava my $type2 = qr{$type1\*+}; 18591da177e4SLinus Torvalds 1860e86bdb24SAditya Srivastava if ($define && $prototype =~ m/^()($name)\s+/) { 1861cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 1862cbb4d3e6SHoria Geanta # list. 1863cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 1864cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 1865cbb4d3e6SHoria Geanta $return_type = $1; 1866cbb4d3e6SHoria Geanta $declaration_name = $2; 1867cbb4d3e6SHoria Geanta $noret = 1; 1868e86bdb24SAditya Srivastava } elsif ($prototype =~ m/^()($name)\s*$prototype_end/ || 1869e86bdb24SAditya Srivastava $prototype =~ m/^($type1)\s+($name)\s*$prototype_end/ || 1870e86bdb24SAditya Srivastava $prototype =~ m/^($type2+)\s*($name)\s*$prototype_end/) { 18711da177e4SLinus Torvalds $return_type = $1; 18721da177e4SLinus Torvalds $declaration_name = $2; 18731da177e4SLinus Torvalds my $args = $3; 18741da177e4SLinus Torvalds 1875151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 18761da177e4SLinus Torvalds } else { 1877d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 18781da177e4SLinus Torvalds return; 18791da177e4SLinus Torvalds } 18801da177e4SLinus Torvalds 188152042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 188252042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: expecting prototype for $identifier(). Prototype was for $declaration_name() instead\n"; 188352042e2dSMauro Carvalho Chehab return; 188452042e2dSMauro Carvalho Chehab } 188552042e2dSMauro Carvalho Chehab 1886a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 18871081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, "function", $sectcheck, $prms); 1888a1d94aa5SRandy Dunlap 18894092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 18904092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 18914092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 18924092bac7SYacine Belkadi # verbose mode. 18934092bac7SYacine Belkadi # TODO: always perform the check. 1894cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 18954092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 18964092bac7SYacine Belkadi } 18974092bac7SYacine Belkadi 189847bcacfdSMauro Carvalho Chehab # The function parser can be called with a typedef parameter. 189947bcacfdSMauro Carvalho Chehab # Handle it. 190047bcacfdSMauro Carvalho Chehab if ($return_type =~ /typedef/) { 190147bcacfdSMauro Carvalho Chehab output_declaration($declaration_name, 190247bcacfdSMauro Carvalho Chehab 'function', 190347bcacfdSMauro Carvalho Chehab {'function' => $declaration_name, 190447bcacfdSMauro Carvalho Chehab 'typedef' => 1, 190547bcacfdSMauro Carvalho Chehab 'module' => $modulename, 190647bcacfdSMauro Carvalho Chehab 'functiontype' => $return_type, 190747bcacfdSMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 190847bcacfdSMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 190947bcacfdSMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 191047bcacfdSMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 191147bcacfdSMauro Carvalho Chehab 'sections' => \%sections, 191247bcacfdSMauro Carvalho Chehab 'purpose' => $declaration_purpose 191347bcacfdSMauro Carvalho Chehab }); 191447bcacfdSMauro Carvalho Chehab } else { 19151da177e4SLinus Torvalds output_declaration($declaration_name, 19161da177e4SLinus Torvalds 'function', 19171da177e4SLinus Torvalds {'function' => $declaration_name, 19181da177e4SLinus Torvalds 'module' => $modulename, 19191da177e4SLinus Torvalds 'functiontype' => $return_type, 19201da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 19211da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 19221da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 19231da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 19241da177e4SLinus Torvalds 'sections' => \%sections, 19251da177e4SLinus Torvalds 'purpose' => $declaration_purpose 19261da177e4SLinus Torvalds }); 19271da177e4SLinus Torvalds } 192847bcacfdSMauro Carvalho Chehab} 19291da177e4SLinus Torvalds 19301da177e4SLinus Torvaldssub reset_state { 19311da177e4SLinus Torvalds $function = ""; 19321da177e4SLinus Torvalds %parameterdescs = (); 19331da177e4SLinus Torvalds %parametertypes = (); 19341da177e4SLinus Torvalds @parameterlist = (); 19351da177e4SLinus Torvalds %sections = (); 19361da177e4SLinus Torvalds @sectionlist = (); 1937a1d94aa5SRandy Dunlap $sectcheck = ""; 1938a1d94aa5SRandy Dunlap $struct_actual = ""; 19391da177e4SLinus Torvalds $prototype = ""; 19401da177e4SLinus Torvalds 194148af606aSJani Nikula $state = STATE_NORMAL; 194248af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 19431da177e4SLinus Torvalds} 19441da177e4SLinus Torvalds 194556afb0f8SJason Baronsub tracepoint_munge($) { 194656afb0f8SJason Baron my $file = shift; 194756afb0f8SJason Baron my $tracepointname = 0; 194856afb0f8SJason Baron my $tracepointargs = 0; 194956afb0f8SJason Baron 195056afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 195156afb0f8SJason Baron $tracepointname = $1; 195256afb0f8SJason Baron } 19533a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 19543a9089fdSJason Baron $tracepointname = $1; 19553a9089fdSJason Baron } 19563a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 19573a9089fdSJason Baron $tracepointname = $2; 19583a9089fdSJason Baron } 19593a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 196056afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 196156afb0f8SJason Baron $tracepointargs = $1; 196256afb0f8SJason Baron } 196356afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 1964d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 196556afb0f8SJason Baron "$prototype\n"; 196656afb0f8SJason Baron } else { 196756afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 196852042e2dSMauro Carvalho Chehab $identifier = "trace_$identifier"; 196956afb0f8SJason Baron } 197056afb0f8SJason Baron} 197156afb0f8SJason Baron 1972b4870bc5SRandy Dunlapsub syscall_munge() { 1973b4870bc5SRandy Dunlap my $void = 0; 1974b4870bc5SRandy Dunlap 19757c9aa015SMauro Carvalho Chehab $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's 1976b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 1977b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 1978b4870bc5SRandy Dunlap $void = 1; 1979b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 1980b4870bc5SRandy Dunlap } 1981b4870bc5SRandy Dunlap 1982b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 1983b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 1984b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 1985b4870bc5SRandy Dunlap } elsif ($void) { 1986b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 1987b4870bc5SRandy Dunlap } 1988b4870bc5SRandy Dunlap 1989b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 1990b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 1991b4870bc5SRandy Dunlap my $count = 0; 1992b4870bc5SRandy Dunlap my $len = length($prototype); 1993b4870bc5SRandy Dunlap if ($void) { 1994b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 1995b4870bc5SRandy Dunlap } 1996b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 1997b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 1998b4870bc5SRandy Dunlap $count++; 1999b4870bc5SRandy Dunlap if ($count % 2 == 1) { 2000b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 2001b4870bc5SRandy Dunlap } 2002b4870bc5SRandy Dunlap } 2003b4870bc5SRandy Dunlap } 2004b4870bc5SRandy Dunlap} 2005b4870bc5SRandy Dunlap 2006b7afa92bSDaniel Vettersub process_proto_function($$) { 20071da177e4SLinus Torvalds my $x = shift; 20081da177e4SLinus Torvalds my $file = shift; 20091da177e4SLinus Torvalds 201051f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 201151f5a0c8SRandy Dunlap 2012890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 20131da177e4SLinus Torvalds # do nothing 20141da177e4SLinus Torvalds } 20151da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 20161da177e4SLinus Torvalds $prototype .= $1; 20171da177e4SLinus Torvalds } 2018b4870bc5SRandy Dunlap 2019890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 20201da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 20211da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 20221da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 20237ae281b0SMauro Carvalho Chehab 20247ae281b0SMauro Carvalho Chehab # Handle prototypes for function pointers like: 20257ae281b0SMauro Carvalho Chehab # int (*pcs_config)(struct foo) 20267ae281b0SMauro Carvalho Chehab $prototype =~ s@^(\S+\s+)\(\s*\*(\S+)\)@$1$2@gos; 20277ae281b0SMauro Carvalho Chehab 2028b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 2029b4870bc5SRandy Dunlap syscall_munge(); 2030b4870bc5SRandy Dunlap } 20313a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 20323a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 20333a9089fdSJason Baron { 203456afb0f8SJason Baron tracepoint_munge($file); 203556afb0f8SJason Baron } 20361da177e4SLinus Torvalds dump_function($prototype, $file); 20371da177e4SLinus Torvalds reset_state(); 20381da177e4SLinus Torvalds } 20391da177e4SLinus Torvalds} 20401da177e4SLinus Torvalds 2041b7afa92bSDaniel Vettersub process_proto_type($$) { 20421da177e4SLinus Torvalds my $x = shift; 20431da177e4SLinus Torvalds my $file = shift; 20441da177e4SLinus Torvalds 20451da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 20461da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 20471da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 204851f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 204951f5a0c8SRandy Dunlap 20501da177e4SLinus Torvalds if ($x =~ /^#/) { 20511da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 20521da177e4SLinus Torvalds $x .= ";"; 20531da177e4SLinus Torvalds } 20541da177e4SLinus Torvalds 20551da177e4SLinus Torvalds while (1) { 2056673bb2dfSBen Hutchings if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) { 2057463a0fdcSMarkus Heiser if( length $prototype ) { 2058463a0fdcSMarkus Heiser $prototype .= " " 2059463a0fdcSMarkus Heiser } 20601da177e4SLinus Torvalds $prototype .= $1 . $2; 20611da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 20621da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 20631da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 20641da177e4SLinus Torvalds dump_declaration($prototype, $file); 20651da177e4SLinus Torvalds reset_state(); 20661da177e4SLinus Torvalds last; 20671da177e4SLinus Torvalds } 20681da177e4SLinus Torvalds $x = $3; 20691da177e4SLinus Torvalds } else { 20701da177e4SLinus Torvalds $prototype .= $x; 20711da177e4SLinus Torvalds last; 20721da177e4SLinus Torvalds } 20731da177e4SLinus Torvalds } 20741da177e4SLinus Torvalds} 20751da177e4SLinus Torvalds 20766b5b55f6SRandy Dunlap 20771ad560e4SJani Nikulasub map_filename($) { 20781ad560e4SJani Nikula my $file; 20791ad560e4SJani Nikula my ($orig_file) = @_; 20801ad560e4SJani Nikula 20811ad560e4SJani Nikula if (defined($ENV{'SRCTREE'})) { 20821ad560e4SJani Nikula $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 20831ad560e4SJani Nikula } else { 20841ad560e4SJani Nikula $file = $orig_file; 20851ad560e4SJani Nikula } 20861ad560e4SJani Nikula 20871ad560e4SJani Nikula if (defined($source_map{$file})) { 20881ad560e4SJani Nikula $file = $source_map{$file}; 20891ad560e4SJani Nikula } 20901ad560e4SJani Nikula 20911ad560e4SJani Nikula return $file; 20921ad560e4SJani Nikula} 20931ad560e4SJani Nikula 209488c2b57dSJani Nikulasub process_export_file($) { 209588c2b57dSJani Nikula my ($orig_file) = @_; 209688c2b57dSJani Nikula my $file = map_filename($orig_file); 209788c2b57dSJani Nikula 209888c2b57dSJani Nikula if (!open(IN,"<$file")) { 209988c2b57dSJani Nikula print STDERR "Error: Cannot open file $file\n"; 210088c2b57dSJani Nikula ++$errors; 210188c2b57dSJani Nikula return; 210288c2b57dSJani Nikula } 210388c2b57dSJani Nikula 210488c2b57dSJani Nikula while (<IN>) { 210588c2b57dSJani Nikula if (/$export_symbol/) { 2106eab795ddSMauro Carvalho Chehab next if (defined($nosymbol_table{$2})); 210788c2b57dSJani Nikula $function_table{$2} = 1; 210888c2b57dSJani Nikula } 210988c2b57dSJani Nikula } 211088c2b57dSJani Nikula 211188c2b57dSJani Nikula close(IN); 211288c2b57dSJani Nikula} 211388c2b57dSJani Nikula 211407048d13SJonathan Corbet# 211507048d13SJonathan Corbet# Parsers for the various processing states. 211607048d13SJonathan Corbet# 211707048d13SJonathan Corbet# STATE_NORMAL: looking for the /** to begin everything. 211807048d13SJonathan Corbet# 211907048d13SJonathan Corbetsub process_normal() { 21201da177e4SLinus Torvalds if (/$doc_start/o) { 212148af606aSJani Nikula $state = STATE_NAME; # next line is always the function name 2122850622dfSRandy Dunlap $in_doc_sect = 0; 21230b0f5f29SDaniel Vetter $declaration_start_line = $. + 1; 21241da177e4SLinus Torvalds } 212507048d13SJonathan Corbet} 212607048d13SJonathan Corbet 21273cac2bc4SJonathan Corbet# 21283cac2bc4SJonathan Corbet# STATE_NAME: Looking for the "name - description" line 21293cac2bc4SJonathan Corbet# 21303cac2bc4SJonathan Corbetsub process_name($$) { 21313cac2bc4SJonathan Corbet my $file = shift; 21321da177e4SLinus Torvalds my $descr; 21331da177e4SLinus Torvalds 21341da177e4SLinus Torvalds if (/$doc_block/o) { 213548af606aSJani Nikula $state = STATE_DOCBLOCK; 21361da177e4SLinus Torvalds $contents = ""; 21375ef09c96SMauro Carvalho Chehab $new_start_line = $.; 21380b0f5f29SDaniel Vetter 21391da177e4SLinus Torvalds if ( $1 eq "" ) { 21401da177e4SLinus Torvalds $section = $section_intro; 21411da177e4SLinus Torvalds } else { 21421da177e4SLinus Torvalds $section = $1; 21431da177e4SLinus Torvalds } 214452042e2dSMauro Carvalho Chehab } elsif (/$doc_decl/o) { 21451da177e4SLinus Torvalds $identifier = $1; 21463e58e839SAditya Srivastava my $is_kernel_comment = 0; 2147e86bdb24SAditya Srivastava my $decl_start = qr{$doc_com}; 2148f9bbc12cSAditya Srivastava # test for pointer declaration type, foo * bar() - desc 2149f9bbc12cSAditya Srivastava my $fn_type = qr{\w+\s*\*\s*}; 2150f9bbc12cSAditya Srivastava my $parenthesis = qr{\(\w*\)}; 2151f9bbc12cSAditya Srivastava my $decl_end = qr{[-:].*}; 2152e86bdb24SAditya Srivastava if (/^$decl_start([\w\s]+?)$parenthesis?\s*$decl_end?$/) { 21531da177e4SLinus Torvalds $identifier = $1; 21541da177e4SLinus Torvalds } 215552042e2dSMauro Carvalho Chehab if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) { 215652042e2dSMauro Carvalho Chehab $decl_type = $1; 215752042e2dSMauro Carvalho Chehab $identifier = $2; 21583e58e839SAditya Srivastava $is_kernel_comment = 1; 215952042e2dSMauro Carvalho Chehab } 2160f9bbc12cSAditya Srivastava # Look for foo() or static void foo() - description; or misspelt 2161f9bbc12cSAditya Srivastava # identifier 2162e86bdb24SAditya Srivastava elsif (/^$decl_start$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ || 2163e86bdb24SAditya Srivastava /^$decl_start$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) { 2164f9bbc12cSAditya Srivastava $identifier = $1; 2165f9bbc12cSAditya Srivastava $decl_type = 'function'; 2166f9bbc12cSAditya Srivastava $identifier =~ s/^define\s+//; 2167f9bbc12cSAditya Srivastava $is_kernel_comment = 1; 2168f9bbc12cSAditya Srivastava } 216952042e2dSMauro Carvalho Chehab $identifier =~ s/\s+$//; 21701da177e4SLinus Torvalds 217117b78717SJonathan Corbet $state = STATE_BODY; 21720b0f5f29SDaniel Vetter # if there's no @param blocks need to set up default section 21730b0f5f29SDaniel Vetter # here 21742f4ad40aSJani Nikula $contents = ""; 21752f4ad40aSJani Nikula $section = $section_default; 21760b0f5f29SDaniel Vetter $new_start_line = $. + 1; 217752042e2dSMauro Carvalho Chehab if (/[-:](.*)/) { 217851f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2179a21217daSRandy Dunlap $descr= $1; 2180a21217daSRandy Dunlap $descr =~ s/^\s*//; 2181a21217daSRandy Dunlap $descr =~ s/\s*$//; 218212ae6779SDaniel Santos $descr =~ s/\s+/ /g; 21830bba924cSJonathan Corbet $declaration_purpose = $descr; 218417b78717SJonathan Corbet $state = STATE_BODY_MAYBE; 21851da177e4SLinus Torvalds } else { 21861da177e4SLinus Torvalds $declaration_purpose = ""; 21871da177e4SLinus Torvalds } 218877cc23b8SRandy Dunlap 21893e58e839SAditya Srivastava if (!$is_kernel_comment) { 21903e58e839SAditya Srivastava print STDERR "${file}:$.: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst\n"; 21913e58e839SAditya Srivastava print STDERR $_; 21923e58e839SAditya Srivastava ++$warnings; 21933e58e839SAditya Srivastava $state = STATE_NORMAL; 21943e58e839SAditya Srivastava } 21953e58e839SAditya Srivastava 219677cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 2197d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 219877cc23b8SRandy Dunlap print STDERR $_; 219977cc23b8SRandy Dunlap ++$warnings; 220077cc23b8SRandy Dunlap } 220177cc23b8SRandy Dunlap 22020b54c2e3SMauro Carvalho Chehab if ($identifier eq "" && $decl_type ne "enum") { 220352042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: wrong kernel-doc identifier on line:\n"; 220452042e2dSMauro Carvalho Chehab print STDERR $_; 220552042e2dSMauro Carvalho Chehab ++$warnings; 220652042e2dSMauro Carvalho Chehab $state = STATE_NORMAL; 22071da177e4SLinus Torvalds } 22081da177e4SLinus Torvalds 22091da177e4SLinus Torvalds if ($verbose) { 221052042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: info: Scanning doc for $decl_type $identifier\n"; 22111da177e4SLinus Torvalds } 22121da177e4SLinus Torvalds } else { 2213d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 22141da177e4SLinus Torvalds " - I thought it was a doc line\n"; 22151da177e4SLinus Torvalds ++$warnings; 221648af606aSJani Nikula $state = STATE_NORMAL; 22171da177e4SLinus Torvalds } 22183cac2bc4SJonathan Corbet} 22193cac2bc4SJonathan Corbet 22203cac2bc4SJonathan Corbet 2221d742f24dSJonathan Corbet# 2222d742f24dSJonathan Corbet# STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment. 2223d742f24dSJonathan Corbet# 2224d742f24dSJonathan Corbetsub process_body($$) { 2225d742f24dSJonathan Corbet my $file = shift; 22263cac2bc4SJonathan Corbet 222743756e34SJonathan Neuschäfer # Until all named variable macro parameters are 222843756e34SJonathan Neuschäfer # documented using the bare name (`x`) rather than with 222943756e34SJonathan Neuschäfer # dots (`x...`), strip the dots: 223043756e34SJonathan Neuschäfer if ($section =~ /\w\.\.\.$/) { 223143756e34SJonathan Neuschäfer $section =~ s/\.\.\.$//; 223243756e34SJonathan Neuschäfer 223343756e34SJonathan Neuschäfer if ($verbose) { 223443756e34SJonathan Neuschäfer print STDERR "${file}:$.: warning: Variable macro arguments should be documented without dots\n"; 223543756e34SJonathan Neuschäfer ++$warnings; 223643756e34SJonathan Neuschäfer } 223743756e34SJonathan Neuschäfer } 223843756e34SJonathan Neuschäfer 22390d55d48bSMauro Carvalho Chehab if ($state == STATE_BODY_WITH_BLANK_LINE && /^\s*\*\s?\S/) { 22400d55d48bSMauro Carvalho Chehab dump_section($file, $section, $contents); 22410d55d48bSMauro Carvalho Chehab $section = $section_default; 22425ef09c96SMauro Carvalho Chehab $new_start_line = $.; 22430d55d48bSMauro Carvalho Chehab $contents = ""; 22440d55d48bSMauro Carvalho Chehab } 22450d55d48bSMauro Carvalho Chehab 2246f624adefSJani Nikula if (/$doc_sect/i) { # case insensitive for supported section names 22471da177e4SLinus Torvalds $newsection = $1; 22481da177e4SLinus Torvalds $newcontents = $2; 22491da177e4SLinus Torvalds 2250f624adefSJani Nikula # map the supported section names to the canonical names 2251f624adefSJani Nikula if ($newsection =~ m/^description$/i) { 2252f624adefSJani Nikula $newsection = $section_default; 2253f624adefSJani Nikula } elsif ($newsection =~ m/^context$/i) { 2254f624adefSJani Nikula $newsection = $section_context; 2255f624adefSJani Nikula } elsif ($newsection =~ m/^returns?$/i) { 2256f624adefSJani Nikula $newsection = $section_return; 2257f624adefSJani Nikula } elsif ($newsection =~ m/^\@return$/) { 2258f624adefSJani Nikula # special: @return is a section, not a param description 2259f624adefSJani Nikula $newsection = $section_return; 2260f624adefSJani Nikula } 2261f624adefSJani Nikula 2262792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 2263850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 2264d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: contents before sections\n"; 2265850622dfSRandy Dunlap ++$warnings; 2266850622dfSRandy Dunlap } 22670bba924cSJonathan Corbet dump_section($file, $section, $contents); 22681da177e4SLinus Torvalds $section = $section_default; 22691da177e4SLinus Torvalds } 22701da177e4SLinus Torvalds 2271850622dfSRandy Dunlap $in_doc_sect = 1; 227217b78717SJonathan Corbet $state = STATE_BODY; 22731da177e4SLinus Torvalds $contents = $newcontents; 22740b0f5f29SDaniel Vetter $new_start_line = $.; 22757c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 227605189497SRandy Dunlap $contents = substr($contents, 1); 227705189497SRandy Dunlap } 22780a726301SJani Nikula if ($contents ne "") { 22791da177e4SLinus Torvalds $contents .= "\n"; 22801da177e4SLinus Torvalds } 22811da177e4SLinus Torvalds $section = $newsection; 2282b7886de4SJani Nikula $leading_space = undef; 22831da177e4SLinus Torvalds } elsif (/$doc_end/) { 22844c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 22850bba924cSJonathan Corbet dump_section($file, $section, $contents); 22861da177e4SLinus Torvalds $section = $section_default; 22871da177e4SLinus Torvalds $contents = ""; 22881da177e4SLinus Torvalds } 228946b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 229046b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2291d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: suspicious ending line: $_"; 229246b958ebSRandy Dunlap ++$warnings; 229346b958ebSRandy Dunlap } 22941da177e4SLinus Torvalds 22951da177e4SLinus Torvalds $prototype = ""; 229648af606aSJani Nikula $state = STATE_PROTO; 22971da177e4SLinus Torvalds $brcount = 0; 22985ef09c96SMauro Carvalho Chehab $new_start_line = $. + 1; 22991da177e4SLinus Torvalds } elsif (/$doc_content/) { 23006423133bSJohannes Weiner if ($1 eq "") { 23010d55d48bSMauro Carvalho Chehab if ($section eq $section_context) { 23020bba924cSJonathan Corbet dump_section($file, $section, $contents); 23031da177e4SLinus Torvalds $section = $section_default; 23041da177e4SLinus Torvalds $contents = ""; 23050b0f5f29SDaniel Vetter $new_start_line = $.; 23060d55d48bSMauro Carvalho Chehab $state = STATE_BODY; 23071da177e4SLinus Torvalds } else { 23080d55d48bSMauro Carvalho Chehab if ($section ne $section_default) { 23090d55d48bSMauro Carvalho Chehab $state = STATE_BODY_WITH_BLANK_LINE; 23100d55d48bSMauro Carvalho Chehab } else { 23110d55d48bSMauro Carvalho Chehab $state = STATE_BODY; 23120d55d48bSMauro Carvalho Chehab } 23136423133bSJohannes Weiner $contents .= "\n"; 23146423133bSJohannes Weiner } 231517b78717SJonathan Corbet } elsif ($state == STATE_BODY_MAYBE) { 23166423133bSJohannes Weiner # Continued declaration purpose 23176423133bSJohannes Weiner chomp($declaration_purpose); 23180bba924cSJonathan Corbet $declaration_purpose .= " " . $1; 231912ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 23206423133bSJohannes Weiner } else { 2321b7886de4SJani Nikula my $cont = $1; 2322b7886de4SJani Nikula if ($section =~ m/^@/ || $section eq $section_context) { 2323b7886de4SJani Nikula if (!defined $leading_space) { 2324b7886de4SJani Nikula if ($cont =~ m/^(\s+)/) { 2325b7886de4SJani Nikula $leading_space = $1; 2326b7886de4SJani Nikula } else { 2327b7886de4SJani Nikula $leading_space = ""; 2328b7886de4SJani Nikula } 2329b7886de4SJani Nikula } 2330b7886de4SJani Nikula $cont =~ s/^$leading_space//; 2331b7886de4SJani Nikula } 2332b7886de4SJani Nikula $contents .= $cont . "\n"; 23331da177e4SLinus Torvalds } 23341da177e4SLinus Torvalds } else { 23351da177e4SLinus Torvalds # i dont know - bad line? ignore. 2336d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: bad line: $_"; 23371da177e4SLinus Torvalds ++$warnings; 23381da177e4SLinus Torvalds } 2339d742f24dSJonathan Corbet} 2340d742f24dSJonathan Corbet 2341d742f24dSJonathan Corbet 2342cc794812SJonathan Corbet# 2343cc794812SJonathan Corbet# STATE_PROTO: reading a function/whatever prototype. 2344cc794812SJonathan Corbet# 2345cc794812SJonathan Corbetsub process_proto($$) { 2346cc794812SJonathan Corbet my $file = shift; 2347cc794812SJonathan Corbet 2348cc794812SJonathan Corbet if (/$doc_inline_oneline/) { 2349cc794812SJonathan Corbet $section = $1; 2350cc794812SJonathan Corbet $contents = $2; 2351cc794812SJonathan Corbet if ($contents ne "") { 2352cc794812SJonathan Corbet $contents .= "\n"; 2353cc794812SJonathan Corbet dump_section($file, $section, $contents); 2354cc794812SJonathan Corbet $section = $section_default; 2355cc794812SJonathan Corbet $contents = ""; 2356cc794812SJonathan Corbet } 2357cc794812SJonathan Corbet } elsif (/$doc_inline_start/) { 2358cc794812SJonathan Corbet $state = STATE_INLINE; 2359cc794812SJonathan Corbet $inline_doc_state = STATE_INLINE_NAME; 2360cc794812SJonathan Corbet } elsif ($decl_type eq 'function') { 2361cc794812SJonathan Corbet process_proto_function($_, $file); 2362cc794812SJonathan Corbet } else { 2363cc794812SJonathan Corbet process_proto_type($_, $file); 2364cc794812SJonathan Corbet } 2365cc794812SJonathan Corbet} 2366cc794812SJonathan Corbet 2367c17add56SJonathan Corbet# 2368c17add56SJonathan Corbet# STATE_DOCBLOCK: within a DOC: block. 2369c17add56SJonathan Corbet# 2370c17add56SJonathan Corbetsub process_docblock($$) { 2371c17add56SJonathan Corbet my $file = shift; 2372cc794812SJonathan Corbet 2373c17add56SJonathan Corbet if (/$doc_end/) { 2374c17add56SJonathan Corbet dump_doc_section($file, $section, $contents); 2375c17add56SJonathan Corbet $section = $section_default; 2376c17add56SJonathan Corbet $contents = ""; 2377c17add56SJonathan Corbet $function = ""; 2378c17add56SJonathan Corbet %parameterdescs = (); 2379c17add56SJonathan Corbet %parametertypes = (); 2380c17add56SJonathan Corbet @parameterlist = (); 2381c17add56SJonathan Corbet %sections = (); 2382c17add56SJonathan Corbet @sectionlist = (); 2383c17add56SJonathan Corbet $prototype = ""; 2384c17add56SJonathan Corbet $state = STATE_NORMAL; 2385c17add56SJonathan Corbet } elsif (/$doc_content/) { 2386c17add56SJonathan Corbet if ( $1 eq "" ) { 2387c17add56SJonathan Corbet $contents .= $blankline; 2388c17add56SJonathan Corbet } else { 2389c17add56SJonathan Corbet $contents .= $1 . "\n"; 2390c17add56SJonathan Corbet } 2391c17add56SJonathan Corbet } 2392d742f24dSJonathan Corbet} 2393d742f24dSJonathan Corbet 2394c17add56SJonathan Corbet# 2395c17add56SJonathan Corbet# STATE_INLINE: docbook comments within a prototype. 2396c17add56SJonathan Corbet# 2397c17add56SJonathan Corbetsub process_inline($$) { 2398c17add56SJonathan Corbet my $file = shift; 2399d742f24dSJonathan Corbet 2400a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 240148af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 2402a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 2403a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 24040b0f5f29SDaniel Vetter $new_start_line = $.; 2405a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 24067c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 2407a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 2408a4c6ebedSDanilo Cesar Lemes de Paula } 2409a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 2410a4c6ebedSDanilo Cesar Lemes de Paula } 241148af606aSJani Nikula $inline_doc_state = STATE_INLINE_TEXT; 2412a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 241348af606aSJani Nikula } elsif (/$doc_inline_end/) { 2414a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 24150bba924cSJonathan Corbet dump_section($file, $section, $contents); 2416a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 2417a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 2418a4c6ebedSDanilo Cesar Lemes de Paula } 241948af606aSJani Nikula $state = STATE_PROTO; 242048af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 2421a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 2422a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 242348af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_TEXT) { 2424a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 24256450c895SJani Nikula # nuke leading blank lines 24266450c895SJani Nikula if ($contents =~ /^\s*$/) { 24276450c895SJani Nikula $contents = ""; 24286450c895SJani Nikula } 242948af606aSJani Nikula } elsif ($inline_doc_state == STATE_INLINE_NAME) { 243048af606aSJani Nikula $inline_doc_state = STATE_INLINE_ERROR; 2431e7ca311eSDaniel Vetter print STDERR "${file}:$.: warning: "; 2432a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Incorrect use of kernel-doc format: $_"; 2433a4c6ebedSDanilo Cesar Lemes de Paula ++$warnings; 2434a4c6ebedSDanilo Cesar Lemes de Paula } 2435a4c6ebedSDanilo Cesar Lemes de Paula } 24360c9aa209SJani Nikula} 2437c17add56SJonathan Corbet 2438c17add56SJonathan Corbet 2439c17add56SJonathan Corbetsub process_file($) { 2440c17add56SJonathan Corbet my $file; 2441c17add56SJonathan Corbet my $initial_section_counter = $section_counter; 2442c17add56SJonathan Corbet my ($orig_file) = @_; 2443c17add56SJonathan Corbet 2444c17add56SJonathan Corbet $file = map_filename($orig_file); 2445c17add56SJonathan Corbet 2446dbe8ba00SMauro Carvalho Chehab if (!open(IN_FILE,"<$file")) { 2447c17add56SJonathan Corbet print STDERR "Error: Cannot open file $file\n"; 2448c17add56SJonathan Corbet ++$errors; 2449c17add56SJonathan Corbet return; 24501da177e4SLinus Torvalds } 2451c17add56SJonathan Corbet 2452c17add56SJonathan Corbet $. = 1; 2453c17add56SJonathan Corbet 2454c17add56SJonathan Corbet $section_counter = 0; 2455dbe8ba00SMauro Carvalho Chehab while (<IN_FILE>) { 2456c17add56SJonathan Corbet while (s/\\\s*$//) { 2457dbe8ba00SMauro Carvalho Chehab $_ .= <IN_FILE>; 2458c17add56SJonathan Corbet } 2459c17add56SJonathan Corbet # Replace tabs by spaces 2460c17add56SJonathan Corbet while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; 2461c17add56SJonathan Corbet # Hand this line to the appropriate state handler 2462c17add56SJonathan Corbet if ($state == STATE_NORMAL) { 2463c17add56SJonathan Corbet process_normal(); 2464c17add56SJonathan Corbet } elsif ($state == STATE_NAME) { 2465c17add56SJonathan Corbet process_name($file, $_); 24660d55d48bSMauro Carvalho Chehab } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE || 24670d55d48bSMauro Carvalho Chehab $state == STATE_BODY_WITH_BLANK_LINE) { 2468c17add56SJonathan Corbet process_body($file, $_); 2469c17add56SJonathan Corbet } elsif ($state == STATE_INLINE) { # scanning for inline parameters 2470c17add56SJonathan Corbet process_inline($file, $_); 2471cc794812SJonathan Corbet } elsif ($state == STATE_PROTO) { 2472cc794812SJonathan Corbet process_proto($file, $_); 247348af606aSJani Nikula } elsif ($state == STATE_DOCBLOCK) { 2474c17add56SJonathan Corbet process_docblock($file, $_); 24751da177e4SLinus Torvalds } 24761da177e4SLinus Torvalds } 2477c17add56SJonathan Corbet 2478c17add56SJonathan Corbet # Make sure we got something interesting. 2479b0d60bfbSJonathan Corbet if ($initial_section_counter == $section_counter && $ 2480b0d60bfbSJonathan Corbet output_mode ne "none") { 2481b0d60bfbSJonathan Corbet if ($output_selection == OUTPUT_INCLUDE) { 2482b0d60bfbSJonathan Corbet print STDERR "${file}:1: warning: '$_' not found\n" 2483b0d60bfbSJonathan Corbet for keys %function_table; 24843a025e1dSMatthew Wilcox } 2485b0d60bfbSJonathan Corbet else { 2486b0d60bfbSJonathan Corbet print STDERR "${file}:1: warning: no structured comments found\n"; 2487e946c43aSJohannes Berg } 24881da177e4SLinus Torvalds } 2489dbe8ba00SMauro Carvalho Chehab close IN_FILE; 24901da177e4SLinus Torvalds} 24918484baaaSRandy Dunlap 24928484baaaSRandy Dunlap 249393351d41SMauro Carvalho Chehabif ($output_mode eq "rst") { 249493351d41SMauro Carvalho Chehab get_sphinx_version() if (!$sphinx_major); 249593351d41SMauro Carvalho Chehab} 249693351d41SMauro Carvalho Chehab 24978484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 24988484baaaSRandy Dunlap 24998484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 25008484baaaSRandy Dunlap# using the s// operator. 25011ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 25024d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 25034d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 25044d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 25054d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 25068484baaaSRandy Dunlap} 25078484baaaSRandy Dunlap 25088484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 25098484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 25108484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 25118484baaaSRandy Dunlap my ($relname, $absname); 25128484baaaSRandy Dunlap while(<SOURCE_MAP>) { 25138484baaaSRandy Dunlap chop(); 25148484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 25158484baaaSRandy Dunlap $relname =~ s:^/+::; 25168484baaaSRandy Dunlap $source_map{$relname} = $absname; 25178484baaaSRandy Dunlap } 25188484baaaSRandy Dunlap close(SOURCE_MAP); 25198484baaaSRandy Dunlap} 25208484baaaSRandy Dunlap 252188c2b57dSJani Nikulaif ($output_selection == OUTPUT_EXPORTED || 252288c2b57dSJani Nikula $output_selection == OUTPUT_INTERNAL) { 2523c9b2cfb3SJani Nikula 2524c9b2cfb3SJani Nikula push(@export_file_list, @ARGV); 2525c9b2cfb3SJani Nikula 252688c2b57dSJani Nikula foreach (@export_file_list) { 252788c2b57dSJani Nikula chomp; 252888c2b57dSJani Nikula process_export_file($_); 252988c2b57dSJani Nikula } 253088c2b57dSJani Nikula} 253188c2b57dSJani Nikula 25328484baaaSRandy Dunlapforeach (@ARGV) { 25338484baaaSRandy Dunlap chomp; 25348484baaaSRandy Dunlap process_file($_); 25358484baaaSRandy Dunlap} 25368484baaaSRandy Dunlapif ($verbose && $errors) { 25378484baaaSRandy Dunlap print STDERR "$errors errors\n"; 25388484baaaSRandy Dunlap} 25398484baaaSRandy Dunlapif ($verbose && $warnings) { 25408484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 25418484baaaSRandy Dunlap} 25428484baaaSRandy Dunlap 25432c12c810SPierre-Louis Bossartif ($Werror && $warnings) { 25442c12c810SPierre-Louis Bossart print STDERR "$warnings warnings as Errors\n"; 25452c12c810SPierre-Louis Bossart exit($warnings); 25462c12c810SPierre-Louis Bossart} else { 25472c12c810SPierre-Louis Bossart exit($output_mode eq "none" ? 0 : $errors) 25482c12c810SPierre-Louis Bossart} 2549