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 ##
10 ## #define enhancements by Armin Kuster <akuster@mvista.com> ##
11 ## Copyright (c) 2000 MontaVista Software, Inc. ##
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.
23 # 27/06/2001 - Allowed whitespace after initial "/**" and
24 # allowed comments before function declarations.
25 # -- Christian Kreibich <ck@whoop.org>
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.
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'.
49 # kernel-doc [ -docbook | -html | -text | -man ] [ -no-doc-sections ]
50 # [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile
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.
57 # Do not output DOC: sections
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.
74 # In the following table, (...)? signifies optional structure.
75 # (...)* signifies 0 or more structure elements
77 # * function_name(:)? (- short description)?
78 # (* @parameterx: (description of parameter x)?)*
80 # * (Description:)? (Description of function)?
81 # * (section header: (section description)? )*
84 # So .. the trivial example would be:
90 # If the Description: header tag is omitted, then there must be a blank line
91 # after the last parameter specification.
94 # * my_function - does my stuff
95 # * @my_arg: its mine damnit
97 # * Does my stuff explained.
100 # or, could also use:
102 # * my_function - does my stuff
103 # * @my_arg: its mine damnit
104 # * Description: Does my stuff explained.
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.
115 # * struct my_struct - short description
117 # * @b: second member
119 # * Longer description
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
134 # Example-sections should contain the string EXAMPLE so that they are marked
135 # appropriately in DocBook.
139 # * user_function - function that can only be called in user context
140 # * @a: some argument
141 # * Context: !in_interrupt()
145 # * user_function(22);
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.
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 = '\\&((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 = "";
209 my %highlights_text = ( $type_constant, "\$1",
212 $type_param, "\$1" );
213 my $blankline_text = "";
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";
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 if (defined($ENV{'KBUILD_VERBOSE'})) {
251 $verbose = "$ENV{'KBUILD_VERBOSE'}";
254 # Generated docbook code is inserted in a template at a point where
255 # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
256 # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
257 # We keep track of number of generated entries and generate a dummy
258 # if needs be to ensure the expanded template can be postprocessed
260 my $section_counter = 0;
266 # 1 - looking for function name
267 # 2 - scanning field start.
268 # 3 - scanning prototype.
269 # 4 - documentation block
273 #declaration types: can be
274 # 'function', 'struct', 'union', 'enum', 'typedef'
277 my $doc_special = "\@\%\$\&";
279 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
281 my $doc_com = '\s*\*\s*';
282 my $doc_decl = $doc_com.'(\w+)';
283 my $doc_sect = $doc_com.'(['.$doc_special.']?[\w\s]+):(.*)';
284 my $doc_content = $doc_com.'(.*)';
285 my $doc_block = $doc_com.'DOC:\s*(.*)?';
294 my $section_default = "Description"; # default section
295 my $section_intro = "Introduction";
296 my $section = $section_default;
297 my $section_context = "Context";
299 my $undescribed = "-- undescribed --";
303 while ($ARGV[0] =~ m/^-(.*)/) {
304 my $cmd = shift @ARGV;
305 if ($cmd eq "-html") {
306 $output_mode = "html";
307 %highlights = %highlights_html;
308 $blankline = $blankline_html;
309 } elsif ($cmd eq "-man") {
310 $output_mode = "man";
311 %highlights = %highlights_man;
312 $blankline = $blankline_man;
313 } elsif ($cmd eq "-text") {
314 $output_mode = "text";
315 %highlights = %highlights_text;
316 $blankline = $blankline_text;
317 } elsif ($cmd eq "-docbook") {
318 $output_mode = "xml";
319 %highlights = %highlights_xml;
320 $blankline = $blankline_xml;
321 } elsif ($cmd eq "-gnome") {
322 $output_mode = "gnome";
323 %highlights = %highlights_gnome;
324 $blankline = $blankline_gnome;
325 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
326 $modulename = shift @ARGV;
327 } elsif ($cmd eq "-function") { # to only output specific functions
329 $function = shift @ARGV;
330 $function_table{$function} = 1;
331 } elsif ($cmd eq "-nofunction") { # to only output specific functions
333 $function = shift @ARGV;
334 $function_table{$function} = 1;
335 } elsif ($cmd eq "-v") {
337 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
339 } elsif ($cmd eq '-filelist') {
340 $filelist = shift @ARGV;
341 } elsif ($cmd eq '-no-doc-sections') {
342 $no_doc_sections = 1;
346 # get kernel version from env
347 sub get_kernel_version() {
348 my $version = 'unknown kernel version';
350 if (defined($ENV{'KERNELVERSION'})) {
351 $version = $ENV{'KERNELVERSION'};
355 my $kernelversion = get_kernel_version();
357 # generate a sequence of code that will splice in highlighting information
358 # using the s// operator.
359 my $dohighlight = "";
360 foreach my $pattern (keys %highlights) {
361 # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
362 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
366 # dumps section contents to arrays/hashes intended for that purpose.
370 my $contents = join "\n", @_;
372 if ($name =~ m/$type_constant/) {
374 # print STDERR "constant section '$1' = '$contents'\n";
375 $constants{$name} = $contents;
376 } elsif ($name =~ m/$type_param/) {
377 # print STDERR "parameter def '$1' = '$contents'\n";
379 $parameterdescs{$name} = $contents;
381 # print STDERR "other section '$name' = '$contents'\n";
382 $sections{$name} = $contents;
383 push @sectionlist, $name;
388 # dump DOC: section after checking that it should go out
390 sub dump_doc_section {
392 my $contents = join "\n", @_;
394 if ($no_doc_sections) {
398 if (($function_only == 0) ||
399 ( $function_only == 1 && defined($function_table{$name})) ||
400 ( $function_only == 2 && !defined($function_table{$name})))
402 dump_section $name, $contents;
403 output_blockhead({'sectionlist' => \@sectionlist,
404 'sections' => \%sections,
405 'module' => $modulename,
406 'content-only' => ($function_only != 0), });
413 # parameterdescs, a hash.
414 # function => "function name"
415 # parameterlist => @list of parameters
416 # parameterdescs => %parameter descriptions
417 # sectionlist => @list of sections
418 # sections => %section descriptions
421 sub output_highlight {
422 my $contents = join "\n",@_;
426 # if (!defined $contents) {
428 # confess "output_highlight got called with no args?\n";
431 if ($output_mode eq "html" || $output_mode eq "xml") {
432 $contents = local_unescape($contents);
433 # convert data read & converted thru xml_escape() into &xyz; format:
434 $contents =~ s/\\\\\\/&/g;
436 # print STDERR "contents b4:$contents\n";
439 # print STDERR "contents af:$contents\n";
441 foreach $line (split "\n", $contents) {
443 print $lineprefix, local_unescape($blankline);
445 $line =~ s/\\\\\\/\&/g;
446 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
449 print $lineprefix, $line;
456 #output sections in html
457 sub output_section_html(%) {
461 foreach $section (@{$args{'sectionlist'}}) {
462 print "<h3>$section</h3>\n";
463 print "<blockquote>\n";
464 output_highlight($args{'sections'}{$section});
465 print "</blockquote>\n";
469 # output enum in html
470 sub output_enum_html(%) {
474 print "<h2>enum ".$args{'enum'}."</h2>\n";
476 print "<b>enum ".$args{'enum'}."</b> {<br>\n";
478 foreach $parameter (@{$args{'parameterlist'}}) {
479 print " <b>".$parameter."</b>";
480 if ($count != $#{$args{'parameterlist'}}) {
488 print "<h3>Constants</h3>\n";
490 foreach $parameter (@{$args{'parameterlist'}}) {
491 print "<dt><b>".$parameter."</b>\n";
493 output_highlight($args{'parameterdescs'}{$parameter});
496 output_section_html(@_);
500 # output typedef in html
501 sub output_typedef_html(%) {
505 print "<h2>typedef ".$args{'typedef'}."</h2>\n";
507 print "<b>typedef ".$args{'typedef'}."</b>\n";
508 output_section_html(@_);
512 # output struct in html
513 sub output_struct_html(%) {
517 print "<h2>".$args{'type'}." ".$args{'struct'}. " - " .$args{'purpose'}."</h2>\n";
518 print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n";
519 foreach $parameter (@{$args{'parameterlist'}}) {
520 if ($parameter =~ /^#/) {
521 print "$parameter<br>\n";
524 my $parameter_name = $parameter;
525 $parameter_name =~ s/\[.*//;
527 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
528 $type = $args{'parametertypes'}{$parameter};
529 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
530 # pointer-to-function
531 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
532 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
534 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
536 print " <i>$type</i> <b>$parameter</b>;<br>\n";
541 print "<h3>Members</h3>\n";
543 foreach $parameter (@{$args{'parameterlist'}}) {
544 ($parameter =~ /^#/) && next;
546 my $parameter_name = $parameter;
547 $parameter_name =~ s/\[.*//;
549 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
550 print "<dt><b>".$parameter."</b>\n";
552 output_highlight($args{'parameterdescs'}{$parameter_name});
555 output_section_html(@_);
559 # output function in html
560 sub output_function_html(%) {
562 my ($parameter, $section);
565 print "<h2>" .$args{'function'}." - ".$args{'purpose'}."</h2>\n";
566 print "<i>".$args{'functiontype'}."</i>\n";
567 print "<b>".$args{'function'}."</b>\n";
570 foreach $parameter (@{$args{'parameterlist'}}) {
571 $type = $args{'parametertypes'}{$parameter};
572 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
573 # pointer-to-function
574 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
576 print "<i>".$type."</i> <b>".$parameter."</b>";
578 if ($count != $#{$args{'parameterlist'}}) {
585 print "<h3>Arguments</h3>\n";
587 foreach $parameter (@{$args{'parameterlist'}}) {
588 my $parameter_name = $parameter;
589 $parameter_name =~ s/\[.*//;
591 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
592 print "<dt><b>".$parameter."</b>\n";
594 output_highlight($args{'parameterdescs'}{$parameter_name});
597 output_section_html(@_);
601 # output DOC: block header in html
602 sub output_blockhead_html(%) {
604 my ($parameter, $section);
607 foreach $section (@{$args{'sectionlist'}}) {
608 print "<h3>$section</h3>\n";
610 output_highlight($args{'sections'}{$section});
616 sub output_section_xml(%) {
619 # print out each section
621 foreach $section (@{$args{'sectionlist'}}) {
622 print "<refsect1>\n";
623 print "<title>$section</title>\n";
624 if ($section =~ m/EXAMPLE/i) {
625 print "<informalexample><programlisting>\n";
629 output_highlight($args{'sections'}{$section});
630 if ($section =~ m/EXAMPLE/i) {
631 print "</programlisting></informalexample>\n";
635 print "</refsect1>\n";
639 # output function in XML DocBook
640 sub output_function_xml(%) {
642 my ($parameter, $section);
646 $id = "API-".$args{'function'};
647 $id =~ s/[^A-Za-z0-9]/-/g;
649 print "<refentry id=\"$id\">\n";
650 print "<refentryinfo>\n";
651 print " <title>LINUX</title>\n";
652 print " <productname>Kernel Hackers Manual</productname>\n";
653 print " <date>$man_date</date>\n";
654 print "</refentryinfo>\n";
656 print " <refentrytitle><phrase>".$args{'function'}."</phrase></refentrytitle>\n";
657 print " <manvolnum>9</manvolnum>\n";
658 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
659 print "</refmeta>\n";
660 print "<refnamediv>\n";
661 print " <refname>".$args{'function'}."</refname>\n";
662 print " <refpurpose>\n";
664 output_highlight ($args{'purpose'});
665 print " </refpurpose>\n";
666 print "</refnamediv>\n";
668 print "<refsynopsisdiv>\n";
669 print " <title>Synopsis</title>\n";
670 print " <funcsynopsis><funcprototype>\n";
671 print " <funcdef>".$args{'functiontype'}." ";
672 print "<function>".$args{'function'}." </function></funcdef>\n";
675 if ($#{$args{'parameterlist'}} >= 0) {
676 foreach $parameter (@{$args{'parameterlist'}}) {
677 $type = $args{'parametertypes'}{$parameter};
678 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
679 # pointer-to-function
680 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
681 print " <funcparams>$2</funcparams></paramdef>\n";
683 print " <paramdef>".$type;
684 print " <parameter>$parameter</parameter></paramdef>\n";
690 print " </funcprototype></funcsynopsis>\n";
691 print "</refsynopsisdiv>\n";
694 print "<refsect1>\n <title>Arguments</title>\n";
695 if ($#{$args{'parameterlist'}} >= 0) {
696 print " <variablelist>\n";
697 foreach $parameter (@{$args{'parameterlist'}}) {
698 my $parameter_name = $parameter;
699 $parameter_name =~ s/\[.*//;
701 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
702 print " <listitem>\n <para>\n";
704 output_highlight($args{'parameterdescs'}{$parameter_name});
705 print " </para>\n </listitem>\n </varlistentry>\n";
707 print " </variablelist>\n";
709 print " <para>\n None\n </para>\n";
711 print "</refsect1>\n";
713 output_section_xml(@_);
714 print "</refentry>\n\n";
717 # output struct in XML DocBook
718 sub output_struct_xml(%) {
720 my ($parameter, $section);
723 $id = "API-struct-".$args{'struct'};
724 $id =~ s/[^A-Za-z0-9]/-/g;
726 print "<refentry id=\"$id\">\n";
727 print "<refentryinfo>\n";
728 print " <title>LINUX</title>\n";
729 print " <productname>Kernel Hackers Manual</productname>\n";
730 print " <date>$man_date</date>\n";
731 print "</refentryinfo>\n";
733 print " <refentrytitle><phrase>".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n";
734 print " <manvolnum>9</manvolnum>\n";
735 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
736 print "</refmeta>\n";
737 print "<refnamediv>\n";
738 print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n";
739 print " <refpurpose>\n";
741 output_highlight ($args{'purpose'});
742 print " </refpurpose>\n";
743 print "</refnamediv>\n";
745 print "<refsynopsisdiv>\n";
746 print " <title>Synopsis</title>\n";
747 print " <programlisting>\n";
748 print $args{'type'}." ".$args{'struct'}." {\n";
749 foreach $parameter (@{$args{'parameterlist'}}) {
750 if ($parameter =~ /^#/) {
751 print "$parameter\n";
755 my $parameter_name = $parameter;
756 $parameter_name =~ s/\[.*//;
758 defined($args{'parameterdescs'}{$parameter_name}) || next;
759 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
760 $type = $args{'parametertypes'}{$parameter};
761 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
762 # pointer-to-function
763 print " $1 $parameter) ($2);\n";
764 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
766 print " $1 $parameter$2;\n";
768 print " ".$type." ".$parameter.";\n";
772 print " </programlisting>\n";
773 print "</refsynopsisdiv>\n";
775 print " <refsect1>\n";
776 print " <title>Members</title>\n";
778 print " <variablelist>\n";
779 foreach $parameter (@{$args{'parameterlist'}}) {
780 ($parameter =~ /^#/) && next;
782 my $parameter_name = $parameter;
783 $parameter_name =~ s/\[.*//;
785 defined($args{'parameterdescs'}{$parameter_name}) || next;
786 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
787 print " <varlistentry>";
788 print " <term>$parameter</term>\n";
789 print " <listitem><para>\n";
790 output_highlight($args{'parameterdescs'}{$parameter_name});
791 print " </para></listitem>\n";
792 print " </varlistentry>\n";
794 print " </variablelist>\n";
795 print " </refsect1>\n";
797 output_section_xml(@_);
799 print "</refentry>\n\n";
802 # output enum in XML DocBook
803 sub output_enum_xml(%) {
805 my ($parameter, $section);
809 $id = "API-enum-".$args{'enum'};
810 $id =~ s/[^A-Za-z0-9]/-/g;
812 print "<refentry id=\"$id\">\n";
813 print "<refentryinfo>\n";
814 print " <title>LINUX</title>\n";
815 print " <productname>Kernel Hackers Manual</productname>\n";
816 print " <date>$man_date</date>\n";
817 print "</refentryinfo>\n";
819 print " <refentrytitle><phrase>enum ".$args{'enum'}."</phrase></refentrytitle>\n";
820 print " <manvolnum>9</manvolnum>\n";
821 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
822 print "</refmeta>\n";
823 print "<refnamediv>\n";
824 print " <refname>enum ".$args{'enum'}."</refname>\n";
825 print " <refpurpose>\n";
827 output_highlight ($args{'purpose'});
828 print " </refpurpose>\n";
829 print "</refnamediv>\n";
831 print "<refsynopsisdiv>\n";
832 print " <title>Synopsis</title>\n";
833 print " <programlisting>\n";
834 print "enum ".$args{'enum'}." {\n";
836 foreach $parameter (@{$args{'parameterlist'}}) {
838 if ($count != $#{$args{'parameterlist'}}) {
845 print " </programlisting>\n";
846 print "</refsynopsisdiv>\n";
848 print "<refsect1>\n";
849 print " <title>Constants</title>\n";
850 print " <variablelist>\n";
851 foreach $parameter (@{$args{'parameterlist'}}) {
852 my $parameter_name = $parameter;
853 $parameter_name =~ s/\[.*//;
855 print " <varlistentry>";
856 print " <term>$parameter</term>\n";
857 print " <listitem><para>\n";
858 output_highlight($args{'parameterdescs'}{$parameter_name});
859 print " </para></listitem>\n";
860 print " </varlistentry>\n";
862 print " </variablelist>\n";
863 print "</refsect1>\n";
865 output_section_xml(@_);
867 print "</refentry>\n\n";
870 # output typedef in XML DocBook
871 sub output_typedef_xml(%) {
873 my ($parameter, $section);
876 $id = "API-typedef-".$args{'typedef'};
877 $id =~ s/[^A-Za-z0-9]/-/g;
879 print "<refentry id=\"$id\">\n";
880 print "<refentryinfo>\n";
881 print " <title>LINUX</title>\n";
882 print " <productname>Kernel Hackers Manual</productname>\n";
883 print " <date>$man_date</date>\n";
884 print "</refentryinfo>\n";
886 print " <refentrytitle><phrase>typedef ".$args{'typedef'}."</phrase></refentrytitle>\n";
887 print " <manvolnum>9</manvolnum>\n";
888 print "</refmeta>\n";
889 print "<refnamediv>\n";
890 print " <refname>typedef ".$args{'typedef'}."</refname>\n";
891 print " <refpurpose>\n";
893 output_highlight ($args{'purpose'});
894 print " </refpurpose>\n";
895 print "</refnamediv>\n";
897 print "<refsynopsisdiv>\n";
898 print " <title>Synopsis</title>\n";
899 print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n";
900 print "</refsynopsisdiv>\n";
902 output_section_xml(@_);
904 print "</refentry>\n\n";
907 # output in XML DocBook
908 sub output_blockhead_xml(%) {
910 my ($parameter, $section);
913 my $id = $args{'module'};
914 $id =~ s/[^A-Za-z0-9]/-/g;
916 # print out each section
918 foreach $section (@{$args{'sectionlist'}}) {
919 if (!$args{'content-only'}) {
920 print "<refsect1>\n <title>$section</title>\n";
922 if ($section =~ m/EXAMPLE/i) {
923 print "<example><para>\n";
927 output_highlight($args{'sections'}{$section});
928 if ($section =~ m/EXAMPLE/i) {
929 print "</para></example>\n";
933 if (!$args{'content-only'}) {
934 print "\n</refsect1>\n";
941 # output in XML DocBook
942 sub output_function_gnome {
944 my ($parameter, $section);
948 $id = $args{'module'}."-".$args{'function'};
949 $id =~ s/[^A-Za-z0-9]/-/g;
952 print " <title id=\"$id\">".$args{'function'}."</title>\n";
954 print " <funcsynopsis>\n";
955 print " <funcdef>".$args{'functiontype'}." ";
956 print "<function>".$args{'function'}." ";
957 print "</function></funcdef>\n";
960 if ($#{$args{'parameterlist'}} >= 0) {
961 foreach $parameter (@{$args{'parameterlist'}}) {
962 $type = $args{'parametertypes'}{$parameter};
963 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
964 # pointer-to-function
965 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
966 print " <funcparams>$2</funcparams></paramdef>\n";
968 print " <paramdef>".$type;
969 print " <parameter>$parameter</parameter></paramdef>\n";
975 print " </funcsynopsis>\n";
976 if ($#{$args{'parameterlist'}} >= 0) {
977 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
978 print "<tgroup cols=\"2\">\n";
979 print "<colspec colwidth=\"2*\">\n";
980 print "<colspec colwidth=\"8*\">\n";
982 foreach $parameter (@{$args{'parameterlist'}}) {
983 my $parameter_name = $parameter;
984 $parameter_name =~ s/\[.*//;
986 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
989 output_highlight($args{'parameterdescs'}{$parameter_name});
990 print " </entry></row>\n";
992 print " </tbody></tgroup></informaltable>\n";
994 print " <para>\n None\n </para>\n";
997 # print out each section
999 foreach $section (@{$args{'sectionlist'}}) {
1000 print "<simplesect>\n <title>$section</title>\n";
1001 if ($section =~ m/EXAMPLE/i) {
1002 print "<example><programlisting>\n";
1006 output_highlight($args{'sections'}{$section});
1008 if ($section =~ m/EXAMPLE/i) {
1009 print "</programlisting></example>\n";
1012 print " </simplesect>\n";
1015 print "</sect2>\n\n";
1019 # output function in man
1020 sub output_function_man(%) {
1021 my %args = %{$_[0]};
1022 my ($parameter, $section);
1025 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
1028 print $args{'function'}." \\- ".$args{'purpose'}."\n";
1030 print ".SH SYNOPSIS\n";
1031 if ($args{'functiontype'} ne "") {
1032 print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n";
1034 print ".B \"".$args{'function'}."\n";
1039 foreach my $parameter (@{$args{'parameterlist'}}) {
1040 if ($count == $#{$args{'parameterlist'}}) {
1043 $type = $args{'parametertypes'}{$parameter};
1044 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1045 # pointer-to-function
1046 print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n";
1048 $type =~ s/([^\*])$/$1 /;
1049 print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n";
1055 print ".SH ARGUMENTS\n";
1056 foreach $parameter (@{$args{'parameterlist'}}) {
1057 my $parameter_name = $parameter;
1058 $parameter_name =~ s/\[.*//;
1060 print ".IP \"".$parameter."\" 12\n";
1061 output_highlight($args{'parameterdescs'}{$parameter_name});
1063 foreach $section (@{$args{'sectionlist'}}) {
1064 print ".SH \"", uc $section, "\"\n";
1065 output_highlight($args{'sections'}{$section});
1070 # output enum in man
1071 sub output_enum_man(%) {
1072 my %args = %{$_[0]};
1073 my ($parameter, $section);
1076 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1079 print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n";
1081 print ".SH SYNOPSIS\n";
1082 print "enum ".$args{'enum'}." {\n";
1084 foreach my $parameter (@{$args{'parameterlist'}}) {
1085 print ".br\n.BI \" $parameter\"\n";
1086 if ($count == $#{$args{'parameterlist'}}) {
1096 print ".SH Constants\n";
1097 foreach $parameter (@{$args{'parameterlist'}}) {
1098 my $parameter_name = $parameter;
1099 $parameter_name =~ s/\[.*//;
1101 print ".IP \"".$parameter."\" 12\n";
1102 output_highlight($args{'parameterdescs'}{$parameter_name});
1104 foreach $section (@{$args{'sectionlist'}}) {
1105 print ".SH \"$section\"\n";
1106 output_highlight($args{'sections'}{$section});
1111 # output struct in man
1112 sub output_struct_man(%) {
1113 my %args = %{$_[0]};
1114 my ($parameter, $section);
1116 print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n";
1119 print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n";
1121 print ".SH SYNOPSIS\n";
1122 print $args{'type'}." ".$args{'struct'}." {\n.br\n";
1124 foreach my $parameter (@{$args{'parameterlist'}}) {
1125 if ($parameter =~ /^#/) {
1126 print ".BI \"$parameter\"\n.br\n";
1129 my $parameter_name = $parameter;
1130 $parameter_name =~ s/\[.*//;
1132 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1133 $type = $args{'parametertypes'}{$parameter};
1134 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1135 # pointer-to-function
1136 print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n";
1137 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1139 print ".BI \" ".$1."\ \" ".$parameter.$2." \""."\"\n;\n";
1141 $type =~ s/([^\*])$/$1 /;
1142 print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n";
1148 print ".SH Members\n";
1149 foreach $parameter (@{$args{'parameterlist'}}) {
1150 ($parameter =~ /^#/) && next;
1152 my $parameter_name = $parameter;
1153 $parameter_name =~ s/\[.*//;
1155 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1156 print ".IP \"".$parameter."\" 12\n";
1157 output_highlight($args{'parameterdescs'}{$parameter_name});
1159 foreach $section (@{$args{'sectionlist'}}) {
1160 print ".SH \"$section\"\n";
1161 output_highlight($args{'sections'}{$section});
1166 # output typedef in man
1167 sub output_typedef_man(%) {
1168 my %args = %{$_[0]};
1169 my ($parameter, $section);
1171 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1174 print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n";
1176 foreach $section (@{$args{'sectionlist'}}) {
1177 print ".SH \"$section\"\n";
1178 output_highlight($args{'sections'}{$section});
1182 sub output_blockhead_man(%) {
1183 my %args = %{$_[0]};
1184 my ($parameter, $section);
1187 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1189 foreach $section (@{$args{'sectionlist'}}) {
1190 print ".SH \"$section\"\n";
1191 output_highlight($args{'sections'}{$section});
1197 sub output_function_text(%) {
1198 my %args = %{$_[0]};
1199 my ($parameter, $section);
1203 print $args{'function'}." - ".$args{'purpose'}."\n";
1205 print "\nSynopsis:\n\n";
1206 if ($args{'functiontype'} ne "") {
1207 $start = $args{'functiontype'}." ".$args{'function'}." (";
1209 $start = $args{'function'}." (";
1214 foreach my $parameter (@{$args{'parameterlist'}}) {
1215 $type = $args{'parametertypes'}{$parameter};
1216 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1217 # pointer-to-function
1218 print $1.$parameter.") (".$2;
1220 print $type." ".$parameter;
1222 if ($count != $#{$args{'parameterlist'}}) {
1225 print " " x length($start);
1231 print "Arguments:\n\n";
1232 foreach $parameter (@{$args{'parameterlist'}}) {
1233 my $parameter_name = $parameter;
1234 $parameter_name =~ s/\[.*//;
1236 print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n";
1238 output_section_text(@_);
1241 #output sections in text
1242 sub output_section_text(%) {
1243 my %args = %{$_[0]};
1247 foreach $section (@{$args{'sectionlist'}}) {
1248 print "$section:\n\n";
1249 output_highlight($args{'sections'}{$section});
1254 # output enum in text
1255 sub output_enum_text(%) {
1256 my %args = %{$_[0]};
1261 print "enum ".$args{'enum'}." - ".$args{'purpose'}."\n\n";
1262 print "enum ".$args{'enum'}." {\n";
1264 foreach $parameter (@{$args{'parameterlist'}}) {
1265 print "\t$parameter";
1266 if ($count != $#{$args{'parameterlist'}}) {
1274 print "Constants:\n\n";
1275 foreach $parameter (@{$args{'parameterlist'}}) {
1276 print "$parameter\n\t";
1277 print $args{'parameterdescs'}{$parameter}."\n";
1280 output_section_text(@_);
1283 # output typedef in text
1284 sub output_typedef_text(%) {
1285 my %args = %{$_[0]};
1288 print "Typedef:\n\n";
1290 print "typedef ".$args{'typedef'}." - ".$args{'purpose'}."\n";
1291 output_section_text(@_);
1294 # output struct as text
1295 sub output_struct_text(%) {
1296 my %args = %{$_[0]};
1299 print $args{'type'}." ".$args{'struct'}." - ".$args{'purpose'}."\n\n";
1300 print $args{'type'}." ".$args{'struct'}." {\n";
1301 foreach $parameter (@{$args{'parameterlist'}}) {
1302 if ($parameter =~ /^#/) {
1303 print "$parameter\n";
1307 my $parameter_name = $parameter;
1308 $parameter_name =~ s/\[.*//;
1310 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1311 $type = $args{'parametertypes'}{$parameter};
1312 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1313 # pointer-to-function
1314 print "\t$1 $parameter) ($2);\n";
1315 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1317 print "\t$1 $parameter$2;\n";
1319 print "\t".$type." ".$parameter.";\n";
1324 print "Members:\n\n";
1325 foreach $parameter (@{$args{'parameterlist'}}) {
1326 ($parameter =~ /^#/) && next;
1328 my $parameter_name = $parameter;
1329 $parameter_name =~ s/\[.*//;
1331 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1332 print "$parameter\n\t";
1333 print $args{'parameterdescs'}{$parameter_name}."\n";
1336 output_section_text(@_);
1339 sub output_blockhead_text(%) {
1340 my %args = %{$_[0]};
1341 my ($parameter, $section);
1343 foreach $section (@{$args{'sectionlist'}}) {
1344 print " $section:\n";
1346 output_highlight($args{'sections'}{$section});
1351 # generic output function for all types (function, struct/union, typedef, enum);
1352 # calls the generated, variable output_ function name based on
1353 # functype and output_mode
1354 sub output_declaration {
1357 my $functype = shift;
1358 my $func = "output_${functype}_$output_mode";
1359 if (($function_only==0) ||
1360 ( $function_only == 1 && defined($function_table{$name})) ||
1361 ( $function_only == 2 && !defined($function_table{$name})))
1369 # generic output function - calls the right one based on current output mode.
1370 sub output_blockhead {
1372 my $func = "output_blockhead_".$output_mode;
1378 # takes a declaration (struct, union, enum, typedef) and
1379 # invokes the right handler. NOT called for functions.
1380 sub dump_declaration($$) {
1382 my ($prototype, $file) = @_;
1383 my $func = "dump_".$decl_type;
1387 sub dump_union($$) {
1391 sub dump_struct($$) {
1395 if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
1396 $declaration_name = $2;
1399 # ignore embedded structs or unions
1400 $members =~ s/{.*?}//g;
1402 # ignore members marked private:
1403 $members =~ s/\/\*.*?private:.*?public:.*?\*\///gos;
1404 $members =~ s/\/\*.*?private:.*//gos;
1406 $members =~ s/\/\*.*?\*\///gos;
1408 create_parameterlist($members, ';', $file);
1410 output_declaration($declaration_name,
1412 {'struct' => $declaration_name,
1413 'module' => $modulename,
1414 'parameterlist' => \@parameterlist,
1415 'parameterdescs' => \%parameterdescs,
1416 'parametertypes' => \%parametertypes,
1417 'sectionlist' => \@sectionlist,
1418 'sections' => \%sections,
1419 'purpose' => $declaration_purpose,
1420 'type' => $decl_type
1424 print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
1433 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1434 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1435 $declaration_name = $1;
1438 foreach my $arg (split ',', $members) {
1439 $arg =~ s/^\s*(\w+).*/$1/;
1440 push @parameterlist, $arg;
1441 if (!$parameterdescs{$arg}) {
1442 $parameterdescs{$arg} = $undescribed;
1443 print STDERR "Warning(${file}:$.): Enum value '$arg' ".
1444 "not described in enum '$declaration_name'\n";
1449 output_declaration($declaration_name,
1451 {'enum' => $declaration_name,
1452 'module' => $modulename,
1453 'parameterlist' => \@parameterlist,
1454 'parameterdescs' => \%parameterdescs,
1455 'sectionlist' => \@sectionlist,
1456 'sections' => \%sections,
1457 'purpose' => $declaration_purpose
1461 print STDERR "Error(${file}:$.): Cannot parse enum!\n";
1466 sub dump_typedef($$) {
1470 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1471 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1472 $x =~ s/\(*.\)\s*;$/;/;
1473 $x =~ s/\[*.\]\s*;$/;/;
1476 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1477 $declaration_name = $1;
1479 output_declaration($declaration_name,
1481 {'typedef' => $declaration_name,
1482 'module' => $modulename,
1483 'sectionlist' => \@sectionlist,
1484 'sections' => \%sections,
1485 'purpose' => $declaration_purpose
1489 print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
1494 sub create_parameterlist($$$) {
1496 my $splitter = shift;
1501 # temporarily replace commas inside function pointer definition
1502 while ($args =~ /(\([^\),]+),/) {
1503 $args =~ s/(\([^\),]+),/$1#/g;
1506 foreach my $arg (split($splitter, $args)) {
1508 $arg =~ s/\/\*.*\*\///;
1509 # strip leading/trailing spaces
1515 # Treat preprocessor directive as a typeless variable just to fill
1516 # corresponding data structures "correctly". Catch it later in
1518 push_parameter($arg, "", $file);
1519 } elsif ($arg =~ m/\(.+\)\s*\(/) {
1520 # pointer-to-function
1522 $arg =~ m/[^\(]+\(\*?\s*(\w*)\s*\)/;
1525 $type =~ s/([^\(]+\(\*?)\s*$param/$1/;
1526 push_parameter($param, $type, $file);
1528 $arg =~ s/\s*:\s*/:/g;
1529 $arg =~ s/\s*\[/\[/g;
1531 my @args = split('\s*,\s*', $arg);
1532 if ($args[0] =~ m/\*/) {
1533 $args[0] =~ s/(\*+)\s*/ $1/;
1537 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1539 push(@first_arg, split('\s+', $1));
1540 push(@first_arg, $2);
1542 @first_arg = split('\s+', shift @args);
1545 unshift(@args, pop @first_arg);
1546 $type = join " ", @first_arg;
1548 foreach $param (@args) {
1549 if ($param =~ m/^(\*+)\s*(.*)/) {
1550 push_parameter($2, "$type $1", $file);
1552 elsif ($param =~ m/(.*?):(\d+)/) {
1553 push_parameter($1, "$type:$2", $file)
1556 push_parameter($param, $type, $file);
1563 sub push_parameter($$$) {
1568 if (($anon_struct_union == 1) && ($type eq "") &&
1570 return; # ignore the ending }; from anon. struct/union
1573 $anon_struct_union = 0;
1574 my $param_name = $param;
1575 $param_name =~ s/\[.*//;
1577 if ($type eq "" && $param =~ /\.\.\.$/)
1580 $parameterdescs{$param} = "variable arguments";
1582 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1586 $parameterdescs{void} = "no arguments";
1588 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1589 # handle unnamed (anonymous) union or struct:
1592 $param = "{unnamed_" . $param . "}";
1593 $parameterdescs{$param} = "anonymous\n";
1594 $anon_struct_union = 1;
1597 # warn if parameter has no description
1598 # (but ignore ones starting with # as these are not parameters
1599 # but inline preprocessor statements);
1600 # also ignore unnamed structs/unions;
1601 if (!$anon_struct_union) {
1602 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1604 $parameterdescs{$param_name} = $undescribed;
1606 if (($type eq 'function') || ($type eq 'enum')) {
1607 print STDERR "Warning(${file}:$.): Function parameter ".
1608 "or member '$param' not " .
1609 "described in '$declaration_name'\n";
1611 print STDERR "Warning(${file}:$.):".
1612 " No description found for parameter '$param'\n";
1617 push @parameterlist, $param;
1618 $parametertypes{$param} = $type;
1622 # takes a function prototype and the name of the current file being
1623 # processed and spits out all the details stored in the global
1625 sub dump_function($$) {
1626 my $prototype = shift;
1629 $prototype =~ s/^static +//;
1630 $prototype =~ s/^extern +//;
1631 $prototype =~ s/^asmlinkage +//;
1632 $prototype =~ s/^inline +//;
1633 $prototype =~ s/^__inline__ +//;
1634 $prototype =~ s/^__inline +//;
1635 $prototype =~ s/^__always_inline +//;
1636 $prototype =~ s/^noinline +//;
1637 $prototype =~ s/__devinit +//;
1638 $prototype =~ s/^#define\s+//; #ak added
1639 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
1641 # Yes, this truly is vile. We are looking for:
1642 # 1. Return type (may be nothing if we're looking at a macro)
1644 # 3. Function parameters.
1646 # All the while we have to watch out for function pointer parameters
1647 # (which IIRC is what the two sections are for), C types (these
1648 # regexps don't even start to express all the possibilities), and
1651 # If you mess with these regexps, it's a good idea to check that
1652 # the following functions' documentation still comes out right:
1653 # - parport_register_device (function pointer parameters)
1654 # - atomic_set (macro)
1655 # - pci_match_device, __copy_to_user (long return type)
1657 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1658 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1659 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1660 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1661 $prototype =~ m/^(\w+\s+\w+\s*\*+)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1662 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1663 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1664 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1665 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1666 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1667 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1668 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1669 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1670 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1671 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1672 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1673 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1675 $declaration_name = $2;
1678 create_parameterlist($args, ',', $file);
1680 print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1685 output_declaration($declaration_name,
1687 {'function' => $declaration_name,
1688 'module' => $modulename,
1689 'functiontype' => $return_type,
1690 'parameterlist' => \@parameterlist,
1691 'parameterdescs' => \%parameterdescs,
1692 'parametertypes' => \%parametertypes,
1693 'sectionlist' => \@sectionlist,
1694 'sections' => \%sections,
1695 'purpose' => $declaration_purpose
1699 sub process_file($);
1701 # Read the file that maps relative names to absolute names for
1702 # separate source and object directories and for shadow trees.
1703 if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
1704 my ($relname, $absname);
1705 while(<SOURCE_MAP>) {
1707 ($relname, $absname) = (split())[0..1];
1708 $relname =~ s:^/+::;
1709 $source_map{$relname} = $absname;
1715 open(FLIST,"<$filelist") or die "Can't open file list $filelist";
1726 if ($verbose && $errors) {
1727 print STDERR "$errors errors\n";
1729 if ($verbose && $warnings) {
1730 print STDERR "$warnings warnings\n";
1738 %parameterdescs = ();
1739 %parametertypes = ();
1740 @parameterlist = ();
1748 sub process_state3_function($$) {
1752 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1754 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) {
1757 elsif ($x =~ /([^\{]*)/) {
1760 if (($x =~ /\{/) || ($x =~ /\#define/) || ($x =~ /;/)) {
1761 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
1762 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1763 $prototype =~ s@^\s+@@gos; # strip leading spaces
1764 dump_function($prototype,$file);
1769 sub process_state3_type($$) {
1773 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1774 $x =~ s@^\s+@@gos; # strip leading spaces
1775 $x =~ s@\s+$@@gos; # strip trailing spaces
1776 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1779 # To distinguish preprocessor directive from regular declaration later.
1784 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1785 $prototype .= $1 . $2;
1786 ($2 eq '{') && $brcount++;
1787 ($2 eq '}') && $brcount--;
1788 if (($2 eq ';') && ($brcount == 0)) {
1789 dump_declaration($prototype,$file);
1801 # xml_escape: replace <, >, and & in the text stream;
1803 # however, formatting controls that are generated internally/locally in the
1804 # kernel-doc script are not escaped here; instead, they begin life like
1805 # $blankline_html (4 of '\' followed by a mnemonic + ':'), then these strings
1806 # are converted to their mnemonic-expected output, without the 4 * '\' & ':',
1807 # just before actual output; (this is done by local_unescape())
1810 if (($output_mode eq "text") || ($output_mode eq "man")) {
1813 $text =~ s/\&/\\\\\\amp;/g;
1814 $text =~ s/\</\\\\\\lt;/g;
1815 $text =~ s/\>/\\\\\\gt;/g;
1819 # convert local escape strings to html
1820 # local escape strings look like: '\\\\menmonic:' (that's 4 backslashes)
1821 sub local_unescape($) {
1823 if (($output_mode eq "text") || ($output_mode eq "man")) {
1826 $text =~ s/\\\\\\\\lt:/</g;
1827 $text =~ s/\\\\\\\\gt:/>/g;
1831 sub process_file($) {
1836 my $initial_section_counter = $section_counter;
1838 if (defined($ENV{'SRCTREE'})) {
1839 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
1844 if (defined($source_map{$file})) {
1845 $file = $source_map{$file};
1848 if (!open(IN,"<$file")) {
1849 print STDERR "Error: Cannot open file $file\n";
1854 $section_counter = 0;
1857 if (/$doc_start/o) {
1858 $state = 1; # next line is always the function name
1861 } elsif ($state == 1) { # this line is the function name (always)
1862 if (/$doc_block/o) {
1866 $section = $section_intro;
1871 elsif (/$doc_decl/o) {
1873 if (/\s*([\w\s]+?)\s*-/) {
1879 # strip leading/trailing/multiple spaces
1884 $declaration_purpose = xml_escape($descr);
1886 $declaration_purpose = "";
1889 if (($declaration_purpose eq "") && $verbose) {
1890 print STDERR "Warning(${file}:$.): missing initial short description on line:\n";
1895 if ($identifier =~ m/^struct/) {
1896 $decl_type = 'struct';
1897 } elsif ($identifier =~ m/^union/) {
1898 $decl_type = 'union';
1899 } elsif ($identifier =~ m/^enum/) {
1900 $decl_type = 'enum';
1901 } elsif ($identifier =~ m/^typedef/) {
1902 $decl_type = 'typedef';
1904 $decl_type = 'function';
1908 print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
1911 print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
1912 " - I thought it was a doc line\n";
1916 } elsif ($state == 2) { # look for head: lines, and include content
1921 if (($contents ne "") && ($contents ne "\n")) {
1922 if (!$in_doc_sect && $verbose) {
1923 print STDERR "Warning(${file}:$.): contents before sections\n";
1926 dump_section($section, xml_escape($contents));
1927 $section = $section_default;
1931 $contents = $newcontents;
1932 if ($contents ne "") {
1933 while ((substr($contents, 0, 1) eq " ") ||
1934 substr($contents, 0, 1) eq "\t") {
1935 $contents = substr($contents, 1);
1939 $section = $newsection;
1940 } elsif (/$doc_end/) {
1942 if ($contents ne "") {
1943 dump_section($section, xml_escape($contents));
1944 $section = $section_default;
1951 # print STDERR "end of doc comment, looking for prototype\n";
1952 } elsif (/$doc_content/) {
1953 # miguel-style comment kludge, look for blank lines after
1954 # @parameter line to signify start of description
1956 ($section =~ m/^@/ || $section eq $section_context)) {
1957 dump_section($section, xml_escape($contents));
1958 $section = $section_default;
1961 $contents .= $1."\n";
1964 # i dont know - bad line? ignore.
1965 print STDERR "Warning(${file}:$.): bad line: $_";
1968 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
1969 if ($decl_type eq 'function') {
1970 process_state3_function($_, $file);
1972 process_state3_type($_, $file);
1974 } elsif ($state == 4) {
1975 # Documentation block
1977 dump_doc_section($section, xml_escape($contents));
1981 %parameterdescs = ();
1982 %parametertypes = ();
1983 @parameterlist = ();
1988 $section = $section_intro;
1995 dump_doc_section($section, xml_escape($contents));
1999 %parameterdescs = ();
2000 %parametertypes = ();
2001 @parameterlist = ();
2007 elsif (/$doc_content/)
2011 $contents .= $blankline;
2015 $contents .= $1 . "\n";
2020 if ($initial_section_counter == $section_counter) {
2021 print STDERR "Warning(${file}): no structured comments found\n";
2022 if ($output_mode eq "xml") {
2023 # The template wants at least one RefEntry here; make one.
2024 print "<refentry>\n";
2025 print " <refnamediv>\n";
2026 print " <refname>\n";
2028 print " </refname>\n";
2029 print " <refpurpose>\n";
2030 print " Document generation inconsistency\n";
2031 print " </refpurpose>\n";
2032 print " </refnamediv>\n";
2033 print " <refsect1>\n";
2036 print " </title>\n";
2037 print " <warning>\n";
2039 print " The template for this document tried to insert\n";
2040 print " the structured comment from the file\n";
2041 print " <filename>${file}</filename> at this point,\n";
2042 print " but none was found.\n";
2043 print " This dummy section is inserted to allow\n";
2044 print " generation to continue.\n";
2046 print " </warning>\n";
2047 print " </refsect1>\n";
2048 print "</refentry>\n";