#! /usr/pkg/gnu/bin/perl

require "getopts.pl";		# including this to handle the command
				# line args

# acts as the driver for the translation from rcc output to mulsim
# acceptable input 

#	check the command line input, arg should be file.mas

&USAGE if $#ARGV < 0;

&Getopts('f:o:p:v');
$infile = $opt_f;
$outfile = $opt_o;
$mcc_path = $opt_p;
$verbose = $opt_v;

&USAGE if ($infile eq "");
&USAGE if ($outfile eq "");
&USAGE if ($mcc_path eq "");

system("rm $outfile") if -e $outfile;

@pre_proc_calls = ("pre_rcc_print_str.prl -f $infile -o $outfile -p $mcc_path",
		   );		

foreach $index (0 .. $#pre_proc_calls) {
    printf("\trunning:\t$pre_proc_calls[$index]\n") if $verbose;
    $comm = $mcc_path . '/lib/' . $pre_proc_calls[$index];
    if ($ret_val = system("$comm")) { exit($ret_val) };
    printf("\tcompleted:\t$pre_proc_calls[$index]\n") if $verbose;
}

open (INF, ">> $outfile");
print INF "/* $0 has run */\n";
close (INF);

sub USAGE {
    print STDERR "usage: $0 -f infile -o outfile -p path [-v]\n\t\t-v\tverbose\n";
    print STDERR "Bye.\n";
    exit (12);
}
