]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
zstdcli: -r (operate recursively on directories) works with dictBuilder and compression
authorinikep <inikep@gmail.com>
Wed, 25 May 2016 13:30:55 +0000 (15:30 +0200)
committerinikep <inikep@gmail.com>
Wed, 25 May 2016 13:30:55 +0000 (15:30 +0200)
lib/common/zbuff_static.h
programs/bench.c
programs/bench.h
programs/util.h
programs/zbufftest.c
programs/zstdcli.c

index 6a4287e4df2c1b51285e286a65a24413227be3d7..c50a3e1667204816885d8c8ee714057ea37a6e6a 100644 (file)
@@ -47,9 +47,7 @@ extern "C" {
 #include "zstd_static.h"     /* ZSTD_parameters */
 #include "zbuff.h"
 
-#ifndef MIN
-    #define MIN(a,b) ((a)<(b) ? (a) : (b))
-#endif
+#define ZBUFF_MIN(a,b) ((a)<(b) ? (a) : (b))
 
 
 /*-*************************************
@@ -73,7 +71,7 @@ ZSTDLIB_API size_t ZBUFF_compressInit_advanced(ZBUFF_CCtx* cctx,
 
 MEM_STATIC size_t ZBUFF_limitCopy(void* dst, size_t dstCapacity, const void* src, size_t srcSize)
 {
-    size_t length = MIN(dstCapacity, srcSize);
+    size_t length = ZBUFF_MIN(dstCapacity, srcSize);
     memcpy(dst, src, length);
     return length;
 }
index a2721552e2d9420caf025a94b75f40495eb1f0ff..52c64d5254efeb5c15bc03652af1dfc4cb4b7bc2 100644 (file)
@@ -26,7 +26,7 @@
 /* *************************************
 *  Includes
 ***************************************/
-#include "util.h"        /* Compiler options, UTIL_GetFileSize, UTIL_HAS_CREATEFILELIST, UTIL_sleep */
+#include "util.h"        /* Compiler options, UTIL_GetFileSize, UTIL_sleep */
 #include <stdlib.h>      /* malloc, free */
 #include <string.h>      /* memset */
 #include <stdio.h>       /* fprintf, fopen, ftello64 */
@@ -495,32 +495,14 @@ static void BMK_syntheticTest(int cLevel, int cLevelLast, double compressibility
 
 
 int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles,
-                   const char* dictFileName, int cLevel, int cLevelLast, int recursive)
+                   const char* dictFileName, int cLevel, int cLevelLast)
 {
     double const compressibility = (double)g_compressibilityDefault / 100;
 
     if (nbFiles == 0)
         BMK_syntheticTest(cLevel, cLevelLast, compressibility);
     else
-    {
-#ifdef UTIL_HAS_CREATEFILELIST
-        if (recursive) {
-            char* buf;
-            const char** filenameTable;
-            unsigned i;
-            filenameTable = UTIL_createFileList(fileNamesTable, nbFiles, &buf, &nbFiles);
-            if (filenameTable) {
-                for (i=0; i<nbFiles; i++) DISPLAYLEVEL(3, "%d %s\n", i, filenameTable[i]);
-                BMK_benchFileTable(filenameTable, nbFiles, dictFileName, cLevel, cLevelLast);
-                UTIL_freeFileList(filenameTable, buf);
-            }
-        }
-        else BMK_benchFileTable(fileNamesTable, nbFiles, dictFileName, cLevel, cLevelLast);
-#else
-        (void)recursive;
         BMK_benchFileTable(fileNamesTable, nbFiles, dictFileName, cLevel, cLevelLast);
-#endif
-    }
     return 0;
 }
 
index 9acac071d305d67f115281a4f2a6279340381b7c..74ac20f9aedff92147680cba47f8f5629df3b23e 100644 (file)
@@ -26,7 +26,7 @@
 
 /* Main function */
 int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles,
-                   const char* dictFileName, int cLevel, int cLevelLast, int recursive);
+                   const char* dictFileName, int cLevel, int cLevelLast);
 
 /* Set Parameters */
 void BMK_SetNbIterations(unsigned nbLoops);
