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 191da177e4SLinus Torvalds# 18/01/2001 - Cleanups 201da177e4SLinus Torvalds# Functions prototyped as foo(void) same as foo() 211da177e4SLinus Torvalds# Stop eval'ing where we don't need to. 221da177e4SLinus Torvalds# -- huggie@earth.li 231da177e4SLinus Torvalds 241da177e4SLinus Torvalds# 27/06/2001 - Allowed whitespace after initial "/**" and 251da177e4SLinus Torvalds# allowed comments before function declarations. 261da177e4SLinus Torvalds# -- Christian Kreibich <ck@whoop.org> 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds# Still to do: 291da177e4SLinus Torvalds# - add perldoc documentation 301da177e4SLinus Torvalds# - Look more closely at some of the scarier bits :) 311da177e4SLinus Torvalds 321da177e4SLinus Torvalds# 26/05/2001 - Support for separate source and object trees. 331da177e4SLinus Torvalds# Return error code. 341da177e4SLinus Torvalds# Keith Owens <kaos@ocs.com.au> 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds# 23/09/2001 - Added support for typedefs, structs, enums and unions 371da177e4SLinus Torvalds# Support for Context section; can be terminated using empty line 381da177e4SLinus Torvalds# Small fixes (like spaces vs. \s in regex) 391da177e4SLinus Torvalds# -- Tim Jansen <tim@tjansen.de> 401da177e4SLinus Torvalds 411b40c194SDan Luedtke# 25/07/2012 - Added support for HTML5 421b40c194SDan Luedtke# -- Dan Luedtke <mail@danrl.de> 431da177e4SLinus Torvalds 44fadc0b31SJani Nikulasub usage { 45fadc0b31SJani Nikula my $message = <<"EOF"; 46fadc0b31SJani NikulaUsage: $0 [OPTION ...] FILE ... 471da177e4SLinus Torvalds 48fadc0b31SJani NikulaRead C language source or header FILEs, extract embedded documentation comments, 49fadc0b31SJani Nikulaand print formatted documentation to standard output. 501da177e4SLinus Torvalds 51fadc0b31SJani NikulaThe documentation comments are identified by "/**" opening comment mark. See 52857af3b7SMauro Carvalho ChehabDocumentation/doc-guide/kernel-doc.rst for the documentation comment syntax. 53fadc0b31SJani Nikula 54fadc0b31SJani NikulaOutput format selection (mutually exclusive): 55fadc0b31SJani Nikula -man Output troff manual page format. This is the default. 56c0d1b6eeSJonathan Corbet -rst Output reStructuredText format. 573a025e1dSMatthew Wilcox -none Do not output documentation, only warnings. 58fadc0b31SJani Nikula 59fadc0b31SJani NikulaOutput selection (mutually exclusive): 6086ae2e38SJani Nikula -export Only output documentation for symbols that have been 6186ae2e38SJani Nikula exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 62c9b2cfb3SJani Nikula in any input FILE or -export-file FILE. 6386ae2e38SJani Nikula -internal Only output documentation for symbols that have NOT been 6486ae2e38SJani Nikula exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 65c9b2cfb3SJani Nikula in any input FILE or -export-file FILE. 66fadc0b31SJani Nikula -function NAME Only output documentation for the given function(s) 67fadc0b31SJani Nikula or DOC: section title(s). All other functions and DOC: 68fadc0b31SJani Nikula sections are ignored. May be specified multiple times. 69eab795ddSMauro Carvalho Chehab -nosymbol NAME Exclude the specified symbols from the output 70eab795ddSMauro Carvalho Chehab documentation. May be specified multiple times. 71fadc0b31SJani Nikula 72fadc0b31SJani NikulaOutput selection modifiers: 73fadc0b31SJani Nikula -no-doc-sections Do not output DOC: sections. 740b0f5f29SDaniel Vetter -enable-lineno Enable output of #define LINENO lines. Only works with 750b0f5f29SDaniel Vetter reStructuredText format. 7688c2b57dSJani Nikula -export-file FILE Specify an additional FILE in which to look for 7788c2b57dSJani Nikula EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with 7888c2b57dSJani Nikula -export or -internal. May be specified multiple times. 79fadc0b31SJani Nikula 80fadc0b31SJani NikulaOther parameters: 81fadc0b31SJani Nikula -v Verbose output, more warnings and other information. 82fadc0b31SJani Nikula -h Print this help. 832c12c810SPierre-Louis Bossart -Werror Treat warnings as errors. 84fadc0b31SJani Nikula 85fadc0b31SJani NikulaEOF 86fadc0b31SJani Nikula print $message; 87fadc0b31SJani Nikula exit 1; 88fadc0b31SJani Nikula} 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds# 911da177e4SLinus Torvalds# format of comments. 921da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure. 931da177e4SLinus Torvalds# (...)* signifies 0 or more structure elements 941da177e4SLinus Torvalds# /** 951da177e4SLinus Torvalds# * function_name(:)? (- short description)? 961da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)* 971da177e4SLinus Torvalds# (* a blank line)? 981da177e4SLinus Torvalds# * (Description:)? (Description of function)? 991da177e4SLinus Torvalds# * (section header: (section description)? )* 1001da177e4SLinus Torvalds# (*)?*/ 1011da177e4SLinus Torvalds# 1021da177e4SLinus Torvalds# So .. the trivial example would be: 1031da177e4SLinus Torvalds# 1041da177e4SLinus Torvalds# /** 1051da177e4SLinus Torvalds# * my_function 106b9d97328SRandy Dunlap# */ 1071da177e4SLinus Torvalds# 108891dcd2fSRandy Dunlap# If the Description: header tag is omitted, then there must be a blank line 1091da177e4SLinus Torvalds# after the last parameter specification. 1101da177e4SLinus Torvalds# e.g. 1111da177e4SLinus Torvalds# /** 1121da177e4SLinus Torvalds# * my_function - does my stuff 1131da177e4SLinus Torvalds# * @my_arg: its mine damnit 1141da177e4SLinus Torvalds# * 1151da177e4SLinus Torvalds# * Does my stuff explained. 1161da177e4SLinus Torvalds# */ 1171da177e4SLinus Torvalds# 1181da177e4SLinus Torvalds# or, could also use: 1191da177e4SLinus Torvalds# /** 1201da177e4SLinus Torvalds# * my_function - does my stuff 1211da177e4SLinus Torvalds# * @my_arg: its mine damnit 1221da177e4SLinus Torvalds# * Description: Does my stuff explained. 1231da177e4SLinus Torvalds# */ 1241da177e4SLinus Torvalds# etc. 1251da177e4SLinus Torvalds# 126b9d97328SRandy Dunlap# Besides functions you can also write documentation for structs, unions, 1271da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name 1281da177e4SLinus Torvalds# of the declaration; the struct/union/enum/typedef must always precede 1291da177e4SLinus Torvalds# the name. Nesting of declarations is not supported. 1301da177e4SLinus Torvalds# Use the argument mechanism to document members or constants. 1311da177e4SLinus Torvalds# e.g. 1321da177e4SLinus Torvalds# /** 1331da177e4SLinus Torvalds# * struct my_struct - short description 1341da177e4SLinus Torvalds# * @a: first member 1351da177e4SLinus Torvalds# * @b: second member 1361da177e4SLinus Torvalds# * 1371da177e4SLinus Torvalds# * Longer description 1381da177e4SLinus Torvalds# */ 1391da177e4SLinus Torvalds# struct my_struct { 1401da177e4SLinus Torvalds# int a; 1411da177e4SLinus Torvalds# int b; 142aeec46b9SMartin Waitz# /* private: */ 143aeec46b9SMartin Waitz# int c; 1441da177e4SLinus Torvalds# }; 1451da177e4SLinus Torvalds# 1461da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description. 1471da177e4SLinus Torvalds# 148a4c6ebedSDanilo Cesar Lemes de Paula# For really longs structs, you can also describe arguments inside the 149a4c6ebedSDanilo Cesar Lemes de Paula# body of the struct. 150a4c6ebedSDanilo Cesar Lemes de Paula# eg. 151a4c6ebedSDanilo Cesar Lemes de Paula# /** 152a4c6ebedSDanilo Cesar Lemes de Paula# * struct my_struct - short description 153a4c6ebedSDanilo Cesar Lemes de Paula# * @a: first member 154a4c6ebedSDanilo Cesar Lemes de Paula# * @b: second member 155a4c6ebedSDanilo Cesar Lemes de Paula# * 156a4c6ebedSDanilo Cesar Lemes de Paula# * Longer description 157a4c6ebedSDanilo Cesar Lemes de Paula# */ 158a4c6ebedSDanilo Cesar Lemes de Paula# struct my_struct { 159a4c6ebedSDanilo Cesar Lemes de Paula# int a; 160a4c6ebedSDanilo Cesar Lemes de Paula# int b; 161a4c6ebedSDanilo Cesar Lemes de Paula# /** 162a4c6ebedSDanilo Cesar Lemes de Paula# * @c: This is longer description of C 163a4c6ebedSDanilo Cesar Lemes de Paula# * 164a4c6ebedSDanilo Cesar Lemes de Paula# * You can use paragraphs to describe arguments 165a4c6ebedSDanilo Cesar Lemes de Paula# * using this method. 166a4c6ebedSDanilo Cesar Lemes de Paula# */ 167a4c6ebedSDanilo Cesar Lemes de Paula# int c; 168a4c6ebedSDanilo Cesar Lemes de Paula# }; 169a4c6ebedSDanilo Cesar Lemes de Paula# 170a4c6ebedSDanilo Cesar Lemes de Paula# This should be use only for struct/enum members. 171a4c6ebedSDanilo Cesar Lemes de Paula# 1721da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you 1731da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions 1741da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an 1751da177e4SLinus Torvalds# empty line. 1764092bac7SYacine Belkadi# A non-void function should have a "Return:" section describing the return 1774092bac7SYacine Belkadi# value(s). 1781da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked 1791da177e4SLinus Torvalds# appropriately in DocBook. 1801da177e4SLinus Torvalds# 1811da177e4SLinus Torvalds# Example: 1821da177e4SLinus Torvalds# /** 1831da177e4SLinus Torvalds# * user_function - function that can only be called in user context 1841da177e4SLinus Torvalds# * @a: some argument 1851da177e4SLinus Torvalds# * Context: !in_interrupt() 1861da177e4SLinus Torvalds# * 1871da177e4SLinus Torvalds# * Some description 1881da177e4SLinus Torvalds# * Example: 1891da177e4SLinus Torvalds# * user_function(22); 1901da177e4SLinus Torvalds# */ 1911da177e4SLinus Torvalds# ... 1921da177e4SLinus Torvalds# 1931da177e4SLinus Torvalds# 1941da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special 1951da177e4SLinus Torvalds# patterns, which are highlighted appropriately. 1961da177e4SLinus Torvalds# 1971da177e4SLinus Torvalds# 'funcname()' - function 1981da177e4SLinus Torvalds# '$ENVVAR' - environmental variable 1991da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct') 2005267dd35SPaolo Bonzini# '&struct_name.member' - name of a structure member 2011da177e4SLinus Torvalds# '@parameter' - name of a parameter 2021da177e4SLinus Torvalds# '%CONST' - name of a constant. 203b97f193aSMauro Carvalho Chehab# '``LITERAL``' - literal string without any spaces on it. 2041da177e4SLinus Torvalds 2058484baaaSRandy Dunlap## init lots of data 2068484baaaSRandy Dunlap 2071da177e4SLinus Torvaldsmy $errors = 0; 2081da177e4SLinus Torvaldsmy $warnings = 0; 2095f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds# match expressions used to find embedded type information 212b97f193aSMauro Carvalho Chehabmy $type_constant = '\b``([^\`]+)``\b'; 213b97f193aSMauro Carvalho Chehabmy $type_constant2 = '\%([-_\w]+)'; 2141da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 215bfd228c7SMike Rapoportmy $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; 216ee2aa759SMauro Carvalho Chehabmy $type_param_ref = '([\!]?)\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; 2175219f18aSJonathan Corbetmy $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params 218346282dbSMauro Carvalho Chehabmy $type_fp_param2 = '\@(\w+->\S+)\(\)'; # Special RST handling for structs with func ptr params 2191da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 220df31175bSPaolo Bonzinimy $type_enum = '\&(enum\s*([_\w]+))'; 221df31175bSPaolo Bonzinimy $type_struct = '\&(struct\s*([_\w]+))'; 222df31175bSPaolo Bonzinimy $type_typedef = '\&(typedef\s*([_\w]+))'; 223df31175bSPaolo Bonzinimy $type_union = '\&(union\s*([_\w]+))'; 2245267dd35SPaolo Bonzinimy $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; 225df31175bSPaolo Bonzinimy $type_fallback = '\&([_\w]+)'; 226f3341dcfSJani Nikulamy $type_member_func = $type_member . '\(\)'; 2271da177e4SLinus Torvalds 2281da177e4SLinus Torvalds# Output conversion substitutions. 2291da177e4SLinus Torvalds# One for each output format 2301da177e4SLinus Torvalds 2311da177e4SLinus Torvalds# these are pretty rough 2324d732701SDanilo Cesar Lemes de Paulamy @highlights_man = ( 2334d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 234b97f193aSMauro Carvalho Chehab [$type_constant2, "\$1"], 2354d732701SDanilo Cesar Lemes de Paula [$type_func, "\\\\fB\$1\\\\fP"], 236df31175bSPaolo Bonzini [$type_enum, "\\\\fI\$1\\\\fP"], 2374d732701SDanilo Cesar Lemes de Paula [$type_struct, "\\\\fI\$1\\\\fP"], 238df31175bSPaolo Bonzini [$type_typedef, "\\\\fI\$1\\\\fP"], 239df31175bSPaolo Bonzini [$type_union, "\\\\fI\$1\\\\fP"], 2405267dd35SPaolo Bonzini [$type_param, "\\\\fI\$1\\\\fP"], 241ee2aa759SMauro Carvalho Chehab [$type_param_ref, "\\\\fI\$1\$2\\\\fP"], 242df31175bSPaolo Bonzini [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], 243df31175bSPaolo Bonzini [$type_fallback, "\\\\fI\$1\\\\fP"] 2444d732701SDanilo Cesar Lemes de Paula ); 2451da177e4SLinus Torvaldsmy $blankline_man = ""; 2461da177e4SLinus Torvalds 247c0d1b6eeSJonathan Corbet# rst-mode 248c0d1b6eeSJonathan Corbetmy @highlights_rst = ( 249c0d1b6eeSJonathan Corbet [$type_constant, "``\$1``"], 250b97f193aSMauro Carvalho Chehab [$type_constant2, "``\$1``"], 251f3341dcfSJani Nikula # Note: need to escape () to avoid func matching later 2525267dd35SPaolo Bonzini [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], 2535267dd35SPaolo Bonzini [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], 2545219f18aSJonathan Corbet [$type_fp_param, "**\$1\\\\(\\\\)**"], 255346282dbSMauro Carvalho Chehab [$type_fp_param2, "**\$1\\\\(\\\\)**"], 256344fdb28SJonathan Corbet [$type_func, "\$1()"], 257df31175bSPaolo Bonzini [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], 258df31175bSPaolo Bonzini [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], 259df31175bSPaolo Bonzini [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], 260df31175bSPaolo Bonzini [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], 261a7291e7eSJani Nikula # in rst this can refer to any type 262df31175bSPaolo Bonzini [$type_fallback, "\\:c\\:type\\:`\$1`"], 263ee2aa759SMauro Carvalho Chehab [$type_param_ref, "**\$1\$2**"] 264c0d1b6eeSJonathan Corbet ); 265c0d1b6eeSJonathan Corbetmy $blankline_rst = "\n"; 266c0d1b6eeSJonathan Corbet 2671da177e4SLinus Torvalds# read arguments 2681da177e4SLinus Torvaldsif ($#ARGV == -1) { 2691da177e4SLinus Torvalds usage(); 2701da177e4SLinus Torvalds} 2711da177e4SLinus Torvalds 2728484baaaSRandy Dunlapmy $kernelversion; 273efa44475SMauro Carvalho Chehabmy $sphinx_major; 274efa44475SMauro Carvalho Chehab 2758484baaaSRandy Dunlapmy $dohighlight = ""; 2768484baaaSRandy Dunlap 2771da177e4SLinus Torvaldsmy $verbose = 0; 2782c12c810SPierre-Louis Bossartmy $Werror = 0; 279bdfe2be3SMauro Carvalho Chehabmy $output_mode = "rst"; 280e314ba31SDaniel Santosmy $output_preformatted = 0; 2814b44595aSJohannes Bergmy $no_doc_sections = 0; 2820b0f5f29SDaniel Vettermy $enable_lineno = 0; 283bdfe2be3SMauro Carvalho Chehabmy @highlights = @highlights_rst; 284bdfe2be3SMauro Carvalho Chehabmy $blankline = $blankline_rst; 2851da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 286b6c3f456SJani Nikula 287b6c3f456SJani Nikulause constant { 288b6c3f456SJani Nikula OUTPUT_ALL => 0, # output all symbols and doc sections 289b6c3f456SJani Nikula OUTPUT_INCLUDE => 1, # output only specified symbols 290eab795ddSMauro Carvalho Chehab OUTPUT_EXPORTED => 2, # output exported symbols 291eab795ddSMauro Carvalho Chehab OUTPUT_INTERNAL => 3, # output non-exported symbols 292b6c3f456SJani Nikula}; 293b6c3f456SJani Nikulamy $output_selection = OUTPUT_ALL; 294b0d60bfbSJonathan Corbetmy $show_not_found = 0; # No longer used 295b2c4105bSBen Hutchings 29688c2b57dSJani Nikulamy @export_file_list; 29788c2b57dSJani Nikula 298b2c4105bSBen Hutchingsmy @build_time; 299b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 300b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 301b2c4105bSBen Hutchings @build_time = gmtime($seconds); 302b2c4105bSBen Hutchings} else { 303b2c4105bSBen Hutchings @build_time = localtime; 304b2c4105bSBen Hutchings} 305b2c4105bSBen Hutchings 3061da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 3071da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 308b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 309b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 3101da177e4SLinus Torvalds 3118484baaaSRandy Dunlap# Essentially these are globals. 312b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 313b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 3141da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 3151da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 316eab795ddSMauro Carvalho Chehabmy %nosymbol_table = (); 3170b0f5f29SDaniel Vettermy $declaration_start_line; 3181da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 3191c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 3201da177e4SLinus Torvalds 321bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 322bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 323bd0e88e5SRandy Dunlap} 324bd0e88e5SRandy Dunlap 3252c12c810SPierre-Louis Bossartif (defined($ENV{'KDOC_WERROR'})) { 3262c12c810SPierre-Louis Bossart $Werror = "$ENV{'KDOC_WERROR'}"; 3272c12c810SPierre-Louis Bossart} 3282c12c810SPierre-Louis Bossart 3292c12c810SPierre-Louis Bossartif (defined($ENV{'KCFLAGS'})) { 3302c12c810SPierre-Louis Bossart my $kcflags = "$ENV{'KCFLAGS'}"; 3312c12c810SPierre-Louis Bossart 3322c12c810SPierre-Louis Bossart if ($kcflags =~ /Werror/) { 3332c12c810SPierre-Louis Bossart $Werror = 1; 3342c12c810SPierre-Louis Bossart } 3352c12c810SPierre-Louis Bossart} 3362c12c810SPierre-Louis Bossart 3371da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 3381da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 33993431e06SAlexander A. Klimov# https://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 3401da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 3411da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 3421da177e4SLinus Torvalds# into html. 3431da177e4SLinus Torvaldsmy $section_counter = 0; 3441da177e4SLinus Torvalds 3451da177e4SLinus Torvaldsmy $lineprefix=""; 3461da177e4SLinus Torvalds 34748af606aSJani Nikula# Parser states 34848af606aSJani Nikulause constant { 34948af606aSJani Nikula STATE_NORMAL => 0, # normal code 35048af606aSJani Nikula STATE_NAME => 1, # looking for function name 35117b78717SJonathan Corbet STATE_BODY_MAYBE => 2, # body - or maybe more description 35217b78717SJonathan Corbet STATE_BODY => 3, # the body of the comment 3530d55d48bSMauro Carvalho Chehab STATE_BODY_WITH_BLANK_LINE => 4, # the body, which has a blank line 3540d55d48bSMauro Carvalho Chehab STATE_PROTO => 5, # scanning prototype 3550d55d48bSMauro Carvalho Chehab STATE_DOCBLOCK => 6, # documentation block 3560d55d48bSMauro Carvalho Chehab STATE_INLINE => 7, # gathering doc outside main block 35748af606aSJani Nikula}; 3581da177e4SLinus Torvaldsmy $state; 359850622dfSRandy Dunlapmy $in_doc_sect; 360d742f24dSJonathan Corbetmy $leading_space; 3611da177e4SLinus Torvalds 36248af606aSJani Nikula# Inline documentation state 36348af606aSJani Nikulause constant { 36448af606aSJani Nikula STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 36548af606aSJani Nikula STATE_INLINE_NAME => 1, # looking for member name (@foo:) 36648af606aSJani Nikula STATE_INLINE_TEXT => 2, # looking for member documentation 36748af606aSJani Nikula STATE_INLINE_END => 3, # done 36848af606aSJani Nikula STATE_INLINE_ERROR => 4, # error - Comment without header was found. 36948af606aSJani Nikula # Spit a warning as it's not 370a4c6ebedSDanilo Cesar Lemes de Paula # proper kernel-doc and ignore the rest. 37148af606aSJani Nikula}; 37248af606aSJani Nikulamy $inline_doc_state; 373a4c6ebedSDanilo Cesar Lemes de Paula 3741da177e4SLinus Torvalds#declaration types: can be 3751da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 3761da177e4SLinus Torvaldsmy $decl_type; 3771da177e4SLinus Torvalds 3781da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 3791da177e4SLinus Torvaldsmy $doc_end = '\*/'; 3801da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 38112ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 3821da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 383f624adefSJani Nikula# @params and a strictly limited set of supported section names 3848569de68SJonathan Corbetmy $doc_sect = $doc_com . 385ef00028bSJonathan Corbet '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)'; 38612ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 3871da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 38848af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$'; 389fe7bc493SMauro Carvalho Chehabmy $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)'; 39048af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$'; 3910c9aa209SJani Nikulamy $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; 39286ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvaldsmy %parameterdescs; 3950b0f5f29SDaniel Vettermy %parameterdesc_start_lines; 3961da177e4SLinus Torvaldsmy @parameterlist; 3971da177e4SLinus Torvaldsmy %sections; 3981da177e4SLinus Torvaldsmy @sectionlist; 3990b0f5f29SDaniel Vettermy %section_start_lines; 400a1d94aa5SRandy Dunlapmy $sectcheck; 401a1d94aa5SRandy Dunlapmy $struct_actual; 4021da177e4SLinus Torvalds 4031da177e4SLinus Torvaldsmy $contents = ""; 4040b0f5f29SDaniel Vettermy $new_start_line = 0; 405f624adefSJani Nikula 406f624adefSJani Nikula# the canonical section names. see also $doc_sect above. 4071da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 4081da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 4091da177e4SLinus Torvaldsmy $section = $section_default; 4101da177e4SLinus Torvaldsmy $section_context = "Context"; 4114092bac7SYacine Belkadimy $section_return = "Return"; 4121da177e4SLinus Torvalds 4131da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 4141da177e4SLinus Torvalds 4151da177e4SLinus Torvaldsreset_state(); 4161da177e4SLinus Torvalds 417b031ac4eSMauro Carvalho Chehabwhile ($ARGV[0] =~ m/^--?(.*)/) { 418b031ac4eSMauro Carvalho Chehab my $cmd = $1; 419b031ac4eSMauro Carvalho Chehab shift @ARGV; 420b031ac4eSMauro Carvalho Chehab if ($cmd eq "man") { 4211da177e4SLinus Torvalds $output_mode = "man"; 4224d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 4231da177e4SLinus Torvalds $blankline = $blankline_man; 424b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "rst") { 425c0d1b6eeSJonathan Corbet $output_mode = "rst"; 426c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 427c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 428b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "none") { 4293a025e1dSMatthew Wilcox $output_mode = "none"; 430b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document 4311da177e4SLinus Torvalds $modulename = shift @ARGV; 432b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "function") { # to only output specific functions 433b6c3f456SJani Nikula $output_selection = OUTPUT_INCLUDE; 4341da177e4SLinus Torvalds $function = shift @ARGV; 4351da177e4SLinus Torvalds $function_table{$function} = 1; 436eab795ddSMauro Carvalho Chehab } elsif ($cmd eq "nosymbol") { # Exclude specific symbols 437eab795ddSMauro Carvalho Chehab my $symbol = shift @ARGV; 438eab795ddSMauro Carvalho Chehab $nosymbol_table{$symbol} = 1; 439b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export") { # only exported symbols 440b6c3f456SJani Nikula $output_selection = OUTPUT_EXPORTED; 441da9726ecSJani Nikula %function_table = (); 442b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "internal") { # only non-exported symbols 443b6c3f456SJani Nikula $output_selection = OUTPUT_INTERNAL; 444da9726ecSJani Nikula %function_table = (); 445b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export-file") { 44688c2b57dSJani Nikula my $file = shift @ARGV; 44788c2b57dSJani Nikula push(@export_file_list, $file); 448b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "v") { 4491da177e4SLinus Torvalds $verbose = 1; 4502c12c810SPierre-Louis Bossart } elsif ($cmd eq "Werror") { 4512c12c810SPierre-Louis Bossart $Werror = 1; 452b031ac4eSMauro Carvalho Chehab } elsif (($cmd eq "h") || ($cmd eq "help")) { 4531da177e4SLinus Torvalds usage(); 454b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'no-doc-sections') { 4554b44595aSJohannes Berg $no_doc_sections = 1; 456b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'enable-lineno') { 4570b0f5f29SDaniel Vetter $enable_lineno = 1; 458b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'show-not-found') { 459b0d60bfbSJonathan Corbet $show_not_found = 1; # A no-op but don't fail 460b031ac4eSMauro Carvalho Chehab } else { 461b031ac4eSMauro Carvalho Chehab # Unknown argument 462b031ac4eSMauro Carvalho Chehab usage(); 4631da177e4SLinus Torvalds } 4641da177e4SLinus Torvalds} 4651da177e4SLinus Torvalds 4668484baaaSRandy Dunlap# continue execution near EOF; 4678484baaaSRandy Dunlap 468efa44475SMauro Carvalho Chehab# The C domain dialect changed on Sphinx 3. So, we need to check the 469efa44475SMauro Carvalho Chehab# version in order to produce the right tags. 470efa44475SMauro Carvalho Chehabsub findprog($) 471efa44475SMauro Carvalho Chehab{ 472efa44475SMauro Carvalho Chehab foreach(split(/:/, $ENV{PATH})) { 473efa44475SMauro Carvalho Chehab return "$_/$_[0]" if(-x "$_/$_[0]"); 474efa44475SMauro Carvalho Chehab } 475efa44475SMauro Carvalho Chehab} 476efa44475SMauro Carvalho Chehab 477efa44475SMauro Carvalho Chehabsub get_sphinx_version() 478efa44475SMauro Carvalho Chehab{ 479efa44475SMauro Carvalho Chehab my $ver; 480efa44475SMauro Carvalho Chehab my $major = 1; 481efa44475SMauro Carvalho Chehab 482efa44475SMauro Carvalho Chehab my $cmd = "sphinx-build"; 483efa44475SMauro Carvalho Chehab if (!findprog($cmd)) { 484efa44475SMauro Carvalho Chehab my $cmd = "sphinx-build3"; 485efa44475SMauro Carvalho Chehab return $major if (!findprog($cmd)); 486efa44475SMauro Carvalho Chehab } 487efa44475SMauro Carvalho Chehab 488efa44475SMauro Carvalho Chehab open IN, "$cmd --version 2>&1 |"; 489efa44475SMauro Carvalho Chehab while (<IN>) { 490efa44475SMauro Carvalho Chehab if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) { 491efa44475SMauro Carvalho Chehab $major=$1; 492efa44475SMauro Carvalho Chehab last; 493efa44475SMauro Carvalho Chehab } 494efa44475SMauro Carvalho Chehab # Sphinx 1.2.x uses a different format 495efa44475SMauro Carvalho Chehab if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+)$/) { 496efa44475SMauro Carvalho Chehab $major=$1; 497efa44475SMauro Carvalho Chehab last; 498efa44475SMauro Carvalho Chehab } 499efa44475SMauro Carvalho Chehab } 500efa44475SMauro Carvalho Chehab close IN; 501efa44475SMauro Carvalho Chehab 502efa44475SMauro Carvalho Chehab return $major; 503efa44475SMauro Carvalho Chehab} 504efa44475SMauro Carvalho Chehab 50553f049faSBorislav Petkov# get kernel version from env 50653f049faSBorislav Petkovsub get_kernel_version() { 5071b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 50853f049faSBorislav Petkov 50953f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 51053f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 51153f049faSBorislav Petkov } 51253f049faSBorislav Petkov return $version; 51353f049faSBorislav Petkov} 5141da177e4SLinus Torvalds 5150b0f5f29SDaniel Vetter# 5160b0f5f29SDaniel Vettersub print_lineno { 5170b0f5f29SDaniel Vetter my $lineno = shift; 5180b0f5f29SDaniel Vetter if ($enable_lineno && defined($lineno)) { 5190b0f5f29SDaniel Vetter print "#define LINENO " . $lineno . "\n"; 5200b0f5f29SDaniel Vetter } 5210b0f5f29SDaniel Vetter} 5221da177e4SLinus Torvalds## 5231da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 5241da177e4SLinus Torvalds# 5251da177e4SLinus Torvaldssub dump_section { 52694dc7ad5SRandy Dunlap my $file = shift; 5271da177e4SLinus Torvalds my $name = shift; 5281da177e4SLinus Torvalds my $contents = join "\n", @_; 5291da177e4SLinus Torvalds 53013901ef2SJani Nikula if ($name =~ m/$type_param/) { 5311da177e4SLinus Torvalds $name = $1; 5321da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 533a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 5340b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 5350b0f5f29SDaniel Vetter $new_start_line = 0; 536ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 537ced69090SRandy Dunlap $name = "..."; 538ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 539a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 5400b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 5410b0f5f29SDaniel Vetter $new_start_line = 0; 5421da177e4SLinus Torvalds } else { 54394dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 54495b6be9dSJani Nikula # Only warn on user specified duplicate section names. 54595b6be9dSJani Nikula if ($name ne $section_default) { 54632217761SJani Nikula print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; 54732217761SJani Nikula ++$warnings; 54895b6be9dSJani Nikula } 54932217761SJani Nikula $sections{$name} .= $contents; 55032217761SJani Nikula } else { 5511da177e4SLinus Torvalds $sections{$name} = $contents; 5521da177e4SLinus Torvalds push @sectionlist, $name; 5530b0f5f29SDaniel Vetter $section_start_lines{$name} = $new_start_line; 5540b0f5f29SDaniel Vetter $new_start_line = 0; 5551da177e4SLinus Torvalds } 5561da177e4SLinus Torvalds } 55732217761SJani Nikula} 5581da177e4SLinus Torvalds 5591da177e4SLinus Torvalds## 560b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 561b112e0f7SJohannes Berg# 562b112e0f7SJohannes Bergsub dump_doc_section { 56394dc7ad5SRandy Dunlap my $file = shift; 564b112e0f7SJohannes Berg my $name = shift; 565b112e0f7SJohannes Berg my $contents = join "\n", @_; 566b112e0f7SJohannes Berg 5674b44595aSJohannes Berg if ($no_doc_sections) { 5684b44595aSJohannes Berg return; 5694b44595aSJohannes Berg } 5704b44595aSJohannes Berg 571eab795ddSMauro Carvalho Chehab return if (defined($nosymbol_table{$name})); 572eab795ddSMauro Carvalho Chehab 573b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 574eab795ddSMauro Carvalho Chehab (($output_selection == OUTPUT_INCLUDE) && 575eab795ddSMauro Carvalho Chehab defined($function_table{$name}))) 576b112e0f7SJohannes Berg { 57794dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 578b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 579b112e0f7SJohannes Berg 'sections' => \%sections, 580b112e0f7SJohannes Berg 'module' => $modulename, 581b6c3f456SJani Nikula 'content-only' => ($output_selection != OUTPUT_ALL), }); 582b112e0f7SJohannes Berg } 583b112e0f7SJohannes Berg} 584b112e0f7SJohannes Berg 585b112e0f7SJohannes Berg## 5861da177e4SLinus Torvalds# output function 5871da177e4SLinus Torvalds# 5881da177e4SLinus Torvalds# parameterdescs, a hash. 5891da177e4SLinus Torvalds# function => "function name" 5901da177e4SLinus Torvalds# parameterlist => @list of parameters 5911da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 5921da177e4SLinus Torvalds# sectionlist => @list of sections 593a21217daSRandy Dunlap# sections => %section descriptions 5941da177e4SLinus Torvalds# 5951da177e4SLinus Torvalds 5961da177e4SLinus Torvaldssub output_highlight { 5971da177e4SLinus Torvalds my $contents = join "\n",@_; 5981da177e4SLinus Torvalds my $line; 5991da177e4SLinus Torvalds 6001da177e4SLinus Torvalds# DEBUG 6011da177e4SLinus Torvalds# if (!defined $contents) { 6021da177e4SLinus Torvalds# use Carp; 6031da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 6041da177e4SLinus Torvalds# } 6051da177e4SLinus Torvalds 6063eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 6071da177e4SLinus Torvalds eval $dohighlight; 6081da177e4SLinus Torvalds die $@ if $@; 6093eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 6103eb014a1SRandy Dunlap 6111da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 61212ae6779SDaniel Santos if (! $output_preformatted) { 61312ae6779SDaniel Santos $line =~ s/^\s*//; 61412ae6779SDaniel Santos } 6151da177e4SLinus Torvalds if ($line eq ""){ 616e314ba31SDaniel Santos if (! $output_preformatted) { 6170bba924cSJonathan Corbet print $lineprefix, $blankline; 618e314ba31SDaniel Santos } 6191da177e4SLinus Torvalds } else { 620cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 621cdccb316SRandy Dunlap print "\\&$line"; 622cdccb316SRandy Dunlap } else { 6231da177e4SLinus Torvalds print $lineprefix, $line; 6241da177e4SLinus Torvalds } 625cdccb316SRandy Dunlap } 6261da177e4SLinus Torvalds print "\n"; 6271da177e4SLinus Torvalds } 6281da177e4SLinus Torvalds} 6291da177e4SLinus Torvalds 6301da177e4SLinus Torvalds## 6311da177e4SLinus Torvalds# output function in man 6321da177e4SLinus Torvaldssub output_function_man(%) { 6331da177e4SLinus Torvalds my %args = %{$_[0]}; 6341da177e4SLinus Torvalds my ($parameter, $section); 6351da177e4SLinus Torvalds my $count; 6361da177e4SLinus Torvalds 6371da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 6381da177e4SLinus Torvalds 6391da177e4SLinus Torvalds print ".SH NAME\n"; 6401da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 6411da177e4SLinus Torvalds 6421da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 643a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 6441da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 645a21217daSRandy Dunlap } else { 646a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 647a21217daSRandy Dunlap } 6481da177e4SLinus Torvalds $count = 0; 6491da177e4SLinus Torvalds my $parenth = "("; 6501da177e4SLinus Torvalds my $post = ","; 6511da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 6521da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 6531da177e4SLinus Torvalds $post = ");"; 6541da177e4SLinus Torvalds } 6551da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 6561da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 6571da177e4SLinus Torvalds # pointer-to-function 658*ed8348e2SMauro Carvalho Chehab print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n"; 6591da177e4SLinus Torvalds } else { 6601da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 661*ed8348e2SMauro Carvalho Chehab print ".BI \"" . $parenth . $type . "\" " . " \"" . $post . "\"\n"; 6621da177e4SLinus Torvalds } 6631da177e4SLinus Torvalds $count++; 6641da177e4SLinus Torvalds $parenth = ""; 6651da177e4SLinus Torvalds } 6661da177e4SLinus Torvalds 6671da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 6681da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6691da177e4SLinus Torvalds my $parameter_name = $parameter; 6701da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6711da177e4SLinus Torvalds 6721da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 6731da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6741da177e4SLinus Torvalds } 6751da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6761da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 6771da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6781da177e4SLinus Torvalds } 6791da177e4SLinus Torvalds} 6801da177e4SLinus Torvalds 6811da177e4SLinus Torvalds## 6821da177e4SLinus Torvalds# output enum in man 6831da177e4SLinus Torvaldssub output_enum_man(%) { 6841da177e4SLinus Torvalds my %args = %{$_[0]}; 6851da177e4SLinus Torvalds my ($parameter, $section); 6861da177e4SLinus Torvalds my $count; 6871da177e4SLinus Torvalds 6881da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 6891da177e4SLinus Torvalds 6901da177e4SLinus Torvalds print ".SH NAME\n"; 6911da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 6921da177e4SLinus Torvalds 6931da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 6941da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 6951da177e4SLinus Torvalds $count = 0; 6961da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 6971da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 6981da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 6991da177e4SLinus Torvalds print "\n};\n"; 7001da177e4SLinus Torvalds last; 7011da177e4SLinus Torvalds } 7021da177e4SLinus Torvalds else { 7031da177e4SLinus Torvalds print ", \n.br\n"; 7041da177e4SLinus Torvalds } 7051da177e4SLinus Torvalds $count++; 7061da177e4SLinus Torvalds } 7071da177e4SLinus Torvalds 7081da177e4SLinus Torvalds print ".SH Constants\n"; 7091da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7101da177e4SLinus Torvalds my $parameter_name = $parameter; 7111da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7121da177e4SLinus Torvalds 7131da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 7141da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7151da177e4SLinus Torvalds } 7161da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7171da177e4SLinus Torvalds print ".SH \"$section\"\n"; 7181da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7191da177e4SLinus Torvalds } 7201da177e4SLinus Torvalds} 7211da177e4SLinus Torvalds 7221da177e4SLinus Torvalds## 7231da177e4SLinus Torvalds# output struct in man 7241da177e4SLinus Torvaldssub output_struct_man(%) { 7251da177e4SLinus Torvalds my %args = %{$_[0]}; 7261da177e4SLinus Torvalds my ($parameter, $section); 7271da177e4SLinus Torvalds 7281da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 7291da177e4SLinus Torvalds 7301da177e4SLinus Torvalds print ".SH NAME\n"; 7311da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 7321da177e4SLinus Torvalds 7338ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 7348ad72163SMauro Carvalho Chehab $declaration =~ s/\t/ /g; 7358ad72163SMauro Carvalho Chehab $declaration =~ s/\n/"\n.br\n.BI \"/g; 7361da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 7371da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 7388ad72163SMauro Carvalho Chehab print ".BI \"$declaration\n};\n.br\n\n"; 7391da177e4SLinus Torvalds 740c51d3dacSRandy Dunlap print ".SH Members\n"; 7411da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7421da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 7431da177e4SLinus Torvalds 7441da177e4SLinus Torvalds my $parameter_name = $parameter; 7451da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7461da177e4SLinus Torvalds 7471da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7481da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 7491da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7501da177e4SLinus Torvalds } 7511da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7521da177e4SLinus Torvalds print ".SH \"$section\"\n"; 7531da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7541da177e4SLinus Torvalds } 7551da177e4SLinus Torvalds} 7561da177e4SLinus Torvalds 7571da177e4SLinus Torvalds## 7581da177e4SLinus Torvalds# output typedef in man 7591da177e4SLinus Torvaldssub output_typedef_man(%) { 7601da177e4SLinus Torvalds my %args = %{$_[0]}; 7611da177e4SLinus Torvalds my ($parameter, $section); 7621da177e4SLinus Torvalds 7631da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 7641da177e4SLinus Torvalds 7651da177e4SLinus Torvalds print ".SH NAME\n"; 7661da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 7671da177e4SLinus Torvalds 7681da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7691da177e4SLinus Torvalds print ".SH \"$section\"\n"; 7701da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7711da177e4SLinus Torvalds } 7721da177e4SLinus Torvalds} 7731da177e4SLinus Torvalds 774b112e0f7SJohannes Bergsub output_blockhead_man(%) { 7751da177e4SLinus Torvalds my %args = %{$_[0]}; 7761da177e4SLinus Torvalds my ($parameter, $section); 7771da177e4SLinus Torvalds my $count; 7781da177e4SLinus Torvalds 7791da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 7801da177e4SLinus Torvalds 7811da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7821da177e4SLinus Torvalds print ".SH \"$section\"\n"; 7831da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7841da177e4SLinus Torvalds } 7851da177e4SLinus Torvalds} 7861da177e4SLinus Torvalds 7871da177e4SLinus Torvalds## 788c0d1b6eeSJonathan Corbet# output in restructured text 789c0d1b6eeSJonathan Corbet# 790c0d1b6eeSJonathan Corbet 791c0d1b6eeSJonathan Corbet# 792c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 793c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 794c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 795c0d1b6eeSJonathan Corbet# 796c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 797c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 798c0d1b6eeSJonathan Corbet my ($parameter, $section); 799c0d1b6eeSJonathan Corbet 800c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 801eab795ddSMauro Carvalho Chehab next if (defined($nosymbol_table{$section})); 802eab795ddSMauro Carvalho Chehab 8039e72184bSJani Nikula if ($output_selection != OUTPUT_INCLUDE) { 804c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 8059e72184bSJani Nikula } 8060b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 807c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 808c0d1b6eeSJonathan Corbet print "\n"; 809c0d1b6eeSJonathan Corbet } 810c0d1b6eeSJonathan Corbet} 811c0d1b6eeSJonathan Corbet 812af250290SJonathan Corbet# 813af250290SJonathan Corbet# Apply the RST highlights to a sub-block of text. 814af250290SJonathan Corbet# 815af250290SJonathan Corbetsub highlight_block($) { 816af250290SJonathan Corbet # The dohighlight kludge requires the text be called $contents 817af250290SJonathan Corbet my $contents = shift; 818c0d1b6eeSJonathan Corbet eval $dohighlight; 819c0d1b6eeSJonathan Corbet die $@ if $@; 820af250290SJonathan Corbet return $contents; 821af250290SJonathan Corbet} 822c0d1b6eeSJonathan Corbet 823af250290SJonathan Corbet# 824af250290SJonathan Corbet# Regexes used only here. 825af250290SJonathan Corbet# 826af250290SJonathan Corbetmy $sphinx_literal = '^[^.].*::$'; 827af250290SJonathan Corbetmy $sphinx_cblock = '^\.\.\ +code-block::'; 828af250290SJonathan Corbet 829af250290SJonathan Corbetsub output_highlight_rst { 830af250290SJonathan Corbet my $input = join "\n",@_; 831af250290SJonathan Corbet my $output = ""; 832af250290SJonathan Corbet my $line; 833af250290SJonathan Corbet my $in_literal = 0; 834af250290SJonathan Corbet my $litprefix; 835af250290SJonathan Corbet my $block = ""; 836af250290SJonathan Corbet 837af250290SJonathan Corbet foreach $line (split "\n",$input) { 838af250290SJonathan Corbet # 839af250290SJonathan Corbet # If we're in a literal block, see if we should drop out 840af250290SJonathan Corbet # of it. Otherwise pass the line straight through unmunged. 841af250290SJonathan Corbet # 842af250290SJonathan Corbet if ($in_literal) { 843af250290SJonathan Corbet if (! ($line =~ /^\s*$/)) { 844af250290SJonathan Corbet # 845af250290SJonathan Corbet # If this is the first non-blank line in a literal 846af250290SJonathan Corbet # block we need to figure out what the proper indent is. 847af250290SJonathan Corbet # 848af250290SJonathan Corbet if ($litprefix eq "") { 849af250290SJonathan Corbet $line =~ /^(\s*)/; 850af250290SJonathan Corbet $litprefix = '^' . $1; 851af250290SJonathan Corbet $output .= $line . "\n"; 852af250290SJonathan Corbet } elsif (! ($line =~ /$litprefix/)) { 853af250290SJonathan Corbet $in_literal = 0; 854af250290SJonathan Corbet } else { 855af250290SJonathan Corbet $output .= $line . "\n"; 856af250290SJonathan Corbet } 857af250290SJonathan Corbet } else { 858af250290SJonathan Corbet $output .= $line . "\n"; 859af250290SJonathan Corbet } 860af250290SJonathan Corbet } 861af250290SJonathan Corbet # 862af250290SJonathan Corbet # Not in a literal block (or just dropped out) 863af250290SJonathan Corbet # 864af250290SJonathan Corbet if (! $in_literal) { 865af250290SJonathan Corbet $block .= $line . "\n"; 866af250290SJonathan Corbet if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) { 867af250290SJonathan Corbet $in_literal = 1; 868af250290SJonathan Corbet $litprefix = ""; 869af250290SJonathan Corbet $output .= highlight_block($block); 870af250290SJonathan Corbet $block = "" 871af250290SJonathan Corbet } 872af250290SJonathan Corbet } 873af250290SJonathan Corbet } 874af250290SJonathan Corbet 875af250290SJonathan Corbet if ($block) { 876af250290SJonathan Corbet $output .= highlight_block($block); 877af250290SJonathan Corbet } 878af250290SJonathan Corbet foreach $line (split "\n", $output) { 879830066a7SJani Nikula print $lineprefix . $line . "\n"; 880c0d1b6eeSJonathan Corbet } 881c0d1b6eeSJonathan Corbet} 882c0d1b6eeSJonathan Corbet 883c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 884c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 885c0d1b6eeSJonathan Corbet my ($parameter, $section); 886c099ff69SJani Nikula my $oldprefix = $lineprefix; 88782801d06SMauro Carvalho Chehab my $start = ""; 888c0d1b6eeSJonathan Corbet 889efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 890e3ad05feSMauro Carvalho Chehab if ($args{'typedef'}) { 89182801d06SMauro Carvalho Chehab print ".. c:type:: ". $args{'function'} . "\n\n"; 89282801d06SMauro Carvalho Chehab print_lineno($declaration_start_line); 89382801d06SMauro Carvalho Chehab print " **Typedef**: "; 89482801d06SMauro Carvalho Chehab $lineprefix = ""; 89582801d06SMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 89682801d06SMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 897c0d1b6eeSJonathan Corbet } else { 89882801d06SMauro Carvalho Chehab print ".. c:function:: "; 89982801d06SMauro Carvalho Chehab } 900e3ad05feSMauro Carvalho Chehab } else { 901e3ad05feSMauro Carvalho Chehab print ".. c:macro:: ". $args{'function'} . "\n\n"; 902e3ad05feSMauro Carvalho Chehab 903e3ad05feSMauro Carvalho Chehab if ($args{'typedef'}) { 904e3ad05feSMauro Carvalho Chehab print_lineno($declaration_start_line); 905e3ad05feSMauro Carvalho Chehab print " **Typedef**: "; 906e3ad05feSMauro Carvalho Chehab $lineprefix = ""; 907e3ad05feSMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 908e3ad05feSMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 909e3ad05feSMauro Carvalho Chehab } else { 910e3ad05feSMauro Carvalho Chehab print "``"; 911e3ad05feSMauro Carvalho Chehab } 912e3ad05feSMauro Carvalho Chehab } 91382801d06SMauro Carvalho Chehab if ($args{'functiontype'} ne "") { 91482801d06SMauro Carvalho Chehab $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; 91582801d06SMauro Carvalho Chehab } else { 91682801d06SMauro Carvalho Chehab $start .= $args{'function'} . " ("; 917c0d1b6eeSJonathan Corbet } 918c0d1b6eeSJonathan Corbet print $start; 919c0d1b6eeSJonathan Corbet 920c0d1b6eeSJonathan Corbet my $count = 0; 921c0d1b6eeSJonathan Corbet foreach my $parameter (@{$args{'parameterlist'}}) { 922c0d1b6eeSJonathan Corbet if ($count ne 0) { 923c0d1b6eeSJonathan Corbet print ", "; 924c0d1b6eeSJonathan Corbet } 925c0d1b6eeSJonathan Corbet $count++; 926c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 927a88b1672SMauro Carvalho Chehab 928c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 929c0d1b6eeSJonathan Corbet # pointer-to-function 930e8f4ba83SPeter Maydell print $1 . $parameter . ") (" . $2 . ")"; 931c0d1b6eeSJonathan Corbet } else { 932*ed8348e2SMauro Carvalho Chehab print $type; 933c0d1b6eeSJonathan Corbet } 934c0d1b6eeSJonathan Corbet } 93582801d06SMauro Carvalho Chehab if ($args{'typedef'}) { 93682801d06SMauro Carvalho Chehab print ");``\n\n"; 93782801d06SMauro Carvalho Chehab } else { 938e3ad05feSMauro Carvalho Chehab if ($sphinx_major < 3) { 939c099ff69SJani Nikula print ")\n\n"; 940e3ad05feSMauro Carvalho Chehab } else { 941e3ad05feSMauro Carvalho Chehab print ")``\n"; 942e3ad05feSMauro Carvalho Chehab } 9430b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 944c099ff69SJani Nikula $lineprefix = " "; 945c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 946c099ff69SJani Nikula print "\n"; 94782801d06SMauro Carvalho Chehab } 948c0d1b6eeSJonathan Corbet 949ecbcfba1SJani Nikula print "**Parameters**\n\n"; 950c099ff69SJani Nikula $lineprefix = " "; 951c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 952c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 953ada5f446SGabriel Krisman Bertazi $parameter_name =~ s/\[.*//; 954c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 955c0d1b6eeSJonathan Corbet 956c0d1b6eeSJonathan Corbet if ($type ne "") { 957*ed8348e2SMauro Carvalho Chehab print "``$type``\n"; 958c0d1b6eeSJonathan Corbet } else { 959c0d1b6eeSJonathan Corbet print "``$parameter``\n"; 960c0d1b6eeSJonathan Corbet } 9610b0f5f29SDaniel Vetter 9620b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 9630b0f5f29SDaniel Vetter 9645e64fa9cSJani Nikula if (defined($args{'parameterdescs'}{$parameter_name}) && 9655e64fa9cSJani Nikula $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 966c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 967c0d1b6eeSJonathan Corbet } else { 968d4b08e0cSJani Nikula print " *undescribed*\n"; 969c0d1b6eeSJonathan Corbet } 970c0d1b6eeSJonathan Corbet print "\n"; 971c0d1b6eeSJonathan Corbet } 972c099ff69SJani Nikula 973c099ff69SJani Nikula $lineprefix = $oldprefix; 974c0d1b6eeSJonathan Corbet output_section_rst(@_); 975c0d1b6eeSJonathan Corbet} 976c0d1b6eeSJonathan Corbet 977c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 978c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 979c0d1b6eeSJonathan Corbet my $section; 980c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 981c0d1b6eeSJonathan Corbet $lineprefix = ""; 982c0d1b6eeSJonathan Corbet 983c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 984ecbcfba1SJani Nikula print "**$section**\n\n"; 9850b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 986c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 987c0d1b6eeSJonathan Corbet print "\n"; 988c0d1b6eeSJonathan Corbet } 989c0d1b6eeSJonathan Corbet print "\n"; 990c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 991c0d1b6eeSJonathan Corbet} 992c0d1b6eeSJonathan Corbet 993c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 994c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 995c0d1b6eeSJonathan Corbet my ($parameter); 996c099ff69SJani Nikula my $oldprefix = $lineprefix; 997c0d1b6eeSJonathan Corbet my $count; 99862850976SJani Nikula 999efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 1000efa44475SMauro Carvalho Chehab my $name = "enum " . $args{'enum'}; 100162850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1002efa44475SMauro Carvalho Chehab } else { 1003efa44475SMauro Carvalho Chehab my $name = $args{'enum'}; 1004efa44475SMauro Carvalho Chehab print "\n\n.. c:enum:: " . $name . "\n\n"; 1005efa44475SMauro Carvalho Chehab } 10060b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1007c099ff69SJani Nikula $lineprefix = " "; 1008c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1009c099ff69SJani Nikula print "\n"; 1010c0d1b6eeSJonathan Corbet 1011ecbcfba1SJani Nikula print "**Constants**\n\n"; 1012c0d1b6eeSJonathan Corbet $lineprefix = " "; 1013c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1014ecbcfba1SJani Nikula print "``$parameter``\n"; 1015c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 1016c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 1017c0d1b6eeSJonathan Corbet } else { 1018d4b08e0cSJani Nikula print " *undescribed*\n"; 1019c0d1b6eeSJonathan Corbet } 1020c0d1b6eeSJonathan Corbet print "\n"; 1021c0d1b6eeSJonathan Corbet } 1022c099ff69SJani Nikula 1023c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1024c0d1b6eeSJonathan Corbet output_section_rst(@_); 1025c0d1b6eeSJonathan Corbet} 1026c0d1b6eeSJonathan Corbet 1027c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 1028c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1029c0d1b6eeSJonathan Corbet my ($parameter); 1030c099ff69SJani Nikula my $oldprefix = $lineprefix; 1031efa44475SMauro Carvalho Chehab my $name; 1032c0d1b6eeSJonathan Corbet 1033efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 1034efa44475SMauro Carvalho Chehab $name = "typedef " . $args{'typedef'}; 1035efa44475SMauro Carvalho Chehab } else { 1036efa44475SMauro Carvalho Chehab $name = $args{'typedef'}; 1037efa44475SMauro Carvalho Chehab } 103862850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 10390b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1040c099ff69SJani Nikula $lineprefix = " "; 1041c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1042c099ff69SJani Nikula print "\n"; 1043c0d1b6eeSJonathan Corbet 1044c099ff69SJani Nikula $lineprefix = $oldprefix; 1045c0d1b6eeSJonathan Corbet output_section_rst(@_); 1046c0d1b6eeSJonathan Corbet} 1047c0d1b6eeSJonathan Corbet 1048c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 1049c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1050c0d1b6eeSJonathan Corbet my ($parameter); 1051c099ff69SJani Nikula my $oldprefix = $lineprefix; 1052c0d1b6eeSJonathan Corbet 1053efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 1054efa44475SMauro Carvalho Chehab my $name = $args{'type'} . " " . $args{'struct'}; 105562850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1056efa44475SMauro Carvalho Chehab } else { 1057efa44475SMauro Carvalho Chehab my $name = $args{'struct'}; 1058efa44475SMauro Carvalho Chehab print "\n\n.. c:struct:: " . $name . "\n\n"; 1059efa44475SMauro Carvalho Chehab } 10600b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1061c099ff69SJani Nikula $lineprefix = " "; 1062c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1063c099ff69SJani Nikula print "\n"; 1064c0d1b6eeSJonathan Corbet 1065ecbcfba1SJani Nikula print "**Definition**\n\n"; 1066c0d1b6eeSJonathan Corbet print "::\n\n"; 10678ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 10688ad72163SMauro Carvalho Chehab $declaration =~ s/\t/ /g; 10698ad72163SMauro Carvalho Chehab print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n"; 1070c0d1b6eeSJonathan Corbet 1071ecbcfba1SJani Nikula print "**Members**\n\n"; 1072c099ff69SJani Nikula $lineprefix = " "; 1073c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1074c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 1075c0d1b6eeSJonathan Corbet 1076c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1077c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 1078c0d1b6eeSJonathan Corbet 1079c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1080c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 10810b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 10826d232c80SMauro Carvalho Chehab print "``" . $parameter . "``\n"; 1083c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1084c0d1b6eeSJonathan Corbet print "\n"; 1085c0d1b6eeSJonathan Corbet } 1086c0d1b6eeSJonathan Corbet print "\n"; 1087c099ff69SJani Nikula 1088c099ff69SJani Nikula $lineprefix = $oldprefix; 1089c0d1b6eeSJonathan Corbet output_section_rst(@_); 1090c0d1b6eeSJonathan Corbet} 1091c0d1b6eeSJonathan Corbet 10923a025e1dSMatthew Wilcox## none mode output functions 10933a025e1dSMatthew Wilcox 10943a025e1dSMatthew Wilcoxsub output_function_none(%) { 10953a025e1dSMatthew Wilcox} 10963a025e1dSMatthew Wilcox 10973a025e1dSMatthew Wilcoxsub output_enum_none(%) { 10983a025e1dSMatthew Wilcox} 10993a025e1dSMatthew Wilcox 11003a025e1dSMatthew Wilcoxsub output_typedef_none(%) { 11013a025e1dSMatthew Wilcox} 11023a025e1dSMatthew Wilcox 11033a025e1dSMatthew Wilcoxsub output_struct_none(%) { 11043a025e1dSMatthew Wilcox} 11053a025e1dSMatthew Wilcox 11063a025e1dSMatthew Wilcoxsub output_blockhead_none(%) { 11073a025e1dSMatthew Wilcox} 11083a025e1dSMatthew Wilcox 11091da177e4SLinus Torvalds## 111027205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 111127205744SRandy Dunlap# calls the generated, variable output_ function name based on 111227205744SRandy Dunlap# functype and output_mode 11131da177e4SLinus Torvaldssub output_declaration { 11141da177e4SLinus Torvalds no strict 'refs'; 11151da177e4SLinus Torvalds my $name = shift; 11161da177e4SLinus Torvalds my $functype = shift; 11171da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 1118eab795ddSMauro Carvalho Chehab 1119eab795ddSMauro Carvalho Chehab return if (defined($nosymbol_table{$name})); 1120eab795ddSMauro Carvalho Chehab 1121b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 1122b6c3f456SJani Nikula (($output_selection == OUTPUT_INCLUDE || 1123b6c3f456SJani Nikula $output_selection == OUTPUT_EXPORTED) && 112486ae2e38SJani Nikula defined($function_table{$name})) || 1125eab795ddSMauro Carvalho Chehab ($output_selection == OUTPUT_INTERNAL && 112686ae2e38SJani Nikula !($functype eq "function" && defined($function_table{$name})))) 11271da177e4SLinus Torvalds { 11281da177e4SLinus Torvalds &$func(@_); 11291da177e4SLinus Torvalds $section_counter++; 11301da177e4SLinus Torvalds } 11311da177e4SLinus Torvalds} 11321da177e4SLinus Torvalds 11331da177e4SLinus Torvalds## 113427205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 1135b112e0f7SJohannes Bergsub output_blockhead { 11361da177e4SLinus Torvalds no strict 'refs'; 1137b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 11381da177e4SLinus Torvalds &$func(@_); 11391da177e4SLinus Torvalds $section_counter++; 11401da177e4SLinus Torvalds} 11411da177e4SLinus Torvalds 11421da177e4SLinus Torvalds## 11431da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 11441da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 11451da177e4SLinus Torvaldssub dump_declaration($$) { 11461da177e4SLinus Torvalds no strict 'refs'; 11471da177e4SLinus Torvalds my ($prototype, $file) = @_; 11481da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 11491da177e4SLinus Torvalds &$func(@_); 11501da177e4SLinus Torvalds} 11511da177e4SLinus Torvalds 11521da177e4SLinus Torvaldssub dump_union($$) { 11531da177e4SLinus Torvalds dump_struct(@_); 11541da177e4SLinus Torvalds} 11551da177e4SLinus Torvalds 11561da177e4SLinus Torvaldssub dump_struct($$) { 11571da177e4SLinus Torvalds my $x = shift; 11581da177e4SLinus Torvalds my $file = shift; 11591da177e4SLinus Torvalds 1160a070991fSJonathan Cameron if ($x =~ /(struct|union)\s+(\w+)\s*\{(.*)\}(\s*(__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*/) { 11615cb5c31cSJohannes Berg my $decl_type = $1; 11621da177e4SLinus Torvalds $declaration_name = $2; 11631da177e4SLinus Torvalds my $members = $3; 11641da177e4SLinus Torvalds 1165aeec46b9SMartin Waitz # ignore members marked private: 11660d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 11670d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 1168aeec46b9SMartin Waitz # strip comments: 1169aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 1170ef5da59fSRandy Dunlap # strip attributes 11713d9bfb19SSakari Ailus $members =~ s/\s*__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)/ /gi; 11723d9bfb19SSakari Ailus $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos; 11733d9bfb19SSakari Ailus $members =~ s/\s*__packed\s*/ /gos; 1174f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos; 1175f861537dSAndré Almeida $members =~ s/\s*____cacheline_aligned_in_smp/ /gos; 1176a070991fSJonathan Cameron $members =~ s/\s*____cacheline_aligned/ /gos; 11773556108eSMauro Carvalho Chehab 1178b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 11793556108eSMauro Carvalho Chehab $members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos; 118045005b27SMauro Carvalho Chehab $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 11811cb566baSJakub Kicinski # replace DECLARE_HASHTABLE 118245005b27SMauro Carvalho Chehab $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos; 118345005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO 118445005b27SMauro Carvalho Chehab $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; 118545005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO_PTR 118645005b27SMauro Carvalho Chehab $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; 1187aeec46b9SMartin Waitz 11888ad72163SMauro Carvalho Chehab my $declaration = $members; 11898ad72163SMauro Carvalho Chehab 11908ad72163SMauro Carvalho Chehab # Split nested struct/union elements as newer ones 119184ce5b98SMauro Carvalho Chehab while ($members =~ m/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/) { 119284ce5b98SMauro Carvalho Chehab my $newmember; 119384ce5b98SMauro Carvalho Chehab my $maintype = $1; 119484ce5b98SMauro Carvalho Chehab my $ids = $4; 11958ad72163SMauro Carvalho Chehab my $content = $3; 119684ce5b98SMauro Carvalho Chehab foreach my $id(split /,/, $ids) { 119784ce5b98SMauro Carvalho Chehab $newmember .= "$maintype $id; "; 119884ce5b98SMauro Carvalho Chehab 11998ad72163SMauro Carvalho Chehab $id =~ s/[:\[].*//; 120084ce5b98SMauro Carvalho Chehab $id =~ s/^\s*\**(\S+)\s*/$1/; 12018ad72163SMauro Carvalho Chehab foreach my $arg (split /;/, $content) { 12028ad72163SMauro Carvalho Chehab next if ($arg =~ m/^\s*$/); 12037c0d7e87SMauro Carvalho Chehab if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) { 12047c0d7e87SMauro Carvalho Chehab # pointer-to-function 12057c0d7e87SMauro Carvalho Chehab my $type = $1; 12067c0d7e87SMauro Carvalho Chehab my $name = $2; 12077c0d7e87SMauro Carvalho Chehab my $extra = $3; 12087c0d7e87SMauro Carvalho Chehab next if (!$name); 12097c0d7e87SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 12107c0d7e87SMauro Carvalho Chehab # anonymous struct/union 12117c0d7e87SMauro Carvalho Chehab $newmember .= "$type$name$extra; "; 12127c0d7e87SMauro Carvalho Chehab } else { 12137c0d7e87SMauro Carvalho Chehab $newmember .= "$type$id.$name$extra; "; 12147c0d7e87SMauro Carvalho Chehab } 12157c0d7e87SMauro Carvalho Chehab } else { 121684ce5b98SMauro Carvalho Chehab my $type; 121784ce5b98SMauro Carvalho Chehab my $names; 121884ce5b98SMauro Carvalho Chehab $arg =~ s/^\s+//; 121984ce5b98SMauro Carvalho Chehab $arg =~ s/\s+$//; 122084ce5b98SMauro Carvalho Chehab # Handle bitmaps 122184ce5b98SMauro Carvalho Chehab $arg =~ s/:\s*\d+\s*//g; 122284ce5b98SMauro Carvalho Chehab # Handle arrays 1223d404d579SMauro Carvalho Chehab $arg =~ s/\[.*\]//g; 122484ce5b98SMauro Carvalho Chehab # The type may have multiple words, 122584ce5b98SMauro Carvalho Chehab # and multiple IDs can be defined, like: 122684ce5b98SMauro Carvalho Chehab # const struct foo, *bar, foobar 122784ce5b98SMauro Carvalho Chehab # So, we remove spaces when parsing the 122884ce5b98SMauro Carvalho Chehab # names, in order to match just names 122984ce5b98SMauro Carvalho Chehab # and commas for the names 123084ce5b98SMauro Carvalho Chehab $arg =~ s/\s*,\s*/,/g; 123184ce5b98SMauro Carvalho Chehab if ($arg =~ m/(.*)\s+([\S+,]+)/) { 123284ce5b98SMauro Carvalho Chehab $type = $1; 123384ce5b98SMauro Carvalho Chehab $names = $2; 123484ce5b98SMauro Carvalho Chehab } else { 123584ce5b98SMauro Carvalho Chehab $newmember .= "$arg; "; 123684ce5b98SMauro Carvalho Chehab next; 123784ce5b98SMauro Carvalho Chehab } 123884ce5b98SMauro Carvalho Chehab foreach my $name (split /,/, $names) { 123984ce5b98SMauro Carvalho Chehab $name =~ s/^\s*\**(\S+)\s*/$1/; 12408ad72163SMauro Carvalho Chehab next if (($name =~ m/^\s*$/)); 12418ad72163SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 12428ad72163SMauro Carvalho Chehab # anonymous struct/union 12438ad72163SMauro Carvalho Chehab $newmember .= "$type $name; "; 12448ad72163SMauro Carvalho Chehab } else { 12458ad72163SMauro Carvalho Chehab $newmember .= "$type $id.$name; "; 12468ad72163SMauro Carvalho Chehab } 12478ad72163SMauro Carvalho Chehab } 12487c0d7e87SMauro Carvalho Chehab } 124984ce5b98SMauro Carvalho Chehab } 125084ce5b98SMauro Carvalho Chehab } 1251673bb2dfSBen Hutchings $members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/$newmember/; 125284ce5b98SMauro Carvalho Chehab } 12538ad72163SMauro Carvalho Chehab 12548ad72163SMauro Carvalho Chehab # Ignore other nested elements, like enums 1255673bb2dfSBen Hutchings $members =~ s/(\{[^\{\}]*\})//g; 12568ad72163SMauro Carvalho Chehab 1257151c468bSMauro Carvalho Chehab create_parameterlist($members, ';', $file, $declaration_name); 12581081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual); 12591da177e4SLinus Torvalds 12608ad72163SMauro Carvalho Chehab # Adjust declaration for better display 1261673bb2dfSBen Hutchings $declaration =~ s/([\{;])/$1\n/g; 1262673bb2dfSBen Hutchings $declaration =~ s/\}\s+;/};/g; 12638ad72163SMauro Carvalho Chehab # Better handle inlined enums 1264673bb2dfSBen Hutchings do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/); 12658ad72163SMauro Carvalho Chehab 12668ad72163SMauro Carvalho Chehab my @def_args = split /\n/, $declaration; 12678ad72163SMauro Carvalho Chehab my $level = 1; 12688ad72163SMauro Carvalho Chehab $declaration = ""; 12698ad72163SMauro Carvalho Chehab foreach my $clause (@def_args) { 12708ad72163SMauro Carvalho Chehab $clause =~ s/^\s+//; 12718ad72163SMauro Carvalho Chehab $clause =~ s/\s+$//; 12728ad72163SMauro Carvalho Chehab $clause =~ s/\s+/ /; 12738ad72163SMauro Carvalho Chehab next if (!$clause); 1274673bb2dfSBen Hutchings $level-- if ($clause =~ m/(\})/ && $level > 1); 12758ad72163SMauro Carvalho Chehab if (!($clause =~ m/^\s*#/)) { 12768ad72163SMauro Carvalho Chehab $declaration .= "\t" x $level; 12778ad72163SMauro Carvalho Chehab } 12788ad72163SMauro Carvalho Chehab $declaration .= "\t" . $clause . "\n"; 1279673bb2dfSBen Hutchings $level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/)); 12808ad72163SMauro Carvalho Chehab } 12811da177e4SLinus Torvalds output_declaration($declaration_name, 12821da177e4SLinus Torvalds 'struct', 12831da177e4SLinus Torvalds {'struct' => $declaration_name, 12841da177e4SLinus Torvalds 'module' => $modulename, 12858ad72163SMauro Carvalho Chehab 'definition' => $declaration, 12861da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 12871da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 12881da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 12891da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 12901da177e4SLinus Torvalds 'sections' => \%sections, 12911da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 12921da177e4SLinus Torvalds 'type' => $decl_type 12931da177e4SLinus Torvalds }); 12941da177e4SLinus Torvalds } 12951da177e4SLinus Torvalds else { 1296d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 12971da177e4SLinus Torvalds ++$errors; 12981da177e4SLinus Torvalds } 12991da177e4SLinus Torvalds} 13001da177e4SLinus Torvalds 130185afe608SMauro Carvalho Chehab 130285afe608SMauro Carvalho Chehabsub show_warnings($$) { 130385afe608SMauro Carvalho Chehab my $functype = shift; 130485afe608SMauro Carvalho Chehab my $name = shift; 130585afe608SMauro Carvalho Chehab 1306eab795ddSMauro Carvalho Chehab return 0 if (defined($nosymbol_table{$name})); 1307eab795ddSMauro Carvalho Chehab 130885afe608SMauro Carvalho Chehab return 1 if ($output_selection == OUTPUT_ALL); 130985afe608SMauro Carvalho Chehab 131085afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_EXPORTED) { 131185afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 131285afe608SMauro Carvalho Chehab return 1; 131385afe608SMauro Carvalho Chehab } else { 131485afe608SMauro Carvalho Chehab return 0; 131585afe608SMauro Carvalho Chehab } 131685afe608SMauro Carvalho Chehab } 131785afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_INTERNAL) { 131885afe608SMauro Carvalho Chehab if (!($functype eq "function" && defined($function_table{$name}))) { 131985afe608SMauro Carvalho Chehab return 1; 132085afe608SMauro Carvalho Chehab } else { 132185afe608SMauro Carvalho Chehab return 0; 132285afe608SMauro Carvalho Chehab } 132385afe608SMauro Carvalho Chehab } 132485afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_INCLUDE) { 132585afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 132685afe608SMauro Carvalho Chehab return 1; 132785afe608SMauro Carvalho Chehab } else { 132885afe608SMauro Carvalho Chehab return 0; 132985afe608SMauro Carvalho Chehab } 133085afe608SMauro Carvalho Chehab } 133185afe608SMauro Carvalho Chehab die("Please add the new output type at show_warnings()"); 133285afe608SMauro Carvalho Chehab} 133385afe608SMauro Carvalho Chehab 13341da177e4SLinus Torvaldssub dump_enum($$) { 13351da177e4SLinus Torvalds my $x = shift; 13361da177e4SLinus Torvalds my $file = shift; 1337d38c8cfbSMauro Carvalho Chehab my $members; 1338d38c8cfbSMauro Carvalho Chehab 13391da177e4SLinus Torvalds 1340aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 13414468e21eSConchúr Navid # strip #define macros inside enums 13424468e21eSConchúr Navid $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 1343b6d676dbSRandy Dunlap 1344d38c8cfbSMauro Carvalho Chehab if ($x =~ /typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;/) { 1345d38c8cfbSMauro Carvalho Chehab $declaration_name = $2; 1346d38c8cfbSMauro Carvalho Chehab $members = $1; 1347d38c8cfbSMauro Carvalho Chehab } elsif ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) { 13481da177e4SLinus Torvalds $declaration_name = $1; 1349d38c8cfbSMauro Carvalho Chehab $members = $2; 1350d38c8cfbSMauro Carvalho Chehab } 1351d38c8cfbSMauro Carvalho Chehab 1352d38c8cfbSMauro Carvalho Chehab if ($declaration_name) { 13535cb5c31cSJohannes Berg my %_members; 13545cb5c31cSJohannes Berg 1355463a0fdcSMarkus Heiser $members =~ s/\s+$//; 13561da177e4SLinus Torvalds 13571da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 13581da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 13591da177e4SLinus Torvalds push @parameterlist, $arg; 13601da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 13611da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 136285afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 13632defb272SMauro Carvalho Chehab print STDERR "${file}:$.: warning: Enum value '$arg' not described in enum '$declaration_name'\n"; 13642defb272SMauro Carvalho Chehab } 13651da177e4SLinus Torvalds } 13665cb5c31cSJohannes Berg $_members{$arg} = 1; 13675cb5c31cSJohannes Berg } 13681da177e4SLinus Torvalds 13695cb5c31cSJohannes Berg while (my ($k, $v) = each %parameterdescs) { 13705cb5c31cSJohannes Berg if (!exists($_members{$k})) { 137185afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 13722defb272SMauro Carvalho Chehab print STDERR "${file}:$.: warning: Excess enum value '$k' description in '$declaration_name'\n"; 13732defb272SMauro Carvalho Chehab } 13745cb5c31cSJohannes Berg } 13751da177e4SLinus Torvalds } 13761da177e4SLinus Torvalds 13771da177e4SLinus Torvalds output_declaration($declaration_name, 13781da177e4SLinus Torvalds 'enum', 13791da177e4SLinus Torvalds {'enum' => $declaration_name, 13801da177e4SLinus Torvalds 'module' => $modulename, 13811da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 13821da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 13831da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 13841da177e4SLinus Torvalds 'sections' => \%sections, 13851da177e4SLinus Torvalds 'purpose' => $declaration_purpose 13861da177e4SLinus Torvalds }); 1387d38c8cfbSMauro Carvalho Chehab } else { 1388d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 13891da177e4SLinus Torvalds ++$errors; 13901da177e4SLinus Torvalds } 13911da177e4SLinus Torvalds} 13921da177e4SLinus Torvalds 13931da177e4SLinus Torvaldssub dump_typedef($$) { 13941da177e4SLinus Torvalds my $x = shift; 13951da177e4SLinus Torvalds my $file = shift; 13961da177e4SLinus Torvalds 1397aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 139883766452SMauro Carvalho Chehab 139983766452SMauro Carvalho Chehab # Parse function prototypes 1400d37c43ceSMauro Carvalho Chehab if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ || 1401d37c43ceSMauro Carvalho Chehab $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) { 1402d37c43ceSMauro Carvalho Chehab 140383766452SMauro Carvalho Chehab # Function typedefs 140483766452SMauro Carvalho Chehab $return_type = $1; 140583766452SMauro Carvalho Chehab $declaration_name = $2; 140683766452SMauro Carvalho Chehab my $args = $3; 140783766452SMauro Carvalho Chehab 1408151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 140983766452SMauro Carvalho Chehab 141083766452SMauro Carvalho Chehab output_declaration($declaration_name, 141183766452SMauro Carvalho Chehab 'function', 141283766452SMauro Carvalho Chehab {'function' => $declaration_name, 141382801d06SMauro Carvalho Chehab 'typedef' => 1, 141483766452SMauro Carvalho Chehab 'module' => $modulename, 141583766452SMauro Carvalho Chehab 'functiontype' => $return_type, 141683766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 141783766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 141883766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 141983766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 142083766452SMauro Carvalho Chehab 'sections' => \%sections, 142183766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 142283766452SMauro Carvalho Chehab }); 142383766452SMauro Carvalho Chehab return; 142483766452SMauro Carvalho Chehab } 142583766452SMauro Carvalho Chehab 14261da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 14271da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 14281da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 14291da177e4SLinus Torvalds } 14301da177e4SLinus Torvalds 14311da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 14321da177e4SLinus Torvalds $declaration_name = $1; 14331da177e4SLinus Torvalds 14341da177e4SLinus Torvalds output_declaration($declaration_name, 14351da177e4SLinus Torvalds 'typedef', 14361da177e4SLinus Torvalds {'typedef' => $declaration_name, 14371da177e4SLinus Torvalds 'module' => $modulename, 14381da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 14391da177e4SLinus Torvalds 'sections' => \%sections, 14401da177e4SLinus Torvalds 'purpose' => $declaration_purpose 14411da177e4SLinus Torvalds }); 14421da177e4SLinus Torvalds } 14431da177e4SLinus Torvalds else { 1444d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 14451da177e4SLinus Torvalds ++$errors; 14461da177e4SLinus Torvalds } 14471da177e4SLinus Torvalds} 14481da177e4SLinus Torvalds 1449a1d94aa5SRandy Dunlapsub save_struct_actual($) { 1450a1d94aa5SRandy Dunlap my $actual = shift; 1451a1d94aa5SRandy Dunlap 1452a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 1453a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 1454a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 1455a1d94aa5SRandy Dunlap} 1456a1d94aa5SRandy Dunlap 1457151c468bSMauro Carvalho Chehabsub create_parameterlist($$$$) { 14581da177e4SLinus Torvalds my $args = shift; 14591da177e4SLinus Torvalds my $splitter = shift; 14601da177e4SLinus Torvalds my $file = shift; 1461151c468bSMauro Carvalho Chehab my $declaration_name = shift; 14621da177e4SLinus Torvalds my $type; 14631da177e4SLinus Torvalds my $param; 14641da177e4SLinus Torvalds 1465a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 14661da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 14671da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 14681da177e4SLinus Torvalds } 14691da177e4SLinus Torvalds 14701da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 14711da177e4SLinus Torvalds # strip comments 14721da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 14731da177e4SLinus Torvalds # strip leading/trailing spaces 14741da177e4SLinus Torvalds $arg =~ s/^\s*//; 14751da177e4SLinus Torvalds $arg =~ s/\s*$//; 14761da177e4SLinus Torvalds $arg =~ s/\s+/ /; 14771da177e4SLinus Torvalds 14781da177e4SLinus Torvalds if ($arg =~ /^#/) { 14791da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 14801da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 14811da177e4SLinus Torvalds # output_* subs. 1482*ed8348e2SMauro Carvalho Chehab push_parameter($arg, "", "", $file); 148300d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 14841da177e4SLinus Torvalds # pointer-to-function 14851da177e4SLinus Torvalds $arg =~ tr/#/,/; 14867c0d7e87SMauro Carvalho Chehab $arg =~ m/[^\(]+\(\*?\s*([\w\.]*)\s*\)/; 14871da177e4SLinus Torvalds $param = $1; 14881da177e4SLinus Torvalds $type = $arg; 148900d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1490a1d94aa5SRandy Dunlap save_struct_actual($param); 1491*ed8348e2SMauro Carvalho Chehab push_parameter($param, $type, $arg, $file, $declaration_name); 1492aeec46b9SMartin Waitz } elsif ($arg) { 14931da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 14941da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 14951da177e4SLinus Torvalds 14961da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 14971da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 14981da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 14991da177e4SLinus Torvalds } 1500884f2810SBorislav Petkov 1501884f2810SBorislav Petkov my @first_arg; 1502884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1503884f2810SBorislav Petkov shift @args; 1504884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 1505884f2810SBorislav Petkov push(@first_arg, $2); 1506884f2810SBorislav Petkov } else { 1507884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 1508884f2810SBorislav Petkov } 1509884f2810SBorislav Petkov 15101da177e4SLinus Torvalds unshift(@args, pop @first_arg); 15111da177e4SLinus Torvalds $type = join " ", @first_arg; 15121da177e4SLinus Torvalds 15131da177e4SLinus Torvalds foreach $param (@args) { 15141da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 1515a1d94aa5SRandy Dunlap save_struct_actual($2); 1516*ed8348e2SMauro Carvalho Chehab 1517*ed8348e2SMauro Carvalho Chehab push_parameter($2, "$type $1", $arg, $file, $declaration_name); 15181da177e4SLinus Torvalds } 15191da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 15207b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 1521a1d94aa5SRandy Dunlap save_struct_actual($1); 1522*ed8348e2SMauro Carvalho Chehab push_parameter($1, "$type:$2", $arg, $file, $declaration_name) 15231da177e4SLinus Torvalds } 15247b97887eSRandy Dunlap } 15251da177e4SLinus Torvalds else { 1526a1d94aa5SRandy Dunlap save_struct_actual($param); 1527*ed8348e2SMauro Carvalho Chehab push_parameter($param, $type, $arg, $file, $declaration_name); 15281da177e4SLinus Torvalds } 15291da177e4SLinus Torvalds } 15301da177e4SLinus Torvalds } 15311da177e4SLinus Torvalds } 15321da177e4SLinus Torvalds} 15331da177e4SLinus Torvalds 1534*ed8348e2SMauro Carvalho Chehabsub push_parameter($$$$$) { 15351da177e4SLinus Torvalds my $param = shift; 15361da177e4SLinus Torvalds my $type = shift; 1537*ed8348e2SMauro Carvalho Chehab my $org_arg = shift; 15381da177e4SLinus Torvalds my $file = shift; 1539151c468bSMauro Carvalho Chehab my $declaration_name = shift; 15401da177e4SLinus Torvalds 15415f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 15425f8c7c98SRandy Dunlap ($param eq "}")) { 15435f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 15445f8c7c98SRandy Dunlap } 15455f8c7c98SRandy Dunlap 15465f8c7c98SRandy Dunlap $anon_struct_union = 0; 1547f9b5c530SMauro Carvalho Chehab $param =~ s/[\[\)].*//; 15481da177e4SLinus Torvalds 1549a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 15501da177e4SLinus Torvalds { 1551c950a173SSilvio Fricke if (!$param =~ /\w\.\.\.$/) { 1552c950a173SSilvio Fricke # handles unnamed variable parameters 1553ef00028bSJonathan Corbet $param = "..."; 1554c950a173SSilvio Fricke } 155543756e34SJonathan Neuschäfer elsif ($param =~ /\w\.\.\.$/) { 155643756e34SJonathan Neuschäfer # for named variable parameters of the form `x...`, remove the dots 155743756e34SJonathan Neuschäfer $param =~ s/\.\.\.$//; 155843756e34SJonathan Neuschäfer } 1559ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1560a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 15611da177e4SLinus Torvalds } 1562ced69090SRandy Dunlap } 15631da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 15641da177e4SLinus Torvalds { 15651da177e4SLinus Torvalds $param="void"; 15661da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 15671da177e4SLinus Torvalds } 1568134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1569134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 1570134fe01bSRandy Dunlap { 1571134fe01bSRandy Dunlap $type = $param; 1572134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 1573134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 15745f8c7c98SRandy Dunlap $anon_struct_union = 1; 1575134fe01bSRandy Dunlap } 1576134fe01bSRandy Dunlap 1577a6d3fe77SMartin Waitz # warn if parameter has no description 1578134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 1579134fe01bSRandy Dunlap # but inline preprocessor statements); 1580151c468bSMauro Carvalho Chehab # Note: It will also ignore void params and unnamed structs/unions 1581f9b5c530SMauro Carvalho Chehab if (!defined $parameterdescs{$param} && $param !~ /^#/) { 1582f9b5c530SMauro Carvalho Chehab $parameterdescs{$param} = $undescribed; 15831da177e4SLinus Torvalds 1584be5cd20cSJonathan Corbet if (show_warnings($type, $declaration_name) && $param !~ /\./) { 1585151c468bSMauro Carvalho Chehab print STDERR 1586151c468bSMauro Carvalho Chehab "${file}:$.: warning: Function parameter or member '$param' not described in '$declaration_name'\n"; 15871da177e4SLinus Torvalds ++$warnings; 15881da177e4SLinus Torvalds } 15892defb272SMauro Carvalho Chehab } 15901da177e4SLinus Torvalds 159125985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 1592e34e7dbbSRandy Dunlap # on @parameterlist; 1593e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 1594e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 1595e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 1596e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 1597e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 1598e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 1599e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 16001da177e4SLinus Torvalds push @parameterlist, $param; 1601*ed8348e2SMauro Carvalho Chehab $org_arg =~ s/\s\s+/ /g; 1602*ed8348e2SMauro Carvalho Chehab $parametertypes{$param} = $org_arg; 16031da177e4SLinus Torvalds} 16041da177e4SLinus Torvalds 16051081de2dSMauro Carvalho Chehabsub check_sections($$$$$) { 16061081de2dSMauro Carvalho Chehab my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_; 1607a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 1608a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 1609a1d94aa5SRandy Dunlap my $err; 1610a1d94aa5SRandy Dunlap my ($px, $sx); 1611a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 1612a1d94aa5SRandy Dunlap 1613a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 1614a1d94aa5SRandy Dunlap $err = 1; 1615a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 1616a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 1617a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 16181f3a6688SJohannes Berg $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 1619e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 1620e34e7dbbSRandy Dunlap # however, the original param string may contain 1621e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 1622e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 1623e34e7dbbSRandy Dunlap # parameter list is split at spaces; 1624e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 1625e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 1626e34e7dbbSRandy Dunlap 1627a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 1628a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 1629a1d94aa5SRandy Dunlap $err = 0; 1630a1d94aa5SRandy Dunlap last; 1631a1d94aa5SRandy Dunlap } 1632a1d94aa5SRandy Dunlap } 1633a1d94aa5SRandy Dunlap if ($err) { 1634a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 1635d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 1636a1d94aa5SRandy Dunlap "Excess function parameter " . 1637a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 1638a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 1639a1d94aa5SRandy Dunlap ++$warnings; 1640a1d94aa5SRandy Dunlap } 1641a1d94aa5SRandy Dunlap } 1642a1d94aa5SRandy Dunlap } 1643a1d94aa5SRandy Dunlap} 1644a1d94aa5SRandy Dunlap 16451da177e4SLinus Torvalds## 16464092bac7SYacine Belkadi# Checks the section describing the return value of a function. 16474092bac7SYacine Belkadisub check_return_section { 16484092bac7SYacine Belkadi my $file = shift; 16494092bac7SYacine Belkadi my $declaration_name = shift; 16504092bac7SYacine Belkadi my $return_type = shift; 16514092bac7SYacine Belkadi 16524092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 16534092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 16544092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 16554092bac7SYacine Belkadi return; 16564092bac7SYacine Belkadi } 16574092bac7SYacine Belkadi 16584092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 16594092bac7SYacine Belkadi $sections{$section_return} eq "") { 1660d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 16614092bac7SYacine Belkadi "No description found for return value of " . 16624092bac7SYacine Belkadi "'$declaration_name'\n"; 16634092bac7SYacine Belkadi ++$warnings; 16644092bac7SYacine Belkadi } 16654092bac7SYacine Belkadi} 16664092bac7SYacine Belkadi 16674092bac7SYacine Belkadi## 16681da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 16691da177e4SLinus Torvalds# processed and spits out all the details stored in the global 16701da177e4SLinus Torvalds# arrays/hashes. 16711da177e4SLinus Torvaldssub dump_function($$) { 16721da177e4SLinus Torvalds my $prototype = shift; 16731da177e4SLinus Torvalds my $file = shift; 1674cbb4d3e6SHoria Geanta my $noret = 0; 16751da177e4SLinus Torvalds 16765eb6b4b3SMauro Carvalho Chehab print_lineno($.); 16775eb6b4b3SMauro Carvalho Chehab 16781da177e4SLinus Torvalds $prototype =~ s/^static +//; 16791da177e4SLinus Torvalds $prototype =~ s/^extern +//; 16804dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 16811da177e4SLinus Torvalds $prototype =~ s/^inline +//; 16821da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 168332e79401SRandy Dunlap $prototype =~ s/^__inline +//; 168432e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 168532e79401SRandy Dunlap $prototype =~ s/^noinline +//; 168674fc5c65SRandy Dunlap $prototype =~ s/__init +//; 168720072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 1688270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 168970c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 16900df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 16910891f959SMatthew Wilcox $prototype =~ s/__sched +//; 169295e760cbSRandy Dunlap $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//; 1693cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 1694b1aaa546SPaolo Bonzini $prototype =~ s/__attribute__\s*\(\( 1695b1aaa546SPaolo Bonzini (?: 1696b1aaa546SPaolo Bonzini [\w\s]++ # attribute name 1697b1aaa546SPaolo Bonzini (?:\([^)]*+\))? # attribute arguments 1698b1aaa546SPaolo Bonzini \s*+,? # optional comma at the end 1699b1aaa546SPaolo Bonzini )+ 1700b1aaa546SPaolo Bonzini \)\)\s+//x; 17011da177e4SLinus Torvalds 17021da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 17031da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 17041da177e4SLinus Torvalds # 2. Function name 17051da177e4SLinus Torvalds # 3. Function parameters. 17061da177e4SLinus Torvalds # 17071da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 17081da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 17091da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 17101da177e4SLinus Torvalds # so on. 17111da177e4SLinus Torvalds # 17121da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 17131da177e4SLinus Torvalds # the following functions' documentation still comes out right: 17141da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 17151da177e4SLinus Torvalds # - atomic_set (macro) 17169598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 17171da177e4SLinus Torvalds 1718cbb4d3e6SHoria Geanta if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 1719cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 1720cbb4d3e6SHoria Geanta # list. 1721cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 1722cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 1723cbb4d3e6SHoria Geanta $return_type = $1; 1724cbb4d3e6SHoria Geanta $declaration_name = $2; 1725cbb4d3e6SHoria Geanta $noret = 1; 1726cbb4d3e6SHoria Geanta } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 17271da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 17285a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 17291da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 173094b3e03cSRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 17311da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 17325a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 17331da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 17341da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 17355a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 17361da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 17375a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 17381da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 17395a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 17409598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 17415a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 17425a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 17431da177e4SLinus Torvalds $return_type = $1; 17441da177e4SLinus Torvalds $declaration_name = $2; 17451da177e4SLinus Torvalds my $args = $3; 17461da177e4SLinus Torvalds 1747151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 17481da177e4SLinus Torvalds } else { 1749d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 17501da177e4SLinus Torvalds return; 17511da177e4SLinus Torvalds } 17521da177e4SLinus Torvalds 1753a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 17541081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, "function", $sectcheck, $prms); 1755a1d94aa5SRandy Dunlap 17564092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 17574092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 17584092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 17594092bac7SYacine Belkadi # verbose mode. 17604092bac7SYacine Belkadi # TODO: always perform the check. 1761cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 17624092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 17634092bac7SYacine Belkadi } 17644092bac7SYacine Belkadi 176547bcacfdSMauro Carvalho Chehab # The function parser can be called with a typedef parameter. 176647bcacfdSMauro Carvalho Chehab # Handle it. 176747bcacfdSMauro Carvalho Chehab if ($return_type =~ /typedef/) { 176847bcacfdSMauro Carvalho Chehab output_declaration($declaration_name, 176947bcacfdSMauro Carvalho Chehab 'function', 177047bcacfdSMauro Carvalho Chehab {'function' => $declaration_name, 177147bcacfdSMauro Carvalho Chehab 'typedef' => 1, 177247bcacfdSMauro Carvalho Chehab 'module' => $modulename, 177347bcacfdSMauro Carvalho Chehab 'functiontype' => $return_type, 177447bcacfdSMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 177547bcacfdSMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 177647bcacfdSMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 177747bcacfdSMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 177847bcacfdSMauro Carvalho Chehab 'sections' => \%sections, 177947bcacfdSMauro Carvalho Chehab 'purpose' => $declaration_purpose 178047bcacfdSMauro Carvalho Chehab }); 178147bcacfdSMauro Carvalho Chehab } else { 17821da177e4SLinus Torvalds output_declaration($declaration_name, 17831da177e4SLinus Torvalds 'function', 17841da177e4SLinus Torvalds {'function' => $declaration_name, 17851da177e4SLinus Torvalds 'module' => $modulename, 17861da177e4SLinus Torvalds 'functiontype' => $return_type, 17871da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 17881da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 17891da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 17901da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 17911da177e4SLinus Torvalds 'sections' => \%sections, 17921da177e4SLinus Torvalds 'purpose' => $declaration_purpose 17931da177e4SLinus Torvalds }); 17941da177e4SLinus Torvalds } 179547bcacfdSMauro Carvalho Chehab} 17961da177e4SLinus Torvalds 17971da177e4SLinus Torvaldssub reset_state { 17981da177e4SLinus Torvalds $function = ""; 17991da177e4SLinus Torvalds %parameterdescs = (); 18001da177e4SLinus Torvalds %parametertypes = (); 18011da177e4SLinus Torvalds @parameterlist = (); 18021da177e4SLinus Torvalds %sections = (); 18031da177e4SLinus Torvalds @sectionlist = (); 1804a1d94aa5SRandy Dunlap $sectcheck = ""; 1805a1d94aa5SRandy Dunlap $struct_actual = ""; 18061da177e4SLinus Torvalds $prototype = ""; 18071da177e4SLinus Torvalds 180848af606aSJani Nikula $state = STATE_NORMAL; 180948af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 18101da177e4SLinus Torvalds} 18111da177e4SLinus Torvalds 181256afb0f8SJason Baronsub tracepoint_munge($) { 181356afb0f8SJason Baron my $file = shift; 181456afb0f8SJason Baron my $tracepointname = 0; 181556afb0f8SJason Baron my $tracepointargs = 0; 181656afb0f8SJason Baron 181756afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 181856afb0f8SJason Baron $tracepointname = $1; 181956afb0f8SJason Baron } 18203a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 18213a9089fdSJason Baron $tracepointname = $1; 18223a9089fdSJason Baron } 18233a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 18243a9089fdSJason Baron $tracepointname = $2; 18253a9089fdSJason Baron } 18263a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 182756afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 182856afb0f8SJason Baron $tracepointargs = $1; 182956afb0f8SJason Baron } 183056afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 1831d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 183256afb0f8SJason Baron "$prototype\n"; 183356afb0f8SJason Baron } else { 183456afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 183556afb0f8SJason Baron } 183656afb0f8SJason Baron} 183756afb0f8SJason Baron 1838b4870bc5SRandy Dunlapsub syscall_munge() { 1839b4870bc5SRandy Dunlap my $void = 0; 1840b4870bc5SRandy Dunlap 18417c9aa015SMauro Carvalho Chehab $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's 1842b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 1843b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 1844b4870bc5SRandy Dunlap $void = 1; 1845b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 1846b4870bc5SRandy Dunlap } 1847b4870bc5SRandy Dunlap 1848b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 1849b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 1850b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 1851b4870bc5SRandy Dunlap } elsif ($void) { 1852b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 1853b4870bc5SRandy Dunlap } 1854b4870bc5SRandy Dunlap 1855b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 1856b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 1857b4870bc5SRandy Dunlap my $count = 0; 1858b4870bc5SRandy Dunlap my $len = length($prototype); 1859b4870bc5SRandy Dunlap if ($void) { 1860b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 1861b4870bc5SRandy Dunlap } 1862b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 1863b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 1864b4870bc5SRandy Dunlap $count++; 1865b4870bc5SRandy Dunlap if ($count % 2 == 1) { 1866b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 1867b4870bc5SRandy Dunlap } 1868b4870bc5SRandy Dunlap } 1869b4870bc5SRandy Dunlap } 1870b4870bc5SRandy Dunlap} 1871b4870bc5SRandy Dunlap 1872b7afa92bSDaniel Vettersub process_proto_function($$) { 18731da177e4SLinus Torvalds my $x = shift; 18741da177e4SLinus Torvalds my $file = shift; 18751da177e4SLinus Torvalds 187651f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 187751f5a0c8SRandy Dunlap 1878890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 18791da177e4SLinus Torvalds # do nothing 18801da177e4SLinus Torvalds } 18811da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 18821da177e4SLinus Torvalds $prototype .= $1; 18831da177e4SLinus Torvalds } 1884b4870bc5SRandy Dunlap 1885890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 18861da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 18871da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 18881da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 18897ae281b0SMauro Carvalho Chehab 18907ae281b0SMauro Carvalho Chehab # Handle prototypes for function pointers like: 18917ae281b0SMauro Carvalho Chehab # int (*pcs_config)(struct foo) 18927ae281b0SMauro Carvalho Chehab $prototype =~ s@^(\S+\s+)\(\s*\*(\S+)\)@$1$2@gos; 18937ae281b0SMauro Carvalho Chehab 1894b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 1895b4870bc5SRandy Dunlap syscall_munge(); 1896b4870bc5SRandy Dunlap } 18973a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 18983a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 18993a9089fdSJason Baron { 190056afb0f8SJason Baron tracepoint_munge($file); 190156afb0f8SJason Baron } 19021da177e4SLinus Torvalds dump_function($prototype, $file); 19031da177e4SLinus Torvalds reset_state(); 19041da177e4SLinus Torvalds } 19051da177e4SLinus Torvalds} 19061da177e4SLinus Torvalds 1907b7afa92bSDaniel Vettersub process_proto_type($$) { 19081da177e4SLinus Torvalds my $x = shift; 19091da177e4SLinus Torvalds my $file = shift; 19101da177e4SLinus Torvalds 19111da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 19121da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 19131da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 191451f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 191551f5a0c8SRandy Dunlap 19161da177e4SLinus Torvalds if ($x =~ /^#/) { 19171da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 19181da177e4SLinus Torvalds $x .= ";"; 19191da177e4SLinus Torvalds } 19201da177e4SLinus Torvalds 19211da177e4SLinus Torvalds while (1) { 1922673bb2dfSBen Hutchings if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) { 1923463a0fdcSMarkus Heiser if( length $prototype ) { 1924463a0fdcSMarkus Heiser $prototype .= " " 1925463a0fdcSMarkus Heiser } 19261da177e4SLinus Torvalds $prototype .= $1 . $2; 19271da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 19281da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 19291da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 19301da177e4SLinus Torvalds dump_declaration($prototype, $file); 19311da177e4SLinus Torvalds reset_state(); 19321da177e4SLinus Torvalds last; 19331da177e4SLinus Torvalds } 19341da177e4SLinus Torvalds $x = $3; 19351da177e4SLinus Torvalds } else { 19361da177e4SLinus Torvalds $prototype .= $x; 19371da177e4SLinus Torvalds last; 19381da177e4SLinus Torvalds } 19391da177e4SLinus Torvalds } 19401da177e4SLinus Torvalds} 19411da177e4SLinus Torvalds 19426b5b55f6SRandy Dunlap 19431ad560e4SJani Nikulasub map_filename($) { 19441ad560e4SJani Nikula my $file; 19451ad560e4SJani Nikula my ($orig_file) = @_; 19461ad560e4SJani Nikula 19471ad560e4SJani Nikula if (defined($ENV{'SRCTREE'})) { 19481ad560e4SJani Nikula $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 19491ad560e4SJani Nikula } else { 19501ad560e4SJani Nikula $file = $orig_file; 19511ad560e4SJani Nikula } 19521ad560e4SJani Nikula 19531ad560e4SJani Nikula if (defined($source_map{$file})) { 19541ad560e4SJani Nikula $file = $source_map{$file}; 19551ad560e4SJani Nikula } 19561ad560e4SJani Nikula 19571ad560e4SJani Nikula return $file; 19581ad560e4SJani Nikula} 19591ad560e4SJani Nikula 196088c2b57dSJani Nikulasub process_export_file($) { 196188c2b57dSJani Nikula my ($orig_file) = @_; 196288c2b57dSJani Nikula my $file = map_filename($orig_file); 196388c2b57dSJani Nikula 196488c2b57dSJani Nikula if (!open(IN,"<$file")) { 196588c2b57dSJani Nikula print STDERR "Error: Cannot open file $file\n"; 196688c2b57dSJani Nikula ++$errors; 196788c2b57dSJani Nikula return; 196888c2b57dSJani Nikula } 196988c2b57dSJani Nikula 197088c2b57dSJani Nikula while (<IN>) { 197188c2b57dSJani Nikula if (/$export_symbol/) { 1972eab795ddSMauro Carvalho Chehab next if (defined($nosymbol_table{$2})); 197388c2b57dSJani Nikula $function_table{$2} = 1; 197488c2b57dSJani Nikula } 197588c2b57dSJani Nikula } 197688c2b57dSJani Nikula 197788c2b57dSJani Nikula close(IN); 197888c2b57dSJani Nikula} 197988c2b57dSJani Nikula 198007048d13SJonathan Corbet# 198107048d13SJonathan Corbet# Parsers for the various processing states. 198207048d13SJonathan Corbet# 198307048d13SJonathan Corbet# STATE_NORMAL: looking for the /** to begin everything. 198407048d13SJonathan Corbet# 198507048d13SJonathan Corbetsub process_normal() { 19861da177e4SLinus Torvalds if (/$doc_start/o) { 198748af606aSJani Nikula $state = STATE_NAME; # next line is always the function name 1988850622dfSRandy Dunlap $in_doc_sect = 0; 19890b0f5f29SDaniel Vetter $declaration_start_line = $. + 1; 19901da177e4SLinus Torvalds } 199107048d13SJonathan Corbet} 199207048d13SJonathan Corbet 19933cac2bc4SJonathan Corbet# 19943cac2bc4SJonathan Corbet# STATE_NAME: Looking for the "name - description" line 19953cac2bc4SJonathan Corbet# 19963cac2bc4SJonathan Corbetsub process_name($$) { 19973cac2bc4SJonathan Corbet my $file = shift; 19981da177e4SLinus Torvalds my $identifier; 19991da177e4SLinus Torvalds my $descr; 20001da177e4SLinus Torvalds 20011da177e4SLinus Torvalds if (/$doc_block/o) { 200248af606aSJani Nikula $state = STATE_DOCBLOCK; 20031da177e4SLinus Torvalds $contents = ""; 20040b0f5f29SDaniel Vetter $new_start_line = $. + 1; 20050b0f5f29SDaniel Vetter 20061da177e4SLinus Torvalds if ( $1 eq "" ) { 20071da177e4SLinus Torvalds $section = $section_intro; 20081da177e4SLinus Torvalds } else { 20091da177e4SLinus Torvalds $section = $1; 20101da177e4SLinus Torvalds } 20111da177e4SLinus Torvalds } 20121da177e4SLinus Torvalds elsif (/$doc_decl/o) { 20131da177e4SLinus Torvalds $identifier = $1; 2014a8dae20bSMike Rapoport if (/\s*([\w\s]+?)(\(\))?\s*-/) { 20151da177e4SLinus Torvalds $identifier = $1; 20161da177e4SLinus Torvalds } 20171da177e4SLinus Torvalds 201817b78717SJonathan Corbet $state = STATE_BODY; 20190b0f5f29SDaniel Vetter # if there's no @param blocks need to set up default section 20200b0f5f29SDaniel Vetter # here 20212f4ad40aSJani Nikula $contents = ""; 20222f4ad40aSJani Nikula $section = $section_default; 20230b0f5f29SDaniel Vetter $new_start_line = $. + 1; 20241da177e4SLinus Torvalds if (/-(.*)/) { 202551f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2026a21217daSRandy Dunlap $descr= $1; 2027a21217daSRandy Dunlap $descr =~ s/^\s*//; 2028a21217daSRandy Dunlap $descr =~ s/\s*$//; 202912ae6779SDaniel Santos $descr =~ s/\s+/ /g; 20300bba924cSJonathan Corbet $declaration_purpose = $descr; 203117b78717SJonathan Corbet $state = STATE_BODY_MAYBE; 20321da177e4SLinus Torvalds } else { 20331da177e4SLinus Torvalds $declaration_purpose = ""; 20341da177e4SLinus Torvalds } 203577cc23b8SRandy Dunlap 203677cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 2037d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 203877cc23b8SRandy Dunlap print STDERR $_; 203977cc23b8SRandy Dunlap ++$warnings; 204077cc23b8SRandy Dunlap } 204177cc23b8SRandy Dunlap 2042cf419d54SRandy Dunlap if ($identifier =~ m/^struct\b/) { 20431da177e4SLinus Torvalds $decl_type = 'struct'; 2044cf419d54SRandy Dunlap } elsif ($identifier =~ m/^union\b/) { 20451da177e4SLinus Torvalds $decl_type = 'union'; 2046cf419d54SRandy Dunlap } elsif ($identifier =~ m/^enum\b/) { 20471da177e4SLinus Torvalds $decl_type = 'enum'; 2048cf419d54SRandy Dunlap } elsif ($identifier =~ m/^typedef\b/) { 20491da177e4SLinus Torvalds $decl_type = 'typedef'; 20501da177e4SLinus Torvalds } else { 20511da177e4SLinus Torvalds $decl_type = 'function'; 20521da177e4SLinus Torvalds } 20531da177e4SLinus Torvalds 20541da177e4SLinus Torvalds if ($verbose) { 2055d40e1e65SBart Van Assche print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; 20561da177e4SLinus Torvalds } 20571da177e4SLinus Torvalds } else { 2058d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 20591da177e4SLinus Torvalds " - I thought it was a doc line\n"; 20601da177e4SLinus Torvalds ++$warnings; 206148af606aSJani Nikula $state = STATE_NORMAL; 20621da177e4SLinus Torvalds } 20633cac2bc4SJonathan Corbet} 20643cac2bc4SJonathan Corbet 20653cac2bc4SJonathan Corbet 2066d742f24dSJonathan Corbet# 2067d742f24dSJonathan Corbet# STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment. 2068d742f24dSJonathan Corbet# 2069d742f24dSJonathan Corbetsub process_body($$) { 2070d742f24dSJonathan Corbet my $file = shift; 20713cac2bc4SJonathan Corbet 207243756e34SJonathan Neuschäfer # Until all named variable macro parameters are 207343756e34SJonathan Neuschäfer # documented using the bare name (`x`) rather than with 207443756e34SJonathan Neuschäfer # dots (`x...`), strip the dots: 207543756e34SJonathan Neuschäfer if ($section =~ /\w\.\.\.$/) { 207643756e34SJonathan Neuschäfer $section =~ s/\.\.\.$//; 207743756e34SJonathan Neuschäfer 207843756e34SJonathan Neuschäfer if ($verbose) { 207943756e34SJonathan Neuschäfer print STDERR "${file}:$.: warning: Variable macro arguments should be documented without dots\n"; 208043756e34SJonathan Neuschäfer ++$warnings; 208143756e34SJonathan Neuschäfer } 208243756e34SJonathan Neuschäfer } 208343756e34SJonathan Neuschäfer 20840d55d48bSMauro Carvalho Chehab if ($state == STATE_BODY_WITH_BLANK_LINE && /^\s*\*\s?\S/) { 20850d55d48bSMauro Carvalho Chehab dump_section($file, $section, $contents); 20860d55d48bSMauro Carvalho Chehab $section = $section_default; 20870d55d48bSMauro Carvalho Chehab $contents = ""; 20880d55d48bSMauro Carvalho Chehab } 20890d55d48bSMauro Carvalho Chehab 2090f624adefSJani Nikula if (/$doc_sect/i) { # case insensitive for supported section names 20911da177e4SLinus Torvalds $newsection = $1; 20921da177e4SLinus Torvalds $newcontents = $2; 20931da177e4SLinus Torvalds 2094f624adefSJani Nikula # map the supported section names to the canonical names 2095f624adefSJani Nikula if ($newsection =~ m/^description$/i) { 2096f624adefSJani Nikula $newsection = $section_default; 2097f624adefSJani Nikula } elsif ($newsection =~ m/^context$/i) { 2098f624adefSJani Nikula $newsection = $section_context; 2099f624adefSJani Nikula } elsif ($newsection =~ m/^returns?$/i) { 2100f624adefSJani Nikula $newsection = $section_return; 2101f624adefSJani Nikula } elsif ($newsection =~ m/^\@return$/) { 2102f624adefSJani Nikula # special: @return is a section, not a param description 2103f624adefSJani Nikula $newsection = $section_return; 2104f624adefSJani Nikula } 2105f624adefSJani Nikula 2106792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 2107850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 2108d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: contents before sections\n"; 2109850622dfSRandy Dunlap ++$warnings; 2110850622dfSRandy Dunlap } 21110bba924cSJonathan Corbet dump_section($file, $section, $contents); 21121da177e4SLinus Torvalds $section = $section_default; 21131da177e4SLinus Torvalds } 21141da177e4SLinus Torvalds 2115850622dfSRandy Dunlap $in_doc_sect = 1; 211617b78717SJonathan Corbet $state = STATE_BODY; 21171da177e4SLinus Torvalds $contents = $newcontents; 21180b0f5f29SDaniel Vetter $new_start_line = $.; 21197c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 212005189497SRandy Dunlap $contents = substr($contents, 1); 212105189497SRandy Dunlap } 21220a726301SJani Nikula if ($contents ne "") { 21231da177e4SLinus Torvalds $contents .= "\n"; 21241da177e4SLinus Torvalds } 21251da177e4SLinus Torvalds $section = $newsection; 2126b7886de4SJani Nikula $leading_space = undef; 21271da177e4SLinus Torvalds } elsif (/$doc_end/) { 21284c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 21290bba924cSJonathan Corbet dump_section($file, $section, $contents); 21301da177e4SLinus Torvalds $section = $section_default; 21311da177e4SLinus Torvalds $contents = ""; 21321da177e4SLinus Torvalds } 213346b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 213446b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2135d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: suspicious ending line: $_"; 213646b958ebSRandy Dunlap ++$warnings; 213746b958ebSRandy Dunlap } 21381da177e4SLinus Torvalds 21391da177e4SLinus Torvalds $prototype = ""; 214048af606aSJani Nikula $state = STATE_PROTO; 21411da177e4SLinus Torvalds $brcount = 0; 21421da177e4SLinus Torvalds } elsif (/$doc_content/) { 21436423133bSJohannes Weiner if ($1 eq "") { 21440d55d48bSMauro Carvalho Chehab if ($section eq $section_context) { 21450bba924cSJonathan Corbet dump_section($file, $section, $contents); 21461da177e4SLinus Torvalds $section = $section_default; 21471da177e4SLinus Torvalds $contents = ""; 21480b0f5f29SDaniel Vetter $new_start_line = $.; 21490d55d48bSMauro Carvalho Chehab $state = STATE_BODY; 21501da177e4SLinus Torvalds } else { 21510d55d48bSMauro Carvalho Chehab if ($section ne $section_default) { 21520d55d48bSMauro Carvalho Chehab $state = STATE_BODY_WITH_BLANK_LINE; 21530d55d48bSMauro Carvalho Chehab } else { 21540d55d48bSMauro Carvalho Chehab $state = STATE_BODY; 21550d55d48bSMauro Carvalho Chehab } 21566423133bSJohannes Weiner $contents .= "\n"; 21576423133bSJohannes Weiner } 215817b78717SJonathan Corbet } elsif ($state == STATE_BODY_MAYBE) { 21596423133bSJohannes Weiner # Continued declaration purpose 21606423133bSJohannes Weiner chomp($declaration_purpose); 21610bba924cSJonathan Corbet $declaration_purpose .= " " . $1; 216212ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 21636423133bSJohannes Weiner } else { 2164b7886de4SJani Nikula my $cont = $1; 2165b7886de4SJani Nikula if ($section =~ m/^@/ || $section eq $section_context) { 2166b7886de4SJani Nikula if (!defined $leading_space) { 2167b7886de4SJani Nikula if ($cont =~ m/^(\s+)/) { 2168b7886de4SJani Nikula $leading_space = $1; 2169b7886de4SJani Nikula } else { 2170b7886de4SJani Nikula $leading_space = ""; 2171b7886de4SJani Nikula } 2172b7886de4SJani Nikula } 2173b7886de4SJani Nikula $cont =~ s/^$leading_space//; 2174b7886de4SJani Nikula } 2175b7886de4SJani Nikula $contents .= $cont . "\n"; 21761da177e4SLinus Torvalds } 21771da177e4SLinus Torvalds } else { 21781da177e4SLinus Torvalds # i dont know - bad line? ignore. 2179d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: bad line: $_"; 21801da177e4SLinus Torvalds ++$warnings; 21811da177e4SLinus Torvalds } 2182d742f24dSJonathan Corbet} 2183d742f24dSJonathan Corbet 2184d742f24dSJonathan Corbet 2185cc794812SJonathan Corbet# 2186cc794812SJonathan Corbet# STATE_PROTO: reading a function/whatever prototype. 2187cc794812SJonathan Corbet# 2188cc794812SJonathan Corbetsub process_proto($$) { 2189cc794812SJonathan Corbet my $file = shift; 2190cc794812SJonathan Corbet 2191cc794812SJonathan Corbet if (/$doc_inline_oneline/) { 2192cc794812SJonathan Corbet $section = $1; 2193cc794812SJonathan Corbet $contents = $2; 2194cc794812SJonathan Corbet if ($contents ne "") { 2195cc794812SJonathan Corbet $contents .= "\n"; 2196cc794812SJonathan Corbet dump_section($file, $section, $contents); 2197cc794812SJonathan Corbet $section = $section_default; 2198cc794812SJonathan Corbet $contents = ""; 2199cc794812SJonathan Corbet } 2200cc794812SJonathan Corbet } elsif (/$doc_inline_start/) { 2201cc794812SJonathan Corbet $state = STATE_INLINE; 2202cc794812SJonathan Corbet $inline_doc_state = STATE_INLINE_NAME; 2203cc794812SJonathan Corbet } elsif ($decl_type eq 'function') { 2204cc794812SJonathan Corbet process_proto_function($_, $file); 2205cc794812SJonathan Corbet } else { 2206cc794812SJonathan Corbet process_proto_type($_, $file); 2207cc794812SJonathan Corbet } 2208cc794812SJonathan Corbet} 2209cc794812SJonathan Corbet 2210c17add56SJonathan Corbet# 2211c17add56SJonathan Corbet# STATE_DOCBLOCK: within a DOC: block. 2212c17add56SJonathan Corbet# 2213c17add56SJonathan Corbetsub process_docblock($$) { 2214c17add56SJonathan Corbet my $file = shift; 2215cc794812SJonathan Corbet 2216c17add56SJonathan Corbet if (/$doc_end/) { 2217c17add56SJonathan Corbet dump_doc_section($file, $section, $contents); 2218c17add56SJonathan Corbet $section = $section_default; 2219c17add56SJonathan Corbet $contents = ""; 2220c17add56SJonathan Corbet $function = ""; 2221c17add56SJonathan Corbet %parameterdescs = (); 2222c17add56SJonathan Corbet %parametertypes = (); 2223c17add56SJonathan Corbet @parameterlist = (); 2224c17add56SJonathan Corbet %sections = (); 2225c17add56SJonathan Corbet @sectionlist = (); 2226c17add56SJonathan Corbet $prototype = ""; 2227c17add56SJonathan Corbet $state = STATE_NORMAL; 2228c17add56SJonathan Corbet } elsif (/$doc_content/) { 2229c17add56SJonathan Corbet if ( $1 eq "" ) { 2230c17add56SJonathan Corbet $contents .= $blankline; 2231c17add56SJonathan Corbet } else { 2232c17add56SJonathan Corbet $contents .= $1 . "\n"; 2233c17add56SJonathan Corbet } 2234c17add56SJonathan Corbet } 2235d742f24dSJonathan Corbet} 2236d742f24dSJonathan Corbet 2237c17add56SJonathan Corbet# 2238c17add56SJonathan Corbet# STATE_INLINE: docbook comments within a prototype. 2239c17add56SJonathan Corbet# 2240c17add56SJonathan Corbetsub process_inline($$) { 2241c17add56SJonathan Corbet my $file = shift; 2242d742f24dSJonathan Corbet 2243a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 224448af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 2245a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 2246a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 22470b0f5f29SDaniel Vetter $new_start_line = $.; 2248a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 22497c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 2250a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 2251a4c6ebedSDanilo Cesar Lemes de Paula } 2252a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 2253a4c6ebedSDanilo Cesar Lemes de Paula } 225448af606aSJani Nikula $inline_doc_state = STATE_INLINE_TEXT; 2255a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 225648af606aSJani Nikula } elsif (/$doc_inline_end/) { 2257a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 22580bba924cSJonathan Corbet dump_section($file, $section, $contents); 2259a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 2260a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 2261a4c6ebedSDanilo Cesar Lemes de Paula } 226248af606aSJani Nikula $state = STATE_PROTO; 226348af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 2264a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 2265a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 226648af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_TEXT) { 2267a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 22686450c895SJani Nikula # nuke leading blank lines 22696450c895SJani Nikula if ($contents =~ /^\s*$/) { 22706450c895SJani Nikula $contents = ""; 22716450c895SJani Nikula } 227248af606aSJani Nikula } elsif ($inline_doc_state == STATE_INLINE_NAME) { 227348af606aSJani Nikula $inline_doc_state = STATE_INLINE_ERROR; 2274e7ca311eSDaniel Vetter print STDERR "${file}:$.: warning: "; 2275a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Incorrect use of kernel-doc format: $_"; 2276a4c6ebedSDanilo Cesar Lemes de Paula ++$warnings; 2277a4c6ebedSDanilo Cesar Lemes de Paula } 2278a4c6ebedSDanilo Cesar Lemes de Paula } 22790c9aa209SJani Nikula} 2280c17add56SJonathan Corbet 2281c17add56SJonathan Corbet 2282c17add56SJonathan Corbetsub process_file($) { 2283c17add56SJonathan Corbet my $file; 2284c17add56SJonathan Corbet my $initial_section_counter = $section_counter; 2285c17add56SJonathan Corbet my ($orig_file) = @_; 2286c17add56SJonathan Corbet 2287c17add56SJonathan Corbet $file = map_filename($orig_file); 2288c17add56SJonathan Corbet 2289dbe8ba00SMauro Carvalho Chehab if (!open(IN_FILE,"<$file")) { 2290c17add56SJonathan Corbet print STDERR "Error: Cannot open file $file\n"; 2291c17add56SJonathan Corbet ++$errors; 2292c17add56SJonathan Corbet return; 22931da177e4SLinus Torvalds } 2294c17add56SJonathan Corbet 2295c17add56SJonathan Corbet $. = 1; 2296c17add56SJonathan Corbet 2297c17add56SJonathan Corbet $section_counter = 0; 2298dbe8ba00SMauro Carvalho Chehab while (<IN_FILE>) { 2299c17add56SJonathan Corbet while (s/\\\s*$//) { 2300dbe8ba00SMauro Carvalho Chehab $_ .= <IN_FILE>; 2301c17add56SJonathan Corbet } 2302c17add56SJonathan Corbet # Replace tabs by spaces 2303c17add56SJonathan Corbet while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; 2304c17add56SJonathan Corbet # Hand this line to the appropriate state handler 2305c17add56SJonathan Corbet if ($state == STATE_NORMAL) { 2306c17add56SJonathan Corbet process_normal(); 2307c17add56SJonathan Corbet } elsif ($state == STATE_NAME) { 2308c17add56SJonathan Corbet process_name($file, $_); 23090d55d48bSMauro Carvalho Chehab } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE || 23100d55d48bSMauro Carvalho Chehab $state == STATE_BODY_WITH_BLANK_LINE) { 2311c17add56SJonathan Corbet process_body($file, $_); 2312c17add56SJonathan Corbet } elsif ($state == STATE_INLINE) { # scanning for inline parameters 2313c17add56SJonathan Corbet process_inline($file, $_); 2314cc794812SJonathan Corbet } elsif ($state == STATE_PROTO) { 2315cc794812SJonathan Corbet process_proto($file, $_); 231648af606aSJani Nikula } elsif ($state == STATE_DOCBLOCK) { 2317c17add56SJonathan Corbet process_docblock($file, $_); 23181da177e4SLinus Torvalds } 23191da177e4SLinus Torvalds } 2320c17add56SJonathan Corbet 2321c17add56SJonathan Corbet # Make sure we got something interesting. 2322b0d60bfbSJonathan Corbet if ($initial_section_counter == $section_counter && $ 2323b0d60bfbSJonathan Corbet output_mode ne "none") { 2324b0d60bfbSJonathan Corbet if ($output_selection == OUTPUT_INCLUDE) { 2325b0d60bfbSJonathan Corbet print STDERR "${file}:1: warning: '$_' not found\n" 2326b0d60bfbSJonathan Corbet for keys %function_table; 23273a025e1dSMatthew Wilcox } 2328b0d60bfbSJonathan Corbet else { 2329b0d60bfbSJonathan Corbet print STDERR "${file}:1: warning: no structured comments found\n"; 2330e946c43aSJohannes Berg } 23311da177e4SLinus Torvalds } 2332dbe8ba00SMauro Carvalho Chehab close IN_FILE; 23331da177e4SLinus Torvalds} 23348484baaaSRandy Dunlap 23358484baaaSRandy Dunlap 2336efa44475SMauro Carvalho Chehab$sphinx_major = get_sphinx_version(); 23378484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 23388484baaaSRandy Dunlap 23398484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 23408484baaaSRandy Dunlap# using the s// operator. 23411ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 23424d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 23434d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 23444d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 23454d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 23468484baaaSRandy Dunlap} 23478484baaaSRandy Dunlap 23488484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 23498484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 23508484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 23518484baaaSRandy Dunlap my ($relname, $absname); 23528484baaaSRandy Dunlap while(<SOURCE_MAP>) { 23538484baaaSRandy Dunlap chop(); 23548484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 23558484baaaSRandy Dunlap $relname =~ s:^/+::; 23568484baaaSRandy Dunlap $source_map{$relname} = $absname; 23578484baaaSRandy Dunlap } 23588484baaaSRandy Dunlap close(SOURCE_MAP); 23598484baaaSRandy Dunlap} 23608484baaaSRandy Dunlap 236188c2b57dSJani Nikulaif ($output_selection == OUTPUT_EXPORTED || 236288c2b57dSJani Nikula $output_selection == OUTPUT_INTERNAL) { 2363c9b2cfb3SJani Nikula 2364c9b2cfb3SJani Nikula push(@export_file_list, @ARGV); 2365c9b2cfb3SJani Nikula 236688c2b57dSJani Nikula foreach (@export_file_list) { 236788c2b57dSJani Nikula chomp; 236888c2b57dSJani Nikula process_export_file($_); 236988c2b57dSJani Nikula } 237088c2b57dSJani Nikula} 237188c2b57dSJani Nikula 23728484baaaSRandy Dunlapforeach (@ARGV) { 23738484baaaSRandy Dunlap chomp; 23748484baaaSRandy Dunlap process_file($_); 23758484baaaSRandy Dunlap} 23768484baaaSRandy Dunlapif ($verbose && $errors) { 23778484baaaSRandy Dunlap print STDERR "$errors errors\n"; 23788484baaaSRandy Dunlap} 23798484baaaSRandy Dunlapif ($verbose && $warnings) { 23808484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 23818484baaaSRandy Dunlap} 23828484baaaSRandy Dunlap 23832c12c810SPierre-Louis Bossartif ($Werror && $warnings) { 23842c12c810SPierre-Louis Bossart print STDERR "$warnings warnings as Errors\n"; 23852c12c810SPierre-Louis Bossart exit($warnings); 23862c12c810SPierre-Louis Bossart} else { 23872c12c810SPierre-Louis Bossart exit($output_mode eq "none" ? 0 : $errors) 23882c12c810SPierre-Louis Bossart} 2389