copy.pl 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/local/bin/perl
  2. use Fcntl;
  3. # copy.pl
  4. # Perl script 'copy' comment. On Windows the built in "copy" command also
  5. # copies timestamps: this messes up Makefile dependencies.
  6. my $stripcr = 0;
  7. my $arg;
  8. foreach $arg (@ARGV) {
  9. if ($arg eq "-stripcr")
  10. {
  11. $stripcr = 1;
  12. next;
  13. }
  14. $arg =~ s|\\|/|g; # compensate for bug/feature in cygwin glob...
  15. foreach (glob $arg)
  16. {
  17. push @filelist, $_;
  18. }
  19. }
  20. $fnum = @filelist;
  21. if ($fnum <= 1)
  22. {
  23. die "Need at least two filenames";
  24. }
  25. $dest = pop @filelist;
  26. if ($fnum > 2 && ! -d $dest)
  27. {
  28. die "Destination must be a directory";
  29. }
  30. foreach (@filelist)
  31. {
  32. if (-d $dest)
  33. {
  34. $dfile = $_;
  35. $dfile =~ s|^.*[/\\]([^/\\]*)$|$1|;
  36. $dfile = "$dest/$dfile";
  37. }
  38. else
  39. {
  40. $dfile = $dest;
  41. }
  42. sysopen(IN, $_, O_RDONLY|O_BINARY) || die "Can't Open $_";
  43. sysopen(OUT, $dfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY)
  44. || die "Can't Open $dfile";
  45. while (sysread IN, $buf, 10240)
  46. {
  47. if ($stripcr)
  48. {
  49. $buf =~ tr/\015//d;
  50. }
  51. syswrite(OUT, $buf, length($buf));
  52. }
  53. close(IN);
  54. close(OUT);
  55. print "Copying: $_ to $dfile\n";
  56. }