#!/usr/local/bin/perl

# Copyright (c) 1995 Matthew Flatt

# Find out what common functions should be created

require "parse.pl";
require "common.pl";

$threshold = 5;

%common = ();
$counter = 0;

print "// generated by xctocmn\n";
print "@INCLUDE wxscomon.xci\n";
print "@COMMON\n";

while (($file = shift(@ARGV)) ne undef) {

    if ($file =~ s/.xc$//) {
    } else {
	print STDERR "Bad extension \"$file\".\n";
	exit 1;
    }
    
    if (!open(IN, "$file.xc")) {
	print STDERR "Couldn't open \"${file}.xc\"\n";
	exit 1;
    }

    $thisfile = "$file.xc";
    &ReadFile();

    close(IN);
}

print "@END\n";

exit(0);

while (@pair = each(%common)) {
    ($name, $count) = @pair;
    if ($count >= $threshold) {
	print "$name $count\n";
    }
}

exit(0);

sub DoPrintClass 
{
    return if ($testfile);

    foreach $function (@functions) {
	&ReadFields($function);
	
	$badflag = 0;
	$name = &MakeCommonName();
	if (!$badflag) {
	    $common{$name} += 1;
	    if ($common{$name} == $threshold) {
		$counter += 1;
		print "@ \"f-${counter}\" : ${returntype} F${counter}(";
		$comma = 0;
		foreach $type (@paramtypes) {
		    if (!$comma) {
			$comma = 1;
		    } else {
			print ", ";
		    }
		    print $type;
		}
		print ")\n";
	    }
	}
    }
}

sub IgnoreLine
{
}

sub PrintHeader
{
}

sub PrintDefine
{
}
