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

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/C/Archive
diff options
context:
space:
mode:
authorIgor Pavlov <ipavlov@users.sourceforge.net>2008-05-05 04:00:00 +0400
committerKornel LesiƄski <kornel@geekhood.net>2016-05-28 02:15:55 +0300
commit3901bf0ab88106a5b031cba7bc18d60cdebf7eef (patch)
tree808a2489abed822223b118b64e0553db80af6087 /C/Archive
parentbd1fa36322ac27f5715433b388742893d6524516 (diff)
4.58 beta
Diffstat (limited to 'C/Archive')
-rwxr-xr-xC/Archive/7z/7z.dsp (renamed from C/Archive/7z/7z_C.dsp)72
-rwxr-xr-xC/Archive/7z/7z.dsw (renamed from C/Archive/7z/7z_C.dsw)2
-rwxr-xr-xC/Archive/7z/7zAlloc.c19
-rwxr-xr-xC/Archive/7z/7zAlloc.h19
-rwxr-xr-xC/Archive/7z/7zBuffer.c29
-rwxr-xr-xC/Archive/7z/7zBuffer.h19
-rwxr-xr-xC/Archive/7z/7zDecode.c280
-rwxr-xr-xC/Archive/7z/7zDecode.h16
-rwxr-xr-xC/Archive/7z/7zExtract.c77
-rwxr-xr-xC/Archive/7z/7zExtract.h10
-rwxr-xr-xC/Archive/7z/7zHeader.c6
-rwxr-xr-xC/Archive/7z/7zHeader.h5
-rwxr-xr-xC/Archive/7z/7zIn.c547
-rwxr-xr-xC/Archive/7z/7zIn.h70
-rwxr-xr-xC/Archive/7z/7zItem.c154
-rwxr-xr-xC/Archive/7z/7zItem.h86
-rwxr-xr-xC/Archive/7z/7zMain.c112
-rwxr-xr-xC/Archive/7z/7zMethodID.c10
-rwxr-xr-xC/Archive/7z/7zMethodID.h10
-rwxr-xr-xC/Archive/7z/makefile60
-rwxr-xr-xC/Archive/7z/makefile.gcc23
21 files changed, 731 insertions, 895 deletions
diff --git a/C/Archive/7z/7z_C.dsp b/C/Archive/7z/7z.dsp
index 9a040ad1..a0246af9 100755
--- a/C/Archive/7z/7z_C.dsp
+++ b/C/Archive/7z/7z.dsp
@@ -1,24 +1,24 @@
-# Microsoft Developer Studio Project File - Name="7z_C" - Package Owner=<4>
+# Microsoft Developer Studio Project File - Name="7z" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
-CFG=7z_C - Win32 Debug
+CFG=7z - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
-!MESSAGE NMAKE /f "7z_C.mak".
+!MESSAGE NMAKE /f "7z.mak".
!MESSAGE
!MESSAGE You can specify a configuration when running NMAKE
!MESSAGE by defining the macro CFG on the command line. For example:
!MESSAGE
-!MESSAGE NMAKE /f "7z_C.mak" CFG="7z_C - Win32 Debug"
+!MESSAGE NMAKE /f "7z.mak" CFG="7z - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
-!MESSAGE "7z_C - Win32 Release" (based on "Win32 (x86) Console Application")
-!MESSAGE "7z_C - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE "7z - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "7z - Win32 Debug" (based on "Win32 (x86) Console Application")
!MESSAGE
# Begin Project
@@ -28,7 +28,7 @@ CFG=7z_C - Win32 Debug
CPP=cl.exe
RSC=rc.exe
-!IF "$(CFG)" == "7z_C - Win32 Release"
+!IF "$(CFG)" == "7z - Win32 Release"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 0
@@ -42,7 +42,7 @@ RSC=rc.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
-# ADD CPP /nologo /MD /W4 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_LZMA_PROB32" /D "_LZMA_IN_CB" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
# ADD BASE RSC /l 0x419 /d "NDEBUG"
# ADD RSC /l 0x419 /d "NDEBUG"
BSC32=bscmake.exe
@@ -53,7 +53,7 @@ LINK32=link.exe
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /out:"Release/7zDec.exe" /opt:NOWIN98
# SUBTRACT LINK32 /pdb:none
-!ELSEIF "$(CFG)" == "7z_C - Win32 Debug"
+!ELSEIF "$(CFG)" == "7z - Win32 Debug"
# PROP BASE Use_MFC 0
# PROP BASE Use_Debug_Libraries 1
@@ -67,7 +67,7 @@ LINK32=link.exe
# PROP Ignore_Export_Lib 0
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
-# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "_LZMA_PROB32" /D "_LZMA_IN_CB" /YX /FD /GZ /c
+# ADD CPP /nologo /W4 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
# ADD BASE RSC /l 0x419 /d "_DEBUG"
# ADD RSC /l 0x419 /d "_DEBUG"
BSC32=bscmake.exe
@@ -81,29 +81,21 @@ LINK32=link.exe
# Begin Target
-# Name "7z_C - Win32 Release"
-# Name "7z_C - Win32 Debug"
-# Begin Group "LZMA"
+# Name "7z - Win32 Release"
+# Name "7z - Win32 Debug"
+# Begin Group "Common"
# PROP Default_Filter ""
# Begin Source File
-SOURCE=..\..\Compress\Lzma\LzmaDecode.c
+SOURCE=..\..\7zBuf.c
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Lzma\LzmaDecode.h
+SOURCE=..\..\7zBuf.h
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Lzma\LzmaTypes.h
-# End Source File
-# End Group
-# Begin Group "Common"
-
-# PROP Default_Filter ""
-# Begin Source File
-
SOURCE=..\..\7zCrc.c
# End Source File
# Begin Source File
@@ -112,31 +104,31 @@ SOURCE=..\..\7zCrc.h
# End Source File
# Begin Source File
-SOURCE=..\..\Types.h
+SOURCE=..\..\Bcj2.c
# End Source File
-# End Group
-# Begin Group "Branch"
+# Begin Source File
-# PROP Default_Filter ""
+SOURCE=..\..\Bcj2.h
+# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\BranchTypes.h
+SOURCE=..\..\Bra.h
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\BranchX86.c
+SOURCE=..\..\Bra86.c
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\BranchX86.h
+SOURCE=..\..\LzmaDec.c
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\BranchX86_2.c
+SOURCE=..\..\LzmaDec.h
# End Source File
# Begin Source File
-SOURCE=..\..\Compress\Branch\BranchX86_2.h
+SOURCE=..\..\Types.h
# End Source File
# End Group
# Begin Source File
@@ -149,14 +141,6 @@ SOURCE=.\7zAlloc.h
# End Source File
# Begin Source File
-SOURCE=.\7zBuffer.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zBuffer.h
-# End Source File
-# Begin Source File
-
SOURCE=.\7zDecode.c
# End Source File
# Begin Source File
@@ -199,13 +183,5 @@ SOURCE=.\7zItem.h
SOURCE=.\7zMain.c
# End Source File
-# Begin Source File
-
-SOURCE=.\7zMethodID.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\7zMethodID.h
-# End Source File
# End Target
# End Project
diff --git a/C/Archive/7z/7z_C.dsw b/C/Archive/7z/7z.dsw
index 6fd39621..848d13cb 100755
--- a/C/Archive/7z/7z_C.dsw
+++ b/C/Archive/7z/7z.dsw
@@ -3,7 +3,7 @@ Microsoft Developer Studio Workspace File, Format Version 6.00
###############################################################################
-Project: "7z_C"=.\7z_C.dsp - Package Owner=<4>
+Project: "7z"=.\7z.dsp - Package Owner=<4>
Package=<5>
{{{
diff --git a/C/Archive/7z/7zAlloc.c b/C/Archive/7z/7zAlloc.c
index 21bb30c7..1b48a258 100755
--- a/C/Archive/7z/7zAlloc.c
+++ b/C/Archive/7z/7zAlloc.c
@@ -1,4 +1,7 @@
-/* 7zAlloc.c */
+/* 7zAlloc.c -- Allocation functions
+2008-03-28
+Igor Pavlov
+Public domain */
#include <stdlib.h>
#include "7zAlloc.h"
@@ -11,13 +14,16 @@
#ifdef _WIN32
#include <windows.h>
#endif
+
#include <stdio.h>
int g_allocCount = 0;
int g_allocCountTemp = 0;
+
#endif
-void *SzAlloc(size_t size)
+void *SzAlloc(void *p, size_t size)
{
+ p = p;
if (size == 0)
return 0;
#ifdef _SZ_ALLOC_DEBUG
@@ -27,8 +33,9 @@ void *SzAlloc(size_t size)
return malloc(size);
}
-void SzFree(void *address)
+void SzFree(void *p, void *address)
{
+ p = p;
#ifdef _SZ_ALLOC_DEBUG
if (address != 0)
{
@@ -39,8 +46,9 @@ void SzFree(void *address)
free(address);
}
-void *SzAllocTemp(size_t size)
+void *SzAllocTemp(void *p, size_t size)
{
+ p = p;
if (size == 0)
return 0;
#ifdef _SZ_ALLOC_DEBUG
@@ -53,8 +61,9 @@ void *SzAllocTemp(size_t size)
return malloc(size);
}
-void SzFreeTemp(void *address)
+void SzFreeTemp(void *p, void *address)
{
+ p = p;
#ifdef _SZ_ALLOC_DEBUG
if (address != 0)
{
diff --git a/C/Archive/7z/7zAlloc.h b/C/Archive/7z/7zAlloc.h
index 4ca4170c..714ecf15 100755
--- a/C/Archive/7z/7zAlloc.h
+++ b/C/Archive/7z/7zAlloc.h
@@ -1,20 +1,17 @@
-/* 7zAlloc.h */
+/* 7zAlloc.h -- Allocation functions
+2008-03-28
+Igor Pavlov
+Public domain */
#ifndef __7Z_ALLOC_H
#define __7Z_ALLOC_H
#include <stddef.h>
-typedef struct _ISzAlloc
-{
- void *(*Alloc)(size_t size);
- void (*Free)(void *address); /* address can be 0 */
-} ISzAlloc;
+void *SzAlloc(void *p, size_t size);
+void SzFree(void *p, void *address);
-void *SzAlloc(size_t size);
-void SzFree(void *address);
-
-void *SzAllocTemp(size_t size);
-void SzFreeTemp(void *address);
+void *SzAllocTemp(void *p, size_t size);
+void SzFreeTemp(void *p, void *address);
#endif
diff --git a/C/Archive/7z/7zBuffer.c b/C/Archive/7z/7zBuffer.c
deleted file mode 100755
index 3c4b71e8..00000000
--- a/C/Archive/7z/7zBuffer.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* 7zBuffer.c */
-
-#include "7zBuffer.h"
-#include "7zAlloc.h"
-
-void SzByteBufferInit(CSzByteBuffer *buffer)
-{
- buffer->Capacity = 0;
- buffer->Items = 0;
-}
-
-int SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size))
-{
- buffer->Capacity = newCapacity;
- if (newCapacity == 0)
- {
- buffer->Items = 0;
- return 1;
- }
- buffer->Items = (Byte *)allocFunc(newCapacity);
- return (buffer->Items != 0);
-}
-
-void SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *))
-{
- freeFunc(buffer->Items);
- buffer->Items = 0;
- buffer->Capacity = 0;
-}
diff --git a/C/Archive/7z/7zBuffer.h b/C/Archive/7z/7zBuffer.h
deleted file mode 100755
index 05c6d748..00000000
--- a/C/Archive/7z/7zBuffer.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* 7zBuffer.h */
-
-#ifndef __7Z_BUFFER_H
-#define __7Z_BUFFER_H
-
-#include <stddef.h>
-#include "../../Types.h"
-
-typedef struct _CSzByteBuffer
-{
- size_t Capacity;
- Byte *Items;
-}CSzByteBuffer;
-
-void SzByteBufferInit(CSzByteBuffer *buffer);
-int SzByteBufferCreate(CSzByteBuffer *buffer, size_t newCapacity, void * (*allocFunc)(size_t size));
-void SzByteBufferFree(CSzByteBuffer *buffer, void (*freeFunc)(void *));
-
-#endif
diff --git a/C/Archive/7z/7zDecode.c b/C/Archive/7z/7zDecode.c
index aea893da..02a3c008 100755
--- a/C/Archive/7z/7zDecode.c
+++ b/C/Archive/7z/7zDecode.c
@@ -1,153 +1,114 @@
-/* 7zDecode.c */
+/* 7zDecode.c Decoding from 7z folder
+2008-04-09
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read 7zDecode.h for license options */
-#include <memory.h>
+#include <string.h>
#include "7zDecode.h"
-#ifdef _SZ_ONE_DIRECTORY
-#include "LzmaDecode.h"
-#else
-#include "../../Compress/Lzma/LzmaDecode.h"
-#include "../../Compress/Branch/BranchX86.h"
-#include "../../Compress/Branch/BranchX86_2.h"
-#endif
+#include "../../LzmaDec.h"
+#include "../../Bra.h"
+#include "../../Bcj2.h"
#define k_Copy 0
#define k_LZMA 0x30101
#define k_BCJ 0x03030103
#define k_BCJ2 0x0303011B
+/*
#ifdef _LZMA_IN_CB
+*/
-typedef struct _CLzmaInCallbackImp
+static SRes SzDecodeLzma(CSzCoderInfo *coder, CFileSize inSize, ISzInStream *inStream,
+ Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)
{
- ILzmaInCallback InCallback;
- ISzInStream *InStream;
- CFileSize Size;
-} CLzmaInCallbackImp;
+ CLzmaDec state;
+ int res = SZ_OK;
+ size_t _inSize;
+ Byte *inBuf = NULL;
-int LzmaReadImp(void *object, const unsigned char **buffer, SizeT *size)
-{
- CLzmaInCallbackImp *cb = (CLzmaInCallbackImp *)object;
- size_t processedSize;
- SZ_RESULT res;
- size_t curSize = (1 << 20);
- if (curSize > cb->Size)
- curSize = (size_t)cb->Size;
- *size = 0;
- res = cb->InStream->Read((void *)cb->InStream, (void **)buffer, curSize, &processedSize);
- *size = (SizeT)processedSize;
- if (processedSize > curSize)
- return (int)SZE_FAIL;
- cb->Size -= processedSize;
- if (res == SZ_OK)
- return 0;
- return (int)res;
-}
+ LzmaDec_Construct(&state);
+ RINOK(LzmaDec_AllocateProbs(&state, coder->Props.data, (unsigned)coder->Props.size, allocMain));
+ state.dic = outBuffer;
+ state.dicBufSize = outSize;
+ LzmaDec_Init(&state);
-#endif
+ _inSize = 0;
-SZ_RESULT SzDecodeLzma(CCoderInfo *coder, CFileSize inSize,
- #ifdef _LZMA_IN_CB
- ISzInStream *inStream,
- #else
- const Byte *inBuffer,
- #endif
- Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)
-{
- #ifdef _LZMA_IN_CB
- CLzmaInCallbackImp lzmaCallback;
- #else
- SizeT inProcessed;
- #endif
-
- CLzmaDecoderState state; /* it's about 24-80 bytes structure, if int is 32-bit */
- int result;
- SizeT outSizeProcessedLoc;
-
- #ifdef _LZMA_IN_CB
- lzmaCallback.Size = inSize;
- lzmaCallback.InStream = inStream;
- lzmaCallback.InCallback.Read = LzmaReadImp;
- #endif
-
- if (LzmaDecodeProperties(&state.Properties, coder->Properties.Items,
- (unsigned)coder->Properties.Capacity) != LZMA_RESULT_OK)
- return SZE_FAIL;
-
- state.Probs = (CProb *)allocMain->Alloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
- if (state.Probs == 0)
- return SZE_OUTOFMEMORY;
-
- #ifdef _LZMA_OUT_READ
- if (state.Properties.DictionarySize == 0)
- state.Dictionary = 0;
- else
+ for (;;)
{
- state.Dictionary = (unsigned char *)allocMain->Alloc(state.Properties.DictionarySize);
- if (state.Dictionary == 0)
+ if (_inSize == 0)
{
- allocMain->Free(state.Probs);
- return SZE_OUTOFMEMORY;
+ _inSize = (1 << 18);
+ if (_inSize > inSize)
+ _inSize = (size_t)(inSize);
+ res = inStream->Read((void *)inStream, (void **)&inBuf, &_inSize);
+ if (res != SZ_OK)
+ break;
+ inSize -= _inSize;
}
- }
- LzmaDecoderInit(&state);
- #endif
-
- result = LzmaDecode(&state,
- #ifdef _LZMA_IN_CB
- &lzmaCallback.InCallback,
- #else
- inBuffer, (SizeT)inSize, &inProcessed,
- #endif
- outBuffer, (SizeT)outSize, &outSizeProcessedLoc);
- allocMain->Free(state.Probs);
- #ifdef _LZMA_OUT_READ
- allocMain->Free(state.Dictionary);
- #endif
- if (result == LZMA_RESULT_DATA_ERROR)
- return SZE_DATA_ERROR;
- if (result != LZMA_RESULT_OK)
- return SZE_FAIL;
- return (outSizeProcessedLoc == outSize) ? SZ_OK : SZE_DATA_ERROR;
+
+ {
+ SizeT inProcessed = _inSize, dicPos = state.dicPos;
+ ELzmaStatus status;
+ res = LzmaDec_DecodeToDic(&state, outSize, inBuf, &inProcessed, LZMA_FINISH_END, &status);
+ _inSize -= inProcessed;
+ inBuf = (Byte *)inBuf + inProcessed;
+ if (res != SZ_OK)
+ break;
+ if (state.dicPos == state.dicBufSize || (inProcessed == 0 && dicPos == state.dicPos))
+ {
+ if (state.dicBufSize != outSize || _inSize != 0 ||
+ (status != LZMA_STATUS_FINISHED_WITH_MARK &&
+ status != LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK))
+ res = SZ_ERROR_DATA;
+ break;
+ }
+ }
+ }
+
+ LzmaDec_FreeProbs(&state, allocMain);
+
+ return res;
}
-#ifdef _LZMA_IN_CB
-SZ_RESULT SzDecodeCopy(CFileSize inSize, ISzInStream *inStream, Byte *outBuffer)
+static SRes SzDecodeCopy(CFileSize inSize, ISzInStream *inStream, Byte *outBuffer)
{
while (inSize > 0)
{
void *inBuffer;
- size_t processedSize, curSize = (1 << 18);
+ size_t curSize = (1 << 18);
if (curSize > inSize)
curSize = (size_t)(inSize);
- RINOK(inStream->Read((void *)inStream, (void **)&inBuffer, curSize, &processedSize));
- if (processedSize == 0)
- return SZE_DATA_ERROR;
- if (processedSize > curSize)
- return SZE_FAIL;
- memcpy(outBuffer, inBuffer, processedSize);
- outBuffer += processedSize;
- inSize -= processedSize;
+ RINOK(inStream->Read((void *)inStream, (void **)&inBuffer, &curSize));
+ if (curSize == 0)
+ return SZ_ERROR_INPUT_EOF;
+ memcpy(outBuffer, inBuffer, curSize);
+ outBuffer += curSize;
+ inSize -= curSize;
}
return SZ_OK;
}
+/*
#endif
+*/
#define IS_UNSUPPORTED_METHOD(m) ((m) != k_Copy && (m) != k_LZMA)
#define IS_UNSUPPORTED_CODER(c) (IS_UNSUPPORTED_METHOD(c.MethodID) || c.NumInStreams != 1 || c.NumOutStreams != 1)
#define IS_NO_BCJ(c) (c.MethodID != k_BCJ || c.NumInStreams != 1 || c.NumOutStreams != 1)
#define IS_NO_BCJ2(c) (c.MethodID != k_BCJ2 || c.NumInStreams != 4 || c.NumOutStreams != 1)
-SZ_RESULT CheckSupportedFolder(const CFolder *f)
+SRes CheckSupportedFolder(const CSzFolder *f)
{
if (f->NumCoders < 1 || f->NumCoders > 4)
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
if (IS_UNSUPPORTED_CODER(f->Coders[0]))
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
if (f->NumCoders == 1)
{
if (f->NumPackStreams != 1 || f->PackStreams[0] != 0 || f->NumBindPairs != 0)
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
return SZ_OK;
}
if (f->NumCoders == 2)
@@ -156,7 +117,7 @@ SZ_RESULT CheckSupportedFolder(const CFolder *f)
f->NumPackStreams != 1 || f->PackStreams[0] != 0 ||
f->NumBindPairs != 1 ||
f->BindPairs[0].InIndex != 1 || f->BindPairs[0].OutIndex != 0)
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
return SZ_OK;
}
if (f->NumCoders == 4)
@@ -164,7 +125,7 @@ SZ_RESULT CheckSupportedFolder(const CFolder *f)
if (IS_UNSUPPORTED_CODER(f->Coders[1]) ||
IS_UNSUPPORTED_CODER(f->Coders[2]) ||
IS_NO_BCJ2(f->Coders[3]))
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
if (f->NumPackStreams != 4 ||
f->PackStreams[0] != 2 ||
f->PackStreams[1] != 6 ||
@@ -174,10 +135,10 @@ SZ_RESULT CheckSupportedFolder(const CFolder *f)
f->BindPairs[0].InIndex != 5 || f->BindPairs[0].OutIndex != 0 ||
f->BindPairs[1].InIndex != 4 || f->BindPairs[1].OutIndex != 1 ||
f->BindPairs[2].InIndex != 3 || f->BindPairs[2].OutIndex != 2)
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
return SZ_OK;
}
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
}
CFileSize GetSum(const CFileSize *values, UInt32 index)
@@ -189,12 +150,16 @@ CFileSize GetSum(const CFileSize *values, UInt32 index)
return sum;
}
-SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
+SRes SzDecode2(const CFileSize *packSizes, const CSzFolder *folder,
+ /*
#ifdef _LZMA_IN_CB
+ */
ISzInStream *inStream, CFileSize startPos,
+ /*
#else
const Byte *inBuffer,
#endif
+ */
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain,
Byte *tempBuf[])
{
@@ -207,7 +172,7 @@ SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
for (ci = 0; ci < folder->NumCoders; ci++)
{
- CCoderInfo *coder = &folder->Coders[ci];
+ CSzCoderInfo *coder = &folder->Coders[ci];
if (coder->MethodID == k_Copy || coder->MethodID == k_LZMA)
{
@@ -226,57 +191,74 @@ SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
Byte *temp;
outSizeCur = (size_t)unpackSize;
if (outSizeCur != unpackSize)
- return SZE_OUTOFMEMORY;
- temp = (Byte *)allocMain->Alloc(outSizeCur);
+ return SZ_ERROR_MEM;
+ temp = (Byte *)IAlloc_Alloc(allocMain, outSizeCur);
if (temp == 0 && outSizeCur != 0)
- return SZE_OUTOFMEMORY;
+ return SZ_ERROR_MEM;
outBufCur = tempBuf[1 - ci] = temp;
tempSizes[1 - ci] = outSizeCur;
}
else if (ci == 2)
{
- if (unpackSize > outSize)
- return SZE_OUTOFMEMORY;
+ if (unpackSize > outSize) // check it
+ return SZ_ERROR_PARAM; // check it
tempBuf3 = outBufCur = outBuffer + (outSize - (size_t)unpackSize);
tempSize3 = outSizeCur = (size_t)unpackSize;
}
else
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
}
offset = GetSum(packSizes, si);
inSize = packSizes[si];
+ /*
#ifdef _LZMA_IN_CB
- RINOK(inStream->Seek(inStream, startPos + offset));
+ */
+ RINOK(inStream->Seek(inStream, startPos + offset, SZ_SEEK_SET));
+ /*
#endif
+ */
if (coder->MethodID == k_Copy)
{
- if (inSize != outSizeCur)
- return SZE_DATA_ERROR;
+ if (inSize != outSizeCur) // check it
+ return SZ_ERROR_DATA;
+ /*
#ifdef _LZMA_IN_CB
+ */
RINOK(SzDecodeCopy(inSize, inStream, outBufCur));
+ /*
#else
memcpy(outBufCur, inBuffer + (size_t)offset, (size_t)inSize);
#endif
+ */
}
else
{
- SZ_RESULT res = SzDecodeLzma(coder, inSize,
- #ifdef _LZMA_IN_CB
+ /*
+ #ifdef _LZMA_IN_CB
+ */
+ SRes res = SzDecodeLzma(coder, inSize,
inStream,
- #else
- inBuffer + (size_t)offset,
- #endif
outBufCur, outSizeCur, allocMain);
- RINOK(res)
+ /*
+ #else
+ SizeT lzmaOutSizeT = outSizeCur;
+ SizeT lzmaInSizeT = (SizeT)inSize;
+ SRes res = LzmaDecode(outBufCur, &lzmaOutSizeT,
+ inBuffer + (size_t)offset, &lzmaInSizeT,
+ coder->Props.Items, (unsigned)coder->Props.size, LZMA_FINISH_BYTE, allocMain);
+ #endif
+ */
+
+ RINOK(res);
}
}
else if (coder->MethodID == k_BCJ)
{
UInt32 state;
if (ci != 1)
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
x86_Convert_Init(state);
x86_Convert(outBuffer, outSize, 0, &state, 0);
}
@@ -284,58 +266,74 @@ SZ_RESULT SzDecode2(const CFileSize *packSizes, const CFolder *folder,
{
CFileSize offset = GetSum(packSizes, 1);
CFileSize s3Size = packSizes[1];
- SZ_RESULT res;
+ SRes res;
if (ci != 3)
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
+ /*
#ifdef _LZMA_IN_CB
- RINOK(inStream->Seek(inStream, startPos + offset));
+ */
+ RINOK(inStream->Seek(inStream, startPos + offset, SZ_SEEK_SET));
tempSizes[2] = (size_t)s3Size;
if (tempSizes[2] != s3Size)
- return SZE_OUTOFMEMORY;
- tempBuf[2] = (Byte *)allocMain->Alloc(tempSizes[2]);
+ return SZ_ERROR_MEM;
+ tempBuf[2] = (Byte *)IAlloc_Alloc(allocMain, tempSizes[2]);
if (tempBuf[2] == 0 && tempSizes[2] != 0)
- return SZE_OUTOFMEMORY;
+ return SZ_ERROR_MEM;
res = SzDecodeCopy(s3Size, inStream, tempBuf[2]);
RINOK(res)
+ /*
#endif
+ */
- res = x86_2_Decode(
+ res = Bcj2_Decode(
tempBuf3, tempSize3,
tempBuf[0], tempSizes[0],
tempBuf[1], tempSizes[1],
+ /*
#ifdef _LZMA_IN_CB
+ */
tempBuf[2], tempSizes[2],
+ /*
#else
inBuffer + (size_t)offset, (size_t)s3Size,
#endif
+ */
outBuffer, outSize);
RINOK(res)
}
else
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
}
return SZ_OK;
}
-SZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,
+SRes SzDecode(const CFileSize *packSizes, const CSzFolder *folder,
+ /*
#ifdef _LZMA_IN_CB
+ */
ISzInStream *inStream, CFileSize startPos,
+ /*
#else
const Byte *inBuffer,
#endif
+ */
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain)
{
Byte *tempBuf[3] = { 0, 0, 0};
int i;
- SZ_RESULT res = SzDecode2(packSizes, folder,
+ SRes res = SzDecode2(packSizes, folder,
+ /*
#ifdef _LZMA_IN_CB
+ */
inStream, startPos,
+ /*
#else
inBuffer,
#endif
+ */
outBuffer, outSize, allocMain, tempBuf);
for (i = 0; i < 3; i++)
- allocMain->Free(tempBuf[i]);
+ IAlloc_Free(allocMain, tempBuf[i]);
return res;
}
diff --git a/C/Archive/7z/7zDecode.h b/C/Archive/7z/7zDecode.h
index 175896ef..5b0996d7 100755
--- a/C/Archive/7z/7zDecode.h
+++ b/C/Archive/7z/7zDecode.h
@@ -1,20 +1,26 @@
-/* 7zDecode.h */
+/* 7zDecode.h -- Decoding from 7z folder
+2008-04-09
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read 7zItem.h for license options */
#ifndef __7Z_DECODE_H
#define __7Z_DECODE_H
#include "7zItem.h"
-#include "7zAlloc.h"
-#ifdef _LZMA_IN_CB
+
#include "7zIn.h"
-#endif
-SZ_RESULT SzDecode(const CFileSize *packSizes, const CFolder *folder,
+SRes SzDecode(const CFileSize *packSizes, const CSzFolder *folder,
+ /*
#ifdef _LZMA_IN_CB
+ */
ISzInStream *stream, CFileSize startPos,
+ /*
#else
const Byte *inBuffer,
#endif
+ */
Byte *outBuffer, size_t outSize, ISzAlloc *allocMain);
#endif
diff --git a/C/Archive/7z/7zExtract.c b/C/Archive/7z/7zExtract.c
index 1760a3ce..40b592aa 100755
--- a/C/Archive/7z/7zExtract.c
+++ b/C/Archive/7z/7zExtract.c
@@ -1,12 +1,16 @@
-/* 7zExtract.c */
+/* 7zExtract.c -- Extracting from 7z archive
+2008-04-09
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read 7zExtract.h for license options */
#include "7zExtract.h"
#include "7zDecode.h"
#include "../../7zCrc.h"
-SZ_RESULT SzExtract(
+SRes SzAr_Extract(
+ const CSzArEx *p,
ISzInStream *inStream,
- CArchiveDatabaseEx *db,
UInt32 fileIndex,
UInt32 *blockIndex,
Byte **outBuffer,
@@ -16,13 +20,13 @@ SZ_RESULT SzExtract(
ISzAlloc *allocMain,
ISzAlloc *allocTemp)
{
- UInt32 folderIndex = db->FileIndexToFolderIndexMap[fileIndex];
- SZ_RESULT res = SZ_OK;
+ UInt32 folderIndex = p->FileIndexToFolderIndexMap[fileIndex];
+ SRes res = SZ_OK;
*offset = 0;
*outSizeProcessed = 0;
if (folderIndex == (UInt32)-1)
{
- allocMain->Free(*outBuffer);
+ IAlloc_Free(allocMain, *outBuffer);
*blockIndex = folderIndex;
*outBuffer = 0;
*outBufferSize = 0;
@@ -31,87 +35,60 @@ SZ_RESULT SzExtract(
if (*outBuffer == 0 || *blockIndex != folderIndex)
{
- CFolder *folder = db->Database.Folders + folderIndex;
- CFileSize unPackSizeSpec = SzFolderGetUnPackSize(folder);
+ CSzFolder *folder = p->db.Folders + folderIndex;
+ CFileSize unPackSizeSpec = SzFolder_GetUnPackSize(folder);
size_t unPackSize = (size_t)unPackSizeSpec;
- CFileSize startOffset = SzArDbGetFolderStreamPos(db, folderIndex, 0);
- #ifndef _LZMA_IN_CB
- Byte *inBuffer = 0;
- size_t processedSize;
- CFileSize packSizeSpec;
- size_t packSize;
- RINOK(SzArDbGetFolderFullPackSize(db, folderIndex, &packSizeSpec));
- packSize = (size_t)packSizeSpec;
- if (packSize != packSizeSpec)
- return SZE_OUTOFMEMORY;
- #endif
+ CFileSize startOffset = SzArEx_GetFolderStreamPos(p, folderIndex, 0);
+
if (unPackSize != unPackSizeSpec)
- return SZE_OUTOFMEMORY;
+ return SZ_ERROR_MEM;
*blockIndex = folderIndex;
- allocMain->Free(*outBuffer);
+ IAlloc_Free(allocMain, *outBuffer);
*outBuffer = 0;
- RINOK(inStream->Seek(inStream, startOffset));
+ RINOK(inStream->Seek(inStream, startOffset, SZ_SEEK_SET));
- #ifndef _LZMA_IN_CB
- if (packSize != 0)
- {
- inBuffer = (Byte *)allocTemp->Alloc(packSize);
- if (inBuffer == 0)
- return SZE_OUTOFMEMORY;
- }
- res = inStream->Read(inStream, inBuffer, packSize, &processedSize);
- if (res == SZ_OK && processedSize != packSize)
- res = SZE_FAIL;
- #endif
if (res == SZ_OK)
{
*outBufferSize = unPackSize;
if (unPackSize != 0)
{
- *outBuffer = (Byte *)allocMain->Alloc(unPackSize);
+ *outBuffer = (Byte *)IAlloc_Alloc(allocMain, unPackSize);
if (*outBuffer == 0)
- res = SZE_OUTOFMEMORY;
+ res = SZ_ERROR_MEM;
}
if (res == SZ_OK)
{
- res = SzDecode(db->Database.PackSizes +
- db->FolderStartPackStreamIndex[folderIndex], folder,
- #ifdef _LZMA_IN_CB
+ res = SzDecode(p->db.PackSizes +
+ p->FolderStartPackStreamIndex[folderIndex], folder,
inStream, startOffset,
- #else
- inBuffer,
- #endif
*outBuffer, unPackSize, allocTemp);
if (res == SZ_OK)
{
if (folder->UnPackCRCDefined)
{
if (CrcCalc(*outBuffer, unPackSize) != folder->UnPackCRC)
- res = SZE_CRC_ERROR;
+ res = SZ_ERROR_CRC;
}
}
}
}
- #ifndef _LZMA_IN_CB
- allocTemp->Free(inBuffer);
- #endif
}
if (res == SZ_OK)
{
UInt32 i;
- CFileItem *fileItem = db->Database.Files + fileIndex;
+ CSzFileItem *fileItem = p->db.Files + fileIndex;
*offset = 0;
- for(i = db->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)
- *offset += (UInt32)db->Database.Files[i].Size;
+ for(i = p->FolderStartFileIndex[folderIndex]; i < fileIndex; i++)
+ *offset += (UInt32)p->db.Files[i].Size;
*outSizeProcessed = (size_t)fileItem->Size;
if (*offset + *outSizeProcessed > *outBufferSize)
- return SZE_FAIL;
+ return SZ_ERROR_FAIL;
{
if (fileItem->IsFileCRCDefined)
{
if (CrcCalc(*outBuffer + *offset, *outSizeProcessed) != fileItem->FileCRC)
- res = SZE_CRC_ERROR;
+ res = SZ_ERROR_CRC;
}
}
}
diff --git a/C/Archive/7z/7zExtract.h b/C/Archive/7z/7zExtract.h
index e9a4fb4e..cd0e4f03 100755
--- a/C/Archive/7z/7zExtract.h
+++ b/C/Archive/7z/7zExtract.h
@@ -1,4 +1,8 @@
-/* 7zExtract.h */
+/* 7zExtract.h -- Extracting from 7z archive
+2008-04-09
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read 7zItem.h for license options */
#ifndef __7Z_EXTRACT_H
#define __7Z_EXTRACT_H
@@ -25,9 +29,9 @@
Free *outBuffer and set *outBuffer to 0, if you want to flush cache.
*/
-SZ_RESULT SzExtract(
+SRes SzAr_Extract(
+ const CSzArEx *db,
ISzInStream *inStream,
- CArchiveDatabaseEx *db,
UInt32 fileIndex, /* index of file */
UInt32 *blockIndex, /* index of solid block */
Byte **outBuffer, /* pointer to pointer to output buffer (allocated with allocMain) */
diff --git a/C/Archive/7z/7zHeader.c b/C/Archive/7z/7zHeader.c
index 3be4bc27..3edb8d00 100755
--- a/C/Archive/7z/7zHeader.c
+++ b/C/Archive/7z/7zHeader.c
@@ -1,4 +1,8 @@
-/* 7zHeader.c */
+/* 7zHeader.c -- 7z Headers
+2008-04-09
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read 7zHeader.h for license options */
#include "7zHeader.h"
diff --git a/C/Archive/7z/7zHeader.h b/C/Archive/7z/7zHeader.h
index 3e67cf57..9cd3e3dc 100755
--- a/C/Archive/7z/7zHeader.h
+++ b/C/Archive/7z/7zHeader.h
@@ -1,4 +1,7 @@
-/* 7zHeader.h */
+/* 7zHeader.h -- 7z Headers
+2008-03-17
+Copyright (c) 1999-2008 Igor Pavlov
+Read LzmaDec.h for license options */
#ifndef __7Z_HEADER_H
#define __7Z_HEADER_H
diff --git a/C/Archive/7z/7zIn.c b/C/Archive/7z/7zIn.c
index ac25dbc7..b99a6ac7 100755
--- a/C/Archive/7z/7zIn.c
+++ b/C/Archive/7z/7zIn.c
@@ -1,28 +1,32 @@
-/* 7zIn.c */
+/* 7zIn.c -- 7z Input functions
+2008-04-09
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read 7zIn.h for license options */
#include "7zIn.h"
#include "7zDecode.h"
#include "../../7zCrc.h"
-#define RINOM(x) { if((x) == 0) return SZE_OUTOFMEMORY; }
+#define RINOM(x) { if((x) == 0) return SZ_ERROR_MEM; }
-void SzArDbExInit(CArchiveDatabaseEx *db)
+void SzArEx_Init(CSzArEx *p)
{
- SzArchiveDatabaseInit(&db->Database);
- db->FolderStartPackStreamIndex = 0;
- db->PackStreamStartPositions = 0;
- db->FolderStartFileIndex = 0;
- db->FileIndexToFolderIndexMap = 0;
+ SzAr_Init(&p->db);
+ p->FolderStartPackStreamIndex = 0;
+ p->PackStreamStartPositions = 0;
+ p->FolderStartFileIndex = 0;
+ p->FileIndexToFolderIndexMap = 0;
}
-void SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *))
+void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc)
{
- freeFunc(db->FolderStartPackStreamIndex);
- freeFunc(db->PackStreamStartPositions);
- freeFunc(db->FolderStartFileIndex);
- freeFunc(db->FileIndexToFolderIndexMap);
- SzArchiveDatabaseFree(&db->Database, freeFunc);
- SzArDbExInit(db);
+ IAlloc_Free(alloc, p->FolderStartPackStreamIndex);
+ IAlloc_Free(alloc, p->PackStreamStartPositions);
+ IAlloc_Free(alloc, p->FolderStartFileIndex);
+ IAlloc_Free(alloc, p->FileIndexToFolderIndexMap);
+ SzAr_Free(&p->db, alloc);
+ SzArEx_Init(p);
}
/*
@@ -36,7 +40,7 @@ CFileSize GetFilePackSize(int fileIndex) const
int folderIndex = FileIndexToFolderIndexMap[fileIndex];
if (folderIndex >= 0)
{
- const CFolder &folderInfo = Folders[folderIndex];
+ const CSzFolder &folderInfo = Folders[folderIndex];
if (FolderStartFileIndex[folderIndex] == fileIndex)
return GetFolderFullPackSize(folderIndex);
}
@@ -44,41 +48,41 @@ CFileSize GetFilePackSize(int fileIndex) const
}
*/
-#define MY_ALLOC(T, p, size, allocFunc) { if ((size) == 0) p = 0; else \
- if ((p = (T *)allocFunc((size) * sizeof(T))) == 0) return SZE_OUTOFMEMORY; }
+#define MY_ALLOC(T, p, size, alloc) { if ((size) == 0) p = 0; else \
+ if ((p = (T *)IAlloc_Alloc(alloc, (size) * sizeof(T))) == 0) return SZ_ERROR_MEM; }
-SZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size))
+static SRes SzArEx_Fill(CSzArEx *p, ISzAlloc *alloc)
{
UInt32 startPos = 0;
CFileSize startPosSize = 0;
UInt32 i;
UInt32 folderIndex = 0;
UInt32 indexInFolder = 0;
- MY_ALLOC(UInt32, db->FolderStartPackStreamIndex, db->Database.NumFolders, allocFunc);
- for(i = 0; i < db->Database.NumFolders; i++)
+ MY_ALLOC(UInt32, p->FolderStartPackStreamIndex, p->db.NumFolders, alloc);
+ for (i = 0; i < p->db.NumFolders; i++)
{
- db->FolderStartPackStreamIndex[i] = startPos;
- startPos += db->Database.Folders[i].NumPackStreams;
+ p->FolderStartPackStreamIndex[i] = startPos;
+ startPos += p->db.Folders[i].NumPackStreams;
}
- MY_ALLOC(CFileSize, db->PackStreamStartPositions, db->Database.NumPackStreams, allocFunc);
+ MY_ALLOC(CFileSize, p->PackStreamStartPositions, p->db.NumPackStreams, alloc);
- for(i = 0; i < db->Database.NumPackStreams; i++)
+ for (i = 0; i < p->db.NumPackStreams; i++)
{
- db->PackStreamStartPositions[i] = startPosSize;
- startPosSize += db->Database.PackSizes[i];
+ p->PackStreamStartPositions[i] = startPosSize;
+ startPosSize += p->db.PackSizes[i];
}
- MY_ALLOC(UInt32, db->FolderStartFileIndex, db->Database.NumFolders, allocFunc);
- MY_ALLOC(UInt32, db->FileIndexToFolderIndexMap, db->Database.NumFiles, allocFunc);
+ MY_ALLOC(UInt32, p->FolderStartFileIndex, p->db.NumFolders, alloc);
+ MY_ALLOC(UInt32, p->FileIndexToFolderIndexMap, p->db.NumFiles, alloc);
- for (i = 0; i < db->Database.NumFiles; i++)
+ for (i = 0; i < p->db.NumFiles; i++)
{
- CFileItem *file = db->Database.Files + i;
+ CSzFileItem *file = p->db.Files + i;
int emptyStream = !file->HasStream;
if (emptyStream && indexInFolder == 0)
{
- db->FileIndexToFolderIndexMap[i] = (UInt32)-1;
+ p->FileIndexToFolderIndexMap[i] = (UInt32)-1;
continue;
}
if (indexInFolder == 0)
@@ -89,19 +93,19 @@ SZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size))
*/
for (;;)
{
- if (folderIndex >= db->Database.NumFolders)
- return SZE_ARCHIVE_ERROR;
- db->FolderStartFileIndex[folderIndex] = i;
- if (db->Database.Folders[folderIndex].NumUnPackStreams != 0)
+ if (folderIndex >= p->db.NumFolders)
+ return SZ_ERROR_ARCHIVE;
+ p->FolderStartFileIndex[folderIndex] = i;
+ if (p->db.Folders[folderIndex].NumUnPackStreams != 0)
break;
folderIndex++;
}
}
- db->FileIndexToFolderIndexMap[i] = folderIndex;
+ p->FileIndexToFolderIndexMap[i] = folderIndex;
if (emptyStream)
continue;
indexInFolder++;
- if (indexInFolder >= db->Database.Folders[folderIndex].NumUnPackStreams)
+ if (indexInFolder >= p->db.Folders[folderIndex].NumUnPackStreams)
{
folderIndex++;
indexInFolder = 0;
@@ -111,23 +115,23 @@ SZ_RESULT SzArDbExFill(CArchiveDatabaseEx *db, void * (*allocFunc)(size_t size))
}
-CFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder)
+CFileSize SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder)
{
- return db->ArchiveInfo.DataStartPosition +
- db->PackStreamStartPositions[db->FolderStartPackStreamIndex[folderIndex] + indexInFolder];
+ return p->ArchiveInfo.DataStartPosition +
+ p->PackStreamStartPositions[p->FolderStartPackStreamIndex[folderIndex] + indexInFolder];
}
-int SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex, CFileSize *resSize)
+int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, CFileSize *resSize)
{
- UInt32 packStreamIndex = db->FolderStartPackStreamIndex[folderIndex];
- CFolder *folder = db->Database.Folders + folderIndex;
+ UInt32 packStreamIndex = p->FolderStartPackStreamIndex[folderIndex];
+ CSzFolder *folder = p->db.Folders + folderIndex;
CFileSize size = 0;
UInt32 i;
for (i = 0; i < folder->NumPackStreams; i++)
{
- CFileSize t = size + db->Database.PackSizes[packStreamIndex + i];
- if (t < size)
- return SZE_FAIL;
+ CFileSize t = size + p->db.PackSizes[packStreamIndex + i];
+ if (t < size) // check it
+ return SZ_ERROR_FAIL;
size = t;
}
*resSize = size;
@@ -136,8 +140,8 @@ int SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex, CFil
/*
-SZ_RESULT SzReadTime(const CObjectVector<CSzByteBuffer> &dataVector,
- CObjectVector<CFileItem> &files, UInt64 type)
+SRes SzReadTime(const CObjectVector<CBuf> &dataVector,
+ CObjectVector<CSzFileItem> &files, UInt64 type)
{
CBoolVector boolVector;
RINOK(ReadBoolVector2(files.Size(), boolVector))
@@ -145,9 +149,9 @@ SZ_RESULT SzReadTime(const CObjectVector<CSzByteBuffer> &dataVector,
CStreamSwitch streamSwitch;
RINOK(streamSwitch.Set(this, &dataVector));
- for(int i = 0; i < files.Size(); i++)
+ for (int i = 0; i < files.Size(); i++)
{
- CFileItem &file = files[i];
+ CSzFileItem &file = files[i];
CArchiveFileTime fileTime;
bool defined = boolVector[i];
if (defined)
@@ -181,40 +185,31 @@ SZ_RESULT SzReadTime(const CObjectVector<CSzByteBuffer> &dataVector,
}
*/
-SZ_RESULT SafeReadDirect(ISzInStream *inStream, Byte *data, size_t size)
+static SRes SafeReadDirect(ISzInStream *inStream, Byte *data, size_t size)
{
- #ifdef _LZMA_IN_CB
while (size > 0)
{
void *inBufferSpec;
- size_t processedSize;
+ size_t processedSize = size;
const Byte *inBuffer;
- RINOK(inStream->Read(inStream, (void **)&inBufferSpec, size, &processedSize));
+ RINOK(inStream->Read(inStream, (void **)&inBufferSpec, &processedSize));
inBuffer = (const Byte *)inBufferSpec;
- if (processedSize == 0 || processedSize > size)
- return SZE_FAIL;
+ if (processedSize == 0)
+ return SZ_ERROR_INPUT_EOF;
size -= processedSize;
do
- {
*data++ = *inBuffer++;
- }
while (--processedSize != 0);
}
- #else
- size_t processedSize;
- RINOK(inStream->Read(inStream, data, size, &processedSize));
- if (processedSize != size)
- return SZE_FAIL;
- #endif
return SZ_OK;
}
-SZ_RESULT SafeReadDirectByte(ISzInStream *inStream, Byte *data)
+static SRes SafeReadDirectByte(ISzInStream *inStream, Byte *data)
{
return SafeReadDirect(inStream, data, 1);
}
-SZ_RESULT SafeReadDirectUInt32(ISzInStream *inStream, UInt32 *value, UInt32 *crc)
+static SRes SafeReadDirectUInt32(ISzInStream *inStream, UInt32 *value, UInt32 *crc)
{
int i;
*value = 0;
@@ -228,7 +223,7 @@ SZ_RESULT SafeReadDirectUInt32(ISzInStream *inStream, UInt32 *value, UInt32 *crc
return SZ_OK;
}
-SZ_RESULT SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value, UInt32 *crc)
+static SRes SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value, UInt32 *crc)
{
int i;
*value = 0;
@@ -242,7 +237,7 @@ SZ_RESULT SafeReadDirectUInt64(ISzInStream *inStream, UInt64 *value, UInt32 *crc
return SZ_OK;
}
-int TestSignatureCandidate(Byte *testBytes)
+static int TestSignatureCandidate(Byte *testBytes)
{
size_t i;
for (i = 0; i < k7zSignatureSize; i++)
@@ -257,16 +252,16 @@ typedef struct _CSzState
size_t Size;
}CSzData;
-SZ_RESULT SzReadByte(CSzData *sd, Byte *b)
+static SRes SzReadByte(CSzData *sd, Byte *b)
{
if (sd->Size == 0)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_ARCHIVE;
sd->Size--;
*b = *sd->Data++;
return SZ_OK;
}
-SZ_RESULT SzReadBytes(CSzData *sd, Byte *data, size_t size)
+static SRes SzReadBytes(CSzData *sd, Byte *data, size_t size)
{
size_t i;
for (i = 0; i < size; i++)
@@ -276,7 +271,7 @@ SZ_RESULT SzReadBytes(CSzData *sd, Byte *data, size_t size)
return SZ_OK;
}
-SZ_RESULT SzReadUInt32(CSzData *sd, UInt32 *value)
+static SRes SzReadUInt32(CSzData *sd, UInt32 *value)
{
int i;
*value = 0;
@@ -289,7 +284,7 @@ SZ_RESULT SzReadUInt32(CSzData *sd, UInt32 *value)
return SZ_OK;
}
-SZ_RESULT SzReadNumber(CSzData *sd, UInt64 *value)
+static SRes SzReadNumber(CSzData *sd, UInt64 *value)
{
Byte firstByte;
Byte mask = 0x80;
@@ -312,7 +307,7 @@ SZ_RESULT SzReadNumber(CSzData *sd, UInt64 *value)
return SZ_OK;
}
-SZ_RESULT SzReadSize(CSzData *sd, CFileSize *value)
+static SRes SzReadSize(CSzData *sd, CFileSize *value)
{
UInt64 value64;
RINOK(SzReadNumber(sd, &value64));
@@ -320,40 +315,40 @@ SZ_RESULT SzReadSize(CSzData *sd, CFileSize *value)
return SZ_OK;
}
-SZ_RESULT SzReadNumber32(CSzData *sd, UInt32 *value)
+static SRes SzReadNumber32(CSzData *sd, UInt32 *value)
{
UInt64 value64;
RINOK(SzReadNumber(sd, &value64));
if (value64 >= 0x80000000)
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
if (value64 >= ((UInt64)(1) << ((sizeof(size_t) - 1) * 8 + 2)))
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
*value = (UInt32)value64;
return SZ_OK;
}
-SZ_RESULT SzReadID(CSzData *sd, UInt64 *value)
+static SRes SzReadID(CSzData *sd, UInt64 *value)
{
return SzReadNumber(sd, value);
}
-SZ_RESULT SzSkeepDataSize(CSzData *sd, UInt64 size)
+static SRes SzSkeepDataSize(CSzData *sd, UInt64 size)
{
if (size > sd->Size)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_ARCHIVE;
sd->Size -= (size_t)size;
sd->Data += (size_t)size;
return SZ_OK;
}
-SZ_RESULT SzSkeepData(CSzData *sd)
+static SRes SzSkeepData(CSzData *sd)
{
UInt64 size;
RINOK(SzReadNumber(sd, &size));
return SzSkeepDataSize(sd, size);
}
-SZ_RESULT SzReadArchiveProperties(CSzData *sd)
+static SRes SzReadArchiveProperties(CSzData *sd)
{
for (;;)
{
@@ -366,7 +361,7 @@ SZ_RESULT SzReadArchiveProperties(CSzData *sd)
return SZ_OK;
}
-SZ_RESULT SzWaitAttribute(CSzData *sd, UInt64 attribute)
+static SRes SzWaitAttribute(CSzData *sd, UInt64 attribute)
{
for (;;)
{
@@ -375,17 +370,17 @@ SZ_RESULT SzWaitAttribute(CSzData *sd, UInt64 attribute)
if (type == attribute)
return SZ_OK;
if (type == k7zIdEnd)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_ARCHIVE;
RINOK(SzSkeepData(sd));
}
}
-SZ_RESULT SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))
+static SRes SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, ISzAlloc *alloc)
{
Byte b = 0;
Byte mask = 0;
size_t i;
- MY_ALLOC(Byte, *v, numItems, allocFunc);
+ MY_ALLOC(Byte, *v, numItems, alloc);
for (i = 0; i < numItems; i++)
{
if (mask == 0)
@@ -399,30 +394,30 @@ SZ_RESULT SzReadBoolVector(CSzData *sd, size_t numItems, Byte **v, void * (*allo
return SZ_OK;
}
-SZ_RESULT SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, void * (*allocFunc)(size_t size))
+static SRes SzReadBoolVector2(CSzData *sd, size_t numItems, Byte **v, ISzAlloc *alloc)
{
Byte allAreDefined;
size_t i;
RINOK(SzReadByte(sd, &allAreDefined));
if (allAreDefined == 0)
- return SzReadBoolVector(sd, numItems, v, allocFunc);
- MY_ALLOC(Byte, *v, numItems, allocFunc);
- for(i = 0; i < numItems; i++)
+ return SzReadBoolVector(sd, numItems, v, alloc);
+ MY_ALLOC(Byte, *v, numItems, alloc);
+ for (i = 0; i < numItems; i++)
(*v)[i] = 1;
return SZ_OK;
}
-SZ_RESULT SzReadHashDigests(
+static SRes SzReadHashDigests(
CSzData *sd,
size_t numItems,
Byte **digestsDefined,
UInt32 **digests,
- void * (*allocFunc)(size_t size))
+ ISzAlloc *alloc)
{
size_t i;
- RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, allocFunc));
- MY_ALLOC(UInt32, *digests, numItems, allocFunc);
- for(i = 0; i < numItems; i++)
+ RINOK(SzReadBoolVector2(sd, numItems, digestsDefined, alloc));
+ MY_ALLOC(UInt32, *digests, numItems, alloc);
+ for (i = 0; i < numItems; i++)
if ((*digestsDefined)[i])
{
RINOK(SzReadUInt32(sd, (*digests) + i));
@@ -430,14 +425,14 @@ SZ_RESULT SzReadHashDigests(
return SZ_OK;
}
-SZ_RESULT SzReadPackInfo(
+static SRes SzReadPackInfo(
CSzData *sd,
CFileSize *dataOffset,
UInt32 *numPackStreams,
CFileSize **packSizes,
Byte **packCRCsDefined,
UInt32 **packCRCs,
- void * (*allocFunc)(size_t size))
+ ISzAlloc *alloc)
{
UInt32 i;
RINOK(SzReadSize(sd, dataOffset));
@@ -445,9 +440,9 @@ SZ_RESULT SzReadPackInfo(
RINOK(SzWaitAttribute(sd, k7zIdSize));
- MY_ALLOC(CFileSize, *packSizes, (size_t)*numPackStreams, allocFunc);
+ MY_ALLOC(CFileSize, *packSizes, (size_t)*numPackStreams, alloc);
- for(i = 0; i < *numPackStreams; i++)
+ for (i = 0; i < *numPackStreams; i++)
{
RINOK(SzReadSize(sd, (*packSizes) + i));
}
@@ -460,16 +455,16 @@ SZ_RESULT SzReadPackInfo(
break;
if (type == k7zIdCRC)
{
- RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, allocFunc));
+ RINOK(SzReadHashDigests(sd, (size_t)*numPackStreams, packCRCsDefined, packCRCs, alloc));
continue;
}
RINOK(SzSkeepData(sd));
}
if (*packCRCsDefined == 0)
{
- MY_ALLOC(Byte, *packCRCsDefined, (size_t)*numPackStreams, allocFunc);
- MY_ALLOC(UInt32, *packCRCs, (size_t)*numPackStreams, allocFunc);
- for(i = 0; i < *numPackStreams; i++)
+ MY_ALLOC(Byte, *packCRCsDefined, (size_t)*numPackStreams, alloc);
+ MY_ALLOC(UInt32, *packCRCs, (size_t)*numPackStreams, alloc);
+ for (i = 0; i < *numPackStreams; i++)
{
(*packCRCsDefined)[i] = 0;
(*packCRCs)[i] = 0;
@@ -478,14 +473,14 @@ SZ_RESULT SzReadPackInfo(
return SZ_OK;
}
-SZ_RESULT SzReadSwitch(CSzData *sd)
+static SRes SzReadSwitch(CSzData *sd)
{
Byte external;
RINOK(SzReadByte(sd, &external));
- return (external == 0) ? SZ_OK: SZE_ARCHIVE_ERROR;
+ return (external == 0) ? SZ_OK: SZ_ERROR_UNSUPPORTED;
}
-SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(size_t size))
+static SRes SzGetNextFolderItem(CSzData *sd, CSzFolder *folder, ISzAlloc *alloc)
{
UInt32 numCoders;
UInt32 numBindPairs;
@@ -496,15 +491,15 @@ SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(
RINOK(SzReadNumber32(sd, &numCoders));
folder->NumCoders = numCoders;
- MY_ALLOC(CCoderInfo, folder->Coders, (size_t)numCoders, allocFunc);
+ MY_ALLOC(CSzCoderInfo, folder->Coders, (size_t)numCoders, alloc);
for (i = 0; i < numCoders; i++)
- SzCoderInfoInit(folder->Coders + i);
+ SzCoderInfo_Init(folder->Coders + i);
for (i = 0; i < numCoders; i++)
{
Byte mainByte;
- CCoderInfo *coder = folder->Coders + i;
+ CSzCoderInfo *coder = folder->Coders + i;
{
unsigned idSize, j;
Byte longID[15];
@@ -512,7 +507,7 @@ SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(
idSize = (unsigned)(mainByte & 0xF);
RINOK(SzReadBytes(sd, longID, idSize));
if (idSize > sizeof(coder->MethodID))
- return SZE_NOTIMPL;
+ return SZ_ERROR_UNSUPPORTED;
coder->MethodID = 0;
for (j = 0; j < idSize; j++)
coder->MethodID |= (CMethodID)longID[idSize - 1 - j] << (8 * j);
@@ -531,9 +526,9 @@ SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(
{
UInt64 propertiesSize = 0;
RINOK(SzReadNumber(sd, &propertiesSize));
- if (!SzByteBufferCreate(&coder->Properties, (size_t)propertiesSize, allocFunc))
- return SZE_OUTOFMEMORY;
- RINOK(SzReadBytes(sd, coder->Properties.Items, (size_t)propertiesSize));
+ if (!Buf_Create(&coder->Props, (size_t)propertiesSize, alloc))
+ return SZ_ERROR_MEM;
+ RINOK(SzReadBytes(sd, coder->Props.data, (size_t)propertiesSize));
}
}
while ((mainByte & 0x80) != 0)
@@ -561,7 +556,7 @@ SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(
folder->NumBindPairs = numBindPairs;
- MY_ALLOC(CBindPair, folder->BindPairs, (size_t)numBindPairs, allocFunc);
+ MY_ALLOC(CBindPair, folder->BindPairs, (size_t)numBindPairs, alloc);
for (i = 0; i < numBindPairs; i++)
{
@@ -573,32 +568,32 @@ SZ_RESULT SzGetNextFolderItem(CSzData *sd, CFolder *folder, void * (*allocFunc)(
numPackedStreams = numInStreams - (UInt32)numBindPairs;
folder->NumPackStreams = numPackedStreams;
- MY_ALLOC(UInt32, folder->PackStreams, (size_t)numPackedStreams, allocFunc);
+ MY_ALLOC(UInt32, folder->PackStreams, (size_t)numPackedStreams, alloc);
if (numPackedStreams == 1)
{
UInt32 j;
UInt32 pi = 0;
for (j = 0; j < numInStreams; j++)
- if (SzFolderFindBindPairForInStream(folder, j) < 0)
+ if (SzFolder_FindBindPairForInStream(folder, j) < 0)
{
folder->PackStreams[pi++] = j;
break;
}
}
else
- for(i = 0; i < numPackedStreams; i++)
+ for (i = 0; i < numPackedStreams; i++)
{
RINOK(SzReadNumber32(sd, folder->PackStreams + i));
}
return SZ_OK;
}
-SZ_RESULT SzReadUnPackInfo(
+static SRes SzReadUnPackInfo(
CSzData *sd,
UInt32 *numFolders,
- CFolder **folders, /* for allocFunc */
- void * (*allocFunc)(size_t size),
+ CSzFolder **folders, /* for alloc */
+ ISzAlloc *alloc,
ISzAlloc *allocTemp)
{
UInt32 i;
@@ -607,28 +602,28 @@ SZ_RESULT SzReadUnPackInfo(
{
RINOK(SzReadSwitch(sd));
- MY_ALLOC(CFolder, *folders, (size_t)*numFolders, allocFunc);
+ MY_ALLOC(CSzFolder, *folders, (size_t)*numFolders, alloc);
- for(i = 0; i < *numFolders; i++)
- SzFolderInit((*folders) + i);
+ for (i = 0; i < *numFolders; i++)
+ SzFolder_Init((*folders) + i);
- for(i = 0; i < *numFolders; i++)
+ for (i = 0; i < *numFolders; i++)
{
- RINOK(SzGetNextFolderItem(sd, (*folders) + i, allocFunc));
+ RINOK(SzGetNextFolderItem(sd, (*folders) + i, alloc));
}
}
RINOK(SzWaitAttribute(sd, k7zIdCodersUnPackSize));
- for(i = 0; i < *numFolders; i++)
+ for (i = 0; i < *numFolders; i++)
{
UInt32 j;
- CFolder *folder = (*folders) + i;
- UInt32 numOutStreams = SzFolderGetNumOutStreams(folder);
+ CSzFolder *folder = (*folders) + i;
+ UInt32 numOutStreams = SzFolder_GetNumOutStreams(folder);
- MY_ALLOC(CFileSize, folder->UnPackSizes, (size_t)numOutStreams, allocFunc);
+ MY_ALLOC(CFileSize, folder->UnPackSizes, (size_t)numOutStreams, alloc);
- for(j = 0; j < numOutStreams; j++)
+ for (j = 0; j < numOutStreams; j++)
{
RINOK(SzReadSize(sd, folder->UnPackSizes + j));
}
@@ -642,21 +637,21 @@ SZ_RESULT SzReadUnPackInfo(
return SZ_OK;
if (type == k7zIdCRC)
{
- SZ_RESULT res;
+ SRes res;
Byte *crcsDefined = 0;
UInt32 *crcs = 0;
- res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp->Alloc);
+ res = SzReadHashDigests(sd, *numFolders, &crcsDefined, &crcs, allocTemp);
if (res == SZ_OK)
{
- for(i = 0; i < *numFolders; i++)
+ for (i = 0; i < *numFolders; i++)
{
- CFolder *folder = (*folders) + i;
+ CSzFolder *folder = (*folders) + i;
folder->UnPackCRCDefined = crcsDefined[i];
folder->UnPackCRC = crcs[i];
}
}
- allocTemp->Free(crcs);
- allocTemp->Free(crcsDefined);
+ IAlloc_Free(allocTemp, crcs);
+ IAlloc_Free(allocTemp, crcsDefined);
RINOK(res);
continue;
}
@@ -664,10 +659,10 @@ SZ_RESULT SzReadUnPackInfo(
}
}
-SZ_RESULT SzReadSubStreamsInfo(
+static SRes SzReadSubStreamsInfo(
CSzData *sd,
UInt32 numFolders,
- CFolder *folders,
+ CSzFolder *folders,
UInt32 *numUnPackStreams,
CFileSize **unPackSizes,
Byte **digestsDefined,
@@ -679,7 +674,7 @@ SZ_RESULT SzReadSubStreamsInfo(
UInt32 si = 0;
UInt32 numDigests = 0;
- for(i = 0; i < numFolders; i++)
+ for (i = 0; i < numFolders; i++)
folders[i].NumUnPackStreams = 1;
*numUnPackStreams = numFolders;
@@ -689,7 +684,7 @@ SZ_RESULT SzReadSubStreamsInfo(
if (type == k7zIdNumUnPackStream)
{
*numUnPackStreams = 0;
- for(i = 0; i < numFolders; i++)
+ for (i = 0; i < numFolders; i++)
{
UInt32 numStreams;
RINOK(SzReadNumber32(sd, &numStreams));
@@ -713,15 +708,15 @@ SZ_RESULT SzReadSubStreamsInfo(
}
else
{
- *unPackSizes = (CFileSize *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(CFileSize));
+ *unPackSizes = (CFileSize *)IAlloc_Alloc(allocTemp, (size_t)*numUnPackStreams * sizeof(CFileSize));
RINOM(*unPackSizes);
- *digestsDefined = (Byte *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(Byte));
+ *digestsDefined = (Byte *)IAlloc_Alloc(allocTemp, (size_t)*numUnPackStreams * sizeof(Byte));
RINOM(*digestsDefined);
- *digests = (UInt32 *)allocTemp->Alloc((size_t)*numUnPackStreams * sizeof(UInt32));
+ *digests = (UInt32 *)IAlloc_Alloc(allocTemp, (size_t)*numUnPackStreams * sizeof(UInt32));
RINOM(*digests);
}
- for(i = 0; i < numFolders; i++)
+ for (i = 0; i < numFolders; i++)
{
/*
v3.13 incorrectly worked with empty folders
@@ -740,21 +735,21 @@ SZ_RESULT SzReadSubStreamsInfo(
(*unPackSizes)[si++] = size;
sum += size;
}
- (*unPackSizes)[si++] = SzFolderGetUnPackSize(folders + i) - sum;
+ (*unPackSizes)[si++] = SzFolder_GetUnPackSize(folders + i) - sum;
}
if (type == k7zIdSize)
{
RINOK(SzReadID(sd, &type));
}
- for(i = 0; i < *numUnPackStreams; i++)
+ for (i = 0; i < *numUnPackStreams; i++)
{
(*digestsDefined)[i] = 0;
(*digests)[i] = 0;
}
- for(i = 0; i < numFolders; i++)
+ for (i = 0; i < numFolders; i++)
{
UInt32 numSubstreams = folders[i].NumUnPackStreams;
if (numSubstreams != 1 || !folders[i].UnPackCRCDefined)
@@ -770,12 +765,12 @@ SZ_RESULT SzReadSubStreamsInfo(
int digestIndex = 0;
Byte *digestsDefined2 = 0;
UInt32 *digests2 = 0;
- SZ_RESULT res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp->Alloc);
+ SRes res = SzReadHashDigests(sd, numDigests, &digestsDefined2, &digests2, allocTemp);
if (res == SZ_OK)
{
for (i = 0; i < numFolders; i++)
{
- CFolder *folder = folders + i;
+ CSzFolder *folder = folders + i;
UInt32 numSubstreams = folder->NumUnPackStreams;
if (numSubstreams == 1 && folder->UnPackCRCDefined)
{
@@ -795,8 +790,8 @@ SZ_RESULT SzReadSubStreamsInfo(
}
}
}
- allocTemp->Free(digestsDefined2);
- allocTemp->Free(digests2);
+ IAlloc_Free(allocTemp, digestsDefined2);
+ IAlloc_Free(allocTemp, digests2);
RINOK(res);
}
else if (type == k7zIdEnd)
@@ -810,15 +805,15 @@ SZ_RESULT SzReadSubStreamsInfo(
}
-SZ_RESULT SzReadStreamsInfo(
+static SRes SzReadStreamsInfo(
CSzData *sd,
CFileSize *dataOffset,
- CArchiveDatabase *db,
+ CSzAr *p,
UInt32 *numUnPackStreams,
CFileSize **unPackSizes, /* allocTemp */
Byte **digestsDefined, /* allocTemp */
UInt32 **digests, /* allocTemp */
- void * (*allocFunc)(size_t size),
+ ISzAlloc *alloc,
ISzAlloc *allocTemp)
{
for (;;)
@@ -826,45 +821,44 @@ SZ_RESULT SzReadStreamsInfo(
UInt64 type;
RINOK(SzReadID(sd, &type));
if ((UInt64)(int)type != type)
- return SZE_FAIL;
+ return SZ_ERROR_UNSUPPORTED;
switch((int)type)
{
case k7zIdEnd:
return SZ_OK;
case k7zIdPackInfo:
{
- RINOK(SzReadPackInfo(sd, dataOffset, &db->NumPackStreams,
- &db->PackSizes, &db->PackCRCsDefined, &db->PackCRCs, allocFunc));
+ RINOK(SzReadPackInfo(sd, dataOffset, &p->NumPackStreams,
+ &p->PackSizes, &p->PackCRCsDefined, &p->PackCRCs, alloc));
break;
}
case k7zIdUnPackInfo:
{
- RINOK(SzReadUnPackInfo(sd, &db->NumFolders, &db->Folders, allocFunc, allocTemp));
+ RINOK(SzReadUnPackInfo(sd, &p->NumFolders, &p->Folders, alloc, allocTemp));
break;
}
case k7zIdSubStreamsInfo:
{
- RINOK(SzReadSubStreamsInfo(sd, db->NumFolders, db->Folders,
+ RINOK(SzReadSubStreamsInfo(sd, p->NumFolders, p->Folders,
numUnPackStreams, unPackSizes, digestsDefined, digests, allocTemp));
break;
}
default:
- return SZE_FAIL;
+ return SZ_ERROR_UNSUPPORTED;
}
}
}
Byte kUtf8Limits[5] = { 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
-SZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files,
- void * (*allocFunc)(size_t size))
+static SRes SzReadFileNames(CSzData *sd, UInt32 numFiles, CSzFileItem *files, ISzAlloc *alloc)
{
UInt32 i;
- for(i = 0; i < numFiles; i++)
+ for (i = 0; i < numFiles; i++)
{
UInt32 len = 0;
UInt32 pos = 0;
- CFileItem *file = files + i;
+ CSzFileItem *file = files + i;
while(pos + 2 <= sd->Size)
{
int numAdds;
@@ -879,13 +873,13 @@ SZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files,
{
UInt32 c2;
if (value >= 0xDC00)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_ARCHIVE;
if (pos + 2 > sd->Size)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_ARCHIVE;
c2 = (UInt32)(sd->Data[pos] | (((UInt32)sd->Data[pos + 1]) << 8));
pos += 2;
if (c2 < 0xDC00 || c2 >= 0xE000)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_ARCHIVE;
value = ((value - 0xD800) << 10) | (c2 - 0xDC00);
}
for (numAdds = 1; numAdds < 5; numAdds++)
@@ -894,7 +888,7 @@ SZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files,
len += numAdds;
}
- MY_ALLOC(char, file->Name, (size_t)len, allocFunc);
+ MY_ALLOC(char, file->Name, (size_t)len, alloc);
len = 0;
while(2 <= sd->Size)
@@ -932,9 +926,9 @@ SZ_RESULT SzReadFileNames(CSzData *sd, UInt32 numFiles, CFileItem *files,
return SZ_OK;
}
-SZ_RESULT SzReadHeader2(
+static SRes SzReadHeader2(
+ CSzArEx *p, /* allocMain */
CSzData *sd,
- CArchiveDatabaseEx *db, /* allocMain */
CFileSize **unPackSizes, /* allocTemp */
Byte **digestsDefined, /* allocTemp */
UInt32 **digests, /* allocTemp */
@@ -947,7 +941,7 @@ SZ_RESULT SzReadHeader2(
UInt64 type;
UInt32 numUnPackStreams = 0;
UInt32 numFiles = 0;
- CFileItem *files = 0;
+ CSzFileItem *files = 0;
UInt32 numEmptyStreams = 0;
UInt32 i;
@@ -963,29 +957,29 @@ SZ_RESULT SzReadHeader2(
if (type == k7zIdMainStreamsInfo)
{
RINOK(SzReadStreamsInfo(sd,
- &db->ArchiveInfo.DataStartPosition,
- &db->Database,
+ &p->ArchiveInfo.DataStartPosition,
+ &p->db,
&numUnPackStreams,
unPackSizes,
digestsDefined,
- digests, allocMain->Alloc, allocTemp));
- db->ArchiveInfo.DataStartPosition += db->ArchiveInfo.StartPositionAfterHeader;
+ digests, allocMain, allocTemp));
+ p->ArchiveInfo.DataStartPosition += p->ArchiveInfo.StartPositionAfterHeader;
RINOK(SzReadID(sd, &type));
}
if (type == k7zIdEnd)
return SZ_OK;
if (type != k7zIdFilesInfo)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_ARCHIVE;
RINOK(SzReadNumber32(sd, &numFiles));
- db->Database.NumFiles = numFiles;
+ p->db.NumFiles = numFiles;
- MY_ALLOC(CFileItem, files, (size_t)numFiles, allocMain->Alloc);
+ MY_ALLOC(CSzFileItem, files, (size_t)numFiles, allocMain);
- db->Database.Files = files;
- for(i = 0; i < numFiles; i++)
- SzFileInit(files + i);
+ p->db.Files = files;
+ for (i = 0; i < numFiles; i++)
+ SzFile_Init(files + i);
for (;;)
{
@@ -1006,12 +1000,12 @@ SZ_RESULT SzReadHeader2(
case k7zIdName:
{
RINOK(SzReadSwitch(sd));
- RINOK(SzReadFileNames(sd, numFiles, files, allocMain->Alloc))
+ RINOK(SzReadFileNames(sd, numFiles, files, allocMain))
break;
}
case k7zIdEmptyStream:
{
- RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp->Alloc));
+ RINOK(SzReadBoolVector(sd, numFiles, emptyStreamVector, allocTemp));
numEmptyStreams = 0;
for (i = 0; i < numFiles; i++)
if ((*emptyStreamVector)[i])
@@ -1020,16 +1014,16 @@ SZ_RESULT SzReadHeader2(
}
case k7zIdEmptyFile:
{
- RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp->Alloc));
+ RINOK(SzReadBoolVector(sd, numEmptyStreams, emptyFileVector, allocTemp));
break;
}
case k7zIdLastWriteTime:
{
- RINOK(SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp->Alloc));
+ RINOK(SzReadBoolVector2(sd, numFiles, lwtVector, allocTemp));
RINOK(SzReadSwitch(sd));
for (i = 0; i < numFiles; i++)
{
- CFileItem *f = &files[i];
+ CSzFileItem *f = &files[i];
Byte defined = (*lwtVector)[i];
f->IsLastWriteTimeDefined = defined;
f->LastWriteTime.Low = f->LastWriteTime.High = 0;
@@ -1051,9 +1045,9 @@ SZ_RESULT SzReadHeader2(
{
UInt32 emptyFileIndex = 0;
UInt32 sizeIndex = 0;
- for(i = 0; i < numFiles; i++)
+ for (i = 0; i < numFiles; i++)
{
- CFileItem *file = files + i;
+ CSzFileItem *file = files + i;
file->IsAnti = 0;
if (*emptyStreamVector == 0)
file->HasStream = 1;
@@ -1079,12 +1073,12 @@ SZ_RESULT SzReadHeader2(
}
}
}
- return SzArDbExFill(db, allocMain->Alloc);
+ return SzArEx_Fill(p, allocMain);
}
-SZ_RESULT SzReadHeader(
+static SRes SzReadHeader(
+ CSzArEx *p,
CSzData *sd,
- CArchiveDatabaseEx *db,
ISzAlloc *allocMain,
ISzAlloc *allocTemp)
{
@@ -1094,118 +1088,89 @@ SZ_RESULT SzReadHeader(
Byte *emptyStreamVector = 0;
Byte *emptyFileVector = 0;
Byte *lwtVector = 0;
- SZ_RESULT res = SzReadHeader2(sd, db,
+ SRes res = SzReadHeader2(p, sd,
&unPackSizes, &digestsDefined, &digests,
&emptyStreamVector, &emptyFileVector, &lwtVector,
allocMain, allocTemp);
- allocTemp->Free(unPackSizes);
- allocTemp->Free(digestsDefined);
- allocTemp->Free(digests);
- allocTemp->Free(emptyStreamVector);
- allocTemp->Free(emptyFileVector);
- allocTemp->Free(lwtVector);
+ IAlloc_Free(allocTemp, unPackSizes);
+ IAlloc_Free(allocTemp, digestsDefined);
+ IAlloc_Free(allocTemp, digests);
+ IAlloc_Free(allocTemp, emptyStreamVector);
+ IAlloc_Free(allocTemp, emptyFileVector);
+ IAlloc_Free(allocTemp, lwtVector);
return res;
}
-SZ_RESULT SzReadAndDecodePackedStreams2(
+static SRes SzReadAndDecodePackedStreams2(
ISzInStream *inStream,
CSzData *sd,
- CSzByteBuffer *outBuffer,
+ CBuf *outBuffer,
CFileSize baseOffset,
- CArchiveDatabase *db,
+ CSzAr *p,
CFileSize **unPackSizes,
Byte **digestsDefined,
UInt32 **digests,
- #ifndef _LZMA_IN_CB
- Byte **inBuffer,
- #endif
ISzAlloc *allocTemp)
{
UInt32 numUnPackStreams = 0;
CFileSize dataStartPos;
- CFolder *folder;
- #ifndef _LZMA_IN_CB
- CFileSize packSize = 0;
- UInt32 i = 0;
- #endif
+ CSzFolder *folder;
CFileSize unPackSize;
- SZ_RESULT res;
+ SRes res;
- RINOK(SzReadStreamsInfo(sd, &dataStartPos, db,
+ RINOK(SzReadStreamsInfo(sd, &dataStartPos, p,
&numUnPackStreams, unPackSizes, digestsDefined, digests,
- allocTemp->Alloc, allocTemp));
+ allocTemp, allocTemp));
dataStartPos += baseOffset;
- if (db->NumFolders != 1)
- return SZE_ARCHIVE_ERROR;
+ if (p->NumFolders != 1)
+ return SZ_ERROR_ARCHIVE;
- folder = db->Folders;
- unPackSize = SzFolderGetUnPackSize(folder);
+ folder = p->Folders;
+ unPackSize = SzFolder_GetUnPackSize(folder);
- RINOK(inStream->Seek(inStream, dataStartPos));
-
- #ifndef _LZMA_IN_CB
- for (i = 0; i < db->NumPackStreams; i++)
- packSize += db->PackSizes[i];
+ RINOK(inStream->Seek(inStream, dataStartPos, SZ_SEEK_SET));
- MY_ALLOC(Byte, *inBuffer, (size_t)packSize, allocTemp->Alloc);
-
- RINOK(SafeReadDirect(inStream, *inBuffer, (size_t)packSize));
- #endif
-
- if (!SzByteBufferCreate(outBuffer, (size_t)unPackSize, allocTemp->Alloc))
- return SZE_OUTOFMEMORY;
+ if (!Buf_Create(outBuffer, (size_t)unPackSize, allocTemp))
+ return SZ_ERROR_MEM;
- res = SzDecode(db->PackSizes, folder,
- #ifdef _LZMA_IN_CB
+ res = SzDecode(p->PackSizes, folder,
inStream, dataStartPos,
- #else
- *inBuffer,
- #endif
- outBuffer->Items, (size_t)unPackSize, allocTemp);
- RINOK(res)
+ outBuffer->data, (size_t)unPackSize, allocTemp);
+ RINOK(res);
if (folder->UnPackCRCDefined)
- if (CrcCalc(outBuffer->Items, (size_t)unPackSize) != folder->UnPackCRC)
- return SZE_FAIL;
+ if (CrcCalc(outBuffer->data, (size_t)unPackSize) != folder->UnPackCRC)
+ return SZ_ERROR_CRC;
return SZ_OK;
}
-SZ_RESULT SzReadAndDecodePackedStreams(
+static SRes SzReadAndDecodePackedStreams(
ISzInStream *inStream,
CSzData *sd,
- CSzByteBuffer *outBuffer,
+ CBuf *outBuffer,
CFileSize baseOffset,
ISzAlloc *allocTemp)
{
- CArchiveDatabase db;
+ CSzAr p;
CFileSize *unPackSizes = 0;
Byte *digestsDefined = 0;
UInt32 *digests = 0;
- #ifndef _LZMA_IN_CB
- Byte *inBuffer = 0;
- #endif
- SZ_RESULT res;
- SzArchiveDatabaseInit(&db);
+ SRes res;
+ SzAr_Init(&p);
res = SzReadAndDecodePackedStreams2(inStream, sd, outBuffer, baseOffset,
- &db, &unPackSizes, &digestsDefined, &digests,
- #ifndef _LZMA_IN_CB
- &inBuffer,
- #endif
+ &p, &unPackSizes, &digestsDefined, &digests,
allocTemp);
- SzArchiveDatabaseFree(&db, allocTemp->Free);
- allocTemp->Free(unPackSizes);
- allocTemp->Free(digestsDefined);
- allocTemp->Free(digests);
- #ifndef _LZMA_IN_CB
- allocTemp->Free(inBuffer);
- #endif
+ SzAr_Free(&p, allocTemp);
+ IAlloc_Free(allocTemp, unPackSizes);
+ IAlloc_Free(allocTemp, digestsDefined);
+ IAlloc_Free(allocTemp, digests);
return res;
}
-SZ_RESULT SzArchiveOpen2(
+static SRes SzArEx_Open2(
+ CSzArEx *p,
ISzInStream *inStream,
- CArchiveDatabaseEx *db,
ISzAlloc *allocMain,
ISzAlloc *allocTemp)
{
@@ -1217,22 +1182,23 @@ SZ_RESULT SzArchiveOpen2(
UInt32 nextHeaderCRC;
UInt32 crc = 0;
CFileSize pos = 0;
- CSzByteBuffer buffer;
+ CBuf buffer;
CSzData sd;
- SZ_RESULT res;
+ SRes res;
- RINOK(SafeReadDirect(inStream, signature, k7zSignatureSize));
+ if (SafeReadDirect(inStream, signature, k7zSignatureSize) != SZ_OK)
+ return SZ_ERROR_NO_ARCHIVE;
if (!TestSignatureCandidate(signature))
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_NO_ARCHIVE;
/*
- db.Clear();
- db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;
+ p.Clear();
+ p.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;
*/
RINOK(SafeReadDirectByte(inStream, &version));
if (version != k7zMajorVersion)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_UNSUPPORTED;
RINOK(SafeReadDirectByte(inStream, &version));
RINOK(SafeReadDirectUInt32(inStream, &crcFromArchive, &crc));
@@ -1243,72 +1209,69 @@ SZ_RESULT SzArchiveOpen2(
RINOK(SafeReadDirectUInt32(inStream, &nextHeaderCRC, &crc));
pos = k7zStartHeaderSize;
- db->ArchiveInfo.StartPositionAfterHeader = pos;
+ p->ArchiveInfo.StartPositionAfterHeader = pos;
if (CRC_GET_DIGEST(crc) != crcFromArchive)
- return SZE_ARCHIVE_ERROR;
+ return SZ_ERROR_CRC;
if (nextHeaderSize == 0)
return SZ_OK;
- RINOK(inStream->Seek(inStream, (CFileSize)(pos + nextHeaderOffset)));
+ RINOK(inStream->Seek(inStream, (CFileSize)(pos + nextHeaderOffset), SZ_SEEK_SET));
- if (!SzByteBufferCreate(&buffer, (size_t)nextHeaderSize, allocTemp->Alloc))
- return SZE_OUTOFMEMORY;
+ if (!Buf_Create(&buffer, (size_t)nextHeaderSize, allocTemp))
+ return SZ_ERROR_MEM;
- res = SafeReadDirect(inStream, buffer.Items, (size_t)nextHeaderSize);
+ res = SafeReadDirect(inStream, buffer.data, (size_t)nextHeaderSize);
if (res == SZ_OK)
{
- res = SZE_ARCHIVE_ERROR;
- if (CrcCalc(buffer.Items, (UInt32)nextHeaderSize) == nextHeaderCRC)
+ res = SZ_ERROR_ARCHIVE;
+ if (CrcCalc(buffer.data, (size_t)nextHeaderSize) == nextHeaderCRC)
{
for (;;)
{
UInt64 type;
- sd.Data = buffer.Items;
- sd.Size = buffer.Capacity;
+ sd.Data = buffer.data;
+ sd.Size = buffer.size;
res = SzReadID(&sd, &type);
if (res != SZ_OK)
break;
if (type == k7zIdHeader)
{
- res = SzReadHeader(&sd, db, allocMain, allocTemp);
+ res = SzReadHeader(p, &sd, allocMain, allocTemp);
break;
}
if (type != k7zIdEncodedHeader)
{
- res = SZE_ARCHIVE_ERROR;
+ res = SZ_ERROR_UNSUPPORTED;
break;
}
{
- CSzByteBuffer outBuffer;
+ CBuf outBuffer;
+ Buf_Init(&outBuffer);
res = SzReadAndDecodePackedStreams(inStream, &sd, &outBuffer,
- db->ArchiveInfo.StartPositionAfterHeader,
+ p->ArchiveInfo.StartPositionAfterHeader,
allocTemp);
if (res != SZ_OK)
{
- SzByteBufferFree(&outBuffer, allocTemp->Free);
+ Buf_Free(&outBuffer, allocTemp);
break;
}
- SzByteBufferFree(&buffer, allocTemp->Free);
- buffer.Items = outBuffer.Items;
- buffer.Capacity = outBuffer.Capacity;
+ Buf_Free(&buffer, allocTemp);
+ buffer.data = outBuffer.data;
+ buffer.size = outBuffer.size;
}
}
}
}
- SzByteBufferFree(&buffer, allocTemp->Free);
+ Buf_Free(&buffer, allocTemp);
return res;
}
-SZ_RESULT SzArchiveOpen(
- ISzInStream *inStream,
- CArchiveDatabaseEx *db,
- ISzAlloc *allocMain,
- ISzAlloc *allocTemp)
+SRes SzArEx_Open(CSzArEx *p, ISzInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp)
{
- SZ_RESULT res = SzArchiveOpen2(inStream, db, allocMain, allocTemp);
+ SRes res = SzArEx_Open2(p, inStream, allocMain, allocTemp);
if (res != SZ_OK)
- SzArDbExFree(db, allocMain->Free);
+ SzArEx_Free(p, allocMain);
return res;
}
diff --git a/C/Archive/7z/7zIn.h b/C/Archive/7z/7zIn.h
index 0b4ca08d..811bbb66 100755
--- a/C/Archive/7z/7zIn.h
+++ b/C/Archive/7z/7zIn.h
@@ -1,55 +1,63 @@
-/* 7zIn.h */
+/* 7zIn.h -- 7z Input functions
+2008-05-05
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read 7zItem.h for license options */
#ifndef __7Z_IN_H
#define __7Z_IN_H
#include "7zHeader.h"
#include "7zItem.h"
-#include "7zAlloc.h"
-
-typedef struct _CInArchiveInfo
+
+typedef struct
{
CFileSize StartPositionAfterHeader;
CFileSize DataStartPosition;
-}CInArchiveInfo;
+} CInArchiveInfo;
-typedef struct _CArchiveDatabaseEx
+typedef struct
{
- CArchiveDatabase Database;
+ CSzAr db;
CInArchiveInfo ArchiveInfo;
UInt32 *FolderStartPackStreamIndex;
CFileSize *PackStreamStartPositions;
UInt32 *FolderStartFileIndex;
UInt32 *FileIndexToFolderIndexMap;
-}CArchiveDatabaseEx;
+} CSzArEx;
-void SzArDbExInit(CArchiveDatabaseEx *db);
-void SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *));
-CFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder);
-int SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex, CFileSize *resSize);
+void SzArEx_Init(CSzArEx *p);
+void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);
+CFileSize SzArEx_GetFolderStreamPos(const CSzArEx *p, UInt32 folderIndex, UInt32 indexInFolder);
+int SzArEx_GetFolderFullPackSize(const CSzArEx *p, UInt32 folderIndex, CFileSize *resSize);
-typedef struct _ISzInStream
+typedef enum
{
- #ifdef _LZMA_IN_CB
- SZ_RESULT (*Read)(
- void *object, /* pointer to ISzInStream itself */
- void **buffer, /* out: pointer to buffer with data */
- size_t maxRequiredSize, /* max required size to read */
- size_t *processedSize); /* real processed size.
- processedSize can be less than maxRequiredSize.
- If processedSize == 0, then there are no more
- bytes in stream. */
- #else
- SZ_RESULT (*Read)(void *object, void *buffer, size_t size, size_t *processedSize);
- #endif
- SZ_RESULT (*Seek)(void *object, CFileSize pos);
+ SZ_SEEK_SET = 0,
+ SZ_SEEK_CUR = 1,
+ SZ_SEEK_END = 2
+} ESzSeek;
+
+typedef struct
+{
+ SRes (*Read)(void *object, void **buf, size_t *size);
+ /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
+ (output(*size) < input(*size)) is allowed */
+ SRes (*Seek)(void *object, CFileSize pos, ESzSeek origin);
} ISzInStream;
-int SzArchiveOpen(
- ISzInStream *inStream,
- CArchiveDatabaseEx *db,
- ISzAlloc *allocMain,
- ISzAlloc *allocTemp);
+/*
+Errors:
+SZ_ERROR_NO_ARCHIVE
+SZ_ERROR_ARCHIVE
+SZ_ERROR_UNSUPPORTED
+SZ_ERROR_MEM
+SZ_ERROR_CRC
+SZ_ERROR_INPUT_EOF
+SZ_ERROR_FAIL
+*/
+
+SRes SzArEx_Open(CSzArEx *p, ISzInStream *inStream, ISzAlloc *allocMain, ISzAlloc *allocTemp);
#endif
diff --git a/C/Archive/7z/7zItem.c b/C/Archive/7z/7zItem.c
index a88afe9a..7a5ad427 100755
--- a/C/Archive/7z/7zItem.c
+++ b/C/Archive/7z/7zItem.c
@@ -1,134 +1,130 @@
-/* 7zItem.c */
+/* 7zItem.c -- 7z Items
+2008-04-09
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read 7zItem.h for license options */
#include "7zItem.h"
-#include "7zAlloc.h"
-void SzCoderInfoInit(CCoderInfo *coder)
+void SzCoderInfo_Init(CSzCoderInfo *p)
{
- SzByteBufferInit(&coder->Properties);
+ Buf_Init(&p->Props);
}
-void SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p))
+void SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc)
{
- SzByteBufferFree(&coder->Properties, freeFunc);
- SzCoderInfoInit(coder);
+ Buf_Free(&p->Props, alloc);
+ SzCoderInfo_Init(p);
}
-void SzFolderInit(CFolder *folder)
+void SzFolder_Init(CSzFolder *p)
{
- folder->NumCoders = 0;
- folder->Coders = 0;
- folder->NumBindPairs = 0;
- folder->BindPairs = 0;
- folder->NumPackStreams = 0;
- folder->PackStreams = 0;
- folder->UnPackSizes = 0;
- folder->UnPackCRCDefined = 0;
- folder->UnPackCRC = 0;
- folder->NumUnPackStreams = 0;
+ p->Coders = 0;
+ p->BindPairs = 0;
+ p->PackStreams = 0;
+ p->UnPackSizes = 0;
+ p->NumCoders = 0;
+ p->NumBindPairs = 0;
+ p->NumPackStreams = 0;
+ p->UnPackCRCDefined = 0;
+ p->UnPackCRC = 0;
+ p->NumUnPackStreams = 0;
}
-void SzFolderFree(CFolder *folder, void (*freeFunc)(void *p))
+void SzFolder_Free(CSzFolder *p, ISzAlloc *alloc)
{
UInt32 i;
- for (i = 0; i < folder->NumCoders; i++)
- SzCoderInfoFree(&folder->Coders[i], freeFunc);
- freeFunc(folder->Coders);
- freeFunc(folder->BindPairs);
- freeFunc(folder->PackStreams);
- freeFunc(folder->UnPackSizes);
- SzFolderInit(folder);
+ if (p->Coders)
+ for (i = 0; i < p->NumCoders; i++)
+ SzCoderInfo_Free(&p->Coders[i], alloc);
+ IAlloc_Free(alloc, p->Coders);
+ IAlloc_Free(alloc, p->BindPairs);
+ IAlloc_Free(alloc, p->PackStreams);
+ IAlloc_Free(alloc, p->UnPackSizes);
+ SzFolder_Init(p);
}
-UInt32 SzFolderGetNumOutStreams(CFolder *folder)
+UInt32 SzFolder_GetNumOutStreams(CSzFolder *p)
{
UInt32 result = 0;
UInt32 i;
- for (i = 0; i < folder->NumCoders; i++)
- result += folder->Coders[i].NumOutStreams;
+ for (i = 0; i < p->NumCoders; i++)
+ result += p->Coders[i].NumOutStreams;
return result;
}
-int SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex)
+int SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex)
{
UInt32 i;
- for(i = 0; i < folder->NumBindPairs; i++)
- if (folder->BindPairs[i].InIndex == inStreamIndex)
+ for (i = 0; i < p->NumBindPairs; i++)
+ if (p->BindPairs[i].InIndex == inStreamIndex)
return i;
return -1;
}
-int SzFolderFindBindPairForOutStream(CFolder *folder, UInt32 outStreamIndex)
+int SzFolder_FindBindPairForOutStream(CSzFolder *p, UInt32 outStreamIndex)
{
UInt32 i;
- for(i = 0; i < folder->NumBindPairs; i++)
- if (folder->BindPairs[i].OutIndex == outStreamIndex)
+ for (i = 0; i < p->NumBindPairs; i++)
+ if (p->BindPairs[i].OutIndex == outStreamIndex)
return i;
return -1;
}
-CFileSize SzFolderGetUnPackSize(CFolder *folder)
+CFileSize SzFolder_GetUnPackSize(CSzFolder *p)
{
- int i = (int)SzFolderGetNumOutStreams(folder);
+ int i = (int)SzFolder_GetNumOutStreams(p);
if (i == 0)
return 0;
for (i--; i >= 0; i--)
- if (SzFolderFindBindPairForOutStream(folder, i) < 0)
- return folder->UnPackSizes[i];
+ if (SzFolder_FindBindPairForOutStream(p, i) < 0)
+ return p->UnPackSizes[i];
/* throw 1; */
return 0;
}
-/*
-int FindPackStreamArrayIndex(int inStreamIndex) const
+void SzFile_Init(CSzFileItem *p)
{
- for(int i = 0; i < PackStreams.Size(); i++)
- if (PackStreams[i] == inStreamIndex)
- return i;
- return -1;
-}
-*/
-
-void SzFileInit(CFileItem *fileItem)
-{
- fileItem->IsFileCRCDefined = 0;
- fileItem->HasStream = 1;
- fileItem->IsDirectory = 0;
- fileItem->IsAnti = 0;
- fileItem->IsLastWriteTimeDefined = 0;
- fileItem->Name = 0;
+ p->IsFileCRCDefined = 0;
+ p->HasStream = 1;
+ p->IsDirectory = 0;
+ p->IsAnti = 0;
+ p->IsLastWriteTimeDefined = 0;
+ p->Name = 0;
}
-void SzFileFree(CFileItem *fileItem, void (*freeFunc)(void *p))
+static void SzFile_Free(CSzFileItem *p, ISzAlloc *alloc)
{
- freeFunc(fileItem->Name);
- SzFileInit(fileItem);
+ IAlloc_Free(alloc, p->Name);
+ SzFile_Init(p);
}
-void SzArchiveDatabaseInit(CArchiveDatabase *db)
+void SzAr_Init(CSzAr *p)
{
- db->NumPackStreams = 0;
- db->PackSizes = 0;
- db->PackCRCsDefined = 0;
- db->PackCRCs = 0;
- db->NumFolders = 0;
- db->Folders = 0;
- db->NumFiles = 0;
- db->Files = 0;
+ p->PackSizes = 0;
+ p->PackCRCsDefined = 0;
+ p->PackCRCs = 0;
+ p->Folders = 0;
+ p->Files = 0;
+ p->NumPackStreams = 0;
+ p->NumFolders = 0;
+ p->NumFiles = 0;
}
-void SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *))
+void SzAr_Free(CSzAr *p, ISzAlloc *alloc)
{
UInt32 i;
- for (i = 0; i < db->NumFolders; i++)
- SzFolderFree(&db->Folders[i], freeFunc);
- for (i = 0; i < db->NumFiles; i++)
- SzFileFree(&db->Files[i], freeFunc);
- freeFunc(db->PackSizes);
- freeFunc(db->PackCRCsDefined);
- freeFunc(db->PackCRCs);
- freeFunc(db->Folders);
- freeFunc(db->Files);
- SzArchiveDatabaseInit(db);
+ if (p->Folders)
+ for (i = 0; i < p->NumFolders; i++)
+ SzFolder_Free(&p->Folders[i], alloc);
+ if (p->Files)
+ for (i = 0; i < p->NumFiles; i++)
+ SzFile_Free(&p->Files[i], alloc);
+ IAlloc_Free(alloc, p->PackSizes);
+ IAlloc_Free(alloc, p->PackCRCsDefined);
+ IAlloc_Free(alloc, p->PackCRCs);
+ IAlloc_Free(alloc, p->Folders);
+ IAlloc_Free(alloc, p->Files);
+ SzAr_Init(p);
}
diff --git a/C/Archive/7z/7zItem.h b/C/Archive/7z/7zItem.h
index 05567bff..074a3a99 100755
--- a/C/Archive/7z/7zItem.h
+++ b/C/Archive/7z/7zItem.h
@@ -1,66 +1,79 @@
-/* 7zItem.h */
+/* 7zItem.h -- 7z Items
+2008-05-01
+Igor Pavlov
+Copyright (c) 1999-2008 Igor Pavlov
+Read LzmaDec.h for license options */
#ifndef __7Z_ITEM_H
#define __7Z_ITEM_H
-#include "7zMethodID.h"
-#include "7zHeader.h"
-#include "7zBuffer.h"
+#include "../../7zBuf.h"
-typedef struct _CCoderInfo
+/* #define _SZ_FILE_SIZE_32 */
+/* You can define _SZ_FILE_SIZE_32, if you don't need support for files larger than 4 GB*/
+
+#ifdef _SZ_FILE_SIZE_32
+typedef UInt32 CFileSize;
+#else
+typedef UInt64 CFileSize;
+#endif
+
+typedef UInt64 CMethodID;
+
+typedef struct
{
UInt32 NumInStreams;
UInt32 NumOutStreams;
CMethodID MethodID;
- CSzByteBuffer Properties;
-}CCoderInfo;
+ CBuf Props;
+} CSzCoderInfo;
-void SzCoderInfoInit(CCoderInfo *coder);
-void SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p));
+void SzCoderInfo_Init(CSzCoderInfo *p);
+void SzCoderInfo_Free(CSzCoderInfo *p, ISzAlloc *alloc);
-typedef struct _CBindPair
+typedef struct
{
UInt32 InIndex;
UInt32 OutIndex;
-}CBindPair;
+} CBindPair;
-typedef struct _CFolder
+typedef struct
{
- UInt32 NumCoders;
- CCoderInfo *Coders;
- UInt32 NumBindPairs;
+ CSzCoderInfo *Coders;
CBindPair *BindPairs;
- UInt32 NumPackStreams;
UInt32 *PackStreams;
CFileSize *UnPackSizes;
+ UInt32 NumCoders;
+ UInt32 NumBindPairs;
+ UInt32 NumPackStreams;
int UnPackCRCDefined;
UInt32 UnPackCRC;
UInt32 NumUnPackStreams;
-}CFolder;
+} CSzFolder;
-void SzFolderInit(CFolder *folder);
-CFileSize SzFolderGetUnPackSize(CFolder *folder);
-int SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex);
-UInt32 SzFolderGetNumOutStreams(CFolder *folder);
-CFileSize SzFolderGetUnPackSize(CFolder *folder);
+void SzFolder_Init(CSzFolder *p);
+CFileSize SzFolder_GetUnPackSize(CSzFolder *p);
+int SzFolder_FindBindPairForInStream(CSzFolder *p, UInt32 inStreamIndex);
+UInt32 SzFolder_GetNumOutStreams(CSzFolder *p);
+CFileSize SzFolder_GetUnPackSize(CSzFolder *p);
-typedef struct _CArchiveFileTime
+typedef struct
{
UInt32 Low;
UInt32 High;
-} CArchiveFileTime;
+} CNtfsFileTime;
-typedef struct _CFileItem
+typedef struct
{
- CArchiveFileTime LastWriteTime;
+ CNtfsFileTime LastWriteTime;
/*
CFileSize StartPos;
UInt32 Attributes;
*/
CFileSize Size;
- UInt32 FileCRC;
char *Name;
+ UInt32 FileCRC;
Byte IsFileCRCDefined;
Byte HasStream;
@@ -72,24 +85,23 @@ typedef struct _CFileItem
int IsLastWriteTimeDefined;
int IsStartPosDefined;
*/
-}CFileItem;
+} CSzFileItem;
-void SzFileInit(CFileItem *fileItem);
+void SzFile_Init(CSzFileItem *p);
-typedef struct _CArchiveDatabase
+typedef struct
{
- UInt32 NumPackStreams;
CFileSize *PackSizes;
Byte *PackCRCsDefined;
UInt32 *PackCRCs;
+ CSzFolder *Folders;
+ CSzFileItem *Files;
+ UInt32 NumPackStreams;
UInt32 NumFolders;
- CFolder *Folders;
UInt32 NumFiles;
- CFileItem *Files;
-}CArchiveDatabase;
-
-void SzArchiveDatabaseInit(CArchiveDatabase *db);
-void SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *));
+} CSzAr;
+void SzAr_Init(CSzAr *p);
+void SzAr_Free(CSzAr *p, ISzAlloc *alloc);
#endif
diff --git a/C/Archive/7z/7zMain.c b/C/Archive/7z/7zMain.c
index 0deef893..62f50689 100755
--- a/C/Archive/7z/7zMain.c
+++ b/C/Archive/7z/7zMain.c
@@ -1,8 +1,7 @@
-/*
-7zMain.c
-Test application for 7z Decoder
-LZMA SDK 4.43 Copyright (c) 1999-2006 Igor Pavlov (2006-06-04)
-*/
+/* 7zMain.c - Test application for 7z Decoder
+2008-04-09
+Igor Pavlov
+Public domain */
#include <stdio.h>
#include <stdlib.h>
@@ -18,6 +17,7 @@ LZMA SDK 4.43 Copyright (c) 1999-2006 Igor Pavlov (2006-06-04)
#include "7zIn.h"
#include "7zExtract.h"
+#include "7zAlloc.h"
#include "../../7zCrc.h"
@@ -48,7 +48,7 @@ void ConvertNumberToString(CFileSize value, char *s)
#define PERIOD_100 (PERIOD_4 * 25 - 1)
#define PERIOD_400 (PERIOD_100 * 4 + 1)
-void ConvertFileTimeToString(CArchiveFileTime *ft, char *s)
+void ConvertFileTimeToString(CNtfsFileTime *ft, char *s)
{
unsigned year, mon, day, hour, min, sec;
UInt64 v64 = ft->Low | ((UInt64)ft->High << 32);
@@ -177,61 +177,59 @@ typedef struct _CFileInStream
MY_FILE_HANDLE File;
} CFileInStream;
-#ifdef _LZMA_IN_CB
#define kBufferSize (1 << 12)
Byte g_Buffer[kBufferSize];
-SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)
+SRes SzFileReadImp(void *object, void **buffer, size_t *size)
{
CFileInStream *s = (CFileInStream *)object;
- size_t processedSizeLoc;
- if (maxRequiredSize > kBufferSize)
- maxRequiredSize = kBufferSize;
- processedSizeLoc = MyReadFile(s->File, g_Buffer, maxRequiredSize);
+ if (*size > kBufferSize)
+ *size = kBufferSize;
+ *size = MyReadFile(s->File, g_Buffer, *size);
*buffer = g_Buffer;
- if (processedSize != 0)
- *processedSize = processedSizeLoc;
return SZ_OK;
}
-#else
-
-SZ_RESULT SzFileReadImp(void *object, void *buffer, size_t size, size_t *processedSize)
-{
- CFileInStream *s = (CFileInStream *)object;
- size_t processedSizeLoc = MyReadFile(s->File, buffer, size);
- if (processedSize != 0)
- *processedSize = processedSizeLoc;
- return SZ_OK;
-}
-
-#endif
-
-SZ_RESULT SzFileSeekImp(void *object, CFileSize pos)
+SRes SzFileSeekImp(void *object, CFileSize pos, ESzSeek origin)
{
CFileInStream *s = (CFileInStream *)object;
#ifdef USE_WINDOWS_FUNCTIONS
{
LARGE_INTEGER value;
+ DWORD moveMethod;
value.LowPart = (DWORD)pos;
value.HighPart = (LONG)((UInt64)pos >> 32);
#ifdef _SZ_FILE_SIZE_32
/* VC 6.0 has bug with >> 32 shifts. */
value.HighPart = 0;
#endif
- value.LowPart = SetFilePointer(s->File, value.LowPart, &value.HighPart, FILE_BEGIN);
+ switch (origin)
+ {
+ case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;
+ case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;
+ case SZ_SEEK_END: moveMethod = FILE_END; break;
+ default: return SZ_ERROR_PARAM;
+ }
+ value.LowPart = SetFilePointer(s->File, value.LowPart, &value.HighPart, moveMethod);
if (value.LowPart == 0xFFFFFFFF)
- if(GetLastError() != NO_ERROR)
- return SZE_FAIL;
+ if (GetLastError() != NO_ERROR)
+ return SZ_ERROR_FAIL;
return SZ_OK;
}
#else
- int res = fseek(s->File, (long)pos, SEEK_SET);
- if (res == 0)
- return SZ_OK;
- return SZE_FAIL;
+ int moveMethod;
+ int res;
+ switch (origin)
+ {
+ case SZ_SEEK_SET: moveMethod = SEEK_SET; break;
+ case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;
+ case SZ_SEEK_END: moveMethod = SEEK_END; break;
+ default: return SZ_ERROR_PARAM;
+ }
+ res = fseek(s->File, (long)pos, moveMethod );
+ return (res == 0) ? SZ_OK : SZ_ERROR_FAIL;
#endif
}
@@ -240,15 +238,15 @@ void PrintError(char *sz)
printf("\nERROR: %s\n", sz);
}
-int main(int numargs, char *args[])
+int MY_CDECL main(int numargs, char *args[])
{
CFileInStream archiveStream;
- CArchiveDatabaseEx db;
- SZ_RESULT res;
+ CSzArEx db;
+ SRes res;
ISzAlloc allocImp;
ISzAlloc allocTempImp;
- printf("\n7z ANSI-C Decoder 4.48 Copyright (c) 1999-2007 Igor Pavlov 2007-06-21\n");
+ printf("\n7z ANSI-C Decoder 4.58 Copyright (c) 1999-2008 Igor Pavlov 2008-04-09\n");
if (numargs == 1)
{
printf(
@@ -267,7 +265,7 @@ int main(int numargs, char *args[])
archiveStream.File =
#ifdef USE_WINDOWS_FUNCTIONS
- CreateFile(args[2], GENERIC_READ, FILE_SHARE_READ,
+ CreateFileA(args[2], GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (archiveStream.File == INVALID_HANDLE_VALUE)
#else
@@ -290,8 +288,8 @@ int main(int numargs, char *args[])
CrcGenerateTable();
- SzArDbExInit(&db);
- res = SzArchiveOpen(&archiveStream.InStream, &db, &allocImp, &allocTempImp);
+ SzArEx_Init(&db);
+ res = SzArEx_Open(&db, &archiveStream.InStream, &allocImp, &allocTempImp);
if (res == SZ_OK)
{
char *command = args[1];
@@ -308,9 +306,9 @@ int main(int numargs, char *args[])
if (listCommand)
{
UInt32 i;
- for (i = 0; i < db.Database.NumFiles; i++)
+ for (i = 0; i < db.db.NumFiles; i++)
{
- CFileItem *f = db.Database.Files + i;
+ CSzFileItem *f = db.db.Files + i;
char s[32], t[32];
ConvertNumberToString(f->Size, s);
if (f->IsLastWriteTimeDefined)
@@ -334,11 +332,11 @@ int main(int numargs, char *args[])
size_t outBufferSize = 0; /* it can have any value before first call (if outBuffer = 0) */
printf("\n");
- for (i = 0; i < db.Database.NumFiles; i++)
+ for (i = 0; i < db.db.NumFiles; i++)
{
size_t offset;
size_t outSizeProcessed;
- CFileItem *f = db.Database.Files + i;
+ CSzFileItem *f = db.db.Files + i;
if (f->IsDirectory)
printf("Directory ");
else
@@ -351,7 +349,7 @@ int main(int numargs, char *args[])
printf("\n");
continue;
}
- res = SzExtract(&archiveStream.InStream, &db, i,
+ res = SzAr_Extract(&db, &archiveStream.InStream, i,
&blockIndex, &outBuffer, &outBufferSize,
&offset, &outSizeProcessed,
&allocImp, &allocTempImp);
@@ -372,7 +370,7 @@ int main(int numargs, char *args[])
outputHandle =
#ifdef USE_WINDOWS_FUNCTIONS
- CreateFile(fileName, GENERIC_WRITE, FILE_SHARE_READ,
+ CreateFileA(fileName, GENERIC_WRITE, FILE_SHARE_READ,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (outputHandle == INVALID_HANDLE_VALUE)
#else
@@ -381,34 +379,34 @@ int main(int numargs, char *args[])
#endif
{
PrintError("can not open output file");
- res = SZE_FAIL;
+ res = SZ_ERROR_FAIL;
break;
}
processedSize = MyWriteFile(outputHandle, outBuffer + offset, outSizeProcessed);
if (processedSize != outSizeProcessed)
{
PrintError("can not write output file");
- res = SZE_FAIL;
+ res = SZ_ERROR_FAIL;
break;
}
if (MyCloseFile(outputHandle))
{
PrintError("can not close output file");
- res = SZE_FAIL;
+ res = SZ_ERROR_FAIL;
break;
}
}
printf("\n");
}
- allocImp.Free(outBuffer);
+ IAlloc_Free(&allocImp, outBuffer);
}
else
{
PrintError("incorrect command");
- res = SZE_FAIL;
+ res = SZ_ERROR_FAIL;
}
}
- SzArDbExFree(&db, allocImp.Free);
+ SzArEx_Free(&db, &allocImp);
MyCloseFile(archiveStream.File);
if (res == SZ_OK)
@@ -416,11 +414,11 @@ int main(int numargs, char *args[])
printf("\nEverything is Ok\n");
return 0;
}
- if (res == (SZ_RESULT)SZE_NOTIMPL)
+ if (res == SZ_ERROR_UNSUPPORTED)
PrintError("decoder doesn't support this archive");
- else if (res == (SZ_RESULT)SZE_OUTOFMEMORY)
+ else if (res == SZ_ERROR_MEM)
PrintError("can not allocate memory");
- else if (res == (SZ_RESULT)SZE_CRC_ERROR)
+ else if (res == SZ_ERROR_CRC)
PrintError("CRC error");
else
printf("\nERROR #%d\n", res);
diff --git a/C/Archive/7z/7zMethodID.c b/C/Archive/7z/7zMethodID.c
deleted file mode 100755
index a7e825de..00000000
--- a/C/Archive/7z/7zMethodID.c
+++ /dev/null
@@ -1,10 +0,0 @@
-/* 7zMethodID.c */
-
-#include "7zMethodID.h"
-
-/*
-int AreMethodsEqual(CMethodID *a1, CMethodID *a2)
-{
- return (*a1 == *a2) ? 1 : 0;
-}
-*/
diff --git a/C/Archive/7z/7zMethodID.h b/C/Archive/7z/7zMethodID.h
deleted file mode 100755
index 57f22a50..00000000
--- a/C/Archive/7z/7zMethodID.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/* 7zMethodID.h */
-
-#ifndef __7Z_METHOD_ID_H
-#define __7Z_METHOD_ID_H
-
-#include "../../Types.h"
-
-typedef UInt64 CMethodID;
-
-#endif
diff --git a/C/Archive/7z/makefile b/C/Archive/7z/makefile
index 6ea3119a..76fdec01 100755
--- a/C/Archive/7z/makefile
+++ b/C/Archive/7z/makefile
@@ -1,74 +1,30 @@
-PROG = 7zDec.exe
-
-!IFDEF CPU
-LIBS = $(LIBS) bufferoverflowU.lib
-CFLAGS = $(CFLAGS) -GS- -Zc:forScope -WX -GS- -Gy -W4
-!ENDIF
-
-!IFNDEF O
-!IFDEF CPU
-O=$(CPU)
-!ELSE
-O=O
-!ENDIF
-!ENDIF
-
-CFLAGS = $(CFLAGS) -nologo -c -Fo$O/ -D_LZMA_IN_CB
-CFLAGS_O1 = $(CFLAGS) -O1
-CFLAGS_O2 = $(CFLAGS) -O2
-
-LFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 -OPT:REF
+MY_STATIC_LINK=1
-PROGPATH = $O\$(PROG)
-
-COMPL_O1 = $(CPP) $(CFLAGS_O1) $**
-COMPL_O2 = $(CPP) $(CFLAGS_O2) $**
-COMPL = $(CPP) $(CFLAGS_O1) $**
+PROG = 7zDec.exe
C_OBJS = \
+ $O\7zBuf.obj \
$O\7zCrc.obj \
-
+ $O\LzmaDec.obj \
+ $O\Bra86.obj \
+ $O\Bcj2.obj \
7Z_OBJS = \
$O\7zAlloc.obj \
- $O\7zBuffer.obj \
$O\7zDecode.obj \
$O\7zExtract.obj \
$O\7zHeader.obj \
$O\7zIn.obj \
$O\7zItem.obj \
$O\7zMain.obj \
- $O\7zMethodID.obj \
OBJS = \
$(7Z_OBJS) \
- $O\LzmaDecode.obj \
- $O\BranchX86.obj \
- $O\BranchX86_2.obj \
$(C_OBJS) \
-all: $(PROGPATH)
-
-clean:
- -del /Q $(PROGPATH) $O\*.exe $O\*.dll $O\*.obj $O\*.lib $O\*.exp $O\*.res $O\*.pch
-
-$O:
- if not exist "$O" mkdir "$O"
-
-$(PROGPATH): $O $(OBJS)
- link $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS)
-
+!include "../../../CPP/Build.mak"
$(7Z_OBJS): $(*B).c
- $(COMPL)
-$O\LzmaDecode.obj: ../../Compress/Lzma/$(*B).c
- $(COMPL_O2)
-
-$O\BranchX86.obj: ../../Compress/Branch/$(*B).c
- $(COMPL_O2)
-
-$O\BranchX86_2.obj: ../../Compress/Branch/$(*B).c
- $(COMPL_O2)
-
+ $(COMPL_O1)
$(C_OBJS): ../../$(*B).c
$(COMPL_O2)
diff --git a/C/Archive/7z/makefile.gcc b/C/Archive/7z/makefile.gcc
index 664ac252..796412a1 100755
--- a/C/Archive/7z/makefile.gcc
+++ b/C/Archive/7z/makefile.gcc
@@ -2,9 +2,9 @@ PROG = 7zDec
CXX = g++
LIB =
RM = rm -f
-CFLAGS = -c -O2 -Wall -D_LZMA_IN_CB
+CFLAGS = -c -O2 -Wall
-OBJS = 7zAlloc.o 7zBuffer.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o 7zMethodID.o LzmaDecode.o BranchX86.o BranchX86_2.o
+OBJS = 7zAlloc.o 7zBuf.o 7zCrc.o 7zDecode.o 7zExtract.o 7zHeader.o 7zIn.o 7zItem.o 7zMain.o LzmaDec.o Bra86.o Bcj2.o
all: $(PROG)
@@ -14,8 +14,8 @@ $(PROG): $(OBJS)
7zAlloc.o: 7zAlloc.c
$(CXX) $(CFLAGS) 7zAlloc.c
-7zBuffer.o: 7zBuffer.c
- $(CXX) $(CFLAGS) 7zBuffer.c
+7zBuf.o: ../../7zBuf.c
+ $(CXX) $(CFLAGS) ../../7zBuf.c
7zCrc.o: ../../7zCrc.c
$(CXX) $(CFLAGS) ../../7zCrc.c
@@ -38,17 +38,14 @@ $(PROG): $(OBJS)
7zMain.o: 7zMain.c
$(CXX) $(CFLAGS) 7zMain.c
-7zMethodID.o: 7zMethodID.c
- $(CXX) $(CFLAGS) 7zMethodID.c
+LzmaDec.o: ../../LzmaDec.c
+ $(CXX) $(CFLAGS) ../../LzmaDec.c
-LzmaDecode.o: ../../Compress/Lzma/LzmaDecode.c
- $(CXX) $(CFLAGS) ../../Compress/Lzma/LzmaDecode.c
+Bra86.o: ../../Bra86.c
+ $(CXX) $(CFLAGS) ../../Bra86.c
-BranchX86.o: ../../Compress/Branch/BranchX86.c
- $(CXX) $(CFLAGS) ../../Compress/Branch/BranchX86.c
-
-BranchX86_2.o: ../../Compress/Branch/BranchX86_2.c
- $(CXX) $(CFLAGS) ../../Compress/Branch/BranchX86_2.c
+Bcj2.o: ../../Bcj2.c
+ $(CXX) $(CFLAGS) ../../Bcj2.c
clean:
-$(RM) $(PROG) $(OBJS)