4.59 beta

This commit is contained in:
Igor Pavlov
2008-08-13 00:00:00 +00:00
committed by Kornel Lesiński
parent 3901bf0ab8
commit 173c07e166
781 changed files with 22124 additions and 13650 deletions

View File

@@ -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;
}

14
C/Aes.c
View File

@@ -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)]] ^

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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) */

View File

@@ -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

View File

@@ -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)
{

View File

@@ -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,

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -1,6 +1,6 @@
PROG = 7zDec
CXX = g++
LIB =
LIB =
RM = rm -f
CFLAGS = -c -O2 -Wall

View File

@@ -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)

View File

@@ -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

10
C/Bra.c
View File

@@ -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) |

14
C/Bra.h
View File

@@ -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;

View File

@@ -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)

View File

@@ -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;

View File

@@ -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

View File

@@ -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]]++;
}
}

View File

@@ -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] =

View File

@@ -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

View File

@@ -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
}

View File

@@ -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);

View File

@@ -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;

View File

@@ -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

View File

File diff suppressed because it is too large Load Diff

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -28,7 +28,7 @@ OBJS = \
!include "../../CPP/Build.mak"
$(SLIBPATH): $O $(OBJS)
$(SLIBPATH): $O $(OBJS)
lib -out:$(SLIBPATH) $(OBJS) $(LIBS)
$(LIB_OBJS): $(*B).c

View File

@@ -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

View File

@@ -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;

View File

@@ -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

View File

@@ -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);

View File

@@ -1,6 +1,6 @@
PROG = lzma
CXX = g++
LIB =
LIB =
RM = rm -f
CFLAGS = -c -O2 -Wall

View File

@@ -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

View File

@@ -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) +

View File

@@ -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

View File

@@ -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)
}
{

View File

@@ -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;
}

View File

@@ -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