From df60512a0dc51134e95650731e5f001f0898806e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 21 Sep 2017 19:23:09 +0200 Subject: [PATCH] Cleanup our dep version of 7zip - we don't want non-stdint types. Other misc. cleanups --- deps/7zip/7zBuf.h | 2 +- deps/7zip/7zCrc.h | 2 +- deps/7zip/7zDec.c | 121 +---- deps/7zip/7zFile.h | 2 +- deps/7zip/7zStream.c | 2 +- deps/7zip/7zTypes.h | 107 +--- deps/7zip/Bcj2.h | 2 +- deps/7zip/Bra.h | 2 +- deps/7zip/Compiler.h | 32 -- deps/7zip/CpuArch.h | 2 +- deps/7zip/LzFind.c | 390 +++---------- deps/7zip/LzFind.h | 80 +-- deps/7zip/LzHash.h | 25 +- deps/7zip/Lzma2Dec.c | 26 +- deps/7zip/Lzma2Dec.h | 7 +- deps/7zip/LzmaDec.c | 8 +- deps/7zip/LzmaDec.h | 2 +- deps/7zip/LzmaEnc.c | 721 +++++++++++-------------- deps/7zip/LzmaEnc.h | 18 +- deps/7zip/Precomp.h | 10 - deps/7zip/Types.h | 201 ------- libretro-common/file/archive_file_7z.c | 5 +- libretro-common/formats/libchdr/chd.c | 4 +- 23 files changed, 511 insertions(+), 1260 deletions(-) delete mode 100644 deps/7zip/Compiler.h delete mode 100644 deps/7zip/Precomp.h delete mode 100644 deps/7zip/Types.h diff --git a/deps/7zip/7zBuf.h b/deps/7zip/7zBuf.h index 66f9005327..485ec12610 100644 --- a/deps/7zip/7zBuf.h +++ b/deps/7zip/7zBuf.h @@ -4,7 +4,7 @@ #ifndef __7Z_BUF_H #define __7Z_BUF_H -#include "Types.h" +#include "7zTypes.h" #ifdef __cplusplus extern "C" { diff --git a/deps/7zip/7zCrc.h b/deps/7zip/7zCrc.h index 9c11923500..4b56a1c506 100644 --- a/deps/7zip/7zCrc.h +++ b/deps/7zip/7zCrc.h @@ -4,7 +4,7 @@ #ifndef __7Z_CRC_H #define __7Z_CRC_H -#include "Types.h" +#include "7zTypes.h" #ifdef __cplusplus extern "C" { diff --git a/deps/7zip/7zDec.c b/deps/7zip/7zDec.c index daccc5afc2..34eac2a832 100644 --- a/deps/7zip/7zDec.c +++ b/deps/7zip/7zDec.c @@ -3,8 +3,7 @@ #include #include - -/* #define _7ZIP_PPMD_SUPPPORT */ +#include #include "7z.h" @@ -13,9 +12,6 @@ #include "CpuArch.h" #include "LzmaDec.h" #include "Lzma2Dec.h" -#ifdef _7ZIP_PPMD_SUPPPORT -#include "Ppmd7.h" -#endif #define k_Copy 0 #define k_LZMA2 0x21 @@ -27,104 +23,6 @@ #define k_SPARC 0x03030805 #define k_BCJ2 0x0303011B -#ifdef _7ZIP_PPMD_SUPPPORT - -#define k_PPMD 0x30401 - -typedef struct -{ - Iuint8_tIn p; - const uint8_t *cur; - const uint8_t *end; - const uint8_t *begin; - uint64_t processed; - Bool extra; - SRes res; - ILookInStream *inStream; -} Cuint8_tInToLook; - -static uint8_t Readuint8_t(void *pp) -{ - Cuint8_tInToLook *p = (Cuint8_tInToLook *)pp; - if (p->cur != p->end) - return *p->cur++; - if (p->res == SZ_OK) - { - size_t size = p->cur - p->begin; - p->processed += size; - p->res = p->inStream->Skip(p->inStream, size); - size = (1 << 25); - p->res = p->inStream->Look(p->inStream, (const void **)&p->begin, &size); - p->cur = p->begin; - p->end = p->begin + size; - if (size != 0) - return *p->cur++; - } - p->extra = True; - return 0; -} - -static SRes SzDecodePpmd(CSzCoderInfo *coder, uint64_t inSize, ILookInStream *inStream, - uint8_t *outBuffer, size_t outSize, ISzAlloc *allocMain) -{ - CPpmd7 ppmd; - Cuint8_tInToLook s; - SRes res = SZ_OK; - - s.p.Read = Readuint8_t; - s.inStream = inStream; - s.begin = s.end = s.cur = NULL; - s.extra = False; - s.res = SZ_OK; - s.processed = 0; - - if (coder->Props.size != 5) - return SZ_ERROR_UNSUPPORTED; - - { - unsigned order = coder->Props.data[0]; - uint32_t memSize = GetUi32(coder->Props.data + 1); - if (order < PPMD7_MIN_ORDER || - order > PPMD7_MAX_ORDER || - memSize < PPMD7_MIN_MEM_SIZE || - memSize > PPMD7_MAX_MEM_SIZE) - return SZ_ERROR_UNSUPPORTED; - Ppmd7_Construct(&ppmd); - if (!Ppmd7_Alloc(&ppmd, memSize, allocMain)) - return SZ_ERROR_MEM; - Ppmd7_Init(&ppmd, order); - } - { - CPpmd7z_RangeDec rc; - Ppmd7z_RangeDec_CreateVTable(&rc); - rc.Stream = &s.p; - if (!Ppmd7z_RangeDec_Init(&rc)) - res = SZ_ERROR_DATA; - else if (s.extra) - res = (s.res != SZ_OK ? s.res : SZ_ERROR_DATA); - else - { - size_t i; - for (i = 0; i < outSize; i++) - { - int sym = Ppmd7_DecodeSymbol(&ppmd, &rc.p); - if (s.extra || sym < 0) - break; - outBuffer[i] = (uint8_t)sym; - } - if (i != outSize) - res = (s.res != SZ_OK ? s.res : SZ_ERROR_DATA); - else if (s.processed + (s.cur - s.begin) != inSize || !Ppmd7z_RangeDec_IsFinishedOK(&rc)) - res = SZ_ERROR_DATA; - } - } - Ppmd7_Free(&ppmd, allocMain); - return res; -} - -#endif - - static SRes SzDecodeLzma(CSzCoderInfo *coder, uint64_t inSize, ILookInStream *inStream, uint8_t *outBuffer, size_t outSize, ISzAlloc *allocMain) { @@ -241,22 +139,19 @@ static SRes SzDecodeCopy(uint64_t inSize, ILookInStream *inStream, uint8_t *outB return SZ_OK; } -static Bool IS_MAIN_METHOD(uint32_t m) +static bool IS_MAIN_METHOD(uint32_t m) { switch(m) { case k_Copy: case k_LZMA: case k_LZMA2: - #ifdef _7ZIP_PPMD_SUPPPORT - case k_PPMD: - #endif - return True; + return true; } - return False; + return false; } -static Bool IS_SUPPORTED_CODER(const CSzCoderInfo *c) +static bool IS_SUPPORTED_CODER(const CSzCoderInfo *c) { return c->NumInStreams == 1 && @@ -402,13 +297,7 @@ static SRes SzFolder_Decode2(const CSzFolder *folder, const uint64_t *packSizes, RINOK(SzDecodeLzma2(coder, inSize, inStream, outBufCur, outSizeCur, allocMain)); } else - { - #ifdef _7ZIP_PPMD_SUPPPORT - RINOK(SzDecodePpmd(coder, inSize, inStream, outBufCur, outSizeCur, allocMain)); - #else return SZ_ERROR_UNSUPPORTED; - #endif - } } else if (coder->MethodID == k_BCJ2) { diff --git a/deps/7zip/7zFile.h b/deps/7zip/7zFile.h index 73d2ff0440..86c3ed1060 100644 --- a/deps/7zip/7zFile.h +++ b/deps/7zip/7zFile.h @@ -14,7 +14,7 @@ #include #endif -#include "Types.h" +#include "7zTypes.h" #ifdef __cplusplus extern "C" { diff --git a/deps/7zip/7zStream.c b/deps/7zip/7zStream.c index 101a024847..c205fbe200 100644 --- a/deps/7zip/7zStream.c +++ b/deps/7zip/7zStream.c @@ -5,7 +5,7 @@ #include #include -#include "Types.h" +#include "7zTypes.h" SRes SeqInStream_Readuint8_t(ISeqInStream *stream, uint8_t *buf); diff --git a/deps/7zip/7zTypes.h b/deps/7zip/7zTypes.h index 3034a3d33f..a64abaa671 100644 --- a/deps/7zip/7zTypes.h +++ b/deps/7zip/7zTypes.h @@ -4,10 +4,7 @@ #ifndef __7Z_TYPES_H #define __7Z_TYPES_H -#ifdef _WIN32 -/* #include */ -#endif - +#include #include #ifndef EXTERN_C_BEGIN @@ -43,7 +40,6 @@ EXTERN_C_BEGIN typedef int SRes; #ifdef _WIN32 -/* typedef DWORD WRes; */ typedef unsigned WRes; #else typedef int WRes; @@ -53,89 +49,22 @@ typedef int WRes; #define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; } #endif -#ifndef ZCONF_H -typedef unsigned char Byte; -#endif -typedef short Int16; -typedef unsigned short UInt16; - -#ifdef _LZMA_UINT32_IS_ULONG -typedef long Int32; -typedef unsigned long UInt32; -#else -typedef int Int32; -typedef unsigned int UInt32; -#endif - -#ifdef _SZ_NO_INT_64 - -/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers. - NOTES: Some code will work incorrectly in that case! */ - -typedef long Int64; -typedef unsigned long UInt64; - -#else - -#if defined(_MSC_VER) || defined(__BORLANDC__) -typedef __int64 Int64; -typedef unsigned __int64 UInt64; -#define UINT64_CONST(n) n -#else -typedef long long int Int64; -typedef unsigned long long int UInt64; -#define UINT64_CONST(n) n ## ULL -#endif - -#endif - -#ifdef _LZMA_NO_SYSTEM_SIZE_T -typedef UInt32 SizeT; -#else -typedef size_t SizeT; -#endif - -typedef int Bool; -#define True 1 -#define False 0 - - -#ifdef _WIN32 -#define MY_STD_CALL __stdcall -#else -#define MY_STD_CALL -#endif - #ifdef _MSC_VER - -#if _MSC_VER >= 1300 -#define MY_NO_INLINE __declspec(noinline) -#else -#define MY_NO_INLINE -#endif - -#define MY_CDECL __cdecl #define MY_FAST_CALL __fastcall - #else - -#define MY_NO_INLINE -#define MY_CDECL #define MY_FAST_CALL - #endif - /* The following interfaces use first parameter as pointer to structure */ typedef struct { - Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */ + unsigned char (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */ } IByteIn; typedef struct { - void (*Write)(void *p, Byte b); + void (*Write)(void *p, unsigned char b); } IByteOut; typedef struct @@ -148,7 +77,7 @@ typedef struct /* it can return SZ_ERROR_INPUT_EOF */ SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size); SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType); -SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf); +SRes SeqInStream_ReadByte(ISeqInStream *stream, unsigned char *buf); typedef struct { @@ -167,7 +96,7 @@ typedef enum typedef struct { SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */ - SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin); + SRes (*Seek)(void *p, int64_t *pos, ESzSeek origin); } ISeekInStream; typedef struct @@ -181,11 +110,11 @@ typedef struct SRes (*Read)(void *p, void *buf, size_t *size); /* reads directly (without buffer). It's same as ISeqInStream::Read */ - SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin); + SRes (*Seek)(void *p, int64_t *pos, ESzSeek origin); } ILookInStream; SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size); -SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset); +SRes LookInStream_SeekTo(ILookInStream *stream, uint64_t offset); /* reads via ILookInStream::Read */ SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType); @@ -199,7 +128,7 @@ typedef struct ISeekInStream *realStream; size_t pos; size_t size; - Byte buf[LookToRead_BUF_SIZE]; + unsigned char buf[LookToRead_BUF_SIZE]; } CLookToRead; void LookToRead_CreateVTable(CLookToRead *p, int lookahead); @@ -223,9 +152,7 @@ void SecToRead_CreateVTable(CSecToRead *p); typedef struct { - SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize); - /* Returns: result. (result != SZ_OK) means break. - Value (UInt64)(Int64)-1 for size means unknown value. */ + SRes (*Progress)(void *p, uint64_t inSize, uint64_t outSize); } ICompressProgress; typedef struct @@ -237,22 +164,6 @@ typedef struct #define IAlloc_Alloc(p, size) (p)->Alloc((p), size) #define IAlloc_Free(p, a) (p)->Free((p), a) -#ifdef _WIN32 - -#define CHAR_PATH_SEPARATOR '\\' -#define WCHAR_PATH_SEPARATOR L'\\' -#define STRING_PATH_SEPARATOR "\\" -#define WSTRING_PATH_SEPARATOR L"\\" - -#else - -#define CHAR_PATH_SEPARATOR '/' -#define WCHAR_PATH_SEPARATOR L'/' -#define STRING_PATH_SEPARATOR "/" -#define WSTRING_PATH_SEPARATOR L"/" - -#endif - EXTERN_C_END #endif diff --git a/deps/7zip/Bcj2.h b/deps/7zip/Bcj2.h index 2a46b0b039..a7651499f7 100644 --- a/deps/7zip/Bcj2.h +++ b/deps/7zip/Bcj2.h @@ -4,7 +4,7 @@ #ifndef __BCJ2_H #define __BCJ2_H -#include "Types.h" +#include "7zTypes.h" #ifdef __cplusplus extern "C" { diff --git a/deps/7zip/Bra.h b/deps/7zip/Bra.h index 11eadf70fc..3e9d9d9a30 100644 --- a/deps/7zip/Bra.h +++ b/deps/7zip/Bra.h @@ -4,7 +4,7 @@ #ifndef __BRA_H #define __BRA_H -#include "Types.h" +#include "7zTypes.h" #ifdef __cplusplus extern "C" { diff --git a/deps/7zip/Compiler.h b/deps/7zip/Compiler.h deleted file mode 100644 index 5bba7ee561..0000000000 --- a/deps/7zip/Compiler.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Compiler.h -2015-08-02 : Igor Pavlov : Public domain */ - -#ifndef __7Z_COMPILER_H -#define __7Z_COMPILER_H - -#ifdef _MSC_VER - - #ifdef UNDER_CE - #define RPC_NO_WINDOWS_H - /* #pragma warning(disable : 4115) // '_RPC_ASYNC_STATE' : named type definition in parentheses */ - #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union - #pragma warning(disable : 4214) // nonstandard extension used : bit field types other than int - #endif - - #if _MSC_VER >= 1300 - #pragma warning(disable : 4996) // This function or variable may be unsafe - #else - #pragma warning(disable : 4511) // copy constructor could not be generated - #pragma warning(disable : 4512) // assignment operator could not be generated - #pragma warning(disable : 4514) // unreferenced inline function has been removed - #pragma warning(disable : 4702) // unreachable code - #pragma warning(disable : 4710) // not inlined - #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information - #endif - -#endif - -#define UNUSED_VAR(x) (void)x; -/* #define UNUSED_VAR(x) x=x; */ - -#endif diff --git a/deps/7zip/CpuArch.h b/deps/7zip/CpuArch.h index d0b56d7451..700945f617 100644 --- a/deps/7zip/CpuArch.h +++ b/deps/7zip/CpuArch.h @@ -4,7 +4,7 @@ #ifndef __CPU_ARCH_H #define __CPU_ARCH_H -#include "Types.h" +#include "7zTypes.h" #ifdef __cplusplus extern "C" { diff --git a/deps/7zip/LzFind.c b/deps/7zip/LzFind.c index 2d05fa3953..6eef8730d9 100644 --- a/deps/7zip/LzFind.c +++ b/deps/7zip/LzFind.c @@ -1,18 +1,18 @@ /* LzFind.c -- Match finder for LZ algorithms 2015-10-15 : Igor Pavlov : Public domain */ -#include "Precomp.h" - +#include #include +#include #include "LzFind.h" #include "LzHash.h" #define kEmptyHashValue 0 -#define kMaxValForNormalize ((UInt32)0xFFFFFFFF) +#define kMaxValForNormalize ((uint32_t)0xFFFFFFFF) #define kNormalizeStepMin (1 << 10) /* it must be power of 2 */ -#define kNormalizeMask (~(UInt32)(kNormalizeStepMin - 1)) -#define kMaxHistorySize ((UInt32)7 << 29) +#define kNormalizeMask (~(uint32_t)(kNormalizeStepMin - 1)) +#define kMaxHistorySize ((uint32_t)7 << 29) #define kStartMaxLen 3 @@ -27,9 +27,9 @@ static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc) /* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */ -static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc) +static int LzInWindow_Create(CMatchFinder *p, uint32_t keepSizeReserv, ISzAlloc *alloc) { - UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv; + uint32_t blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv; if (p->directInput) { p->blockSize = blockSize; @@ -39,16 +39,16 @@ static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *a { LzInWindow_Free(p, alloc); p->blockSize = blockSize; - p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize); + p->bufferBase = (unsigned char*)alloc->Alloc(alloc, (size_t)blockSize); } return (p->bufferBase != NULL); } -Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; } +unsigned char *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; } -UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; } +uint32_t MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; } -void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue) +void MatchFinder_ReduceOffsets(CMatchFinder *p, uint32_t subValue) { p->posLimit -= subValue; p->pos -= subValue; @@ -64,9 +64,9 @@ static void MatchFinder_ReadBlock(CMatchFinder *p) if (p->directInput) { - UInt32 curSize = 0xFFFFFFFF - (p->streamPos - p->pos); + uint32_t curSize = 0xFFFFFFFF - (p->streamPos - p->pos); if (curSize > p->directInputRem) - curSize = (UInt32)p->directInputRem; + curSize = (uint32_t)p->directInputRem; p->directInputRem -= curSize; p->streamPos += curSize; if (p->directInputRem == 0) @@ -76,7 +76,7 @@ static void MatchFinder_ReadBlock(CMatchFinder *p) for (;;) { - Byte *dest = p->buffer + (p->streamPos - p->pos); + unsigned char *dest = p->buffer + (p->streamPos - p->pos); size_t size = (p->bufferBase + p->blockSize - dest); if (size == 0) return; @@ -89,7 +89,7 @@ static void MatchFinder_ReadBlock(CMatchFinder *p) p->streamEndWasReached = 1; return; } - p->streamPos += (UInt32)size; + p->streamPos += (uint32_t)size; if (p->streamPos - p->pos > p->keepSizeAfter) return; } @@ -138,7 +138,7 @@ static void MatchFinder_SetDefaultSettings(CMatchFinder *p) void MatchFinder_Construct(CMatchFinder *p) { - UInt32 i; + uint32_t i; p->bufferBase = NULL; p->directInput = 0; p->hash = NULL; @@ -146,7 +146,7 @@ void MatchFinder_Construct(CMatchFinder *p) for (i = 0; i < 256; i++) { - UInt32 r = i; + uint32_t r = i; unsigned j; for (j = 0; j < 8; j++) r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1)); @@ -174,11 +174,11 @@ static CLzRef* AllocRefs(size_t num, ISzAlloc *alloc) return (CLzRef *)alloc->Alloc(alloc, sizeInBytes); } -int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, - UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, +int MatchFinder_Create(CMatchFinder *p, uint32_t historySize, + uint32_t keepAddBufferBefore, uint32_t matchMaxLen, uint32_t keepAddBufferAfter, ISzAlloc *alloc) { - UInt32 sizeReserv; + uint32_t sizeReserv; if (historySize > kMaxHistorySize) { @@ -187,8 +187,8 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, } sizeReserv = historySize >> 1; - if (historySize >= ((UInt32)3 << 30)) sizeReserv = historySize >> 3; - else if (historySize >= ((UInt32)2 << 30)) sizeReserv = historySize >> 2; + if (historySize >= ((uint32_t)3 << 30)) sizeReserv = historySize >> 3; + else if (historySize >= ((uint32_t)2 << 30)) sizeReserv = historySize >> 2; sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19); @@ -199,8 +199,8 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, if (LzInWindow_Create(p, sizeReserv, alloc)) { - UInt32 newCyclicBufferSize = historySize + 1; - UInt32 hs; + uint32_t newCyclicBufferSize = historySize + 1; + uint32_t hs; p->matchMaxLen = matchMaxLen; { p->fixedHashSize = 0; @@ -265,8 +265,8 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, static void MatchFinder_SetLimits(CMatchFinder *p) { - UInt32 limit = kMaxValForNormalize - p->pos; - UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos; + uint32_t limit = kMaxValForNormalize - p->pos; + uint32_t limit2 = p->cyclicBufferSize - p->cyclicBufferPos; if (limit2 < limit) limit = limit2; @@ -284,7 +284,7 @@ static void MatchFinder_SetLimits(CMatchFinder *p) limit = limit2; { - UInt32 lenLimit = p->streamPos - p->pos; + uint32_t lenLimit = p->streamPos - p->pos; if (lenLimit > p->matchMaxLen) lenLimit = p->matchMaxLen; p->lenLimit = lenLimit; @@ -294,9 +294,9 @@ static void MatchFinder_SetLimits(CMatchFinder *p) void MatchFinder_Init_2(CMatchFinder *p, int readData) { - UInt32 i; - UInt32 *hash = p->hash; - UInt32 num = p->hashSizeSum; + uint32_t i; + uint32_t *hash = p->hash; + uint32_t num = p->hashSizeSum; for (i = 0; i < num; i++) hash[i] = kEmptyHashValue; @@ -314,20 +314,20 @@ void MatchFinder_Init_2(CMatchFinder *p, int readData) void MatchFinder_Init(CMatchFinder *p) { - MatchFinder_Init_2(p, True); + MatchFinder_Init_2(p, true); } -static UInt32 MatchFinder_GetSubValue(CMatchFinder *p) +static uint32_t MatchFinder_GetSubValue(CMatchFinder *p) { return (p->pos - p->historySize - 1) & kNormalizeMask; } -void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems) +void MatchFinder_Normalize3(uint32_t subValue, CLzRef *items, size_t numItems) { size_t i; for (i = 0; i < numItems; i++) { - UInt32 value = items[i]; + uint32_t value = items[i]; if (value <= subValue) value = kEmptyHashValue; else @@ -338,7 +338,7 @@ void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems) static void MatchFinder_Normalize(CMatchFinder *p) { - UInt32 subValue = MatchFinder_GetSubValue(p); + uint32_t subValue = MatchFinder_GetSubValue(p); MatchFinder_Normalize3(subValue, p->hash, p->numRefs); MatchFinder_ReduceOffsets(p, subValue); } @@ -354,22 +354,22 @@ static void MatchFinder_CheckLimits(CMatchFinder *p) MatchFinder_SetLimits(p); } -static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, - UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue, - UInt32 *distances, UInt32 maxLen) +static uint32_t * Hc_GetMatchesSpec(uint32_t lenLimit, uint32_t curMatch, uint32_t pos, const unsigned char *cur, CLzRef *son, + uint32_t _cyclicBufferPos, uint32_t _cyclicBufferSize, uint32_t cutValue, + uint32_t *distances, uint32_t maxLen) { son[_cyclicBufferPos] = curMatch; for (;;) { - UInt32 delta = pos - curMatch; + uint32_t delta = pos - curMatch; if (cutValue-- == 0 || delta >= _cyclicBufferSize) return distances; { - const Byte *pb = cur - delta; + const unsigned char *pb = cur - delta; curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)]; if (pb[maxLen] == cur[maxLen] && *pb == *cur) { - UInt32 len = 0; + uint32_t len = 0; while (++len != lenLimit) if (pb[len] != cur[len]) break; @@ -385,16 +385,16 @@ static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, } } -UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, - UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue, - UInt32 *distances, UInt32 maxLen) +uint32_t * GetMatchesSpec1(uint32_t lenLimit, uint32_t curMatch, uint32_t pos, const unsigned char *cur, CLzRef *son, + uint32_t _cyclicBufferPos, uint32_t _cyclicBufferSize, uint32_t cutValue, + uint32_t *distances, uint32_t maxLen) { CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1; CLzRef *ptr1 = son + (_cyclicBufferPos << 1); - UInt32 len0 = 0, len1 = 0; + uint32_t len0 = 0, len1 = 0; for (;;) { - UInt32 delta = pos - curMatch; + uint32_t delta = pos - curMatch; if (cutValue-- == 0 || delta >= _cyclicBufferSize) { *ptr0 = *ptr1 = kEmptyHashValue; @@ -402,8 +402,8 @@ UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byt } { CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1); - const Byte *pb = cur - delta; - UInt32 len = (len0 < len1 ? len0 : len1); + const unsigned char *pb = cur - delta; + uint32_t len = (len0 < len1 ? len0 : len1); if (pb[len] == cur[len]) { if (++len != lenLimit && pb[len] == cur[len]) @@ -440,15 +440,15 @@ UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byt } } -static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son, - UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue) +static void SkipMatchesSpec(uint32_t lenLimit, uint32_t curMatch, uint32_t pos, const unsigned char *cur, CLzRef *son, + uint32_t _cyclicBufferPos, uint32_t _cyclicBufferSize, uint32_t cutValue) { CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1; CLzRef *ptr1 = son + (_cyclicBufferPos << 1); - UInt32 len0 = 0, len1 = 0; + uint32_t len0 = 0, len1 = 0; for (;;) { - UInt32 delta = pos - curMatch; + uint32_t delta = pos - curMatch; if (cutValue-- == 0 || delta >= _cyclicBufferSize) { *ptr0 = *ptr1 = kEmptyHashValue; @@ -456,8 +456,8 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const } { CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1); - const Byte *pb = cur - delta; - UInt32 len = (len0 < len1 ? len0 : len1); + const unsigned char *pb = cur - delta; + uint32_t len = (len0 < len1 ? len0 : len1); if (pb[len] == cur[len]) { while (++len != lenLimit) @@ -500,7 +500,7 @@ static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; } #define GET_MATCHES_HEADER2(minLen, ret_op) \ - UInt32 lenLimit; UInt32 hv; const Byte *cur; UInt32 curMatch; \ + uint32_t lenLimit; uint32_t hv; const unsigned char *cur; uint32_t curMatch; \ lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \ cur = p->buffer; @@ -510,7 +510,7 @@ static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; } #define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue #define GET_MATCHES_FOOTER(offset, maxLen) \ - offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \ + offset = (uint32_t)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \ distances + offset, maxLen) - distances); MOVE_POS_RET; #define SKIP_FOOTER \ @@ -518,14 +518,14 @@ static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; } #define UPDATE_maxLen { \ ptrdiff_t diff = (ptrdiff_t)0 - d2; \ - const Byte *c = cur + maxLen; \ - const Byte *lim = cur + lenLimit; \ + const unsigned char *c = cur + maxLen; \ + const unsigned char *lim = cur + lenLimit; \ for (; c != lim; c++) if (*(c + diff) != *c) break; \ - maxLen = (UInt32)(c - cur); } + maxLen = (uint32_t)(c - cur); } -static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) +static uint32_t Bt2_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances) { - UInt32 offset; + uint32_t offset; GET_MATCHES_HEADER(2) HASH2_CALC; curMatch = p->hash[hv]; @@ -534,9 +534,9 @@ static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) GET_MATCHES_FOOTER(offset, 1) } -UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) +uint32_t Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances) { - UInt32 offset; + uint32_t offset; GET_MATCHES_HEADER(3) HASH_ZIP_CALC; curMatch = p->hash[hv]; @@ -545,10 +545,10 @@ UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) GET_MATCHES_FOOTER(offset, 2) } -static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) +static uint32_t Bt3_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances) { - UInt32 h2, d2, maxLen, offset, pos; - UInt32 *hash; + uint32_t h2, d2, maxLen, offset, pos; + uint32_t *hash; GET_MATCHES_HEADER(3) HASH3_CALC; @@ -582,10 +582,10 @@ static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) GET_MATCHES_FOOTER(offset, maxLen) } -static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) +static uint32_t Bt4_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances) { - UInt32 h2, h3, d2, d3, maxLen, offset, pos; - UInt32 *hash; + uint32_t h2, h3, d2, d3, maxLen, offset, pos; + uint32_t *hash; GET_MATCHES_HEADER(4) HASH4_CALC; @@ -637,87 +637,10 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) GET_MATCHES_FOOTER(offset, maxLen) } -/* -static UInt32 Bt5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) +static uint32_t Hc4_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances) { - UInt32 h2, h3, h4, d2, d3, d4, maxLen, offset, pos; - UInt32 *hash; - GET_MATCHES_HEADER(5) - - HASH5_CALC; - - hash = p->hash; - pos = p->pos; - - d2 = pos - hash[ h2]; - d3 = pos - hash[kFix3HashSize + h3]; - d4 = pos - hash[kFix4HashSize + h4]; - - curMatch = hash[kFix5HashSize + hv]; - - hash[ h2] = pos; - hash[kFix3HashSize + h3] = pos; - hash[kFix4HashSize + h4] = pos; - hash[kFix5HashSize + hv] = pos; - - maxLen = 0; - offset = 0; - - if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur) - { - distances[0] = maxLen = 2; - distances[1] = d2 - 1; - offset = 2; - if (*(cur - d2 + 2) == cur[2]) - distances[0] = maxLen = 3; - else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur) - { - distances[2] = maxLen = 3; - distances[3] = d3 - 1; - offset = 4; - d2 = d3; - } - } - else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur) - { - distances[0] = maxLen = 3; - distances[1] = d3 - 1; - offset = 2; - d2 = d3; - } - - if (d2 != d4 && d4 < p->cyclicBufferSize - && *(cur - d4) == *cur - && *(cur - d4 + 3) == *(cur + 3)) - { - maxLen = 4; - distances[offset + 1] = d4 - 1; - offset += 2; - d2 = d4; - } - - if (offset != 0) - { - UPDATE_maxLen - distances[offset - 2] = maxLen; - if (maxLen == lenLimit) - { - SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); - MOVE_POS_RET; - } - } - - if (maxLen < 4) - maxLen = 4; - - GET_MATCHES_FOOTER(offset, maxLen) -} -*/ - -static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) -{ - UInt32 h2, h3, d2, d3, maxLen, offset, pos; - UInt32 *hash; + uint32_t h2, h3, d2, d3, maxLen, offset, pos; + uint32_t *hash; GET_MATCHES_HEADER(4) HASH4_CALC; @@ -766,103 +689,24 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) if (maxLen < 3) maxLen = 3; - offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), + offset = (uint32_t)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), distances + offset, maxLen) - (distances)); MOVE_POS_RET } -/* -static UInt32 Hc5_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) +uint32_t Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances) { - UInt32 h2, h3, h4, d2, d3, d4, maxLen, offset, pos - UInt32 *hash; - GET_MATCHES_HEADER(5) - - HASH5_CALC; - - hash = p->hash; - pos = p->pos; - - d2 = pos - hash[ h2]; - d3 = pos - hash[kFix3HashSize + h3]; - d4 = pos - hash[kFix4HashSize + h4]; - - curMatch = hash[kFix5HashSize + hv]; - - hash[ h2] = pos; - hash[kFix3HashSize + h3] = pos; - hash[kFix4HashSize + h4] = pos; - hash[kFix5HashSize + hv] = pos; - - maxLen = 0; - offset = 0; - - if (d2 < p->cyclicBufferSize && *(cur - d2) == *cur) - { - distances[0] = maxLen = 2; - distances[1] = d2 - 1; - offset = 2; - if (*(cur - d2 + 2) == cur[2]) - distances[0] = maxLen = 3; - else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur) - { - distances[2] = maxLen = 3; - distances[3] = d3 - 1; - offset = 4; - d2 = d3; - } - } - else if (d3 < p->cyclicBufferSize && *(cur - d3) == *cur) - { - distances[0] = maxLen = 3; - distances[1] = d3 - 1; - offset = 2; - d2 = d3; - } - - if (d2 != d4 && d4 < p->cyclicBufferSize - && *(cur - d4) == *cur - && *(cur - d4 + 3) == *(cur + 3)) - { - maxLen = 4; - distances[offset + 1] = d4 - 1; - offset += 2; - d2 = d4; - } - - if (offset != 0) - { - UPDATE_maxLen - distances[offset - 2] = maxLen; - if (maxLen == lenLimit) - { - p->son[p->cyclicBufferPos] = curMatch; - MOVE_POS_RET; - } - } - - if (maxLen < 4) - maxLen = 4; - - offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), - distances + offset, maxLen) - (distances)); - MOVE_POS_RET -} -*/ - -UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances) -{ - UInt32 offset; + uint32_t offset; GET_MATCHES_HEADER(3) HASH_ZIP_CALC; curMatch = p->hash[hv]; p->hash[hv] = p->pos; - offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), + offset = (uint32_t)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p), distances, 2) - (distances)); MOVE_POS_RET } -static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num) +static void Bt2_MatchFinder_Skip(CMatchFinder *p, uint32_t num) { do { @@ -875,7 +719,7 @@ static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num) while (--num != 0); } -void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num) +void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, uint32_t num) { do { @@ -888,12 +732,12 @@ void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num) while (--num != 0); } -static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num) +static void Bt3_MatchFinder_Skip(CMatchFinder *p, uint32_t num) { do { - UInt32 h2; - UInt32 *hash; + uint32_t h2; + uint32_t *hash; SKIP_HEADER(3) HASH3_CALC; hash = p->hash; @@ -905,12 +749,12 @@ static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num) while (--num != 0); } -static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) +static void Bt4_MatchFinder_Skip(CMatchFinder *p, uint32_t num) { do { - UInt32 h2, h3; - UInt32 *hash; + uint32_t h2, h3; + uint32_t *hash; SKIP_HEADER(4) HASH4_CALC; hash = p->hash; @@ -923,33 +767,12 @@ static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) while (--num != 0); } -/* -static void Bt5_MatchFinder_Skip(CMatchFinder *p, UInt32 num) +static void Hc4_MatchFinder_Skip(CMatchFinder *p, uint32_t num) { do { - UInt32 h2, h3, h4; - UInt32 *hash; - SKIP_HEADER(5) - HASH5_CALC; - hash = p->hash; - curMatch = hash[kFix5HashSize + hv]; - hash[ h2] = - hash[kFix3HashSize + h3] = - hash[kFix4HashSize + h4] = - hash[kFix5HashSize + hv] = p->pos; - SKIP_FOOTER - } - while (--num != 0); -} -*/ - -static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) -{ - do - { - UInt32 h2, h3; - UInt32 *hash; + uint32_t h2, h3; + uint32_t *hash; SKIP_HEADER(4) HASH4_CALC; hash = p->hash; @@ -963,29 +786,7 @@ static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num) while (--num != 0); } -/* -static void Hc5_MatchFinder_Skip(CMatchFinder *p, UInt32 num) -{ - do - { - UInt32 h2, h3, h4; - UInt32 *hash; - SKIP_HEADER(5) - HASH5_CALC; - hash = p->hash; - curMatch = p->hash[kFix5HashSize + hv]; - hash[ h2] = - hash[kFix3HashSize + h3] = - hash[kFix4HashSize + h4] = - hash[kFix5HashSize + hv] = p->pos; - p->son[p->cyclicBufferPos] = curMatch; - MOVE_POS - } - while (--num != 0); -} -*/ - -void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num) +void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, uint32_t num) { do { @@ -1006,18 +807,10 @@ void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable) vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos; if (!p->btMode) { - /* if (p->numHashBytes <= 4) */ { vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches; vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip; } - /* - else - { - vTable->GetMatches = (Mf_GetMatches_Func)Hc5_MatchFinder_GetMatches; - vTable->Skip = (Mf_Skip_Func)Hc5_MatchFinder_Skip; - } - */ } else if (p->numHashBytes == 2) { @@ -1034,11 +827,4 @@ void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable) vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches; vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip; } - /* - else - { - vTable->GetMatches = (Mf_GetMatches_Func)Bt5_MatchFinder_GetMatches; - vTable->Skip = (Mf_Skip_Func)Bt5_MatchFinder_Skip; - } - */ } diff --git a/deps/7zip/LzFind.h b/deps/7zip/LzFind.h index d119944f44..a7fc117536 100644 --- a/deps/7zip/LzFind.h +++ b/deps/7zip/LzFind.h @@ -8,44 +8,44 @@ EXTERN_C_BEGIN -typedef UInt32 CLzRef; +typedef uint32_t CLzRef; typedef struct _CMatchFinder { - Byte *buffer; - UInt32 pos; - UInt32 posLimit; - UInt32 streamPos; - UInt32 lenLimit; + unsigned char *buffer; + uint32_t pos; + uint32_t posLimit; + uint32_t streamPos; + uint32_t lenLimit; - UInt32 cyclicBufferPos; - UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */ + uint32_t cyclicBufferPos; + uint32_t cyclicBufferSize; /* it must be = (historySize + 1) */ - Byte streamEndWasReached; - Byte btMode; - Byte bigHash; - Byte directInput; + unsigned char streamEndWasReached; + unsigned char btMode; + unsigned char bigHash; + unsigned char directInput; - UInt32 matchMaxLen; + uint32_t matchMaxLen; CLzRef *hash; CLzRef *son; - UInt32 hashMask; - UInt32 cutValue; + uint32_t hashMask; + uint32_t cutValue; - Byte *bufferBase; + unsigned char *bufferBase; ISeqInStream *stream; - UInt32 blockSize; - UInt32 keepSizeBefore; - UInt32 keepSizeAfter; + uint32_t blockSize; + uint32_t keepSizeBefore; + uint32_t keepSizeAfter; - UInt32 numHashBytes; + uint32_t numHashBytes; size_t directInputRem; - UInt32 historySize; - UInt32 fixedHashSize; - UInt32 hashSizeSum; + uint32_t historySize; + uint32_t fixedHashSize; + uint32_t hashSizeSum; SRes result; - UInt32 crc[256]; + uint32_t crc[256]; size_t numRefs; } CMatchFinder; @@ -59,7 +59,7 @@ typedef struct _CMatchFinder && (!(p)->directInput || (p)->directInputRem == 0)) int MatchFinder_NeedMove(CMatchFinder *p); -Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p); +unsigned char *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p); void MatchFinder_MoveBlock(CMatchFinder *p); void MatchFinder_ReadIfRequired(CMatchFinder *p); @@ -69,16 +69,16 @@ void MatchFinder_Construct(CMatchFinder *p); historySize <= 3 GB keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB */ -int MatchFinder_Create(CMatchFinder *p, UInt32 historySize, - UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter, +int MatchFinder_Create(CMatchFinder *p, uint32_t historySize, + uint32_t keepAddBufferBefore, uint32_t matchMaxLen, uint32_t keepAddBufferAfter, ISzAlloc *alloc); void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc); -void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, size_t numItems); -void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue); +void MatchFinder_Normalize3(uint32_t subValue, CLzRef *items, size_t numItems); +void MatchFinder_ReduceOffsets(CMatchFinder *p, uint32_t subValue); -UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son, - UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue, - UInt32 *distances, UInt32 maxLen); +uint32_t * GetMatchesSpec1(uint32_t lenLimit, uint32_t curMatch, uint32_t pos, const unsigned char *buffer, CLzRef *son, + uint32_t _cyclicBufferPos, uint32_t _cyclicBufferSize, uint32_t _cutValue, + uint32_t *distances, uint32_t maxLen); /* Conditions: @@ -87,10 +87,10 @@ Conditions: */ typedef void (*Mf_Init_Func)(void *object); -typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object); -typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object); -typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances); -typedef void (*Mf_Skip_Func)(void *object, UInt32); +typedef uint32_t (*Mf_GetNumAvailableBytes_Func)(void *object); +typedef const unsigned char * (*Mf_GetPointerToCurrentPos_Func)(void *object); +typedef uint32_t (*Mf_GetMatches_Func)(void *object, uint32_t *distances); +typedef void (*Mf_Skip_Func)(void *object, uint32_t); typedef struct _IMatchFinder { @@ -106,11 +106,11 @@ void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable); void MatchFinder_Init_2(CMatchFinder *p, int readData); void MatchFinder_Init(CMatchFinder *p); -UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); -UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances); +uint32_t Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances); +uint32_t Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, uint32_t *distances); -void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); -void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num); +void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, uint32_t num); +void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, uint32_t num); EXTERN_C_END diff --git a/deps/7zip/LzHash.h b/deps/7zip/LzHash.h index e7c942303d..3d01d8df55 100644 --- a/deps/7zip/LzHash.h +++ b/deps/7zip/LzHash.h @@ -12,45 +12,44 @@ #define kFix4HashSize (kHash2Size + kHash3Size) #define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size) -#define HASH2_CALC hv = cur[0] | ((UInt32)cur[1] << 8); +#define HASH2_CALC hv = cur[0] | ((uint32_t)cur[1] << 8); #define HASH3_CALC { \ - UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ + uint32_t temp = p->crc[cur[0]] ^ cur[1]; \ h2 = temp & (kHash2Size - 1); \ - hv = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; } + hv = (temp ^ ((uint32_t)cur[2] << 8)) & p->hashMask; } #define HASH4_CALC { \ - UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ + uint32_t temp = p->crc[cur[0]] ^ cur[1]; \ h2 = temp & (kHash2Size - 1); \ - temp ^= ((UInt32)cur[2] << 8); \ + temp ^= ((uint32_t)cur[2] << 8); \ h3 = temp & (kHash3Size - 1); \ hv = (temp ^ (p->crc[cur[3]] << 5)) & p->hashMask; } #define HASH5_CALC { \ - UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ + uint32_t temp = p->crc[cur[0]] ^ cur[1]; \ h2 = temp & (kHash2Size - 1); \ - temp ^= ((UInt32)cur[2] << 8); \ + temp ^= ((uint32_t)cur[2] << 8); \ h3 = temp & (kHash3Size - 1); \ temp ^= (p->crc[cur[3]] << 5); \ h4 = temp & (kHash4Size - 1); \ hv = (temp ^ (p->crc[cur[4]] << 3)) & p->hashMask; } -/* #define HASH_ZIP_CALC hv = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */ -#define HASH_ZIP_CALC hv = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF; +#define HASH_ZIP_CALC hv = ((cur[2] | ((uint32_t)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF; #define MT_HASH2_CALC \ h2 = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1); #define MT_HASH3_CALC { \ - UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ + uint32_t temp = p->crc[cur[0]] ^ cur[1]; \ h2 = temp & (kHash2Size - 1); \ - h3 = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); } + h3 = (temp ^ ((uint32_t)cur[2] << 8)) & (kHash3Size - 1); } #define MT_HASH4_CALC { \ - UInt32 temp = p->crc[cur[0]] ^ cur[1]; \ + uint32_t temp = p->crc[cur[0]] ^ cur[1]; \ h2 = temp & (kHash2Size - 1); \ - temp ^= ((UInt32)cur[2] << 8); \ + temp ^= ((uint32_t)cur[2] << 8); \ h3 = temp & (kHash3Size - 1); \ h4 = (temp ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); } diff --git a/deps/7zip/Lzma2Dec.c b/deps/7zip/Lzma2Dec.c index 6819d6fdf3..a99b1f91b3 100644 --- a/deps/7zip/Lzma2Dec.c +++ b/deps/7zip/Lzma2Dec.c @@ -80,9 +80,9 @@ SRes Lzma2Dec_Allocate(CLzma2Dec *p, uint8_t prop, ISzAlloc *alloc) void Lzma2Dec_Init(CLzma2Dec *p) { p->state = LZMA2_STATE_CONTROL; - p->needInitDic = True; - p->needInitState = True; - p->needInitProp = True; + p->needInitDic = true; + p->needInitState = true; + p->needInitProp = true; LzmaDec_Init(&p->decoder); } @@ -140,7 +140,7 @@ static ELzma2State Lzma2Dec_UpdateState(CLzma2Dec *p, uint8_t b) return LZMA2_STATE_ERROR; p->decoder.prop.lc = lc; p->decoder.prop.lp = lp; - p->needInitProp = False; + p->needInitProp = false; return LZMA2_STATE_DATA; } } @@ -156,7 +156,7 @@ static void LzmaDec_UpdateWithUncompressed(CLzmaDec *p, const uint8_t *src, size p->processedPos += (uint32_t)size; } -void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState); +void LzmaDec_InitDicAndState(CLzmaDec *p, bool initDic, bool initState); SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, size_t dicLimit, const uint8_t *src, size_t *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status) @@ -207,13 +207,13 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, size_t dicLimit, if (p->state == LZMA2_STATE_DATA) { - Bool initDic = (p->control == LZMA2_CONTROL_COPY_RESET_DIC); + bool initDic = (p->control == LZMA2_CONTROL_COPY_RESET_DIC); if (initDic) - p->needInitProp = p->needInitState = True; + p->needInitProp = p->needInitState = true; else if (p->needInitDic) return SZ_ERROR_DATA; - p->needInitDic = False; - LzmaDec_InitDicAndState(&p->decoder, initDic, False); + p->needInitDic = false; + LzmaDec_InitDicAndState(&p->decoder, initDic, false); } if (srcSizeCur > destSizeCur) @@ -237,14 +237,14 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, size_t dicLimit, if (p->state == LZMA2_STATE_DATA) { int mode = LZMA2_GET_LZMA_MODE(p); - Bool initDic = (mode == 3); - Bool initState = (mode > 0); + bool initDic = (mode == 3); + bool initState = (mode > 0); if ((!initDic && p->needInitDic) || (!initState && p->needInitState)) return SZ_ERROR_DATA; LzmaDec_InitDicAndState(&p->decoder, initDic, initState); - p->needInitDic = False; - p->needInitState = False; + p->needInitDic = false; + p->needInitState = false; p->state = LZMA2_STATE_DATA_CONT; } if (srcSizeCur > p->packSize) diff --git a/deps/7zip/Lzma2Dec.h b/deps/7zip/Lzma2Dec.h index 5affbf3fb0..53797ae049 100644 --- a/deps/7zip/Lzma2Dec.h +++ b/deps/7zip/Lzma2Dec.h @@ -4,6 +4,7 @@ #ifndef __LZMA2_DEC_H #define __LZMA2_DEC_H +#include #include "LzmaDec.h" #ifdef __cplusplus @@ -19,9 +20,9 @@ typedef struct uint32_t unpackSize; int state; uint8_t control; - Bool needInitDic; - Bool needInitState; - Bool needInitProp; + bool needInitDic; + bool needInitState; + bool needInitProp; } CLzma2Dec; #define Lzma2Dec_Construct(p) LzmaDec_Construct(&(p)->decoder) diff --git a/deps/7zip/LzmaDec.c b/deps/7zip/LzmaDec.c index 07f7245cc9..4a0a5a5faf 100644 --- a/deps/7zip/LzmaDec.c +++ b/deps/7zip/LzmaDec.c @@ -2,10 +2,10 @@ 2009-09-20 : Igor Pavlov : Public domain */ #include #include +#include #include "LzmaDec.h" - #define kNumTopBits 24 #define kTopValue ((uint32_t)1 << kNumTopBits) @@ -721,9 +721,9 @@ static void LzmaDec_InitRc(CLzmaDec *p, const uint8_t *data) p->needFlush = 0; } -void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState); +void LzmaDec_InitDicAndState(CLzmaDec *p, bool initDic, bool initState); -void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState) +void LzmaDec_InitDicAndState(CLzmaDec *p, bool initDic, bool initState) { p->needFlush = 1; p->remainLen = 0; @@ -742,7 +742,7 @@ void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState) void LzmaDec_Init(CLzmaDec *p) { p->dicPos = 0; - LzmaDec_InitDicAndState(p, True, True); + LzmaDec_InitDicAndState(p, true, true); } static void LzmaDec_InitStateReal(CLzmaDec *p) diff --git a/deps/7zip/LzmaDec.h b/deps/7zip/LzmaDec.h index 30fd5a7da3..b10837ce99 100644 --- a/deps/7zip/LzmaDec.h +++ b/deps/7zip/LzmaDec.h @@ -4,7 +4,7 @@ #ifndef __LZMA_DEC_H #define __LZMA_DEC_H -#include "Types.h" +#include "7zTypes.h" #ifdef __cplusplus extern "C" { diff --git a/deps/7zip/LzmaEnc.c b/deps/7zip/LzmaEnc.c index 70df4569b7..56bb8fbf8d 100644 --- a/deps/7zip/LzmaEnc.c +++ b/deps/7zip/LzmaEnc.c @@ -1,16 +1,9 @@ /* LzmaEnc.c -- LZMA Encoder 2016-05-16 : Igor Pavlov : Public domain */ -#include "Precomp.h" - +#include #include - -/* #define SHOW_STAT */ -/* #define SHOW_STAT2 */ - -#if defined(SHOW_STAT) || defined(SHOW_STAT2) -#include -#endif +#include #include "LzmaEnc.h" @@ -19,12 +12,8 @@ #include "LzFindMt.h" #endif -#ifdef SHOW_STAT -static unsigned g_STAT_OFFSET = 0; -#endif - -#define kMaxHistorySize ((UInt32)3 << 29) -/* #define kMaxHistorySize ((UInt32)7 << 29) */ +#define kMaxHistorySize ((uint32_t)3 << 29) +/* #define kMaxHistorySize ((uint32_t)7 << 29) */ #define kBlockSizeMax ((1 << LZMA_NUM_BLOCK_SIZE_BITS) - 1) @@ -36,7 +25,7 @@ static unsigned g_STAT_OFFSET = 0; #define kNumMaxDirectBits (31) #define kNumTopBits 24 -#define kTopValue ((UInt32)1 << kNumTopBits) +#define kTopValue ((uint32_t)1 << kNumTopBits) #define kNumBitModelTotalBits 11 #define kBitModelTotal (1 << kNumBitModelTotalBits) @@ -51,7 +40,7 @@ void LzmaEncProps_Init(CLzmaEncProps *p) { p->level = 5; p->dictSize = p->mc = 0; - p->reduceSize = (UInt64)(Int64)-1; + p->reduceSize = (uint64_t)(int64_t)-1; p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1; p->writeEndMark = 0; } @@ -68,8 +57,8 @@ void LzmaEncProps_Normalize(CLzmaEncProps *p) unsigned i; for (i = 11; i <= 30; i++) { - if ((UInt32)p->reduceSize <= ((UInt32)2 << i)) { p->dictSize = ((UInt32)2 << i); break; } - if ((UInt32)p->reduceSize <= ((UInt32)3 << i)) { p->dictSize = ((UInt32)3 << i); break; } + if ((uint32_t)p->reduceSize <= ((uint32_t)2 << i)) { p->dictSize = ((uint32_t)2 << i); break; } + if ((uint32_t)p->reduceSize <= ((uint32_t)3 << i)) { p->dictSize = ((uint32_t)3 << i); break; } } } @@ -92,41 +81,19 @@ void LzmaEncProps_Normalize(CLzmaEncProps *p) #endif } -UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2) +uint32_t LzmaEncProps_GetDictSize(const CLzmaEncProps *props2) { CLzmaEncProps props = *props2; LzmaEncProps_Normalize(&props); return props.dictSize; } -#if (_MSC_VER >= 1400) -/* BSR code is fast for some new CPUs */ -/* #define LZMA_LOG_BSR */ -#endif - -#ifdef LZMA_LOG_BSR - -#define kDicLogSizeMaxCompress 32 - -#define BSR2_RET(pos, res) { unsigned long zz; _BitScanReverse(&zz, (pos)); res = (zz + zz) + ((pos >> (zz - 1)) & 1); } - -static UInt32 GetPosSlot1(UInt32 pos) -{ - UInt32 res; - BSR2_RET(pos, res); - return res; -} -#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); } -#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); } - -#else - #define kNumLogBits (9 + sizeof(size_t) / 2) /* #define kNumLogBits (11 + sizeof(size_t) / 8 * 3) */ #define kDicLogSizeMaxCompress ((kNumLogBits - 1) * 2 + 7) -static void LzmaEnc_FastPosInit(Byte *g_FastPos) +static void LzmaEnc_FastPosInit(unsigned char *g_FastPos) { unsigned slot; g_FastPos[0] = 0; @@ -138,39 +105,18 @@ static void LzmaEnc_FastPosInit(Byte *g_FastPos) size_t k = ((size_t)1 << ((slot >> 1) - 1)); size_t j; for (j = 0; j < k; j++) - g_FastPos[j] = (Byte)slot; + g_FastPos[j] = (unsigned char)slot; g_FastPos += k; } } -/* we can use ((limit - pos) >> 31) only if (pos < ((UInt32)1 << 31)) */ -/* -#define BSR2_RET(pos, res) { UInt32 zz = 6 + ((kNumLogBits - 1) & \ - (0 - (((((UInt32)1 << (kNumLogBits + 6)) - 1) - pos) >> 31))); \ +#define BSR2_RET(pos, res) { uint32_t zz = (pos < (1 << (kNumLogBits + 6))) ? 6 : 6 + kNumLogBits - 1; \ res = p->g_FastPos[pos >> zz] + (zz * 2); } -*/ - -/* -#define BSR2_RET(pos, res) { UInt32 zz = 6 + ((kNumLogBits - 1) & \ - (0 - (((((UInt32)1 << (kNumLogBits)) - 1) - (pos >> 6)) >> 31))); \ - res = p->g_FastPos[pos >> zz] + (zz * 2); } -*/ - -#define BSR2_RET(pos, res) { UInt32 zz = (pos < (1 << (kNumLogBits + 6))) ? 6 : 6 + kNumLogBits - 1; \ - res = p->g_FastPos[pos >> zz] + (zz * 2); } - -/* -#define BSR2_RET(pos, res) { res = (pos < (1 << (kNumLogBits + 6))) ? \ - p->g_FastPos[pos >> 6] + 12 : \ - p->g_FastPos[pos >> (6 + kNumLogBits - 1)] + (6 + (kNumLogBits - 1)) * 2; } -*/ #define GetPosSlot1(pos) p->g_FastPos[pos] #define GetPosSlot2(pos, res) { BSR2_RET(pos, res); } #define GetPosSlot(pos, res) { if (pos < kNumFullDistances) res = p->g_FastPos[pos]; else BSR2_RET(pos, res); } -#endif - #define LZMA_NUM_REPS 4 @@ -178,18 +124,18 @@ typedef unsigned CState; typedef struct { - UInt32 price; + uint32_t price; CState state; int prev1IsChar; int prev2; - UInt32 posPrev2; - UInt32 backPrev2; + uint32_t posPrev2; + uint32_t backPrev2; - UInt32 posPrev; - UInt32 backPrev; - UInt32 backs[LZMA_NUM_REPS]; + uint32_t posPrev; + uint32_t backPrev; + uint32_t backs[LZMA_NUM_REPS]; } COptimal; #define kNumOpts (1 << 12) @@ -212,9 +158,9 @@ typedef struct #define kNumFullDistances (1 << (kEndPosModelIndex >> 1)) #ifdef _LZMA_PROB32 -#define CLzmaProb UInt32 +#define CLzmaProb uint32_t #else -#define CLzmaProb UInt16 +#define CLzmaProb uint16_t #endif #define LZMA_PB_MAX 4 @@ -252,23 +198,23 @@ typedef struct typedef struct { CLenEnc p; - UInt32 tableSize; - UInt32 prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal]; - UInt32 counters[LZMA_NUM_PB_STATES_MAX]; + uint32_t tableSize; + uint32_t prices[LZMA_NUM_PB_STATES_MAX][kLenNumSymbolsTotal]; + uint32_t counters[LZMA_NUM_PB_STATES_MAX]; } CLenPriceEnc; typedef struct { - UInt32 range; - Byte cache; - UInt64 low; - UInt64 cacheSize; - Byte *buf; - Byte *bufLim; - Byte *bufBase; + uint32_t range; + unsigned char cache; + uint64_t low; + uint64_t cacheSize; + unsigned char *buf; + unsigned char*bufLim; + unsigned char *bufBase; ISeqOutStream *outStream; - UInt64 processed; + uint64_t processed; SRes res; } CRangeEnc; @@ -277,8 +223,8 @@ typedef struct { CLzmaProb *litProbs; - UInt32 state; - UInt32 reps[LZMA_NUM_REPS]; + uint32_t state; + uint32_t reps[LZMA_NUM_REPS]; CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX]; CLzmaProb isRep[kNumStates]; @@ -301,17 +247,17 @@ typedef struct void *matchFinderObj; IMatchFinder matchFinder; - UInt32 optimumEndIndex; - UInt32 optimumCurrentIndex; + uint32_t optimumEndIndex; + uint32_t optimumCurrentIndex; - UInt32 longestMatchLength; - UInt32 numPairs; - UInt32 numAvail; + uint32_t longestMatchLength; + uint32_t numPairs; + uint32_t numAvail; - UInt32 numFastBytes; - UInt32 additionalOffset; - UInt32 reps[LZMA_NUM_REPS]; - UInt32 state; + uint32_t numFastBytes; + uint32_t additionalOffset; + uint32_t reps[LZMA_NUM_REPS]; + uint32_t state; unsigned lc, lp, pb; unsigned lpMask, pbMask; @@ -319,47 +265,45 @@ typedef struct CLzmaProb *litProbs; - Bool fastMode; - Bool writeEndMark; - Bool finished; - Bool multiThread; - Bool needInit; + bool fastMode; + bool writeEndMark; + bool finished; + bool multiThread; + bool needInit; - UInt64 nowPos64; + uint64_t nowPos64; - UInt32 matchPriceCount; - UInt32 alignPriceCount; + uint32_t matchPriceCount; + uint32_t alignPriceCount; - UInt32 distTableSize; + uint32_t distTableSize; - UInt32 dictSize; + uint32_t dictSize; SRes result; CRangeEnc rc; #ifndef _7ZIP_ST - Bool mtMode; + bool mtMode; CMatchFinderMt matchFinderMt; #endif CMatchFinder matchFinderBase; #ifndef _7ZIP_ST - Byte pad[128]; + unsigned char pad[128]; #endif COptimal opt[kNumOpts]; - #ifndef LZMA_LOG_BSR - Byte g_FastPos[1 << kNumLogBits]; - #endif + unsigned char g_FastPos[1 << kNumLogBits]; - UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits]; - UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1]; + uint32_t ProbPrices[kBitModelTotal >> kNumMoveReducingBits]; + uint32_t matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1]; - UInt32 posSlotPrices[kNumLenToPosStates][kDistTableSizeMax]; - UInt32 distancesPrices[kNumLenToPosStates][kNumFullDistances]; - UInt32 alignPrices[kAlignTableSize]; + uint32_t posSlotPrices[kNumLenToPosStates][kDistTableSizeMax]; + uint32_t distancesPrices[kNumLenToPosStates][kNumFullDistances]; + uint32_t alignPrices[kAlignTableSize]; CLzmaProb isMatch[kNumStates][LZMA_NUM_PB_STATES_MAX]; CLzmaProb isRep[kNumStates]; @@ -378,7 +322,7 @@ typedef struct CSaveState saveState; #ifndef _7ZIP_ST - Byte pad2[128]; + unsigned char pad2[128]; #endif } CLzmaEnc; @@ -406,7 +350,7 @@ void LzmaEnc_SaveState(CLzmaEncHandle pp) memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders)); memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder)); memcpy(dest->reps, p->reps, sizeof(p->reps)); - memcpy(dest->litProbs, p->litProbs, ((UInt32)0x300 << p->lclp) * sizeof(CLzmaProb)); + memcpy(dest->litProbs, p->litProbs, ((uint32_t)0x300 << p->lclp) * sizeof(CLzmaProb)); } void LzmaEnc_RestoreState(CLzmaEncHandle pp) @@ -432,7 +376,7 @@ void LzmaEnc_RestoreState(CLzmaEncHandle pp) memcpy(dest->posEncoders, p->posEncoders, sizeof(p->posEncoders)); memcpy(dest->posAlignEncoder, p->posAlignEncoder, sizeof(p->posAlignEncoder)); memcpy(dest->reps, p->reps, sizeof(p->reps)); - memcpy(dest->litProbs, p->litProbs, ((UInt32)0x300 << dest->lclp) * sizeof(CLzmaProb)); + memcpy(dest->litProbs, p->litProbs, ((uint32_t)0x300 << dest->lclp) * sizeof(CLzmaProb)); } SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2) @@ -444,7 +388,7 @@ SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2) if (props.lc > LZMA_LC_MAX || props.lp > LZMA_LP_MAX || props.pb > LZMA_PB_MAX - || props.dictSize > ((UInt64)1 << kDicLogSizeMaxCompress) + || props.dictSize > ((uint64_t)1 << kDicLogSizeMaxCompress) || props.dictSize > kMaxHistorySize) return SZ_ERROR_PARAM; @@ -461,9 +405,9 @@ SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2) p->lp = props.lp; p->pb = props.pb; p->fastMode = (props.algo == 0); - p->matchFinderBase.btMode = (Byte)(props.btMode ? 1 : 0); + p->matchFinderBase.btMode = (unsigned char)(props.btMode ? 1 : 0); { - UInt32 numHashBytes = 4; + uint32_t numHashBytes = 4; if (props.btMode) { if (props.numHashBytes < 2) @@ -516,7 +460,7 @@ static int RangeEnc_Alloc(CRangeEnc *p, ISzAlloc *alloc) { if (!p->bufBase) { - p->bufBase = (Byte *)alloc->Alloc(alloc, RC_BUF_SIZE); + p->bufBase = (unsigned char *)alloc->Alloc(alloc, RC_BUF_SIZE); if (!p->bufBase) return 0; p->bufLim = p->bufBase + RC_BUF_SIZE; @@ -558,23 +502,23 @@ static void RangeEnc_FlushStream(CRangeEnc *p) static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p) { - if ((UInt32)p->low < (UInt32)0xFF000000 || (unsigned)(p->low >> 32) != 0) + if ((uint32_t)p->low < (uint32_t)0xFF000000 || (unsigned)(p->low >> 32) != 0) { - Byte temp = p->cache; + unsigned char temp = p->cache; do { - Byte *buf = p->buf; - *buf++ = (Byte)(temp + (Byte)(p->low >> 32)); + unsigned char *buf = p->buf; + *buf++ = (unsigned char)(temp + (unsigned char)(p->low >> 32)); p->buf = buf; if (buf == p->bufLim) RangeEnc_FlushStream(p); temp = 0xFF; } while (--p->cacheSize != 0); - p->cache = (Byte)((UInt32)p->low >> 24); + p->cache = (unsigned char)((uint32_t)p->low >> 24); } p->cacheSize++; - p->low = (UInt32)p->low << 8; + p->low = (uint32_t)p->low << 8; } static void RangeEnc_FlushData(CRangeEnc *p) @@ -584,7 +528,7 @@ static void RangeEnc_FlushData(CRangeEnc *p) RangeEnc_ShiftLow(p); } -static void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, unsigned numBits) +static void RangeEnc_EncodeDirectBits(CRangeEnc *p, uint32_t value, unsigned numBits) { do { @@ -599,10 +543,10 @@ static void RangeEnc_EncodeDirectBits(CRangeEnc *p, UInt32 value, unsigned numBi while (numBits != 0); } -static void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol) +static void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, uint32_t symbol) { - UInt32 ttt = *prob; - UInt32 newBound = (p->range >> kNumBitModelTotalBits) * ttt; + uint32_t ttt = *prob; + uint32_t newBound = (p->range >> kNumBitModelTotalBits) * ttt; if (symbol == 0) { p->range = newBound; @@ -622,7 +566,7 @@ static void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol) } } -static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol) +static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, uint32_t symbol) { symbol |= 0x100; do @@ -633,9 +577,9 @@ static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol) while (symbol < 0x10000); } -static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, UInt32 matchByte) +static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, uint32_t symbol, uint32_t matchByte) { - UInt32 offs = 0x100; + uint32_t offs = 0x100; symbol |= 0x100; do { @@ -647,20 +591,20 @@ static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol, while (symbol < 0x10000); } -static void LzmaEnc_InitPriceTables(UInt32 *ProbPrices) +static void LzmaEnc_InitPriceTables(uint32_t *ProbPrices) { - UInt32 i; + uint32_t i; for (i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits)) { const int kCyclesBits = kNumBitPriceShiftBits; - UInt32 w = i; - UInt32 bitCount = 0; + uint32_t w = i; + uint32_t bitCount = 0; int j; for (j = 0; j < kCyclesBits; j++) { w = w * w; bitCount <<= 1; - while (w >= ((UInt32)1 << 16)) + while (w >= ((uint32_t)1 << 16)) { w >>= 1; bitCount++; @@ -683,9 +627,9 @@ static void LzmaEnc_InitPriceTables(UInt32 *ProbPrices) #define GET_PRICE_0a(prob) ProbPrices[(prob) >> kNumMoveReducingBits] #define GET_PRICE_1a(prob) ProbPrices[((prob) ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits] -static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, const UInt32 *ProbPrices) +static uint32_t LitEnc_GetPrice(const CLzmaProb *probs, uint32_t symbol, const uint32_t *ProbPrices) { - UInt32 price = 0; + uint32_t price = 0; symbol |= 0x100; do { @@ -696,10 +640,10 @@ static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, const UInt3 return price; } -static UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, const UInt32 *ProbPrices) +static uint32_t LitEnc_GetPriceMatched(const CLzmaProb *probs, uint32_t symbol, uint32_t matchByte, const uint32_t *ProbPrices) { - UInt32 price = 0; - UInt32 offs = 0x100; + uint32_t price = 0; + uint32_t offs = 0x100; symbol |= 0x100; do { @@ -713,13 +657,13 @@ static UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt } -static void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol) +static void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, uint32_t symbol) { - UInt32 m = 1; + uint32_t m = 1; int i; for (i = numBitLevels; i != 0;) { - UInt32 bit; + uint32_t bit; i--; bit = (symbol >> i) & 1; RangeEnc_EncodeBit(rc, probs + m, bit); @@ -727,22 +671,22 @@ static void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UIn } } -static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol) +static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, uint32_t symbol) { - UInt32 m = 1; + uint32_t m = 1; int i; for (i = 0; i < numBitLevels; i++) { - UInt32 bit = symbol & 1; + uint32_t bit = symbol & 1; RangeEnc_EncodeBit(rc, probs + m, bit); m = (m << 1) | bit; symbol >>= 1; } } -static UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, const UInt32 *ProbPrices) +static uint32_t RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, uint32_t symbol, const uint32_t *ProbPrices) { - UInt32 price = 0; + uint32_t price = 0; symbol |= (1 << numBitLevels); while (symbol != 1) { @@ -752,14 +696,14 @@ static UInt32 RcTree_GetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 s return price; } -static UInt32 RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, UInt32 symbol, const UInt32 *ProbPrices) +static uint32_t RcTree_ReverseGetPrice(const CLzmaProb *probs, int numBitLevels, uint32_t symbol, const uint32_t *ProbPrices) { - UInt32 price = 0; - UInt32 m = 1; + uint32_t price = 0; + uint32_t m = 1; int i; for (i = numBitLevels; i != 0; i--) { - UInt32 bit = symbol & 1; + uint32_t bit = symbol & 1; symbol >>= 1; price += GET_PRICEa(probs[m], bit); m = (m << 1) | bit; @@ -780,7 +724,7 @@ static void LenEnc_Init(CLenEnc *p) p->high[i] = kProbInitValue; } -static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState) +static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, uint32_t symbol, uint32_t posState) { if (symbol < kLenNumLowSymbols) { @@ -803,13 +747,13 @@ static void LenEnc_Encode(CLenEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posSt } } -static void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UInt32 *prices, const UInt32 *ProbPrices) +static void LenEnc_SetPrices(CLenEnc *p, uint32_t posState, uint32_t numSymbols, uint32_t *prices, const uint32_t *ProbPrices) { - UInt32 a0 = GET_PRICE_0a(p->choice); - UInt32 a1 = GET_PRICE_1a(p->choice); - UInt32 b0 = a1 + GET_PRICE_0a(p->choice2); - UInt32 b1 = a1 + GET_PRICE_1a(p->choice2); - UInt32 i = 0; + uint32_t a0 = GET_PRICE_0a(p->choice); + uint32_t a1 = GET_PRICE_1a(p->choice); + uint32_t b0 = a1 + GET_PRICE_0a(p->choice2); + uint32_t b1 = a1 + GET_PRICE_1a(p->choice2); + uint32_t i = 0; for (i = 0; i < kLenNumLowSymbols; i++) { if (i >= numSymbols) @@ -826,20 +770,20 @@ static void LenEnc_SetPrices(CLenEnc *p, UInt32 posState, UInt32 numSymbols, UIn prices[i] = b1 + RcTree_GetPrice(p->high, kLenNumHighBits, i - kLenNumLowSymbols - kLenNumMidSymbols, ProbPrices); } -static void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, UInt32 posState, const UInt32 *ProbPrices) +static void MY_FAST_CALL LenPriceEnc_UpdateTable(CLenPriceEnc *p, uint32_t posState, const uint32_t *ProbPrices) { LenEnc_SetPrices(&p->p, posState, p->tableSize, p->prices[posState], ProbPrices); p->counters[posState] = p->tableSize; } -static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, UInt32 numPosStates, const UInt32 *ProbPrices) +static void LenPriceEnc_UpdateTables(CLenPriceEnc *p, uint32_t numPosStates, const uint32_t *ProbPrices) { - UInt32 posState; + uint32_t posState; for (posState = 0; posState < numPosStates; posState++) LenPriceEnc_UpdateTable(p, posState, ProbPrices); } -static void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 posState, Bool updatePrice, const UInt32 *ProbPrices) +static void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, uint32_t symbol, uint32_t posState, bool updatePrice, const uint32_t *ProbPrices) { LenEnc_Encode(&p->p, rc, symbol, posState); if (updatePrice) @@ -850,13 +794,8 @@ static void LenEnc_Encode2(CLenPriceEnc *p, CRangeEnc *rc, UInt32 symbol, UInt32 -static void MovePos(CLzmaEnc *p, UInt32 num) +static void MovePos(CLzmaEnc *p, uint32_t num) { - #ifdef SHOW_STAT - g_STAT_OFFSET += num; - printf("\n MovePos %u", num); - #endif - if (num != 0) { p->additionalOffset += num; @@ -864,37 +803,27 @@ static void MovePos(CLzmaEnc *p, UInt32 num) } } -static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes) +static uint32_t ReadMatchDistances(CLzmaEnc *p, uint32_t *numDistancePairsRes) { - UInt32 lenRes = 0, numPairs; + uint32_t lenRes = 0, numPairs; p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj); numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches); - #ifdef SHOW_STAT - printf("\n i = %u numPairs = %u ", g_STAT_OFFSET, numPairs / 2); - g_STAT_OFFSET++; - { - UInt32 i; - for (i = 0; i < numPairs; i += 2) - printf("%2u %6u | ", p->matches[i], p->matches[i + 1]); - } - #endif - if (numPairs > 0) { lenRes = p->matches[numPairs - 2]; if (lenRes == p->numFastBytes) { - UInt32 numAvail = p->numAvail; + uint32_t numAvail = p->numAvail; if (numAvail > LZMA_MATCH_LEN_MAX) numAvail = LZMA_MATCH_LEN_MAX; { - const Byte *pbyCur = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; - const Byte *pby = pbyCur + lenRes; + const unsigned char *pbyCur = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; + const unsigned char *pby = pbyCur + lenRes; ptrdiff_t dif = (ptrdiff_t)-1 - p->matches[numPairs - 1]; - const Byte *pbyLim = pbyCur + numAvail; + const unsigned char *pbyLim = pbyCur + numAvail; for (; pby != pbyLim && *pby == pby[dif]; pby++); - lenRes = (UInt32)(pby - pbyCur); + lenRes = (uint32_t)(pby - pbyCur); } } } @@ -904,20 +833,20 @@ static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes) } -#define MakeAsChar(p) (p)->backPrev = (UInt32)(-1); (p)->prev1IsChar = False; -#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = False; +#define MakeAsChar(p) (p)->backPrev = (uint32_t)(-1); (p)->prev1IsChar = false; +#define MakeAsShortRep(p) (p)->backPrev = 0; (p)->prev1IsChar = false; #define IsShortRep(p) ((p)->backPrev == 0) -static UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState) +static uint32_t GetRepLen1Price(CLzmaEnc *p, uint32_t state, uint32_t posState) { return GET_PRICE_0(p->isRepG0[state]) + GET_PRICE_0(p->isRep0Long[state][posState]); } -static UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 posState) +static uint32_t GetPureRepPrice(CLzmaEnc *p, uint32_t repIndex, uint32_t state, uint32_t posState) { - UInt32 price; + uint32_t price; if (repIndex == 0) { price = GET_PRICE_0(p->isRepG0[state]); @@ -937,16 +866,16 @@ static UInt32 GetPureRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 state, UInt32 return price; } -static UInt32 GetRepPrice(CLzmaEnc *p, UInt32 repIndex, UInt32 len, UInt32 state, UInt32 posState) +static uint32_t GetRepPrice(CLzmaEnc *p, uint32_t repIndex, uint32_t len, uint32_t state, uint32_t posState) { return p->repLenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN] + GetPureRepPrice(p, repIndex, state, posState); } -static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur) +static uint32_t Backward(CLzmaEnc *p, uint32_t *backRes, uint32_t cur) { - UInt32 posMem = p->opt[cur].posPrev; - UInt32 backMem = p->opt[cur].backPrev; + uint32_t posMem = p->opt[cur].posPrev; + uint32_t backMem = p->opt[cur].backPrev; p->optimumEndIndex = cur; do { @@ -956,14 +885,14 @@ static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur) p->opt[posMem].posPrev = posMem - 1; if (p->opt[cur].prev2) { - p->opt[posMem - 1].prev1IsChar = False; + p->opt[posMem - 1].prev1IsChar = false; p->opt[posMem - 1].posPrev = p->opt[cur].posPrev2; p->opt[posMem - 1].backPrev = p->opt[cur].backPrev2; } } { - UInt32 posPrev = posMem; - UInt32 backCur = backMem; + uint32_t posPrev = posMem; + uint32_t backCur = backMem; backMem = p->opt[posPrev].backPrev; posMem = p->opt[posPrev].posPrev; @@ -979,25 +908,25 @@ static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur) return p->optimumCurrentIndex; } -#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * (UInt32)0x300) +#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * (uint32_t)0x300) -static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) +static uint32_t GetOptimum(CLzmaEnc *p, uint32_t position, uint32_t *backRes) { - UInt32 lenEnd, cur; - UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS]; - UInt32 *matches; + uint32_t lenEnd, cur; + uint32_t reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS]; + uint32_t *matches; { - UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, len; - UInt32 matchPrice, repMatchPrice, normalMatchPrice; - const Byte *data; - Byte curByte, matchByte; + uint32_t numAvail, mainLen, numPairs, repMaxIndex, i, posState, len; + uint32_t matchPrice, repMatchPrice, normalMatchPrice; + const unsigned char *data; + unsigned char curByte, matchByte; if (p->optimumEndIndex != p->optimumCurrentIndex) { const COptimal *opt = &p->opt[p->optimumCurrentIndex]; - UInt32 lenRes = opt->posPrev - p->optimumCurrentIndex; + uint32_t lenRes = opt->posPrev - p->optimumCurrentIndex; *backRes = opt->backPrev; p->optimumCurrentIndex = opt->posPrev; return lenRes; @@ -1015,7 +944,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) numAvail = p->numAvail; if (numAvail < 2) { - *backRes = (UInt32)(-1); + *backRes = (uint32_t)(-1); return 1; } if (numAvail > LZMA_MATCH_LEN_MAX) @@ -1025,8 +954,8 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) repMaxIndex = 0; for (i = 0; i < LZMA_NUM_REPS; i++) { - UInt32 lenTest; - const Byte *data2; + uint32_t lenTest; + const unsigned char *data2; reps[i] = p->reps[i]; data2 = data - reps[i] - 1; if (data[0] != data2[0] || data[1] != data2[1]) @@ -1041,7 +970,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) } if (repLens[repMaxIndex] >= p->numFastBytes) { - UInt32 lenRes; + uint32_t lenRes; *backRes = repMaxIndex; lenRes = repLens[repMaxIndex]; MovePos(p, lenRes - 1); @@ -1060,7 +989,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2) { - *backRes = (UInt32)-1; + *backRes = (uint32_t)-1; return 1; } @@ -1083,7 +1012,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) if (matchByte == curByte) { - UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState); + uint32_t shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState); if (shortRepPrice < p->opt[1].price) { p->opt[1].price = shortRepPrice; @@ -1109,21 +1038,21 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) for (i = 0; i < LZMA_NUM_REPS; i++) { - UInt32 repLen = repLens[i]; - UInt32 price; + uint32_t repLen = repLens[i]; + uint32_t price; if (repLen < 2) continue; price = repMatchPrice + GetPureRepPrice(p, i, p->state, posState); do { - UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2]; + uint32_t curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2]; COptimal *opt = &p->opt[repLen]; if (curAndLenPrice < opt->price) { opt->price = curAndLenPrice; opt->posPrev = 0; opt->backPrev = i; - opt->prev1IsChar = False; + opt->prev1IsChar = false; } } while (--repLen >= 2); @@ -1134,21 +1063,21 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2); if (len <= mainLen) { - UInt32 offs = 0; + uint32_t offs = 0; while (len > matches[offs]) offs += 2; for (; ; len++) { COptimal *opt; - UInt32 distance = matches[offs + 1]; + uint32_t distance = matches[offs + 1]; - UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN]; - UInt32 lenToPosState = GetLenToPosState(len); + uint32_t curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN]; + uint32_t lenToPosState = GetLenToPosState(len); if (distance < kNumFullDistances) curAndLenPrice += p->distancesPrices[lenToPosState][distance]; else { - UInt32 slot; + uint32_t slot; GetPosSlot2(distance, slot); curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot]; } @@ -1158,7 +1087,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) opt->price = curAndLenPrice; opt->posPrev = 0; opt->backPrev = distance + LZMA_NUM_REPS; - opt->prev1IsChar = False; + opt->prev1IsChar = false; } if (len == matches[offs]) { @@ -1171,26 +1100,16 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) cur = 0; - #ifdef SHOW_STAT2 - /* if (position >= 0) */ - { - unsigned i; - printf("\n pos = %4X", position); - for (i = cur; i <= lenEnd; i++) - printf("\nprice[%4X] = %u", position - cur + i, p->opt[i].price); - } - #endif - } for (;;) { - UInt32 numAvail; - UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen; - UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice; - Bool nextIsChar; - Byte curByte, matchByte; - const Byte *data; + uint32_t numAvail; + uint32_t numAvailFull, newLen, numPairs, posPrev, state, posState, startLen; + uint32_t curPrice, curAnd1Price, matchPrice, repMatchPrice; + bool nextIsChar; + unsigned char curByte, matchByte; + const unsigned char *data; COptimal *curOpt; COptimal *nextOpt; @@ -1234,7 +1153,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) } else { - UInt32 pos; + uint32_t pos; const COptimal *prevOpt; if (curOpt->prev1IsChar && curOpt->prev2) { @@ -1253,7 +1172,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) prevOpt = &p->opt[posPrev]; if (pos < LZMA_NUM_REPS) { - UInt32 i; + uint32_t i; reps[0] = prevOpt->backs[pos]; for (i = 1; i <= pos; i++) reps[i] = prevOpt->backs[i - 1]; @@ -1262,7 +1181,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) } else { - UInt32 i; + uint32_t i; reps[0] = (pos - LZMA_NUM_REPS); for (i = 1; i < LZMA_NUM_REPS; i++) reps[i] = prevOpt->backs[i - 1]; @@ -1276,7 +1195,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) curOpt->backs[3] = reps[3]; curPrice = curOpt->price; - nextIsChar = False; + nextIsChar = false; data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; curByte = *data; matchByte = *(data - (reps[0] + 1)); @@ -1299,7 +1218,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) nextOpt->price = curAnd1Price; nextOpt->posPrev = cur; MakeAsChar(nextOpt); - nextIsChar = True; + nextIsChar = true; } matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]); @@ -1307,18 +1226,18 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0)) { - UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState); + uint32_t shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState); if (shortRepPrice <= nextOpt->price) { nextOpt->price = shortRepPrice; nextOpt->posPrev = cur; MakeAsShortRep(nextOpt); - nextIsChar = True; + nextIsChar = true; } } numAvailFull = p->numAvail; { - UInt32 temp = kNumOpts - 1 - cur; + uint32_t temp = kNumOpts - 1 - cur; if (temp < numAvailFull) numAvailFull = temp; } @@ -1330,10 +1249,10 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) if (!nextIsChar && matchByte != curByte) /* speed optimization */ { /* try Literal + rep0 */ - UInt32 temp; - UInt32 lenTest2; - const Byte *data2 = data - reps[0] - 1; - UInt32 limit = p->numFastBytes + 1; + uint32_t temp; + uint32_t lenTest2; + const unsigned char *data2 = data - reps[0] - 1; + uint32_t limit = p->numFastBytes + 1; if (limit > numAvailFull) limit = numAvailFull; @@ -1341,16 +1260,16 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) lenTest2 = temp - 1; if (lenTest2 >= 2) { - UInt32 state2 = kLiteralNextStates[state]; - UInt32 posStateNext = (position + 1) & p->pbMask; - UInt32 nextRepMatchPrice = curAnd1Price + + uint32_t state2 = kLiteralNextStates[state]; + uint32_t posStateNext = (position + 1) & p->pbMask; + uint32_t nextRepMatchPrice = curAnd1Price + GET_PRICE_1(p->isMatch[state2][posStateNext]) + GET_PRICE_1(p->isRep[state2]); /* for (; lenTest2 >= 2; lenTest2--) */ { - UInt32 curAndLenPrice; + uint32_t curAndLenPrice; COptimal *opt; - UInt32 offset = cur + 1 + lenTest2; + uint32_t offset = cur + 1 + lenTest2; while (lenEnd < offset) p->opt[++lenEnd].price = kInfinityPrice; curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext); @@ -1360,8 +1279,8 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) opt->price = curAndLenPrice; opt->posPrev = cur + 1; opt->backPrev = 0; - opt->prev1IsChar = True; - opt->prev2 = False; + opt->prev1IsChar = true; + opt->prev2 = false; } } } @@ -1369,13 +1288,13 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) startLen = 2; /* speed optimization */ { - UInt32 repIndex; + uint32_t repIndex; for (repIndex = 0; repIndex < LZMA_NUM_REPS; repIndex++) { - UInt32 lenTest; - UInt32 lenTestTemp; - UInt32 price; - const Byte *data2 = data - reps[repIndex] - 1; + uint32_t lenTest; + uint32_t lenTestTemp; + uint32_t price; + const unsigned char *data2 = data - reps[repIndex] - 1; if (data[0] != data2[0] || data[1] != data2[1]) continue; for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++); @@ -1385,14 +1304,14 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) price = repMatchPrice + GetPureRepPrice(p, repIndex, state, posState); do { - UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2]; + uint32_t curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2]; COptimal *opt = &p->opt[cur + lenTest]; if (curAndLenPrice < opt->price) { opt->price = curAndLenPrice; opt->posPrev = cur; opt->backPrev = repIndex; - opt->prev1IsChar = False; + opt->prev1IsChar = false; } } while (--lenTest >= 2); @@ -1403,18 +1322,18 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) /* if (_maxMode) */ { - UInt32 lenTest2 = lenTest + 1; - UInt32 limit = lenTest2 + p->numFastBytes; + uint32_t lenTest2 = lenTest + 1; + uint32_t limit = lenTest2 + p->numFastBytes; if (limit > numAvailFull) limit = numAvailFull; for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++); lenTest2 -= lenTest + 1; if (lenTest2 >= 2) { - UInt32 nextRepMatchPrice; - UInt32 state2 = kRepNextStates[state]; - UInt32 posStateNext = (position + lenTest) & p->pbMask; - UInt32 curAndLenCharPrice = + uint32_t nextRepMatchPrice; + uint32_t state2 = kRepNextStates[state]; + uint32_t posStateNext = (position + lenTest) & p->pbMask; + uint32_t curAndLenCharPrice = price + p->repLenEnc.prices[posState][lenTest - 2] + GET_PRICE_0(p->isMatch[state2][posStateNext]) + LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]), @@ -1427,9 +1346,9 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) /* for (; lenTest2 >= 2; lenTest2--) */ { - UInt32 curAndLenPrice; + uint32_t curAndLenPrice; COptimal *opt; - UInt32 offset = cur + lenTest + 1 + lenTest2; + uint32_t offset = cur + lenTest + 1 + lenTest2; while (lenEnd < offset) p->opt[++lenEnd].price = kInfinityPrice; curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext); @@ -1439,8 +1358,8 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) opt->price = curAndLenPrice; opt->posPrev = cur + lenTest + 1; opt->backPrev = 0; - opt->prev1IsChar = True; - opt->prev2 = True; + opt->prev1IsChar = true; + opt->prev2 = true; opt->posPrev2 = cur; opt->backPrev2 = repIndex; } @@ -1449,7 +1368,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) } } } - /* for (UInt32 lenTest = 2; lenTest <= newLen; lenTest++) */ + /* for (uint32_t lenTest = 2; lenTest <= newLen; lenTest++) */ if (newLen > numAvail) { newLen = numAvail; @@ -1459,9 +1378,9 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) } if (newLen >= startLen) { - UInt32 normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]); - UInt32 offs, curBack, posSlot; - UInt32 lenTest; + uint32_t normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[state]); + uint32_t offs, curBack, posSlot; + uint32_t lenTest; while (lenEnd < cur + newLen) p->opt[++lenEnd].price = kInfinityPrice; @@ -1472,9 +1391,9 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) GetPosSlot2(curBack, posSlot); for (lenTest = /*2*/ startLen; ; lenTest++) { - UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN]; + uint32_t curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][lenTest - LZMA_MATCH_LEN_MIN]; { - UInt32 lenToPosState = GetLenToPosState(lenTest); + uint32_t lenToPosState = GetLenToPosState(lenTest); COptimal *opt; if (curBack < kNumFullDistances) curAndLenPrice += p->distancesPrices[lenToPosState][curBack]; @@ -1487,26 +1406,26 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) opt->price = curAndLenPrice; opt->posPrev = cur; opt->backPrev = curBack + LZMA_NUM_REPS; - opt->prev1IsChar = False; + opt->prev1IsChar = false; } } if (/*_maxMode && */lenTest == matches[offs]) { /* Try Match + Literal + Rep0 */ - const Byte *data2 = data - curBack - 1; - UInt32 lenTest2 = lenTest + 1; - UInt32 limit = lenTest2 + p->numFastBytes; + const unsigned char *data2 = data - curBack - 1; + uint32_t lenTest2 = lenTest + 1; + uint32_t limit = lenTest2 + p->numFastBytes; if (limit > numAvailFull) limit = numAvailFull; for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++); lenTest2 -= lenTest + 1; if (lenTest2 >= 2) { - UInt32 nextRepMatchPrice; - UInt32 state2 = kMatchNextStates[state]; - UInt32 posStateNext = (position + lenTest) & p->pbMask; - UInt32 curAndLenCharPrice = curAndLenPrice + + uint32_t nextRepMatchPrice; + uint32_t state2 = kMatchNextStates[state]; + uint32_t posStateNext = (position + lenTest) & p->pbMask; + uint32_t curAndLenCharPrice = curAndLenPrice + GET_PRICE_0(p->isMatch[state2][posStateNext]) + LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]), data[lenTest], data2[lenTest], p->ProbPrices); @@ -1518,8 +1437,8 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) /* for (; lenTest2 >= 2; lenTest2--) */ { - UInt32 offset = cur + lenTest + 1 + lenTest2; - UInt32 curAndLenPrice2; + uint32_t offset = cur + lenTest + 1 + lenTest2; + uint32_t curAndLenPrice2; COptimal *opt; while (lenEnd < offset) p->opt[++lenEnd].price = kInfinityPrice; @@ -1530,8 +1449,8 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) opt->price = curAndLenPrice2; opt->posPrev = cur + lenTest + 1; opt->backPrev = 0; - opt->prev1IsChar = True; - opt->prev2 = True; + opt->prev1IsChar = true; + opt->prev2 = true; opt->posPrev2 = cur; opt->backPrev2 = curBack + LZMA_NUM_REPS; } @@ -1551,11 +1470,11 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes) #define ChangePair(smallDist, bigDist) (((bigDist) >> 7) > (smallDist)) -static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes) +static uint32_t GetOptimumFast(CLzmaEnc *p, uint32_t *backRes) { - UInt32 numAvail, mainLen, mainDist, numPairs, repIndex, repLen, i; - const Byte *data; - const UInt32 *matches; + uint32_t numAvail, mainLen, mainDist, numPairs, repIndex, repLen, i; + const unsigned char *data; + const uint32_t *matches; if (p->additionalOffset == 0) mainLen = ReadMatchDistances(p, &numPairs); @@ -1566,7 +1485,7 @@ static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes) } numAvail = p->numAvail; - *backRes = (UInt32)-1; + *backRes = (uint32_t)-1; if (numAvail < 2) return 1; if (numAvail > LZMA_MATCH_LEN_MAX) @@ -1576,8 +1495,8 @@ static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes) repLen = repIndex = 0; for (i = 0; i < LZMA_NUM_REPS; i++) { - UInt32 len; - const Byte *data2 = data - p->reps[i] - 1; + uint32_t len; + const unsigned char *data2 = data - p->reps[i] - 1; if (data[0] != data2[0] || data[1] != data2[1]) continue; for (len = 2; len < numAvail && data[len] == data2[len]; len++); @@ -1634,7 +1553,7 @@ static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes) p->longestMatchLength = ReadMatchDistances(p, &p->numPairs); if (p->longestMatchLength >= 2) { - UInt32 newDistance = matches[p->numPairs - 1]; + uint32_t newDistance = matches[p->numPairs - 1]; if ((p->longestMatchLength >= mainLen && newDistance < mainDist) || (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) || (p->longestMatchLength > mainLen + 1) || @@ -1645,8 +1564,8 @@ static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes) data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1; for (i = 0; i < LZMA_NUM_REPS; i++) { - UInt32 len, limit; - const Byte *data2 = data - p->reps[i] - 1; + uint32_t len, limit; + const unsigned char *data2 = data - p->reps[i] - 1; if (data[0] != data2[0] || data[1] != data2[1]) continue; limit = mainLen - 1; @@ -1659,16 +1578,16 @@ static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes) return mainLen; } -static void WriteEndMarker(CLzmaEnc *p, UInt32 posState) +static void WriteEndMarker(CLzmaEnc *p, uint32_t posState) { - UInt32 len; + uint32_t len; RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 1); RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0); p->state = kMatchNextStates[p->state]; len = LZMA_MATCH_LEN_MIN; LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices); RcTree_Encode(&p->rc, p->posSlotEncoder[GetLenToPosState(len)], kNumPosSlotBits, (1 << kNumPosSlotBits) - 1); - RangeEnc_EncodeDirectBits(&p->rc, (((UInt32)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits); + RangeEnc_EncodeDirectBits(&p->rc, (((uint32_t)1 << 30) - 1) >> kNumAlignBits, 30 - kNumAlignBits); RcTree_ReverseEncode(&p->rc, p->posAlignEncoder, kNumAlignBits, kAlignMask); } @@ -1681,14 +1600,14 @@ static SRes CheckErrors(CLzmaEnc *p) if (p->matchFinderBase.result != SZ_OK) p->result = SZ_ERROR_READ; if (p->result != SZ_OK) - p->finished = True; + p->finished = true; return p->result; } -static SRes Flush(CLzmaEnc *p, UInt32 nowPos) +static SRes Flush(CLzmaEnc *p, uint32_t nowPos) { /* ReleaseMFStream(); */ - p->finished = True; + p->finished = true; if (p->writeEndMark) WriteEndMarker(p, nowPos & p->pbMask); RangeEnc_FlushData(&p->rc); @@ -1698,7 +1617,7 @@ static SRes Flush(CLzmaEnc *p, UInt32 nowPos) static void FillAlignPrices(CLzmaEnc *p) { - UInt32 i; + uint32_t i; for (i = 0; i < kAlignTableSize; i++) p->alignPrices[i] = RcTree_ReverseGetPrice(p->posAlignEncoder, kNumAlignBits, i, p->ProbPrices); p->alignPriceCount = 0; @@ -1706,28 +1625,28 @@ static void FillAlignPrices(CLzmaEnc *p) static void FillDistancesPrices(CLzmaEnc *p) { - UInt32 tempPrices[kNumFullDistances]; - UInt32 i, lenToPosState; + uint32_t tempPrices[kNumFullDistances]; + uint32_t i, lenToPosState; for (i = kStartPosModelIndex; i < kNumFullDistances; i++) { - UInt32 posSlot = GetPosSlot1(i); - UInt32 footerBits = ((posSlot >> 1) - 1); - UInt32 base = ((2 | (posSlot & 1)) << footerBits); + uint32_t posSlot = GetPosSlot1(i); + uint32_t footerBits = ((posSlot >> 1) - 1); + uint32_t base = ((2 | (posSlot & 1)) << footerBits); tempPrices[i] = RcTree_ReverseGetPrice(p->posEncoders + base - posSlot - 1, footerBits, i - base, p->ProbPrices); } for (lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++) { - UInt32 posSlot; + uint32_t posSlot; const CLzmaProb *encoder = p->posSlotEncoder[lenToPosState]; - UInt32 *posSlotPrices = p->posSlotPrices[lenToPosState]; + uint32_t *posSlotPrices = p->posSlotPrices[lenToPosState]; for (posSlot = 0; posSlot < p->distTableSize; posSlot++) posSlotPrices[posSlot] = RcTree_GetPrice(encoder, kNumPosSlotBits, posSlot, p->ProbPrices); for (posSlot = kEndPosModelIndex; posSlot < p->distTableSize; posSlot++) posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << kNumBitPriceShiftBits); { - UInt32 *distancesPrices = p->distancesPrices[lenToPosState]; + uint32_t *distancesPrices = p->distancesPrices[lenToPosState]; for (i = 0; i < kStartPosModelIndex; i++) distancesPrices[i] = posSlotPrices[i]; for (; i < kNumFullDistances; i++) @@ -1753,9 +1672,7 @@ void LzmaEnc_Construct(CLzmaEnc *p) LzmaEnc_SetProps(p, &props); } - #ifndef LZMA_LOG_BSR LzmaEnc_FastPosInit(p->g_FastPos); - #endif LzmaEnc_InitPriceTables(p->ProbPrices); p->litProbs = NULL; @@ -1796,9 +1713,9 @@ void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig) alloc->Free(alloc, p); } -static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize, UInt32 maxUnpackSize) +static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, bool useLimits, uint32_t maxPackSize, uint32_t maxUnpackSize) { - UInt32 nowPos32, startPos32; + uint32_t nowPos32, startPos32; if (p->needInit) { p->matchFinder.Init(p->matchFinderObj); @@ -1809,13 +1726,13 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize return p->result; RINOK(CheckErrors(p)); - nowPos32 = (UInt32)p->nowPos64; + nowPos32 = (uint32_t)p->nowPos64; startPos32 = nowPos32; if (p->nowPos64 == 0) { - UInt32 numPairs; - Byte curByte; + uint32_t numPairs; + unsigned char curByte; if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0) return Flush(p, nowPos32); ReadMatchDistances(p, &numPairs); @@ -1830,23 +1747,19 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) != 0) for (;;) { - UInt32 pos, len, posState; + uint32_t pos, len, posState; if (p->fastMode) len = GetOptimumFast(p, &pos); else len = GetOptimum(p, nowPos32, &pos); - #ifdef SHOW_STAT2 - printf("\n pos = %4X, len = %u pos = %u", nowPos32, len, pos); - #endif - posState = nowPos32 & p->pbMask; - if (len == 1 && pos == (UInt32)-1) + if (len == 1 && pos == (uint32_t)-1) { - Byte curByte; + unsigned char curByte; CLzmaProb *probs; - const Byte *data; + const unsigned char *data; RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][posState], 0); data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset; @@ -1871,7 +1784,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize } else { - UInt32 distance = p->reps[pos]; + uint32_t distance = p->reps[pos]; RangeEnc_EncodeBit(&p->rc, &p->isRepG0[p->state], 1); if (pos == 1) RangeEnc_EncodeBit(&p->rc, &p->isRepG1[p->state], 0); @@ -1896,7 +1809,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize } else { - UInt32 posSlot; + uint32_t posSlot; RangeEnc_EncodeBit(&p->rc, &p->isRep[p->state], 0); p->state = kMatchNextStates[p->state]; LenEnc_Encode2(&p->lenEnc, &p->rc, len - LZMA_MATCH_LEN_MIN, posState, !p->fastMode, p->ProbPrices); @@ -1906,9 +1819,9 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize if (posSlot >= kStartPosModelIndex) { - UInt32 footerBits = ((posSlot >> 1) - 1); - UInt32 base = ((2 | (posSlot & 1)) << footerBits); - UInt32 posReduced = pos - base; + uint32_t footerBits = ((posSlot >> 1) - 1); + uint32_t base = ((2 | (posSlot & 1)) << footerBits); + uint32_t posReduced = pos - base; if (posSlot < kEndPosModelIndex) RcTree_ReverseEncode(&p->rc, p->posEncoders + base - posSlot - 1, footerBits, posReduced); @@ -1930,7 +1843,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize nowPos32 += len; if (p->additionalOffset == 0) { - UInt32 processed; + uint32_t processed; if (!p->fastMode) { if (p->matchPriceCount >= (1 << 7)) @@ -1958,11 +1871,11 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize return Flush(p, nowPos32); } -#define kBigHashDicLimit ((UInt32)1 << 24) +#define kBigHashDicLimit ((uint32_t)1 << 24) -static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig) +static SRes LzmaEnc_Alloc(CLzmaEnc *p, uint32_t keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig) { - UInt32 beforeSize = kNumOpts; + uint32_t beforeSize = kNumOpts; if (!RangeEnc_Alloc(&p->rc, alloc)) return SZ_ERROR_MEM; @@ -1975,8 +1888,8 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, I if (!p->litProbs || !p->saveState.litProbs || p->lclp != lclp) { LzmaEnc_FreeLits(p, alloc); - p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb)); - p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, ((UInt32)0x300 << lclp) * sizeof(CLzmaProb)); + p->litProbs = (CLzmaProb *)alloc->Alloc(alloc, ((uint32_t)0x300 << lclp) * sizeof(CLzmaProb)); + p->saveState.litProbs = (CLzmaProb *)alloc->Alloc(alloc, ((uint32_t)0x300 << lclp) * sizeof(CLzmaProb)); if (!p->litProbs || !p->saveState.litProbs) { LzmaEnc_FreeLits(p, alloc); @@ -1986,7 +1899,7 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, I } } - p->matchFinderBase.bigHash = (Byte)(p->dictSize > kBigHashDicLimit ? 1 : 0); + p->matchFinderBase.bigHash = (unsigned char)(p->dictSize > kBigHashDicLimit ? 1 : 0); if (beforeSize + p->dictSize < keepWindowSize) beforeSize = keepWindowSize - p->dictSize; @@ -2012,7 +1925,7 @@ static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, I void LzmaEnc_Init(CLzmaEnc *p) { - UInt32 i; + uint32_t i; p->state = 0; for (i = 0 ; i < LZMA_NUM_REPS; i++) p->reps[i] = 0; @@ -2022,7 +1935,7 @@ void LzmaEnc_Init(CLzmaEnc *p) for (i = 0; i < kNumStates; i++) { - UInt32 j; + uint32_t j; for (j = 0; j < LZMA_NUM_PB_STATES_MAX; j++) { p->isMatch[i][j] = kProbInitValue; @@ -2035,7 +1948,7 @@ void LzmaEnc_Init(CLzmaEnc *p) } { - UInt32 num = (UInt32)0x300 << (p->lp + p->lc); + uint32_t num = (uint32_t)0x300 << (p->lp + p->lc); CLzmaProb *probs = p->litProbs; for (i = 0; i < num; i++) probs[i] = kProbInitValue; @@ -2045,7 +1958,7 @@ void LzmaEnc_Init(CLzmaEnc *p) for (i = 0; i < kNumLenToPosStates; i++) { CLzmaProb *probs = p->posSlotEncoder[i]; - UInt32 j; + uint32_t j; for (j = 0; j < (1 << kNumPosSlotBits); j++) probs[j] = kProbInitValue; } @@ -2084,15 +1997,15 @@ void LzmaEnc_InitPrices(CLzmaEnc *p) LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices); } -static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig) +static SRes LzmaEnc_AllocAndInit(CLzmaEnc *p, uint32_t keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig) { - UInt32 i; - for (i = 0; i < (UInt32)kDicLogSizeMaxCompress; i++) - if (p->dictSize <= ((UInt32)1 << i)) + uint32_t i; + for (i = 0; i < (uint32_t)kDicLogSizeMaxCompress; i++) + if (p->dictSize <= ((uint32_t)1 << i)) break; p->distTableSize = i * 2; - p->finished = False; + p->finished = false; p->result = SZ_OK; RINOK(LzmaEnc_Alloc(p, keepWindowSize, alloc, allocBig)); LzmaEnc_Init(p); @@ -2112,7 +2025,7 @@ static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInS } SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp, - ISeqInStream *inStream, UInt32 keepWindowSize, + ISeqInStream *inStream, uint32_t keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig) { CLzmaEnc *p = (CLzmaEnc *)pp; @@ -2121,15 +2034,15 @@ SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp, return LzmaEnc_AllocAndInit(p, keepWindowSize, alloc, allocBig); } -static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const Byte *src, SizeT srcLen) +static void LzmaEnc_SetInputBuf(CLzmaEnc *p, const unsigned char *src, size_t srcLen) { p->matchFinderBase.directInput = 1; - p->matchFinderBase.bufferBase = (Byte *)src; + p->matchFinderBase.bufferBase = (unsigned char *)src; p->matchFinderBase.directInputRem = srcLen; } -SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen, - UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig) +SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const unsigned char *src, size_t srcLen, + uint32_t keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig) { CLzmaEnc *p = (CLzmaEnc *)pp; LzmaEnc_SetInputBuf(p, src, srcLen); @@ -2140,22 +2053,20 @@ SRes LzmaEnc_MemPrepare(CLzmaEncHandle pp, const Byte *src, SizeT srcLen, void LzmaEnc_Finish(CLzmaEncHandle pp) { - #ifndef _7ZIP_ST - CLzmaEnc *p = (CLzmaEnc *)pp; - if (p->mtMode) - MatchFinderMt_ReleaseStream(&p->matchFinderMt); - #else - UNUSED_VAR(pp); - #endif +#ifndef _7ZIP_ST + CLzmaEnc *p = (CLzmaEnc *)pp; + if (p->mtMode) + MatchFinderMt_ReleaseStream(&p->matchFinderMt); +#endif } typedef struct { ISeqOutStream funcTable; - Byte *data; - SizeT rem; - Bool overflow; + unsigned char *data; + size_t rem; + bool overflow; } CSeqOutStreamBuf; static size_t MyWrite(void *pp, const void *data, size_t size) @@ -2164,7 +2075,7 @@ static size_t MyWrite(void *pp, const void *data, size_t size) if (p->rem < size) { size = p->rem; - p->overflow = True; + p->overflow = true; } memcpy(p->data, data, size); p->rem -= size; @@ -2173,35 +2084,35 @@ static size_t MyWrite(void *pp, const void *data, size_t size) } -UInt32 LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp) +uint32_t LzmaEnc_GetNumAvailableBytes(CLzmaEncHandle pp) { const CLzmaEnc *p = (CLzmaEnc *)pp; return p->matchFinder.GetNumAvailableBytes(p->matchFinderObj); } -const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp) +const unsigned char *LzmaEnc_GetCurBuf(CLzmaEncHandle pp) { const CLzmaEnc *p = (CLzmaEnc *)pp; return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset; } -SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit, - Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize) +SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, bool reInit, + unsigned char *dest, size_t *destLen, uint32_t desiredPackSize, uint32_t *unpackSize) { CLzmaEnc *p = (CLzmaEnc *)pp; - UInt64 nowPos64; + uint64_t nowPos64; SRes res; CSeqOutStreamBuf outStream; outStream.funcTable.Write = MyWrite; outStream.data = dest; outStream.rem = *destLen; - outStream.overflow = False; + outStream.overflow = false; - p->writeEndMark = False; - p->finished = False; + p->writeEndMark = false; + p->finished = false; p->result = SZ_OK; if (reInit) @@ -2211,9 +2122,9 @@ SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit, RangeEnc_Init(&p->rc); p->rc.outStream = &outStream.funcTable; - res = LzmaEnc_CodeOneBlock(p, True, desiredPackSize, *unpackSize); + res = LzmaEnc_CodeOneBlock(p, true, desiredPackSize, *unpackSize); - *unpackSize = (UInt32)(p->nowPos64 - nowPos64); + *unpackSize = (uint32_t)(p->nowPos64 - nowPos64); *destLen -= outStream.rem; if (outStream.overflow) return SZ_ERROR_OUTPUT_EOF; @@ -2227,14 +2138,14 @@ static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress) SRes res = SZ_OK; #ifndef _7ZIP_ST - Byte allocaDummy[0x300]; + unsigned char allocaDummy[0x300]; allocaDummy[0] = 0; allocaDummy[1] = allocaDummy[0]; #endif for (;;) { - res = LzmaEnc_CodeOneBlock(p, False, 0, 0); + res = LzmaEnc_CodeOneBlock(p, false, 0, 0); if (res != SZ_OK || p->finished) break; if (progress) @@ -2250,12 +2161,6 @@ static SRes LzmaEnc_Encode2(CLzmaEnc *p, ICompressProgress *progress) LzmaEnc_Finish(p); - /* - if (res == S_OK && !Inline_MatchFinder_IsFinishedOK(&p->matchFinderBase)) - res = SZ_ERROR_FAIL; - } - */ - return res; } @@ -2268,35 +2173,35 @@ SRes LzmaEnc_Encode(CLzmaEncHandle pp, ISeqOutStream *outStream, ISeqInStream *i } -SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, Byte *props, SizeT *size) +SRes LzmaEnc_WriteProperties(CLzmaEncHandle pp, unsigned char *props, size_t *size) { CLzmaEnc *p = (CLzmaEnc *)pp; unsigned i; - UInt32 dictSize = p->dictSize; + uint32_t dictSize = p->dictSize; if (*size < LZMA_PROPS_SIZE) return SZ_ERROR_PARAM; *size = LZMA_PROPS_SIZE; - props[0] = (Byte)((p->pb * 5 + p->lp) * 9 + p->lc); + props[0] = (unsigned char)((p->pb * 5 + p->lp) * 9 + p->lc); - if (dictSize >= ((UInt32)1 << 22)) + if (dictSize >= ((uint32_t)1 << 22)) { - UInt32 kDictMask = ((UInt32)1 << 20) - 1; - if (dictSize < (UInt32)0xFFFFFFFF - kDictMask) + uint32_t kDictMask = ((uint32_t)1 << 20) - 1; + if (dictSize < (uint32_t)0xFFFFFFFF - kDictMask) dictSize = (dictSize + kDictMask) & ~kDictMask; } else for (i = 11; i <= 30; i++) { - if (dictSize <= ((UInt32)2 << i)) { dictSize = (2 << i); break; } - if (dictSize <= ((UInt32)3 << i)) { dictSize = (3 << i); break; } + if (dictSize <= ((uint32_t)2 << i)) { dictSize = (2 << i); break; } + if (dictSize <= ((uint32_t)3 << i)) { dictSize = (3 << i); break; } } for (i = 0; i < 4; i++) - props[1 + i] = (Byte)(dictSize >> (8 * i)); + props[1 + i] = (unsigned char)(dictSize >> (8 * i)); return SZ_OK; } -SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, +SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen, int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig) { SRes res; @@ -2307,7 +2212,7 @@ SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte outStream.funcTable.Write = MyWrite; outStream.data = dest; outStream.rem = *destLen; - outStream.overflow = False; + outStream.overflow = false; p->writeEndMark = writeEndMark; p->rc.outStream = &outStream.funcTable; @@ -2328,8 +2233,8 @@ SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte } -SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, - const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, +SRes LzmaEncode(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen, + const CLzmaEncProps *props, unsigned char *propsEncoded, size_t *propsSize, int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig) { CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc); diff --git a/deps/7zip/LzmaEnc.h b/deps/7zip/LzmaEnc.h index cffe220bbf..95aaf678c2 100644 --- a/deps/7zip/LzmaEnc.h +++ b/deps/7zip/LzmaEnc.h @@ -4,6 +4,8 @@ #ifndef __LZMA_ENC_H #define __LZMA_ENC_H +#include +#include #include "7zTypes.h" EXTERN_C_BEGIN @@ -13,10 +15,10 @@ EXTERN_C_BEGIN typedef struct _CLzmaEncProps { int level; /* 0 <= level <= 9 */ - UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version + uint32_t dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version (1 << 12) <= dictSize <= (1 << 30) for 64-bit version default = (1 << 24) */ - UInt64 reduceSize; /* estimated size of data that will be compressed. default = 0xFFFFFFFF. + uint64_t reduceSize; /* estimated size of data that will be compressed. default = 0xFFFFFFFF. Encoder uses this value to reduce dictionary size */ int lc; /* 0 <= lc <= 8, default = 3 */ int lp; /* 0 <= lp <= 4, default = 0 */ @@ -25,14 +27,14 @@ typedef struct _CLzmaEncProps int fb; /* 5 <= fb <= 273, default = 32 */ int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */ int numHashBytes; /* 2, 3 or 4, default = 4 */ - UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */ + uint32_t mc; /* 1 <= mc <= (1 << 30), default = 32 */ unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */ int numThreads; /* 1 or 2, default = 2 */ } CLzmaEncProps; void LzmaEncProps_Init(CLzmaEncProps *p); void LzmaEncProps_Normalize(CLzmaEncProps *p); -UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2); +uint32_t LzmaEncProps_GetDictSize(const CLzmaEncProps *props2); /* ---------- CLzmaEncHandle Interface ---------- */ @@ -52,10 +54,10 @@ typedef void * CLzmaEncHandle; CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc); void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig); SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props); -SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size); +SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, unsigned char *properties, size_t *size); SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); -SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, +SRes LzmaEnc_MemEncode(CLzmaEncHandle p, unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen, int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); /* ---------- One Call Interface ---------- */ @@ -69,8 +71,8 @@ Return code: SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version) */ -SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen, - const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark, +SRes LzmaEncode(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen, + const CLzmaEncProps *props, unsigned char *propsEncoded, size_t *propsSize, int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig); EXTERN_C_END diff --git a/deps/7zip/Precomp.h b/deps/7zip/Precomp.h deleted file mode 100644 index e8ff8b40e8..0000000000 --- a/deps/7zip/Precomp.h +++ /dev/null @@ -1,10 +0,0 @@ -/* Precomp.h -- StdAfx -2013-11-12 : Igor Pavlov : Public domain */ - -#ifndef __7Z_PRECOMP_H -#define __7Z_PRECOMP_H - -#include "Compiler.h" -/* #include "7zTypes.h" */ - -#endif diff --git a/deps/7zip/Types.h b/deps/7zip/Types.h deleted file mode 100644 index ee60fccb60..0000000000 --- a/deps/7zip/Types.h +++ /dev/null @@ -1,201 +0,0 @@ -/* Types.h -- Basic types - 2010-10-09 : Igor Pavlov : Public domain */ - -#ifndef __7Z_TYPES_H -#define __7Z_TYPES_H - -#include - -#ifdef _WIN32 -#include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -#define SZ_OK 0 - -#define SZ_ERROR_DATA 1 -#define SZ_ERROR_MEM 2 -#define SZ_ERROR_CRC 3 -#define SZ_ERROR_UNSUPPORTED 4 -#define SZ_ERROR_PARAM 5 -#define SZ_ERROR_INPUT_EOF 6 -#define SZ_ERROR_OUTPUT_EOF 7 -#define SZ_ERROR_READ 8 -#define SZ_ERROR_WRITE 9 -#define SZ_ERROR_PROGRESS 10 -#define SZ_ERROR_FAIL 11 -#define SZ_ERROR_THREAD 12 - -#define SZ_ERROR_ARCHIVE 16 -#define SZ_ERROR_NO_ARCHIVE 17 - -typedef int SRes; - -#ifdef _WIN32 -typedef DWORD WRes; -#else -typedef int WRes; -#endif - -#ifndef RINOK -#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; } -#endif - -#ifdef _SZ_NO_INT_64 - -#else - -#if defined(_MSC_VER) || defined(__BORLANDC__) -#define UINT64_CONST(n) n -#else -#define UINT64_CONST(n) n ## ULL -#endif - -#endif - -typedef int Bool; -#define True 1 -#define False 0 - -#ifdef _MSC_VER -#define MY_FAST_CALL __fastcall -#else -#define MY_FAST_CALL -#endif - - -/* The following interfaces use first parameter as pointer to structure */ - -typedef struct -{ - uint8_t (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */ -} IByteIn; - -typedef struct -{ - void (*Write)(void *p, uint8_t b); -} IByteOut; - -typedef struct -{ - SRes (*Read)(void *p, void *buf, size_t *size); - /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. - (output(*size) < input(*size)) is allowed */ -} ISeqInStream; - -/* it can return SZ_ERROR_INPUT_EOF */ -SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size); -SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType); -SRes SeqInStream_ReadByte(ISeqInStream *stream, uint8_t *buf); - -typedef struct -{ - size_t (*Write)(void *p, const void *buf, size_t size); - /* Returns: result - the number of actually written bytes. - (result < size) means error */ -} ISeqOutStream; - -typedef enum -{ - SZ_SEEK_SET = 0, - SZ_SEEK_CUR = 1, - SZ_SEEK_END = 2 -} ESzSeek; - -typedef struct -{ - SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */ - SRes (*Seek)(void *p, int64_t *pos, ESzSeek origin); -} ISeekInStream; - -typedef struct -{ - SRes (*Look)(void *p, const void **buf, size_t *size); - /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. - (output(*size) > input(*size)) is not allowed - (output(*size) < input(*size)) is allowed */ - SRes (*Skip)(void *p, size_t offset); - /* offset must be <= output(*size) of Look */ - - SRes (*Read)(void *p, void *buf, size_t *size); - /* reads directly (without buffer). It's same as ISeqInStream::Read */ - SRes (*Seek)(void *p, int64_t *pos, ESzSeek origin); -} ILookInStream; - -SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size); -SRes LookInStream_SeekTo(ILookInStream *stream, uint64_t offset); - -/* reads via ILookInStream::Read */ -SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType); -SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size); - -#define LookToRead_BUF_SIZE (1 << 14) - -typedef struct -{ - ILookInStream s; - ISeekInStream *realStream; - size_t pos; - size_t size; - uint8_t buf[LookToRead_BUF_SIZE]; -} CLookToRead; - -void LookToRead_CreateVTable(CLookToRead *p, int lookahead); -void LookToRead_Init(CLookToRead *p); - -typedef struct -{ - ISeqInStream s; - ILookInStream *realStream; -} CSecToLook; - -void SecToLook_CreateVTable(CSecToLook *p); - -typedef struct -{ - ISeqInStream s; - ILookInStream *realStream; -} CSecToRead; - -void SecToRead_CreateVTable(CSecToRead *p); - -typedef struct -{ - SRes (*Progress)(void *p, uint64_t inSize, uint64_t outSize); - /* Returns: result. (result != SZ_OK) means break. - Value (uint64_t)(int64_t)-1 for size means unknown value. */ -} ICompressProgress; - -typedef struct -{ - void *(*Alloc)(void *p, size_t size); - void (*Free)(void *p, void *address); /* address can be 0 */ -} ISzAlloc; - -#define IAlloc_Alloc(p, size) (p)->Alloc((p), size) -#define IAlloc_Free(p, a) (p)->Free((p), a) - -#ifdef _WIN32 - -#define CHAR_PATH_SEPARATOR '\\' -#define WCHAR_PATH_SEPARATOR L'\\' -#define STRING_PATH_SEPARATOR "\\" -#define WSTRING_PATH_SEPARATOR L"\\" - -#else - -#define CHAR_PATH_SEPARATOR '/' -#define WCHAR_PATH_SEPARATOR L'/' -#define STRING_PATH_SEPARATOR "/" -#define WSTRING_PATH_SEPARATOR L"/" - -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/libretro-common/file/archive_file_7z.c b/libretro-common/file/archive_file_7z.c index 99f3e66c22..7bfb677fcb 100644 --- a/libretro-common/file/archive_file_7z.c +++ b/libretro-common/file/archive_file_7z.c @@ -22,6 +22,7 @@ #include +#include #include #include #include @@ -139,7 +140,7 @@ static int sevenzip_file_read( return -1; FileInStream_CreateVTable(&archiveStream); - LookToRead_CreateVTable(&lookStream, False); + LookToRead_CreateVTable(&lookStream, false); lookStream.realStream = &archiveStream.s; LookToRead_Init(&lookStream); CrcGenerateTable(); @@ -338,7 +339,7 @@ static int sevenzip_parse_file_init(file_archive_transfer_t *state, goto error; FileInStream_CreateVTable(&sevenzip_context->archiveStream); - LookToRead_CreateVTable(&sevenzip_context->lookStream, False); + LookToRead_CreateVTable(&sevenzip_context->lookStream, false); sevenzip_context->lookStream.realStream = &sevenzip_context->archiveStream.s; LookToRead_Init(&sevenzip_context->lookStream); CrcGenerateTable(); diff --git a/libretro-common/formats/libchdr/chd.c b/libretro-common/formats/libchdr/chd.c index 9423c191c1..5ccc343337 100644 --- a/libretro-common/formats/libchdr/chd.c +++ b/libretro-common/formats/libchdr/chd.c @@ -483,7 +483,7 @@ chd_error lzma_codec_init(void* codec, uint32_t hunkbytes) CLzmaEncHandle enc; Byte decoder_props[LZMA_PROPS_SIZE]; lzma_allocator* alloc; - SizeT props_size; + size_t props_size; lzma_codec_data* lzma_codec = (lzma_codec_data*) codec; /* construct the decoder */ @@ -554,7 +554,7 @@ chd_error lzma_codec_decompress(void* codec, const uint8_t *src, uint32_t comple { ELzmaStatus status; SRes res; - SizeT consumedlen, decodedlen; + size_t consumedlen, decodedlen; /* initialize */ lzma_codec_data* lzma_codec = (lzma_codec_data*) codec; LzmaDec_Init(&lzma_codec->decoder);