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