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