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