cli: add GNU separator -- specifying that all following arguments are files

This option is supported by other compressors with compatible cli,
so add it to lz4 as well for better compatibility.
This commit is contained in:
Dmitry V. Levin 2017-03-23 03:48:51 +00:00
parent eff6166eb8
commit b1daffc4e5
4 changed files with 15 additions and 1 deletions

1
NEWS
View File

@ -1,5 +1,6 @@
v1.7.6 v1.7.6
cli : fix : do not modify /dev/null permissions, reported by @Maokaman1 cli : fix : do not modify /dev/null permissions, reported by @Maokaman1
cli : added GNU separator -- specifying that all following arguments are files
API : added LZ4_compress_HC_destSize(), by Oleg (@remittor) API : added LZ4_compress_HC_destSize(), by Oleg (@remittor)
API : fix : expose obsolete decoding functions, reported by Chen Yufei API : fix : expose obsolete decoding functions, reported by Chen Yufei
build : dragonFlyBSD, OpenBSD, NetBSD supported build : dragonFlyBSD, OpenBSD, NetBSD supported

View File

@ -194,6 +194,9 @@ only the latest one will be applied.
* `--rm` : * `--rm` :
Delete source files on successful compression or decompression Delete source files on successful compression or decompression
* `--` :
Treat all subsequent arguments as files
### Benchmark mode ### Benchmark mode

View File

@ -271,6 +271,7 @@ int main(int argc, const char** argv)
forceStdout=0, forceStdout=0,
main_pause=0, main_pause=0,
multiple_inputs=0, multiple_inputs=0,
all_arguments_are_files=0,
operationResult=0; operationResult=0;
operationMode_e mode = om_auto; operationMode_e mode = om_auto;
const char* input_filename = NULL; const char* input_filename = NULL;
@ -315,7 +316,7 @@ int main(int argc, const char** argv)
if(!argument) continue; /* Protection if argument empty */ if(!argument) continue; /* Protection if argument empty */
/* Short commands (note : aggregated short commands are allowed) */ /* Short commands (note : aggregated short commands are allowed) */
if (argument[0]=='-') { if (!all_arguments_are_files && argument[0]=='-') {
/* '-' means stdin/stdout */ /* '-' means stdin/stdout */
if (argument[1]==0) { if (argument[1]==0) {
if (!input_filename) input_filename=stdinmark; if (!input_filename) input_filename=stdinmark;
@ -325,6 +326,7 @@ int main(int argc, const char** argv)
/* long commands (--long-word) */ /* long commands (--long-word) */
if (argument[1]=='-') { if (argument[1]=='-') {
if (!strcmp(argument, "--")) { all_arguments_are_files = 1; continue; }
if (!strcmp(argument, "--compress")) { mode = om_compress; continue; } if (!strcmp(argument, "--compress")) { mode = om_compress; continue; }
if ((!strcmp(argument, "--decompress")) if ((!strcmp(argument, "--decompress"))
|| (!strcmp(argument, "--uncompress"))) { mode = om_decompress; continue; } || (!strcmp(argument, "--uncompress"))) { mode = om_decompress; continue; }

View File

@ -252,6 +252,14 @@ test-lz4-basic: lz4 datagen unlz4 lz4cat
$(DIFF) -q tmp tmp3 $(DIFF) -q tmp tmp3
$(PRGDIR)/lz4cat < tmp > tmp2 # checks lz4cat works with stdin (#285) $(PRGDIR)/lz4cat < tmp > tmp2 # checks lz4cat works with stdin (#285)
$(DIFF) -q tmp tmp2 $(DIFF) -q tmp tmp2
cp tmp ./-d
$(LZ4) --rm -- -d -d.lz4 # compresses ./d into ./-d.lz4
test -f ./-d.lz4
test ! -f ./-d
mv ./-d.lz4 ./-z
$(LZ4) -d --rm -- -z tmp4 # uncompresses ./-z into tmp4
test ! -f ./-z
$(DIFF) -q tmp tmp4
@$(RM) tmp* @$(RM) tmp*
test-lz4-hugefile: lz4 datagen test-lz4-hugefile: lz4 datagen