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