]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
minor cosmetics
authorYann Collet <yann.collet.73@gmail.com>
Thu, 11 Feb 2016 03:17:50 +0000 (04:17 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Thu, 11 Feb 2016 03:17:50 +0000 (04:17 +0100)
lib/legacy/zstd_v04.c
lib/mem.h
lib/zstd_compress.c
lib/zstd_opt.h
programs/fileio.c
programs/xxhash.c
programs/zstdcli.c

index 4a1399ec91598a298f2c6c698074d16e7108045d..57d724c27c31bb246590b2de1a0ec16c1b31eba6 100644 (file)
@@ -1465,7 +1465,7 @@ MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr)
 
 
 /* **************************************************************
-*  Includes
+*  Dependencies
 ****************************************************************/
 #include <stdlib.h>     /* malloc, free, qsort */
 #include <string.h>     /* memcpy, memset */
@@ -1499,7 +1499,7 @@ MEM_STATIC unsigned FSE_endOfDState(const FSE_DState_t* DStatePtr)
 typedef U32 DTable_max_t[FSE_DTABLE_SIZE_U32(FSE_MAX_TABLELOG)];
 
 
-/* **************************************************************
+/*-**************************************************************
 *  Templates
 ****************************************************************/
 /*
@@ -4249,39 +4249,32 @@ static size_t ZBUFF_decompressContinue(ZBUFF_DCtx* zbc, void* dst, size_t* maxDs
                 ip += headerSize;
                 headerSize = ZSTD_getFrameParams(&(zbc->params), zbc->headerBuffer, zbc->hPos);
                 if (ZSTD_isError(headerSize)) return headerSize;
-                if (headerSize)
-                {
+                if (headerSize) {
                     /* not enough input to decode header : tell how many bytes would be necessary */
                     *maxDstSizePtr = 0;
                     return headerSize - zbc->hPos;
-                }
-                // zbc->stage = ZBUFFds_decodeHeader; break;   /* useless : stage follows */
-            }
+            }   }
 
         case ZBUFFds_decodeHeader:
                 /* apply header to create / resize buffers */
                 {
                     size_t neededOutSize = (size_t)1 << zbc->params.windowLog;
                     size_t neededInSize = BLOCKSIZE;   /* a block is never > BLOCKSIZE */
-                    if (zbc->inBuffSize < neededInSize)
-                    {
+                    if (zbc->inBuffSize < neededInSize) {
                         free(zbc->inBuff);
                         zbc->inBuffSize = neededInSize;
                         zbc->inBuff = (char*)malloc(neededInSize);
                         if (zbc->inBuff == NULL) return ERROR(memory_allocation);
                     }
-                    if (zbc->outBuffSize < neededOutSize)
-                    {
+                    if (zbc->outBuffSize < neededOutSize) {
                         free(zbc->outBuff);
                         zbc->outBuffSize = neededOutSize;
                         zbc->outBuff = (char*)malloc(neededOutSize);
                         if (zbc->outBuff == NULL) return ERROR(memory_allocation);
-                    }
-                }
+                }   }
                 if (zbc->dictSize)
                     ZSTD_decompress_insertDictionary(zbc->zc, zbc->dict, zbc->dictSize);
