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 1943caf1a6STomasz Warniełłouse Pod::Usage qw/pod2usage/; 2043caf1a6STomasz Warniełło 21a5cdaea5STomasz Warniełło=head1 NAME 22a5cdaea5STomasz Warniełło 23a5cdaea5STomasz Warniełłokernel-doc - Print formatted kernel documentation to stdout 24a5cdaea5STomasz Warniełło 25a5cdaea5STomasz Warniełło=head1 SYNOPSIS 26a5cdaea5STomasz Warniełło 27a5cdaea5STomasz Warniełło kernel-doc [-h] [-v] [-Werror] 28a5cdaea5STomasz Warniełło [ -man | 29a5cdaea5STomasz Warniełło -rst [-sphinx-version VERSION] [-enable-lineno] | 30a5cdaea5STomasz Warniełło -none 31a5cdaea5STomasz Warniełło ] 32a5cdaea5STomasz Warniełło [ 33a5cdaea5STomasz Warniełło -export | 34a5cdaea5STomasz Warniełło -internal | 35a5cdaea5STomasz Warniełło [-function NAME] ... | 36a5cdaea5STomasz Warniełło [-nosymbol NAME] ... 37a5cdaea5STomasz Warniełło ] 38a5cdaea5STomasz Warniełło [-no-doc-sections] 39a5cdaea5STomasz Warniełło [-export-file FILE] ... 40a5cdaea5STomasz Warniełło FILE ... 41a5cdaea5STomasz Warniełło 42a5cdaea5STomasz WarniełłoRun `kernel-doc -h` for details. 43a5cdaea5STomasz Warniełło 44f1583922STomasz Warniełło=head1 DESCRIPTION 45f1583922STomasz Warniełło 46f1583922STomasz WarniełłoRead C language source or header FILEs, extract embedded documentation comments, 47f1583922STomasz Warniełłoand print formatted documentation to standard output. 48f1583922STomasz Warniełło 49f1583922STomasz WarniełłoThe documentation comments are identified by the "/**" opening comment mark. 50f1583922STomasz Warniełło 51f1583922STomasz WarniełłoSee Documentation/doc-guide/kernel-doc.rst for the documentation comment syntax. 52f1583922STomasz Warniełło 53a5cdaea5STomasz Warniełło=cut 54a5cdaea5STomasz Warniełło 552875f787STomasz Warniełło# more perldoc at the end of the file 562875f787STomasz Warniełło 571da177e4SLinus Torvalds# 18/01/2001 - Cleanups 581da177e4SLinus Torvalds# Functions prototyped as foo(void) same as foo() 591da177e4SLinus Torvalds# Stop eval'ing where we don't need to. 601da177e4SLinus Torvalds# -- huggie@earth.li 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds# 27/06/2001 - Allowed whitespace after initial "/**" and 631da177e4SLinus Torvalds# allowed comments before function declarations. 641da177e4SLinus Torvalds# -- Christian Kreibich <ck@whoop.org> 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds# Still to do: 671da177e4SLinus Torvalds# - add perldoc documentation 681da177e4SLinus Torvalds# - Look more closely at some of the scarier bits :) 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds# 26/05/2001 - Support for separate source and object trees. 711da177e4SLinus Torvalds# Return error code. 721da177e4SLinus Torvalds# Keith Owens <kaos@ocs.com.au> 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds# 23/09/2001 - Added support for typedefs, structs, enums and unions 751da177e4SLinus Torvalds# Support for Context section; can be terminated using empty line 761da177e4SLinus Torvalds# Small fixes (like spaces vs. \s in regex) 771da177e4SLinus Torvalds# -- Tim Jansen <tim@tjansen.de> 781da177e4SLinus Torvalds 791b40c194SDan Luedtke# 25/07/2012 - Added support for HTML5 801b40c194SDan Luedtke# -- Dan Luedtke <mail@danrl.de> 811da177e4SLinus Torvalds 82fadc0b31SJani Nikulasub usage { 83fadc0b31SJani Nikula my $message = <<"EOF"; 84fadc0b31SJani NikulaUsage: $0 [OPTION ...] FILE ... 851da177e4SLinus Torvalds 86fadc0b31SJani NikulaOutput selection (mutually exclusive): 8786ae2e38SJani Nikula -export Only output documentation for symbols that have been 8886ae2e38SJani Nikula exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 89c9b2cfb3SJani Nikula in any input FILE or -export-file FILE. 9086ae2e38SJani Nikula -internal Only output documentation for symbols that have NOT been 9186ae2e38SJani Nikula exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 92c9b2cfb3SJani Nikula in any input FILE or -export-file FILE. 93fadc0b31SJani Nikula -function NAME Only output documentation for the given function(s) 94fadc0b31SJani Nikula or DOC: section title(s). All other functions and DOC: 95fadc0b31SJani Nikula sections are ignored. May be specified multiple times. 96eab795ddSMauro Carvalho Chehab -nosymbol NAME Exclude the specified symbols from the output 97eab795ddSMauro Carvalho Chehab documentation. May be specified multiple times. 98fadc0b31SJani Nikula 99fadc0b31SJani NikulaOutput selection modifiers: 100fadc0b31SJani Nikula -no-doc-sections Do not output DOC: sections. 1010b0f5f29SDaniel Vetter -enable-lineno Enable output of #define LINENO lines. Only works with 1020b0f5f29SDaniel Vetter reStructuredText format. 10388c2b57dSJani Nikula -export-file FILE Specify an additional FILE in which to look for 10488c2b57dSJani Nikula EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with 10588c2b57dSJani Nikula -export or -internal. May be specified multiple times. 106fadc0b31SJani Nikula 107fadc0b31SJani NikulaOther parameters: 108fadc0b31SJani Nikula -v Verbose output, more warnings and other information. 109fadc0b31SJani Nikula -h Print this help. 1102c12c810SPierre-Louis Bossart -Werror Treat warnings as errors. 111fadc0b31SJani Nikula 112fadc0b31SJani NikulaEOF 113fadc0b31SJani Nikula print $message; 114fadc0b31SJani Nikula exit 1; 115fadc0b31SJani Nikula} 1161da177e4SLinus Torvalds 1171da177e4SLinus Torvalds# 1181da177e4SLinus Torvalds# format of comments. 1191da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure. 1201da177e4SLinus Torvalds# (...)* signifies 0 or more structure elements 1211da177e4SLinus Torvalds# /** 1221da177e4SLinus Torvalds# * function_name(:)? (- short description)? 1231da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)* 1241da177e4SLinus Torvalds# (* a blank line)? 1251da177e4SLinus Torvalds# * (Description:)? (Description of function)? 1261da177e4SLinus Torvalds# * (section header: (section description)? )* 1271da177e4SLinus Torvalds# (*)?*/ 1281da177e4SLinus Torvalds# 1291da177e4SLinus Torvalds# So .. the trivial example would be: 1301da177e4SLinus Torvalds# 1311da177e4SLinus Torvalds# /** 1321da177e4SLinus Torvalds# * my_function 133b9d97328SRandy Dunlap# */ 1341da177e4SLinus Torvalds# 135891dcd2fSRandy Dunlap# If the Description: header tag is omitted, then there must be a blank line 1361da177e4SLinus Torvalds# after the last parameter specification. 1371da177e4SLinus Torvalds# e.g. 1381da177e4SLinus Torvalds# /** 1391da177e4SLinus Torvalds# * my_function - does my stuff 1401da177e4SLinus Torvalds# * @my_arg: its mine damnit 1411da177e4SLinus Torvalds# * 1421da177e4SLinus Torvalds# * Does my stuff explained. 1431da177e4SLinus Torvalds# */ 1441da177e4SLinus Torvalds# 1451da177e4SLinus Torvalds# or, could also use: 1461da177e4SLinus Torvalds# /** 1471da177e4SLinus Torvalds# * my_function - does my stuff 1481da177e4SLinus Torvalds# * @my_arg: its mine damnit 1491da177e4SLinus Torvalds# * Description: Does my stuff explained. 1501da177e4SLinus Torvalds# */ 1511da177e4SLinus Torvalds# etc. 1521da177e4SLinus Torvalds# 153b9d97328SRandy Dunlap# Besides functions you can also write documentation for structs, unions, 1541da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name 1551da177e4SLinus Torvalds# of the declaration; the struct/union/enum/typedef must always precede 1561da177e4SLinus Torvalds# the name. Nesting of declarations is not supported. 1571da177e4SLinus Torvalds# Use the argument mechanism to document members or constants. 1581da177e4SLinus Torvalds# e.g. 1591da177e4SLinus Torvalds# /** 1601da177e4SLinus Torvalds# * struct my_struct - short description 1611da177e4SLinus Torvalds# * @a: first member 1621da177e4SLinus Torvalds# * @b: second member 1631da177e4SLinus Torvalds# * 1641da177e4SLinus Torvalds# * Longer description 1651da177e4SLinus Torvalds# */ 1661da177e4SLinus Torvalds# struct my_struct { 1671da177e4SLinus Torvalds# int a; 1681da177e4SLinus Torvalds# int b; 169aeec46b9SMartin Waitz# /* private: */ 170aeec46b9SMartin Waitz# int c; 1711da177e4SLinus Torvalds# }; 1721da177e4SLinus Torvalds# 1731da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description. 1741da177e4SLinus Torvalds# 175a4c6ebedSDanilo Cesar Lemes de Paula# For really longs structs, you can also describe arguments inside the 176a4c6ebedSDanilo Cesar Lemes de Paula# body of the struct. 177a4c6ebedSDanilo Cesar Lemes de Paula# eg. 178a4c6ebedSDanilo Cesar Lemes de Paula# /** 179a4c6ebedSDanilo Cesar Lemes de Paula# * struct my_struct - short description 180a4c6ebedSDanilo Cesar Lemes de Paula# * @a: first member 181a4c6ebedSDanilo Cesar Lemes de Paula# * @b: second member 182a4c6ebedSDanilo Cesar Lemes de Paula# * 183a4c6ebedSDanilo Cesar Lemes de Paula# * Longer description 184a4c6ebedSDanilo Cesar Lemes de Paula# */ 185a4c6ebedSDanilo Cesar Lemes de Paula# struct my_struct { 186a4c6ebedSDanilo Cesar Lemes de Paula# int a; 187a4c6ebedSDanilo Cesar Lemes de Paula# int b; 188a4c6ebedSDanilo Cesar Lemes de Paula# /** 189a4c6ebedSDanilo Cesar Lemes de Paula# * @c: This is longer description of C 190a4c6ebedSDanilo Cesar Lemes de Paula# * 191a4c6ebedSDanilo Cesar Lemes de Paula# * You can use paragraphs to describe arguments 192a4c6ebedSDanilo Cesar Lemes de Paula# * using this method. 193a4c6ebedSDanilo Cesar Lemes de Paula# */ 194a4c6ebedSDanilo Cesar Lemes de Paula# int c; 195a4c6ebedSDanilo Cesar Lemes de Paula# }; 196a4c6ebedSDanilo Cesar Lemes de Paula# 197a4c6ebedSDanilo Cesar Lemes de Paula# This should be use only for struct/enum members. 198a4c6ebedSDanilo Cesar Lemes de Paula# 1991da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you 2001da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions 2011da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an 2021da177e4SLinus Torvalds# empty line. 2034092bac7SYacine Belkadi# A non-void function should have a "Return:" section describing the return 2044092bac7SYacine Belkadi# value(s). 2051da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked 2061da177e4SLinus Torvalds# appropriately in DocBook. 2071da177e4SLinus Torvalds# 2081da177e4SLinus Torvalds# Example: 2091da177e4SLinus Torvalds# /** 2101da177e4SLinus Torvalds# * user_function - function that can only be called in user context 2111da177e4SLinus Torvalds# * @a: some argument 2121da177e4SLinus Torvalds# * Context: !in_interrupt() 2131da177e4SLinus Torvalds# * 2141da177e4SLinus Torvalds# * Some description 2151da177e4SLinus Torvalds# * Example: 2161da177e4SLinus Torvalds# * user_function(22); 2171da177e4SLinus Torvalds# */ 2181da177e4SLinus Torvalds# ... 2191da177e4SLinus Torvalds# 2201da177e4SLinus Torvalds# 2211da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special 2221da177e4SLinus Torvalds# patterns, which are highlighted appropriately. 2231da177e4SLinus Torvalds# 2241da177e4SLinus Torvalds# 'funcname()' - function 2251da177e4SLinus Torvalds# '$ENVVAR' - environmental variable 2261da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct') 2275267dd35SPaolo Bonzini# '&struct_name.member' - name of a structure member 2281da177e4SLinus Torvalds# '@parameter' - name of a parameter 2291da177e4SLinus Torvalds# '%CONST' - name of a constant. 230b97f193aSMauro Carvalho Chehab# '``LITERAL``' - literal string without any spaces on it. 2311da177e4SLinus Torvalds 2328484baaaSRandy Dunlap## init lots of data 2338484baaaSRandy Dunlap 2341da177e4SLinus Torvaldsmy $errors = 0; 2351da177e4SLinus Torvaldsmy $warnings = 0; 2365f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 2371da177e4SLinus Torvalds 2381da177e4SLinus Torvalds# match expressions used to find embedded type information 239b97f193aSMauro Carvalho Chehabmy $type_constant = '\b``([^\`]+)``\b'; 240b97f193aSMauro Carvalho Chehabmy $type_constant2 = '\%([-_\w]+)'; 2411da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 242bfd228c7SMike Rapoportmy $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; 243ee2aa759SMauro Carvalho Chehabmy $type_param_ref = '([\!]?)\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; 2445219f18aSJonathan Corbetmy $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params 245346282dbSMauro Carvalho Chehabmy $type_fp_param2 = '\@(\w+->\S+)\(\)'; # Special RST handling for structs with func ptr params 2461da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 247df31175bSPaolo Bonzinimy $type_enum = '\&(enum\s*([_\w]+))'; 248df31175bSPaolo Bonzinimy $type_struct = '\&(struct\s*([_\w]+))'; 249df31175bSPaolo Bonzinimy $type_typedef = '\&(typedef\s*([_\w]+))'; 250df31175bSPaolo Bonzinimy $type_union = '\&(union\s*([_\w]+))'; 2515267dd35SPaolo Bonzinimy $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; 252df31175bSPaolo Bonzinimy $type_fallback = '\&([_\w]+)'; 253f3341dcfSJani Nikulamy $type_member_func = $type_member . '\(\)'; 2541da177e4SLinus Torvalds 2551da177e4SLinus Torvalds# Output conversion substitutions. 2561da177e4SLinus Torvalds# One for each output format 2571da177e4SLinus Torvalds 2581da177e4SLinus Torvalds# these are pretty rough 2594d732701SDanilo Cesar Lemes de Paulamy @highlights_man = ( 2604d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 261b97f193aSMauro Carvalho Chehab [$type_constant2, "\$1"], 2624d732701SDanilo Cesar Lemes de Paula [$type_func, "\\\\fB\$1\\\\fP"], 263df31175bSPaolo Bonzini [$type_enum, "\\\\fI\$1\\\\fP"], 2644d732701SDanilo Cesar Lemes de Paula [$type_struct, "\\\\fI\$1\\\\fP"], 265df31175bSPaolo Bonzini [$type_typedef, "\\\\fI\$1\\\\fP"], 266df31175bSPaolo Bonzini [$type_union, "\\\\fI\$1\\\\fP"], 2675267dd35SPaolo Bonzini [$type_param, "\\\\fI\$1\\\\fP"], 268ee2aa759SMauro Carvalho Chehab [$type_param_ref, "\\\\fI\$1\$2\\\\fP"], 269df31175bSPaolo Bonzini [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], 270df31175bSPaolo Bonzini [$type_fallback, "\\\\fI\$1\\\\fP"] 2714d732701SDanilo Cesar Lemes de Paula ); 2721da177e4SLinus Torvaldsmy $blankline_man = ""; 2731da177e4SLinus Torvalds 274c0d1b6eeSJonathan Corbet# rst-mode 275c0d1b6eeSJonathan Corbetmy @highlights_rst = ( 276c0d1b6eeSJonathan Corbet [$type_constant, "``\$1``"], 277b97f193aSMauro Carvalho Chehab [$type_constant2, "``\$1``"], 278f3341dcfSJani Nikula # Note: need to escape () to avoid func matching later 2795267dd35SPaolo Bonzini [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], 2805267dd35SPaolo Bonzini [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], 2815219f18aSJonathan Corbet [$type_fp_param, "**\$1\\\\(\\\\)**"], 282346282dbSMauro Carvalho Chehab [$type_fp_param2, "**\$1\\\\(\\\\)**"], 283344fdb28SJonathan Corbet [$type_func, "\$1()"], 284df31175bSPaolo Bonzini [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], 285df31175bSPaolo Bonzini [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], 286df31175bSPaolo Bonzini [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], 287df31175bSPaolo Bonzini [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], 288a7291e7eSJani Nikula # in rst this can refer to any type 289df31175bSPaolo Bonzini [$type_fallback, "\\:c\\:type\\:`\$1`"], 290ee2aa759SMauro Carvalho Chehab [$type_param_ref, "**\$1\$2**"] 291c0d1b6eeSJonathan Corbet ); 292c0d1b6eeSJonathan Corbetmy $blankline_rst = "\n"; 293c0d1b6eeSJonathan Corbet 2941da177e4SLinus Torvalds# read arguments 2951da177e4SLinus Torvaldsif ($#ARGV == -1) { 29643caf1a6STomasz Warniełło pod2usage( 29743caf1a6STomasz Warniełło -message => "No arguments!\n", 29843caf1a6STomasz Warniełło -exitval => 1, 29943caf1a6STomasz Warniełło -verbose => 99, 30043caf1a6STomasz Warniełło -sections => 'SYNOPSIS', 30143caf1a6STomasz Warniełło -output => \*STDERR, 30243caf1a6STomasz Warniełło ); 3031da177e4SLinus Torvalds} 3041da177e4SLinus Torvalds 3058484baaaSRandy Dunlapmy $kernelversion; 30693351d41SMauro Carvalho Chehabmy ($sphinx_major, $sphinx_minor, $sphinx_patch); 307efa44475SMauro Carvalho Chehab 3088484baaaSRandy Dunlapmy $dohighlight = ""; 3098484baaaSRandy Dunlap 3101da177e4SLinus Torvaldsmy $verbose = 0; 3112c12c810SPierre-Louis Bossartmy $Werror = 0; 312bdfe2be3SMauro Carvalho Chehabmy $output_mode = "rst"; 313e314ba31SDaniel Santosmy $output_preformatted = 0; 3144b44595aSJohannes Bergmy $no_doc_sections = 0; 3150b0f5f29SDaniel Vettermy $enable_lineno = 0; 316bdfe2be3SMauro Carvalho Chehabmy @highlights = @highlights_rst; 317bdfe2be3SMauro Carvalho Chehabmy $blankline = $blankline_rst; 3181da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 319b6c3f456SJani Nikula 320b6c3f456SJani Nikulause constant { 321b6c3f456SJani Nikula OUTPUT_ALL => 0, # output all symbols and doc sections 322b6c3f456SJani Nikula OUTPUT_INCLUDE => 1, # output only specified symbols 323eab795ddSMauro Carvalho Chehab OUTPUT_EXPORTED => 2, # output exported symbols 324eab795ddSMauro Carvalho Chehab OUTPUT_INTERNAL => 3, # output non-exported symbols 325b6c3f456SJani Nikula}; 326b6c3f456SJani Nikulamy $output_selection = OUTPUT_ALL; 327b0d60bfbSJonathan Corbetmy $show_not_found = 0; # No longer used 328b2c4105bSBen Hutchings 32988c2b57dSJani Nikulamy @export_file_list; 33088c2b57dSJani Nikula 331b2c4105bSBen Hutchingsmy @build_time; 332b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 333b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 334b2c4105bSBen Hutchings @build_time = gmtime($seconds); 335b2c4105bSBen Hutchings} else { 336b2c4105bSBen Hutchings @build_time = localtime; 337b2c4105bSBen Hutchings} 338b2c4105bSBen Hutchings 3391da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 3401da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 341b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 342b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 3431da177e4SLinus Torvalds 3448484baaaSRandy Dunlap# Essentially these are globals. 345b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 346b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 3471da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 3481da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 349eab795ddSMauro Carvalho Chehabmy %nosymbol_table = (); 3500b0f5f29SDaniel Vettermy $declaration_start_line; 3511da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 3521c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 3531da177e4SLinus Torvalds 354bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 355bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 356bd0e88e5SRandy Dunlap} 357bd0e88e5SRandy Dunlap 3582c12c810SPierre-Louis Bossartif (defined($ENV{'KCFLAGS'})) { 3592c12c810SPierre-Louis Bossart my $kcflags = "$ENV{'KCFLAGS'}"; 3602c12c810SPierre-Louis Bossart 3612c12c810SPierre-Louis Bossart if ($kcflags =~ /Werror/) { 3622c12c810SPierre-Louis Bossart $Werror = 1; 3632c12c810SPierre-Louis Bossart } 3642c12c810SPierre-Louis Bossart} 3652c12c810SPierre-Louis Bossart 366bed4ed30SLaurent Pinchartif (defined($ENV{'KDOC_WERROR'})) { 367bed4ed30SLaurent Pinchart $Werror = "$ENV{'KDOC_WERROR'}"; 368bed4ed30SLaurent Pinchart} 369bed4ed30SLaurent Pinchart 3701da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 3711da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 37293431e06SAlexander A. Klimov# https://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 3731da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 3741da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 3751da177e4SLinus Torvalds# into html. 3761da177e4SLinus Torvaldsmy $section_counter = 0; 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvaldsmy $lineprefix=""; 3791da177e4SLinus Torvalds 38048af606aSJani Nikula# Parser states 38148af606aSJani Nikulause constant { 38248af606aSJani Nikula STATE_NORMAL => 0, # normal code 38348af606aSJani Nikula STATE_NAME => 1, # looking for function name 38417b78717SJonathan Corbet STATE_BODY_MAYBE => 2, # body - or maybe more description 38517b78717SJonathan Corbet STATE_BODY => 3, # the body of the comment 3860d55d48bSMauro Carvalho Chehab STATE_BODY_WITH_BLANK_LINE => 4, # the body, which has a blank line 3870d55d48bSMauro Carvalho Chehab STATE_PROTO => 5, # scanning prototype 3880d55d48bSMauro Carvalho Chehab STATE_DOCBLOCK => 6, # documentation block 3890d55d48bSMauro Carvalho Chehab STATE_INLINE => 7, # gathering doc outside main block 39048af606aSJani Nikula}; 3911da177e4SLinus Torvaldsmy $state; 392850622dfSRandy Dunlapmy $in_doc_sect; 393d742f24dSJonathan Corbetmy $leading_space; 3941da177e4SLinus Torvalds 39548af606aSJani Nikula# Inline documentation state 39648af606aSJani Nikulause constant { 39748af606aSJani Nikula STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 39848af606aSJani Nikula STATE_INLINE_NAME => 1, # looking for member name (@foo:) 39948af606aSJani Nikula STATE_INLINE_TEXT => 2, # looking for member documentation 40048af606aSJani Nikula STATE_INLINE_END => 3, # done 40148af606aSJani Nikula STATE_INLINE_ERROR => 4, # error - Comment without header was found. 40248af606aSJani Nikula # Spit a warning as it's not 403a4c6ebedSDanilo Cesar Lemes de Paula # proper kernel-doc and ignore the rest. 40448af606aSJani Nikula}; 40548af606aSJani Nikulamy $inline_doc_state; 406a4c6ebedSDanilo Cesar Lemes de Paula 4071da177e4SLinus Torvalds#declaration types: can be 4081da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 4091da177e4SLinus Torvaldsmy $decl_type; 4101da177e4SLinus Torvalds 41152042e2dSMauro Carvalho Chehab# Name of the kernel-doc identifier for non-DOC markups 41252042e2dSMauro Carvalho Chehabmy $identifier; 41352042e2dSMauro Carvalho Chehab 4141da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 4151da177e4SLinus Torvaldsmy $doc_end = '\*/'; 4161da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 41712ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 4181da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 419f624adefSJani Nikula# @params and a strictly limited set of supported section names 420212209cfSJonathan Corbet# Specifically: 421212209cfSJonathan Corbet# Match @word: 422212209cfSJonathan Corbet# @...: 423212209cfSJonathan Corbet# @{section-name}: 424212209cfSJonathan Corbet# while trying to not match literal block starts like "example::" 425212209cfSJonathan Corbet# 4268569de68SJonathan Corbetmy $doc_sect = $doc_com . 427212209cfSJonathan Corbet '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:([^:].*)?$'; 42812ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 4291da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 43048af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$'; 431fe7bc493SMauro Carvalho Chehabmy $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)'; 43248af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$'; 4330c9aa209SJani Nikulamy $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; 43486ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 435e86bdb24SAditya Srivastavamy $function_pointer = qr{([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)}; 436e86bdb24SAditya Srivastavamy $attribute = qr{__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)}i; 4371da177e4SLinus Torvalds 4381da177e4SLinus Torvaldsmy %parameterdescs; 4390b0f5f29SDaniel Vettermy %parameterdesc_start_lines; 4401da177e4SLinus Torvaldsmy @parameterlist; 4411da177e4SLinus Torvaldsmy %sections; 4421da177e4SLinus Torvaldsmy @sectionlist; 4430b0f5f29SDaniel Vettermy %section_start_lines; 444a1d94aa5SRandy Dunlapmy $sectcheck; 445a1d94aa5SRandy Dunlapmy $struct_actual; 4461da177e4SLinus Torvalds 4471da177e4SLinus Torvaldsmy $contents = ""; 4480b0f5f29SDaniel Vettermy $new_start_line = 0; 449f624adefSJani Nikula 450f624adefSJani Nikula# the canonical section names. see also $doc_sect above. 4511da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 4521da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 4531da177e4SLinus Torvaldsmy $section = $section_default; 4541da177e4SLinus Torvaldsmy $section_context = "Context"; 4554092bac7SYacine Belkadimy $section_return = "Return"; 4561da177e4SLinus Torvalds 4571da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 4581da177e4SLinus Torvalds 4591da177e4SLinus Torvaldsreset_state(); 4601da177e4SLinus Torvalds 461b031ac4eSMauro Carvalho Chehabwhile ($ARGV[0] =~ m/^--?(.*)/) { 462b031ac4eSMauro Carvalho Chehab my $cmd = $1; 463b031ac4eSMauro Carvalho Chehab shift @ARGV; 464b031ac4eSMauro Carvalho Chehab if ($cmd eq "man") { 4651da177e4SLinus Torvalds $output_mode = "man"; 4664d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 4671da177e4SLinus Torvalds $blankline = $blankline_man; 468b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "rst") { 469c0d1b6eeSJonathan Corbet $output_mode = "rst"; 470c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 471c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 472b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "none") { 4733a025e1dSMatthew Wilcox $output_mode = "none"; 474b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document 4751da177e4SLinus Torvalds $modulename = shift @ARGV; 476b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "function") { # to only output specific functions 477b6c3f456SJani Nikula $output_selection = OUTPUT_INCLUDE; 4781da177e4SLinus Torvalds $function = shift @ARGV; 4791da177e4SLinus Torvalds $function_table{$function} = 1; 480eab795ddSMauro Carvalho Chehab } elsif ($cmd eq "nosymbol") { # Exclude specific symbols 481eab795ddSMauro Carvalho Chehab my $symbol = shift @ARGV; 482eab795ddSMauro Carvalho Chehab $nosymbol_table{$symbol} = 1; 483b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export") { # only exported symbols 484b6c3f456SJani Nikula $output_selection = OUTPUT_EXPORTED; 485da9726ecSJani Nikula %function_table = (); 486b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "internal") { # only non-exported symbols 487b6c3f456SJani Nikula $output_selection = OUTPUT_INTERNAL; 488da9726ecSJani Nikula %function_table = (); 489b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export-file") { 49088c2b57dSJani Nikula my $file = shift @ARGV; 49188c2b57dSJani Nikula push(@export_file_list, $file); 492b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "v") { 4931da177e4SLinus Torvalds $verbose = 1; 4942c12c810SPierre-Louis Bossart } elsif ($cmd eq "Werror") { 4952c12c810SPierre-Louis Bossart $Werror = 1; 496b031ac4eSMauro Carvalho Chehab } elsif (($cmd eq "h") || ($cmd eq "help")) { 4971da177e4SLinus Torvalds usage(); 498b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'no-doc-sections') { 4994b44595aSJohannes Berg $no_doc_sections = 1; 500b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'enable-lineno') { 5010b0f5f29SDaniel Vetter $enable_lineno = 1; 502b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'show-not-found') { 503b0d60bfbSJonathan Corbet $show_not_found = 1; # A no-op but don't fail 50493351d41SMauro Carvalho Chehab } elsif ($cmd eq "sphinx-version") { 50593351d41SMauro Carvalho Chehab my $ver_string = shift @ARGV; 50693351d41SMauro Carvalho Chehab if ($ver_string =~ m/^(\d+)(\.\d+)?(\.\d+)?/) { 50793351d41SMauro Carvalho Chehab $sphinx_major = $1; 50893351d41SMauro Carvalho Chehab if (defined($2)) { 50993351d41SMauro Carvalho Chehab $sphinx_minor = substr($2,1); 51093351d41SMauro Carvalho Chehab } else { 51193351d41SMauro Carvalho Chehab $sphinx_minor = 0; 51293351d41SMauro Carvalho Chehab } 51393351d41SMauro Carvalho Chehab if (defined($3)) { 51493351d41SMauro Carvalho Chehab $sphinx_patch = substr($3,1) 51593351d41SMauro Carvalho Chehab } else { 51693351d41SMauro Carvalho Chehab $sphinx_patch = 0; 51793351d41SMauro Carvalho Chehab } 51893351d41SMauro Carvalho Chehab } else { 51993351d41SMauro Carvalho Chehab die "Sphinx version should either major.minor or major.minor.patch format\n"; 52093351d41SMauro Carvalho Chehab } 521b031ac4eSMauro Carvalho Chehab } else { 522b031ac4eSMauro Carvalho Chehab # Unknown argument 52343caf1a6STomasz Warniełło pod2usage( 52443caf1a6STomasz Warniełło -message => "Argument unknown!\n", 52543caf1a6STomasz Warniełło -exitval => 1, 52643caf1a6STomasz Warniełło -verbose => 99, 52743caf1a6STomasz Warniełło -sections => 'SYNOPSIS', 52843caf1a6STomasz Warniełło -output => \*STDERR, 52943caf1a6STomasz Warniełło ); 5301da177e4SLinus Torvalds } 5311da177e4SLinus Torvalds} 5321da177e4SLinus Torvalds 5338484baaaSRandy Dunlap# continue execution near EOF; 5348484baaaSRandy Dunlap 535efa44475SMauro Carvalho Chehab# The C domain dialect changed on Sphinx 3. So, we need to check the 536efa44475SMauro Carvalho Chehab# version in order to produce the right tags. 537efa44475SMauro Carvalho Chehabsub findprog($) 538efa44475SMauro Carvalho Chehab{ 539efa44475SMauro Carvalho Chehab foreach(split(/:/, $ENV{PATH})) { 540efa44475SMauro Carvalho Chehab return "$_/$_[0]" if(-x "$_/$_[0]"); 541efa44475SMauro Carvalho Chehab } 542efa44475SMauro Carvalho Chehab} 543efa44475SMauro Carvalho Chehab 544efa44475SMauro Carvalho Chehabsub get_sphinx_version() 545efa44475SMauro Carvalho Chehab{ 546efa44475SMauro Carvalho Chehab my $ver; 547efa44475SMauro Carvalho Chehab 548efa44475SMauro Carvalho Chehab my $cmd = "sphinx-build"; 549efa44475SMauro Carvalho Chehab if (!findprog($cmd)) { 550efa44475SMauro Carvalho Chehab my $cmd = "sphinx-build3"; 55193351d41SMauro Carvalho Chehab if (!findprog($cmd)) { 55293351d41SMauro Carvalho Chehab $sphinx_major = 1; 55393351d41SMauro Carvalho Chehab $sphinx_minor = 2; 55493351d41SMauro Carvalho Chehab $sphinx_patch = 0; 55593351d41SMauro Carvalho Chehab printf STDERR "Warning: Sphinx version not found. Using default (Sphinx version %d.%d.%d)\n", 55693351d41SMauro Carvalho Chehab $sphinx_major, $sphinx_minor, $sphinx_patch; 55793351d41SMauro Carvalho Chehab return; 55893351d41SMauro Carvalho Chehab } 559efa44475SMauro Carvalho Chehab } 560efa44475SMauro Carvalho Chehab 561efa44475SMauro Carvalho Chehab open IN, "$cmd --version 2>&1 |"; 562efa44475SMauro Carvalho Chehab while (<IN>) { 563efa44475SMauro Carvalho Chehab if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) { 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 # Sphinx 1.2.x uses a different format 570efa44475SMauro Carvalho Chehab if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+)$/) { 57193351d41SMauro Carvalho Chehab $sphinx_major = $1; 57293351d41SMauro Carvalho Chehab $sphinx_minor = $2; 57393351d41SMauro Carvalho Chehab $sphinx_patch = $3; 574efa44475SMauro Carvalho Chehab last; 575efa44475SMauro Carvalho Chehab } 576efa44475SMauro Carvalho Chehab } 577efa44475SMauro Carvalho Chehab close IN; 578efa44475SMauro Carvalho Chehab} 579efa44475SMauro Carvalho Chehab 58053f049faSBorislav Petkov# get kernel version from env 58153f049faSBorislav Petkovsub get_kernel_version() { 5821b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 58353f049faSBorislav Petkov 58453f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 58553f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 58653f049faSBorislav Petkov } 58753f049faSBorislav Petkov return $version; 58853f049faSBorislav Petkov} 5891da177e4SLinus Torvalds 5900b0f5f29SDaniel Vetter# 5910b0f5f29SDaniel Vettersub print_lineno { 5920b0f5f29SDaniel Vetter my $lineno = shift; 5930b0f5f29SDaniel Vetter if ($enable_lineno && defined($lineno)) { 5940b0f5f29SDaniel Vetter print "#define LINENO " . $lineno . "\n"; 5950b0f5f29SDaniel Vetter } 5960b0f5f29SDaniel Vetter} 5971da177e4SLinus Torvalds## 5981da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 5991da177e4SLinus Torvalds# 6001da177e4SLinus Torvaldssub dump_section { 60194dc7ad5SRandy Dunlap my $file = shift; 6021da177e4SLinus Torvalds my $name = shift; 6031da177e4SLinus Torvalds my $contents = join "\n", @_; 6041da177e4SLinus Torvalds 60513901ef2SJani Nikula if ($name =~ m/$type_param/) { 6061da177e4SLinus Torvalds $name = $1; 6071da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 608a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 6090b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 6100b0f5f29SDaniel Vetter $new_start_line = 0; 611ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 612ced69090SRandy Dunlap $name = "..."; 613ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 614a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 6150b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 6160b0f5f29SDaniel Vetter $new_start_line = 0; 6171da177e4SLinus Torvalds } else { 61894dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 61995b6be9dSJani Nikula # Only warn on user specified duplicate section names. 62095b6be9dSJani Nikula if ($name ne $section_default) { 62132217761SJani Nikula print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; 62232217761SJani Nikula ++$warnings; 62395b6be9dSJani Nikula } 62432217761SJani Nikula $sections{$name} .= $contents; 62532217761SJani Nikula } else { 6261da177e4SLinus Torvalds $sections{$name} = $contents; 6271da177e4SLinus Torvalds push @sectionlist, $name; 6280b0f5f29SDaniel Vetter $section_start_lines{$name} = $new_start_line; 6290b0f5f29SDaniel Vetter $new_start_line = 0; 6301da177e4SLinus Torvalds } 6311da177e4SLinus Torvalds } 63232217761SJani Nikula} 6331da177e4SLinus Torvalds 6341da177e4SLinus Torvalds## 635b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 636b112e0f7SJohannes Berg# 637b112e0f7SJohannes Bergsub dump_doc_section { 63894dc7ad5SRandy Dunlap my $file = shift; 639b112e0f7SJohannes Berg my $name = shift; 640b112e0f7SJohannes Berg my $contents = join "\n", @_; 641b112e0f7SJohannes Berg 6424b44595aSJohannes Berg if ($no_doc_sections) { 6434b44595aSJohannes Berg return; 6444b44595aSJohannes Berg } 6454b44595aSJohannes Berg 646eab795ddSMauro Carvalho Chehab return if (defined($nosymbol_table{$name})); 647eab795ddSMauro Carvalho Chehab 648b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 649eab795ddSMauro Carvalho Chehab (($output_selection == OUTPUT_INCLUDE) && 650eab795ddSMauro Carvalho Chehab defined($function_table{$name}))) 651b112e0f7SJohannes Berg { 65294dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 653b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 654b112e0f7SJohannes Berg 'sections' => \%sections, 655b112e0f7SJohannes Berg 'module' => $modulename, 656b6c3f456SJani Nikula 'content-only' => ($output_selection != OUTPUT_ALL), }); 657b112e0f7SJohannes Berg } 658b112e0f7SJohannes Berg} 659b112e0f7SJohannes Berg 660b112e0f7SJohannes Berg## 6611da177e4SLinus Torvalds# output function 6621da177e4SLinus Torvalds# 6631da177e4SLinus Torvalds# parameterdescs, a hash. 6641da177e4SLinus Torvalds# function => "function name" 6651da177e4SLinus Torvalds# parameterlist => @list of parameters 6661da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 6671da177e4SLinus Torvalds# sectionlist => @list of sections 668a21217daSRandy Dunlap# sections => %section descriptions 6691da177e4SLinus Torvalds# 6701da177e4SLinus Torvalds 6711da177e4SLinus Torvaldssub output_highlight { 6721da177e4SLinus Torvalds my $contents = join "\n",@_; 6731da177e4SLinus Torvalds my $line; 6741da177e4SLinus Torvalds 6751da177e4SLinus Torvalds# DEBUG 6761da177e4SLinus Torvalds# if (!defined $contents) { 6771da177e4SLinus Torvalds# use Carp; 6781da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 6791da177e4SLinus Torvalds# } 6801da177e4SLinus Torvalds 6813eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 6821da177e4SLinus Torvalds eval $dohighlight; 6831da177e4SLinus Torvalds die $@ if $@; 6843eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 6853eb014a1SRandy Dunlap 6861da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 68712ae6779SDaniel Santos if (! $output_preformatted) { 68812ae6779SDaniel Santos $line =~ s/^\s*//; 68912ae6779SDaniel Santos } 6901da177e4SLinus Torvalds if ($line eq ""){ 691e314ba31SDaniel Santos if (! $output_preformatted) { 6920bba924cSJonathan Corbet print $lineprefix, $blankline; 693e314ba31SDaniel Santos } 6941da177e4SLinus Torvalds } else { 695cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 696cdccb316SRandy Dunlap print "\\&$line"; 697cdccb316SRandy Dunlap } else { 6981da177e4SLinus Torvalds print $lineprefix, $line; 6991da177e4SLinus Torvalds } 700cdccb316SRandy Dunlap } 7011da177e4SLinus Torvalds print "\n"; 7021da177e4SLinus Torvalds } 7031da177e4SLinus Torvalds} 7041da177e4SLinus Torvalds 7051da177e4SLinus Torvalds## 7061da177e4SLinus Torvalds# output function in man 7071da177e4SLinus Torvaldssub output_function_man(%) { 7081da177e4SLinus Torvalds my %args = %{$_[0]}; 7091da177e4SLinus Torvalds my ($parameter, $section); 7101da177e4SLinus Torvalds my $count; 7111da177e4SLinus Torvalds 7121da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 7131da177e4SLinus Torvalds 7141da177e4SLinus Torvalds print ".SH NAME\n"; 7151da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 7161da177e4SLinus Torvalds 7171da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 718a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 7191da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 720a21217daSRandy Dunlap } else { 721a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 722a21217daSRandy Dunlap } 7231da177e4SLinus Torvalds $count = 0; 7241da177e4SLinus Torvalds my $parenth = "("; 7251da177e4SLinus Torvalds my $post = ","; 7261da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 7271da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 7281da177e4SLinus Torvalds $post = ");"; 7291da177e4SLinus Torvalds } 7301da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 731e86bdb24SAditya Srivastava if ($type =~ m/$function_pointer/) { 7321da177e4SLinus Torvalds # pointer-to-function 733ed8348e2SMauro Carvalho Chehab print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n"; 7341da177e4SLinus Torvalds } else { 7351da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 736ed8348e2SMauro Carvalho Chehab print ".BI \"" . $parenth . $type . "\" " . " \"" . $post . "\"\n"; 7371da177e4SLinus Torvalds } 7381da177e4SLinus Torvalds $count++; 7391da177e4SLinus Torvalds $parenth = ""; 7401da177e4SLinus Torvalds } 7411da177e4SLinus Torvalds 7421da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 7431da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7441da177e4SLinus Torvalds my $parameter_name = $parameter; 7451da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7461da177e4SLinus Torvalds 7471da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 7481da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7491da177e4SLinus Torvalds } 7501da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7511da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 7521da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7531da177e4SLinus Torvalds } 7541da177e4SLinus Torvalds} 7551da177e4SLinus Torvalds 7561da177e4SLinus Torvalds## 7571da177e4SLinus Torvalds# output enum in man 7581da177e4SLinus Torvaldssub output_enum_man(%) { 7591da177e4SLinus Torvalds my %args = %{$_[0]}; 7601da177e4SLinus Torvalds my ($parameter, $section); 7611da177e4SLinus Torvalds my $count; 7621da177e4SLinus Torvalds 7631da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 7641da177e4SLinus Torvalds 7651da177e4SLinus Torvalds print ".SH NAME\n"; 7661da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 7671da177e4SLinus Torvalds 7681da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 7691da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 7701da177e4SLinus Torvalds $count = 0; 7711da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 7721da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 7731da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 7741da177e4SLinus Torvalds print "\n};\n"; 7751da177e4SLinus Torvalds last; 7761da177e4SLinus Torvalds } 7771da177e4SLinus Torvalds else { 7781da177e4SLinus Torvalds print ", \n.br\n"; 7791da177e4SLinus Torvalds } 7801da177e4SLinus Torvalds $count++; 7811da177e4SLinus Torvalds } 7821da177e4SLinus Torvalds 7831da177e4SLinus Torvalds print ".SH Constants\n"; 7841da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7851da177e4SLinus Torvalds my $parameter_name = $parameter; 7861da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7871da177e4SLinus Torvalds 7881da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 7891da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7901da177e4SLinus Torvalds } 7911da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7921da177e4SLinus Torvalds print ".SH \"$section\"\n"; 7931da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7941da177e4SLinus Torvalds } 7951da177e4SLinus Torvalds} 7961da177e4SLinus Torvalds 7971da177e4SLinus Torvalds## 7981da177e4SLinus Torvalds# output struct in man 7991da177e4SLinus Torvaldssub output_struct_man(%) { 8001da177e4SLinus Torvalds my %args = %{$_[0]}; 8011da177e4SLinus Torvalds my ($parameter, $section); 8021da177e4SLinus Torvalds 8031da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 8041da177e4SLinus Torvalds 8051da177e4SLinus Torvalds print ".SH NAME\n"; 8061da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 8071da177e4SLinus Torvalds 8088ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 8098ad72163SMauro Carvalho Chehab $declaration =~ s/\t/ /g; 8108ad72163SMauro Carvalho Chehab $declaration =~ s/\n/"\n.br\n.BI \"/g; 8111da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 8121da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 8138ad72163SMauro Carvalho Chehab print ".BI \"$declaration\n};\n.br\n\n"; 8141da177e4SLinus Torvalds 815c51d3dacSRandy Dunlap print ".SH Members\n"; 8161da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 8171da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 8181da177e4SLinus Torvalds 8191da177e4SLinus Torvalds my $parameter_name = $parameter; 8201da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 8211da177e4SLinus Torvalds 8221da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 8231da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 8241da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 8251da177e4SLinus Torvalds } 8261da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 8271da177e4SLinus Torvalds print ".SH \"$section\"\n"; 8281da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 8291da177e4SLinus Torvalds } 8301da177e4SLinus Torvalds} 8311da177e4SLinus Torvalds 8321da177e4SLinus Torvalds## 8331da177e4SLinus Torvalds# output typedef in man 8341da177e4SLinus Torvaldssub output_typedef_man(%) { 8351da177e4SLinus Torvalds my %args = %{$_[0]}; 8361da177e4SLinus Torvalds my ($parameter, $section); 8371da177e4SLinus Torvalds 8381da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 8391da177e4SLinus Torvalds 8401da177e4SLinus Torvalds print ".SH NAME\n"; 8411da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 8421da177e4SLinus Torvalds 8431da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 8441da177e4SLinus Torvalds print ".SH \"$section\"\n"; 8451da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 8461da177e4SLinus Torvalds } 8471da177e4SLinus Torvalds} 8481da177e4SLinus Torvalds 849b112e0f7SJohannes Bergsub output_blockhead_man(%) { 8501da177e4SLinus Torvalds my %args = %{$_[0]}; 8511da177e4SLinus Torvalds my ($parameter, $section); 8521da177e4SLinus Torvalds my $count; 8531da177e4SLinus Torvalds 8541da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 8551da177e4SLinus Torvalds 8561da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 8571da177e4SLinus Torvalds print ".SH \"$section\"\n"; 8581da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 8591da177e4SLinus Torvalds } 8601da177e4SLinus Torvalds} 8611da177e4SLinus Torvalds 8621da177e4SLinus Torvalds## 863c0d1b6eeSJonathan Corbet# output in restructured text 864c0d1b6eeSJonathan Corbet# 865c0d1b6eeSJonathan Corbet 866c0d1b6eeSJonathan Corbet# 867c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 868c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 869c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 870c0d1b6eeSJonathan Corbet# 871c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 872c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 873c0d1b6eeSJonathan Corbet my ($parameter, $section); 874c0d1b6eeSJonathan Corbet 875c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 876eab795ddSMauro Carvalho Chehab next if (defined($nosymbol_table{$section})); 877eab795ddSMauro Carvalho Chehab 8789e72184bSJani Nikula if ($output_selection != OUTPUT_INCLUDE) { 87906a755d6SMichal Wajdeczko print ".. _$section:\n\n"; 880c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 8819e72184bSJani Nikula } 8820b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 883c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 884c0d1b6eeSJonathan Corbet print "\n"; 885c0d1b6eeSJonathan Corbet } 886c0d1b6eeSJonathan Corbet} 887c0d1b6eeSJonathan Corbet 888af250290SJonathan Corbet# 889af250290SJonathan Corbet# Apply the RST highlights to a sub-block of text. 890af250290SJonathan Corbet# 891af250290SJonathan Corbetsub highlight_block($) { 892af250290SJonathan Corbet # The dohighlight kludge requires the text be called $contents 893af250290SJonathan Corbet my $contents = shift; 894c0d1b6eeSJonathan Corbet eval $dohighlight; 895c0d1b6eeSJonathan Corbet die $@ if $@; 896af250290SJonathan Corbet return $contents; 897af250290SJonathan Corbet} 898c0d1b6eeSJonathan Corbet 899af250290SJonathan Corbet# 900af250290SJonathan Corbet# Regexes used only here. 901af250290SJonathan Corbet# 902af250290SJonathan Corbetmy $sphinx_literal = '^[^.].*::$'; 903af250290SJonathan Corbetmy $sphinx_cblock = '^\.\.\ +code-block::'; 904af250290SJonathan Corbet 905af250290SJonathan Corbetsub output_highlight_rst { 906af250290SJonathan Corbet my $input = join "\n",@_; 907af250290SJonathan Corbet my $output = ""; 908af250290SJonathan Corbet my $line; 909af250290SJonathan Corbet my $in_literal = 0; 910af250290SJonathan Corbet my $litprefix; 911af250290SJonathan Corbet my $block = ""; 912af250290SJonathan Corbet 913af250290SJonathan Corbet foreach $line (split "\n",$input) { 914af250290SJonathan Corbet # 915af250290SJonathan Corbet # If we're in a literal block, see if we should drop out 916af250290SJonathan Corbet # of it. Otherwise pass the line straight through unmunged. 917af250290SJonathan Corbet # 918af250290SJonathan Corbet if ($in_literal) { 919af250290SJonathan Corbet if (! ($line =~ /^\s*$/)) { 920af250290SJonathan Corbet # 921af250290SJonathan Corbet # If this is the first non-blank line in a literal 922af250290SJonathan Corbet # block we need to figure out what the proper indent is. 923af250290SJonathan Corbet # 924af250290SJonathan Corbet if ($litprefix eq "") { 925af250290SJonathan Corbet $line =~ /^(\s*)/; 926af250290SJonathan Corbet $litprefix = '^' . $1; 927af250290SJonathan Corbet $output .= $line . "\n"; 928af250290SJonathan Corbet } elsif (! ($line =~ /$litprefix/)) { 929af250290SJonathan Corbet $in_literal = 0; 930af250290SJonathan Corbet } else { 931af250290SJonathan Corbet $output .= $line . "\n"; 932af250290SJonathan Corbet } 933af250290SJonathan Corbet } else { 934af250290SJonathan Corbet $output .= $line . "\n"; 935af250290SJonathan Corbet } 936af250290SJonathan Corbet } 937af250290SJonathan Corbet # 938af250290SJonathan Corbet # Not in a literal block (or just dropped out) 939af250290SJonathan Corbet # 940af250290SJonathan Corbet if (! $in_literal) { 941af250290SJonathan Corbet $block .= $line . "\n"; 942af250290SJonathan Corbet if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) { 943af250290SJonathan Corbet $in_literal = 1; 944af250290SJonathan Corbet $litprefix = ""; 945af250290SJonathan Corbet $output .= highlight_block($block); 946af250290SJonathan Corbet $block = "" 947af250290SJonathan Corbet } 948af250290SJonathan Corbet } 949af250290SJonathan Corbet } 950af250290SJonathan Corbet 951af250290SJonathan Corbet if ($block) { 952af250290SJonathan Corbet $output .= highlight_block($block); 953af250290SJonathan Corbet } 954af250290SJonathan Corbet foreach $line (split "\n", $output) { 955830066a7SJani Nikula print $lineprefix . $line . "\n"; 956c0d1b6eeSJonathan Corbet } 957c0d1b6eeSJonathan Corbet} 958c0d1b6eeSJonathan Corbet 959c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 960c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 961c0d1b6eeSJonathan Corbet my ($parameter, $section); 962c099ff69SJani Nikula my $oldprefix = $lineprefix; 96382801d06SMauro Carvalho Chehab my $start = ""; 9646e9e4158SMauro Carvalho Chehab my $is_macro = 0; 965c0d1b6eeSJonathan Corbet 966efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 967e3ad05feSMauro Carvalho Chehab if ($args{'typedef'}) { 96882801d06SMauro Carvalho Chehab print ".. c:type:: ". $args{'function'} . "\n\n"; 96982801d06SMauro Carvalho Chehab print_lineno($declaration_start_line); 97082801d06SMauro Carvalho Chehab print " **Typedef**: "; 97182801d06SMauro Carvalho Chehab $lineprefix = ""; 97282801d06SMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 97382801d06SMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 9746e9e4158SMauro Carvalho Chehab $is_macro = 1; 975c0d1b6eeSJonathan Corbet } else { 97682801d06SMauro Carvalho Chehab print ".. c:function:: "; 97782801d06SMauro Carvalho Chehab } 978e3ad05feSMauro Carvalho Chehab } else { 9796e9e4158SMauro Carvalho Chehab if ($args{'typedef'} || $args{'functiontype'} eq "") { 9806e9e4158SMauro Carvalho Chehab $is_macro = 1; 981e3ad05feSMauro Carvalho Chehab print ".. c:macro:: ". $args{'function'} . "\n\n"; 9826e9e4158SMauro Carvalho Chehab } else { 9836e9e4158SMauro Carvalho Chehab print ".. c:function:: "; 9846e9e4158SMauro Carvalho Chehab } 985e3ad05feSMauro Carvalho Chehab 986e3ad05feSMauro Carvalho Chehab if ($args{'typedef'}) { 987e3ad05feSMauro Carvalho Chehab print_lineno($declaration_start_line); 988e3ad05feSMauro Carvalho Chehab print " **Typedef**: "; 989e3ad05feSMauro Carvalho Chehab $lineprefix = ""; 990e3ad05feSMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 991e3ad05feSMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 992e3ad05feSMauro Carvalho Chehab } else { 9936e9e4158SMauro Carvalho Chehab print "``" if ($is_macro); 994e3ad05feSMauro Carvalho Chehab } 995e3ad05feSMauro Carvalho Chehab } 99682801d06SMauro Carvalho Chehab if ($args{'functiontype'} ne "") { 99782801d06SMauro Carvalho Chehab $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; 99882801d06SMauro Carvalho Chehab } else { 99982801d06SMauro Carvalho Chehab $start .= $args{'function'} . " ("; 1000c0d1b6eeSJonathan Corbet } 1001c0d1b6eeSJonathan Corbet print $start; 1002c0d1b6eeSJonathan Corbet 1003c0d1b6eeSJonathan Corbet my $count = 0; 1004c0d1b6eeSJonathan Corbet foreach my $parameter (@{$args{'parameterlist'}}) { 1005c0d1b6eeSJonathan Corbet if ($count ne 0) { 1006c0d1b6eeSJonathan Corbet print ", "; 1007c0d1b6eeSJonathan Corbet } 1008c0d1b6eeSJonathan Corbet $count++; 1009c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1010a88b1672SMauro Carvalho Chehab 1011e86bdb24SAditya Srivastava if ($type =~ m/$function_pointer/) { 1012c0d1b6eeSJonathan Corbet # pointer-to-function 1013e8f4ba83SPeter Maydell print $1 . $parameter . ") (" . $2 . ")"; 1014c0d1b6eeSJonathan Corbet } else { 1015ed8348e2SMauro Carvalho Chehab print $type; 1016c0d1b6eeSJonathan Corbet } 1017c0d1b6eeSJonathan Corbet } 10186e9e4158SMauro Carvalho Chehab if ($is_macro) { 10196e9e4158SMauro Carvalho Chehab print ")``\n\n"; 102082801d06SMauro Carvalho Chehab } else { 1021c099ff69SJani Nikula print ")\n\n"; 1022e3ad05feSMauro Carvalho Chehab } 10236e9e4158SMauro Carvalho Chehab if (!$args{'typedef'}) { 10240b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1025c099ff69SJani Nikula $lineprefix = " "; 1026c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1027c099ff69SJani Nikula print "\n"; 102882801d06SMauro Carvalho Chehab } 1029c0d1b6eeSJonathan Corbet 1030ecbcfba1SJani Nikula print "**Parameters**\n\n"; 1031c099ff69SJani Nikula $lineprefix = " "; 1032c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1033c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1034ada5f446SGabriel Krisman Bertazi $parameter_name =~ s/\[.*//; 1035c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1036c0d1b6eeSJonathan Corbet 1037c0d1b6eeSJonathan Corbet if ($type ne "") { 1038ed8348e2SMauro Carvalho Chehab print "``$type``\n"; 1039c0d1b6eeSJonathan Corbet } else { 1040c0d1b6eeSJonathan Corbet print "``$parameter``\n"; 1041c0d1b6eeSJonathan Corbet } 10420b0f5f29SDaniel Vetter 10430b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 10440b0f5f29SDaniel Vetter 10455e64fa9cSJani Nikula if (defined($args{'parameterdescs'}{$parameter_name}) && 10465e64fa9cSJani Nikula $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 1047c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1048c0d1b6eeSJonathan Corbet } else { 1049d4b08e0cSJani Nikula print " *undescribed*\n"; 1050c0d1b6eeSJonathan Corbet } 1051c0d1b6eeSJonathan Corbet print "\n"; 1052c0d1b6eeSJonathan Corbet } 1053c099ff69SJani Nikula 1054c099ff69SJani Nikula $lineprefix = $oldprefix; 1055c0d1b6eeSJonathan Corbet output_section_rst(@_); 1056c0d1b6eeSJonathan Corbet} 1057c0d1b6eeSJonathan Corbet 1058c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 1059c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1060c0d1b6eeSJonathan Corbet my $section; 1061c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1062c0d1b6eeSJonathan Corbet $lineprefix = ""; 1063c0d1b6eeSJonathan Corbet 1064c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 1065ecbcfba1SJani Nikula print "**$section**\n\n"; 10660b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 1067c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1068c0d1b6eeSJonathan Corbet print "\n"; 1069c0d1b6eeSJonathan Corbet } 1070c0d1b6eeSJonathan Corbet print "\n"; 1071c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1072c0d1b6eeSJonathan Corbet} 1073c0d1b6eeSJonathan Corbet 1074c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 1075c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1076c0d1b6eeSJonathan Corbet my ($parameter); 1077c099ff69SJani Nikula my $oldprefix = $lineprefix; 1078c0d1b6eeSJonathan Corbet my $count; 107962850976SJani Nikula 1080efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 1081efa44475SMauro Carvalho Chehab my $name = "enum " . $args{'enum'}; 108262850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1083efa44475SMauro Carvalho Chehab } else { 1084efa44475SMauro Carvalho Chehab my $name = $args{'enum'}; 1085efa44475SMauro Carvalho Chehab print "\n\n.. c:enum:: " . $name . "\n\n"; 1086efa44475SMauro Carvalho Chehab } 10870b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1088c099ff69SJani Nikula $lineprefix = " "; 1089c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1090c099ff69SJani Nikula print "\n"; 1091c0d1b6eeSJonathan Corbet 1092ecbcfba1SJani Nikula print "**Constants**\n\n"; 1093c0d1b6eeSJonathan Corbet $lineprefix = " "; 1094c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1095ecbcfba1SJani Nikula print "``$parameter``\n"; 1096c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 1097c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 1098c0d1b6eeSJonathan Corbet } else { 1099d4b08e0cSJani Nikula print " *undescribed*\n"; 1100c0d1b6eeSJonathan Corbet } 1101c0d1b6eeSJonathan Corbet print "\n"; 1102c0d1b6eeSJonathan Corbet } 1103c099ff69SJani Nikula 1104c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1105c0d1b6eeSJonathan Corbet output_section_rst(@_); 1106c0d1b6eeSJonathan Corbet} 1107c0d1b6eeSJonathan Corbet 1108c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 1109c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1110c0d1b6eeSJonathan Corbet my ($parameter); 1111c099ff69SJani Nikula my $oldprefix = $lineprefix; 1112efa44475SMauro Carvalho Chehab my $name; 1113c0d1b6eeSJonathan Corbet 1114efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 1115efa44475SMauro Carvalho Chehab $name = "typedef " . $args{'typedef'}; 1116efa44475SMauro Carvalho Chehab } else { 1117efa44475SMauro Carvalho Chehab $name = $args{'typedef'}; 1118efa44475SMauro Carvalho Chehab } 111962850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 11200b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1121c099ff69SJani Nikula $lineprefix = " "; 1122c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1123c099ff69SJani Nikula print "\n"; 1124c0d1b6eeSJonathan Corbet 1125c099ff69SJani Nikula $lineprefix = $oldprefix; 1126c0d1b6eeSJonathan Corbet output_section_rst(@_); 1127c0d1b6eeSJonathan Corbet} 1128c0d1b6eeSJonathan Corbet 1129c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 1130c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1131c0d1b6eeSJonathan Corbet my ($parameter); 1132c099ff69SJani Nikula my $oldprefix = $lineprefix; 1133c0d1b6eeSJonathan Corbet 1134efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 1135efa44475SMauro Carvalho Chehab my $name = $args{'type'} . " " . $args{'struct'}; 113662850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1137efa44475SMauro Carvalho Chehab } else { 1138efa44475SMauro Carvalho Chehab my $name = $args{'struct'}; 113972b97d0bSMauro Carvalho Chehab if ($args{'type'} eq 'union') { 114072b97d0bSMauro Carvalho Chehab print "\n\n.. c:union:: " . $name . "\n\n"; 114172b97d0bSMauro Carvalho Chehab } else { 1142efa44475SMauro Carvalho Chehab print "\n\n.. c:struct:: " . $name . "\n\n"; 1143efa44475SMauro Carvalho Chehab } 114472b97d0bSMauro Carvalho Chehab } 11450b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1146c099ff69SJani Nikula $lineprefix = " "; 1147c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1148c099ff69SJani Nikula print "\n"; 1149c0d1b6eeSJonathan Corbet 1150ecbcfba1SJani Nikula print "**Definition**\n\n"; 1151c0d1b6eeSJonathan Corbet print "::\n\n"; 11528ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 11538ad72163SMauro Carvalho Chehab $declaration =~ s/\t/ /g; 11548ad72163SMauro Carvalho Chehab print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n"; 1155c0d1b6eeSJonathan Corbet 1156ecbcfba1SJani Nikula print "**Members**\n\n"; 1157c099ff69SJani Nikula $lineprefix = " "; 1158c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1159c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 1160c0d1b6eeSJonathan Corbet 1161c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1162c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 1163c0d1b6eeSJonathan Corbet 1164c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1165c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 11660b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 11676d232c80SMauro Carvalho Chehab print "``" . $parameter . "``\n"; 1168c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1169c0d1b6eeSJonathan Corbet print "\n"; 1170c0d1b6eeSJonathan Corbet } 1171c0d1b6eeSJonathan Corbet print "\n"; 1172c099ff69SJani Nikula 1173c099ff69SJani Nikula $lineprefix = $oldprefix; 1174c0d1b6eeSJonathan Corbet output_section_rst(@_); 1175c0d1b6eeSJonathan Corbet} 1176c0d1b6eeSJonathan Corbet 11773a025e1dSMatthew Wilcox## none mode output functions 11783a025e1dSMatthew Wilcox 11793a025e1dSMatthew Wilcoxsub output_function_none(%) { 11803a025e1dSMatthew Wilcox} 11813a025e1dSMatthew Wilcox 11823a025e1dSMatthew Wilcoxsub output_enum_none(%) { 11833a025e1dSMatthew Wilcox} 11843a025e1dSMatthew Wilcox 11853a025e1dSMatthew Wilcoxsub output_typedef_none(%) { 11863a025e1dSMatthew Wilcox} 11873a025e1dSMatthew Wilcox 11883a025e1dSMatthew Wilcoxsub output_struct_none(%) { 11893a025e1dSMatthew Wilcox} 11903a025e1dSMatthew Wilcox 11913a025e1dSMatthew Wilcoxsub output_blockhead_none(%) { 11923a025e1dSMatthew Wilcox} 11933a025e1dSMatthew Wilcox 11941da177e4SLinus Torvalds## 119527205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 119627205744SRandy Dunlap# calls the generated, variable output_ function name based on 119727205744SRandy Dunlap# functype and output_mode 11981da177e4SLinus Torvaldssub output_declaration { 11991da177e4SLinus Torvalds no strict 'refs'; 12001da177e4SLinus Torvalds my $name = shift; 12011da177e4SLinus Torvalds my $functype = shift; 12021da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 1203eab795ddSMauro Carvalho Chehab 1204eab795ddSMauro Carvalho Chehab return if (defined($nosymbol_table{$name})); 1205eab795ddSMauro Carvalho Chehab 1206b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 1207b6c3f456SJani Nikula (($output_selection == OUTPUT_INCLUDE || 1208b6c3f456SJani Nikula $output_selection == OUTPUT_EXPORTED) && 120986ae2e38SJani Nikula defined($function_table{$name})) || 1210eab795ddSMauro Carvalho Chehab ($output_selection == OUTPUT_INTERNAL && 121186ae2e38SJani Nikula !($functype eq "function" && defined($function_table{$name})))) 12121da177e4SLinus Torvalds { 12131da177e4SLinus Torvalds &$func(@_); 12141da177e4SLinus Torvalds $section_counter++; 12151da177e4SLinus Torvalds } 12161da177e4SLinus Torvalds} 12171da177e4SLinus Torvalds 12181da177e4SLinus Torvalds## 121927205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 1220b112e0f7SJohannes Bergsub output_blockhead { 12211da177e4SLinus Torvalds no strict 'refs'; 1222b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 12231da177e4SLinus Torvalds &$func(@_); 12241da177e4SLinus Torvalds $section_counter++; 12251da177e4SLinus Torvalds} 12261da177e4SLinus Torvalds 12271da177e4SLinus Torvalds## 12281da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 12291da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 12301da177e4SLinus Torvaldssub dump_declaration($$) { 12311da177e4SLinus Torvalds no strict 'refs'; 12321da177e4SLinus Torvalds my ($prototype, $file) = @_; 12331da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 12341da177e4SLinus Torvalds &$func(@_); 12351da177e4SLinus Torvalds} 12361da177e4SLinus Torvalds 12371da177e4SLinus Torvaldssub dump_union($$) { 12381da177e4SLinus Torvalds dump_struct(@_); 12391da177e4SLinus Torvalds} 12401da177e4SLinus Torvalds 12411da177e4SLinus Torvaldssub dump_struct($$) { 12421da177e4SLinus Torvalds my $x = shift; 12431da177e4SLinus Torvalds my $file = shift; 1244a746fe32SAditya Srivastava my $decl_type; 1245a746fe32SAditya Srivastava my $members; 1246a746fe32SAditya Srivastava my $type = qr{struct|union}; 1247a746fe32SAditya Srivastava # For capturing struct/union definition body, i.e. "{members*}qualifiers*" 1248e86bdb24SAditya Srivastava my $qualifiers = qr{$attribute|__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned}; 1249e86bdb24SAditya Srivastava my $definition_body = qr{\{(.*)\}\s*$qualifiers*}; 1250e86bdb24SAditya Srivastava my $struct_members = qr{($type)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;}; 12511da177e4SLinus Torvalds 1252a746fe32SAditya Srivastava if ($x =~ /($type)\s+(\w+)\s*$definition_body/) { 1253a746fe32SAditya Srivastava $decl_type = $1; 12541da177e4SLinus Torvalds $declaration_name = $2; 1255a746fe32SAditya Srivastava $members = $3; 1256a746fe32SAditya Srivastava } elsif ($x =~ /typedef\s+($type)\s*$definition_body\s*(\w+)\s*;/) { 1257a746fe32SAditya Srivastava $decl_type = $1; 1258a746fe32SAditya Srivastava $declaration_name = $3; 1259a746fe32SAditya Srivastava $members = $2; 1260a746fe32SAditya Srivastava } 12611da177e4SLinus Torvalds 1262a746fe32SAditya Srivastava if ($members) { 126352042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 126452042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: expecting prototype for $decl_type $identifier. Prototype was for $decl_type $declaration_name instead\n"; 126552042e2dSMauro Carvalho Chehab return; 126652042e2dSMauro Carvalho Chehab } 126752042e2dSMauro Carvalho Chehab 1268aeec46b9SMartin Waitz # ignore members marked private: 12690d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 12700d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 1271aeec46b9SMartin Waitz # strip comments: 1272aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 1273ef5da59fSRandy Dunlap # strip attributes 1274e86bdb24SAditya Srivastava $members =~ s/\s*$attribute/ /gi; 12753d9bfb19SSakari Ailus $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos; 12763d9bfb19SSakari Ailus $members =~ s/\s*__packed\s*/ /gos; 1277f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos; 1278f861537dSAndré Almeida $members =~ s/\s*____cacheline_aligned_in_smp/ /gos; 1279a070991fSJonathan Cameron $members =~ s/\s*____cacheline_aligned/ /gos; 128050d7bd38SKees Cook # unwrap struct_group(): 128150d7bd38SKees Cook # - first eat non-declaration parameters and rewrite for final match 128250d7bd38SKees Cook # - then remove macro, outer parens, and trailing semicolon 128350d7bd38SKees Cook $members =~ s/\bstruct_group\s*\(([^,]*,)/STRUCT_GROUP(/gos; 128450d7bd38SKees Cook $members =~ s/\bstruct_group_(attr|tagged)\s*\(([^,]*,){2}/STRUCT_GROUP(/gos; 128550d7bd38SKees Cook $members =~ s/\b__struct_group\s*\(([^,]*,){3}/STRUCT_GROUP(/gos; 128650d7bd38SKees Cook $members =~ s/\bSTRUCT_GROUP(\(((?:(?>[^)(]+)|(?1))*)\))[^;]*;/$2/gos; 12873556108eSMauro Carvalho Chehab 1288e86bdb24SAditya Srivastava my $args = qr{([^,)]+)}; 1289b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 12903556108eSMauro Carvalho Chehab $members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos; 1291603bdf5dSRandy Dunlap $members =~ s/DECLARE_PHY_INTERFACE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, PHY_INTERFACE_MODE_MAX)/gos; 1292e86bdb24SAditya Srivastava $members =~ s/DECLARE_BITMAP\s*\($args,\s*$args\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 12931cb566baSJakub Kicinski # replace DECLARE_HASHTABLE 1294e86bdb24SAditya Srivastava $members =~ s/DECLARE_HASHTABLE\s*\($args,\s*$args\)/unsigned long $1\[1 << (($2) - 1)\]/gos; 129545005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO 1296e86bdb24SAditya Srivastava $members =~ s/DECLARE_KFIFO\s*\($args,\s*$args,\s*$args\)/$2 \*$1/gos; 129745005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO_PTR 1298e86bdb24SAditya Srivastava $members =~ s/DECLARE_KFIFO_PTR\s*\($args,\s*$args\)/$2 \*$1/gos; 12993080ea55SKees Cook # replace DECLARE_FLEX_ARRAY 13003080ea55SKees Cook $members =~ s/(?:__)?DECLARE_FLEX_ARRAY\s*\($args,\s*$args\)/$1 $2\[\]/gos; 13018ad72163SMauro Carvalho Chehab my $declaration = $members; 13028ad72163SMauro Carvalho Chehab 13038ad72163SMauro Carvalho Chehab # Split nested struct/union elements as newer ones 1304e86bdb24SAditya Srivastava while ($members =~ m/$struct_members/) { 130584ce5b98SMauro Carvalho Chehab my $newmember; 130684ce5b98SMauro Carvalho Chehab my $maintype = $1; 130784ce5b98SMauro Carvalho Chehab my $ids = $4; 13088ad72163SMauro Carvalho Chehab my $content = $3; 130984ce5b98SMauro Carvalho Chehab foreach my $id(split /,/, $ids) { 131084ce5b98SMauro Carvalho Chehab $newmember .= "$maintype $id; "; 131184ce5b98SMauro Carvalho Chehab 13128ad72163SMauro Carvalho Chehab $id =~ s/[:\[].*//; 131384ce5b98SMauro Carvalho Chehab $id =~ s/^\s*\**(\S+)\s*/$1/; 13148ad72163SMauro Carvalho Chehab foreach my $arg (split /;/, $content) { 13158ad72163SMauro Carvalho Chehab next if ($arg =~ m/^\s*$/); 13167c0d7e87SMauro Carvalho Chehab if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) { 13177c0d7e87SMauro Carvalho Chehab # pointer-to-function 13187c0d7e87SMauro Carvalho Chehab my $type = $1; 13197c0d7e87SMauro Carvalho Chehab my $name = $2; 13207c0d7e87SMauro Carvalho Chehab my $extra = $3; 13217c0d7e87SMauro Carvalho Chehab next if (!$name); 13227c0d7e87SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 13237c0d7e87SMauro Carvalho Chehab # anonymous struct/union 13247c0d7e87SMauro Carvalho Chehab $newmember .= "$type$name$extra; "; 13257c0d7e87SMauro Carvalho Chehab } else { 13267c0d7e87SMauro Carvalho Chehab $newmember .= "$type$id.$name$extra; "; 13277c0d7e87SMauro Carvalho Chehab } 13287c0d7e87SMauro Carvalho Chehab } else { 132984ce5b98SMauro Carvalho Chehab my $type; 133084ce5b98SMauro Carvalho Chehab my $names; 133184ce5b98SMauro Carvalho Chehab $arg =~ s/^\s+//; 133284ce5b98SMauro Carvalho Chehab $arg =~ s/\s+$//; 133384ce5b98SMauro Carvalho Chehab # Handle bitmaps 133484ce5b98SMauro Carvalho Chehab $arg =~ s/:\s*\d+\s*//g; 133584ce5b98SMauro Carvalho Chehab # Handle arrays 1336d404d579SMauro Carvalho Chehab $arg =~ s/\[.*\]//g; 133784ce5b98SMauro Carvalho Chehab # The type may have multiple words, 133884ce5b98SMauro Carvalho Chehab # and multiple IDs can be defined, like: 133984ce5b98SMauro Carvalho Chehab # const struct foo, *bar, foobar 134084ce5b98SMauro Carvalho Chehab # So, we remove spaces when parsing the 134184ce5b98SMauro Carvalho Chehab # names, in order to match just names 134284ce5b98SMauro Carvalho Chehab # and commas for the names 134384ce5b98SMauro Carvalho Chehab $arg =~ s/\s*,\s*/,/g; 134484ce5b98SMauro Carvalho Chehab if ($arg =~ m/(.*)\s+([\S+,]+)/) { 134584ce5b98SMauro Carvalho Chehab $type = $1; 134684ce5b98SMauro Carvalho Chehab $names = $2; 134784ce5b98SMauro Carvalho Chehab } else { 134884ce5b98SMauro Carvalho Chehab $newmember .= "$arg; "; 134984ce5b98SMauro Carvalho Chehab next; 135084ce5b98SMauro Carvalho Chehab } 135184ce5b98SMauro Carvalho Chehab foreach my $name (split /,/, $names) { 135284ce5b98SMauro Carvalho Chehab $name =~ s/^\s*\**(\S+)\s*/$1/; 13538ad72163SMauro Carvalho Chehab next if (($name =~ m/^\s*$/)); 13548ad72163SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 13558ad72163SMauro Carvalho Chehab # anonymous struct/union 13568ad72163SMauro Carvalho Chehab $newmember .= "$type $name; "; 13578ad72163SMauro Carvalho Chehab } else { 13588ad72163SMauro Carvalho Chehab $newmember .= "$type $id.$name; "; 13598ad72163SMauro Carvalho Chehab } 13608ad72163SMauro Carvalho Chehab } 13617c0d7e87SMauro Carvalho Chehab } 136284ce5b98SMauro Carvalho Chehab } 136384ce5b98SMauro Carvalho Chehab } 1364e86bdb24SAditya Srivastava $members =~ s/$struct_members/$newmember/; 136584ce5b98SMauro Carvalho Chehab } 13668ad72163SMauro Carvalho Chehab 13678ad72163SMauro Carvalho Chehab # Ignore other nested elements, like enums 1368673bb2dfSBen Hutchings $members =~ s/(\{[^\{\}]*\})//g; 13698ad72163SMauro Carvalho Chehab 1370151c468bSMauro Carvalho Chehab create_parameterlist($members, ';', $file, $declaration_name); 13711081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual); 13721da177e4SLinus Torvalds 13738ad72163SMauro Carvalho Chehab # Adjust declaration for better display 1374673bb2dfSBen Hutchings $declaration =~ s/([\{;])/$1\n/g; 1375673bb2dfSBen Hutchings $declaration =~ s/\}\s+;/};/g; 13768ad72163SMauro Carvalho Chehab # Better handle inlined enums 1377673bb2dfSBen Hutchings do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/); 13788ad72163SMauro Carvalho Chehab 13798ad72163SMauro Carvalho Chehab my @def_args = split /\n/, $declaration; 13808ad72163SMauro Carvalho Chehab my $level = 1; 13818ad72163SMauro Carvalho Chehab $declaration = ""; 13828ad72163SMauro Carvalho Chehab foreach my $clause (@def_args) { 13838ad72163SMauro Carvalho Chehab $clause =~ s/^\s+//; 13848ad72163SMauro Carvalho Chehab $clause =~ s/\s+$//; 13858ad72163SMauro Carvalho Chehab $clause =~ s/\s+/ /; 13868ad72163SMauro Carvalho Chehab next if (!$clause); 1387673bb2dfSBen Hutchings $level-- if ($clause =~ m/(\})/ && $level > 1); 13888ad72163SMauro Carvalho Chehab if (!($clause =~ m/^\s*#/)) { 13898ad72163SMauro Carvalho Chehab $declaration .= "\t" x $level; 13908ad72163SMauro Carvalho Chehab } 13918ad72163SMauro Carvalho Chehab $declaration .= "\t" . $clause . "\n"; 1392673bb2dfSBen Hutchings $level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/)); 13938ad72163SMauro Carvalho Chehab } 13941da177e4SLinus Torvalds output_declaration($declaration_name, 13951da177e4SLinus Torvalds 'struct', 13961da177e4SLinus Torvalds {'struct' => $declaration_name, 13971da177e4SLinus Torvalds 'module' => $modulename, 13988ad72163SMauro Carvalho Chehab 'definition' => $declaration, 13991da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 14001da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 14011da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 14021da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 14031da177e4SLinus Torvalds 'sections' => \%sections, 14041da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 14051da177e4SLinus Torvalds 'type' => $decl_type 14061da177e4SLinus Torvalds }); 14071da177e4SLinus Torvalds } 14081da177e4SLinus Torvalds else { 1409d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 14101da177e4SLinus Torvalds ++$errors; 14111da177e4SLinus Torvalds } 14121da177e4SLinus Torvalds} 14131da177e4SLinus Torvalds 141485afe608SMauro Carvalho Chehab 141585afe608SMauro Carvalho Chehabsub show_warnings($$) { 141685afe608SMauro Carvalho Chehab my $functype = shift; 141785afe608SMauro Carvalho Chehab my $name = shift; 141885afe608SMauro Carvalho Chehab 1419eab795ddSMauro Carvalho Chehab return 0 if (defined($nosymbol_table{$name})); 1420eab795ddSMauro Carvalho Chehab 142185afe608SMauro Carvalho Chehab return 1 if ($output_selection == OUTPUT_ALL); 142285afe608SMauro Carvalho Chehab 142385afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_EXPORTED) { 142485afe608SMauro Carvalho Chehab if (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_INTERNAL) { 143185afe608SMauro Carvalho Chehab if (!($functype eq "function" && 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 if ($output_selection == OUTPUT_INCLUDE) { 143885afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 143985afe608SMauro Carvalho Chehab return 1; 144085afe608SMauro Carvalho Chehab } else { 144185afe608SMauro Carvalho Chehab return 0; 144285afe608SMauro Carvalho Chehab } 144385afe608SMauro Carvalho Chehab } 144485afe608SMauro Carvalho Chehab die("Please add the new output type at show_warnings()"); 144585afe608SMauro Carvalho Chehab} 144685afe608SMauro Carvalho Chehab 14471da177e4SLinus Torvaldssub dump_enum($$) { 14481da177e4SLinus Torvalds my $x = shift; 14491da177e4SLinus Torvalds my $file = shift; 1450d38c8cfbSMauro Carvalho Chehab my $members; 1451d38c8cfbSMauro Carvalho Chehab 14521da177e4SLinus Torvalds 1453aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 14544468e21eSConchúr Navid # strip #define macros inside enums 14554468e21eSConchúr Navid $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 1456b6d676dbSRandy Dunlap 1457d38c8cfbSMauro Carvalho Chehab if ($x =~ /typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;/) { 1458d38c8cfbSMauro Carvalho Chehab $declaration_name = $2; 1459d38c8cfbSMauro Carvalho Chehab $members = $1; 1460d38c8cfbSMauro Carvalho Chehab } elsif ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) { 14611da177e4SLinus Torvalds $declaration_name = $1; 1462d38c8cfbSMauro Carvalho Chehab $members = $2; 1463d38c8cfbSMauro Carvalho Chehab } 1464d38c8cfbSMauro Carvalho Chehab 1465ae5b17e4SAndy Shevchenko if ($members) { 146652042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 14670b54c2e3SMauro Carvalho Chehab if ($identifier eq "") { 14680b54c2e3SMauro Carvalho Chehab print STDERR "${file}:$.: warning: wrong kernel-doc identifier on line:\n"; 14690b54c2e3SMauro Carvalho Chehab } else { 147052042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: expecting prototype for enum $identifier. Prototype was for enum $declaration_name instead\n"; 14710b54c2e3SMauro Carvalho Chehab } 147252042e2dSMauro Carvalho Chehab return; 147352042e2dSMauro Carvalho Chehab } 14740b54c2e3SMauro Carvalho Chehab $declaration_name = "(anonymous)" if ($declaration_name eq ""); 147552042e2dSMauro Carvalho Chehab 14765cb5c31cSJohannes Berg my %_members; 14775cb5c31cSJohannes Berg 1478463a0fdcSMarkus Heiser $members =~ s/\s+$//; 14791da177e4SLinus Torvalds 14801da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 14811da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 14821da177e4SLinus Torvalds push @parameterlist, $arg; 14831da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 14841da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 148585afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 14862defb272SMauro Carvalho Chehab print STDERR "${file}:$.: warning: Enum value '$arg' not described in enum '$declaration_name'\n"; 14872defb272SMauro Carvalho Chehab } 14881da177e4SLinus Torvalds } 14895cb5c31cSJohannes Berg $_members{$arg} = 1; 14905cb5c31cSJohannes Berg } 14911da177e4SLinus Torvalds 14925cb5c31cSJohannes Berg while (my ($k, $v) = each %parameterdescs) { 14935cb5c31cSJohannes Berg if (!exists($_members{$k})) { 149485afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 14952defb272SMauro Carvalho Chehab print STDERR "${file}:$.: warning: Excess enum value '$k' description in '$declaration_name'\n"; 14962defb272SMauro Carvalho Chehab } 14975cb5c31cSJohannes Berg } 14981da177e4SLinus Torvalds } 14991da177e4SLinus Torvalds 15001da177e4SLinus Torvalds output_declaration($declaration_name, 15011da177e4SLinus Torvalds 'enum', 15021da177e4SLinus Torvalds {'enum' => $declaration_name, 15031da177e4SLinus Torvalds 'module' => $modulename, 15041da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 15051da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 15061da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 15071da177e4SLinus Torvalds 'sections' => \%sections, 15081da177e4SLinus Torvalds 'purpose' => $declaration_purpose 15091da177e4SLinus Torvalds }); 1510d38c8cfbSMauro Carvalho Chehab } else { 1511d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 15121da177e4SLinus Torvalds ++$errors; 15131da177e4SLinus Torvalds } 15141da177e4SLinus Torvalds} 15151da177e4SLinus Torvalds 15167d2c6b1eSMauro Carvalho Chehabmy $typedef_type = qr { ((?:\s+[\w\*]+\b){1,8})\s* }x; 15177efc6c42SMauro Carvalho Chehabmy $typedef_ident = qr { \*?\s*(\w\S+)\s* }x; 15187efc6c42SMauro Carvalho Chehabmy $typedef_args = qr { \s*\((.*)\); }x; 15197efc6c42SMauro Carvalho Chehab 15207efc6c42SMauro Carvalho Chehabmy $typedef1 = qr { typedef$typedef_type\($typedef_ident\)$typedef_args }x; 15217efc6c42SMauro Carvalho Chehabmy $typedef2 = qr { typedef$typedef_type$typedef_ident$typedef_args }x; 15227efc6c42SMauro Carvalho Chehab 15231da177e4SLinus Torvaldssub dump_typedef($$) { 15241da177e4SLinus Torvalds my $x = shift; 15251da177e4SLinus Torvalds my $file = shift; 15261da177e4SLinus Torvalds 1527aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 152883766452SMauro Carvalho Chehab 15297efc6c42SMauro Carvalho Chehab # Parse function typedef prototypes 15307efc6c42SMauro Carvalho Chehab if ($x =~ $typedef1 || $x =~ $typedef2) { 153183766452SMauro Carvalho Chehab $return_type = $1; 153283766452SMauro Carvalho Chehab $declaration_name = $2; 153383766452SMauro Carvalho Chehab my $args = $3; 15346b80975cSMauro Carvalho Chehab $return_type =~ s/^\s+//; 153583766452SMauro Carvalho Chehab 153652042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 153752042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n"; 153852042e2dSMauro Carvalho Chehab return; 153952042e2dSMauro Carvalho Chehab } 154052042e2dSMauro Carvalho Chehab 1541151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 154283766452SMauro Carvalho Chehab 154383766452SMauro Carvalho Chehab output_declaration($declaration_name, 154483766452SMauro Carvalho Chehab 'function', 154583766452SMauro Carvalho Chehab {'function' => $declaration_name, 154682801d06SMauro Carvalho Chehab 'typedef' => 1, 154783766452SMauro Carvalho Chehab 'module' => $modulename, 154883766452SMauro Carvalho Chehab 'functiontype' => $return_type, 154983766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 155083766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 155183766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 155283766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 155383766452SMauro Carvalho Chehab 'sections' => \%sections, 155483766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 155583766452SMauro Carvalho Chehab }); 155683766452SMauro Carvalho Chehab return; 155783766452SMauro Carvalho Chehab } 155883766452SMauro Carvalho Chehab 15591da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 15601da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 15611da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 15621da177e4SLinus Torvalds } 15631da177e4SLinus Torvalds 15641da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 15651da177e4SLinus Torvalds $declaration_name = $1; 15661da177e4SLinus Torvalds 156752042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 156852042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n"; 156952042e2dSMauro Carvalho Chehab return; 157052042e2dSMauro Carvalho Chehab } 157152042e2dSMauro Carvalho Chehab 15721da177e4SLinus Torvalds output_declaration($declaration_name, 15731da177e4SLinus Torvalds 'typedef', 15741da177e4SLinus Torvalds {'typedef' => $declaration_name, 15751da177e4SLinus Torvalds 'module' => $modulename, 15761da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 15771da177e4SLinus Torvalds 'sections' => \%sections, 15781da177e4SLinus Torvalds 'purpose' => $declaration_purpose 15791da177e4SLinus Torvalds }); 15801da177e4SLinus Torvalds } 15811da177e4SLinus Torvalds else { 1582d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 15831da177e4SLinus Torvalds ++$errors; 15841da177e4SLinus Torvalds } 15851da177e4SLinus Torvalds} 15861da177e4SLinus Torvalds 1587a1d94aa5SRandy Dunlapsub save_struct_actual($) { 1588a1d94aa5SRandy Dunlap my $actual = shift; 1589a1d94aa5SRandy Dunlap 1590a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 1591a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 1592a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 1593a1d94aa5SRandy Dunlap} 1594a1d94aa5SRandy Dunlap 1595151c468bSMauro Carvalho Chehabsub create_parameterlist($$$$) { 15961da177e4SLinus Torvalds my $args = shift; 15971da177e4SLinus Torvalds my $splitter = shift; 15981da177e4SLinus Torvalds my $file = shift; 1599151c468bSMauro Carvalho Chehab my $declaration_name = shift; 16001da177e4SLinus Torvalds my $type; 16011da177e4SLinus Torvalds my $param; 16021da177e4SLinus Torvalds 1603a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 1604e86bdb24SAditya Srivastava my $arg_expr = qr{\([^\),]+}; 1605e86bdb24SAditya Srivastava while ($args =~ /$arg_expr,/) { 1606e86bdb24SAditya Srivastava $args =~ s/($arg_expr),/$1#/g; 16071da177e4SLinus Torvalds } 16081da177e4SLinus Torvalds 16091da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 16101da177e4SLinus Torvalds # strip comments 16111da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 16121da177e4SLinus Torvalds # strip leading/trailing spaces 16131da177e4SLinus Torvalds $arg =~ s/^\s*//; 16141da177e4SLinus Torvalds $arg =~ s/\s*$//; 16151da177e4SLinus Torvalds $arg =~ s/\s+/ /; 16161da177e4SLinus Torvalds 16171da177e4SLinus Torvalds if ($arg =~ /^#/) { 16181da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 16191da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 16201da177e4SLinus Torvalds # output_* subs. 1621ed8348e2SMauro Carvalho Chehab push_parameter($arg, "", "", $file); 162200d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 16231da177e4SLinus Torvalds # pointer-to-function 16241da177e4SLinus Torvalds $arg =~ tr/#/,/; 1625336ced2dSAditya Srivastava $arg =~ m/[^\(]+\(\*?\s*([\w\[\]\.]*)\s*\)/; 16261da177e4SLinus Torvalds $param = $1; 16271da177e4SLinus Torvalds $type = $arg; 162800d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1629a1d94aa5SRandy Dunlap save_struct_actual($param); 1630ed8348e2SMauro Carvalho Chehab push_parameter($param, $type, $arg, $file, $declaration_name); 1631aeec46b9SMartin Waitz } elsif ($arg) { 16321da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 16331da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 16341da177e4SLinus Torvalds 16351da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 16361da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 16371da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 16381da177e4SLinus Torvalds } 1639884f2810SBorislav Petkov 1640884f2810SBorislav Petkov my @first_arg; 1641884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1642884f2810SBorislav Petkov shift @args; 1643884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 1644884f2810SBorislav Petkov push(@first_arg, $2); 1645884f2810SBorislav Petkov } else { 1646884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 1647884f2810SBorislav Petkov } 1648884f2810SBorislav Petkov 16491da177e4SLinus Torvalds unshift(@args, pop @first_arg); 16501da177e4SLinus Torvalds $type = join " ", @first_arg; 16511da177e4SLinus Torvalds 16521da177e4SLinus Torvalds foreach $param (@args) { 16531da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 1654a1d94aa5SRandy Dunlap save_struct_actual($2); 1655ed8348e2SMauro Carvalho Chehab 1656ed8348e2SMauro Carvalho Chehab push_parameter($2, "$type $1", $arg, $file, $declaration_name); 16571da177e4SLinus Torvalds } 16581da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 16597b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 1660a1d94aa5SRandy Dunlap save_struct_actual($1); 1661ed8348e2SMauro Carvalho Chehab push_parameter($1, "$type:$2", $arg, $file, $declaration_name) 16621da177e4SLinus Torvalds } 16637b97887eSRandy Dunlap } 16641da177e4SLinus Torvalds else { 1665a1d94aa5SRandy Dunlap save_struct_actual($param); 1666ed8348e2SMauro Carvalho Chehab push_parameter($param, $type, $arg, $file, $declaration_name); 16671da177e4SLinus Torvalds } 16681da177e4SLinus Torvalds } 16691da177e4SLinus Torvalds } 16701da177e4SLinus Torvalds } 16711da177e4SLinus Torvalds} 16721da177e4SLinus Torvalds 1673ed8348e2SMauro Carvalho Chehabsub push_parameter($$$$$) { 16741da177e4SLinus Torvalds my $param = shift; 16751da177e4SLinus Torvalds my $type = shift; 1676ed8348e2SMauro Carvalho Chehab my $org_arg = shift; 16771da177e4SLinus Torvalds my $file = shift; 1678151c468bSMauro Carvalho Chehab my $declaration_name = shift; 16791da177e4SLinus Torvalds 16805f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 16815f8c7c98SRandy Dunlap ($param eq "}")) { 16825f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 16835f8c7c98SRandy Dunlap } 16845f8c7c98SRandy Dunlap 16855f8c7c98SRandy Dunlap $anon_struct_union = 0; 1686f9b5c530SMauro Carvalho Chehab $param =~ s/[\[\)].*//; 16871da177e4SLinus Torvalds 1688a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 16891da177e4SLinus Torvalds { 1690c950a173SSilvio Fricke if (!$param =~ /\w\.\.\.$/) { 1691c950a173SSilvio Fricke # handles unnamed variable parameters 1692ef00028bSJonathan Corbet $param = "..."; 1693c950a173SSilvio Fricke } 169443756e34SJonathan Neuschäfer elsif ($param =~ /\w\.\.\.$/) { 169543756e34SJonathan Neuschäfer # for named variable parameters of the form `x...`, remove the dots 169643756e34SJonathan Neuschäfer $param =~ s/\.\.\.$//; 169743756e34SJonathan Neuschäfer } 1698ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1699a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 17001da177e4SLinus Torvalds } 1701ced69090SRandy Dunlap } 17021da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 17031da177e4SLinus Torvalds { 17041da177e4SLinus Torvalds $param="void"; 17051da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 17061da177e4SLinus Torvalds } 1707134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1708134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 1709134fe01bSRandy Dunlap { 1710134fe01bSRandy Dunlap $type = $param; 1711134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 1712134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 17135f8c7c98SRandy Dunlap $anon_struct_union = 1; 1714134fe01bSRandy Dunlap } 1715134fe01bSRandy Dunlap 1716a6d3fe77SMartin Waitz # warn if parameter has no description 1717134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 1718134fe01bSRandy Dunlap # but inline preprocessor statements); 1719151c468bSMauro Carvalho Chehab # Note: It will also ignore void params and unnamed structs/unions 1720f9b5c530SMauro Carvalho Chehab if (!defined $parameterdescs{$param} && $param !~ /^#/) { 1721f9b5c530SMauro Carvalho Chehab $parameterdescs{$param} = $undescribed; 17221da177e4SLinus Torvalds 1723be5cd20cSJonathan Corbet if (show_warnings($type, $declaration_name) && $param !~ /\./) { 1724151c468bSMauro Carvalho Chehab print STDERR 1725151c468bSMauro Carvalho Chehab "${file}:$.: warning: Function parameter or member '$param' not described in '$declaration_name'\n"; 17261da177e4SLinus Torvalds ++$warnings; 17271da177e4SLinus Torvalds } 17282defb272SMauro Carvalho Chehab } 17291da177e4SLinus Torvalds 173025985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 1731e34e7dbbSRandy Dunlap # on @parameterlist; 1732e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 1733e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 1734e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 1735e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 1736e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 1737e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 1738e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 17391da177e4SLinus Torvalds push @parameterlist, $param; 1740ed8348e2SMauro Carvalho Chehab $org_arg =~ s/\s\s+/ /g; 1741ed8348e2SMauro Carvalho Chehab $parametertypes{$param} = $org_arg; 17421da177e4SLinus Torvalds} 17431da177e4SLinus Torvalds 17441081de2dSMauro Carvalho Chehabsub check_sections($$$$$) { 17451081de2dSMauro Carvalho Chehab my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_; 1746a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 1747a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 1748a1d94aa5SRandy Dunlap my $err; 1749a1d94aa5SRandy Dunlap my ($px, $sx); 1750a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 1751a1d94aa5SRandy Dunlap 1752a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 1753a1d94aa5SRandy Dunlap $err = 1; 1754a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 1755a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 1756a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 1757e86bdb24SAditya Srivastava $prm_clean =~ s/$attribute//i; 1758e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 1759e34e7dbbSRandy Dunlap # however, the original param string may contain 1760e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 1761e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 1762e34e7dbbSRandy Dunlap # parameter list is split at spaces; 1763e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 1764e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 1765e34e7dbbSRandy Dunlap 1766a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 1767a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 1768a1d94aa5SRandy Dunlap $err = 0; 1769a1d94aa5SRandy Dunlap last; 1770a1d94aa5SRandy Dunlap } 1771a1d94aa5SRandy Dunlap } 1772a1d94aa5SRandy Dunlap if ($err) { 1773a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 1774d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 1775a1d94aa5SRandy Dunlap "Excess function parameter " . 1776a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 1777a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 1778a1d94aa5SRandy Dunlap ++$warnings; 1779a1d94aa5SRandy Dunlap } 1780a1d94aa5SRandy Dunlap } 1781a1d94aa5SRandy Dunlap } 1782a1d94aa5SRandy Dunlap} 1783a1d94aa5SRandy Dunlap 17841da177e4SLinus Torvalds## 17854092bac7SYacine Belkadi# Checks the section describing the return value of a function. 17864092bac7SYacine Belkadisub check_return_section { 17874092bac7SYacine Belkadi my $file = shift; 17884092bac7SYacine Belkadi my $declaration_name = shift; 17894092bac7SYacine Belkadi my $return_type = shift; 17904092bac7SYacine Belkadi 17914092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 17924092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 17934092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 17944092bac7SYacine Belkadi return; 17954092bac7SYacine Belkadi } 17964092bac7SYacine Belkadi 17974092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 17984092bac7SYacine Belkadi $sections{$section_return} eq "") { 1799d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 18004092bac7SYacine Belkadi "No description found for return value of " . 18014092bac7SYacine Belkadi "'$declaration_name'\n"; 18024092bac7SYacine Belkadi ++$warnings; 18034092bac7SYacine Belkadi } 18044092bac7SYacine Belkadi} 18054092bac7SYacine Belkadi 18064092bac7SYacine Belkadi## 18071da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 18081da177e4SLinus Torvalds# processed and spits out all the details stored in the global 18091da177e4SLinus Torvalds# arrays/hashes. 18101da177e4SLinus Torvaldssub dump_function($$) { 18111da177e4SLinus Torvalds my $prototype = shift; 18121da177e4SLinus Torvalds my $file = shift; 1813cbb4d3e6SHoria Geanta my $noret = 0; 18141da177e4SLinus Torvalds 18155ef09c96SMauro Carvalho Chehab print_lineno($new_start_line); 18165eb6b4b3SMauro Carvalho Chehab 18171da177e4SLinus Torvalds $prototype =~ s/^static +//; 18181da177e4SLinus Torvalds $prototype =~ s/^extern +//; 18194dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 18201da177e4SLinus Torvalds $prototype =~ s/^inline +//; 18211da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 182232e79401SRandy Dunlap $prototype =~ s/^__inline +//; 182332e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 182432e79401SRandy Dunlap $prototype =~ s/^noinline +//; 182574fc5c65SRandy Dunlap $prototype =~ s/__init +//; 182620072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 182780342d48SMatthew Wilcox $prototype =~ s/__deprecated +//; 1828084aa001SAditya Srivastava $prototype =~ s/__flatten +//; 1829270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 183070c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 18310df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 18320891f959SMatthew Wilcox $prototype =~ s/__sched +//; 183395e760cbSRandy Dunlap $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//; 1834a40a8a11SKees Cook $prototype =~ s/__alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +//; 1835cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 1836084aa001SAditya Srivastava $prototype =~ s/__attribute_const__ +//; 1837b1aaa546SPaolo Bonzini $prototype =~ s/__attribute__\s*\(\( 1838b1aaa546SPaolo Bonzini (?: 1839b1aaa546SPaolo Bonzini [\w\s]++ # attribute name 1840b1aaa546SPaolo Bonzini (?:\([^)]*+\))? # attribute arguments 1841b1aaa546SPaolo Bonzini \s*+,? # optional comma at the end 1842b1aaa546SPaolo Bonzini )+ 1843b1aaa546SPaolo Bonzini \)\)\s+//x; 18441da177e4SLinus Torvalds 18451da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 18461da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 18471da177e4SLinus Torvalds # 2. Function name 18481da177e4SLinus Torvalds # 3. Function parameters. 18491da177e4SLinus Torvalds # 18501da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 18511da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 18521da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 18531da177e4SLinus Torvalds # so on. 18541da177e4SLinus Torvalds # 18551da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 18561da177e4SLinus Torvalds # the following functions' documentation still comes out right: 18571da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 18581da177e4SLinus Torvalds # - atomic_set (macro) 18599598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 1860e86bdb24SAditya Srivastava my $name = qr{[a-zA-Z0-9_~:]+}; 1861e86bdb24SAditya Srivastava my $prototype_end1 = qr{[^\(]*}; 1862e86bdb24SAditya Srivastava my $prototype_end2 = qr{[^\{]*}; 1863e86bdb24SAditya Srivastava my $prototype_end = qr{\(($prototype_end1|$prototype_end2)\)}; 1864e86bdb24SAditya Srivastava my $type1 = qr{[\w\s]+}; 1865e86bdb24SAditya Srivastava my $type2 = qr{$type1\*+}; 18661da177e4SLinus Torvalds 1867e86bdb24SAditya Srivastava if ($define && $prototype =~ m/^()($name)\s+/) { 1868cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 1869cbb4d3e6SHoria Geanta # list. 1870cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 1871cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 1872cbb4d3e6SHoria Geanta $return_type = $1; 1873cbb4d3e6SHoria Geanta $declaration_name = $2; 1874cbb4d3e6SHoria Geanta $noret = 1; 1875e86bdb24SAditya Srivastava } elsif ($prototype =~ m/^()($name)\s*$prototype_end/ || 1876e86bdb24SAditya Srivastava $prototype =~ m/^($type1)\s+($name)\s*$prototype_end/ || 1877e86bdb24SAditya Srivastava $prototype =~ m/^($type2+)\s*($name)\s*$prototype_end/) { 18781da177e4SLinus Torvalds $return_type = $1; 18791da177e4SLinus Torvalds $declaration_name = $2; 18801da177e4SLinus Torvalds my $args = $3; 18811da177e4SLinus Torvalds 1882151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 18831da177e4SLinus Torvalds } else { 1884d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 18851da177e4SLinus Torvalds return; 18861da177e4SLinus Torvalds } 18871da177e4SLinus Torvalds 188852042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 188952042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: expecting prototype for $identifier(). Prototype was for $declaration_name() instead\n"; 189052042e2dSMauro Carvalho Chehab return; 189152042e2dSMauro Carvalho Chehab } 189252042e2dSMauro Carvalho Chehab 1893a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 18941081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, "function", $sectcheck, $prms); 1895a1d94aa5SRandy Dunlap 18964092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 18974092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 18984092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 18994092bac7SYacine Belkadi # verbose mode. 19004092bac7SYacine Belkadi # TODO: always perform the check. 1901cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 19024092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 19034092bac7SYacine Belkadi } 19044092bac7SYacine Belkadi 190547bcacfdSMauro Carvalho Chehab # The function parser can be called with a typedef parameter. 190647bcacfdSMauro Carvalho Chehab # Handle it. 190747bcacfdSMauro Carvalho Chehab if ($return_type =~ /typedef/) { 190847bcacfdSMauro Carvalho Chehab output_declaration($declaration_name, 190947bcacfdSMauro Carvalho Chehab 'function', 191047bcacfdSMauro Carvalho Chehab {'function' => $declaration_name, 191147bcacfdSMauro Carvalho Chehab 'typedef' => 1, 191247bcacfdSMauro Carvalho Chehab 'module' => $modulename, 191347bcacfdSMauro Carvalho Chehab 'functiontype' => $return_type, 191447bcacfdSMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 191547bcacfdSMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 191647bcacfdSMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 191747bcacfdSMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 191847bcacfdSMauro Carvalho Chehab 'sections' => \%sections, 191947bcacfdSMauro Carvalho Chehab 'purpose' => $declaration_purpose 192047bcacfdSMauro Carvalho Chehab }); 192147bcacfdSMauro Carvalho Chehab } else { 19221da177e4SLinus Torvalds output_declaration($declaration_name, 19231da177e4SLinus Torvalds 'function', 19241da177e4SLinus Torvalds {'function' => $declaration_name, 19251da177e4SLinus Torvalds 'module' => $modulename, 19261da177e4SLinus Torvalds 'functiontype' => $return_type, 19271da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 19281da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 19291da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 19301da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 19311da177e4SLinus Torvalds 'sections' => \%sections, 19321da177e4SLinus Torvalds 'purpose' => $declaration_purpose 19331da177e4SLinus Torvalds }); 19341da177e4SLinus Torvalds } 193547bcacfdSMauro Carvalho Chehab} 19361da177e4SLinus Torvalds 19371da177e4SLinus Torvaldssub reset_state { 19381da177e4SLinus Torvalds $function = ""; 19391da177e4SLinus Torvalds %parameterdescs = (); 19401da177e4SLinus Torvalds %parametertypes = (); 19411da177e4SLinus Torvalds @parameterlist = (); 19421da177e4SLinus Torvalds %sections = (); 19431da177e4SLinus Torvalds @sectionlist = (); 1944a1d94aa5SRandy Dunlap $sectcheck = ""; 1945a1d94aa5SRandy Dunlap $struct_actual = ""; 19461da177e4SLinus Torvalds $prototype = ""; 19471da177e4SLinus Torvalds 194848af606aSJani Nikula $state = STATE_NORMAL; 194948af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 19501da177e4SLinus Torvalds} 19511da177e4SLinus Torvalds 195256afb0f8SJason Baronsub tracepoint_munge($) { 195356afb0f8SJason Baron my $file = shift; 195456afb0f8SJason Baron my $tracepointname = 0; 195556afb0f8SJason Baron my $tracepointargs = 0; 195656afb0f8SJason Baron 195756afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 195856afb0f8SJason Baron $tracepointname = $1; 195956afb0f8SJason Baron } 19603a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 19613a9089fdSJason Baron $tracepointname = $1; 19623a9089fdSJason Baron } 19633a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 19643a9089fdSJason Baron $tracepointname = $2; 19653a9089fdSJason Baron } 19663a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 196756afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 196856afb0f8SJason Baron $tracepointargs = $1; 196956afb0f8SJason Baron } 197056afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 1971d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 197256afb0f8SJason Baron "$prototype\n"; 197356afb0f8SJason Baron } else { 197456afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 197552042e2dSMauro Carvalho Chehab $identifier = "trace_$identifier"; 197656afb0f8SJason Baron } 197756afb0f8SJason Baron} 197856afb0f8SJason Baron 1979b4870bc5SRandy Dunlapsub syscall_munge() { 1980b4870bc5SRandy Dunlap my $void = 0; 1981b4870bc5SRandy Dunlap 19827c9aa015SMauro Carvalho Chehab $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's 1983b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 1984b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 1985b4870bc5SRandy Dunlap $void = 1; 1986b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 1987b4870bc5SRandy Dunlap } 1988b4870bc5SRandy Dunlap 1989b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 1990b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 1991b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 1992b4870bc5SRandy Dunlap } elsif ($void) { 1993b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 1994b4870bc5SRandy Dunlap } 1995b4870bc5SRandy Dunlap 1996b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 1997b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 1998b4870bc5SRandy Dunlap my $count = 0; 1999b4870bc5SRandy Dunlap my $len = length($prototype); 2000b4870bc5SRandy Dunlap if ($void) { 2001b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 2002b4870bc5SRandy Dunlap } 2003b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 2004b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 2005b4870bc5SRandy Dunlap $count++; 2006b4870bc5SRandy Dunlap if ($count % 2 == 1) { 2007b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 2008b4870bc5SRandy Dunlap } 2009b4870bc5SRandy Dunlap } 2010b4870bc5SRandy Dunlap } 2011b4870bc5SRandy Dunlap} 2012b4870bc5SRandy Dunlap 2013b7afa92bSDaniel Vettersub process_proto_function($$) { 20141da177e4SLinus Torvalds my $x = shift; 20151da177e4SLinus Torvalds my $file = shift; 20161da177e4SLinus Torvalds 201751f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 201851f5a0c8SRandy Dunlap 2019890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 20201da177e4SLinus Torvalds # do nothing 20211da177e4SLinus Torvalds } 20221da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 20231da177e4SLinus Torvalds $prototype .= $1; 20241da177e4SLinus Torvalds } 2025b4870bc5SRandy Dunlap 2026890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 20271da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 20281da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 20291da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 20307ae281b0SMauro Carvalho Chehab 20317ae281b0SMauro Carvalho Chehab # Handle prototypes for function pointers like: 20327ae281b0SMauro Carvalho Chehab # int (*pcs_config)(struct foo) 20337ae281b0SMauro Carvalho Chehab $prototype =~ s@^(\S+\s+)\(\s*\*(\S+)\)@$1$2@gos; 20347ae281b0SMauro Carvalho Chehab 2035b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 2036b4870bc5SRandy Dunlap syscall_munge(); 2037b4870bc5SRandy Dunlap } 20383a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 20393a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 20403a9089fdSJason Baron { 204156afb0f8SJason Baron tracepoint_munge($file); 204256afb0f8SJason Baron } 20431da177e4SLinus Torvalds dump_function($prototype, $file); 20441da177e4SLinus Torvalds reset_state(); 20451da177e4SLinus Torvalds } 20461da177e4SLinus Torvalds} 20471da177e4SLinus Torvalds 2048b7afa92bSDaniel Vettersub process_proto_type($$) { 20491da177e4SLinus Torvalds my $x = shift; 20501da177e4SLinus Torvalds my $file = shift; 20511da177e4SLinus Torvalds 20521da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 20531da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 20541da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 205551f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 205651f5a0c8SRandy Dunlap 20571da177e4SLinus Torvalds if ($x =~ /^#/) { 20581da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 20591da177e4SLinus Torvalds $x .= ";"; 20601da177e4SLinus Torvalds } 20611da177e4SLinus Torvalds 20621da177e4SLinus Torvalds while (1) { 2063673bb2dfSBen Hutchings if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) { 2064463a0fdcSMarkus Heiser if( length $prototype ) { 2065463a0fdcSMarkus Heiser $prototype .= " " 2066463a0fdcSMarkus Heiser } 20671da177e4SLinus Torvalds $prototype .= $1 . $2; 20681da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 20691da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 20701da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 20711da177e4SLinus Torvalds dump_declaration($prototype, $file); 20721da177e4SLinus Torvalds reset_state(); 20731da177e4SLinus Torvalds last; 20741da177e4SLinus Torvalds } 20751da177e4SLinus Torvalds $x = $3; 20761da177e4SLinus Torvalds } else { 20771da177e4SLinus Torvalds $prototype .= $x; 20781da177e4SLinus Torvalds last; 20791da177e4SLinus Torvalds } 20801da177e4SLinus Torvalds } 20811da177e4SLinus Torvalds} 20821da177e4SLinus Torvalds 20836b5b55f6SRandy Dunlap 20841ad560e4SJani Nikulasub map_filename($) { 20851ad560e4SJani Nikula my $file; 20861ad560e4SJani Nikula my ($orig_file) = @_; 20871ad560e4SJani Nikula 20881ad560e4SJani Nikula if (defined($ENV{'SRCTREE'})) { 20891ad560e4SJani Nikula $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 20901ad560e4SJani Nikula } else { 20911ad560e4SJani Nikula $file = $orig_file; 20921ad560e4SJani Nikula } 20931ad560e4SJani Nikula 20941ad560e4SJani Nikula if (defined($source_map{$file})) { 20951ad560e4SJani Nikula $file = $source_map{$file}; 20961ad560e4SJani Nikula } 20971ad560e4SJani Nikula 20981ad560e4SJani Nikula return $file; 20991ad560e4SJani Nikula} 21001ad560e4SJani Nikula 210188c2b57dSJani Nikulasub process_export_file($) { 210288c2b57dSJani Nikula my ($orig_file) = @_; 210388c2b57dSJani Nikula my $file = map_filename($orig_file); 210488c2b57dSJani Nikula 210588c2b57dSJani Nikula if (!open(IN,"<$file")) { 210688c2b57dSJani Nikula print STDERR "Error: Cannot open file $file\n"; 210788c2b57dSJani Nikula ++$errors; 210888c2b57dSJani Nikula return; 210988c2b57dSJani Nikula } 211088c2b57dSJani Nikula 211188c2b57dSJani Nikula while (<IN>) { 211288c2b57dSJani Nikula if (/$export_symbol/) { 2113eab795ddSMauro Carvalho Chehab next if (defined($nosymbol_table{$2})); 211488c2b57dSJani Nikula $function_table{$2} = 1; 211588c2b57dSJani Nikula } 211688c2b57dSJani Nikula } 211788c2b57dSJani Nikula 211888c2b57dSJani Nikula close(IN); 211988c2b57dSJani Nikula} 212088c2b57dSJani Nikula 212107048d13SJonathan Corbet# 212207048d13SJonathan Corbet# Parsers for the various processing states. 212307048d13SJonathan Corbet# 212407048d13SJonathan Corbet# STATE_NORMAL: looking for the /** to begin everything. 212507048d13SJonathan Corbet# 212607048d13SJonathan Corbetsub process_normal() { 21271da177e4SLinus Torvalds if (/$doc_start/o) { 212848af606aSJani Nikula $state = STATE_NAME; # next line is always the function name 2129850622dfSRandy Dunlap $in_doc_sect = 0; 21300b0f5f29SDaniel Vetter $declaration_start_line = $. + 1; 21311da177e4SLinus Torvalds } 213207048d13SJonathan Corbet} 213307048d13SJonathan Corbet 21343cac2bc4SJonathan Corbet# 21353cac2bc4SJonathan Corbet# STATE_NAME: Looking for the "name - description" line 21363cac2bc4SJonathan Corbet# 21373cac2bc4SJonathan Corbetsub process_name($$) { 21383cac2bc4SJonathan Corbet my $file = shift; 21391da177e4SLinus Torvalds my $descr; 21401da177e4SLinus Torvalds 21411da177e4SLinus Torvalds if (/$doc_block/o) { 214248af606aSJani Nikula $state = STATE_DOCBLOCK; 21431da177e4SLinus Torvalds $contents = ""; 21445ef09c96SMauro Carvalho Chehab $new_start_line = $.; 21450b0f5f29SDaniel Vetter 21461da177e4SLinus Torvalds if ( $1 eq "" ) { 21471da177e4SLinus Torvalds $section = $section_intro; 21481da177e4SLinus Torvalds } else { 21491da177e4SLinus Torvalds $section = $1; 21501da177e4SLinus Torvalds } 215152042e2dSMauro Carvalho Chehab } elsif (/$doc_decl/o) { 21521da177e4SLinus Torvalds $identifier = $1; 21533e58e839SAditya Srivastava my $is_kernel_comment = 0; 2154e86bdb24SAditya Srivastava my $decl_start = qr{$doc_com}; 2155f9bbc12cSAditya Srivastava # test for pointer declaration type, foo * bar() - desc 2156f9bbc12cSAditya Srivastava my $fn_type = qr{\w+\s*\*\s*}; 2157f9bbc12cSAditya Srivastava my $parenthesis = qr{\(\w*\)}; 2158f9bbc12cSAditya Srivastava my $decl_end = qr{[-:].*}; 2159e86bdb24SAditya Srivastava if (/^$decl_start([\w\s]+?)$parenthesis?\s*$decl_end?$/) { 21601da177e4SLinus Torvalds $identifier = $1; 21611da177e4SLinus Torvalds } 216252042e2dSMauro Carvalho Chehab if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) { 216352042e2dSMauro Carvalho Chehab $decl_type = $1; 216452042e2dSMauro Carvalho Chehab $identifier = $2; 21653e58e839SAditya Srivastava $is_kernel_comment = 1; 216652042e2dSMauro Carvalho Chehab } 2167f9bbc12cSAditya Srivastava # Look for foo() or static void foo() - description; or misspelt 2168f9bbc12cSAditya Srivastava # identifier 2169e86bdb24SAditya Srivastava elsif (/^$decl_start$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ || 2170e86bdb24SAditya Srivastava /^$decl_start$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) { 2171f9bbc12cSAditya Srivastava $identifier = $1; 2172f9bbc12cSAditya Srivastava $decl_type = 'function'; 2173f9bbc12cSAditya Srivastava $identifier =~ s/^define\s+//; 2174f9bbc12cSAditya Srivastava $is_kernel_comment = 1; 2175f9bbc12cSAditya Srivastava } 217652042e2dSMauro Carvalho Chehab $identifier =~ s/\s+$//; 21771da177e4SLinus Torvalds 217817b78717SJonathan Corbet $state = STATE_BODY; 21790b0f5f29SDaniel Vetter # if there's no @param blocks need to set up default section 21800b0f5f29SDaniel Vetter # here 21812f4ad40aSJani Nikula $contents = ""; 21822f4ad40aSJani Nikula $section = $section_default; 21830b0f5f29SDaniel Vetter $new_start_line = $. + 1; 218452042e2dSMauro Carvalho Chehab if (/[-:](.*)/) { 218551f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2186a21217daSRandy Dunlap $descr= $1; 2187a21217daSRandy Dunlap $descr =~ s/^\s*//; 2188a21217daSRandy Dunlap $descr =~ s/\s*$//; 218912ae6779SDaniel Santos $descr =~ s/\s+/ /g; 21900bba924cSJonathan Corbet $declaration_purpose = $descr; 219117b78717SJonathan Corbet $state = STATE_BODY_MAYBE; 21921da177e4SLinus Torvalds } else { 21931da177e4SLinus Torvalds $declaration_purpose = ""; 21941da177e4SLinus Torvalds } 219577cc23b8SRandy Dunlap 21963e58e839SAditya Srivastava if (!$is_kernel_comment) { 21973e58e839SAditya Srivastava print STDERR "${file}:$.: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst\n"; 21983e58e839SAditya Srivastava print STDERR $_; 21993e58e839SAditya Srivastava ++$warnings; 22003e58e839SAditya Srivastava $state = STATE_NORMAL; 22013e58e839SAditya Srivastava } 22023e58e839SAditya Srivastava 220377cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 2204d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 220577cc23b8SRandy Dunlap print STDERR $_; 220677cc23b8SRandy Dunlap ++$warnings; 220777cc23b8SRandy Dunlap } 220877cc23b8SRandy Dunlap 22090b54c2e3SMauro Carvalho Chehab if ($identifier eq "" && $decl_type ne "enum") { 221052042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: wrong kernel-doc identifier on line:\n"; 221152042e2dSMauro Carvalho Chehab print STDERR $_; 221252042e2dSMauro Carvalho Chehab ++$warnings; 221352042e2dSMauro Carvalho Chehab $state = STATE_NORMAL; 22141da177e4SLinus Torvalds } 22151da177e4SLinus Torvalds 22161da177e4SLinus Torvalds if ($verbose) { 221752042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: info: Scanning doc for $decl_type $identifier\n"; 22181da177e4SLinus Torvalds } 22191da177e4SLinus Torvalds } else { 2220d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 22211da177e4SLinus Torvalds " - I thought it was a doc line\n"; 22221da177e4SLinus Torvalds ++$warnings; 222348af606aSJani Nikula $state = STATE_NORMAL; 22241da177e4SLinus Torvalds } 22253cac2bc4SJonathan Corbet} 22263cac2bc4SJonathan Corbet 22273cac2bc4SJonathan Corbet 2228d742f24dSJonathan Corbet# 2229d742f24dSJonathan Corbet# STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment. 2230d742f24dSJonathan Corbet# 2231d742f24dSJonathan Corbetsub process_body($$) { 2232d742f24dSJonathan Corbet my $file = shift; 22333cac2bc4SJonathan Corbet 223443756e34SJonathan Neuschäfer # Until all named variable macro parameters are 223543756e34SJonathan Neuschäfer # documented using the bare name (`x`) rather than with 223643756e34SJonathan Neuschäfer # dots (`x...`), strip the dots: 223743756e34SJonathan Neuschäfer if ($section =~ /\w\.\.\.$/) { 223843756e34SJonathan Neuschäfer $section =~ s/\.\.\.$//; 223943756e34SJonathan Neuschäfer 224043756e34SJonathan Neuschäfer if ($verbose) { 224143756e34SJonathan Neuschäfer print STDERR "${file}:$.: warning: Variable macro arguments should be documented without dots\n"; 224243756e34SJonathan Neuschäfer ++$warnings; 224343756e34SJonathan Neuschäfer } 224443756e34SJonathan Neuschäfer } 224543756e34SJonathan Neuschäfer 22460d55d48bSMauro Carvalho Chehab if ($state == STATE_BODY_WITH_BLANK_LINE && /^\s*\*\s?\S/) { 22470d55d48bSMauro Carvalho Chehab dump_section($file, $section, $contents); 22480d55d48bSMauro Carvalho Chehab $section = $section_default; 22495ef09c96SMauro Carvalho Chehab $new_start_line = $.; 22500d55d48bSMauro Carvalho Chehab $contents = ""; 22510d55d48bSMauro Carvalho Chehab } 22520d55d48bSMauro Carvalho Chehab 2253f624adefSJani Nikula if (/$doc_sect/i) { # case insensitive for supported section names 22541da177e4SLinus Torvalds $newsection = $1; 22551da177e4SLinus Torvalds $newcontents = $2; 22561da177e4SLinus Torvalds 2257f624adefSJani Nikula # map the supported section names to the canonical names 2258f624adefSJani Nikula if ($newsection =~ m/^description$/i) { 2259f624adefSJani Nikula $newsection = $section_default; 2260f624adefSJani Nikula } elsif ($newsection =~ m/^context$/i) { 2261f624adefSJani Nikula $newsection = $section_context; 2262f624adefSJani Nikula } elsif ($newsection =~ m/^returns?$/i) { 2263f624adefSJani Nikula $newsection = $section_return; 2264f624adefSJani Nikula } elsif ($newsection =~ m/^\@return$/) { 2265f624adefSJani Nikula # special: @return is a section, not a param description 2266f624adefSJani Nikula $newsection = $section_return; 2267f624adefSJani Nikula } 2268f624adefSJani Nikula 2269792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 2270850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 2271d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: contents before sections\n"; 2272850622dfSRandy Dunlap ++$warnings; 2273850622dfSRandy Dunlap } 22740bba924cSJonathan Corbet dump_section($file, $section, $contents); 22751da177e4SLinus Torvalds $section = $section_default; 22761da177e4SLinus Torvalds } 22771da177e4SLinus Torvalds 2278850622dfSRandy Dunlap $in_doc_sect = 1; 227917b78717SJonathan Corbet $state = STATE_BODY; 22801da177e4SLinus Torvalds $contents = $newcontents; 22810b0f5f29SDaniel Vetter $new_start_line = $.; 22827c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 228305189497SRandy Dunlap $contents = substr($contents, 1); 228405189497SRandy Dunlap } 22850a726301SJani Nikula if ($contents ne "") { 22861da177e4SLinus Torvalds $contents .= "\n"; 22871da177e4SLinus Torvalds } 22881da177e4SLinus Torvalds $section = $newsection; 2289b7886de4SJani Nikula $leading_space = undef; 22901da177e4SLinus Torvalds } elsif (/$doc_end/) { 22914c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 22920bba924cSJonathan Corbet dump_section($file, $section, $contents); 22931da177e4SLinus Torvalds $section = $section_default; 22941da177e4SLinus Torvalds $contents = ""; 22951da177e4SLinus Torvalds } 229646b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 229746b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2298d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: suspicious ending line: $_"; 229946b958ebSRandy Dunlap ++$warnings; 230046b958ebSRandy Dunlap } 23011da177e4SLinus Torvalds 23021da177e4SLinus Torvalds $prototype = ""; 230348af606aSJani Nikula $state = STATE_PROTO; 23041da177e4SLinus Torvalds $brcount = 0; 23055ef09c96SMauro Carvalho Chehab $new_start_line = $. + 1; 23061da177e4SLinus Torvalds } elsif (/$doc_content/) { 23076423133bSJohannes Weiner if ($1 eq "") { 23080d55d48bSMauro Carvalho Chehab if ($section eq $section_context) { 23090bba924cSJonathan Corbet dump_section($file, $section, $contents); 23101da177e4SLinus Torvalds $section = $section_default; 23111da177e4SLinus Torvalds $contents = ""; 23120b0f5f29SDaniel Vetter $new_start_line = $.; 23130d55d48bSMauro Carvalho Chehab $state = STATE_BODY; 23141da177e4SLinus Torvalds } else { 23150d55d48bSMauro Carvalho Chehab if ($section ne $section_default) { 23160d55d48bSMauro Carvalho Chehab $state = STATE_BODY_WITH_BLANK_LINE; 23170d55d48bSMauro Carvalho Chehab } else { 23180d55d48bSMauro Carvalho Chehab $state = STATE_BODY; 23190d55d48bSMauro Carvalho Chehab } 23206423133bSJohannes Weiner $contents .= "\n"; 23216423133bSJohannes Weiner } 232217b78717SJonathan Corbet } elsif ($state == STATE_BODY_MAYBE) { 23236423133bSJohannes Weiner # Continued declaration purpose 23246423133bSJohannes Weiner chomp($declaration_purpose); 23250bba924cSJonathan Corbet $declaration_purpose .= " " . $1; 232612ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 23276423133bSJohannes Weiner } else { 2328b7886de4SJani Nikula my $cont = $1; 2329b7886de4SJani Nikula if ($section =~ m/^@/ || $section eq $section_context) { 2330b7886de4SJani Nikula if (!defined $leading_space) { 2331b7886de4SJani Nikula if ($cont =~ m/^(\s+)/) { 2332b7886de4SJani Nikula $leading_space = $1; 2333b7886de4SJani Nikula } else { 2334b7886de4SJani Nikula $leading_space = ""; 2335b7886de4SJani Nikula } 2336b7886de4SJani Nikula } 2337b7886de4SJani Nikula $cont =~ s/^$leading_space//; 2338b7886de4SJani Nikula } 2339b7886de4SJani Nikula $contents .= $cont . "\n"; 23401da177e4SLinus Torvalds } 23411da177e4SLinus Torvalds } else { 23421da177e4SLinus Torvalds # i dont know - bad line? ignore. 2343d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: bad line: $_"; 23441da177e4SLinus Torvalds ++$warnings; 23451da177e4SLinus Torvalds } 2346d742f24dSJonathan Corbet} 2347d742f24dSJonathan Corbet 2348d742f24dSJonathan Corbet 2349cc794812SJonathan Corbet# 2350cc794812SJonathan Corbet# STATE_PROTO: reading a function/whatever prototype. 2351cc794812SJonathan Corbet# 2352cc794812SJonathan Corbetsub process_proto($$) { 2353cc794812SJonathan Corbet my $file = shift; 2354cc794812SJonathan Corbet 2355cc794812SJonathan Corbet if (/$doc_inline_oneline/) { 2356cc794812SJonathan Corbet $section = $1; 2357cc794812SJonathan Corbet $contents = $2; 2358cc794812SJonathan Corbet if ($contents ne "") { 2359cc794812SJonathan Corbet $contents .= "\n"; 2360cc794812SJonathan Corbet dump_section($file, $section, $contents); 2361cc794812SJonathan Corbet $section = $section_default; 2362cc794812SJonathan Corbet $contents = ""; 2363cc794812SJonathan Corbet } 2364cc794812SJonathan Corbet } elsif (/$doc_inline_start/) { 2365cc794812SJonathan Corbet $state = STATE_INLINE; 2366cc794812SJonathan Corbet $inline_doc_state = STATE_INLINE_NAME; 2367cc794812SJonathan Corbet } elsif ($decl_type eq 'function') { 2368cc794812SJonathan Corbet process_proto_function($_, $file); 2369cc794812SJonathan Corbet } else { 2370cc794812SJonathan Corbet process_proto_type($_, $file); 2371cc794812SJonathan Corbet } 2372cc794812SJonathan Corbet} 2373cc794812SJonathan Corbet 2374c17add56SJonathan Corbet# 2375c17add56SJonathan Corbet# STATE_DOCBLOCK: within a DOC: block. 2376c17add56SJonathan Corbet# 2377c17add56SJonathan Corbetsub process_docblock($$) { 2378c17add56SJonathan Corbet my $file = shift; 2379cc794812SJonathan Corbet 2380c17add56SJonathan Corbet if (/$doc_end/) { 2381c17add56SJonathan Corbet dump_doc_section($file, $section, $contents); 2382c17add56SJonathan Corbet $section = $section_default; 2383c17add56SJonathan Corbet $contents = ""; 2384c17add56SJonathan Corbet $function = ""; 2385c17add56SJonathan Corbet %parameterdescs = (); 2386c17add56SJonathan Corbet %parametertypes = (); 2387c17add56SJonathan Corbet @parameterlist = (); 2388c17add56SJonathan Corbet %sections = (); 2389c17add56SJonathan Corbet @sectionlist = (); 2390c17add56SJonathan Corbet $prototype = ""; 2391c17add56SJonathan Corbet $state = STATE_NORMAL; 2392c17add56SJonathan Corbet } elsif (/$doc_content/) { 2393c17add56SJonathan Corbet if ( $1 eq "" ) { 2394c17add56SJonathan Corbet $contents .= $blankline; 2395c17add56SJonathan Corbet } else { 2396c17add56SJonathan Corbet $contents .= $1 . "\n"; 2397c17add56SJonathan Corbet } 2398c17add56SJonathan Corbet } 2399d742f24dSJonathan Corbet} 2400d742f24dSJonathan Corbet 2401c17add56SJonathan Corbet# 2402c17add56SJonathan Corbet# STATE_INLINE: docbook comments within a prototype. 2403c17add56SJonathan Corbet# 2404c17add56SJonathan Corbetsub process_inline($$) { 2405c17add56SJonathan Corbet my $file = shift; 2406d742f24dSJonathan Corbet 2407a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 240848af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 2409a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 2410a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 24110b0f5f29SDaniel Vetter $new_start_line = $.; 2412a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 24137c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 2414a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 2415a4c6ebedSDanilo Cesar Lemes de Paula } 2416a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 2417a4c6ebedSDanilo Cesar Lemes de Paula } 241848af606aSJani Nikula $inline_doc_state = STATE_INLINE_TEXT; 2419a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 242048af606aSJani Nikula } elsif (/$doc_inline_end/) { 2421a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 24220bba924cSJonathan Corbet dump_section($file, $section, $contents); 2423a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 2424a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 2425a4c6ebedSDanilo Cesar Lemes de Paula } 242648af606aSJani Nikula $state = STATE_PROTO; 242748af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 2428a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 2429a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 243048af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_TEXT) { 2431a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 24326450c895SJani Nikula # nuke leading blank lines 24336450c895SJani Nikula if ($contents =~ /^\s*$/) { 24346450c895SJani Nikula $contents = ""; 24356450c895SJani Nikula } 243648af606aSJani Nikula } elsif ($inline_doc_state == STATE_INLINE_NAME) { 243748af606aSJani Nikula $inline_doc_state = STATE_INLINE_ERROR; 2438e7ca311eSDaniel Vetter print STDERR "${file}:$.: warning: "; 2439a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Incorrect use of kernel-doc format: $_"; 2440a4c6ebedSDanilo Cesar Lemes de Paula ++$warnings; 2441a4c6ebedSDanilo Cesar Lemes de Paula } 2442a4c6ebedSDanilo Cesar Lemes de Paula } 24430c9aa209SJani Nikula} 2444c17add56SJonathan Corbet 2445c17add56SJonathan Corbet 2446c17add56SJonathan Corbetsub process_file($) { 2447c17add56SJonathan Corbet my $file; 2448c17add56SJonathan Corbet my $initial_section_counter = $section_counter; 2449c17add56SJonathan Corbet my ($orig_file) = @_; 2450c17add56SJonathan Corbet 2451c17add56SJonathan Corbet $file = map_filename($orig_file); 2452c17add56SJonathan Corbet 2453dbe8ba00SMauro Carvalho Chehab if (!open(IN_FILE,"<$file")) { 2454c17add56SJonathan Corbet print STDERR "Error: Cannot open file $file\n"; 2455c17add56SJonathan Corbet ++$errors; 2456c17add56SJonathan Corbet return; 24571da177e4SLinus Torvalds } 2458c17add56SJonathan Corbet 2459c17add56SJonathan Corbet $. = 1; 2460c17add56SJonathan Corbet 2461c17add56SJonathan Corbet $section_counter = 0; 2462dbe8ba00SMauro Carvalho Chehab while (<IN_FILE>) { 2463c17add56SJonathan Corbet while (s/\\\s*$//) { 2464dbe8ba00SMauro Carvalho Chehab $_ .= <IN_FILE>; 2465c17add56SJonathan Corbet } 2466c17add56SJonathan Corbet # Replace tabs by spaces 2467c17add56SJonathan Corbet while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; 2468c17add56SJonathan Corbet # Hand this line to the appropriate state handler 2469c17add56SJonathan Corbet if ($state == STATE_NORMAL) { 2470c17add56SJonathan Corbet process_normal(); 2471c17add56SJonathan Corbet } elsif ($state == STATE_NAME) { 2472c17add56SJonathan Corbet process_name($file, $_); 24730d55d48bSMauro Carvalho Chehab } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE || 24740d55d48bSMauro Carvalho Chehab $state == STATE_BODY_WITH_BLANK_LINE) { 2475c17add56SJonathan Corbet process_body($file, $_); 2476c17add56SJonathan Corbet } elsif ($state == STATE_INLINE) { # scanning for inline parameters 2477c17add56SJonathan Corbet process_inline($file, $_); 2478cc794812SJonathan Corbet } elsif ($state == STATE_PROTO) { 2479cc794812SJonathan Corbet process_proto($file, $_); 248048af606aSJani Nikula } elsif ($state == STATE_DOCBLOCK) { 2481c17add56SJonathan Corbet process_docblock($file, $_); 24821da177e4SLinus Torvalds } 24831da177e4SLinus Torvalds } 2484c17add56SJonathan Corbet 2485c17add56SJonathan Corbet # Make sure we got something interesting. 2486b0d60bfbSJonathan Corbet if ($initial_section_counter == $section_counter && $ 2487b0d60bfbSJonathan Corbet output_mode ne "none") { 2488b0d60bfbSJonathan Corbet if ($output_selection == OUTPUT_INCLUDE) { 2489b0d60bfbSJonathan Corbet print STDERR "${file}:1: warning: '$_' not found\n" 2490b0d60bfbSJonathan Corbet for keys %function_table; 24913a025e1dSMatthew Wilcox } 2492b0d60bfbSJonathan Corbet else { 2493b0d60bfbSJonathan Corbet print STDERR "${file}:1: warning: no structured comments found\n"; 2494e946c43aSJohannes Berg } 24951da177e4SLinus Torvalds } 2496dbe8ba00SMauro Carvalho Chehab close IN_FILE; 24971da177e4SLinus Torvalds} 24988484baaaSRandy Dunlap 24998484baaaSRandy Dunlap 250093351d41SMauro Carvalho Chehabif ($output_mode eq "rst") { 250193351d41SMauro Carvalho Chehab get_sphinx_version() if (!$sphinx_major); 250293351d41SMauro Carvalho Chehab} 250393351d41SMauro Carvalho Chehab 25048484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 25058484baaaSRandy Dunlap 25068484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 25078484baaaSRandy Dunlap# using the s// operator. 25081ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 25094d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 25104d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 25114d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 25124d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 25138484baaaSRandy Dunlap} 25148484baaaSRandy Dunlap 25158484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 25168484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 25178484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 25188484baaaSRandy Dunlap my ($relname, $absname); 25198484baaaSRandy Dunlap while(<SOURCE_MAP>) { 25208484baaaSRandy Dunlap chop(); 25218484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 25228484baaaSRandy Dunlap $relname =~ s:^/+::; 25238484baaaSRandy Dunlap $source_map{$relname} = $absname; 25248484baaaSRandy Dunlap } 25258484baaaSRandy Dunlap close(SOURCE_MAP); 25268484baaaSRandy Dunlap} 25278484baaaSRandy Dunlap 252888c2b57dSJani Nikulaif ($output_selection == OUTPUT_EXPORTED || 252988c2b57dSJani Nikula $output_selection == OUTPUT_INTERNAL) { 2530c9b2cfb3SJani Nikula 2531c9b2cfb3SJani Nikula push(@export_file_list, @ARGV); 2532c9b2cfb3SJani Nikula 253388c2b57dSJani Nikula foreach (@export_file_list) { 253488c2b57dSJani Nikula chomp; 253588c2b57dSJani Nikula process_export_file($_); 253688c2b57dSJani Nikula } 253788c2b57dSJani Nikula} 253888c2b57dSJani Nikula 25398484baaaSRandy Dunlapforeach (@ARGV) { 25408484baaaSRandy Dunlap chomp; 25418484baaaSRandy Dunlap process_file($_); 25428484baaaSRandy Dunlap} 25438484baaaSRandy Dunlapif ($verbose && $errors) { 25448484baaaSRandy Dunlap print STDERR "$errors errors\n"; 25458484baaaSRandy Dunlap} 25468484baaaSRandy Dunlapif ($verbose && $warnings) { 25478484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 25488484baaaSRandy Dunlap} 25498484baaaSRandy Dunlap 25502c12c810SPierre-Louis Bossartif ($Werror && $warnings) { 25512c12c810SPierre-Louis Bossart print STDERR "$warnings warnings as Errors\n"; 25522c12c810SPierre-Louis Bossart exit($warnings); 25532c12c810SPierre-Louis Bossart} else { 25542c12c810SPierre-Louis Bossart exit($output_mode eq "none" ? 0 : $errors) 25552c12c810SPierre-Louis Bossart} 25562875f787STomasz Warniełło 25572875f787STomasz Warniełło__END__ 25582875f787STomasz Warniełło 25592875f787STomasz Warniełło=head1 OPTIONS 25602875f787STomasz Warniełło 25612875f787STomasz Warniełło=head2 Output format selection (mutually exclusive): 25622875f787STomasz Warniełło 25632875f787STomasz Warniełło=over 8 25642875f787STomasz Warniełło 25652875f787STomasz Warniełło=item -man 25662875f787STomasz Warniełło 25672875f787STomasz WarniełłoOutput troff manual page format. 25682875f787STomasz Warniełło 25692875f787STomasz Warniełło=item -rst 25702875f787STomasz Warniełło 25712875f787STomasz WarniełłoOutput reStructuredText format. This is the default. 25722875f787STomasz Warniełło 25732875f787STomasz Warniełło=item -none 25742875f787STomasz Warniełło 25752875f787STomasz WarniełłoDo not output documentation, only warnings. 25762875f787STomasz Warniełło 25772875f787STomasz Warniełło=back 25782875f787STomasz Warniełło 2579*dd803b04STomasz Warniełło=head2 Output format modifiers 2580*dd803b04STomasz Warniełło 2581*dd803b04STomasz Warniełło=head3 reStructuredText only 2582*dd803b04STomasz Warniełło 2583*dd803b04STomasz Warniełło=over 8 2584*dd803b04STomasz Warniełło 2585*dd803b04STomasz Warniełło=item -sphinx-version VERSION 2586*dd803b04STomasz Warniełło 2587*dd803b04STomasz WarniełłoUse the ReST C domain dialect compatible with a specific Sphinx Version. 2588*dd803b04STomasz Warniełło 2589*dd803b04STomasz WarniełłoIf not specified, kernel-doc will auto-detect using the sphinx-build version 2590*dd803b04STomasz Warniełłofound on PATH. 2591*dd803b04STomasz Warniełło 2592*dd803b04STomasz Warniełło=back 2593*dd803b04STomasz Warniełło 25942875f787STomasz Warniełło=cut 2595