From: Yann Collet Date: Mon, 4 Jul 2016 16:16:16 +0000 (+0200) Subject: Added GNU separator `--`, to specifies that all following arguments are necessary... X-Git-Tag: v0.7.3^2~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f9cac7a734886bca1e1bc1f6450640ade42a4534;p=thirdparty%2Fzstd.git Added GNU separator `--`, to specifies that all following arguments are necessary file names (and not commands). Suggested by @chipturner (#230) --- diff --git a/NEWS b/NEWS index bb520df7d..88e8c3b1f 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,5 @@ v0.7.3 +added : `--` separator, stating that all following arguments are file names. Suggested by Chip Turner. added : OpenBSD target, by Juan Francisco Cantero Hurtado v0.7.2 diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c index 228205824..366637c0a 100644 --- a/lib/decompress/zstd_decompress.c +++ b/lib/decompress/zstd_decompress.c @@ -735,7 +735,7 @@ static seq_t ZSTD_decodeSequence(seqState_t* seqState) if (MEM_32bits() && (mlBits+llBits>24)) BIT_reloadDStream(&(seqState->DStream)); seq.litLength = LL_base[llCode] + ((llCode>15) ? BIT_readBits(&(seqState->DStream), llBits) : 0); /* <= 16 bits */ - if (MEM_32bits() | + if (MEM_32bits() || (totalBits > 64 - 7 - (LLFSELog+MLFSELog+OffFSELog)) ) BIT_reloadDStream(&(seqState->DStream)); /* ANS state update */ diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 129936e15..24fc33b7d 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -34,7 +34,7 @@ #include "util.h" /* Compiler options, UTIL_HAS_CREATEFILELIST */ #include /* strcmp, strlen */ #include /* toupper */ -#include +#include /* errno */ #include "fileio.h" #ifndef ZSTD_NOBENCH # include "bench.h" /* BMK_benchFiles, BMK_SetNbIterations */ @@ -205,7 +205,8 @@ int main(int argCount, const char** argv) dictBuild=0, nextArgumentIsOutFileName=0, nextArgumentIsMaxDict=0, - nextArgumentIsDictID=0; + nextArgumentIsDictID=0, + nextArgumentIsFile=0; unsigned cLevel = 1; unsigned cLevelLast = 1; unsigned recursive = 0; @@ -247,146 +248,165 @@ int main(int argCount, const char** argv) const char* argument = argv[argNb]; if(!argument) continue; /* Protection if argument empty */ - /* long commands (--long-word) */ - if (!strcmp(argument, "--decompress")) { decode=1; 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=4; continue; } - if (!strcmp(argument, "--quiet")) { displayLevel--; continue; } - if (!strcmp(argument, "--stdout")) { forceStdout=1; outFileName=stdoutmark; displayLevel-=(displayLevel==2); continue; } - if (!strcmp(argument, "--ultra")) { FIO_setMaxWLog(0); 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")) { decode=1; outFileName=nulmark; FIO_overwriteMode(); continue; } - if (!strcmp(argument, "--train")) { dictBuild=1; outFileName=g_defaultDictName; continue; } - if (!strcmp(argument, "--maxdict")) { nextArgumentIsMaxDict=1; continue; } - if (!strcmp(argument, "--dictID")) { nextArgumentIsDictID=1; continue; } - if (!strcmp(argument, "--keep")) { FIO_setRemoveSrcFile(0); continue; } - if (!strcmp(argument, "--rm")) { FIO_setRemoveSrcFile(1); continue; } - - /* '-' means stdin/stdout */ - if (!strcmp(argument, "-")){ - if (!filenameIdx) { - filenameIdx=1, filenameTable[0]=stdinmark; - outFileName=stdoutmark; - displayLevel-=(displayLevel==2); - continue; - } } + if (nextArgumentIsFile==0) { + + /* long commands (--long-word) */ + if (!strcmp(argument, "--")) { nextArgumentIsFile=1; continue; } + if (!strcmp(argument, "--decompress")) { decode=1; 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=4; continue; } + if (!strcmp(argument, "--quiet")) { displayLevel--; continue; } + if (!strcmp(argument, "--stdout")) { forceStdout=1; outFileName=stdoutmark; displayLevel-=(displayLevel==2); continue; } + if (!strcmp(argument, "--ultra")) { FIO_setMaxWLog(0); 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")) { decode=1; outFileName=nulmark; FIO_overwriteMode(); continue; } + if (!strcmp(argument, "--train")) { dictBuild=1; outFileName=g_defaultDictName; continue; } + if (!strcmp(argument, "--maxdict")) { nextArgumentIsMaxDict=1; continue; } + if (!strcmp(argument, "--dictID")) { nextArgumentIsDictID=1; continue; } + if (!strcmp(argument, "--keep")) { FIO_setRemoveSrcFile(0); continue; } + if (!strcmp(argument, "--rm")) { FIO_setRemoveSrcFile(1); continue; } + + /* '-' means stdin/stdout */ + if (!strcmp(argument, "-")){ + if (!filenameIdx) { + filenameIdx=1, filenameTable[0]=stdinmark; + outFileName=stdoutmark; + displayLevel-=(displayLevel==2); + continue; + } } - /* Decode commands (note : aggregated commands are allowed) */ - if (argument[0]=='-') { - argument++; + /* Decode commands (note : aggregated commands are allowed) */ + if (argument[0]=='-') { + argument++; - while (argument[0]!=0) { -#ifndef ZSTD_NOCOMPRESS - /* compression Level */ - if ((*argument>='0') && (*argument<='9')) { - cLevel = readU32FromChar(&argument); - dictCLevel = cLevel; - if (dictCLevel > ZSTD_maxCLevel()) - CLEAN_RETURN(badusage(programName)); - continue; - } -#endif + while (argument[0]!=0) { + #ifndef ZSTD_NOCOMPRESS + /* compression Level */ + if ((*argument>='0') && (*argument<='9')) { + cLevel = readU32FromChar(&argument); + dictCLevel = cLevel; + if (dictCLevel > ZSTD_maxCLevel()) + CLEAN_RETURN(badusage(programName)); + continue; + } + #endif - switch(argument[0]) - { - /* Display help */ - case 'V': displayOut=stdout; DISPLAY(WELCOME_MESSAGE); CLEAN_RETURN(0); /* Version Only */ - case 'H': - case 'h': displayOut=stdout; CLEAN_RETURN(usage_advanced(programName)); + switch(argument[0]) + { + /* Display help */ + case 'V': displayOut=stdout; DISPLAY(WELCOME_MESSAGE); CLEAN_RETURN(0); /* Version Only */ + case 'H': + case 'h': displayOut=stdout; CLEAN_RETURN(usage_advanced(programName)); - /* Decoding */ - case 'd': decode=1; argument++; break; + /* Decoding */ + case 'd': decode=1; argument++; break; - /* Force stdout, even if stdout==console */ - case 'c': forceStdout=1; outFileName=stdoutmark; displayLevel-=(displayLevel==2); argument++; break; + /* Force stdout, even if stdout==console */ + case 'c': forceStdout=1; outFileName=stdoutmark; displayLevel-=(displayLevel==2); argument++; break; - /* Use file content as dictionary */ - case 'D': nextEntryIsDictionary = 1; argument++; break; + /* Use file content as dictionary */ + case 'D': nextEntryIsDictionary = 1; argument++; break; - /* Overwrite */ - case 'f': FIO_overwriteMode(); forceStdout=1; argument++; break; + /* Overwrite */ + case 'f': FIO_overwriteMode(); forceStdout=1; argument++; break; - /* Verbose mode */ - case 'v': displayLevel=4; argument++; break; + /* Verbose mode */ + case 'v': displayLevel=4; argument++; break; - /* Quiet mode */ - case 'q': displayLevel--; argument++; break; + /* Quiet mode */ + case 'q': displayLevel--; argument++; break; - /* keep source file (default); for gzip/xz compatibility */ - case 'k': FIO_setRemoveSrcFile(0); argument++; break; + /* keep source file (default); for gzip/xz compatibility */ + case 'k': FIO_setRemoveSrcFile(0); argument++; break; - /* Checksum */ - case 'C': argument++; FIO_setChecksumFlag(2); break; + /* Checksum */ + case 'C': argument++; FIO_setChecksumFlag(2); break; - /* test compressed file */ - case 't': decode=1; outFileName=nulmark; argument++; break; + /* test compressed file */ + case 't': decode=1; outFileName=nulmark; argument++; break; - /* dictionary name */ - case 'o': nextArgumentIsOutFileName=1; argument++; break; + /* dictionary name */ + case 'o': nextArgumentIsOutFileName=1; argument++; break; - /* recursive */ - case 'r': recursive=1; argument++; break; + /* recursive */ + case 'r': recursive=1; argument++; break; -#ifndef ZSTD_NOBENCH - /* Benchmark */ - case 'b': bench=1; argument++; break; + #ifndef ZSTD_NOBENCH + /* Benchmark */ + case 'b': bench=1; argument++; break; - /* range bench (benchmark only) */ - case 'e': - /* compression Level */ + /* range bench (benchmark only) */ + case 'e': + /* compression Level */ + argument++; + cLevelLast = readU32FromChar(&argument); + break; + + /* Modify Nb Iterations (benchmark only) */ + case 'i': argument++; - cLevelLast = readU32FromChar(&argument); + { U32 const iters = readU32FromChar(&argument); + BMK_setNotificationLevel(displayLevel); + BMK_SetNbIterations(iters); + } break; - /* Modify Nb Iterations (benchmark only) */ - case 'i': - argument++; - { U32 const iters = readU32FromChar(&argument); - BMK_setNotificationLevel(displayLevel); - BMK_SetNbIterations(iters); - } - break; - - /* cut input into blocks (benchmark only) */ - case 'B': - argument++; - { size_t bSize = readU32FromChar(&argument); - if (toupper(*argument)=='K') bSize<<=10, argument++; /* allows using KB notation */ - if (toupper(*argument)=='M') bSize<<=20, argument++; - if (toupper(*argument)=='B') argument++; - BMK_setNotificationLevel(displayLevel); - BMK_SetBlockSize(bSize); - } - break; -#endif /* ZSTD_NOBENCH */ + /* cut input into blocks (benchmark only) */ + case 'B': + argument++; + { size_t bSize = readU32FromChar(&argument); + if (toupper(*argument)=='K') bSize<<=10, argument++; /* allows using KB notation */ + if (toupper(*argument)=='M') bSize<<=20, argument++; + if (toupper(*argument)=='B') argument++; + BMK_setNotificationLevel(displayLevel); + BMK_SetBlockSize(bSize); + } + break; + #endif /* ZSTD_NOBENCH */ - /* Dictionary Selection level */ - case 's': - argument++; - dictSelect = readU32FromChar(&argument); - break; + /* Dictionary Selection level */ + case 's': + argument++; + dictSelect = readU32FromChar(&argument); + break; - /* Pause at the end (-p) or set an additional param (-p#) (hidden option) */ - case 'p': argument++; -#ifndef ZSTD_NOBENCH - if ((*argument>='0') && (*argument<='9')) { - BMK_setAdditionalParam(readU32FromChar(&argument)); - } else -#endif - main_pause=1; - break; - /* unknown command */ - default : CLEAN_RETURN(badusage(programName)); + /* Pause at the end (-p) or set an additional param (-p#) (hidden option) */ + case 'p': argument++; + #ifndef ZSTD_NOBENCH + if ((*argument>='0') && (*argument<='9')) { + BMK_setAdditionalParam(readU32FromChar(&argument)); + } else + #endif + main_pause=1; + break; + /* unknown command */ + default : CLEAN_RETURN(badusage(programName)); + } } + continue; + } /* if (argument[0]=='-') */ + + if (nextArgumentIsMaxDict) { + nextArgumentIsMaxDict = 0; + maxDictSize = readU32FromChar(&argument); + if (toupper(*argument)=='K') maxDictSize <<= 10; + if (toupper(*argument)=='M') maxDictSize <<= 20; + continue; } - continue; - } /* if (argument[0]=='-') */ + + if (nextArgumentIsDictID) { + nextArgumentIsDictID = 0; + dictID = readU32FromChar(&argument); + continue; + } + + } /* if (nextArgumentIsAFile==0) */ if (nextEntryIsDictionary) { nextEntryIsDictionary = 0; @@ -401,20 +421,6 @@ int main(int argCount, const char** argv) continue; } - if (nextArgumentIsMaxDict) { - nextArgumentIsMaxDict = 0; - maxDictSize = readU32FromChar(&argument); - if (toupper(*argument)=='K') maxDictSize <<= 10; - if (toupper(*argument)=='M') maxDictSize <<= 20; - continue; - } - - if (nextArgumentIsDictID) { - nextArgumentIsDictID = 0; - dictID = readU32FromChar(&argument); - continue; - } - /* add filename to list */ filenameTable[filenameIdx++] = argument; }