basic escaping

This commit is contained in:
Ward Wouts 2003-01-23 14:26:11 +00:00
parent 6ae908b4e6
commit edf5502782

View file

@ -26,7 +26,7 @@
use Digest::MD5; use Digest::MD5;
use Getopt::Std; use Getopt::Std;
getopts('s'); getopts('es');
opendir(DIR, ".") or die "can't open . $!"; opendir(DIR, ".") or die "can't open . $!";
while (defined($file = readdir(DIR))) { while (defined($file = readdir(DIR))) {
@ -40,6 +40,8 @@ foreach (@filelist) {
} }
} }
$start = $opt_s ? 1 : 0;
foreach $size (keys %sizes) { foreach $size (keys %sizes) {
if (@{$sizes{$size}} > 1) { if (@{$sizes{$size}} > 1) {
%md5s = (); %md5s = ();
@ -47,16 +49,13 @@ foreach $size (keys %sizes) {
push @{$md5s{&calc_md5($_)}}, $_; push @{$md5s{&calc_md5($_)}}, $_;
} }
foreach $key (keys %md5s) { foreach $key (keys %md5s) {
if ((@{$md5s{$key}} > 1) and !$opt_s ) { if ( @{$md5s{$key}} > 1 ) {
foreach (@{$md5s{$key}}) { print "$_ "; }
print "\n";
}
elsif ((@{$md5s{$key}} > 1) and $opt_s ) {
@files = sort @{$md5s{$key}}; @files = sort @{$md5s{$key}};
for $i (1 .. $#files) { for $i ($start .. $#files) {
chomp $files[$i]; chomp $files[$i];
print "$files[$i]\n"; &output("$files[$i]\n");
} }
unless($opt_s) { print "\n"; }
} }
} }
} }
@ -85,3 +84,17 @@ sub calc_md5($) {
close(FILE); close(FILE);
return $digest; return $digest;
} }
# escape output if necessary
sub output($) {
my $string = shift;
if ($opt_e) {
$string =~ s/\\/\\\\/g;
$string =~ s/ /\\ /g;
$string =~ s/'/\\'/g;
$string =~ s/"/\\"/g;
print "$string";
} else {
print "$string";
}
}