#
eval 'exec perl $0 $*'
    if 0;

$method = 'symbol_';

$in = shift;

if ($in eq "-method") {
    $method = shift;
    $symbol = f77symbol($method, shift);
    print "$symbol\n";
}
else {
    $out = shift;

    open(IN,"<$in");
    open(OUT,">$out");

    while(<IN>) {
        if (/\# *define F77_([A-Z]+[A-Z0-9]+)/) {
            $f77name = $1;
            $cname = f77symbol($method, $f77name);
            printf OUT "#define F77_%s %s\n", $f77name, $cname;
        }
        else {
            printf OUT "%s", $_;
        }
    }
}

sub f77symbol {
    my $method = shift;
    my $f77name = shift;
    my $cname;
    if ($method eq "symbol_") {
        $cname = lc($f77name);
        $cname = "${cname}_";
    }
    elsif ($method eq "symbol") {
        $cname = lc($f77name);
    }
    elsif ($method eq "SYMBOL") {
        $cname = uc($f77name);
    }
    elsif ($method eq "SYMBOL_") {
        $cname = uc($f77name);
        $cname = "${cname}_";
    }
    return $cname;
}
