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; 339d742f24dSJonathan Corbetmy $leading_space; 3401da177e4SLinus Torvalds 34148af606aSJani Nikula# Inline documentation state 34248af606aSJani Nikulause constant { 34348af606aSJani Nikula STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 34448af606aSJani Nikula STATE_INLINE_NAME => 1, # looking for member name (@foo:) 34548af606aSJani Nikula STATE_INLINE_TEXT => 2, # looking for member documentation 34648af606aSJani Nikula STATE_INLINE_END => 3, # done 34748af606aSJani Nikula STATE_INLINE_ERROR => 4, # error - Comment without header was found. 34848af606aSJani Nikula # Spit a warning as it's not 349a4c6ebedSDanilo Cesar Lemes de Paula # proper kernel-doc and ignore the rest. 35048af606aSJani Nikula}; 35148af606aSJani Nikulamy $inline_doc_state; 352a4c6ebedSDanilo Cesar Lemes de Paula 3531da177e4SLinus Torvalds#declaration types: can be 3541da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 3551da177e4SLinus Torvaldsmy $decl_type; 3561da177e4SLinus Torvalds 3571da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 3581da177e4SLinus Torvaldsmy $doc_end = '\*/'; 3591da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 36012ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 3611da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 362f624adefSJani Nikula# @params and a strictly limited set of supported section names 3638569de68SJonathan Corbetmy $doc_sect = $doc_com . 364ef00028bSJonathan Corbet '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)'; 36512ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 3661da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 36748af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$'; 36848af606aSJani Nikulamy $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)'; 36948af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$'; 3700c9aa209SJani Nikulamy $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; 37186ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 3721da177e4SLinus Torvalds 3731da177e4SLinus Torvaldsmy %parameterdescs; 3740b0f5f29SDaniel Vettermy %parameterdesc_start_lines; 3751da177e4SLinus Torvaldsmy @parameterlist; 3761da177e4SLinus Torvaldsmy %sections; 3771da177e4SLinus Torvaldsmy @sectionlist; 3780b0f5f29SDaniel Vettermy %section_start_lines; 379a1d94aa5SRandy Dunlapmy $sectcheck; 380a1d94aa5SRandy Dunlapmy $struct_actual; 3811da177e4SLinus Torvalds 3821da177e4SLinus Torvaldsmy $contents = ""; 3830b0f5f29SDaniel Vettermy $new_start_line = 0; 384f624adefSJani Nikula 385f624adefSJani Nikula# the canonical section names. see also $doc_sect above. 3861da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 3871da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 3881da177e4SLinus Torvaldsmy $section = $section_default; 3891da177e4SLinus Torvaldsmy $section_context = "Context"; 3904092bac7SYacine Belkadimy $section_return = "Return"; 3911da177e4SLinus Torvalds 3921da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 3931da177e4SLinus Torvalds 3941da177e4SLinus Torvaldsreset_state(); 3951da177e4SLinus Torvalds 396b031ac4eSMauro Carvalho Chehabwhile ($ARGV[0] =~ m/^--?(.*)/) { 397b031ac4eSMauro Carvalho Chehab my $cmd = $1; 398b031ac4eSMauro Carvalho Chehab shift @ARGV; 399b031ac4eSMauro Carvalho Chehab if ($cmd eq "man") { 4001da177e4SLinus Torvalds $output_mode = "man"; 4014d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 4021da177e4SLinus Torvalds $blankline = $blankline_man; 403b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "rst") { 404c0d1b6eeSJonathan Corbet $output_mode = "rst"; 405c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 406c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 407b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "none") { 4083a025e1dSMatthew Wilcox $output_mode = "none"; 409b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document 4101da177e4SLinus Torvalds $modulename = shift @ARGV; 411b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "function") { # to only output specific functions 412b6c3f456SJani Nikula $output_selection = OUTPUT_INCLUDE; 4131da177e4SLinus Torvalds $function = shift @ARGV; 4141da177e4SLinus Torvalds $function_table{$function} = 1; 415b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "nofunction") { # output all except specific functions 416b6c3f456SJani Nikula $output_selection = OUTPUT_EXCLUDE; 4171da177e4SLinus Torvalds $function = shift @ARGV; 4181da177e4SLinus Torvalds $function_table{$function} = 1; 419b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export") { # only exported symbols 420b6c3f456SJani Nikula $output_selection = OUTPUT_EXPORTED; 421da9726ecSJani Nikula %function_table = (); 422b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "internal") { # only non-exported symbols 423b6c3f456SJani Nikula $output_selection = OUTPUT_INTERNAL; 424da9726ecSJani Nikula %function_table = (); 425b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export-file") { 42688c2b57dSJani Nikula my $file = shift @ARGV; 42788c2b57dSJani Nikula push(@export_file_list, $file); 428b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "v") { 4291da177e4SLinus Torvalds $verbose = 1; 430b031ac4eSMauro Carvalho Chehab } elsif (($cmd eq "h") || ($cmd eq "help")) { 4311da177e4SLinus Torvalds usage(); 432b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'no-doc-sections') { 4334b44595aSJohannes Berg $no_doc_sections = 1; 434b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'enable-lineno') { 4350b0f5f29SDaniel Vetter $enable_lineno = 1; 436b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'show-not-found') { 437e946c43aSJohannes Berg $show_not_found = 1; 438b031ac4eSMauro Carvalho Chehab } else { 439b031ac4eSMauro Carvalho Chehab # Unknown argument 440b031ac4eSMauro Carvalho Chehab usage(); 4411da177e4SLinus Torvalds } 4421da177e4SLinus Torvalds} 4431da177e4SLinus Torvalds 4448484baaaSRandy Dunlap# continue execution near EOF; 4458484baaaSRandy Dunlap 44653f049faSBorislav Petkov# get kernel version from env 44753f049faSBorislav Petkovsub get_kernel_version() { 4481b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 44953f049faSBorislav Petkov 45053f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 45153f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 45253f049faSBorislav Petkov } 45353f049faSBorislav Petkov return $version; 45453f049faSBorislav Petkov} 4551da177e4SLinus Torvalds 4560b0f5f29SDaniel Vetter# 4570b0f5f29SDaniel Vettersub print_lineno { 4580b0f5f29SDaniel Vetter my $lineno = shift; 4590b0f5f29SDaniel Vetter if ($enable_lineno && defined($lineno)) { 4600b0f5f29SDaniel Vetter print "#define LINENO " . $lineno . "\n"; 4610b0f5f29SDaniel Vetter } 4620b0f5f29SDaniel Vetter} 4631da177e4SLinus Torvalds## 4641da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 4651da177e4SLinus Torvalds# 4661da177e4SLinus Torvaldssub dump_section { 46794dc7ad5SRandy Dunlap my $file = shift; 4681da177e4SLinus Torvalds my $name = shift; 4691da177e4SLinus Torvalds my $contents = join "\n", @_; 4701da177e4SLinus Torvalds 47113901ef2SJani Nikula if ($name =~ m/$type_param/) { 4721da177e4SLinus Torvalds $name = $1; 4731da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 474a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 4750b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 4760b0f5f29SDaniel Vetter $new_start_line = 0; 477ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 478ced69090SRandy Dunlap $name = "..."; 479ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 480a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 4810b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 4820b0f5f29SDaniel Vetter $new_start_line = 0; 4831da177e4SLinus Torvalds } else { 48494dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 48595b6be9dSJani Nikula # Only warn on user specified duplicate section names. 48695b6be9dSJani Nikula if ($name ne $section_default) { 48732217761SJani Nikula print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; 48832217761SJani Nikula ++$warnings; 48995b6be9dSJani Nikula } 49032217761SJani Nikula $sections{$name} .= $contents; 49132217761SJani Nikula } else { 4921da177e4SLinus Torvalds $sections{$name} = $contents; 4931da177e4SLinus Torvalds push @sectionlist, $name; 4940b0f5f29SDaniel Vetter $section_start_lines{$name} = $new_start_line; 4950b0f5f29SDaniel Vetter $new_start_line = 0; 4961da177e4SLinus Torvalds } 4971da177e4SLinus Torvalds } 49832217761SJani Nikula} 4991da177e4SLinus Torvalds 5001da177e4SLinus Torvalds## 501b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 502b112e0f7SJohannes Berg# 503b112e0f7SJohannes Bergsub dump_doc_section { 50494dc7ad5SRandy Dunlap my $file = shift; 505b112e0f7SJohannes Berg my $name = shift; 506b112e0f7SJohannes Berg my $contents = join "\n", @_; 507b112e0f7SJohannes Berg 5084b44595aSJohannes Berg if ($no_doc_sections) { 5094b44595aSJohannes Berg return; 5104b44595aSJohannes Berg } 5114b44595aSJohannes Berg 512b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 513b6c3f456SJani Nikula ($output_selection == OUTPUT_INCLUDE && 514b6c3f456SJani Nikula defined($function_table{$name})) || 515b6c3f456SJani Nikula ($output_selection == OUTPUT_EXCLUDE && 516b6c3f456SJani Nikula !defined($function_table{$name}))) 517b112e0f7SJohannes Berg { 51894dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 519b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 520b112e0f7SJohannes Berg 'sections' => \%sections, 521b112e0f7SJohannes Berg 'module' => $modulename, 522b6c3f456SJani Nikula 'content-only' => ($output_selection != OUTPUT_ALL), }); 523b112e0f7SJohannes Berg } 524b112e0f7SJohannes Berg} 525b112e0f7SJohannes Berg 526b112e0f7SJohannes Berg## 5271da177e4SLinus Torvalds# output function 5281da177e4SLinus Torvalds# 5291da177e4SLinus Torvalds# parameterdescs, a hash. 5301da177e4SLinus Torvalds# function => "function name" 5311da177e4SLinus Torvalds# parameterlist => @list of parameters 5321da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 5331da177e4SLinus Torvalds# sectionlist => @list of sections 534a21217daSRandy Dunlap# sections => %section descriptions 5351da177e4SLinus Torvalds# 5361da177e4SLinus Torvalds 5371da177e4SLinus Torvaldssub output_highlight { 5381da177e4SLinus Torvalds my $contents = join "\n",@_; 5391da177e4SLinus Torvalds my $line; 5401da177e4SLinus Torvalds 5411da177e4SLinus Torvalds# DEBUG 5421da177e4SLinus Torvalds# if (!defined $contents) { 5431da177e4SLinus Torvalds# use Carp; 5441da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 5451da177e4SLinus Torvalds# } 5461da177e4SLinus Torvalds 5473eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 5481da177e4SLinus Torvalds eval $dohighlight; 5491da177e4SLinus Torvalds die $@ if $@; 5503eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 5513eb014a1SRandy Dunlap 5521da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 55312ae6779SDaniel Santos if (! $output_preformatted) { 55412ae6779SDaniel Santos $line =~ s/^\s*//; 55512ae6779SDaniel Santos } 5561da177e4SLinus Torvalds if ($line eq ""){ 557e314ba31SDaniel Santos if (! $output_preformatted) { 5580bba924cSJonathan Corbet print $lineprefix, $blankline; 559e314ba31SDaniel Santos } 5601da177e4SLinus Torvalds } else { 561cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 562cdccb316SRandy Dunlap print "\\&$line"; 563cdccb316SRandy Dunlap } else { 5641da177e4SLinus Torvalds print $lineprefix, $line; 5651da177e4SLinus Torvalds } 566cdccb316SRandy Dunlap } 5671da177e4SLinus Torvalds print "\n"; 5681da177e4SLinus Torvalds } 5691da177e4SLinus Torvalds} 5701da177e4SLinus Torvalds 5711da177e4SLinus Torvalds## 5721da177e4SLinus Torvalds# output function in man 5731da177e4SLinus Torvaldssub output_function_man(%) { 5741da177e4SLinus Torvalds my %args = %{$_[0]}; 5751da177e4SLinus Torvalds my ($parameter, $section); 5761da177e4SLinus Torvalds my $count; 5771da177e4SLinus Torvalds 5781da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 5791da177e4SLinus Torvalds 5801da177e4SLinus Torvalds print ".SH NAME\n"; 5811da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 5821da177e4SLinus Torvalds 5831da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 584a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 5851da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 586a21217daSRandy Dunlap } else { 587a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 588a21217daSRandy Dunlap } 5891da177e4SLinus Torvalds $count = 0; 5901da177e4SLinus Torvalds my $parenth = "("; 5911da177e4SLinus Torvalds my $post = ","; 5921da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 5931da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 5941da177e4SLinus Torvalds $post = ");"; 5951da177e4SLinus Torvalds } 5961da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 5971da177e4SLinus Torvalds if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 5981da177e4SLinus Torvalds # pointer-to-function 5991da177e4SLinus Torvalds print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 6001da177e4SLinus Torvalds } else { 6011da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 6021da177e4SLinus Torvalds print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 6031da177e4SLinus Torvalds } 6041da177e4SLinus Torvalds $count++; 6051da177e4SLinus Torvalds $parenth = ""; 6061da177e4SLinus Torvalds } 6071da177e4SLinus Torvalds 6081da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 6091da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6101da177e4SLinus Torvalds my $parameter_name = $parameter; 6111da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6121da177e4SLinus Torvalds 6131da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 6141da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6151da177e4SLinus Torvalds } 6161da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6171da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 6181da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6191da177e4SLinus Torvalds } 6201da177e4SLinus Torvalds} 6211da177e4SLinus Torvalds 6221da177e4SLinus Torvalds## 6231da177e4SLinus Torvalds# output enum in man 6241da177e4SLinus Torvaldssub output_enum_man(%) { 6251da177e4SLinus Torvalds my %args = %{$_[0]}; 6261da177e4SLinus Torvalds my ($parameter, $section); 6271da177e4SLinus Torvalds my $count; 6281da177e4SLinus Torvalds 6291da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 6301da177e4SLinus Torvalds 6311da177e4SLinus Torvalds print ".SH NAME\n"; 6321da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 6331da177e4SLinus Torvalds 6341da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 6351da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 6361da177e4SLinus Torvalds $count = 0; 6371da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 6381da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 6391da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 6401da177e4SLinus Torvalds print "\n};\n"; 6411da177e4SLinus Torvalds last; 6421da177e4SLinus Torvalds } 6431da177e4SLinus Torvalds else { 6441da177e4SLinus Torvalds print ", \n.br\n"; 6451da177e4SLinus Torvalds } 6461da177e4SLinus Torvalds $count++; 6471da177e4SLinus Torvalds } 6481da177e4SLinus Torvalds 6491da177e4SLinus Torvalds print ".SH Constants\n"; 6501da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6511da177e4SLinus Torvalds my $parameter_name = $parameter; 6521da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6531da177e4SLinus Torvalds 6541da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 6551da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6561da177e4SLinus Torvalds } 6571da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6581da177e4SLinus Torvalds print ".SH \"$section\"\n"; 6591da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6601da177e4SLinus Torvalds } 6611da177e4SLinus Torvalds} 6621da177e4SLinus Torvalds 6631da177e4SLinus Torvalds## 6641da177e4SLinus Torvalds# output struct in man 6651da177e4SLinus Torvaldssub output_struct_man(%) { 6661da177e4SLinus Torvalds my %args = %{$_[0]}; 6671da177e4SLinus Torvalds my ($parameter, $section); 6681da177e4SLinus Torvalds 6691da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 6701da177e4SLinus Torvalds 6711da177e4SLinus Torvalds print ".SH NAME\n"; 6721da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 6731da177e4SLinus Torvalds 6748ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 6758ad72163SMauro Carvalho Chehab $declaration =~ s/\t/ /g; 6768ad72163SMauro Carvalho Chehab $declaration =~ s/\n/"\n.br\n.BI \"/g; 6771da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 6781da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 6798ad72163SMauro Carvalho Chehab print ".BI \"$declaration\n};\n.br\n\n"; 6801da177e4SLinus Torvalds 681c51d3dacSRandy Dunlap print ".SH Members\n"; 6821da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6831da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 6841da177e4SLinus Torvalds 6851da177e4SLinus Torvalds my $parameter_name = $parameter; 6861da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6871da177e4SLinus Torvalds 6881da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6891da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 6901da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6911da177e4SLinus Torvalds } 6921da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6931da177e4SLinus Torvalds print ".SH \"$section\"\n"; 6941da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6951da177e4SLinus Torvalds } 6961da177e4SLinus Torvalds} 6971da177e4SLinus Torvalds 6981da177e4SLinus Torvalds## 6991da177e4SLinus Torvalds# output typedef in man 7001da177e4SLinus Torvaldssub output_typedef_man(%) { 7011da177e4SLinus Torvalds my %args = %{$_[0]}; 7021da177e4SLinus Torvalds my ($parameter, $section); 7031da177e4SLinus Torvalds 7041da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 7051da177e4SLinus Torvalds 7061da177e4SLinus Torvalds print ".SH NAME\n"; 7071da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 7081da177e4SLinus Torvalds 7091da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7101da177e4SLinus Torvalds print ".SH \"$section\"\n"; 7111da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7121da177e4SLinus Torvalds } 7131da177e4SLinus Torvalds} 7141da177e4SLinus Torvalds 715b112e0f7SJohannes Bergsub output_blockhead_man(%) { 7161da177e4SLinus Torvalds my %args = %{$_[0]}; 7171da177e4SLinus Torvalds my ($parameter, $section); 7181da177e4SLinus Torvalds my $count; 7191da177e4SLinus Torvalds 7201da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 7211da177e4SLinus Torvalds 7221da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7231da177e4SLinus Torvalds print ".SH \"$section\"\n"; 7241da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7251da177e4SLinus Torvalds } 7261da177e4SLinus Torvalds} 7271da177e4SLinus Torvalds 7281da177e4SLinus Torvalds## 729c0d1b6eeSJonathan Corbet# output in restructured text 730c0d1b6eeSJonathan Corbet# 731c0d1b6eeSJonathan Corbet 732c0d1b6eeSJonathan Corbet# 733c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 734c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 735c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 736c0d1b6eeSJonathan Corbet# 737c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 738c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 739c0d1b6eeSJonathan Corbet my ($parameter, $section); 740c0d1b6eeSJonathan Corbet 741c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 7429e72184bSJani Nikula if ($output_selection != OUTPUT_INCLUDE) { 743c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 7449e72184bSJani Nikula } 7450b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 746c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 747c0d1b6eeSJonathan Corbet print "\n"; 748c0d1b6eeSJonathan Corbet } 749c0d1b6eeSJonathan Corbet} 750c0d1b6eeSJonathan Corbet 751*af250290SJonathan Corbet# 752*af250290SJonathan Corbet# Apply the RST highlights to a sub-block of text. 753*af250290SJonathan Corbet# 754*af250290SJonathan Corbetsub highlight_block($) { 755*af250290SJonathan Corbet # The dohighlight kludge requires the text be called $contents 756*af250290SJonathan Corbet my $contents = shift; 757c0d1b6eeSJonathan Corbet eval $dohighlight; 758c0d1b6eeSJonathan Corbet die $@ if $@; 759*af250290SJonathan Corbet return $contents; 760*af250290SJonathan Corbet} 761c0d1b6eeSJonathan Corbet 762*af250290SJonathan Corbet# 763*af250290SJonathan Corbet# Regexes used only here. 764*af250290SJonathan Corbet# 765*af250290SJonathan Corbetmy $sphinx_literal = '^[^.].*::$'; 766*af250290SJonathan Corbetmy $sphinx_cblock = '^\.\.\ +code-block::'; 767*af250290SJonathan Corbet 768*af250290SJonathan Corbetsub output_highlight_rst { 769*af250290SJonathan Corbet my $input = join "\n",@_; 770*af250290SJonathan Corbet my $output = ""; 771*af250290SJonathan Corbet my $line; 772*af250290SJonathan Corbet my $in_literal = 0; 773*af250290SJonathan Corbet my $litprefix; 774*af250290SJonathan Corbet my $block = ""; 775*af250290SJonathan Corbet 776*af250290SJonathan Corbet foreach $line (split "\n",$input) { 777*af250290SJonathan Corbet # 778*af250290SJonathan Corbet # If we're in a literal block, see if we should drop out 779*af250290SJonathan Corbet # of it. Otherwise pass the line straight through unmunged. 780*af250290SJonathan Corbet # 781*af250290SJonathan Corbet if ($in_literal) { 782*af250290SJonathan Corbet if (! ($line =~ /^\s*$/)) { 783*af250290SJonathan Corbet # 784*af250290SJonathan Corbet # If this is the first non-blank line in a literal 785*af250290SJonathan Corbet # block we need to figure out what the proper indent is. 786*af250290SJonathan Corbet # 787*af250290SJonathan Corbet if ($litprefix eq "") { 788*af250290SJonathan Corbet $line =~ /^(\s*)/; 789*af250290SJonathan Corbet $litprefix = '^' . $1; 790*af250290SJonathan Corbet $output .= $line . "\n"; 791*af250290SJonathan Corbet } elsif (! ($line =~ /$litprefix/)) { 792*af250290SJonathan Corbet $in_literal = 0; 793*af250290SJonathan Corbet } else { 794*af250290SJonathan Corbet $output .= $line . "\n"; 795*af250290SJonathan Corbet } 796*af250290SJonathan Corbet } else { 797*af250290SJonathan Corbet $output .= $line . "\n"; 798*af250290SJonathan Corbet } 799*af250290SJonathan Corbet } 800*af250290SJonathan Corbet # 801*af250290SJonathan Corbet # Not in a literal block (or just dropped out) 802*af250290SJonathan Corbet # 803*af250290SJonathan Corbet if (! $in_literal) { 804*af250290SJonathan Corbet $block .= $line . "\n"; 805*af250290SJonathan Corbet if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) { 806*af250290SJonathan Corbet $in_literal = 1; 807*af250290SJonathan Corbet $litprefix = ""; 808*af250290SJonathan Corbet $output .= highlight_block($block); 809*af250290SJonathan Corbet $block = "" 810*af250290SJonathan Corbet } 811*af250290SJonathan Corbet } 812*af250290SJonathan Corbet } 813*af250290SJonathan Corbet 814*af250290SJonathan Corbet if ($block) { 815*af250290SJonathan Corbet $output .= highlight_block($block); 816*af250290SJonathan Corbet } 817*af250290SJonathan Corbet foreach $line (split "\n", $output) { 818830066a7SJani Nikula print $lineprefix . $line . "\n"; 819c0d1b6eeSJonathan Corbet } 820c0d1b6eeSJonathan Corbet} 821c0d1b6eeSJonathan Corbet 822c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 823c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 824c0d1b6eeSJonathan Corbet my ($parameter, $section); 825c099ff69SJani Nikula my $oldprefix = $lineprefix; 82682801d06SMauro Carvalho Chehab my $start = ""; 827c0d1b6eeSJonathan Corbet 82882801d06SMauro Carvalho Chehab if ($args{'typedef'}) { 82982801d06SMauro Carvalho Chehab print ".. c:type:: ". $args{'function'} . "\n\n"; 83082801d06SMauro Carvalho Chehab print_lineno($declaration_start_line); 83182801d06SMauro Carvalho Chehab print " **Typedef**: "; 83282801d06SMauro Carvalho Chehab $lineprefix = ""; 83382801d06SMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 83482801d06SMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 835c0d1b6eeSJonathan Corbet } else { 83682801d06SMauro Carvalho Chehab print ".. c:function:: "; 83782801d06SMauro Carvalho Chehab } 83882801d06SMauro Carvalho Chehab if ($args{'functiontype'} ne "") { 83982801d06SMauro Carvalho Chehab $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; 84082801d06SMauro Carvalho Chehab } else { 84182801d06SMauro Carvalho Chehab $start .= $args{'function'} . " ("; 842c0d1b6eeSJonathan Corbet } 843c0d1b6eeSJonathan Corbet print $start; 844c0d1b6eeSJonathan Corbet 845c0d1b6eeSJonathan Corbet my $count = 0; 846c0d1b6eeSJonathan Corbet foreach my $parameter (@{$args{'parameterlist'}}) { 847c0d1b6eeSJonathan Corbet if ($count ne 0) { 848c0d1b6eeSJonathan Corbet print ", "; 849c0d1b6eeSJonathan Corbet } 850c0d1b6eeSJonathan Corbet $count++; 851c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 852a88b1672SMauro Carvalho Chehab 853c0d1b6eeSJonathan Corbet if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 854c0d1b6eeSJonathan Corbet # pointer-to-function 855c0d1b6eeSJonathan Corbet print $1 . $parameter . ") (" . $2; 856c0d1b6eeSJonathan Corbet } else { 857c0d1b6eeSJonathan Corbet print $type . " " . $parameter; 858c0d1b6eeSJonathan Corbet } 859c0d1b6eeSJonathan Corbet } 86082801d06SMauro Carvalho Chehab if ($args{'typedef'}) { 86182801d06SMauro Carvalho Chehab print ");``\n\n"; 86282801d06SMauro Carvalho Chehab } else { 863c099ff69SJani Nikula print ")\n\n"; 8640b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 865c099ff69SJani Nikula $lineprefix = " "; 866c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 867c099ff69SJani Nikula print "\n"; 86882801d06SMauro Carvalho Chehab } 869c0d1b6eeSJonathan Corbet 870ecbcfba1SJani Nikula print "**Parameters**\n\n"; 871c099ff69SJani Nikula $lineprefix = " "; 872c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 873c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 874ada5f446SGabriel Krisman Bertazi $parameter_name =~ s/\[.*//; 875c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 876c0d1b6eeSJonathan Corbet 877c0d1b6eeSJonathan Corbet if ($type ne "") { 878c0d1b6eeSJonathan Corbet print "``$type $parameter``\n"; 879c0d1b6eeSJonathan Corbet } else { 880c0d1b6eeSJonathan Corbet print "``$parameter``\n"; 881c0d1b6eeSJonathan Corbet } 8820b0f5f29SDaniel Vetter 8830b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 8840b0f5f29SDaniel Vetter 8855e64fa9cSJani Nikula if (defined($args{'parameterdescs'}{$parameter_name}) && 8865e64fa9cSJani Nikula $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 887c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 888c0d1b6eeSJonathan Corbet } else { 889d4b08e0cSJani Nikula print " *undescribed*\n"; 890c0d1b6eeSJonathan Corbet } 891c0d1b6eeSJonathan Corbet print "\n"; 892c0d1b6eeSJonathan Corbet } 893c099ff69SJani Nikula 894c099ff69SJani Nikula $lineprefix = $oldprefix; 895c0d1b6eeSJonathan Corbet output_section_rst(@_); 896c0d1b6eeSJonathan Corbet} 897c0d1b6eeSJonathan Corbet 898c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 899c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 900c0d1b6eeSJonathan Corbet my $section; 901c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 902c0d1b6eeSJonathan Corbet $lineprefix = ""; 903c0d1b6eeSJonathan Corbet 904c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 905ecbcfba1SJani Nikula print "**$section**\n\n"; 9060b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 907c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 908c0d1b6eeSJonathan Corbet print "\n"; 909c0d1b6eeSJonathan Corbet } 910c0d1b6eeSJonathan Corbet print "\n"; 911c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 912c0d1b6eeSJonathan Corbet} 913c0d1b6eeSJonathan Corbet 914c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 915c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 916c0d1b6eeSJonathan Corbet my ($parameter); 917c099ff69SJani Nikula my $oldprefix = $lineprefix; 918c0d1b6eeSJonathan Corbet my $count; 919c0d1b6eeSJonathan Corbet my $name = "enum " . $args{'enum'}; 92062850976SJani Nikula 92162850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 9220b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 923c099ff69SJani Nikula $lineprefix = " "; 924c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 925c099ff69SJani Nikula print "\n"; 926c0d1b6eeSJonathan Corbet 927ecbcfba1SJani Nikula print "**Constants**\n\n"; 928c0d1b6eeSJonathan Corbet $lineprefix = " "; 929c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 930ecbcfba1SJani Nikula print "``$parameter``\n"; 931c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 932c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 933c0d1b6eeSJonathan Corbet } else { 934d4b08e0cSJani Nikula print " *undescribed*\n"; 935c0d1b6eeSJonathan Corbet } 936c0d1b6eeSJonathan Corbet print "\n"; 937c0d1b6eeSJonathan Corbet } 938c099ff69SJani Nikula 939c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 940c0d1b6eeSJonathan Corbet output_section_rst(@_); 941c0d1b6eeSJonathan Corbet} 942c0d1b6eeSJonathan Corbet 943c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 944c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 945c0d1b6eeSJonathan Corbet my ($parameter); 946c099ff69SJani Nikula my $oldprefix = $lineprefix; 947c0d1b6eeSJonathan Corbet my $name = "typedef " . $args{'typedef'}; 948c0d1b6eeSJonathan Corbet 94962850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 9500b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 951c099ff69SJani Nikula $lineprefix = " "; 952c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 953c099ff69SJani Nikula print "\n"; 954c0d1b6eeSJonathan Corbet 955c099ff69SJani Nikula $lineprefix = $oldprefix; 956c0d1b6eeSJonathan Corbet output_section_rst(@_); 957c0d1b6eeSJonathan Corbet} 958c0d1b6eeSJonathan Corbet 959c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 960c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 961c0d1b6eeSJonathan Corbet my ($parameter); 962c099ff69SJani Nikula my $oldprefix = $lineprefix; 963c0d1b6eeSJonathan Corbet my $name = $args{'type'} . " " . $args{'struct'}; 964c0d1b6eeSJonathan Corbet 96562850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 9660b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 967c099ff69SJani Nikula $lineprefix = " "; 968c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 969c099ff69SJani Nikula print "\n"; 970c0d1b6eeSJonathan Corbet 971ecbcfba1SJani Nikula print "**Definition**\n\n"; 972c0d1b6eeSJonathan Corbet print "::\n\n"; 9738ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 9748ad72163SMauro Carvalho Chehab $declaration =~ s/\t/ /g; 9758ad72163SMauro Carvalho Chehab print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n"; 976c0d1b6eeSJonathan Corbet 977ecbcfba1SJani Nikula print "**Members**\n\n"; 978c099ff69SJani Nikula $lineprefix = " "; 979c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 980c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 981c0d1b6eeSJonathan Corbet 982c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 983c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 984c0d1b6eeSJonathan Corbet 985c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 986c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 9870b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 9886d232c80SMauro Carvalho Chehab print "``" . $parameter . "``\n"; 989c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 990c0d1b6eeSJonathan Corbet print "\n"; 991c0d1b6eeSJonathan Corbet } 992c0d1b6eeSJonathan Corbet print "\n"; 993c099ff69SJani Nikula 994c099ff69SJani Nikula $lineprefix = $oldprefix; 995c0d1b6eeSJonathan Corbet output_section_rst(@_); 996c0d1b6eeSJonathan Corbet} 997c0d1b6eeSJonathan Corbet 9983a025e1dSMatthew Wilcox## none mode output functions 9993a025e1dSMatthew Wilcox 10003a025e1dSMatthew Wilcoxsub output_function_none(%) { 10013a025e1dSMatthew Wilcox} 10023a025e1dSMatthew Wilcox 10033a025e1dSMatthew Wilcoxsub output_enum_none(%) { 10043a025e1dSMatthew Wilcox} 10053a025e1dSMatthew Wilcox 10063a025e1dSMatthew Wilcoxsub output_typedef_none(%) { 10073a025e1dSMatthew Wilcox} 10083a025e1dSMatthew Wilcox 10093a025e1dSMatthew Wilcoxsub output_struct_none(%) { 10103a025e1dSMatthew Wilcox} 10113a025e1dSMatthew Wilcox 10123a025e1dSMatthew Wilcoxsub output_blockhead_none(%) { 10133a025e1dSMatthew Wilcox} 10143a025e1dSMatthew Wilcox 10151da177e4SLinus Torvalds## 101627205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 101727205744SRandy Dunlap# calls the generated, variable output_ function name based on 101827205744SRandy Dunlap# functype and output_mode 10191da177e4SLinus Torvaldssub output_declaration { 10201da177e4SLinus Torvalds no strict 'refs'; 10211da177e4SLinus Torvalds my $name = shift; 10221da177e4SLinus Torvalds my $functype = shift; 10231da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 1024b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 1025b6c3f456SJani Nikula (($output_selection == OUTPUT_INCLUDE || 1026b6c3f456SJani Nikula $output_selection == OUTPUT_EXPORTED) && 102786ae2e38SJani Nikula defined($function_table{$name})) || 1028b6c3f456SJani Nikula (($output_selection == OUTPUT_EXCLUDE || 1029b6c3f456SJani Nikula $output_selection == OUTPUT_INTERNAL) && 103086ae2e38SJani Nikula !($functype eq "function" && defined($function_table{$name})))) 10311da177e4SLinus Torvalds { 10321da177e4SLinus Torvalds &$func(@_); 10331da177e4SLinus Torvalds $section_counter++; 10341da177e4SLinus Torvalds } 10351da177e4SLinus Torvalds} 10361da177e4SLinus Torvalds 10371da177e4SLinus Torvalds## 103827205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 1039b112e0f7SJohannes Bergsub output_blockhead { 10401da177e4SLinus Torvalds no strict 'refs'; 1041b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 10421da177e4SLinus Torvalds &$func(@_); 10431da177e4SLinus Torvalds $section_counter++; 10441da177e4SLinus Torvalds} 10451da177e4SLinus Torvalds 10461da177e4SLinus Torvalds## 10471da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 10481da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 10491da177e4SLinus Torvaldssub dump_declaration($$) { 10501da177e4SLinus Torvalds no strict 'refs'; 10511da177e4SLinus Torvalds my ($prototype, $file) = @_; 10521da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 10531da177e4SLinus Torvalds &$func(@_); 10541da177e4SLinus Torvalds} 10551da177e4SLinus Torvalds 10561da177e4SLinus Torvaldssub dump_union($$) { 10571da177e4SLinus Torvalds dump_struct(@_); 10581da177e4SLinus Torvalds} 10591da177e4SLinus Torvalds 10601da177e4SLinus Torvaldssub dump_struct($$) { 10611da177e4SLinus Torvalds my $x = shift; 10621da177e4SLinus Torvalds my $file = shift; 10631da177e4SLinus Torvalds 10641da177e4SLinus Torvalds if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 10655cb5c31cSJohannes Berg my $decl_type = $1; 10661da177e4SLinus Torvalds $declaration_name = $2; 10671da177e4SLinus Torvalds my $members = $3; 10681da177e4SLinus Torvalds 1069aeec46b9SMartin Waitz # ignore members marked private: 10700d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 10710d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 1072aeec46b9SMartin Waitz # strip comments: 1073aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 1074ef5da59fSRandy Dunlap # strip attributes 1075f0074929SJonathan Corbet $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 10767b990789SJohannes Berg $members =~ s/__aligned\s*\([^;]*\)//gos; 1077f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; 1078b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 107945005b27SMauro Carvalho Chehab $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 10801cb566baSJakub Kicinski # replace DECLARE_HASHTABLE 108145005b27SMauro Carvalho Chehab $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos; 108245005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO 108345005b27SMauro Carvalho Chehab $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; 108445005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO_PTR 108545005b27SMauro Carvalho Chehab $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; 1086aeec46b9SMartin Waitz 10878ad72163SMauro Carvalho Chehab my $declaration = $members; 10888ad72163SMauro Carvalho Chehab 10898ad72163SMauro Carvalho Chehab # Split nested struct/union elements as newer ones 109084ce5b98SMauro Carvalho Chehab while ($members =~ m/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/) { 109184ce5b98SMauro Carvalho Chehab my $newmember; 109284ce5b98SMauro Carvalho Chehab my $maintype = $1; 109384ce5b98SMauro Carvalho Chehab my $ids = $4; 10948ad72163SMauro Carvalho Chehab my $content = $3; 109584ce5b98SMauro Carvalho Chehab foreach my $id(split /,/, $ids) { 109684ce5b98SMauro Carvalho Chehab $newmember .= "$maintype $id; "; 109784ce5b98SMauro Carvalho Chehab 10988ad72163SMauro Carvalho Chehab $id =~ s/[:\[].*//; 109984ce5b98SMauro Carvalho Chehab $id =~ s/^\s*\**(\S+)\s*/$1/; 11008ad72163SMauro Carvalho Chehab foreach my $arg (split /;/, $content) { 11018ad72163SMauro Carvalho Chehab next if ($arg =~ m/^\s*$/); 11027c0d7e87SMauro Carvalho Chehab if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) { 11037c0d7e87SMauro Carvalho Chehab # pointer-to-function 11047c0d7e87SMauro Carvalho Chehab my $type = $1; 11057c0d7e87SMauro Carvalho Chehab my $name = $2; 11067c0d7e87SMauro Carvalho Chehab my $extra = $3; 11077c0d7e87SMauro Carvalho Chehab next if (!$name); 11087c0d7e87SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 11097c0d7e87SMauro Carvalho Chehab # anonymous struct/union 11107c0d7e87SMauro Carvalho Chehab $newmember .= "$type$name$extra; "; 11117c0d7e87SMauro Carvalho Chehab } else { 11127c0d7e87SMauro Carvalho Chehab $newmember .= "$type$id.$name$extra; "; 11137c0d7e87SMauro Carvalho Chehab } 11147c0d7e87SMauro Carvalho Chehab } else { 111584ce5b98SMauro Carvalho Chehab my $type; 111684ce5b98SMauro Carvalho Chehab my $names; 111784ce5b98SMauro Carvalho Chehab $arg =~ s/^\s+//; 111884ce5b98SMauro Carvalho Chehab $arg =~ s/\s+$//; 111984ce5b98SMauro Carvalho Chehab # Handle bitmaps 112084ce5b98SMauro Carvalho Chehab $arg =~ s/:\s*\d+\s*//g; 112184ce5b98SMauro Carvalho Chehab # Handle arrays 112284ce5b98SMauro Carvalho Chehab $arg =~ s/\[\S+\]//g; 112384ce5b98SMauro Carvalho Chehab # The type may have multiple words, 112484ce5b98SMauro Carvalho Chehab # and multiple IDs can be defined, like: 112584ce5b98SMauro Carvalho Chehab # const struct foo, *bar, foobar 112684ce5b98SMauro Carvalho Chehab # So, we remove spaces when parsing the 112784ce5b98SMauro Carvalho Chehab # names, in order to match just names 112884ce5b98SMauro Carvalho Chehab # and commas for the names 112984ce5b98SMauro Carvalho Chehab $arg =~ s/\s*,\s*/,/g; 113084ce5b98SMauro Carvalho Chehab if ($arg =~ m/(.*)\s+([\S+,]+)/) { 113184ce5b98SMauro Carvalho Chehab $type = $1; 113284ce5b98SMauro Carvalho Chehab $names = $2; 113384ce5b98SMauro Carvalho Chehab } else { 113484ce5b98SMauro Carvalho Chehab $newmember .= "$arg; "; 113584ce5b98SMauro Carvalho Chehab next; 113684ce5b98SMauro Carvalho Chehab } 113784ce5b98SMauro Carvalho Chehab foreach my $name (split /,/, $names) { 113884ce5b98SMauro Carvalho Chehab $name =~ s/^\s*\**(\S+)\s*/$1/; 11398ad72163SMauro Carvalho Chehab next if (($name =~ m/^\s*$/)); 11408ad72163SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 11418ad72163SMauro Carvalho Chehab # anonymous struct/union 11428ad72163SMauro Carvalho Chehab $newmember .= "$type $name; "; 11438ad72163SMauro Carvalho Chehab } else { 11448ad72163SMauro Carvalho Chehab $newmember .= "$type $id.$name; "; 11458ad72163SMauro Carvalho Chehab } 11468ad72163SMauro Carvalho Chehab } 11477c0d7e87SMauro Carvalho Chehab } 114884ce5b98SMauro Carvalho Chehab } 114984ce5b98SMauro Carvalho Chehab } 115084ce5b98SMauro Carvalho Chehab $members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)}([^\{\}\;]*)\;/$newmember/; 115184ce5b98SMauro Carvalho Chehab } 11528ad72163SMauro Carvalho Chehab 11538ad72163SMauro Carvalho Chehab # Ignore other nested elements, like enums 11548ad72163SMauro Carvalho Chehab $members =~ s/({[^\{\}]*})//g; 11558ad72163SMauro Carvalho Chehab 1156151c468bSMauro Carvalho Chehab create_parameterlist($members, ';', $file, $declaration_name); 11571081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual); 11581da177e4SLinus Torvalds 11598ad72163SMauro Carvalho Chehab # Adjust declaration for better display 11608ad72163SMauro Carvalho Chehab $declaration =~ s/([{;])/$1\n/g; 11618ad72163SMauro Carvalho Chehab $declaration =~ s/}\s+;/};/g; 11628ad72163SMauro Carvalho Chehab # Better handle inlined enums 11638ad72163SMauro Carvalho Chehab do {} while ($declaration =~ s/(enum\s+{[^}]+),([^\n])/$1,\n$2/); 11648ad72163SMauro Carvalho Chehab 11658ad72163SMauro Carvalho Chehab my @def_args = split /\n/, $declaration; 11668ad72163SMauro Carvalho Chehab my $level = 1; 11678ad72163SMauro Carvalho Chehab $declaration = ""; 11688ad72163SMauro Carvalho Chehab foreach my $clause (@def_args) { 11698ad72163SMauro Carvalho Chehab $clause =~ s/^\s+//; 11708ad72163SMauro Carvalho Chehab $clause =~ s/\s+$//; 11718ad72163SMauro Carvalho Chehab $clause =~ s/\s+/ /; 11728ad72163SMauro Carvalho Chehab next if (!$clause); 11738ad72163SMauro Carvalho Chehab $level-- if ($clause =~ m/(})/ && $level > 1); 11748ad72163SMauro Carvalho Chehab if (!($clause =~ m/^\s*#/)) { 11758ad72163SMauro Carvalho Chehab $declaration .= "\t" x $level; 11768ad72163SMauro Carvalho Chehab } 11778ad72163SMauro Carvalho Chehab $declaration .= "\t" . $clause . "\n"; 11788ad72163SMauro Carvalho Chehab $level++ if ($clause =~ m/({)/ && !($clause =~m/}/)); 11798ad72163SMauro Carvalho Chehab } 11801da177e4SLinus Torvalds output_declaration($declaration_name, 11811da177e4SLinus Torvalds 'struct', 11821da177e4SLinus Torvalds {'struct' => $declaration_name, 11831da177e4SLinus Torvalds 'module' => $modulename, 11848ad72163SMauro Carvalho Chehab 'definition' => $declaration, 11851da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 11861da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 11871da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 11881da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 11891da177e4SLinus Torvalds 'sections' => \%sections, 11901da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 11911da177e4SLinus Torvalds 'type' => $decl_type 11921da177e4SLinus Torvalds }); 11931da177e4SLinus Torvalds } 11941da177e4SLinus Torvalds else { 1195d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 11961da177e4SLinus Torvalds ++$errors; 11971da177e4SLinus Torvalds } 11981da177e4SLinus Torvalds} 11991da177e4SLinus Torvalds 120085afe608SMauro Carvalho Chehab 120185afe608SMauro Carvalho Chehabsub show_warnings($$) { 120285afe608SMauro Carvalho Chehab my $functype = shift; 120385afe608SMauro Carvalho Chehab my $name = shift; 120485afe608SMauro Carvalho Chehab 120585afe608SMauro Carvalho Chehab return 1 if ($output_selection == OUTPUT_ALL); 120685afe608SMauro Carvalho Chehab 120785afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_EXPORTED) { 120885afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 120985afe608SMauro Carvalho Chehab return 1; 121085afe608SMauro Carvalho Chehab } else { 121185afe608SMauro Carvalho Chehab return 0; 121285afe608SMauro Carvalho Chehab } 121385afe608SMauro Carvalho Chehab } 121485afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_INTERNAL) { 121585afe608SMauro Carvalho Chehab if (!($functype eq "function" && defined($function_table{$name}))) { 121685afe608SMauro Carvalho Chehab return 1; 121785afe608SMauro Carvalho Chehab } else { 121885afe608SMauro Carvalho Chehab return 0; 121985afe608SMauro Carvalho Chehab } 122085afe608SMauro Carvalho Chehab } 122185afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_INCLUDE) { 122285afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 122385afe608SMauro Carvalho Chehab return 1; 122485afe608SMauro Carvalho Chehab } else { 122585afe608SMauro Carvalho Chehab return 0; 122685afe608SMauro Carvalho Chehab } 122785afe608SMauro Carvalho Chehab } 122885afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_EXCLUDE) { 122985afe608SMauro Carvalho Chehab if (!defined($function_table{$name})) { 123085afe608SMauro Carvalho Chehab return 1; 123185afe608SMauro Carvalho Chehab } else { 123285afe608SMauro Carvalho Chehab return 0; 123385afe608SMauro Carvalho Chehab } 123485afe608SMauro Carvalho Chehab } 123585afe608SMauro Carvalho Chehab die("Please add the new output type at show_warnings()"); 123685afe608SMauro Carvalho Chehab} 123785afe608SMauro Carvalho Chehab 12381da177e4SLinus Torvaldssub dump_enum($$) { 12391da177e4SLinus Torvalds my $x = shift; 12401da177e4SLinus Torvalds my $file = shift; 12411da177e4SLinus Torvalds 1242aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 12434468e21eSConchúr Navid # strip #define macros inside enums 12444468e21eSConchúr Navid $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 1245b6d676dbSRandy Dunlap 12461da177e4SLinus Torvalds if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 12471da177e4SLinus Torvalds $declaration_name = $1; 12481da177e4SLinus Torvalds my $members = $2; 12495cb5c31cSJohannes Berg my %_members; 12505cb5c31cSJohannes Berg 1251463a0fdcSMarkus Heiser $members =~ s/\s+$//; 12521da177e4SLinus Torvalds 12531da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 12541da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 12551da177e4SLinus Torvalds push @parameterlist, $arg; 12561da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 12571da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 125885afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 12592defb272SMauro Carvalho Chehab print STDERR "${file}:$.: warning: Enum value '$arg' not described in enum '$declaration_name'\n"; 12602defb272SMauro Carvalho Chehab } 12611da177e4SLinus Torvalds } 12625cb5c31cSJohannes Berg $_members{$arg} = 1; 12635cb5c31cSJohannes Berg } 12641da177e4SLinus Torvalds 12655cb5c31cSJohannes Berg while (my ($k, $v) = each %parameterdescs) { 12665cb5c31cSJohannes Berg if (!exists($_members{$k})) { 126785afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 12682defb272SMauro Carvalho Chehab print STDERR "${file}:$.: warning: Excess enum value '$k' description in '$declaration_name'\n"; 12692defb272SMauro Carvalho Chehab } 12705cb5c31cSJohannes Berg } 12711da177e4SLinus Torvalds } 12721da177e4SLinus Torvalds 12731da177e4SLinus Torvalds output_declaration($declaration_name, 12741da177e4SLinus Torvalds 'enum', 12751da177e4SLinus Torvalds {'enum' => $declaration_name, 12761da177e4SLinus Torvalds 'module' => $modulename, 12771da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 12781da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 12791da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 12801da177e4SLinus Torvalds 'sections' => \%sections, 12811da177e4SLinus Torvalds 'purpose' => $declaration_purpose 12821da177e4SLinus Torvalds }); 12831da177e4SLinus Torvalds } 12841da177e4SLinus Torvalds else { 1285d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 12861da177e4SLinus Torvalds ++$errors; 12871da177e4SLinus Torvalds } 12881da177e4SLinus Torvalds} 12891da177e4SLinus Torvalds 12901da177e4SLinus Torvaldssub dump_typedef($$) { 12911da177e4SLinus Torvalds my $x = shift; 12921da177e4SLinus Torvalds my $file = shift; 12931da177e4SLinus Torvalds 1294aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 129583766452SMauro Carvalho Chehab 129683766452SMauro Carvalho Chehab # Parse function prototypes 1297d37c43ceSMauro Carvalho Chehab if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ || 1298d37c43ceSMauro Carvalho Chehab $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) { 1299d37c43ceSMauro Carvalho Chehab 130083766452SMauro Carvalho Chehab # Function typedefs 130183766452SMauro Carvalho Chehab $return_type = $1; 130283766452SMauro Carvalho Chehab $declaration_name = $2; 130383766452SMauro Carvalho Chehab my $args = $3; 130483766452SMauro Carvalho Chehab 1305151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 130683766452SMauro Carvalho Chehab 130783766452SMauro Carvalho Chehab output_declaration($declaration_name, 130883766452SMauro Carvalho Chehab 'function', 130983766452SMauro Carvalho Chehab {'function' => $declaration_name, 131082801d06SMauro Carvalho Chehab 'typedef' => 1, 131183766452SMauro Carvalho Chehab 'module' => $modulename, 131283766452SMauro Carvalho Chehab 'functiontype' => $return_type, 131383766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 131483766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 131583766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 131683766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 131783766452SMauro Carvalho Chehab 'sections' => \%sections, 131883766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 131983766452SMauro Carvalho Chehab }); 132083766452SMauro Carvalho Chehab return; 132183766452SMauro Carvalho Chehab } 132283766452SMauro Carvalho Chehab 13231da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 13241da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 13251da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 13261da177e4SLinus Torvalds } 13271da177e4SLinus Torvalds 13281da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 13291da177e4SLinus Torvalds $declaration_name = $1; 13301da177e4SLinus Torvalds 13311da177e4SLinus Torvalds output_declaration($declaration_name, 13321da177e4SLinus Torvalds 'typedef', 13331da177e4SLinus Torvalds {'typedef' => $declaration_name, 13341da177e4SLinus Torvalds 'module' => $modulename, 13351da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 13361da177e4SLinus Torvalds 'sections' => \%sections, 13371da177e4SLinus Torvalds 'purpose' => $declaration_purpose 13381da177e4SLinus Torvalds }); 13391da177e4SLinus Torvalds } 13401da177e4SLinus Torvalds else { 1341d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 13421da177e4SLinus Torvalds ++$errors; 13431da177e4SLinus Torvalds } 13441da177e4SLinus Torvalds} 13451da177e4SLinus Torvalds 1346a1d94aa5SRandy Dunlapsub save_struct_actual($) { 1347a1d94aa5SRandy Dunlap my $actual = shift; 1348a1d94aa5SRandy Dunlap 1349a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 1350a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 1351a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 1352a1d94aa5SRandy Dunlap} 1353a1d94aa5SRandy Dunlap 1354151c468bSMauro Carvalho Chehabsub create_parameterlist($$$$) { 13551da177e4SLinus Torvalds my $args = shift; 13561da177e4SLinus Torvalds my $splitter = shift; 13571da177e4SLinus Torvalds my $file = shift; 1358151c468bSMauro Carvalho Chehab my $declaration_name = shift; 13591da177e4SLinus Torvalds my $type; 13601da177e4SLinus Torvalds my $param; 13611da177e4SLinus Torvalds 1362a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 13631da177e4SLinus Torvalds while ($args =~ /(\([^\),]+),/) { 13641da177e4SLinus Torvalds $args =~ s/(\([^\),]+),/$1#/g; 13651da177e4SLinus Torvalds } 13661da177e4SLinus Torvalds 13671da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 13681da177e4SLinus Torvalds # strip comments 13691da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 13701da177e4SLinus Torvalds # strip leading/trailing spaces 13711da177e4SLinus Torvalds $arg =~ s/^\s*//; 13721da177e4SLinus Torvalds $arg =~ s/\s*$//; 13731da177e4SLinus Torvalds $arg =~ s/\s+/ /; 13741da177e4SLinus Torvalds 13751da177e4SLinus Torvalds if ($arg =~ /^#/) { 13761da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 13771da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 13781da177e4SLinus Torvalds # output_* subs. 13791da177e4SLinus Torvalds push_parameter($arg, "", $file); 138000d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 13811da177e4SLinus Torvalds # pointer-to-function 13821da177e4SLinus Torvalds $arg =~ tr/#/,/; 13837c0d7e87SMauro Carvalho Chehab $arg =~ m/[^\(]+\(\*?\s*([\w\.]*)\s*\)/; 13841da177e4SLinus Torvalds $param = $1; 13851da177e4SLinus Torvalds $type = $arg; 138600d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1387a1d94aa5SRandy Dunlap save_struct_actual($param); 1388151c468bSMauro Carvalho Chehab push_parameter($param, $type, $file, $declaration_name); 1389aeec46b9SMartin Waitz } elsif ($arg) { 13901da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 13911da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 13921da177e4SLinus Torvalds 13931da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 13941da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 13951da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 13961da177e4SLinus Torvalds } 1397884f2810SBorislav Petkov 1398884f2810SBorislav Petkov my @first_arg; 1399884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1400884f2810SBorislav Petkov shift @args; 1401884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 1402884f2810SBorislav Petkov push(@first_arg, $2); 1403884f2810SBorislav Petkov } else { 1404884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 1405884f2810SBorislav Petkov } 1406884f2810SBorislav Petkov 14071da177e4SLinus Torvalds unshift(@args, pop @first_arg); 14081da177e4SLinus Torvalds $type = join " ", @first_arg; 14091da177e4SLinus Torvalds 14101da177e4SLinus Torvalds foreach $param (@args) { 14111da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 1412a1d94aa5SRandy Dunlap save_struct_actual($2); 1413151c468bSMauro Carvalho Chehab push_parameter($2, "$type $1", $file, $declaration_name); 14141da177e4SLinus Torvalds } 14151da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 14167b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 1417a1d94aa5SRandy Dunlap save_struct_actual($1); 1418151c468bSMauro Carvalho Chehab push_parameter($1, "$type:$2", $file, $declaration_name) 14191da177e4SLinus Torvalds } 14207b97887eSRandy Dunlap } 14211da177e4SLinus Torvalds else { 1422a1d94aa5SRandy Dunlap save_struct_actual($param); 1423151c468bSMauro Carvalho Chehab push_parameter($param, $type, $file, $declaration_name); 14241da177e4SLinus Torvalds } 14251da177e4SLinus Torvalds } 14261da177e4SLinus Torvalds } 14271da177e4SLinus Torvalds } 14281da177e4SLinus Torvalds} 14291da177e4SLinus Torvalds 1430151c468bSMauro Carvalho Chehabsub push_parameter($$$$) { 14311da177e4SLinus Torvalds my $param = shift; 14321da177e4SLinus Torvalds my $type = shift; 14331da177e4SLinus Torvalds my $file = shift; 1434151c468bSMauro Carvalho Chehab my $declaration_name = shift; 14351da177e4SLinus Torvalds 14365f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 14375f8c7c98SRandy Dunlap ($param eq "}")) { 14385f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 14395f8c7c98SRandy Dunlap } 14405f8c7c98SRandy Dunlap 14415f8c7c98SRandy Dunlap $anon_struct_union = 0; 1442f9b5c530SMauro Carvalho Chehab $param =~ s/[\[\)].*//; 14431da177e4SLinus Torvalds 1444a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 14451da177e4SLinus Torvalds { 1446c950a173SSilvio Fricke if (!$param =~ /\w\.\.\.$/) { 1447c950a173SSilvio Fricke # handles unnamed variable parameters 1448ef00028bSJonathan Corbet $param = "..."; 1449c950a173SSilvio Fricke } 1450ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1451a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 14521da177e4SLinus Torvalds } 1453ced69090SRandy Dunlap } 14541da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 14551da177e4SLinus Torvalds { 14561da177e4SLinus Torvalds $param="void"; 14571da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 14581da177e4SLinus Torvalds } 1459134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1460134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 1461134fe01bSRandy Dunlap { 1462134fe01bSRandy Dunlap $type = $param; 1463134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 1464134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 14655f8c7c98SRandy Dunlap $anon_struct_union = 1; 1466134fe01bSRandy Dunlap } 1467134fe01bSRandy Dunlap 1468a6d3fe77SMartin Waitz # warn if parameter has no description 1469134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 1470134fe01bSRandy Dunlap # but inline preprocessor statements); 1471151c468bSMauro Carvalho Chehab # Note: It will also ignore void params and unnamed structs/unions 1472f9b5c530SMauro Carvalho Chehab if (!defined $parameterdescs{$param} && $param !~ /^#/) { 1473f9b5c530SMauro Carvalho Chehab $parameterdescs{$param} = $undescribed; 14741da177e4SLinus Torvalds 147585afe608SMauro Carvalho Chehab if (show_warnings($type, $declaration_name)) { 1476151c468bSMauro Carvalho Chehab print STDERR 1477151c468bSMauro Carvalho Chehab "${file}:$.: warning: Function parameter or member '$param' not described in '$declaration_name'\n"; 14781da177e4SLinus Torvalds ++$warnings; 14791da177e4SLinus Torvalds } 14802defb272SMauro Carvalho Chehab } 14811da177e4SLinus Torvalds 148225985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 1483e34e7dbbSRandy Dunlap # on @parameterlist; 1484e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 1485e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 1486e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 1487e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 1488e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 1489e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 1490e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 14911da177e4SLinus Torvalds push @parameterlist, $param; 149202a4f4feSPaolo Bonzini $type =~ s/\s\s+/ /g; 14931da177e4SLinus Torvalds $parametertypes{$param} = $type; 14941da177e4SLinus Torvalds} 14951da177e4SLinus Torvalds 14961081de2dSMauro Carvalho Chehabsub check_sections($$$$$) { 14971081de2dSMauro Carvalho Chehab my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_; 1498a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 1499a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 1500a1d94aa5SRandy Dunlap my $err; 1501a1d94aa5SRandy Dunlap my ($px, $sx); 1502a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 1503a1d94aa5SRandy Dunlap 1504a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 1505a1d94aa5SRandy Dunlap $err = 1; 1506a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 1507a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 1508a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 15091f3a6688SJohannes Berg $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 1510e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 1511e34e7dbbSRandy Dunlap # however, the original param string may contain 1512e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 1513e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 1514e34e7dbbSRandy Dunlap # parameter list is split at spaces; 1515e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 1516e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 1517e34e7dbbSRandy Dunlap 1518a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 1519a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 1520a1d94aa5SRandy Dunlap $err = 0; 1521a1d94aa5SRandy Dunlap last; 1522a1d94aa5SRandy Dunlap } 1523a1d94aa5SRandy Dunlap } 1524a1d94aa5SRandy Dunlap if ($err) { 1525a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 1526d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 1527a1d94aa5SRandy Dunlap "Excess function parameter " . 1528a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 1529a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 1530a1d94aa5SRandy Dunlap ++$warnings; 1531a1d94aa5SRandy Dunlap } 1532a1d94aa5SRandy Dunlap } 1533a1d94aa5SRandy Dunlap } 1534a1d94aa5SRandy Dunlap} 1535a1d94aa5SRandy Dunlap 15361da177e4SLinus Torvalds## 15374092bac7SYacine Belkadi# Checks the section describing the return value of a function. 15384092bac7SYacine Belkadisub check_return_section { 15394092bac7SYacine Belkadi my $file = shift; 15404092bac7SYacine Belkadi my $declaration_name = shift; 15414092bac7SYacine Belkadi my $return_type = shift; 15424092bac7SYacine Belkadi 15434092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 15444092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 15454092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 15464092bac7SYacine Belkadi return; 15474092bac7SYacine Belkadi } 15484092bac7SYacine Belkadi 15494092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 15504092bac7SYacine Belkadi $sections{$section_return} eq "") { 1551d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 15524092bac7SYacine Belkadi "No description found for return value of " . 15534092bac7SYacine Belkadi "'$declaration_name'\n"; 15544092bac7SYacine Belkadi ++$warnings; 15554092bac7SYacine Belkadi } 15564092bac7SYacine Belkadi} 15574092bac7SYacine Belkadi 15584092bac7SYacine Belkadi## 15591da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 15601da177e4SLinus Torvalds# processed and spits out all the details stored in the global 15611da177e4SLinus Torvalds# arrays/hashes. 15621da177e4SLinus Torvaldssub dump_function($$) { 15631da177e4SLinus Torvalds my $prototype = shift; 15641da177e4SLinus Torvalds my $file = shift; 1565cbb4d3e6SHoria Geanta my $noret = 0; 15661da177e4SLinus Torvalds 15671da177e4SLinus Torvalds $prototype =~ s/^static +//; 15681da177e4SLinus Torvalds $prototype =~ s/^extern +//; 15694dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 15701da177e4SLinus Torvalds $prototype =~ s/^inline +//; 15711da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 157232e79401SRandy Dunlap $prototype =~ s/^__inline +//; 157332e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 157432e79401SRandy Dunlap $prototype =~ s/^noinline +//; 157574fc5c65SRandy Dunlap $prototype =~ s/__init +//; 157620072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 1577270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 157870c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 15790df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 1580cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 1581b1aaa546SPaolo Bonzini $prototype =~ s/__attribute__\s*\(\( 1582b1aaa546SPaolo Bonzini (?: 1583b1aaa546SPaolo Bonzini [\w\s]++ # attribute name 1584b1aaa546SPaolo Bonzini (?:\([^)]*+\))? # attribute arguments 1585b1aaa546SPaolo Bonzini \s*+,? # optional comma at the end 1586b1aaa546SPaolo Bonzini )+ 1587b1aaa546SPaolo Bonzini \)\)\s+//x; 15881da177e4SLinus Torvalds 15891da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 15901da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 15911da177e4SLinus Torvalds # 2. Function name 15921da177e4SLinus Torvalds # 3. Function parameters. 15931da177e4SLinus Torvalds # 15941da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 15951da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 15961da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 15971da177e4SLinus Torvalds # so on. 15981da177e4SLinus Torvalds # 15991da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 16001da177e4SLinus Torvalds # the following functions' documentation still comes out right: 16011da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 16021da177e4SLinus Torvalds # - atomic_set (macro) 16039598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 16041da177e4SLinus Torvalds 1605cbb4d3e6SHoria Geanta if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 1606cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 1607cbb4d3e6SHoria Geanta # list. 1608cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 1609cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 1610cbb4d3e6SHoria Geanta $return_type = $1; 1611cbb4d3e6SHoria Geanta $declaration_name = $2; 1612cbb4d3e6SHoria Geanta $noret = 1; 1613cbb4d3e6SHoria Geanta } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 16141da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 16155a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 16161da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 161794b3e03cSRandy Dunlap $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 16181da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 16195a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 16201da177e4SLinus Torvalds $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 16211da177e4SLinus Torvalds $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 16225a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 16231da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 16245a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 16251da177e4SLinus Torvalds $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 16265a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 16279598f91fSMartin Waitz $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 16285a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 16295a0bc578SMatthew Wilcox $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 16301da177e4SLinus Torvalds $return_type = $1; 16311da177e4SLinus Torvalds $declaration_name = $2; 16321da177e4SLinus Torvalds my $args = $3; 16331da177e4SLinus Torvalds 1634151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 16351da177e4SLinus Torvalds } else { 1636d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 16371da177e4SLinus Torvalds return; 16381da177e4SLinus Torvalds } 16391da177e4SLinus Torvalds 1640a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 16411081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, "function", $sectcheck, $prms); 1642a1d94aa5SRandy Dunlap 16434092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 16444092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 16454092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 16464092bac7SYacine Belkadi # verbose mode. 16474092bac7SYacine Belkadi # TODO: always perform the check. 1648cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 16494092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 16504092bac7SYacine Belkadi } 16514092bac7SYacine Belkadi 16521da177e4SLinus Torvalds output_declaration($declaration_name, 16531da177e4SLinus Torvalds 'function', 16541da177e4SLinus Torvalds {'function' => $declaration_name, 16551da177e4SLinus Torvalds 'module' => $modulename, 16561da177e4SLinus Torvalds 'functiontype' => $return_type, 16571da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 16581da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 16591da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 16601da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 16611da177e4SLinus Torvalds 'sections' => \%sections, 16621da177e4SLinus Torvalds 'purpose' => $declaration_purpose 16631da177e4SLinus Torvalds }); 16641da177e4SLinus Torvalds} 16651da177e4SLinus Torvalds 16661da177e4SLinus Torvaldssub reset_state { 16671da177e4SLinus Torvalds $function = ""; 16681da177e4SLinus Torvalds %parameterdescs = (); 16691da177e4SLinus Torvalds %parametertypes = (); 16701da177e4SLinus Torvalds @parameterlist = (); 16711da177e4SLinus Torvalds %sections = (); 16721da177e4SLinus Torvalds @sectionlist = (); 1673a1d94aa5SRandy Dunlap $sectcheck = ""; 1674a1d94aa5SRandy Dunlap $struct_actual = ""; 16751da177e4SLinus Torvalds $prototype = ""; 16761da177e4SLinus Torvalds 167748af606aSJani Nikula $state = STATE_NORMAL; 167848af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 16791da177e4SLinus Torvalds} 16801da177e4SLinus Torvalds 168156afb0f8SJason Baronsub tracepoint_munge($) { 168256afb0f8SJason Baron my $file = shift; 168356afb0f8SJason Baron my $tracepointname = 0; 168456afb0f8SJason Baron my $tracepointargs = 0; 168556afb0f8SJason Baron 168656afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 168756afb0f8SJason Baron $tracepointname = $1; 168856afb0f8SJason Baron } 16893a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 16903a9089fdSJason Baron $tracepointname = $1; 16913a9089fdSJason Baron } 16923a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 16933a9089fdSJason Baron $tracepointname = $2; 16943a9089fdSJason Baron } 16953a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 169656afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 169756afb0f8SJason Baron $tracepointargs = $1; 169856afb0f8SJason Baron } 169956afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 1700d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 170156afb0f8SJason Baron "$prototype\n"; 170256afb0f8SJason Baron } else { 170356afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 170456afb0f8SJason Baron } 170556afb0f8SJason Baron} 170656afb0f8SJason Baron 1707b4870bc5SRandy Dunlapsub syscall_munge() { 1708b4870bc5SRandy Dunlap my $void = 0; 1709b4870bc5SRandy Dunlap 17107c9aa015SMauro Carvalho Chehab $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's 1711b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 1712b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 1713b4870bc5SRandy Dunlap $void = 1; 1714b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 1715b4870bc5SRandy Dunlap } 1716b4870bc5SRandy Dunlap 1717b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 1718b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 1719b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 1720b4870bc5SRandy Dunlap } elsif ($void) { 1721b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 1722b4870bc5SRandy Dunlap } 1723b4870bc5SRandy Dunlap 1724b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 1725b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 1726b4870bc5SRandy Dunlap my $count = 0; 1727b4870bc5SRandy Dunlap my $len = length($prototype); 1728b4870bc5SRandy Dunlap if ($void) { 1729b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 1730b4870bc5SRandy Dunlap } 1731b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 1732b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 1733b4870bc5SRandy Dunlap $count++; 1734b4870bc5SRandy Dunlap if ($count % 2 == 1) { 1735b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 1736b4870bc5SRandy Dunlap } 1737b4870bc5SRandy Dunlap } 1738b4870bc5SRandy Dunlap } 1739b4870bc5SRandy Dunlap} 1740b4870bc5SRandy Dunlap 1741b7afa92bSDaniel Vettersub process_proto_function($$) { 17421da177e4SLinus Torvalds my $x = shift; 17431da177e4SLinus Torvalds my $file = shift; 17441da177e4SLinus Torvalds 174551f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 174651f5a0c8SRandy Dunlap 1747890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 17481da177e4SLinus Torvalds # do nothing 17491da177e4SLinus Torvalds } 17501da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 17511da177e4SLinus Torvalds $prototype .= $1; 17521da177e4SLinus Torvalds } 1753b4870bc5SRandy Dunlap 1754890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 17551da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 17561da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 17571da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 1758b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 1759b4870bc5SRandy Dunlap syscall_munge(); 1760b4870bc5SRandy Dunlap } 17613a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 17623a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 17633a9089fdSJason Baron { 176456afb0f8SJason Baron tracepoint_munge($file); 176556afb0f8SJason Baron } 17661da177e4SLinus Torvalds dump_function($prototype, $file); 17671da177e4SLinus Torvalds reset_state(); 17681da177e4SLinus Torvalds } 17691da177e4SLinus Torvalds} 17701da177e4SLinus Torvalds 1771b7afa92bSDaniel Vettersub process_proto_type($$) { 17721da177e4SLinus Torvalds my $x = shift; 17731da177e4SLinus Torvalds my $file = shift; 17741da177e4SLinus Torvalds 17751da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 17761da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 17771da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 177851f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 177951f5a0c8SRandy Dunlap 17801da177e4SLinus Torvalds if ($x =~ /^#/) { 17811da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 17821da177e4SLinus Torvalds $x .= ";"; 17831da177e4SLinus Torvalds } 17841da177e4SLinus Torvalds 17851da177e4SLinus Torvalds while (1) { 17861da177e4SLinus Torvalds if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 1787463a0fdcSMarkus Heiser if( length $prototype ) { 1788463a0fdcSMarkus Heiser $prototype .= " " 1789463a0fdcSMarkus Heiser } 17901da177e4SLinus Torvalds $prototype .= $1 . $2; 17911da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 17921da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 17931da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 17941da177e4SLinus Torvalds dump_declaration($prototype, $file); 17951da177e4SLinus Torvalds reset_state(); 17961da177e4SLinus Torvalds last; 17971da177e4SLinus Torvalds } 17981da177e4SLinus Torvalds $x = $3; 17991da177e4SLinus Torvalds } else { 18001da177e4SLinus Torvalds $prototype .= $x; 18011da177e4SLinus Torvalds last; 18021da177e4SLinus Torvalds } 18031da177e4SLinus Torvalds } 18041da177e4SLinus Torvalds} 18051da177e4SLinus Torvalds 18066b5b55f6SRandy Dunlap 18071ad560e4SJani Nikulasub map_filename($) { 18081ad560e4SJani Nikula my $file; 18091ad560e4SJani Nikula my ($orig_file) = @_; 18101ad560e4SJani Nikula 18111ad560e4SJani Nikula if (defined($ENV{'SRCTREE'})) { 18121ad560e4SJani Nikula $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 18131ad560e4SJani Nikula } else { 18141ad560e4SJani Nikula $file = $orig_file; 18151ad560e4SJani Nikula } 18161ad560e4SJani Nikula 18171ad560e4SJani Nikula if (defined($source_map{$file})) { 18181ad560e4SJani Nikula $file = $source_map{$file}; 18191ad560e4SJani Nikula } 18201ad560e4SJani Nikula 18211ad560e4SJani Nikula return $file; 18221ad560e4SJani Nikula} 18231ad560e4SJani Nikula 182488c2b57dSJani Nikulasub process_export_file($) { 182588c2b57dSJani Nikula my ($orig_file) = @_; 182688c2b57dSJani Nikula my $file = map_filename($orig_file); 182788c2b57dSJani Nikula 182888c2b57dSJani Nikula if (!open(IN,"<$file")) { 182988c2b57dSJani Nikula print STDERR "Error: Cannot open file $file\n"; 183088c2b57dSJani Nikula ++$errors; 183188c2b57dSJani Nikula return; 183288c2b57dSJani Nikula } 183388c2b57dSJani Nikula 183488c2b57dSJani Nikula while (<IN>) { 183588c2b57dSJani Nikula if (/$export_symbol/) { 183688c2b57dSJani Nikula $function_table{$2} = 1; 183788c2b57dSJani Nikula } 183888c2b57dSJani Nikula } 183988c2b57dSJani Nikula 184088c2b57dSJani Nikula close(IN); 184188c2b57dSJani Nikula} 184288c2b57dSJani Nikula 184307048d13SJonathan Corbet# 184407048d13SJonathan Corbet# Parsers for the various processing states. 184507048d13SJonathan Corbet# 184607048d13SJonathan Corbet# STATE_NORMAL: looking for the /** to begin everything. 184707048d13SJonathan Corbet# 184807048d13SJonathan Corbetsub process_normal() { 184907048d13SJonathan Corbet if (/$doc_start/o) { 185007048d13SJonathan Corbet $state = STATE_NAME; # next line is always the function name 185107048d13SJonathan Corbet $in_doc_sect = 0; 185207048d13SJonathan Corbet $declaration_start_line = $. + 1; 185307048d13SJonathan Corbet } 185407048d13SJonathan Corbet} 185507048d13SJonathan Corbet 18563cac2bc4SJonathan Corbet# 18573cac2bc4SJonathan Corbet# STATE_NAME: Looking for the "name - description" line 18583cac2bc4SJonathan Corbet# 18593cac2bc4SJonathan Corbetsub process_name($$) { 18603cac2bc4SJonathan Corbet my $file = shift; 18611da177e4SLinus Torvalds my $identifier; 1862a21217daSRandy Dunlap my $descr; 18631da177e4SLinus Torvalds 18641da177e4SLinus Torvalds if (/$doc_block/o) { 186548af606aSJani Nikula $state = STATE_DOCBLOCK; 18661da177e4SLinus Torvalds $contents = ""; 18670b0f5f29SDaniel Vetter $new_start_line = $. + 1; 18680b0f5f29SDaniel Vetter 18691da177e4SLinus Torvalds if ( $1 eq "" ) { 18701da177e4SLinus Torvalds $section = $section_intro; 18711da177e4SLinus Torvalds } else { 18721da177e4SLinus Torvalds $section = $1; 18731da177e4SLinus Torvalds } 18741da177e4SLinus Torvalds } 18751da177e4SLinus Torvalds elsif (/$doc_decl/o) { 18761da177e4SLinus Torvalds $identifier = $1; 18771da177e4SLinus Torvalds if (/\s*([\w\s]+?)\s*-/) { 18781da177e4SLinus Torvalds $identifier = $1; 18791da177e4SLinus Torvalds } 18801da177e4SLinus Torvalds 188117b78717SJonathan Corbet $state = STATE_BODY; 18820b0f5f29SDaniel Vetter # if there's no @param blocks need to set up default section 18830b0f5f29SDaniel Vetter # here 18842f4ad40aSJani Nikula $contents = ""; 18852f4ad40aSJani Nikula $section = $section_default; 18860b0f5f29SDaniel Vetter $new_start_line = $. + 1; 18871da177e4SLinus Torvalds if (/-(.*)/) { 188851f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 1889a21217daSRandy Dunlap $descr= $1; 1890a21217daSRandy Dunlap $descr =~ s/^\s*//; 1891a21217daSRandy Dunlap $descr =~ s/\s*$//; 189212ae6779SDaniel Santos $descr =~ s/\s+/ /g; 18930bba924cSJonathan Corbet $declaration_purpose = $descr; 189417b78717SJonathan Corbet $state = STATE_BODY_MAYBE; 18951da177e4SLinus Torvalds } else { 18961da177e4SLinus Torvalds $declaration_purpose = ""; 18971da177e4SLinus Torvalds } 189877cc23b8SRandy Dunlap 189977cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 1900d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 190177cc23b8SRandy Dunlap print STDERR $_; 190277cc23b8SRandy Dunlap ++$warnings; 190377cc23b8SRandy Dunlap } 190477cc23b8SRandy Dunlap 19051da177e4SLinus Torvalds if ($identifier =~ m/^struct/) { 19061da177e4SLinus Torvalds $decl_type = 'struct'; 19071da177e4SLinus Torvalds } elsif ($identifier =~ m/^union/) { 19081da177e4SLinus Torvalds $decl_type = 'union'; 19091da177e4SLinus Torvalds } elsif ($identifier =~ m/^enum/) { 19101da177e4SLinus Torvalds $decl_type = 'enum'; 19111da177e4SLinus Torvalds } elsif ($identifier =~ m/^typedef/) { 19121da177e4SLinus Torvalds $decl_type = 'typedef'; 19131da177e4SLinus Torvalds } else { 19141da177e4SLinus Torvalds $decl_type = 'function'; 19151da177e4SLinus Torvalds } 19161da177e4SLinus Torvalds 19171da177e4SLinus Torvalds if ($verbose) { 1918d40e1e65SBart Van Assche print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; 19191da177e4SLinus Torvalds } 19201da177e4SLinus Torvalds } else { 1921d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 19221da177e4SLinus Torvalds " - I thought it was a doc line\n"; 19231da177e4SLinus Torvalds ++$warnings; 192448af606aSJani Nikula $state = STATE_NORMAL; 19251da177e4SLinus Torvalds } 19263cac2bc4SJonathan Corbet} 19273cac2bc4SJonathan Corbet 19283cac2bc4SJonathan Corbet 1929d742f24dSJonathan Corbet# 1930d742f24dSJonathan Corbet# STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment. 1931d742f24dSJonathan Corbet# 1932d742f24dSJonathan Corbetsub process_body($$) { 1933d742f24dSJonathan Corbet my $file = shift; 19343cac2bc4SJonathan Corbet 1935f624adefSJani Nikula if (/$doc_sect/i) { # case insensitive for supported section names 19361da177e4SLinus Torvalds $newsection = $1; 19371da177e4SLinus Torvalds $newcontents = $2; 19381da177e4SLinus Torvalds 1939f624adefSJani Nikula # map the supported section names to the canonical names 1940f624adefSJani Nikula if ($newsection =~ m/^description$/i) { 1941f624adefSJani Nikula $newsection = $section_default; 1942f624adefSJani Nikula } elsif ($newsection =~ m/^context$/i) { 1943f624adefSJani Nikula $newsection = $section_context; 1944f624adefSJani Nikula } elsif ($newsection =~ m/^returns?$/i) { 1945f624adefSJani Nikula $newsection = $section_return; 1946f624adefSJani Nikula } elsif ($newsection =~ m/^\@return$/) { 1947f624adefSJani Nikula # special: @return is a section, not a param description 1948f624adefSJani Nikula $newsection = $section_return; 1949f624adefSJani Nikula } 1950f624adefSJani Nikula 1951792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 1952850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 1953d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: contents before sections\n"; 1954850622dfSRandy Dunlap ++$warnings; 1955850622dfSRandy Dunlap } 19560bba924cSJonathan Corbet dump_section($file, $section, $contents); 19571da177e4SLinus Torvalds $section = $section_default; 19581da177e4SLinus Torvalds } 19591da177e4SLinus Torvalds 1960850622dfSRandy Dunlap $in_doc_sect = 1; 196117b78717SJonathan Corbet $state = STATE_BODY; 19621da177e4SLinus Torvalds $contents = $newcontents; 19630b0f5f29SDaniel Vetter $new_start_line = $.; 19647c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 196505189497SRandy Dunlap $contents = substr($contents, 1); 196605189497SRandy Dunlap } 19670a726301SJani Nikula if ($contents ne "") { 19681da177e4SLinus Torvalds $contents .= "\n"; 19691da177e4SLinus Torvalds } 19701da177e4SLinus Torvalds $section = $newsection; 1971b7886de4SJani Nikula $leading_space = undef; 19721da177e4SLinus Torvalds } elsif (/$doc_end/) { 19734c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 19740bba924cSJonathan Corbet dump_section($file, $section, $contents); 19751da177e4SLinus Torvalds $section = $section_default; 19761da177e4SLinus Torvalds $contents = ""; 19771da177e4SLinus Torvalds } 197846b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 197946b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 1980d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: suspicious ending line: $_"; 198146b958ebSRandy Dunlap ++$warnings; 198246b958ebSRandy Dunlap } 19831da177e4SLinus Torvalds 19841da177e4SLinus Torvalds $prototype = ""; 198548af606aSJani Nikula $state = STATE_PROTO; 19861da177e4SLinus Torvalds $brcount = 0; 19871da177e4SLinus Torvalds } elsif (/$doc_content/) { 19881da177e4SLinus Torvalds # miguel-style comment kludge, look for blank lines after 19891da177e4SLinus Torvalds # @parameter line to signify start of description 19906423133bSJohannes Weiner if ($1 eq "") { 19916423133bSJohannes Weiner if ($section =~ m/^@/ || $section eq $section_context) { 19920bba924cSJonathan Corbet dump_section($file, $section, $contents); 19931da177e4SLinus Torvalds $section = $section_default; 19941da177e4SLinus Torvalds $contents = ""; 19950b0f5f29SDaniel Vetter $new_start_line = $.; 19961da177e4SLinus Torvalds } else { 19976423133bSJohannes Weiner $contents .= "\n"; 19986423133bSJohannes Weiner } 199917b78717SJonathan Corbet $state = STATE_BODY; 200017b78717SJonathan Corbet } elsif ($state == STATE_BODY_MAYBE) { 20016423133bSJohannes Weiner # Continued declaration purpose 20026423133bSJohannes Weiner chomp($declaration_purpose); 20030bba924cSJonathan Corbet $declaration_purpose .= " " . $1; 200412ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 20056423133bSJohannes Weiner } else { 2006b7886de4SJani Nikula my $cont = $1; 2007b7886de4SJani Nikula if ($section =~ m/^@/ || $section eq $section_context) { 2008b7886de4SJani Nikula if (!defined $leading_space) { 2009b7886de4SJani Nikula if ($cont =~ m/^(\s+)/) { 2010b7886de4SJani Nikula $leading_space = $1; 2011b7886de4SJani Nikula } else { 2012b7886de4SJani Nikula $leading_space = ""; 2013b7886de4SJani Nikula } 2014b7886de4SJani Nikula } 2015b7886de4SJani Nikula $cont =~ s/^$leading_space//; 2016b7886de4SJani Nikula } 2017b7886de4SJani Nikula $contents .= $cont . "\n"; 20181da177e4SLinus Torvalds } 20191da177e4SLinus Torvalds } else { 20201da177e4SLinus Torvalds # i dont know - bad line? ignore. 2021d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: bad line: $_"; 20221da177e4SLinus Torvalds ++$warnings; 20231da177e4SLinus Torvalds } 2024d742f24dSJonathan Corbet} 2025d742f24dSJonathan Corbet 2026d742f24dSJonathan Corbet 2027cc794812SJonathan Corbet# 2028cc794812SJonathan Corbet# STATE_PROTO: reading a function/whatever prototype. 2029cc794812SJonathan Corbet# 2030cc794812SJonathan Corbetsub process_proto($$) { 2031cc794812SJonathan Corbet my $file = shift; 2032cc794812SJonathan Corbet 2033cc794812SJonathan Corbet if (/$doc_inline_oneline/) { 2034cc794812SJonathan Corbet $section = $1; 2035cc794812SJonathan Corbet $contents = $2; 2036cc794812SJonathan Corbet if ($contents ne "") { 2037cc794812SJonathan Corbet $contents .= "\n"; 2038cc794812SJonathan Corbet dump_section($file, $section, $contents); 2039cc794812SJonathan Corbet $section = $section_default; 2040cc794812SJonathan Corbet $contents = ""; 2041cc794812SJonathan Corbet } 2042cc794812SJonathan Corbet } elsif (/$doc_inline_start/) { 2043cc794812SJonathan Corbet $state = STATE_INLINE; 2044cc794812SJonathan Corbet $inline_doc_state = STATE_INLINE_NAME; 2045cc794812SJonathan Corbet } elsif ($decl_type eq 'function') { 2046cc794812SJonathan Corbet process_proto_function($_, $file); 2047cc794812SJonathan Corbet } else { 2048cc794812SJonathan Corbet process_proto_type($_, $file); 2049cc794812SJonathan Corbet } 2050cc794812SJonathan Corbet} 2051cc794812SJonathan Corbet 2052c17add56SJonathan Corbet# 2053c17add56SJonathan Corbet# STATE_DOCBLOCK: within a DOC: block. 2054c17add56SJonathan Corbet# 2055c17add56SJonathan Corbetsub process_docblock($$) { 2056c17add56SJonathan Corbet my $file = shift; 2057cc794812SJonathan Corbet 2058c17add56SJonathan Corbet if (/$doc_end/) { 2059c17add56SJonathan Corbet dump_doc_section($file, $section, $contents); 2060c17add56SJonathan Corbet $section = $section_default; 2061c17add56SJonathan Corbet $contents = ""; 2062c17add56SJonathan Corbet $function = ""; 2063c17add56SJonathan Corbet %parameterdescs = (); 2064c17add56SJonathan Corbet %parametertypes = (); 2065c17add56SJonathan Corbet @parameterlist = (); 2066c17add56SJonathan Corbet %sections = (); 2067c17add56SJonathan Corbet @sectionlist = (); 2068c17add56SJonathan Corbet $prototype = ""; 2069c17add56SJonathan Corbet $state = STATE_NORMAL; 2070c17add56SJonathan Corbet } elsif (/$doc_content/) { 2071c17add56SJonathan Corbet if ( $1 eq "" ) { 2072c17add56SJonathan Corbet $contents .= $blankline; 2073c17add56SJonathan Corbet } else { 2074c17add56SJonathan Corbet $contents .= $1 . "\n"; 2075c17add56SJonathan Corbet } 2076c17add56SJonathan Corbet } 2077d742f24dSJonathan Corbet} 2078d742f24dSJonathan Corbet 2079c17add56SJonathan Corbet# 2080c17add56SJonathan Corbet# STATE_INLINE: docbook comments within a prototype. 2081c17add56SJonathan Corbet# 2082c17add56SJonathan Corbetsub process_inline($$) { 2083c17add56SJonathan Corbet my $file = shift; 2084d742f24dSJonathan Corbet 2085a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 208648af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 2087a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 2088a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 20890b0f5f29SDaniel Vetter $new_start_line = $.; 2090a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 20917c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 2092a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 2093a4c6ebedSDanilo Cesar Lemes de Paula } 2094a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 2095a4c6ebedSDanilo Cesar Lemes de Paula } 209648af606aSJani Nikula $inline_doc_state = STATE_INLINE_TEXT; 2097a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 209848af606aSJani Nikula } elsif (/$doc_inline_end/) { 2099a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 21000bba924cSJonathan Corbet dump_section($file, $section, $contents); 2101a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 2102a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 2103a4c6ebedSDanilo Cesar Lemes de Paula } 210448af606aSJani Nikula $state = STATE_PROTO; 210548af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 2106a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 2107a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 210848af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_TEXT) { 2109a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 21106450c895SJani Nikula # nuke leading blank lines 21116450c895SJani Nikula if ($contents =~ /^\s*$/) { 21126450c895SJani Nikula $contents = ""; 21136450c895SJani Nikula } 211448af606aSJani Nikula } elsif ($inline_doc_state == STATE_INLINE_NAME) { 211548af606aSJani Nikula $inline_doc_state = STATE_INLINE_ERROR; 2116e7ca311eSDaniel Vetter print STDERR "${file}:$.: warning: "; 2117a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Incorrect use of kernel-doc format: $_"; 2118a4c6ebedSDanilo Cesar Lemes de Paula ++$warnings; 2119a4c6ebedSDanilo Cesar Lemes de Paula } 2120a4c6ebedSDanilo Cesar Lemes de Paula } 2121c17add56SJonathan Corbet} 2122c17add56SJonathan Corbet 2123c17add56SJonathan Corbet 2124c17add56SJonathan Corbetsub process_file($) { 2125c17add56SJonathan Corbet my $file; 2126c17add56SJonathan Corbet my $initial_section_counter = $section_counter; 2127c17add56SJonathan Corbet my ($orig_file) = @_; 2128c17add56SJonathan Corbet 2129c17add56SJonathan Corbet $file = map_filename($orig_file); 2130c17add56SJonathan Corbet 2131c17add56SJonathan Corbet if (!open(IN,"<$file")) { 2132c17add56SJonathan Corbet print STDERR "Error: Cannot open file $file\n"; 2133c17add56SJonathan Corbet ++$errors; 2134c17add56SJonathan Corbet return; 2135c17add56SJonathan Corbet } 2136c17add56SJonathan Corbet 2137c17add56SJonathan Corbet $. = 1; 2138c17add56SJonathan Corbet 2139c17add56SJonathan Corbet $section_counter = 0; 2140c17add56SJonathan Corbet while (<IN>) { 2141c17add56SJonathan Corbet while (s/\\\s*$//) { 2142c17add56SJonathan Corbet $_ .= <IN>; 2143c17add56SJonathan Corbet } 2144c17add56SJonathan Corbet # Replace tabs by spaces 2145c17add56SJonathan Corbet while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; 2146c17add56SJonathan Corbet 2147c17add56SJonathan Corbet # Hand this line to the appropriate state handler 2148c17add56SJonathan Corbet if ($state == STATE_NORMAL) { 2149c17add56SJonathan Corbet process_normal(); 2150c17add56SJonathan Corbet } elsif ($state == STATE_NAME) { 2151c17add56SJonathan Corbet process_name($file, $_); 2152c17add56SJonathan Corbet } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE) { 2153c17add56SJonathan Corbet process_body($file, $_); 2154c17add56SJonathan Corbet } elsif ($state == STATE_INLINE) { # scanning for inline parameters 2155c17add56SJonathan Corbet process_inline($file, $_); 2156cc794812SJonathan Corbet } elsif ($state == STATE_PROTO) { 2157cc794812SJonathan Corbet process_proto($file, $_); 215848af606aSJani Nikula } elsif ($state == STATE_DOCBLOCK) { 2159c17add56SJonathan Corbet process_docblock($file, $_); 21601da177e4SLinus Torvalds } 21611da177e4SLinus Torvalds } 2162c17add56SJonathan Corbet 2163c17add56SJonathan Corbet # Make sure we got something interesting. 21641da177e4SLinus Torvalds if ($initial_section_counter == $section_counter) { 21653a025e1dSMatthew Wilcox if ($output_mode ne "none") { 2166d40e1e65SBart Van Assche print STDERR "${file}:1: warning: no structured comments found\n"; 21673a025e1dSMatthew Wilcox } 2168b6c3f456SJani Nikula if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) { 2169e946c43aSJohannes Berg print STDERR " Was looking for '$_'.\n" for keys %function_table; 2170e946c43aSJohannes Berg } 21711da177e4SLinus Torvalds } 21721da177e4SLinus Torvalds} 21738484baaaSRandy Dunlap 21748484baaaSRandy Dunlap 21758484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 21768484baaaSRandy Dunlap 21778484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 21788484baaaSRandy Dunlap# using the s// operator. 21791ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 21804d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 21814d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 21824d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 21834d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 21848484baaaSRandy Dunlap} 21858484baaaSRandy Dunlap 21868484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 21878484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 21888484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 21898484baaaSRandy Dunlap my ($relname, $absname); 21908484baaaSRandy Dunlap while(<SOURCE_MAP>) { 21918484baaaSRandy Dunlap chop(); 21928484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 21938484baaaSRandy Dunlap $relname =~ s:^/+::; 21948484baaaSRandy Dunlap $source_map{$relname} = $absname; 21958484baaaSRandy Dunlap } 21968484baaaSRandy Dunlap close(SOURCE_MAP); 21978484baaaSRandy Dunlap} 21988484baaaSRandy Dunlap 219988c2b57dSJani Nikulaif ($output_selection == OUTPUT_EXPORTED || 220088c2b57dSJani Nikula $output_selection == OUTPUT_INTERNAL) { 2201c9b2cfb3SJani Nikula 2202c9b2cfb3SJani Nikula push(@export_file_list, @ARGV); 2203c9b2cfb3SJani Nikula 220488c2b57dSJani Nikula foreach (@export_file_list) { 220588c2b57dSJani Nikula chomp; 220688c2b57dSJani Nikula process_export_file($_); 220788c2b57dSJani Nikula } 220888c2b57dSJani Nikula} 220988c2b57dSJani Nikula 22108484baaaSRandy Dunlapforeach (@ARGV) { 22118484baaaSRandy Dunlap chomp; 22128484baaaSRandy Dunlap process_file($_); 22138484baaaSRandy Dunlap} 22148484baaaSRandy Dunlapif ($verbose && $errors) { 22158484baaaSRandy Dunlap print STDERR "$errors errors\n"; 22168484baaaSRandy Dunlap} 22178484baaaSRandy Dunlapif ($verbose && $warnings) { 22188484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 22198484baaaSRandy Dunlap} 22208484baaaSRandy Dunlap 2221e814bccbSWill Deaconexit($output_mode eq "none" ? 0 : $errors); 2222