-                if (zbc->hPos)
-                {
+                if (zbc->hPos) {
                     /* some data already loaded into headerBuffer : transfer into inBuff */
                     memcpy(zbc->inBuff, zbc->headerBuffer, zbc->hPos);
                     zbc->inPos = zbc->hPos;
index 36ba06f062db2be706cb336581a1c12178280e14..a6606e51d28e35c185f605bb17f63277bcd33fed 100644 (file)
--- a/lib/mem.h
+++ b/lib/mem.h
@@ -86,7 +86,7 @@ extern "C" {
 /*-**************************************************************
 *  Memory I/O
 *****************************************************************/
-/*!MEM_FORCE_MEMORY_ACCESS
+/* MEM_FORCE_MEMORY_ACCESS :
  * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable.
  * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal.
  * The below switch allow to select different access method for improved performance.
@@ -178,7 +178,7 @@ MEM_STATIC void MEM_write64(void* memPtr, U64 value)
     memcpy(memPtr, &value, sizeof(value));
 }
 
-#endif // MEM_FORCE_MEMORY_ACCESS
+#endif /* MEM_FORCE_MEMORY_ACCESS */
 
 
 MEM_STATIC U16 MEM_readLE16(const void* memPtr)
index d59ff12aeaa80269dabd1bd24ae6809efda29dfb..137058b5b92358c7c8f69bff9b3ccb739b775d02 100644 (file)
@@ -1043,8 +1043,7 @@ void ZSTD_compressBlock_fast_generic(ZSTD_CCtx* zc,
                 continue;   /* faster when present ... (?) */
     }   }   }
 
-    /* Last Literals */
-    {
+    {   /* Last Literals */
         size_t lastLLSize = iend - anchor;
         memcpy(seqStorePtr->lit, anchor, lastLLSize);
         seqStorePtr->lit += lastLLSize;
index 6fb94e21aa59eb461943ef62b3e7990a25d876c1..8d9598db3f51de139b9e53c4b8e6b3c60fce1bf3 100644 (file)
@@ -481,27 +481,27 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
         }
 
 
-       best_mlen = (last_pos) ? last_pos : MINMATCH;
+        best_mlen = (last_pos) ? last_pos : MINMATCH;
 
-       if (faster_get_matches && last_pos)
+        if (faster_get_matches && last_pos)
            match_num = 0;
-       else
+        else
            match_num = getAllMatches(ctx, ip, ip, iend, maxSearches, mls, matches, best_mlen); /* first search (depth 0) */
 
-       ZSTD_LOG_PARSER("%d: match_num=%d last_pos=%d\n", (int)(ip-base), match_num, last_pos);
-       if (!last_pos && !match_num) { ip++; continue; }
+        ZSTD_LOG_PARSER("%d: match_num=%d last_pos=%d\n", (int)(ip-base), match_num, last_pos);
+        if (!last_pos && !match_num) { ip++; continue; }
 
-       opt[0].rep = rep_1;
-       opt[0].rep2 = rep_2;
-       opt[0].mlen = 1;
+        opt[0].rep = rep_1;
+        opt[0].rep2 = rep_2;
+        opt[0].mlen = 1;
 
-       if (match_num && matches[match_num-1].len > sufficient_len) {
+        if (match_num && matches[match_num-1].len > sufficient_len) {
             best_mlen = matches[match_num-1].len;
             best_off = matches[match_num-1].off;
             cur = 0;
             last_pos = 1;
             goto _storeSequence;
-       }
+        }
 
        // set prices using matches at position = 0
        for (u = 0; u < match_num; u++) {
@@ -523,8 +523,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
 
 
         // check further positions
-        for (skip_num = 0, cur = 1; cur <= last_pos; cur++)
-        {
+        for (skip_num = 0, cur = 1; cur <= last_pos; cur++) {
            size_t cur_rep;
            inr = ip + cur;
 
@@ -548,7 +547,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
 
            if (cur == last_pos) break;
 
-           if (inr > ilimit) // last match must start at a minimum distance of 8 from oend
+           if (inr > ilimit)  /* last match must start at a minimum distance of 8 from oend */
                continue;
 
             mlen = opt[cur].mlen;
@@ -582,15 +581,15 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
 
 
            if (MEM_read32(inr) == MEM_read32(inr - cur_rep)) {  // check rep
-              mlen = (U32)ZSTD_count(inr+MINMATCH, inr+MINMATCH - cur_rep, iend) + MINMATCH;
-              ZSTD_LOG_PARSER("%d: Found REP mlen=%d off=%d rep=%d opt[%d].off=%d\n", (int)(inr-base), mlen, 0, opt[cur].rep, cur, opt[cur].off);
+               mlen = (U32)ZSTD_count(inr+MINMATCH, inr+MINMATCH - cur_rep, iend) + MINMATCH;
+               ZSTD_LOG_PARSER("%d: Found REP mlen=%d off=%d rep=%d opt[%d].off=%d\n", (int)(inr-base), mlen, 0, opt[cur].rep, cur, opt[cur].off);
 
-              if (mlen > sufficient_len || cur + mlen >= ZSTD_OPT_NUM) {
-                best_mlen = mlen;
-                best_off = 0;
-                ZSTD_LOG_PARSER("%d: REP sufficient_len=%d best_mlen=%d best_off=%d last_pos=%d\n", (int)(inr-base), sufficient_len, best_mlen, best_off, last_pos);
-                last_pos = cur + 1;
-                goto _storeSequence;
+               if (mlen > sufficient_len || cur + mlen >= ZSTD_OPT_NUM) {
+                    best_mlen = mlen;
+                    best_off = 0;
+                    ZSTD_LOG_PARSER("%d: REP sufficient_len=%d best_mlen=%d best_off=%d last_pos=%d\n", (int)(inr-base), sufficient_len, best_mlen, best_off, last_pos);
+                    last_pos = cur + 1;
+                    goto _storeSequence;
                }
 
                if (opt[cur].mlen == 1) {
@@ -622,13 +621,11 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
 
             if (faster_get_matches && skip_num > 0) { skip_num--; continue; }
 
-
             best_mlen = (best_mlen > MINMATCH) ? best_mlen : MINMATCH;
 
             match_num = getAllMatches(ctx, inr, ip, iend, maxSearches, mls, matches, best_mlen);
             ZSTD_LOG_PARSER("%d: ZSTD_GetAllMatches match_num=%d\n", (int)(inr-base), match_num);
 
-
             if (match_num > 0 && matches[match_num-1].len > sufficient_len) {
                 cur -= matches[match_num-1].back;
                 best_mlen = matches[match_num-1].len;
@@ -637,7 +634,6 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
                 goto _storeSequence;
             }
 
-
             /* set prices using matches at position = cur */
             for (u = 0; u < match_num; u++) {
                 mlen = (u>0) ? matches[u-1].len+1 : best_mlen;
@@ -667,9 +663,7 @@ void ZSTD_compressBlock_opt_generic(ZSTD_CCtx* ctx,
                         SET_PRICE(cur2 + mlen, mlen, matches[u].off, litlen, price);
 
                     mlen++;
-            }   }
-        } //  for (skip_num = 0, cur = 1; cur <= last_pos; cur++)
-
+        }   }   }   //  for (skip_num = 0, cur = 1; cur <= last_pos; cur++)
 
         best_mlen = opt[last_pos].mlen;
         best_off = opt[last_pos].off;
@@ -703,34 +697,25 @@ _storeSequence: // cur, last_pos, best_mlen, best_off have to be set
             u += opt[u].mlen;
         }
 
-        cur = 0;
-
-        while (cur < last_pos)
-        {
+        for (cur=0; cur < last_pos; ) {
             ZSTD_LOG_PARSER("%d: price3[%d/%d]=%d off=%d mlen=%d litlen=%d rep=%d rep2=%d\n", (int)(ip-base+cur), cur, last_pos, opt[cur].price, opt[cur].off, opt[cur].mlen, opt[cur].litlen, opt[cur].rep, opt[cur].rep2);
             mlen = opt[cur].mlen;
             if (mlen == 1) { ip++; cur++; continue; }
             offset = opt[cur].off;
             cur += mlen;
 
-
             U32 litLength = (U32)(ip - anchor);
             ZSTD_LOG_ENCODE("%d/%d: ENCODE1 literals=%d mlen=%d off=%d rep1=%d rep2=%d\n", (int)(ip-base), (int)(iend-base), (int)(litLength), (int)mlen, (int)(offset), (int)rep_1, (int)rep_2);
 
-            if (offset)
-            {
+            if (offset) {
                 rep_2 = rep_1;
                 rep_1 = offset;
-            }
-            else
-            {
-                if (litLength == 0)
-                {
+            } else {
+                if (litLength == 0) {
                     best_off = rep_2;
                     rep_2 = rep_1;
                     rep_1 = best_off;
-                }
-            }
+            }   }
 
             ZSTD_LOG_ENCODE("%d/%d: ENCODE2 literals=%d mlen=%d off=%d rep1=%d rep2=%d\n", (int)(ip-base), (int)(iend-base), (int)(litLength), (int)mlen, (int)(offset), (int)rep_1, (int)rep_2);
 
@@ -759,8 +744,7 @@ _storeSequence: // cur, last_pos, best_mlen, best_off have to be set
             anchor = ip = ip + mlen;
         }
 
-
-       // check immediate repcode
+        /* check immediate repcode */
         while ( (anchor <= ilimit)
              && (MEM_read32(anchor) == MEM_read32(anchor - rep_2)) ) {
             /* store sequence */
@@ -774,13 +758,11 @@ _storeSequence: // cur, last_pos, best_mlen, best_off have to be set
             anchor += best_mlen+MINMATCH;
             ip = anchor;
             continue;   // faster when present ... (?)
-        }
-    }
+    }   }
 
-    /* Last Literals */
-    {
-        U32 lastLLSize = (U32)(iend - anchor);
-        ZSTD_LOG_ENCODE("%d: lastLLSize literals=%d\n", (int)(ip-base), (int)(lastLLSize));
+    {   /* Last Literals */
+        size_t lastLLSize = iend - anchor;
+        ZSTD_LOG_ENCODE("%d: lastLLSize literals=%u\n", (int)(ip-base), (U32)lastLLSize);
         memcpy(seqStorePtr->lit, anchor, lastLLSize);
         seqStorePtr->lit += lastLLSize;
     }
@@ -826,21 +808,16 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
     ZSTD_resetSeqStore(seqStorePtr);
     if ((ip - prefixStart) < REPCODE_STARTVALUE) ip += REPCODE_STARTVALUE;
 
-
     /* Match Loop */
     while (ip < ilimit) {
-        U32 u;
-        U32 offset;
-        U32 mlen=0;
-        U32 best_mlen=0;
-        U32 best_off=0;
+        U32 u, offset, best_off=0;
+        U32 mlen=0, best_mlen=0;
         U32 current = (U32)(ip-base);
         memset(opt, 0, sizeof(ZSTD_optimal_t));
         last_pos = 0;
         inr = ip;
         opt[0].litlen = (U32)(ip - anchor);
 
-
         /* check repCode */
         {
             const U32 repIndex = (U32)(current+1 - rep_1);
@@ -872,7 +849,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
        if (faster_get_matches && last_pos)
            match_num = 0;
        else
-           match_num = getAllMatches(ctx, ip, ip, iend, maxSearches, mls, matches, best_mlen); /* first search (depth 0) */
+           match_num = getAllMatches(ctx, ip, ip, iend, maxSearches, mls, matches, best_mlen);  /* first search (depth 0) */
 
        ZSTD_LOG_PARSER("%d: match_num=%d last_pos=%d\n", (int)(ip-base), match_num, last_pos);
        if (!last_pos && !match_num) { ip++; continue; }
@@ -907,8 +884,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
             ip++; continue;
         }
 
-
-        // check further positions
+        /* check further positions */
         for (skip_num = 0, cur = 1; cur <= last_pos; cur++) {
            size_t cur_rep;
            inr = ip + cur;
@@ -955,8 +931,6 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
 
            ZSTD_LOG_PARSER("%d: CURRENT price[%d/%d]=%d off=%d mlen=%d litlen=%d rep=%d rep2=%d\n", (int)(inr-base), cur, last_pos, opt[cur].price, opt[cur].off, opt[cur].mlen, opt[cur].litlen, opt[cur].rep, opt[cur].rep2);
 
-
-
            best_mlen = 0;
 
            if (!opt[cur].off && opt[cur].mlen != 1) {
@@ -970,8 +944,8 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
            const U32 repIndex = (U32)(current+cur - cur_rep);
            const BYTE* const repBase = repIndex < dictLimit ? dictBase : base;
            const BYTE* const repMatch = repBase + repIndex;
-           if ((U32)((dictLimit-1) - repIndex) >= 3)   /* intentional overflow */
-           if (MEM_read32(inr) == MEM_read32(repMatch)) {
+           if ( ((U32)((dictLimit-1) - repIndex) >= 3)   /* intentional overflow */
+              &&(MEM_read32(inr) == MEM_read32(repMatch)) ) {
                 /* repcode detected */
                 const BYTE* const repEnd = repIndex < dictLimit ? dictEnd : iend;
                 mlen = (U32)ZSTD_count_2segments(inr+MINMATCH, repMatch+MINMATCH, iend, repEnd, prefixStart) + MINMATCH;
@@ -983,11 +957,10 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
                     ZSTD_LOG_PARSER("%d: REP sufficient_len=%d best_mlen=%d best_off=%d last_pos=%d\n", (int)(inr-base), sufficient_len, best_mlen, best_off, last_pos);
                     last_pos = cur + 1;
                     goto _storeSequence;
-                 }
+                }
 
                 if (opt[cur].mlen == 1) {
                     litlen = opt[cur].litlen;
-
                     if (cur > litlen) {
                         price = opt[cur - litlen].price + ZSTD_getPrice(seqStorePtr, litlen, inr-litlen, 0, mlen - MINMATCH);
                         ZSTD_LOG_TRY_PRICE("%d: TRY5 opt[%d].price=%d price=%d cur=%d litlen=%d\n", (int)(inr-base), cur - litlen, opt[cur - litlen].price, price, cur, litlen);
@@ -1000,8 +973,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
                 }
 
                 best_mlen = mlen;
-                if (faster_get_matches)
-                    skip_num = best_mlen;
+                if (faster_get_matches) skip_num = best_mlen;
 
                 ZSTD_LOG_PARSER("%d: Found REP mlen=%d off=%d price=%d litlen=%d price[%d]=%d\n", (int)(inr-base), mlen, 0, price, litlen, cur - litlen, opt[cur - litlen].price);
 
@@ -1012,7 +984,6 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
                 } while (mlen >= MINMATCH);
             }
 
-
             if (faster_get_matches && skip_num > 0) { skip_num--; continue; }
 
             best_mlen = (best_mlen > MINMATCH) ? best_mlen : MINMATCH;
@@ -1020,7 +991,6 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
             match_num = getAllMatches(ctx, inr, ip, iend, maxSearches, mls, matches, best_mlen);
             ZSTD_LOG_PARSER("%d: ZSTD_GetAllMatches match_num=%d\n", (int)(inr-base), match_num);
 
-
             if (match_num > 0 && matches[match_num-1].len > sufficient_len) {
                 cur -= matches[match_num-1].back;
                 best_mlen = matches[match_num-1].len;
@@ -1029,7 +999,6 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
                 goto _storeSequence;
             }
 
-
             // set prices using matches at position = cur
             for (u = 0; u < match_num; u++) {
                 mlen = (u>0) ? matches[u-1].len+1 : best_mlen;
@@ -1059,9 +1028,7 @@ void ZSTD_compressBlock_opt_extDict_generic(ZSTD_CCtx* ctx,
                         SET_PRICE(cur2 + mlen, mlen, matches[u].off, litlen, price);
 
                     mlen++;
-            }   }
-        } //  for (skip_num = 0, cur = 1; cur <= last_pos; cur++)
-
+        }   }   }   //  for (skip_num = 0, cur = 1; cur <= last_pos; cur++)
 
         best_mlen = opt[last_pos].mlen;
         best_off = opt[last_pos].off;
