Export ASN1_CONST_*, taken from int.h.
[libtasn1.git] / doc / gdoc
blob06d7dd23b78374151e23f4e6380ae0c1a6e6469e
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 "\@deftypefun {" . $args{'functiontype'} . "} ";
355 print "{".$args{'function'}."} ";
356 print "(";
357 $count = 0;
358 foreach $parameter (@{$args{'parameterlist'}}) {
359 print $args{'parametertypes'}{$parameter}." \@var{".$parameter."}";
360 if ($count != $#{$args{'parameterlist'}}) {
361 $count++;
362 print ", ";
365 print ")\n";
366 foreach $parameter (@{$args{'parameterlist'}}) {
367 if ($args{'parameters'}{$parameter}) {
368 print "\@var{".$parameter."}: ";
369 output_highlight($args{'parameters'}{$parameter});
370 print "\n";
373 foreach $section (@{$args{'sectionlist'}}) {
374 print "\n\@strong{$section:} " if $section ne $section_default;
375 $args{'sections'}{$section} =~ s:([{}]):\@\1:gs;
376 output_highlight($args{'sections'}{$section});
378 print "\@end deftypefun\n\n";
381 # output in html
382 sub output_html {
383 my %args = %{$_[0]};
384 my ($parameter, $section);
385 my $count;
386 print "\n\n<a name=\"". $args{'function'} . "\">&nbsp</a><h2>Function</h2>\n";
388 print "<i>".$args{'functiontype'}."</i>\n";
389 print "<b>".$args{'function'}."</b>\n";
390 print "(";
391 $count = 0;
392 foreach $parameter (@{$args{'parameterlist'}}) {
393 print "<i>".$args{'parametertypes'}{$parameter}."</i> <b>".$parameter."</b>\n";
394 if ($count != $#{$args{'parameterlist'}}) {
395 $count++;
396 print ", ";
399 print ")\n";
401 print "<h3>Arguments</h3>\n";
402 print "<dl>\n";
403 foreach $parameter (@{$args{'parameterlist'}}) {
404 print "<dt><i>".$args{'parametertypes'}{$parameter}."</i> <b>".$parameter."</b>\n";
405 print "<dd>";
406 output_highlight($args{'parameters'}{$parameter});
408 print "</dl>\n";
409 foreach $section (@{$args{'sectionlist'}}) {
410 print "<h3>$section</h3>\n";
411 print "<ul>\n";
412 output_highlight($args{'sections'}{$section});
413 print "</ul>\n";
415 print "<hr>\n";
418 # output in tex
419 sub output_tex {
420 my %args = %{$_[0]};
421 my ($parameter, $section);
422 my $count;
423 my $func = $args{'function'};
424 my $param;
425 my $param2;
426 my $sec;
427 my $check;
428 my $type;
430 $func =~ s/_/\\_/g;
432 print "\n\n\\subsection{". $func . "}\n\\label{" . $args{'function'} . "}\n";
434 $type = $args{'functiontype'};
435 $type =~ s/_/\\_/g;
437 print "{\\it ".$type."}\n";
438 print "{\\bf ".$func."}\n";
439 print "(";
440 $count = 0;
441 foreach $parameter (@{$args{'parameterlist'}}) {
442 $param = $args{'parametertypes'}{$parameter};
443 $param2 = $parameter;
444 $param =~ s/_/\\_/g;
445 $param2 =~ s/_/\\_/g;
447 print "{\\it ".$param."} {\\bf ".$param2."}";
448 if ($count != $#{$args{'parameterlist'}}) {
449 $count++;
450 print ", ";
453 print ")\n";
455 print "\n{\\large{Arguments}}\n";
457 print "\\begin{itemize}\n";
458 $check=0;
459 foreach $parameter (@{$args{'parameterlist'}}) {
460 $param1 = $args{'parametertypes'}{$parameter};
461 $param1 =~ s/_/\\_/g;
462 $param2 = $parameter;
463 $param2 =~ s/_/\\_/g;
465 $check = 1;
466 print "\\item {\\it ".$param1."} {\\bf ".$param2."}: \n";
467 # print "\n";
469 $param3 = $args{'parameters'}{$parameter};
470 $param3 =~ s/#([a-zA-Z\_]+)/{\\it \1}/g;
472 $out = just_highlight($param3);
473 $out =~ s/_/\\_/g;
474 print $out;
476 if ($check==0) {
477 print "\\item void\n";
479 print "\\end{itemize}\n";
481 foreach $section (@{$args{'sectionlist'}}) {
482 $sec = $section;
483 $sec =~ s/_/\\_/g;
484 $sec =~ s/#([a-zA-Z\_]+)/{\\it \1}/g;
486 print "\n{\\large{$sec}}\\\\\n";
487 print "\\begin{rmfamily}\n";
489 $sec = $args{'sections'}{$section};
490 $sec =~ s/\\:/:/g;
491 $sec =~ s/#([a-zA-Z\_]+)/{\\it \1}/g;
492 $sec =~ s/->/\$\\rightarrow\$/g;
493 $sec =~ s/([0-9]+)\^([0-9]+)/\$\{\1\}\^\{\2\}\$/g;
495 $out = just_highlight($sec);
496 $out =~ s/_/\\_/g;
498 print $out;
499 print "\\end{rmfamily}\n";
501 print "\n";
505 # output in sgml DocBook
506 sub output_sgml {
507 my %args = %{$_[0]};
508 my ($parameter, $section);
509 my $count;
510 my $id;
512 $id = $args{'module'}."-".$args{'function'};
513 $id =~ s/[^A-Za-z0-9]/-/g;
515 print "<refentry>\n";
516 print "<refmeta>\n";
517 print "<refentrytitle><phrase id=\"$id\">".$args{'function'}."</phrase></refentrytitle>\n";
518 print "</refmeta>\n";
519 print "<refnamediv>\n";
520 print " <refname>".$args{'function'}."</refname>\n";
521 print " <refpurpose>\n";
522 print " ".$args{'purpose'}."\n";
523 print " </refpurpose>\n";
524 print "</refnamediv>\n";
526 print "<refsynopsisdiv>\n";
527 print " <title>Synopsis</title>\n";
528 print " <funcsynopsis>\n";
529 print " <funcdef>".$args{'functiontype'}." ";
530 print "<function>".$args{'function'}." ";
531 print "</function></funcdef>\n";
533 # print "<refsect1>\n";
534 # print " <title>Synopsis</title>\n";
535 # print " <funcsynopsis>\n";
536 # print " <funcdef>".$args{'functiontype'}." ";
537 # print "<function>".$args{'function'}." ";
538 # print "</function></funcdef>\n";
540 $count = 0;
541 if ($#{$args{'parameterlist'}} >= 0) {
542 foreach $parameter (@{$args{'parameterlist'}}) {
543 print " <paramdef>".$args{'parametertypes'}{$parameter};
544 print " <parameter>$parameter</parameter></paramdef>\n";
546 } else {
547 print " <void>\n";
549 print " </funcsynopsis>\n";
550 print "</refsynopsisdiv>\n";
551 # print "</refsect1>\n";
553 # print parameters
554 print "<refsect1>\n <title>Arguments</title>\n";
555 # print "<para>\nArguments\n";
556 if ($#{$args{'parameterlist'}} >= 0) {
557 print " <variablelist>\n";
558 foreach $parameter (@{$args{'parameterlist'}}) {
559 print " <varlistentry>\n <term><parameter>$parameter</parameter></term>\n";
560 print " <listitem>\n <para>\n";
561 $lineprefix=" ";
562 output_highlight($args{'parameters'}{$parameter});
563 print " </para>\n </listitem>\n </varlistentry>\n";
565 print " </variablelist>\n";
566 } else {
567 print " <para>\n None\n </para>\n";
569 print "</refsect1>\n";
571 # print out each section
572 $lineprefix=" ";
573 foreach $section (@{$args{'sectionlist'}}) {
574 print "<refsect1>\n <title>$section</title>\n <para>\n";
575 # print "<para>\n$section\n";
576 if ($section =~ m/EXAMPLE/i) {
577 print "<example><para>\n";
579 output_highlight($args{'sections'}{$section});
580 # print "</para>";
581 if ($section =~ m/EXAMPLE/i) {
582 print "</para></example>\n";
584 print " </para>\n</refsect1>\n";
587 print "\n\n";
591 # output in man
592 sub output_man {
593 my %args = %{$_[0]};
594 my ($parameter, $section);
595 my $count;
597 print ".\\\" DO NOT MODIFY THIS FILE! It was generated by gdoc.\n";
598 print ".TH \"$args{'function'}\" 3 \"$args{'sourceversion'}\" \"". $args{'module'} . "\" \"". $args{'module'} . "\"\n";
600 print ".SH NAME\n";
602 print $args{'function'};
603 if ($args{'purpose'}) {
604 print " \\- " . $args{'purpose'} . "\n";
605 } else {
606 print " \\- API function\n";
609 print ".SH SYNOPSIS\n";
610 print ".B #include <". $args{'include'} . ">\n"
611 if $args{'include'};
612 print ".B #include <". lc((split /_/, $args{'function'})[0]) . ".h>\n"
613 if $args{'includefuncprefix'};
614 print ".sp\n";
615 print ".BI \"".$args{'functiontype'}." ".$args{'function'}."(";
616 $count = 0;
617 foreach $parameter (@{$args{'parameterlist'}}) {
618 print $args{'parametertypes'}{$parameter}." \" ".$parameter." \"";
619 if ($count != $#{$args{'parameterlist'}}) {
620 $count++;
621 print ", ";
624 print ");\"\n";
626 print ".SH ARGUMENTS\n";
627 foreach $parameter (@{$args{'parameterlist'}}) {
628 print ".IP \"".$args{'parametertypes'}{$parameter}." ".$parameter."\" 12\n";
629 output_highlight($args{'parameters'}{$parameter});
631 foreach $section (@{$args{'sectionlist'}}) {
632 print ".SH \"" . uc($section) . "\"\n";
633 output_highlight($args{'sections'}{$section});
636 if ($args{'bugsto'}) {
637 print ".SH \"REPORTING BUGS\"\n";
638 print "Report bugs to <". $args{'bugsto'} . ">.\n";
641 if ($args{'copyright'}) {
642 print ".SH COPYRIGHT\n";
643 print "Copyright \\(co ". $args{'copyright'} . ".\n";
644 if ($args{'verbatimcopying'}) {
645 print ".br\n";
646 print "Permission is granted to make and distribute verbatim copies of this\n";
647 print "manual provided the copyright notice and this permission notice are\n";
648 print "preserved on all copies.\n";
652 if ($args{'seeinfo'}) {
653 print ".SH \"SEE ALSO\"\n";
654 print "The full documentation for\n";
655 print ".B " . $args{'module'} . "\n";
656 print "is maintained as a Texinfo manual. If the\n";
657 print ".B info\n";
658 print "and\n";
659 print ".B " . $args{'module'} . "\n";
660 print "programs are properly installed at your site, the command\n";
661 print ".IP\n";
662 print ".B info " . $args{'seeinfo'} . "\n";
663 print ".PP\n";
664 print "should give you access to the complete manual.\n";
668 sub output_listfunc {
669 my %args = %{$_[0]};
670 print $args{'function'} . "\n";
674 # output in text
675 sub output_text {
676 my %args = %{$_[0]};
677 my ($parameter, $section);
679 print "Function = ".$args{'function'}."\n";
680 print " return type: ".$args{'functiontype'}."\n\n";
681 foreach $parameter (@{$args{'parameterlist'}}) {
682 print " ".$args{'parametertypes'}{$parameter}." ".$parameter."\n";
683 print " -> ".$args{'parameters'}{$parameter}."\n";
685 foreach $section (@{$args{'sectionlist'}}) {
686 print " $section:\n";
687 print " -> ";
688 output_highlight($args{'sections'}{$section});
693 # generic output function - calls the right one based
694 # on current output mode.
695 sub output_function {
696 # output_html(@_);
697 eval "output_".$output_mode."(\@_);";
702 # takes a function prototype and spits out all the details
703 # stored in the global arrays/hsahes.
704 sub dump_function {
705 my $prototype = shift @_;
707 if ($prototype =~ m/^()([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
708 $prototype =~ m/^(\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
709 $prototype =~ m/^(\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
710 $prototype =~ m/^(\w+\s+\w+)\s+([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/ ||
711 $prototype =~ m/^(\w+\s+\w+\s*\*)\s*([a-zA-Z0-9_~:]+)\s*\(([^\)]*)\)/) {
712 $return_type = $1;
713 $function_name = $2;
714 $args = $3;
716 # print STDERR "ARGS = '$args'\n";
718 foreach $arg (split ',', $args) {
719 # strip leading/trailing spaces
720 $arg =~ s/^\s*//;
721 $arg =~ s/\s*$//;
722 # print STDERR "SCAN ARG: '$arg'\n";
723 @args = split('\s', $arg);
725 # print STDERR " -> @args\n";
726 $param = pop @args;
727 # print STDERR " -> @args\n";
728 if ($param =~ m/^(\*+)(.*)/) {
729 $param = $2;
730 push @args, $1;
732 if ($param =~ m/^(.*)(\[\])$/) {
733 $param = $1;
734 push @args, $2;
736 # print STDERR " :> @args\n";
737 $type = join " ", @args;
739 if ($parameters{$param} eq "" && $param != "void") {
740 $parameters{$param} = "-- undescribed --";
741 print STDERR "Warning($lineno): Function parameter '$param' not described in '$function_name'\n";
744 push @parameterlist, $param;
745 $parametertypes{$param} = $type;
747 # print STDERR "param = '$param', type = '$type'\n";
749 } else {
750 print STDERR "Error($lineno): cannot understand prototype: '$prototype'\n";
751 return;
754 if ($function_only==0 || defined($function_table{$function_name})) {
755 output_function({'function' => $function_name,
756 'module' => $modulename,
757 'sourceversion' => $sourceversion,
758 'include' => $include,
759 'includefuncprefix' => $includefuncprefix,
760 'bugsto' => $bugsto,
761 'copyright' => $copyright,
762 'verbatimcopying' => $verbatimcopying,
763 'seeinfo' => $seeinfo,
764 'functiontype' => $return_type,
765 'parameterlist' => \@parameterlist,
766 'parameters' => \%parameters,
767 'parametertypes' => \%parametertypes,
768 'sectionlist' => \@sectionlist,
769 'sections' => \%sections,
770 'purpose' => $function_purpose
775 ######################################################################
776 # main
777 # states
778 # 0 - normal code
779 # 1 - looking for function name
780 # 2 - scanning field start.
781 # 3 - scanning prototype.
782 $state = 0;
783 $section = "";
785 $doc_special = "\@\%\$\#";
787 $doc_start = "^/\\*\\*\$";
788 $doc_end = "\\*/";
789 $doc_com = "\\s*\\*\\s*";
790 $doc_func = $doc_com."(\\w+):?";
791 $doc_sect = $doc_com."([".$doc_special."[:upper:]][\\w ]+):\\s*(.*)";
792 $doc_content = $doc_com."(.*)";
794 %constants = ();
795 %parameters = ();
796 @parameterlist = ();
797 %sections = ();
798 @sectionlist = ();
800 $contents = "";
801 $section_default = "Description"; # default section
802 $section = $section_default;
804 $lineno = 0;
805 foreach $file (@ARGV) {
806 if (!open(IN,"<$file")) {
807 print STDERR "Error: Cannot open file $file\n";
808 next;
810 while (<IN>) {
811 $lineno++;
813 if ($state == 0) {
814 if (/$doc_start/o) {
815 $state = 1; # next line is always the function name
817 } elsif ($state == 1) { # this line is the function name (always)
818 if (/$doc_func/o) {
819 $function = $1;
820 $state = 2;
821 if (/-\s*(.*)/) {
822 $function_purpose = $1;
823 } else {
824 $function_purpose = "";
826 if ($verbose) {
827 print STDERR "Info($lineno): Scanning doc for $function\n";
829 } else {
830 print STDERR "WARN($lineno): Cannot understand $_ on line $lineno",
831 " - I thought it was a doc line\n";
832 $state = 0;
834 } elsif ($state == 2) { # look for head: lines, and include content
835 if (/$doc_sect/o) {
836 $newsection = $1;
837 $newcontents = $2;
839 if ($contents ne "") {
840 dump_section($section, $contents);
841 $section = $section_default;
844 $contents = $newcontents;
845 if ($contents ne "") {
846 $contents .= "\n";
848 $section = $newsection;
849 } elsif (/$doc_end/) {
851 if ($contents ne "") {
852 dump_section($section, $contents);
853 $section = $section_default;
854 $contents = "";
857 # print STDERR "end of doc comment, looking for prototype\n";
858 $prototype = "";
859 $state = 3;
860 } elsif (/$doc_content/) {
861 # miguel-style comment kludge, look for blank lines after
862 # @parameter line to signify start of description
863 if ($1 eq "" && $section =~ m/^@/) {
864 dump_section($section, $contents);
865 $section = $section_default;
866 $contents = "";
867 } else {
868 $contents .= $1."\n";
870 } else {
871 # i dont know - bad line? ignore.
872 print STDERR "WARNING($lineno): bad line: $_";
874 } elsif ($state == 3) { # scanning for function { (end of prototype)
875 if (m#\s*/\*\s+MACDOC\s*#io) {
876 # do nothing
878 elsif (/([^\{]*)/) {
879 $prototype .= $1;
881 if (/\{/) {
882 $prototype =~ s@/\*.*?\*/@@gos; # strip comments.
883 $prototype =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
884 $prototype =~ s@^ +@@gos; # strip leading spaces
885 dump_function($prototype);
887 $function = "";
888 %constants = ();
889 %parameters = ();
890 %parametertypes = ();
891 @parameterlist = ();
892 %sections = ();
893 @sectionlist = ();
894 $prototype = "";
896 $state = 0;