From 64f556e610b68e6781e05d2d6470ebf8b8dff45c Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 2 Sep 2016 19:32:06 -0700 Subject: lz4cli version number from lz4.h --- .gitignore | 5 ++-- lib/lz4.h | 8 +++---- lib/lz4hc.c | 11 +++++++-- programs/bench.c | 6 ++--- programs/lz4cli.c | 69 ++++++++++++++++++++++--------------------------------- 5 files changed, 46 insertions(+), 53 deletions(-) diff --git a/.gitignore b/.gitignore index d1ce131..54cd8fa 100644 --- a/.gitignore +++ b/.gitignore @@ -18,9 +18,8 @@ *.app lz4 -# Visual solution files +# IDE / editors files *.suo *.user - -# Directories +.clang_complete _codelite/ diff --git a/lib/lz4.h b/lib/lz4.h index b8f9aeb..ba6d70b 100644 --- a/lib/lz4.h +++ b/lib/lz4.h @@ -58,10 +58,10 @@ extern "C" { #define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE) int LZ4_versionNumber (void); -#define LZ4_STR(str) #str -#define LZ4_XSTR(str) LZ4_STR(str) -#define LZ4_VERSION_STRING LZ4_XSTR(LZ4_VERSION_MAJOR) "." \ - LZ4_XSTR(LZ4_VERSION_MINOR) "." LZ4_XSTR(LZ4_VERSION_RELEASE) +#define LZ4_LIB_VERSION LZ4_VERSION_MAJOR.LZ4_VERSION_MINOR.LZ4_VERSION_RELEASE +#define LZ4_QUOTE(str) #str +#define LZ4_EXPAND_AND_QUOTE(str) LZ4_QUOTE(str) +#define LZ4_VERSION_STRING LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION) const char* LZ4_versionString (void); diff --git a/lib/lz4hc.c b/lib/lz4hc.c index c6f67cb..68afa98 100644 --- a/lib/lz4hc.c +++ b/lib/lz4hc.c @@ -313,8 +313,15 @@ FORCE_INLINE int LZ4HC_encodeSequence ( /* Encode MatchLength */ length = (int)(matchLength-MINMATCH); if ((limitedOutputBuffer) && (*op + (length>>8) + (1 + LASTLITERALS) > oend)) return 1; /* Check output limit */ - if (length>=(int)ML_MASK) { *token+=ML_MASK; length-=ML_MASK; for(; length > 509 ; length-=510) { *(*op)++ = 255; *(*op)++ = 255; } if (length > 254) { length-=255; *(*op)++ = 255; } *(*op)++ = (BYTE)length; } - else *token += (BYTE)(length); + if (length>=(int)ML_MASK) { + *token += ML_MASK; + length -= ML_MASK; + for(; length > 509 ; length-=510) { *(*op)++ = 255; *(*op)++ = 255; } + if (length > 254) { length-=255; *(*op)++ = 255; } + *(*op)++ = (BYTE)length; + } else { + *token += (BYTE)(length); + } /* Prepare next loop */ *ip += matchLength; diff --git a/programs/bench.c b/programs/bench.c index 81118c0..5952f47 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -282,7 +282,7 @@ int BMK_benchLevel(const char** fileNamesTable, int nbFiles, int cLevel) /* Fill input buffer */ DISPLAY("Loading %s... \r", inFileName); - if (strlen(inFileName)>16) inFileName += strlen(inFileName)-16; /* can only display 16 characters */ + if (strlen(inFileName)>16) inFileName += strlen(inFileName)-16; /* can only display 16 characters */ readSize = fread(orig_buff, 1, benchedSize, inFile); fclose(inFile); @@ -398,11 +398,11 @@ int BMK_benchFiles(const char** fileNamesTable, int nbFiles, int cLevel, int cLe if (cLevelLast > LZ4HC_MAX_CLEVEL) cLevelLast = LZ4HC_MAX_CLEVEL; if (cLevelLast < cLevel) cLevelLast = cLevel; - DISPLAY("Benchmarking levels from %d to %d\n", cLevel, cLevelLast); + if (cLevelLast > cLevel) DISPLAY("Benchmarking levels from %d to %d\n", cLevel, cLevelLast); for (i=cLevel; i<=cLevelLast; i++) { res = BMK_benchLevel(fileNamesTable, nbFiles, i); if (res != 0) break; } - + return res; } diff --git a/programs/lz4cli.c b/programs/lz4cli.c index a583481..3e09073 100644 --- a/programs/lz4cli.c +++ b/programs/lz4cli.c @@ -62,6 +62,8 @@ #include "bench.h" /* BMK_benchFile, BMK_SetNbIterations, BMK_SetBlocksize, BMK_SetPause */ #include "lz4io.h" /* LZ4IO_compressFilename, LZ4IO_decompressFilename, LZ4IO_compressMultipleFilenames */ #include "lz4hc.h" /* LZ4HC_DEFAULT_CLEVEL */ +#include "lz4.h" /* LZ4_VERSION_STRING */ + /**************************** * OS-specific Includes @@ -87,11 +89,8 @@ * Constants ******************************/ #define COMPRESSOR_NAME "LZ4 command line interface" -#ifndef LZ4_VERSION -# define LZ4_VERSION "r132" -#endif #define AUTHOR "Yann Collet" -#define WELCOME_MESSAGE "*** %s %i-bits %s, by %s (%s) ***\n", COMPRESSOR_NAME, (int)(sizeof(void*)*8), LZ4_VERSION, AUTHOR, __DATE__ +#define WELCOME_MESSAGE "*** %s %i-bits %s, by %s ***\n", COMPRESSOR_NAME, (int)(sizeof(void*)*8), LZ4_VERSION_STRING, AUTHOR #define LZ4_EXTENSION ".lz4" #define LZ4CAT "lz4cat" #define UNLZ4 "unlz4" @@ -345,7 +344,6 @@ int main(int argc, const char** argv) if (!strcmp(argument, "--version")) { DISPLAY(WELCOME_MESSAGE); return 0; } if (!strcmp(argument, "--keep")) { continue; } /* keep source file (default anyway; just for xz/lzma compatibility) */ - /* Short commands (note : aggregated short commands are allowed) */ if (argument[0]=='-') { /* '-' means stdin/stdout */ @@ -414,8 +412,7 @@ int main(int argc, const char** argv) /* Modify Block Properties */ case 'B': - while (argument[1]!=0) - { + while (argument[1]!=0) { int exitBlockProperties=0; switch(argument[1]) { @@ -451,13 +448,10 @@ int main(int argc, const char** argv) /* Modify Nb Iterations (benchmark only) */ case 'i': - { unsigned iters = 0; - while ((argument[1] >='0') && (argument[1] <='9')) - { - iters *= 10; - iters += argument[1] - '0'; - argument++; - } + { unsigned iters; + argument++; + iters = readU32FromChar(&argument); + argument--; BMK_setNbIterations(iters); } break; @@ -482,8 +476,7 @@ int main(int argc, const char** argv) if (!input_filename) { input_filename=argument; continue; } /* Second non-option arg in output_filename to preserve original cli logic. */ - if (!output_filename) - { + if (!output_filename) { output_filename=argument; if (!strcmp (output_filename, nullOutput)) output_filename = nulmark; continue; @@ -501,31 +494,26 @@ int main(int argc, const char** argv) if(!input_filename) { input_filename=stdinmark; } /* Check if input is defined as console; trigger an error in this case */ - if (!strcmp(input_filename, stdinmark) && IS_CONSOLE(stdin) ) - { + if (!strcmp(input_filename, stdinmark) && IS_CONSOLE(stdin) ) { DISPLAYLEVEL(1, "refusing to read from a console\n"); exit(1); } /* Check if benchmark is selected */ - if (bench) - { + if (bench) { int bmkResult = BMK_benchFiles(inFileNames, ifnIdx, cLevel, cLevelLast); free((void*)inFileNames); return bmkResult; } /* No output filename ==> try to select one automatically (when possible) */ - while (!output_filename) - { + while (!output_filename) { if (!IS_CONSOLE(stdout)) { output_filename=stdoutmark; break; } /* Default to stdout whenever possible (i.e. not a console) */ - if ((!decode) && !(forceCompress)) /* auto-determine compression or decompression, based on file extension */ - { + if ((!decode) && !(forceCompress)) { /* auto-determine compression or decompression, based on file extension */ size_t const l = strlen(input_filename); if (!strcmp(input_filename+(l-4), LZ4_EXTENSION)) decode=1; } - if (!decode) /* compression to file */ - { + if (!decode) { /* compression to file */ size_t const l = strlen(input_filename); dynNameSpace = (char*)calloc(1,l+5); if (dynNameSpace==NULL) exit(1); @@ -536,8 +524,7 @@ int main(int argc, const char** argv) break; } /* decompression to file (automatic name will work only if input filename has correct format extension) */ - { - size_t outl; + { size_t outl; size_t inl = strlen(input_filename); dynNameSpace = (char*)calloc(1,inl+1); strcpy(dynNameSpace, input_filename); @@ -563,21 +550,21 @@ int main(int argc, const char** argv) /* IO Stream/File */ LZ4IO_setNotificationLevel(displayLevel); if (decode) { - if (multiple_inputs) - operationResult = LZ4IO_decompressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION); - else - DEFAULT_DECOMPRESSOR(input_filename, output_filename); - } else { - /* compression is default action */ - if (legacy_format) { - DISPLAYLEVEL(3, "! Generating compressed LZ4 using Legacy format (deprecated) ! \n"); - LZ4IO_compressFilename_Legacy(input_filename, output_filename, cLevel); - } else { if (multiple_inputs) - operationResult = LZ4IO_compressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION, cLevel); + operationResult = LZ4IO_decompressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION); else - DEFAULT_COMPRESSOR(input_filename, output_filename, cLevel); - } + DEFAULT_DECOMPRESSOR(input_filename, output_filename); + } else { + /* compression is default action */ + if (legacy_format) { + DISPLAYLEVEL(3, "! Generating compressed LZ4 using Legacy format (deprecated) ! \n"); + LZ4IO_compressFilename_Legacy(input_filename, output_filename, cLevel); + } else { + if (multiple_inputs) + operationResult = LZ4IO_compressMultipleFilenames(inFileNames, ifnIdx, LZ4_EXTENSION, cLevel); + else + DEFAULT_COMPRESSOR(input_filename, output_filename, cLevel); + } } _cleanup: -- cgit v0.12