Reformat SevenZip (Resharper)

This commit is contained in:
Vladimir Kononovich 2020-12-19 23:32:06 +03:00
parent 4925698573
commit 68c88a6b7c
35 changed files with 5095 additions and 5064 deletions

View file

@ -15,7 +15,7 @@ extern const Byte k7zSignature[k7zSignatureSize];
typedef struct typedef struct
{ {
const Byte *Data; const Byte* Data;
size_t Size; size_t Size;
} CSzData; } CSzData;
@ -51,7 +51,7 @@ typedef struct
} CSzFolder; } CSzFolder;
SRes SzGetNextFolderItem(CSzFolder *f, CSzData *sd); SRes SzGetNextFolderItem(CSzFolder* f, CSzData* sd);
typedef struct typedef struct
{ {
@ -61,15 +61,15 @@ typedef struct
typedef struct typedef struct
{ {
Byte *Defs; /* MSB 0 bit numbering */ Byte* Defs; /* MSB 0 bit numbering */
UInt32 *Vals; UInt32* Vals;
} CSzBitUi32s; } CSzBitUi32s;
typedef struct typedef struct
{ {
Byte *Defs; /* MSB 0 bit numbering */ Byte* Defs; /* MSB 0 bit numbering */
// UInt64 *Vals; // UInt64 *Vals;
CNtfsFileTime *Vals; CNtfsFileTime* Vals;
} CSzBitUi64s; } CSzBitUi64s;
#define SzBitArray_Check(p, i) (((p)[(i) >> 3] & (0x80 >> ((i) & 7))) != 0) #define SzBitArray_Check(p, i) (((p)[(i) >> 3] & (0x80 >> ((i) & 7))) != 0)
@ -81,24 +81,24 @@ typedef struct
UInt32 NumPackStreams; UInt32 NumPackStreams;
UInt32 NumFolders; UInt32 NumFolders;
UInt64 *PackPositions; // NumPackStreams + 1 UInt64* PackPositions; // NumPackStreams + 1
CSzBitUi32s FolderCRCs; // NumFolders CSzBitUi32s FolderCRCs; // NumFolders
size_t *FoCodersOffsets; // NumFolders + 1 size_t* FoCodersOffsets; // NumFolders + 1
UInt32 *FoStartPackStreamIndex; // NumFolders + 1 UInt32* FoStartPackStreamIndex; // NumFolders + 1
UInt32 *FoToCoderUnpackSizes; // NumFolders + 1 UInt32* FoToCoderUnpackSizes; // NumFolders + 1
Byte *FoToMainUnpackSizeIndex; // NumFolders Byte* FoToMainUnpackSizeIndex; // NumFolders
UInt64 *CoderUnpackSizes; // for all coders in all folders UInt64* CoderUnpackSizes; // for all coders in all folders
Byte *CodersData; Byte* CodersData;
} CSzAr; } CSzAr;
UInt64 SzAr_GetFolderUnpackSize(const CSzAr *p, UInt32 folderIndex); UInt64 SzAr_GetFolderUnpackSize(const CSzAr* p, UInt32 folderIndex);
SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex, SRes SzAr_DecodeFolder(const CSzAr* p, UInt32 folderIndex,
ILookInStream *stream, UInt64 startPos, ILookInStream* stream, UInt64 startPos,
Byte *outBuffer, size_t outSize, Byte* outBuffer, size_t outSize,
ISzAlloc *allocMain); ISzAlloc* allocMain);
typedef struct typedef struct
{ {
@ -109,9 +109,9 @@ typedef struct
UInt32 NumFiles; UInt32 NumFiles;
UInt64 *UnpackPositions; // NumFiles + 1 UInt64* UnpackPositions; // NumFiles + 1
// Byte *IsEmptyFiles; // Byte *IsEmptyFiles;
Byte *IsDirs; Byte* IsDirs;
CSzBitUi32s CRCs; CSzBitUi32s CRCs;
CSzBitUi32s Attribs; CSzBitUi32s Attribs;
@ -119,21 +119,21 @@ typedef struct
CSzBitUi64s MTime; CSzBitUi64s MTime;
CSzBitUi64s CTime; CSzBitUi64s CTime;
UInt32 *FolderToFile; // NumFolders + 1 UInt32* FolderToFile; // NumFolders + 1
UInt32 *FileToFolder; // NumFiles UInt32* FileToFolder; // NumFiles
size_t *FileNameOffsets; /* in 2-byte steps */ size_t* FileNameOffsets; /* in 2-byte steps */
Byte *FileNames; /* UTF-16-LE */ Byte* FileNames; /* UTF-16-LE */
} CSzArEx; } CSzArEx;
#define SzArEx_IsDir(p, i) (SzBitArray_Check((p)->IsDirs, i)) #define SzArEx_IsDir(p, i) (SzBitArray_Check((p)->IsDirs, i))
#define SzArEx_GetFileSize(p, i) ((p)->UnpackPositions[(i) + 1] - (p)->UnpackPositions[i]) #define SzArEx_GetFileSize(p, i) ((p)->UnpackPositions[(i) + 1] - (p)->UnpackPositions[i])
void SzArEx_Init(CSzArEx *p); void SzArEx_Init(CSzArEx* p);
void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc); void SzArEx_Free(CSzArEx* p, ISzAlloc* alloc);
UInt64 SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder); UInt64 SzArEx_GetFolderStreamPos(const CSzArEx* p, UInt32 folderIndex, UInt32 indexInFolder);
int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, UInt64 *resSize); int SzArEx_GetFolderFullPackSize(const CSzArEx* p, UInt32 folderIndex, UInt64* resSize);
/* /*
if dest == NULL, the return value specifies the required size of the buffer, if dest == NULL, the return value specifies the required size of the buffer,
@ -141,7 +141,7 @@ if dest == NULL, the return value specifies the required size of the buffer,
if dest != NULL, the return value specifies the number of 16-bit characters that if dest != NULL, the return value specifies the number of 16-bit characters that
are written to the dest, including the null-terminating character. */ are written to the dest, including the null-terminating character. */
size_t SzArEx_GetFileNameUtf16(const CSzArEx *p, size_t fileIndex, UInt16 *dest); size_t SzArEx_GetFileNameUtf16(const CSzArEx* p, size_t fileIndex, UInt16* dest);
/* /*
size_t SzArEx_GetFullNameLen(const CSzArEx *p, size_t fileIndex); size_t SzArEx_GetFullNameLen(const CSzArEx *p, size_t fileIndex);
@ -149,7 +149,6 @@ UInt16 *SzArEx_GetFullNameUtf16_Back(const CSzArEx *p, size_t fileIndex, UInt16
*/ */
/* /*
SzArEx_Extract extracts file from archive SzArEx_Extract extracts file from archive
@ -171,16 +170,16 @@ UInt16 *SzArEx_GetFullNameUtf16_Back(const CSzArEx *p, size_t fileIndex, UInt16
*/ */
SRes SzArEx_Extract( SRes SzArEx_Extract(
const CSzArEx *db, const CSzArEx* db,
ILookInStream *inStream, ILookInStream* inStream,
UInt32 fileIndex, /* index of file */ UInt32 fileIndex, /* index of file */
UInt32 *blockIndex, /* index of solid block */ UInt32* blockIndex, /* index of solid block */
Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */ Byte** outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
size_t *outBufferSize, /* buffer size for output buffer */ size_t* outBufferSize, /* buffer size for output buffer */
size_t *offset, /* offset of stream for required file in *outBuffer */ size_t* offset, /* offset of stream for required file in *outBuffer */
size_t *outSizeProcessed, /* size of file in *outBuffer */ size_t* outSizeProcessed, /* size of file in *outBuffer */
ISzAlloc *allocMain, ISzAlloc* allocMain,
ISzAlloc *allocTemp); ISzAlloc* allocTemp);
/* /*
@ -194,8 +193,8 @@ SZ_ERROR_INPUT_EOF
SZ_ERROR_FAIL SZ_ERROR_FAIL
*/ */
SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, SRes SzArEx_Open(CSzArEx* p, ILookInStream* inStream,
ISzAlloc *allocMain, ISzAlloc *allocTemp); ISzAlloc* allocMain, ISzAlloc* allocTemp);
EXTERN_C_END EXTERN_C_END

View file

@ -20,59 +20,59 @@ int g_allocCountTemp = 0;
#endif #endif
void *SzAlloc(void *p, size_t size) void* SzAlloc(void* p, size_t size)
{ {
UNUSED_VAR(p); UNUSED_VAR(p);
if (size == 0) if (size == 0)
return 0; return 0;
#ifdef _SZ_ALLOC_DEBUG #ifdef _SZ_ALLOC_DEBUG
fprintf(stderr, "\nAlloc %10u bytes; count = %10d", (unsigned)size, g_allocCount); fprintf(stderr, "\nAlloc %10u bytes; count = %10d", (unsigned)size, g_allocCount);
g_allocCount++; g_allocCount++;
#endif #endif
return malloc(size); return malloc(size);
} }
void SzFree(void *p, void *address) void SzFree(void* p, void* address)
{ {
UNUSED_VAR(p); UNUSED_VAR(p);
#ifdef _SZ_ALLOC_DEBUG #ifdef _SZ_ALLOC_DEBUG
if (address != 0) if (address != 0)
{ {
g_allocCount--; g_allocCount--;
fprintf(stderr, "\nFree; count = %10d", g_allocCount); fprintf(stderr, "\nFree; count = %10d", g_allocCount);
} }
#endif #endif
free(address); free(address);
} }
void *SzAllocTemp(void *p, size_t size) void* SzAllocTemp(void* p, size_t size)
{ {
UNUSED_VAR(p); UNUSED_VAR(p);
if (size == 0) if (size == 0)
return 0; return 0;
#ifdef _SZ_ALLOC_DEBUG #ifdef _SZ_ALLOC_DEBUG
fprintf(stderr, "\nAlloc_temp %10u bytes; count = %10d", (unsigned)size, g_allocCountTemp); fprintf(stderr, "\nAlloc_temp %10u bytes; count = %10d", (unsigned)size, g_allocCountTemp);
g_allocCountTemp++; g_allocCountTemp++;
#ifdef _WIN32 #ifdef _WIN32
return HeapAlloc(GetProcessHeap(), 0, size); return HeapAlloc(GetProcessHeap(), 0, size);
#endif #endif
#endif #endif
return malloc(size); return malloc(size);
} }
void SzFreeTemp(void *p, void *address) void SzFreeTemp(void* p, void* address)
{ {
UNUSED_VAR(p); UNUSED_VAR(p);
#ifdef _SZ_ALLOC_DEBUG #ifdef _SZ_ALLOC_DEBUG
if (address != 0) if (address != 0)
{ {
g_allocCountTemp--; g_allocCountTemp--;
fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp); fprintf(stderr, "\nFree_temp; count = %10d", g_allocCountTemp);
} }
#ifdef _WIN32 #ifdef _WIN32
HeapFree(GetProcessHeap(), 0, address); HeapFree(GetProcessHeap(), 0, address);
return; return;
#endif #endif
#endif #endif
free(address); free(address);
} }

View file

