Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / scripts / kernel-doc
bloba9d8c30624916073115f970cf701b093a58f4042
1 #!/usr/bin/perl -w
3 use strict;
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-2007 Randy Dunlap ##
9 ## ##
10 ## #define enhancements by Armin Kuster <akuster@mvista.com> ##
11 ## Copyright (c) 2000 MontaVista Software, Inc. ##
12 ## ##
13 ## This software falls under the GNU General Public License. ##
14 ## Please read the COPYING file for more information ##
16 # w.o. 03-11-2000: added the '-filelist' option.
18 # 18/01/2001 - Cleanups
19 # Functions prototyped as foo(void) same as foo()
20 # Stop eval'ing where we don't need to.
21 # -- huggie@earth.li
23 # 27/06/2001 - Allowed whitespace after initial "/**" and
24 # allowed comments before function declarations.
25 # -- Christian Kreibich <ck@whoop.org>
27 # Still to do:
28 # - add perldoc documentation
29 # - Look more closely at some of the scarier bits :)
31 # 26/05/2001 - Support for separate source and object trees.
32 # Return error code.
33 # Keith Owens <kaos@ocs.com.au>
35 # 23/09/2001 - Added support for typedefs, structs, enums and unions
36 # Support for Context section; can be terminated using empty line
37 # Small fixes (like spaces vs. \s in regex)
38 # -- Tim Jansen <tim@tjansen.de>
42 # This will read a 'c' file and scan for embedded comments in the
43 # style of gnome comments (+minor extensions - see below).
46 # Note: This only supports 'c'.
48 # usage:
49 # kernel-doc [ -docbook | -html | -text | -man ] [ -no-doc-sections ]
50 # [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile
51 # or
52 # [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile
54 # Set output format using one of -docbook -html -text or -man. Default is man.
56 # -no-doc-sections
57 # Do not output DOC: sections
59 # -function funcname
60 # If set, then only generate documentation for the given function(s) or
61 # DOC: section titles. All other functions and DOC: sections are ignored.
63 # -nofunction funcname
64 # If set, then only generate documentation for the other function(s)/DOC:
65 # sections. Cannot be used together with -function (yes, that's a bug --
66 # perl hackers can fix it 8))
68 # c files - list of 'c' files to process
70 # All output goes to stdout, with errors to stderr.
73 # format of comments.
74 # In the following table, (...)? signifies optional structure.
75 # (...)* signifies 0 or more structure elements
76 # /**
77 # * function_name(:)? (- short description)?
78 # (* @parameterx: (description of parameter x)?)*
79 # (* a blank line)?
80 # * (Description:)? (Description of function)?
81 # * (section header: (section description)? )*
82 # (*)?*/
84 # So .. the trivial example would be:
86 # /**
87 # * my_function
88 # **/
90 # If the Description: header tag is omitted, then there must be a blank line
91 # after the last parameter specification.
92 # e.g.
93 # /**
94 # * my_function - does my stuff
95 # * @my_arg: its mine damnit
96 # *
97 # * Does my stuff explained.
98 # */
100 # or, could also use:
101 # /**
102 # * my_function - does my stuff
103 # * @my_arg: its mine damnit
104 # * Description: Does my stuff explained.
105 # */
106 # etc.
108 # Beside functions you can also write documentation for structs, unions,
109 # enums and typedefs. Instead of the function name you must write the name
110 # of the declaration; the struct/union/enum/typedef must always precede
111 # the name. Nesting of declarations is not supported.
112 # Use the argument mechanism to document members or constants.
113 # e.g.
114 # /**
115 # * struct my_struct - short description
116 # * @a: first member
117 # * @b: second member
119 # * Longer description
120 # */
121 # struct my_struct {
122 # int a;
123 # int b;
124 # /* private: */
125 # int c;
126 # };
128 # All descriptions can be multiline, except the short function description.
130 # You can also add additional sections. When documenting kernel functions you
131 # should document the "Context:" of the function, e.g. whether the functions
132 # can be called form interrupts. Unlike other sections you can end it with an
133 # empty line.
134 # Example-sections should contain the string EXAMPLE so that they are marked
135 # appropriately in DocBook.
137 # Example:
138 # /**
139 # * user_function - function that can only be called in user context
140 # * @a: some argument
141 # * Context: !in_interrupt()
143 # * Some description
144 # * Example:
145 # * user_function(22);
146 # */
147 # ...
150 # All descriptive text is further processed, scanning for the following special
151 # patterns, which are highlighted appropriately.
153 # 'funcname()' - function
154 # '$ENVVAR' - environmental variable
155 # '&struct_name' - name of a structure (up to two words including 'struct')
156 # '@parameter' - name of a parameter
157 # '%CONST' - name of a constant.
159 my $errors = 0;
160 my $warnings = 0;
161 my $anon_struct_union = 0;
163 # match expressions used to find embedded type information
164 my $type_constant = '\%([-_\w]+)';
165 my $type_func = '(\w+)\(\)';
166 my $type_param = '\@(\w+)';
167 my $type_struct = '\&((struct\s*)*[_\w]+)';
168 my $type_struct_xml = '\\&amp;((struct\s*)*[_\w]+)';
169 my $type_env = '(\$\w+)';
171 # Output conversion substitutions.
172 # One for each output format
174 # these work fairly well
175 my %highlights_html = ( $type_constant, "<i>\$1</i>",
176 $type_func, "<b>\$1</b>",
177 $type_struct_xml, "<i>\$1</i>",
178 $type_env, "<b><i>\$1</i></b>",
179 $type_param, "<tt><b>\$1</b></tt>" );
180 my $local_lt = "\\\\\\\\lt:";
181 my $local_gt = "\\\\\\\\gt:";
182 my $blankline_html = $local_lt . "p" . $local_gt; # was "<p>"
184 # XML, docbook format
185 my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
186 $type_constant, "<constant>\$1</constant>",
187 $type_func, "<function>\$1</function>",
188 $type_struct_xml, "<structname>\$1</structname>",
189 $type_env, "<envar>\$1</envar>",
190 $type_param, "<parameter>\$1</parameter>" );
191 my $blankline_xml = $local_lt . "/para" . $local_gt . $local_lt . "para" . $local_gt . "\n";
193 # gnome, docbook format
194 my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
195 $type_func, "<function>\$1</function>",
196 $type_struct, "<structname>\$1</structname>",
197 $type_env, "<envar>\$1</envar>",
198 $type_param, "<parameter>\$1</parameter>" );
199 my $blankline_gnome = "</para><para>\n";
201 # these are pretty rough
202 my %highlights_man = ( $type_constant, "\$1",
203 $type_func, "\\\\fB\$1\\\\fP",
204 $type_struct, "\\\\fI\$1\\\\fP",
205 $type_param, "\\\\fI\$1\\\\fP" );
206 my $blankline_man = "";
208 # text-mode
209 my %highlights_text = ( $type_constant, "\$1",
210 $type_func, "\$1",
211 $type_struct, "\$1",
212 $type_param, "\$1" );
213 my $blankline_text = "";
216 sub usage {
217 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ] [ -no-doc-sections ]\n";
218 print " [ -function funcname [ -function funcname ...] ]\n";
219 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
220 print " c source file(s) > outputfile\n";
221 print " -v : verbose output, more warnings & other info listed\n";
222 exit 1;
225 # read arguments
226 if ($#ARGV==-1) {
227 usage();
230 my $verbose = 0;
231 my $output_mode = "man";
232 my $no_doc_sections = 0;
233 my %highlights = %highlights_man;
234 my $blankline = $blankline_man;
235 my $modulename = "Kernel API";
236 my $function_only = 0;
237 my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
238 'July', 'August', 'September', 'October',
239 'November', 'December')[(localtime)[4]] .
240 " " . ((localtime)[5]+1900);
242 # Essentially these are globals
243 # They probably want to be tidied up made more localised or summat.
244 # CAVEAT EMPTOR! Some of the others I localised may not want to be which
245 # could cause "use of undefined value" or other bugs.
246 my ($function, %function_table,%parametertypes,$declaration_purpose);
247 my ($type,$declaration_name,$return_type);
248 my ($newsection,$newcontents,$prototype,$filelist, $brcount, %source_map);
250 <<<<<<< HEAD:scripts/kernel-doc
251 =======
252 if (defined($ENV{'KBUILD_VERBOSE'})) {
253 $verbose = "$ENV{'KBUILD_VERBOSE'}";
256 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:scripts/kernel-doc
257 # Generated docbook code is inserted in a template at a point where
258 # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
259 # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
260 # We keep track of number of generated entries and generate a dummy
261 # if needs be to ensure the expanded template can be postprocessed
262 # into html.
263 my $section_counter = 0;
265 my $lineprefix="";
267 # states
268 # 0 - normal code
269 # 1 - looking for function name
270 # 2 - scanning field start.
271 # 3 - scanning prototype.
272 # 4 - documentation block
273 my $state;
274 my $in_doc_sect;
276 #declaration types: can be
277 # 'function', 'struct', 'union', 'enum', 'typedef'
278 my $decl_type;
280 my $doc_special = "\@\%\$\&";
282 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
283 my $doc_end = '\*/';
284 my $doc_com = '\s*\*\s*';
285 my $doc_decl = $doc_com.'(\w+)';
286 my $doc_sect = $doc_com.'(['.$doc_special.']?[\w\s]+):(.*)';
287 my $doc_content = $doc_com.'(.*)';
288 my $doc_block = $doc_com.'DOC:\s*(.*)?';
290 my %constants;
291 my %parameterdescs;
292 my @parameterlist;
293 my %sections;
294 my @sectionlist;
296 my $contents = "";
297 my $section_default = "Description"; # default section
298 my $section_intro = "Introduction";
299 my $section = $section_default;
300 my $section_context = "Context";
302 my $undescribed = "-- undescribed --";
304 reset_state();
306 while ($ARGV[0] =~ m/^-(.*)/) {
307 my $cmd = shift @ARGV;
308 if ($cmd eq "-html") {
309 $output_mode = "html";
310 %highlights = %highlights_html;
311 $blankline = $blankline_html;
312 } elsif ($cmd eq "-man") {
313 $output_mode = "man";
314 %highlights = %highlights_man;
315 $blankline = $blankline_man;
316 } elsif ($cmd eq "-text") {
317 $output_mode = "text";
318 %highlights = %highlights_text;
319 $blankline = $blankline_text;
320 } elsif ($cmd eq "-docbook") {
321 $output_mode = "xml";
322 %highlights = %highlights_xml;
323 $blankline = $blankline_xml;
324 } elsif ($cmd eq "-gnome") {
325 $output_mode = "gnome";
326 %highlights = %highlights_gnome;
327 $blankline = $blankline_gnome;
328 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
329 $modulename = shift @ARGV;
330 } elsif ($cmd eq "-function") { # to only output specific functions
331 $function_only = 1;
332 $function = shift @ARGV;
333 $function_table{$function} = 1;
334 } elsif ($cmd eq "-nofunction") { # to only output specific functions
335 $function_only = 2;
336 $function = shift @ARGV;
337 $function_table{$function} = 1;
338 } elsif ($cmd eq "-v") {
339 $verbose = 1;
340 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
341 usage();
342 } elsif ($cmd eq '-filelist') {
343 $filelist = shift @ARGV;
344 } elsif ($cmd eq '-no-doc-sections') {
345 $no_doc_sections = 1;
349 # get kernel version from env
350 sub get_kernel_version() {
351 my $version = 'unknown kernel version';
353 if (defined($ENV{'KERNELVERSION'})) {
354 $version = $ENV{'KERNELVERSION'};
356 return $version;
358 my $kernelversion = get_kernel_version();
360 # generate a sequence of code that will splice in highlighting information
361 # using the s// operator.
362 my $dohighlight = "";
363 foreach my $pattern (keys %highlights) {
364 # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
365 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
369 # dumps section contents to arrays/hashes intended for that purpose.
371 sub dump_section {
372 my $name = shift;
373 my $contents = join "\n", @_;
375 if ($name =~ m/$type_constant/) {
376 $name = $1;
377 # print STDERR "constant section '$1' = '$contents'\n";
378 $constants{$name} = $contents;
379 } elsif ($name =~ m/$type_param/) {
380 # print STDERR "parameter def '$1' = '$contents'\n";
381 $name = $1;
382 $parameterdescs{$name} = $contents;
383 } else {
384 # print STDERR "other section '$name' = '$contents'\n";
385 $sections{$name} = $contents;
386 push @sectionlist, $name;
391 # dump DOC: section after checking that it should go out
393 sub dump_doc_section {
394 my $name = shift;
395 my $contents = join "\n", @_;
397 if ($no_doc_sections) {
398 return;
401 if (($function_only == 0) ||
402 ( $function_only == 1 && defined($function_table{$name})) ||
403 ( $function_only == 2 && !defined($function_table{$name})))
405 dump_section $name, $contents;
406 output_blockhead({'sectionlist' => \@sectionlist,
407 'sections' => \%sections,
408 'module' => $modulename,
409 'content-only' => ($function_only != 0), });
414 # output function
416 # parameterdescs, a hash.
417 # function => "function name"
418 # parameterlist => @list of parameters
419 # parameterdescs => %parameter descriptions
420 # sectionlist => @list of sections
421 # sections => %section descriptions
424 sub output_highlight {
425 my $contents = join "\n",@_;
426 my $line;
428 # DEBUG
429 # if (!defined $contents) {
430 # use Carp;
431 # confess "output_highlight got called with no args?\n";
434 if ($output_mode eq "html" || $output_mode eq "xml") {
435 $contents = local_unescape($contents);
436 # convert data read & converted thru xml_escape() into &xyz; format:
437 $contents =~ s/\\\\\\/&/g;
439 # print STDERR "contents b4:$contents\n";
440 eval $dohighlight;
441 die $@ if $@;
442 # print STDERR "contents af:$contents\n";
444 foreach $line (split "\n", $contents) {
445 if ($line eq ""){
446 print $lineprefix, local_unescape($blankline);
447 } else {
448 $line =~ s/\\\\\\/\&/g;
449 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
450 print "\\&$line";
451 } else {
452 print $lineprefix, $line;
455 print "\n";
459 #output sections in html
460 sub output_section_html(%) {
461 my %args = %{$_[0]};
462 my $section;
464 foreach $section (@{$args{'sectionlist'}}) {
465 print "<h3>$section</h3>\n";
466 print "<blockquote>\n";
467 output_highlight($args{'sections'}{$section});
468 print "</blockquote>\n";
472 # output enum in html
473 sub output_enum_html(%) {
474 my %args = %{$_[0]};
475 my ($parameter);
476 my $count;
477 print "<h2>enum ".$args{'enum'}."</h2>\n";
479 print "<b>enum ".$args{'enum'}."</b> {<br>\n";
480 $count = 0;
481 foreach $parameter (@{$args{'parameterlist'}}) {
482 print " <b>".$parameter."</b>";
483 if ($count != $#{$args{'parameterlist'}}) {
484 $count++;
485 print ",\n";
487 print "<br>";
489 print "};<br>\n";
491 print "<h3>Constants</h3>\n";
492 print "<dl>\n";
493 foreach $parameter (@{$args{'parameterlist'}}) {
494 print "<dt><b>".$parameter."</b>\n";
495 print "<dd>";
496 output_highlight($args{'parameterdescs'}{$parameter});
498 print "</dl>\n";
499 output_section_html(@_);
500 print "<hr>\n";
503 # output typedef in html
504 sub output_typedef_html(%) {
505 my %args = %{$_[0]};
506 my ($parameter);
507 my $count;
508 print "<h2>typedef ".$args{'typedef'}."</h2>\n";
510 print "<b>typedef ".$args{'typedef'}."</b>\n";
511 output_section_html(@_);
512 print "<hr>\n";
515 # output struct in html
516 sub output_struct_html(%) {
517 my %args = %{$_[0]};
518 my ($parameter);
520 print "<h2>".$args{'type'}." ".$args{'struct'}. " - " .$args{'purpose'}."</h2>\n";
521 print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n";
522 foreach $parameter (@{$args{'parameterlist'}}) {
523 if ($parameter =~ /^#/) {
524 print "$parameter<br>\n";
525 next;
527 my $parameter_name = $parameter;
528 $parameter_name =~ s/\[.*//;
530 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
531 $type = $args{'parametertypes'}{$parameter};
532 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
533 # pointer-to-function
534 print "&nbsp; &nbsp; <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
535 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
536 # bitfield
537 print "&nbsp; &nbsp; <i>$1</i> <b>$parameter</b>$2;<br>\n";
538 } else {
539 print "&nbsp; &nbsp; <i>$type</i> <b>$parameter</b>;<br>\n";
542 print "};<br>\n";
544 print "<h3>Members</h3>\n";
545 print "<dl>\n";
546 foreach $parameter (@{$args{'parameterlist'}}) {
547 ($parameter =~ /^#/) && next;
549 my $parameter_name = $parameter;
550 $parameter_name =~ s/\[.*//;
552 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
553 print "<dt><b>".$parameter."</b>\n";
554 print "<dd>";
555 output_highlight($args{'parameterdescs'}{$parameter_name});
557 print "</dl>\n";
558 output_section_html(@_);
559 print "<hr>\n";
562 # output function in html
563 sub output_function_html(%) {
564 my %args = %{$_[0]};
565 my ($parameter, $section);
566 my $count;
568 print "<h2>" .$args{'function'}." - ".$args{'purpose'}."</h2>\n";
569 print "<i>".$args{'functiontype'}."</i>\n";
570 print "<b>".$args{'function'}."</b>\n";
571 print "(";
572 $count = 0;
573 foreach $parameter (@{$args{'parameterlist'}}) {
574 $type = $args{'parametertypes'}{$parameter};
575 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
576 # pointer-to-function
577 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
578 } else {
579 print "<i>".$type."</i> <b>".$parameter."</b>";
581 if ($count != $#{$args{'parameterlist'}}) {
582 $count++;
583 print ",\n";
586 print ")\n";
588 print "<h3>Arguments</h3>\n";
589 print "<dl>\n";
590 foreach $parameter (@{$args{'parameterlist'}}) {
591 my $parameter_name = $parameter;
592 $parameter_name =~ s/\[.*//;
594 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
595 print "<dt><b>".$parameter."</b>\n";
596 print "<dd>";
597 output_highlight($args{'parameterdescs'}{$parameter_name});
599 print "</dl>\n";
600 output_section_html(@_);
601 print "<hr>\n";
604 # output DOC: block header in html
605 sub output_blockhead_html(%) {
606 my %args = %{$_[0]};
607 my ($parameter, $section);
608 my $count;
610 foreach $section (@{$args{'sectionlist'}}) {
611 print "<h3>$section</h3>\n";
612 print "<ul>\n";
613 output_highlight($args{'sections'}{$section});
614 print "</ul>\n";
616 print "<hr>\n";
619 sub output_section_xml(%) {
620 my %args = %{$_[0]};
621 my $section;
622 # print out each section
623 $lineprefix=" ";
624 foreach $section (@{$args{'sectionlist'}}) {
625 print "<refsect1>\n";
626 print "<title>$section</title>\n";
627 if ($section =~ m/EXAMPLE/i) {
628 print "<informalexample><programlisting>\n";
629 } else {
630 print "<para>\n";
632 output_highlight($args{'sections'}{$section});
633 if ($section =~ m/EXAMPLE/i) {
634 print "</programlisting></informalexample>\n";
635 } else {
636 print "</para>\n";
638 print "</refsect1>\n";
642 # output function in XML DocBook
643 sub output_function_xml(%) {
644 my %args = %{$_[0]};
645 my ($parameter, $section);
646 my $count;
647 my $id;
649 $id = "API-".$args{'function'};
650 $id =~ s/[^A-Za-z0-9]/-/g;
652 print "<refentry id=\"$id\">\n";
653 print "<refentryinfo>\n";
654 print " <title>LINUX</title>\n";
655 print " <productname>Kernel Hackers Manual</productname>\n";
656 print " <date>$man_date</date>\n";
657 print "</refentryinfo>\n";
658 print "<refmeta>\n";
659 print " <refentrytitle><phrase>".$args{'function'}."</phrase></refentrytitle>\n";
660 print " <manvolnum>9</manvolnum>\n";
661 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
662 print "</refmeta>\n";
663 print "<refnamediv>\n";
664 print " <refname>".$args{'function'}."</refname>\n";
665 print " <refpurpose>\n";
666 print " ";
667 output_highlight ($args{'purpose'});
668 print " </refpurpose>\n";
669 print "</refnamediv>\n";
671 print "<refsynopsisdiv>\n";
672 print " <title>Synopsis</title>\n";
673 print " <funcsynopsis><funcprototype>\n";
674 print " <funcdef>".$args{'functiontype'}." ";
675 print "<function>".$args{'function'}." </function></funcdef>\n";
677 $count = 0;
678 if ($#{$args{'parameterlist'}} >= 0) {
679 foreach $parameter (@{$args{'parameterlist'}}) {
680 $type = $args{'parametertypes'}{$parameter};
681 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
682 # pointer-to-function
683 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
684 print " <funcparams>$2</funcparams></paramdef>\n";
685 } else {
686 print " <paramdef>".$type;
687 print " <parameter>$parameter</parameter></paramdef>\n";
690 } else {
691 print " <void/>\n";
693 print " </funcprototype></funcsynopsis>\n";
694 print "</refsynopsisdiv>\n";
696 # print parameters
697 print "<refsect1>\n <title>Arguments</title>\n";
698 if ($#{$args{'parameterlist'}} >= 0) {
699 print " <variablelist>\n";
700 foreach $parameter (@{$args{'parameterlist'}}) {
701 my $parameter_name = $parameter;
702 $parameter_name =~ s/\[.*//;
704 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
705 print " <listitem>\n <para>\n";
706 $lineprefix=" ";
707 output_highlight($args{'parameterdescs'}{$parameter_name});
708 print " </para>\n </listitem>\n </varlistentry>\n";
710 print " </variablelist>\n";
711 } else {
712 print " <para>\n None\n </para>\n";
714 print "</refsect1>\n";
716 output_section_xml(@_);
717 print "</refentry>\n\n";
720 # output struct in XML DocBook
721 sub output_struct_xml(%) {
722 my %args = %{$_[0]};
723 my ($parameter, $section);
724 my $id;
726 $id = "API-struct-".$args{'struct'};
727 $id =~ s/[^A-Za-z0-9]/-/g;
729 print "<refentry id=\"$id\">\n";
730 print "<refentryinfo>\n";
731 print " <title>LINUX</title>\n";
732 print " <productname>Kernel Hackers Manual</productname>\n";
733 print " <date>$man_date</date>\n";
734 print "</refentryinfo>\n";
735 print "<refmeta>\n";
736 print " <refentrytitle><phrase>".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n";
737 print " <manvolnum>9</manvolnum>\n";
738 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
739 print "</refmeta>\n";
740 print "<refnamediv>\n";
741 print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n";
742 print " <refpurpose>\n";
743 print " ";
744 output_highlight ($args{'purpose'});
745 print " </refpurpose>\n";
746 print "</refnamediv>\n";
748 print "<refsynopsisdiv>\n";
749 print " <title>Synopsis</title>\n";
750 print " <programlisting>\n";
751 print $args{'type'}." ".$args{'struct'}." {\n";
752 foreach $parameter (@{$args{'parameterlist'}}) {
753 if ($parameter =~ /^#/) {
754 print "$parameter\n";
755 next;
758 my $parameter_name = $parameter;
759 $parameter_name =~ s/\[.*//;
761 defined($args{'parameterdescs'}{$parameter_name}) || next;
762 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
763 $type = $args{'parametertypes'}{$parameter};
764 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
765 # pointer-to-function
766 print " $1 $parameter) ($2);\n";
767 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
768 # bitfield
769 print " $1 $parameter$2;\n";
770 } else {
771 print " ".$type." ".$parameter.";\n";
774 print "};";
775 print " </programlisting>\n";
776 print "</refsynopsisdiv>\n";
778 print " <refsect1>\n";
779 print " <title>Members</title>\n";
781 print " <variablelist>\n";
782 foreach $parameter (@{$args{'parameterlist'}}) {
783 ($parameter =~ /^#/) && next;
785 my $parameter_name = $parameter;
786 $parameter_name =~ s/\[.*//;
788 defined($args{'parameterdescs'}{$parameter_name}) || next;
789 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
790 print " <varlistentry>";
791 print " <term>$parameter</term>\n";
792 print " <listitem><para>\n";
793 output_highlight($args{'parameterdescs'}{$parameter_name});
794 print " </para></listitem>\n";
795 print " </varlistentry>\n";
797 print " </variablelist>\n";
798 print " </refsect1>\n";
800 output_section_xml(@_);
802 print "</refentry>\n\n";
805 # output enum in XML DocBook
806 sub output_enum_xml(%) {
807 my %args = %{$_[0]};
808 my ($parameter, $section);
809 my $count;
810 my $id;
812 $id = "API-enum-".$args{'enum'};
813 $id =~ s/[^A-Za-z0-9]/-/g;
815 print "<refentry id=\"$id\">\n";
816 print "<refentryinfo>\n";
817 print " <title>LINUX</title>\n";
818 print " <productname>Kernel Hackers Manual</productname>\n";
819 print " <date>$man_date</date>\n";
820 print "</refentryinfo>\n";
821 print "<refmeta>\n";
822 print " <refentrytitle><phrase>enum ".$args{'enum'}."</phrase></refentrytitle>\n";
823 print " <manvolnum>9</manvolnum>\n";
824 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
825 print "</refmeta>\n";
826 print "<refnamediv>\n";
827 print " <refname>enum ".$args{'enum'}."</refname>\n";
828 print " <refpurpose>\n";
829 print " ";
830 output_highlight ($args{'purpose'});
831 print " </refpurpose>\n";
832 print "</refnamediv>\n";
834 print "<refsynopsisdiv>\n";
835 print " <title>Synopsis</title>\n";
836 print " <programlisting>\n";
837 print "enum ".$args{'enum'}." {\n";
838 $count = 0;
839 foreach $parameter (@{$args{'parameterlist'}}) {
840 print " $parameter";
841 if ($count != $#{$args{'parameterlist'}}) {
842 $count++;
843 print ",";
845 print "\n";
847 print "};";
848 print " </programlisting>\n";
849 print "</refsynopsisdiv>\n";
851 print "<refsect1>\n";
852 print " <title>Constants</title>\n";
853 print " <variablelist>\n";
854 foreach $parameter (@{$args{'parameterlist'}}) {
855 my $parameter_name = $parameter;
856 $parameter_name =~ s/\[.*//;
858 print " <varlistentry>";
859 print " <term>$parameter</term>\n";
860 print " <listitem><para>\n";
861 output_highlight($args{'parameterdescs'}{$parameter_name});
862 print " </para></listitem>\n";
863 print " </varlistentry>\n";
865 print " </variablelist>\n";
866 print "</refsect1>\n";
868 output_section_xml(@_);
870 print "</refentry>\n\n";
873 # output typedef in XML DocBook
874 sub output_typedef_xml(%) {
875 my %args = %{$_[0]};
876 my ($parameter, $section);
877 my $id;
879 $id = "API-typedef-".$args{'typedef'};
880 $id =~ s/[^A-Za-z0-9]/-/g;
882 print "<refentry id=\"$id\">\n";
883 print "<refentryinfo>\n";
884 print " <title>LINUX</title>\n";
885 print " <productname>Kernel Hackers Manual</productname>\n";
886 print " <date>$man_date</date>\n";
887 print "</refentryinfo>\n";
888 print "<refmeta>\n";
889 print " <refentrytitle><phrase>typedef ".$args{'typedef'}."</phrase></refentrytitle>\n";
890 print " <manvolnum>9</manvolnum>\n";
891 print "</refmeta>\n";
892 print "<refnamediv>\n";
893 print " <refname>typedef ".$args{'typedef'}."</refname>\n";
894 print " <refpurpose>\n";
895 print " ";
896 output_highlight ($args{'purpose'});
897 print " </refpurpose>\n";
898 print "</refnamediv>\n";
900 print "<refsynopsisdiv>\n";
901 print " <title>Synopsis</title>\n";
902 print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n";
903 print "</refsynopsisdiv>\n";
905 output_section_xml(@_);
907 print "</refentry>\n\n";
910 # output in XML DocBook
911 sub output_blockhead_xml(%) {
912 my %args = %{$_[0]};
913 my ($parameter, $section);
914 my $count;
916 my $id = $args{'module'};
917 $id =~ s/[^A-Za-z0-9]/-/g;
919 # print out each section
920 $lineprefix=" ";
921 foreach $section (@{$args{'sectionlist'}}) {
922 if (!$args{'content-only'}) {
923 print "<refsect1>\n <title>$section</title>\n";
925 if ($section =~ m/EXAMPLE/i) {
926 print "<example><para>\n";
927 } else {
928 print "<para>\n";
930 output_highlight($args{'sections'}{$section});
931 if ($section =~ m/EXAMPLE/i) {
932 print "</para></example>\n";
933 } else {
934 print "</para>";
936 if (!$args{'content-only'}) {
937 print "\n</refsect1>\n";
941 print "\n\n";
944 # output in XML DocBook
945 sub output_function_gnome {
946 my %args = %{$_[0]};
947 my ($parameter, $section);
948 my $count;
949 my $id;
951 $id = $args{'module'}."-".$args{'function'};
952 $id =~ s/[^A-Za-z0-9]/-/g;
954 print "<sect2>\n";
955 print " <title id=\"$id\">".$args{'function'}."</title>\n";
957 print " <funcsynopsis>\n";
958 print " <funcdef>".$args{'functiontype'}." ";
959 print "<function>".$args{'function'}." ";
960 print "</function></funcdef>\n";
962 $count = 0;
963 if ($#{$args{'parameterlist'}} >= 0) {
964 foreach $parameter (@{$args{'parameterlist'}}) {
965 $type = $args{'parametertypes'}{$parameter};
966 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
967 # pointer-to-function
968 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
969 print " <funcparams>$2</funcparams></paramdef>\n";
970 } else {
971 print " <paramdef>".$type;
972 print " <parameter>$parameter</parameter></paramdef>\n";
975 } else {
976 print " <void>\n";
978 print " </funcsynopsis>\n";
979 if ($#{$args{'parameterlist'}} >= 0) {
980 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
981 print "<tgroup cols=\"2\">\n";
982 print "<colspec colwidth=\"2*\">\n";
983 print "<colspec colwidth=\"8*\">\n";
984 print "<tbody>\n";
985 foreach $parameter (@{$args{'parameterlist'}}) {
986 my $parameter_name = $parameter;
987 $parameter_name =~ s/\[.*//;
989 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
990 print " <entry>\n";
991 $lineprefix=" ";
992 output_highlight($args{'parameterdescs'}{$parameter_name});
993 print " </entry></row>\n";
995 print " </tbody></tgroup></informaltable>\n";
996 } else {
997 print " <para>\n None\n </para>\n";
1000 # print out each section
1001 $lineprefix=" ";
1002 foreach $section (@{$args{'sectionlist'}}) {
1003 print "<simplesect>\n <title>$section</title>\n";
1004 if ($section =~ m/EXAMPLE/i) {
1005 print "<example><programlisting>\n";
1006 } else {
1008 print "<para>\n";
1009 output_highlight($args{'sections'}{$section});
1010 print "</para>\n";
1011 if ($section =~ m/EXAMPLE/i) {
1012 print "</programlisting></example>\n";
1013 } else {
1015 print " </simplesect>\n";
1018 print "</sect2>\n\n";
1022 # output function in man
1023 sub output_function_man(%) {
1024 my %args = %{$_[0]};
1025 my ($parameter, $section);
1026 my $count;
1028 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1030 print ".SH NAME\n";
1031 print $args{'function'}." \\- ".$args{'purpose'}."\n";
1033 print ".SH SYNOPSIS\n";
1034 if ($args{'functiontype'} ne "") {
1035 print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n";
1036 } else {
1037 print ".B \"".$args{'function'}."\n";
1039 $count = 0;
1040 my $parenth = "(";
1041 my $post = ",";
1042 foreach my $parameter (@{$args{'parameterlist'}}) {
1043 if ($count == $#{$args{'parameterlist'}}) {
1044 $post = ");";
1046 $type = $args{'parametertypes'}{$parameter};
1047 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1048 # pointer-to-function
1049 print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n";
1050 } else {
1051 $type =~ s/([^\*])$/$1 /;
1052 print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n";
1054 $count++;
1055 $parenth = "";
1058 print ".SH ARGUMENTS\n";
1059 foreach $parameter (@{$args{'parameterlist'}}) {
1060 my $parameter_name = $parameter;
1061 $parameter_name =~ s/\[.*//;
1063 print ".IP \"".$parameter."\" 12\n";
1064 output_highlight($args{'parameterdescs'}{$parameter_name});
1066 foreach $section (@{$args{'sectionlist'}}) {
1067 print ".SH \"", uc $section, "\"\n";
1068 output_highlight($args{'sections'}{$section});
1073 # output enum in man
1074 sub output_enum_man(%) {
1075 my %args = %{$_[0]};
1076 my ($parameter, $section);
1077 my $count;
1079 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1081 print ".SH NAME\n";
1082 print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n";
1084 print ".SH SYNOPSIS\n";
1085 print "enum ".$args{'enum'}." {\n";
1086 $count = 0;
1087 foreach my $parameter (@{$args{'parameterlist'}}) {
1088 print ".br\n.BI \" $parameter\"\n";
1089 if ($count == $#{$args{'parameterlist'}}) {
1090 print "\n};\n";
1091 last;
1093 else {
1094 print ", \n.br\n";
1096 $count++;
1099 print ".SH Constants\n";
1100 foreach $parameter (@{$args{'parameterlist'}}) {
1101 my $parameter_name = $parameter;
1102 $parameter_name =~ s/\[.*//;
1104 print ".IP \"".$parameter."\" 12\n";
1105 output_highlight($args{'parameterdescs'}{$parameter_name});
1107 foreach $section (@{$args{'sectionlist'}}) {
1108 print ".SH \"$section\"\n";
1109 output_highlight($args{'sections'}{$section});
1114 # output struct in man
1115 sub output_struct_man(%) {
1116 my %args = %{$_[0]};
1117 my ($parameter, $section);
1119 print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n";
1121 print ".SH NAME\n";
1122 print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n";
1124 print ".SH SYNOPSIS\n";
1125 print $args{'type'}." ".$args{'struct'}." {\n.br\n";
1127 foreach my $parameter (@{$args{'parameterlist'}}) {
1128 if ($parameter =~ /^#/) {
1129 print ".BI \"$parameter\"\n.br\n";
1130 next;
1132 my $parameter_name = $parameter;
1133 $parameter_name =~ s/\[.*//;
1135 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1136 $type = $args{'parametertypes'}{$parameter};
1137 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1138 # pointer-to-function
1139 print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n";
1140 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1141 # bitfield
1142 print ".BI \" ".$1."\ \" ".$parameter.$2." \""."\"\n;\n";
1143 } else {
1144 $type =~ s/([^\*])$/$1 /;
1145 print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n";
1147 print "\n.br\n";
1149 print "};\n.br\n";
1151 print ".SH Members\n";
1152 foreach $parameter (@{$args{'parameterlist'}}) {
1153 ($parameter =~ /^#/) && next;
1155 my $parameter_name = $parameter;
1156 $parameter_name =~ s/\[.*//;
1158 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1159 print ".IP \"".$parameter."\" 12\n";
1160 output_highlight($args{'parameterdescs'}{$parameter_name});
1162 foreach $section (@{$args{'sectionlist'}}) {
1163 print ".SH \"$section\"\n";
1164 output_highlight($args{'sections'}{$section});
1169 # output typedef in man
1170 sub output_typedef_man(%) {
1171 my %args = %{$_[0]};
1172 my ($parameter, $section);
1174 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1176 print ".SH NAME\n";
1177 print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n";
1179 foreach $section (@{$args{'sectionlist'}}) {
1180 print ".SH \"$section\"\n";
1181 output_highlight($args{'sections'}{$section});
1185 sub output_blockhead_man(%) {
1186 my %args = %{$_[0]};
1187 my ($parameter, $section);
1188 my $count;
1190 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1192 foreach $section (@{$args{'sectionlist'}}) {
1193 print ".SH \"$section\"\n";
1194 output_highlight($args{'sections'}{$section});
1199 # output in text
1200 sub output_function_text(%) {
1201 my %args = %{$_[0]};
1202 my ($parameter, $section);
1203 my $start;
1205 print "Name:\n\n";
1206 print $args{'function'}." - ".$args{'purpose'}."\n";
1208 print "\nSynopsis:\n\n";
1209 if ($args{'functiontype'} ne "") {
1210 $start = $args{'functiontype'}." ".$args{'function'}." (";
1211 } else {
1212 $start = $args{'function'}." (";
1214 print $start;
1216 my $count = 0;
1217 foreach my $parameter (@{$args{'parameterlist'}}) {
1218 $type = $args{'parametertypes'}{$parameter};
1219 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1220 # pointer-to-function
1221 print $1.$parameter.") (".$2;
1222 } else {
1223 print $type." ".$parameter;
1225 if ($count != $#{$args{'parameterlist'}}) {
1226 $count++;
1227 print ",\n";
1228 print " " x length($start);
1229 } else {
1230 print ");\n\n";
1234 print "Arguments:\n\n";
1235 foreach $parameter (@{$args{'parameterlist'}}) {
1236 my $parameter_name = $parameter;
1237 $parameter_name =~ s/\[.*//;
1239 print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n";
1241 output_section_text(@_);
1244 #output sections in text
1245 sub output_section_text(%) {
1246 my %args = %{$_[0]};
1247 my $section;
1249 print "\n";
1250 foreach $section (@{$args{'sectionlist'}}) {
1251 print "$section:\n\n";
1252 output_highlight($args{'sections'}{$section});
1254 print "\n\n";
1257 # output enum in text
1258 sub output_enum_text(%) {
1259 my %args = %{$_[0]};
1260 my ($parameter);
1261 my $count;
1262 print "Enum:\n\n";
1264 print "enum ".$args{'enum'}." - ".$args{'purpose'}."\n\n";
1265 print "enum ".$args{'enum'}." {\n";
1266 $count = 0;
1267 foreach $parameter (@{$args{'parameterlist'}}) {
1268 print "\t$parameter";
1269 if ($count != $#{$args{'parameterlist'}}) {
1270 $count++;
1271 print ",";
1273 print "\n";
1275 print "};\n\n";
1277 print "Constants:\n\n";
1278 foreach $parameter (@{$args{'parameterlist'}}) {
1279 print "$parameter\n\t";
1280 print $args{'parameterdescs'}{$parameter}."\n";
1283 output_section_text(@_);
1286 # output typedef in text
1287 sub output_typedef_text(%) {
1288 my %args = %{$_[0]};
1289 my ($parameter);
1290 my $count;
1291 print "Typedef:\n\n";
1293 print "typedef ".$args{'typedef'}." - ".$args{'purpose'}."\n";
1294 output_section_text(@_);
1297 # output struct as text
1298 sub output_struct_text(%) {
1299 my %args = %{$_[0]};
1300 my ($parameter);
1302 print $args{'type'}." ".$args{'struct'}." - ".$args{'purpose'}."\n\n";
1303 print $args{'type'}." ".$args{'struct'}." {\n";
1304 foreach $parameter (@{$args{'parameterlist'}}) {
1305 if ($parameter =~ /^#/) {
1306 print "$parameter\n";
1307 next;
1310 my $parameter_name = $parameter;
1311 $parameter_name =~ s/\[.*//;
1313 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1314 $type = $args{'parametertypes'}{$parameter};
1315 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1316 # pointer-to-function
1317 print "\t$1 $parameter) ($2);\n";
1318 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1319 # bitfield
1320 print "\t$1 $parameter$2;\n";
1321 } else {
1322 print "\t".$type." ".$parameter.";\n";
1325 print "};\n\n";
1327 print "Members:\n\n";
1328 foreach $parameter (@{$args{'parameterlist'}}) {
1329 ($parameter =~ /^#/) && next;
1331 my $parameter_name = $parameter;
1332 $parameter_name =~ s/\[.*//;
1334 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1335 print "$parameter\n\t";
1336 print $args{'parameterdescs'}{$parameter_name}."\n";
1338 print "\n";
1339 output_section_text(@_);
1342 sub output_blockhead_text(%) {
1343 my %args = %{$_[0]};
1344 my ($parameter, $section);
1346 foreach $section (@{$args{'sectionlist'}}) {
1347 print " $section:\n";
1348 print " -> ";
1349 output_highlight($args{'sections'}{$section});
1354 # generic output function for all types (function, struct/union, typedef, enum);
1355 # calls the generated, variable output_ function name based on
1356 # functype and output_mode
1357 sub output_declaration {
1358 no strict 'refs';
1359 my $name = shift;
1360 my $functype = shift;
1361 my $func = "output_${functype}_$output_mode";
1362 if (($function_only==0) ||
1363 ( $function_only == 1 && defined($function_table{$name})) ||
1364 ( $function_only == 2 && !defined($function_table{$name})))
1366 &$func(@_);
1367 $section_counter++;
1372 # generic output function - calls the right one based on current output mode.
1373 sub output_blockhead {
1374 no strict 'refs';
1375 my $func = "output_blockhead_".$output_mode;
1376 &$func(@_);
1377 $section_counter++;
1381 # takes a declaration (struct, union, enum, typedef) and
1382 # invokes the right handler. NOT called for functions.
1383 sub dump_declaration($$) {
1384 no strict 'refs';
1385 my ($prototype, $file) = @_;
1386 my $func = "dump_".$decl_type;
1387 &$func(@_);
1390 sub dump_union($$) {
1391 dump_struct(@_);
1394 sub dump_struct($$) {
1395 my $x = shift;
1396 my $file = shift;
1398 if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
1399 $declaration_name = $2;
1400 my $members = $3;
1402 # ignore embedded structs or unions
1403 $members =~ s/{.*?}//g;
1405 # ignore members marked private:
1406 $members =~ s/\/\*.*?private:.*?public:.*?\*\///gos;
1407 $members =~ s/\/\*.*?private:.*//gos;
1408 # strip comments:
1409 $members =~ s/\/\*.*?\*\///gos;
1411 create_parameterlist($members, ';', $file);
1413 output_declaration($declaration_name,
1414 'struct',
1415 {'struct' => $declaration_name,
1416 'module' => $modulename,
1417 'parameterlist' => \@parameterlist,
1418 'parameterdescs' => \%parameterdescs,
1419 'parametertypes' => \%parametertypes,
1420 'sectionlist' => \@sectionlist,
1421 'sections' => \%sections,
1422 'purpose' => $declaration_purpose,
1423 'type' => $decl_type
1426 else {
1427 print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
1428 ++$errors;
1432 sub dump_enum($$) {
1433 my $x = shift;
1434 my $file = shift;
1436 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1437 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1438 $declaration_name = $1;
1439 my $members = $2;
1441 foreach my $arg (split ',', $members) {
1442 $arg =~ s/^\s*(\w+).*/$1/;
1443 push @parameterlist, $arg;
1444 if (!$parameterdescs{$arg}) {
1445 $parameterdescs{$arg} = $undescribed;
1446 print STDERR "Warning(${file}:$.): Enum value '$arg' ".
1447 "not described in enum '$declaration_name'\n";
1452 output_declaration($declaration_name,
1453 'enum',
1454 {'enum' => $declaration_name,
1455 'module' => $modulename,
1456 'parameterlist' => \@parameterlist,
1457 'parameterdescs' => \%parameterdescs,
1458 'sectionlist' => \@sectionlist,
1459 'sections' => \%sections,
1460 'purpose' => $declaration_purpose
1463 else {
1464 print STDERR "Error(${file}:$.): Cannot parse enum!\n";
1465 ++$errors;
1469 sub dump_typedef($$) {
1470 my $x = shift;
1471 my $file = shift;
1473 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1474 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1475 $x =~ s/\(*.\)\s*;$/;/;
1476 $x =~ s/\[*.\]\s*;$/;/;
1479 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1480 $declaration_name = $1;
1482 output_declaration($declaration_name,
1483 'typedef',
1484 {'typedef' => $declaration_name,
1485 'module' => $modulename,
1486 'sectionlist' => \@sectionlist,
1487 'sections' => \%sections,
1488 'purpose' => $declaration_purpose
1491 else {
1492 print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
1493 ++$errors;
1497 sub create_parameterlist($$$) {
1498 my $args = shift;
1499 my $splitter = shift;
1500 my $file = shift;
1501 my $type;
1502 my $param;
1504 # temporarily replace commas inside function pointer definition
1505 while ($args =~ /(\([^\),]+),/) {
1506 $args =~ s/(\([^\),]+),/$1#/g;
1509 foreach my $arg (split($splitter, $args)) {
1510 # strip comments
1511 $arg =~ s/\/\*.*\*\///;
1512 # strip leading/trailing spaces
1513 $arg =~ s/^\s*//;
1514 $arg =~ s/\s*$//;
1515 $arg =~ s/\s+/ /;
1517 if ($arg =~ /^#/) {
1518 # Treat preprocessor directive as a typeless variable just to fill
1519 # corresponding data structures "correctly". Catch it later in
1520 # output_* subs.
1521 push_parameter($arg, "", $file);
1522 <<<<<<< HEAD:scripts/kernel-doc
1523 } elsif ($arg =~ m/\(.*\*/) {
1524 =======
1525 } elsif ($arg =~ m/\(.+\)\s*\(/) {
1526 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:scripts/kernel-doc
1527 # pointer-to-function
1528 $arg =~ tr/#/,/;
1529 <<<<<<< HEAD:scripts/kernel-doc
1530 $arg =~ m/[^\(]+\(\*\s*([^\)]+)\)/;
1531 =======
1532 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
1533 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:scripts/kernel-doc
1534 $param = $1;
1535 $type = $arg;
1536 <<<<<<< HEAD:scripts/kernel-doc
1537 $type =~ s/([^\(]+\(\*)$param/$1/;
1538 =======
1539 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
1540 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:scripts/kernel-doc
1541 push_parameter($param, $type, $file);
1542 } elsif ($arg) {
1543 $arg =~ s/\s*:\s*/:/g;
1544 $arg =~ s/\s*\[/\[/g;
1546 my @args = split('\s*,\s*', $arg);
1547 if ($args[0] =~ m/\*/) {
1548 $args[0] =~ s/(\*+)\s*/ $1/;
1551 my @first_arg;
1552 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1553 shift @args;
1554 push(@first_arg, split('\s+', $1));
1555 push(@first_arg, $2);
1556 } else {
1557 @first_arg = split('\s+', shift @args);
1560 unshift(@args, pop @first_arg);
1561 $type = join " ", @first_arg;
1563 foreach $param (@args) {
1564 if ($param =~ m/^(\*+)\s*(.*)/) {
1565 push_parameter($2, "$type $1", $file);
1567 elsif ($param =~ m/(.*?):(\d+)/) {
1568 push_parameter($1, "$type:$2", $file)
1570 else {
1571 push_parameter($param, $type, $file);
1578 sub push_parameter($$$) {
1579 my $param = shift;
1580 my $type = shift;
1581 my $file = shift;
1583 if (($anon_struct_union == 1) && ($type eq "") &&
1584 ($param eq "}")) {
1585 return; # ignore the ending }; from anon. struct/union
1588 $anon_struct_union = 0;
1589 my $param_name = $param;
1590 $param_name =~ s/\[.*//;
1592 if ($type eq "" && $param =~ /\.\.\.$/)
1594 $type="";
1595 $parameterdescs{$param} = "variable arguments";
1597 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1599 $type="";
1600 $param="void";
1601 $parameterdescs{void} = "no arguments";
1603 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1604 # handle unnamed (anonymous) union or struct:
1606 $type = $param;
1607 $param = "{unnamed_" . $param . "}";
1608 $parameterdescs{$param} = "anonymous\n";
1609 $anon_struct_union = 1;
1612 # warn if parameter has no description
1613 # (but ignore ones starting with # as these are not parameters
1614 # but inline preprocessor statements);
1615 # also ignore unnamed structs/unions;
1616 if (!$anon_struct_union) {
1617 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1619 $parameterdescs{$param_name} = $undescribed;
1621 if (($type eq 'function') || ($type eq 'enum')) {
1622 print STDERR "Warning(${file}:$.): Function parameter ".
1623 "or member '$param' not " .
1624 "described in '$declaration_name'\n";
1626 print STDERR "Warning(${file}:$.):".
1627 " No description found for parameter '$param'\n";
1628 ++$warnings;
1632 push @parameterlist, $param;
1633 $parametertypes{$param} = $type;
1637 # takes a function prototype and the name of the current file being
1638 # processed and spits out all the details stored in the global
1639 # arrays/hashes.
1640 sub dump_function($$) {
1641 my $prototype = shift;
1642 my $file = shift;
1644 $prototype =~ s/^static +//;
1645 $prototype =~ s/^extern +//;
1646 $prototype =~ s/^asmlinkage +//;
1647 $prototype =~ s/^inline +//;
1648 $prototype =~ s/^__inline__ +//;
1649 $prototype =~ s/^__inline +//;
1650 $prototype =~ s/^__always_inline +//;
1651 $prototype =~ s/^noinline +//;
1652 $prototype =~ s/__devinit +//;
1653 $prototype =~ s/^#define\s+//; #ak added
1654 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
1656 # Yes, this truly is vile. We are looking for:
1657 # 1. Return type (may be nothing if we're looking at a macro)
1658 # 2. Function name
1659 # 3. Function parameters.
1661 # All the while we have to watch out for function pointer parameters
1662 # (which IIRC is what the two sections are for), C types (these
1663 # regexps don't even start to express all the possibilities), and
1664 # so on.
1666 # If you mess with these regexps, it's a good idea to check that
1667 # the following functions' documentation still comes out right:
1668 # - parport_register_device (function pointer parameters)
1669 # - atomic_set (macro)
1670 # - pci_match_device, __copy_to_user (long return type)
1672 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1673 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1674 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1675 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1676 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1677 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1678 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1679 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1680 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1681 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1682 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1683 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1684 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1685 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1686 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1687 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1688 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1689 $return_type = $1;
1690 $declaration_name = $2;
1691 my $args = $3;
1693 create_parameterlist($args, ',', $file);
1694 } else {
1695 print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1696 ++$errors;
1697 return;
1700 output_declaration($declaration_name,
1701 'function',
1702 {'function' => $declaration_name,
1703 'module' => $modulename,
1704 'functiontype' => $return_type,
1705 'parameterlist' => \@parameterlist,
1706 'parameterdescs' => \%parameterdescs,
1707 'parametertypes' => \%parametertypes,
1708 'sectionlist' => \@sectionlist,
1709 'sections' => \%sections,
1710 'purpose' => $declaration_purpose
1714 sub process_file($);
1716 # Read the file that maps relative names to absolute names for
1717 # separate source and object directories and for shadow trees.
1718 if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
1719 my ($relname, $absname);
1720 while(<SOURCE_MAP>) {
1721 chop();
1722 ($relname, $absname) = (split())[0..1];
1723 $relname =~ s:^/+::;
1724 $source_map{$relname} = $absname;
1726 close(SOURCE_MAP);
1729 if ($filelist) {
1730 open(FLIST,"<$filelist") or die "Can't open file list $filelist";
1731 while(<FLIST>) {
1732 chop;
1733 process_file($_);
1737 foreach (@ARGV) {
1738 chomp;
1739 process_file($_);
1741 if ($verbose && $errors) {
1742 print STDERR "$errors errors\n";
1744 if ($verbose && $warnings) {
1745 print STDERR "$warnings warnings\n";
1748 exit($errors);
1750 sub reset_state {
1751 $function = "";
1752 %constants = ();
1753 %parameterdescs = ();
1754 %parametertypes = ();
1755 @parameterlist = ();
1756 %sections = ();
1757 @sectionlist = ();
1758 $prototype = "";
1760 $state = 0;
1763 sub process_state3_function($$) {
1764 my $x = shift;
1765 my $file = shift;
1767 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1769 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) {
1770 # do nothing
1772 elsif ($x =~ /([^\{]*)/) {
1773 $prototype .= $1;
1775 if (($x =~ /\{/) || ($x =~ /\#define/) || ($x =~ /;/)) {
1776 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
1777 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1778 $prototype =~ s@^\s+@@gos; # strip leading spaces
1779 dump_function($prototype,$file);
1780 reset_state();
1784 sub process_state3_type($$) {
1785 my $x = shift;
1786 my $file = shift;
1788 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1789 $x =~ s@^\s+@@gos; # strip leading spaces
1790 $x =~ s@\s+$@@gos; # strip trailing spaces
1791 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1793 if ($x =~ /^#/) {
1794 # To distinguish preprocessor directive from regular declaration later.
1795 $x .= ";";
1798 while (1) {
1799 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1800 $prototype .= $1 . $2;
1801 ($2 eq '{') && $brcount++;
1802 ($2 eq '}') && $brcount--;
1803 if (($2 eq ';') && ($brcount == 0)) {
1804 dump_declaration($prototype,$file);
1805 reset_state();
1806 last;
1808 $x = $3;
1809 } else {
1810 $prototype .= $x;
1811 last;
1816 # xml_escape: replace <, >, and & in the text stream;
1818 # however, formatting controls that are generated internally/locally in the
1819 # kernel-doc script are not escaped here; instead, they begin life like
1820 # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
1821 # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
1822 # just before actual output; (this is done by local_unescape())
1823 sub xml_escape($) {
1824 my $text = shift;
1825 if (($output_mode eq "text") || ($output_mode eq "man")) {
1826 return $text;
1828 $text =~ s/\&/\\\\\\amp;/g;
1829 $text =~ s/\</\\\\\\lt;/g;
1830 $text =~ s/\>/\\\\\\gt;/g;
1831 return $text;
1834 # convert local escape strings to html
1835 # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
1836 sub local_unescape($) {
1837 my $text = shift;
1838 if (($output_mode eq "text") || ($output_mode eq "man")) {
1839 return $text;
1841 $text =~ s/\\\\\\\\lt:/</g;
1842 $text =~ s/\\\\\\\\gt:/>/g;
1843 return $text;
1846 sub process_file($) {
1847 my $file;
1848 my $identifier;
1849 my $func;
1850 my $descr;
1851 my $initial_section_counter = $section_counter;
1853 if (defined($ENV{'SRCTREE'})) {
1854 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
1856 else {
1857 $file = "@_";
1859 if (defined($source_map{$file})) {
1860 $file = $source_map{$file};
1863 if (!open(IN,"<$file")) {
1864 print STDERR "Error: Cannot open file $file\n";
1865 ++$errors;
1866 return;
1869 $section_counter = 0;
1870 while (<IN>) {
1871 if ($state == 0) {
1872 if (/$doc_start/o) {
1873 $state = 1; # next line is always the function name
1874 $in_doc_sect = 0;
1876 } elsif ($state == 1) { # this line is the function name (always)
1877 if (/$doc_block/o) {
1878 $state = 4;
1879 $contents = "";
1880 if ( $1 eq "" ) {
1881 $section = $section_intro;
1882 } else {
1883 $section = $1;
1886 elsif (/$doc_decl/o) {
1887 $identifier = $1;
1888 if (/\s*([\w\s]+?)\s*-/) {
1889 $identifier = $1;
1892 $state = 2;
1893 if (/-(.*)/) {
1894 # strip leading/trailing/multiple spaces
1895 $descr= $1;
1896 $descr =~ s/^\s*//;
1897 $descr =~ s/\s*$//;
1898 $descr =~ s/\s+/ /;
1899 $declaration_purpose = xml_escape($descr);
1900 } else {
1901 $declaration_purpose = "";
1904 if (($declaration_purpose eq "") && $verbose) {
1905 print STDERR "Warning(${file}:$.): missing initial short description on line:\n";
1906 print STDERR $_;
1907 ++$warnings;
1910 if ($identifier =~ m/^struct/) {
1911 $decl_type = 'struct';
1912 } elsif ($identifier =~ m/^union/) {
1913 $decl_type = 'union';
1914 } elsif ($identifier =~ m/^enum/) {
1915 $decl_type = 'enum';
1916 } elsif ($identifier =~ m/^typedef/) {
1917 $decl_type = 'typedef';
1918 } else {
1919 $decl_type = 'function';
1922 if ($verbose) {
1923 print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
1925 } else {
1926 print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
1927 " - I thought it was a doc line\n";
1928 ++$warnings;
1929 $state = 0;
1931 } elsif ($state == 2) { # look for head: lines, and include content
1932 if (/$doc_sect/o) {
1933 $newsection = $1;
1934 $newcontents = $2;
1936 if (($contents ne "") && ($contents ne "\n")) {
1937 if (!$in_doc_sect && $verbose) {
1938 print STDERR "Warning(${file}:$.): contents before sections\n";
1939 ++$warnings;
1941 dump_section($section, xml_escape($contents));
1942 $section = $section_default;
1945 $in_doc_sect = 1;
1946 $contents = $newcontents;
1947 if ($contents ne "") {
1948 while ((substr($contents, 0, 1) eq " ") ||
1949 substr($contents, 0, 1) eq "\t") {
1950 $contents = substr($contents, 1);
1952 $contents .= "\n";
1954 $section = $newsection;
1955 } elsif (/$doc_end/) {
1957 if ($contents ne "") {
1958 dump_section($section, xml_escape($contents));
1959 $section = $section_default;
1960 $contents = "";
1963 $prototype = "";
1964 $state = 3;
1965 $brcount = 0;
1966 # print STDERR "end of doc comment, looking for prototype\n";
1967 } elsif (/$doc_content/) {
1968 # miguel-style comment kludge, look for blank lines after
1969 # @parameter line to signify start of description
1970 if ($1 eq "" &&
1971 ($section =~ m/^@/ || $section eq $section_context)) {
1972 dump_section($section, xml_escape($contents));
1973 $section = $section_default;
1974 $contents = "";
1975 } else {
1976 $contents .= $1."\n";
1978 } else {
1979 # i dont know - bad line? ignore.
1980 print STDERR "Warning(${file}:$.): bad line: $_";
1981 ++$warnings;
1983 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
1984 if ($decl_type eq 'function') {
1985 process_state3_function($_, $file);
1986 } else {
1987 process_state3_type($_, $file);
1989 } elsif ($state == 4) {
1990 # Documentation block
1991 if (/$doc_block/) {
1992 dump_doc_section($section, xml_escape($contents));
1993 $contents = "";
1994 $function = "";
1995 %constants = ();
1996 %parameterdescs = ();
1997 %parametertypes = ();
1998 @parameterlist = ();
1999 %sections = ();
2000 @sectionlist = ();
2001 $prototype = "";
2002 if ( $1 eq "" ) {
2003 $section = $section_intro;
2004 } else {
2005 $section = $1;
2008 elsif (/$doc_end/)
2010 dump_doc_section($section, xml_escape($contents));
2011 $contents = "";
2012 $function = "";
2013 %constants = ();
2014 %parameterdescs = ();
2015 %parametertypes = ();
2016 @parameterlist = ();
2017 %sections = ();
2018 @sectionlist = ();
2019 $prototype = "";
2020 $state = 0;
2022 elsif (/$doc_content/)
2024 if ( $1 eq "" )
2026 $contents .= $blankline;
2028 else
2030 $contents .= $1 . "\n";
2035 if ($initial_section_counter == $section_counter) {
2036 print STDERR "Warning(${file}): no structured comments found\n";
2037 if ($output_mode eq "xml") {
2038 # The template wants at least one RefEntry here; make one.
2039 print "<refentry>\n";
2040 print " <refnamediv>\n";
2041 print " <refname>\n";
2042 print " ${file}\n";
2043 print " </refname>\n";
2044 print " <refpurpose>\n";
2045 print " Document generation inconsistency\n";
2046 print " </refpurpose>\n";
2047 print " </refnamediv>\n";
2048 print " <refsect1>\n";
2049 print " <title>\n";
2050 print " Oops\n";
2051 print " </title>\n";
2052 print " <warning>\n";
2053 print " <para>\n";
2054 print " The template for this document tried to insert\n";
2055 print " the structured comment from the file\n";
2056 print " <filename>${file}</filename> at this point,\n";
2057 print " but none was found.\n";
2058 print " This dummy section is inserted to allow\n";
2059 print " generation to continue.\n";
2060 print " </para>\n";
2061 print " </warning>\n";
2062 print " </refsect1>\n";
2063 print "</refentry>\n";