Scripts: Add lz4 support to xzgrep and xzdiff.

This commit is contained in:
Lasse Collin 2024-02-13 17:00:17 +02:00
parent de55485cb2
commit 109f1913d4
4 changed files with 19 additions and 10 deletions

View File

@ -5,7 +5,7 @@
.\" .\"
.\" (Note that this file is not based on gzip's zdiff.1.) .\" (Note that this file is not based on gzip's zdiff.1.)
.\" .\"
.TH XZDIFF 1 "2024-02-12" "Tukaani" "XZ Utils" .TH XZDIFF 1 "2024-02-13" "Tukaani" "XZ Utils"
.SH NAME .SH NAME
xzcmp, xzdiff, lzcmp, lzdiff \- compare compressed files xzcmp, xzdiff, lzcmp, lzdiff \- compare compressed files
. .
@ -48,8 +48,9 @@ are specified, they can be uncompressed files or files in formats that
.BR gzip (1), .BR gzip (1),
.BR bzip2 (1), .BR bzip2 (1),
.BR lzop (1), .BR lzop (1),
.BR zstd (1),
or or
.BR zstd (1) .BR lz4 (1)
can decompress. can decompress.
The required decompression commands are determined from The required decompression commands are determined from
the filename suffixes of the filename suffixes of
@ -91,4 +92,5 @@ is used.
.BR gzip (1), .BR gzip (1),
.BR bzip2 (1), .BR bzip2 (1),
.BR lzop (1), .BR lzop (1),
.BR zstd (1) .BR zstd (1),
.BR lz4 (1)

View File

