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 ##
9 ## #define enhancements by Armin Kuster <akuster@mvista.com> ##
10 ## Copyright (c) 2000 MontaVista Software, Inc. ##
12 ## This software falls under the GNU General Public License. ##
13 ## Please read the COPYING file for more information ##
15 # w.o. 03-11-2000: added the '-filelist' option.
17 # 18/01/2001 - Cleanups
18 # Functions prototyped as foo(void) same as foo()
19 # Stop eval'ing where we don't need to.
22 # 27/06/2001 - Allowed whitespace after initial "/**" and
23 # allowed comments before function declarations.
24 # -- Christian Kreibich <ck@whoop.org>
27 # - add perldoc documentation
28 # - Look more closely at some of the scarier bits :)
30 # 26/05/2001 - Support for separate source and object trees.
32 # Keith Owens <kaos@ocs.com.au>
34 # 23/09/2001 - Added support for typedefs, structs, enums and unions
35 # Support for Context section; can be terminated using empty line
36 # Small fixes (like spaces vs. \s in regex)
37 # -- Tim Jansen <tim@tjansen.de>
41 # This will read a 'c' file and scan for embedded comments in the
42 # style of gnome comments (+minor extensions - see below).
45 # Note: This only supports 'c'.
48 # kernel-doc [ -docbook | -html | -text | -man ]
49 # [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile
51 # [ -nofunction funcname [ -function funcname ...] ] c file(s)s > outputfile
53 # Set output format using one of -docbook -html -text or -man. Default is man.
56 # If set, then only generate documentation for the given function(s). All
57 # other functions are ignored.
59 # -nofunction funcname
60 # If set, then only generate documentation for the other function(s).
61 # Cannot be used together with -function
62 # (yes, that's a bug -- perl hackers can fix it 8))
64 # c files - list of 'c' files to process
66 # All output goes to stdout, with errors to stderr.
70 # In the following table, (...)? signifies optional structure.
71 # (...)* signifies 0 or more structure elements
73 # * function_name(:)? (- short description)?
74 # (* @parameterx: (description of parameter x)?)*
76 # * (Description:)? (Description of function)?
77 # * (section header: (section description)? )*
80 # So .. the trivial example would be:
86 # If the Description: header tag is omitted, then there must be a blank line
87 # after the last parameter specification.
90 # * my_function - does my stuff
91 # * @my_arg: its mine damnit
93 # * Does my stuff explained.
98 # * my_function - does my stuff
99 # * @my_arg: its mine damnit
100 # * Description: Does my stuff explained.
104 # Beside functions you can also write documentation for structs, unions,
105 # enums and typedefs. Instead of the function name you must write the name
106 # of the declaration; the struct/union/enum/typedef must always precede
107 # the name. Nesting of declarations is not supported.
108 # Use the argument mechanism to document members or constants.
111 # * struct my_struct - short description
113 # * @b: second member
115 # * Longer description
124 # All descriptions can be multiline, except the short function description.
126 # You can also add additional sections. When documenting kernel functions you
127 # should document the "Context:" of the function, e.g. whether the functions
128 # can be called form interrupts. Unlike other sections you can end it with an
130 # Example-sections should contain the string EXAMPLE so that they are marked
131 # appropriately in DocBook.
135 # * user_function - function that can only be called in user context
136 # * @a: some argument
137 # * Context: !in_interrupt()
141 # * user_function(22);
146 # All descriptive text is further processed, scanning for the following special
147 # patterns, which are highlighted appropriately.
149 # 'funcname()' - function
150 # '$ENVVAR' - environmental variable
151 # '&struct_name' - name of a structure (up to two words including 'struct')
152 # '@parameter' - name of a parameter
153 # '%CONST' - name of a constant.
158 # match expressions used to find embedded type information
159 my $type_constant = '\%([-_\w]+)';
160 my $type_func = '(\w+)\(\)';
161 my $type_param = '\@(\w+)';
162 my $type_struct = '\&((struct\s*)*[_\w]+)';
163 my $type_struct_xml = '\\\amp;((struct\s*)*[_\w]+)';
164 my $type_env = '(\$\w+)';
166 # Output conversion substitutions.
167 # One for each output format
169 # these work fairly well
170 my %highlights_html = ( $type_constant, "<i>\$1</i>",
171 $type_func, "<b>\$1</b>",
172 $type_struct_xml, "<i>\$1</i>",
173 $type_env, "<b><i>\$1</i></b>",
174 $type_param, "<tt><b>\$1</b></tt>" );
175 my $blankline_html = "<p>";
177 # XML, docbook format
178 my %highlights_xml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
179 $type_constant, "<constant>\$1</constant>",
180 $type_func, "<function>\$1</function>",
181 $type_struct, "<structname>\$1</structname>",
182 $type_env, "<envar>\$1</envar>",
183 $type_param, "<parameter>\$1</parameter>" );
184 my $blankline_xml = "</para><para>\n";
186 # gnome, docbook format
187 my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
188 $type_func, "<function>\$1</function>",
189 $type_struct, "<structname>\$1</structname>",
190 $type_env, "<envar>\$1</envar>",
191 $type_param, "<parameter>\$1</parameter>" );
192 my $blankline_gnome = "</para><para>\n";
194 # these are pretty rough
195 my %highlights_man = ( $type_constant, "\$1",
196 $type_func, "\\\\fB\$1\\\\fP",
197 $type_struct, "\\\\fI\$1\\\\fP",
198 $type_param, "\\\\fI\$1\\\\fP" );
199 my $blankline_man = "";
202 my %highlights_text = ( $type_constant, "\$1",
205 $type_param, "\$1" );
206 my $blankline_text = "";
210 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ]\n";
211 print " [ -function funcname [ -function funcname ...] ]\n";
212 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
213 print " c source file(s) > outputfile\n";
223 my $output_mode = "man";
224 my %highlights = %highlights_man;
225 my $blankline = $blankline_man;
226 my $modulename = "Kernel API";
227 my $function_only = 0;
228 my $man_date = ('January', 'February', 'March', 'April', 'May', 'June',
229 'July', 'August', 'September', 'October',
230 'November', 'December')[(localtime)[4]] .
231 " " . ((localtime)[5]+1900);
233 # Essentially these are globals
234 # They probably want to be tidied up made more localised or summat.
235 # CAVEAT EMPTOR! Some of the others I localised may not want to be which
236 # could cause "use of undefined value" or other bugs.
237 my ($function, %function_table,%parametertypes,$declaration_purpose);
238 my ($type,$declaration_name,$return_type);
239 my ($newsection,$newcontents,$prototype,$filelist, $brcount, %source_map);
241 # Generated docbook code is inserted in a template at a point where
242 # docbook v3.1 requires a non-zero sequence of RefEntry's; see:
243 # http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
244 # We keep track of number of generated entries and generate a dummy
245 # if needs be to ensure the expanded template can be postprocessed
247 my $section_counter = 0;
253 # 1 - looking for function name
254 # 2 - scanning field start.
255 # 3 - scanning prototype.
256 # 4 - documentation block
260 #declaration types: can be
261 # 'function', 'struct', 'union', 'enum', 'typedef'
264 my $doc_special = "\@\%\$\&";
266 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
268 my $doc_com = '\s*\*\s*';
269 my $doc_decl = $doc_com.'(\w+)';
270 my $doc_sect = $doc_com.'(['.$doc_special.']?[\w\s]+):(.*)';
271 my $doc_content = $doc_com.'(.*)';
272 my $doc_block = $doc_com.'DOC:\s*(.*)?';
281 my $section_default = "Description"; # default section
282 my $section_intro = "Introduction";
283 my $section = $section_default;
284 my $section_context = "Context";
286 my $undescribed = "-- undescribed --";
290 while ($ARGV[0] =~ m/^-(.*)/) {
291 my $cmd = shift @ARGV;
292 if ($cmd eq "-html") {
293 $output_mode = "html";
294 %highlights = %highlights_html;
295 $blankline = $blankline_html;
296 } elsif ($cmd eq "-man") {
297 $output_mode = "man";
298 %highlights = %highlights_man;
299 $blankline = $blankline_man;
300 } elsif ($cmd eq "-text") {
301 $output_mode = "text";
302 %highlights = %highlights_text;
303 $blankline = $blankline_text;
304 } elsif ($cmd eq "-docbook") {
305 $output_mode = "xml";
306 %highlights = %highlights_xml;
307 $blankline = $blankline_xml;
308 } elsif ($cmd eq "-gnome") {
309 $output_mode = "gnome";
310 %highlights = %highlights_gnome;
311 $blankline = $blankline_gnome;
312 } elsif ($cmd eq "-module") { # not needed for XML, inherits from calling document
313 $modulename = shift @ARGV;
314 } elsif ($cmd eq "-function") { # to only output specific functions
316 $function = shift @ARGV;
317 $function_table{$function} = 1;
318 } elsif ($cmd eq "-nofunction") { # to only output specific functions
320 $function = shift @ARGV;
321 $function_table{$function} = 1;
322 } elsif ($cmd eq "-v") {
324 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
326 } elsif ($cmd eq '-filelist') {
327 $filelist = shift @ARGV;
331 # get kernel version from env
332 sub get_kernel_version
() {
335 if (defined($ENV{'KERNELVERSION'})) {
336 $version = $ENV{'KERNELVERSION'};
340 my $kernelversion = get_kernel_version
();
342 # generate a sequence of code that will splice in highlighting information
343 # using the s// operator.
344 my $dohighlight = "";
345 foreach my $pattern (keys %highlights) {
346 # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
347 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
351 # dumps section contents to arrays/hashes intended for that purpose.
355 my $contents = join "\n", @_;
357 if ($name =~ m/$type_constant/) {
359 # print STDERR "constant section '$1' = '$contents'\n";
360 $constants{$name} = $contents;
361 } elsif ($name =~ m/$type_param/) {
362 # print STDERR "parameter def '$1' = '$contents'\n";
364 $parameterdescs{$name} = $contents;
366 # print STDERR "other section '$name' = '$contents'\n";
367 $sections{$name} = $contents;
368 push @sectionlist, $name;
375 # parameterdescs, a hash.
376 # function => "function name"
377 # parameterlist => @list of parameters
378 # parameterdescs => %parameter descriptions
379 # sectionlist => @list of sections
380 # sections => %section descriptions
383 sub output_highlight
{
384 my $contents = join "\n",@_;
388 # if (!defined $contents) {
390 # confess "output_highlight got called with no args?\n";
393 # print STDERR "contents b4:$contents\n";
396 if ($output_mode eq "html") {
397 $contents =~ s/\\\\//;
399 # print STDERR "contents af:$contents\n";
401 foreach $line (split "\n", $contents) {
403 print $lineprefix, $blankline;
405 $line =~ s/\\\\\\/\&/g;
406 print $lineprefix, $line;
412 #output sections in html
413 sub output_section_html
(%) {
417 foreach $section (@
{$args{'sectionlist'}}) {
418 print "<h3>$section</h3>\n";
419 print "<blockquote>\n";
420 output_highlight
($args{'sections'}{$section});
421 print "</blockquote>\n";
425 # output enum in html
426 sub output_enum_html
(%) {
430 print "<h2>enum ".$args{'enum'}."</h2>\n";
432 print "<b>enum ".$args{'enum'}."</b> {<br>\n";
434 foreach $parameter (@
{$args{'parameterlist'}}) {
435 print " <b>".$parameter."</b>";
436 if ($count != $#{$args{'parameterlist'}}) {
444 print "<h3>Constants</h3>\n";
446 foreach $parameter (@
{$args{'parameterlist'}}) {
447 print "<dt><b>".$parameter."</b>\n";
449 output_highlight
($args{'parameterdescs'}{$parameter});
452 output_section_html
(@_);
456 # output typedef in html
457 sub output_typedef_html
(%) {
461 print "<h2>typedef ".$args{'typedef'}."</h2>\n";
463 print "<b>typedef ".$args{'typedef'}."</b>\n";
464 output_section_html
(@_);
468 # output struct in html
469 sub output_struct_html
(%) {
473 print "<h2>".$args{'type'}." ".$args{'struct'}. " - " .$args{'purpose'}."</h2>\n";
474 print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n";
475 foreach $parameter (@
{$args{'parameterlist'}}) {
476 if ($parameter =~ /^#/) {
477 print "$parameter<br>\n";
480 my $parameter_name = $parameter;
481 $parameter_name =~ s/\[.*//;
483 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
484 $type = $args{'parametertypes'}{$parameter};
485 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
486 # pointer-to-function
487 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
488 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
490 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
492 print " <i>$type</i> <b>$parameter</b>;<br>\n";
497 print "<h3>Members</h3>\n";
499 foreach $parameter (@
{$args{'parameterlist'}}) {
500 ($parameter =~ /^#/) && next;
502 my $parameter_name = $parameter;
503 $parameter_name =~ s/\[.*//;
505 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
506 print "<dt><b>".$parameter."</b>\n";
508 output_highlight
($args{'parameterdescs'}{$parameter_name});
511 output_section_html
(@_);
515 # output function in html
516 sub output_function_html
(%) {
518 my ($parameter, $section);
521 print "<h2>" .$args{'function'}." - ".$args{'purpose'}."</h2>\n";
522 print "<i>".$args{'functiontype'}."</i>\n";
523 print "<b>".$args{'function'}."</b>\n";
526 foreach $parameter (@
{$args{'parameterlist'}}) {
527 $type = $args{'parametertypes'}{$parameter};
528 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
529 # pointer-to-function
530 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
532 print "<i>".$type."</i> <b>".$parameter."</b>";
534 if ($count != $#{$args{'parameterlist'}}) {
541 print "<h3>Arguments</h3>\n";
543 foreach $parameter (@
{$args{'parameterlist'}}) {
544 my $parameter_name = $parameter;
545 $parameter_name =~ s/\[.*//;
547 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
548 print "<dt><b>".$parameter."</b>\n";
550 output_highlight
($args{'parameterdescs'}{$parameter_name});
553 output_section_html
(@_);
557 # output intro in html
558 sub output_intro_html
(%) {
560 my ($parameter, $section);
563 foreach $section (@
{$args{'sectionlist'}}) {
564 print "<h3>$section</h3>\n";
566 output_highlight
($args{'sections'}{$section});
572 sub output_section_xml
(%) {
575 # print out each section
577 foreach $section (@
{$args{'sectionlist'}}) {
578 print "<refsect1>\n";
579 print "<title>$section</title>\n";
580 if ($section =~ m/EXAMPLE/i) {
581 print "<informalexample><programlisting>\n";
585 output_highlight
($args{'sections'}{$section});
586 if ($section =~ m/EXAMPLE/i) {
587 print "</programlisting></informalexample>\n";
591 print "</refsect1>\n";
595 # output function in XML DocBook
596 sub output_function_xml
(%) {
598 my ($parameter, $section);
602 $id = "API-".$args{'function'};
603 $id =~ s/[^A-Za-z0-9]/-/g;
605 print "<refentry id=\"$id\">\n";
606 print "<refentryinfo>\n";
607 print " <title>LINUX</title>\n";
608 print " <productname>Kernel Hackers Manual</productname>\n";
609 print " <date>$man_date</date>\n";
610 print "</refentryinfo>\n";
612 print " <refentrytitle><phrase>".$args{'function'}."</phrase></refentrytitle>\n";
613 print " <manvolnum>9</manvolnum>\n";
614 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
615 print "</refmeta>\n";
616 print "<refnamediv>\n";
617 print " <refname>".$args{'function'}."</refname>\n";
618 print " <refpurpose>\n";
620 output_highlight
($args{'purpose'});
621 print " </refpurpose>\n";
622 print "</refnamediv>\n";
624 print "<refsynopsisdiv>\n";
625 print " <title>Synopsis</title>\n";
626 print " <funcsynopsis><funcprototype>\n";
627 print " <funcdef>".$args{'functiontype'}." ";
628 print "<function>".$args{'function'}." </function></funcdef>\n";
631 if ($#{$args{'parameterlist'}} >= 0) {
632 foreach $parameter (@
{$args{'parameterlist'}}) {
633 $type = $args{'parametertypes'}{$parameter};
634 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
635 # pointer-to-function
636 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
637 print " <funcparams>$2</funcparams></paramdef>\n";
639 print " <paramdef>".$type;
640 print " <parameter>$parameter</parameter></paramdef>\n";
646 print " </funcprototype></funcsynopsis>\n";
647 print "</refsynopsisdiv>\n";
650 print "<refsect1>\n <title>Arguments</title>\n";
651 if ($#{$args{'parameterlist'}} >= 0) {
652 print " <variablelist>\n";
653 foreach $parameter (@
{$args{'parameterlist'}}) {
654 my $parameter_name = $parameter;
655 $parameter_name =~ s/\[.*//;
657 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
658 print " <listitem>\n <para>\n";
660 output_highlight
($args{'parameterdescs'}{$parameter_name});
661 print " </para>\n </listitem>\n </varlistentry>\n";
663 print " </variablelist>\n";
665 print " <para>\n None\n </para>\n";
667 print "</refsect1>\n";
669 output_section_xml
(@_);
670 print "</refentry>\n\n";
673 # output struct in XML DocBook
674 sub output_struct_xml
(%) {
676 my ($parameter, $section);
679 $id = "API-struct-".$args{'struct'};
680 $id =~ s/[^A-Za-z0-9]/-/g;
682 print "<refentry id=\"$id\">\n";
683 print "<refentryinfo>\n";
684 print " <title>LINUX</title>\n";
685 print " <productname>Kernel Hackers Manual</productname>\n";
686 print " <date>$man_date</date>\n";
687 print "</refentryinfo>\n";
689 print " <refentrytitle><phrase>".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n";
690 print " <manvolnum>9</manvolnum>\n";
691 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
692 print "</refmeta>\n";
693 print "<refnamediv>\n";
694 print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n";
695 print " <refpurpose>\n";
697 output_highlight
($args{'purpose'});
698 print " </refpurpose>\n";
699 print "</refnamediv>\n";
701 print "<refsynopsisdiv>\n";
702 print " <title>Synopsis</title>\n";
703 print " <programlisting>\n";
704 print $args{'type'}." ".$args{'struct'}." {\n";
705 foreach $parameter (@
{$args{'parameterlist'}}) {
706 if ($parameter =~ /^#/) {
707 print "$parameter\n";
711 my $parameter_name = $parameter;
712 $parameter_name =~ s/\[.*//;
714 defined($args{'parameterdescs'}{$parameter_name}) || next;
715 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
716 $type = $args{'parametertypes'}{$parameter};
717 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
718 # pointer-to-function
719 print " $1 $parameter) ($2);\n";
720 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
721 print " $1 $parameter$2;\n";
723 print " ".$type." ".$parameter.";\n";
727 print " </programlisting>\n";
728 print "</refsynopsisdiv>\n";
730 print " <refsect1>\n";
731 print " <title>Members</title>\n";
733 print " <variablelist>\n";
734 foreach $parameter (@
{$args{'parameterlist'}}) {
735 ($parameter =~ /^#/) && next;
737 my $parameter_name = $parameter;
738 $parameter_name =~ s/\[.*//;
740 defined($args{'parameterdescs'}{$parameter_name}) || next;
741 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
742 print " <varlistentry>";
743 print " <term>$parameter</term>\n";
744 print " <listitem><para>\n";
745 output_highlight
($args{'parameterdescs'}{$parameter_name});
746 print " </para></listitem>\n";
747 print " </varlistentry>\n";
749 print " </variablelist>\n";
750 print " </refsect1>\n";
752 output_section_xml
(@_);
754 print "</refentry>\n\n";
757 # output enum in XML DocBook
758 sub output_enum_xml
(%) {
760 my ($parameter, $section);
764 $id = "API-enum-".$args{'enum'};
765 $id =~ s/[^A-Za-z0-9]/-/g;
767 print "<refentry id=\"$id\">\n";
768 print "<refentryinfo>\n";
769 print " <title>LINUX</title>\n";
770 print " <productname>Kernel Hackers Manual</productname>\n";
771 print " <date>$man_date</date>\n";
772 print "</refentryinfo>\n";
774 print " <refentrytitle><phrase>enum ".$args{'enum'}."</phrase></refentrytitle>\n";
775 print " <manvolnum>9</manvolnum>\n";
776 print " <refmiscinfo class=\"version\">" . $kernelversion . "</refmiscinfo>\n";
777 print "</refmeta>\n";
778 print "<refnamediv>\n";
779 print " <refname>enum ".$args{'enum'}."</refname>\n";
780 print " <refpurpose>\n";
782 output_highlight
($args{'purpose'});
783 print " </refpurpose>\n";
784 print "</refnamediv>\n";
786 print "<refsynopsisdiv>\n";
787 print " <title>Synopsis</title>\n";
788 print " <programlisting>\n";
789 print "enum ".$args{'enum'}." {\n";
791 foreach $parameter (@
{$args{'parameterlist'}}) {
793 if ($count != $#{$args{'parameterlist'}}) {
800 print " </programlisting>\n";
801 print "</refsynopsisdiv>\n";
803 print "<refsect1>\n";
804 print " <title>Constants</title>\n";
805 print " <variablelist>\n";
806 foreach $parameter (@
{$args{'parameterlist'}}) {
807 my $parameter_name = $parameter;
808 $parameter_name =~ s/\[.*//;
810 print " <varlistentry>";
811 print " <term>$parameter</term>\n";
812 print " <listitem><para>\n";
813 output_highlight
($args{'parameterdescs'}{$parameter_name});
814 print " </para></listitem>\n";
815 print " </varlistentry>\n";
817 print " </variablelist>\n";
818 print "</refsect1>\n";
820 output_section_xml
(@_);
822 print "</refentry>\n\n";
825 # output typedef in XML DocBook
826 sub output_typedef_xml
(%) {
828 my ($parameter, $section);
831 $id = "API-typedef-".$args{'typedef'};
832 $id =~ s/[^A-Za-z0-9]/-/g;
834 print "<refentry id=\"$id\">\n";
835 print "<refentryinfo>\n";
836 print " <title>LINUX</title>\n";
837 print " <productname>Kernel Hackers Manual</productname>\n";
838 print " <date>$man_date</date>\n";
839 print "</refentryinfo>\n";
841 print " <refentrytitle><phrase>typedef ".$args{'typedef'}."</phrase></refentrytitle>\n";
842 print " <manvolnum>9</manvolnum>\n";
843 print "</refmeta>\n";
844 print "<refnamediv>\n";
845 print " <refname>typedef ".$args{'typedef'}."</refname>\n";
846 print " <refpurpose>\n";
848 output_highlight
($args{'purpose'});
849 print " </refpurpose>\n";
850 print "</refnamediv>\n";
852 print "<refsynopsisdiv>\n";
853 print " <title>Synopsis</title>\n";
854 print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n";
855 print "</refsynopsisdiv>\n";
857 output_section_xml
(@_);
859 print "</refentry>\n\n";
862 # output in XML DocBook
863 sub output_intro_xml
(%) {
865 my ($parameter, $section);
868 my $id = $args{'module'};
869 $id =~ s/[^A-Za-z0-9]/-/g;
871 # print out each section
873 foreach $section (@
{$args{'sectionlist'}}) {
874 print "<refsect1>\n <title>$section</title>\n <para>\n";
875 if ($section =~ m/EXAMPLE/i) {
876 print "<example><para>\n";
878 output_highlight
($args{'sections'}{$section});
879 if ($section =~ m/EXAMPLE/i) {
880 print "</para></example>\n";
882 print " </para>\n</refsect1>\n";
888 # output in XML DocBook
889 sub output_function_gnome
{
891 my ($parameter, $section);
895 $id = $args{'module'}."-".$args{'function'};
896 $id =~ s/[^A-Za-z0-9]/-/g;
899 print " <title id=\"$id\">".$args{'function'}."</title>\n";
901 print " <funcsynopsis>\n";
902 print " <funcdef>".$args{'functiontype'}." ";
903 print "<function>".$args{'function'}." ";
904 print "</function></funcdef>\n";
907 if ($#{$args{'parameterlist'}} >= 0) {
908 foreach $parameter (@
{$args{'parameterlist'}}) {
909 $type = $args{'parametertypes'}{$parameter};
910 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
911 # pointer-to-function
912 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
913 print " <funcparams>$2</funcparams></paramdef>\n";
915 print " <paramdef>".$type;
916 print " <parameter>$parameter</parameter></paramdef>\n";
922 print " </funcsynopsis>\n";
923 if ($#{$args{'parameterlist'}} >= 0) {
924 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
925 print "<tgroup cols=\"2\">\n";
926 print "<colspec colwidth=\"2*\">\n";
927 print "<colspec colwidth=\"8*\">\n";
929 foreach $parameter (@
{$args{'parameterlist'}}) {
930 my $parameter_name = $parameter;
931 $parameter_name =~ s/\[.*//;
933 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
936 output_highlight
($args{'parameterdescs'}{$parameter_name});
937 print " </entry></row>\n";
939 print " </tbody></tgroup></informaltable>\n";
941 print " <para>\n None\n </para>\n";
944 # print out each section
946 foreach $section (@
{$args{'sectionlist'}}) {
947 print "<simplesect>\n <title>$section</title>\n";
948 if ($section =~ m/EXAMPLE/i) {
949 print "<example><programlisting>\n";
953 output_highlight
($args{'sections'}{$section});
955 if ($section =~ m/EXAMPLE/i) {
956 print "</programlisting></example>\n";
959 print " </simplesect>\n";
962 print "</sect2>\n\n";
966 # output function in man
967 sub output_function_man
(%) {
969 my ($parameter, $section);
972 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
975 print $args{'function'}." \\- ".$args{'purpose'}."\n";
977 print ".SH SYNOPSIS\n";
978 if ($args{'functiontype'} ne "") {
979 print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n";
981 print ".B \"".$args{'function'}."\n";
986 foreach my $parameter (@
{$args{'parameterlist'}}) {
987 if ($count == $#{$args{'parameterlist'}}) {
990 $type = $args{'parametertypes'}{$parameter};
991 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
992 # pointer-to-function
993 print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n";
995 $type =~ s/([^\*])$/$1 /;
996 print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n";
1002 print ".SH ARGUMENTS\n";
1003 foreach $parameter (@
{$args{'parameterlist'}}) {
1004 my $parameter_name = $parameter;
1005 $parameter_name =~ s/\[.*//;
1007 print ".IP \"".$parameter."\" 12\n";
1008 output_highlight
($args{'parameterdescs'}{$parameter_name});
1010 foreach $section (@
{$args{'sectionlist'}}) {
1011 print ".SH \"", uc $section, "\"\n";
1012 output_highlight
($args{'sections'}{$section});
1017 # output enum in man
1018 sub output_enum_man
(%) {
1019 my %args = %{$_[0]};
1020 my ($parameter, $section);
1023 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1026 print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n";
1028 print ".SH SYNOPSIS\n";
1029 print "enum ".$args{'enum'}." {\n";
1031 foreach my $parameter (@
{$args{'parameterlist'}}) {
1032 print ".br\n.BI \" $parameter\"\n";
1033 if ($count == $#{$args{'parameterlist'}}) {
1043 print ".SH Constants\n";
1044 foreach $parameter (@
{$args{'parameterlist'}}) {
1045 my $parameter_name = $parameter;
1046 $parameter_name =~ s/\[.*//;
1048 print ".IP \"".$parameter."\" 12\n";
1049 output_highlight
($args{'parameterdescs'}{$parameter_name});
1051 foreach $section (@
{$args{'sectionlist'}}) {
1052 print ".SH \"$section\"\n";
1053 output_highlight
($args{'sections'}{$section});
1058 # output struct in man
1059 sub output_struct_man
(%) {
1060 my %args = %{$_[0]};
1061 my ($parameter, $section);
1063 print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n";
1066 print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n";
1068 print ".SH SYNOPSIS\n";
1069 print $args{'type'}." ".$args{'struct'}." {\n.br\n";
1071 foreach my $parameter (@
{$args{'parameterlist'}}) {
1072 if ($parameter =~ /^#/) {
1073 print ".BI \"$parameter\"\n.br\n";
1076 my $parameter_name = $parameter;
1077 $parameter_name =~ s/\[.*//;
1079 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1080 $type = $args{'parametertypes'}{$parameter};
1081 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1082 # pointer-to-function
1083 print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n";
1084 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1086 print ".BI \" ".$1."\ \" ".$parameter.$2." \""."\"\n;\n";
1088 $type =~ s/([^\*])$/$1 /;
1089 print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n";
1095 print ".SH Members\n";
1096 foreach $parameter (@
{$args{'parameterlist'}}) {
1097 ($parameter =~ /^#/) && next;
1099 my $parameter_name = $parameter;
1100 $parameter_name =~ s/\[.*//;
1102 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1103 print ".IP \"".$parameter."\" 12\n";
1104 output_highlight
($args{'parameterdescs'}{$parameter_name});
1106 foreach $section (@
{$args{'sectionlist'}}) {
1107 print ".SH \"$section\"\n";
1108 output_highlight
($args{'sections'}{$section});
1113 # output typedef in man
1114 sub output_typedef_man
(%) {
1115 my %args = %{$_[0]};
1116 my ($parameter, $section);
1118 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1121 print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n";
1123 foreach $section (@
{$args{'sectionlist'}}) {
1124 print ".SH \"$section\"\n";
1125 output_highlight
($args{'sections'}{$section});
1129 sub output_intro_man
(%) {
1130 my %args = %{$_[0]};
1131 my ($parameter, $section);
1134 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1136 foreach $section (@
{$args{'sectionlist'}}) {
1137 print ".SH \"$section\"\n";
1138 output_highlight
($args{'sections'}{$section});
1144 sub output_function_text
(%) {
1145 my %args = %{$_[0]};
1146 my ($parameter, $section);
1150 print $args{'function'}." - ".$args{'purpose'}."\n";
1152 print "\nSynopsis:\n\n";
1153 if ($args{'functiontype'} ne "") {
1154 $start = $args{'functiontype'}." ".$args{'function'}." (";
1156 $start = $args{'function'}." (";
1161 foreach my $parameter (@
{$args{'parameterlist'}}) {
1162 $type = $args{'parametertypes'}{$parameter};
1163 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1164 # pointer-to-function
1165 print $1.$parameter.") (".$2;
1167 print $type." ".$parameter;
1169 if ($count != $#{$args{'parameterlist'}}) {
1172 print " " x
length($start);
1178 print "Arguments:\n\n";
1179 foreach $parameter (@
{$args{'parameterlist'}}) {
1180 my $parameter_name = $parameter;
1181 $parameter_name =~ s/\[.*//;
1183 print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n";
1185 output_section_text
(@_);
1188 #output sections in text
1189 sub output_section_text
(%) {
1190 my %args = %{$_[0]};
1194 foreach $section (@
{$args{'sectionlist'}}) {
1195 print "$section:\n\n";
1196 output_highlight
($args{'sections'}{$section});
1201 # output enum in text
1202 sub output_enum_text
(%) {
1203 my %args = %{$_[0]};
1208 print "enum ".$args{'enum'}." - ".$args{'purpose'}."\n\n";
1209 print "enum ".$args{'enum'}." {\n";
1211 foreach $parameter (@
{$args{'parameterlist'}}) {
1212 print "\t$parameter";
1213 if ($count != $#{$args{'parameterlist'}}) {
1221 print "Constants:\n\n";
1222 foreach $parameter (@
{$args{'parameterlist'}}) {
1223 print "$parameter\n\t";
1224 print $args{'parameterdescs'}{$parameter}."\n";
1227 output_section_text
(@_);
1230 # output typedef in text
1231 sub output_typedef_text
(%) {
1232 my %args = %{$_[0]};
1235 print "Typedef:\n\n";
1237 print "typedef ".$args{'typedef'}." - ".$args{'purpose'}."\n";
1238 output_section_text
(@_);
1241 # output struct as text
1242 sub output_struct_text
(%) {
1243 my %args = %{$_[0]};
1246 print $args{'type'}." ".$args{'struct'}." - ".$args{'purpose'}."\n\n";
1247 print $args{'type'}." ".$args{'struct'}." {\n";
1248 foreach $parameter (@
{$args{'parameterlist'}}) {
1249 if ($parameter =~ /^#/) {
1250 print "$parameter\n";
1254 my $parameter_name = $parameter;
1255 $parameter_name =~ s/\[.*//;
1257 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1258 $type = $args{'parametertypes'}{$parameter};
1259 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1260 # pointer-to-function
1261 print "\t$1 $parameter) ($2);\n";
1262 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1263 print "\t$1 $parameter$2;\n";
1265 print "\t".$type." ".$parameter.";\n";
1270 print "Members:\n\n";
1271 foreach $parameter (@
{$args{'parameterlist'}}) {
1272 ($parameter =~ /^#/) && next;
1274 my $parameter_name = $parameter;
1275 $parameter_name =~ s/\[.*//;
1277 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1278 print "$parameter\n\t";
1279 print $args{'parameterdescs'}{$parameter_name}."\n";
1282 output_section_text
(@_);
1285 sub output_intro_text
(%) {
1286 my %args = %{$_[0]};
1287 my ($parameter, $section);
1289 foreach $section (@
{$args{'sectionlist'}}) {
1290 print " $section:\n";
1292 output_highlight
($args{'sections'}{$section});
1297 # generic output function for all types (function, struct/union, typedef, enum);
1298 # calls the generated, variable output_ function name based on
1299 # functype and output_mode
1300 sub output_declaration
{
1303 my $functype = shift;
1304 my $func = "output_${functype}_$output_mode";
1305 if (($function_only==0) ||
1306 ( $function_only == 1 && defined($function_table{$name})) ||
1307 ( $function_only == 2 && !defined($function_table{$name})))
1315 # generic output function - calls the right one based on current output mode.
1318 my $func = "output_intro_".$output_mode;
1324 # takes a declaration (struct, union, enum, typedef) and
1325 # invokes the right handler. NOT called for functions.
1326 sub dump_declaration
($$) {
1328 my ($prototype, $file) = @_;
1329 my $func = "dump_".$decl_type;
1333 sub dump_union
($$) {
1337 sub dump_struct
($$) {
1341 if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
1342 $declaration_name = $2;
1345 # ignore embedded structs or unions
1346 $members =~ s/{.*?}//g;
1348 # ignore members marked private:
1349 $members =~ s/\/\*.*?private:.*?public:.*?\*\///gos;
1350 $members =~ s/\/\*.*?private:.*//gos
;
1352 $members =~ s/\/\*.*?\*\///gos;
1354 create_parameterlist
($members, ';', $file);
1356 output_declaration
($declaration_name,
1358 {'struct' => $declaration_name,
1359 'module' => $modulename,
1360 'parameterlist' => \
@parameterlist,
1361 'parameterdescs' => \
%parameterdescs,
1362 'parametertypes' => \
%parametertypes,
1363 'sectionlist' => \
@sectionlist,
1364 'sections' => \
%sections,
1365 'purpose' => $declaration_purpose,
1366 'type' => $decl_type
1370 print STDERR
"Error(${file}:$.): Cannot parse struct or union!\n";
1379 $x =~ s@
/\*.*?\*/@
@gos; # strip comments.
1380 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1381 $declaration_name = $1;
1384 foreach my $arg (split ',', $members) {
1385 $arg =~ s/^\s*(\w+).*/$1/;
1386 push @parameterlist, $arg;
1387 if (!$parameterdescs{$arg}) {
1388 $parameterdescs{$arg} = $undescribed;
1389 print STDERR
"Warning(${file}:$.): Enum value '$arg' ".
1390 "not described in enum '$declaration_name'\n";
1395 output_declaration
($declaration_name,
1397 {'enum' => $declaration_name,
1398 'module' => $modulename,
1399 'parameterlist' => \
@parameterlist,
1400 'parameterdescs' => \
%parameterdescs,
1401 'sectionlist' => \
@sectionlist,
1402 'sections' => \
%sections,
1403 'purpose' => $declaration_purpose
1407 print STDERR
"Error(${file}:$.): Cannot parse enum!\n";
1412 sub dump_typedef
($$) {
1416 $x =~ s@
/\*.*?\*/@
@gos; # strip comments.
1417 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1418 $x =~ s/\(*.\)\s*;$/;/;
1419 $x =~ s/\[*.\]\s*;$/;/;
1422 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1423 $declaration_name = $1;
1425 output_declaration
($declaration_name,
1427 {'typedef' => $declaration_name,
1428 'module' => $modulename,
1429 'sectionlist' => \
@sectionlist,
1430 'sections' => \
%sections,
1431 'purpose' => $declaration_purpose
1435 print STDERR
"Error(${file}:$.): Cannot parse typedef!\n";
1440 sub create_parameterlist
($$$) {
1442 my $splitter = shift;
1447 # temporarily replace commas inside function pointer definition
1448 while ($args =~ /(\([^\),]+),/) {
1449 $args =~ s/(\([^\),]+),/$1#/g;
1452 foreach my $arg (split($splitter, $args)) {
1454 $arg =~ s/\/\*.*\*\///;
1455 # strip leading/trailing spaces
1461 # Treat preprocessor directive as a typeless variable just to fill
1462 # corresponding data structures "correctly". Catch it later in
1464 push_parameter
($arg, "", $file);
1465 } elsif ($arg =~ m/\(.*\*/) {
1466 # pointer-to-function
1468 $arg =~ m/[^\(]+\(\*\s*([^\)]+)\)/;
1471 $type =~ s/([^\(]+\(\*)$param/$1/;
1472 push_parameter
($param, $type, $file);
1474 $arg =~ s/\s*:\s*/:/g;
1475 $arg =~ s/\s*\[/\[/g;
1477 my @args = split('\s*,\s*', $arg);
1478 if ($args[0] =~ m/\*/) {
1479 $args[0] =~ s/(\*+)\s*/ $1/;
1483 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1485 push(@first_arg, split('\s+', $1));
1486 push(@first_arg, $2);
1488 @first_arg = split('\s+', shift @args);
1491 unshift(@args, pop @first_arg);
1492 $type = join " ", @first_arg;
1494 foreach $param (@args) {
1495 if ($param =~ m/^(\*+)\s*(.*)/) {
1496 push_parameter
($2, "$type $1", $file);
1498 elsif ($param =~ m/(.*?):(\d+)/) {
1499 push_parameter
($1, "$type:$2", $file)
1502 push_parameter
($param, $type, $file);
1509 sub push_parameter
($$$) {
1515 my $param_name = $param;
1516 $param_name =~ s/\[.*//;
1518 if ($type eq "" && $param =~ /\.\.\.$/)
1521 $parameterdescs{$param} = "variable arguments";
1523 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1527 $parameterdescs{void
} = "no arguments";
1529 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1530 # handle unnamed (anonymous) union or struct:
1533 $param = "{unnamed_" . $param. "}";
1534 $parameterdescs{$param} = "anonymous\n";
1538 # warn if parameter has no description
1539 # (but ignore ones starting with # as these are not parameters
1540 # but inline preprocessor statements);
1541 # also ignore unnamed structs/unions;
1543 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1545 $parameterdescs{$param_name} = $undescribed;
1547 if (($type eq 'function') || ($type eq 'enum')) {
1548 print STDERR
"Warning(${file}:$.): Function parameter ".
1549 "or member '$param' not " .
1550 "described in '$declaration_name'\n";
1552 print STDERR
"Warning(${file}:$.):".
1553 " No description found for parameter '$param'\n";
1558 push @parameterlist, $param;
1559 $parametertypes{$param} = $type;
1563 # takes a function prototype and the name of the current file being
1564 # processed and spits out all the details stored in the global
1566 sub dump_function
($$) {
1567 my $prototype = shift;
1570 $prototype =~ s/^static +//;
1571 $prototype =~ s/^extern +//;
1572 $prototype =~ s/^fastcall +//;
1573 $prototype =~ s/^asmlinkage +//;
1574 $prototype =~ s/^inline +//;
1575 $prototype =~ s/^__inline__ +//;
1576 $prototype =~ s/^__inline +//;
1577 $prototype =~ s/^__always_inline +//;
1578 $prototype =~ s/^noinline +//;
1579 $prototype =~ s/__devinit +//;
1580 $prototype =~ s/^#define\s+//; #ak added
1581 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
1583 # Yes, this truly is vile. We are looking for:
1584 # 1. Return type (may be nothing if we're looking at a macro)
1586 # 3. Function parameters.
1588 # All the while we have to watch out for function pointer parameters
1589 # (which IIRC is what the two sections are for), C types (these
1590 # regexps don't even start to express all the possibilities), and
1593 # If you mess with these regexps, it's a good idea to check that
1594 # the following functions' documentation still comes out right:
1595 # - parport_register_device (function pointer parameters)
1596 # - atomic_set (macro)
1597 # - pci_match_device, __copy_to_user (long return type)
1599 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1600 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1601 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1602 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1603 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1604 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1605 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1606 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1607 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1608 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1609 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1610 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1611 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1612 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1613 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1614 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1615 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1617 $declaration_name = $2;
1620 create_parameterlist
($args, ',', $file);
1622 print STDERR
"Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1627 output_declaration
($declaration_name,
1629 {'function' => $declaration_name,
1630 'module' => $modulename,
1631 'functiontype' => $return_type,
1632 'parameterlist' => \
@parameterlist,
1633 'parameterdescs' => \
%parameterdescs,
1634 'parametertypes' => \
%parametertypes,
1635 'sectionlist' => \
@sectionlist,
1636 'sections' => \
%sections,
1637 'purpose' => $declaration_purpose
1641 sub process_file
($);
1643 # Read the file that maps relative names to absolute names for
1644 # separate source and object directories and for shadow trees.
1645 if (open(SOURCE_MAP
, "<.tmp_filelist.txt")) {
1646 my ($relname, $absname);
1647 while(<SOURCE_MAP
>) {
1649 ($relname, $absname) = (split())[0..1];
1650 $relname =~ s
:^/+::;
1651 $source_map{$relname} = $absname;
1657 open(FLIST
,"<$filelist") or die "Can't open file list $filelist";
1668 if ($verbose && $errors) {
1669 print STDERR
"$errors errors\n";
1671 if ($verbose && $warnings) {
1672 print STDERR
"$warnings warnings\n";
1680 %parameterdescs = ();
1681 %parametertypes = ();
1682 @parameterlist = ();
1690 sub process_state3_function
($$) {
1694 if ($x =~ m
#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) {
1697 elsif ($x =~ /([^\{]*)/) {
1700 if (($x =~ /\{/) || ($x =~ /\#define/) || ($x =~ /;/)) {
1701 $prototype =~ s@
/\*.*?\*/@
@gos; # strip comments.
1702 $prototype =~ s@
[\r\n]+@
@gos; # strip newlines/cr's.
1703 $prototype =~ s@
^\s
+@
@gos; # strip leading spaces
1704 dump_function
($prototype,$file);
1709 sub process_state3_type
($$) {
1713 $x =~ s@
[\r\n]+@
@gos; # strip newlines/cr's.
1714 $x =~ s@
^\s
+@
@gos; # strip leading spaces
1715 $x =~ s@\s
+$@
@gos; # strip trailing spaces
1717 # To distinguish preprocessor directive from regular declaration later.
1722 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1723 $prototype .= $1 . $2;
1724 ($2 eq '{') && $brcount++;
1725 ($2 eq '}') && $brcount--;
1726 if (($2 eq ';') && ($brcount == 0)) {
1727 dump_declaration
($prototype,$file);
1739 # replace <, >, and &
1742 if (($output_mode eq "text") || ($output_mode eq "man")) {
1745 $text =~ s/\&/\\\\\\amp;/g;
1746 $text =~ s/\</\\\\\\lt;/g;
1747 $text =~ s/\>/\\\\\\gt;/g;
1751 sub process_file
($) {
1756 my $initial_section_counter = $section_counter;
1758 if (defined($ENV{'SRCTREE'})) {
1759 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
1764 if (defined($source_map{$file})) {
1765 $file = $source_map{$file};
1768 if (!open(IN
,"<$file")) {
1769 print STDERR
"Error: Cannot open file $file\n";
1774 $section_counter = 0;
1777 if (/$doc_start/o) {
1778 $state = 1; # next line is always the function name
1781 } elsif ($state == 1) { # this line is the function name (always)
1782 if (/$doc_block/o) {
1786 $section = $section_intro;
1791 elsif (/$doc_decl/o) {
1793 if (/\s*([\w\s]+?)\s*-/) {
1799 # strip leading/trailing/multiple spaces #RDD:T:
1804 $declaration_purpose = xml_escape
($descr);
1806 $declaration_purpose = "";
1808 if ($identifier =~ m/^struct/) {
1809 $decl_type = 'struct';
1810 } elsif ($identifier =~ m/^union/) {
1811 $decl_type = 'union';
1812 } elsif ($identifier =~ m/^enum/) {
1813 $decl_type = 'enum';
1814 } elsif ($identifier =~ m/^typedef/) {
1815 $decl_type = 'typedef';
1817 $decl_type = 'function';
1821 print STDERR
"Info(${file}:$.): Scanning doc for $identifier\n";
1824 print STDERR
"Warning(${file}:$.): Cannot understand $_ on line $.",
1825 " - I thought it was a doc line\n";
1829 } elsif ($state == 2) { # look for head: lines, and include content
1834 if ($contents ne "") {
1835 if (!$in_doc_sect && $verbose) {
1836 print STDERR
"Warning(${file}:$.): contents before sections\n";
1839 dump_section
($section, xml_escape
($contents));
1840 $section = $section_default;
1844 $contents = $newcontents;
1845 if ($contents ne "") {
1846 while ((substr($contents, 0, 1) eq " ") ||
1847 substr($contents, 0, 1) eq "\t") {
1848 $contents = substr($contents, 1);
1852 $section = $newsection;
1853 } elsif (/$doc_end/) {
1855 if ($contents ne "") {
1856 dump_section
($section, xml_escape
($contents));
1857 $section = $section_default;
1864 # print STDERR "end of doc comment, looking for prototype\n";
1865 } elsif (/$doc_content/) {
1866 # miguel-style comment kludge, look for blank lines after
1867 # @parameter line to signify start of description
1869 ($section =~ m/^@/ || $section eq $section_context)) {
1870 dump_section
($section, xml_escape
($contents));
1871 $section = $section_default;
1874 $contents .= $1."\n";
1877 # i dont know - bad line? ignore.
1878 print STDERR
"Warning(${file}:$.): bad line: $_";
1881 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
1882 if ($decl_type eq 'function') {
1883 process_state3_function
($_, $file);
1885 process_state3_type
($_, $file);
1887 } elsif ($state == 4) {
1888 # Documentation block
1890 dump_section
($section, $contents);
1891 output_intro
({'sectionlist' => \
@sectionlist,
1892 'sections' => \
%sections });
1896 %parameterdescs = ();
1897 %parametertypes = ();
1898 @parameterlist = ();
1903 $section = $section_intro;
1910 dump_section
($section, $contents);
1911 output_intro
({'sectionlist' => \
@sectionlist,
1912 'sections' => \
%sections });
1916 %parameterdescs = ();
1917 %parametertypes = ();
1918 @parameterlist = ();
1924 elsif (/$doc_content/)
1928 $contents .= $blankline;
1932 $contents .= $1 . "\n";
1937 if ($initial_section_counter == $section_counter) {
1938 print STDERR
"Warning(${file}): no structured comments found\n";
1939 if ($output_mode eq "xml") {
1940 # The template wants at least one RefEntry here; make one.
1941 print "<refentry>\n";
1942 print " <refnamediv>\n";
1943 print " <refname>\n";
1945 print " </refname>\n";
1946 print " <refpurpose>\n";
1947 print " Document generation inconsistency\n";
1948 print " </refpurpose>\n";
1949 print " </refnamediv>\n";
1950 print " <refsect1>\n";
1953 print " </title>\n";
1954 print " <warning>\n";
1956 print " The template for this document tried to insert\n";
1957 print " the structured comment from the file\n";
1958 print " <filename>${file}</filename> at this point,\n";
1959 print " but none was found.\n";
1960 print " This dummy section is inserted to allow\n";
1961 print " generation to continue.\n";
1963 print " </warning>\n";
1964 print " </refsect1>\n";
1965 print "</refentry>\n";