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 | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 8 | ## Copyright (C) 2005-2008 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 |
| 88 | # **/ |
| 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 | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 108 | # Beside functions you can also write documentation for structs, unions, |
| 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 |
| 226 | if ($#ARGV==-1) { |
| 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 |
| 243 | # They probably want to be tidied up made more localised or summat. |
| 244 | # CAVEAT EMPTOR! Some of the others I localised may not want to be which |
| 245 | # could cause "use of undefined value" or other bugs. |
| 246 | my ($function, %function_table,%parametertypes,$declaration_purpose); |
| 247 | my ($type,$declaration_name,$return_type); |
| 248 | my ($newsection,$newcontents,$prototype,$filelist, $brcount, %source_map); |
| 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*'; |
| 282 | my $doc_decl = $doc_com.'(\w+)'; |
Randy Dunlap | 891dcd2 | 2007-02-10 01:45:53 -0800 | [diff] [blame] | 283 | my $doc_sect = $doc_com.'(['.$doc_special.']?[\w\s]+):(.*)'; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | my $doc_content = $doc_com.'(.*)'; |
| 285 | my $doc_block = $doc_com.'DOC:\s*(.*)?'; |
| 286 | |
| 287 | my %constants; |
| 288 | my %parameterdescs; |
| 289 | my @parameterlist; |
| 290 | my %sections; |
| 291 | my @sectionlist; |
| 292 | |
| 293 | my $contents = ""; |
| 294 | my $section_default = "Description"; # default section |
| 295 | my $section_intro = "Introduction"; |
| 296 | my $section = $section_default; |
| 297 | my $section_context = "Context"; |
| 298 | |
| 299 | my $undescribed = "-- undescribed --"; |
| 300 | |
| 301 | reset_state(); |
| 302 | |
| 303 | while ($ARGV[0] =~ m/^-(.*)/) { |
| 304 | my $cmd = shift @ARGV; |
| 305 | if ($cmd eq "-html") { |
| 306 | $output_mode = "html"; |
| 307 | %highlights = %highlights_html; |
| 308 | $blankline = $blankline_html; |
| 309 | } elsif ($cmd eq "-man") { |
| 310 | $output_mode = "man"; |
| 311 | %highlights = %highlights_man; |
| 312 | $blankline = $blankline_man; |
| 313 | } elsif ($cmd eq "-text") { |
| 314 | $output_mode = "text"; |
| 315 | %highlights = %highlights_text; |
| 316 | $blankline = $blankline_text; |
| 317 | } elsif ($cmd eq "-docbook") { |
| 318 | $output_mode = "xml"; |
| 319 | %highlights = %highlights_xml; |
| 320 | $blankline = $blankline_xml; |
| 321 | } elsif ($cmd eq "-gnome") { |
| 322 | $output_mode = "gnome"; |
| 323 | %highlights = %highlights_gnome; |
| 324 | $blankline = $blankline_gnome; |
| 325 | } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document |
| 326 | $modulename = shift @ARGV; |
| 327 | } elsif ($cmd eq "-function") { # to only output specific functions |
| 328 | $function_only = 1; |
| 329 | $function = shift @ARGV; |
| 330 | $function_table{$function} = 1; |
| 331 | } elsif ($cmd eq "-nofunction") { # to only output specific functions |
| 332 | $function_only = 2; |
| 333 | $function = shift @ARGV; |
| 334 | $function_table{$function} = 1; |
| 335 | } elsif ($cmd eq "-v") { |
| 336 | $verbose = 1; |
| 337 | } elsif (($cmd eq "-h") || ($cmd eq "--help")) { |
| 338 | usage(); |
| 339 | } elsif ($cmd eq '-filelist') { |
| 340 | $filelist = shift @ARGV; |
Johannes Berg | 4b44595 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 341 | } elsif ($cmd eq '-no-doc-sections') { |
| 342 | $no_doc_sections = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
Borislav Petkov | 53f049f | 2007-05-08 00:30:54 -0700 | [diff] [blame] | 346 | # get kernel version from env |
| 347 | sub get_kernel_version() { |
Johannes Berg | 1b9bc22 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 348 | my $version = 'unknown kernel version'; |
Borislav Petkov | 53f049f | 2007-05-08 00:30:54 -0700 | [diff] [blame] | 349 | |
| 350 | if (defined($ENV{'KERNELVERSION'})) { |
| 351 | $version = $ENV{'KERNELVERSION'}; |
| 352 | } |
| 353 | return $version; |
| 354 | } |
Borislav Petkov | 0366299 | 2007-05-09 02:33:43 -0700 | [diff] [blame] | 355 | my $kernelversion = get_kernel_version(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | # generate a sequence of code that will splice in highlighting information |
| 358 | # using the s// operator. |
| 359 | my $dohighlight = ""; |
| 360 | foreach my $pattern (keys %highlights) { |
Randy Dunlap | 3eb014a | 2007-05-08 00:29:51 -0700 | [diff] [blame] | 361 | # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n"; |
| 363 | } |
| 364 | |
| 365 | ## |
| 366 | # dumps section contents to arrays/hashes intended for that purpose. |
| 367 | # |
| 368 | sub dump_section { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 369 | my $file = shift; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | my $name = shift; |
| 371 | my $contents = join "\n", @_; |
| 372 | |
| 373 | if ($name =~ m/$type_constant/) { |
| 374 | $name = $1; |
| 375 | # print STDERR "constant section '$1' = '$contents'\n"; |
| 376 | $constants{$name} = $contents; |
| 377 | } elsif ($name =~ m/$type_param/) { |
| 378 | # print STDERR "parameter def '$1' = '$contents'\n"; |
| 379 | $name = $1; |
| 380 | $parameterdescs{$name} = $contents; |
Randy Dunlap | ced6909 | 2008-12-01 13:14:03 -0800 | [diff] [blame^] | 381 | } elsif ($name eq "@\.\.\.") { |
| 382 | # print STDERR "parameter def '...' = '$contents'\n"; |
| 383 | $name = "..."; |
| 384 | $parameterdescs{$name} = $contents; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } else { |
| 386 | # print STDERR "other section '$name' = '$contents'\n"; |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 387 | if (defined($sections{$name}) && ($sections{$name} ne "")) { |
| 388 | print STDERR "Error(${file}:$.): duplicate section name '$name'\n"; |
| 389 | ++$errors; |
| 390 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | $sections{$name} = $contents; |
| 392 | push @sectionlist, $name; |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | ## |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 397 | # dump DOC: section after checking that it should go out |
| 398 | # |
| 399 | sub dump_doc_section { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 400 | my $file = shift; |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 401 | my $name = shift; |
| 402 | my $contents = join "\n", @_; |
| 403 | |
Johannes Berg | 4b44595 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 404 | if ($no_doc_sections) { |
| 405 | return; |
| 406 | } |
| 407 | |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 408 | if (($function_only == 0) || |
| 409 | ( $function_only == 1 && defined($function_table{$name})) || |
| 410 | ( $function_only == 2 && !defined($function_table{$name}))) |
| 411 | { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 412 | dump_section($file, $name, $contents); |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 413 | output_blockhead({'sectionlist' => \@sectionlist, |
| 414 | 'sections' => \%sections, |
| 415 | 'module' => $modulename, |
| 416 | 'content-only' => ($function_only != 0), }); |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | ## |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | # output function |
| 422 | # |
| 423 | # parameterdescs, a hash. |
| 424 | # function => "function name" |
| 425 | # parameterlist => @list of parameters |
| 426 | # parameterdescs => %parameter descriptions |
| 427 | # sectionlist => @list of sections |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 428 | # sections => %section descriptions |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 429 | # |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
| 431 | sub output_highlight { |
| 432 | my $contents = join "\n",@_; |
| 433 | my $line; |
| 434 | |
| 435 | # DEBUG |
| 436 | # if (!defined $contents) { |
| 437 | # use Carp; |
| 438 | # confess "output_highlight got called with no args?\n"; |
| 439 | # } |
| 440 | |
Johannes Berg | 5c98fc0 | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 441 | if ($output_mode eq "html" || $output_mode eq "xml") { |
Randy Dunlap | 6b5b55f | 2007-10-16 23:31:20 -0700 | [diff] [blame] | 442 | $contents = local_unescape($contents); |
| 443 | # convert data read & converted thru xml_escape() into &xyz; format: |
| 444 | $contents =~ s/\\\\\\/&/g; |
| 445 | } |
Randy Dunlap | 3eb014a | 2007-05-08 00:29:51 -0700 | [diff] [blame] | 446 | # print STDERR "contents b4:$contents\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | eval $dohighlight; |
| 448 | die $@ if $@; |
Randy Dunlap | 3eb014a | 2007-05-08 00:29:51 -0700 | [diff] [blame] | 449 | # print STDERR "contents af:$contents\n"; |
| 450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | foreach $line (split "\n", $contents) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 452 | if ($line eq ""){ |
Randy Dunlap | 6b5b55f | 2007-10-16 23:31:20 -0700 | [diff] [blame] | 453 | print $lineprefix, local_unescape($blankline); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } else { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 455 | $line =~ s/\\\\\\/\&/g; |
Randy Dunlap | cdccb31 | 2007-07-19 01:48:25 -0700 | [diff] [blame] | 456 | if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { |
| 457 | print "\\&$line"; |
| 458 | } else { |
| 459 | print $lineprefix, $line; |
| 460 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
| 462 | print "\n"; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | #output sections in html |
| 467 | sub output_section_html(%) { |
| 468 | my %args = %{$_[0]}; |
| 469 | my $section; |
| 470 | |
| 471 | foreach $section (@{$args{'sectionlist'}}) { |
| 472 | print "<h3>$section</h3>\n"; |
| 473 | print "<blockquote>\n"; |
| 474 | output_highlight($args{'sections'}{$section}); |
| 475 | print "</blockquote>\n"; |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 476 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | # output enum in html |
| 480 | sub output_enum_html(%) { |
| 481 | my %args = %{$_[0]}; |
| 482 | my ($parameter); |
| 483 | my $count; |
| 484 | print "<h2>enum ".$args{'enum'}."</h2>\n"; |
| 485 | |
| 486 | print "<b>enum ".$args{'enum'}."</b> {<br>\n"; |
| 487 | $count = 0; |
| 488 | foreach $parameter (@{$args{'parameterlist'}}) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 489 | print " <b>".$parameter."</b>"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | if ($count != $#{$args{'parameterlist'}}) { |
| 491 | $count++; |
| 492 | print ",\n"; |
| 493 | } |
| 494 | print "<br>"; |
| 495 | } |
| 496 | print "};<br>\n"; |
| 497 | |
| 498 | print "<h3>Constants</h3>\n"; |
| 499 | print "<dl>\n"; |
| 500 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 501 | print "<dt><b>".$parameter."</b>\n"; |
| 502 | print "<dd>"; |
| 503 | output_highlight($args{'parameterdescs'}{$parameter}); |
| 504 | } |
| 505 | print "</dl>\n"; |
| 506 | output_section_html(@_); |
| 507 | print "<hr>\n"; |
| 508 | } |
| 509 | |
Randy Dunlap | d28bee0 | 2006-02-01 03:06:57 -0800 | [diff] [blame] | 510 | # output typedef in html |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | sub output_typedef_html(%) { |
| 512 | my %args = %{$_[0]}; |
| 513 | my ($parameter); |
| 514 | my $count; |
| 515 | print "<h2>typedef ".$args{'typedef'}."</h2>\n"; |
| 516 | |
| 517 | print "<b>typedef ".$args{'typedef'}."</b>\n"; |
| 518 | output_section_html(@_); |
| 519 | print "<hr>\n"; |
| 520 | } |
| 521 | |
| 522 | # output struct in html |
| 523 | sub output_struct_html(%) { |
| 524 | my %args = %{$_[0]}; |
| 525 | my ($parameter); |
| 526 | |
Randy Dunlap | 262d9b0 | 2007-02-20 13:58:04 -0800 | [diff] [blame] | 527 | print "<h2>".$args{'type'}." ".$args{'struct'}. " - " .$args{'purpose'}."</h2>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n"; |
| 529 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 530 | if ($parameter =~ /^#/) { |
| 531 | print "$parameter<br>\n"; |
| 532 | next; |
| 533 | } |
| 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 | $type = $args{'parametertypes'}{$parameter}; |
| 539 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 540 | # pointer-to-function |
Randy Dunlap | 3eb014a | 2007-05-08 00:29:51 -0700 | [diff] [blame] | 541 | print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { |
Randy Dunlap | 3eb014a | 2007-05-08 00:29:51 -0700 | [diff] [blame] | 543 | # bitfield |
| 544 | print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | } else { |
Randy Dunlap | 3eb014a | 2007-05-08 00:29:51 -0700 | [diff] [blame] | 546 | print " <i>$type</i> <b>$parameter</b>;<br>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | print "};<br>\n"; |
| 550 | |
| 551 | print "<h3>Members</h3>\n"; |
| 552 | print "<dl>\n"; |
| 553 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 554 | ($parameter =~ /^#/) && next; |
| 555 | |
| 556 | my $parameter_name = $parameter; |
| 557 | $parameter_name =~ s/\[.*//; |
| 558 | |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 559 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | print "<dt><b>".$parameter."</b>\n"; |
| 561 | print "<dd>"; |
| 562 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 563 | } |
| 564 | print "</dl>\n"; |
| 565 | output_section_html(@_); |
| 566 | print "<hr>\n"; |
| 567 | } |
| 568 | |
| 569 | # output function in html |
| 570 | sub output_function_html(%) { |
| 571 | my %args = %{$_[0]}; |
| 572 | my ($parameter, $section); |
| 573 | my $count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
Randy Dunlap | 262d9b0 | 2007-02-20 13:58:04 -0800 | [diff] [blame] | 575 | print "<h2>" .$args{'function'}." - ".$args{'purpose'}."</h2>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | print "<i>".$args{'functiontype'}."</i>\n"; |
| 577 | print "<b>".$args{'function'}."</b>\n"; |
| 578 | print "("; |
| 579 | $count = 0; |
| 580 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 581 | $type = $args{'parametertypes'}{$parameter}; |
| 582 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 583 | # pointer-to-function |
| 584 | print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; |
| 585 | } else { |
| 586 | print "<i>".$type."</i> <b>".$parameter."</b>"; |
| 587 | } |
| 588 | if ($count != $#{$args{'parameterlist'}}) { |
| 589 | $count++; |
| 590 | print ",\n"; |
| 591 | } |
| 592 | } |
| 593 | print ")\n"; |
| 594 | |
| 595 | print "<h3>Arguments</h3>\n"; |
| 596 | print "<dl>\n"; |
| 597 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 598 | my $parameter_name = $parameter; |
| 599 | $parameter_name =~ s/\[.*//; |
| 600 | |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 601 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | print "<dt><b>".$parameter."</b>\n"; |
| 603 | print "<dd>"; |
| 604 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 605 | } |
| 606 | print "</dl>\n"; |
| 607 | output_section_html(@_); |
| 608 | print "<hr>\n"; |
| 609 | } |
| 610 | |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 611 | # output DOC: block header in html |
| 612 | sub output_blockhead_html(%) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | my %args = %{$_[0]}; |
| 614 | my ($parameter, $section); |
| 615 | my $count; |
| 616 | |
| 617 | foreach $section (@{$args{'sectionlist'}}) { |
| 618 | print "<h3>$section</h3>\n"; |
| 619 | print "<ul>\n"; |
| 620 | output_highlight($args{'sections'}{$section}); |
| 621 | print "</ul>\n"; |
| 622 | } |
| 623 | print "<hr>\n"; |
| 624 | } |
| 625 | |
| 626 | sub output_section_xml(%) { |
| 627 | my %args = %{$_[0]}; |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 628 | my $section; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | # print out each section |
| 630 | $lineprefix=" "; |
| 631 | foreach $section (@{$args{'sectionlist'}}) { |
Rich Walker | c73894c | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 632 | print "<refsect1>\n"; |
| 633 | print "<title>$section</title>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | if ($section =~ m/EXAMPLE/i) { |
Rich Walker | c73894c | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 635 | print "<informalexample><programlisting>\n"; |
| 636 | } else { |
| 637 | print "<para>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | } |
| 639 | output_highlight($args{'sections'}{$section}); |
| 640 | if ($section =~ m/EXAMPLE/i) { |
Rich Walker | c73894c | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 641 | print "</programlisting></informalexample>\n"; |
| 642 | } else { |
| 643 | print "</para>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | } |
Rich Walker | c73894c | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 645 | print "</refsect1>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } |
| 647 | } |
| 648 | |
| 649 | # output function in XML DocBook |
| 650 | sub output_function_xml(%) { |
| 651 | my %args = %{$_[0]}; |
| 652 | my ($parameter, $section); |
| 653 | my $count; |
| 654 | my $id; |
| 655 | |
| 656 | $id = "API-".$args{'function'}; |
| 657 | $id =~ s/[^A-Za-z0-9]/-/g; |
| 658 | |
Pavel Pisa | 5449bc9 | 2007-02-10 01:45:37 -0800 | [diff] [blame] | 659 | print "<refentry id=\"$id\">\n"; |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 660 | print "<refentryinfo>\n"; |
| 661 | print " <title>LINUX</title>\n"; |
| 662 | print " <productname>Kernel Hackers Manual</productname>\n"; |
| 663 | print " <date>$man_date</date>\n"; |
| 664 | print "</refentryinfo>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | print "<refmeta>\n"; |
Pavel Pisa | 5449bc9 | 2007-02-10 01:45:37 -0800 | [diff] [blame] | 666 | print " <refentrytitle><phrase>".$args{'function'}."</phrase></refentrytitle>\n"; |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 667 | print " <manvolnum>9</manvolnum>\n"; |
Borislav Petkov | 0366299 | 2007-05-09 02:33:43 -0700 | [diff] [blame] | 668 | print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | print "</refmeta>\n"; |
| 670 | print "<refnamediv>\n"; |
| 671 | print " <refname>".$args{'function'}."</refname>\n"; |
| 672 | print " <refpurpose>\n"; |
| 673 | print " "; |
| 674 | output_highlight ($args{'purpose'}); |
| 675 | print " </refpurpose>\n"; |
| 676 | print "</refnamediv>\n"; |
| 677 | |
| 678 | print "<refsynopsisdiv>\n"; |
| 679 | print " <title>Synopsis</title>\n"; |
| 680 | print " <funcsynopsis><funcprototype>\n"; |
| 681 | print " <funcdef>".$args{'functiontype'}." "; |
| 682 | print "<function>".$args{'function'}." </function></funcdef>\n"; |
| 683 | |
| 684 | $count = 0; |
| 685 | if ($#{$args{'parameterlist'}} >= 0) { |
| 686 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 687 | $type = $args{'parametertypes'}{$parameter}; |
| 688 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 689 | # pointer-to-function |
| 690 | print " <paramdef>$1<parameter>$parameter</parameter>)\n"; |
| 691 | print " <funcparams>$2</funcparams></paramdef>\n"; |
| 692 | } else { |
| 693 | print " <paramdef>".$type; |
| 694 | print " <parameter>$parameter</parameter></paramdef>\n"; |
| 695 | } |
| 696 | } |
| 697 | } else { |
Martin Waitz | 6013d54 | 2005-05-01 08:59:25 -0700 | [diff] [blame] | 698 | print " <void/>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | } |
| 700 | print " </funcprototype></funcsynopsis>\n"; |
| 701 | print "</refsynopsisdiv>\n"; |
| 702 | |
| 703 | # print parameters |
| 704 | print "<refsect1>\n <title>Arguments</title>\n"; |
| 705 | if ($#{$args{'parameterlist'}} >= 0) { |
| 706 | print " <variablelist>\n"; |
| 707 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 708 | my $parameter_name = $parameter; |
| 709 | $parameter_name =~ s/\[.*//; |
| 710 | |
| 711 | print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; |
| 712 | print " <listitem>\n <para>\n"; |
| 713 | $lineprefix=" "; |
| 714 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 715 | print " </para>\n </listitem>\n </varlistentry>\n"; |
| 716 | } |
| 717 | print " </variablelist>\n"; |
| 718 | } else { |
| 719 | print " <para>\n None\n </para>\n"; |
| 720 | } |
| 721 | print "</refsect1>\n"; |
| 722 | |
| 723 | output_section_xml(@_); |
| 724 | print "</refentry>\n\n"; |
| 725 | } |
| 726 | |
| 727 | # output struct in XML DocBook |
| 728 | sub output_struct_xml(%) { |
| 729 | my %args = %{$_[0]}; |
| 730 | my ($parameter, $section); |
| 731 | my $id; |
| 732 | |
| 733 | $id = "API-struct-".$args{'struct'}; |
| 734 | $id =~ s/[^A-Za-z0-9]/-/g; |
| 735 | |
Pavel Pisa | 5449bc9 | 2007-02-10 01:45:37 -0800 | [diff] [blame] | 736 | print "<refentry id=\"$id\">\n"; |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 737 | print "<refentryinfo>\n"; |
| 738 | print " <title>LINUX</title>\n"; |
| 739 | print " <productname>Kernel Hackers Manual</productname>\n"; |
| 740 | print " <date>$man_date</date>\n"; |
| 741 | print "</refentryinfo>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | print "<refmeta>\n"; |
Pavel Pisa | 5449bc9 | 2007-02-10 01:45:37 -0800 | [diff] [blame] | 743 | print " <refentrytitle><phrase>".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n"; |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 744 | print " <manvolnum>9</manvolnum>\n"; |
Borislav Petkov | 0366299 | 2007-05-09 02:33:43 -0700 | [diff] [blame] | 745 | print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | print "</refmeta>\n"; |
| 747 | print "<refnamediv>\n"; |
| 748 | print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n"; |
| 749 | print " <refpurpose>\n"; |
| 750 | print " "; |
| 751 | output_highlight ($args{'purpose'}); |
| 752 | print " </refpurpose>\n"; |
| 753 | print "</refnamediv>\n"; |
| 754 | |
| 755 | print "<refsynopsisdiv>\n"; |
| 756 | print " <title>Synopsis</title>\n"; |
| 757 | print " <programlisting>\n"; |
| 758 | print $args{'type'}." ".$args{'struct'}." {\n"; |
| 759 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 760 | if ($parameter =~ /^#/) { |
| 761 | print "$parameter\n"; |
| 762 | next; |
| 763 | } |
| 764 | |
| 765 | my $parameter_name = $parameter; |
| 766 | $parameter_name =~ s/\[.*//; |
| 767 | |
| 768 | defined($args{'parameterdescs'}{$parameter_name}) || next; |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 769 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | $type = $args{'parametertypes'}{$parameter}; |
| 771 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 772 | # pointer-to-function |
| 773 | print " $1 $parameter) ($2);\n"; |
| 774 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { |
Randy Dunlap | 51f5a0c | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 775 | # bitfield |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | print " $1 $parameter$2;\n"; |
| 777 | } else { |
| 778 | print " ".$type." ".$parameter.";\n"; |
| 779 | } |
| 780 | } |
| 781 | print "};"; |
| 782 | print " </programlisting>\n"; |
| 783 | print "</refsynopsisdiv>\n"; |
| 784 | |
| 785 | print " <refsect1>\n"; |
| 786 | print " <title>Members</title>\n"; |
| 787 | |
Randy Dunlap | 39f00c0 | 2008-09-22 13:57:44 -0700 | [diff] [blame] | 788 | if ($#{$args{'parameterlist'}} >= 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | print " <variablelist>\n"; |
| 790 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 791 | ($parameter =~ /^#/) && next; |
| 792 | |
| 793 | my $parameter_name = $parameter; |
| 794 | $parameter_name =~ s/\[.*//; |
| 795 | |
| 796 | defined($args{'parameterdescs'}{$parameter_name}) || next; |
| 797 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
| 798 | print " <varlistentry>"; |
| 799 | print " <term>$parameter</term>\n"; |
| 800 | print " <listitem><para>\n"; |
| 801 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 802 | print " </para></listitem>\n"; |
| 803 | print " </varlistentry>\n"; |
| 804 | } |
| 805 | print " </variablelist>\n"; |
Randy Dunlap | 39f00c0 | 2008-09-22 13:57:44 -0700 | [diff] [blame] | 806 | } else { |
| 807 | print " <para>\n None\n </para>\n"; |
| 808 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | print " </refsect1>\n"; |
| 810 | |
| 811 | output_section_xml(@_); |
| 812 | |
| 813 | print "</refentry>\n\n"; |
| 814 | } |
| 815 | |
| 816 | # output enum in XML DocBook |
| 817 | sub output_enum_xml(%) { |
| 818 | my %args = %{$_[0]}; |
| 819 | my ($parameter, $section); |
| 820 | my $count; |
| 821 | my $id; |
| 822 | |
| 823 | $id = "API-enum-".$args{'enum'}; |
| 824 | $id =~ s/[^A-Za-z0-9]/-/g; |
| 825 | |
Pavel Pisa | 5449bc9 | 2007-02-10 01:45:37 -0800 | [diff] [blame] | 826 | print "<refentry id=\"$id\">\n"; |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 827 | print "<refentryinfo>\n"; |
| 828 | print " <title>LINUX</title>\n"; |
| 829 | print " <productname>Kernel Hackers Manual</productname>\n"; |
| 830 | print " <date>$man_date</date>\n"; |
| 831 | print "</refentryinfo>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | print "<refmeta>\n"; |
Pavel Pisa | 5449bc9 | 2007-02-10 01:45:37 -0800 | [diff] [blame] | 833 | print " <refentrytitle><phrase>enum ".$args{'enum'}."</phrase></refentrytitle>\n"; |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 834 | print " <manvolnum>9</manvolnum>\n"; |
Borislav Petkov | 0366299 | 2007-05-09 02:33:43 -0700 | [diff] [blame] | 835 | print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | print "</refmeta>\n"; |
| 837 | print "<refnamediv>\n"; |
| 838 | print " <refname>enum ".$args{'enum'}."</refname>\n"; |
| 839 | print " <refpurpose>\n"; |
| 840 | print " "; |
| 841 | output_highlight ($args{'purpose'}); |
| 842 | print " </refpurpose>\n"; |
| 843 | print "</refnamediv>\n"; |
| 844 | |
| 845 | print "<refsynopsisdiv>\n"; |
| 846 | print " <title>Synopsis</title>\n"; |
| 847 | print " <programlisting>\n"; |
| 848 | print "enum ".$args{'enum'}." {\n"; |
| 849 | $count = 0; |
| 850 | foreach $parameter (@{$args{'parameterlist'}}) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 851 | print " $parameter"; |
| 852 | if ($count != $#{$args{'parameterlist'}}) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | $count++; |
| 854 | print ","; |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 855 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | print "\n"; |
| 857 | } |
| 858 | print "};"; |
| 859 | print " </programlisting>\n"; |
| 860 | print "</refsynopsisdiv>\n"; |
| 861 | |
| 862 | print "<refsect1>\n"; |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 863 | print " <title>Constants</title>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | print " <variablelist>\n"; |
| 865 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 866 | my $parameter_name = $parameter; |
| 867 | $parameter_name =~ s/\[.*//; |
| 868 | |
| 869 | print " <varlistentry>"; |
| 870 | print " <term>$parameter</term>\n"; |
| 871 | print " <listitem><para>\n"; |
| 872 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 873 | print " </para></listitem>\n"; |
| 874 | print " </varlistentry>\n"; |
| 875 | } |
| 876 | print " </variablelist>\n"; |
| 877 | print "</refsect1>\n"; |
| 878 | |
| 879 | output_section_xml(@_); |
| 880 | |
| 881 | print "</refentry>\n\n"; |
| 882 | } |
| 883 | |
| 884 | # output typedef in XML DocBook |
| 885 | sub output_typedef_xml(%) { |
| 886 | my %args = %{$_[0]}; |
| 887 | my ($parameter, $section); |
| 888 | my $id; |
| 889 | |
| 890 | $id = "API-typedef-".$args{'typedef'}; |
| 891 | $id =~ s/[^A-Za-z0-9]/-/g; |
| 892 | |
Pavel Pisa | 5449bc9 | 2007-02-10 01:45:37 -0800 | [diff] [blame] | 893 | print "<refentry id=\"$id\">\n"; |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 894 | print "<refentryinfo>\n"; |
| 895 | print " <title>LINUX</title>\n"; |
| 896 | print " <productname>Kernel Hackers Manual</productname>\n"; |
| 897 | print " <date>$man_date</date>\n"; |
| 898 | print "</refentryinfo>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | print "<refmeta>\n"; |
Pavel Pisa | 5449bc9 | 2007-02-10 01:45:37 -0800 | [diff] [blame] | 900 | print " <refentrytitle><phrase>typedef ".$args{'typedef'}."</phrase></refentrytitle>\n"; |
Martin Waitz | 8b0c2d9 | 2005-05-01 08:59:27 -0700 | [diff] [blame] | 901 | print " <manvolnum>9</manvolnum>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | print "</refmeta>\n"; |
| 903 | print "<refnamediv>\n"; |
| 904 | print " <refname>typedef ".$args{'typedef'}."</refname>\n"; |
| 905 | print " <refpurpose>\n"; |
| 906 | print " "; |
| 907 | output_highlight ($args{'purpose'}); |
| 908 | print " </refpurpose>\n"; |
| 909 | print "</refnamediv>\n"; |
| 910 | |
| 911 | print "<refsynopsisdiv>\n"; |
| 912 | print " <title>Synopsis</title>\n"; |
| 913 | print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n"; |
| 914 | print "</refsynopsisdiv>\n"; |
| 915 | |
| 916 | output_section_xml(@_); |
| 917 | |
| 918 | print "</refentry>\n\n"; |
| 919 | } |
| 920 | |
| 921 | # output in XML DocBook |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 922 | sub output_blockhead_xml(%) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | my %args = %{$_[0]}; |
| 924 | my ($parameter, $section); |
| 925 | my $count; |
| 926 | |
| 927 | my $id = $args{'module'}; |
| 928 | $id =~ s/[^A-Za-z0-9]/-/g; |
| 929 | |
| 930 | # print out each section |
| 931 | $lineprefix=" "; |
| 932 | foreach $section (@{$args{'sectionlist'}}) { |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 933 | if (!$args{'content-only'}) { |
| 934 | print "<refsect1>\n <title>$section</title>\n"; |
| 935 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | if ($section =~ m/EXAMPLE/i) { |
| 937 | print "<example><para>\n"; |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 938 | } else { |
| 939 | print "<para>\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | } |
| 941 | output_highlight($args{'sections'}{$section}); |
| 942 | if ($section =~ m/EXAMPLE/i) { |
| 943 | print "</para></example>\n"; |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 944 | } else { |
| 945 | print "</para>"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | } |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 947 | if (!$args{'content-only'}) { |
| 948 | print "\n</refsect1>\n"; |
| 949 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | print "\n\n"; |
| 953 | } |
| 954 | |
| 955 | # output in XML DocBook |
| 956 | sub output_function_gnome { |
| 957 | my %args = %{$_[0]}; |
| 958 | my ($parameter, $section); |
| 959 | my $count; |
| 960 | my $id; |
| 961 | |
| 962 | $id = $args{'module'}."-".$args{'function'}; |
| 963 | $id =~ s/[^A-Za-z0-9]/-/g; |
| 964 | |
| 965 | print "<sect2>\n"; |
| 966 | print " <title id=\"$id\">".$args{'function'}."</title>\n"; |
| 967 | |
| 968 | print " <funcsynopsis>\n"; |
| 969 | print " <funcdef>".$args{'functiontype'}." "; |
| 970 | print "<function>".$args{'function'}." "; |
| 971 | print "</function></funcdef>\n"; |
| 972 | |
| 973 | $count = 0; |
| 974 | if ($#{$args{'parameterlist'}} >= 0) { |
| 975 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 976 | $type = $args{'parametertypes'}{$parameter}; |
| 977 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 978 | # pointer-to-function |
| 979 | print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; |
| 980 | print " <funcparams>$2</funcparams></paramdef>\n"; |
| 981 | } else { |
| 982 | print " <paramdef>".$type; |
| 983 | print " <parameter>$parameter</parameter></paramdef>\n"; |
| 984 | } |
| 985 | } |
| 986 | } else { |
| 987 | print " <void>\n"; |
| 988 | } |
| 989 | print " </funcsynopsis>\n"; |
| 990 | if ($#{$args{'parameterlist'}} >= 0) { |
| 991 | print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; |
| 992 | print "<tgroup cols=\"2\">\n"; |
| 993 | print "<colspec colwidth=\"2*\">\n"; |
| 994 | print "<colspec colwidth=\"8*\">\n"; |
| 995 | print "<tbody>\n"; |
| 996 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 997 | my $parameter_name = $parameter; |
| 998 | $parameter_name =~ s/\[.*//; |
| 999 | |
| 1000 | print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; |
| 1001 | print " <entry>\n"; |
| 1002 | $lineprefix=" "; |
| 1003 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 1004 | print " </entry></row>\n"; |
| 1005 | } |
| 1006 | print " </tbody></tgroup></informaltable>\n"; |
| 1007 | } else { |
| 1008 | print " <para>\n None\n </para>\n"; |
| 1009 | } |
| 1010 | |
| 1011 | # print out each section |
| 1012 | $lineprefix=" "; |
| 1013 | foreach $section (@{$args{'sectionlist'}}) { |
| 1014 | print "<simplesect>\n <title>$section</title>\n"; |
| 1015 | if ($section =~ m/EXAMPLE/i) { |
| 1016 | print "<example><programlisting>\n"; |
| 1017 | } else { |
| 1018 | } |
| 1019 | print "<para>\n"; |
| 1020 | output_highlight($args{'sections'}{$section}); |
| 1021 | print "</para>\n"; |
| 1022 | if ($section =~ m/EXAMPLE/i) { |
| 1023 | print "</programlisting></example>\n"; |
| 1024 | } else { |
| 1025 | } |
| 1026 | print " </simplesect>\n"; |
| 1027 | } |
| 1028 | |
| 1029 | print "</sect2>\n\n"; |
| 1030 | } |
| 1031 | |
| 1032 | ## |
| 1033 | # output function in man |
| 1034 | sub output_function_man(%) { |
| 1035 | my %args = %{$_[0]}; |
| 1036 | my ($parameter, $section); |
| 1037 | my $count; |
| 1038 | |
| 1039 | print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; |
| 1040 | |
| 1041 | print ".SH NAME\n"; |
| 1042 | print $args{'function'}." \\- ".$args{'purpose'}."\n"; |
| 1043 | |
| 1044 | print ".SH SYNOPSIS\n"; |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1045 | if ($args{'functiontype'} ne "") { |
| 1046 | print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n"; |
| 1047 | } else { |
| 1048 | print ".B \"".$args{'function'}."\n"; |
| 1049 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | $count = 0; |
| 1051 | my $parenth = "("; |
| 1052 | my $post = ","; |
| 1053 | foreach my $parameter (@{$args{'parameterlist'}}) { |
| 1054 | if ($count == $#{$args{'parameterlist'}}) { |
| 1055 | $post = ");"; |
| 1056 | } |
| 1057 | $type = $args{'parametertypes'}{$parameter}; |
| 1058 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 1059 | # pointer-to-function |
| 1060 | print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n"; |
| 1061 | } else { |
| 1062 | $type =~ s/([^\*])$/$1 /; |
| 1063 | print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n"; |
| 1064 | } |
| 1065 | $count++; |
| 1066 | $parenth = ""; |
| 1067 | } |
| 1068 | |
| 1069 | print ".SH ARGUMENTS\n"; |
| 1070 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1071 | my $parameter_name = $parameter; |
| 1072 | $parameter_name =~ s/\[.*//; |
| 1073 | |
| 1074 | print ".IP \"".$parameter."\" 12\n"; |
| 1075 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 1076 | } |
| 1077 | foreach $section (@{$args{'sectionlist'}}) { |
| 1078 | print ".SH \"", uc $section, "\"\n"; |
| 1079 | output_highlight($args{'sections'}{$section}); |
| 1080 | } |
| 1081 | } |
| 1082 | |
| 1083 | ## |
| 1084 | # output enum in man |
| 1085 | sub output_enum_man(%) { |
| 1086 | my %args = %{$_[0]}; |
| 1087 | my ($parameter, $section); |
| 1088 | my $count; |
| 1089 | |
| 1090 | print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; |
| 1091 | |
| 1092 | print ".SH NAME\n"; |
| 1093 | print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n"; |
| 1094 | |
| 1095 | print ".SH SYNOPSIS\n"; |
| 1096 | print "enum ".$args{'enum'}." {\n"; |
| 1097 | $count = 0; |
| 1098 | foreach my $parameter (@{$args{'parameterlist'}}) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1099 | print ".br\n.BI \" $parameter\"\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | if ($count == $#{$args{'parameterlist'}}) { |
| 1101 | print "\n};\n"; |
| 1102 | last; |
| 1103 | } |
| 1104 | else { |
| 1105 | print ", \n.br\n"; |
| 1106 | } |
| 1107 | $count++; |
| 1108 | } |
| 1109 | |
| 1110 | print ".SH Constants\n"; |
| 1111 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1112 | my $parameter_name = $parameter; |
| 1113 | $parameter_name =~ s/\[.*//; |
| 1114 | |
| 1115 | print ".IP \"".$parameter."\" 12\n"; |
| 1116 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 1117 | } |
| 1118 | foreach $section (@{$args{'sectionlist'}}) { |
| 1119 | print ".SH \"$section\"\n"; |
| 1120 | output_highlight($args{'sections'}{$section}); |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | ## |
| 1125 | # output struct in man |
| 1126 | sub output_struct_man(%) { |
| 1127 | my %args = %{$_[0]}; |
| 1128 | my ($parameter, $section); |
| 1129 | |
| 1130 | print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n"; |
| 1131 | |
| 1132 | print ".SH NAME\n"; |
| 1133 | print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n"; |
| 1134 | |
| 1135 | print ".SH SYNOPSIS\n"; |
| 1136 | print $args{'type'}." ".$args{'struct'}." {\n.br\n"; |
| 1137 | |
| 1138 | foreach my $parameter (@{$args{'parameterlist'}}) { |
| 1139 | if ($parameter =~ /^#/) { |
| 1140 | print ".BI \"$parameter\"\n.br\n"; |
| 1141 | next; |
| 1142 | } |
| 1143 | my $parameter_name = $parameter; |
| 1144 | $parameter_name =~ s/\[.*//; |
| 1145 | |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1146 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | $type = $args{'parametertypes'}{$parameter}; |
| 1148 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 1149 | # pointer-to-function |
| 1150 | print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n"; |
| 1151 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { |
Randy.Dunlap | 1d7e1d4 | 2006-07-01 04:36:34 -0700 | [diff] [blame] | 1152 | # bitfield |
| 1153 | print ".BI \" ".$1."\ \" ".$parameter.$2." \""."\"\n;\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | } else { |
| 1155 | $type =~ s/([^\*])$/$1 /; |
| 1156 | print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n"; |
| 1157 | } |
| 1158 | print "\n.br\n"; |
| 1159 | } |
| 1160 | print "};\n.br\n"; |
| 1161 | |
Randy Dunlap | c51d3da | 2006-06-25 05:49:14 -0700 | [diff] [blame] | 1162 | print ".SH Members\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1164 | ($parameter =~ /^#/) && next; |
| 1165 | |
| 1166 | my $parameter_name = $parameter; |
| 1167 | $parameter_name =~ s/\[.*//; |
| 1168 | |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1169 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | print ".IP \"".$parameter."\" 12\n"; |
| 1171 | output_highlight($args{'parameterdescs'}{$parameter_name}); |
| 1172 | } |
| 1173 | foreach $section (@{$args{'sectionlist'}}) { |
| 1174 | print ".SH \"$section\"\n"; |
| 1175 | output_highlight($args{'sections'}{$section}); |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | ## |
| 1180 | # output typedef in man |
| 1181 | sub output_typedef_man(%) { |
| 1182 | my %args = %{$_[0]}; |
| 1183 | my ($parameter, $section); |
| 1184 | |
| 1185 | print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; |
| 1186 | |
| 1187 | print ".SH NAME\n"; |
| 1188 | print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n"; |
| 1189 | |
| 1190 | foreach $section (@{$args{'sectionlist'}}) { |
| 1191 | print ".SH \"$section\"\n"; |
| 1192 | output_highlight($args{'sections'}{$section}); |
| 1193 | } |
| 1194 | } |
| 1195 | |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 1196 | sub output_blockhead_man(%) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | my %args = %{$_[0]}; |
| 1198 | my ($parameter, $section); |
| 1199 | my $count; |
| 1200 | |
| 1201 | print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; |
| 1202 | |
| 1203 | foreach $section (@{$args{'sectionlist'}}) { |
| 1204 | print ".SH \"$section\"\n"; |
| 1205 | output_highlight($args{'sections'}{$section}); |
| 1206 | } |
| 1207 | } |
| 1208 | |
| 1209 | ## |
| 1210 | # output in text |
| 1211 | sub output_function_text(%) { |
| 1212 | my %args = %{$_[0]}; |
| 1213 | my ($parameter, $section); |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1214 | my $start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | |
Randy Dunlap | f47634b | 2006-07-01 04:36:36 -0700 | [diff] [blame] | 1216 | print "Name:\n\n"; |
| 1217 | print $args{'function'}." - ".$args{'purpose'}."\n"; |
| 1218 | |
| 1219 | print "\nSynopsis:\n\n"; |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1220 | if ($args{'functiontype'} ne "") { |
| 1221 | $start = $args{'functiontype'}." ".$args{'function'}." ("; |
| 1222 | } else { |
| 1223 | $start = $args{'function'}." ("; |
| 1224 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | print $start; |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | my $count = 0; |
| 1228 | foreach my $parameter (@{$args{'parameterlist'}}) { |
| 1229 | $type = $args{'parametertypes'}{$parameter}; |
| 1230 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 1231 | # pointer-to-function |
| 1232 | print $1.$parameter.") (".$2; |
| 1233 | } else { |
| 1234 | print $type." ".$parameter; |
| 1235 | } |
| 1236 | if ($count != $#{$args{'parameterlist'}}) { |
| 1237 | $count++; |
| 1238 | print ",\n"; |
| 1239 | print " " x length($start); |
| 1240 | } else { |
| 1241 | print ");\n\n"; |
| 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | print "Arguments:\n\n"; |
| 1246 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1247 | my $parameter_name = $parameter; |
| 1248 | $parameter_name =~ s/\[.*//; |
| 1249 | |
| 1250 | print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n"; |
| 1251 | } |
| 1252 | output_section_text(@_); |
| 1253 | } |
| 1254 | |
| 1255 | #output sections in text |
| 1256 | sub output_section_text(%) { |
| 1257 | my %args = %{$_[0]}; |
| 1258 | my $section; |
| 1259 | |
| 1260 | print "\n"; |
| 1261 | foreach $section (@{$args{'sectionlist'}}) { |
| 1262 | print "$section:\n\n"; |
| 1263 | output_highlight($args{'sections'}{$section}); |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1264 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | print "\n\n"; |
| 1266 | } |
| 1267 | |
| 1268 | # output enum in text |
| 1269 | sub output_enum_text(%) { |
| 1270 | my %args = %{$_[0]}; |
| 1271 | my ($parameter); |
| 1272 | my $count; |
| 1273 | print "Enum:\n\n"; |
| 1274 | |
Randy.Dunlap | 1d7e1d4 | 2006-07-01 04:36:34 -0700 | [diff] [blame] | 1275 | print "enum ".$args{'enum'}." - ".$args{'purpose'}."\n\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1276 | print "enum ".$args{'enum'}." {\n"; |
| 1277 | $count = 0; |
| 1278 | foreach $parameter (@{$args{'parameterlist'}}) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1279 | print "\t$parameter"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | if ($count != $#{$args{'parameterlist'}}) { |
| 1281 | $count++; |
| 1282 | print ","; |
| 1283 | } |
| 1284 | print "\n"; |
| 1285 | } |
| 1286 | print "};\n\n"; |
| 1287 | |
| 1288 | print "Constants:\n\n"; |
| 1289 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1290 | print "$parameter\n\t"; |
| 1291 | print $args{'parameterdescs'}{$parameter}."\n"; |
| 1292 | } |
| 1293 | |
| 1294 | output_section_text(@_); |
| 1295 | } |
| 1296 | |
| 1297 | # output typedef in text |
| 1298 | sub output_typedef_text(%) { |
| 1299 | my %args = %{$_[0]}; |
| 1300 | my ($parameter); |
| 1301 | my $count; |
| 1302 | print "Typedef:\n\n"; |
| 1303 | |
Randy.Dunlap | 1d7e1d4 | 2006-07-01 04:36:34 -0700 | [diff] [blame] | 1304 | print "typedef ".$args{'typedef'}." - ".$args{'purpose'}."\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1305 | output_section_text(@_); |
| 1306 | } |
| 1307 | |
| 1308 | # output struct as text |
| 1309 | sub output_struct_text(%) { |
| 1310 | my %args = %{$_[0]}; |
| 1311 | my ($parameter); |
| 1312 | |
Randy.Dunlap | 1d7e1d4 | 2006-07-01 04:36:34 -0700 | [diff] [blame] | 1313 | print $args{'type'}." ".$args{'struct'}." - ".$args{'purpose'}."\n\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | print $args{'type'}." ".$args{'struct'}." {\n"; |
| 1315 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1316 | if ($parameter =~ /^#/) { |
| 1317 | print "$parameter\n"; |
| 1318 | next; |
| 1319 | } |
| 1320 | |
| 1321 | my $parameter_name = $parameter; |
| 1322 | $parameter_name =~ s/\[.*//; |
| 1323 | |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1324 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | $type = $args{'parametertypes'}{$parameter}; |
| 1326 | if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { |
| 1327 | # pointer-to-function |
| 1328 | print "\t$1 $parameter) ($2);\n"; |
| 1329 | } elsif ($type =~ m/^(.*?)\s*(:.*)/) { |
Randy Dunlap | 51f5a0c | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1330 | # bitfield |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | print "\t$1 $parameter$2;\n"; |
| 1332 | } else { |
| 1333 | print "\t".$type." ".$parameter.";\n"; |
| 1334 | } |
| 1335 | } |
| 1336 | print "};\n\n"; |
| 1337 | |
| 1338 | print "Members:\n\n"; |
| 1339 | foreach $parameter (@{$args{'parameterlist'}}) { |
| 1340 | ($parameter =~ /^#/) && next; |
| 1341 | |
| 1342 | my $parameter_name = $parameter; |
| 1343 | $parameter_name =~ s/\[.*//; |
| 1344 | |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1345 | ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | print "$parameter\n\t"; |
| 1347 | print $args{'parameterdescs'}{$parameter_name}."\n"; |
| 1348 | } |
| 1349 | print "\n"; |
| 1350 | output_section_text(@_); |
| 1351 | } |
| 1352 | |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 1353 | sub output_blockhead_text(%) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | my %args = %{$_[0]}; |
| 1355 | my ($parameter, $section); |
| 1356 | |
| 1357 | foreach $section (@{$args{'sectionlist'}}) { |
| 1358 | print " $section:\n"; |
| 1359 | print " -> "; |
| 1360 | output_highlight($args{'sections'}{$section}); |
| 1361 | } |
| 1362 | } |
| 1363 | |
| 1364 | ## |
Randy Dunlap | 2720574 | 2006-10-11 01:22:12 -0700 | [diff] [blame] | 1365 | # generic output function for all types (function, struct/union, typedef, enum); |
| 1366 | # calls the generated, variable output_ function name based on |
| 1367 | # functype and output_mode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | sub output_declaration { |
| 1369 | no strict 'refs'; |
| 1370 | my $name = shift; |
| 1371 | my $functype = shift; |
| 1372 | my $func = "output_${functype}_$output_mode"; |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1373 | if (($function_only==0) || |
| 1374 | ( $function_only == 1 && defined($function_table{$name})) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | ( $function_only == 2 && !defined($function_table{$name}))) |
| 1376 | { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1377 | &$func(@_); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | $section_counter++; |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | ## |
Randy Dunlap | 2720574 | 2006-10-11 01:22:12 -0700 | [diff] [blame] | 1383 | # generic output function - calls the right one based on current output mode. |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 1384 | sub output_blockhead { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | no strict 'refs'; |
Johannes Berg | b112e0f | 2007-10-24 15:08:48 -0700 | [diff] [blame] | 1386 | my $func = "output_blockhead_".$output_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | &$func(@_); |
| 1388 | $section_counter++; |
| 1389 | } |
| 1390 | |
| 1391 | ## |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1392 | # takes a declaration (struct, union, enum, typedef) and |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | # invokes the right handler. NOT called for functions. |
| 1394 | sub dump_declaration($$) { |
| 1395 | no strict 'refs'; |
| 1396 | my ($prototype, $file) = @_; |
| 1397 | my $func = "dump_".$decl_type; |
| 1398 | &$func(@_); |
| 1399 | } |
| 1400 | |
| 1401 | sub dump_union($$) { |
| 1402 | dump_struct(@_); |
| 1403 | } |
| 1404 | |
| 1405 | sub dump_struct($$) { |
| 1406 | my $x = shift; |
| 1407 | my $file = shift; |
| 1408 | |
| 1409 | if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1410 | $declaration_name = $2; |
| 1411 | my $members = $3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | |
| 1413 | # ignore embedded structs or unions |
Randy Dunlap | 32ab8f9 | 2008-08-05 13:01:32 -0700 | [diff] [blame] | 1414 | $members =~ s/{.*}//g; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | |
Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 1416 | # ignore members marked private: |
| 1417 | $members =~ s/\/\*.*?private:.*?public:.*?\*\///gos; |
| 1418 | $members =~ s/\/\*.*?private:.*//gos; |
| 1419 | # strip comments: |
| 1420 | $members =~ s/\/\*.*?\*\///gos; |
| 1421 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | create_parameterlist($members, ';', $file); |
| 1423 | |
| 1424 | output_declaration($declaration_name, |
| 1425 | 'struct', |
| 1426 | {'struct' => $declaration_name, |
| 1427 | 'module' => $modulename, |
| 1428 | 'parameterlist' => \@parameterlist, |
| 1429 | 'parameterdescs' => \%parameterdescs, |
| 1430 | 'parametertypes' => \%parametertypes, |
| 1431 | 'sectionlist' => \@sectionlist, |
| 1432 | 'sections' => \%sections, |
| 1433 | 'purpose' => $declaration_purpose, |
| 1434 | 'type' => $decl_type |
| 1435 | }); |
| 1436 | } |
| 1437 | else { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1438 | print STDERR "Error(${file}:$.): Cannot parse struct or union!\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | ++$errors; |
| 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | sub dump_enum($$) { |
| 1444 | my $x = shift; |
| 1445 | my $file = shift; |
| 1446 | |
Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 1447 | $x =~ s@/\*.*?\*/@@gos; # strip comments. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1449 | $declaration_name = $1; |
| 1450 | my $members = $2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | |
| 1452 | foreach my $arg (split ',', $members) { |
| 1453 | $arg =~ s/^\s*(\w+).*/$1/; |
| 1454 | push @parameterlist, $arg; |
| 1455 | if (!$parameterdescs{$arg}) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1456 | $parameterdescs{$arg} = $undescribed; |
| 1457 | print STDERR "Warning(${file}:$.): Enum value '$arg' ". |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | "not described in enum '$declaration_name'\n"; |
| 1459 | } |
| 1460 | |
| 1461 | } |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1462 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | output_declaration($declaration_name, |
| 1464 | 'enum', |
| 1465 | {'enum' => $declaration_name, |
| 1466 | 'module' => $modulename, |
| 1467 | 'parameterlist' => \@parameterlist, |
| 1468 | 'parameterdescs' => \%parameterdescs, |
| 1469 | 'sectionlist' => \@sectionlist, |
| 1470 | 'sections' => \%sections, |
| 1471 | 'purpose' => $declaration_purpose |
| 1472 | }); |
| 1473 | } |
| 1474 | else { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1475 | print STDERR "Error(${file}:$.): Cannot parse enum!\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | ++$errors; |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | sub dump_typedef($$) { |
| 1481 | my $x = shift; |
| 1482 | my $file = shift; |
| 1483 | |
Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 1484 | $x =~ s@/\*.*?\*/@@gos; # strip comments. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1486 | $x =~ s/\(*.\)\s*;$/;/; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | $x =~ s/\[*.\]\s*;$/;/; |
| 1488 | } |
| 1489 | |
| 1490 | if ($x =~ /typedef.*\s+(\w+)\s*;/) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1491 | $declaration_name = $1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | |
| 1493 | output_declaration($declaration_name, |
| 1494 | 'typedef', |
| 1495 | {'typedef' => $declaration_name, |
| 1496 | 'module' => $modulename, |
| 1497 | 'sectionlist' => \@sectionlist, |
| 1498 | 'sections' => \%sections, |
| 1499 | 'purpose' => $declaration_purpose |
| 1500 | }); |
| 1501 | } |
| 1502 | else { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1503 | print STDERR "Error(${file}:$.): Cannot parse typedef!\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | ++$errors; |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | sub create_parameterlist($$$) { |
| 1509 | my $args = shift; |
| 1510 | my $splitter = shift; |
| 1511 | my $file = shift; |
| 1512 | my $type; |
| 1513 | my $param; |
| 1514 | |
Martin Waitz | a6d3fe7 | 2006-01-09 20:53:55 -0800 | [diff] [blame] | 1515 | # temporarily replace commas inside function pointer definition |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | while ($args =~ /(\([^\),]+),/) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1517 | $args =~ s/(\([^\),]+),/$1#/g; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | } |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1519 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | foreach my $arg (split($splitter, $args)) { |
| 1521 | # strip comments |
| 1522 | $arg =~ s/\/\*.*\*\///; |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1523 | # strip leading/trailing spaces |
| 1524 | $arg =~ s/^\s*//; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | $arg =~ s/\s*$//; |
| 1526 | $arg =~ s/\s+/ /; |
| 1527 | |
| 1528 | if ($arg =~ /^#/) { |
| 1529 | # Treat preprocessor directive as a typeless variable just to fill |
| 1530 | # corresponding data structures "correctly". Catch it later in |
| 1531 | # output_* subs. |
| 1532 | push_parameter($arg, "", $file); |
Richard Kennedy | 00d6296 | 2008-02-23 15:24:01 -0800 | [diff] [blame] | 1533 | } elsif ($arg =~ m/\(.+\)\s*\(/) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | # pointer-to-function |
| 1535 | $arg =~ tr/#/,/; |
Richard Kennedy | 00d6296 | 2008-02-23 15:24:01 -0800 | [diff] [blame] | 1536 | $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | $param = $1; |
| 1538 | $type = $arg; |
Richard Kennedy | 00d6296 | 2008-02-23 15:24:01 -0800 | [diff] [blame] | 1539 | $type =~ s/([^\(]+\(\*?)\s*$param/$1/; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | push_parameter($param, $type, $file); |
Martin Waitz | aeec46b | 2005-11-13 16:08:13 -0800 | [diff] [blame] | 1541 | } elsif ($arg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | $arg =~ s/\s*:\s*/:/g; |
| 1543 | $arg =~ s/\s*\[/\[/g; |
| 1544 | |
| 1545 | my @args = split('\s*,\s*', $arg); |
| 1546 | if ($args[0] =~ m/\*/) { |
| 1547 | $args[0] =~ s/(\*+)\s*/ $1/; |
| 1548 | } |
Borislav Petkov | 884f281 | 2007-05-08 00:29:05 -0700 | [diff] [blame] | 1549 | |
| 1550 | my @first_arg; |
| 1551 | if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { |
| 1552 | shift @args; |
| 1553 | push(@first_arg, split('\s+', $1)); |
| 1554 | push(@first_arg, $2); |
| 1555 | } else { |
| 1556 | @first_arg = split('\s+', shift @args); |
| 1557 | } |
| 1558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | unshift(@args, pop @first_arg); |
| 1560 | $type = join " ", @first_arg; |
| 1561 | |
| 1562 | foreach $param (@args) { |
| 1563 | if ($param =~ m/^(\*+)\s*(.*)/) { |
| 1564 | push_parameter($2, "$type $1", $file); |
| 1565 | } |
| 1566 | elsif ($param =~ m/(.*?):(\d+)/) { |
Randy Dunlap | 7b97887 | 2008-05-16 15:45:52 -0700 | [diff] [blame] | 1567 | if ($type ne "") { # skip unnamed bit-fields |
| 1568 | push_parameter($1, "$type:$2", $file) |
| 1569 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | } |
| 1571 | else { |
| 1572 | push_parameter($param, $type, $file); |
| 1573 | } |
| 1574 | } |
| 1575 | } |
| 1576 | } |
| 1577 | } |
| 1578 | |
| 1579 | sub push_parameter($$$) { |
| 1580 | my $param = shift; |
| 1581 | my $type = shift; |
| 1582 | my $file = shift; |
| 1583 | |
Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1584 | if (($anon_struct_union == 1) && ($type eq "") && |
| 1585 | ($param eq "}")) { |
| 1586 | return; # ignore the ending }; from anon. struct/union |
| 1587 | } |
| 1588 | |
| 1589 | $anon_struct_union = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | my $param_name = $param; |
| 1591 | $param_name =~ s/\[.*//; |
| 1592 | |
Martin Waitz | a6d3fe7 | 2006-01-09 20:53:55 -0800 | [diff] [blame] | 1593 | if ($type eq "" && $param =~ /\.\.\.$/) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | { |
Randy Dunlap | ced6909 | 2008-12-01 13:14:03 -0800 | [diff] [blame^] | 1595 | if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { |
| 1596 | $parameterdescs{$param} = "variable arguments"; |
| 1597 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | } |
| 1599 | elsif ($type eq "" && ($param eq "" or $param eq "void")) |
| 1600 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | $param="void"; |
| 1602 | $parameterdescs{void} = "no arguments"; |
| 1603 | } |
Randy Dunlap | 134fe01 | 2006-12-22 01:10:50 -0800 | [diff] [blame] | 1604 | elsif ($type eq "" && ($param eq "struct" or $param eq "union")) |
| 1605 | # handle unnamed (anonymous) union or struct: |
| 1606 | { |
| 1607 | $type = $param; |
Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1608 | $param = "{unnamed_" . $param . "}"; |
Randy Dunlap | 134fe01 | 2006-12-22 01:10:50 -0800 | [diff] [blame] | 1609 | $parameterdescs{$param} = "anonymous\n"; |
Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1610 | $anon_struct_union = 1; |
Randy Dunlap | 134fe01 | 2006-12-22 01:10:50 -0800 | [diff] [blame] | 1611 | } |
| 1612 | |
Martin Waitz | a6d3fe7 | 2006-01-09 20:53:55 -0800 | [diff] [blame] | 1613 | # warn if parameter has no description |
Randy Dunlap | 134fe01 | 2006-12-22 01:10:50 -0800 | [diff] [blame] | 1614 | # (but ignore ones starting with # as these are not parameters |
| 1615 | # but inline preprocessor statements); |
| 1616 | # also ignore unnamed structs/unions; |
Randy Dunlap | 5f8c7c9 | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1617 | if (!$anon_struct_union) { |
Martin Waitz | a6d3fe7 | 2006-01-09 20:53:55 -0800 | [diff] [blame] | 1618 | if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { |
| 1619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | $parameterdescs{$param_name} = $undescribed; |
| 1621 | |
| 1622 | if (($type eq 'function') || ($type eq 'enum')) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1623 | print STDERR "Warning(${file}:$.): Function parameter ". |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | "or member '$param' not " . |
| 1625 | "described in '$declaration_name'\n"; |
| 1626 | } |
| 1627 | print STDERR "Warning(${file}:$.):". |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1628 | " No description found for parameter '$param'\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1629 | ++$warnings; |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1630 | } |
| 1631 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | |
| 1633 | push @parameterlist, $param; |
| 1634 | $parametertypes{$param} = $type; |
| 1635 | } |
| 1636 | |
| 1637 | ## |
| 1638 | # takes a function prototype and the name of the current file being |
| 1639 | # processed and spits out all the details stored in the global |
| 1640 | # arrays/hashes. |
| 1641 | sub dump_function($$) { |
| 1642 | my $prototype = shift; |
| 1643 | my $file = shift; |
| 1644 | |
| 1645 | $prototype =~ s/^static +//; |
| 1646 | $prototype =~ s/^extern +//; |
Pavel Pisa | 4dc3b16 | 2005-05-01 08:59:25 -0700 | [diff] [blame] | 1647 | $prototype =~ s/^asmlinkage +//; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | $prototype =~ s/^inline +//; |
| 1649 | $prototype =~ s/^__inline__ +//; |
Randy Dunlap | 32e7940 | 2006-10-11 01:22:10 -0700 | [diff] [blame] | 1650 | $prototype =~ s/^__inline +//; |
| 1651 | $prototype =~ s/^__always_inline +//; |
| 1652 | $prototype =~ s/^noinline +//; |
Randy Dunlap | 0129a05 | 2006-07-30 03:03:41 -0700 | [diff] [blame] | 1653 | $prototype =~ s/__devinit +//; |
Randy Dunlap | 74fc5c6 | 2008-06-19 16:03:29 -0700 | [diff] [blame] | 1654 | $prototype =~ s/__init +//; |
Randy Dunlap | 890c78c | 2008-10-25 17:06:43 -0700 | [diff] [blame] | 1655 | $prototype =~ s/^#\s*define\s+//; #ak added |
Randy Dunlap | 328d244 | 2007-02-28 20:12:10 -0800 | [diff] [blame] | 1656 | $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | |
| 1658 | # Yes, this truly is vile. We are looking for: |
| 1659 | # 1. Return type (may be nothing if we're looking at a macro) |
| 1660 | # 2. Function name |
| 1661 | # 3. Function parameters. |
| 1662 | # |
| 1663 | # All the while we have to watch out for function pointer parameters |
| 1664 | # (which IIRC is what the two sections are for), C types (these |
| 1665 | # regexps don't even start to express all the possibilities), and |
| 1666 | # so on. |
| 1667 | # |
| 1668 | # If you mess with these regexps, it's a good idea to check that |
| 1669 | # the following functions' documentation still comes out right: |
| 1670 | # - parport_register_device (function pointer parameters) |
| 1671 | # - atomic_set (macro) |
Martin Waitz | 9598f91 | 2006-02-01 03:06:55 -0800 | [diff] [blame] | 1672 | # - pci_match_device, __copy_to_user (long return type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | |
| 1674 | if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
| 1675 | $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
| 1676 | $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
| 1677 | $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
Randy Dunlap | 94b3e03 | 2008-02-07 00:13:26 -0800 | [diff] [blame] | 1678 | $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1679 | $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
| 1680 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || |
| 1681 | $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
| 1682 | $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
| 1683 | $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
| 1684 | $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
| 1685 | $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
| 1686 | $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] | 1687 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
| 1688 | $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] | 1689 | $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || |
| 1690 | $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] | 1691 | $return_type = $1; |
| 1692 | $declaration_name = $2; |
| 1693 | my $args = $3; |
| 1694 | |
| 1695 | create_parameterlist($args, ',', $file); |
| 1696 | } else { |
| 1697 | print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n"; |
| 1698 | ++$errors; |
| 1699 | return; |
| 1700 | } |
| 1701 | |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1702 | output_declaration($declaration_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | 'function', |
| 1704 | {'function' => $declaration_name, |
| 1705 | 'module' => $modulename, |
| 1706 | 'functiontype' => $return_type, |
| 1707 | 'parameterlist' => \@parameterlist, |
| 1708 | 'parameterdescs' => \%parameterdescs, |
| 1709 | 'parametertypes' => \%parametertypes, |
| 1710 | 'sectionlist' => \@sectionlist, |
| 1711 | 'sections' => \%sections, |
| 1712 | 'purpose' => $declaration_purpose |
| 1713 | }); |
| 1714 | } |
| 1715 | |
| 1716 | sub process_file($); |
| 1717 | |
| 1718 | # Read the file that maps relative names to absolute names for |
| 1719 | # separate source and object directories and for shadow trees. |
| 1720 | if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { |
| 1721 | my ($relname, $absname); |
| 1722 | while(<SOURCE_MAP>) { |
| 1723 | chop(); |
| 1724 | ($relname, $absname) = (split())[0..1]; |
| 1725 | $relname =~ s:^/+::; |
| 1726 | $source_map{$relname} = $absname; |
| 1727 | } |
| 1728 | close(SOURCE_MAP); |
| 1729 | } |
| 1730 | |
| 1731 | if ($filelist) { |
| 1732 | open(FLIST,"<$filelist") or die "Can't open file list $filelist"; |
| 1733 | while(<FLIST>) { |
| 1734 | chop; |
| 1735 | process_file($_); |
| 1736 | } |
| 1737 | } |
| 1738 | |
| 1739 | foreach (@ARGV) { |
| 1740 | chomp; |
| 1741 | process_file($_); |
| 1742 | } |
| 1743 | if ($verbose && $errors) { |
| 1744 | print STDERR "$errors errors\n"; |
| 1745 | } |
| 1746 | if ($verbose && $warnings) { |
| 1747 | print STDERR "$warnings warnings\n"; |
| 1748 | } |
| 1749 | |
| 1750 | exit($errors); |
| 1751 | |
| 1752 | sub reset_state { |
| 1753 | $function = ""; |
| 1754 | %constants = (); |
| 1755 | %parameterdescs = (); |
| 1756 | %parametertypes = (); |
| 1757 | @parameterlist = (); |
| 1758 | %sections = (); |
| 1759 | @sectionlist = (); |
| 1760 | $prototype = ""; |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1761 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | $state = 0; |
| 1763 | } |
| 1764 | |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1765 | sub process_state3_function($$) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | my $x = shift; |
| 1767 | my $file = shift; |
| 1768 | |
Randy Dunlap | 51f5a0c | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1769 | $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line |
| 1770 | |
Randy Dunlap | 890c78c | 2008-10-25 17:06:43 -0700 | [diff] [blame] | 1771 | if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | # do nothing |
| 1773 | } |
| 1774 | elsif ($x =~ /([^\{]*)/) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1775 | $prototype .= $1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | } |
Randy Dunlap | 890c78c | 2008-10-25 17:06:43 -0700 | [diff] [blame] | 1777 | if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1778 | $prototype =~ s@/\*.*?\*/@@gos; # strip comments. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. |
| 1780 | $prototype =~ s@^\s+@@gos; # strip leading spaces |
| 1781 | dump_function($prototype,$file); |
| 1782 | reset_state(); |
| 1783 | } |
| 1784 | } |
| 1785 | |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1786 | sub process_state3_type($$) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | my $x = shift; |
| 1788 | my $file = shift; |
| 1789 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. |
| 1791 | $x =~ s@^\s+@@gos; # strip leading spaces |
| 1792 | $x =~ s@\s+$@@gos; # strip trailing spaces |
Randy Dunlap | 51f5a0c | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1793 | $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line |
| 1794 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | if ($x =~ /^#/) { |
| 1796 | # To distinguish preprocessor directive from regular declaration later. |
| 1797 | $x .= ";"; |
| 1798 | } |
| 1799 | |
| 1800 | while (1) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1801 | if ( $x =~ /([^{};]*)([{};])(.*)/ ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | $prototype .= $1 . $2; |
| 1803 | ($2 eq '{') && $brcount++; |
| 1804 | ($2 eq '}') && $brcount--; |
| 1805 | if (($2 eq ';') && ($brcount == 0)) { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1806 | dump_declaration($prototype,$file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | reset_state(); |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1808 | last; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1809 | } |
| 1810 | $x = $3; |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1811 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | $prototype .= $x; |
| 1813 | last; |
| 1814 | } |
| 1815 | } |
| 1816 | } |
| 1817 | |
Randy Dunlap | 6b5b55f | 2007-10-16 23:31:20 -0700 | [diff] [blame] | 1818 | # xml_escape: replace <, >, and & in the text stream; |
| 1819 | # |
| 1820 | # however, formatting controls that are generated internally/locally in the |
| 1821 | # kernel-doc script are not escaped here; instead, they begin life like |
| 1822 | # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings |
| 1823 | # are converted to their mnemonic-expected output, without the 4 * '\' & ':', |
| 1824 | # just before actual output; (this is done by local_unescape()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | sub xml_escape($) { |
| 1826 | my $text = shift; |
Randy Dunlap | ecfb251 | 2006-06-25 05:49:13 -0700 | [diff] [blame] | 1827 | if (($output_mode eq "text") || ($output_mode eq "man")) { |
| 1828 | return $text; |
| 1829 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | $text =~ s/\&/\\\\\\amp;/g; |
| 1831 | $text =~ s/\</\\\\\\lt;/g; |
| 1832 | $text =~ s/\>/\\\\\\gt;/g; |
| 1833 | return $text; |
| 1834 | } |
| 1835 | |
Randy Dunlap | 6b5b55f | 2007-10-16 23:31:20 -0700 | [diff] [blame] | 1836 | # convert local escape strings to html |
| 1837 | # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) |
| 1838 | sub local_unescape($) { |
| 1839 | my $text = shift; |
| 1840 | if (($output_mode eq "text") || ($output_mode eq "man")) { |
| 1841 | return $text; |
| 1842 | } |
| 1843 | $text =~ s/\\\\\\\\lt:/</g; |
| 1844 | $text =~ s/\\\\\\\\gt:/>/g; |
| 1845 | return $text; |
| 1846 | } |
| 1847 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | sub process_file($) { |
Randy Dunlap | 2283a11 | 2005-07-07 15:39:26 -0700 | [diff] [blame] | 1849 | my $file; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | my $identifier; |
| 1851 | my $func; |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1852 | my $descr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | my $initial_section_counter = $section_counter; |
| 1854 | |
Randy Dunlap | 2283a11 | 2005-07-07 15:39:26 -0700 | [diff] [blame] | 1855 | if (defined($ENV{'SRCTREE'})) { |
| 1856 | $file = "$ENV{'SRCTREE'}" . "/" . "@_"; |
| 1857 | } |
| 1858 | else { |
| 1859 | $file = "@_"; |
| 1860 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | if (defined($source_map{$file})) { |
| 1862 | $file = $source_map{$file}; |
| 1863 | } |
| 1864 | |
| 1865 | if (!open(IN,"<$file")) { |
| 1866 | print STDERR "Error: Cannot open file $file\n"; |
| 1867 | ++$errors; |
| 1868 | return; |
| 1869 | } |
| 1870 | |
| 1871 | $section_counter = 0; |
| 1872 | while (<IN>) { |
| 1873 | if ($state == 0) { |
| 1874 | if (/$doc_start/o) { |
| 1875 | $state = 1; # next line is always the function name |
Randy Dunlap | 850622d | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 1876 | $in_doc_sect = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | } |
| 1878 | } elsif ($state == 1) { # this line is the function name (always) |
| 1879 | if (/$doc_block/o) { |
| 1880 | $state = 4; |
| 1881 | $contents = ""; |
| 1882 | if ( $1 eq "" ) { |
| 1883 | $section = $section_intro; |
| 1884 | } else { |
| 1885 | $section = $1; |
| 1886 | } |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1887 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | elsif (/$doc_decl/o) { |
| 1889 | $identifier = $1; |
| 1890 | if (/\s*([\w\s]+?)\s*-/) { |
| 1891 | $identifier = $1; |
| 1892 | } |
| 1893 | |
| 1894 | $state = 2; |
| 1895 | if (/-(.*)/) { |
Randy Dunlap | 51f5a0c | 2007-07-19 01:48:24 -0700 | [diff] [blame] | 1896 | # strip leading/trailing/multiple spaces |
Randy Dunlap | a21217d | 2007-02-10 01:46:04 -0800 | [diff] [blame] | 1897 | $descr= $1; |
| 1898 | $descr =~ s/^\s*//; |
| 1899 | $descr =~ s/\s*$//; |
| 1900 | $descr =~ s/\s+/ /; |
| 1901 | $declaration_purpose = xml_escape($descr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | } else { |
| 1903 | $declaration_purpose = ""; |
| 1904 | } |
Randy Dunlap | 77cc23b | 2008-02-07 00:13:42 -0800 | [diff] [blame] | 1905 | |
| 1906 | if (($declaration_purpose eq "") && $verbose) { |
| 1907 | print STDERR "Warning(${file}:$.): missing initial short description on line:\n"; |
| 1908 | print STDERR $_; |
| 1909 | ++$warnings; |
| 1910 | } |
| 1911 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | if ($identifier =~ m/^struct/) { |
| 1913 | $decl_type = 'struct'; |
| 1914 | } elsif ($identifier =~ m/^union/) { |
| 1915 | $decl_type = 'union'; |
| 1916 | } elsif ($identifier =~ m/^enum/) { |
| 1917 | $decl_type = 'enum'; |
| 1918 | } elsif ($identifier =~ m/^typedef/) { |
| 1919 | $decl_type = 'typedef'; |
| 1920 | } else { |
| 1921 | $decl_type = 'function'; |
| 1922 | } |
| 1923 | |
| 1924 | if ($verbose) { |
| 1925 | print STDERR "Info(${file}:$.): Scanning doc for $identifier\n"; |
| 1926 | } |
| 1927 | } else { |
| 1928 | print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.", |
| 1929 | " - I thought it was a doc line\n"; |
| 1930 | ++$warnings; |
| 1931 | $state = 0; |
| 1932 | } |
| 1933 | } elsif ($state == 2) { # look for head: lines, and include content |
| 1934 | if (/$doc_sect/o) { |
| 1935 | $newsection = $1; |
| 1936 | $newcontents = $2; |
| 1937 | |
Randy Dunlap | 792aa2f | 2008-02-07 00:13:41 -0800 | [diff] [blame] | 1938 | if (($contents ne "") && ($contents ne "\n")) { |
Randy Dunlap | 850622d | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 1939 | if (!$in_doc_sect && $verbose) { |
| 1940 | print STDERR "Warning(${file}:$.): contents before sections\n"; |
| 1941 | ++$warnings; |
| 1942 | } |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 1943 | dump_section($file, $section, xml_escape($contents)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | $section = $section_default; |
| 1945 | } |
| 1946 | |
Randy Dunlap | 850622d | 2006-06-25 05:48:55 -0700 | [diff] [blame] | 1947 | $in_doc_sect = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | $contents = $newcontents; |
| 1949 | if ($contents ne "") { |
Randy Dunlap | 2720574 | 2006-10-11 01:22:12 -0700 | [diff] [blame] | 1950 | while ((substr($contents, 0, 1) eq " ") || |
| 1951 | substr($contents, 0, 1) eq "\t") { |
| 1952 | $contents = substr($contents, 1); |
Randy Dunlap | 0518949 | 2006-06-25 05:47:47 -0700 | [diff] [blame] | 1953 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | $contents .= "\n"; |
| 1955 | } |
| 1956 | $section = $newsection; |
| 1957 | } elsif (/$doc_end/) { |
| 1958 | |
| 1959 | if ($contents ne "") { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 1960 | dump_section($file, $section, xml_escape($contents)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | $section = $section_default; |
| 1962 | $contents = ""; |
| 1963 | } |
Randy Dunlap | 46b958e | 2008-04-28 02:16:35 -0700 | [diff] [blame] | 1964 | # look for doc_com + <text> + doc_end: |
| 1965 | if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { |
| 1966 | print STDERR "Warning(${file}:$.): suspicious ending line: $_"; |
| 1967 | ++$warnings; |
| 1968 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | |
| 1970 | $prototype = ""; |
| 1971 | $state = 3; |
| 1972 | $brcount = 0; |
Randy Dunlap | 232acbc | 2006-06-25 05:47:48 -0700 | [diff] [blame] | 1973 | # print STDERR "end of doc comment, looking for prototype\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1974 | } elsif (/$doc_content/) { |
| 1975 | # miguel-style comment kludge, look for blank lines after |
| 1976 | # @parameter line to signify start of description |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1977 | if ($1 eq "" && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | ($section =~ m/^@/ || $section eq $section_context)) { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 1979 | dump_section($file, $section, xml_escape($contents)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | $section = $section_default; |
| 1981 | $contents = ""; |
| 1982 | } else { |
| 1983 | $contents .= $1."\n"; |
| 1984 | } |
| 1985 | } else { |
| 1986 | # i dont know - bad line? ignore. |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 1987 | print STDERR "Warning(${file}:$.): bad line: $_"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | ++$warnings; |
| 1989 | } |
Randy Dunlap | 232acbc | 2006-06-25 05:47:48 -0700 | [diff] [blame] | 1990 | } elsif ($state == 3) { # scanning for function '{' (end of prototype) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | if ($decl_type eq 'function') { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1992 | process_state3_function($_, $file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1993 | } else { |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1994 | process_state3_type($_, $file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | } |
| 1996 | } elsif ($state == 4) { |
| 1997 | # Documentation block |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 1998 | if (/$doc_block/) { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 1999 | dump_doc_section($file, $section, xml_escape($contents)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | $contents = ""; |
| 2001 | $function = ""; |
| 2002 | %constants = (); |
| 2003 | %parameterdescs = (); |
| 2004 | %parametertypes = (); |
| 2005 | @parameterlist = (); |
| 2006 | %sections = (); |
| 2007 | @sectionlist = (); |
| 2008 | $prototype = ""; |
| 2009 | if ( $1 eq "" ) { |
| 2010 | $section = $section_intro; |
| 2011 | } else { |
| 2012 | $section = $1; |
| 2013 | } |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2014 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2015 | elsif (/$doc_end/) |
| 2016 | { |
Randy Dunlap | 94dc7ad | 2008-04-28 02:16:34 -0700 | [diff] [blame] | 2017 | dump_doc_section($file, $section, xml_escape($contents)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | $contents = ""; |
| 2019 | $function = ""; |
| 2020 | %constants = (); |
| 2021 | %parameterdescs = (); |
| 2022 | %parametertypes = (); |
| 2023 | @parameterlist = (); |
| 2024 | %sections = (); |
| 2025 | @sectionlist = (); |
| 2026 | $prototype = ""; |
| 2027 | $state = 0; |
| 2028 | } |
| 2029 | elsif (/$doc_content/) |
| 2030 | { |
| 2031 | if ( $1 eq "" ) |
| 2032 | { |
| 2033 | $contents .= $blankline; |
| 2034 | } |
| 2035 | else |
| 2036 | { |
| 2037 | $contents .= $1 . "\n"; |
Randy Dunlap | 3c3b809 | 2006-02-01 03:06:58 -0800 | [diff] [blame] | 2038 | } |
Randy Dunlap | 3c30879 | 2007-05-08 00:24:39 -0700 | [diff] [blame] | 2039 | } |
| 2040 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | } |
| 2042 | if ($initial_section_counter == $section_counter) { |
| 2043 | print STDERR "Warning(${file}): no structured comments found\n"; |
| 2044 | if ($output_mode eq "xml") { |
| 2045 | # The template wants at least one RefEntry here; make one. |
| 2046 | print "<refentry>\n"; |
| 2047 | print " <refnamediv>\n"; |
| 2048 | print " <refname>\n"; |
| 2049 | print " ${file}\n"; |
| 2050 | print " </refname>\n"; |
| 2051 | print " <refpurpose>\n"; |
| 2052 | print " Document generation inconsistency\n"; |
| 2053 | print " </refpurpose>\n"; |
| 2054 | print " </refnamediv>\n"; |
| 2055 | print " <refsect1>\n"; |
| 2056 | print " <title>\n"; |
| 2057 | print " Oops\n"; |
| 2058 | print " </title>\n"; |
| 2059 | print " <warning>\n"; |
| 2060 | print " <para>\n"; |
| 2061 | print " The template for this document tried to insert\n"; |
| 2062 | print " the structured comment from the file\n"; |
| 2063 | print " <filename>${file}</filename> at this point,\n"; |
| 2064 | print " but none was found.\n"; |
| 2065 | print " This dummy section is inserted to allow\n"; |
| 2066 | print " generation to continue.\n"; |
| 2067 | print " </para>\n"; |
| 2068 | print " </warning>\n"; |
| 2069 | print " </refsect1>\n"; |
| 2070 | print "</refentry>\n"; |
| 2071 | } |
| 2072 | } |
| 2073 | } |