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