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