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