From f44b2b02b40e99bfbf076d98c24121d6573a2296 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Tue, 25 Aug 2015 23:32:45 +0100 Subject: [PATCH] Zstd cli : --version and --help write to stdout --- Makefile | 5 ++--- lib/fse.c | 6 +++--- programs/Makefile | 5 ++--- programs/zstdcli.c | 28 +++++++++++++++------------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Makefile b/Makefile index c778cb722..0995d85c7 100644 --- a/Makefile +++ b/Makefile @@ -32,11 +32,10 @@ # ################################################################ # Version number -export VERSION=0.1.0 -export RELEASE=r$(VERSION) +export VERSION=0.1.1 DESTDIR?= -PREFIX ?= /usr +PREFIX ?= /usr/local LIBDIR ?= $(PREFIX)/lib INCLUDEDIR=$(PREFIX)/include diff --git a/lib/fse.c b/lib/fse.c index be3919f45..6871a19e3 100644 --- a/lib/fse.c +++ b/lib/fse.c @@ -1904,14 +1904,14 @@ static U32 HUF_setMaxHeight(nodeElt* huffNode, U32 lastNonNull, U32 maxNbBits) if (rankLast[nBitsToDecrease-1] == noOne) rankLast[nBitsToDecrease-1] = rankLast[nBitsToDecrease]; // now there is one elt huffNode[rankLast[nBitsToDecrease]].nbBits ++; - if (rankLast[nBitsToDecrease] > 0) + if (rankLast[nBitsToDecrease] == 0) + rankLast[nBitsToDecrease] = noOne; + else { rankLast[nBitsToDecrease]--; if (huffNode[rankLast[nBitsToDecrease]].nbBits != maxNbBits-nBitsToDecrease) rankLast[nBitsToDecrease] = noOne; // rank list emptied } - else - rankLast[nBitsToDecrease] = noOne; // rank list emptied } while (totalCost < 0) /* Sometimes, cost correction overshoot */ diff --git a/programs/Makefile b/programs/Makefile index 525832453..277a83c67 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -30,12 +30,12 @@ # fullbench32: Same as fullbench, but forced to compile in 32-bits mode # ########################################################################## -RELEASE?= v0.1.0 +VERSION?= v0.1.1 DESTDIR?= PREFIX ?= /usr 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 FLAGS = $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(MOREFLAGS) @@ -43,7 +43,6 @@ BINDIR=$(PREFIX)/bin MANDIR=$(PREFIX)/share/man/man1 ZSTDDIR=../lib -TEST_FILES = COPYING TEST_TARGETS=test-native diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 7fa85c855..f3780a49f 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -86,8 +86,9 @@ /************************************** * Display Macros **************************************/ -#define DISPLAY(...) fprintf(stderr, __VA_ARGS__) +#define DISPLAY(...) fprintf(displayOut, __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 @@ -137,7 +138,7 @@ static int usage_advanced(const char* programName) //DISPLAY( " -t : test compressed file integrity\n"); DISPLAY( "Benchmark arguments :\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; } @@ -173,30 +174,31 @@ int main(int argc, char** argv) char* dynNameSpace = NULL; char extension[] = ZSTD_EXTENSION; + displayOut = stderr; /* Pick out basename component. Don't rely on stdlib because of conflicting behaviour. */ for (i = (int)strlen(programName); i > 0; i--) { - if (programName[i] == '/') - { - i++; - break; - } + if (programName[i] == '/') { i++; break; } } programName += i; - /* zstdcat behavior */ + /* zstdcat preset behavior */ if (!strcmp(programName, ZSTD_CAT)) { decode=1; forceStdout=1; displayLevel=1; outFileName=stdoutmark; } - /* unzstd behavior */ + /* unzstd preset behavior */ if (!strcmp(programName, ZSTD_UNZSTD)) decode=1; - // command switches + /* command switches */ for(i=1; i