#!/s/std/bin/perl 

if(@ARGV != 2){
    print "usage: rename_conf.pl <input file> <machine name>\n";
    print "argv = " . @ARGV . "\n";
    exit(1);
}

$filename = $ARGV[0];
$machine_name = $ARGV[1];
$outfilename = $filename . ".rename";
@object_list = {};
@file_data = {};

open(data_file, "<$filename") || die "can't open file: " . $filename
. "\n";
open(out_file, ">$outfilename") || die "can't open file: " . $outfilename
. "\n";

while(<data_file>){
    @_ = split;

    #print "line: " . $_;
    push(@file_data, $_);

    if(/OBJECT ([a-zA-Z0-9_\-.]*)/){
        $obj_name = $1;
        push(@object_list, $obj_name);
        #print "OBJECT " . $1 . "\n";
    }
}

#  $extra_line = pop(@file_data);
#  print "extra: " . $extra_line;
foreach $out_line (@file_data){
    $_ = $out_line;
    if (/file:/) {
    }
    else {
        foreach $obj (@object_list){
            #print "OBJECT " . $obj . "\n";
            $new_name = $obj . "_" . $machine_name;   
            s/$obj\b/$new_name/;   #replace obj with newname 
        }
    }
    print $_;
    print out_file $_; 
}

close(data_file);
close(out_file);


    



