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 26dcd39fa2SAndy Shevchenko kernel-doc [-h] [-v] [-Werror] [-Wall] [-Wreturn] [-Wshort-desc[ription]] [-Wcontents-before-sections] 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+))*(\.\.\.)?)'; 678aaf297aSMark Rutlandmy $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``"], 102*af404fb1SVegard Nossum 103f3341dcfSJani Nikula # Note: need to escape () to avoid func matching later 1045267dd35SPaolo Bonzini [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], 1055267dd35SPaolo Bonzini [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], 1065219f18aSJonathan Corbet [$type_fp_param, "**\$1\\\\(\\\\)**"], 107346282dbSMauro Carvalho Chehab [$type_fp_param2, "**\$1\\\\(\\\\)**"], 108344fdb28SJonathan Corbet [$type_func, "\$1()"], 109df31175bSPaolo Bonzini [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], 110df31175bSPaolo Bonzini [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], 111df31175bSPaolo Bonzini [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], 112df31175bSPaolo Bonzini [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], 113*af404fb1SVegard Nossum 114a7291e7eSJani Nikula # in rst this can refer to any type 115df31175bSPaolo Bonzini [$type_fallback, "\\:c\\:type\\:`\$1`"], 116ee2aa759SMauro Carvalho Chehab [$type_param_ref, "**\$1\$2**"] 117c0d1b6eeSJonathan Corbet ); 118c0d1b6eeSJonathan Corbetmy $blankline_rst = "\n"; 119c0d1b6eeSJonathan Corbet 1201da177e4SLinus Torvalds# read arguments 1211da177e4SLinus Torvaldsif ($#ARGV == -1) { 12243caf1a6STomasz Warniełło pod2usage( 12343caf1a6STomasz Warniełło -message => "No arguments!\n", 12443caf1a6STomasz Warniełło -exitval => 1, 12543caf1a6STomasz Warniełło -verbose => 99, 12643caf1a6STomasz Warniełło -sections => 'SYNOPSIS', 12743caf1a6STomasz Warniełło -output => \*STDERR, 12843caf1a6STomasz Warniełło ); 1291da177e4SLinus Torvalds} 1301da177e4SLinus Torvalds 1318484baaaSRandy Dunlapmy $kernelversion; 13293351d41SMauro Carvalho Chehabmy ($sphinx_major, $sphinx_minor, $sphinx_patch); 133efa44475SMauro Carvalho Chehab 1348484baaaSRandy Dunlapmy $dohighlight = ""; 1358484baaaSRandy Dunlap 1361da177e4SLinus Torvaldsmy $verbose = 0; 1372c12c810SPierre-Louis Bossartmy $Werror = 0; 13856b0f453SJohannes Bergmy $Wreturn = 0; 13956b0f453SJohannes Bergmy $Wshort_desc = 0; 14056b0f453SJohannes Bergmy $Wcontents_before_sections = 0; 141bdfe2be3SMauro Carvalho Chehabmy $output_mode = "rst"; 142e314ba31SDaniel Santosmy $output_preformatted = 0; 1434b44595aSJohannes Bergmy $no_doc_sections = 0; 1440b0f5f29SDaniel Vettermy $enable_lineno = 0; 145bdfe2be3SMauro Carvalho Chehabmy @highlights = @highlights_rst; 146bdfe2be3SMauro Carvalho Chehabmy $blankline = $blankline_rst; 1471da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 148b6c3f456SJani Nikula 149b6c3f456SJani Nikulause constant { 150b6c3f456SJani Nikula OUTPUT_ALL => 0, # output all symbols and doc sections 151b6c3f456SJani Nikula OUTPUT_INCLUDE => 1, # output only specified symbols 152eab795ddSMauro Carvalho Chehab OUTPUT_EXPORTED => 2, # output exported symbols 153eab795ddSMauro Carvalho Chehab OUTPUT_INTERNAL => 3, # output non-exported symbols 154b6c3f456SJani Nikula}; 155b6c3f456SJani Nikulamy $output_selection = OUTPUT_ALL; 156b0d60bfbSJonathan Corbetmy $show_not_found = 0; # No longer used 157b2c4105bSBen Hutchings 15888c2b57dSJani Nikulamy @export_file_list; 15988c2b57dSJani Nikula 160b2c4105bSBen Hutchingsmy @build_time; 161b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 162b2c4105bSBen Hutchings (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 163b2c4105bSBen Hutchings @build_time = gmtime($seconds); 164b2c4105bSBen Hutchings} else { 165b2c4105bSBen Hutchings @build_time = localtime; 166b2c4105bSBen Hutchings} 167b2c4105bSBen Hutchings 1681da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 1691da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 170b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 171b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 1721da177e4SLinus Torvalds 1738484baaaSRandy Dunlap# Essentially these are globals. 174b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 175b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 1761da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 1771da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 178eab795ddSMauro Carvalho Chehabmy %nosymbol_table = (); 1790b0f5f29SDaniel Vettermy $declaration_start_line; 1801da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 1811c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 1821da177e4SLinus Torvalds 183c0d3b831SMasahiro Yamadaif (defined($ENV{'KBUILD_VERBOSE'}) && $ENV{'KBUILD_VERBOSE'} =~ '1') { 184c0d3b831SMasahiro Yamada $verbose = 1; 185bd0e88e5SRandy Dunlap} 186bd0e88e5SRandy Dunlap 1872c12c810SPierre-Louis Bossartif (defined($ENV{'KCFLAGS'})) { 1882c12c810SPierre-Louis Bossart my $kcflags = "$ENV{'KCFLAGS'}"; 1892c12c810SPierre-Louis Bossart 190cf63348bSYujie Liu if ($kcflags =~ /(\s|^)-Werror(\s|$)/) { 1912c12c810SPierre-Louis Bossart $Werror = 1; 1922c12c810SPierre-Louis Bossart } 1932c12c810SPierre-Louis Bossart} 1942c12c810SPierre-Louis Bossart 19556b0f453SJohannes Berg# reading this variable is for backwards compat just in case 19656b0f453SJohannes Berg# someone was calling it with the variable from outside the 19756b0f453SJohannes Berg# kernel's build system 198bed4ed30SLaurent Pinchartif (defined($ENV{'KDOC_WERROR'})) { 199bed4ed30SLaurent Pinchart $Werror = "$ENV{'KDOC_WERROR'}"; 200bed4ed30SLaurent Pinchart} 20156b0f453SJohannes Berg# other environment variables are converted to command-line 20256b0f453SJohannes Berg# arguments in cmd_checkdoc in the build system 203bed4ed30SLaurent Pinchart 2041da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 2051da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 20693431e06SAlexander A. Klimov# https://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 2071da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 2081da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 2091da177e4SLinus Torvalds# into html. 2101da177e4SLinus Torvaldsmy $section_counter = 0; 2111da177e4SLinus Torvalds 2121da177e4SLinus Torvaldsmy $lineprefix=""; 2131da177e4SLinus Torvalds 21448af606aSJani Nikula# Parser states 21548af606aSJani Nikulause constant { 21648af606aSJani Nikula STATE_NORMAL => 0, # normal code 21748af606aSJani Nikula STATE_NAME => 1, # looking for function name 21817b78717SJonathan Corbet STATE_BODY_MAYBE => 2, # body - or maybe more description 21917b78717SJonathan Corbet STATE_BODY => 3, # the body of the comment 2200d55d48bSMauro Carvalho Chehab STATE_BODY_WITH_BLANK_LINE => 4, # the body, which has a blank line 2210d55d48bSMauro Carvalho Chehab STATE_PROTO => 5, # scanning prototype 2220d55d48bSMauro Carvalho Chehab STATE_DOCBLOCK => 6, # documentation block 2230d55d48bSMauro Carvalho Chehab STATE_INLINE => 7, # gathering doc outside main block 22448af606aSJani Nikula}; 2251da177e4SLinus Torvaldsmy $state; 226850622dfSRandy Dunlapmy $in_doc_sect; 227d742f24dSJonathan Corbetmy $leading_space; 2281da177e4SLinus Torvalds 22948af606aSJani Nikula# Inline documentation state 23048af606aSJani Nikulause constant { 23148af606aSJani Nikula STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 23248af606aSJani Nikula STATE_INLINE_NAME => 1, # looking for member name (@foo:) 23348af606aSJani Nikula STATE_INLINE_TEXT => 2, # looking for member documentation 23448af606aSJani Nikula STATE_INLINE_END => 3, # done 23548af606aSJani Nikula STATE_INLINE_ERROR => 4, # error - Comment without header was found. 23648af606aSJani Nikula # Spit a warning as it's not 237a4c6ebedSDanilo Cesar Lemes de Paula # proper kernel-doc and ignore the rest. 23848af606aSJani Nikula}; 23948af606aSJani Nikulamy $inline_doc_state; 240a4c6ebedSDanilo Cesar Lemes de Paula 2411da177e4SLinus Torvalds#declaration types: can be 2421da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 2431da177e4SLinus Torvaldsmy $decl_type; 2441da177e4SLinus Torvalds 24552042e2dSMauro Carvalho Chehab# Name of the kernel-doc identifier for non-DOC markups 24652042e2dSMauro Carvalho Chehabmy $identifier; 24752042e2dSMauro Carvalho Chehab 2481da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 2491da177e4SLinus Torvaldsmy $doc_end = '\*/'; 2501da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 25112ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 2521da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 253f624adefSJani Nikula# @params and a strictly limited set of supported section names 254212209cfSJonathan Corbet# Specifically: 255212209cfSJonathan Corbet# Match @word: 256212209cfSJonathan Corbet# @...: 257212209cfSJonathan Corbet# @{section-name}: 258212209cfSJonathan Corbet# while trying to not match literal block starts like "example::" 259212209cfSJonathan Corbet# 2608569de68SJonathan Corbetmy $doc_sect = $doc_com . 261212209cfSJonathan Corbet '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:([^:].*)?$'; 26212ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 2631da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 26448af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$'; 265fe7bc493SMauro Carvalho Chehabmy $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)'; 26648af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$'; 2670c9aa209SJani Nikulamy $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; 26886ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 269632ce137SJason Gunthorpemy $export_symbol_ns = '^\s*EXPORT_SYMBOL_NS(_GPL)?\s*\(\s*(\w+)\s*,\s*\w+\)\s*;'; 270e86bdb24SAditya Srivastavamy $function_pointer = qr{([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)}; 271e86bdb24SAditya Srivastavamy $attribute = qr{__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)}i; 2721da177e4SLinus Torvalds 2731da177e4SLinus Torvaldsmy %parameterdescs; 2740b0f5f29SDaniel Vettermy %parameterdesc_start_lines; 2751da177e4SLinus Torvaldsmy @parameterlist; 2761da177e4SLinus Torvaldsmy %sections; 2771da177e4SLinus Torvaldsmy @sectionlist; 2780b0f5f29SDaniel Vettermy %section_start_lines; 279a1d94aa5SRandy Dunlapmy $sectcheck; 280a1d94aa5SRandy Dunlapmy $struct_actual; 2811da177e4SLinus Torvalds 2821da177e4SLinus Torvaldsmy $contents = ""; 2830b0f5f29SDaniel Vettermy $new_start_line = 0; 284f624adefSJani Nikula 285f624adefSJani Nikula# the canonical section names. see also $doc_sect above. 2861da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 2871da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 2881da177e4SLinus Torvaldsmy $section = $section_default; 2891da177e4SLinus Torvaldsmy $section_context = "Context"; 2904092bac7SYacine Belkadimy $section_return = "Return"; 2911da177e4SLinus Torvalds 2921da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 2931da177e4SLinus Torvalds 2941da177e4SLinus Torvaldsreset_state(); 2951da177e4SLinus Torvalds 296b031ac4eSMauro Carvalho Chehabwhile ($ARGV[0] =~ m/^--?(.*)/) { 297b031ac4eSMauro Carvalho Chehab my $cmd = $1; 298b031ac4eSMauro Carvalho Chehab shift @ARGV; 299b031ac4eSMauro Carvalho Chehab if ($cmd eq "man") { 3001da177e4SLinus Torvalds $output_mode = "man"; 3014d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 3021da177e4SLinus Torvalds $blankline = $blankline_man; 303b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "rst") { 304c0d1b6eeSJonathan Corbet $output_mode = "rst"; 305c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 306c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 307b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "none") { 3083a025e1dSMatthew Wilcox $output_mode = "none"; 309b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document 3101da177e4SLinus Torvalds $modulename = shift @ARGV; 311b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "function") { # to only output specific functions 312b6c3f456SJani Nikula $output_selection = OUTPUT_INCLUDE; 3131da177e4SLinus Torvalds $function = shift @ARGV; 3141da177e4SLinus Torvalds $function_table{$function} = 1; 315eab795ddSMauro Carvalho Chehab } elsif ($cmd eq "nosymbol") { # Exclude specific symbols 316eab795ddSMauro Carvalho Chehab my $symbol = shift @ARGV; 317eab795ddSMauro Carvalho Chehab $nosymbol_table{$symbol} = 1; 318b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export") { # only exported symbols 319b6c3f456SJani Nikula $output_selection = OUTPUT_EXPORTED; 320da9726ecSJani Nikula %function_table = (); 321b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "internal") { # only non-exported symbols 322b6c3f456SJani Nikula $output_selection = OUTPUT_INTERNAL; 323da9726ecSJani Nikula %function_table = (); 324b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export-file") { 32588c2b57dSJani Nikula my $file = shift @ARGV; 32688c2b57dSJani Nikula push(@export_file_list, $file); 327b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "v") { 3281da177e4SLinus Torvalds $verbose = 1; 3292c12c810SPierre-Louis Bossart } elsif ($cmd eq "Werror") { 3302c12c810SPierre-Louis Bossart $Werror = 1; 33156b0f453SJohannes Berg } elsif ($cmd eq "Wreturn") { 33256b0f453SJohannes Berg $Wreturn = 1; 333dcd39fa2SAndy Shevchenko } elsif ($cmd eq "Wshort-desc" or $cmd eq "Wshort-description") { 33456b0f453SJohannes Berg $Wshort_desc = 1; 33556b0f453SJohannes Berg } elsif ($cmd eq "Wcontents-before-sections") { 33656b0f453SJohannes Berg $Wcontents_before_sections = 1; 33756b0f453SJohannes Berg } elsif ($cmd eq "Wall") { 33856b0f453SJohannes Berg $Wreturn = 1; 33956b0f453SJohannes Berg $Wshort_desc = 1; 34056b0f453SJohannes Berg $Wcontents_before_sections = 1; 341b031ac4eSMauro Carvalho Chehab } elsif (($cmd eq "h") || ($cmd eq "help")) { 342252b47daSTomasz Warniełło pod2usage(-exitval => 0, -verbose => 2); 343b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'no-doc-sections') { 3444b44595aSJohannes Berg $no_doc_sections = 1; 345b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'enable-lineno') { 3460b0f5f29SDaniel Vetter $enable_lineno = 1; 347b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'show-not-found') { 348b0d60bfbSJonathan Corbet $show_not_found = 1; # A no-op but don't fail 34993351d41SMauro Carvalho Chehab } elsif ($cmd eq "sphinx-version") { 35093351d41SMauro Carvalho Chehab my $ver_string = shift @ARGV; 35193351d41SMauro Carvalho Chehab if ($ver_string =~ m/^(\d+)(\.\d+)?(\.\d+)?/) { 35293351d41SMauro Carvalho Chehab $sphinx_major = $1; 35393351d41SMauro Carvalho Chehab if (defined($2)) { 35493351d41SMauro Carvalho Chehab $sphinx_minor = substr($2,1); 35593351d41SMauro Carvalho Chehab } else { 35693351d41SMauro Carvalho Chehab $sphinx_minor = 0; 35793351d41SMauro Carvalho Chehab } 35893351d41SMauro Carvalho Chehab if (defined($3)) { 35993351d41SMauro Carvalho Chehab $sphinx_patch = substr($3,1) 36093351d41SMauro Carvalho Chehab } else { 36193351d41SMauro Carvalho Chehab $sphinx_patch = 0; 36293351d41SMauro Carvalho Chehab } 36393351d41SMauro Carvalho Chehab } else { 36493351d41SMauro Carvalho Chehab die "Sphinx version should either major.minor or major.minor.patch format\n"; 36593351d41SMauro Carvalho Chehab } 366b031ac4eSMauro Carvalho Chehab } else { 367b031ac4eSMauro Carvalho Chehab # Unknown argument 36843caf1a6STomasz Warniełło pod2usage( 36943caf1a6STomasz Warniełło -message => "Argument unknown!\n", 37043caf1a6STomasz Warniełło -exitval => 1, 37143caf1a6STomasz Warniełło -verbose => 99, 37243caf1a6STomasz Warniełło -sections => 'SYNOPSIS', 37343caf1a6STomasz Warniełło -output => \*STDERR, 37443caf1a6STomasz Warniełło ); 375e334f873SAkira Yokosawa } 376e334f873SAkira Yokosawa if ($#ARGV < 0){ 377e334f873SAkira Yokosawa pod2usage( 378e334f873SAkira Yokosawa -message => "FILE argument missing\n", 379e334f873SAkira Yokosawa -exitval => 1, 380e334f873SAkira Yokosawa -verbose => 99, 381e334f873SAkira Yokosawa -sections => 'SYNOPSIS', 382e334f873SAkira Yokosawa -output => \*STDERR, 383e334f873SAkira Yokosawa ); 3841da177e4SLinus Torvalds } 3851da177e4SLinus Torvalds} 3861da177e4SLinus Torvalds 3878484baaaSRandy Dunlap# continue execution near EOF; 3888484baaaSRandy Dunlap 389efa44475SMauro Carvalho Chehab# The C domain dialect changed on Sphinx 3. So, we need to check the 390efa44475SMauro Carvalho Chehab# version in order to produce the right tags. 391efa44475SMauro Carvalho Chehabsub findprog($) 392efa44475SMauro Carvalho Chehab{ 393efa44475SMauro Carvalho Chehab foreach(split(/:/, $ENV{PATH})) { 394efa44475SMauro Carvalho Chehab return "$_/$_[0]" if(-x "$_/$_[0]"); 395efa44475SMauro Carvalho Chehab } 396efa44475SMauro Carvalho Chehab} 397efa44475SMauro Carvalho Chehab 398efa44475SMauro Carvalho Chehabsub get_sphinx_version() 399efa44475SMauro Carvalho Chehab{ 400efa44475SMauro Carvalho Chehab my $ver; 401efa44475SMauro Carvalho Chehab 402efa44475SMauro Carvalho Chehab my $cmd = "sphinx-build"; 403efa44475SMauro Carvalho Chehab if (!findprog($cmd)) { 404efa44475SMauro Carvalho Chehab my $cmd = "sphinx-build3"; 40593351d41SMauro Carvalho Chehab if (!findprog($cmd)) { 40693351d41SMauro Carvalho Chehab $sphinx_major = 1; 40793351d41SMauro Carvalho Chehab $sphinx_minor = 2; 40893351d41SMauro Carvalho Chehab $sphinx_patch = 0; 40993351d41SMauro Carvalho Chehab printf STDERR "Warning: Sphinx version not found. Using default (Sphinx version %d.%d.%d)\n", 41093351d41SMauro Carvalho Chehab $sphinx_major, $sphinx_minor, $sphinx_patch; 41193351d41SMauro Carvalho Chehab return; 41293351d41SMauro Carvalho Chehab } 413efa44475SMauro Carvalho Chehab } 414efa44475SMauro Carvalho Chehab 415efa44475SMauro Carvalho Chehab open IN, "$cmd --version 2>&1 |"; 416efa44475SMauro Carvalho Chehab while (<IN>) { 417efa44475SMauro Carvalho Chehab if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) { 41893351d41SMauro Carvalho Chehab $sphinx_major = $1; 41993351d41SMauro Carvalho Chehab $sphinx_minor = $2; 42093351d41SMauro Carvalho Chehab $sphinx_patch = $3; 421efa44475SMauro Carvalho Chehab last; 422efa44475SMauro Carvalho Chehab } 423efa44475SMauro Carvalho Chehab # Sphinx 1.2.x uses a different format 424efa44475SMauro Carvalho Chehab if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+)$/) { 42593351d41SMauro Carvalho Chehab $sphinx_major = $1; 42693351d41SMauro Carvalho Chehab $sphinx_minor = $2; 42793351d41SMauro Carvalho Chehab $sphinx_patch = $3; 428efa44475SMauro Carvalho Chehab last; 429efa44475SMauro Carvalho Chehab } 430efa44475SMauro Carvalho Chehab } 431efa44475SMauro Carvalho Chehab close IN; 432efa44475SMauro Carvalho Chehab} 433efa44475SMauro Carvalho Chehab 43453f049faSBorislav Petkov# get kernel version from env 43553f049faSBorislav Petkovsub get_kernel_version() { 4361b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 43753f049faSBorislav Petkov 43853f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 43953f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 44053f049faSBorislav Petkov } 44153f049faSBorislav Petkov return $version; 44253f049faSBorislav Petkov} 4431da177e4SLinus Torvalds 4440b0f5f29SDaniel Vetter# 4450b0f5f29SDaniel Vettersub print_lineno { 4460b0f5f29SDaniel Vetter my $lineno = shift; 4470b0f5f29SDaniel Vetter if ($enable_lineno && defined($lineno)) { 448b79dfef0SMauro Carvalho Chehab print ".. LINENO " . $lineno . "\n"; 4490b0f5f29SDaniel Vetter } 4500b0f5f29SDaniel Vetter} 451df4bf98eSNiklas Söderlund 452df4bf98eSNiklas Söderlundsub emit_warning { 453df4bf98eSNiklas Söderlund my $location = shift; 454df4bf98eSNiklas Söderlund my $msg = shift; 455df4bf98eSNiklas Söderlund print STDERR "$location: warning: $msg"; 456df4bf98eSNiklas Söderlund ++$warnings; 457df4bf98eSNiklas Söderlund} 4581da177e4SLinus Torvalds## 4591da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 4601da177e4SLinus Torvalds# 4611da177e4SLinus Torvaldssub dump_section { 46294dc7ad5SRandy Dunlap my $file = shift; 4631da177e4SLinus Torvalds my $name = shift; 4641da177e4SLinus Torvalds my $contents = join "\n", @_; 4651da177e4SLinus Torvalds 46613901ef2SJani Nikula if ($name =~ m/$type_param/) { 4671da177e4SLinus Torvalds $name = $1; 4681da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 469a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 4700b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 4710b0f5f29SDaniel Vetter $new_start_line = 0; 472ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 473ced69090SRandy Dunlap $name = "..."; 474ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 475a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 4760b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 4770b0f5f29SDaniel Vetter $new_start_line = 0; 4781da177e4SLinus Torvalds } else { 47994dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 48095b6be9dSJani Nikula # Only warn on user specified duplicate section names. 48195b6be9dSJani Nikula if ($name ne $section_default) { 482df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "duplicate section name '$name'\n"); 48395b6be9dSJani Nikula } 48432217761SJani Nikula $sections{$name} .= $contents; 48532217761SJani Nikula } else { 4861da177e4SLinus Torvalds $sections{$name} = $contents; 4871da177e4SLinus Torvalds push @sectionlist, $name; 4880b0f5f29SDaniel Vetter $section_start_lines{$name} = $new_start_line; 4890b0f5f29SDaniel Vetter $new_start_line = 0; 4901da177e4SLinus Torvalds } 4911da177e4SLinus Torvalds } 49232217761SJani Nikula} 4931da177e4SLinus Torvalds 4941da177e4SLinus Torvalds## 495b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 496b112e0f7SJohannes Berg# 497b112e0f7SJohannes Bergsub dump_doc_section { 49894dc7ad5SRandy Dunlap my $file = shift; 499b112e0f7SJohannes Berg my $name = shift; 500b112e0f7SJohannes Berg my $contents = join "\n", @_; 501b112e0f7SJohannes Berg 5024b44595aSJohannes Berg if ($no_doc_sections) { 5034b44595aSJohannes Berg return; 5044b44595aSJohannes Berg } 5054b44595aSJohannes Berg 506eab795ddSMauro Carvalho Chehab return if (defined($nosymbol_table{$name})); 507eab795ddSMauro Carvalho Chehab 508b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 509eab795ddSMauro Carvalho Chehab (($output_selection == OUTPUT_INCLUDE) && 510eab795ddSMauro Carvalho Chehab defined($function_table{$name}))) 511b112e0f7SJohannes Berg { 51294dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 513b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 514b112e0f7SJohannes Berg 'sections' => \%sections, 515b112e0f7SJohannes Berg 'module' => $modulename, 516b6c3f456SJani Nikula 'content-only' => ($output_selection != OUTPUT_ALL), }); 517b112e0f7SJohannes Berg } 518b112e0f7SJohannes Berg} 519b112e0f7SJohannes Berg 520b112e0f7SJohannes Berg## 5211da177e4SLinus Torvalds# output function 5221da177e4SLinus Torvalds# 5231da177e4SLinus Torvalds# parameterdescs, a hash. 5241da177e4SLinus Torvalds# function => "function name" 5251da177e4SLinus Torvalds# parameterlist => @list of parameters 5261da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 5271da177e4SLinus Torvalds# sectionlist => @list of sections 528a21217daSRandy Dunlap# sections => %section descriptions 5291da177e4SLinus Torvalds# 5301da177e4SLinus Torvalds 5311da177e4SLinus Torvaldssub output_highlight { 5321da177e4SLinus Torvalds my $contents = join "\n",@_; 5331da177e4SLinus Torvalds my $line; 5341da177e4SLinus Torvalds 5351da177e4SLinus Torvalds# DEBUG 5361da177e4SLinus Torvalds# if (!defined $contents) { 5371da177e4SLinus Torvalds# use Carp; 5381da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 5391da177e4SLinus Torvalds# } 5401da177e4SLinus Torvalds 5413eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 5421da177e4SLinus Torvalds eval $dohighlight; 5431da177e4SLinus Torvalds die $@ if $@; 5443eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 5453eb014a1SRandy Dunlap 5461da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 54712ae6779SDaniel Santos if (! $output_preformatted) { 54812ae6779SDaniel Santos $line =~ s/^\s*//; 54912ae6779SDaniel Santos } 5501da177e4SLinus Torvalds if ($line eq ""){ 551e314ba31SDaniel Santos if (! $output_preformatted) { 5520bba924cSJonathan Corbet print $lineprefix, $blankline; 553e314ba31SDaniel Santos } 5541da177e4SLinus Torvalds } else { 555cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 556cdccb316SRandy Dunlap print "\\&$line"; 557cdccb316SRandy Dunlap } else { 5581da177e4SLinus Torvalds print $lineprefix, $line; 5591da177e4SLinus Torvalds } 560cdccb316SRandy Dunlap } 5611da177e4SLinus Torvalds print "\n"; 5621da177e4SLinus Torvalds } 5631da177e4SLinus Torvalds} 5641da177e4SLinus Torvalds 5651da177e4SLinus Torvalds## 5661da177e4SLinus Torvalds# output function in man 5671da177e4SLinus Torvaldssub output_function_man(%) { 5681da177e4SLinus Torvalds my %args = %{$_[0]}; 5691da177e4SLinus Torvalds my ($parameter, $section); 5701da177e4SLinus Torvalds my $count; 5711da177e4SLinus Torvalds 5721da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 5731da177e4SLinus Torvalds 5741da177e4SLinus Torvalds print ".SH NAME\n"; 5751da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 578a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 5791da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 580a21217daSRandy Dunlap } else { 581a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 582a21217daSRandy Dunlap } 5831da177e4SLinus Torvalds $count = 0; 5841da177e4SLinus Torvalds my $parenth = "("; 5851da177e4SLinus Torvalds my $post = ","; 5861da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 5871da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 5881da177e4SLinus Torvalds $post = ");"; 5891da177e4SLinus Torvalds } 5901da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 591e86bdb24SAditya Srivastava if ($type =~ m/$function_pointer/) { 5921da177e4SLinus Torvalds # pointer-to-function 593ed8348e2SMauro Carvalho Chehab print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n"; 5941da177e4SLinus Torvalds } else { 5951da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 596ed8348e2SMauro Carvalho Chehab print ".BI \"" . $parenth . $type . "\" " . " \"" . $post . "\"\n"; 5971da177e4SLinus Torvalds } 5981da177e4SLinus Torvalds $count++; 5991da177e4SLinus Torvalds $parenth = ""; 6001da177e4SLinus Torvalds } 6011da177e4SLinus Torvalds 6021da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 6031da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6041da177e4SLinus Torvalds my $parameter_name = $parameter; 6051da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6061da177e4SLinus Torvalds 6071da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 6081da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6091da177e4SLinus Torvalds } 6101da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6111da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 6121da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6131da177e4SLinus Torvalds } 6141da177e4SLinus Torvalds} 6151da177e4SLinus Torvalds 6161da177e4SLinus Torvalds## 6171da177e4SLinus Torvalds# output enum in man 6181da177e4SLinus Torvaldssub output_enum_man(%) { 6191da177e4SLinus Torvalds my %args = %{$_[0]}; 6201da177e4SLinus Torvalds my ($parameter, $section); 6211da177e4SLinus Torvalds my $count; 6221da177e4SLinus Torvalds 6231da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 6241da177e4SLinus Torvalds 6251da177e4SLinus Torvalds print ".SH NAME\n"; 6261da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 6271da177e4SLinus Torvalds 6281da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 6291da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 6301da177e4SLinus Torvalds $count = 0; 6311da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 6321da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 6331da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 6341da177e4SLinus Torvalds print "\n};\n"; 6351da177e4SLinus Torvalds last; 636*af404fb1SVegard Nossum } else { 6371da177e4SLinus Torvalds print ", \n.br\n"; 6381da177e4SLinus Torvalds } 6391da177e4SLinus Torvalds $count++; 6401da177e4SLinus Torvalds } 6411da177e4SLinus Torvalds 6421da177e4SLinus Torvalds print ".SH Constants\n"; 6431da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6441da177e4SLinus Torvalds my $parameter_name = $parameter; 6451da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6461da177e4SLinus Torvalds 6471da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 6481da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6491da177e4SLinus Torvalds } 6501da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6511da177e4SLinus Torvalds print ".SH \"$section\"\n"; 6521da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6531da177e4SLinus Torvalds } 6541da177e4SLinus Torvalds} 6551da177e4SLinus Torvalds 6561da177e4SLinus Torvalds## 6571da177e4SLinus Torvalds# output struct in man 6581da177e4SLinus Torvaldssub output_struct_man(%) { 6591da177e4SLinus Torvalds my %args = %{$_[0]}; 6601da177e4SLinus Torvalds my ($parameter, $section); 6611da177e4SLinus Torvalds 6621da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 6631da177e4SLinus Torvalds 6641da177e4SLinus Torvalds print ".SH NAME\n"; 6651da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 6661da177e4SLinus Torvalds 6678ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 6688ad72163SMauro Carvalho Chehab $declaration =~ s/\t/ /g; 6698ad72163SMauro Carvalho Chehab $declaration =~ s/\n/"\n.br\n.BI \"/g; 6701da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 6711da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 6728ad72163SMauro Carvalho Chehab print ".BI \"$declaration\n};\n.br\n\n"; 6731da177e4SLinus Torvalds 674c51d3dacSRandy Dunlap print ".SH Members\n"; 6751da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6761da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 6771da177e4SLinus Torvalds 6781da177e4SLinus Torvalds my $parameter_name = $parameter; 6791da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6801da177e4SLinus Torvalds 6811da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6821da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 6831da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6841da177e4SLinus Torvalds } 6851da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6861da177e4SLinus Torvalds print ".SH \"$section\"\n"; 6871da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6881da177e4SLinus Torvalds } 6891da177e4SLinus Torvalds} 6901da177e4SLinus Torvalds 6911da177e4SLinus Torvalds## 6921da177e4SLinus Torvalds# output typedef in man 6931da177e4SLinus Torvaldssub output_typedef_man(%) { 6941da177e4SLinus Torvalds my %args = %{$_[0]}; 6951da177e4SLinus Torvalds my ($parameter, $section); 6961da177e4SLinus Torvalds 6971da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 6981da177e4SLinus Torvalds 6991da177e4SLinus Torvalds print ".SH NAME\n"; 7001da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 7011da177e4SLinus Torvalds 7021da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7031da177e4SLinus Torvalds print ".SH \"$section\"\n"; 7041da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7051da177e4SLinus Torvalds } 7061da177e4SLinus Torvalds} 7071da177e4SLinus Torvalds 708b112e0f7SJohannes Bergsub output_blockhead_man(%) { 7091da177e4SLinus Torvalds my %args = %{$_[0]}; 7101da177e4SLinus Torvalds my ($parameter, $section); 7111da177e4SLinus Torvalds my $count; 7121da177e4SLinus Torvalds 7131da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 7141da177e4SLinus Torvalds 7151da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7161da177e4SLinus Torvalds print ".SH \"$section\"\n"; 7171da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7181da177e4SLinus Torvalds } 7191da177e4SLinus Torvalds} 7201da177e4SLinus Torvalds 7211da177e4SLinus Torvalds## 722c0d1b6eeSJonathan Corbet# output in restructured text 723c0d1b6eeSJonathan Corbet# 724c0d1b6eeSJonathan Corbet 725c0d1b6eeSJonathan Corbet# 726c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 727c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 728c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 729c0d1b6eeSJonathan Corbet# 730c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 731c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 732c0d1b6eeSJonathan Corbet my ($parameter, $section); 733c0d1b6eeSJonathan Corbet 734c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 735eab795ddSMauro Carvalho Chehab next if (defined($nosymbol_table{$section})); 736eab795ddSMauro Carvalho Chehab 7379e72184bSJani Nikula if ($output_selection != OUTPUT_INCLUDE) { 73806a755d6SMichal Wajdeczko print ".. _$section:\n\n"; 739c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 7409e72184bSJani Nikula } 7410b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 742c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 743c0d1b6eeSJonathan Corbet print "\n"; 744c0d1b6eeSJonathan Corbet } 745c0d1b6eeSJonathan Corbet} 746c0d1b6eeSJonathan Corbet 747af250290SJonathan Corbet# 748af250290SJonathan Corbet# Apply the RST highlights to a sub-block of text. 749af250290SJonathan Corbet# 750af250290SJonathan Corbetsub highlight_block($) { 751af250290SJonathan Corbet # The dohighlight kludge requires the text be called $contents 752af250290SJonathan Corbet my $contents = shift; 753c0d1b6eeSJonathan Corbet eval $dohighlight; 754c0d1b6eeSJonathan Corbet die $@ if $@; 755af250290SJonathan Corbet return $contents; 756af250290SJonathan Corbet} 757c0d1b6eeSJonathan Corbet 758af250290SJonathan Corbet# 759af250290SJonathan Corbet# Regexes used only here. 760af250290SJonathan Corbet# 761af250290SJonathan Corbetmy $sphinx_literal = '^[^.].*::$'; 762af250290SJonathan Corbetmy $sphinx_cblock = '^\.\.\ +code-block::'; 763af250290SJonathan Corbet 764af250290SJonathan Corbetsub output_highlight_rst { 765af250290SJonathan Corbet my $input = join "\n",@_; 766af250290SJonathan Corbet my $output = ""; 767af250290SJonathan Corbet my $line; 768af250290SJonathan Corbet my $in_literal = 0; 769af250290SJonathan Corbet my $litprefix; 770af250290SJonathan Corbet my $block = ""; 771af250290SJonathan Corbet 772af250290SJonathan Corbet foreach $line (split "\n",$input) { 773af250290SJonathan Corbet # 774af250290SJonathan Corbet # If we're in a literal block, see if we should drop out 775af250290SJonathan Corbet # of it. Otherwise pass the line straight through unmunged. 776af250290SJonathan Corbet # 777af250290SJonathan Corbet if ($in_literal) { 778af250290SJonathan Corbet if (! ($line =~ /^\s*$/)) { 779af250290SJonathan Corbet # 780af250290SJonathan Corbet # If this is the first non-blank line in a literal 781af250290SJonathan Corbet # block we need to figure out what the proper indent is. 782af250290SJonathan Corbet # 783af250290SJonathan Corbet if ($litprefix eq "") { 784af250290SJonathan Corbet $line =~ /^(\s*)/; 785af250290SJonathan Corbet $litprefix = '^' . $1; 786af250290SJonathan Corbet $output .= $line . "\n"; 787af250290SJonathan Corbet } elsif (! ($line =~ /$litprefix/)) { 788af250290SJonathan Corbet $in_literal = 0; 789af250290SJonathan Corbet } else { 790af250290SJonathan Corbet $output .= $line . "\n"; 791af250290SJonathan Corbet } 792af250290SJonathan Corbet } else { 793af250290SJonathan Corbet $output .= $line . "\n"; 794af250290SJonathan Corbet } 795af250290SJonathan Corbet } 796af250290SJonathan Corbet # 797af250290SJonathan Corbet # Not in a literal block (or just dropped out) 798af250290SJonathan Corbet # 799af250290SJonathan Corbet if (! $in_literal) { 800af250290SJonathan Corbet $block .= $line . "\n"; 801af250290SJonathan Corbet if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) { 802af250290SJonathan Corbet $in_literal = 1; 803af250290SJonathan Corbet $litprefix = ""; 804af250290SJonathan Corbet $output .= highlight_block($block); 805af250290SJonathan Corbet $block = "" 806af250290SJonathan Corbet } 807af250290SJonathan Corbet } 808af250290SJonathan Corbet } 809af250290SJonathan Corbet 810af250290SJonathan Corbet if ($block) { 811af250290SJonathan Corbet $output .= highlight_block($block); 812af250290SJonathan Corbet } 813af250290SJonathan Corbet foreach $line (split "\n", $output) { 814830066a7SJani Nikula print $lineprefix . $line . "\n"; 815c0d1b6eeSJonathan Corbet } 816c0d1b6eeSJonathan Corbet} 817c0d1b6eeSJonathan Corbet 818c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 819c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 820c0d1b6eeSJonathan Corbet my ($parameter, $section); 821c099ff69SJani Nikula my $oldprefix = $lineprefix; 82282801d06SMauro Carvalho Chehab my $start = ""; 8236e9e4158SMauro Carvalho Chehab my $is_macro = 0; 824c0d1b6eeSJonathan Corbet 825efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 826e3ad05feSMauro Carvalho Chehab if ($args{'typedef'}) { 82782801d06SMauro Carvalho Chehab print ".. c:type:: ". $args{'function'} . "\n\n"; 82882801d06SMauro Carvalho Chehab print_lineno($declaration_start_line); 82982801d06SMauro Carvalho Chehab print " **Typedef**: "; 83082801d06SMauro Carvalho Chehab $lineprefix = ""; 83182801d06SMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 83282801d06SMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 8336e9e4158SMauro Carvalho Chehab $is_macro = 1; 834c0d1b6eeSJonathan Corbet } else { 83582801d06SMauro Carvalho Chehab print ".. c:function:: "; 83682801d06SMauro Carvalho Chehab } 837e3ad05feSMauro Carvalho Chehab } else { 8386e9e4158SMauro Carvalho Chehab if ($args{'typedef'} || $args{'functiontype'} eq "") { 8396e9e4158SMauro Carvalho Chehab $is_macro = 1; 840e3ad05feSMauro Carvalho Chehab print ".. c:macro:: ". $args{'function'} . "\n\n"; 8416e9e4158SMauro Carvalho Chehab } else { 8426e9e4158SMauro Carvalho Chehab print ".. c:function:: "; 8436e9e4158SMauro Carvalho Chehab } 844e3ad05feSMauro Carvalho Chehab 845e3ad05feSMauro Carvalho Chehab if ($args{'typedef'}) { 846e3ad05feSMauro Carvalho Chehab print_lineno($declaration_start_line); 847e3ad05feSMauro Carvalho Chehab print " **Typedef**: "; 848e3ad05feSMauro Carvalho Chehab $lineprefix = ""; 849e3ad05feSMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 850e3ad05feSMauro Carvalho Chehab $start = "\n\n**Syntax**\n\n ``"; 851e3ad05feSMauro Carvalho Chehab } else { 8526e9e4158SMauro Carvalho Chehab print "``" if ($is_macro); 853e3ad05feSMauro Carvalho Chehab } 854e3ad05feSMauro Carvalho Chehab } 85582801d06SMauro Carvalho Chehab if ($args{'functiontype'} ne "") { 85682801d06SMauro Carvalho Chehab $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; 85782801d06SMauro Carvalho Chehab } else { 85882801d06SMauro Carvalho Chehab $start .= $args{'function'} . " ("; 859c0d1b6eeSJonathan Corbet } 860c0d1b6eeSJonathan Corbet print $start; 861c0d1b6eeSJonathan Corbet 862c0d1b6eeSJonathan Corbet my $count = 0; 863c0d1b6eeSJonathan Corbet foreach my $parameter (@{$args{'parameterlist'}}) { 864c0d1b6eeSJonathan Corbet if ($count ne 0) { 865c0d1b6eeSJonathan Corbet print ", "; 866c0d1b6eeSJonathan Corbet } 867c0d1b6eeSJonathan Corbet $count++; 868c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 869a88b1672SMauro Carvalho Chehab 870e86bdb24SAditya Srivastava if ($type =~ m/$function_pointer/) { 871c0d1b6eeSJonathan Corbet # pointer-to-function 872e8f4ba83SPeter Maydell print $1 . $parameter . ") (" . $2 . ")"; 873c0d1b6eeSJonathan Corbet } else { 874ed8348e2SMauro Carvalho Chehab print $type; 875c0d1b6eeSJonathan Corbet } 876c0d1b6eeSJonathan Corbet } 8776e9e4158SMauro Carvalho Chehab if ($is_macro) { 8786e9e4158SMauro Carvalho Chehab print ")``\n\n"; 87982801d06SMauro Carvalho Chehab } else { 880c099ff69SJani Nikula print ")\n\n"; 881e3ad05feSMauro Carvalho Chehab } 8826e9e4158SMauro Carvalho Chehab if (!$args{'typedef'}) { 8830b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 884c099ff69SJani Nikula $lineprefix = " "; 885c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 886c099ff69SJani Nikula print "\n"; 88782801d06SMauro Carvalho Chehab } 888c0d1b6eeSJonathan Corbet 889eaf710ceSJonathan Corbet # 890eaf710ceSJonathan Corbet # Put our descriptive text into a container (thus an HTML <div>) to help 891eaf710ceSJonathan Corbet # set the function prototypes apart. 892eaf710ceSJonathan Corbet # 893eaf710ceSJonathan Corbet print ".. container:: kernelindent\n\n"; 894c099ff69SJani Nikula $lineprefix = " "; 895eaf710ceSJonathan Corbet print $lineprefix . "**Parameters**\n\n"; 896c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 897c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 898ada5f446SGabriel Krisman Bertazi $parameter_name =~ s/\[.*//; 899c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 900c0d1b6eeSJonathan Corbet 901c0d1b6eeSJonathan Corbet if ($type ne "") { 902eaf710ceSJonathan Corbet print $lineprefix . "``$type``\n"; 903c0d1b6eeSJonathan Corbet } else { 904eaf710ceSJonathan Corbet print $lineprefix . "``$parameter``\n"; 905c0d1b6eeSJonathan Corbet } 9060b0f5f29SDaniel Vetter 9070b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 9080b0f5f29SDaniel Vetter 909eaf710ceSJonathan Corbet $lineprefix = " "; 9105e64fa9cSJani Nikula if (defined($args{'parameterdescs'}{$parameter_name}) && 9115e64fa9cSJani Nikula $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 912c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 913c0d1b6eeSJonathan Corbet } else { 914eaf710ceSJonathan Corbet print $lineprefix . "*undescribed*\n"; 915c0d1b6eeSJonathan Corbet } 916eaf710ceSJonathan Corbet $lineprefix = " "; 917c0d1b6eeSJonathan Corbet print "\n"; 918c0d1b6eeSJonathan Corbet } 919c099ff69SJani Nikula 920c0d1b6eeSJonathan Corbet output_section_rst(@_); 921eaf710ceSJonathan Corbet $lineprefix = $oldprefix; 922c0d1b6eeSJonathan Corbet} 923c0d1b6eeSJonathan Corbet 924c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 925c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 926c0d1b6eeSJonathan Corbet my $section; 927c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 928c0d1b6eeSJonathan Corbet 929c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 930eaf710ceSJonathan Corbet print $lineprefix . "**$section**\n\n"; 9310b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 932c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 933c0d1b6eeSJonathan Corbet print "\n"; 934c0d1b6eeSJonathan Corbet } 935c0d1b6eeSJonathan Corbet print "\n"; 936c0d1b6eeSJonathan Corbet} 937c0d1b6eeSJonathan Corbet 938c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 939c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 940c0d1b6eeSJonathan Corbet my ($parameter); 941c099ff69SJani Nikula my $oldprefix = $lineprefix; 942c0d1b6eeSJonathan Corbet my $count; 943eaf710ceSJonathan Corbet my $outer; 94462850976SJani Nikula 945efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 946efa44475SMauro Carvalho Chehab my $name = "enum " . $args{'enum'}; 94762850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 948efa44475SMauro Carvalho Chehab } else { 949efa44475SMauro Carvalho Chehab my $name = $args{'enum'}; 950efa44475SMauro Carvalho Chehab print "\n\n.. c:enum:: " . $name . "\n\n"; 951efa44475SMauro Carvalho Chehab } 9520b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 953c099ff69SJani Nikula $lineprefix = " "; 954c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 955c099ff69SJani Nikula print "\n"; 956c0d1b6eeSJonathan Corbet 957eaf710ceSJonathan Corbet print ".. container:: kernelindent\n\n"; 958eaf710ceSJonathan Corbet $outer = $lineprefix . " "; 959eaf710ceSJonathan Corbet $lineprefix = $outer . " "; 960eaf710ceSJonathan Corbet print $outer . "**Constants**\n\n"; 961c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 962eaf710ceSJonathan Corbet print $outer . "``$parameter``\n"; 963eaf710ceSJonathan Corbet 964c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 965c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 966c0d1b6eeSJonathan Corbet } else { 967eaf710ceSJonathan Corbet print $lineprefix . "*undescribed*\n"; 968c0d1b6eeSJonathan Corbet } 969c0d1b6eeSJonathan Corbet print "\n"; 970c0d1b6eeSJonathan Corbet } 971eaf710ceSJonathan Corbet print "\n"; 972c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 973c0d1b6eeSJonathan Corbet output_section_rst(@_); 974c0d1b6eeSJonathan Corbet} 975c0d1b6eeSJonathan Corbet 976c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 977c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 978c0d1b6eeSJonathan Corbet my ($parameter); 979c099ff69SJani Nikula my $oldprefix = $lineprefix; 980efa44475SMauro Carvalho Chehab my $name; 981c0d1b6eeSJonathan Corbet 982efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 983efa44475SMauro Carvalho Chehab $name = "typedef " . $args{'typedef'}; 984efa44475SMauro Carvalho Chehab } else { 985efa44475SMauro Carvalho Chehab $name = $args{'typedef'}; 986efa44475SMauro Carvalho Chehab } 98762850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 9880b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 989c099ff69SJani Nikula $lineprefix = " "; 990c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 991c099ff69SJani Nikula print "\n"; 992c0d1b6eeSJonathan Corbet 993c099ff69SJani Nikula $lineprefix = $oldprefix; 994c0d1b6eeSJonathan Corbet output_section_rst(@_); 995c0d1b6eeSJonathan Corbet} 996c0d1b6eeSJonathan Corbet 997c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 998c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 999c0d1b6eeSJonathan Corbet my ($parameter); 1000c099ff69SJani Nikula my $oldprefix = $lineprefix; 1001c0d1b6eeSJonathan Corbet 1002efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 1003efa44475SMauro Carvalho Chehab my $name = $args{'type'} . " " . $args{'struct'}; 100462850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1005efa44475SMauro Carvalho Chehab } else { 1006efa44475SMauro Carvalho Chehab my $name = $args{'struct'}; 100772b97d0bSMauro Carvalho Chehab if ($args{'type'} eq 'union') { 100872b97d0bSMauro Carvalho Chehab print "\n\n.. c:union:: " . $name . "\n\n"; 100972b97d0bSMauro Carvalho Chehab } else { 1010efa44475SMauro Carvalho Chehab print "\n\n.. c:struct:: " . $name . "\n\n"; 1011efa44475SMauro Carvalho Chehab } 101272b97d0bSMauro Carvalho Chehab } 10130b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1014c099ff69SJani Nikula $lineprefix = " "; 1015c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1016c099ff69SJani Nikula print "\n"; 1017c0d1b6eeSJonathan Corbet 1018eaf710ceSJonathan Corbet print ".. container:: kernelindent\n\n"; 1019eaf710ceSJonathan Corbet print $lineprefix . "**Definition**::\n\n"; 10208ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 1021eaf710ceSJonathan Corbet $lineprefix = $lineprefix . " "; 1022eaf710ceSJonathan Corbet $declaration =~ s/\t/$lineprefix/g; 1023eaf710ceSJonathan Corbet print $lineprefix . $args{'type'} . " " . $args{'struct'} . " {\n$declaration" . $lineprefix . "};\n\n"; 1024c0d1b6eeSJonathan Corbet 1025c099ff69SJani Nikula $lineprefix = " "; 1026eaf710ceSJonathan Corbet print $lineprefix . "**Members**\n\n"; 1027c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1028c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 1029c0d1b6eeSJonathan Corbet 1030c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1031c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 1032c0d1b6eeSJonathan Corbet 1033c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1034c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 10350b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 1036eaf710ceSJonathan Corbet print $lineprefix . "``" . $parameter . "``\n"; 1037eaf710ceSJonathan Corbet $lineprefix = " "; 1038c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1039eaf710ceSJonathan Corbet $lineprefix = " "; 1040c0d1b6eeSJonathan Corbet print "\n"; 1041c0d1b6eeSJonathan Corbet } 1042c0d1b6eeSJonathan Corbet print "\n"; 1043c099ff69SJani Nikula 1044c099ff69SJani Nikula $lineprefix = $oldprefix; 1045c0d1b6eeSJonathan Corbet output_section_rst(@_); 1046c0d1b6eeSJonathan Corbet} 1047c0d1b6eeSJonathan Corbet 10483a025e1dSMatthew Wilcox## none mode output functions 10493a025e1dSMatthew Wilcox 10503a025e1dSMatthew Wilcoxsub output_function_none(%) { 10513a025e1dSMatthew Wilcox} 10523a025e1dSMatthew Wilcox 10533a025e1dSMatthew Wilcoxsub output_enum_none(%) { 10543a025e1dSMatthew Wilcox} 10553a025e1dSMatthew Wilcox 10563a025e1dSMatthew Wilcoxsub output_typedef_none(%) { 10573a025e1dSMatthew Wilcox} 10583a025e1dSMatthew Wilcox 10593a025e1dSMatthew Wilcoxsub output_struct_none(%) { 10603a025e1dSMatthew Wilcox} 10613a025e1dSMatthew Wilcox 10623a025e1dSMatthew Wilcoxsub output_blockhead_none(%) { 10633a025e1dSMatthew Wilcox} 10643a025e1dSMatthew Wilcox 10651da177e4SLinus Torvalds## 106627205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 106727205744SRandy Dunlap# calls the generated, variable output_ function name based on 106827205744SRandy Dunlap# functype and output_mode 10691da177e4SLinus Torvaldssub output_declaration { 10701da177e4SLinus Torvalds no strict 'refs'; 10711da177e4SLinus Torvalds my $name = shift; 10721da177e4SLinus Torvalds my $functype = shift; 10731da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 1074eab795ddSMauro Carvalho Chehab 1075eab795ddSMauro Carvalho Chehab return if (defined($nosymbol_table{$name})); 1076eab795ddSMauro Carvalho Chehab 1077b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 1078b6c3f456SJani Nikula (($output_selection == OUTPUT_INCLUDE || 1079b6c3f456SJani Nikula $output_selection == OUTPUT_EXPORTED) && 108086ae2e38SJani Nikula defined($function_table{$name})) || 1081eab795ddSMauro Carvalho Chehab ($output_selection == OUTPUT_INTERNAL && 108286ae2e38SJani Nikula !($functype eq "function" && defined($function_table{$name})))) 10831da177e4SLinus Torvalds { 10841da177e4SLinus Torvalds &$func(@_); 10851da177e4SLinus Torvalds $section_counter++; 10861da177e4SLinus Torvalds } 10871da177e4SLinus Torvalds} 10881da177e4SLinus Torvalds 10891da177e4SLinus Torvalds## 109027205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 1091b112e0f7SJohannes Bergsub output_blockhead { 10921da177e4SLinus Torvalds no strict 'refs'; 1093b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 10941da177e4SLinus Torvalds &$func(@_); 10951da177e4SLinus Torvalds $section_counter++; 10961da177e4SLinus Torvalds} 10971da177e4SLinus Torvalds 10981da177e4SLinus Torvalds## 10991da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 11001da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 11011da177e4SLinus Torvaldssub dump_declaration($$) { 11021da177e4SLinus Torvalds no strict 'refs'; 11031da177e4SLinus Torvalds my ($prototype, $file) = @_; 11041da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 11051da177e4SLinus Torvalds &$func(@_); 11061da177e4SLinus Torvalds} 11071da177e4SLinus Torvalds 11081da177e4SLinus Torvaldssub dump_union($$) { 11091da177e4SLinus Torvalds dump_struct(@_); 11101da177e4SLinus Torvalds} 11111da177e4SLinus Torvalds 11121da177e4SLinus Torvaldssub dump_struct($$) { 11131da177e4SLinus Torvalds my $x = shift; 11141da177e4SLinus Torvalds my $file = shift; 1115a746fe32SAditya Srivastava my $decl_type; 1116a746fe32SAditya Srivastava my $members; 1117a746fe32SAditya Srivastava my $type = qr{struct|union}; 1118a746fe32SAditya Srivastava # For capturing struct/union definition body, i.e. "{members*}qualifiers*" 1119e86bdb24SAditya Srivastava my $qualifiers = qr{$attribute|__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned}; 1120e86bdb24SAditya Srivastava my $definition_body = qr{\{(.*)\}\s*$qualifiers*}; 1121e86bdb24SAditya Srivastava my $struct_members = qr{($type)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;}; 11221da177e4SLinus Torvalds 1123a746fe32SAditya Srivastava if ($x =~ /($type)\s+(\w+)\s*$definition_body/) { 1124a746fe32SAditya Srivastava $decl_type = $1; 11251da177e4SLinus Torvalds $declaration_name = $2; 1126a746fe32SAditya Srivastava $members = $3; 1127a746fe32SAditya Srivastava } elsif ($x =~ /typedef\s+($type)\s*$definition_body\s*(\w+)\s*;/) { 1128a746fe32SAditya Srivastava $decl_type = $1; 1129a746fe32SAditya Srivastava $declaration_name = $3; 1130a746fe32SAditya Srivastava $members = $2; 1131a746fe32SAditya Srivastava } 11321da177e4SLinus Torvalds 1133a746fe32SAditya Srivastava if ($members) { 113452042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 1135df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "expecting prototype for $decl_type $identifier. Prototype was for $decl_type $declaration_name instead\n"); 113652042e2dSMauro Carvalho Chehab return; 113752042e2dSMauro Carvalho Chehab } 113852042e2dSMauro Carvalho Chehab 1139aeec46b9SMartin Waitz # ignore members marked private: 11400d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 11410d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 1142aeec46b9SMartin Waitz # strip comments: 1143aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 1144ef5da59fSRandy Dunlap # strip attributes 1145e86bdb24SAditya Srivastava $members =~ s/\s*$attribute/ /gi; 11463d9bfb19SSakari Ailus $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos; 1147f600c77aSJonathan Corbet $members =~ s/\s*__counted_by\s*\([^;]*\)/ /gos; 11483d9bfb19SSakari Ailus $members =~ s/\s*__packed\s*/ /gos; 1149f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos; 1150f861537dSAndré Almeida $members =~ s/\s*____cacheline_aligned_in_smp/ /gos; 1151a070991fSJonathan Cameron $members =~ s/\s*____cacheline_aligned/ /gos; 115250d7bd38SKees Cook # unwrap struct_group(): 115350d7bd38SKees Cook # - first eat non-declaration parameters and rewrite for final match 115450d7bd38SKees Cook # - then remove macro, outer parens, and trailing semicolon 115550d7bd38SKees Cook $members =~ s/\bstruct_group\s*\(([^,]*,)/STRUCT_GROUP(/gos; 115650d7bd38SKees Cook $members =~ s/\bstruct_group_(attr|tagged)\s*\(([^,]*,){2}/STRUCT_GROUP(/gos; 115750d7bd38SKees Cook $members =~ s/\b__struct_group\s*\(([^,]*,){3}/STRUCT_GROUP(/gos; 115850d7bd38SKees Cook $members =~ s/\bSTRUCT_GROUP(\(((?:(?>[^)(]+)|(?1))*)\))[^;]*;/$2/gos; 11593556108eSMauro Carvalho Chehab 1160e86bdb24SAditya Srivastava my $args = qr{([^,)]+)}; 1161b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 11623556108eSMauro Carvalho Chehab $members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos; 1163603bdf5dSRandy Dunlap $members =~ s/DECLARE_PHY_INTERFACE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, PHY_INTERFACE_MODE_MAX)/gos; 1164e86bdb24SAditya Srivastava $members =~ s/DECLARE_BITMAP\s*\($args,\s*$args\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 11651cb566baSJakub Kicinski # replace DECLARE_HASHTABLE 1166e86bdb24SAditya Srivastava $members =~ s/DECLARE_HASHTABLE\s*\($args,\s*$args\)/unsigned long $1\[1 << (($2) - 1)\]/gos; 116745005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO 1168e86bdb24SAditya Srivastava $members =~ s/DECLARE_KFIFO\s*\($args,\s*$args,\s*$args\)/$2 \*$1/gos; 116945005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO_PTR 1170e86bdb24SAditya Srivastava $members =~ s/DECLARE_KFIFO_PTR\s*\($args,\s*$args\)/$2 \*$1/gos; 11713080ea55SKees Cook # replace DECLARE_FLEX_ARRAY 11723080ea55SKees Cook $members =~ s/(?:__)?DECLARE_FLEX_ARRAY\s*\($args,\s*$args\)/$1 $2\[\]/gos; 1173be98edcbSPavan Kumar Linga #replace DEFINE_DMA_UNMAP_ADDR 1174be98edcbSPavan Kumar Linga $members =~ s/DEFINE_DMA_UNMAP_ADDR\s*\($args\)/dma_addr_t $1/gos; 1175be98edcbSPavan Kumar Linga #replace DEFINE_DMA_UNMAP_LEN 1176be98edcbSPavan Kumar Linga $members =~ s/DEFINE_DMA_UNMAP_LEN\s*\($args\)/__u32 $1/gos; 11778ad72163SMauro Carvalho Chehab my $declaration = $members; 11788ad72163SMauro Carvalho Chehab 11798ad72163SMauro Carvalho Chehab # Split nested struct/union elements as newer ones 1180e86bdb24SAditya Srivastava while ($members =~ m/$struct_members/) { 118184ce5b98SMauro Carvalho Chehab my $newmember; 118284ce5b98SMauro Carvalho Chehab my $maintype = $1; 118384ce5b98SMauro Carvalho Chehab my $ids = $4; 11848ad72163SMauro Carvalho Chehab my $content = $3; 118584ce5b98SMauro Carvalho Chehab foreach my $id(split /,/, $ids) { 118684ce5b98SMauro Carvalho Chehab $newmember .= "$maintype $id; "; 118784ce5b98SMauro Carvalho Chehab 11888ad72163SMauro Carvalho Chehab $id =~ s/[:\[].*//; 118984ce5b98SMauro Carvalho Chehab $id =~ s/^\s*\**(\S+)\s*/$1/; 11908ad72163SMauro Carvalho Chehab foreach my $arg (split /;/, $content) { 11918ad72163SMauro Carvalho Chehab next if ($arg =~ m/^\s*$/); 11927c0d7e87SMauro Carvalho Chehab if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) { 11937c0d7e87SMauro Carvalho Chehab # pointer-to-function 11947c0d7e87SMauro Carvalho Chehab my $type = $1; 11957c0d7e87SMauro Carvalho Chehab my $name = $2; 11967c0d7e87SMauro Carvalho Chehab my $extra = $3; 11977c0d7e87SMauro Carvalho Chehab next if (!$name); 11987c0d7e87SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 11997c0d7e87SMauro Carvalho Chehab # anonymous struct/union 12007c0d7e87SMauro Carvalho Chehab $newmember .= "$type$name$extra; "; 12017c0d7e87SMauro Carvalho Chehab } else { 12027c0d7e87SMauro Carvalho Chehab $newmember .= "$type$id.$name$extra; "; 12037c0d7e87SMauro Carvalho Chehab } 12047c0d7e87SMauro Carvalho Chehab } else { 120584ce5b98SMauro Carvalho Chehab my $type; 120684ce5b98SMauro Carvalho Chehab my $names; 120784ce5b98SMauro Carvalho Chehab $arg =~ s/^\s+//; 120884ce5b98SMauro Carvalho Chehab $arg =~ s/\s+$//; 120984ce5b98SMauro Carvalho Chehab # Handle bitmaps 121084ce5b98SMauro Carvalho Chehab $arg =~ s/:\s*\d+\s*//g; 121184ce5b98SMauro Carvalho Chehab # Handle arrays 1212d404d579SMauro Carvalho Chehab $arg =~ s/\[.*\]//g; 121384ce5b98SMauro Carvalho Chehab # The type may have multiple words, 121484ce5b98SMauro Carvalho Chehab # and multiple IDs can be defined, like: 121584ce5b98SMauro Carvalho Chehab # const struct foo, *bar, foobar 121684ce5b98SMauro Carvalho Chehab # So, we remove spaces when parsing the 121784ce5b98SMauro Carvalho Chehab # names, in order to match just names 121884ce5b98SMauro Carvalho Chehab # and commas for the names 121984ce5b98SMauro Carvalho Chehab $arg =~ s/\s*,\s*/,/g; 122084ce5b98SMauro Carvalho Chehab if ($arg =~ m/(.*)\s+([\S+,]+)/) { 122184ce5b98SMauro Carvalho Chehab $type = $1; 122284ce5b98SMauro Carvalho Chehab $names = $2; 122384ce5b98SMauro Carvalho Chehab } else { 122484ce5b98SMauro Carvalho Chehab $newmember .= "$arg; "; 122584ce5b98SMauro Carvalho Chehab next; 122684ce5b98SMauro Carvalho Chehab } 122784ce5b98SMauro Carvalho Chehab foreach my $name (split /,/, $names) { 122884ce5b98SMauro Carvalho Chehab $name =~ s/^\s*\**(\S+)\s*/$1/; 12298ad72163SMauro Carvalho Chehab next if (($name =~ m/^\s*$/)); 12308ad72163SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 12318ad72163SMauro Carvalho Chehab # anonymous struct/union 12328ad72163SMauro Carvalho Chehab $newmember .= "$type $name; "; 12338ad72163SMauro Carvalho Chehab } else { 12348ad72163SMauro Carvalho Chehab $newmember .= "$type $id.$name; "; 12358ad72163SMauro Carvalho Chehab } 12368ad72163SMauro Carvalho Chehab } 12377c0d7e87SMauro Carvalho Chehab } 123884ce5b98SMauro Carvalho Chehab } 123984ce5b98SMauro Carvalho Chehab } 1240e86bdb24SAditya Srivastava $members =~ s/$struct_members/$newmember/; 124184ce5b98SMauro Carvalho Chehab } 12428ad72163SMauro Carvalho Chehab 12438ad72163SMauro Carvalho Chehab # Ignore other nested elements, like enums 1244673bb2dfSBen Hutchings $members =~ s/(\{[^\{\}]*\})//g; 12458ad72163SMauro Carvalho Chehab 1246151c468bSMauro Carvalho Chehab create_parameterlist($members, ';', $file, $declaration_name); 12471081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual); 12481da177e4SLinus Torvalds 12498ad72163SMauro Carvalho Chehab # Adjust declaration for better display 1250673bb2dfSBen Hutchings $declaration =~ s/([\{;])/$1\n/g; 1251673bb2dfSBen Hutchings $declaration =~ s/\}\s+;/};/g; 12528ad72163SMauro Carvalho Chehab # Better handle inlined enums 1253673bb2dfSBen Hutchings do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/); 12548ad72163SMauro Carvalho Chehab 12558ad72163SMauro Carvalho Chehab my @def_args = split /\n/, $declaration; 12568ad72163SMauro Carvalho Chehab my $level = 1; 12578ad72163SMauro Carvalho Chehab $declaration = ""; 12588ad72163SMauro Carvalho Chehab foreach my $clause (@def_args) { 12598ad72163SMauro Carvalho Chehab $clause =~ s/^\s+//; 12608ad72163SMauro Carvalho Chehab $clause =~ s/\s+$//; 12618ad72163SMauro Carvalho Chehab $clause =~ s/\s+/ /; 12628ad72163SMauro Carvalho Chehab next if (!$clause); 1263673bb2dfSBen Hutchings $level-- if ($clause =~ m/(\})/ && $level > 1); 12648ad72163SMauro Carvalho Chehab if (!($clause =~ m/^\s*#/)) { 12658ad72163SMauro Carvalho Chehab $declaration .= "\t" x $level; 12668ad72163SMauro Carvalho Chehab } 12678ad72163SMauro Carvalho Chehab $declaration .= "\t" . $clause . "\n"; 1268673bb2dfSBen Hutchings $level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/)); 12698ad72163SMauro Carvalho Chehab } 12701da177e4SLinus Torvalds output_declaration($declaration_name, 12711da177e4SLinus Torvalds 'struct', 12721da177e4SLinus Torvalds {'struct' => $declaration_name, 12731da177e4SLinus Torvalds 'module' => $modulename, 12748ad72163SMauro Carvalho Chehab 'definition' => $declaration, 12751da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 12761da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 12771da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 12781da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 12791da177e4SLinus Torvalds 'sections' => \%sections, 12801da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 12811da177e4SLinus Torvalds 'type' => $decl_type 12821da177e4SLinus Torvalds }); 1283*af404fb1SVegard Nossum } else { 1284d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 12851da177e4SLinus Torvalds ++$errors; 12861da177e4SLinus Torvalds } 12871da177e4SLinus Torvalds} 12881da177e4SLinus Torvalds 128985afe608SMauro Carvalho Chehab 129085afe608SMauro Carvalho Chehabsub show_warnings($$) { 129185afe608SMauro Carvalho Chehab my $functype = shift; 129285afe608SMauro Carvalho Chehab my $name = shift; 129385afe608SMauro Carvalho Chehab 1294eab795ddSMauro Carvalho Chehab return 0 if (defined($nosymbol_table{$name})); 1295eab795ddSMauro Carvalho Chehab 129685afe608SMauro Carvalho Chehab return 1 if ($output_selection == OUTPUT_ALL); 129785afe608SMauro Carvalho Chehab 129885afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_EXPORTED) { 129985afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 130085afe608SMauro Carvalho Chehab return 1; 130185afe608SMauro Carvalho Chehab } else { 130285afe608SMauro Carvalho Chehab return 0; 130385afe608SMauro Carvalho Chehab } 130485afe608SMauro Carvalho Chehab } 130585afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_INTERNAL) { 130685afe608SMauro Carvalho Chehab if (!($functype eq "function" && defined($function_table{$name}))) { 130785afe608SMauro Carvalho Chehab return 1; 130885afe608SMauro Carvalho Chehab } else { 130985afe608SMauro Carvalho Chehab return 0; 131085afe608SMauro Carvalho Chehab } 131185afe608SMauro Carvalho Chehab } 131285afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_INCLUDE) { 131385afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 131485afe608SMauro Carvalho Chehab return 1; 131585afe608SMauro Carvalho Chehab } else { 131685afe608SMauro Carvalho Chehab return 0; 131785afe608SMauro Carvalho Chehab } 131885afe608SMauro Carvalho Chehab } 131985afe608SMauro Carvalho Chehab die("Please add the new output type at show_warnings()"); 132085afe608SMauro Carvalho Chehab} 132185afe608SMauro Carvalho Chehab 13221da177e4SLinus Torvaldssub dump_enum($$) { 13231da177e4SLinus Torvalds my $x = shift; 13241da177e4SLinus Torvalds my $file = shift; 1325d38c8cfbSMauro Carvalho Chehab my $members; 1326d38c8cfbSMauro Carvalho Chehab 1327e27cb89aSJakub Kicinski # ignore members marked private: 1328e27cb89aSJakub Kicinski $x =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 1329e27cb89aSJakub Kicinski $x =~ s/\/\*\s*private:.*}/}/gosi; 13301da177e4SLinus Torvalds 1331aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 13324468e21eSConchúr Navid # strip #define macros inside enums 13334468e21eSConchúr Navid $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 1334b6d676dbSRandy Dunlap 1335d38c8cfbSMauro Carvalho Chehab if ($x =~ /typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;/) { 1336d38c8cfbSMauro Carvalho Chehab $declaration_name = $2; 1337d38c8cfbSMauro Carvalho Chehab $members = $1; 1338d38c8cfbSMauro Carvalho Chehab } elsif ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) { 13391da177e4SLinus Torvalds $declaration_name = $1; 1340d38c8cfbSMauro Carvalho Chehab $members = $2; 1341d38c8cfbSMauro Carvalho Chehab } 1342d38c8cfbSMauro Carvalho Chehab 1343ae5b17e4SAndy Shevchenko if ($members) { 134452042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 13450b54c2e3SMauro Carvalho Chehab if ($identifier eq "") { 1346df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "wrong kernel-doc identifier on line:\n"); 13470b54c2e3SMauro Carvalho Chehab } else { 1348df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "expecting prototype for enum $identifier. Prototype was for enum $declaration_name instead\n"); 13490b54c2e3SMauro Carvalho Chehab } 135052042e2dSMauro Carvalho Chehab return; 135152042e2dSMauro Carvalho Chehab } 13520b54c2e3SMauro Carvalho Chehab $declaration_name = "(anonymous)" if ($declaration_name eq ""); 135352042e2dSMauro Carvalho Chehab 13545cb5c31cSJohannes Berg my %_members; 13555cb5c31cSJohannes Berg 1356463a0fdcSMarkus Heiser $members =~ s/\s+$//; 13570ef5de7bSPavan Kumar Linga $members =~ s/\([^;]*?[\)]//g; 13581da177e4SLinus Torvalds 13591da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 13601da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 13611da177e4SLinus Torvalds push @parameterlist, $arg; 13621da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 13631da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 136485afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 1365df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Enum value '$arg' not described in enum '$declaration_name'\n"); 13662defb272SMauro Carvalho Chehab } 13671da177e4SLinus Torvalds } 13685cb5c31cSJohannes Berg $_members{$arg} = 1; 13695cb5c31cSJohannes Berg } 13701da177e4SLinus Torvalds 13715cb5c31cSJohannes Berg while (my ($k, $v) = each %parameterdescs) { 13725cb5c31cSJohannes Berg if (!exists($_members{$k})) { 137385afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 1374df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Excess enum value '$k' description in '$declaration_name'\n"); 13752defb272SMauro Carvalho Chehab } 13765cb5c31cSJohannes Berg } 13771da177e4SLinus Torvalds } 13781da177e4SLinus Torvalds 13791da177e4SLinus Torvalds output_declaration($declaration_name, 13801da177e4SLinus Torvalds 'enum', 13811da177e4SLinus Torvalds {'enum' => $declaration_name, 13821da177e4SLinus Torvalds 'module' => $modulename, 13831da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 13841da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 13851da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 13861da177e4SLinus Torvalds 'sections' => \%sections, 13871da177e4SLinus Torvalds 'purpose' => $declaration_purpose 13881da177e4SLinus Torvalds }); 1389d38c8cfbSMauro Carvalho Chehab } else { 1390d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 13911da177e4SLinus Torvalds ++$errors; 13921da177e4SLinus Torvalds } 13931da177e4SLinus Torvalds} 13941da177e4SLinus Torvalds 13957d2c6b1eSMauro Carvalho Chehabmy $typedef_type = qr { ((?:\s+[\w\*]+\b){1,8})\s* }x; 13967efc6c42SMauro Carvalho Chehabmy $typedef_ident = qr { \*?\s*(\w\S+)\s* }x; 13977efc6c42SMauro Carvalho Chehabmy $typedef_args = qr { \s*\((.*)\); }x; 13987efc6c42SMauro Carvalho Chehab 13997efc6c42SMauro Carvalho Chehabmy $typedef1 = qr { typedef$typedef_type\($typedef_ident\)$typedef_args }x; 14007efc6c42SMauro Carvalho Chehabmy $typedef2 = qr { typedef$typedef_type$typedef_ident$typedef_args }x; 14017efc6c42SMauro Carvalho Chehab 14021da177e4SLinus Torvaldssub dump_typedef($$) { 14031da177e4SLinus Torvalds my $x = shift; 14041da177e4SLinus Torvalds my $file = shift; 14051da177e4SLinus Torvalds 1406aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 140783766452SMauro Carvalho Chehab 14087efc6c42SMauro Carvalho Chehab # Parse function typedef prototypes 14097efc6c42SMauro Carvalho Chehab if ($x =~ $typedef1 || $x =~ $typedef2) { 141083766452SMauro Carvalho Chehab $return_type = $1; 141183766452SMauro Carvalho Chehab $declaration_name = $2; 141283766452SMauro Carvalho Chehab my $args = $3; 14136b80975cSMauro Carvalho Chehab $return_type =~ s/^\s+//; 141483766452SMauro Carvalho Chehab 141552042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 1416df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n"); 141752042e2dSMauro Carvalho Chehab return; 141852042e2dSMauro Carvalho Chehab } 141952042e2dSMauro Carvalho Chehab 1420151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 142183766452SMauro Carvalho Chehab 142283766452SMauro Carvalho Chehab output_declaration($declaration_name, 142383766452SMauro Carvalho Chehab 'function', 142483766452SMauro Carvalho Chehab {'function' => $declaration_name, 142582801d06SMauro Carvalho Chehab 'typedef' => 1, 142683766452SMauro Carvalho Chehab 'module' => $modulename, 142783766452SMauro Carvalho Chehab 'functiontype' => $return_type, 142883766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 142983766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 143083766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 143183766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 143283766452SMauro Carvalho Chehab 'sections' => \%sections, 143383766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 143483766452SMauro Carvalho Chehab }); 143583766452SMauro Carvalho Chehab return; 143683766452SMauro Carvalho Chehab } 143783766452SMauro Carvalho Chehab 14381da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 14391da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 14401da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 14411da177e4SLinus Torvalds } 14421da177e4SLinus Torvalds 14431da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 14441da177e4SLinus Torvalds $declaration_name = $1; 14451da177e4SLinus Torvalds 144652042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 1447df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n"); 144852042e2dSMauro Carvalho Chehab return; 144952042e2dSMauro Carvalho Chehab } 145052042e2dSMauro Carvalho Chehab 14511da177e4SLinus Torvalds output_declaration($declaration_name, 14521da177e4SLinus Torvalds 'typedef', 14531da177e4SLinus Torvalds {'typedef' => $declaration_name, 14541da177e4SLinus Torvalds 'module' => $modulename, 14551da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 14561da177e4SLinus Torvalds 'sections' => \%sections, 14571da177e4SLinus Torvalds 'purpose' => $declaration_purpose 14581da177e4SLinus Torvalds }); 1459*af404fb1SVegard Nossum } else { 1460d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 14611da177e4SLinus Torvalds ++$errors; 14621da177e4SLinus Torvalds } 14631da177e4SLinus Torvalds} 14641da177e4SLinus Torvalds 1465a1d94aa5SRandy Dunlapsub save_struct_actual($) { 1466a1d94aa5SRandy Dunlap my $actual = shift; 1467a1d94aa5SRandy Dunlap 1468a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 1469a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 1470a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 1471a1d94aa5SRandy Dunlap} 1472a1d94aa5SRandy Dunlap 1473151c468bSMauro Carvalho Chehabsub create_parameterlist($$$$) { 14741da177e4SLinus Torvalds my $args = shift; 14751da177e4SLinus Torvalds my $splitter = shift; 14761da177e4SLinus Torvalds my $file = shift; 1477151c468bSMauro Carvalho Chehab my $declaration_name = shift; 14781da177e4SLinus Torvalds my $type; 14791da177e4SLinus Torvalds my $param; 14801da177e4SLinus Torvalds 1481a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 1482e86bdb24SAditya Srivastava my $arg_expr = qr{\([^\),]+}; 1483e86bdb24SAditya Srivastava while ($args =~ /$arg_expr,/) { 1484e86bdb24SAditya Srivastava $args =~ s/($arg_expr),/$1#/g; 14851da177e4SLinus Torvalds } 14861da177e4SLinus Torvalds 14871da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 14881da177e4SLinus Torvalds # strip comments 14891da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 149003699f27SKees Cook # ignore argument attributes 149103699f27SKees Cook $arg =~ s/\sPOS0?\s/ /; 14921da177e4SLinus Torvalds # strip leading/trailing spaces 14931da177e4SLinus Torvalds $arg =~ s/^\s*//; 14941da177e4SLinus Torvalds $arg =~ s/\s*$//; 14951da177e4SLinus Torvalds $arg =~ s/\s+/ /; 14961da177e4SLinus Torvalds 14971da177e4SLinus Torvalds if ($arg =~ /^#/) { 14981da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 14991da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 15001da177e4SLinus Torvalds # output_* subs. 1501ed8348e2SMauro Carvalho Chehab push_parameter($arg, "", "", $file); 150200d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 15031da177e4SLinus Torvalds # pointer-to-function 15041da177e4SLinus Torvalds $arg =~ tr/#/,/; 1505336ced2dSAditya Srivastava $arg =~ m/[^\(]+\(\*?\s*([\w\[\]\.]*)\s*\)/; 15061da177e4SLinus Torvalds $param = $1; 15071da177e4SLinus Torvalds $type = $arg; 150800d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1509a1d94aa5SRandy Dunlap save_struct_actual($param); 1510ed8348e2SMauro Carvalho Chehab push_parameter($param, $type, $arg, $file, $declaration_name); 1511bbf00be9SSakari Ailus } elsif ($arg =~ m/\(.+\)\s*\[/) { 1512bbf00be9SSakari Ailus # array-of-pointers 1513bbf00be9SSakari Ailus $arg =~ tr/#/,/; 1514bbf00be9SSakari Ailus $arg =~ m/[^\(]+\(\s*\*\s*([\w\[\]\.]*?)\s*(\s*\[\s*[\w]+\s*\]\s*)*\)/; 1515bbf00be9SSakari Ailus $param = $1; 1516bbf00be9SSakari Ailus $type = $arg; 1517bbf00be9SSakari Ailus $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1518bbf00be9SSakari Ailus save_struct_actual($param); 1519bbf00be9SSakari Ailus push_parameter($param, $type, $arg, $file, $declaration_name); 1520aeec46b9SMartin Waitz } elsif ($arg) { 15211da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 15221da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 15231da177e4SLinus Torvalds 15241da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 15251da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 15261da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 15271da177e4SLinus Torvalds } 1528884f2810SBorislav Petkov 1529884f2810SBorislav Petkov my @first_arg; 1530884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1531884f2810SBorislav Petkov shift @args; 1532884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 1533884f2810SBorislav Petkov push(@first_arg, $2); 1534884f2810SBorislav Petkov } else { 1535884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 1536884f2810SBorislav Petkov } 1537884f2810SBorislav Petkov 15381da177e4SLinus Torvalds unshift(@args, pop @first_arg); 15391da177e4SLinus Torvalds $type = join " ", @first_arg; 15401da177e4SLinus Torvalds 15411da177e4SLinus Torvalds foreach $param (@args) { 15421da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 1543a1d94aa5SRandy Dunlap save_struct_actual($2); 1544ed8348e2SMauro Carvalho Chehab 1545ed8348e2SMauro Carvalho Chehab push_parameter($2, "$type $1", $arg, $file, $declaration_name); 1546*af404fb1SVegard Nossum } elsif ($param =~ m/(.*?):(\d+)/) { 15477b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 1548a1d94aa5SRandy Dunlap save_struct_actual($1); 1549ed8348e2SMauro Carvalho Chehab push_parameter($1, "$type:$2", $arg, $file, $declaration_name) 15501da177e4SLinus Torvalds } 1551*af404fb1SVegard Nossum } else { 1552a1d94aa5SRandy Dunlap save_struct_actual($param); 1553ed8348e2SMauro Carvalho Chehab push_parameter($param, $type, $arg, $file, $declaration_name); 15541da177e4SLinus Torvalds } 15551da177e4SLinus Torvalds } 15561da177e4SLinus Torvalds } 15571da177e4SLinus Torvalds } 15581da177e4SLinus Torvalds} 15591da177e4SLinus Torvalds 1560ed8348e2SMauro Carvalho Chehabsub push_parameter($$$$$) { 15611da177e4SLinus Torvalds my $param = shift; 15621da177e4SLinus Torvalds my $type = shift; 1563ed8348e2SMauro Carvalho Chehab my $org_arg = shift; 15641da177e4SLinus Torvalds my $file = shift; 1565151c468bSMauro Carvalho Chehab my $declaration_name = shift; 15661da177e4SLinus Torvalds 15675f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 15685f8c7c98SRandy Dunlap ($param eq "}")) { 15695f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 15705f8c7c98SRandy Dunlap } 15715f8c7c98SRandy Dunlap 15725f8c7c98SRandy Dunlap $anon_struct_union = 0; 1573f9b5c530SMauro Carvalho Chehab $param =~ s/[\[\)].*//; 15741da177e4SLinus Torvalds 1575a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 15761da177e4SLinus Torvalds { 1577c950a173SSilvio Fricke if (!$param =~ /\w\.\.\.$/) { 1578c950a173SSilvio Fricke # handles unnamed variable parameters 1579ef00028bSJonathan Corbet $param = "..."; 1580*af404fb1SVegard Nossum } elsif ($param =~ /\w\.\.\.$/) { 158143756e34SJonathan Neuschäfer # for named variable parameters of the form `x...`, remove the dots 158243756e34SJonathan Neuschäfer $param =~ s/\.\.\.$//; 158343756e34SJonathan Neuschäfer } 1584ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1585a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 15861da177e4SLinus Torvalds } 1587ced69090SRandy Dunlap } 15881da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 15891da177e4SLinus Torvalds { 15901da177e4SLinus Torvalds $param="void"; 15911da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 15921da177e4SLinus Torvalds } 1593134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1594134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 1595134fe01bSRandy Dunlap { 1596134fe01bSRandy Dunlap $type = $param; 1597134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 1598134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 15995f8c7c98SRandy Dunlap $anon_struct_union = 1; 1600134fe01bSRandy Dunlap } 1601aeb9ce05SCoco Li elsif ($param =~ "__cacheline_group" ) 1602aeb9ce05SCoco Li # handle cache group enforcing variables: they do not need be described in header files 1603aeb9ce05SCoco Li { 1604aeb9ce05SCoco Li return; # ignore __cacheline_group_begin and __cacheline_group_end 1605aeb9ce05SCoco Li } 1606134fe01bSRandy Dunlap 1607a6d3fe77SMartin Waitz # warn if parameter has no description 1608134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 1609134fe01bSRandy Dunlap # but inline preprocessor statements); 1610151c468bSMauro Carvalho Chehab # Note: It will also ignore void params and unnamed structs/unions 1611f9b5c530SMauro Carvalho Chehab if (!defined $parameterdescs{$param} && $param !~ /^#/) { 1612f9b5c530SMauro Carvalho Chehab $parameterdescs{$param} = $undescribed; 16131da177e4SLinus Torvalds 1614be5cd20cSJonathan Corbet if (show_warnings($type, $declaration_name) && $param !~ /\./) { 16150c3ebff5SKees Cook emit_warning("${file}:$.", "Function parameter or struct member '$param' not described in '$declaration_name'\n"); 16161da177e4SLinus Torvalds } 16172defb272SMauro Carvalho Chehab } 16181da177e4SLinus Torvalds 161925985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 1620e34e7dbbSRandy Dunlap # on @parameterlist; 1621e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 1622e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 1623e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 1624e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 1625e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 1626e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 1627e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 16281da177e4SLinus Torvalds push @parameterlist, $param; 1629ed8348e2SMauro Carvalho Chehab $org_arg =~ s/\s\s+/ /g; 1630ed8348e2SMauro Carvalho Chehab $parametertypes{$param} = $org_arg; 16311da177e4SLinus Torvalds} 16321da177e4SLinus Torvalds 16331081de2dSMauro Carvalho Chehabsub check_sections($$$$$) { 16341081de2dSMauro Carvalho Chehab my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_; 1635a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 1636a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 1637a1d94aa5SRandy Dunlap my $err; 1638a1d94aa5SRandy Dunlap my ($px, $sx); 1639a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 1640a1d94aa5SRandy Dunlap 1641a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 1642a1d94aa5SRandy Dunlap $err = 1; 1643a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 1644a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 1645a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 1646e86bdb24SAditya Srivastava $prm_clean =~ s/$attribute//i; 1647e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 1648e34e7dbbSRandy Dunlap # however, the original param string may contain 1649e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 1650e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 1651e34e7dbbSRandy Dunlap # parameter list is split at spaces; 1652e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 1653e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 1654e34e7dbbSRandy Dunlap 1655a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 1656a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 1657a1d94aa5SRandy Dunlap $err = 0; 1658a1d94aa5SRandy Dunlap last; 1659a1d94aa5SRandy Dunlap } 1660a1d94aa5SRandy Dunlap } 1661a1d94aa5SRandy Dunlap if ($err) { 1662a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 1663df4bf98eSNiklas Söderlund emit_warning("${file}:$.", 1664a1d94aa5SRandy Dunlap "Excess function parameter " . 1665a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 1666df4bf98eSNiklas Söderlund "description in '$decl_name'\n"); 1667*af404fb1SVegard Nossum } elsif (($decl_type eq "struct") or 1668b77fdd6aSRandy Dunlap ($decl_type eq "union")) { 1669b77fdd6aSRandy Dunlap emit_warning("${file}:$.", 1670b77fdd6aSRandy Dunlap "Excess $decl_type member " . 1671b77fdd6aSRandy Dunlap "'$sects[$sx]' " . 1672b77fdd6aSRandy Dunlap "description in '$decl_name'\n"); 1673b77fdd6aSRandy Dunlap } 1674a1d94aa5SRandy Dunlap } 1675a1d94aa5SRandy Dunlap } 1676a1d94aa5SRandy Dunlap} 1677a1d94aa5SRandy Dunlap 16781da177e4SLinus Torvalds## 16794092bac7SYacine Belkadi# Checks the section describing the return value of a function. 16804092bac7SYacine Belkadisub check_return_section { 16814092bac7SYacine Belkadi my $file = shift; 16824092bac7SYacine Belkadi my $declaration_name = shift; 16834092bac7SYacine Belkadi my $return_type = shift; 16844092bac7SYacine Belkadi 16854092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 16864092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 16874092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 16884092bac7SYacine Belkadi return; 16894092bac7SYacine Belkadi } 16904092bac7SYacine Belkadi 16914092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 1692*af404fb1SVegard Nossum $sections{$section_return} eq "") 1693*af404fb1SVegard Nossum { 1694df4bf98eSNiklas Söderlund emit_warning("${file}:$.", 16954092bac7SYacine Belkadi "No description found for return value of " . 1696df4bf98eSNiklas Söderlund "'$declaration_name'\n"); 16974092bac7SYacine Belkadi } 16984092bac7SYacine Belkadi} 16994092bac7SYacine Belkadi 17004092bac7SYacine Belkadi## 17011da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 17021da177e4SLinus Torvalds# processed and spits out all the details stored in the global 17031da177e4SLinus Torvalds# arrays/hashes. 17041da177e4SLinus Torvaldssub dump_function($$) { 17051da177e4SLinus Torvalds my $prototype = shift; 17061da177e4SLinus Torvalds my $file = shift; 1707cbb4d3e6SHoria Geanta my $noret = 0; 17081da177e4SLinus Torvalds 17095ef09c96SMauro Carvalho Chehab print_lineno($new_start_line); 17105eb6b4b3SMauro Carvalho Chehab 17111da177e4SLinus Torvalds $prototype =~ s/^static +//; 17121da177e4SLinus Torvalds $prototype =~ s/^extern +//; 17134dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 17141da177e4SLinus Torvalds $prototype =~ s/^inline +//; 17151da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 171632e79401SRandy Dunlap $prototype =~ s/^__inline +//; 171732e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 171832e79401SRandy Dunlap $prototype =~ s/^noinline +//; 171903699f27SKees Cook $prototype =~ s/^__FORTIFY_INLINE +//; 172074fc5c65SRandy Dunlap $prototype =~ s/__init +//; 172120072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 172280342d48SMatthew Wilcox $prototype =~ s/__deprecated +//; 1723084aa001SAditya Srivastava $prototype =~ s/__flatten +//; 1724270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 172570c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 17260df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 17270891f959SMatthew Wilcox $prototype =~ s/__sched +//; 172895e760cbSRandy Dunlap $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//; 172903699f27SKees Cook $prototype =~ s/__(?:re)?alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +//; 173003699f27SKees Cook $prototype =~ s/__diagnose_as\s*\(\s*\S+\s*(?:,\s*\d+\s*)*\) +//; 1731cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 1732084aa001SAditya Srivastava $prototype =~ s/__attribute_const__ +//; 1733b1aaa546SPaolo Bonzini $prototype =~ s/__attribute__\s*\(\( 1734b1aaa546SPaolo Bonzini (?: 1735b1aaa546SPaolo Bonzini [\w\s]++ # attribute name 1736b1aaa546SPaolo Bonzini (?:\([^)]*+\))? # attribute arguments 1737b1aaa546SPaolo Bonzini \s*+,? # optional comma at the end 1738b1aaa546SPaolo Bonzini )+ 1739b1aaa546SPaolo Bonzini \)\)\s+//x; 17401da177e4SLinus Torvalds 17411da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 17421da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 17431da177e4SLinus Torvalds # 2. Function name 17441da177e4SLinus Torvalds # 3. Function parameters. 17451da177e4SLinus Torvalds # 17461da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 17471da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 17481da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 17491da177e4SLinus Torvalds # so on. 17501da177e4SLinus Torvalds # 17511da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 17521da177e4SLinus Torvalds # the following functions' documentation still comes out right: 17531da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 17541da177e4SLinus Torvalds # - atomic_set (macro) 17559598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 1756e86bdb24SAditya Srivastava my $name = qr{[a-zA-Z0-9_~:]+}; 1757e86bdb24SAditya Srivastava my $prototype_end1 = qr{[^\(]*}; 1758e86bdb24SAditya Srivastava my $prototype_end2 = qr{[^\{]*}; 1759e86bdb24SAditya Srivastava my $prototype_end = qr{\(($prototype_end1|$prototype_end2)\)}; 1760e86bdb24SAditya Srivastava my $type1 = qr{[\w\s]+}; 1761e86bdb24SAditya Srivastava my $type2 = qr{$type1\*+}; 17621da177e4SLinus Torvalds 1763e86bdb24SAditya Srivastava if ($define && $prototype =~ m/^()($name)\s+/) { 1764cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 1765cbb4d3e6SHoria Geanta # list. 1766cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 1767cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 1768cbb4d3e6SHoria Geanta $return_type = $1; 1769cbb4d3e6SHoria Geanta $declaration_name = $2; 1770cbb4d3e6SHoria Geanta $noret = 1; 1771e86bdb24SAditya Srivastava } elsif ($prototype =~ m/^()($name)\s*$prototype_end/ || 1772e86bdb24SAditya Srivastava $prototype =~ m/^($type1)\s+($name)\s*$prototype_end/ || 1773e86bdb24SAditya Srivastava $prototype =~ m/^($type2+)\s*($name)\s*$prototype_end/) { 17741da177e4SLinus Torvalds $return_type = $1; 17751da177e4SLinus Torvalds $declaration_name = $2; 17761da177e4SLinus Torvalds my $args = $3; 17771da177e4SLinus Torvalds 1778151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 17791da177e4SLinus Torvalds } else { 1780df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "cannot understand function prototype: '$prototype'\n"); 17811da177e4SLinus Torvalds return; 17821da177e4SLinus Torvalds } 17831da177e4SLinus Torvalds 178452042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 1785df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "expecting prototype for $identifier(). Prototype was for $declaration_name() instead\n"); 178652042e2dSMauro Carvalho Chehab return; 178752042e2dSMauro Carvalho Chehab } 178852042e2dSMauro Carvalho Chehab 1789a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 17901081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, "function", $sectcheck, $prms); 1791a1d94aa5SRandy Dunlap 17924092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 17934092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 17944092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 179556b0f453SJohannes Berg # -Wreturn mode. 17964092bac7SYacine Belkadi # TODO: always perform the check. 179756b0f453SJohannes Berg if ($Wreturn && !$noret) { 17984092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 17994092bac7SYacine Belkadi } 18004092bac7SYacine Belkadi 180147bcacfdSMauro Carvalho Chehab # The function parser can be called with a typedef parameter. 180247bcacfdSMauro Carvalho Chehab # Handle it. 180347bcacfdSMauro Carvalho Chehab if ($return_type =~ /typedef/) { 180447bcacfdSMauro Carvalho Chehab output_declaration($declaration_name, 180547bcacfdSMauro Carvalho Chehab 'function', 180647bcacfdSMauro Carvalho Chehab {'function' => $declaration_name, 180747bcacfdSMauro Carvalho Chehab 'typedef' => 1, 180847bcacfdSMauro Carvalho Chehab 'module' => $modulename, 180947bcacfdSMauro Carvalho Chehab 'functiontype' => $return_type, 181047bcacfdSMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 181147bcacfdSMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 181247bcacfdSMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 181347bcacfdSMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 181447bcacfdSMauro Carvalho Chehab 'sections' => \%sections, 181547bcacfdSMauro Carvalho Chehab 'purpose' => $declaration_purpose 181647bcacfdSMauro Carvalho Chehab }); 181747bcacfdSMauro Carvalho Chehab } else { 18181da177e4SLinus Torvalds output_declaration($declaration_name, 18191da177e4SLinus Torvalds 'function', 18201da177e4SLinus Torvalds {'function' => $declaration_name, 18211da177e4SLinus Torvalds 'module' => $modulename, 18221da177e4SLinus Torvalds 'functiontype' => $return_type, 18231da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 18241da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 18251da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 18261da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 18271da177e4SLinus Torvalds 'sections' => \%sections, 18281da177e4SLinus Torvalds 'purpose' => $declaration_purpose 18291da177e4SLinus Torvalds }); 18301da177e4SLinus Torvalds } 183147bcacfdSMauro Carvalho Chehab} 18321da177e4SLinus Torvalds 18331da177e4SLinus Torvaldssub reset_state { 18341da177e4SLinus Torvalds $function = ""; 18351da177e4SLinus Torvalds %parameterdescs = (); 18361da177e4SLinus Torvalds %parametertypes = (); 18371da177e4SLinus Torvalds @parameterlist = (); 18381da177e4SLinus Torvalds %sections = (); 18391da177e4SLinus Torvalds @sectionlist = (); 1840a1d94aa5SRandy Dunlap $sectcheck = ""; 1841a1d94aa5SRandy Dunlap $struct_actual = ""; 18421da177e4SLinus Torvalds $prototype = ""; 18431da177e4SLinus Torvalds 184448af606aSJani Nikula $state = STATE_NORMAL; 184548af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 18461da177e4SLinus Torvalds} 18471da177e4SLinus Torvalds 184856afb0f8SJason Baronsub tracepoint_munge($) { 184956afb0f8SJason Baron my $file = shift; 185056afb0f8SJason Baron my $tracepointname = 0; 185156afb0f8SJason Baron my $tracepointargs = 0; 185256afb0f8SJason Baron 185356afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 185456afb0f8SJason Baron $tracepointname = $1; 185556afb0f8SJason Baron } 18563a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 18573a9089fdSJason Baron $tracepointname = $1; 18583a9089fdSJason Baron } 18593a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 18603a9089fdSJason Baron $tracepointname = $2; 18613a9089fdSJason Baron } 18623a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 186356afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 186456afb0f8SJason Baron $tracepointargs = $1; 186556afb0f8SJason Baron } 186656afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 1867df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Unrecognized tracepoint format: \n". 1868df4bf98eSNiklas Söderlund "$prototype\n"); 186956afb0f8SJason Baron } else { 187056afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 187152042e2dSMauro Carvalho Chehab $identifier = "trace_$identifier"; 187256afb0f8SJason Baron } 187356afb0f8SJason Baron} 187456afb0f8SJason Baron 1875b4870bc5SRandy Dunlapsub syscall_munge() { 1876b4870bc5SRandy Dunlap my $void = 0; 1877b4870bc5SRandy Dunlap 18787c9aa015SMauro Carvalho Chehab $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's 1879b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 1880b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 1881b4870bc5SRandy Dunlap $void = 1; 1882b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 1883b4870bc5SRandy Dunlap } 1884b4870bc5SRandy Dunlap 1885b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 1886b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 1887b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 1888b4870bc5SRandy Dunlap } elsif ($void) { 1889b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 1890b4870bc5SRandy Dunlap } 1891b4870bc5SRandy Dunlap 1892b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 1893b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 1894b4870bc5SRandy Dunlap my $count = 0; 1895b4870bc5SRandy Dunlap my $len = length($prototype); 1896b4870bc5SRandy Dunlap if ($void) { 1897b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 1898b4870bc5SRandy Dunlap } 1899b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 1900b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 1901b4870bc5SRandy Dunlap $count++; 1902b4870bc5SRandy Dunlap if ($count % 2 == 1) { 1903b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 1904b4870bc5SRandy Dunlap } 1905b4870bc5SRandy Dunlap } 1906b4870bc5SRandy Dunlap } 1907b4870bc5SRandy Dunlap} 1908b4870bc5SRandy Dunlap 1909b7afa92bSDaniel Vettersub process_proto_function($$) { 19101da177e4SLinus Torvalds my $x = shift; 19111da177e4SLinus Torvalds my $file = shift; 19121da177e4SLinus Torvalds 191351f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 191451f5a0c8SRandy Dunlap 1915d2a70e28SRandy Dunlap if ($x =~ /^#/ && $x !~ /^#\s*define/) { 19161da177e4SLinus Torvalds # do nothing 1917*af404fb1SVegard Nossum } elsif ($x =~ /([^\{]*)/) { 19181da177e4SLinus Torvalds $prototype .= $1; 19191da177e4SLinus Torvalds } 1920b4870bc5SRandy Dunlap 1921890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 19221da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 19231da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 19241da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 19257ae281b0SMauro Carvalho Chehab 19267ae281b0SMauro Carvalho Chehab # Handle prototypes for function pointers like: 19277ae281b0SMauro Carvalho Chehab # int (*pcs_config)(struct foo) 19287ae281b0SMauro Carvalho Chehab $prototype =~ s@^(\S+\s+)\(\s*\*(\S+)\)@$1$2@gos; 19297ae281b0SMauro Carvalho Chehab 1930b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 1931b4870bc5SRandy Dunlap syscall_munge(); 1932b4870bc5SRandy Dunlap } 19333a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 19343a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 19353a9089fdSJason Baron { 193656afb0f8SJason Baron tracepoint_munge($file); 193756afb0f8SJason Baron } 19381da177e4SLinus Torvalds dump_function($prototype, $file); 19391da177e4SLinus Torvalds reset_state(); 19401da177e4SLinus Torvalds } 19411da177e4SLinus Torvalds} 19421da177e4SLinus Torvalds 1943b7afa92bSDaniel Vettersub process_proto_type($$) { 19441da177e4SLinus Torvalds my $x = shift; 19451da177e4SLinus Torvalds my $file = shift; 19461da177e4SLinus Torvalds 19471da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 19481da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 19491da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 195051f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 195151f5a0c8SRandy Dunlap 19521da177e4SLinus Torvalds if ($x =~ /^#/) { 19531da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 19541da177e4SLinus Torvalds $x .= ";"; 19551da177e4SLinus Torvalds } 19561da177e4SLinus Torvalds 19571da177e4SLinus Torvalds while (1) { 1958673bb2dfSBen Hutchings if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) { 1959463a0fdcSMarkus Heiser if( length $prototype ) { 1960463a0fdcSMarkus Heiser $prototype .= " " 1961463a0fdcSMarkus Heiser } 19621da177e4SLinus Torvalds $prototype .= $1 . $2; 19631da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 19641da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 19651da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 19661da177e4SLinus Torvalds dump_declaration($prototype, $file); 19671da177e4SLinus Torvalds reset_state(); 19681da177e4SLinus Torvalds last; 19691da177e4SLinus Torvalds } 19701da177e4SLinus Torvalds $x = $3; 19711da177e4SLinus Torvalds } else { 19721da177e4SLinus Torvalds $prototype .= $x; 19731da177e4SLinus Torvalds last; 19741da177e4SLinus Torvalds } 19751da177e4SLinus Torvalds } 19761da177e4SLinus Torvalds} 19771da177e4SLinus Torvalds 19786b5b55f6SRandy Dunlap 19791ad560e4SJani Nikulasub map_filename($) { 19801ad560e4SJani Nikula my $file; 19811ad560e4SJani Nikula my ($orig_file) = @_; 19821ad560e4SJani Nikula 19831ad560e4SJani Nikula if (defined($ENV{'SRCTREE'})) { 19841ad560e4SJani Nikula $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 19851ad560e4SJani Nikula } else { 19861ad560e4SJani Nikula $file = $orig_file; 19871ad560e4SJani Nikula } 19881ad560e4SJani Nikula 19891ad560e4SJani Nikula if (defined($source_map{$file})) { 19901ad560e4SJani Nikula $file = $source_map{$file}; 19911ad560e4SJani Nikula } 19921ad560e4SJani Nikula 19931ad560e4SJani Nikula return $file; 19941ad560e4SJani Nikula} 19951ad560e4SJani Nikula 199688c2b57dSJani Nikulasub process_export_file($) { 199788c2b57dSJani Nikula my ($orig_file) = @_; 199888c2b57dSJani Nikula my $file = map_filename($orig_file); 199988c2b57dSJani Nikula 200088c2b57dSJani Nikula if (!open(IN,"<$file")) { 200188c2b57dSJani Nikula print STDERR "Error: Cannot open file $file\n"; 200288c2b57dSJani Nikula ++$errors; 200388c2b57dSJani Nikula return; 200488c2b57dSJani Nikula } 200588c2b57dSJani Nikula 200688c2b57dSJani Nikula while (<IN>) { 200788c2b57dSJani Nikula if (/$export_symbol/) { 2008eab795ddSMauro Carvalho Chehab next if (defined($nosymbol_table{$2})); 200988c2b57dSJani Nikula $function_table{$2} = 1; 201088c2b57dSJani Nikula } 2011632ce137SJason Gunthorpe if (/$export_symbol_ns/) { 2012632ce137SJason Gunthorpe next if (defined($nosymbol_table{$2})); 2013632ce137SJason Gunthorpe $function_table{$2} = 1; 2014632ce137SJason Gunthorpe } 201588c2b57dSJani Nikula } 201688c2b57dSJani Nikula 201788c2b57dSJani Nikula close(IN); 201888c2b57dSJani Nikula} 201988c2b57dSJani Nikula 202007048d13SJonathan Corbet# 202107048d13SJonathan Corbet# Parsers for the various processing states. 202207048d13SJonathan Corbet# 202307048d13SJonathan Corbet# STATE_NORMAL: looking for the /** to begin everything. 202407048d13SJonathan Corbet# 202507048d13SJonathan Corbetsub process_normal() { 20261da177e4SLinus Torvalds if (/$doc_start/o) { 202748af606aSJani Nikula $state = STATE_NAME; # next line is always the function name 2028850622dfSRandy Dunlap $in_doc_sect = 0; 20290b0f5f29SDaniel Vetter $declaration_start_line = $. + 1; 20301da177e4SLinus Torvalds } 203107048d13SJonathan Corbet} 203207048d13SJonathan Corbet 20333cac2bc4SJonathan Corbet# 20343cac2bc4SJonathan Corbet# STATE_NAME: Looking for the "name - description" line 20353cac2bc4SJonathan Corbet# 20363cac2bc4SJonathan Corbetsub process_name($$) { 20373cac2bc4SJonathan Corbet my $file = shift; 20381da177e4SLinus Torvalds my $descr; 20391da177e4SLinus Torvalds 20401da177e4SLinus Torvalds if (/$doc_block/o) { 204148af606aSJani Nikula $state = STATE_DOCBLOCK; 20421da177e4SLinus Torvalds $contents = ""; 20435ef09c96SMauro Carvalho Chehab $new_start_line = $.; 20440b0f5f29SDaniel Vetter 20451da177e4SLinus Torvalds if ( $1 eq "" ) { 20461da177e4SLinus Torvalds $section = $section_intro; 20471da177e4SLinus Torvalds } else { 20481da177e4SLinus Torvalds $section = $1; 20491da177e4SLinus Torvalds } 205052042e2dSMauro Carvalho Chehab } elsif (/$doc_decl/o) { 20511da177e4SLinus Torvalds $identifier = $1; 20523e58e839SAditya Srivastava my $is_kernel_comment = 0; 2053e86bdb24SAditya Srivastava my $decl_start = qr{$doc_com}; 2054f9bbc12cSAditya Srivastava # test for pointer declaration type, foo * bar() - desc 2055f9bbc12cSAditya Srivastava my $fn_type = qr{\w+\s*\*\s*}; 2056f9bbc12cSAditya Srivastava my $parenthesis = qr{\(\w*\)}; 2057f9bbc12cSAditya Srivastava my $decl_end = qr{[-:].*}; 2058e86bdb24SAditya Srivastava if (/^$decl_start([\w\s]+?)$parenthesis?\s*$decl_end?$/) { 20591da177e4SLinus Torvalds $identifier = $1; 20601da177e4SLinus Torvalds } 206152042e2dSMauro Carvalho Chehab if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) { 206252042e2dSMauro Carvalho Chehab $decl_type = $1; 206352042e2dSMauro Carvalho Chehab $identifier = $2; 20643e58e839SAditya Srivastava $is_kernel_comment = 1; 206552042e2dSMauro Carvalho Chehab } 2066f9bbc12cSAditya Srivastava # Look for foo() or static void foo() - description; or misspelt 2067f9bbc12cSAditya Srivastava # identifier 2068e86bdb24SAditya Srivastava elsif (/^$decl_start$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ || 2069e86bdb24SAditya Srivastava /^$decl_start$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) { 2070f9bbc12cSAditya Srivastava $identifier = $1; 2071f9bbc12cSAditya Srivastava $decl_type = 'function'; 2072f9bbc12cSAditya Srivastava $identifier =~ s/^define\s+//; 2073f9bbc12cSAditya Srivastava $is_kernel_comment = 1; 2074f9bbc12cSAditya Srivastava } 207552042e2dSMauro Carvalho Chehab $identifier =~ s/\s+$//; 20761da177e4SLinus Torvalds 207717b78717SJonathan Corbet $state = STATE_BODY; 20780b0f5f29SDaniel Vetter # if there's no @param blocks need to set up default section 20790b0f5f29SDaniel Vetter # here 20802f4ad40aSJani Nikula $contents = ""; 20812f4ad40aSJani Nikula $section = $section_default; 20820b0f5f29SDaniel Vetter $new_start_line = $. + 1; 208352042e2dSMauro Carvalho Chehab if (/[-:](.*)/) { 208451f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2085a21217daSRandy Dunlap $descr= $1; 2086a21217daSRandy Dunlap $descr =~ s/^\s*//; 2087a21217daSRandy Dunlap $descr =~ s/\s*$//; 208812ae6779SDaniel Santos $descr =~ s/\s+/ /g; 20890bba924cSJonathan Corbet $declaration_purpose = $descr; 209017b78717SJonathan Corbet $state = STATE_BODY_MAYBE; 20911da177e4SLinus Torvalds } else { 20921da177e4SLinus Torvalds $declaration_purpose = ""; 20931da177e4SLinus Torvalds } 209477cc23b8SRandy Dunlap 20953e58e839SAditya Srivastava if (!$is_kernel_comment) { 2096df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst\n$_"); 20973e58e839SAditya Srivastava $state = STATE_NORMAL; 20983e58e839SAditya Srivastava } 20993e58e839SAditya Srivastava 210056b0f453SJohannes Berg if (($declaration_purpose eq "") && $Wshort_desc) { 2101df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "missing initial short description on line:\n$_"); 210277cc23b8SRandy Dunlap } 210377cc23b8SRandy Dunlap 21040b54c2e3SMauro Carvalho Chehab if ($identifier eq "" && $decl_type ne "enum") { 2105df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "wrong kernel-doc identifier on line:\n$_"); 210652042e2dSMauro Carvalho Chehab $state = STATE_NORMAL; 21071da177e4SLinus Torvalds } 21081da177e4SLinus Torvalds 21091da177e4SLinus Torvalds if ($verbose) { 211052042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: info: Scanning doc for $decl_type $identifier\n"; 21111da177e4SLinus Torvalds } 21121da177e4SLinus Torvalds } else { 2113df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Cannot understand $_ on line $. - I thought it was a doc line\n"); 211448af606aSJani Nikula $state = STATE_NORMAL; 21151da177e4SLinus Torvalds } 21163cac2bc4SJonathan Corbet} 21173cac2bc4SJonathan Corbet 21183cac2bc4SJonathan Corbet 2119d742f24dSJonathan Corbet# 2120d742f24dSJonathan Corbet# STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment. 2121d742f24dSJonathan Corbet# 2122d742f24dSJonathan Corbetsub process_body($$) { 2123d742f24dSJonathan Corbet my $file = shift; 21243cac2bc4SJonathan Corbet 21250d55d48bSMauro Carvalho Chehab if ($state == STATE_BODY_WITH_BLANK_LINE && /^\s*\*\s?\S/) { 21260d55d48bSMauro Carvalho Chehab dump_section($file, $section, $contents); 21270d55d48bSMauro Carvalho Chehab $section = $section_default; 21285ef09c96SMauro Carvalho Chehab $new_start_line = $.; 21290d55d48bSMauro Carvalho Chehab $contents = ""; 21300d55d48bSMauro Carvalho Chehab } 21310d55d48bSMauro Carvalho Chehab 2132f624adefSJani Nikula if (/$doc_sect/i) { # case insensitive for supported section names 2133afa751e8SRandy Dunlap $in_doc_sect = 1; 21341da177e4SLinus Torvalds $newsection = $1; 21351da177e4SLinus Torvalds $newcontents = $2; 21361da177e4SLinus Torvalds 2137f624adefSJani Nikula # map the supported section names to the canonical names 2138f624adefSJani Nikula if ($newsection =~ m/^description$/i) { 2139f624adefSJani Nikula $newsection = $section_default; 2140f624adefSJani Nikula } elsif ($newsection =~ m/^context$/i) { 2141f624adefSJani Nikula $newsection = $section_context; 2142f624adefSJani Nikula } elsif ($newsection =~ m/^returns?$/i) { 2143f624adefSJani Nikula $newsection = $section_return; 2144f624adefSJani Nikula } elsif ($newsection =~ m/^\@return$/) { 2145f624adefSJani Nikula # special: @return is a section, not a param description 2146f624adefSJani Nikula $newsection = $section_return; 2147f624adefSJani Nikula } 2148f624adefSJani Nikula 2149792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 215056b0f453SJohannes Berg if (!$in_doc_sect && $Wcontents_before_sections) { 2151df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "contents before sections\n"); 2152850622dfSRandy Dunlap } 21530bba924cSJonathan Corbet dump_section($file, $section, $contents); 21541da177e4SLinus Torvalds $section = $section_default; 21551da177e4SLinus Torvalds } 21561da177e4SLinus Torvalds 2157850622dfSRandy Dunlap $in_doc_sect = 1; 215817b78717SJonathan Corbet $state = STATE_BODY; 21591da177e4SLinus Torvalds $contents = $newcontents; 21600b0f5f29SDaniel Vetter $new_start_line = $.; 21617c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 216205189497SRandy Dunlap $contents = substr($contents, 1); 216305189497SRandy Dunlap } 21640a726301SJani Nikula if ($contents ne "") { 21651da177e4SLinus Torvalds $contents .= "\n"; 21661da177e4SLinus Torvalds } 21671da177e4SLinus Torvalds $section = $newsection; 2168b7886de4SJani Nikula $leading_space = undef; 21691da177e4SLinus Torvalds } elsif (/$doc_end/) { 21704c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 21710bba924cSJonathan Corbet dump_section($file, $section, $contents); 21721da177e4SLinus Torvalds $section = $section_default; 21731da177e4SLinus Torvalds $contents = ""; 21741da177e4SLinus Torvalds } 217546b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 217646b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2177df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "suspicious ending line: $_"); 217846b958ebSRandy Dunlap } 21791da177e4SLinus Torvalds 21801da177e4SLinus Torvalds $prototype = ""; 218148af606aSJani Nikula $state = STATE_PROTO; 21821da177e4SLinus Torvalds $brcount = 0; 21835ef09c96SMauro Carvalho Chehab $new_start_line = $. + 1; 21841da177e4SLinus Torvalds } elsif (/$doc_content/) { 21856423133bSJohannes Weiner if ($1 eq "") { 21860d55d48bSMauro Carvalho Chehab if ($section eq $section_context) { 21870bba924cSJonathan Corbet dump_section($file, $section, $contents); 21881da177e4SLinus Torvalds $section = $section_default; 21891da177e4SLinus Torvalds $contents = ""; 21900b0f5f29SDaniel Vetter $new_start_line = $.; 21910d55d48bSMauro Carvalho Chehab $state = STATE_BODY; 21921da177e4SLinus Torvalds } else { 21930d55d48bSMauro Carvalho Chehab if ($section ne $section_default) { 21940d55d48bSMauro Carvalho Chehab $state = STATE_BODY_WITH_BLANK_LINE; 21950d55d48bSMauro Carvalho Chehab } else { 21960d55d48bSMauro Carvalho Chehab $state = STATE_BODY; 21970d55d48bSMauro Carvalho Chehab } 21986423133bSJohannes Weiner $contents .= "\n"; 21996423133bSJohannes Weiner } 220017b78717SJonathan Corbet } elsif ($state == STATE_BODY_MAYBE) { 22016423133bSJohannes Weiner # Continued declaration purpose 22026423133bSJohannes Weiner chomp($declaration_purpose); 22030bba924cSJonathan Corbet $declaration_purpose .= " " . $1; 220412ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 22056423133bSJohannes Weiner } else { 2206b7886de4SJani Nikula my $cont = $1; 2207b7886de4SJani Nikula if ($section =~ m/^@/ || $section eq $section_context) { 2208b7886de4SJani Nikula if (!defined $leading_space) { 2209b7886de4SJani Nikula if ($cont =~ m/^(\s+)/) { 2210b7886de4SJani Nikula $leading_space = $1; 2211b7886de4SJani Nikula } else { 2212b7886de4SJani Nikula $leading_space = ""; 2213b7886de4SJani Nikula } 2214b7886de4SJani Nikula } 2215b7886de4SJani Nikula $cont =~ s/^$leading_space//; 2216b7886de4SJani Nikula } 2217b7886de4SJani Nikula $contents .= $cont . "\n"; 22181da177e4SLinus Torvalds } 22191da177e4SLinus Torvalds } else { 22201da177e4SLinus Torvalds # i dont know - bad line? ignore. 2221df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "bad line: $_"); 22221da177e4SLinus Torvalds } 2223d742f24dSJonathan Corbet} 2224d742f24dSJonathan Corbet 2225d742f24dSJonathan Corbet 2226cc794812SJonathan Corbet# 2227cc794812SJonathan Corbet# STATE_PROTO: reading a function/whatever prototype. 2228cc794812SJonathan Corbet# 2229cc794812SJonathan Corbetsub process_proto($$) { 2230cc794812SJonathan Corbet my $file = shift; 2231cc794812SJonathan Corbet 2232cc794812SJonathan Corbet if (/$doc_inline_oneline/) { 2233cc794812SJonathan Corbet $section = $1; 2234cc794812SJonathan Corbet $contents = $2; 2235cc794812SJonathan Corbet if ($contents ne "") { 2236cc794812SJonathan Corbet $contents .= "\n"; 2237cc794812SJonathan Corbet dump_section($file, $section, $contents); 2238cc794812SJonathan Corbet $section = $section_default; 2239cc794812SJonathan Corbet $contents = ""; 2240cc794812SJonathan Corbet } 2241cc794812SJonathan Corbet } elsif (/$doc_inline_start/) { 2242cc794812SJonathan Corbet $state = STATE_INLINE; 2243cc794812SJonathan Corbet $inline_doc_state = STATE_INLINE_NAME; 2244cc794812SJonathan Corbet } elsif ($decl_type eq 'function') { 2245cc794812SJonathan Corbet process_proto_function($_, $file); 2246cc794812SJonathan Corbet } else { 2247cc794812SJonathan Corbet process_proto_type($_, $file); 2248cc794812SJonathan Corbet } 2249cc794812SJonathan Corbet} 2250cc794812SJonathan Corbet 2251c17add56SJonathan Corbet# 2252c17add56SJonathan Corbet# STATE_DOCBLOCK: within a DOC: block. 2253c17add56SJonathan Corbet# 2254c17add56SJonathan Corbetsub process_docblock($$) { 2255c17add56SJonathan Corbet my $file = shift; 2256cc794812SJonathan Corbet 2257c17add56SJonathan Corbet if (/$doc_end/) { 2258c17add56SJonathan Corbet dump_doc_section($file, $section, $contents); 2259c17add56SJonathan Corbet $section = $section_default; 2260c17add56SJonathan Corbet $contents = ""; 2261c17add56SJonathan Corbet $function = ""; 2262c17add56SJonathan Corbet %parameterdescs = (); 2263c17add56SJonathan Corbet %parametertypes = (); 2264c17add56SJonathan Corbet @parameterlist = (); 2265c17add56SJonathan Corbet %sections = (); 2266c17add56SJonathan Corbet @sectionlist = (); 2267c17add56SJonathan Corbet $prototype = ""; 2268c17add56SJonathan Corbet $state = STATE_NORMAL; 2269c17add56SJonathan Corbet } elsif (/$doc_content/) { 2270c17add56SJonathan Corbet if ( $1 eq "" ) { 2271c17add56SJonathan Corbet $contents .= $blankline; 2272c17add56SJonathan Corbet } else { 2273c17add56SJonathan Corbet $contents .= $1 . "\n"; 2274c17add56SJonathan Corbet } 2275c17add56SJonathan Corbet } 2276d742f24dSJonathan Corbet} 2277d742f24dSJonathan Corbet 2278c17add56SJonathan Corbet# 2279c17add56SJonathan Corbet# STATE_INLINE: docbook comments within a prototype. 2280c17add56SJonathan Corbet# 2281c17add56SJonathan Corbetsub process_inline($$) { 2282c17add56SJonathan Corbet my $file = shift; 2283d742f24dSJonathan Corbet 2284a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 228548af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 2286a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 2287a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 22880b0f5f29SDaniel Vetter $new_start_line = $.; 2289a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 22907c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 2291a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 2292a4c6ebedSDanilo Cesar Lemes de Paula } 2293a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 2294a4c6ebedSDanilo Cesar Lemes de Paula } 229548af606aSJani Nikula $inline_doc_state = STATE_INLINE_TEXT; 2296a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 229748af606aSJani Nikula } elsif (/$doc_inline_end/) { 2298a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 22990bba924cSJonathan Corbet dump_section($file, $section, $contents); 2300a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 2301a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 2302a4c6ebedSDanilo Cesar Lemes de Paula } 230348af606aSJani Nikula $state = STATE_PROTO; 230448af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 2305a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 2306a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 230748af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_TEXT) { 2308a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 23096450c895SJani Nikula # nuke leading blank lines 23106450c895SJani Nikula if ($contents =~ /^\s*$/) { 23116450c895SJani Nikula $contents = ""; 23126450c895SJani Nikula } 231348af606aSJani Nikula } elsif ($inline_doc_state == STATE_INLINE_NAME) { 231448af606aSJani Nikula $inline_doc_state = STATE_INLINE_ERROR; 2315df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Incorrect use of kernel-doc format: $_"); 2316a4c6ebedSDanilo Cesar Lemes de Paula } 2317a4c6ebedSDanilo Cesar Lemes de Paula } 23180c9aa209SJani Nikula} 2319c17add56SJonathan Corbet 2320c17add56SJonathan Corbet 2321c17add56SJonathan Corbetsub process_file($) { 2322c17add56SJonathan Corbet my $file; 2323c17add56SJonathan Corbet my $initial_section_counter = $section_counter; 2324c17add56SJonathan Corbet my ($orig_file) = @_; 2325c17add56SJonathan Corbet 2326c17add56SJonathan Corbet $file = map_filename($orig_file); 2327c17add56SJonathan Corbet 2328dbe8ba00SMauro Carvalho Chehab if (!open(IN_FILE,"<$file")) { 2329c17add56SJonathan Corbet print STDERR "Error: Cannot open file $file\n"; 2330c17add56SJonathan Corbet ++$errors; 2331c17add56SJonathan Corbet return; 23321da177e4SLinus Torvalds } 2333c17add56SJonathan Corbet 2334c17add56SJonathan Corbet $. = 1; 2335c17add56SJonathan Corbet 2336c17add56SJonathan Corbet $section_counter = 0; 2337dbe8ba00SMauro Carvalho Chehab while (<IN_FILE>) { 2338e5a52766SAnna-Maria Behnsen while (!/^ \*/ && s/\\\s*$//) { 2339dbe8ba00SMauro Carvalho Chehab $_ .= <IN_FILE>; 2340c17add56SJonathan Corbet } 2341c17add56SJonathan Corbet # Replace tabs by spaces 2342c17add56SJonathan Corbet while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; 2343c17add56SJonathan Corbet # Hand this line to the appropriate state handler 2344c17add56SJonathan Corbet if ($state == STATE_NORMAL) { 2345c17add56SJonathan Corbet process_normal(); 2346c17add56SJonathan Corbet } elsif ($state == STATE_NAME) { 2347c17add56SJonathan Corbet process_name($file, $_); 23480d55d48bSMauro Carvalho Chehab } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE || 23490d55d48bSMauro Carvalho Chehab $state == STATE_BODY_WITH_BLANK_LINE) { 2350c17add56SJonathan Corbet process_body($file, $_); 2351c17add56SJonathan Corbet } elsif ($state == STATE_INLINE) { # scanning for inline parameters 2352c17add56SJonathan Corbet process_inline($file, $_); 2353cc794812SJonathan Corbet } elsif ($state == STATE_PROTO) { 2354cc794812SJonathan Corbet process_proto($file, $_); 235548af606aSJani Nikula } elsif ($state == STATE_DOCBLOCK) { 2356c17add56SJonathan Corbet process_docblock($file, $_); 23571da177e4SLinus Torvalds } 23581da177e4SLinus Torvalds } 2359c17add56SJonathan Corbet 2360c17add56SJonathan Corbet # Make sure we got something interesting. 2361b0d60bfbSJonathan Corbet if ($initial_section_counter == $section_counter && $ 2362b0d60bfbSJonathan Corbet output_mode ne "none") { 2363b0d60bfbSJonathan Corbet if ($output_selection == OUTPUT_INCLUDE) { 2364df4bf98eSNiklas Söderlund emit_warning("${file}:1", "'$_' not found\n") 2365b0d60bfbSJonathan Corbet for keys %function_table; 2366*af404fb1SVegard Nossum } else { 2367df4bf98eSNiklas Söderlund emit_warning("${file}:1", "no structured comments found\n"); 2368e946c43aSJohannes Berg } 23691da177e4SLinus Torvalds } 2370dbe8ba00SMauro Carvalho Chehab close IN_FILE; 23711da177e4SLinus Torvalds} 23728484baaaSRandy Dunlap 23738484baaaSRandy Dunlap 237493351d41SMauro Carvalho Chehabif ($output_mode eq "rst") { 237593351d41SMauro Carvalho Chehab get_sphinx_version() if (!$sphinx_major); 237693351d41SMauro Carvalho Chehab} 237793351d41SMauro Carvalho Chehab 23788484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 23798484baaaSRandy Dunlap 23808484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 23818484baaaSRandy Dunlap# using the s// operator. 23821ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 23834d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 23844d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 23854d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 23864d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 23878484baaaSRandy Dunlap} 23888484baaaSRandy Dunlap 23898484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 23908484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 23918484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 23928484baaaSRandy Dunlap my ($relname, $absname); 23938484baaaSRandy Dunlap while(<SOURCE_MAP>) { 23948484baaaSRandy Dunlap chop(); 23958484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 23968484baaaSRandy Dunlap $relname =~ s:^/+::; 23978484baaaSRandy Dunlap $source_map{$relname} = $absname; 23988484baaaSRandy Dunlap } 23998484baaaSRandy Dunlap close(SOURCE_MAP); 24008484baaaSRandy Dunlap} 24018484baaaSRandy Dunlap 240288c2b57dSJani Nikulaif ($output_selection == OUTPUT_EXPORTED || 240388c2b57dSJani Nikula $output_selection == OUTPUT_INTERNAL) { 2404c9b2cfb3SJani Nikula 2405c9b2cfb3SJani Nikula push(@export_file_list, @ARGV); 2406c9b2cfb3SJani Nikula 240788c2b57dSJani Nikula foreach (@export_file_list) { 240888c2b57dSJani Nikula chomp; 240988c2b57dSJani Nikula process_export_file($_); 241088c2b57dSJani Nikula } 241188c2b57dSJani Nikula} 241288c2b57dSJani Nikula 24138484baaaSRandy Dunlapforeach (@ARGV) { 24148484baaaSRandy Dunlap chomp; 24158484baaaSRandy Dunlap process_file($_); 24168484baaaSRandy Dunlap} 24178484baaaSRandy Dunlapif ($verbose && $errors) { 24188484baaaSRandy Dunlap print STDERR "$errors errors\n"; 24198484baaaSRandy Dunlap} 24208484baaaSRandy Dunlapif ($verbose && $warnings) { 24218484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 24228484baaaSRandy Dunlap} 24238484baaaSRandy Dunlap 24242c12c810SPierre-Louis Bossartif ($Werror && $warnings) { 24252c12c810SPierre-Louis Bossart print STDERR "$warnings warnings as Errors\n"; 24262c12c810SPierre-Louis Bossart exit($warnings); 24272c12c810SPierre-Louis Bossart} else { 24282c12c810SPierre-Louis Bossart exit($output_mode eq "none" ? 0 : $errors) 24292c12c810SPierre-Louis Bossart} 24302875f787STomasz Warniełło 24312875f787STomasz Warniełło__END__ 24322875f787STomasz Warniełło 24332875f787STomasz Warniełło=head1 OPTIONS 24342875f787STomasz Warniełło 24352875f787STomasz Warniełło=head2 Output format selection (mutually exclusive): 24362875f787STomasz Warniełło 24372875f787STomasz Warniełło=over 8 24382875f787STomasz Warniełło 24392875f787STomasz Warniełło=item -man 24402875f787STomasz Warniełło 24412875f787STomasz WarniełłoOutput troff manual page format. 24422875f787STomasz Warniełło 24432875f787STomasz Warniełło=item -rst 24442875f787STomasz Warniełło 24452875f787STomasz WarniełłoOutput reStructuredText format. This is the default. 24462875f787STomasz Warniełło 24472875f787STomasz Warniełło=item -none 24482875f787STomasz Warniełło 24492875f787STomasz WarniełłoDo not output documentation, only warnings. 24502875f787STomasz Warniełło 24512875f787STomasz Warniełło=back 24522875f787STomasz Warniełło 2453dd803b04STomasz Warniełło=head2 Output format modifiers 2454dd803b04STomasz Warniełło 2455dd803b04STomasz Warniełło=head3 reStructuredText only 2456dd803b04STomasz Warniełło 2457dd803b04STomasz Warniełło=over 8 2458dd803b04STomasz Warniełło 2459dd803b04STomasz Warniełło=item -sphinx-version VERSION 2460dd803b04STomasz Warniełło 2461dd803b04STomasz WarniełłoUse the ReST C domain dialect compatible with a specific Sphinx Version. 2462dd803b04STomasz Warniełło 2463dd803b04STomasz WarniełłoIf not specified, kernel-doc will auto-detect using the sphinx-build version 2464dd803b04STomasz Warniełłofound on PATH. 2465dd803b04STomasz Warniełło 2466dd803b04STomasz Warniełło=back 2467dd803b04STomasz Warniełło 24689c77f108STomasz Warniełło=head2 Output selection (mutually exclusive): 24699c77f108STomasz Warniełło 24709c77f108STomasz Warniełło=over 8 24719c77f108STomasz Warniełło 24729c77f108STomasz Warniełło=item -export 24739c77f108STomasz Warniełło 24749c77f108STomasz WarniełłoOnly output documentation for the symbols that have been exported using 2475632ce137SJason GunthorpeEXPORT_SYMBOL() and related macros in any input FILE or -export-file FILE. 24769c77f108STomasz Warniełło 24779c77f108STomasz Warniełło=item -internal 24789c77f108STomasz Warniełło 24799c77f108STomasz WarniełłoOnly output documentation for the symbols that have NOT been exported using 2480632ce137SJason GunthorpeEXPORT_SYMBOL() and related macros in any input FILE or -export-file FILE. 24819c77f108STomasz Warniełło 24829c77f108STomasz Warniełło=item -function NAME 24839c77f108STomasz Warniełło 24849c77f108STomasz WarniełłoOnly output documentation for the given function or DOC: section title. 24859c77f108STomasz WarniełłoAll other functions and DOC: sections are ignored. 24869c77f108STomasz Warniełło 24879c77f108STomasz WarniełłoMay be specified multiple times. 24889c77f108STomasz Warniełło 24899c77f108STomasz Warniełło=item -nosymbol NAME 24909c77f108STomasz Warniełło 24919c77f108STomasz WarniełłoExclude the specified symbol from the output documentation. 24929c77f108STomasz Warniełło 24939c77f108STomasz WarniełłoMay be specified multiple times. 24949c77f108STomasz Warniełło 24959c77f108STomasz Warniełło=back 24969c77f108STomasz Warniełło 2497c15de5a1STomasz Warniełło=head2 Output selection modifiers: 2498c15de5a1STomasz Warniełło 2499c15de5a1STomasz Warniełło=over 8 2500c15de5a1STomasz Warniełło 2501c15de5a1STomasz Warniełło=item -no-doc-sections 2502c15de5a1STomasz Warniełło 2503c15de5a1STomasz WarniełłoDo not output DOC: sections. 2504c15de5a1STomasz Warniełło 2505c15de5a1STomasz Warniełło=item -export-file FILE 2506c15de5a1STomasz Warniełło 2507632ce137SJason GunthorpeSpecify an additional FILE in which to look for EXPORT_SYMBOL information. 2508c15de5a1STomasz Warniełło 2509c15de5a1STomasz WarniełłoTo be used with -export or -internal. 2510c15de5a1STomasz Warniełło 2511c15de5a1STomasz WarniełłoMay be specified multiple times. 2512c15de5a1STomasz Warniełło 2513c15de5a1STomasz Warniełło=back 2514c15de5a1STomasz Warniełło 2515c15de5a1STomasz Warniełło=head3 reStructuredText only 2516c15de5a1STomasz Warniełło 2517c15de5a1STomasz Warniełło=over 8 2518c15de5a1STomasz Warniełło 2519c15de5a1STomasz Warniełło=item -enable-lineno 2520c15de5a1STomasz Warniełło 2521b79dfef0SMauro Carvalho ChehabEnable output of .. LINENO lines. 2522c15de5a1STomasz Warniełło 2523c15de5a1STomasz Warniełło=back 2524c15de5a1STomasz Warniełło 2525834cf6b9STomasz Warniełło=head2 Other parameters: 2526834cf6b9STomasz Warniełło 2527834cf6b9STomasz Warniełło=over 8 2528834cf6b9STomasz Warniełło 2529834cf6b9STomasz Warniełło=item -h, -help 2530834cf6b9STomasz Warniełło 2531834cf6b9STomasz WarniełłoPrint this help. 2532834cf6b9STomasz Warniełło 2533834cf6b9STomasz Warniełło=item -v 2534834cf6b9STomasz Warniełło 2535834cf6b9STomasz WarniełłoVerbose output, more warnings and other information. 2536834cf6b9STomasz Warniełło 2537834cf6b9STomasz Warniełło=item -Werror 2538834cf6b9STomasz Warniełło 2539834cf6b9STomasz WarniełłoTreat warnings as errors. 2540834cf6b9STomasz Warniełło 2541834cf6b9STomasz Warniełło=back 2542834cf6b9STomasz Warniełło 25432875f787STomasz Warniełło=cut 2544