summaryrefslogtreecommitdiffstats
path: root/programs/lz4cli.c
diff options
context:
space:
mode:
authorinikep <inikep@gmail.com>2016-09-03 06:10:16 (GMT)
committerinikep <inikep@gmail.com>2016-09-03 06:10:16 (GMT)
commit58a1616d7b272e624f78e713fcd37172f845f576 (patch)
tree579df140753d421293418ba6b112c4d68df0e085 /programs/lz4cli.c
parentc77fdb44f101c81ef7740d67fdf77a5f065bc04f (diff)
parent28f98647e3349a4a0a9c8975199aa89f2a02f6b9 (diff)
downloadlz4-58a1616d7b272e624f78e713fcd37172f845f576.zip
lz4-58a1616d7b272e624f78e713fcd37172f845f576.tar.gz
lz4-58a1616d7b272e624f78e713fcd37172f845f576.tar.bz2
Merge remote-tracking branch 'refs/remotes/Cyan4973/dev' into dev
# Conflicts: # programs/Makefile
Diffstat (limited to 'programs/lz4cli.c')
-rw-r--r--programs/lz4cli.c69
1 files changed, 28 insertions, 41 deletions
diff --git a/programs/lz4cli.c b/programs/lz4cli.c
index 3e952c6..961bea1 100644
--- a/programs/lz4cli.c
+++ b/programs/lz4cli.c
@@ -62,6 +62,8 @@
#include "bench.h" /* BMK_benchFile, BMK_SetNbIterations, BMK_SetBlocksize, BMK_SetPause */
#include "lz4io.h" /* LZ4IO_compressFilename, LZ4IO_decompressFilename, LZ4IO_compressMultipleFilenames */
#include "lz4hc.h" /* LZ4HC_DEFAULT_CLEVEL */
+#include "lz4.h" /* LZ4_VERSION_STRING */
+
/****************************
* OS-specific Includes
@@ -84,11 +86,8 @@
* Constants
******************************/
#define COMPRESSOR_NAME "LZ4 command line interface"
-#ifndef LZ4_VERSION
-# define LZ4_VERSION "r132"
-#endif
#define AUTHOR "Yann Collet"
-#define WELCOME_MESSAGE "*** %s %i-bits %s, by %s (%s) ***\n", COMPRESSOR_NAME, (int)(sizeof(void*)*8), LZ4_VERSION, AUTHOR, __DATE__
+#define WELCOME_MESSAGE "*** %s %i-bits v%s, by %s ***\n", COMPRESSOR_NAME, (int)(sizeof(void*)*8), LZ4_VERSION_STRING, AUTHOR
#define LZ4_EXTENSION ".lz4"
#define LZ4CAT "lz4cat"
#define UNLZ4 "unlz4"
@@ -342,7 +341,6 @@ int main(int argc, const char** argv)
if (!strcmp(argument, "--version")) { DISPLAY(WELCOME_MESSAGE); return 0; }
if (!strcmp(argument, "--keep")) { continue; } /* keep source file (default anyway; just for xz/lzma compatibility) */
-
/* Short commands (note : aggregated short commands are allowed) */
if (argument[0]=='-') {
/* '-' means stdin/stdout */
@@ -411,8 +409,7 @@ int main(int argc, const char** argv)
/* Modify Block Properties */
case 'B':
- while (argument[1]!=0)
- {
+ while (argument[1]!=0) {
int exitBlockProperties=0;
switch(argument[1])
{
@@ -448,13 +445,10 @@ int main(int argc, const char** argv)
/* Modify Nb Iterations (benchmark only) */
case 'i':
- { unsigned iters = 0;
- while ((argument[1] >='0') && (argument[1] <='9'))
- {
- iters *= 10;
- iters += argument[1] - '0';
- argument++;
- }
+ { unsigned iters;
+ argument++;
+ iters = readU32FromChar(&argument);
+ argument--;
BMK_setNbIterations(iters);
}
break;
@@ -479,8 +473,7 @@ int main(int argc, const char** argv)
if (!input_filename) { input_filename=argument; continue; }
/* Second non-option arg in output_filename to preserve original cli logic. */
- if (!output_filename)
- {
+ if (!output_filename) {
output_filename=argument;
if (!strcmp (output_filename, nullOutput)) output_filename = nulmark;
continue;
@@ -498,31 +491,26 @@ int main(int argc, const char** argv)
if(!input_filename) { input_filename=stdinmark; }
/* Check if input is defined as console; trigger an error in this case */
- if (!strcmp(input_filename, stdinmark) && IS_CONSOLE(stdin) )
- {
+ if (!strcmp(input_filename, stdinmark) && IS_CONSOLE(stdin) ) {
DISPLAYLEVEL(1, "refusing to read from a console\n");
exit(1);
}
/* Check if benchmark is selected */
- if (bench)
- {
+ if (bench) {
int bmkResult = BMK_benchFiles(inFileNames, ifnIdx, cLevel, cLevelLast);
free((void*)inFileNames);
return bmkResult;
}
/* No output filename ==> try to select one automatically (when possible) */
- while (!output_filename)
- {
+ while (!output_filename) {
if (!IS_CONSOLE(stdout)) { output_filename=stdoutmark; break; } /* Default to stdout whenever possible (i.e. not a console) */
- if ((!decode) && !(forceCompress)) /* auto-determine compression or decompression, based on file extension */
- {
+ if ((!decode) && !(forceCompress)) { /* auto-determine compression or decompression, based on file extension */
size_t const l = strlen(input_filename);
if (!strcmp(input_filename+(l-4), LZ4_EXTENSION)) decode=1;
}
- if (!decode) /* compression to file */
- {
+ if (!decode) { /* compression to file */
size_t const l = strlen(input_filename);
dynNameSpace = (char*)calloc(1,l+5);
if (dynNameSpace==NULL) exit(1);
@@ -533,8 +521,7 @@ int main(int argc, const char** argv)
break;
}
/* decompression to file (automatic name will work only if input filename has correct format extension) */
- {
- size_t outl;
+ { size_t outl;
size_t inl = strlen(input_filename);
dynNameSpace = (char*)calloc(1,inl+1);
strcpy(dynNameSpace, input_filename);
@@ -560,21 +547,21 @@ int main(int argc, const char** argv)
/* IO Stream/File */
LZ4IO_setNotificationLevel(displayLevel);
if (decode) {
- if (multiple_inputs)
- operationResult = LZ4IO_decompressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION);
- else
- DEFAULT_DECOMPRESSOR(input_filename, output_filename);
- } else {
- /* compression is default action */
- if (legacy_format) {
- DISPLAYLEVEL(3, "! Generating compressed LZ4 using Legacy format (deprecated) ! \n");
- LZ4IO_compressFilename_Legacy(input_filename, output_filename, cLevel);
- } else {
if (multiple_inputs)
- operationResult = LZ4IO_compressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION, cLevel);
+ operationResult = LZ4IO_decompressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION);
else
- DEFAULT_COMPRESSOR(input_filename, output_filename, cLevel);
- }
+ DEFAULT_DECOMPRESSOR(input_filename, output_filename);
+ } else {
+ /* compression is default action */
+ if (legacy_format) {
+ DISPLAYLEVEL(3, "! Generating compressed LZ4 using Legacy format (deprecated) ! \n");
+ LZ4IO_compressFilename_Legacy(input_filename, output_filename, cLevel);
+ } else {
+ if (multiple_inputs)
+ operationResult = LZ4IO_compressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION, cLevel);
+ else
+ DEFAULT_COMPRESSOR(input_filename, output_filename, cLevel);
+ }
}
_cleanup: