1cb77f0d6SKamil Rytarowski#!/usr/bin/env perl 238476378SJonathan Corbet# SPDX-License-Identifier: GPL-2.0 31da177e4SLinus Torvalds 4cb77f0d6SKamil Rytarowskiuse warnings; 51da177e4SLinus Torvaldsuse strict; 61da177e4SLinus Torvalds 71da177e4SLinus Torvalds## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## 81da177e4SLinus Torvalds## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## 91da177e4SLinus Torvalds## Copyright (C) 2001 Simon Huggins ## 1070c95b00SRandy Dunlap## Copyright (C) 2005-2012 Randy Dunlap ## 111b40c194SDan Luedtke## Copyright (C) 2012 Dan Luedtke ## 121da177e4SLinus Torvalds## ## 131da177e4SLinus Torvalds## #define enhancements by Armin Kuster <akuster@mvista.com> ## 141da177e4SLinus Torvalds## Copyright (c) 2000 MontaVista Software, Inc. ## 151da177e4SLinus Torvalds## ## 161da177e4SLinus Torvalds## This software falls under the GNU General Public License. ## 171da177e4SLinus Torvalds## Please read the COPYING file for more information ## 181da177e4SLinus Torvalds 1943caf1a6STomasz Warniełłouse Pod::Usage qw/pod2usage/; 2043caf1a6STomasz Warniełło 21a5cdaea5STomasz Warniełło=head1 NAME 22a5cdaea5STomasz Warniełło 23a5cdaea5STomasz Warniełłokernel-doc - Print formatted kernel documentation to stdout 24a5cdaea5STomasz Warniełło 25a5cdaea5STomasz Warniełło=head1 SYNOPSIS 26a5cdaea5STomasz Warniełło 27a5cdaea5STomasz Warniełło kernel-doc [-h] [-v] [-Werror] 28a5cdaea5STomasz Warniełło [ -man | 29a5cdaea5STomasz Warniełło -rst [-sphinx-version VERSION] [-enable-lineno] | 30a5cdaea5STomasz Warniełło -none 31a5cdaea5STomasz Warniełło ] 32a5cdaea5STomasz Warniełło [ 33a5cdaea5STomasz Warniełło -export | 34a5cdaea5STomasz Warniełło -internal | 35a5cdaea5STomasz Warniełło [-function NAME] ... | 36a5cdaea5STomasz Warniełło [-nosymbol NAME] ... 37a5cdaea5STomasz Warniełło ] 38a5cdaea5STomasz Warniełło [-no-doc-sections] 39a5cdaea5STomasz Warniełło [-export-file FILE] ... 40a5cdaea5STomasz Warniełło FILE ... 41a5cdaea5STomasz Warniełło 42a5cdaea5STomasz WarniełłoRun `kernel-doc -h` for details. 43a5cdaea5STomasz Warniełło 44f1583922STomasz Warniełło=head1 DESCRIPTION 45f1583922STomasz Warniełło 46f1583922STomasz WarniełłoRead C language source or header FILEs, extract embedded documentation comments, 47f1583922STomasz Warniełłoand print formatted documentation to standard output. 48f1583922STomasz Warniełło 49f1583922STomasz WarniełłoThe documentation comments are identified by the "/**" opening comment mark. 50f1583922STomasz Warniełło 51f1583922STomasz WarniełłoSee Documentation/doc-guide/kernel-doc.rst for the documentation comment syntax. 52f1583922STomasz Warniełło 53a5cdaea5STomasz Warniełło=cut 54a5cdaea5STomasz Warniełło 552875f787STomasz Warniełło# more perldoc at the end of the file 562875f787STomasz Warniełło 571da177e4SLinus Torvalds# 18/01/2001 - Cleanups 581da177e4SLinus Torvalds# Functions prototyped as foo(void) same as foo() 591da177e4SLinus Torvalds# Stop eval'ing where we don't need to. 601da177e4SLinus Torvalds# -- huggie@earth.li 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds# 27/06/2001 - Allowed whitespace after initial "/**" and 631da177e4SLinus Torvalds# allowed comments before function declarations. 641da177e4SLinus Torvalds# -- Christian Kreibich <ck@whoop.org> 651da177e4SLinus Torvalds 661da177e4SLinus Torvalds# Still to do: 671da177e4SLinus Torvalds# - add perldoc documentation 681da177e4SLinus Torvalds# - Look more closely at some of the scarier bits :) 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds# 26/05/2001 - Support for separate source and object trees. 711da177e4SLinus Torvalds# Return error code. 721da177e4SLinus Torvalds# Keith Owens <kaos@ocs.com.au> 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds# 23/09/2001 - Added support for typedefs, structs, enums and unions 751da177e4SLinus Torvalds# Support for Context section; can be terminated using empty line 761da177e4SLinus Torvalds# Small fixes (like spaces vs. \s in regex) 771da177e4SLinus Torvalds# -- Tim Jansen <tim@tjansen.de> 781da177e4SLinus Torvalds 791b40c194SDan Luedtke# 25/07/2012 - Added support for HTML5 801b40c194SDan Luedtke# -- Dan Luedtke <mail@danrl.de> 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds# 831da177e4SLinus Torvalds# format of comments. 841da177e4SLinus Torvalds# In the following table, (...)? signifies optional structure. 851da177e4SLinus Torvalds# (...)* signifies 0 or more structure elements 861da177e4SLinus Torvalds# /** 871da177e4SLinus Torvalds# * function_name(:)? (- short description)? 881da177e4SLinus Torvalds# (* @parameterx: (description of parameter x)?)* 891da177e4SLinus Torvalds# (* a blank line)? 901da177e4SLinus Torvalds# * (Description:)? (Description of function)? 911da177e4SLinus Torvalds# * (section header: (section description)? )* 921da177e4SLinus Torvalds# (*)?*/ 931da177e4SLinus Torvalds# 941da177e4SLinus Torvalds# So .. the trivial example would be: 951da177e4SLinus Torvalds# 961da177e4SLinus Torvalds# /** 971da177e4SLinus Torvalds# * my_function 98b9d97328SRandy Dunlap# */ 991da177e4SLinus Torvalds# 100891dcd2fSRandy Dunlap# If the Description: header tag is omitted, then there must be a blank line 1011da177e4SLinus Torvalds# after the last parameter specification. 1021da177e4SLinus Torvalds# e.g. 1031da177e4SLinus Torvalds# /** 1041da177e4SLinus Torvalds# * my_function - does my stuff 1051da177e4SLinus Torvalds# * @my_arg: its mine damnit 1061da177e4SLinus Torvalds# * 1071da177e4SLinus Torvalds# * Does my stuff explained. 1081da177e4SLinus Torvalds# */ 1091da177e4SLinus Torvalds# 1101da177e4SLinus Torvalds# or, could also use: 1111da177e4SLinus Torvalds# /** 1121da177e4SLinus Torvalds# * my_function - does my stuff 1131da177e4SLinus Torvalds# * @my_arg: its mine damnit 1141da177e4SLinus Torvalds# * Description: Does my stuff explained. 1151da177e4SLinus Torvalds# */ 1161da177e4SLinus Torvalds# etc. 1171da177e4SLinus Torvalds# 118b9d97328SRandy Dunlap# Besides functions you can also write documentation for structs, unions, 1191da177e4SLinus Torvalds# enums and typedefs. Instead of the function name you must write the name 1201da177e4SLinus Torvalds# of the declaration; the struct/union/enum/typedef must always precede 1211da177e4SLinus Torvalds# the name. Nesting of declarations is not supported. 1221da177e4SLinus Torvalds# Use the argument mechanism to document members or constants. 1231da177e4SLinus Torvalds# e.g. 1241da177e4SLinus Torvalds# /** 1251da177e4SLinus Torvalds# * struct my_struct - short description 1261da177e4SLinus Torvalds# * @a: first member 1271da177e4SLinus Torvalds# * @b: second member 1281da177e4SLinus Torvalds# * 1291da177e4SLinus Torvalds# * Longer description 1301da177e4SLinus Torvalds# */ 1311da177e4SLinus Torvalds# struct my_struct { 1321da177e4SLinus Torvalds# int a; 1331da177e4SLinus Torvalds# int b; 134aeec46b9SMartin Waitz# /* private: */ 135aeec46b9SMartin Waitz# int c; 1361da177e4SLinus Torvalds# }; 1371da177e4SLinus Torvalds# 1381da177e4SLinus Torvalds# All descriptions can be multiline, except the short function description. 1391da177e4SLinus Torvalds# 140a4c6ebedSDanilo Cesar Lemes de Paula# For really longs structs, you can also describe arguments inside the 141a4c6ebedSDanilo Cesar Lemes de Paula# body of the struct. 142a4c6ebedSDanilo Cesar Lemes de Paula# eg. 143a4c6ebedSDanilo Cesar Lemes de Paula# /** 144a4c6ebedSDanilo Cesar Lemes de Paula# * struct my_struct - short description 145a4c6ebedSDanilo Cesar Lemes de Paula# * @a: first member 146a4c6ebedSDanilo Cesar Lemes de Paula# * @b: second member 147a4c6ebedSDanilo Cesar Lemes de Paula# * 148a4c6ebedSDanilo Cesar Lemes de Paula# * Longer description 149a4c6ebedSDanilo Cesar Lemes de Paula# */ 150a4c6ebedSDanilo Cesar Lemes de Paula# struct my_struct { 151a4c6ebedSDanilo Cesar Lemes de Paula# int a; 152a4c6ebedSDanilo Cesar Lemes de Paula# int b; 153a4c6ebedSDanilo Cesar Lemes de Paula# /** 154a4c6ebedSDanilo Cesar Lemes de Paula# * @c: This is longer description of C 155a4c6ebedSDanilo Cesar Lemes de Paula# * 156a4c6ebedSDanilo Cesar Lemes de Paula# * You can use paragraphs to describe arguments 157a4c6ebedSDanilo Cesar Lemes de Paula# * using this method. 158a4c6ebedSDanilo Cesar Lemes de Paula# */ 159a4c6ebedSDanilo Cesar Lemes de Paula# int c; 160a4c6ebedSDanilo Cesar Lemes de Paula# }; 161a4c6ebedSDanilo Cesar Lemes de Paula# 162a4c6ebedSDanilo Cesar Lemes de Paula# This should be use only for struct/enum members. 163a4c6ebedSDanilo Cesar Lemes de Paula# 1641da177e4SLinus Torvalds# You can also add additional sections. When documenting kernel functions you 1651da177e4SLinus Torvalds# should document the "Context:" of the function, e.g. whether the functions 1661da177e4SLinus Torvalds# can be called form interrupts. Unlike other sections you can end it with an 1671da177e4SLinus Torvalds# empty line. 1684092bac7SYacine Belkadi# A non-void function should have a "Return:" section describing the return 1694092bac7SYacine Belkadi# value(s). 1701da177e4SLinus Torvalds# Example-sections should contain the string EXAMPLE so that they are marked 1711da177e4SLinus Torvalds# appropriately in DocBook. 1721da177e4SLinus Torvalds# 1731da177e4SLinus Torvalds# Example: 1741da177e4SLinus Torvalds# /** 1751da177e4SLinus Torvalds# * user_function - function that can only be called in user context 1761da177e4SLinus Torvalds# * @a: some argument 1771da177e4SLinus Torvalds# * Context: !in_interrupt() 1781da177e4SLinus Torvalds# * 1791da177e4SLinus Torvalds# * Some description 1801da177e4SLinus Torvalds# * Example: 1811da177e4SLinus Torvalds# * user_function(22); 1821da177e4SLinus Torvalds# */ 1831da177e4SLinus Torvalds# ... 1841da177e4SLinus Torvalds# 1851da177e4SLinus Torvalds# 1861da177e4SLinus Torvalds# All descriptive text is further processed, scanning for the following special 1871da177e4SLinus Torvalds# patterns, which are highlighted appropriately. 1881da177e4SLinus Torvalds# 1891da177e4SLinus Torvalds# 'funcname()' - function 1901da177e4SLinus Torvalds# '$ENVVAR' - environmental variable 1911da177e4SLinus Torvalds# '&struct_name' - name of a structure (up to two words including 'struct') 1925267dd35SPaolo Bonzini# '&struct_name.member' - name of a structure member 1931da177e4SLinus Torvalds# '@parameter' - name of a parameter 1941da177e4SLinus Torvalds# '%CONST' - name of a constant. 195b97f193aSMauro Carvalho Chehab# '``LITERAL``' - literal string without any spaces on it. 1961da177e4SLinus Torvalds 1978484baaaSRandy Dunlap## init lots of data 1988484baaaSRandy Dunlap 1991da177e4SLinus Torvaldsmy $errors = 0; 2001da177e4SLinus Torvaldsmy $warnings = 0; 2015f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 2021da177e4SLinus Torvalds 2031da177e4SLinus Torvalds# match expressions used to find embedded type information 204b97f193aSMauro Carvalho Chehabmy $type_constant = '\b``([^\`]+)``\b'; 205b97f193aSMauro Carvalho Chehabmy $type_constant2 = '\%([-_\w]+)'; 2061da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 207bfd228c7SMike Rapoportmy $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; 208ee2aa759SMauro Carvalho Chehabmy $type_param_ref = '([\!]?)\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; 2095219f18aSJonathan Corbetmy $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params 210346282dbSMauro Carvalho Chehabmy $type_fp_param2 = '\@(\w+->\S+)\(\)'; # Special RST handling for structs with func ptr params 2111da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 212df31175bSPaolo Bonzinimy $type_enum = '\&(enum\s*([_\w]+))'; 213df31175bSPaolo Bonzinimy $type_struct = '\&(struct\s*([_\w]+))'; 214df31175bSPaolo Bonzinimy $type_typedef = '\&(typedef\s*([_\w]+))'; 215df31175bSPaolo Bonzinimy $type_union = '\&(union\s*([_\w]+))'; 2165267dd35SPaolo Bonzinimy $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; 217df31175bSPaolo Bonzinimy $type_fallback = '\&([_\w]+)'; 218f3341dcfSJani Nikulamy $type_member_func = $type_member . '\(\)'; 2191da177e4SLinus Torvalds 2201da177e4SLinus Torvalds# Output conversion substitutions. 2211da177e4SLinus Torvalds# One for each output format 2221da177e4SLinus Torvalds 2231da177e4SLinus Torvalds# these are pretty rough 2244d732701SDanilo Cesar Lemes de Paulamy @highlights_man = ( 2254d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 226b97f193aSMauro Carvalho Chehab [$type_constant2, "\$1"], 2274d732701SDanilo Cesar Lemes de Paula [$type_func, "\\\\fB\$1\\\\fP"], 228df31175bSPaolo Bonzini [$type_enum, "\\\\fI\$1\\\\fP"], 2294d732701SDanilo Cesar Lemes de Paula [$type_struct, "\\\\fI\$1\\\\fP"], 230df31175bSPaolo Bonzini [$type_typedef, "\\\\fI\$1\\\\fP"], 231df31175bSPaolo Bonzini [$type_union, "\\\\fI\$1\\\\fP"], 2325267dd35SPaolo Bonzini [$type_param, "\\\\fI\$1\\\\fP"], 233ee2aa759SMauro Carvalho Chehab [$type_param_ref, "\\\\fI\$1\$2\\\\fP"], 234df31175bSPaolo Bonzini [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], 235df31175bSPaolo Bonzini [$type_fallback, "\\\\fI\$1\\\\fP"] 2364d732701SDanilo Cesar Lemes de Paula ); 2371da177e4SLinus Torvaldsmy $blankline_man = ""; 2381da177e4SLinus Torvalds 239c0d1b6eeSJonathan Corbet# rst-mode 240c0d1b6eeSJonathan Corbetmy @highlights_rst = ( 241c0d1b6eeSJonathan Corbet [$type_constant, "``\$1``"], 242b97f193aSMauro Carvalho Chehab [$type_constant2, "``\$1``"], 243f3341dcfSJani Nikula # Note: need to escape () to avoid func matching later 2445267dd35SPaolo Bonzini [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], 2455267dd35SPaolo Bonzini [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], 2465219f18aSJonathan Corbet [$type_fp_param, "**\$1\\\\(\\\\)**"], 247346282dbSMauro Carvalho Chehab [$type_fp_param2, "**\$1\\\\(\\\\)**"], 248344fdb28SJonathan Corbet [$type_func, "\$1()"], 249df31175bSPaolo Bonzini [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], 250df31175bSPaolo Bonzini [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], 251df31175bSPaolo Bonzini [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], 252df31175bSPaolo Bonzini [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], 253a7291e7eSJani Nikula # in rst this can refer to any type 254df31175bSPaolo Bonzini [$type_fallback, "\\:c\\:type\\:`\$1`"], 255ee2aa759SMauro Carvalho Chehab [$type_param_ref, "**\$1\$2**"] 256c0d1b6eeSJonathan Corbet ); 257c0d1b6eeSJonathan Corbetmy $blankline_rst = "\n"; 258c0d1b6eeSJonathan Corbet 2591da177e4SLinus Torvalds# read arguments 2601da177e4SLinus Torvaldsif ($#ARGV == -1) { 26143caf1a6STomasz Warniełło pod2usage( 26243caf1a6STomasz Warniełło -message => "No arguments!\n", 26343caf1a6STomasz Warniełło -exitval => 1, 26443caf1a6STomasz Warniełło -verbose => 99, 26543caf1a6STomasz Warniełło -sections => 'SYNOPSIS', 26643caf1a6STomasz Warniełło -output => \*STDERR, 26743caf1a6STomasz Warniełło ); 2681da177e4SLinus Torvalds} 2691da177e4SLinus Torvalds 2708484baaaSRandy Dunlapmy $kernelversion; 27193351d41SMauro Carvalho Chehabmy ($sphinx_major, $sphinx_minor, $sphinx_patch); 272efa44475SMauro Carvalho Chehab 2738484baaaSRandy Dunlapmy $dohighlight = ""; 2748484baaaSRandy Dunlap 2751da177e4SLinus Torvaldsmy $verbose = 0; 2762c12c810SPierre-Louis Bossartmy $Werror = 0; 277bdfe2be3SMauro Carvalho Chehabmy $output_mode = "rst"; 278e314ba31SDaniel Santosmy $output_preformatted = 0; 2794b44595aSJohannes Bergmy $no_doc_sections = 0; 2800b0f5f29SDaniel Vettermy $enable_lineno = 0; 281bdfe2be3SMauro Carvalho Chehabmy @highlights = @highlights_rst; 282bdfe2be3SMauro Carvalho Chehabmy $blankline = $blankline_rst; 2831da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 284b6c3f456SJani Nikula 285b6c3f456SJani Nikulause constant { 286b6c3f456SJani Nikula OUTPUT_ALL => 0, # output all symbols and doc sections 287b6c3f456SJani Nikula OUTPUT_INCLUDE => 1, # output only specified symbols 288eab795ddSMauro Carvalho Chehab OUTPUT_EXPORTED => 2, # output exported symbols 289eab795ddSMauro Carvalho Chehab OUTPUT_INTERNAL => 3, # output non-exported symbols 290b6c3f456SJani Nikula}; 291b6c3f456SJani Nikulamy $output_selection = OUTPUT_ALL; 292b0d60bfbSJonathan Corbetmy $show_not_found = 0; # No longer used 293b2c4105bSBen Hutchings 29488c2b57dSJani Nikulamy @export_file_list; 29588c2b57dSJani Nikula 296b2c4105bSBen Hutchingsmy @build_time; 297b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 298b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 299b2c4105bSBen Hutchings @build_time = gmtime($seconds); 300b2c4105bSBen Hutchings} else { 301b2c4105bSBen Hutchings @build_time = localtime; 302b2c4105bSBen Hutchings} 303b2c4105bSBen Hutchings 3041da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 3051da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 306b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 307b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 3081da177e4SLinus Torvalds 3098484baaaSRandy Dunlap# Essentially these are globals. 310b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 311b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 3121da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 3131da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 314eab795ddSMauro Carvalho Chehabmy %nosymbol_table = (); 3150b0f5f29SDaniel Vettermy $declaration_start_line; 3161da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 3171c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 3181da177e4SLinus Torvalds 319bd0e88e5SRandy Dunlapif (defined($ENV{'KBUILD_VERBOSE'})) { 320bd0e88e5SRandy Dunlap $verbose = "$ENV{'KBUILD_VERBOSE'}"; 321bd0e88e5SRandy Dunlap} 322bd0e88e5SRandy Dunlap 3232c12c810SPierre-Louis Bossartif (defined($ENV{'KCFLAGS'})) { 3242c12c810SPierre-Louis Bossart my $kcflags = "$ENV{'KCFLAGS'}"; 3252c12c810SPierre-Louis Bossart 3262c12c810SPierre-Louis Bossart if ($kcflags =~ /Werror/) { 3272c12c810SPierre-Louis Bossart $Werror = 1; 3282c12c810SPierre-Louis Bossart } 3292c12c810SPierre-Louis Bossart} 3302c12c810SPierre-Louis Bossart 331bed4ed30SLaurent Pinchartif (defined($ENV{'KDOC_WERROR'})) { 332bed4ed30SLaurent Pinchart $Werror = "$ENV{'KDOC_WERROR'}"; 333bed4ed30SLaurent Pinchart} 334bed4ed30SLaurent Pinchart 3351da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 3361da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 33793431e06SAlexander A. Klimov# https://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 3381da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 3391da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 3401da177e4SLinus Torvalds# into html. 3411da177e4SLinus Torvaldsmy $section_counter = 0; 3421da177e4SLinus Torvalds 3431da177e4SLinus Torvaldsmy $lineprefix=""; 3441da177e4SLinus Torvalds 34548af606aSJani Nikula# Parser states 34648af606aSJani Nikulause constant { 34748af606aSJani Nikula STATE_NORMAL => 0, # normal code 34848af606aSJani Nikula STATE_NAME => 1, # looking for function name 34917b78717SJonathan Corbet STATE_BODY_MAYBE => 2, # body - or maybe more description 35017b78717SJonathan Corbet STATE_BODY => 3, # the body of the comment 3510d55d48bSMauro Carvalho Chehab STATE_BODY_WITH_BLANK_LINE => 4, # the body, which has a blank line 3520d55d48bSMauro Carvalho Chehab STATE_PROTO => 5, # scanning prototype 3530d55d48bSMauro Carvalho Chehab STATE_DOCBLOCK => 6, # documentation block 3540d55d48bSMauro Carvalho Chehab STATE_INLINE => 7, # gathering doc outside main block 35548af606aSJani Nikula}; 3561da177e4SLinus Torvaldsmy $state; 357850622dfSRandy Dunlapmy $in_doc_sect; 358d742f24dSJonathan Corbetmy $leading_space; 3591da177e4SLinus Torvalds 36048af606aSJani Nikula# Inline documentation state 36148af606aSJani Nikulause constant { 36248af606aSJani Nikula STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 36348af606aSJani Nikula STATE_INLINE_NAME => 1, # looking for member name (@foo:) 36448af606aSJani Nikula STATE_INLINE_TEXT => 2, # looking for member documentation 36548af606aSJani Nikula STATE_INLINE_END => 3, # done 36648af606aSJani Nikula STATE_INLINE_ERROR => 4, # error - Comment without header was found. 36748af606aSJani Nikula # Spit a warning as it's not 368a4c6ebedSDanilo Cesar Lemes de Paula # proper kernel-doc and ignore the rest. 36948af606aSJani Nikula}; 37048af606aSJani Nikulamy $inline_doc_state; 371a4c6ebedSDanilo Cesar Lemes de Paula 3721da177e4SLinus Torvalds#declaration types: can be 3731da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 3741da177e4SLinus Torvaldsmy $decl_type; 3751da177e4SLinus Torvalds 37652042e2dSMauro Carvalho Chehab# Name of the kernel-doc identifier for non-DOC markups 37752042e2dSMauro Carvalho Chehabmy $identifier; 37852042e2dSMauro Carvalho Chehab 3791da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 3801da177e4SLinus Torvaldsmy $doc_end = '\*/'; 3811da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 38212ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 3831da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 384f624adefSJani Nikula# @params and a strictly limited set of supported section names 385212209cfSJonathan Corbet# Specifically: 386212209cfSJonathan Corbet# Match @word: 387212209cfSJonathan Corbet# @...: 388212209cfSJonathan Corbet# @{section-name}: 389212209cfSJonathan Corbet# while trying to not match literal block starts like "example::" 390212209cfSJonathan Corbet# 3918569de68SJonathan Corbetmy $doc_sect = $doc_com . 392212209cfSJonathan Corbet '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:([^:].*)?$'; 39312ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 3941da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 39548af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$'; 396fe7bc493SMauro Carvalho Chehabmy $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)'; 39748af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$'; 3980c9aa209SJani Nikulamy $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; 39986ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 400e86bdb24SAditya Srivastavamy $function_pointer = qr{([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)}; 401e86bdb24SAditya Srivastavamy $attribute = qr{__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)}i; 4021da177e4SLinus Torvalds 4031da177e4SLinus Torvaldsmy %parameterdescs; 4040b0f5f29SDaniel Vettermy %parameterdesc_start_lines; 4051da177e4SLinus Torvaldsmy @parameterlist; 4061da177e4SLinus Torvaldsmy %sections; 4071da177e4SLinus Torvaldsmy @sectionlist; 4080b0f5f29SDaniel Vettermy %section_start_lines; 409a1d94aa5SRandy Dunlapmy $sectcheck; 410a1d94aa5SRandy Dunlapmy $struct_actual; 4111da177e4SLinus Torvalds 4121da177e4SLinus Torvaldsmy $contents = ""; 4130b0f5f29SDaniel Vettermy $new_start_line = 0; 414f624adefSJani Nikula 415f624adefSJani Nikula# the canonical section names. see also $doc_sect above. 4161da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 4171da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 4181da177e4SLinus Torvaldsmy $section = $section_default; 4191da177e4SLinus Torvaldsmy $section_context = "Context"; 4204092bac7SYacine Belkadimy $section_return = "Return"; 4211da177e4SLinus Torvalds 4221da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 4231da177e4SLinus Torvalds 4241da177e4SLinus Torvaldsreset_state(); 4251da177e4SLinus Torvalds 426b031ac4eSMauro Carvalho Chehabwhile ($ARGV[0] =~ m/^--?(.*)/) { 427b031ac4eSMauro Carvalho Chehab my $cmd = $1; 428b031ac4eSMauro Carvalho Chehab shift @ARGV; 429b031ac4eSMauro Carvalho Chehab if ($cmd eq "man") { 4301da177e4SLinus Torvalds $output_mode = "man"; 4314d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 4321da177e4SLinus Torvalds $blankline = $blankline_man; 433b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "rst") { 434c0d1b6eeSJonathan Corbet $output_mode = "rst"; 435c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 436c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 437b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "none") { 4383a025e1dSMatthew Wilcox $output_mode = "none"; 439b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document 4401da177e4SLinus Torvalds $modulename = shift @ARGV; 441b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "function") { # to only output specific functions 442b6c3f456SJani Nikula $output_selection = OUTPUT_INCLUDE; 4431da177e4SLinus Torvalds $function = shift @ARGV; 4441da177e4SLinus Torvalds $function_table{$function} = 1; 445eab795ddSMauro Carvalho Chehab } elsif ($cmd eq "nosymbol") { # Exclude specific symbols 446eab795ddSMauro Carvalho Chehab my $symbol = shift @ARGV; 447eab795ddSMauro Carvalho Chehab $nosymbol_table{$symbol} = 1; 448b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export") { # only exported symbols 449b6c3f456SJani Nikula $output_selection = OUTPUT_EXPORTED; 450da9726ecSJani Nikula %function_table = (); 451b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "internal") { # only non-exported symbols 452b6c3f456SJani Nikula $output_selection = OUTPUT_INTERNAL; 453da9726ecSJani Nikula %function_table = (); 454b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export-file") { 45588c2b57dSJani Nikula my $file = shift @ARGV; 45688c2b57dSJani Nikula push(@export_file_list, $file); 457b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "v") { 4581da177e4SLinus Torvalds $verbose = 1; 4592c12c810SPierre-Louis Bossart } elsif ($cmd eq "Werror") { 4602c12c810SPierre-Louis Bossart $Werror = 1; 461b031ac4eSMauro Carvalho Chehab } elsif (($cmd eq "h") || ($cmd eq "help")) { 462*252b47daSTomasz Warniełło pod2usage(-exitval => 0, -verbose => 2); 463b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'no-doc-sections') { 4644b44595aSJohannes Berg $no_doc_sections = 1; 465b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'enable-lineno') { 4660b0f5f29SDaniel Vetter $enable_lineno = 1; 467b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'show-not-found') { 468b0d60bfbSJonathan Corbet $show_not_found = 1; # A no-op but don't fail 46993351d41SMauro Carvalho Chehab } elsif ($cmd eq "sphinx-version") { 47093351d41SMauro Carvalho Chehab my $ver_string = shift @ARGV; 47193351d41SMauro Carvalho Chehab if ($ver_string =~ m/^(\d+)(\.\d+)?(\.\d+)?/) { 47293351d41SMauro Carvalho Chehab $sphinx_major = $1; 47393351d41SMauro Carvalho Chehab if (defined($2)) { 47493351d41SMauro Carvalho Chehab $sphinx_minor = substr($2,1); 47593351d41SMauro Carvalho Chehab } else { 47693351d41SMauro Carvalho Chehab $sphinx_minor = 0; 47793351d41SMauro Carvalho Chehab } 47893351d41SMauro Carvalho Chehab if (defined($3)) { 47993351d41SMauro Carvalho Chehab $sphinx_patch = substr($3,1) 48093351d41SMauro Carvalho Chehab } else { 48193351d41SMauro Carvalho Chehab $sphinx_patch = 0; 48293351d41SMauro Carvalho Chehab } 48393351d41SMauro Carvalho Chehab } else { 48493351d41SMauro Carvalho Chehab die "Sphinx version should either major.minor or major.minor.patch format\n"; 48593351d41SMauro Carvalho Chehab } 486b031ac4eSMauro Carvalho Chehab } else { 487b031ac4eSMauro Carvalho Chehab # Unknown argument 48843caf1a6STomasz Warniełło pod2usage( 48943caf1a6STomasz Warniełło -message => "Argument unknown!\n", 49043caf1a6STomasz Warniełło -exitval => 1, 49143caf1a6STomasz Warniełło -verbose => 99, 49243caf1a6STomasz Warniełło -sections => 'SYNOPSIS', 49343caf1a6STomasz Warniełło -output => \*STDERR, 49443caf1a6STomasz Warniełło ); 4951da177e4SLinus Torvalds } 4961da177e4SLinus Torvalds} 4971da177e4SLinus Torvalds 4988484baaaSRandy Dunlap# continue execution near EOF; 4998484baaaSRandy Dunlap 500efa44475SMauro Carvalho Chehab# The C domain dialect changed on Sphinx 3. So, we need to check the 501efa44475SMauro Carvalho Chehab# version in order to produce the right tags. 502efa44475SMauro Carvalho Chehabsub findprog($) 503efa44475SMauro Carvalho Chehab{ 504efa44475SMauro Carvalho Chehab foreach(split(/:/, $ENV{PATH})) { 505efa44475SMauro Carvalho Chehab return "$_/$_[0]" if(-x "$_/$_[0]"); 506efa44475SMauro Carvalho Chehab } 507efa44475SMauro Carvalho Chehab} 508efa44475SMauro Carvalho Chehab 509efa44475SMauro Carvalho Chehabsub get_sphinx_version() 510efa44475SMauro Carvalho Chehab{ 511efa44475SMauro Carvalho Chehab my $ver; 512efa44475SMauro Carvalho Chehab 513efa44475SMauro Carvalho Chehab my $cmd = "sphinx-build"; 514efa44475SMauro Carvalho Chehab if (!findprog($cmd)) { 515efa44475SMauro Carvalho Chehab my $cmd = "sphinx-build3"; 51693351d41SMauro Carvalho Chehab if (!findprog($cmd)) { 51793351d41SMauro Carvalho Chehab $sphinx_major = 1; 51893351d41SMauro Carvalho Chehab $sphinx_minor = 2; 51993351d41SMauro Carvalho Chehab $sphinx_patch = 0; 52093351d41SMauro Carvalho Chehab printf STDERR "Warning: Sphinx version not found. Using default (Sphinx version %d.%d.%d)\n", 52193351d41SMauro Carvalho Chehab $sphinx_major, $sphinx_minor, $sphinx_patch; 52293351d41SMauro Carvalho Chehab return; 52393351d41SMauro Carvalho Chehab } 524efa44475SMauro Carvalho Chehab } 525efa44475SMauro Carvalho Chehab 526efa44475SMauro Carvalho Chehab open IN, "$cmd --version 2>&1 |"; 527efa44475SMauro Carvalho Chehab while (<IN>) { 528efa44475SMauro Carvalho Chehab if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) { 52993351d41SMauro Carvalho Chehab $sphinx_major = $1; 53093351d41SMauro Carvalho Chehab $sphinx_minor = $2; 53193351d41SMauro Carvalho Chehab $sphinx_patch = $3; 532efa44475SMauro Carvalho Chehab last; 533efa44475SMauro Carvalho Chehab } 534efa44475SMauro Carvalho Chehab # Sphinx 1.2.x uses a different format 535efa44475SMauro Carvalho Chehab if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+)$/) { 53693351d41SMauro Carvalho Chehab $sphinx_major = $1; 53793351d41SMauro Carvalho Chehab $sphinx_minor = $2; 53893351d41SMauro Carvalho Chehab $sphinx_patch = $3; 539efa44475SMauro Carvalho Chehab last; 540efa44475SMauro Carvalho Chehab } 541efa44475SMauro Carvalho Chehab } 542efa44475SMauro Carvalho Chehab close IN; 543efa44475SMauro Carvalho Chehab} 544efa44475SMauro Carvalho Chehab 54553f049faSBorislav Petkov# get kernel version from env 54653f049faSBorislav Petkovsub get_kernel_version() { 5471b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 54853f049faSBorislav Petkov 54953f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 55053f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 55153f049faSBorislav Petkov } 55253f049faSBorislav Petkov return $version; 55353f049faSBorislav Petkov} 5541da177e4SLinus Torvalds 5550b0f5f29SDaniel Vetter# 5560b0f5f29SDaniel Vettersub print_lineno { 5570b0f5f29SDaniel Vetter my $lineno = shift; 5580b0f5f29SDaniel Vetter if ($enable_lineno && defined($lineno)) { 5590b0f5f29SDaniel Vetter print "#define LINENO " . $lineno . "\n"; 5600b0f5f29SDaniel Vetter } 5610b0f5f29SDaniel Vetter} 5621da177e4SLinus Torvalds## 5631da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 5641da177e4SLinus Torvalds# 5651da177e4SLinus Torvaldssub dump_section { 56694dc7ad5SRandy Dunlap my $file = shift; 5671da177e4SLinus Torvalds my $name = shift; 5681da177e4SLinus Torvalds my $contents = join "\n", @_; 5691da177e4SLinus Torvalds 57013901ef2SJani Nikula if ($name =~ m/$type_param/) { 5711da177e4SLinus Torvalds $name = $1; 5721da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 573a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 5740b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 5750b0f5f29SDaniel Vetter $new_start_line = 0; 576ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 577ced69090SRandy Dunlap $name = "..."; 578ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 579a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 5800b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 5810b0f5f29SDaniel Vetter $new_start_line = 0; 5821da177e4SLinus Torvalds } else { 58394dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 58495b6be9dSJani Nikula # Only warn on user specified duplicate section names. 58595b6be9dSJani Nikula if ($name ne $section_default) { 58632217761SJani Nikula print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; 58732217761SJani Nikula ++$warnings; 58895b6be9dSJani Nikula } 58932217761SJani Nikula $sections{$name} .= $contents; 59032217761SJani Nikula } else { 5911da177e4SLinus Torvalds $sections{$name} = $contents; 5921da177e4SLinus Torvalds push @sectionlist, $name; 5930b0f5f29SDaniel Vetter $section_start_lines{$name} = $new_start_line; 5940b0f5f29SDaniel Vetter $new_start_line = 0; 5951da177e4SLinus Torvalds } 5961da177e4SLinus Torvalds } 59732217761SJani Nikula} 5981da177e4SLinus Torvalds 5991da177e4SLinus Torvalds## 600b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 601b112e0f7SJohannes Berg# 602b112e0f7SJohannes Bergsub dump_doc_section { 60394dc7ad5SRandy Dunlap my $file = shift; 604b112e0f7SJohannes Berg my $name = shift; 605b112e0f7SJohannes Berg my $contents = join "\n", @_; 606b112e0f7SJohannes Berg 6074b44595aSJohannes Berg if ($no_doc_sections) { 6084b44595aSJohannes Berg return; 6094b44595aSJohannes Berg } 6104b44595aSJohannes Berg 611eab795ddSMauro Carvalho Chehab return if (defined($nosymbol_table{$name})); 612eab795ddSMauro Carvalho Chehab 613b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 614eab795ddSMauro Carvalho Chehab (($output_selection == OUTPUT_INCLUDE) && 615eab795ddSMauro Carvalho Chehab defined($function_table{$name}))) 616b112e0f7SJohannes Berg { 61794dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 618b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 619b112e0f7SJohannes Berg 'sections' => \%sections, 620b112e0f7SJohannes Berg 'module' => $modulename, 621b6c3f456SJani Nikula 'content-only' => ($output_selection != OUTPUT_ALL), }); 622b112e0f7SJohannes Berg } 623b112e0f7SJohannes Berg} 624b112e0f7SJohannes Berg 625b112e0f7SJohannes Berg## 6261da177e4SLinus Torvalds# output function 6271da177e4SLinus Torvalds# 6281da177e4SLinus Torvalds# parameterdescs, a hash. 6291da177e4SLinus Torvalds# function => "function name" 6301da177e4SLinus Torvalds# parameterlist => @list of parameters 6311da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 6321da177e4SLinus Torvalds# sectionlist => @list of sections 633a21217daSRandy Dunlap# sections => %section descriptions 6341da177e4SLinus Torvalds# 6351da177e4SLinus Torvalds 6361da177e4SLinus Torvaldssub output_highlight { 6371da177e4SLinus Torvalds my $contents = join "\n",@_; 6381da177e4SLinus Torvalds my $line; 6391da177e4SLinus Torvalds 6401da177e4SLinus Torvalds# DEBUG 6411da177e4SLinus Torvalds# if (!defined $contents) { 6421da177e4SLinus Torvalds# use Carp; 6431da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 6441da177e4SLinus Torvalds# } 6451da177e4SLinus Torvalds 6463eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 6471da177e4SLinus Torvalds eval $dohighlight; 6481da177e4SLinus Torvalds die $@ if $@; 6493eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 6503eb014a1SRandy Dunlap 6511da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 65212ae6779SDaniel Santos if (! $output_preformatted) { 65312ae6779SDaniel Santos $line =~ s/^\s*//; 65412ae6779SDaniel Santos } 6551da177e4SLinus Torvalds if ($line eq ""){ 656e314ba31SDaniel Santos if (! $output_preformatted) { 6570bba924cSJonathan Corbet print $lineprefix, $blankline; 658e314ba31SDaniel Santos } 6591da177e4SLinus Torvalds } else { 660cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 661cdccb316SRandy Dunlap print "\\&$line"; 662cdccb316SRandy Dunlap } else { 6631da177e4SLinus Torvalds print $lineprefix, $line; 6641da177e4SLinus Torvalds } 665cdccb316SRandy Dunlap } 6661da177e4SLinus Torvalds print "\n"; 6671da177e4SLinus Torvalds } 6681da177e4SLinus Torvalds} 6691da177e4SLinus Torvalds 6701da177e4SLinus Torvalds## 6711da177e4SLinus Torvalds# output function in man 6721da177e4SLinus Torvaldssub output_function_man(%) { 6731da177e4SLinus Torvalds my %args = %{$_[0]}; 6741da177e4SLinus Torvalds my ($parameter, $section); 6751da177e4SLinus Torvalds my $count; 6761da177e4SLinus Torvalds 6771da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 6781da177e4SLinus Torvalds 6791da177e4SLinus Torvalds print ".SH NAME\n"; 6801da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 6811da177e4SLinus Torvalds 6821da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 683a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 6841da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 685a21217daSRandy Dunlap } else { 686a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 687a21217daSRandy Dunlap } 6881da177e4SLinus Torvalds $count = 0; 6891da177e4SLinus Torvalds my $parenth = "("; 6901da177e4SLinus Torvalds my $post = ","; 6911da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 6921da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 6931da177e4SLinus Torvalds $post = ");"; 6941da177e4SLinus Torvalds } 6951da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 696e86bdb24SAditya Srivastava if ($type =~ m/$function_pointer/) { 6971da177e4SLinus Torvalds # pointer-to-function 698ed8348e2SMauro Carvalho Chehab print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n"; 6991da177e4SLinus Torvalds } else { 7001da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 701ed8348e2SMauro Carvalho Chehab print ".BI \"" . $parenth . $type . "\" " . " \"" . $post . "\"\n"; 7021da177e4SLinus Torvalds } 7031da177e4SLinus Torvalds $count++; 7041da177e4SLinus Torvalds $parenth = ""; 7051da177e4SLinus Torvalds } 7061da177e4SLinus Torvalds 7071da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 7081da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7091da177e4SLinus Torvalds my $parameter_name = $parameter; 7101da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7111da177e4SLinus Torvalds 7121da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 7131da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7141da177e4SLinus Torvalds } 7151da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7161da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 7171da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7181da177e4SLinus Torvalds } 7191da177e4SLinus Torvalds} 7201da177e4SLinus Torvalds 7211da177e4SLinus Torvalds## 7221da177e4SLinus Torvalds# output enum in man 7231da177e4SLinus Torvaldssub output_enum_man(%) { 7241da177e4SLinus Torvalds my %args = %{$_[0]}; 7251da177e4SLinus Torvalds my ($parameter, $section); 7261da177e4SLinus Torvalds my $count; 7271da177e4SLinus Torvalds 7281da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 7291da177e4SLinus Torvalds 7301da177e4SLinus Torvalds print ".SH NAME\n"; 7311da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 7321da177e4SLinus Torvalds 7331da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 7341da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 7351da177e4SLinus Torvalds $count = 0; 7361da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 7371da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 7381da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 7391da177e4SLinus Torvalds print "\n};\n"; 7401da177e4SLinus Torvalds last; 7411da177e4SLinus Torvalds } 7421da177e4SLinus Torvalds else { 7431da177e4SLinus Torvalds print ", \n.br\n"; 7441da177e4SLinus Torvalds } 7451da177e4SLinus Torvalds $count++; 7461da177e4SLinus Torvalds } 7471da177e4SLinus Torvalds 7481da177e4SLinus Torvalds print ".SH Constants\n"; 7491da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7501da177e4SLinus Torvalds my $parameter_name = $parameter; 7511da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7521da177e4SLinus Torvalds 7531da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 7541da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7551da177e4SLinus Torvalds } 7561da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7571da177e4SLinus Torvalds print ".SH \"$section\"\n"; 7581da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7591da177e4SLinus Torvalds } 7601da177e4SLinus Torvalds} 7611da177e4SLinus Torvalds 7621da177e4SLinus Torvalds## 7631da177e4SLinus Torvalds# output struct in man 7641da177e4SLinus Torvaldssub output_struct_man(%) { 7651da177e4SLinus Torvalds my %args = %{$_[0]}; 7661da177e4SLinus Torvalds my ($parameter, $section); 7671da177e4SLinus Torvalds 7681da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 7691da177e4SLinus Torvalds 7701da177e4SLinus Torvalds print ".SH NAME\n"; 7711da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 7721da177e4SLinus Torvalds 7738ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 7748ad72163SMauro Carvalho Chehab $declaration =~ s/\t/ /g; 7758ad72163SMauro Carvalho Chehab $declaration =~ s/\n/"\n.br\n.BI \"/g; 7761da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 7771da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 7788ad72163SMauro Carvalho Chehab print ".BI \"$declaration\n};\n.br\n\n"; 7791da177e4SLinus Torvalds 780c51d3dacSRandy Dunlap print ".SH Members\n"; 7811da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 7821da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 7831da177e4SLinus Torvalds 7841da177e4SLinus Torvalds my $parameter_name = $parameter; 7851da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 7861da177e4SLinus Torvalds 7871da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 7881da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 7891da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 7901da177e4SLinus Torvalds } 7911da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7921da177e4SLinus Torvalds print ".SH \"$section\"\n"; 7931da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7941da177e4SLinus Torvalds } 7951da177e4SLinus Torvalds} 7961da177e4SLinus Torvalds 7971da177e4SLinus Torvalds## 7981da177e4SLinus Torvalds# output typedef in man 7991da177e4SLinus Torvaldssub output_typedef_man(%) { 8001da177e4SLinus Torvalds my %args = %{$_[0]}; 8011da177e4SLinus Torvalds my ($parameter, $section); 8021da177e4SLinus Torvalds 8031da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 8041da177e4SLinus Torvalds 8051da177e4SLinus Torvalds print ".SH NAME\n"; 8061da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 8071da177e4SLinus Torvalds 8081da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 8091da177e4SLinus Torvalds print ".SH \"$section\"\n"; 8101da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 8111da177e4SLinus Torvalds } 8121da177e4SLinus Torvalds} 8131da177e4SLinus Torvalds 814b112e0f7SJohannes Bergsub output_blockhead_man(%) { 8151da177e4SLinus Torvalds my %args = %{$_[0]}; 8161da177e4SLinus Torvalds my ($parameter, $section); 8171da177e4SLinus Torvalds my $count; 8181da177e4SLinus Torvalds 8191da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 8201da177e4SLinus Torvalds 8211da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 8221da177e4SLinus Torvalds print ".SH \"$section\"\n"; 8231da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 8241da177e4SLinus Torvalds } 8251da177e4SLinus Torvalds} 8261da177e4SLinus Torvalds 8271da177e4SLinus Torvalds## 828c0d1b6eeSJonathan Corbet# output in restructured text 829c0d1b6eeSJonathan Corbet# 830c0d1b6eeSJonathan Corbet 831c0d1b6eeSJonathan Corbet# 832c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 833c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 834c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 835c0d1b6eeSJonathan Corbet# 836c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 837c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 838c0d1b6eeSJonathan Corbet my ($parameter, $section); 839c0d1b6eeSJonathan Corbet 840c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 841eab795ddSMauro Carvalho Chehab next if (defined($nosymbol_table{$section})); 842eab795ddSMauro Carvalho Chehab 8439e72184bSJani Nikula if ($output_selection != OUTPUT_INCLUDE) { 84406a755d6SMichal Wajdeczko print ".. _$section:\n\n"; 845c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 8469e72184bSJani Nikula } 8470b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 848c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 849c0d1b6eeSJonathan Corbet print "\n"; 850c0d1b6eeSJonathan Corbet } 851c0d1b6eeSJonathan Corbet} 852c0d1b6eeSJonathan Corbet 853af250290SJonathan Corbet# 854af250290SJonathan Corbet# Apply the RST highlights to a sub-block of text. 855af250290SJonathan Corbet# 856af250290SJonathan Corbetsub highlight_block($) { 857af250290SJonathan Corbet # The dohighlight kludge requires the text be called $contents 858af250290SJonathan Corbet my $contents = shift; 859c0d1b6eeSJonathan Corbet eval $dohighlight; 860c0d1b6eeSJonathan Corbet die $@ if $@; 861af250290SJonathan Corbet return $contents; 862af250290SJonathan Corbet} 863c0d1b6eeSJonathan Corbet 864af250290SJonathan Corbet# 865af250290SJonathan Corbet# Regexes used only here. 866af250290SJonathan Corbet# 867af250290SJonathan Corbetmy $sphinx_literal = '^[^.].*::$'; 868af250290SJonathan Corbetmy $sphinx_cblock = '^\.\.\ +code-block::'; 869af250290SJonathan Corbet 870af250290SJonathan Corbetsub output_highlight_rst { 871af250290SJonathan Corbet my $input = join "\n",@_; 872af250290SJonathan Corbet my $output = ""; 873af250290SJonathan Corbet my $line; 874af250290SJonathan Corbet my $in_literal = 0; 875af250290SJonathan Corbet my $litprefix; 876af250290SJonathan Corbet my $block = ""; 877af250290SJonathan Corbet 878af250290SJonathan Corbet foreach $line (split "\n",$input) { 879af250290SJonathan Corbet # 880af250290SJonathan Corbet # If we're in a literal block, see if we should drop out 881af250290SJonathan Corbet # of it. Otherwise pass the line straight through unmunged. 882af250290SJonathan Corbet # 883af250290SJonathan Corbet if ($in_literal) { 884af250290SJonathan Corbet if (! ($line =~ /^\s*$/)) { 885af250290SJonathan Corbet # 886af250290SJonathan Corbet # If this is the first non-blank line in a literal 887af250290SJonathan Corbet # block we need to figure out what the proper indent is. 888af250290SJonathan Corbet # 889af250290SJonathan Corbet if ($litprefix eq "") { 890af250290SJonathan Corbet $line =~ /^(\s*)/; 891af250290SJonathan Corbet $litprefix = '^' . $1; 892af250290SJonathan Corbet $output .= $line . "\n"; 893af250290SJonathan Corbet } elsif (! ($line =~ /$litprefix/)) { 894af250290SJonathan Corbet $in_literal = 0; 895af250290SJonathan Corbet } else { 896af250290SJonathan Corbet $output .= $line . "\n"; 897af250290SJonathan Corbet } 898af250290SJonathan Corbet } else { 899af250290SJonathan Corbet $output .= $line . "\n"; 900af250290SJonathan Corbet } 901af250290SJonathan Corbet } 902af250290SJonathan Corbet # 903af250290SJonathan Corbet # Not in a literal block (or just dropped out) 904af250290SJonathan Corbet # 905af250290SJonathan Corbet if (! $in_literal) { 906af250290SJonathan Corbet $block .= $line . "\n"; 907af250290SJonathan Corbet if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) { 908af250290SJonathan Corbet $in_literal = 1; 909af250290SJonathan Corbet $litprefix = ""; 910af250290SJonathan Corbet $output .= highlight_block($block); 911af250290SJonathan Corbet $block = "" 912af250290SJonathan Corbet } 913af250290SJonathan Corbet } 914af250290SJonathan Corbet } 915af250290SJonathan Corbet 916af250290SJonathan Corbet if ($block) { 917af250290SJonathan Corbet $output .= highlight_block($block); 918af250290SJonathan Corbet } 919af250290SJonathan Corbet foreach $line (split "\n", $output) { 920830066a7SJani Nikula print $lineprefix . $line . "\n"; 921c0d1b6eeSJonathan Corbet } 922c0d1b6eeSJonathan Corbet} 923c0d1b6eeSJonathan Corbet 924c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 925c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 926c0d1b6eeSJonathan Corbet my ($parameter, $section); 927c099ff69SJani Nikula my $oldprefix = $lineprefix; 92882801d06SMauro Carvalho Chehab my $start = ""; 9296e9e4158SMauro Carvalho Chehab my $is_macro = 0; 930c0d1b6eeSJonathan Corbet 931efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 932e3ad05feSMauro Carvalho Chehab if ($args{'typedef'}) { 93382801d06SMauro Carvalho Chehab print ".. c:type:: ". $args{'function'} . "\n\n"; 93482801d06SMauro Carvalho Chehab print_lineno($declaration_start_line); 93582801d06SMauro Carvalho Chehab print " **Typedef**: "; 93682801d06SMauro Carvalho Chehab $lineprefix = ""; 93782801d06SMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 93882801d06SMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 9396e9e4158SMauro Carvalho Chehab $is_macro = 1; 940c0d1b6eeSJonathan Corbet } else { 94182801d06SMauro Carvalho Chehab print ".. c:function:: "; 94282801d06SMauro Carvalho Chehab } 943e3ad05feSMauro Carvalho Chehab } else { 9446e9e4158SMauro Carvalho Chehab if ($args{'typedef'} || $args{'functiontype'} eq "") { 9456e9e4158SMauro Carvalho Chehab $is_macro = 1; 946e3ad05feSMauro Carvalho Chehab print ".. c:macro:: ". $args{'function'} . "\n\n"; 9476e9e4158SMauro Carvalho Chehab } else { 9486e9e4158SMauro Carvalho Chehab print ".. c:function:: "; 9496e9e4158SMauro Carvalho Chehab } 950e3ad05feSMauro Carvalho Chehab 951e3ad05feSMauro Carvalho Chehab if ($args{'typedef'}) { 952e3ad05feSMauro Carvalho Chehab print_lineno($declaration_start_line); 953e3ad05feSMauro Carvalho Chehab print " **Typedef**: "; 954e3ad05feSMauro Carvalho Chehab $lineprefix = ""; 955e3ad05feSMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 956e3ad05feSMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 957e3ad05feSMauro Carvalho Chehab } else { 9586e9e4158SMauro Carvalho Chehab print "``" if ($is_macro); 959e3ad05feSMauro Carvalho Chehab } 960e3ad05feSMauro Carvalho Chehab } 96182801d06SMauro Carvalho Chehab if ($args{'functiontype'} ne "") { 96282801d06SMauro Carvalho Chehab $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; 96382801d06SMauro Carvalho Chehab } else { 96482801d06SMauro Carvalho Chehab $start .= $args{'function'} . " ("; 965c0d1b6eeSJonathan Corbet } 966c0d1b6eeSJonathan Corbet print $start; 967c0d1b6eeSJonathan Corbet 968c0d1b6eeSJonathan Corbet my $count = 0; 969c0d1b6eeSJonathan Corbet foreach my $parameter (@{$args{'parameterlist'}}) { 970c0d1b6eeSJonathan Corbet if ($count ne 0) { 971c0d1b6eeSJonathan Corbet print ", "; 972c0d1b6eeSJonathan Corbet } 973c0d1b6eeSJonathan Corbet $count++; 974c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 975a88b1672SMauro Carvalho Chehab 976e86bdb24SAditya Srivastava if ($type =~ m/$function_pointer/) { 977c0d1b6eeSJonathan Corbet # pointer-to-function 978e8f4ba83SPeter Maydell print $1 . $parameter . ") (" . $2 . ")"; 979c0d1b6eeSJonathan Corbet } else { 980ed8348e2SMauro Carvalho Chehab print $type; 981c0d1b6eeSJonathan Corbet } 982c0d1b6eeSJonathan Corbet } 9836e9e4158SMauro Carvalho Chehab if ($is_macro) { 9846e9e4158SMauro Carvalho Chehab print ")``\n\n"; 98582801d06SMauro Carvalho Chehab } else { 986c099ff69SJani Nikula print ")\n\n"; 987e3ad05feSMauro Carvalho Chehab } 9886e9e4158SMauro Carvalho Chehab if (!$args{'typedef'}) { 9890b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 990c099ff69SJani Nikula $lineprefix = " "; 991c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 992c099ff69SJani Nikula print "\n"; 99382801d06SMauro Carvalho Chehab } 994c0d1b6eeSJonathan Corbet 995ecbcfba1SJani Nikula print "**Parameters**\n\n"; 996c099ff69SJani Nikula $lineprefix = " "; 997c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 998c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 999ada5f446SGabriel Krisman Bertazi $parameter_name =~ s/\[.*//; 1000c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 1001c0d1b6eeSJonathan Corbet 1002c0d1b6eeSJonathan Corbet if ($type ne "") { 1003ed8348e2SMauro Carvalho Chehab print "``$type``\n"; 1004c0d1b6eeSJonathan Corbet } else { 1005c0d1b6eeSJonathan Corbet print "``$parameter``\n"; 1006c0d1b6eeSJonathan Corbet } 10070b0f5f29SDaniel Vetter 10080b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 10090b0f5f29SDaniel Vetter 10105e64fa9cSJani Nikula if (defined($args{'parameterdescs'}{$parameter_name}) && 10115e64fa9cSJani Nikula $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 1012c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1013c0d1b6eeSJonathan Corbet } else { 1014d4b08e0cSJani Nikula print " *undescribed*\n"; 1015c0d1b6eeSJonathan Corbet } 1016c0d1b6eeSJonathan Corbet print "\n"; 1017c0d1b6eeSJonathan Corbet } 1018c099ff69SJani Nikula 1019c099ff69SJani Nikula $lineprefix = $oldprefix; 1020c0d1b6eeSJonathan Corbet output_section_rst(@_); 1021c0d1b6eeSJonathan Corbet} 1022c0d1b6eeSJonathan Corbet 1023c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 1024c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1025c0d1b6eeSJonathan Corbet my $section; 1026c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 1027c0d1b6eeSJonathan Corbet $lineprefix = ""; 1028c0d1b6eeSJonathan Corbet 1029c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 1030ecbcfba1SJani Nikula print "**$section**\n\n"; 10310b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 1032c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 1033c0d1b6eeSJonathan Corbet print "\n"; 1034c0d1b6eeSJonathan Corbet } 1035c0d1b6eeSJonathan Corbet print "\n"; 1036c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1037c0d1b6eeSJonathan Corbet} 1038c0d1b6eeSJonathan Corbet 1039c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 1040c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1041c0d1b6eeSJonathan Corbet my ($parameter); 1042c099ff69SJani Nikula my $oldprefix = $lineprefix; 1043c0d1b6eeSJonathan Corbet my $count; 104462850976SJani Nikula 1045efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 1046efa44475SMauro Carvalho Chehab my $name = "enum " . $args{'enum'}; 104762850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1048efa44475SMauro Carvalho Chehab } else { 1049efa44475SMauro Carvalho Chehab my $name = $args{'enum'}; 1050efa44475SMauro Carvalho Chehab print "\n\n.. c:enum:: " . $name . "\n\n"; 1051efa44475SMauro Carvalho Chehab } 10520b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1053c099ff69SJani Nikula $lineprefix = " "; 1054c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1055c099ff69SJani Nikula print "\n"; 1056c0d1b6eeSJonathan Corbet 1057ecbcfba1SJani Nikula print "**Constants**\n\n"; 1058c0d1b6eeSJonathan Corbet $lineprefix = " "; 1059c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1060ecbcfba1SJani Nikula print "``$parameter``\n"; 1061c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 1062c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 1063c0d1b6eeSJonathan Corbet } else { 1064d4b08e0cSJani Nikula print " *undescribed*\n"; 1065c0d1b6eeSJonathan Corbet } 1066c0d1b6eeSJonathan Corbet print "\n"; 1067c0d1b6eeSJonathan Corbet } 1068c099ff69SJani Nikula 1069c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 1070c0d1b6eeSJonathan Corbet output_section_rst(@_); 1071c0d1b6eeSJonathan Corbet} 1072c0d1b6eeSJonathan Corbet 1073c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 1074c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1075c0d1b6eeSJonathan Corbet my ($parameter); 1076c099ff69SJani Nikula my $oldprefix = $lineprefix; 1077efa44475SMauro Carvalho Chehab my $name; 1078c0d1b6eeSJonathan Corbet 1079efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 1080efa44475SMauro Carvalho Chehab $name = "typedef " . $args{'typedef'}; 1081efa44475SMauro Carvalho Chehab } else { 1082efa44475SMauro Carvalho Chehab $name = $args{'typedef'}; 1083efa44475SMauro Carvalho Chehab } 108462850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 10850b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1086c099ff69SJani Nikula $lineprefix = " "; 1087c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1088c099ff69SJani Nikula print "\n"; 1089c0d1b6eeSJonathan Corbet 1090c099ff69SJani Nikula $lineprefix = $oldprefix; 1091c0d1b6eeSJonathan Corbet output_section_rst(@_); 1092c0d1b6eeSJonathan Corbet} 1093c0d1b6eeSJonathan Corbet 1094c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 1095c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1096c0d1b6eeSJonathan Corbet my ($parameter); 1097c099ff69SJani Nikula my $oldprefix = $lineprefix; 1098c0d1b6eeSJonathan Corbet 1099efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 1100efa44475SMauro Carvalho Chehab my $name = $args{'type'} . " " . $args{'struct'}; 110162850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1102efa44475SMauro Carvalho Chehab } else { 1103efa44475SMauro Carvalho Chehab my $name = $args{'struct'}; 110472b97d0bSMauro Carvalho Chehab if ($args{'type'} eq 'union') { 110572b97d0bSMauro Carvalho Chehab print "\n\n.. c:union:: " . $name . "\n\n"; 110672b97d0bSMauro Carvalho Chehab } else { 1107efa44475SMauro Carvalho Chehab print "\n\n.. c:struct:: " . $name . "\n\n"; 1108efa44475SMauro Carvalho Chehab } 110972b97d0bSMauro Carvalho Chehab } 11100b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1111c099ff69SJani Nikula $lineprefix = " "; 1112c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1113c099ff69SJani Nikula print "\n"; 1114c0d1b6eeSJonathan Corbet 1115ecbcfba1SJani Nikula print "**Definition**\n\n"; 1116c0d1b6eeSJonathan Corbet print "::\n\n"; 11178ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 11188ad72163SMauro Carvalho Chehab $declaration =~ s/\t/ /g; 11198ad72163SMauro Carvalho Chehab print " " . $args{'type'} . " " . $args{'struct'} . " {\n$declaration };\n\n"; 1120c0d1b6eeSJonathan Corbet 1121ecbcfba1SJani Nikula print "**Members**\n\n"; 1122c099ff69SJani Nikula $lineprefix = " "; 1123c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1124c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 1125c0d1b6eeSJonathan Corbet 1126c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1127c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 1128c0d1b6eeSJonathan Corbet 1129c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1130c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 11310b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 11326d232c80SMauro Carvalho Chehab print "``" . $parameter . "``\n"; 1133c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1134c0d1b6eeSJonathan Corbet print "\n"; 1135c0d1b6eeSJonathan Corbet } 1136c0d1b6eeSJonathan Corbet print "\n"; 1137c099ff69SJani Nikula 1138c099ff69SJani Nikula $lineprefix = $oldprefix; 1139c0d1b6eeSJonathan Corbet output_section_rst(@_); 1140c0d1b6eeSJonathan Corbet} 1141c0d1b6eeSJonathan Corbet 11423a025e1dSMatthew Wilcox## none mode output functions 11433a025e1dSMatthew Wilcox 11443a025e1dSMatthew Wilcoxsub output_function_none(%) { 11453a025e1dSMatthew Wilcox} 11463a025e1dSMatthew Wilcox 11473a025e1dSMatthew Wilcoxsub output_enum_none(%) { 11483a025e1dSMatthew Wilcox} 11493a025e1dSMatthew Wilcox 11503a025e1dSMatthew Wilcoxsub output_typedef_none(%) { 11513a025e1dSMatthew Wilcox} 11523a025e1dSMatthew Wilcox 11533a025e1dSMatthew Wilcoxsub output_struct_none(%) { 11543a025e1dSMatthew Wilcox} 11553a025e1dSMatthew Wilcox 11563a025e1dSMatthew Wilcoxsub output_blockhead_none(%) { 11573a025e1dSMatthew Wilcox} 11583a025e1dSMatthew Wilcox 11591da177e4SLinus Torvalds## 116027205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 116127205744SRandy Dunlap# calls the generated, variable output_ function name based on 116227205744SRandy Dunlap# functype and output_mode 11631da177e4SLinus Torvaldssub output_declaration { 11641da177e4SLinus Torvalds no strict 'refs'; 11651da177e4SLinus Torvalds my $name = shift; 11661da177e4SLinus Torvalds my $functype = shift; 11671da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 1168eab795ddSMauro Carvalho Chehab 1169eab795ddSMauro Carvalho Chehab return if (defined($nosymbol_table{$name})); 1170eab795ddSMauro Carvalho Chehab 1171b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 1172b6c3f456SJani Nikula (($output_selection == OUTPUT_INCLUDE || 1173b6c3f456SJani Nikula $output_selection == OUTPUT_EXPORTED) && 117486ae2e38SJani Nikula defined($function_table{$name})) || 1175eab795ddSMauro Carvalho Chehab ($output_selection == OUTPUT_INTERNAL && 117686ae2e38SJani Nikula !($functype eq "function" && defined($function_table{$name})))) 11771da177e4SLinus Torvalds { 11781da177e4SLinus Torvalds &$func(@_); 11791da177e4SLinus Torvalds $section_counter++; 11801da177e4SLinus Torvalds } 11811da177e4SLinus Torvalds} 11821da177e4SLinus Torvalds 11831da177e4SLinus Torvalds## 118427205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 1185b112e0f7SJohannes Bergsub output_blockhead { 11861da177e4SLinus Torvalds no strict 'refs'; 1187b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 11881da177e4SLinus Torvalds &$func(@_); 11891da177e4SLinus Torvalds $section_counter++; 11901da177e4SLinus Torvalds} 11911da177e4SLinus Torvalds 11921da177e4SLinus Torvalds## 11931da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 11941da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 11951da177e4SLinus Torvaldssub dump_declaration($$) { 11961da177e4SLinus Torvalds no strict 'refs'; 11971da177e4SLinus Torvalds my ($prototype, $file) = @_; 11981da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 11991da177e4SLinus Torvalds &$func(@_); 12001da177e4SLinus Torvalds} 12011da177e4SLinus Torvalds 12021da177e4SLinus Torvaldssub dump_union($$) { 12031da177e4SLinus Torvalds dump_struct(@_); 12041da177e4SLinus Torvalds} 12051da177e4SLinus Torvalds 12061da177e4SLinus Torvaldssub dump_struct($$) { 12071da177e4SLinus Torvalds my $x = shift; 12081da177e4SLinus Torvalds my $file = shift; 1209a746fe32SAditya Srivastava my $decl_type; 1210a746fe32SAditya Srivastava my $members; 1211a746fe32SAditya Srivastava my $type = qr{struct|union}; 1212a746fe32SAditya Srivastava # For capturing struct/union definition body, i.e. "{members*}qualifiers*" 1213e86bdb24SAditya Srivastava my $qualifiers = qr{$attribute|__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned}; 1214e86bdb24SAditya Srivastava my $definition_body = qr{\{(.*)\}\s*$qualifiers*}; 1215e86bdb24SAditya Srivastava my $struct_members = qr{($type)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;}; 12161da177e4SLinus Torvalds 1217a746fe32SAditya Srivastava if ($x =~ /($type)\s+(\w+)\s*$definition_body/) { 1218a746fe32SAditya Srivastava $decl_type = $1; 12191da177e4SLinus Torvalds $declaration_name = $2; 1220a746fe32SAditya Srivastava $members = $3; 1221a746fe32SAditya Srivastava } elsif ($x =~ /typedef\s+($type)\s*$definition_body\s*(\w+)\s*;/) { 1222a746fe32SAditya Srivastava $decl_type = $1; 1223a746fe32SAditya Srivastava $declaration_name = $3; 1224a746fe32SAditya Srivastava $members = $2; 1225a746fe32SAditya Srivastava } 12261da177e4SLinus Torvalds 1227a746fe32SAditya Srivastava if ($members) { 122852042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 122952042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: expecting prototype for $decl_type $identifier. Prototype was for $decl_type $declaration_name instead\n"; 123052042e2dSMauro Carvalho Chehab return; 123152042e2dSMauro Carvalho Chehab } 123252042e2dSMauro Carvalho Chehab 1233aeec46b9SMartin Waitz # ignore members marked private: 12340d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 12350d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 1236aeec46b9SMartin Waitz # strip comments: 1237aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 1238ef5da59fSRandy Dunlap # strip attributes 1239e86bdb24SAditya Srivastava $members =~ s/\s*$attribute/ /gi; 12403d9bfb19SSakari Ailus $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos; 12413d9bfb19SSakari Ailus $members =~ s/\s*__packed\s*/ /gos; 1242f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos; 1243f861537dSAndré Almeida $members =~ s/\s*____cacheline_aligned_in_smp/ /gos; 1244a070991fSJonathan Cameron $members =~ s/\s*____cacheline_aligned/ /gos; 124550d7bd38SKees Cook # unwrap struct_group(): 124650d7bd38SKees Cook # - first eat non-declaration parameters and rewrite for final match 124750d7bd38SKees Cook # - then remove macro, outer parens, and trailing semicolon 124850d7bd38SKees Cook $members =~ s/\bstruct_group\s*\(([^,]*,)/STRUCT_GROUP(/gos; 124950d7bd38SKees Cook $members =~ s/\bstruct_group_(attr|tagged)\s*\(([^,]*,){2}/STRUCT_GROUP(/gos; 125050d7bd38SKees Cook $members =~ s/\b__struct_group\s*\(([^,]*,){3}/STRUCT_GROUP(/gos; 125150d7bd38SKees Cook $members =~ s/\bSTRUCT_GROUP(\(((?:(?>[^)(]+)|(?1))*)\))[^;]*;/$2/gos; 12523556108eSMauro Carvalho Chehab 1253e86bdb24SAditya Srivastava my $args = qr{([^,)]+)}; 1254b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 12553556108eSMauro Carvalho Chehab $members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos; 1256603bdf5dSRandy Dunlap $members =~ s/DECLARE_PHY_INTERFACE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, PHY_INTERFACE_MODE_MAX)/gos; 1257e86bdb24SAditya Srivastava $members =~ s/DECLARE_BITMAP\s*\($args,\s*$args\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 12581cb566baSJakub Kicinski # replace DECLARE_HASHTABLE 1259e86bdb24SAditya Srivastava $members =~ s/DECLARE_HASHTABLE\s*\($args,\s*$args\)/unsigned long $1\[1 << (($2) - 1)\]/gos; 126045005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO 1261e86bdb24SAditya Srivastava $members =~ s/DECLARE_KFIFO\s*\($args,\s*$args,\s*$args\)/$2 \*$1/gos; 126245005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO_PTR 1263e86bdb24SAditya Srivastava $members =~ s/DECLARE_KFIFO_PTR\s*\($args,\s*$args\)/$2 \*$1/gos; 12643080ea55SKees Cook # replace DECLARE_FLEX_ARRAY 12653080ea55SKees Cook $members =~ s/(?:__)?DECLARE_FLEX_ARRAY\s*\($args,\s*$args\)/$1 $2\[\]/gos; 12668ad72163SMauro Carvalho Chehab my $declaration = $members; 12678ad72163SMauro Carvalho Chehab 12688ad72163SMauro Carvalho Chehab # Split nested struct/union elements as newer ones 1269e86bdb24SAditya Srivastava while ($members =~ m/$struct_members/) { 127084ce5b98SMauro Carvalho Chehab my $newmember; 127184ce5b98SMauro Carvalho Chehab my $maintype = $1; 127284ce5b98SMauro Carvalho Chehab my $ids = $4; 12738ad72163SMauro Carvalho Chehab my $content = $3; 127484ce5b98SMauro Carvalho Chehab foreach my $id(split /,/, $ids) { 127584ce5b98SMauro Carvalho Chehab $newmember .= "$maintype $id; "; 127684ce5b98SMauro Carvalho Chehab 12778ad72163SMauro Carvalho Chehab $id =~ s/[:\[].*//; 127884ce5b98SMauro Carvalho Chehab $id =~ s/^\s*\**(\S+)\s*/$1/; 12798ad72163SMauro Carvalho Chehab foreach my $arg (split /;/, $content) { 12808ad72163SMauro Carvalho Chehab next if ($arg =~ m/^\s*$/); 12817c0d7e87SMauro Carvalho Chehab if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) { 12827c0d7e87SMauro Carvalho Chehab # pointer-to-function 12837c0d7e87SMauro Carvalho Chehab my $type = $1; 12847c0d7e87SMauro Carvalho Chehab my $name = $2; 12857c0d7e87SMauro Carvalho Chehab my $extra = $3; 12867c0d7e87SMauro Carvalho Chehab next if (!$name); 12877c0d7e87SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 12887c0d7e87SMauro Carvalho Chehab # anonymous struct/union 12897c0d7e87SMauro Carvalho Chehab $newmember .= "$type$name$extra; "; 12907c0d7e87SMauro Carvalho Chehab } else { 12917c0d7e87SMauro Carvalho Chehab $newmember .= "$type$id.$name$extra; "; 12927c0d7e87SMauro Carvalho Chehab } 12937c0d7e87SMauro Carvalho Chehab } else { 129484ce5b98SMauro Carvalho Chehab my $type; 129584ce5b98SMauro Carvalho Chehab my $names; 129684ce5b98SMauro Carvalho Chehab $arg =~ s/^\s+//; 129784ce5b98SMauro Carvalho Chehab $arg =~ s/\s+$//; 129884ce5b98SMauro Carvalho Chehab # Handle bitmaps 129984ce5b98SMauro Carvalho Chehab $arg =~ s/:\s*\d+\s*//g; 130084ce5b98SMauro Carvalho Chehab # Handle arrays 1301d404d579SMauro Carvalho Chehab $arg =~ s/\[.*\]//g; 130284ce5b98SMauro Carvalho Chehab # The type may have multiple words, 130384ce5b98SMauro Carvalho Chehab # and multiple IDs can be defined, like: 130484ce5b98SMauro Carvalho Chehab # const struct foo, *bar, foobar 130584ce5b98SMauro Carvalho Chehab # So, we remove spaces when parsing the 130684ce5b98SMauro Carvalho Chehab # names, in order to match just names 130784ce5b98SMauro Carvalho Chehab # and commas for the names 130884ce5b98SMauro Carvalho Chehab $arg =~ s/\s*,\s*/,/g; 130984ce5b98SMauro Carvalho Chehab if ($arg =~ m/(.*)\s+([\S+,]+)/) { 131084ce5b98SMauro Carvalho Chehab $type = $1; 131184ce5b98SMauro Carvalho Chehab $names = $2; 131284ce5b98SMauro Carvalho Chehab } else { 131384ce5b98SMauro Carvalho Chehab $newmember .= "$arg; "; 131484ce5b98SMauro Carvalho Chehab next; 131584ce5b98SMauro Carvalho Chehab } 131684ce5b98SMauro Carvalho Chehab foreach my $name (split /,/, $names) { 131784ce5b98SMauro Carvalho Chehab $name =~ s/^\s*\**(\S+)\s*/$1/; 13188ad72163SMauro Carvalho Chehab next if (($name =~ m/^\s*$/)); 13198ad72163SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 13208ad72163SMauro Carvalho Chehab # anonymous struct/union 13218ad72163SMauro Carvalho Chehab $newmember .= "$type $name; "; 13228ad72163SMauro Carvalho Chehab } else { 13238ad72163SMauro Carvalho Chehab $newmember .= "$type $id.$name; "; 13248ad72163SMauro Carvalho Chehab } 13258ad72163SMauro Carvalho Chehab } 13267c0d7e87SMauro Carvalho Chehab } 132784ce5b98SMauro Carvalho Chehab } 132884ce5b98SMauro Carvalho Chehab } 1329e86bdb24SAditya Srivastava $members =~ s/$struct_members/$newmember/; 133084ce5b98SMauro Carvalho Chehab } 13318ad72163SMauro Carvalho Chehab 13328ad72163SMauro Carvalho Chehab # Ignore other nested elements, like enums 1333673bb2dfSBen Hutchings $members =~ s/(\{[^\{\}]*\})//g; 13348ad72163SMauro Carvalho Chehab 1335151c468bSMauro Carvalho Chehab create_parameterlist($members, ';', $file, $declaration_name); 13361081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual); 13371da177e4SLinus Torvalds 13388ad72163SMauro Carvalho Chehab # Adjust declaration for better display 1339673bb2dfSBen Hutchings $declaration =~ s/([\{;])/$1\n/g; 1340673bb2dfSBen Hutchings $declaration =~ s/\}\s+;/};/g; 13418ad72163SMauro Carvalho Chehab # Better handle inlined enums 1342673bb2dfSBen Hutchings do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/); 13438ad72163SMauro Carvalho Chehab 13448ad72163SMauro Carvalho Chehab my @def_args = split /\n/, $declaration; 13458ad72163SMauro Carvalho Chehab my $level = 1; 13468ad72163SMauro Carvalho Chehab $declaration = ""; 13478ad72163SMauro Carvalho Chehab foreach my $clause (@def_args) { 13488ad72163SMauro Carvalho Chehab $clause =~ s/^\s+//; 13498ad72163SMauro Carvalho Chehab $clause =~ s/\s+$//; 13508ad72163SMauro Carvalho Chehab $clause =~ s/\s+/ /; 13518ad72163SMauro Carvalho Chehab next if (!$clause); 1352673bb2dfSBen Hutchings $level-- if ($clause =~ m/(\})/ && $level > 1); 13538ad72163SMauro Carvalho Chehab if (!($clause =~ m/^\s*#/)) { 13548ad72163SMauro Carvalho Chehab $declaration .= "\t" x $level; 13558ad72163SMauro Carvalho Chehab } 13568ad72163SMauro Carvalho Chehab $declaration .= "\t" . $clause . "\n"; 1357673bb2dfSBen Hutchings $level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/)); 13588ad72163SMauro Carvalho Chehab } 13591da177e4SLinus Torvalds output_declaration($declaration_name, 13601da177e4SLinus Torvalds 'struct', 13611da177e4SLinus Torvalds {'struct' => $declaration_name, 13621da177e4SLinus Torvalds 'module' => $modulename, 13638ad72163SMauro Carvalho Chehab 'definition' => $declaration, 13641da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 13651da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 13661da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 13671da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 13681da177e4SLinus Torvalds 'sections' => \%sections, 13691da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 13701da177e4SLinus Torvalds 'type' => $decl_type 13711da177e4SLinus Torvalds }); 13721da177e4SLinus Torvalds } 13731da177e4SLinus Torvalds else { 1374d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 13751da177e4SLinus Torvalds ++$errors; 13761da177e4SLinus Torvalds } 13771da177e4SLinus Torvalds} 13781da177e4SLinus Torvalds 137985afe608SMauro Carvalho Chehab 138085afe608SMauro Carvalho Chehabsub show_warnings($$) { 138185afe608SMauro Carvalho Chehab my $functype = shift; 138285afe608SMauro Carvalho Chehab my $name = shift; 138385afe608SMauro Carvalho Chehab 1384eab795ddSMauro Carvalho Chehab return 0 if (defined($nosymbol_table{$name})); 1385eab795ddSMauro Carvalho Chehab 138685afe608SMauro Carvalho Chehab return 1 if ($output_selection == OUTPUT_ALL); 138785afe608SMauro Carvalho Chehab 138885afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_EXPORTED) { 138985afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 139085afe608SMauro Carvalho Chehab return 1; 139185afe608SMauro Carvalho Chehab } else { 139285afe608SMauro Carvalho Chehab return 0; 139385afe608SMauro Carvalho Chehab } 139485afe608SMauro Carvalho Chehab } 139585afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_INTERNAL) { 139685afe608SMauro Carvalho Chehab if (!($functype eq "function" && defined($function_table{$name}))) { 139785afe608SMauro Carvalho Chehab return 1; 139885afe608SMauro Carvalho Chehab } else { 139985afe608SMauro Carvalho Chehab return 0; 140085afe608SMauro Carvalho Chehab } 140185afe608SMauro Carvalho Chehab } 140285afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_INCLUDE) { 140385afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 140485afe608SMauro Carvalho Chehab return 1; 140585afe608SMauro Carvalho Chehab } else { 140685afe608SMauro Carvalho Chehab return 0; 140785afe608SMauro Carvalho Chehab } 140885afe608SMauro Carvalho Chehab } 140985afe608SMauro Carvalho Chehab die("Please add the new output type at show_warnings()"); 141085afe608SMauro Carvalho Chehab} 141185afe608SMauro Carvalho Chehab 14121da177e4SLinus Torvaldssub dump_enum($$) { 14131da177e4SLinus Torvalds my $x = shift; 14141da177e4SLinus Torvalds my $file = shift; 1415d38c8cfbSMauro Carvalho Chehab my $members; 1416d38c8cfbSMauro Carvalho Chehab 14171da177e4SLinus Torvalds 1418aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 14194468e21eSConchúr Navid # strip #define macros inside enums 14204468e21eSConchúr Navid $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 1421b6d676dbSRandy Dunlap 1422d38c8cfbSMauro Carvalho Chehab if ($x =~ /typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;/) { 1423d38c8cfbSMauro Carvalho Chehab $declaration_name = $2; 1424d38c8cfbSMauro Carvalho Chehab $members = $1; 1425d38c8cfbSMauro Carvalho Chehab } elsif ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) { 14261da177e4SLinus Torvalds $declaration_name = $1; 1427d38c8cfbSMauro Carvalho Chehab $members = $2; 1428d38c8cfbSMauro Carvalho Chehab } 1429d38c8cfbSMauro Carvalho Chehab 1430ae5b17e4SAndy Shevchenko if ($members) { 143152042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 14320b54c2e3SMauro Carvalho Chehab if ($identifier eq "") { 14330b54c2e3SMauro Carvalho Chehab print STDERR "${file}:$.: warning: wrong kernel-doc identifier on line:\n"; 14340b54c2e3SMauro Carvalho Chehab } else { 143552042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: expecting prototype for enum $identifier. Prototype was for enum $declaration_name instead\n"; 14360b54c2e3SMauro Carvalho Chehab } 143752042e2dSMauro Carvalho Chehab return; 143852042e2dSMauro Carvalho Chehab } 14390b54c2e3SMauro Carvalho Chehab $declaration_name = "(anonymous)" if ($declaration_name eq ""); 144052042e2dSMauro Carvalho Chehab 14415cb5c31cSJohannes Berg my %_members; 14425cb5c31cSJohannes Berg 1443463a0fdcSMarkus Heiser $members =~ s/\s+$//; 14441da177e4SLinus Torvalds 14451da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 14461da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 14471da177e4SLinus Torvalds push @parameterlist, $arg; 14481da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 14491da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 145085afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 14512defb272SMauro Carvalho Chehab print STDERR "${file}:$.: warning: Enum value '$arg' not described in enum '$declaration_name'\n"; 14522defb272SMauro Carvalho Chehab } 14531da177e4SLinus Torvalds } 14545cb5c31cSJohannes Berg $_members{$arg} = 1; 14555cb5c31cSJohannes Berg } 14561da177e4SLinus Torvalds 14575cb5c31cSJohannes Berg while (my ($k, $v) = each %parameterdescs) { 14585cb5c31cSJohannes Berg if (!exists($_members{$k})) { 145985afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 14602defb272SMauro Carvalho Chehab print STDERR "${file}:$.: warning: Excess enum value '$k' description in '$declaration_name'\n"; 14612defb272SMauro Carvalho Chehab } 14625cb5c31cSJohannes Berg } 14631da177e4SLinus Torvalds } 14641da177e4SLinus Torvalds 14651da177e4SLinus Torvalds output_declaration($declaration_name, 14661da177e4SLinus Torvalds 'enum', 14671da177e4SLinus Torvalds {'enum' => $declaration_name, 14681da177e4SLinus Torvalds 'module' => $modulename, 14691da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 14701da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 14711da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 14721da177e4SLinus Torvalds 'sections' => \%sections, 14731da177e4SLinus Torvalds 'purpose' => $declaration_purpose 14741da177e4SLinus Torvalds }); 1475d38c8cfbSMauro Carvalho Chehab } else { 1476d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 14771da177e4SLinus Torvalds ++$errors; 14781da177e4SLinus Torvalds } 14791da177e4SLinus Torvalds} 14801da177e4SLinus Torvalds 14817d2c6b1eSMauro Carvalho Chehabmy $typedef_type = qr { ((?:\s+[\w\*]+\b){1,8})\s* }x; 14827efc6c42SMauro Carvalho Chehabmy $typedef_ident = qr { \*?\s*(\w\S+)\s* }x; 14837efc6c42SMauro Carvalho Chehabmy $typedef_args = qr { \s*\((.*)\); }x; 14847efc6c42SMauro Carvalho Chehab 14857efc6c42SMauro Carvalho Chehabmy $typedef1 = qr { typedef$typedef_type\($typedef_ident\)$typedef_args }x; 14867efc6c42SMauro Carvalho Chehabmy $typedef2 = qr { typedef$typedef_type$typedef_ident$typedef_args }x; 14877efc6c42SMauro Carvalho Chehab 14881da177e4SLinus Torvaldssub dump_typedef($$) { 14891da177e4SLinus Torvalds my $x = shift; 14901da177e4SLinus Torvalds my $file = shift; 14911da177e4SLinus Torvalds 1492aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 149383766452SMauro Carvalho Chehab 14947efc6c42SMauro Carvalho Chehab # Parse function typedef prototypes 14957efc6c42SMauro Carvalho Chehab if ($x =~ $typedef1 || $x =~ $typedef2) { 149683766452SMauro Carvalho Chehab $return_type = $1; 149783766452SMauro Carvalho Chehab $declaration_name = $2; 149883766452SMauro Carvalho Chehab my $args = $3; 14996b80975cSMauro Carvalho Chehab $return_type =~ s/^\s+//; 150083766452SMauro Carvalho Chehab 150152042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 150252042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n"; 150352042e2dSMauro Carvalho Chehab return; 150452042e2dSMauro Carvalho Chehab } 150552042e2dSMauro Carvalho Chehab 1506151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 150783766452SMauro Carvalho Chehab 150883766452SMauro Carvalho Chehab output_declaration($declaration_name, 150983766452SMauro Carvalho Chehab 'function', 151083766452SMauro Carvalho Chehab {'function' => $declaration_name, 151182801d06SMauro Carvalho Chehab 'typedef' => 1, 151283766452SMauro Carvalho Chehab 'module' => $modulename, 151383766452SMauro Carvalho Chehab 'functiontype' => $return_type, 151483766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 151583766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 151683766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 151783766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 151883766452SMauro Carvalho Chehab 'sections' => \%sections, 151983766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 152083766452SMauro Carvalho Chehab }); 152183766452SMauro Carvalho Chehab return; 152283766452SMauro Carvalho Chehab } 152383766452SMauro Carvalho Chehab 15241da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 15251da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 15261da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 15271da177e4SLinus Torvalds } 15281da177e4SLinus Torvalds 15291da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 15301da177e4SLinus Torvalds $declaration_name = $1; 15311da177e4SLinus Torvalds 153252042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 153352042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n"; 153452042e2dSMauro Carvalho Chehab return; 153552042e2dSMauro Carvalho Chehab } 153652042e2dSMauro Carvalho Chehab 15371da177e4SLinus Torvalds output_declaration($declaration_name, 15381da177e4SLinus Torvalds 'typedef', 15391da177e4SLinus Torvalds {'typedef' => $declaration_name, 15401da177e4SLinus Torvalds 'module' => $modulename, 15411da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 15421da177e4SLinus Torvalds 'sections' => \%sections, 15431da177e4SLinus Torvalds 'purpose' => $declaration_purpose 15441da177e4SLinus Torvalds }); 15451da177e4SLinus Torvalds } 15461da177e4SLinus Torvalds else { 1547d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 15481da177e4SLinus Torvalds ++$errors; 15491da177e4SLinus Torvalds } 15501da177e4SLinus Torvalds} 15511da177e4SLinus Torvalds 1552a1d94aa5SRandy Dunlapsub save_struct_actual($) { 1553a1d94aa5SRandy Dunlap my $actual = shift; 1554a1d94aa5SRandy Dunlap 1555a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 1556a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 1557a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 1558a1d94aa5SRandy Dunlap} 1559a1d94aa5SRandy Dunlap 1560151c468bSMauro Carvalho Chehabsub create_parameterlist($$$$) { 15611da177e4SLinus Torvalds my $args = shift; 15621da177e4SLinus Torvalds my $splitter = shift; 15631da177e4SLinus Torvalds my $file = shift; 1564151c468bSMauro Carvalho Chehab my $declaration_name = shift; 15651da177e4SLinus Torvalds my $type; 15661da177e4SLinus Torvalds my $param; 15671da177e4SLinus Torvalds 1568a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 1569e86bdb24SAditya Srivastava my $arg_expr = qr{\([^\),]+}; 1570e86bdb24SAditya Srivastava while ($args =~ /$arg_expr,/) { 1571e86bdb24SAditya Srivastava $args =~ s/($arg_expr),/$1#/g; 15721da177e4SLinus Torvalds } 15731da177e4SLinus Torvalds 15741da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 15751da177e4SLinus Torvalds # strip comments 15761da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 15771da177e4SLinus Torvalds # strip leading/trailing spaces 15781da177e4SLinus Torvalds $arg =~ s/^\s*//; 15791da177e4SLinus Torvalds $arg =~ s/\s*$//; 15801da177e4SLinus Torvalds $arg =~ s/\s+/ /; 15811da177e4SLinus Torvalds 15821da177e4SLinus Torvalds if ($arg =~ /^#/) { 15831da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 15841da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 15851da177e4SLinus Torvalds # output_* subs. 1586ed8348e2SMauro Carvalho Chehab push_parameter($arg, "", "", $file); 158700d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 15881da177e4SLinus Torvalds # pointer-to-function 15891da177e4SLinus Torvalds $arg =~ tr/#/,/; 1590336ced2dSAditya Srivastava $arg =~ m/[^\(]+\(\*?\s*([\w\[\]\.]*)\s*\)/; 15911da177e4SLinus Torvalds $param = $1; 15921da177e4SLinus Torvalds $type = $arg; 159300d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1594a1d94aa5SRandy Dunlap save_struct_actual($param); 1595ed8348e2SMauro Carvalho Chehab push_parameter($param, $type, $arg, $file, $declaration_name); 1596aeec46b9SMartin Waitz } elsif ($arg) { 15971da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 15981da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 15991da177e4SLinus Torvalds 16001da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 16011da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 16021da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 16031da177e4SLinus Torvalds } 1604884f2810SBorislav Petkov 1605884f2810SBorislav Petkov my @first_arg; 1606884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1607884f2810SBorislav Petkov shift @args; 1608884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 1609884f2810SBorislav Petkov push(@first_arg, $2); 1610884f2810SBorislav Petkov } else { 1611884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 1612884f2810SBorislav Petkov } 1613884f2810SBorislav Petkov 16141da177e4SLinus Torvalds unshift(@args, pop @first_arg); 16151da177e4SLinus Torvalds $type = join " ", @first_arg; 16161da177e4SLinus Torvalds 16171da177e4SLinus Torvalds foreach $param (@args) { 16181da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 1619a1d94aa5SRandy Dunlap save_struct_actual($2); 1620ed8348e2SMauro Carvalho Chehab 1621ed8348e2SMauro Carvalho Chehab push_parameter($2, "$type $1", $arg, $file, $declaration_name); 16221da177e4SLinus Torvalds } 16231da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 16247b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 1625a1d94aa5SRandy Dunlap save_struct_actual($1); 1626ed8348e2SMauro Carvalho Chehab push_parameter($1, "$type:$2", $arg, $file, $declaration_name) 16271da177e4SLinus Torvalds } 16287b97887eSRandy Dunlap } 16291da177e4SLinus Torvalds else { 1630a1d94aa5SRandy Dunlap save_struct_actual($param); 1631ed8348e2SMauro Carvalho Chehab push_parameter($param, $type, $arg, $file, $declaration_name); 16321da177e4SLinus Torvalds } 16331da177e4SLinus Torvalds } 16341da177e4SLinus Torvalds } 16351da177e4SLinus Torvalds } 16361da177e4SLinus Torvalds} 16371da177e4SLinus Torvalds 1638ed8348e2SMauro Carvalho Chehabsub push_parameter($$$$$) { 16391da177e4SLinus Torvalds my $param = shift; 16401da177e4SLinus Torvalds my $type = shift; 1641ed8348e2SMauro Carvalho Chehab my $org_arg = shift; 16421da177e4SLinus Torvalds my $file = shift; 1643151c468bSMauro Carvalho Chehab my $declaration_name = shift; 16441da177e4SLinus Torvalds 16455f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 16465f8c7c98SRandy Dunlap ($param eq "}")) { 16475f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 16485f8c7c98SRandy Dunlap } 16495f8c7c98SRandy Dunlap 16505f8c7c98SRandy Dunlap $anon_struct_union = 0; 1651f9b5c530SMauro Carvalho Chehab $param =~ s/[\[\)].*//; 16521da177e4SLinus Torvalds 1653a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 16541da177e4SLinus Torvalds { 1655c950a173SSilvio Fricke if (!$param =~ /\w\.\.\.$/) { 1656c950a173SSilvio Fricke # handles unnamed variable parameters 1657ef00028bSJonathan Corbet $param = "..."; 1658c950a173SSilvio Fricke } 165943756e34SJonathan Neuschäfer elsif ($param =~ /\w\.\.\.$/) { 166043756e34SJonathan Neuschäfer # for named variable parameters of the form `x...`, remove the dots 166143756e34SJonathan Neuschäfer $param =~ s/\.\.\.$//; 166243756e34SJonathan Neuschäfer } 1663ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1664a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 16651da177e4SLinus Torvalds } 1666ced69090SRandy Dunlap } 16671da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 16681da177e4SLinus Torvalds { 16691da177e4SLinus Torvalds $param="void"; 16701da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 16711da177e4SLinus Torvalds } 1672134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1673134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 1674134fe01bSRandy Dunlap { 1675134fe01bSRandy Dunlap $type = $param; 1676134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 1677134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 16785f8c7c98SRandy Dunlap $anon_struct_union = 1; 1679134fe01bSRandy Dunlap } 1680134fe01bSRandy Dunlap 1681a6d3fe77SMartin Waitz # warn if parameter has no description 1682134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 1683134fe01bSRandy Dunlap # but inline preprocessor statements); 1684151c468bSMauro Carvalho Chehab # Note: It will also ignore void params and unnamed structs/unions 1685f9b5c530SMauro Carvalho Chehab if (!defined $parameterdescs{$param} && $param !~ /^#/) { 1686f9b5c530SMauro Carvalho Chehab $parameterdescs{$param} = $undescribed; 16871da177e4SLinus Torvalds 1688be5cd20cSJonathan Corbet if (show_warnings($type, $declaration_name) && $param !~ /\./) { 1689151c468bSMauro Carvalho Chehab print STDERR 1690151c468bSMauro Carvalho Chehab "${file}:$.: warning: Function parameter or member '$param' not described in '$declaration_name'\n"; 16911da177e4SLinus Torvalds ++$warnings; 16921da177e4SLinus Torvalds } 16932defb272SMauro Carvalho Chehab } 16941da177e4SLinus Torvalds 169525985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 1696e34e7dbbSRandy Dunlap # on @parameterlist; 1697e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 1698e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 1699e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 1700e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 1701e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 1702e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 1703e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 17041da177e4SLinus Torvalds push @parameterlist, $param; 1705ed8348e2SMauro Carvalho Chehab $org_arg =~ s/\s\s+/ /g; 1706ed8348e2SMauro Carvalho Chehab $parametertypes{$param} = $org_arg; 17071da177e4SLinus Torvalds} 17081da177e4SLinus Torvalds 17091081de2dSMauro Carvalho Chehabsub check_sections($$$$$) { 17101081de2dSMauro Carvalho Chehab my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_; 1711a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 1712a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 1713a1d94aa5SRandy Dunlap my $err; 1714a1d94aa5SRandy Dunlap my ($px, $sx); 1715a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 1716a1d94aa5SRandy Dunlap 1717a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 1718a1d94aa5SRandy Dunlap $err = 1; 1719a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 1720a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 1721a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 1722e86bdb24SAditya Srivastava $prm_clean =~ s/$attribute//i; 1723e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 1724e34e7dbbSRandy Dunlap # however, the original param string may contain 1725e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 1726e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 1727e34e7dbbSRandy Dunlap # parameter list is split at spaces; 1728e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 1729e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 1730e34e7dbbSRandy Dunlap 1731a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 1732a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 1733a1d94aa5SRandy Dunlap $err = 0; 1734a1d94aa5SRandy Dunlap last; 1735a1d94aa5SRandy Dunlap } 1736a1d94aa5SRandy Dunlap } 1737a1d94aa5SRandy Dunlap if ($err) { 1738a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 1739d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 1740a1d94aa5SRandy Dunlap "Excess function parameter " . 1741a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 1742a1d94aa5SRandy Dunlap "description in '$decl_name'\n"; 1743a1d94aa5SRandy Dunlap ++$warnings; 1744a1d94aa5SRandy Dunlap } 1745a1d94aa5SRandy Dunlap } 1746a1d94aa5SRandy Dunlap } 1747a1d94aa5SRandy Dunlap} 1748a1d94aa5SRandy Dunlap 17491da177e4SLinus Torvalds## 17504092bac7SYacine Belkadi# Checks the section describing the return value of a function. 17514092bac7SYacine Belkadisub check_return_section { 17524092bac7SYacine Belkadi my $file = shift; 17534092bac7SYacine Belkadi my $declaration_name = shift; 17544092bac7SYacine Belkadi my $return_type = shift; 17554092bac7SYacine Belkadi 17564092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 17574092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 17584092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 17594092bac7SYacine Belkadi return; 17604092bac7SYacine Belkadi } 17614092bac7SYacine Belkadi 17624092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 17634092bac7SYacine Belkadi $sections{$section_return} eq "") { 1764d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: " . 17654092bac7SYacine Belkadi "No description found for return value of " . 17664092bac7SYacine Belkadi "'$declaration_name'\n"; 17674092bac7SYacine Belkadi ++$warnings; 17684092bac7SYacine Belkadi } 17694092bac7SYacine Belkadi} 17704092bac7SYacine Belkadi 17714092bac7SYacine Belkadi## 17721da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 17731da177e4SLinus Torvalds# processed and spits out all the details stored in the global 17741da177e4SLinus Torvalds# arrays/hashes. 17751da177e4SLinus Torvaldssub dump_function($$) { 17761da177e4SLinus Torvalds my $prototype = shift; 17771da177e4SLinus Torvalds my $file = shift; 1778cbb4d3e6SHoria Geanta my $noret = 0; 17791da177e4SLinus Torvalds 17805ef09c96SMauro Carvalho Chehab print_lineno($new_start_line); 17815eb6b4b3SMauro Carvalho Chehab 17821da177e4SLinus Torvalds $prototype =~ s/^static +//; 17831da177e4SLinus Torvalds $prototype =~ s/^extern +//; 17844dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 17851da177e4SLinus Torvalds $prototype =~ s/^inline +//; 17861da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 178732e79401SRandy Dunlap $prototype =~ s/^__inline +//; 178832e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 178932e79401SRandy Dunlap $prototype =~ s/^noinline +//; 179074fc5c65SRandy Dunlap $prototype =~ s/__init +//; 179120072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 179280342d48SMatthew Wilcox $prototype =~ s/__deprecated +//; 1793084aa001SAditya Srivastava $prototype =~ s/__flatten +//; 1794270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 179570c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 17960df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 17970891f959SMatthew Wilcox $prototype =~ s/__sched +//; 179895e760cbSRandy Dunlap $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//; 1799a40a8a11SKees Cook $prototype =~ s/__alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +//; 1800cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 1801084aa001SAditya Srivastava $prototype =~ s/__attribute_const__ +//; 1802b1aaa546SPaolo Bonzini $prototype =~ s/__attribute__\s*\(\( 1803b1aaa546SPaolo Bonzini (?: 1804b1aaa546SPaolo Bonzini [\w\s]++ # attribute name 1805b1aaa546SPaolo Bonzini (?:\([^)]*+\))? # attribute arguments 1806b1aaa546SPaolo Bonzini \s*+,? # optional comma at the end 1807b1aaa546SPaolo Bonzini )+ 1808b1aaa546SPaolo Bonzini \)\)\s+//x; 18091da177e4SLinus Torvalds 18101da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 18111da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 18121da177e4SLinus Torvalds # 2. Function name 18131da177e4SLinus Torvalds # 3. Function parameters. 18141da177e4SLinus Torvalds # 18151da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 18161da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 18171da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 18181da177e4SLinus Torvalds # so on. 18191da177e4SLinus Torvalds # 18201da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 18211da177e4SLinus Torvalds # the following functions' documentation still comes out right: 18221da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 18231da177e4SLinus Torvalds # - atomic_set (macro) 18249598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 1825e86bdb24SAditya Srivastava my $name = qr{[a-zA-Z0-9_~:]+}; 1826e86bdb24SAditya Srivastava my $prototype_end1 = qr{[^\(]*}; 1827e86bdb24SAditya Srivastava my $prototype_end2 = qr{[^\{]*}; 1828e86bdb24SAditya Srivastava my $prototype_end = qr{\(($prototype_end1|$prototype_end2)\)}; 1829e86bdb24SAditya Srivastava my $type1 = qr{[\w\s]+}; 1830e86bdb24SAditya Srivastava my $type2 = qr{$type1\*+}; 18311da177e4SLinus Torvalds 1832e86bdb24SAditya Srivastava if ($define && $prototype =~ m/^()($name)\s+/) { 1833cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 1834cbb4d3e6SHoria Geanta # list. 1835cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 1836cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 1837cbb4d3e6SHoria Geanta $return_type = $1; 1838cbb4d3e6SHoria Geanta $declaration_name = $2; 1839cbb4d3e6SHoria Geanta $noret = 1; 1840e86bdb24SAditya Srivastava } elsif ($prototype =~ m/^()($name)\s*$prototype_end/ || 1841e86bdb24SAditya Srivastava $prototype =~ m/^($type1)\s+($name)\s*$prototype_end/ || 1842e86bdb24SAditya Srivastava $prototype =~ m/^($type2+)\s*($name)\s*$prototype_end/) { 18431da177e4SLinus Torvalds $return_type = $1; 18441da177e4SLinus Torvalds $declaration_name = $2; 18451da177e4SLinus Torvalds my $args = $3; 18461da177e4SLinus Torvalds 1847151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 18481da177e4SLinus Torvalds } else { 1849d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 18501da177e4SLinus Torvalds return; 18511da177e4SLinus Torvalds } 18521da177e4SLinus Torvalds 185352042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 185452042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: expecting prototype for $identifier(). Prototype was for $declaration_name() instead\n"; 185552042e2dSMauro Carvalho Chehab return; 185652042e2dSMauro Carvalho Chehab } 185752042e2dSMauro Carvalho Chehab 1858a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 18591081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, "function", $sectcheck, $prms); 1860a1d94aa5SRandy Dunlap 18614092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 18624092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 18634092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 18644092bac7SYacine Belkadi # verbose mode. 18654092bac7SYacine Belkadi # TODO: always perform the check. 1866cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 18674092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 18684092bac7SYacine Belkadi } 18694092bac7SYacine Belkadi 187047bcacfdSMauro Carvalho Chehab # The function parser can be called with a typedef parameter. 187147bcacfdSMauro Carvalho Chehab # Handle it. 187247bcacfdSMauro Carvalho Chehab if ($return_type =~ /typedef/) { 187347bcacfdSMauro Carvalho Chehab output_declaration($declaration_name, 187447bcacfdSMauro Carvalho Chehab 'function', 187547bcacfdSMauro Carvalho Chehab {'function' => $declaration_name, 187647bcacfdSMauro Carvalho Chehab 'typedef' => 1, 187747bcacfdSMauro Carvalho Chehab 'module' => $modulename, 187847bcacfdSMauro Carvalho Chehab 'functiontype' => $return_type, 187947bcacfdSMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 188047bcacfdSMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 188147bcacfdSMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 188247bcacfdSMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 188347bcacfdSMauro Carvalho Chehab 'sections' => \%sections, 188447bcacfdSMauro Carvalho Chehab 'purpose' => $declaration_purpose 188547bcacfdSMauro Carvalho Chehab }); 188647bcacfdSMauro Carvalho Chehab } else { 18871da177e4SLinus Torvalds output_declaration($declaration_name, 18881da177e4SLinus Torvalds 'function', 18891da177e4SLinus Torvalds {'function' => $declaration_name, 18901da177e4SLinus Torvalds 'module' => $modulename, 18911da177e4SLinus Torvalds 'functiontype' => $return_type, 18921da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 18931da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 18941da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 18951da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 18961da177e4SLinus Torvalds 'sections' => \%sections, 18971da177e4SLinus Torvalds 'purpose' => $declaration_purpose 18981da177e4SLinus Torvalds }); 18991da177e4SLinus Torvalds } 190047bcacfdSMauro Carvalho Chehab} 19011da177e4SLinus Torvalds 19021da177e4SLinus Torvaldssub reset_state { 19031da177e4SLinus Torvalds $function = ""; 19041da177e4SLinus Torvalds %parameterdescs = (); 19051da177e4SLinus Torvalds %parametertypes = (); 19061da177e4SLinus Torvalds @parameterlist = (); 19071da177e4SLinus Torvalds %sections = (); 19081da177e4SLinus Torvalds @sectionlist = (); 1909a1d94aa5SRandy Dunlap $sectcheck = ""; 1910a1d94aa5SRandy Dunlap $struct_actual = ""; 19111da177e4SLinus Torvalds $prototype = ""; 19121da177e4SLinus Torvalds 191348af606aSJani Nikula $state = STATE_NORMAL; 191448af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 19151da177e4SLinus Torvalds} 19161da177e4SLinus Torvalds 191756afb0f8SJason Baronsub tracepoint_munge($) { 191856afb0f8SJason Baron my $file = shift; 191956afb0f8SJason Baron my $tracepointname = 0; 192056afb0f8SJason Baron my $tracepointargs = 0; 192156afb0f8SJason Baron 192256afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 192356afb0f8SJason Baron $tracepointname = $1; 192456afb0f8SJason Baron } 19253a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 19263a9089fdSJason Baron $tracepointname = $1; 19273a9089fdSJason Baron } 19283a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 19293a9089fdSJason Baron $tracepointname = $2; 19303a9089fdSJason Baron } 19313a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 193256afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 193356afb0f8SJason Baron $tracepointargs = $1; 193456afb0f8SJason Baron } 193556afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 1936d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 193756afb0f8SJason Baron "$prototype\n"; 193856afb0f8SJason Baron } else { 193956afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 194052042e2dSMauro Carvalho Chehab $identifier = "trace_$identifier"; 194156afb0f8SJason Baron } 194256afb0f8SJason Baron} 194356afb0f8SJason Baron 1944b4870bc5SRandy Dunlapsub syscall_munge() { 1945b4870bc5SRandy Dunlap my $void = 0; 1946b4870bc5SRandy Dunlap 19477c9aa015SMauro Carvalho Chehab $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's 1948b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 1949b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 1950b4870bc5SRandy Dunlap $void = 1; 1951b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 1952b4870bc5SRandy Dunlap } 1953b4870bc5SRandy Dunlap 1954b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 1955b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 1956b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 1957b4870bc5SRandy Dunlap } elsif ($void) { 1958b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 1959b4870bc5SRandy Dunlap } 1960b4870bc5SRandy Dunlap 1961b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 1962b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 1963b4870bc5SRandy Dunlap my $count = 0; 1964b4870bc5SRandy Dunlap my $len = length($prototype); 1965b4870bc5SRandy Dunlap if ($void) { 1966b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 1967b4870bc5SRandy Dunlap } 1968b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 1969b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 1970b4870bc5SRandy Dunlap $count++; 1971b4870bc5SRandy Dunlap if ($count % 2 == 1) { 1972b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 1973b4870bc5SRandy Dunlap } 1974b4870bc5SRandy Dunlap } 1975b4870bc5SRandy Dunlap } 1976b4870bc5SRandy Dunlap} 1977b4870bc5SRandy Dunlap 1978b7afa92bSDaniel Vettersub process_proto_function($$) { 19791da177e4SLinus Torvalds my $x = shift; 19801da177e4SLinus Torvalds my $file = shift; 19811da177e4SLinus Torvalds 198251f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 198351f5a0c8SRandy Dunlap 1984890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 19851da177e4SLinus Torvalds # do nothing 19861da177e4SLinus Torvalds } 19871da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 19881da177e4SLinus Torvalds $prototype .= $1; 19891da177e4SLinus Torvalds } 1990b4870bc5SRandy Dunlap 1991890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 19921da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 19931da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 19941da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 19957ae281b0SMauro Carvalho Chehab 19967ae281b0SMauro Carvalho Chehab # Handle prototypes for function pointers like: 19977ae281b0SMauro Carvalho Chehab # int (*pcs_config)(struct foo) 19987ae281b0SMauro Carvalho Chehab $prototype =~ s@^(\S+\s+)\(\s*\*(\S+)\)@$1$2@gos; 19997ae281b0SMauro Carvalho Chehab 2000b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 2001b4870bc5SRandy Dunlap syscall_munge(); 2002b4870bc5SRandy Dunlap } 20033a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 20043a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 20053a9089fdSJason Baron { 200656afb0f8SJason Baron tracepoint_munge($file); 200756afb0f8SJason Baron } 20081da177e4SLinus Torvalds dump_function($prototype, $file); 20091da177e4SLinus Torvalds reset_state(); 20101da177e4SLinus Torvalds } 20111da177e4SLinus Torvalds} 20121da177e4SLinus Torvalds 2013b7afa92bSDaniel Vettersub process_proto_type($$) { 20141da177e4SLinus Torvalds my $x = shift; 20151da177e4SLinus Torvalds my $file = shift; 20161da177e4SLinus Torvalds 20171da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 20181da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 20191da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 202051f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 202151f5a0c8SRandy Dunlap 20221da177e4SLinus Torvalds if ($x =~ /^#/) { 20231da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 20241da177e4SLinus Torvalds $x .= ";"; 20251da177e4SLinus Torvalds } 20261da177e4SLinus Torvalds 20271da177e4SLinus Torvalds while (1) { 2028673bb2dfSBen Hutchings if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) { 2029463a0fdcSMarkus Heiser if( length $prototype ) { 2030463a0fdcSMarkus Heiser $prototype .= " " 2031463a0fdcSMarkus Heiser } 20321da177e4SLinus Torvalds $prototype .= $1 . $2; 20331da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 20341da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 20351da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 20361da177e4SLinus Torvalds dump_declaration($prototype, $file); 20371da177e4SLinus Torvalds reset_state(); 20381da177e4SLinus Torvalds last; 20391da177e4SLinus Torvalds } 20401da177e4SLinus Torvalds $x = $3; 20411da177e4SLinus Torvalds } else { 20421da177e4SLinus Torvalds $prototype .= $x; 20431da177e4SLinus Torvalds last; 20441da177e4SLinus Torvalds } 20451da177e4SLinus Torvalds } 20461da177e4SLinus Torvalds} 20471da177e4SLinus Torvalds 20486b5b55f6SRandy Dunlap 20491ad560e4SJani Nikulasub map_filename($) { 20501ad560e4SJani Nikula my $file; 20511ad560e4SJani Nikula my ($orig_file) = @_; 20521ad560e4SJani Nikula 20531ad560e4SJani Nikula if (defined($ENV{'SRCTREE'})) { 20541ad560e4SJani Nikula $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 20551ad560e4SJani Nikula } else { 20561ad560e4SJani Nikula $file = $orig_file; 20571ad560e4SJani Nikula } 20581ad560e4SJani Nikula 20591ad560e4SJani Nikula if (defined($source_map{$file})) { 20601ad560e4SJani Nikula $file = $source_map{$file}; 20611ad560e4SJani Nikula } 20621ad560e4SJani Nikula 20631ad560e4SJani Nikula return $file; 20641ad560e4SJani Nikula} 20651ad560e4SJani Nikula 206688c2b57dSJani Nikulasub process_export_file($) { 206788c2b57dSJani Nikula my ($orig_file) = @_; 206888c2b57dSJani Nikula my $file = map_filename($orig_file); 206988c2b57dSJani Nikula 207088c2b57dSJani Nikula if (!open(IN,"<$file")) { 207188c2b57dSJani Nikula print STDERR "Error: Cannot open file $file\n"; 207288c2b57dSJani Nikula ++$errors; 207388c2b57dSJani Nikula return; 207488c2b57dSJani Nikula } 207588c2b57dSJani Nikula 207688c2b57dSJani Nikula while (<IN>) { 207788c2b57dSJani Nikula if (/$export_symbol/) { 2078eab795ddSMauro Carvalho Chehab next if (defined($nosymbol_table{$2})); 207988c2b57dSJani Nikula $function_table{$2} = 1; 208088c2b57dSJani Nikula } 208188c2b57dSJani Nikula } 208288c2b57dSJani Nikula 208388c2b57dSJani Nikula close(IN); 208488c2b57dSJani Nikula} 208588c2b57dSJani Nikula 208607048d13SJonathan Corbet# 208707048d13SJonathan Corbet# Parsers for the various processing states. 208807048d13SJonathan Corbet# 208907048d13SJonathan Corbet# STATE_NORMAL: looking for the /** to begin everything. 209007048d13SJonathan Corbet# 209107048d13SJonathan Corbetsub process_normal() { 20921da177e4SLinus Torvalds if (/$doc_start/o) { 209348af606aSJani Nikula $state = STATE_NAME; # next line is always the function name 2094850622dfSRandy Dunlap $in_doc_sect = 0; 20950b0f5f29SDaniel Vetter $declaration_start_line = $. + 1; 20961da177e4SLinus Torvalds } 209707048d13SJonathan Corbet} 209807048d13SJonathan Corbet 20993cac2bc4SJonathan Corbet# 21003cac2bc4SJonathan Corbet# STATE_NAME: Looking for the "name - description" line 21013cac2bc4SJonathan Corbet# 21023cac2bc4SJonathan Corbetsub process_name($$) { 21033cac2bc4SJonathan Corbet my $file = shift; 21041da177e4SLinus Torvalds my $descr; 21051da177e4SLinus Torvalds 21061da177e4SLinus Torvalds if (/$doc_block/o) { 210748af606aSJani Nikula $state = STATE_DOCBLOCK; 21081da177e4SLinus Torvalds $contents = ""; 21095ef09c96SMauro Carvalho Chehab $new_start_line = $.; 21100b0f5f29SDaniel Vetter 21111da177e4SLinus Torvalds if ( $1 eq "" ) { 21121da177e4SLinus Torvalds $section = $section_intro; 21131da177e4SLinus Torvalds } else { 21141da177e4SLinus Torvalds $section = $1; 21151da177e4SLinus Torvalds } 211652042e2dSMauro Carvalho Chehab } elsif (/$doc_decl/o) { 21171da177e4SLinus Torvalds $identifier = $1; 21183e58e839SAditya Srivastava my $is_kernel_comment = 0; 2119e86bdb24SAditya Srivastava my $decl_start = qr{$doc_com}; 2120f9bbc12cSAditya Srivastava # test for pointer declaration type, foo * bar() - desc 2121f9bbc12cSAditya Srivastava my $fn_type = qr{\w+\s*\*\s*}; 2122f9bbc12cSAditya Srivastava my $parenthesis = qr{\(\w*\)}; 2123f9bbc12cSAditya Srivastava my $decl_end = qr{[-:].*}; 2124e86bdb24SAditya Srivastava if (/^$decl_start([\w\s]+?)$parenthesis?\s*$decl_end?$/) { 21251da177e4SLinus Torvalds $identifier = $1; 21261da177e4SLinus Torvalds } 212752042e2dSMauro Carvalho Chehab if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) { 212852042e2dSMauro Carvalho Chehab $decl_type = $1; 212952042e2dSMauro Carvalho Chehab $identifier = $2; 21303e58e839SAditya Srivastava $is_kernel_comment = 1; 213152042e2dSMauro Carvalho Chehab } 2132f9bbc12cSAditya Srivastava # Look for foo() or static void foo() - description; or misspelt 2133f9bbc12cSAditya Srivastava # identifier 2134e86bdb24SAditya Srivastava elsif (/^$decl_start$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ || 2135e86bdb24SAditya Srivastava /^$decl_start$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) { 2136f9bbc12cSAditya Srivastava $identifier = $1; 2137f9bbc12cSAditya Srivastava $decl_type = 'function'; 2138f9bbc12cSAditya Srivastava $identifier =~ s/^define\s+//; 2139f9bbc12cSAditya Srivastava $is_kernel_comment = 1; 2140f9bbc12cSAditya Srivastava } 214152042e2dSMauro Carvalho Chehab $identifier =~ s/\s+$//; 21421da177e4SLinus Torvalds 214317b78717SJonathan Corbet $state = STATE_BODY; 21440b0f5f29SDaniel Vetter # if there's no @param blocks need to set up default section 21450b0f5f29SDaniel Vetter # here 21462f4ad40aSJani Nikula $contents = ""; 21472f4ad40aSJani Nikula $section = $section_default; 21480b0f5f29SDaniel Vetter $new_start_line = $. + 1; 214952042e2dSMauro Carvalho Chehab if (/[-:](.*)/) { 215051f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2151a21217daSRandy Dunlap $descr= $1; 2152a21217daSRandy Dunlap $descr =~ s/^\s*//; 2153a21217daSRandy Dunlap $descr =~ s/\s*$//; 215412ae6779SDaniel Santos $descr =~ s/\s+/ /g; 21550bba924cSJonathan Corbet $declaration_purpose = $descr; 215617b78717SJonathan Corbet $state = STATE_BODY_MAYBE; 21571da177e4SLinus Torvalds } else { 21581da177e4SLinus Torvalds $declaration_purpose = ""; 21591da177e4SLinus Torvalds } 216077cc23b8SRandy Dunlap 21613e58e839SAditya Srivastava if (!$is_kernel_comment) { 21623e58e839SAditya Srivastava print STDERR "${file}:$.: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst\n"; 21633e58e839SAditya Srivastava print STDERR $_; 21643e58e839SAditya Srivastava ++$warnings; 21653e58e839SAditya Srivastava $state = STATE_NORMAL; 21663e58e839SAditya Srivastava } 21673e58e839SAditya Srivastava 216877cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 2169d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: missing initial short description on line:\n"; 217077cc23b8SRandy Dunlap print STDERR $_; 217177cc23b8SRandy Dunlap ++$warnings; 217277cc23b8SRandy Dunlap } 217377cc23b8SRandy Dunlap 21740b54c2e3SMauro Carvalho Chehab if ($identifier eq "" && $decl_type ne "enum") { 217552042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: warning: wrong kernel-doc identifier on line:\n"; 217652042e2dSMauro Carvalho Chehab print STDERR $_; 217752042e2dSMauro Carvalho Chehab ++$warnings; 217852042e2dSMauro Carvalho Chehab $state = STATE_NORMAL; 21791da177e4SLinus Torvalds } 21801da177e4SLinus Torvalds 21811da177e4SLinus Torvalds if ($verbose) { 218252042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: info: Scanning doc for $decl_type $identifier\n"; 21831da177e4SLinus Torvalds } 21841da177e4SLinus Torvalds } else { 2185d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", 21861da177e4SLinus Torvalds " - I thought it was a doc line\n"; 21871da177e4SLinus Torvalds ++$warnings; 218848af606aSJani Nikula $state = STATE_NORMAL; 21891da177e4SLinus Torvalds } 21903cac2bc4SJonathan Corbet} 21913cac2bc4SJonathan Corbet 21923cac2bc4SJonathan Corbet 2193d742f24dSJonathan Corbet# 2194d742f24dSJonathan Corbet# STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment. 2195d742f24dSJonathan Corbet# 2196d742f24dSJonathan Corbetsub process_body($$) { 2197d742f24dSJonathan Corbet my $file = shift; 21983cac2bc4SJonathan Corbet 219943756e34SJonathan Neuschäfer # Until all named variable macro parameters are 220043756e34SJonathan Neuschäfer # documented using the bare name (`x`) rather than with 220143756e34SJonathan Neuschäfer # dots (`x...`), strip the dots: 220243756e34SJonathan Neuschäfer if ($section =~ /\w\.\.\.$/) { 220343756e34SJonathan Neuschäfer $section =~ s/\.\.\.$//; 220443756e34SJonathan Neuschäfer 220543756e34SJonathan Neuschäfer if ($verbose) { 220643756e34SJonathan Neuschäfer print STDERR "${file}:$.: warning: Variable macro arguments should be documented without dots\n"; 220743756e34SJonathan Neuschäfer ++$warnings; 220843756e34SJonathan Neuschäfer } 220943756e34SJonathan Neuschäfer } 221043756e34SJonathan Neuschäfer 22110d55d48bSMauro Carvalho Chehab if ($state == STATE_BODY_WITH_BLANK_LINE && /^\s*\*\s?\S/) { 22120d55d48bSMauro Carvalho Chehab dump_section($file, $section, $contents); 22130d55d48bSMauro Carvalho Chehab $section = $section_default; 22145ef09c96SMauro Carvalho Chehab $new_start_line = $.; 22150d55d48bSMauro Carvalho Chehab $contents = ""; 22160d55d48bSMauro Carvalho Chehab } 22170d55d48bSMauro Carvalho Chehab 2218f624adefSJani Nikula if (/$doc_sect/i) { # case insensitive for supported section names 22191da177e4SLinus Torvalds $newsection = $1; 22201da177e4SLinus Torvalds $newcontents = $2; 22211da177e4SLinus Torvalds 2222f624adefSJani Nikula # map the supported section names to the canonical names 2223f624adefSJani Nikula if ($newsection =~ m/^description$/i) { 2224f624adefSJani Nikula $newsection = $section_default; 2225f624adefSJani Nikula } elsif ($newsection =~ m/^context$/i) { 2226f624adefSJani Nikula $newsection = $section_context; 2227f624adefSJani Nikula } elsif ($newsection =~ m/^returns?$/i) { 2228f624adefSJani Nikula $newsection = $section_return; 2229f624adefSJani Nikula } elsif ($newsection =~ m/^\@return$/) { 2230f624adefSJani Nikula # special: @return is a section, not a param description 2231f624adefSJani Nikula $newsection = $section_return; 2232f624adefSJani Nikula } 2233f624adefSJani Nikula 2234792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 2235850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 2236d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: contents before sections\n"; 2237850622dfSRandy Dunlap ++$warnings; 2238850622dfSRandy Dunlap } 22390bba924cSJonathan Corbet dump_section($file, $section, $contents); 22401da177e4SLinus Torvalds $section = $section_default; 22411da177e4SLinus Torvalds } 22421da177e4SLinus Torvalds 2243850622dfSRandy Dunlap $in_doc_sect = 1; 224417b78717SJonathan Corbet $state = STATE_BODY; 22451da177e4SLinus Torvalds $contents = $newcontents; 22460b0f5f29SDaniel Vetter $new_start_line = $.; 22477c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 224805189497SRandy Dunlap $contents = substr($contents, 1); 224905189497SRandy Dunlap } 22500a726301SJani Nikula if ($contents ne "") { 22511da177e4SLinus Torvalds $contents .= "\n"; 22521da177e4SLinus Torvalds } 22531da177e4SLinus Torvalds $section = $newsection; 2254b7886de4SJani Nikula $leading_space = undef; 22551da177e4SLinus Torvalds } elsif (/$doc_end/) { 22564c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 22570bba924cSJonathan Corbet dump_section($file, $section, $contents); 22581da177e4SLinus Torvalds $section = $section_default; 22591da177e4SLinus Torvalds $contents = ""; 22601da177e4SLinus Torvalds } 226146b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 226246b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2263d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: suspicious ending line: $_"; 226446b958ebSRandy Dunlap ++$warnings; 226546b958ebSRandy Dunlap } 22661da177e4SLinus Torvalds 22671da177e4SLinus Torvalds $prototype = ""; 226848af606aSJani Nikula $state = STATE_PROTO; 22691da177e4SLinus Torvalds $brcount = 0; 22705ef09c96SMauro Carvalho Chehab $new_start_line = $. + 1; 22711da177e4SLinus Torvalds } elsif (/$doc_content/) { 22726423133bSJohannes Weiner if ($1 eq "") { 22730d55d48bSMauro Carvalho Chehab if ($section eq $section_context) { 22740bba924cSJonathan Corbet dump_section($file, $section, $contents); 22751da177e4SLinus Torvalds $section = $section_default; 22761da177e4SLinus Torvalds $contents = ""; 22770b0f5f29SDaniel Vetter $new_start_line = $.; 22780d55d48bSMauro Carvalho Chehab $state = STATE_BODY; 22791da177e4SLinus Torvalds } else { 22800d55d48bSMauro Carvalho Chehab if ($section ne $section_default) { 22810d55d48bSMauro Carvalho Chehab $state = STATE_BODY_WITH_BLANK_LINE; 22820d55d48bSMauro Carvalho Chehab } else { 22830d55d48bSMauro Carvalho Chehab $state = STATE_BODY; 22840d55d48bSMauro Carvalho Chehab } 22856423133bSJohannes Weiner $contents .= "\n"; 22866423133bSJohannes Weiner } 228717b78717SJonathan Corbet } elsif ($state == STATE_BODY_MAYBE) { 22886423133bSJohannes Weiner # Continued declaration purpose 22896423133bSJohannes Weiner chomp($declaration_purpose); 22900bba924cSJonathan Corbet $declaration_purpose .= " " . $1; 229112ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 22926423133bSJohannes Weiner } else { 2293b7886de4SJani Nikula my $cont = $1; 2294b7886de4SJani Nikula if ($section =~ m/^@/ || $section eq $section_context) { 2295b7886de4SJani Nikula if (!defined $leading_space) { 2296b7886de4SJani Nikula if ($cont =~ m/^(\s+)/) { 2297b7886de4SJani Nikula $leading_space = $1; 2298b7886de4SJani Nikula } else { 2299b7886de4SJani Nikula $leading_space = ""; 2300b7886de4SJani Nikula } 2301b7886de4SJani Nikula } 2302b7886de4SJani Nikula $cont =~ s/^$leading_space//; 2303b7886de4SJani Nikula } 2304b7886de4SJani Nikula $contents .= $cont . "\n"; 23051da177e4SLinus Torvalds } 23061da177e4SLinus Torvalds } else { 23071da177e4SLinus Torvalds # i dont know - bad line? ignore. 2308d40e1e65SBart Van Assche print STDERR "${file}:$.: warning: bad line: $_"; 23091da177e4SLinus Torvalds ++$warnings; 23101da177e4SLinus Torvalds } 2311d742f24dSJonathan Corbet} 2312d742f24dSJonathan Corbet 2313d742f24dSJonathan Corbet 2314cc794812SJonathan Corbet# 2315cc794812SJonathan Corbet# STATE_PROTO: reading a function/whatever prototype. 2316cc794812SJonathan Corbet# 2317cc794812SJonathan Corbetsub process_proto($$) { 2318cc794812SJonathan Corbet my $file = shift; 2319cc794812SJonathan Corbet 2320cc794812SJonathan Corbet if (/$doc_inline_oneline/) { 2321cc794812SJonathan Corbet $section = $1; 2322cc794812SJonathan Corbet $contents = $2; 2323cc794812SJonathan Corbet if ($contents ne "") { 2324cc794812SJonathan Corbet $contents .= "\n"; 2325cc794812SJonathan Corbet dump_section($file, $section, $contents); 2326cc794812SJonathan Corbet $section = $section_default; 2327cc794812SJonathan Corbet $contents = ""; 2328cc794812SJonathan Corbet } 2329cc794812SJonathan Corbet } elsif (/$doc_inline_start/) { 2330cc794812SJonathan Corbet $state = STATE_INLINE; 2331cc794812SJonathan Corbet $inline_doc_state = STATE_INLINE_NAME; 2332cc794812SJonathan Corbet } elsif ($decl_type eq 'function') { 2333cc794812SJonathan Corbet process_proto_function($_, $file); 2334cc794812SJonathan Corbet } else { 2335cc794812SJonathan Corbet process_proto_type($_, $file); 2336cc794812SJonathan Corbet } 2337cc794812SJonathan Corbet} 2338cc794812SJonathan Corbet 2339c17add56SJonathan Corbet# 2340c17add56SJonathan Corbet# STATE_DOCBLOCK: within a DOC: block. 2341c17add56SJonathan Corbet# 2342c17add56SJonathan Corbetsub process_docblock($$) { 2343c17add56SJonathan Corbet my $file = shift; 2344cc794812SJonathan Corbet 2345c17add56SJonathan Corbet if (/$doc_end/) { 2346c17add56SJonathan Corbet dump_doc_section($file, $section, $contents); 2347c17add56SJonathan Corbet $section = $section_default; 2348c17add56SJonathan Corbet $contents = ""; 2349c17add56SJonathan Corbet $function = ""; 2350c17add56SJonathan Corbet %parameterdescs = (); 2351c17add56SJonathan Corbet %parametertypes = (); 2352c17add56SJonathan Corbet @parameterlist = (); 2353c17add56SJonathan Corbet %sections = (); 2354c17add56SJonathan Corbet @sectionlist = (); 2355c17add56SJonathan Corbet $prototype = ""; 2356c17add56SJonathan Corbet $state = STATE_NORMAL; 2357c17add56SJonathan Corbet } elsif (/$doc_content/) { 2358c17add56SJonathan Corbet if ( $1 eq "" ) { 2359c17add56SJonathan Corbet $contents .= $blankline; 2360c17add56SJonathan Corbet } else { 2361c17add56SJonathan Corbet $contents .= $1 . "\n"; 2362c17add56SJonathan Corbet } 2363c17add56SJonathan Corbet } 2364d742f24dSJonathan Corbet} 2365d742f24dSJonathan Corbet 2366c17add56SJonathan Corbet# 2367c17add56SJonathan Corbet# STATE_INLINE: docbook comments within a prototype. 2368c17add56SJonathan Corbet# 2369c17add56SJonathan Corbetsub process_inline($$) { 2370c17add56SJonathan Corbet my $file = shift; 2371d742f24dSJonathan Corbet 2372a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 237348af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 2374a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 2375a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 23760b0f5f29SDaniel Vetter $new_start_line = $.; 2377a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 23787c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 2379a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 2380a4c6ebedSDanilo Cesar Lemes de Paula } 2381a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 2382a4c6ebedSDanilo Cesar Lemes de Paula } 238348af606aSJani Nikula $inline_doc_state = STATE_INLINE_TEXT; 2384a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 238548af606aSJani Nikula } elsif (/$doc_inline_end/) { 2386a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 23870bba924cSJonathan Corbet dump_section($file, $section, $contents); 2388a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 2389a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 2390a4c6ebedSDanilo Cesar Lemes de Paula } 239148af606aSJani Nikula $state = STATE_PROTO; 239248af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 2393a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 2394a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 239548af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_TEXT) { 2396a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 23976450c895SJani Nikula # nuke leading blank lines 23986450c895SJani Nikula if ($contents =~ /^\s*$/) { 23996450c895SJani Nikula $contents = ""; 24006450c895SJani Nikula } 240148af606aSJani Nikula } elsif ($inline_doc_state == STATE_INLINE_NAME) { 240248af606aSJani Nikula $inline_doc_state = STATE_INLINE_ERROR; 2403e7ca311eSDaniel Vetter print STDERR "${file}:$.: warning: "; 2404a4c6ebedSDanilo Cesar Lemes de Paula print STDERR "Incorrect use of kernel-doc format: $_"; 2405a4c6ebedSDanilo Cesar Lemes de Paula ++$warnings; 2406a4c6ebedSDanilo Cesar Lemes de Paula } 2407a4c6ebedSDanilo Cesar Lemes de Paula } 24080c9aa209SJani Nikula} 2409c17add56SJonathan Corbet 2410c17add56SJonathan Corbet 2411c17add56SJonathan Corbetsub process_file($) { 2412c17add56SJonathan Corbet my $file; 2413c17add56SJonathan Corbet my $initial_section_counter = $section_counter; 2414c17add56SJonathan Corbet my ($orig_file) = @_; 2415c17add56SJonathan Corbet 2416c17add56SJonathan Corbet $file = map_filename($orig_file); 2417c17add56SJonathan Corbet 2418dbe8ba00SMauro Carvalho Chehab if (!open(IN_FILE,"<$file")) { 2419c17add56SJonathan Corbet print STDERR "Error: Cannot open file $file\n"; 2420c17add56SJonathan Corbet ++$errors; 2421c17add56SJonathan Corbet return; 24221da177e4SLinus Torvalds } 2423c17add56SJonathan Corbet 2424c17add56SJonathan Corbet $. = 1; 2425c17add56SJonathan Corbet 2426c17add56SJonathan Corbet $section_counter = 0; 2427dbe8ba00SMauro Carvalho Chehab while (<IN_FILE>) { 2428c17add56SJonathan Corbet while (s/\\\s*$//) { 2429dbe8ba00SMauro Carvalho Chehab $_ .= <IN_FILE>; 2430c17add56SJonathan Corbet } 2431c17add56SJonathan Corbet # Replace tabs by spaces 2432c17add56SJonathan Corbet while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; 2433c17add56SJonathan Corbet # Hand this line to the appropriate state handler 2434c17add56SJonathan Corbet if ($state == STATE_NORMAL) { 2435c17add56SJonathan Corbet process_normal(); 2436c17add56SJonathan Corbet } elsif ($state == STATE_NAME) { 2437c17add56SJonathan Corbet process_name($file, $_); 24380d55d48bSMauro Carvalho Chehab } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE || 24390d55d48bSMauro Carvalho Chehab $state == STATE_BODY_WITH_BLANK_LINE) { 2440c17add56SJonathan Corbet process_body($file, $_); 2441c17add56SJonathan Corbet } elsif ($state == STATE_INLINE) { # scanning for inline parameters 2442c17add56SJonathan Corbet process_inline($file, $_); 2443cc794812SJonathan Corbet } elsif ($state == STATE_PROTO) { 2444cc794812SJonathan Corbet process_proto($file, $_); 244548af606aSJani Nikula } elsif ($state == STATE_DOCBLOCK) { 2446c17add56SJonathan Corbet process_docblock($file, $_); 24471da177e4SLinus Torvalds } 24481da177e4SLinus Torvalds } 2449c17add56SJonathan Corbet 2450c17add56SJonathan Corbet # Make sure we got something interesting. 2451b0d60bfbSJonathan Corbet if ($initial_section_counter == $section_counter && $ 2452b0d60bfbSJonathan Corbet output_mode ne "none") { 2453b0d60bfbSJonathan Corbet if ($output_selection == OUTPUT_INCLUDE) { 2454b0d60bfbSJonathan Corbet print STDERR "${file}:1: warning: '$_' not found\n" 2455b0d60bfbSJonathan Corbet for keys %function_table; 24563a025e1dSMatthew Wilcox } 2457b0d60bfbSJonathan Corbet else { 2458b0d60bfbSJonathan Corbet print STDERR "${file}:1: warning: no structured comments found\n"; 2459e946c43aSJohannes Berg } 24601da177e4SLinus Torvalds } 2461dbe8ba00SMauro Carvalho Chehab close IN_FILE; 24621da177e4SLinus Torvalds} 24638484baaaSRandy Dunlap 24648484baaaSRandy Dunlap 246593351d41SMauro Carvalho Chehabif ($output_mode eq "rst") { 246693351d41SMauro Carvalho Chehab get_sphinx_version() if (!$sphinx_major); 246793351d41SMauro Carvalho Chehab} 246893351d41SMauro Carvalho Chehab 24698484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 24708484baaaSRandy Dunlap 24718484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 24728484baaaSRandy Dunlap# using the s// operator. 24731ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 24744d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 24754d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 24764d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 24774d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 24788484baaaSRandy Dunlap} 24798484baaaSRandy Dunlap 24808484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 24818484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 24828484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 24838484baaaSRandy Dunlap my ($relname, $absname); 24848484baaaSRandy Dunlap while(<SOURCE_MAP>) { 24858484baaaSRandy Dunlap chop(); 24868484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 24878484baaaSRandy Dunlap $relname =~ s:^/+::; 24888484baaaSRandy Dunlap $source_map{$relname} = $absname; 24898484baaaSRandy Dunlap } 24908484baaaSRandy Dunlap close(SOURCE_MAP); 24918484baaaSRandy Dunlap} 24928484baaaSRandy Dunlap 249388c2b57dSJani Nikulaif ($output_selection == OUTPUT_EXPORTED || 249488c2b57dSJani Nikula $output_selection == OUTPUT_INTERNAL) { 2495c9b2cfb3SJani Nikula 2496c9b2cfb3SJani Nikula push(@export_file_list, @ARGV); 2497c9b2cfb3SJani Nikula 249888c2b57dSJani Nikula foreach (@export_file_list) { 249988c2b57dSJani Nikula chomp; 250088c2b57dSJani Nikula process_export_file($_); 250188c2b57dSJani Nikula } 250288c2b57dSJani Nikula} 250388c2b57dSJani Nikula 25048484baaaSRandy Dunlapforeach (@ARGV) { 25058484baaaSRandy Dunlap chomp; 25068484baaaSRandy Dunlap process_file($_); 25078484baaaSRandy Dunlap} 25088484baaaSRandy Dunlapif ($verbose && $errors) { 25098484baaaSRandy Dunlap print STDERR "$errors errors\n"; 25108484baaaSRandy Dunlap} 25118484baaaSRandy Dunlapif ($verbose && $warnings) { 25128484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 25138484baaaSRandy Dunlap} 25148484baaaSRandy Dunlap 25152c12c810SPierre-Louis Bossartif ($Werror && $warnings) { 25162c12c810SPierre-Louis Bossart print STDERR "$warnings warnings as Errors\n"; 25172c12c810SPierre-Louis Bossart exit($warnings); 25182c12c810SPierre-Louis Bossart} else { 25192c12c810SPierre-Louis Bossart exit($output_mode eq "none" ? 0 : $errors) 25202c12c810SPierre-Louis Bossart} 25212875f787STomasz Warniełło 25222875f787STomasz Warniełło__END__ 25232875f787STomasz Warniełło 25242875f787STomasz Warniełło=head1 OPTIONS 25252875f787STomasz Warniełło 25262875f787STomasz Warniełło=head2 Output format selection (mutually exclusive): 25272875f787STomasz Warniełło 25282875f787STomasz Warniełło=over 8 25292875f787STomasz Warniełło 25302875f787STomasz Warniełło=item -man 25312875f787STomasz Warniełło 25322875f787STomasz WarniełłoOutput troff manual page format. 25332875f787STomasz Warniełło 25342875f787STomasz Warniełło=item -rst 25352875f787STomasz Warniełło 25362875f787STomasz WarniełłoOutput reStructuredText format. This is the default. 25372875f787STomasz Warniełło 25382875f787STomasz Warniełło=item -none 25392875f787STomasz Warniełło 25402875f787STomasz WarniełłoDo not output documentation, only warnings. 25412875f787STomasz Warniełło 25422875f787STomasz Warniełło=back 25432875f787STomasz Warniełło 2544dd803b04STomasz Warniełło=head2 Output format modifiers 2545dd803b04STomasz Warniełło 2546dd803b04STomasz Warniełło=head3 reStructuredText only 2547dd803b04STomasz Warniełło 2548dd803b04STomasz Warniełło=over 8 2549dd803b04STomasz Warniełło 2550dd803b04STomasz Warniełło=item -sphinx-version VERSION 2551dd803b04STomasz Warniełło 2552dd803b04STomasz WarniełłoUse the ReST C domain dialect compatible with a specific Sphinx Version. 2553dd803b04STomasz Warniełło 2554dd803b04STomasz WarniełłoIf not specified, kernel-doc will auto-detect using the sphinx-build version 2555dd803b04STomasz Warniełłofound on PATH. 2556dd803b04STomasz Warniełło 2557dd803b04STomasz Warniełło=back 2558dd803b04STomasz Warniełło 25599c77f108STomasz Warniełło=head2 Output selection (mutually exclusive): 25609c77f108STomasz Warniełło 25619c77f108STomasz Warniełło=over 8 25629c77f108STomasz Warniełło 25639c77f108STomasz Warniełło=item -export 25649c77f108STomasz Warniełło 25659c77f108STomasz WarniełłoOnly output documentation for the symbols that have been exported using 25669c77f108STomasz WarniełłoEXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() in any input FILE or -export-file FILE. 25679c77f108STomasz Warniełło 25689c77f108STomasz Warniełło=item -internal 25699c77f108STomasz Warniełło 25709c77f108STomasz WarniełłoOnly output documentation for the symbols that have NOT been exported using 25719c77f108STomasz WarniełłoEXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() in any input FILE or -export-file FILE. 25729c77f108STomasz Warniełło 25739c77f108STomasz Warniełło=item -function NAME 25749c77f108STomasz Warniełło 25759c77f108STomasz WarniełłoOnly output documentation for the given function or DOC: section title. 25769c77f108STomasz WarniełłoAll other functions and DOC: sections are ignored. 25779c77f108STomasz Warniełło 25789c77f108STomasz WarniełłoMay be specified multiple times. 25799c77f108STomasz Warniełło 25809c77f108STomasz Warniełło=item -nosymbol NAME 25819c77f108STomasz Warniełło 25829c77f108STomasz WarniełłoExclude the specified symbol from the output documentation. 25839c77f108STomasz Warniełło 25849c77f108STomasz WarniełłoMay be specified multiple times. 25859c77f108STomasz Warniełło 25869c77f108STomasz Warniełło=back 25879c77f108STomasz Warniełło 2588c15de5a1STomasz Warniełło=head2 Output selection modifiers: 2589c15de5a1STomasz Warniełło 2590c15de5a1STomasz Warniełło=over 8 2591c15de5a1STomasz Warniełło 2592c15de5a1STomasz Warniełło=item -no-doc-sections 2593c15de5a1STomasz Warniełło 2594c15de5a1STomasz WarniełłoDo not output DOC: sections. 2595c15de5a1STomasz Warniełło 2596c15de5a1STomasz Warniełło=item -export-file FILE 2597c15de5a1STomasz Warniełło 2598c15de5a1STomasz WarniełłoSpecify an additional FILE in which to look for EXPORT_SYMBOL() and 2599c15de5a1STomasz WarniełłoEXPORT_SYMBOL_GPL(). 2600c15de5a1STomasz Warniełło 2601c15de5a1STomasz WarniełłoTo be used with -export or -internal. 2602c15de5a1STomasz Warniełło 2603c15de5a1STomasz WarniełłoMay be specified multiple times. 2604c15de5a1STomasz Warniełło 2605c15de5a1STomasz Warniełło=back 2606c15de5a1STomasz Warniełło 2607c15de5a1STomasz Warniełło=head3 reStructuredText only 2608c15de5a1STomasz Warniełło 2609c15de5a1STomasz Warniełło=over 8 2610c15de5a1STomasz Warniełło 2611c15de5a1STomasz Warniełło=item -enable-lineno 2612c15de5a1STomasz Warniełło 2613c15de5a1STomasz WarniełłoEnable output of #define LINENO lines. 2614c15de5a1STomasz Warniełło 2615c15de5a1STomasz Warniełło=back 2616c15de5a1STomasz Warniełło 2617834cf6b9STomasz Warniełło=head2 Other parameters: 2618834cf6b9STomasz Warniełło 2619834cf6b9STomasz Warniełło=over 8 2620834cf6b9STomasz Warniełło 2621834cf6b9STomasz Warniełło=item -h, -help 2622834cf6b9STomasz Warniełło 2623834cf6b9STomasz WarniełłoPrint this help. 2624834cf6b9STomasz Warniełło 2625834cf6b9STomasz Warniełło=item -v 2626834cf6b9STomasz Warniełło 2627834cf6b9STomasz WarniełłoVerbose output, more warnings and other information. 2628834cf6b9STomasz Warniełło 2629834cf6b9STomasz Warniełło=item -Werror 2630834cf6b9STomasz Warniełło 2631834cf6b9STomasz WarniełłoTreat warnings as errors. 2632834cf6b9STomasz Warniełło 2633834cf6b9STomasz Warniełło=back 2634834cf6b9STomasz Warniełło 26352875f787STomasz Warniełło=cut 2636