| Kamil Rytarowski | cb77f0d | 2017-05-07 23:25:26 +0200 | [diff] [blame] | 1 | #!/usr/bin/env perl | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 |  | 
| Kamil Rytarowski | cb77f0d | 2017-05-07 23:25:26 +0200 | [diff] [blame] | 3 | use warnings; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | use strict; | 
|  | 5 |  | 
|  | 6 | ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved        ## | 
|  | 7 | ## Copyright (C) 2000, 1  Tim Waugh <twaugh@redhat.com>          ## | 
|  | 8 | ## Copyright (C) 2001  Simon Huggins                             ## | 
| Randy Dunlap | 70c95b0 | 2012-01-21 10:31:54 -0800 | [diff] [blame] | 9 | ## Copyright (C) 2005-2012  Randy Dunlap                         ## | 
| Dan Luedtke | 1b40c19 | 2012-08-12 10:46:15 +0200 | [diff] [blame] | 10 | ## Copyright (C) 2012  Dan Luedtke                               ## | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | ## 								 ## | 
|  | 12 | ## #define enhancements by Armin Kuster <akuster@mvista.com>	 ## | 
|  | 13 | ## Copyright (c) 2000 MontaVista Software, Inc.			 ## | 
|  | 14 | ## 								 ## | 
|  | 15 | ## This software falls under the GNU General Public License.     ## | 
|  | 16 | ## Please read the COPYING file for more information             ## | 
|  | 17 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | # 18/01/2001 - 	Cleanups | 
|  | 19 | # 		Functions prototyped as foo(void) same as foo() | 
|  | 20 | # 		Stop eval'ing where we don't need to. | 
|  | 21 | # -- huggie@earth.li | 
|  | 22 |  | 
|  | 23 | # 27/06/2001 -  Allowed whitespace after initial "/**" and | 
|  | 24 | #               allowed comments before function declarations. | 
|  | 25 | # -- Christian Kreibich <ck@whoop.org> | 
|  | 26 |  | 
|  | 27 | # Still to do: | 
|  | 28 | # 	- add perldoc documentation | 
|  | 29 | # 	- Look more closely at some of the scarier bits :) | 
|  | 30 |  | 
|  | 31 | # 26/05/2001 - 	Support for separate source and object trees. | 
|  | 32 | #		Return error code. | 
|  | 33 | # 		Keith Owens <kaos@ocs.com.au> | 
|  | 34 |  | 
|  | 35 | # 23/09/2001 - Added support for typedefs, structs, enums and unions | 
|  | 36 | #              Support for Context section; can be terminated using empty line | 
|  | 37 | #              Small fixes (like spaces vs. \s in regex) | 
|  | 38 | # -- Tim Jansen <tim@tjansen.de> | 
|  | 39 |  | 
| Dan Luedtke | 1b40c19 | 2012-08-12 10:46:15 +0200 | [diff] [blame] | 40 | # 25/07/2012 - Added support for HTML5 | 
|  | 41 | # -- Dan Luedtke <mail@danrl.de> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 |  | 
| Jani Nikula | fadc0b3 | 2016-05-12 16:15:36 +0300 | [diff] [blame] | 43 | sub usage { | 
|  | 44 | my $message = <<"EOF"; | 
|  | 45 | Usage: $0 [OPTION ...] FILE ... | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 |  | 
| Jani Nikula | fadc0b3 | 2016-05-12 16:15:36 +0300 | [diff] [blame] | 47 | Read C language source or header FILEs, extract embedded documentation comments, | 
|  | 48 | and print formatted documentation to standard output. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 |  | 
| Jani Nikula | fadc0b3 | 2016-05-12 16:15:36 +0300 | [diff] [blame] | 50 | The documentation comments are identified by "/**" opening comment mark. See | 
| Mauro Carvalho Chehab | 857af3b | 2017-12-18 10:30:08 -0200 | [diff] [blame] | 51 | Documentation/doc-guide/kernel-doc.rst for the documentation comment syntax. | 
| Jani Nikula | fadc0b3 | 2016-05-12 16:15:36 +0300 | [diff] [blame] | 52 |  | 
|  | 53 | Output format selection (mutually exclusive): | 
| Jani Nikula | fadc0b3 | 2016-05-12 16:15:36 +0300 | [diff] [blame] | 54 | -man			Output troff manual page format. This is the default. | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 55 | -rst			Output reStructuredText format. | 
| Matthew Wilcox | 3a025e1 | 2017-11-20 10:40:40 -0800 | [diff] [blame] | 56 | -none			Do not output documentation, only warnings. | 
| Jani Nikula | fadc0b3 | 2016-05-12 16:15:36 +0300 | [diff] [blame] | 57 |  | 
|  | 58 | Output selection (mutually exclusive): | 
| Jani Nikula | 86ae2e3 | 2016-01-21 13:05:22 +0200 | [diff] [blame] | 59 | -export		Only output documentation for symbols that have been | 
|  | 60 | exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() | 
| Jani Nikula | c9b2cfb | 2016-06-07 11:05:53 +0300 | [diff] [blame] | 61 | in any input FILE or -export-file FILE. | 
| Jani Nikula | 86ae2e3 | 2016-01-21 13:05:22 +0200 | [diff] [blame] | 62 | -internal		Only output documentation for symbols that have NOT been | 
|  | 63 | exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() | 
| Jani Nikula | c9b2cfb | 2016-06-07 11:05:53 +0300 | [diff] [blame] | 64 | in any input FILE or -export-file FILE. | 
| Jani Nikula | fadc0b3 | 2016-05-12 16:15:36 +0300 | [diff] [blame] | 65 | -function NAME	Only output documentation for the given function(s) | 
|  | 66 | or DOC: section title(s). All other functions and DOC: | 
|  | 67 | sections are ignored. May be specified multiple times. | 
|  | 68 | -nofunction NAME	Do NOT output documentation for the given function(s); | 
|  | 69 | only output documentation for the other functions and | 
|  | 70 | DOC: sections. May be specified multiple times. | 
|  | 71 |  | 
|  | 72 | Output selection modifiers: | 
|  | 73 | -no-doc-sections	Do not output DOC: sections. | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 74 | -enable-lineno        Enable output of #define LINENO lines. Only works with | 
|  | 75 | reStructuredText format. | 
| Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 76 | -export-file FILE     Specify an additional FILE in which to look for | 
|  | 77 | EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with | 
|  | 78 | -export or -internal. May be specified multiple times. | 
| Jani Nikula | fadc0b3 | 2016-05-12 16:15:36 +0300 | [diff] [blame] | 79 |  | 
|  | 80 | Other parameters: | 
|  | 81 | -v			Verbose output, more warnings and other information. | 
|  | 82 | -h			Print this help. | 
|  | 83 |  | 
|  | 84 | EOF | 
|  | 85 | print $message; | 
|  | 86 | exit 1; | 
|  | 87 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 |  | 
|  | 89 | # | 
|  | 90 | # format of comments. | 
|  | 91 | # In the following table, (...)? signifies optional structure. | 
|  | 92 | #                         (...)* signifies 0 or more structure elements | 
|  | 93 | # /** | 
|  | 94 | #  * function_name(:)? (- short description)? | 
|  | 95 | # (* @parameterx: (description of parameter x)?)* | 
|  | 96 | # (* a blank line)? | 
|  | 97 | #  * (Description:)? (Description of function)? | 
|  | 98 | #  * (section header: (section description)? )* | 
|  | 99 | #  (*)?*/ | 
|  | 100 | # | 
|  | 101 | # So .. the trivial example would be: | 
|  | 102 | # | 
|  | 103 | # /** | 
|  | 104 | #  * my_function | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 105 | #  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | # | 
| Randy Dunlap | 891dcd2 | 2007-02-10 01:45:53 -0800 | [diff] [blame] | 107 | # If the Description: header tag is omitted, then there must be a blank line | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | # after the last parameter specification. | 
|  | 109 | # e.g. | 
|  | 110 | # /** | 
|  | 111 | #  * my_function - does my stuff | 
|  | 112 | #  * @my_arg: its mine damnit | 
|  | 113 | #  * | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 114 | #  * Does my stuff explained. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | #  */ | 
|  | 116 | # | 
|  | 117 | #  or, could also use: | 
|  | 118 | # /** | 
|  | 119 | #  * my_function - does my stuff | 
|  | 120 | #  * @my_arg: its mine damnit | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 121 | #  * Description: Does my stuff explained. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | #  */ | 
|  | 123 | # etc. | 
|  | 124 | # | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 125 | # Besides functions you can also write documentation for structs, unions, | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 126 | # enums and typedefs. Instead of the function name you must write the name | 
|  | 127 | # of the declaration;  the struct/union/enum/typedef must always precede | 
|  | 128 | # the name. Nesting of declarations is not supported. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | # Use the argument mechanism to document members or constants. | 
|  | 130 | # e.g. | 
|  | 131 | # /** | 
|  | 132 | #  * struct my_struct - short description | 
|  | 133 | #  * @a: first member | 
|  | 134 | #  * @b: second member | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 135 | #  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | #  * Longer description | 
|  | 137 | #  */ | 
|  | 138 | # struct my_struct { | 
|  | 139 | #     int a; | 
|  | 140 | #     int b; | 
| Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 141 | # /* private: */ | 
|  | 142 | #     int c; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | # }; | 
|  | 144 | # | 
|  | 145 | # All descriptions can be multiline, except the short function description. | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 146 | # | 
| Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 147 | # For really longs structs, you can also describe arguments inside the | 
|  | 148 | # body of the struct. | 
|  | 149 | # eg. | 
|  | 150 | # /** | 
|  | 151 | #  * struct my_struct - short description | 
|  | 152 | #  * @a: first member | 
|  | 153 | #  * @b: second member | 
|  | 154 | #  * | 
|  | 155 | #  * Longer description | 
|  | 156 | #  */ | 
|  | 157 | # struct my_struct { | 
|  | 158 | #     int a; | 
|  | 159 | #     int b; | 
|  | 160 | #     /** | 
|  | 161 | #      * @c: This is longer description of C | 
|  | 162 | #      * | 
|  | 163 | #      * You can use paragraphs to describe arguments | 
|  | 164 | #      * using this method. | 
|  | 165 | #      */ | 
|  | 166 | #     int c; | 
|  | 167 | # }; | 
|  | 168 | # | 
|  | 169 | # This should be use only for struct/enum members. | 
|  | 170 | # | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 171 | # You can also add additional sections. When documenting kernel functions you | 
|  | 172 | # should document the "Context:" of the function, e.g. whether the functions | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | # can be called form interrupts. Unlike other sections you can end it with an | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 174 | # empty line. | 
| Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 175 | # A non-void function should have a "Return:" section describing the return | 
|  | 176 | # value(s). | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 177 | # Example-sections should contain the string EXAMPLE so that they are marked | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | # appropriately in DocBook. | 
|  | 179 | # | 
|  | 180 | # Example: | 
|  | 181 | # /** | 
|  | 182 | #  * user_function - function that can only be called in user context | 
|  | 183 | #  * @a: some argument | 
|  | 184 | #  * Context: !in_interrupt() | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 185 | #  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | #  * Some description | 
|  | 187 | #  * Example: | 
|  | 188 | #  *    user_function(22); | 
|  | 189 | #  */ | 
|  | 190 | # ... | 
|  | 191 | # | 
|  | 192 | # | 
|  | 193 | # All descriptive text is further processed, scanning for the following special | 
|  | 194 | # patterns, which are highlighted appropriately. | 
|  | 195 | # | 
|  | 196 | # 'funcname()' - function | 
|  | 197 | # '$ENVVAR' - environmental variable | 
|  | 198 | # '&struct_name' - name of a structure (up to two words including 'struct') | 
| Paolo Bonzini | 5267dd3 | 2017-01-02 16:22:26 +0100 | [diff] [blame] | 199 | # '&struct_name.member' - name of a structure member | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | # '@parameter' - name of a parameter | 
|  | 201 | # '%CONST' - name of a constant. | 
| Mauro Carvalho Chehab | b97f193 | 2017-03-30 17:11:28 -0300 | [diff] [blame] | 202 | # '``LITERAL``' - literal string without any spaces on it. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 |  | 
| Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 204 | ## init lots of data | 
|  | 205 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | my $errors = 0; | 
|  | 207 | my $warnings = 0; | 
| Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 208 | my $anon_struct_union = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 |  | 
|  | 210 | # match expressions used to find embedded type information | 
| Mauro Carvalho Chehab | b97f193 | 2017-03-30 17:11:28 -0300 | [diff] [blame] | 211 | my $type_constant = '\b``([^\`]+)``\b'; | 
|  | 212 | my $type_constant2 = '\%([-_\w]+)'; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | my $type_func = '(\w+)\(\)'; | 
| Silvio Fricke | c950a17 | 2016-10-28 10:14:08 +0200 | [diff] [blame] | 214 | my $type_param = '\@(\w+(\.\.\.)?)'; | 
| Jonathan Corbet | 5219f18 | 2016-08-24 16:31:15 -0600 | [diff] [blame] | 215 | my $type_fp_param = '\@(\w+)\(\)';  # Special RST handling for func ptr params | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | my $type_env = '(\$\w+)'; | 
| Paolo Bonzini | df31175 | 2017-01-02 16:22:27 +0100 | [diff] [blame] | 217 | my $type_enum = '\&(enum\s*([_\w]+))'; | 
|  | 218 | my $type_struct = '\&(struct\s*([_\w]+))'; | 
|  | 219 | my $type_typedef = '\&(typedef\s*([_\w]+))'; | 
|  | 220 | my $type_union = '\&(union\s*([_\w]+))'; | 
| Paolo Bonzini | 5267dd3 | 2017-01-02 16:22:26 +0100 | [diff] [blame] | 221 | my $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; | 
| Paolo Bonzini | df31175 | 2017-01-02 16:22:27 +0100 | [diff] [blame] | 222 | my $type_fallback = '\&([_\w]+)'; | 
| Jani Nikula | f3341dc | 2016-05-26 16:35:02 +0300 | [diff] [blame] | 223 | my $type_member_func = $type_member . '\(\)'; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 |  | 
|  | 225 | # Output conversion substitutions. | 
|  | 226 | #  One for each output format | 
|  | 227 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | # these are pretty rough | 
| Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 229 | my @highlights_man = ( | 
|  | 230 | [$type_constant, "\$1"], | 
| Mauro Carvalho Chehab | b97f193 | 2017-03-30 17:11:28 -0300 | [diff] [blame] | 231 | [$type_constant2, "\$1"], | 
| Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 232 | [$type_func, "\\\\fB\$1\\\\fP"], | 
| Paolo Bonzini | df31175 | 2017-01-02 16:22:27 +0100 | [diff] [blame] | 233 | [$type_enum, "\\\\fI\$1\\\\fP"], | 
| Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 234 | [$type_struct, "\\\\fI\$1\\\\fP"], | 
| Paolo Bonzini | df31175 | 2017-01-02 16:22:27 +0100 | [diff] [blame] | 235 | [$type_typedef, "\\\\fI\$1\\\\fP"], | 
|  | 236 | [$type_union, "\\\\fI\$1\\\\fP"], | 
| Paolo Bonzini | 5267dd3 | 2017-01-02 16:22:26 +0100 | [diff] [blame] | 237 | [$type_param, "\\\\fI\$1\\\\fP"], | 
| Paolo Bonzini | df31175 | 2017-01-02 16:22:27 +0100 | [diff] [blame] | 238 | [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], | 
|  | 239 | [$type_fallback, "\\\\fI\$1\\\\fP"] | 
| Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 240 | ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | my $blankline_man = ""; | 
|  | 242 |  | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 243 | # rst-mode | 
|  | 244 | my @highlights_rst = ( | 
|  | 245 | [$type_constant, "``\$1``"], | 
| Mauro Carvalho Chehab | b97f193 | 2017-03-30 17:11:28 -0300 | [diff] [blame] | 246 | [$type_constant2, "``\$1``"], | 
| Jani Nikula | f3341dc | 2016-05-26 16:35:02 +0300 | [diff] [blame] | 247 | # Note: need to escape () to avoid func matching later | 
| Paolo Bonzini | 5267dd3 | 2017-01-02 16:22:26 +0100 | [diff] [blame] | 248 | [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], | 
|  | 249 | [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], | 
| Jonathan Corbet | 5219f18 | 2016-08-24 16:31:15 -0600 | [diff] [blame] | 250 | [$type_fp_param, "**\$1\\\\(\\\\)**"], | 
| Jani Nikula | a19bce6 | 2016-05-26 11:28:16 +0300 | [diff] [blame] | 251 | [$type_func, "\\:c\\:func\\:`\$1()`"], | 
| Paolo Bonzini | df31175 | 2017-01-02 16:22:27 +0100 | [diff] [blame] | 252 | [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], | 
|  | 253 | [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`"], | 
|  | 254 | [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>`"], | 
|  | 255 | [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"], | 
| Jani Nikula | a7291e7 | 2016-05-26 13:57:06 +0300 | [diff] [blame] | 256 | # in rst this can refer to any type | 
| Paolo Bonzini | df31175 | 2017-01-02 16:22:27 +0100 | [diff] [blame] | 257 | [$type_fallback, "\\:c\\:type\\:`\$1`"], | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 258 | [$type_param, "**\$1**"] | 
|  | 259 | ); | 
|  | 260 | my $blankline_rst = "\n"; | 
|  | 261 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | # read arguments | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 263 | if ($#ARGV == -1) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | usage(); | 
|  | 265 | } | 
|  | 266 |  | 
| Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 267 | my $kernelversion; | 
|  | 268 | my $dohighlight = ""; | 
|  | 269 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | my $verbose = 0; | 
|  | 271 | my $output_mode = "man"; | 
| Daniel Santos | e314ba3 | 2012-10-04 17:15:08 -0700 | [diff] [blame] | 272 | my $output_preformatted = 0; | 
| Johannes Berg | 4b44595 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 273 | my $no_doc_sections = 0; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 274 | my $enable_lineno = 0; | 
| Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 275 | my @highlights = @highlights_man; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | my $blankline = $blankline_man; | 
|  | 277 | my $modulename = "Kernel API"; | 
| Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 278 |  | 
|  | 279 | use constant { | 
|  | 280 | OUTPUT_ALL          => 0, # output all symbols and doc sections | 
|  | 281 | OUTPUT_INCLUDE      => 1, # output only specified symbols | 
|  | 282 | OUTPUT_EXCLUDE      => 2, # output everything except specified symbols | 
|  | 283 | OUTPUT_EXPORTED     => 3, # output exported symbols | 
|  | 284 | OUTPUT_INTERNAL     => 4, # output non-exported symbols | 
|  | 285 | }; | 
|  | 286 | my $output_selection = OUTPUT_ALL; | 
| Ben Hutchings | b2c4105 | 2015-07-08 20:07:16 +0100 | [diff] [blame] | 287 | my $show_not_found = 0; | 
|  | 288 |  | 
| Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 289 | my @export_file_list; | 
|  | 290 |  | 
| Ben Hutchings | b2c4105 | 2015-07-08 20:07:16 +0100 | [diff] [blame] | 291 | my @build_time; | 
|  | 292 | if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && | 
|  | 293 | (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { | 
|  | 294 | @build_time = gmtime($seconds); | 
|  | 295 | } else { | 
|  | 296 | @build_time = localtime; | 
|  | 297 | } | 
|  | 298 |  | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 299 | my $man_date = ('January', 'February', 'March', 'April', 'May', 'June', | 
|  | 300 | 'July', 'August', 'September', 'October', | 
| Ben Hutchings | b2c4105 | 2015-07-08 20:07:16 +0100 | [diff] [blame] | 301 | 'November', 'December')[$build_time[4]] . | 
|  | 302 | " " . ($build_time[5]+1900); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 |  | 
| Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 304 | # Essentially these are globals. | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 305 | # They probably want to be tidied up, made more localised or something. | 
|  | 306 | # CAVEAT EMPTOR!  Some of the others I localised may not want to be, which | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | # could cause "use of undefined value" or other bugs. | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 308 | my ($function, %function_table, %parametertypes, $declaration_purpose); | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 309 | my $declaration_start_line; | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 310 | my ($type, $declaration_name, $return_type); | 
| Ilya Dryomov | 1c32fd0 | 2010-02-26 13:06:03 -0800 | [diff] [blame] | 311 | my ($newsection, $newcontents, $prototype, $brcount, %source_map); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 |  | 
| Randy Dunlap | bd0e88e | 2008-03-13 12:32:43 -0700 | [diff] [blame] | 313 | if (defined($ENV{'KBUILD_VERBOSE'})) { | 
|  | 314 | $verbose = "$ENV{'KBUILD_VERBOSE'}"; | 
|  | 315 | } | 
|  | 316 |  | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 317 | # Generated docbook code is inserted in a template at a point where | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | # docbook v3.1 requires a non-zero sequence of RefEntry's; see: | 
|  | 319 | # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html | 
|  | 320 | # We keep track of number of generated entries and generate a dummy | 
|  | 321 | # if needs be to ensure the expanded template can be postprocessed | 
|  | 322 | # into html. | 
|  | 323 | my $section_counter = 0; | 
|  | 324 |  | 
|  | 325 | my $lineprefix=""; | 
|  | 326 |  | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 327 | # Parser states | 
|  | 328 | use constant { | 
|  | 329 | STATE_NORMAL        => 0, # normal code | 
|  | 330 | STATE_NAME          => 1, # looking for function name | 
|  | 331 | STATE_FIELD         => 2, # scanning field start | 
|  | 332 | STATE_PROTO         => 3, # scanning prototype | 
|  | 333 | STATE_DOCBLOCK      => 4, # documentation block | 
|  | 334 | STATE_INLINE        => 5, # gathering documentation outside main block | 
|  | 335 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | my $state; | 
| Randy Dunlap | 850622d | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 337 | my $in_doc_sect; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 |  | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 339 | # Inline documentation state | 
|  | 340 | use constant { | 
|  | 341 | STATE_INLINE_NA     => 0, # not applicable ($state != STATE_INLINE) | 
|  | 342 | STATE_INLINE_NAME   => 1, # looking for member name (@foo:) | 
|  | 343 | STATE_INLINE_TEXT   => 2, # looking for member documentation | 
|  | 344 | STATE_INLINE_END    => 3, # done | 
|  | 345 | STATE_INLINE_ERROR  => 4, # error - Comment without header was found. | 
|  | 346 | # Spit a warning as it's not | 
|  | 347 | # proper kernel-doc and ignore the rest. | 
|  | 348 | }; | 
|  | 349 | my $inline_doc_state; | 
| Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 350 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | #declaration types: can be | 
|  | 352 | # 'function', 'struct', 'union', 'enum', 'typedef' | 
|  | 353 | my $decl_type; | 
|  | 354 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. | 
|  | 356 | my $doc_end = '\*/'; | 
|  | 357 | my $doc_com = '\s*\*\s*'; | 
| Daniel Santos | 12ae677 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 358 | my $doc_com_body = '\s*\* ?'; | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 359 | my $doc_decl = $doc_com . '(\w+)'; | 
| Jani Nikula | f624ade | 2016-05-29 11:35:28 +0300 | [diff] [blame] | 360 | # @params and a strictly limited set of supported section names | 
| Jonathan Corbet | 8569de6 | 2016-06-09 13:35:05 -0600 | [diff] [blame] | 361 | my $doc_sect = $doc_com . | 
| Jonathan Corbet | ef00028 | 2016-08-26 07:14:08 -0600 | [diff] [blame] | 362 | '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)'; | 
| Daniel Santos | 12ae677 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 363 | my $doc_content = $doc_com_body . '(.*)'; | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 364 | my $doc_block = $doc_com . 'DOC:\s*(.*)?'; | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 365 | my $doc_inline_start = '^\s*/\*\*\s*$'; | 
|  | 366 | my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)'; | 
|  | 367 | my $doc_inline_end = '^\s*\*/\s*$'; | 
| Jani Nikula | 0c9aa20 | 2016-11-16 17:26:16 +0200 | [diff] [blame] | 368 | my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s]+):\s*(.*)\s*\*/\s*$'; | 
| Jani Nikula | 86ae2e3 | 2016-01-21 13:05:22 +0200 | [diff] [blame] | 369 | my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | my %parameterdescs; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 372 | my %parameterdesc_start_lines; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | my @parameterlist; | 
|  | 374 | my %sections; | 
|  | 375 | my @sectionlist; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 376 | my %section_start_lines; | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 377 | my $sectcheck; | 
|  | 378 | my $struct_actual; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 |  | 
|  | 380 | my $contents = ""; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 381 | my $new_start_line = 0; | 
| Jani Nikula | f624ade | 2016-05-29 11:35:28 +0300 | [diff] [blame] | 382 |  | 
|  | 383 | # the canonical section names. see also $doc_sect above. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | my $section_default = "Description";	# default section | 
|  | 385 | my $section_intro = "Introduction"; | 
|  | 386 | my $section = $section_default; | 
|  | 387 | my $section_context = "Context"; | 
| Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 388 | my $section_return = "Return"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 |  | 
|  | 390 | my $undescribed = "-- undescribed --"; | 
|  | 391 |  | 
|  | 392 | reset_state(); | 
|  | 393 |  | 
|  | 394 | while ($ARGV[0] =~ m/^-(.*)/) { | 
|  | 395 | my $cmd = shift @ARGV; | 
| Mauro Carvalho Chehab | b051426 | 2017-12-18 10:30:09 -0200 | [diff] [blame^] | 396 | if ($cmd eq "-man") { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | $output_mode = "man"; | 
| Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 398 | @highlights = @highlights_man; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | $blankline = $blankline_man; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 400 | } elsif ($cmd eq "-rst") { | 
|  | 401 | $output_mode = "rst"; | 
|  | 402 | @highlights = @highlights_rst; | 
|  | 403 | $blankline = $blankline_rst; | 
| Matthew Wilcox | 3a025e1 | 2017-11-20 10:40:40 -0800 | [diff] [blame] | 404 | } elsif ($cmd eq "-none") { | 
|  | 405 | $output_mode = "none"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document | 
|  | 407 | $modulename = shift @ARGV; | 
|  | 408 | } elsif ($cmd eq "-function") { # to only output specific functions | 
| Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 409 | $output_selection = OUTPUT_INCLUDE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | $function = shift @ARGV; | 
|  | 411 | $function_table{$function} = 1; | 
| Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 412 | } elsif ($cmd eq "-nofunction") { # output all except specific functions | 
|  | 413 | $output_selection = OUTPUT_EXCLUDE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | $function = shift @ARGV; | 
|  | 415 | $function_table{$function} = 1; | 
| Jani Nikula | 86ae2e3 | 2016-01-21 13:05:22 +0200 | [diff] [blame] | 416 | } elsif ($cmd eq "-export") { # only exported symbols | 
| Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 417 | $output_selection = OUTPUT_EXPORTED; | 
| Jani Nikula | da9726e | 2016-06-07 10:29:59 +0300 | [diff] [blame] | 418 | %function_table = (); | 
| Jani Nikula | 86ae2e3 | 2016-01-21 13:05:22 +0200 | [diff] [blame] | 419 | } elsif ($cmd eq "-internal") { # only non-exported symbols | 
| Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 420 | $output_selection = OUTPUT_INTERNAL; | 
| Jani Nikula | da9726e | 2016-06-07 10:29:59 +0300 | [diff] [blame] | 421 | %function_table = (); | 
| Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 422 | } elsif ($cmd eq "-export-file") { | 
|  | 423 | my $file = shift @ARGV; | 
|  | 424 | push(@export_file_list, $file); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | } elsif ($cmd eq "-v") { | 
|  | 426 | $verbose = 1; | 
|  | 427 | } elsif (($cmd eq "-h") || ($cmd eq "--help")) { | 
|  | 428 | usage(); | 
| Johannes Berg | 4b44595 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 429 | } elsif ($cmd eq '-no-doc-sections') { | 
|  | 430 | $no_doc_sections = 1; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 431 | } elsif ($cmd eq '-enable-lineno') { | 
|  | 432 | $enable_lineno = 1; | 
| Johannes Berg | e946c43a | 2013-11-12 15:11:12 -0800 | [diff] [blame] | 433 | } elsif ($cmd eq '-show-not-found') { | 
|  | 434 | $show_not_found = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | } | 
|  | 436 | } | 
|  | 437 |  | 
| Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 438 | # continue execution near EOF; | 
|  | 439 |  | 
| Borislav Petkov | 53f049f | 2007-05-08 00:30:54 -0700 | [diff] [blame] | 440 | # get kernel version from env | 
|  | 441 | sub get_kernel_version() { | 
| Johannes Berg | 1b9bc22 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 442 | my $version = 'unknown kernel version'; | 
| Borislav Petkov | 53f049f | 2007-05-08 00:30:54 -0700 | [diff] [blame] | 443 |  | 
|  | 444 | if (defined($ENV{'KERNELVERSION'})) { | 
|  | 445 | $version = $ENV{'KERNELVERSION'}; | 
|  | 446 | } | 
|  | 447 | return $version; | 
|  | 448 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 |  | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 450 | # | 
|  | 451 | sub print_lineno { | 
|  | 452 | my $lineno = shift; | 
|  | 453 | if ($enable_lineno && defined($lineno)) { | 
|  | 454 | print "#define LINENO " . $lineno . "\n"; | 
|  | 455 | } | 
|  | 456 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | ## | 
|  | 458 | # dumps section contents to arrays/hashes intended for that purpose. | 
|  | 459 | # | 
|  | 460 | sub dump_section { | 
| Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 461 | my $file = shift; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | my $name = shift; | 
|  | 463 | my $contents = join "\n", @_; | 
|  | 464 |  | 
| Jani Nikula | 13901ef | 2016-05-26 08:57:29 +0300 | [diff] [blame] | 465 | if ($name =~ m/$type_param/) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | $name = $1; | 
|  | 467 | $parameterdescs{$name} = $contents; | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 468 | $sectcheck = $sectcheck . $name . " "; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 469 | $parameterdesc_start_lines{$name} = $new_start_line; | 
|  | 470 | $new_start_line = 0; | 
| Randy Dunlap | ced6909 | 2008-12-01 13:14:03 -0800 | [diff] [blame] | 471 | } elsif ($name eq "@\.\.\.") { | 
| Randy Dunlap | ced6909 | 2008-12-01 13:14:03 -0800 | [diff] [blame] | 472 | $name = "..."; | 
|  | 473 | $parameterdescs{$name} = $contents; | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 474 | $sectcheck = $sectcheck . $name . " "; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 475 | $parameterdesc_start_lines{$name} = $new_start_line; | 
|  | 476 | $new_start_line = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | } else { | 
| Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 478 | if (defined($sections{$name}) && ($sections{$name} ne "")) { | 
| Jani Nikula | 95b6be9 | 2016-06-10 11:14:05 +0300 | [diff] [blame] | 479 | # Only warn on user specified duplicate section names. | 
|  | 480 | if ($name ne $section_default) { | 
|  | 481 | print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; | 
|  | 482 | ++$warnings; | 
|  | 483 | } | 
| Jani Nikula | 3221776 | 2016-05-29 09:40:44 +0300 | [diff] [blame] | 484 | $sections{$name} .= $contents; | 
|  | 485 | } else { | 
|  | 486 | $sections{$name} = $contents; | 
|  | 487 | push @sectionlist, $name; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 488 | $section_start_lines{$name} = $new_start_line; | 
|  | 489 | $new_start_line = 0; | 
| Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 490 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | } | 
|  | 492 | } | 
|  | 493 |  | 
|  | 494 | ## | 
| Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 495 | # dump DOC: section after checking that it should go out | 
|  | 496 | # | 
|  | 497 | sub dump_doc_section { | 
| Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 498 | my $file = shift; | 
| Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 499 | my $name = shift; | 
|  | 500 | my $contents = join "\n", @_; | 
|  | 501 |  | 
| Johannes Berg | 4b44595 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 502 | if ($no_doc_sections) { | 
|  | 503 | return; | 
|  | 504 | } | 
|  | 505 |  | 
| Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 506 | if (($output_selection == OUTPUT_ALL) || | 
|  | 507 | ($output_selection == OUTPUT_INCLUDE && | 
|  | 508 | defined($function_table{$name})) || | 
|  | 509 | ($output_selection == OUTPUT_EXCLUDE && | 
|  | 510 | !defined($function_table{$name}))) | 
| Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 511 | { | 
| Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 512 | dump_section($file, $name, $contents); | 
| Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 513 | output_blockhead({'sectionlist' => \@sectionlist, | 
|  | 514 | 'sections' => \%sections, | 
|  | 515 | 'module' => $modulename, | 
| Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 516 | 'content-only' => ($output_selection != OUTPUT_ALL), }); | 
| Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 517 | } | 
|  | 518 | } | 
|  | 519 |  | 
|  | 520 | ## | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | # output function | 
|  | 522 | # | 
|  | 523 | # parameterdescs, a hash. | 
|  | 524 | #  function => "function name" | 
|  | 525 | #  parameterlist => @list of parameters | 
|  | 526 | #  parameterdescs => %parameter descriptions | 
|  | 527 | #  sectionlist => @list of sections | 
| Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 528 | #  sections => %section descriptions | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 529 | # | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 |  | 
|  | 531 | sub output_highlight { | 
|  | 532 | my $contents = join "\n",@_; | 
|  | 533 | my $line; | 
|  | 534 |  | 
|  | 535 | #   DEBUG | 
|  | 536 | #   if (!defined $contents) { | 
|  | 537 | #	use Carp; | 
|  | 538 | #	confess "output_highlight got called with no args?\n"; | 
|  | 539 | #   } | 
|  | 540 |  | 
| Randy Dunlap | 3eb014a | 2007-05-08 00:29:51 -0700 | [diff] [blame] | 541 | #   print STDERR "contents b4:$contents\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | eval $dohighlight; | 
|  | 543 | die $@ if $@; | 
| Randy Dunlap | 3eb014a | 2007-05-08 00:29:51 -0700 | [diff] [blame] | 544 | #   print STDERR "contents af:$contents\n"; | 
|  | 545 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | foreach $line (split "\n", $contents) { | 
| Daniel Santos | 12ae677 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 547 | if (! $output_preformatted) { | 
|  | 548 | $line =~ s/^\s*//; | 
|  | 549 | } | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 550 | if ($line eq ""){ | 
| Daniel Santos | e314ba3 | 2012-10-04 17:15:08 -0700 | [diff] [blame] | 551 | if (! $output_preformatted) { | 
|  | 552 | print $lineprefix, local_unescape($blankline); | 
|  | 553 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | } else { | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 555 | $line =~ s/\\\\\\/\&/g; | 
| Randy Dunlap | cdccb31 | 2007-07-19 01:48:25 -0700 | [diff] [blame] | 556 | if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { | 
|  | 557 | print "\\&$line"; | 
|  | 558 | } else { | 
|  | 559 | print $lineprefix, $line; | 
|  | 560 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | } | 
|  | 562 | print "\n"; | 
|  | 563 | } | 
|  | 564 | } | 
|  | 565 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | ## | 
|  | 567 | # output function in man | 
|  | 568 | sub output_function_man(%) { | 
|  | 569 | my %args = %{$_[0]}; | 
|  | 570 | my ($parameter, $section); | 
|  | 571 | my $count; | 
|  | 572 |  | 
|  | 573 | print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; | 
|  | 574 |  | 
|  | 575 | print ".SH NAME\n"; | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 576 | print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 |  | 
|  | 578 | print ".SH SYNOPSIS\n"; | 
| Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 579 | if ($args{'functiontype'} ne "") { | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 580 | print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; | 
| Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 581 | } else { | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 582 | print ".B \"" . $args{'function'} . "\n"; | 
| Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 583 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | $count = 0; | 
|  | 585 | my $parenth = "("; | 
|  | 586 | my $post = ","; | 
|  | 587 | foreach my $parameter (@{$args{'parameterlist'}}) { | 
|  | 588 | if ($count == $#{$args{'parameterlist'}}) { | 
|  | 589 | $post = ");"; | 
|  | 590 | } | 
|  | 591 | $type = $args{'parametertypes'}{$parameter}; | 
|  | 592 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | 
|  | 593 | # pointer-to-function | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 594 | print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | } else { | 
|  | 596 | $type =~ s/([^\*])$/$1 /; | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 597 | print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | } | 
|  | 599 | $count++; | 
|  | 600 | $parenth = ""; | 
|  | 601 | } | 
|  | 602 |  | 
|  | 603 | print ".SH ARGUMENTS\n"; | 
|  | 604 | foreach $parameter (@{$args{'parameterlist'}}) { | 
|  | 605 | my $parameter_name = $parameter; | 
|  | 606 | $parameter_name =~ s/\[.*//; | 
|  | 607 |  | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 608 | print ".IP \"" . $parameter . "\" 12\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | output_highlight($args{'parameterdescs'}{$parameter_name}); | 
|  | 610 | } | 
|  | 611 | foreach $section (@{$args{'sectionlist'}}) { | 
|  | 612 | print ".SH \"", uc $section, "\"\n"; | 
|  | 613 | output_highlight($args{'sections'}{$section}); | 
|  | 614 | } | 
|  | 615 | } | 
|  | 616 |  | 
|  | 617 | ## | 
|  | 618 | # output enum in man | 
|  | 619 | sub output_enum_man(%) { | 
|  | 620 | my %args = %{$_[0]}; | 
|  | 621 | my ($parameter, $section); | 
|  | 622 | my $count; | 
|  | 623 |  | 
|  | 624 | print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; | 
|  | 625 |  | 
|  | 626 | print ".SH NAME\n"; | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 627 | print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 |  | 
|  | 629 | print ".SH SYNOPSIS\n"; | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 630 | print "enum " . $args{'enum'} . " {\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | $count = 0; | 
|  | 632 | foreach my $parameter (@{$args{'parameterlist'}}) { | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 633 | print ".br\n.BI \"    $parameter\"\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | if ($count == $#{$args{'parameterlist'}}) { | 
|  | 635 | print "\n};\n"; | 
|  | 636 | last; | 
|  | 637 | } | 
|  | 638 | else { | 
|  | 639 | print ", \n.br\n"; | 
|  | 640 | } | 
|  | 641 | $count++; | 
|  | 642 | } | 
|  | 643 |  | 
|  | 644 | print ".SH Constants\n"; | 
|  | 645 | foreach $parameter (@{$args{'parameterlist'}}) { | 
|  | 646 | my $parameter_name = $parameter; | 
|  | 647 | $parameter_name =~ s/\[.*//; | 
|  | 648 |  | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 649 | print ".IP \"" . $parameter . "\" 12\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | output_highlight($args{'parameterdescs'}{$parameter_name}); | 
|  | 651 | } | 
|  | 652 | foreach $section (@{$args{'sectionlist'}}) { | 
|  | 653 | print ".SH \"$section\"\n"; | 
|  | 654 | output_highlight($args{'sections'}{$section}); | 
|  | 655 | } | 
|  | 656 | } | 
|  | 657 |  | 
|  | 658 | ## | 
|  | 659 | # output struct in man | 
|  | 660 | sub output_struct_man(%) { | 
|  | 661 | my %args = %{$_[0]}; | 
|  | 662 | my ($parameter, $section); | 
|  | 663 |  | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 664 | print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 |  | 
|  | 666 | print ".SH NAME\n"; | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 667 | print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 |  | 
|  | 669 | print ".SH SYNOPSIS\n"; | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 670 | print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 |  | 
|  | 672 | foreach my $parameter (@{$args{'parameterlist'}}) { | 
|  | 673 | if ($parameter =~ /^#/) { | 
|  | 674 | print ".BI \"$parameter\"\n.br\n"; | 
|  | 675 | next; | 
|  | 676 | } | 
|  | 677 | my $parameter_name = $parameter; | 
|  | 678 | $parameter_name =~ s/\[.*//; | 
|  | 679 |  | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 680 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | $type = $args{'parametertypes'}{$parameter}; | 
|  | 682 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | 
|  | 683 | # pointer-to-function | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 684 | print ".BI \"    " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { | 
| Randy.Dunlap | 1d7e1d4 | 2006-07-01 04:36:34 -0700 | [diff] [blame] | 686 | # bitfield | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 687 | print ".BI \"    " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | } else { | 
|  | 689 | $type =~ s/([^\*])$/$1 /; | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 690 | print ".BI \"    " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | } | 
|  | 692 | print "\n.br\n"; | 
|  | 693 | } | 
|  | 694 | print "};\n.br\n"; | 
|  | 695 |  | 
| Randy Dunlap | c51d3da | 2006-06-25 05:49:14 -0700 | [diff] [blame] | 696 | print ".SH Members\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | foreach $parameter (@{$args{'parameterlist'}}) { | 
|  | 698 | ($parameter =~ /^#/) && next; | 
|  | 699 |  | 
|  | 700 | my $parameter_name = $parameter; | 
|  | 701 | $parameter_name =~ s/\[.*//; | 
|  | 702 |  | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 703 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 704 | print ".IP \"" . $parameter . "\" 12\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | output_highlight($args{'parameterdescs'}{$parameter_name}); | 
|  | 706 | } | 
|  | 707 | foreach $section (@{$args{'sectionlist'}}) { | 
|  | 708 | print ".SH \"$section\"\n"; | 
|  | 709 | output_highlight($args{'sections'}{$section}); | 
|  | 710 | } | 
|  | 711 | } | 
|  | 712 |  | 
|  | 713 | ## | 
|  | 714 | # output typedef in man | 
|  | 715 | sub output_typedef_man(%) { | 
|  | 716 | my %args = %{$_[0]}; | 
|  | 717 | my ($parameter, $section); | 
|  | 718 |  | 
|  | 719 | print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; | 
|  | 720 |  | 
|  | 721 | print ".SH NAME\n"; | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 722 | print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 |  | 
|  | 724 | foreach $section (@{$args{'sectionlist'}}) { | 
|  | 725 | print ".SH \"$section\"\n"; | 
|  | 726 | output_highlight($args{'sections'}{$section}); | 
|  | 727 | } | 
|  | 728 | } | 
|  | 729 |  | 
| Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 730 | sub output_blockhead_man(%) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | my %args = %{$_[0]}; | 
|  | 732 | my ($parameter, $section); | 
|  | 733 | my $count; | 
|  | 734 |  | 
|  | 735 | print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; | 
|  | 736 |  | 
|  | 737 | foreach $section (@{$args{'sectionlist'}}) { | 
|  | 738 | print ".SH \"$section\"\n"; | 
|  | 739 | output_highlight($args{'sections'}{$section}); | 
|  | 740 | } | 
|  | 741 | } | 
|  | 742 |  | 
|  | 743 | ## | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 744 | # output in restructured text | 
|  | 745 | # | 
|  | 746 |  | 
|  | 747 | # | 
|  | 748 | # This could use some work; it's used to output the DOC: sections, and | 
|  | 749 | # starts by putting out the name of the doc section itself, but that tends | 
|  | 750 | # to duplicate a header already in the template file. | 
|  | 751 | # | 
|  | 752 | sub output_blockhead_rst(%) { | 
|  | 753 | my %args = %{$_[0]}; | 
|  | 754 | my ($parameter, $section); | 
|  | 755 |  | 
|  | 756 | foreach $section (@{$args{'sectionlist'}}) { | 
| Jani Nikula | 9e72184 | 2016-05-29 22:27:35 +0300 | [diff] [blame] | 757 | if ($output_selection != OUTPUT_INCLUDE) { | 
|  | 758 | print "**$section**\n\n"; | 
|  | 759 | } | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 760 | print_lineno($section_start_lines{$section}); | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 761 | output_highlight_rst($args{'sections'}{$section}); | 
|  | 762 | print "\n"; | 
|  | 763 | } | 
|  | 764 | } | 
|  | 765 |  | 
|  | 766 | sub output_highlight_rst { | 
|  | 767 | my $contents = join "\n",@_; | 
|  | 768 | my $line; | 
|  | 769 |  | 
|  | 770 | # undo the evil effects of xml_escape() earlier | 
|  | 771 | $contents = xml_unescape($contents); | 
|  | 772 |  | 
|  | 773 | eval $dohighlight; | 
|  | 774 | die $@ if $@; | 
|  | 775 |  | 
|  | 776 | foreach $line (split "\n", $contents) { | 
| Jani Nikula | 830066a | 2016-05-26 22:04:33 +0300 | [diff] [blame] | 777 | print $lineprefix . $line . "\n"; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 778 | } | 
|  | 779 | } | 
|  | 780 |  | 
|  | 781 | sub output_function_rst(%) { | 
|  | 782 | my %args = %{$_[0]}; | 
|  | 783 | my ($parameter, $section); | 
| Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 784 | my $oldprefix = $lineprefix; | 
| Mauro Carvalho Chehab | 82801d0 | 2016-08-30 20:20:58 -0300 | [diff] [blame] | 785 | my $start = ""; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 786 |  | 
| Mauro Carvalho Chehab | 82801d0 | 2016-08-30 20:20:58 -0300 | [diff] [blame] | 787 | if ($args{'typedef'}) { | 
|  | 788 | print ".. c:type:: ". $args{'function'} . "\n\n"; | 
|  | 789 | print_lineno($declaration_start_line); | 
|  | 790 | print "   **Typedef**: "; | 
|  | 791 | $lineprefix = ""; | 
|  | 792 | output_highlight_rst($args{'purpose'}); | 
|  | 793 | $start = "\n\n**Syntax**\n\n  ``"; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 794 | } else { | 
| Mauro Carvalho Chehab | 82801d0 | 2016-08-30 20:20:58 -0300 | [diff] [blame] | 795 | print ".. c:function:: "; | 
|  | 796 | } | 
|  | 797 | if ($args{'functiontype'} ne "") { | 
|  | 798 | $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; | 
|  | 799 | } else { | 
|  | 800 | $start .= $args{'function'} . " ("; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 801 | } | 
|  | 802 | print $start; | 
|  | 803 |  | 
|  | 804 | my $count = 0; | 
|  | 805 | foreach my $parameter (@{$args{'parameterlist'}}) { | 
|  | 806 | if ($count ne 0) { | 
|  | 807 | print ", "; | 
|  | 808 | } | 
|  | 809 | $count++; | 
|  | 810 | $type = $args{'parametertypes'}{$parameter}; | 
| Mauro Carvalho Chehab | a88b167 | 2016-07-22 11:46:36 -0300 | [diff] [blame] | 811 |  | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 812 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | 
|  | 813 | # pointer-to-function | 
|  | 814 | print $1 . $parameter . ") (" . $2; | 
|  | 815 | } else { | 
|  | 816 | print $type . " " . $parameter; | 
|  | 817 | } | 
|  | 818 | } | 
| Mauro Carvalho Chehab | 82801d0 | 2016-08-30 20:20:58 -0300 | [diff] [blame] | 819 | if ($args{'typedef'}) { | 
|  | 820 | print ");``\n\n"; | 
|  | 821 | } else { | 
|  | 822 | print ")\n\n"; | 
|  | 823 | print_lineno($declaration_start_line); | 
|  | 824 | $lineprefix = "   "; | 
|  | 825 | output_highlight_rst($args{'purpose'}); | 
|  | 826 | print "\n"; | 
|  | 827 | } | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 828 |  | 
| Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 829 | print "**Parameters**\n\n"; | 
|  | 830 | $lineprefix = "  "; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 831 | foreach $parameter (@{$args{'parameterlist'}}) { | 
|  | 832 | my $parameter_name = $parameter; | 
| Gabriel Krisman Bertazi | ada5f44 | 2017-01-09 18:11:57 -0200 | [diff] [blame] | 833 | $parameter_name =~ s/\[.*//; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 834 | $type = $args{'parametertypes'}{$parameter}; | 
|  | 835 |  | 
|  | 836 | if ($type ne "") { | 
| Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 837 | print "``$type $parameter``\n"; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 838 | } else { | 
| Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 839 | print "``$parameter``\n"; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 840 | } | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 841 |  | 
|  | 842 | print_lineno($parameterdesc_start_lines{$parameter_name}); | 
|  | 843 |  | 
| Jani Nikula | 5e64fa9 | 2016-05-19 20:32:48 +0300 | [diff] [blame] | 844 | if (defined($args{'parameterdescs'}{$parameter_name}) && | 
|  | 845 | $args{'parameterdescs'}{$parameter_name} ne $undescribed) { | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 846 | output_highlight_rst($args{'parameterdescs'}{$parameter_name}); | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 847 | } else { | 
| Jani Nikula | d4b08e0 | 2016-05-28 00:48:17 +0300 | [diff] [blame] | 848 | print "  *undescribed*\n"; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 849 | } | 
|  | 850 | print "\n"; | 
|  | 851 | } | 
| Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 852 |  | 
|  | 853 | $lineprefix = $oldprefix; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 854 | output_section_rst(@_); | 
|  | 855 | } | 
|  | 856 |  | 
|  | 857 | sub output_section_rst(%) { | 
|  | 858 | my %args = %{$_[0]}; | 
|  | 859 | my $section; | 
|  | 860 | my $oldprefix = $lineprefix; | 
| Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 861 | $lineprefix = ""; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 862 |  | 
|  | 863 | foreach $section (@{$args{'sectionlist'}}) { | 
| Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 864 | print "**$section**\n\n"; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 865 | print_lineno($section_start_lines{$section}); | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 866 | output_highlight_rst($args{'sections'}{$section}); | 
|  | 867 | print "\n"; | 
|  | 868 | } | 
|  | 869 | print "\n"; | 
|  | 870 | $lineprefix = $oldprefix; | 
|  | 871 | } | 
|  | 872 |  | 
|  | 873 | sub output_enum_rst(%) { | 
|  | 874 | my %args = %{$_[0]}; | 
|  | 875 | my ($parameter); | 
| Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 876 | my $oldprefix = $lineprefix; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 877 | my $count; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 878 | my $name = "enum " . $args{'enum'}; | 
| Jani Nikula | 6285097 | 2016-05-12 16:15:38 +0300 | [diff] [blame] | 879 |  | 
|  | 880 | print "\n\n.. c:type:: " . $name . "\n\n"; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 881 | print_lineno($declaration_start_line); | 
| Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 882 | $lineprefix = "   "; | 
|  | 883 | output_highlight_rst($args{'purpose'}); | 
|  | 884 | print "\n"; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 885 |  | 
| Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 886 | print "**Constants**\n\n"; | 
|  | 887 | $lineprefix = "  "; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 888 | foreach $parameter (@{$args{'parameterlist'}}) { | 
| Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 889 | print "``$parameter``\n"; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 890 | if ($args{'parameterdescs'}{$parameter} ne $undescribed) { | 
|  | 891 | output_highlight_rst($args{'parameterdescs'}{$parameter}); | 
|  | 892 | } else { | 
| Jani Nikula | d4b08e0 | 2016-05-28 00:48:17 +0300 | [diff] [blame] | 893 | print "  *undescribed*\n"; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 894 | } | 
|  | 895 | print "\n"; | 
|  | 896 | } | 
| Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 897 |  | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 898 | $lineprefix = $oldprefix; | 
|  | 899 | output_section_rst(@_); | 
|  | 900 | } | 
|  | 901 |  | 
|  | 902 | sub output_typedef_rst(%) { | 
|  | 903 | my %args = %{$_[0]}; | 
|  | 904 | my ($parameter); | 
| Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 905 | my $oldprefix = $lineprefix; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 906 | my $name = "typedef " . $args{'typedef'}; | 
|  | 907 |  | 
| Jani Nikula | 6285097 | 2016-05-12 16:15:38 +0300 | [diff] [blame] | 908 | print "\n\n.. c:type:: " . $name . "\n\n"; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 909 | print_lineno($declaration_start_line); | 
| Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 910 | $lineprefix = "   "; | 
|  | 911 | output_highlight_rst($args{'purpose'}); | 
|  | 912 | print "\n"; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 913 |  | 
| Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 914 | $lineprefix = $oldprefix; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 915 | output_section_rst(@_); | 
|  | 916 | } | 
|  | 917 |  | 
|  | 918 | sub output_struct_rst(%) { | 
|  | 919 | my %args = %{$_[0]}; | 
|  | 920 | my ($parameter); | 
| Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 921 | my $oldprefix = $lineprefix; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 922 | my $name = $args{'type'} . " " . $args{'struct'}; | 
|  | 923 |  | 
| Jani Nikula | 6285097 | 2016-05-12 16:15:38 +0300 | [diff] [blame] | 924 | print "\n\n.. c:type:: " . $name . "\n\n"; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 925 | print_lineno($declaration_start_line); | 
| Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 926 | $lineprefix = "   "; | 
|  | 927 | output_highlight_rst($args{'purpose'}); | 
|  | 928 | print "\n"; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 929 |  | 
| Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 930 | print "**Definition**\n\n"; | 
|  | 931 | print "::\n\n"; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 932 | print "  " . $args{'type'} . " " . $args{'struct'} . " {\n"; | 
|  | 933 | foreach $parameter (@{$args{'parameterlist'}}) { | 
|  | 934 | if ($parameter =~ /^#/) { | 
| Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 935 | print "  " . "$parameter\n"; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 936 | next; | 
|  | 937 | } | 
|  | 938 |  | 
|  | 939 | my $parameter_name = $parameter; | 
|  | 940 | $parameter_name =~ s/\[.*//; | 
|  | 941 |  | 
|  | 942 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | 
|  | 943 | $type = $args{'parametertypes'}{$parameter}; | 
|  | 944 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { | 
|  | 945 | # pointer-to-function | 
|  | 946 | print "    $1 $parameter) ($2);\n"; | 
|  | 947 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { | 
|  | 948 | # bitfield | 
|  | 949 | print "    $1 $parameter$2;\n"; | 
|  | 950 | } else { | 
|  | 951 | print "    " . $type . " " . $parameter . ";\n"; | 
|  | 952 | } | 
|  | 953 | } | 
|  | 954 | print "  };\n\n"; | 
|  | 955 |  | 
| Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 956 | print "**Members**\n\n"; | 
|  | 957 | $lineprefix = "  "; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 958 | foreach $parameter (@{$args{'parameterlist'}}) { | 
|  | 959 | ($parameter =~ /^#/) && next; | 
|  | 960 |  | 
|  | 961 | my $parameter_name = $parameter; | 
|  | 962 | $parameter_name =~ s/\[.*//; | 
|  | 963 |  | 
|  | 964 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; | 
|  | 965 | $type = $args{'parametertypes'}{$parameter}; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 966 | print_lineno($parameterdesc_start_lines{$parameter_name}); | 
| Mauro Carvalho Chehab | 6d232c8 | 2016-08-22 22:02:57 -0300 | [diff] [blame] | 967 | print "``" . $parameter . "``\n"; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 968 | output_highlight_rst($args{'parameterdescs'}{$parameter_name}); | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 969 | print "\n"; | 
|  | 970 | } | 
|  | 971 | print "\n"; | 
| Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 972 |  | 
|  | 973 | $lineprefix = $oldprefix; | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 974 | output_section_rst(@_); | 
|  | 975 | } | 
|  | 976 |  | 
| Matthew Wilcox | 3a025e1 | 2017-11-20 10:40:40 -0800 | [diff] [blame] | 977 | ## none mode output functions | 
|  | 978 |  | 
|  | 979 | sub output_function_none(%) { | 
|  | 980 | } | 
|  | 981 |  | 
|  | 982 | sub output_enum_none(%) { | 
|  | 983 | } | 
|  | 984 |  | 
|  | 985 | sub output_typedef_none(%) { | 
|  | 986 | } | 
|  | 987 |  | 
|  | 988 | sub output_struct_none(%) { | 
|  | 989 | } | 
|  | 990 |  | 
|  | 991 | sub output_blockhead_none(%) { | 
|  | 992 | } | 
|  | 993 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | ## | 
| Randy Dunlap | 2720574 | 2006-10-11 01:22:12 -0700 | [diff] [blame] | 995 | # generic output function for all types (function, struct/union, typedef, enum); | 
|  | 996 | # calls the generated, variable output_ function name based on | 
|  | 997 | # functype and output_mode | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | sub output_declaration { | 
|  | 999 | no strict 'refs'; | 
|  | 1000 | my $name = shift; | 
|  | 1001 | my $functype = shift; | 
|  | 1002 | my $func = "output_${functype}_$output_mode"; | 
| Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 1003 | if (($output_selection == OUTPUT_ALL) || | 
|  | 1004 | (($output_selection == OUTPUT_INCLUDE || | 
|  | 1005 | $output_selection == OUTPUT_EXPORTED) && | 
|  | 1006 | defined($function_table{$name})) || | 
|  | 1007 | (($output_selection == OUTPUT_EXCLUDE || | 
|  | 1008 | $output_selection == OUTPUT_INTERNAL) && | 
|  | 1009 | !($functype eq "function" && defined($function_table{$name})))) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | { | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1011 | &$func(@_); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | $section_counter++; | 
|  | 1013 | } | 
|  | 1014 | } | 
|  | 1015 |  | 
|  | 1016 | ## | 
| Randy Dunlap | 2720574 | 2006-10-11 01:22:12 -0700 | [diff] [blame] | 1017 | # generic output function - calls the right one based on current output mode. | 
| Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 1018 | sub output_blockhead { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | no strict 'refs'; | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1020 | my $func = "output_blockhead_" . $output_mode; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | &$func(@_); | 
|  | 1022 | $section_counter++; | 
|  | 1023 | } | 
|  | 1024 |  | 
|  | 1025 | ## | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1026 | # takes a declaration (struct, union, enum, typedef) and | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | # invokes the right handler. NOT called for functions. | 
|  | 1028 | sub dump_declaration($$) { | 
|  | 1029 | no strict 'refs'; | 
|  | 1030 | my ($prototype, $file) = @_; | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1031 | my $func = "dump_" . $decl_type; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | &$func(@_); | 
|  | 1033 | } | 
|  | 1034 |  | 
|  | 1035 | sub dump_union($$) { | 
|  | 1036 | dump_struct(@_); | 
|  | 1037 | } | 
|  | 1038 |  | 
|  | 1039 | sub dump_struct($$) { | 
|  | 1040 | my $x = shift; | 
|  | 1041 | my $file = shift; | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1042 | my $nested; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 |  | 
| Randy Dunlap | 52dc5ae | 2009-04-30 15:08:53 -0700 | [diff] [blame] | 1044 | if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { | 
| Johannes Berg | 5cb5c31 | 2017-09-19 13:08:13 +0200 | [diff] [blame] | 1045 | my $decl_type = $1; | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1046 | $declaration_name = $2; | 
|  | 1047 | my $members = $3; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 |  | 
|  | 1049 | # ignore embedded structs or unions | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1050 | $members =~ s/({.*})//g; | 
|  | 1051 | $nested = $1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 |  | 
| Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 1053 | # ignore members marked private: | 
| Mauro Carvalho Chehab | 0d8c39e | 2015-10-05 09:03:48 -0300 | [diff] [blame] | 1054 | $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; | 
|  | 1055 | $members =~ s/\/\*\s*private:.*//gosi; | 
| Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 1056 | # strip comments: | 
|  | 1057 | $members =~ s/\/\*.*?\*\///gos; | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1058 | $nested =~ s/\/\*.*?\*\///gos; | 
| Randy Dunlap | ef5da59 | 2010-03-23 13:35:14 -0700 | [diff] [blame] | 1059 | # strip attributes | 
| Jonathan Corbet | f007492 | 2015-08-23 13:35:23 -0600 | [diff] [blame] | 1060 | $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; | 
| Johannes Berg | 7b99078 | 2014-12-10 15:41:28 -0800 | [diff] [blame] | 1061 | $members =~ s/__aligned\s*\([^;]*\)//gos; | 
| Jonathan Corbet | f007492 | 2015-08-23 13:35:23 -0600 | [diff] [blame] | 1062 | $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; | 
| Conchúr Navid | b22b5a9 | 2015-11-08 10:52:00 +0100 | [diff] [blame] | 1063 | # replace DECLARE_BITMAP | 
| Mauro Carvalho Chehab | 45005b2 | 2017-12-08 09:05:12 -0500 | [diff] [blame] | 1064 | $members =~ s/DECLARE_BITMAP\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; | 
| Jakub Kicinski | 1cb566b | 2017-06-30 19:09:59 -0700 | [diff] [blame] | 1065 | # replace DECLARE_HASHTABLE | 
| Mauro Carvalho Chehab | 45005b2 | 2017-12-08 09:05:12 -0500 | [diff] [blame] | 1066 | $members =~ s/DECLARE_HASHTABLE\s*\(([^,)]+),\s*([^,)]+)\)/unsigned long $1\[1 << (($2) - 1)\]/gos; | 
|  | 1067 | # replace DECLARE_KFIFO | 
|  | 1068 | $members =~ s/DECLARE_KFIFO\s*\(([^,)]+),\s*([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; | 
|  | 1069 | # replace DECLARE_KFIFO_PTR | 
|  | 1070 | $members =~ s/DECLARE_KFIFO_PTR\s*\(([^,)]+),\s*([^,)]+)\)/$2 \*$1/gos; | 
| Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 1071 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | create_parameterlist($members, ';', $file); | 
| Johannes Berg | 5cb5c31 | 2017-09-19 13:08:13 +0200 | [diff] [blame] | 1073 | check_sections($file, $declaration_name, $decl_type, $sectcheck, $struct_actual, $nested); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1074 |  | 
|  | 1075 | output_declaration($declaration_name, | 
|  | 1076 | 'struct', | 
|  | 1077 | {'struct' => $declaration_name, | 
|  | 1078 | 'module' => $modulename, | 
|  | 1079 | 'parameterlist' => \@parameterlist, | 
|  | 1080 | 'parameterdescs' => \%parameterdescs, | 
|  | 1081 | 'parametertypes' => \%parametertypes, | 
|  | 1082 | 'sectionlist' => \@sectionlist, | 
|  | 1083 | 'sections' => \%sections, | 
|  | 1084 | 'purpose' => $declaration_purpose, | 
|  | 1085 | 'type' => $decl_type | 
|  | 1086 | }); | 
|  | 1087 | } | 
|  | 1088 | else { | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1089 | print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | ++$errors; | 
|  | 1091 | } | 
|  | 1092 | } | 
|  | 1093 |  | 
|  | 1094 | sub dump_enum($$) { | 
|  | 1095 | my $x = shift; | 
|  | 1096 | my $file = shift; | 
|  | 1097 |  | 
| Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 1098 | $x =~ s@/\*.*?\*/@@gos;	# strip comments. | 
| Conchúr Navid | 4468e21 | 2015-11-08 10:48:05 +0100 | [diff] [blame] | 1099 | # strip #define macros inside enums | 
|  | 1100 | $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; | 
| Randy Dunlap | b6d676d | 2010-08-10 18:02:50 -0700 | [diff] [blame] | 1101 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1103 | $declaration_name = $1; | 
|  | 1104 | my $members = $2; | 
| Johannes Berg | 5cb5c31 | 2017-09-19 13:08:13 +0200 | [diff] [blame] | 1105 | my %_members; | 
|  | 1106 |  | 
| Markus Heiser | 463a0fd | 2017-06-16 21:27:48 +0200 | [diff] [blame] | 1107 | $members =~ s/\s+$//; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 |  | 
|  | 1109 | foreach my $arg (split ',', $members) { | 
|  | 1110 | $arg =~ s/^\s*(\w+).*/$1/; | 
|  | 1111 | push @parameterlist, $arg; | 
|  | 1112 | if (!$parameterdescs{$arg}) { | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1113 | $parameterdescs{$arg} = $undescribed; | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1114 | print STDERR "${file}:$.: warning: Enum value '$arg' ". | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | "not described in enum '$declaration_name'\n"; | 
|  | 1116 | } | 
| Johannes Berg | 5cb5c31 | 2017-09-19 13:08:13 +0200 | [diff] [blame] | 1117 | $_members{$arg} = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | } | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1119 |  | 
| Johannes Berg | 5cb5c31 | 2017-09-19 13:08:13 +0200 | [diff] [blame] | 1120 | while (my ($k, $v) = each %parameterdescs) { | 
|  | 1121 | if (!exists($_members{$k})) { | 
|  | 1122 | print STDERR "${file}:$.: warning: Excess enum value " . | 
|  | 1123 | "'$k' description in '$declaration_name'\n"; | 
|  | 1124 | } | 
|  | 1125 | } | 
|  | 1126 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | output_declaration($declaration_name, | 
|  | 1128 | 'enum', | 
|  | 1129 | {'enum' => $declaration_name, | 
|  | 1130 | 'module' => $modulename, | 
|  | 1131 | 'parameterlist' => \@parameterlist, | 
|  | 1132 | 'parameterdescs' => \%parameterdescs, | 
|  | 1133 | 'sectionlist' => \@sectionlist, | 
|  | 1134 | 'sections' => \%sections, | 
|  | 1135 | 'purpose' => $declaration_purpose | 
|  | 1136 | }); | 
|  | 1137 | } | 
|  | 1138 | else { | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1139 | print STDERR "${file}:$.: error: Cannot parse enum!\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | ++$errors; | 
|  | 1141 | } | 
|  | 1142 | } | 
|  | 1143 |  | 
|  | 1144 | sub dump_typedef($$) { | 
|  | 1145 | my $x = shift; | 
|  | 1146 | my $file = shift; | 
|  | 1147 |  | 
| Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 1148 | $x =~ s@/\*.*?\*/@@gos;	# strip comments. | 
| Mauro Carvalho Chehab | 8376645 | 2015-10-08 16:14:45 -0300 | [diff] [blame] | 1149 |  | 
|  | 1150 | # Parse function prototypes | 
| Mauro Carvalho Chehab | d37c43c | 2016-08-30 20:20:57 -0300 | [diff] [blame] | 1151 | if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ || | 
|  | 1152 | $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) { | 
|  | 1153 |  | 
| Mauro Carvalho Chehab | 8376645 | 2015-10-08 16:14:45 -0300 | [diff] [blame] | 1154 | # Function typedefs | 
|  | 1155 | $return_type = $1; | 
|  | 1156 | $declaration_name = $2; | 
|  | 1157 | my $args = $3; | 
|  | 1158 |  | 
|  | 1159 | create_parameterlist($args, ',', $file); | 
|  | 1160 |  | 
|  | 1161 | output_declaration($declaration_name, | 
|  | 1162 | 'function', | 
|  | 1163 | {'function' => $declaration_name, | 
| Mauro Carvalho Chehab | 82801d0 | 2016-08-30 20:20:58 -0300 | [diff] [blame] | 1164 | 'typedef' => 1, | 
| Mauro Carvalho Chehab | 8376645 | 2015-10-08 16:14:45 -0300 | [diff] [blame] | 1165 | 'module' => $modulename, | 
|  | 1166 | 'functiontype' => $return_type, | 
|  | 1167 | 'parameterlist' => \@parameterlist, | 
|  | 1168 | 'parameterdescs' => \%parameterdescs, | 
|  | 1169 | 'parametertypes' => \%parametertypes, | 
|  | 1170 | 'sectionlist' => \@sectionlist, | 
|  | 1171 | 'sections' => \%sections, | 
|  | 1172 | 'purpose' => $declaration_purpose | 
|  | 1173 | }); | 
|  | 1174 | return; | 
|  | 1175 | } | 
|  | 1176 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1178 | $x =~ s/\(*.\)\s*;$/;/; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | $x =~ s/\[*.\]\s*;$/;/; | 
|  | 1180 | } | 
|  | 1181 |  | 
|  | 1182 | if ($x =~ /typedef.*\s+(\w+)\s*;/) { | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1183 | $declaration_name = $1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 |  | 
|  | 1185 | output_declaration($declaration_name, | 
|  | 1186 | 'typedef', | 
|  | 1187 | {'typedef' => $declaration_name, | 
|  | 1188 | 'module' => $modulename, | 
|  | 1189 | 'sectionlist' => \@sectionlist, | 
|  | 1190 | 'sections' => \%sections, | 
|  | 1191 | 'purpose' => $declaration_purpose | 
|  | 1192 | }); | 
|  | 1193 | } | 
|  | 1194 | else { | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1195 | print STDERR "${file}:$.: error: Cannot parse typedef!\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | ++$errors; | 
|  | 1197 | } | 
|  | 1198 | } | 
|  | 1199 |  | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1200 | sub save_struct_actual($) { | 
|  | 1201 | my $actual = shift; | 
|  | 1202 |  | 
|  | 1203 | # strip all spaces from the actual param so that it looks like one string item | 
|  | 1204 | $actual =~ s/\s*//g; | 
|  | 1205 | $struct_actual = $struct_actual . $actual . " "; | 
|  | 1206 | } | 
|  | 1207 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | sub create_parameterlist($$$) { | 
|  | 1209 | my $args = shift; | 
|  | 1210 | my $splitter = shift; | 
|  | 1211 | my $file = shift; | 
|  | 1212 | my $type; | 
|  | 1213 | my $param; | 
|  | 1214 |  | 
| Martin Waitz | a6d3fe7 | 2006-01-09 20:53:55 -0800 | [diff] [blame] | 1215 | # temporarily replace commas inside function pointer definition | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | while ($args =~ /(\([^\),]+),/) { | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1217 | $args =~ s/(\([^\),]+),/$1#/g; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | } | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1219 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | foreach my $arg (split($splitter, $args)) { | 
|  | 1221 | # strip comments | 
|  | 1222 | $arg =~ s/\/\*.*\*\///; | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1223 | # strip leading/trailing spaces | 
|  | 1224 | $arg =~ s/^\s*//; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | $arg =~ s/\s*$//; | 
|  | 1226 | $arg =~ s/\s+/ /; | 
|  | 1227 |  | 
|  | 1228 | if ($arg =~ /^#/) { | 
|  | 1229 | # Treat preprocessor directive as a typeless variable just to fill | 
|  | 1230 | # corresponding data structures "correctly". Catch it later in | 
|  | 1231 | # output_* subs. | 
|  | 1232 | push_parameter($arg, "", $file); | 
| Richard Kennedy | 00d6296 | 2008-02-23 15:24:01 -0800 | [diff] [blame] | 1233 | } elsif ($arg =~ m/\(.+\)\s*\(/) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | # pointer-to-function | 
|  | 1235 | $arg =~ tr/#/,/; | 
| Richard Kennedy | 00d6296 | 2008-02-23 15:24:01 -0800 | [diff] [blame] | 1236 | $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | $param = $1; | 
|  | 1238 | $type = $arg; | 
| Richard Kennedy | 00d6296 | 2008-02-23 15:24:01 -0800 | [diff] [blame] | 1239 | $type =~ s/([^\(]+\(\*?)\s*$param/$1/; | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1240 | save_struct_actual($param); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | push_parameter($param, $type, $file); | 
| Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 1242 | } elsif ($arg) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | $arg =~ s/\s*:\s*/:/g; | 
|  | 1244 | $arg =~ s/\s*\[/\[/g; | 
|  | 1245 |  | 
|  | 1246 | my @args = split('\s*,\s*', $arg); | 
|  | 1247 | if ($args[0] =~ m/\*/) { | 
|  | 1248 | $args[0] =~ s/(\*+)\s*/ $1/; | 
|  | 1249 | } | 
| Borislav Petkov | 884f281 | 2007-05-08 00:29:05 -0700 | [diff] [blame] | 1250 |  | 
|  | 1251 | my @first_arg; | 
|  | 1252 | if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { | 
|  | 1253 | shift @args; | 
|  | 1254 | push(@first_arg, split('\s+', $1)); | 
|  | 1255 | push(@first_arg, $2); | 
|  | 1256 | } else { | 
|  | 1257 | @first_arg = split('\s+', shift @args); | 
|  | 1258 | } | 
|  | 1259 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | unshift(@args, pop @first_arg); | 
|  | 1261 | $type = join " ", @first_arg; | 
|  | 1262 |  | 
|  | 1263 | foreach $param (@args) { | 
|  | 1264 | if ($param =~ m/^(\*+)\s*(.*)/) { | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1265 | save_struct_actual($2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | push_parameter($2, "$type $1", $file); | 
|  | 1267 | } | 
|  | 1268 | elsif ($param =~ m/(.*?):(\d+)/) { | 
| Randy Dunlap | 7b97887 | 2008-05-16 15:45:52 -0700 | [diff] [blame] | 1269 | if ($type ne "") { # skip unnamed bit-fields | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1270 | save_struct_actual($1); | 
| Randy Dunlap | 7b97887 | 2008-05-16 15:45:52 -0700 | [diff] [blame] | 1271 | push_parameter($1, "$type:$2", $file) | 
|  | 1272 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1273 | } | 
|  | 1274 | else { | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1275 | save_struct_actual($param); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | push_parameter($param, $type, $file); | 
|  | 1277 | } | 
|  | 1278 | } | 
|  | 1279 | } | 
|  | 1280 | } | 
|  | 1281 | } | 
|  | 1282 |  | 
|  | 1283 | sub push_parameter($$$) { | 
|  | 1284 | my $param = shift; | 
|  | 1285 | my $type = shift; | 
|  | 1286 | my $file = shift; | 
|  | 1287 |  | 
| Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1288 | if (($anon_struct_union == 1) && ($type eq "") && | 
|  | 1289 | ($param eq "}")) { | 
|  | 1290 | return;		# ignore the ending }; from anon. struct/union | 
|  | 1291 | } | 
|  | 1292 |  | 
|  | 1293 | $anon_struct_union = 0; | 
| Mauro Carvalho Chehab | f9b5c53 | 2017-03-30 17:11:29 -0300 | [diff] [blame] | 1294 | $param =~ s/[\[\)].*//; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 |  | 
| Martin Waitz | a6d3fe7 | 2006-01-09 20:53:55 -0800 | [diff] [blame] | 1296 | if ($type eq "" && $param =~ /\.\.\.$/) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | { | 
| Silvio Fricke | c950a17 | 2016-10-28 10:14:08 +0200 | [diff] [blame] | 1298 | if (!$param =~ /\w\.\.\.$/) { | 
|  | 1299 | # handles unnamed variable parameters | 
|  | 1300 | $param = "..."; | 
|  | 1301 | } | 
| Randy Dunlap | ced6909 | 2008-12-01 13:14:03 -0800 | [diff] [blame] | 1302 | if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { | 
|  | 1303 | $parameterdescs{$param} = "variable arguments"; | 
|  | 1304 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | } | 
|  | 1306 | elsif ($type eq "" && ($param eq "" or $param eq "void")) | 
|  | 1307 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | $param="void"; | 
|  | 1309 | $parameterdescs{void} = "no arguments"; | 
|  | 1310 | } | 
| Randy Dunlap | 134fe01 | 2006-12-22 01:10:50 -0800 | [diff] [blame] | 1311 | elsif ($type eq "" && ($param eq "struct" or $param eq "union")) | 
|  | 1312 | # handle unnamed (anonymous) union or struct: | 
|  | 1313 | { | 
|  | 1314 | $type = $param; | 
| Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1315 | $param = "{unnamed_" . $param . "}"; | 
| Randy Dunlap | 134fe01 | 2006-12-22 01:10:50 -0800 | [diff] [blame] | 1316 | $parameterdescs{$param} = "anonymous\n"; | 
| Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1317 | $anon_struct_union = 1; | 
| Randy Dunlap | 134fe01 | 2006-12-22 01:10:50 -0800 | [diff] [blame] | 1318 | } | 
|  | 1319 |  | 
| Martin Waitz | a6d3fe7 | 2006-01-09 20:53:55 -0800 | [diff] [blame] | 1320 | # warn if parameter has no description | 
| Randy Dunlap | 134fe01 | 2006-12-22 01:10:50 -0800 | [diff] [blame] | 1321 | # (but ignore ones starting with # as these are not parameters | 
|  | 1322 | # but inline preprocessor statements); | 
|  | 1323 | # also ignore unnamed structs/unions; | 
| Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1324 | if (!$anon_struct_union) { | 
| Mauro Carvalho Chehab | f9b5c53 | 2017-03-30 17:11:29 -0300 | [diff] [blame] | 1325 | if (!defined $parameterdescs{$param} && $param !~ /^#/) { | 
| Martin Waitz | a6d3fe7 | 2006-01-09 20:53:55 -0800 | [diff] [blame] | 1326 |  | 
| Mauro Carvalho Chehab | f9b5c53 | 2017-03-30 17:11:29 -0300 | [diff] [blame] | 1327 | $parameterdescs{$param} = $undescribed; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1328 |  | 
|  | 1329 | if (($type eq 'function') || ($type eq 'enum')) { | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1330 | print STDERR "${file}:$.: warning: Function parameter ". | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | "or member '$param' not " . | 
|  | 1332 | "described in '$declaration_name'\n"; | 
|  | 1333 | } | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1334 | print STDERR "${file}:$.: warning:" . | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1335 | " No description found for parameter '$param'\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | ++$warnings; | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1337 | } | 
|  | 1338 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 |  | 
| Randy Dunlap | 2b35f4d | 2010-11-18 12:27:31 -0800 | [diff] [blame] | 1340 | $param = xml_escape($param); | 
|  | 1341 |  | 
| Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1342 | # strip spaces from $param so that it is one continuous string | 
| Randy Dunlap | e34e7db | 2009-06-17 17:37:47 -0700 | [diff] [blame] | 1343 | # on @parameterlist; | 
|  | 1344 | # this fixes a problem where check_sections() cannot find | 
|  | 1345 | # a parameter like "addr[6 + 2]" because it actually appears | 
|  | 1346 | # as "addr[6", "+", "2]" on the parameter list; | 
|  | 1347 | # but it's better to maintain the param string unchanged for output, | 
|  | 1348 | # so just weaken the string compare in check_sections() to ignore | 
|  | 1349 | # "[blah" in a parameter string; | 
|  | 1350 | ###$param =~ s/\s*//g; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1351 | push @parameterlist, $param; | 
| Paolo Bonzini | 02a4f4f | 2017-01-02 16:22:23 +0100 | [diff] [blame] | 1352 | $type =~ s/\s\s+/ /g; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | $parametertypes{$param} = $type; | 
|  | 1354 | } | 
|  | 1355 |  | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1356 | sub check_sections($$$$$$) { | 
|  | 1357 | my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; | 
|  | 1358 | my @sects = split ' ', $sectcheck; | 
|  | 1359 | my @prms = split ' ', $prmscheck; | 
|  | 1360 | my $err; | 
|  | 1361 | my ($px, $sx); | 
|  | 1362 | my $prm_clean;		# strip trailing "[array size]" and/or beginning "*" | 
|  | 1363 |  | 
|  | 1364 | foreach $sx (0 .. $#sects) { | 
|  | 1365 | $err = 1; | 
|  | 1366 | foreach $px (0 .. $#prms) { | 
|  | 1367 | $prm_clean = $prms[$px]; | 
|  | 1368 | $prm_clean =~ s/\[.*\]//; | 
| Johannes Berg | 1f3a668 | 2010-09-11 15:55:12 -0700 | [diff] [blame] | 1369 | $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; | 
| Randy Dunlap | e34e7db | 2009-06-17 17:37:47 -0700 | [diff] [blame] | 1370 | # ignore array size in a parameter string; | 
|  | 1371 | # however, the original param string may contain | 
|  | 1372 | # spaces, e.g.:  addr[6 + 2] | 
|  | 1373 | # and this appears in @prms as "addr[6" since the | 
|  | 1374 | # parameter list is split at spaces; | 
|  | 1375 | # hence just ignore "[..." for the sections check; | 
|  | 1376 | $prm_clean =~ s/\[.*//; | 
|  | 1377 |  | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1378 | ##$prm_clean =~ s/^\**//; | 
|  | 1379 | if ($prm_clean eq $sects[$sx]) { | 
|  | 1380 | $err = 0; | 
|  | 1381 | last; | 
|  | 1382 | } | 
|  | 1383 | } | 
|  | 1384 | if ($err) { | 
|  | 1385 | if ($decl_type eq "function") { | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1386 | print STDERR "${file}:$.: warning: " . | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1387 | "Excess function parameter " . | 
|  | 1388 | "'$sects[$sx]' " . | 
|  | 1389 | "description in '$decl_name'\n"; | 
|  | 1390 | ++$warnings; | 
|  | 1391 | } else { | 
|  | 1392 | if ($nested !~ m/\Q$sects[$sx]\E/) { | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1393 | print STDERR "${file}:$.: warning: " . | 
| Johannes Berg | 5cb5c31 | 2017-09-19 13:08:13 +0200 | [diff] [blame] | 1394 | "Excess $decl_type member " . | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1395 | "'$sects[$sx]' " . | 
|  | 1396 | "description in '$decl_name'\n"; | 
|  | 1397 | ++$warnings; | 
|  | 1398 | } | 
|  | 1399 | } | 
|  | 1400 | } | 
|  | 1401 | } | 
|  | 1402 | } | 
|  | 1403 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | ## | 
| Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 1405 | # Checks the section describing the return value of a function. | 
|  | 1406 | sub check_return_section { | 
|  | 1407 | my $file = shift; | 
|  | 1408 | my $declaration_name = shift; | 
|  | 1409 | my $return_type = shift; | 
|  | 1410 |  | 
|  | 1411 | # Ignore an empty return type (It's a macro) | 
|  | 1412 | # Ignore functions with a "void" return type. (But don't ignore "void *") | 
|  | 1413 | if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { | 
|  | 1414 | return; | 
|  | 1415 | } | 
|  | 1416 |  | 
|  | 1417 | if (!defined($sections{$section_return}) || | 
|  | 1418 | $sections{$section_return} eq "") { | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1419 | print STDERR "${file}:$.: warning: " . | 
| Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 1420 | "No description found for return value of " . | 
|  | 1421 | "'$declaration_name'\n"; | 
|  | 1422 | ++$warnings; | 
|  | 1423 | } | 
|  | 1424 | } | 
|  | 1425 |  | 
|  | 1426 | ## | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | # takes a function prototype and the name of the current file being | 
|  | 1428 | # processed and spits out all the details stored in the global | 
|  | 1429 | # arrays/hashes. | 
|  | 1430 | sub dump_function($$) { | 
|  | 1431 | my $prototype = shift; | 
|  | 1432 | my $file = shift; | 
| Horia Geanta | cbb4d3e | 2014-07-12 09:55:03 -0700 | [diff] [blame] | 1433 | my $noret = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 |  | 
|  | 1435 | $prototype =~ s/^static +//; | 
|  | 1436 | $prototype =~ s/^extern +//; | 
| Pavel Pisa | 4dc3b16 | 2005-05-01 08:59:25 -0700 | [diff] [blame] | 1437 | $prototype =~ s/^asmlinkage +//; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | $prototype =~ s/^inline +//; | 
|  | 1439 | $prototype =~ s/^__inline__ +//; | 
| Randy Dunlap | 32e7940 | 2006-10-11 01:22:10 -0700 | [diff] [blame] | 1440 | $prototype =~ s/^__inline +//; | 
|  | 1441 | $prototype =~ s/^__always_inline +//; | 
|  | 1442 | $prototype =~ s/^noinline +//; | 
| Randy Dunlap | 74fc5c6 | 2008-06-19 16:03:29 -0700 | [diff] [blame] | 1443 | $prototype =~ s/__init +//; | 
| Randy Dunlap | 2007220 | 2010-03-23 13:35:24 -0700 | [diff] [blame] | 1444 | $prototype =~ s/__init_or_module +//; | 
| Randy Dunlap | 270a009 | 2014-08-24 18:17:17 -0700 | [diff] [blame] | 1445 | $prototype =~ s/__meminit +//; | 
| Randy Dunlap | 70c95b0 | 2012-01-21 10:31:54 -0800 | [diff] [blame] | 1446 | $prototype =~ s/__must_check +//; | 
| Randy Dunlap | 0df7c0e | 2012-08-16 16:23:20 -0700 | [diff] [blame] | 1447 | $prototype =~ s/__weak +//; | 
| Horia Geanta | cbb4d3e | 2014-07-12 09:55:03 -0700 | [diff] [blame] | 1448 | my $define = $prototype =~ s/^#\s*define\s+//; #ak added | 
| Paolo Bonzini | b1aaa54 | 2017-01-02 16:22:24 +0100 | [diff] [blame] | 1449 | $prototype =~ s/__attribute__\s*\(\( | 
|  | 1450 | (?: | 
|  | 1451 | [\w\s]++          # attribute name | 
|  | 1452 | (?:\([^)]*+\))?   # attribute arguments | 
|  | 1453 | \s*+,?            # optional comma at the end | 
|  | 1454 | )+ | 
|  | 1455 | \)\)\s+//x; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 |  | 
|  | 1457 | # Yes, this truly is vile.  We are looking for: | 
|  | 1458 | # 1. Return type (may be nothing if we're looking at a macro) | 
|  | 1459 | # 2. Function name | 
|  | 1460 | # 3. Function parameters. | 
|  | 1461 | # | 
|  | 1462 | # All the while we have to watch out for function pointer parameters | 
|  | 1463 | # (which IIRC is what the two sections are for), C types (these | 
|  | 1464 | # regexps don't even start to express all the possibilities), and | 
|  | 1465 | # so on. | 
|  | 1466 | # | 
|  | 1467 | # If you mess with these regexps, it's a good idea to check that | 
|  | 1468 | # the following functions' documentation still comes out right: | 
|  | 1469 | # - parport_register_device (function pointer parameters) | 
|  | 1470 | # - atomic_set (macro) | 
| Martin Waitz | 9598f91 | 2006-02-01 03:06:55 -0800 | [diff] [blame] | 1471 | # - pci_match_device, __copy_to_user (long return type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 |  | 
| Horia Geanta | cbb4d3e | 2014-07-12 09:55:03 -0700 | [diff] [blame] | 1473 | if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { | 
|  | 1474 | # This is an object-like macro, it has no return type and no parameter | 
|  | 1475 | # list. | 
|  | 1476 | # Function-like macros are not allowed to have spaces between | 
|  | 1477 | # declaration_name and opening parenthesis (notice the \s+). | 
|  | 1478 | $return_type = $1; | 
|  | 1479 | $declaration_name = $2; | 
|  | 1480 | $noret = 1; | 
|  | 1481 | } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | 
| Matthew Wilcox | 5a0bc57 | 2017-01-23 00:18:10 -0800 | [diff] [blame] | 1483 | $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | 
| Randy Dunlap | 94b3e03 | 2008-02-07 00:13:26 -0800 | [diff] [blame] | 1485 | $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | 
| Matthew Wilcox | 5a0bc57 | 2017-01-23 00:18:10 -0800 | [diff] [blame] | 1487 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | 
|  | 1489 | $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | 
| Matthew Wilcox | 5a0bc57 | 2017-01-23 00:18:10 -0800 | [diff] [blame] | 1490 | $prototype =~ m/^(\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | 
| Matthew Wilcox | 5a0bc57 | 2017-01-23 00:18:10 -0800 | [diff] [blame] | 1492 | $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | 
| Matthew Wilcox | 5a0bc57 | 2017-01-23 00:18:10 -0800 | [diff] [blame] | 1494 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | 
| Martin Waitz | 9598f91 | 2006-02-01 03:06:55 -0800 | [diff] [blame] | 1495 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | 
| Matthew Wilcox | 5a0bc57 | 2017-01-23 00:18:10 -0800 | [diff] [blame] | 1496 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || | 
|  | 1497 | $prototype =~ m/^(\w+\s+\w+\s*\*+\s*\w+\s*\*+\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/)  { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | $return_type = $1; | 
|  | 1499 | $declaration_name = $2; | 
|  | 1500 | my $args = $3; | 
|  | 1501 |  | 
|  | 1502 | create_parameterlist($args, ',', $file); | 
|  | 1503 | } else { | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1504 | print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | return; | 
|  | 1506 | } | 
|  | 1507 |  | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1508 | my $prms = join " ", @parameterlist; | 
|  | 1509 | check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); | 
|  | 1510 |  | 
| Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 1511 | # This check emits a lot of warnings at the moment, because many | 
|  | 1512 | # functions don't have a 'Return' doc section. So until the number | 
|  | 1513 | # of warnings goes sufficiently down, the check is only performed in | 
|  | 1514 | # verbose mode. | 
|  | 1515 | # TODO: always perform the check. | 
| Horia Geanta | cbb4d3e | 2014-07-12 09:55:03 -0700 | [diff] [blame] | 1516 | if ($verbose && !$noret) { | 
| Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 1517 | check_return_section($file, $declaration_name, $return_type); | 
|  | 1518 | } | 
|  | 1519 |  | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1520 | output_declaration($declaration_name, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1521 | 'function', | 
|  | 1522 | {'function' => $declaration_name, | 
|  | 1523 | 'module' => $modulename, | 
|  | 1524 | 'functiontype' => $return_type, | 
|  | 1525 | 'parameterlist' => \@parameterlist, | 
|  | 1526 | 'parameterdescs' => \%parameterdescs, | 
|  | 1527 | 'parametertypes' => \%parametertypes, | 
|  | 1528 | 'sectionlist' => \@sectionlist, | 
|  | 1529 | 'sections' => \%sections, | 
|  | 1530 | 'purpose' => $declaration_purpose | 
|  | 1531 | }); | 
|  | 1532 | } | 
|  | 1533 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | sub reset_state { | 
|  | 1535 | $function = ""; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | %parameterdescs = (); | 
|  | 1537 | %parametertypes = (); | 
|  | 1538 | @parameterlist = (); | 
|  | 1539 | %sections = (); | 
|  | 1540 | @sectionlist = (); | 
| Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 1541 | $sectcheck = ""; | 
|  | 1542 | $struct_actual = ""; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | $prototype = ""; | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1544 |  | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1545 | $state = STATE_NORMAL; | 
|  | 1546 | $inline_doc_state = STATE_INLINE_NA; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | } | 
|  | 1548 |  | 
| Jason Baron | 56afb0f | 2009-04-30 13:29:36 -0400 | [diff] [blame] | 1549 | sub tracepoint_munge($) { | 
|  | 1550 | my $file = shift; | 
|  | 1551 | my $tracepointname = 0; | 
|  | 1552 | my $tracepointargs = 0; | 
|  | 1553 |  | 
| Jason Baron | 3a9089f | 2009-12-01 12:18:49 -0500 | [diff] [blame] | 1554 | if ($prototype =~ m/TRACE_EVENT\((.*?),/) { | 
| Jason Baron | 56afb0f | 2009-04-30 13:29:36 -0400 | [diff] [blame] | 1555 | $tracepointname = $1; | 
|  | 1556 | } | 
| Jason Baron | 3a9089f | 2009-12-01 12:18:49 -0500 | [diff] [blame] | 1557 | if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { | 
|  | 1558 | $tracepointname = $1; | 
|  | 1559 | } | 
|  | 1560 | if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { | 
|  | 1561 | $tracepointname = $2; | 
|  | 1562 | } | 
|  | 1563 | $tracepointname =~ s/^\s+//; #strip leading whitespace | 
|  | 1564 | if ($prototype =~ m/TP_PROTO\((.*?)\)/) { | 
| Jason Baron | 56afb0f | 2009-04-30 13:29:36 -0400 | [diff] [blame] | 1565 | $tracepointargs = $1; | 
|  | 1566 | } | 
|  | 1567 | if (($tracepointname eq 0) || ($tracepointargs eq 0)) { | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1568 | print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". | 
| Jason Baron | 56afb0f | 2009-04-30 13:29:36 -0400 | [diff] [blame] | 1569 | "$prototype\n"; | 
|  | 1570 | } else { | 
|  | 1571 | $prototype = "static inline void trace_$tracepointname($tracepointargs)"; | 
|  | 1572 | } | 
|  | 1573 | } | 
|  | 1574 |  | 
| Randy Dunlap | b4870bc | 2009-02-11 13:04:33 -0800 | [diff] [blame] | 1575 | sub syscall_munge() { | 
|  | 1576 | my $void = 0; | 
|  | 1577 |  | 
|  | 1578 | $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs | 
|  | 1579 | ##	if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { | 
|  | 1580 | if ($prototype =~ m/SYSCALL_DEFINE0/) { | 
|  | 1581 | $void = 1; | 
|  | 1582 | ##		$prototype = "long sys_$1(void)"; | 
|  | 1583 | } | 
|  | 1584 |  | 
|  | 1585 | $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name | 
|  | 1586 | if ($prototype =~ m/long (sys_.*?),/) { | 
|  | 1587 | $prototype =~ s/,/\(/; | 
|  | 1588 | } elsif ($void) { | 
|  | 1589 | $prototype =~ s/\)/\(void\)/; | 
|  | 1590 | } | 
|  | 1591 |  | 
|  | 1592 | # now delete all of the odd-number commas in $prototype | 
|  | 1593 | # so that arg types & arg names don't have a comma between them | 
|  | 1594 | my $count = 0; | 
|  | 1595 | my $len = length($prototype); | 
|  | 1596 | if ($void) { | 
|  | 1597 | $len = 0;	# skip the for-loop | 
|  | 1598 | } | 
|  | 1599 | for (my $ix = 0; $ix < $len; $ix++) { | 
|  | 1600 | if (substr($prototype, $ix, 1) eq ',') { | 
|  | 1601 | $count++; | 
|  | 1602 | if ($count % 2 == 1) { | 
|  | 1603 | substr($prototype, $ix, 1) = ' '; | 
|  | 1604 | } | 
|  | 1605 | } | 
|  | 1606 | } | 
|  | 1607 | } | 
|  | 1608 |  | 
| Daniel Vetter | b7afa92 | 2016-06-01 23:46:24 +0200 | [diff] [blame] | 1609 | sub process_proto_function($$) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | my $x = shift; | 
|  | 1611 | my $file = shift; | 
|  | 1612 |  | 
| Randy Dunlap | 51f5a0c | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1613 | $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line | 
|  | 1614 |  | 
| Randy Dunlap | 890c78c | 2008-10-25 17:06:43 -0700 | [diff] [blame] | 1615 | if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | # do nothing | 
|  | 1617 | } | 
|  | 1618 | elsif ($x =~ /([^\{]*)/) { | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1619 | $prototype .= $1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | } | 
| Randy Dunlap | b4870bc | 2009-02-11 13:04:33 -0800 | [diff] [blame] | 1621 |  | 
| Randy Dunlap | 890c78c | 2008-10-25 17:06:43 -0700 | [diff] [blame] | 1622 | if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1623 | $prototype =~ s@/\*.*?\*/@@gos;	# strip comments. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. | 
|  | 1625 | $prototype =~ s@^\s+@@gos; # strip leading spaces | 
| Randy Dunlap | b4870bc | 2009-02-11 13:04:33 -0800 | [diff] [blame] | 1626 | if ($prototype =~ /SYSCALL_DEFINE/) { | 
|  | 1627 | syscall_munge(); | 
|  | 1628 | } | 
| Jason Baron | 3a9089f | 2009-12-01 12:18:49 -0500 | [diff] [blame] | 1629 | if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || | 
|  | 1630 | $prototype =~ /DEFINE_SINGLE_EVENT/) | 
|  | 1631 | { | 
| Jason Baron | 56afb0f | 2009-04-30 13:29:36 -0400 | [diff] [blame] | 1632 | tracepoint_munge($file); | 
|  | 1633 | } | 
| Randy Dunlap | b4870bc | 2009-02-11 13:04:33 -0800 | [diff] [blame] | 1634 | dump_function($prototype, $file); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1635 | reset_state(); | 
|  | 1636 | } | 
|  | 1637 | } | 
|  | 1638 |  | 
| Daniel Vetter | b7afa92 | 2016-06-01 23:46:24 +0200 | [diff] [blame] | 1639 | sub process_proto_type($$) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1640 | my $x = shift; | 
|  | 1641 | my $file = shift; | 
|  | 1642 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. | 
|  | 1644 | $x =~ s@^\s+@@gos; # strip leading spaces | 
|  | 1645 | $x =~ s@\s+$@@gos; # strip trailing spaces | 
| Randy Dunlap | 51f5a0c | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1646 | $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line | 
|  | 1647 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | if ($x =~ /^#/) { | 
|  | 1649 | # To distinguish preprocessor directive from regular declaration later. | 
|  | 1650 | $x .= ";"; | 
|  | 1651 | } | 
|  | 1652 |  | 
|  | 1653 | while (1) { | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1654 | if ( $x =~ /([^{};]*)([{};])(.*)/ ) { | 
| Markus Heiser | 463a0fd | 2017-06-16 21:27:48 +0200 | [diff] [blame] | 1655 | if( length $prototype ) { | 
|  | 1656 | $prototype .= " " | 
|  | 1657 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | $prototype .= $1 . $2; | 
|  | 1659 | ($2 eq '{') && $brcount++; | 
|  | 1660 | ($2 eq '}') && $brcount--; | 
|  | 1661 | if (($2 eq ';') && ($brcount == 0)) { | 
| Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1662 | dump_declaration($prototype, $file); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | reset_state(); | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1664 | last; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | } | 
|  | 1666 | $x = $3; | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1667 | } else { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | $prototype .= $x; | 
|  | 1669 | last; | 
|  | 1670 | } | 
|  | 1671 | } | 
|  | 1672 | } | 
|  | 1673 |  | 
| Randy Dunlap | 6b5b55f | 2007-10-16 23:31:20 -0700 | [diff] [blame] | 1674 | # xml_escape: replace <, >, and & in the text stream; | 
|  | 1675 | # | 
|  | 1676 | # however, formatting controls that are generated internally/locally in the | 
|  | 1677 | # kernel-doc script are not escaped here; instead, they begin life like | 
|  | 1678 | # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings | 
|  | 1679 | # are converted to their mnemonic-expected output, without the 4 * '\' & ':', | 
|  | 1680 | # just before actual output; (this is done by local_unescape()) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | sub xml_escape($) { | 
|  | 1682 | my $text = shift; | 
| Mauro Carvalho Chehab | b051426 | 2017-12-18 10:30:09 -0200 | [diff] [blame^] | 1683 | if ($output_mode eq "man") { | 
| Randy Dunlap | ecfb251 | 2006-06-25 05:49:13 -0700 | [diff] [blame] | 1684 | return $text; | 
|  | 1685 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | $text =~ s/\&/\\\\\\amp;/g; | 
|  | 1687 | $text =~ s/\</\\\\\\lt;/g; | 
|  | 1688 | $text =~ s/\>/\\\\\\gt;/g; | 
|  | 1689 | return $text; | 
|  | 1690 | } | 
|  | 1691 |  | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1692 | # xml_unescape: reverse the effects of xml_escape | 
|  | 1693 | sub xml_unescape($) { | 
|  | 1694 | my $text = shift; | 
| Mauro Carvalho Chehab | b051426 | 2017-12-18 10:30:09 -0200 | [diff] [blame^] | 1695 | if ($output_mode eq "man") { | 
| Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1696 | return $text; | 
|  | 1697 | } | 
|  | 1698 | $text =~ s/\\\\\\amp;/\&/g; | 
|  | 1699 | $text =~ s/\\\\\\lt;/</g; | 
|  | 1700 | $text =~ s/\\\\\\gt;/>/g; | 
|  | 1701 | return $text; | 
|  | 1702 | } | 
|  | 1703 |  | 
| Randy Dunlap | 6b5b55f | 2007-10-16 23:31:20 -0700 | [diff] [blame] | 1704 | # convert local escape strings to html | 
|  | 1705 | # local escape strings look like:  '\\\\menmonic:' (that's 4 backslashes) | 
|  | 1706 | sub local_unescape($) { | 
|  | 1707 | my $text = shift; | 
| Mauro Carvalho Chehab | b051426 | 2017-12-18 10:30:09 -0200 | [diff] [blame^] | 1708 | if ($output_mode eq "man") { | 
| Randy Dunlap | 6b5b55f | 2007-10-16 23:31:20 -0700 | [diff] [blame] | 1709 | return $text; | 
|  | 1710 | } | 
|  | 1711 | $text =~ s/\\\\\\\\lt:/</g; | 
|  | 1712 | $text =~ s/\\\\\\\\gt:/>/g; | 
|  | 1713 | return $text; | 
|  | 1714 | } | 
|  | 1715 |  | 
| Jani Nikula | 1ad560e | 2016-06-07 10:53:39 +0300 | [diff] [blame] | 1716 | sub map_filename($) { | 
|  | 1717 | my $file; | 
|  | 1718 | my ($orig_file) = @_; | 
|  | 1719 |  | 
|  | 1720 | if (defined($ENV{'SRCTREE'})) { | 
|  | 1721 | $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; | 
|  | 1722 | } else { | 
|  | 1723 | $file = $orig_file; | 
|  | 1724 | } | 
|  | 1725 |  | 
|  | 1726 | if (defined($source_map{$file})) { | 
|  | 1727 | $file = $source_map{$file}; | 
|  | 1728 | } | 
|  | 1729 |  | 
|  | 1730 | return $file; | 
|  | 1731 | } | 
|  | 1732 |  | 
| Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 1733 | sub process_export_file($) { | 
|  | 1734 | my ($orig_file) = @_; | 
|  | 1735 | my $file = map_filename($orig_file); | 
|  | 1736 |  | 
|  | 1737 | if (!open(IN,"<$file")) { | 
|  | 1738 | print STDERR "Error: Cannot open file $file\n"; | 
|  | 1739 | ++$errors; | 
|  | 1740 | return; | 
|  | 1741 | } | 
|  | 1742 |  | 
|  | 1743 | while (<IN>) { | 
|  | 1744 | if (/$export_symbol/) { | 
|  | 1745 | $function_table{$2} = 1; | 
|  | 1746 | } | 
|  | 1747 | } | 
|  | 1748 |  | 
|  | 1749 | close(IN); | 
|  | 1750 | } | 
|  | 1751 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | sub process_file($) { | 
| Randy Dunlap | 2283a11 | 2005-07-07 15:39:26 -0700 | [diff] [blame] | 1753 | my $file; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | my $identifier; | 
|  | 1755 | my $func; | 
| Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1756 | my $descr; | 
| Johannes Weiner | 6423133 | 2009-09-17 19:26:53 -0700 | [diff] [blame] | 1757 | my $in_purpose = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1758 | my $initial_section_counter = $section_counter; | 
| Ben Hutchings | 68f8666 | 2015-09-01 23:48:49 +0100 | [diff] [blame] | 1759 | my ($orig_file) = @_; | 
| Jani Nikula | b7886de | 2016-05-28 00:41:50 +0300 | [diff] [blame] | 1760 | my $leading_space; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1761 |  | 
| Jani Nikula | 1ad560e | 2016-06-07 10:53:39 +0300 | [diff] [blame] | 1762 | $file = map_filename($orig_file); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 |  | 
|  | 1764 | if (!open(IN,"<$file")) { | 
|  | 1765 | print STDERR "Error: Cannot open file $file\n"; | 
|  | 1766 | ++$errors; | 
|  | 1767 | return; | 
|  | 1768 | } | 
|  | 1769 |  | 
| Ilya Dryomov | a9e7314 | 2010-02-26 13:05:47 -0800 | [diff] [blame] | 1770 | $. = 1; | 
|  | 1771 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | $section_counter = 0; | 
|  | 1773 | while (<IN>) { | 
| Daniel Santos | 6547842 | 2012-10-04 17:15:05 -0700 | [diff] [blame] | 1774 | while (s/\\\s*$//) { | 
|  | 1775 | $_ .= <IN>; | 
|  | 1776 | } | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1777 | if ($state == STATE_NORMAL) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | if (/$doc_start/o) { | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1779 | $state = STATE_NAME;	# next line is always the function name | 
| Randy Dunlap | 850622d | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 1780 | $in_doc_sect = 0; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 1781 | $declaration_start_line = $. + 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | } | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1783 | } elsif ($state == STATE_NAME) {# this line is the function name (always) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | if (/$doc_block/o) { | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1785 | $state = STATE_DOCBLOCK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | $contents = ""; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 1787 | $new_start_line = $. + 1; | 
|  | 1788 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | if ( $1 eq "" ) { | 
|  | 1790 | $section = $section_intro; | 
|  | 1791 | } else { | 
|  | 1792 | $section = $1; | 
|  | 1793 | } | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1794 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | elsif (/$doc_decl/o) { | 
|  | 1796 | $identifier = $1; | 
|  | 1797 | if (/\s*([\w\s]+?)\s*-/) { | 
|  | 1798 | $identifier = $1; | 
|  | 1799 | } | 
|  | 1800 |  | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1801 | $state = STATE_FIELD; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 1802 | # if there's no @param blocks need to set up default section | 
|  | 1803 | # here | 
| Jani Nikula | 2f4ad40 | 2016-05-30 11:21:06 +0300 | [diff] [blame] | 1804 | $contents = ""; | 
|  | 1805 | $section = $section_default; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 1806 | $new_start_line = $. + 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | if (/-(.*)/) { | 
| Randy Dunlap | 51f5a0c | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1808 | # strip leading/trailing/multiple spaces | 
| Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1809 | $descr= $1; | 
|  | 1810 | $descr =~ s/^\s*//; | 
|  | 1811 | $descr =~ s/\s*$//; | 
| Daniel Santos | 12ae677 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 1812 | $descr =~ s/\s+/ /g; | 
| Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1813 | $declaration_purpose = xml_escape($descr); | 
| Johannes Weiner | 6423133 | 2009-09-17 19:26:53 -0700 | [diff] [blame] | 1814 | $in_purpose = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | } else { | 
|  | 1816 | $declaration_purpose = ""; | 
|  | 1817 | } | 
| Randy Dunlap | 77cc23b | 2008-02-07 00:13:42 -0800 | [diff] [blame] | 1818 |  | 
|  | 1819 | if (($declaration_purpose eq "") && $verbose) { | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1820 | print STDERR "${file}:$.: warning: missing initial short description on line:\n"; | 
| Randy Dunlap | 77cc23b | 2008-02-07 00:13:42 -0800 | [diff] [blame] | 1821 | print STDERR $_; | 
|  | 1822 | ++$warnings; | 
|  | 1823 | } | 
|  | 1824 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | if ($identifier =~ m/^struct/) { | 
|  | 1826 | $decl_type = 'struct'; | 
|  | 1827 | } elsif ($identifier =~ m/^union/) { | 
|  | 1828 | $decl_type = 'union'; | 
|  | 1829 | } elsif ($identifier =~ m/^enum/) { | 
|  | 1830 | $decl_type = 'enum'; | 
|  | 1831 | } elsif ($identifier =~ m/^typedef/) { | 
|  | 1832 | $decl_type = 'typedef'; | 
|  | 1833 | } else { | 
|  | 1834 | $decl_type = 'function'; | 
|  | 1835 | } | 
|  | 1836 |  | 
|  | 1837 | if ($verbose) { | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1838 | print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | } | 
|  | 1840 | } else { | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1841 | print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | " - I thought it was a doc line\n"; | 
|  | 1843 | ++$warnings; | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1844 | $state = STATE_NORMAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | } | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1846 | } elsif ($state == STATE_FIELD) {	# look for head: lines, and include content | 
| Jani Nikula | f624ade | 2016-05-29 11:35:28 +0300 | [diff] [blame] | 1847 | if (/$doc_sect/i) { # case insensitive for supported section names | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | $newsection = $1; | 
|  | 1849 | $newcontents = $2; | 
|  | 1850 |  | 
| Jani Nikula | f624ade | 2016-05-29 11:35:28 +0300 | [diff] [blame] | 1851 | # map the supported section names to the canonical names | 
|  | 1852 | if ($newsection =~ m/^description$/i) { | 
|  | 1853 | $newsection = $section_default; | 
|  | 1854 | } elsif ($newsection =~ m/^context$/i) { | 
|  | 1855 | $newsection = $section_context; | 
|  | 1856 | } elsif ($newsection =~ m/^returns?$/i) { | 
|  | 1857 | $newsection = $section_return; | 
|  | 1858 | } elsif ($newsection =~ m/^\@return$/) { | 
|  | 1859 | # special: @return is a section, not a param description | 
|  | 1860 | $newsection = $section_return; | 
|  | 1861 | } | 
|  | 1862 |  | 
| Randy Dunlap | 792aa2f | 2008-02-07 00:13:41 -0800 | [diff] [blame] | 1863 | if (($contents ne "") && ($contents ne "\n")) { | 
| Randy Dunlap | 850622d | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 1864 | if (!$in_doc_sect && $verbose) { | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1865 | print STDERR "${file}:$.: warning: contents before sections\n"; | 
| Randy Dunlap | 850622d | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 1866 | ++$warnings; | 
|  | 1867 | } | 
| Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 1868 | dump_section($file, $section, xml_escape($contents)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | $section = $section_default; | 
|  | 1870 | } | 
|  | 1871 |  | 
| Randy Dunlap | 850622d | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 1872 | $in_doc_sect = 1; | 
| Johannes Weiner | 6423133 | 2009-09-17 19:26:53 -0700 | [diff] [blame] | 1873 | $in_purpose = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | $contents = $newcontents; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 1875 | $new_start_line = $.; | 
| Jani Nikula | 0a72630 | 2016-05-28 14:50:20 +0300 | [diff] [blame] | 1876 | while ((substr($contents, 0, 1) eq " ") || | 
|  | 1877 | substr($contents, 0, 1) eq "\t") { | 
|  | 1878 | $contents = substr($contents, 1); | 
|  | 1879 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | if ($contents ne "") { | 
|  | 1881 | $contents .= "\n"; | 
|  | 1882 | } | 
|  | 1883 | $section = $newsection; | 
| Jani Nikula | b7886de | 2016-05-28 00:41:50 +0300 | [diff] [blame] | 1884 | $leading_space = undef; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | } elsif (/$doc_end/) { | 
| Randy Dunlap | 4c98eca | 2010-03-10 15:22:02 -0800 | [diff] [blame] | 1886 | if (($contents ne "") && ($contents ne "\n")) { | 
| Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 1887 | dump_section($file, $section, xml_escape($contents)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | $section = $section_default; | 
|  | 1889 | $contents = ""; | 
|  | 1890 | } | 
| Randy Dunlap | 46b958e | 2008-04-28 02:16:35 -0700 | [diff] [blame] | 1891 | # look for doc_com + <text> + doc_end: | 
|  | 1892 | if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1893 | print STDERR "${file}:$.: warning: suspicious ending line: $_"; | 
| Randy Dunlap | 46b958e | 2008-04-28 02:16:35 -0700 | [diff] [blame] | 1894 | ++$warnings; | 
|  | 1895 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1896 |  | 
|  | 1897 | $prototype = ""; | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1898 | $state = STATE_PROTO; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | $brcount = 0; | 
| Randy Dunlap | 232acbc | 2006-06-25 05:47:48 -0700 | [diff] [blame] | 1900 | #		print STDERR "end of doc comment, looking for prototype\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1901 | } elsif (/$doc_content/) { | 
|  | 1902 | # miguel-style comment kludge, look for blank lines after | 
|  | 1903 | # @parameter line to signify start of description | 
| Johannes Weiner | 6423133 | 2009-09-17 19:26:53 -0700 | [diff] [blame] | 1904 | if ($1 eq "") { | 
|  | 1905 | if ($section =~ m/^@/ || $section eq $section_context) { | 
|  | 1906 | dump_section($file, $section, xml_escape($contents)); | 
|  | 1907 | $section = $section_default; | 
|  | 1908 | $contents = ""; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 1909 | $new_start_line = $.; | 
| Johannes Weiner | 6423133 | 2009-09-17 19:26:53 -0700 | [diff] [blame] | 1910 | } else { | 
|  | 1911 | $contents .= "\n"; | 
|  | 1912 | } | 
|  | 1913 | $in_purpose = 0; | 
|  | 1914 | } elsif ($in_purpose == 1) { | 
|  | 1915 | # Continued declaration purpose | 
|  | 1916 | chomp($declaration_purpose); | 
|  | 1917 | $declaration_purpose .= " " . xml_escape($1); | 
| Daniel Santos | 12ae677 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 1918 | $declaration_purpose =~ s/\s+/ /g; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | } else { | 
| Jani Nikula | b7886de | 2016-05-28 00:41:50 +0300 | [diff] [blame] | 1920 | my $cont = $1; | 
|  | 1921 | if ($section =~ m/^@/ || $section eq $section_context) { | 
|  | 1922 | if (!defined $leading_space) { | 
|  | 1923 | if ($cont =~ m/^(\s+)/) { | 
|  | 1924 | $leading_space = $1; | 
|  | 1925 | } else { | 
|  | 1926 | $leading_space = ""; | 
|  | 1927 | } | 
|  | 1928 | } | 
|  | 1929 |  | 
|  | 1930 | $cont =~ s/^$leading_space//; | 
|  | 1931 | } | 
|  | 1932 | $contents .= $cont . "\n"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | } | 
|  | 1934 | } else { | 
|  | 1935 | # i dont know - bad line?  ignore. | 
| Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 1936 | print STDERR "${file}:$.: warning: bad line: $_"; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1937 | ++$warnings; | 
|  | 1938 | } | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1939 | } elsif ($state == STATE_INLINE) { # scanning for inline parameters | 
| Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 1940 | # First line (state 1) needs to be a @parameter | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1941 | if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { | 
| Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 1942 | $section = $1; | 
|  | 1943 | $contents = $2; | 
| Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 1944 | $new_start_line = $.; | 
| Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 1945 | if ($contents ne "") { | 
|  | 1946 | while ((substr($contents, 0, 1) eq " ") || | 
|  | 1947 | substr($contents, 0, 1) eq "\t") { | 
|  | 1948 | $contents = substr($contents, 1); | 
|  | 1949 | } | 
| Jani Nikula | a0b96c2 | 2016-05-26 22:04:06 +0300 | [diff] [blame] | 1950 | $contents .= "\n"; | 
| Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 1951 | } | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1952 | $inline_doc_state = STATE_INLINE_TEXT; | 
| Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 1953 | # Documentation block end */ | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1954 | } elsif (/$doc_inline_end/) { | 
| Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 1955 | if (($contents ne "") && ($contents ne "\n")) { | 
|  | 1956 | dump_section($file, $section, xml_escape($contents)); | 
|  | 1957 | $section = $section_default; | 
|  | 1958 | $contents = ""; | 
|  | 1959 | } | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1960 | $state = STATE_PROTO; | 
|  | 1961 | $inline_doc_state = STATE_INLINE_NA; | 
| Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 1962 | # Regular text | 
|  | 1963 | } elsif (/$doc_content/) { | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1964 | if ($inline_doc_state == STATE_INLINE_TEXT) { | 
| Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 1965 | $contents .= $1 . "\n"; | 
| Jani Nikula | 6450c89 | 2016-05-26 22:04:42 +0300 | [diff] [blame] | 1966 | # nuke leading blank lines | 
|  | 1967 | if ($contents =~ /^\s*$/) { | 
|  | 1968 | $contents = ""; | 
|  | 1969 | } | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1970 | } elsif ($inline_doc_state == STATE_INLINE_NAME) { | 
|  | 1971 | $inline_doc_state = STATE_INLINE_ERROR; | 
| Daniel Vetter | e7ca311 | 2016-07-15 10:19:30 +0200 | [diff] [blame] | 1972 | print STDERR "${file}:$.: warning: "; | 
| Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 1973 | print STDERR "Incorrect use of kernel-doc format: $_"; | 
|  | 1974 | ++$warnings; | 
|  | 1975 | } | 
|  | 1976 | } | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1977 | } elsif ($state == STATE_PROTO) {	# scanning for function '{' (end of prototype) | 
| Jani Nikula | 0c9aa20 | 2016-11-16 17:26:16 +0200 | [diff] [blame] | 1978 | if (/$doc_inline_oneline/) { | 
|  | 1979 | $section = $1; | 
|  | 1980 | $contents = $2; | 
|  | 1981 | if ($contents ne "") { | 
|  | 1982 | $contents .= "\n"; | 
|  | 1983 | dump_section($file, $section, xml_escape($contents)); | 
|  | 1984 | $section = $section_default; | 
|  | 1985 | $contents = ""; | 
|  | 1986 | } | 
|  | 1987 | } elsif (/$doc_inline_start/) { | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1988 | $state = STATE_INLINE; | 
|  | 1989 | $inline_doc_state = STATE_INLINE_NAME; | 
| Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 1990 | } elsif ($decl_type eq 'function') { | 
| Daniel Vetter | b7afa92 | 2016-06-01 23:46:24 +0200 | [diff] [blame] | 1991 | process_proto_function($_, $file); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | } else { | 
| Daniel Vetter | b7afa92 | 2016-06-01 23:46:24 +0200 | [diff] [blame] | 1993 | process_proto_type($_, $file); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | } | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 1995 | } elsif ($state == STATE_DOCBLOCK) { | 
| Daniel Vetter | ebff7f9 | 2016-06-01 23:46:23 +0200 | [diff] [blame] | 1996 | if (/$doc_end/) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1997 | { | 
| Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 1998 | dump_doc_section($file, $section, xml_escape($contents)); | 
| Jani Nikula | 2f4ad40 | 2016-05-30 11:21:06 +0300 | [diff] [blame] | 1999 | $section = $section_default; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | $contents = ""; | 
|  | 2001 | $function = ""; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | %parameterdescs = (); | 
|  | 2003 | %parametertypes = (); | 
|  | 2004 | @parameterlist = (); | 
|  | 2005 | %sections = (); | 
|  | 2006 | @sectionlist = (); | 
|  | 2007 | $prototype = ""; | 
| Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 2008 | $state = STATE_NORMAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | } | 
|  | 2010 | elsif (/$doc_content/) | 
|  | 2011 | { | 
|  | 2012 | if ( $1 eq "" ) | 
|  | 2013 | { | 
|  | 2014 | $contents .= $blankline; | 
|  | 2015 | } | 
|  | 2016 | else | 
|  | 2017 | { | 
|  | 2018 | $contents .= $1 . "\n"; | 
| Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 2019 | } | 
| Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2020 | } | 
|  | 2021 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | } | 
|  | 2023 | if ($initial_section_counter == $section_counter) { | 
| Matthew Wilcox | 3a025e1 | 2017-11-20 10:40:40 -0800 | [diff] [blame] | 2024 | if ($output_mode ne "none") { | 
|  | 2025 | print STDERR "${file}:1: warning: no structured comments found\n"; | 
|  | 2026 | } | 
| Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 2027 | if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) { | 
| Johannes Berg | e946c43a | 2013-11-12 15:11:12 -0800 | [diff] [blame] | 2028 | print STDERR "    Was looking for '$_'.\n" for keys %function_table; | 
|  | 2029 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | } | 
|  | 2031 | } | 
| Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 2032 |  | 
|  | 2033 |  | 
|  | 2034 | $kernelversion = get_kernel_version(); | 
|  | 2035 |  | 
|  | 2036 | # generate a sequence of code that will splice in highlighting information | 
|  | 2037 | # using the s// operator. | 
| Mauro Carvalho Chehab | 1ef0623 | 2015-11-17 13:29:49 -0200 | [diff] [blame] | 2038 | for (my $k = 0; $k < @highlights; $k++) { | 
| Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 2039 | my $pattern = $highlights[$k][0]; | 
|  | 2040 | my $result = $highlights[$k][1]; | 
|  | 2041 | #   print STDERR "scanning pattern:$pattern, highlight:($result)\n"; | 
|  | 2042 | $dohighlight .=  "\$contents =~ s:$pattern:$result:gs;\n"; | 
| Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 2043 | } | 
|  | 2044 |  | 
|  | 2045 | # Read the file that maps relative names to absolute names for | 
|  | 2046 | # separate source and object directories and for shadow trees. | 
|  | 2047 | if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { | 
|  | 2048 | my ($relname, $absname); | 
|  | 2049 | while(<SOURCE_MAP>) { | 
|  | 2050 | chop(); | 
|  | 2051 | ($relname, $absname) = (split())[0..1]; | 
|  | 2052 | $relname =~ s:^/+::; | 
|  | 2053 | $source_map{$relname} = $absname; | 
|  | 2054 | } | 
|  | 2055 | close(SOURCE_MAP); | 
|  | 2056 | } | 
|  | 2057 |  | 
| Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 2058 | if ($output_selection == OUTPUT_EXPORTED || | 
|  | 2059 | $output_selection == OUTPUT_INTERNAL) { | 
| Jani Nikula | c9b2cfb | 2016-06-07 11:05:53 +0300 | [diff] [blame] | 2060 |  | 
|  | 2061 | push(@export_file_list, @ARGV); | 
|  | 2062 |  | 
| Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 2063 | foreach (@export_file_list) { | 
|  | 2064 | chomp; | 
|  | 2065 | process_export_file($_); | 
|  | 2066 | } | 
|  | 2067 | } | 
|  | 2068 |  | 
| Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 2069 | foreach (@ARGV) { | 
|  | 2070 | chomp; | 
|  | 2071 | process_file($_); | 
|  | 2072 | } | 
|  | 2073 | if ($verbose && $errors) { | 
|  | 2074 | print STDERR "$errors errors\n"; | 
|  | 2075 | } | 
|  | 2076 | if ($verbose && $warnings) { | 
|  | 2077 | print STDERR "$warnings warnings\n"; | 
|  | 2078 | } | 
|  | 2079 |  | 
| Will Deacon | e814bcc | 2017-11-29 15:20:03 +0000 | [diff] [blame] | 2080 | exit($output_mode eq "none" ? 0 : $errors); |