1cb77f0d6SKamil Rytarowski#!/usr/bin/env perl 238476378SJonathan Corbet# SPDX-License-Identifier: GPL-2.0 3a3a23d36SVegard Nossum# vim: softtabstop=4 41da177e4SLinus Torvalds 5cb77f0d6SKamil Rytarowskiuse warnings; 61da177e4SLinus Torvaldsuse strict; 71da177e4SLinus Torvalds 81da177e4SLinus Torvalds## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## 91da177e4SLinus Torvalds## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## 101da177e4SLinus Torvalds## Copyright (C) 2001 Simon Huggins ## 1170c95b00SRandy Dunlap## Copyright (C) 2005-2012 Randy Dunlap ## 121b40c194SDan Luedtke## Copyright (C) 2012 Dan Luedtke ## 131da177e4SLinus Torvalds## ## 141da177e4SLinus Torvalds## #define enhancements by Armin Kuster <akuster@mvista.com> ## 151da177e4SLinus Torvalds## Copyright (c) 2000 MontaVista Software, Inc. ## 162b306ecaSTomasz Warniełło# 172b306ecaSTomasz Warniełło# Copyright (C) 2022 Tomasz Warniełło (POD) 181da177e4SLinus Torvalds 1943caf1a6STomasz Warniełłouse Pod::Usage qw/pod2usage/; 2043caf1a6STomasz Warniełło 21a5cdaea5STomasz Warniełło=head1 NAME 22a5cdaea5STomasz Warniełło 23a5cdaea5STomasz Warniełłokernel-doc - Print formatted kernel documentation to stdout 24a5cdaea5STomasz Warniełło 25a5cdaea5STomasz Warniełło=head1 SYNOPSIS 26a5cdaea5STomasz Warniełło 27dcd39fa2SAndy Shevchenko kernel-doc [-h] [-v] [-Werror] [-Wall] [-Wreturn] [-Wshort-desc[ription]] [-Wcontents-before-sections] 28a5cdaea5STomasz Warniełło [ -man | 29a5cdaea5STomasz Warniełło -rst [-sphinx-version VERSION] [-enable-lineno] | 30a5cdaea5STomasz Warniełło -none 31a5cdaea5STomasz Warniełło ] 32a5cdaea5STomasz Warniełło [ 33a5cdaea5STomasz Warniełło -export | 34a5cdaea5STomasz Warniełło -internal | 35a5cdaea5STomasz Warniełło [-function NAME] ... | 36a5cdaea5STomasz Warniełło [-nosymbol NAME] ... 37a5cdaea5STomasz Warniełło ] 38a5cdaea5STomasz Warniełło [-no-doc-sections] 39a5cdaea5STomasz Warniełło [-export-file FILE] ... 40a5cdaea5STomasz Warniełło FILE ... 41a5cdaea5STomasz Warniełło 42a5cdaea5STomasz WarniełłoRun `kernel-doc -h` for details. 43a5cdaea5STomasz Warniełło 44f1583922STomasz Warniełło=head1 DESCRIPTION 45f1583922STomasz Warniełło 46f1583922STomasz WarniełłoRead C language source or header FILEs, extract embedded documentation comments, 47f1583922STomasz Warniełłoand print formatted documentation to standard output. 48f1583922STomasz Warniełło 49f1583922STomasz WarniełłoThe documentation comments are identified by the "/**" opening comment mark. 50f1583922STomasz Warniełło 51f1583922STomasz WarniełłoSee Documentation/doc-guide/kernel-doc.rst for the documentation comment syntax. 52f1583922STomasz Warniełło 53a5cdaea5STomasz Warniełło=cut 54a5cdaea5STomasz Warniełło 552875f787STomasz Warniełło# more perldoc at the end of the file 562875f787STomasz Warniełło 578484baaaSRandy Dunlap## init lots of data 588484baaaSRandy Dunlap 591da177e4SLinus Torvaldsmy $errors = 0; 601da177e4SLinus Torvaldsmy $warnings = 0; 615f8c7c98SRandy Dunlapmy $anon_struct_union = 0; 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds# match expressions used to find embedded type information 64b97f193aSMauro Carvalho Chehabmy $type_constant = '\b``([^\`]+)``\b'; 65d3dedad4SUtkarsh Tripathimy $type_constant2 = '\%([-_*\w]+)'; 661da177e4SLinus Torvaldsmy $type_func = '(\w+)\(\)'; 67bfd228c7SMike Rapoportmy $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; 6869fc23efSAkira Yokosawamy $type_param_ref = '([\!~\*]?)\@(\w*((\.\w+)|(->\w+))*(\.\.\.)?)'; 695219f18aSJonathan Corbetmy $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params 70346282dbSMauro Carvalho Chehabmy $type_fp_param2 = '\@(\w+->\S+)\(\)'; # Special RST handling for structs with func ptr params 711da177e4SLinus Torvaldsmy $type_env = '(\$\w+)'; 72df31175bSPaolo Bonzinimy $type_enum = '\&(enum\s*([_\w]+))'; 73df31175bSPaolo Bonzinimy $type_struct = '\&(struct\s*([_\w]+))'; 74df31175bSPaolo Bonzinimy $type_typedef = '\&(typedef\s*([_\w]+))'; 75df31175bSPaolo Bonzinimy $type_union = '\&(union\s*([_\w]+))'; 765267dd35SPaolo Bonzinimy $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; 77df31175bSPaolo Bonzinimy $type_fallback = '\&([_\w]+)'; 78f3341dcfSJani Nikulamy $type_member_func = $type_member . '\(\)'; 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds# Output conversion substitutions. 811da177e4SLinus Torvalds# One for each output format 821da177e4SLinus Torvalds 831da177e4SLinus Torvalds# these are pretty rough 844d732701SDanilo Cesar Lemes de Paulamy @highlights_man = ( 854d732701SDanilo Cesar Lemes de Paula [$type_constant, "\$1"], 86b97f193aSMauro Carvalho Chehab [$type_constant2, "\$1"], 874d732701SDanilo Cesar Lemes de Paula [$type_func, "\\\\fB\$1\\\\fP"], 88df31175bSPaolo Bonzini [$type_enum, "\\\\fI\$1\\\\fP"], 894d732701SDanilo Cesar Lemes de Paula [$type_struct, "\\\\fI\$1\\\\fP"], 90df31175bSPaolo Bonzini [$type_typedef, "\\\\fI\$1\\\\fP"], 91df31175bSPaolo Bonzini [$type_union, "\\\\fI\$1\\\\fP"], 925267dd35SPaolo Bonzini [$type_param, "\\\\fI\$1\\\\fP"], 93ee2aa759SMauro Carvalho Chehab [$type_param_ref, "\\\\fI\$1\$2\\\\fP"], 94df31175bSPaolo Bonzini [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], 95df31175bSPaolo Bonzini [$type_fallback, "\\\\fI\$1\\\\fP"] 964d732701SDanilo Cesar Lemes de Paula ); 971da177e4SLinus Torvaldsmy $blankline_man = ""; 981da177e4SLinus Torvalds 99c0d1b6eeSJonathan Corbet# rst-mode 100c0d1b6eeSJonathan Corbetmy @highlights_rst = ( 101c0d1b6eeSJonathan Corbet [$type_constant, "``\$1``"], 102b97f193aSMauro Carvalho Chehab [$type_constant2, "``\$1``"], 103af404fb1SVegard Nossum 104f3341dcfSJani Nikula # Note: need to escape () to avoid func matching later 1055267dd35SPaolo Bonzini [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], 1065267dd35SPaolo Bonzini [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], 1075219f18aSJonathan Corbet [$type_fp_param, "**\$1\\\\(\\\\)**"], 108346282dbSMauro Carvalho Chehab [$type_fp_param2, "**\$1\\\\(\\\\)**"], 109344fdb28SJonathan Corbet [$type_func, "\$1()"], 110df31175bSPaolo Bonzini [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], 111df31175bSPaolo Bonzini [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], 112df31175bSPaolo Bonzini [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], 113df31175bSPaolo Bonzini [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], 114af404fb1SVegard Nossum 115a7291e7eSJani Nikula # in rst this can refer to any type 116df31175bSPaolo Bonzini [$type_fallback, "\\:c\\:type\\:`\$1`"], 117ee2aa759SMauro Carvalho Chehab [$type_param_ref, "**\$1\$2**"] 118c0d1b6eeSJonathan Corbet ); 119c0d1b6eeSJonathan Corbetmy $blankline_rst = "\n"; 120c0d1b6eeSJonathan Corbet 1211da177e4SLinus Torvalds# read arguments 1221da177e4SLinus Torvaldsif ($#ARGV == -1) { 12343caf1a6STomasz Warniełło pod2usage( 12443caf1a6STomasz Warniełło -message => "No arguments!\n", 12543caf1a6STomasz Warniełło -exitval => 1, 12643caf1a6STomasz Warniełło -verbose => 99, 12743caf1a6STomasz Warniełło -sections => 'SYNOPSIS', 12843caf1a6STomasz Warniełło -output => \*STDERR, 12943caf1a6STomasz Warniełło ); 1301da177e4SLinus Torvalds} 1311da177e4SLinus Torvalds 1328484baaaSRandy Dunlapmy $kernelversion; 13393351d41SMauro Carvalho Chehabmy ($sphinx_major, $sphinx_minor, $sphinx_patch); 134efa44475SMauro Carvalho Chehab 1358484baaaSRandy Dunlapmy $dohighlight = ""; 1368484baaaSRandy Dunlap 1371da177e4SLinus Torvaldsmy $verbose = 0; 1382c12c810SPierre-Louis Bossartmy $Werror = 0; 13956b0f453SJohannes Bergmy $Wreturn = 0; 14056b0f453SJohannes Bergmy $Wshort_desc = 0; 14156b0f453SJohannes Bergmy $Wcontents_before_sections = 0; 142bdfe2be3SMauro Carvalho Chehabmy $output_mode = "rst"; 143e314ba31SDaniel Santosmy $output_preformatted = 0; 1444b44595aSJohannes Bergmy $no_doc_sections = 0; 1450b0f5f29SDaniel Vettermy $enable_lineno = 0; 146bdfe2be3SMauro Carvalho Chehabmy @highlights = @highlights_rst; 147bdfe2be3SMauro Carvalho Chehabmy $blankline = $blankline_rst; 1481da177e4SLinus Torvaldsmy $modulename = "Kernel API"; 149b6c3f456SJani Nikula 150b6c3f456SJani Nikulause constant { 151b6c3f456SJani Nikula OUTPUT_ALL => 0, # output all symbols and doc sections 152b6c3f456SJani Nikula OUTPUT_INCLUDE => 1, # output only specified symbols 153eab795ddSMauro Carvalho Chehab OUTPUT_EXPORTED => 2, # output exported symbols 154eab795ddSMauro Carvalho Chehab OUTPUT_INTERNAL => 3, # output non-exported symbols 155b6c3f456SJani Nikula}; 156b6c3f456SJani Nikulamy $output_selection = OUTPUT_ALL; 157b0d60bfbSJonathan Corbetmy $show_not_found = 0; # No longer used 158b2c4105bSBen Hutchings 15988c2b57dSJani Nikulamy @export_file_list; 16088c2b57dSJani Nikula 161b2c4105bSBen Hutchingsmy @build_time; 162b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 163b2c4105bSBen Hutchings (my $seconds = `date -d "${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 164b2c4105bSBen Hutchings @build_time = gmtime($seconds); 165b2c4105bSBen Hutchings} else { 166b2c4105bSBen Hutchings @build_time = localtime; 167b2c4105bSBen Hutchings} 168b2c4105bSBen Hutchings 1691da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 1701da177e4SLinus Torvalds 'July', 'August', 'September', 'October', 171b2c4105bSBen Hutchings 'November', 'December')[$build_time[4]] . 172b2c4105bSBen Hutchings " " . ($build_time[5]+1900); 1731da177e4SLinus Torvalds 1748484baaaSRandy Dunlap# Essentially these are globals. 175b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something. 176b9d97328SRandy Dunlap# CAVEAT EMPTOR! Some of the others I localised may not want to be, which 1771da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs. 1781da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose); 179eab795ddSMauro Carvalho Chehabmy %nosymbol_table = (); 1800b0f5f29SDaniel Vettermy $declaration_start_line; 1811da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type); 1821c32fd0cSIlya Dryomovmy ($newsection, $newcontents, $prototype, $brcount, %source_map); 1831da177e4SLinus Torvalds 184c0d3b831SMasahiro Yamadaif (defined($ENV{'KBUILD_VERBOSE'}) && $ENV{'KBUILD_VERBOSE'} =~ '1') { 185c0d3b831SMasahiro Yamada $verbose = 1; 186bd0e88e5SRandy Dunlap} 187bd0e88e5SRandy Dunlap 1882c12c810SPierre-Louis Bossartif (defined($ENV{'KCFLAGS'})) { 1892c12c810SPierre-Louis Bossart my $kcflags = "$ENV{'KCFLAGS'}"; 1902c12c810SPierre-Louis Bossart 191cf63348bSYujie Liu if ($kcflags =~ /(\s|^)-Werror(\s|$)/) { 1922c12c810SPierre-Louis Bossart $Werror = 1; 1932c12c810SPierre-Louis Bossart } 1942c12c810SPierre-Louis Bossart} 1952c12c810SPierre-Louis Bossart 19656b0f453SJohannes Berg# reading this variable is for backwards compat just in case 19756b0f453SJohannes Berg# someone was calling it with the variable from outside the 19856b0f453SJohannes Berg# kernel's build system 199bed4ed30SLaurent Pinchartif (defined($ENV{'KDOC_WERROR'})) { 200bed4ed30SLaurent Pinchart $Werror = "$ENV{'KDOC_WERROR'}"; 201bed4ed30SLaurent Pinchart} 20256b0f453SJohannes Berg# other environment variables are converted to command-line 20356b0f453SJohannes Berg# arguments in cmd_checkdoc in the build system 204bed4ed30SLaurent Pinchart 2051da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where 2061da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 20793431e06SAlexander A. Klimov# https://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 2081da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy 2091da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed 2101da177e4SLinus Torvalds# into html. 2111da177e4SLinus Torvaldsmy $section_counter = 0; 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvaldsmy $lineprefix=""; 2141da177e4SLinus Torvalds 21548af606aSJani Nikula# Parser states 21648af606aSJani Nikulause constant { 21748af606aSJani Nikula STATE_NORMAL => 0, # normal code 21848af606aSJani Nikula STATE_NAME => 1, # looking for function name 21917b78717SJonathan Corbet STATE_BODY_MAYBE => 2, # body - or maybe more description 22017b78717SJonathan Corbet STATE_BODY => 3, # the body of the comment 2210d55d48bSMauro Carvalho Chehab STATE_BODY_WITH_BLANK_LINE => 4, # the body, which has a blank line 2220d55d48bSMauro Carvalho Chehab STATE_PROTO => 5, # scanning prototype 2230d55d48bSMauro Carvalho Chehab STATE_DOCBLOCK => 6, # documentation block 2240d55d48bSMauro Carvalho Chehab STATE_INLINE => 7, # gathering doc outside main block 22548af606aSJani Nikula}; 2261da177e4SLinus Torvaldsmy $state; 227850622dfSRandy Dunlapmy $in_doc_sect; 228d742f24dSJonathan Corbetmy $leading_space; 2291da177e4SLinus Torvalds 23048af606aSJani Nikula# Inline documentation state 23148af606aSJani Nikulause constant { 23248af606aSJani Nikula STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 23348af606aSJani Nikula STATE_INLINE_NAME => 1, # looking for member name (@foo:) 23448af606aSJani Nikula STATE_INLINE_TEXT => 2, # looking for member documentation 23548af606aSJani Nikula STATE_INLINE_END => 3, # done 23648af606aSJani Nikula STATE_INLINE_ERROR => 4, # error - Comment without header was found. 23748af606aSJani Nikula # Spit a warning as it's not 238a4c6ebedSDanilo Cesar Lemes de Paula # proper kernel-doc and ignore the rest. 23948af606aSJani Nikula}; 24048af606aSJani Nikulamy $inline_doc_state; 241a4c6ebedSDanilo Cesar Lemes de Paula 2421da177e4SLinus Torvalds#declaration types: can be 2431da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef' 2441da177e4SLinus Torvaldsmy $decl_type; 2451da177e4SLinus Torvalds 24652042e2dSMauro Carvalho Chehab# Name of the kernel-doc identifier for non-DOC markups 24752042e2dSMauro Carvalho Chehabmy $identifier; 24852042e2dSMauro Carvalho Chehab 2491da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 2501da177e4SLinus Torvaldsmy $doc_end = '\*/'; 2511da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*'; 25212ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?'; 2531da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)'; 254f624adefSJani Nikula# @params and a strictly limited set of supported section names 255212209cfSJonathan Corbet# Specifically: 256212209cfSJonathan Corbet# Match @word: 257212209cfSJonathan Corbet# @...: 258212209cfSJonathan Corbet# @{section-name}: 259212209cfSJonathan Corbet# while trying to not match literal block starts like "example::" 260212209cfSJonathan Corbet# 2618569de68SJonathan Corbetmy $doc_sect = $doc_com . 262212209cfSJonathan Corbet '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:([^:].*)?$'; 26312ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)'; 2641da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?'; 26548af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$'; 266fe7bc493SMauro Carvalho Chehabmy $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)'; 26748af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$'; 2680c9aa209SJani Nikulamy $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; 26986ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 270*d9339496SAkira Yokosawamy $export_symbol_ns = '^\s*EXPORT_SYMBOL_NS(_GPL)?\s*\(\s*(\w+)\s*,\s*"\S+"\)\s*;'; 271e86bdb24SAditya Srivastavamy $function_pointer = qr{([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)}; 272e86bdb24SAditya Srivastavamy $attribute = qr{__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)}i; 2731da177e4SLinus Torvalds 2741da177e4SLinus Torvaldsmy %parameterdescs; 2750b0f5f29SDaniel Vettermy %parameterdesc_start_lines; 2761da177e4SLinus Torvaldsmy @parameterlist; 2771da177e4SLinus Torvaldsmy %sections; 2781da177e4SLinus Torvaldsmy @sectionlist; 2790b0f5f29SDaniel Vettermy %section_start_lines; 280a1d94aa5SRandy Dunlapmy $sectcheck; 281a1d94aa5SRandy Dunlapmy $struct_actual; 2821da177e4SLinus Torvalds 2831da177e4SLinus Torvaldsmy $contents = ""; 2840b0f5f29SDaniel Vettermy $new_start_line = 0; 285f624adefSJani Nikula 286f624adefSJani Nikula# the canonical section names. see also $doc_sect above. 2871da177e4SLinus Torvaldsmy $section_default = "Description"; # default section 2881da177e4SLinus Torvaldsmy $section_intro = "Introduction"; 2891da177e4SLinus Torvaldsmy $section = $section_default; 2901da177e4SLinus Torvaldsmy $section_context = "Context"; 2914092bac7SYacine Belkadimy $section_return = "Return"; 2921da177e4SLinus Torvalds 2931da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --"; 2941da177e4SLinus Torvalds 2951da177e4SLinus Torvaldsreset_state(); 2961da177e4SLinus Torvalds 297b031ac4eSMauro Carvalho Chehabwhile ($ARGV[0] =~ m/^--?(.*)/) { 298b031ac4eSMauro Carvalho Chehab my $cmd = $1; 299b031ac4eSMauro Carvalho Chehab shift @ARGV; 300b031ac4eSMauro Carvalho Chehab if ($cmd eq "man") { 3011da177e4SLinus Torvalds $output_mode = "man"; 3024d732701SDanilo Cesar Lemes de Paula @highlights = @highlights_man; 3031da177e4SLinus Torvalds $blankline = $blankline_man; 304b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "rst") { 305c0d1b6eeSJonathan Corbet $output_mode = "rst"; 306c0d1b6eeSJonathan Corbet @highlights = @highlights_rst; 307c0d1b6eeSJonathan Corbet $blankline = $blankline_rst; 308b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "none") { 3093a025e1dSMatthew Wilcox $output_mode = "none"; 310b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document 3111da177e4SLinus Torvalds $modulename = shift @ARGV; 312b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "function") { # to only output specific functions 313b6c3f456SJani Nikula $output_selection = OUTPUT_INCLUDE; 3141da177e4SLinus Torvalds $function = shift @ARGV; 3151da177e4SLinus Torvalds $function_table{$function} = 1; 316eab795ddSMauro Carvalho Chehab } elsif ($cmd eq "nosymbol") { # Exclude specific symbols 317eab795ddSMauro Carvalho Chehab my $symbol = shift @ARGV; 318eab795ddSMauro Carvalho Chehab $nosymbol_table{$symbol} = 1; 319b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export") { # only exported symbols 320b6c3f456SJani Nikula $output_selection = OUTPUT_EXPORTED; 321da9726ecSJani Nikula %function_table = (); 322b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "internal") { # only non-exported symbols 323b6c3f456SJani Nikula $output_selection = OUTPUT_INTERNAL; 324da9726ecSJani Nikula %function_table = (); 325b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "export-file") { 32688c2b57dSJani Nikula my $file = shift @ARGV; 32788c2b57dSJani Nikula push(@export_file_list, $file); 328b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq "v") { 3291da177e4SLinus Torvalds $verbose = 1; 3302c12c810SPierre-Louis Bossart } elsif ($cmd eq "Werror") { 3312c12c810SPierre-Louis Bossart $Werror = 1; 33256b0f453SJohannes Berg } elsif ($cmd eq "Wreturn") { 33356b0f453SJohannes Berg $Wreturn = 1; 334dcd39fa2SAndy Shevchenko } elsif ($cmd eq "Wshort-desc" or $cmd eq "Wshort-description") { 33556b0f453SJohannes Berg $Wshort_desc = 1; 33656b0f453SJohannes Berg } elsif ($cmd eq "Wcontents-before-sections") { 33756b0f453SJohannes Berg $Wcontents_before_sections = 1; 33856b0f453SJohannes Berg } elsif ($cmd eq "Wall") { 33956b0f453SJohannes Berg $Wreturn = 1; 34056b0f453SJohannes Berg $Wshort_desc = 1; 34156b0f453SJohannes Berg $Wcontents_before_sections = 1; 342b031ac4eSMauro Carvalho Chehab } elsif (($cmd eq "h") || ($cmd eq "help")) { 343252b47daSTomasz Warniełło pod2usage(-exitval => 0, -verbose => 2); 344b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'no-doc-sections') { 3454b44595aSJohannes Berg $no_doc_sections = 1; 346b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'enable-lineno') { 3470b0f5f29SDaniel Vetter $enable_lineno = 1; 348b031ac4eSMauro Carvalho Chehab } elsif ($cmd eq 'show-not-found') { 349b0d60bfbSJonathan Corbet $show_not_found = 1; # A no-op but don't fail 35093351d41SMauro Carvalho Chehab } elsif ($cmd eq "sphinx-version") { 35193351d41SMauro Carvalho Chehab my $ver_string = shift @ARGV; 35293351d41SMauro Carvalho Chehab if ($ver_string =~ m/^(\d+)(\.\d+)?(\.\d+)?/) { 35393351d41SMauro Carvalho Chehab $sphinx_major = $1; 35493351d41SMauro Carvalho Chehab if (defined($2)) { 35593351d41SMauro Carvalho Chehab $sphinx_minor = substr($2,1); 35693351d41SMauro Carvalho Chehab } else { 35793351d41SMauro Carvalho Chehab $sphinx_minor = 0; 35893351d41SMauro Carvalho Chehab } 35993351d41SMauro Carvalho Chehab if (defined($3)) { 36093351d41SMauro Carvalho Chehab $sphinx_patch = substr($3,1) 36193351d41SMauro Carvalho Chehab } else { 36293351d41SMauro Carvalho Chehab $sphinx_patch = 0; 36393351d41SMauro Carvalho Chehab } 36493351d41SMauro Carvalho Chehab } else { 36593351d41SMauro Carvalho Chehab die "Sphinx version should either major.minor or major.minor.patch format\n"; 36693351d41SMauro Carvalho Chehab } 367b031ac4eSMauro Carvalho Chehab } else { 368b031ac4eSMauro Carvalho Chehab # Unknown argument 36943caf1a6STomasz Warniełło pod2usage( 37043caf1a6STomasz Warniełło -message => "Argument unknown!\n", 37143caf1a6STomasz Warniełło -exitval => 1, 37243caf1a6STomasz Warniełło -verbose => 99, 37343caf1a6STomasz Warniełło -sections => 'SYNOPSIS', 37443caf1a6STomasz Warniełło -output => \*STDERR, 37543caf1a6STomasz Warniełło ); 376e334f873SAkira Yokosawa } 377e334f873SAkira Yokosawa if ($#ARGV < 0){ 378e334f873SAkira Yokosawa pod2usage( 379e334f873SAkira Yokosawa -message => "FILE argument missing\n", 380e334f873SAkira Yokosawa -exitval => 1, 381e334f873SAkira Yokosawa -verbose => 99, 382e334f873SAkira Yokosawa -sections => 'SYNOPSIS', 383e334f873SAkira Yokosawa -output => \*STDERR, 384e334f873SAkira Yokosawa ); 3851da177e4SLinus Torvalds } 3861da177e4SLinus Torvalds} 3871da177e4SLinus Torvalds 3888484baaaSRandy Dunlap# continue execution near EOF; 3898484baaaSRandy Dunlap 390efa44475SMauro Carvalho Chehab# The C domain dialect changed on Sphinx 3. So, we need to check the 391efa44475SMauro Carvalho Chehab# version in order to produce the right tags. 392efa44475SMauro Carvalho Chehabsub findprog($) 393efa44475SMauro Carvalho Chehab{ 394efa44475SMauro Carvalho Chehab foreach(split(/:/, $ENV{PATH})) { 395efa44475SMauro Carvalho Chehab return "$_/$_[0]" if(-x "$_/$_[0]"); 396efa44475SMauro Carvalho Chehab } 397efa44475SMauro Carvalho Chehab} 398efa44475SMauro Carvalho Chehab 399efa44475SMauro Carvalho Chehabsub get_sphinx_version() 400efa44475SMauro Carvalho Chehab{ 401efa44475SMauro Carvalho Chehab my $ver; 402efa44475SMauro Carvalho Chehab 403efa44475SMauro Carvalho Chehab my $cmd = "sphinx-build"; 404efa44475SMauro Carvalho Chehab if (!findprog($cmd)) { 405efa44475SMauro Carvalho Chehab my $cmd = "sphinx-build3"; 40693351d41SMauro Carvalho Chehab if (!findprog($cmd)) { 40793351d41SMauro Carvalho Chehab $sphinx_major = 1; 40893351d41SMauro Carvalho Chehab $sphinx_minor = 2; 40993351d41SMauro Carvalho Chehab $sphinx_patch = 0; 41093351d41SMauro Carvalho Chehab printf STDERR "Warning: Sphinx version not found. Using default (Sphinx version %d.%d.%d)\n", 41193351d41SMauro Carvalho Chehab $sphinx_major, $sphinx_minor, $sphinx_patch; 41293351d41SMauro Carvalho Chehab return; 41393351d41SMauro Carvalho Chehab } 414efa44475SMauro Carvalho Chehab } 415efa44475SMauro Carvalho Chehab 416efa44475SMauro Carvalho Chehab open IN, "$cmd --version 2>&1 |"; 417efa44475SMauro Carvalho Chehab while (<IN>) { 418efa44475SMauro Carvalho Chehab if (m/^\s*sphinx-build\s+([\d]+)\.([\d\.]+)(\+\/[\da-f]+)?$/) { 41993351d41SMauro Carvalho Chehab $sphinx_major = $1; 42093351d41SMauro Carvalho Chehab $sphinx_minor = $2; 42193351d41SMauro Carvalho Chehab $sphinx_patch = $3; 422efa44475SMauro Carvalho Chehab last; 423efa44475SMauro Carvalho Chehab } 424efa44475SMauro Carvalho Chehab # Sphinx 1.2.x uses a different format 425efa44475SMauro Carvalho Chehab if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+)$/) { 42693351d41SMauro Carvalho Chehab $sphinx_major = $1; 42793351d41SMauro Carvalho Chehab $sphinx_minor = $2; 42893351d41SMauro Carvalho Chehab $sphinx_patch = $3; 429efa44475SMauro Carvalho Chehab last; 430efa44475SMauro Carvalho Chehab } 431efa44475SMauro Carvalho Chehab } 432efa44475SMauro Carvalho Chehab close IN; 433efa44475SMauro Carvalho Chehab} 434efa44475SMauro Carvalho Chehab 43553f049faSBorislav Petkov# get kernel version from env 43653f049faSBorislav Petkovsub get_kernel_version() { 4371b9bc22dSJohannes Berg my $version = 'unknown kernel version'; 43853f049faSBorislav Petkov 43953f049faSBorislav Petkov if (defined($ENV{'KERNELVERSION'})) { 44053f049faSBorislav Petkov $version = $ENV{'KERNELVERSION'}; 44153f049faSBorislav Petkov } 44253f049faSBorislav Petkov return $version; 44353f049faSBorislav Petkov} 4441da177e4SLinus Torvalds 4450b0f5f29SDaniel Vetter# 4460b0f5f29SDaniel Vettersub print_lineno { 4470b0f5f29SDaniel Vetter my $lineno = shift; 4480b0f5f29SDaniel Vetter if ($enable_lineno && defined($lineno)) { 449b79dfef0SMauro Carvalho Chehab print ".. LINENO " . $lineno . "\n"; 4500b0f5f29SDaniel Vetter } 4510b0f5f29SDaniel Vetter} 452df4bf98eSNiklas Söderlund 453df4bf98eSNiklas Söderlundsub emit_warning { 454df4bf98eSNiklas Söderlund my $location = shift; 455df4bf98eSNiklas Söderlund my $msg = shift; 456df4bf98eSNiklas Söderlund print STDERR "$location: warning: $msg"; 457df4bf98eSNiklas Söderlund ++$warnings; 458df4bf98eSNiklas Söderlund} 4591da177e4SLinus Torvalds## 4601da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose. 4611da177e4SLinus Torvalds# 4621da177e4SLinus Torvaldssub dump_section { 46394dc7ad5SRandy Dunlap my $file = shift; 4641da177e4SLinus Torvalds my $name = shift; 4651da177e4SLinus Torvalds my $contents = join "\n", @_; 4661da177e4SLinus Torvalds 46713901ef2SJani Nikula if ($name =~ m/$type_param/) { 4681da177e4SLinus Torvalds $name = $1; 4691da177e4SLinus Torvalds $parameterdescs{$name} = $contents; 470a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 4710b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 4720b0f5f29SDaniel Vetter $new_start_line = 0; 473ced69090SRandy Dunlap } elsif ($name eq "@\.\.\.") { 474ced69090SRandy Dunlap $name = "..."; 475ced69090SRandy Dunlap $parameterdescs{$name} = $contents; 476a1d94aa5SRandy Dunlap $sectcheck = $sectcheck . $name . " "; 4770b0f5f29SDaniel Vetter $parameterdesc_start_lines{$name} = $new_start_line; 4780b0f5f29SDaniel Vetter $new_start_line = 0; 4791da177e4SLinus Torvalds } else { 48094dc7ad5SRandy Dunlap if (defined($sections{$name}) && ($sections{$name} ne "")) { 48195b6be9dSJani Nikula # Only warn on user specified duplicate section names. 48295b6be9dSJani Nikula if ($name ne $section_default) { 483df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "duplicate section name '$name'\n"); 48495b6be9dSJani Nikula } 48532217761SJani Nikula $sections{$name} .= $contents; 48632217761SJani Nikula } else { 4871da177e4SLinus Torvalds $sections{$name} = $contents; 4881da177e4SLinus Torvalds push @sectionlist, $name; 4890b0f5f29SDaniel Vetter $section_start_lines{$name} = $new_start_line; 4900b0f5f29SDaniel Vetter $new_start_line = 0; 4911da177e4SLinus Torvalds } 4921da177e4SLinus Torvalds } 49332217761SJani Nikula} 4941da177e4SLinus Torvalds 4951da177e4SLinus Torvalds## 496b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out 497b112e0f7SJohannes Berg# 498b112e0f7SJohannes Bergsub dump_doc_section { 49994dc7ad5SRandy Dunlap my $file = shift; 500b112e0f7SJohannes Berg my $name = shift; 501b112e0f7SJohannes Berg my $contents = join "\n", @_; 502b112e0f7SJohannes Berg 5034b44595aSJohannes Berg if ($no_doc_sections) { 5044b44595aSJohannes Berg return; 5054b44595aSJohannes Berg } 5064b44595aSJohannes Berg 507eab795ddSMauro Carvalho Chehab return if (defined($nosymbol_table{$name})); 508eab795ddSMauro Carvalho Chehab 509b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 510eab795ddSMauro Carvalho Chehab (($output_selection == OUTPUT_INCLUDE) && 511eab795ddSMauro Carvalho Chehab defined($function_table{$name}))) 512b112e0f7SJohannes Berg { 51394dc7ad5SRandy Dunlap dump_section($file, $name, $contents); 514b112e0f7SJohannes Berg output_blockhead({'sectionlist' => \@sectionlist, 515b112e0f7SJohannes Berg 'sections' => \%sections, 516b112e0f7SJohannes Berg 'module' => $modulename, 517b6c3f456SJani Nikula 'content-only' => ($output_selection != OUTPUT_ALL), }); 518b112e0f7SJohannes Berg } 519b112e0f7SJohannes Berg} 520b112e0f7SJohannes Berg 521b112e0f7SJohannes Berg## 5221da177e4SLinus Torvalds# output function 5231da177e4SLinus Torvalds# 5241da177e4SLinus Torvalds# parameterdescs, a hash. 5251da177e4SLinus Torvalds# function => "function name" 5261da177e4SLinus Torvalds# parameterlist => @list of parameters 5271da177e4SLinus Torvalds# parameterdescs => %parameter descriptions 5281da177e4SLinus Torvalds# sectionlist => @list of sections 529a21217daSRandy Dunlap# sections => %section descriptions 5301da177e4SLinus Torvalds# 5311da177e4SLinus Torvalds 5321da177e4SLinus Torvaldssub output_highlight { 5331da177e4SLinus Torvalds my $contents = join "\n",@_; 5341da177e4SLinus Torvalds my $line; 5351da177e4SLinus Torvalds 5361da177e4SLinus Torvalds# DEBUG 5371da177e4SLinus Torvalds# if (!defined $contents) { 5381da177e4SLinus Torvalds# use Carp; 5391da177e4SLinus Torvalds# confess "output_highlight got called with no args?\n"; 5401da177e4SLinus Torvalds# } 5411da177e4SLinus Torvalds 5423eb014a1SRandy Dunlap# print STDERR "contents b4:$contents\n"; 5431da177e4SLinus Torvalds eval $dohighlight; 5441da177e4SLinus Torvalds die $@ if $@; 5453eb014a1SRandy Dunlap# print STDERR "contents af:$contents\n"; 5463eb014a1SRandy Dunlap 5471da177e4SLinus Torvalds foreach $line (split "\n", $contents) { 54812ae6779SDaniel Santos if (! $output_preformatted) { 54912ae6779SDaniel Santos $line =~ s/^\s*//; 55012ae6779SDaniel Santos } 5511da177e4SLinus Torvalds if ($line eq ""){ 552e314ba31SDaniel Santos if (! $output_preformatted) { 5530bba924cSJonathan Corbet print $lineprefix, $blankline; 554e314ba31SDaniel Santos } 5551da177e4SLinus Torvalds } else { 556cdccb316SRandy Dunlap if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 557cdccb316SRandy Dunlap print "\\&$line"; 558cdccb316SRandy Dunlap } else { 5591da177e4SLinus Torvalds print $lineprefix, $line; 5601da177e4SLinus Torvalds } 561cdccb316SRandy Dunlap } 5621da177e4SLinus Torvalds print "\n"; 5631da177e4SLinus Torvalds } 5641da177e4SLinus Torvalds} 5651da177e4SLinus Torvalds 5661da177e4SLinus Torvalds## 5671da177e4SLinus Torvalds# output function in man 5681da177e4SLinus Torvaldssub output_function_man(%) { 5691da177e4SLinus Torvalds my %args = %{$_[0]}; 5701da177e4SLinus Torvalds my ($parameter, $section); 5711da177e4SLinus Torvalds my $count; 572bb8fd09eSRandy Dunlap my $func_macro = $args{'func_macro'}; 573bb8fd09eSRandy Dunlap my $paramcount = $#{$args{'parameterlist'}}; # -1 is empty 5741da177e4SLinus Torvalds 5751da177e4SLinus Torvalds print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 5761da177e4SLinus Torvalds 5771da177e4SLinus Torvalds print ".SH NAME\n"; 5781da177e4SLinus Torvalds print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 5791da177e4SLinus Torvalds 5801da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 581a21217daSRandy Dunlap if ($args{'functiontype'} ne "") { 5821da177e4SLinus Torvalds print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 583a21217daSRandy Dunlap } else { 584a21217daSRandy Dunlap print ".B \"" . $args{'function'} . "\n"; 585a21217daSRandy Dunlap } 5861da177e4SLinus Torvalds $count = 0; 5871da177e4SLinus Torvalds my $parenth = "("; 5881da177e4SLinus Torvalds my $post = ","; 5891da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 5901da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 5911da177e4SLinus Torvalds $post = ");"; 5921da177e4SLinus Torvalds } 5931da177e4SLinus Torvalds $type = $args{'parametertypes'}{$parameter}; 594e86bdb24SAditya Srivastava if ($type =~ m/$function_pointer/) { 5951da177e4SLinus Torvalds # pointer-to-function 596ed8348e2SMauro Carvalho Chehab print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n"; 5971da177e4SLinus Torvalds } else { 5981da177e4SLinus Torvalds $type =~ s/([^\*])$/$1 /; 599ed8348e2SMauro Carvalho Chehab print ".BI \"" . $parenth . $type . "\" " . " \"" . $post . "\"\n"; 6001da177e4SLinus Torvalds } 6011da177e4SLinus Torvalds $count++; 6021da177e4SLinus Torvalds $parenth = ""; 6031da177e4SLinus Torvalds } 6041da177e4SLinus Torvalds 605bb8fd09eSRandy Dunlap $paramcount = $#{$args{'parameterlist'}}; # -1 is empty 606bb8fd09eSRandy Dunlap if ($paramcount >= 0) { 6071da177e4SLinus Torvalds print ".SH ARGUMENTS\n"; 608bb8fd09eSRandy Dunlap } 6091da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6101da177e4SLinus Torvalds my $parameter_name = $parameter; 6111da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6121da177e4SLinus Torvalds 6131da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 6141da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6151da177e4SLinus Torvalds } 6161da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6171da177e4SLinus Torvalds print ".SH \"", uc $section, "\"\n"; 6181da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6191da177e4SLinus Torvalds } 6201da177e4SLinus Torvalds} 6211da177e4SLinus Torvalds 6221da177e4SLinus Torvalds## 6231da177e4SLinus Torvalds# output enum in man 6241da177e4SLinus Torvaldssub output_enum_man(%) { 6251da177e4SLinus Torvalds my %args = %{$_[0]}; 6261da177e4SLinus Torvalds my ($parameter, $section); 6271da177e4SLinus Torvalds my $count; 6281da177e4SLinus Torvalds 6291da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 6301da177e4SLinus Torvalds 6311da177e4SLinus Torvalds print ".SH NAME\n"; 6321da177e4SLinus Torvalds print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 6331da177e4SLinus Torvalds 6341da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 6351da177e4SLinus Torvalds print "enum " . $args{'enum'} . " {\n"; 6361da177e4SLinus Torvalds $count = 0; 6371da177e4SLinus Torvalds foreach my $parameter (@{$args{'parameterlist'}}) { 6381da177e4SLinus Torvalds print ".br\n.BI \" $parameter\"\n"; 6391da177e4SLinus Torvalds if ($count == $#{$args{'parameterlist'}}) { 6401da177e4SLinus Torvalds print "\n};\n"; 6411da177e4SLinus Torvalds last; 642af404fb1SVegard Nossum } else { 6431da177e4SLinus Torvalds print ", \n.br\n"; 6441da177e4SLinus Torvalds } 6451da177e4SLinus Torvalds $count++; 6461da177e4SLinus Torvalds } 6471da177e4SLinus Torvalds 6481da177e4SLinus Torvalds print ".SH Constants\n"; 6491da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6501da177e4SLinus Torvalds my $parameter_name = $parameter; 6511da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6521da177e4SLinus Torvalds 6531da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 6541da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6551da177e4SLinus Torvalds } 6561da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6571da177e4SLinus Torvalds print ".SH \"$section\"\n"; 6581da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6591da177e4SLinus Torvalds } 6601da177e4SLinus Torvalds} 6611da177e4SLinus Torvalds 6621da177e4SLinus Torvalds## 6631da177e4SLinus Torvalds# output struct in man 6641da177e4SLinus Torvaldssub output_struct_man(%) { 6651da177e4SLinus Torvalds my %args = %{$_[0]}; 6661da177e4SLinus Torvalds my ($parameter, $section); 6671da177e4SLinus Torvalds 6681da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 6691da177e4SLinus Torvalds 6701da177e4SLinus Torvalds print ".SH NAME\n"; 6711da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 6721da177e4SLinus Torvalds 6738ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 6748ad72163SMauro Carvalho Chehab $declaration =~ s/\t/ /g; 6758ad72163SMauro Carvalho Chehab $declaration =~ s/\n/"\n.br\n.BI \"/g; 6761da177e4SLinus Torvalds print ".SH SYNOPSIS\n"; 6771da177e4SLinus Torvalds print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 6788ad72163SMauro Carvalho Chehab print ".BI \"$declaration\n};\n.br\n\n"; 6791da177e4SLinus Torvalds 680c51d3dacSRandy Dunlap print ".SH Members\n"; 6811da177e4SLinus Torvalds foreach $parameter (@{$args{'parameterlist'}}) { 6821da177e4SLinus Torvalds ($parameter =~ /^#/) && next; 6831da177e4SLinus Torvalds 6841da177e4SLinus Torvalds my $parameter_name = $parameter; 6851da177e4SLinus Torvalds $parameter_name =~ s/\[.*//; 6861da177e4SLinus Torvalds 6871da177e4SLinus Torvalds ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 6881da177e4SLinus Torvalds print ".IP \"" . $parameter . "\" 12\n"; 6891da177e4SLinus Torvalds output_highlight($args{'parameterdescs'}{$parameter_name}); 6901da177e4SLinus Torvalds } 6911da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 6921da177e4SLinus Torvalds print ".SH \"$section\"\n"; 6931da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 6941da177e4SLinus Torvalds } 6951da177e4SLinus Torvalds} 6961da177e4SLinus Torvalds 6971da177e4SLinus Torvalds## 6981da177e4SLinus Torvalds# output typedef in man 6991da177e4SLinus Torvaldssub output_typedef_man(%) { 7001da177e4SLinus Torvalds my %args = %{$_[0]}; 7011da177e4SLinus Torvalds my ($parameter, $section); 7021da177e4SLinus Torvalds 7031da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 7041da177e4SLinus Torvalds 7051da177e4SLinus Torvalds print ".SH NAME\n"; 7061da177e4SLinus Torvalds print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 7071da177e4SLinus Torvalds 7081da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7091da177e4SLinus Torvalds print ".SH \"$section\"\n"; 7101da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7111da177e4SLinus Torvalds } 7121da177e4SLinus Torvalds} 7131da177e4SLinus Torvalds 714b112e0f7SJohannes Bergsub output_blockhead_man(%) { 7151da177e4SLinus Torvalds my %args = %{$_[0]}; 7161da177e4SLinus Torvalds my ($parameter, $section); 7171da177e4SLinus Torvalds my $count; 7181da177e4SLinus Torvalds 7191da177e4SLinus Torvalds print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 7201da177e4SLinus Torvalds 7211da177e4SLinus Torvalds foreach $section (@{$args{'sectionlist'}}) { 7221da177e4SLinus Torvalds print ".SH \"$section\"\n"; 7231da177e4SLinus Torvalds output_highlight($args{'sections'}{$section}); 7241da177e4SLinus Torvalds } 7251da177e4SLinus Torvalds} 7261da177e4SLinus Torvalds 7271da177e4SLinus Torvalds## 728c0d1b6eeSJonathan Corbet# output in restructured text 729c0d1b6eeSJonathan Corbet# 730c0d1b6eeSJonathan Corbet 731c0d1b6eeSJonathan Corbet# 732c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and 733c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends 734c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file. 735c0d1b6eeSJonathan Corbet# 736c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) { 737c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 738c0d1b6eeSJonathan Corbet my ($parameter, $section); 739c0d1b6eeSJonathan Corbet 740c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 741eab795ddSMauro Carvalho Chehab next if (defined($nosymbol_table{$section})); 742eab795ddSMauro Carvalho Chehab 7439e72184bSJani Nikula if ($output_selection != OUTPUT_INCLUDE) { 74406a755d6SMichal Wajdeczko print ".. _$section:\n\n"; 745c0d1b6eeSJonathan Corbet print "**$section**\n\n"; 7469e72184bSJani Nikula } 7470b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 748c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 749c0d1b6eeSJonathan Corbet print "\n"; 750c0d1b6eeSJonathan Corbet } 751c0d1b6eeSJonathan Corbet} 752c0d1b6eeSJonathan Corbet 753af250290SJonathan Corbet# 754af250290SJonathan Corbet# Apply the RST highlights to a sub-block of text. 755af250290SJonathan Corbet# 756af250290SJonathan Corbetsub highlight_block($) { 757af250290SJonathan Corbet # The dohighlight kludge requires the text be called $contents 758af250290SJonathan Corbet my $contents = shift; 759c0d1b6eeSJonathan Corbet eval $dohighlight; 760c0d1b6eeSJonathan Corbet die $@ if $@; 761af250290SJonathan Corbet return $contents; 762af250290SJonathan Corbet} 763c0d1b6eeSJonathan Corbet 764af250290SJonathan Corbet# 765af250290SJonathan Corbet# Regexes used only here. 766af250290SJonathan Corbet# 767af250290SJonathan Corbetmy $sphinx_literal = '^[^.].*::$'; 768af250290SJonathan Corbetmy $sphinx_cblock = '^\.\.\ +code-block::'; 769af250290SJonathan Corbet 770af250290SJonathan Corbetsub output_highlight_rst { 771af250290SJonathan Corbet my $input = join "\n",@_; 772af250290SJonathan Corbet my $output = ""; 773af250290SJonathan Corbet my $line; 774af250290SJonathan Corbet my $in_literal = 0; 775af250290SJonathan Corbet my $litprefix; 776af250290SJonathan Corbet my $block = ""; 777af250290SJonathan Corbet 778af250290SJonathan Corbet foreach $line (split "\n",$input) { 779af250290SJonathan Corbet # 780af250290SJonathan Corbet # If we're in a literal block, see if we should drop out 781af250290SJonathan Corbet # of it. Otherwise pass the line straight through unmunged. 782af250290SJonathan Corbet # 783af250290SJonathan Corbet if ($in_literal) { 784af250290SJonathan Corbet if (! ($line =~ /^\s*$/)) { 785af250290SJonathan Corbet # 786af250290SJonathan Corbet # If this is the first non-blank line in a literal 787af250290SJonathan Corbet # block we need to figure out what the proper indent is. 788af250290SJonathan Corbet # 789af250290SJonathan Corbet if ($litprefix eq "") { 790af250290SJonathan Corbet $line =~ /^(\s*)/; 791af250290SJonathan Corbet $litprefix = '^' . $1; 792af250290SJonathan Corbet $output .= $line . "\n"; 793af250290SJonathan Corbet } elsif (! ($line =~ /$litprefix/)) { 794af250290SJonathan Corbet $in_literal = 0; 795af250290SJonathan Corbet } else { 796af250290SJonathan Corbet $output .= $line . "\n"; 797af250290SJonathan Corbet } 798af250290SJonathan Corbet } else { 799af250290SJonathan Corbet $output .= $line . "\n"; 800af250290SJonathan Corbet } 801af250290SJonathan Corbet } 802af250290SJonathan Corbet # 803af250290SJonathan Corbet # Not in a literal block (or just dropped out) 804af250290SJonathan Corbet # 805af250290SJonathan Corbet if (! $in_literal) { 806af250290SJonathan Corbet $block .= $line . "\n"; 807af250290SJonathan Corbet if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) { 808af250290SJonathan Corbet $in_literal = 1; 809af250290SJonathan Corbet $litprefix = ""; 810af250290SJonathan Corbet $output .= highlight_block($block); 811af250290SJonathan Corbet $block = "" 812af250290SJonathan Corbet } 813af250290SJonathan Corbet } 814af250290SJonathan Corbet } 815af250290SJonathan Corbet 816af250290SJonathan Corbet if ($block) { 817af250290SJonathan Corbet $output .= highlight_block($block); 818af250290SJonathan Corbet } 819af250290SJonathan Corbet foreach $line (split "\n", $output) { 820830066a7SJani Nikula print $lineprefix . $line . "\n"; 821c0d1b6eeSJonathan Corbet } 822c0d1b6eeSJonathan Corbet} 823c0d1b6eeSJonathan Corbet 824c0d1b6eeSJonathan Corbetsub output_function_rst(%) { 825c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 826c0d1b6eeSJonathan Corbet my ($parameter, $section); 827c099ff69SJani Nikula my $oldprefix = $lineprefix; 828c0d1b6eeSJonathan Corbet 829d3c55a71SVegard Nossum my $signature = ""; 830bb8fd09eSRandy Dunlap my $func_macro = $args{'func_macro'}; 831bb8fd09eSRandy Dunlap my $paramcount = $#{$args{'parameterlist'}}; # -1 is empty 832bb8fd09eSRandy Dunlap 833bb8fd09eSRandy Dunlap if ($func_macro) { 834bb8fd09eSRandy Dunlap $signature = $args{'function'}; 835d3c55a71SVegard Nossum } else { 836bb8fd09eSRandy Dunlap if ($args{'functiontype'}) { 837bb8fd09eSRandy Dunlap $signature = $args{'functiontype'} . " "; 838bb8fd09eSRandy Dunlap } 839bb8fd09eSRandy Dunlap $signature .= $args{'function'} . " ("; 840d3c55a71SVegard Nossum } 841d3c55a71SVegard Nossum 842d3c55a71SVegard Nossum my $count = 0; 843d3c55a71SVegard Nossum foreach my $parameter (@{$args{'parameterlist'}}) { 844d3c55a71SVegard Nossum if ($count ne 0) { 845d3c55a71SVegard Nossum $signature .= ", "; 846d3c55a71SVegard Nossum } 847d3c55a71SVegard Nossum $count++; 848d3c55a71SVegard Nossum $type = $args{'parametertypes'}{$parameter}; 849d3c55a71SVegard Nossum 850d3c55a71SVegard Nossum if ($type =~ m/$function_pointer/) { 851d3c55a71SVegard Nossum # pointer-to-function 852d3c55a71SVegard Nossum $signature .= $1 . $parameter . ") (" . $2 . ")"; 853d3c55a71SVegard Nossum } else { 854d3c55a71SVegard Nossum $signature .= $type; 855d3c55a71SVegard Nossum } 856d3c55a71SVegard Nossum } 857d3c55a71SVegard Nossum 858bb8fd09eSRandy Dunlap if (!$func_macro) { 859d3c55a71SVegard Nossum $signature .= ")"; 860bb8fd09eSRandy Dunlap } 861d3c55a71SVegard Nossum 862efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 863e3ad05feSMauro Carvalho Chehab if ($args{'typedef'}) { 86482801d06SMauro Carvalho Chehab print ".. c:type:: ". $args{'function'} . "\n\n"; 86582801d06SMauro Carvalho Chehab print_lineno($declaration_start_line); 86682801d06SMauro Carvalho Chehab print " **Typedef**: "; 86782801d06SMauro Carvalho Chehab $lineprefix = ""; 86882801d06SMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 8699f6f4c11SVegard Nossum print "\n\n**Syntax**\n\n"; 8709f6f4c11SVegard Nossum print " ``$signature``\n\n"; 871c0d1b6eeSJonathan Corbet } else { 8729f6f4c11SVegard Nossum print ".. c:function:: $signature\n\n"; 87382801d06SMauro Carvalho Chehab } 874e3ad05feSMauro Carvalho Chehab } else { 8756e9e4158SMauro Carvalho Chehab if ($args{'typedef'} || $args{'functiontype'} eq "") { 876e3ad05feSMauro Carvalho Chehab print ".. c:macro:: ". $args{'function'} . "\n\n"; 877e3ad05feSMauro Carvalho Chehab 878e3ad05feSMauro Carvalho Chehab if ($args{'typedef'}) { 879e3ad05feSMauro Carvalho Chehab print_lineno($declaration_start_line); 880e3ad05feSMauro Carvalho Chehab print " **Typedef**: "; 881e3ad05feSMauro Carvalho Chehab $lineprefix = ""; 882e3ad05feSMauro Carvalho Chehab output_highlight_rst($args{'purpose'}); 8839f6f4c11SVegard Nossum print "\n\n**Syntax**\n\n"; 8849f6f4c11SVegard Nossum print " ``$signature``\n\n"; 885e3ad05feSMauro Carvalho Chehab } else { 8869f6f4c11SVegard Nossum print "``$signature``\n\n"; 8879f6f4c11SVegard Nossum } 8889f6f4c11SVegard Nossum } else { 8899f6f4c11SVegard Nossum print ".. c:function:: $signature\n\n"; 890e3ad05feSMauro Carvalho Chehab } 891e3ad05feSMauro Carvalho Chehab } 892c0d1b6eeSJonathan Corbet 8936e9e4158SMauro Carvalho Chehab if (!$args{'typedef'}) { 8940b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 895c099ff69SJani Nikula $lineprefix = " "; 896c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 897c099ff69SJani Nikula print "\n"; 89882801d06SMauro Carvalho Chehab } 899c0d1b6eeSJonathan Corbet 900eaf710ceSJonathan Corbet # 901eaf710ceSJonathan Corbet # Put our descriptive text into a container (thus an HTML <div>) to help 902eaf710ceSJonathan Corbet # set the function prototypes apart. 903eaf710ceSJonathan Corbet # 904c099ff69SJani Nikula $lineprefix = " "; 905bb8fd09eSRandy Dunlap if ($paramcount >= 0) { 906bb8fd09eSRandy Dunlap print ".. container:: kernelindent\n\n"; 907eaf710ceSJonathan Corbet print $lineprefix . "**Parameters**\n\n"; 908bb8fd09eSRandy Dunlap } 909c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 910c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 911ada5f446SGabriel Krisman Bertazi $parameter_name =~ s/\[.*//; 912c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 913c0d1b6eeSJonathan Corbet 914c0d1b6eeSJonathan Corbet if ($type ne "") { 915eaf710ceSJonathan Corbet print $lineprefix . "``$type``\n"; 916c0d1b6eeSJonathan Corbet } else { 917eaf710ceSJonathan Corbet print $lineprefix . "``$parameter``\n"; 918c0d1b6eeSJonathan Corbet } 9190b0f5f29SDaniel Vetter 9200b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 9210b0f5f29SDaniel Vetter 922eaf710ceSJonathan Corbet $lineprefix = " "; 9235e64fa9cSJani Nikula if (defined($args{'parameterdescs'}{$parameter_name}) && 9245e64fa9cSJani Nikula $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 925c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 926c0d1b6eeSJonathan Corbet } else { 927eaf710ceSJonathan Corbet print $lineprefix . "*undescribed*\n"; 928c0d1b6eeSJonathan Corbet } 929eaf710ceSJonathan Corbet $lineprefix = " "; 930c0d1b6eeSJonathan Corbet print "\n"; 931c0d1b6eeSJonathan Corbet } 932c099ff69SJani Nikula 933c0d1b6eeSJonathan Corbet output_section_rst(@_); 934eaf710ceSJonathan Corbet $lineprefix = $oldprefix; 935c0d1b6eeSJonathan Corbet} 936c0d1b6eeSJonathan Corbet 937c0d1b6eeSJonathan Corbetsub output_section_rst(%) { 938c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 939c0d1b6eeSJonathan Corbet my $section; 940c0d1b6eeSJonathan Corbet my $oldprefix = $lineprefix; 941c0d1b6eeSJonathan Corbet 942c0d1b6eeSJonathan Corbet foreach $section (@{$args{'sectionlist'}}) { 943eaf710ceSJonathan Corbet print $lineprefix . "**$section**\n\n"; 9440b0f5f29SDaniel Vetter print_lineno($section_start_lines{$section}); 945c0d1b6eeSJonathan Corbet output_highlight_rst($args{'sections'}{$section}); 946c0d1b6eeSJonathan Corbet print "\n"; 947c0d1b6eeSJonathan Corbet } 948c0d1b6eeSJonathan Corbet print "\n"; 949c0d1b6eeSJonathan Corbet} 950c0d1b6eeSJonathan Corbet 951c0d1b6eeSJonathan Corbetsub output_enum_rst(%) { 952c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 953c0d1b6eeSJonathan Corbet my ($parameter); 954c099ff69SJani Nikula my $oldprefix = $lineprefix; 955c0d1b6eeSJonathan Corbet my $count; 956eaf710ceSJonathan Corbet my $outer; 95762850976SJani Nikula 958efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 959efa44475SMauro Carvalho Chehab my $name = "enum " . $args{'enum'}; 96062850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 961efa44475SMauro Carvalho Chehab } else { 962efa44475SMauro Carvalho Chehab my $name = $args{'enum'}; 963efa44475SMauro Carvalho Chehab print "\n\n.. c:enum:: " . $name . "\n\n"; 964efa44475SMauro Carvalho Chehab } 9650b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 966c099ff69SJani Nikula $lineprefix = " "; 967c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 968c099ff69SJani Nikula print "\n"; 969c0d1b6eeSJonathan Corbet 970eaf710ceSJonathan Corbet print ".. container:: kernelindent\n\n"; 971eaf710ceSJonathan Corbet $outer = $lineprefix . " "; 972eaf710ceSJonathan Corbet $lineprefix = $outer . " "; 973eaf710ceSJonathan Corbet print $outer . "**Constants**\n\n"; 974c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 975eaf710ceSJonathan Corbet print $outer . "``$parameter``\n"; 976eaf710ceSJonathan Corbet 977c0d1b6eeSJonathan Corbet if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 978c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter}); 979c0d1b6eeSJonathan Corbet } else { 980eaf710ceSJonathan Corbet print $lineprefix . "*undescribed*\n"; 981c0d1b6eeSJonathan Corbet } 982c0d1b6eeSJonathan Corbet print "\n"; 983c0d1b6eeSJonathan Corbet } 984eaf710ceSJonathan Corbet print "\n"; 985c0d1b6eeSJonathan Corbet $lineprefix = $oldprefix; 986c0d1b6eeSJonathan Corbet output_section_rst(@_); 987c0d1b6eeSJonathan Corbet} 988c0d1b6eeSJonathan Corbet 989c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) { 990c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 991c0d1b6eeSJonathan Corbet my ($parameter); 992c099ff69SJani Nikula my $oldprefix = $lineprefix; 993efa44475SMauro Carvalho Chehab my $name; 994c0d1b6eeSJonathan Corbet 995efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 996efa44475SMauro Carvalho Chehab $name = "typedef " . $args{'typedef'}; 997efa44475SMauro Carvalho Chehab } else { 998efa44475SMauro Carvalho Chehab $name = $args{'typedef'}; 999efa44475SMauro Carvalho Chehab } 100062850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 10010b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1002c099ff69SJani Nikula $lineprefix = " "; 1003c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1004c099ff69SJani Nikula print "\n"; 1005c0d1b6eeSJonathan Corbet 1006c099ff69SJani Nikula $lineprefix = $oldprefix; 1007c0d1b6eeSJonathan Corbet output_section_rst(@_); 1008c0d1b6eeSJonathan Corbet} 1009c0d1b6eeSJonathan Corbet 1010c0d1b6eeSJonathan Corbetsub output_struct_rst(%) { 1011c0d1b6eeSJonathan Corbet my %args = %{$_[0]}; 1012c0d1b6eeSJonathan Corbet my ($parameter); 1013c099ff69SJani Nikula my $oldprefix = $lineprefix; 1014c0d1b6eeSJonathan Corbet 1015efa44475SMauro Carvalho Chehab if ($sphinx_major < 3) { 1016efa44475SMauro Carvalho Chehab my $name = $args{'type'} . " " . $args{'struct'}; 101762850976SJani Nikula print "\n\n.. c:type:: " . $name . "\n\n"; 1018efa44475SMauro Carvalho Chehab } else { 1019efa44475SMauro Carvalho Chehab my $name = $args{'struct'}; 102072b97d0bSMauro Carvalho Chehab if ($args{'type'} eq 'union') { 102172b97d0bSMauro Carvalho Chehab print "\n\n.. c:union:: " . $name . "\n\n"; 102272b97d0bSMauro Carvalho Chehab } else { 1023efa44475SMauro Carvalho Chehab print "\n\n.. c:struct:: " . $name . "\n\n"; 1024efa44475SMauro Carvalho Chehab } 102572b97d0bSMauro Carvalho Chehab } 10260b0f5f29SDaniel Vetter print_lineno($declaration_start_line); 1027c099ff69SJani Nikula $lineprefix = " "; 1028c099ff69SJani Nikula output_highlight_rst($args{'purpose'}); 1029c099ff69SJani Nikula print "\n"; 1030c0d1b6eeSJonathan Corbet 1031eaf710ceSJonathan Corbet print ".. container:: kernelindent\n\n"; 1032eaf710ceSJonathan Corbet print $lineprefix . "**Definition**::\n\n"; 10338ad72163SMauro Carvalho Chehab my $declaration = $args{'definition'}; 1034eaf710ceSJonathan Corbet $lineprefix = $lineprefix . " "; 1035eaf710ceSJonathan Corbet $declaration =~ s/\t/$lineprefix/g; 1036eaf710ceSJonathan Corbet print $lineprefix . $args{'type'} . " " . $args{'struct'} . " {\n$declaration" . $lineprefix . "};\n\n"; 1037c0d1b6eeSJonathan Corbet 1038c099ff69SJani Nikula $lineprefix = " "; 1039eaf710ceSJonathan Corbet print $lineprefix . "**Members**\n\n"; 1040c0d1b6eeSJonathan Corbet foreach $parameter (@{$args{'parameterlist'}}) { 1041c0d1b6eeSJonathan Corbet ($parameter =~ /^#/) && next; 1042c0d1b6eeSJonathan Corbet 1043c0d1b6eeSJonathan Corbet my $parameter_name = $parameter; 1044c0d1b6eeSJonathan Corbet $parameter_name =~ s/\[.*//; 1045c0d1b6eeSJonathan Corbet 1046c0d1b6eeSJonathan Corbet ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1047c0d1b6eeSJonathan Corbet $type = $args{'parametertypes'}{$parameter}; 10480b0f5f29SDaniel Vetter print_lineno($parameterdesc_start_lines{$parameter_name}); 1049eaf710ceSJonathan Corbet print $lineprefix . "``" . $parameter . "``\n"; 1050eaf710ceSJonathan Corbet $lineprefix = " "; 1051c0d1b6eeSJonathan Corbet output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1052eaf710ceSJonathan Corbet $lineprefix = " "; 1053c0d1b6eeSJonathan Corbet print "\n"; 1054c0d1b6eeSJonathan Corbet } 1055c0d1b6eeSJonathan Corbet print "\n"; 1056c099ff69SJani Nikula 1057c099ff69SJani Nikula $lineprefix = $oldprefix; 1058c0d1b6eeSJonathan Corbet output_section_rst(@_); 1059c0d1b6eeSJonathan Corbet} 1060c0d1b6eeSJonathan Corbet 10613a025e1dSMatthew Wilcox## none mode output functions 10623a025e1dSMatthew Wilcox 10633a025e1dSMatthew Wilcoxsub output_function_none(%) { 10643a025e1dSMatthew Wilcox} 10653a025e1dSMatthew Wilcox 10663a025e1dSMatthew Wilcoxsub output_enum_none(%) { 10673a025e1dSMatthew Wilcox} 10683a025e1dSMatthew Wilcox 10693a025e1dSMatthew Wilcoxsub output_typedef_none(%) { 10703a025e1dSMatthew Wilcox} 10713a025e1dSMatthew Wilcox 10723a025e1dSMatthew Wilcoxsub output_struct_none(%) { 10733a025e1dSMatthew Wilcox} 10743a025e1dSMatthew Wilcox 10753a025e1dSMatthew Wilcoxsub output_blockhead_none(%) { 10763a025e1dSMatthew Wilcox} 10773a025e1dSMatthew Wilcox 10781da177e4SLinus Torvalds## 107927205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum); 108027205744SRandy Dunlap# calls the generated, variable output_ function name based on 108127205744SRandy Dunlap# functype and output_mode 10821da177e4SLinus Torvaldssub output_declaration { 10831da177e4SLinus Torvalds no strict 'refs'; 10841da177e4SLinus Torvalds my $name = shift; 10851da177e4SLinus Torvalds my $functype = shift; 10861da177e4SLinus Torvalds my $func = "output_${functype}_$output_mode"; 1087eab795ddSMauro Carvalho Chehab 1088eab795ddSMauro Carvalho Chehab return if (defined($nosymbol_table{$name})); 1089eab795ddSMauro Carvalho Chehab 1090b6c3f456SJani Nikula if (($output_selection == OUTPUT_ALL) || 1091b6c3f456SJani Nikula (($output_selection == OUTPUT_INCLUDE || 1092b6c3f456SJani Nikula $output_selection == OUTPUT_EXPORTED) && 109386ae2e38SJani Nikula defined($function_table{$name})) || 1094eab795ddSMauro Carvalho Chehab ($output_selection == OUTPUT_INTERNAL && 109586ae2e38SJani Nikula !($functype eq "function" && defined($function_table{$name})))) 10961da177e4SLinus Torvalds { 10971da177e4SLinus Torvalds &$func(@_); 10981da177e4SLinus Torvalds $section_counter++; 10991da177e4SLinus Torvalds } 11001da177e4SLinus Torvalds} 11011da177e4SLinus Torvalds 11021da177e4SLinus Torvalds## 110327205744SRandy Dunlap# generic output function - calls the right one based on current output mode. 1104b112e0f7SJohannes Bergsub output_blockhead { 11051da177e4SLinus Torvalds no strict 'refs'; 1106b112e0f7SJohannes Berg my $func = "output_blockhead_" . $output_mode; 11071da177e4SLinus Torvalds &$func(@_); 11081da177e4SLinus Torvalds $section_counter++; 11091da177e4SLinus Torvalds} 11101da177e4SLinus Torvalds 11111da177e4SLinus Torvalds## 11121da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and 11131da177e4SLinus Torvalds# invokes the right handler. NOT called for functions. 11141da177e4SLinus Torvaldssub dump_declaration($$) { 11151da177e4SLinus Torvalds no strict 'refs'; 11161da177e4SLinus Torvalds my ($prototype, $file) = @_; 11171da177e4SLinus Torvalds my $func = "dump_" . $decl_type; 11181da177e4SLinus Torvalds &$func(@_); 11191da177e4SLinus Torvalds} 11201da177e4SLinus Torvalds 11211da177e4SLinus Torvaldssub dump_union($$) { 11221da177e4SLinus Torvalds dump_struct(@_); 11231da177e4SLinus Torvalds} 11241da177e4SLinus Torvalds 11251da177e4SLinus Torvaldssub dump_struct($$) { 11261da177e4SLinus Torvalds my $x = shift; 11271da177e4SLinus Torvalds my $file = shift; 1128a746fe32SAditya Srivastava my $decl_type; 1129a746fe32SAditya Srivastava my $members; 1130a746fe32SAditya Srivastava my $type = qr{struct|union}; 1131a746fe32SAditya Srivastava # For capturing struct/union definition body, i.e. "{members*}qualifiers*" 1132e86bdb24SAditya Srivastava my $qualifiers = qr{$attribute|__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned}; 1133e86bdb24SAditya Srivastava my $definition_body = qr{\{(.*)\}\s*$qualifiers*}; 1134e86bdb24SAditya Srivastava my $struct_members = qr{($type)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;}; 11351da177e4SLinus Torvalds 1136a746fe32SAditya Srivastava if ($x =~ /($type)\s+(\w+)\s*$definition_body/) { 1137a746fe32SAditya Srivastava $decl_type = $1; 11381da177e4SLinus Torvalds $declaration_name = $2; 1139a746fe32SAditya Srivastava $members = $3; 1140a746fe32SAditya Srivastava } elsif ($x =~ /typedef\s+($type)\s*$definition_body\s*(\w+)\s*;/) { 1141a746fe32SAditya Srivastava $decl_type = $1; 1142a746fe32SAditya Srivastava $declaration_name = $3; 1143a746fe32SAditya Srivastava $members = $2; 1144a746fe32SAditya Srivastava } 11451da177e4SLinus Torvalds 1146a746fe32SAditya Srivastava if ($members) { 114752042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 1148df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "expecting prototype for $decl_type $identifier. Prototype was for $decl_type $declaration_name instead\n"); 114952042e2dSMauro Carvalho Chehab return; 115052042e2dSMauro Carvalho Chehab } 115152042e2dSMauro Carvalho Chehab 1152aeec46b9SMartin Waitz # ignore members marked private: 11530d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 11540d8c39e6SMauro Carvalho Chehab $members =~ s/\/\*\s*private:.*//gosi; 1155aeec46b9SMartin Waitz # strip comments: 1156aeec46b9SMartin Waitz $members =~ s/\/\*.*?\*\///gos; 1157ef5da59fSRandy Dunlap # strip attributes 1158e86bdb24SAditya Srivastava $members =~ s/\s*$attribute/ /gi; 11593d9bfb19SSakari Ailus $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos; 1160f600c77aSJonathan Corbet $members =~ s/\s*__counted_by\s*\([^;]*\)/ /gos; 1161ca7e324eSAlexander Lobakin $members =~ s/\s*__counted_by_(le|be)\s*\([^;]*\)/ /gos; 11623d9bfb19SSakari Ailus $members =~ s/\s*__packed\s*/ /gos; 1163f0074929SJonathan Corbet $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos; 1164f861537dSAndré Almeida $members =~ s/\s*____cacheline_aligned_in_smp/ /gos; 1165a070991fSJonathan Cameron $members =~ s/\s*____cacheline_aligned/ /gos; 116650d7bd38SKees Cook # unwrap struct_group(): 116750d7bd38SKees Cook # - first eat non-declaration parameters and rewrite for final match 116850d7bd38SKees Cook # - then remove macro, outer parens, and trailing semicolon 116950d7bd38SKees Cook $members =~ s/\bstruct_group\s*\(([^,]*,)/STRUCT_GROUP(/gos; 11705f8e4007SKees Cook $members =~ s/\bstruct_group_attr\s*\(([^,]*,){2}/STRUCT_GROUP(/gos; 11715f8e4007SKees Cook $members =~ s/\bstruct_group_tagged\s*\(([^,]*),([^,]*),/struct $1 $2; STRUCT_GROUP(/gos; 117250d7bd38SKees Cook $members =~ s/\b__struct_group\s*\(([^,]*,){3}/STRUCT_GROUP(/gos; 117350d7bd38SKees Cook $members =~ s/\bSTRUCT_GROUP(\(((?:(?>[^)(]+)|(?1))*)\))[^;]*;/$2/gos; 11743556108eSMauro Carvalho Chehab 1175e86bdb24SAditya Srivastava my $args = qr{([^,)]+)}; 1176b22b5a9eSConchúr Navid # replace DECLARE_BITMAP 11773556108eSMauro Carvalho Chehab $members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos; 1178603bdf5dSRandy Dunlap $members =~ s/DECLARE_PHY_INTERFACE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, PHY_INTERFACE_MODE_MAX)/gos; 1179e86bdb24SAditya Srivastava $members =~ s/DECLARE_BITMAP\s*\($args,\s*$args\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 11801cb566baSJakub Kicinski # replace DECLARE_HASHTABLE 1181e86bdb24SAditya Srivastava $members =~ s/DECLARE_HASHTABLE\s*\($args,\s*$args\)/unsigned long $1\[1 << (($2) - 1)\]/gos; 118245005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO 1183e86bdb24SAditya Srivastava $members =~ s/DECLARE_KFIFO\s*\($args,\s*$args,\s*$args\)/$2 \*$1/gos; 118445005b27SMauro Carvalho Chehab # replace DECLARE_KFIFO_PTR 1185e86bdb24SAditya Srivastava $members =~ s/DECLARE_KFIFO_PTR\s*\($args,\s*$args\)/$2 \*$1/gos; 11863080ea55SKees Cook # replace DECLARE_FLEX_ARRAY 11873080ea55SKees Cook $members =~ s/(?:__)?DECLARE_FLEX_ARRAY\s*\($args,\s*$args\)/$1 $2\[\]/gos; 1188be98edcbSPavan Kumar Linga #replace DEFINE_DMA_UNMAP_ADDR 1189be98edcbSPavan Kumar Linga $members =~ s/DEFINE_DMA_UNMAP_ADDR\s*\($args\)/dma_addr_t $1/gos; 1190be98edcbSPavan Kumar Linga #replace DEFINE_DMA_UNMAP_LEN 1191be98edcbSPavan Kumar Linga $members =~ s/DEFINE_DMA_UNMAP_LEN\s*\($args\)/__u32 $1/gos; 11928ad72163SMauro Carvalho Chehab my $declaration = $members; 11938ad72163SMauro Carvalho Chehab 11948ad72163SMauro Carvalho Chehab # Split nested struct/union elements as newer ones 1195e86bdb24SAditya Srivastava while ($members =~ m/$struct_members/) { 119684ce5b98SMauro Carvalho Chehab my $newmember; 119784ce5b98SMauro Carvalho Chehab my $maintype = $1; 119884ce5b98SMauro Carvalho Chehab my $ids = $4; 11998ad72163SMauro Carvalho Chehab my $content = $3; 120084ce5b98SMauro Carvalho Chehab foreach my $id(split /,/, $ids) { 120184ce5b98SMauro Carvalho Chehab $newmember .= "$maintype $id; "; 120284ce5b98SMauro Carvalho Chehab 12038ad72163SMauro Carvalho Chehab $id =~ s/[:\[].*//; 120484ce5b98SMauro Carvalho Chehab $id =~ s/^\s*\**(\S+)\s*/$1/; 12058ad72163SMauro Carvalho Chehab foreach my $arg (split /;/, $content) { 12068ad72163SMauro Carvalho Chehab next if ($arg =~ m/^\s*$/); 12077c0d7e87SMauro Carvalho Chehab if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) { 12087c0d7e87SMauro Carvalho Chehab # pointer-to-function 12097c0d7e87SMauro Carvalho Chehab my $type = $1; 12107c0d7e87SMauro Carvalho Chehab my $name = $2; 12117c0d7e87SMauro Carvalho Chehab my $extra = $3; 12127c0d7e87SMauro Carvalho Chehab next if (!$name); 12137c0d7e87SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 12147c0d7e87SMauro Carvalho Chehab # anonymous struct/union 12157c0d7e87SMauro Carvalho Chehab $newmember .= "$type$name$extra; "; 12167c0d7e87SMauro Carvalho Chehab } else { 12177c0d7e87SMauro Carvalho Chehab $newmember .= "$type$id.$name$extra; "; 12187c0d7e87SMauro Carvalho Chehab } 12197c0d7e87SMauro Carvalho Chehab } else { 122084ce5b98SMauro Carvalho Chehab my $type; 122184ce5b98SMauro Carvalho Chehab my $names; 122284ce5b98SMauro Carvalho Chehab $arg =~ s/^\s+//; 122384ce5b98SMauro Carvalho Chehab $arg =~ s/\s+$//; 122484ce5b98SMauro Carvalho Chehab # Handle bitmaps 122584ce5b98SMauro Carvalho Chehab $arg =~ s/:\s*\d+\s*//g; 122684ce5b98SMauro Carvalho Chehab # Handle arrays 1227d404d579SMauro Carvalho Chehab $arg =~ s/\[.*\]//g; 122884ce5b98SMauro Carvalho Chehab # The type may have multiple words, 122984ce5b98SMauro Carvalho Chehab # and multiple IDs can be defined, like: 123084ce5b98SMauro Carvalho Chehab # const struct foo, *bar, foobar 123184ce5b98SMauro Carvalho Chehab # So, we remove spaces when parsing the 123284ce5b98SMauro Carvalho Chehab # names, in order to match just names 123384ce5b98SMauro Carvalho Chehab # and commas for the names 123484ce5b98SMauro Carvalho Chehab $arg =~ s/\s*,\s*/,/g; 123584ce5b98SMauro Carvalho Chehab if ($arg =~ m/(.*)\s+([\S+,]+)/) { 123684ce5b98SMauro Carvalho Chehab $type = $1; 123784ce5b98SMauro Carvalho Chehab $names = $2; 123884ce5b98SMauro Carvalho Chehab } else { 123984ce5b98SMauro Carvalho Chehab $newmember .= "$arg; "; 124084ce5b98SMauro Carvalho Chehab next; 124184ce5b98SMauro Carvalho Chehab } 124284ce5b98SMauro Carvalho Chehab foreach my $name (split /,/, $names) { 124384ce5b98SMauro Carvalho Chehab $name =~ s/^\s*\**(\S+)\s*/$1/; 12448ad72163SMauro Carvalho Chehab next if (($name =~ m/^\s*$/)); 12458ad72163SMauro Carvalho Chehab if ($id =~ m/^\s*$/) { 12468ad72163SMauro Carvalho Chehab # anonymous struct/union 12478ad72163SMauro Carvalho Chehab $newmember .= "$type $name; "; 12488ad72163SMauro Carvalho Chehab } else { 12498ad72163SMauro Carvalho Chehab $newmember .= "$type $id.$name; "; 12508ad72163SMauro Carvalho Chehab } 12518ad72163SMauro Carvalho Chehab } 12527c0d7e87SMauro Carvalho Chehab } 125384ce5b98SMauro Carvalho Chehab } 125484ce5b98SMauro Carvalho Chehab } 1255e86bdb24SAditya Srivastava $members =~ s/$struct_members/$newmember/; 125684ce5b98SMauro Carvalho Chehab } 12578ad72163SMauro Carvalho Chehab 12588ad72163SMauro Carvalho Chehab # Ignore other nested elements, like enums 1259673bb2dfSBen Hutchings $members =~ s/(\{[^\{\}]*\})//g; 12608ad72163SMauro Carvalho Chehab 1261151c468bSMauro Carvalho Chehab create_parameterlist($members, ';', $file, $declaration_name); 12621081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual); 12631da177e4SLinus Torvalds 12648ad72163SMauro Carvalho Chehab # Adjust declaration for better display 1265673bb2dfSBen Hutchings $declaration =~ s/([\{;])/$1\n/g; 1266673bb2dfSBen Hutchings $declaration =~ s/\}\s+;/};/g; 12678ad72163SMauro Carvalho Chehab # Better handle inlined enums 1268673bb2dfSBen Hutchings do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/); 12698ad72163SMauro Carvalho Chehab 12708ad72163SMauro Carvalho Chehab my @def_args = split /\n/, $declaration; 12718ad72163SMauro Carvalho Chehab my $level = 1; 12728ad72163SMauro Carvalho Chehab $declaration = ""; 12738ad72163SMauro Carvalho Chehab foreach my $clause (@def_args) { 12748ad72163SMauro Carvalho Chehab $clause =~ s/^\s+//; 12758ad72163SMauro Carvalho Chehab $clause =~ s/\s+$//; 12768ad72163SMauro Carvalho Chehab $clause =~ s/\s+/ /; 12778ad72163SMauro Carvalho Chehab next if (!$clause); 1278673bb2dfSBen Hutchings $level-- if ($clause =~ m/(\})/ && $level > 1); 12798ad72163SMauro Carvalho Chehab if (!($clause =~ m/^\s*#/)) { 12808ad72163SMauro Carvalho Chehab $declaration .= "\t" x $level; 12818ad72163SMauro Carvalho Chehab } 12828ad72163SMauro Carvalho Chehab $declaration .= "\t" . $clause . "\n"; 1283673bb2dfSBen Hutchings $level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/)); 12848ad72163SMauro Carvalho Chehab } 12851da177e4SLinus Torvalds output_declaration($declaration_name, 12861da177e4SLinus Torvalds 'struct', 12871da177e4SLinus Torvalds {'struct' => $declaration_name, 12881da177e4SLinus Torvalds 'module' => $modulename, 12898ad72163SMauro Carvalho Chehab 'definition' => $declaration, 12901da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 12911da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 12921da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 12931da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 12941da177e4SLinus Torvalds 'sections' => \%sections, 12951da177e4SLinus Torvalds 'purpose' => $declaration_purpose, 12961da177e4SLinus Torvalds 'type' => $decl_type 12971da177e4SLinus Torvalds }); 1298af404fb1SVegard Nossum } else { 1299d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 13001da177e4SLinus Torvalds ++$errors; 13011da177e4SLinus Torvalds } 13021da177e4SLinus Torvalds} 13031da177e4SLinus Torvalds 130485afe608SMauro Carvalho Chehab 130585afe608SMauro Carvalho Chehabsub show_warnings($$) { 130685afe608SMauro Carvalho Chehab my $functype = shift; 130785afe608SMauro Carvalho Chehab my $name = shift; 130885afe608SMauro Carvalho Chehab 1309eab795ddSMauro Carvalho Chehab return 0 if (defined($nosymbol_table{$name})); 1310eab795ddSMauro Carvalho Chehab 131185afe608SMauro Carvalho Chehab return 1 if ($output_selection == OUTPUT_ALL); 131285afe608SMauro Carvalho Chehab 131385afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_EXPORTED) { 131485afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 131585afe608SMauro Carvalho Chehab return 1; 131685afe608SMauro Carvalho Chehab } else { 131785afe608SMauro Carvalho Chehab return 0; 131885afe608SMauro Carvalho Chehab } 131985afe608SMauro Carvalho Chehab } 132085afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_INTERNAL) { 132185afe608SMauro Carvalho Chehab if (!($functype eq "function" && defined($function_table{$name}))) { 132285afe608SMauro Carvalho Chehab return 1; 132385afe608SMauro Carvalho Chehab } else { 132485afe608SMauro Carvalho Chehab return 0; 132585afe608SMauro Carvalho Chehab } 132685afe608SMauro Carvalho Chehab } 132785afe608SMauro Carvalho Chehab if ($output_selection == OUTPUT_INCLUDE) { 132885afe608SMauro Carvalho Chehab if (defined($function_table{$name})) { 132985afe608SMauro Carvalho Chehab return 1; 133085afe608SMauro Carvalho Chehab } else { 133185afe608SMauro Carvalho Chehab return 0; 133285afe608SMauro Carvalho Chehab } 133385afe608SMauro Carvalho Chehab } 133485afe608SMauro Carvalho Chehab die("Please add the new output type at show_warnings()"); 133585afe608SMauro Carvalho Chehab} 133685afe608SMauro Carvalho Chehab 13371da177e4SLinus Torvaldssub dump_enum($$) { 13381da177e4SLinus Torvalds my $x = shift; 13391da177e4SLinus Torvalds my $file = shift; 1340d38c8cfbSMauro Carvalho Chehab my $members; 1341d38c8cfbSMauro Carvalho Chehab 1342e27cb89aSJakub Kicinski # ignore members marked private: 1343e27cb89aSJakub Kicinski $x =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 1344e27cb89aSJakub Kicinski $x =~ s/\/\*\s*private:.*}/}/gosi; 13451da177e4SLinus Torvalds 1346aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 13474468e21eSConchúr Navid # strip #define macros inside enums 13488e93cb78SJohannes Berg $x =~ s@#\s*((define|ifdef|if)\s+|endif)[^;]*;@@gos; 1349b6d676dbSRandy Dunlap 1350d38c8cfbSMauro Carvalho Chehab if ($x =~ /typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;/) { 1351d38c8cfbSMauro Carvalho Chehab $declaration_name = $2; 1352d38c8cfbSMauro Carvalho Chehab $members = $1; 1353d38c8cfbSMauro Carvalho Chehab } elsif ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) { 13541da177e4SLinus Torvalds $declaration_name = $1; 1355d38c8cfbSMauro Carvalho Chehab $members = $2; 1356d38c8cfbSMauro Carvalho Chehab } 1357d38c8cfbSMauro Carvalho Chehab 1358ae5b17e4SAndy Shevchenko if ($members) { 135952042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 13600b54c2e3SMauro Carvalho Chehab if ($identifier eq "") { 1361df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "wrong kernel-doc identifier on line:\n"); 13620b54c2e3SMauro Carvalho Chehab } else { 1363df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "expecting prototype for enum $identifier. Prototype was for enum $declaration_name instead\n"); 13640b54c2e3SMauro Carvalho Chehab } 136552042e2dSMauro Carvalho Chehab return; 136652042e2dSMauro Carvalho Chehab } 13670b54c2e3SMauro Carvalho Chehab $declaration_name = "(anonymous)" if ($declaration_name eq ""); 136852042e2dSMauro Carvalho Chehab 13695cb5c31cSJohannes Berg my %_members; 13705cb5c31cSJohannes Berg 1371463a0fdcSMarkus Heiser $members =~ s/\s+$//; 13720ef5de7bSPavan Kumar Linga $members =~ s/\([^;]*?[\)]//g; 13731da177e4SLinus Torvalds 13741da177e4SLinus Torvalds foreach my $arg (split ',', $members) { 13751da177e4SLinus Torvalds $arg =~ s/^\s*(\w+).*/$1/; 13761da177e4SLinus Torvalds push @parameterlist, $arg; 13771da177e4SLinus Torvalds if (!$parameterdescs{$arg}) { 13781da177e4SLinus Torvalds $parameterdescs{$arg} = $undescribed; 137985afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 1380df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Enum value '$arg' not described in enum '$declaration_name'\n"); 13812defb272SMauro Carvalho Chehab } 13821da177e4SLinus Torvalds } 13835cb5c31cSJohannes Berg $_members{$arg} = 1; 13845cb5c31cSJohannes Berg } 13851da177e4SLinus Torvalds 13865cb5c31cSJohannes Berg while (my ($k, $v) = each %parameterdescs) { 13875cb5c31cSJohannes Berg if (!exists($_members{$k})) { 138885afe608SMauro Carvalho Chehab if (show_warnings("enum", $declaration_name)) { 1389df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Excess enum value '$k' description in '$declaration_name'\n"); 13902defb272SMauro Carvalho Chehab } 13915cb5c31cSJohannes Berg } 13921da177e4SLinus Torvalds } 13931da177e4SLinus Torvalds 13941da177e4SLinus Torvalds output_declaration($declaration_name, 13951da177e4SLinus Torvalds 'enum', 13961da177e4SLinus Torvalds {'enum' => $declaration_name, 13971da177e4SLinus Torvalds 'module' => $modulename, 13981da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 13991da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 14001da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 14011da177e4SLinus Torvalds 'sections' => \%sections, 14021da177e4SLinus Torvalds 'purpose' => $declaration_purpose 14031da177e4SLinus Torvalds }); 1404d38c8cfbSMauro Carvalho Chehab } else { 1405d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse enum!\n"; 14061da177e4SLinus Torvalds ++$errors; 14071da177e4SLinus Torvalds } 14081da177e4SLinus Torvalds} 14091da177e4SLinus Torvalds 14107d2c6b1eSMauro Carvalho Chehabmy $typedef_type = qr { ((?:\s+[\w\*]+\b){1,8})\s* }x; 14117efc6c42SMauro Carvalho Chehabmy $typedef_ident = qr { \*?\s*(\w\S+)\s* }x; 14127efc6c42SMauro Carvalho Chehabmy $typedef_args = qr { \s*\((.*)\); }x; 14137efc6c42SMauro Carvalho Chehab 14147efc6c42SMauro Carvalho Chehabmy $typedef1 = qr { typedef$typedef_type\($typedef_ident\)$typedef_args }x; 14157efc6c42SMauro Carvalho Chehabmy $typedef2 = qr { typedef$typedef_type$typedef_ident$typedef_args }x; 14167efc6c42SMauro Carvalho Chehab 14171da177e4SLinus Torvaldssub dump_typedef($$) { 14181da177e4SLinus Torvalds my $x = shift; 14191da177e4SLinus Torvalds my $file = shift; 14201da177e4SLinus Torvalds 1421aeec46b9SMartin Waitz $x =~ s@/\*.*?\*/@@gos; # strip comments. 142283766452SMauro Carvalho Chehab 14237efc6c42SMauro Carvalho Chehab # Parse function typedef prototypes 14247efc6c42SMauro Carvalho Chehab if ($x =~ $typedef1 || $x =~ $typedef2) { 142583766452SMauro Carvalho Chehab $return_type = $1; 142683766452SMauro Carvalho Chehab $declaration_name = $2; 142783766452SMauro Carvalho Chehab my $args = $3; 14286b80975cSMauro Carvalho Chehab $return_type =~ s/^\s+//; 142983766452SMauro Carvalho Chehab 143052042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 1431df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n"); 143252042e2dSMauro Carvalho Chehab return; 143352042e2dSMauro Carvalho Chehab } 143452042e2dSMauro Carvalho Chehab 1435151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 143683766452SMauro Carvalho Chehab 143783766452SMauro Carvalho Chehab output_declaration($declaration_name, 143883766452SMauro Carvalho Chehab 'function', 143983766452SMauro Carvalho Chehab {'function' => $declaration_name, 144082801d06SMauro Carvalho Chehab 'typedef' => 1, 144183766452SMauro Carvalho Chehab 'module' => $modulename, 144283766452SMauro Carvalho Chehab 'functiontype' => $return_type, 144383766452SMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 144483766452SMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 144583766452SMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 144683766452SMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 144783766452SMauro Carvalho Chehab 'sections' => \%sections, 144883766452SMauro Carvalho Chehab 'purpose' => $declaration_purpose 144983766452SMauro Carvalho Chehab }); 145083766452SMauro Carvalho Chehab return; 145183766452SMauro Carvalho Chehab } 145283766452SMauro Carvalho Chehab 14531da177e4SLinus Torvalds while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 14541da177e4SLinus Torvalds $x =~ s/\(*.\)\s*;$/;/; 14551da177e4SLinus Torvalds $x =~ s/\[*.\]\s*;$/;/; 14561da177e4SLinus Torvalds } 14571da177e4SLinus Torvalds 14581da177e4SLinus Torvalds if ($x =~ /typedef.*\s+(\w+)\s*;/) { 14591da177e4SLinus Torvalds $declaration_name = $1; 14601da177e4SLinus Torvalds 146152042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 1462df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n"); 146352042e2dSMauro Carvalho Chehab return; 146452042e2dSMauro Carvalho Chehab } 146552042e2dSMauro Carvalho Chehab 14661da177e4SLinus Torvalds output_declaration($declaration_name, 14671da177e4SLinus Torvalds 'typedef', 14681da177e4SLinus Torvalds {'typedef' => $declaration_name, 14691da177e4SLinus Torvalds 'module' => $modulename, 14701da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 14711da177e4SLinus Torvalds 'sections' => \%sections, 14721da177e4SLinus Torvalds 'purpose' => $declaration_purpose 14731da177e4SLinus Torvalds }); 1474af404fb1SVegard Nossum } else { 1475d40e1e65SBart Van Assche print STDERR "${file}:$.: error: Cannot parse typedef!\n"; 14761da177e4SLinus Torvalds ++$errors; 14771da177e4SLinus Torvalds } 14781da177e4SLinus Torvalds} 14791da177e4SLinus Torvalds 1480a1d94aa5SRandy Dunlapsub save_struct_actual($) { 1481a1d94aa5SRandy Dunlap my $actual = shift; 1482a1d94aa5SRandy Dunlap 1483a1d94aa5SRandy Dunlap # strip all spaces from the actual param so that it looks like one string item 1484a1d94aa5SRandy Dunlap $actual =~ s/\s*//g; 1485a1d94aa5SRandy Dunlap $struct_actual = $struct_actual . $actual . " "; 1486a1d94aa5SRandy Dunlap} 1487a1d94aa5SRandy Dunlap 1488151c468bSMauro Carvalho Chehabsub create_parameterlist($$$$) { 14891da177e4SLinus Torvalds my $args = shift; 14901da177e4SLinus Torvalds my $splitter = shift; 14911da177e4SLinus Torvalds my $file = shift; 1492151c468bSMauro Carvalho Chehab my $declaration_name = shift; 14931da177e4SLinus Torvalds my $type; 14941da177e4SLinus Torvalds my $param; 14951da177e4SLinus Torvalds 1496a6d3fe77SMartin Waitz # temporarily replace commas inside function pointer definition 1497e86bdb24SAditya Srivastava my $arg_expr = qr{\([^\),]+}; 1498e86bdb24SAditya Srivastava while ($args =~ /$arg_expr,/) { 1499e86bdb24SAditya Srivastava $args =~ s/($arg_expr),/$1#/g; 15001da177e4SLinus Torvalds } 15011da177e4SLinus Torvalds 15021da177e4SLinus Torvalds foreach my $arg (split($splitter, $args)) { 15031da177e4SLinus Torvalds # strip comments 15041da177e4SLinus Torvalds $arg =~ s/\/\*.*\*\///; 150503699f27SKees Cook # ignore argument attributes 150603699f27SKees Cook $arg =~ s/\sPOS0?\s/ /; 15071da177e4SLinus Torvalds # strip leading/trailing spaces 15081da177e4SLinus Torvalds $arg =~ s/^\s*//; 15091da177e4SLinus Torvalds $arg =~ s/\s*$//; 15101da177e4SLinus Torvalds $arg =~ s/\s+/ /; 15111da177e4SLinus Torvalds 15121da177e4SLinus Torvalds if ($arg =~ /^#/) { 15131da177e4SLinus Torvalds # Treat preprocessor directive as a typeless variable just to fill 15141da177e4SLinus Torvalds # corresponding data structures "correctly". Catch it later in 15151da177e4SLinus Torvalds # output_* subs. 1516ed8348e2SMauro Carvalho Chehab push_parameter($arg, "", "", $file); 151700d62961SRichard Kennedy } elsif ($arg =~ m/\(.+\)\s*\(/) { 15181da177e4SLinus Torvalds # pointer-to-function 15191da177e4SLinus Torvalds $arg =~ tr/#/,/; 1520336ced2dSAditya Srivastava $arg =~ m/[^\(]+\(\*?\s*([\w\[\]\.]*)\s*\)/; 15211da177e4SLinus Torvalds $param = $1; 15221da177e4SLinus Torvalds $type = $arg; 152300d62961SRichard Kennedy $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1524a1d94aa5SRandy Dunlap save_struct_actual($param); 1525ed8348e2SMauro Carvalho Chehab push_parameter($param, $type, $arg, $file, $declaration_name); 1526bbf00be9SSakari Ailus } elsif ($arg =~ m/\(.+\)\s*\[/) { 1527bbf00be9SSakari Ailus # array-of-pointers 1528bbf00be9SSakari Ailus $arg =~ tr/#/,/; 1529bbf00be9SSakari Ailus $arg =~ m/[^\(]+\(\s*\*\s*([\w\[\]\.]*?)\s*(\s*\[\s*[\w]+\s*\]\s*)*\)/; 1530bbf00be9SSakari Ailus $param = $1; 1531bbf00be9SSakari Ailus $type = $arg; 1532bbf00be9SSakari Ailus $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1533bbf00be9SSakari Ailus save_struct_actual($param); 1534bbf00be9SSakari Ailus push_parameter($param, $type, $arg, $file, $declaration_name); 1535aeec46b9SMartin Waitz } elsif ($arg) { 15361da177e4SLinus Torvalds $arg =~ s/\s*:\s*/:/g; 15371da177e4SLinus Torvalds $arg =~ s/\s*\[/\[/g; 15381da177e4SLinus Torvalds 15391da177e4SLinus Torvalds my @args = split('\s*,\s*', $arg); 15401da177e4SLinus Torvalds if ($args[0] =~ m/\*/) { 15411da177e4SLinus Torvalds $args[0] =~ s/(\*+)\s*/ $1/; 15421da177e4SLinus Torvalds } 1543884f2810SBorislav Petkov 1544884f2810SBorislav Petkov my @first_arg; 1545884f2810SBorislav Petkov if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1546884f2810SBorislav Petkov shift @args; 1547884f2810SBorislav Petkov push(@first_arg, split('\s+', $1)); 1548884f2810SBorislav Petkov push(@first_arg, $2); 1549884f2810SBorislav Petkov } else { 1550884f2810SBorislav Petkov @first_arg = split('\s+', shift @args); 1551884f2810SBorislav Petkov } 1552884f2810SBorislav Petkov 15531da177e4SLinus Torvalds unshift(@args, pop @first_arg); 15541da177e4SLinus Torvalds $type = join " ", @first_arg; 15551da177e4SLinus Torvalds 15561da177e4SLinus Torvalds foreach $param (@args) { 15571da177e4SLinus Torvalds if ($param =~ m/^(\*+)\s*(.*)/) { 1558a1d94aa5SRandy Dunlap save_struct_actual($2); 1559ed8348e2SMauro Carvalho Chehab 1560ed8348e2SMauro Carvalho Chehab push_parameter($2, "$type $1", $arg, $file, $declaration_name); 15610ec69b3bSDonald Hunter } elsif ($param =~ m/(.*?):(\w+)/) { 15627b97887eSRandy Dunlap if ($type ne "") { # skip unnamed bit-fields 1563a1d94aa5SRandy Dunlap save_struct_actual($1); 1564ed8348e2SMauro Carvalho Chehab push_parameter($1, "$type:$2", $arg, $file, $declaration_name) 15651da177e4SLinus Torvalds } 1566af404fb1SVegard Nossum } else { 1567a1d94aa5SRandy Dunlap save_struct_actual($param); 1568ed8348e2SMauro Carvalho Chehab push_parameter($param, $type, $arg, $file, $declaration_name); 15691da177e4SLinus Torvalds } 15701da177e4SLinus Torvalds } 15711da177e4SLinus Torvalds } 15721da177e4SLinus Torvalds } 15731da177e4SLinus Torvalds} 15741da177e4SLinus Torvalds 1575ed8348e2SMauro Carvalho Chehabsub push_parameter($$$$$) { 15761da177e4SLinus Torvalds my $param = shift; 15771da177e4SLinus Torvalds my $type = shift; 1578ed8348e2SMauro Carvalho Chehab my $org_arg = shift; 15791da177e4SLinus Torvalds my $file = shift; 1580151c468bSMauro Carvalho Chehab my $declaration_name = shift; 15811da177e4SLinus Torvalds 15825f8c7c98SRandy Dunlap if (($anon_struct_union == 1) && ($type eq "") && 15835f8c7c98SRandy Dunlap ($param eq "}")) { 15845f8c7c98SRandy Dunlap return; # ignore the ending }; from anon. struct/union 15855f8c7c98SRandy Dunlap } 15865f8c7c98SRandy Dunlap 15875f8c7c98SRandy Dunlap $anon_struct_union = 0; 1588f9b5c530SMauro Carvalho Chehab $param =~ s/[\[\)].*//; 15891da177e4SLinus Torvalds 1590a6d3fe77SMartin Waitz if ($type eq "" && $param =~ /\.\.\.$/) 15911da177e4SLinus Torvalds { 1592c950a173SSilvio Fricke if (!$param =~ /\w\.\.\.$/) { 1593c950a173SSilvio Fricke # handles unnamed variable parameters 1594ef00028bSJonathan Corbet $param = "..."; 1595af404fb1SVegard Nossum } elsif ($param =~ /\w\.\.\.$/) { 159643756e34SJonathan Neuschäfer # for named variable parameters of the form `x...`, remove the dots 159743756e34SJonathan Neuschäfer $param =~ s/\.\.\.$//; 159843756e34SJonathan Neuschäfer } 1599ced69090SRandy Dunlap if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1600a6d3fe77SMartin Waitz $parameterdescs{$param} = "variable arguments"; 16011da177e4SLinus Torvalds } 1602ced69090SRandy Dunlap } 16031da177e4SLinus Torvalds elsif ($type eq "" && ($param eq "" or $param eq "void")) 16041da177e4SLinus Torvalds { 16051da177e4SLinus Torvalds $param="void"; 16061da177e4SLinus Torvalds $parameterdescs{void} = "no arguments"; 16071da177e4SLinus Torvalds } 1608134fe01bSRandy Dunlap elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1609134fe01bSRandy Dunlap # handle unnamed (anonymous) union or struct: 1610134fe01bSRandy Dunlap { 1611134fe01bSRandy Dunlap $type = $param; 1612134fe01bSRandy Dunlap $param = "{unnamed_" . $param . "}"; 1613134fe01bSRandy Dunlap $parameterdescs{$param} = "anonymous\n"; 16145f8c7c98SRandy Dunlap $anon_struct_union = 1; 1615134fe01bSRandy Dunlap } 1616aeb9ce05SCoco Li elsif ($param =~ "__cacheline_group" ) 1617aeb9ce05SCoco Li # handle cache group enforcing variables: they do not need be described in header files 1618aeb9ce05SCoco Li { 1619aeb9ce05SCoco Li return; # ignore __cacheline_group_begin and __cacheline_group_end 1620aeb9ce05SCoco Li } 1621134fe01bSRandy Dunlap 1622a6d3fe77SMartin Waitz # warn if parameter has no description 1623134fe01bSRandy Dunlap # (but ignore ones starting with # as these are not parameters 1624134fe01bSRandy Dunlap # but inline preprocessor statements); 1625151c468bSMauro Carvalho Chehab # Note: It will also ignore void params and unnamed structs/unions 1626f9b5c530SMauro Carvalho Chehab if (!defined $parameterdescs{$param} && $param !~ /^#/) { 1627f9b5c530SMauro Carvalho Chehab $parameterdescs{$param} = $undescribed; 16281da177e4SLinus Torvalds 1629be5cd20cSJonathan Corbet if (show_warnings($type, $declaration_name) && $param !~ /\./) { 16300c3ebff5SKees Cook emit_warning("${file}:$.", "Function parameter or struct member '$param' not described in '$declaration_name'\n"); 16311da177e4SLinus Torvalds } 16322defb272SMauro Carvalho Chehab } 16331da177e4SLinus Torvalds 163425985edcSLucas De Marchi # strip spaces from $param so that it is one continuous string 1635e34e7dbbSRandy Dunlap # on @parameterlist; 1636e34e7dbbSRandy Dunlap # this fixes a problem where check_sections() cannot find 1637e34e7dbbSRandy Dunlap # a parameter like "addr[6 + 2]" because it actually appears 1638e34e7dbbSRandy Dunlap # as "addr[6", "+", "2]" on the parameter list; 1639e34e7dbbSRandy Dunlap # but it's better to maintain the param string unchanged for output, 1640e34e7dbbSRandy Dunlap # so just weaken the string compare in check_sections() to ignore 1641e34e7dbbSRandy Dunlap # "[blah" in a parameter string; 1642e34e7dbbSRandy Dunlap ###$param =~ s/\s*//g; 16431da177e4SLinus Torvalds push @parameterlist, $param; 1644ed8348e2SMauro Carvalho Chehab $org_arg =~ s/\s\s+/ /g; 1645ed8348e2SMauro Carvalho Chehab $parametertypes{$param} = $org_arg; 16461da177e4SLinus Torvalds} 16471da177e4SLinus Torvalds 16481081de2dSMauro Carvalho Chehabsub check_sections($$$$$) { 16491081de2dSMauro Carvalho Chehab my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_; 1650a1d94aa5SRandy Dunlap my @sects = split ' ', $sectcheck; 1651a1d94aa5SRandy Dunlap my @prms = split ' ', $prmscheck; 1652a1d94aa5SRandy Dunlap my $err; 1653a1d94aa5SRandy Dunlap my ($px, $sx); 1654a1d94aa5SRandy Dunlap my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 1655a1d94aa5SRandy Dunlap 1656a1d94aa5SRandy Dunlap foreach $sx (0 .. $#sects) { 1657a1d94aa5SRandy Dunlap $err = 1; 1658a1d94aa5SRandy Dunlap foreach $px (0 .. $#prms) { 1659a1d94aa5SRandy Dunlap $prm_clean = $prms[$px]; 1660a1d94aa5SRandy Dunlap $prm_clean =~ s/\[.*\]//; 1661e86bdb24SAditya Srivastava $prm_clean =~ s/$attribute//i; 1662e34e7dbbSRandy Dunlap # ignore array size in a parameter string; 1663e34e7dbbSRandy Dunlap # however, the original param string may contain 1664e34e7dbbSRandy Dunlap # spaces, e.g.: addr[6 + 2] 1665e34e7dbbSRandy Dunlap # and this appears in @prms as "addr[6" since the 1666e34e7dbbSRandy Dunlap # parameter list is split at spaces; 1667e34e7dbbSRandy Dunlap # hence just ignore "[..." for the sections check; 1668e34e7dbbSRandy Dunlap $prm_clean =~ s/\[.*//; 1669e34e7dbbSRandy Dunlap 1670a1d94aa5SRandy Dunlap ##$prm_clean =~ s/^\**//; 1671a1d94aa5SRandy Dunlap if ($prm_clean eq $sects[$sx]) { 1672a1d94aa5SRandy Dunlap $err = 0; 1673a1d94aa5SRandy Dunlap last; 1674a1d94aa5SRandy Dunlap } 1675a1d94aa5SRandy Dunlap } 1676a1d94aa5SRandy Dunlap if ($err) { 1677a1d94aa5SRandy Dunlap if ($decl_type eq "function") { 1678df4bf98eSNiklas Söderlund emit_warning("${file}:$.", 1679a1d94aa5SRandy Dunlap "Excess function parameter " . 1680a1d94aa5SRandy Dunlap "'$sects[$sx]' " . 1681df4bf98eSNiklas Söderlund "description in '$decl_name'\n"); 1682af404fb1SVegard Nossum } elsif (($decl_type eq "struct") or 1683b77fdd6aSRandy Dunlap ($decl_type eq "union")) { 1684b77fdd6aSRandy Dunlap emit_warning("${file}:$.", 1685b77fdd6aSRandy Dunlap "Excess $decl_type member " . 1686b77fdd6aSRandy Dunlap "'$sects[$sx]' " . 1687b77fdd6aSRandy Dunlap "description in '$decl_name'\n"); 1688b77fdd6aSRandy Dunlap } 1689a1d94aa5SRandy Dunlap } 1690a1d94aa5SRandy Dunlap } 1691a1d94aa5SRandy Dunlap} 1692a1d94aa5SRandy Dunlap 16931da177e4SLinus Torvalds## 16944092bac7SYacine Belkadi# Checks the section describing the return value of a function. 16954092bac7SYacine Belkadisub check_return_section { 16964092bac7SYacine Belkadi my $file = shift; 16974092bac7SYacine Belkadi my $declaration_name = shift; 16984092bac7SYacine Belkadi my $return_type = shift; 16994092bac7SYacine Belkadi 17004092bac7SYacine Belkadi # Ignore an empty return type (It's a macro) 17014092bac7SYacine Belkadi # Ignore functions with a "void" return type. (But don't ignore "void *") 17024092bac7SYacine Belkadi if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 17034092bac7SYacine Belkadi return; 17044092bac7SYacine Belkadi } 17054092bac7SYacine Belkadi 17064092bac7SYacine Belkadi if (!defined($sections{$section_return}) || 1707af404fb1SVegard Nossum $sections{$section_return} eq "") 1708af404fb1SVegard Nossum { 1709df4bf98eSNiklas Söderlund emit_warning("${file}:$.", 17104092bac7SYacine Belkadi "No description found for return value of " . 1711df4bf98eSNiklas Söderlund "'$declaration_name'\n"); 17124092bac7SYacine Belkadi } 17134092bac7SYacine Belkadi} 17144092bac7SYacine Belkadi 17154092bac7SYacine Belkadi## 17161da177e4SLinus Torvalds# takes a function prototype and the name of the current file being 17171da177e4SLinus Torvalds# processed and spits out all the details stored in the global 17181da177e4SLinus Torvalds# arrays/hashes. 17191da177e4SLinus Torvaldssub dump_function($$) { 17201da177e4SLinus Torvalds my $prototype = shift; 17211da177e4SLinus Torvalds my $file = shift; 1722bb8fd09eSRandy Dunlap my $func_macro = 0; 17231da177e4SLinus Torvalds 17245ef09c96SMauro Carvalho Chehab print_lineno($new_start_line); 17255eb6b4b3SMauro Carvalho Chehab 17261da177e4SLinus Torvalds $prototype =~ s/^static +//; 17271da177e4SLinus Torvalds $prototype =~ s/^extern +//; 17284dc3b16bSPavel Pisa $prototype =~ s/^asmlinkage +//; 17291da177e4SLinus Torvalds $prototype =~ s/^inline +//; 17301da177e4SLinus Torvalds $prototype =~ s/^__inline__ +//; 173132e79401SRandy Dunlap $prototype =~ s/^__inline +//; 173232e79401SRandy Dunlap $prototype =~ s/^__always_inline +//; 173332e79401SRandy Dunlap $prototype =~ s/^noinline +//; 173403699f27SKees Cook $prototype =~ s/^__FORTIFY_INLINE +//; 173574fc5c65SRandy Dunlap $prototype =~ s/__init +//; 173620072205SRandy Dunlap $prototype =~ s/__init_or_module +//; 173780342d48SMatthew Wilcox $prototype =~ s/__deprecated +//; 1738084aa001SAditya Srivastava $prototype =~ s/__flatten +//; 1739270a0096SRandy Dunlap $prototype =~ s/__meminit +//; 174070c95b00SRandy Dunlap $prototype =~ s/__must_check +//; 17410df7c0e3SRandy Dunlap $prototype =~ s/__weak +//; 17420891f959SMatthew Wilcox $prototype =~ s/__sched +//; 174351a7bf02SRandy Dunlap $prototype =~ s/_noprof//; 174495e760cbSRandy Dunlap $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//; 174503699f27SKees Cook $prototype =~ s/__(?:re)?alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +//; 174603699f27SKees Cook $prototype =~ s/__diagnose_as\s*\(\s*\S+\s*(?:,\s*\d+\s*)*\) +//; 174767f2df3bSKees Cook $prototype =~ s/DECL_BUCKET_PARAMS\s*\(\s*(\S+)\s*,\s*(\S+)\s*\)/$1, $2/; 1748cbb4d3e6SHoria Geanta my $define = $prototype =~ s/^#\s*define\s+//; #ak added 1749084aa001SAditya Srivastava $prototype =~ s/__attribute_const__ +//; 1750b1aaa546SPaolo Bonzini $prototype =~ s/__attribute__\s*\(\( 1751b1aaa546SPaolo Bonzini (?: 1752b1aaa546SPaolo Bonzini [\w\s]++ # attribute name 1753b1aaa546SPaolo Bonzini (?:\([^)]*+\))? # attribute arguments 1754b1aaa546SPaolo Bonzini \s*+,? # optional comma at the end 1755b1aaa546SPaolo Bonzini )+ 1756b1aaa546SPaolo Bonzini \)\)\s+//x; 17571da177e4SLinus Torvalds 17581da177e4SLinus Torvalds # Yes, this truly is vile. We are looking for: 17591da177e4SLinus Torvalds # 1. Return type (may be nothing if we're looking at a macro) 17601da177e4SLinus Torvalds # 2. Function name 17611da177e4SLinus Torvalds # 3. Function parameters. 17621da177e4SLinus Torvalds # 17631da177e4SLinus Torvalds # All the while we have to watch out for function pointer parameters 17641da177e4SLinus Torvalds # (which IIRC is what the two sections are for), C types (these 17651da177e4SLinus Torvalds # regexps don't even start to express all the possibilities), and 17661da177e4SLinus Torvalds # so on. 17671da177e4SLinus Torvalds # 17681da177e4SLinus Torvalds # If you mess with these regexps, it's a good idea to check that 17691da177e4SLinus Torvalds # the following functions' documentation still comes out right: 17701da177e4SLinus Torvalds # - parport_register_device (function pointer parameters) 17711da177e4SLinus Torvalds # - atomic_set (macro) 17729598f91fSMartin Waitz # - pci_match_device, __copy_to_user (long return type) 1773e86bdb24SAditya Srivastava my $name = qr{[a-zA-Z0-9_~:]+}; 1774e86bdb24SAditya Srivastava my $prototype_end1 = qr{[^\(]*}; 1775e86bdb24SAditya Srivastava my $prototype_end2 = qr{[^\{]*}; 1776e86bdb24SAditya Srivastava my $prototype_end = qr{\(($prototype_end1|$prototype_end2)\)}; 1777e86bdb24SAditya Srivastava my $type1 = qr{[\w\s]+}; 1778e86bdb24SAditya Srivastava my $type2 = qr{$type1\*+}; 17791da177e4SLinus Torvalds 1780e86bdb24SAditya Srivastava if ($define && $prototype =~ m/^()($name)\s+/) { 1781cbb4d3e6SHoria Geanta # This is an object-like macro, it has no return type and no parameter 1782cbb4d3e6SHoria Geanta # list. 1783cbb4d3e6SHoria Geanta # Function-like macros are not allowed to have spaces between 1784cbb4d3e6SHoria Geanta # declaration_name and opening parenthesis (notice the \s+). 1785cbb4d3e6SHoria Geanta $return_type = $1; 1786cbb4d3e6SHoria Geanta $declaration_name = $2; 1787bb8fd09eSRandy Dunlap $func_macro = 1; 1788e86bdb24SAditya Srivastava } elsif ($prototype =~ m/^()($name)\s*$prototype_end/ || 1789e86bdb24SAditya Srivastava $prototype =~ m/^($type1)\s+($name)\s*$prototype_end/ || 1790e86bdb24SAditya Srivastava $prototype =~ m/^($type2+)\s*($name)\s*$prototype_end/) { 17911da177e4SLinus Torvalds $return_type = $1; 17921da177e4SLinus Torvalds $declaration_name = $2; 17931da177e4SLinus Torvalds my $args = $3; 17941da177e4SLinus Torvalds 1795151c468bSMauro Carvalho Chehab create_parameterlist($args, ',', $file, $declaration_name); 17961da177e4SLinus Torvalds } else { 1797df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "cannot understand function prototype: '$prototype'\n"); 17981da177e4SLinus Torvalds return; 17991da177e4SLinus Torvalds } 18001da177e4SLinus Torvalds 180152042e2dSMauro Carvalho Chehab if ($identifier ne $declaration_name) { 1802df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "expecting prototype for $identifier(). Prototype was for $declaration_name() instead\n"); 180352042e2dSMauro Carvalho Chehab return; 180452042e2dSMauro Carvalho Chehab } 180552042e2dSMauro Carvalho Chehab 1806a1d94aa5SRandy Dunlap my $prms = join " ", @parameterlist; 18071081de2dSMauro Carvalho Chehab check_sections($file, $declaration_name, "function", $sectcheck, $prms); 1808a1d94aa5SRandy Dunlap 18094092bac7SYacine Belkadi # This check emits a lot of warnings at the moment, because many 18104092bac7SYacine Belkadi # functions don't have a 'Return' doc section. So until the number 18114092bac7SYacine Belkadi # of warnings goes sufficiently down, the check is only performed in 181256b0f453SJohannes Berg # -Wreturn mode. 18134092bac7SYacine Belkadi # TODO: always perform the check. 1814bb8fd09eSRandy Dunlap if ($Wreturn && !$func_macro) { 18154092bac7SYacine Belkadi check_return_section($file, $declaration_name, $return_type); 18164092bac7SYacine Belkadi } 18174092bac7SYacine Belkadi 181847bcacfdSMauro Carvalho Chehab # The function parser can be called with a typedef parameter. 181947bcacfdSMauro Carvalho Chehab # Handle it. 182047bcacfdSMauro Carvalho Chehab if ($return_type =~ /typedef/) { 182147bcacfdSMauro Carvalho Chehab output_declaration($declaration_name, 182247bcacfdSMauro Carvalho Chehab 'function', 182347bcacfdSMauro Carvalho Chehab {'function' => $declaration_name, 182447bcacfdSMauro Carvalho Chehab 'typedef' => 1, 182547bcacfdSMauro Carvalho Chehab 'module' => $modulename, 182647bcacfdSMauro Carvalho Chehab 'functiontype' => $return_type, 182747bcacfdSMauro Carvalho Chehab 'parameterlist' => \@parameterlist, 182847bcacfdSMauro Carvalho Chehab 'parameterdescs' => \%parameterdescs, 182947bcacfdSMauro Carvalho Chehab 'parametertypes' => \%parametertypes, 183047bcacfdSMauro Carvalho Chehab 'sectionlist' => \@sectionlist, 183147bcacfdSMauro Carvalho Chehab 'sections' => \%sections, 1832bb8fd09eSRandy Dunlap 'purpose' => $declaration_purpose, 1833bb8fd09eSRandy Dunlap 'func_macro' => $func_macro 183447bcacfdSMauro Carvalho Chehab }); 183547bcacfdSMauro Carvalho Chehab } else { 18361da177e4SLinus Torvalds output_declaration($declaration_name, 18371da177e4SLinus Torvalds 'function', 18381da177e4SLinus Torvalds {'function' => $declaration_name, 18391da177e4SLinus Torvalds 'module' => $modulename, 18401da177e4SLinus Torvalds 'functiontype' => $return_type, 18411da177e4SLinus Torvalds 'parameterlist' => \@parameterlist, 18421da177e4SLinus Torvalds 'parameterdescs' => \%parameterdescs, 18431da177e4SLinus Torvalds 'parametertypes' => \%parametertypes, 18441da177e4SLinus Torvalds 'sectionlist' => \@sectionlist, 18451da177e4SLinus Torvalds 'sections' => \%sections, 1846bb8fd09eSRandy Dunlap 'purpose' => $declaration_purpose, 1847bb8fd09eSRandy Dunlap 'func_macro' => $func_macro 18481da177e4SLinus Torvalds }); 18491da177e4SLinus Torvalds } 185047bcacfdSMauro Carvalho Chehab} 18511da177e4SLinus Torvalds 18521da177e4SLinus Torvaldssub reset_state { 18531da177e4SLinus Torvalds $function = ""; 18541da177e4SLinus Torvalds %parameterdescs = (); 18551da177e4SLinus Torvalds %parametertypes = (); 18561da177e4SLinus Torvalds @parameterlist = (); 18571da177e4SLinus Torvalds %sections = (); 18581da177e4SLinus Torvalds @sectionlist = (); 1859a1d94aa5SRandy Dunlap $sectcheck = ""; 1860a1d94aa5SRandy Dunlap $struct_actual = ""; 18611da177e4SLinus Torvalds $prototype = ""; 18621da177e4SLinus Torvalds 186348af606aSJani Nikula $state = STATE_NORMAL; 186448af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 18651da177e4SLinus Torvalds} 18661da177e4SLinus Torvalds 186756afb0f8SJason Baronsub tracepoint_munge($) { 186856afb0f8SJason Baron my $file = shift; 186956afb0f8SJason Baron my $tracepointname = 0; 187056afb0f8SJason Baron my $tracepointargs = 0; 187156afb0f8SJason Baron 187256afb0f8SJason Baron if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 187356afb0f8SJason Baron $tracepointname = $1; 187456afb0f8SJason Baron } 18753a9089fdSJason Baron if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 18763a9089fdSJason Baron $tracepointname = $1; 18773a9089fdSJason Baron } 18783a9089fdSJason Baron if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 18793a9089fdSJason Baron $tracepointname = $2; 18803a9089fdSJason Baron } 18813a9089fdSJason Baron $tracepointname =~ s/^\s+//; #strip leading whitespace 188256afb0f8SJason Baron if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 188356afb0f8SJason Baron $tracepointargs = $1; 188456afb0f8SJason Baron } 188556afb0f8SJason Baron if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 1886df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Unrecognized tracepoint format: \n". 1887df4bf98eSNiklas Söderlund "$prototype\n"); 188856afb0f8SJason Baron } else { 188956afb0f8SJason Baron $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 189052042e2dSMauro Carvalho Chehab $identifier = "trace_$identifier"; 189156afb0f8SJason Baron } 189256afb0f8SJason Baron} 189356afb0f8SJason Baron 1894b4870bc5SRandy Dunlapsub syscall_munge() { 1895b4870bc5SRandy Dunlap my $void = 0; 1896b4870bc5SRandy Dunlap 18977c9aa015SMauro Carvalho Chehab $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's 1898b4870bc5SRandy Dunlap## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 1899b4870bc5SRandy Dunlap if ($prototype =~ m/SYSCALL_DEFINE0/) { 1900b4870bc5SRandy Dunlap $void = 1; 1901b4870bc5SRandy Dunlap## $prototype = "long sys_$1(void)"; 1902b4870bc5SRandy Dunlap } 1903b4870bc5SRandy Dunlap 1904b4870bc5SRandy Dunlap $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 1905b4870bc5SRandy Dunlap if ($prototype =~ m/long (sys_.*?),/) { 1906b4870bc5SRandy Dunlap $prototype =~ s/,/\(/; 1907b4870bc5SRandy Dunlap } elsif ($void) { 1908b4870bc5SRandy Dunlap $prototype =~ s/\)/\(void\)/; 1909b4870bc5SRandy Dunlap } 1910b4870bc5SRandy Dunlap 1911b4870bc5SRandy Dunlap # now delete all of the odd-number commas in $prototype 1912b4870bc5SRandy Dunlap # so that arg types & arg names don't have a comma between them 1913b4870bc5SRandy Dunlap my $count = 0; 1914b4870bc5SRandy Dunlap my $len = length($prototype); 1915b4870bc5SRandy Dunlap if ($void) { 1916b4870bc5SRandy Dunlap $len = 0; # skip the for-loop 1917b4870bc5SRandy Dunlap } 1918b4870bc5SRandy Dunlap for (my $ix = 0; $ix < $len; $ix++) { 1919b4870bc5SRandy Dunlap if (substr($prototype, $ix, 1) eq ',') { 1920b4870bc5SRandy Dunlap $count++; 1921b4870bc5SRandy Dunlap if ($count % 2 == 1) { 1922b4870bc5SRandy Dunlap substr($prototype, $ix, 1) = ' '; 1923b4870bc5SRandy Dunlap } 1924b4870bc5SRandy Dunlap } 1925b4870bc5SRandy Dunlap } 1926b4870bc5SRandy Dunlap} 1927b4870bc5SRandy Dunlap 1928b7afa92bSDaniel Vettersub process_proto_function($$) { 19291da177e4SLinus Torvalds my $x = shift; 19301da177e4SLinus Torvalds my $file = shift; 19311da177e4SLinus Torvalds 193251f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 193351f5a0c8SRandy Dunlap 1934d2a70e28SRandy Dunlap if ($x =~ /^#/ && $x !~ /^#\s*define/) { 19351da177e4SLinus Torvalds # do nothing 1936af404fb1SVegard Nossum } elsif ($x =~ /([^\{]*)/) { 19371da177e4SLinus Torvalds $prototype .= $1; 19381da177e4SLinus Torvalds } 1939b4870bc5SRandy Dunlap 1940890c78c2SRandy Dunlap if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 19411da177e4SLinus Torvalds $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 19421da177e4SLinus Torvalds $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 19431da177e4SLinus Torvalds $prototype =~ s@^\s+@@gos; # strip leading spaces 19447ae281b0SMauro Carvalho Chehab 19457ae281b0SMauro Carvalho Chehab # Handle prototypes for function pointers like: 19467ae281b0SMauro Carvalho Chehab # int (*pcs_config)(struct foo) 19477ae281b0SMauro Carvalho Chehab $prototype =~ s@^(\S+\s+)\(\s*\*(\S+)\)@$1$2@gos; 19487ae281b0SMauro Carvalho Chehab 1949b4870bc5SRandy Dunlap if ($prototype =~ /SYSCALL_DEFINE/) { 1950b4870bc5SRandy Dunlap syscall_munge(); 1951b4870bc5SRandy Dunlap } 19523a9089fdSJason Baron if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 19533a9089fdSJason Baron $prototype =~ /DEFINE_SINGLE_EVENT/) 19543a9089fdSJason Baron { 195556afb0f8SJason Baron tracepoint_munge($file); 195656afb0f8SJason Baron } 19571da177e4SLinus Torvalds dump_function($prototype, $file); 19581da177e4SLinus Torvalds reset_state(); 19591da177e4SLinus Torvalds } 19601da177e4SLinus Torvalds} 19611da177e4SLinus Torvalds 1962b7afa92bSDaniel Vettersub process_proto_type($$) { 19631da177e4SLinus Torvalds my $x = shift; 19641da177e4SLinus Torvalds my $file = shift; 19651da177e4SLinus Torvalds 19661da177e4SLinus Torvalds $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 19671da177e4SLinus Torvalds $x =~ s@^\s+@@gos; # strip leading spaces 19681da177e4SLinus Torvalds $x =~ s@\s+$@@gos; # strip trailing spaces 196951f5a0c8SRandy Dunlap $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 197051f5a0c8SRandy Dunlap 19711da177e4SLinus Torvalds if ($x =~ /^#/) { 19721da177e4SLinus Torvalds # To distinguish preprocessor directive from regular declaration later. 19731da177e4SLinus Torvalds $x .= ";"; 19741da177e4SLinus Torvalds } 19751da177e4SLinus Torvalds 19761da177e4SLinus Torvalds while (1) { 1977673bb2dfSBen Hutchings if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) { 1978463a0fdcSMarkus Heiser if( length $prototype ) { 1979463a0fdcSMarkus Heiser $prototype .= " " 1980463a0fdcSMarkus Heiser } 19811da177e4SLinus Torvalds $prototype .= $1 . $2; 19821da177e4SLinus Torvalds ($2 eq '{') && $brcount++; 19831da177e4SLinus Torvalds ($2 eq '}') && $brcount--; 19841da177e4SLinus Torvalds if (($2 eq ';') && ($brcount == 0)) { 19851da177e4SLinus Torvalds dump_declaration($prototype, $file); 19861da177e4SLinus Torvalds reset_state(); 19871da177e4SLinus Torvalds last; 19881da177e4SLinus Torvalds } 19891da177e4SLinus Torvalds $x = $3; 19901da177e4SLinus Torvalds } else { 19911da177e4SLinus Torvalds $prototype .= $x; 19921da177e4SLinus Torvalds last; 19931da177e4SLinus Torvalds } 19941da177e4SLinus Torvalds } 19951da177e4SLinus Torvalds} 19961da177e4SLinus Torvalds 19976b5b55f6SRandy Dunlap 19981ad560e4SJani Nikulasub map_filename($) { 19991ad560e4SJani Nikula my $file; 20001ad560e4SJani Nikula my ($orig_file) = @_; 20011ad560e4SJani Nikula 20021ad560e4SJani Nikula if (defined($ENV{'SRCTREE'})) { 20031ad560e4SJani Nikula $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 20041ad560e4SJani Nikula } else { 20051ad560e4SJani Nikula $file = $orig_file; 20061ad560e4SJani Nikula } 20071ad560e4SJani Nikula 20081ad560e4SJani Nikula if (defined($source_map{$file})) { 20091ad560e4SJani Nikula $file = $source_map{$file}; 20101ad560e4SJani Nikula } 20111ad560e4SJani Nikula 20121ad560e4SJani Nikula return $file; 20131ad560e4SJani Nikula} 20141ad560e4SJani Nikula 201588c2b57dSJani Nikulasub process_export_file($) { 201688c2b57dSJani Nikula my ($orig_file) = @_; 201788c2b57dSJani Nikula my $file = map_filename($orig_file); 201888c2b57dSJani Nikula 201988c2b57dSJani Nikula if (!open(IN,"<$file")) { 202088c2b57dSJani Nikula print STDERR "Error: Cannot open file $file\n"; 202188c2b57dSJani Nikula ++$errors; 202288c2b57dSJani Nikula return; 202388c2b57dSJani Nikula } 202488c2b57dSJani Nikula 202588c2b57dSJani Nikula while (<IN>) { 202688c2b57dSJani Nikula if (/$export_symbol/) { 2027eab795ddSMauro Carvalho Chehab next if (defined($nosymbol_table{$2})); 202888c2b57dSJani Nikula $function_table{$2} = 1; 202988c2b57dSJani Nikula } 2030632ce137SJason Gunthorpe if (/$export_symbol_ns/) { 2031632ce137SJason Gunthorpe next if (defined($nosymbol_table{$2})); 2032632ce137SJason Gunthorpe $function_table{$2} = 1; 2033632ce137SJason Gunthorpe } 203488c2b57dSJani Nikula } 203588c2b57dSJani Nikula 203688c2b57dSJani Nikula close(IN); 203788c2b57dSJani Nikula} 203888c2b57dSJani Nikula 203907048d13SJonathan Corbet# 204007048d13SJonathan Corbet# Parsers for the various processing states. 204107048d13SJonathan Corbet# 204207048d13SJonathan Corbet# STATE_NORMAL: looking for the /** to begin everything. 204307048d13SJonathan Corbet# 204407048d13SJonathan Corbetsub process_normal() { 20451da177e4SLinus Torvalds if (/$doc_start/o) { 204648af606aSJani Nikula $state = STATE_NAME; # next line is always the function name 2047850622dfSRandy Dunlap $in_doc_sect = 0; 20480b0f5f29SDaniel Vetter $declaration_start_line = $. + 1; 20491da177e4SLinus Torvalds } 205007048d13SJonathan Corbet} 205107048d13SJonathan Corbet 20523cac2bc4SJonathan Corbet# 20533cac2bc4SJonathan Corbet# STATE_NAME: Looking for the "name - description" line 20543cac2bc4SJonathan Corbet# 20553cac2bc4SJonathan Corbetsub process_name($$) { 20563cac2bc4SJonathan Corbet my $file = shift; 20571da177e4SLinus Torvalds my $descr; 20581da177e4SLinus Torvalds 20591da177e4SLinus Torvalds if (/$doc_block/o) { 206048af606aSJani Nikula $state = STATE_DOCBLOCK; 20611da177e4SLinus Torvalds $contents = ""; 20625ef09c96SMauro Carvalho Chehab $new_start_line = $.; 20630b0f5f29SDaniel Vetter 20641da177e4SLinus Torvalds if ( $1 eq "" ) { 20651da177e4SLinus Torvalds $section = $section_intro; 20661da177e4SLinus Torvalds } else { 20671da177e4SLinus Torvalds $section = $1; 20681da177e4SLinus Torvalds } 206952042e2dSMauro Carvalho Chehab } elsif (/$doc_decl/o) { 20701da177e4SLinus Torvalds $identifier = $1; 20713e58e839SAditya Srivastava my $is_kernel_comment = 0; 2072e86bdb24SAditya Srivastava my $decl_start = qr{$doc_com}; 2073f9bbc12cSAditya Srivastava # test for pointer declaration type, foo * bar() - desc 2074f9bbc12cSAditya Srivastava my $fn_type = qr{\w+\s*\*\s*}; 2075f9bbc12cSAditya Srivastava my $parenthesis = qr{\(\w*\)}; 2076f9bbc12cSAditya Srivastava my $decl_end = qr{[-:].*}; 2077e86bdb24SAditya Srivastava if (/^$decl_start([\w\s]+?)$parenthesis?\s*$decl_end?$/) { 20781da177e4SLinus Torvalds $identifier = $1; 20791da177e4SLinus Torvalds } 208052042e2dSMauro Carvalho Chehab if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) { 208152042e2dSMauro Carvalho Chehab $decl_type = $1; 208252042e2dSMauro Carvalho Chehab $identifier = $2; 20833e58e839SAditya Srivastava $is_kernel_comment = 1; 208452042e2dSMauro Carvalho Chehab } 2085f9bbc12cSAditya Srivastava # Look for foo() or static void foo() - description; or misspelt 2086f9bbc12cSAditya Srivastava # identifier 2087e86bdb24SAditya Srivastava elsif (/^$decl_start$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ || 2088e86bdb24SAditya Srivastava /^$decl_start$fn_type?(\w+.*)$parenthesis?\s*$decl_end$/) { 2089f9bbc12cSAditya Srivastava $identifier = $1; 2090f9bbc12cSAditya Srivastava $decl_type = 'function'; 2091f9bbc12cSAditya Srivastava $identifier =~ s/^define\s+//; 2092f9bbc12cSAditya Srivastava $is_kernel_comment = 1; 2093f9bbc12cSAditya Srivastava } 209452042e2dSMauro Carvalho Chehab $identifier =~ s/\s+$//; 20951da177e4SLinus Torvalds 209617b78717SJonathan Corbet $state = STATE_BODY; 20970b0f5f29SDaniel Vetter # if there's no @param blocks need to set up default section 20980b0f5f29SDaniel Vetter # here 20992f4ad40aSJani Nikula $contents = ""; 21002f4ad40aSJani Nikula $section = $section_default; 21010b0f5f29SDaniel Vetter $new_start_line = $. + 1; 210252042e2dSMauro Carvalho Chehab if (/[-:](.*)/) { 210351f5a0c8SRandy Dunlap # strip leading/trailing/multiple spaces 2104a21217daSRandy Dunlap $descr= $1; 2105a21217daSRandy Dunlap $descr =~ s/^\s*//; 2106a21217daSRandy Dunlap $descr =~ s/\s*$//; 210712ae6779SDaniel Santos $descr =~ s/\s+/ /g; 21080bba924cSJonathan Corbet $declaration_purpose = $descr; 210917b78717SJonathan Corbet $state = STATE_BODY_MAYBE; 21101da177e4SLinus Torvalds } else { 21111da177e4SLinus Torvalds $declaration_purpose = ""; 21121da177e4SLinus Torvalds } 211377cc23b8SRandy Dunlap 21143e58e839SAditya Srivastava if (!$is_kernel_comment) { 2115df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst\n$_"); 21163e58e839SAditya Srivastava $state = STATE_NORMAL; 21173e58e839SAditya Srivastava } 21183e58e839SAditya Srivastava 211956b0f453SJohannes Berg if (($declaration_purpose eq "") && $Wshort_desc) { 2120df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "missing initial short description on line:\n$_"); 212177cc23b8SRandy Dunlap } 212277cc23b8SRandy Dunlap 21230b54c2e3SMauro Carvalho Chehab if ($identifier eq "" && $decl_type ne "enum") { 2124df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "wrong kernel-doc identifier on line:\n$_"); 212552042e2dSMauro Carvalho Chehab $state = STATE_NORMAL; 21261da177e4SLinus Torvalds } 21271da177e4SLinus Torvalds 21281da177e4SLinus Torvalds if ($verbose) { 212952042e2dSMauro Carvalho Chehab print STDERR "${file}:$.: info: Scanning doc for $decl_type $identifier\n"; 21301da177e4SLinus Torvalds } 21311da177e4SLinus Torvalds } else { 2132df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Cannot understand $_ on line $. - I thought it was a doc line\n"); 213348af606aSJani Nikula $state = STATE_NORMAL; 21341da177e4SLinus Torvalds } 21353cac2bc4SJonathan Corbet} 21363cac2bc4SJonathan Corbet 21373cac2bc4SJonathan Corbet 2138d742f24dSJonathan Corbet# 2139d742f24dSJonathan Corbet# STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment. 2140d742f24dSJonathan Corbet# 2141d742f24dSJonathan Corbetsub process_body($$) { 2142d742f24dSJonathan Corbet my $file = shift; 21433cac2bc4SJonathan Corbet 21440d55d48bSMauro Carvalho Chehab if ($state == STATE_BODY_WITH_BLANK_LINE && /^\s*\*\s?\S/) { 21450d55d48bSMauro Carvalho Chehab dump_section($file, $section, $contents); 21460d55d48bSMauro Carvalho Chehab $section = $section_default; 21475ef09c96SMauro Carvalho Chehab $new_start_line = $.; 21480d55d48bSMauro Carvalho Chehab $contents = ""; 21490d55d48bSMauro Carvalho Chehab } 21500d55d48bSMauro Carvalho Chehab 2151f624adefSJani Nikula if (/$doc_sect/i) { # case insensitive for supported section names 2152afa751e8SRandy Dunlap $in_doc_sect = 1; 21531da177e4SLinus Torvalds $newsection = $1; 21541da177e4SLinus Torvalds $newcontents = $2; 21551da177e4SLinus Torvalds 2156f624adefSJani Nikula # map the supported section names to the canonical names 2157f624adefSJani Nikula if ($newsection =~ m/^description$/i) { 2158f624adefSJani Nikula $newsection = $section_default; 2159f624adefSJani Nikula } elsif ($newsection =~ m/^context$/i) { 2160f624adefSJani Nikula $newsection = $section_context; 2161f624adefSJani Nikula } elsif ($newsection =~ m/^returns?$/i) { 2162f624adefSJani Nikula $newsection = $section_return; 2163f624adefSJani Nikula } elsif ($newsection =~ m/^\@return$/) { 2164f624adefSJani Nikula # special: @return is a section, not a param description 2165f624adefSJani Nikula $newsection = $section_return; 2166f624adefSJani Nikula } 2167f624adefSJani Nikula 2168792aa2f2SRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 216956b0f453SJohannes Berg if (!$in_doc_sect && $Wcontents_before_sections) { 2170df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "contents before sections\n"); 2171850622dfSRandy Dunlap } 21720bba924cSJonathan Corbet dump_section($file, $section, $contents); 21731da177e4SLinus Torvalds $section = $section_default; 21741da177e4SLinus Torvalds } 21751da177e4SLinus Torvalds 2176850622dfSRandy Dunlap $in_doc_sect = 1; 217717b78717SJonathan Corbet $state = STATE_BODY; 21781da177e4SLinus Torvalds $contents = $newcontents; 21790b0f5f29SDaniel Vetter $new_start_line = $.; 21807c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 218105189497SRandy Dunlap $contents = substr($contents, 1); 218205189497SRandy Dunlap } 21830a726301SJani Nikula if ($contents ne "") { 21841da177e4SLinus Torvalds $contents .= "\n"; 21851da177e4SLinus Torvalds } 21861da177e4SLinus Torvalds $section = $newsection; 2187b7886de4SJani Nikula $leading_space = undef; 21881da177e4SLinus Torvalds } elsif (/$doc_end/) { 21894c98ecafSRandy Dunlap if (($contents ne "") && ($contents ne "\n")) { 21900bba924cSJonathan Corbet dump_section($file, $section, $contents); 21911da177e4SLinus Torvalds $section = $section_default; 21921da177e4SLinus Torvalds $contents = ""; 21931da177e4SLinus Torvalds } 219446b958ebSRandy Dunlap # look for doc_com + <text> + doc_end: 219546b958ebSRandy Dunlap if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { 2196df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "suspicious ending line: $_"); 219746b958ebSRandy Dunlap } 21981da177e4SLinus Torvalds 21991da177e4SLinus Torvalds $prototype = ""; 220048af606aSJani Nikula $state = STATE_PROTO; 22011da177e4SLinus Torvalds $brcount = 0; 22025ef09c96SMauro Carvalho Chehab $new_start_line = $. + 1; 22031da177e4SLinus Torvalds } elsif (/$doc_content/) { 22046423133bSJohannes Weiner if ($1 eq "") { 22050d55d48bSMauro Carvalho Chehab if ($section eq $section_context) { 22060bba924cSJonathan Corbet dump_section($file, $section, $contents); 22071da177e4SLinus Torvalds $section = $section_default; 22081da177e4SLinus Torvalds $contents = ""; 22090b0f5f29SDaniel Vetter $new_start_line = $.; 22100d55d48bSMauro Carvalho Chehab $state = STATE_BODY; 22111da177e4SLinus Torvalds } else { 22120d55d48bSMauro Carvalho Chehab if ($section ne $section_default) { 22130d55d48bSMauro Carvalho Chehab $state = STATE_BODY_WITH_BLANK_LINE; 22140d55d48bSMauro Carvalho Chehab } else { 22150d55d48bSMauro Carvalho Chehab $state = STATE_BODY; 22160d55d48bSMauro Carvalho Chehab } 22176423133bSJohannes Weiner $contents .= "\n"; 22186423133bSJohannes Weiner } 221917b78717SJonathan Corbet } elsif ($state == STATE_BODY_MAYBE) { 22206423133bSJohannes Weiner # Continued declaration purpose 22216423133bSJohannes Weiner chomp($declaration_purpose); 22220bba924cSJonathan Corbet $declaration_purpose .= " " . $1; 222312ae6779SDaniel Santos $declaration_purpose =~ s/\s+/ /g; 22246423133bSJohannes Weiner } else { 2225b7886de4SJani Nikula my $cont = $1; 2226b7886de4SJani Nikula if ($section =~ m/^@/ || $section eq $section_context) { 2227b7886de4SJani Nikula if (!defined $leading_space) { 2228b7886de4SJani Nikula if ($cont =~ m/^(\s+)/) { 2229b7886de4SJani Nikula $leading_space = $1; 2230b7886de4SJani Nikula } else { 2231b7886de4SJani Nikula $leading_space = ""; 2232b7886de4SJani Nikula } 2233b7886de4SJani Nikula } 2234b7886de4SJani Nikula $cont =~ s/^$leading_space//; 2235b7886de4SJani Nikula } 2236b7886de4SJani Nikula $contents .= $cont . "\n"; 22371da177e4SLinus Torvalds } 22381da177e4SLinus Torvalds } else { 22391da177e4SLinus Torvalds # i dont know - bad line? ignore. 2240df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "bad line: $_"); 22411da177e4SLinus Torvalds } 2242d742f24dSJonathan Corbet} 2243d742f24dSJonathan Corbet 2244d742f24dSJonathan Corbet 2245cc794812SJonathan Corbet# 2246cc794812SJonathan Corbet# STATE_PROTO: reading a function/whatever prototype. 2247cc794812SJonathan Corbet# 2248cc794812SJonathan Corbetsub process_proto($$) { 2249cc794812SJonathan Corbet my $file = shift; 2250cc794812SJonathan Corbet 2251cc794812SJonathan Corbet if (/$doc_inline_oneline/) { 2252cc794812SJonathan Corbet $section = $1; 2253cc794812SJonathan Corbet $contents = $2; 2254cc794812SJonathan Corbet if ($contents ne "") { 2255cc794812SJonathan Corbet $contents .= "\n"; 2256cc794812SJonathan Corbet dump_section($file, $section, $contents); 2257cc794812SJonathan Corbet $section = $section_default; 2258cc794812SJonathan Corbet $contents = ""; 2259cc794812SJonathan Corbet } 2260cc794812SJonathan Corbet } elsif (/$doc_inline_start/) { 2261cc794812SJonathan Corbet $state = STATE_INLINE; 2262cc794812SJonathan Corbet $inline_doc_state = STATE_INLINE_NAME; 2263cc794812SJonathan Corbet } elsif ($decl_type eq 'function') { 2264cc794812SJonathan Corbet process_proto_function($_, $file); 2265cc794812SJonathan Corbet } else { 2266cc794812SJonathan Corbet process_proto_type($_, $file); 2267cc794812SJonathan Corbet } 2268cc794812SJonathan Corbet} 2269cc794812SJonathan Corbet 2270c17add56SJonathan Corbet# 2271c17add56SJonathan Corbet# STATE_DOCBLOCK: within a DOC: block. 2272c17add56SJonathan Corbet# 2273c17add56SJonathan Corbetsub process_docblock($$) { 2274c17add56SJonathan Corbet my $file = shift; 2275cc794812SJonathan Corbet 2276c17add56SJonathan Corbet if (/$doc_end/) { 2277c17add56SJonathan Corbet dump_doc_section($file, $section, $contents); 2278c17add56SJonathan Corbet $section = $section_default; 2279c17add56SJonathan Corbet $contents = ""; 2280c17add56SJonathan Corbet $function = ""; 2281c17add56SJonathan Corbet %parameterdescs = (); 2282c17add56SJonathan Corbet %parametertypes = (); 2283c17add56SJonathan Corbet @parameterlist = (); 2284c17add56SJonathan Corbet %sections = (); 2285c17add56SJonathan Corbet @sectionlist = (); 2286c17add56SJonathan Corbet $prototype = ""; 2287c17add56SJonathan Corbet $state = STATE_NORMAL; 2288c17add56SJonathan Corbet } elsif (/$doc_content/) { 2289c17add56SJonathan Corbet if ( $1 eq "" ) { 2290c17add56SJonathan Corbet $contents .= $blankline; 2291c17add56SJonathan Corbet } else { 2292c17add56SJonathan Corbet $contents .= $1 . "\n"; 2293c17add56SJonathan Corbet } 2294c17add56SJonathan Corbet } 2295d742f24dSJonathan Corbet} 2296d742f24dSJonathan Corbet 2297c17add56SJonathan Corbet# 2298c17add56SJonathan Corbet# STATE_INLINE: docbook comments within a prototype. 2299c17add56SJonathan Corbet# 2300c17add56SJonathan Corbetsub process_inline($$) { 2301c17add56SJonathan Corbet my $file = shift; 2302d742f24dSJonathan Corbet 2303a4c6ebedSDanilo Cesar Lemes de Paula # First line (state 1) needs to be a @parameter 230448af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { 2305a4c6ebedSDanilo Cesar Lemes de Paula $section = $1; 2306a4c6ebedSDanilo Cesar Lemes de Paula $contents = $2; 23070b0f5f29SDaniel Vetter $new_start_line = $.; 2308a4c6ebedSDanilo Cesar Lemes de Paula if ($contents ne "") { 23097c9aa015SMauro Carvalho Chehab while (substr($contents, 0, 1) eq " ") { 2310a4c6ebedSDanilo Cesar Lemes de Paula $contents = substr($contents, 1); 2311a4c6ebedSDanilo Cesar Lemes de Paula } 2312a4c6ebedSDanilo Cesar Lemes de Paula $contents .= "\n"; 2313a4c6ebedSDanilo Cesar Lemes de Paula } 231448af606aSJani Nikula $inline_doc_state = STATE_INLINE_TEXT; 2315a4c6ebedSDanilo Cesar Lemes de Paula # Documentation block end */ 231648af606aSJani Nikula } elsif (/$doc_inline_end/) { 2317a4c6ebedSDanilo Cesar Lemes de Paula if (($contents ne "") && ($contents ne "\n")) { 23180bba924cSJonathan Corbet dump_section($file, $section, $contents); 2319a4c6ebedSDanilo Cesar Lemes de Paula $section = $section_default; 2320a4c6ebedSDanilo Cesar Lemes de Paula $contents = ""; 2321a4c6ebedSDanilo Cesar Lemes de Paula } 232248af606aSJani Nikula $state = STATE_PROTO; 232348af606aSJani Nikula $inline_doc_state = STATE_INLINE_NA; 2324a4c6ebedSDanilo Cesar Lemes de Paula # Regular text 2325a4c6ebedSDanilo Cesar Lemes de Paula } elsif (/$doc_content/) { 232648af606aSJani Nikula if ($inline_doc_state == STATE_INLINE_TEXT) { 2327a4c6ebedSDanilo Cesar Lemes de Paula $contents .= $1 . "\n"; 23286450c895SJani Nikula # nuke leading blank lines 23296450c895SJani Nikula if ($contents =~ /^\s*$/) { 23306450c895SJani Nikula $contents = ""; 23316450c895SJani Nikula } 233248af606aSJani Nikula } elsif ($inline_doc_state == STATE_INLINE_NAME) { 233348af606aSJani Nikula $inline_doc_state = STATE_INLINE_ERROR; 2334df4bf98eSNiklas Söderlund emit_warning("${file}:$.", "Incorrect use of kernel-doc format: $_"); 2335a4c6ebedSDanilo Cesar Lemes de Paula } 2336a4c6ebedSDanilo Cesar Lemes de Paula } 23370c9aa209SJani Nikula} 2338c17add56SJonathan Corbet 2339c17add56SJonathan Corbet 2340c17add56SJonathan Corbetsub process_file($) { 2341c17add56SJonathan Corbet my $file; 2342c17add56SJonathan Corbet my ($orig_file) = @_; 2343c17add56SJonathan Corbet 2344c17add56SJonathan Corbet $file = map_filename($orig_file); 2345c17add56SJonathan Corbet 2346dbe8ba00SMauro Carvalho Chehab if (!open(IN_FILE,"<$file")) { 2347c17add56SJonathan Corbet print STDERR "Error: Cannot open file $file\n"; 2348c17add56SJonathan Corbet ++$errors; 2349c17add56SJonathan Corbet return; 23501da177e4SLinus Torvalds } 2351c17add56SJonathan Corbet 2352c17add56SJonathan Corbet $. = 1; 2353c17add56SJonathan Corbet 2354c17add56SJonathan Corbet $section_counter = 0; 2355dbe8ba00SMauro Carvalho Chehab while (<IN_FILE>) { 2356e5a52766SAnna-Maria Behnsen while (!/^ \*/ && s/\\\s*$//) { 2357dbe8ba00SMauro Carvalho Chehab $_ .= <IN_FILE>; 2358c17add56SJonathan Corbet } 2359c17add56SJonathan Corbet # Replace tabs by spaces 2360c17add56SJonathan Corbet while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {}; 2361c17add56SJonathan Corbet # Hand this line to the appropriate state handler 2362c17add56SJonathan Corbet if ($state == STATE_NORMAL) { 2363c17add56SJonathan Corbet process_normal(); 2364c17add56SJonathan Corbet } elsif ($state == STATE_NAME) { 2365c17add56SJonathan Corbet process_name($file, $_); 23660d55d48bSMauro Carvalho Chehab } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE || 23670d55d48bSMauro Carvalho Chehab $state == STATE_BODY_WITH_BLANK_LINE) { 2368c17add56SJonathan Corbet process_body($file, $_); 2369c17add56SJonathan Corbet } elsif ($state == STATE_INLINE) { # scanning for inline parameters 2370c17add56SJonathan Corbet process_inline($file, $_); 2371cc794812SJonathan Corbet } elsif ($state == STATE_PROTO) { 2372cc794812SJonathan Corbet process_proto($file, $_); 237348af606aSJani Nikula } elsif ($state == STATE_DOCBLOCK) { 2374c17add56SJonathan Corbet process_docblock($file, $_); 23751da177e4SLinus Torvalds } 23761da177e4SLinus Torvalds } 2377c17add56SJonathan Corbet 2378c17add56SJonathan Corbet # Make sure we got something interesting. 2379be926411SChen-Yu Tsai if (!$section_counter && $output_mode ne "none") { 2380b0d60bfbSJonathan Corbet if ($output_selection == OUTPUT_INCLUDE) { 2381df4bf98eSNiklas Söderlund emit_warning("${file}:1", "'$_' not found\n") 2382b0d60bfbSJonathan Corbet for keys %function_table; 2383af404fb1SVegard Nossum } else { 2384df4bf98eSNiklas Söderlund emit_warning("${file}:1", "no structured comments found\n"); 2385e946c43aSJohannes Berg } 23861da177e4SLinus Torvalds } 2387dbe8ba00SMauro Carvalho Chehab close IN_FILE; 23881da177e4SLinus Torvalds} 23898484baaaSRandy Dunlap 23908484baaaSRandy Dunlap 239193351d41SMauro Carvalho Chehabif ($output_mode eq "rst") { 239293351d41SMauro Carvalho Chehab get_sphinx_version() if (!$sphinx_major); 239393351d41SMauro Carvalho Chehab} 239493351d41SMauro Carvalho Chehab 23958484baaaSRandy Dunlap$kernelversion = get_kernel_version(); 23968484baaaSRandy Dunlap 23978484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information 23988484baaaSRandy Dunlap# using the s// operator. 23991ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) { 24004d732701SDanilo Cesar Lemes de Paula my $pattern = $highlights[$k][0]; 24014d732701SDanilo Cesar Lemes de Paula my $result = $highlights[$k][1]; 24024d732701SDanilo Cesar Lemes de Paula# print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 24034d732701SDanilo Cesar Lemes de Paula $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 24048484baaaSRandy Dunlap} 24058484baaaSRandy Dunlap 24068484baaaSRandy Dunlap# Read the file that maps relative names to absolute names for 24078484baaaSRandy Dunlap# separate source and object directories and for shadow trees. 24088484baaaSRandy Dunlapif (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 24098484baaaSRandy Dunlap my ($relname, $absname); 24108484baaaSRandy Dunlap while(<SOURCE_MAP>) { 24118484baaaSRandy Dunlap chop(); 24128484baaaSRandy Dunlap ($relname, $absname) = (split())[0..1]; 24138484baaaSRandy Dunlap $relname =~ s:^/+::; 24148484baaaSRandy Dunlap $source_map{$relname} = $absname; 24158484baaaSRandy Dunlap } 24168484baaaSRandy Dunlap close(SOURCE_MAP); 24178484baaaSRandy Dunlap} 24188484baaaSRandy Dunlap 241988c2b57dSJani Nikulaif ($output_selection == OUTPUT_EXPORTED || 242088c2b57dSJani Nikula $output_selection == OUTPUT_INTERNAL) { 2421c9b2cfb3SJani Nikula 2422c9b2cfb3SJani Nikula push(@export_file_list, @ARGV); 2423c9b2cfb3SJani Nikula 242488c2b57dSJani Nikula foreach (@export_file_list) { 242588c2b57dSJani Nikula chomp; 242688c2b57dSJani Nikula process_export_file($_); 242788c2b57dSJani Nikula } 242888c2b57dSJani Nikula} 242988c2b57dSJani Nikula 24308484baaaSRandy Dunlapforeach (@ARGV) { 24318484baaaSRandy Dunlap chomp; 24328484baaaSRandy Dunlap process_file($_); 24338484baaaSRandy Dunlap} 24348484baaaSRandy Dunlapif ($verbose && $errors) { 24358484baaaSRandy Dunlap print STDERR "$errors errors\n"; 24368484baaaSRandy Dunlap} 24378484baaaSRandy Dunlapif ($verbose && $warnings) { 24388484baaaSRandy Dunlap print STDERR "$warnings warnings\n"; 24398484baaaSRandy Dunlap} 24408484baaaSRandy Dunlap 24412c12c810SPierre-Louis Bossartif ($Werror && $warnings) { 24422c12c810SPierre-Louis Bossart print STDERR "$warnings warnings as Errors\n"; 24432c12c810SPierre-Louis Bossart exit($warnings); 24442c12c810SPierre-Louis Bossart} else { 24452c12c810SPierre-Louis Bossart exit($output_mode eq "none" ? 0 : $errors) 24462c12c810SPierre-Louis Bossart} 24472875f787STomasz Warniełło 24482875f787STomasz Warniełło__END__ 24492875f787STomasz Warniełło 24502875f787STomasz Warniełło=head1 OPTIONS 24512875f787STomasz Warniełło 24522875f787STomasz Warniełło=head2 Output format selection (mutually exclusive): 24532875f787STomasz Warniełło 24542875f787STomasz Warniełło=over 8 24552875f787STomasz Warniełło 24562875f787STomasz Warniełło=item -man 24572875f787STomasz Warniełło 24582875f787STomasz WarniełłoOutput troff manual page format. 24592875f787STomasz Warniełło 24602875f787STomasz Warniełło=item -rst 24612875f787STomasz Warniełło 24622875f787STomasz WarniełłoOutput reStructuredText format. This is the default. 24632875f787STomasz Warniełło 24642875f787STomasz Warniełło=item -none 24652875f787STomasz Warniełło 24662875f787STomasz WarniełłoDo not output documentation, only warnings. 24672875f787STomasz Warniełło 24682875f787STomasz Warniełło=back 24692875f787STomasz Warniełło 2470dd803b04STomasz Warniełło=head2 Output format modifiers 2471dd803b04STomasz Warniełło 2472dd803b04STomasz Warniełło=head3 reStructuredText only 2473dd803b04STomasz Warniełło 2474dd803b04STomasz Warniełło=over 8 2475dd803b04STomasz Warniełło 2476dd803b04STomasz Warniełło=item -sphinx-version VERSION 2477dd803b04STomasz Warniełło 2478dd803b04STomasz WarniełłoUse the ReST C domain dialect compatible with a specific Sphinx Version. 2479dd803b04STomasz Warniełło 2480dd803b04STomasz WarniełłoIf not specified, kernel-doc will auto-detect using the sphinx-build version 2481dd803b04STomasz Warniełłofound on PATH. 2482dd803b04STomasz Warniełło 2483dd803b04STomasz Warniełło=back 2484dd803b04STomasz Warniełło 24859c77f108STomasz Warniełło=head2 Output selection (mutually exclusive): 24869c77f108STomasz Warniełło 24879c77f108STomasz Warniełło=over 8 24889c77f108STomasz Warniełło 24899c77f108STomasz Warniełło=item -export 24909c77f108STomasz Warniełło 24919c77f108STomasz WarniełłoOnly output documentation for the symbols that have been exported using 2492632ce137SJason GunthorpeEXPORT_SYMBOL() and related macros in any input FILE or -export-file FILE. 24939c77f108STomasz Warniełło 24949c77f108STomasz Warniełło=item -internal 24959c77f108STomasz Warniełło 24969c77f108STomasz WarniełłoOnly output documentation for the symbols that have NOT been exported using 2497632ce137SJason GunthorpeEXPORT_SYMBOL() and related macros in any input FILE or -export-file FILE. 24989c77f108STomasz Warniełło 24999c77f108STomasz Warniełło=item -function NAME 25009c77f108STomasz Warniełło 25019c77f108STomasz WarniełłoOnly output documentation for the given function or DOC: section title. 25029c77f108STomasz WarniełłoAll other functions and DOC: sections are ignored. 25039c77f108STomasz Warniełło 25049c77f108STomasz WarniełłoMay be specified multiple times. 25059c77f108STomasz Warniełło 25069c77f108STomasz Warniełło=item -nosymbol NAME 25079c77f108STomasz Warniełło 25089c77f108STomasz WarniełłoExclude the specified symbol from the output documentation. 25099c77f108STomasz Warniełło 25109c77f108STomasz WarniełłoMay be specified multiple times. 25119c77f108STomasz Warniełło 25129c77f108STomasz Warniełło=back 25139c77f108STomasz Warniełło 2514c15de5a1STomasz Warniełło=head2 Output selection modifiers: 2515c15de5a1STomasz Warniełło 2516c15de5a1STomasz Warniełło=over 8 2517c15de5a1STomasz Warniełło 2518c15de5a1STomasz Warniełło=item -no-doc-sections 2519c15de5a1STomasz Warniełło 2520c15de5a1STomasz WarniełłoDo not output DOC: sections. 2521c15de5a1STomasz Warniełło 2522c15de5a1STomasz Warniełło=item -export-file FILE 2523c15de5a1STomasz Warniełło 2524632ce137SJason GunthorpeSpecify an additional FILE in which to look for EXPORT_SYMBOL information. 2525c15de5a1STomasz Warniełło 2526c15de5a1STomasz WarniełłoTo be used with -export or -internal. 2527c15de5a1STomasz Warniełło 2528c15de5a1STomasz WarniełłoMay be specified multiple times. 2529c15de5a1STomasz Warniełło 2530c15de5a1STomasz Warniełło=back 2531c15de5a1STomasz Warniełło 2532c15de5a1STomasz Warniełło=head3 reStructuredText only 2533c15de5a1STomasz Warniełło 2534c15de5a1STomasz Warniełło=over 8 2535c15de5a1STomasz Warniełło 2536c15de5a1STomasz Warniełło=item -enable-lineno 2537c15de5a1STomasz Warniełło 2538b79dfef0SMauro Carvalho ChehabEnable output of .. LINENO lines. 2539c15de5a1STomasz Warniełło 2540c15de5a1STomasz Warniełło=back 2541c15de5a1STomasz Warniełło 2542834cf6b9STomasz Warniełło=head2 Other parameters: 2543834cf6b9STomasz Warniełło 2544834cf6b9STomasz Warniełło=over 8 2545834cf6b9STomasz Warniełło 2546834cf6b9STomasz Warniełło=item -h, -help 2547834cf6b9STomasz Warniełło 2548834cf6b9STomasz WarniełłoPrint this help. 2549834cf6b9STomasz Warniełło 2550834cf6b9STomasz Warniełło=item -v 2551834cf6b9STomasz Warniełło 2552834cf6b9STomasz WarniełłoVerbose output, more warnings and other information. 2553834cf6b9STomasz Warniełło 2554834cf6b9STomasz Warniełło=item -Werror 2555834cf6b9STomasz Warniełło 2556834cf6b9STomasz WarniełłoTreat warnings as errors. 2557834cf6b9STomasz Warniełło 2558834cf6b9STomasz Warniełło=back 2559834cf6b9STomasz Warniełło 25602875f787STomasz Warniełło=cut 2561