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