make-examples.pl 911 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/perl -w
  2. foreach $path (@ARGV) {
  3. $writing = 0;
  4. if (!open(IN, $path)) {
  5. print "trying to open $path: $!\n";
  6. next;
  7. }
  8. while ($line = <IN>) {
  9. if ($line =~ /EXAMPLE (\w*) ([\w\-\.]*)/) {
  10. $command = $1;
  11. $filename = $2 . ".example";
  12. if ($command eq 'START') {
  13. if ($writing == 0) {
  14. if (!open(OUT, ">>$filename")) {
  15. print "trying to write to $filename: $!\n";
  16. } else {
  17. print "$path: writing to $filename\n";
  18. $writing = 1;
  19. }
  20. } else {
  21. print "$path: got $line while already writing!\n";
  22. }
  23. }
  24. if ($command eq 'STOP') {
  25. if ($writing == 1) {
  26. close(OUT);
  27. $writing = 0;
  28. } else {
  29. chomp($line);
  30. die "$path line $.: got $line when not writing!\n";
  31. }
  32. }
  33. } else {
  34. if ($writing && $line !~ /SKIPLINE/) {
  35. print OUT $line;
  36. }
  37. }
  38. }
  39. if ($writing) {
  40. close(OUT);
  41. }
  42. close(IN);
  43. }