From 740a0f1807871740f8f3c4aeb9ca64626f26c416 Mon Sep 17 00:00:00 2001
From: Andreas Mohr <and@gmx.li>
Date: Sun, 27 Dec 2015 19:53:02 +0000
Subject: [PATCH] support lz4 compress format (#3523)
Signed-off-by: Andreas Mohr <and@gmx.li>
---
lib/util.c | 6 ++++++
lib/util.h | 1 +
misc/ext.d/archive.sh | 14 ++++++++++++++
misc/ext.d/text.sh.in | 7 +++++--
misc/filehighlight.ini | 2 +-
misc/mc.ext.in | 18 ++++++++++++++++++
misc/mc.menu.in | 5 ++++-
misc/mc.menu.sr.in | 5 ++++-
src/editor/edit.c | 1 +
src/vfs/extfs/helpers/iso9660.in | 1 +
src/vfs/extfs/helpers/lslR.in | 1 +
src/vfs/extfs/helpers/mailfs.in | 3 +++
src/vfs/extfs/helpers/patchfs.in | 9 +++++++--
src/vfs/extfs/helpers/sfs.ini | 2 ++
14 files changed, 68 insertions(+), 7 deletions(-)
diff --git a/lib/util.c b/lib/util.c
index 5fcfd7c..342c3dc 100644
a
|
b
|
get_compression_type (int fd, const char *name) |
864 | 864 | } |
865 | 865 | } |
866 | 866 | |
| 867 | /* LZ4 format - v1.5.0 - 0x184D2204 (little endian) */ |
| 868 | if (magic[0] == 0x04 && magic[1] == 0x22 && magic[2] == 0x4d && magic[3] == 0x18) |
| 869 | return COMPRESSION_LZ4; |
| 870 | |
867 | 871 | /* Support for LZMA (only utils format with magic in header). |
868 | 872 | * This is the default format of LZMA utils 4.32.1 and later. */ |
869 | 873 | |
… |
… |
decompress_extension (int type) |
904 | 908 | return "/ubz" VFS_PATH_URL_DELIMITER; |
905 | 909 | case COMPRESSION_BZIP2: |
906 | 910 | return "/ubz2" VFS_PATH_URL_DELIMITER; |
| 911 | case COMPRESSION_LZ4: |
| 912 | return "/ulz4" VFS_PATH_URL_DELIMITER; |
907 | 913 | case COMPRESSION_LZMA: |
908 | 914 | return "/ulzma" VFS_PATH_URL_DELIMITER; |
909 | 915 | case COMPRESSION_XZ: |
diff --git a/lib/util.h b/lib/util.h
index 9c972ed..1832c9e 100644
a
|
b
|
enum compression_type |
54 | 54 | COMPRESSION_GZIP, |
55 | 55 | COMPRESSION_BZIP, |
56 | 56 | COMPRESSION_BZIP2, |
| 57 | COMPRESSION_LZ4, |
57 | 58 | COMPRESSION_LZMA, |
58 | 59 | COMPRESSION_XZ |
59 | 60 | }; |
diff --git a/misc/ext.d/archive.sh b/misc/ext.d/archive.sh
index e141bf8..27d5116 100755
a
|
b
|
do_view_action() { |
23 | 23 | bzip) |
24 | 24 | bzip2 -dc "${MC_EXT_FILENAME}" 2>/dev/null |
25 | 25 | ;; |
| 26 | lz4) |
| 27 | lz4 -dc "${MC_EXT_FILENAME}" 2>/dev/null |
| 28 | ;; |
26 | 29 | lzma) |
27 | 30 | lzma -dc "${MC_EXT_FILENAME}" 2>/dev/null |
28 | 31 | ;; |
… |
… |
do_view_action() { |
44 | 47 | bzip2 -dc "${MC_EXT_FILENAME}" 2>/dev/null | \ |
45 | 48 | tar tvvf - |
46 | 49 | ;; |
| 50 | tar.lz4) |
| 51 | lz4 -dc "${MC_EXT_FILENAME}" 2>/dev/null | \ |
| 52 | tar tvvf - |
| 53 | ;; |
47 | 54 | tar.lzma) |
48 | 55 | lzma -dc "${MC_EXT_FILENAME}" 2>/dev/null | \ |
49 | 56 | tar tvvf - |
… |
… |
do_view_action() { |
81 | 88 | gzip -dc "${MC_EXT_FILENAME}" | \ |
82 | 89 | cpio -itv 2>/dev/null |
83 | 90 | ;; |
| 91 | cpio.lz4) |
| 92 | lz4 -dc "${MC_EXT_FILENAME}" | \ |
| 93 | cpio -itv 2>/dev/null |
| 94 | ;; |
84 | 95 | cpio.xz) |
85 | 96 | xz -dc "${MC_EXT_FILENAME}" | \ |
86 | 97 | cpio -itv 2>/dev/null |
… |
… |
do_open_action() { |
124 | 135 | gz) |
125 | 136 | gz -dc "${MC_EXT_FILENAME}" | ${pager} |
126 | 137 | ;; |
| 138 | lz4) |
| 139 | lz4 -dc "${MC_EXT_FILENAME}" | ${pager} |
| 140 | ;; |
127 | 141 | lzma) |
128 | 142 | lzma -dc "${MC_EXT_FILENAME}" | ${pager} |
129 | 143 | ;; |
diff --git a/misc/ext.d/text.sh.in b/misc/ext.d/text.sh.in
index d6e1933..b5476cf 100644
a
|
b
|
get_unpacker() { |
22 | 22 | man.bz2) |
23 | 23 | unpacker="bzip2 -dc" |
24 | 24 | ;; |
| 25 | man.lz4) |
| 26 | unpacker="lz4 -dc" |
| 27 | ;; |
25 | 28 | man.lzma) |
26 | 29 | unpacker="lzma -dc" |
27 | 30 | ;; |
… |
… |
do_view_action() { |
58 | 61 | nroff.ms) |
59 | 62 | nroff @MAN_FLAGS@ -ms "${MC_EXT_FILENAME}" |
60 | 63 | ;; |
61 | | man.gz|man.bz|man.bz2|man.lzma|man.xz) |
| 64 | man.gz|man.bz|man.bz2|man.lz4|man.lzma|man.xz) |
62 | 65 | case "${MC_EXT_FILENAME}" in |
63 | 66 | */log/*|*/logs/*) |
64 | 67 | ${unpacker} "${MC_EXT_FILENAME}" |
… |
… |
do_open_action() { |
105 | 108 | nroff.ms) |
106 | 109 | nroff @MAN_FLAGS@ -ms "${MC_EXT_FILENAME}" | ${pager} |
107 | 110 | ;; |
108 | | man.gz|man.bz|man.bz2|man.lzma|man.xz) |
| 111 | man.gz|man.bz|man.bz2|man.lz4|man.lzma|man.xz) |
109 | 112 | case "${MC_EXT_FILENAME}" in |
110 | 113 | */log/*|*/logs/*) |
111 | 114 | ${unpacker} "${MC_EXT_FILENAME}" |
diff --git a/misc/filehighlight.ini b/misc/filehighlight.ini
index 8bc1722..cae8732 100644
a
|
b
|
|
28 | 28 | regexp=(^#.*|.*~$) |
29 | 29 | |
30 | 30 | [archive] |
31 | | extensions=gz;bz2;tar;tgz;rpm;Z;rar;zip;arj;cab;lzh;lha;zoo;arc;ark;xz;tbz;tbz2;7z;ace |
| 31 | extensions=gz;bz2;tar;tgz;rpm;Z;rar;zip;arj;cab;lzh;lha;zoo;arc;ark;xz;tbz;tbz2;7z;ace;lz4 |
32 | 32 | |
33 | 33 | [doc] |
34 | 34 | extensions=txt;doc;rtf;diz;ctl;me;ps;pdf;xml;xsd;xslt;dtd;html;shtml;htm;mail;msg;lsm;po;nroff;man;tex;sgml;css;text;letter;chm;docx;docm;xlsx;xlsm;pptx;pptm |
diff --git a/misc/mc.ext.in b/misc/mc.ext.in
index 70a5089..c78a298 100644
a
|
b
|
regex/\.t(ar\.lzma|lz)$ |
135 | 135 | Open=%cd %p/utar:// |
136 | 136 | View=%view{ascii} @EXTHELPERSDIR@/archive.sh view tar.lzma |
137 | 137 | |
| 138 | # .tar.lz4, .tlz4 |
| 139 | regex/\.t(ar\.lz4|lz4)$ |
| 140 | Open=%cd %p/utar:// |
| 141 | View=%view{ascii} @EXTHELPERSDIR@/archive.sh view tar.lz4 |
| 142 | |
138 | 143 | # .tar.xz, .txz |
139 | 144 | regex/\.t(ar\.xz|xz)$ |
140 | 145 | Open=%cd %p/utar:// |
… |
… |
shell/.cpio.Z |
190 | 195 | Open=%cd %p/ucpio:// |
191 | 196 | View=%view{ascii} @EXTHELPERSDIR@/archive.sh view cpio.z |
192 | 197 | |
| 198 | shell/.cpio.lz4 |
| 199 | Open=%cd %p/ucpio:// |
| 200 | View=%view{ascii} @EXTHELPERSDIR@/archive.sh view cpio.lz4 |
| 201 | |
193 | 202 | shell/.cpio.xz |
194 | 203 | Open=%cd %p/ucpio:// |
195 | 204 | View=%view{ascii} @EXTHELPERSDIR@/archive.sh view cpio.xz |
… |
… |
regex/([^0-9]|^[^\.]*)\.([1-9][A-Za-z]*|[ln])\.bz2$ |
360 | 369 | Open=@EXTHELPERSDIR@/text.sh open man.bz2 %var{PAGER:more} |
361 | 370 | View=%view{ascii,nroff} @EXTHELPERSDIR@/text.sh view man.bz2 %var{PAGER:more} |
362 | 371 | |
| 372 | regex/([^0-9]|^[^\.]*)\.([1-9][A-Za-z]*|[ln])\.lz4$ |
| 373 | Open=@EXTHELPERSDIR@/text.sh open man.lz4 %var{PAGER:more} |
| 374 | View=%view{ascii,nroff} @EXTHELPERSDIR@/text.sh view man.lz4 %var{PAGER:more} |
| 375 | |
363 | 376 | regex/([^0-9]|^[^\.]*)\.([1-9][A-Za-z]*|[ln])\.lzma$ |
364 | 377 | Open=@EXTHELPERSDIR@/text.sh open man.lzma %var{PAGER:more} |
365 | 378 | View=%view{ascii,nroff} @EXTHELPERSDIR@/text.sh view man.lzma %var{PAGER:more} |
… |
… |
type/^compress |
730 | 743 | Open=@EXTHELPERSDIR@/archive.sh view gz %var{PAGER:more} |
731 | 744 | View=%view{ascii} @EXTHELPERSDIR@/archive.sh view gz |
732 | 745 | |
| 746 | # lz4 |
| 747 | regex/\.lz4$ |
| 748 | Open=@EXTHELPERSDIR@/archive.sh view lz4 %var{PAGER:more} |
| 749 | View=%view{ascii} @EXTHELPERSDIR@/archive.sh view lz4 |
| 750 | |
733 | 751 | # lzma |
734 | 752 | regex/\.lzma$ |
735 | 753 | Open=@EXTHELPERSDIR@/archive.sh view lzma %var{PAGER:more} |
diff --git a/misc/mc.menu.in b/misc/mc.menu.in
index 4d341a7..b6a6d29 100644
a
|
b
|
U Uudecode marked news articles (needs work) |
204 | 204 | fi |
205 | 205 | echo "Please test the output file before deleting anything." |
206 | 206 | |
207 | | =+ f \.tar\.gz$ | f \.tar\.z$ | f \.tgz$ | f \.tpz$ | f \.tar\.lz$ | f \.tar\.lzma$ | f \.tar\.7z$ | f \.tar\.xz$ | f \.tar\.Z$ | f \.tar\.bz2$ & t r |
| 207 | =+ f \.tar\.gz$ | f \.tar\.z$ | f \.tgz$ | f \.tpz$ | f \.tar\.lz$ | f \.tar\.lz4$ | f \.tar\.lzma$ | f \.tar\.7z$ | f \.tar\.xz$ | f \.tar\.Z$ | f \.tar\.bz2$ & t r |
208 | 208 | x Extract the contents of a compressed tar file |
209 | 209 | unset PRG |
210 | 210 | case %f in |
… |
… |
x Extract the contents of a compressed tar file |
220 | 220 | *.tar.lz) |
221 | 221 | PRG="lzip -dc" |
222 | 222 | ;; |
| 223 | *.tar.lz4) |
| 224 | PRG="lz4 -dc" |
| 225 | ;; |
223 | 226 | *.tar.xz) |
224 | 227 | PRG="xz -dc" |
225 | 228 | ;; |
diff --git a/misc/mc.menu.sr.in b/misc/mc.menu.sr.in
index a0bb57a..5810aef 100644
a
|
b
|
U Уудекодирај означени чланак вести (тре |
184 | 184 | fi |
185 | 185 | echo "Молим да проверите излазну датотеку пре било каквог брисања." |
186 | 186 | |
187 | | =+ f \.tar\.gz$ | f \.tar\.z$ | f \.tgz$ | f \.tpz$ | f \.tar\.lz$ | f \.tar\.lzma$ | f \.tar\.7z$ | f \.tar\.xz$ | f \.tar\.Z$ | f \.tar\.bz2$ & t r |
| 187 | =+ f \.tar\.gz$ | f \.tar\.z$ | f \.tgz$ | f \.tpz$ | f \.tar\.lz$ | f \.tar\.lz4$ | f \.tar\.lzma$ | f \.tar\.7z$ | f \.tar\.xz$ | f \.tar\.Z$ | f \.tar\.bz2$ & t r |
188 | 188 | x Издвој садржај компримоване датотеке врсте `tar' |
189 | 189 | unset PRG |
190 | 190 | case %f in |
… |
… |
x Издвој садржај компримоване датотеке в |
200 | 200 | *.tar.lz) |
201 | 201 | PRG="lzip -dc" |
202 | 202 | ;; |
| 203 | *.tar.lz4) |
| 204 | PRG="lz4 -dc" |
| 205 | ;; |
203 | 206 | *.tar.xz) |
204 | 207 | PRG="xz -dc" |
205 | 208 | ;; |
diff --git a/src/editor/edit.c b/src/editor/edit.c
index 808239b..733e12e 100644
a
|
b
|
static const struct edit_filters |
129 | 129 | { |
130 | 130 | /* *INDENT-OFF* */ |
131 | 131 | { "xz -cd %s 2>&1", "xz > %s", ".xz"}, |
| 132 | { "lz4 -cd %s 2>&1", "lz4 > %s", ".lz4" }, |
132 | 133 | { "lzma -cd %s 2>&1", "lzma > %s", ".lzma" }, |
133 | 134 | { "bzip2 -cd %s 2>&1", "bzip2 > %s", ".bz2" }, |
134 | 135 | { "gzip -cd %s 2>&1", "gzip > %s", ".gz" }, |
diff --git a/src/vfs/extfs/helpers/iso9660.in b/src/vfs/extfs/helpers/iso9660.in
index fd652b8..ffac9b2 100644
a
|
b
|
test_iso () { |
121 | 121 | mcisofs_list () { |
122 | 122 | # left as a reminder to implement compressed image support =) |
123 | 123 | case "$1" in |
| 124 | *.lz4) MYCAT="lz4 -dc";; |
124 | 125 | *.lzma) MYCAT="lzma -dc";; |
125 | 126 | *.xz) MYCAT="xz -dc";; |
126 | 127 | *.bz2) MYCAT="bzip2 -dc";; |
diff --git a/src/vfs/extfs/helpers/lslR.in b/src/vfs/extfs/helpers/lslR.in
index 8b6833a..b4a3637 100644
a
|
b
|
AWK=@AWK@ |
12 | 12 | |
13 | 13 | mclslRfs_list () { |
14 | 14 | case "$1" in |
| 15 | *.lz4) MYCAT="lz4 -dc";; |
15 | 16 | *.lzma) MYCAT="lzma -dc";; |
16 | 17 | *.xz) MYCAT="xz -dc";; |
17 | 18 | *.bz2) MYCAT="bzip2 -dc";; |
diff --git a/src/vfs/extfs/helpers/mailfs.in b/src/vfs/extfs/helpers/mailfs.in
index bb372e3..7f566da 100644
a
|
b
|
use bytes; |
7 | 7 | |
8 | 8 | $zcat="zcat"; # gunzip to stdout |
9 | 9 | $bzcat="bzip2 -dc"; # bunzip2 to stdout |
| 10 | $lz4cat="lz4 -dc"; # unlz4 to stdout |
10 | 11 | $lzcat="lzma -dc"; # unlzma to stdout |
11 | 12 | $xzcat="xz -dc"; # unxz to stdout |
12 | 13 | $file="file"; # "file" command |
… |
… |
if (/gzip/) { |
184 | 185 | exit 1 unless (open IN, "$zcat $mbox_qname|"); |
185 | 186 | } elsif (/bzip/) { |
186 | 187 | exit 1 unless (open IN, "$bzcat $mbox_qname|"); |
| 188 | } elsif (/lz4/) { |
| 189 | exit 1 unless (open IN, "$lz4cat $mbox_qname|"); |
187 | 190 | } elsif (/lzma/) { |
188 | 191 | exit 1 unless (open IN, "$lzcat $mbox_qname|"); |
189 | 192 | } elsif (/xz/) { |
diff --git a/src/vfs/extfs/helpers/patchfs.in b/src/vfs/extfs/helpers/patchfs.in
index c1c4f99..c1ff6b2 100644
a
|
b
|
use POSIX; |
13 | 13 | use File::Temp 'tempfile'; |
14 | 14 | |
15 | 15 | # standard binaries |
| 16 | my $lz4 = 'lz4'; |
16 | 17 | my $lzma = 'lzma'; |
17 | 18 | my $xz = 'xz'; |
18 | 19 | my $bzip = 'bzip2'; |
… |
… |
sub myin |
78 | 79 | my ($qfname)=(quotemeta $_[0]); |
79 | 80 | |
80 | 81 | $_=`$fileutil $qfname`; |
81 | | if (/^'*lzma/) { |
| 82 | if (/^'*lz4/) { |
| 83 | return "$lz4 -dc $qfname"; |
| 84 | } elsif (/^'*lzma/) { |
82 | 85 | return "$lzma -dc $qfname"; |
83 | 86 | } elsif (/^'*xz/) { |
84 | 87 | return "$xz -dc $qfname"; |
… |
… |
sub myout |
98 | 101 | my ($sep) = $append ? '>>' : '>'; |
99 | 102 | |
100 | 103 | $_=`$fileutil $qfname`; |
101 | | if (/^'*lzma/) { |
| 104 | if (/^'*lz4/) { |
| 105 | return "$lz4 -c $sep $qfname"; |
| 106 | } elsif (/^'*lzma/) { |
102 | 107 | return "$lzma -c $sep $qfname"; |
103 | 108 | } elsif (/^'*xz/) { |
104 | 109 | return "$xz -c $sep $qfname"; |
diff --git a/src/vfs/extfs/helpers/sfs.ini b/src/vfs/extfs/helpers/sfs.ini
index 522cca1..b1f51c8 100644
a
|
b
|
bz/1 bzip < %1 > %3 |
10 | 10 | ubz/1 bzip -d < %1 > %3 |
11 | 11 | bz2/1 bzip2 < %1 > %3 |
12 | 12 | ubz2/1 bzip2 -d < %1 > %3 |
| 13 | lz4/1 lz4 < %1 > %3 |
| 14 | ulz4/1 lz4 -d < %1 > %3 |
13 | 15 | lzma/1 lzma < %1 > %3 |
14 | 16 | ulzma/1 lzma -d < %1 > %3 |
15 | 17 | xz/1 xz < %1 > %3 |