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