#!/usr/local/bin/perl
#!/usr/local/bin/perl -w
#
# $Source: /tmp_mnt/net/dworshak2/users/student/evans911/prog/cs481/src/RCS/pmerge.pl,v $
# $Author: evans911 $
# Current revision: $Revision: 0.3 $
# Last modified: $Date: 1996/10/29 01:33:01 $
# State of current revision: $State: Exp $
# Currently locked by: $Locker:  $
#
# Description: Merges several perl files into one.
#              
# Author: Jason Evans
#
# $Log: pmerge.pl,v $
# Revision 0.3  1996/10/29 01:33:01  evans911
# Modified perl path to include name of perl.
#
# Revision 0.2  1996/10/24 16:32:39  evans911
# Usage statement had arguments backwards.  Fixed.
#
# Revision 0.1  1996/10/24 16:30:09  evans911
# Initial revision.
#
#

# set the output file name
if ($#ARGV == 1)
{
    $perlpath = $ARGV[0];
    print "Using $perlpath as perl.\n";
    $outfile = $ARGV[1];
    print "Outputting to $outfile.\n";
}
else
{
    print STDERR "$0 usage: $0 <perl_location> <outfile>\n";
    exit(-1);
}

# first file should be the one with the main code
@files = ("cca.pl",
	  "gen_report.pl",
	  "process_c_file.pl",
	  "stack.pl",
	  "verify.pl",
	  "vg.pl",
	  "gen_image.pl",
	  "assign_position.pl",
	  "ps.pl",
	  );

(open(OUTFILE, ">$outfile")) ||
    die "$0: can't open \"$outfile\".";

# insert perl header
print OUTFILE "#!$perlpath\n";

foreach (@files)
{
    (open(INFILE, "$_")) ||
	die "$0: can't open \"$_\".";

    while (<INFILE>)
    {
	unless ($_ =~ /(^\s*1;\s*$|\s*require|^\s*\#|^\s*$)/)
#	unless ($_ =~ /(^\s*1;\s*$|\s*require|^\#)/)
	{
	    print OUTFILE $_;
	}
    }
    close INFILE;
}

system("/bin/chmod u+x $outfile");

print "Finished writing output to $outfile.\n";