@@ -1084,8 +1051,7 @@ _storeSequence: // cur, last_pos, best_mlen, best_off have to be set
             opt[cur].off = best_off;
             best_mlen = mlen;
             best_off = offset;
-            if (mlen > cur)
-                break;
+            if (mlen > cur) break;
             cur -= mlen;
         }
 
@@ -1144,7 +1110,6 @@ _storeSequence: // cur, last_pos, best_mlen, best_off have to be set
             anchor = ip = ip + mlen;
         }
 
-
         /* check immediate repcode */
         while (anchor <= ilimit) {
             const U32 repIndex = (U32)((anchor-base) - rep_2);
@@ -1166,10 +1131,9 @@ _storeSequence: // cur, last_pos, best_mlen, best_off have to be set
             break;
     }   }
 
-    /* Last Literals */
-    {
-        U32 lastLLSize = (U32)(iend - anchor);
-        ZSTD_LOG_ENCODE("%d: lastLLSize literals=%d\n", (int)(ip-base), (int)(lastLLSize));
+    {   /* Last Literals */
+        size_t lastLLSize = iend - anchor;
+        ZSTD_LOG_ENCODE("%d: lastLLSize literals=%u\n", (int)(ip-base), (U32)(lastLLSize));
         memcpy(seqStorePtr->lit, anchor, lastLLSize);
         seqStorePtr->lit += lastLLSize;
     }
index ed2a06181d1766fc992c8e62860f1e53e86666a4..a5739ab4d4df89531d1a48093b15166018e4ecf2 100644 (file)
@@ -1,6 +1,6 @@
 /*
-  fileio.c - File i/o handler
-  Copyright (C) Yann Collet 2013-2015
+  fileio.c - File i/o handler for zstd
+  Copyright (C) Yann Collet 2013-2016
 
   GPL v2 License
 
@@ -19,8 +19,7 @@
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
   You can contact the author at :
-  - zstd source repository : https://github.com/Cyan4973/zstd
-  - Public forum : https://groups.google.com/forum/#!forum/lz4c
+  - zstd homepage : http://www.zstd.net
 */
 /*
   Note : this is stand-alone program.
@@ -33,7 +32,7 @@
 *  Tuning options
 ***************************************/
 #ifndef ZSTD_LEGACY_SUPPORT
-/**LEGACY_SUPPORT :
+/* LEGACY_SUPPORT :
 *  decompressor can decode older formats (starting from Zstd 0.1+) */
 #  define ZSTD_LEGACY_SUPPORT 1
 #endif
@@ -80,9 +79,6 @@
 #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
 #  include <fcntl.h>    /* _O_BINARY */
 #  include <io.h>       /* _setmode, _isatty */
-#  ifdef __MINGW32__
-   // int _fileno(FILE *stream);   /* seems no longer useful /* MINGW somehow forgets to include this windows declaration into <stdio.h> */
-#  endif
 #  define SET_BINARY_MODE(file) { int unused = _setmode(_fileno(file), _O_BINARY); (void)unused; }
 #  define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream))
 #else
@@ -317,10 +313,10 @@ static void FIO_freeCResources(cRess_t ress)
 }
 
 
