home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / perl / scripts-convex / convex / spuedit < prev    next >
Encoding:
Text File  |  1990-10-12  |  1.1 KB  |  48 lines

  1. #!/usr/bin/perl
  2. #
  3. # spuedit -- edit spu file from JP, keeping a backup
  4. # tom christiansen
  5.  
  6. die "usage: $0 spufile ...\n"     if $#ARGV < 0;
  7.  
  8. die "$0: Not superuser\n"     if $>;
  9.  
  10. $editor = $ENV{'VISUAL'} || $ENV{'EDITOR'} || 'vi';
  11. $tmp    = "/tmp/spuedit.$$";
  12. $status = 0;
  13. $| = 1;
  14.  
  15. for $file (@ARGV) {
  16.     system("/usr/convex/spu -r $file > $tmp\n") && exit(1);
  17.  
  18.     ($otime = (stat($tmp))[9]) 
  19.     || die "$0: Can't stat $tmp: $!\n";
  20.  
  21.     system($editor,$tmp) 
  22.     && die "$0: Command \"$editor $tmp\" failed\n";
  23.  
  24.     ($ntime = (stat($tmp))[9]) 
  25.     || die "$0: Can't stat $tmp: $!\n";
  26.  
  27.     if ($ntime > $otime) {
  28.     print "copying file..";
  29.     $cmd = "cp $file $file.bak";
  30.     chop($output = `/usr/convex/spucmd $cmd 2>&1`);
  31.     $status |= $?;
  32.     if (($? >>= 8) || $output ne "+ $cmd ") {
  33.         warn "spucmd \"$cmd\" failed:\n\t(status $?) \"$output\"\n";
  34.         warn "temporary file saved to $tmp\n";
  35.     } else {
  36.         print "..";
  37.         $status |= system("/usr/convex/spu -w $file < $tmp\n");
  38.         print "done\n";
  39.     }
  40.     } else {
  41.     warn "$0: Temporary file $tmp unmodified\n";
  42.     $status |= 1;
  43.     } 
  44.     unlink $tmp;
  45. }
  46.  
  47. exit $status;
  48.