Add.
[gsasl.git] / doc / gdoc
blob09b154a4c541c53e1ecc0a31c2c0dada45b053ec
1 #!/usr/bin/perl
3 ## Copyright (c) 2002, 2003, 2004, 2005, 2006 Simon Josefsson ##
4 ## added -texinfo, -listfunc ##
5 ## man page revamp ##
6 ## various improvements ##
7 ## Copyright (c) 1998 Michael Zucchi, All Rights Reserved ##
8 ## hacked to allow -tex option --nmav ##
9 ## ##
10 ## This software falls under the GNU Public License. Please read ##
11 ## the COPYING file for more information ##
14 # This will read a 'c' file and scan for embedded comments in the
15 # style of gnome comments (+minor extensions - see below).
17 # This program is modified by Nikos Mavroyanopoulos, for the gnutls
18 # project.
20 # Note: This only supports 'c'.
22 # usage:
23 # gdoc [ -docbook | -html | -text | -man | -tex | -texinfo | -listfunc ]
24 # [ -sourceversion verno ] [ -include file | -includefuncprefix ]
25 # [ -bugsto address ]
26 # [ -seeinfo infonode ] [ -copyright notice ] [ -verbatimcopying ]
27 # [ -function funcname [ -function funcname ...] ] c file(s)s > outputfile
29 # Set output format using one of -docbook, -html, -text, -man, -tex,
30 # -texinfo, or -listfunc. Default is man.
32 # -sourceversion
33 # Version number for source code, e.g. '1.0.4'. Used in 'man' headers.
34 # Defaults to using current date.
36 # -include FILE
37 # For man pages, mention #include <FILE.h> in the synopsis.
39 # -includefuncprefix
40 # For man pages, mention a #include <FILE.h> in the synopsis.
41 # The FILE derived from the function prefix. For example, a
42 # function gss_init_sec_context will generate an include
43 # statement of #include <gss.h>.
45 # -bugsto address
46 # For man pages, include a section about reporting bugs and mention
47 # the given e-mail address, e.g 'bug-libidn@gnu.org'.
49 # -seeinfo infonode
50 # For man pages, include a section that point to an info manual
51 # for more information.
53 # -copyright notice
54 # For man pages, include a copyright section with the given
55 # notice after a preamble. Use, e.g., '2002, 2003 Simon Josefsson'.
57 # -verbatimcopying
58 # For man pages, and when the -copyright parameter is used,
59 # add a licensing statement that say verbatim copying is permitted.
61 # -function funcname
62 # If set, then only generate documentation for the given function(s). All
63 # other functions are ignored.
65 # c files - list of 'c' files to process
67 # All output goes to stdout, with errors to stderr.
70 # format of comments.
71 # In the following table, (...)? signifies optional structure.
72 # (...)* signifies 0 or more structure elements
73 # /**
74 # * function_name(:)? (- short description)?
75 # (* @parameterx: (description of parameter x)?)*
76 # (* a blank line)?
77 # * (Description:)? (Description of function)?
78 # * (Section header: (section description)? )*
79 # (*)?*/
81 # So .. the trivial example would be:
83 # /**
84 # * my_function
85 # **/
87 # If the Description: header tag is ommitted, then there must be a blank line
88 # after the last parameter specification.
89 # e.g.
90 # /**
91 # * my_function - does my stuff
92 # * @my_arg: its mine damnit
93 # *
94 # * Does my stuff explained.
95 # */
97 # or, could also use:
98 # /**
99 # * my_function - does my stuff
100 # * @my_arg: its mine damnit
101 # * Description: Does my stuff explained.
102 # */
103 # etc.
105 # All descriptions can be multiline, apart from the short function description.
107 # All descriptive text is further processed, scanning for the following special
108 # patterns, which are highlighted appropriately.
110 # 'funcname()' - function
111 # '$ENVVAR' - environmental variable OBSOLETE (?)
112 # '#struct_name' - name of a structure
113 # '@parameter' - name of a parameter
114 # '%CONST' - name of a constant.
117 # Extensions for LaTeX:
119 # 1. the symbol '->' will be replaced with a rightarrow
120 # 2. x^y with ${x}^{y}$.
121 # 3. xxx\: with xxx:
123 use POSIX qw(strftime);
125 # match expressions used to find embedded type information
126 $type_constant = "\\\%(\\w+)";
127 $type_func = "(\\w+\\(\\))";
128 $type_param = "\\\@(\\w+)";
129 $type_struct = "\\\#(\\w+)";
130 $type_env = "(\\\$\\w+)";
133 # Output conversion substitutions.
134 # One for each output format
136 # these work fairly well
137 %highlights_html = ( $type_constant, "<i>\$1</i>",
138 $type_func, "<b>\$1</b>",
139 $type_struct, "<i>\$1</i>",
140 $type_param, "<tt><b>\$1</b></tt>" );
141 $blankline_html = "<p>";
143 %highlights_texinfo = ( $type_constant, "\\\@code{\$1}",
144 $type_func, "\\\@code{\$1}",
145 $type_struct, "\\\@code{\$1}",
146 $type_param, "\\\@code{\$1}" );
147 $blankline_texinfo = "";
149 %highlights_tex = ( $type_constant, "{\\\\it \$1}",
150 $type_func, "{\\\\bf \$1}",
151 $type_struct, "{\\\\it \$1}",
152 $type_param, "{\\\\bf \$1}" );
153 $blankline_tex = "\\\\";
155 # sgml, docbook format
156 %highlights_sgml = ( $type_constant, "<replaceable class=\"option\">\$1</replaceable>",
157 $type_func, "<function>\$1</function>",
158 $type_struct, "<structname>\$1</structname>",
159 $type_env, "<envar>\$1</envar>",
160 $type_param, "<parameter>\$1</parameter>" );
161 $blankline_sgml = "</para><para>\n";
163 # these are pretty rough
164 %highlights_man = ( $type_constant, "\\\\fB\$1\\\\fP",
165 $type_func, "\\\\fB\$1\\\\fP",
166 $type_struct, "\\\\fB\$1\\\\fP",
167 $type_param, "\\\\fI\$1\\\\fP" );
168 $blankline_man = "";
170 # text-mode
171 %highlights_text = ( $type_constant, "\$1",
172 $type_func, "\$1",
173 $type_struct, "\$1",
174 $type_param, "\$1" );
175 $blankline_text = "";
178 sub usage {
179 print "Usage: $0 [ -v ] [ -docbook | -html | -text | -man | -tex | -texinfo -listfunc ]\n";
180 print " [ -sourceversion verno ] [ -include file | -includefuncprefix ]\n";
181 print " [ -bugsto address ] [ -seeinfo infonode ] [ -copyright notice]\n";
182 print " [ -verbatimcopying ]\n";
183 print " [ -function funcname [ -function funcname ...] ]\n";
184 print " c source file(s) > outputfile\n";
185 exit 1;
188 # read arguments
189 if ($#ARGV==-1) {
190 usage();
193 $verbose = 0;
194 $output_mode = "man";
195 %highlights = %highlights_man;
196 $blankline = $blankline_man;
197 $modulename = "API Documentation";
198 $sourceversion = strftime "%Y-%m-%d", localtime;
199 $function_only = 0;
200 while ($ARGV[0] =~ m/^-(.*)/) {
201 $cmd = shift @ARGV;
202 if ($cmd eq "-html") {
203 $output_mode = "html";
204 %highlights = %highlights_html;
205 $blankline = $blankline_html;
206 } elsif ($cmd eq "-man") {
207 $output_mode = "man";
208 %highlights = %highlights_man;
209 $blankline = $blankline_man;
210 } elsif ($cmd eq "-tex") {
211 $output_mode = "tex";
212 %highlights = %highlights_tex;
213 $blankline = $blankline_tex;
214 } elsif ($cmd eq "-texinfo") {
215 $output_mode = "texinfo";
216 %highlights = %highlights_texinfo;
217 $blankline = $blankline_texinfo;
218 } elsif ($cmd eq "-text") {
219 $output_mode = "text";
220 %highlights = %highlights_text;
221 $blankline = $blankline_text;
222 } elsif ($cmd eq "-docbook") {
223 $output_mode = "sgml";
224 %highlights = %highlights_sgml;
225 $blankline = $blankline_sgml;
226 } elsif ($cmd eq "-listfunc") {
227 $output_mode = "listfunc";
228 } elsif ($cmd eq "-module") { # not needed for sgml, inherits from calling document
229 $modulename = shift @ARGV;
230 } elsif ($cmd eq "-sourceversion") {
231 $sourceversion = shift @ARGV;
232 } elsif ($cmd eq "-include") {
233 $include = shift @ARGV;
234 } elsif ($cmd eq "-includefuncprefix") {
235 $includefuncprefix = 1;
236 } elsif ($cmd eq "-bugsto") {
237 $bugsto = shift @ARGV;
238 } elsif ($cmd eq "-copyright") {
239 $copyright = shift @ARGV;
240 } elsif ($cmd eq "-verbatimcopying") {
241 $verbatimcopying = 1;
242 } elsif ($cmd eq "-seeinfo") {
243 $seeinfo = shift @ARGV;
244 } elsif ($cmd eq "-function") { # to only output specific functions
245 $function_only = 1;
246 $function = shift @ARGV;
247 $function_table{$function} = 1;
248 } elsif ($cmd eq "-v") {
249 $verbose = 1;
250 } elsif (($cmd eq "-h") || ($cmd eq "--help")) {
251 usage();
256 # dumps section contents to arrays/hashes intended for that purpose.
258 sub dump_section {
259 my $name = shift @_;
260 my $contents = join "\n", @_;
262 if ($name =~ m/$type_constant/) {
263 $name = $1;
264 # print STDERR "constant section '$1' = '$contents'\n";
265 $constants{$name} = $contents;
266 } elsif ($name =~ m/$type_param/) {
267 # print STDERR "parameter def '$1' = '$contents'\n";
268 $name = $1;
269 $parameters{$name} = $contents;
270 } else {
271 # print STDERR "other section '$name' = '$contents'\n";
272 $sections{$name} = $contents;
273 push @sectionlist, $name;
278 # output function
280 # parameters, a hash.
281 # function => "function name"
282 # parameterlist => @list of parameters
283 # parameters => %parameter descriptions
284 # sectionlist => @list of sections
285 # sections => %descriont descriptions
288 sub repstr {
289 $pattern = shift;
290 $repl = shift;
291 $match1 = shift;
292 $match2 = shift;
293 $match3 = shift;
294 $match4 = shift;
296 $output = $repl;
297 $output =~ s,\$1,$match1,g;
298 $output =~ s,\$2,$match2,g;
299 $output =~ s,\$3,$match3,g;
300 $output =~ s,\$4,$match4,g;
302 eval "\$return = qq/$output/";
304 # print "pattern $pattern matched 1=$match1 2=$match2 3=$match3 4=$match4 replace $repl yielded $output interpolated $return\n";
306 $return;
309 sub output_highlight {
310 my $contents = join "\n", @_;
311 my $line;
313 foreach $pattern (keys %highlights) {
314 # print "scanning pattern $pattern ($highlights{$pattern})\n";
315 $contents =~ s:$pattern:repstr($pattern, $highlights{$pattern}, $1, $2, $3, $4):gse;
317 foreach $line (split "\n", $contents) {
318 if ($line eq ""){
319 print $lineprefix, $blankline;
320 } else {
321 print $lineprefix, $line;
323 print "\n";
327 sub just_highlight {
328 my $contents = join "\n", @_;
329 my $line;
330 my $ret = "";
332 foreach $pattern (keys %highlights) {
333 # print "scanning pattern $pattern ($highlights{$pattern})\n";
334 $contents =~ s:$pattern:repstr($pattern, $highlights{$pattern}, $1, $2, $3, $4):gse;
336 foreach $line (split "\n", $contents) {
337 if ($line eq ""){
338 $ret = $ret . $lineprefix . $blankline;
339 } else {
340 $ret = $ret . $lineprefix . $line;
342 $ret = $ret . "\n";
345 return $ret;
348 # output in texinfo
349 sub output_texinfo {
350 my %args = %{$_[0]};
351 my ($parameter, $section);
352 my $count;
354 print "\@subheading ".$args{'function'}."\n";
355 print "\@anchor{".$args{'function'}."}\n";
356 print "\@deftypefun {" . $args{'functiontype'} . "} ";
357 print "{".$args{'function'}."} ";
358 print "(";
359 $count = 0;
360 foreach $parameter (@{$args{'parameterlist'}}) {
361 print $args{'parametertypes'}{$parameter}." \@var{".$parameter."}";
362 if ($count != $#{$args{'parameterlist'}}) {
363 $count++;
364 print ", ";
367 print ")\n";
368 foreach $parameter (@{$args{'parameterlist'}}) {
369 if ($args{'parameters'}{$parameter}) {
370 print "\@var{".$parameter."}: ";
371 output_highlight($args{'parameters'}{$parameter});
372 print "\n";
375 foreach $section (@{$args{'sectionlist'}}) {
376 print "\n\@strong{$section:} " if $section ne $section_default;
377 $args{'sections'}{$section} =~ s:([{}]):\@\1:gs;
378 output_highlight($args{'sections'}{$section});
380 print "\@end deftypefun\n\n";
383 # output in html
384 sub output_html {
385 my %args = %{$_[0]};
386 my ($parameter, $section);
387 my $count;
388 print "\n\n<a name=\"". $args{'function'} . "\">&nbsp</a><h2>Function</h2>\n";
390 print "<i>".$args{'functiontype'}."</i>\n";
391 print "<b>".$args{'function'}."</b>\n";
392 print "(";
393 $count = 0;
394 foreach $parameter (@{$args{'parameterlist'}}) {
395 print "<i>".$args{'parametertypes'}{$parameter}."</i> <b>".$parameter."</b>\n";
396 if ($count != $#{$args{'parameterlist'}}) {
397 $count++;
398 print ", ";
401 print ")\n";
403 print "<h3>Arguments</h3>\n";
404 print "<dl>\n";
405 foreach $parameter (@{$args{'parameterlist'}}) {
406 print "<dt><i>".$args{'parametertypes'}{$parameter}."</i> <b>".$parameter."</b>\n";
407 print "<dd>";
408 output_highlight($args{'parameters'}{$parameter});
410 print "</dl>\n";
411 foreach $section (@{$args{'sectionlist'}}) {
412 print "<h3>$section</h3>\n";
413 print "<ul>\n";
414 output_highlight($args{'sections'}{$section});
415 print "</ul>\n";
417 print "<hr>\n";
420 # output in tex
421 sub output_tex {
422 my %args = %{$_[0]};
423 my ($parameter, $section);
424 my $count;
425 my $func = $args{'function'};
426 my $param;
427 my $param2;
428 my $sec;
429 my $check;
430 my $type;
432 $func =~ s/_/\\_/g;
434 print "\n\n\\subsection{". $func . "}\n\\label{" . $args{'function'} . "}\n";
436 $type = $args{'functiontype'};
437 $type =~ s/_/\\_/g;
439 print "{\\it ".$type."}\n";
440 print "{\\bf ".$func."}\n";
441 print "(";
442 $count = 0;
443 foreach $parameter (@{$args{'parameterlist'}}) {
444 $param = $args{'parametertypes'}{$parameter};
445 $param2 = $parameter;
446 $param =~ s/_/\\_/g;
447 $param2 =~ s/_/\\_/g;
449 print "{\\it ".$param."} {\\bf ".$param2."}";
450 if ($count != $#{$args{'parameterlist'}}) {
451 $count++;
452 print ", ";
455 print ")\n";
457 print "\n{\\large{Arguments}}\n";
459 print "\\begin{itemize}\n";
460 $check=0;
461 foreach $parameter (@{$args{'parameterlist'}}) {
462 $param1 = $args{'parametertypes'}{$parameter};
463 $param1 =~ s/_/\\_/g;
464 $param2 = $parameter;
465 $param2 =~ s/_/\\_/g;
467 $check = 1;
468 print "\\item {\\it ".$param1."} {\\bf ".$param2."}: \n";
469 # print "\n";
471 $param3 = $args{'parameters'}{$parameter};
472 $param3 =~ s/#([a-zA-Z\_]+)/{\\it \1}/g;
474 $out = just_highlight($param3);
475 $out =~ s/_/\\_/g;
476 print $out;
478 if ($check==0) {
479 print "\\item void\n";
481 print "\\end{itemize}\n";
483 foreach $section (@{$args{'sectionlist'}}) {
484 $sec = $section;
485 $sec =~ s/_/\\_/g;
486 $sec =~ s/#([a-zA-Z\_]+)/{\\it \1}/g;
488 print "\n{\\large{$sec}}\\\\\n";
489 print "\\begin{rmfamily}\n";
491 $sec = $args{'sections'}{$section};
492 $sec =~ s/\\:/:/g;
493 $sec =~ s/#([a-zA-Z\_]+)/{\\it \1}/g;
494 $sec =~ s/->/\$\\rightarrow\$/g;
495 $sec =~ s/([0-9]+)\^([0-9]+)/\$\{\1\}\^\{\2\}\$/g;
497 $out = just_highlight($sec);
498 $out =~ s/_/\\_/g;
500 print $out;
501 print "\\end{rmfamily}\n";
503 print "\n";
507 # output in sgml DocBook
508 sub output_sgml {
509 my %args = %{$_[0]};
510 my ($parameter, $section);
511 my $count;
512 my $id;
514 $id = $args{'module'}."-".$args{'function'};
515 $id =~ s/[^A-Za-z0-9]/-/g;
517 print "<refentry>\n";
518 print "<refmeta>\n";
519 print "<refentrytitle><phrase id=\"$id\">".$args{'function'}."</phrase></refentrytitle>\n";
520 print "</refmeta>\n";
521 print "<refnamediv>\n";
522 print " <refname>".$args{'function'}."</refname>\n";
523 print " <refpurpose>\n";
524 print " ".$args{'purpose'}."\n";
525 print " </refpurpose>\n";
526 print "</refnamediv>\n";
528 print "<refsynopsisdiv>\n";
529 print " <title>Synopsis</title>\n";
530 print " <funcsynopsis>\n";
531 print " <funcdef>".$args{'functiontype'}." ";
532 print "<function>".$args{'function'}." ";
533 print "</function></funcdef>\n";
535 # print "<refsect1>\n";
536 # print " <title>Synopsis</title>\n";
537 # print " <funcsynopsis>\n";
538 # print " <funcdef>".$args{'functiontype'}." ";
539 # print "<function>".$args{'function'}." ";
540 # print "</function></funcdef>\n";
542 $count = 0;
543 if ($#{$args{'parameterlist'}} >= 0) {
544 foreach $parameter (@{$args{'parameterlist'}}) {
545 print " <paramdef>".$args{'parametertypes'}{$parameter};
546 print " <parameter>$parameter</parameter></paramdef>\n";
548 } else {
549 print " <void>\n";
551 print " </funcsynopsis>\n";
552 print "</refsynopsisdiv>\n";
553 # print "</refsect1>\n";
555 # print parameters
556 print "<refsect1>\n <title>Arguments</title>\n";
557 # print "<para>\nArguments\n";
558 if ($#{$args{'parameterlist'}} >= 0) {
559 print " <variablelist>\n";
560 foreach $parameter (@{$args{'parameterlist'}}) {
561 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
562 print " <listitem>\n <para>\n";
563 $lineprefix=" ";
564 output_highlight($args{'parameters'}{$parameter});
565 print " </para>\n </listitem>\n </varlistentry>\n";
567 print " </variablelist>\n";
568 } else {
569 print " <para>\n None\n </para>\n";
571 print "</refsect1>\n";
573 # print out each section
574 $lineprefix=" ";
575 foreach $section (@{$args{'sectionlist'}}) {
576 print "<refsect1>\n <title>$section</title>\n <para>\n";
577 # print "<para>\n$section\n";
578 if ($section =~ m/EXAMPLE/i) {
579 print "<example><para>\n";
581 output_highlight($args{'sections'}{$section});
582 # print "</para>";
583 if ($section =~ m/EXAMPLE/i) {
584 print "</para></example>\n";
586 print " </para>\n</refsect1>\n";
589 print "\n\n";
593 # output in man
594 sub output_man {
595 my %args = %{$_[0]};
596 my ($parameter, $section);
597 my $count;
599 print ".\\\" DO NOT MODIFY THIS FILE! It was generated by gdoc.\n";
600 print ".TH \"$args{'function'}\" 3 \"$args{'sourceversion'}\" \"". $args{'module'} . "\" \"". $args{'module'} . "\"\n";
602 print ".SH NAME\n";
604 print $args{'function'};
605 if ($args{'purpose'}) {
606 print " \\- " . $args{'purpose'} . "\n";
607 } else {
608 print " \\- API function\n";
611 print ".SH SYNOPSIS\n";
612 print ".B #include <". $args{'include'} . ">\n"
613 if $args{'include'};
614 print ".B #include <". lc((split /_/, $args{'function'})[0]) . ".h>\n"
615 if $args{'includefuncprefix'};
616 print ".sp\n";
617 print ".BI \"".$args{'functiontype'}." ".$args{'function'}."(";
618 $count = 0;
619 foreach $parameter (@{$args{'parameterlist'}}) {
620 print $args{'parametertypes'}{$parameter}." \" ".$parameter." \"";
621 if ($count != $#{$args{'parameterlist'}}) {
622 $count++;
623 print ", ";
626 print ");\"\n";
628 print ".SH ARGUMENTS\n";
629 foreach $parameter (@{$args{'parameterlist'}}) {
630 print ".IP \"".$args{'parametertypes'}{$parameter}." ".$parameter."\" 12\n";
631 output_highlight($args{'parameters'}{$parameter});
633 foreach $section (@{$args{'sectionlist'}}) {
634 print ".SH \"" . uc($section) . "\"\n";
635 $sec = $args{'sections'}{$section};
636 $sec =~ s/-/\\-/g;
637 output_highlight($sec);
640 if ($args{'bugsto'}) {
641 print ".SH \"REPORTING BUGS\"\n";
642 print "Report bugs to <". $args{'bugsto'} . ">.\n";
645 if ($args{'copyright'}) {
646 print ".SH COPYRIGHT\n";
647 print "Copyright \\(co ". $args{'copyright'} . ".\n";
648 if ($args{'verbatimcopying'}) {
649 print ".br\n";
650 print "Permission is granted to make and distribute verbatim copies of this\n";
651 print "manual provided the copyright notice and this permission notice are\n";
652 print "preserved on all copies.\n";
656 if ($args{'seeinfo'}) {
657 print ".SH \"SEE ALSO\"\n";
658 print "The full documentation for\n";
659 print ".B " . $args{'module'} . "\n";
660 print "is maintained as a Texinfo manual. If the\n";
661 print ".B info\n";
662 print "and\n";
663 print ".B " . $args{'module'} . "\n";
664 print "programs are properly installed at your site, the command\n";
665 print ".IP\n";
666 print ".B info " . $args{'seeinfo'} . "\n";
667 print ".PP\n";
668 print "should give you access to the complete manual.\n";
672 sub output_listfunc {
673 my %args = %{$_[0]};
674 print $args{'function'} . "\n";
678 # output in text
679 sub output_text {
680 my %args = %{$_[0]};
681 my ($parameter, $section);
683 print "Function = ".$args{'function'}."\n";
684 print " return type: ".$args{'functiontype'}."\n\n";
685 foreach $parameter (@{$args{'parameterlist'}}) {
686 print " ".$args{'parametertypes'}{$parameter}." ".$parameter."\n";
687 print " -> ".$args{'parameters'}{$parameter}."\n";
689 foreach $section (@{$args{'sectionlist'}}) {
690 print " $section:\n";
691 print " -> ";
692 output_highlight($args{'sections'}{$section});
697 # generic output function - calls the right one based
698 # on current output mode.
699 sub output_function {
700 # output_html(@_);
701 eval "output_".$output_mode."(\@_);";
706 # takes a function prototype and spits out all the details
707 # stored in the global arrays/hsahes.
708 sub dump_function {
709 my $prototype = shift @_;
711 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
712 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
713 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
714 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
715 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/) {
716 $return_type = $1;
717 $function_name = $2;
718 $args = $3;
720 # print STDERR "ARGS = '$args'\n";
722 foreach $arg (split ',', $args) {
723 # strip leading/trailing spaces
724 $arg =~ s/^\s*//;
725 $arg =~ s/\s*$//;
726 # print STDERR "SCAN ARG: '$arg'\n";
727 @args = split('\s', $arg);
729 # print STDERR " -> @args\n";
730 $param = pop @args;
731 # print STDERR " -> @args\n";
732 if ($param =~ m/^(\*+)(.*)/) {
733 $param = $2;
734 push @args, $1;
736 if ($param =~ m/^(.*)(\[\])$/) {
737 $param = $1;
738 push @args, $2;
740 # print STDERR " :> @args\n";
741 $type = join " ", @args;
743 if ($parameters{$param} eq "" && $param != "void") {
744 $parameters{$param} = "-- undescribed --";
745 print STDERR "warning: $lineno: Function parameter '$param' not described in '$function_name'\n";
748 push @parameterlist, $param;
749 $parametertypes{$param} = $type;
751 # print STDERR "param = '$param', type = '$type'\n";
753 } else {
754 print STDERR "warning: $lineno: Cannot understand prototype: '$prototype'\n";
755 return;
758 if ($function_only==0 || defined($function_table{$function_name})) {
759 output_function({'function' => $function_name,
760 'module' => $modulename,
761 'sourceversion' => $sourceversion,
762 'include' => $include,
763 'includefuncprefix' => $includefuncprefix,
764 'bugsto' => $bugsto,
765 'copyright' => $copyright,
766 'verbatimcopying' => $verbatimcopying,
767 'seeinfo' => $seeinfo,
768 'functiontype' => $return_type,
769 'parameterlist' => \@parameterlist,
770 'parameters' => \%parameters,
771 'parametertypes' => \%parametertypes,
772 'sectionlist' => \@sectionlist,
773 'sections' => \%sections,
774 'purpose' => $function_purpose
779 ######################################################################
780 # main
781 # states
782 # 0 - normal code
783 # 1 - looking for function name
784 # 2 - scanning field start.
785 # 3 - scanning prototype.
786 $state = 0;
787 $section = "";
789 $doc_special = "\@\%\$\#";
791 $doc_start = "^/\\*\\*\$";
792 $doc_end = "\\*/";
793 $doc_com = "\\s*\\*\\s*";
794 $doc_func = $doc_com."(\\w+):?";
795 $doc_sect = $doc_com."([".$doc_special."[:upper:]][\\w ]+):\\s*(.*)";
796 $doc_content = $doc_com."(.*)";
798 %constants = ();
799 %parameters = ();
800 @parameterlist = ();
801 %sections = ();
802 @sectionlist = ();
804 $contents = "";
805 $section_default = "Description"; # default section
806 $section = $section_default;
808 $lineno = 0;
809 foreach $file (@ARGV) {
810 if (!open(IN,"<$file")) {
811 print STDERR "Error: Cannot open file $file\n";
812 next;
814 while (<IN>) {
815 $lineno++;
817 if ($state == 0) {
818 if (/$doc_start/o) {
819 $state = 1; # next line is always the function name
821 } elsif ($state == 1) { # this line is the function name (always)
822 if (/$doc_func/o) {
823 $function = $1;
824 $state = 2;
825 if (/-\s*(.*)/) {
826 $function_purpose = $1;
827 } else {
828 $function_purpose = "";
830 if ($verbose) {
831 print STDERR "Info($lineno): Scanning doc for $function\n";
833 } else {
834 print STDERR "warning: $lineno: Cannot understand $_ on line $lineno",
835 " - I thought it was a doc line\n";
836 $state = 0;
838 } elsif ($state == 2) { # look for head: lines, and include content
839 if (/$doc_sect/o) {
840 $newsection = $1;
841 $newcontents = $2;
843 if ($contents ne "") {
844 dump_section($section, $contents);
845 $section = $section_default;
848 $contents = $newcontents;
849 if ($contents ne "") {
850 $contents .= "\n";
852 $section = $newsection;
853 } elsif (/$doc_end/) {
855 if ($contents ne "") {
856 dump_section($section, $contents);
857 $section = $section_default;
858 $contents = "";
861 # print STDERR "end of doc comment, looking for prototype\n";
862 $prototype = "";
863 $state = 3;
864 } elsif (/$doc_content/) {
865 # miguel-style comment kludge, look for blank lines after
866 # @parameter line to signify start of description
867 if ($1 eq "" && $section =~ m/^@/) {
868 dump_section($section, $contents);
869 $section = $section_default;
870 $contents = "";
871 } else {
872 $contents .= $1."\n";
874 } else {
875 # i dont know - bad line? ignore.
876 print STDERR "warning: $lineno: Bad line: $_";
878 } elsif ($state == 3) { # scanning for function { (end of prototype)
879 if (m#\s*/\*\s+MACDOC\s*#io) {
880 # do nothing
882 elsif (/([^\{]*)/) {
883 $prototype .= $1;
885 if (/\{/) {
886 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
887 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
888 $prototype =~ s@^ +@@gos; # strip leading spaces
889 dump_function($prototype);
891 $function = "";
892 %constants = ();
893 %parameters = ();
894 %parametertypes = ();
895 @parameterlist = ();
896 %sections = ();
897 @sectionlist = ();
898 $prototype = "";
900 $state = 0;