@ -10,11 +10,11 @@
extern "C" { extern "C" {
#endif #endif
void *SzAlloc(void *p, size_t size); void* SzAlloc(void* p, size_t size);
void SzFree(void *p, void *address); void SzFree(void* p, void* address);
void *SzAllocTemp(void *p, size_t size); void* SzAllocTemp(void* p, size_t size);
void SzFreeTemp(void *p, void *address); void SzFreeTemp(void* p, void* address);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -60,7 +60,7 @@ const Byte k7zSignature[k7zSignatureSize] = {'7', 'z', 0xBC, 0xAF, 0x27, 0x1C};
#define SzBitUi32s_Init(p) { (p)->Defs = NULL; (p)->Vals = NULL; } #define SzBitUi32s_Init(p) { (p)->Defs = NULL; (p)->Vals = NULL; }
static SRes SzBitUi32s_Alloc(CSzBitUi32s *p, size_t num, ISzAlloc *alloc) static SRes SzBitUi32s_Alloc(CSzBitUi32s* p, size_t num, ISzAlloc* alloc)
{ {
if (num == 0) if (num == 0)
{ {
@ -75,22 +75,26 @@ static SRes SzBitUi32s_Alloc(CSzBitUi32s *p, size_t num, ISzAlloc *alloc)
return SZ_OK; return SZ_OK;
} }
void SzBitUi32s_Free(CSzBitUi32s *p, ISzAlloc *alloc) void SzBitUi32s_Free(CSzBitUi32s* p, ISzAlloc* alloc)
{ {
IAlloc_Free(alloc, p->Defs); p->Defs = NULL; IAlloc_Free(alloc, p->Defs);
IAlloc_Free(alloc, p->Vals); p->Vals = NULL; p->Defs = NULL;
IAlloc_Free(alloc, p->Vals);
p->Vals = NULL;
} }
#define SzBitUi64s_Init(p) { (p)->Defs = NULL; (p)->Vals = NULL; } #define SzBitUi64s_Init(p) { (p)->Defs = NULL; (p)->Vals = NULL; }
void SzBitUi64s_Free(CSzBitUi64s *p, ISzAlloc *alloc) void SzBitUi64s_Free(CSzBitUi64s* p, ISzAlloc* alloc)
{ {
IAlloc_Free(alloc, p->Defs); p->Defs = NULL; IAlloc_Free(alloc, p->Defs);
IAlloc_Free(alloc, p->Vals); p->Vals = NULL; p->Defs = NULL;
IAlloc_Free(alloc, p->Vals);
p->Vals = NULL;
} }
static void SzAr_Init(CSzAr *p) static void SzAr_Init(CSzAr* p)
{ {
p->NumPackStreams = 0; p->NumPackStreams = 0;
p->NumFolders = 0; p->NumFolders = 0;
@ -107,7 +111,7 @@ static void SzAr_Init(CSzAr *p)
p->CodersData = NULL; p->CodersData = NULL;
} }
static void SzAr_Free(CSzAr *p, ISzAlloc *alloc) static void SzAr_Free(CSzAr* p, ISzAlloc* alloc)
{ {
IAlloc_Free(alloc, p->PackPositions); IAlloc_Free(alloc, p->PackPositions);
SzBitUi32s_Free(&p->FolderCRCs, alloc); SzBitUi32s_Free(&p->FolderCRCs, alloc);
@ -124,7 +128,7 @@ static void SzAr_Free(CSzAr *p, ISzAlloc *alloc)
} }
void SzArEx_Init(CSzArEx *p) void SzArEx_Init(CSzArEx* p)
{ {
SzAr_Init(&p->db); SzAr_Init(&p->db);
@ -147,7 +151,7 @@ void SzArEx_Init(CSzArEx *p)
SzBitUi64s_Init(&p->CTime); SzBitUi64s_Init(&p->CTime);
} }
void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc) void SzArEx_Free(CSzArEx* p, ISzAlloc* alloc)
{ {
IAlloc_Free(alloc, p->UnpackPositions); IAlloc_Free(alloc, p->UnpackPositions);
IAlloc_Free(alloc, p->IsDirs); IAlloc_Free(alloc, p->IsDirs);
@ -169,7 +173,7 @@ void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc)
} }
static int TestSignatureCandidate(const Byte *testBytes) static int TestSignatureCandidate(const Byte* testBytes)
{ {
unsigned i; unsigned i;
for (i = 0; i < k7zSignatureSize; i++) for (i = 0; i < k7zSignatureSize; i++)
@ -190,7 +194,7 @@ static int TestSignatureCandidate(const Byte *testBytes)
#define SZ_READ_32(dest) if (sd.Size < 4) return SZ_ERROR_ARCHIVE; \ #define SZ_READ_32(dest) if (sd.Size < 4) return SZ_ERROR_ARCHIVE; \
dest = GetUi32(sd.Data); SKIP_DATA2(sd, 4); dest = GetUi32(sd.Data); SKIP_DATA2(sd, 4);
static MY_NO_INLINE SRes ReadNumber(CSzData *sd, UInt64 *value) static MY_NO_INLINE SRes ReadNumber(CSzData* sd, UInt64* value)
{ {
Byte firstByte, mask; Byte firstByte, mask;
unsigned i; unsigned i;
@ -228,7 +232,7 @@ static MY_NO_INLINE SRes ReadNumber(CSzData *sd, UInt64 *value)
} }
static MY_NO_INLINE SRes SzReadNumber32(CSzData *sd, UInt32 *value) static MY_NO_INLINE SRes SzReadNumber32(CSzData* sd, UInt32* value)
{ {
Byte firstByte; Byte firstByte;
UInt64 value64; UInt64 value64;
@ -253,7 +257,7 @@ static MY_NO_INLINE SRes SzReadNumber32(CSzData *sd, UInt32 *value)
#define ReadID(sd, value) ReadNumber(sd, value) #define ReadID(sd, value) ReadNumber(sd, value)
static SRes SkipData(CSzData *sd) static SRes SkipData(CSzData* sd)
{ {
UInt64 size; UInt64 size;
RINOK(ReadNumber(sd, &size)); RINOK(ReadNumber(sd, &size));
@ -263,7 +267,7 @@ static SRes SkipData(CSzData *sd)
return SZ_OK; return SZ_OK;
} }
static SRes WaitId(CSzData *sd, UInt32 id) static SRes WaitId(CSzData* sd, UInt32 id)
{ {
for (;;) for (;;)
{ {
@ -277,7 +281,7 @@ static SRes WaitId(CSzData *sd, UInt32 id)
} }
} }
static SRes RememberBitVector(CSzData *sd, UInt32 numItems, const Byte **v) static SRes RememberBitVector(CSzData* sd, UInt32 numItems, const Byte** v)
{ {
UInt32 numBytes = (numItems + 7) >> 3; UInt32 numBytes = (numItems + 7) >> 3;
if (numBytes > sd->Size) if (numBytes > sd->Size)
@ -287,7 +291,7 @@ static SRes RememberBitVector(CSzData *sd, UInt32 numItems, const Byte **v)
return SZ_OK; return SZ_OK;
} }
static UInt32 CountDefinedBits(const Byte *bits, UInt32 numItems) static UInt32 CountDefinedBits(const Byte* bits, UInt32 numItems)
{ {
Byte b = 0; Byte b = 0;
unsigned m = 0; unsigned m = 0;
@ -305,10 +309,10 @@ static UInt32 CountDefinedBits(const Byte *bits, UInt32 numItems)
return sum; return sum;
} }
static MY_NO_INLINE SRes ReadBitVector(CSzData *sd, UInt32 numItems, Byte **v, ISzAlloc *alloc) static MY_NO_INLINE SRes ReadBitVector(CSzData* sd, UInt32 numItems, Byte** v, ISzAlloc* alloc)
{ {
Byte allAreDefined; Byte allAreDefined;
Byte *v2; Byte* v2;
UInt32 numBytes = (numItems + 7) >> 3; UInt32 numBytes = (numItems + 7) >> 3;
*v = NULL; *v = NULL;
SZ_READ_BYTE(allAreDefined); SZ_READ_BYTE(allAreDefined);
@ -333,12 +337,12 @@ static MY_NO_INLINE SRes ReadBitVector(CSzData *sd, UInt32 numItems, Byte **v, I
return SZ_OK; return SZ_OK;
} }
static MY_NO_INLINE SRes ReadUi32s(CSzData *sd2, UInt32 numItems, CSzBitUi32s *crcs, ISzAlloc *alloc) static MY_NO_INLINE SRes ReadUi32s(CSzData* sd2, UInt32 numItems, CSzBitUi32s* crcs, ISzAlloc* alloc)
{ {
UInt32 i; UInt32 i;
CSzData sd; CSzData sd;
UInt32 *vals; UInt32* vals;
const Byte *defs; const Byte* defs;
MY_ALLOC_ZE(UInt32, crcs->Vals, numItems, alloc); MY_ALLOC_ZE(UInt32, crcs->Vals, numItems, alloc);
sd = *sd2; sd = *sd2;
defs = crcs->Defs; defs = crcs->Defs;
@ -354,14 +358,14 @@ static MY_NO_INLINE SRes ReadUi32s(CSzData *sd2, UInt32 numItems, CSzBitUi32s *c
return SZ_OK; return SZ_OK;
} }
static SRes ReadBitUi32s(CSzData *sd, UInt32 numItems, CSzBitUi32s *crcs, ISzAlloc *alloc) static SRes ReadBitUi32s(CSzData* sd, UInt32 numItems, CSzBitUi32s* crcs, ISzAlloc* alloc)
{ {
SzBitUi32s_Free(crcs, alloc); SzBitUi32s_Free(crcs, alloc);
RINOK(ReadBitVector(sd, numItems, &crcs->Defs, alloc)); RINOK(ReadBitVector(sd, numItems, &crcs->Defs, alloc));
return ReadUi32s(sd, numItems, crcs, alloc); return ReadUi32s(sd, numItems, crcs, alloc);
} }
static SRes SkipBitUi32s(CSzData *sd, UInt32 numItems) static SRes SkipBitUi32s(CSzData* sd, UInt32 numItems)
{ {
Byte allAreDefined; Byte allAreDefined;
UInt32 numDefined = numItems; UInt32 numDefined = numItems;
@ -380,7 +384,7 @@ static SRes SkipBitUi32s(CSzData *sd, UInt32 numItems)
return SZ_OK; return SZ_OK;
} }
static SRes ReadPackInfo(CSzAr *p, CSzData *sd, ISzAlloc *alloc) static SRes ReadPackInfo(CSzAr* p, CSzData* sd, ISzAlloc* alloc)
{ {
RINOK(SzReadNumber32(sd, &p->NumPackStreams)); RINOK(SzReadNumber32(sd, &p->NumPackStreams));
@ -429,11 +433,11 @@ static SRes SzReadSwitch(CSzData *sd)
#define k_NumCodersStreams_in_Folder_MAX (SZ_NUM_BONDS_IN_FOLDER_MAX + SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX) #define k_NumCodersStreams_in_Folder_MAX (SZ_NUM_BONDS_IN_FOLDER_MAX + SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX)
SRes SzGetNextFolderItem(CSzFolder *f, CSzData *sd) SRes SzGetNextFolderItem(CSzFolder* f, CSzData* sd)
{ {
UInt32 numCoders, i; UInt32 numCoders, i;
UInt32 numInStreams = 0; UInt32 numInStreams = 0;
const Byte *dataStart = sd->Data; const Byte* dataStart = sd->Data;
f->NumCoders = 0; f->NumCoders = 0;
f->NumBonds = 0; f->NumBonds = 0;
@ -447,7 +451,7 @@ SRes SzGetNextFolderItem(CSzFolder *f, CSzData *sd)
for (i = 0; i < numCoders; i++) for (i = 0; i < numCoders; i++)
{ {
Byte mainByte; Byte mainByte;
CSzCoderInfo *coder = f->Coders + i; CSzCoderInfo* coder = f->Coders + i;
unsigned idSize, j; unsigned idSize, j;
UInt64 id; UInt64 id;
@ -545,7 +549,7 @@ SRes SzGetNextFolderItem(CSzFolder *f, CSzData *sd)
for (i = 0; i < numBonds; i++) for (i = 0; i < numBonds; i++)
{ {
CSzBond *bp = f->Bonds + i; CSzBond* bp = f->Bonds + i;
RINOK(SzReadNumber32(sd, &bp->InIndex)); RINOK(SzReadNumber32(sd, &bp->InIndex));
if (bp->InIndex >= numInStreams || streamUsed[bp->InIndex]) if (bp->InIndex >= numInStreams || streamUsed[bp->InIndex])
@ -596,7 +600,7 @@ SRes SzGetNextFolderItem(CSzFolder *f, CSzData *sd)
} }
static MY_NO_INLINE SRes SkipNumbers(CSzData *sd2, UInt32 num) static MY_NO_INLINE SRes SkipNumbers(CSzData* sd2, UInt32 num)
{ {
CSzData sd; CSzData sd;
sd = *sd2; sd = *sd2;
@ -631,16 +635,16 @@ static MY_NO_INLINE SRes SkipNumbers(CSzData *sd2, UInt32 num)
#define k_Scan_NumCodersStreams_in_Folder_MAX 64 #define k_Scan_NumCodersStreams_in_Folder_MAX 64
static SRes ReadUnpackInfo(CSzAr *p, static SRes ReadUnpackInfo(CSzAr* p,
CSzData *sd2, CSzData* sd2,
UInt32 numFoldersMax, UInt32 numFoldersMax,
const CBuf *tempBufs, UInt32 numTempBufs, const CBuf* tempBufs, UInt32 numTempBufs,
ISzAlloc *alloc) ISzAlloc* alloc)
{ {
CSzData sd; CSzData sd;
UInt32 fo, numFolders, numCodersOutStreams, packStreamIndex; UInt32 fo, numFolders, numCodersOutStreams, packStreamIndex;
const Byte *startBufPtr; const Byte* startBufPtr;
Byte external; Byte external;
RINOK(WaitId(sd2, k7zIdFolder)); RINOK(WaitId(sd2, k7zIdFolder));
@ -840,7 +844,7 @@ static SRes ReadUnpackInfo(CSzAr *p,
} }
UInt64 SzAr_GetFolderUnpackSize(const CSzAr *p, UInt32 folderIndex) UInt64 SzAr_GetFolderUnpackSize(const CSzAr* p, UInt32 folderIndex)
{ {
return p->CoderUnpackSizes[p->FoToCoderUnpackSizes[folderIndex] + p->FoToMainUnpackSizeIndex[folderIndex]]; return p->CoderUnpackSizes[p->FoToCoderUnpackSizes[folderIndex] + p->FoToMainUnpackSizeIndex[folderIndex]];
} }
@ -856,7 +860,7 @@ typedef struct
} CSubStreamInfo; } CSubStreamInfo;
static SRes ReadSubStreamsInfo(CSzAr *p, CSzData *sd, CSubStreamInfo *ssi) static SRes ReadSubStreamsInfo(CSzAr* p, CSzData* sd, CSubStreamInfo* ssi)
{ {
UInt64 type = 0; UInt64 type = 0;
UInt32 numSubDigests = 0; UInt32 numSubDigests = 0;
@ -929,12 +933,12 @@ static SRes ReadSubStreamsInfo(CSzAr *p, CSzData *sd, CSubStreamInfo *ssi)
} }
} }
static SRes SzReadStreamsInfo(CSzAr *p, static SRes SzReadStreamsInfo(CSzAr* p,
CSzData *sd, CSzData* sd,
UInt32 numFoldersMax, const CBuf *tempBufs, UInt32 numTempBufs, UInt32 numFoldersMax, const CBuf* tempBufs, UInt32 numTempBufs,
UInt64 *dataOffset, UInt64* dataOffset,
CSubStreamInfo *ssi, CSubStreamInfo* ssi,
ISzAlloc *alloc) ISzAlloc* alloc)
{ {
UInt64 type; UInt64 type;
@ -970,13 +974,13 @@ static SRes SzReadStreamsInfo(CSzAr *p,
} }
static SRes SzReadAndDecodePackedStreams( static SRes SzReadAndDecodePackedStreams(
ILookInStream *inStream, ILookInStream* inStream,
CSzData *sd, CSzData* sd,
CBuf *tempBufs, CBuf* tempBufs,
UInt32 numFoldersMax, UInt32 numFoldersMax,
UInt64 baseOffset, UInt64 baseOffset,
CSzAr *p, CSzAr* p,
ISzAlloc *allocTemp) ISzAlloc* allocTemp)
{ {
UInt64 dataStartPos; UInt64 dataStartPos;
UInt32 fo; UInt32 fo;
@ -993,7 +997,7 @@ static SRes SzReadAndDecodePackedStreams(
for (fo = 0; fo < p->NumFolders; fo++) for (fo = 0; fo < p->NumFolders; fo++)
{ {
CBuf *tempBuf = tempBufs + fo; CBuf* tempBuf = tempBufs + fo;
UInt64 unpackSize = SzAr_GetFolderUnpackSize(p, fo); UInt64 unpackSize = SzAr_GetFolderUnpackSize(p, fo);
if ((size_t)unpackSize != unpackSize) if ((size_t)unpackSize != unpackSize)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
@ -1003,7 +1007,7 @@ static SRes SzReadAndDecodePackedStreams(
for (fo = 0; fo < p->NumFolders; fo++) for (fo = 0; fo < p->NumFolders; fo++)
{ {
const CBuf *tempBuf = tempBufs + fo; const CBuf* tempBuf = tempBufs + fo;
RINOK(LookInStream_SeekTo(inStream, dataStartPos)); RINOK(LookInStream_SeekTo(inStream, dataStartPos));
RINOK(SzAr_DecodeFolder(p, fo, inStream, dataStartPos, tempBuf->data, tempBuf->size, allocTemp)); RINOK(SzAr_DecodeFolder(p, fo, inStream, dataStartPos, tempBuf->data, tempBuf->size, allocTemp));
} }
@ -1011,7 +1015,7 @@ static SRes SzReadAndDecodePackedStreams(
return SZ_OK; return SZ_OK;
} }
static SRes SzReadFileNames(const Byte *data, size_t size, UInt32 numFiles, size_t *offsets) static SRes SzReadFileNames(const Byte* data, size_t size, UInt32 numFiles, size_t* offsets)
{ {
size_t pos = 0; size_t pos = 0;
*offsets++ = 0; *offsets++ = 0;
@ -1023,15 +1027,15 @@ static SRes SzReadFileNames(const Byte *data, size_t size, UInt32 numFiles, size
return SZ_ERROR_ARCHIVE; return SZ_ERROR_ARCHIVE;
do do
{ {
const Byte *p; const Byte* p;
if (pos == size) if (pos == size)
return SZ_ERROR_ARCHIVE; return SZ_ERROR_ARCHIVE;
for (p = data + pos; for (p = data + pos;
#ifdef _WIN32 #ifdef _WIN32
*(const UInt16 *)p != 0 *(const UInt16*)p != 0
#else #else
p[0] != 0 || p[1] != 0 p[0] != 0 || p[1] != 0
#endif #endif
; p += 2); ; p += 2);
pos = p - data + 2; pos = p - data + 2;
*offsets++ = (pos >> 1); *offsets++ = (pos >> 1);
@ -1040,15 +1044,15 @@ static SRes SzReadFileNames(const Byte *data, size_t size, UInt32 numFiles, size
return (pos == size) ? SZ_OK : SZ_ERROR_ARCHIVE; return (pos == size) ? SZ_OK : SZ_ERROR_ARCHIVE;
} }
static MY_NO_INLINE SRes ReadTime(CSzBitUi64s *p, UInt32 num, static MY_NO_INLINE SRes ReadTime(CSzBitUi64s* p, UInt32 num,
CSzData *sd2, CSzData* sd2,
const CBuf *tempBufs, UInt32 numTempBufs, const CBuf* tempBufs, UInt32 numTempBufs,
ISzAlloc *alloc) ISzAlloc* alloc)
{ {
CSzData sd; CSzData sd;
UInt32 i; UInt32 i;
CNtfsFileTime *vals; CNtfsFileTime* vals;
Byte *defs; Byte* defs;
Byte external; Byte external;
RINOK(ReadBitVector(sd2, num, &p->Defs, alloc)); RINOK(ReadBitVector(sd2, num, &p->Defs, alloc));
@ -1092,17 +1096,17 @@ static MY_NO_INLINE SRes ReadTime(CSzBitUi64s *p, UInt32 num,
static SRes SzReadHeader2( static SRes SzReadHeader2(
CSzArEx *p, /* allocMain */ CSzArEx* p, /* allocMain */
CSzData *sd, CSzData* sd,
ILookInStream *inStream, ILookInStream* inStream,
CBuf *tempBufs, UInt32 *numTempBufs, CBuf* tempBufs, UInt32* numTempBufs,
ISzAlloc *allocMain, ISzAlloc* allocMain,
ISzAlloc *allocTemp ISzAlloc* allocTemp
) )
{ {
CSubStreamInfo ssi; CSubStreamInfo ssi;
{ {
UInt64 type; UInt64 type;
SzData_Clear(&ssi.sdSizes); SzData_Clear(&ssi.sdSizes);
@ -1158,13 +1162,13 @@ static SRes SzReadHeader2(
if (type != k7zIdFilesInfo) if (type != k7zIdFilesInfo)
return SZ_ERROR_ARCHIVE; return SZ_ERROR_ARCHIVE;
} }
{ {
UInt32 numFiles = 0; UInt32 numFiles = 0;
UInt32 numEmptyStreams = 0; UInt32 numEmptyStreams = 0;
const Byte *emptyStreams = NULL; const Byte* emptyStreams = NULL;
const Byte *emptyFiles = NULL; const Byte* emptyFiles = NULL;
RINOK(SzReadNumber32(sd, &numFiles)); RINOK(SzReadNumber32(sd, &numFiles));
p->NumFiles = numFiles; p->NumFiles = numFiles;
@ -1184,12 +1188,13 @@ static SRes SzReadHeader2(
{ {
SKIP_DATA(sd, size); SKIP_DATA(sd, size);
} }
else switch ((unsigned)type) else
switch ((unsigned)type)
{ {
case k7zIdName: case k7zIdName:
{ {
size_t namesSize; size_t namesSize;
const Byte *namesData; const Byte* namesData;
Byte external; Byte external;
SZ_READ_BYTE(external); SZ_READ_BYTE(external);
@ -1235,7 +1240,7 @@ static SRes SzReadHeader2(
{ {
Byte external; Byte external;
CSzData sdSwitch; CSzData sdSwitch;
CSzData *sdPtr; CSzData* sdPtr;
SzBitUi32s_Free(&p->Attribs, allocMain); SzBitUi32s_Free(&p->Attribs, allocMain);
RINOK(ReadBitVector(sd, numFiles, &p->Attribs.Defs, allocMain)); RINOK(ReadBitVector(sd, numFiles, &p->Attribs.Defs, allocMain));
@ -1265,8 +1270,10 @@ static SRes SzReadHeader2(
break; break;
} }
*/ */
case k7zIdMTime: RINOK(ReadTime(&p->MTime, numFiles, sd, tempBufs, *numTempBufs, allocMain)); break; case k7zIdMTime: RINOK(ReadTime(&p->MTime, numFiles, sd, tempBufs, *numTempBufs, allocMain));
case k7zIdCTime: RINOK(ReadTime(&p->CTime, numFiles, sd, tempBufs, *numTempBufs, allocMain)); break; break;
case k7zIdCTime: RINOK(ReadTime(&p->CTime, numFiles, sd, tempBufs, *numTempBufs, allocMain));
break;
default: default:
{ {
SKIP_DATA(sd, size); SKIP_DATA(sd, size);
@ -1293,8 +1300,8 @@ static SRes SzReadHeader2(
UInt32 remSubStreams = 0; UInt32 remSubStreams = 0;
UInt32 numSubStreams = 0; UInt32 numSubStreams = 0;
UInt64 unpackPos = 0; UInt64 unpackPos = 0;
const Byte *digestsDefs = NULL; const Byte* digestsDefs = NULL;
const Byte *digestsVals = NULL; const Byte* digestsVals = NULL;
UInt32 digestsValsIndex = 0; UInt32 digestsValsIndex = 0;
UInt32 digestIndex; UInt32 digestIndex;
Byte allDigestsDefined = 0; Byte allDigestsDefined = 0;
@ -1463,17 +1470,17 @@ static SRes SzReadHeader2(
if (ssi.sdNumSubStreams.Data && ssi.sdNumSubStreams.Size != 0) if (ssi.sdNumSubStreams.Data && ssi.sdNumSubStreams.Size != 0)
return SZ_ERROR_ARCHIVE; return SZ_ERROR_ARCHIVE;
} }
} }
return SZ_OK; return SZ_OK;
} }
static SRes SzReadHeader( static SRes SzReadHeader(
CSzArEx *p, CSzArEx* p,
CSzData *sd, CSzData* sd,
ILookInStream *inStream, ILookInStream* inStream,
ISzAlloc *allocMain, ISzAlloc* allocMain,
ISzAlloc *allocTemp) ISzAlloc* allocTemp)
{ {
UInt32 i; UInt32 i;
UInt32 numTempBufs = 0; UInt32 numTempBufs = 0;
@ -1499,10 +1506,10 @@ static SRes SzReadHeader(
} }
static SRes SzArEx_Open2( static SRes SzArEx_Open2(
CSzArEx *p, CSzArEx* p,
ILookInStream *inStream, ILookInStream* inStream,
ISzAlloc *allocMain, ISzAlloc* allocMain,
ISzAlloc *allocTemp) ISzAlloc* allocTemp)
{ {
Byte header[k7zStartHeaderSize]; Byte header[k7zStartHeaderSize];
Int64 startArcPos; Int64 startArcPos;
@ -1622,8 +1629,8 @@ static SRes SzArEx_Open2(
} }
SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream, SRes SzArEx_Open(CSzArEx* p, ILookInStream* inStream,
ISzAlloc *allocMain, ISzAlloc *allocTemp) ISzAlloc* allocMain, ISzAlloc* allocTemp)
{ {
SRes res = SzArEx_Open2(p, inStream, allocMain, allocTemp); SRes res = SzArEx_Open2(p, inStream, allocMain, allocTemp);
if (res != SZ_OK) if (res != SZ_OK)
@ -1633,16 +1640,16 @@ SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream,
SRes SzArEx_Extract( SRes SzArEx_Extract(
const CSzArEx *p, const CSzArEx* p,
ILookInStream *inStream, ILookInStream* inStream,
UInt32 fileIndex, UInt32 fileIndex,
UInt32 *blockIndex, UInt32* blockIndex,
Byte **tempBuf, Byte** tempBuf,
size_t *outBufferSize, size_t* outBufferSize,
size_t *offset, size_t* offset,
size_t *outSizeProcessed, size_t* outSizeProcessed,
ISzAlloc *allocMain, ISzAlloc* allocMain,
ISzAlloc *allocTemp) ISzAlloc* allocTemp)
{ {
UInt32 folderIndex = p->FileToFolder[fileIndex]; UInt32 folderIndex = p->FileToFolder[fileIndex];
SRes res = SZ_OK; SRes res = SZ_OK;
@ -1680,7 +1687,7 @@ SRes SzArEx_Extract(
*outBufferSize = unpackSize; *outBufferSize = unpackSize;
if (unpackSize != 0) if (unpackSize != 0)
{ {
*tempBuf = (Byte *)IAlloc_Alloc(allocMain, unpackSize); *tempBuf = (Byte*)IAlloc_Alloc(allocMain, unpackSize);
if (*tempBuf == NULL) if (*tempBuf == NULL)
res = SZ_ERROR_MEM; res = SZ_ERROR_MEM;
} }
@ -1709,14 +1716,14 @@ SRes SzArEx_Extract(
} }
size_t SzArEx_GetFileNameUtf16(const CSzArEx *p, size_t fileIndex, UInt16 *dest) size_t SzArEx_GetFileNameUtf16(const CSzArEx* p, size_t fileIndex, UInt16* dest)
{ {
size_t offs = p->FileNameOffsets[fileIndex]; size_t offs = p->FileNameOffsets[fileIndex];
size_t len = p->FileNameOffsets[fileIndex + 1] - offs; size_t len = p->FileNameOffsets[fileIndex + 1] - offs;
if (dest != 0) if (dest != 0)
{ {
size_t i; size_t i;
const Byte *src = p->FileNames + offs * 2; const Byte* src = p->FileNames + offs * 2;
for (i = 0; i < len; i++) for (i = 0; i < len; i++)
dest[i] = GetUi16(src + i * 2); dest[i] = GetUi16(src + i * 2);
} }

View file

@ -5,13 +5,13 @@
#include "7zBuf.h" #include "7zBuf.h"
void Buf_Init(CBuf *p) void Buf_Init(CBuf* p)
{ {
p->data = 0; p->data = 0;
p->size = 0; p->size = 0;
} }
int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc) int Buf_Create(CBuf* p, size_t size, ISzAlloc* alloc)
{ {
p->size = 0; p->size = 0;
if (size == 0) if (size == 0)
@ -19,7 +19,7 @@ int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc)
p->data = 0; p->data = 0;
return 1; return 1;
} }
p->data = (Byte *)alloc->Alloc(alloc, size); p->data = (Byte*)alloc->Alloc(alloc, size);
if (p->data != 0) if (p->data != 0)
{ {
p->size = size; p->size = size;
@ -28,7 +28,7 @@ int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc)
return 0; return 0;
} }
void Buf_Free(CBuf *p, ISzAlloc *alloc) void Buf_Free(CBuf* p, ISzAlloc* alloc)
{ {
alloc->Free(alloc, p->data); alloc->Free(alloc, p->data);
p->data = 0; p->data = 0;

View file

@ -10,25 +10,25 @@ EXTERN_C_BEGIN
typedef struct typedef struct
{ {
Byte *data; Byte* data;
size_t size; size_t size;
} CBuf; } CBuf;
void Buf_Init(CBuf *p); void Buf_Init(CBuf* p);
int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc); int Buf_Create(CBuf* p, size_t size, ISzAlloc* alloc);
void Buf_Free(CBuf *p, ISzAlloc *alloc); void Buf_Free(CBuf* p, ISzAlloc* alloc);
typedef struct typedef struct
{ {
Byte *data; Byte* data;
size_t size; size_t size;
size_t pos; size_t pos;
} CDynBuf; } CDynBuf;
void DynBuf_Construct(CDynBuf *p); void DynBuf_Construct(CDynBuf* p);
void DynBuf_SeekToBeg(CDynBuf *p); void DynBuf_SeekToBeg(CDynBuf* p);
int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc); int DynBuf_Write(CDynBuf* p, const Byte* buf, size_t size, ISzAlloc* alloc);
void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc); void DynBuf_Free(CDynBuf* p, ISzAlloc* alloc);
EXTERN_C_END EXTERN_C_END

View file

@ -9,7 +9,7 @@
#define kCrcPoly 0xEDB88320 #define kCrcPoly 0xEDB88320
#ifdef MY_CPU_LE #ifdef MY_CPU_LE
#define CRC_NUM_TABLES 8 #define CRC_NUM_TABLES 8
#else #else
#define CRC_NUM_TABLES 9 #define CRC_NUM_TABLES 9
@ -20,11 +20,11 @@
#endif #endif
#ifndef MY_CPU_BE #ifndef MY_CPU_BE
UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table); UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void* data, size_t size, const UInt32* table);
UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table); UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void* data, size_t size, const UInt32* table);
#endif #endif
typedef UInt32 (MY_FAST_CALL *CRC_FUNC)(UInt32 v, const void *data, size_t size, const UInt32 *table); typedef UInt32 (MY_FAST_CALL *CRC_FUNC)(UInt32 v, const void* data, size_t size, const UInt32* table);
CRC_FUNC g_CrcUpdateT4; CRC_FUNC g_CrcUpdateT4;
CRC_FUNC g_CrcUpdateT8; CRC_FUNC g_CrcUpdateT8;
@ -32,22 +32,22 @@ CRC_FUNC g_CrcUpdate;
UInt32 g_CrcTable[256 * CRC_NUM_TABLES]; UInt32 g_CrcTable[256 * CRC_NUM_TABLES];
UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size) UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void* data, size_t size)
{ {
return g_CrcUpdate(v, data, size, g_CrcTable); return g_CrcUpdate(v, data, size, g_CrcTable);
} }
UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size) UInt32 MY_FAST_CALL CrcCalc(const void* data, size_t size)
{ {
return g_CrcUpdate(CRC_INIT_VAL, data, size, g_CrcTable) ^ CRC_INIT_VAL; return g_CrcUpdate(CRC_INIT_VAL, data, size, g_CrcTable) ^ CRC_INIT_VAL;
} }
#define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) #define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
UInt32 MY_FAST_CALL CrcUpdateT1(UInt32 v, const void *data, size_t size, const UInt32 *table) UInt32 MY_FAST_CALL CrcUpdateT1(UInt32 v, const void* data, size_t size, const UInt32* table)
{ {
const Byte *p = (const Byte *)data; const Byte* p = (const Byte*)data;
const Byte *pEnd = p + size; const Byte* pEnd = p + size;
for (; p != pEnd; p++) for (; p != pEnd; p++)
v = CRC_UPDATE_BYTE_2(v, *p); v = CRC_UPDATE_BYTE_2(v, *p);
return v; return v;
@ -70,44 +70,44 @@ void MY_FAST_CALL CrcGenerateTable()
g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8); g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8);
} }
#if CRC_NUM_TABLES < 4 #if CRC_NUM_TABLES < 4
g_CrcUpdate = CrcUpdateT1; g_CrcUpdate = CrcUpdateT1;
#else #else
#ifdef MY_CPU_LE #ifdef MY_CPU_LE
g_CrcUpdateT4 = CrcUpdateT4; g_CrcUpdateT4 = CrcUpdateT4;
g_CrcUpdate = CrcUpdateT4; g_CrcUpdate = CrcUpdateT4;
#if CRC_NUM_TABLES >= 8 #if CRC_NUM_TABLES >= 8
g_CrcUpdateT8 = CrcUpdateT8; g_CrcUpdateT8 = CrcUpdateT8;
#ifdef MY_CPU_X86_OR_AMD64 #ifdef MY_CPU_X86_OR_AMD64
if (!CPU_Is_InOrder()) if (!CPU_Is_InOrder())
g_CrcUpdate = CrcUpdateT8; g_CrcUpdate = CrcUpdateT8;
#endif #endif
#endif #endif
#else #else
{ {
#ifndef MY_CPU_BE #ifndef MY_CPU_BE
UInt32 k = 0x01020304; UInt32 k = 0x01020304;
const Byte *p = (const Byte *)&k; const Byte *p = (const Byte *)&k;
if (p[0] == 4 && p[1] == 3) if (p[0] == 4 && p[1] == 3)
{ {
g_CrcUpdateT4 = CrcUpdateT4; g_CrcUpdateT4 = CrcUpdateT4;
g_CrcUpdate = CrcUpdateT4; g_CrcUpdate = CrcUpdateT4;
#if CRC_NUM_TABLES >= 8 #if CRC_NUM_TABLES >= 8
g_CrcUpdateT8 = CrcUpdateT8; g_CrcUpdateT8 = CrcUpdateT8;
// g_CrcUpdate = CrcUpdateT8; // g_CrcUpdate = CrcUpdateT8;
#endif #endif
} }
else if (p[0] != 1 || p[1] != 2) else if (p[0] != 1 || p[1] != 2)
g_CrcUpdate = CrcUpdateT1; g_CrcUpdate = CrcUpdateT1;
else else
#endif #endif
{ {
for (i = 256 * CRC_NUM_TABLES - 1; i >= 256; i--) for (i = 256 * CRC_NUM_TABLES - 1; i >= 256; i--)
{ {
@ -116,13 +116,13 @@ void MY_FAST_CALL CrcGenerateTable()
} }
g_CrcUpdateT4 = CrcUpdateT1_BeT4; g_CrcUpdateT4 = CrcUpdateT1_BeT4;
g_CrcUpdate = CrcUpdateT1_BeT4; g_CrcUpdate = CrcUpdateT1_BeT4;
#if CRC_NUM_TABLES >= 8 #if CRC_NUM_TABLES >= 8
g_CrcUpdateT8 = CrcUpdateT1_BeT8; g_CrcUpdateT8 = CrcUpdateT1_BeT8;
// g_CrcUpdate = CrcUpdateT1_BeT8; // g_CrcUpdate = CrcUpdateT1_BeT8;
#endif #endif
} }
} }
#endif #endif
#endif #endif
} }

View file

@ -17,8 +17,8 @@ void MY_FAST_CALL CrcGenerateTable(void);
#define CRC_GET_DIGEST(crc) ((crc) ^ CRC_INIT_VAL) #define CRC_GET_DIGEST(crc) ((crc) ^ CRC_INIT_VAL)
#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) #define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size); UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void* data, size_t size);
UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size); UInt32 MY_FAST_CALL CrcCalc(const void* data, size_t size);
EXTERN_C_END EXTERN_C_END

View file

@ -9,16 +9,16 @@
#define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8)) #define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table) UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void* data, size_t size, const UInt32* table)
{ {
const Byte *p = (const Byte *)data; const Byte* p = (const Byte*)data;
for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++) for (; size > 0 && ((unsigned)(ptrdiff_t)p & 3) != 0; size--, p++)
v = CRC_UPDATE_BYTE_2(v, *p); v = CRC_UPDATE_BYTE_2(v, *p);
for (; size >= 4; size -= 4, p += 4) for (; size >= 4; size -= 4, p += 4)
{ {
v ^= *(const UInt32 *)p; v ^= *(const UInt32*)p;
v = v =
table[0x300 + ((v ) & 0xFF)] table[0x300 + ((v) & 0xFF)]
^ table[0x200 + ((v >> 8) & 0xFF)] ^ table[0x200 + ((v >> 8) & 0xFF)]
^ table[0x100 + ((v >> 16) & 0xFF)] ^ table[0x100 + ((v >> 16) & 0xFF)]
^ table[0x000 + ((v >> 24))]; ^ table[0x000 + ((v >> 24))];
@ -28,23 +28,23 @@ UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const U
return v; return v;
} }
UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table) UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void* data, size_t size, const UInt32* table)
{ {
const Byte *p = (const Byte *)data; const Byte* p = (const Byte*)data;
for (; size > 0 && ((unsigned)(ptrdiff_t)p & 7) != 0; size--, p++) for (; size > 0 && ((unsigned)(ptrdiff_t)p & 7) != 0; size--, p++)
v = CRC_UPDATE_BYTE_2(v, *p); v = CRC_UPDATE_BYTE_2(v, *p);
for (; size >= 8; size -= 8, p += 8) for (; size >= 8; size -= 8, p += 8)
{ {
UInt32 d; UInt32 d;
v ^= *(const UInt32 *)p; v ^= *(const UInt32*)p;
v = v =
table[0x700 + ((v ) & 0xFF)] table[0x700 + ((v) & 0xFF)]
^ table[0x600 + ((v >> 8) & 0xFF)] ^ table[0x600 + ((v >> 8) & 0xFF)]
^ table[0x500 + ((v >> 16) & 0xFF)] ^ table[0x500 + ((v >> 16) & 0xFF)]
^ table[0x400 + ((v >> 24))]; ^ table[0x400 + ((v >> 24))];
d = *((const UInt32 *)p + 1); d = *((const UInt32*)p + 1);
v ^= v ^=
table[0x300 + ((d ) & 0xFF)] table[0x300 + ((d) & 0xFF)]
^ table[0x200 + ((d >> 8) & 0xFF)] ^ table[0x200 + ((d >> 8) & 0xFF)]
^ table[0x100 + ((d >> 16) & 0xFF)] ^ table[0x100 + ((d >> 16) & 0xFF)]
^ table[0x000 + ((d >> 24))]; ^ table[0x000 + ((d >> 24))];

View file

@ -131,8 +131,8 @@ static SRes SzDecodePpmd(const Byte *props, unsigned propsSize, UInt64 inSize, I
#endif #endif
static SRes SzDecodeLzma(const Byte *props, unsigned propsSize, UInt64 inSize, ILookInStream *inStream, static SRes SzDecodeLzma(const Byte* props, unsigned propsSize, UInt64 inSize, ILookInStream* inStream,
Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain) Byte* outBuffer, SizeT outSize, ISzAlloc* allocMain)
{ {
CLzmaDec state; CLzmaDec state;
SRes res = SZ_OK; SRes res = SZ_OK;
@ -145,7 +145,7 @@ static SRes SzDecodeLzma(const Byte *props, unsigned propsSize, UInt64 inSize, I
for (;;) for (;;)
{ {
const void *inBuf = NULL; const void* inBuf = NULL;
size_t lookahead = (1 << 18); size_t lookahead = (1 << 18);
if (lookahead > inSize) if (lookahead > inSize)
lookahead = (size_t)inSize; lookahead = (size_t)inSize;
@ -178,7 +178,7 @@ static SRes SzDecodeLzma(const Byte *props, unsigned propsSize, UInt64 inSize, I
break; break;
} }
res = inStream->Skip((void *)inStream, inProcessed); res = inStream->Skip((void*)inStream, inProcessed);
if (res != SZ_OK) if (res != SZ_OK)
break; break;
} }
@ -191,8 +191,8 @@ static SRes SzDecodeLzma(const Byte *props, unsigned propsSize, UInt64 inSize, I
#ifndef _7Z_NO_METHOD_LZMA2 #ifndef _7Z_NO_METHOD_LZMA2
static SRes SzDecodeLzma2(const Byte *props, unsigned propsSize, UInt64 inSize, ILookInStream *inStream, static SRes SzDecodeLzma2(const Byte* props, unsigned propsSize, UInt64 inSize, ILookInStream* inStream,
Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain) Byte* outBuffer, SizeT outSize, ISzAlloc* allocMain)
{ {
CLzma2Dec state; CLzma2Dec state;
SRes res = SZ_OK; SRes res = SZ_OK;
@ -207,7 +207,7 @@ static SRes SzDecodeLzma2(const Byte *props, unsigned propsSize, UInt64 inSize,
for (;;) for (;;)
{ {
const void *inBuf = NULL; const void* inBuf = NULL;
size_t lookahead = (1 << 18); size_t lookahead = (1 << 18);
if (lookahead > inSize) if (lookahead > inSize)
lookahead = (size_t)inSize; lookahead = (size_t)inSize;
@ -237,7 +237,7 @@ static SRes SzDecodeLzma2(const Byte *props, unsigned propsSize, UInt64 inSize,
break; break;
} }
res = inStream->Skip((void *)inStream, inProcessed); res = inStream->Skip((void*)inStream, inProcessed);
if (res != SZ_OK) if (res != SZ_OK)
break; break;
} }
@ -250,11 +250,11 @@ static SRes SzDecodeLzma2(const Byte *props, unsigned propsSize, UInt64 inSize,
#endif #endif
static SRes SzDecodeCopy(UInt64 inSize, ILookInStream *inStream, Byte *outBuffer) static SRes SzDecodeCopy(UInt64 inSize, ILookInStream* inStream, Byte* outBuffer)
{ {
while (inSize > 0) while (inSize > 0)
{ {
const void *inBuf; const void* inBuf;
size_t curSize = (1 << 18); size_t curSize = (1 << 18);
if (curSize > inSize) if (curSize > inSize)
curSize = (size_t)inSize; curSize = (size_t)inSize;
@ -275,18 +275,18 @@ static Bool IS_MAIN_METHOD(UInt32 m)
{ {
case k_Copy: case k_Copy:
case k_LZMA: case k_LZMA:
#ifndef _7Z_NO_METHOD_LZMA2 #ifndef _7Z_NO_METHOD_LZMA2
case k_LZMA2: case k_LZMA2:
#endif #endif
#ifdef _7ZIP_PPMD_SUPPPORT #ifdef _7ZIP_PPMD_SUPPPORT
case k_PPMD: case k_PPMD:
#endif #endif
return True; return True;
} }
return False; return False;
} }
static Bool IS_SUPPORTED_CODER(const CSzCoderInfo *c) static Bool IS_SUPPORTED_CODER(const CSzCoderInfo* c)
{ {
return return
c->NumStreams == 1 c->NumStreams == 1
@ -296,7 +296,7 @@ static Bool IS_SUPPORTED_CODER(const CSzCoderInfo *c)
#define IS_BCJ2(c) ((c)->MethodID == k_BCJ2 && (c)->NumStreams == 4) #define IS_BCJ2(c) ((c)->MethodID == k_BCJ2 && (c)->NumStreams == 4)
static SRes CheckSupportedFolder(const CSzFolder *f) static SRes CheckSupportedFolder(const CSzFolder* f)
{ {
if (f->NumCoders < 1 || f->NumCoders > 4) if (f->NumCoders < 1 || f->NumCoders > 4)
return SZ_ERROR_UNSUPPORTED; return SZ_ERROR_UNSUPPORTED;
@ -310,11 +310,11 @@ static SRes CheckSupportedFolder(const CSzFolder *f)
} }
#ifndef _7Z_NO_METHODS_FILTERS #ifndef _7Z_NO_METHODS_FILTERS
if (f->NumCoders == 2) if (f->NumCoders == 2)
{ {
const CSzCoderInfo *c = &f->Coders[1]; const CSzCoderInfo* c = &f->Coders[1];
if ( if (
/* c->MethodID > (UInt32)0xFFFFFFFF || */ /* c->MethodID > (UInt32)0xFFFFFFFF || */
c->NumStreams != 1 c->NumStreams != 1
@ -340,7 +340,7 @@ static SRes CheckSupportedFolder(const CSzFolder *f)
return SZ_OK; return SZ_OK;
} }
#endif #endif
if (f->NumCoders == 4) if (f->NumCoders == 4)
@ -367,44 +367,44 @@ static SRes CheckSupportedFolder(const CSzFolder *f)
#define CASE_BRA_CONV(isa) case k_ ## isa: isa ## _Convert(outBuffer, outSize, 0, 0); break; #define CASE_BRA_CONV(isa) case k_ ## isa: isa ## _Convert(outBuffer, outSize, 0, 0); break;
static SRes SzFolder_Decode2(const CSzFolder *folder, static SRes SzFolder_Decode2(const CSzFolder* folder,
const Byte *propsData, const Byte* propsData,
const UInt64 *unpackSizes, const UInt64* unpackSizes,
const UInt64 *packPositions, const UInt64* packPositions,
ILookInStream *inStream, UInt64 startPos, ILookInStream* inStream, UInt64 startPos,
Byte *outBuffer, SizeT outSize, ISzAlloc *allocMain, Byte* outBuffer, SizeT outSize, ISzAlloc* allocMain,
Byte *tempBuf[]) Byte* tempBuf[])
{ {
UInt32 ci; UInt32 ci;
SizeT tempSizes[3] = { 0, 0, 0}; SizeT tempSizes[3] = {0, 0, 0};
SizeT tempSize3 = 0; SizeT tempSize3 = 0;
Byte *tempBuf3 = 0; Byte* tempBuf3 = 0;
RINOK(CheckSupportedFolder(folder)); RINOK(CheckSupportedFolder(folder));
for (ci = 0; ci < folder->NumCoders; ci++) for (ci = 0; ci < folder->NumCoders; ci++)
{ {
const CSzCoderInfo *coder = &folder->Coders[ci]; const CSzCoderInfo* coder = &folder->Coders[ci];
if (IS_MAIN_METHOD((UInt32)coder->MethodID)) if (IS_MAIN_METHOD((UInt32)coder->MethodID))
{ {
UInt32 si = 0; UInt32 si = 0;
UInt64 offset; UInt64 offset;
UInt64 inSize; UInt64 inSize;
Byte *outBufCur = outBuffer; Byte* outBufCur = outBuffer;
SizeT outSizeCur = outSize; SizeT outSizeCur = outSize;
if (folder->NumCoders == 4) if (folder->NumCoders == 4)
{ {
UInt32 indices[] = { 3, 2, 0 }; UInt32 indices[] = {3, 2, 0};
UInt64 unpackSize = unpackSizes[ci]; UInt64 unpackSize = unpackSizes[ci];
si = indices[ci]; si = indices[ci];
if (ci < 2) if (ci < 2)
{ {
Byte *temp; Byte* temp;
outSizeCur = (SizeT)unpackSize; outSizeCur = (SizeT)unpackSize;
if (outSizeCur != unpackSize) if (outSizeCur != unpackSize)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
temp = (Byte *)IAlloc_Alloc(allocMain, outSizeCur); temp = (Byte*)IAlloc_Alloc(allocMain, outSizeCur);
if (!temp && outSizeCur != 0) if (!temp && outSizeCur != 0)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
outBufCur = tempBuf[1 - ci] = temp; outBufCur = tempBuf[1 - ci] = temp;
@ -432,20 +432,22 @@ static SRes SzFolder_Decode2(const CSzFolder *folder,
} }
else if (coder->MethodID == k_LZMA) else if (coder->MethodID == k_LZMA)
{ {
RINOK(SzDecodeLzma(propsData + coder->PropsOffset, coder->PropsSize, inSize, inStream, outBufCur, outSizeCur, allocMain)); RINOK(SzDecodeLzma(propsData + coder->PropsOffset, coder->PropsSize, inSize, inStream, outBufCur, outSizeCur
, allocMain));
} }
#ifndef _7Z_NO_METHOD_LZMA2 #ifndef _7Z_NO_METHOD_LZMA2
else if (coder->MethodID == k_LZMA2) else if (coder->MethodID == k_LZMA2)
{ {
RINOK(SzDecodeLzma2(propsData + coder->PropsOffset, coder->PropsSize, inSize, inStream, outBufCur, outSizeCur, allocMain)); RINOK(SzDecodeLzma2(propsData + coder->PropsOffset, coder->PropsSize, inSize, inStream, outBufCur,
outSizeCur, allocMain));
} }
#endif #endif
#ifdef _7ZIP_PPMD_SUPPPORT #ifdef _7ZIP_PPMD_SUPPPORT
else if (coder->MethodID == k_PPMD) else if (coder->MethodID == k_PPMD)
{ {
RINOK(SzDecodePpmd(propsData + coder->PropsOffset, coder->PropsSize, inSize, inStream, outBufCur, outSizeCur, allocMain)); RINOK(SzDecodePpmd(propsData + coder->PropsOffset, coder->PropsSize, inSize, inStream, outBufCur, outSizeCur, allocMain));
} }
#endif #endif
else else
return SZ_ERROR_UNSUPPORTED; return SZ_ERROR_UNSUPPORTED;
} }
@ -460,7 +462,7 @@ static SRes SzFolder_Decode2(const CSzFolder *folder,
tempSizes[2] = (SizeT)s3Size; tempSizes[2] = (SizeT)s3Size;
if (tempSizes[2] != s3Size) if (tempSizes[2] != s3Size)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
tempBuf[2] = (Byte *)IAlloc_Alloc(allocMain, tempSizes[2]); tempBuf[2] = (Byte*)IAlloc_Alloc(allocMain, tempSizes[2]);
if (!tempBuf[2] && tempSizes[2] != 0) if (!tempBuf[2] && tempSizes[2] != 0)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
@ -475,10 +477,14 @@ static SRes SzFolder_Decode2(const CSzFolder *folder,
{ {
CBcj2Dec p; CBcj2Dec p;
p.bufs[0] = tempBuf3; p.lims[0] = tempBuf3 + tempSize3; p.bufs[0] = tempBuf3;
p.bufs[1] = tempBuf[0]; p.lims[1] = tempBuf[0] + tempSizes[0]; p.lims[0] = tempBuf3 + tempSize3;
p.bufs[2] = tempBuf[1]; p.lims[2] = tempBuf[1] + tempSizes[1]; p.bufs[1] = tempBuf[0];
p.bufs[3] = tempBuf[2]; p.lims[3] = tempBuf[2] + tempSizes[2]; p.lims[1] = tempBuf[0] + tempSizes[0];
p.bufs[2] = tempBuf[1];
p.lims[2] = tempBuf[1] + tempSizes[1];
p.bufs[3] = tempBuf[2];
p.lims[3] = tempBuf[2] + tempSizes[2];
p.dest = outBuffer; p.dest = outBuffer;
p.destLim = outBuffer + outSize; p.destLim = outBuffer + outSize;
@ -501,7 +507,7 @@ static SRes SzFolder_Decode2(const CSzFolder *folder,
} }
} }
} }
#ifndef _7Z_NO_METHODS_FILTERS #ifndef _7Z_NO_METHODS_FILTERS
else if (ci == 1) else if (ci == 1)
{ {
if (coder->MethodID == k_Delta) if (coder->MethodID == k_Delta)
@ -537,7 +543,7 @@ static SRes SzFolder_Decode2(const CSzFolder *folder,
} }
} }
} }
#endif #endif
else else
return SZ_ERROR_UNSUPPORTED; return SZ_ERROR_UNSUPPORTED;
} }
@ -546,16 +552,16 @@ static SRes SzFolder_Decode2(const CSzFolder *folder,
} }
SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex, SRes SzAr_DecodeFolder(const CSzAr* p, UInt32 folderIndex,
ILookInStream *inStream, UInt64 startPos, ILookInStream* inStream, UInt64 startPos,
Byte *outBuffer, size_t outSize, Byte* outBuffer, size_t outSize,
ISzAlloc *allocMain) ISzAlloc* allocMain)
{ {
SRes res; SRes res;
CSzFolder folder; CSzFolder folder;
CSzData sd; CSzData sd;
const Byte *data = p->CodersData + p->FoCodersOffsets[folderIndex]; const Byte* data = p->CodersData + p->FoCodersOffsets[folderIndex];
sd.Data = data; sd.Data = data;
sd.Size = p->FoCodersOffsets[folderIndex + 1] - p->FoCodersOffsets[folderIndex]; sd.Size = p->FoCodersOffsets[folderIndex + 1] - p->FoCodersOffsets[folderIndex];
@ -570,7 +576,7 @@ SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex,
return SZ_ERROR_FAIL; return SZ_ERROR_FAIL;
{ {
unsigned i; unsigned i;
Byte *tempBuf[3] = { 0, 0, 0}; Byte* tempBuf[3] = {0, 0, 0};
res = SzFolder_Decode2(&folder, data, res = SzFolder_Decode2(&folder, data,
&p->CoderUnpackSizes[p->FoToCoderUnpackSizes[folderIndex]], &p->CoderUnpackSizes[p->FoToCoderUnpackSizes[folderIndex]],

View file

@ -27,42 +27,42 @@
#endif #endif
void File_Construct(CSzFile *p) void File_Construct(CSzFile* p)
{ {
#ifdef USE_WINDOWS_FILE #ifdef USE_WINDOWS_FILE
p->handle = INVALID_HANDLE_VALUE; p->handle = INVALID_HANDLE_VALUE;
#else #else
p->file = NULL; p->file = NULL;
#endif #endif
} }
#if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE) #if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE)
static WRes File_Open(CSzFile *p, const char *name, int writeMode) static WRes File_Open(CSzFile* p, const char* name, int writeMode)
{ {
#ifdef USE_WINDOWS_FILE #ifdef USE_WINDOWS_FILE
p->handle = CreateFileA(name, p->handle = CreateFileA(name,
writeMode ? GENERIC_WRITE : GENERIC_READ, writeMode ? GENERIC_WRITE : GENERIC_READ,
FILE_SHARE_READ, NULL, FILE_SHARE_READ, NULL,
writeMode ? CREATE_ALWAYS : OPEN_EXISTING, writeMode ? CREATE_ALWAYS : OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL); FILE_ATTRIBUTE_NORMAL, NULL);
return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError(); return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();
#else #else
p->file = fopen(name, writeMode ? "wb+" : "rb"); p->file = fopen(name, writeMode ? "wb+" : "rb");
return (p->file != 0) ? 0 : return (p->file != 0) ? 0 :
#ifdef UNDER_CE #ifdef UNDER_CE
2; /* ENOENT */ 2; /* ENOENT */
#else #else
errno; errno;
#endif #endif
#endif #endif
} }
WRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); } WRes InFile_Open(CSzFile* p, const char* name) { return File_Open(p, name, 0); }
WRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); } WRes OutFile_Open(CSzFile* p, const char* name) { return File_Open(p, name, 1); }
#endif #endif
#ifdef USE_WINDOWS_FILE #ifdef USE_WINDOWS_FILE
static WRes File_OpenW(CSzFile *p, const WCHAR *name, int writeMode) static WRes File_OpenW(CSzFile* p, const WCHAR* name, int writeMode)
{ {
p->handle = CreateFileW(name, p->handle = CreateFileW(name,
writeMode ? GENERIC_WRITE : GENERIC_READ, writeMode ? GENERIC_WRITE : GENERIC_READ,
@ -71,20 +71,21 @@ static WRes File_OpenW(CSzFile *p, const WCHAR *name, int writeMode)
FILE_ATTRIBUTE_NORMAL, NULL); FILE_ATTRIBUTE_NORMAL, NULL);
return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError(); return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();
} }
WRes InFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 0); }
WRes OutFile_OpenW(CSzFile *p, const WCHAR *name) { return File_OpenW(p, name, 1); } WRes InFile_OpenW(CSzFile* p, const WCHAR* name) { return File_OpenW(p, name, 0); }
WRes OutFile_OpenW(CSzFile* p, const WCHAR* name) { return File_OpenW(p, name, 1); }
#endif #endif
WRes File_Close(CSzFile *p) WRes File_Close(CSzFile* p)
{ {
#ifdef USE_WINDOWS_FILE #ifdef USE_WINDOWS_FILE
if (p->handle != INVALID_HANDLE_VALUE) if (p->handle != INVALID_HANDLE_VALUE)
{ {
if (!CloseHandle(p->handle)) if (!CloseHandle(p->handle))
return GetLastError(); return GetLastError();
p->handle = INVALID_HANDLE_VALUE; p->handle = INVALID_HANDLE_VALUE;
} }
#else #else
if (p->file != NULL) if (p->file != NULL)
{ {
int res = fclose(p->file); int res = fclose(p->file);
@ -92,17 +93,17 @@ WRes File_Close(CSzFile *p)
return res; return res;
p->file = NULL; p->file = NULL;
} }
#endif #endif
return 0; return 0;
} }
WRes File_Read(CSzFile *p, void *data, size_t *size) WRes File_Read(CSzFile* p, void* data, size_t* size)
{ {
size_t originalSize = *size; size_t originalSize = *size;
if (originalSize == 0) if (originalSize == 0)
return 0; return 0;
#ifdef USE_WINDOWS_FILE #ifdef USE_WINDOWS_FILE
*size = 0; *size = 0;
do do
@ -110,7 +111,7 @@ WRes File_Read(CSzFile *p, void *data, size_t *size)
DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize; DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
DWORD processed = 0; DWORD processed = 0;
BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL); BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);
data = (void *)((Byte *)data + processed); data = (void*)((Byte*)data + processed);
originalSize -= processed; originalSize -= processed;
*size += processed; *size += processed;
if (!res) if (!res)
@ -121,23 +122,23 @@ WRes File_Read(CSzFile *p, void *data, size_t *size)
while (originalSize > 0); while (originalSize > 0);
return 0; return 0;
#else #else
*size = fread(data, 1, originalSize, p->file); *size = fread(data, 1, originalSize, p->file);
if (*size == originalSize) if (*size == originalSize)
return 0; return 0;
return ferror(p->file); return ferror(p->file);
#endif #endif
} }
WRes File_Write(CSzFile *p, const void *data, size_t *size) WRes File_Write(CSzFile* p, const void* data, size_t* size)
{ {
size_t originalSize = *size; size_t originalSize = *size;
if (originalSize == 0) if (originalSize == 0)
return 0; return 0;
#ifdef USE_WINDOWS_FILE #ifdef USE_WINDOWS_FILE
*size = 0; *size = 0;
do do
@ -145,7 +146,7 @@ WRes File_Write(CSzFile *p, const void *data, size_t *size)
DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize; DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
DWORD processed = 0; DWORD processed = 0;
BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL); BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL);
data = (void *)((Byte *)data + processed); data = (void*)((Byte*)data + processed);
originalSize -= processed; originalSize -= processed;
*size += processed; *size += processed;
if (!res) if (!res)
@ -156,19 +157,19 @@ WRes File_Write(CSzFile *p, const void *data, size_t *size)
while (originalSize > 0); while (originalSize > 0);
return 0; return 0;
#else #else
*size = fwrite(data, 1, originalSize, p->file); *size = fwrite(data, 1, originalSize, p->file);
if (*size == originalSize) if (*size == originalSize)
return 0; return 0;
return ferror(p->file); return ferror(p->file);
#endif #endif
} }
WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin) WRes File_Seek(CSzFile* p, Int64* pos, ESzSeek origin)
{ {
#ifdef USE_WINDOWS_FILE #ifdef USE_WINDOWS_FILE
LARGE_INTEGER value; LARGE_INTEGER value;
DWORD moveMethod; DWORD moveMethod;
@ -176,9 +177,12 @@ WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)
value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */ value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */
switch (origin) switch (origin)
{ {
case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break; case SZ_SEEK_SET: moveMethod = FILE_BEGIN;
case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break; break;
case SZ_SEEK_END: moveMethod = FILE_END; break; case SZ_SEEK_CUR: moveMethod = FILE_CURRENT;
break;
case SZ_SEEK_END: moveMethod = FILE_END;
break;
default: return ERROR_INVALID_PARAMETER; default: return ERROR_INVALID_PARAMETER;
} }
value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod); value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);
@ -191,7 +195,7 @@ WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)
*pos = ((Int64)value.HighPart << 32) | value.LowPart; *pos = ((Int64)value.HighPart << 32) | value.LowPart;
return 0; return 0;
#else #else
int moveMethod; int moveMethod;
int res; int res;
@ -206,12 +210,12 @@ WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)
*pos = ftell(p->file); *pos = ftell(p->file);
return res; return res;
#endif #endif
} }
WRes File_GetLength(CSzFile *p, UInt64 *length) WRes File_GetLength(CSzFile* p, UInt64* length)
{ {
#ifdef USE_WINDOWS_FILE #ifdef USE_WINDOWS_FILE
DWORD sizeHigh; DWORD sizeHigh;
DWORD sizeLow = GetFileSize(p->handle, &sizeHigh); DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);
@ -224,7 +228,7 @@ WRes File_GetLength(CSzFile *p, UInt64 *length)
*length = (((UInt64)sizeHigh) << 32) + sizeLow; *length = (((UInt64)sizeHigh) << 32) + sizeLow;
return 0; return 0;
#else #else
long pos = ftell(p->file); long pos = ftell(p->file);
int res = fseek(p->file, 0, SEEK_END); int res = fseek(p->file, 0, SEEK_END);
@ -232,19 +236,19 @@ WRes File_GetLength(CSzFile *p, UInt64 *length)
fseek(p->file, pos, SEEK_SET); fseek(p->file, pos, SEEK_SET);
return res; return res;
#endif #endif
} }
/* ---------- FileSeqInStream ---------- */ /* ---------- FileSeqInStream ---------- */
static SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size) static SRes FileSeqInStream_Read(void* pp, void* buf, size_t* size)
{ {
CFileSeqInStream *p = (CFileSeqInStream *)pp; CFileSeqInStream* p = (CFileSeqInStream*)pp;
return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ; return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ;
} }
void FileSeqInStream_CreateVTable(CFileSeqInStream *p) void FileSeqInStream_CreateVTable(CFileSeqInStream* p)
{ {
p->s.Read = FileSeqInStream_Read; p->s.Read = FileSeqInStream_Read;
} }
@ -252,19 +256,19 @@ void FileSeqInStream_CreateVTable(CFileSeqInStream *p)
/* ---------- FileInStream ---------- */ /* ---------- FileInStream ---------- */
static SRes FileInStream_Read(void *pp, void *buf, size_t *size) static SRes FileInStream_Read(void* pp, void* buf, size_t* size)
{ {
CFileInStream *p = (CFileInStream *)pp; CFileInStream* p = (CFileInStream*)pp;
return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ; return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;
} }
static SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin) static SRes FileInStream_Seek(void* pp, Int64* pos, ESzSeek origin)
{ {
CFileInStream *p = (CFileInStream *)pp; CFileInStream* p = (CFileInStream*)pp;
return File_Seek(&p->file, pos, origin); return File_Seek(&p->file, pos, origin);
} }
void FileInStream_CreateVTable(CFileInStream *p) void FileInStream_CreateVTable(CFileInStream* p)
{ {
p->s.Read = FileInStream_Read; p->s.Read = FileInStream_Read;
p->s.Seek = FileInStream_Seek; p->s.Seek = FileInStream_Seek;
@ -273,14 +277,14 @@ void FileInStream_CreateVTable(CFileInStream *p)
/* ---------- FileOutStream ---------- */ /* ---------- FileOutStream ---------- */
static size_t FileOutStream_Write(void *pp, const void *data, size_t size) static size_t FileOutStream_Write(void* pp, const void* data, size_t size)
{ {
CFileOutStream *p = (CFileOutStream *)pp; CFileOutStream* p = (CFileOutStream*)pp;
File_Write(&p->file, data, &size); File_Write(&p->file, data, &size);
return size; return size;
} }
void FileOutStream_CreateVTable(CFileOutStream *p) void FileOutStream_CreateVTable(CFileOutStream* p)
{ {
p->s.Write = FileOutStream_Write; p->s.Write = FileOutStream_Write;
} }

View file

@ -22,32 +22,32 @@ EXTERN_C_BEGIN
typedef struct typedef struct
{ {
#ifdef USE_WINDOWS_FILE #ifdef USE_WINDOWS_FILE
HANDLE handle; HANDLE handle;
#else #else
FILE *file; FILE *file;
#endif #endif
} CSzFile; } CSzFile;
void File_Construct(CSzFile *p); void File_Construct(CSzFile* p);
#if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE) #if !defined(UNDER_CE) || !defined(USE_WINDOWS_FILE)
WRes InFile_Open(CSzFile *p, const char *name); WRes InFile_Open(CSzFile* p, const char* name);
WRes OutFile_Open(CSzFile *p, const char *name); WRes OutFile_Open(CSzFile* p, const char* name);
#endif #endif
#ifdef USE_WINDOWS_FILE #ifdef USE_WINDOWS_FILE
WRes InFile_OpenW(CSzFile *p, const WCHAR *name); WRes InFile_OpenW(CSzFile* p, const WCHAR* name);
WRes OutFile_OpenW(CSzFile *p, const WCHAR *name); WRes OutFile_OpenW(CSzFile* p, const WCHAR* name);
#endif #endif
WRes File_Close(CSzFile *p); WRes File_Close(CSzFile* p);
/* reads max(*size, remain file's size) bytes */ /* reads max(*size, remain file's size) bytes */
WRes File_Read(CSzFile *p, void *data, size_t *size); WRes File_Read(CSzFile* p, void* data, size_t* size);
/* writes *size bytes */ /* writes *size bytes */
WRes File_Write(CSzFile *p, const void *data, size_t *size); WRes File_Write(CSzFile* p, const void* data, size_t* size);
WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin); WRes File_Seek(CSzFile* p, Int64* pos, ESzSeek origin);
WRes File_GetLength(CSzFile *p, UInt64 *length); WRes File_GetLength(CSzFile* p, UInt64* length);
/* ---------- FileInStream ---------- */ /* ---------- FileInStream ---------- */
@ -58,7 +58,7 @@ typedef struct
CSzFile file; CSzFile file;
} CFileSeqInStream; } CFileSeqInStream;
void FileSeqInStream_CreateVTable(CFileSeqInStream *p); void FileSeqInStream_CreateVTable(CFileSeqInStream* p);
typedef struct typedef struct
@ -67,7 +67,7 @@ typedef struct
CSzFile file; CSzFile file;
} CFileInStream; } CFileInStream;
void FileInStream_CreateVTable(CFileInStream *p); void FileInStream_CreateVTable(CFileInStream* p);
typedef struct typedef struct
@ -76,7 +76,7 @@ typedef struct
CSzFile file; CSzFile file;
} CFileOutStream; } CFileOutStream;
void FileOutStream_CreateVTable(CFileOutStream *p); void FileOutStream_CreateVTable(CFileOutStream* p);
EXTERN_C_END EXTERN_C_END

View file

@ -2,10 +2,10 @@
#include "7zMemBuffer.h" #include "7zMemBuffer.h"
#include <memory.h> #include <memory.h>
WRes MemBuffer_Read(CSzMemBuffer *p, void *data, size_t *size) WRes MemBuffer_Read(CSzMemBuffer* p, void* data, size_t* size)
{ {
size_t originalSize = *size; size_t originalSize = *size;
if(originalSize == 0) if (originalSize == 0)
return 0; return 0;
size_t length = (size_t)(p->pos + (Int64)(*size) > p->size ? p->size - p->pos - 1 : *size); size_t length = (size_t)(p->pos + (Int64)(*size) > p->size ? p->size - p->pos - 1 : *size);
@ -14,31 +14,35 @@ WRes MemBuffer_Read(CSzMemBuffer *p, void *data, size_t *size)
return 0; return 0;
} }
WRes MemBuffer_Seek(CSzMemBuffer *p, Int64 *pos, ESzSeek origin) WRes MemBuffer_Seek(CSzMemBuffer* p, Int64* pos, ESzSeek origin)
{ {
switch(origin) { switch (origin)
case SZ_SEEK_SET: p->pos = 0 + *pos; break; {
case SZ_SEEK_CUR: p->pos += *pos; break; case SZ_SEEK_SET: p->pos = 0 + *pos;
case SZ_SEEK_END: p->pos = p->size - *pos; break; break;
case SZ_SEEK_CUR: p->pos += *pos;
break;
case SZ_SEEK_END: p->pos = p->size - *pos;
break;
default: return 1; default: return 1;
} }
*pos = p->pos; *pos = p->pos;
return 0; return 0;
} }
static SRes MemBufferInStream_Read(void *pp, void *buf, size_t *size) static SRes MemBufferInStream_Read(void* pp, void* buf, size_t* size)
{ {
CMemBufferInStream *p = (CMemBufferInStream *)pp; CMemBufferInStream* p = (CMemBufferInStream*)pp;
return (MemBuffer_Read(&p->buffer, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ; return (MemBuffer_Read(&p->buffer, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;
} }
static SRes MemBufferInStream_Seek(void *pp, Int64 *pos, ESzSeek origin) static SRes MemBufferInStream_Seek(void* pp, Int64* pos, ESzSeek origin)
{ {
CMemBufferInStream *p = (CMemBufferInStream *)pp; CMemBufferInStream* p = (CMemBufferInStream*)pp;
return MemBuffer_Seek(&p->buffer, pos, origin); return MemBuffer_Seek(&p->buffer, pos, origin);
} }
void MemBufferInit(CMemBufferInStream *memBuferStream, CLookToRead *lookStream, void* buffer, size_t size) void MemBufferInit(CMemBufferInStream* memBuferStream, CLookToRead* lookStream, void* buffer, size_t size)
{ {
memBuferStream->buffer.buffer = buffer; memBuferStream->buffer.buffer = buffer;
memBuferStream->buffer.pos = 0; memBuferStream->buffer.pos = 0;

View file

@ -14,8 +14,8 @@ typedef struct
} CSzMemBuffer; } CSzMemBuffer;
/* reads max(*size, remain file's size) bytes */ /* reads max(*size, remain file's size) bytes */
WRes MemBuffer_Read(CSzMemBuffer *p, void *data, size_t *size); WRes MemBuffer_Read(CSzMemBuffer* p, void* data, size_t* size);
WRes MemBuffer_Seek(CSzMemBuffer *p, Int64 *pos, ESzSeek origin); WRes MemBuffer_Seek(CSzMemBuffer* p, Int64* pos, ESzSeek origin);
/* ---------- FileInStream ---------- */ /* ---------- FileInStream ---------- */
typedef struct typedef struct
@ -24,6 +24,6 @@ typedef struct
CSzMemBuffer buffer; CSzMemBuffer buffer;
} CMemBufferInStream; } CMemBufferInStream;
void MemBufferInit(CMemBufferInStream *memBuferStream, CLookToRead *lookStream, void* buffer, size_t size); void MemBufferInit(CMemBufferInStream* memBuferStream, CLookToRead* lookStream, void* buffer, size_t size);
EXTERN_C_END EXTERN_C_END

View file

@ -7,7 +7,7 @@
#include "7zTypes.h" #include "7zTypes.h"
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType) SRes SeqInStream_Read2(ISeqInStream* stream, void* buf, size_t size, SRes errorType)
{ {
while (size != 0) while (size != 0)
{ {
@ -15,33 +15,33 @@ SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorT
RINOK(stream->Read(stream, buf, &processed)); RINOK(stream->Read(stream, buf, &processed));
if (processed == 0) if (processed == 0)
return errorType; return errorType;
buf = (void *)((Byte *)buf + processed); buf = (void*)((Byte*)buf + processed);
size -= processed; size -= processed;
} }
return SZ_OK; return SZ_OK;
} }
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size) SRes SeqInStream_Read(ISeqInStream* stream, void* buf, size_t size)
{ {
return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF); return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
} }
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf) SRes SeqInStream_ReadByte(ISeqInStream* stream, Byte* buf)
{ {
size_t processed = 1; size_t processed = 1;
RINOK(stream->Read(stream, buf, &processed)); RINOK(stream->Read(stream, buf, &processed));
return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF; return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;
} }
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset) SRes LookInStream_SeekTo(ILookInStream* stream, UInt64 offset)
{ {
Int64 t = offset; Int64 t = offset;
return stream->Seek(stream, &t, SZ_SEEK_SET); return stream->Seek(stream, &t, SZ_SEEK_SET);
} }
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size) SRes LookInStream_LookRead(ILookInStream* stream, void* buf, size_t* size)
{ {
const void *lookBuf; const void* lookBuf;
if (*size == 0) if (*size == 0)
return SZ_OK; return SZ_OK;
RINOK(stream->Look(stream, &lookBuf, size)); RINOK(stream->Look(stream, &lookBuf, size));
@ -49,7 +49,7 @@ SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)
return stream->Skip(stream, *size); return stream->Skip(stream, *size);
} }
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType) SRes LookInStream_Read2(ILookInStream* stream, void* buf, size_t size, SRes errorType)
{ {
while (size != 0) while (size != 0)
{ {
@ -57,21 +57,21 @@ SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes erro
RINOK(stream->Read(stream, buf, &processed)); RINOK(stream->Read(stream, buf, &processed));
if (processed == 0) if (processed == 0)
return errorType; return errorType;
buf = (void *)((Byte *)buf + processed); buf = (void*)((Byte*)buf + processed);
size -= processed; size -= processed;
} }
return SZ_OK; return SZ_OK;
} }
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size) SRes LookInStream_Read(ILookInStream* stream, void* buf, size_t size)
{ {
return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF); return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
} }
static SRes LookToRead_Look_Lookahead(void *pp, const void **buf, size_t *size) static SRes LookToRead_Look_Lookahead(void* pp, const void** buf, size_t* size)
{ {
SRes res = SZ_OK; SRes res = SZ_OK;
CLookToRead *p = (CLookToRead *)pp; CLookToRead* p = (CLookToRead*)pp;
size_t size2 = p->size - p->pos; size_t size2 = p->size - p->pos;
if (size2 == 0 && *size > 0) if (size2 == 0 && *size > 0)
{ {
@ -86,10 +86,10 @@ static SRes LookToRead_Look_Lookahead(void *pp, const void **buf, size_t *size)
return res; return res;
} }
static SRes LookToRead_Look_Exact(void *pp, const void **buf, size_t *size) static SRes LookToRead_Look_Exact(void* pp, const void** buf, size_t* size)
{ {
SRes res = SZ_OK; SRes res = SZ_OK;
CLookToRead *p = (CLookToRead *)pp; CLookToRead* p = (CLookToRead*)pp;
size_t size2 = p->size - p->pos; size_t size2 = p->size - p->pos;
if (size2 == 0 && *size > 0) if (size2 == 0 && *size > 0)
{ {
@ -105,16 +105,16 @@ static SRes LookToRead_Look_Exact(void *pp, const void **buf, size_t *size)
return res; return res;
} }
static SRes LookToRead_Skip(void *pp, size_t offset) static SRes LookToRead_Skip(void* pp, size_t offset)
{ {
CLookToRead *p = (CLookToRead *)pp; CLookToRead* p = (CLookToRead*)pp;
p->pos += offset; p->pos += offset;
return SZ_OK; return SZ_OK;
} }
static SRes LookToRead_Read(void *pp, void *buf, size_t *size) static SRes LookToRead_Read(void* pp, void* buf, size_t* size)
{ {
CLookToRead *p = (CLookToRead *)pp; CLookToRead* p = (CLookToRead*)pp;
size_t rem = p->size - p->pos; size_t rem = p->size - p->pos;
if (rem == 0) if (rem == 0)
return p->realStream->Read(p->realStream, buf, size); return p->realStream->Read(p->realStream, buf, size);
@ -126,46 +126,44 @@ static SRes LookToRead_Read(void *pp, void *buf, size_t *size)
return SZ_OK; return SZ_OK;
} }
static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin) static SRes LookToRead_Seek(void* pp, Int64* pos, ESzSeek origin)
{ {
CLookToRead *p = (CLookToRead *)pp; CLookToRead* p = (CLookToRead*)pp;
p->pos = p->size = 0; p->pos = p->size = 0;
return p->realStream->Seek(p->realStream, pos, origin); return p->realStream->Seek(p->realStream, pos, origin);
} }
void LookToRead_CreateVTable(CLookToRead *p, int lookahead) void LookToRead_CreateVTable(CLookToRead* p, int lookahead)
{ {
p->s.Look = lookahead ? p->s.Look = lookahead ? LookToRead_Look_Lookahead : LookToRead_Look_Exact;
LookToRead_Look_Lookahead :
LookToRead_Look_Exact;
p->s.Skip = LookToRead_Skip; p->s.Skip = LookToRead_Skip;
p->s.Read = LookToRead_Read; p->s.Read = LookToRead_Read;
p->s.Seek = LookToRead_Seek; p->s.Seek = LookToRead_Seek;
} }
void LookToRead_Init(CLookToRead *p) void LookToRead_Init(CLookToRead* p)
{ {
p->pos = p->size = 0; p->pos = p->size = 0;
} }
static SRes SecToLook_Read(void *pp, void *buf, size_t *size) static SRes SecToLook_Read(void* pp, void* buf, size_t* size)
{ {
CSecToLook *p = (CSecToLook *)pp; CSecToLook* p = (CSecToLook*)pp;
return LookInStream_LookRead(p->realStream, buf, size); return LookInStream_LookRead(p->realStream, buf, size);
} }
void SecToLook_CreateVTable(CSecToLook *p) void SecToLook_CreateVTable(CSecToLook* p)
{ {
p->s.Read = SecToLook_Read; p->s.Read = SecToLook_Read;
} }
static SRes SecToRead_Read(void *pp, void *buf, size_t *size) static SRes SecToRead_Read(void* pp, void* buf, size_t* size)
{ {
CSecToRead *p = (CSecToRead *)pp; CSecToRead* p = (CSecToRead*)pp;
return p->realStream->Read(p->realStream, buf, size); return p->realStream->Read(p->realStream, buf, size);
} }
void SecToRead_CreateVTable(CSecToRead *p) void SecToRead_CreateVTable(CSecToRead* p)
{ {
p->s.Read = SecToRead_Read; p->s.Read = SecToRead_Read;
} }

View file

@ -128,29 +128,29 @@ typedef int Bool;
typedef struct typedef struct
{ {
Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */ Byte (*Read)(void* p); /* reads one byte, returns 0 in case of EOF or error */
} IByteIn; } IByteIn;
typedef struct typedef struct
{ {
void (*Write)(void *p, Byte b); void (*Write)(void* p, Byte b);
} IByteOut; } IByteOut;
typedef struct typedef struct
{ {
SRes (*Read)(void *p, void *buf, size_t *size); SRes (*Read)(void* p, void* buf, size_t* size);
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
(output(*size) < input(*size)) is allowed */ (output(*size) < input(*size)) is allowed */
} ISeqInStream; } ISeqInStream;
/* it can return SZ_ERROR_INPUT_EOF */ /* it can return SZ_ERROR_INPUT_EOF */
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size); SRes SeqInStream_Read(ISeqInStream* stream, void* buf, size_t size);
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType); SRes SeqInStream_Read2(ISeqInStream* stream, void* buf, size_t size, SRes errorType);
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf); SRes SeqInStream_ReadByte(ISeqInStream* stream, Byte* buf);
typedef struct typedef struct
{ {
size_t (*Write)(void *p, const void *buf, size_t size); size_t (*Write)(void* p, const void* buf, size_t size);
/* Returns: result - the number of actually written bytes. /* Returns: result - the number of actually written bytes.
(result < size) means error */ (result < size) means error */
} ISeqOutStream; } ISeqOutStream;
@ -164,72 +164,72 @@ typedef enum
typedef struct typedef struct
{ {
SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */ SRes (*Read)(void* p, void* buf, size_t* size); /* same as ISeqInStream::Read */
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin); SRes (*Seek)(void* p, Int64* pos, ESzSeek origin);
} ISeekInStream; } ISeekInStream;
typedef struct typedef struct
{ {
SRes (*Look)(void *p, const void **buf, size_t *size); SRes (*Look)(void* p, const void** buf, size_t* size);
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
(output(*size) > input(*size)) is not allowed (output(*size) > input(*size)) is not allowed
(output(*size) < input(*size)) is allowed */ (output(*size) < input(*size)) is allowed */
SRes (*Skip)(void *p, size_t offset); SRes (*Skip)(void* p, size_t offset);
/* offset must be <= output(*size) of Look */ /* offset must be <= output(*size) of Look */
SRes (*Read)(void *p, void *buf, size_t *size); SRes (*Read)(void* p, void* buf, size_t* size);
/* reads directly (without buffer). It's same as ISeqInStream::Read */ /* reads directly (without buffer). It's same as ISeqInStream::Read */
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin); SRes (*Seek)(void* p, Int64* pos, ESzSeek origin);
} ILookInStream; } ILookInStream;
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size); SRes LookInStream_LookRead(ILookInStream* stream, void* buf, size_t* size);
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset); SRes LookInStream_SeekTo(ILookInStream* stream, UInt64 offset);
/* reads via ILookInStream::Read */ /* reads via ILookInStream::Read */
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType); SRes LookInStream_Read2(ILookInStream* stream, void* buf, size_t size, SRes errorType);
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size); SRes LookInStream_Read(ILookInStream* stream, void* buf, size_t size);
#define LookToRead_BUF_SIZE (1 << 14) #define LookToRead_BUF_SIZE (1 << 14)
typedef struct typedef struct
{ {
ILookInStream s; ILookInStream s;
ISeekInStream *realStream; ISeekInStream* realStream;
size_t pos; size_t pos;
size_t size; size_t size;
Byte buf[LookToRead_BUF_SIZE]; Byte buf[LookToRead_BUF_SIZE];
} CLookToRead; } CLookToRead;
void LookToRead_CreateVTable(CLookToRead *p, int lookahead); void LookToRead_CreateVTable(CLookToRead* p, int lookahead);
void LookToRead_Init(CLookToRead *p); void LookToRead_Init(CLookToRead* p);
typedef struct typedef struct
{ {
ISeqInStream s; ISeqInStream s;
ILookInStream *realStream; ILookInStream* realStream;
} CSecToLook; } CSecToLook;
void SecToLook_CreateVTable(CSecToLook *p); void SecToLook_CreateVTable(CSecToLook* p);
typedef struct typedef struct
{ {
ISeqInStream s; ISeqInStream s;
ILookInStream *realStream; ILookInStream* realStream;
} CSecToRead; } CSecToRead;
void SecToRead_CreateVTable(CSecToRead *p); void SecToRead_CreateVTable(CSecToRead* p);
typedef struct typedef struct
{ {
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize); SRes (*Progress)(void* p, UInt64 inSize, UInt64 outSize);
/* Returns: result. (result != SZ_OK) means break. /* Returns: result. (result != SZ_OK) means break.
Value (UInt64)(Int64)-1 for size means unknown value. */ Value (UInt64)(Int64)-1 for size means unknown value. */
} ICompressProgress; } ICompressProgress;
typedef struct typedef struct
{ {
void *(*Alloc)(void *p, size_t size); void*(*Alloc)(void* p, size_t size);
void (*Free)(void *p, void *address); /* address can be 0 */ void (*Free)(void* p, void* address); /* address can be 0 */
} ISzAlloc; } ISzAlloc;
#define IAlloc_Alloc(p, size) (p)->Alloc((p), size) #define IAlloc_Alloc(p, size) (p)->Alloc((p), size)

View file

@ -17,7 +17,7 @@
#define _UPDATE_0 p->range = bound; *prob = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); #define _UPDATE_0 p->range = bound; *prob = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
#define _UPDATE_1 p->range -= bound; p->code -= bound; *prob = (CProb)(ttt - (ttt >> kNumMoveBits)); #define _UPDATE_1 p->range -= bound; p->code -= bound; *prob = (CProb)(ttt - (ttt >> kNumMoveBits));
void Bcj2Dec_Init(CBcj2Dec *p) void Bcj2Dec_Init(CBcj2Dec* p)
{ {
unsigned i; unsigned i;
@ -30,7 +30,7 @@ void Bcj2Dec_Init(CBcj2Dec *p)
p->probs[i] = kBitModelTotal >> 1; p->probs[i] = kBitModelTotal >> 1;
} }
SRes Bcj2Dec_Decode(CBcj2Dec *p) SRes Bcj2Dec_Decode(CBcj2Dec* p)
{ {
if (p->range <= 5) if (p->range <= 5)
{ {
@ -58,7 +58,7 @@ SRes Bcj2Dec_Decode(CBcj2Dec *p)
{ {
while (p->state <= BCJ2_DEC_STATE_ORIG_3) while (p->state <= BCJ2_DEC_STATE_ORIG_3)
{ {
Byte *dest = p->dest; Byte* dest = p->dest;
if (dest == p->destLim) if (dest == p->destLim)
return SZ_OK; return SZ_OK;
*dest = p->temp[p->state++ - BCJ2_DEC_STATE_ORIG_0]; *dest = p->temp[p->state++ - BCJ2_DEC_STATE_ORIG_0];
@ -119,9 +119,9 @@ SRes Bcj2Dec_Decode(CBcj2Dec *p)
} }
{ {
const Byte *src = p->bufs[BCJ2_STREAM_MAIN]; const Byte* src = p->bufs[BCJ2_STREAM_MAIN];
const Byte *srcLim; const Byte* srcLim;
Byte *dest; Byte* dest;
SizeT num = p->lims[BCJ2_STREAM_MAIN] - src; SizeT num = p->lims[BCJ2_STREAM_MAIN] - src;
if (num == 0) if (num == 0)
@ -145,7 +145,8 @@ SRes Bcj2Dec_Decode(CBcj2Dec *p)
if (p->temp[3] == 0x0F && (src[0] & 0xF0) == 0x80) if (p->temp[3] == 0x0F && (src[0] & 0xF0) == 0x80)
*dest = src[0]; *dest = src[0];
else for (;;) else
for (;;)
{ {
Byte b = *src; Byte b = *src;
*dest = b; *dest = b;
@ -177,15 +178,15 @@ SRes Bcj2Dec_Decode(CBcj2Dec *p)
p->dest += num; p->dest += num;
p->state = p->state =
p->bufs[BCJ2_STREAM_MAIN] == p->bufs[BCJ2_STREAM_MAIN] ==
p->lims[BCJ2_STREAM_MAIN] ? p->lims[BCJ2_STREAM_MAIN]
(unsigned)BCJ2_STREAM_MAIN : ? (unsigned)BCJ2_STREAM_MAIN
(unsigned)BCJ2_DEC_STATE_ORIG; : (unsigned)BCJ2_DEC_STATE_ORIG;
return SZ_OK; return SZ_OK;
} }
{ {
UInt32 bound, ttt; UInt32 bound, ttt;
CProb *prob; CProb* prob;
Byte b = src[0]; Byte b = src[0];
Byte prev = (Byte)(num == 0 ? p->temp[3] : src[-1]); Byte prev = (Byte)(num == 0 ? p->temp[3] : src[-1]);
@ -203,7 +204,6 @@ SRes Bcj2Dec_Decode(CBcj2Dec *p)
continue; continue;
} }
_UPDATE_1 _UPDATE_1
} }
} }
} }
@ -211,8 +211,8 @@ SRes Bcj2Dec_Decode(CBcj2Dec *p)
{ {
UInt32 val; UInt32 val;
unsigned cj = (p->temp[3] == 0xE8) ? BCJ2_STREAM_CALL : BCJ2_STREAM_JUMP; unsigned cj = (p->temp[3] == 0xE8) ? BCJ2_STREAM_CALL : BCJ2_STREAM_JUMP;
const Byte *cur = p->bufs[cj]; const Byte* cur = p->bufs[cj];
Byte *dest; Byte* dest;
SizeT rem; SizeT rem;
if (cur == p->lims[cj]) if (cur == p->lims[cj])

View file

@ -61,10 +61,10 @@ dest is allowed to overlap with bufs[BCJ2_STREAM_MAIN], with the following condi
typedef struct typedef struct
{ {
const Byte *bufs[BCJ2_NUM_STREAMS]; const Byte* bufs[BCJ2_NUM_STREAMS];
const Byte *lims[BCJ2_NUM_STREAMS]; const Byte* lims[BCJ2_NUM_STREAMS];
Byte *dest; Byte* dest;
const Byte *destLim; const Byte* destLim;
unsigned state; /* BCJ2_STREAM_MAIN has more priority than BCJ2_STATE_ORIG */ unsigned state; /* BCJ2_STREAM_MAIN has more priority than BCJ2_STATE_ORIG */
@ -75,15 +75,14 @@ typedef struct
UInt16 probs[2 + 256]; UInt16 probs[2 + 256];
} CBcj2Dec; } CBcj2Dec;
void Bcj2Dec_Init(CBcj2Dec *p); void Bcj2Dec_Init(CBcj2Dec* p);
/* Returns: SZ_OK or SZ_ERROR_DATA */ /* Returns: SZ_OK or SZ_ERROR_DATA */
SRes Bcj2Dec_Decode(CBcj2Dec *p); SRes Bcj2Dec_Decode(CBcj2Dec* p);
#define Bcj2Dec_IsFinished(_p_) ((_p_)->code == 0) #define Bcj2Dec_IsFinished(_p_) ((_p_)->code == 0)
typedef enum typedef enum
{ {
BCJ2_ENC_FINISH_MODE_CONTINUE, BCJ2_ENC_FINISH_MODE_CONTINUE,
@ -93,10 +92,10 @@ typedef enum
typedef struct typedef struct
{ {
Byte *bufs[BCJ2_NUM_STREAMS]; Byte* bufs[BCJ2_NUM_STREAMS];
const Byte *lims[BCJ2_NUM_STREAMS]; const Byte* lims[BCJ2_NUM_STREAMS];
const Byte *src; const Byte* src;
const Byte *srcLim; const Byte* srcLim;
unsigned state; unsigned state;
EBcj2Enc_FinishMode finishMode; EBcj2Enc_FinishMode finishMode;
@ -128,8 +127,8 @@ typedef struct
UInt16 probs[2 + 256]; UInt16 probs[2 + 256];
} CBcj2Enc; } CBcj2Enc;
void Bcj2Enc_Init(CBcj2Enc *p); void Bcj2Enc_Init(CBcj2Enc* p);
void Bcj2Enc_Encode(CBcj2Enc *p); void Bcj2Enc_Encode(CBcj2Enc* p);
#define Bcj2Enc_Get_InputData_Size(p) ((SizeT)((p)->srcLim - (p)->src) + (p)->tempPos) #define Bcj2Enc_Get_InputData_Size(p) ((SizeT)((p)->srcLim - (p)->src) + (p)->tempPos)
#define Bcj2Enc_IsFinished(p) ((p)->flushPos == 5) #define Bcj2Enc_IsFinished(p) ((p)->flushPos == 5)

View file

@ -5,7 +5,7 @@
#include "Bra.h" #include "Bra.h"
SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) SizeT ARM_Convert(Byte* data, SizeT size, UInt32 ip, int encoding)
{ {
SizeT i; SizeT i;
if (size < 4) if (size < 4)
@ -32,7 +32,7 @@ SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
return i; return i;
} }
SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) SizeT ARMT_Convert(Byte* data, SizeT size, UInt32 ip, int encoding)
{ {
SizeT i; SizeT i;
if (size < 4) if (size < 4)
@ -68,7 +68,7 @@ SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
return i; return i;
} }
SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) SizeT PPC_Convert(Byte* data, SizeT size, UInt32 ip, int encoding)
{ {
SizeT i; SizeT i;
if (size < 4) if (size < 4)
@ -98,7 +98,7 @@ SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
return i; return i;
} }
SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) SizeT SPARC_Convert(Byte* data, SizeT size, UInt32 ip, int encoding)
{ {
UInt32 i; UInt32 i;
if (size < 4) if (size < 4)

View file

@ -52,12 +52,12 @@ in CALL instructions to increase the compression ratio.
*/ */
#define x86_Convert_Init(state) { state = 0; } #define x86_Convert_Init(state) { state = 0; }
SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding); SizeT x86_Convert(Byte* data, SizeT size, UInt32 ip, UInt32* state, int encoding);
SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); SizeT ARM_Convert(Byte* data, SizeT size, UInt32 ip, int encoding);
SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); SizeT ARMT_Convert(Byte* data, SizeT size, UInt32 ip, int encoding);
SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); SizeT PPC_Convert(Byte* data, SizeT size, UInt32 ip, int encoding);
SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); SizeT SPARC_Convert(Byte* data, SizeT size, UInt32 ip, int encoding);
SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding); SizeT IA64_Convert(Byte* data, SizeT size, UInt32 ip, int encoding);
EXTERN_C_END EXTERN_C_END

View file

@ -7,7 +7,7 @@
#define Test86MSByte(b) ((((b) + 1) & 0xFE) == 0) #define Test86MSByte(b) ((((b) + 1) & 0xFE) == 0)
SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding) SizeT x86_Convert(Byte* data, SizeT size, UInt32 ip, UInt32* state, int encoding)
{ {
SizeT pos = 0; SizeT pos = 0;
UInt32 mask = *state & 7; UInt32 mask = *state & 7;
@ -18,8 +18,8 @@ SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding
for (;;) for (;;)
{ {
Byte *p = data + pos; Byte* p = data + pos;
const Byte *limit = data + size; const Byte* limit = data + size;
for (; p < limit; p++) for (; p < limit; p++)
if ((*p & 0xFE) == 0xE8) if ((*p & 0xFE) == 0xE8)
break; break;

View file

@ -13,7 +13,7 @@ static const Byte kBranchTable[32] =
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) SizeT IA64_Convert(Byte* data, SizeT size, UInt32 ip, int encoding)
{ {
SizeT i; SizeT i;
if (size < 16) if (size < 16)

View file

@ -6,23 +6,23 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#ifdef UNDER_CE #ifdef UNDER_CE
#define RPC_NO_WINDOWS_H #define RPC_NO_WINDOWS_H
/* #pragma warning(disable : 4115) // '_RPC_ASYNC_STATE' : named type definition in parentheses */ /* #pragma warning(disable : 4115) // '_RPC_ASYNC_STATE' : named type definition in parentheses */
#pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union #pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
#pragma warning(disable : 4214) // nonstandard extension used : bit field types other than int #pragma warning(disable : 4214) // nonstandard extension used : bit field types other than int
#endif #endif
#if _MSC_VER >= 1300 #if _MSC_VER >= 1300
#pragma warning(disable : 4996) // This function or variable may be unsafe #pragma warning(disable : 4996) // This function or variable may be unsafe
#else #else
#pragma warning(disable : 4511) // copy constructor could not be generated #pragma warning(disable : 4511) // copy constructor could not be generated
#pragma warning(disable : 4512) // assignment operator could not be generated #pragma warning(disable : 4512) // assignment operator could not be generated
#pragma warning(disable : 4514) // unreferenced inline function has been removed #pragma warning(disable : 4514) // unreferenced inline function has been removed
#pragma warning(disable : 4702) // unreachable code #pragma warning(disable : 4702) // unreachable code
#pragma warning(disable : 4710) // not inlined #pragma warning(disable : 4710) // not inlined
#pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information #pragma warning(disable : 4786) // identifier was truncated to '255' characters in the debug information
#endif #endif
#endif #endif

View file

@ -18,7 +18,7 @@
#if defined(USE_ASM) && !defined(MY_CPU_AMD64) #if defined(USE_ASM) && !defined(MY_CPU_AMD64)
static UInt32 CheckFlag(UInt32 flag) static UInt32 CheckFlag(UInt32 flag)
{ {
#ifdef _MSC_VER #ifdef _MSC_VER
__asm pushfd; __asm pushfd;
__asm pop EAX; __asm pop EAX;
__asm mov EDX, EAX; __asm mov EDX, EAX;
@ -31,7 +31,7 @@ static UInt32 CheckFlag(UInt32 flag)
__asm push EDX; __asm push EDX;
__asm popfd; __asm popfd;
__asm and flag, EAX; __asm and flag, EAX;
#else #else
__asm__ __volatile__ ( __asm__ __volatile__ (
"pushf\n\t" "pushf\n\t"
"pop %%EAX\n\t" "pop %%EAX\n\t"
@ -47,7 +47,7 @@ static UInt32 CheckFlag(UInt32 flag)
"andl %%EAX, %0\n\t": "andl %%EAX, %0\n\t":
"=c" (flag) : "c" (flag) : "=c" (flag) : "c" (flag) :
"%eax", "%edx"); "%eax", "%edx");
#endif #endif
return flag; return flag;
} }
#define CHECK_CPUID_IS_SUPPORTED if (CheckFlag(1 << 18) == 0 || CheckFlag(1 << 21) == 0) return False; #define CHECK_CPUID_IS_SUPPORTED if (CheckFlag(1 << 18) == 0 || CheckFlag(1 << 21) == 0) return False;
@ -55,11 +55,11 @@ static UInt32 CheckFlag(UInt32 flag)
#define CHECK_CPUID_IS_SUPPORTED #define CHECK_CPUID_IS_SUPPORTED
#endif #endif
void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d) void MyCPUID(UInt32 function, UInt32* a, UInt32* b, UInt32* c, UInt32* d)
{ {
#ifdef USE_ASM #ifdef USE_ASM
#ifdef _MSC_VER #ifdef _MSC_VER
UInt32 a2, b2, c2, d2; UInt32 a2, b2, c2, d2;
__asm xor EBX, EBX; __asm xor EBX, EBX;
@ -77,33 +77,33 @@ void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
*c = c2; *c = c2;
*d = d2; *d = d2;
#else #else
__asm__ __volatile__ ( __asm__ __volatile__ (
#if defined(MY_CPU_AMD64) && defined(__PIC__) #if defined(MY_CPU_AMD64) && defined(__PIC__)
"mov %%rbx, %%rdi;" "mov %%rbx, %%rdi;"
"cpuid;" "cpuid;"
"xchg %%rbx, %%rdi;" "xchg %%rbx, %%rdi;"
: "=a" (*a) , : "=a" (*a) ,
"=D" (*b) , "=D" (*b) ,
#elif defined(MY_CPU_X86) && defined(__PIC__) #elif defined(MY_CPU_X86) && defined(__PIC__)
"mov %%ebx, %%edi;" "mov %%ebx, %%edi;"
"cpuid;" "cpuid;"
"xchgl %%ebx, %%edi;" "xchgl %%ebx, %%edi;"
: "=a" (*a) , : "=a" (*a) ,
"=D" (*b) , "=D" (*b) ,
#else #else
"cpuid" "cpuid"
: "=a" (*a) , : "=a" (*a) ,
"=b" (*b) , "=b" (*b) ,
#endif #endif
"=c" (*c) , "=c" (*c) ,
"=d" (*d) "=d" (*d)
: "0" (function)) ; : "0" (function)) ;
#endif #endif
#else #else
int CPUInfo[4]; int CPUInfo[4];
__cpuid(CPUInfo, function); __cpuid(CPUInfo, function);
@ -112,10 +112,10 @@ void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d)
*c = CPUInfo[2]; *c = CPUInfo[2];
*d = CPUInfo[3]; *d = CPUInfo[3];
#endif #endif
} }
Bool x86cpuid_CheckAndRead(Cx86cpuid *p) Bool x86cpuid_CheckAndRead(Cx86cpuid* p)
{ {
CHECK_CPUID_IS_SUPPORTED CHECK_CPUID_IS_SUPPORTED
MyCPUID(0, &p->maxFunc, &p->vendor[0], &p->vendor[2], &p->vendor[1]); MyCPUID(0, &p->maxFunc, &p->vendor[0], &p->vendor[2], &p->vendor[1]);
@ -125,17 +125,17 @@ Bool x86cpuid_CheckAndRead(Cx86cpuid *p)
static const UInt32 kVendors[][3] = static const UInt32 kVendors[][3] =
{ {
{ 0x756E6547, 0x49656E69, 0x6C65746E}, {0x756E6547, 0x49656E69, 0x6C65746E},
{ 0x68747541, 0x69746E65, 0x444D4163}, {0x68747541, 0x69746E65, 0x444D4163},
{ 0x746E6543, 0x48727561, 0x736C7561} {0x746E6543, 0x48727561, 0x736C7561}
}; };
int x86cpuid_GetFirm(const Cx86cpuid *p) int x86cpuid_GetFirm(const Cx86cpuid* p)
{ {
unsigned i; unsigned i;
for (i = 0; i < sizeof(kVendors) / sizeof(kVendors[i]); i++) for (i = 0; i < sizeof(kVendors) / sizeof(kVendors[i]); i++)
{ {
const UInt32 *v = kVendors[i]; const UInt32* v = kVendors[i];
if (v[0] == p->vendor[0] && if (v[0] == p->vendor[0] &&
v[1] == p->vendor[1] && v[1] == p->vendor[1] &&
v[2] == p->vendor[2]) v[2] == p->vendor[2])

View file

@ -21,14 +21,14 @@ MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned mem
|| defined(__x86_64__) \ || defined(__x86_64__) \
|| defined(__AMD64__) \ || defined(__AMD64__) \
|| defined(__amd64__) || defined(__amd64__)
#define MY_CPU_AMD64 #define MY_CPU_AMD64
#endif #endif
#if defined(MY_CPU_AMD64) \ #if defined(MY_CPU_AMD64) \
|| defined(_M_IA64) \ || defined(_M_IA64) \
|| defined(__AARCH64EL__) \ || defined(__AARCH64EL__) \
|| defined(__AARCH64EB__) || defined(__AARCH64EB__)
#define MY_CPU_64BIT #define MY_CPU_64BIT
#endif #endif
#if defined(_M_IX86) || defined(__i386__) #if defined(_M_IX86) || defined(__i386__)
@ -67,7 +67,7 @@ MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned mem
|| defined(__MIPSEL) \ || defined(__MIPSEL) \
|| defined(_MIPSEL) \ || defined(_MIPSEL) \
|| (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) || (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
#define MY_CPU_LE #define MY_CPU_LE
#endif #endif
#if defined(__BIG_ENDIAN__) \ #if defined(__BIG_ENDIAN__) \
@ -91,10 +91,10 @@ Stop_Compiling_Bad_Endian
#ifdef MY_CPU_LE #ifdef MY_CPU_LE
#if defined(MY_CPU_X86_OR_AMD64) \ #if defined(MY_CPU_X86_OR_AMD64) \
/* || defined(__AARCH64EL__) */ /* || defined(__AARCH64EL__) */
#define MY_CPU_LE_UNALIGN #define MY_CPU_LE_UNALIGN
#endif #endif
#endif #endif
@ -183,7 +183,6 @@ Stop_Compiling_Bad_Endian
((const Byte *)(p))[1] )) ((const Byte *)(p))[1] ))
#ifdef MY_CPU_X86_OR_AMD64 #ifdef MY_CPU_X86_OR_AMD64
typedef struct typedef struct
@ -203,10 +202,10 @@ enum
CPU_FIRM_VIA CPU_FIRM_VIA
}; };
void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d); void MyCPUID(UInt32 function, UInt32* a, UInt32* b, UInt32* c, UInt32* d);
Bool x86cpuid_CheckAndRead(Cx86cpuid *p); Bool x86cpuid_CheckAndRead(Cx86cpuid* p);
int x86cpuid_GetFirm(const Cx86cpuid *p); int x86cpuid_GetFirm(const Cx86cpuid* p);
#define x86cpuid_GetFamily(ver) (((ver >> 16) & 0xFF0) | ((ver >> 8) & 0xF)) #define x86cpuid_GetFamily(ver) (((ver >> 16) & 0xFF0) | ((ver >> 8) & 0xF))
#define x86cpuid_GetModel(ver) (((ver >> 12) & 0xF0) | ((ver >> 4) & 0xF)) #define x86cpuid_GetModel(ver) (((ver >> 12) & 0xF0) | ((ver >> 4) & 0xF))

View file

@ -5,21 +5,21 @@
#include "Delta.h" #include "Delta.h"
void Delta_Init(Byte *state) void Delta_Init(Byte* state)
{ {
unsigned i; unsigned i;
for (i = 0; i < DELTA_STATE_SIZE; i++) for (i = 0; i < DELTA_STATE_SIZE; i++)
state[i] = 0; state[i] = 0;
} }
static void MyMemCpy(Byte *dest, const Byte *src, unsigned size) static void MyMemCpy(Byte* dest, const Byte* src, unsigned size)
{ {
unsigned i; unsigned i;
for (i = 0; i < size; i++) for (i = 0; i < size; i++)
dest[i] = src[i]; dest[i] = src[i];
} }
void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size) void Delta_Encode(Byte* state, unsigned delta, Byte* data, SizeT size)
{ {
Byte buf[DELTA_STATE_SIZE]; Byte buf[DELTA_STATE_SIZE];
unsigned j = 0; unsigned j = 0;
@ -42,7 +42,7 @@ void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size)
MyMemCpy(state + delta - j, buf, j); MyMemCpy(state + delta - j, buf, j);
} }
void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size) void Delta_Decode(Byte* state, unsigned delta, Byte* data, SizeT size)
{ {
Byte buf[DELTA_STATE_SIZE]; Byte buf[DELTA_STATE_SIZE];
unsigned j = 0; unsigned j = 0;

View file

@ -10,9 +10,9 @@ EXTERN_C_BEGIN
#define DELTA_STATE_SIZE 256 #define DELTA_STATE_SIZE 256
void Delta_Init(Byte *state); void Delta_Init(Byte* state);
void Delta_Encode(Byte *state, unsigned delta, Byte *data, SizeT size); void Delta_Encode(Byte* state, unsigned delta, Byte* data, SizeT size);
void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size); void Delta_Decode(Byte* state, unsigned delta, Byte* data, SizeT size);
EXTERN_C_END EXTERN_C_END

View file

@ -60,7 +60,7 @@ typedef enum
LZMA2_STATE_ERROR LZMA2_STATE_ERROR
} ELzma2State; } ELzma2State;
static SRes Lzma2Dec_GetOldProps(Byte prop, Byte *props) static SRes Lzma2Dec_GetOldProps(Byte prop, Byte* props)
{ {
UInt32 dicSize; UInt32 dicSize;
if (prop > 40) if (prop > 40)
@ -74,21 +74,21 @@ static SRes Lzma2Dec_GetOldProps(Byte prop, Byte *props)
return SZ_OK; return SZ_OK;
} }
SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAlloc *alloc) SRes Lzma2Dec_AllocateProbs(CLzma2Dec* p, Byte prop, ISzAlloc* alloc)
{ {
Byte props[LZMA_PROPS_SIZE]; Byte props[LZMA_PROPS_SIZE];
RINOK(Lzma2Dec_GetOldProps(prop, props)); RINOK(Lzma2Dec_GetOldProps(prop, props));
return LzmaDec_AllocateProbs(&p->decoder, props, LZMA_PROPS_SIZE, alloc); return LzmaDec_AllocateProbs(&p->decoder, props, LZMA_PROPS_SIZE, alloc);
} }
SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAlloc *alloc) SRes Lzma2Dec_Allocate(CLzma2Dec* p, Byte prop, ISzAlloc* alloc)
{ {
Byte props[LZMA_PROPS_SIZE]; Byte props[LZMA_PROPS_SIZE];
RINOK(Lzma2Dec_GetOldProps(prop, props)); RINOK(Lzma2Dec_GetOldProps(prop, props));
return LzmaDec_Allocate(&p->decoder, props, LZMA_PROPS_SIZE, alloc); return LzmaDec_Allocate(&p->decoder, props, LZMA_PROPS_SIZE, alloc);
} }
void Lzma2Dec_Init(CLzma2Dec *p) void Lzma2Dec_Init(CLzma2Dec* p)
{ {
p->state = LZMA2_STATE_CONTROL; p->state = LZMA2_STATE_CONTROL;
p->needInitDic = True; p->needInitDic = True;
@ -97,7 +97,7 @@ void Lzma2Dec_Init(CLzma2Dec *p)
LzmaDec_Init(&p->decoder); LzmaDec_Init(&p->decoder);
} }
static ELzma2State Lzma2Dec_UpdateState(CLzma2Dec *p, Byte b) static ELzma2State Lzma2Dec_UpdateState(CLzma2Dec* p, Byte b)
{ {
switch (p->state) switch (p->state)
{ {
@ -135,8 +135,9 @@ static ELzma2State Lzma2Dec_UpdateState(CLzma2Dec *p, Byte b)
p->packSize |= (UInt32)b; p->packSize |= (UInt32)b;
p->packSize++; p->packSize++;
PRF(printf(" %8u", (unsigned)p->packSize)); PRF(printf(" %8u", (unsigned)p->packSize));
return LZMA2_IS_THERE_PROP(LZMA2_GET_LZMA_MODE(p)) ? LZMA2_STATE_PROP: return LZMA2_IS_THERE_PROP(LZMA2_GET_LZMA_MODE(p))
(p->needInitProp ? LZMA2_STATE_ERROR : LZMA2_STATE_DATA); ? LZMA2_STATE_PROP
: (p->needInitProp ? LZMA2_STATE_ERROR : LZMA2_STATE_DATA);
case LZMA2_STATE_PROP: case LZMA2_STATE_PROP:
{ {
@ -158,7 +159,7 @@ static ELzma2State Lzma2Dec_UpdateState(CLzma2Dec *p, Byte b)
return LZMA2_STATE_ERROR; return LZMA2_STATE_ERROR;
} }
static void LzmaDec_UpdateWithUncompressed(CLzmaDec *p, const Byte *src, SizeT size) static void LzmaDec_UpdateWithUncompressed(CLzmaDec* p, const Byte* src, SizeT size)
{ {
memcpy(p->dic + p->dicPos, src, size); memcpy(p->dic + p->dicPos, src, size);
p->dicPos += size; p->dicPos += size;
@ -167,10 +168,10 @@ static void LzmaDec_UpdateWithUncompressed(CLzmaDec *p, const Byte *src, SizeT s
p->processedPos += (UInt32)size; p->processedPos += (UInt32)size;
} }
void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState); void LzmaDec_InitDicAndState(CLzmaDec* p, Bool initDic, Bool initState);
SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit, SRes Lzma2Dec_DecodeToDic(CLzma2Dec* p, SizeT dicLimit,
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status) const Byte* src, SizeT* srcLen, ELzmaFinishMode finishMode, ELzmaStatus* status)
{ {
SizeT inSize = *srcLen; SizeT inSize = *srcLen;
*srcLen = 0; *srcLen = 0;
@ -316,7 +317,8 @@ SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
return SZ_OK; return SZ_OK;
} }
SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status) SRes Lzma2Dec_DecodeToBuf(CLzma2Dec* p, Byte* dest, SizeT* destLen, const Byte* src, SizeT* srcLen,
ELzmaFinishMode finishMode, ELzmaStatus* status)
{ {
SizeT outSize = *destLen, inSize = *srcLen; SizeT outSize = *destLen, inSize = *srcLen;
*srcLen = *destLen = 0; *srcLen = *destLen = 0;
@ -355,8 +357,8 @@ SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen, const Byte *
} }
} }
SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, SRes Lzma2Decode(Byte* dest, SizeT* destLen, const Byte* src, SizeT* srcLen,
Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc) Byte prop, ELzmaFinishMode finishMode, ELzmaStatus* status, ISzAlloc* alloc)
{ {
CLzma2Dec p; CLzma2Dec p;
SRes res; SRes res;

View file

@ -26,9 +26,9 @@ typedef struct
#define Lzma2Dec_FreeProbs(p, alloc) LzmaDec_FreeProbs(&(p)->decoder, alloc); #define Lzma2Dec_FreeProbs(p, alloc) LzmaDec_FreeProbs(&(p)->decoder, alloc);
#define Lzma2Dec_Free(p, alloc) LzmaDec_Free(&(p)->decoder, alloc); #define Lzma2Dec_Free(p, alloc) LzmaDec_Free(&(p)->decoder, alloc);
SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAlloc *alloc); SRes Lzma2Dec_AllocateProbs(CLzma2Dec* p, Byte prop, ISzAlloc* alloc);
SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAlloc *alloc); SRes Lzma2Dec_Allocate(CLzma2Dec* p, Byte prop, ISzAlloc* alloc);
void Lzma2Dec_Init(CLzma2Dec *p); void Lzma2Dec_Init(CLzma2Dec* p);
/* /*
@ -46,11 +46,11 @@ Returns:
SZ_ERROR_DATA - Data error SZ_ERROR_DATA - Data error
*/ */
SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit, SRes Lzma2Dec_DecodeToDic(CLzma2Dec* p, SizeT dicLimit,
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); const Byte* src, SizeT* srcLen, ELzmaFinishMode finishMode, ELzmaStatus* status);
SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen, SRes Lzma2Dec_DecodeToBuf(CLzma2Dec* p, Byte* dest, SizeT* destLen,
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); const Byte* src, SizeT* srcLen, ELzmaFinishMode finishMode, ELzmaStatus* status);
/* ---------- One Call Interface ---------- */ /* ---------- One Call Interface ---------- */
@ -72,8 +72,8 @@ Returns:
SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
*/ */
SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, SRes Lzma2Decode(Byte* dest, SizeT* destLen, const Byte* src, SizeT* srcLen,
Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc); Byte prop, ELzmaFinishMode finishMode, ELzmaStatus* status, ISzAlloc* alloc);
EXTERN_C_END EXTERN_C_END

