1cb77f0d6SKamil Rytarowski#!/usr/bin/env perl 21da177e4SLinus Torvalds 3cb77f0d6SKamil Rytarowskiuse warnings; 41da177e4SLinus Torvaldsuse strict; 51da177e4SLinus Torvalds 61da177e4SLinus Torvalds## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## 71da177e4SLinus Torvalds## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## 81da177e4SLinus Torvalds## Copyright (C) 2001 Simon Huggins ## 970c95b00SRandy Dunlap## Copyright (C) 2005-2012 Randy Dunlap ## 101b40c194SDan Luedtke## Copyright (C) 2012 Dan Luedtke ## 111da177e4SLinus Torvalds## ## 121da177e4SLinus Torvalds## #define enhancements by Armin Kuster <akuster@mvista.com> ## 131da177e4SLinus Torvalds## Copyright (c) 2000 MontaVista Software, Inc. ## 141da177e4SLinus Torvalds## ## 151da177e4SLinus Torvalds## This software falls under the GNU General Public License. ## 161da177e4SLinus Torvalds## Please read the COPYING file for more information ## 171da177e4SLinus Torvalds 181da177e4SLinus Torvalds# 18/01/2001 - Cleanups 191da177e4SLinus Torvalds# Functions prototyped as foo(void) same as foo() 201da177e4SLinus Torvalds# Stop eval'ing where we don't need to. 211da177e4SLinus Torvalds# -- huggie@earth.li 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds# 27/06/2001 - Allowed whitespace after initial "/**" and 241da177e4SLinus Torvalds# allowed comments before function declarations. 251da177e4SLinus Torvalds# -- Christian Kreibich <ck@whoop.org> 261da177e4SLinus Torvalds 271da177e4SLinus Torvalds# Still to do: 281da177e4SLinus Torvalds# - add perldoc documentation 291da177e4SLinus Torvalds# - Look more closely at some of the scarier bits :) 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds# 26/05/2001 - Support for separate source and object trees. 321da177e4SLinus Torvalds# Return error code. 331da177e4SLinus Torvalds# Keith Owens <kaos@ocs.com.au> 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds# 23/09/2001 - Added support for typedefs, structs, enums and unions 361da177e4SLinus Torvalds# Support for Context section; can be terminated using empty line 371da177e4SLinus Torvalds# Small fixes (like spaces vs. \s in regex) 381da177e4SLinus Torvalds# -- Tim Jansen <tim@tjansen.de> 391da177e4SLinus Torvalds 401b40c194SDan Luedtke# 25/07/2012 - Added support for HTML5 411b40c194SDan Luedtke# -- Dan Luedtke <mail@danrl.de> 421da177e4SLinus Torvalds 43fadc0b31SJani Nikulasub usage { 44fadc0b31SJani Nikula my $message = <<"EOF"; 45fadc0b31SJani NikulaUsage: $0 [OPTION ...] FILE ... 461da177e4SLinus Torvalds 47fadc0b31SJani NikulaRead C language source or header FILEs, extract embedded documentation comments, 48fadc0b31SJani Nikulaand print formatted documentation to standard output. 491da177e4SLinus Torvalds 50fadc0b31SJani NikulaThe documentation comments are identified by "/**" opening comment mark. See 51857af3b7SMauro Carvalho ChehabDocumentation/doc-guide/kernel-doc.rst for the documentation comment syntax. 52fadc0b31SJani Nikula 53fadc0b31SJani NikulaOutput format selection (mutually exclusive): 54fadc0b31SJani Nikula -man Output troff manual page format. This is the default. 55c0d1b6eeSJonathan Corbet -rst Output reStructuredText format. 563a025e1dSMatthew Wilcox -none Do not output documentation, only warnings. 57fadc0b31SJani Nikula 58fadc0b31SJani NikulaOutput selection (mutually exclusive): 5986ae2e38SJani Nikula -export Only output documentation for symbols that have been 6086ae2e38SJani Nikula exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 61c9b2cfb3SJani Nikula in any input FILE or -export-file FILE. 6286ae2e38SJani Nikula -internal Only output documentation for symbols that have NOT been 6386ae2e38SJani Nikula exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 64c9b2cfb3SJani Nikula in any input FILE or -export-file FILE. 65fadc0b31SJani Nikula -function NAME Only output documentation for the given function(s) 66fadc0b31SJani Nikula or DOC: section title(s). All other functions and DOC: 67fadc0b31SJani Nikula sections are ignored. May be specified multiple times. 68fadc0b31SJani Nikula -nofunction NAME Do NOT output documentation for the given function(s); 69fadc0b31SJani Nikula only output documentation for the other functions and 70fadc0b31SJani Nikula DOC: sections. 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. 83fadc0b31SJani Nikula 84fadc0b31SJani NikulaEOF 85fadc0b31SJani Nikula print $message; 86fadc0b31SJani Nikula exit 1; 87fadc0b31SJani Nikula} 881da177e4SLinus Torvalds 891da177e4SLinus Torvalds# 901da177e4SLinus Torvalds# format of comments. 911da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure. 921da177e4SLinus Torvalds# (...)* signifies 0 or more structure elements 931da177e4SLinus Torvalds# /** 941da177e4SLinus Torvalds# * function_name(:)? (- short description)? 951da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)* 961da177e4SLinus Torvalds# (* a blank line)? 971da177e4SLinus Torvalds# * (Description:)? (Description of function)? 981da177e4SLinus Torvalds# * (section header: (section description)? )* 991da177e4SLinus Torvalds# (*)?*/ 1001da177e4SLinus Torvalds# 1011da177e4SLinus Torvalds# So .. the trivial example would be: 1021da177e4SLinus Torvalds# 1031da177e4SLinus Torvalds# /** 1041da177e4SLinus Torvalds# * my_function 105b9d97328SRandy Dunlap# */ 1061da177e4SLinus Torvalds# 107891dcd2fSRandy Dunlap# If the Description: header tag is omitted, then there must be a blank line 1081da177e4SLinus Torvalds# after the last parameter specification. 1091da177e4SLinus Torvalds# e.g. 1101da177e4SLinus Torvalds# /** 1111da177e4SLinus Torvalds# * my_function - does my stuff 1121da177e4SLinus Torvalds# * @my_arg: its mine damnit 1131da177e4SLinus Torvalds# * 1141da177e4SLinus Torvalds# * Does my stuff explained. 1151da177e4SLinus Torvalds# */ 1161da177e4SLinus Torvalds# 1171da177e4SLinus Torvalds# or, could also use: 1181da177e4SLinus Torvalds# /** 1191da177e4SLinus Torvalds# * my_function - does my stuff 1201da177e4SLinus Torvalds# * @my_arg: its mine damnit 1211da177e4SLinus Torvalds# * Description: Does my stuff explained. 1221da177e4SLinus Torvalds# */ 1231da177e4SLinus Torvalds# etc. 1241da177e4SLinus Torvalds# 125b9d97328SRandy Dunlap# Besides functions you can also write documentation for structs, unions, 1261da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name 1271da177e4SLinus Torvalds# of the declaration; the struct/union/enum/typedef must always precede 1281da177e4SLinus Torvalds# the name. Nesting of declarations is not supported. 1291da177e4SLinus Torvalds# Use the argument mechanism to document members or constants. 1301da177e4SLinus Torvalds# e.g. 1311da177e4SLinus Torvalds# /** 1321da177e4SLinus Torvalds# * struct my_struct - short description 1331da177e4SLinus Torvalds# * @a: first member 1341da177e4SLinus Torvalds# * @b: second member 1351da177e4SLinus Torvalds# * 1361da177e4SLinus Torvalds# * Longer description 1371da177e4SLinus Torvalds# */ 1381da177e4SLinus Torvalds# struct my_struct { 1391da177e4SLinus Torvalds# int a; 1401da177e4SLinus Torvalds# int b; 141aeec46b9SMartin Waitz# /* private: */ 142aeec46b9SMartin Waitz# int c; 1431da177e4SLinus Torvalds# }; 1441da177e4SLinus Torvalds# 1451da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description. 1461da177e4SLinus Torvalds# 147a4c6ebedSDanilo Cesar Lemes de Paula# For really longs structs, you can also describe arguments inside the 148a4c6ebedSDanilo Cesar Lemes de Paula# body of the struct. 149a4c6ebedSDanilo Cesar Lemes de Paula# eg. 150a4c6ebedSDanilo Cesar Lemes de Paula# /** 151a4c6ebedSDanilo Cesar Lemes de Paula# * struct my_struct - short description 152a4c6ebedSDanilo Cesar Lemes de Paula# * @a: first member 153a4c6ebedSDanilo Cesar Lemes de Paula# * @b: second member 154a4c6ebedSDanilo Cesar Lemes de Paula# * 155a4c6ebedSDanilo Cesar Lemes de Paula# * Longer description 156a4c6ebedSDanilo Cesar Lemes de Paula# */ 157a4c6ebedSDanilo Cesar Lemes de Paula# struct my_struct { 158a4c6ebedSDanilo Cesar Lemes de Paula# int a; 159a4c6ebedSDanilo Cesar Lemes de Paula# int b; 160a4c6ebedSDanilo Cesar Lemes de Paula# /** 161a4c6ebedSDanilo Cesar Lemes de Paula# * @c: This is longer description of C 162a4c6ebedSDanilo Cesar Lemes de Paula# * 163a4c6ebedSDanilo Cesar Lemes de Paula# * You can use paragraphs to describe arguments 164a4c6ebedSDanilo Cesar Lemes de Paula# * using this method. 165a4c6ebedSDanilo Cesar Lemes de Paula# */ 166a4c6ebedSDanilo Cesar Lemes de Paula# int c; 167a4c6ebedSDanilo Cesar Lemes de Paula# }; 168a4c6ebedSDanilo Cesar Lemes de Paula# 169a4c6ebedSDanilo Cesar Lemes de Paula# This should be use only for struct/enum members. 170a4c6ebedSDanilo Cesar Lemes de Paula# 1711da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you 1721da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions 1731da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an 1741da177e4SLinus Torvalds# empty line. 1754092bac7SYacine Belkadi# A non-void function should have a "Return:" section describing the return 1764092bac7SYacine Belkadi# value(s). 1771da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked 1781da177e4SLinus Torvalds# appropriately in DocBook. 1791da177e4SLinus Torvalds# 1801da177e4SLinus Torvalds# Example: 1811da177e4SLinus Torvalds# /** 1821da177e4SLinus Torvalds# * user_function - function that can only be called in user context 1831da177e4SLinus Torvalds# * @a: some argument 1841da177e4SLinus Torvalds# * Context: !in_interrupt() 1851da177e4SLinus Torvalds# * 1861da177e4SLinus Torvalds# * Some description 1871da177e4SLinus Torvalds# * Example: 1881da177e4SLinus Torvalds# * user_function(22); 1891da177e4SLinus Torvalds# */ 1901da177e4SLinus Torvalds# ... 1911da177e4SLinus Torvalds# 1921da177e4SLinus Torvalds# 1931da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special 1941da177e4SLinus Torvalds# patterns, which are highlighted appropriately. 1951da177e4SLinus Torvalds# 1961da177e4SLinus Torvalds# 'funcname()' - function 1971da177e4SLinus Torvalds# '$ENVVAR' - environmental variable 1981da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct') 1995267dd35SPaolo Bonzini# '&struct_name.member' - name of a structure member 2001da177e4SLinus Torvalds# '@parameter' - name of a parameter 2011da177e4SLinus Torvalds# '%CONST' - name of a constant. 202b97f193aSMauro Carvalho Chehab# '``LITERAL``' - literal string without any spaces on it. 2031da177e4SLinus Torvalds 2048484baaaSRandy Dunlap## init lots of data 2058484baaaSRandy Dunlap 2061da177e4SLinus Torvaldsmy $errors = 0; 2071da177e4SLinus Torvaldsmy $warnings = 0; 2085f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 2091da177e4SLinus Torvalds 2101da177e4SLinus Torvalds# match expressions used to find embedded type information 211b97f193aSMauro Carvalho Chehabmy $type_constant = '\b``([^\`]+)``\b'; 212b97f193aSMauro Carvalho Chehabmy $type_constant2 = '\%([-_\w]+)'; 2131da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 2148ad72163SMauro Carvalho Chehabmy $type_param = '\@(\w*(\.\w+)*(\.\.\.)?)'; 2155219f18aSJonathan Corbetmy $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params 2161da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 217df31175bSPaolo Bonzinimy $type_enum = '\&(enum\s*([_\w]+))'; 218df31175bSPaolo Bonzinimy $type_struct = '\&(struct\s*([_\w]+))'; 219df31175bSPaolo Bonzinimy $type_typedef = '\&(typedef\s*([_\w]+))'; 220df31175bSPaolo Bonzinimy $type_union = '\&(union\s*([_\w]+))'; 2215267dd35SPaolo Bonzinimy $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; 222df31175bSPaolo Bonzinimy $type_fallback = '\&([_\w]+)'; 223f3341dcfSJani Nikulamy $type_member_func = $type_member . '\(\)'; 2241da177e4SLinus Torvalds 2251da177e4SLinus Torvalds# Output conversion substitutions. 2261da177e4SLinus Torvalds# One for each output format 2271da177e4SLinus Torvalds 2281da177e4SLinus Torvalds# these are pretty rough 2294d732701SDanilo Cesar Lemes de Paulamy @highlights_man = ( 2304d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 231b97f193aSMauro Carvalho Chehab [$type_constant2, "\$1"], 2324d732701SDanilo Cesar Lemes de Paula [$type_func, "\\\\fB\$1\\\\fP"], 233df31175bSPaolo Bonzini [$type_enum, "\\\\fI\$1\\\\fP"], 2344d732701SDanilo Cesar Lemes de Paula [$type_struct, "\\\\fI\$1\\\\fP"], 235df31175bSPaolo Bonzini [$type_typedef, "\\\\fI\$1\\\\fP"], 236df31175bSPaolo Bonzini [$type_union, "\\\\fI\$1\\\\fP"], 2375267dd35SPaolo Bonzini [$type_param, "\\\\fI\$1\\\\fP"], 238df31175bSPaolo Bonzini [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], 239df31175bSPaolo Bonzini [$type_fallback, "\\\\fI\$1\\\\fP"] 2404d732701SDanilo Cesar Lemes de Paula ); 2411da177e4SLinus Torvaldsmy $blankline_man = ""; 2421da177e4SLinus Torvalds 243c0d1b6eeSJonathan Corbet# rst-mode 244c0d1b6eeSJonathan Corbetmy @highlights_rst = ( 245c0d1b6eeSJonathan Corbet [$type_constant, "``\$1``"], 246b97f193aSMauro Carvalho Chehab [$type_constant2, "``\$1``"], 247f3341dcfSJani Nikula # Note: need to escape () to avoid func matching later 2485267dd35SPaolo Bonzini [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], 2495267dd35SPaolo Bonzini [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], 2505219f18aSJonathan Corbet [$type_fp_param, "**\$1\\\\(\\\\)**"], 251a19bce64SJani Nikula [$type_func, "\\:c\\:func\\:`\$1()`"], 252df31175bSPaolo Bonzini [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], 253df31175bSPaolo Bonzini [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], 254df31175bSPaolo Bonzini [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], 255df31175bSPaolo Bonzini [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], 256a7291e7eSJani Nikula # in rst this can refer to any type 257df31175bSPaolo Bonzini [$type_fallback, "\\:c\\:type\\:`\$1`"], 258c0d1b6eeSJonathan Corbet [$type_param, "**\$1**"] 259c0d1b6eeSJonathan Corbet ); 260c0d1b6eeSJonathan Corbetmy $blankline_rst = "\n"; 261c0d1b6eeSJonathan Corbet 2621da177e4SLinus Torvalds# read arguments 2631da177e4SLinus Torvaldsif ($#ARGV == -1) { 2641da177e4SLinus Torvalds usage(); 2651da177e4SLinus Torvalds} 2661da177e4SLinus Torvalds 2678484baaaSRandy Dunlapmy $kernelversion; 2688484baaaSRandy Dunlapmy $dohighlight = ""; 2698484baaaSRandy Dunlap 2701da177e4SLinus Torvaldsmy $verbose = 0; 271bdfe2be3SMauro Carvalho Chehabmy $output_mode = "rst"; 272e314ba31SDaniel Santosmy $output_preformatted = 0; 2734b44595aSJohannes Bergmy $no_doc_sections = 0; 2740b0f5f29SDaniel Vettermy $enable_lineno = 0; 275bdfe2be3SMauro Carvalho Chehabmy @highlights = @highlights_rst; 276bdfe2be3SMauro Carvalho Chehabmy $blankline = $blankline_rst; 2771da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 278b6c3f456SJani Nikula 279b6c3f456SJani Nikulause constant { 280b6c3f456SJani Nikula OUTPUT_ALL => 0, # output all symbols and doc sections 281b6c3f456SJani Nikula OUTPUT_INCLUDE => 1, # output only specified symbols 282b6c3f456SJani Nikula OUTPUT_EXCLUDE => 2, # output everything except specified symbols 283b6c3f456SJani Nikula OUTPUT_EXPORTED => 3, # output exported symbols 284b6c3f456SJani Nikula OUTPUT_INTERNAL => 4, # output non-exported symbols 285b6c3f456SJani Nikula}; 286b6c3f456SJani Nikulamy $output_selection = OUTPUT_ALL; 287b2c4105bSBen Hutchingsmy $show_not_found = 0; 288b2c4105bSBen Hutchings 28988c2b57dSJani Nikulamy @export_file_list; 29088c2b57dSJani Nikula 291b2c4105bSBen Hutchingsmy @build_time; 292b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 293b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 294b2c4105bSBen Hutchings @build_time = gmtime($seconds); 295b2c4105bSBen Hutchings} else { 296b2c4105bSBen Hutchings @build_time = localtime; 297b2c4105bSBen Hutchings} 298b2c4105bSBen Hutchings 2991da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 3001da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 301b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 302b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 3031da177e4SLinus Torvalds 3048484baaaSRandy Dunlap# Essentially these are globals. 305b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 306b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 3071da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 3081da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 3090b0f5f29SDaniel Vettermy $declaration_start_line; 3101da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 3111c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 3121da177e4SLinus Torvalds 313bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 314bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 315bd0e88e5SRandy Dunlap} 316bd0e88e5SRandy Dunlap 3171da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 3181da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 3191da177e4SLinus Torvalds# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 3201da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 3211da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 3221da177e4SLinus Torvalds# into html. 3231da177e4SLinus Torvaldsmy $section_counter = 0; 3241da177e4SLinus Torvalds 3251da177e4SLinus Torvaldsmy $lineprefix=""; 3261da177e4SLinus Torvalds 32748af606aSJani Nikula# Parser states 32848af606aSJani Nikulause constant { 32948af606aSJani Nikula STATE_NORMAL => 0, # normal code 33048af606aSJani Nikula STATE_NAME => 1, # looking for function name 33117b78717SJonathan Corbet STATE_BODY_MAYBE => 2, # body - or maybe more description 33217b78717SJonathan Corbet STATE_BODY => 3, # the body of the comment 33317b78717SJonathan Corbet STATE_PROTO => 4, # scanning prototype 33417b78717SJonathan Corbet STATE_DOCBLOCK => 5, # documentation block 33517b78717SJonathan Corbet STATE_INLINE => 6, # gathering documentation outside main block 33648af606aSJani Nikula}; 3371da177e4SLinus Torvaldsmy $state; 338850622dfSRandy Dunlapmy $in_doc_sect; 3391da177e4SLinus Torvalds 34048af606aSJani Nikula# Inline documentation state 34148af606aSJani Nikulause constant { 34248af606aSJani Nikula STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 34348af606aSJani Nikula STATE_INLINE_NAME => 1, # looking for member name (@foo:) 34448af606aSJani Nikula STATE_INLINE_TEXT => 2, # looking for member documentation 34548af606aSJani Nikula STATE_INLINE_END => 3, # done 34648af606aSJani Nikula STATE_INLINE_ERROR => 4, # error - Comment without header was found. 34748af606aSJani Nikula # Spit a warning as it's not 348a4c6ebedSDanilo Cesar Lemes de Paula # proper kernel-doc and ignore the rest. 34948af606aSJani Nikula}; 35048af606aSJani Nikulamy $inline_doc_state; 351a4c6ebedSDanilo Cesar Lemes de Paula 3521da177e4SLinus Torvalds#declaration types: can be 3531da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 3541da177e4SLinus Torvaldsmy $decl_type; 3551da177e4SLinus Torvalds 3561da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 3571da177e4SLinus Torvaldsmy $doc_end = '\*/'; 3581da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 35912ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 3601da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 361f624adefSJani Nikula# @params and a strictly limited set of supported section names 3628569de68SJonathan Corbetmy $doc_sect = $doc_com . 363ef00028bSJonathan Corbet '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)'; 36412ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 3651da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 36648af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$'; 36748af606aSJani Nikulamy $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)'; 36848af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$'; 3690c9aa209SJani Nikulamy $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; 37086ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 3711da177e4SLinus Torvalds 3721da177e4SLinus Torvaldsmy %parameterdescs; 3730b0f5f29SDaniel Vettermy %parameterdesc_start_lines; 3741da177e4SLinus Torvaldsmy @parameterlist; 3751da177e4SLinus Torvaldsmy %sections; 3761da177e4SLinus Torvaldsmy @sectionlist; 3770b0f5f29SDaniel Vettermy %section_start_lines; 378a1d94aa5SRandy Dunlapmy $sectcheck; 379a1d94aa5SRandy Dunlapmy $struct_actual; 3801da177e4SLinus Torvalds 3811da177e4SLinus Torvaldsmy $contents = ""; 3820b0f5f29SDaniel Vettermy $new_start_line = 0; 383f624adefSJani Nikula 384f624adefSJani Nikula# the canonical section names. see also $doc_sect above. 3851da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 3861da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 3871da177e4SLinus Torvaldsmy $section = $section_default; 3881da177e4SLinus Torvaldsmy $section_context = "Context"; 3894092bac7SYacine Belkadimy $section_return = "Return"; 3901da177e4SLinus Torvalds 3911da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 3921da177e4SLinus Torvalds 3931da177e4SLinus Torvaldsreset_state(); 3941da177e4SLinus Torvalds 395b031ac4eSMauro Carvalho Chehabwhile ($ARGV[0] =~ m/^--?(.*)/) { 396b031ac4eSMauro Carvalho Chehab my $cmd = $1; 397b031ac4eSMauro Carvalho Chehab shift @ARGV; 398b031ac4eSMauro Carvalho Chehab if ($cmd eq "man") { 3991da177e4SLinus Torvalds $output_mode = "man"; 4004d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 4011da177e4SLinus Torvalds $blankline = $blankline_man; 402b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "rst") { 403c0d1b6eeSJonathan Corbet $output_mode = "rst"; 404c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 405c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 406b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "none") { 4073a025e1dSMatthew Wilcox $output_mode = "none"; 408b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document 4091da177e4SLinus Torvalds $modulename = shift @ARGV; 410b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "function") { # to only output specific functions 411b6c3f456SJani Nikula $output_selection = OUTPUT_INCLUDE; 4121da177e4SLinus Torvalds $function = shift @ARGV; 4131da177e4SLinus Torvalds $function_table{$function} = 1; 414b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "nofunction") { # output all except specific functions 415b6c3f456SJani Nikula $output_selection = OUTPUT_EXCLUDE; 4161da177e4SLinus Torvalds $function = shift @ARGV; 4171da177e4SLinus Torvalds $function_table{$function} = 1; 418b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export") { # only exported symbols 419b6c3f456SJani Nikula $output_selection = OUTPUT_EXPORTED; 420da9726ecSJani Nikula %function_table = (); 421b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "internal") { # only non-exported symbols 422b6c3f456SJani Nikula $output_selection = OUTPUT_INTERNAL; 423da9726ecSJani Nikula %function_table = (); 424b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export-file") { 42588c2b57dSJani Nikula my $file = shift @ARGV; 42688c2b57dSJani Nikula push(@export_file_list, $file); 427b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "v") { 4281da177e4SLinus Torvalds $verbose = 1; 429b031ac4eSMauro Carvalho Chehab } elsif (($cmd eq "h") || ($cmd eq "help")) { 4301da177e4SLinus Torvalds usage(); 431b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'no-doc-sections') { 4324b44595aSJohannes Berg $no_doc_sections = 1; 433b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'enable-lineno') { 4340b0f5f29SDaniel Vetter $enable_lineno = 1; 435b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'show-not-found') { 436e946c43aSJohannes Berg $show_not_found = 1; 437b031ac4eSMauro Carvalho Chehab } else { 438b031ac4eSMauro Carvalho Chehab # Unknown argument 439b031ac4eSMauro Carvalho Chehab usage(); 4401da177e4SLinus Torvalds } 4411da177e4SLinus Torvalds} 4421da177e4SLinus Torvalds 4438484baaaSRandy Dunlap# continue execution near EOF; 4448484baaaSRandy Dunlap 44553f049faSBorislav Petkov# get kernel version from env 44653f049faSBorislav Petkovsub get_kernel_version() { 4471b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 44853f049faSBorislav Petkov 44953f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 45053f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 45153f049faSBorislav Petkov } 45253f049faSBorislav Petkov return $version; 45353f049faSBorislav Petkov} 4541da177e4SLinus Torvalds 4550b0f5f29SDaniel Vetter# 4560b0f5f29SDaniel Vettersub print_lineno { 4570b0f5f29SDaniel Vetter my $lineno = shift; 4580b0f5f29SDaniel Vetter if ($enable_lineno && defined($lineno)) { 4590b0f5f29SDaniel Vetter print "#define LINENO " . $lineno . "\n"; 4600b0f5f29SDaniel Vetter } 4610b0f5f29SDaniel Vetter} 4621da177e4SLinus Torvalds## 4631da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 4641da177e4SLinus Torvalds# 4651da177e4SLinus Torvaldssub dump_section { 46694dc7ad5SRandy Dunlap my $file = shift; 4671da177e4SLinus Torvalds my $name = shift; 4681da177e4SLinus Torvalds my $contents = join "\n", @_; 4691da177e4SLinus Torvalds 47013901ef2SJani Nikula if ($name =~ m/$type_param/) { 4711da177e4SLinus Torvalds $name = $1; 4721da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 473a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 4740b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 4750b0f5f29SDaniel Vetter $new_start_line = 0; 476ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 477ced69090SRandy Dunlap $name = "..."; 478ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 479a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 4800b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 4810b0f5f29SDaniel Vetter $new_start_line = 0; 4821da177e4SLinus Torvalds } else { 48394dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 48495b6be9dSJani Nikula # Only warn on user specified duplicate section names. 48595b6be9dSJani Nikula if ($name ne $section_default) { 48632217761SJani Nikula print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; 48732217761SJani Nikula ++$warnings; 48895b6be9dSJani Nikula } 48932217761SJani Nikula $sections{$name} .= $contents; 49032217761SJani Nikula } else { 4911da177e4SLinus Torvalds $sections{$name} = $contents; 4921da177e4SLinus Torvalds push @sectionlist, $name; 4930b0f5f29SDaniel Vetter $section_start_lines{$name} = $new_start_line; 4940b0f5f29SDaniel Vetter $new_start_line = 0; 4951da177e4SLinus Torvalds } 4961da177e4SLinus Torvalds } 49732217761SJani Nikula} 4981da177e4SLinus Torvalds 4991da177e4SLinus Torvalds## 500b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 501b112e0f7SJohannes Berg# 502b112e0f7SJohannes Bergsub dump_doc_section { 50394dc7ad5SRandy Dunlap my $file = shift; 504b112e0f7SJohannes Berg my $name = shift; 505b112e0f7SJohannes Berg my $contents = join "\n", @_; 506b112e0f7SJohannes Berg 5074b44595aSJohannes Berg if ($no_doc_sections) { 5084b44595aSJohannes Berg return; 5094b44595aSJohannes Berg } 5104b44595aSJohannes Berg 511b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 512b6c3f456SJani Nikula ($output_selection == OUTPUT_INCLUDE && 513b6c3f456SJani Nikula defined($function_table{$name})) || 514b6c3f456SJani Nikula ($output_selection == OUTPUT_EXCLUDE && 515b6c3f456SJani Nikula !defined($function_table{$name}))) 516b112e0f7SJohannes Berg { 51794dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 518b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 519b112e0f7SJohannes Berg 'sections' => \%sections, 520b112e0f7SJohannes Berg 'module' => $modulename, 521b6c3f456SJani Nikula 'content-only' => ($output_selection != OUTPUT_ALL), }); 522b112e0f7SJohannes Berg } 523b112e0f7SJohannes Berg} 524b112e0f7SJohannes Berg 525b112e0f7SJohannes Berg## 5261da177e4SLinus Torvalds# output function 5271da177e4SLinus Torvalds# 5281da177e4SLinus Torvalds# parameterdescs, a hash. 5291da177e4SLinus Torvalds# function => "function name" 5301da177e4SLinus Torvalds# parameterlist => @list of parameters 5311da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 5321da177e4SLinus Torvalds# sectionlist => @list of sections 533a21217daSRandy Dunlap# sections => %section descriptions 5341da177e4SLinus Torvalds# 5351da177e4SLinus Torvalds 5361da177e4SLinus Torvaldssub output_highlight { 5371da177e4SLinus Torvalds my $contents = join "\n",@_; 5381da177e4SLinus Torvalds my $line; 5391da177e4SLinus Torvalds 5401da177e4SLinus Torvalds# DEBUG 5411da177e4SLinus Torvalds# if (!defined $contents) { 5421da177e4SLinus Torvalds# use Carp; 5431da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 5441da177e4SLinus Torvalds# } 5451da177e4SLinus Torvalds 5463eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 5471da177e4SLinus Torvalds eval $dohighlight; 5481da177e4SLinus Torvalds die $@ if $@; 5493eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 5503eb014a1SRandy Dunlap 5511da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 55212ae6779SDaniel Santos if (! $output_preformatted) { 55312ae6779SDaniel Santos $line =~ s/^\s*//; 55412ae6779SDaniel Santos } 5551da177e4SLinus Torvalds if ($line eq ""){ 556e314ba31SDaniel Santos if (! $output_preformatted) { 5570bba924cSJonathan Corbet print $lineprefix, $blankline; 558e314ba31SDaniel Santos } 5591da177e4SLinus Torvalds } else { 560cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 561cdccb316SRandy Dunlap print "\\&$line"; 562cdccb316SRandy Dunlap } else { 5631da177e4SLinus Torvalds print $lineprefix, $line; 5641da177e4SLinus Torvalds } 565cdccb316SRandy Dunlap } 5661da177e4SLinus Torvalds print "\n"; 5671da177e4SLinus Torvalds } 5681da177e4SLinus Torvalds} 5691da177e4SLinus Torvalds 5701da177e4SLinus Torvalds## 5711da177e4SLinus Torvalds# output function in man 5721da177e4SLinus Torvaldssub output_function_man(%) { 5731da177e4SLinus Torvalds my %args = %{$_[0]}; 5741da177e4SLinus Torvalds my ($parameter, $section); 5751da177e4SLinus Torvalds my $count; 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 5781da177e4SLinus Torvalds 5791da177e4SLinus Torvalds print ".SH NAME\n"; 5801da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 5811da177e4SLinus Torvalds 5821da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 583a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 5841da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 585a21217daSRandy Dunlap } else { 586a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 587a21217daSRandy Dunlap } 5881da177e4SLinus Torvalds $count = 0; 5891da177e4SLinus Torvalds my $parenth = "("; 5901da177e4SLinus Torvalds my $post = ","; 5911da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 5921da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 5931da177e4SLinus Torvalds $post = ");"; 5941da177e4SLinus Torvalds } 5951da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 5961da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 5971da177e4SLinus Torvalds # pointer-to-function 5981da177e4SLinus Torvalds print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 5991da177e4SLinus Torvalds } else { 6001da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 6011da177e4SLinus Torvalds print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 6021da177e4SLinus Torvalds } 6031da177e4SLinus Torvalds $count++; 6041da177e4SLinus Torvalds $parenth = ""; 6051da177e4SLinus Torvalds } 6061da177e4SLinus Torvalds 6071da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 6081da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6091da177e4SLinus Torvalds my $parameter_name = $parameter; 6101da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6111da177e4SLinus Torvalds 6121da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 6131da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6141da177e4SLinus Torvalds } 6151da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6161da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 6171da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6181da177e4SLinus Torvalds } 6191da177e4SLinus Torvalds} 6201da177e4SLinus Torvalds 6211da177e4SLinus Torvalds## 6221da177e4SLinus Torvalds# output enum in man 6231da177e4SLinus Torvaldssub output_enum_man(%) { 6241da177e4SLinus Torvalds my %args = %{$_[0]}; 6251da177e4SLinus Torvalds my ($parameter, $section); 6261da177e4SLinus Torvalds my $count; 6271da177e4SLinus Torvalds 6281da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 6291da177e4SLinus Torvalds 6301da177e4SLinus Torvalds print ".SH NAME\n"; 6311da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 6321da177e4SLinus Torvalds 6331da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 6341da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 6351da177e4SLinus Torvalds $count = 0; 6361da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 6371da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 6381da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 6391da177e4SLinus Torvalds print "\n};\n"; 6401da177e4SLinus Torvalds last; 6411da177e4SLinus Torvalds } 6421da177e4SLinus Torvalds else { 6431da177e4SLinus Torvalds print ", \n.br\n"; 6441da177e4SLinus Torvalds } 6451da177e4SLinus Torvalds $count++; 6461da177e4SLinus Torvalds } 6471da177e4SLinus Torvalds 6481da177e4SLinus Torvalds print ".SH Constants\n"; 6491da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6501da177e4SLinus Torvalds my $parameter_name = $parameter; 6511da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6521da177e4SLinus Torvalds 6531da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 6541da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6551da177e4SLinus Torvalds } 6561da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6571da177e4SLinus Torvalds print ".SH \"$section\"\n"; 6581da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6591da177e4SLinus Torvalds } 6601da177e4SLinus Torvalds} 6611da177e4SLinus Torvalds 6621da177e4SLinus Torvalds## 6631da177e4SLinus Torvalds# output struct in man 6641da177e4SLinus Torvaldssub output_struct_man(%) { 6651da177e4SLinus Torvalds my %args = %{$_[0]}; 6661da177e4SLinus Torvalds my ($parameter, $section); 6671da177e4SLinus Torvalds 6681da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 6691da177e4SLinus Torvalds 6701da177e4SLinus Torvalds print ".SH NAME\n"; 6711da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 6721da177e4SLinus Torvalds 6738ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 6748ad72163SMauro Carvalho Chehab $declaration =~ s/\t/ /g; 6758ad72163SMauro Carvalho Chehab $declaration =~ s/\n/"\n.br\n.BI \"/g; 6761da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 6771da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 6788ad72163SMauro Carvalho Chehab print ".BI \"$declaration\n};\n.br\n\n"; 6791da177e4SLinus Torvalds 680c51d3dacSRandy Dunlap print ".SH Members\n"; 6811da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6821da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 6831da177e4SLinus Torvalds 6841da177e4SLinus Torvalds my $parameter_name = $parameter; 6851da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6861da177e4SLinus Torvalds 6871da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6881da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 6891da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6901da177e4SLinus Torvalds } 6911da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6921da177e4SLinus Torvalds print ".SH \"$section\"\n"; 6931da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6941da177e4SLinus Torvalds } 6951da177e4SLinus Torvalds} 6961da177e4SLinus Torvalds 6971da177e4SLinus Torvalds## 6981da177e4SLinus Torvalds# output typedef in man 6991da177e4SLinus Torvaldssub output_typedef_man(%) { 7001da177e4SLinus Torvalds my %args = %{$_[0]}; 7011da177e4SLinus Torvalds my ($parameter, $section); 7021da177e4SLinus Torvalds 7031da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 7041da177e4SLinus Torvalds 7051da177e4SLinus Torvalds print ".SH NAME\n"; 7061da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 7071da177e4SLinus Torvalds 7081da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7091da177e4SLinus Torvalds print ".SH \"$section\"\n"; 7101da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7111da177e4SLinus Torvalds } 7121da177e4SLinus Torvalds} 7131da177e4SLinus Torvalds 714b112e0f7SJohannes Bergsub output_blockhead_man(%) { 7151da177e4SLinus Torvalds my %args = %{$_[0]}; 7161da177e4SLinus Torvalds my ($parameter, $section); 7171da177e4SLinus Torvalds my $count; 7181da177e4SLinus Torvalds 7191da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 7201da177e4SLinus Torvalds 7211da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7221da177e4SLinus Torvalds print ".SH \"$section\"\n"; 7231da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7241da177e4SLinus Torvalds } 7251da177e4SLinus Torvalds} 7261da177e4SLinus Torvalds 7271da177e4SLinus Torvalds## 728c0d1b6eeSJonathan Corbet# output in restructured text 729c0d1b6eeSJonathan Corbet# 730c0d1b6eeSJonathan Corbet 731c0d1b6eeSJonathan Corbet# 732c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 733c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 734c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 735c0d1b6eeSJonathan Corbet# 736c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 737c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 738c0d1b6eeSJonathan Corbet my ($parameter, $section); 739c0d1b6eeSJonathan Corbet 740c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 7419e72184bSJani Nikula if ($output_selection != OUTPUT_INCLUDE) { 742c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 7439e72184bSJani Nikula } 7440b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 745c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 746c0d1b6eeSJonathan Corbet print "\n"; 747c0d1b6eeSJonathan Corbet } 748c0d1b6eeSJonathan Corbet} 749c0d1b6eeSJonathan Corbet 750c0d1b6eeSJonathan Corbetsub output_highlight_rst { 751c0d1b6eeSJonathan Corbet my $contents = join "\n",@_; 752c0d1b6eeSJonathan Corbet my $line; 753c0d1b6eeSJonathan Corbet 754c0d1b6eeSJonathan Corbet eval $dohighlight; 755c0d1b6eeSJonathan Corbet die $@ if $@; 756c0d1b6eeSJonathan Corbet 757c0d1b6eeSJonathan Corbet foreach $line (split "\n", $contents) { 758830066a7SJani Nikula print $lineprefix . $line . "\n"; 759c0d1b6eeSJonathan Corbet } 760c0d1b6eeSJonathan Corbet} 761c0d1b6eeSJonathan Corbet 762c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 763c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 764c0d1b6eeSJonathan Corbet my ($parameter, $section); 765c099ff69SJani Nikula my $oldprefix = $lineprefix; 76682801d06SMauro Carvalho Chehab my $start = ""; 767c0d1b6eeSJonathan Corbet 76882801d06SMauro Carvalho Chehab if ($args{'typedef'}) { 76982801d06SMauro Carvalho Chehab print ".. c:type:: ". $args{'function'} . "\n\n"; 77082801d06SMauro Carvalho Chehab print_lineno($declaration_start_line); 77182801d06SMauro Carvalho Chehab print " **Typedef**: "; 77282801d06SMauro Carvalho Chehab $lineprefix = ""; 77382801d06SMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 77482801d06SMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 775c0d1b6eeSJonathan Corbet } else { 77682801d06SMauro Carvalho Chehab print ".. c:function:: "; 77782801d06SMauro Carvalho Chehab } 77882801d06SMauro Carvalho Chehab if ($args{'functiontype'} ne "") { 77982801d06SMauro Carvalho Chehab $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; 78082801d06SMauro Carvalho Chehab } else { 78182801d06SMauro Carvalho Chehab $start .= $args{'function'} . " ("; 782c0d1b6eeSJonathan Corbet } 783c0d1b6eeSJonathan Corbet print $start; 784c0d1b6eeSJonathan Corbet 785c0d1b6eeSJonathan Corbet my $count = 0; 786c0d1b6eeSJonathan Corbet foreach my $parameter (@{$args{'parameterlist'}}) { 787c0d1b6eeSJonathan Corbet if ($count ne 0) { 788c0d1b6eeSJonathan Corbet print ", "; 789c0d1b6eeSJonathan Corbet } 790c0d1b6eeSJonathan Corbet $count++; 791c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 792a88b1672SMauro Carvalho Chehab 793c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 794c0d1b6eeSJonathan Corbet # pointer-to-function 795c0d1b6eeSJonathan Corbet print $1 . $parameter . ") (" . $2; 796c0d1b6eeSJonathan Corbet } else { 797c0d1b6eeSJonathan Corbet print $type . " " . $parameter; 798c0d1b6eeSJonathan Corbet } 799c0d1b6eeSJonathan Corbet } 80082801d06SMauro Carvalho Chehab if ($args{'typedef'}) { 80182801d06SMauro Carvalho Chehab print ");``\n\n"; 80282801d06SMauro Carvalho Chehab } else { 803c099ff69SJani Nikula print ")\n\n"; 8040b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 805c099ff69SJani Nikula $lineprefix = " "; 806c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 807c099ff69SJani Nikula print "\n"; 80882801d06SMauro Carvalho Chehab } 809c0d1b6eeSJonathan Corbet 810ecbcfba1SJani Nikula print "**Parameters**\n\n"; 811c099ff69SJani Nikula $lineprefix = " "; 812c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 813c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 814ada5f446SGabriel Krisman Bertazi $parameter_name =~ s/\[.*//; 815c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 816c0d1b6eeSJonathan Corbet 817c0d1b6eeSJonathan Corbet if ($type ne "") { 818c0d1b6eeSJonathan Corbet print "``$type $parameter``\n"; 819c0d1b6eeSJonathan Corbet } else { 820c0d1b6eeSJonathan Corbet print "``$parameter``\n"; 821c0d1b6eeSJonathan Corbet } 8220b0f5f29SDaniel Vetter 8230b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 8240b0f5f29SDaniel Vetter 8255e64fa9cSJani Nikula if (defined($args{'parameterdescs'}{$parameter_name}) && 8265e64fa9cSJani Nikula $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 827c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 828c0d1b6eeSJonathan Corbet } else { 829d4b08e0cSJani Nikula print " *undescribed*\n"; 830c0d1b6eeSJonathan Corbet } 831c0d1b6eeSJonathan Corbet print "\n"; 832c0d1b6eeSJonathan Corbet } 833c099ff69SJani Nikula 834c099ff69SJani Nikula $lineprefix = $oldprefix; 835c0d1b6eeSJonathan Corbet output_section_rst(@_); 836c0d1b6eeSJonathan Corbet} 837c0d1b6eeSJonathan Corbet 838c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 839c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 840c0d1b6eeSJonathan Corbet my $section; 841c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 842c0d1b6eeSJonathan Corbet $lineprefix = ""; 843c0d1b6eeSJonathan Corbet 844c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 845ecbcfba1SJani Nikula print "**$section**\n\n"; 8460b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 847c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 848c0d1b6eeSJonathan Corbet print "\n"; 849c0d1b6eeSJonathan Corbet } 850c0d1b6eeSJonathan Corbet print "\n"; 851c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 852c0d1b6eeSJonathan Corbet} 853c0d1b6eeSJonathan Corbet 854c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 855c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 856c0d1b6eeSJonathan Corbet my ($parameter); 857c099ff69SJani Nikula my $oldprefix = $lineprefix; 858c0d1b6eeSJonathan Corbet my $count; 859c0d1b6eeSJonathan Corbet my $name = "enum " . $args{'enum'}; 86062850976SJani Nikula 86162850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 8620b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 863c099ff69SJani Nikula $lineprefix = " "; 864c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 865c099ff69SJani Nikula print "\n"; 866c0d1b6eeSJonathan Corbet 867ecbcfba1SJani Nikula print "**Constants**\n\n"; 868c0d1b6eeSJonathan Corbet $lineprefix = " "; 869c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 870ecbcfba1SJani Nikula print "``$parameter``\n"; 871c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 872c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 873c0d1b6eeSJonathan Corbet } else { 874d4b08e0cSJani Nikula print " *undescribed*\n"; 875c0d1b6eeSJonathan Corbet } 876c0d1b6eeSJonathan Corbet print "\n"; 877c0d1b6eeSJonathan Corbet } 878c099ff69SJani Nikula 879c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 880c0d1b6eeSJonathan Corbet output_section_rst(@_); 881c0d1b6eeSJonathan Corbet} 882c0d1b6eeSJonathan Corbet 883c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 884c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 885c0d1b6eeSJonathan Corbet my ($parameter); 886c099ff69SJani Nikula my $oldprefix = $lineprefix; 887c0d1b6eeSJonathan Corbet my $name = "typedef " . $args{'typedef'}; 888c0d1b6eeSJonathan Corbet 88962850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 8900b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 891c099ff69SJani Nikula $lineprefix = " "; 892c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 893c099ff69SJani Nikula print "\n"; 894c0d1b6eeSJonathan Corbet 895c099ff69SJani Nikula $lineprefix = $oldprefix; 896c0d1b6eeSJonathan Corbet output_section_rst(@_); 897c0d1b6eeSJonathan Corbet} 898c0d1b6eeSJonathan Corbet 899c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 900c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 901c0d1b6eeSJonathan Corbet my ($parameter); 902c099ff69SJani Nikula my $oldprefix = $lineprefix; 903c0d1b6eeSJonathan Corbet my $name = $args{'type'} . " " . $args{'struct'}; 904c0d1b6eeSJonathan Corbet 90562850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 9060b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 907c099ff69SJani Nikula $lineprefix = " "; 908c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 909c099ff69SJani Nikula print "\n"; 910c0d1b6eeSJonathan Corbet 911ecbcfba1SJani Nikula print "**Definition**\n\n"; 912c0d1b6eeSJonathan Corbet print "::\n\n"; 9138ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 9148ad72163SMauro Carvalho Chehab $declaration =~ s/\t/ /g; 9158ad72163SMauro Carvalho Chehab print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n"; 916c0d1b6eeSJonathan Corbet 917ecbcfba1SJani Nikula print "**Members**\n\n"; 918c099ff69SJani Nikula $lineprefix = " "; 919c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 920c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 921c0d1b6eeSJonathan Corbet 922c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 923c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 924c0d1b6eeSJonathan Corbet 925c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 926c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 9270b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 9286d232c80SMauro Carvalho Chehab print "``" . $parameter . "``\n"; 929c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 930c0d1b6eeSJonathan Corbet print "\n"; 931c0d1b6eeSJonathan Corbet } 932c0d1b6eeSJonathan Corbet print "\n"; 933c099ff69SJani Nikula 934c099ff69SJani Nikula $lineprefix = $oldprefix; 935c0d1b6eeSJonathan Corbet output_section_rst(@_); 936c0d1b6eeSJonathan Corbet} 937c0d1b6eeSJonathan Corbet 9383a025e1dSMatthew Wilcox## none mode output functions 9393a025e1dSMatthew Wilcox 9403a025e1dSMatthew Wilcoxsub output_function_none(%) { 9413a025e1dSMatthew Wilcox} 9423a025e1dSMatthew Wilcox 9433a025e1dSMatthew Wilcoxsub output_enum_none(%) { 9443a025e1dSMatthew Wilcox} 9453a025e1dSMatthew Wilcox 9463a025e1dSMatthew Wilcoxsub output_typedef_none(%) { 9473a025e1dSMatthew Wilcox} 9483a025e1dSMatthew Wilcox 9493a025e1dSMatthew Wilcoxsub output_struct_none(%) { 9503a025e1dSMatthew Wilcox} 9513a025e1dSMatthew Wilcox 9523a025e1dSMatthew Wilcoxsub output_blockhead_none(%) { 9533a025e1dSMatthew Wilcox} 9543a025e1dSMatthew Wilcox 9551da177e4SLinus Torvalds## 95627205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 95727205744SRandy Dunlap# calls the generated, variable output_ function name based on 95827205744SRandy Dunlap# functype and output_mode 9591da177e4SLinus Torvaldssub output_declaration { 9601da177e4SLinus Torvalds no strict 'refs'; 9611da177e4SLinus Torvalds my $name = shift; 9621da177e4SLinus Torvalds my $functype = shift; 9631da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 964b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 965b6c3f456SJani Nikula (($output_selection == OUTPUT_INCLUDE || 966b6c3f456SJani Nikula $output_selection == OUTPUT_EXPORTED) && 96786ae2e38SJani Nikula defined($function_table{$name})) || 968b6c3f456SJani Nikula (($output_selection == OUTPUT_EXCLUDE || 969b6c3f456SJani Nikula $output_selection == OUTPUT_INTERNAL) && 97086ae2e38SJani Nikula !($functype eq "function" && defined($function_table{$name})))) 9711da177e4SLinus Torvalds { 9721da177e4SLinus Torvalds &$func(@_); 9731da177e4SLinus Torvalds $section_counter++; 9741da177e4SLinus Torvalds } 9751da177e4SLinus Torvalds} 9761da177e4SLinus Torvalds 9771da177e4SLinus Torvalds## 97827205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 979b112e0f7SJohannes Bergsub output_blockhead { 9801da177e4SLinus Torvalds no strict 'refs'; 981b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 9821da177e4SLinus Torvalds &$func(@_); 9831da177e4SLinus Torvalds $section_counter++; 9841da177e4SLinus Torvalds} 9851da177e4SLinus Torvalds 9861da177e4SLinus Torvalds## 9871da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 9881da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 9891da177e4SLinus Torvaldssub dump_declaration($$) { 9901da177e4SLinus Torvalds no strict 'refs'; 9911da177e4SLinus Torvalds my ($prototype, $file) = @_; 9921da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 9931da177e4SLinus Torvalds &$func(@_); 9941da177e4SLinus Torvalds} 9951da177e4SLinus Torvalds 9961da177e4SLinus Torvaldssub dump_union($$) { 9971da177e4SLinus Torvalds dump_struct(@_); 9981da177e4SLinus Torvalds} 9991da177e4SLinus Torvalds 10001da177e4SLinus Torvaldssub dump_struct($$) { 10011da177e4SLinus Torvalds my $x = shift; 10021da177e4SLinus Torvalds my $file = shift; 10031da177e4SLinus Torvalds 10041da177e4SLinus Torvalds if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 10055cb5c31cSJohannes Berg my $decl_type = $1; 10061da177e4SLinus Torvalds $declaration_name = $2; 10071da177e4SLinus Torvalds my $members = $3; 10081da177e4SLinus Torvalds 1009aeec46b9SMartin Waitz # ignore members marked private: 10100d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 10110d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 1012aeec46b9SMartin Waitz # strip comments: 1013aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 1014ef5da59fSRandy Dunlap # strip attributes 1015f0074929SJonathan Corbet $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 10167b990789SJohannes Berg $members =~ s/__aligned\s*\([^;]*\)//gos; 1017f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; 1018b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 101945005b27SMauro Carvalho Chehab $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 10201cb566baSJakub Kicinski # replace DECLARE_HASHTABLE 102145005b27SMauro Carvalho Chehab $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos; 102245005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO 102345005b27SMauro Carvalho Chehab $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; 102445005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO_PTR 102545005b27SMauro Carvalho Chehab $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; 1026aeec46b9SMartin Waitz 10278ad72163SMauro Carvalho Chehab my $declaration = $members; 10288ad72163SMauro Carvalho Chehab 10298ad72163SMauro Carvalho Chehab # Split nested struct/union elements as newer ones 103084ce5b98SMauro Carvalho Chehab while ($members =~ m/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/) { 103184ce5b98SMauro Carvalho Chehab my $newmember; 103284ce5b98SMauro Carvalho Chehab my $maintype = $1; 103384ce5b98SMauro Carvalho Chehab my $ids = $4; 10348ad72163SMauro Carvalho Chehab my $content = $3; 103584ce5b98SMauro Carvalho Chehab foreach my $id(split /,/, $ids) { 103684ce5b98SMauro Carvalho Chehab $newmember .= "$maintype $id; "; 103784ce5b98SMauro Carvalho Chehab 10388ad72163SMauro Carvalho Chehab $id =~ s/[:\[].*//; 103984ce5b98SMauro Carvalho Chehab $id =~ s/^\s*\**(\S+)\s*/$1/; 10408ad72163SMauro Carvalho Chehab foreach my $arg (split /;/, $content) { 10418ad72163SMauro Carvalho Chehab next if ($arg =~ m/^\s*$/); 10427c0d7e87SMauro Carvalho Chehab if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) { 10437c0d7e87SMauro Carvalho Chehab # pointer-to-function 10447c0d7e87SMauro Carvalho Chehab my $type = $1; 10457c0d7e87SMauro Carvalho Chehab my $name = $2; 10467c0d7e87SMauro Carvalho Chehab my $extra = $3; 10477c0d7e87SMauro Carvalho Chehab next if (!$name); 10487c0d7e87SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 10497c0d7e87SMauro Carvalho Chehab # anonymous struct/union 10507c0d7e87SMauro Carvalho Chehab $newmember .= "$type$name$extra; "; 10517c0d7e87SMauro Carvalho Chehab } else { 10527c0d7e87SMauro Carvalho Chehab $newmember .= "$type$id.$name$extra; "; 10537c0d7e87SMauro Carvalho Chehab } 10547c0d7e87SMauro Carvalho Chehab } else { 105584ce5b98SMauro Carvalho Chehab my $type; 105684ce5b98SMauro Carvalho Chehab my $names; 105784ce5b98SMauro Carvalho Chehab $arg =~ s/^\s+//; 105884ce5b98SMauro Carvalho Chehab $arg =~ s/\s+$//; 105984ce5b98SMauro Carvalho Chehab # Handle bitmaps 106084ce5b98SMauro Carvalho Chehab $arg =~ s/:\s*\d+\s*//g; 106184ce5b98SMauro Carvalho Chehab # Handle arrays 106284ce5b98SMauro Carvalho Chehab $arg =~ s/\[\S+\]//g; 106384ce5b98SMauro Carvalho Chehab # The type may have multiple words, 106484ce5b98SMauro Carvalho Chehab # and multiple IDs can be defined, like: 106584ce5b98SMauro Carvalho Chehab # const struct foo, *bar, foobar 106684ce5b98SMauro Carvalho Chehab # So, we remove spaces when parsing the 106784ce5b98SMauro Carvalho Chehab # names, in order to match just names 106884ce5b98SMauro Carvalho Chehab # and commas for the names 106984ce5b98SMauro Carvalho Chehab $arg =~ s/\s*,\s*/,/g; 107084ce5b98SMauro Carvalho Chehab if ($arg =~ m/(.*)\s+([\S+,]+)/) { 107184ce5b98SMauro Carvalho Chehab $type = $1; 107284ce5b98SMauro Carvalho Chehab $names = $2; 107384ce5b98SMauro Carvalho Chehab } else { 107484ce5b98SMauro Carvalho Chehab $newmember .= "$arg; "; 107584ce5b98SMauro Carvalho Chehab next; 107684ce5b98SMauro Carvalho Chehab } 107784ce5b98SMauro Carvalho Chehab foreach my $name (split /,/, $names) { 107884ce5b98SMauro Carvalho Chehab $name =~ s/^\s*\**(\S+)\s*/$1/; 10798ad72163SMauro Carvalho Chehab next if (($name =~ m/^\s*$/)); 10808ad72163SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 10818ad72163SMauro Carvalho Chehab # anonymous struct/union 10828ad72163SMauro Carvalho Chehab $newmember .= "$type $name; "; 10838ad72163SMauro Carvalho Chehab } else { 10848ad72163SMauro Carvalho Chehab $newmember .= "$type $id.$name; "; 10858ad72163SMauro Carvalho Chehab } 10868ad72163SMauro Carvalho Chehab } 10877c0d7e87SMauro Carvalho Chehab } 108884ce5b98SMauro Carvalho Chehab } 108984ce5b98SMauro Carvalho Chehab } 109084ce5b98SMauro Carvalho Chehab $members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)}([^\{\}\;]*)\;/$newmember/; 109184ce5b98SMauro Carvalho Chehab } 10928ad72163SMauro Carvalho Chehab 10938ad72163SMauro Carvalho Chehab # Ignore other nested elements, like enums 10948ad72163SMauro Carvalho Chehab $members =~ s/({[^\{\}]*})//g; 10958ad72163SMauro Carvalho Chehab 1096151c468bSMauro Carvalho Chehab create_parameterlist($members, ';', $file, $declaration_name); 10971081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual); 10981da177e4SLinus Torvalds 10998ad72163SMauro Carvalho Chehab # Adjust declaration for better display 11008ad72163SMauro Carvalho Chehab $declaration =~ s/([{;])/$1\n/g; 11018ad72163SMauro Carvalho Chehab $declaration =~ s/}\s+;/};/g; 11028ad72163SMauro Carvalho Chehab # Better handle inlined enums 11038ad72163SMauro Carvalho Chehab do {} while ($declaration =~ s/(enum\s+{[^}]+),([^\n])/$1,\n$2/); 11048ad72163SMauro Carvalho Chehab 11058ad72163SMauro Carvalho Chehab my @def_args = split /\n/, $declaration; 11068ad72163SMauro Carvalho Chehab my $level = 1; 11078ad72163SMauro Carvalho Chehab $declaration = ""; 11088ad72163SMauro Carvalho Chehab foreach my $clause (@def_args) { 11098ad72163SMauro Carvalho Chehab $clause =~ s/^\s+//; 11108ad72163SMauro Carvalho Chehab $clause =~ s/\s+$//; 11118ad72163SMauro Carvalho Chehab $clause =~ s/\s+/ /; 11128ad72163SMauro Carvalho Chehab next if (!$clause); 11138ad72163SMauro Carvalho Chehab $level-- if ($clause =~ m/(})/ && $level > 1); 11148ad72163SMauro Carvalho Chehab if (!($clause =~ m/^\s*#/)) { 11158ad72163SMauro Carvalho Chehab $declaration .= "\t" x $level; 11168ad72163SMauro Carvalho Chehab } 11178ad72163SMauro Carvalho Chehab $declaration .= "\t" . $clause . "\n"; 11188ad72163SMauro Carvalho Chehab $level++ if ($clause =~ m/({)/ && !($clause =~m/}/)); 11198ad72163SMauro Carvalho Chehab } 11201da177e4SLinus Torvalds output_declaration($declaration_name, 11211da177e4SLinus Torvalds 'struct', 11221da177e4SLinus Torvalds {'struct' => $declaration_name, 11231da177e4SLinus Torvalds 'module' => $modulename, 11248ad72163SMauro Carvalho Chehab 'definition' => $declaration, 11251da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 11261da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 11271da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 11281da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 11291da177e4SLinus Torvalds 'sections' => \%sections, 11301da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 11311da177e4SLinus Torvalds 'type' => $decl_type 11321da177e4SLinus Torvalds }); 11331da177e4SLinus Torvalds } 11341da177e4SLinus Torvalds else { 1135d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 11361da177e4SLinus Torvalds ++$errors; 11371da177e4SLinus Torvalds } 11381da177e4SLinus Torvalds} 11391da177e4SLinus Torvalds 114085afe608SMauro Carvalho Chehab 114185afe608SMauro Carvalho Chehabsub show_warnings($$) { 114285afe608SMauro Carvalho Chehab my $functype = shift; 114385afe608SMauro Carvalho Chehab my $name = shift; 114485afe608SMauro Carvalho Chehab 114585afe608SMauro Carvalho Chehab return 1 if ($output_selection == OUTPUT_ALL); 114685afe608SMauro Carvalho Chehab 114785afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_EXPORTED) { 114885afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 114985afe608SMauro Carvalho Chehab return 1; 115085afe608SMauro Carvalho Chehab } else { 115185afe608SMauro Carvalho Chehab return 0; 115285afe608SMauro Carvalho Chehab } 115385afe608SMauro Carvalho Chehab } 115485afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_INTERNAL) { 115585afe608SMauro Carvalho Chehab if (!($functype eq "function" && defined($function_table{$name}))) { 115685afe608SMauro Carvalho Chehab return 1; 115785afe608SMauro Carvalho Chehab } else { 115885afe608SMauro Carvalho Chehab return 0; 115985afe608SMauro Carvalho Chehab } 116085afe608SMauro Carvalho Chehab } 116185afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_INCLUDE) { 116285afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 116385afe608SMauro Carvalho Chehab return 1; 116485afe608SMauro Carvalho Chehab } else { 116585afe608SMauro Carvalho Chehab return 0; 116685afe608SMauro Carvalho Chehab } 116785afe608SMauro Carvalho Chehab } 116885afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_EXCLUDE) { 116985afe608SMauro Carvalho Chehab if (!defined($function_table{$name})) { 117085afe608SMauro Carvalho Chehab return 1; 117185afe608SMauro Carvalho Chehab } else { 117285afe608SMauro Carvalho Chehab return 0; 117385afe608SMauro Carvalho Chehab } 117485afe608SMauro Carvalho Chehab } 117585afe608SMauro Carvalho Chehab die("Please add the new output type at show_warnings()"); 117685afe608SMauro Carvalho Chehab} 117785afe608SMauro Carvalho Chehab 11781da177e4SLinus Torvaldssub dump_enum($$) { 11791da177e4SLinus Torvalds my $x = shift; 11801da177e4SLinus Torvalds my $file = shift; 11811da177e4SLinus Torvalds 1182aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 11834468e21eSConchúr Navid # strip #define macros inside enums 11844468e21eSConchúr Navid $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 1185b6d676dbSRandy Dunlap 11861da177e4SLinus Torvalds if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 11871da177e4SLinus Torvalds $declaration_name = $1; 11881da177e4SLinus Torvalds my $members = $2; 11895cb5c31cSJohannes Berg my %_members; 11905cb5c31cSJohannes Berg 1191463a0fdcSMarkus Heiser $members =~ s/\s+$//; 11921da177e4SLinus Torvalds 11931da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 11941da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 11951da177e4SLinus Torvalds push @parameterlist, $arg; 11961da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 11971da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 119885afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 11992defb272SMauro Carvalho Chehab print STDERR "${file}:$.: warning: Enum value '$arg' not described in enum '$declaration_name'\n"; 12002defb272SMauro Carvalho Chehab } 12011da177e4SLinus Torvalds } 12025cb5c31cSJohannes Berg $_members{$arg} = 1; 12035cb5c31cSJohannes Berg } 12041da177e4SLinus Torvalds 12055cb5c31cSJohannes Berg while (my ($k, $v) = each %parameterdescs) { 12065cb5c31cSJohannes Berg if (!exists($_members{$k})) { 120785afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 12082defb272SMauro Carvalho Chehab print STDERR "${file}:$.: warning: Excess enum value '$k' description in '$declaration_name'\n"; 12092defb272SMauro Carvalho Chehab } 12105cb5c31cSJohannes Berg } 12111da177e4SLinus Torvalds } 12121da177e4SLinus Torvalds 12131da177e4SLinus Torvalds output_declaration($declaration_name, 12141da177e4SLinus Torvalds 'enum', 12151da177e4SLinus Torvalds {'enum' => $declaration_name, 12161da177e4SLinus Torvalds 'module' => $modulename, 12171da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 12181da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 12191da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 12201da177e4SLinus Torvalds 'sections' => \%sections, 12211da177e4SLinus Torvalds 'purpose' => $declaration_purpose 12221da177e4SLinus Torvalds }); 12231da177e4SLinus Torvalds } 12241da177e4SLinus Torvalds else { 1225d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 12261da177e4SLinus Torvalds ++$errors; 12271da177e4SLinus Torvalds } 12281da177e4SLinus Torvalds} 12291da177e4SLinus Torvalds 12301da177e4SLinus Torvaldssub dump_typedef($$) { 12311da177e4SLinus Torvalds my $x = shift; 12321da177e4SLinus Torvalds my $file = shift; 12331da177e4SLinus Torvalds 1234aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 123583766452SMauro Carvalho Chehab 123683766452SMauro Carvalho Chehab # Parse function prototypes 1237d37c43ceSMauro Carvalho Chehab if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ || 1238d37c43ceSMauro Carvalho Chehab $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) { 1239d37c43ceSMauro Carvalho Chehab 124083766452SMauro Carvalho Chehab # Function typedefs 124183766452SMauro Carvalho Chehab $return_type = $1; 124283766452SMauro Carvalho Chehab $declaration_name = $2; 124383766452SMauro Carvalho Chehab my $args = $3; 124483766452SMauro Carvalho Chehab 1245151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 124683766452SMauro Carvalho Chehab 124783766452SMauro Carvalho Chehab output_declaration($declaration_name, 124883766452SMauro Carvalho Chehab 'function', 124983766452SMauro Carvalho Chehab {'function' => $declaration_name, 125082801d06SMauro Carvalho Chehab 'typedef' => 1, 125183766452SMauro Carvalho Chehab 'module' => $modulename, 125283766452SMauro Carvalho Chehab 'functiontype' => $return_type, 125383766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 125483766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 125583766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 125683766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 125783766452SMauro Carvalho Chehab 'sections' => \%sections, 125883766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 125983766452SMauro Carvalho Chehab }); 126083766452SMauro Carvalho Chehab return; 126183766452SMauro Carvalho Chehab } 126283766452SMauro Carvalho Chehab 12631da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 12641da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 12651da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 12661da177e4SLinus Torvalds } 12671da177e4SLinus Torvalds 12681da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 12691da177e4SLinus Torvalds $declaration_name = $1; 12701da177e4SLinus Torvalds 12711da177e4SLinus Torvalds output_declaration($declaration_name, 12721da177e4SLinus Torvalds 'typedef', 12731da177e4SLinus Torvalds {'typedef' => $declaration_name, 12741da177e4SLinus Torvalds 'module' => $modulename, 12751da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 12761da177e4SLinus Torvalds 'sections' => \%sections, 12771da177e4SLinus Torvalds 'purpose' => $declaration_purpose 12781da177e4SLinus Torvalds }); 12791da177e4SLinus Torvalds } 12801da177e4SLinus Torvalds else { 1281d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 12821da177e4SLinus Torvalds ++$errors; 12831da177e4SLinus Torvalds } 12841da177e4SLinus Torvalds} 12851da177e4SLinus Torvalds 1286a1d94aa5SRandy Dunlapsub save_struct_actual($) { 1287a1d94aa5SRandy Dunlap my $actual = shift; 1288a1d94aa5SRandy Dunlap 1289a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 1290a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 1291a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 1292a1d94aa5SRandy Dunlap} 1293a1d94aa5SRandy Dunlap 1294151c468bSMauro Carvalho Chehabsub create_parameterlist($$$$) { 12951da177e4SLinus Torvalds my $args = shift; 12961da177e4SLinus Torvalds my $splitter = shift; 12971da177e4SLinus Torvalds my $file = shift; 1298151c468bSMauro Carvalho Chehab my $declaration_name = shift; 12991da177e4SLinus Torvalds my $type; 13001da177e4SLinus Torvalds my $param; 13011da177e4SLinus Torvalds 1302a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 13031da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 13041da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 13051da177e4SLinus Torvalds } 13061da177e4SLinus Torvalds 13071da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 13081da177e4SLinus Torvalds # strip comments 13091da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 13101da177e4SLinus Torvalds # strip leading/trailing spaces 13111da177e4SLinus Torvalds $arg =~ s/^\s*//; 13121da177e4SLinus Torvalds $arg =~ s/\s*$//; 13131da177e4SLinus Torvalds $arg =~ s/\s+/ /; 13141da177e4SLinus Torvalds 13151da177e4SLinus Torvalds if ($arg =~ /^#/) { 13161da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 13171da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 13181da177e4SLinus Torvalds # output_* subs. 13191da177e4SLinus Torvalds push_parameter($arg, "", $file); 132000d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 13211da177e4SLinus Torvalds # pointer-to-function 13221da177e4SLinus Torvalds $arg =~ tr/#/,/; 13237c0d7e87SMauro Carvalho Chehab $arg =~ m/[^\(]+\(\*?\s*([\w\.]*)\s*\)/; 13241da177e4SLinus Torvalds $param = $1; 13251da177e4SLinus Torvalds $type = $arg; 132600d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1327a1d94aa5SRandy Dunlap save_struct_actual($param); 1328151c468bSMauro Carvalho Chehab push_parameter($param, $type, $file, $declaration_name); 1329aeec46b9SMartin Waitz } elsif ($arg) { 13301da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 13311da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 13321da177e4SLinus Torvalds 13331da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 13341da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 13351da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 13361da177e4SLinus Torvalds } 1337884f2810SBorislav Petkov 1338884f2810SBorislav Petkov my @first_arg; 1339884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1340884f2810SBorislav Petkov shift @args; 1341884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 1342884f2810SBorislav Petkov push(@first_arg, $2); 1343884f2810SBorislav Petkov } else { 1344884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 1345884f2810SBorislav Petkov } 1346884f2810SBorislav Petkov 13471da177e4SLinus Torvalds unshift(@args, pop @first_arg); 13481da177e4SLinus Torvalds $type = join " ", @first_arg; 13491da177e4SLinus Torvalds 13501da177e4SLinus Torvalds foreach $param (@args) { 13511da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 1352a1d94aa5SRandy Dunlap save_struct_actual($2); 1353151c468bSMauro Carvalho Chehab push_parameter($2, "$type $1", $file, $declaration_name); 13541da177e4SLinus Torvalds } 13551da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 13567b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 1357a1d94aa5SRandy Dunlap save_struct_actual($1); 1358151c468bSMauro Carvalho Chehab push_parameter($1, "$type:$2", $file, $declaration_name) 13591da177e4SLinus Torvalds } 13607b97887eSRandy Dunlap } 13611da177e4SLinus Torvalds else { 1362a1d94aa5SRandy Dunlap save_struct_actual($param); 1363151c468bSMauro Carvalho Chehab push_parameter($param, $type, $file, $declaration_name); 13641da177e4SLinus Torvalds } 13651da177e4SLinus Torvalds } 13661da177e4SLinus Torvalds } 13671da177e4SLinus Torvalds } 13681da177e4SLinus Torvalds} 13691da177e4SLinus Torvalds 1370151c468bSMauro Carvalho Chehabsub push_parameter($$$$) { 13711da177e4SLinus Torvalds my $param = shift; 13721da177e4SLinus Torvalds my $type = shift; 13731da177e4SLinus Torvalds my $file = shift; 1374151c468bSMauro Carvalho Chehab my $declaration_name = shift; 13751da177e4SLinus Torvalds 13765f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 13775f8c7c98SRandy Dunlap ($param eq "}")) { 13785f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 13795f8c7c98SRandy Dunlap } 13805f8c7c98SRandy Dunlap 13815f8c7c98SRandy Dunlap $anon_struct_union = 0; 1382f9b5c530SMauro Carvalho Chehab $param =~ s/[\[\)].*//; 13831da177e4SLinus Torvalds 1384a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 13851da177e4SLinus Torvalds { 1386c950a173SSilvio Fricke if (!$param =~ /\w\.\.\.$/) { 1387c950a173SSilvio Fricke # handles unnamed variable parameters 1388ef00028bSJonathan Corbet $param = "..."; 1389c950a173SSilvio Fricke } 1390ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1391a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 13921da177e4SLinus Torvalds } 1393ced69090SRandy Dunlap } 13941da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 13951da177e4SLinus Torvalds { 13961da177e4SLinus Torvalds $param="void"; 13971da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 13981da177e4SLinus Torvalds } 1399134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1400134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 1401134fe01bSRandy Dunlap { 1402134fe01bSRandy Dunlap $type = $param; 1403134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 1404134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 14055f8c7c98SRandy Dunlap $anon_struct_union = 1; 1406134fe01bSRandy Dunlap } 1407134fe01bSRandy Dunlap 1408a6d3fe77SMartin Waitz # warn if parameter has no description 1409134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 1410134fe01bSRandy Dunlap # but inline preprocessor statements); 1411151c468bSMauro Carvalho Chehab # Note: It will also ignore void params and unnamed structs/unions 1412f9b5c530SMauro Carvalho Chehab if (!defined $parameterdescs{$param} && $param !~ /^#/) { 1413f9b5c530SMauro Carvalho Chehab $parameterdescs{$param} = $undescribed; 14141da177e4SLinus Torvalds 141585afe608SMauro Carvalho Chehab if (show_warnings($type, $declaration_name)) { 1416151c468bSMauro Carvalho Chehab print STDERR 1417151c468bSMauro Carvalho Chehab "${file}:$.: warning: Function parameter or member '$param' not described in '$declaration_name'\n"; 14181da177e4SLinus Torvalds ++$warnings; 14191da177e4SLinus Torvalds } 14202defb272SMauro Carvalho Chehab } 14211da177e4SLinus Torvalds 142225985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 1423e34e7dbbSRandy Dunlap # on @parameterlist; 1424e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 1425e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 1426e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 1427e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 1428e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 1429e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 1430e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 14311da177e4SLinus Torvalds push @parameterlist, $param; 143202a4f4feSPaolo Bonzini $type =~ s/\s\s+/ /g; 14331da177e4SLinus Torvalds $parametertypes{$param} = $type; 14341da177e4SLinus Torvalds} 14351da177e4SLinus Torvalds 14361081de2dSMauro Carvalho Chehabsub check_sections($$$$$) { 14371081de2dSMauro Carvalho Chehab my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_; 1438a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 1439a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 1440a1d94aa5SRandy Dunlap my $err; 1441a1d94aa5SRandy Dunlap my ($px, $sx); 1442a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 1443a1d94aa5SRandy Dunlap 1444a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 1445a1d94aa5SRandy Dunlap $err = 1; 1446a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 1447a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 1448a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 14491f3a6688SJohannes Berg $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 1450e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 1451e34e7dbbSRandy Dunlap # however, the original param string may contain 1452e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 1453e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 1454e34e7dbbSRandy Dunlap # parameter list is split at spaces; 1455e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 1456e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 1457e34e7dbbSRandy Dunlap 1458a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 1459a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 1460a1d94aa5SRandy Dunlap $err = 0; 1461a1d94aa5SRandy Dunlap last; 1462a1d94aa5SRandy Dunlap } 1463a1d94aa5SRandy Dunlap } 1464a1d94aa5SRandy Dunlap if ($err) { 1465a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 1466d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 1467a1d94aa5SRandy Dunlap "Excess function parameter " . 1468a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 1469a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 1470a1d94aa5SRandy Dunlap ++$warnings; 1471a1d94aa5SRandy Dunlap } 1472a1d94aa5SRandy Dunlap } 1473a1d94aa5SRandy Dunlap } 1474a1d94aa5SRandy Dunlap} 1475a1d94aa5SRandy Dunlap 14761da177e4SLinus Torvalds## 14774092bac7SYacine Belkadi# Checks the section describing the return value of a function. 14784092bac7SYacine Belkadisub check_return_section { 14794092bac7SYacine Belkadi my $file = shift; 14804092bac7SYacine Belkadi my $declaration_name = shift; 14814092bac7SYacine Belkadi my $return_type = shift; 14824092bac7SYacine Belkadi 14834092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 14844092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 14854092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 14864092bac7SYacine Belkadi return; 14874092bac7SYacine Belkadi } 14884092bac7SYacine Belkadi 14894092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 14904092bac7SYacine Belkadi $sections{$section_return} eq "") { 1491d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 14924092bac7SYacine Belkadi "No description found for return value of " . 14934092bac7SYacine Belkadi "'$declaration_name'\n"; 14944092bac7SYacine Belkadi ++$warnings; 14954092bac7SYacine Belkadi } 14964092bac7SYacine Belkadi} 14974092bac7SYacine Belkadi 14984092bac7SYacine Belkadi## 14991da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 15001da177e4SLinus Torvalds# processed and spits out all the details stored in the global 15011da177e4SLinus Torvalds# arrays/hashes. 15021da177e4SLinus Torvaldssub dump_function($$) { 15031da177e4SLinus Torvalds my $prototype = shift; 15041da177e4SLinus Torvalds my $file = shift; 1505cbb4d3e6SHoria Geanta my $noret = 0; 15061da177e4SLinus Torvalds 15071da177e4SLinus Torvalds $prototype =~ s/^static +//; 15081da177e4SLinus Torvalds $prototype =~ s/^extern +//; 15094dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 15101da177e4SLinus Torvalds $prototype =~ s/^inline +//; 15111da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 151232e79401SRandy Dunlap $prototype =~ s/^__inline +//; 151332e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 151432e79401SRandy Dunlap $prototype =~ s/^noinline +//; 151574fc5c65SRandy Dunlap $prototype =~ s/__init +//; 151620072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 1517270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 151870c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 15190df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 1520cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 1521b1aaa546SPaolo Bonzini $prototype =~ s/__attribute__\s*\(\( 1522b1aaa546SPaolo Bonzini (?: 1523b1aaa546SPaolo Bonzini [\w\s]++ # attribute name 1524b1aaa546SPaolo Bonzini (?:\([^)]*+\))? # attribute arguments 1525b1aaa546SPaolo Bonzini \s*+,? # optional comma at the end 1526b1aaa546SPaolo Bonzini )+ 1527b1aaa546SPaolo Bonzini \)\)\s+//x; 15281da177e4SLinus Torvalds 15291da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 15301da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 15311da177e4SLinus Torvalds # 2. Function name 15321da177e4SLinus Torvalds # 3. Function parameters. 15331da177e4SLinus Torvalds # 15341da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 15351da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 15361da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 15371da177e4SLinus Torvalds # so on. 15381da177e4SLinus Torvalds # 15391da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 15401da177e4SLinus Torvalds # the following functions' documentation still comes out right: 15411da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 15421da177e4SLinus Torvalds # - atomic_set (macro) 15439598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 15441da177e4SLinus Torvalds 1545cbb4d3e6SHoria Geanta if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 1546cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 1547cbb4d3e6SHoria Geanta # list. 1548cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 1549cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 1550cbb4d3e6SHoria Geanta $return_type = $1; 1551cbb4d3e6SHoria Geanta $declaration_name = $2; 1552cbb4d3e6SHoria Geanta $noret = 1; 1553cbb4d3e6SHoria Geanta } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 15541da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 15555a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 15561da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 155794b3e03cSRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 15581da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 15595a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 15601da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 15611da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 15625a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 15631da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 15645a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 15651da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 15665a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 15679598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 15685a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 15695a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 15701da177e4SLinus Torvalds $return_type = $1; 15711da177e4SLinus Torvalds $declaration_name = $2; 15721da177e4SLinus Torvalds my $args = $3; 15731da177e4SLinus Torvalds 1574151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 15751da177e4SLinus Torvalds } else { 1576d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 15771da177e4SLinus Torvalds return; 15781da177e4SLinus Torvalds } 15791da177e4SLinus Torvalds 1580a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 15811081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, "function", $sectcheck, $prms); 1582a1d94aa5SRandy Dunlap 15834092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 15844092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 15854092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 15864092bac7SYacine Belkadi # verbose mode. 15874092bac7SYacine Belkadi # TODO: always perform the check. 1588cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 15894092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 15904092bac7SYacine Belkadi } 15914092bac7SYacine Belkadi 15921da177e4SLinus Torvalds output_declaration($declaration_name, 15931da177e4SLinus Torvalds 'function', 15941da177e4SLinus Torvalds {'function' => $declaration_name, 15951da177e4SLinus Torvalds 'module' => $modulename, 15961da177e4SLinus Torvalds 'functiontype' => $return_type, 15971da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 15981da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 15991da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 16001da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 16011da177e4SLinus Torvalds 'sections' => \%sections, 16021da177e4SLinus Torvalds 'purpose' => $declaration_purpose 16031da177e4SLinus Torvalds }); 16041da177e4SLinus Torvalds} 16051da177e4SLinus Torvalds 16061da177e4SLinus Torvaldssub reset_state { 16071da177e4SLinus Torvalds $function = ""; 16081da177e4SLinus Torvalds %parameterdescs = (); 16091da177e4SLinus Torvalds %parametertypes = (); 16101da177e4SLinus Torvalds @parameterlist = (); 16111da177e4SLinus Torvalds %sections = (); 16121da177e4SLinus Torvalds @sectionlist = (); 1613a1d94aa5SRandy Dunlap $sectcheck = ""; 1614a1d94aa5SRandy Dunlap $struct_actual = ""; 16151da177e4SLinus Torvalds $prototype = ""; 16161da177e4SLinus Torvalds 161748af606aSJani Nikula $state = STATE_NORMAL; 161848af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 16191da177e4SLinus Torvalds} 16201da177e4SLinus Torvalds 162156afb0f8SJason Baronsub tracepoint_munge($) { 162256afb0f8SJason Baron my $file = shift; 162356afb0f8SJason Baron my $tracepointname = 0; 162456afb0f8SJason Baron my $tracepointargs = 0; 162556afb0f8SJason Baron 162656afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 162756afb0f8SJason Baron $tracepointname = $1; 162856afb0f8SJason Baron } 16293a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 16303a9089fdSJason Baron $tracepointname = $1; 16313a9089fdSJason Baron } 16323a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 16333a9089fdSJason Baron $tracepointname = $2; 16343a9089fdSJason Baron } 16353a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 163656afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 163756afb0f8SJason Baron $tracepointargs = $1; 163856afb0f8SJason Baron } 163956afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 1640d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 164156afb0f8SJason Baron "$prototype\n"; 164256afb0f8SJason Baron } else { 164356afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 164456afb0f8SJason Baron } 164556afb0f8SJason Baron} 164656afb0f8SJason Baron 1647b4870bc5SRandy Dunlapsub syscall_munge() { 1648b4870bc5SRandy Dunlap my $void = 0; 1649b4870bc5SRandy Dunlap 16507c9aa015SMauro Carvalho Chehab $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's 1651b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 1652b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 1653b4870bc5SRandy Dunlap $void = 1; 1654b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 1655b4870bc5SRandy Dunlap } 1656b4870bc5SRandy Dunlap 1657b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 1658b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 1659b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 1660b4870bc5SRandy Dunlap } elsif ($void) { 1661b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 1662b4870bc5SRandy Dunlap } 1663b4870bc5SRandy Dunlap 1664b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 1665b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 1666b4870bc5SRandy Dunlap my $count = 0; 1667b4870bc5SRandy Dunlap my $len = length($prototype); 1668b4870bc5SRandy Dunlap if ($void) { 1669b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 1670b4870bc5SRandy Dunlap } 1671b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 1672b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 1673b4870bc5SRandy Dunlap $count++; 1674b4870bc5SRandy Dunlap if ($count % 2 == 1) { 1675b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 1676b4870bc5SRandy Dunlap } 1677b4870bc5SRandy Dunlap } 1678b4870bc5SRandy Dunlap } 1679b4870bc5SRandy Dunlap} 1680b4870bc5SRandy Dunlap 1681b7afa92bSDaniel Vettersub process_proto_function($$) { 16821da177e4SLinus Torvalds my $x = shift; 16831da177e4SLinus Torvalds my $file = shift; 16841da177e4SLinus Torvalds 168551f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 168651f5a0c8SRandy Dunlap 1687890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 16881da177e4SLinus Torvalds # do nothing 16891da177e4SLinus Torvalds } 16901da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 16911da177e4SLinus Torvalds $prototype .= $1; 16921da177e4SLinus Torvalds } 1693b4870bc5SRandy Dunlap 1694890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 16951da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 16961da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 16971da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 1698b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 1699b4870bc5SRandy Dunlap syscall_munge(); 1700b4870bc5SRandy Dunlap } 17013a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 17023a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 17033a9089fdSJason Baron { 170456afb0f8SJason Baron tracepoint_munge($file); 170556afb0f8SJason Baron } 17061da177e4SLinus Torvalds dump_function($prototype, $file); 17071da177e4SLinus Torvalds reset_state(); 17081da177e4SLinus Torvalds } 17091da177e4SLinus Torvalds} 17101da177e4SLinus Torvalds 1711b7afa92bSDaniel Vettersub process_proto_type($$) { 17121da177e4SLinus Torvalds my $x = shift; 17131da177e4SLinus Torvalds my $file = shift; 17141da177e4SLinus Torvalds 17151da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 17161da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 17171da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 171851f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 171951f5a0c8SRandy Dunlap 17201da177e4SLinus Torvalds if ($x =~ /^#/) { 17211da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 17221da177e4SLinus Torvalds $x .= ";"; 17231da177e4SLinus Torvalds } 17241da177e4SLinus Torvalds 17251da177e4SLinus Torvalds while (1) { 17261da177e4SLinus Torvalds if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 1727463a0fdcSMarkus Heiser if( length $prototype ) { 1728463a0fdcSMarkus Heiser $prototype .= " " 1729463a0fdcSMarkus Heiser } 17301da177e4SLinus Torvalds $prototype .= $1 . $2; 17311da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 17321da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 17331da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 17341da177e4SLinus Torvalds dump_declaration($prototype, $file); 17351da177e4SLinus Torvalds reset_state(); 17361da177e4SLinus Torvalds last; 17371da177e4SLinus Torvalds } 17381da177e4SLinus Torvalds $x = $3; 17391da177e4SLinus Torvalds } else { 17401da177e4SLinus Torvalds $prototype .= $x; 17411da177e4SLinus Torvalds last; 17421da177e4SLinus Torvalds } 17431da177e4SLinus Torvalds } 17441da177e4SLinus Torvalds} 17451da177e4SLinus Torvalds 17466b5b55f6SRandy Dunlap 17471ad560e4SJani Nikulasub map_filename($) { 17481ad560e4SJani Nikula my $file; 17491ad560e4SJani Nikula my ($orig_file) = @_; 17501ad560e4SJani Nikula 17511ad560e4SJani Nikula if (defined($ENV{'SRCTREE'})) { 17521ad560e4SJani Nikula $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 17531ad560e4SJani Nikula } else { 17541ad560e4SJani Nikula $file = $orig_file; 17551ad560e4SJani Nikula } 17561ad560e4SJani Nikula 17571ad560e4SJani Nikula if (defined($source_map{$file})) { 17581ad560e4SJani Nikula $file = $source_map{$file}; 17591ad560e4SJani Nikula } 17601ad560e4SJani Nikula 17611ad560e4SJani Nikula return $file; 17621ad560e4SJani Nikula} 17631ad560e4SJani Nikula 176488c2b57dSJani Nikulasub process_export_file($) { 176588c2b57dSJani Nikula my ($orig_file) = @_; 176688c2b57dSJani Nikula my $file = map_filename($orig_file); 176788c2b57dSJani Nikula 176888c2b57dSJani Nikula if (!open(IN,"<$file")) { 176988c2b57dSJani Nikula print STDERR "Error: Cannot open file $file\n"; 177088c2b57dSJani Nikula ++$errors; 177188c2b57dSJani Nikula return; 177288c2b57dSJani Nikula } 177388c2b57dSJani Nikula 177488c2b57dSJani Nikula while (<IN>) { 177588c2b57dSJani Nikula if (/$export_symbol/) { 177688c2b57dSJani Nikula $function_table{$2} = 1; 177788c2b57dSJani Nikula } 177888c2b57dSJani Nikula } 177988c2b57dSJani Nikula 178088c2b57dSJani Nikula close(IN); 178188c2b57dSJani Nikula} 178288c2b57dSJani Nikula 178307048d13SJonathan Corbet# 178407048d13SJonathan Corbet# Parsers for the various processing states. 178507048d13SJonathan Corbet# 178607048d13SJonathan Corbet# STATE_NORMAL: looking for the /** to begin everything. 178707048d13SJonathan Corbet# 178807048d13SJonathan Corbetsub process_normal() { 178907048d13SJonathan Corbet if (/$doc_start/o) { 179007048d13SJonathan Corbet $state = STATE_NAME; # next line is always the function name 179107048d13SJonathan Corbet $in_doc_sect = 0; 179207048d13SJonathan Corbet $declaration_start_line = $. + 1; 179307048d13SJonathan Corbet } 179407048d13SJonathan Corbet} 179507048d13SJonathan Corbet 1796*3cac2bc4SJonathan Corbet# 1797*3cac2bc4SJonathan Corbet# STATE_NAME: Looking for the "name - description" line 1798*3cac2bc4SJonathan Corbet# 1799*3cac2bc4SJonathan Corbetsub process_name($$) { 1800*3cac2bc4SJonathan Corbet my $file = shift; 18011da177e4SLinus Torvalds my $identifier; 1802a21217daSRandy Dunlap my $descr; 18031da177e4SLinus Torvalds 18041da177e4SLinus Torvalds if (/$doc_block/o) { 180548af606aSJani Nikula $state = STATE_DOCBLOCK; 18061da177e4SLinus Torvalds $contents = ""; 18070b0f5f29SDaniel Vetter $new_start_line = $. + 1; 18080b0f5f29SDaniel Vetter 18091da177e4SLinus Torvalds if ( $1 eq "" ) { 18101da177e4SLinus Torvalds $section = $section_intro; 18111da177e4SLinus Torvalds } else { 18121da177e4SLinus Torvalds $section = $1; 18131da177e4SLinus Torvalds } 18141da177e4SLinus Torvalds } 18151da177e4SLinus Torvalds elsif (/$doc_decl/o) { 18161da177e4SLinus Torvalds $identifier = $1; 18171da177e4SLinus Torvalds if (/\s*([\w\s]+?)\s*-/) { 18181da177e4SLinus Torvalds $identifier = $1; 18191da177e4SLinus Torvalds } 18201da177e4SLinus Torvalds 182117b78717SJonathan Corbet $state = STATE_BODY; 18220b0f5f29SDaniel Vetter # if there's no @param blocks need to set up default section 18230b0f5f29SDaniel Vetter # here 18242f4ad40aSJani Nikula $contents = ""; 18252f4ad40aSJani Nikula $section = $section_default; 18260b0f5f29SDaniel Vetter $new_start_line = $. + 1; 18271da177e4SLinus Torvalds if (/-(.*)/) { 182851f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 1829a21217daSRandy Dunlap $descr= $1; 1830a21217daSRandy Dunlap $descr =~ s/^\s*//; 1831a21217daSRandy Dunlap $descr =~ s/\s*$//; 183212ae6779SDaniel Santos $descr =~ s/\s+/ /g; 18330bba924cSJonathan Corbet $declaration_purpose = $descr; 183417b78717SJonathan Corbet $state = STATE_BODY_MAYBE; 18351da177e4SLinus Torvalds } else { 18361da177e4SLinus Torvalds $declaration_purpose = ""; 18371da177e4SLinus Torvalds } 183877cc23b8SRandy Dunlap 183977cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 1840d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 184177cc23b8SRandy Dunlap print STDERR $_; 184277cc23b8SRandy Dunlap ++$warnings; 184377cc23b8SRandy Dunlap } 184477cc23b8SRandy Dunlap 18451da177e4SLinus Torvalds if ($identifier =~ m/^struct/) { 18461da177e4SLinus Torvalds $decl_type = 'struct'; 18471da177e4SLinus Torvalds } elsif ($identifier =~ m/^union/) { 18481da177e4SLinus Torvalds $decl_type = 'union'; 18491da177e4SLinus Torvalds } elsif ($identifier =~ m/^enum/) { 18501da177e4SLinus Torvalds $decl_type = 'enum'; 18511da177e4SLinus Torvalds } elsif ($identifier =~ m/^typedef/) { 18521da177e4SLinus Torvalds $decl_type = 'typedef'; 18531da177e4SLinus Torvalds } else { 18541da177e4SLinus Torvalds $decl_type = 'function'; 18551da177e4SLinus Torvalds } 18561da177e4SLinus Torvalds 18571da177e4SLinus Torvalds if ($verbose) { 1858d40e1e65SBart Van Assche print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; 18591da177e4SLinus Torvalds } 18601da177e4SLinus Torvalds } else { 1861d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 18621da177e4SLinus Torvalds " - I thought it was a doc line\n"; 18631da177e4SLinus Torvalds ++$warnings; 186448af606aSJani Nikula $state = STATE_NORMAL; 18651da177e4SLinus Torvalds } 1866*3cac2bc4SJonathan Corbet} 1867*3cac2bc4SJonathan Corbet 1868*3cac2bc4SJonathan Corbetsub process_file($) { 1869*3cac2bc4SJonathan Corbet my $file; 1870*3cac2bc4SJonathan Corbet my $func; 1871*3cac2bc4SJonathan Corbet my $initial_section_counter = $section_counter; 1872*3cac2bc4SJonathan Corbet my ($orig_file) = @_; 1873*3cac2bc4SJonathan Corbet my $leading_space; 1874*3cac2bc4SJonathan Corbet 1875*3cac2bc4SJonathan Corbet $file = map_filename($orig_file); 1876*3cac2bc4SJonathan Corbet 1877*3cac2bc4SJonathan Corbet if (!open(IN,"<$file")) { 1878*3cac2bc4SJonathan Corbet print STDERR "Error: Cannot open file $file\n"; 1879*3cac2bc4SJonathan Corbet ++$errors; 1880*3cac2bc4SJonathan Corbet return; 1881*3cac2bc4SJonathan Corbet } 1882*3cac2bc4SJonathan Corbet 1883*3cac2bc4SJonathan Corbet $. = 1; 1884*3cac2bc4SJonathan Corbet 1885*3cac2bc4SJonathan Corbet $section_counter = 0; 1886*3cac2bc4SJonathan Corbet while (<IN>) { 1887*3cac2bc4SJonathan Corbet while (s/\\\s*$//) { 1888*3cac2bc4SJonathan Corbet $_ .= <IN>; 1889*3cac2bc4SJonathan Corbet } 1890*3cac2bc4SJonathan Corbet # Replace tabs by spaces 1891*3cac2bc4SJonathan Corbet while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; 1892*3cac2bc4SJonathan Corbet if ($state == STATE_NORMAL) { 1893*3cac2bc4SJonathan Corbet process_normal(); 1894*3cac2bc4SJonathan Corbet } elsif ($state == STATE_NAME) { 1895*3cac2bc4SJonathan Corbet process_name($file, $_); 189617b78717SJonathan Corbet } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE) { 1897f624adefSJani Nikula if (/$doc_sect/i) { # case insensitive for supported section names 18981da177e4SLinus Torvalds $newsection = $1; 18991da177e4SLinus Torvalds $newcontents = $2; 19001da177e4SLinus Torvalds 1901f624adefSJani Nikula # map the supported section names to the canonical names 1902f624adefSJani Nikula if ($newsection =~ m/^description$/i) { 1903f624adefSJani Nikula $newsection = $section_default; 1904f624adefSJani Nikula } elsif ($newsection =~ m/^context$/i) { 1905f624adefSJani Nikula $newsection = $section_context; 1906f624adefSJani Nikula } elsif ($newsection =~ m/^returns?$/i) { 1907f624adefSJani Nikula $newsection = $section_return; 1908f624adefSJani Nikula } elsif ($newsection =~ m/^\@return$/) { 1909f624adefSJani Nikula # special: @return is a section, not a param description 1910f624adefSJani Nikula $newsection = $section_return; 1911f624adefSJani Nikula } 1912f624adefSJani Nikula 1913792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 1914850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 1915d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: contents before sections\n"; 1916850622dfSRandy Dunlap ++$warnings; 1917850622dfSRandy Dunlap } 19180bba924cSJonathan Corbet dump_section($file, $section, $contents); 19191da177e4SLinus Torvalds $section = $section_default; 19201da177e4SLinus Torvalds } 19211da177e4SLinus Torvalds 1922850622dfSRandy Dunlap $in_doc_sect = 1; 192317b78717SJonathan Corbet $state = STATE_BODY; 19241da177e4SLinus Torvalds $contents = $newcontents; 19250b0f5f29SDaniel Vetter $new_start_line = $.; 19267c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 192705189497SRandy Dunlap $contents = substr($contents, 1); 192805189497SRandy Dunlap } 19290a726301SJani Nikula if ($contents ne "") { 19301da177e4SLinus Torvalds $contents .= "\n"; 19311da177e4SLinus Torvalds } 19321da177e4SLinus Torvalds $section = $newsection; 1933b7886de4SJani Nikula $leading_space = undef; 19341da177e4SLinus Torvalds } elsif (/$doc_end/) { 19354c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 19360bba924cSJonathan Corbet dump_section($file, $section, $contents); 19371da177e4SLinus Torvalds $section = $section_default; 19381da177e4SLinus Torvalds $contents = ""; 19391da177e4SLinus Torvalds } 194046b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 194146b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 1942d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: suspicious ending line: $_"; 194346b958ebSRandy Dunlap ++$warnings; 194446b958ebSRandy Dunlap } 19451da177e4SLinus Torvalds 19461da177e4SLinus Torvalds $prototype = ""; 194748af606aSJani Nikula $state = STATE_PROTO; 19481da177e4SLinus Torvalds $brcount = 0; 19491da177e4SLinus Torvalds# print STDERR "end of doc comment, looking for prototype\n"; 19501da177e4SLinus Torvalds } elsif (/$doc_content/) { 19511da177e4SLinus Torvalds # miguel-style comment kludge, look for blank lines after 19521da177e4SLinus Torvalds # @parameter line to signify start of description 19536423133bSJohannes Weiner if ($1 eq "") { 19546423133bSJohannes Weiner if ($section =~ m/^@/ || $section eq $section_context) { 19550bba924cSJonathan Corbet dump_section($file, $section, $contents); 19561da177e4SLinus Torvalds $section = $section_default; 19571da177e4SLinus Torvalds $contents = ""; 19580b0f5f29SDaniel Vetter $new_start_line = $.; 19591da177e4SLinus Torvalds } else { 19606423133bSJohannes Weiner $contents .= "\n"; 19616423133bSJohannes Weiner } 196217b78717SJonathan Corbet $state = STATE_BODY; 196317b78717SJonathan Corbet } elsif ($state == STATE_BODY_MAYBE) { 19646423133bSJohannes Weiner # Continued declaration purpose 19656423133bSJohannes Weiner chomp($declaration_purpose); 19660bba924cSJonathan Corbet $declaration_purpose .= " " . $1; 196712ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 19686423133bSJohannes Weiner } else { 1969b7886de4SJani Nikula my $cont = $1; 1970b7886de4SJani Nikula if ($section =~ m/^@/ || $section eq $section_context) { 1971b7886de4SJani Nikula if (!defined $leading_space) { 1972b7886de4SJani Nikula if ($cont =~ m/^(\s+)/) { 1973b7886de4SJani Nikula $leading_space = $1; 1974b7886de4SJani Nikula } else { 1975b7886de4SJani Nikula $leading_space = ""; 1976b7886de4SJani Nikula } 1977b7886de4SJani Nikula } 1978b7886de4SJani Nikula 1979b7886de4SJani Nikula $cont =~ s/^$leading_space//; 1980b7886de4SJani Nikula } 1981b7886de4SJani Nikula $contents .= $cont . "\n"; 19821da177e4SLinus Torvalds } 19831da177e4SLinus Torvalds } else { 19841da177e4SLinus Torvalds # i dont know - bad line? ignore. 1985d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: bad line: $_"; 19861da177e4SLinus Torvalds ++$warnings; 19871da177e4SLinus Torvalds } 198848af606aSJani Nikula } elsif ($state == STATE_INLINE) { # scanning for inline parameters 1989a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 199048af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 1991a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 1992a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 19930b0f5f29SDaniel Vetter $new_start_line = $.; 1994a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 19957c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 1996a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 1997a4c6ebedSDanilo Cesar Lemes de Paula } 1998a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 1999a4c6ebedSDanilo Cesar Lemes de Paula } 200048af606aSJani Nikula $inline_doc_state = STATE_INLINE_TEXT; 2001a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 200248af606aSJani Nikula } elsif (/$doc_inline_end/) { 2003a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 20040bba924cSJonathan Corbet dump_section($file, $section, $contents); 2005a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 2006a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 2007a4c6ebedSDanilo Cesar Lemes de Paula } 200848af606aSJani Nikula $state = STATE_PROTO; 200948af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 2010a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 2011a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 201248af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_TEXT) { 2013a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 20146450c895SJani Nikula # nuke leading blank lines 20156450c895SJani Nikula if ($contents =~ /^\s*$/) { 20166450c895SJani Nikula $contents = ""; 20176450c895SJani Nikula } 201848af606aSJani Nikula } elsif ($inline_doc_state == STATE_INLINE_NAME) { 201948af606aSJani Nikula $inline_doc_state = STATE_INLINE_ERROR; 2020e7ca311eSDaniel Vetter print STDERR "${file}:$.: warning: "; 2021a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Incorrect use of kernel-doc format: $_"; 2022a4c6ebedSDanilo Cesar Lemes de Paula ++$warnings; 2023a4c6ebedSDanilo Cesar Lemes de Paula } 2024a4c6ebedSDanilo Cesar Lemes de Paula } 202548af606aSJani Nikula } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype) 20260c9aa209SJani Nikula if (/$doc_inline_oneline/) { 20270c9aa209SJani Nikula $section = $1; 20280c9aa209SJani Nikula $contents = $2; 20290c9aa209SJani Nikula if ($contents ne "") { 20300c9aa209SJani Nikula $contents .= "\n"; 20310bba924cSJonathan Corbet dump_section($file, $section, $contents); 20320c9aa209SJani Nikula $section = $section_default; 20330c9aa209SJani Nikula $contents = ""; 20340c9aa209SJani Nikula } 20350c9aa209SJani Nikula } elsif (/$doc_inline_start/) { 203648af606aSJani Nikula $state = STATE_INLINE; 203748af606aSJani Nikula $inline_doc_state = STATE_INLINE_NAME; 2038a4c6ebedSDanilo Cesar Lemes de Paula } elsif ($decl_type eq 'function') { 2039b7afa92bSDaniel Vetter process_proto_function($_, $file); 20401da177e4SLinus Torvalds } else { 2041b7afa92bSDaniel Vetter process_proto_type($_, $file); 20421da177e4SLinus Torvalds } 204348af606aSJani Nikula } elsif ($state == STATE_DOCBLOCK) { 2044ebff7f92SDaniel Vetter if (/$doc_end/) 20451da177e4SLinus Torvalds { 20460bba924cSJonathan Corbet dump_doc_section($file, $section, $contents); 20472f4ad40aSJani Nikula $section = $section_default; 20481da177e4SLinus Torvalds $contents = ""; 20491da177e4SLinus Torvalds $function = ""; 20501da177e4SLinus Torvalds %parameterdescs = (); 20511da177e4SLinus Torvalds %parametertypes = (); 20521da177e4SLinus Torvalds @parameterlist = (); 20531da177e4SLinus Torvalds %sections = (); 20541da177e4SLinus Torvalds @sectionlist = (); 20551da177e4SLinus Torvalds $prototype = ""; 205648af606aSJani Nikula $state = STATE_NORMAL; 20571da177e4SLinus Torvalds } 20581da177e4SLinus Torvalds elsif (/$doc_content/) 20591da177e4SLinus Torvalds { 20601da177e4SLinus Torvalds if ( $1 eq "" ) 20611da177e4SLinus Torvalds { 20621da177e4SLinus Torvalds $contents .= $blankline; 20631da177e4SLinus Torvalds } 20641da177e4SLinus Torvalds else 20651da177e4SLinus Torvalds { 20661da177e4SLinus Torvalds $contents .= $1 . "\n"; 20671da177e4SLinus Torvalds } 20681da177e4SLinus Torvalds } 20691da177e4SLinus Torvalds } 20701da177e4SLinus Torvalds } 20711da177e4SLinus Torvalds if ($initial_section_counter == $section_counter) { 20723a025e1dSMatthew Wilcox if ($output_mode ne "none") { 2073d40e1e65SBart Van Assche print STDERR "${file}:1: warning: no structured comments found\n"; 20743a025e1dSMatthew Wilcox } 2075b6c3f456SJani Nikula if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) { 2076e946c43aSJohannes Berg print STDERR " Was looking for '$_'.\n" for keys %function_table; 2077e946c43aSJohannes Berg } 20781da177e4SLinus Torvalds } 20791da177e4SLinus Torvalds} 20808484baaaSRandy Dunlap 20818484baaaSRandy Dunlap 20828484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 20838484baaaSRandy Dunlap 20848484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 20858484baaaSRandy Dunlap# using the s// operator. 20861ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 20874d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 20884d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 20894d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 20904d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 20918484baaaSRandy Dunlap} 20928484baaaSRandy Dunlap 20938484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 20948484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 20958484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 20968484baaaSRandy Dunlap my ($relname, $absname); 20978484baaaSRandy Dunlap while(<SOURCE_MAP>) { 20988484baaaSRandy Dunlap chop(); 20998484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 21008484baaaSRandy Dunlap $relname =~ s:^/+::; 21018484baaaSRandy Dunlap $source_map{$relname} = $absname; 21028484baaaSRandy Dunlap } 21038484baaaSRandy Dunlap close(SOURCE_MAP); 21048484baaaSRandy Dunlap} 21058484baaaSRandy Dunlap 210688c2b57dSJani Nikulaif ($output_selection == OUTPUT_EXPORTED || 210788c2b57dSJani Nikula $output_selection == OUTPUT_INTERNAL) { 2108c9b2cfb3SJani Nikula 2109c9b2cfb3SJani Nikula push(@export_file_list, @ARGV); 2110c9b2cfb3SJani Nikula 211188c2b57dSJani Nikula foreach (@export_file_list) { 211288c2b57dSJani Nikula chomp; 211388c2b57dSJani Nikula process_export_file($_); 211488c2b57dSJani Nikula } 211588c2b57dSJani Nikula} 211688c2b57dSJani Nikula 21178484baaaSRandy Dunlapforeach (@ARGV) { 21188484baaaSRandy Dunlap chomp; 21198484baaaSRandy Dunlap process_file($_); 21208484baaaSRandy Dunlap} 21218484baaaSRandy Dunlapif ($verbose && $errors) { 21228484baaaSRandy Dunlap print STDERR "$errors errors\n"; 21238484baaaSRandy Dunlap} 21248484baaaSRandy Dunlapif ($verbose && $warnings) { 21258484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 21268484baaaSRandy Dunlap} 21278484baaaSRandy Dunlap 2128e814bccbSWill Deaconexit($output_mode eq "none" ? 0 : $errors); 2129