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