1 diff --git a/src/src/exigrep.src b/src/src/exigrep.src
2 index 0950b58..9e0ced3 100644
3 --- a/src/src/exigrep.src
4 +++ b/src/src/exigrep.src
5 @@ -124,6 +124,60 @@ elsif ( ($invert && (($insensitive && !/$pattern/io) || !/$pattern/o)) ||
9 +# Rotated log files are frequently compressed and there are a variety of
10 +# formats it could be compressed with. Rather than use just one that is
11 +# detected and hardcoded at Exim compile time, detect and use what the
12 +# logfile is compressed with on the fly.
14 +# List of known compression extensions and their associated commands:
16 + gz => { cmd => 'zcat', args => '' },
17 + bz2 => { cmd => 'bzcat', args => '' },
18 + xz => { cmd => 'xzcat', args => '' },
19 + lzma => { cmd => 'lzma', args => '-dc' }
23 +sub detect_compressor_bin
26 + my $c = $compressors->{$ext}->{cmd};
27 + $compressors->{$ext}->{bin} = `which $c 2>/dev/null`;
28 + chomp($compressors->{$ext}->{bin});
31 +sub detect_compressor_capable
33 + my $filename = shift();
34 + map { &detect_compressor_bin($_) } keys %$compressors
38 + unless (grep {$filename =~ /\.(?:$_)$/} keys %$compressors);
39 + # Loop through them, figure out which one it detected,
40 + # and build the commandline.
41 + my $cmdline = undef;
42 + foreach my $ext (keys %$compressors)
44 + if ($filename =~ /\.(?:$ext)$/)
47 + # 1) Better to just print the error and return...
48 + if ($compressors->{$ext}->{bin} eq '')
50 + warn("Didn't find $ext decompressor for $filename\n");
53 + # 2) ...or just return undef that will result in no output
54 + $cmdline = ($compressors->{$ext}->{bin} eq '') ?
56 + $compressors->{$ext}->{bin} ." ".
57 + $compressors->{$ext}->{args};
64 # The main program. Extract the pattern and make sure any relevant characters
65 # are quoted if the -l flag is given. The -t flag gives a time-on-queue value
66 @@ -154,6 +208,11 @@ if (@ARGV)
67 open(LOG, "ZCAT_COMMAND $filename |") ||
68 die "Unable to zcat $filename: $!\n";
70 + elsif (my $cmdline = &detect_compressor_capable($filename))
72 + open(LOG, "$cmdline $filename |") ||
73 + die "Unable to decompress $filename: $!\n";
77 open(LOG, "<$filename") || die "Unable to open $filename: $!\n";