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