gen-eem.pl 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/perl
  2. use strict;
  3. if (scalar(@ARGV) != 1) {
  4. print STDERR "usage: gen-eem.pl infile\n";
  5. exit(1);
  6. }
  7. my $infile = $ARGV[0];
  8. if (!-f $infile) {
  9. print STDERR "File $infile does not exist.\n";
  10. exit(1);
  11. }
  12. unless (open(IN, $infile)) {
  13. print STDERR "Failed to open $infile for reading: $!\n";
  14. exit(1);
  15. }
  16. my $outfile = $infile;
  17. $outfile =~ s/\.in$//;
  18. my @contents = <IN>;
  19. close(IN);
  20. unless (open(OUT, ">$outfile")) {
  21. print STDERR "Failed to open $outfile for writing: $!\n";
  22. exit(1);
  23. }
  24. my $action = 1;
  25. foreach my $line (@contents) {
  26. if ($line =~ /^#/) {
  27. $action = 1;
  28. $line =~ s/^#//;
  29. print OUT $line;
  30. } elsif ($line =~ /^!/) {
  31. print OUT $line;
  32. } elsif ($line =~ /^\@/) {
  33. $line =~ s/^\@//;
  34. print OUT $line;
  35. } else {
  36. my $act = sprintf(" action %03d ", $action++);
  37. print OUT $act . $line;
  38. }
  39. }
  40. close(OUT);