#############################################################
#                                                           #
# ml401.pl
# DATE: 08/31/2004
# Xilinx Inc.
# Systems Engineering Group
#
#############################################################

# Correct V4 SVF file that was output from iMPACT

if ($#ARGV != 1){
  print "usage: ml401.pl svf_file_name.svf corrected_svf_file_name.svf\n";
  exit(1);
}

print "## Converting ML401 $ARGV[0] into $ARGV[1]\n";

open (INFILE, "$ARGV[0]") || die "Can't open file $ARGV[0]: $!\n";
open (OUTFILE, ">$ARGV[1]") || die "Can't open file $ARGV[1]: $!\n";

{
  local $/ = ''; # will read the entire file into $_ on the read operation
  $insvf = <INFILE>; 
}

close (INFILE) || die("Error Closing File: $ARGV[0] : $!");

$line1 = 'RUNTEST\s10000\sTCK;';
$line2 = '//\sLoading\sdevice\swith\sa\s`cfg_in`\sinstruction.\s';
$line3 = 'SIR\s10\sTDI\s\(03c5\)\s;';
$line4 = '// Loading device with a `cfg_in` instruction. *NEW SEQUENCE*';
$line5 = 'SIR 10 TDI (03c5) ;';
$line6 = 'RUNTEST 10000 TCK;';

$insvf =~ s/$line1\n$line2\n$line3/("$line4\n$line5\n$line6")/smex;

# Rewrite complete SVF file 
print OUTFILE $insvf;
close (OUTFILE) || die("Error Closing File: $ARGV[1] : $!");

print "\n## Modified SVF complete. \n\n";

exit(0);

