]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Zstd cli : --version and --help write to stdout
authorYann Collet <yann.collet.73@gmail.com>
Tue, 25 Aug 2015 22:32:45 +0000 (23:32 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Tue, 25 Aug 2015 22:32:45 +0000 (23:32 +0100)
Makefile
lib/fse.c
programs/Makefile
programs/zstdcli.c

index c778cb722b78df00a9d5b682b114517224d1c54a..0995d85c718b0d1341d2da0f24f32427d6f4e71c 100644 (file)
--- a/Makefile
+++ b/Makefile
 # ################################################################
 
 # 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
index be3919f45badf91c0d03c1bb0433b46816420b5c..6871a19e3209a700ce70e7655e679c5186bb72c1 100644 (file)
--- 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 */
index 525832453fa68cbad3d9adcac0e7cd8f617c96e4..277a83c671878a4962af7066e8baf61fd63cef38 100644 (file)
 # 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
 
 
index 7fa85c855c1081b557795b9926d4267577005446..f3780a49fafee5011aa7fe9d8e6fe7364e72e877 100644 (file)
@@ -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<argc; 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) */
         if (argument[0]=='-')
@@ -215,9 +217,9 @@ int main(int argc, char** argv)
                 switch(argument[0])
                 {
                     /* 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': return usage_advanced(programName);
+                case 'h': displayOut=stdout; return usage_advanced(programName);
 
                     // Compression (default)
                 //case 'z': forceCompress = 1; break;