diff --git a/ext/VFS/build/7z_VS2005.vcproj b/ext/VFS/build/7z_VS2005.vcproj
index 770de9ea..7ab79db1 100644
--- a/ext/VFS/build/7z_VS2005.vcproj
+++ b/ext/VFS/build/7z_VS2005.vcproj
@@ -595,22 +595,6 @@
RelativePath="..\ext\7z\src\Ppmd7Enc.c"
>
-
-
-
-
-
-
-
-
diff --git a/ext/VFS/build/7z_VS2008.vcproj b/ext/VFS/build/7z_VS2008.vcproj
index 6bbe8d0f..986638a4 100644
--- a/ext/VFS/build/7z_VS2008.vcproj
+++ b/ext/VFS/build/7z_VS2008.vcproj
@@ -1,7 +1,7 @@
-
-
-
-
-
-
-
-
diff --git a/ext/VFS/build/7z_VS2010.vcxproj b/ext/VFS/build/7z_VS2010.vcxproj
index 136c06e3..70b03244 100644
--- a/ext/VFS/build/7z_VS2010.vcxproj
+++ b/ext/VFS/build/7z_VS2010.vcxproj
@@ -46,7 +46,6 @@
-
@@ -85,9 +84,6 @@
-
-
-
diff --git a/ext/VFS/build/7z_VS2010.vcxproj.filters b/ext/VFS/build/7z_VS2010.vcxproj.filters
index d1193e71..7777b4ec 100644
--- a/ext/VFS/build/7z_VS2010.vcxproj.filters
+++ b/ext/VFS/build/7z_VS2010.vcxproj.filters
@@ -24,7 +24,6 @@
-
@@ -63,9 +62,6 @@
-
-
-
diff --git a/ext/VFS/ext/7z/doc/Methods.txt b/ext/VFS/ext/7z/doc/Methods.txt
index 9ed27428..4c3ec68d 100644
--- a/ext/VFS/ext/7z/doc/Methods.txt
+++ b/ext/VFS/ext/7z/doc/Methods.txt
@@ -1,4 +1,4 @@
-7-Zip method IDs (9.04)
+7-Zip method IDs (9.18)
-----------------------
Each compression or crypto method in 7z has unique binary value (ID).
@@ -77,7 +77,13 @@ List of defined IDs
06 - Implode
08 - Deflate
09 - Deflate64
+ 10 - Imploding
12 - BZip2 (not used). Use {04 02 02} instead
+ 14 - LZMA
+ 60 - Jpeg
+ 61 - WavPack
+ 62 - PPMd
+ 63 - wzAES
02 - BZip
02 - BZip2
03 - Rar
diff --git a/ext/VFS/ext/7z/doc/history.txt b/ext/VFS/ext/7z/doc/history.txt
index 3b09fe91..36d01d7d 100644
--- a/ext/VFS/ext/7z/doc/history.txt
+++ b/ext/VFS/ext/7z/doc/history.txt
@@ -1,6 +1,19 @@
HISTORY of the LZMA SDK
-----------------------
+9.21 beta 2011-04-11
+-------------------------
+- New class FString for file names at file systems.
+- Speed optimization in CRC code for big-endian CPUs.
+- The BUG in Lzma2Dec.c was fixed:
+ Lzma2Decode function didn't work.
+
+
+9.18 beta 2010-11-02
+-------------------------
+- New small SFX module for installers (SfxSetup).
+
+
9.12 beta 2010-03-24
-------------------------
- The BUG in LZMA SDK 9.* was fixed: LZMA2 codec didn't work,
diff --git a/ext/VFS/ext/7z/doc/lzma.txt b/ext/VFS/ext/7z/doc/lzma.txt
index a2f3477e..9d3cef00 100644
--- a/ext/VFS/ext/7z/doc/lzma.txt
+++ b/ext/VFS/ext/7z/doc/lzma.txt
@@ -1,4 +1,4 @@
-LZMA SDK 9.12
+LZMA SDK 9.22
-------------
LZMA SDK provides the documentation, samples, header files, libraries,
@@ -20,10 +20,16 @@ LICENSE
LZMA SDK is written and placed in the public domain by Igor Pavlov.
-Some code in LZMA is based on public domain code from another developers:
+Some code in LZMA SDK is based on public domain code from another developers:
1) PPMd var.H (2001): Dmitry Shkarin
2) SHA-256: Wei Dai (Crypto++ library)
+You can copy, modify, distribute and perform LZMA SDK code, even for commercial purposes,
+all without asking permission.
+
+LZMA SDK code is compatible with open source licenses, for example, you can
+include it to GNU GPL or GNU LGPL code.
+
LZMA SDK Contents
-----------------
@@ -37,7 +43,7 @@ LZMA SDK includes:
UNIX/Linux version
------------------
To compile C++ version of file->file LZMA encoding, go to directory
-C++/7zip/Compress/LZMA_Alone
+CPP/7zip/Bundles/LzmaCon
and call make to recompile it:
make -f makefile.gcc clean all
@@ -91,8 +97,6 @@ CPP/ -- CPP files
Compress - files related to compression/decompression
- LZMA_Alone - file->file LZMA compression/decompression
-
Archive - files related to archiving
Common - common files for archive handling
@@ -101,6 +105,7 @@ CPP/ -- CPP files
Bundles - Modules that are bundles of other modules
Alone7z - 7zr.exe: Standalone version of 7z.exe that supports only 7z/LZMA/BCJ/BCJ2
+ LzmaCon - lzma.exe: LZMA compression/decompression
Format7zR - 7zr.dll: Reduced version of 7za.dll: extracting/compressing to 7z/LZMA/BCJ/BCJ2
Format7zExtractR - 7zxr.dll: Reduced version of 7zxa.dll: extracting from 7z/LZMA/BCJ/BCJ2.
diff --git a/ext/VFS/ext/7z/src/7z.h b/ext/VFS/ext/7z/src/7z.h
index e65ab55c..b7edd3ba 100644
--- a/ext/VFS/ext/7z/src/7z.h
+++ b/ext/VFS/ext/7z/src/7z.h
@@ -10,7 +10,7 @@ EXTERN_C_BEGIN
#define k7zStartHeaderSize 0x20
#define k7zSignatureSize 6
-SZIP_API extern Byte k7zSignature[k7zSignatureSize];
+extern Byte k7zSignature[k7zSignatureSize];
#define k7zMajorVersion 0
enum EIdEnum
@@ -76,10 +76,10 @@ typedef struct
} CSzFolder;
void SzFolder_Init(CSzFolder *p);
-SZIP_API UInt64 SzFolder_GetUnpackSize(CSzFolder *p);
+UInt64 SzFolder_GetUnpackSize(CSzFolder *p);
int SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex);
-SZIP_API UInt32 SzFolder_GetNumOutStreams(CSzFolder *p);
-SZIP_API UInt64 SzFolder_GetUnpackSize(CSzFolder *p);
+UInt32 SzFolder_GetNumOutStreams(CSzFolder *p);
+UInt64 SzFolder_GetUnpackSize(CSzFolder *p);
SRes SzFolder_Decode(const CSzFolder *folder, const UInt64 *packSizes,
ILookInStream *stream, UInt64 startPos,
@@ -159,9 +159,9 @@ typedef struct
CBuf FileNames; /* UTF-16-LE */
} CSzArEx;
-SZIP_API void SzArEx_Init(CSzArEx *p);
+void SzArEx_Init(CSzArEx *p);
void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);
-SZIP_API UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);
+UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);
int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize);
/*
@@ -170,7 +170,7 @@ if dest == NULL, the return value specifies the required size of the buffer,
if dest != NULL, the return value specifies the number of 16-bit characters that
are written to the dest, including the null-terminating character. */
-SZIP_API size_t SzArEx_GetFileNameUtf16(const CSzArEx *p, size_t fileIndex, UInt16 *dest);
+size_t SzArEx_GetFileNameUtf16(const CSzArEx *p, size_t fileIndex, UInt16 *dest);
SRes SzArEx_Extract(
const CSzArEx *db,
@@ -196,7 +196,7 @@ SZ_ERROR_INPUT_EOF
SZ_ERROR_FAIL
*/
-SZIP_API SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp);
+SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp);
EXTERN_C_END
diff --git a/ext/VFS/ext/7z/src/7zAlloc.c b/ext/VFS/ext/7z/src/7zAlloc.c
index b5918d00..8874496d 100644
--- a/ext/VFS/ext/7z/src/7zAlloc.c
+++ b/ext/VFS/ext/7z/src/7zAlloc.c
@@ -1,7 +1,6 @@
/* 7zAlloc.c -- Allocation functions
-2008-10-04 : Igor Pavlov : Public domain */
+2010-10-29 : Igor Pavlov : Public domain */
-#include
#include "7zAlloc.h"
/* #define _SZ_ALLOC_DEBUG */
diff --git a/ext/VFS/ext/7z/src/7zAlloc.h b/ext/VFS/ext/7z/src/7zAlloc.h
index b161d90f..860f116a 100644
--- a/ext/VFS/ext/7z/src/7zAlloc.h
+++ b/ext/VFS/ext/7z/src/7zAlloc.h
@@ -1,24 +1,15 @@
/* 7zAlloc.h -- Allocation functions
-2009-02-07 : Igor Pavlov : Public domain */
+2010-10-29 : Igor Pavlov : Public domain */
#ifndef __7Z_ALLOC_H
#define __7Z_ALLOC_H
-#include
-#include "Types.h"
+#include
-#ifdef __cplusplus
-extern "C" {
-#endif
+void *SzAlloc(void *p, size_t size);
+void SzFree(void *p, void *address);
-SZIP_API void *SzAlloc(void *p, size_t size);
-SZIP_API void SzFree(void *p, void *address);
-
-SZIP_API void *SzAllocTemp(void *p, size_t size);
-SZIP_API void SzFreeTemp(void *p, void *address);
-
-#ifdef __cplusplus
-}
-#endif
+void *SzAllocTemp(void *p, size_t size);
+void SzFreeTemp(void *p, void *address);
#endif
diff --git a/ext/VFS/ext/7z/src/7zCrc.c b/ext/VFS/ext/7z/src/7zCrc.c
index 5801dabf..6993a698 100644
--- a/ext/VFS/ext/7z/src/7zCrc.c
+++ b/ext/VFS/ext/7z/src/7zCrc.c
@@ -1,15 +1,24 @@
-/* 7zCrc.c -- CRC32 calculation
-2009-11-23 : Igor Pavlov : Public domain */
+/* 7zCrc.c -- CRC32 init
+2010-12-01 : Igor Pavlov : Public domain */
#include "7zCrc.h"
#include "CpuArch.h"
#define kCrcPoly 0xEDB88320
-#ifdef MY_CPU_LE
-#define CRC_NUM_TABLES 8
+#ifdef MY_CPU_X86_OR_AMD64
+ #define CRC_NUM_TABLES 8
+ UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table);
+#elif defined(MY_CPU_LE)
+ #define CRC_NUM_TABLES 4
#else
-#define CRC_NUM_TABLES 1
+ #define CRC_NUM_TABLES 5
+ #define CRC_UINT32_SWAP(v) ((v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | (v << 24))
+ UInt32 MY_FAST_CALL CrcUpdateT1_BeT4(UInt32 v, const void *data, size_t size, const UInt32 *table);
+#endif
+
+#ifndef MY_CPU_BE
+ UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table);
#endif
typedef UInt32 (MY_FAST_CALL *CRC_FUNC)(UInt32 v, const void *data, size_t size, const UInt32 *table);
@@ -17,25 +26,6 @@ typedef UInt32 (MY_FAST_CALL *CRC_FUNC)(UInt32 v, const void *data, size_t size,
static CRC_FUNC g_CrcUpdate;
UInt32 g_CrcTable[256 * CRC_NUM_TABLES];
-#if CRC_NUM_TABLES == 1
-
-#define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
-
-static UInt32 MY_FAST_CALL CrcUpdateT1(UInt32 v, const void *data, size_t size, const UInt32 *table)
-{
- const Byte *p = (const Byte *)data;
- for (; size > 0; size--, p++)
- v = CRC_UPDATE_BYTE_2(v, *p);
- return v;
-}
-
-#else
-
-UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table);
-UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table);
-
-#endif
-
UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)
{
return g_CrcUpdate(v, data, size, g_CrcTable);
@@ -57,18 +47,37 @@ void MY_FAST_CALL CrcGenerateTable()
r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
g_CrcTable[i] = r;
}
- #if CRC_NUM_TABLES == 1
- g_CrcUpdate = CrcUpdateT1;
- #else
for (; i < 256 * CRC_NUM_TABLES; i++)
{
UInt32 r = g_CrcTable[i - 256];
g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8);
}
+
+ #ifdef MY_CPU_LE
+
g_CrcUpdate = CrcUpdateT4;
- #ifdef MY_CPU_X86_OR_AMD64
+
+ #if CRC_NUM_TABLES == 8
if (!CPU_Is_InOrder())
g_CrcUpdate = CrcUpdateT8;
#endif
+
+ #else
+ {
+ #ifndef MY_CPU_BE
+ UInt32 k = 1;
+ if (*(const Byte *)&k == 1)
+ g_CrcUpdate = CrcUpdateT4;
+ else
+ #endif
+ {
+ for (i = 256 * CRC_NUM_TABLES - 1; i >= 256; i--)
+ {
+ UInt32 x = g_CrcTable[i - 256];
+ g_CrcTable[i] = CRC_UINT32_SWAP(x);
+ }
+ g_CrcUpdate = CrcUpdateT1_BeT4;
+ }
+ }
#endif
}
diff --git a/ext/VFS/ext/7z/src/7zCrc.h b/ext/VFS/ext/7z/src/7zCrc.h
index 0af71ae3..4a1ec38c 100644
--- a/ext/VFS/ext/7z/src/7zCrc.h
+++ b/ext/VFS/ext/7z/src/7zCrc.h
@@ -11,14 +11,14 @@ EXTERN_C_BEGIN
extern UInt32 g_CrcTable[];
/* Call CrcGenerateTable one time before other CRC functions */
-SZIP_API void MY_FAST_CALL CrcGenerateTable(void);
+void MY_FAST_CALL CrcGenerateTable(void);
#define CRC_INIT_VAL 0xFFFFFFFF
#define CRC_GET_DIGEST(crc) ((crc) ^ CRC_INIT_VAL)
#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);
-SZIP_API UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);
+UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);
EXTERN_C_END
diff --git a/ext/VFS/ext/7z/src/7zCrcOpt.c b/ext/VFS/ext/7z/src/7zCrcOpt.c
index 6205d716..85405ccf 100644
--- a/ext/VFS/ext/7z/src/7zCrcOpt.c
+++ b/ext/VFS/ext/7z/src/7zCrcOpt.c
@@ -1,12 +1,12 @@
-/* 7zCrcOpt.c -- CRC32 calculation : optimized version
-2009-11-23 : Igor Pavlov : Public domain */
+/* 7zCrcOpt.c -- CRC32 calculation
+2010-12-01 : Igor Pavlov : Public domain */
#include "CpuArch.h"
-#ifdef MY_CPU_LE
-
#define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
+#ifndef MY_CPU_BE
+
UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table)
{
const Byte *p = (const Byte *)data;
@@ -32,3 +32,33 @@ UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const U
}
#endif
+
+
+#ifndef MY_CPU_LE
+
+#define CRC_UINT32_SWAP(v) ((v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | (v << 24))
+
+UInt32 MY_FAST_CALL CrcUpdateT1_BeT4(UInt32 v, const void *data, size_t size, const UInt32 *table)
+{
+ const Byte *p = (const Byte *)data;
+ for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)
+ v = CRC_UPDATE_BYTE_2(v, *p);
+ v = CRC_UINT32_SWAP(v);
+ table += 0x100;
+ for (; size >= 4; size -= 4, p += 4)
+ {
+ v ^= *(const UInt32 *)p;
+ v =
+ table[0x000 + (v & 0xFF)] ^
+ table[0x100 + ((v >> 8) & 0xFF)] ^
+ table[0x200 + ((v >> 16) & 0xFF)] ^
+ table[0x300 + ((v >> 24))];
+ }
+ table -= 0x100;
+ v = CRC_UINT32_SWAP(v);
+ for (; size > 0; size--, p++)
+ v = CRC_UPDATE_BYTE_2(v, *p);
+ return v;
+}
+
+#endif
diff --git a/ext/VFS/ext/7z/src/7zDec.c b/ext/VFS/ext/7z/src/7zDec.c
index efe8a33b..33868074 100644
--- a/ext/VFS/ext/7z/src/7zDec.c
+++ b/ext/VFS/ext/7z/src/7zDec.c
@@ -1,5 +1,5 @@
/* 7zDec.c -- Decoding from 7z folder
-2010-03-15 : Igor Pavlov : Public domain */
+2010-11-02 : Igor Pavlov : Public domain */
#include
@@ -18,9 +18,13 @@
#define k_Copy 0
#define k_LZMA2 0x21
-#define k_LZMA 0x30101
-#define k_BCJ 0x03030103
-#define k_BCJ2 0x0303011B
+#define k_LZMA 0x30101
+#define k_BCJ 0x03030103
+#define k_PPC 0x03030205
+#define k_ARM 0x03030501
+#define k_ARMT 0x03030701
+#define k_SPARC 0x03030805
+#define k_BCJ2 0x0303011B
#ifdef _7ZIP_PPMD_SUPPPORT
@@ -260,7 +264,6 @@ static Bool IS_SUPPORTED_CODER(const CSzCoderInfo *c)
IS_MAIN_METHOD((UInt32)c->MethodID);
}
-#define IS_BCJ(c) ((c)->MethodID == k_BCJ && (c)->NumInStreams == 1 && (c)->NumOutStreams == 1)
#define IS_BCJ2(c) ((c)->MethodID == k_BCJ2 && (c)->NumInStreams == 4 && (c)->NumOutStreams == 1)
static SRes CheckSupportedFolder(const CSzFolder *f)
@@ -277,11 +280,24 @@ static SRes CheckSupportedFolder(const CSzFolder *f)
}
if (f->NumCoders == 2)
{
- if (!IS_BCJ(&f->Coders[1]) ||
- f->NumPackStreams != 1 || f->PackStreams[0] != 0 ||
+ CSzCoderInfo *c = &f->Coders[1];
+ if (c->MethodID > (UInt32)0xFFFFFFFF ||
+ c->NumInStreams != 1 ||
+ c->NumOutStreams != 1 ||
+ f->NumPackStreams != 1 ||
+ f->PackStreams[0] != 0 ||
f->NumBindPairs != 1 ||
- f->BindPairs[0].InIndex != 1 || f->BindPairs[0].OutIndex != 0)
+ f->BindPairs[0].InIndex != 1 ||
+ f->BindPairs[0].OutIndex != 0)
return SZ_ERROR_UNSUPPORTED;
+ switch ((UInt32)c->MethodID)
+ {
+ case k_BCJ:
+ case k_ARM:
+ break;
+ default:
+ return SZ_ERROR_UNSUPPORTED;
+ }
return SZ_OK;
}
if (f->NumCoders == 4)
@@ -314,6 +330,8 @@ static UInt64 GetSum(const UInt64 *values, UInt32 index)
return sum;
}
+#define CASE_BRA_CONV(isa) case k_ ## isa: isa ## _Convert(outBuffer, outSize, 0, 0); break;
+
static SRes SzFolder_Decode2(const CSzFolder *folder, const UInt64 *packSizes,
ILookInStream *inStream, UInt64 startPos,
Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain,
@@ -391,14 +409,6 @@ static SRes SzFolder_Decode2(const CSzFolder *folder, const UInt64 *packSizes,
#endif
}
}
- else if (coder->MethodID == k_BCJ)
- {
- UInt32 state;
- if (ci != 1)
- return SZ_ERROR_UNSUPPORTED;
- x86_Convert_Init(state);
- x86_Convert(outBuffer, outSize, 0, &state, 0);
- }
else if (coder->MethodID == k_BCJ2)
{
UInt64 offset = GetSum(packSizes, 1);
@@ -425,7 +435,23 @@ static SRes SzFolder_Decode2(const CSzFolder *folder, const UInt64 *packSizes,
RINOK(res)
}
else
- return SZ_ERROR_UNSUPPORTED;
+ {
+ if (ci != 1)
+ return SZ_ERROR_UNSUPPORTED;
+ switch(coder->MethodID)
+ {
+ case k_BCJ:
+ {
+ UInt32 state;
+ x86_Convert_Init(state);
+ x86_Convert(outBuffer, outSize, 0, &state, 0);
+ break;
+ }
+ CASE_BRA_CONV(ARM)
+ default:
+ return SZ_ERROR_UNSUPPORTED;
+ }
+ }
}
return SZ_OK;
}
diff --git a/ext/VFS/ext/7z/src/7zIn.c b/ext/VFS/ext/7z/src/7zIn.c
index a0c83ee4..f1a44928 100644
--- a/ext/VFS/ext/7z/src/7zIn.c
+++ b/ext/VFS/ext/7z/src/7zIn.c
@@ -1,5 +1,5 @@
/* 7zIn.c -- 7z Input functions
-2010-03-11 : Igor Pavlov : Public domain */
+2010-10-29 : Igor Pavlov : Public domain */
#include
@@ -1218,12 +1218,16 @@ static SRes SzArEx_Open2(
ISzAlloc *allocTemp)
{
Byte header[k7zStartHeaderSize];
+ Int64 startArcPos;
UInt64 nextHeaderOffset, nextHeaderSize;
size_t nextHeaderSizeT;
UInt32 nextHeaderCRC;
CBuf buffer;
SRes res;
+ startArcPos = 0;
+ RINOK(inStream->Seek(inStream, &startArcPos, SZ_SEEK_CUR));
+
RINOK(LookInStream_Read2(inStream, header, k7zStartHeaderSize, SZ_ERROR_NO_ARCHIVE));
if (!TestSignatureCandidate(header))
@@ -1235,7 +1239,7 @@ static SRes SzArEx_Open2(
nextHeaderSize = GetUi64(header + 20);
nextHeaderCRC = GetUi32(header + 28);
- p->startPosAfterHeader = k7zStartHeaderSize;
+ p->startPosAfterHeader = startArcPos + k7zStartHeaderSize;
if (CrcCalc(header + 12, 20) != GetUi32(header + 8))
return SZ_ERROR_CRC;
@@ -1252,13 +1256,13 @@ static SRes SzArEx_Open2(
{
Int64 pos = 0;
RINOK(inStream->Seek(inStream, &pos, SZ_SEEK_END));
- if ((UInt64)pos < nextHeaderOffset ||
- (UInt64)pos < k7zStartHeaderSize + nextHeaderOffset ||
- (UInt64)pos < k7zStartHeaderSize + nextHeaderOffset + nextHeaderSize)
+ if ((UInt64)pos < startArcPos + nextHeaderOffset ||
+ (UInt64)pos < startArcPos + k7zStartHeaderSize + nextHeaderOffset ||
+ (UInt64)pos < startArcPos + k7zStartHeaderSize + nextHeaderOffset + nextHeaderSize)
return SZ_ERROR_INPUT_EOF;
}
- RINOK(LookInStream_SeekTo(inStream, k7zStartHeaderSize + nextHeaderOffset));
+ RINOK(LookInStream_SeekTo(inStream, startArcPos + k7zStartHeaderSize + nextHeaderOffset));
if (!Buf_Create(&buffer, nextHeaderSizeT, allocTemp))
return SZ_ERROR_MEM;
diff --git a/ext/VFS/ext/7z/src/7zVersion.h b/ext/VFS/ext/7z/src/7zVersion.h
index e489bb44..43f0fef6 100644
--- a/ext/VFS/ext/7z/src/7zVersion.h
+++ b/ext/VFS/ext/7z/src/7zVersion.h
@@ -1,7 +1,8 @@
#define MY_VER_MAJOR 9
-#define MY_VER_MINOR 12
-#define MY_VER_BUILD 0
-#define MY_VERSION "9.12 beta"
-#define MY_DATE "2010-03-24"
+#define MY_VER_MINOR 22
+#define MY_VER_BUILD 00
+#define MY_VERSION "9.22 beta"
+#define MY_7ZIP_VERSION "9.22 beta"
+#define MY_DATE "2011-04-18"
#define MY_COPYRIGHT ": Igor Pavlov : Public domain"
#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " : " MY_DATE
diff --git a/ext/VFS/ext/7z/src/Bra.c b/ext/VFS/ext/7z/src/Bra.c
index 3b75f0cc..2a0f147b 100644
--- a/ext/VFS/ext/7z/src/Bra.c
+++ b/ext/VFS/ext/7z/src/Bra.c
@@ -1,5 +1,5 @@
/* Bra.c -- Converters for RISC code
-2008-10-04 : Igor Pavlov : Public domain */
+2010-04-16 : Igor Pavlov : Public domain */
#include "Bra.h"
@@ -104,8 +104,8 @@ SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
size -= 4;
for (i = 0; i <= size; i += 4)
{
- if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 ||
- data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)
+ if ((data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00) ||
+ (data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0))
{
UInt32 src =
((UInt32)data[i + 0] << 24) |
diff --git a/ext/VFS/ext/7z/src/CpuArch.c b/ext/VFS/ext/7z/src/CpuArch.c
index c954010c..36e7680d 100644
--- a/ext/VFS/ext/7z/src/CpuArch.c
+++ b/ext/VFS/ext/7z/src/CpuArch.c
@@ -1,5 +1,5 @@
/* CpuArch.c -- CPU specific code
-2009-12-12: Igor Pavlov : Public domain */
+2010-10-26: Igor Pavlov : Public domain */
#include "CpuArch.h"
@@ -71,28 +71,14 @@ static void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
*d = d2;
#else
- #ifdef ORIGINAL_7ZIP
- __asm__ __volatile__ (
- "cpuid"
- : "=a" (*a) ,
- "=b" (*b) ,
- "=c" (*c) ,
- "=d" (*d)
- : "0" (function)) ;
- #else
- //
- // Original code doesn't compile on linux for a shared library build
- // Use proposed fix from the 7-Zip forum on SourceForge
- // http://sourceforge.net/projects/sevenzip/forums/forum/45797/topic/3768042
- //
- __asm__ __volatile__("pushl %%ebx \n\t" /* save %ebx */
- "cpuid \n\t"
- "movl %%ebx, %1 \n\t" /* save what cpuid just put in %ebx */
- "popl %%ebx \n\t" /* restore the old %ebx */
- : "=a"(*a), "=r"(*b), "=c"(*c), "=d"(*d)
- : "a"(function)
- : "cc");
- #endif
+
+ __asm__ __volatile__ (
+ "cpuid"
+ : "=a" (*a) ,
+ "=b" (*b) ,
+ "=c" (*c) ,
+ "=d" (*d)
+ : "0" (function)) ;
#endif
diff --git a/ext/VFS/ext/7z/src/CpuArch.h b/ext/VFS/ext/7z/src/CpuArch.h
index 00e3693c..1cd7c29c 100644
--- a/ext/VFS/ext/7z/src/CpuArch.h
+++ b/ext/VFS/ext/7z/src/CpuArch.h
@@ -1,5 +1,5 @@
/* CpuArch.h -- CPU specific code
-2010-03-11: Igor Pavlov : Public domain */
+2010-12-01: Igor Pavlov : Public domain */
#ifndef __CPU_ARCH_H
#define __CPU_ARCH_H
@@ -40,14 +40,26 @@ If MY_CPU_LE_UNALIGN is not defined, we don't know about these properties of pla
#define MY_CPU_ARM_LE
#endif
+#if defined(_WIN32) && defined(_M_IA64)
+#define MY_CPU_IA64_LE
+#endif
+
#if defined(MY_CPU_X86_OR_AMD64)
#define MY_CPU_LE_UNALIGN
#endif
-#if defined(MY_CPU_X86_OR_AMD64) || defined(MY_CPU_ARM_LE)
+#if defined(MY_CPU_X86_OR_AMD64) || defined(MY_CPU_ARM_LE) || defined(MY_CPU_IA64_LE) || defined(__ARMEL__) || defined(__MIPSEL__) || defined(__LITTLE_ENDIAN__)
#define MY_CPU_LE
#endif
+#if defined(__BIG_ENDIAN__) || defined(__m68k__) || defined(__ARMEB__) || defined(__MIPSEB__)
+#define MY_CPU_BE
+#endif
+
+#if defined(MY_CPU_LE) && defined(MY_CPU_BE)
+Stop_Compiling_Bad_Endian
+#endif
+
#ifdef MY_CPU_LE_UNALIGN
#define GetUi16(p) (*(const UInt16 *)(p))
@@ -55,6 +67,7 @@ If MY_CPU_LE_UNALIGN is not defined, we don't know about these properties of pla
#define GetUi64(p) (*(const UInt64 *)(p))
#define SetUi16(p, d) *(UInt16 *)(p) = (d);
#define SetUi32(p, d) *(UInt32 *)(p) = (d);
+#define SetUi64(p, d) *(UInt64 *)(p) = (d);
#else
@@ -78,6 +91,10 @@ If MY_CPU_LE_UNALIGN is not defined, we don't know about these properties of pla
((Byte *)(p))[2] = (Byte)(_x_ >> 16); \
((Byte *)(p))[3] = (Byte)(_x_ >> 24); }
+#define SetUi64(p, d) { UInt64 _x64_ = (d); \
+ SetUi32(p, (UInt32)_x64_); \
+ SetUi32(((Byte *)(p)) + 4, (UInt32)(_x64_ >> 32)); }
+
#endif
#if defined(MY_CPU_LE_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)
diff --git a/ext/VFS/ext/7z/src/Lzma2Dec.c b/ext/VFS/ext/7z/src/Lzma2Dec.c
index 8f240675..7c4eb444 100644
--- a/ext/VFS/ext/7z/src/Lzma2Dec.c
+++ b/ext/VFS/ext/7z/src/Lzma2Dec.c
@@ -1,5 +1,5 @@
/* Lzma2Dec.c -- LZMA2 Decoder
-2009-05-03 : Igor Pavlov : Public domain */
+2010-12-15 : Igor Pavlov : Public domain */
/* #define SHOW_DEBUG_INFO */
@@ -330,27 +330,21 @@ SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen, const Byte *
SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc)
{
- CLzma2Dec decoder;
+ CLzma2Dec p;
SRes res;
SizeT outSize = *destLen, inSize = *srcLen;
- Byte props[LZMA_PROPS_SIZE];
-
- Lzma2Dec_Construct(&decoder);
-
*destLen = *srcLen = 0;
*status = LZMA_STATUS_NOT_SPECIFIED;
- decoder.decoder.dic = dest;
- decoder.decoder.dicBufSize = outSize;
-
- RINOK(Lzma2Dec_GetOldProps(prop, props));
- RINOK(LzmaDec_AllocateProbs(&decoder.decoder, props, LZMA_PROPS_SIZE, alloc));
-
+ Lzma2Dec_Construct(&p);
+ RINOK(Lzma2Dec_AllocateProbs(&p, prop, alloc));
+ p.decoder.dic = dest;
+ p.decoder.dicBufSize = outSize;
+ Lzma2Dec_Init(&p);
*srcLen = inSize;
- res = Lzma2Dec_DecodeToDic(&decoder, outSize, src, srcLen, finishMode, status);
- *destLen = decoder.decoder.dicPos;
+ res = Lzma2Dec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);
+ *destLen = p.decoder.dicPos;
if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
res = SZ_ERROR_INPUT_EOF;
-
- LzmaDec_FreeProbs(&decoder.decoder, alloc);
+ Lzma2Dec_FreeProbs(&p, alloc);
return res;
}
diff --git a/ext/VFS/ext/7z/src/Lzma2Enc.c b/ext/VFS/ext/7z/src/Lzma2Enc.c
index 6f2e280b..35f6ed7c 100644
--- a/ext/VFS/ext/7z/src/Lzma2Enc.c
+++ b/ext/VFS/ext/7z/src/Lzma2Enc.c
@@ -1,5 +1,5 @@
/* Lzma2Enc.c -- LZMA2 Encoder
-2010-03-24 : Igor Pavlov : Public domain */
+2010-09-24 : Igor Pavlov : Public domain */
/* #include */
#include
@@ -141,7 +141,7 @@ static SRes Lzma2EncInt_EncodeSubblock(CLzma2EncInt *p, Byte *outBuf,
PRF(printf(" "));
- outBuf[destPos++] = (Byte)(LZMA2_CONTROL_LZMA | (mode << 5) | (u >> 16) & 0x1F);
+ outBuf[destPos++] = (Byte)(LZMA2_CONTROL_LZMA | (mode << 5) | ((u >> 16) & 0x1F));
outBuf[destPos++] = (Byte)(u >> 8);
outBuf[destPos++] = (Byte)u;
outBuf[destPos++] = (Byte)(pm >> 8);
@@ -240,9 +240,7 @@ static SRes Progress(ICompressProgress *p, UInt64 inSize, UInt64 outSize)
/* ---------- Lzma2 ---------- */
-extern struct _CLzma2Enc;
-
-typedef struct _CLzma2Enc
+typedef struct
{
Byte propEncoded;
CLzma2EncProps props;
@@ -271,7 +269,7 @@ static SRes Lzma2Enc_EncodeMt1(CLzma2EncInt *p, CLzma2Enc *mainEncoder,
if (mainEncoder->outBuf == 0)
{
- mainEncoder->outBuf = IAlloc_Alloc(mainEncoder->alloc, LZMA2_CHUNK_SIZE_COMPRESSED_MAX);
+ mainEncoder->outBuf = (Byte *)IAlloc_Alloc(mainEncoder->alloc, LZMA2_CHUNK_SIZE_COMPRESSED_MAX);
if (mainEncoder->outBuf == 0)
return SZ_ERROR_MEM;
}
diff --git a/ext/VFS/ext/7z/src/LzmaDec.c b/ext/VFS/ext/7z/src/LzmaDec.c
index 4fdc11d4..72451d1f 100644
--- a/ext/VFS/ext/7z/src/LzmaDec.c
+++ b/ext/VFS/ext/7z/src/LzmaDec.c
@@ -1,5 +1,5 @@
/* LzmaDec.c -- LZMA Decoder
-2009-09-20 : Igor Pavlov : Public domain */
+2010-12-15 : Igor Pavlov : Public domain */
#include "LzmaDec.h"
@@ -442,8 +442,9 @@ static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
p->processedPos += len;
p->remainLen -= len;
- while (len-- != 0)
+ while (len != 0)
{
+ len--;
dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
dicPos++;
}
@@ -972,28 +973,21 @@ SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
{
CLzmaDec p;
SRes res;
- SizeT inSize = *srcLen;
- SizeT outSize = *destLen;
- *srcLen = *destLen = 0;
+ SizeT outSize = *destLen, inSize = *srcLen;
+ *destLen = *srcLen = 0;
+ *status = LZMA_STATUS_NOT_SPECIFIED;
if (inSize < RC_INIT_SIZE)
return SZ_ERROR_INPUT_EOF;
-
LzmaDec_Construct(&p);
- res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);
- if (res != 0)
- return res;
+ RINOK(LzmaDec_AllocateProbs(&p, propData, propSize, alloc));
p.dic = dest;
p.dicBufSize = outSize;
-
LzmaDec_Init(&p);
-
*srcLen = inSize;
res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);
-
+ *destLen = p.dicPos;
if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
res = SZ_ERROR_INPUT_EOF;
-
- (*destLen) = p.dicPos;
LzmaDec_FreeProbs(&p, alloc);
return res;
}
diff --git a/ext/VFS/ext/7z/src/LzmaEnc.c b/ext/VFS/ext/7z/src/LzmaEnc.c
index 1f5dcb58..da39520c 100644
--- a/ext/VFS/ext/7z/src/LzmaEnc.c
+++ b/ext/VFS/ext/7z/src/LzmaEnc.c
@@ -1,5 +1,5 @@
/* LzmaEnc.c -- LZMA Encoder
-2009-11-24 : Igor Pavlov : Public domain */
+2011-01-27 : Igor Pavlov : Public domain */
#include
@@ -46,6 +46,7 @@ void LzmaEncProps_Init(CLzmaEncProps *p)
{
p->level = 5;
p->dictSize = p->mc = 0;
+ p->reduceSize = (UInt32)(Int32)-1;
p->lc = p->lp = p->pb = p->algo = p->fb = p->btMode = p->numHashBytes = p->numThreads = -1;
p->writeEndMark = 0;
}
@@ -56,6 +57,15 @@ void LzmaEncProps_Normalize(CLzmaEncProps *p)
if (level < 0) level = 5;
p->level = level;
if (p->dictSize == 0) p->dictSize = (level <= 5 ? (1 << (level * 2 + 14)) : (level == 6 ? (1 << 25) : (1 << 26)));
+ if (p->dictSize > p->reduceSize)
+ {
+ unsigned i;
+ for (i = 15; i <= 30; i++)
+ {
+ if (p->reduceSize <= ((UInt32)2 << i)) { p->dictSize = ((UInt32)2 << i); break; }
+ if (p->reduceSize <= ((UInt32)3 << i)) { p->dictSize = ((UInt32)3 << i); break; }
+ }
+ }
if (p->lc < 0) p->lc = 3;
if (p->lp < 0) p->lp = 0;
if (p->pb < 0) p->pb = 2;
@@ -329,7 +339,6 @@ typedef struct
SRes result;
UInt32 dictSize;
- UInt32 matchFinderCycles;
int needInit;
@@ -395,10 +404,9 @@ SRes LzmaEnc_SetProps(CLzmaEncHandle pp, const CLzmaEncProps *props2)
LzmaEncProps_Normalize(&props);
if (props.lc > LZMA_LC_MAX || props.lp > LZMA_LP_MAX || props.pb > LZMA_PB_MAX ||
- props.dictSize > (1 << kDicLogSizeMaxCompress) || props.dictSize > (1 << 30))
+ props.dictSize > ((UInt32)1 << kDicLogSizeMaxCompress) || props.dictSize > ((UInt32)1 << 30))
return SZ_ERROR_PARAM;
p->dictSize = props.dictSize;
- p->matchFinderCycles = props.mc;
{
unsigned fb = props.fb;
if (fb < 5)
diff --git a/ext/VFS/ext/7z/src/LzmaEnc.h b/ext/VFS/ext/7z/src/LzmaEnc.h
index 999f5aff..7573ba01 100644
--- a/ext/VFS/ext/7z/src/LzmaEnc.h
+++ b/ext/VFS/ext/7z/src/LzmaEnc.h
@@ -1,14 +1,12 @@
/* LzmaEnc.h -- LZMA Encoder
-2009-02-07 : Igor Pavlov : Public domain */
+2011-01-27 : Igor Pavlov : Public domain */
#ifndef __LZMA_ENC_H
#define __LZMA_ENC_H
#include "Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+EXTERN_C_BEGIN
#define LZMA_PROPS_SIZE 5
@@ -18,6 +16,8 @@ typedef struct _CLzmaEncProps
UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
(1 << 12) <= dictSize <= (1 << 30) for 64-bit version
default = (1 << 24) */
+ UInt32 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 */
int pb; /* 0 <= pb <= 4, default = 2 */
@@ -73,8 +73,6 @@ SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
-#ifdef __cplusplus
-}
-#endif
+EXTERN_C_END
#endif
diff --git a/ext/VFS/ext/7z/src/MtCoder.c b/ext/VFS/ext/7z/src/MtCoder.c
index 16165919..9f0d268c 100644
--- a/ext/VFS/ext/7z/src/MtCoder.c
+++ b/ext/VFS/ext/7z/src/MtCoder.c
@@ -1,5 +1,5 @@
/* MtCoder.c -- Multi-thread Coder
-2010-03-24 : Igor Pavlov : Public domain */
+2010-09-24 : Igor Pavlov : Public domain */
#include
@@ -148,7 +148,7 @@ static void CMtThread_Destruct(CMtThread *p)
#define MY_BUF_ALLOC(buf, size, newSize) \
if (buf == 0 || size != newSize) \
{ IAlloc_Free(p->mtCoder->alloc, buf); \
- size = newSize; buf = IAlloc_Alloc(p->mtCoder->alloc, size); \
+ size = newSize; buf = (Byte *)IAlloc_Alloc(p->mtCoder->alloc, size); \
if (buf == 0) return SZ_ERROR_MEM; }
static SRes CMtThread_Prepare(CMtThread *p)
diff --git a/ext/VFS/ext/7z/src/Ppmd.h b/ext/VFS/ext/7z/src/Ppmd.h
index 14344a71..d62df4d3 100644
--- a/ext/VFS/ext/7z/src/Ppmd.h
+++ b/ext/VFS/ext/7z/src/Ppmd.h
@@ -1,5 +1,5 @@
/* Ppmd.h -- PPMD codec common code
-2010-03-12 : Igor Pavlov : Public domain
+2011-01-27 : Igor Pavlov : Public domain
This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
#ifndef __PPMD_H
@@ -29,6 +29,9 @@ EXTERN_C_BEGIN
#define PPMD_N4 ((128 + 3 - 1 * PPMD_N1 - 2 * PPMD_N2 - 3 * PPMD_N3) / 4)
#define PPMD_NUM_INDEXES (PPMD_N1 + PPMD_N2 + PPMD_N3 + PPMD_N4)
+#pragma pack(push, 1)
+/* Most compilers works OK here even without #pragma pack(push, 1), but some GCC compilers need it. */
+
/* SEE-contexts for PPM-contexts with masked symbols */
typedef struct
{
@@ -48,6 +51,8 @@ typedef struct
UInt16 SuccessorHigh;
} CPpmd_State;
+#pragma pack(pop)
+
typedef
#ifdef PPMD_32BIT
CPpmd_State *
diff --git a/ext/VFS/ext/7z/src/Ppmd8.c b/ext/VFS/ext/7z/src/Ppmd8.c
deleted file mode 100644
index 4fe723fe..00000000
--- a/ext/VFS/ext/7z/src/Ppmd8.c
+++ /dev/null
@@ -1,1120 +0,0 @@
-/* Ppmd8.c -- PPMdI codec
-2010-03-24 : Igor Pavlov : Public domain
-This code is based on PPMd var.I (2002): Dmitry Shkarin : Public domain */
-
-#include
-
-#include "Ppmd8.h"
-
-const Byte PPMD8_kExpEscape[16] = { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 };
-static const UInt16 kInitBinEsc[] = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051};
-
-#define MAX_FREQ 124
-#define UNIT_SIZE 12
-
-#define U2B(nu) ((UInt32)(nu) * UNIT_SIZE)
-#define U2I(nu) (p->Units2Indx[(nu) - 1])
-#define I2U(indx) (p->Indx2Units[indx])
-
-#ifdef PPMD_32BIT
- #define REF(ptr) (ptr)
-#else
- #define REF(ptr) ((UInt32)((Byte *)(ptr) - (p)->Base))
-#endif
-
-#define STATS_REF(ptr) ((CPpmd_State_Ref)REF(ptr))
-
-#define CTX(ref) ((CPpmd8_Context *)Ppmd8_GetContext(p, ref))
-#define STATS(ctx) Ppmd8_GetStats(p, ctx)
-#define ONE_STATE(ctx) Ppmd8Context_OneState(ctx)
-#define SUFFIX(ctx) CTX((ctx)->Suffix)
-
-typedef CPpmd8_Context * CTX_PTR;
-
-struct CPpmd8_Node_;
-
-typedef
- #ifdef PPMD_32BIT
- struct CPpmd8_Node_ *
- #else
- UInt32
- #endif
- CPpmd8_Node_Ref;
-
-typedef struct CPpmd8_Node_
-{
- UInt32 Stamp;
- CPpmd8_Node_Ref Next;
- UInt32 NU;
-} CPpmd8_Node;
-
-#ifdef PPMD_32BIT
- #define NODE(ptr) (ptr)
-#else
- #define NODE(offs) ((CPpmd8_Node *)(p->Base + (offs)))
-#endif
-
-#define EMPTY_NODE 0xFFFFFFFF
-
-void Ppmd8_Construct(CPpmd8 *p)
-{
- unsigned i, k, m;
-
- p->Base = 0;
-
- for (i = 0, k = 0; i < PPMD_NUM_INDEXES; i++)
- {
- unsigned step = (i >= 12 ? 4 : (i >> 2) + 1);
- do { p->Units2Indx[k++] = (Byte)i; } while(--step);
- p->Indx2Units[i] = (Byte)k;
- }
-
- p->NS2BSIndx[0] = (0 << 1);
- p->NS2BSIndx[1] = (1 << 1);
- memset(p->NS2BSIndx + 2, (2 << 1), 9);
- memset(p->NS2BSIndx + 11, (3 << 1), 256 - 11);
-
- for (i = 0; i < 5; i++)
- p->NS2Indx[i] = (Byte)i;
- for (m = i, k = 1; i < 260; i++)
- {
- p->NS2Indx[i] = (Byte)m;
- if (--k == 0)
- k = (++m) - 4;
- }
-}
-
-void Ppmd8_Free(CPpmd8 *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->Base);
- p->Size = 0;
- p->Base = 0;
-}
-
-Bool Ppmd8_Alloc(CPpmd8 *p, UInt32 size, ISzAlloc *alloc)
-{
- if (p->Base == 0 || p->Size != size)
- {
- Ppmd8_Free(p, alloc);
- p->AlignOffset =
- #ifdef PPMD_32BIT
- (4 - size) & 3;
- #else
- 4 - (size & 3);
- #endif
- if ((p->Base = (Byte *)alloc->Alloc(alloc, p->AlignOffset + size)) == 0)
- return False;
- p->Size = size;
- }
- return True;
-}
-
-static void InsertNode(CPpmd8 *p, void *node, unsigned indx)
-{
- ((CPpmd8_Node *)node)->Stamp = EMPTY_NODE;
- ((CPpmd8_Node *)node)->Next = (CPpmd8_Node_Ref)p->FreeList[indx];
- ((CPpmd8_Node *)node)->NU = I2U(indx);
- p->FreeList[indx] = REF(node);
- p->Stamps[indx]++;
-}
-
-static void *RemoveNode(CPpmd8 *p, unsigned indx)
-{
- CPpmd8_Node *node = NODE((CPpmd8_Node_Ref)p->FreeList[indx]);
- p->FreeList[indx] = node->Next;
- p->Stamps[indx]--;
- return node;
-}
-
-static void SplitBlock(CPpmd8 *p, void *ptr, unsigned oldIndx, unsigned newIndx)
-{
- unsigned i, nu = I2U(oldIndx) - I2U(newIndx);
- ptr = (Byte *)ptr + U2B(I2U(newIndx));
- if (I2U(i = U2I(nu)) != nu)
- {
- unsigned k = I2U(--i);
- InsertNode(p, ((Byte *)ptr) + U2B(k), nu - k - 1);
- }
- InsertNode(p, ptr, i);
-}
-
-static void GlueFreeBlocks(CPpmd8 *p)
-{
- CPpmd8_Node_Ref head = 0;
- CPpmd8_Node_Ref *prev = &head;
- unsigned i;
-
- p->GlueCount = 1 << 13;
- memset(p->Stamps, 0, sizeof(p->Stamps));
-
- /* Order-0 context is always at top UNIT, so we don't need guard NODE at the end.
- All blocks up to p->LoUnit can be free, so we need guard NODE at LoUnit. */
- if (p->LoUnit != p->HiUnit)
- ((CPpmd8_Node *)p->LoUnit)->Stamp = 0;
-
- /* Glue free blocks */
- for (i = 0; i < PPMD_NUM_INDEXES; i++)
- {
- CPpmd8_Node_Ref next = (CPpmd8_Node_Ref)p->FreeList[i];
- p->FreeList[i] = 0;
- while (next != 0)
- {
- CPpmd8_Node *node = NODE(next);
- if (node->NU != 0)
- {
- CPpmd8_Node *node2;
- *prev = next;
- prev = &(node->Next);
- while ((node2 = node + node->NU)->Stamp == EMPTY_NODE)
- {
- node->NU += node2->NU;
- node2->NU = 0;
- }
- }
- next = node->Next;
- }
- }
- *prev = 0;
-
- /* Fill lists of free blocks */
- while (head != 0)
- {
- CPpmd8_Node *node = NODE(head);
- unsigned nu;
- head = node->Next;
- nu = node->NU;
- if (nu == 0)
- continue;
- for (; nu > 128; nu -= 128, node += 128)
- InsertNode(p, node, PPMD_NUM_INDEXES - 1);
- if (I2U(i = U2I(nu)) != nu)
- {
- unsigned k = I2U(--i);
- InsertNode(p, node + k, nu - k - 1);
- }
- InsertNode(p, node, i);
- }
-}
-
-static void *AllocUnitsRare(CPpmd8 *p, unsigned indx)
-{
- unsigned i;
- void *retVal;
- if (p->GlueCount == 0)
- {
- GlueFreeBlocks(p);
- if (p->FreeList[indx] != 0)
- return RemoveNode(p, indx);
- }
- i = indx;
- do
- {
- if (++i == PPMD_NUM_INDEXES)
- {
- UInt32 numBytes = U2B(I2U(indx));
- p->GlueCount--;
- return ((UInt32)(p->UnitsStart - p->Text) > numBytes) ? (p->UnitsStart -= numBytes) : (NULL);
- }
- }
- while (p->FreeList[i] == 0);
- retVal = RemoveNode(p, i);
- SplitBlock(p, retVal, i, indx);
- return retVal;
-}
-
-static void *AllocUnits(CPpmd8 *p, unsigned indx)
-{
- UInt32 numBytes;
- if (p->FreeList[indx] != 0)
- return RemoveNode(p, indx);
- numBytes = U2B(I2U(indx));
- if (numBytes <= (UInt32)(p->HiUnit - p->LoUnit))
- {
- void *retVal = p->LoUnit;
- p->LoUnit += numBytes;
- return retVal;
- }
- return AllocUnitsRare(p, indx);
-}
-
-#define MyMem12Cpy(dest, src, num) \
- { UInt32 *d = (UInt32 *)dest; const UInt32 *s = (const UInt32 *)src; UInt32 n = num; \
- do { d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; s += 3; d += 3; } while(--n); }
-
-static void *ShrinkUnits(CPpmd8 *p, void *oldPtr, unsigned oldNU, unsigned newNU)
-{
- unsigned i0 = U2I(oldNU);
- unsigned i1 = U2I(newNU);
- if (i0 == i1)
- return oldPtr;
- if (p->FreeList[i1] != 0)
- {
- void *ptr = RemoveNode(p, i1);
- MyMem12Cpy(ptr, oldPtr, newNU);
- InsertNode(p, oldPtr, i0);
- return ptr;
- }
- SplitBlock(p, oldPtr, i0, i1);
- return oldPtr;
-}
-
-static void FreeUnits(CPpmd8 *p, void *ptr, unsigned nu)
-{
- InsertNode(p, ptr, U2I(nu));
-}
-
-static void SpecialFreeUnit(CPpmd8 *p, void *ptr)
-{
- if ((Byte *)ptr != p->UnitsStart)
- InsertNode(p, ptr, 0);
- else
- {
- #ifdef PPMD8_FREEZE_SUPPORT
- *(UInt32 *)ptr = EMPTY_NODE; /* it's used for (Flags == 0xFF) check in RemoveBinContexts */
- #endif
- p->UnitsStart += UNIT_SIZE;
- }
-}
-
-static void *MoveUnitsUp(CPpmd8 *p, void *oldPtr, unsigned nu)
-{
- unsigned indx = U2I(nu);
- void *ptr;
- if ((Byte *)oldPtr > p->UnitsStart + 16 * 1024 || REF(oldPtr) > p->FreeList[indx])
- return oldPtr;
- ptr = RemoveNode(p, indx);
- MyMem12Cpy(ptr, oldPtr, nu);
- if ((Byte*)oldPtr != p->UnitsStart)
- InsertNode(p, oldPtr, indx);
- else
- p->UnitsStart += U2B(I2U(indx));
- return ptr;
-}
-
-static void ExpandTextArea(CPpmd8 *p)
-{
- UInt32 count[PPMD_NUM_INDEXES];
- unsigned i;
- memset(count, 0, sizeof(count));
- if (p->LoUnit != p->HiUnit)
- ((CPpmd8_Node *)p->LoUnit)->Stamp = 0;
-
- {
- CPpmd8_Node *node = (CPpmd8_Node *)p->UnitsStart;
- for (; node->Stamp == EMPTY_NODE; node += node->NU)
- {
- node->Stamp = 0;
- count[U2I(node->NU)]++;
- }
- p->UnitsStart = (Byte *)node;
- }
-
- for (i = 0; i < PPMD_NUM_INDEXES; i++)
- {
- CPpmd8_Node_Ref *next = (CPpmd8_Node_Ref *)&p->FreeList[i];
- while (count[i] != 0)
- {
- CPpmd8_Node *node = NODE(*next);
- while (node->Stamp == 0)
- {
- *next = node->Next;
- node = NODE(*next);
- p->Stamps[i]--;
- if (--count[i] == 0)
- break;
- }
- next = &node->Next;
- }
- }
-}
-
-#define SUCCESSOR(p) ((CPpmd_Void_Ref)((p)->SuccessorLow | ((UInt32)(p)->SuccessorHigh << 16)))
-
-static void SetSuccessor(CPpmd_State *p, CPpmd_Void_Ref v)
-{
- (p)->SuccessorLow = (UInt16)((UInt32)(v) & 0xFFFF);
- (p)->SuccessorHigh = (UInt16)(((UInt32)(v) >> 16) & 0xFFFF);
-}
-
-#define RESET_TEXT(offs) { p->Text = p->Base + p->AlignOffset + (offs); }
-
-static void RestartModel(CPpmd8 *p)
-{
- unsigned i, k, m, r;
-
- memset(p->FreeList, 0, sizeof(p->FreeList));
- memset(p->Stamps, 0, sizeof(p->Stamps));
- RESET_TEXT(0);
- p->HiUnit = p->Text + p->Size;
- p->LoUnit = p->UnitsStart = p->HiUnit - p->Size / 8 / UNIT_SIZE * 7 * UNIT_SIZE;
- p->GlueCount = 0;
-
- p->OrderFall = p->MaxOrder;
- p->RunLength = p->InitRL = -(Int32)((p->MaxOrder < 12) ? p->MaxOrder : 12) - 1;
- p->PrevSuccess = 0;
-
- p->MinContext = p->MaxContext = (CTX_PTR)(p->HiUnit -= UNIT_SIZE); /* AllocContext(p); */
- p->MinContext->Suffix = 0;
- p->MinContext->NumStats = 255;
- p->MinContext->Flags = 0;
- p->MinContext->SummFreq = 256 + 1;
- p->FoundState = (CPpmd_State *)p->LoUnit; /* AllocUnits(p, PPMD_NUM_INDEXES - 1); */
- p->LoUnit += U2B(256 / 2);
- p->MinContext->Stats = REF(p->FoundState);
- for (i = 0; i < 256; i++)
- {
- CPpmd_State *s = &p->FoundState[i];
- s->Symbol = (Byte)i;
- s->Freq = 1;
- SetSuccessor(s, 0);
- }
-
- for (i = m = 0; m < 25; m++)
- {
- while (p->NS2Indx[i] == m)
- i++;
- for (k = 0; k < 8; k++)
- {
- UInt16 val = (UInt16)(PPMD_BIN_SCALE - kInitBinEsc[k] / (i + 1));
- UInt16 *dest = p->BinSumm[m] + k;
- for (r = 0; r < 64; r += 8)
- dest[r] = val;
- }
- }
-
- for (i = m = 0; m < 24; m++)
- {
- while (p->NS2Indx[i + 3] == m + 3)
- i++;
- for (k = 0; k < 32; k++)
- {
- CPpmd_See *s = &p->See[m][k];
- s->Summ = (UInt16)((2 * i + 5) << (s->Shift = PPMD_PERIOD_BITS - 4));
- s->Count = 7;
- }
- }
-}
-
-void Ppmd8_Init(CPpmd8 *p, unsigned maxOrder, unsigned restoreMethod)
-{
- p->MaxOrder = maxOrder;
- p->RestoreMethod = restoreMethod;
- RestartModel(p);
- p->DummySee.Shift = PPMD_PERIOD_BITS;
- p->DummySee.Summ = 0; /* unused */
- p->DummySee.Count = 64; /* unused */
-}
-
-static void Refresh(CPpmd8 *p, CTX_PTR ctx, unsigned oldNU, unsigned scale)
-{
- unsigned i = ctx->NumStats, escFreq, sumFreq, flags;
- CPpmd_State *s = (CPpmd_State *)ShrinkUnits(p, STATS(ctx), oldNU, (i + 2) >> 1);
- ctx->Stats = REF(s);
- #ifdef PPMD8_FREEZE_SUPPORT
- /* fixed over Shkarin's code. Fixed code is not compatible with original code for some files in FREEZE mode. */
- scale |= (ctx->SummFreq >= ((UInt32)1 << 15));
- #endif
- flags = (ctx->Flags & (0x10 + 0x04 * scale)) + 0x08 * (s->Symbol >= 0x40);
- escFreq = ctx->SummFreq - s->Freq;
- sumFreq = (s->Freq = (Byte)((s->Freq + scale) >> scale));
- do
- {
- escFreq -= (++s)->Freq;
- sumFreq += (s->Freq = (Byte)((s->Freq + scale) >> scale));
- flags |= 0x08 * (s->Symbol >= 0x40);
- }
- while (--i);
- ctx->SummFreq = (UInt16)(sumFreq + ((escFreq + scale) >> scale));
- ctx->Flags = (Byte)flags;
-}
-
-static void SwapStates(CPpmd_State *t1, CPpmd_State *t2)
-{
- CPpmd_State tmp = *t1;
- *t1 = *t2;
- *t2 = tmp;
-}
-
-static CPpmd_Void_Ref CutOff(CPpmd8 *p, CTX_PTR ctx, unsigned order)
-{
- int i;
- unsigned tmp;
- CPpmd_State *s;
-
- if (!ctx->NumStats)
- {
- s = ONE_STATE(ctx);
- if ((Byte *)Ppmd8_GetPtr(p, SUCCESSOR(s)) >= p->UnitsStart)
- {
- if (order < p->MaxOrder)
- SetSuccessor(s, CutOff(p, CTX(SUCCESSOR(s)), order + 1));
- else
- SetSuccessor(s, 0);
- if (SUCCESSOR(s) || order <= 9) /* O_BOUND */
- return REF(ctx);
- }
- SpecialFreeUnit(p, ctx);
- return 0;
- }
-
- ctx->Stats = STATS_REF(MoveUnitsUp(p, STATS(ctx), tmp = ((unsigned)ctx->NumStats + 2) >> 1));
-
- for (s = STATS(ctx) + (i = ctx->NumStats); s >= STATS(ctx); s--)
- if ((Byte *)Ppmd8_GetPtr(p, SUCCESSOR(s)) < p->UnitsStart)
- {
- CPpmd_State *s2 = STATS(ctx) + (i--);
- SetSuccessor(s, 0);
- SwapStates(s, s2);
- }
- else if (order < p->MaxOrder)
- SetSuccessor(s, CutOff(p, CTX(SUCCESSOR(s)), order + 1));
- else
- SetSuccessor(s, 0);
-
- if (i != ctx->NumStats && order)
- {
- ctx->NumStats = (Byte)i;
- s = STATS(ctx);
- if (i < 0)
- {
- FreeUnits(p, s, tmp);
- SpecialFreeUnit(p, ctx);
- return 0;
- }
- if (i == 0)
- {
- ctx->Flags = (ctx->Flags & 0x10) + 0x08 * (s->Symbol >= 0x40);
- *ONE_STATE(ctx) = *s;
- FreeUnits(p, s, tmp);
- ONE_STATE(ctx)->Freq = (Byte)((unsigned)ONE_STATE(ctx)->Freq + 11) >> 3;
- }
- else
- Refresh(p, ctx, tmp, ctx->SummFreq > 16 * i);
- }
- return REF(ctx);
-}
-
-#ifdef PPMD8_FREEZE_SUPPORT
-static CPpmd_Void_Ref RemoveBinContexts(CPpmd8 *p, CTX_PTR ctx, unsigned order)
-{
- CPpmd_State *s;
- if (!ctx->NumStats)
- {
- s = ONE_STATE(ctx);
- if ((Byte *)Ppmd8_GetPtr(p, SUCCESSOR(s)) >= p->UnitsStart && order < p->MaxOrder)
- SetSuccessor(s, RemoveBinContexts(p, CTX(SUCCESSOR(s)), order + 1));
- else
- SetSuccessor(s, 0);
- /* Suffix context can be removed already, since different (high-order)
- Successors may refer to same context. So we check Flags == 0xFF (Stamp == EMPTY_NODE) */
- if (!SUCCESSOR(s) && (!SUFFIX(ctx)->NumStats || SUFFIX(ctx)->Flags == 0xFF))
- {
- FreeUnits(p, ctx, 1);
- return 0;
- }
- else
- return REF(ctx);
- }
-
- for (s = STATS(ctx) + ctx->NumStats; s >= STATS(ctx); s--)
- if ((Byte *)Ppmd8_GetPtr(p, SUCCESSOR(s)) >= p->UnitsStart && order < p->MaxOrder)
- SetSuccessor(s, RemoveBinContexts(p, CTX(SUCCESSOR(s)), order + 1));
- else
- SetSuccessor(s, 0);
-
- return REF(ctx);
-}
-#endif
-
-static UInt32 GetUsedMemory(const CPpmd8 *p)
-{
- UInt32 v = 0;
- unsigned i;
- for (i = 0; i < PPMD_NUM_INDEXES; i++)
- v += p->Stamps[i] * I2U(i);
- return p->Size - (UInt32)(p->HiUnit - p->LoUnit) - (UInt32)(p->UnitsStart - p->Text) - U2B(v);
-}
-
-#ifdef PPMD8_FREEZE_SUPPORT
- #define RESTORE_MODEL(c1, fSuccessor) RestoreModel(p, c1, fSuccessor)
-#else
- #define RESTORE_MODEL(c1, fSuccessor) RestoreModel(p, c1)
-#endif
-
-static void RestoreModel(CPpmd8 *p, CTX_PTR c1
- #ifdef PPMD8_FREEZE_SUPPORT
- , CTX_PTR fSuccessor
- #endif
- )
-{
- CTX_PTR c;
- CPpmd_State *s;
- RESET_TEXT(0);
- for (c = p->MaxContext; c != c1; c = SUFFIX(c))
- if (--(c->NumStats) == 0)
- {
- s = STATS(c);
- c->Flags = (c->Flags & 0x10) + 0x08 * (s->Symbol >= 0x40);
- *ONE_STATE(c) = *s;
- SpecialFreeUnit(p, s);
- ONE_STATE(c)->Freq = (ONE_STATE(c)->Freq + 11) >> 3;
- }
- else
- Refresh(p, c, (c->NumStats+3) >> 1, 0);
-
- for (; c != p->MinContext; c = SUFFIX(c))
- if (!c->NumStats)
- ONE_STATE(c)->Freq -= ONE_STATE(c)->Freq >> 1;
- else if ((c->SummFreq += 4) > 128 + 4 * c->NumStats)
- Refresh(p, c, (c->NumStats + 2) >> 1, 1);
-
- #ifdef PPMD8_FREEZE_SUPPORT
- if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE)
- {
- p->MaxContext = fSuccessor;
- p->GlueCount += !(p->Stamps[1] & 1);
- }
- else if (p->RestoreMethod == PPMD8_RESTORE_METHOD_FREEZE)
- {
- while (p->MaxContext->Suffix)
- p->MaxContext = SUFFIX(p->MaxContext);
- RemoveBinContexts(p, p->MaxContext, 0);
- p->RestoreMethod++;
- p->GlueCount = 0;
- p->OrderFall = p->MaxOrder;
- }
- else
- #endif
- if (p->RestoreMethod == PPMD8_RESTORE_METHOD_RESTART || GetUsedMemory(p) < (p->Size >> 1))
- RestartModel(p);
- else
- {
- while (p->MaxContext->Suffix)
- p->MaxContext = SUFFIX(p->MaxContext);
- do
- {
- CutOff(p, p->MaxContext, 0);
- ExpandTextArea(p);
- }
- while (GetUsedMemory(p) > 3 * (p->Size >> 2));
- p->GlueCount = 0;
- p->OrderFall = p->MaxOrder;
- }
-}
-
-static CTX_PTR CreateSuccessors(CPpmd8 *p, Bool skip, CPpmd_State *s1, CTX_PTR c)
-{
- CPpmd_State upState;
- Byte flags;
- CPpmd_Byte_Ref upBranch = (CPpmd_Byte_Ref)SUCCESSOR(p->FoundState);
- /* fixed over Shkarin's code. Maybe it could work without + 1 too. */
- CPpmd_State *ps[PPMD8_MAX_ORDER + 1];
- unsigned numPs = 0;
-
- if (!skip)
- ps[numPs++] = p->FoundState;
-
- while (c->Suffix)
- {
- CPpmd_Void_Ref successor;
- CPpmd_State *s;
- c = SUFFIX(c);
- if (s1)
- {
- s = s1;
- s1 = NULL;
- }
- else if (c->NumStats != 0)
- {
- for (s = STATS(c); s->Symbol != p->FoundState->Symbol; s++);
- if (s->Freq < MAX_FREQ - 9)
- {
- s->Freq++;
- c->SummFreq++;
- }
- }
- else
- {
- s = ONE_STATE(c);
- s->Freq += (!SUFFIX(c)->NumStats & (s->Freq < 24));
- }
- successor = SUCCESSOR(s);
- if (successor != upBranch)
- {
- c = CTX(successor);
- if (numPs == 0)
- return c;
- break;
- }
- ps[numPs++] = s;
- }
-
- upState.Symbol = *(const Byte *)Ppmd8_GetPtr(p, upBranch);
- SetSuccessor(&upState, upBranch + 1);
- flags = 0x10 * (p->FoundState->Symbol >= 0x40) + 0x08 * (upState.Symbol >= 0x40);
-
- if (c->NumStats == 0)
- upState.Freq = ONE_STATE(c)->Freq;
- else
- {
- UInt32 cf, s0;
- CPpmd_State *s;
- for (s = STATS(c); s->Symbol != upState.Symbol; s++);
- cf = s->Freq - 1;
- s0 = c->SummFreq - c->NumStats - cf;
- upState.Freq = (Byte)(1 + ((2 * cf <= s0) ? (5 * cf > s0) : ((cf + 2 * s0 - 3) / s0)));
- }
-
- do
- {
- /* Create Child */
- CTX_PTR c1; /* = AllocContext(p); */
- if (p->HiUnit != p->LoUnit)
- c1 = (CTX_PTR)(p->HiUnit -= UNIT_SIZE);
- else if (p->FreeList[0] != 0)
- c1 = (CTX_PTR)RemoveNode(p, 0);
- else
- {
- c1 = (CTX_PTR)AllocUnitsRare(p, 0);
- if (!c1)
- return NULL;
- }
- c1->NumStats = 0;
- c1->Flags = flags;
- *ONE_STATE(c1) = upState;
- c1->Suffix = REF(c);
- SetSuccessor(ps[--numPs], REF(c1));
- c = c1;
- }
- while (numPs != 0);
-
- return c;
-}
-
-static CTX_PTR ReduceOrder(CPpmd8 *p, CPpmd_State *s1, CTX_PTR c)
-{
- CPpmd_State *s = NULL;
- CTX_PTR c1 = c;
- CPpmd_Void_Ref upBranch = REF(p->Text);
-
- #ifdef PPMD8_FREEZE_SUPPORT
- /* The BUG in Shkarin's code was fixed: ps could overflow in CUT_OFF mode. */
- CPpmd_State *ps[PPMD8_MAX_ORDER + 1];
- unsigned numPs = 0;
- ps[numPs++] = p->FoundState;
- #endif
-
- SetSuccessor(p->FoundState, upBranch);
- p->OrderFall++;
-
- for (;;)
- {
- if (s1)
- {
- c = SUFFIX(c);
- s = s1;
- s1 = NULL;
- }
- else
- {
- if (!c->Suffix)
- {
- #ifdef PPMD8_FREEZE_SUPPORT
- if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE)
- {
- do { SetSuccessor(ps[--numPs], REF(c)); } while (numPs);
- RESET_TEXT(1);
- p->OrderFall = 1;
- }
- #endif
- return c;
- }
- c = SUFFIX(c);
- if (c->NumStats)
- {
- if ((s = STATS(c))->Symbol != p->FoundState->Symbol)
- do { s++; } while (s->Symbol != p->FoundState->Symbol);
- if (s->Freq < MAX_FREQ - 9)
- {
- s->Freq += 2;
- c->SummFreq += 2;
- }
- }
- else
- {
- s = ONE_STATE(c);
- s->Freq += (s->Freq < 32);
- }
- }
- if (SUCCESSOR(s))
- break;
- #ifdef PPMD8_FREEZE_SUPPORT
- ps[numPs++] = s;
- #endif
- SetSuccessor(s, upBranch);
- p->OrderFall++;
- }
-
- #ifdef PPMD8_FREEZE_SUPPORT
- if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE)
- {
- c = CTX(SUCCESSOR(s));
- do { SetSuccessor(ps[--numPs], REF(c)); } while (numPs);
- RESET_TEXT(1);
- p->OrderFall = 1;
- return c;
- }
- else
- #endif
- if (SUCCESSOR(s) <= upBranch)
- {
- CTX_PTR successor;
- CPpmd_State *s1 = p->FoundState;
- p->FoundState = s;
-
- successor = CreateSuccessors(p, False, NULL, c);
- if (successor == NULL)
- SetSuccessor(s, 0);
- else
- SetSuccessor(s, REF(successor));
- p->FoundState = s1;
- }
-
- if (p->OrderFall == 1 && c1 == p->MaxContext)
- {
- SetSuccessor(p->FoundState, SUCCESSOR(s));
- p->Text--;
- }
- if (SUCCESSOR(s) == 0)
- return NULL;
- return CTX(SUCCESSOR(s));
-}
-
-static void UpdateModel(CPpmd8 *p)
-{
- CPpmd_Void_Ref successor, fSuccessor = SUCCESSOR(p->FoundState);
- CTX_PTR c;
- unsigned s0, ns, fFreq = p->FoundState->Freq;
- Byte flag, fSymbol = p->FoundState->Symbol;
- CPpmd_State *s = NULL;
-
- if (p->FoundState->Freq < MAX_FREQ / 4 && p->MinContext->Suffix != 0)
- {
- c = SUFFIX(p->MinContext);
-
- if (c->NumStats == 0)
- {
- s = ONE_STATE(c);
- if (s->Freq < 32)
- s->Freq++;
- }
- else
- {
- s = STATS(c);
- if (s->Symbol != p->FoundState->Symbol)
- {
- do { s++; } while (s->Symbol != p->FoundState->Symbol);
- if (s[0].Freq >= s[-1].Freq)
- {
- SwapStates(&s[0], &s[-1]);
- s--;
- }
- }
- if (s->Freq < MAX_FREQ - 9)
- {
- s->Freq += 2;
- c->SummFreq += 2;
- }
- }
- }
-
- c = p->MaxContext;
- if (p->OrderFall == 0 && fSuccessor)
- {
- CTX_PTR cs = CreateSuccessors(p, True, s, p->MinContext);
- if (cs == 0)
- {
- SetSuccessor(p->FoundState, 0);
- RESTORE_MODEL(c, CTX(fSuccessor));
- }
- else
- {
- SetSuccessor(p->FoundState, REF(cs));
- p->MaxContext = cs;
- }
- return;
- }
-
- *p->Text++ = p->FoundState->Symbol;
- successor = REF(p->Text);
- if (p->Text >= p->UnitsStart)
- {
- RESTORE_MODEL(c, CTX(fSuccessor)); /* check it */
- return;
- }
-
- if (!fSuccessor)
- {
- CTX_PTR cs = ReduceOrder(p, s, p->MinContext);
- if (cs == NULL)
- {
- RESTORE_MODEL(c, 0);
- return;
- }
- fSuccessor = REF(cs);
- }
- else if ((Byte *)Ppmd8_GetPtr(p, fSuccessor) < p->UnitsStart)
- {
- CTX_PTR cs = CreateSuccessors(p, False, s, p->MinContext);
- if (cs == NULL)
- {
- RESTORE_MODEL(c, 0);
- return;
- }
- fSuccessor = REF(cs);
- }
-
- if (--p->OrderFall == 0)
- {
- successor = fSuccessor;
- p->Text -= (p->MaxContext != p->MinContext);
- }
- #ifdef PPMD8_FREEZE_SUPPORT
- else if (p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE)
- {
- successor = fSuccessor;
- RESET_TEXT(0);
- p->OrderFall = 0;
- }
- #endif
-
- s0 = p->MinContext->SummFreq - (ns = p->MinContext->NumStats) - fFreq;
- flag = 0x08 * (fSymbol >= 0x40);
-
- for (; c != p->MinContext; c = SUFFIX(c))
- {
- unsigned ns1;
- UInt32 cf, sf;
- if ((ns1 = c->NumStats) != 0)
- {
- if ((ns1 & 1) != 0)
- {
- /* Expand for one UNIT */
- unsigned oldNU = (ns1 + 1) >> 1;
- unsigned i = U2I(oldNU);
- if (i != U2I(oldNU + 1))
- {
- void *ptr = AllocUnits(p, i + 1);
- void *oldPtr;
- if (!ptr)
- {
- RESTORE_MODEL(c, CTX(fSuccessor));
- return;
- }
- oldPtr = STATS(c);
- MyMem12Cpy(ptr, oldPtr, oldNU);
- InsertNode(p, oldPtr, i);
- c->Stats = STATS_REF(ptr);
- }
- }
- c->SummFreq = (UInt16)(c->SummFreq + (3 * ns1 + 1 < ns));
- }
- else
- {
- CPpmd_State *s = (CPpmd_State*)AllocUnits(p, 0);
- if (!s)
- {
- RESTORE_MODEL(c, CTX(fSuccessor));
- return;
- }
- *s = *ONE_STATE(c);
- c->Stats = REF(s);
- if (s->Freq < MAX_FREQ / 4 - 1)
- s->Freq <<= 1;
- else
- s->Freq = MAX_FREQ - 4;
- c->SummFreq = (UInt16)(s->Freq + p->InitEsc + (ns > 2));
- }
- cf = 2 * fFreq * (c->SummFreq + 6);
- sf = (UInt32)s0 + c->SummFreq;
- if (cf < 6 * sf)
- {
- cf = 1 + (cf > sf) + (cf >= 4 * sf);
- c->SummFreq += 4;
- }
- else
- {
- cf = 4 + (cf > 9 * sf) + (cf > 12 * sf) + (cf > 15 * sf);
- c->SummFreq = (UInt16)(c->SummFreq + cf);
- }
- {
- CPpmd_State *s = STATS(c) + ns1 + 1;
- SetSuccessor(s, successor);
- s->Symbol = fSymbol;
- s->Freq = (Byte)cf;
- c->Flags |= flag;
- c->NumStats = (Byte)(ns1 + 1);
- }
- }
- p->MaxContext = p->MinContext = CTX(fSuccessor);
-}
-
-static void Rescale(CPpmd8 *p)
-{
- unsigned i, adder, sumFreq, escFreq;
- CPpmd_State *stats = STATS(p->MinContext);
- CPpmd_State *s = p->FoundState;
- {
- CPpmd_State tmp = *s;
- for (; s != stats; s--)
- s[0] = s[-1];
- *s = tmp;
- }
- escFreq = p->MinContext->SummFreq - s->Freq;
- s->Freq += 4;
- adder = (p->OrderFall != 0
- #ifdef PPMD8_FREEZE_SUPPORT
- || p->RestoreMethod > PPMD8_RESTORE_METHOD_FREEZE
- #endif
- );
- s->Freq = (Byte)((s->Freq + adder) >> 1);
- sumFreq = s->Freq;
-
- i = p->MinContext->NumStats;
- do
- {
- escFreq -= (++s)->Freq;
- s->Freq = (Byte)((s->Freq + adder) >> 1);
- sumFreq += s->Freq;
- if (s[0].Freq > s[-1].Freq)
- {
- CPpmd_State *s1 = s;
- CPpmd_State tmp = *s1;
- do
- s1[0] = s1[-1];
- while (--s1 != stats && tmp.Freq > s1[-1].Freq);
- *s1 = tmp;
- }
- }
- while (--i);
-
- if (s->Freq == 0)
- {
- unsigned numStats = p->MinContext->NumStats;
- unsigned n0, n1;
- do { i++; } while ((--s)->Freq == 0);
- escFreq += i;
- p->MinContext->NumStats = (Byte)(p->MinContext->NumStats - i);
- if (p->MinContext->NumStats == 0)
- {
- CPpmd_State tmp = *stats;
- tmp.Freq = (Byte)((2 * tmp.Freq + escFreq - 1) / escFreq);
- if (tmp.Freq > MAX_FREQ / 3)
- tmp.Freq = MAX_FREQ / 3;
- InsertNode(p, stats, U2I((numStats + 2) >> 1));
- p->MinContext->Flags = (p->MinContext->Flags & 0x10) + 0x08 * (tmp.Symbol >= 0x40);
- *(p->FoundState = ONE_STATE(p->MinContext)) = tmp;
- return;
- }
- n0 = (numStats + 2) >> 1;
- n1 = (p->MinContext->NumStats + 2) >> 1;
- if (n0 != n1)
- p->MinContext->Stats = STATS_REF(ShrinkUnits(p, stats, n0, n1));
- p->MinContext->Flags &= ~0x08;
- p->MinContext->Flags |= 0x08 * ((s = STATS(p->MinContext))->Symbol >= 0x40);
- i = p->MinContext->NumStats;
- do { p->MinContext->Flags |= 0x08*((++s)->Symbol >= 0x40); } while (--i);
- }
- p->MinContext->SummFreq = (UInt16)(sumFreq + escFreq - (escFreq >> 1));
- p->MinContext->Flags |= 0x4;
- p->FoundState = STATS(p->MinContext);
-}
-
-CPpmd_See *Ppmd8_MakeEscFreq(CPpmd8 *p, unsigned numMasked1, UInt32 *escFreq)
-{
- CPpmd_See *see;
- if (p->MinContext->NumStats != 0xFF)
- {
- see = p->See[p->NS2Indx[p->MinContext->NumStats + 2] - 3] +
- (p->MinContext->SummFreq > 11 * ((unsigned)p->MinContext->NumStats + 1)) +
- 2 * (2 * (unsigned)p->MinContext->NumStats <
- ((unsigned)SUFFIX(p->MinContext)->NumStats + numMasked1)) +
- p->MinContext->Flags;
- {
- unsigned r = (see->Summ >> see->Shift);
- see->Summ = (UInt16)(see->Summ - r);
- *escFreq = r + (r == 0);
- }
- }
- else
- {
- see = &p->DummySee;
- *escFreq = 1;
- }
- return see;
-}
-
-static void NextContext(CPpmd8 *p)
-{
- CTX_PTR c = CTX(SUCCESSOR(p->FoundState));
- if (p->OrderFall == 0 && (Byte *)c >= p->UnitsStart)
- p->MinContext = p->MaxContext = c;
- else
- {
- UpdateModel(p);
- p->MinContext = p->MaxContext;
- }
-}
-
-void Ppmd8_Update1(CPpmd8 *p)
-{
- CPpmd_State *s = p->FoundState;
- s->Freq += 4;
- p->MinContext->SummFreq += 4;
- if (s[0].Freq > s[-1].Freq)
- {
- SwapStates(&s[0], &s[-1]);
- p->FoundState = --s;
- if (s->Freq > MAX_FREQ)
- Rescale(p);
- }
- NextContext(p);
-}
-
-void Ppmd8_Update1_0(CPpmd8 *p)
-{
- p->PrevSuccess = (2 * p->FoundState->Freq >= p->MinContext->SummFreq);
- p->RunLength += p->PrevSuccess;
- p->MinContext->SummFreq += 4;
- if ((p->FoundState->Freq += 4) > MAX_FREQ)
- Rescale(p);
- NextContext(p);
-}
-
-void Ppmd8_UpdateBin(CPpmd8 *p)
-{
- p->FoundState->Freq = (Byte)(p->FoundState->Freq + (p->FoundState->Freq < 196));
- p->PrevSuccess = 1;
- p->RunLength++;
- NextContext(p);
-}
-
-void Ppmd8_Update2(CPpmd8 *p)
-{
- p->MinContext->SummFreq += 4;
- if ((p->FoundState->Freq += 4) > MAX_FREQ)
- Rescale(p);
- p->RunLength = p->InitRL;
- UpdateModel(p);
- p->MinContext = p->MaxContext;
-}
-
-/* H->I changes:
- NS2Indx
- GlewCount, and Glue method
- BinSum
- See / EscFreq
- CreateSuccessors updates more suffix contexts
- UpdateModel consts.
- PrevSuccess Update
-*/
diff --git a/ext/VFS/ext/7z/src/Ppmd8.h b/ext/VFS/ext/7z/src/Ppmd8.h
deleted file mode 100644
index 6efd4eaf..00000000
--- a/ext/VFS/ext/7z/src/Ppmd8.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/* Ppmd8.h -- PPMdI codec
-2010-03-24 : Igor Pavlov : Public domain
-This code is based on:
- PPMd var.I (2002): Dmitry Shkarin : Public domain
- Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
-
-#ifndef __PPMD8_H
-#define __PPMD8_H
-
-#include "Ppmd.h"
-
-EXTERN_C_BEGIN
-
-#define PPMD8_MIN_ORDER 2
-#define PPMD8_MAX_ORDER 16
-
-struct CPpmd8_Context_;
-
-typedef
- #ifdef PPMD_32BIT
- struct CPpmd8_Context_ *
- #else
- UInt32
- #endif
- CPpmd8_Context_Ref;
-
-typedef struct CPpmd8_Context_
-{
- Byte NumStats;
- Byte Flags;
- UInt16 SummFreq;
- CPpmd_State_Ref Stats;
- CPpmd8_Context_Ref Suffix;
-} CPpmd8_Context;
-
-#define Ppmd8Context_OneState(p) ((CPpmd_State *)&(p)->SummFreq)
-
-/* The BUG in Shkarin's code for FREEZE mode was fixed, but that fixed
- code is not compatible with original code for some files compressed
- in FREEZE mode. So we disable FREEZE mode support. */
-
-enum
-{
- PPMD8_RESTORE_METHOD_RESTART,
- PPMD8_RESTORE_METHOD_CUT_OFF
- #ifdef PPMD8_FREEZE_SUPPORT
- , PPMD8_RESTORE_METHOD_FREEZE
- #endif
-};
-
-typedef struct
-{
- CPpmd8_Context *MinContext, *MaxContext;
- CPpmd_State *FoundState;
- unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder;
- Int32 RunLength, InitRL; /* must be 32-bit at least */
-
- UInt32 Size;
- UInt32 GlueCount;
- Byte *Base, *LoUnit, *HiUnit, *Text, *UnitsStart;
- UInt32 AlignOffset;
- unsigned RestoreMethod;
-
- /* Range Coder */
- UInt32 Range;
- UInt32 Code;
- UInt32 Low;
- union
- {
- IByteIn *In;
- IByteOut *Out;
- } Stream;
-
- Byte Indx2Units[PPMD_NUM_INDEXES];
- Byte Units2Indx[128];
- CPpmd_Void_Ref FreeList[PPMD_NUM_INDEXES];
- UInt32 Stamps[PPMD_NUM_INDEXES];
-
- Byte NS2BSIndx[256], NS2Indx[260];
- CPpmd_See DummySee, See[24][32];
- UInt16 BinSumm[25][64];
-} CPpmd8;
-
-void Ppmd8_Construct(CPpmd8 *p);
-Bool Ppmd8_Alloc(CPpmd8 *p, UInt32 size, ISzAlloc *alloc);
-void Ppmd8_Free(CPpmd8 *p, ISzAlloc *alloc);
-void Ppmd8_Init(CPpmd8 *p, unsigned maxOrder, unsigned restoreMethod);
-#define Ppmd8_WasAllocated(p) ((p)->Base != NULL)
-
-
-/* ---------- Internal Functions ---------- */
-
-extern const Byte PPMD8_kExpEscape[16];
-
-#ifdef PPMD_32BIT
- #define Ppmd8_GetPtr(p, ptr) (ptr)
- #define Ppmd8_GetContext(p, ptr) (ptr)
- #define Ppmd8_GetStats(p, ctx) ((ctx)->Stats)
-#else
- #define Ppmd8_GetPtr(p, offs) ((void *)((p)->Base + (offs)))
- #define Ppmd8_GetContext(p, offs) ((CPpmd8_Context *)Ppmd8_GetPtr((p), (offs)))
- #define Ppmd8_GetStats(p, ctx) ((CPpmd_State *)Ppmd8_GetPtr((p), ((ctx)->Stats)))
-#endif
-
-void Ppmd8_Update1(CPpmd8 *p);
-void Ppmd8_Update1_0(CPpmd8 *p);
-void Ppmd8_Update2(CPpmd8 *p);
-void Ppmd8_UpdateBin(CPpmd8 *p);
-
-#define Ppmd8_GetBinSumm(p) \
- &p->BinSumm[p->NS2Indx[Ppmd8Context_OneState(p->MinContext)->Freq - 1]][ \
- p->NS2BSIndx[Ppmd8_GetContext(p, p->MinContext->Suffix)->NumStats] + \
- p->PrevSuccess + p->MinContext->Flags + ((p->RunLength >> 26) & 0x20)]
-
-CPpmd_See *Ppmd8_MakeEscFreq(CPpmd8 *p, unsigned numMasked, UInt32 *scale);
-
-
-/* ---------- Decode ---------- */
-
-Bool Ppmd8_RangeDec_Init(CPpmd8 *p);
-#define Ppmd8_RangeDec_IsFinishedOK(p) ((p)->Code == 0)
-int Ppmd8_DecodeSymbol(CPpmd8 *p); /* returns: -1 as EndMarker, -2 as DataError */
-
-
-/* ---------- Encode ---------- */
-
-#define Ppmd8_RangeEnc_Init(p) { (p)->Low = 0; (p)->Range = 0xFFFFFFFF; }
-void Ppmd8_RangeEnc_FlushData(CPpmd8 *p);
-void Ppmd8_EncodeSymbol(CPpmd8 *p, int symbol); /* symbol = -1 means EndMarker */
-
-EXTERN_C_END
-
-#endif
diff --git a/ext/VFS/ext/7z/src/Ppmd8Dec.c b/ext/VFS/ext/7z/src/Ppmd8Dec.c
deleted file mode 100644
index 2d2c06cb..00000000
--- a/ext/VFS/ext/7z/src/Ppmd8Dec.c
+++ /dev/null
@@ -1,155 +0,0 @@
-/* Ppmd8Dec.c -- PPMdI Decoder
-2010-03-12 : Igor Pavlov : Public domain
-This code is based on:
- PPMd var.I (2002): Dmitry Shkarin : Public domain
- Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
-
-#include "Ppmd8.h"
-
-#define kTop (1 << 24)
-#define kBot (1 << 15)
-
-Bool Ppmd8_RangeDec_Init(CPpmd8 *p)
-{
- unsigned i;
- p->Low = 0;
- p->Range = 0xFFFFFFFF;
- p->Code = 0;
- for (i = 0; i < 4; i++)
- p->Code = (p->Code << 8) | p->Stream.In->Read(p->Stream.In);
- return (p->Code < 0xFFFFFFFF);
-}
-
-static UInt32 RangeDec_GetThreshold(CPpmd8 *p, UInt32 total)
-{
- return p->Code / (p->Range /= total);
-}
-
-static void RangeDec_Decode(CPpmd8 *p, UInt32 start, UInt32 size)
-{
- start *= p->Range;
- p->Low += start;
- p->Code -= start;
- p->Range *= size;
-
- while ((p->Low ^ (p->Low + p->Range)) < kTop ||
- p->Range < kBot && ((p->Range = (0 - p->Low) & (kBot - 1)), 1))
- {
- p->Code = (p->Code << 8) | p->Stream.In->Read(p->Stream.In);
- p->Range <<= 8;
- p->Low <<= 8;
- }
-}
-
-#define MASK(sym) ((signed char *)charMask)[sym]
-
-int Ppmd8_DecodeSymbol(CPpmd8 *p)
-{
- size_t charMask[256 / sizeof(size_t)];
- if (p->MinContext->NumStats != 0)
- {
- CPpmd_State *s = Ppmd8_GetStats(p, p->MinContext);
- unsigned i;
- UInt32 count, hiCnt;
- if ((count = RangeDec_GetThreshold(p, p->MinContext->SummFreq)) < (hiCnt = s->Freq))
- {
- Byte symbol;
- RangeDec_Decode(p, 0, s->Freq);
- p->FoundState = s;
- symbol = s->Symbol;
- Ppmd8_Update1_0(p);
- return symbol;
- }
- p->PrevSuccess = 0;
- i = p->MinContext->NumStats;
- do
- {
- if ((hiCnt += (++s)->Freq) > count)
- {
- Byte symbol;
- RangeDec_Decode(p, hiCnt - s->Freq, s->Freq);
- p->FoundState = s;
- symbol = s->Symbol;
- Ppmd8_Update1(p);
- return symbol;
- }
- }
- while (--i);
- if (count >= p->MinContext->SummFreq)
- return -2;
- RangeDec_Decode(p, hiCnt, p->MinContext->SummFreq - hiCnt);
- PPMD_SetAllBitsIn256Bytes(charMask);
- MASK(s->Symbol) = 0;
- i = p->MinContext->NumStats;
- do { MASK((--s)->Symbol) = 0; } while (--i);
- }
- else
- {
- UInt16 *prob = Ppmd8_GetBinSumm(p);
- if (((p->Code / (p->Range >>= 14)) < *prob))
- {
- Byte symbol;
- RangeDec_Decode(p, 0, *prob);
- *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob);
- symbol = (p->FoundState = Ppmd8Context_OneState(p->MinContext))->Symbol;
- Ppmd8_UpdateBin(p);
- return symbol;
- }
- RangeDec_Decode(p, *prob, (1 << 14) - *prob);
- *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob);
- p->InitEsc = PPMD8_kExpEscape[*prob >> 10];
- PPMD_SetAllBitsIn256Bytes(charMask);
- MASK(Ppmd8Context_OneState(p->MinContext)->Symbol) = 0;
- p->PrevSuccess = 0;
- }
- for (;;)
- {
- CPpmd_State *ps[256], *s;
- UInt32 freqSum, count, hiCnt;
- CPpmd_See *see;
- unsigned i, num, numMasked = p->MinContext->NumStats;
- do
- {
- p->OrderFall++;
- if (!p->MinContext->Suffix)
- return -1;
- p->MinContext = Ppmd8_GetContext(p, p->MinContext->Suffix);
- }
- while (p->MinContext->NumStats == numMasked);
- hiCnt = 0;
- s = Ppmd8_GetStats(p, p->MinContext);
- i = 0;
- num = p->MinContext->NumStats - numMasked;
- do
- {
- int k = (int)(MASK(s->Symbol));
- hiCnt += (s->Freq & k);
- ps[i] = s++;
- i -= k;
- }
- while (i != num);
-
- see = Ppmd8_MakeEscFreq(p, numMasked, &freqSum);
- freqSum += hiCnt;
- count = RangeDec_GetThreshold(p, freqSum);
-
- if (count < hiCnt)
- {
- Byte symbol;
- CPpmd_State **pps = ps;
- for (hiCnt = 0; (hiCnt += (*pps)->Freq) <= count; pps++);
- s = *pps;
- RangeDec_Decode(p, hiCnt - s->Freq, s->Freq);
- Ppmd_See_Update(see);
- p->FoundState = s;
- symbol = s->Symbol;
- Ppmd8_Update2(p);
- return symbol;
- }
- if (count >= freqSum)
- return -2;
- RangeDec_Decode(p, hiCnt, freqSum - hiCnt);
- see->Summ = (UInt16)(see->Summ + freqSum);
- do { MASK(ps[--i]->Symbol) = 0; } while (i != 0);
- }
-}
diff --git a/ext/VFS/ext/7z/src/Ppmd8Enc.c b/ext/VFS/ext/7z/src/Ppmd8Enc.c
deleted file mode 100644
index 7be55caf..00000000
--- a/ext/VFS/ext/7z/src/Ppmd8Enc.c
+++ /dev/null
@@ -1,161 +0,0 @@
-/* Ppmd8Enc.c -- PPMdI Encoder
-2010-03-12 : Igor Pavlov : Public domain
-This code is based on:
- PPMd var.I (2002): Dmitry Shkarin : Public domain
- Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
-
-#include "Ppmd8.h"
-
-#define kTop (1 << 24)
-#define kBot (1 << 15)
-
-void Ppmd8_RangeEnc_FlushData(CPpmd8 *p)
-{
- unsigned i;
- for (i = 0; i < 4; i++, p->Low <<= 8 )
- p->Stream.Out->Write(p->Stream.Out, (Byte)(p->Low >> 24));
-}
-
-static void RangeEnc_Normalize(CPpmd8 *p)
-{
- while ((p->Low ^ (p->Low + p->Range)) < kTop ||
- p->Range < kBot && ((p->Range = (0 - p->Low) & (kBot - 1)), 1))
- {
- p->Stream.Out->Write(p->Stream.Out, (Byte)(p->Low >> 24));
- p->Range <<= 8;
- p->Low <<= 8;
- }
-}
-
-static void RangeEnc_Encode(CPpmd8 *p, UInt32 start, UInt32 size, UInt32 total)
-{
- p->Low += start * (p->Range /= total);
- p->Range *= size;
- RangeEnc_Normalize(p);
-}
-
-static void RangeEnc_EncodeBit_0(CPpmd8 *p, UInt32 size0)
-{
- p->Range >>= 14;
- p->Range *= size0;
- RangeEnc_Normalize(p);
-}
-
-static void RangeEnc_EncodeBit_1(CPpmd8 *p, UInt32 size0)
-{
- p->Low += size0 * (p->Range >>= 14);
- p->Range *= ((1 << 14) - size0);
- RangeEnc_Normalize(p);
-}
-
-
-#define MASK(sym) ((signed char *)charMask)[sym]
-
-void Ppmd8_EncodeSymbol(CPpmd8 *p, int symbol)
-{
- size_t charMask[256 / sizeof(size_t)];
- if (p->MinContext->NumStats != 0)
- {
- CPpmd_State *s = Ppmd8_GetStats(p, p->MinContext);
- UInt32 sum;
- unsigned i;
- if (s->Symbol == symbol)
- {
- RangeEnc_Encode(p, 0, s->Freq, p->MinContext->SummFreq);
- p->FoundState = s;
- Ppmd8_Update1_0(p);
- return;
- }
- p->PrevSuccess = 0;
- sum = s->Freq;
- i = p->MinContext->NumStats;
- do
- {
- if ((++s)->Symbol == symbol)
- {
- RangeEnc_Encode(p, sum, s->Freq, p->MinContext->SummFreq);
- p->FoundState = s;
- Ppmd8_Update1(p);
- return;
- }
- sum += s->Freq;
- }
- while (--i);
-
- PPMD_SetAllBitsIn256Bytes(charMask);
- MASK(s->Symbol) = 0;
- i = p->MinContext->NumStats;
- do { MASK((--s)->Symbol) = 0; } while (--i);
- RangeEnc_Encode(p, sum, p->MinContext->SummFreq - sum, p->MinContext->SummFreq);
- }
- else
- {
- UInt16 *prob = Ppmd8_GetBinSumm(p);
- CPpmd_State *s = Ppmd8Context_OneState(p->MinContext);
- if (s->Symbol == symbol)
- {
- RangeEnc_EncodeBit_0(p, *prob);
- *prob = (UInt16)PPMD_UPDATE_PROB_0(*prob);
- p->FoundState = s;
- Ppmd8_UpdateBin(p);
- return;
- }
- else
- {
- RangeEnc_EncodeBit_1(p, *prob);
- *prob = (UInt16)PPMD_UPDATE_PROB_1(*prob);
- p->InitEsc = PPMD8_kExpEscape[*prob >> 10];
- PPMD_SetAllBitsIn256Bytes(charMask);
- MASK(s->Symbol) = 0;
- p->PrevSuccess = 0;
- }
- }
- for (;;)
- {
- UInt32 escFreq;
- CPpmd_See *see;
- CPpmd_State *s;
- UInt32 sum;
- unsigned i, numMasked = p->MinContext->NumStats;
- do
- {
- p->OrderFall++;
- if (!p->MinContext->Suffix)
- return; /* EndMarker (symbol = -1) */
- p->MinContext = Ppmd8_GetContext(p, p->MinContext->Suffix);
- }
- while (p->MinContext->NumStats == numMasked);
-
- see = Ppmd8_MakeEscFreq(p, numMasked, &escFreq);
- s = Ppmd8_GetStats(p, p->MinContext);
- sum = 0;
- i = p->MinContext->NumStats + 1;
- do
- {
- int cur = s->Symbol;
- if (cur == symbol)
- {
- UInt32 low = sum;
- CPpmd_State *s1 = s;
- do
- {
- sum += (s->Freq & (int)(MASK(s->Symbol)));
- s++;
- }
- while (--i);
- RangeEnc_Encode(p, low, s1->Freq, sum + escFreq);
- Ppmd_See_Update(see);
- p->FoundState = s1;
- Ppmd8_Update2(p);
- return;
- }
- sum += (s->Freq & (int)(MASK(cur)));
- MASK(cur) = 0;
- s++;
- }
- while (--i);
-
- RangeEnc_Encode(p, sum, escFreq, sum + escFreq);
- see->Summ = (UInt16)(see->Summ + sum + escFreq);
- }
-}
diff --git a/ext/VFS/ext/7z/src/Sha256.c b/ext/VFS/ext/7z/src/Sha256.c
index cab4048c..cfb9eace 100644
--- a/ext/VFS/ext/7z/src/Sha256.c
+++ b/ext/VFS/ext/7z/src/Sha256.c
@@ -1,9 +1,9 @@
-/* Crypto/Sha256.c -- SHA-256 Hash function
-2008-11-06 : Igor Pavlov : Public domain
+/* Crypto/Sha256.c -- SHA-256 Hash
+2010-06-11 : Igor Pavlov : Public domain
This code is based on public domain code from Wei Dai's Crypto++ library. */
-#include "Sha256.h"
#include "RotateDefs.h"
+#include "Sha256.h"
/* define it for speed optimization */
/* #define _SHA256_UNROLL */
@@ -71,7 +71,7 @@ void Sha256_Init(CSha256 *p)
#endif
-const UInt32 K[64] = {
+static const UInt32 K[64] = {
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
diff --git a/ext/VFS/ext/7z/src/Sha256.h b/ext/VFS/ext/7z/src/Sha256.h
index 971c4f6e..26d1e3af 100644
--- a/ext/VFS/ext/7z/src/Sha256.h
+++ b/ext/VFS/ext/7z/src/Sha256.h
@@ -1,14 +1,12 @@
/* Sha256.h -- SHA-256 Hash
-2009-02-07 : Igor Pavlov : Public domain */
+2010-06-11 : Igor Pavlov : Public domain */
#ifndef __CRYPTO_SHA256_H
#define __CRYPTO_SHA256_H
#include "Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+EXTERN_C_BEGIN
#define SHA256_DIGEST_SIZE 32
@@ -23,8 +21,6 @@ void Sha256_Init(CSha256 *p);
void Sha256_Update(CSha256 *p, const Byte *data, size_t size);
void Sha256_Final(CSha256 *p, Byte *digest);
-#ifdef __cplusplus
-}
-#endif
+EXTERN_C_END
#endif
diff --git a/ext/VFS/ext/7z/src/Types.h b/ext/VFS/ext/7z/src/Types.h
index c60c1563..f193ce2f 100644
--- a/ext/VFS/ext/7z/src/Types.h
+++ b/ext/VFS/ext/7z/src/Types.h
@@ -1,5 +1,5 @@
/* Types.h -- Basic types
-2010-03-11 : Igor Pavlov : Public domain */
+2010-10-09 : Igor Pavlov : Public domain */
#ifndef __7Z_TYPES_H
#define __7Z_TYPES_H
@@ -20,21 +20,6 @@
#endif
#endif
-//#ifdef __cplusplus
-#if defined(_WIN32) && defined(_MSC_VER)
-# if !defined(SZIP_STATIC)
-# if defined(SZIP_EXPORT)
-# define SZIP_API __declspec(dllexport)
-# else
-# define SZIP_API __declspec(dllimport)
-# endif
-# else
-# define SZIP_API
-# endif
-#else
-# define SZIP_API
-#endif
-
EXTERN_C_BEGIN
#define SZ_OK 0
@@ -92,9 +77,11 @@ typedef unsigned long UInt64;
#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
@@ -211,8 +198,8 @@ typedef struct
Byte buf[LookToRead_BUF_SIZE];
} CLookToRead;
-SZIP_API void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
-SZIP_API void LookToRead_Init(CLookToRead *p);
+void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
+void LookToRead_Init(CLookToRead *p);
typedef struct
{
@@ -246,6 +233,22 @@ 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/ext/VFS/ext/7z/src/Xz.h b/ext/VFS/ext/7z/src/Xz.h
index 65359712..a8f3ec55 100644
--- a/ext/VFS/ext/7z/src/Xz.h
+++ b/ext/VFS/ext/7z/src/Xz.h
@@ -1,14 +1,12 @@
/* Xz.h - Xz interface
-2009-04-15 : Igor Pavlov : Public domain */
+2011-01-09 : Igor Pavlov : Public domain */
#ifndef __XZ_H
#define __XZ_H
#include "Sha256.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+EXTERN_C_BEGIN
#define XZ_ID_Subblock 1
#define XZ_ID_Delta 3
@@ -140,7 +138,7 @@ typedef enum
CODER_STATUS_NOT_SPECIFIED, /* use main error code instead */
CODER_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
CODER_STATUS_NOT_FINISHED, /* stream was not finished */
- CODER_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
+ CODER_STATUS_NEEDS_MORE_INPUT /* you must provide more input bytes */
} ECoderStatus;
typedef enum
@@ -222,7 +220,8 @@ typedef struct
Byte buf[XZ_BLOCK_HEADER_SIZE_MAX];
} CXzUnpacker;
-SRes XzUnpacker_Create(CXzUnpacker *p, ISzAlloc *alloc);
+void XzUnpacker_Construct(CXzUnpacker *p, ISzAlloc *alloc);
+void XzUnpacker_Init(CXzUnpacker *p);
void XzUnpacker_Free(CXzUnpacker *p);
/*
@@ -234,8 +233,9 @@ finishMode:
Returns:
SZ_OK
status:
- LZMA_STATUS_FINISHED_WITH_MARK
- LZMA_STATUS_NOT_FINISHED
+ CODER_STATUS_NOT_FINISHED,
+ CODER_STATUS_NEEDS_MORE_INPUT - maybe there are more xz streams,
+ call XzUnpacker_IsStreamWasFinished to check that current stream was finished
SZ_ERROR_DATA - Data error
SZ_ERROR_MEM - Memory allocation error
SZ_ERROR_UNSUPPORTED - Unsupported properties
@@ -249,8 +249,6 @@ SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen,
Bool XzUnpacker_IsStreamWasFinished(CXzUnpacker *p);
-#ifdef __cplusplus
-}
-#endif
+EXTERN_C_END
#endif
diff --git a/ext/VFS/ext/7z/src/XzCrc64.c b/ext/VFS/ext/7z/src/XzCrc64.c
index b99495d4..f688b071 100644
--- a/ext/VFS/ext/7z/src/XzCrc64.c
+++ b/ext/VFS/ext/7z/src/XzCrc64.c
@@ -1,9 +1,9 @@
/* XzCrc64.c -- CRC64 calculation
-2009-04-15 : Igor Pavlov : Public domain */
+2010-04-16 : Igor Pavlov : Public domain */
#include "XzCrc64.h"
-#define kCrc64Poly 0xC96C5795D7870F42
+#define kCrc64Poly UINT64_CONST(0xC96C5795D7870F42)
UInt64 g_Crc64Table[256];
void MY_FAST_CALL Crc64GenerateTable(void)
diff --git a/ext/VFS/ext/7z/src/XzCrc64.h b/ext/VFS/ext/7z/src/XzCrc64.h
index 3cd1526a..05d0d09c 100644
--- a/ext/VFS/ext/7z/src/XzCrc64.h
+++ b/ext/VFS/ext/7z/src/XzCrc64.h
@@ -1,5 +1,5 @@
-/* XzCrc64.c -- CRC64 calculation
-2009-04-15 : Igor Pavlov : Public domain */
+/* XzCrc64.h -- CRC64 calculation
+2010-04-16 : Igor Pavlov : Public domain */
#ifndef __XZ_CRC64_H
#define __XZ_CRC64_H
@@ -8,23 +8,19 @@
#include "Types.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+EXTERN_C_BEGIN
extern UInt64 g_Crc64Table[];
void MY_FAST_CALL Crc64GenerateTable(void);
-#define CRC64_INIT_VAL 0xFFFFFFFFFFFFFFFF
-#define CRC64_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFFFFFFFFFF)
+#define CRC64_INIT_VAL UINT64_CONST(0xFFFFFFFFFFFFFFFF)
+#define CRC64_GET_DIGEST(crc) ((crc) ^ CRC64_INIT_VAL)
#define CRC64_UPDATE_BYTE(crc, b) (g_Crc64Table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
UInt64 MY_FAST_CALL Crc64Update(UInt64 crc, const void *data, size_t size);
UInt64 MY_FAST_CALL Crc64Calc(const void *data, size_t size);
-#ifdef __cplusplus
-}
-#endif
+EXTERN_C_END
#endif
diff --git a/ext/VFS/ext/7z/src/XzDec.c b/ext/VFS/ext/7z/src/XzDec.c
index 14a459e1..fe859bfa 100644
--- a/ext/VFS/ext/7z/src/XzDec.c
+++ b/ext/VFS/ext/7z/src/XzDec.c
@@ -1,5 +1,5 @@
/* XzDec.c -- Xz Decode
-2009-06-08 : Igor Pavlov : Public domain */
+2011-02-07 : Igor Pavlov : Public domain */
/* #define XZ_DUMP */
@@ -18,7 +18,8 @@
#include "Lzma2Dec.h"
#ifdef USE_SUBBLOCK
-#include "SbDec.h"
+#include "Bcj3Dec.c"
+#include "SbDec.c"
#endif
#include "Xz.h"
@@ -72,7 +73,6 @@ SRes BraState_SetProps(void *pp, const Byte *props, size_t propSize, ISzAlloc *a
{
CBraState *p = ((CBraState *)pp);
alloc = alloc;
- p->encodeMode = 0;
p->ip = 0;
if (p->methodId == XZ_ID_Delta)
{
@@ -195,7 +195,7 @@ static SRes BraState_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *src,
return SZ_OK;
}
-SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, ISzAlloc *alloc)
+SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, int encodeMode, ISzAlloc *alloc)
{
CBraState *decoder;
if (id != XZ_ID_Delta &&
@@ -211,6 +211,7 @@ SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, ISzAlloc *alloc)
if (decoder == 0)
return SZ_ERROR_MEM;
decoder->methodId = (UInt32)id;
+ decoder->encodeMode = encodeMode;
p->p = decoder;
p->Free = BraState_Free;
p->SetProps = BraState_SetProps;
@@ -225,8 +226,8 @@ SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, ISzAlloc *alloc)
static void SbState_Free(void *pp, ISzAlloc *alloc)
{
- CSubblockDec *p = (CSubblockDec *)pp;
- SubblockDec_Free(p, alloc);
+ CSbDec *p = (CSbDec *)pp;
+ SbDec_Free(p);
alloc->Free(alloc, pp);
}
@@ -240,24 +241,32 @@ static SRes SbState_SetProps(void *pp, const Byte *props, size_t propSize, ISzAl
static void SbState_Init(void *pp)
{
- SubblockDec_Init((CSubblockDec *)pp);
+ SbDec_Init((CSbDec *)pp);
}
static SRes SbState_Code(void *pp, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
int srcWasFinished, ECoderFinishMode finishMode, int *wasFinished)
{
- ECoderStatus status;
- SRes res = SubblockDec_Decode((CSubblockDec *)pp, dest, destLen, src, srcLen, finishMode, &status);
+ CSbDec *p = (CSbDec *)pp;
+ SRes res;
srcWasFinished = srcWasFinished;
- *wasFinished = (status == LZMA_STATUS_FINISHED_WITH_MARK);
+ p->dest = dest;
+ p->destLen = *destLen;
+ p->src = src;
+ p->srcLen = *srcLen;
+ p->finish = finishMode; /* change it */
+ res = SbDec_Decode((CSbDec *)pp);
+ *destLen -= p->destLen;
+ *srcLen -= p->srcLen;
+ *wasFinished = (*destLen == 0 && *srcLen == 0); /* change it */
return res;
}
SRes SbState_SetFromMethod(IStateCoder *p, ISzAlloc *alloc)
{
- CSubblockDec *decoder;
+ CSbDec *decoder;
p->p = 0;
- decoder = alloc->Alloc(alloc, sizeof(CSubblockDec));
+ decoder = alloc->Alloc(alloc, sizeof(CSbDec));
if (decoder == 0)
return SZ_ERROR_MEM;
p->p = decoder;
@@ -265,7 +274,8 @@ SRes SbState_SetFromMethod(IStateCoder *p, ISzAlloc *alloc)
p->SetProps = SbState_SetProps;
p->Init = SbState_Init;
p->Code = SbState_Code;
- SubblockDec_Construct(decoder);
+ SbDec_Construct(decoder);
+ SbDec_SetAlloc(decoder, alloc);
return SZ_OK;
}
#endif
@@ -369,7 +379,7 @@ SRes MixCoder_SetFromMethod(CMixCoder *p, int coderIndex, UInt64 methodId)
}
if (coderIndex == 0)
return SZ_ERROR_UNSUPPORTED;
- return BraState_SetFromMethod(sc, methodId, p->alloc);
+ return BraState_SetFromMethod(sc, methodId, 0, p->alloc);
}
SRes MixCoder_Code(CMixCoder *p, Byte *dest, SizeT *destLen,
@@ -587,13 +597,17 @@ SRes XzDec_Init(CMixCoder *p, const CXzBlock *block)
return SZ_OK;
}
-SRes XzUnpacker_Create(CXzUnpacker *p, ISzAlloc *alloc)
+void XzUnpacker_Init(CXzUnpacker *p)
{
- MixCoder_Construct(&p->decoder, alloc);
p->state = XZ_STATE_STREAM_HEADER;
p->pos = 0;
p->numStreams = 0;
- return SZ_OK;
+}
+
+void XzUnpacker_Construct(CXzUnpacker *p, ISzAlloc *alloc)
+{
+ MixCoder_Construct(&p->decoder, alloc);
+ XzUnpacker_Init(p);
}
void XzUnpacker_Free(CXzUnpacker *p)
@@ -858,6 +872,8 @@ SRes XzUnpacker_Code(CXzUnpacker *p, Byte *dest, SizeT *destLen,
}
break;
}
+
+ case XZ_STATE_BLOCK: break; /* to disable GCC warning */
}
}
/*
diff --git a/ext/VFS/ext/7z/src/XzEnc.c b/ext/VFS/ext/7z/src/XzEnc.c
index e6101406..a7f9125f 100644
--- a/ext/VFS/ext/7z/src/XzEnc.c
+++ b/ext/VFS/ext/7z/src/XzEnc.c
@@ -1,5 +1,5 @@
/* XzEnc.c -- Xz Encode
-2009-06-04 : Igor Pavlov : Public domain */
+2011-02-07 : Igor Pavlov : Public domain */
#include
#include
@@ -9,7 +9,9 @@
#include "Bra.h"
#include "CpuArch.h"
#ifdef USE_SUBBLOCK
-#include "SbEnc.h"
+#include "Bcj3Enc.c"
+#include "SbFind.c"
+#include "SbEnc.c"
#endif
#include "XzEnc.h"
@@ -198,158 +200,147 @@ static size_t MyWrite(void *pp, const void *data, size_t size)
/* ---------- CSeqInFilter ---------- */
-/*
-typedef struct _IFilter
-{
- void *p;
- void (*Free)(void *p, ISzAlloc *alloc);
- SRes (*SetProps)(void *p, const Byte *props, size_t propSize, ISzAlloc *alloc);
- void (*Init)(void *p);
- size_t (*Filter)(void *p, Byte *data, SizeT destLen);
-} IFilter;
-
-#define FILT_BUF_SIZE (1 << 19)
+#define FILTER_BUF_SIZE (1 << 20)
typedef struct
{
ISeqInStream p;
ISeqInStream *realStream;
- UInt32 x86State;
- UInt32 ip;
- UInt64 processed;
- CXzCheck check;
- Byte buf[FILT_BUF_SIZE];
- UInt32 bufferPos;
- UInt32 convertedPosBegin;
- UInt32 convertedPosEnd;
- IFilter *filter;
+ IStateCoder StateCoder;
+ Byte *buf;
+ size_t curPos;
+ size_t endPos;
+ int srcWasFinished;
} CSeqInFilter;
static SRes SeqInFilter_Read(void *pp, void *data, size_t *size)
{
CSeqInFilter *p = (CSeqInFilter *)pp;
- size_t remSize = *size;
+ size_t sizeOriginal = *size;
+ if (sizeOriginal == 0)
+ return S_OK;
*size = 0;
-
- while (remSize > 0)
+ for (;;)
{
- int i;
- if (p->convertedPosBegin != p->convertedPosEnd)
+ if (!p->srcWasFinished && p->curPos == p->endPos)
{
- UInt32 sizeTemp = p->convertedPosEnd - p->convertedPosBegin;
- if (remSize < sizeTemp)
- sizeTemp = (UInt32)remSize;
- memmove(data, p->buf + p->convertedPosBegin, sizeTemp);
- p->convertedPosBegin += sizeTemp;
- data = (void *)((Byte *)data + sizeTemp);
- remSize -= sizeTemp;
- *size += sizeTemp;
- break;
+ p->curPos = 0;
+ p->endPos = FILTER_BUF_SIZE;
+ RINOK(p->realStream->Read(p->realStream, p->buf, &p->endPos));
+ if (p->endPos == 0)
+ p->srcWasFinished = 1;
}
- for (i = 0; p->convertedPosEnd + i < p->bufferPos; i++)
- p->buf[i] = p->buf[i + p->convertedPosEnd];
- p->bufferPos = i;
- p->convertedPosBegin = p->convertedPosEnd = 0;
{
- size_t processedSizeTemp = FILT_BUF_SIZE - p->bufferPos;
- RINOK(p->realStream->Read(p->realStream, p->buf + p->bufferPos, &processedSizeTemp));
- p->bufferPos = p->bufferPos + (UInt32)processedSizeTemp;
- }
- p->convertedPosEnd = (UInt32)p->filter->Filter(p->filter->p, p->buf, p->bufferPos);
- if (p->convertedPosEnd == 0)
- {
- if (p->bufferPos == 0)
- break;
- else
- {
- p->convertedPosEnd = p->bufferPos;
- continue;
- }
- }
- if (p->convertedPosEnd > p->bufferPos)
- {
- for (; p->bufferPos < p->convertedPosEnd; p->bufferPos++)
- p->buf[p->bufferPos] = 0;
- p->convertedPosEnd = (UInt32)p->filter->Filter(p->filter->p, p->buf, p->bufferPos);
+ SizeT srcLen = p->endPos - p->curPos;
+ int wasFinished;
+ SRes res;
+ *size = sizeOriginal;
+ res = p->StateCoder.Code(p->StateCoder.p, data, size, p->buf + p->curPos, &srcLen,
+ p->srcWasFinished, CODER_FINISH_ANY, &wasFinished);
+ p->curPos += srcLen;
+ if (*size != 0 || srcLen == 0 || res != 0)
+ return res;
}
}
- return SZ_OK;
}
-*/
-/*
-typedef struct
+static void SeqInFilter_Construct(CSeqInFilter *p)
{
- ISeqInStream p;
- ISeqInStream *realStream;
- CMixCoder mixCoder;
- Byte buf[FILT_BUF_SIZE];
- UInt32 bufPos;
- UInt32 bufSize;
-} CMixCoderSeqInStream;
+ p->buf = NULL;
+ p->p.Read = SeqInFilter_Read;
+}
-static SRes CMixCoderSeqInStream_Read(void *pp, void *data, size_t *size)
+static void SeqInFilter_Free(CSeqInFilter *p)
{
- CMixCoderSeqInStream *p = (CMixCoderSeqInStream *)pp;
- SRes res = SZ_OK;
- size_t remSize = *size;
- *size = 0;
- while (remSize > 0)
+ if (p->buf)
{
- if (p->bufPos == p->bufSize)
- {
- size_t curSize;
- p->bufPos = p->bufSize = 0;
- if (*size != 0)
- break;
- curSize = FILT_BUF_SIZE;
- RINOK(p->realStream->Read(p->realStream, p->buf, &curSize));
- p->bufSize = (UInt32)curSize;
- }
- {
- SizeT destLen = remSize;
- SizeT srcLen = p->bufSize - p->bufPos;
- res = MixCoder_Code(&p->mixCoder, data, &destLen, p->buf + p->bufPos, &srcLen, 0);
- data = (void *)((Byte *)data + destLen);
- remSize -= destLen;
- *size += destLen;
- p->bufPos += srcLen;
- }
+ g_Alloc.Free(&g_Alloc, p->buf);
+ p->buf = NULL;
}
- return res;
}
-*/
+
+SRes BraState_SetFromMethod(IStateCoder *p, UInt64 id, int encodeMode, ISzAlloc *alloc);
+
+static SRes SeqInFilter_Init(CSeqInFilter *p, const CXzFilter *props)
+{
+ if (!p->buf)
+ {
+ p->buf = g_Alloc.Alloc(&g_Alloc, FILTER_BUF_SIZE);
+ if (!p->buf)
+ return SZ_ERROR_MEM;
+ }
+ p->curPos = p->endPos = 0;
+ p->srcWasFinished = 0;
+ RINOK(BraState_SetFromMethod(&p->StateCoder, props->id, 1, &g_Alloc));
+ RINOK(p->StateCoder.SetProps(p->StateCoder.p, props->props, props->propsSize, &g_Alloc));
+ p->StateCoder.Init(p->StateCoder.p);
+ return S_OK;
+}
+
+/* ---------- CSbEncInStream ---------- */
#ifdef USE_SUBBLOCK
+
typedef struct
{
ISeqInStream p;
- CSubblockEnc sb;
- UInt64 processed;
+ ISeqInStream *inStream;
+ CSbEnc enc;
} CSbEncInStream;
-void SbEncInStream_Init(CSbEncInStream *p)
-{
- p->processed = 0;
- SubblockEnc_Init(&p->sb);
-}
-
static SRes SbEncInStream_Read(void *pp, void *data, size_t *size)
{
CSbEncInStream *p = (CSbEncInStream *)pp;
- SRes res = SubblockEnc_Read(&p->sb, data, size);
- p->processed += *size;
- return res;
+ size_t sizeOriginal = *size;
+ if (sizeOriginal == 0)
+ return S_OK;
+ for (;;)
+ {
+ if (p->enc.needRead && !p->enc.readWasFinished)
+ {
+ size_t processed = p->enc.needReadSizeMax;
+ RINOK(p->inStream->Read(p->inStream, p->enc.buf + p->enc.readPos, &processed));
+ p->enc.readPos += processed;
+ if (processed == 0)
+ {
+ p->enc.readWasFinished = True;
+ p->enc.isFinalFinished = True;
+ }
+ p->enc.needRead = False;
+ }
+ *size = sizeOriginal;
+ RINOK(SbEnc_Read(&p->enc, data, size));
+ if (*size != 0 || !p->enc.needRead)
+ return S_OK;
+ }
}
+
+void SbEncInStream_Construct(CSbEncInStream *p, ISzAlloc *alloc)
+{
+ SbEnc_Construct(&p->enc, alloc);
+ p->p.Read = SbEncInStream_Read;
+}
+
+SRes SbEncInStream_Init(CSbEncInStream *p)
+{
+ return SbEnc_Init(&p->enc);
+}
+
+void SbEncInStream_Free(CSbEncInStream *p)
+{
+ SbEnc_Free(&p->enc);
+}
+
#endif
+
typedef struct
{
- /* CMixCoderSeqInStream inStream; */
CLzma2EncHandle lzma2;
#ifdef USE_SUBBLOCK
CSbEncInStream sb;
#endif
+ CSeqInFilter filter;
ISzAlloc *alloc;
ISzAlloc *bigAlloc;
} CLzma2WithFilters;
@@ -361,9 +352,9 @@ static void Lzma2WithFilters_Construct(CLzma2WithFilters *p, ISzAlloc *alloc, IS
p->bigAlloc = bigAlloc;
p->lzma2 = NULL;
#ifdef USE_SUBBLOCK
- p->sb.p.Read = SbEncInStream_Read;
- SubblockEnc_Construct(&p->sb.sb, p->alloc);
+ SbEncInStream_Construct(&p->sb, alloc);
#endif
+ SeqInFilter_Construct(&p->filter);
}
static SRes Lzma2WithFilters_Create(CLzma2WithFilters *p)
@@ -376,8 +367,9 @@ static SRes Lzma2WithFilters_Create(CLzma2WithFilters *p)
static void Lzma2WithFilters_Free(CLzma2WithFilters *p)
{
+ SeqInFilter_Free(&p->filter);
#ifdef USE_SUBBLOCK
- SubblockEnc_Free(&p->sb.sb);
+ SbEncInStream_Free(&p->sb);
#endif
if (p->lzma2)
{
@@ -386,17 +378,28 @@ static void Lzma2WithFilters_Free(CLzma2WithFilters *p)
}
}
-static SRes Xz_Compress(CXzStream *xz,
- CLzma2WithFilters *lzmaf,
- ISeqOutStream *outStream,
- ISeqInStream *inStream,
- const CLzma2EncProps *lzma2Props,
- Bool useSubblock,
- ICompressProgress *progress)
+void XzProps_Init(CXzProps *p)
{
- xz->flags = XZ_CHECK_CRC32;
+ p->lzma2Props = 0;
+ p->filterProps = 0;
+ p->checkId = XZ_CHECK_CRC32;
+}
- RINOK(Lzma2Enc_SetProps(lzmaf->lzma2, lzma2Props));
+void XzFilterProps_Init(CXzFilterProps *p)
+{
+ p->id = 0;
+ p->delta = 0;
+ p->ip= 0;
+ p->ipDefined = False;
+}
+
+static SRes Xz_Compress(CXzStream *xz, CLzma2WithFilters *lzmaf,
+ ISeqOutStream *outStream, ISeqInStream *inStream,
+ const CXzProps *props, ICompressProgress *progress)
+{
+ xz->flags = (Byte)props->checkId;
+
+ RINOK(Lzma2Enc_SetProps(lzmaf->lzma2, props->lzma2Props));
RINOK(Xz_WriteHeader(xz->flags, outStream));
{
@@ -404,15 +407,27 @@ static SRes Xz_Compress(CXzStream *xz,
CSeqSizeOutStream seqSizeOutStream;
CXzBlock block;
int filterIndex = 0;
+ CXzFilter *filter = NULL;
+ const CXzFilterProps *fp = props->filterProps;
XzBlock_ClearFlags(&block);
- XzBlock_SetNumFilters(&block, 1 + (useSubblock ? 1 : 0));
+ XzBlock_SetNumFilters(&block, 1 + (fp ? 1 : 0));
- if (useSubblock)
+ if (fp)
{
- CXzFilter *f = &block.filters[filterIndex++];
- f->id = XZ_ID_Subblock;
- f->propsSize = 0;
+ filter = &block.filters[filterIndex++];
+ filter->id = fp->id;
+ filter->propsSize = 0;
+ if (fp->id == XZ_ID_Delta)
+ {
+ filter->props[0] = (Byte)(fp->delta - 1);
+ filter->propsSize = 1;
+ }
+ else if (fp->ipDefined)
+ {
+ SetUi32(filter->props, fp->ip);
+ filter->propsSize = 4;
+ }
}
{
@@ -432,20 +447,30 @@ static SRes Xz_Compress(CXzStream *xz,
checkInStream.realStream = inStream;
SeqCheckInStream_Init(&checkInStream, XzFlags_GetCheckType(xz->flags));
- #ifdef USE_SUBBLOCK
- if (useSubblock)
+ if (fp)
{
- lzmaf->sb.sb.inStream = &checkInStream.p;
- SubblockEnc_Init(&lzmaf->sb.sb);
+ #ifdef USE_SUBBLOCK
+ if (fp->id == XZ_ID_Subblock)
+ {
+ lzmaf->sb.inStream = &checkInStream.p;
+ RINOK(SbEncInStream_Init(&lzmaf->sb));
+ }
+ else
+ #endif
+ {
+ lzmaf->filter.realStream = &checkInStream.p;
+ RINOK(SeqInFilter_Init(&lzmaf->filter, filter));
+ }
}
- #endif
-
+
{
UInt64 packPos = seqSizeOutStream.processed;
SRes res = Lzma2Enc_Encode(lzmaf->lzma2, &seqSizeOutStream.p,
+ fp ?
#ifdef USE_SUBBLOCK
- useSubblock ? &lzmaf->sb.p:
+ (fp->id == XZ_ID_Subblock) ? &lzmaf->sb.p:
#endif
+ &lzmaf->filter.p:
&checkInStream.p,
progress);
RINOK(res);
@@ -467,8 +492,7 @@ static SRes Xz_Compress(CXzStream *xz,
}
SRes Xz_Encode(ISeqOutStream *outStream, ISeqInStream *inStream,
- const CLzma2EncProps *lzma2Props, Bool useSubblock,
- ICompressProgress *progress)
+ const CXzProps *props, ICompressProgress *progress)
{
SRes res;
CXzStream xz;
@@ -477,8 +501,7 @@ SRes Xz_Encode(ISeqOutStream *outStream, ISeqInStream *inStream,
Lzma2WithFilters_Construct(&lzmaf, &g_Alloc, &g_BigAlloc);
res = Lzma2WithFilters_Create(&lzmaf);
if (res == SZ_OK)
- res = Xz_Compress(&xz, &lzmaf, outStream, inStream,
- lzma2Props, useSubblock, progress);
+ res = Xz_Compress(&xz, &lzmaf, outStream, inStream, props, progress);
Lzma2WithFilters_Free(&lzmaf);
Xz_Free(&xz, &g_Alloc);
return res;
diff --git a/ext/VFS/ext/7z/src/XzEnc.h b/ext/VFS/ext/7z/src/XzEnc.h
index aad9aa4e..e9cea34f 100644
--- a/ext/VFS/ext/7z/src/XzEnc.h
+++ b/ext/VFS/ext/7z/src/XzEnc.h
@@ -1,5 +1,5 @@
/* XzEnc.h -- Xz Encode
-2009-04-15 : Igor Pavlov : Public domain */
+2011-02-07 : Igor Pavlov : Public domain */
#ifndef __XZ_ENC_H
#define __XZ_ENC_H
@@ -8,18 +8,32 @@
#include "Xz.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
+EXTERN_C_BEGIN
+
+typedef struct
+{
+ UInt32 id;
+ UInt32 delta;
+ UInt32 ip;
+ int ipDefined;
+} CXzFilterProps;
+
+void XzFilterProps_Init(CXzFilterProps *p);
+
+typedef struct
+{
+ const CLzma2EncProps *lzma2Props;
+ const CXzFilterProps *filterProps;
+ unsigned checkId;
+} CXzProps;
+
+void XzProps_Init(CXzProps *p);
SRes Xz_Encode(ISeqOutStream *outStream, ISeqInStream *inStream,
- const CLzma2EncProps *lzma2Props, Bool useSubblock,
- ICompressProgress *progress);
+ const CXzProps *props, ICompressProgress *progress);
SRes Xz_EncodeEmpty(ISeqOutStream *outStream);
-#ifdef __cplusplus
-}
-#endif
+EXTERN_C_END
#endif
diff --git a/ext/VFS/ext/7z/src/XzIn.c b/ext/VFS/ext/7z/src/XzIn.c
index 356d0193..13d3f851 100644
--- a/ext/VFS/ext/7z/src/XzIn.c
+++ b/ext/VFS/ext/7z/src/XzIn.c
@@ -1,5 +1,5 @@
/* XzIn.c - Xz input
-2009-06-19 : Igor Pavlov : Public domain */
+2011-02-01 : Igor Pavlov : Public domain */
#include
@@ -152,39 +152,38 @@ static SRes Xz_ReadBackward(CXzStream *p, ILookInStream *stream, Int64 *startOff
if (memcmp(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE) != 0)
{
- Int64 i = 0;
+ UInt32 total = 0;
*startOffset += XZ_STREAM_FOOTER_SIZE;
for (;;)
{
- int j;
- size_t processedSize;
+ size_t i;
#define TEMP_BUF_SIZE (1 << 10)
Byte tempBuf[TEMP_BUF_SIZE];
- if (*startOffset < XZ_STREAM_FOOTER_SIZE || i > (1 << 16))
+ if (*startOffset < XZ_STREAM_FOOTER_SIZE || total > (1 << 16))
return SZ_ERROR_NO_ARCHIVE;
- processedSize = (*startOffset > TEMP_BUF_SIZE) ? TEMP_BUF_SIZE : (size_t)*startOffset;
- i += processedSize;
- *startOffset = -(Int64)processedSize;
+ i = (*startOffset > TEMP_BUF_SIZE) ? TEMP_BUF_SIZE : (size_t)*startOffset;
+ total += (UInt32)i;
+ *startOffset = -(Int64)i;
RINOK(SeekFromCur(stream, startOffset));
- RINOK(LookInStream_Read2(stream, tempBuf, processedSize, SZ_ERROR_NO_ARCHIVE));
- for (j = (int)processedSize; j >= 0; j--)
- if (tempBuf[j -1] != 0)
+ RINOK(LookInStream_Read2(stream, tempBuf, i, SZ_ERROR_NO_ARCHIVE));
+ for (; i != 0; i--)
+ if (tempBuf[i - 1] != 0)
break;
- if (j != 0)
+ if (i != 0)
{
- if ((j & 3) != 0)
- return SZ_ERROR_NO_ARCHIVE;
- *startOffset += j;
- if (*startOffset < XZ_STREAM_FOOTER_SIZE)
- return SZ_ERROR_NO_ARCHIVE;
- *startOffset -= XZ_STREAM_FOOTER_SIZE;
- RINOK(stream->Seek(stream, startOffset, SZ_SEEK_SET));
- RINOK(LookInStream_Read2(stream, buf, XZ_STREAM_FOOTER_SIZE, SZ_ERROR_NO_ARCHIVE));
- if (memcmp(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE) != 0)
+ if ((i & 3) != 0)
return SZ_ERROR_NO_ARCHIVE;
+ *startOffset += i;
break;
}
}
+ if (*startOffset < XZ_STREAM_FOOTER_SIZE)
+ return SZ_ERROR_NO_ARCHIVE;
+ *startOffset -= XZ_STREAM_FOOTER_SIZE;
+ RINOK(stream->Seek(stream, startOffset, SZ_SEEK_SET));
+ RINOK(LookInStream_Read2(stream, buf, XZ_STREAM_FOOTER_SIZE, SZ_ERROR_NO_ARCHIVE));
+ if (memcmp(buf + 10, XZ_FOOTER_SIG, XZ_FOOTER_SIG_SIZE) != 0)
+ return SZ_ERROR_NO_ARCHIVE;
}
p->flags = (CXzStreamFlags)GetBe16(buf + 8);
diff --git a/ext/versions.txt b/ext/versions.txt
index cbcba1ed..f8862aef 100644
--- a/ext/versions.txt
+++ b/ext/versions.txt
@@ -1,4 +1,4 @@
-7z(lzma) : 4.65
+7z(lzma) : 9.22
utfcpp : 2.3.4
libpng : 1.2.50
zlib : 1.2.8