-/*
- * FIO_compressFilename_extRess()
- * result : 0 : compression completed correctly
- *          1 : missing or pb opening srcFileName
+/*!
+ * FIO_compressFilename_extRess() :
+ * @result : 0 : compression completed correctly,
+ *           1 : missing or pb opening srcFileName
  */
 static int FIO_compressFilename_extRess(cRess_t ress,
                                         const char* dstFileName, const char* srcFileName,
index d33113fe2763c406af8a4e7357bc82c69ab071d3..352d1e540679ec98914607048ab3ecc044d53f32 100644 (file)
@@ -175,7 +175,7 @@ static U64 XXH_read64(const void* memPtr)
     return val;
 }
 
-#endif // XXH_FORCE_DIRECT_MEMORY_ACCESS
+#endif   /* XXH_FORCE_DIRECT_MEMORY_ACCESS */
 
 
 /* ****************************************
index 89027afd86104248bff70f4d6f9ad83198b3ed4d..3f3c5cd51e33393787bfbac092eef629698f69d1 100644 (file)
@@ -1,6 +1,6 @@
 /*
   zstdcli - Command Line Interface (cli) for zstd
-  Copyright (C) Yann Collet 2014-2015
+  Copyright (C) Yann Collet 2014-2016
 
   GPL v2 License
 
@@ -19,8 +19,7 @@
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
   You can contact the author at :
-  - zstd source repository : https://github.com/Cyan4973/zstd
-  - ztsd public forum : https://groups.google.com/forum/#!forum/lz4c
+  - zstd homepage : http://www.zstd.net/
 */
 /*
   Note : this is user program.
 */
 
 
