]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fix zstdcat
authorYann Collet <cyan@fb.com>
Fri, 2 Dec 2016 23:18:57 +0000 (15:18 -0800)
committerYann Collet <cyan@fb.com>
Fri, 2 Dec 2016 23:18:57 +0000 (15:18 -0800)
NEWS
programs/fileio.c
programs/fileio.h
programs/zstd.1
programs/zstdcli.c
tests/playTests.sh

diff --git a/NEWS b/NEWS
index eaae710ce1e4ce6013f20ca19622231afc3ada3e..0b3dd92a50114e073bc9df5141c0368f5e967be9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,7 +1,9 @@
 v1.1.2
 Improved : faster decompression speed at ultra compression settings and in 32-bits mode
-cli : new : preserve file attributes, by Przemyslaw Skibinski
+cli : new : gzstd, experimental version able to decode .gz files, by Przemyslaw Skibinski
+cli : new : preserve file attributes
 cli : fixed : status displays total amount decoded, even for file consisting of multiple frames (like pzstd)
+cli : fixed : zstdcat
 API : changed : zbuff prototypes now generate deprecation warnings
 Changed : reduced stack memory use
 
index 446799af8f9dd36b49f7987f461da98a2c325727..dff4eae05f12c8027441f2d3e8fdddb5a1297710 100644 (file)
@@ -700,7 +700,7 @@ static unsigned long long FIO_decompressGzFrame(dRess_t ress, FILE* srcFile, con
     @return : 0 : OK
               1 : operation not started
 */
-static int FIO_decompressSrcFile(dRess_t ress, const char* srcFileName)
+static int FIO_decompressSrcFile(dRess_t ress, const char* dstFileName, const char* srcFileName)
 {
     FILE* srcFile;
     unsigned readSomething = 0;
@@ -737,7 +737,7 @@ static int FIO_decompressSrcFile(dRess_t ress, const char* srcFileName)
 #endif
         } else {
             if (!ZSTD_isFrame(ress.srcBuffer, toRead)) {
-                if ((g_overwrite) && !strcmp (srcFileName, stdinmark)) {  /* pass-through mode */
+                if ((g_overwrite) && !strcmp (dstFileName, stdoutmark)) {  /* pass-through mode */
                     unsigned const result = FIO_passThrough(ress.dstFile, srcFile, ress.srcBuffer, ress.srcBufferSize);
                     if (fclose(srcFile)) EXM_THROW(32, "zstd: %s close error", srcFileName);  /* error should never happen */
                     return result;
@@ -777,7 +777,7 @@ static int FIO_decompressDstFile(dRess_t ress,
     if (ress.dstFile==0) return 1;
 
     if (strcmp (srcFileName, stdinmark) && UTIL_getFileStat(srcFileName, &statbuf)) stat_result = 1;
-    result = FIO_decompressSrcFile(ress, srcFileName);
+    result = FIO_decompressSrcFile(ress, dstFileName, srcFileName);
 
     if (fclose(ress.dstFile)) EXM_THROW(38, "Write error : cannot properly close %s", dstFileName);
 
@@ -814,12 +814,12 @@ int FIO_decompressMultipleFilenames(const char** srcNamesTable, unsigned nbFiles
 
     if (suffix==NULL) EXM_THROW(70, "zstd: decompression: unknown dst");   /* should never happen */
 
-    if (!strcmp(suffix, stdoutmark) || !strcmp(suffix, nulmark)) {
+    if (!strcmp(suffix, stdoutmark) || !strcmp(suffix, nulmark)) {  /* special cases : -c or -t */
         unsigned u;
         ress.dstFile = FIO_openDstFile(suffix);
         if (ress.dstFile == 0) EXM_THROW(71, "cannot open %s", suffix);
         for (u=0; u<nbFiles; u++)
-            missingFiles += FIO_decompressSrcFile(ress, srcNamesTable[u]);
+            missingFiles += FIO_decompressSrcFile(ress, suffix, srcNamesTable[u]);
         if (fclose(ress.dstFile)) EXM_THROW(72, "Write error : cannot properly close stdout");
     } else {
         size_t const suffixSize = strlen(suffix);
index a740f35efde5a4dfab82ce6f465e1bd853f76595..06e0be372ffa385c85585d7b1ca08d5fa5618914 100644 (file)
@@ -18,7 +18,7 @@ extern "C" {
 /* *************************************
 *  Special i/o constants
 **************************************/
-#define stdinmark "/*stdin*\\"
+#define stdinmark  "/*stdin*\\"
 #define stdoutmark "/*stdout*\\"
 #ifdef _WIN32
 #  define nulmark "nul"
index 9d91b51001ae3a71a08cf848a5163b6f888ad0d6..63b60d1e925d04f78bd4de4c7f87cdca6d3a8b21 100644 (file)
@@ -22,7 +22,7 @@ is equivalent to
 .br
 .B zstdcat
 is equivalent to
-.BR "zstd \-dc"
+.BR "zstd \-dcf"
 .br
 
 .SH DESCRIPTION
index 63ee99dac09015f2112161d0a7403f9492621544..c7c682bb3b4dfcf782078a56092f9e1f410ec1e5 100644 (file)
@@ -191,10 +191,15 @@ static unsigned readU32FromChar(const char** stringPtr)
     return result;
 }
 
+/** longCommandWArg() :
+ *  check is *stringPtr is the same as longCommand.
+ *  If yes, @return 1 and advances *stringPtr to the position which immediately follows longCommand.
+ *  @return 0 and doesn't modify *stringPtr otherwise.
+ */
 static unsigned longCommandWArg(const char** stringPtr, const char* longCommand)
 {
     size_t const comSize = strlen(longCommand);
-    unsigned const result = !strncmp(*stringPtr, longCommand, comSize);
+    int const result = !strncmp(*stringPtr, longCommand, comSize);
     if (result) *stringPtr += comSize;
     return result;
 }
@@ -213,7 +218,7 @@ int main(int argCount, const char* argv[])
         nextArgumentIsOutFileName=0,
         nextArgumentIsMaxDict=0,
         nextArgumentIsDictID=0,
-        nextArgumentIsFile=0,
+        nextArgumentsAreFiles=0,
         ultra=0,
         lastCommand = 0;
     zstd_operation_mode operation = zom_compress;
@@ -252,45 +257,15 @@ int main(int argCount, const char* argv[])
 
     /* preset behaviors */
     if (!strcmp(programName, ZSTD_UNZSTD)) operation=zom_decompress;
-    if (!strcmp(programName, ZSTD_CAT)) { operation=zom_decompress; forceStdout=1; displayLevel=1; outFileName=stdoutmark; }
+    if (!strcmp(programName, ZSTD_CAT)) { operation=zom_decompress; forceStdout=1; FIO_overwriteMode(); outFileName=stdoutmark; displayLevel=1; }
 
     /* command switches */
     for (argNb=1; argNb<argCount; argNb++) {
         const char* argument = argv[argNb];
         if(!argument) continue;   /* Protection if argument empty */
 
-        if (nextArgumentIsFile==0) {
-
-            /* long commands (--long-word) */
-            if (!strcmp(argument, "--")) { nextArgumentIsFile=1; continue; }   /* only file names allowed from now on */
-            if (!strcmp(argument, "--compress")) { operation=zom_compress; continue; }
-            if (!strcmp(argument, "--decompress")) { operation=zom_decompress; continue; }
-            if (!strcmp(argument, "--uncompress")) { operation=zom_decompress; continue; }
-            if (!strcmp(argument, "--force")) { FIO_overwriteMode(); continue; }
-            if (!strcmp(argument, "--version")) { displayOut=stdout; DISPLAY(WELCOME_MESSAGE); CLEAN_RETURN(0); }
-            if (!strcmp(argument, "--help")) { displayOut=stdout; CLEAN_RETURN(usage_advanced(programName)); }
-            if (!strcmp(argument, "--verbose")) { displayLevel++; continue; }
-            if (!strcmp(argument, "--quiet")) { displayLevel--; continue; }
-            if (!strcmp(argument, "--stdout")) { forceStdout=1; outFileName=stdoutmark; displayLevel-=(displayLevel==2); continue; }
-            if (!strcmp(argument, "--ultra")) { ultra=1; continue; }
-            if (!strcmp(argument, "--check")) { FIO_setChecksumFlag(2); continue; }
-            if (!strcmp(argument, "--no-check")) { FIO_setChecksumFlag(0); continue; }
-            if (!strcmp(argument, "--no-dictID")) { FIO_setDictIDFlag(0); continue; }
-            if (!strcmp(argument, "--sparse")) { FIO_setSparseWrite(2); continue; }
-            if (!strcmp(argument, "--no-sparse")) { FIO_setSparseWrite(0); continue; }
-            if (!strcmp(argument, "--test")) { operation=zom_test; continue; }
-            if (!strcmp(argument, "--train")) { operation=zom_train; outFileName=g_defaultDictName; continue; }
-            if (!strcmp(argument, "--maxdict")) { nextArgumentIsMaxDict=1; lastCommand=1; continue; }
-            if (!strcmp(argument, "--dictID")) { nextArgumentIsDictID=1; lastCommand=1; continue; }
-            if (!strcmp(argument, "--keep")) { FIO_setRemoveSrcFile(0); continue; }
-            if (!strcmp(argument, "--rm")) { FIO_setRemoveSrcFile(1); continue; }
-
-            /* long commands with arguments */
-            if (longCommandWArg(&argument, "--memlimit=")) { memLimit = readU32FromChar(&argument); continue; }
-            if (longCommandWArg(&argument, "--memory=")) { memLimit = readU32FromChar(&argument); continue; }
-            if (longCommandWArg(&argument, "--memlimit-decompress=")) { memLimit = readU32FromChar(&argument); continue; }
-
-            /* '-' means stdin/stdout */
+        if (nextArgumentsAreFiles==0) {
+            /* "-" means stdin/stdout */
             if (!strcmp(argument, "-")){
                 if (!filenameIdx) {
                     filenameIdx=1, filenameTable[0]=stdinmark;
@@ -301,8 +276,40 @@ int main(int argCount, const char* argv[])
 
             /* Decode commands (note : aggregated commands are allowed) */
             if (argument[0]=='-') {
-                argument++;
 
+                if (argument[1]=='-') {
+                    /* long commands (--long-word) */
+                    if (!strcmp(argument, "--")) { nextArgumentsAreFiles=1; continue; }   /* only file names allowed from now on */
+                    if (!strcmp(argument, "--compress")) { operation=zom_compress; continue; }
+                    if (!strcmp(argument, "--decompress")) { operation=zom_decompress; continue; }
+                    if (!strcmp(argument, "--uncompress")) { operation=zom_decompress; continue; }
+                    if (!strcmp(argument, "--force")) { FIO_overwriteMode(); continue; }
+                    if (!strcmp(argument, "--version")) { displayOut=stdout; DISPLAY(WELCOME_MESSAGE); CLEAN_RETURN(0); }
+                    if (!strcmp(argument, "--help")) { displayOut=stdout; CLEAN_RETURN(usage_advanced(programName)); }
+                    if (!strcmp(argument, "--verbose")) { displayLevel++; continue; }
+                    if (!strcmp(argument, "--quiet")) { displayLevel--; continue; }
+                    if (!strcmp(argument, "--stdout")) { forceStdout=1; outFileName=stdoutmark; displayLevel-=(displayLevel==2); continue; }
+                    if (!strcmp(argument, "--ultra")) { ultra=1; continue; }
+                    if (!strcmp(argument, "--check")) { FIO_setChecksumFlag(2); continue; }
+                    if (!strcmp(argument, "--no-check")) { FIO_setChecksumFlag(0); continue; }
+                    if (!strcmp(argument, "--sparse")) { FIO_setSparseWrite(2); continue; }
+                    if (!strcmp(argument, "--no-sparse")) { FIO_setSparseWrite(0); continue; }
+                    if (!strcmp(argument, "--test")) { operation=zom_test; continue; }
+                    if (!strcmp(argument, "--train")) { operation=zom_train; outFileName=g_defaultDictName; continue; }
+                    if (!strcmp(argument, "--maxdict")) { nextArgumentIsMaxDict=1; lastCommand=1; continue; }
+                    if (!strcmp(argument, "--dictID")) { nextArgumentIsDictID=1; lastCommand=1; continue; }
+                    if (!strcmp(argument, "--no-dictID")) { FIO_setDictIDFlag(0); continue; }
+                    if (!strcmp(argument, "--keep")) { FIO_setRemoveSrcFile(0); continue; }
+                    if (!strcmp(argument, "--rm")) { FIO_setRemoveSrcFile(1); continue; }
+
+                    /* long commands with arguments */
+                    if (longCommandWArg(&argument, "--memlimit=")) { memLimit = readU32FromChar(&argument); continue; }
+                    if (longCommandWArg(&argument, "--memory=")) { memLimit = readU32FromChar(&argument); continue; }
+                    if (longCommandWArg(&argument, "--memlimit-decompress=")) { memLimit = readU32FromChar(&argument); continue; }
+                    /* fall-through, will trigger bad_usage() later on */
+                }
+
+                argument++;
                 while (argument[0]!=0) {
                     if (lastCommand) {
                         DISPLAY("error : command must be followed by argument \n");
index c539d567f58c23602613be4633551fe51a01bcdb..dfca1de87e72d12ab8fdaab9ad78f021f5dd3d0d 100755 (executable)
@@ -100,8 +100,10 @@ ls tmp.zst && die "tmp.zst should not be created"
 
 
 $ECHO "\n**** Pass-Through mode **** "
-$ECHO "Hello world !" | $ZSTD -df
-$ECHO "Hello world !" | $ZSTD -dcf
+$ECHO "Hello world 1!" | $ZSTD -df
+$ECHO "Hello world 2!" | $ZSTD -dcf
+$ECHO "Hello world 3!" > tmp1
+$ZSTD -dcf tmp1
 
 
 $ECHO "\n**** frame concatenation **** "