From bbb08d7e23a9a3561524502b74a4e274ca63926a Mon Sep 17 00:00:00 2001
From: Adam Borowski <kilobyte@angband.pl>
Date: Sun, 18 Mar 2018 18:23:33 +0100
Subject: [PATCH] ZSTD support.
Signed-off-by: Adam Borowski <kilobyte@angband.pl>
---
lib/util.c | 5 +++++
lib/util.h | 3 ++-
misc/ext.d/archive.sh | 14 ++++++++++++++
misc/ext.d/text.sh.in | 7 +++++--
misc/filehighlight.ini | 2 +-
misc/mc.ext.in | 22 ++++++++++++++++++++++
misc/mc.menu.in | 12 +++++++++++-
misc/syntax/sh.syntax | 1 +
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 | 5 +++++
src/vfs/extfs/helpers/sfs.ini | 2 ++
14 files changed, 74 insertions(+), 5 deletions(-)
diff --git a/lib/util.c b/lib/util.c
index 2ecfd978d..aaa8c5f5e 100644
a
|
b
|
get_compression_type (int fd, const char *name) |
893 | 893 | && magic[2] == 0x7A && magic[3] == 0x58 && magic[4] == 0x5A && magic[5] == 0x00) |
894 | 894 | return COMPRESSION_XZ; |
895 | 895 | |
| 896 | if (magic[0] == 0x28 && magic[1] == 0xB5 && magic[2] == 0x2F && magic[3] == 0xFD) |
| 897 | return COMPRESSION_ZSTD; |
| 898 | |
896 | 899 | str_len = strlen (name); |
897 | 900 | /* HACK: we must belive to extension of LZMA file :) ... */ |
898 | 901 | if ((str_len > 5 && strcmp (&name[str_len - 5], ".lzma") == 0) || |
… |
… |
decompress_extension (int type) |
923 | 926 | return "/ulzma" VFS_PATH_URL_DELIMITER; |
924 | 927 | case COMPRESSION_XZ: |
925 | 928 | return "/uxz" VFS_PATH_URL_DELIMITER; |
| 929 | case COMPRESSION_ZSTD: |
| 930 | return "/uzst" VFS_PATH_URL_DELIMITER; |
926 | 931 | default: |
927 | 932 | break; |
928 | 933 | } |
diff --git a/lib/util.h b/lib/util.h
index 28b834d39..46ac1f0b4 100644
a
|
b
|
enum compression_type |
60 | 60 | COMPRESSION_LZIP, |
61 | 61 | COMPRESSION_LZ4, |
62 | 62 | COMPRESSION_LZMA, |
63 | | COMPRESSION_XZ |
| 63 | COMPRESSION_XZ, |
| 64 | COMPRESSION_ZSTD, |
64 | 65 | }; |
65 | 66 | |
66 | 67 | /* stdout or stderr stream of child process */ |
diff --git a/misc/ext.d/archive.sh b/misc/ext.d/archive.sh
index e6105fdc1..a4a041eaa 100755
a
|
b
|
do_view_action() { |
35 | 35 | xz) |
36 | 36 | xz -dc "${MC_EXT_FILENAME}" 2>/dev/null |
37 | 37 | ;; |
| 38 | zst) |
| 39 | zstd -dc "${MC_EXT_FILENAME}" 2>/dev/null |
| 40 | ;; |
38 | 41 | tar) |
39 | 42 | tar tvvf - < "${MC_EXT_FILENAME}" |
40 | 43 | ;; |
… |
… |
do_view_action() { |
66 | 69 | xz -dc "${MC_EXT_FILENAME}" 2>/dev/null | \ |
67 | 70 | tar tvvf - |
68 | 71 | ;; |
| 72 | tar.zst|tzst) |
| 73 | zstd -dc "${MC_EXT_FILENAME}" 2>/dev/null | \ |
| 74 | tar tvvf - |
| 75 | ;; |
69 | 76 | tar.F) |
70 | 77 | freeze -dc "${MC_EXT_FILENAME}" 2>/dev/null | \ |
71 | 78 | tar tvvf - |
… |
… |
do_view_action() { |
107 | 114 | xz -dc "${MC_EXT_FILENAME}" | \ |
108 | 115 | cpio -itv 2>/dev/null |
109 | 116 | ;; |
| 117 | cpio.zst) |
| 118 | zstd -dc "${MC_EXT_FILENAME}" | \ |
| 119 | cpio -itv 2>/dev/null |
| 120 | ;; |
110 | 121 | cpio) |
111 | 122 | cpio -itv < "${MC_EXT_FILENAME}" 2>/dev/null |
112 | 123 | ;; |
… |
… |
do_open_action() { |
158 | 169 | xz) |
159 | 170 | xz -dc "${MC_EXT_FILENAME}" | ${pager} |
160 | 171 | ;; |
| 172 | zst) |
| 173 | zstd -dc "${MC_EXT_FILENAME}" | ${pager} |
| 174 | ;; |
161 | 175 | par2) |
162 | 176 | par2 r "${MC_EXT_FILENAME}" |
163 | 177 | ;; |
diff --git a/misc/ext.d/text.sh.in b/misc/ext.d/text.sh.in
index b47425876..2bd6ca05c 100644
a
|
b
|
get_unpacker() { |
34 | 34 | man.xz) |
35 | 35 | unpacker="xz -dc" |
36 | 36 | ;; |
| 37 | man.zst) |
| 38 | unpacker="zstd -dc" |
| 39 | ;; |
37 | 40 | esac |
38 | 41 | echo ${unpacker} |
39 | 42 | } |
… |
… |
do_view_action() { |
64 | 67 | nroff.ms) |
65 | 68 | nroff @MAN_FLAGS@ -ms "${MC_EXT_FILENAME}" |
66 | 69 | ;; |
67 | | man.gz|man.bz|man.bz2|man.lz|man.lz4|man.lzma|man.xz) |
| 70 | man.gz|man.bz|man.bz2|man.lz|man.lz4|man.lzma|man.xz|man.zst) |
68 | 71 | case "${MC_EXT_FILENAME}" in |
69 | 72 | */log/*|*/logs/*) |
70 | 73 | ${unpacker} "${MC_EXT_FILENAME}" |
… |
… |
do_open_action() { |
111 | 114 | nroff.ms) |
112 | 115 | nroff @MAN_FLAGS@ -ms "${MC_EXT_FILENAME}" | ${pager} |
113 | 116 | ;; |
114 | | man.gz|man.bz|man.bz2|man.lz|man.lz4|man.lzma|man.xz) |
| 117 | man.gz|man.bz|man.bz2|man.lz|man.lz4|man.lzma|man.xz|man.zst) |
115 | 118 | case "${MC_EXT_FILENAME}" in |
116 | 119 | */log/*|*/logs/*) |
117 | 120 | ${unpacker} "${MC_EXT_FILENAME}" |
diff --git a/misc/filehighlight.ini b/misc/filehighlight.ini
index 4a7a41855..8d6f0194b 100644
a
|
b
|
|
28 | 28 | regexp=(^#.*|.*~$) |
29 | 29 | |
30 | 30 | [archive] |
31 | | extensions=7z;Z;ace;arc;arj;ark;bz2;cab;gz;lha;lz;lz4;lzh;lzma;rar;rpm;tar;tbz;tbz2;tgz;tlz;txz;xz;zip;zoo |
| 31 | extensions=7z;Z;ace;arc;arj;ark;bz2;cab;gz;lha;lz;lz4;lzh;lzma;rar;rpm;tar;tbz;tbz2;tgz;tlz;txz;xz;tzst;zst;zip;zoo |
32 | 32 | |
33 | 33 | [doc] |
34 | 34 | extensions=chm;css;ctl;diz;doc;docm;docx;dtd;htm;html;letter;lsm;mail;man;me;msg;nroff;odp;ods;odt;pdf;po;ppt;pptm;pptx;ps;rtf;sgml;shtml;tex;text;txt;xls;xlsm;xlsx;xml;xsd;xslt |
diff --git a/misc/mc.ext.in b/misc/mc.ext.in
index 92f908b6e..228c89311 100644
a
|
b
|
regex/\.t(ar\.xz|xz)$ |
150 | 150 | Open=%cd %p/utar:// |
151 | 151 | View=%view{ascii} @EXTHELPERSDIR@/archive.sh view tar.xz |
152 | 152 | |
| 153 | # .tar.zst, .tzst |
| 154 | regex/\.t(ar\.zst|zst)$ |
| 155 | Open=%cd %p/utar:// |
| 156 | View=%view{ascii} @EXTHELPERSDIR@/archive.sh view tar.zst |
| 157 | |
153 | 158 | # .tar.F - used in QNX |
154 | 159 | shell/.tar.F |
155 | 160 | # Open=%cd %p/utar:// |
… |
… |
shell/.cpio.xz |
212 | 217 | Open=%cd %p/ucpio:// |
213 | 218 | View=%view{ascii} @EXTHELPERSDIR@/archive.sh view cpio.xz |
214 | 219 | |
| 220 | shell/.cpio.zst |
| 221 | Open=%cd %p/ucpio:// |
| 222 | View=%view{ascii} @EXTHELPERSDIR@/archive.sh view cpio.zst |
| 223 | |
215 | 224 | shell/.cpio.gz |
216 | 225 | Open=%cd %p/ucpio:// |
217 | 226 | View=%view{ascii} @EXTHELPERSDIR@/archive.sh view cpio.gz |
… |
… |
regex/\.(diff|patch)(\.xz)$ |
243 | 252 | Open=%cd %p/patchfs:// |
244 | 253 | View=%view{ascii} @EXTHELPERSDIR@/archive.sh view xz |
245 | 254 | |
| 255 | regex/\.(diff|patch)(\.zst)$ |
| 256 | Open=%cd %p/patchfs:// |
| 257 | View=%view{ascii} @EXTHELPERSDIR@/archive.sh view zst |
| 258 | |
246 | 259 | # ls-lR |
247 | 260 | regex/(^|\.)ls-?lR(\.gz|Z|bz2)$ |
248 | 261 | Open=%cd %p/lslR:// |
… |
… |
regex/([^0-9]|^[^\.]*)\.([1-9][A-Za-z]*|[ln])\.xz$ |
403 | 416 | Open=@EXTHELPERSDIR@/text.sh open man.xz %var{PAGER:more} |
404 | 417 | View=%view{ascii,nroff} @EXTHELPERSDIR@/text.sh view man.xz %var{PAGER:more} |
405 | 418 | |
| 419 | regex/([^0-9]|^[^\.]*)\.([1-9][A-Za-z]*|[ln])\.zst$ |
| 420 | Open=@EXTHELPERSDIR@/text.sh open man.zst %var{PAGER:more} |
| 421 | View=%view{ascii,nroff} @EXTHELPERSDIR@/text.sh view man.zst %var{PAGER:more} |
| 422 | |
406 | 423 | # CHM |
407 | 424 | shell/i/.chm |
408 | 425 | Open=@EXTHELPERSDIR@/text.sh open chm |
… |
… |
regex/\.xz$ |
790 | 807 | Open=@EXTHELPERSDIR@/archive.sh view xz %var{PAGER:more} |
791 | 808 | View=%view{ascii} @EXTHELPERSDIR@/archive.sh view xz |
792 | 809 | |
| 810 | # zstd |
| 811 | regex/\.zst$ |
| 812 | Open=@EXTHELPERSDIR@/archive.sh view zst %var{PAGER:more} |
| 813 | View=%view{ascii} @EXTHELPERSDIR@/archive.sh view zst |
| 814 | |
793 | 815 | # Parity Archive |
794 | 816 | type/^Parity\ Archive\ Volume\ Set |
795 | 817 | Open=@EXTHELPERSDIR@/archive.sh open par2 |
diff --git a/misc/mc.menu.in b/misc/mc.menu.in
index 8488a8750..2bf39c48e 100644
a
|
b
|
shell_patterns=0 |
84 | 84 | tar cf - "$Pwd" | xz -f > "$tar.tar.xz" && \ |
85 | 85 | echo "../$tar.tar.xz created." |
86 | 86 | |
| 87 | 7 Compress the current subdirectory (tar.zst) |
| 88 | Pwd=`basename %d /` |
| 89 | echo -n "Name of the compressed file (without extension) [$Pwd]: " |
| 90 | read tar |
| 91 | [ "$tar"x = x ] && tar="$Pwd" |
| 92 | cd .. && \ |
| 93 | tar cf - "$Pwd" | zstd -f > "$tar.tar.zst" && \ |
| 94 | echo "../$tar.tar.zst created." |
| 95 | |
87 | 96 | = f \.c$ & t r |
88 | 97 | + f \.c$ & t r & ! t t |
89 | 98 | c Compile and link current .c file |
… |
… |
U Uudecode marked news articles (needs work) |
219 | 228 | fi |
220 | 229 | echo "Please test the output file before deleting anything." |
221 | 230 | |
222 | | =+ 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 |
| 231 | =+ 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\.zst | f \.tar\.Z$ | f \.tar\.bz2$ & t r |
223 | 232 | x Extract the contents of a compressed tar file |
224 | 233 | unset PRG |
225 | 234 | case %f in |
… |
… |
x Extract the contents of a compressed tar file |
230 | 239 | *.tar.lz4) PRG="lz4 -dc";; |
231 | 240 | *.tar.lzma) PRG="lzma -dc";; |
232 | 241 | *.tar.xz) PRG="xz -dc";; |
| 242 | *.tar.zst) PRG="zstd -dc";; |
233 | 243 | *) exit 1;; |
234 | 244 | esac |
235 | 245 | $PRG %f | tar xvf - |
diff --git a/misc/syntax/sh.syntax b/misc/syntax/sh.syntax
index ff9ba2bc5..032433ee8 100644
a
|
b
|
wholechars abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-._ |
1995 | 1995 | keyword whole zoo cyan |
1996 | 1996 | keyword whole zsh cyan |
1997 | 1997 | keyword whole zsoelim cyan |
| 1998 | keyword whole zstd cyan |
1998 | 1999 | keyword whole zxpdf cyan |
1999 | 2000 | |
2000 | 2001 | keyword whole pamcut cyan |
diff --git a/src/editor/edit.c b/src/editor/edit.c
index 174637253..016496fee 100644
a
|
b
|
static const struct edit_filters |
126 | 126 | { |
127 | 127 | /* *INDENT-OFF* */ |
128 | 128 | { "xz -cd %s 2>&1", "xz > %s", ".xz"}, |
| 129 | { "zstd -cd %s 2>&1", "zstd > %s", ".zst"}, |
129 | 130 | { "lz4 -cd %s 2>&1", "lz4 > %s", ".lz4" }, |
130 | 131 | { "lzip -cd %s 2>&1", "lzip > %s", ".lz"}, |
131 | 132 | { "lzma -cd %s 2>&1", "lzma > %s", ".lzma" }, |
diff --git a/src/vfs/extfs/helpers/iso9660.in b/src/vfs/extfs/helpers/iso9660.in
index 192667123..8c2240e8e 100644
a
|
b
|
mcisofs_list () { |
125 | 125 | *.lz4) MYCAT="lz4 -dc";; |
126 | 126 | *.lzma) MYCAT="lzma -dc";; |
127 | 127 | *.xz) MYCAT="xz -dc";; |
| 128 | *.zst) MYCAT="zstd -dc";; |
128 | 129 | *.bz2) MYCAT="bzip2 -dc";; |
129 | 130 | *.gz) MYCAT="gzip -dc";; |
130 | 131 | *.z) MYCAT="gzip -dc";; |
diff --git a/src/vfs/extfs/helpers/lslR.in b/src/vfs/extfs/helpers/lslR.in
index aba5457c5..69b663b40 100644
a
|
b
|
case "$1" in |
16 | 16 | *.lz4) MYCAT="lz4 -dc";; |
17 | 17 | *.lzma) MYCAT="lzma -dc";; |
18 | 18 | *.xz) MYCAT="xz -dc";; |
| 19 | *.zst) MYCAT="zstd -dc";; |
19 | 20 | *.bz2) MYCAT="bzip2 -dc";; |
20 | 21 | *.gz) MYCAT="gzip -dc";; |
21 | 22 | *.z) MYCAT="gzip -dc";; |
diff --git a/src/vfs/extfs/helpers/mailfs.in b/src/vfs/extfs/helpers/mailfs.in
index e9455bef0..4bdd68b61 100644
a
|
b
|
$lzipcat="lzip -dc"; # unlzip to stdout |
11 | 11 | $lz4cat="lz4 -dc"; # unlz4 to stdout |
12 | 12 | $lzcat="lzma -dc"; # unlzma to stdout |
13 | 13 | $xzcat="xz -dc"; # unxz to stdout |
| 14 | $zstdcat="zstd -dc"; # unzstd to stdout |
14 | 15 | $file="file"; # "file" command |
15 | 16 | $TZ='GMT'; # default timezone (for Date module) |
16 | 17 | |
… |
… |
if (/gzip/) { |
194 | 195 | exit 1 unless (open IN, "$lzcat $mbox_qname|"); |
195 | 196 | } elsif (/xz/) { |
196 | 197 | exit 1 unless (open IN, "$xzcat $mbox_qname|"); |
| 198 | } elsif (/zst/) { |
| 199 | exit 1 unless (open IN, "$zstdcat $mbox_qname|"); |
197 | 200 | } else { |
198 | 201 | exit 1 unless (open IN, "<$mbox_name"); |
199 | 202 | } |
diff --git a/src/vfs/extfs/helpers/patchfs.in b/src/vfs/extfs/helpers/patchfs.in
index ef407de3a..c20cd54ef 100644
a
|
b
|
my $lzip = 'lzip'; |
17 | 17 | my $lz4 = 'lz4'; |
18 | 18 | my $lzma = 'lzma'; |
19 | 19 | my $xz = 'xz'; |
| 20 | my $zstd = 'zstd'; |
20 | 21 | my $bzip = 'bzip2'; |
21 | 22 | my $gzip = 'gzip'; |
22 | 23 | my $fileutil = 'file -b'; |
… |
… |
sub myin |
88 | 89 | return "$lzma -dc $qfname"; |
89 | 90 | } elsif (/^'*xz/) { |
90 | 91 | return "$xz -dc $qfname"; |
| 92 | } elsif (/^'*zst/) { |
| 93 | return "$zstd -dc $qfname"; |
91 | 94 | } elsif (/^'*bzip/) { |
92 | 95 | return "$bzip -dc $qfname"; |
93 | 96 | } elsif (/^'*gzip/) { |
… |
… |
sub myout |
112 | 115 | return "$lzma -c $sep $qfname"; |
113 | 116 | } elsif (/^'*xz/) { |
114 | 117 | return "$xz -c $sep $qfname"; |
| 118 | } elsif (/^'*zst/) { |
| 119 | return "$zstd -c $sep $qfname"; |
115 | 120 | } elsif (/^'*bzip/) { |
116 | 121 | return "$bzip -c $sep $qfname"; |
117 | 122 | } elsif (/^'*gzip/) { |
diff --git a/src/vfs/extfs/helpers/sfs.ini b/src/vfs/extfs/helpers/sfs.ini
index 699078aa6..d817dc9f4 100644
a
|
b
|
lzma/1 lzma < %1 > %3 |
18 | 18 | ulzma/1 lzma -d < %1 > %3 |
19 | 19 | xz/1 xz < %1 > %3 |
20 | 20 | uxz/1 xz -d < %1 > %3 |
| 21 | zst/1 zstd < %1 > %3 |
| 22 | uzst/1 zstd -d < %1 > %3 |
21 | 23 | tar/1 tar cf %3 %1 |
22 | 24 | tgz/1 tar czf %3 %1 |
23 | 25 | uhtml/1 lynx -force_html -dump %1 > %3 |