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 # kerneldoc [ -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). All
61 # other functions are ignored. Cannot be used with -function together
62 # (yes thats 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 ommitted, 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
122 # All descriptions can be multiline, except the short function description.
124 # You can also add additional sections. When documenting kernel functions you
125 # should document the "Context:" of the function, e.g. whether the functions
126 # can be called form interrupts. Unlike other sections you can end it with an
128 # Example-sections should contain the string EXAMPLE so that they are marked
129 # appropriately in DocBook.
133 # * user_function - function that can only be called in user context
134 # * @a: some argument
135 # * Context: !in_interrupt()
139 # * user_function(22);
144 # All descriptive text is further processed, scanning for the following special
145 # patterns, which are highlighted appropriately.
147 # 'funcname()' - function
148 # '$ENVVAR' - environmental variable
149 # '&struct_name' - name of a structure (up to two words including 'struct')
150 # '@parameter' - name of a parameter
151 # '%CONST' - name of a constant.
156 # match expressions used to find embedded type information
157 my $type_constant = '\%([-_\w]+)';
158 my $type_func = '(\w+)\(\)';
159 my $type_param = '\@(\w+)';
160 my $type_struct = '\&((struct\s*)?[_\w]+)';
161 my $type_env = '(\$\w+)';
163 # Output conversion substitutions.
164 # One for each output format
166 # these work fairly well
167 my %highlights_html = ( $type_constant, "<i>\$1</i>",
168 $type_func, "<b>\$1</b>",
169 $type_struct, "<i>\$1</i>",
170 $type_param, "<tt><b>\$1</b></tt>" );
171 my $blankline_html = "<p>";
173 # sgml, docbook format
174 my %highlights_sgml = ( "([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>",
175 $type_constant, "<constant>\$1</constant>",
176 $type_func, "<function>\$1</function>",
177 $type_struct, "<structname>\$1</structname>",
178 $type_env, "<envar>\$1</envar>",
179 $type_param, "<parameter>\$1</parameter>" );
180 my $blankline_sgml = "</para><para>\n";
182 # gnome, docbook format
183 my %highlights_gnome = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
184 $type_func, "<function>\$1</function>",
185 $type_struct, "<structname>\$1</structname>",
186 $type_env, "<envar>\$1</envar>",
187 $type_param, "<parameter>\$1</parameter>" );
188 my $blankline_gnome = "</para><para>\n";
190 # these are pretty rough
191 my %highlights_man = ( $type_constant, "\$1",
192 $type_func, "\\\\fB\$1\\\\fP",
193 $type_struct, "\\\\fI\$1\\\\fP",
194 $type_param, "\\\\fI\$1\\\\fP" );
195 my $blankline_man = "";
198 my %highlights_text = ( $type_constant, "\$1",
201 $type_param, "\$1" );
202 my $blankline_text = "";
206 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man ]\n";
207 print " [ -sgmlreferencetitle title ]\n";
208 print " [ -function funcname [ -function funcname ...] ]\n";
209 print " [ -nofunction funcname [ -nofunction funcname ...] ]\n";
210 print " [ -no-dummy-per-file ]\n";
211 print " c source file(s) > outputfile\n";
221 my $add_dummy_entry_per_file = 1;
222 my $sgml_reference_title = "";
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
259 #declaration types: can be
260 # 'function', 'struct', 'union', 'enum', 'typedef'
263 my $doc_special = "\@\%\$\&";
265 my $doc_start = '^/\*\*\s*$'; # Allow whitespace at end of comment start.
267 my $doc_com = '\s*\*\s*';
268 my $doc_decl = $doc_com.'(\w+)';
269 my $doc_sect = $doc_com.'(['.$doc_special.']?[\w ]+):(.*)';
270 my $doc_content = $doc_com.'(.*)';
271 my $doc_block = $doc_com.'DOC:\s*(.*)?';
280 my $section_default = "Description"; # default section
281 my $section_intro = "Introduction";
282 my $section = $section_default;
283 my $section_context = "Context";
285 my $undescribed = "-- undescribed --";
289 while ($ARGV[0] =~ m/^-(.*)/) {
290 my $cmd = shift @ARGV;
291 if ($cmd eq "-html") {
292 $output_mode = "html";
293 %highlights = %highlights_html;
294 $blankline = $blankline_html;
295 } elsif ($cmd eq "-man") {
296 $output_mode = "man";
297 %highlights = %highlights_man;
298 $blankline = $blankline_man;
299 } elsif ($cmd eq "-text") {
300 $output_mode = "text";
301 %highlights = %highlights_text;
302 $blankline = $blankline_text;
303 } elsif ($cmd eq "-docbook") {
304 $output_mode = "sgml";
305 %highlights = %highlights_sgml;
306 $blankline = $blankline_sgml;
307 } elsif ($cmd eq "-gnome") {
308 $output_mode = "gnome";
309 %highlights = %highlights_gnome;
310 $blankline = $blankline_gnome;
311 } elsif ($cmd eq "-module") { # not needed for sgml, inherits from calling document
312 $modulename = shift @ARGV;
313 } elsif ($cmd eq "-sgmlreferencetitle") { # valid XML document
314 $sgml_reference_title = shift @ARGV;
315 } elsif ($cmd eq "-no-dummy-per-file") {
316 $add_dummy_entry_per_file = 0;
317 } elsif ($cmd eq "-function") { # to only output specific functions
319 $function = shift @ARGV;
320 $function_table{$function} = 1;
321 } elsif ($cmd eq "-nofunction") { # to only output specific functions
323 $function = shift @ARGV;
324 $function_table{$function} = 1;
325 } elsif ($cmd eq "-v") {
327 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
329 } elsif ($cmd eq '-filelist') {
330 $filelist = shift @ARGV;
335 # generate a sequence of code that will splice in highlighting information
336 # using the s// operator.
337 my $dohighlight = "";
338 foreach my $pattern (keys %highlights) {
339 # print "scanning pattern $pattern ($highlights{$pattern})\n";
340 $dohighlight .= "\$contents =~ s:$pattern:$highlights{$pattern}:gs;\n";
344 # dumps section contents to arrays/hashes intended for that purpose.
348 my $contents = join "\n", @_;
350 if ($name =~ m/$type_constant/) {
352 # print STDERR "constant section '$1' = '$contents'\n";
353 $constants{$name} = $contents;
354 } elsif ($name =~ m/$type_param/) {
355 # print STDERR "parameter def '$1' = '$contents'\n";
357 $parameterdescs{$name} = $contents;
359 # print STDERR "other section '$name' = '$contents'\n";
360 $sections{$name} = $contents;
361 push @sectionlist, $name;
368 # parameterdescs, a hash.
369 # function => "function name"
370 # parameterlist => @list of parameters
371 # parameterdescs => %parameter descriptions
372 # sectionlist => @list of sections
373 # sections => %descriont descriptions
376 sub output_highlight {
377 my $contents = join "\n",@_;
381 # if (!defined $contents) {
383 # confess "output_highlight got called with no args?\n";
388 foreach $line (split "\n", $contents) {
390 print $lineprefix, $blankline;
392 $line =~ s/\\\\\\/\&/g;
393 print $lineprefix, $line;
399 #output sections in html
400 sub output_section_html(%) {
404 foreach $section (@{$args{'sectionlist'}}) {
405 print "<h3>$section</h3>\n";
406 print "<blockquote>\n";
407 output_highlight($args{'sections'}{$section});
408 print "</blockquote>\n";
412 # output enum in html
413 sub output_enum_html(%) {
417 print "<h2>enum ".$args{'enum'}."</h2>\n";
419 print "<b>enum ".$args{'enum'}."</b> {<br>\n";
421 foreach $parameter (@{$args{'parameterlist'}}) {
422 print " <b>".$parameter."</b>";
423 if ($count != $#{$args{'parameterlist'}}) {
431 print "<h3>Constants</h3>\n";
433 foreach $parameter (@{$args{'parameterlist'}}) {
434 print "<dt><b>".$parameter."</b>\n";
436 output_highlight($args{'parameterdescs'}{$parameter});
439 output_section_html(@_);
443 # output tyepdef in html
444 sub output_typedef_html(%) {
448 print "<h2>typedef ".$args{'typedef'}."</h2>\n";
450 print "<b>typedef ".$args{'typedef'}."</b>\n";
451 output_section_html(@_);
455 # output struct in html
456 sub output_struct_html(%) {
460 print "<h2>".$args{'type'}." ".$args{'struct'}."</h2>\n";
461 print "<b>".$args{'type'}." ".$args{'struct'}."</b> {<br>\n";
462 foreach $parameter (@{$args{'parameterlist'}}) {
463 if ($parameter =~ /^#/) {
464 print "$parameter<br>\n";
467 my $parameter_name = $parameter;
468 $parameter_name =~ s/\[.*//;
470 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
471 $type = $args{'parametertypes'}{$parameter};
472 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
473 # pointer-to-function
474 print " <i>$1</i><b>$parameter</b>) <i>($2)</i>;<br>\n";
475 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
476 print " <i>$1</i> <b>$parameter</b>$2;<br>\n";
478 print " <i>$type</i> <b>$parameter</b>;<br>\n";
483 print "<h3>Members</h3>\n";
485 foreach $parameter (@{$args{'parameterlist'}}) {
486 ($parameter =~ /^#/) && next;
488 my $parameter_name = $parameter;
489 $parameter_name =~ s/\[.*//;
491 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
492 print "<dt><b>".$parameter."</b>\n";
494 output_highlight($args{'parameterdescs'}{$parameter_name});
497 output_section_html(@_);
501 # output function in html
502 sub output_function_html(%) {
504 my ($parameter, $section);
506 print "<h2>Function</h2>\n";
508 print "<i>".$args{'functiontype'}."</i>\n";
509 print "<b>".$args{'function'}."</b>\n";
512 foreach $parameter (@{$args{'parameterlist'}}) {
513 $type = $args{'parametertypes'}{$parameter};
514 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
515 # pointer-to-function
516 print "<i>$1</i><b>$parameter</b>) <i>($2)</i>";
518 print "<i>".$type."</i> <b>".$parameter."</b>";
520 if ($count != $#{$args{'parameterlist'}}) {
527 print "<h3>Arguments</h3>\n";
529 foreach $parameter (@{$args{'parameterlist'}}) {
530 my $parameter_name = $parameter;
531 $parameter_name =~ s/\[.*//;
533 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
534 print "<dt><b>".$parameter."</b>\n";
536 output_highlight($args{'parameterdescs'}{$parameter_name});
539 output_section_html(@_);
543 # output intro in html
544 sub output_intro_html(%) {
546 my ($parameter, $section);
549 foreach $section (@{$args{'sectionlist'}}) {
550 print "<h3>$section</h3>\n";
552 output_highlight($args{'sections'}{$section});
558 sub output_section_sgml(%) {
561 # print out each section
563 foreach $section (@{$args{'sectionlist'}}) {
564 print "<refsect1>\n <title>$section</title>\n <para>\n";
565 if ($section =~ m/EXAMPLE/i) {
566 print "<example><para>\n";
568 output_highlight($args{'sections'}{$section});
569 if ($section =~ m/EXAMPLE/i) {
570 print "</para></example>\n";
572 print " </para>\n</refsect1>\n";
576 # output function in sgml DocBook
577 sub output_function_sgml(%) {
579 my ($parameter, $section);
583 $id = "API-".$args{'function'};
584 $id =~ s/[^A-Za-z0-9]/-/g;
587 print STDERR "generating doc for function ".$args{'function'}."\n";
589 print "<refentry>\n";
591 print "<refentrytitle><phrase id=\"$id\">".$args{'function'}."</phrase></refentrytitle>\n";
592 print "</refmeta>\n";
593 print "<refnamediv>\n";
594 print " <refname>".$args{'function'}."</refname>\n";
595 print " <refpurpose>\n";
597 output_highlight ($args{'purpose'});
598 print " </refpurpose>\n";
599 print "</refnamediv>\n";
601 print "<refsynopsisdiv>\n";
602 print " <title>Synopsis</title>\n";
603 print " <funcsynopsis><funcprototype>\n";
604 print " <funcdef>".$args{'functiontype'}." ";
605 print "<function>".$args{'function'}." </function></funcdef>\n";
608 if ($#{$args{'parameterlist'}} >= 0) {
609 foreach $parameter (@{$args{'parameterlist'}}) {
610 $type = $args{'parametertypes'}{$parameter};
611 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
612 # pointer-to-function
613 print " <paramdef>$1<parameter>$parameter</parameter>)\n";
614 print " <funcparams>$2</funcparams></paramdef>\n";
616 print " <paramdef>".$type;
617 print " <parameter>$parameter</parameter></paramdef>\n";
623 print " </funcprototype></funcsynopsis>\n";
624 print "</refsynopsisdiv>\n";
627 print "<refsect1>\n <title>Arguments</title>\n";
628 if ($#{$args{'parameterlist'}} >= 0) {
629 print " <variablelist>\n";
630 foreach $parameter (@{$args{'parameterlist'}}) {
631 my $parameter_name = $parameter;
632 $parameter_name =~ s/\[.*//;
634 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
635 print " <listitem>\n <para>\n";
637 output_highlight($args{'parameterdescs'}{$parameter_name});
638 print " </para>\n </listitem>\n </varlistentry>\n";
640 print " </variablelist>\n";
642 print " <para>\n None\n </para>\n";
644 print "</refsect1>\n";
646 output_section_sgml(@_);
647 print "</refentry>\n\n";
650 # output struct in sgml DocBook
651 sub output_struct_sgml(%) {
653 my ($parameter, $section);
656 $id = "API-struct-".$args{'struct'};
657 $id =~ s/[^A-Za-z0-9]/-/g;
660 print STDERR "generating doc for struct ".$args{'struct'}."\n";
662 print "<refentry>\n";
664 print "<refentrytitle><phrase id=\"$id\">".$args{'type'}." ".$args{'struct'}."</phrase></refentrytitle>\n";
665 print "</refmeta>\n";
666 print "<refnamediv>\n";
667 print " <refname>".$args{'type'}." ".$args{'struct'}."</refname>\n";
668 print " <refpurpose>\n";
670 output_highlight ($args{'purpose'});
671 print " </refpurpose>\n";
672 print "</refnamediv>\n";
674 print "<refsynopsisdiv>\n";
675 print " <title>Synopsis</title>\n";
676 print " <programlisting>\n";
677 print $args{'type'}." ".$args{'struct'}." {\n";
678 foreach $parameter (@{$args{'parameterlist'}}) {
679 if ($parameter =~ /^#/) {
680 print "$parameter\n";
684 my $parameter_name = $parameter;
685 $parameter_name =~ s/\[.*//;
687 defined($args{'parameterdescs'}{$parameter_name}) || next;
688 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
689 $type = $args{'parametertypes'}{$parameter};
690 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
691 # pointer-to-function
692 print " $1 $parameter) ($2);\n";
693 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
694 print " $1 $parameter$2;\n";
696 print " ".$type." ".$parameter.";\n";
700 print " </programlisting>\n";
701 print "</refsynopsisdiv>\n";
703 print " <refsect1>\n";
704 print " <title>Members</title>\n";
706 print " <variablelist>\n";
707 foreach $parameter (@{$args{'parameterlist'}}) {
708 ($parameter =~ /^#/) && next;
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 print " <varlistentry>";
716 print " <term>$parameter</term>\n";
717 print " <listitem><para>\n";
718 output_highlight($args{'parameterdescs'}{$parameter_name});
719 print " </para></listitem>\n";
720 print " </varlistentry>\n";
722 print " </variablelist>\n";
723 print " </refsect1>\n";
725 output_section_sgml(@_);
727 print "</refentry>\n\n";
730 # output enum in sgml DocBook
731 sub output_enum_sgml(%) {
733 my ($parameter, $section);
737 $id = "API-enum-".$args{'enum'};
738 $id =~ s/[^A-Za-z0-9]/-/g;
741 print STDERR "generating doc for enum ".$args{'enum'}."\n";
743 print "<refentry>\n";
745 print "<refentrytitle><phrase id=\"$id\">enum ".$args{'enum'}."</phrase></refentrytitle>\n";
746 print "</refmeta>\n";
747 print "<refnamediv>\n";
748 print " <refname>enum ".$args{'enum'}."</refname>\n";
749 print " <refpurpose>\n";
751 output_highlight ($args{'purpose'});
752 print " </refpurpose>\n";
753 print "</refnamediv>\n";
755 print "<refsynopsisdiv>\n";
756 print " <title>Synopsis</title>\n";
757 print " <programlisting>\n";
758 print "enum ".$args{'enum'}." {\n";
760 foreach $parameter (@{$args{'parameterlist'}}) {
762 if ($count != $#{$args{'parameterlist'}}) {
769 print " </programlisting>\n";
770 print "</refsynopsisdiv>\n";
772 print "<refsect1>\n";
773 print " <title>Constants</title>\n";
774 print " <variablelist>\n";
775 foreach $parameter (@{$args{'parameterlist'}}) {
776 my $parameter_name = $parameter;
777 $parameter_name =~ s/\[.*//;
779 print " <varlistentry>";
780 print " <term>$parameter</term>\n";
781 print " <listitem><para>\n";
782 output_highlight($args{'parameterdescs'}{$parameter_name});
783 print " </para></listitem>\n";
784 print " </varlistentry>\n";
786 print " </variablelist>\n";
787 print "</refsect1>\n";
789 output_section_sgml(@_);
791 print "</refentry>\n\n";
794 # output typedef in sgml DocBook
795 sub output_typedef_sgml(%) {
797 my ($parameter, $section);
800 $id = "API-typedef-".$args{'typedef'};
801 $id =~ s/[^A-Za-z0-9]/-/g;
804 print STDERR "generating doc for typedef ".$args{'typedef'}."\n";
806 print "<refentry>\n";
808 print "<refentrytitle><phrase id=\"$id\">typedef ".$args{'typedef'}."</phrase></refentrytitle>\n";
809 print "</refmeta>\n";
810 print "<refnamediv>\n";
811 print " <refname>typedef ".$args{'typedef'}."</refname>\n";
812 print " <refpurpose>\n";
814 output_highlight ($args{'purpose'});
815 print " </refpurpose>\n";
816 print "</refnamediv>\n";
818 print "<refsynopsisdiv>\n";
819 print " <title>Synopsis</title>\n";
820 print " <synopsis>typedef ".$args{'typedef'}.";</synopsis>\n";
821 print "</refsynopsisdiv>\n";
823 output_section_sgml(@_);
825 print "</refentry>\n\n";
828 # output in sgml DocBook
829 sub output_intro_sgml(%) {
831 my ($parameter, $section);
834 my $id = $args{'module'};
835 $id =~ s/[^A-Za-z0-9]/-/g;
837 # print out each section
839 foreach $section (@{$args{'sectionlist'}}) {
840 print "<refsect1>\n <title>$section</title>\n <para>\n";
841 if ($section =~ m/EXAMPLE/i) {
842 print "<example><para>\n";
844 output_highlight($args{'sections'}{$section});
845 if ($section =~ m/EXAMPLE/i) {
846 print "</para></example>\n";
848 print " </para>\n</refsect1>\n";
854 # output in sgml DocBook
855 sub output_function_gnome {
857 my ($parameter, $section);
861 $id = $args{'module'}."-".$args{'function'};
862 $id =~ s/[^A-Za-z0-9]/-/g;
865 print " <title id=\"$id\">".$args{'function'}."</title>\n";
867 print " <funcsynopsis>\n";
868 print " <funcdef>".$args{'functiontype'}." ";
869 print "<function>".$args{'function'}." ";
870 print "</function></funcdef>\n";
873 if ($#{$args{'parameterlist'}} >= 0) {
874 foreach $parameter (@{$args{'parameterlist'}}) {
875 $type = $args{'parametertypes'}{$parameter};
876 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
877 # pointer-to-function
878 print " <paramdef>$1 <parameter>$parameter</parameter>)\n";
879 print " <funcparams>$2</funcparams></paramdef>\n";
881 print " <paramdef>".$type;
882 print " <parameter>$parameter</parameter></paramdef>\n";
888 print " </funcsynopsis>\n";
889 if ($#{$args{'parameterlist'}} >= 0) {
890 print " <informaltable pgwide=\"1\" frame=\"none\" role=\"params\">\n";
891 print "<tgroup cols=\"2\">\n";
892 print "<colspec colwidth=\"2*\">\n";
893 print "<colspec colwidth=\"8*\">\n";
895 foreach $parameter (@{$args{'parameterlist'}}) {
896 my $parameter_name = $parameter;
897 $parameter_name =~ s/\[.*//;
899 print " <row><entry align=\"right\"><parameter>$parameter</parameter></entry>\n";
902 output_highlight($args{'parameterdescs'}{$parameter_name});
903 print " </entry></row>\n";
905 print " </tbody></tgroup></informaltable>\n";
907 print " <para>\n None\n </para>\n";
910 # print out each section
912 foreach $section (@{$args{'sectionlist'}}) {
913 print "<simplesect>\n <title>$section</title>\n";
914 if ($section =~ m/EXAMPLE/i) {
915 print "<example><programlisting>\n";
919 output_highlight($args{'sections'}{$section});
921 if ($section =~ m/EXAMPLE/i) {
922 print "</programlisting></example>\n";
925 print " </simplesect>\n";
928 print "</sect2>\n\n";
932 # output function in man
933 sub output_function_man(%) {
935 my ($parameter, $section);
938 print ".TH \"$args{'function'}\" 9 \"$args{'function'}\" \"$man_date\" \"Kernel Hacker's Manual\" LINUX\n";
941 print $args{'function'}." \\- ".$args{'purpose'}."\n";
943 print ".SH SYNOPSIS\n";
944 print ".B \"".$args{'functiontype'}."\" ".$args{'function'}."\n";
948 foreach my $parameter (@{$args{'parameterlist'}}) {
949 if ($count == $#{$args{'parameterlist'}}) {
952 $type = $args{'parametertypes'}{$parameter};
953 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
954 # pointer-to-function
955 print ".BI \"".$parenth.$1."\" ".$parameter." \") (".$2.")".$post."\"\n";
957 $type =~ s/([^\*])$/$1 /;
958 print ".BI \"".$parenth.$type."\" ".$parameter." \"".$post."\"\n";
964 print ".SH ARGUMENTS\n";
965 foreach $parameter (@{$args{'parameterlist'}}) {
966 my $parameter_name = $parameter;
967 $parameter_name =~ s/\[.*//;
969 print ".IP \"".$parameter."\" 12\n";
970 output_highlight($args{'parameterdescs'}{$parameter_name});
972 foreach $section (@{$args{'sectionlist'}}) {
973 print ".SH \"", uc $section, "\"\n";
974 output_highlight($args{'sections'}{$section});
980 sub output_enum_man(%) {
982 my ($parameter, $section);
985 print ".TH \"$args{'module'}\" 9 \"enum $args{'enum'}\" \"$man_date\" \"API Manual\" LINUX\n";
988 print "enum ".$args{'enum'}." \\- ".$args{'purpose'}."\n";
990 print ".SH SYNOPSIS\n";
991 print "enum ".$args{'enum'}." {\n";
993 foreach my $parameter (@{$args{'parameterlist'}}) {
994 print ".br\n.BI \" $parameter\"\n";
995 if ($count == $#{$args{'parameterlist'}}) {
1005 print ".SH Constants\n";
1006 foreach $parameter (@{$args{'parameterlist'}}) {
1007 my $parameter_name = $parameter;
1008 $parameter_name =~ s/\[.*//;
1010 print ".IP \"".$parameter."\" 12\n";
1011 output_highlight($args{'parameterdescs'}{$parameter_name});
1013 foreach $section (@{$args{'sectionlist'}}) {
1014 print ".SH \"$section\"\n";
1015 output_highlight($args{'sections'}{$section});
1020 # output struct in man
1021 sub output_struct_man(%) {
1022 my %args = %{$_[0]};
1023 my ($parameter, $section);
1025 print ".TH \"$args{'module'}\" 9 \"".$args{'type'}." ".$args{'struct'}."\" \"$man_date\" \"API Manual\" LINUX\n";
1028 print $args{'type'}." ".$args{'struct'}." \\- ".$args{'purpose'}."\n";
1030 print ".SH SYNOPSIS\n";
1031 print $args{'type'}." ".$args{'struct'}." {\n.br\n";
1033 foreach my $parameter (@{$args{'parameterlist'}}) {
1034 if ($parameter =~ /^#/) {
1035 print ".BI \"$parameter\"\n.br\n";
1038 my $parameter_name = $parameter;
1039 $parameter_name =~ s/\[.*//;
1041 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1042 $type = $args{'parametertypes'}{$parameter};
1043 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1044 # pointer-to-function
1045 print ".BI \" ".$1."\" ".$parameter." \") (".$2.")"."\"\n;\n";
1046 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1047 print ".BI \" ".$1."\" ".$parameter.$2." \""."\"\n;\n";
1049 $type =~ s/([^\*])$/$1 /;
1050 print ".BI \" ".$type."\" ".$parameter." \""."\"\n;\n";
1056 print ".SH Arguments\n";
1057 foreach $parameter (@{$args{'parameterlist'}}) {
1058 ($parameter =~ /^#/) && next;
1060 my $parameter_name = $parameter;
1061 $parameter_name =~ s/\[.*//;
1063 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1064 print ".IP \"".$parameter."\" 12\n";
1065 output_highlight($args{'parameterdescs'}{$parameter_name});
1067 foreach $section (@{$args{'sectionlist'}}) {
1068 print ".SH \"$section\"\n";
1069 output_highlight($args{'sections'}{$section});
1074 # output typedef in man
1075 sub output_typedef_man(%) {
1076 my %args = %{$_[0]};
1077 my ($parameter, $section);
1079 print ".TH \"$args{'module'}\" 9 \"$args{'typedef'}\" \"$man_date\" \"API Manual\" LINUX\n";
1082 print "typedef ".$args{'typedef'}." \\- ".$args{'purpose'}."\n";
1084 foreach $section (@{$args{'sectionlist'}}) {
1085 print ".SH \"$section\"\n";
1086 output_highlight($args{'sections'}{$section});
1090 sub output_intro_man(%) {
1091 my %args = %{$_[0]};
1092 my ($parameter, $section);
1095 print ".TH \"$args{'module'}\" 9 \"$args{'module'}\" \"$man_date\" \"API Manual\" LINUX\n";
1097 foreach $section (@{$args{'sectionlist'}}) {
1098 print ".SH \"$section\"\n";
1099 output_highlight($args{'sections'}{$section});
1105 sub output_function_text(%) {
1106 my %args = %{$_[0]};
1107 my ($parameter, $section);
1109 print "Function:\n\n";
1110 my $start=$args{'functiontype'}." ".$args{'function'}." (";
1113 foreach my $parameter (@{$args{'parameterlist'}}) {
1114 $type = $args{'parametertypes'}{$parameter};
1115 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1116 # pointer-to-function
1117 print $1.$parameter.") (".$2;
1119 print $type." ".$parameter;
1121 if ($count != $#{$args{'parameterlist'}}) {
1124 print " " x length($start);
1130 print "Arguments:\n\n";
1131 foreach $parameter (@{$args{'parameterlist'}}) {
1132 my $parameter_name = $parameter;
1133 $parameter_name =~ s/\[.*//;
1135 print $parameter."\n\t".$args{'parameterdescs'}{$parameter_name}."\n";
1137 output_section_text(@_);
1140 #output sections in text
1141 sub output_section_text(%) {
1142 my %args = %{$_[0]};
1146 foreach $section (@{$args{'sectionlist'}}) {
1147 print "$section:\n\n";
1148 output_highlight($args{'sections'}{$section});
1153 # output enum in text
1154 sub output_enum_text(%) {
1155 my %args = %{$_[0]};
1160 print "enum ".$args{'enum'}." {\n";
1162 foreach $parameter (@{$args{'parameterlist'}}) {
1163 print "\t$parameter";
1164 if ($count != $#{$args{'parameterlist'}}) {
1172 print "Constants:\n\n";
1173 foreach $parameter (@{$args{'parameterlist'}}) {
1174 print "$parameter\n\t";
1175 print $args{'parameterdescs'}{$parameter}."\n";
1178 output_section_text(@_);
1181 # output typedef in text
1182 sub output_typedef_text(%) {
1183 my %args = %{$_[0]};
1186 print "Typedef:\n\n";
1188 print "typedef ".$args{'typedef'}."\n";
1189 output_section_text(@_);
1192 # output struct as text
1193 sub output_struct_text(%) {
1194 my %args = %{$_[0]};
1197 print $args{'type'}." ".$args{'struct'}.":\n\n";
1198 print $args{'type'}." ".$args{'struct'}." {\n";
1199 foreach $parameter (@{$args{'parameterlist'}}) {
1200 if ($parameter =~ /^#/) {
1201 print "$parameter\n";
1205 my $parameter_name = $parameter;
1206 $parameter_name =~ s/\[.*//;
1208 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1209 $type = $args{'parametertypes'}{$parameter};
1210 if ($type =~ m/([^\(]*\(\*)\s*\)\s*\(([^\)]*)\)/) {
1211 # pointer-to-function
1212 print "\t$1 $parameter) ($2);\n";
1213 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1214 print "\t$1 $parameter$2;\n";
1216 print "\t".$type." ".$parameter.";\n";
1221 print "Members:\n\n";
1222 foreach $parameter (@{$args{'parameterlist'}}) {
1223 ($parameter =~ /^#/) && next;
1225 my $parameter_name = $parameter;
1226 $parameter_name =~ s/\[.*//;
1228 ($args{'parameterdescs'}{$parameter_name} ne $undescribed) || next;
1229 print "$parameter\n\t";
1230 print $args{'parameterdescs'}{$parameter_name}."\n";
1233 output_section_text(@_);
1236 sub output_intro_text(%) {
1237 my %args = %{$_[0]};
1238 my ($parameter, $section);
1240 foreach $section (@{$args{'sectionlist'}}) {
1241 print " $section:\n";
1243 output_highlight($args{'sections'}{$section});
1248 # generic output function for typedefs
1249 sub output_declaration {
1252 my $functype = shift;
1253 my $func = "output_${functype}_$output_mode";
1255 # print STDERR "Info(): function_only: $function_only output_declaration for $name\n";
1256 # if(defined($function_table{$name})) {
1257 # print STDERR "Info(): function $name defined in function_table\n";
1260 if (($function_only==0) ||
1261 ( $function_only == 1 && defined($function_table{$name})) ||
1262 ( $function_only == 2 && !defined($function_table{$name})))
1266 # print STDERR "Info(): incrementing section_counter: $section_counter\n";
1273 # generic output function - calls the right one based
1274 # on current output mode.
1277 my $func = "output_intro_".$output_mode;
1283 # takes a declaration (struct, union, enum, typedef) and
1284 # invokes the right handler. NOT called for functions.
1285 sub dump_declaration($$) {
1287 my ($prototype, $file) = @_;
1288 my $func = "dump_".$decl_type;
1292 sub dump_union($$) {
1296 sub dump_struct($$) {
1300 if ($x =~/(struct|union)\s+(\w+)\s*{(.*)}/) {
1301 $declaration_name = $2;
1304 # ignore embedded structs or unions
1305 $members =~ s/{.*?}//g;
1307 create_parameterlist($members, ';', $file);
1309 output_declaration($declaration_name,
1311 {'struct' => $declaration_name,
1312 'module' => $modulename,
1313 'parameterlist' => \@parameterlist,
1314 'parameterdescs' => \%parameterdescs,
1315 'parametertypes' => \%parametertypes,
1316 'sectionlist' => \@sectionlist,
1317 'sections' => \%sections,
1318 'purpose' => $declaration_purpose,
1319 'type' => $decl_type
1323 print STDERR "Error(${file}:$.): Cannot parse struct or union!\n";
1332 if ($x =~ /enum\s+(\w+)\s*{(.*)}/) {
1333 $declaration_name = $1;
1336 foreach my $arg (split ',', $members) {
1337 $arg =~ s/^\s*(\w+).*/$1/;
1338 push @parameterlist, $arg;
1339 if (!$parameterdescs{$arg}) {
1340 $parameterdescs{$arg} = $undescribed;
1341 print STDERR "Warning(${file}:$.): Enum value '$arg' ".
1342 "not described in enum '$declaration_name'\n";
1347 output_declaration($declaration_name,
1349 {'enum' => $declaration_name,
1350 'module' => $modulename,
1351 'parameterlist' => \@parameterlist,
1352 'parameterdescs' => \%parameterdescs,
1353 'sectionlist' => \@sectionlist,
1354 'sections' => \%sections,
1355 'purpose' => $declaration_purpose
1359 print STDERR "Error(${file}:$.): Cannot parse enum!\n";
1364 sub dump_typedef($$) {
1368 while (($x =~ /\(*.\)\s*;$/) || ($x =~ /\[*.\]\s*;$/)) {
1369 $x =~ s/\(*.\)\s*;$/;/;
1370 $x =~ s/\[*.\]\s*;$/;/;
1373 if ($x =~ /typedef.*\s+(\w+)\s*;/) {
1374 $declaration_name = $1;
1376 output_declaration($declaration_name,
1378 {'typedef' => $declaration_name,
1379 'module' => $modulename,
1380 'sectionlist' => \@sectionlist,
1381 'sections' => \%sections,
1382 'purpose' => $declaration_purpose
1386 print STDERR "Error(${file}:$.): Cannot parse typedef!\n";
1391 sub create_parameterlist($$$) {
1393 my $splitter = shift;
1398 while ($args =~ /(\([^\),]+),/) {
1399 $args =~ s/(\([^\),]+),/$1#/g;
1402 foreach my $arg (split($splitter, $args)) {
1404 $arg =~ s/\/\*.*\*\///;
1405 # strip leading/trailing spaces
1411 # Treat preprocessor directive as a typeless variable just to fill
1412 # corresponding data structures "correctly". Catch it later in
1414 push_parameter($arg, "", $file);
1415 } elsif ($arg =~ m/\(/) {
1416 # pointer-to-function
1418 $arg =~ m/[^\(]+\(\*([^\)]+)\)/;
1421 $type =~ s/([^\(]+\(\*)$param/$1/;
1422 push_parameter($param, $type, $file);
1424 $arg =~ s/\s*:\s*/:/g;
1425 $arg =~ s/\s*\[/\[/g;
1427 my @args = split('\s*,\s*', $arg);
1428 if ($args[0] =~ m/\*/) {
1429 $args[0] =~ s/(\*+)\s*/ $1/;
1431 my @first_arg = split('\s+', shift @args);
1432 unshift(@args, pop @first_arg);
1433 $type = join " ", @first_arg;
1435 foreach $param (@args) {
1436 if ($param =~ m/^(\*+)\s*(.*)/) {
1437 push_parameter($2, "$type $1", $file);
1439 elsif ($param =~ m/(.*?):(\d+)/) {
1440 push_parameter($1, "$type:$2", $file)
1443 push_parameter($param, $type, $file);
1450 sub push_parameter($$$) {
1455 my $param_name = $param;
1456 $param_name =~ s/\[.*//;
1458 if ($type eq "" && $param eq "...")
1462 $parameterdescs{"..."} = "variable arguments";
1464 elsif ($type eq "" && ($param eq "" or $param eq "void"))
1468 $parameterdescs{void} = "no arguments";
1470 if (defined $type && $type && !defined $parameterdescs{$param_name}) {
1471 $parameterdescs{$param_name} = $undescribed;
1473 if (($type eq 'function') || ($type eq 'enum')) {
1474 print STDERR "Warning(${file}:$.): Function parameter ".
1475 "or member '$param' not " .
1476 "described in '$declaration_name'\n";
1478 print STDERR "Warning(${file}:$.):".
1479 " No description found for parameter '$param'\n";
1483 push @parameterlist, $param;
1484 $parametertypes{$param} = $type;
1488 # takes a function prototype and the name of the current file being
1489 # processed and spits out all the details stored in the global
1491 sub dump_function($$) {
1492 my $prototype = shift;
1495 $prototype =~ s/^static +//;
1496 $prototype =~ s/^extern +//;
1497 $prototype =~ s/^fastcall +//;
1498 $prototype =~ s/^asmlinkage +//;
1499 $prototype =~ s/^inline +//;
1500 $prototype =~ s/^__inline__ +//;
1501 $prototype =~ s/^#define +//; #ak added
1502 $prototype =~ s/__attribute__ \(\([a-z,]*\)\)//;
1504 # Yes, this truly is vile. We are looking for:
1505 # 1. Return type (may be nothing if we're looking at a macro)
1507 # 3. Function parameters.
1509 # All the while we have to watch out for function pointer parameters
1510 # (which IIRC is what the two sections are for), C types (these
1511 # regexps don't even start to express all the possibilities), and
1514 # If you mess with these regexps, it's a good idea to check that
1515 # the following functions' documentation still comes out right:
1516 # - parport_register_device (function pointer parameters)
1517 # - atomic_set (macro)
1518 # - pci_match_device (long return type)
1520 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1521 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1522 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1523 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1524 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1525 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1526 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\(]*)\)/ ||
1527 $prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1528 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1529 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1530 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1531 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1532 $prototype =~ m/^(\w+\s+\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/ ||
1533 $prototype =~ m/^(\w+\s+\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\{]*)\)/) {
1535 $declaration_name = $2;
1538 create_parameterlist($args, ',', $file);
1540 print STDERR "Error(${file}:$.): cannot understand prototype: '$prototype'\n";
1545 output_declaration($declaration_name,
1547 {'function' => $declaration_name,
1548 'module' => $modulename,
1549 'functiontype' => $return_type,
1550 'parameterlist' => \@parameterlist,
1551 'parameterdescs' => \%parameterdescs,
1552 'parametertypes' => \%parametertypes,
1553 'sectionlist' => \@sectionlist,
1554 'sections' => \%sections,
1555 'purpose' => $declaration_purpose
1559 sub process_file($);
1561 # Read the file that maps relative names to absolute names for
1562 # separate source and object directories and for shadow trees.
1563 if (open(SOURCE_MAP, "<.tmp_filelist.txt")) {
1564 my ($relname, $absname);
1565 while(<SOURCE_MAP>) {
1567 ($relname, $absname) = (split())[0..1];
1568 $relname =~ s:^/+::;
1569 $source_map{$relname} = $absname;
1574 if (! ($sgml_reference_title eq "")) {
1575 print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
1576 print "<section><title>$sgml_reference_title</title>\n";
1580 open(FLIST,"<$filelist") or die "Can't open file list $filelist";
1592 if (! ($sgml_reference_title eq "")) {
1593 print "</section>\n";
1595 if ($verbose && $errors) {
1596 print STDERR "$errors errors\n";
1598 if ($verbose && $warnings) {
1599 print STDERR "$warnings warnings\n";
1607 %parameterdescs = ();
1608 %parametertypes = ();
1609 @parameterlist = ();
1617 sub process_state3_function($$) {
1621 if ($x =~ m#\s*/\*\s+MACDOC\s*#io) {
1624 elsif ($x =~ /([^\{]*)/) {
1627 if (($x =~ /\{/) || ($x =~ /\#/) || ($x =~ /;/)) {
1628 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
1629 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1630 $prototype =~ s@^\s+@@gos; # strip leading spaces
1631 dump_function($prototype,$file);
1636 sub process_state3_type($$) {
1640 $x =~ s@/\*.*?\*/@@gos; # strip comments.
1641 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1642 $x =~ s@^\s+@@gos; # strip leading spaces
1643 $x =~ s@\s+$@@gos; # strip trailing spaces
1645 # To distinguish preprocessor directive from regular declaration later.
1650 if ( $x =~ /([^{};]*)([{};])(.*)/ ) {
1651 $prototype .= $1 . $2;
1652 ($2 eq '{') && $brcount++;
1653 ($2 eq '}') && $brcount--;
1654 if (($2 eq ';') && ($brcount == 0)) {
1655 dump_declaration($prototype,$file);
1667 sub process_file($) {
1668 #my ($file) = "$ENV{'SRCTREE'}@_";
1672 my $initial_section_counter = $section_counter;
1674 if (defined($source_map{$file})) {
1675 $file = $source_map{$file};
1678 if (!open(IN,"<$file")) {
1679 print STDERR "Error: Cannot open file $file\n";
1684 print STDERR "Parsing file $file\n";
1685 #$section_counter = 0;
1688 if (/$doc_start/o) {
1689 $state = 1; # next line is always the function name
1690 #print STDERR "found doc start\n";
1692 } elsif ($state == 1) { # this line is the function name (always)
1693 if (/$doc_block/o) {
1697 $section = $section_intro;
1702 elsif (/$doc_decl/o) {
1704 if (/\s*([\w\s]+?)\s*-/) {
1710 $declaration_purpose = $1;
1712 $declaration_purpose = "";
1714 if ($identifier =~ m/^struct/) {
1715 $decl_type = 'struct';
1716 } elsif ($identifier =~ m/^union/) {
1717 $decl_type = 'union';
1718 } elsif ($identifier =~ m/^enum/) {
1719 $decl_type = 'enum';
1720 } elsif ($identifier =~ m/^typedef/) {
1721 $decl_type = 'typedef';
1723 $decl_type = 'function';
1727 print STDERR "Info(${file}:$.): Scanning doc for $identifier\n";
1730 print STDERR "Warning(${file}:$.): Cannot understand $_ on line $.",
1731 " - I thought it was a doc line\n";
1735 } elsif ($state == 2) { # look for head: lines, and include content
1740 if ($contents ne "") {
1741 $contents =~ s/\&/\\\\\\amp;/g;
1742 $contents =~ s/\</\\\\\\lt;/g;
1743 $contents =~ s/\>/\\\\\\gt;/g;
1744 dump_section($section, $contents);
1745 $section = $section_default;
1748 $contents = $newcontents;
1749 if ($contents ne "") {
1752 $section = $newsection;
1753 } elsif (/$doc_end/) {
1755 if ($contents ne "") {
1756 $contents =~ s/\&/\\\\\\amp;/g;
1757 $contents =~ s/\</\\\\\\lt;/g;
1758 $contents =~ s/\>/\\\\\\gt;/g;
1759 dump_section($section, $contents);
1760 $section = $section_default;
1767 # print STDERR "end of doc comment, looking for prototype\n";
1768 } elsif (/$doc_content/) {
1769 # miguel-style comment kludge, look for blank lines after
1770 # @parameter line to signify start of description
1772 ($section =~ m/^@/ || $section eq $section_context)) {
1773 $contents =~ s/\&/\\\\\\amp;/g;
1774 $contents =~ s/\</\\\\\\lt;/g;
1775 $contents =~ s/\>/\\\\\\gt;/g;
1776 dump_section($section, $contents);
1777 $section = $section_default;
1780 $contents .= $1."\n";
1783 # i dont know - bad line? ignore.
1784 print STDERR "Warning(${file}:$.): bad line: $_";
1787 } elsif ($state == 3) { # scanning for function { (end of prototype)
1788 if ($decl_type eq 'function') {
1789 process_state3_function($_, $file);
1791 process_state3_type($_, $file);
1793 } elsif ($state == 4) {
1794 # Documentation block
1796 dump_section($section, $contents);
1797 output_intro({'sectionlist' => \@sectionlist,
1798 'sections' => \%sections });
1802 %parameterdescs = ();
1803 %parametertypes = ();
1804 @parameterlist = ();
1809 $section = $section_intro;
1816 dump_section($section, $contents);
1817 output_intro({'sectionlist' => \@sectionlist,
1818 'sections' => \%sections });
1822 %parameterdescs = ();
1823 %parametertypes = ();
1824 @parameterlist = ();
1830 elsif (/$doc_content/)
1834 $contents .= $blankline;
1838 $contents .= $1 . "\n";
1843 if ($initial_section_counter == $section_counter) {
1844 print STDERR "Warning(${file}): no structured comments found\n";
1845 if ($output_mode eq "sgml" && $add_dummy_entry_per_file > 0) {
1846 # The template wants at least one RefEntry here; make one.
1847 print "<refentry>\n";
1848 print " <refnamediv>\n";
1849 print " <refname>\n";
1851 print " </refname>\n";
1852 print " <refpurpose>\n";
1853 print " Document generation inconsistency\n";
1854 print " </refpurpose>\n";
1855 print " </refnamediv>\n";
1856 print " <refsect1>\n";
1859 print " </title>\n";
1860 print " <warning>\n";
1862 print " The template for this document tried to insert\n";
1863 print " the structured comment from the file\n";
1864 print " <filename>${file}</filename> at this point,\n";
1865 print " but none was found.\n";
1866 print " This dummy section is inserted to allow\n";
1867 print " generation to continue.\n";
1869 print " </warning>\n";
1870 print " </refsect1>\n";
1871 print "</refentry>\n";