#!/usr/local/bin/perl
#
#       generatefile
#
# this program creates a file from a ".gen" file by copying
# the ".gen" file line by line, except where it sees a line
# beginning with "#EVAL:" in which case it evaluates the 
# contents of the line and puts that in the generated file. 
#
# In a nutshell:
#     perl -pe 's/^\#EVAL:(.*\S).*$/eval $1/e; ' <file.gen >file
#

sub filegen {
	local($file) = @_;
	open(SRC,$file.".gen") || die "cant open ${file}.gen file";
	open(OUT,">$file") || die "cant open $file file";
	while(<SRC>) {
		if(m/^\#EVAL\:(.*)/) {
			print OUT (eval($1)) ;
		}
		else {
			print OUT;
		}
	}
	close(OUT);
	close(SRC);
}
$file = shift(@ARGV);
$file || die "usage:  generatefile <filename>\n";
&filegen($file);
