diff --git a/7zip/Archive/7z_C/7zAlloc.h b/7zip/Archive/7z_C/7zAlloc.h deleted file mode 100755 index 4ca4170c..00000000 --- a/7zip/Archive/7z_C/7zAlloc.h +++ /dev/null @@ -1,20 +0,0 @@ -/* 7zAlloc.h */ - -#ifndef __7Z_ALLOC_H -#define __7Z_ALLOC_H - -#include - -typedef struct _ISzAlloc -{ - void *(*Alloc)(size_t size); - void (*Free)(void *address); /* address can be 0 */ -} ISzAlloc; - -void *SzAlloc(size_t size); -void SzFree(void *address); - -void *SzAllocTemp(size_t size); -void SzFreeTemp(void *address); - -#endif diff --git a/7zip/Archive/7z_C/7zBuffer.h b/7zip/Archive/7z_C/7zBuffer.h deleted file mode 100755 index 17e59060..00000000 --- a/7zip/Archive/7z_C/7zBuffer.h +++ /dev/null @@ -1,19 +0,0 @@ -/* 7zBuffer.h */ - -#ifndef __7Z_BUFFER_H -#define __7Z_BUFFER_H - -#include -#include "7zTypes.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/7zip/Archive/7z_C/7zCrc.c b/7zip/Archive/7z_C/7zCrc.c deleted file mode 100755 index 97738404..00000000 --- a/7zip/Archive/7z_C/7zCrc.c +++ /dev/null @@ -1,76 +0,0 @@ -/* 7zCrc.c */ - -#include "7zCrc.h" - -#define kCrcPoly 0xEDB88320 - -UInt32 g_CrcTable[256]; - -void InitCrcTable() -{ - UInt32 i; - for (i = 0; i < 256; i++) - { - UInt32 r = i; - int j; - for (j = 0; j < 8; j++) - if (r & 1) - r = (r >> 1) ^ kCrcPoly; - else - r >>= 1; - g_CrcTable[i] = r; - } -} - -void CrcInit(UInt32 *crc) { *crc = 0xFFFFFFFF; } -UInt32 CrcGetDigest(UInt32 *crc) { return *crc ^ 0xFFFFFFFF; } - -void CrcUpdateByte(UInt32 *crc, Byte b) -{ - *crc = g_CrcTable[((Byte)(*crc)) ^ b] ^ (*crc >> 8); -} - -void CrcUpdateUInt16(UInt32 *crc, UInt16 v) -{ - CrcUpdateByte(crc, (Byte)v); - CrcUpdateByte(crc, (Byte)(v >> 8)); -} - -void CrcUpdateUInt32(UInt32 *crc, UInt32 v) -{ - int i; - for (i = 0; i < 4; i++) - CrcUpdateByte(crc, (Byte)(v >> (8 * i))); -} - -void CrcUpdateUInt64(UInt32 *crc, UInt64 v) -{ - int i; - for (i = 0; i < 8; i++) - { - CrcUpdateByte(crc, (Byte)(v)); - v >>= 8; - } -} - -void CrcUpdate(UInt32 *crc, const void *data, size_t size) -{ - UInt32 v = *crc; - const Byte *p = (const Byte *)data; - for (; size > 0 ; size--, p++) - v = g_CrcTable[((Byte)(v)) ^ *p] ^ (v >> 8); - *crc = v; -} - -UInt32 CrcCalculateDigest(const void *data, size_t size) -{ - UInt32 crc; - CrcInit(&crc); - CrcUpdate(&crc, data, size); - return CrcGetDigest(&crc); -} - -int CrcVerifyDigest(UInt32 digest, const void *data, size_t size) -{ - return (CrcCalculateDigest(data, size) == digest); -} diff --git a/7zip/Archive/7z_C/7zDecode.h b/7zip/Archive/7z_C/7zDecode.h deleted file mode 100755 index 74bb180f..00000000 --- a/7zip/Archive/7z_C/7zDecode.h +++ /dev/null @@ -1,21 +0,0 @@ -/* 7zDecode.h */ - -#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, - #ifdef _LZMA_IN_CB - ISzInStream *stream, - #else - const Byte *inBuffer, - #endif - Byte *outBuffer, size_t outSize, - size_t *outSizeProcessed, ISzAlloc *allocMain); - -#endif diff --git a/7zip/Archive/7z_C/7zExtract.h b/7zip/Archive/7z_C/7zExtract.h deleted file mode 100755 index e9a4fb4e..00000000 --- a/7zip/Archive/7z_C/7zExtract.h +++ /dev/null @@ -1,40 +0,0 @@ -/* 7zExtract.h */ - -#ifndef __7Z_EXTRACT_H -#define __7Z_EXTRACT_H - -#include "7zIn.h" - -/* - SzExtract extracts file from archive - - *outBuffer must be 0 before first call for each new archive. - - Extracting cache: - If you need to decompress more than one file, you can send - these values from previous call: - *blockIndex, - *outBuffer, - *outBufferSize - You can consider "*outBuffer" as cache of solid block. If your archive is solid, - it will increase decompression speed. - - If you use external function, you can declare these 3 cache variables - (blockIndex, outBuffer, outBufferSize) as static in that external function. - - Free *outBuffer and set *outBuffer to 0, if you want to flush cache. -*/ - -SZ_RESULT SzExtract( - 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) */ - size_t *outBufferSize, /* buffer size for output buffer */ - size_t *offset, /* offset of stream for required file in *outBuffer */ - size_t *outSizeProcessed, /* size of file in *outBuffer */ - ISzAlloc *allocMain, - ISzAlloc *allocTemp); - -#endif diff --git a/7zip/Archive/7z_C/7zHeader.h b/7zip/Archive/7z_C/7zHeader.h deleted file mode 100755 index 0356aaa6..00000000 --- a/7zip/Archive/7z_C/7zHeader.h +++ /dev/null @@ -1,55 +0,0 @@ -/* 7zHeader.h */ - -#ifndef __7Z_HEADER_H -#define __7Z_HEADER_H - -#include "7zTypes.h" - -#define k7zSignatureSize 6 -extern Byte k7zSignature[k7zSignatureSize]; - -#define k7zMajorVersion 0 - -#define k7zStartHeaderSize 0x20 - -enum EIdEnum -{ - k7zIdEnd, - - k7zIdHeader, - - k7zIdArchiveProperties, - - k7zIdAdditionalStreamsInfo, - k7zIdMainStreamsInfo, - k7zIdFilesInfo, - - k7zIdPackInfo, - k7zIdUnPackInfo, - k7zIdSubStreamsInfo, - - k7zIdSize, - k7zIdCRC, - - k7zIdFolder, - - k7zIdCodersUnPackSize, - k7zIdNumUnPackStream, - - k7zIdEmptyStream, - k7zIdEmptyFile, - k7zIdAnti, - - k7zIdName, - k7zIdCreationTime, - k7zIdLastAccessTime, - k7zIdLastWriteTime, - k7zIdWinAttributes, - k7zIdComment, - - k7zIdEncodedHeader, - - k7zIdStartPos -}; - -#endif diff --git a/7zip/Archive/7z_C/7zIn.h b/7zip/Archive/7z_C/7zIn.h deleted file mode 100755 index 6bfa2a70..00000000 --- a/7zip/Archive/7z_C/7zIn.h +++ /dev/null @@ -1,55 +0,0 @@ -/* 7zIn.h */ - -#ifndef __7Z_IN_H -#define __7Z_IN_H - -#include "7zHeader.h" -#include "7zItem.h" -#include "7zAlloc.h" - -typedef struct _CInArchiveInfo -{ - CFileSize StartPositionAfterHeader; - CFileSize DataStartPosition; -}CInArchiveInfo; - -typedef struct _CArchiveDatabaseEx -{ - CArchiveDatabase Database; - CInArchiveInfo ArchiveInfo; - UInt32 *FolderStartPackStreamIndex; - CFileSize *PackStreamStartPositions; - UInt32 *FolderStartFileIndex; - UInt32 *FileIndexToFolderIndexMap; -}CArchiveDatabaseEx; - -void SzArDbExInit(CArchiveDatabaseEx *db); -void SzArDbExFree(CArchiveDatabaseEx *db, void (*freeFunc)(void *)); -CFileSize SzArDbGetFolderStreamPos(CArchiveDatabaseEx *db, UInt32 folderIndex, UInt32 indexInFolder); -CFileSize SzArDbGetFolderFullPackSize(CArchiveDatabaseEx *db, UInt32 folderIndex); - -typedef struct _ISzInStream -{ - #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); -} ISzInStream; - - -int SzArchiveOpen( - ISzInStream *inStream, - CArchiveDatabaseEx *db, - ISzAlloc *allocMain, - ISzAlloc *allocTemp); - -#endif diff --git a/7zip/Archive/7z_C/7zItem.h b/7zip/Archive/7z_C/7zItem.h deleted file mode 100755 index 876539a9..00000000 --- a/7zip/Archive/7z_C/7zItem.h +++ /dev/null @@ -1,90 +0,0 @@ -/* 7zItem.h */ - -#ifndef __7Z_ITEM_H -#define __7Z_ITEM_H - -#include "7zMethodID.h" -#include "7zHeader.h" -#include "7zBuffer.h" - -typedef struct _CCoderInfo -{ - UInt32 NumInStreams; - UInt32 NumOutStreams; - CMethodID MethodID; - CSzByteBuffer Properties; -}CCoderInfo; - -void SzCoderInfoInit(CCoderInfo *coder); -void SzCoderInfoFree(CCoderInfo *coder, void (*freeFunc)(void *p)); - -typedef struct _CBindPair -{ - UInt32 InIndex; - UInt32 OutIndex; -}CBindPair; - -typedef struct _CFolder -{ - UInt32 NumCoders; - CCoderInfo *Coders; - UInt32 NumBindPairs; - CBindPair *BindPairs; - UInt32 NumPackStreams; - UInt32 *PackStreams; - CFileSize *UnPackSizes; - int UnPackCRCDefined; - UInt32 UnPackCRC; - - UInt32 NumUnPackStreams; -}CFolder; - -void SzFolderInit(CFolder *folder); -CFileSize SzFolderGetUnPackSize(CFolder *folder); -int SzFolderFindBindPairForInStream(CFolder *folder, UInt32 inStreamIndex); -UInt32 SzFolderGetNumOutStreams(CFolder *folder); -CFileSize SzFolderGetUnPackSize(CFolder *folder); - -/* #define CArchiveFileTime UInt64 */ - -typedef struct _CFileItem -{ - /* - CArchiveFileTime LastWriteTime; - CFileSize StartPos; - UInt32 Attributes; - */ - CFileSize Size; - UInt32 FileCRC; - char *Name; - - Byte IsFileCRCDefined; - Byte HasStream; - Byte IsDirectory; - Byte IsAnti; - /* - int AreAttributesDefined; - int IsLastWriteTimeDefined; - int IsStartPosDefined; - */ -}CFileItem; - -void SzFileInit(CFileItem *fileItem); - -typedef struct _CArchiveDatabase -{ - UInt32 NumPackStreams; - CFileSize *PackSizes; - Byte *PackCRCsDefined; - UInt32 *PackCRCs; - UInt32 NumFolders; - CFolder *Folders; - UInt32 NumFiles; - CFileItem *Files; -}CArchiveDatabase; - -void SzArchiveDatabaseInit(CArchiveDatabase *db); -void SzArchiveDatabaseFree(CArchiveDatabase *db, void (*freeFunc)(void *)); - - -#endif diff --git a/7zip/Archive/7z_C/7zMethodID.h b/7zip/Archive/7z_C/7zMethodID.h deleted file mode 100755 index 162fcd15..00000000 --- a/7zip/Archive/7z_C/7zMethodID.h +++ /dev/null @@ -1,18 +0,0 @@ -/* 7zMethodID.h */ - -#ifndef __7Z_METHOD_ID_H -#define __7Z_METHOD_ID_H - -#include "7zTypes.h" - -#define kMethodIDSize 15 - -typedef struct _CMethodID -{ - Byte ID[kMethodIDSize]; - Byte IDSize; -} CMethodID; - -int AreMethodsEqual(CMethodID *a1, CMethodID *a2); - -#endif diff --git a/7zip/Compress/BWT/BlockSort.cpp b/7zip/Compress/BWT/BlockSort.cpp deleted file mode 100755 index ffe7dd9d..00000000 --- a/7zip/Compress/BWT/BlockSort.cpp +++ /dev/null @@ -1,288 +0,0 @@ -// BlockSort.cpp - -#include "StdAfx.h" - -#include "BlockSort.h" - -#include "Common/Alloc.h" - -namespace NCompress { - -static const int kNumHashBytes = 2; -static const UInt32 kNumHashValues = 1 << (kNumHashBytes * 8); - -static const int kNumFlagsBits = 5; // 32 Flags in UInt32 word -static const UInt32 kNumFlagsInWord = (1 << kNumFlagsBits); -static const UInt32 kFlagsMask = kNumFlagsInWord - 1; -static const UInt32 kAllFlags = 0xFFFFFFFF; - -bool CBlockSorter::Create(UInt32 blockSizeMax) -{ - if (Indices != 0 && blockSizeMax == BlockSizeMax) - return true; - Free(); - BlockSizeMax = blockSizeMax; - Indices = (UInt32 *)::BigAlloc((blockSizeMax * 2 + - ((blockSizeMax + kFlagsMask) >> kNumFlagsBits) + kNumHashValues) * sizeof(UInt32)); - return (Indices != 0); -} - -void CBlockSorter::Free() -{ - ::BigFree(Indices); - Indices = 0; -} - -// SortGroup - is recursive Radix-Range-Sort function with Bubble-Sort optimization -// It uses both mask & maskSize (Range-Sort), since it can change values (Groups) -// during sorting -// returns: 0 - if there are groups, 1 - no more groups -UInt32 CBlockSorter::SortGroup(UInt32 groupOffset, UInt32 groupSize, UInt32 mask, UInt32 maskSize) -{ - if (groupSize <= 2) - { - if (groupSize <= 1) - return 0; - UInt32 *ind2 = Indices + groupOffset; - UInt32 stringPos = ind2[0] + NumSortedBytes; - if (stringPos >= BlockSize) - stringPos -= BlockSize; - UInt32 group = Groups[stringPos]; - stringPos = ind2[1] + NumSortedBytes; - if (stringPos >= BlockSize) - stringPos -= BlockSize; - if (group == Groups[stringPos]) - return 1; - if (group > Groups[stringPos]) - { - UInt32 temp = ind2[0]; - ind2[0] = ind2[1]; - ind2[1] = temp; - } - Flags[groupOffset >> kNumFlagsBits] &= ~(1 << (groupOffset & kFlagsMask)); - Groups[ind2[1]] = groupOffset + 1; - return 0; - } - - // Check that all strings are in one group (cannot sort) - UInt32 *ind2 = Indices + groupOffset; - { - UInt32 stringPos = ind2[0] + NumSortedBytes; - if (stringPos >= BlockSize) - stringPos -= BlockSize; - UInt32 group = Groups[stringPos]; - UInt32 j; - for (j = 1; j < groupSize; j++) - { - stringPos = ind2[j] + NumSortedBytes; - if (stringPos >= BlockSize) - stringPos -= BlockSize; - if (Groups[stringPos] != group) - break; - } - if (j == groupSize) - return 1; - } - - if (groupSize <= 15) - { - // Bubble-Sort - UInt32 lastChange = groupSize; - do - { - UInt32 stringPos = ind2[0] + NumSortedBytes; - if (stringPos >= BlockSize) - stringPos -= BlockSize; - UInt32 group = Groups[stringPos]; - - UInt32 sortSize = lastChange; - lastChange = 0; - for (UInt32 j = 1; j < sortSize; j++) - { - stringPos = ind2[j] + NumSortedBytes; - if (stringPos >= BlockSize) - stringPos -= BlockSize; - if (Groups[stringPos] < group) - { - UInt32 temp = ind2[j]; - ind2[j] = ind2[j - 1]; - ind2[j - 1] = temp; - lastChange = j; - } - else - group = Groups[stringPos]; - } - } - while(lastChange > 1); - - // Write Flags - UInt32 stringPos = ind2[0] + NumSortedBytes; - if (stringPos >= BlockSize) - stringPos -= BlockSize; - UInt32 group = Groups[stringPos]; - - UInt32 j; - for (j = 1; j < groupSize; j++) - { - stringPos = ind2[j] + NumSortedBytes; - if (stringPos >= BlockSize) - stringPos -= BlockSize; - if (Groups[stringPos] != group) - { - group = Groups[stringPos]; - UInt32 t = groupOffset + j - 1; - Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask)); - } - } - - // Write new Groups values and Check that there are groups - UInt32 thereAreGroups = 0; - for (j = 0; j < groupSize; j++) - { - UInt32 group = groupOffset + j; - for (;;) - { - Groups[ind2[j]] = group; - if ((Flags[(groupOffset + j) >> kNumFlagsBits] & (1 << ((groupOffset + j) & kFlagsMask))) == 0) - break; - j++; - thereAreGroups = 1; - } - } - return thereAreGroups; - } - - // Radix-Range Sort - UInt32 i; - for (;;) - { - if (maskSize == 0) - return 1; - UInt32 j = groupSize; - i = 0; - do - { - UInt32 stringPos = ind2[i] + NumSortedBytes; - if (stringPos >= BlockSize) - stringPos -= BlockSize; - if (Groups[stringPos] >= mask) - { - for (j--; j > i; j--) - { - stringPos = ind2[j] + NumSortedBytes; - if (stringPos >= BlockSize) - stringPos -= BlockSize; - if (Groups[stringPos] < mask) - { - UInt32 temp = ind2[i]; - ind2[i] = ind2[j]; - ind2[j] = temp; - break; - } - } - if (i >= j) - break; - } - } - while(++i < j); - maskSize >>= 1; - if (i == 0) - mask += maskSize; - else if (i == groupSize) - mask -= maskSize; - else - break; - } - UInt32 t = (groupOffset + i - 1); - Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask)); - - for (UInt32 j = i; j < groupSize; j++) - Groups[ind2[j]] = groupOffset + i; - - UInt32 res = SortGroup(groupOffset, i, mask - maskSize, maskSize); - return res | SortGroup(groupOffset + i, groupSize - i, mask + maskSize, maskSize); -} - -UInt32 CBlockSorter::Sort(const Byte *data, UInt32 blockSize) -{ - BlockSize = blockSize; - UInt32 *counters = Indices + blockSize; - Groups = counters + kNumHashValues; - Flags = Groups + blockSize; - UInt32 i; - - // Radix-Sort for 2 bytes - for (i = 0; i < kNumHashValues; i++) - counters[i] = 0; - for (i = 0; i < blockSize - 1; i++) - counters[((UInt32)data[i] << 8) | data[i + 1]]++; - counters[((UInt32)data[i] << 8) | data[0]]++; - - { - { - UInt32 numWords = (blockSize + kFlagsMask) >> kNumFlagsBits; - for (i = 0; i < numWords; i++) - Flags[i] = kAllFlags; - } - - UInt32 sum = 0; - for (i = 0; i < kNumHashValues; i++) - { - UInt32 groupSize = counters[i]; - if (groupSize > 0) - { - UInt32 t = sum + groupSize - 1; - Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask)); - sum += groupSize; - } - counters[i] = sum - groupSize; - } - - for (i = 0; i < blockSize - 1; i++) - Groups[i] = counters[((UInt32)data[i] << 8) | data[i + 1]]; - Groups[i] = counters[((UInt32)data[i] << 8) | data[0]]; - - for (i = 0; i < blockSize - 1; i++) - Indices[counters[((UInt32)data[i] << 8) | data[i + 1]]++] = i; - Indices[counters[((UInt32)data[i] << 8) | data[0]]++] = i; - } - - UInt32 mask; - for (mask = 2; mask < blockSize; mask <<= 1); - mask >>= 1; - for (NumSortedBytes = kNumHashBytes; ; NumSortedBytes <<= 1) - { - UInt32 newLimit = 0; - for (i = 0; i < blockSize;) - { - if ((Flags[i >> kNumFlagsBits] & (1 << (i & kFlagsMask))) == 0) - { - i++; - continue; - } - UInt32 groupSize; - for(groupSize = 1; - (Flags[(i + groupSize) >> kNumFlagsBits] & (1 << ((i + groupSize) & kFlagsMask))) != 0; - groupSize++); - - groupSize++; - - if (NumSortedBytes >= blockSize) - for (UInt32 j = 0; j < groupSize; j++) - { - UInt32 t = (i + j); - Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask)); - Groups[Indices[t]] = t; - } - else - if (SortGroup(i, groupSize, mask, mask) != 0) - newLimit = i + groupSize; - i += groupSize; - } - if (newLimit == 0) - break; - } - return Groups[0]; -} - -} diff --git a/7zip/Compress/BWT/BlockSort.h b/7zip/Compress/BWT/BlockSort.h deleted file mode 100755 index 599c3b60..00000000 --- a/7zip/Compress/BWT/BlockSort.h +++ /dev/null @@ -1,29 +0,0 @@ -// BlockSort.h - -#ifndef __BLOCKSORT_H -#define __BLOCKSORT_H - -#include "Common/Types.h" - -namespace NCompress { - -class CBlockSorter -{ - UInt32 *Groups; - UInt32 *Flags; - UInt32 BlockSize; - UInt32 NumSortedBytes; - UInt32 BlockSizeMax; - UInt32 SortGroup(UInt32 groupOffset, UInt32 groupSize, UInt32 mask, UInt32 maskSize); -public: - UInt32 *Indices; - CBlockSorter(): Indices(0) {} - ~CBlockSorter() { Free(); } - bool Create(UInt32 blockSizeMax); - void Free(); - UInt32 Sort(const Byte *data, UInt32 blockSize); -}; - -} - -#endif diff --git a/7zip/Compress/Huffman/HuffmanEncoder.cpp b/7zip/Compress/Huffman/HuffmanEncoder.cpp deleted file mode 100755 index c0e42799..00000000 --- a/7zip/Compress/Huffman/HuffmanEncoder.cpp +++ /dev/null @@ -1,325 +0,0 @@ -// Compression/HuffmanEncoder.cpp - -#include "StdAfx.h" - -#include "HuffmanEncoder.h" -#include "Common/Defs.h" -#include "Common/Alloc.h" - -namespace NCompression { -namespace NHuffman { - -static const char *kIncorrectBitLenCountsMessage = "Incorrect bit len counts"; - -CEncoder::CEncoder(): - m_Items(0), - m_Heap(0), - m_Depth(0) -{} - -void CEncoder::Free() -{ - MyFree(m_Items); - MyFree(m_Heap); - MyFree(m_Depth); - m_Items = 0; - m_Heap = 0; - m_Depth = 0; -} - -bool CEncoder::Create(UInt32 numSymbols, - const Byte *extraBits, UInt32 extraBase, UInt32 maxLength) -{ - m_NumSymbols = numSymbols; - m_ExtraBits = extraBits; - m_ExtraBase = extraBase; - m_MaxLength = maxLength; - m_HeapSize = numSymbols * 2 + 1; - Free(); - m_Items = (CItem *)MyAlloc(m_HeapSize * sizeof(CItem)); - m_Heap = (UInt32 *)MyAlloc(m_HeapSize * sizeof(UInt32)); - m_Depth = (Byte *)MyAlloc(m_HeapSize * sizeof(Byte)); - if (m_Items == 0 || m_Heap == 0 || m_Depth == 0) - { - Free(); - return false; - } - return true; -} - -CEncoder::~CEncoder() -{ - Free(); -} - -void CEncoder::StartNewBlock() -{ - for (UInt32 i = 0; i < m_NumSymbols; i++) - m_Items[i].Freq = 0; -} - -static const int kSmallest = 1; - -// =========================================================================== -// Remove the smallest element from the heap and recreate the heap with -// one less element. Updates heap and m_HeapLength. - -UInt32 CEncoder::RemoveSmallest() -{ - UInt32 top = m_Heap[kSmallest]; - m_Heap[kSmallest] = m_Heap[m_HeapLength--]; - DownHeap(kSmallest); - return top; -} - -// =========================================================================== -// Compares to subtrees, using the tree m_Depth as tie breaker when -// the subtrees have equal frequency. This minimizes the worst case length. - -bool CEncoder::Smaller(int n, int m) -{ - return (m_Items[n].Freq < m_Items[m].Freq || - (m_Items[n].Freq == m_Items[m].Freq && m_Depth[n] <= m_Depth[m])); -} - -// =========================================================================== -// Restore the m_Heap property by moving down the tree starting at node k, -// exchanging a node with the smallest of its two sons if necessary, stopping -// when the m_Heap property is re-established (each father CompareFreqs than its -// two sons). - -void CEncoder::DownHeap(UInt32 k) -{ - UInt32 symbol = m_Heap[k]; - for (UInt32 j = k << 1; j <= m_HeapLength;) // j: left son of k - { - // Set j to the smallest of the two sons: - if (j < m_HeapLength && Smaller(m_Heap[j+1], m_Heap[j])) - j++; - UInt32 htemp = m_Heap[j]; // htemp required because of bug in SASC compiler - if (Smaller(symbol, htemp)) // Exit if v is smaller than both sons - break; - m_Heap[k] = htemp; // Exchange v with the smallest son - k = j; - j <<= 1; // And continue down the tree, setting j to the left son of k - } - m_Heap[k] = symbol; -} - -// =========================================================================== -// Compute the optimal bit lengths for a tree and update the total bit length -// for the current block. -// IN assertion: the fields freq and dad are set, heap[heapMax] and -// above are the tree nodes sorted by increasing frequency. -// OUT assertions: the field len is set to the optimal bit length, the -// array m_BitLenCounters contains the frequencies for each bit length. -// The length m_BlockBitLength is updated; static_len is also updated if stree is -// not null. - -void CEncoder::GenerateBitLen(UInt32 maxCode, UInt32 heapMax) -{ - int overflow = 0; // number of elements with bit length too large - - for (UInt32 i = 0; i <= kNumBitsInLongestCode; i++) - m_BitLenCounters[i] = 0; - - /* In a first pass, compute the optimal bit lengths (which may - * overflow in the case of the bit length tree). - */ - m_Items[m_Heap[heapMax]].Len = 0; /* root of the heap */ - UInt32 h; /* heap index */ - for (h = heapMax+1; h < m_HeapSize; h++) - { - UInt32 symbol = m_Heap[h]; - UInt32 len = m_Items[m_Items[symbol].Dad].Len + 1; - if (len > m_MaxLength) - { - len = m_MaxLength; - overflow++; - } - m_Items[symbol].Len = len; // We overwrite m_Items[symbol].Dad which is no longer needed - if (symbol > maxCode) - continue; // not a leaf node - m_BitLenCounters[len]++; - UInt32 extraBits; - if (m_ExtraBits != 0 && symbol >= m_ExtraBase) - extraBits = m_ExtraBits[symbol - m_ExtraBase]; - else - extraBits = 0; - m_BlockBitLength += (m_Items[symbol].Freq * (len + extraBits)); - } - if (overflow == 0) - return; - - // This happens for example on obj2 and pic of the Calgary corpus - // Find the first bit length which could increase: - do - { - UInt32 bits = m_MaxLength-1; - while (m_BitLenCounters[bits] == 0) - bits--; - m_BitLenCounters[bits]--; // move one leaf down the m_Items - m_BitLenCounters[bits + 1] += 2; // move one overflow item as its brother - m_BitLenCounters[m_MaxLength]--; - // The brother of the overflow item also moves one step up, - // but this does not affect m_BitLenCounters[m_MaxLength] - overflow -= 2; - } - while (overflow > 0); - - // Now recompute all bit lengths, scanning in increasing frequency. - // h is still equal to HEAP_SIZE. (It is simpler to reconstruct all - // lengths instead of fixing only the wrong ones. This idea is taken - // from 'ar' written by Haruhiko Okumura.) - for (UInt32 bits = m_MaxLength; bits != 0; bits--) - { - UInt32 numNodes = m_BitLenCounters[bits]; - while (numNodes != 0) - { - UInt32 m = m_Heap[--h]; - if (m > maxCode) - continue; - if (m_Items[m].Len != (unsigned) bits) - { - m_BlockBitLength += ((long)bits - (long)m_Items[m].Len) * (long)m_Items[m].Freq; - m_Items[m].Len = bits; - } - numNodes--; - } - } -} - - -// =========================================================================== -// Generate the codes for a given tree and bit counts (which need not be -// optimal). -// IN assertion: the array m_BitLenCounters contains the bit length statistics for -// the given tree and the field len is set for all tree elements. -// OUT assertion: the field code is set for all tree elements of non -// zero code length. - -// UInt32 maxCode = largest code with non zero frequency - - -void CEncoder::GenerateCodes(UInt32 maxCode) -{ - UInt32 nextCodes[kNumBitsInLongestCode + 1]; // next code value for each bit length - UInt32 code = 0; // running code value - // The distribution counts are first used to generate the code values - // without bit reversal. - for (UInt32 bits = 1; bits <= kNumBitsInLongestCode; bits++) - nextCodes[bits] = code = (code + m_BitLenCounters[bits - 1]) << 1; - // Check that the bit counts in m_BitLenCounters are consistent. The last code - // must be all ones. - if (code + m_BitLenCounters[kNumBitsInLongestCode] - 1 != (1 << kNumBitsInLongestCode) - 1) - throw kIncorrectBitLenCountsMessage; - for (UInt32 n = 0; n <= maxCode; n++) - { - int len = m_Items[n].Len; - if (len == 0) - continue; - m_Items[n].Code = nextCodes[len]++; - } -} - - -// =========================================================================== -// Construct one Huffman tree and assigns the code bit strings and lengths. -// Update the total bit length for the current block. -// IN assertion: the field freq is set for all tree elements. -// OUT assertions: the fields len and code are set to the optimal bit length -// and corresponding code. The length m_BlockBitLength is updated; static_len is -// also updated if stree is not null. The field max_code is set. - -void CEncoder::BuildTree(Byte *levels) -{ - m_BlockBitLength = 0; - int maxCode = -1; // WAS = -1; largest code with non zero frequency */ - - // Construct the initial m_Heap, with least frequent element in - // m_Heap[kSmallest]. The sons of m_Heap[n] are m_Heap[2*n] and m_Heap[2*n+1]. - // m_Heap[0] is not used. - // - - m_HeapLength = 0; - UInt32 n; // iterate over m_Heap elements - for (n = 0; n < m_NumSymbols; n++) - { - if (m_Items[n].Freq != 0) - { - m_Heap[++m_HeapLength] = maxCode = n; - m_Depth[n] = 0; - } - else - m_Items[n].Len = 0; - } - - // The pkzip format requires that at least one distance code exists, - // and that at least one bit should be sent even if there is only one - // possible code. So to avoid special checks later on we force at least - // two codes of non zero frequency. - while (m_HeapLength < 2) - { - int aNewNode = m_Heap[++m_HeapLength] = (maxCode < 2 ? ++maxCode : 0); - m_Items[aNewNode].Freq = 1; - m_Depth[aNewNode] = 0; - m_BlockBitLength--; - // if (stree) static_len -= stree[aNewNode].Len; - // aNewNode is 0 or 1 so it does not have m_ExtraBits bits - } - - // The elements m_Heap[m_HeapLength/2+1 .. m_HeapLength] are leaves of the m_Items, - // establish sub-heaps of increasing lengths: - for (n = m_HeapLength / 2; n >= 1; n--) - DownHeap(n); - - // Construct the Huffman tree by repeatedly combining the least two - // frequent nodes. - int node = m_NumSymbols; // next internal node of the tree - UInt32 heapMax = m_NumSymbols * 2+ 1; - do - { - n = RemoveSmallest(); /* n = node of least frequency */ - UInt32 m = m_Heap[kSmallest]; /* m = node of next least frequency */ - - m_Heap[--heapMax] = n; /* keep the nodes sorted by frequency */ - m_Heap[--heapMax] = m; - - // Create a new node father of n and m - m_Items[node].Freq = m_Items[n].Freq + m_Items[m].Freq; - m_Depth[node] = (Byte) (MyMax(m_Depth[n], m_Depth[m]) + 1); - m_Items[n].Dad = m_Items[m].Dad = node; - // and insert the new node in the m_Heap - m_Heap[kSmallest] = node++; - DownHeap(kSmallest); - - } - while (m_HeapLength >= 2); - - m_Heap[--heapMax] = m_Heap[kSmallest]; - - // At this point, the fields freq and dad are set. We can now - // generate the bit lengths. - GenerateBitLen(maxCode, heapMax); - - // The field len is now set, we can generate the bit codes - GenerateCodes (maxCode); - - for (n = 0; n < m_NumSymbols; n++) - levels[n] = Byte(m_Items[n].Len); -} - -void CEncoder::ReverseBits() -{ - for (UInt32 symbol = 0; symbol < m_NumSymbols; symbol++) - { - CItem &item = m_Items[symbol]; - UInt32 value = item.Code; - UInt32 reverseValue = 0; - for(UInt32 i = item.Len; i != 0; i--, value >>= 1) - reverseValue = (reverseValue << 1) | (value & 1); - item.Code = reverseValue; - } -} - -}} diff --git a/7zip/Compress/Huffman/HuffmanEncoder.h b/7zip/Compress/Huffman/HuffmanEncoder.h deleted file mode 100755 index 76304a45..00000000 --- a/7zip/Compress/Huffman/HuffmanEncoder.h +++ /dev/null @@ -1,82 +0,0 @@ -// Compression/HuffmanEncoder.h - -#ifndef __COMPRESSION_HUFFMANENCODER_H -#define __COMPRESSION_HUFFMANENCODER_H - -#include "../../../Common/Types.h" - -namespace NCompression { -namespace NHuffman { - -const int kNumBitsInLongestCode = 20; - -struct CItem -{ - UInt32 Freq; - UInt32 Code; - UInt32 Dad; - UInt32 Len; -}; - -class CEncoder -{ -public: - UInt32 m_NumSymbols; // number of symbols in adwSymbol - - CItem *m_Items; - UInt32 *m_Heap; - UInt32 m_HeapSize; - Byte *m_Depth; - const Byte *m_ExtraBits; - UInt32 m_ExtraBase; - UInt32 m_MaxLength; - - UInt32 m_HeapLength; - UInt32 m_BitLenCounters[kNumBitsInLongestCode + 1]; - - UInt32 RemoveSmallest(); - bool Smaller(int n, int m); - void DownHeap(UInt32 k); - void GenerateBitLen(UInt32 maxCode, UInt32 heapMax); - void GenerateCodes(UInt32 maxCode); - - UInt32 m_BlockBitLength; - - void Free(); - -public: - - CEncoder(); - ~CEncoder(); - bool Create(UInt32 numSymbols, const Byte *extraBits, - UInt32 extraBase, UInt32 maxLength); - void StartNewBlock(); - - void AddSymbol(UInt32 symbol) { m_Items[symbol].Freq++; } - - UInt32 GetPrice(const Byte *length) const - { - UInt32 price = 0; - for (UInt32 i = 0; i < m_NumSymbols; i++) - { - price += length[i] * m_Items[i].Freq; - if (m_ExtraBits && i >= m_ExtraBase) - price += m_ExtraBits[i - m_ExtraBase] * m_Items[i].Freq; - } - return price; - }; - void SetFreq(UInt32 symbol, UInt32 value) { m_Items[symbol].Freq = value; }; - - void BuildTree(Byte *levels); - UInt32 GetBlockBitLength() const { return m_BlockBitLength; } - - template - void CodeOneValue(TBitEncoder *bitEncoder, UInt32 symbol) - { bitEncoder->WriteBits(m_Items[symbol].Code, m_Items[symbol].Len); } - - void ReverseBits(); -}; - -}} - -#endif diff --git a/7zip/Compress/LZ/BinTree/BinTree.h b/7zip/Compress/LZ/BinTree/BinTree.h deleted file mode 100755 index b3b3f13a..00000000 --- a/7zip/Compress/LZ/BinTree/BinTree.h +++ /dev/null @@ -1,54 +0,0 @@ -// BinTree.h - -#include "../LZInWindow.h" -#include "../IMatchFinder.h" - -namespace BT_NAMESPACE { - -typedef UInt32 CIndex; -const UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1; - -class CMatchFinder: - public IMatchFinder, - public CLZInWindow, - public CMyUnknownImp, - public IMatchFinderSetNumPasses -{ - UInt32 _cyclicBufferPos; - UInt32 _cyclicBufferSize; // it must be historySize + 1 - UInt32 _matchMaxLen; - CIndex *_hash; - CIndex *_son; - UInt32 _hashMask; - UInt32 _cutValue; - UInt32 _hashSizeSum; - - void Normalize(); - void FreeThisClassMemory(); - void FreeMemory(); - - MY_UNKNOWN_IMP - - STDMETHOD(SetStream)(ISequentialInStream *inStream); - STDMETHOD_(void, ReleaseStream)(); - STDMETHOD(Init)(); - HRESULT MovePos(); - STDMETHOD_(Byte, GetIndexByte)(Int32 index); - STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit); - STDMETHOD_(UInt32, GetNumAvailableBytes)(); - STDMETHOD_(const Byte *, GetPointerToCurrentPos)(); - STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes); - STDMETHOD_(void, ChangeBufferPos)(); - - STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, - UInt32 matchMaxLen, UInt32 keepAddBufferAfter); - STDMETHOD(GetMatches)(UInt32 *distances); - STDMETHOD(Skip)(UInt32 num); - -public: - CMatchFinder(); - virtual ~CMatchFinder(); - virtual void SetNumPasses(UInt32 numPasses) { _cutValue = numPasses; } -}; - -} diff --git a/7zip/Compress/LZ/BinTree/BinTree2.h b/7zip/Compress/LZ/BinTree/BinTree2.h deleted file mode 100755 index 74ca8d9d..00000000 --- a/7zip/Compress/LZ/BinTree/BinTree2.h +++ /dev/null @@ -1,12 +0,0 @@ -// BinTree2.h - -#ifndef __BINTREE2_H -#define __BINTREE2_H - -#define BT_NAMESPACE NBT2 - -#include "BinTreeMain.h" - -#undef BT_NAMESPACE - -#endif diff --git a/7zip/Compress/LZ/BinTree/BinTree3.h b/7zip/Compress/LZ/BinTree/BinTree3.h deleted file mode 100755 index 76bd9ddd..00000000 --- a/7zip/Compress/LZ/BinTree/BinTree3.h +++ /dev/null @@ -1,16 +0,0 @@ -// BinTree3.h - -#ifndef __BINTREE3_H -#define __BINTREE3_H - -#define BT_NAMESPACE NBT3 - -#define HASH_ARRAY_2 - -#include "BinTreeMain.h" - -#undef HASH_ARRAY_2 - -#undef BT_NAMESPACE - -#endif diff --git a/7zip/Compress/LZ/BinTree/BinTree3Z.h b/7zip/Compress/LZ/BinTree/BinTree3Z.h deleted file mode 100755 index d2c092b4..00000000 --- a/7zip/Compress/LZ/BinTree/BinTree3Z.h +++ /dev/null @@ -1,16 +0,0 @@ -// BinTree3Z.h - -#ifndef __BINTREE3Z_H -#define __BINTREE3Z_H - -#define BT_NAMESPACE NBT3Z - -#define HASH_ZIP - -#include "BinTreeMain.h" - -#undef HASH_ZIP - -#undef BT_NAMESPACE - -#endif diff --git a/7zip/Compress/LZ/BinTree/BinTree4.h b/7zip/Compress/LZ/BinTree/BinTree4.h deleted file mode 100755 index 08e2d1ce..00000000 --- a/7zip/Compress/LZ/BinTree/BinTree4.h +++ /dev/null @@ -1,18 +0,0 @@ -// BinTree4.h - -#ifndef __BINTREE4_H -#define __BINTREE4_H - -#define BT_NAMESPACE NBT4 - -#define HASH_ARRAY_2 -#define HASH_ARRAY_3 - -#include "BinTreeMain.h" - -#undef HASH_ARRAY_2 -#undef HASH_ARRAY_3 - -#undef BT_NAMESPACE - -#endif diff --git a/7zip/Compress/LZ/BinTree/BinTreeMain.h b/7zip/Compress/LZ/BinTree/BinTreeMain.h deleted file mode 100755 index ef9f6ce2..00000000 --- a/7zip/Compress/LZ/BinTree/BinTreeMain.h +++ /dev/null @@ -1,531 +0,0 @@ -// BinTreeMain.h - -#include "../../../../Common/Defs.h" -#include "../../../../Common/CRC.h" -#include "../../../../Common/Alloc.h" - -#include "BinTree.h" - -// #include -// It's for prefetch -// But prefetch doesn't give big gain in K8. - -namespace BT_NAMESPACE { - -#ifdef HASH_ARRAY_2 - static const UInt32 kHash2Size = 1 << 10; - #define kNumHashDirectBytes 0 - #ifdef HASH_ARRAY_3 - static const UInt32 kNumHashBytes = 4; - static const UInt32 kHash3Size = 1 << 16; - #else - static const UInt32 kNumHashBytes = 3; - #endif - static const UInt32 kHashSize = 0; - static const UInt32 kMinMatchCheck = kNumHashBytes; - static const UInt32 kStartMaxLen = 1; -#else - #ifdef HASH_ZIP - #define kNumHashDirectBytes 0 - static const UInt32 kNumHashBytes = 3; - static const UInt32 kHashSize = 1 << 16; - static const UInt32 kMinMatchCheck = kNumHashBytes; - static const UInt32 kStartMaxLen = 1; - #else - #define kNumHashDirectBytes 2 - static const UInt32 kNumHashBytes = 2; - static const UInt32 kHashSize = 1 << (8 * kNumHashBytes); - static const UInt32 kMinMatchCheck = kNumHashBytes + 1; - static const UInt32 kStartMaxLen = 1; - #endif -#endif - -#ifdef HASH_ARRAY_2 -#ifdef HASH_ARRAY_3 -static const UInt32 kHash3Offset = kHash2Size; -#endif -#endif - -static const UInt32 kFixHashSize = 0 - #ifdef HASH_ARRAY_2 - + kHash2Size - #ifdef HASH_ARRAY_3 - + kHash3Size - #endif - #endif - ; - -CMatchFinder::CMatchFinder(): - _hash(0) -{ -} - -void CMatchFinder::FreeThisClassMemory() -{ - BigFree(_hash); - _hash = 0; -} - -void CMatchFinder::FreeMemory() -{ - FreeThisClassMemory(); - CLZInWindow::Free(); -} - -CMatchFinder::~CMatchFinder() -{ - FreeMemory(); -} - -STDMETHODIMP CMatchFinder::Create(UInt32 historySize, UInt32 keepAddBufferBefore, - UInt32 matchMaxLen, UInt32 keepAddBufferAfter) -{ - if (historySize > kMaxValForNormalize - 256) - { - FreeMemory(); - return E_INVALIDARG; - } - _cutValue = - #ifdef _HASH_CHAIN - 8 + (matchMaxLen >> 2); - #else - 16 + (matchMaxLen >> 1); - #endif - UInt32 sizeReserv = (historySize + keepAddBufferBefore + - matchMaxLen + keepAddBufferAfter) / 2 + 256; - if (CLZInWindow::Create(historySize + keepAddBufferBefore, - matchMaxLen + keepAddBufferAfter, sizeReserv)) - { - _matchMaxLen = matchMaxLen; - UInt32 newCyclicBufferSize = historySize + 1; - if (_hash != 0 && newCyclicBufferSize == _cyclicBufferSize) - return S_OK; - FreeThisClassMemory(); - _cyclicBufferSize = newCyclicBufferSize; // don't change it - - UInt32 hs = kHashSize; - - #ifdef HASH_ARRAY_2 - hs = historySize - 1; - hs |= (hs >> 1); - hs |= (hs >> 2); - hs |= (hs >> 4); - hs |= (hs >> 8); - hs >>= 1; - hs |= 0xFFFF; - if (hs > (1 << 24)) - { - #ifdef HASH_ARRAY_3 - hs >>= 1; - #else - hs = (1 << 24) - 1; - #endif - } - _hashMask = hs; - hs++; - #endif - _hashSizeSum = hs + kFixHashSize; - UInt32 numItems = _hashSizeSum + _cyclicBufferSize - #ifndef _HASH_CHAIN - * 2 - #endif - ; - size_t sizeInBytes = (size_t)numItems * sizeof(CIndex); - if (sizeInBytes / sizeof(CIndex) != numItems) - return E_OUTOFMEMORY; - _hash = (CIndex *)BigAlloc(sizeInBytes); - _son = _hash + _hashSizeSum; - if (_hash != 0) - return S_OK; - } - FreeMemory(); - return E_OUTOFMEMORY; -} - -static const UInt32 kEmptyHashValue = 0; - -STDMETHODIMP CMatchFinder::SetStream(ISequentialInStream *stream) -{ - CLZInWindow::SetStream(stream); - return S_OK; -} - -STDMETHODIMP CMatchFinder::Init() -{ - RINOK(CLZInWindow::Init()); - for(UInt32 i = 0; i < _hashSizeSum; i++) - _hash[i] = kEmptyHashValue; - _cyclicBufferPos = 0; - ReduceOffsets(-1); - return S_OK; -} - -STDMETHODIMP_(void) CMatchFinder::ReleaseStream() -{ - // ReleaseStream(); -} - -#ifdef HASH_ARRAY_2 -#ifdef HASH_ARRAY_3 - -#define HASH_CALC { \ - UInt32 temp = CCRC::Table[cur[0]] ^ cur[1]; \ - hash2Value = temp & (kHash2Size - 1); \ - hash3Value = (temp ^ (UInt32(cur[2]) << 8)) & (kHash3Size - 1); \ - hashValue = (temp ^ (UInt32(cur[2]) << 8) ^ (CCRC::Table[cur[3]] << 5)) & _hashMask; } - -#else // no HASH_ARRAY_3 -#define HASH_CALC { \ - UInt32 temp = CCRC::Table[cur[0]] ^ cur[1]; \ - hash2Value = temp & (kHash2Size - 1); \ - hashValue = (temp ^ (UInt32(cur[2]) << 8)) & _hashMask; } -#endif // HASH_ARRAY_3 -#else // no HASH_ARRAY_2 -#ifdef HASH_ZIP -inline UInt32 Hash(const Byte *pointer) -{ - return ((UInt32(pointer[0]) << 8) ^ CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1); -} -#else // no HASH_ZIP -inline UInt32 Hash(const Byte *pointer) -{ - return pointer[0] ^ (UInt32(pointer[1]) << 8); -} -#endif // HASH_ZIP -#endif // HASH_ARRAY_2 - -STDMETHODIMP CMatchFinder::GetMatches(UInt32 *distances) -{ - UInt32 lenLimit; - if (_pos + _matchMaxLen <= _streamPos) - lenLimit = _matchMaxLen; - else - { - lenLimit = _streamPos - _pos; - if(lenLimit < kMinMatchCheck) - { - distances[0] = 0; - return MovePos(); - } - } - - int offset = 1; - - UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0; - const Byte *cur = _buffer + _pos; - - UInt32 maxLen = kStartMaxLen; // to avoid items for len < hashSize; - - #ifdef HASH_ARRAY_2 - UInt32 hash2Value; - #ifdef HASH_ARRAY_3 - UInt32 hash3Value; - #endif - UInt32 hashValue; - HASH_CALC; - #else - UInt32 hashValue = Hash(cur); - #endif - - UInt32 curMatch = _hash[kFixHashSize + hashValue]; - #ifdef HASH_ARRAY_2 - UInt32 curMatch2 = _hash[hash2Value]; - #ifdef HASH_ARRAY_3 - UInt32 curMatch3 = _hash[kHash3Offset + hash3Value]; - #endif - _hash[hash2Value] = _pos; - if(curMatch2 > matchMinPos) - if (_buffer[curMatch2] == cur[0]) - { - distances[offset++] = maxLen = 2; - distances[offset++] = _pos - curMatch2 - 1; - } - - #ifdef HASH_ARRAY_3 - _hash[kHash3Offset + hash3Value] = _pos; - if(curMatch3 > matchMinPos) - if (_buffer[curMatch3] == cur[0]) - { - if (curMatch3 == curMatch2) - offset -= 2; - distances[offset++] = maxLen = 3; - distances[offset++] = _pos - curMatch3 - 1; - curMatch2 = curMatch3; - } - #endif - if (offset != 1 && curMatch2 == curMatch) - { - offset -= 2; - maxLen = kStartMaxLen; - } - #endif - - _hash[kFixHashSize + hashValue] = _pos; - - CIndex *son = _son; - - #ifdef _HASH_CHAIN - son[_cyclicBufferPos] = curMatch; - #else - CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1; - CIndex *ptr1 = son + (_cyclicBufferPos << 1); - - UInt32 len0, len1; - len0 = len1 = kNumHashDirectBytes; - #endif - - #if kNumHashDirectBytes != 0 - if(curMatch > matchMinPos) - { - if (_buffer[curMatch + kNumHashDirectBytes] != cur[kNumHashDirectBytes]) - { - distances[offset++] = maxLen = kNumHashDirectBytes; - distances[offset++] = _pos - curMatch - 1; - } - } - #endif - UInt32 count = _cutValue; - for (;;) - { - if(curMatch <= matchMinPos || count-- == 0) - { - #ifndef _HASH_CHAIN - *ptr0 = *ptr1 = kEmptyHashValue; - #endif - break; - } - UInt32 delta = _pos - curMatch; - UInt32 cyclicPos = (delta <= _cyclicBufferPos) ? - (_cyclicBufferPos - delta): - (_cyclicBufferPos - delta + _cyclicBufferSize); - CIndex *pair = son + - #ifdef _HASH_CHAIN - cyclicPos; - #else - (cyclicPos << 1); - #endif - - // _mm_prefetch((const char *)pair, _MM_HINT_T0); - - const Byte *pb = _buffer + curMatch; - UInt32 len = - #ifdef _HASH_CHAIN - kNumHashDirectBytes; - if (pb[maxLen] == cur[maxLen]) - #else - MyMin(len0, len1); - #endif - if (pb[len] == cur[len]) - { - while(++len != lenLimit) - if (pb[len] != cur[len]) - break; - if (maxLen < len) - { - distances[offset++] = maxLen = len; - distances[offset++] = delta - 1; - if (len == lenLimit) - { - #ifndef _HASH_CHAIN - *ptr1 = pair[0]; - *ptr0 = pair[1]; - #endif - break; - } - } - } - #ifdef _HASH_CHAIN - curMatch = *pair; - #else - if (pb[len] < cur[len]) - { - *ptr1 = curMatch; - ptr1 = pair + 1; - curMatch = *ptr1; - len1 = len; - } - else - { - *ptr0 = curMatch; - ptr0 = pair; - curMatch = *ptr0; - len0 = len; - } - #endif - } - distances[0] = offset - 1; - if (++_cyclicBufferPos == _cyclicBufferSize) - _cyclicBufferPos = 0; - RINOK(CLZInWindow::MovePos()); - if (_pos == kMaxValForNormalize) - Normalize(); - return S_OK; -} - -STDMETHODIMP CMatchFinder::Skip(UInt32 num) -{ - do - { - #ifdef _HASH_CHAIN - if (_streamPos - _pos < kNumHashBytes) - { - RINOK(MovePos()); - continue; - } - #else - UInt32 lenLimit; - if (_pos + _matchMaxLen <= _streamPos) - lenLimit = _matchMaxLen; - else - { - lenLimit = _streamPos - _pos; - if(lenLimit < kMinMatchCheck) - { - RINOK(MovePos()); - continue; - } - } - UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0; - #endif - const Byte *cur = _buffer + _pos; - - #ifdef HASH_ARRAY_2 - UInt32 hash2Value; - #ifdef HASH_ARRAY_3 - UInt32 hash3Value; - UInt32 hashValue; - HASH_CALC; - _hash[kHash3Offset + hash3Value] = _pos; - #else - UInt32 hashValue; - HASH_CALC; - #endif - _hash[hash2Value] = _pos; - #else - UInt32 hashValue = Hash(cur); - #endif - - UInt32 curMatch = _hash[kFixHashSize + hashValue]; - _hash[kFixHashSize + hashValue] = _pos; - - #ifdef _HASH_CHAIN - _son[_cyclicBufferPos] = curMatch; - #else - CIndex *son = _son; - CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1; - CIndex *ptr1 = son + (_cyclicBufferPos << 1); - - UInt32 len0, len1; - len0 = len1 = kNumHashDirectBytes; - UInt32 count = _cutValue; - for (;;) - { - if(curMatch <= matchMinPos || count-- == 0) - { - *ptr0 = *ptr1 = kEmptyHashValue; - break; - } - - UInt32 delta = _pos - curMatch; - UInt32 cyclicPos = (delta <= _cyclicBufferPos) ? - (_cyclicBufferPos - delta): - (_cyclicBufferPos - delta + _cyclicBufferSize); - CIndex *pair = son + (cyclicPos << 1); - - // _mm_prefetch((const char *)pair, _MM_HINT_T0); - - const Byte *pb = _buffer + curMatch; - UInt32 len = MyMin(len0, len1); - - if (pb[len] == cur[len]) - { - while(++len != lenLimit) - if (pb[len] != cur[len]) - break; - if (len == lenLimit) - { - *ptr1 = pair[0]; - *ptr0 = pair[1]; - break; - } - } - if (pb[len] < cur[len]) - { - *ptr1 = curMatch; - ptr1 = pair + 1; - curMatch = *ptr1; - len1 = len; - } - else - { - *ptr0 = curMatch; - ptr0 = pair; - curMatch = *ptr0; - len0 = len; - } - } - #endif - if (++_cyclicBufferPos == _cyclicBufferSize) - _cyclicBufferPos = 0; - RINOK(CLZInWindow::MovePos()); - if (_pos == kMaxValForNormalize) - Normalize(); - } - while(--num != 0); - return S_OK; -} - -void CMatchFinder::Normalize() -{ - UInt32 subValue = _pos - _cyclicBufferSize; - CIndex *items = _hash; - UInt32 numItems = (_hashSizeSum + _cyclicBufferSize - #ifndef _HASH_CHAIN - * 2 - #endif - ); - for (UInt32 i = 0; i < numItems; i++) - { - UInt32 value = items[i]; - if (value <= subValue) - value = kEmptyHashValue; - else - value -= subValue; - items[i] = value; - } - ReduceOffsets(subValue); -} - -HRESULT CMatchFinder::MovePos() -{ - if (++_cyclicBufferPos == _cyclicBufferSize) - _cyclicBufferPos = 0; - RINOK(CLZInWindow::MovePos()); - if (_pos == kMaxValForNormalize) - Normalize(); - return S_OK; -} - -STDMETHODIMP_(Byte) CMatchFinder::GetIndexByte(Int32 index) - { return CLZInWindow::GetIndexByte(index); } - -STDMETHODIMP_(UInt32) CMatchFinder::GetMatchLen(Int32 index, - UInt32 back, UInt32 limit) - { return CLZInWindow::GetMatchLen(index, back, limit); } - -STDMETHODIMP_(UInt32) CMatchFinder::GetNumAvailableBytes() - { return CLZInWindow::GetNumAvailableBytes(); } - -STDMETHODIMP_(const Byte *) CMatchFinder::GetPointerToCurrentPos() - { return CLZInWindow::GetPointerToCurrentPos(); } - -STDMETHODIMP_(Int32) CMatchFinder::NeedChangeBufferPos(UInt32 numCheckBytes) - { return CLZInWindow::NeedMove(numCheckBytes) ? 1: 0; } - -STDMETHODIMP_(void) CMatchFinder::ChangeBufferPos() - { CLZInWindow::MoveBlock();} - -#undef HASH_CALC -#undef kNumHashDirectBytes - -} diff --git a/7zip/Compress/LZ/HashChain/HC2.h b/7zip/Compress/LZ/HashChain/HC2.h deleted file mode 100755 index d8e61a74..00000000 --- a/7zip/Compress/LZ/HashChain/HC2.h +++ /dev/null @@ -1,13 +0,0 @@ -// HC2.h - -#ifndef __HC2_H -#define __HC2_H - -#define BT_NAMESPACE NHC2 - -#include "HCMain.h" - -#undef BT_NAMESPACE - -#endif - diff --git a/7zip/Compress/LZ/HashChain/HC3.h b/7zip/Compress/LZ/HashChain/HC3.h deleted file mode 100755 index 263690af..00000000 --- a/7zip/Compress/LZ/HashChain/HC3.h +++ /dev/null @@ -1,16 +0,0 @@ -// HC3.h - -#ifndef __HC3_H -#define __HC3_H - -#define BT_NAMESPACE NHC3 - -#define HASH_ARRAY_2 - -#include "HCMain.h" - -#undef HASH_ARRAY_2 -#undef BT_NAMESPACE - -#endif - diff --git a/7zip/Compress/LZ/HashChain/HC4.h b/7zip/Compress/LZ/HashChain/HC4.h deleted file mode 100755 index 1fda4ac6..00000000 --- a/7zip/Compress/LZ/HashChain/HC4.h +++ /dev/null @@ -1,19 +0,0 @@ -// HC4.h - -#ifndef __HC4_H -#define __HC4_H - -#define BT_NAMESPACE NHC4 - -#define HASH_ARRAY_2 -#define HASH_ARRAY_3 - -#include "HCMain.h" - -#undef HASH_ARRAY_2 -#undef HASH_ARRAY_3 - -#undef BT_NAMESPACE - -#endif - diff --git a/7zip/Compress/LZ/HashChain/HCMain.h b/7zip/Compress/LZ/HashChain/HCMain.h deleted file mode 100755 index d509befe..00000000 --- a/7zip/Compress/LZ/HashChain/HCMain.h +++ /dev/null @@ -1,6 +0,0 @@ -// HCMain.h - -#define _HASH_CHAIN -#include "../BinTree/BinTreeMain.h" -#undef _HASH_CHAIN - diff --git a/7zip/Compress/LZ/IMatchFinder.h b/7zip/Compress/LZ/IMatchFinder.h deleted file mode 100755 index 528b7b1c..00000000 --- a/7zip/Compress/LZ/IMatchFinder.h +++ /dev/null @@ -1,32 +0,0 @@ -// MatchFinders/IMatchFinder.h - -#ifndef __IMATCHFINDER_H -#define __IMATCHFINDER_H - -struct IInWindowStream: public IUnknown -{ - STDMETHOD(SetStream)(ISequentialInStream *inStream) PURE; - STDMETHOD_(void, ReleaseStream)() PURE; - STDMETHOD(Init)() PURE; - STDMETHOD_(Byte, GetIndexByte)(Int32 index) PURE; - STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit) PURE; - STDMETHOD_(UInt32, GetNumAvailableBytes)() PURE; - STDMETHOD_(const Byte *, GetPointerToCurrentPos)() PURE; - STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes) PURE; - STDMETHOD_(void, ChangeBufferPos)() PURE; -}; - -struct IMatchFinder: public IInWindowStream -{ - STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, - UInt32 matchMaxLen, UInt32 keepAddBufferAfter) PURE; - STDMETHOD(GetMatches)(UInt32 *distances) PURE; - STDMETHOD(Skip)(UInt32 num) PURE; -}; - -struct IMatchFinderSetNumPasses -{ - virtual void SetNumPasses(UInt32 numPasses) PURE; -}; - -#endif diff --git a/7zip/Compress/LZ/LZInWindow.cpp b/7zip/Compress/LZ/LZInWindow.cpp deleted file mode 100755 index aacaea9d..00000000 --- a/7zip/Compress/LZ/LZInWindow.cpp +++ /dev/null @@ -1,105 +0,0 @@ -// LZInWindow.cpp - -#include "StdAfx.h" - -#include "LZInWindow.h" -#include "../../../Common/MyCom.h" -#include "../../../Common/Alloc.h" - -void CLZInWindow::Free() -{ - ::BigFree(_bufferBase); - _bufferBase = 0; -} - -bool CLZInWindow::Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv) -{ - _keepSizeBefore = keepSizeBefore; - _keepSizeAfter = keepSizeAfter; - UInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv; - if (_bufferBase == 0 || _blockSize != blockSize) - { - Free(); - _blockSize = blockSize; - if (_blockSize != 0) - _bufferBase = (Byte *)::BigAlloc(_blockSize); - } - _pointerToLastSafePosition = _bufferBase + _blockSize - keepSizeAfter; - if (_blockSize == 0) - return true; - return (_bufferBase != 0); -} - -void CLZInWindow::SetStream(ISequentialInStream *stream) -{ - _stream = stream; -} - -HRESULT CLZInWindow::Init() -{ - _buffer = _bufferBase; - _pos = 0; - _streamPos = 0; - _streamEndWasReached = false; - return ReadBlock(); -} - -/* -void CLZInWindow::ReleaseStream() -{ - _stream.Release(); -} -*/ - -/////////////////////////////////////////// -// ReadBlock - -// In State: -// (_buffer + _streamPos) <= (_bufferBase + _blockSize) -// Out State: -// _posLimit <= _blockSize - _keepSizeAfter; -// if(_streamEndWasReached == false): -// _streamPos >= _pos + _keepSizeAfter -// _posLimit = _streamPos - _keepSizeAfter; -// else -// - -HRESULT CLZInWindow::ReadBlock() -{ - if(_streamEndWasReached) - return S_OK; - for (;;) - { - UInt32 size = (UInt32)(_bufferBase - _buffer) + _blockSize - _streamPos; - if(size == 0) - return S_OK; - UInt32 numReadBytes; - RINOK(_stream->Read(_buffer + _streamPos, size, &numReadBytes)); - if(numReadBytes == 0) - { - _posLimit = _streamPos; - const Byte *pointerToPostion = _buffer + _posLimit; - if(pointerToPostion > _pointerToLastSafePosition) - _posLimit = (UInt32)(_pointerToLastSafePosition - _buffer); - _streamEndWasReached = true; - return S_OK; - } - _streamPos += numReadBytes; - if(_streamPos >= _pos + _keepSizeAfter) - { - _posLimit = _streamPos - _keepSizeAfter; - return S_OK; - } - } -} - -void CLZInWindow::MoveBlock() -{ - UInt32 offset = (UInt32)(_buffer - _bufferBase) + _pos - _keepSizeBefore; - // we need one additional byte, since MovePos moves on 1 byte. - if (offset > 0) - offset--; - UInt32 numBytes = (UInt32)(_buffer - _bufferBase) + _streamPos - offset; - memmove(_bufferBase, _bufferBase + offset, numBytes); - _buffer -= offset; -} diff --git a/7zip/Compress/LZ/LZInWindow.h b/7zip/Compress/LZ/LZInWindow.h deleted file mode 100755 index 20e0331b..00000000 --- a/7zip/Compress/LZ/LZInWindow.h +++ /dev/null @@ -1,87 +0,0 @@ -// LZInWindow.h - -#ifndef __LZ_IN_WINDOW_H -#define __LZ_IN_WINDOW_H - -#include "../../IStream.h" - -class CLZInWindow -{ - Byte *_bufferBase; // pointer to buffer with data - ISequentialInStream *_stream; - UInt32 _posLimit; // offset (from _buffer) when new block reading must be done - bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream - const Byte *_pointerToLastSafePosition; -protected: - Byte *_buffer; // Pointer to virtual Buffer begin - UInt32 _blockSize; // Size of Allocated memory block - UInt32 _pos; // offset (from _buffer) of curent byte - UInt32 _keepSizeBefore; // how many BYTEs must be kept in buffer before _pos - UInt32 _keepSizeAfter; // how many BYTEs must be kept buffer after _pos - UInt32 _streamPos; // offset (from _buffer) of first not read byte from Stream - - void MoveBlock(); - HRESULT ReadBlock(); - void Free(); -public: - CLZInWindow(): _bufferBase(0) {} - virtual ~CLZInWindow() { Free(); } - - // keepSizeBefore + keepSizeAfter + keepSizeReserv < 4G) - bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv = (1<<17)); - - void SetStream(ISequentialInStream *stream); - HRESULT Init(); - // void ReleaseStream(); - - Byte *GetBuffer() const { return _buffer; } - - const Byte *GetPointerToCurrentPos() const { return _buffer + _pos; } - - HRESULT MovePos() - { - _pos++; - if (_pos > _posLimit) - { - const Byte *pointerToPostion = _buffer + _pos; - if(pointerToPostion > _pointerToLastSafePosition) - MoveBlock(); - return ReadBlock(); - } - else - return S_OK; - } - Byte GetIndexByte(Int32 index) const { return _buffer[(size_t)_pos + index]; } - - // index + limit have not to exceed _keepSizeAfter; - // -2G <= index < 2G - UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) const - { - if(_streamEndWasReached) - if ((_pos + index) + limit > _streamPos) - limit = _streamPos - (_pos + index); - distance++; - const Byte *pby = _buffer + (size_t)_pos + index; - UInt32 i; - for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++); - return i; - } - - UInt32 GetNumAvailableBytes() const { return _streamPos - _pos; } - - void ReduceOffsets(Int32 subValue) - { - _buffer += subValue; - _posLimit -= subValue; - _pos -= subValue; - _streamPos -= subValue; - } - - bool NeedMove(UInt32 numCheckBytes) - { - size_t reserv = (size_t)(_pointerToLastSafePosition - (_buffer + _pos)); - return (reserv <= numCheckBytes); - } -}; - -#endif diff --git a/7zip/Compress/LZ/MT/MT.cpp b/7zip/Compress/LZ/MT/MT.cpp deleted file mode 100755 index b0ac456d..00000000 --- a/7zip/Compress/LZ/MT/MT.cpp +++ /dev/null @@ -1,295 +0,0 @@ -// MT.cpp - -#include "StdAfx.h" - -#include "../../../../Common/Alloc.h" - -#include "MT.h" - -static const UInt32 kBlockSize = (1 << 14); - -static DWORD WINAPI MFThread(void *threadCoderInfo) -{ - return ((CMatchFinderMT *)threadCoderInfo)->ThreadFunc(); -} - -CMatchFinderMT::CMatchFinderMT(): - m_Buffer(0), - m_NeedStart(true) -{ - m_BlockIndex = kNumMTBlocks - 1; - m_CS[m_BlockIndex].Enter(); - if (!m_Thread.Create(MFThread, this)) - throw 271826; -} - -CMatchFinderMT::~CMatchFinderMT() -{ - m_Exit = true; - m_CS[m_BlockIndex].Leave(); - m_CanChangeBufferPos.Set(); - if (m_NeedStart) - m_MtCanStart.Set(); - m_Thread.Wait(); - FreeMem(); -} - -void CMatchFinderMT::FreeMem() -{ - ::MyFree(m_Buffer); - m_Buffer = 0; -} - -STDMETHODIMP CMatchFinderMT::Create(UInt32 sizeHistory, UInt32 keepAddBufferBefore, - UInt32 matchMaxLen, UInt32 keepAddBufferAfter) -{ - FreeMem(); - m_MatchMaxLen = matchMaxLen; - if (kBlockSize <= matchMaxLen * 4) - return E_INVALIDARG; - UInt32 bufferSize = kBlockSize * kNumMTBlocks; - m_Buffer = (UInt32 *)::MyAlloc(bufferSize * sizeof(UInt32)); - if (m_Buffer == 0) - return E_OUTOFMEMORY; - keepAddBufferBefore += bufferSize; - keepAddBufferAfter += (kBlockSize + 1); - return m_MatchFinder->Create(sizeHistory, keepAddBufferBefore, matchMaxLen, keepAddBufferAfter); -} - -// UInt32 blockSizeMult = 800 -HRESULT CMatchFinderMT::SetMatchFinder(IMatchFinder *matchFinder) -{ - m_MatchFinder = matchFinder; - return S_OK; -} - -STDMETHODIMP CMatchFinderMT::SetStream(ISequentialInStream *s) -{ - return m_MatchFinder->SetStream(s); -} - -// Call it after ReleaseStream / SetStream -STDMETHODIMP CMatchFinderMT::Init() -{ - m_NeedStart = true; - m_Pos = 0; - m_PosLimit = 0; - - HRESULT result = m_MatchFinder->Init(); - if (result == S_OK) - m_DataCurrentPos = m_MatchFinder->GetPointerToCurrentPos(); - m_NumAvailableBytes = m_MatchFinder->GetNumAvailableBytes(); - return result; -} - -// ReleaseStream is required to finish multithreading -STDMETHODIMP_(void) CMatchFinderMT::ReleaseStream() -{ - m_StopWriting = true; - m_CS[m_BlockIndex].Leave(); - if (!m_NeedStart) - { - m_CanChangeBufferPos.Set(); - m_MtWasStopped.Lock(); - m_NeedStart = true; - } - m_MatchFinder->ReleaseStream(); - m_BlockIndex = kNumMTBlocks - 1; - m_CS[m_BlockIndex].Enter(); -} - -STDMETHODIMP_(Byte) CMatchFinderMT::GetIndexByte(Int32 index) -{ - return m_DataCurrentPos[index]; -} - -STDMETHODIMP_(UInt32) CMatchFinderMT::GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) -{ - if ((Int32)(index + limit) > m_NumAvailableBytes) - limit = m_NumAvailableBytes - (index); - distance++; - const Byte *pby = m_DataCurrentPos + index; - UInt32 i; - for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++); - return i; -} - -STDMETHODIMP_(const Byte *) CMatchFinderMT::GetPointerToCurrentPos() -{ - return m_DataCurrentPos; -} - -STDMETHODIMP_(UInt32) CMatchFinderMT::GetNumAvailableBytes() -{ - return m_NumAvailableBytes; -} - -void CMatchFinderMT::GetNextBlock() -{ - if (m_NeedStart) - { - m_NeedStart = false; - for (UInt32 i = 0; i < kNumMTBlocks; i++) - m_StopReading[i] = false; - m_StopWriting = false; - m_Exit = false; - m_MtWasStarted.Reset(); - m_MtWasStopped.Reset(); - m_CanChangeBufferPos.Reset(); - m_BufferPosWasChanged.Reset(); - m_MtCanStart.Set(); - m_MtWasStarted.Lock(); - m_Result = S_OK; - } - for (;;) - { - UInt32 nextIndex = (m_BlockIndex == kNumMTBlocks - 1) ? 0 : m_BlockIndex + 1; - m_CS[nextIndex].Enter(); - if (!m_StopReading[nextIndex]) - { - m_CS[m_BlockIndex].Leave(); - m_BlockIndex = nextIndex; - break; - } - m_StopReading[nextIndex] = false; - m_CS[nextIndex].Leave(); - m_CanChangeBufferPos.Set(); - m_BufferPosWasChanged.Lock(); - m_CS[nextIndex].Enter(); - m_CS[m_BlockIndex].Leave(); - m_BlockIndex = nextIndex; - } - m_Pos = m_BlockIndex * kBlockSize; - m_PosLimit = m_Buffer[m_Pos++]; - m_NumAvailableBytes = m_Buffer[m_Pos++]; - m_Result = m_Results[m_BlockIndex]; -} - -STDMETHODIMP CMatchFinderMT::GetMatches(UInt32 *distances) -{ - if (m_Pos == m_PosLimit) - GetNextBlock(); - - if (m_Result != S_OK) - return m_Result; - m_NumAvailableBytes--; - m_DataCurrentPos++; - - const UInt32 *buffer = m_Buffer + m_Pos; - UInt32 len = *buffer++; - *distances++ = len; - m_Pos += 1 + len; - for (UInt32 i = 0; i != len; i += 2) - { - distances[i] = buffer[i]; - distances[i + 1] = buffer[i + 1]; - } - return S_OK; -} - -STDMETHODIMP CMatchFinderMT::Skip(UInt32 num) -{ - do - { - if (m_Pos == m_PosLimit) - GetNextBlock(); - - if (m_Result != S_OK) - return m_Result; - m_NumAvailableBytes--; - m_DataCurrentPos++; - - UInt32 len = m_Buffer[m_Pos++]; - m_Pos += len; - } - while(--num != 0); - return S_OK; -} - -STDMETHODIMP_(Int32) CMatchFinderMT::NeedChangeBufferPos(UInt32 /* numCheckBytes */) -{ - throw 1; -} - -STDMETHODIMP_(void) CMatchFinderMT::ChangeBufferPos() -{ - throw 1; -} - - -DWORD CMatchFinderMT::ThreadFunc() -{ - for (;;) - { - bool needStartEvent = true; - m_MtCanStart.Lock(); - HRESULT result = S_OK; - UInt32 blockIndex = 0; - for (;;) - { - m_CS[blockIndex].Enter(); - if (needStartEvent) - { - m_MtWasStarted.Set(); - needStartEvent = false; - } - else - m_CS[(blockIndex == 0) ? kNumMTBlocks - 1 : blockIndex - 1].Leave(); - if (m_Exit) - return 0; - if (m_StopWriting) - { - m_MtWasStopped.Set(); - m_CS[blockIndex].Leave(); - break; - } - if (result == S_OK) - { - IMatchFinder *mf = m_MatchFinder; - if (mf->NeedChangeBufferPos(kBlockSize) != 0) - { - // m_AskChangeBufferPos.Set(); - m_StopReading[blockIndex] = true; - m_CS[blockIndex].Leave(); - m_CanChangeBufferPos.Lock(); - m_CS[blockIndex].Enter(); - const Byte *bufferPosBefore = mf->GetPointerToCurrentPos(); - mf->ChangeBufferPos(); - m_DataCurrentPos += mf->GetPointerToCurrentPos() - bufferPosBefore; - m_BufferPosWasChanged.Set(); - } - else - { - UInt32 curPos = blockIndex * kBlockSize; - UInt32 limit = curPos + kBlockSize - m_MatchMaxLen - m_MatchMaxLen - 1; - UInt32 *buffer = m_Buffer; - m_Results[blockIndex] = S_OK; - curPos++; - UInt32 numAvailableBytes = mf->GetNumAvailableBytes(); - buffer[curPos++] = numAvailableBytes; - - while (numAvailableBytes-- != 0 && curPos < limit) - { - result = mf->GetMatches(buffer + curPos); - if (result != S_OK) - { - m_Results[blockIndex] = result; - break; - } - curPos += buffer[curPos] + 1; - } - buffer[blockIndex * kBlockSize] = curPos; - } - } - else - { - UInt32 curPos = blockIndex * kBlockSize; - m_Buffer[curPos] = curPos + 2; // size of buffer - m_Buffer[curPos + 1] = 0; // NumAvailableBytes - m_Results[blockIndex] = result; // error - } - if (++blockIndex == kNumMTBlocks) - blockIndex = 0; - } - } -} diff --git a/7zip/Compress/LZ/MT/MT.h b/7zip/Compress/LZ/MT/MT.h deleted file mode 100755 index 1ba7b7c9..00000000 --- a/7zip/Compress/LZ/MT/MT.h +++ /dev/null @@ -1,79 +0,0 @@ -// LZ/MT.h - -#ifndef __LZ_MT_H -#define __LZ_MT_H - -#include "../../../../Common/MyCom.h" - -#include "../../../../Windows/Thread.h" -#include "../../../../Windows/Synchronization.h" - -#include "../../../ICoder.h" -#include "../IMatchFinder.h" - -const UInt32 kNumMTBlocks = (1 << 6); - -class CMatchFinderMT: - public IMatchFinder, - public CMyUnknownImp -{ - MY_UNKNOWN_IMP - - STDMETHOD(SetStream)(ISequentialInStream *inStream); - STDMETHOD_(void, ReleaseStream)(); - STDMETHOD(Init)(); - STDMETHOD_(Byte, GetIndexByte)(Int32 index); - STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit); - STDMETHOD_(UInt32, GetNumAvailableBytes)(); - STDMETHOD_(const Byte *, GetPointerToCurrentPos)(); - STDMETHOD(Create)(UInt32 sizeHistory, UInt32 keepAddBufferBefore, - UInt32 matchMaxLen, UInt32 keepAddBufferAfter); - STDMETHOD(GetMatches)(UInt32 *distances); - STDMETHOD(Skip)(UInt32 num); - - STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes); - STDMETHOD_(void, ChangeBufferPos)(); - - UInt32 m_Pos; - UInt32 m_PosLimit; - UInt32 m_MatchMaxLen; - - UInt32 *m_Buffer; - - bool m_NeedStart; - UInt32 m_BlockIndex; - HRESULT m_Result; - UInt32 m_NumAvailableBytes; - const Byte *m_DataCurrentPos; - - // Common variables - - CMyComPtr m_MatchFinder; - NWindows::CThread m_Thread; - NWindows::NSynchronization::CAutoResetEvent m_MtCanStart; - NWindows::NSynchronization::CAutoResetEvent m_MtWasStarted; - NWindows::NSynchronization::CAutoResetEvent m_MtWasStopped; - NWindows::NSynchronization::CAutoResetEvent m_CanChangeBufferPos; - NWindows::NSynchronization::CAutoResetEvent m_BufferPosWasChanged; - - NWindows::NSynchronization::CCriticalSection m_CS[kNumMTBlocks]; - - HRESULT m_Results[kNumMTBlocks]; - bool m_StopReading[kNumMTBlocks]; - bool m_Exit; - bool m_StopWriting; - - //////////////////////////// - - void FreeMem(); - void GetNextBlock(); -public: - - DWORD ThreadFunc(); - - CMatchFinderMT(); - ~CMatchFinderMT(); - HRESULT SetMatchFinder(IMatchFinder *matchFinder); -}; - -#endif diff --git a/7zip/Compress/LZ/MT/StdAfx.h b/7zip/Compress/LZ/MT/StdAfx.h deleted file mode 100755 index a2f1e97b..00000000 --- a/7zip/Compress/LZ/MT/StdAfx.h +++ /dev/null @@ -1,8 +0,0 @@ -// StdAfx.h - -#ifndef __STDAFX_H -#define __STDAFX_H - -#include "../../../../Common/MyWindows.h" - -#endif diff --git a/7zip/Compress/Rar20/DllExports.cpp b/7zip/Compress/Rar20/DllExports.cpp deleted file mode 100755 index 599d71c3..00000000 --- a/7zip/Compress/Rar20/DllExports.cpp +++ /dev/null @@ -1,66 +0,0 @@ -// DLLExports.cpp - -#include "StdAfx.h" - -#include "Common/MyInitGuid.h" -#include "Common/ComTry.h" - -#include "Rar20Decoder.h" - -// {23170F69-40C1-278B-0403-020000000000} -DEFINE_GUID(CLSID_CCompressRar20Decoder, -0x23170F69, 0x40C1, 0x278B, 0x04, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00); - -extern "C" -BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/) -{ - return TRUE; -} - -STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject) -{ - COM_TRY_BEGIN - *outObject = 0; - if (*clsid != CLSID_CCompressRar20Decoder) - return CLASS_E_CLASSNOTAVAILABLE; - if (*iid != IID_ICompressCoder) - return E_NOINTERFACE; - CMyComPtr coder = (ICompressCoder *)new - NCompress::NRar20::CDecoder; - *outObject = coder.Detach(); - COM_TRY_END - return S_OK; -} - -STDAPI GetNumberOfMethods(UINT32 *numMethods) -{ - *numMethods = 1; - return S_OK; -} - -STDAPI GetMethodProperty(UINT32 index, PROPID propID, PROPVARIANT *value) -{ - if (index != 0) - return E_INVALIDARG; - ::VariantClear((tagVARIANT *)value); - switch(propID) - { - case NMethodPropID::kID: - { - const char id[] = { 0x04, 0x03, 0x02 }; - if ((value->bstrVal = ::SysAllocStringByteLen(id, sizeof(id))) != 0) - value->vt = VT_BSTR; - return S_OK; - } - case NMethodPropID::kName: - if ((value->bstrVal = ::SysAllocString(L"Rar20")) != 0) - value->vt = VT_BSTR; - return S_OK; - case NMethodPropID::kDecoder: - if ((value->bstrVal = ::SysAllocStringByteLen( - (const char *)&CLSID_CCompressRar20Decoder, sizeof(GUID))) != 0) - value->vt = VT_BSTR; - return S_OK; - } - return S_OK; -} diff --git a/7zip/Compress/Rar20/Rar20Const.h b/7zip/Compress/Rar20/Rar20Const.h deleted file mode 100755 index 6c5fecb6..00000000 --- a/7zip/Compress/Rar20/Rar20Const.h +++ /dev/null @@ -1,65 +0,0 @@ -// Rar20CoderConst.h -// According to unRAR license, -// this code may not be used to develop a -// RAR (WinRAR) compatible archiver - -#ifndef __RAR20_CONST_H -#define __RAR20_CONST_H - -#include "Rar20ExtConst.h" - -namespace NCompress { -namespace NRar20 { - -const UInt32 kMainTableSize = 298; -const UInt32 kLenTableSize = 28; - -const UInt32 kDistTableStart = kMainTableSize; -const UInt32 kLenTableStart = kDistTableStart + kDistTableSize; - -const UInt32 kHeapTablesSizesSum = kMainTableSize + kDistTableSize + kLenTableSize; - -const UInt32 kLevelTableSize = 19; - -const UInt32 kMMTablesSizesSum = kMMTableSize * 4; - -const UInt32 kMaxTableSize = kMMTablesSizesSum; - -const UInt32 kTableDirectLevels = 16; -const UInt32 kTableLevelRepNumber = kTableDirectLevels; -const UInt32 kTableLevel0Number = kTableLevelRepNumber + 1; -const UInt32 kTableLevel0Number2 = kTableLevel0Number + 1; - -const UInt32 kLevelMask = 0xF; - - -const UInt32 kRepBothNumber = 256; -const UInt32 kRepNumber = kRepBothNumber + 1; -const UInt32 kLen2Number = kRepNumber + 4; - -const UInt32 kLen2NumNumbers = 8; -const UInt32 kReadTableNumber = kLen2Number + kLen2NumNumbers; -const UInt32 kMatchNumber = kReadTableNumber + 1; - -const Byte kLenStart[kLenTableSize] = {0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224}; -const Byte kLenDirectBits[kLenTableSize] = {0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5}; - -const UInt32 kDistStart[kDistTableSize] = {0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,512,768,1024,1536,2048,3072,4096,6144,8192,12288,16384,24576,32768U,49152U,65536,98304,131072,196608,262144,327680,393216,458752,524288,589824,655360,720896,786432,851968,917504,983040}; -const Byte kDistDirectBits[kDistTableSize] = {0,0,0,0,1,1,2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16}; - -const Byte kLevelDirectBits[kLevelTableSize] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7}; - -const Byte kLen2DistStarts[kLen2NumNumbers]={0,4,8,16,32,64,128,192}; -const Byte kLen2DistDirectBits[kLen2NumNumbers]={2,2,3, 4, 5, 6, 6, 6}; - -const UInt32 kDistLimit2 = 0x101 - 1; -const UInt32 kDistLimit3 = 0x2000 - 1; -const UInt32 kDistLimit4 = 0x40000 - 1; - -const UInt32 kMatchMaxLen = 255 + 2; -const UInt32 kMatchMaxLenMax = 255 + 5; -const UInt32 kNormalMatchMinLen = 3; - -}} - -#endif diff --git a/7zip/Compress/Rar20/Rar20Decoder.cpp b/7zip/Compress/Rar20/Rar20Decoder.cpp deleted file mode 100755 index f990811f..00000000 --- a/7zip/Compress/Rar20/Rar20Decoder.cpp +++ /dev/null @@ -1,322 +0,0 @@ -// Rar20Decoder.cpp -// According to unRAR license, -// this code may not be used to develop a -// RAR (WinRAR) compatible archiver - -#include "StdAfx.h" - -#include "Rar20Decoder.h" -#include "Rar20Const.h" - -namespace NCompress { -namespace NRar20 { - -class CException -{ -public: - enum ECauseType - { - kData - } Cause; - CException(ECauseType cause): Cause(cause) {} -}; - -static const char *kNumberErrorMessage = "Number error"; - -static const UInt32 kHistorySize = 1 << 20; - -static const int kNumStats = 11; - -static const UInt32 kWindowReservSize = (1 << 22) + 256; - -CDecoder::CDecoder(): - m_IsSolid(false) -{ -} - -void CDecoder::InitStructures() -{ - m_Predictor.Init(); - for(int i = 0; i < kNumRepDists; i++) - m_RepDists[i] = 0; - m_RepDistPtr = 0; - m_LastLength = 0; - memset(m_LastLevels, 0, kMaxTableSize); -} - -#define RIF(x) { if (!(x)) return false; } - -bool CDecoder::ReadTables(void) -{ - Byte levelLevels[kLevelTableSize]; - Byte newLevels[kMaxTableSize]; - m_AudioMode = (m_InBitStream.ReadBits(1) == 1); - - if (m_InBitStream.ReadBits(1) == 0) - memset(m_LastLevels, 0, kMaxTableSize); - int numLevels; - if (m_AudioMode) - { - m_NumChannels = m_InBitStream.ReadBits(2) + 1; - if (m_Predictor.CurrentChannel >= m_NumChannels) - m_Predictor.CurrentChannel = 0; - numLevels = m_NumChannels * kMMTableSize; - } - else - numLevels = kHeapTablesSizesSum; - - int i; - for (i = 0; i < kLevelTableSize; i++) - levelLevels[i] = Byte(m_InBitStream.ReadBits(4)); - RIF(m_LevelDecoder.SetCodeLengths(levelLevels)); - i = 0; - while (i < numLevels) - { - UInt32 number = m_LevelDecoder.DecodeSymbol(&m_InBitStream); - if (number < kTableDirectLevels) - { - newLevels[i] = Byte((number + m_LastLevels[i]) & kLevelMask); - i++; - } - else - { - if (number == kTableLevelRepNumber) - { - int t = m_InBitStream.ReadBits(2) + 3; - for (int reps = t; reps > 0 && i < numLevels ; reps--, i++) - newLevels[i] = newLevels[i - 1]; - } - else - { - int num; - if (number == kTableLevel0Number) - num = m_InBitStream.ReadBits(3) + 3; - else if (number == kTableLevel0Number2) - num = m_InBitStream.ReadBits(7) + 11; - else - return false; - for (;num > 0 && i < numLevels; num--) - newLevels[i++] = 0; - } - } - } - if (m_AudioMode) - for (i = 0; i < m_NumChannels; i++) - { - RIF(m_MMDecoders[i].SetCodeLengths(&newLevels[i * kMMTableSize])); - } - else - { - RIF(m_MainDecoder.SetCodeLengths(&newLevels[0])); - RIF(m_DistDecoder.SetCodeLengths(&newLevels[kMainTableSize])); - RIF(m_LenDecoder.SetCodeLengths(&newLevels[kMainTableSize + kDistTableSize])); - } - memcpy(m_LastLevels, newLevels, kMaxTableSize); - return true; -} - -bool CDecoder::ReadLastTables() -{ - // it differs a little from pure RAR sources; - // UInt64 ttt = m_InBitStream.GetProcessedSize() + 2; - // + 2 works for: return 0xFF; in CInBuffer::ReadByte. - if (m_InBitStream.GetProcessedSize() + 7 <= m_PackSize) // test it: probably incorrect; - // if (m_InBitStream.GetProcessedSize() + 2 <= m_PackSize) // test it: probably incorrect; - if (m_AudioMode) - { - UInt32 symbol = m_MMDecoders[m_Predictor.CurrentChannel].DecodeSymbol(&m_InBitStream); - if (symbol == 256) - return ReadTables(); - if (symbol >= kMMTableSize) - return false; - } - else - { - UInt32 number = m_MainDecoder.DecodeSymbol(&m_InBitStream); - if (number == kReadTableNumber) - return ReadTables(); - if (number >= kMainTableSize) - return false; - } - return true; -} - -class CCoderReleaser -{ - CDecoder *m_Coder; -public: - CCoderReleaser(CDecoder *coder): m_Coder(coder) {} - ~CCoderReleaser() - { - m_Coder->ReleaseStreams(); - } -}; - -STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream, - ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, - ICompressProgressInfo *progress) -{ - if (inSize == NULL || outSize == NULL) - return E_INVALIDARG; - - if (!m_OutWindowStream.Create(kHistorySize)) - return E_OUTOFMEMORY; - if (!m_InBitStream.Create(1 << 20)) - return E_OUTOFMEMORY; - - m_PackSize = *inSize; - - UInt64 pos = 0, unPackSize = *outSize; - - m_OutWindowStream.SetStream(outStream); - m_OutWindowStream.Init(m_IsSolid); - m_InBitStream.SetStream(inStream); - m_InBitStream.Init(); - - CCoderReleaser coderReleaser(this); - if (!m_IsSolid) - { - InitStructures(); - if (unPackSize == 0) - { - if (m_InBitStream.GetProcessedSize() + 2 <= m_PackSize) // test it: probably incorrect; - if (!ReadTables()) - return S_FALSE; - return S_OK; - } - if (!ReadTables()) - return S_FALSE; - } - - while(pos < unPackSize) - { - if (m_AudioMode) - while(pos < unPackSize) - { - UInt32 symbol = m_MMDecoders[m_Predictor.CurrentChannel].DecodeSymbol(&m_InBitStream); - if (symbol == 256) - { - if (progress != 0) - { - UInt64 packSize = m_InBitStream.GetProcessedSize(); - RINOK(progress->SetRatioInfo(&packSize, &pos)); - } - if (!ReadTables()) - return S_FALSE; - break; - } - if (symbol >= kMMTableSize) - return S_FALSE; - Byte byPredict = m_Predictor.Predict(); - Byte byReal = (Byte)(byPredict - (Byte)symbol); - m_Predictor.Update(byReal, byPredict); - m_OutWindowStream.PutByte(byReal); - if (++m_Predictor.CurrentChannel == m_NumChannels) - m_Predictor.CurrentChannel = 0; - pos++; - } - else - while(pos < unPackSize) - { - UInt32 number = m_MainDecoder.DecodeSymbol(&m_InBitStream); - UInt32 length, distance; - if (number < 256) - { - m_OutWindowStream.PutByte(Byte(number)); - pos++; - continue; - } - else if (number >= kMatchNumber) - { - number -= kMatchNumber; - length = kNormalMatchMinLen + UInt32(kLenStart[number]) + - m_InBitStream.ReadBits(kLenDirectBits[number]); - number = m_DistDecoder.DecodeSymbol(&m_InBitStream); - if (number >= kDistTableSize) - return S_FALSE; - distance = kDistStart[number] + m_InBitStream.ReadBits(kDistDirectBits[number]); - if (distance >= kDistLimit3) - { - length += 2 - ((distance - kDistLimit4) >> 31); - // length++; - // if (distance >= kDistLimit4) - // length++; - } - } - else if (number == kRepBothNumber) - { - length = m_LastLength; - distance = m_RepDists[(m_RepDistPtr + 4 - 1) & 3]; - } - else if (number < kLen2Number) - { - distance = m_RepDists[(m_RepDistPtr - (number - kRepNumber + 1)) & 3]; - number = m_LenDecoder.DecodeSymbol(&m_InBitStream); - if (number >= kLenTableSize) - return S_FALSE; - length = 2 + kLenStart[number] + m_InBitStream.ReadBits(kLenDirectBits[number]); - if (distance >= kDistLimit2) - { - length++; - if (distance >= kDistLimit3) - { - length += 2 - ((distance - kDistLimit4) >> 31); - // length++; - // if (distance >= kDistLimit4) - // length++; - } - } - } - else if (number < kReadTableNumber) - { - number -= kLen2Number; - distance = kLen2DistStarts[number] + - m_InBitStream.ReadBits(kLen2DistDirectBits[number]); - length = 2; - } - else if (number == kReadTableNumber) - { - if (progress != 0) - { - UInt64 packSize = m_InBitStream.GetProcessedSize(); - RINOK(progress->SetRatioInfo(&packSize, &pos)); - } - if (!ReadTables()) - return S_FALSE; - break; - } - else - return S_FALSE; - m_RepDists[m_RepDistPtr++ & 3] = distance; - m_LastLength = length; - if (!m_OutWindowStream.CopyBlock(distance, length)) - return S_FALSE; - pos += length; - } - } - if (pos > unPackSize) - throw CException(CException::kData); - - if (!ReadLastTables()) - return S_FALSE; - return m_OutWindowStream.Flush(); -} - -STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, - ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, - ICompressProgressInfo *progress) -{ - try { return CodeReal(inStream, outStream, inSize, outSize, progress); } - catch(const CLZOutWindowException &e) { return e.ErrorCode; } - catch(...) { return S_FALSE; } -} - -STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size) -{ - if (size < 1) - return E_INVALIDARG; - m_IsSolid = (data[0] != 0); - return S_OK; -} - -}} diff --git a/7zip/Compress/Rar20/Rar20ExtConst.h b/7zip/Compress/Rar20/Rar20ExtConst.h deleted file mode 100755 index b74bc0cf..00000000 --- a/7zip/Compress/Rar20/Rar20ExtConst.h +++ /dev/null @@ -1,21 +0,0 @@ -// Rar20ExtConst.h -// According to unRAR license, -// this code may not be used to develop a -// RAR (WinRAR) compatible archiver - -#ifndef __RAR20_EXTCONST_H -#define __RAR20_EXTCONST_H - -#include "../../../Common/Types.h" - -namespace NCompress { -namespace NRar20 { - -const UInt32 kNumRepDists = 4; -const UInt32 kDistTableSize = 48; - -const int kMMTableSize = 256 + 1; - -}} - -#endif diff --git a/7zip/Compress/Rar20/Rar20Multimedia.cpp b/7zip/Compress/Rar20/Rar20Multimedia.cpp deleted file mode 100755 index 3c0a13af..00000000 --- a/7zip/Compress/Rar20/Rar20Multimedia.cpp +++ /dev/null @@ -1,128 +0,0 @@ -// Rar20Multimedia.cpp -// According to unRAR license, -// this code may not be used to develop a -// RAR (WinRAR) compatible archiver - -#include "StdAfx.h" - -#include "Rar20Multimedia.h" - -namespace NCompress { -namespace NRar20 { -namespace NMultimedia { - -void CAudioVariables::Init() -{ - memset(this, 0, sizeof(CAudioVariables)); -} - -void CPredictor::Init() -{ - for(int i = 0; i < kNumChanelsMax; i++) - m_AudioVariablesArray[i].Init(); - m_ChannelDelta = 0; - CurrentChannel = 0; -} - -Byte CPredictor::Predict() -{ - CAudioVariables *v = &m_AudioVariablesArray[CurrentChannel]; - v->ByteCount++; - v->D4 = v->D3; - v->D3 = v->D2; - v->D2 = v->LastDelta-v->D1; - v->D1 = v->LastDelta; - int pCh = 8 * v->LastChar + - v->K1 * v->D1 + - v->K2 * v->D2 + - v->K3 * v->D3 + - v->K4 * v->D4 + - v->K5*m_ChannelDelta; - pCh = (pCh >> 3) & 0xFF; - return Byte(pCh); -} - -void CPredictor::Update(Byte realValue, int predictedValue) -{ - struct CAudioVariables *v = &m_AudioVariablesArray[CurrentChannel]; - - int delta = predictedValue - realValue; - int i = ((signed char)delta) << 3; - - v->Dif[0] += abs(i); - v->Dif[1] += abs(i - v->D1); - v->Dif[2] += abs(i + v->D1); - v->Dif[3] += abs(i - v->D2); - v->Dif[4] += abs(i + v->D2); - v->Dif[5] += abs(i - v->D3); - v->Dif[6] += abs(i + v->D3); - v->Dif[7] += abs(i - v->D4); - v->Dif[8] += abs(i + v->D4); - v->Dif[9] += abs(i - m_ChannelDelta); - v->Dif[10] += abs(i + m_ChannelDelta); - - m_ChannelDelta = v->LastDelta = (signed char)(realValue - v->LastChar); - v->LastChar = realValue; - - UInt32 numMinDif, minDif; - if ((v->ByteCount & 0x1F)==0) - { - minDif = v->Dif[0]; - numMinDif = 0; - v->Dif[0] = 0; - for (i = 1; i < sizeof(v->Dif) / sizeof(v->Dif[0]); i++) - { - if (v->Dif[i] < minDif) - { - minDif = v->Dif[i]; - numMinDif = i; - } - v->Dif[i] = 0; - } - switch(numMinDif) - { - case 1: - if (v->K1 >= -16) - v->K1--; - break; - case 2: - if (v->K1 < 16) - v->K1++; - break; - case 3: - if (v->K2 >= -16) - v->K2--; - break; - case 4: - if (v->K2 < 16) - v->K2++; - break; - case 5: - if (v->K3 >= -16) - v->K3--; - break; - case 6: - if (v->K3 < 16) - v->K3++; - break; - case 7: - if (v->K4 >= -16) - v->K4--; - break; - case 8: - if (v->K4 < 16) - v->K4++; - break; - case 9: - if (v->K5 >= -16) - v->K5--; - break; - case 10: - if (v->K5 < 16) - v->K5++; - break; - } - } -} - -}}} diff --git a/7zip/Compress/Rar20/Rar20Multimedia.h b/7zip/Compress/Rar20/Rar20Multimedia.h deleted file mode 100755 index 7af86d07..00000000 --- a/7zip/Compress/Rar20/Rar20Multimedia.h +++ /dev/null @@ -1,43 +0,0 @@ -// Rar20Multimedia.h -// According to unRAR license, -// this code may not be used to develop a -// RAR (WinRAR) compatible archiver - -#ifndef __RAR20_MULTIMEDIA_H -#define __RAR20_MULTIMEDIA_H - -#include "../../../Common/Types.h" - -namespace NCompress { -namespace NRar20 { -namespace NMultimedia { - -struct CAudioVariables -{ - int K1,K2,K3,K4,K5; - int D1,D2,D3,D4; - int LastDelta; - UInt32 Dif[11]; - UInt32 ByteCount; - int LastChar; - - void Init(); -}; - -const int kNumChanelsMax = 4; - -class CPredictor -{ - CAudioVariables m_AudioVariablesArray[kNumChanelsMax]; - int m_ChannelDelta; -public: - int CurrentChannel; - - void Init(); - Byte Predict(); - void Update(Byte realValue, int predictedValue); -}; - -}}} - -#endif diff --git a/7zip/Compress/Rar29/Original/archive.hpp b/7zip/Compress/Rar29/Original/archive.hpp deleted file mode 100755 index c076b5b7..00000000 --- a/7zip/Compress/Rar29/Original/archive.hpp +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef _RAR_ARCHIVE_ -#define _RAR_ARCHIVE_ - -class Pack; - -enum {EN_LOCK=1,EN_VOL=2,EN_FIRSTVOL=4}; - -class Archive:public File -{ - private: - bool IsSignature(byte *D); - void UpdateLatestTime(FileHeader *CurBlock); - void Protect(int RecSectors); - void ConvertNameCase(char *Name); - void ConvertNameCase(wchar *Name); - void ConvertUnknownHeader(); - bool AddArcComment(char *NameToShow); - int ReadOldHeader(); - void PrepareExtraTime(FileHeader *hd,EXTTIME_MODE etm,EXTTIME_MODE etc,EXTTIME_MODE eta,EXTTIME_MODE etarc,Array &TimeData); - -#if !defined(SHELL_EXT) && !defined(NOCRYPT) - CryptData HeadersCrypt; - byte HeadersSalt[SALT_SIZE]; -#endif -#ifndef SHELL_EXT - ComprDataIO SubDataIO; - byte SubDataSalt[SALT_SIZE]; -#endif - RAROptions *Cmd,DummyCmd; - - MarkHeader MarkHead; - OldMainHeader OldMhd; - - int RecoverySectors; - Int64 RecoveryPos; - - RarTime LatestTime; - int LastReadBlock; - int CurHeaderType; - - bool SilentOpen; - public: - Archive(RAROptions *InitCmd=NULL); - bool IsArchive(bool EnableBroken); - int SearchBlock(int BlockType); - int SearchSubBlock(const char *Type); - int ReadBlock(int BlockType); - void WriteBlock(int BlockType,BaseBlock *wb=NULL); - int PrepareNamesToWrite(char *Name,wchar *NameW,char *DestName,byte *DestNameW); - void SetLhdSize(); - int ReadHeader(); - void CheckArc(bool EnableBroken); - void CheckOpen(char *Name,wchar *NameW=NULL); - bool WCheckOpen(char *Name,wchar *NameW=NULL); - bool TestLock(int Mode); - void MakeTemp(); - void CopyMainHeader(Archive &Src,bool CopySFX=true,char *NameToDisplay=NULL); - bool ProcessToFileHead(Archive &Src,bool LastBlockAdded, - Pack *Pack=NULL,const char *SkipName=NULL); - void TmpToArc(Archive &Src); - void CloseNew(int AdjustRecovery,bool CloseVolume); - void WriteEndBlock(bool CloseVolume); - void CopyFileRecord(Archive &Src); - void CopyArchiveData(Archive &Src); - bool GetComment(Array &CmtData); - void ViewComment(); - void ViewFileComment(); - void SetLatestTime(RarTime *NewTime); - void SeekToNext(); - bool CheckAccess(); - bool IsArcDir(); - bool IsArcLabel(); - void ConvertAttributes(); - int GetRecoverySize(bool Required); - void VolSubtractHeaderSize(int SubSize); - void AddSubData(byte *SrcData,int DataSize,File *SrcFile,char *Name,bool AllowSplit); - bool ReadSubData(Array *UnpData,File *DestFile); - int GetHeaderType() {return(CurHeaderType);}; - int ReadCommentData(Array &CmtData); - void WriteCommentData(byte *Data,int DataSize,bool FileComment); - RAROptions* GetRAROptions() {return(Cmd);} - void SetSilentOpen(bool Mode) {SilentOpen=Mode;} - - BaseBlock ShortBlock; - MainHeader NewMhd; - FileHeader NewLhd; - EndArcHeader EndArcHead; - SubBlockHeader SubBlockHead; - FileHeader SubHead; - CommentHeader CommHead; - ProtectHeader ProtectHead; - AVHeader AVHead; - SignHeader SignHead; - UnixOwnersHeader UOHead; - MacFInfoHeader MACHead; - EAHeader EAHead; - StreamHeader StreamHead; - - Int64 CurBlockPos; - Int64 NextBlockPos; - - bool OldFormat; - bool Solid; - bool Volume; - bool MainComment; - bool Locked; - bool Signed; - bool NotFirstVolume; - bool Protected; - bool Encrypted; - uint SFXSize; - bool BrokenFileHeader; - - bool Splitting; - - ushort HeaderCRC; - - Int64 VolWrite; - Int64 AddingFilesSize; - uint AddingHeadersSize; - - bool NewArchive; - - char FirstVolumeName[NM]; - wchar FirstVolumeNameW[NM]; -}; - -#endif diff --git a/7zip/Compress/Rar29/Original/array.hpp b/7zip/Compress/Rar29/Original/array.hpp deleted file mode 100755 index 3afec70c..00000000 --- a/7zip/Compress/Rar29/Original/array.hpp +++ /dev/null @@ -1,121 +0,0 @@ -#ifndef _RAR_ARRAY_ -#define _RAR_ARRAY_ - -extern ErrorHandler ErrHandler; - -template class Array -{ - private: - T *Buffer; - int BufSize; - int AllocSize; - public: - Array(); - Array(int Size); - ~Array(); - inline void CleanData(); - inline T& operator [](int Item); - inline int Size(); - void Add(int Items); - void Alloc(int Items); - void Reset(); - void operator = (Array &Src); - void Push(T Item); -}; - -template void Array::CleanData() -{ - Buffer=NULL; - BufSize=0; - AllocSize=0; -} - - -template Array::Array() -{ - CleanData(); -} - - -template Array::Array(int Size) -{ - Buffer=(T *)rarmalloc(sizeof(T)*Size); - if (Buffer==NULL && Size!=0) - ErrHandler.MemoryError(); - - AllocSize=BufSize=Size; -} - - -template Array::~Array() -{ - if (Buffer!=NULL) - rarfree(Buffer); -} - - -template inline T& Array::operator [](int Item) -{ - return(Buffer[Item]); -} - - -template inline int Array::Size() -{ - return(BufSize); -} - - -template void Array::Add(int Items) -{ - BufSize+=Items; - if (BufSize>AllocSize) - { - int Suggested=AllocSize+AllocSize/4+32; - int NewSize=Max(BufSize,Suggested); - - Buffer=(T *)rarrealloc(Buffer,NewSize*sizeof(T)); - if (Buffer==NULL) - ErrHandler.MemoryError(); - AllocSize=NewSize; - } -} - - -template void Array::Alloc(int Items) -{ - if (Items>AllocSize) - Add(Items-BufSize); - else - BufSize=Items; -} - - -template void Array::Reset() -{ - if (Buffer!=NULL) - { - rarfree(Buffer); - Buffer=NULL; - } - BufSize=0; - AllocSize=0; -} - - -template void Array::operator =(Array &Src) -{ - Reset(); - Alloc(Src.BufSize); - if (Src.BufSize!=0) - memcpy((void *)Buffer,(void *)Src.Buffer,Src.BufSize*sizeof(T)); -} - - -template void Array::Push(T Item) -{ - Add(1); - (*this)[Size()-1]=Item; -} - -#endif diff --git a/7zip/Compress/Rar29/Original/cmddata.hpp b/7zip/Compress/Rar29/Original/cmddata.hpp deleted file mode 100755 index 08b92c11..00000000 --- a/7zip/Compress/Rar29/Original/cmddata.hpp +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _RAR_CMDDATA_ -#define _RAR_CMDDATA_ - -#define DefaultStoreList "ace;arj;bz2;cab;gz;jpeg;jpg;lha;lzh;mp3;rar;zip;taz;tgz;z" - -class CommandData:public RAROptions -{ - private: - void ProcessSwitchesString(char *Str); - void ProcessSwitch(char *Switch); - void BadSwitch(char *Switch); - bool ExclCheckArgs(StringList *Args,char *CheckName,bool CheckFullPath,int MatchMode); - uint GetExclAttr(char *Str); - - bool FileLists; - bool NoMoreSwitches; - bool TimeConverted; - bool BareOutput; - public: - CommandData(); - ~CommandData(); - void Init(); - void Close(); - void ParseArg(char *Arg,wchar *ArgW); - void ParseDone(); - void ParseEnvVar(); - void ReadConfig(int argc,char *argv[]); - bool IsConfigEnabled(int argc,char *argv[]); - void OutTitle(); - void OutHelp(); - bool IsSwitch(int Ch); - bool ExclCheck(char *CheckName,bool CheckFullPath); - bool StoreCheck(char *CheckName); - bool TimeCheck(RarTime &ft); - int IsProcessFile(FileHeader &NewLhd,bool *ExactMatch=NULL,int MatchType=MATCH_WILDSUBPATH); - void ProcessCommand(); - void AddArcName(char *Name,wchar *NameW); - bool GetArcName(char *Name,wchar *NameW,int MaxSize); - bool CheckWinSize(); - - int GetRecoverySize(char *Str,int DefSize); - - char Command[NM+16]; - wchar CommandW[NM+16]; - - char ArcName[NM]; - wchar ArcNameW[NM]; - - StringList *FileArgs; - StringList *ExclArgs; - StringList *InclArgs; - StringList *ArcNames; - StringList *StoreArgs; -}; - -#endif diff --git a/7zip/Compress/Rar29/Original/coder.cpp b/7zip/Compress/Rar29/Original/coder.cpp deleted file mode 100755 index cb6a8836..00000000 --- a/7zip/Compress/Rar29/Original/coder.cpp +++ /dev/null @@ -1,47 +0,0 @@ - - -inline unsigned int RangeCoder::GetChar() -{ - return(UnpackRead->GetChar()); -} - - -void RangeCoder::InitDecoder(Unpack *UnpackRead) -{ - RangeCoder::UnpackRead=UnpackRead; - - low=code=0; - range=uint(-1); - for (int i=0;i < 4;i++) - code=(code << 8) | GetChar(); -} - - -#define ARI_DEC_NORMALIZE(code,low,range,read) \ -{ \ - while ((low^(low+range))GetChar(); \ - range <<= 8; \ - low <<= 8; \ - } \ -} - - -inline int RangeCoder::GetCurrentCount() -{ - return (code-low)/(range /= SubRange.scale); -} - - -inline uint RangeCoder::GetCurrentShiftCount(uint SHIFT) -{ - return (code-low)/(range >>= SHIFT); -} - - -inline void RangeCoder::Decode() -{ - low += range*SubRange.LowCount; - range *= SubRange.HighCount-SubRange.LowCount; -} diff --git a/7zip/Compress/Rar29/Original/coder.hpp b/7zip/Compress/Rar29/Original/coder.hpp deleted file mode 100755 index f09f911c..00000000 --- a/7zip/Compress/Rar29/Original/coder.hpp +++ /dev/null @@ -1,24 +0,0 @@ -/**************************************************************************** - * Contents: 'Carryless rangecoder' by Dmitry Subbotin * - ****************************************************************************/ - -const uint TOP=1 << 24, BOT=1 << 15; - -class RangeCoder -{ - public: - void InitDecoder(Unpack *UnpackRead); - inline int GetCurrentCount(); - inline uint GetCurrentShiftCount(uint SHIFT); - inline void Decode(); - inline void PutChar(unsigned int c); - inline unsigned int GetChar(); - - uint low, code, range; - struct SUBRANGE - { - uint LowCount, HighCount, scale; - } SubRange; - - Unpack *UnpackRead; -}; diff --git a/7zip/Compress/Rar29/Original/compress.hpp b/7zip/Compress/Rar29/Original/compress.hpp deleted file mode 100755 index 2ba7b23e..00000000 --- a/7zip/Compress/Rar29/Original/compress.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _RAR_COMPRESS_ -#define _RAR_COMPRESS_ - -class ComprDataIO; -class PackingFileTable; - -#define CODEBUFSIZE 0x4000 -#define MAXWINSIZE 0x400000 -#define MAXWINMASK (MAXWINSIZE-1) - -#define LOW_DIST_REP_COUNT 16 - -#define NC 299 /* alphabet = {0, 1, 2, ..., NC - 1} */ -#define DC 60 -#define LDC 17 -#define RC 28 -#define HUFF_TABLE_SIZE (NC+DC+RC+LDC) -#define BC 20 - -#define NC20 298 /* alphabet = {0, 1, 2, ..., NC - 1} */ -#define DC20 48 -#define RC20 28 -#define BC20 19 -#define MC20 257 - -enum {CODE_HUFFMAN,CODE_LZ,CODE_LZ2,CODE_REPEATLZ,CODE_CACHELZ, - CODE_STARTFILE,CODE_ENDFILE,CODE_VM,CODE_VMDATA}; - - -enum FilterType { - FILTER_NONE, FILTER_PPM /*dummy*/, FILTER_E8, FILTER_E8E9, - FILTER_UPCASETOLOW, FILTER_AUDIO, FILTER_RGB, FILTER_DELTA, - FILTER_ITANIUM, FILTER_E8E9V2 -}; - -#endif diff --git a/7zip/Compress/Rar29/Original/consio.hpp b/7zip/Compress/Rar29/Original/consio.hpp deleted file mode 100755 index 780ae7f3..00000000 --- a/7zip/Compress/Rar29/Original/consio.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef _RAR_CONSIO_ -#define _RAR_CONSIO_ - -enum {ALARM_SOUND,ERROR_SOUND,QUESTION_SOUND}; - -enum PASSWORD_TYPE {PASSWORD_GLOBAL,PASSWORD_FILE,PASSWORD_ARCHIVE}; - -void InitConsoleOptions(MESSAGE_TYPE MsgStream,bool Sound); - -#ifndef SILENT -void mprintf(const char *fmt,...); -void eprintf(const char *fmt,...); -void Alarm(); -void GetPasswordText(char *Str,int MaxLength); -unsigned int GetKey(); -bool GetPassword(PASSWORD_TYPE Type,const char *FileName,char *Password,int MaxLength); -int Ask(const char *AskStr); -#endif - -int KbdAnsi(char *Addr,int Size); -void OutComment(char *Comment,int Size); - -#ifdef SILENT -#ifdef __GNUC__ - #define mprintf(args...) - #define eprintf(args...) -#else - inline void mprintf(const char *fmt,const char *a=NULL,const char *b=NULL) {} - inline void eprintf(const char *fmt,const char *a=NULL,const char *b=NULL) {} - inline void mprintf(const char *fmt,int b) {} - inline void eprintf(const char *fmt,int b) {} - inline void mprintf(const char *fmt,const char *a,int b) {} - inline void eprintf(const char *fmt,const char *a,int b) {} -#endif -inline void Alarm() {} -inline void GetPasswordText(char *Str,int MaxLength) {} -inline unsigned int GetKey() {return(0);} -inline bool GetPassword(PASSWORD_TYPE Type,const char *FileName,char *Password,int MaxLength) {return(false);} -inline int Ask(const char *AskStr) {return(0);} -#endif - -#endif diff --git a/7zip/Compress/Rar29/Original/crc.cpp b/7zip/Compress/Rar29/Original/crc.cpp deleted file mode 100755 index c19f8595..00000000 --- a/7zip/Compress/Rar29/Original/crc.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "rar.hpp" - -uint CRCTab[256]; - -void InitCRC() -{ - for (int I=0;I<256;I++) - { - uint C=I; - for (int J=0;J<8;J++) - C=(C & 1) ? (C>>1)^0xEDB88320L : (C>>1); - CRCTab[I]=C; - } -} - - -uint CRC(uint StartCRC,const void *Addr,uint Size) -{ - if (CRCTab[1]==0) - InitCRC(); - byte *Data=(byte *)Addr; -#if defined(LITTLE_ENDIAN) && defined(PRESENT_INT32) - while (Size>0 && ((long)Data & 7)) - { - StartCRC=CRCTab[(byte)(StartCRC^Data[0])]^(StartCRC>>8); - Size--; - Data++; - } - while (Size>=8) - { - StartCRC^=*(uint32 *)Data; - StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8); - StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8); - StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8); - StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8); - StartCRC^=*(uint32 *)(Data+4); - StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8); - StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8); - StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8); - StartCRC=CRCTab[(byte)StartCRC]^(StartCRC>>8); - Data+=8; - Size-=8; - } -#endif - for (int I=0;I>8); - return(StartCRC); -} - -#ifndef SFX_MODULE -ushort OldCRC(ushort StartCRC,const void *Addr,uint Size) -{ - byte *Data=(byte *)Addr; - for (int I=0;I>15))&0xffff; - } - return(StartCRC); -} -#endif diff --git a/7zip/Compress/Rar29/Original/crc.hpp b/7zip/Compress/Rar29/Original/crc.hpp deleted file mode 100755 index 47ee7e23..00000000 --- a/7zip/Compress/Rar29/Original/crc.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _RAR_CRC_ -#define _RAR_CRC_ - -extern uint CRCTab[256]; - -void InitCRC(); -uint CRC(uint StartCRC,const void *Addr,uint Size); -ushort OldCRC(ushort StartCRC,const void *Addr,uint Size); - -#endif diff --git a/7zip/Compress/Rar29/Original/crypt.hpp b/7zip/Compress/Rar29/Original/crypt.hpp deleted file mode 100755 index 809d76a5..00000000 --- a/7zip/Compress/Rar29/Original/crypt.hpp +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef _RAR_CRYPT_ -#define _RAR_CRYPT_ - -enum { OLD_DECODE=0,OLD_ENCODE=1,NEW_CRYPT=2 }; - -struct CryptKeyCacheItem -{ -#ifndef _SFX_RTL_ - CryptKeyCacheItem() - { - *Password=0; - } - - ~CryptKeyCacheItem() - { - memset(AESKey,0,sizeof(AESKey)); - memset(AESInit,0,sizeof(AESInit)); - memset(Password,0,sizeof(Password)); - } -#endif - byte AESKey[16],AESInit[16]; - char Password[MAXPASSWORD]; - bool SaltPresent; - byte Salt[SALT_SIZE]; -}; - -class CryptData -{ - private: - void Encode13(byte *Data,uint Count); - void Decode13(byte *Data,uint Count); - void Crypt15(byte *Data,uint Count); - void UpdKeys(byte *Buf); - void Swap(byte *Ch1,byte *Ch2); - void SetOldKeys(char *Password); - - Rijndael rin; - - byte SubstTable[256]; - uint Key[4]; - ushort OldKey[4]; - byte PN1,PN2,PN3; - - byte AESKey[16],AESInit[16]; - - static CryptKeyCacheItem Cache[4]; - static int CachePos; - public: - void SetCryptKeys(char *Password,byte *Salt,bool Encrypt,bool OldOnly=false); - void SetAV15Encryption(); - void SetCmt13Encryption(); - void EncryptBlock20(byte *Buf); - void DecryptBlock20(byte *Buf); - void EncryptBlock(byte *Buf,int Size); - void DecryptBlock(byte *Buf,int Size); - void Crypt(byte *Data,uint Count,int Method); - static void SetSalt(byte *Salt,int SaltSize); -}; - -#endif diff --git a/7zip/Compress/Rar29/Original/encname.hpp b/7zip/Compress/Rar29/Original/encname.hpp deleted file mode 100755 index 586f4216..00000000 --- a/7zip/Compress/Rar29/Original/encname.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef _RAR_ENCNAME_ -#define _RAR_ENCNAME_ - -class EncodeFileName -{ - private: - void AddFlags(int Value); - - byte *EncName; - byte Flags; - int FlagBits; - int FlagsPos; - int DestSize; - public: - EncodeFileName(); - int Encode(char *Name,wchar *NameW,byte *EncName); - void Decode(char *Name,byte *EncName,int EncSize,wchar *NameW,int MaxDecSize); -}; - -#endif diff --git a/7zip/Compress/Rar29/Original/errhnd.cpp b/7zip/Compress/Rar29/Original/errhnd.cpp deleted file mode 100755 index 6e162217..00000000 --- a/7zip/Compress/Rar29/Original/errhnd.cpp +++ /dev/null @@ -1,356 +0,0 @@ -#include "rar.hpp" - - -static bool UserBreak; - -ErrorHandler::ErrorHandler() -{ - Clean(); -} - - -void ErrorHandler::Clean() -{ - ExitCode=SUCCESS; - ErrCount=0; - EnableBreak=true; - Silent=false; - DoShutdown=false; -} - - -void ErrorHandler::MemoryError() -{ - MemoryErrorMsg(); - Throw(MEMORY_ERROR); -} - - -void ErrorHandler::OpenError(const char *FileName) -{ -#ifndef SILENT - OpenErrorMsg(FileName); - Throw(OPEN_ERROR); -#endif -} - - -void ErrorHandler::CloseError(const char *FileName) -{ -#ifndef SILENT - if (!UserBreak) - { - ErrMsg(NULL,St(MErrFClose),FileName); - SysErrMsg(); - } -#endif -#if !defined(SILENT) || defined(RARDLL) - Throw(FATAL_ERROR); -#endif -} - - -void ErrorHandler::ReadError(const char *FileName) -{ -#ifndef SILENT - ReadErrorMsg(NULL,FileName); -#endif -#if !defined(SILENT) || defined(RARDLL) - Throw(FATAL_ERROR); -#endif -} - - -bool ErrorHandler::AskRepeatRead(const char *FileName) -{ -#if !defined(SILENT) && !defined(SFX_MODULE) && !defined(_WIN_CE) - if (!Silent) - { - mprintf("\n"); - Log(NULL,St(MErrRead),FileName); - return(Ask(St(MRetryAbort))==1); - } -#endif - return(false); -} - - -void ErrorHandler::WriteError(const char *ArcName,const char *FileName) -{ -#ifndef SILENT - WriteErrorMsg(ArcName,FileName); -#endif -#if !defined(SILENT) || defined(RARDLL) - Throw(WRITE_ERROR); -#endif -} - - -#ifdef _WIN_32 -void ErrorHandler::WriteErrorFAT(const char *FileName) -{ -#if !defined(SILENT) && !defined(SFX_MODULE) - SysErrMsg(); - ErrMsg(NULL,St(MNTFSRequired),FileName); -#endif -#if !defined(SILENT) && !defined(SFX_MODULE) || defined(RARDLL) - Throw(WRITE_ERROR); -#endif -} -#endif - - -bool ErrorHandler::AskRepeatWrite(const char *FileName) -{ -#if !defined(SILENT) && !defined(_WIN_CE) - if (!Silent) - { - mprintf("\n"); - Log(NULL,St(MErrWrite),FileName); - return(Ask(St(MRetryAbort))==1); - } -#endif - return(false); -} - - -void ErrorHandler::SeekError(const char *FileName) -{ -#ifndef SILENT - if (!UserBreak) - { - ErrMsg(NULL,St(MErrSeek),FileName); - SysErrMsg(); - } -#endif -#if !defined(SILENT) || defined(RARDLL) - Throw(FATAL_ERROR); -#endif -} - - -void ErrorHandler::MemoryErrorMsg() -{ -#ifndef SILENT - ErrMsg(NULL,St(MErrOutMem)); -#endif -} - - -void ErrorHandler::OpenErrorMsg(const char *FileName) -{ - OpenErrorMsg(NULL,FileName); -} - - -void ErrorHandler::OpenErrorMsg(const char *ArcName,const char *FileName) -{ -#ifndef SILENT - Log(ArcName && *ArcName ? ArcName:NULL,St(MCannotOpen),FileName); - Alarm(); - SysErrMsg(); -#endif -} - - -void ErrorHandler::CreateErrorMsg(const char *FileName) -{ - CreateErrorMsg(NULL,FileName); -} - - -void ErrorHandler::CreateErrorMsg(const char *ArcName,const char *FileName) -{ -#ifndef SILENT - Log(ArcName && *ArcName ? ArcName:NULL,St(MCannotCreate),FileName); - Alarm(); -#if defined(_WIN_32) && !defined(_WIN_CE) && !defined(SFX_MODULE) && defined(MAXPATH) - if (GetLastError()==ERROR_PATH_NOT_FOUND) - { - int NameLength=strlen(FileName); - if (!IsFullPath(FileName)) - { - char CurDir[NM]; - GetCurrentDirectory(sizeof(CurDir),CurDir); - NameLength+=strlen(CurDir)+1; - } - if (NameLength>MAXPATH) - { - Log(ArcName && *ArcName ? ArcName:NULL,St(MMaxPathLimit),MAXPATH); - } - } -#endif - SysErrMsg(); -#endif -} - - -void ErrorHandler::ReadErrorMsg(const char *ArcName,const char *FileName) -{ -#ifndef SILENT - ErrMsg(ArcName,St(MErrRead),FileName); - SysErrMsg(); -#endif -} - - -void ErrorHandler::WriteErrorMsg(const char *ArcName,const char *FileName) -{ -#ifndef SILENT - ErrMsg(ArcName,St(MErrWrite),FileName); - SysErrMsg(); -#endif -} - - -void ErrorHandler::Exit(int ExitCode) -{ -#ifndef SFX_MODULE - Alarm(); -#endif - Throw(ExitCode); -} - - -#ifndef GUI -void ErrorHandler::ErrMsg(const char *ArcName,const char *fmt,...) -{ - safebuf char Msg[NM+1024]; - va_list argptr; - va_start(argptr,fmt); - vsprintf(Msg,fmt,argptr); - va_end(argptr); -#ifdef _WIN_32 - if (UserBreak) - Sleep(5000); -#endif - Alarm(); - if (*Msg) - { - Log(ArcName,"\n%s",Msg); - mprintf("\n%s\n",St(MProgAborted)); - } -} -#endif - - -void ErrorHandler::SetErrorCode(int Code) -{ - switch(Code) - { - case WARNING: - case USER_BREAK: - if (ExitCode==SUCCESS) - ExitCode=Code; - break; - case FATAL_ERROR: - if (ExitCode==SUCCESS || ExitCode==WARNING) - ExitCode=FATAL_ERROR; - break; - default: - ExitCode=Code; - break; - } - ErrCount++; -} - - -#if !defined(GUI) && !defined(_SFX_RTL_) -#ifdef _WIN_32 -BOOL __stdcall ProcessSignal(DWORD SigType) -#else -#if defined(__sun) -extern "C" -#endif -void _stdfunction ProcessSignal(int SigType) -#endif -{ -#ifdef _WIN_32 - if (SigType==CTRL_LOGOFF_EVENT) - return(TRUE); -#endif - UserBreak=true; - mprintf(St(MBreak)); - for (int I=0; - // Igor Pavlov - // !File::RemoveCreated() && - I<3;I++) - { -#ifdef _WIN_32 - Sleep(100); -#endif - } -#if defined(USE_RC) && !defined(SFX_MODULE) && !defined(_WIN_CE) - ExtRes.UnloadDLL(); -#endif - exit(USER_BREAK); -#ifdef _WIN_32 - return(TRUE); -#endif -} -#endif - - -void ErrorHandler::SetSignalHandlers(bool Enable) -{ - EnableBreak=Enable; -#if !defined(GUI) && !defined(_SFX_RTL_) -#ifdef _WIN_32 - SetConsoleCtrlHandler(Enable ? ProcessSignal:NULL,TRUE); -// signal(SIGBREAK,Enable ? ProcessSignal:SIG_IGN); -#else - signal(SIGINT,Enable ? ProcessSignal:SIG_IGN); - signal(SIGTERM,Enable ? ProcessSignal:SIG_IGN); -#endif -#endif -} - - -void ErrorHandler::Throw(int Code) -{ - if (Code==USER_BREAK && !EnableBreak) - return; - ErrHandler.SetErrorCode(Code); -#ifdef ALLOW_EXCEPTIONS - throw Code; -#else - // Igor Pavlov - // File::RemoveCreated(); - exit(Code); -#endif -} - - -void ErrorHandler::SysErrMsg() -{ -#if defined(_WIN_32) && !defined(SFX_MODULE) && !defined(SILENT) - #define STRCHR strchr - #define ERRCHAR char - ERRCHAR *lpMsgBuf=NULL; - int ErrType=GetLastError(); - if (ErrType!=0 && FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM, - NULL,ErrType,MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&lpMsgBuf,0,NULL)) - { - ERRCHAR *CurMsg=lpMsgBuf; - while (CurMsg!=NULL) - { - while (*CurMsg=='\r' || *CurMsg=='\n') - CurMsg++; - if (*CurMsg==0) - break; - ERRCHAR *EndMsg=STRCHR(CurMsg,'\r'); - if (EndMsg==NULL) - EndMsg=STRCHR(CurMsg,'\n'); - if (EndMsg!=NULL) - { - *EndMsg=0; - EndMsg++; - } - Log(NULL,"\n%s",CurMsg); - CurMsg=EndMsg; - } - } - LocalFree( lpMsgBuf ); -#endif -} diff --git a/7zip/Compress/Rar29/Original/errhnd.hpp b/7zip/Compress/Rar29/Original/errhnd.hpp deleted file mode 100755 index 9e276222..00000000 --- a/7zip/Compress/Rar29/Original/errhnd.hpp +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef _RAR_ERRHANDLER_ -#define _RAR_ERRHANDLER_ - -#if (defined(GUI) || !defined(_WIN_32)) && !defined(SFX_MODULE) && !defined(_WIN_CE) || defined(RARDLL) -#define ALLOW_EXCEPTIONS -#endif - - - -#define rarmalloc malloc -#define rarcalloc calloc -#define rarrealloc realloc -#define rarfree free -#define rarstrdup strdup - - - -enum { SUCCESS,WARNING,FATAL_ERROR,CRC_ERROR,LOCK_ERROR,WRITE_ERROR, - OPEN_ERROR,USER_ERROR,MEMORY_ERROR,CREATE_ERROR,USER_BREAK=255}; - -class ErrorHandler -{ - private: - void ErrMsg(const char *ArcName,const char *fmt,...); - - int ExitCode; - int ErrCount; - bool EnableBreak; - bool Silent; - bool DoShutdown; - public: - ErrorHandler(); - void Clean(); - void MemoryError(); - void OpenError(const char *FileName); - void CloseError(const char *FileName); - void ReadError(const char *FileName); - bool AskRepeatRead(const char *FileName); - void WriteError(const char *ArcName,const char *FileName); - void WriteErrorFAT(const char *FileName); - bool AskRepeatWrite(const char *FileName); - void SeekError(const char *FileName); - void MemoryErrorMsg(); - void OpenErrorMsg(const char *FileName); - void OpenErrorMsg(const char *ArcName,const char *FileName); - void CreateErrorMsg(const char *FileName); - void CreateErrorMsg(const char *ArcName,const char *FileName); - void ReadErrorMsg(const char *ArcName,const char *FileName); - void WriteErrorMsg(const char *ArcName,const char *FileName); - void Exit(int ExitCode); - void SetErrorCode(int Code); - int GetErrorCode() {return(ExitCode);} - int GetErrorCount() {return(ErrCount);} - void SetSignalHandlers(bool Enable); - void Throw(int Code); - void SetSilent(bool Mode) {Silent=Mode;}; - void SetShutdown(bool Mode) {DoShutdown=Mode;}; - void SysErrMsg(); -}; - -#endif diff --git a/7zip/Compress/Rar29/Original/extinfo.hpp b/7zip/Compress/Rar29/Original/extinfo.hpp deleted file mode 100755 index db7cea53..00000000 --- a/7zip/Compress/Rar29/Original/extinfo.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _RAR_EXTINFO_ -#define _RAR_EXTINFO_ - - -void SetExtraInfo(CommandData *Cmd,Archive &Arc,char *Name,wchar *NameW); -void SetExtraInfoNew(CommandData *Cmd,Archive &Arc,char *Name,wchar *NameW); - -#endif diff --git a/7zip/Compress/Rar29/Original/extract.hpp b/7zip/Compress/Rar29/Original/extract.hpp deleted file mode 100755 index b78c988d..00000000 --- a/7zip/Compress/Rar29/Original/extract.hpp +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _RAR_EXTRACT_ -#define _RAR_EXTRACT_ - -enum EXTRACT_ARC_CODE {EXTRACT_ARC_NEXT,EXTRACT_ARC_REPEAT}; - -class CmdExtract -{ - private: - ComprDataIO DataIO; - Unpack *Unp; - long TotalFileCount; - - long FileCount; - long MatchedArgs; - bool FirstFile; - bool AllMatchesExact; - bool ReconstructDone; - - char ArcName[NM]; - wchar ArcNameW[NM]; - - char Password[MAXPASSWORD]; - bool PasswordAll; - bool PrevExtracted; - bool SignatureFound; - char DestFileName[NM]; - wchar DestFileNameW[NM]; - bool PasswordCancelled; - public: - CmdExtract(); - ~CmdExtract(); - void DoExtract(CommandData *Cmd); - void ExtractArchiveInit(CommandData *Cmd,Archive &Arc); - EXTRACT_ARC_CODE ExtractArchive(CommandData *Cmd); - bool ExtractCurrentFile(CommandData *Cmd,Archive &Arc,int HeaderSize, - bool &Repeat); - static void UnstoreFile(ComprDataIO &DataIO,Int64 DestUnpSize); -}; - -#endif diff --git a/7zip/Compress/Rar29/Original/filcreat.hpp b/7zip/Compress/Rar29/Original/filcreat.hpp deleted file mode 100755 index fa1fddd0..00000000 --- a/7zip/Compress/Rar29/Original/filcreat.hpp +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _RAR_FILECREATE_ -#define _RAR_FILECREATE_ - -bool FileCreate(RAROptions *Cmd,File *NewFile,char *Name,wchar *NameW, - OVERWRITE_MODE Mode,bool *UserReject,Int64 FileSize=INT64ERR, - uint FileTime=0); - -#if defined(_WIN_32) && !defined(_WIN_CE) -bool UpdateExistingShortName(char *Name,wchar *NameW); -#endif - -#endif diff --git a/7zip/Compress/Rar29/Original/file.hpp b/7zip/Compress/Rar29/Original/file.hpp deleted file mode 100755 index afa9529c..00000000 --- a/7zip/Compress/Rar29/Original/file.hpp +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef _RAR_FILE_ -#define _RAR_FILE_ - -#ifdef _WIN_32 -typedef HANDLE FileHandle; -#define BAD_HANDLE INVALID_HANDLE_VALUE -#else -typedef FILE* FileHandle; -#define BAD_HANDLE NULL -#endif - -class RAROptions; - -enum FILE_HANDLETYPE {FILE_HANDLENORMAL,FILE_HANDLESTD,FILE_HANDLEERR}; - -enum FILE_ERRORTYPE {FILE_SUCCESS,FILE_NOTFOUND,FILE_READERROR}; - -struct FileStat -{ - uint FileAttr; - uint FileTime; - Int64 FileSize; - bool IsDir; -}; - - -class File -{ - private: - void AddFileToList(FileHandle hFile); - - FileHandle hFile; - bool LastWrite; - FILE_HANDLETYPE HandleType; - bool SkipClose; - bool IgnoreReadErrors; - bool NewFile; - bool AllowDelete; - bool AllowExceptions; -#ifdef _WIN_32 - bool NoSequentialRead; -#endif - protected: - bool OpenShared; - public: - char FileName[NM]; - wchar FileNameW[NM]; - - FILE_ERRORTYPE ErrorType; - - uint CloseCount; - public: - File(); - virtual ~File(); - void operator = (File &SrcFile); - bool Open(const char *Name,const wchar *NameW=NULL,bool OpenShared=false,bool Update=false); - void TOpen(const char *Name,const wchar *NameW=NULL); - bool WOpen(const char *Name,const wchar *NameW=NULL); - bool Create(const char *Name,const wchar *NameW=NULL); - void TCreate(const char *Name,const wchar *NameW=NULL); - bool WCreate(const char *Name,const wchar *NameW=NULL); - bool Close(); - void Flush(); - bool Delete(); - bool Rename(const char *NewName); - void Write(const void *Data,int Size); - int Read(void *Data,int Size); - int DirectRead(void *Data,int Size); - void Seek(Int64 Offset,int Method); - bool RawSeek(Int64 Offset,int Method); - Int64 Tell(); - void Prealloc(Int64 Size); - byte GetByte(); - void PutByte(byte Byte); - bool Truncate(); - void SetOpenFileTime(RarTime *ftm,RarTime *ftc=NULL,RarTime *fta=NULL); - void SetCloseFileTime(RarTime *ftm,RarTime *fta=NULL); - static void SetCloseFileTimeByName(const char *Name,RarTime *ftm,RarTime *fta); - void SetOpenFileStat(RarTime *ftm,RarTime *ftc,RarTime *fta); - void SetCloseFileStat(RarTime *ftm,RarTime *fta,uint FileAttr); - void GetOpenFileTime(RarTime *ft); - bool IsOpened() {return(hFile!=BAD_HANDLE);}; - Int64 FileLength(); - void SetHandleType(FILE_HANDLETYPE Type); - FILE_HANDLETYPE GetHandleType() {return(HandleType);}; - bool IsDevice(); - void fprintf(const char *fmt,...); - static bool RemoveCreated(); - FileHandle GetHandle() {return(hFile);}; - void SetIgnoreReadErrors(bool Mode) {IgnoreReadErrors=Mode;}; - char *GetName() {return(FileName);} - long Copy(File &Dest,Int64 Length=INT64ERR); - void SetAllowDelete(bool Allow) {AllowDelete=Allow;} - void SetExceptions(bool Allow) {AllowExceptions=Allow;} -#ifdef _WIN_32 - void RemoveSequentialFlag() {NoSequentialRead=true;} -#endif -}; - -#endif diff --git a/7zip/Compress/Rar29/Original/filefn.hpp b/7zip/Compress/Rar29/Original/filefn.hpp deleted file mode 100755 index 3ad31b5e..00000000 --- a/7zip/Compress/Rar29/Original/filefn.hpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _RAR_FILEFN_ -#define _RAR_FILEFN_ - -enum MKDIR_CODE {MKDIR_SUCCESS,MKDIR_ERROR,MKDIR_BADPATH}; - -MKDIR_CODE MakeDir(const char *Name,const wchar *NameW,uint Attr); -void CreatePath(const char *Path,const wchar *PathW,bool SkipLastName); -void SetDirTime(const char *Name,RarTime *ftm,RarTime *ftc,RarTime *fta); -bool IsRemovable(const char *Name); -Int64 GetFreeDisk(const char *Name); -bool FileExist(const char *Name,const wchar *NameW=NULL); -bool WildFileExist(const char *Name,const wchar *NameW=NULL); -bool IsDir(uint Attr); -bool IsUnreadable(uint Attr); -bool IsLabel(uint Attr); -bool IsLink(uint Attr); -void SetSFXMode(const char *FileName); -void EraseDiskContents(const char *FileName); -bool IsDeleteAllowed(uint FileAttr); -void PrepareToDelete(const char *Name,const wchar *NameW=NULL); -uint GetFileAttr(const char *Name,const wchar *NameW=NULL); -bool SetFileAttr(const char *Name,const wchar *NameW,uint Attr); -void ConvertNameToFull(const char *Src,char *Dest); -void ConvertNameToFull(const wchar *Src,wchar *Dest); -char* MkTemp(char *Name); - - -uint CalcFileCRC(File *SrcFile,Int64 Size=INT64ERR); -bool RenameFile(const char *SrcName,const wchar *SrcNameW,const char *DestName,const wchar *DestNameW); -bool DelFile(const char *Name); -bool DelFile(const char *Name,const wchar *NameW); -bool DelDir(const char *Name); -bool DelDir(const char *Name,const wchar *NameW); - -#if defined(_WIN_32) && !defined(_WIN_CE) -bool SetFileCompression(char *Name,wchar *NameW,bool State); -#endif - -#endif diff --git a/7zip/Compress/Rar29/Original/filestr.hpp b/7zip/Compress/Rar29/Original/filestr.hpp deleted file mode 100755 index b2bcbe0e..00000000 --- a/7zip/Compress/Rar29/Original/filestr.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _RAR_FILESTR_ -#define _RAR_FILESTR_ - -bool ReadTextFile(char *Name,StringList *List,bool Config, - bool AbortOnError=false,bool ConvertToAnsi=false, - bool Unquote=false,bool SkipComments=false); - -#endif diff --git a/7zip/Compress/Rar29/Original/find.hpp b/7zip/Compress/Rar29/Original/find.hpp deleted file mode 100755 index 81548199..00000000 --- a/7zip/Compress/Rar29/Original/find.hpp +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef _RAR_FINDDATA_ -#define _RAR_FINDDATA_ - -struct FindData -{ - char Name[NM]; - wchar NameW[NM]; - Int64 Size; - uint FileAttr; - uint FileTime; - bool IsDir; - RarTime mtime; - RarTime ctime; - RarTime atime; -#ifdef _WIN_32 - char ShortName[NM]; - FILETIME ftCreationTime; - FILETIME ftLastAccessTime; - FILETIME ftLastWriteTime; -#endif - bool Error; -}; - -class FindFile -{ - private: -#ifdef _WIN_32 - static HANDLE Win32Find(HANDLE hFind,const char *Mask,const wchar *MaskW,struct FindData *fd); -#endif - - char FindMask[NM]; - wchar FindMaskW[NM]; - int FirstCall; -#ifdef _WIN_32 - HANDLE hFind; -#else - DIR *dirp; -#endif - public: - FindFile(); - ~FindFile(); - void SetMask(const char *FindMask); - void SetMaskW(const wchar *FindMaskW); - bool Next(struct FindData *fd,bool GetSymLink=false); - static bool FastFind(const char *FindMask,const wchar *FindMaskW,struct FindData *fd,bool GetSymLink=false); -}; - -#endif diff --git a/7zip/Compress/Rar29/Original/getbits.cpp b/7zip/Compress/Rar29/Original/getbits.cpp deleted file mode 100755 index 71ecfc87..00000000 --- a/7zip/Compress/Rar29/Original/getbits.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "rar.hpp" - -BitInput::BitInput() -{ - InBuf=new byte[MAX_SIZE]; -} - - -BitInput::~BitInput() -{ - delete[] InBuf; -} - - -void BitInput::faddbits(int Bits) -{ - addbits(Bits); -} - - -unsigned int BitInput::fgetbits() -{ - return(getbits()); -} diff --git a/7zip/Compress/Rar29/Original/getbits.hpp b/7zip/Compress/Rar29/Original/getbits.hpp deleted file mode 100755 index 8819f53a..00000000 --- a/7zip/Compress/Rar29/Original/getbits.hpp +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _RAR_GETBITS_ -#define _RAR_GETBITS_ - -class BitInput -{ - public: - enum BufferSize {MAX_SIZE=0x8000}; - protected: - int InAddr,InBit; - public: - BitInput(); - ~BitInput(); - - byte *InBuf; - - void InitBitInput() - { - InAddr=InBit=0; - } - void addbits(int Bits) - { - Bits+=InBit; - InAddr+=Bits>>3; - InBit=Bits&7; - } - unsigned int getbits() - { - unsigned int BitField=(uint)InBuf[InAddr] << 16; - BitField|=(uint)InBuf[InAddr+1] << 8; - BitField|=(uint)InBuf[InAddr+2]; - BitField >>= (8-InBit); - return(BitField & 0xffff); - } - void faddbits(int Bits); - unsigned int fgetbits(); -}; -#endif diff --git a/7zip/Compress/Rar29/Original/global.hpp b/7zip/Compress/Rar29/Original/global.hpp deleted file mode 100755 index 35c6cf91..00000000 --- a/7zip/Compress/Rar29/Original/global.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef _RAR_GLOBAL_ -#define _RAR_GLOBAL_ - -#ifdef INCLUDEGLOBAL - #define EXTVAR -#else - #define EXTVAR extern -#endif - -EXTVAR ErrorHandler ErrHandler; - - - -#endif diff --git a/7zip/Compress/Rar29/Original/headers.hpp b/7zip/Compress/Rar29/Original/headers.hpp deleted file mode 100755 index f719a7ec..00000000 --- a/7zip/Compress/Rar29/Original/headers.hpp +++ /dev/null @@ -1,304 +0,0 @@ -#ifndef _RAR_HEADERS_ -#define _RAR_HEADERS_ - -#define SIZEOF_MARKHEAD 7 -#define SIZEOF_OLDMHD 7 -#define SIZEOF_NEWMHD 13 -#define SIZEOF_OLDLHD 21 -#define SIZEOF_NEWLHD 32 -#define SIZEOF_SHORTBLOCKHEAD 7 -#define SIZEOF_LONGBLOCKHEAD 11 -#define SIZEOF_SUBBLOCKHEAD 14 -#define SIZEOF_COMMHEAD 13 -#define SIZEOF_PROTECTHEAD 26 -#define SIZEOF_AVHEAD 14 -#define SIZEOF_SIGNHEAD 15 -#define SIZEOF_UOHEAD 18 -#define SIZEOF_MACHEAD 22 -#define SIZEOF_EAHEAD 24 -#define SIZEOF_BEEAHEAD 24 -#define SIZEOF_STREAMHEAD 26 - -#define PACK_VER 29 -#define PACK_CRYPT_VER 29 -#define UNP_VER 29 -#define CRYPT_VER 29 -#define AV_VER 20 -#define PROTECT_VER 20 - -#define MHD_VOLUME 0x0001 -#define MHD_COMMENT 0x0002 -#define MHD_LOCK 0x0004 -#define MHD_SOLID 0x0008 -#define MHD_PACK_COMMENT 0x0010 -#define MHD_NEWNUMBERING 0x0010 -#define MHD_AV 0x0020 -#define MHD_PROTECT 0x0040 -#define MHD_PASSWORD 0x0080 -#define MHD_FIRSTVOLUME 0x0100 - -#define LHD_SPLIT_BEFORE 0x0001 -#define LHD_SPLIT_AFTER 0x0002 -#define LHD_PASSWORD 0x0004 -#define LHD_COMMENT 0x0008 -#define LHD_SOLID 0x0010 - -#define LHD_WINDOWMASK 0x00e0 -#define LHD_WINDOW64 0x0000 -#define LHD_WINDOW128 0x0020 -#define LHD_WINDOW256 0x0040 -#define LHD_WINDOW512 0x0060 -#define LHD_WINDOW1024 0x0080 -#define LHD_WINDOW2048 0x00a0 -#define LHD_WINDOW4096 0x00c0 -#define LHD_DIRECTORY 0x00e0 - -#define LHD_LARGE 0x0100 -#define LHD_UNICODE 0x0200 -#define LHD_SALT 0x0400 -#define LHD_VERSION 0x0800 -#define LHD_EXTTIME 0x1000 -#define LHD_EXTFLAGS 0x2000 - -#define SKIP_IF_UNKNOWN 0x4000 -#define LONG_BLOCK 0x8000 - -#define EARC_NEXT_VOLUME 0x0001 -#define EARC_DATACRC 0x0002 -#define EARC_REVSPACE 0x0004 -#define EARC_VOLNUMBER 0x0008 - -enum HEADER_TYPE { - MARK_HEAD=0x72,MAIN_HEAD=0x73,FILE_HEAD=0x74,COMM_HEAD=0x75,AV_HEAD=0x76, - SUB_HEAD=0x77,PROTECT_HEAD=0x78,SIGN_HEAD=0x79,NEWSUB_HEAD=0x7a, - ENDARC_HEAD=0x7b -}; - -enum { EA_HEAD=0x100,UO_HEAD=0x101,MAC_HEAD=0x102,BEEA_HEAD=0x103, - NTACL_HEAD=0x104,STREAM_HEAD=0x105 }; - -enum HOST_SYSTEM { - HOST_MSDOS=0,HOST_OS2=1,HOST_WIN32=2,HOST_UNIX=3,HOST_MACOS=4, - HOST_BEOS=5,HOST_MAX -}; - -#define SUBHEAD_TYPE_CMT "CMT" -#define SUBHEAD_TYPE_ACL "ACL" -#define SUBHEAD_TYPE_STREAM "STM" -#define SUBHEAD_TYPE_UOWNER "UOW" -#define SUBHEAD_TYPE_AV "AV" -#define SUBHEAD_TYPE_RR "RR" -#define SUBHEAD_TYPE_OS2EA "EA2" -#define SUBHEAD_TYPE_BEOSEA "EABE" - -/* new file inherits a subblock when updating a host file */ -#define SUBHEAD_FLAGS_INHERITED 0x80000000 - -#define SUBHEAD_FLAGS_CMT_UNICODE 0x00000001 - -struct OldMainHeader -{ - byte Mark[4]; - ushort HeadSize; - byte Flags; -}; - - -struct OldFileHeader -{ - uint PackSize; - uint UnpSize; - ushort FileCRC; - ushort HeadSize; - uint FileTime; - byte FileAttr; - byte Flags; - byte UnpVer; - byte NameSize; - byte Method; -}; - - -struct MarkHeader -{ - byte Mark[7]; -}; - - -struct BaseBlock -{ - ushort HeadCRC; - HEADER_TYPE HeadType;//byte - ushort Flags; - ushort HeadSize; - - bool IsSubBlock() - { - if (HeadType==SUB_HEAD) - return(true); - if (HeadType==NEWSUB_HEAD && (Flags & LHD_SOLID)!=0) - return(true); - return(false); - } -}; - -struct BlockHeader:BaseBlock -{ - union { - uint DataSize; - uint PackSize; - }; -}; - - -struct MainHeader:BlockHeader -{ - ushort HighPosAV; - uint PosAV; -}; - - -#define SALT_SIZE 8 - -struct FileHeader:BlockHeader -{ - uint UnpSize; - byte HostOS; - uint FileCRC; - uint FileTime; - byte UnpVer; - byte Method; - ushort NameSize; - union { - uint FileAttr; - uint SubFlags; - }; -/* optional */ - uint HighPackSize; - uint HighUnpSize; -/* names */ - char FileName[NM]; - wchar FileNameW[NM]; -/* optional */ - Array SubData; - byte Salt[SALT_SIZE]; - - RarTime mtime; - RarTime ctime; - RarTime atime; - RarTime arctime; -/* dummy */ - Int64 FullPackSize; - Int64 FullUnpSize; - - void Clear(int SubDataSize) - { - SubData.Alloc(SubDataSize); - Flags=LONG_BLOCK; - SubFlags=0; - } - - bool CmpName(const char *Name) - { - return(strcmp(FileName,Name)==0); - } - - FileHeader& operator = (FileHeader &hd) - { - SubData.Reset(); - memcpy(this,&hd,sizeof(*this)); - SubData.CleanData(); - SubData=hd.SubData; - return(*this); - } -}; - - -struct EndArcHeader:BaseBlock -{ - uint ArcDataCRC; - ushort VolNumber; -}; - - -struct SubBlockHeader:BlockHeader -{ - ushort SubType; - byte Level; -}; - - -struct CommentHeader:BaseBlock -{ - ushort UnpSize; - byte UnpVer; - byte Method; - ushort CommCRC; -}; - - -struct ProtectHeader:BlockHeader -{ - byte Version; - ushort RecSectors; - uint TotalBlocks; - byte Mark[8]; -}; - - -struct AVHeader:BaseBlock -{ - byte UnpVer; - byte Method; - byte AVVer; - uint AVInfoCRC; -}; - - -struct SignHeader:BaseBlock -{ - uint CreationTime; - ushort ArcNameSize; - ushort UserNameSize; -}; - - -struct UnixOwnersHeader:SubBlockHeader -{ - ushort OwnerNameSize; - ushort GroupNameSize; -/* dummy */ - char OwnerName[NM]; - char GroupName[NM]; -}; - - -struct EAHeader:SubBlockHeader -{ - uint UnpSize; - byte UnpVer; - byte Method; - uint EACRC; -}; - - -struct StreamHeader:SubBlockHeader -{ - uint UnpSize; - byte UnpVer; - byte Method; - uint StreamCRC; - ushort StreamNameSize; -/* dummy */ - byte StreamName[NM]; -}; - - -struct MacFInfoHeader:SubBlockHeader -{ - uint fileType; - uint fileCreator; -}; - - -#endif diff --git a/7zip/Compress/Rar29/Original/int64.cpp b/7zip/Compress/Rar29/Original/int64.cpp deleted file mode 100755 index 996d0ea6..00000000 --- a/7zip/Compress/Rar29/Original/int64.cpp +++ /dev/null @@ -1,274 +0,0 @@ -#include "rar.hpp" - -#ifndef NATIVE_INT64 - -Int64::Int64() -{ -} - - -Int64::Int64(uint n) -{ - HighPart=0; - LowPart=n; -} - - -Int64::Int64(uint HighPart,uint LowPart) -{ - Int64::HighPart=HighPart; - Int64::LowPart=LowPart; -} - - -/* -Int64 Int64::operator = (Int64 n) -{ - HighPart=n.HighPart; - LowPart=n.LowPart; - return(*this); -} -*/ - - -Int64 Int64::operator << (int n) -{ - Int64 res=*this; - while (n--) - { - res.HighPart<<=1; - if (res.LowPart & 0x80000000) - res.HighPart|=1; - res.LowPart<<=1; - } - return(res); -} - - -Int64 Int64::operator >> (int n) -{ - Int64 res=*this; - while (n--) - { - res.LowPart>>=1; - if (res.HighPart & 1) - res.LowPart|=0x80000000; - res.HighPart>>=1; - } - return(res); -} - - -Int64 operator / (Int64 n1,Int64 n2) -{ - if (n1.HighPart==0 && n2.HighPart==0) - return(Int64(0,n1.LowPart/n2.LowPart)); - int ShiftCount=0; - while (n1>n2) - { - n2=n2<<1; - if (++ShiftCount>64) - return(0); - } - Int64 res=0; - while (ShiftCount-- >= 0) - { - res=res<<1; - if (n1>=n2) - { - n1-=n2; - ++res; - } - n2=n2>>1; - } - return(res); -} - - -Int64 operator * (Int64 n1,Int64 n2) -{ - if (n1<0x10000 && n2<0x10000) - return(Int64(0,n1.LowPart*n2.LowPart)); - Int64 res=0; - for (int I=0;I<64;I++) - { - if (n2.LowPart & 1) - res+=n1; - n1=n1<<1; - n2=n2>>1; - } - return(res); -} - - -Int64 operator % (Int64 n1,Int64 n2) -{ - if (n1.HighPart==0 && n2.HighPart==0) - return(Int64(0,n1.LowPart%n2.LowPart)); - return(n1-n1/n2*n2); -} - - -Int64 operator + (Int64 n1,Int64 n2) -{ - n1.LowPart+=n2.LowPart; - if (n1.LowPart (Int64 n1,Int64 n2) -{ - return((int)n1.HighPart>(int)n2.HighPart || n1.HighPart==n2.HighPart && n1.LowPart>n2.LowPart); -} - - -bool operator < (Int64 n1,Int64 n2) -{ - return((int)n1.HighPart<(int)n2.HighPart || n1.HighPart==n2.HighPart && n1.LowPart= (Int64 n1,Int64 n2) -{ - return(n1>n2 || n1==n2); -} - - -bool operator <= (Int64 n1,Int64 n2) -{ - return(n1='0' && *Str<='9') - { - n=n*10+*Str-'0'; - Str++; - } - return(n); -} diff --git a/7zip/Compress/Rar29/Original/int64.hpp b/7zip/Compress/Rar29/Original/int64.hpp deleted file mode 100755 index a8057522..00000000 --- a/7zip/Compress/Rar29/Original/int64.hpp +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef _RAR_INT64_ -#define _RAR_INT64_ - -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define NATIVE_INT64 -typedef __int64 Int64; -#endif - -#if defined(__GNUC__) || defined(__HP_aCC) -#define NATIVE_INT64 -typedef long long Int64; -#endif - -#ifdef NATIVE_INT64 - -#define int64to32(x) ((uint)(x)) -#define int32to64(high,low) ((((Int64)(high))<<32)+(low)) -#define is64plus(x) (x>=0) - -#else - -class Int64 -{ - public: - Int64(); - Int64(uint n); - Int64(uint HighPart,uint LowPart); - -// Int64 operator = (Int64 n); - Int64 operator << (int n); - Int64 operator >> (int n); - - friend Int64 operator / (Int64 n1,Int64 n2); - friend Int64 operator * (Int64 n1,Int64 n2); - friend Int64 operator % (Int64 n1,Int64 n2); - friend Int64 operator + (Int64 n1,Int64 n2); - friend Int64 operator - (Int64 n1,Int64 n2); - friend Int64 operator += (Int64 &n1,Int64 n2); - friend Int64 operator -= (Int64 &n1,Int64 n2); - friend Int64 operator *= (Int64 &n1,Int64 n2); - friend Int64 operator /= (Int64 &n1,Int64 n2); - friend Int64 operator | (Int64 n1,Int64 n2); - friend Int64 operator & (Int64 n1,Int64 n2); - inline friend void operator -= (Int64 &n1,unsigned int n2) - { - if (n1.LowPart (Int64 n1,Int64 n2); - friend bool operator < (Int64 n1,Int64 n2); - friend bool operator != (Int64 n1,Int64 n2); - friend bool operator >= (Int64 n1,Int64 n2); - friend bool operator <= (Int64 n1,Int64 n2); - - void Set(uint HighPart,uint LowPart); - uint GetLowPart() {return(LowPart);} - - uint LowPart; - uint HighPart; -}; - -inline uint int64to32(Int64 n) {return(n.GetLowPart());} -#define int32to64(high,low) (Int64((high),(low))) -#define is64plus(x) ((int)(x).HighPart>=0) - -#endif - -#define INT64ERR int32to64(0x80000000,0) -#define INT64MAX int32to64(0x7fffffff,0) - -void itoa(Int64 n,char *Str); -Int64 atoil(char *Str); - -#endif diff --git a/7zip/Compress/Rar29/Original/isnt.hpp b/7zip/Compress/Rar29/Original/isnt.hpp deleted file mode 100755 index 02652361..00000000 --- a/7zip/Compress/Rar29/Original/isnt.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _RAR_ISNT_ -#define _RAR_ISNT_ - -int WinNT(); - -#endif diff --git a/7zip/Compress/Rar29/Original/list.hpp b/7zip/Compress/Rar29/Original/list.hpp deleted file mode 100755 index 7721ae52..00000000 --- a/7zip/Compress/Rar29/Original/list.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _RAR_LIST_ -#define _RAR_LIST_ - -void ListArchive(CommandData *Cmd); - -#endif diff --git a/7zip/Compress/Rar29/Original/loclang.hpp b/7zip/Compress/Rar29/Original/loclang.hpp deleted file mode 100755 index 05eefdde..00000000 --- a/7zip/Compress/Rar29/Original/loclang.hpp +++ /dev/null @@ -1,340 +0,0 @@ -#define MYesNo "_Yes_No" -#define MYesNoAll "_Yes_No_All" -#define MYesNoAllRenQ "_Yes_No_All_nEver_Rename_Quit" -#define MContinueQuit "_Continue_Quit" -#define MRetryAbort "_Retry_Abort" -#define MCopyright "\nRAR %s Copyright (c) 1993-%d Alexander Roshal %d %s %d" -#define MRegTo "\nRegistered to %s\n" -#define MShare "\nShareware version Type RAR -? for help\n" -#define MUCopyright "\nUNRAR %s freeware Copyright (c) 1993-%d Alexander Roshal\n" -#define MBeta "beta" -#define MMonthJan "Jan" -#define MMonthFeb "Feb" -#define MMonthMar "Mar" -#define MMonthApr "Apr" -#define MMonthMay "May" -#define MMonthJun "Jun" -#define MMonthJul "Jul" -#define MMonthAug "Aug" -#define MMonthSep "Sep" -#define MMonthOct "Oct" -#define MMonthNov "Nov" -#define MMonthDec "Dec" -#define MRARTitle1 "\nUsage: rar - - " -#define MUNRARTitle1 "\nUsage: unrar - - " -#define MRARTitle2 "\n <@listfiles...> " -#define MCHelpCmd "\n\n" -#define MCHelpCmdA "\n a Add files to archive" -#define MCHelpCmdC "\n c Add archive comment" -#define MCHelpCmdCF "\n cf Add files comment" -#define MCHelpCmdCW "\n cw Write archive comment to file" -#define MCHelpCmdD "\n d Delete files from archive" -#define MCHelpCmdE "\n e Extract files to current directory" -#define MCHelpCmdF "\n f Freshen files in archive" -#define MCHelpCmdI "\n i[par]= Find string in archives" -#define MCHelpCmdK "\n k Lock archive" -#define MCHelpCmdL "\n l[t,b] List archive [technical, bare]" -#define MCHelpCmdM "\n m[f] Move to archive [files only]" -#define MCHelpCmdP "\n p Print file to stdout" -#define MCHelpCmdR "\n r Repair archive" -#define MCHelpCmdRC "\n rc Reconstruct missing volumes" -#define MCHelpCmdRN "\n rn Rename archived files" -#define MCHelpCmdRR "\n rr[N] Add data recovery record" -#define MCHelpCmdRV "\n rv[N] Create recovery volumes" -#define MCHelpCmdS "\n s[name|-] Convert archive to or from SFX" -#define MCHelpCmdT "\n t Test archive files" -#define MCHelpCmdU "\n u Update files in archive" -#define MCHelpCmdV "\n v[t,b] Verbosely list archive [technical,bare]" -#define MCHelpCmdX "\n x Extract files with full path" -#define MCHelpSw "\n\n" -#define MCHelpSwm "\n - Stop switches scanning" -#define MCHelpSwAC "\n ac Clear Archive attribute after compression or extraction" -#define MCHelpSwAD "\n ad Append archive name to destination path" -#define MCHelpSwAG "\n ag[format] Generate archive name using the current date" -#define MCHelpSwAO "\n ao Add files with Archive attribute set" -#define MCHelpSwAP "\n ap Set path inside archive" -#define MCHelpSwAS "\n as Synchronize archive contents" -#define MCHelpSwAV "\n av Put authenticity verification (registered versions only)" -#define MCHelpSwAVm "\n av- Disable authenticity verification check" -#define MCHelpSwCm "\n c- Disable comments show" -#define MCHelpSwCFGm "\n cfg- Disable read configuration" -#define MCHelpSwCL "\n cl Convert names to lower case" -#define MCHelpSwCU "\n cu Convert names to upper case" -#define MCHelpSwDF "\n df Delete files after archiving" -#define MCHelpSwDH "\n dh Open shared files" -#define MCHelpSwDS "\n ds Disable name sort for solid archive" -#define MCHelpSwEa "\n e[+] Set file exclude and include attributes" -#define MCHelpSwED "\n ed Do not add empty directories" -#define MCHelpSwEE "\n ee Do not save and extract extended attributes" -#define MCHelpSwEN "\n en Do not put 'end of archive' block" -#define MCHelpSwEP "\n ep Exclude paths from names" -#define MCHelpSwEP1 "\n ep1 Exclude base directory from names" -#define MCHelpSwEP2 "\n ep2 Expand paths to full" -#define MCHelpSwEP3 "\n ep3 Expand paths to full including the drive letter" -#define MCHelpSwF "\n f Freshen files" -#define MCHelpSwHP "\n hp[password] Encrypt both file data and headers" -#define MCHelpSwIDP "\n id[c,d,p,q] Disable messages" -#define MCHelpSwIEML "\n ieml[addr] Send archive by email" -#define MCHelpSwIERR "\n ierr Send all messages to stderr" -#define MCHelpSwILOG "\n ilog[name] Log errors to file (registered versions only)" -#define MCHelpSwINUL "\n inul Disable all messages" -#define MCHelpSwIOFF "\n ioff Turn PC off after completing an operation" -#define MCHelpSwISND "\n isnd Enable sound" -#define MCHelpSwK "\n k Lock archive" -#define MCHelpSwKB "\n kb Keep broken extracted files" -#define MCHelpSwMn "\n m<0..5> Set compression level (0-store...3-default...5-maximal)" -#define MCHelpSwMC "\n mc Set advanced compression parameters" -#define MCHelpSwMD "\n md Dictionary size in KB (64,128,256,512,1024,2048,4096 or A-G)" -#define MCHelpSwMS "\n ms[ext;ext] Specify file types to store" -#define MCHelpSwN "\n n Include only specified file" -#define MCHelpSwNa "\n n@ Read file names to include from stdin" -#define MCHelpSwNal "\n n@ Include files in specified list file" -#define MCHelpSwOp "\n o+ Overwrite existing files" -#define MCHelpSwOm "\n o- Do not overwrite existing files" -#define MCHelpSwOC "\n oc Set NTFS Compressed attribute" -#define MCHelpSwOL "\n ol Save symbolic links as the link instead of the file" -#define MCHelpSwOS "\n os Save NTFS streams" -#define MCHelpSwOW "\n ow Save or restore file owner and group" -#define MCHelpSwP "\n p[password] Set password" -#define MCHelpSwPm "\n p- Do not query password" -#define MCHelpSwR "\n r Recurse subdirectories" -#define MCHelpSwR0 "\n r0 Recurse subdirectories for wildcard names only" -#define MCHelpSwRI "\n ri

[:] Set priority (0-default,1-min..15-max) and sleep time in ms" -#define MCHelpSwRR "\n rr[N] Add data recovery record" -#define MCHelpSwRV "\n rv[N] Create recovery volumes" -#define MCHelpSwS "\n s[,v[-],e] Create solid archive" -#define MCHelpSwSm "\n s- Disable solid archiving" -#define MCHelpSwSFX "\n sfx[name] Create SFX archive" -#define MCHelpSwSI "\n si[name] Read data from standard input (stdin)" -#define MCHelpSwT "\n t Test files after archiving" -#define MCHelpSwTK "\n tk Keep original archive time" -#define MCHelpSwTL "\n tl Set archive time to latest file" -#define MCHelpSwTN "\n tn