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