index f8b4dcb6c7299bb77239aff1d86b223c32c25df6..2b739dc3b376e50eb44796dcac1689497824711b 100644 (file)
@@ -345,8 +345,7 @@ UTIL_STATIC const char** UTIL_createFileList(const char **inputNames, unsigned i
     bufend = buf + LIST_SIZE_INCREASE;
 
     for (i=0, pos=0, nbFiles=0; i<inputNamesNb; i++) {
-        if (UTIL_doesFileExists(inputNames[i])) {
-       // printf ("UTIL_doesFileExists=[%s]\n", inputNames[i]);
+        if (!UTIL_isDirectory(inputNames[i])) {
             size_t len = strlen(inputNames[i]);
             if (buf + pos + len >= bufend) {
                 ptrdiff_t newListSize = (bufend - buf) + LIST_SIZE_INCREASE;
index c780b8f4e5d9124516a75dbc8974cf32e14178c8..fce0ab27559e2c05e641bafccf9189218308eed3 100644 (file)
@@ -262,6 +262,8 @@ static size_t FUZ_randomLength(U32* seed, U32 maxLog)
     return FUZ_rLogLength(seed, logLength);
 }
 
+#define MIN(a,b)   ( (a) < (b) ? (a) : (b) )
+
 #define CHECK(cond, ...) if (cond) { DISPLAY("Error => "); DISPLAY(__VA_ARGS__); \
                          DISPLAY(" (seed %u, test nb %u)  \n", seed, testNb); goto _output_error; }
 
index 2151578738972920a1d92b3ac853233f1a02a81c..f367f49af0008cf80cf6a1f64c2d90bb3cb8c979 100644 (file)
@@ -129,6 +129,9 @@ static int usage_advanced(const char* programName)
     DISPLAY( " -v     : verbose mode\n");
     DISPLAY( " -q     : suppress warnings; specify twice to suppress errors too\n");
     DISPLAY( " -c     : force write to standard output, even if it is the console\n");
+#ifdef UTIL_HAS_CREATEFILELIST
+    DISPLAY( " -r     : operate recursively on directories\n");
+#endif
 #ifndef ZSTD_NOCOMPRESS
     DISPLAY( "--ultra : enable ultra modes (requires more memory to decompress)\n");
 #endif
@@ -147,9 +150,6 @@ static int usage_advanced(const char* programName)
     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)\n");
-#ifdef UTIL_HAS_CREATEFILELIST
-    DISPLAY( " -r     : operate recursively on directories\n");
-#endif
     DISPLAY( " -B#    : cut file into independent blocks of size # (default: no block)\n");
 #endif
     return 0;
@@ -198,6 +198,11 @@ int main(int argCount, const char** argv)
     unsigned maxDictSize = g_defaultMaxDictSize;
     unsigned dictCLevel = g_defaultDictCLevel;
     unsigned dictSelect = g_defaultSelectivityLevel;
+#ifdef UTIL_HAS_CREATEFILELIST
+    const char** fileNamesTable = NULL;
+    char* fileNamesBuf;
+    unsigned fileNamesNb;
+#endif
 
     /* init */
     (void)recursive; (void)cLevelLast; (void)dictCLevel;   /* not used when ZSTD_NOBENCH / ZSTD_NODICT set */
@@ -296,6 +301,9 @@ int main(int argCount, const char** argv)
                     /* dictionary name */
                 case 'o': nextArgumentIsOutFileName=1; argument++; break;
 
+                    /* recursive */
+                case 'r': recursive=1; argument++; break;
+
 #ifndef ZSTD_NOBENCH
                     /* Benchmark */
                 case 'b': bench=1; argument++; break;
@@ -322,9 +330,6 @@ int main(int argCount, const char** argv)
                     }
                     break;
 
-                    /* recursive */
-                case 'r': recursive=1; argument++; break;
-
                     /* cut input into blocks (benchmark only) */
                 case 'B':
                     {   size_t bSize = 0;
@@ -395,11 +400,24 @@ int main(int argCount, const char** argv)
     /* Welcome message (if verbose) */
     DISPLAYLEVEL(3, WELCOME_MESSAGE);
 
+#ifdef UTIL_HAS_CREATEFILELIST
+    if (recursive) {
+        fileNamesTable = UTIL_createFileList(filenameTable, filenameIdx, &fileNamesBuf, &fileNamesNb);
+        if (fileNamesTable) {
+            unsigned i;
+            for (i=0; i<fileNamesNb; i++) DISPLAYLEVEL(3, "%d %s\n", i, fileNamesTable[i]);
+            free((void*)filenameTable);
+            filenameTable = fileNamesTable;
+            filenameIdx = fileNamesNb;
+        }
+    }
+#endif
+
     /* Check if benchmark is selected */
     if (bench) {
 #ifndef ZSTD_NOBENCH
         BMK_setNotificationLevel(displayLevel);
-        BMK_benchFiles(filenameTable, filenameIdx, dictFileName, cLevel, cLevelLast, recursive);
+        BMK_benchFiles(filenameTable, filenameIdx, dictFileName, cLevel, cLevelLast);
 #endif
         goto _end;
     }
@@ -459,6 +477,11 @@ int main(int argCount, const char** argv)
 _end:
     if (main_pause) waitEnter();
     free(dynNameSpace);
-    free((void*)filenameTable);
+#ifdef UTIL_HAS_CREATEFILELIST
+    if (fileNamesTable)
+        UTIL_freeFileList(fileNamesTable, fileNamesBuf);
+    else
+#endif
+        free((void*)filenameTable);
     return operationResult;
 }