1e2c54635SPaolo Bonzini#!/usr/bin/env perl 2*06e23296SPhilippe Mathieu-Daudé# SPDX-License-Identifier: GPL-2.0-only 3e2c54635SPaolo Bonzini 4e2c54635SPaolo Bonziniuse warnings; 5e2c54635SPaolo Bonziniuse strict; 6e2c54635SPaolo Bonzini 7e2c54635SPaolo Bonzini## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## 8e2c54635SPaolo Bonzini## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## 9e2c54635SPaolo Bonzini## Copyright (C) 2001 Simon Huggins ## 10e2c54635SPaolo Bonzini## Copyright (C) 2005-2012 Randy Dunlap ## 11e2c54635SPaolo Bonzini## Copyright (C) 2012 Dan Luedtke ## 12e2c54635SPaolo Bonzini## ## 13e2c54635SPaolo Bonzini## #define enhancements by Armin Kuster <akuster@mvista.com> ## 14e2c54635SPaolo Bonzini## Copyright (c) 2000 MontaVista Software, Inc. ## 15e2c54635SPaolo Bonzini## ## 16e2c54635SPaolo Bonzini## This software falls under the GNU General Public License. ## 17e2c54635SPaolo Bonzini## Please read the COPYING file for more information ## 18e2c54635SPaolo Bonzini 19e2c54635SPaolo Bonzini# 18/01/2001 - Cleanups 20e2c54635SPaolo Bonzini# Functions prototyped as foo(void) same as foo() 21e2c54635SPaolo Bonzini# Stop eval'ing where we don't need to. 22e2c54635SPaolo Bonzini# -- huggie@earth.li 23e2c54635SPaolo Bonzini 24e2c54635SPaolo Bonzini# 27/06/2001 - Allowed whitespace after initial "/**" and 25e2c54635SPaolo Bonzini# allowed comments before function declarations. 26e2c54635SPaolo Bonzini# -- Christian Kreibich <ck@whoop.org> 27e2c54635SPaolo Bonzini 28e2c54635SPaolo Bonzini# Still to do: 29e2c54635SPaolo Bonzini# - add perldoc documentation 30e2c54635SPaolo Bonzini# - Look more closely at some of the scarier bits :) 31e2c54635SPaolo Bonzini 32e2c54635SPaolo Bonzini# 26/05/2001 - Support for separate source and object trees. 33e2c54635SPaolo Bonzini# Return error code. 34e2c54635SPaolo Bonzini# Keith Owens <kaos@ocs.com.au> 35e2c54635SPaolo Bonzini 36e2c54635SPaolo Bonzini# 23/09/2001 - Added support for typedefs, structs, enums and unions 37e2c54635SPaolo Bonzini# Support for Context section; can be terminated using empty line 38e2c54635SPaolo Bonzini# Small fixes (like spaces vs. \s in regex) 39e2c54635SPaolo Bonzini# -- Tim Jansen <tim@tjansen.de> 40e2c54635SPaolo Bonzini 41e2c54635SPaolo Bonzini# 25/07/2012 - Added support for HTML5 42e2c54635SPaolo Bonzini# -- Dan Luedtke <mail@danrl.de> 43e2c54635SPaolo Bonzini 44e2c54635SPaolo Bonzinisub usage { 45e2c54635SPaolo Bonzini my $message = <<"EOF"; 46e2c54635SPaolo BonziniUsage: $0 [OPTION ...] FILE ... 47e2c54635SPaolo Bonzini 48e2c54635SPaolo BonziniRead C language source or header FILEs, extract embedded documentation comments, 49e2c54635SPaolo Bonziniand print formatted documentation to standard output. 50e2c54635SPaolo Bonzini 51e2c54635SPaolo BonziniThe documentation comments are identified by "/**" opening comment mark. See 52e2c54635SPaolo BonziniDocumentation/doc-guide/kernel-doc.rst for the documentation comment syntax. 53e2c54635SPaolo Bonzini 54e2c54635SPaolo BonziniOutput format selection (mutually exclusive): 55e2c54635SPaolo Bonzini -man Output troff manual page format. This is the default. 56e2c54635SPaolo Bonzini -rst Output reStructuredText format. 57e2c54635SPaolo Bonzini -none Do not output documentation, only warnings. 58e2c54635SPaolo Bonzini 59486966e4SMauro Carvalho ChehabOutput format selection modifier (affects only ReST output): 60486966e4SMauro Carvalho Chehab 61486966e4SMauro Carvalho Chehab -sphinx-version Use the ReST C domain dialect compatible with an 62486966e4SMauro Carvalho Chehab specific Sphinx Version. 63486966e4SMauro Carvalho Chehab If not specified, kernel-doc will auto-detect using 64486966e4SMauro Carvalho Chehab the sphinx-build version found on PATH. 65486966e4SMauro Carvalho Chehab 66e2c54635SPaolo BonziniOutput selection (mutually exclusive): 67e2c54635SPaolo Bonzini -export Only output documentation for symbols that have been 68e2c54635SPaolo Bonzini exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 69e2c54635SPaolo Bonzini in any input FILE or -export-file FILE. 70e2c54635SPaolo Bonzini -internal Only output documentation for symbols that have NOT been 71e2c54635SPaolo Bonzini exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() 72e2c54635SPaolo Bonzini in any input FILE or -export-file FILE. 73e2c54635SPaolo Bonzini -function NAME Only output documentation for the given function(s) 74e2c54635SPaolo Bonzini or DOC: section title(s). All other functions and DOC: 75e2c54635SPaolo Bonzini sections are ignored. May be specified multiple times. 7678c8c92cSMauro Carvalho Chehab -nosymbol NAME Exclude the specified symbols from the output 7778c8c92cSMauro Carvalho Chehab documentation. May be specified multiple times. 78e2c54635SPaolo Bonzini 79e2c54635SPaolo BonziniOutput selection modifiers: 80e2c54635SPaolo Bonzini -no-doc-sections Do not output DOC: sections. 81e2c54635SPaolo Bonzini -enable-lineno Enable output of #define LINENO lines. Only works with 82e2c54635SPaolo Bonzini reStructuredText format. 83e2c54635SPaolo Bonzini -export-file FILE Specify an additional FILE in which to look for 84e2c54635SPaolo Bonzini EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with 85e2c54635SPaolo Bonzini -export or -internal. May be specified multiple times. 86e2c54635SPaolo Bonzini 87e2c54635SPaolo BonziniOther parameters: 88e2c54635SPaolo Bonzini -v Verbose output, more warnings and other information. 89e2c54635SPaolo Bonzini -h Print this help. 9086cba217SPierre-Louis Bossart -Werror Treat warnings as errors. 91e2c54635SPaolo Bonzini 92e2c54635SPaolo BonziniEOF 93e2c54635SPaolo Bonzini print $message; 94e2c54635SPaolo Bonzini exit 1; 95e2c54635SPaolo Bonzini} 96e2c54635SPaolo Bonzini 97e2c54635SPaolo Bonzini# 98e2c54635SPaolo Bonzini# format of comments. 99e2c54635SPaolo Bonzini# In the following table, (...)? signifies optional structure. 100e2c54635SPaolo Bonzini# (...)* signifies 0 or more structure elements 101e2c54635SPaolo Bonzini# /** 102e2c54635SPaolo Bonzini# * function_name(:)? (- short description)? 103e2c54635SPaolo Bonzini# (* @parameterx: (description of parameter x)?)* 104e2c54635SPaolo Bonzini# (* a blank line)? 105e2c54635SPaolo Bonzini# * (Description:)? (Description of function)? 106e2c54635SPaolo Bonzini# * (section header: (section description)? )* 107e2c54635SPaolo Bonzini# (*)?*/ 108e2c54635SPaolo Bonzini# 109e2c54635SPaolo Bonzini# So .. the trivial example would be: 110e2c54635SPaolo Bonzini# 111e2c54635SPaolo Bonzini# /** 112e2c54635SPaolo Bonzini# * my_function 113e2c54635SPaolo Bonzini# */ 114e2c54635SPaolo Bonzini# 115e2c54635SPaolo Bonzini# If the Description: header tag is omitted, then there must be a blank line 116e2c54635SPaolo Bonzini# after the last parameter specification. 117e2c54635SPaolo Bonzini# e.g. 118e2c54635SPaolo Bonzini# /** 119e2c54635SPaolo Bonzini# * my_function - does my stuff 120e2c54635SPaolo Bonzini# * @my_arg: its mine damnit 121e2c54635SPaolo Bonzini# * 122e2c54635SPaolo Bonzini# * Does my stuff explained. 123e2c54635SPaolo Bonzini# */ 124e2c54635SPaolo Bonzini# 125e2c54635SPaolo Bonzini# or, could also use: 126e2c54635SPaolo Bonzini# /** 127e2c54635SPaolo Bonzini# * my_function - does my stuff 128e2c54635SPaolo Bonzini# * @my_arg: its mine damnit 129e2c54635SPaolo Bonzini# * Description: Does my stuff explained. 130e2c54635SPaolo Bonzini# */ 131e2c54635SPaolo Bonzini# etc. 132e2c54635SPaolo Bonzini# 133e2c54635SPaolo Bonzini# Besides functions you can also write documentation for structs, unions, 134e2c54635SPaolo Bonzini# enums and typedefs. Instead of the function name you must write the name 135e2c54635SPaolo Bonzini# of the declaration; the struct/union/enum/typedef must always precede 136e2c54635SPaolo Bonzini# the name. Nesting of declarations is not supported. 137e2c54635SPaolo Bonzini# Use the argument mechanism to document members or constants. 138e2c54635SPaolo Bonzini# e.g. 139e2c54635SPaolo Bonzini# /** 140e2c54635SPaolo Bonzini# * struct my_struct - short description 141e2c54635SPaolo Bonzini# * @a: first member 142e2c54635SPaolo Bonzini# * @b: second member 143e2c54635SPaolo Bonzini# * 144e2c54635SPaolo Bonzini# * Longer description 145e2c54635SPaolo Bonzini# */ 146e2c54635SPaolo Bonzini# struct my_struct { 147e2c54635SPaolo Bonzini# int a; 148e2c54635SPaolo Bonzini# int b; 149e2c54635SPaolo Bonzini# /* private: */ 150e2c54635SPaolo Bonzini# int c; 151e2c54635SPaolo Bonzini# }; 152e2c54635SPaolo Bonzini# 153e2c54635SPaolo Bonzini# All descriptions can be multiline, except the short function description. 154e2c54635SPaolo Bonzini# 155e2c54635SPaolo Bonzini# For really longs structs, you can also describe arguments inside the 156e2c54635SPaolo Bonzini# body of the struct. 157e2c54635SPaolo Bonzini# eg. 158e2c54635SPaolo Bonzini# /** 159e2c54635SPaolo Bonzini# * struct my_struct - short description 160e2c54635SPaolo Bonzini# * @a: first member 161e2c54635SPaolo Bonzini# * @b: second member 162e2c54635SPaolo Bonzini# * 163e2c54635SPaolo Bonzini# * Longer description 164e2c54635SPaolo Bonzini# */ 165e2c54635SPaolo Bonzini# struct my_struct { 166e2c54635SPaolo Bonzini# int a; 167e2c54635SPaolo Bonzini# int b; 168e2c54635SPaolo Bonzini# /** 169e2c54635SPaolo Bonzini# * @c: This is longer description of C 170e2c54635SPaolo Bonzini# * 171e2c54635SPaolo Bonzini# * You can use paragraphs to describe arguments 172e2c54635SPaolo Bonzini# * using this method. 173e2c54635SPaolo Bonzini# */ 174e2c54635SPaolo Bonzini# int c; 175e2c54635SPaolo Bonzini# }; 176e2c54635SPaolo Bonzini# 177e2c54635SPaolo Bonzini# This should be use only for struct/enum members. 178e2c54635SPaolo Bonzini# 179e2c54635SPaolo Bonzini# You can also add additional sections. When documenting kernel functions you 180e2c54635SPaolo Bonzini# should document the "Context:" of the function, e.g. whether the functions 181e2c54635SPaolo Bonzini# can be called form interrupts. Unlike other sections you can end it with an 182e2c54635SPaolo Bonzini# empty line. 183e2c54635SPaolo Bonzini# A non-void function should have a "Return:" section describing the return 184e2c54635SPaolo Bonzini# value(s). 185e2c54635SPaolo Bonzini# Example-sections should contain the string EXAMPLE so that they are marked 186e2c54635SPaolo Bonzini# appropriately in DocBook. 187e2c54635SPaolo Bonzini# 188e2c54635SPaolo Bonzini# Example: 189e2c54635SPaolo Bonzini# /** 190e2c54635SPaolo Bonzini# * user_function - function that can only be called in user context 191e2c54635SPaolo Bonzini# * @a: some argument 192e2c54635SPaolo Bonzini# * Context: !in_interrupt() 193e2c54635SPaolo Bonzini# * 194e2c54635SPaolo Bonzini# * Some description 195e2c54635SPaolo Bonzini# * Example: 196e2c54635SPaolo Bonzini# * user_function(22); 197e2c54635SPaolo Bonzini# */ 198e2c54635SPaolo Bonzini# ... 199e2c54635SPaolo Bonzini# 200e2c54635SPaolo Bonzini# 201e2c54635SPaolo Bonzini# All descriptive text is further processed, scanning for the following special 202e2c54635SPaolo Bonzini# patterns, which are highlighted appropriately. 203e2c54635SPaolo Bonzini# 204e2c54635SPaolo Bonzini# 'funcname()' - function 205e2c54635SPaolo Bonzini# '$ENVVAR' - environmental variable 206e2c54635SPaolo Bonzini# '&struct_name' - name of a structure (up to two words including 'struct') 207e2c54635SPaolo Bonzini# '&struct_name.member' - name of a structure member 208e2c54635SPaolo Bonzini# '@parameter' - name of a parameter 209e2c54635SPaolo Bonzini# '%CONST' - name of a constant. 210e2c54635SPaolo Bonzini# '``LITERAL``' - literal string without any spaces on it. 211e2c54635SPaolo Bonzini 212e2c54635SPaolo Bonzini## init lots of data 213e2c54635SPaolo Bonzini 214e2c54635SPaolo Bonzinimy $errors = 0; 215e2c54635SPaolo Bonzinimy $warnings = 0; 216e2c54635SPaolo Bonzinimy $anon_struct_union = 0; 217e2c54635SPaolo Bonzini 218e2c54635SPaolo Bonzini# match expressions used to find embedded type information 219e2c54635SPaolo Bonzinimy $type_constant = '\b``([^\`]+)``\b'; 220e2c54635SPaolo Bonzinimy $type_constant2 = '\%([-_\w]+)'; 221e2c54635SPaolo Bonzinimy $type_func = '(\w+)\(\)'; 222e2c54635SPaolo Bonzinimy $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; 223b1e8e720SMauro Carvalho Chehabmy $type_param_ref = '([\!]?)\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; 224e2c54635SPaolo Bonzinimy $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params 22576083982SMauro Carvalho Chehabmy $type_fp_param2 = '\@(\w+->\S+)\(\)'; # Special RST handling for structs with func ptr params 226e2c54635SPaolo Bonzinimy $type_env = '(\$\w+)'; 2274cf41794SPaolo Bonzinimy $type_enum = '#(enum\s*([_\w]+))'; 2284cf41794SPaolo Bonzinimy $type_struct = '#(struct\s*([_\w]+))'; 2294cf41794SPaolo Bonzinimy $type_typedef = '#(([A-Z][_\w]*))'; 2304cf41794SPaolo Bonzinimy $type_union = '#(union\s*([_\w]+))'; 2314cf41794SPaolo Bonzinimy $type_member = '#([_\w]+)(\.|->)([_\w]+)'; 2324cf41794SPaolo Bonzinimy $type_fallback = '(?!)'; # this never matches 233e2c54635SPaolo Bonzinimy $type_member_func = $type_member . '\(\)'; 234e2c54635SPaolo Bonzini 235e2c54635SPaolo Bonzini# Output conversion substitutions. 236e2c54635SPaolo Bonzini# One for each output format 237e2c54635SPaolo Bonzini 238e2c54635SPaolo Bonzini# these are pretty rough 239e2c54635SPaolo Bonzinimy @highlights_man = ( 240e2c54635SPaolo Bonzini [$type_constant, "\$1"], 241e2c54635SPaolo Bonzini [$type_constant2, "\$1"], 242e2c54635SPaolo Bonzini [$type_func, "\\\\fB\$1\\\\fP"], 243e2c54635SPaolo Bonzini [$type_enum, "\\\\fI\$1\\\\fP"], 244e2c54635SPaolo Bonzini [$type_struct, "\\\\fI\$1\\\\fP"], 245e2c54635SPaolo Bonzini [$type_typedef, "\\\\fI\$1\\\\fP"], 246e2c54635SPaolo Bonzini [$type_union, "\\\\fI\$1\\\\fP"], 247e2c54635SPaolo Bonzini [$type_param, "\\\\fI\$1\\\\fP"], 248b1e8e720SMauro Carvalho Chehab [$type_param_ref, "\\\\fI\$1\$2\\\\fP"], 249e2c54635SPaolo Bonzini [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], 250e2c54635SPaolo Bonzini [$type_fallback, "\\\\fI\$1\\\\fP"] 251e2c54635SPaolo Bonzini ); 252e2c54635SPaolo Bonzinimy $blankline_man = ""; 253e2c54635SPaolo Bonzini 254e2c54635SPaolo Bonzini# rst-mode 255e2c54635SPaolo Bonzinimy @highlights_rst = ( 256e2c54635SPaolo Bonzini [$type_constant, "``\$1``"], 257e2c54635SPaolo Bonzini [$type_constant2, "``\$1``"], 258e2c54635SPaolo Bonzini # Note: need to escape () to avoid func matching later 259e2c54635SPaolo Bonzini [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], 260e2c54635SPaolo Bonzini [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], 261e2c54635SPaolo Bonzini [$type_fp_param, "**\$1\\\\(\\\\)**"], 26276083982SMauro Carvalho Chehab [$type_fp_param2, "**\$1\\\\(\\\\)**"], 263e2c54635SPaolo Bonzini [$type_func, "\$1()"], 264e2c54635SPaolo Bonzini [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], 265e2c54635SPaolo Bonzini [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], 266e2c54635SPaolo Bonzini [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], 267e2c54635SPaolo Bonzini [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], 268e2c54635SPaolo Bonzini # in rst this can refer to any type 269e2c54635SPaolo Bonzini [$type_fallback, "\\:c\\:type\\:`\$1`"], 270b1e8e720SMauro Carvalho Chehab [$type_param_ref, "**\$1\$2**"] 271e2c54635SPaolo Bonzini ); 272e2c54635SPaolo Bonzinimy $blankline_rst = "\n"; 273e2c54635SPaolo Bonzini 274e2c54635SPaolo Bonzini# read arguments 275e2c54635SPaolo Bonziniif ($#ARGV == -1) { 276e2c54635SPaolo Bonzini usage(); 277e2c54635SPaolo Bonzini} 278e2c54635SPaolo Bonzini 279e2c54635SPaolo Bonzinimy $kernelversion; 280486966e4SMauro Carvalho Chehabmy ($sphinx_major, $sphinx_minor, $sphinx_patch); 2816d3a3cfcSMauro Carvalho Chehab 282e2c54635SPaolo Bonzinimy $dohighlight = ""; 283e2c54635SPaolo Bonzini 284e2c54635SPaolo Bonzinimy $verbose = 0; 28586cba217SPierre-Louis Bossartmy $Werror = 0; 286e2c54635SPaolo Bonzinimy $output_mode = "rst"; 287e2c54635SPaolo Bonzinimy $output_preformatted = 0; 288e2c54635SPaolo Bonzinimy $no_doc_sections = 0; 289e2c54635SPaolo Bonzinimy $enable_lineno = 0; 290e2c54635SPaolo Bonzinimy @highlights = @highlights_rst; 291e2c54635SPaolo Bonzinimy $blankline = $blankline_rst; 292e2c54635SPaolo Bonzinimy $modulename = "Kernel API"; 293e2c54635SPaolo Bonzini 294e2c54635SPaolo Bonziniuse constant { 295e2c54635SPaolo Bonzini OUTPUT_ALL => 0, # output all symbols and doc sections 296e2c54635SPaolo Bonzini OUTPUT_INCLUDE => 1, # output only specified symbols 29778c8c92cSMauro Carvalho Chehab OUTPUT_EXPORTED => 2, # output exported symbols 29878c8c92cSMauro Carvalho Chehab OUTPUT_INTERNAL => 3, # output non-exported symbols 299e2c54635SPaolo Bonzini}; 300e2c54635SPaolo Bonzinimy $output_selection = OUTPUT_ALL; 301e2c54635SPaolo Bonzinimy $show_not_found = 0; # No longer used 302e2c54635SPaolo Bonzini 303e2c54635SPaolo Bonzinimy @export_file_list; 304e2c54635SPaolo Bonzini 305e2c54635SPaolo Bonzinimy @build_time; 306e2c54635SPaolo Bonziniif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 307e2c54635SPaolo Bonzini (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 308e2c54635SPaolo Bonzini @build_time = gmtime($seconds); 309e2c54635SPaolo Bonzini} else { 310e2c54635SPaolo Bonzini @build_time = localtime; 311e2c54635SPaolo Bonzini} 312e2c54635SPaolo Bonzini 313e2c54635SPaolo Bonzinimy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 314e2c54635SPaolo Bonzini 'July', 'August', 'September', 'October', 315e2c54635SPaolo Bonzini 'November', 'December')[$build_time[4]] . 316e2c54635SPaolo Bonzini " " . ($build_time[5]+1900); 317e2c54635SPaolo Bonzini 318e2c54635SPaolo Bonzini# Essentially these are globals. 319e2c54635SPaolo Bonzini# They probably want to be tidied up, made more localised or something. 320e2c54635SPaolo Bonzini# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 321e2c54635SPaolo Bonzini# could cause "use of undefined value" or other bugs. 322e2c54635SPaolo Bonzinimy ($function, %function_table, %parametertypes, $declaration_purpose); 32378c8c92cSMauro Carvalho Chehabmy %nosymbol_table = (); 324e2c54635SPaolo Bonzinimy $declaration_start_line; 325e2c54635SPaolo Bonzinimy ($type, $declaration_name, $return_type); 326e2c54635SPaolo Bonzinimy ($newsection, $newcontents, $prototype, $brcount, %source_map); 327e2c54635SPaolo Bonzini 328e2c54635SPaolo Bonziniif (defined($ENV{'KBUILD_VERBOSE'})) { 329e2c54635SPaolo Bonzini $verbose = "$ENV{'KBUILD_VERBOSE'}"; 330e2c54635SPaolo Bonzini} 331e2c54635SPaolo Bonzini 33286cba217SPierre-Louis Bossartif (defined($ENV{'KDOC_WERROR'})) { 33386cba217SPierre-Louis Bossart $Werror = "$ENV{'KDOC_WERROR'}"; 33486cba217SPierre-Louis Bossart} 33586cba217SPierre-Louis Bossart 33686cba217SPierre-Louis Bossartif (defined($ENV{'KCFLAGS'})) { 33786cba217SPierre-Louis Bossart my $kcflags = "$ENV{'KCFLAGS'}"; 33886cba217SPierre-Louis Bossart 33986cba217SPierre-Louis Bossart if ($kcflags =~ /Werror/) { 34086cba217SPierre-Louis Bossart $Werror = 1; 34186cba217SPierre-Louis Bossart } 34286cba217SPierre-Louis Bossart} 34386cba217SPierre-Louis Bossart 344e2c54635SPaolo Bonzini# Generated docbook code is inserted in a template at a point where 345e2c54635SPaolo Bonzini# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 346cd08b809SAlexander A. Klimov# https://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 347e2c54635SPaolo Bonzini# We keep track of number of generated entries and generate a dummy 348e2c54635SPaolo Bonzini# if needs be to ensure the expanded template can be postprocessed 349e2c54635SPaolo Bonzini# into html. 350e2c54635SPaolo Bonzinimy $section_counter = 0; 351e2c54635SPaolo Bonzini 352e2c54635SPaolo Bonzinimy $lineprefix=""; 353e2c54635SPaolo Bonzini 354e2c54635SPaolo Bonzini# Parser states 355e2c54635SPaolo Bonziniuse constant { 356e2c54635SPaolo Bonzini STATE_NORMAL => 0, # normal code 357e2c54635SPaolo Bonzini STATE_NAME => 1, # looking for function name 358e2c54635SPaolo Bonzini STATE_BODY_MAYBE => 2, # body - or maybe more description 359e2c54635SPaolo Bonzini STATE_BODY => 3, # the body of the comment 3609f2b463aSMauro Carvalho Chehab STATE_BODY_WITH_BLANK_LINE => 4, # the body, which has a blank line 3619f2b463aSMauro Carvalho Chehab STATE_PROTO => 5, # scanning prototype 3629f2b463aSMauro Carvalho Chehab STATE_DOCBLOCK => 6, # documentation block 3639f2b463aSMauro Carvalho Chehab STATE_INLINE => 7, # gathering doc outside main block 364e2c54635SPaolo Bonzini}; 365e2c54635SPaolo Bonzinimy $state; 366e2c54635SPaolo Bonzinimy $in_doc_sect; 367e2c54635SPaolo Bonzinimy $leading_space; 368e2c54635SPaolo Bonzini 369e2c54635SPaolo Bonzini# Inline documentation state 370e2c54635SPaolo Bonziniuse constant { 371e2c54635SPaolo Bonzini STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 372e2c54635SPaolo Bonzini STATE_INLINE_NAME => 1, # looking for member name (@foo:) 373e2c54635SPaolo Bonzini STATE_INLINE_TEXT => 2, # looking for member documentation 374e2c54635SPaolo Bonzini STATE_INLINE_END => 3, # done 375e2c54635SPaolo Bonzini STATE_INLINE_ERROR => 4, # error - Comment without header was found. 376e2c54635SPaolo Bonzini # Spit a warning as it's not 377e2c54635SPaolo Bonzini # proper kernel-doc and ignore the rest. 378e2c54635SPaolo Bonzini}; 379e2c54635SPaolo Bonzinimy $inline_doc_state; 380e2c54635SPaolo Bonzini 381e2c54635SPaolo Bonzini#declaration types: can be 382e2c54635SPaolo Bonzini# 'function', 'struct', 'union', 'enum', 'typedef' 383e2c54635SPaolo Bonzinimy $decl_type; 384e2c54635SPaolo Bonzini 385e2c54635SPaolo Bonzinimy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 386e2c54635SPaolo Bonzinimy $doc_end = '\*/'; 387e2c54635SPaolo Bonzinimy $doc_com = '\s*\*\s*'; 388e2c54635SPaolo Bonzinimy $doc_com_body = '\s*\* ?'; 389e2c54635SPaolo Bonzinimy $doc_decl = $doc_com . '(\w+)'; 390e2c54635SPaolo Bonzini# @params and a strictly limited set of supported section names 391e2c54635SPaolo Bonzinimy $doc_sect = $doc_com . 392e2c54635SPaolo Bonzini '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)'; 393e2c54635SPaolo Bonzinimy $doc_content = $doc_com_body . '(.*)'; 394e2c54635SPaolo Bonzinimy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 395e2c54635SPaolo Bonzinimy $doc_inline_start = '^\s*/\*\*\s*$'; 396e2c54635SPaolo Bonzinimy $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)'; 397e2c54635SPaolo Bonzinimy $doc_inline_end = '^\s*\*/\s*$'; 398e2c54635SPaolo Bonzinimy $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; 399e2c54635SPaolo Bonzinimy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 400e2c54635SPaolo Bonzini 401e2c54635SPaolo Bonzinimy %parameterdescs; 402e2c54635SPaolo Bonzinimy %parameterdesc_start_lines; 403e2c54635SPaolo Bonzinimy @parameterlist; 404e2c54635SPaolo Bonzinimy %sections; 405e2c54635SPaolo Bonzinimy @sectionlist; 406e2c54635SPaolo Bonzinimy %section_start_lines; 407e2c54635SPaolo Bonzinimy $sectcheck; 408e2c54635SPaolo Bonzinimy $struct_actual; 409e2c54635SPaolo Bonzini 410e2c54635SPaolo Bonzinimy $contents = ""; 411e2c54635SPaolo Bonzinimy $new_start_line = 0; 412e2c54635SPaolo Bonzini 413e2c54635SPaolo Bonzini# the canonical section names. see also $doc_sect above. 414e2c54635SPaolo Bonzinimy $section_default = "Description"; # default section 415e2c54635SPaolo Bonzinimy $section_intro = "Introduction"; 416e2c54635SPaolo Bonzinimy $section = $section_default; 417e2c54635SPaolo Bonzinimy $section_context = "Context"; 418e2c54635SPaolo Bonzinimy $section_return = "Return"; 419e2c54635SPaolo Bonzini 420e2c54635SPaolo Bonzinimy $undescribed = "-- undescribed --"; 421e2c54635SPaolo Bonzini 422e2c54635SPaolo Bonzinireset_state(); 423e2c54635SPaolo Bonzini 424e2c54635SPaolo Bonziniwhile ($ARGV[0] =~ m/^--?(.*)/) { 425e2c54635SPaolo Bonzini my $cmd = $1; 426e2c54635SPaolo Bonzini shift @ARGV; 427e2c54635SPaolo Bonzini if ($cmd eq "man") { 428e2c54635SPaolo Bonzini $output_mode = "man"; 429e2c54635SPaolo Bonzini @highlights = @highlights_man; 430e2c54635SPaolo Bonzini $blankline = $blankline_man; 431e2c54635SPaolo Bonzini } elsif ($cmd eq "rst") { 432e2c54635SPaolo Bonzini $output_mode = "rst"; 433e2c54635SPaolo Bonzini @highlights = @highlights_rst; 434e2c54635SPaolo Bonzini $blankline = $blankline_rst; 435e2c54635SPaolo Bonzini } elsif ($cmd eq "none") { 436e2c54635SPaolo Bonzini $output_mode = "none"; 437e2c54635SPaolo Bonzini } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document 438e2c54635SPaolo Bonzini $modulename = shift @ARGV; 439e2c54635SPaolo Bonzini } elsif ($cmd eq "function") { # to only output specific functions 440e2c54635SPaolo Bonzini $output_selection = OUTPUT_INCLUDE; 441e2c54635SPaolo Bonzini $function = shift @ARGV; 442e2c54635SPaolo Bonzini $function_table{$function} = 1; 44378c8c92cSMauro Carvalho Chehab } elsif ($cmd eq "nosymbol") { # Exclude specific symbols 44478c8c92cSMauro Carvalho Chehab my $symbol = shift @ARGV; 44578c8c92cSMauro Carvalho Chehab $nosymbol_table{$symbol} = 1; 446e2c54635SPaolo Bonzini } elsif ($cmd eq "export") { # only exported symbols 447e2c54635SPaolo Bonzini $output_selection = OUTPUT_EXPORTED; 448e2c54635SPaolo Bonzini %function_table = (); 449e2c54635SPaolo Bonzini } elsif ($cmd eq "internal") { # only non-exported symbols 450e2c54635SPaolo Bonzini $output_selection = OUTPUT_INTERNAL; 451e2c54635SPaolo Bonzini %function_table = (); 452e2c54635SPaolo Bonzini } elsif ($cmd eq "export-file") { 453e2c54635SPaolo Bonzini my $file = shift @ARGV; 454e2c54635SPaolo Bonzini push(@export_file_list, $file); 455e2c54635SPaolo Bonzini } elsif ($cmd eq "v") { 456e2c54635SPaolo Bonzini $verbose = 1; 45786cba217SPierre-Louis Bossart } elsif ($cmd eq "Werror") { 45886cba217SPierre-Louis Bossart $Werror = 1; 459e2c54635SPaolo Bonzini } elsif (($cmd eq "h") || ($cmd eq "help")) { 460e2c54635SPaolo Bonzini usage(); 461e2c54635SPaolo Bonzini } elsif ($cmd eq 'no-doc-sections') { 462e2c54635SPaolo Bonzini $no_doc_sections = 1; 463e2c54635SPaolo Bonzini } elsif ($cmd eq 'enable-lineno') { 464e2c54635SPaolo Bonzini $enable_lineno = 1; 465e2c54635SPaolo Bonzini } elsif ($cmd eq 'show-not-found') { 466e2c54635SPaolo Bonzini $show_not_found = 1; # A no-op but don't fail 467486966e4SMauro Carvalho Chehab } elsif ($cmd eq "sphinx-version") { 468486966e4SMauro Carvalho Chehab my $ver_string = shift @ARGV; 469486966e4SMauro Carvalho Chehab if ($ver_string =~ m/^(\d+)(\.\d+)?(\.\d+)?/) { 470486966e4SMauro Carvalho Chehab $sphinx_major = $1; 471486966e4SMauro Carvalho Chehab if (defined($2)) { 472486966e4SMauro Carvalho Chehab $sphinx_minor = substr($2,1); 473486966e4SMauro Carvalho Chehab } else { 474486966e4SMauro Carvalho Chehab $sphinx_minor = 0; 475486966e4SMauro Carvalho Chehab } 476486966e4SMauro Carvalho Chehab if (defined($3)) { 477486966e4SMauro Carvalho Chehab $sphinx_patch = substr($3,1) 478486966e4SMauro Carvalho Chehab } else { 479486966e4SMauro Carvalho Chehab $sphinx_patch = 0; 480486966e4SMauro Carvalho Chehab } 481486966e4SMauro Carvalho Chehab } else { 482486966e4SMauro Carvalho Chehab die "Sphinx version should either major.minor or major.minor.patch format\n"; 483486966e4SMauro Carvalho Chehab } 484e2c54635SPaolo Bonzini } else { 485e2c54635SPaolo Bonzini # Unknown argument 486e2c54635SPaolo Bonzini usage(); 487e2c54635SPaolo Bonzini } 488e2c54635SPaolo Bonzini} 489e2c54635SPaolo Bonzini 490e2c54635SPaolo Bonzini# continue execution near EOF; 491e2c54635SPaolo Bonzini 4926d3a3cfcSMauro Carvalho Chehab# The C domain dialect changed on Sphinx 3. So, we need to check the 4936d3a3cfcSMauro Carvalho Chehab# version in order to produce the right tags. 4946d3a3cfcSMauro Carvalho Chehabsub findprog($) 4956d3a3cfcSMauro Carvalho Chehab{ 4966d3a3cfcSMauro Carvalho Chehab foreach(split(/:/, $ENV{PATH})) { 4976d3a3cfcSMauro Carvalho Chehab return "$_/$_[0]" if(-x "$_/$_[0]"); 4986d3a3cfcSMauro Carvalho Chehab } 4996d3a3cfcSMauro Carvalho Chehab} 5006d3a3cfcSMauro Carvalho Chehab 5016d3a3cfcSMauro Carvalho Chehabsub get_sphinx_version() 5026d3a3cfcSMauro Carvalho Chehab{ 5036d3a3cfcSMauro Carvalho Chehab my $ver; 5046d3a3cfcSMauro Carvalho Chehab 5056d3a3cfcSMauro Carvalho Chehab my $cmd = "sphinx-build"; 5066d3a3cfcSMauro Carvalho Chehab if (!findprog($cmd)) { 5076d3a3cfcSMauro Carvalho Chehab my $cmd = "sphinx-build3"; 508486966e4SMauro Carvalho Chehab if (!findprog($cmd)) { 509486966e4SMauro Carvalho Chehab $sphinx_major = 1; 510486966e4SMauro Carvalho Chehab $sphinx_minor = 2; 511486966e4SMauro Carvalho Chehab $sphinx_patch = 0; 512486966e4SMauro Carvalho Chehab printf STDERR "Warning: Sphinx version not found. Using default (Sphinx version %d.%d.%d)\n", 513486966e4SMauro Carvalho Chehab $sphinx_major, $sphinx_minor, $sphinx_patch; 514486966e4SMauro Carvalho Chehab return; 515486966e4SMauro Carvalho Chehab } 5166d3a3cfcSMauro Carvalho Chehab } 5176d3a3cfcSMauro Carvalho Chehab 5186d3a3cfcSMauro Carvalho Chehab open IN, "$cmd --version 2>&1 |"; 5196d3a3cfcSMauro Carvalho Chehab while (<IN>) { 5206d3a3cfcSMauro Carvalho Chehab if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) { 521486966e4SMauro Carvalho Chehab $sphinx_major = $1; 522486966e4SMauro Carvalho Chehab $sphinx_minor = $2; 523486966e4SMauro Carvalho Chehab $sphinx_patch = $3; 5246d3a3cfcSMauro Carvalho Chehab last; 5256d3a3cfcSMauro Carvalho Chehab } 5266d3a3cfcSMauro Carvalho Chehab # Sphinx 1.2.x uses a different format 5276d3a3cfcSMauro Carvalho Chehab if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+)$/) { 528486966e4SMauro Carvalho Chehab $sphinx_major = $1; 529486966e4SMauro Carvalho Chehab $sphinx_minor = $2; 530486966e4SMauro Carvalho Chehab $sphinx_patch = $3; 5316d3a3cfcSMauro Carvalho Chehab last; 5326d3a3cfcSMauro Carvalho Chehab } 5336d3a3cfcSMauro Carvalho Chehab } 5346d3a3cfcSMauro Carvalho Chehab close IN; 5356d3a3cfcSMauro Carvalho Chehab} 5366d3a3cfcSMauro Carvalho Chehab 537e2c54635SPaolo Bonzini# get kernel version from env 538e2c54635SPaolo Bonzinisub get_kernel_version() { 539e2c54635SPaolo Bonzini my $version = 'unknown kernel version'; 540e2c54635SPaolo Bonzini 541e2c54635SPaolo Bonzini if (defined($ENV{'KERNELVERSION'})) { 542e2c54635SPaolo Bonzini $version = $ENV{'KERNELVERSION'}; 543e2c54635SPaolo Bonzini } 544e2c54635SPaolo Bonzini return $version; 545e2c54635SPaolo Bonzini} 546e2c54635SPaolo Bonzini 547e2c54635SPaolo Bonzini# 548e2c54635SPaolo Bonzinisub print_lineno { 549e2c54635SPaolo Bonzini my $lineno = shift; 550e2c54635SPaolo Bonzini if ($enable_lineno && defined($lineno)) { 551e2c54635SPaolo Bonzini print "#define LINENO " . $lineno . "\n"; 552e2c54635SPaolo Bonzini } 553e2c54635SPaolo Bonzini} 554e2c54635SPaolo Bonzini## 555e2c54635SPaolo Bonzini# dumps section contents to arrays/hashes intended for that purpose. 556e2c54635SPaolo Bonzini# 557e2c54635SPaolo Bonzinisub dump_section { 558e2c54635SPaolo Bonzini my $file = shift; 559e2c54635SPaolo Bonzini my $name = shift; 560e2c54635SPaolo Bonzini my $contents = join "\n", @_; 561e2c54635SPaolo Bonzini 562e2c54635SPaolo Bonzini if ($name =~ m/$type_param/) { 563e2c54635SPaolo Bonzini $name = $1; 564e2c54635SPaolo Bonzini $parameterdescs{$name} = $contents; 565e2c54635SPaolo Bonzini $sectcheck = $sectcheck . $name . " "; 566e2c54635SPaolo Bonzini $parameterdesc_start_lines{$name} = $new_start_line; 567e2c54635SPaolo Bonzini $new_start_line = 0; 568e2c54635SPaolo Bonzini } elsif ($name eq "@\.\.\.") { 569e2c54635SPaolo Bonzini $name = "..."; 570e2c54635SPaolo Bonzini $parameterdescs{$name} = $contents; 571e2c54635SPaolo Bonzini $sectcheck = $sectcheck . $name . " "; 572e2c54635SPaolo Bonzini $parameterdesc_start_lines{$name} = $new_start_line; 573e2c54635SPaolo Bonzini $new_start_line = 0; 574e2c54635SPaolo Bonzini } else { 575e2c54635SPaolo Bonzini if (defined($sections{$name}) && ($sections{$name} ne "")) { 576e2c54635SPaolo Bonzini # Only warn on user specified duplicate section names. 577e2c54635SPaolo Bonzini if ($name ne $section_default) { 578e2c54635SPaolo Bonzini print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; 579e2c54635SPaolo Bonzini ++$warnings; 580e2c54635SPaolo Bonzini } 581e2c54635SPaolo Bonzini $sections{$name} .= $contents; 582e2c54635SPaolo Bonzini } else { 583e2c54635SPaolo Bonzini $sections{$name} = $contents; 584e2c54635SPaolo Bonzini push @sectionlist, $name; 585e2c54635SPaolo Bonzini $section_start_lines{$name} = $new_start_line; 586e2c54635SPaolo Bonzini $new_start_line = 0; 587e2c54635SPaolo Bonzini } 588e2c54635SPaolo Bonzini } 589e2c54635SPaolo Bonzini} 590e2c54635SPaolo Bonzini 591e2c54635SPaolo Bonzini## 592e2c54635SPaolo Bonzini# dump DOC: section after checking that it should go out 593e2c54635SPaolo Bonzini# 594e2c54635SPaolo Bonzinisub dump_doc_section { 595e2c54635SPaolo Bonzini my $file = shift; 596e2c54635SPaolo Bonzini my $name = shift; 597e2c54635SPaolo Bonzini my $contents = join "\n", @_; 598e2c54635SPaolo Bonzini 599e2c54635SPaolo Bonzini if ($no_doc_sections) { 600e2c54635SPaolo Bonzini return; 601e2c54635SPaolo Bonzini } 602e2c54635SPaolo Bonzini 60378c8c92cSMauro Carvalho Chehab return if (defined($nosymbol_table{$name})); 60478c8c92cSMauro Carvalho Chehab 605e2c54635SPaolo Bonzini if (($output_selection == OUTPUT_ALL) || 60678c8c92cSMauro Carvalho Chehab (($output_selection == OUTPUT_INCLUDE) && 60778c8c92cSMauro Carvalho Chehab defined($function_table{$name}))) 608e2c54635SPaolo Bonzini { 609e2c54635SPaolo Bonzini dump_section($file, $name, $contents); 610e2c54635SPaolo Bonzini output_blockhead({'sectionlist' => \@sectionlist, 611e2c54635SPaolo Bonzini 'sections' => \%sections, 612e2c54635SPaolo Bonzini 'module' => $modulename, 613e2c54635SPaolo Bonzini 'content-only' => ($output_selection != OUTPUT_ALL), }); 614e2c54635SPaolo Bonzini } 615e2c54635SPaolo Bonzini} 616e2c54635SPaolo Bonzini 617e2c54635SPaolo Bonzini## 618e2c54635SPaolo Bonzini# output function 619e2c54635SPaolo Bonzini# 620e2c54635SPaolo Bonzini# parameterdescs, a hash. 621e2c54635SPaolo Bonzini# function => "function name" 622e2c54635SPaolo Bonzini# parameterlist => @list of parameters 623e2c54635SPaolo Bonzini# parameterdescs => %parameter descriptions 624e2c54635SPaolo Bonzini# sectionlist => @list of sections 625e2c54635SPaolo Bonzini# sections => %section descriptions 626e2c54635SPaolo Bonzini# 627e2c54635SPaolo Bonzini 628e2c54635SPaolo Bonzinisub output_highlight { 629e2c54635SPaolo Bonzini my $contents = join "\n",@_; 630e2c54635SPaolo Bonzini my $line; 631e2c54635SPaolo Bonzini 632e2c54635SPaolo Bonzini# DEBUG 633e2c54635SPaolo Bonzini# if (!defined $contents) { 634e2c54635SPaolo Bonzini# use Carp; 635e2c54635SPaolo Bonzini# confess "output_highlight got called with no args?\n"; 636e2c54635SPaolo Bonzini# } 637e2c54635SPaolo Bonzini 638e2c54635SPaolo Bonzini# print STDERR "contents b4:$contents\n"; 639e2c54635SPaolo Bonzini eval $dohighlight; 640e2c54635SPaolo Bonzini die $@ if $@; 641e2c54635SPaolo Bonzini# print STDERR "contents af:$contents\n"; 642e2c54635SPaolo Bonzini 643e2c54635SPaolo Bonzini foreach $line (split "\n", $contents) { 644e2c54635SPaolo Bonzini if (! $output_preformatted) { 645e2c54635SPaolo Bonzini $line =~ s/^\s*//; 646e2c54635SPaolo Bonzini } 647e2c54635SPaolo Bonzini if ($line eq ""){ 648e2c54635SPaolo Bonzini if (! $output_preformatted) { 649e2c54635SPaolo Bonzini print $lineprefix, $blankline; 650e2c54635SPaolo Bonzini } 651e2c54635SPaolo Bonzini } else { 652e2c54635SPaolo Bonzini if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 653e2c54635SPaolo Bonzini print "\\&$line"; 654e2c54635SPaolo Bonzini } else { 655e2c54635SPaolo Bonzini print $lineprefix, $line; 656e2c54635SPaolo Bonzini } 657e2c54635SPaolo Bonzini } 658e2c54635SPaolo Bonzini print "\n"; 659e2c54635SPaolo Bonzini } 660e2c54635SPaolo Bonzini} 661e2c54635SPaolo Bonzini 662e2c54635SPaolo Bonzini## 663e2c54635SPaolo Bonzini# output function in man 664e2c54635SPaolo Bonzinisub output_function_man(%) { 665e2c54635SPaolo Bonzini my %args = %{$_[0]}; 666e2c54635SPaolo Bonzini my ($parameter, $section); 667e2c54635SPaolo Bonzini my $count; 668e2c54635SPaolo Bonzini 669e2c54635SPaolo Bonzini print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 670e2c54635SPaolo Bonzini 671e2c54635SPaolo Bonzini print ".SH NAME\n"; 672e2c54635SPaolo Bonzini print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 673e2c54635SPaolo Bonzini 674e2c54635SPaolo Bonzini print ".SH SYNOPSIS\n"; 675e2c54635SPaolo Bonzini if ($args{'functiontype'} ne "") { 676e2c54635SPaolo Bonzini print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 677e2c54635SPaolo Bonzini } else { 678e2c54635SPaolo Bonzini print ".B \"" . $args{'function'} . "\n"; 679e2c54635SPaolo Bonzini } 680e2c54635SPaolo Bonzini $count = 0; 681e2c54635SPaolo Bonzini my $parenth = "("; 682e2c54635SPaolo Bonzini my $post = ","; 683e2c54635SPaolo Bonzini foreach my $parameter (@{$args{'parameterlist'}}) { 684e2c54635SPaolo Bonzini if ($count == $#{$args{'parameterlist'}}) { 685e2c54635SPaolo Bonzini $post = ");"; 686e2c54635SPaolo Bonzini } 687e2c54635SPaolo Bonzini $type = $args{'parametertypes'}{$parameter}; 688e2c54635SPaolo Bonzini if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 689e2c54635SPaolo Bonzini # pointer-to-function 6900c771852SMauro Carvalho Chehab print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n"; 691e2c54635SPaolo Bonzini } else { 692e2c54635SPaolo Bonzini $type =~ s/([^\*])$/$1 /; 6930c771852SMauro Carvalho Chehab print ".BI \"" . $parenth . $type . "\" " . " \"" . $post . "\"\n"; 694e2c54635SPaolo Bonzini } 695e2c54635SPaolo Bonzini $count++; 696e2c54635SPaolo Bonzini $parenth = ""; 697e2c54635SPaolo Bonzini } 698e2c54635SPaolo Bonzini 699e2c54635SPaolo Bonzini print ".SH ARGUMENTS\n"; 700e2c54635SPaolo Bonzini foreach $parameter (@{$args{'parameterlist'}}) { 701e2c54635SPaolo Bonzini my $parameter_name = $parameter; 702e2c54635SPaolo Bonzini $parameter_name =~ s/\[.*//; 703e2c54635SPaolo Bonzini 704e2c54635SPaolo Bonzini print ".IP \"" . $parameter . "\" 12\n"; 705e2c54635SPaolo Bonzini output_highlight($args{'parameterdescs'}{$parameter_name}); 706e2c54635SPaolo Bonzini } 707e2c54635SPaolo Bonzini foreach $section (@{$args{'sectionlist'}}) { 708e2c54635SPaolo Bonzini print ".SH \"", uc $section, "\"\n"; 709e2c54635SPaolo Bonzini output_highlight($args{'sections'}{$section}); 710e2c54635SPaolo Bonzini } 711e2c54635SPaolo Bonzini} 712e2c54635SPaolo Bonzini 713e2c54635SPaolo Bonzini## 714e2c54635SPaolo Bonzini# output enum in man 715e2c54635SPaolo Bonzinisub output_enum_man(%) { 716e2c54635SPaolo Bonzini my %args = %{$_[0]}; 717e2c54635SPaolo Bonzini my ($parameter, $section); 718e2c54635SPaolo Bonzini my $count; 719e2c54635SPaolo Bonzini 720e2c54635SPaolo Bonzini print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 721e2c54635SPaolo Bonzini 722e2c54635SPaolo Bonzini print ".SH NAME\n"; 723e2c54635SPaolo Bonzini print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 724e2c54635SPaolo Bonzini 725e2c54635SPaolo Bonzini print ".SH SYNOPSIS\n"; 726e2c54635SPaolo Bonzini print "enum " . $args{'enum'} . " {\n"; 727e2c54635SPaolo Bonzini $count = 0; 728e2c54635SPaolo Bonzini foreach my $parameter (@{$args{'parameterlist'}}) { 729e2c54635SPaolo Bonzini print ".br\n.BI \" $parameter\"\n"; 730e2c54635SPaolo Bonzini if ($count == $#{$args{'parameterlist'}}) { 731e2c54635SPaolo Bonzini print "\n};\n"; 732e2c54635SPaolo Bonzini last; 733e2c54635SPaolo Bonzini } 734e2c54635SPaolo Bonzini else { 735e2c54635SPaolo Bonzini print ", \n.br\n"; 736e2c54635SPaolo Bonzini } 737e2c54635SPaolo Bonzini $count++; 738e2c54635SPaolo Bonzini } 739e2c54635SPaolo Bonzini 740e2c54635SPaolo Bonzini print ".SH Constants\n"; 741e2c54635SPaolo Bonzini foreach $parameter (@{$args{'parameterlist'}}) { 742e2c54635SPaolo Bonzini my $parameter_name = $parameter; 743e2c54635SPaolo Bonzini $parameter_name =~ s/\[.*//; 744e2c54635SPaolo Bonzini 745e2c54635SPaolo Bonzini print ".IP \"" . $parameter . "\" 12\n"; 746e2c54635SPaolo Bonzini output_highlight($args{'parameterdescs'}{$parameter_name}); 747e2c54635SPaolo Bonzini } 748e2c54635SPaolo Bonzini foreach $section (@{$args{'sectionlist'}}) { 749e2c54635SPaolo Bonzini print ".SH \"$section\"\n"; 750e2c54635SPaolo Bonzini output_highlight($args{'sections'}{$section}); 751e2c54635SPaolo Bonzini } 752e2c54635SPaolo Bonzini} 753e2c54635SPaolo Bonzini 754e2c54635SPaolo Bonzini## 755e2c54635SPaolo Bonzini# output struct in man 756e2c54635SPaolo Bonzinisub output_struct_man(%) { 757e2c54635SPaolo Bonzini my %args = %{$_[0]}; 758e2c54635SPaolo Bonzini my ($parameter, $section); 759e2c54635SPaolo Bonzini 760e2c54635SPaolo Bonzini print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 761e2c54635SPaolo Bonzini 762e2c54635SPaolo Bonzini print ".SH NAME\n"; 763e2c54635SPaolo Bonzini print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 764e2c54635SPaolo Bonzini 765e2c54635SPaolo Bonzini my $declaration = $args{'definition'}; 766e2c54635SPaolo Bonzini $declaration =~ s/\t/ /g; 767e2c54635SPaolo Bonzini $declaration =~ s/\n/"\n.br\n.BI \"/g; 768e2c54635SPaolo Bonzini print ".SH SYNOPSIS\n"; 769e2c54635SPaolo Bonzini print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 770e2c54635SPaolo Bonzini print ".BI \"$declaration\n};\n.br\n\n"; 771e2c54635SPaolo Bonzini 772e2c54635SPaolo Bonzini print ".SH Members\n"; 773e2c54635SPaolo Bonzini foreach $parameter (@{$args{'parameterlist'}}) { 774e2c54635SPaolo Bonzini ($parameter =~ /^#/) && next; 775e2c54635SPaolo Bonzini 776e2c54635SPaolo Bonzini my $parameter_name = $parameter; 777e2c54635SPaolo Bonzini $parameter_name =~ s/\[.*//; 778e2c54635SPaolo Bonzini 779e2c54635SPaolo Bonzini ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 780e2c54635SPaolo Bonzini print ".IP \"" . $parameter . "\" 12\n"; 781e2c54635SPaolo Bonzini output_highlight($args{'parameterdescs'}{$parameter_name}); 782e2c54635SPaolo Bonzini } 783e2c54635SPaolo Bonzini foreach $section (@{$args{'sectionlist'}}) { 784e2c54635SPaolo Bonzini print ".SH \"$section\"\n"; 785e2c54635SPaolo Bonzini output_highlight($args{'sections'}{$section}); 786e2c54635SPaolo Bonzini } 787e2c54635SPaolo Bonzini} 788e2c54635SPaolo Bonzini 789e2c54635SPaolo Bonzini## 790e2c54635SPaolo Bonzini# output typedef in man 791e2c54635SPaolo Bonzinisub output_typedef_man(%) { 792e2c54635SPaolo Bonzini my %args = %{$_[0]}; 793e2c54635SPaolo Bonzini my ($parameter, $section); 794e2c54635SPaolo Bonzini 795e2c54635SPaolo Bonzini print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 796e2c54635SPaolo Bonzini 797e2c54635SPaolo Bonzini print ".SH NAME\n"; 798e2c54635SPaolo Bonzini print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 799e2c54635SPaolo Bonzini 800e2c54635SPaolo Bonzini foreach $section (@{$args{'sectionlist'}}) { 801e2c54635SPaolo Bonzini print ".SH \"$section\"\n"; 802e2c54635SPaolo Bonzini output_highlight($args{'sections'}{$section}); 803e2c54635SPaolo Bonzini } 804e2c54635SPaolo Bonzini} 805e2c54635SPaolo Bonzini 806e2c54635SPaolo Bonzinisub output_blockhead_man(%) { 807e2c54635SPaolo Bonzini my %args = %{$_[0]}; 808e2c54635SPaolo Bonzini my ($parameter, $section); 809e2c54635SPaolo Bonzini my $count; 810e2c54635SPaolo Bonzini 811e2c54635SPaolo Bonzini print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 812e2c54635SPaolo Bonzini 813e2c54635SPaolo Bonzini foreach $section (@{$args{'sectionlist'}}) { 814e2c54635SPaolo Bonzini print ".SH \"$section\"\n"; 815e2c54635SPaolo Bonzini output_highlight($args{'sections'}{$section}); 816e2c54635SPaolo Bonzini } 817e2c54635SPaolo Bonzini} 818e2c54635SPaolo Bonzini 819e2c54635SPaolo Bonzini## 820e2c54635SPaolo Bonzini# output in restructured text 821e2c54635SPaolo Bonzini# 822e2c54635SPaolo Bonzini 823e2c54635SPaolo Bonzini# 824e2c54635SPaolo Bonzini# This could use some work; it's used to output the DOC: sections, and 825e2c54635SPaolo Bonzini# starts by putting out the name of the doc section itself, but that tends 826e2c54635SPaolo Bonzini# to duplicate a header already in the template file. 827e2c54635SPaolo Bonzini# 828e2c54635SPaolo Bonzinisub output_blockhead_rst(%) { 829e2c54635SPaolo Bonzini my %args = %{$_[0]}; 830e2c54635SPaolo Bonzini my ($parameter, $section); 831e2c54635SPaolo Bonzini 832e2c54635SPaolo Bonzini foreach $section (@{$args{'sectionlist'}}) { 83378c8c92cSMauro Carvalho Chehab next if (defined($nosymbol_table{$section})); 83478c8c92cSMauro Carvalho Chehab 835e2c54635SPaolo Bonzini if ($output_selection != OUTPUT_INCLUDE) { 836e2c54635SPaolo Bonzini print "**$section**\n\n"; 837e2c54635SPaolo Bonzini } 838e2c54635SPaolo Bonzini print_lineno($section_start_lines{$section}); 839e2c54635SPaolo Bonzini output_highlight_rst($args{'sections'}{$section}); 840e2c54635SPaolo Bonzini print "\n"; 841e2c54635SPaolo Bonzini } 842e2c54635SPaolo Bonzini} 843e2c54635SPaolo Bonzini 844e2c54635SPaolo Bonzini# 845e2c54635SPaolo Bonzini# Apply the RST highlights to a sub-block of text. 846e2c54635SPaolo Bonzini# 847e2c54635SPaolo Bonzinisub highlight_block($) { 848e2c54635SPaolo Bonzini # The dohighlight kludge requires the text be called $contents 849e2c54635SPaolo Bonzini my $contents = shift; 850e2c54635SPaolo Bonzini eval $dohighlight; 851e2c54635SPaolo Bonzini die $@ if $@; 852e2c54635SPaolo Bonzini return $contents; 853e2c54635SPaolo Bonzini} 854e2c54635SPaolo Bonzini 855e2c54635SPaolo Bonzini# 856e2c54635SPaolo Bonzini# Regexes used only here. 857e2c54635SPaolo Bonzini# 858e2c54635SPaolo Bonzinimy $sphinx_literal = '^[^.].*::$'; 859e2c54635SPaolo Bonzinimy $sphinx_cblock = '^\.\.\ +code-block::'; 860e2c54635SPaolo Bonzini 861e2c54635SPaolo Bonzinisub output_highlight_rst { 862e2c54635SPaolo Bonzini my $input = join "\n",@_; 863e2c54635SPaolo Bonzini my $output = ""; 864e2c54635SPaolo Bonzini my $line; 865e2c54635SPaolo Bonzini my $in_literal = 0; 866e2c54635SPaolo Bonzini my $litprefix; 867e2c54635SPaolo Bonzini my $block = ""; 868e2c54635SPaolo Bonzini 869e2c54635SPaolo Bonzini foreach $line (split "\n",$input) { 870e2c54635SPaolo Bonzini # 871e2c54635SPaolo Bonzini # If we're in a literal block, see if we should drop out 872e2c54635SPaolo Bonzini # of it. Otherwise pass the line straight through unmunged. 873e2c54635SPaolo Bonzini # 874e2c54635SPaolo Bonzini if ($in_literal) { 875e2c54635SPaolo Bonzini if (! ($line =~ /^\s*$/)) { 876e2c54635SPaolo Bonzini # 877e2c54635SPaolo Bonzini # If this is the first non-blank line in a literal 878e2c54635SPaolo Bonzini # block we need to figure out what the proper indent is. 879e2c54635SPaolo Bonzini # 880e2c54635SPaolo Bonzini if ($litprefix eq "") { 881e2c54635SPaolo Bonzini $line =~ /^(\s*)/; 882e2c54635SPaolo Bonzini $litprefix = '^' . $1; 883e2c54635SPaolo Bonzini $output .= $line . "\n"; 884e2c54635SPaolo Bonzini } elsif (! ($line =~ /$litprefix/)) { 885e2c54635SPaolo Bonzini $in_literal = 0; 886e2c54635SPaolo Bonzini } else { 887e2c54635SPaolo Bonzini $output .= $line . "\n"; 888e2c54635SPaolo Bonzini } 889e2c54635SPaolo Bonzini } else { 890e2c54635SPaolo Bonzini $output .= $line . "\n"; 891e2c54635SPaolo Bonzini } 892e2c54635SPaolo Bonzini } 893e2c54635SPaolo Bonzini # 894e2c54635SPaolo Bonzini # Not in a literal block (or just dropped out) 895e2c54635SPaolo Bonzini # 896e2c54635SPaolo Bonzini if (! $in_literal) { 897e2c54635SPaolo Bonzini $block .= $line . "\n"; 898e2c54635SPaolo Bonzini if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) { 899e2c54635SPaolo Bonzini $in_literal = 1; 900e2c54635SPaolo Bonzini $litprefix = ""; 901e2c54635SPaolo Bonzini $output .= highlight_block($block); 902e2c54635SPaolo Bonzini $block = "" 903e2c54635SPaolo Bonzini } 904e2c54635SPaolo Bonzini } 905e2c54635SPaolo Bonzini } 906e2c54635SPaolo Bonzini 907e2c54635SPaolo Bonzini if ($block) { 908e2c54635SPaolo Bonzini $output .= highlight_block($block); 909e2c54635SPaolo Bonzini } 910e2c54635SPaolo Bonzini foreach $line (split "\n", $output) { 911e2c54635SPaolo Bonzini print $lineprefix . $line . "\n"; 912e2c54635SPaolo Bonzini } 913e2c54635SPaolo Bonzini} 914e2c54635SPaolo Bonzini 915e2c54635SPaolo Bonzinisub output_function_rst(%) { 916e2c54635SPaolo Bonzini my %args = %{$_[0]}; 917e2c54635SPaolo Bonzini my ($parameter, $section); 918e2c54635SPaolo Bonzini my $oldprefix = $lineprefix; 919e2c54635SPaolo Bonzini my $start = ""; 920ac3617d9SMauro Carvalho Chehab my $is_macro = 0; 921e2c54635SPaolo Bonzini 9226d3a3cfcSMauro Carvalho Chehab if ($sphinx_major < 3) { 92360ef7c18SMauro Carvalho Chehab if ($args{'typedef'}) { 924e2c54635SPaolo Bonzini print ".. c:type:: ". $args{'function'} . "\n\n"; 925e2c54635SPaolo Bonzini print_lineno($declaration_start_line); 926e2c54635SPaolo Bonzini print " **Typedef**: "; 927e2c54635SPaolo Bonzini $lineprefix = ""; 928e2c54635SPaolo Bonzini output_highlight_rst($args{'purpose'}); 929e2c54635SPaolo Bonzini $start = "\n\n**Syntax**\n\n ``"; 930ac3617d9SMauro Carvalho Chehab $is_macro = 1; 931e2c54635SPaolo Bonzini } else { 932e2c54635SPaolo Bonzini print ".. c:function:: "; 933e2c54635SPaolo Bonzini } 93460ef7c18SMauro Carvalho Chehab } else { 935ac3617d9SMauro Carvalho Chehab if ($args{'typedef'} || $args{'functiontype'} eq "") { 936ac3617d9SMauro Carvalho Chehab $is_macro = 1; 93760ef7c18SMauro Carvalho Chehab print ".. c:macro:: ". $args{'function'} . "\n\n"; 938ac3617d9SMauro Carvalho Chehab } else { 939ac3617d9SMauro Carvalho Chehab print ".. c:function:: "; 940ac3617d9SMauro Carvalho Chehab } 94160ef7c18SMauro Carvalho Chehab 94260ef7c18SMauro Carvalho Chehab if ($args{'typedef'}) { 94360ef7c18SMauro Carvalho Chehab print_lineno($declaration_start_line); 94460ef7c18SMauro Carvalho Chehab print " **Typedef**: "; 94560ef7c18SMauro Carvalho Chehab $lineprefix = ""; 94660ef7c18SMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 94760ef7c18SMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 94860ef7c18SMauro Carvalho Chehab } else { 949ac3617d9SMauro Carvalho Chehab print "``" if ($is_macro); 95060ef7c18SMauro Carvalho Chehab } 95160ef7c18SMauro Carvalho Chehab } 952e2c54635SPaolo Bonzini if ($args{'functiontype'} ne "") { 953e2c54635SPaolo Bonzini $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; 954e2c54635SPaolo Bonzini } else { 955e2c54635SPaolo Bonzini $start .= $args{'function'} . " ("; 956e2c54635SPaolo Bonzini } 957e2c54635SPaolo Bonzini print $start; 958e2c54635SPaolo Bonzini 959e2c54635SPaolo Bonzini my $count = 0; 960e2c54635SPaolo Bonzini foreach my $parameter (@{$args{'parameterlist'}}) { 961e2c54635SPaolo Bonzini if ($count ne 0) { 962e2c54635SPaolo Bonzini print ", "; 963e2c54635SPaolo Bonzini } 964e2c54635SPaolo Bonzini $count++; 965e2c54635SPaolo Bonzini $type = $args{'parametertypes'}{$parameter}; 966e2c54635SPaolo Bonzini 967e2c54635SPaolo Bonzini if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 968e2c54635SPaolo Bonzini # pointer-to-function 969a62d5637SPeter Maydell print $1 . $parameter . ") (" . $2 . ")"; 970e2c54635SPaolo Bonzini } else { 9710c771852SMauro Carvalho Chehab print $type; 972e2c54635SPaolo Bonzini } 973e2c54635SPaolo Bonzini } 974ac3617d9SMauro Carvalho Chehab if ($is_macro) { 975ac3617d9SMauro Carvalho Chehab print ")``\n\n"; 976e2c54635SPaolo Bonzini } else { 977e2c54635SPaolo Bonzini print ")\n\n"; 97860ef7c18SMauro Carvalho Chehab } 979ac3617d9SMauro Carvalho Chehab if (!$args{'typedef'}) { 980e2c54635SPaolo Bonzini print_lineno($declaration_start_line); 981e2c54635SPaolo Bonzini $lineprefix = " "; 982e2c54635SPaolo Bonzini output_highlight_rst($args{'purpose'}); 983e2c54635SPaolo Bonzini print "\n"; 984e2c54635SPaolo Bonzini } 985e2c54635SPaolo Bonzini 986e2c54635SPaolo Bonzini print "**Parameters**\n\n"; 987e2c54635SPaolo Bonzini $lineprefix = " "; 988e2c54635SPaolo Bonzini foreach $parameter (@{$args{'parameterlist'}}) { 989e2c54635SPaolo Bonzini my $parameter_name = $parameter; 990e2c54635SPaolo Bonzini $parameter_name =~ s/\[.*//; 991e2c54635SPaolo Bonzini $type = $args{'parametertypes'}{$parameter}; 992e2c54635SPaolo Bonzini 993e2c54635SPaolo Bonzini if ($type ne "") { 9940c771852SMauro Carvalho Chehab print "``$type``\n"; 995e2c54635SPaolo Bonzini } else { 996e2c54635SPaolo Bonzini print "``$parameter``\n"; 997e2c54635SPaolo Bonzini } 998e2c54635SPaolo Bonzini 999e2c54635SPaolo Bonzini print_lineno($parameterdesc_start_lines{$parameter_name}); 1000e2c54635SPaolo Bonzini 1001e2c54635SPaolo Bonzini if (defined($args{'parameterdescs'}{$parameter_name}) && 1002e2c54635SPaolo Bonzini $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 1003e2c54635SPaolo Bonzini output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1004e2c54635SPaolo Bonzini } else { 1005e2c54635SPaolo Bonzini print " *undescribed*\n"; 1006e2c54635SPaolo Bonzini } 1007e2c54635SPaolo Bonzini print "\n"; 1008e2c54635SPaolo Bonzini } 1009e2c54635SPaolo Bonzini 1010e2c54635SPaolo Bonzini $lineprefix = $oldprefix; 1011e2c54635SPaolo Bonzini output_section_rst(@_); 1012e2c54635SPaolo Bonzini} 1013e2c54635SPaolo Bonzini 1014e2c54635SPaolo Bonzinisub output_section_rst(%) { 1015e2c54635SPaolo Bonzini my %args = %{$_[0]}; 1016e2c54635SPaolo Bonzini my $section; 1017e2c54635SPaolo Bonzini my $oldprefix = $lineprefix; 1018e2c54635SPaolo Bonzini $lineprefix = ""; 1019e2c54635SPaolo Bonzini 1020e2c54635SPaolo Bonzini foreach $section (@{$args{'sectionlist'}}) { 1021e2c54635SPaolo Bonzini print "**$section**\n\n"; 1022e2c54635SPaolo Bonzini print_lineno($section_start_lines{$section}); 1023e2c54635SPaolo Bonzini output_highlight_rst($args{'sections'}{$section}); 1024e2c54635SPaolo Bonzini print "\n"; 1025e2c54635SPaolo Bonzini } 1026e2c54635SPaolo Bonzini print "\n"; 1027e2c54635SPaolo Bonzini $lineprefix = $oldprefix; 1028e2c54635SPaolo Bonzini} 1029e2c54635SPaolo Bonzini 1030e2c54635SPaolo Bonzinisub output_enum_rst(%) { 1031e2c54635SPaolo Bonzini my %args = %{$_[0]}; 1032e2c54635SPaolo Bonzini my ($parameter); 1033e2c54635SPaolo Bonzini my $oldprefix = $lineprefix; 1034e2c54635SPaolo Bonzini my $count; 1035e2c54635SPaolo Bonzini 10366d3a3cfcSMauro Carvalho Chehab if ($sphinx_major < 3) { 10376d3a3cfcSMauro Carvalho Chehab my $name = "enum " . $args{'enum'}; 1038e2c54635SPaolo Bonzini print "\n\n.. c:type:: " . $name . "\n\n"; 10396d3a3cfcSMauro Carvalho Chehab } else { 10406d3a3cfcSMauro Carvalho Chehab my $name = $args{'enum'}; 10416d3a3cfcSMauro Carvalho Chehab print "\n\n.. c:enum:: " . $name . "\n\n"; 10426d3a3cfcSMauro Carvalho Chehab } 1043e2c54635SPaolo Bonzini print_lineno($declaration_start_line); 1044e2c54635SPaolo Bonzini $lineprefix = " "; 1045e2c54635SPaolo Bonzini output_highlight_rst($args{'purpose'}); 1046e2c54635SPaolo Bonzini print "\n"; 1047e2c54635SPaolo Bonzini 1048e2c54635SPaolo Bonzini print "**Constants**\n\n"; 1049e2c54635SPaolo Bonzini $lineprefix = " "; 1050e2c54635SPaolo Bonzini foreach $parameter (@{$args{'parameterlist'}}) { 1051e2c54635SPaolo Bonzini print "``$parameter``\n"; 1052e2c54635SPaolo Bonzini if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 1053e2c54635SPaolo Bonzini output_highlight_rst($args{'parameterdescs'}{$parameter}); 1054e2c54635SPaolo Bonzini } else { 1055e2c54635SPaolo Bonzini print " *undescribed*\n"; 1056e2c54635SPaolo Bonzini } 1057e2c54635SPaolo Bonzini print "\n"; 1058e2c54635SPaolo Bonzini } 1059e2c54635SPaolo Bonzini 1060e2c54635SPaolo Bonzini $lineprefix = $oldprefix; 1061e2c54635SPaolo Bonzini output_section_rst(@_); 1062e2c54635SPaolo Bonzini} 1063e2c54635SPaolo Bonzini 1064e2c54635SPaolo Bonzinisub output_typedef_rst(%) { 1065e2c54635SPaolo Bonzini my %args = %{$_[0]}; 1066e2c54635SPaolo Bonzini my ($parameter); 1067e2c54635SPaolo Bonzini my $oldprefix = $lineprefix; 10686d3a3cfcSMauro Carvalho Chehab my $name; 1069e2c54635SPaolo Bonzini 10706d3a3cfcSMauro Carvalho Chehab if ($sphinx_major < 3) { 10716d3a3cfcSMauro Carvalho Chehab $name = "typedef " . $args{'typedef'}; 10726d3a3cfcSMauro Carvalho Chehab } else { 10736d3a3cfcSMauro Carvalho Chehab $name = $args{'typedef'}; 10746d3a3cfcSMauro Carvalho Chehab } 1075e2c54635SPaolo Bonzini print "\n\n.. c:type:: " . $name . "\n\n"; 1076e2c54635SPaolo Bonzini print_lineno($declaration_start_line); 1077e2c54635SPaolo Bonzini $lineprefix = " "; 1078e2c54635SPaolo Bonzini output_highlight_rst($args{'purpose'}); 1079e2c54635SPaolo Bonzini print "\n"; 1080e2c54635SPaolo Bonzini 1081e2c54635SPaolo Bonzini $lineprefix = $oldprefix; 1082e2c54635SPaolo Bonzini output_section_rst(@_); 1083e2c54635SPaolo Bonzini} 1084e2c54635SPaolo Bonzini 1085e2c54635SPaolo Bonzinisub output_struct_rst(%) { 1086e2c54635SPaolo Bonzini my %args = %{$_[0]}; 1087e2c54635SPaolo Bonzini my ($parameter); 1088e2c54635SPaolo Bonzini my $oldprefix = $lineprefix; 1089e2c54635SPaolo Bonzini 10906d3a3cfcSMauro Carvalho Chehab if ($sphinx_major < 3) { 10916d3a3cfcSMauro Carvalho Chehab my $name = $args{'type'} . " " . $args{'struct'}; 1092e2c54635SPaolo Bonzini print "\n\n.. c:type:: " . $name . "\n\n"; 10936d3a3cfcSMauro Carvalho Chehab } else { 10946d3a3cfcSMauro Carvalho Chehab my $name = $args{'struct'}; 1095a1b8a57aSMauro Carvalho Chehab if ($args{'type'} eq 'union') { 1096a1b8a57aSMauro Carvalho Chehab print "\n\n.. c:union:: " . $name . "\n\n"; 1097a1b8a57aSMauro Carvalho Chehab } else { 10986d3a3cfcSMauro Carvalho Chehab print "\n\n.. c:struct:: " . $name . "\n\n"; 10996d3a3cfcSMauro Carvalho Chehab } 1100a1b8a57aSMauro Carvalho Chehab } 1101e2c54635SPaolo Bonzini print_lineno($declaration_start_line); 1102e2c54635SPaolo Bonzini $lineprefix = " "; 1103e2c54635SPaolo Bonzini output_highlight_rst($args{'purpose'}); 1104e2c54635SPaolo Bonzini print "\n"; 1105e2c54635SPaolo Bonzini 1106e2c54635SPaolo Bonzini print "**Definition**\n\n"; 1107e2c54635SPaolo Bonzini print "::\n\n"; 1108e2c54635SPaolo Bonzini my $declaration = $args{'definition'}; 1109e2c54635SPaolo Bonzini $declaration =~ s/\t/ /g; 1110e2c54635SPaolo Bonzini print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n"; 1111e2c54635SPaolo Bonzini 1112e2c54635SPaolo Bonzini print "**Members**\n\n"; 1113e2c54635SPaolo Bonzini $lineprefix = " "; 1114e2c54635SPaolo Bonzini foreach $parameter (@{$args{'parameterlist'}}) { 1115e2c54635SPaolo Bonzini ($parameter =~ /^#/) && next; 1116e2c54635SPaolo Bonzini 1117e2c54635SPaolo Bonzini my $parameter_name = $parameter; 1118e2c54635SPaolo Bonzini $parameter_name =~ s/\[.*//; 1119e2c54635SPaolo Bonzini 1120e2c54635SPaolo Bonzini ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1121e2c54635SPaolo Bonzini $type = $args{'parametertypes'}{$parameter}; 1122e2c54635SPaolo Bonzini print_lineno($parameterdesc_start_lines{$parameter_name}); 1123e2c54635SPaolo Bonzini print "``" . $parameter . "``\n"; 1124e2c54635SPaolo Bonzini output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1125e2c54635SPaolo Bonzini print "\n"; 1126e2c54635SPaolo Bonzini } 1127e2c54635SPaolo Bonzini print "\n"; 1128e2c54635SPaolo Bonzini 1129e2c54635SPaolo Bonzini $lineprefix = $oldprefix; 1130e2c54635SPaolo Bonzini output_section_rst(@_); 1131e2c54635SPaolo Bonzini} 1132e2c54635SPaolo Bonzini 1133e2c54635SPaolo Bonzini## none mode output functions 1134e2c54635SPaolo Bonzini 1135e2c54635SPaolo Bonzinisub output_function_none(%) { 1136e2c54635SPaolo Bonzini} 1137e2c54635SPaolo Bonzini 1138e2c54635SPaolo Bonzinisub output_enum_none(%) { 1139e2c54635SPaolo Bonzini} 1140e2c54635SPaolo Bonzini 1141e2c54635SPaolo Bonzinisub output_typedef_none(%) { 1142e2c54635SPaolo Bonzini} 1143e2c54635SPaolo Bonzini 1144e2c54635SPaolo Bonzinisub output_struct_none(%) { 1145e2c54635SPaolo Bonzini} 1146e2c54635SPaolo Bonzini 1147e2c54635SPaolo Bonzinisub output_blockhead_none(%) { 1148e2c54635SPaolo Bonzini} 1149e2c54635SPaolo Bonzini 1150e2c54635SPaolo Bonzini## 1151e2c54635SPaolo Bonzini# generic output function for all types (function, struct/union, typedef, enum); 1152e2c54635SPaolo Bonzini# calls the generated, variable output_ function name based on 1153e2c54635SPaolo Bonzini# functype and output_mode 1154e2c54635SPaolo Bonzinisub output_declaration { 1155e2c54635SPaolo Bonzini no strict 'refs'; 1156e2c54635SPaolo Bonzini my $name = shift; 1157e2c54635SPaolo Bonzini my $functype = shift; 1158e2c54635SPaolo Bonzini my $func = "output_${functype}_$output_mode"; 115978c8c92cSMauro Carvalho Chehab 116078c8c92cSMauro Carvalho Chehab return if (defined($nosymbol_table{$name})); 116178c8c92cSMauro Carvalho Chehab 1162e2c54635SPaolo Bonzini if (($output_selection == OUTPUT_ALL) || 1163e2c54635SPaolo Bonzini (($output_selection == OUTPUT_INCLUDE || 1164e2c54635SPaolo Bonzini $output_selection == OUTPUT_EXPORTED) && 1165e2c54635SPaolo Bonzini defined($function_table{$name})) || 116678c8c92cSMauro Carvalho Chehab ($output_selection == OUTPUT_INTERNAL && 1167e2c54635SPaolo Bonzini !($functype eq "function" && defined($function_table{$name})))) 1168e2c54635SPaolo Bonzini { 1169e2c54635SPaolo Bonzini &$func(@_); 1170e2c54635SPaolo Bonzini $section_counter++; 1171e2c54635SPaolo Bonzini } 1172e2c54635SPaolo Bonzini} 1173e2c54635SPaolo Bonzini 1174e2c54635SPaolo Bonzini## 1175e2c54635SPaolo Bonzini# generic output function - calls the right one based on current output mode. 1176e2c54635SPaolo Bonzinisub output_blockhead { 1177e2c54635SPaolo Bonzini no strict 'refs'; 1178e2c54635SPaolo Bonzini my $func = "output_blockhead_" . $output_mode; 1179e2c54635SPaolo Bonzini &$func(@_); 1180e2c54635SPaolo Bonzini $section_counter++; 1181e2c54635SPaolo Bonzini} 1182e2c54635SPaolo Bonzini 1183e2c54635SPaolo Bonzini## 1184e2c54635SPaolo Bonzini# takes a declaration (struct, union, enum, typedef) and 1185e2c54635SPaolo Bonzini# invokes the right handler. NOT called for functions. 1186e2c54635SPaolo Bonzinisub dump_declaration($$) { 1187e2c54635SPaolo Bonzini no strict 'refs'; 1188e2c54635SPaolo Bonzini my ($prototype, $file) = @_; 1189e2c54635SPaolo Bonzini my $func = "dump_" . $decl_type; 1190e2c54635SPaolo Bonzini &$func(@_); 1191e2c54635SPaolo Bonzini} 1192e2c54635SPaolo Bonzini 1193e2c54635SPaolo Bonzinisub dump_union($$) { 1194e2c54635SPaolo Bonzini dump_struct(@_); 1195e2c54635SPaolo Bonzini} 1196e2c54635SPaolo Bonzini 1197e2c54635SPaolo Bonzinisub dump_struct($$) { 1198e2c54635SPaolo Bonzini my $x = shift; 1199e2c54635SPaolo Bonzini my $file = shift; 1200e2c54635SPaolo Bonzini 12015c51f435SJonathan Cameron if ($x =~ /(struct|union)\s+(\w+)\s*\{(.*)\}(\s*(__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned|__attribute__\s*\(\([a-z0-9,_\s\(\)]*\)\)))*/) { 1202e2c54635SPaolo Bonzini my $decl_type = $1; 1203e2c54635SPaolo Bonzini $declaration_name = $2; 1204e2c54635SPaolo Bonzini my $members = $3; 1205e2c54635SPaolo Bonzini 1206e2c54635SPaolo Bonzini # ignore members marked private: 1207e2c54635SPaolo Bonzini $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 1208e2c54635SPaolo Bonzini $members =~ s/\/\*\s*private:.*//gosi; 1209e2c54635SPaolo Bonzini # strip comments: 1210e2c54635SPaolo Bonzini $members =~ s/\/\*.*?\*\///gos; 1211e2c54635SPaolo Bonzini # strip attributes 1212e2c54635SPaolo Bonzini $members =~ s/\s*__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)/ /gi; 1213e2c54635SPaolo Bonzini $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos; 1214e2c54635SPaolo Bonzini $members =~ s/\s*__packed\s*/ /gos; 1215e2c54635SPaolo Bonzini $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos; 1216b5a8dfb5SAndré Almeida $members =~ s/\s*____cacheline_aligned_in_smp/ /gos; 12175c51f435SJonathan Cameron $members =~ s/\s*____cacheline_aligned/ /gos; 1218f0fd307dSMauro Carvalho Chehab 1219e2c54635SPaolo Bonzini # replace DECLARE_BITMAP 1220f0fd307dSMauro Carvalho Chehab $members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos; 1221e2c54635SPaolo Bonzini $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 1222e2c54635SPaolo Bonzini # replace DECLARE_HASHTABLE 1223e2c54635SPaolo Bonzini $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos; 1224e2c54635SPaolo Bonzini # replace DECLARE_KFIFO 1225e2c54635SPaolo Bonzini $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; 1226e2c54635SPaolo Bonzini # replace DECLARE_KFIFO_PTR 1227e2c54635SPaolo Bonzini $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; 1228e2c54635SPaolo Bonzini 1229e2c54635SPaolo Bonzini my $declaration = $members; 1230e2c54635SPaolo Bonzini 1231e2c54635SPaolo Bonzini # Split nested struct/union elements as newer ones 1232e2c54635SPaolo Bonzini while ($members =~ m/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/) { 1233e2c54635SPaolo Bonzini my $newmember; 1234e2c54635SPaolo Bonzini my $maintype = $1; 1235e2c54635SPaolo Bonzini my $ids = $4; 1236e2c54635SPaolo Bonzini my $content = $3; 1237e2c54635SPaolo Bonzini foreach my $id(split /,/, $ids) { 1238e2c54635SPaolo Bonzini $newmember .= "$maintype $id; "; 1239e2c54635SPaolo Bonzini 1240e2c54635SPaolo Bonzini $id =~ s/[:\[].*//; 1241e2c54635SPaolo Bonzini $id =~ s/^\s*\**(\S+)\s*/$1/; 1242e2c54635SPaolo Bonzini foreach my $arg (split /;/, $content) { 1243e2c54635SPaolo Bonzini next if ($arg =~ m/^\s*$/); 1244e2c54635SPaolo Bonzini if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) { 1245e2c54635SPaolo Bonzini # pointer-to-function 1246e2c54635SPaolo Bonzini my $type = $1; 1247e2c54635SPaolo Bonzini my $name = $2; 1248e2c54635SPaolo Bonzini my $extra = $3; 1249e2c54635SPaolo Bonzini next if (!$name); 1250e2c54635SPaolo Bonzini if ($id =~ m/^\s*$/) { 1251e2c54635SPaolo Bonzini # anonymous struct/union 1252e2c54635SPaolo Bonzini $newmember .= "$type$name$extra; "; 1253e2c54635SPaolo Bonzini } else { 1254e2c54635SPaolo Bonzini $newmember .= "$type$id.$name$extra; "; 1255e2c54635SPaolo Bonzini } 1256e2c54635SPaolo Bonzini } else { 1257e2c54635SPaolo Bonzini my $type; 1258e2c54635SPaolo Bonzini my $names; 1259e2c54635SPaolo Bonzini $arg =~ s/^\s+//; 1260e2c54635SPaolo Bonzini $arg =~ s/\s+$//; 1261e2c54635SPaolo Bonzini # Handle bitmaps 1262e2c54635SPaolo Bonzini $arg =~ s/:\s*\d+\s*//g; 1263e2c54635SPaolo Bonzini # Handle arrays 1264e2c54635SPaolo Bonzini $arg =~ s/\[.*\]//g; 1265e2c54635SPaolo Bonzini # The type may have multiple words, 1266e2c54635SPaolo Bonzini # and multiple IDs can be defined, like: 1267e2c54635SPaolo Bonzini # const struct foo, *bar, foobar 1268e2c54635SPaolo Bonzini # So, we remove spaces when parsing the 1269e2c54635SPaolo Bonzini # names, in order to match just names 1270e2c54635SPaolo Bonzini # and commas for the names 1271e2c54635SPaolo Bonzini $arg =~ s/\s*,\s*/,/g; 1272e2c54635SPaolo Bonzini if ($arg =~ m/(.*)\s+([\S+,]+)/) { 1273e2c54635SPaolo Bonzini $type = $1; 1274e2c54635SPaolo Bonzini $names = $2; 1275e2c54635SPaolo Bonzini } else { 1276e2c54635SPaolo Bonzini $newmember .= "$arg; "; 1277e2c54635SPaolo Bonzini next; 1278e2c54635SPaolo Bonzini } 1279e2c54635SPaolo Bonzini foreach my $name (split /,/, $names) { 1280e2c54635SPaolo Bonzini $name =~ s/^\s*\**(\S+)\s*/$1/; 1281e2c54635SPaolo Bonzini next if (($name =~ m/^\s*$/)); 1282e2c54635SPaolo Bonzini if ($id =~ m/^\s*$/) { 1283e2c54635SPaolo Bonzini # anonymous struct/union 1284e2c54635SPaolo Bonzini $newmember .= "$type $name; "; 1285e2c54635SPaolo Bonzini } else { 1286e2c54635SPaolo Bonzini $newmember .= "$type $id.$name; "; 1287e2c54635SPaolo Bonzini } 1288e2c54635SPaolo Bonzini } 1289e2c54635SPaolo Bonzini } 1290e2c54635SPaolo Bonzini } 1291e2c54635SPaolo Bonzini } 1292e2c54635SPaolo Bonzini $members =~ s/(struct|union)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;/$newmember/; 1293e2c54635SPaolo Bonzini } 1294e2c54635SPaolo Bonzini 1295e2c54635SPaolo Bonzini # Ignore other nested elements, like enums 1296e2c54635SPaolo Bonzini $members =~ s/(\{[^\{\}]*\})//g; 1297e2c54635SPaolo Bonzini 1298e2c54635SPaolo Bonzini create_parameterlist($members, ';', $file, $declaration_name); 1299e2c54635SPaolo Bonzini check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual); 1300e2c54635SPaolo Bonzini 1301e2c54635SPaolo Bonzini # Adjust declaration for better display 1302e2c54635SPaolo Bonzini $declaration =~ s/([\{;])/$1\n/g; 1303e2c54635SPaolo Bonzini $declaration =~ s/\}\s+;/};/g; 1304e2c54635SPaolo Bonzini # Better handle inlined enums 1305e2c54635SPaolo Bonzini do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/); 1306e2c54635SPaolo Bonzini 1307e2c54635SPaolo Bonzini my @def_args = split /\n/, $declaration; 1308e2c54635SPaolo Bonzini my $level = 1; 1309e2c54635SPaolo Bonzini $declaration = ""; 1310e2c54635SPaolo Bonzini foreach my $clause (@def_args) { 1311e2c54635SPaolo Bonzini $clause =~ s/^\s+//; 1312e2c54635SPaolo Bonzini $clause =~ s/\s+$//; 1313e2c54635SPaolo Bonzini $clause =~ s/\s+/ /; 1314e2c54635SPaolo Bonzini next if (!$clause); 1315e2c54635SPaolo Bonzini $level-- if ($clause =~ m/(\})/ && $level > 1); 1316e2c54635SPaolo Bonzini if (!($clause =~ m/^\s*#/)) { 1317e2c54635SPaolo Bonzini $declaration .= "\t" x $level; 1318e2c54635SPaolo Bonzini } 1319e2c54635SPaolo Bonzini $declaration .= "\t" . $clause . "\n"; 1320e2c54635SPaolo Bonzini $level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/)); 1321e2c54635SPaolo Bonzini } 1322e2c54635SPaolo Bonzini output_declaration($declaration_name, 1323e2c54635SPaolo Bonzini 'struct', 1324e2c54635SPaolo Bonzini {'struct' => $declaration_name, 1325e2c54635SPaolo Bonzini 'module' => $modulename, 1326e2c54635SPaolo Bonzini 'definition' => $declaration, 1327e2c54635SPaolo Bonzini 'parameterlist' => \@parameterlist, 1328e2c54635SPaolo Bonzini 'parameterdescs' => \%parameterdescs, 1329e2c54635SPaolo Bonzini 'parametertypes' => \%parametertypes, 1330e2c54635SPaolo Bonzini 'sectionlist' => \@sectionlist, 1331e2c54635SPaolo Bonzini 'sections' => \%sections, 1332e2c54635SPaolo Bonzini 'purpose' => $declaration_purpose, 1333e2c54635SPaolo Bonzini 'type' => $decl_type 1334e2c54635SPaolo Bonzini }); 1335e2c54635SPaolo Bonzini } 1336e2c54635SPaolo Bonzini else { 1337e2c54635SPaolo Bonzini print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 1338e2c54635SPaolo Bonzini ++$errors; 1339e2c54635SPaolo Bonzini } 1340e2c54635SPaolo Bonzini} 1341e2c54635SPaolo Bonzini 1342e2c54635SPaolo Bonzini 1343e2c54635SPaolo Bonzinisub show_warnings($$) { 1344e2c54635SPaolo Bonzini my $functype = shift; 1345e2c54635SPaolo Bonzini my $name = shift; 1346e2c54635SPaolo Bonzini 134778c8c92cSMauro Carvalho Chehab return 0 if (defined($nosymbol_table{$name})); 134878c8c92cSMauro Carvalho Chehab 1349e2c54635SPaolo Bonzini return 1 if ($output_selection == OUTPUT_ALL); 1350e2c54635SPaolo Bonzini 1351e2c54635SPaolo Bonzini if ($output_selection == OUTPUT_EXPORTED) { 1352e2c54635SPaolo Bonzini if (defined($function_table{$name})) { 1353e2c54635SPaolo Bonzini return 1; 1354e2c54635SPaolo Bonzini } else { 1355e2c54635SPaolo Bonzini return 0; 1356e2c54635SPaolo Bonzini } 1357e2c54635SPaolo Bonzini } 1358e2c54635SPaolo Bonzini if ($output_selection == OUTPUT_INTERNAL) { 1359e2c54635SPaolo Bonzini if (!($functype eq "function" && defined($function_table{$name}))) { 1360e2c54635SPaolo Bonzini return 1; 1361e2c54635SPaolo Bonzini } else { 1362e2c54635SPaolo Bonzini return 0; 1363e2c54635SPaolo Bonzini } 1364e2c54635SPaolo Bonzini } 1365e2c54635SPaolo Bonzini if ($output_selection == OUTPUT_INCLUDE) { 1366e2c54635SPaolo Bonzini if (defined($function_table{$name})) { 1367e2c54635SPaolo Bonzini return 1; 1368e2c54635SPaolo Bonzini } else { 1369e2c54635SPaolo Bonzini return 0; 1370e2c54635SPaolo Bonzini } 1371e2c54635SPaolo Bonzini } 1372e2c54635SPaolo Bonzini die("Please add the new output type at show_warnings()"); 1373e2c54635SPaolo Bonzini} 1374e2c54635SPaolo Bonzini 1375e2c54635SPaolo Bonzinisub dump_enum($$) { 1376e2c54635SPaolo Bonzini my $x = shift; 1377e2c54635SPaolo Bonzini my $file = shift; 1378306b015cSMauro Carvalho Chehab my $members; 1379306b015cSMauro Carvalho Chehab 1380e2c54635SPaolo Bonzini 1381e2c54635SPaolo Bonzini $x =~ s@/\*.*?\*/@@gos; # strip comments. 1382e2c54635SPaolo Bonzini # strip #define macros inside enums 1383e2c54635SPaolo Bonzini $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 1384e2c54635SPaolo Bonzini 1385306b015cSMauro Carvalho Chehab if ($x =~ /typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;/) { 1386306b015cSMauro Carvalho Chehab $declaration_name = $2; 1387306b015cSMauro Carvalho Chehab $members = $1; 1388306b015cSMauro Carvalho Chehab } elsif ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) { 1389e2c54635SPaolo Bonzini $declaration_name = $1; 1390306b015cSMauro Carvalho Chehab $members = $2; 1391306b015cSMauro Carvalho Chehab } 1392306b015cSMauro Carvalho Chehab 1393306b015cSMauro Carvalho Chehab if ($declaration_name) { 1394e2c54635SPaolo Bonzini my %_members; 1395e2c54635SPaolo Bonzini 1396e2c54635SPaolo Bonzini $members =~ s/\s+$//; 1397e2c54635SPaolo Bonzini 1398e2c54635SPaolo Bonzini foreach my $arg (split ',', $members) { 1399e2c54635SPaolo Bonzini $arg =~ s/^\s*(\w+).*/$1/; 1400e2c54635SPaolo Bonzini push @parameterlist, $arg; 1401e2c54635SPaolo Bonzini if (!$parameterdescs{$arg}) { 1402e2c54635SPaolo Bonzini $parameterdescs{$arg} = $undescribed; 1403e2c54635SPaolo Bonzini if (show_warnings("enum", $declaration_name)) { 1404e2c54635SPaolo Bonzini print STDERR "${file}:$.: warning: Enum value '$arg' not described in enum '$declaration_name'\n"; 1405e2c54635SPaolo Bonzini } 1406e2c54635SPaolo Bonzini } 1407e2c54635SPaolo Bonzini $_members{$arg} = 1; 1408e2c54635SPaolo Bonzini } 1409e2c54635SPaolo Bonzini 1410e2c54635SPaolo Bonzini while (my ($k, $v) = each %parameterdescs) { 1411e2c54635SPaolo Bonzini if (!exists($_members{$k})) { 1412e2c54635SPaolo Bonzini if (show_warnings("enum", $declaration_name)) { 1413e2c54635SPaolo Bonzini print STDERR "${file}:$.: warning: Excess enum value '$k' description in '$declaration_name'\n"; 1414e2c54635SPaolo Bonzini } 1415e2c54635SPaolo Bonzini } 1416e2c54635SPaolo Bonzini } 1417e2c54635SPaolo Bonzini 1418e2c54635SPaolo Bonzini output_declaration($declaration_name, 1419e2c54635SPaolo Bonzini 'enum', 1420e2c54635SPaolo Bonzini {'enum' => $declaration_name, 1421e2c54635SPaolo Bonzini 'module' => $modulename, 1422e2c54635SPaolo Bonzini 'parameterlist' => \@parameterlist, 1423e2c54635SPaolo Bonzini 'parameterdescs' => \%parameterdescs, 1424e2c54635SPaolo Bonzini 'sectionlist' => \@sectionlist, 1425e2c54635SPaolo Bonzini 'sections' => \%sections, 1426e2c54635SPaolo Bonzini 'purpose' => $declaration_purpose 1427e2c54635SPaolo Bonzini }); 1428306b015cSMauro Carvalho Chehab } else { 1429e2c54635SPaolo Bonzini print STDERR "${file}:$.: error: Cannot parse enum!\n"; 1430e2c54635SPaolo Bonzini ++$errors; 1431e2c54635SPaolo Bonzini } 1432e2c54635SPaolo Bonzini} 1433e2c54635SPaolo Bonzini 1434e495a1b2SMauro Carvalho Chehabmy $typedef_type = qr { ((?:\s+[\w\*]+){1,8})\s* }x; 1435e495a1b2SMauro Carvalho Chehabmy $typedef_ident = qr { \*?\s*(\w\S+)\s* }x; 1436e495a1b2SMauro Carvalho Chehabmy $typedef_args = qr { \s*\((.*)\); }x; 1437e495a1b2SMauro Carvalho Chehab 1438e495a1b2SMauro Carvalho Chehabmy $typedef1 = qr { typedef$typedef_type\($typedef_ident\)$typedef_args }x; 1439e495a1b2SMauro Carvalho Chehabmy $typedef2 = qr { typedef$typedef_type$typedef_ident$typedef_args }x; 1440e495a1b2SMauro Carvalho Chehab 1441e2c54635SPaolo Bonzinisub dump_typedef($$) { 1442e2c54635SPaolo Bonzini my $x = shift; 1443e2c54635SPaolo Bonzini my $file = shift; 1444e2c54635SPaolo Bonzini 1445e2c54635SPaolo Bonzini $x =~ s@/\*.*?\*/@@gos; # strip comments. 1446e2c54635SPaolo Bonzini 1447e495a1b2SMauro Carvalho Chehab # Parse function typedef prototypes 1448e495a1b2SMauro Carvalho Chehab if ($x =~ $typedef1 || $x =~ $typedef2) { 1449e2c54635SPaolo Bonzini $return_type = $1; 1450e2c54635SPaolo Bonzini $declaration_name = $2; 1451e2c54635SPaolo Bonzini my $args = $3; 145201a7917dSMauro Carvalho Chehab $return_type =~ s/^\s+//; 1453e2c54635SPaolo Bonzini 1454e2c54635SPaolo Bonzini create_parameterlist($args, ',', $file, $declaration_name); 1455e2c54635SPaolo Bonzini 1456e2c54635SPaolo Bonzini output_declaration($declaration_name, 1457e2c54635SPaolo Bonzini 'function', 1458e2c54635SPaolo Bonzini {'function' => $declaration_name, 1459e2c54635SPaolo Bonzini 'typedef' => 1, 1460e2c54635SPaolo Bonzini 'module' => $modulename, 1461e2c54635SPaolo Bonzini 'functiontype' => $return_type, 1462e2c54635SPaolo Bonzini 'parameterlist' => \@parameterlist, 1463e2c54635SPaolo Bonzini 'parameterdescs' => \%parameterdescs, 1464e2c54635SPaolo Bonzini 'parametertypes' => \%parametertypes, 1465e2c54635SPaolo Bonzini 'sectionlist' => \@sectionlist, 1466e2c54635SPaolo Bonzini 'sections' => \%sections, 1467e2c54635SPaolo Bonzini 'purpose' => $declaration_purpose 1468e2c54635SPaolo Bonzini }); 1469e2c54635SPaolo Bonzini return; 1470e2c54635SPaolo Bonzini } 1471e2c54635SPaolo Bonzini 1472e2c54635SPaolo Bonzini while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 1473e2c54635SPaolo Bonzini $x =~ s/\(*.\)\s*;$/;/; 1474e2c54635SPaolo Bonzini $x =~ s/\[*.\]\s*;$/;/; 1475e2c54635SPaolo Bonzini } 1476e2c54635SPaolo Bonzini 1477e2c54635SPaolo Bonzini if ($x =~ /typedef.*\s+(\w+)\s*;/) { 1478e2c54635SPaolo Bonzini $declaration_name = $1; 1479e2c54635SPaolo Bonzini 1480e2c54635SPaolo Bonzini output_declaration($declaration_name, 1481e2c54635SPaolo Bonzini 'typedef', 1482e2c54635SPaolo Bonzini {'typedef' => $declaration_name, 1483e2c54635SPaolo Bonzini 'module' => $modulename, 1484e2c54635SPaolo Bonzini 'sectionlist' => \@sectionlist, 1485e2c54635SPaolo Bonzini 'sections' => \%sections, 1486e2c54635SPaolo Bonzini 'purpose' => $declaration_purpose 1487e2c54635SPaolo Bonzini }); 1488e2c54635SPaolo Bonzini } 1489e2c54635SPaolo Bonzini else { 1490e2c54635SPaolo Bonzini print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 1491e2c54635SPaolo Bonzini ++$errors; 1492e2c54635SPaolo Bonzini } 1493e2c54635SPaolo Bonzini} 1494e2c54635SPaolo Bonzini 1495e2c54635SPaolo Bonzinisub save_struct_actual($) { 1496e2c54635SPaolo Bonzini my $actual = shift; 1497e2c54635SPaolo Bonzini 1498e2c54635SPaolo Bonzini # strip all spaces from the actual param so that it looks like one string item 1499e2c54635SPaolo Bonzini $actual =~ s/\s*//g; 1500e2c54635SPaolo Bonzini $struct_actual = $struct_actual . $actual . " "; 1501e2c54635SPaolo Bonzini} 1502e2c54635SPaolo Bonzini 1503e2c54635SPaolo Bonzinisub create_parameterlist($$$$) { 1504e2c54635SPaolo Bonzini my $args = shift; 1505e2c54635SPaolo Bonzini my $splitter = shift; 1506e2c54635SPaolo Bonzini my $file = shift; 1507e2c54635SPaolo Bonzini my $declaration_name = shift; 1508e2c54635SPaolo Bonzini my $type; 1509e2c54635SPaolo Bonzini my $param; 1510e2c54635SPaolo Bonzini 1511e2c54635SPaolo Bonzini # temporarily replace commas inside function pointer definition 1512e2c54635SPaolo Bonzini while ($args =~ /(\([^\),]+),/) { 1513e2c54635SPaolo Bonzini $args =~ s/(\([^\),]+),/$1#/g; 1514e2c54635SPaolo Bonzini } 1515e2c54635SPaolo Bonzini 1516e2c54635SPaolo Bonzini foreach my $arg (split($splitter, $args)) { 1517e2c54635SPaolo Bonzini # strip comments 1518e2c54635SPaolo Bonzini $arg =~ s/\/\*.*\*\///; 1519e2c54635SPaolo Bonzini # strip leading/trailing spaces 1520e2c54635SPaolo Bonzini $arg =~ s/^\s*//; 1521e2c54635SPaolo Bonzini $arg =~ s/\s*$//; 1522e2c54635SPaolo Bonzini $arg =~ s/\s+/ /; 1523e2c54635SPaolo Bonzini 1524e2c54635SPaolo Bonzini if ($arg =~ /^#/) { 1525e2c54635SPaolo Bonzini # Treat preprocessor directive as a typeless variable just to fill 1526e2c54635SPaolo Bonzini # corresponding data structures "correctly". Catch it later in 1527e2c54635SPaolo Bonzini # output_* subs. 15280c771852SMauro Carvalho Chehab push_parameter($arg, "", "", $file); 1529e2c54635SPaolo Bonzini } elsif ($arg =~ m/\(.+\)\s*\(/) { 1530e2c54635SPaolo Bonzini # pointer-to-function 1531e2c54635SPaolo Bonzini $arg =~ tr/#/,/; 1532e2c54635SPaolo Bonzini $arg =~ m/[^\(]+\(\*?\s*([\w\.]*)\s*\)/; 1533e2c54635SPaolo Bonzini $param = $1; 1534e2c54635SPaolo Bonzini $type = $arg; 1535e2c54635SPaolo Bonzini $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1536e2c54635SPaolo Bonzini save_struct_actual($param); 15370c771852SMauro Carvalho Chehab push_parameter($param, $type, $arg, $file, $declaration_name); 1538e2c54635SPaolo Bonzini } elsif ($arg) { 1539e2c54635SPaolo Bonzini $arg =~ s/\s*:\s*/:/g; 1540e2c54635SPaolo Bonzini $arg =~ s/\s*\[/\[/g; 1541e2c54635SPaolo Bonzini 1542e2c54635SPaolo Bonzini my @args = split('\s*,\s*', $arg); 1543e2c54635SPaolo Bonzini if ($args[0] =~ m/\*/) { 1544e2c54635SPaolo Bonzini $args[0] =~ s/(\*+)\s*/ $1/; 1545e2c54635SPaolo Bonzini } 1546e2c54635SPaolo Bonzini 1547e2c54635SPaolo Bonzini my @first_arg; 1548e2c54635SPaolo Bonzini if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1549e2c54635SPaolo Bonzini shift @args; 1550e2c54635SPaolo Bonzini push(@first_arg, split('\s+', $1)); 1551e2c54635SPaolo Bonzini push(@first_arg, $2); 1552e2c54635SPaolo Bonzini } else { 1553e2c54635SPaolo Bonzini @first_arg = split('\s+', shift @args); 1554e2c54635SPaolo Bonzini } 1555e2c54635SPaolo Bonzini 1556e2c54635SPaolo Bonzini unshift(@args, pop @first_arg); 1557e2c54635SPaolo Bonzini $type = join " ", @first_arg; 1558e2c54635SPaolo Bonzini 1559e2c54635SPaolo Bonzini foreach $param (@args) { 1560e2c54635SPaolo Bonzini if ($param =~ m/^(\*+)\s*(.*)/) { 1561e2c54635SPaolo Bonzini save_struct_actual($2); 15620c771852SMauro Carvalho Chehab 15630c771852SMauro Carvalho Chehab push_parameter($2, "$type $1", $arg, $file, $declaration_name); 1564e2c54635SPaolo Bonzini } 1565e2c54635SPaolo Bonzini elsif ($param =~ m/(.*?):(\d+)/) { 1566e2c54635SPaolo Bonzini if ($type ne "") { # skip unnamed bit-fields 1567e2c54635SPaolo Bonzini save_struct_actual($1); 15680c771852SMauro Carvalho Chehab push_parameter($1, "$type:$2", $arg, $file, $declaration_name) 1569e2c54635SPaolo Bonzini } 1570e2c54635SPaolo Bonzini } 1571e2c54635SPaolo Bonzini else { 1572e2c54635SPaolo Bonzini save_struct_actual($param); 15730c771852SMauro Carvalho Chehab push_parameter($param, $type, $arg, $file, $declaration_name); 1574e2c54635SPaolo Bonzini } 1575e2c54635SPaolo Bonzini } 1576e2c54635SPaolo Bonzini } 1577e2c54635SPaolo Bonzini } 1578e2c54635SPaolo Bonzini} 1579e2c54635SPaolo Bonzini 15800c771852SMauro Carvalho Chehabsub push_parameter($$$$$) { 1581e2c54635SPaolo Bonzini my $param = shift; 1582e2c54635SPaolo Bonzini my $type = shift; 15830c771852SMauro Carvalho Chehab my $org_arg = shift; 1584e2c54635SPaolo Bonzini my $file = shift; 1585e2c54635SPaolo Bonzini my $declaration_name = shift; 1586e2c54635SPaolo Bonzini 1587e2c54635SPaolo Bonzini if (($anon_struct_union == 1) && ($type eq "") && 1588e2c54635SPaolo Bonzini ($param eq "}")) { 1589e2c54635SPaolo Bonzini return; # ignore the ending }; from anon. struct/union 1590e2c54635SPaolo Bonzini } 1591e2c54635SPaolo Bonzini 1592e2c54635SPaolo Bonzini $anon_struct_union = 0; 1593e2c54635SPaolo Bonzini $param =~ s/[\[\)].*//; 1594e2c54635SPaolo Bonzini 1595e2c54635SPaolo Bonzini if ($type eq "" && $param =~ /\.\.\.$/) 1596e2c54635SPaolo Bonzini { 1597e2c54635SPaolo Bonzini if (!$param =~ /\w\.\.\.$/) { 1598e2c54635SPaolo Bonzini # handles unnamed variable parameters 1599e2c54635SPaolo Bonzini $param = "..."; 1600e2c54635SPaolo Bonzini } 160165fb67bfSJonathan Neuschäfer elsif ($param =~ /\w\.\.\.$/) { 160265fb67bfSJonathan Neuschäfer # for named variable parameters of the form `x...`, remove the dots 160365fb67bfSJonathan Neuschäfer $param =~ s/\.\.\.$//; 160465fb67bfSJonathan Neuschäfer } 1605e2c54635SPaolo Bonzini if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1606e2c54635SPaolo Bonzini $parameterdescs{$param} = "variable arguments"; 1607e2c54635SPaolo Bonzini } 1608e2c54635SPaolo Bonzini } 1609e2c54635SPaolo Bonzini elsif ($type eq "" && ($param eq "" or $param eq "void")) 1610e2c54635SPaolo Bonzini { 1611e2c54635SPaolo Bonzini $param="void"; 1612e2c54635SPaolo Bonzini $parameterdescs{void} = "no arguments"; 1613e2c54635SPaolo Bonzini } 1614e2c54635SPaolo Bonzini elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1615e2c54635SPaolo Bonzini # handle unnamed (anonymous) union or struct: 1616e2c54635SPaolo Bonzini { 1617e2c54635SPaolo Bonzini $type = $param; 1618e2c54635SPaolo Bonzini $param = "{unnamed_" . $param . "}"; 1619e2c54635SPaolo Bonzini $parameterdescs{$param} = "anonymous\n"; 1620e2c54635SPaolo Bonzini $anon_struct_union = 1; 1621e2c54635SPaolo Bonzini } 1622e2c54635SPaolo Bonzini 1623e2c54635SPaolo Bonzini # warn if parameter has no description 1624e2c54635SPaolo Bonzini # (but ignore ones starting with # as these are not parameters 1625e2c54635SPaolo Bonzini # but inline preprocessor statements); 1626e2c54635SPaolo Bonzini # Note: It will also ignore void params and unnamed structs/unions 1627e2c54635SPaolo Bonzini if (!defined $parameterdescs{$param} && $param !~ /^#/) { 1628e2c54635SPaolo Bonzini $parameterdescs{$param} = $undescribed; 1629e2c54635SPaolo Bonzini 1630e2c54635SPaolo Bonzini if (show_warnings($type, $declaration_name) && $param !~ /\./) { 1631e2c54635SPaolo Bonzini print STDERR 1632e2c54635SPaolo Bonzini "${file}:$.: warning: Function parameter or member '$param' not described in '$declaration_name'\n"; 1633e2c54635SPaolo Bonzini ++$warnings; 1634e2c54635SPaolo Bonzini } 1635e2c54635SPaolo Bonzini } 1636e2c54635SPaolo Bonzini 1637e2c54635SPaolo Bonzini # strip spaces from $param so that it is one continuous string 1638e2c54635SPaolo Bonzini # on @parameterlist; 1639e2c54635SPaolo Bonzini # this fixes a problem where check_sections() cannot find 1640e2c54635SPaolo Bonzini # a parameter like "addr[6 + 2]" because it actually appears 1641e2c54635SPaolo Bonzini # as "addr[6", "+", "2]" on the parameter list; 1642e2c54635SPaolo Bonzini # but it's better to maintain the param string unchanged for output, 1643e2c54635SPaolo Bonzini # so just weaken the string compare in check_sections() to ignore 1644e2c54635SPaolo Bonzini # "[blah" in a parameter string; 1645e2c54635SPaolo Bonzini ###$param =~ s/\s*//g; 1646e2c54635SPaolo Bonzini push @parameterlist, $param; 16470c771852SMauro Carvalho Chehab $org_arg =~ s/\s\s+/ /g; 16480c771852SMauro Carvalho Chehab $parametertypes{$param} = $org_arg; 1649e2c54635SPaolo Bonzini} 1650e2c54635SPaolo Bonzini 1651e2c54635SPaolo Bonzinisub check_sections($$$$$) { 1652e2c54635SPaolo Bonzini my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_; 1653e2c54635SPaolo Bonzini my @sects = split ' ', $sectcheck; 1654e2c54635SPaolo Bonzini my @prms = split ' ', $prmscheck; 1655e2c54635SPaolo Bonzini my $err; 1656e2c54635SPaolo Bonzini my ($px, $sx); 1657e2c54635SPaolo Bonzini my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 1658e2c54635SPaolo Bonzini 1659e2c54635SPaolo Bonzini foreach $sx (0 .. $#sects) { 1660e2c54635SPaolo Bonzini $err = 1; 1661e2c54635SPaolo Bonzini foreach $px (0 .. $#prms) { 1662e2c54635SPaolo Bonzini $prm_clean = $prms[$px]; 1663e2c54635SPaolo Bonzini $prm_clean =~ s/\[.*\]//; 1664e2c54635SPaolo Bonzini $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 1665e2c54635SPaolo Bonzini # ignore array size in a parameter string; 1666e2c54635SPaolo Bonzini # however, the original param string may contain 1667e2c54635SPaolo Bonzini # spaces, e.g.: addr[6 + 2] 1668e2c54635SPaolo Bonzini # and this appears in @prms as "addr[6" since the 1669e2c54635SPaolo Bonzini # parameter list is split at spaces; 1670e2c54635SPaolo Bonzini # hence just ignore "[..." for the sections check; 1671e2c54635SPaolo Bonzini $prm_clean =~ s/\[.*//; 1672e2c54635SPaolo Bonzini 1673e2c54635SPaolo Bonzini ##$prm_clean =~ s/^\**//; 1674e2c54635SPaolo Bonzini if ($prm_clean eq $sects[$sx]) { 1675e2c54635SPaolo Bonzini $err = 0; 1676e2c54635SPaolo Bonzini last; 1677e2c54635SPaolo Bonzini } 1678e2c54635SPaolo Bonzini } 1679e2c54635SPaolo Bonzini if ($err) { 1680e2c54635SPaolo Bonzini if ($decl_type eq "function") { 1681e2c54635SPaolo Bonzini print STDERR "${file}:$.: warning: " . 1682e2c54635SPaolo Bonzini "Excess function parameter " . 1683e2c54635SPaolo Bonzini "'$sects[$sx]' " . 1684e2c54635SPaolo Bonzini "description in '$decl_name'\n"; 1685e2c54635SPaolo Bonzini ++$warnings; 1686e2c54635SPaolo Bonzini } 1687e2c54635SPaolo Bonzini } 1688e2c54635SPaolo Bonzini } 1689e2c54635SPaolo Bonzini} 1690e2c54635SPaolo Bonzini 1691e2c54635SPaolo Bonzini## 1692e2c54635SPaolo Bonzini# Checks the section describing the return value of a function. 1693e2c54635SPaolo Bonzinisub check_return_section { 1694e2c54635SPaolo Bonzini my $file = shift; 1695e2c54635SPaolo Bonzini my $declaration_name = shift; 1696e2c54635SPaolo Bonzini my $return_type = shift; 1697e2c54635SPaolo Bonzini 1698e2c54635SPaolo Bonzini # Ignore an empty return type (It's a macro) 1699e2c54635SPaolo Bonzini # Ignore functions with a "void" return type. (But don't ignore "void *") 1700e2c54635SPaolo Bonzini if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 1701e2c54635SPaolo Bonzini return; 1702e2c54635SPaolo Bonzini } 1703e2c54635SPaolo Bonzini 1704e2c54635SPaolo Bonzini if (!defined($sections{$section_return}) || 1705e2c54635SPaolo Bonzini $sections{$section_return} eq "") { 1706e2c54635SPaolo Bonzini print STDERR "${file}:$.: warning: " . 1707e2c54635SPaolo Bonzini "No description found for return value of " . 1708e2c54635SPaolo Bonzini "'$declaration_name'\n"; 1709e2c54635SPaolo Bonzini ++$warnings; 1710e2c54635SPaolo Bonzini } 1711e2c54635SPaolo Bonzini} 1712e2c54635SPaolo Bonzini 1713e2c54635SPaolo Bonzini## 1714e2c54635SPaolo Bonzini# takes a function prototype and the name of the current file being 1715e2c54635SPaolo Bonzini# processed and spits out all the details stored in the global 1716e2c54635SPaolo Bonzini# arrays/hashes. 1717e2c54635SPaolo Bonzinisub dump_function($$) { 1718e2c54635SPaolo Bonzini my $prototype = shift; 1719e2c54635SPaolo Bonzini my $file = shift; 1720e2c54635SPaolo Bonzini my $noret = 0; 1721e2c54635SPaolo Bonzini 17224f5f16a1SMauro Carvalho Chehab print_lineno($new_start_line); 1723697f668aSMauro Carvalho Chehab 1724e2c54635SPaolo Bonzini $prototype =~ s/^static +//; 1725e2c54635SPaolo Bonzini $prototype =~ s/^extern +//; 1726e2c54635SPaolo Bonzini $prototype =~ s/^asmlinkage +//; 1727e2c54635SPaolo Bonzini $prototype =~ s/^inline +//; 1728e2c54635SPaolo Bonzini $prototype =~ s/^__inline__ +//; 1729e2c54635SPaolo Bonzini $prototype =~ s/^__inline +//; 1730e2c54635SPaolo Bonzini $prototype =~ s/^__always_inline +//; 1731e2c54635SPaolo Bonzini $prototype =~ s/^noinline +//; 1732e2c54635SPaolo Bonzini $prototype =~ s/__init +//; 1733e2c54635SPaolo Bonzini $prototype =~ s/__init_or_module +//; 1734e2c54635SPaolo Bonzini $prototype =~ s/__meminit +//; 1735e2c54635SPaolo Bonzini $prototype =~ s/__must_check +//; 1736e2c54635SPaolo Bonzini $prototype =~ s/__weak +//; 1737e2c54635SPaolo Bonzini $prototype =~ s/__sched +//; 1738e2c54635SPaolo Bonzini $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//; 1739e2c54635SPaolo Bonzini my $define = $prototype =~ s/^#\s*define\s+//; #ak added 1740e2c54635SPaolo Bonzini $prototype =~ s/__attribute__\s*\(\( 1741e2c54635SPaolo Bonzini (?: 1742e2c54635SPaolo Bonzini [\w\s]++ # attribute name 1743e2c54635SPaolo Bonzini (?:\([^)]*+\))? # attribute arguments 1744e2c54635SPaolo Bonzini \s*+,? # optional comma at the end 1745e2c54635SPaolo Bonzini )+ 1746e2c54635SPaolo Bonzini \)\)\s+//x; 1747e2c54635SPaolo Bonzini 1748b30df275SAlex Bennée # Strip QEMU specific compiler annotations 1749b30df275SAlex Bennée $prototype =~ s/QEMU_[A-Z_]+ +//; 1750b30df275SAlex Bennée 1751e2c54635SPaolo Bonzini # Yes, this truly is vile. We are looking for: 1752e2c54635SPaolo Bonzini # 1. Return type (may be nothing if we're looking at a macro) 1753e2c54635SPaolo Bonzini # 2. Function name 1754e2c54635SPaolo Bonzini # 3. Function parameters. 1755e2c54635SPaolo Bonzini # 1756e2c54635SPaolo Bonzini # All the while we have to watch out for function pointer parameters 1757e2c54635SPaolo Bonzini # (which IIRC is what the two sections are for), C types (these 1758e2c54635SPaolo Bonzini # regexps don't even start to express all the possibilities), and 1759e2c54635SPaolo Bonzini # so on. 1760e2c54635SPaolo Bonzini # 1761e2c54635SPaolo Bonzini # If you mess with these regexps, it's a good idea to check that 1762e2c54635SPaolo Bonzini # the following functions' documentation still comes out right: 1763e2c54635SPaolo Bonzini # - parport_register_device (function pointer parameters) 1764953d0c33SPaolo Bonzini # - atomic_set (macro) 1765e2c54635SPaolo Bonzini # - pci_match_device, __copy_to_user (long return type) 1766e2c54635SPaolo Bonzini 1767e2c54635SPaolo Bonzini if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 1768e2c54635SPaolo Bonzini # This is an object-like macro, it has no return type and no parameter 1769e2c54635SPaolo Bonzini # list. 1770e2c54635SPaolo Bonzini # Function-like macros are not allowed to have spaces between 1771e2c54635SPaolo Bonzini # declaration_name and opening parenthesis (notice the \s+). 1772e2c54635SPaolo Bonzini $return_type = $1; 1773e2c54635SPaolo Bonzini $declaration_name = $2; 1774e2c54635SPaolo Bonzini $noret = 1; 1775e2c54635SPaolo Bonzini } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1776e2c54635SPaolo Bonzini $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1777e2c54635SPaolo Bonzini $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1778e2c54635SPaolo Bonzini $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1779e2c54635SPaolo Bonzini $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1780e2c54635SPaolo Bonzini $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1781e2c54635SPaolo Bonzini $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1782e2c54635SPaolo Bonzini $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1783e2c54635SPaolo Bonzini $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1784e2c54635SPaolo Bonzini $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1785e2c54635SPaolo Bonzini $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1786e2c54635SPaolo Bonzini $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1787e2c54635SPaolo Bonzini $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1788e2c54635SPaolo Bonzini $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1789e2c54635SPaolo Bonzini $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1790e2c54635SPaolo Bonzini $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || 1791e2c54635SPaolo Bonzini $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { 1792e2c54635SPaolo Bonzini $return_type = $1; 1793e2c54635SPaolo Bonzini $declaration_name = $2; 1794e2c54635SPaolo Bonzini my $args = $3; 1795e2c54635SPaolo Bonzini 1796e2c54635SPaolo Bonzini create_parameterlist($args, ',', $file, $declaration_name); 1797e2c54635SPaolo Bonzini } else { 1798e2c54635SPaolo Bonzini print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 1799e2c54635SPaolo Bonzini return; 1800e2c54635SPaolo Bonzini } 1801e2c54635SPaolo Bonzini 1802e2c54635SPaolo Bonzini my $prms = join " ", @parameterlist; 1803e2c54635SPaolo Bonzini check_sections($file, $declaration_name, "function", $sectcheck, $prms); 1804e2c54635SPaolo Bonzini 1805e2c54635SPaolo Bonzini # This check emits a lot of warnings at the moment, because many 1806e2c54635SPaolo Bonzini # functions don't have a 'Return' doc section. So until the number 1807e2c54635SPaolo Bonzini # of warnings goes sufficiently down, the check is only performed in 1808e2c54635SPaolo Bonzini # verbose mode. 1809e2c54635SPaolo Bonzini # TODO: always perform the check. 1810e2c54635SPaolo Bonzini if ($verbose && !$noret) { 1811e2c54635SPaolo Bonzini check_return_section($file, $declaration_name, $return_type); 1812e2c54635SPaolo Bonzini } 1813e2c54635SPaolo Bonzini 18143999ffcfSMauro Carvalho Chehab # The function parser can be called with a typedef parameter. 18153999ffcfSMauro Carvalho Chehab # Handle it. 18163999ffcfSMauro Carvalho Chehab if ($return_type =~ /typedef/) { 18173999ffcfSMauro Carvalho Chehab output_declaration($declaration_name, 18183999ffcfSMauro Carvalho Chehab 'function', 18193999ffcfSMauro Carvalho Chehab {'function' => $declaration_name, 18203999ffcfSMauro Carvalho Chehab 'typedef' => 1, 18213999ffcfSMauro Carvalho Chehab 'module' => $modulename, 18223999ffcfSMauro Carvalho Chehab 'functiontype' => $return_type, 18233999ffcfSMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 18243999ffcfSMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 18253999ffcfSMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 18263999ffcfSMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 18273999ffcfSMauro Carvalho Chehab 'sections' => \%sections, 18283999ffcfSMauro Carvalho Chehab 'purpose' => $declaration_purpose 18293999ffcfSMauro Carvalho Chehab }); 18303999ffcfSMauro Carvalho Chehab } else { 1831e2c54635SPaolo Bonzini output_declaration($declaration_name, 1832e2c54635SPaolo Bonzini 'function', 1833e2c54635SPaolo Bonzini {'function' => $declaration_name, 1834e2c54635SPaolo Bonzini 'module' => $modulename, 1835e2c54635SPaolo Bonzini 'functiontype' => $return_type, 1836e2c54635SPaolo Bonzini 'parameterlist' => \@parameterlist, 1837e2c54635SPaolo Bonzini 'parameterdescs' => \%parameterdescs, 1838e2c54635SPaolo Bonzini 'parametertypes' => \%parametertypes, 1839e2c54635SPaolo Bonzini 'sectionlist' => \@sectionlist, 1840e2c54635SPaolo Bonzini 'sections' => \%sections, 1841e2c54635SPaolo Bonzini 'purpose' => $declaration_purpose 1842e2c54635SPaolo Bonzini }); 1843e2c54635SPaolo Bonzini } 18443999ffcfSMauro Carvalho Chehab} 1845e2c54635SPaolo Bonzini 1846e2c54635SPaolo Bonzinisub reset_state { 1847e2c54635SPaolo Bonzini $function = ""; 1848e2c54635SPaolo Bonzini %parameterdescs = (); 1849e2c54635SPaolo Bonzini %parametertypes = (); 1850e2c54635SPaolo Bonzini @parameterlist = (); 1851e2c54635SPaolo Bonzini %sections = (); 1852e2c54635SPaolo Bonzini @sectionlist = (); 1853e2c54635SPaolo Bonzini $sectcheck = ""; 1854e2c54635SPaolo Bonzini $struct_actual = ""; 1855e2c54635SPaolo Bonzini $prototype = ""; 1856e2c54635SPaolo Bonzini 1857e2c54635SPaolo Bonzini $state = STATE_NORMAL; 1858e2c54635SPaolo Bonzini $inline_doc_state = STATE_INLINE_NA; 1859e2c54635SPaolo Bonzini} 1860e2c54635SPaolo Bonzini 1861e2c54635SPaolo Bonzinisub tracepoint_munge($) { 1862e2c54635SPaolo Bonzini my $file = shift; 1863e2c54635SPaolo Bonzini my $tracepointname = 0; 1864e2c54635SPaolo Bonzini my $tracepointargs = 0; 1865e2c54635SPaolo Bonzini 1866e2c54635SPaolo Bonzini if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 1867e2c54635SPaolo Bonzini $tracepointname = $1; 1868e2c54635SPaolo Bonzini } 1869e2c54635SPaolo Bonzini if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 1870e2c54635SPaolo Bonzini $tracepointname = $1; 1871e2c54635SPaolo Bonzini } 1872e2c54635SPaolo Bonzini if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 1873e2c54635SPaolo Bonzini $tracepointname = $2; 1874e2c54635SPaolo Bonzini } 1875e2c54635SPaolo Bonzini $tracepointname =~ s/^\s+//; #strip leading whitespace 1876e2c54635SPaolo Bonzini if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 1877e2c54635SPaolo Bonzini $tracepointargs = $1; 1878e2c54635SPaolo Bonzini } 1879e2c54635SPaolo Bonzini if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 1880e2c54635SPaolo Bonzini print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 1881e2c54635SPaolo Bonzini "$prototype\n"; 1882e2c54635SPaolo Bonzini } else { 1883e2c54635SPaolo Bonzini $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 1884e2c54635SPaolo Bonzini } 1885e2c54635SPaolo Bonzini} 1886e2c54635SPaolo Bonzini 1887e2c54635SPaolo Bonzinisub syscall_munge() { 1888e2c54635SPaolo Bonzini my $void = 0; 1889e2c54635SPaolo Bonzini 1890e2c54635SPaolo Bonzini $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's 1891e2c54635SPaolo Bonzini## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 1892e2c54635SPaolo Bonzini if ($prototype =~ m/SYSCALL_DEFINE0/) { 1893e2c54635SPaolo Bonzini $void = 1; 1894e2c54635SPaolo Bonzini## $prototype = "long sys_$1(void)"; 1895e2c54635SPaolo Bonzini } 1896e2c54635SPaolo Bonzini 1897e2c54635SPaolo Bonzini $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 1898e2c54635SPaolo Bonzini if ($prototype =~ m/long (sys_.*?),/) { 1899e2c54635SPaolo Bonzini $prototype =~ s/,/\(/; 1900e2c54635SPaolo Bonzini } elsif ($void) { 1901e2c54635SPaolo Bonzini $prototype =~ s/\)/\(void\)/; 1902e2c54635SPaolo Bonzini } 1903e2c54635SPaolo Bonzini 1904e2c54635SPaolo Bonzini # now delete all of the odd-number commas in $prototype 1905e2c54635SPaolo Bonzini # so that arg types & arg names don't have a comma between them 1906e2c54635SPaolo Bonzini my $count = 0; 1907e2c54635SPaolo Bonzini my $len = length($prototype); 1908e2c54635SPaolo Bonzini if ($void) { 1909e2c54635SPaolo Bonzini $len = 0; # skip the for-loop 1910e2c54635SPaolo Bonzini } 1911e2c54635SPaolo Bonzini for (my $ix = 0; $ix < $len; $ix++) { 1912e2c54635SPaolo Bonzini if (substr($prototype, $ix, 1) eq ',') { 1913e2c54635SPaolo Bonzini $count++; 1914e2c54635SPaolo Bonzini if ($count % 2 == 1) { 1915e2c54635SPaolo Bonzini substr($prototype, $ix, 1) = ' '; 1916e2c54635SPaolo Bonzini } 1917e2c54635SPaolo Bonzini } 1918e2c54635SPaolo Bonzini } 1919e2c54635SPaolo Bonzini} 1920e2c54635SPaolo Bonzini 1921e2c54635SPaolo Bonzinisub process_proto_function($$) { 1922e2c54635SPaolo Bonzini my $x = shift; 1923e2c54635SPaolo Bonzini my $file = shift; 1924e2c54635SPaolo Bonzini 1925e2c54635SPaolo Bonzini $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 1926e2c54635SPaolo Bonzini 1927e2c54635SPaolo Bonzini if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 1928e2c54635SPaolo Bonzini # do nothing 1929e2c54635SPaolo Bonzini } 1930e2c54635SPaolo Bonzini elsif ($x =~ /([^\{]*)/) { 1931e2c54635SPaolo Bonzini $prototype .= $1; 1932e2c54635SPaolo Bonzini } 1933e2c54635SPaolo Bonzini 1934e2c54635SPaolo Bonzini if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 1935e2c54635SPaolo Bonzini $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 1936e2c54635SPaolo Bonzini $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 1937e2c54635SPaolo Bonzini $prototype =~ s@^\s+@@gos; # strip leading spaces 19382552f59aSMauro Carvalho Chehab 19392552f59aSMauro Carvalho Chehab # Handle prototypes for function pointers like: 19402552f59aSMauro Carvalho Chehab # int (*pcs_config)(struct foo) 19412552f59aSMauro Carvalho Chehab $prototype =~ s@^(\S+\s+)\(\s*\*(\S+)\)@$1$2@gos; 19422552f59aSMauro Carvalho Chehab 1943e2c54635SPaolo Bonzini if ($prototype =~ /SYSCALL_DEFINE/) { 1944e2c54635SPaolo Bonzini syscall_munge(); 1945e2c54635SPaolo Bonzini } 1946e2c54635SPaolo Bonzini if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 1947e2c54635SPaolo Bonzini $prototype =~ /DEFINE_SINGLE_EVENT/) 1948e2c54635SPaolo Bonzini { 1949e2c54635SPaolo Bonzini tracepoint_munge($file); 1950e2c54635SPaolo Bonzini } 1951e2c54635SPaolo Bonzini dump_function($prototype, $file); 1952e2c54635SPaolo Bonzini reset_state(); 1953e2c54635SPaolo Bonzini } 1954e2c54635SPaolo Bonzini} 1955e2c54635SPaolo Bonzini 1956e2c54635SPaolo Bonzinisub process_proto_type($$) { 1957e2c54635SPaolo Bonzini my $x = shift; 1958e2c54635SPaolo Bonzini my $file = shift; 1959e2c54635SPaolo Bonzini 1960e2c54635SPaolo Bonzini $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 1961e2c54635SPaolo Bonzini $x =~ s@^\s+@@gos; # strip leading spaces 1962e2c54635SPaolo Bonzini $x =~ s@\s+$@@gos; # strip trailing spaces 1963e2c54635SPaolo Bonzini $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 1964e2c54635SPaolo Bonzini 1965e2c54635SPaolo Bonzini if ($x =~ /^#/) { 1966e2c54635SPaolo Bonzini # To distinguish preprocessor directive from regular declaration later. 1967e2c54635SPaolo Bonzini $x .= ";"; 1968e2c54635SPaolo Bonzini } 1969e2c54635SPaolo Bonzini 1970e2c54635SPaolo Bonzini while (1) { 1971e2c54635SPaolo Bonzini if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) { 1972e2c54635SPaolo Bonzini if( length $prototype ) { 1973e2c54635SPaolo Bonzini $prototype .= " " 1974e2c54635SPaolo Bonzini } 1975e2c54635SPaolo Bonzini $prototype .= $1 . $2; 1976e2c54635SPaolo Bonzini ($2 eq '{') && $brcount++; 1977e2c54635SPaolo Bonzini ($2 eq '}') && $brcount--; 1978e2c54635SPaolo Bonzini if (($2 eq ';') && ($brcount == 0)) { 1979e2c54635SPaolo Bonzini dump_declaration($prototype, $file); 1980e2c54635SPaolo Bonzini reset_state(); 1981e2c54635SPaolo Bonzini last; 1982e2c54635SPaolo Bonzini } 1983e2c54635SPaolo Bonzini $x = $3; 1984e2c54635SPaolo Bonzini } else { 1985e2c54635SPaolo Bonzini $prototype .= $x; 1986e2c54635SPaolo Bonzini last; 1987e2c54635SPaolo Bonzini } 1988e2c54635SPaolo Bonzini } 1989e2c54635SPaolo Bonzini} 1990e2c54635SPaolo Bonzini 1991e2c54635SPaolo Bonzini 1992e2c54635SPaolo Bonzinisub map_filename($) { 1993e2c54635SPaolo Bonzini my $file; 1994e2c54635SPaolo Bonzini my ($orig_file) = @_; 1995e2c54635SPaolo Bonzini 1996e2c54635SPaolo Bonzini if (defined($ENV{'SRCTREE'})) { 1997e2c54635SPaolo Bonzini $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 1998e2c54635SPaolo Bonzini } else { 1999e2c54635SPaolo Bonzini $file = $orig_file; 2000e2c54635SPaolo Bonzini } 2001e2c54635SPaolo Bonzini 2002e2c54635SPaolo Bonzini if (defined($source_map{$file})) { 2003e2c54635SPaolo Bonzini $file = $source_map{$file}; 2004e2c54635SPaolo Bonzini } 2005e2c54635SPaolo Bonzini 2006e2c54635SPaolo Bonzini return $file; 2007e2c54635SPaolo Bonzini} 2008e2c54635SPaolo Bonzini 2009e2c54635SPaolo Bonzinisub process_export_file($) { 2010e2c54635SPaolo Bonzini my ($orig_file) = @_; 2011e2c54635SPaolo Bonzini my $file = map_filename($orig_file); 2012e2c54635SPaolo Bonzini 2013e2c54635SPaolo Bonzini if (!open(IN,"<$file")) { 2014e2c54635SPaolo Bonzini print STDERR "Error: Cannot open file $file\n"; 2015e2c54635SPaolo Bonzini ++$errors; 2016e2c54635SPaolo Bonzini return; 2017e2c54635SPaolo Bonzini } 2018e2c54635SPaolo Bonzini 2019e2c54635SPaolo Bonzini while (<IN>) { 2020e2c54635SPaolo Bonzini if (/$export_symbol/) { 202178c8c92cSMauro Carvalho Chehab next if (defined($nosymbol_table{$2})); 2022e2c54635SPaolo Bonzini $function_table{$2} = 1; 2023e2c54635SPaolo Bonzini } 2024e2c54635SPaolo Bonzini } 2025e2c54635SPaolo Bonzini 2026e2c54635SPaolo Bonzini close(IN); 2027e2c54635SPaolo Bonzini} 2028e2c54635SPaolo Bonzini 2029e2c54635SPaolo Bonzini# 2030e2c54635SPaolo Bonzini# Parsers for the various processing states. 2031e2c54635SPaolo Bonzini# 2032e2c54635SPaolo Bonzini# STATE_NORMAL: looking for the /** to begin everything. 2033e2c54635SPaolo Bonzini# 2034e2c54635SPaolo Bonzinisub process_normal() { 2035e2c54635SPaolo Bonzini if (/$doc_start/o) { 2036e2c54635SPaolo Bonzini $state = STATE_NAME; # next line is always the function name 2037e2c54635SPaolo Bonzini $in_doc_sect = 0; 2038e2c54635SPaolo Bonzini $declaration_start_line = $. + 1; 2039e2c54635SPaolo Bonzini } 2040e2c54635SPaolo Bonzini} 2041e2c54635SPaolo Bonzini 2042e2c54635SPaolo Bonzini# 2043e2c54635SPaolo Bonzini# STATE_NAME: Looking for the "name - description" line 2044e2c54635SPaolo Bonzini# 2045e2c54635SPaolo Bonzinisub process_name($$) { 2046e2c54635SPaolo Bonzini my $file = shift; 2047e2c54635SPaolo Bonzini my $identifier; 2048e2c54635SPaolo Bonzini my $descr; 2049e2c54635SPaolo Bonzini 2050e2c54635SPaolo Bonzini if (/$doc_block/o) { 2051e2c54635SPaolo Bonzini $state = STATE_DOCBLOCK; 2052e2c54635SPaolo Bonzini $contents = ""; 20534f5f16a1SMauro Carvalho Chehab $new_start_line = $.; 2054e2c54635SPaolo Bonzini 2055e2c54635SPaolo Bonzini if ( $1 eq "" ) { 2056e2c54635SPaolo Bonzini $section = $section_intro; 2057e2c54635SPaolo Bonzini } else { 2058e2c54635SPaolo Bonzini $section = $1; 2059e2c54635SPaolo Bonzini } 2060e2c54635SPaolo Bonzini } 2061e2c54635SPaolo Bonzini elsif (/$doc_decl/o) { 2062e2c54635SPaolo Bonzini $identifier = $1; 20634cf41794SPaolo Bonzini if (/\s*([\w\s]+?)(\s*-|:)/) { 2064e2c54635SPaolo Bonzini $identifier = $1; 2065e2c54635SPaolo Bonzini } 2066e2c54635SPaolo Bonzini 2067e2c54635SPaolo Bonzini $state = STATE_BODY; 2068e2c54635SPaolo Bonzini # if there's no @param blocks need to set up default section 2069e2c54635SPaolo Bonzini # here 2070e2c54635SPaolo Bonzini $contents = ""; 2071e2c54635SPaolo Bonzini $section = $section_default; 2072e2c54635SPaolo Bonzini $new_start_line = $. + 1; 20734cf41794SPaolo Bonzini if (/[-:](.*)/) { 2074e2c54635SPaolo Bonzini # strip leading/trailing/multiple spaces 2075e2c54635SPaolo Bonzini $descr= $1; 2076e2c54635SPaolo Bonzini $descr =~ s/^\s*//; 2077e2c54635SPaolo Bonzini $descr =~ s/\s*$//; 2078e2c54635SPaolo Bonzini $descr =~ s/\s+/ /g; 2079e2c54635SPaolo Bonzini $declaration_purpose = $descr; 2080e2c54635SPaolo Bonzini $state = STATE_BODY_MAYBE; 2081e2c54635SPaolo Bonzini } else { 2082e2c54635SPaolo Bonzini $declaration_purpose = ""; 2083e2c54635SPaolo Bonzini } 2084e2c54635SPaolo Bonzini 2085e2c54635SPaolo Bonzini if (($declaration_purpose eq "") && $verbose) { 2086e2c54635SPaolo Bonzini print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 2087e2c54635SPaolo Bonzini print STDERR $_; 2088e2c54635SPaolo Bonzini ++$warnings; 2089e2c54635SPaolo Bonzini } 2090e2c54635SPaolo Bonzini 2091eb4c9775SEduardo Habkost if ($identifier =~ m/^struct\b/) { 2092e2c54635SPaolo Bonzini $decl_type = 'struct'; 2093e2c54635SPaolo Bonzini } elsif ($identifier =~ m/^union\b/) { 2094e2c54635SPaolo Bonzini $decl_type = 'union'; 2095e2c54635SPaolo Bonzini } elsif ($identifier =~ m/^enum\b/) { 2096e2c54635SPaolo Bonzini $decl_type = 'enum'; 2097e2c54635SPaolo Bonzini } elsif ($identifier =~ m/^typedef\b/) { 2098e2c54635SPaolo Bonzini $decl_type = 'typedef'; 2099e2c54635SPaolo Bonzini } else { 2100e2c54635SPaolo Bonzini $decl_type = 'function'; 2101e2c54635SPaolo Bonzini } 2102e2c54635SPaolo Bonzini 2103e2c54635SPaolo Bonzini if ($verbose) { 2104e2c54635SPaolo Bonzini print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; 2105e2c54635SPaolo Bonzini } 2106e2c54635SPaolo Bonzini } else { 2107e2c54635SPaolo Bonzini print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 2108e2c54635SPaolo Bonzini " - I thought it was a doc line\n"; 2109e2c54635SPaolo Bonzini ++$warnings; 2110e2c54635SPaolo Bonzini $state = STATE_NORMAL; 2111e2c54635SPaolo Bonzini } 2112e2c54635SPaolo Bonzini} 2113e2c54635SPaolo Bonzini 2114e2c54635SPaolo Bonzini 2115e2c54635SPaolo Bonzini# 2116e2c54635SPaolo Bonzini# STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment. 2117e2c54635SPaolo Bonzini# 2118e2c54635SPaolo Bonzinisub process_body($$) { 2119e2c54635SPaolo Bonzini my $file = shift; 2120e2c54635SPaolo Bonzini 212165fb67bfSJonathan Neuschäfer # Until all named variable macro parameters are 212265fb67bfSJonathan Neuschäfer # documented using the bare name (`x`) rather than with 212365fb67bfSJonathan Neuschäfer # dots (`x...`), strip the dots: 212465fb67bfSJonathan Neuschäfer if ($section =~ /\w\.\.\.$/) { 212565fb67bfSJonathan Neuschäfer $section =~ s/\.\.\.$//; 212665fb67bfSJonathan Neuschäfer 212765fb67bfSJonathan Neuschäfer if ($verbose) { 212865fb67bfSJonathan Neuschäfer print STDERR "${file}:$.: warning: Variable macro arguments should be documented without dots\n"; 212965fb67bfSJonathan Neuschäfer ++$warnings; 213065fb67bfSJonathan Neuschäfer } 213165fb67bfSJonathan Neuschäfer } 213265fb67bfSJonathan Neuschäfer 21339f2b463aSMauro Carvalho Chehab if ($state == STATE_BODY_WITH_BLANK_LINE && /^\s*\*\s?\S/) { 21349f2b463aSMauro Carvalho Chehab dump_section($file, $section, $contents); 21359f2b463aSMauro Carvalho Chehab $section = $section_default; 21364f5f16a1SMauro Carvalho Chehab $new_start_line = $.; 21379f2b463aSMauro Carvalho Chehab $contents = ""; 21389f2b463aSMauro Carvalho Chehab } 21399f2b463aSMauro Carvalho Chehab 2140e2c54635SPaolo Bonzini if (/$doc_sect/i) { # case insensitive for supported section names 2141e2c54635SPaolo Bonzini $newsection = $1; 2142e2c54635SPaolo Bonzini $newcontents = $2; 2143e2c54635SPaolo Bonzini 2144e2c54635SPaolo Bonzini # map the supported section names to the canonical names 2145e2c54635SPaolo Bonzini if ($newsection =~ m/^description$/i) { 2146e2c54635SPaolo Bonzini $newsection = $section_default; 2147e2c54635SPaolo Bonzini } elsif ($newsection =~ m/^context$/i) { 2148e2c54635SPaolo Bonzini $newsection = $section_context; 2149e2c54635SPaolo Bonzini } elsif ($newsection =~ m/^returns?$/i) { 2150e2c54635SPaolo Bonzini $newsection = $section_return; 2151e2c54635SPaolo Bonzini } elsif ($newsection =~ m/^\@return$/) { 2152e2c54635SPaolo Bonzini # special: @return is a section, not a param description 2153e2c54635SPaolo Bonzini $newsection = $section_return; 2154e2c54635SPaolo Bonzini } 2155e2c54635SPaolo Bonzini 2156e2c54635SPaolo Bonzini if (($contents ne "") && ($contents ne "\n")) { 2157e2c54635SPaolo Bonzini if (!$in_doc_sect && $verbose) { 2158e2c54635SPaolo Bonzini print STDERR "${file}:$.: warning: contents before sections\n"; 2159e2c54635SPaolo Bonzini ++$warnings; 2160e2c54635SPaolo Bonzini } 2161e2c54635SPaolo Bonzini dump_section($file, $section, $contents); 2162e2c54635SPaolo Bonzini $section = $section_default; 2163e2c54635SPaolo Bonzini } 2164e2c54635SPaolo Bonzini 2165e2c54635SPaolo Bonzini $in_doc_sect = 1; 2166e2c54635SPaolo Bonzini $state = STATE_BODY; 2167e2c54635SPaolo Bonzini $contents = $newcontents; 2168e2c54635SPaolo Bonzini $new_start_line = $.; 2169e2c54635SPaolo Bonzini while (substr($contents, 0, 1) eq " ") { 2170e2c54635SPaolo Bonzini $contents = substr($contents, 1); 2171e2c54635SPaolo Bonzini } 2172e2c54635SPaolo Bonzini if ($contents ne "") { 2173e2c54635SPaolo Bonzini $contents .= "\n"; 2174e2c54635SPaolo Bonzini } 2175e2c54635SPaolo Bonzini $section = $newsection; 2176e2c54635SPaolo Bonzini $leading_space = undef; 2177e2c54635SPaolo Bonzini } elsif (/$doc_end/) { 2178e2c54635SPaolo Bonzini if (($contents ne "") && ($contents ne "\n")) { 2179e2c54635SPaolo Bonzini dump_section($file, $section, $contents); 2180e2c54635SPaolo Bonzini $section = $section_default; 2181e2c54635SPaolo Bonzini $contents = ""; 2182e2c54635SPaolo Bonzini } 2183e2c54635SPaolo Bonzini # look for doc_com + <text> + doc_end: 2184e2c54635SPaolo Bonzini if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2185e2c54635SPaolo Bonzini print STDERR "${file}:$.: warning: suspicious ending line: $_"; 2186e2c54635SPaolo Bonzini ++$warnings; 2187e2c54635SPaolo Bonzini } 2188e2c54635SPaolo Bonzini 2189e2c54635SPaolo Bonzini $prototype = ""; 2190e2c54635SPaolo Bonzini $state = STATE_PROTO; 2191e2c54635SPaolo Bonzini $brcount = 0; 21924f5f16a1SMauro Carvalho Chehab $new_start_line = $. + 1; 2193e2c54635SPaolo Bonzini } elsif (/$doc_content/) { 2194e2c54635SPaolo Bonzini if ($1 eq "") { 21959f2b463aSMauro Carvalho Chehab if ($section eq $section_context) { 2196e2c54635SPaolo Bonzini dump_section($file, $section, $contents); 2197e2c54635SPaolo Bonzini $section = $section_default; 2198e2c54635SPaolo Bonzini $contents = ""; 2199e2c54635SPaolo Bonzini $new_start_line = $.; 22009f2b463aSMauro Carvalho Chehab $state = STATE_BODY; 2201e2c54635SPaolo Bonzini } else { 22029f2b463aSMauro Carvalho Chehab if ($section ne $section_default) { 22039f2b463aSMauro Carvalho Chehab $state = STATE_BODY_WITH_BLANK_LINE; 22049f2b463aSMauro Carvalho Chehab } else { 22059f2b463aSMauro Carvalho Chehab $state = STATE_BODY; 22069f2b463aSMauro Carvalho Chehab } 2207e2c54635SPaolo Bonzini $contents .= "\n"; 2208e2c54635SPaolo Bonzini } 2209e2c54635SPaolo Bonzini } elsif ($state == STATE_BODY_MAYBE) { 2210e2c54635SPaolo Bonzini # Continued declaration purpose 2211e2c54635SPaolo Bonzini chomp($declaration_purpose); 2212e2c54635SPaolo Bonzini $declaration_purpose .= " " . $1; 2213e2c54635SPaolo Bonzini $declaration_purpose =~ s/\s+/ /g; 2214e2c54635SPaolo Bonzini } else { 2215e2c54635SPaolo Bonzini my $cont = $1; 2216e2c54635SPaolo Bonzini if ($section =~ m/^@/ || $section eq $section_context) { 2217e2c54635SPaolo Bonzini if (!defined $leading_space) { 2218e2c54635SPaolo Bonzini if ($cont =~ m/^(\s+)/) { 2219e2c54635SPaolo Bonzini $leading_space = $1; 2220e2c54635SPaolo Bonzini } else { 2221e2c54635SPaolo Bonzini $leading_space = ""; 2222e2c54635SPaolo Bonzini } 2223e2c54635SPaolo Bonzini } 2224e2c54635SPaolo Bonzini $cont =~ s/^$leading_space//; 2225e2c54635SPaolo Bonzini } 2226e2c54635SPaolo Bonzini $contents .= $cont . "\n"; 2227e2c54635SPaolo Bonzini } 2228e2c54635SPaolo Bonzini } else { 2229e2c54635SPaolo Bonzini # i dont know - bad line? ignore. 2230e2c54635SPaolo Bonzini print STDERR "${file}:$.: warning: bad line: $_"; 2231e2c54635SPaolo Bonzini ++$warnings; 2232e2c54635SPaolo Bonzini } 2233e2c54635SPaolo Bonzini} 2234e2c54635SPaolo Bonzini 2235e2c54635SPaolo Bonzini 2236e2c54635SPaolo Bonzini# 2237e2c54635SPaolo Bonzini# STATE_PROTO: reading a function/whatever prototype. 2238e2c54635SPaolo Bonzini# 2239e2c54635SPaolo Bonzinisub process_proto($$) { 2240e2c54635SPaolo Bonzini my $file = shift; 2241e2c54635SPaolo Bonzini 2242e2c54635SPaolo Bonzini if (/$doc_inline_oneline/) { 2243e2c54635SPaolo Bonzini $section = $1; 2244e2c54635SPaolo Bonzini $contents = $2; 2245e2c54635SPaolo Bonzini if ($contents ne "") { 2246e2c54635SPaolo Bonzini $contents .= "\n"; 2247e2c54635SPaolo Bonzini dump_section($file, $section, $contents); 2248e2c54635SPaolo Bonzini $section = $section_default; 2249e2c54635SPaolo Bonzini $contents = ""; 2250e2c54635SPaolo Bonzini } 2251e2c54635SPaolo Bonzini } elsif (/$doc_inline_start/) { 2252e2c54635SPaolo Bonzini $state = STATE_INLINE; 2253e2c54635SPaolo Bonzini $inline_doc_state = STATE_INLINE_NAME; 2254e2c54635SPaolo Bonzini } elsif ($decl_type eq 'function') { 2255e2c54635SPaolo Bonzini process_proto_function($_, $file); 2256e2c54635SPaolo Bonzini } else { 2257e2c54635SPaolo Bonzini process_proto_type($_, $file); 2258e2c54635SPaolo Bonzini } 2259e2c54635SPaolo Bonzini} 2260e2c54635SPaolo Bonzini 2261e2c54635SPaolo Bonzini# 2262e2c54635SPaolo Bonzini# STATE_DOCBLOCK: within a DOC: block. 2263e2c54635SPaolo Bonzini# 2264e2c54635SPaolo Bonzinisub process_docblock($$) { 2265e2c54635SPaolo Bonzini my $file = shift; 2266e2c54635SPaolo Bonzini 2267e2c54635SPaolo Bonzini if (/$doc_end/) { 2268e2c54635SPaolo Bonzini dump_doc_section($file, $section, $contents); 2269e2c54635SPaolo Bonzini $section = $section_default; 2270e2c54635SPaolo Bonzini $contents = ""; 2271e2c54635SPaolo Bonzini $function = ""; 2272e2c54635SPaolo Bonzini %parameterdescs = (); 2273e2c54635SPaolo Bonzini %parametertypes = (); 2274e2c54635SPaolo Bonzini @parameterlist = (); 2275e2c54635SPaolo Bonzini %sections = (); 2276e2c54635SPaolo Bonzini @sectionlist = (); 2277e2c54635SPaolo Bonzini $prototype = ""; 2278e2c54635SPaolo Bonzini $state = STATE_NORMAL; 2279e2c54635SPaolo Bonzini } elsif (/$doc_content/) { 2280e2c54635SPaolo Bonzini if ( $1 eq "" ) { 2281e2c54635SPaolo Bonzini $contents .= $blankline; 2282e2c54635SPaolo Bonzini } else { 2283e2c54635SPaolo Bonzini $contents .= $1 . "\n"; 2284e2c54635SPaolo Bonzini } 2285e2c54635SPaolo Bonzini } 2286e2c54635SPaolo Bonzini} 2287e2c54635SPaolo Bonzini 2288e2c54635SPaolo Bonzini# 2289e2c54635SPaolo Bonzini# STATE_INLINE: docbook comments within a prototype. 2290e2c54635SPaolo Bonzini# 2291e2c54635SPaolo Bonzinisub process_inline($$) { 2292e2c54635SPaolo Bonzini my $file = shift; 2293e2c54635SPaolo Bonzini 2294e2c54635SPaolo Bonzini # First line (state 1) needs to be a @parameter 2295e2c54635SPaolo Bonzini if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 2296e2c54635SPaolo Bonzini $section = $1; 2297e2c54635SPaolo Bonzini $contents = $2; 2298e2c54635SPaolo Bonzini $new_start_line = $.; 2299e2c54635SPaolo Bonzini if ($contents ne "") { 2300e2c54635SPaolo Bonzini while (substr($contents, 0, 1) eq " ") { 2301e2c54635SPaolo Bonzini $contents = substr($contents, 1); 2302e2c54635SPaolo Bonzini } 2303e2c54635SPaolo Bonzini $contents .= "\n"; 2304e2c54635SPaolo Bonzini } 2305e2c54635SPaolo Bonzini $inline_doc_state = STATE_INLINE_TEXT; 2306e2c54635SPaolo Bonzini # Documentation block end */ 2307e2c54635SPaolo Bonzini } elsif (/$doc_inline_end/) { 2308e2c54635SPaolo Bonzini if (($contents ne "") && ($contents ne "\n")) { 2309e2c54635SPaolo Bonzini dump_section($file, $section, $contents); 2310e2c54635SPaolo Bonzini $section = $section_default; 2311e2c54635SPaolo Bonzini $contents = ""; 2312e2c54635SPaolo Bonzini } 2313e2c54635SPaolo Bonzini $state = STATE_PROTO; 2314e2c54635SPaolo Bonzini $inline_doc_state = STATE_INLINE_NA; 2315e2c54635SPaolo Bonzini # Regular text 2316e2c54635SPaolo Bonzini } elsif (/$doc_content/) { 2317e2c54635SPaolo Bonzini if ($inline_doc_state == STATE_INLINE_TEXT) { 2318e2c54635SPaolo Bonzini $contents .= $1 . "\n"; 2319e2c54635SPaolo Bonzini # nuke leading blank lines 2320e2c54635SPaolo Bonzini if ($contents =~ /^\s*$/) { 2321e2c54635SPaolo Bonzini $contents = ""; 2322e2c54635SPaolo Bonzini } 2323e2c54635SPaolo Bonzini } elsif ($inline_doc_state == STATE_INLINE_NAME) { 2324e2c54635SPaolo Bonzini $inline_doc_state = STATE_INLINE_ERROR; 2325e2c54635SPaolo Bonzini print STDERR "${file}:$.: warning: "; 2326e2c54635SPaolo Bonzini print STDERR "Incorrect use of kernel-doc format: $_"; 2327e2c54635SPaolo Bonzini ++$warnings; 2328e2c54635SPaolo Bonzini } 2329e2c54635SPaolo Bonzini } 2330e2c54635SPaolo Bonzini} 2331e2c54635SPaolo Bonzini 2332e2c54635SPaolo Bonzini 2333e2c54635SPaolo Bonzinisub process_file($) { 2334e2c54635SPaolo Bonzini my $file; 2335e2c54635SPaolo Bonzini my $initial_section_counter = $section_counter; 2336e2c54635SPaolo Bonzini my ($orig_file) = @_; 2337e2c54635SPaolo Bonzini 2338e2c54635SPaolo Bonzini $file = map_filename($orig_file); 2339e2c54635SPaolo Bonzini 23405abfaa6aSMauro Carvalho Chehab if (!open(IN_FILE,"<$file")) { 2341e2c54635SPaolo Bonzini print STDERR "Error: Cannot open file $file\n"; 2342e2c54635SPaolo Bonzini ++$errors; 2343e2c54635SPaolo Bonzini return; 2344e2c54635SPaolo Bonzini } 2345e2c54635SPaolo Bonzini 2346e2c54635SPaolo Bonzini $. = 1; 2347e2c54635SPaolo Bonzini 2348e2c54635SPaolo Bonzini $section_counter = 0; 23495abfaa6aSMauro Carvalho Chehab while (<IN_FILE>) { 2350e2c54635SPaolo Bonzini while (s/\\\s*$//) { 23515abfaa6aSMauro Carvalho Chehab $_ .= <IN_FILE>; 2352e2c54635SPaolo Bonzini } 2353e2c54635SPaolo Bonzini # Replace tabs by spaces 2354e2c54635SPaolo Bonzini while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; 2355e2c54635SPaolo Bonzini # Hand this line to the appropriate state handler 2356e2c54635SPaolo Bonzini if ($state == STATE_NORMAL) { 2357e2c54635SPaolo Bonzini process_normal(); 2358e2c54635SPaolo Bonzini } elsif ($state == STATE_NAME) { 2359e2c54635SPaolo Bonzini process_name($file, $_); 23609f2b463aSMauro Carvalho Chehab } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE || 23619f2b463aSMauro Carvalho Chehab $state == STATE_BODY_WITH_BLANK_LINE) { 2362e2c54635SPaolo Bonzini process_body($file, $_); 2363e2c54635SPaolo Bonzini } elsif ($state == STATE_INLINE) { # scanning for inline parameters 2364e2c54635SPaolo Bonzini process_inline($file, $_); 2365e2c54635SPaolo Bonzini } elsif ($state == STATE_PROTO) { 2366e2c54635SPaolo Bonzini process_proto($file, $_); 2367e2c54635SPaolo Bonzini } elsif ($state == STATE_DOCBLOCK) { 2368e2c54635SPaolo Bonzini process_docblock($file, $_); 2369e2c54635SPaolo Bonzini } 2370e2c54635SPaolo Bonzini } 2371e2c54635SPaolo Bonzini 2372e2c54635SPaolo Bonzini # Make sure we got something interesting. 2373e2c54635SPaolo Bonzini if ($initial_section_counter == $section_counter && $ 2374e2c54635SPaolo Bonzini output_mode ne "none") { 2375e2c54635SPaolo Bonzini if ($output_selection == OUTPUT_INCLUDE) { 2376e2c54635SPaolo Bonzini print STDERR "${file}:1: warning: '$_' not found\n" 2377e2c54635SPaolo Bonzini for keys %function_table; 2378e2c54635SPaolo Bonzini } 2379e2c54635SPaolo Bonzini else { 2380e2c54635SPaolo Bonzini print STDERR "${file}:1: warning: no structured comments found\n"; 2381e2c54635SPaolo Bonzini } 2382e2c54635SPaolo Bonzini } 23835abfaa6aSMauro Carvalho Chehab close IN_FILE; 2384e2c54635SPaolo Bonzini} 2385e2c54635SPaolo Bonzini 2386e2c54635SPaolo Bonzini 2387486966e4SMauro Carvalho Chehabif ($output_mode eq "rst") { 2388486966e4SMauro Carvalho Chehab get_sphinx_version() if (!$sphinx_major); 2389486966e4SMauro Carvalho Chehab} 2390486966e4SMauro Carvalho Chehab 2391e2c54635SPaolo Bonzini$kernelversion = get_kernel_version(); 2392e2c54635SPaolo Bonzini 2393e2c54635SPaolo Bonzini# generate a sequence of code that will splice in highlighting information 2394e2c54635SPaolo Bonzini# using the s// operator. 2395e2c54635SPaolo Bonzinifor (my $k = 0; $k < @highlights; $k++) { 2396e2c54635SPaolo Bonzini my $pattern = $highlights[$k][0]; 2397e2c54635SPaolo Bonzini my $result = $highlights[$k][1]; 2398e2c54635SPaolo Bonzini# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 2399e2c54635SPaolo Bonzini $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 2400e2c54635SPaolo Bonzini} 2401e2c54635SPaolo Bonzini 2402e2c54635SPaolo Bonzini# Read the file that maps relative names to absolute names for 2403e2c54635SPaolo Bonzini# separate source and object directories and for shadow trees. 2404e2c54635SPaolo Bonziniif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 2405e2c54635SPaolo Bonzini my ($relname, $absname); 2406e2c54635SPaolo Bonzini while(<SOURCE_MAP>) { 2407e2c54635SPaolo Bonzini chop(); 2408e2c54635SPaolo Bonzini ($relname, $absname) = (split())[0..1]; 2409e2c54635SPaolo Bonzini $relname =~ s:^/+::; 2410e2c54635SPaolo Bonzini $source_map{$relname} = $absname; 2411e2c54635SPaolo Bonzini } 2412e2c54635SPaolo Bonzini close(SOURCE_MAP); 2413e2c54635SPaolo Bonzini} 2414e2c54635SPaolo Bonzini 2415e2c54635SPaolo Bonziniif ($output_selection == OUTPUT_EXPORTED || 2416e2c54635SPaolo Bonzini $output_selection == OUTPUT_INTERNAL) { 2417e2c54635SPaolo Bonzini 2418e2c54635SPaolo Bonzini push(@export_file_list, @ARGV); 2419e2c54635SPaolo Bonzini 2420e2c54635SPaolo Bonzini foreach (@export_file_list) { 2421e2c54635SPaolo Bonzini chomp; 2422e2c54635SPaolo Bonzini process_export_file($_); 2423e2c54635SPaolo Bonzini } 2424e2c54635SPaolo Bonzini} 2425e2c54635SPaolo Bonzini 2426e2c54635SPaolo Bonziniforeach (@ARGV) { 2427e2c54635SPaolo Bonzini chomp; 2428e2c54635SPaolo Bonzini process_file($_); 2429e2c54635SPaolo Bonzini} 2430e2c54635SPaolo Bonziniif ($verbose && $errors) { 2431e2c54635SPaolo Bonzini print STDERR "$errors errors\n"; 2432e2c54635SPaolo Bonzini} 2433e2c54635SPaolo Bonziniif ($verbose && $warnings) { 2434e2c54635SPaolo Bonzini print STDERR "$warnings warnings\n"; 2435e2c54635SPaolo Bonzini} 2436e2c54635SPaolo Bonzini 243786cba217SPierre-Louis Bossartif ($Werror && $warnings) { 243886cba217SPierre-Louis Bossart print STDERR "$warnings warnings as Errors\n"; 243986cba217SPierre-Louis Bossart exit($warnings); 244086cba217SPierre-Louis Bossart} else { 244186cba217SPierre-Louis Bossart exit($output_mode eq "none" ? 0 : $errors) 244286cba217SPierre-Louis Bossart} 2443