-/**************************************
+/*-************************************
 *  Compiler Options
 **************************************/
 #define _CRT_SECURE_NO_WARNINGS  /* Visual : removes warning from strcpy */
 #define _POSIX_SOURCE 1          /* triggers fileno() within <stdio.h> on unix */
 
 
-/**************************************
+/*-************************************
 *  Includes
 **************************************/
 #include <stdio.h>    /* fprintf, getchar */
@@ -50,7 +49,7 @@
 #include "zstd.h"     /* ZSTD version numbers */
 
 
-/**************************************
+/*-************************************
 *  OS-specific Includes
 **************************************/
 #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)
@@ -68,7 +67,7 @@
 #endif
 
 
-/**************************************
+/*-************************************
 *  Constants
 **************************************/
 #define COMPRESSOR_NAME "zstd command line interface"
 #define GB *(1U<<30)
 
 
-/**************************************
+/*-************************************
 *  Display Macros
 **************************************/
 #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
+static unsigned displayLevel = 2;   /* 0 : no display,  1: errors,  2 : + result + interaction + warnings,  3 : + progression,  4 : + information */
 
 
-/**************************************
+/*-************************************
 *  Exceptions
 **************************************/
 #define DEBUG 0
@@ -112,7 +111,7 @@ static unsigned displayLevel = 2;   // 0 : no display  // 1: errors  // 2 : + re
 }
 
 
