diff options
author | Yann Collet <Cyan4973@users.noreply.github.com> | 2017-10-10 23:18:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-10 23:18:16 (GMT) |
commit | 34da12c6e62ce9b43f4b4185ac51658255122a68 (patch) | |
tree | 9dce51a96a28007ac4bb52863ccbe426ec4d9c0d /programs/lz4cli.c | |
parent | 87968517f926b55c2af3cf39e9692b368c566103 (diff) | |
parent | 9a16272261f571d54e4642c760d099adb6cc27b1 (diff) | |
download | lz4-34da12c6e62ce9b43f4b4185ac51658255122a68.zip lz4-34da12c6e62ce9b43f4b4185ac51658255122a68.tar.gz lz4-34da12c6e62ce9b43f4b4185ac51658255122a68.tar.bz2 |
Merge pull request #403 from felixhandte/lz4-cli-dict-support-tests
Support Dictionaries on the Command Line
Diffstat (limited to 'programs/lz4cli.c')
-rw-r--r-- | programs/lz4cli.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/programs/lz4cli.c b/programs/lz4cli.c index ff489c6..857fa65 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -113,6 +113,7 @@ static int usage(const char* exeName) DISPLAY( " -9 : High compression \n"); DISPLAY( " -d : decompression (default for %s extension)\n", LZ4_EXTENSION); DISPLAY( " -z : force compression \n"); + DISPLAY( " -D FILE: use dictionary in FILE \n"); DISPLAY( " -f : overwrite output without prompting \n"); DISPLAY( " -k : preserve source files(s) (default) \n"); DISPLAY( "--rm : remove source file(s) after successful de/compression \n"); @@ -290,6 +291,7 @@ int main(int argc, const char** argv) operationMode_e mode = om_auto; const char* input_filename = NULL; const char* output_filename= NULL; + const char* dictionary_filename = NULL; char* dynNameSpace = NULL; const char** inFileNames = (const char**) calloc(argc, sizeof(char*)); unsigned ifnIdx=0; @@ -399,6 +401,22 @@ int main(int argc, const char** argv) /* Compression (default) */ case 'z': mode = om_compress; break; + case 'D': + if (argument[1] == '\0') { + /* path is next arg */ + if (i + 1 == argc) { + /* there is no next arg */ + badusage(exeName); + } + dictionary_filename = argv[++i]; + } else { + /* path follows immediately */ + dictionary_filename = argument + 1; + } + /* skip to end of argument so that we jump to parsing next argument */ + argument += strlen(argument) - 1; + break; + /* Use Legacy format (ex : Linux kernel compression) */ case 'l': legacy_format = 1; blockSize = 8 MB; break; @@ -560,6 +578,15 @@ int main(int argc, const char** argv) mode = om_decompress; /* defer to decompress */ } + if (dictionary_filename) { + if (!strcmp(dictionary_filename, stdinmark) && IS_CONSOLE(stdin)) { + DISPLAYLEVEL(1, "refusing to read from a console\n"); + exit(1); + } + + LZ4IO_setDictionaryFilename(dictionary_filename); + } + /* compress or decompress */ if (!input_filename) input_filename = stdinmark; /* Check if input is defined as console; trigger an error in this case */ |