Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #!/usr/bin/perl -w |
| 2 | |
| 3 | use strict; |
| 4 | |
| 5 | ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## |
| 6 | ## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## |
| 7 | ## Copyright (C) 2001 Simon Huggins ## |
Randy Dunlap | 70c95b0 | 2012-01-21 10:31:54 -0800 | [diff] [blame] | 8 | ## Copyright (C) 2005-2012 Randy Dunlap ## |
Dan Luedtke | 1b40c19 | 2012-08-12 10:46:15 +0200 | [diff] [blame] | 9 | ## Copyright (C) 2012 Dan Luedtke ## |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | ## ## |
| 11 | ## #define enhancements by Armin Kuster <akuster@mvista.com> ## |
| 12 | ## Copyright (c) 2000 MontaVista Software, Inc. ## |
| 13 | ## ## |
| 14 | ## This software falls under the GNU General Public License. ## |
| 15 | ## Please read the COPYING file for more information ## |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | # 18/01/2001 - Cleanups |
| 18 | # Functions prototyped as foo(void) same as foo() |
| 19 | # Stop eval'ing where we don't need to. |
| 20 | # -- huggie@earth.li |
| 21 | |
| 22 | # 27/06/2001 - Allowed whitespace after initial "/**" and |
| 23 | # allowed comments before function declarations. |
| 24 | # -- Christian Kreibich <ck@whoop.org> |
| 25 | |
| 26 | # Still to do: |
| 27 | # - add perldoc documentation |
| 28 | # - Look more closely at some of the scarier bits :) |
| 29 | |
| 30 | # 26/05/2001 - Support for separate source and object trees. |
| 31 | # Return error code. |
| 32 | # Keith Owens <kaos@ocs.com.au> |
| 33 | |
| 34 | # 23/09/2001 - Added support for typedefs, structs, enums and unions |
| 35 | # Support for Context section; can be terminated using empty line |
| 36 | # Small fixes (like spaces vs. \s in regex) |
| 37 | # -- Tim Jansen <tim@tjansen.de> |
| 38 | |
Dan Luedtke | 1b40c19 | 2012-08-12 10:46:15 +0200 | [diff] [blame] | 39 | # 25/07/2012 - Added support for HTML5 |
| 40 | # -- Dan Luedtke <mail@danrl.de> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Jani Nikula | fadc0b3 | 2016-05-12 16:15:36 +0300 | [diff] [blame] | 42 | sub usage { |
| 43 | my $message = <<"EOF"; |
| 44 | Usage: $0 [OPTION ...] FILE ... |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Jani Nikula | fadc0b3 | 2016-05-12 16:15:36 +0300 | [diff] [blame] | 46 | Read C language source or header FILEs, extract embedded documentation comments, |
| 47 | and print formatted documentation to standard output. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Jani Nikula | fadc0b3 | 2016-05-12 16:15:36 +0300 | [diff] [blame] | 49 | The documentation comments are identified by "/**" opening comment mark. See |
| 50 | Documentation/kernel-doc-nano-HOWTO.txt for the documentation comment syntax. |
| 51 | |
| 52 | Output format selection (mutually exclusive): |
| 53 | -docbook Output DocBook format. |
| 54 | -html Output HTML format. |
| 55 | -html5 Output HTML5 format. |
| 56 | -list Output symbol list format. This is for use by docproc. |
| 57 | -man Output troff manual page format. This is the default. |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 58 | -rst Output reStructuredText format. |
Jani Nikula | fadc0b3 | 2016-05-12 16:15:36 +0300 | [diff] [blame] | 59 | -text Output plain text format. |
| 60 | |
| 61 | Output selection (mutually exclusive): |
Jani Nikula | 86ae2e3 | 2016-01-21 13:05:22 +0200 | [diff] [blame] | 62 | -export Only output documentation for symbols that have 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 | 86ae2e3 | 2016-01-21 13:05:22 +0200 | [diff] [blame] | 65 | -internal Only output documentation for symbols that have NOT been |
| 66 | exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() |
Jani Nikula | c9b2cfb | 2016-06-07 11:05:53 +0300 | [diff] [blame] | 67 | in any input FILE or -export-file FILE. |
Jani Nikula | fadc0b3 | 2016-05-12 16:15:36 +0300 | [diff] [blame] | 68 | -function NAME Only output documentation for the given function(s) |
| 69 | or DOC: section title(s). All other functions and DOC: |
| 70 | sections are ignored. May be specified multiple times. |
| 71 | -nofunction NAME Do NOT output documentation for the given function(s); |
| 72 | only output documentation for the other functions and |
| 73 | DOC: sections. May be specified multiple times. |
| 74 | |
| 75 | Output selection modifiers: |
| 76 | -no-doc-sections Do not output DOC: sections. |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 77 | -enable-lineno Enable output of #define LINENO lines. Only works with |
| 78 | reStructuredText format. |
Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 79 | -export-file FILE Specify an additional FILE in which to look for |
| 80 | EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with |
| 81 | -export or -internal. May be specified multiple times. |
Jani Nikula | fadc0b3 | 2016-05-12 16:15:36 +0300 | [diff] [blame] | 82 | |
| 83 | Other parameters: |
| 84 | -v Verbose output, more warnings and other information. |
| 85 | -h Print this help. |
| 86 | |
| 87 | EOF |
| 88 | print $message; |
| 89 | exit 1; |
| 90 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | # |
| 93 | # format of comments. |
| 94 | # In the following table, (...)? signifies optional structure. |
| 95 | # (...)* signifies 0 or more structure elements |
| 96 | # /** |
| 97 | # * function_name(:)? (- short description)? |
| 98 | # (* @parameterx: (description of parameter x)?)* |
| 99 | # (* a blank line)? |
| 100 | # * (Description:)? (Description of function)? |
| 101 | # * (section header: (section description)? )* |
| 102 | # (*)?*/ |
| 103 | # |
| 104 | # So .. the trivial example would be: |
| 105 | # |
| 106 | # /** |
| 107 | # * my_function |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 108 | # */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | # |
Randy Dunlap | 891dcd2 | 2007-02-10 01:45:53 -0800 | [diff] [blame] | 110 | # 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] | 111 | # after the last parameter specification. |
| 112 | # e.g. |
| 113 | # /** |
| 114 | # * my_function - does my stuff |
| 115 | # * @my_arg: its mine damnit |
| 116 | # * |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 117 | # * Does my stuff explained. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | # */ |
| 119 | # |
| 120 | # or, could also use: |
| 121 | # /** |
| 122 | # * my_function - does my stuff |
| 123 | # * @my_arg: its mine damnit |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 124 | # * Description: Does my stuff explained. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | # */ |
| 126 | # etc. |
| 127 | # |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 128 | # Besides functions you can also write documentation for structs, unions, |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 129 | # enums and typedefs. Instead of the function name you must write the name |
| 130 | # of the declaration; the struct/union/enum/typedef must always precede |
| 131 | # the name. Nesting of declarations is not supported. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | # Use the argument mechanism to document members or constants. |
| 133 | # e.g. |
| 134 | # /** |
| 135 | # * struct my_struct - short description |
| 136 | # * @a: first member |
| 137 | # * @b: second member |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 138 | # * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | # * Longer description |
| 140 | # */ |
| 141 | # struct my_struct { |
| 142 | # int a; |
| 143 | # int b; |
Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 144 | # /* private: */ |
| 145 | # int c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | # }; |
| 147 | # |
| 148 | # All descriptions can be multiline, except the short function description. |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 149 | # |
Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 150 | # For really longs structs, you can also describe arguments inside the |
| 151 | # body of the struct. |
| 152 | # eg. |
| 153 | # /** |
| 154 | # * struct my_struct - short description |
| 155 | # * @a: first member |
| 156 | # * @b: second member |
| 157 | # * |
| 158 | # * Longer description |
| 159 | # */ |
| 160 | # struct my_struct { |
| 161 | # int a; |
| 162 | # int b; |
| 163 | # /** |
| 164 | # * @c: This is longer description of C |
| 165 | # * |
| 166 | # * You can use paragraphs to describe arguments |
| 167 | # * using this method. |
| 168 | # */ |
| 169 | # int c; |
| 170 | # }; |
| 171 | # |
| 172 | # This should be use only for struct/enum members. |
| 173 | # |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 174 | # You can also add additional sections. When documenting kernel functions you |
| 175 | # should document the "Context:" of the function, e.g. whether the functions |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | # 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] | 177 | # empty line. |
Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 178 | # A non-void function should have a "Return:" section describing the return |
| 179 | # value(s). |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 180 | # Example-sections should contain the string EXAMPLE so that they are marked |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | # appropriately in DocBook. |
| 182 | # |
| 183 | # Example: |
| 184 | # /** |
| 185 | # * user_function - function that can only be called in user context |
| 186 | # * @a: some argument |
| 187 | # * Context: !in_interrupt() |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 188 | # * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | # * Some description |
| 190 | # * Example: |
| 191 | # * user_function(22); |
| 192 | # */ |
| 193 | # ... |
| 194 | # |
| 195 | # |
| 196 | # All descriptive text is further processed, scanning for the following special |
| 197 | # patterns, which are highlighted appropriately. |
| 198 | # |
| 199 | # 'funcname()' - function |
| 200 | # '$ENVVAR' - environmental variable |
| 201 | # '&struct_name' - name of a structure (up to two words including 'struct') |
| 202 | # '@parameter' - name of a parameter |
| 203 | # '%CONST' - name of a constant. |
| 204 | |
Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 205 | ## init lots of data |
| 206 | |
Silvio Fricke | c950a17 | 2016-10-28 10:14:08 +0200 | [diff] [blame^] | 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | my $errors = 0; |
| 209 | my $warnings = 0; |
Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 210 | my $anon_struct_union = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
| 212 | # match expressions used to find embedded type information |
| 213 | my $type_constant = '\%([-_\w]+)'; |
| 214 | my $type_func = '(\w+)\(\)'; |
Silvio Fricke | c950a17 | 2016-10-28 10:14:08 +0200 | [diff] [blame^] | 215 | my $type_param = '\@(\w+(\.\.\.)?)'; |
Jonathan Corbet | 5219f18 | 2016-08-24 16:31:15 -0600 | [diff] [blame] | 216 | my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params |
Randy Dunlap | 3eb014a | 2007-05-08 00:29:51 -0700 | [diff] [blame] | 217 | my $type_struct = '\&((struct\s*)*[_\w]+)'; |
Randy Dunlap | 6b5b55f | 2007-10-16 23:31:20 -0700 | [diff] [blame] | 218 | my $type_struct_xml = '\\&((struct\s*)*[_\w]+)'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | my $type_env = '(\$\w+)'; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 220 | my $type_enum_full = '\&(enum)\s*([_\w]+)'; |
| 221 | my $type_struct_full = '\&(struct)\s*([_\w]+)'; |
Jani Nikula | 47ae7ae | 2016-05-26 13:57:18 +0300 | [diff] [blame] | 222 | my $type_typedef_full = '\&(typedef)\s*([_\w]+)'; |
| 223 | my $type_union_full = '\&(union)\s*([_\w]+)'; |
Jani Nikula | f3341dc | 2016-05-26 16:35:02 +0300 | [diff] [blame] | 224 | my $type_member = '\&([_\w]+)((\.|->)[_\w]+)'; |
| 225 | my $type_member_func = $type_member . '\(\)'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
| 227 | # Output conversion substitutions. |
| 228 | # One for each output format |
| 229 | |
| 230 | # these work fairly well |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 231 | my @highlights_html = ( |
| 232 | [$type_constant, "<i>\$1</i>"], |
| 233 | [$type_func, "<b>\$1</b>"], |
| 234 | [$type_struct_xml, "<i>\$1</i>"], |
| 235 | [$type_env, "<b><i>\$1</i></b>"], |
| 236 | [$type_param, "<tt><b>\$1</b></tt>"] |
| 237 | ); |
Randy Dunlap | 6b5b55f | 2007-10-16 23:31:20 -0700 | [diff] [blame] | 238 | my $local_lt = "\\\\\\\\lt:"; |
| 239 | my $local_gt = "\\\\\\\\gt:"; |
| 240 | my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
Dan Luedtke | 1b40c19 | 2012-08-12 10:46:15 +0200 | [diff] [blame] | 242 | # html version 5 |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 243 | my @highlights_html5 = ( |
| 244 | [$type_constant, "<span class=\"const\">\$1</span>"], |
| 245 | [$type_func, "<span class=\"func\">\$1</span>"], |
| 246 | [$type_struct_xml, "<span class=\"struct\">\$1</span>"], |
| 247 | [$type_env, "<span class=\"env\">\$1</span>"], |
| 248 | [$type_param, "<span class=\"param\">\$1</span>]"] |
| 249 | ); |
Dan Luedtke | 1b40c19 | 2012-08-12 10:46:15 +0200 | [diff] [blame] | 250 | my $blankline_html5 = $local_lt . "br /" . $local_gt; |
| 251 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | # XML, docbook format |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 253 | my @highlights_xml = ( |
| 254 | ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"], |
| 255 | [$type_constant, "<constant>\$1</constant>"], |
| 256 | [$type_struct_xml, "<structname>\$1</structname>"], |
| 257 | [$type_param, "<parameter>\$1</parameter>"], |
| 258 | [$type_func, "<function>\$1</function>"], |
| 259 | [$type_env, "<envar>\$1</envar>"] |
| 260 | ); |
Johannes Berg | 5c98fc0 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 261 | my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
| 263 | # gnome, docbook format |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 264 | my @highlights_gnome = ( |
| 265 | [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"], |
| 266 | [$type_func, "<function>\$1</function>"], |
| 267 | [$type_struct, "<structname>\$1</structname>"], |
| 268 | [$type_env, "<envar>\$1</envar>"], |
| 269 | [$type_param, "<parameter>\$1</parameter>" ] |
| 270 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | my $blankline_gnome = "</para><para>\n"; |
| 272 | |
| 273 | # these are pretty rough |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 274 | my @highlights_man = ( |
| 275 | [$type_constant, "\$1"], |
| 276 | [$type_func, "\\\\fB\$1\\\\fP"], |
| 277 | [$type_struct, "\\\\fI\$1\\\\fP"], |
| 278 | [$type_param, "\\\\fI\$1\\\\fP"] |
| 279 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | my $blankline_man = ""; |
| 281 | |
| 282 | # text-mode |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 283 | my @highlights_text = ( |
| 284 | [$type_constant, "\$1"], |
| 285 | [$type_func, "\$1"], |
| 286 | [$type_struct, "\$1"], |
| 287 | [$type_param, "\$1"] |
| 288 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | my $blankline_text = ""; |
| 290 | |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 291 | # rst-mode |
| 292 | my @highlights_rst = ( |
| 293 | [$type_constant, "``\$1``"], |
Jani Nikula | f3341dc | 2016-05-26 16:35:02 +0300 | [diff] [blame] | 294 | # Note: need to escape () to avoid func matching later |
| 295 | [$type_member_func, "\\:c\\:type\\:`\$1\$2\\\\(\\\\) <\$1>`"], |
| 296 | [$type_member, "\\:c\\:type\\:`\$1\$2 <\$1>`"], |
Jonathan Corbet | 5219f18 | 2016-08-24 16:31:15 -0600 | [diff] [blame] | 297 | [$type_fp_param, "**\$1\\\\(\\\\)**"], |
Jani Nikula | a19bce6 | 2016-05-26 11:28:16 +0300 | [diff] [blame] | 298 | [$type_func, "\\:c\\:func\\:`\$1()`"], |
Jani Nikula | 6285097 | 2016-05-12 16:15:38 +0300 | [diff] [blame] | 299 | [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], |
| 300 | [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], |
Jani Nikula | 47ae7ae | 2016-05-26 13:57:18 +0300 | [diff] [blame] | 301 | [$type_typedef_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], |
| 302 | [$type_union_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], |
Jani Nikula | a7291e7 | 2016-05-26 13:57:06 +0300 | [diff] [blame] | 303 | # in rst this can refer to any type |
| 304 | [$type_struct, "\\:c\\:type\\:`\$1`"], |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 305 | [$type_param, "**\$1**"] |
| 306 | ); |
| 307 | my $blankline_rst = "\n"; |
| 308 | |
Johannes Berg | eda603f | 2010-09-11 15:55:22 -0700 | [diff] [blame] | 309 | # list mode |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 310 | my @highlights_list = ( |
| 311 | [$type_constant, "\$1"], |
| 312 | [$type_func, "\$1"], |
| 313 | [$type_struct, "\$1"], |
| 314 | [$type_param, "\$1"] |
| 315 | ); |
Johannes Berg | eda603f | 2010-09-11 15:55:22 -0700 | [diff] [blame] | 316 | my $blankline_list = ""; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | # read arguments |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 319 | if ($#ARGV == -1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | usage(); |
| 321 | } |
| 322 | |
Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 323 | my $kernelversion; |
| 324 | my $dohighlight = ""; |
| 325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | my $verbose = 0; |
| 327 | my $output_mode = "man"; |
Daniel Santos | e314ba3 | 2012-10-04 17:15:08 -0700 | [diff] [blame] | 328 | my $output_preformatted = 0; |
Johannes Berg | 4b44595 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 329 | my $no_doc_sections = 0; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 330 | my $enable_lineno = 0; |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 331 | my @highlights = @highlights_man; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | my $blankline = $blankline_man; |
| 333 | my $modulename = "Kernel API"; |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 334 | |
| 335 | use constant { |
| 336 | OUTPUT_ALL => 0, # output all symbols and doc sections |
| 337 | OUTPUT_INCLUDE => 1, # output only specified symbols |
| 338 | OUTPUT_EXCLUDE => 2, # output everything except specified symbols |
| 339 | OUTPUT_EXPORTED => 3, # output exported symbols |
| 340 | OUTPUT_INTERNAL => 4, # output non-exported symbols |
| 341 | }; |
| 342 | my $output_selection = OUTPUT_ALL; |
Ben Hutchings | b2c4105 | 2015-07-08 20:07:16 +0100 | [diff] [blame] | 343 | my $show_not_found = 0; |
| 344 | |
Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 345 | my @export_file_list; |
| 346 | |
Ben Hutchings | b2c4105 | 2015-07-08 20:07:16 +0100 | [diff] [blame] | 347 | my @build_time; |
| 348 | if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && |
| 349 | (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { |
| 350 | @build_time = gmtime($seconds); |
| 351 | } else { |
| 352 | @build_time = localtime; |
| 353 | } |
| 354 | |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 355 | my $man_date = ('January', 'February', 'March', 'April', 'May', 'June', |
| 356 | 'July', 'August', 'September', 'October', |
Ben Hutchings | b2c4105 | 2015-07-08 20:07:16 +0100 | [diff] [blame] | 357 | 'November', 'December')[$build_time[4]] . |
| 358 | " " . ($build_time[5]+1900); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 360 | # Essentially these are globals. |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 361 | # They probably want to be tidied up, made more localised or something. |
| 362 | # 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] | 363 | # could cause "use of undefined value" or other bugs. |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 364 | my ($function, %function_table, %parametertypes, $declaration_purpose); |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 365 | my $declaration_start_line; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 366 | my ($type, $declaration_name, $return_type); |
Ilya Dryomov | 1c32fd0 | 2010-02-26 13:06:03 -0800 | [diff] [blame] | 367 | my ($newsection, $newcontents, $prototype, $brcount, %source_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
Randy Dunlap | bd0e88e | 2008-03-13 12:32:43 -0700 | [diff] [blame] | 369 | if (defined($ENV{'KBUILD_VERBOSE'})) { |
| 370 | $verbose = "$ENV{'KBUILD_VERBOSE'}"; |
| 371 | } |
| 372 | |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 373 | # Generated docbook code is inserted in a template at a point where |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | # docbook v3.1 requires a non-zero sequence of RefEntry's; see: |
| 375 | # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html |
| 376 | # We keep track of number of generated entries and generate a dummy |
| 377 | # if needs be to ensure the expanded template can be postprocessed |
| 378 | # into html. |
| 379 | my $section_counter = 0; |
| 380 | |
| 381 | my $lineprefix=""; |
| 382 | |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 383 | # Parser states |
| 384 | use constant { |
| 385 | STATE_NORMAL => 0, # normal code |
| 386 | STATE_NAME => 1, # looking for function name |
| 387 | STATE_FIELD => 2, # scanning field start |
| 388 | STATE_PROTO => 3, # scanning prototype |
| 389 | STATE_DOCBLOCK => 4, # documentation block |
| 390 | STATE_INLINE => 5, # gathering documentation outside main block |
| 391 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | my $state; |
Randy Dunlap | 850622d | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 393 | my $in_doc_sect; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 395 | # Inline documentation state |
| 396 | use constant { |
| 397 | STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) |
| 398 | STATE_INLINE_NAME => 1, # looking for member name (@foo:) |
| 399 | STATE_INLINE_TEXT => 2, # looking for member documentation |
| 400 | STATE_INLINE_END => 3, # done |
| 401 | STATE_INLINE_ERROR => 4, # error - Comment without header was found. |
| 402 | # Spit a warning as it's not |
| 403 | # proper kernel-doc and ignore the rest. |
| 404 | }; |
| 405 | my $inline_doc_state; |
Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 406 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | #declaration types: can be |
| 408 | # 'function', 'struct', 'union', 'enum', 'typedef' |
| 409 | my $decl_type; |
| 410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. |
| 412 | my $doc_end = '\*/'; |
| 413 | my $doc_com = '\s*\*\s*'; |
Daniel Santos | 12ae677 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 414 | my $doc_com_body = '\s*\* ?'; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 415 | my $doc_decl = $doc_com . '(\w+)'; |
Jani Nikula | f624ade | 2016-05-29 11:35:28 +0300 | [diff] [blame] | 416 | # @params and a strictly limited set of supported section names |
Jonathan Corbet | 8569de6 | 2016-06-09 13:35:05 -0600 | [diff] [blame] | 417 | my $doc_sect = $doc_com . |
Jonathan Corbet | ef00028 | 2016-08-26 07:14:08 -0600 | [diff] [blame] | 418 | '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)'; |
Daniel Santos | 12ae677 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 419 | my $doc_content = $doc_com_body . '(.*)'; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 420 | my $doc_block = $doc_com . 'DOC:\s*(.*)?'; |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 421 | my $doc_inline_start = '^\s*/\*\*\s*$'; |
| 422 | my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)'; |
| 423 | my $doc_inline_end = '^\s*\*/\s*$'; |
Jani Nikula | 86ae2e3 | 2016-01-21 13:05:22 +0200 | [diff] [blame] | 424 | my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | my %parameterdescs; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 427 | my %parameterdesc_start_lines; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | my @parameterlist; |
| 429 | my %sections; |
| 430 | my @sectionlist; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 431 | my %section_start_lines; |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 432 | my $sectcheck; |
| 433 | my $struct_actual; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
| 435 | my $contents = ""; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 436 | my $new_start_line = 0; |
Jani Nikula | f624ade | 2016-05-29 11:35:28 +0300 | [diff] [blame] | 437 | |
| 438 | # the canonical section names. see also $doc_sect above. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | my $section_default = "Description"; # default section |
| 440 | my $section_intro = "Introduction"; |
| 441 | my $section = $section_default; |
| 442 | my $section_context = "Context"; |
Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 443 | my $section_return = "Return"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
| 445 | my $undescribed = "-- undescribed --"; |
| 446 | |
| 447 | reset_state(); |
| 448 | |
| 449 | while ($ARGV[0] =~ m/^-(.*)/) { |
| 450 | my $cmd = shift @ARGV; |
| 451 | if ($cmd eq "-html") { |
| 452 | $output_mode = "html"; |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 453 | @highlights = @highlights_html; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | $blankline = $blankline_html; |
Dan Luedtke | 1b40c19 | 2012-08-12 10:46:15 +0200 | [diff] [blame] | 455 | } elsif ($cmd eq "-html5") { |
| 456 | $output_mode = "html5"; |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 457 | @highlights = @highlights_html5; |
Dan Luedtke | 1b40c19 | 2012-08-12 10:46:15 +0200 | [diff] [blame] | 458 | $blankline = $blankline_html5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } elsif ($cmd eq "-man") { |
| 460 | $output_mode = "man"; |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 461 | @highlights = @highlights_man; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | $blankline = $blankline_man; |
| 463 | } elsif ($cmd eq "-text") { |
| 464 | $output_mode = "text"; |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 465 | @highlights = @highlights_text; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | $blankline = $blankline_text; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 467 | } elsif ($cmd eq "-rst") { |
| 468 | $output_mode = "rst"; |
| 469 | @highlights = @highlights_rst; |
| 470 | $blankline = $blankline_rst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | } elsif ($cmd eq "-docbook") { |
| 472 | $output_mode = "xml"; |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 473 | @highlights = @highlights_xml; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | $blankline = $blankline_xml; |
Johannes Berg | eda603f | 2010-09-11 15:55:22 -0700 | [diff] [blame] | 475 | } elsif ($cmd eq "-list") { |
| 476 | $output_mode = "list"; |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 477 | @highlights = @highlights_list; |
Johannes Berg | eda603f | 2010-09-11 15:55:22 -0700 | [diff] [blame] | 478 | $blankline = $blankline_list; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | } elsif ($cmd eq "-gnome") { |
| 480 | $output_mode = "gnome"; |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 481 | @highlights = @highlights_gnome; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | $blankline = $blankline_gnome; |
| 483 | } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document |
| 484 | $modulename = shift @ARGV; |
| 485 | } elsif ($cmd eq "-function") { # to only output specific functions |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 486 | $output_selection = OUTPUT_INCLUDE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | $function = shift @ARGV; |
| 488 | $function_table{$function} = 1; |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 489 | } elsif ($cmd eq "-nofunction") { # output all except specific functions |
| 490 | $output_selection = OUTPUT_EXCLUDE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | $function = shift @ARGV; |
| 492 | $function_table{$function} = 1; |
Jani Nikula | 86ae2e3 | 2016-01-21 13:05:22 +0200 | [diff] [blame] | 493 | } elsif ($cmd eq "-export") { # only exported symbols |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 494 | $output_selection = OUTPUT_EXPORTED; |
Jani Nikula | da9726e | 2016-06-07 10:29:59 +0300 | [diff] [blame] | 495 | %function_table = (); |
Jani Nikula | 86ae2e3 | 2016-01-21 13:05:22 +0200 | [diff] [blame] | 496 | } elsif ($cmd eq "-internal") { # only non-exported symbols |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 497 | $output_selection = OUTPUT_INTERNAL; |
Jani Nikula | da9726e | 2016-06-07 10:29:59 +0300 | [diff] [blame] | 498 | %function_table = (); |
Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 499 | } elsif ($cmd eq "-export-file") { |
| 500 | my $file = shift @ARGV; |
| 501 | push(@export_file_list, $file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | } elsif ($cmd eq "-v") { |
| 503 | $verbose = 1; |
| 504 | } elsif (($cmd eq "-h") || ($cmd eq "--help")) { |
| 505 | usage(); |
Johannes Berg | 4b44595 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 506 | } elsif ($cmd eq '-no-doc-sections') { |
| 507 | $no_doc_sections = 1; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 508 | } elsif ($cmd eq '-enable-lineno') { |
| 509 | $enable_lineno = 1; |
Johannes Berg | e946c43a | 2013-11-12 15:11:12 -0800 | [diff] [blame] | 510 | } elsif ($cmd eq '-show-not-found') { |
| 511 | $show_not_found = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 515 | # continue execution near EOF; |
| 516 | |
Borislav Petkov | 53f049f | 2007-05-08 00:30:54 -0700 | [diff] [blame] | 517 | # get kernel version from env |
| 518 | sub get_kernel_version() { |
Johannes Berg | 1b9bc22 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 519 | my $version = 'unknown kernel version'; |
Borislav Petkov | 53f049f | 2007-05-08 00:30:54 -0700 | [diff] [blame] | 520 | |
| 521 | if (defined($ENV{'KERNELVERSION'})) { |
| 522 | $version = $ENV{'KERNELVERSION'}; |
| 523 | } |
| 524 | return $version; |
| 525 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 527 | # |
| 528 | sub print_lineno { |
| 529 | my $lineno = shift; |
| 530 | if ($enable_lineno && defined($lineno)) { |
| 531 | print "#define LINENO " . $lineno . "\n"; |
| 532 | } |
| 533 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | ## |
| 535 | # dumps section contents to arrays/hashes intended for that purpose. |
| 536 | # |
| 537 | sub dump_section { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 538 | my $file = shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | my $name = shift; |
| 540 | my $contents = join "\n", @_; |
| 541 | |
Jani Nikula | 13901ef | 2016-05-26 08:57:29 +0300 | [diff] [blame] | 542 | if ($name =~ m/$type_param/) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | $name = $1; |
| 544 | $parameterdescs{$name} = $contents; |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 545 | $sectcheck = $sectcheck . $name . " "; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 546 | $parameterdesc_start_lines{$name} = $new_start_line; |
| 547 | $new_start_line = 0; |
Randy Dunlap | ced6909 | 2008-12-01 13:14:03 -0800 | [diff] [blame] | 548 | } elsif ($name eq "@\.\.\.") { |
Randy Dunlap | ced6909 | 2008-12-01 13:14:03 -0800 | [diff] [blame] | 549 | $name = "..."; |
| 550 | $parameterdescs{$name} = $contents; |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 551 | $sectcheck = $sectcheck . $name . " "; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 552 | $parameterdesc_start_lines{$name} = $new_start_line; |
| 553 | $new_start_line = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | } else { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 555 | if (defined($sections{$name}) && ($sections{$name} ne "")) { |
Jani Nikula | 95b6be9 | 2016-06-10 11:14:05 +0300 | [diff] [blame] | 556 | # Only warn on user specified duplicate section names. |
| 557 | if ($name ne $section_default) { |
| 558 | print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; |
| 559 | ++$warnings; |
| 560 | } |
Jani Nikula | 3221776 | 2016-05-29 09:40:44 +0300 | [diff] [blame] | 561 | $sections{$name} .= $contents; |
| 562 | } else { |
| 563 | $sections{$name} = $contents; |
| 564 | push @sectionlist, $name; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 565 | $section_start_lines{$name} = $new_start_line; |
| 566 | $new_start_line = 0; |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 567 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } |
| 569 | } |
| 570 | |
| 571 | ## |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 572 | # dump DOC: section after checking that it should go out |
| 573 | # |
| 574 | sub dump_doc_section { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 575 | my $file = shift; |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 576 | my $name = shift; |
| 577 | my $contents = join "\n", @_; |
| 578 | |
Johannes Berg | 4b44595 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 579 | if ($no_doc_sections) { |
| 580 | return; |
| 581 | } |
| 582 | |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 583 | if (($output_selection == OUTPUT_ALL) || |
| 584 | ($output_selection == OUTPUT_INCLUDE && |
| 585 | defined($function_table{$name})) || |
| 586 | ($output_selection == OUTPUT_EXCLUDE && |
| 587 | !defined($function_table{$name}))) |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 588 | { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 589 | dump_section($file, $name, $contents); |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 590 | output_blockhead({'sectionlist' => \@sectionlist, |
| 591 | 'sections' => \%sections, |
| 592 | 'module' => $modulename, |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 593 | 'content-only' => ($output_selection != OUTPUT_ALL), }); |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 594 | } |
| 595 | } |
| 596 | |
| 597 | ## |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | # output function |
| 599 | # |
| 600 | # parameterdescs, a hash. |
| 601 | # function => "function name" |
| 602 | # parameterlist => @list of parameters |
| 603 | # parameterdescs => %parameter descriptions |
| 604 | # sectionlist => @list of sections |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 605 | # sections => %section descriptions |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 606 | # |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
| 608 | sub output_highlight { |
| 609 | my $contents = join "\n",@_; |
| 610 | my $line; |
| 611 | |
| 612 | # DEBUG |
| 613 | # if (!defined $contents) { |
| 614 | # use Carp; |
| 615 | # confess "output_highlight got called with no args?\n"; |
| 616 | # } |
| 617 | |
Dan Luedtke | 1b40c19 | 2012-08-12 10:46:15 +0200 | [diff] [blame] | 618 | if ($output_mode eq "html" || $output_mode eq "html5" || |
| 619 | $output_mode eq "xml") { |
Randy Dunlap | 6b5b55f | 2007-10-16 23:31:20 -0700 | [diff] [blame] | 620 | $contents = local_unescape($contents); |
| 621 | # convert data read & converted thru xml_escape() into &xyz; format: |
Randy Dunlap | 2b35f4d | 2010-11-18 12:27:31 -0800 | [diff] [blame] | 622 | $contents =~ s/\\\\\\/\&/g; |
Randy Dunlap | 6b5b55f | 2007-10-16 23:31:20 -0700 | [diff] [blame] | 623 | } |
Randy Dunlap | 3eb014a | 2007-05-08 00:29:51 -0700 | [diff] [blame] | 624 | # print STDERR "contents b4:$contents\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | eval $dohighlight; |
| 626 | die $@ if $@; |
Randy Dunlap | 3eb014a | 2007-05-08 00:29:51 -0700 | [diff] [blame] | 627 | # print STDERR "contents af:$contents\n"; |
| 628 | |
Dan Luedtke | 1b40c19 | 2012-08-12 10:46:15 +0200 | [diff] [blame] | 629 | # strip whitespaces when generating html5 |
| 630 | if ($output_mode eq "html5") { |
| 631 | $contents =~ s/^\s+//; |
| 632 | $contents =~ s/\s+$//; |
| 633 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | foreach $line (split "\n", $contents) { |
Daniel Santos | 12ae677 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 635 | if (! $output_preformatted) { |
| 636 | $line =~ s/^\s*//; |
| 637 | } |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 638 | if ($line eq ""){ |
Daniel Santos | e314ba3 | 2012-10-04 17:15:08 -0700 | [diff] [blame] | 639 | if (! $output_preformatted) { |
| 640 | print $lineprefix, local_unescape($blankline); |
| 641 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | } else { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 643 | $line =~ s/\\\\\\/\&/g; |
Randy Dunlap | cdccb31 | 2007-07-19 01:48:25 -0700 | [diff] [blame] | 644 | if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { |
| 645 | print "\\&$line"; |
| 646 | } else { |
| 647 | print $lineprefix, $line; |
| 648 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | } |
| 650 | print "\n"; |
| 651 | } |
| 652 | } |
| 653 | |
Dan Luedtke | 1b40c19 | 2012-08-12 10:46:15 +0200 | [diff] [blame] | 654 | # output sections in html |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | sub output_section_html(%) { |
| 656 | my %args = %{$_[0]}; |
| 657 | my $section; |
| 658 | |
| 659 | foreach $section (@{$args{'sectionlist'}}) { |
| 660 | print "<h3>$section</h3>\n"; |
| 661 | print "<blockquote>\n"; |
| 662 | output_highlight($args{'sections'}{$section}); |
| 663 | print "</blockquote>\n"; |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 664 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | # output enum in html |
| 668 | sub output_enum_html(%) { |
| 669 | my %args = %{$_[0]}; |
| 670 | my ($parameter); |
| 671 | my $count; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 672 | print "<h2>enum " . $args{'enum'} . "</h2>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 674 | print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | $count = 0; |
| 676 | foreach $parameter (@{$args{'parameterlist'}}) { |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 677 | print " <b>" . $parameter . "</b>"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | if ($count != $#{$args{'parameterlist'}}) { |
| 679 | $count++; |
| 680 | print ",\n"; |
| 681 | } |
| 682 | print "<br>"; |
| 683 | } |
| 684 | print "};<br>\n"; |
| 685 | |
| 686 | print "<h3>Constants</h3>\n"; |
| 687 | print "<dl>\n"; |
| 688 | foreach $parameter (@{$args{'parameterlist'}}) { |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 689 | print "<dt><b>" . $parameter . "</b>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | print "<dd>"; |
| 691 | output_highlight($args{'parameterdescs'}{$parameter}); |
| 692 | } |
| 693 | print "</dl>\n"; |
| 694 | output_section_html(@_); |
| 695 | print "<hr>\n"; |
| 696 | } |
| 697 | |
Randy Dunlap | d28bee0 | 2006-02-01 03:06:57 -0800 | [diff] [blame] | 698 | # output typedef in html |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | sub output_typedef_html(%) { |
| 700 | my %args = %{$_[0]}; |
| 701 | my ($parameter); |
| 702 | my $count; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 703 | print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 705 | print "<b>typedef " . $args{'typedef'} . "</b>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | output_section_html(@_); |
| 707 | print "<hr>\n"; |
| 708 | } |
| 709 | |
| 710 | # output struct in html |
| 711 | sub output_struct_html(%) { |
| 712 | my %args = %{$_[0]}; |
| 713 | my ($parameter); |
| 714 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 715 | print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; |
| 716 | print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 718 | if ($parameter =~ /^#/) { |
| 719 | print "$parameter<br>\n"; |
| 720 | next; |
| 721 | } |
| 722 | my $parameter_name = $parameter; |
| 723 | $parameter_name =~ s/\[.*//; |
| 724 | |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 725 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | $type = $args{'parametertypes'}{$parameter}; |
| 727 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 728 | # pointer-to-function |
Randy Dunlap | 3eb014a | 2007-05-08 00:29:51 -0700 | [diff] [blame] | 729 | print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { |
Randy Dunlap | 3eb014a | 2007-05-08 00:29:51 -0700 | [diff] [blame] | 731 | # bitfield |
| 732 | print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | } else { |
Randy Dunlap | 3eb014a | 2007-05-08 00:29:51 -0700 | [diff] [blame] | 734 | print " <i>$type</i> <b>$parameter</b>;<br>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | } |
| 736 | } |
| 737 | print "};<br>\n"; |
| 738 | |
| 739 | print "<h3>Members</h3>\n"; |
| 740 | print "<dl>\n"; |
| 741 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 742 | ($parameter =~ /^#/) && next; |
| 743 | |
| 744 | my $parameter_name = $parameter; |
| 745 | $parameter_name =~ s/\[.*//; |
| 746 | |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 747 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 748 | print "<dt><b>" . $parameter . "</b>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | print "<dd>"; |
| 750 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 751 | } |
| 752 | print "</dl>\n"; |
| 753 | output_section_html(@_); |
| 754 | print "<hr>\n"; |
| 755 | } |
| 756 | |
| 757 | # output function in html |
| 758 | sub output_function_html(%) { |
| 759 | my %args = %{$_[0]}; |
| 760 | my ($parameter, $section); |
| 761 | my $count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 763 | print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; |
| 764 | print "<i>" . $args{'functiontype'} . "</i>\n"; |
| 765 | print "<b>" . $args{'function'} . "</b>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | print "("; |
| 767 | $count = 0; |
| 768 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 769 | $type = $args{'parametertypes'}{$parameter}; |
| 770 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 771 | # pointer-to-function |
| 772 | print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; |
| 773 | } else { |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 774 | print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | } |
| 776 | if ($count != $#{$args{'parameterlist'}}) { |
| 777 | $count++; |
| 778 | print ",\n"; |
| 779 | } |
| 780 | } |
| 781 | print ")\n"; |
| 782 | |
| 783 | print "<h3>Arguments</h3>\n"; |
| 784 | print "<dl>\n"; |
| 785 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 786 | my $parameter_name = $parameter; |
| 787 | $parameter_name =~ s/\[.*//; |
| 788 | |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 789 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 790 | print "<dt><b>" . $parameter . "</b>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | print "<dd>"; |
| 792 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 793 | } |
| 794 | print "</dl>\n"; |
| 795 | output_section_html(@_); |
| 796 | print "<hr>\n"; |
| 797 | } |
| 798 | |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 799 | # output DOC: block header in html |
| 800 | sub output_blockhead_html(%) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | my %args = %{$_[0]}; |
| 802 | my ($parameter, $section); |
| 803 | my $count; |
| 804 | |
| 805 | foreach $section (@{$args{'sectionlist'}}) { |
| 806 | print "<h3>$section</h3>\n"; |
| 807 | print "<ul>\n"; |
| 808 | output_highlight($args{'sections'}{$section}); |
| 809 | print "</ul>\n"; |
| 810 | } |
| 811 | print "<hr>\n"; |
| 812 | } |
| 813 | |
Dan Luedtke | 1b40c19 | 2012-08-12 10:46:15 +0200 | [diff] [blame] | 814 | # output sections in html5 |
| 815 | sub output_section_html5(%) { |
| 816 | my %args = %{$_[0]}; |
| 817 | my $section; |
| 818 | |
| 819 | foreach $section (@{$args{'sectionlist'}}) { |
| 820 | print "<section>\n"; |
| 821 | print "<h1>$section</h1>\n"; |
| 822 | print "<p>\n"; |
| 823 | output_highlight($args{'sections'}{$section}); |
| 824 | print "</p>\n"; |
| 825 | print "</section>\n"; |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | # output enum in html5 |
| 830 | sub output_enum_html5(%) { |
| 831 | my %args = %{$_[0]}; |
| 832 | my ($parameter); |
| 833 | my $count; |
| 834 | my $html5id; |
| 835 | |
| 836 | $html5id = $args{'enum'}; |
| 837 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; |
| 838 | print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; |
| 839 | print "<h1>enum " . $args{'enum'} . "</h1>\n"; |
| 840 | print "<ol class=\"code\">\n"; |
| 841 | print "<li>"; |
| 842 | print "<span class=\"keyword\">enum</span> "; |
| 843 | print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; |
| 844 | print "</li>\n"; |
| 845 | $count = 0; |
| 846 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 847 | print "<li class=\"indent\">"; |
| 848 | print "<span class=\"param\">" . $parameter . "</span>"; |
| 849 | if ($count != $#{$args{'parameterlist'}}) { |
| 850 | $count++; |
| 851 | print ","; |
| 852 | } |
| 853 | print "</li>\n"; |
| 854 | } |
| 855 | print "<li>};</li>\n"; |
| 856 | print "</ol>\n"; |
| 857 | |
| 858 | print "<section>\n"; |
| 859 | print "<h1>Constants</h1>\n"; |
| 860 | print "<dl>\n"; |
| 861 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 862 | print "<dt>" . $parameter . "</dt>\n"; |
| 863 | print "<dd>"; |
| 864 | output_highlight($args{'parameterdescs'}{$parameter}); |
| 865 | print "</dd>\n"; |
| 866 | } |
| 867 | print "</dl>\n"; |
| 868 | print "</section>\n"; |
| 869 | output_section_html5(@_); |
| 870 | print "</article>\n"; |
| 871 | } |
| 872 | |
| 873 | # output typedef in html5 |
| 874 | sub output_typedef_html5(%) { |
| 875 | my %args = %{$_[0]}; |
| 876 | my ($parameter); |
| 877 | my $count; |
| 878 | my $html5id; |
| 879 | |
| 880 | $html5id = $args{'typedef'}; |
| 881 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; |
| 882 | print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; |
| 883 | print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; |
| 884 | |
| 885 | print "<ol class=\"code\">\n"; |
| 886 | print "<li>"; |
| 887 | print "<span class=\"keyword\">typedef</span> "; |
| 888 | print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; |
| 889 | print "</li>\n"; |
| 890 | print "</ol>\n"; |
| 891 | output_section_html5(@_); |
| 892 | print "</article>\n"; |
| 893 | } |
| 894 | |
| 895 | # output struct in html5 |
| 896 | sub output_struct_html5(%) { |
| 897 | my %args = %{$_[0]}; |
| 898 | my ($parameter); |
| 899 | my $html5id; |
| 900 | |
| 901 | $html5id = $args{'struct'}; |
| 902 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; |
| 903 | print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n"; |
| 904 | print "<hgroup>\n"; |
| 905 | print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>"; |
| 906 | print "<h2>". $args{'purpose'} . "</h2>\n"; |
| 907 | print "</hgroup>\n"; |
| 908 | print "<ol class=\"code\">\n"; |
| 909 | print "<li>"; |
| 910 | print "<span class=\"type\">" . $args{'type'} . "</span> "; |
| 911 | print "<span class=\"identifier\">" . $args{'struct'} . "</span> {"; |
| 912 | print "</li>\n"; |
| 913 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 914 | print "<li class=\"indent\">"; |
| 915 | if ($parameter =~ /^#/) { |
| 916 | print "<span class=\"param\">" . $parameter ."</span>\n"; |
| 917 | print "</li>\n"; |
| 918 | next; |
| 919 | } |
| 920 | my $parameter_name = $parameter; |
| 921 | $parameter_name =~ s/\[.*//; |
| 922 | |
| 923 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
| 924 | $type = $args{'parametertypes'}{$parameter}; |
| 925 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 926 | # pointer-to-function |
| 927 | print "<span class=\"type\">$1</span> "; |
| 928 | print "<span class=\"param\">$parameter</span>"; |
| 929 | print "<span class=\"type\">)</span> "; |
| 930 | print "(<span class=\"args\">$2</span>);"; |
| 931 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { |
| 932 | # bitfield |
| 933 | print "<span class=\"type\">$1</span> "; |
| 934 | print "<span class=\"param\">$parameter</span>"; |
| 935 | print "<span class=\"bits\">$2</span>;"; |
| 936 | } else { |
| 937 | print "<span class=\"type\">$type</span> "; |
| 938 | print "<span class=\"param\">$parameter</span>;"; |
| 939 | } |
| 940 | print "</li>\n"; |
| 941 | } |
| 942 | print "<li>};</li>\n"; |
| 943 | print "</ol>\n"; |
| 944 | |
| 945 | print "<section>\n"; |
| 946 | print "<h1>Members</h1>\n"; |
| 947 | print "<dl>\n"; |
| 948 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 949 | ($parameter =~ /^#/) && next; |
| 950 | |
| 951 | my $parameter_name = $parameter; |
| 952 | $parameter_name =~ s/\[.*//; |
| 953 | |
| 954 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
| 955 | print "<dt>" . $parameter . "</dt>\n"; |
| 956 | print "<dd>"; |
| 957 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 958 | print "</dd>\n"; |
| 959 | } |
| 960 | print "</dl>\n"; |
| 961 | print "</section>\n"; |
| 962 | output_section_html5(@_); |
| 963 | print "</article>\n"; |
| 964 | } |
| 965 | |
| 966 | # output function in html5 |
| 967 | sub output_function_html5(%) { |
| 968 | my %args = %{$_[0]}; |
| 969 | my ($parameter, $section); |
| 970 | my $count; |
| 971 | my $html5id; |
| 972 | |
| 973 | $html5id = $args{'function'}; |
| 974 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; |
| 975 | print "<article class=\"function\" id=\"func:". $html5id . "\">\n"; |
| 976 | print "<hgroup>\n"; |
| 977 | print "<h1>" . $args{'function'} . "</h1>"; |
| 978 | print "<h2>" . $args{'purpose'} . "</h2>\n"; |
| 979 | print "</hgroup>\n"; |
| 980 | print "<ol class=\"code\">\n"; |
| 981 | print "<li>"; |
| 982 | print "<span class=\"type\">" . $args{'functiontype'} . "</span> "; |
| 983 | print "<span class=\"identifier\">" . $args{'function'} . "</span> ("; |
| 984 | print "</li>"; |
| 985 | $count = 0; |
| 986 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 987 | print "<li class=\"indent\">"; |
| 988 | $type = $args{'parametertypes'}{$parameter}; |
| 989 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 990 | # pointer-to-function |
| 991 | print "<span class=\"type\">$1</span> "; |
| 992 | print "<span class=\"param\">$parameter</span>"; |
| 993 | print "<span class=\"type\">)</span> "; |
| 994 | print "(<span class=\"args\">$2</span>)"; |
| 995 | } else { |
| 996 | print "<span class=\"type\">$type</span> "; |
| 997 | print "<span class=\"param\">$parameter</span>"; |
| 998 | } |
| 999 | if ($count != $#{$args{'parameterlist'}}) { |
| 1000 | $count++; |
| 1001 | print ","; |
| 1002 | } |
| 1003 | print "</li>\n"; |
| 1004 | } |
| 1005 | print "<li>)</li>\n"; |
| 1006 | print "</ol>\n"; |
| 1007 | |
| 1008 | print "<section>\n"; |
| 1009 | print "<h1>Arguments</h1>\n"; |
| 1010 | print "<p>\n"; |
| 1011 | print "<dl>\n"; |
| 1012 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1013 | my $parameter_name = $parameter; |
| 1014 | $parameter_name =~ s/\[.*//; |
| 1015 | |
| 1016 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
| 1017 | print "<dt>" . $parameter . "</dt>\n"; |
| 1018 | print "<dd>"; |
| 1019 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 1020 | print "</dd>\n"; |
| 1021 | } |
| 1022 | print "</dl>\n"; |
| 1023 | print "</section>\n"; |
| 1024 | output_section_html5(@_); |
| 1025 | print "</article>\n"; |
| 1026 | } |
| 1027 | |
| 1028 | # output DOC: block header in html5 |
| 1029 | sub output_blockhead_html5(%) { |
| 1030 | my %args = %{$_[0]}; |
| 1031 | my ($parameter, $section); |
| 1032 | my $count; |
| 1033 | my $html5id; |
| 1034 | |
| 1035 | foreach $section (@{$args{'sectionlist'}}) { |
| 1036 | $html5id = $section; |
| 1037 | $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; |
| 1038 | print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n"; |
| 1039 | print "<h1>$section</h1>\n"; |
| 1040 | print "<p>\n"; |
| 1041 | output_highlight($args{'sections'}{$section}); |
| 1042 | print "</p>\n"; |
| 1043 | } |
| 1044 | print "</article>\n"; |
| 1045 | } |
| 1046 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | sub output_section_xml(%) { |
| 1048 | my %args = %{$_[0]}; |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1049 | my $section; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | # print out each section |
| 1051 | $lineprefix=" "; |
| 1052 | foreach $section (@{$args{'sectionlist'}}) { |
Rich Walker | c73894c | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 1053 | print "<refsect1>\n"; |
| 1054 | print "<title>$section</title>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | if ($section =~ m/EXAMPLE/i) { |
Rich Walker | c73894c | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 1056 | print "<informalexample><programlisting>\n"; |
Daniel Santos | e314ba3 | 2012-10-04 17:15:08 -0700 | [diff] [blame] | 1057 | $output_preformatted = 1; |
Rich Walker | c73894c | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 1058 | } else { |
| 1059 | print "<para>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | } |
| 1061 | output_highlight($args{'sections'}{$section}); |
Daniel Santos | e314ba3 | 2012-10-04 17:15:08 -0700 | [diff] [blame] | 1062 | $output_preformatted = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | if ($section =~ m/EXAMPLE/i) { |
Rich Walker | c73894c | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 1064 | print "</programlisting></informalexample>\n"; |
| 1065 | } else { |
| 1066 | print "</para>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1067 | } |
Rich Walker | c73894c | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 1068 | print "</refsect1>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | # output function in XML DocBook |
| 1073 | sub output_function_xml(%) { |
| 1074 | my %args = %{$_[0]}; |
| 1075 | my ($parameter, $section); |
| 1076 | my $count; |
| 1077 | my $id; |
| 1078 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1079 | $id = "API-" . $args{'function'}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | $id =~ s/[^A-Za-z0-9]/-/g; |
| 1081 | |
Pavel Pisa | 5449bc9 | 2007-02-10 01:45:37 -0800 | [diff] [blame] | 1082 | print "<refentry id=\"$id\">\n"; |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 1083 | print "<refentryinfo>\n"; |
| 1084 | print " <title>LINUX</title>\n"; |
| 1085 | print " <productname>Kernel Hackers Manual</productname>\n"; |
| 1086 | print " <date>$man_date</date>\n"; |
| 1087 | print "</refentryinfo>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | print "<refmeta>\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1089 | print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 1090 | print " <manvolnum>9</manvolnum>\n"; |
Borislav Petkov | 0366299 | 2007-05-09 02:33:43 -0700 | [diff] [blame] | 1091 | print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | print "</refmeta>\n"; |
| 1093 | print "<refnamediv>\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1094 | print " <refname>" . $args{'function'} . "</refname>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | print " <refpurpose>\n"; |
| 1096 | print " "; |
| 1097 | output_highlight ($args{'purpose'}); |
| 1098 | print " </refpurpose>\n"; |
| 1099 | print "</refnamediv>\n"; |
| 1100 | |
| 1101 | print "<refsynopsisdiv>\n"; |
| 1102 | print " <title>Synopsis</title>\n"; |
| 1103 | print " <funcsynopsis><funcprototype>\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1104 | print " <funcdef>" . $args{'functiontype'} . " "; |
| 1105 | print "<function>" . $args{'function'} . " </function></funcdef>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | |
| 1107 | $count = 0; |
| 1108 | if ($#{$args{'parameterlist'}} >= 0) { |
| 1109 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1110 | $type = $args{'parametertypes'}{$parameter}; |
| 1111 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 1112 | # pointer-to-function |
| 1113 | print " <paramdef>$1<parameter>$parameter</parameter>)\n"; |
| 1114 | print " <funcparams>$2</funcparams></paramdef>\n"; |
| 1115 | } else { |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1116 | print " <paramdef>" . $type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | print " <parameter>$parameter</parameter></paramdef>\n"; |
| 1118 | } |
| 1119 | } |
| 1120 | } else { |
Martin Waitz | 6013d54 | 2005-05-01 08:59:25 -0700 | [diff] [blame] | 1121 | print " <void/>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | } |
| 1123 | print " </funcprototype></funcsynopsis>\n"; |
| 1124 | print "</refsynopsisdiv>\n"; |
| 1125 | |
| 1126 | # print parameters |
| 1127 | print "<refsect1>\n <title>Arguments</title>\n"; |
| 1128 | if ($#{$args{'parameterlist'}} >= 0) { |
| 1129 | print " <variablelist>\n"; |
| 1130 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1131 | my $parameter_name = $parameter; |
| 1132 | $parameter_name =~ s/\[.*//; |
| 1133 | |
| 1134 | print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; |
| 1135 | print " <listitem>\n <para>\n"; |
| 1136 | $lineprefix=" "; |
| 1137 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 1138 | print " </para>\n </listitem>\n </varlistentry>\n"; |
| 1139 | } |
| 1140 | print " </variablelist>\n"; |
| 1141 | } else { |
| 1142 | print " <para>\n None\n </para>\n"; |
| 1143 | } |
| 1144 | print "</refsect1>\n"; |
| 1145 | |
| 1146 | output_section_xml(@_); |
| 1147 | print "</refentry>\n\n"; |
| 1148 | } |
| 1149 | |
| 1150 | # output struct in XML DocBook |
| 1151 | sub output_struct_xml(%) { |
| 1152 | my %args = %{$_[0]}; |
| 1153 | my ($parameter, $section); |
| 1154 | my $id; |
| 1155 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1156 | $id = "API-struct-" . $args{'struct'}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | $id =~ s/[^A-Za-z0-9]/-/g; |
| 1158 | |
Pavel Pisa | 5449bc9 | 2007-02-10 01:45:37 -0800 | [diff] [blame] | 1159 | print "<refentry id=\"$id\">\n"; |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 1160 | print "<refentryinfo>\n"; |
| 1161 | print " <title>LINUX</title>\n"; |
| 1162 | print " <productname>Kernel Hackers Manual</productname>\n"; |
| 1163 | print " <date>$man_date</date>\n"; |
| 1164 | print "</refentryinfo>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | print "<refmeta>\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1166 | print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 1167 | print " <manvolnum>9</manvolnum>\n"; |
Borislav Petkov | 0366299 | 2007-05-09 02:33:43 -0700 | [diff] [blame] | 1168 | print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | print "</refmeta>\n"; |
| 1170 | print "<refnamediv>\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1171 | print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | print " <refpurpose>\n"; |
| 1173 | print " "; |
| 1174 | output_highlight ($args{'purpose'}); |
| 1175 | print " </refpurpose>\n"; |
| 1176 | print "</refnamediv>\n"; |
| 1177 | |
| 1178 | print "<refsynopsisdiv>\n"; |
| 1179 | print " <title>Synopsis</title>\n"; |
| 1180 | print " <programlisting>\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1181 | print $args{'type'} . " " . $args{'struct'} . " {\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1183 | if ($parameter =~ /^#/) { |
Randy Dunlap | 2b35f4d | 2010-11-18 12:27:31 -0800 | [diff] [blame] | 1184 | my $prm = $parameter; |
| 1185 | # convert data read & converted thru xml_escape() into &xyz; format: |
| 1186 | # This allows us to have #define macros interspersed in a struct. |
| 1187 | $prm =~ s/\\\\\\/\&/g; |
| 1188 | print "$prm\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | next; |
| 1190 | } |
| 1191 | |
| 1192 | my $parameter_name = $parameter; |
| 1193 | $parameter_name =~ s/\[.*//; |
| 1194 | |
| 1195 | defined($args{'parameterdescs'}{$parameter_name}) || next; |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1196 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | $type = $args{'parametertypes'}{$parameter}; |
| 1198 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 1199 | # pointer-to-function |
| 1200 | print " $1 $parameter) ($2);\n"; |
| 1201 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { |
Randy Dunlap | 51f5a0c | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1202 | # bitfield |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | print " $1 $parameter$2;\n"; |
| 1204 | } else { |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1205 | print " " . $type . " " . $parameter . ";\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | } |
| 1207 | } |
| 1208 | print "};"; |
| 1209 | print " </programlisting>\n"; |
| 1210 | print "</refsynopsisdiv>\n"; |
| 1211 | |
| 1212 | print " <refsect1>\n"; |
| 1213 | print " <title>Members</title>\n"; |
| 1214 | |
Randy Dunlap | 39f00c0 | 2008-09-22 13:57:44 -0700 | [diff] [blame] | 1215 | if ($#{$args{'parameterlist'}} >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | print " <variablelist>\n"; |
| 1217 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1218 | ($parameter =~ /^#/) && next; |
| 1219 | |
| 1220 | my $parameter_name = $parameter; |
| 1221 | $parameter_name =~ s/\[.*//; |
| 1222 | |
| 1223 | defined($args{'parameterdescs'}{$parameter_name}) || next; |
| 1224 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
| 1225 | print " <varlistentry>"; |
| 1226 | print " <term>$parameter</term>\n"; |
| 1227 | print " <listitem><para>\n"; |
| 1228 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 1229 | print " </para></listitem>\n"; |
| 1230 | print " </varlistentry>\n"; |
| 1231 | } |
| 1232 | print " </variablelist>\n"; |
Randy Dunlap | 39f00c0 | 2008-09-22 13:57:44 -0700 | [diff] [blame] | 1233 | } else { |
| 1234 | print " <para>\n None\n </para>\n"; |
| 1235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | print " </refsect1>\n"; |
| 1237 | |
| 1238 | output_section_xml(@_); |
| 1239 | |
| 1240 | print "</refentry>\n\n"; |
| 1241 | } |
| 1242 | |
| 1243 | # output enum in XML DocBook |
| 1244 | sub output_enum_xml(%) { |
| 1245 | my %args = %{$_[0]}; |
| 1246 | my ($parameter, $section); |
| 1247 | my $count; |
| 1248 | my $id; |
| 1249 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1250 | $id = "API-enum-" . $args{'enum'}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | $id =~ s/[^A-Za-z0-9]/-/g; |
| 1252 | |
Pavel Pisa | 5449bc9 | 2007-02-10 01:45:37 -0800 | [diff] [blame] | 1253 | print "<refentry id=\"$id\">\n"; |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 1254 | print "<refentryinfo>\n"; |
| 1255 | print " <title>LINUX</title>\n"; |
| 1256 | print " <productname>Kernel Hackers Manual</productname>\n"; |
| 1257 | print " <date>$man_date</date>\n"; |
| 1258 | print "</refentryinfo>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | print "<refmeta>\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1260 | print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 1261 | print " <manvolnum>9</manvolnum>\n"; |
Borislav Petkov | 0366299 | 2007-05-09 02:33:43 -0700 | [diff] [blame] | 1262 | print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | print "</refmeta>\n"; |
| 1264 | print "<refnamediv>\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1265 | print " <refname>enum " . $args{'enum'} . "</refname>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | print " <refpurpose>\n"; |
| 1267 | print " "; |
| 1268 | output_highlight ($args{'purpose'}); |
| 1269 | print " </refpurpose>\n"; |
| 1270 | print "</refnamediv>\n"; |
| 1271 | |
| 1272 | print "<refsynopsisdiv>\n"; |
| 1273 | print " <title>Synopsis</title>\n"; |
| 1274 | print " <programlisting>\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1275 | print "enum " . $args{'enum'} . " {\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | $count = 0; |
| 1277 | foreach $parameter (@{$args{'parameterlist'}}) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1278 | print " $parameter"; |
| 1279 | if ($count != $#{$args{'parameterlist'}}) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | $count++; |
| 1281 | print ","; |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1282 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | print "\n"; |
| 1284 | } |
| 1285 | print "};"; |
| 1286 | print " </programlisting>\n"; |
| 1287 | print "</refsynopsisdiv>\n"; |
| 1288 | |
| 1289 | print "<refsect1>\n"; |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1290 | print " <title>Constants</title>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | print " <variablelist>\n"; |
| 1292 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1293 | my $parameter_name = $parameter; |
| 1294 | $parameter_name =~ s/\[.*//; |
| 1295 | |
| 1296 | print " <varlistentry>"; |
| 1297 | print " <term>$parameter</term>\n"; |
| 1298 | print " <listitem><para>\n"; |
| 1299 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 1300 | print " </para></listitem>\n"; |
| 1301 | print " </varlistentry>\n"; |
| 1302 | } |
| 1303 | print " </variablelist>\n"; |
| 1304 | print "</refsect1>\n"; |
| 1305 | |
| 1306 | output_section_xml(@_); |
| 1307 | |
| 1308 | print "</refentry>\n\n"; |
| 1309 | } |
| 1310 | |
| 1311 | # output typedef in XML DocBook |
| 1312 | sub output_typedef_xml(%) { |
| 1313 | my %args = %{$_[0]}; |
| 1314 | my ($parameter, $section); |
| 1315 | my $id; |
| 1316 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1317 | $id = "API-typedef-" . $args{'typedef'}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | $id =~ s/[^A-Za-z0-9]/-/g; |
| 1319 | |
Pavel Pisa | 5449bc9 | 2007-02-10 01:45:37 -0800 | [diff] [blame] | 1320 | print "<refentry id=\"$id\">\n"; |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 1321 | print "<refentryinfo>\n"; |
| 1322 | print " <title>LINUX</title>\n"; |
| 1323 | print " <productname>Kernel Hackers Manual</productname>\n"; |
| 1324 | print " <date>$man_date</date>\n"; |
| 1325 | print "</refentryinfo>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1326 | print "<refmeta>\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1327 | print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 1328 | print " <manvolnum>9</manvolnum>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | print "</refmeta>\n"; |
| 1330 | print "<refnamediv>\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1331 | print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1332 | print " <refpurpose>\n"; |
| 1333 | print " "; |
| 1334 | output_highlight ($args{'purpose'}); |
| 1335 | print " </refpurpose>\n"; |
| 1336 | print "</refnamediv>\n"; |
| 1337 | |
| 1338 | print "<refsynopsisdiv>\n"; |
| 1339 | print " <title>Synopsis</title>\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1340 | print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | print "</refsynopsisdiv>\n"; |
| 1342 | |
| 1343 | output_section_xml(@_); |
| 1344 | |
| 1345 | print "</refentry>\n\n"; |
| 1346 | } |
| 1347 | |
| 1348 | # output in XML DocBook |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 1349 | sub output_blockhead_xml(%) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | my %args = %{$_[0]}; |
| 1351 | my ($parameter, $section); |
| 1352 | my $count; |
| 1353 | |
| 1354 | my $id = $args{'module'}; |
| 1355 | $id =~ s/[^A-Za-z0-9]/-/g; |
| 1356 | |
| 1357 | # print out each section |
| 1358 | $lineprefix=" "; |
| 1359 | foreach $section (@{$args{'sectionlist'}}) { |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 1360 | if (!$args{'content-only'}) { |
| 1361 | print "<refsect1>\n <title>$section</title>\n"; |
| 1362 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | if ($section =~ m/EXAMPLE/i) { |
| 1364 | print "<example><para>\n"; |
Daniel Santos | e314ba3 | 2012-10-04 17:15:08 -0700 | [diff] [blame] | 1365 | $output_preformatted = 1; |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 1366 | } else { |
| 1367 | print "<para>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | } |
| 1369 | output_highlight($args{'sections'}{$section}); |
Daniel Santos | e314ba3 | 2012-10-04 17:15:08 -0700 | [diff] [blame] | 1370 | $output_preformatted = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1371 | if ($section =~ m/EXAMPLE/i) { |
| 1372 | print "</para></example>\n"; |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 1373 | } else { |
| 1374 | print "</para>"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | } |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 1376 | if (!$args{'content-only'}) { |
| 1377 | print "\n</refsect1>\n"; |
| 1378 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | print "\n\n"; |
| 1382 | } |
| 1383 | |
| 1384 | # output in XML DocBook |
| 1385 | sub output_function_gnome { |
| 1386 | my %args = %{$_[0]}; |
| 1387 | my ($parameter, $section); |
| 1388 | my $count; |
| 1389 | my $id; |
| 1390 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1391 | $id = $args{'module'} . "-" . $args{'function'}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | $id =~ s/[^A-Za-z0-9]/-/g; |
| 1393 | |
| 1394 | print "<sect2>\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1395 | print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | |
| 1397 | print " <funcsynopsis>\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1398 | print " <funcdef>" . $args{'functiontype'} . " "; |
| 1399 | print "<function>" . $args{'function'} . " "; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | print "</function></funcdef>\n"; |
| 1401 | |
| 1402 | $count = 0; |
| 1403 | if ($#{$args{'parameterlist'}} >= 0) { |
| 1404 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1405 | $type = $args{'parametertypes'}{$parameter}; |
| 1406 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 1407 | # pointer-to-function |
| 1408 | print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; |
| 1409 | print " <funcparams>$2</funcparams></paramdef>\n"; |
| 1410 | } else { |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1411 | print " <paramdef>" . $type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | print " <parameter>$parameter</parameter></paramdef>\n"; |
| 1413 | } |
| 1414 | } |
| 1415 | } else { |
| 1416 | print " <void>\n"; |
| 1417 | } |
| 1418 | print " </funcsynopsis>\n"; |
| 1419 | if ($#{$args{'parameterlist'}} >= 0) { |
| 1420 | print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; |
| 1421 | print "<tgroup cols=\"2\">\n"; |
| 1422 | print "<colspec colwidth=\"2*\">\n"; |
| 1423 | print "<colspec colwidth=\"8*\">\n"; |
| 1424 | print "<tbody>\n"; |
| 1425 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1426 | my $parameter_name = $parameter; |
| 1427 | $parameter_name =~ s/\[.*//; |
| 1428 | |
| 1429 | print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; |
| 1430 | print " <entry>\n"; |
| 1431 | $lineprefix=" "; |
| 1432 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 1433 | print " </entry></row>\n"; |
| 1434 | } |
| 1435 | print " </tbody></tgroup></informaltable>\n"; |
| 1436 | } else { |
| 1437 | print " <para>\n None\n </para>\n"; |
| 1438 | } |
| 1439 | |
| 1440 | # print out each section |
| 1441 | $lineprefix=" "; |
| 1442 | foreach $section (@{$args{'sectionlist'}}) { |
| 1443 | print "<simplesect>\n <title>$section</title>\n"; |
| 1444 | if ($section =~ m/EXAMPLE/i) { |
| 1445 | print "<example><programlisting>\n"; |
Daniel Santos | e314ba3 | 2012-10-04 17:15:08 -0700 | [diff] [blame] | 1446 | $output_preformatted = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | } else { |
| 1448 | } |
| 1449 | print "<para>\n"; |
| 1450 | output_highlight($args{'sections'}{$section}); |
Daniel Santos | e314ba3 | 2012-10-04 17:15:08 -0700 | [diff] [blame] | 1451 | $output_preformatted = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | print "</para>\n"; |
| 1453 | if ($section =~ m/EXAMPLE/i) { |
| 1454 | print "</programlisting></example>\n"; |
| 1455 | } else { |
| 1456 | } |
| 1457 | print " </simplesect>\n"; |
| 1458 | } |
| 1459 | |
| 1460 | print "</sect2>\n\n"; |
| 1461 | } |
| 1462 | |
| 1463 | ## |
| 1464 | # output function in man |
| 1465 | sub output_function_man(%) { |
| 1466 | my %args = %{$_[0]}; |
| 1467 | my ($parameter, $section); |
| 1468 | my $count; |
| 1469 | |
| 1470 | print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; |
| 1471 | |
| 1472 | print ".SH NAME\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1473 | print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | |
| 1475 | print ".SH SYNOPSIS\n"; |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1476 | if ($args{'functiontype'} ne "") { |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1477 | print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1478 | } else { |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1479 | print ".B \"" . $args{'function'} . "\n"; |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1480 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | $count = 0; |
| 1482 | my $parenth = "("; |
| 1483 | my $post = ","; |
| 1484 | foreach my $parameter (@{$args{'parameterlist'}}) { |
| 1485 | if ($count == $#{$args{'parameterlist'}}) { |
| 1486 | $post = ");"; |
| 1487 | } |
| 1488 | $type = $args{'parametertypes'}{$parameter}; |
| 1489 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 1490 | # pointer-to-function |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1491 | print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | } else { |
| 1493 | $type =~ s/([^\*])$/$1 /; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1494 | print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | } |
| 1496 | $count++; |
| 1497 | $parenth = ""; |
| 1498 | } |
| 1499 | |
| 1500 | print ".SH ARGUMENTS\n"; |
| 1501 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1502 | my $parameter_name = $parameter; |
| 1503 | $parameter_name =~ s/\[.*//; |
| 1504 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1505 | print ".IP \"" . $parameter . "\" 12\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1506 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 1507 | } |
| 1508 | foreach $section (@{$args{'sectionlist'}}) { |
| 1509 | print ".SH \"", uc $section, "\"\n"; |
| 1510 | output_highlight($args{'sections'}{$section}); |
| 1511 | } |
| 1512 | } |
| 1513 | |
| 1514 | ## |
| 1515 | # output enum in man |
| 1516 | sub output_enum_man(%) { |
| 1517 | my %args = %{$_[0]}; |
| 1518 | my ($parameter, $section); |
| 1519 | my $count; |
| 1520 | |
| 1521 | print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; |
| 1522 | |
| 1523 | print ".SH NAME\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1524 | print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | |
| 1526 | print ".SH SYNOPSIS\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1527 | print "enum " . $args{'enum'} . " {\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | $count = 0; |
| 1529 | foreach my $parameter (@{$args{'parameterlist'}}) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1530 | print ".br\n.BI \" $parameter\"\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | if ($count == $#{$args{'parameterlist'}}) { |
| 1532 | print "\n};\n"; |
| 1533 | last; |
| 1534 | } |
| 1535 | else { |
| 1536 | print ", \n.br\n"; |
| 1537 | } |
| 1538 | $count++; |
| 1539 | } |
| 1540 | |
| 1541 | print ".SH Constants\n"; |
| 1542 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1543 | my $parameter_name = $parameter; |
| 1544 | $parameter_name =~ s/\[.*//; |
| 1545 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1546 | print ".IP \"" . $parameter . "\" 12\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 1548 | } |
| 1549 | foreach $section (@{$args{'sectionlist'}}) { |
| 1550 | print ".SH \"$section\"\n"; |
| 1551 | output_highlight($args{'sections'}{$section}); |
| 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | ## |
| 1556 | # output struct in man |
| 1557 | sub output_struct_man(%) { |
| 1558 | my %args = %{$_[0]}; |
| 1559 | my ($parameter, $section); |
| 1560 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1561 | 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] | 1562 | |
| 1563 | print ".SH NAME\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1564 | print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | |
| 1566 | print ".SH SYNOPSIS\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1567 | print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | |
| 1569 | foreach my $parameter (@{$args{'parameterlist'}}) { |
| 1570 | if ($parameter =~ /^#/) { |
| 1571 | print ".BI \"$parameter\"\n.br\n"; |
| 1572 | next; |
| 1573 | } |
| 1574 | my $parameter_name = $parameter; |
| 1575 | $parameter_name =~ s/\[.*//; |
| 1576 | |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1577 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | $type = $args{'parametertypes'}{$parameter}; |
| 1579 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 1580 | # pointer-to-function |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1581 | print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { |
Randy.Dunlap | 1d7e1d4 | 2006-07-01 04:36:34 -0700 | [diff] [blame] | 1583 | # bitfield |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1584 | print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | } else { |
| 1586 | $type =~ s/([^\*])$/$1 /; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1587 | print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | } |
| 1589 | print "\n.br\n"; |
| 1590 | } |
| 1591 | print "};\n.br\n"; |
| 1592 | |
Randy Dunlap | c51d3dac | 2006-06-25 05:49:14 -0700 | [diff] [blame] | 1593 | print ".SH Members\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1595 | ($parameter =~ /^#/) && next; |
| 1596 | |
| 1597 | my $parameter_name = $parameter; |
| 1598 | $parameter_name =~ s/\[.*//; |
| 1599 | |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1600 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1601 | print ".IP \"" . $parameter . "\" 12\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 1603 | } |
| 1604 | foreach $section (@{$args{'sectionlist'}}) { |
| 1605 | print ".SH \"$section\"\n"; |
| 1606 | output_highlight($args{'sections'}{$section}); |
| 1607 | } |
| 1608 | } |
| 1609 | |
| 1610 | ## |
| 1611 | # output typedef in man |
| 1612 | sub output_typedef_man(%) { |
| 1613 | my %args = %{$_[0]}; |
| 1614 | my ($parameter, $section); |
| 1615 | |
| 1616 | print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; |
| 1617 | |
| 1618 | print ".SH NAME\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1619 | print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | |
| 1621 | foreach $section (@{$args{'sectionlist'}}) { |
| 1622 | print ".SH \"$section\"\n"; |
| 1623 | output_highlight($args{'sections'}{$section}); |
| 1624 | } |
| 1625 | } |
| 1626 | |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 1627 | sub output_blockhead_man(%) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | my %args = %{$_[0]}; |
| 1629 | my ($parameter, $section); |
| 1630 | my $count; |
| 1631 | |
| 1632 | print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; |
| 1633 | |
| 1634 | foreach $section (@{$args{'sectionlist'}}) { |
| 1635 | print ".SH \"$section\"\n"; |
| 1636 | output_highlight($args{'sections'}{$section}); |
| 1637 | } |
| 1638 | } |
| 1639 | |
| 1640 | ## |
| 1641 | # output in text |
| 1642 | sub output_function_text(%) { |
| 1643 | my %args = %{$_[0]}; |
| 1644 | my ($parameter, $section); |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1645 | my $start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | |
Randy Dunlap | f47634b | 2006-07-01 04:36:36 -0700 | [diff] [blame] | 1647 | print "Name:\n\n"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1648 | print $args{'function'} . " - " . $args{'purpose'} . "\n"; |
Randy Dunlap | f47634b | 2006-07-01 04:36:36 -0700 | [diff] [blame] | 1649 | |
| 1650 | print "\nSynopsis:\n\n"; |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1651 | if ($args{'functiontype'} ne "") { |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1652 | $start = $args{'functiontype'} . " " . $args{'function'} . " ("; |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1653 | } else { |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1654 | $start = $args{'function'} . " ("; |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1655 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | print $start; |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1657 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | my $count = 0; |
| 1659 | foreach my $parameter (@{$args{'parameterlist'}}) { |
| 1660 | $type = $args{'parametertypes'}{$parameter}; |
| 1661 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 1662 | # pointer-to-function |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1663 | print $1 . $parameter . ") (" . $2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | } else { |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1665 | print $type . " " . $parameter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | } |
| 1667 | if ($count != $#{$args{'parameterlist'}}) { |
| 1668 | $count++; |
| 1669 | print ",\n"; |
| 1670 | print " " x length($start); |
| 1671 | } else { |
| 1672 | print ");\n\n"; |
| 1673 | } |
| 1674 | } |
| 1675 | |
| 1676 | print "Arguments:\n\n"; |
| 1677 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1678 | my $parameter_name = $parameter; |
| 1679 | $parameter_name =~ s/\[.*//; |
| 1680 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1681 | print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | } |
| 1683 | output_section_text(@_); |
| 1684 | } |
| 1685 | |
| 1686 | #output sections in text |
| 1687 | sub output_section_text(%) { |
| 1688 | my %args = %{$_[0]}; |
| 1689 | my $section; |
| 1690 | |
| 1691 | print "\n"; |
| 1692 | foreach $section (@{$args{'sectionlist'}}) { |
| 1693 | print "$section:\n\n"; |
| 1694 | output_highlight($args{'sections'}{$section}); |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1695 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | print "\n\n"; |
| 1697 | } |
| 1698 | |
| 1699 | # output enum in text |
| 1700 | sub output_enum_text(%) { |
| 1701 | my %args = %{$_[0]}; |
| 1702 | my ($parameter); |
| 1703 | my $count; |
| 1704 | print "Enum:\n\n"; |
| 1705 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1706 | print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; |
| 1707 | print "enum " . $args{'enum'} . " {\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | $count = 0; |
| 1709 | foreach $parameter (@{$args{'parameterlist'}}) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1710 | print "\t$parameter"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | if ($count != $#{$args{'parameterlist'}}) { |
| 1712 | $count++; |
| 1713 | print ","; |
| 1714 | } |
| 1715 | print "\n"; |
| 1716 | } |
| 1717 | print "};\n\n"; |
| 1718 | |
| 1719 | print "Constants:\n\n"; |
| 1720 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1721 | print "$parameter\n\t"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1722 | print $args{'parameterdescs'}{$parameter} . "\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | output_section_text(@_); |
| 1726 | } |
| 1727 | |
| 1728 | # output typedef in text |
| 1729 | sub output_typedef_text(%) { |
| 1730 | my %args = %{$_[0]}; |
| 1731 | my ($parameter); |
| 1732 | my $count; |
| 1733 | print "Typedef:\n\n"; |
| 1734 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1735 | print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | output_section_text(@_); |
| 1737 | } |
| 1738 | |
| 1739 | # output struct as text |
| 1740 | sub output_struct_text(%) { |
| 1741 | my %args = %{$_[0]}; |
| 1742 | my ($parameter); |
| 1743 | |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1744 | print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; |
| 1745 | print $args{'type'} . " " . $args{'struct'} . " {\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1747 | if ($parameter =~ /^#/) { |
| 1748 | print "$parameter\n"; |
| 1749 | next; |
| 1750 | } |
| 1751 | |
| 1752 | my $parameter_name = $parameter; |
| 1753 | $parameter_name =~ s/\[.*//; |
| 1754 | |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1755 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | $type = $args{'parametertypes'}{$parameter}; |
| 1757 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 1758 | # pointer-to-function |
| 1759 | print "\t$1 $parameter) ($2);\n"; |
| 1760 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { |
Randy Dunlap | 51f5a0c | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1761 | # bitfield |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | print "\t$1 $parameter$2;\n"; |
| 1763 | } else { |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1764 | print "\t" . $type . " " . $parameter . ";\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | } |
| 1766 | } |
| 1767 | print "};\n\n"; |
| 1768 | |
| 1769 | print "Members:\n\n"; |
| 1770 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1771 | ($parameter =~ /^#/) && next; |
| 1772 | |
| 1773 | my $parameter_name = $parameter; |
| 1774 | $parameter_name =~ s/\[.*//; |
| 1775 | |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1776 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1777 | print "$parameter\n\t"; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 1778 | print $args{'parameterdescs'}{$parameter_name} . "\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | } |
| 1780 | print "\n"; |
| 1781 | output_section_text(@_); |
| 1782 | } |
| 1783 | |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 1784 | sub output_blockhead_text(%) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | my %args = %{$_[0]}; |
| 1786 | my ($parameter, $section); |
| 1787 | |
| 1788 | foreach $section (@{$args{'sectionlist'}}) { |
| 1789 | print " $section:\n"; |
| 1790 | print " -> "; |
| 1791 | output_highlight($args{'sections'}{$section}); |
| 1792 | } |
| 1793 | } |
| 1794 | |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1795 | ## |
| 1796 | # output in restructured text |
| 1797 | # |
| 1798 | |
| 1799 | # |
| 1800 | # This could use some work; it's used to output the DOC: sections, and |
| 1801 | # starts by putting out the name of the doc section itself, but that tends |
| 1802 | # to duplicate a header already in the template file. |
| 1803 | # |
| 1804 | sub output_blockhead_rst(%) { |
| 1805 | my %args = %{$_[0]}; |
| 1806 | my ($parameter, $section); |
| 1807 | |
| 1808 | foreach $section (@{$args{'sectionlist'}}) { |
Jani Nikula | 9e72184 | 2016-05-29 22:27:35 +0300 | [diff] [blame] | 1809 | if ($output_selection != OUTPUT_INCLUDE) { |
| 1810 | print "**$section**\n\n"; |
| 1811 | } |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 1812 | print_lineno($section_start_lines{$section}); |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1813 | output_highlight_rst($args{'sections'}{$section}); |
| 1814 | print "\n"; |
| 1815 | } |
| 1816 | } |
| 1817 | |
| 1818 | sub output_highlight_rst { |
| 1819 | my $contents = join "\n",@_; |
| 1820 | my $line; |
| 1821 | |
| 1822 | # undo the evil effects of xml_escape() earlier |
| 1823 | $contents = xml_unescape($contents); |
| 1824 | |
| 1825 | eval $dohighlight; |
| 1826 | die $@ if $@; |
| 1827 | |
| 1828 | foreach $line (split "\n", $contents) { |
Jani Nikula | 830066a | 2016-05-26 22:04:33 +0300 | [diff] [blame] | 1829 | print $lineprefix . $line . "\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1830 | } |
| 1831 | } |
| 1832 | |
| 1833 | sub output_function_rst(%) { |
| 1834 | my %args = %{$_[0]}; |
| 1835 | my ($parameter, $section); |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 1836 | my $oldprefix = $lineprefix; |
Mauro Carvalho Chehab | 82801d0 | 2016-08-30 20:20:58 -0300 | [diff] [blame] | 1837 | my $start = ""; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1838 | |
Mauro Carvalho Chehab | 82801d0 | 2016-08-30 20:20:58 -0300 | [diff] [blame] | 1839 | if ($args{'typedef'}) { |
| 1840 | print ".. c:type:: ". $args{'function'} . "\n\n"; |
| 1841 | print_lineno($declaration_start_line); |
| 1842 | print " **Typedef**: "; |
| 1843 | $lineprefix = ""; |
| 1844 | output_highlight_rst($args{'purpose'}); |
| 1845 | $start = "\n\n**Syntax**\n\n ``"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1846 | } else { |
Mauro Carvalho Chehab | 82801d0 | 2016-08-30 20:20:58 -0300 | [diff] [blame] | 1847 | print ".. c:function:: "; |
| 1848 | } |
| 1849 | if ($args{'functiontype'} ne "") { |
| 1850 | $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; |
| 1851 | } else { |
| 1852 | $start .= $args{'function'} . " ("; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1853 | } |
| 1854 | print $start; |
| 1855 | |
| 1856 | my $count = 0; |
| 1857 | foreach my $parameter (@{$args{'parameterlist'}}) { |
| 1858 | if ($count ne 0) { |
| 1859 | print ", "; |
| 1860 | } |
| 1861 | $count++; |
| 1862 | $type = $args{'parametertypes'}{$parameter}; |
Mauro Carvalho Chehab | a88b167 | 2016-07-22 11:46:36 -0300 | [diff] [blame] | 1863 | |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1864 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 1865 | # pointer-to-function |
| 1866 | print $1 . $parameter . ") (" . $2; |
| 1867 | } else { |
| 1868 | print $type . " " . $parameter; |
| 1869 | } |
| 1870 | } |
Mauro Carvalho Chehab | 82801d0 | 2016-08-30 20:20:58 -0300 | [diff] [blame] | 1871 | if ($args{'typedef'}) { |
| 1872 | print ");``\n\n"; |
| 1873 | } else { |
| 1874 | print ")\n\n"; |
| 1875 | print_lineno($declaration_start_line); |
| 1876 | $lineprefix = " "; |
| 1877 | output_highlight_rst($args{'purpose'}); |
| 1878 | print "\n"; |
| 1879 | } |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1880 | |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 1881 | print "**Parameters**\n\n"; |
| 1882 | $lineprefix = " "; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1883 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1884 | my $parameter_name = $parameter; |
| 1885 | #$parameter_name =~ s/\[.*//; |
| 1886 | $type = $args{'parametertypes'}{$parameter}; |
| 1887 | |
| 1888 | if ($type ne "") { |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 1889 | print "``$type $parameter``\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1890 | } else { |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 1891 | print "``$parameter``\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1892 | } |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 1893 | |
| 1894 | print_lineno($parameterdesc_start_lines{$parameter_name}); |
| 1895 | |
Jani Nikula | 5e64fa9 | 2016-05-19 20:32:48 +0300 | [diff] [blame] | 1896 | if (defined($args{'parameterdescs'}{$parameter_name}) && |
| 1897 | $args{'parameterdescs'}{$parameter_name} ne $undescribed) { |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1898 | output_highlight_rst($args{'parameterdescs'}{$parameter_name}); |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1899 | } else { |
Jani Nikula | d4b08e0 | 2016-05-28 00:48:17 +0300 | [diff] [blame] | 1900 | print " *undescribed*\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1901 | } |
| 1902 | print "\n"; |
| 1903 | } |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 1904 | |
| 1905 | $lineprefix = $oldprefix; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1906 | output_section_rst(@_); |
| 1907 | } |
| 1908 | |
| 1909 | sub output_section_rst(%) { |
| 1910 | my %args = %{$_[0]}; |
| 1911 | my $section; |
| 1912 | my $oldprefix = $lineprefix; |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 1913 | $lineprefix = ""; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1914 | |
| 1915 | foreach $section (@{$args{'sectionlist'}}) { |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 1916 | print "**$section**\n\n"; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 1917 | print_lineno($section_start_lines{$section}); |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1918 | output_highlight_rst($args{'sections'}{$section}); |
| 1919 | print "\n"; |
| 1920 | } |
| 1921 | print "\n"; |
| 1922 | $lineprefix = $oldprefix; |
| 1923 | } |
| 1924 | |
| 1925 | sub output_enum_rst(%) { |
| 1926 | my %args = %{$_[0]}; |
| 1927 | my ($parameter); |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 1928 | my $oldprefix = $lineprefix; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1929 | my $count; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1930 | my $name = "enum " . $args{'enum'}; |
Jani Nikula | 6285097 | 2016-05-12 16:15:38 +0300 | [diff] [blame] | 1931 | |
| 1932 | print "\n\n.. c:type:: " . $name . "\n\n"; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 1933 | print_lineno($declaration_start_line); |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 1934 | $lineprefix = " "; |
| 1935 | output_highlight_rst($args{'purpose'}); |
| 1936 | print "\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1937 | |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 1938 | print "**Constants**\n\n"; |
| 1939 | $lineprefix = " "; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1940 | foreach $parameter (@{$args{'parameterlist'}}) { |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 1941 | print "``$parameter``\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1942 | if ($args{'parameterdescs'}{$parameter} ne $undescribed) { |
| 1943 | output_highlight_rst($args{'parameterdescs'}{$parameter}); |
| 1944 | } else { |
Jani Nikula | d4b08e0 | 2016-05-28 00:48:17 +0300 | [diff] [blame] | 1945 | print " *undescribed*\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1946 | } |
| 1947 | print "\n"; |
| 1948 | } |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 1949 | |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1950 | $lineprefix = $oldprefix; |
| 1951 | output_section_rst(@_); |
| 1952 | } |
| 1953 | |
| 1954 | sub output_typedef_rst(%) { |
| 1955 | my %args = %{$_[0]}; |
| 1956 | my ($parameter); |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 1957 | my $oldprefix = $lineprefix; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1958 | my $name = "typedef " . $args{'typedef'}; |
| 1959 | |
Jani Nikula | 6285097 | 2016-05-12 16:15:38 +0300 | [diff] [blame] | 1960 | print "\n\n.. c:type:: " . $name . "\n\n"; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 1961 | print_lineno($declaration_start_line); |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 1962 | $lineprefix = " "; |
| 1963 | output_highlight_rst($args{'purpose'}); |
| 1964 | print "\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1965 | |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 1966 | $lineprefix = $oldprefix; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1967 | output_section_rst(@_); |
| 1968 | } |
| 1969 | |
| 1970 | sub output_struct_rst(%) { |
| 1971 | my %args = %{$_[0]}; |
| 1972 | my ($parameter); |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 1973 | my $oldprefix = $lineprefix; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1974 | my $name = $args{'type'} . " " . $args{'struct'}; |
| 1975 | |
Jani Nikula | 6285097 | 2016-05-12 16:15:38 +0300 | [diff] [blame] | 1976 | print "\n\n.. c:type:: " . $name . "\n\n"; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 1977 | print_lineno($declaration_start_line); |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 1978 | $lineprefix = " "; |
| 1979 | output_highlight_rst($args{'purpose'}); |
| 1980 | print "\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1981 | |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 1982 | print "**Definition**\n\n"; |
| 1983 | print "::\n\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1984 | print " " . $args{'type'} . " " . $args{'struct'} . " {\n"; |
| 1985 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1986 | if ($parameter =~ /^#/) { |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 1987 | print " " . "$parameter\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 1988 | next; |
| 1989 | } |
| 1990 | |
| 1991 | my $parameter_name = $parameter; |
| 1992 | $parameter_name =~ s/\[.*//; |
| 1993 | |
| 1994 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
| 1995 | $type = $args{'parametertypes'}{$parameter}; |
| 1996 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 1997 | # pointer-to-function |
| 1998 | print " $1 $parameter) ($2);\n"; |
| 1999 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { |
| 2000 | # bitfield |
| 2001 | print " $1 $parameter$2;\n"; |
| 2002 | } else { |
| 2003 | print " " . $type . " " . $parameter . ";\n"; |
| 2004 | } |
| 2005 | } |
| 2006 | print " };\n\n"; |
| 2007 | |
Jani Nikula | ecbcfba | 2016-05-26 18:30:27 +0300 | [diff] [blame] | 2008 | print "**Members**\n\n"; |
| 2009 | $lineprefix = " "; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 2010 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 2011 | ($parameter =~ /^#/) && next; |
| 2012 | |
| 2013 | my $parameter_name = $parameter; |
| 2014 | $parameter_name =~ s/\[.*//; |
| 2015 | |
| 2016 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
| 2017 | $type = $args{'parametertypes'}{$parameter}; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 2018 | print_lineno($parameterdesc_start_lines{$parameter_name}); |
Mauro Carvalho Chehab | 6d232c8 | 2016-08-22 22:02:57 -0300 | [diff] [blame] | 2019 | print "``" . $parameter . "``\n"; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 2020 | output_highlight_rst($args{'parameterdescs'}{$parameter_name}); |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 2021 | print "\n"; |
| 2022 | } |
| 2023 | print "\n"; |
Jani Nikula | c099ff6 | 2016-05-26 17:18:17 +0300 | [diff] [blame] | 2024 | |
| 2025 | $lineprefix = $oldprefix; |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 2026 | output_section_rst(@_); |
| 2027 | } |
| 2028 | |
| 2029 | |
Johannes Berg | eda603f | 2010-09-11 15:55:22 -0700 | [diff] [blame] | 2030 | ## list mode output functions |
| 2031 | |
| 2032 | sub output_function_list(%) { |
| 2033 | my %args = %{$_[0]}; |
| 2034 | |
| 2035 | print $args{'function'} . "\n"; |
| 2036 | } |
| 2037 | |
| 2038 | # output enum in list |
| 2039 | sub output_enum_list(%) { |
| 2040 | my %args = %{$_[0]}; |
| 2041 | print $args{'enum'} . "\n"; |
| 2042 | } |
| 2043 | |
| 2044 | # output typedef in list |
| 2045 | sub output_typedef_list(%) { |
| 2046 | my %args = %{$_[0]}; |
| 2047 | print $args{'typedef'} . "\n"; |
| 2048 | } |
| 2049 | |
| 2050 | # output struct as list |
| 2051 | sub output_struct_list(%) { |
| 2052 | my %args = %{$_[0]}; |
| 2053 | |
| 2054 | print $args{'struct'} . "\n"; |
| 2055 | } |
| 2056 | |
| 2057 | sub output_blockhead_list(%) { |
| 2058 | my %args = %{$_[0]}; |
| 2059 | my ($parameter, $section); |
| 2060 | |
| 2061 | foreach $section (@{$args{'sectionlist'}}) { |
| 2062 | print "DOC: $section\n"; |
| 2063 | } |
| 2064 | } |
| 2065 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2066 | ## |
Randy Dunlap | 2720574 | 2006-10-11 01:22:12 -0700 | [diff] [blame] | 2067 | # generic output function for all types (function, struct/union, typedef, enum); |
| 2068 | # calls the generated, variable output_ function name based on |
| 2069 | # functype and output_mode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2070 | sub output_declaration { |
| 2071 | no strict 'refs'; |
| 2072 | my $name = shift; |
| 2073 | my $functype = shift; |
| 2074 | my $func = "output_${functype}_$output_mode"; |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 2075 | if (($output_selection == OUTPUT_ALL) || |
| 2076 | (($output_selection == OUTPUT_INCLUDE || |
| 2077 | $output_selection == OUTPUT_EXPORTED) && |
| 2078 | defined($function_table{$name})) || |
| 2079 | (($output_selection == OUTPUT_EXCLUDE || |
| 2080 | $output_selection == OUTPUT_INTERNAL) && |
| 2081 | !($functype eq "function" && defined($function_table{$name})))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2083 | &$func(@_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2084 | $section_counter++; |
| 2085 | } |
| 2086 | } |
| 2087 | |
| 2088 | ## |
Randy Dunlap | 2720574 | 2006-10-11 01:22:12 -0700 | [diff] [blame] | 2089 | # generic output function - calls the right one based on current output mode. |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 2090 | sub output_blockhead { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2091 | no strict 'refs'; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 2092 | my $func = "output_blockhead_" . $output_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | &$func(@_); |
| 2094 | $section_counter++; |
| 2095 | } |
| 2096 | |
| 2097 | ## |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 2098 | # takes a declaration (struct, union, enum, typedef) and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | # invokes the right handler. NOT called for functions. |
| 2100 | sub dump_declaration($$) { |
| 2101 | no strict 'refs'; |
| 2102 | my ($prototype, $file) = @_; |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 2103 | my $func = "dump_" . $decl_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | &$func(@_); |
| 2105 | } |
| 2106 | |
| 2107 | sub dump_union($$) { |
| 2108 | dump_struct(@_); |
| 2109 | } |
| 2110 | |
| 2111 | sub dump_struct($$) { |
| 2112 | my $x = shift; |
| 2113 | my $file = shift; |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 2114 | my $nested; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | |
Randy Dunlap | 52dc5ae | 2009-04-30 15:08:53 -0700 | [diff] [blame] | 2116 | if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { |
| 2117 | #my $decl_type = $1; |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2118 | $declaration_name = $2; |
| 2119 | my $members = $3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | |
| 2121 | # ignore embedded structs or unions |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 2122 | $members =~ s/({.*})//g; |
| 2123 | $nested = $1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | |
Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 2125 | # ignore members marked private: |
Mauro Carvalho Chehab | 0d8c39e | 2015-10-05 09:03:48 -0300 | [diff] [blame] | 2126 | $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; |
| 2127 | $members =~ s/\/\*\s*private:.*//gosi; |
Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 2128 | # strip comments: |
| 2129 | $members =~ s/\/\*.*?\*\///gos; |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 2130 | $nested =~ s/\/\*.*?\*\///gos; |
Randy Dunlap | d960eea | 2009-06-29 14:54:11 -0700 | [diff] [blame] | 2131 | # strip kmemcheck_bitfield_{begin,end}.*; |
| 2132 | $members =~ s/kmemcheck_bitfield_.*?;//gos; |
Randy Dunlap | ef5da59 | 2010-03-23 13:35:14 -0700 | [diff] [blame] | 2133 | # strip attributes |
Jonathan Corbet | f007492 | 2015-08-23 13:35:23 -0600 | [diff] [blame] | 2134 | $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; |
Johannes Berg | 7b99078 | 2014-12-10 15:41:28 -0800 | [diff] [blame] | 2135 | $members =~ s/__aligned\s*\([^;]*\)//gos; |
Jonathan Corbet | f007492 | 2015-08-23 13:35:23 -0600 | [diff] [blame] | 2136 | $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; |
Conchúr Navid | b22b5a9 | 2015-11-08 10:52:00 +0100 | [diff] [blame] | 2137 | # replace DECLARE_BITMAP |
| 2138 | $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; |
Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 2139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2140 | create_parameterlist($members, ';', $file); |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 2141 | check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | |
| 2143 | output_declaration($declaration_name, |
| 2144 | 'struct', |
| 2145 | {'struct' => $declaration_name, |
| 2146 | 'module' => $modulename, |
| 2147 | 'parameterlist' => \@parameterlist, |
| 2148 | 'parameterdescs' => \%parameterdescs, |
| 2149 | 'parametertypes' => \%parametertypes, |
| 2150 | 'sectionlist' => \@sectionlist, |
| 2151 | 'sections' => \%sections, |
| 2152 | 'purpose' => $declaration_purpose, |
| 2153 | 'type' => $decl_type |
| 2154 | }); |
| 2155 | } |
| 2156 | else { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2157 | print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | ++$errors; |
| 2159 | } |
| 2160 | } |
| 2161 | |
| 2162 | sub dump_enum($$) { |
| 2163 | my $x = shift; |
| 2164 | my $file = shift; |
| 2165 | |
Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 2166 | $x =~ s@/\*.*?\*/@@gos; # strip comments. |
Conchúr Navid | 4468e21 | 2015-11-08 10:48:05 +0100 | [diff] [blame] | 2167 | # strip #define macros inside enums |
| 2168 | $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; |
Randy Dunlap | b6d676d | 2010-08-10 18:02:50 -0700 | [diff] [blame] | 2169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2170 | if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2171 | $declaration_name = $1; |
| 2172 | my $members = $2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | |
| 2174 | foreach my $arg (split ',', $members) { |
| 2175 | $arg =~ s/^\s*(\w+).*/$1/; |
| 2176 | push @parameterlist, $arg; |
| 2177 | if (!$parameterdescs{$arg}) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2178 | $parameterdescs{$arg} = $undescribed; |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2179 | print STDERR "${file}:$.: warning: Enum value '$arg' ". |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | "not described in enum '$declaration_name'\n"; |
| 2181 | } |
| 2182 | |
| 2183 | } |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 2184 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | output_declaration($declaration_name, |
| 2186 | 'enum', |
| 2187 | {'enum' => $declaration_name, |
| 2188 | 'module' => $modulename, |
| 2189 | 'parameterlist' => \@parameterlist, |
| 2190 | 'parameterdescs' => \%parameterdescs, |
| 2191 | 'sectionlist' => \@sectionlist, |
| 2192 | 'sections' => \%sections, |
| 2193 | 'purpose' => $declaration_purpose |
| 2194 | }); |
| 2195 | } |
| 2196 | else { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2197 | print STDERR "${file}:$.: error: Cannot parse enum!\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2198 | ++$errors; |
| 2199 | } |
| 2200 | } |
| 2201 | |
| 2202 | sub dump_typedef($$) { |
| 2203 | my $x = shift; |
| 2204 | my $file = shift; |
| 2205 | |
Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 2206 | $x =~ s@/\*.*?\*/@@gos; # strip comments. |
Mauro Carvalho Chehab | 8376645 | 2015-10-08 16:14:45 -0300 | [diff] [blame] | 2207 | |
| 2208 | # Parse function prototypes |
Mauro Carvalho Chehab | d37c43c | 2016-08-30 20:20:57 -0300 | [diff] [blame] | 2209 | if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ || |
| 2210 | $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) { |
| 2211 | |
Mauro Carvalho Chehab | 8376645 | 2015-10-08 16:14:45 -0300 | [diff] [blame] | 2212 | # Function typedefs |
| 2213 | $return_type = $1; |
| 2214 | $declaration_name = $2; |
| 2215 | my $args = $3; |
| 2216 | |
| 2217 | create_parameterlist($args, ',', $file); |
| 2218 | |
| 2219 | output_declaration($declaration_name, |
| 2220 | 'function', |
| 2221 | {'function' => $declaration_name, |
Mauro Carvalho Chehab | 82801d0 | 2016-08-30 20:20:58 -0300 | [diff] [blame] | 2222 | 'typedef' => 1, |
Mauro Carvalho Chehab | 8376645 | 2015-10-08 16:14:45 -0300 | [diff] [blame] | 2223 | 'module' => $modulename, |
| 2224 | 'functiontype' => $return_type, |
| 2225 | 'parameterlist' => \@parameterlist, |
| 2226 | 'parameterdescs' => \%parameterdescs, |
| 2227 | 'parametertypes' => \%parametertypes, |
| 2228 | 'sectionlist' => \@sectionlist, |
| 2229 | 'sections' => \%sections, |
| 2230 | 'purpose' => $declaration_purpose |
| 2231 | }); |
| 2232 | return; |
| 2233 | } |
| 2234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2236 | $x =~ s/\(*.\)\s*;$/;/; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2237 | $x =~ s/\[*.\]\s*;$/;/; |
| 2238 | } |
| 2239 | |
| 2240 | if ($x =~ /typedef.*\s+(\w+)\s*;/) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2241 | $declaration_name = $1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | |
| 2243 | output_declaration($declaration_name, |
| 2244 | 'typedef', |
| 2245 | {'typedef' => $declaration_name, |
| 2246 | 'module' => $modulename, |
| 2247 | 'sectionlist' => \@sectionlist, |
| 2248 | 'sections' => \%sections, |
| 2249 | 'purpose' => $declaration_purpose |
| 2250 | }); |
| 2251 | } |
| 2252 | else { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2253 | print STDERR "${file}:$.: error: Cannot parse typedef!\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2254 | ++$errors; |
| 2255 | } |
| 2256 | } |
| 2257 | |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 2258 | sub save_struct_actual($) { |
| 2259 | my $actual = shift; |
| 2260 | |
| 2261 | # strip all spaces from the actual param so that it looks like one string item |
| 2262 | $actual =~ s/\s*//g; |
| 2263 | $struct_actual = $struct_actual . $actual . " "; |
| 2264 | } |
| 2265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2266 | sub create_parameterlist($$$) { |
| 2267 | my $args = shift; |
| 2268 | my $splitter = shift; |
| 2269 | my $file = shift; |
| 2270 | my $type; |
| 2271 | my $param; |
| 2272 | |
Martin Waitz | a6d3fe7 | 2006-01-09 20:53:55 -0800 | [diff] [blame] | 2273 | # temporarily replace commas inside function pointer definition |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2274 | while ($args =~ /(\([^\),]+),/) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2275 | $args =~ s/(\([^\),]+),/$1#/g; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | } |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 2277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2278 | foreach my $arg (split($splitter, $args)) { |
| 2279 | # strip comments |
| 2280 | $arg =~ s/\/\*.*\*\///; |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2281 | # strip leading/trailing spaces |
| 2282 | $arg =~ s/^\s*//; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | $arg =~ s/\s*$//; |
| 2284 | $arg =~ s/\s+/ /; |
| 2285 | |
| 2286 | if ($arg =~ /^#/) { |
| 2287 | # Treat preprocessor directive as a typeless variable just to fill |
| 2288 | # corresponding data structures "correctly". Catch it later in |
| 2289 | # output_* subs. |
| 2290 | push_parameter($arg, "", $file); |
Richard Kennedy | 00d6296 | 2008-02-23 15:24:01 -0800 | [diff] [blame] | 2291 | } elsif ($arg =~ m/\(.+\)\s*\(/) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | # pointer-to-function |
| 2293 | $arg =~ tr/#/,/; |
Richard Kennedy | 00d6296 | 2008-02-23 15:24:01 -0800 | [diff] [blame] | 2294 | $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | $param = $1; |
| 2296 | $type = $arg; |
Richard Kennedy | 00d6296 | 2008-02-23 15:24:01 -0800 | [diff] [blame] | 2297 | $type =~ s/([^\(]+\(\*?)\s*$param/$1/; |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 2298 | save_struct_actual($param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2299 | push_parameter($param, $type, $file); |
Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 2300 | } elsif ($arg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | $arg =~ s/\s*:\s*/:/g; |
| 2302 | $arg =~ s/\s*\[/\[/g; |
| 2303 | |
| 2304 | my @args = split('\s*,\s*', $arg); |
| 2305 | if ($args[0] =~ m/\*/) { |
| 2306 | $args[0] =~ s/(\*+)\s*/ $1/; |
| 2307 | } |
Borislav Petkov | 884f281 | 2007-05-08 00:29:05 -0700 | [diff] [blame] | 2308 | |
| 2309 | my @first_arg; |
| 2310 | if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { |
| 2311 | shift @args; |
| 2312 | push(@first_arg, split('\s+', $1)); |
| 2313 | push(@first_arg, $2); |
| 2314 | } else { |
| 2315 | @first_arg = split('\s+', shift @args); |
| 2316 | } |
| 2317 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | unshift(@args, pop @first_arg); |
| 2319 | $type = join " ", @first_arg; |
| 2320 | |
| 2321 | foreach $param (@args) { |
| 2322 | if ($param =~ m/^(\*+)\s*(.*)/) { |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 2323 | save_struct_actual($2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | push_parameter($2, "$type $1", $file); |
| 2325 | } |
| 2326 | elsif ($param =~ m/(.*?):(\d+)/) { |
Randy Dunlap | 7b97887 | 2008-05-16 15:45:52 -0700 | [diff] [blame] | 2327 | if ($type ne "") { # skip unnamed bit-fields |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 2328 | save_struct_actual($1); |
Randy Dunlap | 7b97887 | 2008-05-16 15:45:52 -0700 | [diff] [blame] | 2329 | push_parameter($1, "$type:$2", $file) |
| 2330 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | } |
| 2332 | else { |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 2333 | save_struct_actual($param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2334 | push_parameter($param, $type, $file); |
| 2335 | } |
| 2336 | } |
| 2337 | } |
| 2338 | } |
| 2339 | } |
| 2340 | |
| 2341 | sub push_parameter($$$) { |
| 2342 | my $param = shift; |
| 2343 | my $type = shift; |
| 2344 | my $file = shift; |
| 2345 | |
Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 2346 | if (($anon_struct_union == 1) && ($type eq "") && |
| 2347 | ($param eq "}")) { |
| 2348 | return; # ignore the ending }; from anon. struct/union |
| 2349 | } |
| 2350 | |
| 2351 | $anon_struct_union = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2352 | my $param_name = $param; |
| 2353 | $param_name =~ s/\[.*//; |
| 2354 | |
Martin Waitz | a6d3fe7 | 2006-01-09 20:53:55 -0800 | [diff] [blame] | 2355 | if ($type eq "" && $param =~ /\.\.\.$/) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | { |
Silvio Fricke | c950a17 | 2016-10-28 10:14:08 +0200 | [diff] [blame^] | 2357 | if (!$param =~ /\w\.\.\.$/) { |
| 2358 | # handles unnamed variable parameters |
| 2359 | $param = "..."; |
| 2360 | } |
Randy Dunlap | ced6909 | 2008-12-01 13:14:03 -0800 | [diff] [blame] | 2361 | if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { |
| 2362 | $parameterdescs{$param} = "variable arguments"; |
| 2363 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | } |
| 2365 | elsif ($type eq "" && ($param eq "" or $param eq "void")) |
| 2366 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | $param="void"; |
| 2368 | $parameterdescs{void} = "no arguments"; |
| 2369 | } |
Randy Dunlap | 134fe01 | 2006-12-22 01:10:50 -0800 | [diff] [blame] | 2370 | elsif ($type eq "" && ($param eq "struct" or $param eq "union")) |
| 2371 | # handle unnamed (anonymous) union or struct: |
| 2372 | { |
| 2373 | $type = $param; |
Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 2374 | $param = "{unnamed_" . $param . "}"; |
Randy Dunlap | 134fe01 | 2006-12-22 01:10:50 -0800 | [diff] [blame] | 2375 | $parameterdescs{$param} = "anonymous\n"; |
Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 2376 | $anon_struct_union = 1; |
Randy Dunlap | 134fe01 | 2006-12-22 01:10:50 -0800 | [diff] [blame] | 2377 | } |
| 2378 | |
Martin Waitz | a6d3fe7 | 2006-01-09 20:53:55 -0800 | [diff] [blame] | 2379 | # warn if parameter has no description |
Randy Dunlap | 134fe01 | 2006-12-22 01:10:50 -0800 | [diff] [blame] | 2380 | # (but ignore ones starting with # as these are not parameters |
| 2381 | # but inline preprocessor statements); |
| 2382 | # also ignore unnamed structs/unions; |
Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 2383 | if (!$anon_struct_union) { |
Martin Waitz | a6d3fe7 | 2006-01-09 20:53:55 -0800 | [diff] [blame] | 2384 | if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { |
| 2385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | $parameterdescs{$param_name} = $undescribed; |
| 2387 | |
| 2388 | if (($type eq 'function') || ($type eq 'enum')) { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2389 | print STDERR "${file}:$.: warning: Function parameter ". |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | "or member '$param' not " . |
| 2391 | "described in '$declaration_name'\n"; |
| 2392 | } |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2393 | print STDERR "${file}:$.: warning:" . |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2394 | " No description found for parameter '$param'\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2395 | ++$warnings; |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2396 | } |
| 2397 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2398 | |
Randy Dunlap | 2b35f4d | 2010-11-18 12:27:31 -0800 | [diff] [blame] | 2399 | $param = xml_escape($param); |
| 2400 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2401 | # strip spaces from $param so that it is one continuous string |
Randy Dunlap | e34e7db | 2009-06-17 17:37:47 -0700 | [diff] [blame] | 2402 | # on @parameterlist; |
| 2403 | # this fixes a problem where check_sections() cannot find |
| 2404 | # a parameter like "addr[6 + 2]" because it actually appears |
| 2405 | # as "addr[6", "+", "2]" on the parameter list; |
| 2406 | # but it's better to maintain the param string unchanged for output, |
| 2407 | # so just weaken the string compare in check_sections() to ignore |
| 2408 | # "[blah" in a parameter string; |
| 2409 | ###$param =~ s/\s*//g; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | push @parameterlist, $param; |
| 2411 | $parametertypes{$param} = $type; |
| 2412 | } |
| 2413 | |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 2414 | sub check_sections($$$$$$) { |
| 2415 | my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; |
| 2416 | my @sects = split ' ', $sectcheck; |
| 2417 | my @prms = split ' ', $prmscheck; |
| 2418 | my $err; |
| 2419 | my ($px, $sx); |
| 2420 | my $prm_clean; # strip trailing "[array size]" and/or beginning "*" |
| 2421 | |
| 2422 | foreach $sx (0 .. $#sects) { |
| 2423 | $err = 1; |
| 2424 | foreach $px (0 .. $#prms) { |
| 2425 | $prm_clean = $prms[$px]; |
| 2426 | $prm_clean =~ s/\[.*\]//; |
Johannes Berg | 1f3a668 | 2010-09-11 15:55:12 -0700 | [diff] [blame] | 2427 | $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; |
Randy Dunlap | e34e7db | 2009-06-17 17:37:47 -0700 | [diff] [blame] | 2428 | # ignore array size in a parameter string; |
| 2429 | # however, the original param string may contain |
| 2430 | # spaces, e.g.: addr[6 + 2] |
| 2431 | # and this appears in @prms as "addr[6" since the |
| 2432 | # parameter list is split at spaces; |
| 2433 | # hence just ignore "[..." for the sections check; |
| 2434 | $prm_clean =~ s/\[.*//; |
| 2435 | |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 2436 | ##$prm_clean =~ s/^\**//; |
| 2437 | if ($prm_clean eq $sects[$sx]) { |
| 2438 | $err = 0; |
| 2439 | last; |
| 2440 | } |
| 2441 | } |
| 2442 | if ($err) { |
| 2443 | if ($decl_type eq "function") { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2444 | print STDERR "${file}:$.: warning: " . |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 2445 | "Excess function parameter " . |
| 2446 | "'$sects[$sx]' " . |
| 2447 | "description in '$decl_name'\n"; |
| 2448 | ++$warnings; |
| 2449 | } else { |
| 2450 | if ($nested !~ m/\Q$sects[$sx]\E/) { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2451 | print STDERR "${file}:$.: warning: " . |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 2452 | "Excess struct/union/enum/typedef member " . |
| 2453 | "'$sects[$sx]' " . |
| 2454 | "description in '$decl_name'\n"; |
| 2455 | ++$warnings; |
| 2456 | } |
| 2457 | } |
| 2458 | } |
| 2459 | } |
| 2460 | } |
| 2461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | ## |
Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 2463 | # Checks the section describing the return value of a function. |
| 2464 | sub check_return_section { |
| 2465 | my $file = shift; |
| 2466 | my $declaration_name = shift; |
| 2467 | my $return_type = shift; |
| 2468 | |
| 2469 | # Ignore an empty return type (It's a macro) |
| 2470 | # Ignore functions with a "void" return type. (But don't ignore "void *") |
| 2471 | if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { |
| 2472 | return; |
| 2473 | } |
| 2474 | |
| 2475 | if (!defined($sections{$section_return}) || |
| 2476 | $sections{$section_return} eq "") { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2477 | print STDERR "${file}:$.: warning: " . |
Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 2478 | "No description found for return value of " . |
| 2479 | "'$declaration_name'\n"; |
| 2480 | ++$warnings; |
| 2481 | } |
| 2482 | } |
| 2483 | |
| 2484 | ## |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | # takes a function prototype and the name of the current file being |
| 2486 | # processed and spits out all the details stored in the global |
| 2487 | # arrays/hashes. |
| 2488 | sub dump_function($$) { |
| 2489 | my $prototype = shift; |
| 2490 | my $file = shift; |
Horia Geanta | cbb4d3e | 2014-07-12 09:55:03 -0700 | [diff] [blame] | 2491 | my $noret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | |
| 2493 | $prototype =~ s/^static +//; |
| 2494 | $prototype =~ s/^extern +//; |
Pavel Pisa | 4dc3b16 | 2005-05-01 08:59:25 -0700 | [diff] [blame] | 2495 | $prototype =~ s/^asmlinkage +//; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | $prototype =~ s/^inline +//; |
| 2497 | $prototype =~ s/^__inline__ +//; |
Randy Dunlap | 32e7940 | 2006-10-11 01:22:10 -0700 | [diff] [blame] | 2498 | $prototype =~ s/^__inline +//; |
| 2499 | $prototype =~ s/^__always_inline +//; |
| 2500 | $prototype =~ s/^noinline +//; |
Randy Dunlap | 74fc5c6 | 2008-06-19 16:03:29 -0700 | [diff] [blame] | 2501 | $prototype =~ s/__init +//; |
Randy Dunlap | 2007220 | 2010-03-23 13:35:24 -0700 | [diff] [blame] | 2502 | $prototype =~ s/__init_or_module +//; |
Randy Dunlap | 270a009 | 2014-08-24 18:17:17 -0700 | [diff] [blame] | 2503 | $prototype =~ s/__meminit +//; |
Randy Dunlap | 70c95b0 | 2012-01-21 10:31:54 -0800 | [diff] [blame] | 2504 | $prototype =~ s/__must_check +//; |
Randy Dunlap | 0df7c0e | 2012-08-16 16:23:20 -0700 | [diff] [blame] | 2505 | $prototype =~ s/__weak +//; |
Horia Geanta | cbb4d3e | 2014-07-12 09:55:03 -0700 | [diff] [blame] | 2506 | my $define = $prototype =~ s/^#\s*define\s+//; #ak added |
Randy Dunlap | 328d244 | 2007-02-28 20:12:10 -0800 | [diff] [blame] | 2507 | $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2508 | |
| 2509 | # Yes, this truly is vile. We are looking for: |
| 2510 | # 1. Return type (may be nothing if we're looking at a macro) |
| 2511 | # 2. Function name |
| 2512 | # 3. Function parameters. |
| 2513 | # |
| 2514 | # All the while we have to watch out for function pointer parameters |
| 2515 | # (which IIRC is what the two sections are for), C types (these |
| 2516 | # regexps don't even start to express all the possibilities), and |
| 2517 | # so on. |
| 2518 | # |
| 2519 | # If you mess with these regexps, it's a good idea to check that |
| 2520 | # the following functions' documentation still comes out right: |
| 2521 | # - parport_register_device (function pointer parameters) |
| 2522 | # - atomic_set (macro) |
Martin Waitz | 9598f91 | 2006-02-01 03:06:55 -0800 | [diff] [blame] | 2523 | # - pci_match_device, __copy_to_user (long return type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | |
Horia Geanta | cbb4d3e | 2014-07-12 09:55:03 -0700 | [diff] [blame] | 2525 | if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { |
| 2526 | # This is an object-like macro, it has no return type and no parameter |
| 2527 | # list. |
| 2528 | # Function-like macros are not allowed to have spaces between |
| 2529 | # declaration_name and opening parenthesis (notice the \s+). |
| 2530 | $return_type = $1; |
| 2531 | $declaration_name = $2; |
| 2532 | $noret = 1; |
| 2533 | } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
| 2535 | $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
| 2536 | $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
Randy Dunlap | 94b3e03 | 2008-02-07 00:13:26 -0800 | [diff] [blame] | 2537 | $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
| 2539 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
| 2540 | $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
| 2541 | $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
| 2542 | $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
| 2543 | $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
| 2544 | $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
| 2545 | $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
Martin Waitz | 9598f91 | 2006-02-01 03:06:55 -0800 | [diff] [blame] | 2546 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
| 2547 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
Randy Dunlap | 412ecd77 | 2007-02-10 22:47:33 -0800 | [diff] [blame] | 2548 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
| 2549 | $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] | 2550 | $return_type = $1; |
| 2551 | $declaration_name = $2; |
| 2552 | my $args = $3; |
| 2553 | |
| 2554 | create_parameterlist($args, ',', $file); |
| 2555 | } else { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2556 | print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | return; |
| 2558 | } |
| 2559 | |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 2560 | my $prms = join " ", @parameterlist; |
| 2561 | check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); |
| 2562 | |
Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 2563 | # This check emits a lot of warnings at the moment, because many |
| 2564 | # functions don't have a 'Return' doc section. So until the number |
| 2565 | # of warnings goes sufficiently down, the check is only performed in |
| 2566 | # verbose mode. |
| 2567 | # TODO: always perform the check. |
Horia Geanta | cbb4d3e | 2014-07-12 09:55:03 -0700 | [diff] [blame] | 2568 | if ($verbose && !$noret) { |
Yacine Belkadi | 4092bac | 2012-11-26 22:22:27 +0100 | [diff] [blame] | 2569 | check_return_section($file, $declaration_name, $return_type); |
| 2570 | } |
| 2571 | |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 2572 | output_declaration($declaration_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2573 | 'function', |
| 2574 | {'function' => $declaration_name, |
| 2575 | 'module' => $modulename, |
| 2576 | 'functiontype' => $return_type, |
| 2577 | 'parameterlist' => \@parameterlist, |
| 2578 | 'parameterdescs' => \%parameterdescs, |
| 2579 | 'parametertypes' => \%parametertypes, |
| 2580 | 'sectionlist' => \@sectionlist, |
| 2581 | 'sections' => \%sections, |
| 2582 | 'purpose' => $declaration_purpose |
| 2583 | }); |
| 2584 | } |
| 2585 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | sub reset_state { |
| 2587 | $function = ""; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | %parameterdescs = (); |
| 2589 | %parametertypes = (); |
| 2590 | @parameterlist = (); |
| 2591 | %sections = (); |
| 2592 | @sectionlist = (); |
Randy Dunlap | a1d94aa | 2008-12-19 08:49:30 -0800 | [diff] [blame] | 2593 | $sectcheck = ""; |
| 2594 | $struct_actual = ""; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | $prototype = ""; |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 2596 | |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 2597 | $state = STATE_NORMAL; |
| 2598 | $inline_doc_state = STATE_INLINE_NA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | } |
| 2600 | |
Jason Baron | 56afb0f | 2009-04-30 13:29:36 -0400 | [diff] [blame] | 2601 | sub tracepoint_munge($) { |
| 2602 | my $file = shift; |
| 2603 | my $tracepointname = 0; |
| 2604 | my $tracepointargs = 0; |
| 2605 | |
Jason Baron | 3a9089f | 2009-12-01 12:18:49 -0500 | [diff] [blame] | 2606 | if ($prototype =~ m/TRACE_EVENT\((.*?),/) { |
Jason Baron | 56afb0f | 2009-04-30 13:29:36 -0400 | [diff] [blame] | 2607 | $tracepointname = $1; |
| 2608 | } |
Jason Baron | 3a9089f | 2009-12-01 12:18:49 -0500 | [diff] [blame] | 2609 | if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { |
| 2610 | $tracepointname = $1; |
| 2611 | } |
| 2612 | if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { |
| 2613 | $tracepointname = $2; |
| 2614 | } |
| 2615 | $tracepointname =~ s/^\s+//; #strip leading whitespace |
| 2616 | if ($prototype =~ m/TP_PROTO\((.*?)\)/) { |
Jason Baron | 56afb0f | 2009-04-30 13:29:36 -0400 | [diff] [blame] | 2617 | $tracepointargs = $1; |
| 2618 | } |
| 2619 | if (($tracepointname eq 0) || ($tracepointargs eq 0)) { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2620 | print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". |
Jason Baron | 56afb0f | 2009-04-30 13:29:36 -0400 | [diff] [blame] | 2621 | "$prototype\n"; |
| 2622 | } else { |
| 2623 | $prototype = "static inline void trace_$tracepointname($tracepointargs)"; |
| 2624 | } |
| 2625 | } |
| 2626 | |
Randy Dunlap | b4870bc | 2009-02-11 13:04:33 -0800 | [diff] [blame] | 2627 | sub syscall_munge() { |
| 2628 | my $void = 0; |
| 2629 | |
| 2630 | $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs |
| 2631 | ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { |
| 2632 | if ($prototype =~ m/SYSCALL_DEFINE0/) { |
| 2633 | $void = 1; |
| 2634 | ## $prototype = "long sys_$1(void)"; |
| 2635 | } |
| 2636 | |
| 2637 | $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name |
| 2638 | if ($prototype =~ m/long (sys_.*?),/) { |
| 2639 | $prototype =~ s/,/\(/; |
| 2640 | } elsif ($void) { |
| 2641 | $prototype =~ s/\)/\(void\)/; |
| 2642 | } |
| 2643 | |
| 2644 | # now delete all of the odd-number commas in $prototype |
| 2645 | # so that arg types & arg names don't have a comma between them |
| 2646 | my $count = 0; |
| 2647 | my $len = length($prototype); |
| 2648 | if ($void) { |
| 2649 | $len = 0; # skip the for-loop |
| 2650 | } |
| 2651 | for (my $ix = 0; $ix < $len; $ix++) { |
| 2652 | if (substr($prototype, $ix, 1) eq ',') { |
| 2653 | $count++; |
| 2654 | if ($count % 2 == 1) { |
| 2655 | substr($prototype, $ix, 1) = ' '; |
| 2656 | } |
| 2657 | } |
| 2658 | } |
| 2659 | } |
| 2660 | |
Daniel Vetter | b7afa92 | 2016-06-01 23:46:24 +0200 | [diff] [blame] | 2661 | sub process_proto_function($$) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | my $x = shift; |
| 2663 | my $file = shift; |
| 2664 | |
Randy Dunlap | 51f5a0c | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 2665 | $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line |
| 2666 | |
Randy Dunlap | 890c78c | 2008-10-25 17:06:43 -0700 | [diff] [blame] | 2667 | if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | # do nothing |
| 2669 | } |
| 2670 | elsif ($x =~ /([^\{]*)/) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2671 | $prototype .= $1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | } |
Randy Dunlap | b4870bc | 2009-02-11 13:04:33 -0800 | [diff] [blame] | 2673 | |
Randy Dunlap | 890c78c | 2008-10-25 17:06:43 -0700 | [diff] [blame] | 2674 | if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2675 | $prototype =~ s@/\*.*?\*/@@gos; # strip comments. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2676 | $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. |
| 2677 | $prototype =~ s@^\s+@@gos; # strip leading spaces |
Randy Dunlap | b4870bc | 2009-02-11 13:04:33 -0800 | [diff] [blame] | 2678 | if ($prototype =~ /SYSCALL_DEFINE/) { |
| 2679 | syscall_munge(); |
| 2680 | } |
Jason Baron | 3a9089f | 2009-12-01 12:18:49 -0500 | [diff] [blame] | 2681 | if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || |
| 2682 | $prototype =~ /DEFINE_SINGLE_EVENT/) |
| 2683 | { |
Jason Baron | 56afb0f | 2009-04-30 13:29:36 -0400 | [diff] [blame] | 2684 | tracepoint_munge($file); |
| 2685 | } |
Randy Dunlap | b4870bc | 2009-02-11 13:04:33 -0800 | [diff] [blame] | 2686 | dump_function($prototype, $file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2687 | reset_state(); |
| 2688 | } |
| 2689 | } |
| 2690 | |
Daniel Vetter | b7afa92 | 2016-06-01 23:46:24 +0200 | [diff] [blame] | 2691 | sub process_proto_type($$) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | my $x = shift; |
| 2693 | my $file = shift; |
| 2694 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. |
| 2696 | $x =~ s@^\s+@@gos; # strip leading spaces |
| 2697 | $x =~ s@\s+$@@gos; # strip trailing spaces |
Randy Dunlap | 51f5a0c | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 2698 | $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line |
| 2699 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | if ($x =~ /^#/) { |
| 2701 | # To distinguish preprocessor directive from regular declaration later. |
| 2702 | $x .= ";"; |
| 2703 | } |
| 2704 | |
| 2705 | while (1) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2706 | if ( $x =~ /([^{};]*)([{};])(.*)/ ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2707 | $prototype .= $1 . $2; |
| 2708 | ($2 eq '{') && $brcount++; |
| 2709 | ($2 eq '}') && $brcount--; |
| 2710 | if (($2 eq ';') && ($brcount == 0)) { |
Randy Dunlap | b9d97328 | 2009-06-09 08:50:38 -0700 | [diff] [blame] | 2711 | dump_declaration($prototype, $file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | reset_state(); |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2713 | last; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | } |
| 2715 | $x = $3; |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2716 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | $prototype .= $x; |
| 2718 | last; |
| 2719 | } |
| 2720 | } |
| 2721 | } |
| 2722 | |
Randy Dunlap | 6b5b55f | 2007-10-16 23:31:20 -0700 | [diff] [blame] | 2723 | # xml_escape: replace <, >, and & in the text stream; |
| 2724 | # |
| 2725 | # however, formatting controls that are generated internally/locally in the |
| 2726 | # kernel-doc script are not escaped here; instead, they begin life like |
| 2727 | # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings |
| 2728 | # are converted to their mnemonic-expected output, without the 4 * '\' & ':', |
| 2729 | # just before actual output; (this is done by local_unescape()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2730 | sub xml_escape($) { |
| 2731 | my $text = shift; |
Randy Dunlap | ecfb251 | 2006-06-25 05:49:13 -0700 | [diff] [blame] | 2732 | if (($output_mode eq "text") || ($output_mode eq "man")) { |
| 2733 | return $text; |
| 2734 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | $text =~ s/\&/\\\\\\amp;/g; |
| 2736 | $text =~ s/\</\\\\\\lt;/g; |
| 2737 | $text =~ s/\>/\\\\\\gt;/g; |
| 2738 | return $text; |
| 2739 | } |
| 2740 | |
Jonathan Corbet | c0d1b6e | 2016-05-12 16:15:37 +0300 | [diff] [blame] | 2741 | # xml_unescape: reverse the effects of xml_escape |
| 2742 | sub xml_unescape($) { |
| 2743 | my $text = shift; |
| 2744 | if (($output_mode eq "text") || ($output_mode eq "man")) { |
| 2745 | return $text; |
| 2746 | } |
| 2747 | $text =~ s/\\\\\\amp;/\&/g; |
| 2748 | $text =~ s/\\\\\\lt;/</g; |
| 2749 | $text =~ s/\\\\\\gt;/>/g; |
| 2750 | return $text; |
| 2751 | } |
| 2752 | |
Randy Dunlap | 6b5b55f | 2007-10-16 23:31:20 -0700 | [diff] [blame] | 2753 | # convert local escape strings to html |
| 2754 | # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) |
| 2755 | sub local_unescape($) { |
| 2756 | my $text = shift; |
| 2757 | if (($output_mode eq "text") || ($output_mode eq "man")) { |
| 2758 | return $text; |
| 2759 | } |
| 2760 | $text =~ s/\\\\\\\\lt:/</g; |
| 2761 | $text =~ s/\\\\\\\\gt:/>/g; |
| 2762 | return $text; |
| 2763 | } |
| 2764 | |
Jani Nikula | 1ad560e | 2016-06-07 10:53:39 +0300 | [diff] [blame] | 2765 | sub map_filename($) { |
| 2766 | my $file; |
| 2767 | my ($orig_file) = @_; |
| 2768 | |
| 2769 | if (defined($ENV{'SRCTREE'})) { |
| 2770 | $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; |
| 2771 | } else { |
| 2772 | $file = $orig_file; |
| 2773 | } |
| 2774 | |
| 2775 | if (defined($source_map{$file})) { |
| 2776 | $file = $source_map{$file}; |
| 2777 | } |
| 2778 | |
| 2779 | return $file; |
| 2780 | } |
| 2781 | |
Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 2782 | sub process_export_file($) { |
| 2783 | my ($orig_file) = @_; |
| 2784 | my $file = map_filename($orig_file); |
| 2785 | |
| 2786 | if (!open(IN,"<$file")) { |
| 2787 | print STDERR "Error: Cannot open file $file\n"; |
| 2788 | ++$errors; |
| 2789 | return; |
| 2790 | } |
| 2791 | |
| 2792 | while (<IN>) { |
| 2793 | if (/$export_symbol/) { |
| 2794 | $function_table{$2} = 1; |
| 2795 | } |
| 2796 | } |
| 2797 | |
| 2798 | close(IN); |
| 2799 | } |
| 2800 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2801 | sub process_file($) { |
Randy Dunlap | 2283a11 | 2005-07-07 15:39:26 -0700 | [diff] [blame] | 2802 | my $file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | my $identifier; |
| 2804 | my $func; |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 2805 | my $descr; |
Johannes Weiner | 6423133 | 2009-09-17 19:26:53 -0700 | [diff] [blame] | 2806 | my $in_purpose = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2807 | my $initial_section_counter = $section_counter; |
Ben Hutchings | 68f8666 | 2015-09-01 23:48:49 +0100 | [diff] [blame] | 2808 | my ($orig_file) = @_; |
Jani Nikula | b7886de | 2016-05-28 00:41:50 +0300 | [diff] [blame] | 2809 | my $leading_space; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | |
Jani Nikula | 1ad560e | 2016-06-07 10:53:39 +0300 | [diff] [blame] | 2811 | $file = map_filename($orig_file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | |
| 2813 | if (!open(IN,"<$file")) { |
| 2814 | print STDERR "Error: Cannot open file $file\n"; |
| 2815 | ++$errors; |
| 2816 | return; |
| 2817 | } |
| 2818 | |
Ilya Dryomov | a9e7314 | 2010-02-26 13:05:47 -0800 | [diff] [blame] | 2819 | $. = 1; |
| 2820 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | $section_counter = 0; |
| 2822 | while (<IN>) { |
Daniel Santos | 6547842 | 2012-10-04 17:15:05 -0700 | [diff] [blame] | 2823 | while (s/\\\s*$//) { |
| 2824 | $_ .= <IN>; |
| 2825 | } |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 2826 | if ($state == STATE_NORMAL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2827 | if (/$doc_start/o) { |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 2828 | $state = STATE_NAME; # next line is always the function name |
Randy Dunlap | 850622d | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 2829 | $in_doc_sect = 0; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 2830 | $declaration_start_line = $. + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2831 | } |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 2832 | } elsif ($state == STATE_NAME) {# this line is the function name (always) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | if (/$doc_block/o) { |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 2834 | $state = STATE_DOCBLOCK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | $contents = ""; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 2836 | $new_start_line = $. + 1; |
| 2837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2838 | if ( $1 eq "" ) { |
| 2839 | $section = $section_intro; |
| 2840 | } else { |
| 2841 | $section = $1; |
| 2842 | } |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2843 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2844 | elsif (/$doc_decl/o) { |
| 2845 | $identifier = $1; |
| 2846 | if (/\s*([\w\s]+?)\s*-/) { |
| 2847 | $identifier = $1; |
| 2848 | } |
| 2849 | |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 2850 | $state = STATE_FIELD; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 2851 | # if there's no @param blocks need to set up default section |
| 2852 | # here |
Jani Nikula | 2f4ad40 | 2016-05-30 11:21:06 +0300 | [diff] [blame] | 2853 | $contents = ""; |
| 2854 | $section = $section_default; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 2855 | $new_start_line = $. + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2856 | if (/-(.*)/) { |
Randy Dunlap | 51f5a0c | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 2857 | # strip leading/trailing/multiple spaces |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 2858 | $descr= $1; |
| 2859 | $descr =~ s/^\s*//; |
| 2860 | $descr =~ s/\s*$//; |
Daniel Santos | 12ae677 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 2861 | $descr =~ s/\s+/ /g; |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 2862 | $declaration_purpose = xml_escape($descr); |
Johannes Weiner | 6423133 | 2009-09-17 19:26:53 -0700 | [diff] [blame] | 2863 | $in_purpose = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2864 | } else { |
| 2865 | $declaration_purpose = ""; |
| 2866 | } |
Randy Dunlap | 77cc23b | 2008-02-07 00:13:42 -0800 | [diff] [blame] | 2867 | |
| 2868 | if (($declaration_purpose eq "") && $verbose) { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2869 | print STDERR "${file}:$.: warning: missing initial short description on line:\n"; |
Randy Dunlap | 77cc23b | 2008-02-07 00:13:42 -0800 | [diff] [blame] | 2870 | print STDERR $_; |
| 2871 | ++$warnings; |
| 2872 | } |
| 2873 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2874 | if ($identifier =~ m/^struct/) { |
| 2875 | $decl_type = 'struct'; |
| 2876 | } elsif ($identifier =~ m/^union/) { |
| 2877 | $decl_type = 'union'; |
| 2878 | } elsif ($identifier =~ m/^enum/) { |
| 2879 | $decl_type = 'enum'; |
| 2880 | } elsif ($identifier =~ m/^typedef/) { |
| 2881 | $decl_type = 'typedef'; |
| 2882 | } else { |
| 2883 | $decl_type = 'function'; |
| 2884 | } |
| 2885 | |
| 2886 | if ($verbose) { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2887 | print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2888 | } |
| 2889 | } else { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2890 | print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2891 | " - I thought it was a doc line\n"; |
| 2892 | ++$warnings; |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 2893 | $state = STATE_NORMAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | } |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 2895 | } elsif ($state == STATE_FIELD) { # look for head: lines, and include content |
Jani Nikula | f624ade | 2016-05-29 11:35:28 +0300 | [diff] [blame] | 2896 | if (/$doc_sect/i) { # case insensitive for supported section names |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2897 | $newsection = $1; |
| 2898 | $newcontents = $2; |
| 2899 | |
Jani Nikula | f624ade | 2016-05-29 11:35:28 +0300 | [diff] [blame] | 2900 | # map the supported section names to the canonical names |
| 2901 | if ($newsection =~ m/^description$/i) { |
| 2902 | $newsection = $section_default; |
| 2903 | } elsif ($newsection =~ m/^context$/i) { |
| 2904 | $newsection = $section_context; |
| 2905 | } elsif ($newsection =~ m/^returns?$/i) { |
| 2906 | $newsection = $section_return; |
| 2907 | } elsif ($newsection =~ m/^\@return$/) { |
| 2908 | # special: @return is a section, not a param description |
| 2909 | $newsection = $section_return; |
| 2910 | } |
| 2911 | |
Randy Dunlap | 792aa2f | 2008-02-07 00:13:41 -0800 | [diff] [blame] | 2912 | if (($contents ne "") && ($contents ne "\n")) { |
Randy Dunlap | 850622d | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 2913 | if (!$in_doc_sect && $verbose) { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2914 | print STDERR "${file}:$.: warning: contents before sections\n"; |
Randy Dunlap | 850622d | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 2915 | ++$warnings; |
| 2916 | } |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 2917 | dump_section($file, $section, xml_escape($contents)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2918 | $section = $section_default; |
| 2919 | } |
| 2920 | |
Randy Dunlap | 850622d | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 2921 | $in_doc_sect = 1; |
Johannes Weiner | 6423133 | 2009-09-17 19:26:53 -0700 | [diff] [blame] | 2922 | $in_purpose = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2923 | $contents = $newcontents; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 2924 | $new_start_line = $.; |
Jani Nikula | 0a72630 | 2016-05-28 14:50:20 +0300 | [diff] [blame] | 2925 | while ((substr($contents, 0, 1) eq " ") || |
| 2926 | substr($contents, 0, 1) eq "\t") { |
| 2927 | $contents = substr($contents, 1); |
| 2928 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2929 | if ($contents ne "") { |
| 2930 | $contents .= "\n"; |
| 2931 | } |
| 2932 | $section = $newsection; |
Jani Nikula | b7886de | 2016-05-28 00:41:50 +0300 | [diff] [blame] | 2933 | $leading_space = undef; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2934 | } elsif (/$doc_end/) { |
Randy Dunlap | 4c98eca | 2010-03-10 15:22:02 -0800 | [diff] [blame] | 2935 | if (($contents ne "") && ($contents ne "\n")) { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 2936 | dump_section($file, $section, xml_escape($contents)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2937 | $section = $section_default; |
| 2938 | $contents = ""; |
| 2939 | } |
Randy Dunlap | 46b958e | 2008-04-28 02:16:35 -0700 | [diff] [blame] | 2940 | # look for doc_com + <text> + doc_end: |
| 2941 | if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2942 | print STDERR "${file}:$.: warning: suspicious ending line: $_"; |
Randy Dunlap | 46b958e | 2008-04-28 02:16:35 -0700 | [diff] [blame] | 2943 | ++$warnings; |
| 2944 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2945 | |
| 2946 | $prototype = ""; |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 2947 | $state = STATE_PROTO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2948 | $brcount = 0; |
Randy Dunlap | 232acbc | 2006-06-25 05:47:48 -0700 | [diff] [blame] | 2949 | # print STDERR "end of doc comment, looking for prototype\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2950 | } elsif (/$doc_content/) { |
| 2951 | # miguel-style comment kludge, look for blank lines after |
| 2952 | # @parameter line to signify start of description |
Johannes Weiner | 6423133 | 2009-09-17 19:26:53 -0700 | [diff] [blame] | 2953 | if ($1 eq "") { |
| 2954 | if ($section =~ m/^@/ || $section eq $section_context) { |
| 2955 | dump_section($file, $section, xml_escape($contents)); |
| 2956 | $section = $section_default; |
| 2957 | $contents = ""; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 2958 | $new_start_line = $.; |
Johannes Weiner | 6423133 | 2009-09-17 19:26:53 -0700 | [diff] [blame] | 2959 | } else { |
| 2960 | $contents .= "\n"; |
| 2961 | } |
| 2962 | $in_purpose = 0; |
| 2963 | } elsif ($in_purpose == 1) { |
| 2964 | # Continued declaration purpose |
| 2965 | chomp($declaration_purpose); |
| 2966 | $declaration_purpose .= " " . xml_escape($1); |
Daniel Santos | 12ae677 | 2012-10-04 17:15:10 -0700 | [diff] [blame] | 2967 | $declaration_purpose =~ s/\s+/ /g; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2968 | } else { |
Jani Nikula | b7886de | 2016-05-28 00:41:50 +0300 | [diff] [blame] | 2969 | my $cont = $1; |
| 2970 | if ($section =~ m/^@/ || $section eq $section_context) { |
| 2971 | if (!defined $leading_space) { |
| 2972 | if ($cont =~ m/^(\s+)/) { |
| 2973 | $leading_space = $1; |
| 2974 | } else { |
| 2975 | $leading_space = ""; |
| 2976 | } |
| 2977 | } |
| 2978 | |
| 2979 | $cont =~ s/^$leading_space//; |
| 2980 | } |
| 2981 | $contents .= $cont . "\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | } |
| 2983 | } else { |
| 2984 | # i dont know - bad line? ignore. |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 2985 | print STDERR "${file}:$.: warning: bad line: $_"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2986 | ++$warnings; |
| 2987 | } |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 2988 | } elsif ($state == STATE_INLINE) { # scanning for inline parameters |
Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 2989 | # First line (state 1) needs to be a @parameter |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 2990 | 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] | 2991 | $section = $1; |
| 2992 | $contents = $2; |
Daniel Vetter | 0b0f5f29 | 2016-06-03 22:21:34 +0200 | [diff] [blame] | 2993 | $new_start_line = $.; |
Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 2994 | if ($contents ne "") { |
| 2995 | while ((substr($contents, 0, 1) eq " ") || |
| 2996 | substr($contents, 0, 1) eq "\t") { |
| 2997 | $contents = substr($contents, 1); |
| 2998 | } |
Jani Nikula | a0b96c2 | 2016-05-26 22:04:06 +0300 | [diff] [blame] | 2999 | $contents .= "\n"; |
Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 3000 | } |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 3001 | $inline_doc_state = STATE_INLINE_TEXT; |
Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 3002 | # Documentation block end */ |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 3003 | } elsif (/$doc_inline_end/) { |
Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 3004 | if (($contents ne "") && ($contents ne "\n")) { |
| 3005 | dump_section($file, $section, xml_escape($contents)); |
| 3006 | $section = $section_default; |
| 3007 | $contents = ""; |
| 3008 | } |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 3009 | $state = STATE_PROTO; |
| 3010 | $inline_doc_state = STATE_INLINE_NA; |
Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 3011 | # Regular text |
| 3012 | } elsif (/$doc_content/) { |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 3013 | if ($inline_doc_state == STATE_INLINE_TEXT) { |
Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 3014 | $contents .= $1 . "\n"; |
Jani Nikula | 6450c89 | 2016-05-26 22:04:42 +0300 | [diff] [blame] | 3015 | # nuke leading blank lines |
| 3016 | if ($contents =~ /^\s*$/) { |
| 3017 | $contents = ""; |
| 3018 | } |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 3019 | } elsif ($inline_doc_state == STATE_INLINE_NAME) { |
| 3020 | $inline_doc_state = STATE_INLINE_ERROR; |
Daniel Vetter | e7ca311 | 2016-07-15 10:19:30 +0200 | [diff] [blame] | 3021 | print STDERR "${file}:$.: warning: "; |
Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 3022 | print STDERR "Incorrect use of kernel-doc format: $_"; |
| 3023 | ++$warnings; |
| 3024 | } |
| 3025 | } |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 3026 | } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype) |
| 3027 | if (/$doc_inline_start/) { |
| 3028 | $state = STATE_INLINE; |
| 3029 | $inline_doc_state = STATE_INLINE_NAME; |
Danilo Cesar Lemes de Paula | a4c6ebe | 2015-08-04 09:04:08 -0300 | [diff] [blame] | 3030 | } elsif ($decl_type eq 'function') { |
Daniel Vetter | b7afa92 | 2016-06-01 23:46:24 +0200 | [diff] [blame] | 3031 | process_proto_function($_, $file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | } else { |
Daniel Vetter | b7afa92 | 2016-06-01 23:46:24 +0200 | [diff] [blame] | 3033 | process_proto_type($_, $file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | } |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 3035 | } elsif ($state == STATE_DOCBLOCK) { |
Daniel Vetter | ebff7f9 | 2016-06-01 23:46:23 +0200 | [diff] [blame] | 3036 | if (/$doc_end/) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3037 | { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 3038 | dump_doc_section($file, $section, xml_escape($contents)); |
Jani Nikula | 2f4ad40 | 2016-05-30 11:21:06 +0300 | [diff] [blame] | 3039 | $section = $section_default; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3040 | $contents = ""; |
| 3041 | $function = ""; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | %parameterdescs = (); |
| 3043 | %parametertypes = (); |
| 3044 | @parameterlist = (); |
| 3045 | %sections = (); |
| 3046 | @sectionlist = (); |
| 3047 | $prototype = ""; |
Jani Nikula | 48af606 | 2016-05-26 14:56:05 +0300 | [diff] [blame] | 3048 | $state = STATE_NORMAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3049 | } |
| 3050 | elsif (/$doc_content/) |
| 3051 | { |
| 3052 | if ( $1 eq "" ) |
| 3053 | { |
| 3054 | $contents .= $blankline; |
| 3055 | } |
| 3056 | else |
| 3057 | { |
| 3058 | $contents .= $1 . "\n"; |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 3059 | } |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 3060 | } |
| 3061 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | } |
| 3063 | if ($initial_section_counter == $section_counter) { |
Bart Van Assche | d40e1e6 | 2015-09-04 15:43:21 -0700 | [diff] [blame] | 3064 | print STDERR "${file}:1: warning: no structured comments found\n"; |
Jani Nikula | b6c3f45 | 2016-05-29 22:19:35 +0300 | [diff] [blame] | 3065 | if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) { |
Johannes Berg | e946c43a | 2013-11-12 15:11:12 -0800 | [diff] [blame] | 3066 | print STDERR " Was looking for '$_'.\n" for keys %function_table; |
| 3067 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3068 | if ($output_mode eq "xml") { |
| 3069 | # The template wants at least one RefEntry here; make one. |
| 3070 | print "<refentry>\n"; |
| 3071 | print " <refnamediv>\n"; |
| 3072 | print " <refname>\n"; |
Ben Hutchings | 68f8666 | 2015-09-01 23:48:49 +0100 | [diff] [blame] | 3073 | print " ${orig_file}\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3074 | print " </refname>\n"; |
| 3075 | print " <refpurpose>\n"; |
| 3076 | print " Document generation inconsistency\n"; |
| 3077 | print " </refpurpose>\n"; |
| 3078 | print " </refnamediv>\n"; |
| 3079 | print " <refsect1>\n"; |
| 3080 | print " <title>\n"; |
| 3081 | print " Oops\n"; |
| 3082 | print " </title>\n"; |
| 3083 | print " <warning>\n"; |
| 3084 | print " <para>\n"; |
| 3085 | print " The template for this document tried to insert\n"; |
| 3086 | print " the structured comment from the file\n"; |
Ben Hutchings | 68f8666 | 2015-09-01 23:48:49 +0100 | [diff] [blame] | 3087 | print " <filename>${orig_file}</filename> at this point,\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | print " but none was found.\n"; |
| 3089 | print " This dummy section is inserted to allow\n"; |
| 3090 | print " generation to continue.\n"; |
| 3091 | print " </para>\n"; |
| 3092 | print " </warning>\n"; |
| 3093 | print " </refsect1>\n"; |
| 3094 | print "</refentry>\n"; |
| 3095 | } |
| 3096 | } |
| 3097 | } |
Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 3098 | |
| 3099 | |
| 3100 | $kernelversion = get_kernel_version(); |
| 3101 | |
| 3102 | # generate a sequence of code that will splice in highlighting information |
| 3103 | # using the s// operator. |
Mauro Carvalho Chehab | 1ef0623 | 2015-11-17 13:29:49 -0200 | [diff] [blame] | 3104 | for (my $k = 0; $k < @highlights; $k++) { |
Danilo Cesar Lemes de Paula | 4d73270 | 2015-09-07 17:01:59 -0300 | [diff] [blame] | 3105 | my $pattern = $highlights[$k][0]; |
| 3106 | my $result = $highlights[$k][1]; |
| 3107 | # print STDERR "scanning pattern:$pattern, highlight:($result)\n"; |
| 3108 | $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; |
Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 3109 | } |
| 3110 | |
| 3111 | # Read the file that maps relative names to absolute names for |
| 3112 | # separate source and object directories and for shadow trees. |
| 3113 | if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { |
| 3114 | my ($relname, $absname); |
| 3115 | while(<SOURCE_MAP>) { |
| 3116 | chop(); |
| 3117 | ($relname, $absname) = (split())[0..1]; |
| 3118 | $relname =~ s:^/+::; |
| 3119 | $source_map{$relname} = $absname; |
| 3120 | } |
| 3121 | close(SOURCE_MAP); |
| 3122 | } |
| 3123 | |
Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 3124 | if ($output_selection == OUTPUT_EXPORTED || |
| 3125 | $output_selection == OUTPUT_INTERNAL) { |
Jani Nikula | c9b2cfb | 2016-06-07 11:05:53 +0300 | [diff] [blame] | 3126 | |
| 3127 | push(@export_file_list, @ARGV); |
| 3128 | |
Jani Nikula | 88c2b57 | 2016-06-07 11:00:52 +0300 | [diff] [blame] | 3129 | foreach (@export_file_list) { |
| 3130 | chomp; |
| 3131 | process_export_file($_); |
| 3132 | } |
| 3133 | } |
| 3134 | |
Randy Dunlap | 8484baa | 2011-01-05 16:28:43 -0800 | [diff] [blame] | 3135 | foreach (@ARGV) { |
| 3136 | chomp; |
| 3137 | process_file($_); |
| 3138 | } |
| 3139 | if ($verbose && $errors) { |
| 3140 | print STDERR "$errors errors\n"; |
| 3141 | } |
| 3142 | if ($verbose && $warnings) { |
| 3143 | print STDERR "$warnings warnings\n"; |
| 3144 | } |
| 3145 | |
| 3146 | exit($errors); |