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