#!/usr/bin/perl $ftxt = "ipercent_val"; $ctxt = $ftxt . "__"; $myname = $0; @names = (); $count = 0; while ($ARGV[0] =~ /^-/) { $opt .= " $ARGV[0]"; if ($ARGV[0] eq "-o") { shift; $opt .= " $ARGV[0]"; } shift; } if ("$opt" eq " -1") {&phase1;} elsif ("$opt" eq " -2") {&phase2;} else { $src = $ARGV[0]; $tmp = $src; $tmp =~ s:.*/::; $tmp =~ s:f$:c:; $tmp = "/tmp/$tmp"; system "$myname -1 < $src | f2c -f | $myname -2 > $tmp"; system "cc -c $opt $tmp"; unlink $tmp; } exit 0; sub phase1 { while (<>) { s/%[Vv][Aa][Ll]/$ftxt/g; print $_; } } sub phase2 { while (<>) { if (/(\s*)(\w*)(\s*=\s*)($ctxt)/) { s/$ctxt\(&/\(/; $names[$count] = $2; $count++; print $_; } else { if ($count && /(\s*)(\w*)_\(/) { &repl ($_); } else { print $_; } } } } sub repl { $l = shift; while ($l) { foreach (@names) { $l =~ s/&$_/$_/g; } print $l; if ($l =~ /\);/) { @names = (); $count = 0; return; } $l = <>; } }