#!/usr/local/bin/perl # ACESrcPP # A dimensional preprocessor thingy for the DAGH library # Paul Walker , spring 1996 # Idea is you have a file named # GridFunction.%X%.h # A command line directive in that file of the form # -v X=1,2,3 # And it makes 3 files, GridFunction1.h GridFunction2.h, and GridFunction3.h # with .%X% replaced with 1,2,or 3 in each. Note how the dot is replaced. # Also you can do # /*% X == 1 { %*/ # code for X = 1 only # /*% } %*/ # These must be alone on a line. I know these are a little # arduous, but easy to parse! # Usage: DAGHSrcPP -i file -v Var [-o outdir] require "getopts.pl"; # Get input options &Getopts("i:o:v:"); $opt_v || &usage; $file = $opt_i || &usage; $outdir = $opt_o || "."; if ($file =~ m/%([^%])%/) { $myvar = $1; } $vals = $opt_v; $vals =~ s:^.*=::; $vals =~ s:\s::g; @vals = split(',',$vals); foreach $val (@vals) { open (IN, "<$file"); $outf = $file; $outf =~ s/\.%$myvar%/$val/; open (OUT, ">$outdir/$outf") || die "$outdir/$outf"; printf ("Creating $outdir/$outf\n"); $printing = 1; while () { if ($printing) { if ($_ =~ m:/\*%\s*$myvar\s*==\s*(\d)\s*\{\s*%\*/:) { $printing = 0 unless ($1 =~ m/$val/) } if ($_ =~ m:/\*%\s*$myvar\s*!=\s*(\d)\s*\{\s*%\*/:) { $printing = 0 if ($1 =~ m/$val/) } s/%$myvar%/$val/g; print OUT if ($printing); } else { if ($_ =~ m:/\*%\s*\}\s*%\*/:) { $printing = 1; } } } } sub usage { print <