fix zstdcat
diff --git a/NEWS b/NEWS
index eaae710..0b3dd92 100644
--- 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
diff --git a/programs/fileio.c b/programs/fileio.c
index 446799a..dff4eae 100644
--- a/programs/fileio.c
+++ b/programs/fileio.c
@@ -700,7 +700,7 @@
@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 @@
#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 @@
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 @@
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);
diff --git a/programs/fileio.h b/programs/fileio.h
index a740f35..06e0be3 100644
--- a/programs/fileio.h
+++ b/programs/fileio.h
@@ -18,7 +18,7 @@
/* *************************************
* Special i/o constants
**************************************/
-#define stdinmark "/*stdin*\\"
+#define stdinmark "/*stdin*\\"
#define stdoutmark "/*stdout*\\"
#ifdef _WIN32
# define nulmark "nul"
diff --git a/programs/zstd.1 b/programs/zstd.1
index 9d91b51..63b60d1 100644
--- a/programs/zstd.1
+++ b/programs/zstd.1
@@ -22,7 +22,7 @@
.br
.B zstdcat
is equivalent to
-.BR "zstd \-dc"
+.BR "zstd \-dcf"
.br
.SH DESCRIPTION
diff --git a/programs/zstdcli.c b/programs/zstdcli.c
index 63ee99d..c7c682b 100644
--- a/programs/zstdcli.c
+++ b/programs/zstdcli.c
@@ -191,10 +191,15 @@
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 @@
nextArgumentIsOutFileName=0,
nextArgumentIsMaxDict=0,
nextArgumentIsDictID=0,
- nextArgumentIsFile=0,
+ nextArgumentsAreFiles=0,
ultra=0,
lastCommand = 0;
zstd_operation_mode operation = zom_compress;
@@ -252,45 +257,15 @@
/* 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 @@
/* 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");
diff --git a/tests/playTests.sh b/tests/playTests.sh
index c539d56..dfca1de 100755
--- a/tests/playTests.sh
+++ b/tests/playTests.sh
@@ -100,8 +100,10 @@
$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 **** "