#!/usr/bin/perl use strict; if (scalar(@ARGV) != 1) { print STDERR "usage: gen-eem.pl infile\n"; exit(1); } my $infile = $ARGV[0]; if (!-f $infile) { print STDERR "File $infile does not exist.\n"; exit(1); } unless (open(IN, $infile)) { print STDERR "Failed to open $infile for reading: $!\n"; exit(1); } my $outfile = $infile; $outfile =~ s/\.in$//; my @contents = ; close(IN); unless (open(OUT, ">$outfile")) { print STDERR "Failed to open $outfile for writing: $!\n"; exit(1); } my $action = 1; foreach my $line (@contents) { if ($line =~ /^#/) { $action = 1; $line =~ s/^#//; print OUT $line; } elsif ($line =~ /^!/) { print OUT $line; } elsif ($line =~ /^\@/) { $line =~ s/^\@//; print OUT $line; } else { my $act = sprintf(" action %03d ", $action++); print OUT $act . $line; } } close(OUT);