View file

@ -137,9 +137,9 @@ Out:
= kMatchSpecLenStart + 2 : State Init Marker (unused now) = kMatchSpecLenStart + 2 : State Init Marker (unused now)
*/ */
static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit) static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec* p, SizeT limit, const Byte* bufLimit)
{ {
CLzmaProb *probs = p->probs; CLzmaProb* probs = p->probs;
unsigned state = p->state; unsigned state = p->state;
UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3]; UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];
@ -147,7 +147,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1; unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;
unsigned lc = p->prop.lc; unsigned lc = p->prop.lc;
Byte *dic = p->dic; Byte* dic = p->dic;
SizeT dicBufSize = p->dicBufSize; SizeT dicBufSize = p->dicBufSize;
SizeT dicPos = p->dicPos; SizeT dicPos = p->dicPos;
@ -155,13 +155,13 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
UInt32 checkDicSize = p->checkDicSize; UInt32 checkDicSize = p->checkDicSize;
unsigned len = 0; unsigned len = 0;
const Byte *buf = p->buf; const Byte* buf = p->buf;
UInt32 range = p->range; UInt32 range = p->range;
UInt32 code = p->code; UInt32 code = p->code;
do do
{ {
CLzmaProb *prob; CLzmaProb* prob;
UInt32 bound; UInt32 bound;
unsigned ttt; unsigned ttt;
unsigned posState = processedPos & pbMask; unsigned posState = processedPos & pbMask;
@ -181,9 +181,9 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
{ {
state -= (state < 4) ? state : 3; state -= (state < 4) ? state : 3;
symbol = 1; symbol = 1;
#ifdef _LZMA_SIZE_OPT #ifdef _LZMA_SIZE_OPT
do { NORMAL_LITER_DEC } while (symbol < 0x100); do { NORMAL_LITER_DEC } while (symbol < 0x100);
#else #else
NORMAL_LITER_DEC NORMAL_LITER_DEC
NORMAL_LITER_DEC NORMAL_LITER_DEC
NORMAL_LITER_DEC NORMAL_LITER_DEC
@ -192,7 +192,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
NORMAL_LITER_DEC NORMAL_LITER_DEC
NORMAL_LITER_DEC NORMAL_LITER_DEC
NORMAL_LITER_DEC NORMAL_LITER_DEC
#endif #endif
} }
else else
{ {
@ -200,7 +200,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
unsigned offs = 0x100; unsigned offs = 0x100;
state -= (state < 10) ? 3 : 6; state -= (state < 10) ? 3 : 6;
symbol = 1; symbol = 1;
#ifdef _LZMA_SIZE_OPT #ifdef _LZMA_SIZE_OPT
do do
{ {
unsigned bit; unsigned bit;
@ -208,10 +208,10 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
MATCHED_LITER_DEC MATCHED_LITER_DEC
} }
while (symbol < 0x100); while (symbol < 0x100);
#else #else
{ {
unsigned bit; unsigned bit;
CLzmaProb *probLit; CLzmaProb* probLit;
MATCHED_LITER_DEC MATCHED_LITER_DEC
MATCHED_LITER_DEC MATCHED_LITER_DEC
MATCHED_LITER_DEC MATCHED_LITER_DEC
@ -221,7 +221,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
MATCHED_LITER_DEC MATCHED_LITER_DEC
MATCHED_LITER_DEC MATCHED_LITER_DEC
} }
#endif #endif
} }
dic[dicPos++] = (Byte)symbol; dic[dicPos++] = (Byte)symbol;
@ -292,7 +292,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
prob = probs + RepLenCoder; prob = probs + RepLenCoder;
} }
#ifdef _LZMA_SIZE_OPT #ifdef _LZMA_SIZE_OPT
{ {
unsigned lim, offset; unsigned lim, offset;
CLzmaProb *probLen = prob + LenChoice; CLzmaProb *probLen = prob + LenChoice;
@ -325,9 +325,9 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
TREE_DECODE(probLen, lim, len); TREE_DECODE(probLen, lim, len);
len += offset; len += offset;
} }
#else #else
{ {
CLzmaProb *probLen = prob + LenChoice; CLzmaProb* probLen = prob + LenChoice;
IF_BIT_0(probLen) IF_BIT_0(probLen)
{ {
UPDATE_0(probLen); UPDATE_0(probLen);
@ -360,7 +360,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
} }
} }
} }
#endif #endif
if (state >= kNumStates) if (state >= kNumStates)
{ {
@ -382,7 +382,7 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
unsigned i = 1; unsigned i = 1;
do do
{ {
GET_BIT2(prob + i, i, ; , distance |= mask); GET_BIT2(prob + i, i, ;, distance |= mask);
mask <<= 1; mask <<= 1;
} }
while (--numDirectBits != 0); while (--numDirectBits != 0);
@ -417,10 +417,10 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
distance <<= kNumAlignBits; distance <<= kNumAlignBits;
{ {
unsigned i = 1; unsigned i = 1;
GET_BIT2(prob + i, i, ; , distance |= 1); GET_BIT2(prob + i, i, ;, distance |= 1);
GET_BIT2(prob + i, i, ; , distance |= 2); GET_BIT2(prob + i, i, ;, distance |= 2);
GET_BIT2(prob + i, i, ; , distance |= 4); GET_BIT2(prob + i, i, ;, distance |= 4);
GET_BIT2(prob + i, i, ; , distance |= 8); GET_BIT2(prob + i, i, ;, distance |= 8);
} }
if (distance == (UInt32)0xFFFFFFFF) if (distance == (UInt32)0xFFFFFFFF)
{ {
@ -472,9 +472,9 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
len -= curLen; len -= curLen;
if (curLen <= dicBufSize - pos) if (curLen <= dicBufSize - pos)
{ {
Byte *dest = dic + dicPos; Byte* dest = dic + dicPos;
ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos; ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
const Byte *lim = dest + curLen; const Byte* lim = dest + curLen;
dicPos += curLen; dicPos += curLen;
do do
*(dest) = (Byte)*(dest + src); *(dest) = (Byte)*(dest + src);
@ -512,11 +512,11 @@ static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte
return SZ_OK; return SZ_OK;
} }
static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit) static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec* p, SizeT limit)
{ {
if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart) if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)
{ {
Byte *dic = p->dic; Byte* dic = p->dic;
SizeT dicPos = p->dicPos; SizeT dicPos = p->dicPos;
SizeT dicBufSize = p->dicBufSize; SizeT dicBufSize = p->dicBufSize;
unsigned len = p->remainLen; unsigned len = p->remainLen;
@ -540,7 +540,7 @@ static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
} }
} }
static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit) static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec* p, SizeT limit, const Byte* bufLimit)
{ {
do do
{ {
@ -569,23 +569,24 @@ static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte
typedef enum typedef enum
{ {
DUMMY_ERROR, /* unexpected end of input stream */ DUMMY_ERROR,
/* unexpected end of input stream */
DUMMY_LIT, DUMMY_LIT,
DUMMY_MATCH, DUMMY_MATCH,
DUMMY_REP DUMMY_REP
} ELzmaDummy; } ELzmaDummy;
static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize) static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec* p, const Byte* buf, SizeT inSize)
{ {
UInt32 range = p->range; UInt32 range = p->range;
UInt32 code = p->code; UInt32 code = p->code;
const Byte *bufLimit = buf + inSize; const Byte* bufLimit = buf + inSize;
const CLzmaProb *probs = p->probs; const CLzmaProb* probs = p->probs;
unsigned state = p->state; unsigned state = p->state;
ELzmaDummy res; ELzmaDummy res;
{ {
const CLzmaProb *prob; const CLzmaProb* prob;
UInt32 bound; UInt32 bound;
unsigned ttt; unsigned ttt;
unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1); unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);
@ -606,7 +607,8 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
if (state < kNumLitStates) if (state < kNumLitStates)
{ {
unsigned symbol = 1; unsigned symbol = 1;
do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100); do { GET_BIT_CHECK(prob + symbol, symbol) }
while (symbol < 0x100);
} }
else else
{ {
@ -617,7 +619,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
do do
{ {
unsigned bit; unsigned bit;
const CLzmaProb *probLit; const CLzmaProb* probLit;
matchByte <<= 1; matchByte <<= 1;
bit = (matchByte & offs); bit = (matchByte & offs);
probLit = prob + offs + bit + symbol; probLit = prob + offs + bit + symbol;
@ -687,7 +689,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
} }
{ {
unsigned limit, offset; unsigned limit, offset;
const CLzmaProb *probLen = prob + LenChoice; const CLzmaProb* probLen = prob + LenChoice;
IF_BIT_0_CHECK(probLen) IF_BIT_0_CHECK(probLen)
{ {
UPDATE_0_CHECK; UPDATE_0_CHECK;
@ -766,7 +768,7 @@ static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inS
} }
void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState) void LzmaDec_InitDicAndState(CLzmaDec* p, Bool initDic, Bool initState)
{ {
p->needFlush = 1; p->needFlush = 1;
p->remainLen = 0; p->remainLen = 0;
@ -782,17 +784,17 @@ void LzmaDec_InitDicAndState(CLzmaDec *p, Bool initDic, Bool initState)
p->needInitState = 1; p->needInitState = 1;
} }
void LzmaDec_Init(CLzmaDec *p) void LzmaDec_Init(CLzmaDec* p)
{ {
p->dicPos = 0; p->dicPos = 0;
LzmaDec_InitDicAndState(p, True, True); LzmaDec_InitDicAndState(p, True, True);
} }
static void LzmaDec_InitStateReal(CLzmaDec *p) static void LzmaDec_InitStateReal(CLzmaDec* p)
{ {
SizeT numProbs = LzmaProps_GetNumProbs(&p->prop); SizeT numProbs = LzmaProps_GetNumProbs(&p->prop);
SizeT i; SizeT i;
CLzmaProb *probs = p->probs; CLzmaProb* probs = p->probs;
for (i = 0; i < numProbs; i++) 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->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
@ -800,8 +802,8 @@ static void LzmaDec_InitStateReal(CLzmaDec *p)
p->needInitState = 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) ELzmaFinishMode finishMode, ELzmaStatus* status)
{ {
SizeT inSize = *srcLen; SizeT inSize = *srcLen;
(*srcLen) = 0; (*srcLen) = 0;
@ -861,7 +863,7 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
if (p->tempBufSize == 0) if (p->tempBufSize == 0)
{ {
SizeT processed; SizeT processed;
const Byte *bufLimit; const Byte* bufLimit;
if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow) if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
{ {
int dummyRes = LzmaDec_TryDummy(p, src, inSize); int dummyRes = LzmaDec_TryDummy(p, src, inSize);
@ -935,7 +937,8 @@ SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *sr
return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA; return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
} }
SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status) SRes LzmaDec_DecodeToBuf(CLzmaDec* p, Byte* dest, SizeT* destLen, const Byte* src, SizeT* srcLen,
ELzmaFinishMode finishMode, ELzmaStatus* status)
{ {
SizeT outSize = *destLen; SizeT outSize = *destLen;
SizeT inSize = *srcLen; SizeT inSize = *srcLen;
@ -975,25 +978,25 @@ SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *sr
} }
} }
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc) void LzmaDec_FreeProbs(CLzmaDec* p, ISzAlloc* alloc)
{ {
alloc->Free(alloc, p->probs); alloc->Free(alloc, p->probs);
p->probs = NULL; p->probs = NULL;
} }
static void LzmaDec_FreeDict(CLzmaDec *p, ISzAlloc *alloc) static void LzmaDec_FreeDict(CLzmaDec* p, ISzAlloc* alloc)
{ {
alloc->Free(alloc, p->dic); alloc->Free(alloc, p->dic);
p->dic = NULL; p->dic = NULL;
} }
void LzmaDec_Free(CLzmaDec *p, ISzAlloc *alloc) void LzmaDec_Free(CLzmaDec* p, ISzAlloc* alloc)
{ {
LzmaDec_FreeProbs(p, alloc); LzmaDec_FreeProbs(p, alloc);
LzmaDec_FreeDict(p, alloc); LzmaDec_FreeDict(p, alloc);
} }
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size) SRes LzmaProps_Decode(CLzmaProps* p, const Byte* data, unsigned size)
{ {
UInt32 dicSize; UInt32 dicSize;
Byte d; Byte d;
@ -1019,13 +1022,13 @@ SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size)
return SZ_OK; return SZ_OK;
} }
static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAlloc *alloc) static SRes LzmaDec_AllocateProbs2(CLzmaDec* p, const CLzmaProps* propNew, ISzAlloc* alloc)
{ {
UInt32 numProbs = LzmaProps_GetNumProbs(propNew); UInt32 numProbs = LzmaProps_GetNumProbs(propNew);
if (!p->probs || numProbs != p->numProbs) if (!p->probs || numProbs != p->numProbs)
{ {
LzmaDec_FreeProbs(p, alloc); LzmaDec_FreeProbs(p, alloc);
p->probs = (CLzmaProb *)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb)); p->probs = (CLzmaProb*)alloc->Alloc(alloc, numProbs * sizeof(CLzmaProb));
p->numProbs = numProbs; p->numProbs = numProbs;
if (!p->probs) if (!p->probs)
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
@ -1033,7 +1036,7 @@ static SRes LzmaDec_AllocateProbs2(CLzmaDec *p, const CLzmaProps *propNew, ISzAl
return SZ_OK; return SZ_OK;
} }
SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc) SRes LzmaDec_AllocateProbs(CLzmaDec* p, const Byte* props, unsigned propsSize, ISzAlloc* alloc)
{ {
CLzmaProps propNew; CLzmaProps propNew;
RINOK(LzmaProps_Decode(&propNew, props, propsSize)); RINOK(LzmaProps_Decode(&propNew, props, propsSize));
@ -1042,7 +1045,7 @@ SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, I
return SZ_OK; return SZ_OK;
} }
SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc) SRes LzmaDec_Allocate(CLzmaDec* p, const Byte* props, unsigned propsSize, ISzAlloc* alloc)
{ {
CLzmaProps propNew; CLzmaProps propNew;
SizeT dicBufSize; SizeT dicBufSize;
@ -1062,7 +1065,7 @@ SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAll
if (!p->dic || dicBufSize != p->dicBufSize) if (!p->dic || dicBufSize != p->dicBufSize)
{ {
LzmaDec_FreeDict(p, alloc); LzmaDec_FreeDict(p, alloc);
p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize); p->dic = (Byte*)alloc->Alloc(alloc, dicBufSize);
if (!p->dic) if (!p->dic)
{ {
LzmaDec_FreeProbs(p, alloc); LzmaDec_FreeProbs(p, alloc);
@ -1074,9 +1077,9 @@ SRes LzmaDec_Allocate(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAll
return SZ_OK; return SZ_OK;
} }
SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, 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) ELzmaStatus* status, ISzAlloc* alloc)
{ {
CLzmaDec p; CLzmaDec p;
SRes res; SRes res;

View file

@ -35,7 +35,7 @@ Returns:
SZ_ERROR_UNSUPPORTED - Unsupported properties SZ_ERROR_UNSUPPORTED - Unsupported properties
*/ */
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size); SRes LzmaProps_Decode(CLzmaProps* p, const Byte* data, unsigned size);
/* ---------- LZMA Decoder state ---------- */ /* ---------- LZMA Decoder state ---------- */
@ -48,9 +48,9 @@ SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
typedef struct typedef struct
{ {
CLzmaProps prop; CLzmaProps prop;
CLzmaProb *probs; CLzmaProb* probs;
Byte *dic; Byte* dic;
const Byte *buf; const Byte* buf;
UInt32 range, code; UInt32 range, code;
SizeT dicPos; SizeT dicPos;
SizeT dicBufSize; SizeT dicBufSize;
@ -68,7 +68,7 @@ typedef struct
#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; } #define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
void LzmaDec_Init(CLzmaDec *p); void LzmaDec_Init(CLzmaDec* p);
/* There are two types of LZMA streams: /* There are two types of LZMA streams:
0) Stream with end mark. That end mark adds about 6 bytes to compressed size. 0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
@ -76,7 +76,8 @@ void LzmaDec_Init(CLzmaDec *p);
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 */ LZMA_FINISH_END /* block must be finished at the end */
} ELzmaFinishMode; } ELzmaFinishMode;
@ -97,10 +98,14 @@ typedef enum
typedef enum typedef enum
{ {
LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */ LZMA_STATUS_NOT_SPECIFIED,
LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */ /* use main error code instead */
LZMA_STATUS_NOT_FINISHED, /* stream was not finished */ LZMA_STATUS_FINISHED_WITH_MARK,
LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */ /* 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_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */ LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
} ELzmaStatus; } ELzmaStatus;
@ -129,11 +134,11 @@ LzmaDec_Allocate* can return:
SZ_ERROR_UNSUPPORTED - Unsupported properties SZ_ERROR_UNSUPPORTED - Unsupported properties
*/ */
SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc); SRes LzmaDec_AllocateProbs(CLzmaDec* p, const Byte* props, unsigned propsSize, ISzAlloc* alloc);
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc); void LzmaDec_FreeProbs(CLzmaDec* p, ISzAlloc* alloc);
SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc); SRes LzmaDec_Allocate(CLzmaDec* state, const Byte* prop, unsigned propsSize, ISzAlloc* alloc);
void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc); void LzmaDec_Free(CLzmaDec* state, ISzAlloc* alloc);
/* ---------- Dictionary Interface ---------- */ /* ---------- Dictionary Interface ---------- */
@ -176,8 +181,8 @@ Returns:
SZ_ERROR_DATA - Data error 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); const Byte* src, SizeT* srcLen, ELzmaFinishMode finishMode, ELzmaStatus* status);
/* ---------- Buffer Interface ---------- */ /* ---------- Buffer Interface ---------- */
@ -193,8 +198,8 @@ finishMode:
LZMA_FINISH_END - Stream must be finished after (*destLen). 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); const Byte* src, SizeT* srcLen, ELzmaFinishMode finishMode, ELzmaStatus* status);
/* ---------- One Call Interface ---------- */ /* ---------- One Call Interface ---------- */
@ -218,9 +223,9 @@ Returns:
SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
*/ */
SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, 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); ELzmaStatus* status, ISzAlloc* alloc);
EXTERN_C_END EXTERN_C_END

