summaryrefslogtreecommitdiffstats
path: root/programs/lz4cli.c
diff options
context:
space:
mode:
Diffstat (limited to 'programs/lz4cli.c')
-rw-r--r--programs/lz4cli.c64
1 files changed, 44 insertions, 20 deletions
diff --git a/programs/lz4cli.c b/programs/lz4cli.c
index f77be3d..e49bbcb 100644
--- a/programs/lz4cli.c
+++ b/programs/lz4cli.c
@@ -42,13 +42,6 @@
/**************************************
* Compiler Options
***************************************/
-/* Disable some Visual warning messages */
-#ifdef _MSC_VER
-# define _CRT_SECURE_NO_WARNINGS
-# define _CRT_SECURE_NO_DEPRECATE /* VS2005 */
-# pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
-#endif
-
/* cf. http://man7.org/linux/man-pages/man7/feature_test_macros.7.html */
#define _XOPEN_VERSION 600 /* POSIX.2001, for fileno() within <stdio.h> on unix */
@@ -56,6 +49,7 @@
/****************************
* Includes
*****************************/
+#include "util.h" /* Compiler options, UTIL_HAS_CREATEFILELIST */
#include <stdio.h> /* fprintf, getchar */
#include <stdlib.h> /* exit, calloc, free */
#include <string.h> /* strcmp, strlen */
@@ -171,6 +165,9 @@ static int usage_advanced(void)
DISPLAY( " -c : force write to standard output, even if it is the console\n");
DISPLAY( " -t : test compressed file integrity\n");
DISPLAY( " -m : multiple input files (implies automatic output filenames)\n");
+#ifdef UTIL_HAS_CREATEFILELIST
+ DISPLAY( " -r : operate recursively on directories (sets also -m)\n");
+#endif
DISPLAY( " -l : compress using Legacy format (Linux kernel compression)\n");
DISPLAY( " -B# : Block size [4-7](default : 7)\n");
DISPLAY( " -BD : Block dependency (improve compression ratio)\n");
@@ -179,10 +176,9 @@ static int usage_advanced(void)
DISPLAY( "--content-size : compressed frame includes original size (default:not present)\n");
DISPLAY( "--[no-]sparse : sparse mode (default:enabled on file, disabled on stdout)\n");
DISPLAY( "Benchmark arguments :\n");
- DISPLAY( "Benchmark arguments :\n");
DISPLAY( " -b# : benchmark file(s), using # compression level (default : 1) \n");
- DISPLAY( " -e# : test all compression levels from -bX to # (default: 1)\n");
- DISPLAY( " -i# : iteration loops [1-9](default : 3), benchmark mode only\n");
+ DISPLAY( " -e# : test all compression levels from -bX to # (default : 1)\n");
+ DISPLAY( " -i# : minimum evaluation time in seconds (default : 3s)\n");
#if defined(ENABLE_LZ4C_LEGACY_OPTIONS)
DISPLAY( "Legacy arguments :\n");
DISPLAY( " -c0 : fast compression\n");
@@ -304,6 +300,11 @@ int main(int argc, const char** argv)
char nullOutput[] = NULL_OUTPUT;
char extension[] = LZ4_EXTENSION;
int blockSize;
+#ifdef UTIL_HAS_CREATEFILELIST
+ const char** extendedFileList = NULL;
+ char* fileNamesBuf = NULL;
+ unsigned fileNamesNb, recursive=0;
+#endif
/* Init */
programName = argv[0];
@@ -419,7 +420,7 @@ int main(int argc, const char** argv)
case '7':
{ int B = argument[1] - '0';
blockSize = LZ4IO_setBlockSizeID(B);
- BMK_setBlocksize(blockSize);
+ BMK_SetBlockSize(blockSize);
argument++;
break;
}
@@ -437,24 +438,28 @@ int main(int argc, const char** argv)
inFileNames = (const char**) malloc(argc * sizeof(char*));
break;
+#ifdef UTIL_HAS_CREATEFILELIST
+ /* recursive */
+ case 'r': recursive=1; /* without break */
+#endif
/* Treat non-option args as input files. See https://code.google.com/p/lz4/issues/detail?id=151 */
case 'm': multiple_inputs=1;
if (inFileNames == NULL)
inFileNames = (const char**) malloc(argc * sizeof(char*));
break;
- /* Modify Nb Iterations (benchmark only) */
+ /* Modify Nb Seconds (benchmark only) */
case 'i':
{ unsigned iters;
argument++;
iters = readU32FromChar(&argument);
argument--;
- BMK_setNbIterations(iters);
+ BMK_SetNbSeconds(iters);
}
break;
/* Pause at the end (hidden option) */
- case 'p': main_pause=1; BMK_setPause(); break;
+ case 'p': main_pause=1; break;
/* Specific commands for customized versions */
EXTENDED_ARGUMENTS;
@@ -487,7 +492,22 @@ int main(int argc, const char** argv)
if (!decode) DISPLAYLEVEL(4, "Blocks size : %i KB\n", blockSize>>10);
/* No input filename ==> use stdin */
- if (multiple_inputs) input_filename = inFileNames[0], output_filename = (const char*)(inFileNames[0]);
+ if (multiple_inputs) {
+ input_filename = inFileNames[0];
+ output_filename = (const char*)(inFileNames[0]);
+#ifdef UTIL_HAS_CREATEFILELIST
+ if (recursive) { /* at this stage, filenameTable is a list of paths, which can contain both files and directories */
+ extendedFileList = UTIL_createFileList(inFileNames, ifnIdx, &fileNamesBuf, &fileNamesNb);
+ if (extendedFileList) {
+ unsigned u;
+ for (u=0; u<fileNamesNb; u++) DISPLAYLEVEL(4, "%u %s\n", u, extendedFileList[u]);
+ free((void*)inFileNames);
+ inFileNames = extendedFileList;
+ ifnIdx = fileNamesNb;
+ }
+ }
+#endif
+ }
if(!input_filename) { input_filename=stdinmark; }
/* Check if input is defined as console; trigger an error in this case */
@@ -498,9 +518,8 @@ int main(int argc, const char** argv)
/* Check if benchmark is selected */
if (bench) {
- int bmkResult = BMK_benchFiles(inFileNames, ifnIdx, cLevel, cLevelLast);
- free((void*)inFileNames);
- return bmkResult;
+ operationResult = BMK_benchFiles(inFileNames, ifnIdx, cLevel, cLevelLast);
+ goto _cleanup;
}
/* No output filename ==> try to select one automatically (when possible) */
@@ -566,7 +585,12 @@ int main(int argc, const char** argv)
_cleanup:
if (main_pause) waitEnter();
- free(dynNameSpace);
- free((void*)inFileNames);
+ if (dynNameSpace) free(dynNameSpace);
+#ifdef UTIL_HAS_CREATEFILELIST
+ if (extendedFileList)
+ UTIL_freeFileList(extendedFileList, fileNamesBuf);
+ else
+#endif
+ free((void*)inFileNames);
return operationResult;
}