1160814Ssimon#!/usr/local/bin/perl 2160814Ssimon 3160814Ssimonuse Fcntl; 4160814Ssimon 5160814Ssimon 6160814Ssimon# copy.pl 7160814Ssimon 8160814Ssimon# Perl script 'copy' comment. On Windows the built in "copy" command also 9160814Ssimon# copies timestamps: this messes up Makefile dependencies. 10160814Ssimon 11194206Ssimonmy $stripcr = 0; 12194206Ssimon 13160814Ssimonmy $arg; 14160814Ssimon 15160814Ssimonforeach $arg (@ARGV) { 16194206Ssimon if ($arg eq "-stripcr") 17194206Ssimon { 18194206Ssimon $stripcr = 1; 19194206Ssimon next; 20194206Ssimon } 21160814Ssimon $arg =~ s|\\|/|g; # compensate for bug/feature in cygwin glob... 22326663Sjkim $arg = qq("$arg") if ($arg =~ /\s/); # compensate for bug in 5.10... 23326663Sjkim foreach (glob $arg) 24160814Ssimon { 25160814Ssimon push @filelist, $_; 26160814Ssimon } 27160814Ssimon} 28160814Ssimon 29160814Ssimon$fnum = @filelist; 30160814Ssimon 31160814Ssimonif ($fnum <= 1) 32160814Ssimon { 33160814Ssimon die "Need at least two filenames"; 34160814Ssimon } 35160814Ssimon 36160814Ssimon$dest = pop @filelist; 37160814Ssimon 38160814Ssimonif ($fnum > 2 && ! -d $dest) 39160814Ssimon { 40160814Ssimon die "Destination must be a directory"; 41160814Ssimon } 42160814Ssimon 43160814Ssimonforeach (@filelist) 44160814Ssimon { 45160814Ssimon if (-d $dest) 46160814Ssimon { 47160814Ssimon $dfile = $_; 48160814Ssimon $dfile =~ s|^.*[/\\]([^/\\]*)$|$1|; 49160814Ssimon $dfile = "$dest/$dfile"; 50160814Ssimon } 51160814Ssimon else 52160814Ssimon { 53160814Ssimon $dfile = $dest; 54160814Ssimon } 55160814Ssimon sysopen(IN, $_, O_RDONLY|O_BINARY) || die "Can't Open $_"; 56160814Ssimon sysopen(OUT, $dfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY) 57160814Ssimon || die "Can't Open $dfile"; 58160814Ssimon while (sysread IN, $buf, 10240) 59160814Ssimon { 60194206Ssimon if ($stripcr) 61194206Ssimon { 62194206Ssimon $buf =~ tr/\015//d; 63194206Ssimon } 64160814Ssimon syswrite(OUT, $buf, length($buf)); 65160814Ssimon } 66160814Ssimon close(IN); 67160814Ssimon close(OUT); 68160814Ssimon print "Copying: $_ to $dfile\n"; 69160814Ssimon } 70160814Ssimon 71160814Ssimon 72