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. ## 152b306ecaSTomasz Warniełło# 162b306ecaSTomasz Warniełło# Copyright (C) 2022 Tomasz Warniełło (POD) 171da177e4SLinus Torvalds 1843caf1a6STomasz Warniełłouse Pod::Usage qw/pod2usage/; 1943caf1a6STomasz Warniełło 20a5cdaea5STomasz Warniełło=head1 NAME 21a5cdaea5STomasz Warniełło 22a5cdaea5STomasz Warniełłokernel-doc - Print formatted kernel documentation to stdout 23a5cdaea5STomasz Warniełło 24a5cdaea5STomasz Warniełło=head1 SYNOPSIS 25a5cdaea5STomasz Warniełło 26a5cdaea5STomasz Warniełło kernel-doc [-h] [-v] [-Werror] 27a5cdaea5STomasz Warniełło [ -man | 28a5cdaea5STomasz Warniełło -rst [-sphinx-version VERSION] [-enable-lineno] | 29a5cdaea5STomasz Warniełło -none 30a5cdaea5STomasz Warniełło ] 31a5cdaea5STomasz Warniełło [ 32a5cdaea5STomasz Warniełło -export | 33a5cdaea5STomasz Warniełło -internal | 34a5cdaea5STomasz Warniełło [-function NAME] ... | 35a5cdaea5STomasz Warniełło [-nosymbol NAME] ... 36a5cdaea5STomasz Warniełło ] 37a5cdaea5STomasz Warniełło [-no-doc-sections] 38a5cdaea5STomasz Warniełło [-export-file FILE] ... 39a5cdaea5STomasz Warniełło FILE ... 40a5cdaea5STomasz Warniełło 41a5cdaea5STomasz WarniełłoRun `kernel-doc -h` for details. 42a5cdaea5STomasz Warniełło 43f1583922STomasz Warniełło=head1 DESCRIPTION 44f1583922STomasz Warniełło 45f1583922STomasz WarniełłoRead C language source or header FILEs, extract embedded documentation comments, 46f1583922STomasz Warniełłoand print formatted documentation to standard output. 47f1583922STomasz Warniełło 48f1583922STomasz WarniełłoThe documentation comments are identified by the "/**" opening comment mark. 49f1583922STomasz Warniełło 50f1583922STomasz WarniełłoSee Documentation/doc-guide/kernel-doc.rst for the documentation comment syntax. 51f1583922STomasz Warniełło 52a5cdaea5STomasz Warniełło=cut 53a5cdaea5STomasz Warniełło 542875f787STomasz Warniełło# more perldoc at the end of the file 552875f787STomasz Warniełło 568484baaaSRandy Dunlap## init lots of data 578484baaaSRandy Dunlap 581da177e4SLinus Torvaldsmy $errors = 0; 591da177e4SLinus Torvaldsmy $warnings = 0; 605f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds# match expressions used to find embedded type information 63b97f193aSMauro Carvalho Chehabmy $type_constant = '\b``([^\`]+)``\b'; 64b97f193aSMauro Carvalho Chehabmy $type_constant2 = '\%([-_\w]+)'; 651da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 66bfd228c7SMike Rapoportmy $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; 67ee2aa759SMauro Carvalho Chehabmy $type_param_ref = '([\!]?)\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; 685219f18aSJonathan Corbetmy $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params 69346282dbSMauro Carvalho Chehabmy $type_fp_param2 = '\@(\w+->\S+)\(\)'; # Special RST handling for structs with func ptr params 701da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 71df31175bSPaolo Bonzinimy $type_enum = '\&(enum\s*([_\w]+))'; 72df31175bSPaolo Bonzinimy $type_struct = '\&(struct\s*([_\w]+))'; 73df31175bSPaolo Bonzinimy $type_typedef = '\&(typedef\s*([_\w]+))'; 74df31175bSPaolo Bonzinimy $type_union = '\&(union\s*([_\w]+))'; 755267dd35SPaolo Bonzinimy $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; 76df31175bSPaolo Bonzinimy $type_fallback = '\&([_\w]+)'; 77f3341dcfSJani Nikulamy $type_member_func = $type_member . '\(\)'; 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds# Output conversion substitutions. 801da177e4SLinus Torvalds# One for each output format 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds# these are pretty rough 834d732701SDanilo Cesar Lemes de Paulamy @highlights_man = ( 844d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 85b97f193aSMauro Carvalho Chehab [$type_constant2, "\$1"], 864d732701SDanilo Cesar Lemes de Paula [$type_func, "\\\\fB\$1\\\\fP"], 87df31175bSPaolo Bonzini [$type_enum, "\\\\fI\$1\\\\fP"], 884d732701SDanilo Cesar Lemes de Paula [$type_struct, "\\\\fI\$1\\\\fP"], 89df31175bSPaolo Bonzini [$type_typedef, "\\\\fI\$1\\\\fP"], 90df31175bSPaolo Bonzini [$type_union, "\\\\fI\$1\\\\fP"], 915267dd35SPaolo Bonzini [$type_param, "\\\\fI\$1\\\\fP"], 92ee2aa759SMauro Carvalho Chehab [$type_param_ref, "\\\\fI\$1\$2\\\\fP"], 93df31175bSPaolo Bonzini [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], 94df31175bSPaolo Bonzini [$type_fallback, "\\\\fI\$1\\\\fP"] 954d732701SDanilo Cesar Lemes de Paula ); 961da177e4SLinus Torvaldsmy $blankline_man = ""; 971da177e4SLinus Torvalds 98c0d1b6eeSJonathan Corbet# rst-mode 99c0d1b6eeSJonathan Corbetmy @highlights_rst = ( 100c0d1b6eeSJonathan Corbet [$type_constant, "``\$1``"], 101b97f193aSMauro Carvalho Chehab [$type_constant2, "``\$1``"], 102f3341dcfSJani Nikula # Note: need to escape () to avoid func matching later 1035267dd35SPaolo Bonzini [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], 1045267dd35SPaolo Bonzini [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], 1055219f18aSJonathan Corbet [$type_fp_param, "**\$1\\\\(\\\\)**"], 106346282dbSMauro Carvalho Chehab [$type_fp_param2, "**\$1\\\\(\\\\)**"], 107344fdb28SJonathan Corbet [$type_func, "\$1()"], 108df31175bSPaolo Bonzini [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], 109df31175bSPaolo Bonzini [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], 110df31175bSPaolo Bonzini [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], 111df31175bSPaolo Bonzini [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], 112a7291e7eSJani Nikula # in rst this can refer to any type 113df31175bSPaolo Bonzini [$type_fallback, "\\:c\\:type\\:`\$1`"], 114ee2aa759SMauro Carvalho Chehab [$type_param_ref, "**\$1\$2**"] 115c0d1b6eeSJonathan Corbet ); 116c0d1b6eeSJonathan Corbetmy $blankline_rst = "\n"; 117c0d1b6eeSJonathan Corbet 1181da177e4SLinus Torvalds# read arguments 1191da177e4SLinus Torvaldsif ($#ARGV == -1) { 12043caf1a6STomasz Warniełło pod2usage( 12143caf1a6STomasz Warniełło -message => "No arguments!\n", 12243caf1a6STomasz Warniełło -exitval => 1, 12343caf1a6STomasz Warniełło -verbose => 99, 12443caf1a6STomasz Warniełło -sections => 'SYNOPSIS', 12543caf1a6STomasz Warniełło -output => \*STDERR, 12643caf1a6STomasz Warniełło ); 1271da177e4SLinus Torvalds} 1281da177e4SLinus Torvalds 1298484baaaSRandy Dunlapmy $kernelversion; 13093351d41SMauro Carvalho Chehabmy ($sphinx_major, $sphinx_minor, $sphinx_patch); 131efa44475SMauro Carvalho Chehab 1328484baaaSRandy Dunlapmy $dohighlight = ""; 1338484baaaSRandy Dunlap 1341da177e4SLinus Torvaldsmy $verbose = 0; 1352c12c810SPierre-Louis Bossartmy $Werror = 0; 136bdfe2be3SMauro Carvalho Chehabmy $output_mode = "rst"; 137e314ba31SDaniel Santosmy $output_preformatted = 0; 1384b44595aSJohannes Bergmy $no_doc_sections = 0; 1390b0f5f29SDaniel Vettermy $enable_lineno = 0; 140bdfe2be3SMauro Carvalho Chehabmy @highlights = @highlights_rst; 141bdfe2be3SMauro Carvalho Chehabmy $blankline = $blankline_rst; 1421da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 143b6c3f456SJani Nikula 144b6c3f456SJani Nikulause constant { 145b6c3f456SJani Nikula OUTPUT_ALL => 0, # output all symbols and doc sections 146b6c3f456SJani Nikula OUTPUT_INCLUDE => 1, # output only specified symbols 147eab795ddSMauro Carvalho Chehab OUTPUT_EXPORTED => 2, # output exported symbols 148eab795ddSMauro Carvalho Chehab OUTPUT_INTERNAL => 3, # output non-exported symbols 149b6c3f456SJani Nikula}; 150b6c3f456SJani Nikulamy $output_selection = OUTPUT_ALL; 151b0d60bfbSJonathan Corbetmy $show_not_found = 0; # No longer used 152b2c4105bSBen Hutchings 15388c2b57dSJani Nikulamy @export_file_list; 15488c2b57dSJani Nikula 155b2c4105bSBen Hutchingsmy @build_time; 156b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 157b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 158b2c4105bSBen Hutchings @build_time = gmtime($seconds); 159b2c4105bSBen Hutchings} else { 160b2c4105bSBen Hutchings @build_time = localtime; 161b2c4105bSBen Hutchings} 162b2c4105bSBen Hutchings 1631da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 1641da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 165b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 166b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 1671da177e4SLinus Torvalds 1688484baaaSRandy Dunlap# Essentially these are globals. 169b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 170b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 1711da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 1721da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 173eab795ddSMauro Carvalho Chehabmy %nosymbol_table = (); 1740b0f5f29SDaniel Vettermy $declaration_start_line; 1751da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 1761c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 1771da177e4SLinus Torvalds 178*c0d3b831SMasahiro Yamadaif (defined($ENV{'KBUILD_VERBOSE'}) && $ENV{'KBUILD_VERBOSE'} =~ '1') { 179*c0d3b831SMasahiro Yamada $verbose = 1; 180bd0e88e5SRandy Dunlap} 181bd0e88e5SRandy Dunlap 1822c12c810SPierre-Louis Bossartif (defined($ENV{'KCFLAGS'})) { 1832c12c810SPierre-Louis Bossart my $kcflags = "$ENV{'KCFLAGS'}"; 1842c12c810SPierre-Louis Bossart 1852c12c810SPierre-Louis Bossart if ($kcflags =~ /Werror/) { 1862c12c810SPierre-Louis Bossart $Werror = 1; 1872c12c810SPierre-Louis Bossart } 1882c12c810SPierre-Louis Bossart} 1892c12c810SPierre-Louis Bossart 190bed4ed30SLaurent Pinchartif (defined($ENV{'KDOC_WERROR'})) { 191bed4ed30SLaurent Pinchart $Werror = "$ENV{'KDOC_WERROR'}"; 192bed4ed30SLaurent Pinchart} 193bed4ed30SLaurent Pinchart 1941da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 1951da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 19693431e06SAlexander A. Klimov# https://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 1971da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 1981da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 1991da177e4SLinus Torvalds# into html. 2001da177e4SLinus Torvaldsmy $section_counter = 0; 2011da177e4SLinus Torvalds 2021da177e4SLinus Torvaldsmy $lineprefix=""; 2031da177e4SLinus Torvalds 20448af606aSJani Nikula# Parser states 20548af606aSJani Nikulause constant { 20648af606aSJani Nikula STATE_NORMAL => 0, # normal code 20748af606aSJani Nikula STATE_NAME => 1, # looking for function name 20817b78717SJonathan Corbet STATE_BODY_MAYBE => 2, # body - or maybe more description 20917b78717SJonathan Corbet STATE_BODY => 3, # the body of the comment 2100d55d48bSMauro Carvalho Chehab STATE_BODY_WITH_BLANK_LINE => 4, # the body, which has a blank line 2110d55d48bSMauro Carvalho Chehab STATE_PROTO => 5, # scanning prototype 2120d55d48bSMauro Carvalho Chehab STATE_DOCBLOCK => 6, # documentation block 2130d55d48bSMauro Carvalho Chehab STATE_INLINE => 7, # gathering doc outside main block 21448af606aSJani Nikula}; 2151da177e4SLinus Torvaldsmy $state; 216850622dfSRandy Dunlapmy $in_doc_sect; 217d742f24dSJonathan Corbetmy $leading_space; 2181da177e4SLinus Torvalds 21948af606aSJani Nikula# Inline documentation state 22048af606aSJani Nikulause constant { 22148af606aSJani Nikula STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 22248af606aSJani Nikula STATE_INLINE_NAME => 1, # looking for member name (@foo:) 22348af606aSJani Nikula STATE_INLINE_TEXT => 2, # looking for member documentation 22448af606aSJani Nikula STATE_INLINE_END => 3, # done 22548af606aSJani Nikula STATE_INLINE_ERROR => 4, # error - Comment without header was found. 22648af606aSJani Nikula # Spit a warning as it's not 227a4c6ebedSDanilo Cesar Lemes de Paula # proper kernel-doc and ignore the rest. 22848af606aSJani Nikula}; 22948af606aSJani Nikulamy $inline_doc_state; 230a4c6ebedSDanilo Cesar Lemes de Paula 2311da177e4SLinus Torvalds#declaration types: can be 2321da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 2331da177e4SLinus Torvaldsmy $decl_type; 2341da177e4SLinus Torvalds 23552042e2dSMauro Carvalho Chehab# Name of the kernel-doc identifier for non-DOC markups 23652042e2dSMauro Carvalho Chehabmy $identifier; 23752042e2dSMauro Carvalho Chehab 2381da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 2391da177e4SLinus Torvaldsmy $doc_end = '\*/'; 2401da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 24112ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 2421da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 243f624adefSJani Nikula# @params and a strictly limited set of supported section names 244212209cfSJonathan Corbet# Specifically: 245212209cfSJonathan Corbet# Match @word: 246212209cfSJonathan Corbet# @...: 247212209cfSJonathan Corbet# @{section-name}: 248212209cfSJonathan Corbet# while trying to not match literal block starts like "example::" 249212209cfSJonathan Corbet# 2508569de68SJonathan Corbetmy $doc_sect = $doc_com . 251212209cfSJonathan Corbet '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:([^:].*)?$'; 25212ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 2531da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 25448af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$'; 255fe7bc493SMauro Carvalho Chehabmy $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)'; 25648af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$'; 2570c9aa209SJani Nikulamy $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; 25886ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 259632ce137SJason Gunthorpemy $export_symbol_ns = '^\s*EXPORT_SYMBOL_NS(_GPL)?\s*\(\s*(\w+)\s*,\s*\w+\)\s*;'; 260e86bdb24SAditya Srivastavamy $function_pointer = qr{([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)}; 261e86bdb24SAditya Srivastavamy $attribute = qr{__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)}i; 2621da177e4SLinus Torvalds 2631da177e4SLinus Torvaldsmy %parameterdescs; 2640b0f5f29SDaniel Vettermy %parameterdesc_start_lines; 2651da177e4SLinus Torvaldsmy @parameterlist; 2661da177e4SLinus Torvaldsmy %sections; 2671da177e4SLinus Torvaldsmy @sectionlist; 2680b0f5f29SDaniel Vettermy %section_start_lines; 269a1d94aa5SRandy Dunlapmy $sectcheck; 270a1d94aa5SRandy Dunlapmy $struct_actual; 2711da177e4SLinus Torvalds 2721da177e4SLinus Torvaldsmy $contents = ""; 2730b0f5f29SDaniel Vettermy $new_start_line = 0; 274f624adefSJani Nikula 275f624adefSJani Nikula# the canonical section names. see also $doc_sect above. 2761da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 2771da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 2781da177e4SLinus Torvaldsmy $section = $section_default; 2791da177e4SLinus Torvaldsmy $section_context = "Context"; 2804092bac7SYacine Belkadimy $section_return = "Return"; 2811da177e4SLinus Torvalds 2821da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 2831da177e4SLinus Torvalds 2841da177e4SLinus Torvaldsreset_state(); 2851da177e4SLinus Torvalds 286b031ac4eSMauro Carvalho Chehabwhile ($ARGV[0] =~ m/^--?(.*)/) { 287b031ac4eSMauro Carvalho Chehab my $cmd = $1; 288b031ac4eSMauro Carvalho Chehab shift @ARGV; 289b031ac4eSMauro Carvalho Chehab if ($cmd eq "man") { 2901da177e4SLinus Torvalds $output_mode = "man"; 2914d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 2921da177e4SLinus Torvalds $blankline = $blankline_man; 293b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "rst") { 294c0d1b6eeSJonathan Corbet $output_mode = "rst"; 295c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 296c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 297b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "none") { 2983a025e1dSMatthew Wilcox $output_mode = "none"; 299b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document 3001da177e4SLinus Torvalds $modulename = shift @ARGV; 301b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "function") { # to only output specific functions 302b6c3f456SJani Nikula $output_selection = OUTPUT_INCLUDE; 3031da177e4SLinus Torvalds $function = shift @ARGV; 3041da177e4SLinus Torvalds $function_table{$function} = 1; 305eab795ddSMauro Carvalho Chehab } elsif ($cmd eq "nosymbol") { # Exclude specific symbols 306eab795ddSMauro Carvalho Chehab my $symbol = shift @ARGV; 307eab795ddSMauro Carvalho Chehab $nosymbol_table{$symbol} = 1; 308b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export") { # only exported symbols 309b6c3f456SJani Nikula $output_selection = OUTPUT_EXPORTED; 310da9726ecSJani Nikula %function_table = (); 311b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "internal") { # only non-exported symbols 312b6c3f456SJani Nikula $output_selection = OUTPUT_INTERNAL; 313da9726ecSJani Nikula %function_table = (); 314b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export-file") { 31588c2b57dSJani Nikula my $file = shift @ARGV; 31688c2b57dSJani Nikula push(@export_file_list, $file); 317b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "v") { 3181da177e4SLinus Torvalds $verbose = 1; 3192c12c810SPierre-Louis Bossart } elsif ($cmd eq "Werror") { 3202c12c810SPierre-Louis Bossart $Werror = 1; 321b031ac4eSMauro Carvalho Chehab } elsif (($cmd eq "h") || ($cmd eq "help")) { 322252b47daSTomasz Warniełło pod2usage(-exitval => 0, -verbose => 2); 323b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'no-doc-sections') { 3244b44595aSJohannes Berg $no_doc_sections = 1; 325b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'enable-lineno') { 3260b0f5f29SDaniel Vetter $enable_lineno = 1; 327b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'show-not-found') { 328b0d60bfbSJonathan Corbet $show_not_found = 1; # A no-op but don't fail 32993351d41SMauro Carvalho Chehab } elsif ($cmd eq "sphinx-version") { 33093351d41SMauro Carvalho Chehab my $ver_string = shift @ARGV; 33193351d41SMauro Carvalho Chehab if ($ver_string =~ m/^(\d+)(\.\d+)?(\.\d+)?/) { 33293351d41SMauro Carvalho Chehab $sphinx_major = $1; 33393351d41SMauro Carvalho Chehab if (defined($2)) { 33493351d41SMauro Carvalho Chehab $sphinx_minor = substr($2,1); 33593351d41SMauro Carvalho Chehab } else { 33693351d41SMauro Carvalho Chehab $sphinx_minor = 0; 33793351d41SMauro Carvalho Chehab } 33893351d41SMauro Carvalho Chehab if (defined($3)) { 33993351d41SMauro Carvalho Chehab $sphinx_patch = substr($3,1) 34093351d41SMauro Carvalho Chehab } else { 34193351d41SMauro Carvalho Chehab $sphinx_patch = 0; 34293351d41SMauro Carvalho Chehab } 34393351d41SMauro Carvalho Chehab } else { 34493351d41SMauro Carvalho Chehab die "Sphinx version should either major.minor or major.minor.patch format\n"; 34593351d41SMauro Carvalho Chehab } 346b031ac4eSMauro Carvalho Chehab } else { 347b031ac4eSMauro Carvalho Chehab # Unknown argument 34843caf1a6STomasz Warniełło pod2usage( 34943caf1a6STomasz Warniełło -message => "Argument unknown!\n", 35043caf1a6STomasz Warniełło -exitval => 1, 35143caf1a6STomasz Warniełło -verbose => 99, 35243caf1a6STomasz Warniełło -sections => 'SYNOPSIS', 35343caf1a6STomasz Warniełło -output => \*STDERR, 35443caf1a6STomasz Warniełło ); 355e334f873SAkira Yokosawa } 356e334f873SAkira Yokosawa if ($#ARGV < 0){ 357e334f873SAkira Yokosawa pod2usage( 358e334f873SAkira Yokosawa -message => "FILE argument missing\n", 359e334f873SAkira Yokosawa -exitval => 1, 360e334f873SAkira Yokosawa -verbose => 99, 361e334f873SAkira Yokosawa -sections => 'SYNOPSIS', 362e334f873SAkira Yokosawa -output => \*STDERR, 363e334f873SAkira Yokosawa ); 3641da177e4SLinus Torvalds } 3651da177e4SLinus Torvalds} 3661da177e4SLinus Torvalds 3678484baaaSRandy Dunlap# continue execution near EOF; 3688484baaaSRandy Dunlap 369efa44475SMauro Carvalho Chehab# The C domain dialect changed on Sphinx 3. So, we need to check the 370efa44475SMauro Carvalho Chehab# version in order to produce the right tags. 371efa44475SMauro Carvalho Chehabsub findprog($) 372efa44475SMauro Carvalho Chehab{ 373efa44475SMauro Carvalho Chehab foreach(split(/:/, $ENV{PATH})) { 374efa44475SMauro Carvalho Chehab return "$_/$_[0]" if(-x "$_/$_[0]"); 375efa44475SMauro Carvalho Chehab } 376efa44475SMauro Carvalho Chehab} 377efa44475SMauro Carvalho Chehab 378efa44475SMauro Carvalho Chehabsub get_sphinx_version() 379efa44475SMauro Carvalho Chehab{ 380efa44475SMauro Carvalho Chehab my $ver; 381efa44475SMauro Carvalho Chehab 382efa44475SMauro Carvalho Chehab my $cmd = "sphinx-build"; 383efa44475SMauro Carvalho Chehab if (!findprog($cmd)) { 384efa44475SMauro Carvalho Chehab my $cmd = "sphinx-build3"; 38593351d41SMauro Carvalho Chehab if (!findprog($cmd)) { 38693351d41SMauro Carvalho Chehab $sphinx_major = 1; 38793351d41SMauro Carvalho Chehab $sphinx_minor = 2; 38893351d41SMauro Carvalho Chehab $sphinx_patch = 0; 38993351d41SMauro Carvalho Chehab printf STDERR "Warning: Sphinx version not found. Using default (Sphinx version %d.%d.%d)\n", 39093351d41SMauro Carvalho Chehab $sphinx_major, $sphinx_minor, $sphinx_patch; 39193351d41SMauro Carvalho Chehab return; 39293351d41SMauro Carvalho Chehab } 393efa44475SMauro Carvalho Chehab } 394efa44475SMauro Carvalho Chehab 395efa44475SMauro Carvalho Chehab open IN, "$cmd --version 2>&1 |"; 396efa44475SMauro Carvalho Chehab while (<IN>) { 397efa44475SMauro Carvalho Chehab if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) { 39893351d41SMauro Carvalho Chehab $sphinx_major = $1; 39993351d41SMauro Carvalho Chehab $sphinx_minor = $2; 40093351d41SMauro Carvalho Chehab $sphinx_patch = $3; 401efa44475SMauro Carvalho Chehab last; 402efa44475SMauro Carvalho Chehab } 403efa44475SMauro Carvalho Chehab # Sphinx 1.2.x uses a different format 404efa44475SMauro Carvalho Chehab if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+)$/) { 40593351d41SMauro Carvalho Chehab $sphinx_major = $1; 40693351d41SMauro Carvalho Chehab $sphinx_minor = $2; 40793351d41SMauro Carvalho Chehab $sphinx_patch = $3; 408efa44475SMauro Carvalho Chehab last; 409efa44475SMauro Carvalho Chehab } 410efa44475SMauro Carvalho Chehab } 411efa44475SMauro Carvalho Chehab close IN; 412efa44475SMauro Carvalho Chehab} 413efa44475SMauro Carvalho Chehab 41453f049faSBorislav Petkov# get kernel version from env 41553f049faSBorislav Petkovsub get_kernel_version() { 4161b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 41753f049faSBorislav Petkov 41853f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 41953f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 42053f049faSBorislav Petkov } 42153f049faSBorislav Petkov return $version; 42253f049faSBorislav Petkov} 4231da177e4SLinus Torvalds 4240b0f5f29SDaniel Vetter# 4250b0f5f29SDaniel Vettersub print_lineno { 4260b0f5f29SDaniel Vetter my $lineno = shift; 4270b0f5f29SDaniel Vetter if ($enable_lineno && defined($lineno)) { 428b79dfef0SMauro Carvalho Chehab print ".. LINENO " . $lineno . "\n"; 4290b0f5f29SDaniel Vetter } 4300b0f5f29SDaniel Vetter} 431df4bf98eSNiklas Söderlund 432df4bf98eSNiklas Söderlundsub emit_warning { 433df4bf98eSNiklas Söderlund my $location = shift; 434df4bf98eSNiklas Söderlund my $msg = shift; 435df4bf98eSNiklas Söderlund print STDERR "$location: warning: $msg"; 436df4bf98eSNiklas Söderlund ++$warnings; 437df4bf98eSNiklas Söderlund} 4381da177e4SLinus Torvalds## 4391da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 4401da177e4SLinus Torvalds# 4411da177e4SLinus Torvaldssub dump_section { 44294dc7ad5SRandy Dunlap my $file = shift; 4431da177e4SLinus Torvalds my $name = shift; 4441da177e4SLinus Torvalds my $contents = join "\n", @_; 4451da177e4SLinus Torvalds 44613901ef2SJani Nikula if ($name =~ m/$type_param/) { 4471da177e4SLinus Torvalds $name = $1; 4481da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 449a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 4500b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 4510b0f5f29SDaniel Vetter $new_start_line = 0; 452ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 453ced69090SRandy Dunlap $name = "..."; 454ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 455a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 4560b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 4570b0f5f29SDaniel Vetter $new_start_line = 0; 4581da177e4SLinus Torvalds } else { 45994dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 46095b6be9dSJani Nikula # Only warn on user specified duplicate section names. 46195b6be9dSJani Nikula if ($name ne $section_default) { 462df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "duplicate section name '$name'\n"); 46395b6be9dSJani Nikula } 46432217761SJani Nikula $sections{$name} .= $contents; 46532217761SJani Nikula } else { 4661da177e4SLinus Torvalds $sections{$name} = $contents; 4671da177e4SLinus Torvalds push @sectionlist, $name; 4680b0f5f29SDaniel Vetter $section_start_lines{$name} = $new_start_line; 4690b0f5f29SDaniel Vetter $new_start_line = 0; 4701da177e4SLinus Torvalds } 4711da177e4SLinus Torvalds } 47232217761SJani Nikula} 4731da177e4SLinus Torvalds 4741da177e4SLinus Torvalds## 475b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 476b112e0f7SJohannes Berg# 477b112e0f7SJohannes Bergsub dump_doc_section { 47894dc7ad5SRandy Dunlap my $file = shift; 479b112e0f7SJohannes Berg my $name = shift; 480b112e0f7SJohannes Berg my $contents = join "\n", @_; 481b112e0f7SJohannes Berg 4824b44595aSJohannes Berg if ($no_doc_sections) { 4834b44595aSJohannes Berg return; 4844b44595aSJohannes Berg } 4854b44595aSJohannes Berg 486eab795ddSMauro Carvalho Chehab return if (defined($nosymbol_table{$name})); 487eab795ddSMauro Carvalho Chehab 488b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 489eab795ddSMauro Carvalho Chehab (($output_selection == OUTPUT_INCLUDE) && 490eab795ddSMauro Carvalho Chehab defined($function_table{$name}))) 491b112e0f7SJohannes Berg { 49294dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 493b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 494b112e0f7SJohannes Berg 'sections' => \%sections, 495b112e0f7SJohannes Berg 'module' => $modulename, 496b6c3f456SJani Nikula 'content-only' => ($output_selection != OUTPUT_ALL), }); 497b112e0f7SJohannes Berg } 498b112e0f7SJohannes Berg} 499b112e0f7SJohannes Berg 500b112e0f7SJohannes Berg## 5011da177e4SLinus Torvalds# output function 5021da177e4SLinus Torvalds# 5031da177e4SLinus Torvalds# parameterdescs, a hash. 5041da177e4SLinus Torvalds# function => "function name" 5051da177e4SLinus Torvalds# parameterlist => @list of parameters 5061da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 5071da177e4SLinus Torvalds# sectionlist => @list of sections 508a21217daSRandy Dunlap# sections => %section descriptions 5091da177e4SLinus Torvalds# 5101da177e4SLinus Torvalds 5111da177e4SLinus Torvaldssub output_highlight { 5121da177e4SLinus Torvalds my $contents = join "\n",@_; 5131da177e4SLinus Torvalds my $line; 5141da177e4SLinus Torvalds 5151da177e4SLinus Torvalds# DEBUG 5161da177e4SLinus Torvalds# if (!defined $contents) { 5171da177e4SLinus Torvalds# use Carp; 5181da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 5191da177e4SLinus Torvalds# } 5201da177e4SLinus Torvalds 5213eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 5221da177e4SLinus Torvalds eval $dohighlight; 5231da177e4SLinus Torvalds die $@ if $@; 5243eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 5253eb014a1SRandy Dunlap 5261da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 52712ae6779SDaniel Santos if (! $output_preformatted) { 52812ae6779SDaniel Santos $line =~ s/^\s*//; 52912ae6779SDaniel Santos } 5301da177e4SLinus Torvalds if ($line eq ""){ 531e314ba31SDaniel Santos if (! $output_preformatted) { 5320bba924cSJonathan Corbet print $lineprefix, $blankline; 533e314ba31SDaniel Santos } 5341da177e4SLinus Torvalds } else { 535cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 536cdccb316SRandy Dunlap print "\\&$line"; 537cdccb316SRandy Dunlap } else { 5381da177e4SLinus Torvalds print $lineprefix, $line; 5391da177e4SLinus Torvalds } 540cdccb316SRandy Dunlap } 5411da177e4SLinus Torvalds print "\n"; 5421da177e4SLinus Torvalds } 5431da177e4SLinus Torvalds} 5441da177e4SLinus Torvalds 5451da177e4SLinus Torvalds## 5461da177e4SLinus Torvalds# output function in man 5471da177e4SLinus Torvaldssub output_function_man(%) { 5481da177e4SLinus Torvalds my %args = %{$_[0]}; 5491da177e4SLinus Torvalds my ($parameter, $section); 5501da177e4SLinus Torvalds my $count; 5511da177e4SLinus Torvalds 5521da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 5531da177e4SLinus Torvalds 5541da177e4SLinus Torvalds print ".SH NAME\n"; 5551da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 5561da177e4SLinus Torvalds 5571da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 558a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 5591da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 560a21217daSRandy Dunlap } else { 561a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 562a21217daSRandy Dunlap } 5631da177e4SLinus Torvalds $count = 0; 5641da177e4SLinus Torvalds my $parenth = "("; 5651da177e4SLinus Torvalds my $post = ","; 5661da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 5671da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 5681da177e4SLinus Torvalds $post = ");"; 5691da177e4SLinus Torvalds } 5701da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 571e86bdb24SAditya Srivastava if ($type =~ m/$function_pointer/) { 5721da177e4SLinus Torvalds # pointer-to-function 573ed8348e2SMauro Carvalho Chehab print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n"; 5741da177e4SLinus Torvalds } else { 5751da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 576ed8348e2SMauro Carvalho Chehab print ".BI \"" . $parenth . $type . "\" " . " \"" . $post . "\"\n"; 5771da177e4SLinus Torvalds } 5781da177e4SLinus Torvalds $count++; 5791da177e4SLinus Torvalds $parenth = ""; 5801da177e4SLinus Torvalds } 5811da177e4SLinus Torvalds 5821da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 5831da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 5841da177e4SLinus Torvalds my $parameter_name = $parameter; 5851da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 5861da177e4SLinus Torvalds 5871da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 5881da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 5891da177e4SLinus Torvalds } 5901da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 5911da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 5921da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 5931da177e4SLinus Torvalds } 5941da177e4SLinus Torvalds} 5951da177e4SLinus Torvalds 5961da177e4SLinus Torvalds## 5971da177e4SLinus Torvalds# output enum in man 5981da177e4SLinus Torvaldssub output_enum_man(%) { 5991da177e4SLinus Torvalds my %args = %{$_[0]}; 6001da177e4SLinus Torvalds my ($parameter, $section); 6011da177e4SLinus Torvalds my $count; 6021da177e4SLinus Torvalds 6031da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 6041da177e4SLinus Torvalds 6051da177e4SLinus Torvalds print ".SH NAME\n"; 6061da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 6071da177e4SLinus Torvalds 6081da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 6091da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 6101da177e4SLinus Torvalds $count = 0; 6111da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 6121da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 6131da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 6141da177e4SLinus Torvalds print "\n};\n"; 6151da177e4SLinus Torvalds last; 6161da177e4SLinus Torvalds } 6171da177e4SLinus Torvalds else { 6181da177e4SLinus Torvalds print ", \n.br\n"; 6191da177e4SLinus Torvalds } 6201da177e4SLinus Torvalds $count++; 6211da177e4SLinus Torvalds } 6221da177e4SLinus Torvalds 6231da177e4SLinus Torvalds print ".SH Constants\n"; 6241da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6251da177e4SLinus Torvalds my $parameter_name = $parameter; 6261da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6271da177e4SLinus Torvalds 6281da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 6291da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6301da177e4SLinus Torvalds } 6311da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6321da177e4SLinus Torvalds print ".SH \"$section\"\n"; 6331da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6341da177e4SLinus Torvalds } 6351da177e4SLinus Torvalds} 6361da177e4SLinus Torvalds 6371da177e4SLinus Torvalds## 6381da177e4SLinus Torvalds# output struct in man 6391da177e4SLinus Torvaldssub output_struct_man(%) { 6401da177e4SLinus Torvalds my %args = %{$_[0]}; 6411da177e4SLinus Torvalds my ($parameter, $section); 6421da177e4SLinus Torvalds 6431da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 6441da177e4SLinus Torvalds 6451da177e4SLinus Torvalds print ".SH NAME\n"; 6461da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 6471da177e4SLinus Torvalds 6488ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 6498ad72163SMauro Carvalho Chehab $declaration =~ s/\t/ /g; 6508ad72163SMauro Carvalho Chehab $declaration =~ s/\n/"\n.br\n.BI \"/g; 6511da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 6521da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 6538ad72163SMauro Carvalho Chehab print ".BI \"$declaration\n};\n.br\n\n"; 6541da177e4SLinus Torvalds 655c51d3dacSRandy Dunlap print ".SH Members\n"; 6561da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6571da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 6581da177e4SLinus Torvalds 6591da177e4SLinus Torvalds my $parameter_name = $parameter; 6601da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6611da177e4SLinus Torvalds 6621da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6631da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 6641da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6651da177e4SLinus Torvalds } 6661da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6671da177e4SLinus Torvalds print ".SH \"$section\"\n"; 6681da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6691da177e4SLinus Torvalds } 6701da177e4SLinus Torvalds} 6711da177e4SLinus Torvalds 6721da177e4SLinus Torvalds## 6731da177e4SLinus Torvalds# output typedef in man 6741da177e4SLinus Torvaldssub output_typedef_man(%) { 6751da177e4SLinus Torvalds my %args = %{$_[0]}; 6761da177e4SLinus Torvalds my ($parameter, $section); 6771da177e4SLinus Torvalds 6781da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 6791da177e4SLinus Torvalds 6801da177e4SLinus Torvalds print ".SH NAME\n"; 6811da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 6821da177e4SLinus Torvalds 6831da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6841da177e4SLinus Torvalds print ".SH \"$section\"\n"; 6851da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6861da177e4SLinus Torvalds } 6871da177e4SLinus Torvalds} 6881da177e4SLinus Torvalds 689b112e0f7SJohannes Bergsub output_blockhead_man(%) { 6901da177e4SLinus Torvalds my %args = %{$_[0]}; 6911da177e4SLinus Torvalds my ($parameter, $section); 6921da177e4SLinus Torvalds my $count; 6931da177e4SLinus Torvalds 6941da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 6951da177e4SLinus Torvalds 6961da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6971da177e4SLinus Torvalds print ".SH \"$section\"\n"; 6981da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6991da177e4SLinus Torvalds } 7001da177e4SLinus Torvalds} 7011da177e4SLinus Torvalds 7021da177e4SLinus Torvalds## 703c0d1b6eeSJonathan Corbet# output in restructured text 704c0d1b6eeSJonathan Corbet# 705c0d1b6eeSJonathan Corbet 706c0d1b6eeSJonathan Corbet# 707c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 708c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 709c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 710c0d1b6eeSJonathan Corbet# 711c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 712c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 713c0d1b6eeSJonathan Corbet my ($parameter, $section); 714c0d1b6eeSJonathan Corbet 715c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 716eab795ddSMauro Carvalho Chehab next if (defined($nosymbol_table{$section})); 717eab795ddSMauro Carvalho Chehab 7189e72184bSJani Nikula if ($output_selection != OUTPUT_INCLUDE) { 71906a755d6SMichal Wajdeczko print ".. _$section:\n\n"; 720c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 7219e72184bSJani Nikula } 7220b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 723c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 724c0d1b6eeSJonathan Corbet print "\n"; 725c0d1b6eeSJonathan Corbet } 726c0d1b6eeSJonathan Corbet} 727c0d1b6eeSJonathan Corbet 728af250290SJonathan Corbet# 729af250290SJonathan Corbet# Apply the RST highlights to a sub-block of text. 730af250290SJonathan Corbet# 731af250290SJonathan Corbetsub highlight_block($) { 732af250290SJonathan Corbet # The dohighlight kludge requires the text be called $contents 733af250290SJonathan Corbet my $contents = shift; 734c0d1b6eeSJonathan Corbet eval $dohighlight; 735c0d1b6eeSJonathan Corbet die $@ if $@; 736af250290SJonathan Corbet return $contents; 737af250290SJonathan Corbet} 738c0d1b6eeSJonathan Corbet 739af250290SJonathan Corbet# 740af250290SJonathan Corbet# Regexes used only here. 741af250290SJonathan Corbet# 742af250290SJonathan Corbetmy $sphinx_literal = '^[^.].*::$'; 743af250290SJonathan Corbetmy $sphinx_cblock = '^\.\.\ +code-block::'; 744af250290SJonathan Corbet 745af250290SJonathan Corbetsub output_highlight_rst { 746af250290SJonathan Corbet my $input = join "\n",@_; 747af250290SJonathan Corbet my $output = ""; 748af250290SJonathan Corbet my $line; 749af250290SJonathan Corbet my $in_literal = 0; 750af250290SJonathan Corbet my $litprefix; 751af250290SJonathan Corbet my $block = ""; 752af250290SJonathan Corbet 753af250290SJonathan Corbet foreach $line (split "\n",$input) { 754af250290SJonathan Corbet # 755af250290SJonathan Corbet # If we're in a literal block, see if we should drop out 756af250290SJonathan Corbet # of it. Otherwise pass the line straight through unmunged. 757af250290SJonathan Corbet # 758af250290SJonathan Corbet if ($in_literal) { 759af250290SJonathan Corbet if (! ($line =~ /^\s*$/)) { 760af250290SJonathan Corbet # 761af250290SJonathan Corbet # If this is the first non-blank line in a literal 762af250290SJonathan Corbet # block we need to figure out what the proper indent is. 763af250290SJonathan Corbet # 764af250290SJonathan Corbet if ($litprefix eq "") { 765af250290SJonathan Corbet $line =~ /^(\s*)/; 766af250290SJonathan Corbet $litprefix = '^' . $1; 767af250290SJonathan Corbet $output .= $line . "\n"; 768af250290SJonathan Corbet } elsif (! ($line =~ /$litprefix/)) { 769af250290SJonathan Corbet $in_literal = 0; 770af250290SJonathan Corbet } else { 771af250290SJonathan Corbet $output .= $line . "\n"; 772af250290SJonathan Corbet } 773af250290SJonathan Corbet } else { 774af250290SJonathan Corbet $output .= $line . "\n"; 775af250290SJonathan Corbet } 776af250290SJonathan Corbet } 777af250290SJonathan Corbet # 778af250290SJonathan Corbet # Not in a literal block (or just dropped out) 779af250290SJonathan Corbet # 780af250290SJonathan Corbet if (! $in_literal) { 781af250290SJonathan Corbet $block .= $line . "\n"; 782af250290SJonathan Corbet if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) { 783af250290SJonathan Corbet $in_literal = 1; 784af250290SJonathan Corbet $litprefix = ""; 785af250290SJonathan Corbet $output .= highlight_block($block); 786af250290SJonathan Corbet $block = "" 787af250290SJonathan Corbet } 788af250290SJonathan Corbet } 789af250290SJonathan Corbet } 790af250290SJonathan Corbet 791af250290SJonathan Corbet if ($block) { 792af250290SJonathan Corbet $output .= highlight_block($block); 793af250290SJonathan Corbet } 794af250290SJonathan Corbet foreach $line (split "\n", $output) { 795830066a7SJani Nikula print $lineprefix . $line . "\n"; 796c0d1b6eeSJonathan Corbet } 797c0d1b6eeSJonathan Corbet} 798c0d1b6eeSJonathan Corbet 799c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 800c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 801c0d1b6eeSJonathan Corbet my ($parameter, $section); 802c099ff69SJani Nikula my $oldprefix = $lineprefix; 80382801d06SMauro Carvalho Chehab my $start = ""; 8046e9e4158SMauro Carvalho Chehab my $is_macro = 0; 805c0d1b6eeSJonathan Corbet 806efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 807e3ad05feSMauro Carvalho Chehab if ($args{'typedef'}) { 80882801d06SMauro Carvalho Chehab print ".. c:type:: ". $args{'function'} . "\n\n"; 80982801d06SMauro Carvalho Chehab print_lineno($declaration_start_line); 81082801d06SMauro Carvalho Chehab print " **Typedef**: "; 81182801d06SMauro Carvalho Chehab $lineprefix = ""; 81282801d06SMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 81382801d06SMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 8146e9e4158SMauro Carvalho Chehab $is_macro = 1; 815c0d1b6eeSJonathan Corbet } else { 81682801d06SMauro Carvalho Chehab print ".. c:function:: "; 81782801d06SMauro Carvalho Chehab } 818e3ad05feSMauro Carvalho Chehab } else { 8196e9e4158SMauro Carvalho Chehab if ($args{'typedef'} || $args{'functiontype'} eq "") { 8206e9e4158SMauro Carvalho Chehab $is_macro = 1; 821e3ad05feSMauro Carvalho Chehab print ".. c:macro:: ". $args{'function'} . "\n\n"; 8226e9e4158SMauro Carvalho Chehab } else { 8236e9e4158SMauro Carvalho Chehab print ".. c:function:: "; 8246e9e4158SMauro Carvalho Chehab } 825e3ad05feSMauro Carvalho Chehab 826e3ad05feSMauro Carvalho Chehab if ($args{'typedef'}) { 827e3ad05feSMauro Carvalho Chehab print_lineno($declaration_start_line); 828e3ad05feSMauro Carvalho Chehab print " **Typedef**: "; 829e3ad05feSMauro Carvalho Chehab $lineprefix = ""; 830e3ad05feSMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 831e3ad05feSMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 832e3ad05feSMauro Carvalho Chehab } else { 8336e9e4158SMauro Carvalho Chehab print "``" if ($is_macro); 834e3ad05feSMauro Carvalho Chehab } 835e3ad05feSMauro Carvalho Chehab } 83682801d06SMauro Carvalho Chehab if ($args{'functiontype'} ne "") { 83782801d06SMauro Carvalho Chehab $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; 83882801d06SMauro Carvalho Chehab } else { 83982801d06SMauro Carvalho Chehab $start .= $args{'function'} . " ("; 840c0d1b6eeSJonathan Corbet } 841c0d1b6eeSJonathan Corbet print $start; 842c0d1b6eeSJonathan Corbet 843c0d1b6eeSJonathan Corbet my $count = 0; 844c0d1b6eeSJonathan Corbet foreach my $parameter (@{$args{'parameterlist'}}) { 845c0d1b6eeSJonathan Corbet if ($count ne 0) { 846c0d1b6eeSJonathan Corbet print ", "; 847c0d1b6eeSJonathan Corbet } 848c0d1b6eeSJonathan Corbet $count++; 849c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 850a88b1672SMauro Carvalho Chehab 851e86bdb24SAditya Srivastava if ($type =~ m/$function_pointer/) { 852c0d1b6eeSJonathan Corbet # pointer-to-function 853e8f4ba83SPeter Maydell print $1 . $parameter . ") (" . $2 . ")"; 854c0d1b6eeSJonathan Corbet } else { 855ed8348e2SMauro Carvalho Chehab print $type; 856c0d1b6eeSJonathan Corbet } 857c0d1b6eeSJonathan Corbet } 8586e9e4158SMauro Carvalho Chehab if ($is_macro) { 8596e9e4158SMauro Carvalho Chehab print ")``\n\n"; 86082801d06SMauro Carvalho Chehab } else { 861c099ff69SJani Nikula print ")\n\n"; 862e3ad05feSMauro Carvalho Chehab } 8636e9e4158SMauro Carvalho Chehab if (!$args{'typedef'}) { 8640b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 865c099ff69SJani Nikula $lineprefix = " "; 866c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 867c099ff69SJani Nikula print "\n"; 86882801d06SMauro Carvalho Chehab } 869c0d1b6eeSJonathan Corbet 870eaf710ceSJonathan Corbet # 871eaf710ceSJonathan Corbet # Put our descriptive text into a container (thus an HTML <div>) to help 872eaf710ceSJonathan Corbet # set the function prototypes apart. 873eaf710ceSJonathan Corbet # 874eaf710ceSJonathan Corbet print ".. container:: kernelindent\n\n"; 875c099ff69SJani Nikula $lineprefix = " "; 876eaf710ceSJonathan Corbet print $lineprefix . "**Parameters**\n\n"; 877c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 878c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 879ada5f446SGabriel Krisman Bertazi $parameter_name =~ s/\[.*//; 880c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 881c0d1b6eeSJonathan Corbet 882c0d1b6eeSJonathan Corbet if ($type ne "") { 883eaf710ceSJonathan Corbet print $lineprefix . "``$type``\n"; 884c0d1b6eeSJonathan Corbet } else { 885eaf710ceSJonathan Corbet print $lineprefix . "``$parameter``\n"; 886c0d1b6eeSJonathan Corbet } 8870b0f5f29SDaniel Vetter 8880b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 8890b0f5f29SDaniel Vetter 890eaf710ceSJonathan Corbet $lineprefix = " "; 8915e64fa9cSJani Nikula if (defined($args{'parameterdescs'}{$parameter_name}) && 8925e64fa9cSJani Nikula $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 893c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 894c0d1b6eeSJonathan Corbet } else { 895eaf710ceSJonathan Corbet print $lineprefix . "*undescribed*\n"; 896c0d1b6eeSJonathan Corbet } 897eaf710ceSJonathan Corbet $lineprefix = " "; 898c0d1b6eeSJonathan Corbet print "\n"; 899c0d1b6eeSJonathan Corbet } 900c099ff69SJani Nikula 901c0d1b6eeSJonathan Corbet output_section_rst(@_); 902eaf710ceSJonathan Corbet $lineprefix = $oldprefix; 903c0d1b6eeSJonathan Corbet} 904c0d1b6eeSJonathan Corbet 905c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 906c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 907c0d1b6eeSJonathan Corbet my $section; 908c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 909c0d1b6eeSJonathan Corbet 910c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 911eaf710ceSJonathan Corbet print $lineprefix . "**$section**\n\n"; 9120b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 913c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 914c0d1b6eeSJonathan Corbet print "\n"; 915c0d1b6eeSJonathan Corbet } 916c0d1b6eeSJonathan Corbet print "\n"; 917c0d1b6eeSJonathan Corbet} 918c0d1b6eeSJonathan Corbet 919c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 920c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 921c0d1b6eeSJonathan Corbet my ($parameter); 922c099ff69SJani Nikula my $oldprefix = $lineprefix; 923c0d1b6eeSJonathan Corbet my $count; 924eaf710ceSJonathan Corbet my $outer; 92562850976SJani Nikula 926efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 927efa44475SMauro Carvalho Chehab my $name = "enum " . $args{'enum'}; 92862850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 929efa44475SMauro Carvalho Chehab } else { 930efa44475SMauro Carvalho Chehab my $name = $args{'enum'}; 931efa44475SMauro Carvalho Chehab print "\n\n.. c:enum:: " . $name . "\n\n"; 932efa44475SMauro Carvalho Chehab } 9330b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 934c099ff69SJani Nikula $lineprefix = " "; 935c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 936c099ff69SJani Nikula print "\n"; 937c0d1b6eeSJonathan Corbet 938eaf710ceSJonathan Corbet print ".. container:: kernelindent\n\n"; 939eaf710ceSJonathan Corbet $outer = $lineprefix . " "; 940eaf710ceSJonathan Corbet $lineprefix = $outer . " "; 941eaf710ceSJonathan Corbet print $outer . "**Constants**\n\n"; 942c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 943eaf710ceSJonathan Corbet print $outer . "``$parameter``\n"; 944eaf710ceSJonathan Corbet 945c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 946c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 947c0d1b6eeSJonathan Corbet } else { 948eaf710ceSJonathan Corbet print $lineprefix . "*undescribed*\n"; 949c0d1b6eeSJonathan Corbet } 950c0d1b6eeSJonathan Corbet print "\n"; 951c0d1b6eeSJonathan Corbet } 952eaf710ceSJonathan Corbet print "\n"; 953c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 954c0d1b6eeSJonathan Corbet output_section_rst(@_); 955c0d1b6eeSJonathan Corbet} 956c0d1b6eeSJonathan Corbet 957c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 958c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 959c0d1b6eeSJonathan Corbet my ($parameter); 960c099ff69SJani Nikula my $oldprefix = $lineprefix; 961efa44475SMauro Carvalho Chehab my $name; 962c0d1b6eeSJonathan Corbet 963efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 964efa44475SMauro Carvalho Chehab $name = "typedef " . $args{'typedef'}; 965efa44475SMauro Carvalho Chehab } else { 966efa44475SMauro Carvalho Chehab $name = $args{'typedef'}; 967efa44475SMauro Carvalho Chehab } 96862850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 9690b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 970c099ff69SJani Nikula $lineprefix = " "; 971c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 972c099ff69SJani Nikula print "\n"; 973c0d1b6eeSJonathan Corbet 974c099ff69SJani Nikula $lineprefix = $oldprefix; 975c0d1b6eeSJonathan Corbet output_section_rst(@_); 976c0d1b6eeSJonathan Corbet} 977c0d1b6eeSJonathan Corbet 978c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 979c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 980c0d1b6eeSJonathan Corbet my ($parameter); 981c099ff69SJani Nikula my $oldprefix = $lineprefix; 982c0d1b6eeSJonathan Corbet 983efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 984efa44475SMauro Carvalho Chehab my $name = $args{'type'} . " " . $args{'struct'}; 98562850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 986efa44475SMauro Carvalho Chehab } else { 987efa44475SMauro Carvalho Chehab my $name = $args{'struct'}; 98872b97d0bSMauro Carvalho Chehab if ($args{'type'} eq 'union') { 98972b97d0bSMauro Carvalho Chehab print "\n\n.. c:union:: " . $name . "\n\n"; 99072b97d0bSMauro Carvalho Chehab } else { 991efa44475SMauro Carvalho Chehab print "\n\n.. c:struct:: " . $name . "\n\n"; 992efa44475SMauro Carvalho Chehab } 99372b97d0bSMauro Carvalho Chehab } 9940b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 995c099ff69SJani Nikula $lineprefix = " "; 996c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 997c099ff69SJani Nikula print "\n"; 998c0d1b6eeSJonathan Corbet 999eaf710ceSJonathan Corbet print ".. container:: kernelindent\n\n"; 1000eaf710ceSJonathan Corbet print $lineprefix . "**Definition**::\n\n"; 10018ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 1002eaf710ceSJonathan Corbet $lineprefix = $lineprefix . " "; 1003eaf710ceSJonathan Corbet $declaration =~ s/\t/$lineprefix/g; 1004eaf710ceSJonathan Corbet print $lineprefix . $args{'type'} . " " . $args{'struct'} . " {\n$declaration" . $lineprefix . "};\n\n"; 1005c0d1b6eeSJonathan Corbet 1006c099ff69SJani Nikula $lineprefix = " "; 1007eaf710ceSJonathan Corbet print $lineprefix . "**Members**\n\n"; 1008c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1009c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 1010c0d1b6eeSJonathan Corbet 1011c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1012c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 1013c0d1b6eeSJonathan Corbet 1014c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1015c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 10160b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 1017eaf710ceSJonathan Corbet print $lineprefix . "``" . $parameter . "``\n"; 1018eaf710ceSJonathan Corbet $lineprefix = " "; 1019c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1020eaf710ceSJonathan Corbet $lineprefix = " "; 1021c0d1b6eeSJonathan Corbet print "\n"; 1022c0d1b6eeSJonathan Corbet } 1023c0d1b6eeSJonathan Corbet print "\n"; 1024c099ff69SJani Nikula 1025c099ff69SJani Nikula $lineprefix = $oldprefix; 1026c0d1b6eeSJonathan Corbet output_section_rst(@_); 1027c0d1b6eeSJonathan Corbet} 1028c0d1b6eeSJonathan Corbet 10293a025e1dSMatthew Wilcox## none mode output functions 10303a025e1dSMatthew Wilcox 10313a025e1dSMatthew Wilcoxsub output_function_none(%) { 10323a025e1dSMatthew Wilcox} 10333a025e1dSMatthew Wilcox 10343a025e1dSMatthew Wilcoxsub output_enum_none(%) { 10353a025e1dSMatthew Wilcox} 10363a025e1dSMatthew Wilcox 10373a025e1dSMatthew Wilcoxsub output_typedef_none(%) { 10383a025e1dSMatthew Wilcox} 10393a025e1dSMatthew Wilcox 10403a025e1dSMatthew Wilcoxsub output_struct_none(%) { 10413a025e1dSMatthew Wilcox} 10423a025e1dSMatthew Wilcox 10433a025e1dSMatthew Wilcoxsub output_blockhead_none(%) { 10443a025e1dSMatthew Wilcox} 10453a025e1dSMatthew Wilcox 10461da177e4SLinus Torvalds## 104727205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 104827205744SRandy Dunlap# calls the generated, variable output_ function name based on 104927205744SRandy Dunlap# functype and output_mode 10501da177e4SLinus Torvaldssub output_declaration { 10511da177e4SLinus Torvalds no strict 'refs'; 10521da177e4SLinus Torvalds my $name = shift; 10531da177e4SLinus Torvalds my $functype = shift; 10541da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 1055eab795ddSMauro Carvalho Chehab 1056eab795ddSMauro Carvalho Chehab return if (defined($nosymbol_table{$name})); 1057eab795ddSMauro Carvalho Chehab 1058b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 1059b6c3f456SJani Nikula (($output_selection == OUTPUT_INCLUDE || 1060b6c3f456SJani Nikula $output_selection == OUTPUT_EXPORTED) && 106186ae2e38SJani Nikula defined($function_table{$name})) || 1062eab795ddSMauro Carvalho Chehab ($output_selection == OUTPUT_INTERNAL && 106386ae2e38SJani Nikula !($functype eq "function" && defined($function_table{$name})))) 10641da177e4SLinus Torvalds { 10651da177e4SLinus Torvalds &$func(@_); 10661da177e4SLinus Torvalds $section_counter++; 10671da177e4SLinus Torvalds } 10681da177e4SLinus Torvalds} 10691da177e4SLinus Torvalds 10701da177e4SLinus Torvalds## 107127205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 1072b112e0f7SJohannes Bergsub output_blockhead { 10731da177e4SLinus Torvalds no strict 'refs'; 1074b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 10751da177e4SLinus Torvalds &$func(@_); 10761da177e4SLinus Torvalds $section_counter++; 10771da177e4SLinus Torvalds} 10781da177e4SLinus Torvalds 10791da177e4SLinus Torvalds## 10801da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 10811da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 10821da177e4SLinus Torvaldssub dump_declaration($$) { 10831da177e4SLinus Torvalds no strict 'refs'; 10841da177e4SLinus Torvalds my ($prototype, $file) = @_; 10851da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 10861da177e4SLinus Torvalds &$func(@_); 10871da177e4SLinus Torvalds} 10881da177e4SLinus Torvalds 10891da177e4SLinus Torvaldssub dump_union($$) { 10901da177e4SLinus Torvalds dump_struct(@_); 10911da177e4SLinus Torvalds} 10921da177e4SLinus Torvalds 10931da177e4SLinus Torvaldssub dump_struct($$) { 10941da177e4SLinus Torvalds my $x = shift; 10951da177e4SLinus Torvalds my $file = shift; 1096a746fe32SAditya Srivastava my $decl_type; 1097a746fe32SAditya Srivastava my $members; 1098a746fe32SAditya Srivastava my $type = qr{struct|union}; 1099a746fe32SAditya Srivastava # For capturing struct/union definition body, i.e. "{members*}qualifiers*" 1100e86bdb24SAditya Srivastava my $qualifiers = qr{$attribute|__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned}; 1101e86bdb24SAditya Srivastava my $definition_body = qr{\{(.*)\}\s*$qualifiers*}; 1102e86bdb24SAditya Srivastava my $struct_members = qr{($type)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;}; 11031da177e4SLinus Torvalds 1104a746fe32SAditya Srivastava if ($x =~ /($type)\s+(\w+)\s*$definition_body/) { 1105a746fe32SAditya Srivastava $decl_type = $1; 11061da177e4SLinus Torvalds $declaration_name = $2; 1107a746fe32SAditya Srivastava $members = $3; 1108a746fe32SAditya Srivastava } elsif ($x =~ /typedef\s+($type)\s*$definition_body\s*(\w+)\s*;/) { 1109a746fe32SAditya Srivastava $decl_type = $1; 1110a746fe32SAditya Srivastava $declaration_name = $3; 1111a746fe32SAditya Srivastava $members = $2; 1112a746fe32SAditya Srivastava } 11131da177e4SLinus Torvalds 1114a746fe32SAditya Srivastava if ($members) { 111552042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 1116df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "expecting prototype for $decl_type $identifier. Prototype was for $decl_type $declaration_name instead\n"); 111752042e2dSMauro Carvalho Chehab return; 111852042e2dSMauro Carvalho Chehab } 111952042e2dSMauro Carvalho Chehab 1120aeec46b9SMartin Waitz # ignore members marked private: 11210d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 11220d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 1123aeec46b9SMartin Waitz # strip comments: 1124aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 1125ef5da59fSRandy Dunlap # strip attributes 1126e86bdb24SAditya Srivastava $members =~ s/\s*$attribute/ /gi; 11273d9bfb19SSakari Ailus $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos; 11283d9bfb19SSakari Ailus $members =~ s/\s*__packed\s*/ /gos; 1129f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos; 1130f861537dSAndré Almeida $members =~ s/\s*____cacheline_aligned_in_smp/ /gos; 1131a070991fSJonathan Cameron $members =~ s/\s*____cacheline_aligned/ /gos; 113250d7bd38SKees Cook # unwrap struct_group(): 113350d7bd38SKees Cook # - first eat non-declaration parameters and rewrite for final match 113450d7bd38SKees Cook # - then remove macro, outer parens, and trailing semicolon 113550d7bd38SKees Cook $members =~ s/\bstruct_group\s*\(([^,]*,)/STRUCT_GROUP(/gos; 113650d7bd38SKees Cook $members =~ s/\bstruct_group_(attr|tagged)\s*\(([^,]*,){2}/STRUCT_GROUP(/gos; 113750d7bd38SKees Cook $members =~ s/\b__struct_group\s*\(([^,]*,){3}/STRUCT_GROUP(/gos; 113850d7bd38SKees Cook $members =~ s/\bSTRUCT_GROUP(\(((?:(?>[^)(]+)|(?1))*)\))[^;]*;/$2/gos; 11393556108eSMauro Carvalho Chehab 1140e86bdb24SAditya Srivastava my $args = qr{([^,)]+)}; 1141b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 11423556108eSMauro Carvalho Chehab $members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos; 1143603bdf5dSRandy Dunlap $members =~ s/DECLARE_PHY_INTERFACE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, PHY_INTERFACE_MODE_MAX)/gos; 1144e86bdb24SAditya Srivastava $members =~ s/DECLARE_BITMAP\s*\($args,\s*$args\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 11451cb566baSJakub Kicinski # replace DECLARE_HASHTABLE 1146e86bdb24SAditya Srivastava $members =~ s/DECLARE_HASHTABLE\s*\($args,\s*$args\)/unsigned long $1\[1 << (($2) - 1)\]/gos; 114745005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO 1148e86bdb24SAditya Srivastava $members =~ s/DECLARE_KFIFO\s*\($args,\s*$args,\s*$args\)/$2 \*$1/gos; 114945005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO_PTR 1150e86bdb24SAditya Srivastava $members =~ s/DECLARE_KFIFO_PTR\s*\($args,\s*$args\)/$2 \*$1/gos; 11513080ea55SKees Cook # replace DECLARE_FLEX_ARRAY 11523080ea55SKees Cook $members =~ s/(?:__)?DECLARE_FLEX_ARRAY\s*\($args,\s*$args\)/$1 $2\[\]/gos; 11538ad72163SMauro Carvalho Chehab my $declaration = $members; 11548ad72163SMauro Carvalho Chehab 11558ad72163SMauro Carvalho Chehab # Split nested struct/union elements as newer ones 1156e86bdb24SAditya Srivastava while ($members =~ m/$struct_members/) { 115784ce5b98SMauro Carvalho Chehab my $newmember; 115884ce5b98SMauro Carvalho Chehab my $maintype = $1; 115984ce5b98SMauro Carvalho Chehab my $ids = $4; 11608ad72163SMauro Carvalho Chehab my $content = $3; 116184ce5b98SMauro Carvalho Chehab foreach my $id(split /,/, $ids) { 116284ce5b98SMauro Carvalho Chehab $newmember .= "$maintype $id; "; 116384ce5b98SMauro Carvalho Chehab 11648ad72163SMauro Carvalho Chehab $id =~ s/[:\[].*//; 116584ce5b98SMauro Carvalho Chehab $id =~ s/^\s*\**(\S+)\s*/$1/; 11668ad72163SMauro Carvalho Chehab foreach my $arg (split /;/, $content) { 11678ad72163SMauro Carvalho Chehab next if ($arg =~ m/^\s*$/); 11687c0d7e87SMauro Carvalho Chehab if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) { 11697c0d7e87SMauro Carvalho Chehab # pointer-to-function 11707c0d7e87SMauro Carvalho Chehab my $type = $1; 11717c0d7e87SMauro Carvalho Chehab my $name = $2; 11727c0d7e87SMauro Carvalho Chehab my $extra = $3; 11737c0d7e87SMauro Carvalho Chehab next if (!$name); 11747c0d7e87SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 11757c0d7e87SMauro Carvalho Chehab # anonymous struct/union 11767c0d7e87SMauro Carvalho Chehab $newmember .= "$type$name$extra; "; 11777c0d7e87SMauro Carvalho Chehab } else { 11787c0d7e87SMauro Carvalho Chehab $newmember .= "$type$id.$name$extra; "; 11797c0d7e87SMauro Carvalho Chehab } 11807c0d7e87SMauro Carvalho Chehab } else { 118184ce5b98SMauro Carvalho Chehab my $type; 118284ce5b98SMauro Carvalho Chehab my $names; 118384ce5b98SMauro Carvalho Chehab $arg =~ s/^\s+//; 118484ce5b98SMauro Carvalho Chehab $arg =~ s/\s+$//; 118584ce5b98SMauro Carvalho Chehab # Handle bitmaps 118684ce5b98SMauro Carvalho Chehab $arg =~ s/:\s*\d+\s*//g; 118784ce5b98SMauro Carvalho Chehab # Handle arrays 1188d404d579SMauro Carvalho Chehab $arg =~ s/\[.*\]//g; 118984ce5b98SMauro Carvalho Chehab # The type may have multiple words, 119084ce5b98SMauro Carvalho Chehab # and multiple IDs can be defined, like: 119184ce5b98SMauro Carvalho Chehab # const struct foo, *bar, foobar 119284ce5b98SMauro Carvalho Chehab # So, we remove spaces when parsing the 119384ce5b98SMauro Carvalho Chehab # names, in order to match just names 119484ce5b98SMauro Carvalho Chehab # and commas for the names 119584ce5b98SMauro Carvalho Chehab $arg =~ s/\s*,\s*/,/g; 119684ce5b98SMauro Carvalho Chehab if ($arg =~ m/(.*)\s+([\S+,]+)/) { 119784ce5b98SMauro Carvalho Chehab $type = $1; 119884ce5b98SMauro Carvalho Chehab $names = $2; 119984ce5b98SMauro Carvalho Chehab } else { 120084ce5b98SMauro Carvalho Chehab $newmember .= "$arg; "; 120184ce5b98SMauro Carvalho Chehab next; 120284ce5b98SMauro Carvalho Chehab } 120384ce5b98SMauro Carvalho Chehab foreach my $name (split /,/, $names) { 120484ce5b98SMauro Carvalho Chehab $name =~ s/^\s*\**(\S+)\s*/$1/; 12058ad72163SMauro Carvalho Chehab next if (($name =~ m/^\s*$/)); 12068ad72163SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 12078ad72163SMauro Carvalho Chehab # anonymous struct/union 12088ad72163SMauro Carvalho Chehab $newmember .= "$type $name; "; 12098ad72163SMauro Carvalho Chehab } else { 12108ad72163SMauro Carvalho Chehab $newmember .= "$type $id.$name; "; 12118ad72163SMauro Carvalho Chehab } 12128ad72163SMauro Carvalho Chehab } 12137c0d7e87SMauro Carvalho Chehab } 121484ce5b98SMauro Carvalho Chehab } 121584ce5b98SMauro Carvalho Chehab } 1216e86bdb24SAditya Srivastava $members =~ s/$struct_members/$newmember/; 121784ce5b98SMauro Carvalho Chehab } 12188ad72163SMauro Carvalho Chehab 12198ad72163SMauro Carvalho Chehab # Ignore other nested elements, like enums 1220673bb2dfSBen Hutchings $members =~ s/(\{[^\{\}]*\})//g; 12218ad72163SMauro Carvalho Chehab 1222151c468bSMauro Carvalho Chehab create_parameterlist($members, ';', $file, $declaration_name); 12231081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual); 12241da177e4SLinus Torvalds 12258ad72163SMauro Carvalho Chehab # Adjust declaration for better display 1226673bb2dfSBen Hutchings $declaration =~ s/([\{;])/$1\n/g; 1227673bb2dfSBen Hutchings $declaration =~ s/\}\s+;/};/g; 12288ad72163SMauro Carvalho Chehab # Better handle inlined enums 1229673bb2dfSBen Hutchings do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/); 12308ad72163SMauro Carvalho Chehab 12318ad72163SMauro Carvalho Chehab my @def_args = split /\n/, $declaration; 12328ad72163SMauro Carvalho Chehab my $level = 1; 12338ad72163SMauro Carvalho Chehab $declaration = ""; 12348ad72163SMauro Carvalho Chehab foreach my $clause (@def_args) { 12358ad72163SMauro Carvalho Chehab $clause =~ s/^\s+//; 12368ad72163SMauro Carvalho Chehab $clause =~ s/\s+$//; 12378ad72163SMauro Carvalho Chehab $clause =~ s/\s+/ /; 12388ad72163SMauro Carvalho Chehab next if (!$clause); 1239673bb2dfSBen Hutchings $level-- if ($clause =~ m/(\})/ && $level > 1); 12408ad72163SMauro Carvalho Chehab if (!($clause =~ m/^\s*#/)) { 12418ad72163SMauro Carvalho Chehab $declaration .= "\t" x $level; 12428ad72163SMauro Carvalho Chehab } 12438ad72163SMauro Carvalho Chehab $declaration .= "\t" . $clause . "\n"; 1244673bb2dfSBen Hutchings $level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/)); 12458ad72163SMauro Carvalho Chehab } 12461da177e4SLinus Torvalds output_declaration($declaration_name, 12471da177e4SLinus Torvalds 'struct', 12481da177e4SLinus Torvalds {'struct' => $declaration_name, 12491da177e4SLinus Torvalds 'module' => $modulename, 12508ad72163SMauro Carvalho Chehab 'definition' => $declaration, 12511da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 12521da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 12531da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 12541da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 12551da177e4SLinus Torvalds 'sections' => \%sections, 12561da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 12571da177e4SLinus Torvalds 'type' => $decl_type 12581da177e4SLinus Torvalds }); 12591da177e4SLinus Torvalds } 12601da177e4SLinus Torvalds else { 1261d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 12621da177e4SLinus Torvalds ++$errors; 12631da177e4SLinus Torvalds } 12641da177e4SLinus Torvalds} 12651da177e4SLinus Torvalds 126685afe608SMauro Carvalho Chehab 126785afe608SMauro Carvalho Chehabsub show_warnings($$) { 126885afe608SMauro Carvalho Chehab my $functype = shift; 126985afe608SMauro Carvalho Chehab my $name = shift; 127085afe608SMauro Carvalho Chehab 1271eab795ddSMauro Carvalho Chehab return 0 if (defined($nosymbol_table{$name})); 1272eab795ddSMauro Carvalho Chehab 127385afe608SMauro Carvalho Chehab return 1 if ($output_selection == OUTPUT_ALL); 127485afe608SMauro Carvalho Chehab 127585afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_EXPORTED) { 127685afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 127785afe608SMauro Carvalho Chehab return 1; 127885afe608SMauro Carvalho Chehab } else { 127985afe608SMauro Carvalho Chehab return 0; 128085afe608SMauro Carvalho Chehab } 128185afe608SMauro Carvalho Chehab } 128285afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_INTERNAL) { 128385afe608SMauro Carvalho Chehab if (!($functype eq "function" && defined($function_table{$name}))) { 128485afe608SMauro Carvalho Chehab return 1; 128585afe608SMauro Carvalho Chehab } else { 128685afe608SMauro Carvalho Chehab return 0; 128785afe608SMauro Carvalho Chehab } 128885afe608SMauro Carvalho Chehab } 128985afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_INCLUDE) { 129085afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 129185afe608SMauro Carvalho Chehab return 1; 129285afe608SMauro Carvalho Chehab } else { 129385afe608SMauro Carvalho Chehab return 0; 129485afe608SMauro Carvalho Chehab } 129585afe608SMauro Carvalho Chehab } 129685afe608SMauro Carvalho Chehab die("Please add the new output type at show_warnings()"); 129785afe608SMauro Carvalho Chehab} 129885afe608SMauro Carvalho Chehab 12991da177e4SLinus Torvaldssub dump_enum($$) { 13001da177e4SLinus Torvalds my $x = shift; 13011da177e4SLinus Torvalds my $file = shift; 1302d38c8cfbSMauro Carvalho Chehab my $members; 1303d38c8cfbSMauro Carvalho Chehab 13041da177e4SLinus Torvalds 1305aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 13064468e21eSConchúr Navid # strip #define macros inside enums 13074468e21eSConchúr Navid $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 1308b6d676dbSRandy Dunlap 1309d38c8cfbSMauro Carvalho Chehab if ($x =~ /typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;/) { 1310d38c8cfbSMauro Carvalho Chehab $declaration_name = $2; 1311d38c8cfbSMauro Carvalho Chehab $members = $1; 1312d38c8cfbSMauro Carvalho Chehab } elsif ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) { 13131da177e4SLinus Torvalds $declaration_name = $1; 1314d38c8cfbSMauro Carvalho Chehab $members = $2; 1315d38c8cfbSMauro Carvalho Chehab } 1316d38c8cfbSMauro Carvalho Chehab 1317ae5b17e4SAndy Shevchenko if ($members) { 131852042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 13190b54c2e3SMauro Carvalho Chehab if ($identifier eq "") { 1320df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "wrong kernel-doc identifier on line:\n"); 13210b54c2e3SMauro Carvalho Chehab } else { 1322df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "expecting prototype for enum $identifier. Prototype was for enum $declaration_name instead\n"); 13230b54c2e3SMauro Carvalho Chehab } 132452042e2dSMauro Carvalho Chehab return; 132552042e2dSMauro Carvalho Chehab } 13260b54c2e3SMauro Carvalho Chehab $declaration_name = "(anonymous)" if ($declaration_name eq ""); 132752042e2dSMauro Carvalho Chehab 13285cb5c31cSJohannes Berg my %_members; 13295cb5c31cSJohannes Berg 1330463a0fdcSMarkus Heiser $members =~ s/\s+$//; 13311da177e4SLinus Torvalds 13321da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 13331da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 13341da177e4SLinus Torvalds push @parameterlist, $arg; 13351da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 13361da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 133785afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 1338df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Enum value '$arg' not described in enum '$declaration_name'\n"); 13392defb272SMauro Carvalho Chehab } 13401da177e4SLinus Torvalds } 13415cb5c31cSJohannes Berg $_members{$arg} = 1; 13425cb5c31cSJohannes Berg } 13431da177e4SLinus Torvalds 13445cb5c31cSJohannes Berg while (my ($k, $v) = each %parameterdescs) { 13455cb5c31cSJohannes Berg if (!exists($_members{$k})) { 134685afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 1347df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Excess enum value '$k' description in '$declaration_name'\n"); 13482defb272SMauro Carvalho Chehab } 13495cb5c31cSJohannes Berg } 13501da177e4SLinus Torvalds } 13511da177e4SLinus Torvalds 13521da177e4SLinus Torvalds output_declaration($declaration_name, 13531da177e4SLinus Torvalds 'enum', 13541da177e4SLinus Torvalds {'enum' => $declaration_name, 13551da177e4SLinus Torvalds 'module' => $modulename, 13561da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 13571da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 13581da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 13591da177e4SLinus Torvalds 'sections' => \%sections, 13601da177e4SLinus Torvalds 'purpose' => $declaration_purpose 13611da177e4SLinus Torvalds }); 1362d38c8cfbSMauro Carvalho Chehab } else { 1363d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 13641da177e4SLinus Torvalds ++$errors; 13651da177e4SLinus Torvalds } 13661da177e4SLinus Torvalds} 13671da177e4SLinus Torvalds 13687d2c6b1eSMauro Carvalho Chehabmy $typedef_type = qr { ((?:\s+[\w\*]+\b){1,8})\s* }x; 13697efc6c42SMauro Carvalho Chehabmy $typedef_ident = qr { \*?\s*(\w\S+)\s* }x; 13707efc6c42SMauro Carvalho Chehabmy $typedef_args = qr { \s*\((.*)\); }x; 13717efc6c42SMauro Carvalho Chehab 13727efc6c42SMauro Carvalho Chehabmy $typedef1 = qr { typedef$typedef_type\($typedef_ident\)$typedef_args }x; 13737efc6c42SMauro Carvalho Chehabmy $typedef2 = qr { typedef$typedef_type$typedef_ident$typedef_args }x; 13747efc6c42SMauro Carvalho Chehab 13751da177e4SLinus Torvaldssub dump_typedef($$) { 13761da177e4SLinus Torvalds my $x = shift; 13771da177e4SLinus Torvalds my $file = shift; 13781da177e4SLinus Torvalds 1379aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 138083766452SMauro Carvalho Chehab 13817efc6c42SMauro Carvalho Chehab # Parse function typedef prototypes 13827efc6c42SMauro Carvalho Chehab if ($x =~ $typedef1 || $x =~ $typedef2) { 138383766452SMauro Carvalho Chehab $return_type = $1; 138483766452SMauro Carvalho Chehab $declaration_name = $2; 138583766452SMauro Carvalho Chehab my $args = $3; 13866b80975cSMauro Carvalho Chehab $return_type =~ s/^\s+//; 138783766452SMauro Carvalho Chehab 138852042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 1389df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n"); 139052042e2dSMauro Carvalho Chehab return; 139152042e2dSMauro Carvalho Chehab } 139252042e2dSMauro Carvalho Chehab 1393151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 139483766452SMauro Carvalho Chehab 139583766452SMauro Carvalho Chehab output_declaration($declaration_name, 139683766452SMauro Carvalho Chehab 'function', 139783766452SMauro Carvalho Chehab {'function' => $declaration_name, 139882801d06SMauro Carvalho Chehab 'typedef' => 1, 139983766452SMauro Carvalho Chehab 'module' => $modulename, 140083766452SMauro Carvalho Chehab 'functiontype' => $return_type, 140183766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 140283766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 140383766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 140483766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 140583766452SMauro Carvalho Chehab 'sections' => \%sections, 140683766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 140783766452SMauro Carvalho Chehab }); 140883766452SMauro Carvalho Chehab return; 140983766452SMauro Carvalho Chehab } 141083766452SMauro Carvalho Chehab 14111da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 14121da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 14131da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 14141da177e4SLinus Torvalds } 14151da177e4SLinus Torvalds 14161da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 14171da177e4SLinus Torvalds $declaration_name = $1; 14181da177e4SLinus Torvalds 141952042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 1420df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n"); 142152042e2dSMauro Carvalho Chehab return; 142252042e2dSMauro Carvalho Chehab } 142352042e2dSMauro Carvalho Chehab 14241da177e4SLinus Torvalds output_declaration($declaration_name, 14251da177e4SLinus Torvalds 'typedef', 14261da177e4SLinus Torvalds {'typedef' => $declaration_name, 14271da177e4SLinus Torvalds 'module' => $modulename, 14281da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 14291da177e4SLinus Torvalds 'sections' => \%sections, 14301da177e4SLinus Torvalds 'purpose' => $declaration_purpose 14311da177e4SLinus Torvalds }); 14321da177e4SLinus Torvalds } 14331da177e4SLinus Torvalds else { 1434d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 14351da177e4SLinus Torvalds ++$errors; 14361da177e4SLinus Torvalds } 14371da177e4SLinus Torvalds} 14381da177e4SLinus Torvalds 1439a1d94aa5SRandy Dunlapsub save_struct_actual($) { 1440a1d94aa5SRandy Dunlap my $actual = shift; 1441a1d94aa5SRandy Dunlap 1442a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 1443a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 1444a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 1445a1d94aa5SRandy Dunlap} 1446a1d94aa5SRandy Dunlap 1447151c468bSMauro Carvalho Chehabsub create_parameterlist($$$$) { 14481da177e4SLinus Torvalds my $args = shift; 14491da177e4SLinus Torvalds my $splitter = shift; 14501da177e4SLinus Torvalds my $file = shift; 1451151c468bSMauro Carvalho Chehab my $declaration_name = shift; 14521da177e4SLinus Torvalds my $type; 14531da177e4SLinus Torvalds my $param; 14541da177e4SLinus Torvalds 1455a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 1456e86bdb24SAditya Srivastava my $arg_expr = qr{\([^\),]+}; 1457e86bdb24SAditya Srivastava while ($args =~ /$arg_expr,/) { 1458e86bdb24SAditya Srivastava $args =~ s/($arg_expr),/$1#/g; 14591da177e4SLinus Torvalds } 14601da177e4SLinus Torvalds 14611da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 14621da177e4SLinus Torvalds # strip comments 14631da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 146403699f27SKees Cook # ignore argument attributes 146503699f27SKees Cook $arg =~ s/\sPOS0?\s/ /; 14661da177e4SLinus Torvalds # strip leading/trailing spaces 14671da177e4SLinus Torvalds $arg =~ s/^\s*//; 14681da177e4SLinus Torvalds $arg =~ s/\s*$//; 14691da177e4SLinus Torvalds $arg =~ s/\s+/ /; 14701da177e4SLinus Torvalds 14711da177e4SLinus Torvalds if ($arg =~ /^#/) { 14721da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 14731da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 14741da177e4SLinus Torvalds # output_* subs. 1475ed8348e2SMauro Carvalho Chehab push_parameter($arg, "", "", $file); 147600d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 14771da177e4SLinus Torvalds # pointer-to-function 14781da177e4SLinus Torvalds $arg =~ tr/#/,/; 1479336ced2dSAditya Srivastava $arg =~ m/[^\(]+\(\*?\s*([\w\[\]\.]*)\s*\)/; 14801da177e4SLinus Torvalds $param = $1; 14811da177e4SLinus Torvalds $type = $arg; 148200d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1483a1d94aa5SRandy Dunlap save_struct_actual($param); 1484ed8348e2SMauro Carvalho Chehab push_parameter($param, $type, $arg, $file, $declaration_name); 1485aeec46b9SMartin Waitz } elsif ($arg) { 14861da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 14871da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 14881da177e4SLinus Torvalds 14891da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 14901da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 14911da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 14921da177e4SLinus Torvalds } 1493884f2810SBorislav Petkov 1494884f2810SBorislav Petkov my @first_arg; 1495884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1496884f2810SBorislav Petkov shift @args; 1497884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 1498884f2810SBorislav Petkov push(@first_arg, $2); 1499884f2810SBorislav Petkov } else { 1500884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 1501884f2810SBorislav Petkov } 1502884f2810SBorislav Petkov 15031da177e4SLinus Torvalds unshift(@args, pop @first_arg); 15041da177e4SLinus Torvalds $type = join " ", @first_arg; 15051da177e4SLinus Torvalds 15061da177e4SLinus Torvalds foreach $param (@args) { 15071da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 1508a1d94aa5SRandy Dunlap save_struct_actual($2); 1509ed8348e2SMauro Carvalho Chehab 1510ed8348e2SMauro Carvalho Chehab push_parameter($2, "$type $1", $arg, $file, $declaration_name); 15111da177e4SLinus Torvalds } 15121da177e4SLinus Torvalds elsif ($param =~ m/(.*?):(\d+)/) { 15137b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 1514a1d94aa5SRandy Dunlap save_struct_actual($1); 1515ed8348e2SMauro Carvalho Chehab push_parameter($1, "$type:$2", $arg, $file, $declaration_name) 15161da177e4SLinus Torvalds } 15177b97887eSRandy Dunlap } 15181da177e4SLinus Torvalds else { 1519a1d94aa5SRandy Dunlap save_struct_actual($param); 1520ed8348e2SMauro Carvalho Chehab push_parameter($param, $type, $arg, $file, $declaration_name); 15211da177e4SLinus Torvalds } 15221da177e4SLinus Torvalds } 15231da177e4SLinus Torvalds } 15241da177e4SLinus Torvalds } 15251da177e4SLinus Torvalds} 15261da177e4SLinus Torvalds 1527ed8348e2SMauro Carvalho Chehabsub push_parameter($$$$$) { 15281da177e4SLinus Torvalds my $param = shift; 15291da177e4SLinus Torvalds my $type = shift; 1530ed8348e2SMauro Carvalho Chehab my $org_arg = shift; 15311da177e4SLinus Torvalds my $file = shift; 1532151c468bSMauro Carvalho Chehab my $declaration_name = shift; 15331da177e4SLinus Torvalds 15345f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 15355f8c7c98SRandy Dunlap ($param eq "}")) { 15365f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 15375f8c7c98SRandy Dunlap } 15385f8c7c98SRandy Dunlap 15395f8c7c98SRandy Dunlap $anon_struct_union = 0; 1540f9b5c530SMauro Carvalho Chehab $param =~ s/[\[\)].*//; 15411da177e4SLinus Torvalds 1542a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 15431da177e4SLinus Torvalds { 1544c950a173SSilvio Fricke if (!$param =~ /\w\.\.\.$/) { 1545c950a173SSilvio Fricke # handles unnamed variable parameters 1546ef00028bSJonathan Corbet $param = "..."; 1547c950a173SSilvio Fricke } 154843756e34SJonathan Neuschäfer elsif ($param =~ /\w\.\.\.$/) { 154943756e34SJonathan Neuschäfer # for named variable parameters of the form `x...`, remove the dots 155043756e34SJonathan Neuschäfer $param =~ s/\.\.\.$//; 155143756e34SJonathan Neuschäfer } 1552ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1553a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 15541da177e4SLinus Torvalds } 1555ced69090SRandy Dunlap } 15561da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 15571da177e4SLinus Torvalds { 15581da177e4SLinus Torvalds $param="void"; 15591da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 15601da177e4SLinus Torvalds } 1561134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1562134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 1563134fe01bSRandy Dunlap { 1564134fe01bSRandy Dunlap $type = $param; 1565134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 1566134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 15675f8c7c98SRandy Dunlap $anon_struct_union = 1; 1568134fe01bSRandy Dunlap } 1569134fe01bSRandy Dunlap 1570a6d3fe77SMartin Waitz # warn if parameter has no description 1571134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 1572134fe01bSRandy Dunlap # but inline preprocessor statements); 1573151c468bSMauro Carvalho Chehab # Note: It will also ignore void params and unnamed structs/unions 1574f9b5c530SMauro Carvalho Chehab if (!defined $parameterdescs{$param} && $param !~ /^#/) { 1575f9b5c530SMauro Carvalho Chehab $parameterdescs{$param} = $undescribed; 15761da177e4SLinus Torvalds 1577be5cd20cSJonathan Corbet if (show_warnings($type, $declaration_name) && $param !~ /\./) { 1578df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Function parameter or member '$param' not described in '$declaration_name'\n"); 15791da177e4SLinus Torvalds } 15802defb272SMauro Carvalho Chehab } 15811da177e4SLinus Torvalds 158225985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 1583e34e7dbbSRandy Dunlap # on @parameterlist; 1584e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 1585e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 1586e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 1587e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 1588e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 1589e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 1590e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 15911da177e4SLinus Torvalds push @parameterlist, $param; 1592ed8348e2SMauro Carvalho Chehab $org_arg =~ s/\s\s+/ /g; 1593ed8348e2SMauro Carvalho Chehab $parametertypes{$param} = $org_arg; 15941da177e4SLinus Torvalds} 15951da177e4SLinus Torvalds 15961081de2dSMauro Carvalho Chehabsub check_sections($$$$$) { 15971081de2dSMauro Carvalho Chehab my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_; 1598a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 1599a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 1600a1d94aa5SRandy Dunlap my $err; 1601a1d94aa5SRandy Dunlap my ($px, $sx); 1602a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 1603a1d94aa5SRandy Dunlap 1604a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 1605a1d94aa5SRandy Dunlap $err = 1; 1606a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 1607a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 1608a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 1609e86bdb24SAditya Srivastava $prm_clean =~ s/$attribute//i; 1610e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 1611e34e7dbbSRandy Dunlap # however, the original param string may contain 1612e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 1613e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 1614e34e7dbbSRandy Dunlap # parameter list is split at spaces; 1615e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 1616e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 1617e34e7dbbSRandy Dunlap 1618a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 1619a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 1620a1d94aa5SRandy Dunlap $err = 0; 1621a1d94aa5SRandy Dunlap last; 1622a1d94aa5SRandy Dunlap } 1623a1d94aa5SRandy Dunlap } 1624a1d94aa5SRandy Dunlap if ($err) { 1625a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 1626df4bf98eSNiklas Söderlund emit_warning("${file}:$.", 1627a1d94aa5SRandy Dunlap "Excess function parameter " . 1628a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 1629df4bf98eSNiklas Söderlund "description in '$decl_name'\n"); 1630a1d94aa5SRandy Dunlap } 1631a1d94aa5SRandy Dunlap } 1632a1d94aa5SRandy Dunlap } 1633a1d94aa5SRandy Dunlap} 1634a1d94aa5SRandy Dunlap 16351da177e4SLinus Torvalds## 16364092bac7SYacine Belkadi# Checks the section describing the return value of a function. 16374092bac7SYacine Belkadisub check_return_section { 16384092bac7SYacine Belkadi my $file = shift; 16394092bac7SYacine Belkadi my $declaration_name = shift; 16404092bac7SYacine Belkadi my $return_type = shift; 16414092bac7SYacine Belkadi 16424092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 16434092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 16444092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 16454092bac7SYacine Belkadi return; 16464092bac7SYacine Belkadi } 16474092bac7SYacine Belkadi 16484092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 16494092bac7SYacine Belkadi $sections{$section_return} eq "") { 1650df4bf98eSNiklas Söderlund emit_warning("${file}:$.", 16514092bac7SYacine Belkadi "No description found for return value of " . 1652df4bf98eSNiklas Söderlund "'$declaration_name'\n"); 16534092bac7SYacine Belkadi } 16544092bac7SYacine Belkadi} 16554092bac7SYacine Belkadi 16564092bac7SYacine Belkadi## 16571da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 16581da177e4SLinus Torvalds# processed and spits out all the details stored in the global 16591da177e4SLinus Torvalds# arrays/hashes. 16601da177e4SLinus Torvaldssub dump_function($$) { 16611da177e4SLinus Torvalds my $prototype = shift; 16621da177e4SLinus Torvalds my $file = shift; 1663cbb4d3e6SHoria Geanta my $noret = 0; 16641da177e4SLinus Torvalds 16655ef09c96SMauro Carvalho Chehab print_lineno($new_start_line); 16665eb6b4b3SMauro Carvalho Chehab 16671da177e4SLinus Torvalds $prototype =~ s/^static +//; 16681da177e4SLinus Torvalds $prototype =~ s/^extern +//; 16694dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 16701da177e4SLinus Torvalds $prototype =~ s/^inline +//; 16711da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 167232e79401SRandy Dunlap $prototype =~ s/^__inline +//; 167332e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 167432e79401SRandy Dunlap $prototype =~ s/^noinline +//; 167503699f27SKees Cook $prototype =~ s/^__FORTIFY_INLINE +//; 167674fc5c65SRandy Dunlap $prototype =~ s/__init +//; 167720072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 167880342d48SMatthew Wilcox $prototype =~ s/__deprecated +//; 1679084aa001SAditya Srivastava $prototype =~ s/__flatten +//; 1680270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 168170c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 16820df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 16830891f959SMatthew Wilcox $prototype =~ s/__sched +//; 168495e760cbSRandy Dunlap $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//; 168503699f27SKees Cook $prototype =~ s/__(?:re)?alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +//; 168603699f27SKees Cook $prototype =~ s/__diagnose_as\s*\(\s*\S+\s*(?:,\s*\d+\s*)*\) +//; 1687cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 1688084aa001SAditya Srivastava $prototype =~ s/__attribute_const__ +//; 1689b1aaa546SPaolo Bonzini $prototype =~ s/__attribute__\s*\(\( 1690b1aaa546SPaolo Bonzini (?: 1691b1aaa546SPaolo Bonzini [\w\s]++ # attribute name 1692b1aaa546SPaolo Bonzini (?:\([^)]*+\))? # attribute arguments 1693b1aaa546SPaolo Bonzini \s*+,? # optional comma at the end 1694b1aaa546SPaolo Bonzini )+ 1695b1aaa546SPaolo Bonzini \)\)\s+//x; 16961da177e4SLinus Torvalds 16971da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 16981da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 16991da177e4SLinus Torvalds # 2. Function name 17001da177e4SLinus Torvalds # 3. Function parameters. 17011da177e4SLinus Torvalds # 17021da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 17031da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 17041da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 17051da177e4SLinus Torvalds # so on. 17061da177e4SLinus Torvalds # 17071da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 17081da177e4SLinus Torvalds # the following functions' documentation still comes out right: 17091da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 17101da177e4SLinus Torvalds # - atomic_set (macro) 17119598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 1712e86bdb24SAditya Srivastava my $name = qr{[a-zA-Z0-9_~:]+}; 1713e86bdb24SAditya Srivastava my $prototype_end1 = qr{[^\(]*}; 1714e86bdb24SAditya Srivastava my $prototype_end2 = qr{[^\{]*}; 1715e86bdb24SAditya Srivastava my $prototype_end = qr{\(($prototype_end1|$prototype_end2)\)}; 1716e86bdb24SAditya Srivastava my $type1 = qr{[\w\s]+}; 1717e86bdb24SAditya Srivastava my $type2 = qr{$type1\*+}; 17181da177e4SLinus Torvalds 1719e86bdb24SAditya Srivastava if ($define && $prototype =~ m/^()($name)\s+/) { 1720cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 1721cbb4d3e6SHoria Geanta # list. 1722cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 1723cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 1724cbb4d3e6SHoria Geanta $return_type = $1; 1725cbb4d3e6SHoria Geanta $declaration_name = $2; 1726cbb4d3e6SHoria Geanta $noret = 1; 1727e86bdb24SAditya Srivastava } elsif ($prototype =~ m/^()($name)\s*$prototype_end/ || 1728e86bdb24SAditya Srivastava $prototype =~ m/^($type1)\s+($name)\s*$prototype_end/ || 1729e86bdb24SAditya Srivastava $prototype =~ m/^($type2+)\s*($name)\s*$prototype_end/) { 17301da177e4SLinus Torvalds $return_type = $1; 17311da177e4SLinus Torvalds $declaration_name = $2; 17321da177e4SLinus Torvalds my $args = $3; 17331da177e4SLinus Torvalds 1734151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 17351da177e4SLinus Torvalds } else { 1736df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "cannot understand function prototype: '$prototype'\n"); 17371da177e4SLinus Torvalds return; 17381da177e4SLinus Torvalds } 17391da177e4SLinus Torvalds 174052042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 1741df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "expecting prototype for $identifier(). Prototype was for $declaration_name() instead\n"); 174252042e2dSMauro Carvalho Chehab return; 174352042e2dSMauro Carvalho Chehab } 174452042e2dSMauro Carvalho Chehab 1745a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 17461081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, "function", $sectcheck, $prms); 1747a1d94aa5SRandy Dunlap 17484092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 17494092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 17504092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 17514092bac7SYacine Belkadi # verbose mode. 17524092bac7SYacine Belkadi # TODO: always perform the check. 1753cbb4d3e6SHoria Geanta if ($verbose && !$noret) { 17544092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 17554092bac7SYacine Belkadi } 17564092bac7SYacine Belkadi 175747bcacfdSMauro Carvalho Chehab # The function parser can be called with a typedef parameter. 175847bcacfdSMauro Carvalho Chehab # Handle it. 175947bcacfdSMauro Carvalho Chehab if ($return_type =~ /typedef/) { 176047bcacfdSMauro Carvalho Chehab output_declaration($declaration_name, 176147bcacfdSMauro Carvalho Chehab 'function', 176247bcacfdSMauro Carvalho Chehab {'function' => $declaration_name, 176347bcacfdSMauro Carvalho Chehab 'typedef' => 1, 176447bcacfdSMauro Carvalho Chehab 'module' => $modulename, 176547bcacfdSMauro Carvalho Chehab 'functiontype' => $return_type, 176647bcacfdSMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 176747bcacfdSMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 176847bcacfdSMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 176947bcacfdSMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 177047bcacfdSMauro Carvalho Chehab 'sections' => \%sections, 177147bcacfdSMauro Carvalho Chehab 'purpose' => $declaration_purpose 177247bcacfdSMauro Carvalho Chehab }); 177347bcacfdSMauro Carvalho Chehab } else { 17741da177e4SLinus Torvalds output_declaration($declaration_name, 17751da177e4SLinus Torvalds 'function', 17761da177e4SLinus Torvalds {'function' => $declaration_name, 17771da177e4SLinus Torvalds 'module' => $modulename, 17781da177e4SLinus Torvalds 'functiontype' => $return_type, 17791da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 17801da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 17811da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 17821da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 17831da177e4SLinus Torvalds 'sections' => \%sections, 17841da177e4SLinus Torvalds 'purpose' => $declaration_purpose 17851da177e4SLinus Torvalds }); 17861da177e4SLinus Torvalds } 178747bcacfdSMauro Carvalho Chehab} 17881da177e4SLinus Torvalds 17891da177e4SLinus Torvaldssub reset_state { 17901da177e4SLinus Torvalds $function = ""; 17911da177e4SLinus Torvalds %parameterdescs = (); 17921da177e4SLinus Torvalds %parametertypes = (); 17931da177e4SLinus Torvalds @parameterlist = (); 17941da177e4SLinus Torvalds %sections = (); 17951da177e4SLinus Torvalds @sectionlist = (); 1796a1d94aa5SRandy Dunlap $sectcheck = ""; 1797a1d94aa5SRandy Dunlap $struct_actual = ""; 17981da177e4SLinus Torvalds $prototype = ""; 17991da177e4SLinus Torvalds 180048af606aSJani Nikula $state = STATE_NORMAL; 180148af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 18021da177e4SLinus Torvalds} 18031da177e4SLinus Torvalds 180456afb0f8SJason Baronsub tracepoint_munge($) { 180556afb0f8SJason Baron my $file = shift; 180656afb0f8SJason Baron my $tracepointname = 0; 180756afb0f8SJason Baron my $tracepointargs = 0; 180856afb0f8SJason Baron 180956afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 181056afb0f8SJason Baron $tracepointname = $1; 181156afb0f8SJason Baron } 18123a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 18133a9089fdSJason Baron $tracepointname = $1; 18143a9089fdSJason Baron } 18153a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 18163a9089fdSJason Baron $tracepointname = $2; 18173a9089fdSJason Baron } 18183a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 181956afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 182056afb0f8SJason Baron $tracepointargs = $1; 182156afb0f8SJason Baron } 182256afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 1823df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Unrecognized tracepoint format: \n". 1824df4bf98eSNiklas Söderlund "$prototype\n"); 182556afb0f8SJason Baron } else { 182656afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 182752042e2dSMauro Carvalho Chehab $identifier = "trace_$identifier"; 182856afb0f8SJason Baron } 182956afb0f8SJason Baron} 183056afb0f8SJason Baron 1831b4870bc5SRandy Dunlapsub syscall_munge() { 1832b4870bc5SRandy Dunlap my $void = 0; 1833b4870bc5SRandy Dunlap 18347c9aa015SMauro Carvalho Chehab $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's 1835b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 1836b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 1837b4870bc5SRandy Dunlap $void = 1; 1838b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 1839b4870bc5SRandy Dunlap } 1840b4870bc5SRandy Dunlap 1841b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 1842b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 1843b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 1844b4870bc5SRandy Dunlap } elsif ($void) { 1845b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 1846b4870bc5SRandy Dunlap } 1847b4870bc5SRandy Dunlap 1848b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 1849b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 1850b4870bc5SRandy Dunlap my $count = 0; 1851b4870bc5SRandy Dunlap my $len = length($prototype); 1852b4870bc5SRandy Dunlap if ($void) { 1853b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 1854b4870bc5SRandy Dunlap } 1855b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 1856b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 1857b4870bc5SRandy Dunlap $count++; 1858b4870bc5SRandy Dunlap if ($count % 2 == 1) { 1859b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 1860b4870bc5SRandy Dunlap } 1861b4870bc5SRandy Dunlap } 1862b4870bc5SRandy Dunlap } 1863b4870bc5SRandy Dunlap} 1864b4870bc5SRandy Dunlap 1865b7afa92bSDaniel Vettersub process_proto_function($$) { 18661da177e4SLinus Torvalds my $x = shift; 18671da177e4SLinus Torvalds my $file = shift; 18681da177e4SLinus Torvalds 186951f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 187051f5a0c8SRandy Dunlap 1871890c78c2SRandy Dunlap if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 18721da177e4SLinus Torvalds # do nothing 18731da177e4SLinus Torvalds } 18741da177e4SLinus Torvalds elsif ($x =~ /([^\{]*)/) { 18751da177e4SLinus Torvalds $prototype .= $1; 18761da177e4SLinus Torvalds } 1877b4870bc5SRandy Dunlap 1878890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 18791da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 18801da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 18811da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 18827ae281b0SMauro Carvalho Chehab 18837ae281b0SMauro Carvalho Chehab # Handle prototypes for function pointers like: 18847ae281b0SMauro Carvalho Chehab # int (*pcs_config)(struct foo) 18857ae281b0SMauro Carvalho Chehab $prototype =~ s@^(\S+\s+)\(\s*\*(\S+)\)@$1$2@gos; 18867ae281b0SMauro Carvalho Chehab 1887b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 1888b4870bc5SRandy Dunlap syscall_munge(); 1889b4870bc5SRandy Dunlap } 18903a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 18913a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 18923a9089fdSJason Baron { 189356afb0f8SJason Baron tracepoint_munge($file); 189456afb0f8SJason Baron } 18951da177e4SLinus Torvalds dump_function($prototype, $file); 18961da177e4SLinus Torvalds reset_state(); 18971da177e4SLinus Torvalds } 18981da177e4SLinus Torvalds} 18991da177e4SLinus Torvalds 1900b7afa92bSDaniel Vettersub process_proto_type($$) { 19011da177e4SLinus Torvalds my $x = shift; 19021da177e4SLinus Torvalds my $file = shift; 19031da177e4SLinus Torvalds 19041da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 19051da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 19061da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 190751f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 190851f5a0c8SRandy Dunlap 19091da177e4SLinus Torvalds if ($x =~ /^#/) { 19101da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 19111da177e4SLinus Torvalds $x .= ";"; 19121da177e4SLinus Torvalds } 19131da177e4SLinus Torvalds 19141da177e4SLinus Torvalds while (1) { 1915673bb2dfSBen Hutchings if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) { 1916463a0fdcSMarkus Heiser if( length $prototype ) { 1917463a0fdcSMarkus Heiser $prototype .= " " 1918463a0fdcSMarkus Heiser } 19191da177e4SLinus Torvalds $prototype .= $1 . $2; 19201da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 19211da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 19221da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 19231da177e4SLinus Torvalds dump_declaration($prototype, $file); 19241da177e4SLinus Torvalds reset_state(); 19251da177e4SLinus Torvalds last; 19261da177e4SLinus Torvalds } 19271da177e4SLinus Torvalds $x = $3; 19281da177e4SLinus Torvalds } else { 19291da177e4SLinus Torvalds $prototype .= $x; 19301da177e4SLinus Torvalds last; 19311da177e4SLinus Torvalds } 19321da177e4SLinus Torvalds } 19331da177e4SLinus Torvalds} 19341da177e4SLinus Torvalds 19356b5b55f6SRandy Dunlap 19361ad560e4SJani Nikulasub map_filename($) { 19371ad560e4SJani Nikula my $file; 19381ad560e4SJani Nikula my ($orig_file) = @_; 19391ad560e4SJani Nikula 19401ad560e4SJani Nikula if (defined($ENV{'SRCTREE'})) { 19411ad560e4SJani Nikula $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 19421ad560e4SJani Nikula } else { 19431ad560e4SJani Nikula $file = $orig_file; 19441ad560e4SJani Nikula } 19451ad560e4SJani Nikula 19461ad560e4SJani Nikula if (defined($source_map{$file})) { 19471ad560e4SJani Nikula $file = $source_map{$file}; 19481ad560e4SJani Nikula } 19491ad560e4SJani Nikula 19501ad560e4SJani Nikula return $file; 19511ad560e4SJani Nikula} 19521ad560e4SJani Nikula 195388c2b57dSJani Nikulasub process_export_file($) { 195488c2b57dSJani Nikula my ($orig_file) = @_; 195588c2b57dSJani Nikula my $file = map_filename($orig_file); 195688c2b57dSJani Nikula 195788c2b57dSJani Nikula if (!open(IN,"<$file")) { 195888c2b57dSJani Nikula print STDERR "Error: Cannot open file $file\n"; 195988c2b57dSJani Nikula ++$errors; 196088c2b57dSJani Nikula return; 196188c2b57dSJani Nikula } 196288c2b57dSJani Nikula 196388c2b57dSJani Nikula while (<IN>) { 196488c2b57dSJani Nikula if (/$export_symbol/) { 1965eab795ddSMauro Carvalho Chehab next if (defined($nosymbol_table{$2})); 196688c2b57dSJani Nikula $function_table{$2} = 1; 196788c2b57dSJani Nikula } 1968632ce137SJason Gunthorpe if (/$export_symbol_ns/) { 1969632ce137SJason Gunthorpe next if (defined($nosymbol_table{$2})); 1970632ce137SJason Gunthorpe $function_table{$2} = 1; 1971632ce137SJason Gunthorpe } 197288c2b57dSJani Nikula } 197388c2b57dSJani Nikula 197488c2b57dSJani Nikula close(IN); 197588c2b57dSJani Nikula} 197688c2b57dSJani Nikula 197707048d13SJonathan Corbet# 197807048d13SJonathan Corbet# Parsers for the various processing states. 197907048d13SJonathan Corbet# 198007048d13SJonathan Corbet# STATE_NORMAL: looking for the /** to begin everything. 198107048d13SJonathan Corbet# 198207048d13SJonathan Corbetsub process_normal() { 19831da177e4SLinus Torvalds if (/$doc_start/o) { 198448af606aSJani Nikula $state = STATE_NAME; # next line is always the function name 1985850622dfSRandy Dunlap $in_doc_sect = 0; 19860b0f5f29SDaniel Vetter $declaration_start_line = $. + 1; 19871da177e4SLinus Torvalds } 198807048d13SJonathan Corbet} 198907048d13SJonathan Corbet 19903cac2bc4SJonathan Corbet# 19913cac2bc4SJonathan Corbet# STATE_NAME: Looking for the "name - description" line 19923cac2bc4SJonathan Corbet# 19933cac2bc4SJonathan Corbetsub process_name($$) { 19943cac2bc4SJonathan Corbet my $file = shift; 19951da177e4SLinus Torvalds my $descr; 19961da177e4SLinus Torvalds 19971da177e4SLinus Torvalds if (/$doc_block/o) { 199848af606aSJani Nikula $state = STATE_DOCBLOCK; 19991da177e4SLinus Torvalds $contents = ""; 20005ef09c96SMauro Carvalho Chehab $new_start_line = $.; 20010b0f5f29SDaniel Vetter 20021da177e4SLinus Torvalds if ( $1 eq "" ) { 20031da177e4SLinus Torvalds $section = $section_intro; 20041da177e4SLinus Torvalds } else { 20051da177e4SLinus Torvalds $section = $1; 20061da177e4SLinus Torvalds } 200752042e2dSMauro Carvalho Chehab } elsif (/$doc_decl/o) { 20081da177e4SLinus Torvalds $identifier = $1; 20093e58e839SAditya Srivastava my $is_kernel_comment = 0; 2010e86bdb24SAditya Srivastava my $decl_start = qr{$doc_com}; 2011f9bbc12cSAditya Srivastava # test for pointer declaration type, foo * bar() - desc 2012f9bbc12cSAditya Srivastava my $fn_type = qr{\w+\s*\*\s*}; 2013f9bbc12cSAditya Srivastava my $parenthesis = qr{\(\w*\)}; 2014f9bbc12cSAditya Srivastava my $decl_end = qr{[-:].*}; 2015e86bdb24SAditya Srivastava if (/^$decl_start([\w\s]+?)$parenthesis?\s*$decl_end?$/) { 20161da177e4SLinus Torvalds $identifier = $1; 20171da177e4SLinus Torvalds } 201852042e2dSMauro Carvalho Chehab if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) { 201952042e2dSMauro Carvalho Chehab $decl_type = $1; 202052042e2dSMauro Carvalho Chehab $identifier = $2; 20213e58e839SAditya Srivastava $is_kernel_comment = 1; 202252042e2dSMauro Carvalho Chehab } 2023f9bbc12cSAditya Srivastava # Look for foo() or static void foo() - description; or misspelt 2024f9bbc12cSAditya Srivastava # identifier 2025e86bdb24SAditya Srivastava elsif (/^$decl_start$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ || 2026e86bdb24SAditya Srivastava /^$decl_start$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) { 2027f9bbc12cSAditya Srivastava $identifier = $1; 2028f9bbc12cSAditya Srivastava $decl_type = 'function'; 2029f9bbc12cSAditya Srivastava $identifier =~ s/^define\s+//; 2030f9bbc12cSAditya Srivastava $is_kernel_comment = 1; 2031f9bbc12cSAditya Srivastava } 203252042e2dSMauro Carvalho Chehab $identifier =~ s/\s+$//; 20331da177e4SLinus Torvalds 203417b78717SJonathan Corbet $state = STATE_BODY; 20350b0f5f29SDaniel Vetter # if there's no @param blocks need to set up default section 20360b0f5f29SDaniel Vetter # here 20372f4ad40aSJani Nikula $contents = ""; 20382f4ad40aSJani Nikula $section = $section_default; 20390b0f5f29SDaniel Vetter $new_start_line = $. + 1; 204052042e2dSMauro Carvalho Chehab if (/[-:](.*)/) { 204151f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2042a21217daSRandy Dunlap $descr= $1; 2043a21217daSRandy Dunlap $descr =~ s/^\s*//; 2044a21217daSRandy Dunlap $descr =~ s/\s*$//; 204512ae6779SDaniel Santos $descr =~ s/\s+/ /g; 20460bba924cSJonathan Corbet $declaration_purpose = $descr; 204717b78717SJonathan Corbet $state = STATE_BODY_MAYBE; 20481da177e4SLinus Torvalds } else { 20491da177e4SLinus Torvalds $declaration_purpose = ""; 20501da177e4SLinus Torvalds } 205177cc23b8SRandy Dunlap 20523e58e839SAditya Srivastava if (!$is_kernel_comment) { 2053df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst\n$_"); 20543e58e839SAditya Srivastava $state = STATE_NORMAL; 20553e58e839SAditya Srivastava } 20563e58e839SAditya Srivastava 205777cc23b8SRandy Dunlap if (($declaration_purpose eq "") && $verbose) { 2058df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "missing initial short description on line:\n$_"); 205977cc23b8SRandy Dunlap } 206077cc23b8SRandy Dunlap 20610b54c2e3SMauro Carvalho Chehab if ($identifier eq "" && $decl_type ne "enum") { 2062df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "wrong kernel-doc identifier on line:\n$_"); 206352042e2dSMauro Carvalho Chehab $state = STATE_NORMAL; 20641da177e4SLinus Torvalds } 20651da177e4SLinus Torvalds 20661da177e4SLinus Torvalds if ($verbose) { 206752042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: info: Scanning doc for $decl_type $identifier\n"; 20681da177e4SLinus Torvalds } 20691da177e4SLinus Torvalds } else { 2070df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Cannot understand $_ on line $. - I thought it was a doc line\n"); 207148af606aSJani Nikula $state = STATE_NORMAL; 20721da177e4SLinus Torvalds } 20733cac2bc4SJonathan Corbet} 20743cac2bc4SJonathan Corbet 20753cac2bc4SJonathan Corbet 2076d742f24dSJonathan Corbet# 2077d742f24dSJonathan Corbet# STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment. 2078d742f24dSJonathan Corbet# 2079d742f24dSJonathan Corbetsub process_body($$) { 2080d742f24dSJonathan Corbet my $file = shift; 20813cac2bc4SJonathan Corbet 208243756e34SJonathan Neuschäfer # Until all named variable macro parameters are 208343756e34SJonathan Neuschäfer # documented using the bare name (`x`) rather than with 208443756e34SJonathan Neuschäfer # dots (`x...`), strip the dots: 208543756e34SJonathan Neuschäfer if ($section =~ /\w\.\.\.$/) { 208643756e34SJonathan Neuschäfer $section =~ s/\.\.\.$//; 208743756e34SJonathan Neuschäfer 208843756e34SJonathan Neuschäfer if ($verbose) { 2089df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Variable macro arguments should be documented without dots\n"); 209043756e34SJonathan Neuschäfer } 209143756e34SJonathan Neuschäfer } 209243756e34SJonathan Neuschäfer 20930d55d48bSMauro Carvalho Chehab if ($state == STATE_BODY_WITH_BLANK_LINE && /^\s*\*\s?\S/) { 20940d55d48bSMauro Carvalho Chehab dump_section($file, $section, $contents); 20950d55d48bSMauro Carvalho Chehab $section = $section_default; 20965ef09c96SMauro Carvalho Chehab $new_start_line = $.; 20970d55d48bSMauro Carvalho Chehab $contents = ""; 20980d55d48bSMauro Carvalho Chehab } 20990d55d48bSMauro Carvalho Chehab 2100f624adefSJani Nikula if (/$doc_sect/i) { # case insensitive for supported section names 21011da177e4SLinus Torvalds $newsection = $1; 21021da177e4SLinus Torvalds $newcontents = $2; 21031da177e4SLinus Torvalds 2104f624adefSJani Nikula # map the supported section names to the canonical names 2105f624adefSJani Nikula if ($newsection =~ m/^description$/i) { 2106f624adefSJani Nikula $newsection = $section_default; 2107f624adefSJani Nikula } elsif ($newsection =~ m/^context$/i) { 2108f624adefSJani Nikula $newsection = $section_context; 2109f624adefSJani Nikula } elsif ($newsection =~ m/^returns?$/i) { 2110f624adefSJani Nikula $newsection = $section_return; 2111f624adefSJani Nikula } elsif ($newsection =~ m/^\@return$/) { 2112f624adefSJani Nikula # special: @return is a section, not a param description 2113f624adefSJani Nikula $newsection = $section_return; 2114f624adefSJani Nikula } 2115f624adefSJani Nikula 2116792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 2117850622dfSRandy Dunlap if (!$in_doc_sect && $verbose) { 2118df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "contents before sections\n"); 2119850622dfSRandy Dunlap } 21200bba924cSJonathan Corbet dump_section($file, $section, $contents); 21211da177e4SLinus Torvalds $section = $section_default; 21221da177e4SLinus Torvalds } 21231da177e4SLinus Torvalds 2124850622dfSRandy Dunlap $in_doc_sect = 1; 212517b78717SJonathan Corbet $state = STATE_BODY; 21261da177e4SLinus Torvalds $contents = $newcontents; 21270b0f5f29SDaniel Vetter $new_start_line = $.; 21287c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 212905189497SRandy Dunlap $contents = substr($contents, 1); 213005189497SRandy Dunlap } 21310a726301SJani Nikula if ($contents ne "") { 21321da177e4SLinus Torvalds $contents .= "\n"; 21331da177e4SLinus Torvalds } 21341da177e4SLinus Torvalds $section = $newsection; 2135b7886de4SJani Nikula $leading_space = undef; 21361da177e4SLinus Torvalds } elsif (/$doc_end/) { 21374c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 21380bba924cSJonathan Corbet dump_section($file, $section, $contents); 21391da177e4SLinus Torvalds $section = $section_default; 21401da177e4SLinus Torvalds $contents = ""; 21411da177e4SLinus Torvalds } 214246b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 214346b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2144df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "suspicious ending line: $_"); 214546b958ebSRandy Dunlap } 21461da177e4SLinus Torvalds 21471da177e4SLinus Torvalds $prototype = ""; 214848af606aSJani Nikula $state = STATE_PROTO; 21491da177e4SLinus Torvalds $brcount = 0; 21505ef09c96SMauro Carvalho Chehab $new_start_line = $. + 1; 21511da177e4SLinus Torvalds } elsif (/$doc_content/) { 21526423133bSJohannes Weiner if ($1 eq "") { 21530d55d48bSMauro Carvalho Chehab if ($section eq $section_context) { 21540bba924cSJonathan Corbet dump_section($file, $section, $contents); 21551da177e4SLinus Torvalds $section = $section_default; 21561da177e4SLinus Torvalds $contents = ""; 21570b0f5f29SDaniel Vetter $new_start_line = $.; 21580d55d48bSMauro Carvalho Chehab $state = STATE_BODY; 21591da177e4SLinus Torvalds } else { 21600d55d48bSMauro Carvalho Chehab if ($section ne $section_default) { 21610d55d48bSMauro Carvalho Chehab $state = STATE_BODY_WITH_BLANK_LINE; 21620d55d48bSMauro Carvalho Chehab } else { 21630d55d48bSMauro Carvalho Chehab $state = STATE_BODY; 21640d55d48bSMauro Carvalho Chehab } 21656423133bSJohannes Weiner $contents .= "\n"; 21666423133bSJohannes Weiner } 216717b78717SJonathan Corbet } elsif ($state == STATE_BODY_MAYBE) { 21686423133bSJohannes Weiner # Continued declaration purpose 21696423133bSJohannes Weiner chomp($declaration_purpose); 21700bba924cSJonathan Corbet $declaration_purpose .= " " . $1; 217112ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 21726423133bSJohannes Weiner } else { 2173b7886de4SJani Nikula my $cont = $1; 2174b7886de4SJani Nikula if ($section =~ m/^@/ || $section eq $section_context) { 2175b7886de4SJani Nikula if (!defined $leading_space) { 2176b7886de4SJani Nikula if ($cont =~ m/^(\s+)/) { 2177b7886de4SJani Nikula $leading_space = $1; 2178b7886de4SJani Nikula } else { 2179b7886de4SJani Nikula $leading_space = ""; 2180b7886de4SJani Nikula } 2181b7886de4SJani Nikula } 2182b7886de4SJani Nikula $cont =~ s/^$leading_space//; 2183b7886de4SJani Nikula } 2184b7886de4SJani Nikula $contents .= $cont . "\n"; 21851da177e4SLinus Torvalds } 21861da177e4SLinus Torvalds } else { 21871da177e4SLinus Torvalds # i dont know - bad line? ignore. 2188df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "bad line: $_"); 21891da177e4SLinus Torvalds } 2190d742f24dSJonathan Corbet} 2191d742f24dSJonathan Corbet 2192d742f24dSJonathan Corbet 2193cc794812SJonathan Corbet# 2194cc794812SJonathan Corbet# STATE_PROTO: reading a function/whatever prototype. 2195cc794812SJonathan Corbet# 2196cc794812SJonathan Corbetsub process_proto($$) { 2197cc794812SJonathan Corbet my $file = shift; 2198cc794812SJonathan Corbet 2199cc794812SJonathan Corbet if (/$doc_inline_oneline/) { 2200cc794812SJonathan Corbet $section = $1; 2201cc794812SJonathan Corbet $contents = $2; 2202cc794812SJonathan Corbet if ($contents ne "") { 2203cc794812SJonathan Corbet $contents .= "\n"; 2204cc794812SJonathan Corbet dump_section($file, $section, $contents); 2205cc794812SJonathan Corbet $section = $section_default; 2206cc794812SJonathan Corbet $contents = ""; 2207cc794812SJonathan Corbet } 2208cc794812SJonathan Corbet } elsif (/$doc_inline_start/) { 2209cc794812SJonathan Corbet $state = STATE_INLINE; 2210cc794812SJonathan Corbet $inline_doc_state = STATE_INLINE_NAME; 2211cc794812SJonathan Corbet } elsif ($decl_type eq 'function') { 2212cc794812SJonathan Corbet process_proto_function($_, $file); 2213cc794812SJonathan Corbet } else { 2214cc794812SJonathan Corbet process_proto_type($_, $file); 2215cc794812SJonathan Corbet } 2216cc794812SJonathan Corbet} 2217cc794812SJonathan Corbet 2218c17add56SJonathan Corbet# 2219c17add56SJonathan Corbet# STATE_DOCBLOCK: within a DOC: block. 2220c17add56SJonathan Corbet# 2221c17add56SJonathan Corbetsub process_docblock($$) { 2222c17add56SJonathan Corbet my $file = shift; 2223cc794812SJonathan Corbet 2224c17add56SJonathan Corbet if (/$doc_end/) { 2225c17add56SJonathan Corbet dump_doc_section($file, $section, $contents); 2226c17add56SJonathan Corbet $section = $section_default; 2227c17add56SJonathan Corbet $contents = ""; 2228c17add56SJonathan Corbet $function = ""; 2229c17add56SJonathan Corbet %parameterdescs = (); 2230c17add56SJonathan Corbet %parametertypes = (); 2231c17add56SJonathan Corbet @parameterlist = (); 2232c17add56SJonathan Corbet %sections = (); 2233c17add56SJonathan Corbet @sectionlist = (); 2234c17add56SJonathan Corbet $prototype = ""; 2235c17add56SJonathan Corbet $state = STATE_NORMAL; 2236c17add56SJonathan Corbet } elsif (/$doc_content/) { 2237c17add56SJonathan Corbet if ( $1 eq "" ) { 2238c17add56SJonathan Corbet $contents .= $blankline; 2239c17add56SJonathan Corbet } else { 2240c17add56SJonathan Corbet $contents .= $1 . "\n"; 2241c17add56SJonathan Corbet } 2242c17add56SJonathan Corbet } 2243d742f24dSJonathan Corbet} 2244d742f24dSJonathan Corbet 2245c17add56SJonathan Corbet# 2246c17add56SJonathan Corbet# STATE_INLINE: docbook comments within a prototype. 2247c17add56SJonathan Corbet# 2248c17add56SJonathan Corbetsub process_inline($$) { 2249c17add56SJonathan Corbet my $file = shift; 2250d742f24dSJonathan Corbet 2251a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 225248af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 2253a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 2254a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 22550b0f5f29SDaniel Vetter $new_start_line = $.; 2256a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 22577c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 2258a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 2259a4c6ebedSDanilo Cesar Lemes de Paula } 2260a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 2261a4c6ebedSDanilo Cesar Lemes de Paula } 226248af606aSJani Nikula $inline_doc_state = STATE_INLINE_TEXT; 2263a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 226448af606aSJani Nikula } elsif (/$doc_inline_end/) { 2265a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 22660bba924cSJonathan Corbet dump_section($file, $section, $contents); 2267a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 2268a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 2269a4c6ebedSDanilo Cesar Lemes de Paula } 227048af606aSJani Nikula $state = STATE_PROTO; 227148af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 2272a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 2273a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 227448af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_TEXT) { 2275a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 22766450c895SJani Nikula # nuke leading blank lines 22776450c895SJani Nikula if ($contents =~ /^\s*$/) { 22786450c895SJani Nikula $contents = ""; 22796450c895SJani Nikula } 228048af606aSJani Nikula } elsif ($inline_doc_state == STATE_INLINE_NAME) { 228148af606aSJani Nikula $inline_doc_state = STATE_INLINE_ERROR; 2282df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Incorrect use of kernel-doc format: $_"); 2283a4c6ebedSDanilo Cesar Lemes de Paula } 2284a4c6ebedSDanilo Cesar Lemes de Paula } 22850c9aa209SJani Nikula} 2286c17add56SJonathan Corbet 2287c17add56SJonathan Corbet 2288c17add56SJonathan Corbetsub process_file($) { 2289c17add56SJonathan Corbet my $file; 2290c17add56SJonathan Corbet my $initial_section_counter = $section_counter; 2291c17add56SJonathan Corbet my ($orig_file) = @_; 2292c17add56SJonathan Corbet 2293c17add56SJonathan Corbet $file = map_filename($orig_file); 2294c17add56SJonathan Corbet 2295dbe8ba00SMauro Carvalho Chehab if (!open(IN_FILE,"<$file")) { 2296c17add56SJonathan Corbet print STDERR "Error: Cannot open file $file\n"; 2297c17add56SJonathan Corbet ++$errors; 2298c17add56SJonathan Corbet return; 22991da177e4SLinus Torvalds } 2300c17add56SJonathan Corbet 2301c17add56SJonathan Corbet $. = 1; 2302c17add56SJonathan Corbet 2303c17add56SJonathan Corbet $section_counter = 0; 2304dbe8ba00SMauro Carvalho Chehab while (<IN_FILE>) { 2305c17add56SJonathan Corbet while (s/\\\s*$//) { 2306dbe8ba00SMauro Carvalho Chehab $_ .= <IN_FILE>; 2307c17add56SJonathan Corbet } 2308c17add56SJonathan Corbet # Replace tabs by spaces 2309c17add56SJonathan Corbet while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; 2310c17add56SJonathan Corbet # Hand this line to the appropriate state handler 2311c17add56SJonathan Corbet if ($state == STATE_NORMAL) { 2312c17add56SJonathan Corbet process_normal(); 2313c17add56SJonathan Corbet } elsif ($state == STATE_NAME) { 2314c17add56SJonathan Corbet process_name($file, $_); 23150d55d48bSMauro Carvalho Chehab } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE || 23160d55d48bSMauro Carvalho Chehab $state == STATE_BODY_WITH_BLANK_LINE) { 2317c17add56SJonathan Corbet process_body($file, $_); 2318c17add56SJonathan Corbet } elsif ($state == STATE_INLINE) { # scanning for inline parameters 2319c17add56SJonathan Corbet process_inline($file, $_); 2320cc794812SJonathan Corbet } elsif ($state == STATE_PROTO) { 2321cc794812SJonathan Corbet process_proto($file, $_); 232248af606aSJani Nikula } elsif ($state == STATE_DOCBLOCK) { 2323c17add56SJonathan Corbet process_docblock($file, $_); 23241da177e4SLinus Torvalds } 23251da177e4SLinus Torvalds } 2326c17add56SJonathan Corbet 2327c17add56SJonathan Corbet # Make sure we got something interesting. 2328b0d60bfbSJonathan Corbet if ($initial_section_counter == $section_counter && $ 2329b0d60bfbSJonathan Corbet output_mode ne "none") { 2330b0d60bfbSJonathan Corbet if ($output_selection == OUTPUT_INCLUDE) { 2331df4bf98eSNiklas Söderlund emit_warning("${file}:1", "'$_' not found\n") 2332b0d60bfbSJonathan Corbet for keys %function_table; 23333a025e1dSMatthew Wilcox } 2334b0d60bfbSJonathan Corbet else { 2335df4bf98eSNiklas Söderlund emit_warning("${file}:1", "no structured comments found\n"); 2336e946c43aSJohannes Berg } 23371da177e4SLinus Torvalds } 2338dbe8ba00SMauro Carvalho Chehab close IN_FILE; 23391da177e4SLinus Torvalds} 23408484baaaSRandy Dunlap 23418484baaaSRandy Dunlap 234293351d41SMauro Carvalho Chehabif ($output_mode eq "rst") { 234393351d41SMauro Carvalho Chehab get_sphinx_version() if (!$sphinx_major); 234493351d41SMauro Carvalho Chehab} 234593351d41SMauro Carvalho Chehab 23468484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 23478484baaaSRandy Dunlap 23488484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 23498484baaaSRandy Dunlap# using the s// operator. 23501ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 23514d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 23524d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 23534d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 23544d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 23558484baaaSRandy Dunlap} 23568484baaaSRandy Dunlap 23578484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 23588484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 23598484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 23608484baaaSRandy Dunlap my ($relname, $absname); 23618484baaaSRandy Dunlap while(<SOURCE_MAP>) { 23628484baaaSRandy Dunlap chop(); 23638484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 23648484baaaSRandy Dunlap $relname =~ s:^/+::; 23658484baaaSRandy Dunlap $source_map{$relname} = $absname; 23668484baaaSRandy Dunlap } 23678484baaaSRandy Dunlap close(SOURCE_MAP); 23688484baaaSRandy Dunlap} 23698484baaaSRandy Dunlap 237088c2b57dSJani Nikulaif ($output_selection == OUTPUT_EXPORTED || 237188c2b57dSJani Nikula $output_selection == OUTPUT_INTERNAL) { 2372c9b2cfb3SJani Nikula 2373c9b2cfb3SJani Nikula push(@export_file_list, @ARGV); 2374c9b2cfb3SJani Nikula 237588c2b57dSJani Nikula foreach (@export_file_list) { 237688c2b57dSJani Nikula chomp; 237788c2b57dSJani Nikula process_export_file($_); 237888c2b57dSJani Nikula } 237988c2b57dSJani Nikula} 238088c2b57dSJani Nikula 23818484baaaSRandy Dunlapforeach (@ARGV) { 23828484baaaSRandy Dunlap chomp; 23838484baaaSRandy Dunlap process_file($_); 23848484baaaSRandy Dunlap} 23858484baaaSRandy Dunlapif ($verbose && $errors) { 23868484baaaSRandy Dunlap print STDERR "$errors errors\n"; 23878484baaaSRandy Dunlap} 23888484baaaSRandy Dunlapif ($verbose && $warnings) { 23898484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 23908484baaaSRandy Dunlap} 23918484baaaSRandy Dunlap 23922c12c810SPierre-Louis Bossartif ($Werror && $warnings) { 23932c12c810SPierre-Louis Bossart print STDERR "$warnings warnings as Errors\n"; 23942c12c810SPierre-Louis Bossart exit($warnings); 23952c12c810SPierre-Louis Bossart} else { 23962c12c810SPierre-Louis Bossart exit($output_mode eq "none" ? 0 : $errors) 23972c12c810SPierre-Louis Bossart} 23982875f787STomasz Warniełło 23992875f787STomasz Warniełło__END__ 24002875f787STomasz Warniełło 24012875f787STomasz Warniełło=head1 OPTIONS 24022875f787STomasz Warniełło 24032875f787STomasz Warniełło=head2 Output format selection (mutually exclusive): 24042875f787STomasz Warniełło 24052875f787STomasz Warniełło=over 8 24062875f787STomasz Warniełło 24072875f787STomasz Warniełło=item -man 24082875f787STomasz Warniełło 24092875f787STomasz WarniełłoOutput troff manual page format. 24102875f787STomasz Warniełło 24112875f787STomasz Warniełło=item -rst 24122875f787STomasz Warniełło 24132875f787STomasz WarniełłoOutput reStructuredText format. This is the default. 24142875f787STomasz Warniełło 24152875f787STomasz Warniełło=item -none 24162875f787STomasz Warniełło 24172875f787STomasz WarniełłoDo not output documentation, only warnings. 24182875f787STomasz Warniełło 24192875f787STomasz Warniełło=back 24202875f787STomasz Warniełło 2421dd803b04STomasz Warniełło=head2 Output format modifiers 2422dd803b04STomasz Warniełło 2423dd803b04STomasz Warniełło=head3 reStructuredText only 2424dd803b04STomasz Warniełło 2425dd803b04STomasz Warniełło=over 8 2426dd803b04STomasz Warniełło 2427dd803b04STomasz Warniełło=item -sphinx-version VERSION 2428dd803b04STomasz Warniełło 2429dd803b04STomasz WarniełłoUse the ReST C domain dialect compatible with a specific Sphinx Version. 2430dd803b04STomasz Warniełło 2431dd803b04STomasz WarniełłoIf not specified, kernel-doc will auto-detect using the sphinx-build version 2432dd803b04STomasz Warniełłofound on PATH. 2433dd803b04STomasz Warniełło 2434dd803b04STomasz Warniełło=back 2435dd803b04STomasz Warniełło 24369c77f108STomasz Warniełło=head2 Output selection (mutually exclusive): 24379c77f108STomasz Warniełło 24389c77f108STomasz Warniełło=over 8 24399c77f108STomasz Warniełło 24409c77f108STomasz Warniełło=item -export 24419c77f108STomasz Warniełło 24429c77f108STomasz WarniełłoOnly output documentation for the symbols that have been exported using 2443632ce137SJason GunthorpeEXPORT_SYMBOL() and related macros in any input FILE or -export-file FILE. 24449c77f108STomasz Warniełło 24459c77f108STomasz Warniełło=item -internal 24469c77f108STomasz Warniełło 24479c77f108STomasz WarniełłoOnly output documentation for the symbols that have NOT been exported using 2448632ce137SJason GunthorpeEXPORT_SYMBOL() and related macros in any input FILE or -export-file FILE. 24499c77f108STomasz Warniełło 24509c77f108STomasz Warniełło=item -function NAME 24519c77f108STomasz Warniełło 24529c77f108STomasz WarniełłoOnly output documentation for the given function or DOC: section title. 24539c77f108STomasz WarniełłoAll other functions and DOC: sections are ignored. 24549c77f108STomasz Warniełło 24559c77f108STomasz WarniełłoMay be specified multiple times. 24569c77f108STomasz Warniełło 24579c77f108STomasz Warniełło=item -nosymbol NAME 24589c77f108STomasz Warniełło 24599c77f108STomasz WarniełłoExclude the specified symbol from the output documentation. 24609c77f108STomasz Warniełło 24619c77f108STomasz WarniełłoMay be specified multiple times. 24629c77f108STomasz Warniełło 24639c77f108STomasz Warniełło=back 24649c77f108STomasz Warniełło 2465c15de5a1STomasz Warniełło=head2 Output selection modifiers: 2466c15de5a1STomasz Warniełło 2467c15de5a1STomasz Warniełło=over 8 2468c15de5a1STomasz Warniełło 2469c15de5a1STomasz Warniełło=item -no-doc-sections 2470c15de5a1STomasz Warniełło 2471c15de5a1STomasz WarniełłoDo not output DOC: sections. 2472c15de5a1STomasz Warniełło 2473c15de5a1STomasz Warniełło=item -export-file FILE 2474c15de5a1STomasz Warniełło 2475632ce137SJason GunthorpeSpecify an additional FILE in which to look for EXPORT_SYMBOL information. 2476c15de5a1STomasz Warniełło 2477c15de5a1STomasz WarniełłoTo be used with -export or -internal. 2478c15de5a1STomasz Warniełło 2479c15de5a1STomasz WarniełłoMay be specified multiple times. 2480c15de5a1STomasz Warniełło 2481c15de5a1STomasz Warniełło=back 2482c15de5a1STomasz Warniełło 2483c15de5a1STomasz Warniełło=head3 reStructuredText only 2484c15de5a1STomasz Warniełło 2485c15de5a1STomasz Warniełło=over 8 2486c15de5a1STomasz Warniełło 2487c15de5a1STomasz Warniełło=item -enable-lineno 2488c15de5a1STomasz Warniełło 2489b79dfef0SMauro Carvalho ChehabEnable output of .. LINENO lines. 2490c15de5a1STomasz Warniełło 2491c15de5a1STomasz Warniełło=back 2492c15de5a1STomasz Warniełło 2493834cf6b9STomasz Warniełło=head2 Other parameters: 2494834cf6b9STomasz Warniełło 2495834cf6b9STomasz Warniełło=over 8 2496834cf6b9STomasz Warniełło 2497834cf6b9STomasz Warniełło=item -h, -help 2498834cf6b9STomasz Warniełło 2499834cf6b9STomasz WarniełłoPrint this help. 2500834cf6b9STomasz Warniełło 2501834cf6b9STomasz Warniełło=item -v 2502834cf6b9STomasz Warniełło 2503834cf6b9STomasz WarniełłoVerbose output, more warnings and other information. 2504834cf6b9STomasz Warniełło 2505834cf6b9STomasz Warniełło=item -Werror 2506834cf6b9STomasz Warniełło 2507834cf6b9STomasz WarniełłoTreat warnings as errors. 2508834cf6b9STomasz Warniełło 2509834cf6b9STomasz Warniełło=back 2510834cf6b9STomasz Warniełło 25112875f787STomasz Warniełło=cut 2512