Zstd cli : --version and --help write to stdout

This commit is contained in:
Yann Collet 2015-08-25 23:32:45 +01:00
parent c705567522
commit f44b2b02b4
4 changed files with 22 additions and 22 deletions

View File

@ -32,11 +32,10 @@
# ################################################################ # ################################################################
# Version number # Version number
export VERSION=0.1.0 export VERSION=0.1.1
export RELEASE=r$(VERSION)
DESTDIR?= DESTDIR?=
PREFIX ?= /usr PREFIX ?= /usr/local
LIBDIR ?= $(PREFIX)/lib LIBDIR ?= $(PREFIX)/lib
INCLUDEDIR=$(PREFIX)/include INCLUDEDIR=$(PREFIX)/include

View File

@ -1904,14 +1904,14 @@ static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 maxNbBits)
if (rankLast[nBitsToDecrease-1] == noOne) if (rankLast[nBitsToDecrease-1] == noOne)
rankLast[nBitsToDecrease-1] = rankLast[nBitsToDecrease]; // now there is one elt rankLast[nBitsToDecrease-1] = rankLast[nBitsToDecrease]; // now there is one elt
huffNode[rankLast[nBitsToDecrease]].nbBits ++; huffNode[rankLast[nBitsToDecrease]].nbBits ++;
if (rankLast[nBitsToDecrease] > 0) if (rankLast[nBitsToDecrease] == 0)
rankLast[nBitsToDecrease] = noOne;
else
{ {
rankLast[nBitsToDecrease]--; rankLast[nBitsToDecrease]--;
if (huffNode[rankLast[nBitsToDecrease]].nbBits != maxNbBits-nBitsToDecrease) if (huffNode[rankLast[nBitsToDecrease]].nbBits != maxNbBits-nBitsToDecrease)
rankLast[nBitsToDecrease] = noOne; // rank list emptied rankLast[nBitsToDecrease] = noOne; // rank list emptied
} }
else
rankLast[nBitsToDecrease] = noOne; // rank list emptied
} }
while (totalCost < 0) /* Sometimes, cost correction overshoot */ while (totalCost < 0) /* Sometimes, cost correction overshoot */

View File

@ -30,12 +30,12 @@
# fullbench32: Same as fullbench, but forced to compile in 32-bits mode # fullbench32: Same as fullbench, but forced to compile in 32-bits mode
# ########################################################################## # ##########################################################################
RELEASE?= v0.1.0 VERSION?= v0.1.1
DESTDIR?= DESTDIR?=
PREFIX ?= /usr PREFIX ?= /usr
CFLAGS ?= -O3 CFLAGS ?= -O3
CFLAGS += -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes -DZSTD_VERSION=\"$(RELEASE)\" CFLAGS += -std=c99 -Wall -Wextra -Wundef -Wshadow -Wcast-qual -Wcast-align -Wstrict-prototypes -DZSTD_VERSION=\"$(VERSION)\"
LDFLAGS = -I../lib LDFLAGS = -I../lib
FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(MOREFLAGS) FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(MOREFLAGS)
@ -43,7 +43,6 @@ BINDIR=$(PREFIX)/bin
MANDIR=$(PREFIX)/share/man/man1 MANDIR=$(PREFIX)/share/man/man1
ZSTDDIR=../lib ZSTDDIR=../lib
TEST_FILES = COPYING
TEST_TARGETS=test-native TEST_TARGETS=test-native

View File

@ -86,8 +86,9 @@
/************************************** /**************************************
* Display Macros * Display Macros
**************************************/ **************************************/
#define DISPLAY(...) fprintf(stderr, __VA_ARGS__) #define DISPLAY(...) fprintf(displayOut, __VA_ARGS__)
#define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); } #define DISPLAYLEVEL(l, ...) if (displayLevel>=l) { DISPLAY(__VA_ARGS__); }
static FILE* displayOut;
static unsigned displayLevel = 2; // 0 : no display // 1: errors // 2 : + result + interaction + warnings ; // 3 : + progression; // 4 : + information static unsigned displayLevel = 2; // 0 : no display // 1: errors // 2 : + result + interaction + warnings ; // 3 : + progression; // 4 : + information
@ -137,7 +138,7 @@ static int usage_advanced(const char* programName)
//DISPLAY( " -t : test compressed file integrity\n"); //DISPLAY( " -t : test compressed file integrity\n");
DISPLAY( "Benchmark arguments :\n"); DISPLAY( "Benchmark arguments :\n");
DISPLAY( " -b : benchmark file(s)\n"); DISPLAY( " -b : benchmark file(s)\n");
DISPLAY( " -i# : iteration loops [1-9](default : 3), benchmark mode only\n"); DISPLAY( " -i# : iteration loops [1-9](default : 3)\n");
return 0; return 0;
} }
@ -173,30 +174,31 @@ int main(int argc, char** argv)
char* dynNameSpace = NULL; char* dynNameSpace = NULL;
char extension[] = ZSTD_EXTENSION; char extension[] = ZSTD_EXTENSION;
displayOut = stderr;
/* Pick out basename component. Don't rely on stdlib because of conflicting behaviour. */ /* Pick out basename component. Don't rely on stdlib because of conflicting behaviour. */
for (i = (int)strlen(programName); i > 0; i--) for (i = (int)strlen(programName); i > 0; i--)
{ {
if (programName[i] == '/') if (programName[i] == '/') { i++; break; }
{
i++;
break;
}
} }
programName += i; programName += i;
/* zstdcat behavior */ /* zstdcat preset behavior */
if (!strcmp(programName, ZSTD_CAT)) { decode=1; forceStdout=1; displayLevel=1; outFileName=stdoutmark; } if (!strcmp(programName, ZSTD_CAT)) { decode=1; forceStdout=1; displayLevel=1; outFileName=stdoutmark; }
/* unzstd behavior */ /* unzstd preset behavior */
if (!strcmp(programName, ZSTD_UNZSTD)) if (!strcmp(programName, ZSTD_UNZSTD))
decode=1; decode=1;
// command switches /* command switches */
for(i=1; i<argc; i++) for(i=1; i<argc; i++)
{ {
char* argument = argv[i]; char* argument = argv[i];
if(!argument) continue; // Protection if argument empty if(!argument) continue; /* Protection if argument empty */
/* long commands (--long-word) */
if (!strcmp(argument, "--version")) { displayOut=stdout; DISPLAY(WELCOME_MESSAGE); return 0; }
if (!strcmp(argument, "--help")) { displayOut=stdout; return usage_advanced(programName); }
/* Decode commands (note : aggregated commands are allowed) */ /* Decode commands (note : aggregated commands are allowed) */
if (argument[0]=='-') if (argument[0]=='-')
@ -215,9 +217,9 @@ int main(int argc, char** argv)
switch(argument[0]) switch(argument[0])
{ {
/* Display help */ /* Display help */
case 'V': DISPLAY(WELCOME_MESSAGE); return 0; /* Version Only */ case 'V': displayOut=stdout; DISPLAY(WELCOME_MESSAGE); return 0; /* Version Only */
case 'H': case 'H':
case 'h': return usage_advanced(programName); case 'h': displayOut=stdout; return usage_advanced(programName);
// Compression (default) // Compression (default)
//case 'z': forceCompress = 1; break; //case 'z': forceCompress = 1; break;