#!/usr/bin/perl
#------------------------------------------------------------
# protogen
# extracts documentation and function prototypes from perl
# modules
#------------------------------------------------------------
# $Id: protogen,v 1.2 1999/03/31 23:18:56 kiwi Exp $
#------------------------------------------------------------

open (PM, "find . -name '*.pm' -print |");
chomp (@pm = <PM>);
close (PM);

chomp ($cd = `pwd`);


foreach my $p (@pm)
{
	next if ($p =~ /\/perl/);
	next if -l $p;

	$className = $p;

	$className =~ s/^\./SW/g;

	open (FILE, $p);

	@fileLines = <FILE>;

	close (FILE);

	foreach $l (@fileLines)
	{
		$lastComment .= $l if ($l=~/^#/);

		if ($l =~ /^sub/)
		{
			chomp $l;
			($sub, $subName) = split(" ", $l, 2);
			push (@methods, "$className..$subName");

			$data .= "<a href=#top>Top</a>\n\n<a name=\"$className..$subName\">";
			$data .= "<i>$lastComment</i>\n\n";
			$data .= "<b>$subName</b>\n";
			$lastComment = "";
		}
		if ($l =~ /shift/ || $l =~ /\@_/)
		{
			$data .= $l;
		}
	}
}

$index = "";
foreach $m (@methods)
{
	$index .= "<a href=#$m>$m</a><br>";
}

print <<EOL;
<body bgcolor=#8080ff text=#000000 link=#202000 vlink=#300000>
<font face=Verdana,Arial size=2>
<a name=top>
This is a list of methods in every SmartWorker class, indexed by
class.  This file is automatically generated by the "protogen"
program, which attempts to generate function prototypes for Perl
subroutines.  It accomplishes this by extracting lines that are
subroutine headers, and then searching for subsequent lines that are
probably related to argument processing, such as "shift" or
direct references to the \@_ array.  Note that it doesn't check for
references to the \$_ variable, so these will not appear.
<p>
$index
</font>
<p>
<pre>
$data;
</pre>
</body>
EOL
;