View file

@ -53,28 +53,28 @@ typedef struct
#pragma pack(pop) #pragma pack(pop)
typedef typedef
#ifdef PPMD_32BIT #ifdef PPMD_32BIT
CPpmd_State * CPpmd_State *
#else #else
UInt32 UInt32
#endif #endif
CPpmd_State_Ref; CPpmd_State_Ref;
typedef typedef
#ifdef PPMD_32BIT #ifdef PPMD_32BIT
void * void *
#else #else
UInt32 UInt32
#endif #endif
CPpmd_Void_Ref; CPpmd_Void_Ref;
typedef typedef
#ifdef PPMD_32BIT #ifdef PPMD_32BIT
Byte * Byte *
#else #else
UInt32 UInt32
#endif #endif
CPpmd_Byte_Ref; CPpmd_Byte_Ref;
#define PPMD_SetAllBitsIn256Bytes(p) \ #define PPMD_SetAllBitsIn256Bytes(p) \
{ unsigned z; for (z = 0; z < 256 / sizeof(p[0]); z += 8) { \ { unsigned z; for (z = 0; z < 256 / sizeof(p[0]); z += 8) { \

View file

@ -8,8 +8,8 @@ This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
#include "Ppmd7.h" #include "Ppmd7.h"
const Byte PPMD7_kExpEscape[16] = { 25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2 }; const Byte PPMD7_kExpEscape[16] = {25, 14, 9, 7, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2};
static const UInt16 kInitBinEsc[] = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051}; static const UInt16 kInitBinEsc[] = {0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x5ABC, 0x6632, 0x6051};
#define MAX_FREQ 124 #define MAX_FREQ 124
#define UNIT_SIZE 12 #define UNIT_SIZE 12
@ -21,7 +21,7 @@ static const UInt16 kInitBinEsc[] = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x
#ifdef PPMD_32BIT #ifdef PPMD_32BIT
#define REF(ptr) (ptr) #define REF(ptr) (ptr)
#else #else
#define REF(ptr) ((UInt32)((Byte *)(ptr) - (p)->Base)) #define REF(ptr) ((UInt32)((Byte *)(ptr) - (p)->Base))
#endif #endif
#define STATS_REF(ptr) ((CPpmd_State_Ref)REF(ptr)) #define STATS_REF(ptr) ((CPpmd_State_Ref)REF(ptr))
@ -31,17 +31,17 @@ static const UInt16 kInitBinEsc[] = { 0x3CDD, 0x1F3F, 0x59BF, 0x48F3, 0x64A1, 0x
#define ONE_STATE(ctx) Ppmd7Context_OneState(ctx) #define ONE_STATE(ctx) Ppmd7Context_OneState(ctx)
#define SUFFIX(ctx) CTX((ctx)->Suffix) #define SUFFIX(ctx) CTX((ctx)->Suffix)
typedef CPpmd7_Context * CTX_PTR; typedef CPpmd7_Context* CTX_PTR;
struct CPpmd7_Node_; struct CPpmd7_Node_;
typedef typedef
#ifdef PPMD_32BIT #ifdef PPMD_32BIT
struct CPpmd7_Node_ * struct CPpmd7_Node_ *
#else #else
UInt32 UInt32
#endif #endif
CPpmd7_Node_Ref; CPpmd7_Node_Ref;
typedef struct CPpmd7_Node_ typedef struct CPpmd7_Node_
{ {
@ -54,10 +54,10 @@ typedef struct CPpmd7_Node_
#ifdef PPMD_32BIT #ifdef PPMD_32BIT
#define NODE(ptr) (ptr) #define NODE(ptr) (ptr)
#else #else
#define NODE(offs) ((CPpmd7_Node *)(p->Base + (offs))) #define NODE(offs) ((CPpmd7_Node *)(p->Base + (offs)))
#endif #endif
void Ppmd7_Construct(CPpmd7 *p) void Ppmd7_Construct(CPpmd7* p)
{ {
unsigned i, k, m; unsigned i, k, m;
@ -66,7 +66,8 @@ void Ppmd7_Construct(CPpmd7 *p)
for (i = 0, k = 0; i < PPMD_NUM_INDEXES; i++) for (i = 0, k = 0; i < PPMD_NUM_INDEXES; i++)
{ {
unsigned step = (i >= 12 ? 4 : (i >> 2) + 1); unsigned step = (i >= 12 ? 4 : (i >> 2) + 1);
do { p->Units2Indx[k++] = (Byte)i; } while (--step); do { p->Units2Indx[k++] = (Byte)i; }
while (--step);
p->Indx2Units[i] = (Byte)k; p->Indx2Units[i] = (Byte)k;
} }
@ -88,28 +89,28 @@ void Ppmd7_Construct(CPpmd7 *p)
memset(p->HB2Flag + 0x40, 8, 0x100 - 0x40); memset(p->HB2Flag + 0x40, 8, 0x100 - 0x40);
} }
void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc) void Ppmd7_Free(CPpmd7* p, ISzAlloc* alloc)
{ {
alloc->Free(alloc, p->Base); alloc->Free(alloc, p->Base);
p->Size = 0; p->Size = 0;
p->Base = 0; p->Base = 0;
} }
Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc) Bool Ppmd7_Alloc(CPpmd7* p, UInt32 size, ISzAlloc* alloc)
{ {
if (p->Base == 0 || p->Size != size) if (p->Base == 0 || p->Size != size)
{ {
Ppmd7_Free(p, alloc); Ppmd7_Free(p, alloc);
p->AlignOffset = p->AlignOffset =
#ifdef PPMD_32BIT #ifdef PPMD_32BIT
(4 - size) & 3; (4 - size) & 3;
#else #else
4 - (size & 3); 4 - (size & 3);
#endif #endif
if ((p->Base = (Byte *)alloc->Alloc(alloc, p->AlignOffset + size if ((p->Base = (Byte*)alloc->Alloc(alloc, p->AlignOffset + size
#ifndef PPMD_32BIT #ifndef PPMD_32BIT
+ UNIT_SIZE + UNIT_SIZE
#endif #endif
)) == 0) )) == 0)
return False; return False;
p->Size = size; p->Size = size;
@ -117,39 +118,39 @@ Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc)
return True; return True;
} }
static void InsertNode(CPpmd7 *p, void *node, unsigned indx) static void InsertNode(CPpmd7* p, void* node, unsigned indx)
{ {
*((CPpmd_Void_Ref *)node) = p->FreeList[indx]; *((CPpmd_Void_Ref*)node) = p->FreeList[indx];
p->FreeList[indx] = REF(node); p->FreeList[indx] = REF(node);
} }
static void *RemoveNode(CPpmd7 *p, unsigned indx) static void* RemoveNode(CPpmd7* p, unsigned indx)
{ {
CPpmd_Void_Ref *node = (CPpmd_Void_Ref *)Ppmd7_GetPtr(p, p->FreeList[indx]); CPpmd_Void_Ref* node = (CPpmd_Void_Ref*)Ppmd7_GetPtr(p, p->FreeList[indx]);
p->FreeList[indx] = *node; p->FreeList[indx] = *node;
return node; return node;
} }
static void SplitBlock(CPpmd7 *p, void *ptr, unsigned oldIndx, unsigned newIndx) static void SplitBlock(CPpmd7* p, void* ptr, unsigned oldIndx, unsigned newIndx)
{ {
unsigned i, nu = I2U(oldIndx) - I2U(newIndx); unsigned i, nu = I2U(oldIndx) - I2U(newIndx);
ptr = (Byte *)ptr + U2B(I2U(newIndx)); ptr = (Byte*)ptr + U2B(I2U(newIndx));
if (I2U(i = U2I(nu)) != nu) if (I2U(i = U2I(nu)) != nu)
{ {
unsigned k = I2U(--i); unsigned k = I2U(--i);
InsertNode(p, ((Byte *)ptr) + U2B(k), nu - k - 1); InsertNode(p, ((Byte*)ptr) + U2B(k), nu - k - 1);
} }
InsertNode(p, ptr, i); InsertNode(p, ptr, i);
} }
static void GlueFreeBlocks(CPpmd7 *p) static void GlueFreeBlocks(CPpmd7* p)
{ {
#ifdef PPMD_32BIT #ifdef PPMD_32BIT
CPpmd7_Node headItem; CPpmd7_Node headItem;
CPpmd7_Node_Ref head = &headItem; CPpmd7_Node_Ref head = &headItem;
#else #else
CPpmd7_Node_Ref head = p->AlignOffset + p->Size; CPpmd7_Node_Ref head = p->AlignOffset + p->Size;
#endif #endif
CPpmd7_Node_Ref n = head; CPpmd7_Node_Ref n = head;
unsigned i; unsigned i;
@ -164,10 +165,10 @@ static void GlueFreeBlocks(CPpmd7 *p)
p->FreeList[i] = 0; p->FreeList[i] = 0;
while (next != 0) while (next != 0)
{ {
CPpmd7_Node *node = NODE(next); CPpmd7_Node* node = NODE(next);
node->Next = n; node->Next = n;
n = NODE(n)->Prev = next; n = NODE(n)->Prev = next;
next = *(const CPpmd7_Node_Ref *)node; next = *(const CPpmd7_Node_Ref*)node;
node->Stamp = 0; node->Stamp = 0;
node->NU = (UInt16)nu; node->NU = (UInt16)nu;
} }
@ -176,16 +177,16 @@ static void GlueFreeBlocks(CPpmd7 *p)
NODE(head)->Next = n; NODE(head)->Next = n;
NODE(n)->Prev = head; NODE(n)->Prev = head;
if (p->LoUnit != p->HiUnit) if (p->LoUnit != p->HiUnit)
((CPpmd7_Node *)p->LoUnit)->Stamp = 1; ((CPpmd7_Node*)p->LoUnit)->Stamp = 1;
/* Glue free blocks */ /* Glue free blocks */
while (n != head) while (n != head)
{ {
CPpmd7_Node *node = NODE(n); CPpmd7_Node* node = NODE(n);
UInt32 nu = (UInt32)node->NU; UInt32 nu = (UInt32)node->NU;
for (;;) for (;;)
{ {
CPpmd7_Node *node2 = NODE(n) + nu; CPpmd7_Node* node2 = NODE(n) + nu;
nu += node2->NU; nu += node2->NU;
if (node2->Stamp != 0 || nu >= 0x10000) if (node2->Stamp != 0 || nu >= 0x10000)
break; break;
@ -199,7 +200,7 @@ static void GlueFreeBlocks(CPpmd7 *p)
/* Fill lists of free blocks */ /* Fill lists of free blocks */
for (n = NODE(head)->Next; n != head;) for (n = NODE(head)->Next; n != head;)
{ {
CPpmd7_Node *node = NODE(n); CPpmd7_Node* node = NODE(n);
unsigned nu; unsigned nu;
CPpmd7_Node_Ref next = node->Next; CPpmd7_Node_Ref next = node->Next;
for (nu = node->NU; nu > 128; nu -= 128, node += 128) for (nu = node->NU; nu > 128; nu -= 128, node += 128)
@ -214,10 +215,10 @@ static void GlueFreeBlocks(CPpmd7 *p)
} }
} }
static void *AllocUnitsRare(CPpmd7 *p, unsigned indx) static void* AllocUnitsRare(CPpmd7* p, unsigned indx)
{ {
unsigned i; unsigned i;
void *retVal; void* retVal;
if (p->GlueCount == 0) if (p->GlueCount == 0)
{ {
GlueFreeBlocks(p); GlueFreeBlocks(p);
@ -240,7 +241,7 @@ static void *AllocUnitsRare(CPpmd7 *p, unsigned indx)
return retVal; return retVal;
} }
static void *AllocUnits(CPpmd7 *p, unsigned indx) static void* AllocUnits(CPpmd7* p, unsigned indx)
{ {
UInt32 numBytes; UInt32 numBytes;
if (p->FreeList[indx] != 0) if (p->FreeList[indx] != 0)
@ -248,7 +249,7 @@ static void *AllocUnits(CPpmd7 *p, unsigned indx)
numBytes = U2B(I2U(indx)); numBytes = U2B(I2U(indx));
if (numBytes <= (UInt32)(p->HiUnit - p->LoUnit)) if (numBytes <= (UInt32)(p->HiUnit - p->LoUnit))
{ {
void *retVal = p->LoUnit; void* retVal = p->LoUnit;
p->LoUnit += numBytes; p->LoUnit += numBytes;
return retVal; return retVal;
} }
@ -259,7 +260,7 @@ static void *AllocUnits(CPpmd7 *p, unsigned indx)
{ UInt32 *d = (UInt32 *)dest; const UInt32 *s = (const UInt32 *)src; UInt32 n = num; \ { UInt32 *d = (UInt32 *)dest; const UInt32 *s = (const UInt32 *)src; UInt32 n = num; \
do { d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; s += 3; d += 3; } while (--n); } do { d[0] = s[0]; d[1] = s[1]; d[2] = s[2]; s += 3; d += 3; } while (--n); }
static void *ShrinkUnits(CPpmd7 *p, void *oldPtr, unsigned oldNU, unsigned newNU) static void* ShrinkUnits(CPpmd7* p, void* oldPtr, unsigned oldNU, unsigned newNU)
{ {
unsigned i0 = U2I(oldNU); unsigned i0 = U2I(oldNU);
unsigned i1 = U2I(newNU); unsigned i1 = U2I(newNU);
@ -267,7 +268,7 @@ static void *ShrinkUnits(CPpmd7 *p, void *oldPtr, unsigned oldNU, unsigned newNU
return oldPtr; return oldPtr;
if (p->FreeList[i1] != 0) if (p->FreeList[i1] != 0)
{ {
void *ptr = RemoveNode(p, i1); void* ptr = RemoveNode(p, i1);
MyMem12Cpy(ptr, oldPtr, newNU); MyMem12Cpy(ptr, oldPtr, newNU);
InsertNode(p, oldPtr, i0); InsertNode(p, oldPtr, i0);
return ptr; return ptr;
@ -278,13 +279,13 @@ static void *ShrinkUnits(CPpmd7 *p, void *oldPtr, unsigned oldNU, unsigned newNU
#define SUCCESSOR(p) ((CPpmd_Void_Ref)((p)->SuccessorLow | ((UInt32)(p)->SuccessorHigh << 16))) #define SUCCESSOR(p) ((CPpmd_Void_Ref)((p)->SuccessorLow | ((UInt32)(p)->SuccessorHigh << 16)))
static void SetSuccessor(CPpmd_State *p, CPpmd_Void_Ref v) static void SetSuccessor(CPpmd_State* p, CPpmd_Void_Ref v)
{ {
(p)->SuccessorLow = (UInt16)((UInt32)(v) & 0xFFFF); (p)->SuccessorLow = (UInt16)((UInt32)(v) & 0xFFFF);
(p)->SuccessorHigh = (UInt16)(((UInt32)(v) >> 16) & 0xFFFF); (p)->SuccessorHigh = (UInt16)(((UInt32)(v) >> 16) & 0xFFFF);
} }
static void RestartModel(CPpmd7 *p) static void RestartModel(CPpmd7* p)
{ {
unsigned i, k, m; unsigned i, k, m;
@ -302,12 +303,12 @@ static void RestartModel(CPpmd7 *p)
p->MinContext->Suffix = 0; p->MinContext->Suffix = 0;
p->MinContext->NumStats = 256; p->MinContext->NumStats = 256;
p->MinContext->SummFreq = 256 + 1; p->MinContext->SummFreq = 256 + 1;
p->FoundState = (CPpmd_State *)p->LoUnit; /* AllocUnits(p, PPMD_NUM_INDEXES - 1); */ p->FoundState = (CPpmd_State*)p->LoUnit; /* AllocUnits(p, PPMD_NUM_INDEXES - 1); */
p->LoUnit += U2B(256 / 2); p->LoUnit += U2B(256 / 2);
p->MinContext->Stats = REF(p->FoundState); p->MinContext->Stats = REF(p->FoundState);
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
CPpmd_State *s = &p->FoundState[i]; CPpmd_State* s = &p->FoundState[i];
s->Symbol = (Byte)i; s->Symbol = (Byte)i;
s->Freq = 1; s->Freq = 1;
SetSuccessor(s, 0); SetSuccessor(s, 0);
@ -316,7 +317,7 @@ static void RestartModel(CPpmd7 *p)
for (i = 0; i < 128; i++) for (i = 0; i < 128; i++)
for (k = 0; k < 8; k++) for (k = 0; k < 8; k++)
{ {
UInt16 *dest = p->BinSumm[i] + k; UInt16* dest = p->BinSumm[i] + k;
UInt16 val = (UInt16)(PPMD_BIN_SCALE - kInitBinEsc[k] / (i + 2)); UInt16 val = (UInt16)(PPMD_BIN_SCALE - kInitBinEsc[k] / (i + 2));
for (m = 0; m < 64; m += 8) for (m = 0; m < 64; m += 8)
dest[m] = val; dest[m] = val;
@ -325,13 +326,13 @@ static void RestartModel(CPpmd7 *p)
for (i = 0; i < 25; i++) for (i = 0; i < 25; i++)
for (k = 0; k < 16; k++) for (k = 0; k < 16; k++)
{ {
CPpmd_See *s = &p->See[i][k]; CPpmd_See* s = &p->See[i][k];
s->Summ = (UInt16)((5 * i + 10) << (s->Shift = PPMD_PERIOD_BITS - 4)); s->Summ = (UInt16)((5 * i + 10) << (s->Shift = PPMD_PERIOD_BITS - 4));
s->Count = 4; s->Count = 4;
} }
} }
void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder) void Ppmd7_Init(CPpmd7* p, unsigned maxOrder)
{ {
p->MaxOrder = maxOrder; p->MaxOrder = maxOrder;
RestartModel(p); RestartModel(p);
@ -340,12 +341,12 @@ void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder)
p->DummySee.Count = 64; /* unused */ p->DummySee.Count = 64; /* unused */
} }
static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip) static CTX_PTR CreateSuccessors(CPpmd7* p, Bool skip)
{ {
CPpmd_State upState; CPpmd_State upState;
CTX_PTR c = p->MinContext; CTX_PTR c = p->MinContext;
CPpmd_Byte_Ref upBranch = (CPpmd_Byte_Ref)SUCCESSOR(p->FoundState); CPpmd_Byte_Ref upBranch = (CPpmd_Byte_Ref)SUCCESSOR(p->FoundState);
CPpmd_State *ps[PPMD7_MAX_ORDER]; CPpmd_State* ps[PPMD7_MAX_ORDER];
unsigned numPs = 0; unsigned numPs = 0;
if (!skip) if (!skip)
@ -354,7 +355,7 @@ static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip)
while (c->Suffix) while (c->Suffix)
{ {
CPpmd_Void_Ref successor; CPpmd_Void_Ref successor;
CPpmd_State *s; CPpmd_State* s;
c = SUFFIX(c); c = SUFFIX(c);
if (c->NumStats != 1) if (c->NumStats != 1)
{ {
@ -373,7 +374,7 @@ static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip)
ps[numPs++] = s; ps[numPs++] = s;
} }
upState.Symbol = *(const Byte *)Ppmd7_GetPtr(p, upBranch); upState.Symbol = *(const Byte*)Ppmd7_GetPtr(p, upBranch);
SetSuccessor(&upState, upBranch + 1); SetSuccessor(&upState, upBranch + 1);
if (c->NumStats == 1) if (c->NumStats == 1)
@ -381,7 +382,7 @@ static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip)
else else
{ {
UInt32 cf, s0; UInt32 cf, s0;
CPpmd_State *s; CPpmd_State* s;
for (s = STATS(c); s->Symbol != upState.Symbol; s++); for (s = STATS(c); s->Symbol != upState.Symbol; s++);
cf = s->Freq - 1; cf = s->Freq - 1;
s0 = c->SummFreq - c->NumStats - cf; s0 = c->SummFreq - c->NumStats - cf;
@ -413,14 +414,14 @@ static CTX_PTR CreateSuccessors(CPpmd7 *p, Bool skip)
return c; return c;
} }
static void SwapStates(CPpmd_State *t1, CPpmd_State *t2) static void SwapStates(CPpmd_State* t1, CPpmd_State* t2)
{ {
CPpmd_State tmp = *t1; CPpmd_State tmp = *t1;
*t1 = *t2; *t1 = *t2;
*t2 = tmp; *t2 = tmp;
} }
static void UpdateModel(CPpmd7 *p) static void UpdateModel(CPpmd7* p)
{ {
CPpmd_Void_Ref successor, fSuccessor = SUCCESSOR(p->FoundState); CPpmd_Void_Ref successor, fSuccessor = SUCCESSOR(p->FoundState);
CTX_PTR c; CTX_PTR c;
@ -432,16 +433,17 @@ static void UpdateModel(CPpmd7 *p)
if (c->NumStats == 1) if (c->NumStats == 1)
{ {
CPpmd_State *s = ONE_STATE(c); CPpmd_State* s = ONE_STATE(c);
if (s->Freq < 32) if (s->Freq < 32)
s->Freq++; s->Freq++;
} }
else else
{ {
CPpmd_State *s = STATS(c); CPpmd_State* s = STATS(c);
if (s->Symbol != p->FoundState->Symbol) if (s->Symbol != p->FoundState->Symbol)
{ {
do { s++; } while (s->Symbol != p->FoundState->Symbol); do { s++; }
while (s->Symbol != p->FoundState->Symbol);
if (s[0].Freq >= s[-1].Freq) if (s[0].Freq >= s[-1].Freq)
{ {
SwapStates(&s[0], &s[-1]); SwapStates(&s[0], &s[-1]);
@ -515,8 +517,8 @@ static void UpdateModel(CPpmd7 *p)
unsigned i = U2I(oldNU); unsigned i = U2I(oldNU);
if (i != U2I(oldNU + 1)) if (i != U2I(oldNU + 1))
{ {
void *ptr = AllocUnits(p, i + 1); void* ptr = AllocUnits(p, i + 1);
void *oldPtr; void* oldPtr;
if (!ptr) if (!ptr)
{ {
RestartModel(p); RestartModel(p);
@ -532,7 +534,7 @@ static void UpdateModel(CPpmd7 *p)
} }
else else
{ {
CPpmd_State *s = (CPpmd_State*)AllocUnits(p, 0); CPpmd_State* s = (CPpmd_State*)AllocUnits(p, 0);
if (!s) if (!s)
{ {
RestartModel(p); RestartModel(p);
@ -559,7 +561,7 @@ static void UpdateModel(CPpmd7 *p)
c->SummFreq = (UInt16)(c->SummFreq + cf); c->SummFreq = (UInt16)(c->SummFreq + cf);
} }
{ {
CPpmd_State *s = STATS(c) + ns1; CPpmd_State* s = STATS(c) + ns1;
SetSuccessor(s, successor); SetSuccessor(s, successor);
s->Symbol = p->FoundState->Symbol; s->Symbol = p->FoundState->Symbol;
s->Freq = (Byte)cf; s->Freq = (Byte)cf;
@ -569,11 +571,11 @@ static void UpdateModel(CPpmd7 *p)
p->MaxContext = p->MinContext = CTX(fSuccessor); p->MaxContext = p->MinContext = CTX(fSuccessor);
} }
static void Rescale(CPpmd7 *p) static void Rescale(CPpmd7* p)
{ {
unsigned i, adder, sumFreq, escFreq; unsigned i, adder, sumFreq, escFreq;
CPpmd_State *stats = STATS(p->MinContext); CPpmd_State* stats = STATS(p->MinContext);
CPpmd_State *s = p->FoundState; CPpmd_State* s = p->FoundState;
{ {
CPpmd_State tmp = *s; CPpmd_State tmp = *s;
for (; s != stats; s--) for (; s != stats; s--)
@ -594,7 +596,7 @@ static void Rescale(CPpmd7 *p)
sumFreq += s->Freq; sumFreq += s->Freq;
if (s[0].Freq > s[-1].Freq) if (s[0].Freq > s[-1].Freq)
{ {
CPpmd_State *s1 = s; CPpmd_State* s1 = s;
CPpmd_State tmp = *s1; CPpmd_State tmp = *s1;
do do
s1[0] = s1[-1]; s1[0] = s1[-1];
@ -608,7 +610,8 @@ static void Rescale(CPpmd7 *p)
{ {
unsigned numStats = p->MinContext->NumStats; unsigned numStats = p->MinContext->NumStats;
unsigned n0, n1; unsigned n0, n1;
do { i++; } while ((--s)->Freq == 0); do { i++; }
while ((--s)->Freq == 0);
escFreq += i; escFreq += i;
p->MinContext->NumStats = (UInt16)(p->MinContext->NumStats - i); p->MinContext->NumStats = (UInt16)(p->MinContext->NumStats - i);
if (p->MinContext->NumStats == 1) if (p->MinContext->NumStats == 1)
@ -633,9 +636,9 @@ static void Rescale(CPpmd7 *p)
p->FoundState = STATS(p->MinContext); p->FoundState = STATS(p->MinContext);
} }
CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *escFreq) CPpmd_See* Ppmd7_MakeEscFreq(CPpmd7* p, unsigned numMasked, UInt32* escFreq)
{ {
CPpmd_See *see; CPpmd_See* see;
unsigned nonMasked = p->MinContext->NumStats - numMasked; unsigned nonMasked = p->MinContext->NumStats - numMasked;
if (p->MinContext->NumStats != 256) if (p->MinContext->NumStats != 256)
{ {
@ -658,18 +661,18 @@ CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *escFreq)
return see; return see;
} }
static void NextContext(CPpmd7 *p) static void NextContext(CPpmd7* p)
{ {
CTX_PTR c = CTX(SUCCESSOR(p->FoundState)); CTX_PTR c = CTX(SUCCESSOR(p->FoundState));
if (p->OrderFall == 0 && (Byte *)c > p->Text) if (p->OrderFall == 0 && (Byte*)c > p->Text)
p->MinContext = p->MaxContext = c; p->MinContext = p->MaxContext = c;
else else
UpdateModel(p); UpdateModel(p);
} }
void Ppmd7_Update1(CPpmd7 *p) void Ppmd7_Update1(CPpmd7* p)
{ {
CPpmd_State *s = p->FoundState; CPpmd_State* s = p->FoundState;
s->Freq += 4; s->Freq += 4;
p->MinContext->SummFreq += 4; p->MinContext->SummFreq += 4;
if (s[0].Freq > s[-1].Freq) if (s[0].Freq > s[-1].Freq)
@ -682,7 +685,7 @@ void Ppmd7_Update1(CPpmd7 *p)
NextContext(p); NextContext(p);
} }
void Ppmd7_Update1_0(CPpmd7 *p) void Ppmd7_Update1_0(CPpmd7* p)
{ {
p->PrevSuccess = (2 * p->FoundState->Freq > p->MinContext->SummFreq); p->PrevSuccess = (2 * p->FoundState->Freq > p->MinContext->SummFreq);
p->RunLength += p->PrevSuccess; p->RunLength += p->PrevSuccess;
@ -692,15 +695,15 @@ void Ppmd7_Update1_0(CPpmd7 *p)
NextContext(p); NextContext(p);
} }
void Ppmd7_UpdateBin(CPpmd7 *p) void Ppmd7_UpdateBin(CPpmd7* p)
{ {
p->FoundState->Freq = (Byte)(p->FoundState->Freq + (p->FoundState->Freq < 128 ? 1: 0)); p->FoundState->Freq = (Byte)(p->FoundState->Freq + (p->FoundState->Freq < 128 ? 1 : 0));
p->PrevSuccess = 1; p->PrevSuccess = 1;
p->RunLength++; p->RunLength++;
NextContext(p); NextContext(p);
} }
void Ppmd7_Update2(CPpmd7 *p) void Ppmd7_Update2(CPpmd7* p)
{ {
p->MinContext->SummFreq += 4; p->MinContext->SummFreq += 4;
if ((p->FoundState->Freq += 4) > MAX_FREQ) if ((p->FoundState->Freq += 4) > MAX_FREQ)

View file

@ -22,12 +22,12 @@ EXTERN_C_BEGIN
struct CPpmd7_Context_; struct CPpmd7_Context_;
typedef typedef
#ifdef PPMD_32BIT #ifdef PPMD_32BIT
struct CPpmd7_Context_ * struct CPpmd7_Context_ *
#else #else
UInt32 UInt32
#endif #endif
CPpmd7_Context_Ref; CPpmd7_Context_Ref;
typedef struct CPpmd7_Context_ typedef struct CPpmd7_Context_
{ {
@ -42,7 +42,7 @@ typedef struct CPpmd7_Context_
typedef struct typedef struct
{ {
CPpmd7_Context *MinContext, *MaxContext; CPpmd7_Context *MinContext, *MaxContext;
CPpmd_State *FoundState; CPpmd_State* FoundState;
unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder, HiBitsFlag; unsigned OrderFall, InitEsc, PrevSuccess, MaxOrder, HiBitsFlag;
Int32 RunLength, InitRL; /* must be 32-bit at least */ Int32 RunLength, InitRL; /* must be 32-bit at least */
@ -59,10 +59,10 @@ typedef struct
UInt16 BinSumm[128][64]; UInt16 BinSumm[128][64];
} CPpmd7; } CPpmd7;
void Ppmd7_Construct(CPpmd7 *p); void Ppmd7_Construct(CPpmd7* p);
Bool Ppmd7_Alloc(CPpmd7 *p, UInt32 size, ISzAlloc *alloc); Bool Ppmd7_Alloc(CPpmd7* p, UInt32 size, ISzAlloc* alloc);
void Ppmd7_Free(CPpmd7 *p, ISzAlloc *alloc); void Ppmd7_Free(CPpmd7* p, ISzAlloc* alloc);
void Ppmd7_Init(CPpmd7 *p, unsigned maxOrder); void Ppmd7_Init(CPpmd7* p, unsigned maxOrder);
#define Ppmd7_WasAllocated(p) ((p)->Base != NULL) #define Ppmd7_WasAllocated(p) ((p)->Base != NULL)
@ -75,15 +75,15 @@ extern const Byte PPMD7_kExpEscape[16];
#define Ppmd7_GetContext(p, ptr) (ptr) #define Ppmd7_GetContext(p, ptr) (ptr)
#define Ppmd7_GetStats(p, ctx) ((ctx)->Stats) #define Ppmd7_GetStats(p, ctx) ((ctx)->Stats)
#else #else
#define Ppmd7_GetPtr(p, offs) ((void *)((p)->Base + (offs))) #define Ppmd7_GetPtr(p, offs) ((void *)((p)->Base + (offs)))
#define Ppmd7_GetContext(p, offs) ((CPpmd7_Context *)Ppmd7_GetPtr((p), (offs))) #define Ppmd7_GetContext(p, offs) ((CPpmd7_Context *)Ppmd7_GetPtr((p), (offs)))
#define Ppmd7_GetStats(p, ctx) ((CPpmd_State *)Ppmd7_GetPtr((p), ((ctx)->Stats))) #define Ppmd7_GetStats(p, ctx) ((CPpmd_State *)Ppmd7_GetPtr((p), ((ctx)->Stats)))
#endif #endif
void Ppmd7_Update1(CPpmd7 *p); void Ppmd7_Update1(CPpmd7* p);
void Ppmd7_Update1_0(CPpmd7 *p); void Ppmd7_Update1_0(CPpmd7* p);
void Ppmd7_Update2(CPpmd7 *p); void Ppmd7_Update2(CPpmd7* p);
void Ppmd7_UpdateBin(CPpmd7 *p); void Ppmd7_UpdateBin(CPpmd7* p);
#define Ppmd7_GetBinSumm(p) \ #define Ppmd7_GetBinSumm(p) \
&p->BinSumm[(unsigned)Ppmd7Context_OneState(p->MinContext)->Freq - 1][p->PrevSuccess + \ &p->BinSumm[(unsigned)Ppmd7Context_OneState(p->MinContext)->Freq - 1][p->PrevSuccess + \
@ -92,16 +92,16 @@ void Ppmd7_UpdateBin(CPpmd7 *p);
2 * p->HB2Flag[(unsigned)Ppmd7Context_OneState(p->MinContext)->Symbol] + \ 2 * p->HB2Flag[(unsigned)Ppmd7Context_OneState(p->MinContext)->Symbol] + \
((p->RunLength >> 26) & 0x20)] ((p->RunLength >> 26) & 0x20)]
CPpmd_See *Ppmd7_MakeEscFreq(CPpmd7 *p, unsigned numMasked, UInt32 *scale); CPpmd_See* Ppmd7_MakeEscFreq(CPpmd7* p, unsigned numMasked, UInt32* scale);
/* ---------- Decode ---------- */ /* ---------- Decode ---------- */
typedef struct typedef struct
{ {
UInt32 (*GetThreshold)(void *p, UInt32 total); UInt32 (*GetThreshold)(void* p, UInt32 total);
void (*Decode)(void *p, UInt32 start, UInt32 size); void (*Decode)(void* p, UInt32 start, UInt32 size);
UInt32 (*DecodeBit)(void *p, UInt32 size0); UInt32 (*DecodeBit)(void* p, UInt32 size0);
} IPpmd7_RangeDec; } IPpmd7_RangeDec;
typedef struct typedef struct
@ -109,14 +109,14 @@ typedef struct
IPpmd7_RangeDec p; IPpmd7_RangeDec p;
UInt32 Range; UInt32 Range;
UInt32 Code; UInt32 Code;
IByteIn *Stream; IByteIn* Stream;
} CPpmd7z_RangeDec; } CPpmd7z_RangeDec;
void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p); void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec* p);
Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p); Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec* p);
#define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0) #define Ppmd7z_RangeDec_IsFinishedOK(p) ((p)->Code == 0)
int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc); int Ppmd7_DecodeSymbol(CPpmd7* p, IPpmd7_RangeDec* rc);
/* ---------- Encode ---------- */ /* ---------- Encode ---------- */
@ -127,13 +127,13 @@ typedef struct
UInt32 Range; UInt32 Range;
Byte Cache; Byte Cache;
UInt64 CacheSize; UInt64 CacheSize;
IByteOut *Stream; IByteOut* Stream;
} CPpmd7z_RangeEnc; } CPpmd7z_RangeEnc;
void Ppmd7z_RangeEnc_Init(CPpmd7z_RangeEnc *p); void Ppmd7z_RangeEnc_Init(CPpmd7z_RangeEnc* p);
void Ppmd7z_RangeEnc_FlushData(CPpmd7z_RangeEnc *p); void Ppmd7z_RangeEnc_FlushData(CPpmd7z_RangeEnc* p);
void Ppmd7_EncodeSymbol(CPpmd7 *p, CPpmd7z_RangeEnc *rc, int symbol); void Ppmd7_EncodeSymbol(CPpmd7* p, CPpmd7z_RangeEnc* rc, int symbol);
EXTERN_C_END EXTERN_C_END

View file

@ -8,49 +8,49 @@ This code is based on PPMd var.H (2001): Dmitry Shkarin : Public domain */
#define kTopValue (1 << 24) #define kTopValue (1 << 24)
Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec *p) Bool Ppmd7z_RangeDec_Init(CPpmd7z_RangeDec* p)
{ {
unsigned i; unsigned i;
p->Code = 0; p->Code = 0;
p->Range = 0xFFFFFFFF; p->Range = 0xFFFFFFFF;
if (p->Stream->Read((void *)p->Stream) != 0) if (p->Stream->Read((void*)p->Stream) != 0)
return False; return False;
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream); p->Code = (p->Code << 8) | p->Stream->Read((void*)p->Stream);
return (p->Code < 0xFFFFFFFF); return (p->Code < 0xFFFFFFFF);
} }
static UInt32 Range_GetThreshold(void *pp, UInt32 total) static UInt32 Range_GetThreshold(void* pp, UInt32 total)
{ {
CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; CPpmd7z_RangeDec* p = (CPpmd7z_RangeDec*)pp;
return (p->Code) / (p->Range /= total); return (p->Code) / (p->Range /= total);
} }
static void Range_Normalize(CPpmd7z_RangeDec *p) static void Range_Normalize(CPpmd7z_RangeDec* p)
{ {
if (p->Range < kTopValue) if (p->Range < kTopValue)
{ {
p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream); p->Code = (p->Code << 8) | p->Stream->Read((void*)p->Stream);
p->Range <<= 8; p->Range <<= 8;
if (p->Range < kTopValue) if (p->Range < kTopValue)
{ {
p->Code = (p->Code << 8) | p->Stream->Read((void *)p->Stream); p->Code = (p->Code << 8) | p->Stream->Read((void*)p->Stream);
p->Range <<= 8; p->Range <<= 8;
} }
} }
} }
static void Range_Decode(void *pp, UInt32 start, UInt32 size) static void Range_Decode(void* pp, UInt32 start, UInt32 size)
{ {
CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; CPpmd7z_RangeDec* p = (CPpmd7z_RangeDec*)pp;
p->Code -= start * p->Range; p->Code -= start * p->Range;
p->Range *= size; p->Range *= size;
Range_Normalize(p); Range_Normalize(p);
} }
static UInt32 Range_DecodeBit(void *pp, UInt32 size0) static UInt32 Range_DecodeBit(void* pp, UInt32 size0)
{ {
CPpmd7z_RangeDec *p = (CPpmd7z_RangeDec *)pp; CPpmd7z_RangeDec* p = (CPpmd7z_RangeDec*)pp;
UInt32 newBound = (p->Range >> 14) * size0; UInt32 newBound = (p->Range >> 14) * size0;
UInt32 symbol; UInt32 symbol;
if (p->Code < newBound) if (p->Code < newBound)
@ -68,7 +68,7 @@ static UInt32 Range_DecodeBit(void *pp, UInt32 size0)
return symbol; return symbol;
} }
void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p) void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec* p)
{ {
p->p.GetThreshold = Range_GetThreshold; p->p.GetThreshold = Range_GetThreshold;
p->p.Decode = Range_Decode; p->p.Decode = Range_Decode;
@ -78,12 +78,12 @@ void Ppmd7z_RangeDec_CreateVTable(CPpmd7z_RangeDec *p)
#define MASK(sym) ((signed char *)charMask)[sym] #define MASK(sym) ((signed char *)charMask)[sym]
int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc) int Ppmd7_DecodeSymbol(CPpmd7* p, IPpmd7_RangeDec* rc)
{ {
size_t charMask[256 / sizeof(size_t)]; size_t charMask[256 / sizeof(size_t)];
if (p->MinContext->NumStats != 1) if (p->MinContext->NumStats != 1)
{ {
CPpmd_State *s = Ppmd7_GetStats(p, p->MinContext); CPpmd_State* s = Ppmd7_GetStats(p, p->MinContext);
unsigned i; unsigned i;
UInt32 count, hiCnt; UInt32 count, hiCnt;
if ((count = rc->GetThreshold(rc, p->MinContext->SummFreq)) < (hiCnt = s->Freq)) if ((count = rc->GetThreshold(rc, p->MinContext->SummFreq)) < (hiCnt = s->Freq))
@ -117,11 +117,12 @@ int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc)
PPMD_SetAllBitsIn256Bytes(charMask); PPMD_SetAllBitsIn256Bytes(charMask);
MASK(s->Symbol) = 0; MASK(s->Symbol) = 0;
i = p->MinContext->NumStats - 1; i = p->MinContext->NumStats - 1;
do { MASK((--s)->Symbol) = 0; } while (--i); do { MASK((--s)->Symbol) = 0; }
while (--i);
} }
else else
{ {
UInt16 *prob = Ppmd7_GetBinSumm(p); UInt16* prob = Ppmd7_GetBinSumm(p);
if (rc->DecodeBit(rc, *prob) == 0) if (rc->DecodeBit(rc, *prob) == 0)
{ {
Byte symbol; Byte symbol;
@ -140,7 +141,7 @@ int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc)
{ {
CPpmd_State *ps[256], *s; CPpmd_State *ps[256], *s;
UInt32 freqSum, count, hiCnt; UInt32 freqSum, count, hiCnt;
CPpmd_See *see; CPpmd_See* see;
unsigned i, num, numMasked = p->MinContext->NumStats; unsigned i, num, numMasked = p->MinContext->NumStats;
do do
{ {
@ -170,7 +171,7 @@ int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc)
if (count < hiCnt) if (count < hiCnt)
{ {
Byte symbol; Byte symbol;
CPpmd_State **pps = ps; CPpmd_State** pps = ps;
for (hiCnt = 0; (hiCnt += (*pps)->Freq) <= count; pps++); for (hiCnt = 0; (hiCnt += (*pps)->Freq) <= count; pps++);
s = *pps; s = *pps;
rc->Decode(rc, hiCnt - s->Freq, s->Freq); rc->Decode(rc, hiCnt - s->Freq, s->Freq);
@ -184,6 +185,7 @@ int Ppmd7_DecodeSymbol(CPpmd7 *p, IPpmd7_RangeDec *rc)
return -2; return -2;
rc->Decode(rc, hiCnt, freqSum - hiCnt); rc->Decode(rc, hiCnt, freqSum - hiCnt);
see->Summ = (UInt16)(see->Summ + freqSum); see->Summ = (UInt16)(see->Summ + freqSum);
do { MASK(ps[--i]->Symbol) = 0; } while (i != 0); do { MASK(ps[--i]->Symbol) = 0; }
while (i != 0);
} }
} }