1 #!/usr/bin/env perl !! 1 #!/usr/bin/perl -w 2 # SPDX-License-Identifier: GPL-2.0 << 3 # vim: softtabstop=4 << 4 2 5 use warnings; << 6 use strict; 3 use strict; 7 4 8 ## Copyright (c) 1998 Michael Zucchi, All Righ 5 ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ## 9 ## Copyright (C) 2000, 1 Tim Waugh <twaugh@red 6 ## Copyright (C) 2000, 1 Tim Waugh <twaugh@redhat.com> ## 10 ## Copyright (C) 2001 Simon Huggins 7 ## Copyright (C) 2001 Simon Huggins ## 11 ## Copyright (C) 2005-2012 Randy Dunlap 8 ## Copyright (C) 2005-2012 Randy Dunlap ## 12 ## Copyright (C) 2012 Dan Luedtke 9 ## Copyright (C) 2012 Dan Luedtke ## 13 ## 10 ## ## 14 ## #define enhancements by Armin Kuster <akuste 11 ## #define enhancements by Armin Kuster <akuster@mvista.com> ## 15 ## Copyright (c) 2000 MontaVista Software, Inc 12 ## Copyright (c) 2000 MontaVista Software, Inc. ## 16 # !! 13 ## ## 17 # Copyright (C) 2022 Tomasz Warniełło (POD) !! 14 ## This software falls under the GNU General Public License. ## 18 !! 15 ## Please read the COPYING file for more information ## 19 use Pod::Usage qw/pod2usage/; << 20 << 21 =head1 NAME << 22 << 23 kernel-doc - Print formatted kernel documentat << 24 << 25 =head1 SYNOPSIS << 26 << 27 kernel-doc [-h] [-v] [-Werror] [-Wall] [-Wret << 28 [ -man | << 29 -rst [-sphinx-version VERSION] [-enable-l << 30 -none << 31 ] << 32 [ << 33 -export | << 34 -internal | << 35 [-function NAME] ... | << 36 [-nosymbol NAME] ... << 37 ] << 38 [-no-doc-sections] << 39 [-export-file FILE] ... << 40 FILE ... << 41 << 42 Run `kernel-doc -h` for details. << 43 16 44 =head1 DESCRIPTION !! 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 >> 39 # 25/07/2012 - Added support for HTML5 >> 40 # -- Dan Luedtke <mail@danrl.de> >> 41 >> 42 sub usage { >> 43 my $message = <<"EOF"; >> 44 Usage: $0 [OPTION ...] FILE ... 45 45 46 Read C language source or header FILEs, extrac 46 Read C language source or header FILEs, extract embedded documentation comments, 47 and print formatted documentation to standard 47 and print formatted documentation to standard output. 48 48 49 The documentation comments are identified by t !! 49 The documentation comments are identified by "/**" opening comment mark. See 50 !! 50 Documentation/kernel-doc-nano-HOWTO.txt for the documentation comment syntax. 51 See Documentation/doc-guide/kernel-doc.rst for << 52 << 53 =cut << 54 51 55 # more perldoc at the end of the file !! 52 Output format selection (mutually exclusive): >> 53 -docbook Output DocBook format. >> 54 -html Output HTML format. >> 55 -html5 Output HTML5 format. >> 56 -list Output symbol list format. This is for use by docproc. >> 57 -man Output troff manual page format. This is the default. >> 58 -rst Output reStructuredText format. >> 59 -text Output plain text format. >> 60 >> 61 Output selection (mutually exclusive): >> 62 -export Only output documentation for symbols that have been >> 63 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() >> 64 in any input FILE or -export-file FILE. >> 65 -internal Only output documentation for symbols that have NOT been >> 66 exported using EXPORT_SYMBOL() or EXPORT_SYMBOL_GPL() >> 67 in any input FILE or -export-file FILE. >> 68 -function NAME Only output documentation for the given function(s) >> 69 or DOC: section title(s). All other functions and DOC: >> 70 sections are ignored. May be specified multiple times. >> 71 -nofunction NAME Do NOT output documentation for the given function(s); >> 72 only output documentation for the other functions and >> 73 DOC: sections. May be specified multiple times. >> 74 >> 75 Output selection modifiers: >> 76 -no-doc-sections Do not output DOC: sections. >> 77 -enable-lineno Enable output of #define LINENO lines. Only works with >> 78 reStructuredText format. >> 79 -export-file FILE Specify an additional FILE in which to look for >> 80 EXPORT_SYMBOL() and EXPORT_SYMBOL_GPL(). To be used with >> 81 -export or -internal. May be specified multiple times. >> 82 >> 83 Other parameters: >> 84 -v Verbose output, more warnings and other information. >> 85 -h Print this help. >> 86 >> 87 EOF >> 88 print $message; >> 89 exit 1; >> 90 } >> 91 >> 92 # >> 93 # format of comments. >> 94 # In the following table, (...)? signifies optional structure. >> 95 # (...)* signifies 0 or more structure elements >> 96 # /** >> 97 # * function_name(:)? (- short description)? >> 98 # (* @parameterx: (description of parameter x)?)* >> 99 # (* a blank line)? >> 100 # * (Description:)? (Description of function)? >> 101 # * (section header: (section description)? )* >> 102 # (*)?*/ >> 103 # >> 104 # So .. the trivial example would be: >> 105 # >> 106 # /** >> 107 # * my_function >> 108 # */ >> 109 # >> 110 # If the Description: header tag is omitted, then there must be a blank line >> 111 # after the last parameter specification. >> 112 # e.g. >> 113 # /** >> 114 # * my_function - does my stuff >> 115 # * @my_arg: its mine damnit >> 116 # * >> 117 # * Does my stuff explained. >> 118 # */ >> 119 # >> 120 # or, could also use: >> 121 # /** >> 122 # * my_function - does my stuff >> 123 # * @my_arg: its mine damnit >> 124 # * Description: Does my stuff explained. >> 125 # */ >> 126 # etc. >> 127 # >> 128 # Besides functions you can also write documentation for structs, unions, >> 129 # enums and typedefs. Instead of the function name you must write the name >> 130 # of the declaration; the struct/union/enum/typedef must always precede >> 131 # the name. Nesting of declarations is not supported. >> 132 # Use the argument mechanism to document members or constants. >> 133 # e.g. >> 134 # /** >> 135 # * struct my_struct - short description >> 136 # * @a: first member >> 137 # * @b: second member >> 138 # * >> 139 # * Longer description >> 140 # */ >> 141 # struct my_struct { >> 142 # int a; >> 143 # int b; >> 144 # /* private: */ >> 145 # int c; >> 146 # }; >> 147 # >> 148 # All descriptions can be multiline, except the short function description. >> 149 # >> 150 # For really longs structs, you can also describe arguments inside the >> 151 # body of the struct. >> 152 # eg. >> 153 # /** >> 154 # * struct my_struct - short description >> 155 # * @a: first member >> 156 # * @b: second member >> 157 # * >> 158 # * Longer description >> 159 # */ >> 160 # struct my_struct { >> 161 # int a; >> 162 # int b; >> 163 # /** >> 164 # * @c: This is longer description of C >> 165 # * >> 166 # * You can use paragraphs to describe arguments >> 167 # * using this method. >> 168 # */ >> 169 # int c; >> 170 # }; >> 171 # >> 172 # This should be use only for struct/enum members. >> 173 # >> 174 # You can also add additional sections. When documenting kernel functions you >> 175 # should document the "Context:" of the function, e.g. whether the functions >> 176 # can be called form interrupts. Unlike other sections you can end it with an >> 177 # empty line. >> 178 # A non-void function should have a "Return:" section describing the return >> 179 # value(s). >> 180 # Example-sections should contain the string EXAMPLE so that they are marked >> 181 # appropriately in DocBook. >> 182 # >> 183 # Example: >> 184 # /** >> 185 # * user_function - function that can only be called in user context >> 186 # * @a: some argument >> 187 # * Context: !in_interrupt() >> 188 # * >> 189 # * Some description >> 190 # * Example: >> 191 # * user_function(22); >> 192 # */ >> 193 # ... >> 194 # >> 195 # >> 196 # All descriptive text is further processed, scanning for the following special >> 197 # patterns, which are highlighted appropriately. >> 198 # >> 199 # 'funcname()' - function >> 200 # '$ENVVAR' - environmental variable >> 201 # '&struct_name' - name of a structure (up to two words including 'struct') >> 202 # '@parameter' - name of a parameter >> 203 # '%CONST' - name of a constant. 56 204 57 ## init lots of data 205 ## init lots of data 58 206 59 my $errors = 0; 207 my $errors = 0; 60 my $warnings = 0; 208 my $warnings = 0; 61 my $anon_struct_union = 0; 209 my $anon_struct_union = 0; 62 210 63 # match expressions used to find embedded type 211 # match expressions used to find embedded type information 64 my $type_constant = '\b``([^\`]+)``\b'; !! 212 my $type_constant = '\%([-_\w]+)'; 65 my $type_constant2 = '\%([-_*\w]+)'; << 66 my $type_func = '(\w+)\(\)'; 213 my $type_func = '(\w+)\(\)'; 67 my $type_param = '\@(\w*((\.\w+)|(->\w+))*(\.\ !! 214 my $type_param = '\@(\w+)'; 68 my $type_param_ref = '([\!~\*]?)\@(\w*((\.\w+) << 69 my $type_fp_param = '\@(\w+)\(\)'; # Special 215 my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params 70 my $type_fp_param2 = '\@(\w+->\S+)\(\)'; # Sp !! 216 my $type_struct = '\&((struct\s*)*[_\w]+)'; >> 217 my $type_struct_xml = '\\&((struct\s*)*[_\w]+)'; 71 my $type_env = '(\$\w+)'; 218 my $type_env = '(\$\w+)'; 72 my $type_enum = '\&(enum\s*([_\w]+))'; !! 219 my $type_enum_full = '\&(enum)\s*([_\w]+)'; 73 my $type_struct = '\&(struct\s*([_\w]+))'; !! 220 my $type_struct_full = '\&(struct)\s*([_\w]+)'; 74 my $type_typedef = '\&(typedef\s*([_\w]+))'; !! 221 my $type_typedef_full = '\&(typedef)\s*([_\w]+)'; 75 my $type_union = '\&(union\s*([_\w]+))'; !! 222 my $type_union_full = '\&(union)\s*([_\w]+)'; 76 my $type_member = '\&([_\w]+)(\.|->)([_\w]+)'; !! 223 my $type_member = '\&([_\w]+)((\.|->)[_\w]+)'; 77 my $type_fallback = '\&([_\w]+)'; << 78 my $type_member_func = $type_member . '\(\)'; 224 my $type_member_func = $type_member . '\(\)'; 79 225 80 # Output conversion substitutions. 226 # Output conversion substitutions. 81 # One for each output format 227 # One for each output format 82 228 >> 229 # these work fairly well >> 230 my @highlights_html = ( >> 231 [$type_constant, "<i>\$1</i>"], >> 232 [$type_func, "<b>\$1</b>"], >> 233 [$type_struct_xml, "<i>\$1</i>"], >> 234 [$type_env, "<b><i>\$1</i></b>"], >> 235 [$type_param, "<tt><b>\$1</b></tt>"] >> 236 ); >> 237 my $local_lt = "\\\\\\\\lt:"; >> 238 my $local_gt = "\\\\\\\\gt:"; >> 239 my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>" >> 240 >> 241 # html version 5 >> 242 my @highlights_html5 = ( >> 243 [$type_constant, "<span class=\"const\">\$1</span>"], >> 244 [$type_func, "<span class=\"func\">\$1</span>"], >> 245 [$type_struct_xml, "<span class=\"struct\">\$1</span>"], >> 246 [$type_env, "<span class=\"env\">\$1</span>"], >> 247 [$type_param, "<span class=\"param\">\$1</span>]"] >> 248 ); >> 249 my $blankline_html5 = $local_lt . "br /" . $local_gt; >> 250 >> 251 # XML, docbook format >> 252 my @highlights_xml = ( >> 253 ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"], >> 254 [$type_constant, "<constant>\$1</constant>"], >> 255 [$type_struct_xml, "<structname>\$1</structname>"], >> 256 [$type_param, "<parameter>\$1</parameter>"], >> 257 [$type_func, "<function>\$1</function>"], >> 258 [$type_env, "<envar>\$1</envar>"] >> 259 ); >> 260 my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n"; >> 261 >> 262 # gnome, docbook format >> 263 my @highlights_gnome = ( >> 264 [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"], >> 265 [$type_func, "<function>\$1</function>"], >> 266 [$type_struct, "<structname>\$1</structname>"], >> 267 [$type_env, "<envar>\$1</envar>"], >> 268 [$type_param, "<parameter>\$1</parameter>" ] >> 269 ); >> 270 my $blankline_gnome = "</para><para>\n"; >> 271 83 # these are pretty rough 272 # these are pretty rough 84 my @highlights_man = ( 273 my @highlights_man = ( 85 [$type_constant, "\$1"], !! 274 [$type_constant, "\$1"], 86 [$type_constant2, "\$1"], !! 275 [$type_func, "\\\\fB\$1\\\\fP"], 87 [$type_func, "\\\\fB\$1\\\\fP"], !! 276 [$type_struct, "\\\\fI\$1\\\\fP"], 88 [$type_enum, "\\\\fI\$1\\\\fP"], !! 277 [$type_param, "\\\\fI\$1\\\\fP"] 89 [$type_struct, "\\\\fI\$1\\\\fP"], !! 278 ); 90 [$type_typedef, "\\\\fI\$1\\\\fP"], << 91 [$type_union, "\\\\fI\$1\\\\fP"], << 92 [$type_param, "\\\\fI\$1\\\\fP"], << 93 [$type_param_ref, "\\\\fI\$1\$2\\\\fP"], << 94 [$type_member, "\\\\fI\$1\$2\$3\\\\fP"], << 95 [$type_fallback, "\\\\fI\$1\\\\fP"] << 96 ); << 97 my $blankline_man = ""; 279 my $blankline_man = ""; 98 280 >> 281 # text-mode >> 282 my @highlights_text = ( >> 283 [$type_constant, "\$1"], >> 284 [$type_func, "\$1"], >> 285 [$type_struct, "\$1"], >> 286 [$type_param, "\$1"] >> 287 ); >> 288 my $blankline_text = ""; >> 289 99 # rst-mode 290 # rst-mode 100 my @highlights_rst = ( 291 my @highlights_rst = ( 101 [$type_constant, "``\$1``"], !! 292 [$type_constant, "``\$1``"], 102 [$type_constant2, "``\$1``"], !! 293 # Note: need to escape () to avoid func matching later 103 !! 294 [$type_member_func, "\\:c\\:type\\:`\$1\$2\\\\(\\\\) <\$1>`"], 104 # Note: need to escape () to avoid func ma !! 295 [$type_member, "\\:c\\:type\\:`\$1\$2 <\$1>`"], 105 [$type_member_func, "\\:c\\:type\\:`\$1\$2 !! 296 [$type_fp_param, "**\$1\\\\(\\\\)**"], 106 [$type_member, "\\:c\\:type\\:`\$1\$2\$3 < !! 297 [$type_func, "\\:c\\:func\\:`\$1()`"], 107 [$type_fp_param, "**\$1\\\\(\\\\)**"], !! 298 [$type_struct_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 108 [$type_fp_param2, "**\$1\\\\(\\\\)**"], !! 299 [$type_enum_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 109 [$type_func, "\$1()"], !! 300 [$type_typedef_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 110 [$type_enum, "\\:c\\:type\\:`\$1 <\$2>`"], !! 301 [$type_union_full, "\\:c\\:type\\:`\$1 \$2 <\$2>`"], 111 [$type_struct, "\\:c\\:type\\:`\$1 <\$2>`" !! 302 # in rst this can refer to any type 112 [$type_typedef, "\\:c\\:type\\:`\$1 <\$2>` !! 303 [$type_struct, "\\:c\\:type\\:`\$1`"], 113 [$type_union, "\\:c\\:type\\:`\$1 <\$2>`"] !! 304 [$type_param, "**\$1**"] 114 !! 305 ); 115 # in rst this can refer to any type << 116 [$type_fallback, "\\:c\\:type\\:`\$1`"], << 117 [$type_param_ref, "**\$1\$2**"] << 118 ); << 119 my $blankline_rst = "\n"; 306 my $blankline_rst = "\n"; 120 307 >> 308 # list mode >> 309 my @highlights_list = ( >> 310 [$type_constant, "\$1"], >> 311 [$type_func, "\$1"], >> 312 [$type_struct, "\$1"], >> 313 [$type_param, "\$1"] >> 314 ); >> 315 my $blankline_list = ""; >> 316 121 # read arguments 317 # read arguments 122 if ($#ARGV == -1) { 318 if ($#ARGV == -1) { 123 pod2usage( !! 319 usage(); 124 -message => "No arguments!\n", << 125 -exitval => 1, << 126 -verbose => 99, << 127 -sections => 'SYNOPSIS', << 128 -output => \*STDERR, << 129 ); << 130 } 320 } 131 321 132 my $kernelversion; 322 my $kernelversion; 133 my ($sphinx_major, $sphinx_minor, $sphinx_patc << 134 << 135 my $dohighlight = ""; 323 my $dohighlight = ""; 136 324 137 my $verbose = 0; 325 my $verbose = 0; 138 my $Werror = 0; !! 326 my $output_mode = "man"; 139 my $Wreturn = 0; << 140 my $Wshort_desc = 0; << 141 my $Wcontents_before_sections = 0; << 142 my $output_mode = "rst"; << 143 my $output_preformatted = 0; 327 my $output_preformatted = 0; 144 my $no_doc_sections = 0; 328 my $no_doc_sections = 0; 145 my $enable_lineno = 0; 329 my $enable_lineno = 0; 146 my @highlights = @highlights_rst; !! 330 my @highlights = @highlights_man; 147 my $blankline = $blankline_rst; !! 331 my $blankline = $blankline_man; 148 my $modulename = "Kernel API"; 332 my $modulename = "Kernel API"; 149 333 150 use constant { 334 use constant { 151 OUTPUT_ALL => 0, # output all sym 335 OUTPUT_ALL => 0, # output all symbols and doc sections 152 OUTPUT_INCLUDE => 1, # output only sp 336 OUTPUT_INCLUDE => 1, # output only specified symbols 153 OUTPUT_EXPORTED => 2, # output exporte !! 337 OUTPUT_EXCLUDE => 2, # output everything except specified symbols 154 OUTPUT_INTERNAL => 3, # output non-exp !! 338 OUTPUT_EXPORTED => 3, # output exported symbols >> 339 OUTPUT_INTERNAL => 4, # output non-exported symbols 155 }; 340 }; 156 my $output_selection = OUTPUT_ALL; 341 my $output_selection = OUTPUT_ALL; 157 my $show_not_found = 0; # No longer used !! 342 my $show_not_found = 0; 158 343 159 my @export_file_list; 344 my @export_file_list; 160 345 161 my @build_time; 346 my @build_time; 162 if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 347 if (defined($ENV{'KBUILD_BUILD_TIMESTAMP'}) && 163 (my $seconds = `date -d"${ENV{'KBUILD_BUIL 348 (my $seconds = `date -d"${ENV{'KBUILD_BUILD_TIMESTAMP'}}" +%s`) ne '') { 164 @build_time = gmtime($seconds); 349 @build_time = gmtime($seconds); 165 } else { 350 } else { 166 @build_time = localtime; 351 @build_time = localtime; 167 } 352 } 168 353 169 my $man_date = ('January', 'February', 'March' 354 my $man_date = ('January', 'February', 'March', 'April', 'May', 'June', 170 'July', 'August', 'September', !! 355 'July', 'August', 'September', 'October', 171 'November', 'December')[$build !! 356 'November', 'December')[$build_time[4]] . 172 " " . ($build_time[5]+1900); !! 357 " " . ($build_time[5]+1900); 173 358 174 # Essentially these are globals. 359 # Essentially these are globals. 175 # They probably want to be tidied up, made mor 360 # They probably want to be tidied up, made more localised or something. 176 # CAVEAT EMPTOR! Some of the others I localis 361 # CAVEAT EMPTOR! Some of the others I localised may not want to be, which 177 # could cause "use of undefined value" or othe 362 # could cause "use of undefined value" or other bugs. 178 my ($function, %function_table, %parametertype 363 my ($function, %function_table, %parametertypes, $declaration_purpose); 179 my %nosymbol_table = (); << 180 my $declaration_start_line; 364 my $declaration_start_line; 181 my ($type, $declaration_name, $return_type); 365 my ($type, $declaration_name, $return_type); 182 my ($newsection, $newcontents, $prototype, $br 366 my ($newsection, $newcontents, $prototype, $brcount, %source_map); 183 367 184 if (defined($ENV{'KBUILD_VERBOSE'}) && $ENV{'K !! 368 if (defined($ENV{'KBUILD_VERBOSE'})) { 185 $verbose = 1; !! 369 $verbose = "$ENV{'KBUILD_VERBOSE'}"; 186 } << 187 << 188 if (defined($ENV{'KCFLAGS'})) { << 189 my $kcflags = "$ENV{'KCFLAGS'}"; << 190 << 191 if ($kcflags =~ /(\s|^)-Werror(\s|$)/) { << 192 $Werror = 1; << 193 } << 194 } 370 } 195 371 196 # reading this variable is for backwards compa << 197 # someone was calling it with the variable fro << 198 # kernel's build system << 199 if (defined($ENV{'KDOC_WERROR'})) { << 200 $Werror = "$ENV{'KDOC_WERROR'}"; << 201 } << 202 # other environment variables are converted to << 203 # arguments in cmd_checkdoc in the build syste << 204 << 205 # Generated docbook code is inserted in a temp 372 # Generated docbook code is inserted in a template at a point where 206 # docbook v3.1 requires a non-zero sequence of 373 # docbook v3.1 requires a non-zero sequence of RefEntry's; see: 207 # https://www.oasis-open.org/docbook/documenta !! 374 # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 208 # We keep track of number of generated entries 375 # We keep track of number of generated entries and generate a dummy 209 # if needs be to ensure the expanded template 376 # if needs be to ensure the expanded template can be postprocessed 210 # into html. 377 # into html. 211 my $section_counter = 0; 378 my $section_counter = 0; 212 379 213 my $lineprefix=""; 380 my $lineprefix=""; 214 381 215 # Parser states 382 # Parser states 216 use constant { 383 use constant { 217 STATE_NORMAL => 0, # normal !! 384 STATE_NORMAL => 0, # normal code 218 STATE_NAME => 1, # looking !! 385 STATE_NAME => 1, # looking for function name 219 STATE_BODY_MAYBE => 2, # body - !! 386 STATE_FIELD => 2, # scanning field start 220 STATE_BODY => 3, # the bod !! 387 STATE_PROTO => 3, # scanning prototype 221 STATE_BODY_WITH_BLANK_LINE => 4, # the bod !! 388 STATE_DOCBLOCK => 4, # documentation block 222 STATE_PROTO => 5, # scannin !! 389 STATE_INLINE => 5, # gathering documentation outside main block 223 STATE_DOCBLOCK => 6, # documen << 224 STATE_INLINE => 7, # gatheri << 225 }; 390 }; 226 my $state; 391 my $state; 227 my $in_doc_sect; 392 my $in_doc_sect; 228 my $leading_space; << 229 393 230 # Inline documentation state 394 # Inline documentation state 231 use constant { 395 use constant { 232 STATE_INLINE_NA => 0, # not applicable 396 STATE_INLINE_NA => 0, # not applicable ($state != STATE_INLINE) 233 STATE_INLINE_NAME => 1, # looking for me 397 STATE_INLINE_NAME => 1, # looking for member name (@foo:) 234 STATE_INLINE_TEXT => 2, # looking for me 398 STATE_INLINE_TEXT => 2, # looking for member documentation 235 STATE_INLINE_END => 3, # done 399 STATE_INLINE_END => 3, # done 236 STATE_INLINE_ERROR => 4, # error - Commen 400 STATE_INLINE_ERROR => 4, # error - Comment without header was found. 237 # Spit a warning 401 # Spit a warning as it's not 238 # proper kernel- 402 # proper kernel-doc and ignore the rest. 239 }; 403 }; 240 my $inline_doc_state; 404 my $inline_doc_state; 241 405 242 #declaration types: can be 406 #declaration types: can be 243 # 'function', 'struct', 'union', 'enum', 'type 407 # 'function', 'struct', 'union', 'enum', 'typedef' 244 my $decl_type; 408 my $decl_type; 245 409 246 # Name of the kernel-doc identifier for non-DO << 247 my $identifier; << 248 << 249 my $doc_start = '^/\*\*\s*$'; # Allow whitespa 410 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start. 250 my $doc_end = '\*/'; 411 my $doc_end = '\*/'; 251 my $doc_com = '\s*\*\s*'; 412 my $doc_com = '\s*\*\s*'; 252 my $doc_com_body = '\s*\* ?'; 413 my $doc_com_body = '\s*\* ?'; 253 my $doc_decl = $doc_com . '(\w+)'; 414 my $doc_decl = $doc_com . '(\w+)'; 254 # @params and a strictly limited set of suppor 415 # @params and a strictly limited set of supported section names 255 # Specifically: !! 416 my $doc_sect = $doc_com . 256 # Match @word: !! 417 '\s*(\@[.\w]+|\@\.\.\.|description|context|returns?|notes?|examples?)\s*:(.*)'; 257 # @...: << 258 # @{section-name}: << 259 # while trying to not match literal block star << 260 # << 261 my $doc_sect = $doc_com . << 262 '\s*(\@[.\w]+|\@\.\.\.|description|context << 263 my $doc_content = $doc_com_body . '(.*)'; 418 my $doc_content = $doc_com_body . '(.*)'; 264 my $doc_block = $doc_com . 'DOC:\s*(.*)?'; 419 my $doc_block = $doc_com . 'DOC:\s*(.*)?'; 265 my $doc_inline_start = '^\s*/\*\*\s*$'; 420 my $doc_inline_start = '^\s*/\*\*\s*$'; 266 my $doc_inline_sect = '\s*\*\s*(@\s*[\w][\w\.] !! 421 my $doc_inline_sect = '\s*\*\s*(@[\w\s]+):(.*)'; 267 my $doc_inline_end = '^\s*\*/\s*$'; 422 my $doc_inline_end = '^\s*\*/\s*$'; 268 my $doc_inline_oneline = '^\s*/\*\*\s*(@[\w\s] << 269 my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\ 423 my $export_symbol = '^\s*EXPORT_SYMBOL(_GPL)?\s*\(\s*(\w+)\s*\)\s*;'; 270 my $export_symbol_ns = '^\s*EXPORT_SYMBOL_NS(_ << 271 my $function_pointer = qr{([^\(]*\(\*)\s*\)\s* << 272 my $attribute = qr{__attribute__\s*\(\([a-z0-9 << 273 424 274 my %parameterdescs; 425 my %parameterdescs; 275 my %parameterdesc_start_lines; 426 my %parameterdesc_start_lines; 276 my @parameterlist; 427 my @parameterlist; 277 my %sections; 428 my %sections; 278 my @sectionlist; 429 my @sectionlist; 279 my %section_start_lines; 430 my %section_start_lines; 280 my $sectcheck; 431 my $sectcheck; 281 my $struct_actual; 432 my $struct_actual; 282 433 283 my $contents = ""; 434 my $contents = ""; 284 my $new_start_line = 0; 435 my $new_start_line = 0; 285 436 286 # the canonical section names. see also $doc_s 437 # the canonical section names. see also $doc_sect above. 287 my $section_default = "Description"; # defa 438 my $section_default = "Description"; # default section 288 my $section_intro = "Introduction"; 439 my $section_intro = "Introduction"; 289 my $section = $section_default; 440 my $section = $section_default; 290 my $section_context = "Context"; 441 my $section_context = "Context"; 291 my $section_return = "Return"; 442 my $section_return = "Return"; 292 443 293 my $undescribed = "-- undescribed --"; 444 my $undescribed = "-- undescribed --"; 294 445 295 reset_state(); 446 reset_state(); 296 447 297 while ($ARGV[0] =~ m/^--?(.*)/) { !! 448 while ($ARGV[0] =~ m/^-(.*)/) { 298 my $cmd = $1; !! 449 my $cmd = shift @ARGV; 299 shift @ARGV; !! 450 if ($cmd eq "-html") { 300 if ($cmd eq "man") { !! 451 $output_mode = "html"; 301 $output_mode = "man"; !! 452 @highlights = @highlights_html; 302 @highlights = @highlights_man; !! 453 $blankline = $blankline_html; 303 $blankline = $blankline_man; !! 454 } elsif ($cmd eq "-html5") { 304 } elsif ($cmd eq "rst") { !! 455 $output_mode = "html5"; 305 $output_mode = "rst"; !! 456 @highlights = @highlights_html5; 306 @highlights = @highlights_rst; !! 457 $blankline = $blankline_html5; 307 $blankline = $blankline_rst; !! 458 } elsif ($cmd eq "-man") { 308 } elsif ($cmd eq "none") { !! 459 $output_mode = "man"; 309 $output_mode = "none"; !! 460 @highlights = @highlights_man; 310 } elsif ($cmd eq "module") { # not needed !! 461 $blankline = $blankline_man; 311 $modulename = shift @ARGV; !! 462 } elsif ($cmd eq "-text") { 312 } elsif ($cmd eq "function") { # to only o !! 463 $output_mode = "text"; 313 $output_selection = OUTPUT_INCLUDE; !! 464 @highlights = @highlights_text; 314 $function = shift @ARGV; !! 465 $blankline = $blankline_text; 315 $function_table{$function} = 1; !! 466 } elsif ($cmd eq "-rst") { 316 } elsif ($cmd eq "nosymbol") { # Exclude s !! 467 $output_mode = "rst"; 317 my $symbol = shift @ARGV; !! 468 @highlights = @highlights_rst; 318 $nosymbol_table{$symbol} = 1; !! 469 $blankline = $blankline_rst; 319 } elsif ($cmd eq "export") { # only export !! 470 } elsif ($cmd eq "-docbook") { 320 $output_selection = OUTPUT_EXPORTED; !! 471 $output_mode = "xml"; 321 %function_table = (); !! 472 @highlights = @highlights_xml; 322 } elsif ($cmd eq "internal") { # only non- !! 473 $blankline = $blankline_xml; 323 $output_selection = OUTPUT_INTERNAL; !! 474 } elsif ($cmd eq "-list") { 324 %function_table = (); !! 475 $output_mode = "list"; 325 } elsif ($cmd eq "export-file") { !! 476 @highlights = @highlights_list; 326 my $file = shift @ARGV; !! 477 $blankline = $blankline_list; 327 push(@export_file_list, $file); !! 478 } elsif ($cmd eq "-gnome") { 328 } elsif ($cmd eq "v") { !! 479 $output_mode = "gnome"; 329 $verbose = 1; !! 480 @highlights = @highlights_gnome; 330 } elsif ($cmd eq "Werror") { !! 481 $blankline = $blankline_gnome; 331 $Werror = 1; !! 482 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document 332 } elsif ($cmd eq "Wreturn") { !! 483 $modulename = shift @ARGV; 333 $Wreturn = 1; !! 484 } elsif ($cmd eq "-function") { # to only output specific functions 334 } elsif ($cmd eq "Wshort-desc" or $cmd eq !! 485 $output_selection = OUTPUT_INCLUDE; 335 $Wshort_desc = 1; !! 486 $function = shift @ARGV; 336 } elsif ($cmd eq "Wcontents-before-section !! 487 $function_table{$function} = 1; 337 $Wcontents_before_sections = 1; !! 488 } elsif ($cmd eq "-nofunction") { # output all except specific functions 338 } elsif ($cmd eq "Wall") { !! 489 $output_selection = OUTPUT_EXCLUDE; 339 $Wreturn = 1; !! 490 $function = shift @ARGV; 340 $Wshort_desc = 1; !! 491 $function_table{$function} = 1; 341 $Wcontents_before_sections = 1; !! 492 } elsif ($cmd eq "-export") { # only exported symbols 342 } elsif (($cmd eq "h") || ($cmd eq "help") !! 493 $output_selection = OUTPUT_EXPORTED; 343 pod2usage(-exitval => 0, -verbose => 2 !! 494 %function_table = (); 344 } elsif ($cmd eq 'no-doc-sections') { !! 495 } elsif ($cmd eq "-internal") { # only non-exported symbols 345 $no_doc_sections = 1; !! 496 $output_selection = OUTPUT_INTERNAL; 346 } elsif ($cmd eq 'enable-lineno') { !! 497 %function_table = (); 347 $enable_lineno = 1; !! 498 } elsif ($cmd eq "-export-file") { 348 } elsif ($cmd eq 'show-not-found') { !! 499 my $file = shift @ARGV; 349 $show_not_found = 1; # A no-op but do !! 500 push(@export_file_list, $file); 350 } elsif ($cmd eq "sphinx-version") { !! 501 } elsif ($cmd eq "-v") { 351 my $ver_string = shift @ARGV; !! 502 $verbose = 1; 352 if ($ver_string =~ m/^(\d+)(\.\d+)?(\. !! 503 } elsif (($cmd eq "-h") || ($cmd eq "--help")) { 353 $sphinx_major = $1; !! 504 usage(); 354 if (defined($2)) { !! 505 } elsif ($cmd eq '-no-doc-sections') { 355 $sphinx_minor = substr($2,1); !! 506 $no_doc_sections = 1; 356 } else { !! 507 } elsif ($cmd eq '-enable-lineno') { 357 $sphinx_minor = 0; !! 508 $enable_lineno = 1; 358 } !! 509 } elsif ($cmd eq '-show-not-found') { 359 if (defined($3)) { !! 510 $show_not_found = 1; 360 $sphinx_patch = substr($3,1) << 361 } else { << 362 $sphinx_patch = 0; << 363 } << 364 } else { << 365 die "Sphinx version should either << 366 } << 367 } else { << 368 # Unknown argument << 369 pod2usage( << 370 -message => "Argument unknown!\n", << 371 -exitval => 1, << 372 -verbose => 99, << 373 -sections => 'SYNOPSIS', << 374 -output => \*STDERR, << 375 ); << 376 } << 377 if ($#ARGV < 0){ << 378 pod2usage( << 379 -message => "FILE argument missing << 380 -exitval => 1, << 381 -verbose => 99, << 382 -sections => 'SYNOPSIS', << 383 -output => \*STDERR, << 384 ); << 385 } 511 } 386 } 512 } 387 513 388 # continue execution near EOF; 514 # continue execution near EOF; 389 515 390 # The C domain dialect changed on Sphinx 3. So << 391 # version in order to produce the right tags. << 392 sub findprog($) << 393 { << 394 foreach(split(/:/, $ENV{PATH})) { << 395 return "$_/$_[0]" if(-x "$_/$_[0]"); << 396 } << 397 } << 398 << 399 sub get_sphinx_version() << 400 { << 401 my $ver; << 402 << 403 my $cmd = "sphinx-build"; << 404 if (!findprog($cmd)) { << 405 my $cmd = "sphinx-build3"; << 406 if (!findprog($cmd)) { << 407 $sphinx_major = 1; << 408 $sphinx_minor = 2; << 409 $sphinx_patch = 0; << 410 printf STDERR "Warning: Sphinx ver << 411 $sphinx_major, $sphinx_mino << 412 return; << 413 } << 414 } << 415 << 416 open IN, "$cmd --version 2>&1 |"; << 417 while (<IN>) { << 418 if (m/^\s*sphinx-build\s+([\d]+)\.([\d << 419 $sphinx_major = $1; << 420 $sphinx_minor = $2; << 421 $sphinx_patch = $3; << 422 last; << 423 } << 424 # Sphinx 1.2.x uses a different format << 425 if (m/^\s*Sphinx.*\s+([\d]+)\.([\d\.]+ << 426 $sphinx_major = $1; << 427 $sphinx_minor = $2; << 428 $sphinx_patch = $3; << 429 last; << 430 } << 431 } << 432 close IN; << 433 } << 434 << 435 # get kernel version from env 516 # get kernel version from env 436 sub get_kernel_version() { 517 sub get_kernel_version() { 437 my $version = 'unknown kernel version'; 518 my $version = 'unknown kernel version'; 438 519 439 if (defined($ENV{'KERNELVERSION'})) { 520 if (defined($ENV{'KERNELVERSION'})) { 440 $version = $ENV{'KERNELVERSION'}; !! 521 $version = $ENV{'KERNELVERSION'}; 441 } 522 } 442 return $version; 523 return $version; 443 } 524 } 444 525 445 # 526 # 446 sub print_lineno { 527 sub print_lineno { 447 my $lineno = shift; 528 my $lineno = shift; 448 if ($enable_lineno && defined($lineno)) { 529 if ($enable_lineno && defined($lineno)) { 449 print ".. LINENO " . $lineno . "\n"; !! 530 print "#define LINENO " . $lineno . "\n"; 450 } 531 } 451 } 532 } 452 << 453 sub emit_warning { << 454 my $location = shift; << 455 my $msg = shift; << 456 print STDERR "$location: warning: $msg"; << 457 ++$warnings; << 458 } << 459 ## 533 ## 460 # dumps section contents to arrays/hashes inte 534 # dumps section contents to arrays/hashes intended for that purpose. 461 # 535 # 462 sub dump_section { 536 sub dump_section { 463 my $file = shift; 537 my $file = shift; 464 my $name = shift; 538 my $name = shift; 465 my $contents = join "\n", @_; 539 my $contents = join "\n", @_; 466 540 467 if ($name =~ m/$type_param/) { 541 if ($name =~ m/$type_param/) { 468 $name = $1; !! 542 $name = $1; 469 $parameterdescs{$name} = $contents; !! 543 $parameterdescs{$name} = $contents; 470 $sectcheck = $sectcheck . $name . " "; !! 544 $sectcheck = $sectcheck . $name . " "; 471 $parameterdesc_start_lines{$name} = $n 545 $parameterdesc_start_lines{$name} = $new_start_line; 472 $new_start_line = 0; 546 $new_start_line = 0; 473 } elsif ($name eq "@\.\.\.") { 547 } elsif ($name eq "@\.\.\.") { 474 $name = "..."; !! 548 $name = "..."; 475 $parameterdescs{$name} = $contents; !! 549 $parameterdescs{$name} = $contents; 476 $sectcheck = $sectcheck . $name . " "; !! 550 $sectcheck = $sectcheck . $name . " "; 477 $parameterdesc_start_lines{$name} = $n 551 $parameterdesc_start_lines{$name} = $new_start_line; 478 $new_start_line = 0; 552 $new_start_line = 0; 479 } else { 553 } else { 480 if (defined($sections{$name}) && ($sec !! 554 if (defined($sections{$name}) && ($sections{$name} ne "")) { 481 # Only warn on user specified dupl !! 555 # Only warn on user specified duplicate section names. 482 if ($name ne $section_default) { !! 556 if ($name ne $section_default) { 483 emit_warning("${file}:$.", "du !! 557 print STDERR "${file}:$.: warning: duplicate section name '$name'\n"; 484 } !! 558 ++$warnings; 485 $sections{$name} .= $contents; !! 559 } 486 } else { !! 560 $sections{$name} .= $contents; 487 $sections{$name} = $contents; !! 561 } else { 488 push @sectionlist, $name; !! 562 $sections{$name} = $contents; >> 563 push @sectionlist, $name; 489 $section_start_lines{$name} = $new 564 $section_start_lines{$name} = $new_start_line; 490 $new_start_line = 0; 565 $new_start_line = 0; 491 } !! 566 } 492 } 567 } 493 } 568 } 494 569 495 ## 570 ## 496 # dump DOC: section after checking that it sho 571 # dump DOC: section after checking that it should go out 497 # 572 # 498 sub dump_doc_section { 573 sub dump_doc_section { 499 my $file = shift; 574 my $file = shift; 500 my $name = shift; 575 my $name = shift; 501 my $contents = join "\n", @_; 576 my $contents = join "\n", @_; 502 577 503 if ($no_doc_sections) { 578 if ($no_doc_sections) { 504 return; 579 return; 505 } 580 } 506 581 507 return if (defined($nosymbol_table{$name}) << 508 << 509 if (($output_selection == OUTPUT_ALL) || 582 if (($output_selection == OUTPUT_ALL) || 510 (($output_selection == OUTPUT_INCLUDE) !! 583 ($output_selection == OUTPUT_INCLUDE && 511 defined($function_table{$name}))) !! 584 defined($function_table{$name})) || >> 585 ($output_selection == OUTPUT_EXCLUDE && >> 586 !defined($function_table{$name}))) 512 { 587 { 513 dump_section($file, $name, $contents); !! 588 dump_section($file, $name, $contents); 514 output_blockhead({'sectionlist' => \@s !! 589 output_blockhead({'sectionlist' => \@sectionlist, 515 'sections' => \%sect !! 590 'sections' => \%sections, 516 'module' => $modulen !! 591 'module' => $modulename, 517 'content-only' => ($ !! 592 'content-only' => ($output_selection != OUTPUT_ALL), }); 518 } 593 } 519 } 594 } 520 595 521 ## 596 ## 522 # output function 597 # output function 523 # 598 # 524 # parameterdescs, a hash. 599 # parameterdescs, a hash. 525 # function => "function name" 600 # function => "function name" 526 # parameterlist => @list of parameters 601 # parameterlist => @list of parameters 527 # parameterdescs => %parameter descriptions 602 # parameterdescs => %parameter descriptions 528 # sectionlist => @list of sections 603 # sectionlist => @list of sections 529 # sections => %section descriptions 604 # sections => %section descriptions 530 # 605 # 531 606 532 sub output_highlight { 607 sub output_highlight { 533 my $contents = join "\n",@_; 608 my $contents = join "\n",@_; 534 my $line; 609 my $line; 535 610 536 # DEBUG 611 # DEBUG 537 # if (!defined $contents) { 612 # if (!defined $contents) { 538 # use Carp; 613 # use Carp; 539 # confess "output_highlight got called w 614 # confess "output_highlight got called with no args?\n"; 540 # } 615 # } 541 616 >> 617 if ($output_mode eq "html" || $output_mode eq "html5" || >> 618 $output_mode eq "xml") { >> 619 $contents = local_unescape($contents); >> 620 # convert data read & converted thru xml_escape() into &xyz; format: >> 621 $contents =~ s/\\\\\\/\&/g; >> 622 } 542 # print STDERR "contents b4:$contents\n"; 623 # print STDERR "contents b4:$contents\n"; 543 eval $dohighlight; 624 eval $dohighlight; 544 die $@ if $@; 625 die $@ if $@; 545 # print STDERR "contents af:$contents\n"; 626 # print STDERR "contents af:$contents\n"; 546 627 >> 628 # strip whitespaces when generating html5 >> 629 if ($output_mode eq "html5") { >> 630 $contents =~ s/^\s+//; >> 631 $contents =~ s/\s+$//; >> 632 } 547 foreach $line (split "\n", $contents) { 633 foreach $line (split "\n", $contents) { 548 if (! $output_preformatted) { !! 634 if (! $output_preformatted) { 549 $line =~ s/^\s*//; !! 635 $line =~ s/^\s*//; 550 } !! 636 } 551 if ($line eq ""){ !! 637 if ($line eq ""){ 552 if (! $output_preformatted) { !! 638 if (! $output_preformatted) { 553 print $lineprefix, $blankline; !! 639 print $lineprefix, local_unescape($blankline); 554 } !! 640 } 555 } else { !! 641 } else { 556 if ($output_mode eq "man" && subst !! 642 $line =~ s/\\\\\\/\&/g; 557 print "\\&$line"; !! 643 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") { 558 } else { !! 644 print "\\&$line"; 559 print $lineprefix, $line; !! 645 } else { 560 } !! 646 print $lineprefix, $line; 561 } !! 647 } 562 print "\n"; !! 648 } >> 649 print "\n"; >> 650 } >> 651 } >> 652 >> 653 # output sections in html >> 654 sub output_section_html(%) { >> 655 my %args = %{$_[0]}; >> 656 my $section; >> 657 >> 658 foreach $section (@{$args{'sectionlist'}}) { >> 659 print "<h3>$section</h3>\n"; >> 660 print "<blockquote>\n"; >> 661 output_highlight($args{'sections'}{$section}); >> 662 print "</blockquote>\n"; >> 663 } >> 664 } >> 665 >> 666 # output enum in html >> 667 sub output_enum_html(%) { >> 668 my %args = %{$_[0]}; >> 669 my ($parameter); >> 670 my $count; >> 671 print "<h2>enum " . $args{'enum'} . "</h2>\n"; >> 672 >> 673 print "<b>enum " . $args{'enum'} . "</b> {<br>\n"; >> 674 $count = 0; >> 675 foreach $parameter (@{$args{'parameterlist'}}) { >> 676 print " <b>" . $parameter . "</b>"; >> 677 if ($count != $#{$args{'parameterlist'}}) { >> 678 $count++; >> 679 print ",\n"; >> 680 } >> 681 print "<br>"; >> 682 } >> 683 print "};<br>\n"; >> 684 >> 685 print "<h3>Constants</h3>\n"; >> 686 print "<dl>\n"; >> 687 foreach $parameter (@{$args{'parameterlist'}}) { >> 688 print "<dt><b>" . $parameter . "</b>\n"; >> 689 print "<dd>"; >> 690 output_highlight($args{'parameterdescs'}{$parameter}); >> 691 } >> 692 print "</dl>\n"; >> 693 output_section_html(@_); >> 694 print "<hr>\n"; >> 695 } >> 696 >> 697 # output typedef in html >> 698 sub output_typedef_html(%) { >> 699 my %args = %{$_[0]}; >> 700 my ($parameter); >> 701 my $count; >> 702 print "<h2>typedef " . $args{'typedef'} . "</h2>\n"; >> 703 >> 704 print "<b>typedef " . $args{'typedef'} . "</b>\n"; >> 705 output_section_html(@_); >> 706 print "<hr>\n"; >> 707 } >> 708 >> 709 # output struct in html >> 710 sub output_struct_html(%) { >> 711 my %args = %{$_[0]}; >> 712 my ($parameter); >> 713 >> 714 print "<h2>" . $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "</h2>\n"; >> 715 print "<b>" . $args{'type'} . " " . $args{'struct'} . "</b> {<br>\n"; >> 716 foreach $parameter (@{$args{'parameterlist'}}) { >> 717 if ($parameter =~ /^#/) { >> 718 print "$parameter<br>\n"; >> 719 next; >> 720 } >> 721 my $parameter_name = $parameter; >> 722 $parameter_name =~ s/\[.*//; >> 723 >> 724 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; >> 725 $type = $args{'parametertypes'}{$parameter}; >> 726 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { >> 727 # pointer-to-function >> 728 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n"; >> 729 } elsif ($type =~ m/^(.*?)\s*(:.*)/) { >> 730 # bitfield >> 731 print " <i>$1</i> <b>$parameter</b>$2;<br>\n"; >> 732 } else { >> 733 print " <i>$type</i> <b>$parameter</b>;<br>\n"; >> 734 } >> 735 } >> 736 print "};<br>\n"; >> 737 >> 738 print "<h3>Members</h3>\n"; >> 739 print "<dl>\n"; >> 740 foreach $parameter (@{$args{'parameterlist'}}) { >> 741 ($parameter =~ /^#/) && next; >> 742 >> 743 my $parameter_name = $parameter; >> 744 $parameter_name =~ s/\[.*//; >> 745 >> 746 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; >> 747 print "<dt><b>" . $parameter . "</b>\n"; >> 748 print "<dd>"; >> 749 output_highlight($args{'parameterdescs'}{$parameter_name}); >> 750 } >> 751 print "</dl>\n"; >> 752 output_section_html(@_); >> 753 print "<hr>\n"; >> 754 } >> 755 >> 756 # output function in html >> 757 sub output_function_html(%) { >> 758 my %args = %{$_[0]}; >> 759 my ($parameter, $section); >> 760 my $count; >> 761 >> 762 print "<h2>" . $args{'function'} . " - " . $args{'purpose'} . "</h2>\n"; >> 763 print "<i>" . $args{'functiontype'} . "</i>\n"; >> 764 print "<b>" . $args{'function'} . "</b>\n"; >> 765 print "("; >> 766 $count = 0; >> 767 foreach $parameter (@{$args{'parameterlist'}}) { >> 768 $type = $args{'parametertypes'}{$parameter}; >> 769 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { >> 770 # pointer-to-function >> 771 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>"; >> 772 } else { >> 773 print "<i>" . $type . "</i> <b>" . $parameter . "</b>"; >> 774 } >> 775 if ($count != $#{$args{'parameterlist'}}) { >> 776 $count++; >> 777 print ",\n"; >> 778 } >> 779 } >> 780 print ")\n"; >> 781 >> 782 print "<h3>Arguments</h3>\n"; >> 783 print "<dl>\n"; >> 784 foreach $parameter (@{$args{'parameterlist'}}) { >> 785 my $parameter_name = $parameter; >> 786 $parameter_name =~ s/\[.*//; >> 787 >> 788 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; >> 789 print "<dt><b>" . $parameter . "</b>\n"; >> 790 print "<dd>"; >> 791 output_highlight($args{'parameterdescs'}{$parameter_name}); >> 792 } >> 793 print "</dl>\n"; >> 794 output_section_html(@_); >> 795 print "<hr>\n"; >> 796 } >> 797 >> 798 # output DOC: block header in html >> 799 sub output_blockhead_html(%) { >> 800 my %args = %{$_[0]}; >> 801 my ($parameter, $section); >> 802 my $count; >> 803 >> 804 foreach $section (@{$args{'sectionlist'}}) { >> 805 print "<h3>$section</h3>\n"; >> 806 print "<ul>\n"; >> 807 output_highlight($args{'sections'}{$section}); >> 808 print "</ul>\n"; >> 809 } >> 810 print "<hr>\n"; >> 811 } >> 812 >> 813 # output sections in html5 >> 814 sub output_section_html5(%) { >> 815 my %args = %{$_[0]}; >> 816 my $section; >> 817 >> 818 foreach $section (@{$args{'sectionlist'}}) { >> 819 print "<section>\n"; >> 820 print "<h1>$section</h1>\n"; >> 821 print "<p>\n"; >> 822 output_highlight($args{'sections'}{$section}); >> 823 print "</p>\n"; >> 824 print "</section>\n"; >> 825 } >> 826 } >> 827 >> 828 # output enum in html5 >> 829 sub output_enum_html5(%) { >> 830 my %args = %{$_[0]}; >> 831 my ($parameter); >> 832 my $count; >> 833 my $html5id; >> 834 >> 835 $html5id = $args{'enum'}; >> 836 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; >> 837 print "<article class=\"enum\" id=\"enum:". $html5id . "\">"; >> 838 print "<h1>enum " . $args{'enum'} . "</h1>\n"; >> 839 print "<ol class=\"code\">\n"; >> 840 print "<li>"; >> 841 print "<span class=\"keyword\">enum</span> "; >> 842 print "<span class=\"identifier\">" . $args{'enum'} . "</span> {"; >> 843 print "</li>\n"; >> 844 $count = 0; >> 845 foreach $parameter (@{$args{'parameterlist'}}) { >> 846 print "<li class=\"indent\">"; >> 847 print "<span class=\"param\">" . $parameter . "</span>"; >> 848 if ($count != $#{$args{'parameterlist'}}) { >> 849 $count++; >> 850 print ","; >> 851 } >> 852 print "</li>\n"; >> 853 } >> 854 print "<li>};</li>\n"; >> 855 print "</ol>\n"; >> 856 >> 857 print "<section>\n"; >> 858 print "<h1>Constants</h1>\n"; >> 859 print "<dl>\n"; >> 860 foreach $parameter (@{$args{'parameterlist'}}) { >> 861 print "<dt>" . $parameter . "</dt>\n"; >> 862 print "<dd>"; >> 863 output_highlight($args{'parameterdescs'}{$parameter}); >> 864 print "</dd>\n"; >> 865 } >> 866 print "</dl>\n"; >> 867 print "</section>\n"; >> 868 output_section_html5(@_); >> 869 print "</article>\n"; >> 870 } >> 871 >> 872 # output typedef in html5 >> 873 sub output_typedef_html5(%) { >> 874 my %args = %{$_[0]}; >> 875 my ($parameter); >> 876 my $count; >> 877 my $html5id; >> 878 >> 879 $html5id = $args{'typedef'}; >> 880 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; >> 881 print "<article class=\"typedef\" id=\"typedef:" . $html5id . "\">\n"; >> 882 print "<h1>typedef " . $args{'typedef'} . "</h1>\n"; >> 883 >> 884 print "<ol class=\"code\">\n"; >> 885 print "<li>"; >> 886 print "<span class=\"keyword\">typedef</span> "; >> 887 print "<span class=\"identifier\">" . $args{'typedef'} . "</span>"; >> 888 print "</li>\n"; >> 889 print "</ol>\n"; >> 890 output_section_html5(@_); >> 891 print "</article>\n"; >> 892 } >> 893 >> 894 # output struct in html5 >> 895 sub output_struct_html5(%) { >> 896 my %args = %{$_[0]}; >> 897 my ($parameter); >> 898 my $html5id; >> 899 >> 900 $html5id = $args{'struct'}; >> 901 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; >> 902 print "<article class=\"struct\" id=\"struct:" . $html5id . "\">\n"; >> 903 print "<hgroup>\n"; >> 904 print "<h1>" . $args{'type'} . " " . $args{'struct'} . "</h1>"; >> 905 print "<h2>". $args{'purpose'} . "</h2>\n"; >> 906 print "</hgroup>\n"; >> 907 print "<ol class=\"code\">\n"; >> 908 print "<li>"; >> 909 print "<span class=\"type\">" . $args{'type'} . "</span> "; >> 910 print "<span class=\"identifier\">" . $args{'struct'} . "</span> {"; >> 911 print "</li>\n"; >> 912 foreach $parameter (@{$args{'parameterlist'}}) { >> 913 print "<li class=\"indent\">"; >> 914 if ($parameter =~ /^#/) { >> 915 print "<span class=\"param\">" . $parameter ."</span>\n"; >> 916 print "</li>\n"; >> 917 next; >> 918 } >> 919 my $parameter_name = $parameter; >> 920 $parameter_name =~ s/\[.*//; >> 921 >> 922 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; >> 923 $type = $args{'parametertypes'}{$parameter}; >> 924 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { >> 925 # pointer-to-function >> 926 print "<span class=\"type\">$1</span> "; >> 927 print "<span class=\"param\">$parameter</span>"; >> 928 print "<span class=\"type\">)</span> "; >> 929 print "(<span class=\"args\">$2</span>);"; >> 930 } elsif ($type =~ m/^(.*?)\s*(:.*)/) { >> 931 # bitfield >> 932 print "<span class=\"type\">$1</span> "; >> 933 print "<span class=\"param\">$parameter</span>"; >> 934 print "<span class=\"bits\">$2</span>;"; >> 935 } else { >> 936 print "<span class=\"type\">$type</span> "; >> 937 print "<span class=\"param\">$parameter</span>;"; >> 938 } >> 939 print "</li>\n"; >> 940 } >> 941 print "<li>};</li>\n"; >> 942 print "</ol>\n"; >> 943 >> 944 print "<section>\n"; >> 945 print "<h1>Members</h1>\n"; >> 946 print "<dl>\n"; >> 947 foreach $parameter (@{$args{'parameterlist'}}) { >> 948 ($parameter =~ /^#/) && next; >> 949 >> 950 my $parameter_name = $parameter; >> 951 $parameter_name =~ s/\[.*//; >> 952 >> 953 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; >> 954 print "<dt>" . $parameter . "</dt>\n"; >> 955 print "<dd>"; >> 956 output_highlight($args{'parameterdescs'}{$parameter_name}); >> 957 print "</dd>\n"; 563 } 958 } >> 959 print "</dl>\n"; >> 960 print "</section>\n"; >> 961 output_section_html5(@_); >> 962 print "</article>\n"; >> 963 } >> 964 >> 965 # output function in html5 >> 966 sub output_function_html5(%) { >> 967 my %args = %{$_[0]}; >> 968 my ($parameter, $section); >> 969 my $count; >> 970 my $html5id; >> 971 >> 972 $html5id = $args{'function'}; >> 973 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; >> 974 print "<article class=\"function\" id=\"func:". $html5id . "\">\n"; >> 975 print "<hgroup>\n"; >> 976 print "<h1>" . $args{'function'} . "</h1>"; >> 977 print "<h2>" . $args{'purpose'} . "</h2>\n"; >> 978 print "</hgroup>\n"; >> 979 print "<ol class=\"code\">\n"; >> 980 print "<li>"; >> 981 print "<span class=\"type\">" . $args{'functiontype'} . "</span> "; >> 982 print "<span class=\"identifier\">" . $args{'function'} . "</span> ("; >> 983 print "</li>"; >> 984 $count = 0; >> 985 foreach $parameter (@{$args{'parameterlist'}}) { >> 986 print "<li class=\"indent\">"; >> 987 $type = $args{'parametertypes'}{$parameter}; >> 988 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { >> 989 # pointer-to-function >> 990 print "<span class=\"type\">$1</span> "; >> 991 print "<span class=\"param\">$parameter</span>"; >> 992 print "<span class=\"type\">)</span> "; >> 993 print "(<span class=\"args\">$2</span>)"; >> 994 } else { >> 995 print "<span class=\"type\">$type</span> "; >> 996 print "<span class=\"param\">$parameter</span>"; >> 997 } >> 998 if ($count != $#{$args{'parameterlist'}}) { >> 999 $count++; >> 1000 print ","; >> 1001 } >> 1002 print "</li>\n"; >> 1003 } >> 1004 print "<li>)</li>\n"; >> 1005 print "</ol>\n"; >> 1006 >> 1007 print "<section>\n"; >> 1008 print "<h1>Arguments</h1>\n"; >> 1009 print "<p>\n"; >> 1010 print "<dl>\n"; >> 1011 foreach $parameter (@{$args{'parameterlist'}}) { >> 1012 my $parameter_name = $parameter; >> 1013 $parameter_name =~ s/\[.*//; >> 1014 >> 1015 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; >> 1016 print "<dt>" . $parameter . "</dt>\n"; >> 1017 print "<dd>"; >> 1018 output_highlight($args{'parameterdescs'}{$parameter_name}); >> 1019 print "</dd>\n"; >> 1020 } >> 1021 print "</dl>\n"; >> 1022 print "</section>\n"; >> 1023 output_section_html5(@_); >> 1024 print "</article>\n"; >> 1025 } >> 1026 >> 1027 # output DOC: block header in html5 >> 1028 sub output_blockhead_html5(%) { >> 1029 my %args = %{$_[0]}; >> 1030 my ($parameter, $section); >> 1031 my $count; >> 1032 my $html5id; >> 1033 >> 1034 foreach $section (@{$args{'sectionlist'}}) { >> 1035 $html5id = $section; >> 1036 $html5id =~ s/[^a-zA-Z0-9\-]+/_/g; >> 1037 print "<article class=\"doc\" id=\"doc:". $html5id . "\">\n"; >> 1038 print "<h1>$section</h1>\n"; >> 1039 print "<p>\n"; >> 1040 output_highlight($args{'sections'}{$section}); >> 1041 print "</p>\n"; >> 1042 } >> 1043 print "</article>\n"; >> 1044 } >> 1045 >> 1046 sub output_section_xml(%) { >> 1047 my %args = %{$_[0]}; >> 1048 my $section; >> 1049 # print out each section >> 1050 $lineprefix=" "; >> 1051 foreach $section (@{$args{'sectionlist'}}) { >> 1052 print "<refsect1>\n"; >> 1053 print "<title>$section</title>\n"; >> 1054 if ($section =~ m/EXAMPLE/i) { >> 1055 print "<informalexample><programlisting>\n"; >> 1056 $output_preformatted = 1; >> 1057 } else { >> 1058 print "<para>\n"; >> 1059 } >> 1060 output_highlight($args{'sections'}{$section}); >> 1061 $output_preformatted = 0; >> 1062 if ($section =~ m/EXAMPLE/i) { >> 1063 print "</programlisting></informalexample>\n"; >> 1064 } else { >> 1065 print "</para>\n"; >> 1066 } >> 1067 print "</refsect1>\n"; >> 1068 } >> 1069 } >> 1070 >> 1071 # output function in XML DocBook >> 1072 sub output_function_xml(%) { >> 1073 my %args = %{$_[0]}; >> 1074 my ($parameter, $section); >> 1075 my $count; >> 1076 my $id; >> 1077 >> 1078 $id = "API-" . $args{'function'}; >> 1079 $id =~ s/[^A-Za-z0-9]/-/g; >> 1080 >> 1081 print "<refentry id=\"$id\">\n"; >> 1082 print "<refentryinfo>\n"; >> 1083 print " <title>LINUX</title>\n"; >> 1084 print " <productname>Kernel Hackers Manual</productname>\n"; >> 1085 print " <date>$man_date</date>\n"; >> 1086 print "</refentryinfo>\n"; >> 1087 print "<refmeta>\n"; >> 1088 print " <refentrytitle><phrase>" . $args{'function'} . "</phrase></refentrytitle>\n"; >> 1089 print " <manvolnum>9</manvolnum>\n"; >> 1090 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; >> 1091 print "</refmeta>\n"; >> 1092 print "<refnamediv>\n"; >> 1093 print " <refname>" . $args{'function'} . "</refname>\n"; >> 1094 print " <refpurpose>\n"; >> 1095 print " "; >> 1096 output_highlight ($args{'purpose'}); >> 1097 print " </refpurpose>\n"; >> 1098 print "</refnamediv>\n"; >> 1099 >> 1100 print "<refsynopsisdiv>\n"; >> 1101 print " <title>Synopsis</title>\n"; >> 1102 print " <funcsynopsis><funcprototype>\n"; >> 1103 print " <funcdef>" . $args{'functiontype'} . " "; >> 1104 print "<function>" . $args{'function'} . " </function></funcdef>\n"; >> 1105 >> 1106 $count = 0; >> 1107 if ($#{$args{'parameterlist'}} >= 0) { >> 1108 foreach $parameter (@{$args{'parameterlist'}}) { >> 1109 $type = $args{'parametertypes'}{$parameter}; >> 1110 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { >> 1111 # pointer-to-function >> 1112 print " <paramdef>$1<parameter>$parameter</parameter>)\n"; >> 1113 print " <funcparams>$2</funcparams></paramdef>\n"; >> 1114 } else { >> 1115 print " <paramdef>" . $type; >> 1116 print " <parameter>$parameter</parameter></paramdef>\n"; >> 1117 } >> 1118 } >> 1119 } else { >> 1120 print " <void/>\n"; >> 1121 } >> 1122 print " </funcprototype></funcsynopsis>\n"; >> 1123 print "</refsynopsisdiv>\n"; >> 1124 >> 1125 # print parameters >> 1126 print "<refsect1>\n <title>Arguments</title>\n"; >> 1127 if ($#{$args{'parameterlist'}} >= 0) { >> 1128 print " <variablelist>\n"; >> 1129 foreach $parameter (@{$args{'parameterlist'}}) { >> 1130 my $parameter_name = $parameter; >> 1131 $parameter_name =~ s/\[.*//; >> 1132 >> 1133 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n"; >> 1134 print " <listitem>\n <para>\n"; >> 1135 $lineprefix=" "; >> 1136 output_highlight($args{'parameterdescs'}{$parameter_name}); >> 1137 print " </para>\n </listitem>\n </varlistentry>\n"; >> 1138 } >> 1139 print " </variablelist>\n"; >> 1140 } else { >> 1141 print " <para>\n None\n </para>\n"; >> 1142 } >> 1143 print "</refsect1>\n"; >> 1144 >> 1145 output_section_xml(@_); >> 1146 print "</refentry>\n\n"; >> 1147 } >> 1148 >> 1149 # output struct in XML DocBook >> 1150 sub output_struct_xml(%) { >> 1151 my %args = %{$_[0]}; >> 1152 my ($parameter, $section); >> 1153 my $id; >> 1154 >> 1155 $id = "API-struct-" . $args{'struct'}; >> 1156 $id =~ s/[^A-Za-z0-9]/-/g; >> 1157 >> 1158 print "<refentry id=\"$id\">\n"; >> 1159 print "<refentryinfo>\n"; >> 1160 print " <title>LINUX</title>\n"; >> 1161 print " <productname>Kernel Hackers Manual</productname>\n"; >> 1162 print " <date>$man_date</date>\n"; >> 1163 print "</refentryinfo>\n"; >> 1164 print "<refmeta>\n"; >> 1165 print " <refentrytitle><phrase>" . $args{'type'} . " " . $args{'struct'} . "</phrase></refentrytitle>\n"; >> 1166 print " <manvolnum>9</manvolnum>\n"; >> 1167 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; >> 1168 print "</refmeta>\n"; >> 1169 print "<refnamediv>\n"; >> 1170 print " <refname>" . $args{'type'} . " " . $args{'struct'} . "</refname>\n"; >> 1171 print " <refpurpose>\n"; >> 1172 print " "; >> 1173 output_highlight ($args{'purpose'}); >> 1174 print " </refpurpose>\n"; >> 1175 print "</refnamediv>\n"; >> 1176 >> 1177 print "<refsynopsisdiv>\n"; >> 1178 print " <title>Synopsis</title>\n"; >> 1179 print " <programlisting>\n"; >> 1180 print $args{'type'} . " " . $args{'struct'} . " {\n"; >> 1181 foreach $parameter (@{$args{'parameterlist'}}) { >> 1182 if ($parameter =~ /^#/) { >> 1183 my $prm = $parameter; >> 1184 # convert data read & converted thru xml_escape() into &xyz; format: >> 1185 # This allows us to have #define macros interspersed in a struct. >> 1186 $prm =~ s/\\\\\\/\&/g; >> 1187 print "$prm\n"; >> 1188 next; >> 1189 } >> 1190 >> 1191 my $parameter_name = $parameter; >> 1192 $parameter_name =~ s/\[.*//; >> 1193 >> 1194 defined($args{'parameterdescs'}{$parameter_name}) || next; >> 1195 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; >> 1196 $type = $args{'parametertypes'}{$parameter}; >> 1197 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { >> 1198 # pointer-to-function >> 1199 print " $1 $parameter) ($2);\n"; >> 1200 } elsif ($type =~ m/^(.*?)\s*(:.*)/) { >> 1201 # bitfield >> 1202 print " $1 $parameter$2;\n"; >> 1203 } else { >> 1204 print " " . $type . " " . $parameter . ";\n"; >> 1205 } >> 1206 } >> 1207 print "};"; >> 1208 print " </programlisting>\n"; >> 1209 print "</refsynopsisdiv>\n"; >> 1210 >> 1211 print " <refsect1>\n"; >> 1212 print " <title>Members</title>\n"; >> 1213 >> 1214 if ($#{$args{'parameterlist'}} >= 0) { >> 1215 print " <variablelist>\n"; >> 1216 foreach $parameter (@{$args{'parameterlist'}}) { >> 1217 ($parameter =~ /^#/) && next; >> 1218 >> 1219 my $parameter_name = $parameter; >> 1220 $parameter_name =~ s/\[.*//; >> 1221 >> 1222 defined($args{'parameterdescs'}{$parameter_name}) || next; >> 1223 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; >> 1224 print " <varlistentry>"; >> 1225 print " <term>$parameter</term>\n"; >> 1226 print " <listitem><para>\n"; >> 1227 output_highlight($args{'parameterdescs'}{$parameter_name}); >> 1228 print " </para></listitem>\n"; >> 1229 print " </varlistentry>\n"; >> 1230 } >> 1231 print " </variablelist>\n"; >> 1232 } else { >> 1233 print " <para>\n None\n </para>\n"; >> 1234 } >> 1235 print " </refsect1>\n"; >> 1236 >> 1237 output_section_xml(@_); >> 1238 >> 1239 print "</refentry>\n\n"; >> 1240 } >> 1241 >> 1242 # output enum in XML DocBook >> 1243 sub output_enum_xml(%) { >> 1244 my %args = %{$_[0]}; >> 1245 my ($parameter, $section); >> 1246 my $count; >> 1247 my $id; >> 1248 >> 1249 $id = "API-enum-" . $args{'enum'}; >> 1250 $id =~ s/[^A-Za-z0-9]/-/g; >> 1251 >> 1252 print "<refentry id=\"$id\">\n"; >> 1253 print "<refentryinfo>\n"; >> 1254 print " <title>LINUX</title>\n"; >> 1255 print " <productname>Kernel Hackers Manual</productname>\n"; >> 1256 print " <date>$man_date</date>\n"; >> 1257 print "</refentryinfo>\n"; >> 1258 print "<refmeta>\n"; >> 1259 print " <refentrytitle><phrase>enum " . $args{'enum'} . "</phrase></refentrytitle>\n"; >> 1260 print " <manvolnum>9</manvolnum>\n"; >> 1261 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n"; >> 1262 print "</refmeta>\n"; >> 1263 print "<refnamediv>\n"; >> 1264 print " <refname>enum " . $args{'enum'} . "</refname>\n"; >> 1265 print " <refpurpose>\n"; >> 1266 print " "; >> 1267 output_highlight ($args{'purpose'}); >> 1268 print " </refpurpose>\n"; >> 1269 print "</refnamediv>\n"; >> 1270 >> 1271 print "<refsynopsisdiv>\n"; >> 1272 print " <title>Synopsis</title>\n"; >> 1273 print " <programlisting>\n"; >> 1274 print "enum " . $args{'enum'} . " {\n"; >> 1275 $count = 0; >> 1276 foreach $parameter (@{$args{'parameterlist'}}) { >> 1277 print " $parameter"; >> 1278 if ($count != $#{$args{'parameterlist'}}) { >> 1279 $count++; >> 1280 print ","; >> 1281 } >> 1282 print "\n"; >> 1283 } >> 1284 print "};"; >> 1285 print " </programlisting>\n"; >> 1286 print "</refsynopsisdiv>\n"; >> 1287 >> 1288 print "<refsect1>\n"; >> 1289 print " <title>Constants</title>\n"; >> 1290 print " <variablelist>\n"; >> 1291 foreach $parameter (@{$args{'parameterlist'}}) { >> 1292 my $parameter_name = $parameter; >> 1293 $parameter_name =~ s/\[.*//; >> 1294 >> 1295 print " <varlistentry>"; >> 1296 print " <term>$parameter</term>\n"; >> 1297 print " <listitem><para>\n"; >> 1298 output_highlight($args{'parameterdescs'}{$parameter_name}); >> 1299 print " </para></listitem>\n"; >> 1300 print " </varlistentry>\n"; >> 1301 } >> 1302 print " </variablelist>\n"; >> 1303 print "</refsect1>\n"; >> 1304 >> 1305 output_section_xml(@_); >> 1306 >> 1307 print "</refentry>\n\n"; >> 1308 } >> 1309 >> 1310 # output typedef in XML DocBook >> 1311 sub output_typedef_xml(%) { >> 1312 my %args = %{$_[0]}; >> 1313 my ($parameter, $section); >> 1314 my $id; >> 1315 >> 1316 $id = "API-typedef-" . $args{'typedef'}; >> 1317 $id =~ s/[^A-Za-z0-9]/-/g; >> 1318 >> 1319 print "<refentry id=\"$id\">\n"; >> 1320 print "<refentryinfo>\n"; >> 1321 print " <title>LINUX</title>\n"; >> 1322 print " <productname>Kernel Hackers Manual</productname>\n"; >> 1323 print " <date>$man_date</date>\n"; >> 1324 print "</refentryinfo>\n"; >> 1325 print "<refmeta>\n"; >> 1326 print " <refentrytitle><phrase>typedef " . $args{'typedef'} . "</phrase></refentrytitle>\n"; >> 1327 print " <manvolnum>9</manvolnum>\n"; >> 1328 print "</refmeta>\n"; >> 1329 print "<refnamediv>\n"; >> 1330 print " <refname>typedef " . $args{'typedef'} . "</refname>\n"; >> 1331 print " <refpurpose>\n"; >> 1332 print " "; >> 1333 output_highlight ($args{'purpose'}); >> 1334 print " </refpurpose>\n"; >> 1335 print "</refnamediv>\n"; >> 1336 >> 1337 print "<refsynopsisdiv>\n"; >> 1338 print " <title>Synopsis</title>\n"; >> 1339 print " <synopsis>typedef " . $args{'typedef'} . ";</synopsis>\n"; >> 1340 print "</refsynopsisdiv>\n"; >> 1341 >> 1342 output_section_xml(@_); >> 1343 >> 1344 print "</refentry>\n\n"; >> 1345 } >> 1346 >> 1347 # output in XML DocBook >> 1348 sub output_blockhead_xml(%) { >> 1349 my %args = %{$_[0]}; >> 1350 my ($parameter, $section); >> 1351 my $count; >> 1352 >> 1353 my $id = $args{'module'}; >> 1354 $id =~ s/[^A-Za-z0-9]/-/g; >> 1355 >> 1356 # print out each section >> 1357 $lineprefix=" "; >> 1358 foreach $section (@{$args{'sectionlist'}}) { >> 1359 if (!$args{'content-only'}) { >> 1360 print "<refsect1>\n <title>$section</title>\n"; >> 1361 } >> 1362 if ($section =~ m/EXAMPLE/i) { >> 1363 print "<example><para>\n"; >> 1364 $output_preformatted = 1; >> 1365 } else { >> 1366 print "<para>\n"; >> 1367 } >> 1368 output_highlight($args{'sections'}{$section}); >> 1369 $output_preformatted = 0; >> 1370 if ($section =~ m/EXAMPLE/i) { >> 1371 print "</para></example>\n"; >> 1372 } else { >> 1373 print "</para>"; >> 1374 } >> 1375 if (!$args{'content-only'}) { >> 1376 print "\n</refsect1>\n"; >> 1377 } >> 1378 } >> 1379 >> 1380 print "\n\n"; >> 1381 } >> 1382 >> 1383 # output in XML DocBook >> 1384 sub output_function_gnome { >> 1385 my %args = %{$_[0]}; >> 1386 my ($parameter, $section); >> 1387 my $count; >> 1388 my $id; >> 1389 >> 1390 $id = $args{'module'} . "-" . $args{'function'}; >> 1391 $id =~ s/[^A-Za-z0-9]/-/g; >> 1392 >> 1393 print "<sect2>\n"; >> 1394 print " <title id=\"$id\">" . $args{'function'} . "</title>\n"; >> 1395 >> 1396 print " <funcsynopsis>\n"; >> 1397 print " <funcdef>" . $args{'functiontype'} . " "; >> 1398 print "<function>" . $args{'function'} . " "; >> 1399 print "</function></funcdef>\n"; >> 1400 >> 1401 $count = 0; >> 1402 if ($#{$args{'parameterlist'}} >= 0) { >> 1403 foreach $parameter (@{$args{'parameterlist'}}) { >> 1404 $type = $args{'parametertypes'}{$parameter}; >> 1405 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { >> 1406 # pointer-to-function >> 1407 print " <paramdef>$1 <parameter>$parameter</parameter>)\n"; >> 1408 print " <funcparams>$2</funcparams></paramdef>\n"; >> 1409 } else { >> 1410 print " <paramdef>" . $type; >> 1411 print " <parameter>$parameter</parameter></paramdef>\n"; >> 1412 } >> 1413 } >> 1414 } else { >> 1415 print " <void>\n"; >> 1416 } >> 1417 print " </funcsynopsis>\n"; >> 1418 if ($#{$args{'parameterlist'}} >= 0) { >> 1419 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n"; >> 1420 print "<tgroup cols=\"2\">\n"; >> 1421 print "<colspec colwidth=\"2*\">\n"; >> 1422 print "<colspec colwidth=\"8*\">\n"; >> 1423 print "<tbody>\n"; >> 1424 foreach $parameter (@{$args{'parameterlist'}}) { >> 1425 my $parameter_name = $parameter; >> 1426 $parameter_name =~ s/\[.*//; >> 1427 >> 1428 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n"; >> 1429 print " <entry>\n"; >> 1430 $lineprefix=" "; >> 1431 output_highlight($args{'parameterdescs'}{$parameter_name}); >> 1432 print " </entry></row>\n"; >> 1433 } >> 1434 print " </tbody></tgroup></informaltable>\n"; >> 1435 } else { >> 1436 print " <para>\n None\n </para>\n"; >> 1437 } >> 1438 >> 1439 # print out each section >> 1440 $lineprefix=" "; >> 1441 foreach $section (@{$args{'sectionlist'}}) { >> 1442 print "<simplesect>\n <title>$section</title>\n"; >> 1443 if ($section =~ m/EXAMPLE/i) { >> 1444 print "<example><programlisting>\n"; >> 1445 $output_preformatted = 1; >> 1446 } else { >> 1447 } >> 1448 print "<para>\n"; >> 1449 output_highlight($args{'sections'}{$section}); >> 1450 $output_preformatted = 0; >> 1451 print "</para>\n"; >> 1452 if ($section =~ m/EXAMPLE/i) { >> 1453 print "</programlisting></example>\n"; >> 1454 } else { >> 1455 } >> 1456 print " </simplesect>\n"; >> 1457 } >> 1458 >> 1459 print "</sect2>\n\n"; 564 } 1460 } 565 1461 566 ## 1462 ## 567 # output function in man 1463 # output function in man 568 sub output_function_man(%) { 1464 sub output_function_man(%) { 569 my %args = %{$_[0]}; 1465 my %args = %{$_[0]}; 570 my ($parameter, $section); 1466 my ($parameter, $section); 571 my $count; 1467 my $count; 572 1468 573 print ".TH \"$args{'function'}\" 9 \"$args 1469 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n"; 574 1470 575 print ".SH NAME\n"; 1471 print ".SH NAME\n"; 576 print $args{'function'} . " \\- " . $args{ 1472 print $args{'function'} . " \\- " . $args{'purpose'} . "\n"; 577 1473 578 print ".SH SYNOPSIS\n"; 1474 print ".SH SYNOPSIS\n"; 579 if ($args{'functiontype'} ne "") { 1475 if ($args{'functiontype'} ne "") { 580 print ".B \"" . $args{'functiontype'} !! 1476 print ".B \"" . $args{'functiontype'} . "\" " . $args{'function'} . "\n"; 581 } else { 1477 } else { 582 print ".B \"" . $args{'function'} . "\ !! 1478 print ".B \"" . $args{'function'} . "\n"; 583 } 1479 } 584 $count = 0; 1480 $count = 0; 585 my $parenth = "("; 1481 my $parenth = "("; 586 my $post = ","; 1482 my $post = ","; 587 foreach my $parameter (@{$args{'parameterl 1483 foreach my $parameter (@{$args{'parameterlist'}}) { 588 if ($count == $#{$args{'parameterlist' !! 1484 if ($count == $#{$args{'parameterlist'}}) { 589 $post = ");"; !! 1485 $post = ");"; 590 } !! 1486 } 591 $type = $args{'parametertypes'}{$param !! 1487 $type = $args{'parametertypes'}{$parameter}; 592 if ($type =~ m/$function_pointer/) { !! 1488 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 593 # pointer-to-function !! 1489 # pointer-to-function 594 print ".BI \"" . $parenth . $1 . " !! 1490 print ".BI \"" . $parenth . $1 . "\" " . $parameter . " \") (" . $2 . ")" . $post . "\"\n"; 595 } else { !! 1491 } else { 596 $type =~ s/([^\*])$/$1 /; !! 1492 $type =~ s/([^\*])$/$1 /; 597 print ".BI \"" . $parenth . $type !! 1493 print ".BI \"" . $parenth . $type . "\" " . $parameter . " \"" . $post . "\"\n"; 598 } !! 1494 } 599 $count++; !! 1495 $count++; 600 $parenth = ""; !! 1496 $parenth = ""; 601 } 1497 } 602 1498 603 print ".SH ARGUMENTS\n"; 1499 print ".SH ARGUMENTS\n"; 604 foreach $parameter (@{$args{'parameterlist 1500 foreach $parameter (@{$args{'parameterlist'}}) { 605 my $parameter_name = $parameter; !! 1501 my $parameter_name = $parameter; 606 $parameter_name =~ s/\[.*//; !! 1502 $parameter_name =~ s/\[.*//; 607 1503 608 print ".IP \"" . $parameter . "\" 12\n !! 1504 print ".IP \"" . $parameter . "\" 12\n"; 609 output_highlight($args{'parameterdescs !! 1505 output_highlight($args{'parameterdescs'}{$parameter_name}); 610 } 1506 } 611 foreach $section (@{$args{'sectionlist'}}) 1507 foreach $section (@{$args{'sectionlist'}}) { 612 print ".SH \"", uc $section, "\"\n"; !! 1508 print ".SH \"", uc $section, "\"\n"; 613 output_highlight($args{'sections'}{$se !! 1509 output_highlight($args{'sections'}{$section}); 614 } 1510 } 615 } 1511 } 616 1512 617 ## 1513 ## 618 # output enum in man 1514 # output enum in man 619 sub output_enum_man(%) { 1515 sub output_enum_man(%) { 620 my %args = %{$_[0]}; 1516 my %args = %{$_[0]}; 621 my ($parameter, $section); 1517 my ($parameter, $section); 622 my $count; 1518 my $count; 623 1519 624 print ".TH \"$args{'module'}\" 9 \"enum $a 1520 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n"; 625 1521 626 print ".SH NAME\n"; 1522 print ".SH NAME\n"; 627 print "enum " . $args{'enum'} . " \\- " . 1523 print "enum " . $args{'enum'} . " \\- " . $args{'purpose'} . "\n"; 628 1524 629 print ".SH SYNOPSIS\n"; 1525 print ".SH SYNOPSIS\n"; 630 print "enum " . $args{'enum'} . " {\n"; 1526 print "enum " . $args{'enum'} . " {\n"; 631 $count = 0; 1527 $count = 0; 632 foreach my $parameter (@{$args{'parameterl 1528 foreach my $parameter (@{$args{'parameterlist'}}) { 633 print ".br\n.BI \" $parameter\"\n"; !! 1529 print ".br\n.BI \" $parameter\"\n"; 634 if ($count == $#{$args{'parameterlist' !! 1530 if ($count == $#{$args{'parameterlist'}}) { 635 print "\n};\n"; !! 1531 print "\n};\n"; 636 last; !! 1532 last; 637 } else { !! 1533 } 638 print ", \n.br\n"; !! 1534 else { 639 } !! 1535 print ", \n.br\n"; 640 $count++; !! 1536 } >> 1537 $count++; 641 } 1538 } 642 1539 643 print ".SH Constants\n"; 1540 print ".SH Constants\n"; 644 foreach $parameter (@{$args{'parameterlist 1541 foreach $parameter (@{$args{'parameterlist'}}) { 645 my $parameter_name = $parameter; !! 1542 my $parameter_name = $parameter; 646 $parameter_name =~ s/\[.*//; !! 1543 $parameter_name =~ s/\[.*//; 647 1544 648 print ".IP \"" . $parameter . "\" 12\n !! 1545 print ".IP \"" . $parameter . "\" 12\n"; 649 output_highlight($args{'parameterdescs !! 1546 output_highlight($args{'parameterdescs'}{$parameter_name}); 650 } 1547 } 651 foreach $section (@{$args{'sectionlist'}}) 1548 foreach $section (@{$args{'sectionlist'}}) { 652 print ".SH \"$section\"\n"; !! 1549 print ".SH \"$section\"\n"; 653 output_highlight($args{'sections'}{$se !! 1550 output_highlight($args{'sections'}{$section}); 654 } 1551 } 655 } 1552 } 656 1553 657 ## 1554 ## 658 # output struct in man 1555 # output struct in man 659 sub output_struct_man(%) { 1556 sub output_struct_man(%) { 660 my %args = %{$_[0]}; 1557 my %args = %{$_[0]}; 661 my ($parameter, $section); 1558 my ($parameter, $section); 662 1559 663 print ".TH \"$args{'module'}\" 9 \"" . $ar 1560 print ".TH \"$args{'module'}\" 9 \"" . $args{'type'} . " " . $args{'struct'} . "\" \"$man_date\" \"API Manual\" LINUX\n"; 664 1561 665 print ".SH NAME\n"; 1562 print ".SH NAME\n"; 666 print $args{'type'} . " " . $args{'struct' 1563 print $args{'type'} . " " . $args{'struct'} . " \\- " . $args{'purpose'} . "\n"; 667 1564 668 my $declaration = $args{'definition'}; << 669 $declaration =~ s/\t/ /g; << 670 $declaration =~ s/\n/"\n.br\n.BI \"/g; << 671 print ".SH SYNOPSIS\n"; 1565 print ".SH SYNOPSIS\n"; 672 print $args{'type'} . " " . $args{'struct' 1566 print $args{'type'} . " " . $args{'struct'} . " {\n.br\n"; 673 print ".BI \"$declaration\n};\n.br\n\n"; !! 1567 >> 1568 foreach my $parameter (@{$args{'parameterlist'}}) { >> 1569 if ($parameter =~ /^#/) { >> 1570 print ".BI \"$parameter\"\n.br\n"; >> 1571 next; >> 1572 } >> 1573 my $parameter_name = $parameter; >> 1574 $parameter_name =~ s/\[.*//; >> 1575 >> 1576 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; >> 1577 $type = $args{'parametertypes'}{$parameter}; >> 1578 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { >> 1579 # pointer-to-function >> 1580 print ".BI \" " . $1 . "\" " . $parameter . " \") (" . $2 . ")" . "\"\n;\n"; >> 1581 } elsif ($type =~ m/^(.*?)\s*(:.*)/) { >> 1582 # bitfield >> 1583 print ".BI \" " . $1 . "\ \" " . $parameter . $2 . " \"" . "\"\n;\n"; >> 1584 } else { >> 1585 $type =~ s/([^\*])$/$1 /; >> 1586 print ".BI \" " . $type . "\" " . $parameter . " \"" . "\"\n;\n"; >> 1587 } >> 1588 print "\n.br\n"; >> 1589 } >> 1590 print "};\n.br\n"; 674 1591 675 print ".SH Members\n"; 1592 print ".SH Members\n"; 676 foreach $parameter (@{$args{'parameterlist 1593 foreach $parameter (@{$args{'parameterlist'}}) { 677 ($parameter =~ /^#/) && next; !! 1594 ($parameter =~ /^#/) && next; 678 1595 679 my $parameter_name = $parameter; !! 1596 my $parameter_name = $parameter; 680 $parameter_name =~ s/\[.*//; !! 1597 $parameter_name =~ s/\[.*//; 681 1598 682 ($args{'parameterdescs'}{$parameter_na !! 1599 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 683 print ".IP \"" . $parameter . "\" 12\n !! 1600 print ".IP \"" . $parameter . "\" 12\n"; 684 output_highlight($args{'parameterdescs !! 1601 output_highlight($args{'parameterdescs'}{$parameter_name}); 685 } 1602 } 686 foreach $section (@{$args{'sectionlist'}}) 1603 foreach $section (@{$args{'sectionlist'}}) { 687 print ".SH \"$section\"\n"; !! 1604 print ".SH \"$section\"\n"; 688 output_highlight($args{'sections'}{$se !! 1605 output_highlight($args{'sections'}{$section}); 689 } 1606 } 690 } 1607 } 691 1608 692 ## 1609 ## 693 # output typedef in man 1610 # output typedef in man 694 sub output_typedef_man(%) { 1611 sub output_typedef_man(%) { 695 my %args = %{$_[0]}; 1612 my %args = %{$_[0]}; 696 my ($parameter, $section); 1613 my ($parameter, $section); 697 1614 698 print ".TH \"$args{'module'}\" 9 \"$args{' 1615 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n"; 699 1616 700 print ".SH NAME\n"; 1617 print ".SH NAME\n"; 701 print "typedef " . $args{'typedef'} . " \\ 1618 print "typedef " . $args{'typedef'} . " \\- " . $args{'purpose'} . "\n"; 702 1619 703 foreach $section (@{$args{'sectionlist'}}) 1620 foreach $section (@{$args{'sectionlist'}}) { 704 print ".SH \"$section\"\n"; !! 1621 print ".SH \"$section\"\n"; 705 output_highlight($args{'sections'}{$se !! 1622 output_highlight($args{'sections'}{$section}); 706 } 1623 } 707 } 1624 } 708 1625 709 sub output_blockhead_man(%) { 1626 sub output_blockhead_man(%) { 710 my %args = %{$_[0]}; 1627 my %args = %{$_[0]}; 711 my ($parameter, $section); 1628 my ($parameter, $section); 712 my $count; 1629 my $count; 713 1630 714 print ".TH \"$args{'module'}\" 9 \"$args{' 1631 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n"; 715 1632 716 foreach $section (@{$args{'sectionlist'}}) 1633 foreach $section (@{$args{'sectionlist'}}) { 717 print ".SH \"$section\"\n"; !! 1634 print ".SH \"$section\"\n"; 718 output_highlight($args{'sections'}{$se !! 1635 output_highlight($args{'sections'}{$section}); >> 1636 } >> 1637 } >> 1638 >> 1639 ## >> 1640 # output in text >> 1641 sub output_function_text(%) { >> 1642 my %args = %{$_[0]}; >> 1643 my ($parameter, $section); >> 1644 my $start; >> 1645 >> 1646 print "Name:\n\n"; >> 1647 print $args{'function'} . " - " . $args{'purpose'} . "\n"; >> 1648 >> 1649 print "\nSynopsis:\n\n"; >> 1650 if ($args{'functiontype'} ne "") { >> 1651 $start = $args{'functiontype'} . " " . $args{'function'} . " ("; >> 1652 } else { >> 1653 $start = $args{'function'} . " ("; >> 1654 } >> 1655 print $start; >> 1656 >> 1657 my $count = 0; >> 1658 foreach my $parameter (@{$args{'parameterlist'}}) { >> 1659 $type = $args{'parametertypes'}{$parameter}; >> 1660 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { >> 1661 # pointer-to-function >> 1662 print $1 . $parameter . ") (" . $2; >> 1663 } else { >> 1664 print $type . " " . $parameter; >> 1665 } >> 1666 if ($count != $#{$args{'parameterlist'}}) { >> 1667 $count++; >> 1668 print ",\n"; >> 1669 print " " x length($start); >> 1670 } else { >> 1671 print ");\n\n"; >> 1672 } >> 1673 } >> 1674 >> 1675 print "Arguments:\n\n"; >> 1676 foreach $parameter (@{$args{'parameterlist'}}) { >> 1677 my $parameter_name = $parameter; >> 1678 $parameter_name =~ s/\[.*//; >> 1679 >> 1680 print $parameter . "\n\t" . $args{'parameterdescs'}{$parameter_name} . "\n"; >> 1681 } >> 1682 output_section_text(@_); >> 1683 } >> 1684 >> 1685 #output sections in text >> 1686 sub output_section_text(%) { >> 1687 my %args = %{$_[0]}; >> 1688 my $section; >> 1689 >> 1690 print "\n"; >> 1691 foreach $section (@{$args{'sectionlist'}}) { >> 1692 print "$section:\n\n"; >> 1693 output_highlight($args{'sections'}{$section}); >> 1694 } >> 1695 print "\n\n"; >> 1696 } >> 1697 >> 1698 # output enum in text >> 1699 sub output_enum_text(%) { >> 1700 my %args = %{$_[0]}; >> 1701 my ($parameter); >> 1702 my $count; >> 1703 print "Enum:\n\n"; >> 1704 >> 1705 print "enum " . $args{'enum'} . " - " . $args{'purpose'} . "\n\n"; >> 1706 print "enum " . $args{'enum'} . " {\n"; >> 1707 $count = 0; >> 1708 foreach $parameter (@{$args{'parameterlist'}}) { >> 1709 print "\t$parameter"; >> 1710 if ($count != $#{$args{'parameterlist'}}) { >> 1711 $count++; >> 1712 print ","; >> 1713 } >> 1714 print "\n"; >> 1715 } >> 1716 print "};\n\n"; >> 1717 >> 1718 print "Constants:\n\n"; >> 1719 foreach $parameter (@{$args{'parameterlist'}}) { >> 1720 print "$parameter\n\t"; >> 1721 print $args{'parameterdescs'}{$parameter} . "\n"; >> 1722 } >> 1723 >> 1724 output_section_text(@_); >> 1725 } >> 1726 >> 1727 # output typedef in text >> 1728 sub output_typedef_text(%) { >> 1729 my %args = %{$_[0]}; >> 1730 my ($parameter); >> 1731 my $count; >> 1732 print "Typedef:\n\n"; >> 1733 >> 1734 print "typedef " . $args{'typedef'} . " - " . $args{'purpose'} . "\n"; >> 1735 output_section_text(@_); >> 1736 } >> 1737 >> 1738 # output struct as text >> 1739 sub output_struct_text(%) { >> 1740 my %args = %{$_[0]}; >> 1741 my ($parameter); >> 1742 >> 1743 print $args{'type'} . " " . $args{'struct'} . " - " . $args{'purpose'} . "\n\n"; >> 1744 print $args{'type'} . " " . $args{'struct'} . " {\n"; >> 1745 foreach $parameter (@{$args{'parameterlist'}}) { >> 1746 if ($parameter =~ /^#/) { >> 1747 print "$parameter\n"; >> 1748 next; >> 1749 } >> 1750 >> 1751 my $parameter_name = $parameter; >> 1752 $parameter_name =~ s/\[.*//; >> 1753 >> 1754 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; >> 1755 $type = $args{'parametertypes'}{$parameter}; >> 1756 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { >> 1757 # pointer-to-function >> 1758 print "\t$1 $parameter) ($2);\n"; >> 1759 } elsif ($type =~ m/^(.*?)\s*(:.*)/) { >> 1760 # bitfield >> 1761 print "\t$1 $parameter$2;\n"; >> 1762 } else { >> 1763 print "\t" . $type . " " . $parameter . ";\n"; >> 1764 } >> 1765 } >> 1766 print "};\n\n"; >> 1767 >> 1768 print "Members:\n\n"; >> 1769 foreach $parameter (@{$args{'parameterlist'}}) { >> 1770 ($parameter =~ /^#/) && next; >> 1771 >> 1772 my $parameter_name = $parameter; >> 1773 $parameter_name =~ s/\[.*//; >> 1774 >> 1775 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; >> 1776 print "$parameter\n\t"; >> 1777 print $args{'parameterdescs'}{$parameter_name} . "\n"; >> 1778 } >> 1779 print "\n"; >> 1780 output_section_text(@_); >> 1781 } >> 1782 >> 1783 sub output_blockhead_text(%) { >> 1784 my %args = %{$_[0]}; >> 1785 my ($parameter, $section); >> 1786 >> 1787 foreach $section (@{$args{'sectionlist'}}) { >> 1788 print " $section:\n"; >> 1789 print " -> "; >> 1790 output_highlight($args{'sections'}{$section}); 719 } 1791 } 720 } 1792 } 721 1793 722 ## 1794 ## 723 # output in restructured text 1795 # output in restructured text 724 # 1796 # 725 1797 726 # 1798 # 727 # This could use some work; it's used to outpu 1799 # This could use some work; it's used to output the DOC: sections, and 728 # starts by putting out the name of the doc se 1800 # starts by putting out the name of the doc section itself, but that tends 729 # to duplicate a header already in the templat 1801 # to duplicate a header already in the template file. 730 # 1802 # 731 sub output_blockhead_rst(%) { 1803 sub output_blockhead_rst(%) { 732 my %args = %{$_[0]}; 1804 my %args = %{$_[0]}; 733 my ($parameter, $section); 1805 my ($parameter, $section); 734 1806 735 foreach $section (@{$args{'sectionlist'}}) 1807 foreach $section (@{$args{'sectionlist'}}) { 736 next if (defined($nosymbol_table{$sect !! 1808 if ($output_selection != OUTPUT_INCLUDE) { 737 !! 1809 print "**$section**\n\n"; 738 if ($output_selection != OUTPUT_INCLUD !! 1810 } 739 print ".. _$section:\n\n"; << 740 print "**$section**\n\n"; << 741 } << 742 print_lineno($section_start_lines{$sec 1811 print_lineno($section_start_lines{$section}); 743 output_highlight_rst($args{'sections'} !! 1812 output_highlight_rst($args{'sections'}{$section}); 744 print "\n"; !! 1813 print "\n"; 745 } 1814 } 746 } 1815 } 747 1816 748 # << 749 # Apply the RST highlights to a sub-block of t << 750 # << 751 sub highlight_block($) { << 752 # The dohighlight kludge requires the text << 753 my $contents = shift; << 754 eval $dohighlight; << 755 die $@ if $@; << 756 return $contents; << 757 } << 758 << 759 # << 760 # Regexes used only here. << 761 # << 762 my $sphinx_literal = '^[^.].*::$'; << 763 my $sphinx_cblock = '^\.\.\ +code-block::'; << 764 << 765 sub output_highlight_rst { 1817 sub output_highlight_rst { 766 my $input = join "\n",@_; !! 1818 my $contents = join "\n",@_; 767 my $output = ""; << 768 my $line; 1819 my $line; 769 my $in_literal = 0; << 770 my $litprefix; << 771 my $block = ""; << 772 << 773 foreach $line (split "\n",$input) { << 774 # << 775 # If we're in a literal block, see if << 776 # of it. Otherwise pass the line stra << 777 # << 778 if ($in_literal) { << 779 if (! ($line =~ /^\s*$/)) { << 780 # << 781 # If this is the first non-bla << 782 # block we need to figure out << 783 # << 784 if ($litprefix eq "") { << 785 $line =~ /^(\s*)/; << 786 $litprefix = '^' . $1; << 787 $output .= $line . "\n"; << 788 } elsif (! ($line =~ /$litpref << 789 $in_literal = 0; << 790 } else { << 791 $output .= $line . "\n"; << 792 } << 793 } else { << 794 $output .= $line . "\n"; << 795 } << 796 } << 797 # << 798 # Not in a literal block (or just drop << 799 # << 800 if (! $in_literal) { << 801 $block .= $line . "\n"; << 802 if (($line =~ /$sphinx_literal/) | << 803 $in_literal = 1; << 804 $litprefix = ""; << 805 $output .= highlight_block($bl << 806 $block = "" << 807 } << 808 } << 809 } << 810 1820 811 if ($block) { !! 1821 # undo the evil effects of xml_escape() earlier 812 $output .= highlight_block($block); !! 1822 $contents = xml_unescape($contents); 813 } !! 1823 814 foreach $line (split "\n", $output) { !! 1824 eval $dohighlight; 815 print $lineprefix . $line . "\n"; !! 1825 die $@ if $@; >> 1826 >> 1827 foreach $line (split "\n", $contents) { >> 1828 print $lineprefix . $line . "\n"; 816 } 1829 } 817 } 1830 } 818 1831 819 sub output_function_rst(%) { 1832 sub output_function_rst(%) { 820 my %args = %{$_[0]}; 1833 my %args = %{$_[0]}; 821 my ($parameter, $section); 1834 my ($parameter, $section); 822 my $oldprefix = $lineprefix; 1835 my $oldprefix = $lineprefix; >> 1836 my $start = ""; 823 1837 824 my $signature = ""; !! 1838 if ($args{'typedef'}) { >> 1839 print ".. c:type:: ". $args{'function'} . "\n\n"; >> 1840 print_lineno($declaration_start_line); >> 1841 print " **Typedef**: "; >> 1842 $lineprefix = ""; >> 1843 output_highlight_rst($args{'purpose'}); >> 1844 $start = "\n\n**Syntax**\n\n ``"; >> 1845 } else { >> 1846 print ".. c:function:: "; >> 1847 } 825 if ($args{'functiontype'} ne "") { 1848 if ($args{'functiontype'} ne "") { 826 $signature = $args{'functiontype'} . " !! 1849 $start .= $args{'functiontype'} . " " . $args{'function'} . " ("; 827 } else { 1850 } else { 828 $signature = $args{'function'} . " ("; !! 1851 $start .= $args{'function'} . " ("; 829 } 1852 } >> 1853 print $start; 830 1854 831 my $count = 0; 1855 my $count = 0; 832 foreach my $parameter (@{$args{'parameterl 1856 foreach my $parameter (@{$args{'parameterlist'}}) { 833 if ($count ne 0) { !! 1857 if ($count ne 0) { 834 $signature .= ", "; !! 1858 print ", "; 835 } !! 1859 } 836 $count++; !! 1860 $count++; 837 $type = $args{'parametertypes'}{$param !! 1861 $type = $args{'parametertypes'}{$parameter}; 838 !! 1862 839 if ($type =~ m/$function_pointer/) { !! 1863 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { 840 # pointer-to-function !! 1864 # pointer-to-function 841 $signature .= $1 . $parameter . ") !! 1865 print $1 . $parameter . ") (" . $2; 842 } else { !! 1866 } else { 843 $signature .= $type; !! 1867 print $type . " " . $parameter; 844 } !! 1868 } 845 } 1869 } 846 !! 1870 if ($args{'typedef'}) { 847 $signature .= ")"; !! 1871 print ");``\n\n"; 848 << 849 if ($sphinx_major < 3) { << 850 if ($args{'typedef'}) { << 851 print ".. c:type:: ". $args{'funct << 852 print_lineno($declaration_start_li << 853 print " **Typedef**: "; << 854 $lineprefix = ""; << 855 output_highlight_rst($args{'purpos << 856 print "\n\n**Syntax**\n\n"; << 857 print " ``$signature``\n\n"; << 858 } else { << 859 print ".. c:function:: $signature\ << 860 } << 861 } else { 1872 } else { 862 if ($args{'typedef'} || $args{'functio !! 1873 print ")\n\n"; 863 print ".. c:macro:: ". $args{'func !! 1874 print_lineno($declaration_start_line); 864 !! 1875 $lineprefix = " "; 865 if ($args{'typedef'}) { !! 1876 output_highlight_rst($args{'purpose'}); 866 print_lineno($declaration_star !! 1877 print "\n"; 867 print " **Typedef**: "; << 868 $lineprefix = ""; << 869 output_highlight_rst($args{'pu << 870 print "\n\n**Syntax**\n\n"; << 871 print " ``$signature``\n\n"; << 872 } else { << 873 print "``$signature``\n\n"; << 874 } << 875 } else { << 876 print ".. c:function:: $signature\ << 877 } << 878 } << 879 << 880 if (!$args{'typedef'}) { << 881 print_lineno($declaration_start_line); << 882 $lineprefix = " "; << 883 output_highlight_rst($args{'purpose'}) << 884 print "\n"; << 885 } 1878 } 886 1879 887 # !! 1880 print "**Parameters**\n\n"; 888 # Put our descriptive text into a containe << 889 # set the function prototypes apart. << 890 # << 891 print ".. container:: kernelindent\n\n"; << 892 $lineprefix = " "; 1881 $lineprefix = " "; 893 print $lineprefix . "**Parameters**\n\n"; << 894 foreach $parameter (@{$args{'parameterlist 1882 foreach $parameter (@{$args{'parameterlist'}}) { 895 my $parameter_name = $parameter; !! 1883 my $parameter_name = $parameter; 896 $parameter_name =~ s/\[.*//; !! 1884 #$parameter_name =~ s/\[.*//; 897 $type = $args{'parametertypes'}{$param !! 1885 $type = $args{'parametertypes'}{$parameter}; 898 !! 1886 899 if ($type ne "") { !! 1887 if ($type ne "") { 900 print $lineprefix . "``$type``\n"; !! 1888 print "``$type $parameter``\n"; 901 } else { !! 1889 } else { 902 print $lineprefix . "``$parameter` !! 1890 print "``$parameter``\n"; 903 } !! 1891 } 904 1892 905 print_lineno($parameterdesc_start_line 1893 print_lineno($parameterdesc_start_lines{$parameter_name}); 906 1894 907 $lineprefix = " "; !! 1895 if (defined($args{'parameterdescs'}{$parameter_name}) && 908 if (defined($args{'parameterdescs'}{$p !! 1896 $args{'parameterdescs'}{$parameter_name} ne $undescribed) { 909 $args{'parameterdescs'}{$parameter !! 1897 output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 910 output_highlight_rst($args{'parame !! 1898 } else { 911 } else { !! 1899 print " *undescribed*\n"; 912 print $lineprefix . "*undescribed* !! 1900 } 913 } !! 1901 print "\n"; 914 $lineprefix = " "; << 915 print "\n"; << 916 } 1902 } 917 1903 918 output_section_rst(@_); << 919 $lineprefix = $oldprefix; 1904 $lineprefix = $oldprefix; >> 1905 output_section_rst(@_); 920 } 1906 } 921 1907 922 sub output_section_rst(%) { 1908 sub output_section_rst(%) { 923 my %args = %{$_[0]}; 1909 my %args = %{$_[0]}; 924 my $section; 1910 my $section; 925 my $oldprefix = $lineprefix; 1911 my $oldprefix = $lineprefix; >> 1912 $lineprefix = ""; 926 1913 927 foreach $section (@{$args{'sectionlist'}}) 1914 foreach $section (@{$args{'sectionlist'}}) { 928 print $lineprefix . "**$section**\n\n" !! 1915 print "**$section**\n\n"; 929 print_lineno($section_start_lines{$sec 1916 print_lineno($section_start_lines{$section}); 930 output_highlight_rst($args{'sections'} !! 1917 output_highlight_rst($args{'sections'}{$section}); 931 print "\n"; !! 1918 print "\n"; 932 } 1919 } 933 print "\n"; 1920 print "\n"; >> 1921 $lineprefix = $oldprefix; 934 } 1922 } 935 1923 936 sub output_enum_rst(%) { 1924 sub output_enum_rst(%) { 937 my %args = %{$_[0]}; 1925 my %args = %{$_[0]}; 938 my ($parameter); 1926 my ($parameter); 939 my $oldprefix = $lineprefix; 1927 my $oldprefix = $lineprefix; 940 my $count; 1928 my $count; 941 my $outer; !! 1929 my $name = "enum " . $args{'enum'}; 942 1930 943 if ($sphinx_major < 3) { !! 1931 print "\n\n.. c:type:: " . $name . "\n\n"; 944 my $name = "enum " . $args{'enum'}; << 945 print "\n\n.. c:type:: " . $name . "\n << 946 } else { << 947 my $name = $args{'enum'}; << 948 print "\n\n.. c:enum:: " . $name . "\n << 949 } << 950 print_lineno($declaration_start_line); 1932 print_lineno($declaration_start_line); 951 $lineprefix = " "; !! 1933 $lineprefix = " "; 952 output_highlight_rst($args{'purpose'}); 1934 output_highlight_rst($args{'purpose'}); 953 print "\n"; 1935 print "\n"; 954 1936 955 print ".. container:: kernelindent\n\n"; !! 1937 print "**Constants**\n\n"; 956 $outer = $lineprefix . " "; !! 1938 $lineprefix = " "; 957 $lineprefix = $outer . " "; !! 1939 foreach $parameter (@{$args{'parameterlist'}}) { 958 print $outer . "**Constants**\n\n"; !! 1940 print "``$parameter``\n"; 959 foreach $parameter (@{$args{'parameterlist !! 1941 if ($args{'parameterdescs'}{$parameter} ne $undescribed) { 960 print $outer . "``$parameter``\n"; !! 1942 output_highlight_rst($args{'parameterdescs'}{$parameter}); 961 !! 1943 } else { 962 if ($args{'parameterdescs'}{$parameter !! 1944 print " *undescribed*\n"; 963 output_highlight_rst($args{'parame !! 1945 } 964 } else { !! 1946 print "\n"; 965 print $lineprefix . "*undescribed* << 966 } << 967 print "\n"; << 968 } 1947 } 969 print "\n"; !! 1948 970 $lineprefix = $oldprefix; 1949 $lineprefix = $oldprefix; 971 output_section_rst(@_); 1950 output_section_rst(@_); 972 } 1951 } 973 1952 974 sub output_typedef_rst(%) { 1953 sub output_typedef_rst(%) { 975 my %args = %{$_[0]}; 1954 my %args = %{$_[0]}; 976 my ($parameter); 1955 my ($parameter); 977 my $oldprefix = $lineprefix; 1956 my $oldprefix = $lineprefix; 978 my $name; !! 1957 my $name = "typedef " . $args{'typedef'}; 979 1958 980 if ($sphinx_major < 3) { << 981 $name = "typedef " . $args{'typedef'}; << 982 } else { << 983 $name = $args{'typedef'}; << 984 } << 985 print "\n\n.. c:type:: " . $name . "\n\n"; 1959 print "\n\n.. c:type:: " . $name . "\n\n"; 986 print_lineno($declaration_start_line); 1960 print_lineno($declaration_start_line); 987 $lineprefix = " "; 1961 $lineprefix = " "; 988 output_highlight_rst($args{'purpose'}); 1962 output_highlight_rst($args{'purpose'}); 989 print "\n"; 1963 print "\n"; 990 1964 991 $lineprefix = $oldprefix; 1965 $lineprefix = $oldprefix; 992 output_section_rst(@_); 1966 output_section_rst(@_); 993 } 1967 } 994 1968 995 sub output_struct_rst(%) { 1969 sub output_struct_rst(%) { 996 my %args = %{$_[0]}; 1970 my %args = %{$_[0]}; 997 my ($parameter); 1971 my ($parameter); 998 my $oldprefix = $lineprefix; 1972 my $oldprefix = $lineprefix; >> 1973 my $name = $args{'type'} . " " . $args{'struct'}; 999 1974 1000 if ($sphinx_major < 3) { !! 1975 print "\n\n.. c:type:: " . $name . "\n\n"; 1001 my $name = $args{'type'} . " " . $arg << 1002 print "\n\n.. c:type:: " . $name . "\ << 1003 } else { << 1004 my $name = $args{'struct'}; << 1005 if ($args{'type'} eq 'union') { << 1006 print "\n\n.. c:union:: " . $name << 1007 } else { << 1008 print "\n\n.. c:struct:: " . $nam << 1009 } << 1010 } << 1011 print_lineno($declaration_start_line); 1976 print_lineno($declaration_start_line); 1012 $lineprefix = " "; !! 1977 $lineprefix = " "; 1013 output_highlight_rst($args{'purpose'}); 1978 output_highlight_rst($args{'purpose'}); 1014 print "\n"; 1979 print "\n"; 1015 1980 1016 print ".. container:: kernelindent\n\n"; !! 1981 print "**Definition**\n\n"; 1017 print $lineprefix . "**Definition**::\n\n !! 1982 print "::\n\n"; 1018 my $declaration = $args{'definition'}; !! 1983 print " " . $args{'type'} . " " . $args{'struct'} . " {\n"; 1019 $lineprefix = $lineprefix . " "; !! 1984 foreach $parameter (@{$args{'parameterlist'}}) { 1020 $declaration =~ s/\t/$lineprefix/g; !! 1985 if ($parameter =~ /^#/) { 1021 print $lineprefix . $args{'type'} . " " . !! 1986 print " " . "$parameter\n"; >> 1987 next; >> 1988 } >> 1989 >> 1990 my $parameter_name = $parameter; >> 1991 $parameter_name =~ s/\[.*//; >> 1992 >> 1993 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; >> 1994 $type = $args{'parametertypes'}{$parameter}; >> 1995 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) { >> 1996 # pointer-to-function >> 1997 print " $1 $parameter) ($2);\n"; >> 1998 } elsif ($type =~ m/^(.*?)\s*(:.*)/) { >> 1999 # bitfield >> 2000 print " $1 $parameter$2;\n"; >> 2001 } else { >> 2002 print " " . $type . " " . $parameter . ";\n"; >> 2003 } >> 2004 } >> 2005 print " };\n\n"; 1022 2006 >> 2007 print "**Members**\n\n"; 1023 $lineprefix = " "; 2008 $lineprefix = " "; 1024 print $lineprefix . "**Members**\n\n"; << 1025 foreach $parameter (@{$args{'parameterlis 2009 foreach $parameter (@{$args{'parameterlist'}}) { 1026 ($parameter =~ /^#/) && next; !! 2010 ($parameter =~ /^#/) && next; 1027 2011 1028 my $parameter_name = $parameter; !! 2012 my $parameter_name = $parameter; 1029 $parameter_name =~ s/\[.*//; !! 2013 $parameter_name =~ s/\[.*//; 1030 2014 1031 ($args{'parameterdescs'}{$parameter_n !! 2015 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next; 1032 $type = $args{'parametertypes'}{$para !! 2016 $type = $args{'parametertypes'}{$parameter}; 1033 print_lineno($parameterdesc_start_lin 2017 print_lineno($parameterdesc_start_lines{$parameter_name}); 1034 print $lineprefix . "``" . $parameter !! 2018 print "``" . $parameter . "``\n"; 1035 $lineprefix = " "; !! 2019 output_highlight_rst($args{'parameterdescs'}{$parameter_name}); 1036 output_highlight_rst($args{'parameter !! 2020 print "\n"; 1037 $lineprefix = " "; << 1038 print "\n"; << 1039 } 2021 } 1040 print "\n"; 2022 print "\n"; 1041 2023 1042 $lineprefix = $oldprefix; 2024 $lineprefix = $oldprefix; 1043 output_section_rst(@_); 2025 output_section_rst(@_); 1044 } 2026 } 1045 2027 1046 ## none mode output functions << 1047 2028 1048 sub output_function_none(%) { !! 2029 ## list mode output functions >> 2030 >> 2031 sub output_function_list(%) { >> 2032 my %args = %{$_[0]}; >> 2033 >> 2034 print $args{'function'} . "\n"; 1049 } 2035 } 1050 2036 1051 sub output_enum_none(%) { !! 2037 # output enum in list >> 2038 sub output_enum_list(%) { >> 2039 my %args = %{$_[0]}; >> 2040 print $args{'enum'} . "\n"; 1052 } 2041 } 1053 2042 1054 sub output_typedef_none(%) { !! 2043 # output typedef in list >> 2044 sub output_typedef_list(%) { >> 2045 my %args = %{$_[0]}; >> 2046 print $args{'typedef'} . "\n"; 1055 } 2047 } 1056 2048 1057 sub output_struct_none(%) { !! 2049 # output struct as list >> 2050 sub output_struct_list(%) { >> 2051 my %args = %{$_[0]}; >> 2052 >> 2053 print $args{'struct'} . "\n"; 1058 } 2054 } 1059 2055 1060 sub output_blockhead_none(%) { !! 2056 sub output_blockhead_list(%) { >> 2057 my %args = %{$_[0]}; >> 2058 my ($parameter, $section); >> 2059 >> 2060 foreach $section (@{$args{'sectionlist'}}) { >> 2061 print "DOC: $section\n"; >> 2062 } 1061 } 2063 } 1062 2064 1063 ## 2065 ## 1064 # generic output function for all types (func 2066 # generic output function for all types (function, struct/union, typedef, enum); 1065 # calls the generated, variable output_ funct 2067 # calls the generated, variable output_ function name based on 1066 # functype and output_mode 2068 # functype and output_mode 1067 sub output_declaration { 2069 sub output_declaration { 1068 no strict 'refs'; 2070 no strict 'refs'; 1069 my $name = shift; 2071 my $name = shift; 1070 my $functype = shift; 2072 my $functype = shift; 1071 my $func = "output_${functype}_$output_mo 2073 my $func = "output_${functype}_$output_mode"; 1072 << 1073 return if (defined($nosymbol_table{$name} << 1074 << 1075 if (($output_selection == OUTPUT_ALL) || 2074 if (($output_selection == OUTPUT_ALL) || 1076 (($output_selection == OUTPUT_INCLUDE !! 2075 (($output_selection == OUTPUT_INCLUDE || 1077 $output_selection == OUTPUT_EXPORTE !! 2076 $output_selection == OUTPUT_EXPORTED) && 1078 defined($function_table{$name})) || !! 2077 defined($function_table{$name})) || 1079 ($output_selection == OUTPUT_INTERNAL !! 2078 (($output_selection == OUTPUT_EXCLUDE || 1080 !($functype eq "function" && defined !! 2079 $output_selection == OUTPUT_INTERNAL) && >> 2080 !($functype eq "function" && defined($function_table{$name})))) 1081 { 2081 { 1082 &$func(@_); !! 2082 &$func(@_); 1083 $section_counter++; !! 2083 $section_counter++; 1084 } 2084 } 1085 } 2085 } 1086 2086 1087 ## 2087 ## 1088 # generic output function - calls the right o 2088 # generic output function - calls the right one based on current output mode. 1089 sub output_blockhead { 2089 sub output_blockhead { 1090 no strict 'refs'; 2090 no strict 'refs'; 1091 my $func = "output_blockhead_" . $output_ 2091 my $func = "output_blockhead_" . $output_mode; 1092 &$func(@_); 2092 &$func(@_); 1093 $section_counter++; 2093 $section_counter++; 1094 } 2094 } 1095 2095 1096 ## 2096 ## 1097 # takes a declaration (struct, union, enum, t 2097 # takes a declaration (struct, union, enum, typedef) and 1098 # invokes the right handler. NOT called for f 2098 # invokes the right handler. NOT called for functions. 1099 sub dump_declaration($$) { 2099 sub dump_declaration($$) { 1100 no strict 'refs'; 2100 no strict 'refs'; 1101 my ($prototype, $file) = @_; 2101 my ($prototype, $file) = @_; 1102 my $func = "dump_" . $decl_type; 2102 my $func = "dump_" . $decl_type; 1103 &$func(@_); 2103 &$func(@_); 1104 } 2104 } 1105 2105 1106 sub dump_union($$) { 2106 sub dump_union($$) { 1107 dump_struct(@_); 2107 dump_struct(@_); 1108 } 2108 } 1109 2109 1110 sub dump_struct($$) { 2110 sub dump_struct($$) { 1111 my $x = shift; 2111 my $x = shift; 1112 my $file = shift; 2112 my $file = shift; 1113 my $decl_type; !! 2113 my $nested; 1114 my $members; << 1115 my $type = qr{struct|union}; << 1116 # For capturing struct/union definition b << 1117 my $qualifiers = qr{$attribute|__packed|_ << 1118 my $definition_body = qr{\{(.*)\}\s*$qual << 1119 my $struct_members = qr{($type)([^\{\};]+ << 1120 2114 1121 if ($x =~ /($type)\s+(\w+)\s*$definition_ !! 2115 if ($x =~ /(struct|union)\s+(\w+)\s*{(.*)}/) { 1122 $decl_type = $1; !! 2116 #my $decl_type = $1; 1123 $declaration_name = $2; !! 2117 $declaration_name = $2; 1124 $members = $3; !! 2118 my $members = $3; 1125 } elsif ($x =~ /typedef\s+($type)\s*$defi !! 2119 1126 $decl_type = $1; !! 2120 # ignore embedded structs or unions 1127 $declaration_name = $3; !! 2121 $members =~ s/({.*})//g; 1128 $members = $2; !! 2122 $nested = $1; 1129 } !! 2123 1130 !! 2124 # ignore members marked private: 1131 if ($members) { !! 2125 $members =~ s/\/\*\s*private:.*?\/\*\s*public:.*?\*\///gosi; 1132 if ($identifier ne $declaration_name) !! 2126 $members =~ s/\/\*\s*private:.*//gosi; 1133 emit_warning("${file}:$.", "expec !! 2127 # strip comments: 1134 return; !! 2128 $members =~ s/\/\*.*?\*\///gos; 1135 } !! 2129 $nested =~ s/\/\*.*?\*\///gos; 1136 !! 2130 # strip kmemcheck_bitfield_{begin,end}.*; 1137 # ignore members marked private: !! 2131 $members =~ s/kmemcheck_bitfield_.*?;//gos; 1138 $members =~ s/\/\*\s*private:.*?\/\*\ !! 2132 # strip attributes 1139 $members =~ s/\/\*\s*private:.*//gosi !! 2133 $members =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 1140 # strip comments: !! 2134 $members =~ s/__aligned\s*\([^;]*\)//gos; 1141 $members =~ s/\/\*.*?\*\///gos; !! 2135 $members =~ s/\s*CRYPTO_MINALIGN_ATTR//gos; 1142 # strip attributes !! 2136 # replace DECLARE_BITMAP 1143 $members =~ s/\s*$attribute/ /gi; !! 2137 $members =~ s/DECLARE_BITMAP\s*\(([^,)]+), ([^,)]+)\)/unsigned long $1\[BITS_TO_LONGS($2)\]/gos; 1144 $members =~ s/\s*__aligned\s*\([^;]*\ !! 2138 1145 $members =~ s/\s*__counted_by\s*\([^; !! 2139 create_parameterlist($members, ';', $file); 1146 $members =~ s/\s*__counted_by_(le|be) !! 2140 check_sections($file, $declaration_name, "struct", $sectcheck, $struct_actual, $nested); 1147 $members =~ s/\s*__packed\s*/ /gos; !! 2141 1148 $members =~ s/\s*CRYPTO_MINALIGN_ATTR !! 2142 output_declaration($declaration_name, 1149 $members =~ s/\s*____cacheline_aligne !! 2143 'struct', 1150 $members =~ s/\s*____cacheline_aligne !! 2144 {'struct' => $declaration_name, 1151 # unwrap struct_group(): !! 2145 'module' => $modulename, 1152 # - first eat non-declaration paramet !! 2146 'parameterlist' => \@parameterlist, 1153 # - then remove macro, outer parens, !! 2147 'parameterdescs' => \%parameterdescs, 1154 $members =~ s/\bstruct_group\s*\(([^, !! 2148 'parametertypes' => \%parametertypes, 1155 $members =~ s/\bstruct_group_attr\s*\ !! 2149 'sectionlist' => \@sectionlist, 1156 $members =~ s/\bstruct_group_tagged\s !! 2150 'sections' => \%sections, 1157 $members =~ s/\b__struct_group\s*\(([ !! 2151 'purpose' => $declaration_purpose, 1158 $members =~ s/\bSTRUCT_GROUP(\(((?:(? !! 2152 'type' => $decl_type 1159 !! 2153 }); 1160 my $args = qr{([^,)]+)}; !! 2154 } 1161 # replace DECLARE_BITMAP !! 2155 else { 1162 $members =~ s/__ETHTOOL_DECLARE_LINK_ !! 2156 print STDERR "${file}:$.: error: Cannot parse struct or union!\n"; 1163 $members =~ s/DECLARE_PHY_INTERFACE_M !! 2157 ++$errors; 1164 $members =~ s/DECLARE_BITMAP\s*\($arg << 1165 # replace DECLARE_HASHTABLE << 1166 $members =~ s/DECLARE_HASHTABLE\s*\($ << 1167 # replace DECLARE_KFIFO << 1168 $members =~ s/DECLARE_KFIFO\s*\($args << 1169 # replace DECLARE_KFIFO_PTR << 1170 $members =~ s/DECLARE_KFIFO_PTR\s*\($ << 1171 # replace DECLARE_FLEX_ARRAY << 1172 $members =~ s/(?:__)?DECLARE_FLEX_ARR << 1173 #replace DEFINE_DMA_UNMAP_ADDR << 1174 $members =~ s/DEFINE_DMA_UNMAP_ADDR\s << 1175 #replace DEFINE_DMA_UNMAP_LEN << 1176 $members =~ s/DEFINE_DMA_UNMAP_LEN\s* << 1177 my $declaration = $members; << 1178 << 1179 # Split nested struct/union elements << 1180 while ($members =~ m/$struct_members/ << 1181 my $newmember; << 1182 my $maintype = $1; << 1183 my $ids = $4; << 1184 my $content = $3; << 1185 foreach my $id(split /,/, $ids) { << 1186 $newmember .= "$maintype $id; << 1187 << 1188 $id =~ s/[:\[].*//; << 1189 $id =~ s/^\s*\**(\S+)\s*/$1/; << 1190 foreach my $arg (split /;/, $ << 1191 next if ($arg =~ m/^\s*$/ << 1192 if ($arg =~ m/^([^\(]+\(\ << 1193 # pointer-to-function << 1194 my $type = $1; << 1195 my $name = $2; << 1196 my $extra = $3; << 1197 next if (!$name); << 1198 if ($id =~ m/^\s*$/) << 1199 # anonymous struc << 1200 $newmember .= "$t << 1201 } else { << 1202 $newmember .= "$t << 1203 } << 1204 } else { << 1205 my $type; << 1206 my $names; << 1207 $arg =~ s/^\s+//; << 1208 $arg =~ s/\s+$//; << 1209 # Handle bitmaps << 1210 $arg =~ s/:\s*\d+\s*/ << 1211 # Handle arrays << 1212 $arg =~ s/\[.*\]//g; << 1213 # The type may have m << 1214 # and multiple IDs ca << 1215 # const struct foo << 1216 # So, we remove space << 1217 # names, in order to << 1218 # and commas for the << 1219 $arg =~ s/\s*,\s*/,/g << 1220 if ($arg =~ m/(.*)\s+ << 1221 $type = $1; << 1222 $names = $2; << 1223 } else { << 1224 $newmember .= "$a << 1225 next; << 1226 } << 1227 foreach my $name (spl << 1228 $name =~ s/^\s*\* << 1229 next if (($name = << 1230 if ($id =~ m/^\s* << 1231 # anonymous s << 1232 $newmember .= << 1233 } else { << 1234 $newmember .= << 1235 } << 1236 } << 1237 } << 1238 } << 1239 } << 1240 $members =~ s/$struct_members/$ne << 1241 } << 1242 << 1243 # Ignore other nested elements, like << 1244 $members =~ s/(\{[^\{\}]*\})//g; << 1245 << 1246 create_parameterlist($members, ';', $ << 1247 check_sections($file, $declaration_na << 1248 << 1249 # Adjust declaration for better displ << 1250 $declaration =~ s/([\{;])/$1\n/g; << 1251 $declaration =~ s/\}\s+;/};/g; << 1252 # Better handle inlined enums << 1253 do {} while ($declaration =~ s/(enum\ << 1254 << 1255 my @def_args = split /\n/, $declarati << 1256 my $level = 1; << 1257 $declaration = ""; << 1258 foreach my $clause (@def_args) { << 1259 $clause =~ s/^\s+//; << 1260 $clause =~ s/\s+$//; << 1261 $clause =~ s/\s+/ /; << 1262 next if (!$clause); << 1263 $level-- if ($clause =~ m/(\})/ & << 1264 if (!($clause =~ m/^\s*#/)) { << 1265 $declaration .= "\t" x $level << 1266 } << 1267 $declaration .= "\t" . $clause . << 1268 $level++ if ($clause =~ m/(\{)/ & << 1269 } << 1270 output_declaration($declaration_name, << 1271 'struct', << 1272 {'struct' => $declaration_ << 1273 'module' => $modulename, << 1274 'definition' => $declarat << 1275 'parameterlist' => \@para << 1276 'parameterdescs' => \%par << 1277 'parametertypes' => \%par << 1278 'sectionlist' => \@sectio << 1279 'sections' => \%sections, << 1280 'purpose' => $declaration << 1281 'type' => $decl_type << 1282 }); << 1283 } else { << 1284 print STDERR "${file}:$.: error: Cann << 1285 ++$errors; << 1286 } << 1287 } << 1288 << 1289 << 1290 sub show_warnings($$) { << 1291 my $functype = shift; << 1292 my $name = shift; << 1293 << 1294 return 0 if (defined($nosymbol_table{$nam << 1295 << 1296 return 1 if ($output_selection == OUTPUT_ << 1297 << 1298 if ($output_selection == OUTPUT_EXPORTED) << 1299 if (defined($function_table{$name})) << 1300 return 1; << 1301 } else { << 1302 return 0; << 1303 } << 1304 } << 1305 if ($output_selection == OUTPUT_INTERNAL) << 1306 if (!($functype eq "function" && defi << 1307 return 1; << 1308 } else { << 1309 return 0; << 1310 } << 1311 } << 1312 if ($output_selection == OUTPUT_INCLUDE) << 1313 if (defined($function_table{$name})) << 1314 return 1; << 1315 } else { << 1316 return 0; << 1317 } << 1318 } 2158 } 1319 die("Please add the new output type at sh << 1320 } 2159 } 1321 2160 1322 sub dump_enum($$) { 2161 sub dump_enum($$) { 1323 my $x = shift; 2162 my $x = shift; 1324 my $file = shift; 2163 my $file = shift; 1325 my $members; << 1326 << 1327 # ignore members marked private: << 1328 $x =~ s/\/\*\s*private:.*?\/\*\s*public:. << 1329 $x =~ s/\/\*\s*private:.*}/}/gosi; << 1330 2164 1331 $x =~ s@/\*.*?\*/@@gos; # strip comme 2165 $x =~ s@/\*.*?\*/@@gos; # strip comments. 1332 # strip #define macros inside enums 2166 # strip #define macros inside enums 1333 $x =~ s@#\s*((define|ifdef|if)\s+|endif)[ !! 2167 $x =~ s@#\s*((define|ifdef)\s+|endif)[^;]*;@@gos; 1334 2168 1335 if ($x =~ /typedef\s+enum\s*\{(.*)\}\s*(\ !! 2169 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) { 1336 $declaration_name = $2; !! 2170 $declaration_name = $1; 1337 $members = $1; !! 2171 my $members = $2; 1338 } elsif ($x =~ /enum\s+(\w*)\s*\{(.*)\}/) !! 2172 1339 $declaration_name = $1; !! 2173 foreach my $arg (split ',', $members) { 1340 $members = $2; !! 2174 $arg =~ s/^\s*(\w+).*/$1/; 1341 } !! 2175 push @parameterlist, $arg; 1342 !! 2176 if (!$parameterdescs{$arg}) { 1343 if ($members) { !! 2177 $parameterdescs{$arg} = $undescribed; 1344 if ($identifier ne $declaration_name) !! 2178 print STDERR "${file}:$.: warning: Enum value '$arg' ". 1345 if ($identifier eq "") { !! 2179 "not described in enum '$declaration_name'\n"; 1346 emit_warning("${file}:$.", "w !! 2180 } 1347 } else { !! 2181 1348 emit_warning("${file}:$.", "e !! 2182 } 1349 } !! 2183 1350 return; !! 2184 output_declaration($declaration_name, 1351 } !! 2185 'enum', 1352 $declaration_name = "(anonymous)" if !! 2186 {'enum' => $declaration_name, 1353 !! 2187 'module' => $modulename, 1354 my %_members; !! 2188 'parameterlist' => \@parameterlist, 1355 !! 2189 'parameterdescs' => \%parameterdescs, 1356 $members =~ s/\s+$//; !! 2190 'sectionlist' => \@sectionlist, 1357 $members =~ s/\([^;]*?[\)]//g; !! 2191 'sections' => \%sections, 1358 !! 2192 'purpose' => $declaration_purpose 1359 foreach my $arg (split ',', $members) !! 2193 }); 1360 $arg =~ s/^\s*(\w+).*/$1/; !! 2194 } 1361 push @parameterlist, $arg; !! 2195 else { 1362 if (!$parameterdescs{$arg}) { !! 2196 print STDERR "${file}:$.: error: Cannot parse enum!\n"; 1363 $parameterdescs{$arg} = $unde !! 2197 ++$errors; 1364 if (show_warnings("enum", $de << 1365 emit_warning("${file}:$." << 1366 } << 1367 } << 1368 $_members{$arg} = 1; << 1369 } << 1370 << 1371 while (my ($k, $v) = each %parameterd << 1372 if (!exists($_members{$k})) { << 1373 if (show_warnings("enum", $de << 1374 emit_warning("${file}:$." << 1375 } << 1376 } << 1377 } << 1378 << 1379 output_declaration($declaration_name, << 1380 'enum', << 1381 {'enum' => $declar << 1382 'module' => $modu << 1383 'parameterlist' = << 1384 'parameterdescs' << 1385 'sectionlist' => << 1386 'sections' => \%s << 1387 'purpose' => $dec << 1388 }); << 1389 } else { << 1390 print STDERR "${file}:$.: error: Cann << 1391 ++$errors; << 1392 } 2198 } 1393 } 2199 } 1394 2200 1395 my $typedef_type = qr { ((?:\s+[\w\*]+\b){1,8 << 1396 my $typedef_ident = qr { \*?\s*(\w\S+)\s* }x; << 1397 my $typedef_args = qr { \s*\((.*)\); }x; << 1398 << 1399 my $typedef1 = qr { typedef$typedef_type\($ty << 1400 my $typedef2 = qr { typedef$typedef_type$type << 1401 << 1402 sub dump_typedef($$) { 2201 sub dump_typedef($$) { 1403 my $x = shift; 2202 my $x = shift; 1404 my $file = shift; 2203 my $file = shift; 1405 2204 1406 $x =~ s@/\*.*?\*/@@gos; # strip comme 2205 $x =~ s@/\*.*?\*/@@gos; # strip comments. 1407 2206 1408 # Parse function typedef prototypes !! 2207 # Parse function prototypes 1409 if ($x =~ $typedef1 || $x =~ $typedef2) { !! 2208 if ($x =~ /typedef\s+(\w+)\s*\(\*\s*(\w\S+)\s*\)\s*\((.*)\);/ || 1410 $return_type = $1; !! 2209 $x =~ /typedef\s+(\w+)\s*(\w\S+)\s*\s*\((.*)\);/) { 1411 $declaration_name = $2; !! 2210 1412 my $args = $3; !! 2211 # Function typedefs 1413 $return_type =~ s/^\s+//; !! 2212 $return_type = $1; 1414 !! 2213 $declaration_name = $2; 1415 if ($identifier ne $declaration_name) !! 2214 my $args = $3; 1416 emit_warning("${file}:$.", "expec !! 2215 1417 return; !! 2216 create_parameterlist($args, ',', $file); 1418 } !! 2217 1419 !! 2218 output_declaration($declaration_name, 1420 create_parameterlist($args, ',', $fil !! 2219 'function', 1421 !! 2220 {'function' => $declaration_name, 1422 output_declaration($declaration_name, !! 2221 'typedef' => 1, 1423 'function', !! 2222 'module' => $modulename, 1424 {'function' => $de !! 2223 'functiontype' => $return_type, 1425 'typedef' => 1, !! 2224 'parameterlist' => \@parameterlist, 1426 'module' => $modu !! 2225 'parameterdescs' => \%parameterdescs, 1427 'functiontype' => !! 2226 'parametertypes' => \%parametertypes, 1428 'parameterlist' = !! 2227 'sectionlist' => \@sectionlist, 1429 'parameterdescs' !! 2228 'sections' => \%sections, 1430 'parametertypes' !! 2229 'purpose' => $declaration_purpose 1431 'sectionlist' => !! 2230 }); 1432 'sections' => \%s !! 2231 return; 1433 'purpose' => $dec << 1434 }); << 1435 return; << 1436 } 2232 } 1437 2233 1438 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\ 2234 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) { 1439 $x =~ s/\(*.\)\s*;$/;/; !! 2235 $x =~ s/\(*.\)\s*;$/;/; 1440 $x =~ s/\[*.\]\s*;$/;/; !! 2236 $x =~ s/\[*.\]\s*;$/;/; 1441 } 2237 } 1442 2238 1443 if ($x =~ /typedef.*\s+(\w+)\s*;/) { 2239 if ($x =~ /typedef.*\s+(\w+)\s*;/) { 1444 $declaration_name = $1; !! 2240 $declaration_name = $1; 1445 << 1446 if ($identifier ne $declaration_name) << 1447 emit_warning("${file}:$.", "expec << 1448 return; << 1449 } << 1450 2241 1451 output_declaration($declaration_name, !! 2242 output_declaration($declaration_name, 1452 'typedef', !! 2243 'typedef', 1453 {'typedef' => $dec !! 2244 {'typedef' => $declaration_name, 1454 'module' => $modu !! 2245 'module' => $modulename, 1455 'sectionlist' => !! 2246 'sectionlist' => \@sectionlist, 1456 'sections' => \%s !! 2247 'sections' => \%sections, 1457 'purpose' => $dec !! 2248 'purpose' => $declaration_purpose 1458 }); !! 2249 }); 1459 } else { !! 2250 } 1460 print STDERR "${file}:$.: error: Cann !! 2251 else { 1461 ++$errors; !! 2252 print STDERR "${file}:$.: error: Cannot parse typedef!\n"; >> 2253 ++$errors; 1462 } 2254 } 1463 } 2255 } 1464 2256 1465 sub save_struct_actual($) { 2257 sub save_struct_actual($) { 1466 my $actual = shift; 2258 my $actual = shift; 1467 2259 1468 # strip all spaces from the actual param 2260 # strip all spaces from the actual param so that it looks like one string item 1469 $actual =~ s/\s*//g; 2261 $actual =~ s/\s*//g; 1470 $struct_actual = $struct_actual . $actual 2262 $struct_actual = $struct_actual . $actual . " "; 1471 } 2263 } 1472 2264 1473 sub create_parameterlist($$$$) { !! 2265 sub create_parameterlist($$$) { 1474 my $args = shift; 2266 my $args = shift; 1475 my $splitter = shift; 2267 my $splitter = shift; 1476 my $file = shift; 2268 my $file = shift; 1477 my $declaration_name = shift; << 1478 my $type; 2269 my $type; 1479 my $param; 2270 my $param; 1480 2271 1481 # temporarily replace commas inside funct 2272 # temporarily replace commas inside function pointer definition 1482 my $arg_expr = qr{\([^\),]+}; !! 2273 while ($args =~ /(\([^\),]+),/) { 1483 while ($args =~ /$arg_expr,/) { !! 2274 $args =~ s/(\([^\),]+),/$1#/g; 1484 $args =~ s/($arg_expr),/$1#/g; << 1485 } 2275 } 1486 2276 1487 foreach my $arg (split($splitter, $args)) 2277 foreach my $arg (split($splitter, $args)) { 1488 # strip comments !! 2278 # strip comments 1489 $arg =~ s/\/\*.*\*\///; !! 2279 $arg =~ s/\/\*.*\*\///; 1490 # ignore argument attributes !! 2280 # strip leading/trailing spaces 1491 $arg =~ s/\sPOS0?\s/ /; !! 2281 $arg =~ s/^\s*//; 1492 # strip leading/trailing spaces !! 2282 $arg =~ s/\s*$//; 1493 $arg =~ s/^\s*//; !! 2283 $arg =~ s/\s+/ /; 1494 $arg =~ s/\s*$//; !! 2284 1495 $arg =~ s/\s+/ /; !! 2285 if ($arg =~ /^#/) { 1496 !! 2286 # Treat preprocessor directive as a typeless variable just to fill 1497 if ($arg =~ /^#/) { !! 2287 # corresponding data structures "correctly". Catch it later in 1498 # Treat preprocessor directive as !! 2288 # output_* subs. 1499 # corresponding data structures " !! 2289 push_parameter($arg, "", $file); 1500 # output_* subs. !! 2290 } elsif ($arg =~ m/\(.+\)\s*\(/) { 1501 push_parameter($arg, "", "", $fil !! 2291 # pointer-to-function 1502 } elsif ($arg =~ m/\(.+\)\s*\(/) { !! 2292 $arg =~ tr/#/,/; 1503 # pointer-to-function !! 2293 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/; 1504 $arg =~ tr/#/,/; !! 2294 $param = $1; 1505 $arg =~ m/[^\(]+\(\*?\s*([\w\[\]\ !! 2295 $type = $arg; 1506 $param = $1; !! 2296 $type =~ s/([^\(]+\(\*?)\s*$param/$1/; 1507 $type = $arg; !! 2297 save_struct_actual($param); 1508 $type =~ s/([^\(]+\(\*?)\s*$param !! 2298 push_parameter($param, $type, $file); 1509 save_struct_actual($param); !! 2299 } elsif ($arg) { 1510 push_parameter($param, $type, $ar !! 2300 $arg =~ s/\s*:\s*/:/g; 1511 } elsif ($arg =~ m/\(.+\)\s*\[/) { !! 2301 $arg =~ s/\s*\[/\[/g; 1512 # array-of-pointers !! 2302 1513 $arg =~ tr/#/,/; !! 2303 my @args = split('\s*,\s*', $arg); 1514 $arg =~ m/[^\(]+\(\s*\*\s*([\w\[\ !! 2304 if ($args[0] =~ m/\*/) { 1515 $param = $1; !! 2305 $args[0] =~ s/(\*+)\s*/ $1/; 1516 $type = $arg; !! 2306 } 1517 $type =~ s/([^\(]+\(\*?)\s*$param !! 2307 1518 save_struct_actual($param); !! 2308 my @first_arg; 1519 push_parameter($param, $type, $ar !! 2309 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) { 1520 } elsif ($arg) { !! 2310 shift @args; 1521 $arg =~ s/\s*:\s*/:/g; !! 2311 push(@first_arg, split('\s+', $1)); 1522 $arg =~ s/\s*\[/\[/g; !! 2312 push(@first_arg, $2); 1523 !! 2313 } else { 1524 my @args = split('\s*,\s*', $arg) !! 2314 @first_arg = split('\s+', shift @args); 1525 if ($args[0] =~ m/\*/) { !! 2315 } 1526 $args[0] =~ s/(\*+)\s*/ $1/; !! 2316 1527 } !! 2317 unshift(@args, pop @first_arg); 1528 !! 2318 $type = join " ", @first_arg; 1529 my @first_arg; !! 2319 1530 if ($args[0] =~ /^(.*\s+)(.*?\[.* !! 2320 foreach $param (@args) { 1531 shift @args; !! 2321 if ($param =~ m/^(\*+)\s*(.*)/) { 1532 push(@first_arg, split('\s+', !! 2322 save_struct_actual($2); 1533 push(@first_arg, $2); !! 2323 push_parameter($2, "$type $1", $file); 1534 } else { !! 2324 } 1535 @first_arg = split('\s+', shi !! 2325 elsif ($param =~ m/(.*?):(\d+)/) { 1536 } !! 2326 if ($type ne "") { # skip unnamed bit-fields 1537 !! 2327 save_struct_actual($1); 1538 unshift(@args, pop @first_arg); !! 2328 push_parameter($1, "$type:$2", $file) 1539 $type = join " ", @first_arg; !! 2329 } 1540 !! 2330 } 1541 foreach $param (@args) { !! 2331 else { 1542 if ($param =~ m/^(\*+)\s*(.*) !! 2332 save_struct_actual($param); 1543 save_struct_actual($2); !! 2333 push_parameter($param, $type, $file); 1544 !! 2334 } 1545 push_parameter($2, "$type !! 2335 } 1546 } elsif ($param =~ m/(.*?):(\ !! 2336 } 1547 if ($type ne "") { # skip !! 2337 } 1548 save_struct_actual($1 !! 2338 } 1549 push_parameter($1, "$ !! 2339 1550 } !! 2340 sub push_parameter($$$) { 1551 } else { !! 2341 my $param = shift; 1552 save_struct_actual($param !! 2342 my $type = shift; 1553 push_parameter($param, $t !! 2343 my $file = shift; 1554 } !! 2344 1555 } !! 2345 if (($anon_struct_union == 1) && ($type eq "") && 1556 } !! 2346 ($param eq "}")) { 1557 } !! 2347 return; # ignore the ending }; from anon. struct/union 1558 } !! 2348 } 1559 !! 2349 1560 sub push_parameter($$$$$) { !! 2350 $anon_struct_union = 0; 1561 my $param = shift; !! 2351 my $param_name = $param; 1562 my $type = shift; !! 2352 $param_name =~ s/\[.*//; 1563 my $org_arg = shift; !! 2353 1564 my $file = shift; !! 2354 if ($type eq "" && $param =~ /\.\.\.$/) 1565 my $declaration_name = shift; !! 2355 { 1566 !! 2356 $param = "..."; 1567 if (($anon_struct_union == 1) && ($type e !! 2357 if (!defined $parameterdescs{$param} || $parameterdescs{$param} eq "") { 1568 ($param eq "}")) { !! 2358 $parameterdescs{$param} = "variable arguments"; 1569 return; # ignore the ending }; !! 2359 } 1570 } !! 2360 } 1571 !! 2361 elsif ($type eq "" && ($param eq "" or $param eq "void")) 1572 $anon_struct_union = 0; !! 2362 { 1573 $param =~ s/[\[\)].*//; !! 2363 $param="void"; 1574 !! 2364 $parameterdescs{void} = "no arguments"; 1575 if ($type eq "" && $param =~ /\.\.\.$/) !! 2365 } 1576 { !! 2366 elsif ($type eq "" && ($param eq "struct" or $param eq "union")) 1577 if (!$param =~ /\w\.\.\.$/) { !! 2367 # handle unnamed (anonymous) union or struct: 1578 # handles unnamed variable parame !! 2368 { 1579 $param = "..."; !! 2369 $type = $param; 1580 } elsif ($param =~ /\w\.\.\.$/) { !! 2370 $param = "{unnamed_" . $param . "}"; 1581 # for named variable parameters o !! 2371 $parameterdescs{$param} = "anonymous\n"; 1582 $param =~ s/\.\.\.$//; !! 2372 $anon_struct_union = 1; 1583 } !! 2373 } 1584 if (!defined $parameterdescs{$param} !! 2374 1585 $parameterdescs{$param} = "variab !! 2375 # warn if parameter has no description 1586 } !! 2376 # (but ignore ones starting with # as these are not parameters 1587 } !! 2377 # but inline preprocessor statements); 1588 elsif ($type eq "" && ($param eq "" or $p !! 2378 # also ignore unnamed structs/unions; 1589 { !! 2379 if (!$anon_struct_union) { 1590 $param="void"; !! 2380 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { 1591 $parameterdescs{void} = "no arguments !! 2381 1592 } !! 2382 $parameterdescs{$param_name} = $undescribed; 1593 elsif ($type eq "" && ($param eq "struct" !! 2383 1594 # handle unnamed (anonymous) union or str !! 2384 if (($type eq 'function') || ($type eq 'enum')) { 1595 { !! 2385 print STDERR "${file}:$.: warning: Function parameter ". 1596 $type = $param; !! 2386 "or member '$param' not " . 1597 $param = "{unnamed_" . $param . "}"; !! 2387 "described in '$declaration_name'\n"; 1598 $parameterdescs{$param} = "anonymous\ !! 2388 } 1599 $anon_struct_union = 1; !! 2389 print STDERR "${file}:$.: warning:" . 1600 } !! 2390 " No description found for parameter '$param'\n"; 1601 elsif ($param =~ "__cacheline_group" ) !! 2391 ++$warnings; 1602 # handle cache group enforcing variables: !! 2392 } 1603 { !! 2393 } 1604 return; # ignore __cacheline_group_be !! 2394 1605 } !! 2395 $param = xml_escape($param); 1606 !! 2396 1607 # warn if parameter has no description !! 2397 # strip spaces from $param so that it is one continuous string 1608 # (but ignore ones starting with # as the !! 2398 # on @parameterlist; 1609 # but inline preprocessor statements); !! 2399 # this fixes a problem where check_sections() cannot find 1610 # Note: It will also ignore void params a !! 2400 # a parameter like "addr[6 + 2]" because it actually appears 1611 if (!defined $parameterdescs{$param} && $ !! 2401 # as "addr[6", "+", "2]" on the parameter list; 1612 $parameterdescs{$param} = $undescribe !! 2402 # but it's better to maintain the param string unchanged for output, 1613 !! 2403 # so just weaken the string compare in check_sections() to ignore 1614 if (show_warnings($type, $declaration !! 2404 # "[blah" in a parameter string; 1615 emit_warning("${file}:$.", "Funct !! 2405 ###$param =~ s/\s*//g; 1616 } !! 2406 push @parameterlist, $param; 1617 } !! 2407 $parametertypes{$param} = $type; 1618 !! 2408 } 1619 # strip spaces from $param so that it is !! 2409 1620 # on @parameterlist; !! 2410 sub check_sections($$$$$$) { 1621 # this fixes a problem where check_sectio !! 2411 my ($file, $decl_name, $decl_type, $sectcheck, $prmscheck, $nested) = @_; 1622 # a parameter like "addr[6 + 2]" because !! 2412 my @sects = split ' ', $sectcheck; 1623 # as "addr[6", "+", "2]" on the parameter !! 2413 my @prms = split ' ', $prmscheck; 1624 # but it's better to maintain the param s !! 2414 my $err; 1625 # so just weaken the string compare in ch !! 2415 my ($px, $sx); 1626 # "[blah" in a parameter string; !! 2416 my $prm_clean; # strip trailing "[array size]" and/or beginning "*" 1627 ###$param =~ s/\s*//g; !! 2417 1628 push @parameterlist, $param; !! 2418 foreach $sx (0 .. $#sects) { 1629 $org_arg =~ s/\s\s+/ /g; !! 2419 $err = 1; 1630 $parametertypes{$param} = $org_arg; !! 2420 foreach $px (0 .. $#prms) { 1631 } !! 2421 $prm_clean = $prms[$px]; 1632 !! 2422 $prm_clean =~ s/\[.*\]//; 1633 sub check_sections($$$$$) { !! 2423 $prm_clean =~ s/__attribute__\s*\(\([a-z,_\*\s\(\)]*\)\)//i; 1634 my ($file, $decl_name, $decl_type, $sectc !! 2424 # ignore array size in a parameter string; 1635 my @sects = split ' ', $sectcheck; !! 2425 # however, the original param string may contain 1636 my @prms = split ' ', $prmscheck; !! 2426 # spaces, e.g.: addr[6 + 2] 1637 my $err; !! 2427 # and this appears in @prms as "addr[6" since the 1638 my ($px, $sx); !! 2428 # parameter list is split at spaces; 1639 my $prm_clean; # strip trailing "[ !! 2429 # hence just ignore "[..." for the sections check; 1640 !! 2430 $prm_clean =~ s/\[.*//; 1641 foreach $sx (0 .. $#sects) { !! 2431 1642 $err = 1; !! 2432 ##$prm_clean =~ s/^\**//; 1643 foreach $px (0 .. $#prms) { !! 2433 if ($prm_clean eq $sects[$sx]) { 1644 $prm_clean = $prms[$px]; !! 2434 $err = 0; 1645 $prm_clean =~ s/\[.*\]//; !! 2435 last; 1646 $prm_clean =~ s/$attribute//i; !! 2436 } 1647 # ignore array size in a paramete !! 2437 } 1648 # however, the original param str !! 2438 if ($err) { 1649 # spaces, e.g.: addr[6 + 2] !! 2439 if ($decl_type eq "function") { 1650 # and this appears in @prms as "a !! 2440 print STDERR "${file}:$.: warning: " . 1651 # parameter list is split at spac !! 2441 "Excess function parameter " . 1652 # hence just ignore "[..." for th !! 2442 "'$sects[$sx]' " . 1653 $prm_clean =~ s/\[.*//; !! 2443 "description in '$decl_name'\n"; 1654 !! 2444 ++$warnings; 1655 ##$prm_clean =~ s/^\**//; !! 2445 } else { 1656 if ($prm_clean eq $sects[$sx]) { !! 2446 if ($nested !~ m/\Q$sects[$sx]\E/) { 1657 $err = 0; !! 2447 print STDERR "${file}:$.: warning: " . 1658 last; !! 2448 "Excess struct/union/enum/typedef member " . 1659 } !! 2449 "'$sects[$sx]' " . 1660 } !! 2450 "description in '$decl_name'\n"; 1661 if ($err) { !! 2451 ++$warnings; 1662 if ($decl_type eq "function") { !! 2452 } 1663 emit_warning("${file}:$.", !! 2453 } 1664 "Excess function paramete !! 2454 } 1665 "'$sects[$sx]' " . !! 2455 } 1666 "description in '$decl_na << 1667 } elsif (($decl_type eq "struct") << 1668 ($decl_type eq "uni << 1669 emit_warning("${file}:$.", << 1670 "Excess $decl_type member << 1671 "'$sects[$sx]' " . << 1672 "description in '$decl_na << 1673 } << 1674 } << 1675 } << 1676 } 2456 } 1677 2457 1678 ## 2458 ## 1679 # Checks the section describing the return va 2459 # Checks the section describing the return value of a function. 1680 sub check_return_section { 2460 sub check_return_section { 1681 my $file = shift; !! 2461 my $file = shift; 1682 my $declaration_name = shift; !! 2462 my $declaration_name = shift; 1683 my $return_type = shift; !! 2463 my $return_type = shift; 1684 !! 2464 1685 # Ignore an empty return type (It's a mac !! 2465 # Ignore an empty return type (It's a macro) 1686 # Ignore functions with a "void" return t !! 2466 # Ignore functions with a "void" return type. (But don't ignore "void *") 1687 if (($return_type eq "") || ($return_type !! 2467 if (($return_type eq "") || ($return_type =~ /void\s*\w*\s*$/)) { 1688 return; !! 2468 return; 1689 } !! 2469 } 1690 !! 2470 1691 if (!defined($sections{$section_return}) !! 2471 if (!defined($sections{$section_return}) || 1692 $sections{$section_return} eq "") !! 2472 $sections{$section_return} eq "") { 1693 { !! 2473 print STDERR "${file}:$.: warning: " . 1694 emit_warning("${file}:$.", !! 2474 "No description found for return value of " . 1695 "No description found fo !! 2475 "'$declaration_name'\n"; 1696 "'$declaration_name'\n") !! 2476 ++$warnings; 1697 } !! 2477 } 1698 } 2478 } 1699 2479 1700 ## 2480 ## 1701 # takes a function prototype and the name of 2481 # takes a function prototype and the name of the current file being 1702 # processed and spits out all the details sto 2482 # processed and spits out all the details stored in the global 1703 # arrays/hashes. 2483 # arrays/hashes. 1704 sub dump_function($$) { 2484 sub dump_function($$) { 1705 my $prototype = shift; 2485 my $prototype = shift; 1706 my $file = shift; 2486 my $file = shift; 1707 my $noret = 0; 2487 my $noret = 0; 1708 2488 1709 print_lineno($new_start_line); << 1710 << 1711 $prototype =~ s/^static +//; 2489 $prototype =~ s/^static +//; 1712 $prototype =~ s/^extern +//; 2490 $prototype =~ s/^extern +//; 1713 $prototype =~ s/^asmlinkage +//; 2491 $prototype =~ s/^asmlinkage +//; 1714 $prototype =~ s/^inline +//; 2492 $prototype =~ s/^inline +//; 1715 $prototype =~ s/^__inline__ +//; 2493 $prototype =~ s/^__inline__ +//; 1716 $prototype =~ s/^__inline +//; 2494 $prototype =~ s/^__inline +//; 1717 $prototype =~ s/^__always_inline +//; 2495 $prototype =~ s/^__always_inline +//; 1718 $prototype =~ s/^noinline +//; 2496 $prototype =~ s/^noinline +//; 1719 $prototype =~ s/^__FORTIFY_INLINE +//; << 1720 $prototype =~ s/__init +//; 2497 $prototype =~ s/__init +//; 1721 $prototype =~ s/__init_or_module +//; 2498 $prototype =~ s/__init_or_module +//; 1722 $prototype =~ s/__deprecated +//; << 1723 $prototype =~ s/__flatten +//; << 1724 $prototype =~ s/__meminit +//; 2499 $prototype =~ s/__meminit +//; 1725 $prototype =~ s/__must_check +//; 2500 $prototype =~ s/__must_check +//; 1726 $prototype =~ s/__weak +//; 2501 $prototype =~ s/__weak +//; 1727 $prototype =~ s/__sched +//; << 1728 $prototype =~ s/_noprof//; << 1729 $prototype =~ s/__printf\s*\(\s*\d*\s*,\s << 1730 $prototype =~ s/__(?:re)?alloc_size\s*\(\ << 1731 $prototype =~ s/__diagnose_as\s*\(\s*\S+\ << 1732 $prototype =~ s/DECL_BUCKET_PARAMS\s*\(\s << 1733 my $define = $prototype =~ s/^#\s*define\ 2502 my $define = $prototype =~ s/^#\s*define\s+//; #ak added 1734 $prototype =~ s/__attribute_const__ +//; !! 2503 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//; 1735 $prototype =~ s/__attribute__\s*\(\( << 1736 (?: << 1737 [\w\s]++ # attribut << 1738 (?:\([^)]*+\))? # attribut << 1739 \s*+,? # optional << 1740 )+ << 1741 \)\)\s+//x; << 1742 2504 1743 # Yes, this truly is vile. We are lookin 2505 # Yes, this truly is vile. We are looking for: 1744 # 1. Return type (may be nothing if we're 2506 # 1. Return type (may be nothing if we're looking at a macro) 1745 # 2. Function name 2507 # 2. Function name 1746 # 3. Function parameters. 2508 # 3. Function parameters. 1747 # 2509 # 1748 # All the while we have to watch out for 2510 # All the while we have to watch out for function pointer parameters 1749 # (which IIRC is what the two sections ar 2511 # (which IIRC is what the two sections are for), C types (these 1750 # regexps don't even start to express all 2512 # regexps don't even start to express all the possibilities), and 1751 # so on. 2513 # so on. 1752 # 2514 # 1753 # If you mess with these regexps, it's a 2515 # If you mess with these regexps, it's a good idea to check that 1754 # the following functions' documentation 2516 # the following functions' documentation still comes out right: 1755 # - parport_register_device (function poi 2517 # - parport_register_device (function pointer parameters) 1756 # - atomic_set (macro) 2518 # - atomic_set (macro) 1757 # - pci_match_device, __copy_to_user (lon 2519 # - pci_match_device, __copy_to_user (long return type) 1758 my $name = qr{[a-zA-Z0-9_~:]+}; << 1759 my $prototype_end1 = qr{[^\(]*}; << 1760 my $prototype_end2 = qr{[^\{]*}; << 1761 my $prototype_end = qr{\(($prototype_end1 << 1762 my $type1 = qr{[\w\s]+}; << 1763 my $type2 = qr{$type1\*+}; << 1764 2520 1765 if ($define && $prototype =~ m/^()($name) !! 2521 if ($define && $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s+/) { 1766 # This is an object-like macro, it ha 2522 # This is an object-like macro, it has no return type and no parameter 1767 # list. 2523 # list. 1768 # Function-like macros are not allowe 2524 # Function-like macros are not allowed to have spaces between 1769 # declaration_name and opening parent 2525 # declaration_name and opening parenthesis (notice the \s+). 1770 $return_type = $1; 2526 $return_type = $1; 1771 $declaration_name = $2; 2527 $declaration_name = $2; 1772 $noret = 1; 2528 $noret = 1; 1773 } elsif ($prototype =~ m/^()($name)\s*$pr !! 2529 } elsif ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1774 $prototype =~ m/^($type1)\s+($name)\s !! 2530 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1775 $prototype =~ m/^($type2+)\s*($name)\ !! 2531 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1776 $return_type = $1; !! 2532 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1777 $declaration_name = $2; !! 2533 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || 1778 my $args = $3; !! 2534 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || >> 2535 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ || >> 2536 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || >> 2537 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || >> 2538 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || >> 2539 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || >> 2540 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || >> 2541 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || >> 2542 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || >> 2543 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || >> 2544 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ || >> 2545 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) { >> 2546 $return_type = $1; >> 2547 $declaration_name = $2; >> 2548 my $args = $3; 1779 2549 1780 create_parameterlist($args, ',', $fil !! 2550 create_parameterlist($args, ',', $file); 1781 } else { 2551 } else { 1782 emit_warning("${file}:$.", "cannot un !! 2552 print STDERR "${file}:$.: warning: cannot understand function prototype: '$prototype'\n"; 1783 return; !! 2553 return; 1784 } 2554 } 1785 2555 1786 if ($identifier ne $declaration_name) { !! 2556 my $prms = join " ", @parameterlist; 1787 emit_warning("${file}:$.", "expecting !! 2557 check_sections($file, $declaration_name, "function", $sectcheck, $prms, ""); 1788 return; << 1789 } << 1790 << 1791 my $prms = join " ", @parameterlist; << 1792 check_sections($file, $declaration_name, << 1793 2558 1794 # This check emits a lot of warnings at t !! 2559 # This check emits a lot of warnings at the moment, because many 1795 # functions don't have a 'Return' doc sec !! 2560 # functions don't have a 'Return' doc section. So until the number 1796 # of warnings goes sufficiently down, the !! 2561 # of warnings goes sufficiently down, the check is only performed in 1797 # -Wreturn mode. !! 2562 # verbose mode. 1798 # TODO: always perform the check. !! 2563 # TODO: always perform the check. 1799 if ($Wreturn && !$noret) { !! 2564 if ($verbose && !$noret) { 1800 check_return_section($file, $declarat !! 2565 check_return_section($file, $declaration_name, $return_type); 1801 } !! 2566 } 1802 !! 2567 1803 # The function parser can be called with !! 2568 output_declaration($declaration_name, 1804 # Handle it. !! 2569 'function', 1805 if ($return_type =~ /typedef/) { !! 2570 {'function' => $declaration_name, 1806 output_declaration($declaration_name, !! 2571 'module' => $modulename, 1807 'function', !! 2572 'functiontype' => $return_type, 1808 {'function' => $de !! 2573 'parameterlist' => \@parameterlist, 1809 'typedef' => 1, !! 2574 'parameterdescs' => \%parameterdescs, 1810 'module' => $modu !! 2575 'parametertypes' => \%parametertypes, 1811 'functiontype' => !! 2576 'sectionlist' => \@sectionlist, 1812 'parameterlist' = !! 2577 'sections' => \%sections, 1813 'parameterdescs' !! 2578 'purpose' => $declaration_purpose 1814 'parametertypes' !! 2579 }); 1815 'sectionlist' => << 1816 'sections' => \%s << 1817 'purpose' => $dec << 1818 }); << 1819 } else { << 1820 output_declaration($declaration_name, << 1821 'function', << 1822 {'function' => $de << 1823 'module' => $modu << 1824 'functiontype' => << 1825 'parameterlist' = << 1826 'parameterdescs' << 1827 'parametertypes' << 1828 'sectionlist' => << 1829 'sections' => \%s << 1830 'purpose' => $dec << 1831 }); << 1832 } << 1833 } 2580 } 1834 2581 1835 sub reset_state { 2582 sub reset_state { 1836 $function = ""; 2583 $function = ""; 1837 %parameterdescs = (); 2584 %parameterdescs = (); 1838 %parametertypes = (); 2585 %parametertypes = (); 1839 @parameterlist = (); 2586 @parameterlist = (); 1840 %sections = (); 2587 %sections = (); 1841 @sectionlist = (); 2588 @sectionlist = (); 1842 $sectcheck = ""; 2589 $sectcheck = ""; 1843 $struct_actual = ""; 2590 $struct_actual = ""; 1844 $prototype = ""; 2591 $prototype = ""; 1845 2592 1846 $state = STATE_NORMAL; 2593 $state = STATE_NORMAL; 1847 $inline_doc_state = STATE_INLINE_NA; 2594 $inline_doc_state = STATE_INLINE_NA; 1848 } 2595 } 1849 2596 1850 sub tracepoint_munge($) { 2597 sub tracepoint_munge($) { 1851 my $file = shift; !! 2598 my $file = shift; 1852 my $tracepointname = 0; !! 2599 my $tracepointname = 0; 1853 my $tracepointargs = 0; !! 2600 my $tracepointargs = 0; 1854 !! 2601 1855 if ($prototype =~ m/TRACE_EVENT\((.*?),/) !! 2602 if ($prototype =~ m/TRACE_EVENT\((.*?),/) { 1856 $tracepointname = $1; !! 2603 $tracepointname = $1; 1857 } !! 2604 } 1858 if ($prototype =~ m/DEFINE_SINGLE_EVENT\( !! 2605 if ($prototype =~ m/DEFINE_SINGLE_EVENT\((.*?),/) { 1859 $tracepointname = $1; !! 2606 $tracepointname = $1; 1860 } !! 2607 } 1861 if ($prototype =~ m/DEFINE_EVENT\((.*?),( !! 2608 if ($prototype =~ m/DEFINE_EVENT\((.*?),(.*?),/) { 1862 $tracepointname = $2; !! 2609 $tracepointname = $2; 1863 } !! 2610 } 1864 $tracepointname =~ s/^\s+//; #strip leadi !! 2611 $tracepointname =~ s/^\s+//; #strip leading whitespace 1865 if ($prototype =~ m/TP_PROTO\((.*?)\)/) { !! 2612 if ($prototype =~ m/TP_PROTO\((.*?)\)/) { 1866 $tracepointargs = $1; !! 2613 $tracepointargs = $1; 1867 } !! 2614 } 1868 if (($tracepointname eq 0) || ($tracepoin !! 2615 if (($tracepointname eq 0) || ($tracepointargs eq 0)) { 1869 emit_warning("${file}:$.", "Unrecogni !! 2616 print STDERR "${file}:$.: warning: Unrecognized tracepoint format: \n". 1870 "$prototype\n"); !! 2617 "$prototype\n"; 1871 } else { !! 2618 } else { 1872 $prototype = "static inline void trac !! 2619 $prototype = "static inline void trace_$tracepointname($tracepointargs)"; 1873 $identifier = "trace_$identifier"; !! 2620 } 1874 } << 1875 } 2621 } 1876 2622 1877 sub syscall_munge() { 2623 sub syscall_munge() { 1878 my $void = 0; !! 2624 my $void = 0; 1879 << 1880 $prototype =~ s@[\r\n]+@ @gos; # strip ne << 1881 ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\ << 1882 if ($prototype =~ m/SYSCALL_DEFINE0/) { << 1883 $void = 1; << 1884 ## $prototype = "long sys_$1(void)"; << 1885 } << 1886 2625 1887 $prototype =~ s/SYSCALL_DEFINE.*\(/long s !! 2626 $prototype =~ s@[\r\n\t]+@ @gos; # strip newlines/CR's/tabs 1888 if ($prototype =~ m/long (sys_.*?),/) { !! 2627 ## if ($prototype =~ m/SYSCALL_DEFINE0\s*\(\s*(a-zA-Z0-9_)*\s*\)/) { 1889 $prototype =~ s/,/\(/; !! 2628 if ($prototype =~ m/SYSCALL_DEFINE0/) { 1890 } elsif ($void) { !! 2629 $void = 1; 1891 $prototype =~ s/\)/\(void\)/; !! 2630 ## $prototype = "long sys_$1(void)"; 1892 } !! 2631 } 1893 !! 2632 1894 # now delete all of the odd-number commas !! 2633 $prototype =~ s/SYSCALL_DEFINE.*\(/long sys_/; # fix return type & func name 1895 # so that arg types & arg names don't hav !! 2634 if ($prototype =~ m/long (sys_.*?),/) { 1896 my $count = 0; !! 2635 $prototype =~ s/,/\(/; 1897 my $len = length($prototype); !! 2636 } elsif ($void) { 1898 if ($void) { !! 2637 $prototype =~ s/\)/\(void\)/; 1899 $len = 0; # skip the for-loop !! 2638 } 1900 } !! 2639 1901 for (my $ix = 0; $ix < $len; $ix++) { !! 2640 # now delete all of the odd-number commas in $prototype 1902 if (substr($prototype, $ix, 1) eq ',' !! 2641 # so that arg types & arg names don't have a comma between them 1903 $count++; !! 2642 my $count = 0; 1904 if ($count % 2 == 1) { !! 2643 my $len = length($prototype); 1905 substr($prototype, $ix, 1) = !! 2644 if ($void) { 1906 } !! 2645 $len = 0; # skip the for-loop 1907 } !! 2646 } 1908 } !! 2647 for (my $ix = 0; $ix < $len; $ix++) { >> 2648 if (substr($prototype, $ix, 1) eq ',') { >> 2649 $count++; >> 2650 if ($count % 2 == 1) { >> 2651 substr($prototype, $ix, 1) = ' '; >> 2652 } >> 2653 } >> 2654 } 1909 } 2655 } 1910 2656 1911 sub process_proto_function($$) { 2657 sub process_proto_function($$) { 1912 my $x = shift; 2658 my $x = shift; 1913 my $file = shift; 2659 my $file = shift; 1914 2660 1915 $x =~ s@\/\/.*$@@gos; # strip C99-style c 2661 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 1916 2662 1917 if ($x =~ /^#/ && $x !~ /^#\s*define/) { !! 2663 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#\s*define/)) { 1918 # do nothing !! 2664 # do nothing 1919 } elsif ($x =~ /([^\{]*)/) { !! 2665 } 1920 $prototype .= $1; !! 2666 elsif ($x =~ /([^\{]*)/) { >> 2667 $prototype .= $1; 1921 } 2668 } 1922 2669 1923 if (($x =~ /\{/) || ($x =~ /\#\s*define/) 2670 if (($x =~ /\{/) || ($x =~ /\#\s*define/) || ($x =~ /;/)) { 1924 $prototype =~ s@/\*.*?\*/@@gos; !! 2671 $prototype =~ s@/\*.*?\*/@@gos; # strip comments. 1925 $prototype =~ s@[\r\n]+@ @gos; # stri !! 2672 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 1926 $prototype =~ s@^\s+@@gos; # strip le !! 2673 $prototype =~ s@^\s+@@gos; # strip leading spaces 1927 !! 2674 if ($prototype =~ /SYSCALL_DEFINE/) { 1928 # Handle prototypes for function poin !! 2675 syscall_munge(); 1929 # int (*pcs_config)(struct foo) !! 2676 } 1930 $prototype =~ s@^(\S+\s+)\(\s*\*(\S+) !! 2677 if ($prototype =~ /TRACE_EVENT/ || $prototype =~ /DEFINE_EVENT/ || 1931 !! 2678 $prototype =~ /DEFINE_SINGLE_EVENT/) 1932 if ($prototype =~ /SYSCALL_DEFINE/) { !! 2679 { 1933 syscall_munge(); !! 2680 tracepoint_munge($file); 1934 } !! 2681 } 1935 if ($prototype =~ /TRACE_EVENT/ || $p !! 2682 dump_function($prototype, $file); 1936 $prototype =~ /DEFINE_SINGLE_EVEN !! 2683 reset_state(); 1937 { << 1938 tracepoint_munge($file); << 1939 } << 1940 dump_function($prototype, $file); << 1941 reset_state(); << 1942 } 2684 } 1943 } 2685 } 1944 2686 1945 sub process_proto_type($$) { 2687 sub process_proto_type($$) { 1946 my $x = shift; 2688 my $x = shift; 1947 my $file = shift; 2689 my $file = shift; 1948 2690 1949 $x =~ s@[\r\n]+@ @gos; # strip newlines/c 2691 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 1950 $x =~ s@^\s+@@gos; # strip leading spaces 2692 $x =~ s@^\s+@@gos; # strip leading spaces 1951 $x =~ s@\s+$@@gos; # strip trailing space 2693 $x =~ s@\s+$@@gos; # strip trailing spaces 1952 $x =~ s@\/\/.*$@@gos; # strip C99-style c 2694 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line 1953 2695 1954 if ($x =~ /^#/) { 2696 if ($x =~ /^#/) { 1955 # To distinguish preprocessor directi !! 2697 # To distinguish preprocessor directive from regular declaration later. 1956 $x .= ";"; !! 2698 $x .= ";"; 1957 } 2699 } 1958 2700 1959 while (1) { 2701 while (1) { 1960 if ( $x =~ /([^\{\};]*)([\{\};])(.*)/ !! 2702 if ( $x =~ /([^{};]*)([{};])(.*)/ ) { 1961 if( length $prototype ) { !! 2703 $prototype .= $1 . $2; 1962 $prototype .= " " !! 2704 ($2 eq '{') && $brcount++; 1963 } !! 2705 ($2 eq '}') && $brcount--; 1964 $prototype .= $1 . $2; !! 2706 if (($2 eq ';') && ($brcount == 0)) { 1965 ($2 eq '{') && $brcount++; !! 2707 dump_declaration($prototype, $file); 1966 ($2 eq '}') && $brcount--; !! 2708 reset_state(); 1967 if (($2 eq ';') && ($brcount == 0 !! 2709 last; 1968 dump_declaration($prototype, !! 2710 } 1969 reset_state(); !! 2711 $x = $3; 1970 last; !! 2712 } else { 1971 } !! 2713 $prototype .= $x; 1972 $x = $3; !! 2714 last; 1973 } else { !! 2715 } 1974 $prototype .= $x; << 1975 last; << 1976 } << 1977 } 2716 } 1978 } 2717 } 1979 2718 >> 2719 # xml_escape: replace <, >, and & in the text stream; >> 2720 # >> 2721 # however, formatting controls that are generated internally/locally in the >> 2722 # kernel-doc script are not escaped here; instead, they begin life like >> 2723 # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings >> 2724 # are converted to their mnemonic-expected output, without the 4 * '\' & ':', >> 2725 # just before actual output; (this is done by local_unescape()) >> 2726 sub xml_escape($) { >> 2727 my $text = shift; >> 2728 if (($output_mode eq "text") || ($output_mode eq "man")) { >> 2729 return $text; >> 2730 } >> 2731 $text =~ s/\&/\\\\\\amp;/g; >> 2732 $text =~ s/\</\\\\\\lt;/g; >> 2733 $text =~ s/\>/\\\\\\gt;/g; >> 2734 return $text; >> 2735 } >> 2736 >> 2737 # xml_unescape: reverse the effects of xml_escape >> 2738 sub xml_unescape($) { >> 2739 my $text = shift; >> 2740 if (($output_mode eq "text") || ($output_mode eq "man")) { >> 2741 return $text; >> 2742 } >> 2743 $text =~ s/\\\\\\amp;/\&/g; >> 2744 $text =~ s/\\\\\\lt;/</g; >> 2745 $text =~ s/\\\\\\gt;/>/g; >> 2746 return $text; >> 2747 } >> 2748 >> 2749 # convert local escape strings to html >> 2750 # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes) >> 2751 sub local_unescape($) { >> 2752 my $text = shift; >> 2753 if (($output_mode eq "text") || ($output_mode eq "man")) { >> 2754 return $text; >> 2755 } >> 2756 $text =~ s/\\\\\\\\lt:/</g; >> 2757 $text =~ s/\\\\\\\\gt:/>/g; >> 2758 return $text; >> 2759 } 1980 2760 1981 sub map_filename($) { 2761 sub map_filename($) { 1982 my $file; 2762 my $file; 1983 my ($orig_file) = @_; 2763 my ($orig_file) = @_; 1984 2764 1985 if (defined($ENV{'SRCTREE'})) { 2765 if (defined($ENV{'SRCTREE'})) { 1986 $file = "$ENV{'SRCTREE'}" . "/" . $or !! 2766 $file = "$ENV{'SRCTREE'}" . "/" . $orig_file; 1987 } else { 2767 } else { 1988 $file = $orig_file; !! 2768 $file = $orig_file; 1989 } 2769 } 1990 2770 1991 if (defined($source_map{$file})) { 2771 if (defined($source_map{$file})) { 1992 $file = $source_map{$file}; !! 2772 $file = $source_map{$file}; 1993 } 2773 } 1994 2774 1995 return $file; 2775 return $file; 1996 } 2776 } 1997 2777 1998 sub process_export_file($) { 2778 sub process_export_file($) { 1999 my ($orig_file) = @_; 2779 my ($orig_file) = @_; 2000 my $file = map_filename($orig_file); 2780 my $file = map_filename($orig_file); 2001 2781 2002 if (!open(IN,"<$file")) { 2782 if (!open(IN,"<$file")) { 2003 print STDERR "Error: Cannot open file !! 2783 print STDERR "Error: Cannot open file $file\n"; 2004 ++$errors; !! 2784 ++$errors; 2005 return; !! 2785 return; 2006 } 2786 } 2007 2787 2008 while (<IN>) { 2788 while (<IN>) { 2009 if (/$export_symbol/) { !! 2789 if (/$export_symbol/) { 2010 next if (defined($nosymbol_table{ !! 2790 $function_table{$2} = 1; 2011 $function_table{$2} = 1; !! 2791 } 2012 } << 2013 if (/$export_symbol_ns/) { << 2014 next if (defined($nosymbol_table{ << 2015 $function_table{$2} = 1; << 2016 } << 2017 } 2792 } 2018 2793 2019 close(IN); 2794 close(IN); 2020 } 2795 } 2021 2796 2022 # << 2023 # Parsers for the various processing states. << 2024 # << 2025 # STATE_NORMAL: looking for the /** to begin << 2026 # << 2027 sub process_normal() { << 2028 if (/$doc_start/o) { << 2029 $state = STATE_NAME; # next li << 2030 $in_doc_sect = 0; << 2031 $declaration_start_line = $. + 1; << 2032 } << 2033 } << 2034 << 2035 # << 2036 # STATE_NAME: Looking for the "name - descrip << 2037 # << 2038 sub process_name($$) { << 2039 my $file = shift; << 2040 my $descr; << 2041 << 2042 if (/$doc_block/o) { << 2043 $state = STATE_DOCBLOCK; << 2044 $contents = ""; << 2045 $new_start_line = $.; << 2046 << 2047 if ( $1 eq "" ) { << 2048 $section = $section_intro; << 2049 } else { << 2050 $section = $1; << 2051 } << 2052 } elsif (/$doc_decl/o) { << 2053 $identifier = $1; << 2054 my $is_kernel_comment = 0; << 2055 my $decl_start = qr{$doc_com}; << 2056 # test for pointer declaration type, << 2057 my $fn_type = qr{\w+\s*\*\s*}; << 2058 my $parenthesis = qr{\(\w*\)}; << 2059 my $decl_end = qr{[-:].*}; << 2060 if (/^$decl_start([\w\s]+?)$parenthes << 2061 $identifier = $1; << 2062 } << 2063 if ($identifier =~ m/^(struct|union|e << 2064 $decl_type = $1; << 2065 $identifier = $2; << 2066 $is_kernel_comment = 1; << 2067 } << 2068 # Look for foo() or static void foo() << 2069 # identifier << 2070 elsif (/^$decl_start$fn_type?(\w+)\s* << 2071 /^$decl_start$fn_type?(\w+.*)$par << 2072 $identifier = $1; << 2073 $decl_type = 'function'; << 2074 $identifier =~ s/^define\s+//; << 2075 $is_kernel_comment = 1; << 2076 } << 2077 $identifier =~ s/\s+$//; << 2078 << 2079 $state = STATE_BODY; << 2080 # if there's no @param blocks need to << 2081 # here << 2082 $contents = ""; << 2083 $section = $section_default; << 2084 $new_start_line = $. + 1; << 2085 if (/[-:](.*)/) { << 2086 # strip leading/trailing/multiple << 2087 $descr= $1; << 2088 $descr =~ s/^\s*//; << 2089 $descr =~ s/\s*$//; << 2090 $descr =~ s/\s+/ /g; << 2091 $declaration_purpose = $descr; << 2092 $state = STATE_BODY_MAYBE; << 2093 } else { << 2094 $declaration_purpose = ""; << 2095 } << 2096 << 2097 if (!$is_kernel_comment) { << 2098 emit_warning("${file}:$.", "This << 2099 $state = STATE_NORMAL; << 2100 } << 2101 << 2102 if (($declaration_purpose eq "") && $ << 2103 emit_warning("${file}:$.", "missi << 2104 } << 2105 << 2106 if ($identifier eq "" && $decl_type n << 2107 emit_warning("${file}:$.", "wrong << 2108 $state = STATE_NORMAL; << 2109 } << 2110 << 2111 if ($verbose) { << 2112 print STDERR "${file}:$.: info: S << 2113 } << 2114 } else { << 2115 emit_warning("${file}:$.", "Cannot un << 2116 $state = STATE_NORMAL; << 2117 } << 2118 } << 2119 << 2120 << 2121 # << 2122 # STATE_BODY and STATE_BODY_MAYBE: the bulk o << 2123 # << 2124 sub process_body($$) { << 2125 my $file = shift; << 2126 << 2127 if ($state == STATE_BODY_WITH_BLANK_LINE << 2128 dump_section($file, $section, $conten << 2129 $section = $section_default; << 2130 $new_start_line = $.; << 2131 $contents = ""; << 2132 } << 2133 << 2134 if (/$doc_sect/i) { # case insensitive fo << 2135 $in_doc_sect = 1; << 2136 $newsection = $1; << 2137 $newcontents = $2; << 2138 << 2139 # map the supported section names to << 2140 if ($newsection =~ m/^description$/i) << 2141 $newsection = $section_default; << 2142 } elsif ($newsection =~ m/^context$/i << 2143 $newsection = $section_context; << 2144 } elsif ($newsection =~ m/^returns?$/ << 2145 $newsection = $section_return; << 2146 } elsif ($newsection =~ m/^\@return$/ << 2147 # special: @return is a section, << 2148 $newsection = $section_return; << 2149 } << 2150 << 2151 if (($contents ne "") && ($contents n << 2152 if (!$in_doc_sect && $Wcontents_b << 2153 emit_warning("${file}:$.", "c << 2154 } << 2155 dump_section($file, $section, $co << 2156 $section = $section_default; << 2157 } << 2158 << 2159 $in_doc_sect = 1; << 2160 $state = STATE_BODY; << 2161 $contents = $newcontents; << 2162 $new_start_line = $.; << 2163 while (substr($contents, 0, 1) eq " " << 2164 $contents = substr($contents, 1); << 2165 } << 2166 if ($contents ne "") { << 2167 $contents .= "\n"; << 2168 } << 2169 $section = $newsection; << 2170 $leading_space = undef; << 2171 } elsif (/$doc_end/) { << 2172 if (($contents ne "") && ($contents n << 2173 dump_section($file, $section, $co << 2174 $section = $section_default; << 2175 $contents = ""; << 2176 } << 2177 # look for doc_com + <text> + doc_end << 2178 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\ << 2179 emit_warning("${file}:$.", "suspi << 2180 } << 2181 << 2182 $prototype = ""; << 2183 $state = STATE_PROTO; << 2184 $brcount = 0; << 2185 $new_start_line = $. + 1; << 2186 } elsif (/$doc_content/) { << 2187 if ($1 eq "") { << 2188 if ($section eq $section_context) << 2189 dump_section($file, $section, << 2190 $section = $section_default; << 2191 $contents = ""; << 2192 $new_start_line = $.; << 2193 $state = STATE_BODY; << 2194 } else { << 2195 if ($section ne $section_defa << 2196 $state = STATE_BODY_WITH_ << 2197 } else { << 2198 $state = STATE_BODY; << 2199 } << 2200 $contents .= "\n"; << 2201 } << 2202 } elsif ($state == STATE_BODY_MAYBE) << 2203 # Continued declaration purpose << 2204 chomp($declaration_purpose); << 2205 $declaration_purpose .= " " . $1; << 2206 $declaration_purpose =~ s/\s+/ /g << 2207 } else { << 2208 my $cont = $1; << 2209 if ($section =~ m/^@/ || $section << 2210 if (!defined $leading_space) << 2211 if ($cont =~ m/^(\s+)/) { << 2212 $leading_space = $1; << 2213 } else { << 2214 $leading_space = ""; << 2215 } << 2216 } << 2217 $cont =~ s/^$leading_space//; << 2218 } << 2219 $contents .= $cont . "\n"; << 2220 } << 2221 } else { << 2222 # i dont know - bad line? ignore. << 2223 emit_warning("${file}:$.", "bad line: << 2224 } << 2225 } << 2226 << 2227 << 2228 # << 2229 # STATE_PROTO: reading a function/whatever pr << 2230 # << 2231 sub process_proto($$) { << 2232 my $file = shift; << 2233 << 2234 if (/$doc_inline_oneline/) { << 2235 $section = $1; << 2236 $contents = $2; << 2237 if ($contents ne "") { << 2238 $contents .= "\n"; << 2239 dump_section($file, $section, $co << 2240 $section = $section_default; << 2241 $contents = ""; << 2242 } << 2243 } elsif (/$doc_inline_start/) { << 2244 $state = STATE_INLINE; << 2245 $inline_doc_state = STATE_INLINE_NAME << 2246 } elsif ($decl_type eq 'function') { << 2247 process_proto_function($_, $file); << 2248 } else { << 2249 process_proto_type($_, $file); << 2250 } << 2251 } << 2252 << 2253 # << 2254 # STATE_DOCBLOCK: within a DOC: block. << 2255 # << 2256 sub process_docblock($$) { << 2257 my $file = shift; << 2258 << 2259 if (/$doc_end/) { << 2260 dump_doc_section($file, $section, $co << 2261 $section = $section_default; << 2262 $contents = ""; << 2263 $function = ""; << 2264 %parameterdescs = (); << 2265 %parametertypes = (); << 2266 @parameterlist = (); << 2267 %sections = (); << 2268 @sectionlist = (); << 2269 $prototype = ""; << 2270 $state = STATE_NORMAL; << 2271 } elsif (/$doc_content/) { << 2272 if ( $1 eq "" ) { << 2273 $contents .= $blankline; << 2274 } else { << 2275 $contents .= $1 . "\n"; << 2276 } << 2277 } << 2278 } << 2279 << 2280 # << 2281 # STATE_INLINE: docbook comments within a pro << 2282 # << 2283 sub process_inline($$) { << 2284 my $file = shift; << 2285 << 2286 # First line (state 1) needs to be a @par << 2287 if ($inline_doc_state == STATE_INLINE_NAM << 2288 $section = $1; << 2289 $contents = $2; << 2290 $new_start_line = $.; << 2291 if ($contents ne "") { << 2292 while (substr($contents, 0, 1) eq << 2293 $contents = substr($contents, << 2294 } << 2295 $contents .= "\n"; << 2296 } << 2297 $inline_doc_state = STATE_INLINE_TEXT << 2298 # Documentation block end */ << 2299 } elsif (/$doc_inline_end/) { << 2300 if (($contents ne "") && ($contents n << 2301 dump_section($file, $section, $co << 2302 $section = $section_default; << 2303 $contents = ""; << 2304 } << 2305 $state = STATE_PROTO; << 2306 $inline_doc_state = STATE_INLINE_NA; << 2307 # Regular text << 2308 } elsif (/$doc_content/) { << 2309 if ($inline_doc_state == STATE_INLINE << 2310 $contents .= $1 . "\n"; << 2311 # nuke leading blank lines << 2312 if ($contents =~ /^\s*$/) { << 2313 $contents = ""; << 2314 } << 2315 } elsif ($inline_doc_state == STATE_I << 2316 $inline_doc_state = STATE_INLINE_ << 2317 emit_warning("${file}:$.", "Incor << 2318 } << 2319 } << 2320 } << 2321 << 2322 << 2323 sub process_file($) { 2797 sub process_file($) { 2324 my $file; 2798 my $file; >> 2799 my $identifier; >> 2800 my $func; >> 2801 my $descr; >> 2802 my $in_purpose = 0; 2325 my $initial_section_counter = $section_co 2803 my $initial_section_counter = $section_counter; 2326 my ($orig_file) = @_; 2804 my ($orig_file) = @_; >> 2805 my $leading_space; 2327 2806 2328 $file = map_filename($orig_file); 2807 $file = map_filename($orig_file); 2329 2808 2330 if (!open(IN_FILE,"<$file")) { !! 2809 if (!open(IN,"<$file")) { 2331 print STDERR "Error: Cannot open file !! 2810 print STDERR "Error: Cannot open file $file\n"; 2332 ++$errors; !! 2811 ++$errors; 2333 return; !! 2812 return; 2334 } 2813 } 2335 2814 2336 $. = 1; 2815 $. = 1; 2337 2816 2338 $section_counter = 0; 2817 $section_counter = 0; 2339 while (<IN_FILE>) { !! 2818 while (<IN>) { 2340 while (!/^ \*/ && s/\\\s*$//) { !! 2819 while (s/\\\s*$//) { 2341 $_ .= <IN_FILE>; !! 2820 $_ .= <IN>; 2342 } !! 2821 } 2343 # Replace tabs by spaces !! 2822 if ($state == STATE_NORMAL) { 2344 while ($_ =~ s/\t+/' ' x (length($&) !! 2823 if (/$doc_start/o) { 2345 # Hand this line to the appropriate s !! 2824 $state = STATE_NAME; # next line is always the function name 2346 if ($state == STATE_NORMAL) { !! 2825 $in_doc_sect = 0; 2347 process_normal(); !! 2826 $declaration_start_line = $. + 1; 2348 } elsif ($state == STATE_NAME) { !! 2827 } 2349 process_name($file, $_); !! 2828 } elsif ($state == STATE_NAME) {# this line is the function name (always) 2350 } elsif ($state == STATE_BODY || $sta !! 2829 if (/$doc_block/o) { 2351 $state == STATE_BODY_WITH_BL !! 2830 $state = STATE_DOCBLOCK; 2352 process_body($file, $_); !! 2831 $contents = ""; 2353 } elsif ($state == STATE_INLINE) { # !! 2832 $new_start_line = $. + 1; 2354 process_inline($file, $_); !! 2833 2355 } elsif ($state == STATE_PROTO) { !! 2834 if ( $1 eq "" ) { 2356 process_proto($file, $_); !! 2835 $section = $section_intro; 2357 } elsif ($state == STATE_DOCBLOCK) { !! 2836 } else { 2358 process_docblock($file, $_); !! 2837 $section = $1; 2359 } !! 2838 } 2360 } !! 2839 } 2361 !! 2840 elsif (/$doc_decl/o) { 2362 # Make sure we got something interesting. !! 2841 $identifier = $1; 2363 if ($initial_section_counter == $section_ !! 2842 if (/\s*([\w\s]+?)\s*-/) { 2364 output_mode ne "none") { !! 2843 $identifier = $1; 2365 if ($output_selection == OUTPUT_INCLU !! 2844 } 2366 emit_warning("${file}:1", "'$_' n !! 2845 2367 for keys %function_table; !! 2846 $state = STATE_FIELD; 2368 } else { !! 2847 # if there's no @param blocks need to set up default section 2369 emit_warning("${file}:1", "no str !! 2848 # here 2370 } !! 2849 $contents = ""; >> 2850 $section = $section_default; >> 2851 $new_start_line = $. + 1; >> 2852 if (/-(.*)/) { >> 2853 # strip leading/trailing/multiple spaces >> 2854 $descr= $1; >> 2855 $descr =~ s/^\s*//; >> 2856 $descr =~ s/\s*$//; >> 2857 $descr =~ s/\s+/ /g; >> 2858 $declaration_purpose = xml_escape($descr); >> 2859 $in_purpose = 1; >> 2860 } else { >> 2861 $declaration_purpose = ""; >> 2862 } >> 2863 >> 2864 if (($declaration_purpose eq "") && $verbose) { >> 2865 print STDERR "${file}:$.: warning: missing initial short description on line:\n"; >> 2866 print STDERR $_; >> 2867 ++$warnings; >> 2868 } >> 2869 >> 2870 if ($identifier =~ m/^struct/) { >> 2871 $decl_type = 'struct'; >> 2872 } elsif ($identifier =~ m/^union/) { >> 2873 $decl_type = 'union'; >> 2874 } elsif ($identifier =~ m/^enum/) { >> 2875 $decl_type = 'enum'; >> 2876 } elsif ($identifier =~ m/^typedef/) { >> 2877 $decl_type = 'typedef'; >> 2878 } else { >> 2879 $decl_type = 'function'; >> 2880 } >> 2881 >> 2882 if ($verbose) { >> 2883 print STDERR "${file}:$.: info: Scanning doc for $identifier\n"; >> 2884 } >> 2885 } else { >> 2886 print STDERR "${file}:$.: warning: Cannot understand $_ on line $.", >> 2887 " - I thought it was a doc line\n"; >> 2888 ++$warnings; >> 2889 $state = STATE_NORMAL; >> 2890 } >> 2891 } elsif ($state == STATE_FIELD) { # look for head: lines, and include content >> 2892 if (/$doc_sect/i) { # case insensitive for supported section names >> 2893 $newsection = $1; >> 2894 $newcontents = $2; >> 2895 >> 2896 # map the supported section names to the canonical names >> 2897 if ($newsection =~ m/^description$/i) { >> 2898 $newsection = $section_default; >> 2899 } elsif ($newsection =~ m/^context$/i) { >> 2900 $newsection = $section_context; >> 2901 } elsif ($newsection =~ m/^returns?$/i) { >> 2902 $newsection = $section_return; >> 2903 } elsif ($newsection =~ m/^\@return$/) { >> 2904 # special: @return is a section, not a param description >> 2905 $newsection = $section_return; >> 2906 } >> 2907 >> 2908 if (($contents ne "") && ($contents ne "\n")) { >> 2909 if (!$in_doc_sect && $verbose) { >> 2910 print STDERR "${file}:$.: warning: contents before sections\n"; >> 2911 ++$warnings; >> 2912 } >> 2913 dump_section($file, $section, xml_escape($contents)); >> 2914 $section = $section_default; >> 2915 } >> 2916 >> 2917 $in_doc_sect = 1; >> 2918 $in_purpose = 0; >> 2919 $contents = $newcontents; >> 2920 $new_start_line = $.; >> 2921 while ((substr($contents, 0, 1) eq " ") || >> 2922 substr($contents, 0, 1) eq "\t") { >> 2923 $contents = substr($contents, 1); >> 2924 } >> 2925 if ($contents ne "") { >> 2926 $contents .= "\n"; >> 2927 } >> 2928 $section = $newsection; >> 2929 $leading_space = undef; >> 2930 } elsif (/$doc_end/) { >> 2931 if (($contents ne "") && ($contents ne "\n")) { >> 2932 dump_section($file, $section, xml_escape($contents)); >> 2933 $section = $section_default; >> 2934 $contents = ""; >> 2935 } >> 2936 # look for doc_com + <text> + doc_end: >> 2937 if ($_ =~ m'\s*\*\s*[a-zA-Z_0-9:\.]+\*/') { >> 2938 print STDERR "${file}:$.: warning: suspicious ending line: $_"; >> 2939 ++$warnings; >> 2940 } >> 2941 >> 2942 $prototype = ""; >> 2943 $state = STATE_PROTO; >> 2944 $brcount = 0; >> 2945 # print STDERR "end of doc comment, looking for prototype\n"; >> 2946 } elsif (/$doc_content/) { >> 2947 # miguel-style comment kludge, look for blank lines after >> 2948 # @parameter line to signify start of description >> 2949 if ($1 eq "") { >> 2950 if ($section =~ m/^@/ || $section eq $section_context) { >> 2951 dump_section($file, $section, xml_escape($contents)); >> 2952 $section = $section_default; >> 2953 $contents = ""; >> 2954 $new_start_line = $.; >> 2955 } else { >> 2956 $contents .= "\n"; >> 2957 } >> 2958 $in_purpose = 0; >> 2959 } elsif ($in_purpose == 1) { >> 2960 # Continued declaration purpose >> 2961 chomp($declaration_purpose); >> 2962 $declaration_purpose .= " " . xml_escape($1); >> 2963 $declaration_purpose =~ s/\s+/ /g; >> 2964 } else { >> 2965 my $cont = $1; >> 2966 if ($section =~ m/^@/ || $section eq $section_context) { >> 2967 if (!defined $leading_space) { >> 2968 if ($cont =~ m/^(\s+)/) { >> 2969 $leading_space = $1; >> 2970 } else { >> 2971 $leading_space = ""; >> 2972 } >> 2973 } >> 2974 >> 2975 $cont =~ s/^$leading_space//; >> 2976 } >> 2977 $contents .= $cont . "\n"; >> 2978 } >> 2979 } else { >> 2980 # i dont know - bad line? ignore. >> 2981 print STDERR "${file}:$.: warning: bad line: $_"; >> 2982 ++$warnings; >> 2983 } >> 2984 } elsif ($state == STATE_INLINE) { # scanning for inline parameters >> 2985 # First line (state 1) needs to be a @parameter >> 2986 if ($inline_doc_state == STATE_INLINE_NAME && /$doc_inline_sect/o) { >> 2987 $section = $1; >> 2988 $contents = $2; >> 2989 $new_start_line = $.; >> 2990 if ($contents ne "") { >> 2991 while ((substr($contents, 0, 1) eq " ") || >> 2992 substr($contents, 0, 1) eq "\t") { >> 2993 $contents = substr($contents, 1); >> 2994 } >> 2995 $contents .= "\n"; >> 2996 } >> 2997 $inline_doc_state = STATE_INLINE_TEXT; >> 2998 # Documentation block end */ >> 2999 } elsif (/$doc_inline_end/) { >> 3000 if (($contents ne "") && ($contents ne "\n")) { >> 3001 dump_section($file, $section, xml_escape($contents)); >> 3002 $section = $section_default; >> 3003 $contents = ""; >> 3004 } >> 3005 $state = STATE_PROTO; >> 3006 $inline_doc_state = STATE_INLINE_NA; >> 3007 # Regular text >> 3008 } elsif (/$doc_content/) { >> 3009 if ($inline_doc_state == STATE_INLINE_TEXT) { >> 3010 $contents .= $1 . "\n"; >> 3011 # nuke leading blank lines >> 3012 if ($contents =~ /^\s*$/) { >> 3013 $contents = ""; >> 3014 } >> 3015 } elsif ($inline_doc_state == STATE_INLINE_NAME) { >> 3016 $inline_doc_state = STATE_INLINE_ERROR; >> 3017 print STDERR "${file}:$.: warning: "; >> 3018 print STDERR "Incorrect use of kernel-doc format: $_"; >> 3019 ++$warnings; >> 3020 } >> 3021 } >> 3022 } elsif ($state == STATE_PROTO) { # scanning for function '{' (end of prototype) >> 3023 if (/$doc_inline_start/) { >> 3024 $state = STATE_INLINE; >> 3025 $inline_doc_state = STATE_INLINE_NAME; >> 3026 } elsif ($decl_type eq 'function') { >> 3027 process_proto_function($_, $file); >> 3028 } else { >> 3029 process_proto_type($_, $file); >> 3030 } >> 3031 } elsif ($state == STATE_DOCBLOCK) { >> 3032 if (/$doc_end/) >> 3033 { >> 3034 dump_doc_section($file, $section, xml_escape($contents)); >> 3035 $section = $section_default; >> 3036 $contents = ""; >> 3037 $function = ""; >> 3038 %parameterdescs = (); >> 3039 %parametertypes = (); >> 3040 @parameterlist = (); >> 3041 %sections = (); >> 3042 @sectionlist = (); >> 3043 $prototype = ""; >> 3044 $state = STATE_NORMAL; >> 3045 } >> 3046 elsif (/$doc_content/) >> 3047 { >> 3048 if ( $1 eq "" ) >> 3049 { >> 3050 $contents .= $blankline; >> 3051 } >> 3052 else >> 3053 { >> 3054 $contents .= $1 . "\n"; >> 3055 } >> 3056 } >> 3057 } >> 3058 } >> 3059 if ($initial_section_counter == $section_counter) { >> 3060 print STDERR "${file}:1: warning: no structured comments found\n"; >> 3061 if (($output_selection == OUTPUT_INCLUDE) && ($show_not_found == 1)) { >> 3062 print STDERR " Was looking for '$_'.\n" for keys %function_table; >> 3063 } >> 3064 if ($output_mode eq "xml") { >> 3065 # The template wants at least one RefEntry here; make one. >> 3066 print "<refentry>\n"; >> 3067 print " <refnamediv>\n"; >> 3068 print " <refname>\n"; >> 3069 print " ${orig_file}\n"; >> 3070 print " </refname>\n"; >> 3071 print " <refpurpose>\n"; >> 3072 print " Document generation inconsistency\n"; >> 3073 print " </refpurpose>\n"; >> 3074 print " </refnamediv>\n"; >> 3075 print " <refsect1>\n"; >> 3076 print " <title>\n"; >> 3077 print " Oops\n"; >> 3078 print " </title>\n"; >> 3079 print " <warning>\n"; >> 3080 print " <para>\n"; >> 3081 print " The template for this document tried to insert\n"; >> 3082 print " the structured comment from the file\n"; >> 3083 print " <filename>${orig_file}</filename> at this point,\n"; >> 3084 print " but none was found.\n"; >> 3085 print " This dummy section is inserted to allow\n"; >> 3086 print " generation to continue.\n"; >> 3087 print " </para>\n"; >> 3088 print " </warning>\n"; >> 3089 print " </refsect1>\n"; >> 3090 print "</refentry>\n"; >> 3091 } 2371 } 3092 } 2372 close IN_FILE; << 2373 } 3093 } 2374 3094 2375 3095 2376 if ($output_mode eq "rst") { << 2377 get_sphinx_version() if (!$sphinx_major); << 2378 } << 2379 << 2380 $kernelversion = get_kernel_version(); 3096 $kernelversion = get_kernel_version(); 2381 3097 2382 # generate a sequence of code that will splic 3098 # generate a sequence of code that will splice in highlighting information 2383 # using the s// operator. 3099 # using the s// operator. 2384 for (my $k = 0; $k < @highlights; $k++) { 3100 for (my $k = 0; $k < @highlights; $k++) { 2385 my $pattern = $highlights[$k][0]; 3101 my $pattern = $highlights[$k][0]; 2386 my $result = $highlights[$k][1]; 3102 my $result = $highlights[$k][1]; 2387 # print STDERR "scanning pattern:$pattern, 3103 # print STDERR "scanning pattern:$pattern, highlight:($result)\n"; 2388 $dohighlight .= "\$contents =~ s:$patter 3104 $dohighlight .= "\$contents =~ s:$pattern:$result:gs;\n"; 2389 } 3105 } 2390 3106 2391 # Read the file that maps relative names to a 3107 # Read the file that maps relative names to absolute names for 2392 # separate source and object directories and 3108 # separate source and object directories and for shadow trees. 2393 if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 3109 if (open(SOURCE_MAP, "<.tmp_filelist.txt")) { 2394 my ($relname, $absname); !! 3110 my ($relname, $absname); 2395 while(<SOURCE_MAP>) { !! 3111 while(<SOURCE_MAP>) { 2396 chop(); !! 3112 chop(); 2397 ($relname, $absname) = (split())[0..1 !! 3113 ($relname, $absname) = (split())[0..1]; 2398 $relname =~ s:^/+::; !! 3114 $relname =~ s:^/+::; 2399 $source_map{$relname} = $absname; !! 3115 $source_map{$relname} = $absname; 2400 } !! 3116 } 2401 close(SOURCE_MAP); !! 3117 close(SOURCE_MAP); 2402 } 3118 } 2403 3119 2404 if ($output_selection == OUTPUT_EXPORTED || 3120 if ($output_selection == OUTPUT_EXPORTED || 2405 $output_selection == OUTPUT_INTERNAL) { 3121 $output_selection == OUTPUT_INTERNAL) { 2406 3122 2407 push(@export_file_list, @ARGV); 3123 push(@export_file_list, @ARGV); 2408 3124 2409 foreach (@export_file_list) { 3125 foreach (@export_file_list) { 2410 chomp; !! 3126 chomp; 2411 process_export_file($_); !! 3127 process_export_file($_); 2412 } 3128 } 2413 } 3129 } 2414 3130 2415 foreach (@ARGV) { 3131 foreach (@ARGV) { 2416 chomp; 3132 chomp; 2417 process_file($_); 3133 process_file($_); 2418 } 3134 } 2419 if ($verbose && $errors) { 3135 if ($verbose && $errors) { 2420 print STDERR "$errors errors\n"; !! 3136 print STDERR "$errors errors\n"; 2421 } 3137 } 2422 if ($verbose && $warnings) { 3138 if ($verbose && $warnings) { 2423 print STDERR "$warnings warnings\n"; !! 3139 print STDERR "$warnings warnings\n"; 2424 } << 2425 << 2426 if ($Werror && $warnings) { << 2427 print STDERR "$warnings warnings as Error << 2428 exit($warnings); << 2429 } else { << 2430 exit($output_mode eq "none" ? 0 : $errors << 2431 } 3140 } 2432 3141 2433 __END__ !! 3142 exit($output_mode eq "none" ? 0 : $errors); 2434 << 2435 =head1 OPTIONS << 2436 << 2437 =head2 Output format selection (mutually excl << 2438 << 2439 =over 8 << 2440 << 2441 =item -man << 2442 << 2443 Output troff manual page format. << 2444 << 2445 =item -rst << 2446 << 2447 Output reStructuredText format. This is the d << 2448 << 2449 =item -none << 2450 << 2451 Do not output documentation, only warnings. << 2452 << 2453 =back << 2454 << 2455 =head2 Output format modifiers << 2456 << 2457 =head3 reStructuredText only << 2458 << 2459 =over 8 << 2460 << 2461 =item -sphinx-version VERSION << 2462 << 2463 Use the ReST C domain dialect compatible with << 2464 << 2465 If not specified, kernel-doc will auto-detect << 2466 found on PATH. << 2467 << 2468 =back << 2469 << 2470 =head2 Output selection (mutually exclusive): << 2471 << 2472 =over 8 << 2473 << 2474 =item -export << 2475 << 2476 Only output documentation for the symbols tha << 2477 EXPORT_SYMBOL() and related macros in any inp << 2478 << 2479 =item -internal << 2480 << 2481 Only output documentation for the symbols tha << 2482 EXPORT_SYMBOL() and related macros in any inp << 2483 << 2484 =item -function NAME << 2485 << 2486 Only output documentation for the given funct << 2487 All other functions and DOC: sections are ign << 2488 << 2489 May be specified multiple times. << 2490 << 2491 =item -nosymbol NAME << 2492 << 2493 Exclude the specified symbol from the output << 2494 << 2495 May be specified multiple times. << 2496 << 2497 =back << 2498 << 2499 =head2 Output selection modifiers: << 2500 << 2501 =over 8 << 2502 << 2503 =item -no-doc-sections << 2504 << 2505 Do not output DOC: sections. << 2506 << 2507 =item -export-file FILE << 2508 << 2509 Specify an additional FILE in which to look f << 2510 << 2511 To be used with -export or -internal. << 2512 << 2513 May be specified multiple times. << 2514 << 2515 =back << 2516 << 2517 =head3 reStructuredText only << 2518 << 2519 =over 8 << 2520 << 2521 =item -enable-lineno << 2522 << 2523 Enable output of .. LINENO lines. << 2524 << 2525 =back << 2526 << 2527 =head2 Other parameters: << 2528 << 2529 =over 8 << 2530 << 2531 =item -h, -help << 2532 << 2533 Print this help. << 2534 << 2535 =item -v << 2536 << 2537 Verbose output, more warnings and other infor << 2538 << 2539 =item -Werror << 2540 << 2541 Treat warnings as errors. << 2542 << 2543 =back << 2544 << 2545 =cut <<
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.