cvsuser     02/08/01 10:59:38

  Modified:    .        assemble.pl
  Log:
  - Allow assemble.pl to read from STDIN
  - Use the '-' symbol to indicate STDIN
  - Made invocation failures/usages behave more correctly
  - Minor refactorings in this code section
  
  Courtesy of Brian Ingerson <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.83      +14 -16    parrot/assemble.pl
  
  Index: assemble.pl
  ===================================================================
  RCS file: /cvs/public/parrot/assemble.pl,v
  retrieving revision 1.82
  retrieving revision 1.83
  diff -u -w -r1.82 -r1.83
  --- assemble.pl       18 Jul 2002 02:13:27 -0000      1.82
  +++ assemble.pl       1 Aug 2002 17:59:38 -0000       1.83
  @@ -1047,35 +1047,33 @@
   sub process_args {
     my ($args,$files) = @_;
   
  -  for (my $count = 0; $count < @ARGV; $count++) {
  -    my $arg = $ARGV[$count];
  -
  +  while (my $arg = shift @ARGV) {
       if($arg =~ /^-(c|-checksyntax)$/) { $args->{-c} = 1; }
       elsif($arg =~ /^-E$/)             { $args->{-E} = 1; }
  -    elsif($arg =~ /^-(o|-output)$/)   { $args->{-o} = $ARGV[++$count]; }
  -    elsif($arg =~ /^-(h|-help)$/)     { Usage(); }
  -    else {
  -      push @$files,$arg;
  -    }
  +    elsif($arg =~ /^-(o|-output)$/)   { $args->{-o} = shift @ARGV; }
  +    elsif($arg =~ /^-(h|-help)$/)     { Usage(); exit 0; }
  +    elsif($arg =~ /^-./)              { Fail("Invalid option '$arg'\n"); }
  +    else                              { push @$files,$arg; }
     }
  -  unless(@$files) {
  -    print STDERR "No files to process.\n";
  -    Usage();
  +  Fail("No files to process.\n") unless(@$files);
  +  Fail("File '$_' does not exist.\n") for grep { not (-e or /^-$/) } @$files;
     }
  -  for(@$files) {
  -    next if -e $_;
  -    print STDERR "File '$_' does not exist.\n";
  +
  +sub Fail {
  +    print STDERR @_;
       Usage();
  -  }
  +    exit 1;
   }
   
   sub Usage {
     print <<"  _EOF_";
  +
   usage: $0 [options] file [file...]
   
       -E              Preprocess input files and terminate processing
       -h,--help       Print this message
       -o,--output     Write file 
       -c,-checksyntax Check syntax only, do not generate bytecode
  +
     _EOF_
   }
  
  
  


Reply via email to