xref: /linux-6.15/scripts/kernel-doc (revision b9609ecb)
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 <[email protected]>          ##
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 <[email protected]>	 ##
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 |
29089e06c3SMauro Carvalho Chehab     -rst [-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;
133efa44475SMauro Carvalho Chehab
1348484baaaSRandy Dunlapmy $dohighlight = "";
1358484baaaSRandy Dunlap
1361da177e4SLinus Torvaldsmy $verbose = 0;
1372c12c810SPierre-Louis Bossartmy $Werror = 0;
13856b0f453SJohannes Bergmy $Wreturn = 0;
13956b0f453SJohannes Bergmy $Wshort_desc = 0;
14056b0f453SJohannes Bergmy $Wcontents_before_sections = 0;
141bdfe2be3SMauro Carvalho Chehabmy $output_mode = "rst";
142e314ba31SDaniel Santosmy $output_preformatted = 0;
1434b44595aSJohannes Bergmy $no_doc_sections = 0;
1440b0f5f29SDaniel Vettermy $enable_lineno = 0;
145bdfe2be3SMauro Carvalho Chehabmy @highlights = @highlights_rst;
146bdfe2be3SMauro Carvalho Chehabmy $blankline = $blankline_rst;
1471da177e4SLinus Torvaldsmy $modulename = "Kernel API";
148b6c3f456SJani Nikula
149b6c3f456SJani Nikulause constant {
150b6c3f456SJani Nikula    OUTPUT_ALL          => 0, # output all symbols and doc sections
151b6c3f456SJani Nikula    OUTPUT_INCLUDE      => 1, # output only specified symbols
152eab795ddSMauro Carvalho Chehab    OUTPUT_EXPORTED     => 2, # output exported symbols
153eab795ddSMauro Carvalho Chehab    OUTPUT_INTERNAL     => 3, # output non-exported symbols
154b6c3f456SJani Nikula};
155b6c3f456SJani Nikulamy $output_selection = OUTPUT_ALL;
156b0d60bfbSJonathan Corbetmy $show_not_found = 0;	# No longer used
157b2c4105bSBen Hutchings
15888c2b57dSJani Nikulamy @export_file_list;
15988c2b57dSJani Nikula
160b2c4105bSBen Hutchingsmy @build_time;
161b2c4105bSBen Hutchingsif (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) &&
162b2c4105bSBen Hutchings    (my $seconds = `date -d "${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') {
163b2c4105bSBen Hutchings    @build_time = gmtime($seconds);
164b2c4105bSBen Hutchings} else {
165b2c4105bSBen Hutchings    @build_time = localtime;
166b2c4105bSBen Hutchings}
167b2c4105bSBen Hutchings
1681da177e4SLinus Torvaldsmy $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
1691da177e4SLinus Torvalds                'July', 'August', 'September', 'October',
170b2c4105bSBen Hutchings                'November', 'December')[$build_time[4]] .
171b2c4105bSBen Hutchings    " " . ($build_time[5]+1900);
1721da177e4SLinus Torvalds
1738484baaaSRandy Dunlap# Essentially these are globals.
174b9d97328SRandy Dunlap# They probably want to be tidied up, made more localised or something.
175b9d97328SRandy Dunlap# CAVEAT EMPTOR!  Some of the others I localised may not want to be, which
1761da177e4SLinus Torvalds# could cause "use of undefined value" or other bugs.
1771da177e4SLinus Torvaldsmy ($function, %function_table, %parametertypes, $declaration_purpose);
178eab795ddSMauro Carvalho Chehabmy %nosymbol_table = ();
1790b0f5f29SDaniel Vettermy $declaration_start_line;
1801da177e4SLinus Torvaldsmy ($type, $declaration_name, $return_type);
181ba561b48SMauro Carvalho Chehabmy ($newsection, $newcontents, $prototype, $brcount);
1821da177e4SLinus Torvalds
183c0d3b831SMasahiro Yamadaif (defined($ENV{'KBUILD_VERBOSE'}) && $ENV{'KBUILD_VERBOSE'} =~ '1') {
184c0d3b831SMasahiro Yamada    $verbose = 1;
185bd0e88e5SRandy Dunlap}
186bd0e88e5SRandy Dunlap
1872c12c810SPierre-Louis Bossartif (defined($ENV{'KCFLAGS'})) {
1882c12c810SPierre-Louis Bossart    my $kcflags = "$ENV{'KCFLAGS'}";
1892c12c810SPierre-Louis Bossart
190cf63348bSYujie Liu    if ($kcflags =~ /(\s|^)-Werror(\s|$)/) {
1912c12c810SPierre-Louis Bossart        $Werror = 1;
1922c12c810SPierre-Louis Bossart    }
1932c12c810SPierre-Louis Bossart}
1942c12c810SPierre-Louis Bossart
19556b0f453SJohannes Berg# reading this variable is for backwards compat just in case
19656b0f453SJohannes Berg# someone was calling it with the variable from outside the
19756b0f453SJohannes Berg# kernel's build system
198bed4ed30SLaurent Pinchartif (defined($ENV{'KDOC_WERROR'})) {
199bed4ed30SLaurent Pinchart    $Werror = "$ENV{'KDOC_WERROR'}";
200bed4ed30SLaurent Pinchart}
20156b0f453SJohannes Berg# other environment variables are converted to command-line
20256b0f453SJohannes Berg# arguments in cmd_checkdoc in the build system
203bed4ed30SLaurent Pinchart
2041da177e4SLinus Torvalds# Generated docbook code is inserted in a template at a point where
2051da177e4SLinus Torvalds# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
20693431e06SAlexander A. Klimov# https://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
2071da177e4SLinus Torvalds# We keep track of number of generated entries and generate a dummy
2081da177e4SLinus Torvalds# if needs be to ensure the expanded template can be postprocessed
2091da177e4SLinus Torvalds# into html.
2101da177e4SLinus Torvaldsmy $section_counter = 0;
2111da177e4SLinus Torvalds
2121da177e4SLinus Torvaldsmy $lineprefix="";
2131da177e4SLinus Torvalds
21448af606aSJani Nikula# Parser states
21548af606aSJani Nikulause constant {
21648af606aSJani Nikula    STATE_NORMAL        => 0,        # normal code
21748af606aSJani Nikula    STATE_NAME          => 1,        # looking for function name
21817b78717SJonathan Corbet    STATE_BODY_MAYBE    => 2,        # body - or maybe more description
21917b78717SJonathan Corbet    STATE_BODY          => 3,        # the body of the comment
2200d55d48bSMauro Carvalho Chehab    STATE_BODY_WITH_BLANK_LINE => 4, # the body, which has a blank line
2210d55d48bSMauro Carvalho Chehab    STATE_PROTO         => 5,        # scanning prototype
2220d55d48bSMauro Carvalho Chehab    STATE_DOCBLOCK      => 6,        # documentation block
2230d55d48bSMauro Carvalho Chehab    STATE_INLINE        => 7,        # gathering doc outside main block
22448af606aSJani Nikula};
2251da177e4SLinus Torvaldsmy $state;
226850622dfSRandy Dunlapmy $in_doc_sect;
227d742f24dSJonathan Corbetmy $leading_space;
2281da177e4SLinus Torvalds
22948af606aSJani Nikula# Inline documentation state
23048af606aSJani Nikulause constant {
23148af606aSJani Nikula    STATE_INLINE_NA     => 0, # not applicable ($state != STATE_INLINE)
23248af606aSJani Nikula    STATE_INLINE_NAME   => 1, # looking for member name (@foo:)
23348af606aSJani Nikula    STATE_INLINE_TEXT   => 2, # looking for member documentation
23448af606aSJani Nikula    STATE_INLINE_END    => 3, # done
23548af606aSJani Nikula    STATE_INLINE_ERROR  => 4, # error - Comment without header was found.
23648af606aSJani Nikula                              # Spit a warning as it's not
237a4c6ebedSDanilo Cesar Lemes de Paula                              # proper kernel-doc and ignore the rest.
23848af606aSJani Nikula};
23948af606aSJani Nikulamy $inline_doc_state;
240a4c6ebedSDanilo Cesar Lemes de Paula
2411da177e4SLinus Torvalds#declaration types: can be
2421da177e4SLinus Torvalds# 'function', 'struct', 'union', 'enum', 'typedef'
2431da177e4SLinus Torvaldsmy $decl_type;
2441da177e4SLinus Torvalds
24552042e2dSMauro Carvalho Chehab# Name of the kernel-doc identifier for non-DOC markups
24652042e2dSMauro Carvalho Chehabmy $identifier;
24752042e2dSMauro Carvalho Chehab
2481da177e4SLinus Torvaldsmy $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
2491da177e4SLinus Torvaldsmy $doc_end = '\*/';
2501da177e4SLinus Torvaldsmy $doc_com = '\s*\*\s*';
25112ae6779SDaniel Santosmy $doc_com_body = '\s*\* ?';
2521da177e4SLinus Torvaldsmy $doc_decl = $doc_com . '(\w+)';
253f624adefSJani Nikula# @params and a strictly limited set of supported section names
254212209cfSJonathan Corbet# Specifically:
255212209cfSJonathan Corbet#   Match @word:
256212209cfSJonathan Corbet#	  @...:
257212209cfSJonathan Corbet#         @{section-name}:
258212209cfSJonathan Corbet# while trying to not match literal block starts like "example::"
259212209cfSJonathan Corbet#
2608569de68SJonathan Corbetmy $doc_sect = $doc_com .
261212209cfSJonathan Corbet    '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:([^:].*)?$';
26212ae6779SDaniel Santosmy $doc_content = $doc_com_body . '(.*)';
2631da177e4SLinus Torvaldsmy $doc_block = $doc_com . 'DOC:\s*(.*)?';
26448af606aSJani Nikulamy $doc_inline_start = '^\s*/\*\*\s*$';
265fe7bc493SMauro Carvalho Chehabmy $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.]*\s*):(.*)';
26648af606aSJani Nikulamy $doc_inline_end = '^\s*\*/\s*$';
2670c9aa209SJani Nikulamy $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$';
26886ae2e38SJani Nikulamy $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;';
269d9339496SAkira Yokosawamy $export_symbol_ns = '^\s*EXPORT_SYMBOL_NS(_GPL)?\s*\(\s*(\w+)\s*,\s*"\S+"\)\s*;';
270e86bdb24SAditya Srivastavamy $function_pointer = qr{([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)};
271e86bdb24SAditya Srivastavamy $attribute = qr{__attribute__\s*\(\([a-z0-9,_\*\s\(\)]*\)\)}i;
2721da177e4SLinus Torvalds
2731da177e4SLinus Torvaldsmy %parameterdescs;
2740b0f5f29SDaniel Vettermy %parameterdesc_start_lines;
2751da177e4SLinus Torvaldsmy @parameterlist;
2761da177e4SLinus Torvaldsmy %sections;
2771da177e4SLinus Torvaldsmy @sectionlist;
2780b0f5f29SDaniel Vettermy %section_start_lines;
279a1d94aa5SRandy Dunlapmy $sectcheck;
280a1d94aa5SRandy Dunlapmy $struct_actual;
2811da177e4SLinus Torvalds
2821da177e4SLinus Torvaldsmy $contents = "";
2830b0f5f29SDaniel Vettermy $new_start_line = 0;
284f624adefSJani Nikula
285f624adefSJani Nikula# the canonical section names. see also $doc_sect above.
2861da177e4SLinus Torvaldsmy $section_default = "Description";	# default section
2871da177e4SLinus Torvaldsmy $section_intro = "Introduction";
2881da177e4SLinus Torvaldsmy $section = $section_default;
2891da177e4SLinus Torvaldsmy $section_context = "Context";
2904092bac7SYacine Belkadimy $section_return = "Return";
2911da177e4SLinus Torvalds
2921da177e4SLinus Torvaldsmy $undescribed = "-- undescribed --";
2931da177e4SLinus Torvalds
2941da177e4SLinus Torvaldsreset_state();
2951da177e4SLinus Torvalds
296b031ac4eSMauro Carvalho Chehabwhile ($ARGV[0] =~ m/^--?(.*)/) {
297b031ac4eSMauro Carvalho Chehab    my $cmd = $1;
298b031ac4eSMauro Carvalho Chehab    shift @ARGV;
299b031ac4eSMauro Carvalho Chehab    if ($cmd eq "man") {
3001da177e4SLinus Torvalds        $output_mode = "man";
3014d732701SDanilo Cesar Lemes de Paula        @highlights = @highlights_man;
3021da177e4SLinus Torvalds        $blankline = $blankline_man;
303b031ac4eSMauro Carvalho Chehab    } elsif ($cmd eq "rst") {
304c0d1b6eeSJonathan Corbet        $output_mode = "rst";
305c0d1b6eeSJonathan Corbet        @highlights = @highlights_rst;
306c0d1b6eeSJonathan Corbet        $blankline = $blankline_rst;
307b031ac4eSMauro Carvalho Chehab    } elsif ($cmd eq "none") {
3083a025e1dSMatthew Wilcox        $output_mode = "none";
309b031ac4eSMauro Carvalho Chehab    } elsif ($cmd eq "module") { # not needed for XML, inherits from calling document
3101da177e4SLinus Torvalds        $modulename = shift @ARGV;
311b031ac4eSMauro Carvalho Chehab    } elsif ($cmd eq "function") { # to only output specific functions
312b6c3f456SJani Nikula        $output_selection = OUTPUT_INCLUDE;
3131da177e4SLinus Torvalds        $function = shift @ARGV;
3141da177e4SLinus Torvalds        $function_table{$function} = 1;
315eab795ddSMauro Carvalho Chehab    } elsif ($cmd eq "nosymbol") { # Exclude specific symbols
316eab795ddSMauro Carvalho Chehab        my $symbol = shift @ARGV;
317eab795ddSMauro Carvalho Chehab        $nosymbol_table{$symbol} = 1;
318b031ac4eSMauro Carvalho Chehab    } elsif ($cmd eq "export") { # only exported symbols
319b6c3f456SJani Nikula        $output_selection = OUTPUT_EXPORTED;
320da9726ecSJani Nikula        %function_table = ();
321b031ac4eSMauro Carvalho Chehab    } elsif ($cmd eq "internal") { # only non-exported symbols
322b6c3f456SJani Nikula        $output_selection = OUTPUT_INTERNAL;
323da9726ecSJani Nikula        %function_table = ();
324b031ac4eSMauro Carvalho Chehab    } elsif ($cmd eq "export-file") {
32588c2b57dSJani Nikula        my $file = shift @ARGV;
32688c2b57dSJani Nikula        push(@export_file_list, $file);
327b031ac4eSMauro Carvalho Chehab    } elsif ($cmd eq "v") {
3281da177e4SLinus Torvalds        $verbose = 1;
3292c12c810SPierre-Louis Bossart    } elsif ($cmd eq "Werror") {
3302c12c810SPierre-Louis Bossart        $Werror = 1;
33156b0f453SJohannes Berg    } elsif ($cmd eq "Wreturn") {
33256b0f453SJohannes Berg        $Wreturn = 1;
333dcd39fa2SAndy Shevchenko    } elsif ($cmd eq "Wshort-desc" or $cmd eq "Wshort-description") {
33456b0f453SJohannes Berg        $Wshort_desc = 1;
33556b0f453SJohannes Berg    } elsif ($cmd eq "Wcontents-before-sections") {
33656b0f453SJohannes Berg        $Wcontents_before_sections = 1;
33756b0f453SJohannes Berg    } elsif ($cmd eq "Wall") {
33856b0f453SJohannes Berg        $Wreturn = 1;
33956b0f453SJohannes Berg        $Wshort_desc = 1;
34056b0f453SJohannes Berg        $Wcontents_before_sections = 1;
341b031ac4eSMauro Carvalho Chehab    } elsif (($cmd eq "h") || ($cmd eq "help")) {
342252b47daSTomasz Warniełło        pod2usage(-exitval => 0, -verbose => 2);
343b031ac4eSMauro Carvalho Chehab    } elsif ($cmd eq 'no-doc-sections') {
3444b44595aSJohannes Berg        $no_doc_sections = 1;
345b031ac4eSMauro Carvalho Chehab    } elsif ($cmd eq 'enable-lineno') {
3460b0f5f29SDaniel Vetter        $enable_lineno = 1;
347b031ac4eSMauro Carvalho Chehab    } elsif ($cmd eq 'show-not-found') {
348b0d60bfbSJonathan Corbet        $show_not_found = 1;  # A no-op but don't fail
349b031ac4eSMauro Carvalho Chehab    } else {
350b031ac4eSMauro Carvalho Chehab        # Unknown argument
35143caf1a6STomasz Warniełło        pod2usage(
35243caf1a6STomasz Warniełło            -message => "Argument unknown!\n",
35343caf1a6STomasz Warniełło            -exitval => 1,
35443caf1a6STomasz Warniełło            -verbose => 99,
35543caf1a6STomasz Warniełło            -sections => 'SYNOPSIS',
35643caf1a6STomasz Warniełło            -output => \*STDERR,
35743caf1a6STomasz Warniełło            );
358e334f873SAkira Yokosawa    }
359e334f873SAkira Yokosawa    if ($#ARGV < 0){
360e334f873SAkira Yokosawa        pod2usage(
361e334f873SAkira Yokosawa            -message => "FILE argument missing\n",
362e334f873SAkira Yokosawa            -exitval => 1,
363e334f873SAkira Yokosawa            -verbose => 99,
364e334f873SAkira Yokosawa            -sections => 'SYNOPSIS',
365e334f873SAkira Yokosawa            -output => \*STDERR,
366e334f873SAkira Yokosawa            );
3671da177e4SLinus Torvalds    }
3681da177e4SLinus Torvalds}
3691da177e4SLinus Torvalds
3708484baaaSRandy Dunlap# continue execution near EOF;
3718484baaaSRandy Dunlap
372efa44475SMauro Carvalho Chehabsub findprog($)
373efa44475SMauro Carvalho Chehab{
374efa44475SMauro Carvalho Chehab    foreach(split(/:/, $ENV{PATH})) {
375efa44475SMauro Carvalho Chehab        return "$_/$_[0]" if(-x "$_/$_[0]");
376efa44475SMauro Carvalho Chehab    }
377efa44475SMauro Carvalho Chehab}
378efa44475SMauro Carvalho Chehab
37953f049faSBorislav Petkov# get kernel version from env
38053f049faSBorislav Petkovsub get_kernel_version() {
3811b9bc22dSJohannes Berg    my $version = 'unknown kernel version';
38253f049faSBorislav Petkov
38353f049faSBorislav Petkov    if (defined($ENV{'KERNELVERSION'})) {
38453f049faSBorislav Petkov        $version = $ENV{'KERNELVERSION'};
38553f049faSBorislav Petkov    }
38653f049faSBorislav Petkov    return $version;
38753f049faSBorislav Petkov}
3881da177e4SLinus Torvalds
3890b0f5f29SDaniel Vetter#
3900b0f5f29SDaniel Vettersub print_lineno {
3910b0f5f29SDaniel Vetter    my $lineno = shift;
3920b0f5f29SDaniel Vetter    if ($enable_lineno && defined($lineno)) {
393b79dfef0SMauro Carvalho Chehab        print ".. LINENO " . $lineno . "\n";
3940b0f5f29SDaniel Vetter    }
3950b0f5f29SDaniel Vetter}
396df4bf98eSNiklas Söderlund
397df4bf98eSNiklas Söderlundsub emit_warning {
398df4bf98eSNiklas Söderlund    my $location = shift;
399df4bf98eSNiklas Söderlund    my $msg = shift;
400df4bf98eSNiklas Söderlund    print STDERR "$location: warning: $msg";
401df4bf98eSNiklas Söderlund    ++$warnings;
402df4bf98eSNiklas Söderlund}
4031da177e4SLinus Torvalds##
4041da177e4SLinus Torvalds# dumps section contents to arrays/hashes intended for that purpose.
4051da177e4SLinus Torvalds#
4061da177e4SLinus Torvaldssub dump_section {
40794dc7ad5SRandy Dunlap    my $file = shift;
4081da177e4SLinus Torvalds    my $name = shift;
4091da177e4SLinus Torvalds    my $contents = join "\n", @_;
4101da177e4SLinus Torvalds
41113901ef2SJani Nikula    if ($name =~ m/$type_param/) {
4121da177e4SLinus Torvalds        $name = $1;
4131da177e4SLinus Torvalds        $parameterdescs{$name} = $contents;
414a1d94aa5SRandy Dunlap        $sectcheck = $sectcheck . $name . " ";
4150b0f5f29SDaniel Vetter        $parameterdesc_start_lines{$name} = $new_start_line;
4160b0f5f29SDaniel Vetter        $new_start_line = 0;
417ced69090SRandy Dunlap    } elsif ($name eq "@\.\.\.") {
418ced69090SRandy Dunlap        $name = "...";
419ced69090SRandy Dunlap        $parameterdescs{$name} = $contents;
420a1d94aa5SRandy Dunlap        $sectcheck = $sectcheck . $name . " ";
4210b0f5f29SDaniel Vetter        $parameterdesc_start_lines{$name} = $new_start_line;
4220b0f5f29SDaniel Vetter        $new_start_line = 0;
4231da177e4SLinus Torvalds    } else {
42494dc7ad5SRandy Dunlap        if (defined($sections{$name}) && ($sections{$name} ne "")) {
42595b6be9dSJani Nikula            # Only warn on user specified duplicate section names.
42695b6be9dSJani Nikula            if ($name ne $section_default) {
427df4bf98eSNiklas Söderlund                emit_warning("${file}:$.", "duplicate section name '$name'\n");
42895b6be9dSJani Nikula            }
42932217761SJani Nikula            $sections{$name} .= $contents;
43032217761SJani Nikula        } else {
4311da177e4SLinus Torvalds            $sections{$name} = $contents;
4321da177e4SLinus Torvalds            push @sectionlist, $name;
4330b0f5f29SDaniel Vetter            $section_start_lines{$name} = $new_start_line;
4340b0f5f29SDaniel Vetter            $new_start_line = 0;
4351da177e4SLinus Torvalds        }
4361da177e4SLinus Torvalds    }
43732217761SJani Nikula}
4381da177e4SLinus Torvalds
4391da177e4SLinus Torvalds##
440b112e0f7SJohannes Berg# dump DOC: section after checking that it should go out
441b112e0f7SJohannes Berg#
442b112e0f7SJohannes Bergsub dump_doc_section {
44394dc7ad5SRandy Dunlap    my $file = shift;
444b112e0f7SJohannes Berg    my $name = shift;
445b112e0f7SJohannes Berg    my $contents = join "\n", @_;
446b112e0f7SJohannes Berg
4474b44595aSJohannes Berg    if ($no_doc_sections) {
4484b44595aSJohannes Berg        return;
4494b44595aSJohannes Berg    }
4504b44595aSJohannes Berg
451eab795ddSMauro Carvalho Chehab    return if (defined($nosymbol_table{$name}));
452eab795ddSMauro Carvalho Chehab
453b6c3f456SJani Nikula    if (($output_selection == OUTPUT_ALL) ||
454eab795ddSMauro Carvalho Chehab        (($output_selection == OUTPUT_INCLUDE) &&
455eab795ddSMauro Carvalho Chehab         defined($function_table{$name})))
456b112e0f7SJohannes Berg    {
45794dc7ad5SRandy Dunlap        dump_section($file, $name, $contents);
458b112e0f7SJohannes Berg        output_blockhead({'sectionlist' => \@sectionlist,
459b112e0f7SJohannes Berg                          'sections' => \%sections,
460b112e0f7SJohannes Berg                          'module' => $modulename,
461b6c3f456SJani Nikula                          'content-only' => ($output_selection != OUTPUT_ALL), });
462b112e0f7SJohannes Berg    }
463b112e0f7SJohannes Berg}
464b112e0f7SJohannes Berg
465b112e0f7SJohannes Berg##
4661da177e4SLinus Torvalds# output function
4671da177e4SLinus Torvalds#
4681da177e4SLinus Torvalds# parameterdescs, a hash.
4691da177e4SLinus Torvalds#  function => "function name"
4701da177e4SLinus Torvalds#  parameterlist => @list of parameters
4711da177e4SLinus Torvalds#  parameterdescs => %parameter descriptions
4721da177e4SLinus Torvalds#  sectionlist => @list of sections
473a21217daSRandy Dunlap#  sections => %section descriptions
4741da177e4SLinus Torvalds#
4751da177e4SLinus Torvalds
4761da177e4SLinus Torvaldssub output_highlight {
4771da177e4SLinus Torvalds    my $contents = join "\n",@_;
4781da177e4SLinus Torvalds    my $line;
4791da177e4SLinus Torvalds
4801da177e4SLinus Torvalds#   DEBUG
4811da177e4SLinus Torvalds#   if (!defined $contents) {
4821da177e4SLinus Torvalds#	use Carp;
4831da177e4SLinus Torvalds#	confess "output_highlight got called with no args?\n";
4841da177e4SLinus Torvalds#   }
4851da177e4SLinus Torvalds
4863eb014a1SRandy Dunlap#   print STDERR "contents b4:$contents\n";
4871da177e4SLinus Torvalds    eval $dohighlight;
4881da177e4SLinus Torvalds    die $@ if $@;
4893eb014a1SRandy Dunlap#   print STDERR "contents af:$contents\n";
4903eb014a1SRandy Dunlap
4911da177e4SLinus Torvalds    foreach $line (split "\n", $contents) {
49212ae6779SDaniel Santos        if (! $output_preformatted) {
49312ae6779SDaniel Santos            $line =~ s/^\s*//;
49412ae6779SDaniel Santos        }
4951da177e4SLinus Torvalds        if ($line eq ""){
496e314ba31SDaniel Santos            if (! $output_preformatted) {
4970bba924cSJonathan Corbet                print $lineprefix, $blankline;
498e314ba31SDaniel Santos            }
4991da177e4SLinus Torvalds        } else {
500cdccb316SRandy Dunlap            if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
501cdccb316SRandy Dunlap                print "\\&$line";
502cdccb316SRandy Dunlap            } else {
5031da177e4SLinus Torvalds                print $lineprefix, $line;
5041da177e4SLinus Torvalds            }
505cdccb316SRandy Dunlap        }
5061da177e4SLinus Torvalds        print "\n";
5071da177e4SLinus Torvalds    }
5081da177e4SLinus Torvalds}
5091da177e4SLinus Torvalds
5101da177e4SLinus Torvalds##
5111da177e4SLinus Torvalds# output function in man
5121da177e4SLinus Torvaldssub output_function_man(%) {
5131da177e4SLinus Torvalds    my %args = %{$_[0]};
5141da177e4SLinus Torvalds    my ($parameter, $section);
5151da177e4SLinus Torvalds    my $count;
516bb8fd09eSRandy Dunlap    my $func_macro = $args{'func_macro'};
517bb8fd09eSRandy Dunlap    my $paramcount = $#{$args{'parameterlist'}}; # -1 is empty
5181da177e4SLinus Torvalds
5191da177e4SLinus Torvalds    print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
5201da177e4SLinus Torvalds
5211da177e4SLinus Torvalds    print ".SH NAME\n";
5221da177e4SLinus Torvalds    print $args{'function'} . " \\- " . $args{'purpose'} . "\n";
5231da177e4SLinus Torvalds
5241da177e4SLinus Torvalds    print ".SH SYNOPSIS\n";
525a21217daSRandy Dunlap    if ($args{'functiontype'} ne "") {
5261da177e4SLinus Torvalds        print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n";
527a21217daSRandy Dunlap    } else {
528a21217daSRandy Dunlap        print ".B \"" . $args{'function'} . "\n";
529a21217daSRandy Dunlap    }
5301da177e4SLinus Torvalds    $count = 0;
5311da177e4SLinus Torvalds    my $parenth = "(";
5321da177e4SLinus Torvalds    my $post = ",";
5331da177e4SLinus Torvalds    foreach my $parameter (@{$args{'parameterlist'}}) {
5341da177e4SLinus Torvalds        if ($count == $#{$args{'parameterlist'}}) {
5351da177e4SLinus Torvalds            $post = ");";
5361da177e4SLinus Torvalds        }
5371da177e4SLinus Torvalds        $type = $args{'parametertypes'}{$parameter};
538e86bdb24SAditya Srivastava        if ($type =~ m/$function_pointer/) {
5391da177e4SLinus Torvalds            # pointer-to-function
540ed8348e2SMauro Carvalho Chehab            print ".BI \"" . $parenth . $1 . "\" " . " \") (" . $2 . ")" . $post . "\"\n";
5411da177e4SLinus Torvalds        } else {
5421da177e4SLinus Torvalds            $type =~ s/([^\*])$/$1 /;
543ed8348e2SMauro Carvalho Chehab            print ".BI \"" . $parenth . $type . "\" " . " \"" . $post . "\"\n";
5441da177e4SLinus Torvalds        }
5451da177e4SLinus Torvalds        $count++;
5461da177e4SLinus Torvalds        $parenth = "";
5471da177e4SLinus Torvalds    }
5481da177e4SLinus Torvalds
549bb8fd09eSRandy Dunlap    $paramcount = $#{$args{'parameterlist'}}; # -1 is empty
550bb8fd09eSRandy Dunlap    if ($paramcount >= 0) {
5511da177e4SLinus Torvalds    	print ".SH ARGUMENTS\n";
552bb8fd09eSRandy Dunlap	}
5531da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
5541da177e4SLinus Torvalds        my $parameter_name = $parameter;
5551da177e4SLinus Torvalds        $parameter_name =~ s/\[.*//;
5561da177e4SLinus Torvalds
5571da177e4SLinus Torvalds        print ".IP \"" . $parameter . "\" 12\n";
5581da177e4SLinus Torvalds        output_highlight($args{'parameterdescs'}{$parameter_name});
5591da177e4SLinus Torvalds    }
5601da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
5611da177e4SLinus Torvalds        print ".SH \"", uc $section, "\"\n";
5621da177e4SLinus Torvalds        output_highlight($args{'sections'}{$section});
5631da177e4SLinus Torvalds    }
5641da177e4SLinus Torvalds}
5651da177e4SLinus Torvalds
5661da177e4SLinus Torvalds##
5671da177e4SLinus Torvalds# output enum in man
5681da177e4SLinus Torvaldssub output_enum_man(%) {
5691da177e4SLinus Torvalds    my %args = %{$_[0]};
5701da177e4SLinus Torvalds    my ($parameter, $section);
5711da177e4SLinus Torvalds    my $count;
5721da177e4SLinus Torvalds
5731da177e4SLinus Torvalds    print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
5741da177e4SLinus Torvalds
5751da177e4SLinus Torvalds    print ".SH NAME\n";
5761da177e4SLinus Torvalds    print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n";
5771da177e4SLinus Torvalds
5781da177e4SLinus Torvalds    print ".SH SYNOPSIS\n";
5791da177e4SLinus Torvalds    print "enum " . $args{'enum'} . " {\n";
5801da177e4SLinus Torvalds    $count = 0;
5811da177e4SLinus Torvalds    foreach my $parameter (@{$args{'parameterlist'}}) {
5821da177e4SLinus Torvalds        print ".br\n.BI \"    $parameter\"\n";
5831da177e4SLinus Torvalds        if ($count == $#{$args{'parameterlist'}}) {
5841da177e4SLinus Torvalds            print "\n};\n";
5851da177e4SLinus Torvalds            last;
586af404fb1SVegard Nossum        } else {
5871da177e4SLinus Torvalds            print ", \n.br\n";
5881da177e4SLinus Torvalds        }
5891da177e4SLinus Torvalds        $count++;
5901da177e4SLinus Torvalds    }
5911da177e4SLinus Torvalds
5921da177e4SLinus Torvalds    print ".SH Constants\n";
5931da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
5941da177e4SLinus Torvalds        my $parameter_name = $parameter;
5951da177e4SLinus Torvalds        $parameter_name =~ s/\[.*//;
5961da177e4SLinus Torvalds
5971da177e4SLinus Torvalds        print ".IP \"" . $parameter . "\" 12\n";
5981da177e4SLinus Torvalds        output_highlight($args{'parameterdescs'}{$parameter_name});
5991da177e4SLinus Torvalds    }
6001da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
6011da177e4SLinus Torvalds        print ".SH \"$section\"\n";
6021da177e4SLinus Torvalds        output_highlight($args{'sections'}{$section});
6031da177e4SLinus Torvalds    }
6041da177e4SLinus Torvalds}
6051da177e4SLinus Torvalds
6061da177e4SLinus Torvalds##
6071da177e4SLinus Torvalds# output struct in man
6081da177e4SLinus Torvaldssub output_struct_man(%) {
6091da177e4SLinus Torvalds    my %args = %{$_[0]};
6101da177e4SLinus Torvalds    my ($parameter, $section);
6111da177e4SLinus Torvalds
6121da177e4SLinus Torvalds    print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n";
6131da177e4SLinus Torvalds
6141da177e4SLinus Torvalds    print ".SH NAME\n";
6151da177e4SLinus Torvalds    print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n";
6161da177e4SLinus Torvalds
6178ad72163SMauro Carvalho Chehab    my $declaration = $args{'definition'};
6188ad72163SMauro Carvalho Chehab    $declaration =~ s/\t/  /g;
6198ad72163SMauro Carvalho Chehab    $declaration =~ s/\n/"\n.br\n.BI \"/g;
6201da177e4SLinus Torvalds    print ".SH SYNOPSIS\n";
6211da177e4SLinus Torvalds    print $args{'type'} . " " . $args{'struct'} . " {\n.br\n";
6228ad72163SMauro Carvalho Chehab    print ".BI \"$declaration\n};\n.br\n\n";
6231da177e4SLinus Torvalds
624c51d3dacSRandy Dunlap    print ".SH Members\n";
6251da177e4SLinus Torvalds    foreach $parameter (@{$args{'parameterlist'}}) {
6261da177e4SLinus Torvalds        ($parameter =~ /^#/) && next;
6271da177e4SLinus Torvalds
6281da177e4SLinus Torvalds        my $parameter_name = $parameter;
6291da177e4SLinus Torvalds        $parameter_name =~ s/\[.*//;
6301da177e4SLinus Torvalds
6311da177e4SLinus Torvalds        ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
6321da177e4SLinus Torvalds        print ".IP \"" . $parameter . "\" 12\n";
6331da177e4SLinus Torvalds        output_highlight($args{'parameterdescs'}{$parameter_name});
6341da177e4SLinus Torvalds    }
6351da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
6361da177e4SLinus Torvalds        print ".SH \"$section\"\n";
6371da177e4SLinus Torvalds        output_highlight($args{'sections'}{$section});
6381da177e4SLinus Torvalds    }
6391da177e4SLinus Torvalds}
6401da177e4SLinus Torvalds
6411da177e4SLinus Torvalds##
6421da177e4SLinus Torvalds# output typedef in man
6431da177e4SLinus Torvaldssub output_typedef_man(%) {
6441da177e4SLinus Torvalds    my %args = %{$_[0]};
6451da177e4SLinus Torvalds    my ($parameter, $section);
6461da177e4SLinus Torvalds
6471da177e4SLinus Torvalds    print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
6481da177e4SLinus Torvalds
6491da177e4SLinus Torvalds    print ".SH NAME\n";
6501da177e4SLinus Torvalds    print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n";
6511da177e4SLinus Torvalds
6521da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
6531da177e4SLinus Torvalds        print ".SH \"$section\"\n";
6541da177e4SLinus Torvalds        output_highlight($args{'sections'}{$section});
6551da177e4SLinus Torvalds    }
6561da177e4SLinus Torvalds}
6571da177e4SLinus Torvalds
658b112e0f7SJohannes Bergsub output_blockhead_man(%) {
6591da177e4SLinus Torvalds    my %args = %{$_[0]};
6601da177e4SLinus Torvalds    my ($parameter, $section);
6611da177e4SLinus Torvalds    my $count;
6621da177e4SLinus Torvalds
6631da177e4SLinus Torvalds    print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
6641da177e4SLinus Torvalds
6651da177e4SLinus Torvalds    foreach $section (@{$args{'sectionlist'}}) {
6661da177e4SLinus Torvalds        print ".SH \"$section\"\n";
6671da177e4SLinus Torvalds        output_highlight($args{'sections'}{$section});
6681da177e4SLinus Torvalds    }
6691da177e4SLinus Torvalds}
6701da177e4SLinus Torvalds
6711da177e4SLinus Torvalds##
672c0d1b6eeSJonathan Corbet# output in restructured text
673c0d1b6eeSJonathan Corbet#
674c0d1b6eeSJonathan Corbet
675c0d1b6eeSJonathan Corbet#
676c0d1b6eeSJonathan Corbet# This could use some work; it's used to output the DOC: sections, and
677c0d1b6eeSJonathan Corbet# starts by putting out the name of the doc section itself, but that tends
678c0d1b6eeSJonathan Corbet# to duplicate a header already in the template file.
679c0d1b6eeSJonathan Corbet#
680c0d1b6eeSJonathan Corbetsub output_blockhead_rst(%) {
681c0d1b6eeSJonathan Corbet    my %args = %{$_[0]};
682c0d1b6eeSJonathan Corbet    my ($parameter, $section);
683c0d1b6eeSJonathan Corbet
684c0d1b6eeSJonathan Corbet    foreach $section (@{$args{'sectionlist'}}) {
685eab795ddSMauro Carvalho Chehab        next if (defined($nosymbol_table{$section}));
686eab795ddSMauro Carvalho Chehab
6879e72184bSJani Nikula        if ($output_selection != OUTPUT_INCLUDE) {
68806a755d6SMichal Wajdeczko            print ".. _$section:\n\n";
689c0d1b6eeSJonathan Corbet            print "**$section**\n\n";
6909e72184bSJani Nikula        }
6910b0f5f29SDaniel Vetter        print_lineno($section_start_lines{$section});
692c0d1b6eeSJonathan Corbet        output_highlight_rst($args{'sections'}{$section});
693c0d1b6eeSJonathan Corbet        print "\n";
694c0d1b6eeSJonathan Corbet    }
695c0d1b6eeSJonathan Corbet}
696c0d1b6eeSJonathan Corbet
697af250290SJonathan Corbet#
698af250290SJonathan Corbet# Apply the RST highlights to a sub-block of text.
699af250290SJonathan Corbet#
700af250290SJonathan Corbetsub highlight_block($) {
701af250290SJonathan Corbet    # The dohighlight kludge requires the text be called $contents
702af250290SJonathan Corbet    my $contents = shift;
703c0d1b6eeSJonathan Corbet    eval $dohighlight;
704c0d1b6eeSJonathan Corbet    die $@ if $@;
705af250290SJonathan Corbet    return $contents;
706af250290SJonathan Corbet}
707c0d1b6eeSJonathan Corbet
708af250290SJonathan Corbet#
709af250290SJonathan Corbet# Regexes used only here.
710af250290SJonathan Corbet#
711af250290SJonathan Corbetmy $sphinx_literal = '^[^.].*::$';
712af250290SJonathan Corbetmy $sphinx_cblock = '^\.\.\ +code-block::';
713af250290SJonathan Corbet
714af250290SJonathan Corbetsub output_highlight_rst {
715af250290SJonathan Corbet    my $input = join "\n",@_;
716af250290SJonathan Corbet    my $output = "";
717af250290SJonathan Corbet    my $line;
718af250290SJonathan Corbet    my $in_literal = 0;
719af250290SJonathan Corbet    my $litprefix;
720af250290SJonathan Corbet    my $block = "";
721af250290SJonathan Corbet
722af250290SJonathan Corbet    foreach $line (split "\n",$input) {
723af250290SJonathan Corbet        #
724af250290SJonathan Corbet        # If we're in a literal block, see if we should drop out
725af250290SJonathan Corbet        # of it.  Otherwise pass the line straight through unmunged.
726af250290SJonathan Corbet        #
727af250290SJonathan Corbet        if ($in_literal) {
728af250290SJonathan Corbet            if (! ($line =~ /^\s*$/)) {
729af250290SJonathan Corbet                #
730af250290SJonathan Corbet                # If this is the first non-blank line in a literal
731af250290SJonathan Corbet                # block we need to figure out what the proper indent is.
732af250290SJonathan Corbet                #
733af250290SJonathan Corbet                if ($litprefix eq "") {
734af250290SJonathan Corbet                    $line =~ /^(\s*)/;
735af250290SJonathan Corbet                    $litprefix = '^' . $1;
736af250290SJonathan Corbet                    $output .= $line . "\n";
737af250290SJonathan Corbet                } elsif (! ($line =~ /$litprefix/)) {
738af250290SJonathan Corbet                    $in_literal = 0;
739af250290SJonathan Corbet                } else {
740af250290SJonathan Corbet                    $output .= $line . "\n";
741af250290SJonathan Corbet                }
742af250290SJonathan Corbet            } else {
743af250290SJonathan Corbet                $output .= $line . "\n";
744af250290SJonathan Corbet            }
745af250290SJonathan Corbet        }
746af250290SJonathan Corbet        #
747af250290SJonathan Corbet        # Not in a literal block (or just dropped out)
748af250290SJonathan Corbet        #
749af250290SJonathan Corbet        if (! $in_literal) {
750af250290SJonathan Corbet            $block .= $line . "\n";
751af250290SJonathan Corbet            if (($line =~ /$sphinx_literal/) || ($line =~ /$sphinx_cblock/)) {
752af250290SJonathan Corbet                $in_literal = 1;
753af250290SJonathan Corbet                $litprefix = "";
754af250290SJonathan Corbet                $output .= highlight_block($block);
755af250290SJonathan Corbet                $block = ""
756af250290SJonathan Corbet            }
757af250290SJonathan Corbet        }
758af250290SJonathan Corbet    }
759af250290SJonathan Corbet
760af250290SJonathan Corbet    if ($block) {
761af250290SJonathan Corbet        $output .= highlight_block($block);
762af250290SJonathan Corbet    }
763*b9609ecbSMauro Carvalho Chehab
764*b9609ecbSMauro Carvalho Chehab    $output =~ s/^\n+//g;
765*b9609ecbSMauro Carvalho Chehab    $output =~ s/\n+$//g;
766*b9609ecbSMauro Carvalho Chehab
767af250290SJonathan Corbet    foreach $line (split "\n", $output) {
768830066a7SJani Nikula        print $lineprefix . $line . "\n";
769c0d1b6eeSJonathan Corbet    }
770c0d1b6eeSJonathan Corbet}
771c0d1b6eeSJonathan Corbet
772c0d1b6eeSJonathan Corbetsub output_function_rst(%) {
773c0d1b6eeSJonathan Corbet    my %args = %{$_[0]};
774c0d1b6eeSJonathan Corbet    my ($parameter, $section);
775c099ff69SJani Nikula    my $oldprefix = $lineprefix;
776c0d1b6eeSJonathan Corbet
777d3c55a71SVegard Nossum    my $signature = "";
778bb8fd09eSRandy Dunlap    my $func_macro = $args{'func_macro'};
779bb8fd09eSRandy Dunlap    my $paramcount = $#{$args{'parameterlist'}}; # -1 is empty
780bb8fd09eSRandy Dunlap
781bb8fd09eSRandy Dunlap	if ($func_macro) {
782bb8fd09eSRandy Dunlap        $signature = $args{'function'};
783d3c55a71SVegard Nossum	} else {
784bb8fd09eSRandy Dunlap		if ($args{'functiontype'}) {
785bb8fd09eSRandy Dunlap        	$signature = $args{'functiontype'} . " ";
786bb8fd09eSRandy Dunlap		}
787bb8fd09eSRandy Dunlap		$signature .= $args{'function'} . " (";
788d3c55a71SVegard Nossum    }
789d3c55a71SVegard Nossum
790d3c55a71SVegard Nossum    my $count = 0;
791d3c55a71SVegard Nossum    foreach my $parameter (@{$args{'parameterlist'}}) {
792d3c55a71SVegard Nossum        if ($count ne 0) {
793d3c55a71SVegard Nossum            $signature .= ", ";
794d3c55a71SVegard Nossum        }
795d3c55a71SVegard Nossum        $count++;
796d3c55a71SVegard Nossum        $type = $args{'parametertypes'}{$parameter};
797d3c55a71SVegard Nossum
798d3c55a71SVegard Nossum        if ($type =~ m/$function_pointer/) {
799d3c55a71SVegard Nossum            # pointer-to-function
800d3c55a71SVegard Nossum            $signature .= $1 . $parameter . ") (" . $2 . ")";
801d3c55a71SVegard Nossum        } else {
802d3c55a71SVegard Nossum            $signature .= $type;
803d3c55a71SVegard Nossum        }
804d3c55a71SVegard Nossum    }
805d3c55a71SVegard Nossum
806bb8fd09eSRandy Dunlap    if (!$func_macro) {
807d3c55a71SVegard Nossum    	$signature .= ")";
808bb8fd09eSRandy Dunlap    }
809d3c55a71SVegard Nossum
8106e9e4158SMauro Carvalho Chehab    if ($args{'typedef'} || $args{'functiontype'} eq "") {
811e3ad05feSMauro Carvalho Chehab        print ".. c:macro:: ". $args{'function'} . "\n\n";
812e3ad05feSMauro Carvalho Chehab
813e3ad05feSMauro Carvalho Chehab        if ($args{'typedef'}) {
814e3ad05feSMauro Carvalho Chehab            print_lineno($declaration_start_line);
815e3ad05feSMauro Carvalho Chehab            print "   **Typedef**: ";
816e3ad05feSMauro Carvalho Chehab            $lineprefix = "";
817e3ad05feSMauro Carvalho Chehab            output_highlight_rst($args{'purpose'});
8189f6f4c11SVegard Nossum            print "\n\n**Syntax**\n\n";
8199f6f4c11SVegard Nossum            print "  ``$signature``\n\n";
820e3ad05feSMauro Carvalho Chehab        } else {
8219f6f4c11SVegard Nossum            print "``$signature``\n\n";
8229f6f4c11SVegard Nossum        }
8239f6f4c11SVegard Nossum    } else {
8249f6f4c11SVegard Nossum        print ".. c:function:: $signature\n\n";
825e3ad05feSMauro Carvalho Chehab    }
826c0d1b6eeSJonathan Corbet
8276e9e4158SMauro Carvalho Chehab    if (!$args{'typedef'}) {
8280b0f5f29SDaniel Vetter        print_lineno($declaration_start_line);
829c099ff69SJani Nikula        $lineprefix = "   ";
830c099ff69SJani Nikula        output_highlight_rst($args{'purpose'});
831c099ff69SJani Nikula        print "\n";
83282801d06SMauro Carvalho Chehab    }
833c0d1b6eeSJonathan Corbet
834eaf710ceSJonathan Corbet    #
835eaf710ceSJonathan Corbet    # Put our descriptive text into a container (thus an HTML <div>) to help
836eaf710ceSJonathan Corbet    # set the function prototypes apart.
837eaf710ceSJonathan Corbet    #
838c099ff69SJani Nikula    $lineprefix = "  ";
839bb8fd09eSRandy Dunlap	if ($paramcount >= 0) {
840bb8fd09eSRandy Dunlap    	print ".. container:: kernelindent\n\n";
841eaf710ceSJonathan Corbet   		print $lineprefix . "**Parameters**\n\n";
842bb8fd09eSRandy Dunlap    }
843c0d1b6eeSJonathan Corbet    foreach $parameter (@{$args{'parameterlist'}}) {
844c0d1b6eeSJonathan Corbet        my $parameter_name = $parameter;
845ada5f446SGabriel Krisman Bertazi        $parameter_name =~ s/\[.*//;
846c0d1b6eeSJonathan Corbet        $type = $args{'parametertypes'}{$parameter};
847c0d1b6eeSJonathan Corbet
848c0d1b6eeSJonathan Corbet        if ($type ne "") {
849eaf710ceSJonathan Corbet            print $lineprefix . "``$type``\n";
850c0d1b6eeSJonathan Corbet        } else {
851eaf710ceSJonathan Corbet            print $lineprefix . "``$parameter``\n";
852c0d1b6eeSJonathan Corbet        }
8530b0f5f29SDaniel Vetter
8540b0f5f29SDaniel Vetter        print_lineno($parameterdesc_start_lines{$parameter_name});
8550b0f5f29SDaniel Vetter
856eaf710ceSJonathan Corbet        $lineprefix = "    ";
8575e64fa9cSJani Nikula        if (defined($args{'parameterdescs'}{$parameter_name}) &&
8585e64fa9cSJani Nikula            $args{'parameterdescs'}{$parameter_name} ne $undescribed) {
859c0d1b6eeSJonathan Corbet            output_highlight_rst($args{'parameterdescs'}{$parameter_name});
860c0d1b6eeSJonathan Corbet        } else {
861eaf710ceSJonathan Corbet            print $lineprefix . "*undescribed*\n";
862c0d1b6eeSJonathan Corbet        }
863eaf710ceSJonathan Corbet        $lineprefix = "  ";
864c0d1b6eeSJonathan Corbet        print "\n";
865c0d1b6eeSJonathan Corbet    }
866c099ff69SJani Nikula
867c0d1b6eeSJonathan Corbet    output_section_rst(@_);
868eaf710ceSJonathan Corbet    $lineprefix = $oldprefix;
869c0d1b6eeSJonathan Corbet}
870c0d1b6eeSJonathan Corbet
871c0d1b6eeSJonathan Corbetsub output_section_rst(%) {
872c0d1b6eeSJonathan Corbet    my %args = %{$_[0]};
873c0d1b6eeSJonathan Corbet    my $section;
874c0d1b6eeSJonathan Corbet    my $oldprefix = $lineprefix;
875c0d1b6eeSJonathan Corbet
876c0d1b6eeSJonathan Corbet    foreach $section (@{$args{'sectionlist'}}) {
877eaf710ceSJonathan Corbet        print $lineprefix . "**$section**\n\n";
8780b0f5f29SDaniel Vetter        print_lineno($section_start_lines{$section});
879c0d1b6eeSJonathan Corbet        output_highlight_rst($args{'sections'}{$section});
880c0d1b6eeSJonathan Corbet        print "\n";
881c0d1b6eeSJonathan Corbet    }
882c0d1b6eeSJonathan Corbet    print "\n";
883c0d1b6eeSJonathan Corbet}
884c0d1b6eeSJonathan Corbet
885c0d1b6eeSJonathan Corbetsub output_enum_rst(%) {
886c0d1b6eeSJonathan Corbet    my %args = %{$_[0]};
887c0d1b6eeSJonathan Corbet    my ($parameter);
888c099ff69SJani Nikula    my $oldprefix = $lineprefix;
889c0d1b6eeSJonathan Corbet    my $count;
890eaf710ceSJonathan Corbet    my $outer;
89162850976SJani Nikula
892efa44475SMauro Carvalho Chehab    my $name = $args{'enum'};
893efa44475SMauro Carvalho Chehab    print "\n\n.. c:enum:: " . $name . "\n\n";
894089e06c3SMauro Carvalho Chehab
8950b0f5f29SDaniel Vetter    print_lineno($declaration_start_line);
896c099ff69SJani Nikula    $lineprefix = "  ";
897c099ff69SJani Nikula    output_highlight_rst($args{'purpose'});
898c099ff69SJani Nikula    print "\n";
899c0d1b6eeSJonathan Corbet
900eaf710ceSJonathan Corbet    print ".. container:: kernelindent\n\n";
901eaf710ceSJonathan Corbet    $outer = $lineprefix . "  ";
902eaf710ceSJonathan Corbet    $lineprefix = $outer . "  ";
903eaf710ceSJonathan Corbet    print $outer . "**Constants**\n\n";
904c0d1b6eeSJonathan Corbet    foreach $parameter (@{$args{'parameterlist'}}) {
905eaf710ceSJonathan Corbet        print $outer . "``$parameter``\n";
906eaf710ceSJonathan Corbet
907c0d1b6eeSJonathan Corbet        if ($args{'parameterdescs'}{$parameter} ne $undescribed) {
908c0d1b6eeSJonathan Corbet            output_highlight_rst($args{'parameterdescs'}{$parameter});
909c0d1b6eeSJonathan Corbet        } else {
910eaf710ceSJonathan Corbet            print $lineprefix . "*undescribed*\n";
911c0d1b6eeSJonathan Corbet        }
912c0d1b6eeSJonathan Corbet        print "\n";
913c0d1b6eeSJonathan Corbet    }
914eaf710ceSJonathan Corbet    print "\n";
915c0d1b6eeSJonathan Corbet    $lineprefix = $oldprefix;
916c0d1b6eeSJonathan Corbet    output_section_rst(@_);
917c0d1b6eeSJonathan Corbet}
918c0d1b6eeSJonathan Corbet
919c0d1b6eeSJonathan Corbetsub output_typedef_rst(%) {
920c0d1b6eeSJonathan Corbet    my %args = %{$_[0]};
921c0d1b6eeSJonathan Corbet    my ($parameter);
922c099ff69SJani Nikula    my $oldprefix = $lineprefix;
923efa44475SMauro Carvalho Chehab    my $name;
924c0d1b6eeSJonathan Corbet
925efa44475SMauro Carvalho Chehab    $name = $args{'typedef'};
926089e06c3SMauro Carvalho Chehab
92762850976SJani Nikula    print "\n\n.. c:type:: " . $name . "\n\n";
9280b0f5f29SDaniel Vetter    print_lineno($declaration_start_line);
929c099ff69SJani Nikula    $lineprefix = "   ";
930c099ff69SJani Nikula    output_highlight_rst($args{'purpose'});
931c099ff69SJani Nikula    print "\n";
932c0d1b6eeSJonathan Corbet
933c099ff69SJani Nikula    $lineprefix = $oldprefix;
934c0d1b6eeSJonathan Corbet    output_section_rst(@_);
935c0d1b6eeSJonathan Corbet}
936c0d1b6eeSJonathan Corbet
937c0d1b6eeSJonathan Corbetsub output_struct_rst(%) {
938c0d1b6eeSJonathan Corbet    my %args = %{$_[0]};
939c0d1b6eeSJonathan Corbet    my ($parameter);
940c099ff69SJani Nikula    my $oldprefix = $lineprefix;
941c0d1b6eeSJonathan Corbet
942efa44475SMauro Carvalho Chehab    my $name = $args{'struct'};
94372b97d0bSMauro Carvalho Chehab    if ($args{'type'} eq 'union') {
94472b97d0bSMauro Carvalho Chehab        print "\n\n.. c:union:: " . $name . "\n\n";
94572b97d0bSMauro Carvalho Chehab    } else {
946efa44475SMauro Carvalho Chehab        print "\n\n.. c:struct:: " . $name . "\n\n";
947efa44475SMauro Carvalho Chehab    }
948089e06c3SMauro Carvalho Chehab
9490b0f5f29SDaniel Vetter    print_lineno($declaration_start_line);
950c099ff69SJani Nikula    $lineprefix = "  ";
951c099ff69SJani Nikula    output_highlight_rst($args{'purpose'});
952c099ff69SJani Nikula    print "\n";
953c0d1b6eeSJonathan Corbet
954eaf710ceSJonathan Corbet    print ".. container:: kernelindent\n\n";
955eaf710ceSJonathan Corbet    print $lineprefix . "**Definition**::\n\n";
9568ad72163SMauro Carvalho Chehab    my $declaration = $args{'definition'};
957eaf710ceSJonathan Corbet    $lineprefix = $lineprefix . "  ";
958eaf710ceSJonathan Corbet    $declaration =~ s/\t/$lineprefix/g;
959eaf710ceSJonathan Corbet    print $lineprefix . $args{'type'} . " " . $args{'struct'} . " {\n$declaration" . $lineprefix . "};\n\n";
960c0d1b6eeSJonathan Corbet
961c099ff69SJani Nikula    $lineprefix = "  ";
962eaf710ceSJonathan Corbet    print $lineprefix . "**Members**\n\n";
963c0d1b6eeSJonathan Corbet    foreach $parameter (@{$args{'parameterlist'}}) {
964c0d1b6eeSJonathan Corbet        ($parameter =~ /^#/) && next;
965c0d1b6eeSJonathan Corbet
966c0d1b6eeSJonathan Corbet        my $parameter_name = $parameter;
967c0d1b6eeSJonathan Corbet        $parameter_name =~ s/\[.*//;
968c0d1b6eeSJonathan Corbet
969c0d1b6eeSJonathan Corbet        ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
970c0d1b6eeSJonathan Corbet        $type = $args{'parametertypes'}{$parameter};
9710b0f5f29SDaniel Vetter        print_lineno($parameterdesc_start_lines{$parameter_name});
972eaf710ceSJonathan Corbet        print $lineprefix . "``" . $parameter . "``\n";
973eaf710ceSJonathan Corbet        $lineprefix = "    ";
974c0d1b6eeSJonathan Corbet        output_highlight_rst($args{'parameterdescs'}{$parameter_name});
975eaf710ceSJonathan Corbet        $lineprefix = "  ";
976c0d1b6eeSJonathan Corbet        print "\n";
977c0d1b6eeSJonathan Corbet    }
978c0d1b6eeSJonathan Corbet    print "\n";
979c099ff69SJani Nikula
980c099ff69SJani Nikula    $lineprefix = $oldprefix;
981c0d1b6eeSJonathan Corbet    output_section_rst(@_);
982c0d1b6eeSJonathan Corbet}
983c0d1b6eeSJonathan Corbet
9843a025e1dSMatthew Wilcox## none mode output functions
9853a025e1dSMatthew Wilcox
9863a025e1dSMatthew Wilcoxsub output_function_none(%) {
9873a025e1dSMatthew Wilcox}
9883a025e1dSMatthew Wilcox
9893a025e1dSMatthew Wilcoxsub output_enum_none(%) {
9903a025e1dSMatthew Wilcox}
9913a025e1dSMatthew Wilcox
9923a025e1dSMatthew Wilcoxsub output_typedef_none(%) {
9933a025e1dSMatthew Wilcox}
9943a025e1dSMatthew Wilcox
9953a025e1dSMatthew Wilcoxsub output_struct_none(%) {
9963a025e1dSMatthew Wilcox}
9973a025e1dSMatthew Wilcox
9983a025e1dSMatthew Wilcoxsub output_blockhead_none(%) {
9993a025e1dSMatthew Wilcox}
10003a025e1dSMatthew Wilcox
10011da177e4SLinus Torvalds##
100227205744SRandy Dunlap# generic output function for all types (function, struct/union, typedef, enum);
100327205744SRandy Dunlap# calls the generated, variable output_ function name based on
100427205744SRandy Dunlap# functype and output_mode
10051da177e4SLinus Torvaldssub output_declaration {
10061da177e4SLinus Torvalds    no strict 'refs';
10071da177e4SLinus Torvalds    my $name = shift;
10081da177e4SLinus Torvalds    my $functype = shift;
10091da177e4SLinus Torvalds    my $func = "output_${functype}_$output_mode";
1010eab795ddSMauro Carvalho Chehab
1011eab795ddSMauro Carvalho Chehab    return if (defined($nosymbol_table{$name}));
1012eab795ddSMauro Carvalho Chehab
1013b6c3f456SJani Nikula    if (($output_selection == OUTPUT_ALL) ||
1014b6c3f456SJani Nikula        (($output_selection == OUTPUT_INCLUDE ||
1015b6c3f456SJani Nikula          $output_selection == OUTPUT_EXPORTED) &&
101686ae2e38SJani Nikula         defined($function_table{$name})) ||
1017eab795ddSMauro Carvalho Chehab        ($output_selection == OUTPUT_INTERNAL &&
101886ae2e38SJani Nikula         !($functype eq "function" && defined($function_table{$name}))))
10191da177e4SLinus Torvalds    {
10201da177e4SLinus Torvalds        &$func(@_);
10211da177e4SLinus Torvalds        $section_counter++;
10221da177e4SLinus Torvalds    }
10231da177e4SLinus Torvalds}
10241da177e4SLinus Torvalds
10251da177e4SLinus Torvalds##
102627205744SRandy Dunlap# generic output function - calls the right one based on current output mode.
1027b112e0f7SJohannes Bergsub output_blockhead {
10281da177e4SLinus Torvalds    no strict 'refs';
1029b112e0f7SJohannes Berg    my $func = "output_blockhead_" . $output_mode;
10301da177e4SLinus Torvalds    &$func(@_);
10311da177e4SLinus Torvalds    $section_counter++;
10321da177e4SLinus Torvalds}
10331da177e4SLinus Torvalds
10341da177e4SLinus Torvalds##
10351da177e4SLinus Torvalds# takes a declaration (struct, union, enum, typedef) and
10361da177e4SLinus Torvalds# invokes the right handler. NOT called for functions.
10371da177e4SLinus Torvaldssub dump_declaration($$) {
10381da177e4SLinus Torvalds    no strict 'refs';
10391da177e4SLinus Torvalds    my ($prototype, $file) = @_;
10401da177e4SLinus Torvalds    my $func = "dump_" . $decl_type;
10411da177e4SLinus Torvalds    &$func(@_);
10421da177e4SLinus Torvalds}
10431da177e4SLinus Torvalds
10441da177e4SLinus Torvaldssub dump_union($$) {
10451da177e4SLinus Torvalds    dump_struct(@_);
10461da177e4SLinus Torvalds}
10471da177e4SLinus Torvalds
10481da177e4SLinus Torvaldssub dump_struct($$) {
10491da177e4SLinus Torvalds    my $x = shift;
10501da177e4SLinus Torvalds    my $file = shift;
1051a746fe32SAditya Srivastava    my $decl_type;
1052a746fe32SAditya Srivastava    my $members;
1053a746fe32SAditya Srivastava    my $type = qr{struct|union};
1054a746fe32SAditya Srivastava    # For capturing struct/union definition body, i.e. "{members*}qualifiers*"
1055e86bdb24SAditya Srivastava    my $qualifiers = qr{$attribute|__packed|__aligned|____cacheline_aligned_in_smp|____cacheline_aligned};
1056e86bdb24SAditya Srivastava    my $definition_body = qr{\{(.*)\}\s*$qualifiers*};
1057e86bdb24SAditya Srivastava    my $struct_members = qr{($type)([^\{\};]+)\{([^\{\}]*)\}([^\{\}\;]*)\;};
10581da177e4SLinus Torvalds
1059a746fe32SAditya Srivastava    if ($x =~ /($type)\s+(\w+)\s*$definition_body/) {
1060a746fe32SAditya Srivastava        $decl_type = $1;
10611da177e4SLinus Torvalds        $declaration_name = $2;
1062a746fe32SAditya Srivastava        $members = $3;
1063a746fe32SAditya Srivastava    } elsif ($x =~ /typedef\s+($type)\s*$definition_body\s*(\w+)\s*;/) {
1064a746fe32SAditya Srivastava        $decl_type = $1;
1065a746fe32SAditya Srivastava        $declaration_name = $3;
1066a746fe32SAditya Srivastava        $members = $2;
1067a746fe32SAditya Srivastava    }
10681da177e4SLinus Torvalds
1069a746fe32SAditya Srivastava    if ($members) {
107052042e2dSMauro Carvalho Chehab        if ($identifier ne $declaration_name) {
1071df4bf98eSNiklas Söderlund            emit_warning("${file}:$.", "expecting prototype for $decl_type $identifier. Prototype was for $decl_type $declaration_name instead\n");
107252042e2dSMauro Carvalho Chehab            return;
107352042e2dSMauro Carvalho Chehab        }
107452042e2dSMauro Carvalho Chehab
1075aeec46b9SMartin Waitz        # ignore members marked private:
10760d8c39e6SMauro Carvalho Chehab        $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
10770d8c39e6SMauro Carvalho Chehab        $members =~ s/\/\*\s*private:.*//gosi;
1078aeec46b9SMartin Waitz        # strip comments:
1079aeec46b9SMartin Waitz        $members =~ s/\/\*.*?\*\///gos;
1080ef5da59fSRandy Dunlap        # strip attributes
1081e86bdb24SAditya Srivastava        $members =~ s/\s*$attribute/ /gi;
10823d9bfb19SSakari Ailus        $members =~ s/\s*__aligned\s*\([^;]*\)/ /gos;
1083f600c77aSJonathan Corbet        $members =~ s/\s*__counted_by\s*\([^;]*\)/ /gos;
1084ca7e324eSAlexander Lobakin        $members =~ s/\s*__counted_by_(le|be)\s*\([^;]*\)/ /gos;
10853d9bfb19SSakari Ailus        $members =~ s/\s*__packed\s*/ /gos;
1086f0074929SJonathan Corbet        $members =~ s/\s*CRYPTO_MINALIGN_ATTR/ /gos;
1087f861537dSAndré Almeida        $members =~ s/\s*____cacheline_aligned_in_smp/ /gos;
1088a070991fSJonathan Cameron        $members =~ s/\s*____cacheline_aligned/ /gos;
108950d7bd38SKees Cook        # unwrap struct_group():
109050d7bd38SKees Cook        # - first eat non-declaration parameters and rewrite for final match
109150d7bd38SKees Cook        # - then remove macro, outer parens, and trailing semicolon
109250d7bd38SKees Cook        $members =~ s/\bstruct_group\s*\(([^,]*,)/STRUCT_GROUP(/gos;
10935f8e4007SKees Cook        $members =~ s/\bstruct_group_attr\s*\(([^,]*,){2}/STRUCT_GROUP(/gos;
10945f8e4007SKees Cook        $members =~ s/\bstruct_group_tagged\s*\(([^,]*),([^,]*),/struct $1 $2; STRUCT_GROUP(/gos;
109550d7bd38SKees Cook        $members =~ s/\b__struct_group\s*\(([^,]*,){3}/STRUCT_GROUP(/gos;
109650d7bd38SKees Cook        $members =~ s/\bSTRUCT_GROUP(\(((?:(?>[^)(]+)|(?1))*)\))[^;]*;/$2/gos;
10973556108eSMauro Carvalho Chehab
1098e86bdb24SAditya Srivastava        my $args = qr{([^,)]+)};
1099b22b5a9eSConchúr Navid        # replace DECLARE_BITMAP
11003556108eSMauro Carvalho Chehab        $members =~ s/__ETHTOOL_DECLARE_LINK_MODE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, __ETHTOOL_LINK_MODE_MASK_NBITS)/gos;
1101603bdf5dSRandy Dunlap        $members =~ s/DECLARE_PHY_INTERFACE_MASK\s*\(([^\)]+)\)/DECLARE_BITMAP($1, PHY_INTERFACE_MODE_MAX)/gos;
1102e86bdb24SAditya Srivastava        $members =~ s/DECLARE_BITMAP\s*\($args,\s*$args\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos;
11031cb566baSJakub Kicinski        # replace DECLARE_HASHTABLE
1104e86bdb24SAditya Srivastava        $members =~ s/DECLARE_HASHTABLE\s*\($args,\s*$args\)/unsigned long $1\[1 << (($2) - 1)\]/gos;
110545005b27SMauro Carvalho Chehab        # replace DECLARE_KFIFO
1106e86bdb24SAditya Srivastava        $members =~ s/DECLARE_KFIFO\s*\($args,\s*$args,\s*$args\)/$2 \*$1/gos;
110745005b27SMauro Carvalho Chehab        # replace DECLARE_KFIFO_PTR
1108e86bdb24SAditya Srivastava        $members =~ s/DECLARE_KFIFO_PTR\s*\($args,\s*$args\)/$2 \*$1/gos;
11093080ea55SKees Cook        # replace DECLARE_FLEX_ARRAY
11103080ea55SKees Cook        $members =~ s/(?:__)?DECLARE_FLEX_ARRAY\s*\($args,\s*$args\)/$1 $2\[\]/gos;
1111be98edcbSPavan Kumar Linga        #replace DEFINE_DMA_UNMAP_ADDR
1112be98edcbSPavan Kumar Linga        $members =~ s/DEFINE_DMA_UNMAP_ADDR\s*\($args\)/dma_addr_t $1/gos;
1113be98edcbSPavan Kumar Linga        #replace DEFINE_DMA_UNMAP_LEN
1114be98edcbSPavan Kumar Linga        $members =~ s/DEFINE_DMA_UNMAP_LEN\s*\($args\)/__u32 $1/gos;
11158ad72163SMauro Carvalho Chehab        my $declaration = $members;
11168ad72163SMauro Carvalho Chehab
11178ad72163SMauro Carvalho Chehab        # Split nested struct/union elements as newer ones
1118e86bdb24SAditya Srivastava        while ($members =~ m/$struct_members/) {
111984ce5b98SMauro Carvalho Chehab            my $newmember;
112084ce5b98SMauro Carvalho Chehab            my $maintype = $1;
112184ce5b98SMauro Carvalho Chehab            my $ids = $4;
11228ad72163SMauro Carvalho Chehab            my $content = $3;
112384ce5b98SMauro Carvalho Chehab            foreach my $id(split /,/, $ids) {
112484ce5b98SMauro Carvalho Chehab                $newmember .= "$maintype $id; ";
112584ce5b98SMauro Carvalho Chehab
11268ad72163SMauro Carvalho Chehab                $id =~ s/[:\[].*//;
112784ce5b98SMauro Carvalho Chehab                $id =~ s/^\s*\**(\S+)\s*/$1/;
11288ad72163SMauro Carvalho Chehab                foreach my $arg (split /;/, $content) {
11298ad72163SMauro Carvalho Chehab                    next if ($arg =~ m/^\s*$/);
11307c0d7e87SMauro Carvalho Chehab                    if ($arg =~ m/^([^\(]+\(\*?\s*)([\w\.]*)(\s*\).*)/) {
11317c0d7e87SMauro Carvalho Chehab                        # pointer-to-function
11327c0d7e87SMauro Carvalho Chehab                        my $type = $1;
11337c0d7e87SMauro Carvalho Chehab                        my $name = $2;
11347c0d7e87SMauro Carvalho Chehab                        my $extra = $3;
11357c0d7e87SMauro Carvalho Chehab                        next if (!$name);
11367c0d7e87SMauro Carvalho Chehab                        if ($id =~ m/^\s*$/) {
11377c0d7e87SMauro Carvalho Chehab                            # anonymous struct/union
11387c0d7e87SMauro Carvalho Chehab                            $newmember .= "$type$name$extra; ";
11397c0d7e87SMauro Carvalho Chehab                        } else {
11407c0d7e87SMauro Carvalho Chehab                            $newmember .= "$type$id.$name$extra; ";
11417c0d7e87SMauro Carvalho Chehab                        }
11427c0d7e87SMauro Carvalho Chehab                    } else {
114384ce5b98SMauro Carvalho Chehab                        my $type;
114484ce5b98SMauro Carvalho Chehab                        my $names;
114584ce5b98SMauro Carvalho Chehab                        $arg =~ s/^\s+//;
114684ce5b98SMauro Carvalho Chehab                        $arg =~ s/\s+$//;
114784ce5b98SMauro Carvalho Chehab                        # Handle bitmaps
114884ce5b98SMauro Carvalho Chehab                        $arg =~ s/:\s*\d+\s*//g;
114984ce5b98SMauro Carvalho Chehab                        # Handle arrays
1150d404d579SMauro Carvalho Chehab                        $arg =~ s/\[.*\]//g;
115184ce5b98SMauro Carvalho Chehab                        # The type may have multiple words,
115284ce5b98SMauro Carvalho Chehab                        # and multiple IDs can be defined, like:
115384ce5b98SMauro Carvalho Chehab                        #    const struct foo, *bar, foobar
115484ce5b98SMauro Carvalho Chehab                        # So, we remove spaces when parsing the
115584ce5b98SMauro Carvalho Chehab                        # names, in order to match just names
115684ce5b98SMauro Carvalho Chehab                        # and commas for the names
115784ce5b98SMauro Carvalho Chehab                        $arg =~ s/\s*,\s*/,/g;
115884ce5b98SMauro Carvalho Chehab                        if ($arg =~ m/(.*)\s+([\S+,]+)/) {
115984ce5b98SMauro Carvalho Chehab                            $type = $1;
116084ce5b98SMauro Carvalho Chehab                            $names = $2;
116184ce5b98SMauro Carvalho Chehab                        } else {
116284ce5b98SMauro Carvalho Chehab                            $newmember .= "$arg; ";
116384ce5b98SMauro Carvalho Chehab                            next;
116484ce5b98SMauro Carvalho Chehab                        }
116584ce5b98SMauro Carvalho Chehab                        foreach my $name (split /,/, $names) {
116684ce5b98SMauro Carvalho Chehab                            $name =~ s/^\s*\**(\S+)\s*/$1/;
11678ad72163SMauro Carvalho Chehab                            next if (($name =~ m/^\s*$/));
11688ad72163SMauro Carvalho Chehab                            if ($id =~ m/^\s*$/) {
11698ad72163SMauro Carvalho Chehab                                # anonymous struct/union
11708ad72163SMauro Carvalho Chehab                                $newmember .= "$type $name; ";
11718ad72163SMauro Carvalho Chehab                            } else {
11728ad72163SMauro Carvalho Chehab                                $newmember .= "$type $id.$name; ";
11738ad72163SMauro Carvalho Chehab                            }
11748ad72163SMauro Carvalho Chehab                        }
11757c0d7e87SMauro Carvalho Chehab                    }
117684ce5b98SMauro Carvalho Chehab                }
117784ce5b98SMauro Carvalho Chehab            }
1178e86bdb24SAditya Srivastava            $members =~ s/$struct_members/$newmember/;
117984ce5b98SMauro Carvalho Chehab        }
11808ad72163SMauro Carvalho Chehab
11818ad72163SMauro Carvalho Chehab        # Ignore other nested elements, like enums
1182673bb2dfSBen Hutchings        $members =~ s/(\{[^\{\}]*\})//g;
11838ad72163SMauro Carvalho Chehab
1184151c468bSMauro Carvalho Chehab        create_parameterlist($members, ';', $file, $declaration_name);
11851081de2dSMauro Carvalho Chehab        check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual);
11861da177e4SLinus Torvalds
11878ad72163SMauro Carvalho Chehab        # Adjust declaration for better display
1188673bb2dfSBen Hutchings        $declaration =~ s/([\{;])/$1\n/g;
1189673bb2dfSBen Hutchings        $declaration =~ s/\}\s+;/};/g;
11908ad72163SMauro Carvalho Chehab        # Better handle inlined enums
1191673bb2dfSBen Hutchings        do {} while ($declaration =~ s/(enum\s+\{[^\}]+),([^\n])/$1,\n$2/);
11928ad72163SMauro Carvalho Chehab
11938ad72163SMauro Carvalho Chehab        my @def_args = split /\n/, $declaration;
11948ad72163SMauro Carvalho Chehab        my $level = 1;
11958ad72163SMauro Carvalho Chehab        $declaration = "";
11968ad72163SMauro Carvalho Chehab        foreach my $clause (@def_args) {
11978ad72163SMauro Carvalho Chehab            $clause =~ s/^\s+//;
11988ad72163SMauro Carvalho Chehab            $clause =~ s/\s+$//;
11998ad72163SMauro Carvalho Chehab            $clause =~ s/\s+/ /;
12008ad72163SMauro Carvalho Chehab            next if (!$clause);
1201673bb2dfSBen Hutchings            $level-- if ($clause =~ m/(\})/ && $level > 1);
12028ad72163SMauro Carvalho Chehab            if (!($clause =~ m/^\s*#/)) {
12038ad72163SMauro Carvalho Chehab                $declaration .= "\t" x $level;
12048ad72163SMauro Carvalho Chehab            }
12058ad72163SMauro Carvalho Chehab            $declaration .= "\t" . $clause . "\n";
1206673bb2dfSBen Hutchings            $level++ if ($clause =~ m/(\{)/ && !($clause =~m/\}/));
12078ad72163SMauro Carvalho Chehab        }
12081da177e4SLinus Torvalds        output_declaration($declaration_name,
12091da177e4SLinus Torvalds                   'struct',
12101da177e4SLinus Torvalds                   {'struct' => $declaration_name,
12111da177e4SLinus Torvalds                    'module' => $modulename,
12128ad72163SMauro Carvalho Chehab                    'definition' => $declaration,
12131da177e4SLinus Torvalds                    'parameterlist' => \@parameterlist,
12141da177e4SLinus Torvalds                    'parameterdescs' => \%parameterdescs,
12151da177e4SLinus Torvalds                    'parametertypes' => \%parametertypes,
12161da177e4SLinus Torvalds                    'sectionlist' => \@sectionlist,
12171da177e4SLinus Torvalds                    'sections' => \%sections,
12181da177e4SLinus Torvalds                    'purpose' => $declaration_purpose,
12191da177e4SLinus Torvalds                    'type' => $decl_type
12201da177e4SLinus Torvalds                   });
1221af404fb1SVegard Nossum    } else {
1222d40e1e65SBart Van Assche        print STDERR "${file}:$.: error: Cannot parse struct or union!\n";
12231da177e4SLinus Torvalds        ++$errors;
12241da177e4SLinus Torvalds    }
12251da177e4SLinus Torvalds}
12261da177e4SLinus Torvalds
122785afe608SMauro Carvalho Chehab
122885afe608SMauro Carvalho Chehabsub show_warnings($$) {
122985afe608SMauro Carvalho Chehab    my $functype = shift;
123085afe608SMauro Carvalho Chehab    my $name = shift;
123185afe608SMauro Carvalho Chehab
1232eab795ddSMauro Carvalho Chehab    return 0 if (defined($nosymbol_table{$name}));
1233eab795ddSMauro Carvalho Chehab
123485afe608SMauro Carvalho Chehab    return 1 if ($output_selection == OUTPUT_ALL);
123585afe608SMauro Carvalho Chehab
123685afe608SMauro Carvalho Chehab    if ($output_selection == OUTPUT_EXPORTED) {
123785afe608SMauro Carvalho Chehab        if (defined($function_table{$name})) {
123885afe608SMauro Carvalho Chehab            return 1;
123985afe608SMauro Carvalho Chehab        } else {
124085afe608SMauro Carvalho Chehab            return 0;
124185afe608SMauro Carvalho Chehab        }
124285afe608SMauro Carvalho Chehab    }
124385afe608SMauro Carvalho Chehab    if ($output_selection == OUTPUT_INTERNAL) {
124485afe608SMauro Carvalho Chehab        if (!($functype eq "function" && defined($function_table{$name}))) {
124585afe608SMauro Carvalho Chehab            return 1;
124685afe608SMauro Carvalho Chehab        } else {
124785afe608SMauro Carvalho Chehab            return 0;
124885afe608SMauro Carvalho Chehab        }
124985afe608SMauro Carvalho Chehab    }
125085afe608SMauro Carvalho Chehab    if ($output_selection == OUTPUT_INCLUDE) {
125185afe608SMauro Carvalho Chehab        if (defined($function_table{$name})) {
125285afe608SMauro Carvalho Chehab            return 1;
125385afe608SMauro Carvalho Chehab        } else {
125485afe608SMauro Carvalho Chehab            return 0;
125585afe608SMauro Carvalho Chehab        }
125685afe608SMauro Carvalho Chehab    }
125785afe608SMauro Carvalho Chehab    die("Please add the new output type at show_warnings()");
125885afe608SMauro Carvalho Chehab}
125985afe608SMauro Carvalho Chehab
12601da177e4SLinus Torvaldssub dump_enum($$) {
12611da177e4SLinus Torvalds    my $x = shift;
12621da177e4SLinus Torvalds    my $file = shift;
1263d38c8cfbSMauro Carvalho Chehab    my $members;
1264d38c8cfbSMauro Carvalho Chehab
1265e27cb89aSJakub Kicinski    # ignore members marked private:
1266e27cb89aSJakub Kicinski    $x =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi;
1267e27cb89aSJakub Kicinski    $x =~ s/\/\*\s*private:.*}/}/gosi;
12681da177e4SLinus Torvalds
1269aeec46b9SMartin Waitz    $x =~ s@/\*.*?\*/@@gos;	# strip comments.
12704468e21eSConchúr Navid    # strip #define macros inside enums
12718e93cb78SJohannes Berg    $x =~ s@#\s*((define|ifdef|if)\s+|endif)[^;]*;@@gos;
1272b6d676dbSRandy Dunlap
1273d38c8cfbSMauro Carvalho Chehab    if ($x =~ /typedef\s+enum\s*\{(.*)\}\s*(\w*)\s*;/) {
1274d38c8cfbSMauro Carvalho Chehab        $declaration_name = $2;
1275d38c8cfbSMauro Carvalho Chehab        $members = $1;
1276d38c8cfbSMauro Carvalho Chehab    } elsif ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) {
12771da177e4SLinus Torvalds        $declaration_name = $1;
1278d38c8cfbSMauro Carvalho Chehab        $members = $2;
1279d38c8cfbSMauro Carvalho Chehab    }
1280d38c8cfbSMauro Carvalho Chehab
1281ae5b17e4SAndy Shevchenko    if ($members) {
128252042e2dSMauro Carvalho Chehab        if ($identifier ne $declaration_name) {
12830b54c2e3SMauro Carvalho Chehab            if ($identifier eq "") {
1284df4bf98eSNiklas Söderlund                emit_warning("${file}:$.", "wrong kernel-doc identifier on line:\n");
12850b54c2e3SMauro Carvalho Chehab            } else {
1286df4bf98eSNiklas Söderlund                emit_warning("${file}:$.", "expecting prototype for enum $identifier. Prototype was for enum $declaration_name instead\n");
12870b54c2e3SMauro Carvalho Chehab            }
128852042e2dSMauro Carvalho Chehab            return;
128952042e2dSMauro Carvalho Chehab        }
12900b54c2e3SMauro Carvalho Chehab        $declaration_name = "(anonymous)" if ($declaration_name eq "");
129152042e2dSMauro Carvalho Chehab
12925cb5c31cSJohannes Berg        my %_members;
12935cb5c31cSJohannes Berg
1294463a0fdcSMarkus Heiser        $members =~ s/\s+$//;
12950ef5de7bSPavan Kumar Linga        $members =~ s/\([^;]*?[\)]//g;
12961da177e4SLinus Torvalds
12971da177e4SLinus Torvalds        foreach my $arg (split ',', $members) {
12981da177e4SLinus Torvalds            $arg =~ s/^\s*(\w+).*/$1/;
12991da177e4SLinus Torvalds            push @parameterlist, $arg;
13001da177e4SLinus Torvalds            if (!$parameterdescs{$arg}) {
13011da177e4SLinus Torvalds                $parameterdescs{$arg} = $undescribed;
130285afe608SMauro Carvalho Chehab                if (show_warnings("enum", $declaration_name)) {
1303df4bf98eSNiklas Söderlund                    emit_warning("${file}:$.", "Enum value '$arg' not described in enum '$declaration_name'\n");
13042defb272SMauro Carvalho Chehab                }
13051da177e4SLinus Torvalds            }
13065cb5c31cSJohannes Berg            $_members{$arg} = 1;
13075cb5c31cSJohannes Berg        }
13081da177e4SLinus Torvalds
13095cb5c31cSJohannes Berg        while (my ($k, $v) = each %parameterdescs) {
13105cb5c31cSJohannes Berg            if (!exists($_members{$k})) {
131185afe608SMauro Carvalho Chehab                if (show_warnings("enum", $declaration_name)) {
1312df4bf98eSNiklas Söderlund                    emit_warning("${file}:$.", "Excess enum value '$k' description in '$declaration_name'\n");
13132defb272SMauro Carvalho Chehab                }
13145cb5c31cSJohannes Berg            }
13151da177e4SLinus Torvalds        }
13161da177e4SLinus Torvalds
13171da177e4SLinus Torvalds        output_declaration($declaration_name,
13181da177e4SLinus Torvalds                           'enum',
13191da177e4SLinus Torvalds                           {'enum' => $declaration_name,
13201da177e4SLinus Torvalds                            'module' => $modulename,
13211da177e4SLinus Torvalds                            'parameterlist' => \@parameterlist,
13221da177e4SLinus Torvalds                            'parameterdescs' => \%parameterdescs,
13231da177e4SLinus Torvalds                            'sectionlist' => \@sectionlist,
13241da177e4SLinus Torvalds                            'sections' => \%sections,
13251da177e4SLinus Torvalds                            'purpose' => $declaration_purpose
13261da177e4SLinus Torvalds                           });
1327d38c8cfbSMauro Carvalho Chehab    } else {
1328d40e1e65SBart Van Assche        print STDERR "${file}:$.: error: Cannot parse enum!\n";
13291da177e4SLinus Torvalds        ++$errors;
13301da177e4SLinus Torvalds    }
13311da177e4SLinus Torvalds}
13321da177e4SLinus Torvalds
13337d2c6b1eSMauro Carvalho Chehabmy $typedef_type = qr { ((?:\s+[\w\*]+\b){1,8})\s* }x;
13347efc6c42SMauro Carvalho Chehabmy $typedef_ident = qr { \*?\s*(\w\S+)\s* }x;
13357efc6c42SMauro Carvalho Chehabmy $typedef_args = qr { \s*\((.*)\); }x;
13367efc6c42SMauro Carvalho Chehab
13377efc6c42SMauro Carvalho Chehabmy $typedef1 = qr { typedef$typedef_type\($typedef_ident\)$typedef_args }x;
13387efc6c42SMauro Carvalho Chehabmy $typedef2 = qr { typedef$typedef_type$typedef_ident$typedef_args }x;
13397efc6c42SMauro Carvalho Chehab
13401da177e4SLinus Torvaldssub dump_typedef($$) {
13411da177e4SLinus Torvalds    my $x = shift;
13421da177e4SLinus Torvalds    my $file = shift;
13431da177e4SLinus Torvalds
1344aeec46b9SMartin Waitz    $x =~ s@/\*.*?\*/@@gos;	# strip comments.
134583766452SMauro Carvalho Chehab
13467efc6c42SMauro Carvalho Chehab    # Parse function typedef prototypes
13477efc6c42SMauro Carvalho Chehab    if ($x =~ $typedef1 || $x =~ $typedef2) {
134883766452SMauro Carvalho Chehab        $return_type = $1;
134983766452SMauro Carvalho Chehab        $declaration_name = $2;
135083766452SMauro Carvalho Chehab        my $args = $3;
13516b80975cSMauro Carvalho Chehab        $return_type =~ s/^\s+//;
135283766452SMauro Carvalho Chehab
135352042e2dSMauro Carvalho Chehab        if ($identifier ne $declaration_name) {
1354df4bf98eSNiklas Söderlund            emit_warning("${file}:$.", "expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n");
135552042e2dSMauro Carvalho Chehab            return;
135652042e2dSMauro Carvalho Chehab        }
135752042e2dSMauro Carvalho Chehab
1358151c468bSMauro Carvalho Chehab        create_parameterlist($args, ',', $file, $declaration_name);
135983766452SMauro Carvalho Chehab
136083766452SMauro Carvalho Chehab        output_declaration($declaration_name,
136183766452SMauro Carvalho Chehab                           'function',
136283766452SMauro Carvalho Chehab                           {'function' => $declaration_name,
136382801d06SMauro Carvalho Chehab                            'typedef' => 1,
136483766452SMauro Carvalho Chehab                            'module' => $modulename,
136583766452SMauro Carvalho Chehab                            'functiontype' => $return_type,
136683766452SMauro Carvalho Chehab                            'parameterlist' => \@parameterlist,
136783766452SMauro Carvalho Chehab                            'parameterdescs' => \%parameterdescs,
136883766452SMauro Carvalho Chehab                            'parametertypes' => \%parametertypes,
136983766452SMauro Carvalho Chehab                            'sectionlist' => \@sectionlist,
137083766452SMauro Carvalho Chehab                            'sections' => \%sections,
137183766452SMauro Carvalho Chehab                            'purpose' => $declaration_purpose
137283766452SMauro Carvalho Chehab                           });
137383766452SMauro Carvalho Chehab        return;
137483766452SMauro Carvalho Chehab    }
137583766452SMauro Carvalho Chehab
13761da177e4SLinus Torvalds    while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
13771da177e4SLinus Torvalds        $x =~ s/\(*.\)\s*;$/;/;
13781da177e4SLinus Torvalds        $x =~ s/\[*.\]\s*;$/;/;
13791da177e4SLinus Torvalds    }
13801da177e4SLinus Torvalds
13811da177e4SLinus Torvalds    if ($x =~ /typedef.*\s+(\w+)\s*;/) {
13821da177e4SLinus Torvalds        $declaration_name = $1;
13831da177e4SLinus Torvalds
138452042e2dSMauro Carvalho Chehab        if ($identifier ne $declaration_name) {
1385df4bf98eSNiklas Söderlund            emit_warning("${file}:$.", "expecting prototype for typedef $identifier. Prototype was for typedef $declaration_name instead\n");
138652042e2dSMauro Carvalho Chehab            return;
138752042e2dSMauro Carvalho Chehab        }
138852042e2dSMauro Carvalho Chehab
13891da177e4SLinus Torvalds        output_declaration($declaration_name,
13901da177e4SLinus Torvalds                           'typedef',
13911da177e4SLinus Torvalds                           {'typedef' => $declaration_name,
13921da177e4SLinus Torvalds                            'module' => $modulename,
13931da177e4SLinus Torvalds                            'sectionlist' => \@sectionlist,
13941da177e4SLinus Torvalds                            'sections' => \%sections,
13951da177e4SLinus Torvalds                            'purpose' => $declaration_purpose
13961da177e4SLinus Torvalds                           });
1397af404fb1SVegard Nossum    } else {
1398d40e1e65SBart Van Assche        print STDERR "${file}:$.: error: Cannot parse typedef!\n";
13991da177e4SLinus Torvalds        ++$errors;
14001da177e4SLinus Torvalds    }
14011da177e4SLinus Torvalds}
14021da177e4SLinus Torvalds
1403a1d94aa5SRandy Dunlapsub save_struct_actual($) {
1404a1d94aa5SRandy Dunlap    my $actual = shift;
1405a1d94aa5SRandy Dunlap
1406a1d94aa5SRandy Dunlap    # strip all spaces from the actual param so that it looks like one string item
1407a1d94aa5SRandy Dunlap    $actual =~ s/\s*//g;
1408a1d94aa5SRandy Dunlap    $struct_actual = $struct_actual . $actual . " ";
1409a1d94aa5SRandy Dunlap}
1410a1d94aa5SRandy Dunlap
1411151c468bSMauro Carvalho Chehabsub create_parameterlist($$$$) {
14121da177e4SLinus Torvalds    my $args = shift;
14131da177e4SLinus Torvalds    my $splitter = shift;
14141da177e4SLinus Torvalds    my $file = shift;
1415151c468bSMauro Carvalho Chehab    my $declaration_name = shift;
14161da177e4SLinus Torvalds    my $type;
14171da177e4SLinus Torvalds    my $param;
14181da177e4SLinus Torvalds
1419a6d3fe77SMartin Waitz    # temporarily replace commas inside function pointer definition
1420e86bdb24SAditya Srivastava    my $arg_expr = qr{\([^\),]+};
1421e86bdb24SAditya Srivastava    while ($args =~ /$arg_expr,/) {
1422e86bdb24SAditya Srivastava        $args =~ s/($arg_expr),/$1#/g;
14231da177e4SLinus Torvalds    }
14241da177e4SLinus Torvalds
14251da177e4SLinus Torvalds    foreach my $arg (split($splitter, $args)) {
14261da177e4SLinus Torvalds        # strip comments
14271da177e4SLinus Torvalds        $arg =~ s/\/\*.*\*\///;
142803699f27SKees Cook        # ignore argument attributes
142903699f27SKees Cook        $arg =~ s/\sPOS0?\s/ /;
14301da177e4SLinus Torvalds        # strip leading/trailing spaces
14311da177e4SLinus Torvalds        $arg =~ s/^\s*//;
14321da177e4SLinus Torvalds        $arg =~ s/\s*$//;
14331da177e4SLinus Torvalds        $arg =~ s/\s+/ /;
14341da177e4SLinus Torvalds
14351da177e4SLinus Torvalds        if ($arg =~ /^#/) {
14361da177e4SLinus Torvalds            # Treat preprocessor directive as a typeless variable just to fill
14371da177e4SLinus Torvalds            # corresponding data structures "correctly". Catch it later in
14381da177e4SLinus Torvalds            # output_* subs.
1439ed8348e2SMauro Carvalho Chehab            push_parameter($arg, "", "", $file);
144000d62961SRichard Kennedy        } elsif ($arg =~ m/\(.+\)\s*\(/) {
14411da177e4SLinus Torvalds            # pointer-to-function
14421da177e4SLinus Torvalds            $arg =~ tr/#/,/;
1443336ced2dSAditya Srivastava            $arg =~ m/[^\(]+\(\*?\s*([\w\[\]\.]*)\s*\)/;
14441da177e4SLinus Torvalds            $param = $1;
14451da177e4SLinus Torvalds            $type = $arg;
144600d62961SRichard Kennedy            $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
1447a1d94aa5SRandy Dunlap            save_struct_actual($param);
1448ed8348e2SMauro Carvalho Chehab            push_parameter($param, $type, $arg, $file, $declaration_name);
1449bbf00be9SSakari Ailus        } elsif ($arg =~ m/\(.+\)\s*\[/) {
1450bbf00be9SSakari Ailus            # array-of-pointers
1451bbf00be9SSakari Ailus            $arg =~ tr/#/,/;
1452bbf00be9SSakari Ailus            $arg =~ m/[^\(]+\(\s*\*\s*([\w\[\]\.]*?)\s*(\s*\[\s*[\w]+\s*\]\s*)*\)/;
1453bbf00be9SSakari Ailus            $param = $1;
1454bbf00be9SSakari Ailus            $type = $arg;
1455bbf00be9SSakari Ailus            $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
1456bbf00be9SSakari Ailus            save_struct_actual($param);
1457bbf00be9SSakari Ailus            push_parameter($param, $type, $arg, $file, $declaration_name);
1458aeec46b9SMartin Waitz        } elsif ($arg) {
14591da177e4SLinus Torvalds            $arg =~ s/\s*:\s*/:/g;
14601da177e4SLinus Torvalds            $arg =~ s/\s*\[/\[/g;
14611da177e4SLinus Torvalds
14621da177e4SLinus Torvalds            my @args = split('\s*,\s*', $arg);
14631da177e4SLinus Torvalds            if ($args[0] =~ m/\*/) {
14641da177e4SLinus Torvalds                $args[0] =~ s/(\*+)\s*/ $1/;
14651da177e4SLinus Torvalds            }
1466884f2810SBorislav Petkov
1467884f2810SBorislav Petkov            my @first_arg;
1468884f2810SBorislav Petkov            if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1469884f2810SBorislav Petkov                shift @args;
1470884f2810SBorislav Petkov                push(@first_arg, split('\s+', $1));
1471884f2810SBorislav Petkov                push(@first_arg, $2);
1472884f2810SBorislav Petkov            } else {
1473884f2810SBorislav Petkov                @first_arg = split('\s+', shift @args);
1474884f2810SBorislav Petkov            }
1475884f2810SBorislav Petkov
14761da177e4SLinus Torvalds            unshift(@args, pop @first_arg);
14771da177e4SLinus Torvalds            $type = join " ", @first_arg;
14781da177e4SLinus Torvalds
14791da177e4SLinus Torvalds            foreach $param (@args) {
14801da177e4SLinus Torvalds                if ($param =~ m/^(\*+)\s*(.*)/) {
1481a1d94aa5SRandy Dunlap                    save_struct_actual($2);
1482ed8348e2SMauro Carvalho Chehab
1483ed8348e2SMauro Carvalho Chehab                    push_parameter($2, "$type $1", $arg, $file, $declaration_name);
14840ec69b3bSDonald Hunter                } elsif ($param =~ m/(.*?):(\w+)/) {
14857b97887eSRandy Dunlap                    if ($type ne "") { # skip unnamed bit-fields
1486a1d94aa5SRandy Dunlap                        save_struct_actual($1);
1487ed8348e2SMauro Carvalho Chehab                        push_parameter($1, "$type:$2", $arg, $file, $declaration_name)
14881da177e4SLinus Torvalds                    }
1489af404fb1SVegard Nossum                } else {
1490a1d94aa5SRandy Dunlap                    save_struct_actual($param);
1491ed8348e2SMauro Carvalho Chehab                    push_parameter($param, $type, $arg, $file, $declaration_name);
14921da177e4SLinus Torvalds                }
14931da177e4SLinus Torvalds            }
14941da177e4SLinus Torvalds        }
14951da177e4SLinus Torvalds    }
14961da177e4SLinus Torvalds}
14971da177e4SLinus Torvalds
1498ed8348e2SMauro Carvalho Chehabsub push_parameter($$$$$) {
14991da177e4SLinus Torvalds    my $param = shift;
15001da177e4SLinus Torvalds    my $type = shift;
1501ed8348e2SMauro Carvalho Chehab    my $org_arg = shift;
15021da177e4SLinus Torvalds    my $file = shift;
1503151c468bSMauro Carvalho Chehab    my $declaration_name = shift;
15041da177e4SLinus Torvalds
15055f8c7c98SRandy Dunlap    if (($anon_struct_union == 1) && ($type eq "") &&
15065f8c7c98SRandy Dunlap        ($param eq "}")) {
15075f8c7c98SRandy Dunlap        return;        # ignore the ending }; from anon. struct/union
15085f8c7c98SRandy Dunlap    }
15095f8c7c98SRandy Dunlap
15105f8c7c98SRandy Dunlap    $anon_struct_union = 0;
1511f9b5c530SMauro Carvalho Chehab    $param =~ s/[\[\)].*//;
15121da177e4SLinus Torvalds
1513a6d3fe77SMartin Waitz    if ($type eq "" && $param =~ /\.\.\.$/)
15141da177e4SLinus Torvalds    {
1515c950a173SSilvio Fricke        if (!$param =~ /\w\.\.\.$/) {
1516c950a173SSilvio Fricke            # handles unnamed variable parameters
1517ef00028bSJonathan Corbet            $param = "...";
1518af404fb1SVegard Nossum        } elsif ($param =~ /\w\.\.\.$/) {
151943756e34SJonathan Neuschäfer            # for named variable parameters of the form `x...`, remove the dots
152043756e34SJonathan Neuschäfer            $param =~ s/\.\.\.$//;
152143756e34SJonathan Neuschäfer        }
1522ced69090SRandy Dunlap        if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") {
1523a6d3fe77SMartin Waitz            $parameterdescs{$param} = "variable arguments";
15241da177e4SLinus Torvalds        }
1525ced69090SRandy Dunlap    }
15261da177e4SLinus Torvalds    elsif ($type eq "" && ($param eq "" or $param eq "void"))
15271da177e4SLinus Torvalds    {
15281da177e4SLinus Torvalds        $param="void";
15291da177e4SLinus Torvalds        $parameterdescs{void} = "no arguments";
15301da177e4SLinus Torvalds    }
1531134fe01bSRandy Dunlap    elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1532134fe01bSRandy Dunlap    # handle unnamed (anonymous) union or struct:
1533134fe01bSRandy Dunlap    {
1534134fe01bSRandy Dunlap        $type = $param;
1535134fe01bSRandy Dunlap        $param = "{unnamed_" . $param . "}";
1536134fe01bSRandy Dunlap        $parameterdescs{$param} = "anonymous\n";
15375f8c7c98SRandy Dunlap        $anon_struct_union = 1;
1538134fe01bSRandy Dunlap    }
1539aeb9ce05SCoco Li    elsif ($param =~ "__cacheline_group" )
1540aeb9ce05SCoco Li    # handle cache group enforcing variables: they do not need be described in header files
1541aeb9ce05SCoco Li    {
1542aeb9ce05SCoco Li        return; # ignore __cacheline_group_begin and __cacheline_group_end
1543aeb9ce05SCoco Li    }
1544134fe01bSRandy Dunlap
1545a6d3fe77SMartin Waitz    # warn if parameter has no description
1546134fe01bSRandy Dunlap    # (but ignore ones starting with # as these are not parameters
1547134fe01bSRandy Dunlap    # but inline preprocessor statements);
1548151c468bSMauro Carvalho Chehab    # Note: It will also ignore void params and unnamed structs/unions
1549f9b5c530SMauro Carvalho Chehab    if (!defined $parameterdescs{$param} && $param !~ /^#/) {
1550f9b5c530SMauro Carvalho Chehab        $parameterdescs{$param} = $undescribed;
15511da177e4SLinus Torvalds
1552be5cd20cSJonathan Corbet        if (show_warnings($type, $declaration_name) && $param !~ /\./) {
15530c3ebff5SKees Cook            emit_warning("${file}:$.", "Function parameter or struct member '$param' not described in '$declaration_name'\n");
15541da177e4SLinus Torvalds        }
15552defb272SMauro Carvalho Chehab    }
15561da177e4SLinus Torvalds
155725985edcSLucas De Marchi    # strip spaces from $param so that it is one continuous string
1558e34e7dbbSRandy Dunlap    # on @parameterlist;
1559e34e7dbbSRandy Dunlap    # this fixes a problem where check_sections() cannot find
1560e34e7dbbSRandy Dunlap    # a parameter like "addr[6 + 2]" because it actually appears
1561e34e7dbbSRandy Dunlap    # as "addr[6", "+", "2]" on the parameter list;
1562e34e7dbbSRandy Dunlap    # but it's better to maintain the param string unchanged for output,
1563e34e7dbbSRandy Dunlap    # so just weaken the string compare in check_sections() to ignore
1564e34e7dbbSRandy Dunlap    # "[blah" in a parameter string;
1565e34e7dbbSRandy Dunlap    ###$param =~ s/\s*//g;
15661da177e4SLinus Torvalds    push @parameterlist, $param;
1567ed8348e2SMauro Carvalho Chehab    $org_arg =~ s/\s\s+/ /g;
1568ed8348e2SMauro Carvalho Chehab    $parametertypes{$param} = $org_arg;
15691da177e4SLinus Torvalds}
15701da177e4SLinus Torvalds
15711081de2dSMauro Carvalho Chehabsub check_sections($$$$$) {
15721081de2dSMauro Carvalho Chehab    my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck) = @_;
1573a1d94aa5SRandy Dunlap    my @sects = split ' ', $sectcheck;
1574a1d94aa5SRandy Dunlap    my @prms = split ' ', $prmscheck;
1575a1d94aa5SRandy Dunlap    my $err;
1576a1d94aa5SRandy Dunlap    my ($px, $sx);
1577a1d94aa5SRandy Dunlap    my $prm_clean;        # strip trailing "[array size]" and/or beginning "*"
1578a1d94aa5SRandy Dunlap
1579a1d94aa5SRandy Dunlap    foreach $sx (0 .. $#sects) {
1580a1d94aa5SRandy Dunlap        $err = 1;
1581a1d94aa5SRandy Dunlap        foreach $px (0 .. $#prms) {
1582a1d94aa5SRandy Dunlap            $prm_clean = $prms[$px];
1583a1d94aa5SRandy Dunlap            $prm_clean =~ s/\[.*\]//;
1584e86bdb24SAditya Srivastava            $prm_clean =~ s/$attribute//i;
1585e34e7dbbSRandy Dunlap            # ignore array size in a parameter string;
1586e34e7dbbSRandy Dunlap            # however, the original param string may contain
1587e34e7dbbSRandy Dunlap            # spaces, e.g.:  addr[6 + 2]
1588e34e7dbbSRandy Dunlap            # and this appears in @prms as "addr[6" since the
1589e34e7dbbSRandy Dunlap            # parameter list is split at spaces;
1590e34e7dbbSRandy Dunlap            # hence just ignore "[..." for the sections check;
1591e34e7dbbSRandy Dunlap            $prm_clean =~ s/\[.*//;
1592e34e7dbbSRandy Dunlap
1593a1d94aa5SRandy Dunlap            ##$prm_clean =~ s/^\**//;
1594a1d94aa5SRandy Dunlap            if ($prm_clean eq $sects[$sx]) {
1595a1d94aa5SRandy Dunlap                $err = 0;
1596a1d94aa5SRandy Dunlap                last;
1597a1d94aa5SRandy Dunlap            }
1598a1d94aa5SRandy Dunlap        }
1599a1d94aa5SRandy Dunlap        if ($err) {
1600a1d94aa5SRandy Dunlap            if ($decl_type eq "function") {
1601df4bf98eSNiklas Söderlund                emit_warning("${file}:$.",
1602a1d94aa5SRandy Dunlap                    "Excess function parameter " .
1603a1d94aa5SRandy Dunlap                    "'$sects[$sx]' " .
1604df4bf98eSNiklas Söderlund                    "description in '$decl_name'\n");
1605af404fb1SVegard Nossum            } elsif (($decl_type eq "struct") or
1606b77fdd6aSRandy Dunlap                          ($decl_type eq "union")) {
1607b77fdd6aSRandy Dunlap                emit_warning("${file}:$.",
1608b77fdd6aSRandy Dunlap                    "Excess $decl_type member " .
1609b77fdd6aSRandy Dunlap                    "'$sects[$sx]' " .
1610b77fdd6aSRandy Dunlap                    "description in '$decl_name'\n");
1611b77fdd6aSRandy Dunlap            }
1612a1d94aa5SRandy Dunlap        }
1613a1d94aa5SRandy Dunlap    }
1614a1d94aa5SRandy Dunlap}
1615a1d94aa5SRandy Dunlap
16161da177e4SLinus Torvalds##
16174092bac7SYacine Belkadi# Checks the section describing the return value of a function.
16184092bac7SYacine Belkadisub check_return_section {
16194092bac7SYacine Belkadi    my $file = shift;
16204092bac7SYacine Belkadi    my $declaration_name = shift;
16214092bac7SYacine Belkadi    my $return_type = shift;
16224092bac7SYacine Belkadi
16234092bac7SYacine Belkadi    # Ignore an empty return type (It's a macro)
16244092bac7SYacine Belkadi    # Ignore functions with a "void" return type. (But don't ignore "void *")
16254092bac7SYacine Belkadi    if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) {
16264092bac7SYacine Belkadi        return;
16274092bac7SYacine Belkadi    }
16284092bac7SYacine Belkadi
16294092bac7SYacine Belkadi    if (!defined($sections{$section_return}) ||
1630af404fb1SVegard Nossum        $sections{$section_return} eq "")
1631af404fb1SVegard Nossum    {
1632df4bf98eSNiklas Söderlund        emit_warning("${file}:$.",
16334092bac7SYacine Belkadi                     "No description found for return value of " .
1634df4bf98eSNiklas Söderlund                     "'$declaration_name'\n");
16354092bac7SYacine Belkadi    }
16364092bac7SYacine Belkadi}
16374092bac7SYacine Belkadi
16384092bac7SYacine Belkadi##
16391da177e4SLinus Torvalds# takes a function prototype and the name of the current file being
16401da177e4SLinus Torvalds# processed and spits out all the details stored in the global
16411da177e4SLinus Torvalds# arrays/hashes.
16421da177e4SLinus Torvaldssub dump_function($$) {
16431da177e4SLinus Torvalds    my $prototype = shift;
16441da177e4SLinus Torvalds    my $file = shift;
1645bb8fd09eSRandy Dunlap    my $func_macro = 0;
16461da177e4SLinus Torvalds
16475ef09c96SMauro Carvalho Chehab    print_lineno($new_start_line);
16485eb6b4b3SMauro Carvalho Chehab
16491da177e4SLinus Torvalds    $prototype =~ s/^static +//;
16501da177e4SLinus Torvalds    $prototype =~ s/^extern +//;
16514dc3b16bSPavel Pisa    $prototype =~ s/^asmlinkage +//;
16521da177e4SLinus Torvalds    $prototype =~ s/^inline +//;
16531da177e4SLinus Torvalds    $prototype =~ s/^__inline__ +//;
165432e79401SRandy Dunlap    $prototype =~ s/^__inline +//;
165532e79401SRandy Dunlap    $prototype =~ s/^__always_inline +//;
165632e79401SRandy Dunlap    $prototype =~ s/^noinline +//;
165703699f27SKees Cook    $prototype =~ s/^__FORTIFY_INLINE +//;
165874fc5c65SRandy Dunlap    $prototype =~ s/__init +//;
165920072205SRandy Dunlap    $prototype =~ s/__init_or_module +//;
166080342d48SMatthew Wilcox    $prototype =~ s/__deprecated +//;
1661084aa001SAditya Srivastava    $prototype =~ s/__flatten +//;
1662270a0096SRandy Dunlap    $prototype =~ s/__meminit +//;
166370c95b00SRandy Dunlap    $prototype =~ s/__must_check +//;
16640df7c0e3SRandy Dunlap    $prototype =~ s/__weak +//;
16650891f959SMatthew Wilcox    $prototype =~ s/__sched +//;
166651a7bf02SRandy Dunlap    $prototype =~ s/_noprof//;
166795e760cbSRandy Dunlap    $prototype =~ s/__printf\s*\(\s*\d*\s*,\s*\d*\s*\) +//;
166803699f27SKees Cook    $prototype =~ s/__(?:re)?alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\) +//;
166903699f27SKees Cook    $prototype =~ s/__diagnose_as\s*\(\s*\S+\s*(?:,\s*\d+\s*)*\) +//;
167067f2df3bSKees Cook    $prototype =~ s/DECL_BUCKET_PARAMS\s*\(\s*(\S+)\s*,\s*(\S+)\s*\)/$1, $2/;
1671cbb4d3e6SHoria Geanta    my $define = $prototype =~ s/^#\s*define\s+//; #ak added
1672084aa001SAditya Srivastava    $prototype =~ s/__attribute_const__ +//;
1673b1aaa546SPaolo Bonzini    $prototype =~ s/__attribute__\s*\(\(
1674b1aaa546SPaolo Bonzini            (?:
1675b1aaa546SPaolo Bonzini                 [\w\s]++          # attribute name
1676b1aaa546SPaolo Bonzini                 (?:\([^)]*+\))?   # attribute arguments
1677b1aaa546SPaolo Bonzini                 \s*+,?            # optional comma at the end
1678b1aaa546SPaolo Bonzini            )+
1679b1aaa546SPaolo Bonzini          \)\)\s+//x;
16801da177e4SLinus Torvalds
16811da177e4SLinus Torvalds    # Yes, this truly is vile.  We are looking for:
16821da177e4SLinus Torvalds    # 1. Return type (may be nothing if we're looking at a macro)
16831da177e4SLinus Torvalds    # 2. Function name
16841da177e4SLinus Torvalds    # 3. Function parameters.
16851da177e4SLinus Torvalds    #
16861da177e4SLinus Torvalds    # All the while we have to watch out for function pointer parameters
16871da177e4SLinus Torvalds    # (which IIRC is what the two sections are for), C types (these
16881da177e4SLinus Torvalds    # regexps don't even start to express all the possibilities), and
16891da177e4SLinus Torvalds    # so on.
16901da177e4SLinus Torvalds    #
16911da177e4SLinus Torvalds    # If you mess with these regexps, it's a good idea to check that
16921da177e4SLinus Torvalds    # the following functions' documentation still comes out right:
16931da177e4SLinus Torvalds    # - parport_register_device (function pointer parameters)
16941da177e4SLinus Torvalds    # - atomic_set (macro)
16959598f91fSMartin Waitz    # - pci_match_device, __copy_to_user (long return type)
1696e86bdb24SAditya Srivastava    my $name = qr{[a-zA-Z0-9_~:]+};
1697e86bdb24SAditya Srivastava    my $prototype_end1 = qr{[^\(]*};
1698e86bdb24SAditya Srivastava    my $prototype_end2 = qr{[^\{]*};
1699e86bdb24SAditya Srivastava    my $prototype_end = qr{\(($prototype_end1|$prototype_end2)\)};
1700e86bdb24SAditya Srivastava    my $type1 = qr{[\w\s]+};
1701e86bdb24SAditya Srivastava    my $type2 = qr{$type1\*+};
17021da177e4SLinus Torvalds
1703e86bdb24SAditya Srivastava    if ($define && $prototype =~ m/^()($name)\s+/) {
1704cbb4d3e6SHoria Geanta        # This is an object-like macro, it has no return type and no parameter
1705cbb4d3e6SHoria Geanta        # list.
1706cbb4d3e6SHoria Geanta        # Function-like macros are not allowed to have spaces between
1707cbb4d3e6SHoria Geanta        # declaration_name and opening parenthesis (notice the \s+).
1708cbb4d3e6SHoria Geanta        $return_type = $1;
1709cbb4d3e6SHoria Geanta        $declaration_name = $2;
1710bb8fd09eSRandy Dunlap        $func_macro = 1;
1711e86bdb24SAditya Srivastava    } elsif ($prototype =~ m/^()($name)\s*$prototype_end/ ||
1712e86bdb24SAditya Srivastava        $prototype =~ m/^($type1)\s+($name)\s*$prototype_end/ ||
1713e86bdb24SAditya Srivastava        $prototype =~ m/^($type2+)\s*($name)\s*$prototype_end/)  {
17141da177e4SLinus Torvalds        $return_type = $1;
17151da177e4SLinus Torvalds        $declaration_name = $2;
17161da177e4SLinus Torvalds        my $args = $3;
17171da177e4SLinus Torvalds
1718151c468bSMauro Carvalho Chehab        create_parameterlist($args, ',', $file, $declaration_name);
17191da177e4SLinus Torvalds    } else {
1720df4bf98eSNiklas Söderlund        emit_warning("${file}:$.", "cannot understand function prototype: '$prototype'\n");
17211da177e4SLinus Torvalds        return;
17221da177e4SLinus Torvalds    }
17231da177e4SLinus Torvalds
172452042e2dSMauro Carvalho Chehab    if ($identifier ne $declaration_name) {
1725df4bf98eSNiklas Söderlund        emit_warning("${file}:$.", "expecting prototype for $identifier(). Prototype was for $declaration_name() instead\n");
172652042e2dSMauro Carvalho Chehab        return;
172752042e2dSMauro Carvalho Chehab    }
172852042e2dSMauro Carvalho Chehab
1729a1d94aa5SRandy Dunlap    my $prms = join " ", @parameterlist;
17301081de2dSMauro Carvalho Chehab    check_sections($file, $declaration_name, "function", $sectcheck, $prms);
1731a1d94aa5SRandy Dunlap
17324092bac7SYacine Belkadi    # This check emits a lot of warnings at the moment, because many
17334092bac7SYacine Belkadi    # functions don't have a 'Return' doc section. So until the number
17344092bac7SYacine Belkadi    # of warnings goes sufficiently down, the check is only performed in
173556b0f453SJohannes Berg    # -Wreturn mode.
17364092bac7SYacine Belkadi    # TODO: always perform the check.
1737bb8fd09eSRandy Dunlap    if ($Wreturn && !$func_macro) {
17384092bac7SYacine Belkadi        check_return_section($file, $declaration_name, $return_type);
17394092bac7SYacine Belkadi    }
17404092bac7SYacine Belkadi
174147bcacfdSMauro Carvalho Chehab    # The function parser can be called with a typedef parameter.
174247bcacfdSMauro Carvalho Chehab    # Handle it.
174347bcacfdSMauro Carvalho Chehab    if ($return_type =~ /typedef/) {
174447bcacfdSMauro Carvalho Chehab        output_declaration($declaration_name,
174547bcacfdSMauro Carvalho Chehab                           'function',
174647bcacfdSMauro Carvalho Chehab                           {'function' => $declaration_name,
174747bcacfdSMauro Carvalho Chehab                            'typedef' => 1,
174847bcacfdSMauro Carvalho Chehab                            'module' => $modulename,
174947bcacfdSMauro Carvalho Chehab                            'functiontype' => $return_type,
175047bcacfdSMauro Carvalho Chehab                            'parameterlist' => \@parameterlist,
175147bcacfdSMauro Carvalho Chehab                            'parameterdescs' => \%parameterdescs,
175247bcacfdSMauro Carvalho Chehab                            'parametertypes' => \%parametertypes,
175347bcacfdSMauro Carvalho Chehab                            'sectionlist' => \@sectionlist,
175447bcacfdSMauro Carvalho Chehab                            'sections' => \%sections,
1755bb8fd09eSRandy Dunlap                            'purpose' => $declaration_purpose,
1756bb8fd09eSRandy Dunlap							'func_macro' => $func_macro
175747bcacfdSMauro Carvalho Chehab                           });
175847bcacfdSMauro Carvalho Chehab    } else {
17591da177e4SLinus Torvalds        output_declaration($declaration_name,
17601da177e4SLinus Torvalds                           'function',
17611da177e4SLinus Torvalds                           {'function' => $declaration_name,
17621da177e4SLinus Torvalds                            'module' => $modulename,
17631da177e4SLinus Torvalds                            'functiontype' => $return_type,
17641da177e4SLinus Torvalds                            'parameterlist' => \@parameterlist,
17651da177e4SLinus Torvalds                            'parameterdescs' => \%parameterdescs,
17661da177e4SLinus Torvalds                            'parametertypes' => \%parametertypes,
17671da177e4SLinus Torvalds                            'sectionlist' => \@sectionlist,
17681da177e4SLinus Torvalds                            'sections' => \%sections,
1769bb8fd09eSRandy Dunlap                            'purpose' => $declaration_purpose,
1770bb8fd09eSRandy Dunlap							'func_macro' => $func_macro
17711da177e4SLinus Torvalds                           });
17721da177e4SLinus Torvalds    }
177347bcacfdSMauro Carvalho Chehab}
17741da177e4SLinus Torvalds
17751da177e4SLinus Torvaldssub reset_state {
17761da177e4SLinus Torvalds    $function = "";
17771da177e4SLinus Torvalds    %parameterdescs = ();
17781da177e4SLinus Torvalds    %parametertypes = ();
17791da177e4SLinus Torvalds    @parameterlist = ();
17801da177e4SLinus Torvalds    %sections = ();
17811da177e4SLinus Torvalds    @sectionlist = ();
1782a1d94aa5SRandy Dunlap    $sectcheck = "";
1783a1d94aa5SRandy Dunlap    $struct_actual = "";
17841da177e4SLinus Torvalds    $prototype = "";
17851da177e4SLinus Torvalds
178648af606aSJani Nikula    $state = STATE_NORMAL;
178748af606aSJani Nikula    $inline_doc_state = STATE_INLINE_NA;
17881da177e4SLinus Torvalds}
17891da177e4SLinus Torvalds
179056afb0f8SJason Baronsub tracepoint_munge($) {
179156afb0f8SJason Baron    my $file = shift;
179256afb0f8SJason Baron    my $tracepointname = 0;
179356afb0f8SJason Baron    my $tracepointargs = 0;
179456afb0f8SJason Baron
179556afb0f8SJason Baron    if ($prototype =~ m/TRACE_EVENT\((.*?),/) {
179656afb0f8SJason Baron        $tracepointname = $1;
179756afb0f8SJason Baron    }
17983a9089fdSJason Baron    if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) {
17993a9089fdSJason Baron        $tracepointname = $1;
18003a9089fdSJason Baron    }
18013a9089fdSJason Baron    if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) {
18023a9089fdSJason Baron        $tracepointname = $2;
18033a9089fdSJason Baron    }
18043a9089fdSJason Baron    $tracepointname =~ s/^\s+//; #strip leading whitespace
180556afb0f8SJason Baron    if ($prototype =~ m/TP_PROTO\((.*?)\)/) {
180656afb0f8SJason Baron        $tracepointargs = $1;
180756afb0f8SJason Baron    }
180856afb0f8SJason Baron    if (($tracepointname eq 0) || ($tracepointargs eq 0)) {
1809df4bf98eSNiklas Söderlund        emit_warning("${file}:$.", "Unrecognized tracepoint format: \n".
1810df4bf98eSNiklas Söderlund                 "$prototype\n");
181156afb0f8SJason Baron    } else {
181256afb0f8SJason Baron        $prototype = "static inline void trace_$tracepointname($tracepointargs)";
181352042e2dSMauro Carvalho Chehab        $identifier = "trace_$identifier";
181456afb0f8SJason Baron    }
181556afb0f8SJason Baron}
181656afb0f8SJason Baron
1817b4870bc5SRandy Dunlapsub syscall_munge() {
1818b4870bc5SRandy Dunlap    my $void = 0;
1819b4870bc5SRandy Dunlap
18207c9aa015SMauro Carvalho Chehab    $prototype =~ s@[\r\n]+@ @gos; # strip newlines/CR's
1821b4870bc5SRandy Dunlap##    if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) {
1822b4870bc5SRandy Dunlap    if ($prototype =~ m/SYSCALL_DEFINE0/) {
1823b4870bc5SRandy Dunlap        $void = 1;
1824b4870bc5SRandy Dunlap##        $prototype = "long sys_$1(void)";
1825b4870bc5SRandy Dunlap    }
1826b4870bc5SRandy Dunlap
1827b4870bc5SRandy Dunlap    $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name
1828b4870bc5SRandy Dunlap    if ($prototype =~ m/long (sys_.*?),/) {
1829b4870bc5SRandy Dunlap        $prototype =~ s/,/\(/;
1830b4870bc5SRandy Dunlap    } elsif ($void) {
1831b4870bc5SRandy Dunlap        $prototype =~ s/\)/\(void\)/;
1832b4870bc5SRandy Dunlap    }
1833b4870bc5SRandy Dunlap
1834b4870bc5SRandy Dunlap    # now delete all of the odd-number commas in $prototype
1835b4870bc5SRandy Dunlap    # so that arg types & arg names don't have a comma between them
1836b4870bc5SRandy Dunlap    my $count = 0;
1837b4870bc5SRandy Dunlap    my $len = length($prototype);
1838b4870bc5SRandy Dunlap    if ($void) {
1839b4870bc5SRandy Dunlap        $len = 0;    # skip the for-loop
1840b4870bc5SRandy Dunlap    }
1841b4870bc5SRandy Dunlap    for (my $ix = 0; $ix < $len; $ix++) {
1842b4870bc5SRandy Dunlap        if (substr($prototype, $ix, 1) eq ',') {
1843b4870bc5SRandy Dunlap            $count++;
1844b4870bc5SRandy Dunlap            if ($count % 2 == 1) {
1845b4870bc5SRandy Dunlap                substr($prototype, $ix, 1) = ' ';
1846b4870bc5SRandy Dunlap            }
1847b4870bc5SRandy Dunlap        }
1848b4870bc5SRandy Dunlap    }
1849b4870bc5SRandy Dunlap}
1850b4870bc5SRandy Dunlap
1851b7afa92bSDaniel Vettersub process_proto_function($$) {
18521da177e4SLinus Torvalds    my $x = shift;
18531da177e4SLinus Torvalds    my $file = shift;
18541da177e4SLinus Torvalds
185551f5a0c8SRandy Dunlap    $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
185651f5a0c8SRandy Dunlap
1857d2a70e28SRandy Dunlap    if ($x =~ /^#/ && $x !~ /^#\s*define/) {
18581da177e4SLinus Torvalds        # do nothing
1859af404fb1SVegard Nossum    } elsif ($x =~ /([^\{]*)/) {
18601da177e4SLinus Torvalds        $prototype .= $1;
18611da177e4SLinus Torvalds    }
1862b4870bc5SRandy Dunlap
1863890c78c2SRandy Dunlap    if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) {
18641da177e4SLinus Torvalds        $prototype =~ s@/\*.*?\*/@@gos;        # strip comments.
18651da177e4SLinus Torvalds        $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
18661da177e4SLinus Torvalds        $prototype =~ s@^\s+@@gos; # strip leading spaces
18677ae281b0SMauro Carvalho Chehab
18687ae281b0SMauro Carvalho Chehab        # Handle prototypes for function pointers like:
18697ae281b0SMauro Carvalho Chehab        # int (*pcs_config)(struct foo)
18707ae281b0SMauro Carvalho Chehab        $prototype =~ s@^(\S+\s+)\(\s*\*(\S+)\)@$1$2@gos;
18717ae281b0SMauro Carvalho Chehab
1872b4870bc5SRandy Dunlap        if ($prototype =~ /SYSCALL_DEFINE/) {
1873b4870bc5SRandy Dunlap            syscall_munge();
1874b4870bc5SRandy Dunlap        }
18753a9089fdSJason Baron        if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ ||
18763a9089fdSJason Baron            $prototype =~ /DEFINE_SINGLE_EVENT/)
18773a9089fdSJason Baron        {
187856afb0f8SJason Baron            tracepoint_munge($file);
187956afb0f8SJason Baron        }
18801da177e4SLinus Torvalds        dump_function($prototype, $file);
18811da177e4SLinus Torvalds        reset_state();
18821da177e4SLinus Torvalds    }
18831da177e4SLinus Torvalds}
18841da177e4SLinus Torvalds
1885b7afa92bSDaniel Vettersub process_proto_type($$) {
18861da177e4SLinus Torvalds    my $x = shift;
18871da177e4SLinus Torvalds    my $file = shift;
18881da177e4SLinus Torvalds
18891da177e4SLinus Torvalds    $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
18901da177e4SLinus Torvalds    $x =~ s@^\s+@@gos; # strip leading spaces
18911da177e4SLinus Torvalds    $x =~ s@\s+$@@gos; # strip trailing spaces
189251f5a0c8SRandy Dunlap    $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
189351f5a0c8SRandy Dunlap
18941da177e4SLinus Torvalds    if ($x =~ /^#/) {
18951da177e4SLinus Torvalds        # To distinguish preprocessor directive from regular declaration later.
18961da177e4SLinus Torvalds        $x .= ";";
18971da177e4SLinus Torvalds    }
18981da177e4SLinus Torvalds
18991da177e4SLinus Torvalds    while (1) {
1900673bb2dfSBen Hutchings        if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ ) {
1901463a0fdcSMarkus Heiser            if( length $prototype ) {
1902463a0fdcSMarkus Heiser                $prototype .= " "
1903463a0fdcSMarkus Heiser            }
19041da177e4SLinus Torvalds            $prototype .= $1 . $2;
19051da177e4SLinus Torvalds            ($2 eq '{') && $brcount++;
19061da177e4SLinus Torvalds            ($2 eq '}') && $brcount--;
19071da177e4SLinus Torvalds            if (($2 eq ';') && ($brcount == 0)) {
19081da177e4SLinus Torvalds                dump_declaration($prototype, $file);
19091da177e4SLinus Torvalds                reset_state();
19101da177e4SLinus Torvalds                last;
19111da177e4SLinus Torvalds            }
19121da177e4SLinus Torvalds            $x = $3;
19131da177e4SLinus Torvalds        } else {
19141da177e4SLinus Torvalds            $prototype .= $x;
19151da177e4SLinus Torvalds            last;
19161da177e4SLinus Torvalds        }
19171da177e4SLinus Torvalds    }
19181da177e4SLinus Torvalds}
19191da177e4SLinus Torvalds
19206b5b55f6SRandy Dunlap
19211ad560e4SJani Nikulasub map_filename($) {
19221ad560e4SJani Nikula    my $file;
19231ad560e4SJani Nikula    my ($orig_file) = @_;
19241ad560e4SJani Nikula
19251ad560e4SJani Nikula    if (defined($ENV{'SRCTREE'})) {
19261ad560e4SJani Nikula        $file = "$ENV{'SRCTREE'}" . "/" . $orig_file;
19271ad560e4SJani Nikula    } else {
19281ad560e4SJani Nikula        $file = $orig_file;
19291ad560e4SJani Nikula    }
19301ad560e4SJani Nikula
19311ad560e4SJani Nikula    return $file;
19321ad560e4SJani Nikula}
19331ad560e4SJani Nikula
193488c2b57dSJani Nikulasub process_export_file($) {
193588c2b57dSJani Nikula    my ($orig_file) = @_;
193688c2b57dSJani Nikula    my $file = map_filename($orig_file);
193788c2b57dSJani Nikula
193888c2b57dSJani Nikula    if (!open(IN,"<$file")) {
193988c2b57dSJani Nikula        print STDERR "Error: Cannot open file $file\n";
194088c2b57dSJani Nikula        ++$errors;
194188c2b57dSJani Nikula        return;
194288c2b57dSJani Nikula    }
194388c2b57dSJani Nikula
194488c2b57dSJani Nikula    while (<IN>) {
194588c2b57dSJani Nikula        if (/$export_symbol/) {
1946eab795ddSMauro Carvalho Chehab            next if (defined($nosymbol_table{$2}));
194788c2b57dSJani Nikula            $function_table{$2} = 1;
194888c2b57dSJani Nikula        }
1949632ce137SJason Gunthorpe        if (/$export_symbol_ns/) {
1950632ce137SJason Gunthorpe            next if (defined($nosymbol_table{$2}));
1951632ce137SJason Gunthorpe            $function_table{$2} = 1;
1952632ce137SJason Gunthorpe        }
195388c2b57dSJani Nikula    }
195488c2b57dSJani Nikula
195588c2b57dSJani Nikula    close(IN);
195688c2b57dSJani Nikula}
195788c2b57dSJani Nikula
195807048d13SJonathan Corbet#
195907048d13SJonathan Corbet# Parsers for the various processing states.
196007048d13SJonathan Corbet#
196107048d13SJonathan Corbet# STATE_NORMAL: looking for the /** to begin everything.
196207048d13SJonathan Corbet#
196307048d13SJonathan Corbetsub process_normal() {
19641da177e4SLinus Torvalds    if (/$doc_start/o) {
196548af606aSJani Nikula        $state = STATE_NAME;        # next line is always the function name
1966850622dfSRandy Dunlap        $in_doc_sect = 0;
19670b0f5f29SDaniel Vetter        $declaration_start_line = $. + 1;
19681da177e4SLinus Torvalds    }
196907048d13SJonathan Corbet}
197007048d13SJonathan Corbet
19713cac2bc4SJonathan Corbet#
19723cac2bc4SJonathan Corbet# STATE_NAME: Looking for the "name - description" line
19733cac2bc4SJonathan Corbet#
19743cac2bc4SJonathan Corbetsub process_name($$) {
19753cac2bc4SJonathan Corbet    my $file = shift;
19761da177e4SLinus Torvalds    my $descr;
19771da177e4SLinus Torvalds
19781da177e4SLinus Torvalds    if (/$doc_block/o) {
197948af606aSJani Nikula        $state = STATE_DOCBLOCK;
19801da177e4SLinus Torvalds        $contents = "";
19815ef09c96SMauro Carvalho Chehab        $new_start_line = $.;
19820b0f5f29SDaniel Vetter
19831da177e4SLinus Torvalds        if ( $1 eq "" ) {
19841da177e4SLinus Torvalds            $section = $section_intro;
19851da177e4SLinus Torvalds        } else {
19861da177e4SLinus Torvalds            $section = $1;
19871da177e4SLinus Torvalds        }
198852042e2dSMauro Carvalho Chehab    } elsif (/$doc_decl/o) {
19891da177e4SLinus Torvalds        $identifier = $1;
19903e58e839SAditya Srivastava        my $is_kernel_comment = 0;
1991e86bdb24SAditya Srivastava        my $decl_start = qr{$doc_com};
1992f9bbc12cSAditya Srivastava        # test for pointer declaration type, foo * bar() - desc
1993f9bbc12cSAditya Srivastava        my $fn_type = qr{\w+\s*\*\s*};
1994f9bbc12cSAditya Srivastava        my $parenthesis = qr{\(\w*\)};
1995f9bbc12cSAditya Srivastava        my $decl_end = qr{[-:].*};
1996e86bdb24SAditya Srivastava        if (/^$decl_start([\w\s]+?)$parenthesis?\s*$decl_end?$/) {
19971da177e4SLinus Torvalds            $identifier = $1;
19981da177e4SLinus Torvalds        }
199952042e2dSMauro Carvalho Chehab        if ($identifier =~ m/^(struct|union|enum|typedef)\b\s*(\S*)/) {
200052042e2dSMauro Carvalho Chehab            $decl_type = $1;
200152042e2dSMauro Carvalho Chehab            $identifier = $2;
20023e58e839SAditya Srivastava            $is_kernel_comment = 1;
200352042e2dSMauro Carvalho Chehab        }
2004f9bbc12cSAditya Srivastava        # Look for foo() or static void foo() - description; or misspelt
2005f9bbc12cSAditya Srivastava        # identifier
2006e86bdb24SAditya Srivastava        elsif (/^$decl_start$fn_type?(\w+)\s*$parenthesis?\s*$decl_end?$/ ||
2007da3ecf00SVegard Nossum            /^$decl_start$fn_type?(\w+[^-:]*)$parenthesis?\s*$decl_end$/) {
2008f9bbc12cSAditya Srivastava            $identifier = $1;
2009f9bbc12cSAditya Srivastava            $decl_type = 'function';
2010f9bbc12cSAditya Srivastava            $identifier =~ s/^define\s+//;
2011f9bbc12cSAditya Srivastava            $is_kernel_comment = 1;
2012f9bbc12cSAditya Srivastava        }
201352042e2dSMauro Carvalho Chehab        $identifier =~ s/\s+$//;
20141da177e4SLinus Torvalds
201517b78717SJonathan Corbet        $state = STATE_BODY;
20160b0f5f29SDaniel Vetter        # if there's no @param blocks need to set up default section
20170b0f5f29SDaniel Vetter        # here
20182f4ad40aSJani Nikula        $contents = "";
20192f4ad40aSJani Nikula        $section = $section_default;
20200b0f5f29SDaniel Vetter        $new_start_line = $. + 1;
202152042e2dSMauro Carvalho Chehab        if (/[-:](.*)/) {
202251f5a0c8SRandy Dunlap            # strip leading/trailing/multiple spaces
2023a21217daSRandy Dunlap            $descr= $1;
2024a21217daSRandy Dunlap            $descr =~ s/^\s*//;
2025a21217daSRandy Dunlap            $descr =~ s/\s*$//;
202612ae6779SDaniel Santos            $descr =~ s/\s+/ /g;
20270bba924cSJonathan Corbet            $declaration_purpose = $descr;
202817b78717SJonathan Corbet            $state = STATE_BODY_MAYBE;
20291da177e4SLinus Torvalds        } else {
20301da177e4SLinus Torvalds            $declaration_purpose = "";
20311da177e4SLinus Torvalds        }
203277cc23b8SRandy Dunlap
20333e58e839SAditya Srivastava        if (!$is_kernel_comment) {
2034df4bf98eSNiklas Söderlund            emit_warning("${file}:$.", "This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst\n$_");
20353e58e839SAditya Srivastava            $state = STATE_NORMAL;
20363e58e839SAditya Srivastava        }
20373e58e839SAditya Srivastava
203856b0f453SJohannes Berg        if (($declaration_purpose eq "") && $Wshort_desc) {
2039df4bf98eSNiklas Söderlund            emit_warning("${file}:$.", "missing initial short description on line:\n$_");
204077cc23b8SRandy Dunlap        }
204177cc23b8SRandy Dunlap
20420b54c2e3SMauro Carvalho Chehab        if ($identifier eq "" && $decl_type ne "enum") {
2043df4bf98eSNiklas Söderlund            emit_warning("${file}:$.", "wrong kernel-doc identifier on line:\n$_");
204452042e2dSMauro Carvalho Chehab            $state = STATE_NORMAL;
20451da177e4SLinus Torvalds        }
20461da177e4SLinus Torvalds
20471da177e4SLinus Torvalds        if ($verbose) {
204852042e2dSMauro Carvalho Chehab            print STDERR "${file}:$.: info: Scanning doc for $decl_type $identifier\n";
20491da177e4SLinus Torvalds        }
20501da177e4SLinus Torvalds    } else {
2051df4bf98eSNiklas Söderlund        emit_warning("${file}:$.", "Cannot understand $_ on line $. - I thought it was a doc line\n");
205248af606aSJani Nikula        $state = STATE_NORMAL;
20531da177e4SLinus Torvalds    }
20543cac2bc4SJonathan Corbet}
20553cac2bc4SJonathan Corbet
20563cac2bc4SJonathan Corbet
2057d742f24dSJonathan Corbet#
2058d742f24dSJonathan Corbet# STATE_BODY and STATE_BODY_MAYBE: the bulk of a kerneldoc comment.
2059d742f24dSJonathan Corbet#
2060d742f24dSJonathan Corbetsub process_body($$) {
2061d742f24dSJonathan Corbet    my $file = shift;
20623cac2bc4SJonathan Corbet
20630d55d48bSMauro Carvalho Chehab    if ($state == STATE_BODY_WITH_BLANK_LINE && /^\s*\*\s?\S/) {
20640d55d48bSMauro Carvalho Chehab        dump_section($file, $section, $contents);
20650d55d48bSMauro Carvalho Chehab        $section = $section_default;
20665ef09c96SMauro Carvalho Chehab        $new_start_line = $.;
20670d55d48bSMauro Carvalho Chehab        $contents = "";
20680d55d48bSMauro Carvalho Chehab    }
20690d55d48bSMauro Carvalho Chehab
2070f624adefSJani Nikula    if (/$doc_sect/i) { # case insensitive for supported section names
2071afa751e8SRandy Dunlap        $in_doc_sect = 1;
20721da177e4SLinus Torvalds        $newsection = $1;
20731da177e4SLinus Torvalds        $newcontents = $2;
20741da177e4SLinus Torvalds
2075f624adefSJani Nikula        # map the supported section names to the canonical names
2076f624adefSJani Nikula        if ($newsection =~ m/^description$/i) {
2077f624adefSJani Nikula            $newsection = $section_default;
2078f624adefSJani Nikula        } elsif ($newsection =~ m/^context$/i) {
2079f624adefSJani Nikula            $newsection = $section_context;
2080f624adefSJani Nikula        } elsif ($newsection =~ m/^returns?$/i) {
2081f624adefSJani Nikula            $newsection = $section_return;
2082f624adefSJani Nikula        } elsif ($newsection =~ m/^\@return$/) {
2083f624adefSJani Nikula            # special: @return is a section, not a param description
2084f624adefSJani Nikula            $newsection = $section_return;
2085f624adefSJani Nikula        }
2086f624adefSJani Nikula
2087792aa2f2SRandy Dunlap        if (($contents ne "") && ($contents ne "\n")) {
208856b0f453SJohannes Berg            if (!$in_doc_sect && $Wcontents_before_sections) {
2089df4bf98eSNiklas Söderlund                emit_warning("${file}:$.", "contents before sections\n");
2090850622dfSRandy Dunlap            }
20910bba924cSJonathan Corbet            dump_section($file, $section, $contents);
20921da177e4SLinus Torvalds            $section = $section_default;
20931da177e4SLinus Torvalds        }
20941da177e4SLinus Torvalds
2095850622dfSRandy Dunlap        $in_doc_sect = 1;
209617b78717SJonathan Corbet        $state = STATE_BODY;
20971da177e4SLinus Torvalds        $contents = $newcontents;
20980b0f5f29SDaniel Vetter        $new_start_line = $.;
20997c9aa015SMauro Carvalho Chehab        while (substr($contents, 0, 1) eq " ") {
210005189497SRandy Dunlap            $contents = substr($contents, 1);
210105189497SRandy Dunlap        }
21020a726301SJani Nikula        if ($contents ne "") {
21031da177e4SLinus Torvalds            $contents .= "\n";
21041da177e4SLinus Torvalds        }
21051da177e4SLinus Torvalds        $section = $newsection;
2106b7886de4SJani Nikula        $leading_space = undef;
21071da177e4SLinus Torvalds    } elsif (/$doc_end/) {
21084c98ecafSRandy Dunlap        if (($contents ne "") && ($contents ne "\n")) {
21090bba924cSJonathan Corbet            dump_section($file, $section, $contents);
21101da177e4SLinus Torvalds            $section = $section_default;
21111da177e4SLinus Torvalds            $contents = "";
21121da177e4SLinus Torvalds        }
211346b958ebSRandy Dunlap        # look for doc_com + <text> + doc_end:
211446b958ebSRandy Dunlap        if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') {
2115df4bf98eSNiklas Söderlund            emit_warning("${file}:$.", "suspicious ending line: $_");
211646b958ebSRandy Dunlap        }
21171da177e4SLinus Torvalds
21181da177e4SLinus Torvalds        $prototype = "";
211948af606aSJani Nikula        $state = STATE_PROTO;
21201da177e4SLinus Torvalds        $brcount = 0;
21215ef09c96SMauro Carvalho Chehab        $new_start_line = $. + 1;
21221da177e4SLinus Torvalds    } elsif (/$doc_content/) {
21236423133bSJohannes Weiner        if ($1 eq "") {
21240d55d48bSMauro Carvalho Chehab            if ($section eq $section_context) {
21250bba924cSJonathan Corbet                dump_section($file, $section, $contents);
21261da177e4SLinus Torvalds                $section = $section_default;
21271da177e4SLinus Torvalds                $contents = "";
21280b0f5f29SDaniel Vetter                $new_start_line = $.;
21290d55d48bSMauro Carvalho Chehab                $state = STATE_BODY;
21301da177e4SLinus Torvalds            } else {
21310d55d48bSMauro Carvalho Chehab                if ($section ne $section_default) {
21320d55d48bSMauro Carvalho Chehab                    $state = STATE_BODY_WITH_BLANK_LINE;
21330d55d48bSMauro Carvalho Chehab                } else {
21340d55d48bSMauro Carvalho Chehab                    $state = STATE_BODY;
21350d55d48bSMauro Carvalho Chehab                }
21366423133bSJohannes Weiner                $contents .= "\n";
21376423133bSJohannes Weiner            }
213817b78717SJonathan Corbet        } elsif ($state == STATE_BODY_MAYBE) {
21396423133bSJohannes Weiner            # Continued declaration purpose
21406423133bSJohannes Weiner            chomp($declaration_purpose);
21410bba924cSJonathan Corbet            $declaration_purpose .= " " . $1;
214212ae6779SDaniel Santos            $declaration_purpose =~ s/\s+/ /g;
21436423133bSJohannes Weiner        } else {
2144b7886de4SJani Nikula            my $cont = $1;
2145b7886de4SJani Nikula            if ($section =~ m/^@/ || $section eq $section_context) {
2146b7886de4SJani Nikula                if (!defined $leading_space) {
2147b7886de4SJani Nikula                    if ($cont =~ m/^(\s+)/) {
2148b7886de4SJani Nikula                        $leading_space = $1;
2149b7886de4SJani Nikula                    } else {
2150b7886de4SJani Nikula                        $leading_space = "";
2151b7886de4SJani Nikula                    }
2152b7886de4SJani Nikula                }
2153b7886de4SJani Nikula                $cont =~ s/^$leading_space//;
2154b7886de4SJani Nikula            }
2155b7886de4SJani Nikula            $contents .= $cont . "\n";
21561da177e4SLinus Torvalds        }
21571da177e4SLinus Torvalds    } else {
21581da177e4SLinus Torvalds        # i dont know - bad line?  ignore.
2159df4bf98eSNiklas Söderlund        emit_warning("${file}:$.", "bad line: $_");
21601da177e4SLinus Torvalds    }
2161d742f24dSJonathan Corbet}
2162d742f24dSJonathan Corbet
2163d742f24dSJonathan Corbet
2164cc794812SJonathan Corbet#
2165cc794812SJonathan Corbet# STATE_PROTO: reading a function/whatever prototype.
2166cc794812SJonathan Corbet#
2167cc794812SJonathan Corbetsub process_proto($$) {
2168cc794812SJonathan Corbet    my $file = shift;
2169cc794812SJonathan Corbet
2170cc794812SJonathan Corbet    if (/$doc_inline_oneline/) {
2171cc794812SJonathan Corbet        $section = $1;
2172cc794812SJonathan Corbet        $contents = $2;
2173cc794812SJonathan Corbet        if ($contents ne "") {
2174cc794812SJonathan Corbet            $contents .= "\n";
2175cc794812SJonathan Corbet            dump_section($file, $section, $contents);
2176cc794812SJonathan Corbet            $section = $section_default;
2177cc794812SJonathan Corbet            $contents = "";
2178cc794812SJonathan Corbet        }
2179cc794812SJonathan Corbet    } elsif (/$doc_inline_start/) {
2180cc794812SJonathan Corbet        $state = STATE_INLINE;
2181cc794812SJonathan Corbet        $inline_doc_state = STATE_INLINE_NAME;
2182cc794812SJonathan Corbet    } elsif ($decl_type eq 'function') {
2183cc794812SJonathan Corbet        process_proto_function($_, $file);
2184cc794812SJonathan Corbet    } else {
2185cc794812SJonathan Corbet        process_proto_type($_, $file);
2186cc794812SJonathan Corbet    }
2187cc794812SJonathan Corbet}
2188cc794812SJonathan Corbet
2189c17add56SJonathan Corbet#
2190c17add56SJonathan Corbet# STATE_DOCBLOCK: within a DOC: block.
2191c17add56SJonathan Corbet#
2192c17add56SJonathan Corbetsub process_docblock($$) {
2193c17add56SJonathan Corbet    my $file = shift;
2194cc794812SJonathan Corbet
2195c17add56SJonathan Corbet    if (/$doc_end/) {
2196c17add56SJonathan Corbet        dump_doc_section($file, $section, $contents);
2197c17add56SJonathan Corbet        $section = $section_default;
2198c17add56SJonathan Corbet        $contents = "";
2199c17add56SJonathan Corbet        $function = "";
2200c17add56SJonathan Corbet        %parameterdescs = ();
2201c17add56SJonathan Corbet        %parametertypes = ();
2202c17add56SJonathan Corbet        @parameterlist = ();
2203c17add56SJonathan Corbet        %sections = ();
2204c17add56SJonathan Corbet        @sectionlist = ();
2205c17add56SJonathan Corbet        $prototype = "";
2206c17add56SJonathan Corbet        $state = STATE_NORMAL;
2207c17add56SJonathan Corbet    } elsif (/$doc_content/) {
2208c17add56SJonathan Corbet        if ( $1 eq "" )        {
2209c17add56SJonathan Corbet            $contents .= $blankline;
2210c17add56SJonathan Corbet        } else {
2211c17add56SJonathan Corbet            $contents .= $1 . "\n";
2212c17add56SJonathan Corbet        }
2213c17add56SJonathan Corbet    }
2214d742f24dSJonathan Corbet}
2215d742f24dSJonathan Corbet
2216c17add56SJonathan Corbet#
2217c17add56SJonathan Corbet# STATE_INLINE: docbook comments within a prototype.
2218c17add56SJonathan Corbet#
2219c17add56SJonathan Corbetsub process_inline($$) {
2220c17add56SJonathan Corbet    my $file = shift;
2221d742f24dSJonathan Corbet
2222a4c6ebedSDanilo Cesar Lemes de Paula    # First line (state 1) needs to be a @parameter
222348af606aSJani Nikula    if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) {
2224a4c6ebedSDanilo Cesar Lemes de Paula        $section = $1;
2225a4c6ebedSDanilo Cesar Lemes de Paula        $contents = $2;
22260b0f5f29SDaniel Vetter        $new_start_line = $.;
2227a4c6ebedSDanilo Cesar Lemes de Paula        if ($contents ne "") {
22287c9aa015SMauro Carvalho Chehab            while (substr($contents, 0, 1) eq " ") {
2229a4c6ebedSDanilo Cesar Lemes de Paula                $contents = substr($contents, 1);
2230a4c6ebedSDanilo Cesar Lemes de Paula            }
2231a4c6ebedSDanilo Cesar Lemes de Paula            $contents .= "\n";
2232a4c6ebedSDanilo Cesar Lemes de Paula        }
223348af606aSJani Nikula        $inline_doc_state = STATE_INLINE_TEXT;
2234a4c6ebedSDanilo Cesar Lemes de Paula        # Documentation block end */
223548af606aSJani Nikula    } elsif (/$doc_inline_end/) {
2236a4c6ebedSDanilo Cesar Lemes de Paula        if (($contents ne "") && ($contents ne "\n")) {
22370bba924cSJonathan Corbet            dump_section($file, $section, $contents);
2238a4c6ebedSDanilo Cesar Lemes de Paula            $section = $section_default;
2239a4c6ebedSDanilo Cesar Lemes de Paula            $contents = "";
2240a4c6ebedSDanilo Cesar Lemes de Paula        }
224148af606aSJani Nikula        $state = STATE_PROTO;
224248af606aSJani Nikula        $inline_doc_state = STATE_INLINE_NA;
2243a4c6ebedSDanilo Cesar Lemes de Paula        # Regular text
2244a4c6ebedSDanilo Cesar Lemes de Paula    } elsif (/$doc_content/) {
224548af606aSJani Nikula        if ($inline_doc_state == STATE_INLINE_TEXT) {
2246a4c6ebedSDanilo Cesar Lemes de Paula            $contents .= $1 . "\n";
22476450c895SJani Nikula            # nuke leading blank lines
22486450c895SJani Nikula            if ($contents =~ /^\s*$/) {
22496450c895SJani Nikula                $contents = "";
22506450c895SJani Nikula            }
225148af606aSJani Nikula        } elsif ($inline_doc_state == STATE_INLINE_NAME) {
225248af606aSJani Nikula            $inline_doc_state = STATE_INLINE_ERROR;
2253df4bf98eSNiklas Söderlund            emit_warning("${file}:$.", "Incorrect use of kernel-doc format: $_");
2254a4c6ebedSDanilo Cesar Lemes de Paula        }
2255a4c6ebedSDanilo Cesar Lemes de Paula    }
22560c9aa209SJani Nikula}
2257c17add56SJonathan Corbet
2258c17add56SJonathan Corbet
2259c17add56SJonathan Corbetsub process_file($) {
2260c17add56SJonathan Corbet    my $file;
2261c17add56SJonathan Corbet    my ($orig_file) = @_;
2262c17add56SJonathan Corbet
2263c17add56SJonathan Corbet    $file = map_filename($orig_file);
2264c17add56SJonathan Corbet
2265dbe8ba00SMauro Carvalho Chehab    if (!open(IN_FILE,"<$file")) {
2266c17add56SJonathan Corbet        print STDERR "Error: Cannot open file $file\n";
2267c17add56SJonathan Corbet        ++$errors;
2268c17add56SJonathan Corbet        return;
22691da177e4SLinus Torvalds    }
2270c17add56SJonathan Corbet
2271c17add56SJonathan Corbet    $. = 1;
2272c17add56SJonathan Corbet
2273c17add56SJonathan Corbet    $section_counter = 0;
2274dbe8ba00SMauro Carvalho Chehab    while (<IN_FILE>) {
2275e5a52766SAnna-Maria Behnsen        while (!/^ \*/ && s/\\\s*$//) {
2276dbe8ba00SMauro Carvalho Chehab            $_ .= <IN_FILE>;
2277c17add56SJonathan Corbet        }
2278c17add56SJonathan Corbet        # Replace tabs by spaces
2279c17add56SJonathan Corbet        while ($_ =~ s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e) {};
2280c17add56SJonathan Corbet        # Hand this line to the appropriate state handler
2281c17add56SJonathan Corbet        if ($state == STATE_NORMAL) {
2282c17add56SJonathan Corbet            process_normal();
2283c17add56SJonathan Corbet        } elsif ($state == STATE_NAME) {
2284c17add56SJonathan Corbet            process_name($file, $_);
22850d55d48bSMauro Carvalho Chehab        } elsif ($state == STATE_BODY || $state == STATE_BODY_MAYBE ||
22860d55d48bSMauro Carvalho Chehab                 $state == STATE_BODY_WITH_BLANK_LINE) {
2287c17add56SJonathan Corbet            process_body($file, $_);
2288c17add56SJonathan Corbet        } elsif ($state == STATE_INLINE) { # scanning for inline parameters
2289c17add56SJonathan Corbet            process_inline($file, $_);
2290cc794812SJonathan Corbet        } elsif ($state == STATE_PROTO) {
2291cc794812SJonathan Corbet            process_proto($file, $_);
229248af606aSJani Nikula        } elsif ($state == STATE_DOCBLOCK) {
2293c17add56SJonathan Corbet            process_docblock($file, $_);
22941da177e4SLinus Torvalds        }
22951da177e4SLinus Torvalds    }
2296c17add56SJonathan Corbet
2297c17add56SJonathan Corbet    # Make sure we got something interesting.
2298be926411SChen-Yu Tsai    if (!$section_counter && $output_mode ne "none") {
2299b0d60bfbSJonathan Corbet        if ($output_selection == OUTPUT_INCLUDE) {
2300df4bf98eSNiklas Söderlund            emit_warning("${file}:1", "'$_' not found\n")
2301b0d60bfbSJonathan Corbet                for keys %function_table;
2302af404fb1SVegard Nossum        } else {
2303df4bf98eSNiklas Söderlund            emit_warning("${file}:1", "no structured comments found\n");
2304e946c43aSJohannes Berg        }
23051da177e4SLinus Torvalds    }
2306dbe8ba00SMauro Carvalho Chehab    close IN_FILE;
23071da177e4SLinus Torvalds}
23088484baaaSRandy Dunlap
23098484baaaSRandy Dunlap$kernelversion = get_kernel_version();
23108484baaaSRandy Dunlap
23118484baaaSRandy Dunlap# generate a sequence of code that will splice in highlighting information
23128484baaaSRandy Dunlap# using the s// operator.
23131ef06233SMauro Carvalho Chehabfor (my $k = 0; $k < @highlights; $k++) {
23144d732701SDanilo Cesar Lemes de Paula    my $pattern = $highlights[$k][0];
23154d732701SDanilo Cesar Lemes de Paula    my $result = $highlights[$k][1];
23164d732701SDanilo Cesar Lemes de Paula#   print STDERR "scanning pattern:$pattern, highlight:($result)\n";
23174d732701SDanilo Cesar Lemes de Paula    $dohighlight .=  "\$contents =~ s:$pattern:$result:gs;\n";
23188484baaaSRandy Dunlap}
23198484baaaSRandy Dunlap
232088c2b57dSJani Nikulaif ($output_selection == OUTPUT_EXPORTED ||
232188c2b57dSJani Nikula    $output_selection == OUTPUT_INTERNAL) {
2322c9b2cfb3SJani Nikula
2323c9b2cfb3SJani Nikula    push(@export_file_list, @ARGV);
2324c9b2cfb3SJani Nikula
232588c2b57dSJani Nikula    foreach (@export_file_list) {
232688c2b57dSJani Nikula        chomp;
232788c2b57dSJani Nikula        process_export_file($_);
232888c2b57dSJani Nikula    }
232988c2b57dSJani Nikula}
233088c2b57dSJani Nikula
23318484baaaSRandy Dunlapforeach (@ARGV) {
23328484baaaSRandy Dunlap    chomp;
23338484baaaSRandy Dunlap    process_file($_);
23348484baaaSRandy Dunlap}
23358484baaaSRandy Dunlapif ($verbose && $errors) {
23368484baaaSRandy Dunlap    print STDERR "$errors errors\n";
23378484baaaSRandy Dunlap}
23388484baaaSRandy Dunlapif ($verbose && $warnings) {
23398484baaaSRandy Dunlap    print STDERR "$warnings warnings\n";
23408484baaaSRandy Dunlap}
23418484baaaSRandy Dunlap
23422c12c810SPierre-Louis Bossartif ($Werror && $warnings) {
23432c12c810SPierre-Louis Bossart    print STDERR "$warnings warnings as Errors\n";
23442c12c810SPierre-Louis Bossart    exit($warnings);
23452c12c810SPierre-Louis Bossart} else {
23462c12c810SPierre-Louis Bossart    exit($output_mode eq "none" ? 0 : $errors)
23472c12c810SPierre-Louis Bossart}
23482875f787STomasz Warniełło
23492875f787STomasz Warniełło__END__
23502875f787STomasz Warniełło
23512875f787STomasz Warniełło=head1 OPTIONS
23522875f787STomasz Warniełło
23532875f787STomasz Warniełło=head2 Output format selection (mutually exclusive):
23542875f787STomasz Warniełło
23552875f787STomasz Warniełło=over 8
23562875f787STomasz Warniełło
23572875f787STomasz Warniełło=item -man
23582875f787STomasz Warniełło
23592875f787STomasz WarniełłoOutput troff manual page format.
23602875f787STomasz Warniełło
23612875f787STomasz Warniełło=item -rst
23622875f787STomasz Warniełło
23632875f787STomasz WarniełłoOutput reStructuredText format. This is the default.
23642875f787STomasz Warniełło
23652875f787STomasz Warniełło=item -none
23662875f787STomasz Warniełło
23672875f787STomasz WarniełłoDo not output documentation, only warnings.
23682875f787STomasz Warniełło
23692875f787STomasz Warniełło=back
23702875f787STomasz Warniełło
2371dd803b04STomasz Warniełło=head2 Output format modifiers
2372dd803b04STomasz Warniełło
2373dd803b04STomasz Warniełło=head3 reStructuredText only
2374dd803b04STomasz Warniełło
23759c77f108STomasz Warniełło=head2 Output selection (mutually exclusive):
23769c77f108STomasz Warniełło
23779c77f108STomasz Warniełło=over 8
23789c77f108STomasz Warniełło
23799c77f108STomasz Warniełło=item -export
23809c77f108STomasz Warniełło
23819c77f108STomasz WarniełłoOnly output documentation for the symbols that have been exported using
2382632ce137SJason GunthorpeEXPORT_SYMBOL() and related macros in any input FILE or -export-file FILE.
23839c77f108STomasz Warniełło
23849c77f108STomasz Warniełło=item -internal
23859c77f108STomasz Warniełło
23869c77f108STomasz WarniełłoOnly output documentation for the symbols that have NOT been exported using
2387632ce137SJason GunthorpeEXPORT_SYMBOL() and related macros in any input FILE or -export-file FILE.
23889c77f108STomasz Warniełło
23899c77f108STomasz Warniełło=item -function NAME
23909c77f108STomasz Warniełło
23919c77f108STomasz WarniełłoOnly output documentation for the given function or DOC: section title.
23929c77f108STomasz WarniełłoAll other functions and DOC: sections are ignored.
23939c77f108STomasz Warniełło
23949c77f108STomasz WarniełłoMay be specified multiple times.
23959c77f108STomasz Warniełło
23969c77f108STomasz Warniełło=item -nosymbol NAME
23979c77f108STomasz Warniełło
23989c77f108STomasz WarniełłoExclude the specified symbol from the output documentation.
23999c77f108STomasz Warniełło
24009c77f108STomasz WarniełłoMay be specified multiple times.
24019c77f108STomasz Warniełło
24029c77f108STomasz Warniełło=back
24039c77f108STomasz Warniełło
2404c15de5a1STomasz Warniełło=head2 Output selection modifiers:
2405c15de5a1STomasz Warniełło
2406c15de5a1STomasz Warniełło=over 8
2407c15de5a1STomasz Warniełło
2408c15de5a1STomasz Warniełło=item -no-doc-sections
2409c15de5a1STomasz Warniełło
2410c15de5a1STomasz WarniełłoDo not output DOC: sections.
2411c15de5a1STomasz Warniełło
2412c15de5a1STomasz Warniełło=item -export-file FILE
2413c15de5a1STomasz Warniełło
2414632ce137SJason GunthorpeSpecify an additional FILE in which to look for EXPORT_SYMBOL information.
2415c15de5a1STomasz Warniełło
2416c15de5a1STomasz WarniełłoTo be used with -export or -internal.
2417c15de5a1STomasz Warniełło
2418c15de5a1STomasz WarniełłoMay be specified multiple times.
2419c15de5a1STomasz Warniełło
2420c15de5a1STomasz Warniełło=back
2421c15de5a1STomasz Warniełło
2422c15de5a1STomasz Warniełło=head3 reStructuredText only
2423c15de5a1STomasz Warniełło
2424c15de5a1STomasz Warniełło=over 8
2425c15de5a1STomasz Warniełło
2426c15de5a1STomasz Warniełło=item -enable-lineno
2427c15de5a1STomasz Warniełło
2428b79dfef0SMauro Carvalho ChehabEnable output of .. LINENO lines.
2429c15de5a1STomasz Warniełło
2430c15de5a1STomasz Warniełło=back
2431c15de5a1STomasz Warniełło
2432834cf6b9STomasz Warniełło=head2 Other parameters:
2433834cf6b9STomasz Warniełło
2434834cf6b9STomasz Warniełło=over 8
2435834cf6b9STomasz Warniełło
2436834cf6b9STomasz Warniełło=item -h, -help
2437834cf6b9STomasz Warniełło
2438834cf6b9STomasz WarniełłoPrint this help.
2439834cf6b9STomasz Warniełło
2440834cf6b9STomasz Warniełło=item -v
2441834cf6b9STomasz Warniełło
2442834cf6b9STomasz WarniełłoVerbose output, more warnings and other information.
2443834cf6b9STomasz Warniełło
2444834cf6b9STomasz Warniełło=item -Werror
2445834cf6b9STomasz Warniełło
2446834cf6b9STomasz WarniełłoTreat warnings as errors.
2447834cf6b9STomasz Warniełło
2448834cf6b9STomasz Warniełło=back
2449834cf6b9STomasz Warniełło
24502875f787STomasz Warniełło=cut
2451