-/**************************************
+/*-************************************
 *  Command Line
 **************************************/
 static int usage(const char* programName)
@@ -126,7 +125,6 @@ static int usage(const char* programName)
     DISPLAY( " -#     : # compression level (1-19, default:1) \n");
     DISPLAY( " -d     : decompression \n");
     DISPLAY( " -D file: use `file` as Dictionary \n");
-    //DISPLAY( " -z     : force compression\n");
     DISPLAY( " -f     : overwrite output without prompting \n");
     DISPLAY( " -h/-H  : display help/long help and exit\n");
     return 0;
@@ -203,10 +201,8 @@ int main(int argCount, const char** argv)
     if (!strcmp(programName, ZSTD_CAT)) { decode=1; forceStdout=1; displayLevel=1; outFileName=stdoutmark; }
 
     /* command switches */
-    for(i=1; i<argCount; i++)
-    {
+    for(i=1; i<argCount; i++) {
         const char* argument = argv[i];
-
         if(!argument) continue;   /* Protection if argument empty */
 
         /* long commands (--long-word) */
@@ -217,11 +213,9 @@ int main(int argCount, const char** argv)
         if (!strcmp(argument, "--quiet")) { displayLevel--; continue; }
 
         /* Decode commands (note : aggregated commands are allowed) */
-        if (argument[0]=='-')
-        {
+        if (argument[0]=='-') {
             /* '-' means stdin/stdout */
-            if (argument[1]==0)
-            {
+            if (argument[1]==0) {
                 if (!filenameIdx) { filenameIdx=1, filenameTable[0]=stdinmark; continue; }
                 outFileName=stdoutmark; continue;
             }
@@ -250,10 +244,7 @@ int main(int argCount, const char** argv)
                 case 'H':
                 case 'h': displayOut=stdout; return usage_advanced(programName);
 
-                    /* Compression (default) */
-                //case 'z': forceCompress = 1; break;
-
-                    /* Decoding */
+                     /* Decoding */
                 case 'd': decode=1; argument++; break;
 
                     /* Multiple input files */
@@ -265,9 +256,6 @@ int main(int argCount, const char** argv)
                     /* Use file content as dictionary */
                 case 'D': nextEntryIsDictionary = 1; argument++; break;
 
-                    /* Test -- not implemented */
-                /* case 't': decode=1; LZ4IO_setOverwrite(1); output_filename=nulmark; break; */
-
                     /* Overwrite */
                 case 'f': FIO_overwriteMode(); argument++; break;
 
@@ -327,8 +315,7 @@ int main(int argCount, const char** argv)
         }
 
         /* dictionary */
-        if (nextEntryIsDictionary)
-        {
+        if (nextEntryIsDictionary) {
             nextEntryIsDictionary = 0;
             dictFileName = argument;
             continue;
@@ -342,8 +329,7 @@ int main(int argCount, const char** argv)
     DISPLAYLEVEL(3, WELCOME_MESSAGE);
 
     /* Check if benchmark is selected */
-    if (bench)
-    {
+    if (bench) {
 #ifndef ZSTD_NOBENCH
         BMK_benchFiles(filenameTable, filenameIdx, dictFileName, cLevel*rangeBench);
 #endif
@@ -358,11 +344,9 @@ int main(int argCount, const char** argv)
 
     /* No output filename ==> try to select one automatically (when possible) */
     if (filenameIdx>=2) outFileName = filenameTable[1];
-    while (!outFileName)   /* while : just to allow break statement */
-    {
+    while (!outFileName) {   /* while : just to allow break statement */
         if (!IS_CONSOLE(stdout)) { outFileName=stdoutmark; break; }   /* Default to stdout whenever possible (i.e. not a console) */
-        if (!decode)   /* compression to file */
-        {
+        if (!decode) {  /* compression to file */
             size_t l = strlen(filenameTable[0]);
             dynNameSpace = (char*)calloc(1,l+5);
             if (dynNameSpace==NULL) { DISPLAY("not enough memory\n"); exit(1); }
@@ -375,8 +359,7 @@ int main(int argCount, const char** argv)
         /* decompression to file (automatic name will work only if input filename has correct format extension) */
         {
             size_t filenameSize = strlen(filenameTable[0]);
-            if (strcmp(filenameTable[0] + (filenameSize-4), extension))
-            {
+            if (strcmp(filenameTable[0] + (filenameSize-4), extension)) {
                  DISPLAYLEVEL(1, "unknown suffix - cannot determine destination filename\n");
                  return badusage(programName);
             }
@@ -386,8 +369,7 @@ int main(int argCount, const char** argv)
             strcpy(dynNameSpace, filenameTable[0]);
             dynNameSpace[filenameSize-4]=0;
             DISPLAYLEVEL(2, "Decoding file %s \n", outFileName);
-        }
-    }
+    }   }
 
     /* Check if output is defined as console; trigger an error in this case */
     if (!strcmp(outFileName,stdoutmark) && IS_CONSOLE(stdout) && !forceStdout) return badusage(programName);
@@ -396,23 +378,19 @@ int main(int argCount, const char** argv)
     if (!strcmp(filenameTable[0], stdinmark) && !strcmp(outFileName,stdoutmark) && (displayLevel==2)) displayLevel=1;
     if (multiple && (displayLevel==2)) displayLevel=1;
 
-    if ((!multiple) && (filenameIdx>2))
-    {
+    if ((!multiple) && (filenameIdx>2)) {
         DISPLAY("Too many files on the command line (%u > 2). Do you mean -m ? \n", filenameIdx);
         return filenameIdx;
     }
 
     /* IO Stream/File */
     FIO_setNotificationLevel(displayLevel);
-    if (decode)
-    {
+    if (decode) {
       if (multiple)
         operationResult = FIO_decompressMultipleFilenames(filenameTable, filenameIdx, ZSTD_EXTENSION, dictFileName);
       else
         operationResult = FIO_decompressFilename(outFileName, filenameTable[0], dictFileName);
-    }
-    else
-    {
+    } else {  /* compression */
         if (multiple)
           operationResult = FIO_compressMultipleFilenames(filenameTable, filenameIdx, ZSTD_EXTENSION, dictFileName, cLevel);
         else