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