#!/usr/bin/perl -w
# John Lapeyre Sat Mar 21 18:17:54 MST 1998
# look at c code in src dir
# and print out prototypes
# not perfect , but works ok.
use Cwd;

sub getdir;
sub deb;

$tdir = cwd();

#@dirs = ( '../math' );
#@dirs = ( '../math', '../appl', '../unix', '../graphics');
@dirs = ( "math", "appl", 'unix', 'graphics', 'main');


foreach $dir (@dirs) {
    chdir("$tdir/../src/$dir");
    $curdir = cwd();
    chomp $curdir;
    deb "\n>>>>>>>Chdir to $curdir\n";
    get_protos($curdir);
}




sub get_protos {
    my $curdir = shift;
    my @cfiles = grep /\.c$/, getdir($curdir) or die "Couldn't read dir";
    my @protos = ();
    my $file;
    foreach $file (@cfiles) {
	open IH, "<$file" or die "Can't open $file";
#	deb "Opening $file";
	my $line;
	my ($funcname) =  $file =~ /(.)\.c$/;
	while(1) {
	    if (eof(IH)) {
#		deb "Failed on $file";
		last;
	    }
	    $line = <IH>;
#	    if ($line =~ /$funcname\(/) {
	    if ($line =~ /^(int|double|void|long|float|char).+\(/) {
#		next if $line =~ /F77/;
		push @protos, $line;
#		last;
	    }
	}
	close IH;
    }
    foreach (@protos) {
	print;
    }
}

#-------------------------------------------

sub deb {
#    print STDERR "$_[0]\n";
    print "$_[0]\n";
}


sub getdir {
    my $dir = shift;
    local(*HAND);
    opendir HAND,"$dir" or die "Can't open $dir";
    my @files = grep !/^\.\.?$/, readdir HAND;
    closedir HAND;
    return @files;
}