@ -84,13 +84,15 @@ if test $# -eq 1; then
xz1=lzop;; xz1=lzop;;
*[-.]zst | *.tzst) *[-.]zst | *.tzst)
xz1='zstd -q';; xz1='zstd -q';;
*[-.]lz4)
xz1=lz4;;
*) *)
printf '%s\n' "$0: $1: Unknown compressed file name suffix" >&2 printf '%s\n' "$0: $1: Unknown compressed file name suffix" >&2
exit 2;; exit 2;;
esac esac
case $1 in case $1 in
*[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *[-.]lz | *[-.]lzo | *[-.]zst) *[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *[-.]lz | *[-.]lzo | *[-.]zst | *[-.]lz4)
FILE=`expr "X$1" : 'X\(.*\)[-.][abglmostxzZ2]*$'`;; FILE=`expr "X$1" : 'X\(.*\)[-.][abglmostxzZ24]*$'`;;
*.t[abglx]z) *.t[abglx]z)
FILE=`expr "X$1" : 'X\(.*[-.]t\)[abglx]z$'`ar;; FILE=`expr "X$1" : 'X\(.*[-.]t\)[abglx]z$'`ar;;
*.tbz2) *.tbz2)
@ -110,17 +112,19 @@ elif test $# -eq 2; then
*[-.][zZ] | *_z | *[-.]gz | *.t[ag]z) xz1=gzip;; *[-.][zZ] | *_z | *[-.]gz | *.t[ag]z) xz1=gzip;;
*[-.]lzo | *.tzo) xz1=lzop;; *[-.]lzo | *.tzo) xz1=lzop;;
*[-.]zst | *.tzst) xz1='zstd -q';; *[-.]zst | *.tzst) xz1='zstd -q';;
*[-.]lz4) xz1=lz4;;
esac esac
case $2 in case $2 in
*[-.]bz2 | *.tbz | *.tbz2) xz2=bzip2;; *[-.]bz2 | *.tbz | *.tbz2) xz2=bzip2;;
*[-.][zZ] | *_z | *[-.]gz | *.t[ag]z) xz2=gzip;; *[-.][zZ] | *_z | *[-.]gz | *.t[ag]z) xz2=gzip;;
*[-.]lzo | *.tzo) xz2=lzop;; *[-.]lzo | *.tzo) xz2=lzop;;
*[-.]zst | *.tzst) xz2='zstd -q';; *[-.]zst | *.tzst) xz2='zstd -q';;
*[-.]lz4) xz2=lz4;;
esac esac
case $1 in case $1 in
*[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *[-.]lz | *.t[abglx]z | *.tbz2 | *[-.]lzo | *.tzo | *[-.]zst | *.tzst | -) *[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *[-.]lz | *.t[abglx]z | *.tbz2 | *[-.]lzo | *.tzo | *[-.]zst | *.tzst | *[-.]lz4 | -)
case "$2" in case "$2" in
*[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *[-.]lz | *.t[abglx]z | *.tbz2 | *[-.]lzo | *.tzo | *[-.]zst | *.tzst | -) *[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *[-.]lz | *.t[abglx]z | *.tbz2 | *[-.]lzo | *.tzo | *[-.]zst | *.tzst | *[-.]lz4 | -)
if test "$1$2" = --; then if test "$1$2" = --; then
xz_status=$( xz_status=$(
exec 4>&1 exec 4>&1
@ -184,7 +188,7 @@ elif test $# -eq 2; then
esac;; esac;;
*) *)
case "$2" in case "$2" in
*[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *[-.]lz | *.t[abglx]z | *.tbz2 | *[-.]lzo | *.tzo | *[-.]zst | *.tzst | -) *[-.][zZ] | *_z | *[-.][gx]z | *[-.]bz2 | *[-.]lzma | *[-.]lz | *.t[abglx]z | *.tbz2 | *[-.]lzo | *.tzo | *[-.]zst | *.tzst | *[-.]lz4 | -)
xz_status=$( xz_status=$(
exec 4>&1 exec 4>&1
($xz2 -cdf -- "$2" 4>&-; echo $? >&4) 3>&- | ($xz2 -cdf -- "$2" 4>&-; echo $? >&4) 3>&- |

View File

@ -5,7 +5,7 @@
.\" .\"
.\" (Note that this file is not based on gzip's zgrep.1.) .\" (Note that this file is not based on gzip's zgrep.1.)
.\" .\"
.TH XZGREP 1 "2024-02-12" "Tukaani" "XZ Utils" .TH XZGREP 1 "2024-02-13" "Tukaani" "XZ Utils"
.SH NAME .SH NAME
xzgrep \- search possibly-compressed files for patterns xzgrep \- search possibly-compressed files for patterns
. .
@ -45,8 +45,9 @@ with a suffix supported by
.BR gzip (1), .BR gzip (1),
.BR bzip2 (1), .BR bzip2 (1),
.BR lzop (1), .BR lzop (1),
.BR zstd (1),
or or
.BR zstd (1) .BR lz4 (1)
will be decompressed; will be decompressed;
all other files are assumed to be uncompressed. all other files are assumed to be uncompressed.
.PP .PP
@ -139,4 +140,5 @@ or
.BR bzip2 (1), .BR bzip2 (1),
.BR lzop (1), .BR lzop (1),
.BR zstd (1), .BR zstd (1),
.BR lz4 (1),
.BR zgrep (1) .BR zgrep (1)

View File

@ -181,6 +181,7 @@ for i; do
*[-.]bz2 | *[-.]tbz | *.tbz2) uncompress="bzip2 -cdf";; *[-.]bz2 | *[-.]tbz | *.tbz2) uncompress="bzip2 -cdf";;
*[-.]lzo | *[-.]tzo) uncompress="lzop -cdf";; *[-.]lzo | *[-.]tzo) uncompress="lzop -cdf";;
*[-.]zst | *[-.]tzst) uncompress="zstd -cdfq";; # zstd needs -q. *[-.]zst | *[-.]tzst) uncompress="zstd -cdfq";; # zstd needs -q.
*[-.]lz4) uncompress="lz4 -cdf";;
*) uncompress="$xz -cdfqQ";; # -qQ to ignore warnings like unsupp. check. *) uncompress="$xz -cdfqQ";; # -qQ to ignore warnings like unsupp. check.
esac esac
# xz_status will hold the decompressor's exit status. # xz_status will hold the decompressor's exit status.