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