1 eval '(exit $?0)' && eval 'exec perl "$0" ${1+"$@"}'
2 & eval 'exec perl "$0" $argv:q'
5 ## Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Simon Josefsson
6 ## added -texinfo, -listfunc, -pkg-name
8 ## various improvements
9 ## Copyright (c) 2001, 2002 Nikos Mavrogiannopoulos
11 ## Copyright (c) 1998 Michael Zucchi
12 ## Copyright (c) 2013 Adam Sampson
13 ## made highlighting not depend on hash order, for Perl 5.18
15 # This program is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU General Public License as published by
17 # the Free Software Foundation, either version 3 of the License, or
18 # (at your option) any later version.
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program. If not, see <http://www.gnu.org/licenses/>.
28 # This will read a C source code file and scan for embedded comments
29 # in the style of gnome comments (+minor extensions - see below).
32 # gdoc [ -docbook | -html | -text | -man | -tex | -texinfo | -listfunc ]
33 # [ -sourceversion verno ] [ -include file | -includefuncprefix ]
34 # [ -bugsto address ] [ -pkg-name packagename ]
35 # [ -seeinfo infonode ] [ -copyright notice ] [ -verbatimcopying ]
36 # [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile
38 # Set output format using one of -docbook, -html, -text, -man, -tex,
39 # -texinfo, or -listfunc. Default is man.
42 # Version number for source code, e.g. '1.0.4'. Used in 'man' headers.
43 # Defaults to using current date.
46 # For man pages, mention #include <FILE.h> in the synopsis.
49 # For man pages, mention a #include <FILE.h> in the synopsis.
50 # The FILE derived from the function prefix. For example, a
51 # function gss_init_sec_context will generate an include
52 # statement of #include <gss.h>.
55 # For man pages, include a section about reporting bugs and mention
56 # the given e-mail address, e.g 'bug-libidn@gnu.org'.
58 # -pkg-name packagename
59 # For man pages when -bugsto is used, also include help URLs to the
60 # the project's home page. For example, "GNU Libidn".
63 # For man pages, include a section that point to an info manual
64 # for more information.
67 # For man pages, include a copyright section with the given
68 # notice after a preamble. Use, e.g., '2002, 2003 Simon Josefsson'.
71 # For man pages, and when the -copyright parameter is used,
72 # add a licensing statement that say verbatim copying is permitted.
75 # If set, then only generate documentation for the given function(s). All
76 # other functions are ignored.
78 # c files - list of 'c' files to process
80 # All output goes to stdout, with errors to stderr.
84 # In the following table, (...)? signifies optional structure.
85 # (...)* signifies 0 or more structure elements
87 # * function_name(:)? (- short description)?
88 # (* @parameterx: (description of parameter x)?)*
90 # * (Description:)? (Description of function)?
91 # * (Section header: (section description)? )*
94 # So .. the trivial example would be:
100 # If the Description: header tag is ommitted, then there must be a blank line
101 # after the last parameter specification.
104 # * my_function - does my stuff
105 # * @my_arg: its mine damnit
107 # * Does my stuff explained.
110 # or, could also use:
112 # * my_function - does my stuff
113 # * @my_arg: its mine damnit
114 # * Description: Does my stuff explained.
118 # All descriptions can be multiline, apart from the short function description.
120 # All descriptive text is further processed, scanning for the following special
121 # patterns, which are highlighted appropriately.
123 # 'funcname()' - function
124 # '$ENVVAR' - environmental variable OBSOLETE (?)
125 # '#struct_name' - name of a structure
126 # '@parameter' - name of a parameter
127 # '%CONST' - name of a constant.
130 # Extensions for LaTeX:
132 # 1. the symbol '->' will be replaced with a rightarrow
133 # 2. x^y with ${x}^{y}$.
136 use POSIX qw(strftime);
138 # match expressions used to find embedded type information
139 $type_constant = "\\\%([A-Za-z0-9_]+)";
140 $type_func = "([A-Za-z0-9_]+\\(\\))";
141 $type_param = '\@([A-Za-z0-9_]+)\s*';
142 $type_struct = "\\\#([A-Za-z0-9_]+)";
143 $type_env = "(\\\$[A-Za-z0-9_]+)";
146 # Output conversion substitutions.
147 # One for each output format
149 # these work fairly well
150 @highlights_html = ( [$type_constant, '"<i>$1</i>"'],
151 [$type_func, '"<b>$1</b>"'],
152 [$type_struct, '"<i>$1</i>"'],
153 [$type_param, '" <tt><b>$1</b></tt> "'] );
154 $blankline_html = "<p>";
156 @highlights_texinfo = ( [$type_param, '" \@code{$1} "'],
157 [$type_constant, '"\@code{$1} "'],
158 [$type_func, '"\@code{$1} "'],
159 [$type_struct, '"\@code{$1} "'],
161 $blankline_texinfo = "";
163 @highlights_tex = ( [$type_param, '" {\\\bf $1} "'],
164 [$type_constant, '"{\\\it $1}"'],
165 [$type_func, '"{\\\bf $1}"'],
166 [$type_struct, '"{\\\it $1}"'],
168 $blankline_tex = "\\\\";
170 # sgml, docbook format
171 @highlights_sgml = ( [$type_constant, '"<replaceable class=\"option\">$1</replaceable>"'],
172 [$type_func, '"<function>$1</function>"'],
173 [$type_struct, '"<structname>$1</structname>"'],
174 [$type_env, '"<envar>$1</envar>"'],
175 [$type_param, '" <parameter>$1</parameter> "'] );
176 $blankline_sgml = "</para><para>\n";
178 # these are pretty rough
179 @highlights_man = ( [$type_constant, '"\\\fB$1\\\fP"'],
180 [$type_func, '"\\\fB$1\\\fP"'],
181 [$type_struct, '"\\\fB$1\\\fP"'],
182 [$type_param, '" \\\fI$1\\\fP "'] );
186 @highlights_text = ( [$type_constant, '"$1"'],
187 [$type_func, '"$1"'],
188 [$type_struct, '"$1"'],
189 [$type_param, '"$1 "'] );
190 $blankline_text = "";
194 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man | -tex | -texinfo -listfunc ]\n";
195 print " [ -sourceversion verno ] [ -include file | -includefuncprefix ]\n";
196 print " [ -bugsto address ] [ -seeinfo infonode ] [ -copyright notice]\n";
197 print " [ -verbatimcopying ] [ -pkg-name packagename ]\n";
198 print " [ -function funcname [ -function funcname ...] ]\n";
199 print " c source file(s) > outputfile\n";
209 $output_mode = "man";
210 @highlights = @highlights_man;
211 $blankline = $blankline_man;
212 $modulename = "API Documentation";
213 $sourceversion = strftime "%Y-%m-%d", localtime;
215 while ($ARGV[0] =~ m/^-(.*)/) {
217 if ($cmd eq "-html") {
218 $output_mode = "html";
219 @highlights = @highlights_html;
220 $blankline = $blankline_html;
221 } elsif ($cmd eq "-man") {
222 $output_mode = "man";
223 @highlights = @highlights_man;
224 $blankline = $blankline_man;
225 } elsif ($cmd eq "-tex") {
226 $output_mode = "tex";
227 @highlights = @highlights_tex;
228 $blankline = $blankline_tex;
229 } elsif ($cmd eq "-texinfo") {
230 $output_mode = "texinfo";
231 @highlights = @highlights_texinfo;
232 $blankline = $blankline_texinfo;
233 } elsif ($cmd eq "-text") {
234 $output_mode = "text";
235 @highlights = @highlights_text;
236 $blankline = $blankline_text;
237 } elsif ($cmd eq "-docbook") {
238 $output_mode = "sgml";
239 @highlights = @highlights_sgml;
240 $blankline = $blankline_sgml;
241 } elsif ($cmd eq "-listfunc") {
242 $output_mode = "listfunc";
243 } elsif ($cmd eq "-module") { # not needed for sgml, inherits from calling document
244 $modulename = shift @ARGV;
245 } elsif ($cmd eq "-sourceversion") {
246 $sourceversion = shift @ARGV;
247 } elsif ($cmd eq "-include") {
248 $include = shift @ARGV;
249 } elsif ($cmd eq "-includefuncprefix") {
250 $includefuncprefix = 1;
251 } elsif ($cmd eq "-bugsto") {
252 $bugsto = shift @ARGV;
253 } elsif ($cmd eq "-pkg-name") {
254 $pkgname = shift @ARGV;
255 } elsif ($cmd eq "-copyright") {
256 $copyright = shift @ARGV;
257 } elsif ($cmd eq "-verbatimcopying") {
258 $verbatimcopying = 1;
259 } elsif ($cmd eq "-seeinfo") {
260 $seeinfo = shift @ARGV;
261 } elsif ($cmd eq "-function") { # to only output specific functions
263 $function = shift @ARGV;
264 $function_table{$function} = 1;
265 } elsif ($cmd eq "-v") {
267 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
273 # dumps section contents to arrays/hashes intended for that purpose.
277 my $contents = join "\n", @_;
281 if ($name =~ m/$type_constant/) {
283 # print STDERR "constant section '$1' = '$contents'\n";
284 $constants{$name} = $contents;
285 } elsif ($name =~ m/$type_param/) {
286 # print STDERR "parameter def '$1' = '$contents'\n";
288 $parameters{$name} = $contents;
290 # print STDERR "other section '$name' = '$contents'\n";
292 $sections{$name} = $contents;
293 push @sectionlist, $name;
300 # parameters, a hash.
301 # function => "function name"
302 # parameterlist => @list of parameters
303 # parameters => %parameter descriptions
304 # sectionlist => @list of sections
305 # sections => %descriont descriptions
309 my $contents = join "\n", @_;
313 foreach $highlight (@highlights) {
314 my ($pattern, $replace) = @$highlight;
315 #print "scanning pattern $pattern ($replace)\n";
316 $contents =~ s/$pattern/$replace/gees;
318 foreach $line (split "\n", $contents) {
320 $ret = $ret . $lineprefix . $blankline;
322 $ret = $ret . $lineprefix . $line;
330 sub output_highlight {
331 print (just_highlight (@_));
337 my ($parameter, $section);
340 print "\@subheading ".$args{'function'}."\n";
341 print "\@anchor{".$args{'function'}."}\n";
342 print "\@deftypefun {" . $args{'functiontype'} . "} ";
343 print "{".$args{'function'}."} ";
346 foreach $parameter (@{$args{'parameterlist'}}) {
347 print $args{'parametertypes'}{$parameter}." \@var{".$parameter."}";
348 if ($count != $#{$args{'parameterlist'}}) {
354 foreach $parameter (@{$args{'parameterlist'}}) {
355 if ($args{'parameters'}{$parameter}) {
356 print "\@var{".$parameter."}: ";
357 output_highlight($args{'parameters'}{$parameter});
361 foreach $section (@{$args{'sectionlist'}}) {
363 print "\n\@strong{$section:} " if $section ne $section_default;
364 $args{'sections'}{$section} =~ s:([{}]):\@$1:gs;
365 output_highlight($args{'sections'}{$section});
367 print "\@end deftypefun\n\n";
370 sub output_enum_texinfo {
372 my ($parameter, $section);
374 my $name = $args{'enum'};
381 print "\n\@c $name\n";
382 print "\@table \@code\n";
385 foreach $parameter (@{$args{'parameterlist'}}) {
386 $param1 = $parameter;
387 $param1 =~ s/_/_\@-/g;
390 print "\@item ".$param1."\n";
393 $param2 = $args{'parameters'}{$parameter};
394 $out = just_highlight($param2);
398 print "\@end table\n";
404 my ($parameter, $section);
406 print "\n\n<a name=\"". $args{'function'} . "\"> </a><h2>Function</h2>\n";
408 print "<i>".$args{'functiontype'}."</i>\n";
409 print "<b>".$args{'function'}."</b>\n";
412 foreach $parameter (@{$args{'parameterlist'}}) {
413 print "<i>".$args{'parametertypes'}{$parameter}."</i> <b>".$parameter."</b>\n";
414 if ($count != $#{$args{'parameterlist'}}) {
421 print "<h3>Arguments</h3>\n";
423 foreach $parameter (@{$args{'parameterlist'}}) {
424 print "<dt><i>".$args{'parametertypes'}{$parameter}."</i> <b>".$parameter."</b>\n";
426 output_highlight($args{'parameters'}{$parameter});
429 foreach $section (@{$args{'sectionlist'}}) {
430 print "<h3>$section</h3>\n";
432 output_highlight($args{'sections'}{$section});
441 my ($parameter, $section);
443 my $func = $args{'function'};
452 print "\n\n\\begin{function}\n";
453 print "\\functionTitle{". $func . "}\n";
454 print "\\index{". $func . "}\n";
456 $type = $args{'functiontype'};
459 print "{\\it ".$type."}\n";
460 print "{\\bf ".$func."}\n";
463 foreach $parameter (@{$args{'parameterlist'}}) {
464 $param = $args{'parametertypes'}{$parameter};
465 $param2 = $parameter;
467 $param2 =~ s/_/\\_/g;
469 print "{\\it ".$param."} {\\bf ".$param2."}";
470 if ($count != $#{$args{'parameterlist'}}) {
477 print "\n\\begin{functionArguments}\n";
480 foreach $parameter (@{$args{'parameterlist'}}) {
481 $param1 = $args{'parametertypes'}{$parameter};
482 $param1 =~ s/_/\\_/g;
483 $param2 = $parameter;
484 $param2 =~ s/_/\\_/g;
487 print "\\functionArgument {\\it ".$param1."} {\\bf ".$param2."}: \n";
490 $param3 = $args{'parameters'}{$parameter};
491 $param3 =~ s/\#([a-zA-Z\_]+)/{\\it $1}/g;
492 $param3 =~ s/\%([a-zA-Z\_]+)/{\\bf $1}/g;
494 $out = just_highlight($param3);
499 print "\\item void\n";
501 print "\\end{functionArguments}\n";
503 foreach $section (@{$args{'sectionlist'}}) {
506 $sec =~ s/#([a-zA-Z\_]+)/{\\it $1}/g;
508 print "\n\\begin{function${sec}}\n";
509 $out = $args{'sections'}{$section};
511 $out =~ s/\#([a-zA-Z\_]+)/{\\it $1}/g;
512 $out =~ s/\%([a-zA-Z\_]+)/{\\bf $1}/g;
513 $out =~ s/\@([a-zA-Z\_]+)/{\\bf $1}/g;
514 $out =~ s/_/\\_\\-/g;
519 $out =~ s/\-\>/\$\\rightarrow\$/g;
520 $out =~ s/([0-9]+)\^([0-9]+)/\$\{$1\}\^\{$2\}\$/g;
523 print "\\end{function${sec}}\n";
525 print "\\end{function}\n\n";
528 sub output_enum_tex {
530 my ($parameter, $section);
532 my $name = $args{'enum'};
539 print "\n\n\\begin{enum}\n";
541 print "\\enumTitle{". $name . "}\n";
542 print "\\index{". $name . "}\n";
544 print "\n\\begin{enumList}\n";
547 foreach $parameter (@{$args{'parameterlist'}}) {
548 $param1 = $parameter;
549 $param1 =~ s/_/\\_\\-/g;
552 print "\\enumElement{".$param1."}{";
555 $param2 = $args{'parameters'}{$parameter};
556 $param2 =~ s/\#([a-zA-Z\_]+)/{\\it $1}/g;
557 $param2 =~ s/\%([a-zA-Z\_]+)/{\\bf $1}/g;
558 $out = just_highlight($param2);
563 print "\\end{enumList}\n";
565 print "\\end{enum}\n\n";
568 # output in sgml DocBook
571 my ($parameter, $section);
575 $id = $args{'module'}."-".$args{'function'};
576 $id =~ s/[^A-Za-z0-9]/-/g;
578 print "<refentry>\n";
580 print "<refentrytitle><phrase id=\"$id\">".$args{'function'}."</phrase></refentrytitle>\n";
581 print "</refmeta>\n";
582 print "<refnamediv>\n";
583 print " <refname>".$args{'function'}."</refname>\n";
584 print " <refpurpose>\n";
585 print " ".$args{'purpose'}."\n";
586 print " </refpurpose>\n";
587 print "</refnamediv>\n";
589 print "<refsynopsisdiv>\n";
590 print " <title>Synopsis</title>\n";
591 print " <funcsynopsis>\n";
592 print " <funcdef>".$args{'functiontype'}." ";
593 print "<function>".$args{'function'}." ";
594 print "</function></funcdef>\n";
596 # print "<refsect1>\n";
597 # print " <title>Synopsis</title>\n";
598 # print " <funcsynopsis>\n";
599 # print " <funcdef>".$args{'functiontype'}." ";
600 # print "<function>".$args{'function'}." ";
601 # print "</function></funcdef>\n";
604 if ($#{$args{'parameterlist'}} >= 0) {
605 foreach $parameter (@{$args{'parameterlist'}}) {
606 print " <paramdef>".$args{'parametertypes'}{$parameter};
607 print " <parameter>$parameter</parameter></paramdef>\n";
612 print " </funcsynopsis>\n";
613 print "</refsynopsisdiv>\n";
614 # print "</refsect1>\n";
617 print "<refsect1>\n <title>Arguments</title>\n";
618 # print "<para>\nArguments\n";
619 if ($#{$args{'parameterlist'}} >= 0) {
620 print " <variablelist>\n";
621 foreach $parameter (@{$args{'parameterlist'}}) {
622 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
623 print " <listitem>\n <para>\n";
625 output_highlight($args{'parameters'}{$parameter});
626 print " </para>\n </listitem>\n </varlistentry>\n";
628 print " </variablelist>\n";
630 print " <para>\n None\n </para>\n";
632 print "</refsect1>\n";
634 # print out each section
636 foreach $section (@{$args{'sectionlist'}}) {
637 print "<refsect1>\n <title>$section</title>\n <para>\n";
638 # print "<para>\n$section\n";
639 if ($section =~ m/EXAMPLE/i) {
640 print "<example><para>\n";
642 output_highlight($args{'sections'}{$section});
644 if ($section =~ m/EXAMPLE/i) {
645 print "</para></example>\n";
647 print " </para>\n</refsect1>\n";
657 my ($parameter, $section);
660 print ".\\\" DO NOT MODIFY THIS FILE! It was generated by gdoc.\n";
661 print ".TH \"$args{'function'}\" 3 \"$args{'sourceversion'}\" \"". $args{'module'} . "\" \"". $args{'module'} . "\"\n";
665 print $args{'function'};
666 if ($args{'purpose'}) {
667 print " \\- " . $args{'purpose'} . "\n";
669 print " \\- API function\n";
672 print ".SH SYNOPSIS\n";
673 print ".B #include <". $args{'include'} . ">\n"
675 print ".B #include <". lc((split /_/, $args{'function'})[0]) . ".h>\n"
676 if $args{'includefuncprefix'};
678 print ".BI \"".$args{'functiontype'}." ".$args{'function'}."(";
680 foreach $parameter (@{$args{'parameterlist'}}) {
681 print $args{'parametertypes'}{$parameter}." \" ".$parameter." \"";
682 if ($count != $#{$args{'parameterlist'}}) {
689 print ".SH ARGUMENTS\n";
690 foreach $parameter (@{$args{'parameterlist'}}) {
691 print ".IP \"".$args{'parametertypes'}{$parameter}." ".$parameter."\" 12\n";
692 $param = $args{'parameters'}{$parameter};
694 output_highlight($param);
696 foreach $section (@{$args{'sectionlist'}}) {
697 print ".SH \"" . uc($section) . "\"\n";
698 $sec = $args{'sections'}{$section};
700 output_highlight($sec);
703 if ($args{'bugsto'}) {
704 print ".SH \"REPORTING BUGS\"\n";
705 print "Report bugs to <". $args{'bugsto'} . ">.\n";
707 print "General guidelines for reporting bugs: http://www.gnu.org/gethelp/\n";
709 if ($args{'pkgname'}) {
710 print $args{'pkgname'} . " home page: " .
711 "http://www.gnu.org/software/" . $args{'module'} . "/\n";
716 if ($args{'copyright'}) {
717 print ".SH COPYRIGHT\n";
718 print "Copyright \\(co ". $args{'copyright'} . ".\n";
719 if ($args{'verbatimcopying'}) {
721 print "Copying and distribution of this file, with or without modification,\n";
722 print "are permitted in any medium without royalty provided the copyright\n";
723 print "notice and this notice are preserved.\n";
727 if ($args{'seeinfo'}) {
728 print ".SH \"SEE ALSO\"\n";
729 print "The full documentation for\n";
730 print ".B " . $args{'module'} . "\n";
731 print "is maintained as a Texinfo manual. If the\n";
734 print ".B " . $args{'module'} . "\n";
735 print "programs are properly installed at your site, the command\n";
737 print ".B info " . $args{'seeinfo'} . "\n";
739 print "should give you access to the complete manual.\n";
740 print "As an alternative you may obtain the manual from:\n";
742 print ".B http://www.gnu.org/software/" . $args{'module'} . "/manual/\n";
747 sub output_listfunc {
749 print $args{'function'} . "\n";
756 my ($parameter, $section);
758 print "Function = ".$args{'function'}."\n";
759 print " return type: ".$args{'functiontype'}."\n\n";
760 foreach $parameter (@{$args{'parameterlist'}}) {
761 print " ".$args{'parametertypes'}{$parameter}." ".$parameter."\n";
762 print " -> ".$args{'parameters'}{$parameter}."\n";
764 foreach $section (@{$args{'sectionlist'}}) {
765 print " $section:\n";
767 output_highlight($args{'sections'}{$section});
772 # generic output function - calls the right one based
773 # on current output mode.
774 sub output_function {
776 eval "output_".$output_mode."(\@_);";
780 eval "output_enum_".$output_mode."(\@_);";
785 # takes a function prototype and spits out all the details
786 # stored in the global arrays/hsahes.
788 my $prototype = shift @_;
790 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
791 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
792 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
793 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
794 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/) {
799 # print STDERR "ARGS = '$args'\n";
801 foreach $arg (split ',', $args) {
802 # strip leading/trailing spaces
805 # print STDERR "SCAN ARG: '$arg'\n";
806 @args = split('\s', $arg);
808 # print STDERR " -> @args\n";
810 # print STDERR " -> @args\n";
811 if ($param =~ m/^(\*+)(.*)/) {
815 if ($param =~ m/^(.*)(\[\])$/) {
819 # print STDERR " :> @args\n";
820 $type = join " ", @args;
822 if ((!defined($parameters{$param}) || $parameters{$param} eq "") && $param ne "void") {
823 $parameters{$param} = "-- undescribed --";
824 print STDERR "warning: $lineno: Function parameter '$param' not described in '$function_name'\n";
827 push @parameterlist, $param;
828 $parametertypes{$param} = $type;
830 # print STDERR "param = '$param', type = '$type'\n";
833 print STDERR "warning: $lineno: Cannot understand prototype: '$prototype'\n";
837 if ($function_only==0 || defined($function_table{$function_name})) {
838 output_function({'function' => $function_name,
839 'module' => $modulename,
840 'sourceversion' => $sourceversion,
841 'include' => $include,
842 'includefuncprefix' => $includefuncprefix,
844 'pkgname' => $pkgname,
845 'copyright' => $copyright,
846 'verbatimcopying' => $verbatimcopying,
847 'seeinfo' => $seeinfo,
848 'functiontype' => $return_type,
849 'parameterlist' => \@parameterlist,
850 'parameters' => \%parameters,
851 'parametertypes' => \%parametertypes,
852 'sectionlist' => \@sectionlist,
853 'sections' => \%sections,
854 'purpose' => $function_purpose
860 my $prototype = shift @_;
862 if (($prototype =~ m/^\s*typedef\s+enum\s*[a-zA-Z0-9_~:]*\s*\{([\-a-zA-Z0-9_~=,:\s\(\)\<]+)\s*\}\s*([a-zA-Z0-9_]+);.*/)) {
863 # || $prototype =~ m/^\s*enum\s+([a-zA-Z0-9_~:]+).*/) {
867 foreach $arg (split ',', $args) {
868 # strip leading/trailing spaces
871 $arg =~ s/([A-Za-z0-9_]+)\s*=.*/$1/g;
872 # print STDERR "SCAN ARG: '$arg'\n";
875 if ((!defined($parameters{$arg}) || $parameters{$arg} eq "")) {
876 $parameters{$arg} = "-- undescribed --";
877 print STDERR "warning: $lineno: Enumeration parameter '$arg' not described in '$name'\n";
880 push @parameterlist, $arg;
882 # print STDERR "param = '$arg'\n";
885 # print STDERR "warning: $lineno: Cannot understand enumeration: '$prototype'\n";
889 output_enum({'enum' => $name,
890 'module' => $modulename,
891 'sourceversion' => $sourceversion,
892 'include' => $include,
893 'includefuncprefix' => $includefuncprefix,
895 'pkgname' => $pkgname,
896 'copyright' => $copyright,
897 'verbatimcopying' => $verbatimcopying,
898 'seeinfo' => $seeinfo,
899 'functiontype' => $return_type,
900 'parameterlist' => \@parameterlist,
901 'parameters' => \%parameters,
902 'parametertypes' => \%parametertypes,
903 'sectionlist' => \@sectionlist,
904 'sections' => \%sections,
905 'purpose' => $function_purpose
909 ######################################################################
913 # 1 - looking for function name
914 # 2 - scanning field start.
915 # 3 - scanning prototype.
919 $doc_special = "\@\%\$\#";
921 $doc_start = "^/\\*\\*\$";
923 $doc_com = "\\s*\\*\\s*";
924 $doc_func = $doc_com."(\\w+):?";
925 $doc_sect = $doc_com."([".$doc_special."[:upper:]][\\w]+):\\s*(.*)";
926 $doc_content = $doc_com."(.*)";
935 $section_default = "Description"; # default section
936 $section = $section_default;
941 foreach $file (@ARGV) {
942 if (!open(IN,"<$file")) {
943 print STDERR "Error: Cannot open file $file\n";
946 while ($line = <IN>) {
950 if ($line =~ /$doc_start/o) {
951 $state = 1; # next line is always the function name
952 # print STDERR "XXX: start of doc comment\n";
954 } elsif ($state == 1) { # this line is the function name (always)
955 if ($line =~ /$doc_func/o) {
958 # print STDERR "XXX: start of doc comment, looking for prototype\n";
960 if ($line =~ /-\s*(.*)/) {
961 $function_purpose = $1;
963 $function_purpose = "";
966 print STDERR "Info($lineno): Scanning doc for $function\n";
969 print STDERR "warning: $lineno: Cannot understand $_ on line $lineno",
970 " - I thought it was a doc line\n";
973 } elsif ($state == 2) { # look for head: lines, and include content
974 if ($line =~ /$doc_sect/o) {
978 if ($contents ne '') {
979 dump_section($section, $contents);
980 $section = $section_default;
983 $contents = $newcontents;
984 if ($contents ne "") {
987 $section = $newsection;
988 } elsif ($line =~ /$doc_end/) {
990 if ($contents ne "") {
991 dump_section($section, $contents);
992 $section = $section_default;
998 } elsif ($line =~ /$doc_content/) {
999 # miguel-style comment kludge, look for blank lines after
1000 # @parameter line to signify start of description
1001 if ($1 eq '' && $section =~ m/^@/) {
1002 dump_section($section, $contents);
1003 $section = $section_default;
1006 $contents .= $1."\n";
1009 # i dont know - bad line? ignore.
1010 print STDERR "warning: $lineno: Bad line: $_";
1012 } elsif ($state == 3) { # scanning for function { (end of prototype)
1013 if ($line =~ /([a-zA-Z\s]+)enum(.*)$/) {
1017 if ($line =~ m#\s*/\*\s+MACDOC\s*#io) {
1020 elsif ($enum == 1 && $line =~ /(\s*\{).*/) {
1021 $prototype = "typedef enum {";
1023 elsif ($line =~ /([^\{]*)/) {
1027 if ($enum == 0 && $line =~ /;/) {
1028 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
1029 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1030 $prototype =~ s@^ +@@gos; # strip leading spaces
1032 dump_function($prototype);
1037 %parametertypes = ();
1038 @parameterlist = ();
1046 elsif ($enum == 1 && $line =~ /\}/) {
1047 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
1048 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1049 $prototype =~ s@^ +@@gos; # strip leading spaces
1051 dump_enum($prototype);
1056 %parametertypes = ();
1057 @parameterlist = ();