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'};
341 # generate a sequence of code that will splice in highlighting information
342 # using the s// operator.
343 my $dohighlight = "";
344 foreach my $pattern (keys %highlights) {
345 # print STDERR "scanning pattern:$pattern, highlight:($highlights{$pattern})\n";
346 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
350 # dumps section contents to arrays/hashes intended for that purpose.
354 my $contents = join "\n", @_;
356 if ($name =~ m/$type_constant/) {
358 # print STDERR "constant section '$1' = '$contents'\n";
359 $constants{$name} = $contents;
360 } elsif ($name =~ m/$type_param/) {
361 # print STDERR "parameter def '$1' = '$contents'\n";
363 $parameterdescs{$name} = $contents;
365 # print STDERR "other section '$name' = '$contents'\n";
366 $sections{$name} = $contents;
367 push @sectionlist, $name;
374 # parameterdescs, a hash.
375 # function => "function name"
376 # parameterlist => @list of parameters
377 # parameterdescs => %parameter descriptions
378 # sectionlist => @list of sections
379 # sections => %section descriptions
382 sub output_highlight {
383 my $contents = join "\n",@_;
387 # if (!defined $contents) {
389 # confess "output_highlight got called with no args?\n";
392 # print STDERR "contents b4:$contents\n";
395 if ($output_mode eq "html") {
396 $contents =~ s/\\\\//;
398 # print STDERR "contents af:$contents\n";
400 foreach $line (split "\n", $contents) {
402 print $lineprefix, $blankline;
404 $line =~ s/\\\\\\/\&/g;
405 print $lineprefix, $line;
411 #output sections in html
412 sub output_section_html(%) {
416 foreach $section (@{$args{'sectionlist'}}) {
417 print "<h3>$section</h3>\n";
418 print "<blockquote>\n";
419 output_highlight($args{'sections'}{$section});
420 print "</blockquote>\n";
424 # output enum in html
425 sub output_enum_html(%) {
429 print "<h2>enum ".$args{'enum'}."</h2>\n";
431 print "<b>enum ".$args{'enum'}."</b> {<br>\n";
433 foreach $parameter (@{$args{'parameterlist'}}) {
434 print " <b>".$parameter."</b>";
435 if ($count != $#{$args{'parameterlist'}}) {
443 print "<h3>Constants</h3>\n";
445 foreach $parameter (@{$args{'parameterlist'}}) {
446 print "<dt><b>".$parameter."</b>\n";
448 output_highlight($args{'parameterdescs'}{$parameter});
451 output_section_html(@_);
455 # output typedef in html
456 sub output_typedef_html(%) {
460 print "<h2>typedef ".$args{'typedef'}."</h2>\n";
462 print "<b>typedef ".$args{'typedef'}."</b>\n";
463 output_section_html(@_);
467 # output struct in html
468 sub output_struct_html(%) {
472 print "<h2>".$args{'type'}." ".$args{'struct'}. " - " .$args{'purpose'}."</h2>\n";
473 print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n";
474 foreach $parameter (@{$args{'parameterlist'}}) {
475 if ($parameter =~ /^#/) {
476 print "$parameter<br>\n";
479 my $parameter_name = $parameter;
480 $parameter_name =~ s/\[.*//;
482 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
483 $type = $args{'parametertypes'}{$parameter};
484 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
485 # pointer-to-function
486 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
487 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
489 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
491 print " <i>$type</i> <b>$parameter</b>;<br>\n";
496 print "<h3>Members</h3>\n";
498 foreach $parameter (@{$args{'parameterlist'}}) {
499 ($parameter =~ /^#/) && next;
501 my $parameter_name = $parameter;
502 $parameter_name =~ s/\[.*//;
504 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
505 print "<dt><b>".$parameter."</b>\n";
507 output_highlight($args{'parameterdescs'}{$parameter_name});
510 output_section_html(@_);
514 # output function in html
515 sub output_function_html(%) {
517 my ($parameter, $section);
520 print "<h2>" .$args{'function'}." - ".$args{'purpose'}."</h2>\n";
521 print "<i>".$args{'functiontype'}."</i>\n";
522 print "<b>".$args{'function'}."</b>\n";
525 foreach $parameter (@{$args{'parameterlist'}}) {
526 $type = $args{'parametertypes'}{$parameter};
527 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
528 # pointer-to-function
529 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
531 print "<i>".$type."</i> <b>".$parameter."</b>";
533 if ($count != $#{$args{'parameterlist'}}) {
540 print "<h3>Arguments</h3>\n";
542 foreach $parameter (@{$args{'parameterlist'}}) {
543 my $parameter_name = $parameter;
544 $parameter_name =~ s/\[.*//;
546 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
547 print "<dt><b>".$parameter."</b>\n";
549 output_highlight($args{'parameterdescs'}{$parameter_name});
552 output_section_html(@_);
556 # output intro in html
557 sub output_intro_html(%) {
559 my ($parameter, $section);
562 foreach $section (@{$args{'sectionlist'}}) {
563 print "<h3>$section</h3>\n";
565 output_highlight($args{'sections'}{$section});
571 sub output_section_xml(%) {
574 # print out each section
576 foreach $section (@{$args{'sectionlist'}}) {
577 print "<refsect1>\n";
578 print "<title>$section</title>\n";
579 if ($section =~ m/EXAMPLE/i) {
580 print "<informalexample><programlisting>\n";
584 output_highlight($args{'sections'}{$section});
585 if ($section =~ m/EXAMPLE/i) {
586 print "</programlisting></informalexample>\n";
590 print "</refsect1>\n";
594 # output function in XML DocBook
595 sub output_function_xml(%) {
597 my ($parameter, $section);
601 $id = "API-".$args{'function'};
602 $id =~ s/[^A-Za-z0-9]/-/g;
604 print "<refentry id=\"$id\">\n";
605 print "<refentryinfo>\n";
606 print " <title>LINUX</title>\n";
607 print " <productname>Kernel Hackers Manual</productname>\n";
608 print " <date>$man_date</date>\n";
609 print "</refentryinfo>\n";
611 print " <refentrytitle><phrase>".$args{'function'}."</phrase></refentrytitle>\n";
612 print " <manvolnum>9</manvolnum>\n";
613 print " <refmiscinfo class=\"version\">" . get_kernel_version() . "</refmiscinfo>\n";
614 print "</refmeta>\n";
615 print "<refnamediv>\n";
616 print " <refname>".$args{'function'}."</refname>\n";
617 print " <refpurpose>\n";
619 output_highlight ($args{'purpose'});
620 print " </refpurpose>\n";
621 print "</refnamediv>\n";
623 print "<refsynopsisdiv>\n";
624 print " <title>Synopsis</title>\n";
625 print " <funcsynopsis><funcprototype>\n";
626 print " <funcdef>".$args{'functiontype'}." ";
627 print "<function>".$args{'function'}." </function></funcdef>\n";
630 if ($#{$args{'parameterlist'}} >= 0) {
631 foreach $parameter (@{$args{'parameterlist'}}) {
632 $type = $args{'parametertypes'}{$parameter};
633 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
634 # pointer-to-function
635 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
636 print " <funcparams>$2</funcparams></paramdef>\n";
638 print " <paramdef>".$type;
639 print " <parameter>$parameter</parameter></paramdef>\n";
645 print " </funcprototype></funcsynopsis>\n";
646 print "</refsynopsisdiv>\n";
649 print "<refsect1>\n <title>Arguments</title>\n";
650 if ($#{$args{'parameterlist'}} >= 0) {
651 print " <variablelist>\n";
652 foreach $parameter (@{$args{'parameterlist'}}) {
653 my $parameter_name = $parameter;
654 $parameter_name =~ s/\[.*//;
656 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
657 print " <listitem>\n <para>\n";
659 output_highlight($args{'parameterdescs'}{$parameter_name});
660 print " </para>\n </listitem>\n </varlistentry>\n";
662 print " </variablelist>\n";
664 print " <para>\n None\n </para>\n";
666 print "</refsect1>\n";
668 output_section_xml(@_);
669 print "</refentry>\n\n";
672 # output struct in XML DocBook
673 sub output_struct_xml(%) {
675 my ($parameter, $section);
678 $id = "API-struct-".$args{'struct'};
679 $id =~ s/[^A-Za-z0-9]/-/g;
681 print "<refentry id=\"$id\">\n";
682 print "<refentryinfo>\n";
683 print " <title>LINUX</title>\n";
684 print " <productname>Kernel Hackers Manual</productname>\n";
685 print " <date>$man_date</date>\n";
686 print "</refentryinfo>\n";
688 print " <refentrytitle><phrase>".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n";
689 print " <manvolnum>9</manvolnum>\n";
690 print " <refmiscinfo class=\"version\">" . get_kernel_version() . "</refmiscinfo>\n";
691 print "</refmeta>\n";
692 print "<refnamediv>\n";
693 print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n";
694 print " <refpurpose>\n";
696 output_highlight ($args{'purpose'});
697 print " </refpurpose>\n";
698 print "</refnamediv>\n";
700 print "<refsynopsisdiv>\n";
701 print " <title>Synopsis</title>\n";
702 print " <programlisting>\n";
703 print $args{'type'}." ".$args{'struct'}." {\n";
704 foreach $parameter (@{$args{'parameterlist'}}) {
705 if ($parameter =~ /^#/) {
706 print "$parameter\n";
710 my $parameter_name = $parameter;
711 $parameter_name =~ s/\[.*//;
713 defined($args{'parameterdescs'}{$parameter_name}) || next;
714 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
715 $type = $args{'parametertypes'}{$parameter};
716 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
717 # pointer-to-function
718 print " $1 $parameter) ($2);\n";
719 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
720 print " $1 $parameter$2;\n";
722 print " ".$type." ".$parameter.";\n";
726 print " </programlisting>\n";
727 print "</refsynopsisdiv>\n";
729 print " <refsect1>\n";
730 print " <title>Members</title>\n";
732 print " <variablelist>\n";
733 foreach $parameter (@{$args{'parameterlist'}}) {
734 ($parameter =~ /^#/) && next;
736 my $parameter_name = $parameter;
737 $parameter_name =~ s/\[.*//;
739 defined($args{'parameterdescs'}{$parameter_name}) || next;
740 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
741 print " <varlistentry>";
742 print " <term>$parameter</term>\n";
743 print " <listitem><para>\n";
744 output_highlight($args{'parameterdescs'}{$parameter_name});
745 print " </para></listitem>\n";
746 print " </varlistentry>\n";
748 print " </variablelist>\n";
749 print " </refsect1>\n";
751 output_section_xml(@_);
753 print "</refentry>\n\n";
756 # output enum in XML DocBook
757 sub output_enum_xml(%) {
759 my ($parameter, $section);
763 $id = "API-enum-".$args{'enum'};
764 $id =~ s/[^A-Za-z0-9]/-/g;
766 print "<refentry id=\"$id\">\n";
767 print "<refentryinfo>\n";
768 print " <title>LINUX</title>\n";
769 print " <productname>Kernel Hackers Manual</productname>\n";
770 print " <date>$man_date</date>\n";
771 print "</refentryinfo>\n";
773 print " <refentrytitle><phrase>enum ".$args{'enum'}."</phrase></refentrytitle>\n";
774 print " <manvolnum>9</manvolnum>\n";
775 print " <refmiscinfo class=\"version\">" . get_kernel_version() . "</refmiscinfo>\n";
776 print "</refmeta>\n";
777 print "<refnamediv>\n";
778 print " <refname>enum ".$args{'enum'}."</refname>\n";
779 print " <refpurpose>\n";
781 output_highlight ($args{'purpose'});
782 print " </refpurpose>\n";
783 print "</refnamediv>\n";
785 print "<refsynopsisdiv>\n";
786 print " <title>Synopsis</title>\n";
787 print " <programlisting>\n";
788 print "enum ".$args{'enum'}." {\n";
790 foreach $parameter (@{$args{'parameterlist'}}) {
792 if ($count != $#{$args{'parameterlist'}}) {
799 print " </programlisting>\n";
800 print "</refsynopsisdiv>\n";
802 print "<refsect1>\n";
803 print " <title>Constants</title>\n";
804 print " <variablelist>\n";
805 foreach $parameter (@{$args{'parameterlist'}}) {
806 my $parameter_name = $parameter;
807 $parameter_name =~ s/\[.*//;
809 print " <varlistentry>";
810 print " <term>$parameter</term>\n";
811 print " <listitem><para>\n";
812 output_highlight($args{'parameterdescs'}{$parameter_name});
813 print " </para></listitem>\n";
814 print " </varlistentry>\n";
816 print " </variablelist>\n";
817 print "</refsect1>\n";
819 output_section_xml(@_);
821 print "</refentry>\n\n";
824 # output typedef in XML DocBook
825 sub output_typedef_xml(%) {
827 my ($parameter, $section);
830 $id = "API-typedef-".$args{'typedef'};
831 $id =~ s/[^A-Za-z0-9]/-/g;
833 print "<refentry id=\"$id\">\n";
834 print "<refentryinfo>\n";
835 print " <title>LINUX</title>\n";
836 print " <productname>Kernel Hackers Manual</productname>\n";
837 print " <date>$man_date</date>\n";
838 print "</refentryinfo>\n";
840 print " <refentrytitle><phrase>typedef ".$args{'typedef'}."</phrase></refentrytitle>\n";
841 print " <manvolnum>9</manvolnum>\n";
842 print "</refmeta>\n";
843 print "<refnamediv>\n";
844 print " <refname>typedef ".$args{'typedef'}."</refname>\n";
845 print " <refpurpose>\n";
847 output_highlight ($args{'purpose'});
848 print " </refpurpose>\n";
849 print "</refnamediv>\n";
851 print "<refsynopsisdiv>\n";
852 print " <title>Synopsis</title>\n";
853 print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n";
854 print "</refsynopsisdiv>\n";
856 output_section_xml(@_);
858 print "</refentry>\n\n";
861 # output in XML DocBook
862 sub output_intro_xml(%) {
864 my ($parameter, $section);
867 my $id = $args{'module'};
868 $id =~ s/[^A-Za-z0-9]/-/g;
870 # print out each section
872 foreach $section (@{$args{'sectionlist'}}) {
873 print "<refsect1>\n <title>$section</title>\n <para>\n";
874 if ($section =~ m/EXAMPLE/i) {
875 print "<example><para>\n";
877 output_highlight($args{'sections'}{$section});
878 if ($section =~ m/EXAMPLE/i) {
879 print "</para></example>\n";
881 print " </para>\n</refsect1>\n";
887 # output in XML DocBook
888 sub output_function_gnome {
890 my ($parameter, $section);
894 $id = $args{'module'}."-".$args{'function'};
895 $id =~ s/[^A-Za-z0-9]/-/g;
898 print " <title id=\"$id\">".$args{'function'}."</title>\n";
900 print " <funcsynopsis>\n";
901 print " <funcdef>".$args{'functiontype'}." ";
902 print "<function>".$args{'function'}." ";
903 print "</function></funcdef>\n";
906 if ($#{$args{'parameterlist'}} >= 0) {
907 foreach $parameter (@{$args{'parameterlist'}}) {
908 $type = $args{'parametertypes'}{$parameter};
909 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
910 # pointer-to-function
911 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
912 print " <funcparams>$2</funcparams></paramdef>\n";
914 print " <paramdef>".$type;
915 print " <parameter>$parameter</parameter></paramdef>\n";
921 print " </funcsynopsis>\n";
922 if ($#{$args{'parameterlist'}} >= 0) {
923 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
924 print "<tgroup cols=\"2\">\n";
925 print "<colspec colwidth=\"2*\">\n";
926 print "<colspec colwidth=\"8*\">\n";
928 foreach $parameter (@{$args{'parameterlist'}}) {
929 my $parameter_name = $parameter;
930 $parameter_name =~ s/\[.*//;
932 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
935 output_highlight($args{'parameterdescs'}{$parameter_name});
936 print " </entry></row>\n";
938 print " </tbody></tgroup></informaltable>\n";
940 print " <para>\n None\n </para>\n";
943 # print out each section
945 foreach $section (@{$args{'sectionlist'}}) {
946 print "<simplesect>\n <title>$section</title>\n";
947 if ($section =~ m/EXAMPLE/i) {
948 print "<example><programlisting>\n";
952 output_highlight($args{'sections'}{$section});
954 if ($section =~ m/EXAMPLE/i) {
955 print "</programlisting></example>\n";
958 print " </simplesect>\n";
961 print "</sect2>\n\n";
965 # output function in man
966 sub output_function_man(%) {
968 my ($parameter, $section);
971 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
974 print $args{'function'}." \\- ".$args{'purpose'}."\n";
976 print ".SH SYNOPSIS\n";
977 if ($args{'functiontype'} ne "") {
978 print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n";
980 print ".B \"".$args{'function'}."\n";
985 foreach my $parameter (@{$args{'parameterlist'}}) {
986 if ($count == $#{$args{'parameterlist'}}) {
989 $type = $args{'parametertypes'}{$parameter};
990 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
991 # pointer-to-function
992 print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n";
994 $type =~ s/([^\*])$/$1 /;
995 print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n";
1001 print ".SH ARGUMENTS\n";
1002 foreach $parameter (@{$args{'parameterlist'}}) {
1003 my $parameter_name = $parameter;
1004 $parameter_name =~ s/\[.*//;
1006 print ".IP \"".$parameter."\" 12\n";
1007 output_highlight($args{'parameterdescs'}{$parameter_name});
1009 foreach $section (@{$args{'sectionlist'}}) {
1010 print ".SH \"", uc $section, "\"\n";
1011 output_highlight($args{'sections'}{$section});
1016 # output enum in man
1017 sub output_enum_man(%) {
1018 my %args = %{$_[0]};
1019 my ($parameter, $section);
1022 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
1025 print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n";
1027 print ".SH SYNOPSIS\n";
1028 print "enum ".$args{'enum'}." {\n";
1030 foreach my $parameter (@{$args{'parameterlist'}}) {
1031 print ".br\n.BI \" $parameter\"\n";
1032 if ($count == $#{$args{'parameterlist'}}) {
1042 print ".SH Constants\n";
1043 foreach $parameter (@{$args{'parameterlist'}}) {
1044 my $parameter_name = $parameter;
1045 $parameter_name =~ s/\[.*//;
1047 print ".IP \"".$parameter."\" 12\n";
1048 output_highlight($args{'parameterdescs'}{$parameter_name});
1050 foreach $section (@{$args{'sectionlist'}}) {
1051 print ".SH \"$section\"\n";
1052 output_highlight($args{'sections'}{$section});
1057 # output struct in man
1058 sub output_struct_man(%) {
1059 my %args = %{$_[0]};
1060 my ($parameter, $section);
1062 print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n";
1065 print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n";
1067 print ".SH SYNOPSIS\n";
1068 print $args{'type'}." ".$args{'struct'}." {\n.br\n";
1070 foreach my $parameter (@{$args{'parameterlist'}}) {
1071 if ($parameter =~ /^#/) {
1072 print ".BI \"$parameter\"\n.br\n";
1075 my $parameter_name = $parameter;
1076 $parameter_name =~ s/\[.*//;
1078 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1079 $type = $args{'parametertypes'}{$parameter};
1080 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1081 # pointer-to-function
1082 print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n";
1083 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1085 print ".BI \" ".$1."\ \" ".$parameter.$2." \""."\"\n;\n";
1087 $type =~ s/([^\*])$/$1 /;
1088 print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n";
1094 print ".SH Members\n";
1095 foreach $parameter (@{$args{'parameterlist'}}) {
1096 ($parameter =~ /^#/) && next;
1098 my $parameter_name = $parameter;
1099 $parameter_name =~ s/\[.*//;
1101 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1102 print ".IP \"".$parameter."\" 12\n";
1103 output_highlight($args{'parameterdescs'}{$parameter_name});
1105 foreach $section (@{$args{'sectionlist'}}) {
1106 print ".SH \"$section\"\n";
1107 output_highlight($args{'sections'}{$section});
1112 # output typedef in man
1113 sub output_typedef_man(%) {
1114 my %args = %{$_[0]};
1115 my ($parameter, $section);
1117 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1120 print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n";
1122 foreach $section (@{$args{'sectionlist'}}) {
1123 print ".SH \"$section\"\n";
1124 output_highlight($args{'sections'}{$section});
1128 sub output_intro_man(%) {
1129 my %args = %{$_[0]};
1130 my ($parameter, $section);
1133 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1135 foreach $section (@{$args{'sectionlist'}}) {
1136 print ".SH \"$section\"\n";
1137 output_highlight($args{'sections'}{$section});
1143 sub output_function_text(%) {
1144 my %args = %{$_[0]};
1145 my ($parameter, $section);
1149 print $args{'function'}." - ".$args{'purpose'}."\n";
1151 print "\nSynopsis:\n\n";
1152 if ($args{'functiontype'} ne "") {
1153 $start = $args{'functiontype'}." ".$args{'function'}." (";
1155 $start = $args{'function'}." (";
1160 foreach my $parameter (@{$args{'parameterlist'}}) {
1161 $type = $args{'parametertypes'}{$parameter};
1162 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1163 # pointer-to-function
1164 print $1.$parameter.") (".$2;
1166 print $type." ".$parameter;
1168 if ($count != $#{$args{'parameterlist'}}) {
1171 print " " x length($start);
1177 print "Arguments:\n\n";
1178 foreach $parameter (@{$args{'parameterlist'}}) {
1179 my $parameter_name = $parameter;
1180 $parameter_name =~ s/\[.*//;
1182 print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n";
1184 output_section_text(@_);
1187 #output sections in text
1188 sub output_section_text(%) {
1189 my %args = %{$_[0]};
1193 foreach $section (@{$args{'sectionlist'}}) {
1194 print "$section:\n\n";
1195 output_highlight($args{'sections'}{$section});
1200 # output enum in text
1201 sub output_enum_text(%) {
1202 my %args = %{$_[0]};
1207 print "enum ".$args{'enum'}." - ".$args{'purpose'}."\n\n";
1208 print "enum ".$args{'enum'}." {\n";
1210 foreach $parameter (@{$args{'parameterlist'}}) {
1211 print "\t$parameter";
1212 if ($count != $#{$args{'parameterlist'}}) {
1220 print "Constants:\n\n";
1221 foreach $parameter (@{$args{'parameterlist'}}) {
1222 print "$parameter\n\t";
1223 print $args{'parameterdescs'}{$parameter}."\n";
1226 output_section_text(@_);
1229 # output typedef in text
1230 sub output_typedef_text(%) {
1231 my %args = %{$_[0]};
1234 print "Typedef:\n\n";
1236 print "typedef ".$args{'typedef'}." - ".$args{'purpose'}."\n";
1237 output_section_text(@_);
1240 # output struct as text
1241 sub output_struct_text(%) {
1242 my %args = %{$_[0]};
1245 print $args{'type'}." ".$args{'struct'}." - ".$args{'purpose'}."\n\n";
1246 print $args{'type'}." ".$args{'struct'}." {\n";
1247 foreach $parameter (@{$args{'parameterlist'}}) {
1248 if ($parameter =~ /^#/) {
1249 print "$parameter\n";
1253 my $parameter_name = $parameter;
1254 $parameter_name =~ s/\[.*//;
1256 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1257 $type = $args{'parametertypes'}{$parameter};
1258 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1259 # pointer-to-function
1260 print "\t$1 $parameter) ($2);\n";
1261 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1262 print "\t$1 $parameter$2;\n";
1264 print "\t".$type." ".$parameter.";\n";
1269 print "Members:\n\n";
1270 foreach $parameter (@{$args{'parameterlist'}}) {
1271 ($parameter =~ /^#/) && next;
1273 my $parameter_name = $parameter;
1274 $parameter_name =~ s/\[.*//;
1276 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1277 print "$parameter\n\t";
1278 print $args{'parameterdescs'}{$parameter_name}."\n";
1281 output_section_text(@_);
1284 sub output_intro_text(%) {
1285 my %args = %{$_[0]};
1286 my ($parameter, $section);
1288 foreach $section (@{$args{'sectionlist'}}) {
1289 print " $section:\n";
1291 output_highlight($args{'sections'}{$section});
1296 # generic output function for all types (function, struct/union, typedef, enum);
1297 # calls the generated, variable output_ function name based on
1298 # functype and output_mode
1299 sub output_declaration {
1302 my $functype = shift;
1303 my $func = "output_${functype}_$output_mode";
1304 if (($function_only==0) ||
1305 ( $function_only == 1 && defined($function_table{$name})) ||
1306 ( $function_only == 2 && !defined($function_table{$name})))
1314 # generic output function - calls the right one based on current output mode.
1317 my $func = "output_intro_".$output_mode;
1323 # takes a declaration (struct, union, enum, typedef) and
1324 # invokes the right handler. NOT called for functions.
1325 sub dump_declaration($$) {
1327 my ($prototype, $file) = @_;
1328 my $func = "dump_".$decl_type;
1332 sub dump_union($$) {
1336 sub dump_struct($$) {
1340 if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
1341 $declaration_name = $2;
1344 # ignore embedded structs or unions
1345 $members =~ s/{.*?}//g;
1347 # ignore members marked private:
1348 $members =~ s/\/\*.*?private:.*?public:.*?\*\///gos;
1349 $members =~ s/\/\*.*?private:.*//gos;
1351 $members =~ s/\/\*.*?\*\///gos;
1353 create_parameterlist($members, ';', $file);
1355 output_declaration($declaration_name,
1357 {'struct' => $declaration_name,
1358 'module' => $modulename,
1359 'parameterlist' => \@parameterlist,
1360 'parameterdescs' => \%parameterdescs,
1361 'parametertypes' => \%parametertypes,
1362 'sectionlist' => \@sectionlist,
1363 'sections' => \%sections,
1364 'purpose' => $declaration_purpose,
1365 'type' => $decl_type
1369 print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
1378 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1379 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1380 $declaration_name = $1;
1383 foreach my $arg (split ',', $members) {
1384 $arg =~ s/^\s*(\w+).*/$1/;
1385 push @parameterlist, $arg;
1386 if (!$parameterdescs{$arg}) {
1387 $parameterdescs{$arg} = $undescribed;
1388 print STDERR "Warning(${file}:$.): Enum value '$arg' ".
1389 "not described in enum '$declaration_name'\n";
1394 output_declaration($declaration_name,
1396 {'enum' => $declaration_name,
1397 'module' => $modulename,
1398 'parameterlist' => \@parameterlist,
1399 'parameterdescs' => \%parameterdescs,
1400 'sectionlist' => \@sectionlist,
1401 'sections' => \%sections,
1402 'purpose' => $declaration_purpose
1406 print STDERR "Error(${file}:$.): Cannot parse enum!\n";
1411 sub dump_typedef($$) {
1415 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1416 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1417 $x =~ s/\(*.\)\s*;$/;/;
1418 $x =~ s/\[*.\]\s*;$/;/;
1421 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1422 $declaration_name = $1;
1424 output_declaration($declaration_name,
1426 {'typedef' => $declaration_name,
1427 'module' => $modulename,
1428 'sectionlist' => \@sectionlist,
1429 'sections' => \%sections,
1430 'purpose' => $declaration_purpose
1434 print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
1439 sub create_parameterlist($$$) {
1441 my $splitter = shift;
1446 # temporarily replace commas inside function pointer definition
1447 while ($args =~ /(\([^\),]+),/) {
1448 $args =~ s/(\([^\),]+),/$1#/g;
1451 foreach my $arg (split($splitter, $args)) {
1453 $arg =~ s/\/\*.*\*\///;
1454 # strip leading/trailing spaces
1460 # Treat preprocessor directive as a typeless variable just to fill
1461 # corresponding data structures "correctly". Catch it later in
1463 push_parameter($arg, "", $file);
1464 } elsif ($arg =~ m/\(.*\*/) {
1465 # pointer-to-function
1467 $arg =~ m/[^\(]+\(\*\s*([^\)]+)\)/;
1470 $type =~ s/([^\(]+\(\*)$param/$1/;
1471 push_parameter($param, $type, $file);
1473 $arg =~ s/\s*:\s*/:/g;
1474 $arg =~ s/\s*\[/\[/g;
1476 my @args = split('\s*,\s*', $arg);
1477 if ($args[0] =~ m/\*/) {
1478 $args[0] =~ s/(\*+)\s*/ $1/;
1482 if ($args[0] =~ /^(.*\s+)(.*?\[.*\].*)$/) {
1484 push(@first_arg, split('\s+', $1));
1485 push(@first_arg, $2);
1487 @first_arg = split('\s+', shift @args);
1490 unshift(@args, pop @first_arg);
1491 $type = join " ", @first_arg;
1493 foreach $param (@args) {
1494 if ($param =~ m/^(\*+)\s*(.*)/) {
1495 push_parameter($2, "$type $1", $file);
1497 elsif ($param =~ m/(.*?):(\d+)/) {
1498 push_parameter($1, "$type:$2", $file)
1501 push_parameter($param, $type, $file);
1508 sub push_parameter($$$) {
1514 my $param_name = $param;
1515 $param_name =~ s/\[.*//;
1517 if ($type eq "" && $param =~ /\.\.\.$/)
1520 $parameterdescs{$param} = "variable arguments";
1522 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1526 $parameterdescs{void} = "no arguments";
1528 elsif ($type eq "" && ($param eq "struct" or $param eq "union"))
1529 # handle unnamed (anonymous) union or struct:
1532 $param = "{unnamed_" . $param. "}";
1533 $parameterdescs{$param} = "anonymous\n";
1537 # warn if parameter has no description
1538 # (but ignore ones starting with # as these are not parameters
1539 # but inline preprocessor statements);
1540 # also ignore unnamed structs/unions;
1542 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1544 $parameterdescs{$param_name} = $undescribed;
1546 if (($type eq 'function') || ($type eq 'enum')) {
1547 print STDERR "Warning(${file}:$.): Function parameter ".
1548 "or member '$param' not " .
1549 "described in '$declaration_name'\n";
1551 print STDERR "Warning(${file}:$.):".
1552 " No description found for parameter '$param'\n";
1557 push @parameterlist, $param;
1558 $parametertypes{$param} = $type;
1562 # takes a function prototype and the name of the current file being
1563 # processed and spits out all the details stored in the global
1565 sub dump_function($$) {
1566 my $prototype = shift;
1569 $prototype =~ s/^static +//;
1570 $prototype =~ s/^extern +//;
1571 $prototype =~ s/^fastcall +//;
1572 $prototype =~ s/^asmlinkage +//;
1573 $prototype =~ s/^inline +//;
1574 $prototype =~ s/^__inline__ +//;
1575 $prototype =~ s/^__inline +//;
1576 $prototype =~ s/^__always_inline +//;
1577 $prototype =~ s/^noinline +//;
1578 $prototype =~ s/__devinit +//;
1579 $prototype =~ s/^#define\s+//; #ak added
1580 $prototype =~ s/__attribute__\s*\(\([a-z,]*\)\)//;
1582 # Yes, this truly is vile. We are looking for:
1583 # 1. Return type (may be nothing if we're looking at a macro)
1585 # 3. Function parameters.
1587 # All the while we have to watch out for function pointer parameters
1588 # (which IIRC is what the two sections are for), C types (these
1589 # regexps don't even start to express all the possibilities), and
1592 # If you mess with these regexps, it's a good idea to check that
1593 # the following functions' documentation still comes out right:
1594 # - parport_register_device (function pointer parameters)
1595 # - atomic_set (macro)
1596 # - pci_match_device, __copy_to_user (long return type)
1598 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1599 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1600 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1601 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1602 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1603 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1604 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1605 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1606 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1607 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1608 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1609 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1610 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1611 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1612 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1613 $prototype =~ m/^(\w+\s+\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1614 $prototype =~ m/^(\w+\s+\w+\s*\*\s*\w+\s*\*\s*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1616 $declaration_name = $2;
1619 create_parameterlist($args, ',', $file);
1621 print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1626 output_declaration($declaration_name,
1628 {'function' => $declaration_name,
1629 'module' => $modulename,
1630 'functiontype' => $return_type,
1631 'parameterlist' => \@parameterlist,
1632 'parameterdescs' => \%parameterdescs,
1633 'parametertypes' => \%parametertypes,
1634 'sectionlist' => \@sectionlist,
1635 'sections' => \%sections,
1636 'purpose' => $declaration_purpose
1640 sub process_file($);
1642 # Read the file that maps relative names to absolute names for
1643 # separate source and object directories and for shadow trees.
1644 if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
1645 my ($relname, $absname);
1646 while(<SOURCE_MAP>) {
1648 ($relname, $absname) = (split())[0..1];
1649 $relname =~ s:^/+::;
1650 $source_map{$relname} = $absname;
1656 open(FLIST,"<$filelist") or die "Can't open file list $filelist";
1667 if ($verbose && $errors) {
1668 print STDERR "$errors errors\n";
1670 if ($verbose && $warnings) {
1671 print STDERR "$warnings warnings\n";
1679 %parameterdescs = ();
1680 %parametertypes = ();
1681 @parameterlist = ();
1689 sub process_state3_function($$) {
1693 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) {
1696 elsif ($x =~ /([^\{]*)/) {
1699 if (($x =~ /\{/) || ($x =~ /\#define/) || ($x =~ /;/)) {
1700 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
1701 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1702 $prototype =~ s@^\s+@@gos; # strip leading spaces
1703 dump_function($prototype,$file);
1708 sub process_state3_type($$) {
1712 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1713 $x =~ s@^\s+@@gos; # strip leading spaces
1714 $x =~ s@\s+$@@gos; # strip trailing spaces
1716 # To distinguish preprocessor directive from regular declaration later.
1721 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1722 $prototype .= $1 . $2;
1723 ($2 eq '{') && $brcount++;
1724 ($2 eq '}') && $brcount--;
1725 if (($2 eq ';') && ($brcount == 0)) {
1726 dump_declaration($prototype,$file);
1738 # replace <, >, and &
1741 if (($output_mode eq "text") || ($output_mode eq "man")) {
1744 $text =~ s/\&/\\\\\\amp;/g;
1745 $text =~ s/\</\\\\\\lt;/g;
1746 $text =~ s/\>/\\\\\\gt;/g;
1750 sub process_file($) {
1755 my $initial_section_counter = $section_counter;
1757 if (defined($ENV{'SRCTREE'})) {
1758 $file = "$ENV{'SRCTREE'}" . "/" . "@_";
1763 if (defined($source_map{$file})) {
1764 $file = $source_map{$file};
1767 if (!open(IN,"<$file")) {
1768 print STDERR "Error: Cannot open file $file\n";
1773 $section_counter = 0;
1776 if (/$doc_start/o) {
1777 $state = 1; # next line is always the function name
1780 } elsif ($state == 1) { # this line is the function name (always)
1781 if (/$doc_block/o) {
1785 $section = $section_intro;
1790 elsif (/$doc_decl/o) {
1792 if (/\s*([\w\s]+?)\s*-/) {
1798 # strip leading/trailing/multiple spaces #RDD:T:
1803 $declaration_purpose = xml_escape($descr);
1805 $declaration_purpose = "";
1807 if ($identifier =~ m/^struct/) {
1808 $decl_type = 'struct';
1809 } elsif ($identifier =~ m/^union/) {
1810 $decl_type = 'union';
1811 } elsif ($identifier =~ m/^enum/) {
1812 $decl_type = 'enum';
1813 } elsif ($identifier =~ m/^typedef/) {
1814 $decl_type = 'typedef';
1816 $decl_type = 'function';
1820 print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
1823 print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
1824 " - I thought it was a doc line\n";
1828 } elsif ($state == 2) { # look for head: lines, and include content
1833 if ($contents ne "") {
1834 if (!$in_doc_sect && $verbose) {
1835 print STDERR "Warning(${file}:$.): contents before sections\n";
1838 dump_section($section, xml_escape($contents));
1839 $section = $section_default;
1843 $contents = $newcontents;
1844 if ($contents ne "") {
1845 while ((substr($contents, 0, 1) eq " ") ||
1846 substr($contents, 0, 1) eq "\t") {
1847 $contents = substr($contents, 1);
1851 $section = $newsection;
1852 } elsif (/$doc_end/) {
1854 if ($contents ne "") {
1855 dump_section($section, xml_escape($contents));
1856 $section = $section_default;
1863 # print STDERR "end of doc comment, looking for prototype\n";
1864 } elsif (/$doc_content/) {
1865 # miguel-style comment kludge, look for blank lines after
1866 # @parameter line to signify start of description
1868 ($section =~ m/^@/ || $section eq $section_context)) {
1869 dump_section($section, xml_escape($contents));
1870 $section = $section_default;
1873 $contents .= $1."\n";
1876 # i dont know - bad line? ignore.
1877 print STDERR "Warning(${file}:$.): bad line: $_";
1880 } elsif ($state == 3) { # scanning for function '{' (end of prototype)
1881 if ($decl_type eq 'function') {
1882 process_state3_function($_, $file);
1884 process_state3_type($_, $file);
1886 } elsif ($state == 4) {
1887 # Documentation block
1889 dump_section($section, $contents);
1890 output_intro({'sectionlist' => \@sectionlist,
1891 'sections' => \%sections });
1895 %parameterdescs = ();
1896 %parametertypes = ();
1897 @parameterlist = ();
1902 $section = $section_intro;
1909 dump_section($section, $contents);
1910 output_intro({'sectionlist' => \@sectionlist,
1911 'sections' => \%sections });
1915 %parameterdescs = ();
1916 %parametertypes = ();
1917 @parameterlist = ();
1923 elsif (/$doc_content/)
1927 $contents .= $blankline;
1931 $contents .= $1 . "\n";
1936 if ($initial_section_counter == $section_counter) {
1937 print STDERR "Warning(${file}): no structured comments found\n";
1938 if ($output_mode eq "xml") {
1939 # The template wants at least one RefEntry here; make one.
1940 print "<refentry>\n";
1941 print " <refnamediv>\n";
1942 print " <refname>\n";
1944 print " </refname>\n";
1945 print " <refpurpose>\n";
1946 print " Document generation inconsistency\n";
1947 print " </refpurpose>\n";
1948 print " </refnamediv>\n";
1949 print " <refsect1>\n";
1952 print " </title>\n";
1953 print " <warning>\n";
1955 print " The template for this document tried to insert\n";
1956 print " the structured comment from the file\n";
1957 print " <filename>${file}</filename> at this point,\n";
1958 print " but none was found.\n";
1959 print " This dummy section is inserted to allow\n";
1960 print " generation to continue.\n";
1962 print " </warning>\n";
1963 print " </refsect1>\n";
1964 print "</refentry>\n";