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