Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/C
diff options
context:
space:
mode:
authorIgor Pavlov <ipavlov@users.sourceforge.net>2008-08-13 04:00:00 +0400
committerKornel LesiƄski <kornel@geekhood.net>2016-05-28 02:15:56 +0300
commit173c07e166fdf6fcd20f18ea73008f1b628945df (patch)
tree13ebea85cdc4c16ae93714ff0627ee9f91ad7e08 /C
parent3901bf0ab88106a5b031cba7bc18d60cdebf7eef (diff)
4.59 beta
Diffstat (limited to 'C')
-rwxr-xr-xC/7zCrc.c4
-rwxr-xr-xC/Aes.c14
-rwxr-xr-xC/Aes.h8
-rwxr-xr-xC/Alloc.c4
-rwxr-xr-xC/Archive/7z/7zDecode.c24
-rwxr-xr-xC/Archive/7z/7zExtract.c38
-rwxr-xr-xC/Archive/7z/7zExtract.h16
-rwxr-xr-xC/Archive/7z/7zHeader.h17
-rwxr-xr-xC/Archive/7z/7zIn.c226
-rwxr-xr-xC/Archive/7z/7zIn.h6
-rwxr-xr-xC/Archive/7z/7zItem.c24
-rwxr-xr-xC/Archive/7z/7zItem.h37
-rwxr-xr-xC/Archive/7z/7zMain.c56
-rwxr-xr-xC/Archive/7z/makefile.gcc2
-rwxr-xr-xC/Bcj2.c24
-rwxr-xr-xC/Bcj2.h12
-rwxr-xr-xC/Bra.c10
-rwxr-xr-xC/Bra.h14
-rwxr-xr-xC/BraIA64.c8
-rwxr-xr-xC/BwtSort.c20
-rwxr-xr-xC/CpuArch.h43
-rwxr-xr-xC/HuffEnc.c32
-rwxr-xr-xC/LzFind.c44
-rwxr-xr-xC/LzFind.h16
-rwxr-xr-xC/LzFindMt.c94
-rwxr-xr-xC/LzFindMt.h4
-rwxr-xr-xC/LzmaDec.c90
-rwxr-xr-xC/LzmaDec.h58
-rwxr-xr-xC/LzmaEnc.c499
-rwxr-xr-xC/LzmaEnc.h20
-rwxr-xr-xC/LzmaLib.c12
-rwxr-xr-xC/LzmaLib.h58
-rwxr-xr-xC/LzmaLib/makefile2
-rwxr-xr-xC/LzmaUtil/Lzma86Dec.h14
-rwxr-xr-xC/LzmaUtil/Lzma86Enc.c16
-rwxr-xr-xC/LzmaUtil/Lzma86Enc.h20
-rwxr-xr-xC/LzmaUtil/LzmaUtil.c10
-rwxr-xr-xC/LzmaUtil/makefile.gcc2
-rwxr-xr-xC/RotateDefs.h6
-rwxr-xr-xC/Sha256.c6
-rwxr-xr-xC/Sha256.h4
-rwxr-xr-xC/Sort.c2
-rwxr-xr-xC/Threads.c28
-rwxr-xr-xC/Types.h6
44 files changed, 796 insertions, 854 deletions
diff --git a/C/7zCrc.c b/C/7zCrc.c
index acc309a4..71962b2c 100755
--- a/C/7zCrc.c
+++ b/C/7zCrc.c
@@ -1,5 +1,5 @@
/* 7zCrc.c -- CRC32 calculation
-2008-03-13
+2008-08-05
Igor Pavlov
Public domain */
@@ -24,7 +24,7 @@ void MY_FAST_CALL CrcGenerateTable(void)
UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)
{
const Byte *p = (const Byte *)data;
- for (; size > 0 ; size--, p++)
+ for (; size > 0 ; size--, p++)
v = CRC_UPDATE_BYTE(v, *p);
return v;
}
diff --git a/C/Aes.c b/C/Aes.c
index 6e2b7bf0..5feb9fc3 100755
--- a/C/Aes.c
+++ b/C/Aes.c
@@ -1,5 +1,5 @@
/* Aes.c -- AES encryption / decryption
-2008-03-26
+2008-08-05
Igor Pavlov
Public domain */
@@ -7,7 +7,7 @@ Public domain */
#include "CpuArch.h"
static UInt32 T[256 * 4];
-static Byte Sbox[256] = {
+static Byte Sbox[256] = {
0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76,
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0,
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
@@ -114,16 +114,16 @@ void Aes_SetKeyEncode(CAes *p, const Byte *key, unsigned keySize)
wSize = (p->numRounds2 * 2 + 1) * 4;
w = p->rkey;
- for (i = 0; i < keySize; i++, key += 4)
+ for (i = 0; i < keySize; i++, key += 4)
w[i] = Ui32(key[0], key[1], key[2], key[3]);
- for (; i < wSize; i++)
+ for (; i < wSize; i++)
{
UInt32 t = w[i - 1];
unsigned rem = i % keySize;
- if (rem == 0)
+ if (rem == 0)
t = Ui32(Sbox[gb1(t)] ^ Rcon[i / keySize], Sbox[gb2(t)], Sbox[gb3(t)], Sbox[gb0(t)]);
- else if (keySize > 6 && rem == 4)
+ else if (keySize > 6 && rem == 4)
t = Ui32(Sbox[gb0(t)], Sbox[gb1(t)], Sbox[gb2(t)], Sbox[gb3(t)]);
w[i] = w[i - keySize] ^ t;
}
@@ -139,7 +139,7 @@ void Aes_SetKeyDecode(CAes *p, const Byte *key, unsigned keySize)
for (i = 0; i < num; i++)
{
UInt32 r = w[i];
- w[i] =
+ w[i] =
D[ Sbox[gb0(r)]] ^
D[0x100 + Sbox[gb1(r)]] ^
D[0x200 + Sbox[gb2(r)]] ^
diff --git a/C/Aes.h b/C/Aes.h
index d5779788..ede4064a 100755
--- a/C/Aes.h
+++ b/C/Aes.h
@@ -1,5 +1,5 @@
/* Aes.h -- AES encryption / decryption
-2008-03-26
+2008-08-05
Igor Pavlov
Public domain */
@@ -20,7 +20,7 @@ typedef struct
void AesGenTables(void);
/* keySize = 16 or 24 or 32 (bytes) */
-void Aes_SetKeyEncode(CAes *p, const Byte *key, unsigned keySize);
+void Aes_SetKeyEncode(CAes *p, const Byte *key, unsigned keySize);
void Aes_SetKeyDecode(CAes *p, const Byte *key, unsigned keySize);
/* Aes_Encode32 and Aes_Decode32 functions work with little-endian words.
@@ -39,8 +39,8 @@ void AesCbc_Init(CAesCbc *p, const Byte *iv); /* iv size is AES_BLOCK_SIZE */
/* AesCbc_Encode and AesCbc_Decode:
if (res <= size): Filter have converted res bytes
- if (res > size): Filter have not converted anything. And it needs at
- least res = AES_BLOCK_SIZE bytes to convert one block */
+ if (res > size): Filter have not converted anything. And it needs at
+ least res = AES_BLOCK_SIZE bytes to convert one block */
SizeT AesCbc_Encode(CAesCbc *p, Byte *data, SizeT size);
SizeT AesCbc_Decode(CAesCbc *p, Byte *data, SizeT size);
diff --git a/C/Alloc.c b/C/Alloc.c
index c8418047..63b7da0c 100755
--- a/C/Alloc.c
+++ b/C/Alloc.c
@@ -1,5 +1,5 @@
/* Alloc.c -- Memory allocation functions
-2008-03-13
+2008-08-05
Igor Pavlov
Public domain */
@@ -98,7 +98,7 @@ void *BigAlloc(size_t size)
#ifdef _7ZIP_LARGE_PAGES
if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))
{
- void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),
+ void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),
MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
if (res != 0)
return res;
diff --git a/C/Archive/7z/7zDecode.c b/C/Archive/7z/7zDecode.c
index 02a3c008..aad7daf8 100755
--- a/C/Archive/7z/7zDecode.c
+++ b/C/Archive/7z/7zDecode.c
@@ -1,5 +1,5 @@
/* 7zDecode.c Decoding from 7z folder
-2008-04-09
+2008-08-05
Igor Pavlov
Copyright (c) 1999-2008 Igor Pavlov
Read 7zDecode.h for license options */
@@ -60,13 +60,13 @@ static SRes SzDecodeLzma(CSzCoderInfo *coder, CFileSize inSize, ISzInStream *inS
if (state.dicPos == state.dicBufSize || (inProcessed == 0 && dicPos == state.dicPos))
{
if (state.dicBufSize != outSize || _inSize != 0 ||
- (status != LZMA_STATUS_FINISHED_WITH_MARK &&
+ (status != LZMA_STATUS_FINISHED_WITH_MARK &&
status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK))
res = SZ_ERROR_DATA;
break;
}
}
- }
+ }
LzmaDec_FreeProbs(&state, allocMain);
@@ -126,7 +126,7 @@ SRes CheckSupportedFolder(const CSzFolder *f)
IS_UNSUPPORTED_CODER(f->Coders[2]) ||
IS_NO_BCJ2(f->Coders[3]))
return SZ_ERROR_UNSUPPORTED;
- if (f->NumPackStreams != 4 ||
+ if (f->NumPackStreams != 4 ||
f->PackStreams[0] != 2 ||
f->PackStreams[1] != 6 ||
f->PackStreams[2] != 1 ||
@@ -184,7 +184,7 @@ SRes SzDecode2(const CFileSize *packSizes, const CSzFolder *folder,
if (folder->NumCoders == 4)
{
UInt32 indices[] = { 3, 2, 0 };
- CFileSize unpackSize = folder->UnPackSizes[ci];
+ CFileSize unpackSize = folder->UnpackSizes[ci];
si = indices[ci];
if (ci < 2)
{
@@ -287,22 +287,22 @@ SRes SzDecode2(const CFileSize *packSizes, const CSzFolder *folder,
*/
res = Bcj2_Decode(
- tempBuf3, tempSize3,
- tempBuf[0], tempSizes[0],
- tempBuf[1], tempSizes[1],
+ tempBuf3, tempSize3,
+ tempBuf[0], tempSizes[0],
+ tempBuf[1], tempSizes[1],
/*
#ifdef _LZMA_IN_CB
*/
- tempBuf[2], tempSizes[2],
- /*
+ tempBuf[2], tempSizes[2],
+ /*
#else
- inBuffer + (size_t)offset, (size_t)s3Size,
+ inBuffer + (size_t)offset, (size_t)s3Size,
#endif
*/
outBuffer, outSize);
RINOK(res)
}
- else
+ else
return SZ_ERROR_UNSUPPORTED;
}
return SZ_OK;
diff --git a/C/Archive/7z/7zExtract.c b/C/Archive/7z/7zExtract.c
index 40b592aa..da5b57c7 100755
--- a/C/Archive/7z/7zExtract.c
+++ b/C/Archive/7z/7zExtract.c
@@ -1,5 +1,5 @@
/* 7zExtract.c -- Extracting from 7z archive
-2008-04-09
+2008-08-05
Igor Pavlov
Copyright (c) 1999-2008 Igor Pavlov
Read 7zExtract.h for license options */
@@ -10,13 +10,13 @@ Read 7zExtract.h for license options */
SRes SzAr_Extract(
const CSzArEx *p,
- ISzInStream *inStream,
+ ISzInStream *inStream,
UInt32 fileIndex,
UInt32 *blockIndex,
- Byte **outBuffer,
+ Byte **outBuffer,
size_t *outBufferSize,
- size_t *offset,
- size_t *outSizeProcessed,
+ size_t *offset,
+ size_t *outSizeProcessed,
ISzAlloc *allocMain,
ISzAlloc *allocTemp)
{
@@ -36,11 +36,11 @@ SRes SzAr_Extract(
if (*outBuffer == 0 || *blockIndex != folderIndex)
{
CSzFolder *folder = p->db.Folders + folderIndex;
- CFileSize unPackSizeSpec = SzFolder_GetUnPackSize(folder);
- size_t unPackSize = (size_t)unPackSizeSpec;
+ CFileSize unpackSizeSpec = SzFolder_GetUnpackSize(folder);
+ size_t unpackSize = (size_t)unpackSizeSpec;
CFileSize startOffset = SzArEx_GetFolderStreamPos(p, folderIndex, 0);
- if (unPackSize != unPackSizeSpec)
+ if (unpackSize != unpackSizeSpec)
return SZ_ERROR_MEM;
*blockIndex = folderIndex;
IAlloc_Free(allocMain, *outBuffer);
@@ -50,24 +50,24 @@ SRes SzAr_Extract(
if (res == SZ_OK)
{
- *outBufferSize = unPackSize;
- if (unPackSize != 0)
+ *outBufferSize = unpackSize;
+ if (unpackSize != 0)
{
- *outBuffer = (Byte *)IAlloc_Alloc(allocMain, unPackSize);
+ *outBuffer = (Byte *)IAlloc_Alloc(allocMain, unpackSize);
if (*outBuffer == 0)
res = SZ_ERROR_MEM;
}
if (res == SZ_OK)
{
- res = SzDecode(p->db.PackSizes +
- p->FolderStartPackStreamIndex[folderIndex], folder,
- inStream, startOffset,
- *outBuffer, unPackSize, allocTemp);
+ res = SzDecode(p->db.PackSizes +
+ p->FolderStartPackStreamIndex[folderIndex], folder,
+ inStream, startOffset,
+ *outBuffer, unpackSize, allocTemp);
if (res == SZ_OK)
{
- if (folder->UnPackCRCDefined)
+ if (folder->UnpackCRCDefined)
{
- if (CrcCalc(*outBuffer, unPackSize) != folder->UnPackCRC)
+ if (CrcCalc(*outBuffer, unpackSize) != folder->UnpackCRC)
res = SZ_ERROR_CRC;
}
}
@@ -76,7 +76,7 @@ SRes SzAr_Extract(
}
if (res == SZ_OK)
{
- UInt32 i;
+ UInt32 i;
CSzFileItem *fileItem = p->db.Files + fileIndex;
*offset = 0;
for(i = p->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)
@@ -85,7 +85,7 @@ SRes SzAr_Extract(
if (*offset + *outSizeProcessed > *outBufferSize)
return SZ_ERROR_FAIL;
{
- if (fileItem->IsFileCRCDefined)
+ if (fileItem->FileCRCDefined)
{
if (CrcCalc(*outBuffer + *offset, *outSizeProcessed) != fileItem->FileCRC)
res = SZ_ERROR_CRC;
diff --git a/C/Archive/7z/7zExtract.h b/C/Archive/7z/7zExtract.h
index cd0e4f03..4aa197a6 100755
--- a/C/Archive/7z/7zExtract.h
+++ b/C/Archive/7z/7zExtract.h
@@ -1,5 +1,5 @@
/* 7zExtract.h -- Extracting from 7z archive
-2008-04-09
+2008-08-05
Igor Pavlov
Copyright (c) 1999-2008 Igor Pavlov
Read 7zItem.h for license options */
@@ -12,18 +12,18 @@ Read 7zItem.h for license options */
/*
SzExtract extracts file from archive
- *outBuffer must be 0 before first call for each new archive.
+ *outBuffer must be 0 before first call for each new archive.
Extracting cache:
- If you need to decompress more than one file, you can send
+ If you need to decompress more than one file, you can send
these values from previous call:
- *blockIndex,
- *outBuffer,
+ *blockIndex,
+ *outBuffer,
*outBufferSize
- You can consider "*outBuffer" as cache of solid block. If your archive is solid,
+ You can consider "*outBuffer" as cache of solid block. If your archive is solid,
it will increase decompression speed.
- If you use external function, you can declare these 3 cache variables
+ If you use external function, you can declare these 3 cache variables
(blockIndex, outBuffer, outBufferSize) as static in that external function.
Free *outBuffer and set *outBuffer to 0, if you want to flush cache.
@@ -31,7 +31,7 @@ Read 7zItem.h for license options */
SRes SzAr_Extract(
const CSzArEx *db,
- ISzInStream *inStream,
+ ISzInStream *inStream,
UInt32 fileIndex, /* index of file */
UInt32 *blockIndex, /* index of solid block */
Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
diff --git a/C/Archive/7z/7zHeader.h b/C/Archive/7z/7zHeader.h
index 9cd3e3dc..325fe4c6 100755
--- a/C/Archive/7z/7zHeader.h
+++ b/C/Archive/7z/7zHeader.h
@@ -1,5 +1,5 @@
/* 7zHeader.h -- 7z Headers
-2008-03-17
+2008-07-14
Copyright (c) 1999-2008 Igor Pavlov
Read LzmaDec.h for license options */
@@ -28,7 +28,7 @@ enum EIdEnum
k7zIdFilesInfo,
k7zIdPackInfo,
- k7zIdUnPackInfo,
+ k7zIdUnpackInfo,
k7zIdSubStreamsInfo,
k7zIdSize,
@@ -36,23 +36,24 @@ enum EIdEnum
k7zIdFolder,
- k7zIdCodersUnPackSize,
- k7zIdNumUnPackStream,
+ k7zIdCodersUnpackSize,
+ k7zIdNumUnpackStream,
k7zIdEmptyStream,
k7zIdEmptyFile,
k7zIdAnti,
k7zIdName,
- k7zIdCreationTime,
- k7zIdLastAccessTime,
- k7zIdLastWriteTime,
+ k7zIdCTime,
+ k7zIdATime,
+ k7zIdMTime,
k7zIdWinAttributes,
k7zIdComment,
k7zIdEncodedHeader,
- k7zIdStartPos
+ k7zIdStartPos,
+ k7zIdDummy
};
#endif
diff --git a/C/Archive/7z/7zIn.c b/C/Archive/7z/7zIn.c
index b99a6ac7..9a4d6dd1 100755
--- a/C/Archive/7z/7zIn.c
+++ b/C/Archive/7z/7zIn.c
@@ -1,5 +1,5 @@
/* 7zIn.c -- 7z Input functions
-2008-04-09
+2008-08-05
Igor Pavlov
Copyright (c) 1999-2008 Igor Pavlov
Read 7zIn.h for license options */
@@ -30,7 +30,7 @@ void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc)
}
/*
-CFileSize GetFolderPackStreamSize(int folderIndex, int streamIndex) const
+CFileSize GetFolderPackStreamSize(int folderIndex, int streamIndex) const
{
return PackSizes[FolderStartPackStreamIndex[folderIndex] + streamIndex];
}
@@ -96,7 +96,7 @@ static SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)
if (folderIndex >= p->db.NumFolders)
return SZ_ERROR_ARCHIVE;
p->FolderStartFileIndex[folderIndex] = i;
- if (p->db.Folders[folderIndex].NumUnPackStreams != 0)
+ if (p->db.Folders[folderIndex].NumUnpackStreams != 0)
break;
folderIndex++;
}
@@ -105,7 +105,7 @@ static SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)
if (emptyStream)
continue;
indexInFolder++;
- if (indexInFolder >= p->db.Folders[folderIndex].NumUnPackStreams)
+ if (indexInFolder >= p->db.Folders[folderIndex].NumUnpackStreams)
{
folderIndex++;
indexInFolder = 0;
@@ -117,7 +117,7 @@ static SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)
CFileSize SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder)
{
- return p->ArchiveInfo.DataStartPosition +
+ return p->ArchiveInfo.DataStartPosition +
p->PackStreamStartPositions[p->FolderStartPackStreamIndex[folderIndex] + indexInFolder];
}
@@ -164,21 +164,9 @@ SRes SzReadTime(const CObjectVector<CBuf> &dataVector,
}
switch(type)
{
- case k7zIdCreationTime:
- file.IsCreationTimeDefined = defined;
- if (defined)
- file.CreationTime = fileTime;
- break;
- case k7zIdLastWriteTime:
- file.IsLastWriteTimeDefined = defined;
- if (defined)
- file.LastWriteTime = fileTime;
- break;
- case k7zIdLastAccessTime:
- file.IsLastAccessTimeDefined = defined;
- if (defined)
- file.LastAccessTime = fileTime;
- break;
+ case k7zIdCTime: file.IsCTimeDefined = defined; if (defined) file.CTime = fileTime; break;
+ case k7zIdATime: file.IsATimeDefined = defined; if (defined) file.ATime = fileTime; break;
+ case k7zIdMTime: file.IsMTimeDefined = defined; if (defined) file.MTime = fileTime; break;
}
}
return SZ_OK;
@@ -327,9 +315,9 @@ static SRes SzReadNumber32(CSzData *sd, UInt32 *value)
return SZ_OK;
}
-static SRes SzReadID(CSzData *sd, UInt64 *value)
-{
- return SzReadNumber(sd, value);
+static SRes SzReadID(CSzData *sd, UInt64 *value)
+{
+ return SzReadNumber(sd, value);
}
static SRes SzSkeepDataSize(CSzData *sd, UInt64 size)
@@ -408,10 +396,10 @@ static SRes SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, ISzAlloc *
}
static SRes SzReadHashDigests(
- CSzData *sd,
+ CSzData *sd,
size_t numItems,
- Byte **digestsDefined,
- UInt32 **digests,
+ Byte **digestsDefined,
+ UInt32 **digests,
ISzAlloc *alloc)
{
size_t i;
@@ -426,7 +414,7 @@ static SRes SzReadHashDigests(
}
static SRes SzReadPackInfo(
- CSzData *sd,
+ CSzData *sd,
CFileSize *dataOffset,
UInt32 *numPackStreams,
CFileSize **packSizes,
@@ -455,7 +443,7 @@ static SRes SzReadPackInfo(
break;
if (type == k7zIdCRC)
{
- RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, alloc));
+ RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, alloc));
continue;
}
RINOK(SzSkeepData(sd));
@@ -562,7 +550,7 @@ static SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)
{
CBindPair *bindPair = folder->BindPairs + i;;
RINOK(SzReadNumber32(sd, &bindPair->InIndex));
- RINOK(SzReadNumber32(sd, &bindPair->OutIndex));
+ RINOK(SzReadNumber32(sd, &bindPair->OutIndex));
}
numPackedStreams = numInStreams - (UInt32)numBindPairs;
@@ -589,8 +577,8 @@ static SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)
return SZ_OK;
}
-static SRes SzReadUnPackInfo(
- CSzData *sd,
+static SRes SzReadUnpackInfo(
+ CSzData *sd,
UInt32 *numFolders,
CSzFolder **folders, /* for alloc */
ISzAlloc *alloc,
@@ -613,7 +601,7 @@ static SRes SzReadUnPackInfo(
}
}
- RINOK(SzWaitAttribute(sd, k7zIdCodersUnPackSize));
+ RINOK(SzWaitAttribute(sd, k7zIdCodersUnpackSize));
for (i = 0; i < *numFolders; i++)
{
@@ -621,11 +609,11 @@ static SRes SzReadUnPackInfo(
CSzFolder *folder = (*folders) + i;
UInt32 numOutStreams = SzFolder_GetNumOutStreams(folder);
- MY_ALLOC(CFileSize, folder->UnPackSizes, (size_t)numOutStreams, alloc);
+ MY_ALLOC(CFileSize, folder->UnpackSizes, (size_t)numOutStreams, alloc);
for (j = 0; j < numOutStreams; j++)
{
- RINOK(SzReadSize(sd, folder->UnPackSizes + j));
+ RINOK(SzReadSize(sd, folder->UnpackSizes + j));
}
}
@@ -640,14 +628,14 @@ static SRes SzReadUnPackInfo(
SRes res;
Byte *crcsDefined = 0;
UInt32 *crcs = 0;
- res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp);
+ res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp);
if (res == SZ_OK)
{
for (i = 0; i < *numFolders; i++)
{
CSzFolder *folder = (*folders) + i;
- folder->UnPackCRCDefined = crcsDefined[i];
- folder->UnPackCRC = crcs[i];
+ folder->UnpackCRCDefined = crcsDefined[i];
+ folder->UnpackCRC = crcs[i];
}
}
IAlloc_Free(allocTemp, crcs);
@@ -660,11 +648,11 @@ static SRes SzReadUnPackInfo(
}
static SRes SzReadSubStreamsInfo(
- CSzData *sd,
+ CSzData *sd,
UInt32 numFolders,
CSzFolder *folders,
- UInt32 *numUnPackStreams,
- CFileSize **unPackSizes,
+ UInt32 *numUnpackStreams,
+ CFileSize **unpackSizes,
Byte **digestsDefined,
UInt32 **digests,
ISzAlloc *allocTemp)
@@ -675,21 +663,21 @@ static SRes SzReadSubStreamsInfo(
UInt32 numDigests = 0;
for (i = 0; i < numFolders; i++)
- folders[i].NumUnPackStreams = 1;
- *numUnPackStreams = numFolders;
+ folders[i].NumUnpackStreams = 1;
+ *numUnpackStreams = numFolders;
for (;;)
{
RINOK(SzReadID(sd, &type));
- if (type == k7zIdNumUnPackStream)
+ if (type == k7zIdNumUnpackStream)
{
- *numUnPackStreams = 0;
+ *numUnpackStreams = 0;
for (i = 0; i < numFolders; i++)
{
UInt32 numStreams;
RINOK(SzReadNumber32(sd, &numStreams));
- folders[i].NumUnPackStreams = numStreams;
- *numUnPackStreams += numStreams;
+ folders[i].NumUnpackStreams = numStreams;
+ *numUnpackStreams += numStreams;
}
continue;
}
@@ -700,19 +688,19 @@ static SRes SzReadSubStreamsInfo(
RINOK(SzSkeepData(sd));
}
- if (*numUnPackStreams == 0)
+ if (*numUnpackStreams == 0)
{
- *unPackSizes = 0;
+ *unpackSizes = 0;
*digestsDefined = 0;
*digests = 0;
}
else
{
- *unPackSizes = (CFileSize *)IAlloc_Alloc(allocTemp, (size_t)*numUnPackStreams * sizeof(CFileSize));
- RINOM(*unPackSizes);
- *digestsDefined = (Byte *)IAlloc_Alloc(allocTemp, (size_t)*numUnPackStreams * sizeof(Byte));
+ *unpackSizes = (CFileSize *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(CFileSize));
+ RINOM(*unpackSizes);
+ *digestsDefined = (Byte *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(Byte));
RINOM(*digestsDefined);
- *digests = (UInt32 *)IAlloc_Alloc(allocTemp, (size_t)*numUnPackStreams * sizeof(UInt32));
+ *digests = (UInt32 *)IAlloc_Alloc(allocTemp, (size_t)*numUnpackStreams * sizeof(UInt32));
RINOM(*digests);
}
@@ -724,7 +712,7 @@ static SRes SzReadSubStreamsInfo(
*/
CFileSize sum = 0;
UInt32 j;
- UInt32 numSubstreams = folders[i].NumUnPackStreams;
+ UInt32 numSubstreams = folders[i].NumUnpackStreams;
if (numSubstreams == 0)
continue;
if (type == k7zIdSize)
@@ -732,17 +720,17 @@ static SRes SzReadSubStreamsInfo(
{
CFileSize size;
RINOK(SzReadSize(sd, &size));
- (*unPackSizes)[si++] = size;
+ (*unpackSizes)[si++] = size;
sum += size;
}
- (*unPackSizes)[si++] = SzFolder_GetUnPackSize(folders + i) - sum;
+ (*unpackSizes)[si++] = SzFolder_GetUnpackSize(folders + i) - sum;
}
if (type == k7zIdSize)
{
RINOK(SzReadID(sd, &type));
}
- for (i = 0; i < *numUnPackStreams; i++)
+ for (i = 0; i < *numUnpackStreams; i++)
{
(*digestsDefined)[i] = 0;
(*digests)[i] = 0;
@@ -751,8 +739,8 @@ static SRes SzReadSubStreamsInfo(
for (i = 0; i < numFolders; i++)
{
- UInt32 numSubstreams = folders[i].NumUnPackStreams;
- if (numSubstreams != 1 || !folders[i].UnPackCRCDefined)
+ UInt32 numSubstreams = folders[i].NumUnpackStreams;
+ if (numSubstreams != 1 || !folders[i].UnpackCRCDefined)
numDigests += numSubstreams;
}
@@ -763,7 +751,7 @@ static SRes SzReadSubStreamsInfo(
if (type == k7zIdCRC)
{
int digestIndex = 0;
- Byte *digestsDefined2 = 0;
+ Byte *digestsDefined2 = 0;
UInt32 *digests2 = 0;
SRes res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp);
if (res == SZ_OK)
@@ -771,11 +759,11 @@ static SRes SzReadSubStreamsInfo(
for (i = 0; i < numFolders; i++)
{
CSzFolder *folder = folders + i;
- UInt32 numSubstreams = folder->NumUnPackStreams;
- if (numSubstreams == 1 && folder->UnPackCRCDefined)
+ UInt32 numSubstreams = folder->NumUnpackStreams;
+ if (numSubstreams == 1 && folder->UnpackCRCDefined)
{
(*digestsDefined)[si] = 1;
- (*digests)[si] = folder->UnPackCRC;
+ (*digests)[si] = folder->UnpackCRC;
si++;
}
else
@@ -806,11 +794,11 @@ static SRes SzReadSubStreamsInfo(
static SRes SzReadStreamsInfo(
- CSzData *sd,
+ CSzData *sd,
CFileSize *dataOffset,
CSzAr *p,
- UInt32 *numUnPackStreams,
- CFileSize **unPackSizes, /* allocTemp */
+ UInt32 *numUnpackStreams,
+ CFileSize **unpackSizes, /* allocTemp */
Byte **digestsDefined, /* allocTemp */
UInt32 **digests, /* allocTemp */
ISzAlloc *alloc,
@@ -828,19 +816,19 @@ static SRes SzReadStreamsInfo(
return SZ_OK;
case k7zIdPackInfo:
{
- RINOK(SzReadPackInfo(sd, dataOffset, &p->NumPackStreams,
+ RINOK(SzReadPackInfo(sd, dataOffset, &p->NumPackStreams,
&p->PackSizes, &p->PackCRCsDefined, &p->PackCRCs, alloc));
break;
}
- case k7zIdUnPackInfo:
+ case k7zIdUnpackInfo:
{
- RINOK(SzReadUnPackInfo(sd, &p->NumFolders, &p->Folders, alloc, allocTemp));
+ RINOK(SzReadUnpackInfo(sd, &p->NumFolders, &p->Folders, alloc, allocTemp));
break;
}
case k7zIdSubStreamsInfo:
{
- RINOK(SzReadSubStreamsInfo(sd, p->NumFolders, p->Folders,
- numUnPackStreams, unPackSizes, digestsDefined, digests, allocTemp));
+ RINOK(SzReadSubStreamsInfo(sd, p->NumFolders, p->Folders,
+ numUnpackStreams, unpackSizes, digestsDefined, digests, allocTemp));
break;
}
default:
@@ -928,18 +916,18 @@ static SRes SzReadFileNames(CSzData *sd, UInt32 numFiles, CSzFileItem *files, IS
static SRes SzReadHeader2(
CSzArEx *p, /* allocMain */
- CSzData *sd,
- CFileSize **unPackSizes, /* allocTemp */
+ CSzData *sd,
+ CFileSize **unpackSizes, /* allocTemp */
Byte **digestsDefined, /* allocTemp */
UInt32 **digests, /* allocTemp */
Byte **emptyStreamVector, /* allocTemp */
Byte **emptyFileVector, /* allocTemp */
Byte **lwtVector, /* allocTemp */
- ISzAlloc *allocMain,
+ ISzAlloc *allocMain,
ISzAlloc *allocTemp)
{
UInt64 type;
- UInt32 numUnPackStreams = 0;
+ UInt32 numUnpackStreams = 0;
UInt32 numFiles = 0;
CSzFileItem *files = 0;
UInt32 numEmptyStreams = 0;
@@ -958,9 +946,9 @@ static SRes SzReadHeader2(
{
RINOK(SzReadStreamsInfo(sd,
&p->ArchiveInfo.DataStartPosition,
- &p->db,
- &numUnPackStreams,
- unPackSizes,
+ &p->db,
+ &numUnpackStreams,
+ unpackSizes,
digestsDefined,
digests, allocMain, allocTemp));
p->ArchiveInfo.DataStartPosition += p->ArchiveInfo.StartPositionAfterHeader;
@@ -1017,7 +1005,7 @@ static SRes SzReadHeader2(
RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp));
break;
}
- case k7zIdLastWriteTime:
+ case k7zIdMTime:
{
RINOK(SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp));
RINOK(SzReadSwitch(sd));
@@ -1025,12 +1013,12 @@ static SRes SzReadHeader2(
{
CSzFileItem *f = &files[i];
Byte defined = (*lwtVector)[i];
- f->IsLastWriteTimeDefined = defined;
- f->LastWriteTime.Low = f->LastWriteTime.High = 0;
+ f->MTimeDefined = defined;
+ f->MTime.Low = f->MTime.High = 0;
if (defined)
{
- RINOK(SzReadUInt32(sd, &f->LastWriteTime.Low));
- RINOK(SzReadUInt32(sd, &f->LastWriteTime.High));
+ RINOK(SzReadUInt32(sd, &f->MTime.Low));
+ RINOK(SzReadUInt32(sd, &f->MTime.High));
}
}
break;
@@ -1055,21 +1043,21 @@ static SRes SzReadHeader2(
file->HasStream = (Byte)((*emptyStreamVector)[i] ? 0 : 1);
if(file->HasStream)
{
- file->IsDirectory = 0;
- file->Size = (*unPackSizes)[sizeIndex];
+ file->IsDir = 0;
+ file->Size = (*unpackSizes)[sizeIndex];
file->FileCRC = (*digests)[sizeIndex];
- file->IsFileCRCDefined = (Byte)(*digestsDefined)[sizeIndex];
+ file->FileCRCDefined = (Byte)(*digestsDefined)[sizeIndex];
sizeIndex++;
}
else
{
if (*emptyFileVector == 0)
- file->IsDirectory = 1;
+ file->IsDir = 1;
else
- file->IsDirectory = (Byte)((*emptyFileVector)[emptyFileIndex] ? 0 : 1);
+ file->IsDir = (Byte)((*emptyFileVector)[emptyFileIndex] ? 0 : 1);
emptyFileIndex++;
file->Size = 0;
- file->IsFileCRCDefined = 0;
+ file->FileCRCDefined = 0;
}
}
}
@@ -1077,50 +1065,50 @@ static SRes SzReadHeader2(
}
static SRes SzReadHeader(
- CSzArEx *p,
- CSzData *sd,
- ISzAlloc *allocMain,
+ CSzArEx *p,
+ CSzData *sd,
+ ISzAlloc *allocMain,
ISzAlloc *allocTemp)
{
- CFileSize *unPackSizes = 0;
+ CFileSize *unpackSizes = 0;
Byte *digestsDefined = 0;
UInt32 *digests = 0;
Byte *emptyStreamVector = 0;
Byte *emptyFileVector = 0;
Byte *lwtVector = 0;
SRes res = SzReadHeader2(p, sd,
- &unPackSizes, &digestsDefined, &digests,
- &emptyStreamVector, &emptyFileVector, &lwtVector,
+ &unpackSizes, &digestsDefined, &digests,
+ &emptyStreamVector, &emptyFileVector, &lwtVector,
allocMain, allocTemp);
- IAlloc_Free(allocTemp, unPackSizes);
+ IAlloc_Free(allocTemp, unpackSizes);
IAlloc_Free(allocTemp, digestsDefined);
IAlloc_Free(allocTemp, digests);
IAlloc_Free(allocTemp, emptyStreamVector);
IAlloc_Free(allocTemp, emptyFileVector);
IAlloc_Free(allocTemp, lwtVector);
return res;
-}
+}
static SRes SzReadAndDecodePackedStreams2(
- ISzInStream *inStream,
+ ISzInStream *inStream,
CSzData *sd,
CBuf *outBuffer,
- CFileSize baseOffset,
+ CFileSize baseOffset,
CSzAr *p,
- CFileSize **unPackSizes,
+ CFileSize **unpackSizes,
Byte **digestsDefined,
UInt32 **digests,
ISzAlloc *allocTemp)
{
- UInt32 numUnPackStreams = 0;
+ UInt32 numUnpackStreams = 0;
CFileSize dataStartPos;
CSzFolder *folder;
- CFileSize unPackSize;
+ CFileSize unpackSize;
SRes res;
RINOK(SzReadStreamsInfo(sd, &dataStartPos, p,
- &numUnPackStreams, unPackSizes, digestsDefined, digests,
+ &numUnpackStreams, unpackSizes, digestsDefined, digests,
allocTemp, allocTemp));
dataStartPos += baseOffset;
@@ -1128,41 +1116,41 @@ static SRes SzReadAndDecodePackedStreams2(
return SZ_ERROR_ARCHIVE;
folder = p->Folders;
- unPackSize = SzFolder_GetUnPackSize(folder);
+ unpackSize = SzFolder_GetUnpackSize(folder);
RINOK(inStream->Seek(inStream, dataStartPos, SZ_SEEK_SET));
- if (!Buf_Create(outBuffer, (size_t)unPackSize, allocTemp))
+ if (!Buf_Create(outBuffer, (size_t)unpackSize, allocTemp))
return SZ_ERROR_MEM;
- res = SzDecode(p->PackSizes, folder,
- inStream, dataStartPos,
- outBuffer->data, (size_t)unPackSize, allocTemp);
+ res = SzDecode(p->PackSizes, folder,
+ inStream, dataStartPos,
+ outBuffer->data, (size_t)unpackSize, allocTemp);
RINOK(res);
- if (folder->UnPackCRCDefined)
- if (CrcCalc(outBuffer->data, (size_t)unPackSize) != folder->UnPackCRC)
+ if (folder->UnpackCRCDefined)
+ if (CrcCalc(outBuffer->data, (size_t)unpackSize) != folder->UnpackCRC)
return SZ_ERROR_CRC;
return SZ_OK;
}
static SRes SzReadAndDecodePackedStreams(
- ISzInStream *inStream,
+ ISzInStream *inStream,
CSzData *sd,
CBuf *outBuffer,
- CFileSize baseOffset,
+ CFileSize baseOffset,
ISzAlloc *allocTemp)
{
CSzAr p;
- CFileSize *unPackSizes = 0;
+ CFileSize *unpackSizes = 0;
Byte *digestsDefined = 0;
UInt32 *digests = 0;
SRes res;
SzAr_Init(&p);
- res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset,
- &p, &unPackSizes, &digestsDefined, &digests,
+ res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset,
+ &p, &unpackSizes, &digestsDefined, &digests,
allocTemp);
SzAr_Free(&p, allocTemp);
- IAlloc_Free(allocTemp, unPackSizes);
+ IAlloc_Free(allocTemp, unpackSizes);
IAlloc_Free(allocTemp, digestsDefined);
IAlloc_Free(allocTemp, digests);
return res;
@@ -1170,8 +1158,8 @@ static SRes SzReadAndDecodePackedStreams(
static SRes SzArEx_Open2(
CSzArEx *p,
- ISzInStream *inStream,
- ISzAlloc *allocMain,
+ ISzInStream *inStream,
+ ISzAlloc *allocMain,
ISzAlloc *allocTemp)
{
Byte signature[k7zSignatureSize];
@@ -1249,8 +1237,8 @@ static SRes SzArEx_Open2(
{
CBuf outBuffer;
Buf_Init(&outBuffer);
- res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer,
- p->ArchiveInfo.StartPositionAfterHeader,
+ res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer,
+ p->ArchiveInfo.StartPositionAfterHeader,
allocTemp);
if (res != SZ_OK)
{
diff --git a/C/Archive/7z/7zIn.h b/C/Archive/7z/7zIn.h
index 811bbb66..ba8a84f9 100755
--- a/C/Archive/7z/7zIn.h
+++ b/C/Archive/7z/7zIn.h
@@ -1,5 +1,5 @@
/* 7zIn.h -- 7z Input functions
-2008-05-05
+2008-08-05
Igor Pavlov
Copyright (c) 1999-2008 Igor Pavlov
Read 7zItem.h for license options */
@@ -12,7 +12,7 @@ Read 7zItem.h for license options */
typedef struct
{
- CFileSize StartPositionAfterHeader;
+ CFileSize StartPositionAfterHeader;
CFileSize DataStartPosition;
} CInArchiveInfo;
@@ -31,7 +31,7 @@ void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);
CFileSize SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);
int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, CFileSize *resSize);
-typedef enum
+typedef enum
{
SZ_SEEK_SET = 0,
SZ_SEEK_CUR = 1,
diff --git a/C/Archive/7z/7zItem.c b/C/Archive/7z/7zItem.c
index 7a5ad427..2ebcf64c 100755
--- a/C/Archive/7z/7zItem.c
+++ b/C/Archive/7z/7zItem.c
@@ -1,5 +1,5 @@
/* 7zItem.c -- 7z Items
-2008-04-09
+2008-08-05
Igor Pavlov
Copyright (c) 1999-2008 Igor Pavlov
Read 7zItem.h for license options */
@@ -22,13 +22,13 @@ void SzFolder_Init(CSzFolder *p)
p->Coders = 0;
p->BindPairs = 0;
p->PackStreams = 0;
- p->UnPackSizes = 0;
+ p->UnpackSizes = 0;
p->NumCoders = 0;
p->NumBindPairs = 0;
p->NumPackStreams = 0;
- p->UnPackCRCDefined = 0;
- p->UnPackCRC = 0;
- p->NumUnPackStreams = 0;
+ p->UnpackCRCDefined = 0;
+ p->UnpackCRC = 0;
+ p->NumUnpackStreams = 0;
}
void SzFolder_Free(CSzFolder *p, ISzAlloc *alloc)
@@ -40,7 +40,7 @@ void SzFolder_Free(CSzFolder *p, ISzAlloc *alloc)
IAlloc_Free(alloc, p->Coders);
IAlloc_Free(alloc, p->BindPairs);
IAlloc_Free(alloc, p->PackStreams);
- IAlloc_Free(alloc, p->UnPackSizes);
+ IAlloc_Free(alloc, p->UnpackSizes);
SzFolder_Init(p);
}
@@ -72,25 +72,25 @@ int SzFolder_FindBindPairForOutStream(CSzFolder *p, UInt32 outStreamIndex)
return -1;
}
-CFileSize SzFolder_GetUnPackSize(CSzFolder *p)
-{
+CFileSize SzFolder_GetUnpackSize(CSzFolder *p)
+{
int i = (int)SzFolder_GetNumOutStreams(p);
if (i == 0)
return 0;
for (i--; i >= 0; i--)
if (SzFolder_FindBindPairForOutStream(p, i) < 0)
- return p->UnPackSizes[i];
+ return p->UnpackSizes[i];
/* throw 1; */
return 0;
}
void SzFile_Init(CSzFileItem *p)
{
- p->IsFileCRCDefined = 0;
p->HasStream = 1;
- p->IsDirectory = 0;
+ p->IsDir = 0;
p->IsAnti = 0;
- p->IsLastWriteTimeDefined = 0;
+ p->FileCRCDefined = 0;
+ p->MTimeDefined = 0;
p->Name = 0;
}
diff --git a/C/Archive/7z/7zItem.h b/C/Archive/7z/7zItem.h
index 074a3a99..ede1a8c3 100755
--- a/C/Archive/7z/7zItem.h
+++ b/C/Archive/7z/7zItem.h
@@ -1,5 +1,5 @@
/* 7zItem.h -- 7z Items
-2008-05-01
+2008-07-09
Igor Pavlov
Copyright (c) 1999-2008 Igor Pavlov
Read LzmaDec.h for license options */
@@ -13,9 +13,9 @@ Read LzmaDec.h for license options */
/* You can define _SZ_FILE_SIZE_32, if you don't need support for files larger than 4 GB*/
#ifdef _SZ_FILE_SIZE_32
-typedef UInt32 CFileSize;
+typedef UInt32 CFileSize;
#else
-typedef UInt64 CFileSize;
+typedef UInt64 CFileSize;
#endif
typedef UInt64 CMethodID;
@@ -42,21 +42,21 @@ typedef struct
CSzCoderInfo *Coders;
CBindPair *BindPairs;
UInt32 *PackStreams;
- CFileSize *UnPackSizes;
+ CFileSize *UnpackSizes;
UInt32 NumCoders;
UInt32 NumBindPairs;
- UInt32 NumPackStreams;
- int UnPackCRCDefined;
- UInt32 UnPackCRC;
+ UInt32 NumPackStreams;
+ int UnpackCRCDefined;
+ UInt32 UnpackCRC;
- UInt32 NumUnPackStreams;
+ UInt32 NumUnpackStreams;
} CSzFolder;
void SzFolder_Init(CSzFolder *p);
-CFileSize SzFolder_GetUnPackSize(CSzFolder *p);
+CFileSize SzFolder_GetUnpackSize(CSzFolder *p);
int SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex);
UInt32 SzFolder_GetNumOutStreams(CSzFolder *p);
-CFileSize SzFolder_GetUnPackSize(CSzFolder *p);
+CFileSize SzFolder_GetUnpackSize(CSzFolder *p);
typedef struct
{
@@ -66,25 +66,16 @@ typedef struct
typedef struct
{
- CNtfsFileTime LastWriteTime;
- /*
- CFileSize StartPos;
- UInt32 Attributes;
- */
+ CNtfsFileTime MTime;
CFileSize Size;
char *Name;
UInt32 FileCRC;
- Byte IsFileCRCDefined;
Byte HasStream;
- Byte IsDirectory;
+ Byte IsDir;
Byte IsAnti;
- Byte IsLastWriteTimeDefined;
- /*
- int AreAttributesDefined;
- int IsLastWriteTimeDefined;
- int IsStartPosDefined;
- */
+ Byte FileCRCDefined;
+ Byte MTimeDefined;
} CSzFileItem;
void SzFile_Init(CSzFileItem *p);
diff --git a/C/Archive/7z/7zMain.c b/C/Archive/7z/7zMain.c
index 62f50689..082a2ebd 100755
--- a/C/Archive/7z/7zMain.c
+++ b/C/Archive/7z/7zMain.c
@@ -1,5 +1,5 @@
/* 7zMain.c - Test application for 7z Decoder
-2008-04-09
+2008-08-05
Igor Pavlov
Public domain */
@@ -32,7 +32,7 @@ void ConvertNumberToString(CFileSize value, char *s)
{
char temp[32];
int pos = 0;
- do
+ do
{
temp[pos++] = (char)('0' + (int)(value % 10));
value /= 10;
@@ -54,7 +54,7 @@ void ConvertFileTimeToString(CNtfsFileTime *ft, char *s)
UInt64 v64 = ft->Low | ((UInt64)ft->High << 32);
Byte ms[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
unsigned temp;
- UInt32 v;
+ UInt32 v;
v64 /= 10000000;
sec = (unsigned)(v64 % 60);
v64 /= 60;
@@ -103,15 +103,15 @@ void ConvertFileTimeToString(CNtfsFileTime *ft, char *s)
#ifdef USE_WINDOWS_FUNCTIONS
/*
ReadFile and WriteFile functions in Windows have BUG:
- If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
- from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
+ If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
+ from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
(Insufficient system resources exist to complete the requested service).
*/
#define kChunkSizeMax (1 << 24)
#endif
size_t MyReadFile(MY_FILE_HANDLE file, void *data, size_t size)
-{
+{
if (size == 0)
return 0;
#ifdef USE_WINDOWS_FUNCTIONS
@@ -132,12 +132,12 @@ size_t MyReadFile(MY_FILE_HANDLE file, void *data, size_t size)
return processedSize;
}
#else
- return fread(data, 1, size, file);
+ return fread(data, 1, size, file);
#endif
}
size_t MyWriteFile(MY_FILE_HANDLE file, void *data, size_t size)
-{
+{
if (size == 0)
return 0;
#ifdef USE_WINDOWS_FUNCTIONS
@@ -158,16 +158,16 @@ size_t MyWriteFile(MY_FILE_HANDLE file, void *data, size_t size)
return processedSize;
}
#else
- return fwrite(data, 1, size, file);
+ return fwrite(data, 1, size, file);
#endif
}
int MyCloseFile(MY_FILE_HANDLE file)
-{
+{
#ifdef USE_WINDOWS_FUNCTIONS
return (CloseHandle(file) != FALSE) ? 0 : 1;
#else
- return fclose(file);
+ return fclose(file);
#endif
}
@@ -205,7 +205,7 @@ SRes SzFileSeekImp(void *object, CFileSize pos, ESzSeek origin)
/* VC 6.0 has bug with >> 32 shifts. */
value.HighPart = 0;
#endif
- switch (origin)
+ switch (origin)
{
case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;
case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;
@@ -214,14 +214,14 @@ SRes SzFileSeekImp(void *object, CFileSize pos, ESzSeek origin)
}
value.LowPart = SetFilePointer(s->File, value.LowPart, &value.HighPart, moveMethod);
if (value.LowPart == 0xFFFFFFFF)
- if (GetLastError() != NO_ERROR)
+ if (GetLastError() != NO_ERROR)
return SZ_ERROR_FAIL;
return SZ_OK;
}
#else
int moveMethod;
int res;
- switch (origin)
+ switch (origin)
{
case SZ_SEEK_SET: moveMethod = SEEK_SET; break;
case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;
@@ -246,7 +246,7 @@ int MY_CDECL main(int numargs, char *args[])
ISzAlloc allocImp;
ISzAlloc allocTempImp;
- printf("\n7z ANSI-C Decoder 4.58 Copyright (c) 1999-2008 Igor Pavlov 2008-04-09\n");
+ printf("\n7z ANSI-C Decoder 4.59 Copyright (c) 1999-2008 Igor Pavlov 2008-07-09\n");
if (numargs == 1)
{
printf(
@@ -263,9 +263,9 @@ int MY_CDECL main(int numargs, char *args[])
return 1;
}
- archiveStream.File =
+ archiveStream.File =
#ifdef USE_WINDOWS_FUNCTIONS
- CreateFileA(args[2], GENERIC_READ, FILE_SHARE_READ,
+ CreateFileA(args[2], GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (archiveStream.File == INVALID_HANDLE_VALUE)
#else
@@ -311,8 +311,8 @@ int MY_CDECL main(int numargs, char *args[])
CSzFileItem *f = db.db.Files + i;
char s[32], t[32];
ConvertNumberToString(f->Size, s);
- if (f->IsLastWriteTimeDefined)
- ConvertFileTimeToString(&f->LastWriteTime, t);
+ if (f->MTimeDefined)
+ ConvertFileTimeToString(&f->MTime, t);
else
strcpy(t, " ");
@@ -337,21 +337,21 @@ int MY_CDECL main(int numargs, char *args[])
size_t offset;
size_t outSizeProcessed;
CSzFileItem *f = db.db.Files + i;
- if (f->IsDirectory)
+ if (f->IsDir)
printf("Directory ");
else
- printf(testCommand ?
+ printf(testCommand ?
"Testing ":
"Extracting");
printf(" %s", f->Name);
- if (f->IsDirectory)
+ if (f->IsDir)
{
printf("\n");
continue;
}
- res = SzAr_Extract(&db, &archiveStream.InStream, i,
- &blockIndex, &outBuffer, &outBufferSize,
- &offset, &outSizeProcessed,
+ res = SzAr_Extract(&db, &archiveStream.InStream, i,
+ &blockIndex, &outBuffer, &outBufferSize,
+ &offset, &outSizeProcessed,
&allocImp, &allocTempImp);
if (res != SZ_OK)
break;
@@ -368,9 +368,9 @@ int MY_CDECL main(int numargs, char *args[])
break;
}
- outputHandle =
+ outputHandle =
#ifdef USE_WINDOWS_FUNCTIONS
- CreateFileA(fileName, GENERIC_WRITE, FILE_SHARE_READ,
+ CreateFileA(fileName, GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (outputHandle == INVALID_HANDLE_VALUE)
#else
@@ -420,7 +420,7 @@ int MY_CDECL main(int numargs, char *args[])
PrintError("can not allocate memory");
else if (res == SZ_ERROR_CRC)
PrintError("CRC error");
- else
+ else
printf("\nERROR #%d\n", res);
return 1;
}
diff --git a/C/Archive/7z/makefile.gcc b/C/Archive/7z/makefile.gcc
index 796412a1..6d3da99c 100755
--- a/C/Archive/7z/makefile.gcc
+++ b/C/Archive/7z/makefile.gcc
@@ -1,6 +1,6 @@
PROG = 7zDec
CXX = g++
-LIB =
+LIB =
RM = rm -f
CFLAGS = -c -O2 -Wall
diff --git a/C/Bcj2.c b/C/Bcj2.c
index 3a1d82fe..a4dafac8 100755
--- a/C/Bcj2.c
+++ b/C/Bcj2.c
@@ -1,12 +1,10 @@
/* Bcj2.c -- Converter for x86 code (BCJ2)
-2008-04-11
+2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
Read Bra.h for license options */
#include "Bcj2.h"
-#include "Alloc.h"
-
#ifdef _LZMA_PROB32
#define CProb UInt32
#else
@@ -31,14 +29,14 @@ Read Bra.h for license options */
#define NORMALIZE if (range < kTopValue) { RC_TEST; range <<= 8; code = (code << 8) | RC_READ_BYTE; }
#define IF_BIT_0(p) ttt = *(p); bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
-#define UPDATE_0(p) range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE;
-#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE;
+#define UPDATE_0(p) range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE;
+#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE;
int Bcj2_Decode(
- const Byte *buf0, SizeT size0,
- const Byte *buf1, SizeT size1,
- const Byte *buf2, SizeT size2,
- const Byte *buf3, SizeT size3,
+ const Byte *buf0, SizeT size0,
+ const Byte *buf1, SizeT size1,
+ const Byte *buf2, SizeT size2,
+ const Byte *buf3, SizeT size3,
Byte *outBuf, SizeT outSize)
{
CProb p[256 + 2];
@@ -50,10 +48,10 @@ int Bcj2_Decode(
unsigned int i;
for (i = 0; i < sizeof(p) / sizeof(p[0]); i++)
- p[i] = kBitModelTotal >> 1;
+ p[i] = kBitModelTotal >> 1;
- buffer = buf3;
- bufferLim = buffer + size3;
+ buffer = buf3;
+ bufferLim = buffer + size3;
RC_INIT2
if (outSize == 0)
@@ -118,7 +116,7 @@ int Bcj2_Decode(
buf2 += 4;
size2 -= 4;
}
- dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) |
+ dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) |
((UInt32)v[2] << 8) | ((UInt32)v[3])) - ((UInt32)outPos + 4);
outBuf[outPos++] = (Byte)dest;
if (outPos == outSize)
diff --git a/C/Bcj2.h b/C/Bcj2.h
index 9dd81b5c..bc82a274 100755
--- a/C/Bcj2.h
+++ b/C/Bcj2.h
@@ -1,5 +1,5 @@
/* Bcj2.h -- Converter for x86 code (BCJ2)
-2008-04-11
+2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
Read Bra.h for license options */
@@ -10,7 +10,7 @@ Read Bra.h for license options */
/*
Conditions:
- outSize <= FullOutputSize,
+ outSize <= FullOutputSize,
where FullOutputSize is full size of output stream of x86_2 filter.
If buf0 overlaps outBuf, there are two required conditions:
@@ -23,10 +23,10 @@ Returns:
*/
int Bcj2_Decode(
- const Byte *buf0, SizeT size0,
- const Byte *buf1, SizeT size1,
- const Byte *buf2, SizeT size2,
- const Byte *buf3, SizeT size3,
+ const Byte *buf0, SizeT size0,
+ const Byte *buf1, SizeT size1,
+ const Byte *buf2, SizeT size2,
+ const Byte *buf3, SizeT size3,
Byte *outBuf, SizeT outSize);
#endif
diff --git a/C/Bra.c b/C/Bra.c
index 5683cb34..c703fc8f 100755
--- a/C/Bra.c
+++ b/C/Bra.c
@@ -1,5 +1,5 @@
/* Bra.c -- converters for RISC code
-2008-03-19
+2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
Read Bra.h for license options */
@@ -41,11 +41,11 @@ SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
ip += 4;
for (i = 0; i <= size; i += 2)
{
- if ((data[i + 1] & 0xF8) == 0xF0 &&
+ if ((data[i + 1] & 0xF8) == 0xF0 &&
(data[i + 3] & 0xF8) == 0xF8)
{
UInt32 dest;
- UInt32 src =
+ UInt32 src =
(((UInt32)data[i + 1] & 0x7) << 19) |
((UInt32)data[i + 0] << 11) |
(((UInt32)data[i + 3] & 0x7) << 8) |
@@ -106,10 +106,10 @@ 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 ||
+ if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 ||
data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)
{
- UInt32 src =
+ UInt32 src =
((UInt32)data[i + 0] << 24) |
((UInt32)data[i + 1] << 16) |
((UInt32)data[i + 2] << 8) |
diff --git a/C/Bra.h b/C/Bra.h
index 66800535..0ff7b842 100755
--- a/C/Bra.h
+++ b/C/Bra.h
@@ -1,5 +1,5 @@
/* Bra.h -- Branch converters for executables
-2008-03-19
+2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
Read LzmaDec.h for license options */
@@ -8,18 +8,18 @@ Read LzmaDec.h for license options */
#include "Types.h"
-/*
-These functions convert relative addresses to absolute addresses
+/*
+These functions convert relative addresses to absolute addresses
in CALL instructions to increase the compression ratio.
- In:
+ In:
data - data buffer
size - size of data
ip - current virtual Instruction Pinter (IP) value
state - state variable for x86 converter
encoding - 0 (for decoding), 1 (for encoding)
- Out:
+ Out:
state - state variable for x86 converter
Returns:
@@ -41,9 +41,9 @@ in CALL instructions to increase the compression ratio.
Example:
UInt32 ip = 0;
- for()
+ for()
{
- // size must be >= Alignment + LookAhead, if it's not last block
+ // size must be >= Alignment + LookAhead, if it's not last block
SizeT processed = Convert(data, size, ip, 1);
data += processed;
size -= processed;
diff --git a/C/BraIA64.c b/C/BraIA64.c
index 8e02cdea..d2570922 100755
--- a/C/BraIA64.c
+++ b/C/BraIA64.c
@@ -1,16 +1,16 @@
/* BraIA64.c -- converter for IA-64 code
-2008-03-19
+2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
Read Bra.h for license options */
#include "Bra.h"
-static const Byte kBranchTable[32] =
-{
+static const Byte kBranchTable[32] =
+{
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
4, 4, 6, 6, 0, 0, 7, 7,
- 4, 4, 0, 0, 4, 4, 0, 0
+ 4, 4, 0, 0, 4, 4, 0, 0
};
SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
diff --git a/C/BwtSort.c b/C/BwtSort.c
index 507046ad..fdac5545 100755
--- a/C/BwtSort.c
+++ b/C/BwtSort.c
@@ -1,5 +1,5 @@
/* BwtSort.c -- BWT block sorting
-2008-03-26
+2008-08-05
Igor Pavlov
Public domain */
@@ -22,12 +22,12 @@ Public domain */
#ifdef BLOCK_SORT_EXTERNAL_FLAGS
/* 32 Flags in UInt32 word */
-#define kNumFlagsBits 5
+#define kNumFlagsBits 5
#define kNumFlagsInWord (1 << kNumFlagsBits)
#define kFlagsMask (kNumFlagsInWord - 1)
#define kAllFlags 0xFFFFFFFF
-#else
+#else
#define kNumBitsMax 20
#define kIndexMask ((1 << kNumBitsMax) - 1)
@@ -78,7 +78,7 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
return 0;
}
Groups = Indices + BlockSize + BS_TEMP_SIZE;
- if (groupSize <= ((UInt32)1 << NumRefBits)
+ if (groupSize <= ((UInt32)1 << NumRefBits)
#ifndef BLOCK_SORT_USE_HEAP_SORT
&& groupSize <= range
#endif
@@ -117,7 +117,7 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
HeapSort(temp, groupSize);
mask = ((1 << NumRefBits) - 1);
- thereAreGroups = 0;
+ thereAreGroups = 0;
group = groupOffset;
cg = (temp[0] >> NumRefBits);
@@ -233,7 +233,7 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
}
else if (i == groupSize)
range = (mid - left);
- else
+ else
break;
}
@@ -307,7 +307,7 @@ UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 group
}
{
/* Write new Groups values and Check that there are groups */
- UInt32 thereAreGroups = 0;
+ UInt32 thereAreGroups = 0;
for (j = 0; j < groupSize; j++)
{
UInt32 group = groupOffset + j;
@@ -438,8 +438,8 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
i++;
continue;
}
- for(groupSize = 1;
- (Flags[(i + groupSize) >> kNumFlagsBits] & (1 << ((i + groupSize) & kFlagsMask))) != 0;
+ for(groupSize = 1;
+ (Flags[(i + groupSize) >> kNumFlagsBits] & (1 << ((i + groupSize) & kFlagsMask))) != 0;
groupSize++);
groupSize++;
@@ -488,7 +488,7 @@ UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize)
if (SortGroup(blockSize, NumSortedBytes, i, groupSize, NumRefBits, Indices
#ifndef BLOCK_SORT_USE_HEAP_SORT
, 0, blockSize
- #endif
+ #endif
) != 0)
newLimit = i + groupSize;
i += groupSize;
diff --git a/C/CpuArch.h b/C/CpuArch.h
index 2ec7081f..7384b0c3 100755
--- a/C/CpuArch.h
+++ b/C/CpuArch.h
@@ -1,16 +1,16 @@
/* CpuArch.h
-2008-03-26
+2008-08-05
Igor Pavlov
Public domain */
#ifndef __CPUARCH_H
#define __CPUARCH_H
-/*
+/*
LITTLE_ENDIAN_UNALIGN means:
1) CPU is LITTLE_ENDIAN
2) it's allowed to make unaligned memory accesses
-if LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know
+if LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know
about these properties of platform.
*/
@@ -23,19 +23,19 @@ about these properties of platform.
#define GetUi16(p) (*(const UInt16 *)(p))
#define GetUi32(p) (*(const UInt32 *)(p))
#define GetUi64(p) (*(const UInt64 *)(p))
-#define SetUi32(p, d) *(UInt32 *)(p) = d;
+#define SetUi32(p, d) *(UInt32 *)(p) = (d);
#else
-#define GetUi16(p) (((const Byte *)(p))[0] | \
- ((UInt16)((const Byte *)(p))[1] << 8))
+#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))
-#define GetUi32(p) (((const Byte *)(p))[0] | \
- ((UInt32)((const Byte *)(p))[1] << 8 ) | \
- ((UInt32)((const Byte *)(p))[2] << 16) | \
- ((UInt32)((const Byte *)(p))[3] << 24))
+#define GetUi32(p) ( \
+ ((const Byte *)(p))[0] | \
+ ((UInt32)((const Byte *)(p))[1] << 8) | \
+ ((UInt32)((const Byte *)(p))[2] << 16) | \
+ ((UInt32)((const Byte *)(p))[3] << 24))
-#define GetUi64(p) (GetUi32(p) | (UInt64)GetUi32(((const Byte *)(p)) + 4) << 32)
+#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
#define SetUi32(p, d) { UInt32 _x_ = (d); \
((Byte *)(p))[0] = (Byte)_x_; \
@@ -45,4 +45,25 @@ about these properties of platform.
#endif
+#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)
+
+#pragma intrinsic(_byteswap_ulong)
+#pragma intrinsic(_byteswap_uint64)
+#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
+#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
+
+#else
+
+#define GetBe32(p) ( \
+ ((UInt32)((const Byte *)(p))[0] << 24) | \
+ ((UInt32)((const Byte *)(p))[1] << 16) | \
+ ((UInt32)((const Byte *)(p))[2] << 8) | \
+ ((const Byte *)(p))[3] )
+
+#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
+
+#endif
+
+#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])
+
#endif
diff --git a/C/HuffEnc.c b/C/HuffEnc.c
index 65f5d27a..6e58d2ce 100755
--- a/C/HuffEnc.c
+++ b/C/HuffEnc.c
@@ -1,5 +1,5 @@
/* HuffEnc.c -- functions for Huffman encoding
-2008-03-26
+2008-08-05
Igor Pavlov
Public domain */
@@ -24,22 +24,22 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb
#ifdef HUFFMAN_SPEED_OPT
UInt32 counters[NUM_COUNTERS];
- for (i = 0; i < NUM_COUNTERS; i++)
+ for (i = 0; i < NUM_COUNTERS; i++)
counters[i] = 0;
- for (i = 0; i < numSymbols; i++)
+ for (i = 0; i < numSymbols; i++)
{
UInt32 freq = freqs[i];
counters[(freq < NUM_COUNTERS - 1) ? freq : NUM_COUNTERS - 1]++;
}
- for (i = 1; i < NUM_COUNTERS; i++)
+ for (i = 1; i < NUM_COUNTERS; i++)
{
UInt32 temp = counters[i];
counters[i] = num;
num += temp;
}
- for (i = 0; i < numSymbols; i++)
+ for (i = 0; i < numSymbols; i++)
{
UInt32 freq = freqs[i];
if (freq == 0)
@@ -52,7 +52,7 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb
#else
- for (i = 0; i < numSymbols; i++)
+ for (i = 0; i < numSymbols; i++)
{
UInt32 freq = freqs[i];
if (freq == 0)
@@ -65,7 +65,7 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb
#endif
}
- if (num < 2)
+ if (num < 2)
{
int minCode = 0;
int maxCode = 1;
@@ -85,7 +85,7 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb
UInt32 b, e, i;
i = b = e = 0;
- do
+ do
{
UInt32 n, m, freq;
n = (i != num && (b == e || (p[i] >> NUM_BITS) <= (p[b] >> NUM_BITS))) ? i++ : b++;
@@ -96,21 +96,21 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb
p[m] = (p[m] & MASK) | (e << NUM_BITS);
p[e] = (p[e] & MASK) | freq;
e++;
- }
+ }
while (num - e > 1);
{
UInt32 lenCounters[kMaxLen + 1];
- for (i = 0; i <= kMaxLen; i++)
+ for (i = 0; i <= kMaxLen; i++)
lenCounters[i] = 0;
p[--e] &= MASK;
lenCounters[1] = 2;
- while (e > 0)
+ while (e > 0)
{
UInt32 len = (p[p[--e] >> NUM_BITS] >> NUM_BITS) + 1;
p[e] = (p[e] & MASK) | (len << NUM_BITS);
- if (len >= maxLen)
+ if (len >= maxLen)
for (len = maxLen - 1; lenCounters[len] == 0; len--);
lenCounters[len]--;
lenCounters[len + 1] += 2;
@@ -119,10 +119,10 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb
{
UInt32 len;
i = 0;
- for (len = maxLen; len != 0; len--)
+ for (len = maxLen; len != 0; len--)
{
UInt32 num;
- for (num = lenCounters[len]; num != 0; num--)
+ for (num = lenCounters[len]; num != 0; num--)
lens[p[i++] & MASK] = (Byte)len;
}
}
@@ -132,14 +132,14 @@ void Huffman_Generate(const UInt32 *freqs, UInt32 *p, Byte *lens, UInt32 numSymb
{
UInt32 code = 0;
UInt32 len;
- for (len = 1; len <= kMaxLen; len++)
+ for (len = 1; len <= kMaxLen; len++)
nextCodes[len] = code = (code + lenCounters[len - 1]) << 1;
}
/* if (code + lenCounters[kMaxLen] - 1 != (1 << kMaxLen) - 1) throw 1; */
{
UInt32 i;
- for (i = 0; i < numSymbols; i++)
+ for (i = 0; i < numSymbols; i++)
p[i] = nextCodes[lens[i]]++;
}
}
diff --git a/C/LzFind.c b/C/LzFind.c
index 831f0e47..d3938548 100755
--- a/C/LzFind.c
+++ b/C/LzFind.c
@@ -1,5 +1,5 @@
/* LzFind.c -- Match finder for LZ algorithms
-2008-04-04
+2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
Read LzFind.h for license options */
@@ -82,8 +82,8 @@ static void MatchFinder_ReadBlock(CMatchFinder *p)
void MatchFinder_MoveBlock(CMatchFinder *p)
{
- memmove(p->bufferBase,
- p->buffer - p->keepSizeBefore,
+ memmove(p->bufferBase,
+ p->buffer - p->keepSizeBefore,
(size_t)(p->streamPos - p->pos + p->keepSizeBefore));
p->buffer = p->bufferBase + p->keepSizeBefore;
}
@@ -96,7 +96,7 @@ int MatchFinder_NeedMove(CMatchFinder *p)
void MatchFinder_ReadIfRequired(CMatchFinder *p)
{
- if (p->streamEndWasReached)
+ if (p->streamEndWasReached)
return;
if (p->keepSizeAfter >= p->streamPos - p->pos)
MatchFinder_ReadBlock(p);
@@ -159,7 +159,7 @@ static CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)
return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);
}
-int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
+int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
ISzAlloc *alloc)
{
@@ -174,7 +174,7 @@ int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
sizeReserv = historySize >> 2;
sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);
- p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
+ p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;
/* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */
if (LzInWindow_Create(p, sizeReserv, alloc))
@@ -239,7 +239,7 @@ static void MatchFinder_SetLimits(CMatchFinder *p)
{
UInt32 limit = kMaxValForNormalize - p->pos;
UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
- if (limit2 < limit)
+ if (limit2 < limit)
limit = limit2;
limit2 = p->streamPos - p->pos;
if (limit2 <= p->keepSizeAfter)
@@ -249,7 +249,7 @@ static void MatchFinder_SetLimits(CMatchFinder *p)
}
else
limit2 -= p->keepSizeAfter;
- if (limit2 < limit)
+ if (limit2 < limit)
limit = limit2;
{
UInt32 lenLimit = p->streamPos - p->pos;
@@ -274,9 +274,9 @@ void MatchFinder_Init(CMatchFinder *p)
MatchFinder_SetLimits(p);
}
-static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
-{
- return (p->pos - p->historySize - 1) & kNormalizeMask;
+static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
+{
+ return (p->pos - p->historySize - 1) & kNormalizeMask;
}
void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
@@ -311,8 +311,8 @@ static void MatchFinder_CheckLimits(CMatchFinder *p)
MatchFinder_SetLimits(p);
}
-static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
+static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
+ UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
UInt32 *distances, UInt32 maxLen)
{
son[_cyclicBufferPos] = curMatch;
@@ -342,8 +342,8 @@ static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos,
}
}
-UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
+UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
+ UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
UInt32 *distances, UInt32 maxLen)
{
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
@@ -397,7 +397,7 @@ UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byt
}
}
-static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
+static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)
{
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
@@ -505,7 +505,7 @@ static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
delta2 = p->pos - p->hash[hash2Value];
curMatch = p->hash[kFix3HashSize + hashValue];
- p->hash[hash2Value] =
+ p->hash[hash2Value] =
p->hash[kFix3HashSize + hashValue] = p->pos;
@@ -522,7 +522,7 @@ static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (maxLen == lenLimit)
{
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
- MOVE_POS_RET;
+ MOVE_POS_RET;
}
}
GET_MATCHES_FOOTER(offset, maxLen)
@@ -567,7 +567,7 @@ static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (maxLen == lenLimit)
{
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
- MOVE_POS_RET;
+ MOVE_POS_RET;
}
}
if (maxLen < 3)
@@ -614,7 +614,7 @@ static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
if (maxLen == lenLimit)
{
p->son[p->cyclicBufferPos] = curMatch;
- MOVE_POS_RET;
+ MOVE_POS_RET;
}
}
if (maxLen < 3)
@@ -640,7 +640,7 @@ static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
{
do
{
- SKIP_HEADER(2)
+ SKIP_HEADER(2)
HASH2_CALC;
curMatch = p->hash[hashValue];
p->hash[hashValue] = p->pos;
@@ -682,7 +682,7 @@ static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
do
{
UInt32 hash2Value, hash3Value;
- SKIP_HEADER(4)
+ SKIP_HEADER(4)
HASH4_CALC;
curMatch = p->hash[kFix4HashSize + hashValue];
p->hash[ hash2Value] =
diff --git a/C/LzFind.h b/C/LzFind.h
index 01b9f732..fb3815d2 100755
--- a/C/LzFind.h
+++ b/C/LzFind.h
@@ -1,12 +1,12 @@
/* LzFind.h -- Match finder for LZ algorithms
-2008-04-04
+2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
You can use any of the following license options:
1) GNU Lesser General Public License (GNU LGPL)
2) Common Public License (CPL)
- 3) Common Development and Distribution License (CDDL) Version 1.0
- 4) Igor Pavlov, as the author of this code, expressly permits you to
- statically or dynamically link your code (or bind by name) to this file,
+ 3) Common Development and Distribution License (CDDL) Version 1.0
+ 4) Igor Pavlov, as the author of this code, expressly permits you to
+ statically or dynamically link your code (or bind by name) to this file,
while you keep this file unmodified.
*/
@@ -71,18 +71,18 @@ void MatchFinder_Construct(CMatchFinder *p);
historySize <= 3 GB
keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
*/
-int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
+int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
ISzAlloc *alloc);
void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
-UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
+UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
+ UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
UInt32 *distances, UInt32 maxLen);
-/*
+/*
Conditions:
Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
diff --git a/C/LzFindMt.c b/C/LzFindMt.c
index 7ed2030a..3df50ac0 100755
--- a/C/LzFindMt.c
+++ b/C/LzFindMt.c
@@ -1,5 +1,5 @@
/* LzFindMt.c -- multithreaded Match finder for LZ algorithms
-2008-04-11
+2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
Read LzFind.h for license options */
@@ -49,7 +49,7 @@ void MtSync_GetNextBlock(CMtSync *p)
/* MtSync_StopWriting must be called if Writing was started */
void MtSync_StopWriting(CMtSync *p)
-{
+{
UInt32 myNumBlocks = p->numProcessedBlocks;
if (!Thread_WasCreated(&p->thread) || p->needStart)
return;
@@ -233,8 +233,8 @@ void MatchFinderMt_GetNextBlock_Hash(CMatchFinderMt *p)
#define NO_INLINE MY_FAST_CALL
-Int32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,
- UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
+Int32 NO_INLINE GetMatchesSpecN(UInt32 lenLimit, UInt32 pos, const Byte *cur, CLzRef *son,
+ UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
UInt32 *_distances, UInt32 _maxLen, const UInt32 *hash, Int32 limit, UInt32 size, UInt32 *posRes)
{
do
@@ -347,8 +347,8 @@ void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)
while (curPos < limit && size-- != 0)
{
UInt32 *startDistances = distances + curPos;
- UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++],
- pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
+ UInt32 num = (UInt32)(GetMatchesSpec1(lenLimit, pos - p->hashBuf[p->hashBufPos++],
+ pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
startDistances + 1, p->numHashBytes - 1) - startDistances);
*startDistances = num - 1;
curPos += num;
@@ -359,7 +359,7 @@ void BtGetMatches(CMatchFinderMt *p, UInt32 *distances)
#else
{
UInt32 posRes;
- curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
+ curPos = limit - GetMatchesSpecN(lenLimit, pos, p->buffer, p->son, cyclicBufferPos, p->cyclicBufferSize, p->cutValue,
distances + curPos, p->numHashBytes - 1, p->hashBuf + p->hashBufPos, (Int32)(limit - curPos) , size, &posRes);
p->hashBufPos += posRes - pos;
cyclicBufferPos += posRes - pos;
@@ -454,19 +454,19 @@ void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc)
#define kBtBufferSize (kMtBtBlockSize * kMtBtNumBlocks)
static unsigned MY_STD_CALL HashThreadFunc2(void *p) { HashThreadFunc((CMatchFinderMt *)p); return 0; }
-static unsigned MY_STD_CALL BtThreadFunc2(void *p)
-{
+static unsigned MY_STD_CALL BtThreadFunc2(void *p)
+{
Byte allocaDummy[0x180];
int i = 0;
for (i = 0; i < 16; i++)
allocaDummy[i] = (Byte)i;
- BtThreadFunc((CMatchFinderMt *)p);
- return 0;
+ BtThreadFunc((CMatchFinderMt *)p);
+ return 0;
}
-SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
+SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc)
-{
+{
CMatchFinder *mf = p->MatchFinder;
p->historySize = historySize;
if (kMtBtBlockSize <= matchMaxLen * 4)
@@ -490,7 +490,7 @@ SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddB
/* Call it after ReleaseStream / SetStream */
void MatchFinderMt_Init(CMatchFinderMt *p)
-{
+{
CMatchFinder *mf = p->MatchFinder;
p->btBufPos = p->btBufPosLimit = 0;
p->hashBufPos = p->hashBufPosLimit = 0;
@@ -515,7 +515,7 @@ void MatchFinderMt_Init(CMatchFinderMt *p)
/* ReleaseStream is required to finish multithreading */
void MatchFinderMt_ReleaseStream(CMatchFinderMt *p)
-{
+{
MtSync_StopWriting(&p->btSync);
/* p->MatchFinder->ReleaseStream(); */
}
@@ -534,7 +534,7 @@ void MatchFinderMt_GetNextBlock_Bt(CMatchFinderMt *p)
p->btBufPosLimit = p->btBufPos = blockIndex * kMtBtBlockSize;
p->btBufPosLimit += p->btBuf[p->btBufPos++];
p->btNumAvailBytes = p->btBuf[p->btBufPos++];
- if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize)
+ if (p->lzPos >= kMtMaxValForNormalize - kMtBtBlockSize)
MatchFinderMt_Normalize(p);
}
@@ -546,14 +546,14 @@ const Byte * MatchFinderMt_GetPointerToCurrentPos(CMatchFinderMt *p)
#define GET_NEXT_BLOCK_IF_REQUIRED if (p->btBufPos == p->btBufPosLimit) MatchFinderMt_GetNextBlock_Bt(p);
UInt32 MatchFinderMt_GetNumAvailableBytes(CMatchFinderMt *p)
-{
+{
GET_NEXT_BLOCK_IF_REQUIRED;
return p->btNumAvailBytes;
}
Byte MatchFinderMt_GetIndexByte(CMatchFinderMt *p, Int32 index)
-{
- return p->pointerToCurPos[index];
+{
+ return p->pointerToCurPos[index];
}
UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
@@ -561,16 +561,16 @@ UInt32 * MixMatches2(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
UInt32 hash2Value, curMatch2;
UInt32 *hash = p->hash;
const Byte *cur = p->pointerToCurPos;
- UInt32 lzPos = p->lzPos;
+ UInt32 lzPos = p->lzPos;
MT_HASH2_CALC
curMatch2 = hash[hash2Value];
hash[hash2Value] = lzPos;
- if (curMatch2 >= matchMinPos)
+ if (curMatch2 >= matchMinPos)
if (cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
{
- *distances++ = 2;
+ *distances++ = 2;
*distances++ = lzPos - curMatch2 - 1;
}
return distances;
@@ -581,31 +581,31 @@ UInt32 * MixMatches3(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
UInt32 hash2Value, hash3Value, curMatch2, curMatch3;
UInt32 *hash = p->hash;
const Byte *cur = p->pointerToCurPos;
- UInt32 lzPos = p->lzPos;
+ UInt32 lzPos = p->lzPos;
MT_HASH3_CALC
curMatch2 = hash[ hash2Value];
curMatch3 = hash[kFix3HashSize + hash3Value];
- hash[ hash2Value] =
- hash[kFix3HashSize + hash3Value] =
+ hash[ hash2Value] =
+ hash[kFix3HashSize + hash3Value] =
lzPos;
if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
- {
+ {
distances[1] = lzPos - curMatch2 - 1;
if (cur[(ptrdiff_t)curMatch2 - lzPos + 2] == cur[2])
{
distances[0] = 3;
return distances + 2;
}
- distances[0] = 2;
+ distances[0] = 2;
distances += 2;
}
if (curMatch3 >= matchMinPos && cur[(ptrdiff_t)curMatch3 - lzPos] == cur[0])
- {
- *distances++ = 3;
- *distances++ = lzPos - curMatch3 - 1;
+ {
+ *distances++ = 3;
+ *distances++ = lzPos - curMatch3 - 1;
}
return distances;
}
@@ -616,16 +616,16 @@ UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
UInt32 hash2Value, hash3Value, hash4Value, curMatch2, curMatch3, curMatch4;
UInt32 *hash = p->hash;
const Byte *cur = p->pointerToCurPos;
- UInt32 lzPos = p->lzPos;
+ UInt32 lzPos = p->lzPos;
MT_HASH4_CALC
curMatch2 = hash[ hash2Value];
curMatch3 = hash[kFix3HashSize + hash3Value];
curMatch4 = hash[kFix4HashSize + hash4Value];
- hash[ hash2Value] =
- hash[kFix3HashSize + hash3Value] =
- hash[kFix4HashSize + hash4Value] =
+ hash[ hash2Value] =
+ hash[kFix3HashSize + hash3Value] =
+ hash[kFix4HashSize + hash4Value] =
lzPos;
if (curMatch2 >= matchMinPos && cur[(ptrdiff_t)curMatch2 - lzPos] == cur[0])
@@ -667,7 +667,7 @@ UInt32 *MixMatches4(CMatchFinderMt *p, UInt32 matchMinPos, UInt32 *distances)
#define INCREASE_LZ_POS p->lzPos++; p->pointerToCurPos++;
UInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)
-{
+{
const UInt32 *btBuf = p->btBuf + p->btBufPos;
UInt32 len = *btBuf++;
p->btBufPos += 1 + len;
@@ -685,14 +685,14 @@ UInt32 MatchFinderMt2_GetMatches(CMatchFinderMt *p, UInt32 *distances)
}
UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)
-{
+{
const UInt32 *btBuf = p->btBuf + p->btBufPos;
UInt32 len = *btBuf++;
p->btBufPos += 1 + len;
if (len == 0)
{
- if (p->btNumAvailBytes-- >= 4)
+ if (p->btNumAvailBytes-- >= 4)
len = (UInt32)(p->MixMatchesFunc(p, p->lzPos - p->historySize, distances) - (distances));
}
else
@@ -701,7 +701,7 @@ UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)
UInt32 *distances2;
p->btNumAvailBytes--;
distances2 = p->MixMatchesFunc(p, p->lzPos - btBuf[1], distances);
- do
+ do
{
*distances2++ = *btBuf++;
*distances2++ = *btBuf++;
@@ -718,13 +718,13 @@ UInt32 MatchFinderMt_GetMatches(CMatchFinderMt *p, UInt32 *distances)
#define SKIP_FOOTER } INCREASE_LZ_POS p->btBufPos += p->btBuf[p->btBufPos] + 1; } while(--num != 0);
void MatchFinderMt0_Skip(CMatchFinderMt *p, UInt32 num)
-{
+{
SKIP_HEADER2 { p->btNumAvailBytes--;
SKIP_FOOTER
}
void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)
-{
+{
SKIP_HEADER(2)
UInt32 hash2Value;
MT_HASH2_CALC
@@ -733,25 +733,25 @@ void MatchFinderMt2_Skip(CMatchFinderMt *p, UInt32 num)
}
void MatchFinderMt3_Skip(CMatchFinderMt *p, UInt32 num)
-{
+{
SKIP_HEADER(3)
UInt32 hash2Value, hash3Value;
MT_HASH3_CALC
- hash[kFix3HashSize + hash3Value] =
- hash[ hash2Value] =
+ hash[kFix3HashSize + hash3Value] =
+ hash[ hash2Value] =
p->lzPos;
SKIP_FOOTER
}
/*
void MatchFinderMt4_Skip(CMatchFinderMt *p, UInt32 num)
-{
+{
SKIP_HEADER(4)
UInt32 hash2Value, hash3Value, hash4Value;
MT_HASH4_CALC
- hash[kFix4HashSize + hash4Value] =
- hash[kFix3HashSize + hash3Value] =
- hash[ hash2Value] =
+ hash[kFix4HashSize + hash4Value] =
+ hash[kFix3HashSize + hash3Value] =
+ hash[ hash2Value] =
p->lzPos;
SKIP_FOOTER
}
diff --git a/C/LzFindMt.h b/C/LzFindMt.h
index 36343b4f..e24ed471 100755
--- a/C/LzFindMt.h
+++ b/C/LzFindMt.h
@@ -1,5 +1,5 @@
/* LzFindMt.h -- multithreaded Match finder for LZ algorithms
-2008-04-04
+2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
Read LzFind.h for license options */
@@ -91,7 +91,7 @@ typedef struct _CMatchFinderMt
void MatchFinderMt_Construct(CMatchFinderMt *p);
void MatchFinderMt_Destruct(CMatchFinderMt *p, ISzAlloc *alloc);
-SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
+SRes MatchFinderMt_Create(CMatchFinderMt *p, UInt32 historySize, UInt32 keepAddBufferBefore,
UInt32 matchMaxLen, UInt32 keepAddBufferAfter, ISzAlloc *alloc);
void MatchFinderMt_CreateVTable(CMatchFinderMt *p, IMatchFinder *vTable);
void MatchFinderMt_ReleaseStream(CMatchFinderMt *p);
diff --git a/C/LzmaDec.c b/C/LzmaDec.c
index 37dd6c9d..0a782070 100755
--- a/C/LzmaDec.c
+++ b/C/LzmaDec.c
@@ -1,5 +1,5 @@
/* LzmaDec.c -- LZMA Decoder
-2008-04-29
+2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
Read LzmaDec.h for license options */
@@ -23,8 +23,8 @@ Read LzmaDec.h for license options */
#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CLzmaProb)(ttt - (ttt >> kNumMoveBits));
#define GET_BIT2(p, i, A0, A1) IF_BIT_0(p) \
{ UPDATE_0(p); i = (i + i); A0; } else \
- { UPDATE_1(p); i = (i + i) + 1; A1; }
-#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)
+ { UPDATE_1(p); i = (i + i) + 1; A1; }
+#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)
#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }
#define TREE_DECODE(probs, limit, i) \
@@ -53,8 +53,8 @@ Read LzmaDec.h for license options */
#define UPDATE_1_CHECK range -= bound; code -= bound;
#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \
{ UPDATE_0_CHECK; i = (i + i); A0; } else \
- { UPDATE_1_CHECK; i = (i + i) + 1; A1; }
-#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)
+ { UPDATE_1_CHECK; i = (i + i) + 1; A1; }
+#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)
#define TREE_DECODE_CHECK(probs, limit, i) \
{ i = 1; do { GET_BIT_CHECK(probs + i, i) } while(i < limit); i -= limit; }
@@ -74,7 +74,7 @@ Read LzmaDec.h for license options */
#define LenLow (LenChoice2 + 1)
#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
-#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
+#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
#define kNumStates 12
@@ -120,16 +120,16 @@ StopCompilingDueBUG
#define LZMA_SPEC_LEN_OFFSET (-3)
*/
-Byte kLiteralNextStates[kNumStates * 2] =
+const Byte kLiteralNextStates[kNumStates * 2] =
{
- 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5,
+ 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5,
7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10
};
#define LZMA_DIC_MIN (1 << 12)
-/* First LZMA-symbol is always decoded.
-And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization
+/* First LZMA-symbol is always decoded.
+And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization
Out:
Result:
0 - OK
@@ -177,7 +177,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
UPDATE_0(prob);
prob = probs + Literal;
if (checkDicSize != 0 || processedPos != 0)
- prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +
+ prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +
(dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));
if (state < kNumLitStates)
@@ -208,7 +208,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
/* if (state < 4) state = 0; else if (state < 10) state -= 3; else state -= 6; */
continue;
}
- else
+ else
{
UPDATE_1(prob);
prob = probs + IsRep + state;
@@ -249,7 +249,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
UPDATE_0(prob);
distance = rep1;
}
- else
+ else
{
UPDATE_1(prob);
prob = probs + IsRepG2 + state;
@@ -313,7 +313,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
TREE_6_DECODE(prob, distance);
if (distance >= kStartPosModelIndex)
{
- unsigned posSlot = (unsigned)distance;
+ unsigned posSlot = (unsigned)distance;
int numDirectBits = (int)(((distance >> 1) - 1));
distance = (2 | (distance & 1));
if (posSlot < kEndPosModelIndex)
@@ -376,7 +376,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
rep3 = rep2;
rep2 = rep1;
rep1 = rep0;
- rep0 = distance + 1;
+ rep0 = distance + 1;
if (checkDicSize == 0)
{
if (distance >= processedPos)
@@ -404,8 +404,8 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
const Byte *lim = dest + curLen;
dicPos += curLen;
- do
- *(dest) = (Byte)*(dest + src);
+ do
+ *(dest) = (Byte)*(dest + src);
while (++dest != lim);
}
else
@@ -491,7 +491,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte
return 0;
}
-typedef enum
+typedef enum
{
DUMMY_ERROR, /* unexpected end of input stream */
DUMMY_LIT,
@@ -523,8 +523,8 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
prob = probs + Literal;
if (p->checkDicSize != 0 || p->processedPos != 0)
- prob += (LZMA_LIT_SIZE *
- ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
+ prob += (LZMA_LIT_SIZE *
+ ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
(p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
if (state < kNumLitStates)
@@ -534,7 +534,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
}
else
{
- unsigned matchByte = p->dic[p->dicPos - p->reps[0] +
+ unsigned matchByte = p->dic[p->dicPos - p->reps[0] +
((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];
unsigned offs = 0x100;
unsigned symbol = 1;
@@ -551,7 +551,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
}
res = DUMMY_LIT;
}
- else
+ else
{
unsigned len;
UPDATE_1_CHECK;
@@ -592,7 +592,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
{
UPDATE_0_CHECK;
}
- else
+ else
{
UPDATE_1_CHECK;
prob = probs + IsRepG2 + state;
@@ -646,7 +646,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
{
unsigned posSlot;
prob = probs + PosSlot +
- ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
+ ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
kNumPosSlotBits);
TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);
if (posSlot >= kStartPosModelIndex)
@@ -697,11 +697,11 @@ static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)
p->needFlush = 0;
}
-void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
-{
- p->needFlush = 1;
- p->remainLen = 0;
- p->tempBufSize = 0;
+void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
+{
+ p->needFlush = 1;
+ p->remainLen = 0;
+ p->tempBufSize = 0;
if (initDic)
{
@@ -713,9 +713,9 @@ void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
p->needInitState = 1;
}
-void LzmaDec_Init(CLzmaDec *p)
-{
- p->dicPos = 0;
+void LzmaDec_Init(CLzmaDec *p)
+{
+ p->dicPos = 0;
LzmaDec_InitDicAndState(p, True, True);
}
@@ -725,13 +725,13 @@ static void LzmaDec_InitStateReal(CLzmaDec *p)
UInt32 i;
CLzmaProb *probs = p->probs;
for (i = 0; i < numProbs; i++)
- probs[i] = kBitModelTotal >> 1;
+ probs[i] = kBitModelTotal >> 1;
p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
p->state = 0;
p->needInitState = 0;
}
-SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
+SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
ELzmaFinishMode finishMode, ELzmaStatus *status)
{
SizeT inSize = *srcLen;
@@ -847,7 +847,7 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
p->tempBufSize = 0;
}
}
- if (p->code == 0)
+ if (p->code == 0)
*status = LZMA_STATUS_FINISHED_WITH_MARK;
return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
}
@@ -892,16 +892,16 @@ SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *sr
}
}
-void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->probs);
- p->probs = 0;
+void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc)
+{
+ alloc->Free(alloc, p->probs);
+ p->probs = 0;
}
-static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
-{
- alloc->Free(alloc, p->dic);
- p->dic = 0;
+static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc)
+{
+ alloc->Free(alloc, p->dic);
+ p->dic = 0;
}
void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)
@@ -912,7 +912,7 @@ void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc)
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
{
- UInt32 dicSize;
+ UInt32 dicSize;
Byte d;
if (size < LZMA_PROPS_SIZE)
@@ -982,7 +982,7 @@ SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAll
}
SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
- const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
+ const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
ELzmaStatus *status, ISzAlloc *alloc)
{
CLzmaDec p;
diff --git a/C/LzmaDec.h b/C/LzmaDec.h
index 9610f0ec..be594a1c 100755
--- a/C/LzmaDec.h
+++ b/C/LzmaDec.h
@@ -1,12 +1,12 @@
/* LzmaDec.h -- LZMA Decoder
-2008-04-29
+2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
You can use any of the following license options:
1) GNU Lesser General Public License (GNU LGPL)
2) Common Public License (CPL)
- 3) Common Development and Distribution License (CDDL) Version 1.0
- 4) Igor Pavlov, as the author of this code, expressly permits you to
- statically or dynamically link your code (or bind by name) to this file,
+ 3) Common Development and Distribution License (CDDL) Version 1.0
+ 4) Igor Pavlov, as the author of this code, expressly permits you to
+ statically or dynamically link your code (or bind by name) to this file,
while you keep this file unmodified.
*/
@@ -16,7 +16,7 @@ You can use any of the following license options:
#include "Types.h"
/* #define _LZMA_PROB32 */
-/* _LZMA_PROB32 can increase the speed on some CPUs,
+/* _LZMA_PROB32 can increase the speed on some CPUs,
but memory usage for CLzmaDec::probs will be doubled in that case */
#ifdef _LZMA_PROB32
@@ -26,7 +26,7 @@ You can use any of the following license options:
#endif
-/* ---------- LZMA Properties ---------- */
+/* ---------- LZMA Properties ---------- */
#define LZMA_PROPS_SIZE 5
@@ -45,7 +45,7 @@ Returns:
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
-/* ---------- LZMA Decoder state ---------- */
+/* ---------- LZMA Decoder state ---------- */
/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
@@ -81,15 +81,15 @@ void LzmaDec_Init(CLzmaDec *p);
0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
-typedef enum
+typedef enum
{
- LZMA_FINISH_ANY, /* finish at any point */
+ LZMA_FINISH_ANY, /* finish at any point */
LZMA_FINISH_END /* block must be finished at the end */
} ELzmaFinishMode;
/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
- You must use LZMA_FINISH_END, when you know that current output buffer
+ You must use LZMA_FINISH_END, when you know that current output buffer
covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
@@ -99,36 +99,36 @@ typedef enum
You can use multiple checks to test data integrity after full decompression:
1) Check Result and "status" variable.
2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
- 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
- You must use correct finish mode in that case. */
+ 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
+ You must use correct finish mode in that case. */
-typedef enum
+typedef enum
{
LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
- LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
+ LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
} ELzmaStatus;
/* ELzmaStatus is used only as output value for function call */
-/* ---------- Interfaces ---------- */
+/* ---------- Interfaces ---------- */
/* There are 3 levels of interfaces:
1) Dictionary Interface
2) Buffer Interface
3) One Call Interface
- You can select any of these interfaces, but don't mix functions from different
+ You can select any of these interfaces, but don't mix functions from different
groups for same object. */
/* There are two variants to allocate state for Dictionary Interface:
1) LzmaDec_Allocate / LzmaDec_Free
2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
- You can use variant 2, if you set dictionary buffer manually.
- For Buffer Interface you must always use variant 1.
+ You can use variant 2, if you set dictionary buffer manually.
+ For Buffer Interface you must always use variant 1.
LzmaDec_Allocate* can return:
SZ_OK
@@ -142,9 +142,9 @@ void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
-/* ---------- Dictionary Interface ---------- */
+/* ---------- Dictionary Interface ---------- */
-/* You can use it, if you want to eliminate the overhead for data copying from
+/* You can use it, if you want to eliminate the overhead for data copying from
dictionary to some other external buffer.
You must work with CLzmaDec variables directly in this interface.
@@ -166,7 +166,7 @@ void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
/* LzmaDec_DecodeToDic
The decoding to internal dictionary buffer (CLzmaDec::dic).
- You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
+ You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
finishMode:
It has meaning only if the decoding reaches output limit (dicLimit).
@@ -177,34 +177,34 @@ Returns:
SZ_OK
status:
LZMA_STATUS_FINISHED_WITH_MARK
- LZMA_STATUS_NOT_FINISHED
+ LZMA_STATUS_NOT_FINISHED
LZMA_STATUS_NEEDS_MORE_INPUT
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
SZ_ERROR_DATA - Data error
*/
-SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
+SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
-/* ---------- Buffer Interface ---------- */
+/* ---------- Buffer Interface ---------- */
/* It's zlib-like interface.
See LzmaDec_DecodeToDic description for information about STEPS and return results,
but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
to work with CLzmaDec variables manually.
-finishMode:
+finishMode:
It has meaning only if the decoding reaches output limit (*destLen).
LZMA_FINISH_ANY - Decode just destLen bytes.
LZMA_FINISH_END - Stream must be finished after (*destLen).
*/
-SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
+SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
-/* ---------- One Call Interface ---------- */
+/* ---------- One Call Interface ---------- */
/* LzmaDecode
@@ -217,7 +217,7 @@ Returns:
SZ_OK
status:
LZMA_STATUS_FINISHED_WITH_MARK
- LZMA_STATUS_NOT_FINISHED
+ LZMA_STATUS_NOT_FINISHED
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
SZ_ERROR_DATA - Data error
SZ_ERROR_MEM - Memory allocation error
@@ -226,7 +226,7 @@ Returns:
*/
SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
- const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
+ const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
ELzmaStatus *status, ISzAlloc *alloc);
#endif
diff --git a/C/LzmaEnc.c b/C/LzmaEnc.c
index 402e2742..34b976d0 100755
--- a/C/LzmaEnc.c
+++ b/C/LzmaEnc.c
@@ -1,11 +1,17 @@
/* LzmaEnc.c -- LZMA Encoder
-2008-04-28
+2008-08-13
Copyright (c) 1999-2008 Igor Pavlov
Read LzmaEnc.h for license options */
-#include <stdio.h>
#include <string.h>
+/* #define SHOW_STAT */
+/* #define SHOW_STAT2 */
+
+#if defined(SHOW_STAT) || defined(SHOW_STAT2)
+#include <stdio.h>
+#endif
+
#include "LzmaEnc.h"
#include "LzFind.h"
@@ -13,9 +19,6 @@ Read LzmaEnc.h for license options */
#include "LzFindMt.h"
#endif
-/* #define SHOW_STAT */
-/* #define SHOW_STAT2 */
-
#ifdef SHOW_STAT
static int ttt = 0;
#endif
@@ -55,13 +58,13 @@ 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->lc < 0) p->lc = 3;
- if (p->lp < 0) p->lp = 0;
- if (p->pb < 0) p->pb = 2;
- if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);
- if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);
- if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);
- if (p->numHashBytes < 0) p->numHashBytes = 4;
+ if (p->lc < 0) p->lc = 3;
+ if (p->lp < 0) p->lp = 0;
+ if (p->pb < 0) p->pb = 2;
+ if (p->algo < 0) p->algo = (level < 5 ? 0 : 1);
+ if (p->fb < 0) p->fb = (level < 7 ? 32 : 64);
+ if (p->btMode < 0) p->btMode = (p->algo == 0 ? 0 : 1);
+ if (p->numHashBytes < 0) p->numHashBytes = 4;
if (p->mc == 0) p->mc = (16 + (p->fb >> 1)) >> (p->btMode ? 0 : 1);
if (p->numThreads < 0) p->numThreads = ((p->btMode && p->algo) ? 2 : 1);
}
@@ -83,11 +86,11 @@ UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2)
#define BSR2_RET(pos, res) { unsigned long i; _BitScanReverse(&i, (pos)); res = (i + i) + ((pos >> (i - 1)) & 1); }
-UInt32 GetPosSlot1(UInt32 pos)
-{
- UInt32 res;
- BSR2_RET(pos, res);
- return res;
+UInt32 GetPosSlot1(UInt32 pos)
+{
+ UInt32 res;
+ BSR2_RET(pos, res);
+ return res;
}
#define GetPosSlot2(pos, res) { BSR2_RET(pos, res); }
#define GetPosSlot(pos, res) { if (pos < 2) res = pos; else BSR2_RET(pos, res); }
@@ -134,26 +137,26 @@ typedef unsigned CState;
typedef struct _COptimal
{
- UInt32 price;
+ UInt32 price;
CState state;
int prev1IsChar;
int prev2;
UInt32 posPrev2;
- UInt32 backPrev2;
+ UInt32 backPrev2;
UInt32 posPrev;
- UInt32 backPrev;
+ UInt32 backPrev;
UInt32 backs[LZMA_NUM_REPS];
} COptimal;
#define kNumOpts (1 << 12)
#define kNumLenToPosStates 4
-#define kNumPosSlotBits 6
-#define kDicLogSizeMin 0
-#define kDicLogSizeMax 32
+#define kNumPosSlotBits 6
+#define kDicLogSizeMin 0
+#define kDicLogSizeMax 32
#define kDistTableSizeMax (kDicLogSizeMax * 2)
@@ -245,7 +248,7 @@ static SRes MyRead(void *pp, void *data, size_t *size)
return SZ_OK;
}
-typedef struct
+typedef struct
{
CLzmaProb *litProbs;
@@ -286,10 +289,9 @@ typedef struct _CLzmaEnc
UInt32 optimumEndIndex;
UInt32 optimumCurrentIndex;
- Bool longestMatchWasFound;
- UInt32 longestMatchLength;
- UInt32 numDistancePairs;
-
+ UInt32 longestMatchLength;
+ UInt32 numPairs;
+ UInt32 numAvail;
COptimal opt[kNumOpts];
#ifndef LZMA_LOG_BSR
@@ -297,7 +299,7 @@ typedef struct _CLzmaEnc
#endif
UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
- UInt32 matchDistances[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];
+ UInt32 matches[LZMA_MATCH_LEN_MAX * 2 + 2 + 1];
UInt32 numFastBytes;
UInt32 additionalOffset;
UInt32 reps[LZMA_NUM_REPS];
@@ -462,16 +464,8 @@ static const int kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10,
static const int kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
static const int kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
-/*
- void UpdateChar() { Index = kLiteralNextStates[Index]; }
- void UpdateMatch() { Index = kMatchNextStates[Index]; }
- void UpdateRep() { Index = kRepNextStates[Index]; }
- void UpdateShortRep() { Index = kShortRepNextStates[Index]; }
-*/
-
#define IsCharState(s) ((s) < 7)
-
#define GetLenToPosState(len) (((len) < kNumLenToPosStates + 1) ? (len) - 2 : kNumLenToPosStates - 1)
#define kInfinityPrice (1 << 30)
@@ -531,7 +525,7 @@ static void RangeEnc_FlushStream(CRangeEnc *p)
static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)
{
- if ((UInt32)p->low < (UInt32)0xFF000000 || (int)(p->low >> 32) != 0)
+ if ((UInt32)p->low < (UInt32)0xFF000000 || (int)(p->low >> 32) != 0)
{
Byte temp = p->cache;
do
@@ -544,10 +538,10 @@ static void MY_FAST_CALL RangeEnc_ShiftLow(CRangeEnc *p)
temp = 0xFF;
}
while (--p->cacheSize != 0);
- p->cache = (Byte)((UInt32)p->low >> 24);
- }
- p->cacheSize++;
- p->low = (UInt32)p->low << 8;
+ p->cache = (Byte)((UInt32)p->low >> 24);
+ }
+ p->cacheSize++;
+ p->low = (UInt32)p->low << 8;
}
static void RangeEnc_FlushData(CRangeEnc *p)
@@ -598,7 +592,7 @@ static void RangeEnc_EncodeBit(CRangeEnc *p, CLzmaProb *prob, UInt32 symbol)
static void LitEnc_Encode(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol)
{
symbol |= 0x100;
- do
+ do
{
RangeEnc_EncodeBit(p, probs + (symbol >> 8), (symbol >> 7) & 1);
symbol <<= 1;
@@ -610,7 +604,7 @@ static void LitEnc_EncodeMatched(CRangeEnc *p, CLzmaProb *probs, UInt32 symbol,
{
UInt32 offs = 0x100;
symbol |= 0x100;
- do
+ do
{
matchByte <<= 1;
RangeEnc_EncodeBit(p, probs + (offs + (matchByte & offs) + (symbol >> 8)), (symbol >> 7) & 1);
@@ -667,14 +661,14 @@ static UInt32 LitEnc_GetPrice(const CLzmaProb *probs, UInt32 symbol, UInt32 *Pro
}
while (symbol < 0x10000);
return price;
-};
+}
static UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt32 matchByte, UInt32 *ProbPrices)
{
UInt32 price = 0;
UInt32 offs = 0x100;
symbol |= 0x100;
- do
+ do
{
matchByte <<= 1;
price += GET_PRICEa(probs[offs + (matchByte & offs) + (symbol >> 8)], (symbol >> 7) & 1);
@@ -683,14 +677,14 @@ static UInt32 LitEnc_GetPriceMatched(const CLzmaProb *probs, UInt32 symbol, UInt
}
while (symbol < 0x10000);
return price;
-};
+}
static void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)
{
UInt32 m = 1;
int i;
- for (i = numBitLevels; i != 0 ;)
+ for (i = numBitLevels; i != 0;)
{
UInt32 bit;
i--;
@@ -698,7 +692,7 @@ static void RcTree_Encode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UIn
RangeEnc_EncodeBit(rc, probs + m, bit);
m = (m << 1) | bit;
}
-};
+}
static void RcTree_ReverseEncode(CRangeEnc *rc, CLzmaProb *probs, int numBitLevels, UInt32 symbol)
{
@@ -838,31 +832,28 @@ static void MovePos(CLzmaEnc *p, UInt32 num)
static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)
{
- UInt32 lenRes = 0, numDistancePairs;
- numDistancePairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matchDistances);
+ UInt32 lenRes = 0, numPairs;
+ p->numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
+ numPairs = p->matchFinder.GetMatches(p->matchFinderObj, p->matches);
#ifdef SHOW_STAT
- printf("\n i = %d numPairs = %d ", ttt, numDistancePairs / 2);
- if (ttt >= 61994)
- ttt = ttt;
-
+ printf("\n i = %d numPairs = %d ", ttt, numPairs / 2);
ttt++;
{
UInt32 i;
- for (i = 0; i < numDistancePairs; i += 2)
- printf("%2d %6d | ", p->matchDistances[i], p->matchDistances[i + 1]);
+ for (i = 0; i < numPairs; i += 2)
+ printf("%2d %6d | ", p->matches[i], p->matches[i + 1]);
}
#endif
- if (numDistancePairs > 0)
+ if (numPairs > 0)
{
- lenRes = p->matchDistances[numDistancePairs - 2];
+ lenRes = p->matches[numPairs - 2];
if (lenRes == p->numFastBytes)
{
- UInt32 numAvail = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) + 1;
const Byte *pby = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- UInt32 distance = p->matchDistances[numDistancePairs - 1] + 1;
+ UInt32 distance = p->matches[numPairs - 1] + 1;
+ UInt32 numAvail = p->numAvail;
if (numAvail > LZMA_MATCH_LEN_MAX)
numAvail = LZMA_MATCH_LEN_MAX;
-
{
const Byte *pby2 = pby - distance;
for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++);
@@ -870,7 +861,7 @@ static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)
}
}
p->additionalOffset++;
- *numDistancePairsRes = numDistancePairs;
+ *numDistancePairsRes = numPairs;
return lenRes;
}
@@ -881,7 +872,7 @@ static UInt32 ReadMatchDistances(CLzmaEnc *p, UInt32 *numDistancePairsRes)
static UInt32 GetRepLen1Price(CLzmaEnc *p, UInt32 state, UInt32 posState)
{
- return
+ return
GET_PRICE_0(p->isRepG0[state]) +
GET_PRICE_0(p->isRep0Long[state][posState]);
}
@@ -947,26 +938,19 @@ static UInt32 Backward(CLzmaEnc *p, UInt32 *backRes, UInt32 cur)
while (cur != 0);
*backRes = p->opt[0].backPrev;
p->optimumCurrentIndex = p->opt[0].posPrev;
- return p->optimumCurrentIndex;
+ return p->optimumCurrentIndex;
}
#define LIT_PROBS(pos, prevByte) (p->litProbs + ((((pos) & p->lpMask) << p->lc) + ((prevByte) >> (8 - p->lc))) * 0x300)
static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
{
- UInt32 numAvailableBytes, lenMain, numDistancePairs;
+ UInt32 numAvail, mainLen, numPairs, repMaxIndex, i, posState, lenEnd, len, cur;
+ UInt32 matchPrice, repMatchPrice, normalMatchPrice;
+ UInt32 reps[LZMA_NUM_REPS], repLens[LZMA_NUM_REPS];
+ UInt32 *matches;
const Byte *data;
- UInt32 reps[LZMA_NUM_REPS];
- UInt32 repLens[LZMA_NUM_REPS];
- UInt32 repMaxIndex, i;
- UInt32 *matchDistances;
- Byte currentByte, matchByte;
- UInt32 posState;
- UInt32 matchPrice, repMatchPrice;
- UInt32 lenEnd;
- UInt32 len;
- UInt32 normalMatchPrice;
- UInt32 cur;
+ Byte curByte, matchByte;
if (p->optimumEndIndex != p->optimumCurrentIndex)
{
const COptimal *opt = &p->opt[p->optimumCurrentIndex];
@@ -977,28 +961,24 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
}
p->optimumCurrentIndex = p->optimumEndIndex = 0;
- numAvailableBytes = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
-
- if (!p->longestMatchWasFound)
- {
- lenMain = ReadMatchDistances(p, &numDistancePairs);
- }
+ if (p->additionalOffset == 0)
+ mainLen = ReadMatchDistances(p, &numPairs);
else
{
- lenMain = p->longestMatchLength;
- numDistancePairs = p->numDistancePairs;
- p->longestMatchWasFound = False;
+ mainLen = p->longestMatchLength;
+ numPairs = p->numPairs;
}
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- if (numAvailableBytes < 2)
+ numAvail = p->numAvail;
+ if (numAvail < 2)
{
*backRes = (UInt32)(-1);
return 1;
}
- if (numAvailableBytes > LZMA_MATCH_LEN_MAX)
- numAvailableBytes = LZMA_MATCH_LEN_MAX;
+ if (numAvail > LZMA_MATCH_LEN_MAX)
+ numAvail = LZMA_MATCH_LEN_MAX;
+ data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
repMaxIndex = 0;
for (i = 0; i < LZMA_NUM_REPS; i++)
{
@@ -1011,7 +991,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
repLens[i] = 0;
continue;
}
- for (lenTest = 2; lenTest < numAvailableBytes && data[lenTest] == data2[lenTest]; lenTest++);
+ for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);
repLens[i] = lenTest;
if (lenTest > repLens[repMaxIndex])
repMaxIndex = i;
@@ -1025,17 +1005,17 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
return lenRes;
}
- matchDistances = p->matchDistances;
- if (lenMain >= p->numFastBytes)
+ matches = p->matches;
+ if (mainLen >= p->numFastBytes)
{
- *backRes = matchDistances[numDistancePairs - 1] + LZMA_NUM_REPS;
- MovePos(p, lenMain - 1);
- return lenMain;
+ *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;
+ MovePos(p, mainLen - 1);
+ return mainLen;
}
- currentByte = *data;
+ curByte = *data;
matchByte = *(data - (reps[0] + 1));
- if (lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2)
+ if (mainLen < 2 && curByte != matchByte && repLens[repMaxIndex] < 2)
{
*backRes = (UInt32)-1;
return 1;
@@ -1047,10 +1027,10 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
{
const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
- p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +
- (!IsCharState(p->state) ?
- LitEnc_GetPriceMatched(probs, currentByte, matchByte, p->ProbPrices) :
- LitEnc_GetPrice(probs, currentByte, p->ProbPrices));
+ p->opt[1].price = GET_PRICE_0(p->isMatch[p->state][posState]) +
+ (!IsCharState(p->state) ?
+ LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :
+ LitEnc_GetPrice(probs, curByte, p->ProbPrices));
}
MakeAsChar(&p->opt[1]);
@@ -1058,7 +1038,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
matchPrice = GET_PRICE_1(p->isMatch[p->state][posState]);
repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[p->state]);
- if (matchByte == currentByte)
+ if (matchByte == curByte)
{
UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, p->state, posState);
if (shortRepPrice < p->opt[1].price)
@@ -1067,7 +1047,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
MakeAsShortRep(&p->opt[1]);
}
}
- lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);
+ lenEnd = ((mainLen >= repLens[repMaxIndex]) ? mainLen : repLens[repMaxIndex]);
if (lenEnd < 2)
{
@@ -1095,7 +1075,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
{
UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][repLen - 2];
COptimal *opt = &p->opt[repLen];
- if (curAndLenPrice < opt->price)
+ if (curAndLenPrice < opt->price)
{
opt->price = curAndLenPrice;
opt->posPrev = 0;
@@ -1109,15 +1089,15 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
normalMatchPrice = matchPrice + GET_PRICE_0(p->isRep[p->state]);
len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);
- if (len <= lenMain)
+ if (len <= mainLen)
{
UInt32 offs = 0;
- while (len > matchDistances[offs])
+ while (len > matches[offs])
offs += 2;
for (; ; len++)
{
COptimal *opt;
- UInt32 distance = matchDistances[offs + 1];
+ UInt32 distance = matches[offs + 1];
UInt32 curAndLenPrice = normalMatchPrice + p->lenEnc.prices[posState][len - LZMA_MATCH_LEN_MIN];
UInt32 lenToPosState = GetLenToPosState(len);
@@ -1130,17 +1110,17 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
curAndLenPrice += p->alignPrices[distance & kAlignMask] + p->posSlotPrices[lenToPosState][slot];
}
opt = &p->opt[len];
- if (curAndLenPrice < opt->price)
+ if (curAndLenPrice < opt->price)
{
opt->price = curAndLenPrice;
opt->posPrev = 0;
opt->backPrev = distance + LZMA_NUM_REPS;
opt->prev1IsChar = False;
}
- if (len == matchDistances[offs])
+ if (len == matches[offs])
{
offs += 2;
- if (offs == numDistancePairs)
+ if (offs == numPairs)
break;
}
}
@@ -1160,32 +1140,23 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
for (;;)
{
- UInt32 numAvailableBytesFull, newLen, numDistancePairs;
- COptimal *curOpt;
- UInt32 posPrev;
- UInt32 state;
- UInt32 curPrice;
+ UInt32 numAvailFull, newLen, numPairs, posPrev, state, posState, startLen;
+ UInt32 curPrice, curAnd1Price, matchPrice, repMatchPrice;
Bool nextIsChar;
+ Byte curByte, matchByte;
const Byte *data;
- Byte currentByte, matchByte;
- UInt32 posState;
- UInt32 curAnd1Price;
+ COptimal *curOpt;
COptimal *nextOpt;
- UInt32 matchPrice, repMatchPrice;
- UInt32 numAvailableBytes;
- UInt32 startLen;
cur++;
if (cur == lenEnd)
return Backward(p, backRes, cur);
- numAvailableBytesFull = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
- newLen = ReadMatchDistances(p, &numDistancePairs);
+ newLen = ReadMatchDistances(p, &numPairs);
if (newLen >= p->numFastBytes)
{
- p->numDistancePairs = numDistancePairs;
+ p->numPairs = numPairs;
p->longestMatchLength = newLen;
- p->longestMatchWasFound = True;
return Backward(p, backRes, cur);
}
position++;
@@ -1258,10 +1229,10 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
curOpt->backs[2] = reps[2];
curOpt->backs[3] = reps[3];
- curPrice = curOpt->price;
+ curPrice = curOpt->price;
nextIsChar = False;
data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- currentByte = *data;
+ curByte = *data;
matchByte = *(data - (reps[0] + 1));
posState = (position & p->pbMask);
@@ -1269,15 +1240,15 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
curAnd1Price = curPrice + GET_PRICE_0(p->isMatch[state][posState]);
{
const CLzmaProb *probs = LIT_PROBS(position, *(data - 1));
- curAnd1Price +=
- (!IsCharState(state) ?
- LitEnc_GetPriceMatched(probs, currentByte, matchByte, p->ProbPrices) :
- LitEnc_GetPrice(probs, currentByte, p->ProbPrices));
- }
+ curAnd1Price +=
+ (!IsCharState(state) ?
+ LitEnc_GetPriceMatched(probs, curByte, matchByte, p->ProbPrices) :
+ LitEnc_GetPrice(probs, curByte, p->ProbPrices));
+ }
nextOpt = &p->opt[cur + 1];
- if (curAnd1Price < nextOpt->price)
+ if (curAnd1Price < nextOpt->price)
{
nextOpt->price = curAnd1Price;
nextOpt->posPrev = cur;
@@ -1288,7 +1259,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
matchPrice = curPrice + GET_PRICE_1(p->isMatch[state][posState]);
repMatchPrice = matchPrice + GET_PRICE_1(p->isRep[state]);
- if (matchByte == currentByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0))
+ if (matchByte == curByte && !(nextOpt->posPrev < cur && nextOpt->backPrev == 0))
{
UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(p, state, posState);
if (shortRepPrice <= nextOpt->price)
@@ -1299,27 +1270,26 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
nextIsChar = True;
}
}
-
+ numAvailFull = p->numAvail;
{
UInt32 temp = kNumOpts - 1 - cur;
- if (temp < numAvailableBytesFull)
- numAvailableBytesFull = temp;
+ if (temp < numAvailFull)
+ numAvailFull = temp;
}
- numAvailableBytes = numAvailableBytesFull;
- if (numAvailableBytes < 2)
+ if (numAvailFull < 2)
continue;
- if (numAvailableBytes > p->numFastBytes)
- numAvailableBytes = p->numFastBytes;
- if (!nextIsChar && matchByte != currentByte) /* speed optimization */
+ numAvail = (numAvailFull <= p->numFastBytes ? numAvailFull : p->numFastBytes);
+
+ if (!nextIsChar && matchByte != curByte) /* speed optimization */
{
/* try Literal + rep0 */
UInt32 temp;
UInt32 lenTest2;
const Byte *data2 = data - (reps[0] + 1);
UInt32 limit = p->numFastBytes + 1;
- if (limit > numAvailableBytesFull)
- limit = numAvailableBytesFull;
+ if (limit > numAvailFull)
+ limit = numAvailFull;
for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++);
lenTest2 = temp - 1;
@@ -1327,7 +1297,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
{
UInt32 state2 = kLiteralNextStates[state];
UInt32 posStateNext = (position + 1) & p->pbMask;
- UInt32 nextRepMatchPrice = curAnd1Price +
+ UInt32 nextRepMatchPrice = curAnd1Price +
GET_PRICE_1(p->isMatch[state2][posStateNext]) +
GET_PRICE_1(p->isRep[state2]);
/* for (; lenTest2 >= 2; lenTest2--) */
@@ -1339,7 +1309,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
p->opt[++lenEnd].price = kInfinityPrice;
curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
opt = &p->opt[offset];
- if (curAndLenPrice < opt->price)
+ if (curAndLenPrice < opt->price)
{
opt->price = curAndLenPrice;
opt->posPrev = cur + 1;
@@ -1362,7 +1332,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
const Byte *data2 = data - (reps[repIndex] + 1);
if (data[0] != data2[0] || data[1] != data2[1])
continue;
- for (lenTest = 2; lenTest < numAvailableBytes && data[lenTest] == data2[lenTest]; lenTest++);
+ for (lenTest = 2; lenTest < numAvail && data[lenTest] == data2[lenTest]; lenTest++);
while (lenEnd < cur + lenTest)
p->opt[++lenEnd].price = kInfinityPrice;
lenTestTemp = lenTest;
@@ -1371,7 +1341,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
{
UInt32 curAndLenPrice = price + p->repLenEnc.prices[posState][lenTest - 2];
COptimal *opt = &p->opt[cur + lenTest];
- if (curAndLenPrice < opt->price)
+ if (curAndLenPrice < opt->price)
{
opt->price = curAndLenPrice;
opt->posPrev = cur;
@@ -1390,22 +1360,22 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
UInt32 lenTest2 = lenTest + 1;
UInt32 limit = lenTest2 + p->numFastBytes;
UInt32 nextRepMatchPrice;
- if (limit > numAvailableBytesFull)
- limit = numAvailableBytesFull;
+ if (limit > numAvailFull)
+ limit = numAvailFull;
for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);
lenTest2 -= lenTest + 1;
if (lenTest2 >= 2)
{
UInt32 state2 = kRepNextStates[state];
UInt32 posStateNext = (position + lenTest) & p->pbMask;
- UInt32 curAndLenCharPrice =
- price + p->repLenEnc.prices[posState][lenTest - 2] +
+ UInt32 curAndLenCharPrice =
+ price + p->repLenEnc.prices[posState][lenTest - 2] +
GET_PRICE_0(p->isMatch[state2][posStateNext]) +
LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),
data[lenTest], data2[lenTest], p->ProbPrices);
state2 = kLiteralNextStates[state2];
posStateNext = (position + lenTest + 1) & p->pbMask;
- nextRepMatchPrice = curAndLenCharPrice +
+ nextRepMatchPrice = curAndLenCharPrice +
GET_PRICE_1(p->isMatch[state2][posStateNext]) +
GET_PRICE_1(p->isRep[state2]);
@@ -1418,7 +1388,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
p->opt[++lenEnd].price = kInfinityPrice;
curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
opt = &p->opt[offset];
- if (curAndLenPrice < opt->price)
+ if (curAndLenPrice < opt->price)
{
opt->price = curAndLenPrice;
opt->posPrev = cur + lenTest + 1;
@@ -1434,12 +1404,12 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
}
}
/* for (UInt32 lenTest = 2; lenTest <= newLen; lenTest++) */
- if (newLen > numAvailableBytes)
+ if (newLen > numAvail)
{
- newLen = numAvailableBytes;
- for (numDistancePairs = 0; newLen > matchDistances[numDistancePairs]; numDistancePairs += 2);
- matchDistances[numDistancePairs] = newLen;
- numDistancePairs += 2;
+ newLen = numAvail;
+ for (numPairs = 0; newLen > matches[numPairs]; numPairs += 2);
+ matches[numPairs] = newLen;
+ numPairs += 2;
}
if (newLen >= startLen)
{
@@ -1450,9 +1420,9 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
p->opt[++lenEnd].price = kInfinityPrice;
offs = 0;
- while (startLen > matchDistances[offs])
+ while (startLen > matches[offs])
offs += 2;
- curBack = matchDistances[offs + 1];
+ curBack = matches[offs + 1];
GetPosSlot2(curBack, posSlot);
for (lenTest = /*2*/ startLen; ; lenTest++)
{
@@ -1465,7 +1435,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
curAndLenPrice += p->posSlotPrices[lenToPosState][posSlot] + p->alignPrices[curBack & kAlignMask];
opt = &p->opt[cur + lenTest];
- if (curAndLenPrice < opt->price)
+ if (curAndLenPrice < opt->price)
{
opt->price = curAndLenPrice;
opt->posPrev = cur;
@@ -1473,28 +1443,28 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
opt->prev1IsChar = False;
}
- if (/*_maxMode && */lenTest == matchDistances[offs])
+ if (/*_maxMode && */lenTest == matches[offs])
{
/* Try Match + Literal + Rep0 */
const Byte *data2 = data - (curBack + 1);
UInt32 lenTest2 = lenTest + 1;
UInt32 limit = lenTest2 + p->numFastBytes;
UInt32 nextRepMatchPrice;
- if (limit > numAvailableBytesFull)
- limit = numAvailableBytesFull;
+ if (limit > numAvailFull)
+ limit = numAvailFull;
for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++);
lenTest2 -= lenTest + 1;
if (lenTest2 >= 2)
{
UInt32 state2 = kMatchNextStates[state];
UInt32 posStateNext = (position + lenTest) & p->pbMask;
- UInt32 curAndLenCharPrice = curAndLenPrice +
+ UInt32 curAndLenCharPrice = curAndLenPrice +
GET_PRICE_0(p->isMatch[state2][posStateNext]) +
LitEnc_GetPriceMatched(LIT_PROBS(position + lenTest, data[lenTest - 1]),
data[lenTest], data2[lenTest], p->ProbPrices);
state2 = kLiteralNextStates[state2];
posStateNext = (posStateNext + 1) & p->pbMask;
- nextRepMatchPrice = curAndLenCharPrice +
+ nextRepMatchPrice = curAndLenCharPrice +
GET_PRICE_1(p->isMatch[state2][posStateNext]) +
GET_PRICE_1(p->isRep[state2]);
@@ -1507,7 +1477,7 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
p->opt[++lenEnd].price = kInfinityPrice;
curAndLenPrice = nextRepMatchPrice + GetRepPrice(p, 0, lenTest2, state2, posStateNext);
opt = &p->opt[offset];
- if (curAndLenPrice < opt->price)
+ if (curAndLenPrice < opt->price)
{
opt->price = curAndLenPrice;
opt->posPrev = cur + lenTest + 1;
@@ -1520,9 +1490,9 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
}
}
offs += 2;
- if (offs == numDistancePairs)
+ if (offs == numPairs)
break;
- curBack = matchDistances[offs + 1];
+ curBack = matches[offs + 1];
if (curBack >= kNumFullDistances)
GetPosSlot2(curBack, posSlot);
}
@@ -1535,136 +1505,110 @@ static UInt32 GetOptimum(CLzmaEnc *p, UInt32 position, UInt32 *backRes)
static UInt32 GetOptimumFast(CLzmaEnc *p, UInt32 *backRes)
{
- UInt32 numAvailableBytes = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
- UInt32 lenMain, numDistancePairs;
+ UInt32 numAvail, mainLen, mainDist, numPairs, repIndex, repLen, i;
const Byte *data;
- UInt32 repLens[LZMA_NUM_REPS];
- UInt32 repMaxIndex, i;
- UInt32 *matchDistances;
- UInt32 backMain;
+ const UInt32 *matches;
- if (!p->longestMatchWasFound)
- {
- lenMain = ReadMatchDistances(p, &numDistancePairs);
- }
+ if (p->additionalOffset == 0)
+ mainLen = ReadMatchDistances(p, &numPairs);
else
{
- lenMain = p->longestMatchLength;
- numDistancePairs = p->numDistancePairs;
- p->longestMatchWasFound = False;
+ mainLen = p->longestMatchLength;
+ numPairs = p->numPairs;
}
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- if (numAvailableBytes > LZMA_MATCH_LEN_MAX)
- numAvailableBytes = LZMA_MATCH_LEN_MAX;
- if (numAvailableBytes < 2)
- {
- *backRes = (UInt32)(-1);
+ numAvail = p->numAvail;
+ *backRes = (UInt32)-1;
+ if (numAvail < 2)
return 1;
- }
-
- repMaxIndex = 0;
+ if (numAvail > LZMA_MATCH_LEN_MAX)
+ numAvail = LZMA_MATCH_LEN_MAX;
+ data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+ repLen = repIndex = 0;
for (i = 0; i < LZMA_NUM_REPS; i++)
{
- const Byte *data2 = data - (p->reps[i] + 1);
UInt32 len;
+ const Byte *data2 = data - (p->reps[i] + 1);
if (data[0] != data2[0] || data[1] != data2[1])
- {
- repLens[i] = 0;
continue;
- }
- for (len = 2; len < numAvailableBytes && data[len] == data2[len]; len++);
+ for (len = 2; len < numAvail && data[len] == data2[len]; len++);
if (len >= p->numFastBytes)
{
*backRes = i;
MovePos(p, len - 1);
return len;
}
- repLens[i] = len;
- if (len > repLens[repMaxIndex])
- repMaxIndex = i;
+ if (len > repLen)
+ {
+ repIndex = i;
+ repLen = len;
+ }
}
- matchDistances = p->matchDistances;
- if (lenMain >= p->numFastBytes)
+
+ matches = p->matches;
+ if (mainLen >= p->numFastBytes)
{
- *backRes = matchDistances[numDistancePairs - 1] + LZMA_NUM_REPS;
- MovePos(p, lenMain - 1);
- return lenMain;
+ *backRes = matches[numPairs - 1] + LZMA_NUM_REPS;
+ MovePos(p, mainLen - 1);
+ return mainLen;
}
- backMain = 0; /* for GCC */
- if (lenMain >= 2)
+ mainDist = 0; /* for GCC */
+ if (mainLen >= 2)
{
- backMain = matchDistances[numDistancePairs - 1];
- while (numDistancePairs > 2 && lenMain == matchDistances[numDistancePairs - 4] + 1)
+ mainDist = matches[numPairs - 1];
+ while (numPairs > 2 && mainLen == matches[numPairs - 4] + 1)
{
- if (!ChangePair(matchDistances[numDistancePairs - 3], backMain))
+ if (!ChangePair(matches[numPairs - 3], mainDist))
break;
- numDistancePairs -= 2;
- lenMain = matchDistances[numDistancePairs - 2];
- backMain = matchDistances[numDistancePairs - 1];
+ numPairs -= 2;
+ mainLen = matches[numPairs - 2];
+ mainDist = matches[numPairs - 1];
}
- if (lenMain == 2 && backMain >= 0x80)
- lenMain = 1;
+ if (mainLen == 2 && mainDist >= 0x80)
+ mainLen = 1;
}
- if (repLens[repMaxIndex] >= 2)
+ if (repLen >= 2 && (
+ (repLen + 1 >= mainLen) ||
+ (repLen + 2 >= mainLen && mainDist >= (1 << 9)) ||
+ (repLen + 3 >= mainLen && mainDist >= (1 << 15))))
{
- if (repLens[repMaxIndex] + 1 >= lenMain ||
- (repLens[repMaxIndex] + 2 >= lenMain && (backMain > (1 << 9))) ||
- (repLens[repMaxIndex] + 3 >= lenMain && (backMain > (1 << 15))))
- {
- UInt32 lenRes;
- *backRes = repMaxIndex;
- lenRes = repLens[repMaxIndex];
- MovePos(p, lenRes - 1);
- return lenRes;
- }
+ *backRes = repIndex;
+ MovePos(p, repLen - 1);
+ return repLen;
}
- if (lenMain >= 2 && numAvailableBytes > 2)
+ if (mainLen < 2 || numAvail <= 2)
+ return 1;
+
+ p->longestMatchLength = ReadMatchDistances(p, &p->numPairs);
+ if (p->longestMatchLength >= 2)
{
- UInt32 i;
- numAvailableBytes = p->matchFinder.GetNumAvailableBytes(p->matchFinderObj);
- p->longestMatchLength = ReadMatchDistances(p, &p->numDistancePairs);
- if (p->longestMatchLength >= 2)
- {
- UInt32 newDistance = matchDistances[p->numDistancePairs - 1];
- if ((p->longestMatchLength >= lenMain && newDistance < backMain) ||
- (p->longestMatchLength == lenMain + 1 && !ChangePair(backMain, newDistance)) ||
- (p->longestMatchLength > lenMain + 1) ||
- (p->longestMatchLength + 1 >= lenMain && lenMain >= 3 && ChangePair(newDistance, backMain)))
- {
- p->longestMatchWasFound = True;
- *backRes = (UInt32)(-1);
- return 1;
- }
- }
- data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
- for (i = 0; i < LZMA_NUM_REPS; i++)
- {
- UInt32 len;
- const Byte *data2 = data - (p->reps[i] + 1);
- if (data[1] != data2[1] || data[2] != data2[2])
- {
- repLens[i] = 0;
- continue;
- }
- for (len = 2; len < numAvailableBytes && data[len] == data2[len]; len++);
- if (len + 1 >= lenMain)
- {
- p->longestMatchWasFound = True;
- *backRes = (UInt32)(-1);
- return 1;
- }
- }
- *backRes = backMain + LZMA_NUM_REPS;
- MovePos(p, lenMain - 2);
- return lenMain;
+ UInt32 newDistance = matches[p->numPairs - 1];
+ if ((p->longestMatchLength >= mainLen && newDistance < mainDist) ||
+ (p->longestMatchLength == mainLen + 1 && !ChangePair(mainDist, newDistance)) ||
+ (p->longestMatchLength > mainLen + 1) ||
+ (p->longestMatchLength + 1 >= mainLen && mainLen >= 3 && ChangePair(newDistance, mainDist)))
+ return 1;
}
- *backRes = (UInt32)(-1);
- return 1;
+
+ data = p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - 1;
+ for (i = 0; i < LZMA_NUM_REPS; i++)
+ {
+ UInt32 len, limit;
+ const Byte *data2 = data - (p->reps[i] + 1);
+ if (data[0] != data2[0] || data[1] != data2[1])
+ continue;
+ limit = mainLen - 1;
+ for (len = 2; len < limit && data[len] == data2[len]; len++);
+ if (len >= limit)
+ return 1;
+ }
+ *backRes = mainDist + LZMA_NUM_REPS;
+ MovePos(p, mainLen - 2);
+ return mainLen;
}
static void WriteEndMarker(CLzmaEnc *p, UInt32 posState)
@@ -1717,7 +1661,7 @@ static void FillDistancesPrices(CLzmaEnc *p)
UInt32 tempPrices[kNumFullDistances];
UInt32 i, lenToPosState;
for (i = kStartPosModelIndex; i < kNumFullDistances; i++)
- {
+ {
UInt32 posSlot = GetPosSlot1(i);
UInt32 footerBits = ((posSlot >> 1) - 1);
UInt32 base = ((2 | (posSlot & 1)) << footerBits);
@@ -1822,11 +1766,11 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize
if (p->nowPos64 == 0)
{
- UInt32 numDistancePairs;
+ UInt32 numPairs;
Byte curByte;
if (p->matchFinder.GetNumAvailableBytes(p->matchFinderObj) == 0)
return Flush(p, nowPos32);
- ReadMatchDistances(p, &numDistancePairs);
+ ReadMatchDistances(p, &numPairs);
RangeEnc_EncodeBit(&p->rc, &p->isMatch[p->state][0], 0);
p->state = kLiteralNextStates[p->state];
curByte = p->matchFinder.GetIndexByte(p->matchFinderObj, 0 - p->additionalOffset);
@@ -1850,7 +1794,7 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize
#endif
posState = nowPos32 & p->pbMask;
- if (len == 1 && pos == 0xFFFFFFFF)
+ if (len == 1 && pos == (UInt32)-1)
{
Byte curByte;
CLzmaProb *probs;
@@ -2068,7 +2012,6 @@ void LzmaEnc_Init(CLzmaEnc *p)
for (i = 0; i < (1 << kNumAlignBits); i++)
p->posAlignEncoder[i] = kProbInitValue;
- p->longestMatchWasFound = False;
p->optimumEndIndex = 0;
p->optimumCurrentIndex = 0;
p->additionalOffset = 0;
@@ -2085,8 +2028,8 @@ void LzmaEnc_InitPrices(CLzmaEnc *p)
FillAlignPrices(p);
}
- p->lenEnc.tableSize =
- p->repLenEnc.tableSize =
+ p->lenEnc.tableSize =
+ p->repLenEnc.tableSize =
p->numFastBytes + 1 - LZMA_MATCH_LEN_MIN;
LenPriceEnc_UpdateTables(&p->lenEnc, 1 << p->pb, p->ProbPrices);
LenPriceEnc_UpdateTables(&p->repLenEnc, 1 << p->pb, p->ProbPrices);
@@ -2118,7 +2061,7 @@ static SRes LzmaEnc_Prepare(CLzmaEncHandle pp, ISeqInStream *inStream, ISeqOutSt
return LzmaEnc_AllocAndInit(p, 0, alloc, allocBig);
}
-SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
+SRes LzmaEnc_PrepareForLzma2(CLzmaEncHandle pp,
ISeqInStream *inStream, UInt32 keepWindowSize,
ISzAlloc *alloc, ISzAlloc *allocBig)
{
@@ -2187,7 +2130,7 @@ const Byte *LzmaEnc_GetCurBuf(CLzmaEncHandle pp)
return p->matchFinder.GetPointerToCurrentPos(p->matchFinderObj) - p->additionalOffset;
}
-SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
+SRes LzmaEnc_CodeOneMemBlock(CLzmaEncHandle pp, Bool reInit,
Byte *dest, size_t *destLen, UInt32 desiredPackSize, UInt32 *unpackSize)
{
CLzmaEnc *p = (CLzmaEnc *)pp;
@@ -2300,7 +2243,7 @@ SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte
outStream.overflow = False;
p->writeEndMark = writeEndMark;
- res = LzmaEnc_Encode(pp, &outStream.funcTable, &p->seqBufInStream.funcTable,
+ res = LzmaEnc_Encode(pp, &outStream.funcTable, &p->seqBufInStream.funcTable,
progress, alloc, allocBig);
*destLen -= outStream.rem;
@@ -2310,7 +2253,7 @@ SRes LzmaEnc_MemEncode(CLzmaEncHandle pp, Byte *dest, SizeT *destLen, const Byte
}
SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
+ const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig)
{
CLzmaEnc *p = (CLzmaEnc *)LzmaEnc_Create(alloc);
diff --git a/C/LzmaEnc.h b/C/LzmaEnc.h
index 949f40f4..54b140e0 100755
--- a/C/LzmaEnc.h
+++ b/C/LzmaEnc.h
@@ -1,5 +1,5 @@
/* LzmaEnc.h -- LZMA Encoder
-2008-04-27
+2008-08-05
Copyright (c) 1999-2008 Igor Pavlov
Read LzFind.h for license options */
@@ -12,13 +12,13 @@ Read LzFind.h for license options */
typedef struct _CLzmaEncProps
{
- int level; /* 0 <= level <= 9 */
+ int level; /* 0 <= level <= 9 */
UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
- (1 << 12) <= dictSize <= (1 << 30) for 64-bit version
+ (1 << 12) <= dictSize <= (1 << 30) for 64-bit version
default = (1 << 24) */
- int lc; /* 0 <= lc <= 8, default = 3 */
- int lp; /* 0 <= lp <= 4, default = 0 */
- int pb; /* 0 <= pb <= 4, default = 2 */
+ int lc; /* 0 <= lc <= 8, default = 3 */
+ int lp; /* 0 <= lp <= 4, default = 0 */
+ int pb; /* 0 <= pb <= 4, default = 2 */
int algo; /* 0 - fast, 1 - normal, default = 1 */
int fb; /* 5 <= fb <= 273, default = 32 */
int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */
@@ -38,7 +38,7 @@ UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
/* LzmaEnc_* functions can return the following exit codes:
Returns:
SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_MEM - Memory allocation error
SZ_ERROR_PARAM - Incorrect paramater in props
SZ_ERROR_WRITE - Write callback error.
SZ_ERROR_PROGRESS - some break from progress callback
@@ -51,7 +51,7 @@ CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);
void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);
SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
-SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
+SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
@@ -61,14 +61,14 @@ SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte
/* LzmaEncode
Return code:
SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_MEM - Memory allocation error
SZ_ERROR_PARAM - Incorrect paramater
SZ_ERROR_OUTPUT_EOF - output buffer overflow
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
*/
SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
- const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
+ const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
#endif
diff --git a/C/LzmaLib.c b/C/LzmaLib.c
index 32b0a459..02a51185 100755
--- a/C/LzmaLib.c
+++ b/C/LzmaLib.c
@@ -1,5 +1,5 @@
/* LzmaLib.c -- LZMA library wrapper
-2008-04-07
+2008-08-05
Igor Pavlov
Public domain */
@@ -16,9 +16,9 @@ MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned cha
unsigned char *outProps, size_t *outPropsSize,
int level, /* 0 <= level <= 9, default = 5 */
unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */
- int lc, /* 0 <= lc <= 8, default = 3 */
- int lp, /* 0 <= lp <= 4, default = 0 */
- int pb, /* 0 <= pb <= 4, default = 2 */
+ int lc, /* 0 <= lc <= 8, default = 3 */
+ int lp, /* 0 <= lp <= 4, default = 0 */
+ int pb, /* 0 <= pb <= 4, default = 2 */
int fb, /* 5 <= fb <= 273, default = 32 */
int numThreads /* 1 or 2, default = 2 */
)
@@ -33,12 +33,12 @@ MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned cha
props.fb = fb;
props.numThreads = numThreads;
- return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0,
+ return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0,
NULL, &g_Alloc, &g_Alloc);
}
-MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t *srcLen,
+MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t *srcLen,
const unsigned char *props, size_t propsSize)
{
ELzmaStatus status;
diff --git a/C/LzmaLib.h b/C/LzmaLib.h
index ac7f90f8..5c9eeec7 100755
--- a/C/LzmaLib.h
+++ b/C/LzmaLib.h
@@ -1,5 +1,5 @@
/* LzmaLib.h -- LZMA library interface
-2008-04-11
+2008-08-05
Igor Pavlov
Public domain */
@@ -35,7 +35,7 @@ LZMA properties (5 bytes) format
LzmaCompress
------------
-outPropsSize -
+outPropsSize -
In: the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
@@ -46,7 +46,7 @@ outPropsSize -
level - compression level: 0 <= level <= 9;
level dictSize algo fb
- 0: 16 KB 0 32
+ 0: 16 KB 0 32
1: 64 KB 0 32
2: 256 KB 0 32
3: 1 MB 0 32
@@ -60,40 +60,40 @@ level - compression level: 0 <= level <= 9;
algo = 0 means fast method
algo = 1 means normal method
-dictSize - The dictionary size in bytes. The maximum value is
+dictSize - The dictionary size in bytes. The maximum value is
128 MB = (1 << 27) bytes for 32-bit version
1 GB = (1 << 30) bytes for 64-bit version
The default value is 16 MB = (1 << 24) bytes.
- It's recommended to use the dictionary that is larger than 4 KB and
- that can be calculated as (1 << N) or (3 << N) sizes.
+ It's recommended to use the dictionary that is larger than 4 KB and
+ that can be calculated as (1 << N) or (3 << N) sizes.
-lc - The number of literal context bits (high bits of previous literal).
- It can be in the range from 0 to 8. The default value is 3.
+lc - The number of literal context bits (high bits of previous literal).
+ It can be in the range from 0 to 8. The default value is 3.
Sometimes lc=4 gives the gain for big files.
lp - The number of literal pos bits (low bits of current position for literals).
- It can be in the range from 0 to 4. The default value is 0.
- The lp switch is intended for periodical data when the period is equal to 2^lp.
- For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's
+ It can be in the range from 0 to 4. The default value is 0.
+ The lp switch is intended for periodical data when the period is equal to 2^lp.
+ For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's
better to set lc=0, if you change lp switch.
-pb - The number of pos bits (low bits of current position).
- It can be in the range from 0 to 4. The default value is 2.
- The pb switch is intended for periodical data when the period is equal 2^pb.
+pb - The number of pos bits (low bits of current position).
+ It can be in the range from 0 to 4. The default value is 2.
+ The pb switch is intended for periodical data when the period is equal 2^pb.
-fb - Word size (the number of fast bytes).
+fb - Word size (the number of fast bytes).
It can be in the range from 5 to 273. The default value is 32.
- Usually, a big number gives a little bit better compression ratio and
- slower compression process.
+ Usually, a big number gives a little bit better compression ratio and
+ slower compression process.
numThreads - The number of thereads. 1 or 2. The default value is 2.
Fast mode (algo = 0) can use only 1 thread.
-Out:
- destLen - processed output size
+Out:
+ destLen - processed output size
Returns:
SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_MEM - Memory allocation error
SZ_ERROR_PARAM - Incorrect paramater
SZ_ERROR_OUTPUT_EOF - output buffer overflow
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
@@ -103,24 +103,24 @@ MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char
unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */
int level, /* 0 <= level <= 9, default = 5 */
unsigned dictSize, /* default = (1 << 24) */
- int lc, /* 0 <= lc <= 8, default = 3 */
- int lp, /* 0 <= lp <= 4, default = 0 */
- int pb, /* 0 <= pb <= 4, default = 2 */
+ int lc, /* 0 <= lc <= 8, default = 3 */
+ int lp, /* 0 <= lp <= 4, default = 0 */
+ int pb, /* 0 <= pb <= 4, default = 2 */
int fb, /* 5 <= fb <= 273, default = 32 */
int numThreads /* 1 or 2, default = 2 */
);
-/*
+/*
LzmaUncompress
--------------
-In:
+In:
dest - output data
destLen - output data size
src - input data
srcLen - input data size
-Out:
- destLen - processed output size
- srcLen - processed input size
+Out:
+ destLen - processed output size
+ srcLen - processed input size
Returns:
SZ_OK - OK
SZ_ERROR_DATA - Data error
@@ -129,7 +129,7 @@ Returns:
SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer (src)
*/
-MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,
+MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,
const unsigned char *props, size_t propsSize);
#endif
diff --git a/C/LzmaLib/makefile b/C/LzmaLib/makefile
index 01c86cb3..1e6b40cc 100755
--- a/C/LzmaLib/makefile
+++ b/C/LzmaLib/makefile
@@ -28,7 +28,7 @@ OBJS = \
!include "../../CPP/Build.mak"
-$(SLIBPATH): $O $(OBJS)
+$(SLIBPATH): $O $(OBJS)
lib -out:$(SLIBPATH) $(OBJS) $(LIBS)
$(LIB_OBJS): $(*B).c
diff --git a/C/LzmaUtil/Lzma86Dec.h b/C/LzmaUtil/Lzma86Dec.h
index 702a37ba..f7118219 100755
--- a/C/LzmaUtil/Lzma86Dec.h
+++ b/C/LzmaUtil/Lzma86Dec.h
@@ -1,5 +1,5 @@
/* Lzma86Dec.h -- LZMA + x86 (BCJ) Filter Decoder
-2008-04-07
+2008-08-05
Igor Pavlov
Public domain */
@@ -10,10 +10,10 @@ Public domain */
/*
Lzma86_GetUnpackSize:
- In:
+ In:
src - input data
srcLen - input data size
- Out:
+ Out:
unpackSize - size of uncompressed stream
Return code:
SZ_OK - OK
@@ -24,14 +24,14 @@ SRes Lzma86_GetUnpackSize(const Byte *src, SizeT srcLen, UInt64 *unpackSize);
/*
Lzma86_Decode:
- In:
+ In:
dest - output data
destLen - output data size
src - input data
srcLen - input data size
- Out:
- destLen - processed output size
- srcLen - processed input size
+ Out:
+ destLen - processed output size
+ srcLen - processed input size
Return code:
SZ_OK - OK
SZ_ERROR_DATA - Data error
diff --git a/C/LzmaUtil/Lzma86Enc.c b/C/LzmaUtil/Lzma86Enc.c
index f058e38f..efc81ea3 100755
--- a/C/LzmaUtil/Lzma86Enc.c
+++ b/C/LzmaUtil/Lzma86Enc.c
@@ -1,5 +1,5 @@
/* Lzma86Enc.c -- LZMA + x86 (BCJ) Filter Encoder
-2008-04-07
+2008-08-05
Igor Pavlov
Public domain */
@@ -20,7 +20,7 @@ static ISzAlloc g_Alloc = { SzAlloc, SzFree };
#define LZMA86_SIZE_OFFSET (1 + LZMA_PROPS_SIZE)
#define LZMA86_HEADER_SIZE (LZMA86_SIZE_OFFSET + 8)
-int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
+int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
int level, UInt32 dictSize, int filterMode)
{
size_t outSize2 = *destLen;
@@ -32,7 +32,7 @@ int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
props.level = level;
props.dictSize = dictSize;
- *destLen = 0;
+ *destLen = 0;
if (outSize2 < LZMA86_HEADER_SIZE)
return SZ_ERROR_OUTPUT_EOF;
@@ -66,8 +66,8 @@ int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
Bool bestIsFiltered = False;
/* passes for SZ_FILTER_AUTO:
- 0 - BCJ + LZMA
- 1 - LZMA
+ 0 - BCJ + LZMA
+ 1 - LZMA
2 - BCJ + LZMA agaian, if pass 0 (BCJ + LZMA) is better.
*/
int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1;
@@ -84,9 +84,9 @@ int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
if (useFilter && i == 0)
curModeIsFiltered = True;
- curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed,
+ curRes = LzmaEncode(dest + LZMA86_HEADER_SIZE, &outSizeProcessed,
curModeIsFiltered ? filteredStream : src, srcLen,
- &props, dest + 1, &outPropsSize, 0,
+ &props, dest + 1, &outPropsSize, 0,
NULL, &g_Alloc, &g_Alloc);
if (curRes != SZ_ERROR_OUTPUT_EOF)
@@ -95,7 +95,7 @@ int Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
{
mainResult = curRes;
break;
- }
+ }
if (outSizeProcessed <= minSize || mainResult != SZ_OK)
{
minSize = outSizeProcessed;
diff --git a/C/LzmaUtil/Lzma86Enc.h b/C/LzmaUtil/Lzma86Enc.h
index 03258782..10be1cd7 100755
--- a/C/LzmaUtil/Lzma86Enc.h
+++ b/C/LzmaUtil/Lzma86Enc.h
@@ -1,5 +1,5 @@
/* Lzma86Enc.h -- LZMA + x86 (BCJ) Filter Encoder
-2008-04-07
+2008-08-05
Igor Pavlov
Public domain */
@@ -14,7 +14,7 @@ You can use .lzma86 extension, if you write that stream to file.
.lzma86 header adds one additional byte to standard .lzma header.
.lzma86 header (14 bytes):
Offset Size Description
- 0 1 = 0 - no filter,
+ 0 1 = 0 - no filter,
= 1 - x86 filter
1 1 lc, lp and pb in encoded form
2 4 dictSize (little endian)
@@ -26,25 +26,25 @@ Lzma86_Encode
level - compression level: 0 <= level <= 9, the default value for "level" is 5.
-dictSize - The dictionary size in bytes. The maximum value is
+dictSize - The dictionary size in bytes. The maximum value is
128 MB = (1 << 27) bytes for 32-bit version
1 GB = (1 << 30) bytes for 64-bit version
The default value is 16 MB = (1 << 24) bytes, for level = 5.
- It's recommended to use the dictionary that is larger than 4 KB and
- that can be calculated as (1 << N) or (3 << N) sizes.
+ It's recommended to use the dictionary that is larger than 4 KB and
+ that can be calculated as (1 << N) or (3 << N) sizes.
For better compression ratio dictSize must be >= inSize.
filterMode:
SZ_FILTER_NO - no Filter
SZ_FILTER_YES - x86 Filter
- SZ_FILTER_AUTO - it tries both alternatives to select best.
+ SZ_FILTER_AUTO - it tries both alternatives to select best.
Encoder will use 2 or 3 passes:
2 passes when FILTER_NO provides better compression.
3 passes when FILTER_YES provides better compression.
Lzma86Encode allocates Data with MyAlloc functions.
RAM Requirements for compressing:
- RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize
+ RamSize = dictionarySize * 11.5 + 6MB + FilterBlockSize
filterMode FilterBlockSize
SZ_FILTER_NO 0
SZ_FILTER_YES inSize
@@ -53,20 +53,20 @@ RAM Requirements for compressing:
Return code:
SZ_OK - OK
- SZ_ERROR_MEM - Memory allocation error
+ SZ_ERROR_MEM - Memory allocation error
SZ_ERROR_PARAM - Incorrect paramater
SZ_ERROR_OUTPUT_EOF - output buffer overflow
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
*/
-enum ESzFilterMode
+enum ESzFilterMode
{
SZ_FILTER_NO,
SZ_FILTER_YES,
SZ_FILTER_AUTO
};
-SRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
+SRes Lzma86_Encode(Byte *dest, size_t *destLen, const Byte *src, size_t srcLen,
int level, UInt32 dictSize, int filterMode);
#endif
diff --git a/C/LzmaUtil/LzmaUtil.c b/C/LzmaUtil/LzmaUtil.c
index a7f3bdff..a6fa0a2b 100755
--- a/C/LzmaUtil/LzmaUtil.c
+++ b/C/LzmaUtil/LzmaUtil.c
@@ -1,5 +1,5 @@
/* LzmaUtil.c -- Test application for LZMA compression
-2008-04-29
+2008-08-05
Igor Pavlov
public domain */
@@ -35,10 +35,10 @@ int MyReadFileAndCheck(FILE *file, void *data, size_t size)
{ return (MyReadFile(file, data, size) == size); }
size_t MyWriteFile(FILE *file, const void *data, size_t size)
-{
+{
if (size == 0)
return 0;
- return fwrite(data, 1, size, file);
+ return fwrite(data, 1, size, file);
}
int MyWriteFileAndCheck(FILE *file, const void *data, size_t size)
@@ -137,7 +137,7 @@ static int Decode(FILE *inFile, FILE *outFile, char *rs)
finishMode = LZMA_FINISH_END;
}
- res = LzmaDec_DecodeToBuf(&state, outBuf + outPos, &outProcessed,
+ res = LzmaDec_DecodeToBuf(&state, outBuf + outPos, &outProcessed,
inBuf + inPos, &inProcessed, finishMode, &status);
inPos += (UInt32)inProcessed;
outPos += outProcessed;
@@ -228,7 +228,7 @@ static SRes Encode(FILE *inFile, FILE *outFile, char *rs)
return PrintError(rs, "writing error");
if (res == SZ_OK)
- res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable,
+ res = LzmaEnc_Encode(enc, &outStream.funcTable, &inStream.funcTable,
NULL, &g_Alloc, &g_Alloc);
}
LzmaEnc_Destroy(enc, &g_Alloc, &g_Alloc);
diff --git a/C/LzmaUtil/makefile.gcc b/C/LzmaUtil/makefile.gcc
index bfcdc3c3..1d3442bc 100755
--- a/C/LzmaUtil/makefile.gcc
+++ b/C/LzmaUtil/makefile.gcc
@@ -1,6 +1,6 @@
PROG = lzma
CXX = g++
-LIB =
+LIB =
RM = rm -f
CFLAGS = -c -O2 -Wall
diff --git a/C/RotateDefs.h b/C/RotateDefs.h
index cd666271..95d9646b 100755
--- a/C/RotateDefs.h
+++ b/C/RotateDefs.h
@@ -1,6 +1,6 @@
-/* RotateDefs.h -- Rotate functions
-2008-03-24
-Igor Pavlov
+/* RotateDefs.h -- Rotate functions
+2008-08-05
+Igor Pavlov
Public domain */
#ifndef __ROTATEDEFS_H
diff --git a/C/Sha256.c b/C/Sha256.c
index f052c0ec..f4692072 100755
--- a/C/Sha256.c
+++ b/C/Sha256.c
@@ -1,7 +1,7 @@
/* Crypto/Sha256.c -- SHA-256 Hash function
-2008-03-24
+2008-08-05
This code is based on public domain code from Wei Dai's Crypto++ library.
-Igor Pavlov
+Igor Pavlov
Public domain */
#include "Sha256.h"
@@ -151,7 +151,7 @@ static void Sha256_WriteByteBlock(CSha256 *p)
UInt32 data32[16];
unsigned i;
for (i = 0; i < 16; i++)
- data32[i] =
+ data32[i] =
((UInt32)(p->buffer[i * 4 ]) << 24) +
((UInt32)(p->buffer[i * 4 + 1]) << 16) +
((UInt32)(p->buffer[i * 4 + 2]) << 8) +
diff --git a/C/Sha256.h b/C/Sha256.h
index 37d6b059..9f4080f9 100755
--- a/C/Sha256.h
+++ b/C/Sha256.h
@@ -1,6 +1,6 @@
/* Crypto/Sha256.h -- SHA-256 Hash function
-2008-03-24
-Igor Pavlov
+2008-08-05
+Igor Pavlov
Public domain */
#ifndef __CRYPTO_SHA256_H
diff --git a/C/Sort.c b/C/Sort.c
index 15e4c6e3..8438c787 100755
--- a/C/Sort.c
+++ b/C/Sort.c
@@ -44,7 +44,7 @@ void HeapSort(UInt32 *p, UInt32 size)
UInt32 temp = p[size];
UInt32 k = (p[3] > p[2]) ? 3 : 2;
p[size--] = p[1];
- p[1] = p[k];
+ p[1] = p[k];
HeapSortDown(p, k, size, temp)
}
{
diff --git a/C/Threads.c b/C/Threads.c
index 237f3f90..4fdd69b0 100755
--- a/C/Threads.c
+++ b/C/Threads.c
@@ -1,5 +1,5 @@
/* Threads.c -- multithreading library
-2008-04-04
+2008-08-05
Igor Pavlov
Public domain */
@@ -25,9 +25,9 @@ static WRes MyCloseHandle(HANDLE *h)
}
WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE *startAddress)(void *), LPVOID parameter)
-{
+{
unsigned threadId; /* Windows Me/98/95: threadId parameter may not be NULL in _beginthreadex/CreateThread functions */
- thread->handle =
+ thread->handle =
/* CreateThread(0, 0, startAddress, parameter, 0, &threadId); */
(HANDLE)_beginthreadex(NULL, 0, startAddress, parameter, 0, &threadId);
/* maybe we must use errno here, but probably GetLastError() is also OK. */
@@ -36,14 +36,14 @@ WRes Thread_Create(CThread *thread, THREAD_FUNC_RET_TYPE (THREAD_FUNC_CALL_TYPE
WRes WaitObject(HANDLE h)
{
- return (WRes)WaitForSingleObject(h, INFINITE);
+ return (WRes)WaitForSingleObject(h, INFINITE);
}
WRes Thread_Wait(CThread *thread)
{
if (thread->handle == NULL)
return 1;
- return WaitObject(thread->handle);
+ return WaitObject(thread->handle);
}
WRes Thread_Close(CThread *thread)
@@ -59,12 +59,12 @@ WRes Event_Create(CEvent *p, BOOL manualReset, int initialSignaled)
WRes ManualResetEvent_Create(CManualResetEvent *p, int initialSignaled)
{ return Event_Create(p, TRUE, initialSignaled); }
-WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p)
+WRes ManualResetEvent_CreateNotSignaled(CManualResetEvent *p)
{ return ManualResetEvent_Create(p, 0); }
WRes AutoResetEvent_Create(CAutoResetEvent *p, int initialSignaled)
{ return Event_Create(p, FALSE, initialSignaled); }
-WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p)
+WRes AutoResetEvent_CreateNotSignaled(CAutoResetEvent *p)
{ return AutoResetEvent_Create(p, 0); }
WRes Event_Set(CEvent *p) { return BOOLToWRes(SetEvent(p->handle)); }
@@ -79,9 +79,9 @@ WRes Semaphore_Create(CSemaphore *p, UInt32 initiallyCount, UInt32 maxCount)
return HandleToWRes(p->handle);
}
-WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)
-{
- return BOOLToWRes(ReleaseSemaphore(p->handle, releaseCount, previousCount));
+WRes Semaphore_Release(CSemaphore *p, LONG releaseCount, LONG *previousCount)
+{
+ return BOOLToWRes(ReleaseSemaphore(p->handle, releaseCount, previousCount));
}
WRes Semaphore_ReleaseN(CSemaphore *p, UInt32 releaseCount)
{
@@ -98,11 +98,11 @@ WRes Semaphore_Close(CSemaphore *p) { return MyCloseHandle(&p->handle); }
WRes CriticalSection_Init(CCriticalSection *p)
{
/* InitializeCriticalSection can raise only STATUS_NO_MEMORY exception */
- __try
- {
- InitializeCriticalSection(p);
+ __try
+ {
+ InitializeCriticalSection(p);
/* InitializeCriticalSectionAndSpinCount(p, 0); */
- }
+ }
__except (EXCEPTION_EXECUTE_HANDLER) { return 1; }
return 0;
}
diff --git a/C/Types.h b/C/Types.h
index 956e2721..3d703f6b 100755
--- a/C/Types.h
+++ b/C/Types.h
@@ -1,5 +1,5 @@
/* Types.h -- Basic types
-2008-04-11
+2008-08-05
Igor Pavlov
Public domain */
@@ -83,8 +83,8 @@ typedef int Bool;
#endif
#define MY_CDECL __cdecl
-#define MY_STD_CALL __stdcall
-#define MY_FAST_CALL MY_NO_INLINE __fastcall
+#define MY_STD_CALL __stdcall
+#define MY_FAST_CALL MY_NO_INLINE __fastcall
#else