[llvm-commits] [test-suite] r170306 [4/7] - in /test-suite/trunk: ./ MultiSource/Benchmarks/ MultiSource/Benchmarks/7zip/ MultiSource/Benchmarks/7zip/C/ MultiSource/Benchmarks/7zip/C/LzmaUtil/ MultiSource/Benchmarks/7zip/CPP/ MultiSource/Benchmarks/7zip/CPP/7zip/ MultiSource/Benchmarks/7zip/CPP/7zip/Archive/ MultiSource/Benchmarks/7zip/CPP/7zip/Archive/7z/ MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Cab/ MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Chm/ MultiSource/Benchmarks/7zip/CPP/7zip/Archive/Com/ MultiSource/Ben...
Michael Gottesman
mgottesman at apple.com
Sun Dec 16 21:23:34 PST 2012
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Decoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Decoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Decoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Decoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,943 @@
+// BZip2Decoder.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/Alloc.h"
+
+#include "BZip2Decoder.h"
+#include "Mtf8.h"
+
+namespace NCompress {
+namespace NBZip2 {
+
+#undef NO_INLINE
+#define NO_INLINE
+
+static const UInt32 kNumThreadsMax = 4;
+
+static const UInt32 kBufferSize = (1 << 17);
+
+static const UInt16 kRandNums[512] = {
+ 619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
+ 985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
+ 733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
+ 419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
+ 878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
+ 862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
+ 150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
+ 170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
+ 73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
+ 909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
+ 641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
+ 161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
+ 382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
+ 98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
+ 227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
+ 469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
+ 184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
+ 715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
+ 951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
+ 652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
+ 645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
+ 609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
+ 653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
+ 411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
+ 170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
+ 857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
+ 669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
+ 944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
+ 344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
+ 897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
+ 433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
+ 686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
+ 946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
+ 978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
+ 680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
+ 707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
+ 297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
+ 134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
+ 343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
+ 140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
+ 170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
+ 369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
+ 804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
+ 896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
+ 661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
+ 768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
+ 61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
+ 372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
+ 780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
+ 920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
+ 645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
+ 936, 638
+};
+
+bool CState::Alloc()
+{
+ if (!Counters)
+ Counters = (UInt32 *)::BigAlloc((256 + kBlockSizeMax) * sizeof(UInt32));
+ return (Counters != 0);
+}
+
+void CState::Free()
+{
+ ::BigFree(Counters);
+ Counters = 0;
+}
+
+UInt32 CDecoder::ReadBits(unsigned numBits) { return m_InStream.ReadBits(numBits); }
+Byte CDecoder::ReadByte() {return (Byte)ReadBits(8); }
+bool CDecoder::ReadBit() { return ReadBits(1) != 0; }
+
+UInt32 CDecoder::ReadCrc()
+{
+ UInt32 crc = 0;
+ for (int i = 0; i < 4; i++)
+ {
+ crc <<= 8;
+ crc |= ReadByte();
+ }
+ return crc;
+}
+
+static UInt32 NO_INLINE ReadBits(NBitm::CDecoder<CInBuffer> *m_InStream, unsigned num)
+{
+ return m_InStream->ReadBits(num);
+}
+
+static UInt32 NO_INLINE ReadBit(NBitm::CDecoder<CInBuffer> *m_InStream)
+{
+ return m_InStream->ReadBits(1);
+}
+
+static HRESULT NO_INLINE ReadBlock(NBitm::CDecoder<CInBuffer> *m_InStream,
+ UInt32 *CharCounters, UInt32 blockSizeMax, Byte *m_Selectors, CHuffmanDecoder *m_HuffmanDecoders,
+ UInt32 *blockSizeRes, UInt32 *origPtrRes, bool *randRes)
+{
+ if (randRes)
+ *randRes = ReadBit(m_InStream) ? true : false;
+ *origPtrRes = ReadBits(m_InStream, kNumOrigBits);
+
+ // in original code it compares OrigPtr to (UInt32)(10 + blockSizeMax)) : why ?
+ if (*origPtrRes >= blockSizeMax)
+ return S_FALSE;
+
+ CMtf8Decoder mtf;
+ mtf.StartInit();
+
+ int numInUse = 0;
+ {
+ Byte inUse16[16];
+ int i;
+ for (i = 0; i < 16; i++)
+ inUse16[i] = (Byte)ReadBit(m_InStream);
+ for (i = 0; i < 256; i++)
+ if (inUse16[i >> 4])
+ {
+ if (ReadBit(m_InStream))
+ mtf.Add(numInUse++, (Byte)i);
+ }
+ if (numInUse == 0)
+ return S_FALSE;
+ // mtf.Init(numInUse);
+ }
+ int alphaSize = numInUse + 2;
+
+ int numTables = ReadBits(m_InStream, kNumTablesBits);
+ if (numTables < kNumTablesMin || numTables > kNumTablesMax)
+ return S_FALSE;
+
+ UInt32 numSelectors = ReadBits(m_InStream, kNumSelectorsBits);
+ if (numSelectors < 1 || numSelectors > kNumSelectorsMax)
+ return S_FALSE;
+
+ {
+ Byte mtfPos[kNumTablesMax];
+ int t = 0;
+ do
+ mtfPos[t] = (Byte)t;
+ while(++t < numTables);
+ UInt32 i = 0;
+ do
+ {
+ int j = 0;
+ while (ReadBit(m_InStream))
+ if (++j >= numTables)
+ return S_FALSE;
+ Byte tmp = mtfPos[j];
+ for (;j > 0; j--)
+ mtfPos[j] = mtfPos[j - 1];
+ m_Selectors[i] = mtfPos[0] = tmp;
+ }
+ while(++i < numSelectors);
+ }
+
+ int t = 0;
+ do
+ {
+ Byte lens[kMaxAlphaSize];
+ int len = (int)ReadBits(m_InStream, kNumLevelsBits);
+ int i;
+ for (i = 0; i < alphaSize; i++)
+ {
+ for (;;)
+ {
+ if (len < 1 || len > kMaxHuffmanLen)
+ return S_FALSE;
+ if (!ReadBit(m_InStream))
+ break;
+ len += 1 - (int)(ReadBit(m_InStream) << 1);
+ }
+ lens[i] = (Byte)len;
+ }
+ for (; i < kMaxAlphaSize; i++)
+ lens[i] = 0;
+ if(!m_HuffmanDecoders[t].SetCodeLengths(lens))
+ return S_FALSE;
+ }
+ while(++t < numTables);
+
+ {
+ for (int i = 0; i < 256; i++)
+ CharCounters[i] = 0;
+ }
+
+ UInt32 blockSize = 0;
+ {
+ UInt32 groupIndex = 0;
+ UInt32 groupSize = 0;
+ CHuffmanDecoder *huffmanDecoder = 0;
+ int runPower = 0;
+ UInt32 runCounter = 0;
+
+ for (;;)
+ {
+ if (groupSize == 0)
+ {
+ if (groupIndex >= numSelectors)
+ return S_FALSE;
+ groupSize = kGroupSize;
+ huffmanDecoder = &m_HuffmanDecoders[m_Selectors[groupIndex++]];
+ }
+ groupSize--;
+
+ UInt32 nextSym = huffmanDecoder->DecodeSymbol(m_InStream);
+
+ if (nextSym < 2)
+ {
+ runCounter += ((UInt32)(nextSym + 1) << runPower++);
+ if (blockSizeMax - blockSize < runCounter)
+ return S_FALSE;
+ continue;
+ }
+ if (runCounter != 0)
+ {
+ UInt32 b = (UInt32)mtf.GetHead();
+ CharCounters[b] += runCounter;
+ do
+ CharCounters[256 + blockSize++] = b;
+ while(--runCounter != 0);
+ runPower = 0;
+ }
+ if (nextSym <= (UInt32)numInUse)
+ {
+ UInt32 b = (UInt32)mtf.GetAndMove((int)nextSym - 1);
+ if (blockSize >= blockSizeMax)
+ return S_FALSE;
+ CharCounters[b]++;
+ CharCounters[256 + blockSize++] = b;
+ }
+ else if (nextSym == (UInt32)numInUse + 1)
+ break;
+ else
+ return S_FALSE;
+ }
+ }
+ *blockSizeRes = blockSize;
+ return (*origPtrRes < blockSize) ? S_OK : S_FALSE;
+}
+
+static void NO_INLINE DecodeBlock1(UInt32 *charCounters, UInt32 blockSize)
+{
+ {
+ UInt32 sum = 0;
+ for (UInt32 i = 0; i < 256; i++)
+ {
+ sum += charCounters[i];
+ charCounters[i] = sum - charCounters[i];
+ }
+ }
+
+ UInt32 *tt = charCounters + 256;
+ // Compute the T^(-1) vector
+ UInt32 i = 0;
+ do
+ tt[charCounters[tt[i] & 0xFF]++] |= (i << 8);
+ while(++i < blockSize);
+}
+
+static UInt32 NO_INLINE DecodeBlock2(const UInt32 *tt, UInt32 blockSize, UInt32 OrigPtr, COutBuffer &m_OutStream)
+{
+ CBZip2Crc crc;
+
+ // it's for speed optimization: prefetch & prevByte_init;
+ UInt32 tPos = tt[tt[OrigPtr] >> 8];
+ unsigned prevByte = (unsigned)(tPos & 0xFF);
+
+ unsigned numReps = 0;
+
+ do
+ {
+ unsigned b = (unsigned)(tPos & 0xFF);
+ tPos = tt[tPos >> 8];
+
+ if (numReps == kRleModeRepSize)
+ {
+ for (; b > 0; b--)
+ {
+ crc.UpdateByte(prevByte);
+ m_OutStream.WriteByte((Byte)prevByte);
+ }
+ numReps = 0;
+ continue;
+ }
+ if (b != prevByte)
+ numReps = 0;
+ numReps++;
+ prevByte = b;
+ crc.UpdateByte(b);
+ m_OutStream.WriteByte((Byte)b);
+
+ /*
+ prevByte = b;
+ crc.UpdateByte(b);
+ m_OutStream.WriteByte((Byte)b);
+ for (; --blockSize != 0;)
+ {
+ b = (unsigned)(tPos & 0xFF);
+ tPos = tt[tPos >> 8];
+ crc.UpdateByte(b);
+ m_OutStream.WriteByte((Byte)b);
+ if (b != prevByte)
+ {
+ prevByte = b;
+ continue;
+ }
+ if (--blockSize == 0)
+ break;
+
+ b = (unsigned)(tPos & 0xFF);
+ tPos = tt[tPos >> 8];
+ crc.UpdateByte(b);
+ m_OutStream.WriteByte((Byte)b);
+ if (b != prevByte)
+ {
+ prevByte = b;
+ continue;
+ }
+ if (--blockSize == 0)
+ break;
+
+ b = (unsigned)(tPos & 0xFF);
+ tPos = tt[tPos >> 8];
+ crc.UpdateByte(b);
+ m_OutStream.WriteByte((Byte)b);
+ if (b != prevByte)
+ {
+ prevByte = b;
+ continue;
+ }
+ --blockSize;
+ break;
+ }
+ if (blockSize == 0)
+ break;
+
+ b = (unsigned)(tPos & 0xFF);
+ tPos = tt[tPos >> 8];
+
+ for (; b > 0; b--)
+ {
+ crc.UpdateByte(prevByte);
+ m_OutStream.WriteByte((Byte)prevByte);
+ }
+ */
+ }
+ while(--blockSize != 0);
+ return crc.GetDigest();
+}
+
+static UInt32 NO_INLINE DecodeBlock2Rand(const UInt32 *tt, UInt32 blockSize, UInt32 OrigPtr, COutBuffer &m_OutStream)
+{
+ CBZip2Crc crc;
+
+ UInt32 randIndex = 1;
+ UInt32 randToGo = kRandNums[0] - 2;
+
+ unsigned numReps = 0;
+
+ // it's for speed optimization: prefetch & prevByte_init;
+ UInt32 tPos = tt[tt[OrigPtr] >> 8];
+ unsigned prevByte = (unsigned)(tPos & 0xFF);
+
+ do
+ {
+ unsigned b = (unsigned)(tPos & 0xFF);
+ tPos = tt[tPos >> 8];
+
+ {
+ if (randToGo == 0)
+ {
+ b ^= 1;
+ randToGo = kRandNums[randIndex++];
+ randIndex &= 0x1FF;
+ }
+ randToGo--;
+ }
+
+ if (numReps == kRleModeRepSize)
+ {
+ for (; b > 0; b--)
+ {
+ crc.UpdateByte(prevByte);
+ m_OutStream.WriteByte((Byte)prevByte);
+ }
+ numReps = 0;
+ continue;
+ }
+ if (b != prevByte)
+ numReps = 0;
+ numReps++;
+ prevByte = b;
+ crc.UpdateByte(b);
+ m_OutStream.WriteByte((Byte)b);
+ }
+ while(--blockSize != 0);
+ return crc.GetDigest();
+}
+
+
+CDecoder::CDecoder()
+{
+ #ifndef _7ZIP_ST
+ m_States = 0;
+ m_NumThreadsPrev = 0;
+ NumThreads = 1;
+ #endif
+ _needInStreamInit = true;
+}
+
+#ifndef _7ZIP_ST
+
+CDecoder::~CDecoder()
+{
+ Free();
+}
+
+#define RINOK_THREAD(x) { WRes __result_ = (x); if(__result_ != 0) return __result_; }
+
+HRESULT CDecoder::Create()
+{
+ RINOK_THREAD(CanProcessEvent.CreateIfNotCreated());
+ RINOK_THREAD(CanStartWaitingEvent.CreateIfNotCreated());
+ if (m_States != 0 && m_NumThreadsPrev == NumThreads)
+ return S_OK;
+ Free();
+ MtMode = (NumThreads > 1);
+ m_NumThreadsPrev = NumThreads;
+ try
+ {
+ m_States = new CState[NumThreads];
+ if (!m_States)
+ return E_OUTOFMEMORY;
+ }
+ catch(...) { return E_OUTOFMEMORY; }
+ for (UInt32 t = 0; t < NumThreads; t++)
+ {
+ CState &ti = m_States[t];
+ ti.Decoder = this;
+ if (MtMode)
+ {
+ HRESULT res = ti.Create();
+ if (res != S_OK)
+ {
+ NumThreads = t;
+ Free();
+ return res;
+ }
+ }
+ }
+ return S_OK;
+}
+
+void CDecoder::Free()
+{
+ if (!m_States)
+ return;
+ CloseThreads = true;
+ CanProcessEvent.Set();
+ for (UInt32 t = 0; t < NumThreads; t++)
+ {
+ CState &s = m_States[t];
+ if (MtMode)
+ s.Thread.Wait();
+ s.Free();
+ }
+ delete []m_States;
+ m_States = 0;
+}
+
+#endif
+
+HRESULT CDecoder::ReadSignatures(bool &wasFinished, UInt32 &crc)
+{
+ wasFinished = false;
+ Byte s[6];
+ for (int i = 0; i < 6; i++)
+ s[i] = ReadByte();
+ crc = ReadCrc();
+ if (s[0] == kFinSig0)
+ {
+ if (s[1] != kFinSig1 ||
+ s[2] != kFinSig2 ||
+ s[3] != kFinSig3 ||
+ s[4] != kFinSig4 ||
+ s[5] != kFinSig5)
+ return S_FALSE;
+
+ wasFinished = true;
+ return (crc == CombinedCrc.GetDigest()) ? S_OK : S_FALSE;
+ }
+ if (s[0] != kBlockSig0 ||
+ s[1] != kBlockSig1 ||
+ s[2] != kBlockSig2 ||
+ s[3] != kBlockSig3 ||
+ s[4] != kBlockSig4 ||
+ s[5] != kBlockSig5)
+ return S_FALSE;
+ CombinedCrc.Update(crc);
+ return S_OK;
+}
+
+HRESULT CDecoder::DecodeFile(bool &isBZ, ICompressProgressInfo *progress)
+{
+ Progress = progress;
+ #ifndef _7ZIP_ST
+ RINOK(Create());
+ for (UInt32 t = 0; t < NumThreads; t++)
+ {
+ CState &s = m_States[t];
+ if (!s.Alloc())
+ return E_OUTOFMEMORY;
+ if (MtMode)
+ {
+ RINOK(s.StreamWasFinishedEvent.Reset());
+ RINOK(s.WaitingWasStartedEvent.Reset());
+ RINOK(s.CanWriteEvent.Reset());
+ }
+ }
+ #else
+ if (!m_States[0].Alloc())
+ return E_OUTOFMEMORY;
+ #endif
+
+ isBZ = false;
+ Byte s[6];
+ int i;
+ for (i = 0; i < 4; i++)
+ s[i] = ReadByte();
+ if (s[0] != kArSig0 ||
+ s[1] != kArSig1 ||
+ s[2] != kArSig2 ||
+ s[3] <= kArSig3 ||
+ s[3] > kArSig3 + kBlockSizeMultMax)
+ return S_OK;
+ isBZ = true;
+ UInt32 dicSize = (UInt32)(s[3] - kArSig3) * kBlockSizeStep;
+
+ CombinedCrc.Init();
+ #ifndef _7ZIP_ST
+ if (MtMode)
+ {
+ NextBlockIndex = 0;
+ StreamWasFinished1 = StreamWasFinished2 = false;
+ CloseThreads = false;
+ CanStartWaitingEvent.Reset();
+ m_States[0].CanWriteEvent.Set();
+ BlockSizeMax = dicSize;
+ Result1 = Result2 = S_OK;
+ CanProcessEvent.Set();
+ UInt32 t;
+ for (t = 0; t < NumThreads; t++)
+ m_States[t].StreamWasFinishedEvent.Lock();
+ CanProcessEvent.Reset();
+ CanStartWaitingEvent.Set();
+ for (t = 0; t < NumThreads; t++)
+ m_States[t].WaitingWasStartedEvent.Lock();
+ CanStartWaitingEvent.Reset();
+ RINOK(Result2);
+ RINOK(Result1);
+ }
+ else
+ #endif
+ {
+ CState &state = m_States[0];
+ for (;;)
+ {
+ RINOK(SetRatioProgress(m_InStream.GetProcessedSize()));
+ bool wasFinished;
+ UInt32 crc;
+ RINOK(ReadSignatures(wasFinished, crc));
+ if (wasFinished)
+ return S_OK;
+
+ UInt32 blockSize, origPtr;
+ bool randMode;
+ RINOK(ReadBlock(&m_InStream, state.Counters, dicSize,
+ m_Selectors, m_HuffmanDecoders,
+ &blockSize, &origPtr, &randMode));
+ DecodeBlock1(state.Counters, blockSize);
+ if ((randMode ?
+ DecodeBlock2Rand(state.Counters + 256, blockSize, origPtr, m_OutStream) :
+ DecodeBlock2(state.Counters + 256, blockSize, origPtr, m_OutStream)) != crc)
+ return S_FALSE;
+ }
+ }
+ return SetRatioProgress(m_InStream.GetProcessedSize());
+}
+
+HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ bool &isBZ, ICompressProgressInfo *progress)
+{
+ isBZ = false;
+ try
+ {
+
+ if (!m_InStream.Create(kBufferSize))
+ return E_OUTOFMEMORY;
+ if (!m_OutStream.Create(kBufferSize))
+ return E_OUTOFMEMORY;
+
+ if (inStream)
+ m_InStream.SetStream(inStream);
+
+ CDecoderFlusher flusher(this, inStream != NULL);
+
+ if (_needInStreamInit)
+ {
+ m_InStream.Init();
+ _needInStreamInit = false;
+ }
+ _inStart = m_InStream.GetProcessedSize();
+
+ m_InStream.AlignToByte();
+
+ m_OutStream.SetStream(outStream);
+ m_OutStream.Init();
+
+ RINOK(DecodeFile(isBZ, progress));
+ flusher.NeedFlush = false;
+ return Flush();
+
+ }
+ catch(const CInBufferException &e) { return e.ErrorCode; }
+ catch(const COutBufferException &e) { return e.ErrorCode; }
+ catch(...) { return E_FAIL; }
+}
+
+STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)
+{
+ _needInStreamInit = true;
+ bool isBZ;
+ RINOK(CodeReal(inStream, outStream, isBZ, progress));
+ return isBZ ? S_OK : S_FALSE;
+}
+
+HRESULT CDecoder::CodeResume(ISequentialOutStream *outStream, bool &isBZ, ICompressProgressInfo *progress)
+{
+ return CodeReal(NULL, outStream, isBZ, progress);
+}
+
+STDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream) { m_InStream.SetStream(inStream); return S_OK; }
+STDMETHODIMP CDecoder::ReleaseInStream() { m_InStream.ReleaseStream(); return S_OK; }
+
+#ifndef _7ZIP_ST
+
+static THREAD_FUNC_DECL MFThread(void *p) { ((CState *)p)->ThreadFunc(); return 0; }
+
+HRESULT CState::Create()
+{
+ RINOK_THREAD(StreamWasFinishedEvent.CreateIfNotCreated());
+ RINOK_THREAD(WaitingWasStartedEvent.CreateIfNotCreated());
+ RINOK_THREAD(CanWriteEvent.CreateIfNotCreated());
+ RINOK_THREAD(Thread.Create(MFThread, this));
+ return S_OK;
+}
+
+void CState::FinishStream()
+{
+ Decoder->StreamWasFinished1 = true;
+ StreamWasFinishedEvent.Set();
+ Decoder->CS.Leave();
+ Decoder->CanStartWaitingEvent.Lock();
+ WaitingWasStartedEvent.Set();
+}
+
+void CState::ThreadFunc()
+{
+ for (;;)
+ {
+ Decoder->CanProcessEvent.Lock();
+ Decoder->CS.Enter();
+ if (Decoder->CloseThreads)
+ {
+ Decoder->CS.Leave();
+ return;
+ }
+ if (Decoder->StreamWasFinished1)
+ {
+ FinishStream();
+ continue;
+ }
+ HRESULT res = S_OK;
+
+ UInt32 blockIndex = Decoder->NextBlockIndex;
+ UInt32 nextBlockIndex = blockIndex + 1;
+ if (nextBlockIndex == Decoder->NumThreads)
+ nextBlockIndex = 0;
+ Decoder->NextBlockIndex = nextBlockIndex;
+ UInt32 crc;
+ UInt64 packSize = 0;
+ UInt32 blockSize = 0, origPtr = 0;
+ bool randMode = false;
+
+ try
+ {
+ bool wasFinished;
+ res = Decoder->ReadSignatures(wasFinished, crc);
+ if (res != S_OK)
+ {
+ Decoder->Result1 = res;
+ FinishStream();
+ continue;
+ }
+ if (wasFinished)
+ {
+ Decoder->Result1 = res;
+ FinishStream();
+ continue;
+ }
+
+ res = ReadBlock(&Decoder->m_InStream, Counters, Decoder->BlockSizeMax,
+ Decoder->m_Selectors, Decoder->m_HuffmanDecoders,
+ &blockSize, &origPtr, &randMode);
+ if (res != S_OK)
+ {
+ Decoder->Result1 = res;
+ FinishStream();
+ continue;
+ }
+ packSize = Decoder->m_InStream.GetProcessedSize();
+ }
+ catch(const CInBufferException &e) { res = e.ErrorCode; if (res != S_OK) res = E_FAIL; }
+ catch(...) { res = E_FAIL; }
+ if (res != S_OK)
+ {
+ Decoder->Result1 = res;
+ FinishStream();
+ continue;
+ }
+
+ Decoder->CS.Leave();
+
+ DecodeBlock1(Counters, blockSize);
+
+ bool needFinish = true;
+ try
+ {
+ Decoder->m_States[blockIndex].CanWriteEvent.Lock();
+ needFinish = Decoder->StreamWasFinished2;
+ if (!needFinish)
+ {
+ if ((randMode ?
+ DecodeBlock2Rand(Counters + 256, blockSize, origPtr, Decoder->m_OutStream) :
+ DecodeBlock2(Counters + 256, blockSize, origPtr, Decoder->m_OutStream)) == crc)
+ res = Decoder->SetRatioProgress(packSize);
+ else
+ res = S_FALSE;
+ }
+ }
+ catch(const COutBufferException &e) { res = e.ErrorCode; if (res != S_OK) res = E_FAIL; }
+ catch(...) { res = E_FAIL; }
+ if (res != S_OK)
+ {
+ Decoder->Result2 = res;
+ Decoder->StreamWasFinished2 = true;
+ }
+ Decoder->m_States[nextBlockIndex].CanWriteEvent.Set();
+ if (res != S_OK || needFinish)
+ {
+ StreamWasFinishedEvent.Set();
+ Decoder->CanStartWaitingEvent.Lock();
+ WaitingWasStartedEvent.Set();
+ }
+ }
+}
+
+STDMETHODIMP CDecoder::SetNumberOfThreads(UInt32 numThreads)
+{
+ NumThreads = numThreads;
+ if (NumThreads < 1)
+ NumThreads = 1;
+ if (NumThreads > kNumThreadsMax)
+ NumThreads = kNumThreadsMax;
+ return S_OK;
+}
+
+#endif
+
+HRESULT CDecoder::SetRatioProgress(UInt64 packSize)
+{
+ if (!Progress)
+ return S_OK;
+ packSize -= _inStart;
+ UInt64 unpackSize = m_OutStream.GetProcessedSize();
+ return Progress->SetRatioInfo(&packSize, &unpackSize);
+}
+
+
+// ---------- NSIS ----------
+
+enum
+{
+ NSIS_STATE_INIT,
+ NSIS_STATE_NEW_BLOCK,
+ NSIS_STATE_DATA,
+ NSIS_STATE_FINISHED,
+ NSIS_STATE_ERROR
+};
+
+STDMETHODIMP CNsisDecoder::SetInStream(ISequentialInStream *inStream) { m_InStream.SetStream(inStream); return S_OK; }
+STDMETHODIMP CNsisDecoder::ReleaseInStream() { m_InStream.ReleaseStream(); return S_OK; }
+
+STDMETHODIMP CNsisDecoder::SetOutStreamSize(const UInt64 * /* outSize */)
+{
+ _nsisState = NSIS_STATE_INIT;
+ return S_OK;
+}
+
+STDMETHODIMP CNsisDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)
+{
+ try {
+
+ *processedSize = 0;
+ if (_nsisState == NSIS_STATE_FINISHED)
+ return S_OK;
+ if (_nsisState == NSIS_STATE_ERROR)
+ return S_FALSE;
+ if (size == 0)
+ return S_OK;
+
+ CState &state = m_State;
+
+ if (_nsisState == NSIS_STATE_INIT)
+ {
+ if (!m_InStream.Create(kBufferSize))
+ return E_OUTOFMEMORY;
+ if (!state.Alloc())
+ return E_OUTOFMEMORY;
+ m_InStream.Init();
+ _nsisState = NSIS_STATE_NEW_BLOCK;
+ }
+
+ if (_nsisState == NSIS_STATE_NEW_BLOCK)
+ {
+ Byte b = (Byte)m_InStream.ReadBits(8);
+ if (b == kFinSig0)
+ {
+ _nsisState = NSIS_STATE_FINISHED;
+ return S_OK;
+ }
+ if (b != kBlockSig0)
+ {
+ _nsisState = NSIS_STATE_ERROR;
+ return S_FALSE;
+ }
+ UInt32 origPtr;
+ RINOK(ReadBlock(&m_InStream, state.Counters, 9 * kBlockSizeStep,
+ m_Selectors, m_HuffmanDecoders, &_blockSize, &origPtr, NULL));
+ DecodeBlock1(state.Counters, _blockSize);
+ const UInt32 *tt = state.Counters + 256;
+ _tPos = tt[tt[origPtr] >> 8];
+ _prevByte = (unsigned)(_tPos & 0xFF);
+ _numReps = 0;
+ _repRem = 0;
+ _nsisState = NSIS_STATE_DATA;
+ }
+
+ UInt32 tPos = _tPos;
+ unsigned prevByte = _prevByte;
+ unsigned numReps = _numReps;
+ UInt32 blockSize = _blockSize;
+ const UInt32 *tt = state.Counters + 256;
+
+ while (_repRem)
+ {
+ _repRem--;
+ *(Byte *)data = (Byte)prevByte;
+ data = (Byte *)data + 1;
+ (*processedSize)++;
+ if (--size == 0)
+ return S_OK;
+ }
+
+ if (blockSize == 0)
+ {
+ _nsisState = NSIS_STATE_NEW_BLOCK;
+ return S_OK;
+ }
+
+ do
+ {
+ unsigned b = (unsigned)(tPos & 0xFF);
+ tPos = tt[tPos >> 8];
+ blockSize--;
+
+ if (numReps == kRleModeRepSize)
+ {
+ numReps = 0;
+ while (b)
+ {
+ b--;
+ *(Byte *)data = (Byte)prevByte;
+ data = (Byte *)data + 1;
+ (*processedSize)++;
+ if (--size == 0)
+ break;
+ }
+ _repRem = b;
+ continue;
+ }
+ if (b != prevByte)
+ numReps = 0;
+ numReps++;
+ prevByte = b;
+ *(Byte *)data = (Byte)b;
+ data = (Byte *)data + 1;
+ (*processedSize)++;
+ size--;
+ }
+ while (size && blockSize);
+ _tPos = tPos;
+ _prevByte = prevByte;
+ _numReps = numReps;
+ _blockSize = blockSize;
+ return S_OK;
+
+ }
+ catch(const CInBufferException &e) { return e.ErrorCode; }
+ catch(...) { return S_FALSE; }
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Decoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Decoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Decoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Decoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,205 @@
+// Compress/BZip2Decoder.h
+
+#ifndef __COMPRESS_BZIP2_DECODER_H
+#define __COMPRESS_BZIP2_DECODER_H
+
+#include "../../Common/MyCom.h"
+
+#ifndef _7ZIP_ST
+#include "../../Windows/Synchronization.h"
+#include "../../Windows/Thread.h"
+#endif
+
+#include "../ICoder.h"
+
+#include "../Common/InBuffer.h"
+#include "../Common/OutBuffer.h"
+
+#include "BitmDecoder.h"
+#include "BZip2Const.h"
+#include "BZip2Crc.h"
+#include "HuffmanDecoder.h"
+
+namespace NCompress {
+namespace NBZip2 {
+
+typedef NCompress::NHuffman::CDecoder<kMaxHuffmanLen, kMaxAlphaSize> CHuffmanDecoder;
+
+class CDecoder;
+
+struct CState
+{
+ UInt32 *Counters;
+
+ #ifndef _7ZIP_ST
+
+ CDecoder *Decoder;
+ NWindows::CThread Thread;
+ bool m_OptimizeNumTables;
+
+ NWindows::NSynchronization::CAutoResetEvent StreamWasFinishedEvent;
+ NWindows::NSynchronization::CAutoResetEvent WaitingWasStartedEvent;
+
+ // it's not member of this thread. We just need one event per thread
+ NWindows::NSynchronization::CAutoResetEvent CanWriteEvent;
+
+ Byte MtPad[1 << 8]; // It's pad for Multi-Threading. Must be >= Cache_Line_Size.
+
+ HRESULT Create();
+ void FinishStream();
+ void ThreadFunc();
+
+ #endif
+
+ CState(): Counters(0) {}
+ ~CState() { Free(); }
+ bool Alloc();
+ void Free();
+};
+
+class CDecoder :
+ public ICompressCoder,
+ #ifndef _7ZIP_ST
+ public ICompressSetCoderMt,
+ #endif
+ public CMyUnknownImp
+{
+public:
+ COutBuffer m_OutStream;
+ Byte MtPad[1 << 8]; // It's pad for Multi-Threading. Must be >= Cache_Line_Size.
+ NBitm::CDecoder<CInBuffer> m_InStream;
+ Byte m_Selectors[kNumSelectorsMax];
+ CHuffmanDecoder m_HuffmanDecoders[kNumTablesMax];
+ UInt64 _inStart;
+
+private:
+
+ bool _needInStreamInit;
+
+ UInt32 ReadBits(unsigned numBits);
+ Byte ReadByte();
+ bool ReadBit();
+ UInt32 ReadCrc();
+ HRESULT DecodeFile(bool &isBZ, ICompressProgressInfo *progress);
+ HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ bool &isBZ, ICompressProgressInfo *progress);
+ class CDecoderFlusher
+ {
+ CDecoder *_decoder;
+ public:
+ bool NeedFlush;
+ bool ReleaseInStream;
+ CDecoderFlusher(CDecoder *decoder, bool releaseInStream):
+ _decoder(decoder),
+ ReleaseInStream(releaseInStream),
+ NeedFlush(true) {}
+ ~CDecoderFlusher()
+ {
+ if (NeedFlush)
+ _decoder->Flush();
+ _decoder->ReleaseStreams(ReleaseInStream);
+ }
+ };
+
+public:
+ CBZip2CombinedCrc CombinedCrc;
+ ICompressProgressInfo *Progress;
+
+ #ifndef _7ZIP_ST
+ CState *m_States;
+ UInt32 m_NumThreadsPrev;
+
+ NWindows::NSynchronization::CManualResetEvent CanProcessEvent;
+ NWindows::NSynchronization::CCriticalSection CS;
+ UInt32 NumThreads;
+ bool MtMode;
+ UInt32 NextBlockIndex;
+ bool CloseThreads;
+ bool StreamWasFinished1;
+ bool StreamWasFinished2;
+ NWindows::NSynchronization::CManualResetEvent CanStartWaitingEvent;
+
+ HRESULT Result1;
+ HRESULT Result2;
+
+ UInt32 BlockSizeMax;
+ ~CDecoder();
+ HRESULT Create();
+ void Free();
+
+ #else
+ CState m_States[1];
+ #endif
+
+ CDecoder();
+
+ HRESULT SetRatioProgress(UInt64 packSize);
+ HRESULT ReadSignatures(bool &wasFinished, UInt32 &crc);
+
+ HRESULT Flush() { return m_OutStream.Flush(); }
+ void ReleaseStreams(bool releaseInStream)
+ {
+ if (releaseInStream)
+ m_InStream.ReleaseStream();
+ m_OutStream.ReleaseStream();
+ }
+
+ MY_QUERYINTERFACE_BEGIN2(ICompressCoder)
+ #ifndef _7ZIP_ST
+ MY_QUERYINTERFACE_ENTRY(ICompressSetCoderMt)
+ #endif
+
+ MY_QUERYINTERFACE_END
+ MY_ADDREF_RELEASE
+
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ STDMETHOD(SetInStream)(ISequentialInStream *inStream);
+ STDMETHOD(ReleaseInStream)();
+
+ HRESULT CodeResume(ISequentialOutStream *outStream, bool &isBZ, ICompressProgressInfo *progress);
+ UInt64 GetInputProcessedSize() const { return m_InStream.GetProcessedSize(); }
+
+ #ifndef _7ZIP_ST
+ STDMETHOD(SetNumberOfThreads)(UInt32 numThreads);
+ #endif
+};
+
+
+class CNsisDecoder :
+ public ISequentialInStream,
+ public ICompressSetInStream,
+ public ICompressSetOutStreamSize,
+ public CMyUnknownImp
+{
+ NBitm::CDecoder<CInBuffer> m_InStream;
+ Byte m_Selectors[kNumSelectorsMax];
+ CHuffmanDecoder m_HuffmanDecoders[kNumTablesMax];
+ CState m_State;
+
+ int _nsisState;
+ UInt32 _tPos;
+ unsigned _prevByte;
+ unsigned _repRem;
+ unsigned _numReps;
+ UInt32 _blockSize;
+
+public:
+
+ MY_QUERYINTERFACE_BEGIN2(ISequentialInStream)
+ MY_QUERYINTERFACE_ENTRY(ICompressSetInStream)
+ MY_QUERYINTERFACE_ENTRY(ICompressSetOutStreamSize)
+ MY_QUERYINTERFACE_END
+ MY_ADDREF_RELEASE
+
+ STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
+ STDMETHOD(SetInStream)(ISequentialInStream *inStream);
+ STDMETHOD(ReleaseInStream)();
+ STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Encoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Encoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Encoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Encoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,895 @@
+// BZip2Encoder.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/Alloc.h"
+#include "../../../C/BwtSort.h"
+#include "../../../C/HuffEnc.h"
+
+#include "BZip2Crc.h"
+#include "BZip2Encoder.h"
+#include "Mtf8.h"
+
+namespace NCompress {
+namespace NBZip2 {
+
+const int kMaxHuffmanLenForEncoding = 16; // it must be < kMaxHuffmanLen = 20
+
+static const UInt32 kBufferSize = (1 << 17);
+static const int kNumHuffPasses = 4;
+
+bool CThreadInfo::Alloc()
+{
+ if (m_BlockSorterIndex == 0)
+ {
+ m_BlockSorterIndex = (UInt32 *)::BigAlloc(BLOCK_SORT_BUF_SIZE(kBlockSizeMax) * sizeof(UInt32));
+ if (m_BlockSorterIndex == 0)
+ return false;
+ }
+
+ if (m_Block == 0)
+ {
+ m_Block = (Byte *)::MidAlloc(kBlockSizeMax * 5 + kBlockSizeMax / 10 + (20 << 10));
+ if (m_Block == 0)
+ return false;
+ m_MtfArray = m_Block + kBlockSizeMax;
+ m_TempArray = m_MtfArray + kBlockSizeMax * 2 + 2;
+ }
+ return true;
+}
+
+void CThreadInfo::Free()
+{
+ ::BigFree(m_BlockSorterIndex);
+ m_BlockSorterIndex = 0;
+ ::MidFree(m_Block);
+ m_Block = 0;
+}
+
+#ifndef _7ZIP_ST
+
+static THREAD_FUNC_DECL MFThread(void *threadCoderInfo)
+{
+ return ((CThreadInfo *)threadCoderInfo)->ThreadFunc();
+}
+
+#define RINOK_THREAD(x) { WRes __result_ = (x); if(__result_ != 0) return __result_; }
+
+HRESULT CThreadInfo::Create()
+{
+ RINOK_THREAD(StreamWasFinishedEvent.Create());
+ RINOK_THREAD(WaitingWasStartedEvent.Create());
+ RINOK_THREAD(CanWriteEvent.Create());
+ RINOK_THREAD(Thread.Create(MFThread, this));
+ return S_OK;
+}
+
+void CThreadInfo::FinishStream(bool needLeave)
+{
+ Encoder->StreamWasFinished = true;
+ StreamWasFinishedEvent.Set();
+ if (needLeave)
+ Encoder->CS.Leave();
+ Encoder->CanStartWaitingEvent.Lock();
+ WaitingWasStartedEvent.Set();
+}
+
+DWORD CThreadInfo::ThreadFunc()
+{
+ for (;;)
+ {
+ Encoder->CanProcessEvent.Lock();
+ Encoder->CS.Enter();
+ if (Encoder->CloseThreads)
+ {
+ Encoder->CS.Leave();
+ return 0;
+ }
+ if (Encoder->StreamWasFinished)
+ {
+ FinishStream(true);
+ continue;
+ }
+ HRESULT res = S_OK;
+ bool needLeave = true;
+ try
+ {
+ UInt32 blockSize = Encoder->ReadRleBlock(m_Block);
+ m_PackSize = Encoder->m_InStream.GetProcessedSize();
+ m_BlockIndex = Encoder->NextBlockIndex;
+ if (++Encoder->NextBlockIndex == Encoder->NumThreads)
+ Encoder->NextBlockIndex = 0;
+ if (blockSize == 0)
+ {
+ FinishStream(true);
+ continue;
+ }
+ Encoder->CS.Leave();
+ needLeave = false;
+ res = EncodeBlock3(blockSize);
+ }
+ catch(const CInBufferException &e) { res = e.ErrorCode; }
+ catch(const COutBufferException &e) { res = e.ErrorCode; }
+ catch(...) { res = E_FAIL; }
+ if (res != S_OK)
+ {
+ Encoder->Result = res;
+ FinishStream(needLeave);
+ continue;
+ }
+ }
+}
+
+#endif
+
+CEncoder::CEncoder():
+ NumPasses(1),
+ m_OptimizeNumTables(false),
+ m_BlockSizeMult(kBlockSizeMultMax)
+{
+ #ifndef _7ZIP_ST
+ ThreadsInfo = 0;
+ m_NumThreadsPrev = 0;
+ NumThreads = 1;
+ #endif
+}
+
+#ifndef _7ZIP_ST
+CEncoder::~CEncoder()
+{
+ Free();
+}
+
+HRESULT CEncoder::Create()
+{
+ RINOK_THREAD(CanProcessEvent.CreateIfNotCreated());
+ RINOK_THREAD(CanStartWaitingEvent.CreateIfNotCreated());
+ if (ThreadsInfo != 0 && m_NumThreadsPrev == NumThreads)
+ return S_OK;
+ try
+ {
+ Free();
+ MtMode = (NumThreads > 1);
+ m_NumThreadsPrev = NumThreads;
+ ThreadsInfo = new CThreadInfo[NumThreads];
+ if (ThreadsInfo == 0)
+ return E_OUTOFMEMORY;
+ }
+ catch(...) { return E_OUTOFMEMORY; }
+ for (UInt32 t = 0; t < NumThreads; t++)
+ {
+ CThreadInfo &ti = ThreadsInfo[t];
+ ti.Encoder = this;
+ if (MtMode)
+ {
+ HRESULT res = ti.Create();
+ if (res != S_OK)
+ {
+ NumThreads = t;
+ Free();
+ return res;
+ }
+ }
+ }
+ return S_OK;
+}
+
+void CEncoder::Free()
+{
+ if (!ThreadsInfo)
+ return;
+ CloseThreads = true;
+ CanProcessEvent.Set();
+ for (UInt32 t = 0; t < NumThreads; t++)
+ {
+ CThreadInfo &ti = ThreadsInfo[t];
+ if (MtMode)
+ ti.Thread.Wait();
+ ti.Free();
+ }
+ delete []ThreadsInfo;
+ ThreadsInfo = 0;
+}
+#endif
+
+UInt32 CEncoder::ReadRleBlock(Byte *buffer)
+{
+ UInt32 i = 0;
+ Byte prevByte;
+ if (m_InStream.ReadByte(prevByte))
+ {
+ UInt32 blockSize = m_BlockSizeMult * kBlockSizeStep - 1;
+ int numReps = 1;
+ buffer[i++] = prevByte;
+ while (i < blockSize) // "- 1" to support RLE
+ {
+ Byte b;
+ if (!m_InStream.ReadByte(b))
+ break;
+ if (b != prevByte)
+ {
+ if (numReps >= kRleModeRepSize)
+ buffer[i++] = (Byte)(numReps - kRleModeRepSize);
+ buffer[i++] = b;
+ numReps = 1;
+ prevByte = b;
+ continue;
+ }
+ numReps++;
+ if (numReps <= kRleModeRepSize)
+ buffer[i++] = b;
+ else if (numReps == kRleModeRepSize + 255)
+ {
+ buffer[i++] = (Byte)(numReps - kRleModeRepSize);
+ numReps = 0;
+ }
+ }
+ // it's to support original BZip2 decoder
+ if (numReps >= kRleModeRepSize)
+ buffer[i++] = (Byte)(numReps - kRleModeRepSize);
+ }
+ return i;
+}
+
+void CThreadInfo::WriteBits2(UInt32 value, UInt32 numBits)
+ { m_OutStreamCurrent->WriteBits(value, numBits); }
+void CThreadInfo::WriteByte2(Byte b) { WriteBits2(b , 8); }
+void CThreadInfo::WriteBit2(bool v) { WriteBits2((v ? 1 : 0), 1); }
+void CThreadInfo::WriteCrc2(UInt32 v)
+{
+ for (int i = 0; i < 4; i++)
+ WriteByte2(((Byte)(v >> (24 - i * 8))));
+}
+
+void CEncoder::WriteBits(UInt32 value, UInt32 numBits)
+ { m_OutStream.WriteBits(value, numBits); }
+void CEncoder::WriteByte(Byte b) { WriteBits(b , 8); }
+void CEncoder::WriteBit(bool v) { WriteBits((v ? 1 : 0), 1); }
+void CEncoder::WriteCrc(UInt32 v)
+{
+ for (int i = 0; i < 4; i++)
+ WriteByte(((Byte)(v >> (24 - i * 8))));
+}
+
+
+// blockSize > 0
+void CThreadInfo::EncodeBlock(const Byte *block, UInt32 blockSize)
+{
+ WriteBit2(false); // Randomised = false
+
+ {
+ UInt32 origPtr = BlockSort(m_BlockSorterIndex, block, blockSize);
+ // if (m_BlockSorterIndex[origPtr] != 0) throw 1;
+ m_BlockSorterIndex[origPtr] = blockSize;
+ WriteBits2(origPtr, kNumOrigBits);
+ }
+
+ CMtf8Encoder mtf;
+ int numInUse = 0;
+ {
+ bool inUse[256];
+ bool inUse16[16];
+ UInt32 i;
+ for (i = 0; i < 256; i++)
+ inUse[i] = false;
+ for (i = 0; i < 16; i++)
+ inUse16[i] = false;
+ for (i = 0; i < blockSize; i++)
+ inUse[block[i]] = true;
+ for (i = 0; i < 256; i++)
+ if (inUse[i])
+ {
+ inUse16[i >> 4] = true;
+ mtf.Buf[numInUse++] = (Byte)i;
+ }
+ for (i = 0; i < 16; i++)
+ WriteBit2(inUse16[i]);
+ for (i = 0; i < 256; i++)
+ if (inUse16[i >> 4])
+ WriteBit2(inUse[i]);
+ }
+ int alphaSize = numInUse + 2;
+
+ Byte *mtfs = m_MtfArray;
+ UInt32 mtfArraySize = 0;
+ UInt32 symbolCounts[kMaxAlphaSize];
+ {
+ for (int i = 0; i < kMaxAlphaSize; i++)
+ symbolCounts[i] = 0;
+ }
+
+ {
+ UInt32 rleSize = 0;
+ UInt32 i = 0;
+ const UInt32 *bsIndex = m_BlockSorterIndex;
+ block--;
+ do
+ {
+ int pos = mtf.FindAndMove(block[bsIndex[i]]);
+ if (pos == 0)
+ rleSize++;
+ else
+ {
+ while (rleSize != 0)
+ {
+ rleSize--;
+ mtfs[mtfArraySize++] = (Byte)(rleSize & 1);
+ symbolCounts[rleSize & 1]++;
+ rleSize >>= 1;
+ }
+ if (pos >= 0xFE)
+ {
+ mtfs[mtfArraySize++] = 0xFF;
+ mtfs[mtfArraySize++] = (Byte)(pos - 0xFE);
+ }
+ else
+ mtfs[mtfArraySize++] = (Byte)(pos + 1);
+ symbolCounts[pos + 1]++;
+ }
+ }
+ while (++i < blockSize);
+
+ while (rleSize != 0)
+ {
+ rleSize--;
+ mtfs[mtfArraySize++] = (Byte)(rleSize & 1);
+ symbolCounts[rleSize & 1]++;
+ rleSize >>= 1;
+ }
+
+ if (alphaSize < 256)
+ mtfs[mtfArraySize++] = (Byte)(alphaSize - 1);
+ else
+ {
+ mtfs[mtfArraySize++] = 0xFF;
+ mtfs[mtfArraySize++] = (Byte)(alphaSize - 256);
+ }
+ symbolCounts[alphaSize - 1]++;
+ }
+
+ UInt32 numSymbols = 0;
+ {
+ for (int i = 0; i < kMaxAlphaSize; i++)
+ numSymbols += symbolCounts[i];
+ }
+
+ int bestNumTables = kNumTablesMin;
+ UInt32 bestPrice = 0xFFFFFFFF;
+ UInt32 startPos = m_OutStreamCurrent->GetPos();
+ Byte startCurByte = m_OutStreamCurrent->GetCurByte();
+ for (int nt = kNumTablesMin; nt <= kNumTablesMax + 1; nt++)
+ {
+ int numTables;
+
+ if(m_OptimizeNumTables)
+ {
+ m_OutStreamCurrent->SetPos(startPos);
+ m_OutStreamCurrent->SetCurState((startPos & 7), startCurByte);
+ if (nt <= kNumTablesMax)
+ numTables = nt;
+ else
+ numTables = bestNumTables;
+ }
+ else
+ {
+ if (numSymbols < 200) numTables = 2;
+ else if (numSymbols < 600) numTables = 3;
+ else if (numSymbols < 1200) numTables = 4;
+ else if (numSymbols < 2400) numTables = 5;
+ else numTables = 6;
+ }
+
+ WriteBits2(numTables, kNumTablesBits);
+
+ UInt32 numSelectors = (numSymbols + kGroupSize - 1) / kGroupSize;
+ WriteBits2(numSelectors, kNumSelectorsBits);
+
+ {
+ UInt32 remFreq = numSymbols;
+ int gs = 0;
+ int t = numTables;
+ do
+ {
+ UInt32 tFreq = remFreq / t;
+ int ge = gs;
+ UInt32 aFreq = 0;
+ while (aFreq < tFreq) // && ge < alphaSize)
+ aFreq += symbolCounts[ge++];
+
+ if (ge - 1 > gs && t != numTables && t != 1 && (((numTables - t) & 1) == 1))
+ aFreq -= symbolCounts[--ge];
+
+ Byte *lens = Lens[t - 1];
+ int i = 0;
+ do
+ lens[i] = (i >= gs && i < ge) ? 0 : 1;
+ while (++i < alphaSize);
+ gs = ge;
+ remFreq -= aFreq;
+ }
+ while(--t != 0);
+ }
+
+
+ for (int pass = 0; pass < kNumHuffPasses; pass++)
+ {
+ {
+ int t = 0;
+ do
+ memset(Freqs[t], 0, sizeof(Freqs[t]));
+ while(++t < numTables);
+ }
+
+ {
+ UInt32 mtfPos = 0;
+ UInt32 g = 0;
+ do
+ {
+ UInt32 symbols[kGroupSize];
+ int i = 0;
+ do
+ {
+ UInt32 symbol = mtfs[mtfPos++];
+ if (symbol >= 0xFF)
+ symbol += mtfs[mtfPos++];
+ symbols[i] = symbol;
+ }
+ while (++i < kGroupSize && mtfPos < mtfArraySize);
+
+ UInt32 bestPrice = 0xFFFFFFFF;
+ int t = 0;
+ do
+ {
+ const Byte *lens = Lens[t];
+ UInt32 price = 0;
+ int j = 0;
+ do
+ price += lens[symbols[j]];
+ while (++j < i);
+ if (price < bestPrice)
+ {
+ m_Selectors[g] = (Byte)t;
+ bestPrice = price;
+ }
+ }
+ while(++t < numTables);
+ UInt32 *freqs = Freqs[m_Selectors[g++]];
+ int j = 0;
+ do
+ freqs[symbols[j]]++;
+ while (++j < i);
+ }
+ while (mtfPos < mtfArraySize);
+ }
+
+ int t = 0;
+ do
+ {
+ UInt32 *freqs = Freqs[t];
+ int i = 0;
+ do
+ if (freqs[i] == 0)
+ freqs[i] = 1;
+ while(++i < alphaSize);
+ Huffman_Generate(freqs, Codes[t], Lens[t], kMaxAlphaSize, kMaxHuffmanLenForEncoding);
+ }
+ while(++t < numTables);
+ }
+
+ {
+ Byte mtfSel[kNumTablesMax];
+ {
+ int t = 0;
+ do
+ mtfSel[t] = (Byte)t;
+ while(++t < numTables);
+ }
+
+ UInt32 i = 0;
+ do
+ {
+ Byte sel = m_Selectors[i];
+ int pos;
+ for (pos = 0; mtfSel[pos] != sel; pos++)
+ WriteBit2(true);
+ WriteBit2(false);
+ for (; pos > 0; pos--)
+ mtfSel[pos] = mtfSel[pos - 1];
+ mtfSel[0] = sel;
+ }
+ while(++i < numSelectors);
+ }
+
+ {
+ int t = 0;
+ do
+ {
+ const Byte *lens = Lens[t];
+ UInt32 len = lens[0];
+ WriteBits2(len, kNumLevelsBits);
+ int i = 0;
+ do
+ {
+ UInt32 level = lens[i];
+ while (len != level)
+ {
+ WriteBit2(true);
+ if (len < level)
+ {
+ WriteBit2(false);
+ len++;
+ }
+ else
+ {
+ WriteBit2(true);
+ len--;
+ }
+ }
+ WriteBit2(false);
+ }
+ while (++i < alphaSize);
+ }
+ while(++t < numTables);
+ }
+
+ {
+ UInt32 groupSize = 0;
+ UInt32 groupIndex = 0;
+ const Byte *lens = 0;
+ const UInt32 *codes = 0;
+ UInt32 mtfPos = 0;
+ do
+ {
+ UInt32 symbol = mtfs[mtfPos++];
+ if (symbol >= 0xFF)
+ symbol += mtfs[mtfPos++];
+ if (groupSize == 0)
+ {
+ groupSize = kGroupSize;
+ int t = m_Selectors[groupIndex++];
+ lens = Lens[t];
+ codes = Codes[t];
+ }
+ groupSize--;
+ m_OutStreamCurrent->WriteBits(codes[symbol], lens[symbol]);
+ }
+ while (mtfPos < mtfArraySize);
+ }
+
+ if (!m_OptimizeNumTables)
+ break;
+ UInt32 price = m_OutStreamCurrent->GetPos() - startPos;
+ if (price <= bestPrice)
+ {
+ if (nt == kNumTablesMax)
+ break;
+ bestPrice = price;
+ bestNumTables = nt;
+ }
+ }
+}
+
+// blockSize > 0
+UInt32 CThreadInfo::EncodeBlockWithHeaders(const Byte *block, UInt32 blockSize)
+{
+ WriteByte2(kBlockSig0);
+ WriteByte2(kBlockSig1);
+ WriteByte2(kBlockSig2);
+ WriteByte2(kBlockSig3);
+ WriteByte2(kBlockSig4);
+ WriteByte2(kBlockSig5);
+
+ CBZip2Crc crc;
+ int numReps = 0;
+ Byte prevByte = block[0];
+ UInt32 i = 0;
+ do
+ {
+ Byte b = block[i];
+ if (numReps == kRleModeRepSize)
+ {
+ for (; b > 0; b--)
+ crc.UpdateByte(prevByte);
+ numReps = 0;
+ continue;
+ }
+ if (prevByte == b)
+ numReps++;
+ else
+ {
+ numReps = 1;
+ prevByte = b;
+ }
+ crc.UpdateByte(b);
+ }
+ while (++i < blockSize);
+ UInt32 crcRes = crc.GetDigest();
+ WriteCrc2(crcRes);
+ EncodeBlock(block, blockSize);
+ return crcRes;
+}
+
+void CThreadInfo::EncodeBlock2(const Byte *block, UInt32 blockSize, UInt32 numPasses)
+{
+ UInt32 numCrcs = m_NumCrcs;
+ bool needCompare = false;
+
+ UInt32 startBytePos = m_OutStreamCurrent->GetBytePos();
+ UInt32 startPos = m_OutStreamCurrent->GetPos();
+ Byte startCurByte = m_OutStreamCurrent->GetCurByte();
+ Byte endCurByte = 0;
+ UInt32 endPos = 0;
+ if (numPasses > 1 && blockSize >= (1 << 10))
+ {
+ UInt32 blockSize0 = blockSize / 2;
+ for (;(block[blockSize0] == block[blockSize0 - 1] ||
+ block[blockSize0 - 1] == block[blockSize0 - 2]) &&
+ blockSize0 < blockSize; blockSize0++);
+ if (blockSize0 < blockSize)
+ {
+ EncodeBlock2(block, blockSize0, numPasses - 1);
+ EncodeBlock2(block + blockSize0, blockSize - blockSize0, numPasses - 1);
+ endPos = m_OutStreamCurrent->GetPos();
+ endCurByte = m_OutStreamCurrent->GetCurByte();
+ if ((endPos & 7) > 0)
+ WriteBits2(0, 8 - (endPos & 7));
+ m_OutStreamCurrent->SetCurState((startPos & 7), startCurByte);
+ needCompare = true;
+ }
+ }
+
+ UInt32 startBytePos2 = m_OutStreamCurrent->GetBytePos();
+ UInt32 startPos2 = m_OutStreamCurrent->GetPos();
+ UInt32 crcVal = EncodeBlockWithHeaders(block, blockSize);
+ UInt32 endPos2 = m_OutStreamCurrent->GetPos();
+
+ if (needCompare)
+ {
+ UInt32 size2 = endPos2 - startPos2;
+ if (size2 < endPos - startPos)
+ {
+ UInt32 numBytes = m_OutStreamCurrent->GetBytePos() - startBytePos2;
+ Byte *buffer = m_OutStreamCurrent->GetStream();
+ for (UInt32 i = 0; i < numBytes; i++)
+ buffer[startBytePos + i] = buffer[startBytePos2 + i];
+ m_OutStreamCurrent->SetPos(startPos + endPos2 - startPos2);
+ m_NumCrcs = numCrcs;
+ m_CRCs[m_NumCrcs++] = crcVal;
+ }
+ else
+ {
+ m_OutStreamCurrent->SetPos(endPos);
+ m_OutStreamCurrent->SetCurState((endPos & 7), endCurByte);
+ }
+ }
+ else
+ {
+ m_NumCrcs = numCrcs;
+ m_CRCs[m_NumCrcs++] = crcVal;
+ }
+}
+
+HRESULT CThreadInfo::EncodeBlock3(UInt32 blockSize)
+{
+ CMsbfEncoderTemp outStreamTemp;
+ outStreamTemp.SetStream(m_TempArray);
+ outStreamTemp.Init();
+ m_OutStreamCurrent = &outStreamTemp;
+
+ m_NumCrcs = 0;
+
+ EncodeBlock2(m_Block, blockSize, Encoder->NumPasses);
+
+ #ifndef _7ZIP_ST
+ if (Encoder->MtMode)
+ Encoder->ThreadsInfo[m_BlockIndex].CanWriteEvent.Lock();
+ #endif
+ for (UInt32 i = 0; i < m_NumCrcs; i++)
+ Encoder->CombinedCrc.Update(m_CRCs[i]);
+ Encoder->WriteBytes(m_TempArray, outStreamTemp.GetPos(), outStreamTemp.GetCurByte());
+ HRESULT res = S_OK;
+ #ifndef _7ZIP_ST
+ if (Encoder->MtMode)
+ {
+ UInt32 blockIndex = m_BlockIndex + 1;
+ if (blockIndex == Encoder->NumThreads)
+ blockIndex = 0;
+
+ if (Encoder->Progress)
+ {
+ UInt64 unpackSize = Encoder->m_OutStream.GetProcessedSize();
+ res = Encoder->Progress->SetRatioInfo(&m_PackSize, &unpackSize);
+ }
+
+ Encoder->ThreadsInfo[blockIndex].CanWriteEvent.Set();
+ }
+ #endif
+ return res;
+}
+
+void CEncoder::WriteBytes(const Byte *data, UInt32 sizeInBits, Byte lastByte)
+{
+ UInt32 bytesSize = (sizeInBits / 8);
+ for (UInt32 i = 0; i < bytesSize; i++)
+ m_OutStream.WriteBits(data[i], 8);
+ WriteBits(lastByte, (sizeInBits & 7));
+}
+
+
+HRESULT CEncoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)
+{
+ #ifndef _7ZIP_ST
+ Progress = progress;
+ RINOK(Create());
+ for (UInt32 t = 0; t < NumThreads; t++)
+ #endif
+ {
+ #ifndef _7ZIP_ST
+ CThreadInfo &ti = ThreadsInfo[t];
+ if (MtMode)
+ {
+ RINOK(ti.StreamWasFinishedEvent.Reset());
+ RINOK(ti.WaitingWasStartedEvent.Reset());
+ RINOK(ti.CanWriteEvent.Reset());
+ }
+ #else
+ CThreadInfo &ti = ThreadsInfo;
+ ti.Encoder = this;
+ #endif
+
+ ti.m_OptimizeNumTables = m_OptimizeNumTables;
+
+ if (!ti.Alloc())
+ return E_OUTOFMEMORY;
+ }
+
+
+ if (!m_InStream.Create(kBufferSize))
+ return E_OUTOFMEMORY;
+ if (!m_OutStream.Create(kBufferSize))
+ return E_OUTOFMEMORY;
+
+
+ m_InStream.SetStream(inStream);
+ m_InStream.Init();
+
+ m_OutStream.SetStream(outStream);
+ m_OutStream.Init();
+
+ CFlusher flusher(this);
+
+ CombinedCrc.Init();
+ #ifndef _7ZIP_ST
+ NextBlockIndex = 0;
+ StreamWasFinished = false;
+ CloseThreads = false;
+ CanStartWaitingEvent.Reset();
+ #endif
+
+ WriteByte(kArSig0);
+ WriteByte(kArSig1);
+ WriteByte(kArSig2);
+ WriteByte((Byte)(kArSig3 + m_BlockSizeMult));
+
+ #ifndef _7ZIP_ST
+
+ if (MtMode)
+ {
+ ThreadsInfo[0].CanWriteEvent.Set();
+ Result = S_OK;
+ CanProcessEvent.Set();
+ UInt32 t;
+ for (t = 0; t < NumThreads; t++)
+ ThreadsInfo[t].StreamWasFinishedEvent.Lock();
+ CanProcessEvent.Reset();
+ CanStartWaitingEvent.Set();
+ for (t = 0; t < NumThreads; t++)
+ ThreadsInfo[t].WaitingWasStartedEvent.Lock();
+ CanStartWaitingEvent.Reset();
+ RINOK(Result);
+ }
+ else
+ #endif
+ {
+ for (;;)
+ {
+ CThreadInfo &ti =
+ #ifndef _7ZIP_ST
+ ThreadsInfo[0];
+ #else
+ ThreadsInfo;
+ #endif
+ UInt32 blockSize = ReadRleBlock(ti.m_Block);
+ if (blockSize == 0)
+ break;
+ RINOK(ti.EncodeBlock3(blockSize));
+ if (progress)
+ {
+ UInt64 packSize = m_InStream.GetProcessedSize();
+ UInt64 unpackSize = m_OutStream.GetProcessedSize();
+ RINOK(progress->SetRatioInfo(&packSize, &unpackSize));
+ }
+ }
+ }
+ WriteByte(kFinSig0);
+ WriteByte(kFinSig1);
+ WriteByte(kFinSig2);
+ WriteByte(kFinSig3);
+ WriteByte(kFinSig4);
+ WriteByte(kFinSig5);
+
+ WriteCrc(CombinedCrc.GetDigest());
+ return Flush();
+}
+
+STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
+{
+ try { return CodeReal(inStream, outStream, inSize, outSize, progress); }
+ catch(const CInBufferException &e) { return e.ErrorCode; }
+ catch(const COutBufferException &e) { return e.ErrorCode; }
+ catch(...) { return S_FALSE; }
+}
+
+HRESULT CEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps)
+{
+ for(UInt32 i = 0; i < numProps; i++)
+ {
+ const PROPVARIANT &prop = props[i];
+ switch(propIDs[i])
+ {
+ case NCoderPropID::kNumPasses:
+ {
+ if (prop.vt != VT_UI4)
+ return E_INVALIDARG;
+ UInt32 numPasses = prop.ulVal;
+ if (numPasses == 0)
+ numPasses = 1;
+ if (numPasses > kNumPassesMax)
+ numPasses = kNumPassesMax;
+ NumPasses = numPasses;
+ m_OptimizeNumTables = (NumPasses > 1);
+ break;
+ }
+ case NCoderPropID::kDictionarySize:
+ {
+ if (prop.vt != VT_UI4)
+ return E_INVALIDARG;
+ UInt32 dictionary = prop.ulVal / kBlockSizeStep;
+ if (dictionary < kBlockSizeMultMin)
+ dictionary = kBlockSizeMultMin;
+ else if (dictionary > kBlockSizeMultMax)
+ dictionary = kBlockSizeMultMax;
+ m_BlockSizeMult = dictionary;
+ break;
+ }
+ case NCoderPropID::kNumThreads:
+ {
+ #ifndef _7ZIP_ST
+ if (prop.vt != VT_UI4)
+ return E_INVALIDARG;
+ NumThreads = prop.ulVal;
+ if (NumThreads < 1)
+ NumThreads = 1;
+ #endif
+ break;
+ }
+ default:
+ return E_INVALIDARG;
+ }
+ }
+ return S_OK;
+}
+
+#ifndef _7ZIP_ST
+STDMETHODIMP CEncoder::SetNumberOfThreads(UInt32 numThreads)
+{
+ NumThreads = numThreads;
+ if (NumThreads < 1)
+ NumThreads = 1;
+ return S_OK;
+}
+#endif
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Encoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Encoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Encoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Encoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,245 @@
+// BZip2Encoder.h
+
+#ifndef __COMPRESS_BZIP2_ENCODER_H
+#define __COMPRESS_BZIP2_ENCODER_H
+
+#include "../../Common/Defs.h"
+#include "../../Common/MyCom.h"
+
+#ifndef _7ZIP_ST
+#include "../../Windows/Synchronization.h"
+#include "../../Windows/Thread.h"
+#endif
+
+#include "../ICoder.h"
+
+#include "../Common/InBuffer.h"
+#include "../Common/OutBuffer.h"
+
+#include "BitmEncoder.h"
+#include "BZip2Const.h"
+#include "BZip2Crc.h"
+
+namespace NCompress {
+namespace NBZip2 {
+
+class CMsbfEncoderTemp
+{
+ UInt32 m_Pos;
+ int m_BitPos;
+ Byte m_CurByte;
+ Byte *Buffer;
+public:
+ void SetStream(Byte *buffer) { Buffer = buffer; }
+ Byte *GetStream() const { return Buffer; }
+
+ void Init()
+ {
+ m_Pos = 0;
+ m_BitPos = 8;
+ m_CurByte = 0;
+ }
+
+ void Flush()
+ {
+ if (m_BitPos < 8)
+ WriteBits(0, m_BitPos);
+ }
+
+ void WriteBits(UInt32 value, int numBits)
+ {
+ while (numBits > 0)
+ {
+ int numNewBits = MyMin(numBits, m_BitPos);
+ numBits -= numNewBits;
+
+ m_CurByte <<= numNewBits;
+ UInt32 newBits = value >> numBits;
+ m_CurByte |= Byte(newBits);
+ value -= (newBits << numBits);
+
+ m_BitPos -= numNewBits;
+
+ if (m_BitPos == 0)
+ {
+ Buffer[m_Pos++] = m_CurByte;
+ m_BitPos = 8;
+ }
+ }
+ }
+
+ UInt32 GetBytePos() const { return m_Pos ; }
+ UInt32 GetPos() const { return m_Pos * 8 + (8 - m_BitPos); }
+ Byte GetCurByte() const { return m_CurByte; }
+ void SetPos(UInt32 bitPos)
+ {
+ m_Pos = bitPos / 8;
+ m_BitPos = 8 - ((int)bitPos & 7);
+ }
+ void SetCurState(int bitPos, Byte curByte)
+ {
+ m_BitPos = 8 - bitPos;
+ m_CurByte = curByte;
+ }
+};
+
+class CEncoder;
+
+const int kNumPassesMax = 10;
+
+class CThreadInfo
+{
+public:
+ Byte *m_Block;
+private:
+ Byte *m_MtfArray;
+ Byte *m_TempArray;
+ UInt32 *m_BlockSorterIndex;
+
+ CMsbfEncoderTemp *m_OutStreamCurrent;
+
+ Byte Lens[kNumTablesMax][kMaxAlphaSize];
+ UInt32 Freqs[kNumTablesMax][kMaxAlphaSize];
+ UInt32 Codes[kNumTablesMax][kMaxAlphaSize];
+
+ Byte m_Selectors[kNumSelectorsMax];
+
+ UInt32 m_CRCs[1 << kNumPassesMax];
+ UInt32 m_NumCrcs;
+
+ UInt32 m_BlockIndex;
+
+ void WriteBits2(UInt32 value, UInt32 numBits);
+ void WriteByte2(Byte b);
+ void WriteBit2(bool v);
+ void WriteCrc2(UInt32 v);
+
+ void EncodeBlock(const Byte *block, UInt32 blockSize);
+ UInt32 EncodeBlockWithHeaders(const Byte *block, UInt32 blockSize);
+ void EncodeBlock2(const Byte *block, UInt32 blockSize, UInt32 numPasses);
+public:
+ bool m_OptimizeNumTables;
+ CEncoder *Encoder;
+ #ifndef _7ZIP_ST
+ NWindows::CThread Thread;
+
+ NWindows::NSynchronization::CAutoResetEvent StreamWasFinishedEvent;
+ NWindows::NSynchronization::CAutoResetEvent WaitingWasStartedEvent;
+
+ // it's not member of this thread. We just need one event per thread
+ NWindows::NSynchronization::CAutoResetEvent CanWriteEvent;
+
+ UInt64 m_PackSize;
+
+ Byte MtPad[1 << 8]; // It's pad for Multi-Threading. Must be >= Cache_Line_Size.
+ HRESULT Create();
+ void FinishStream(bool needLeave);
+ DWORD ThreadFunc();
+ #endif
+
+ CThreadInfo(): m_BlockSorterIndex(0), m_Block(0) {}
+ ~CThreadInfo() { Free(); }
+ bool Alloc();
+ void Free();
+
+ HRESULT EncodeBlock3(UInt32 blockSize);
+};
+
+class CEncoder :
+ public ICompressCoder,
+ public ICompressSetCoderProperties,
+ #ifndef _7ZIP_ST
+ public ICompressSetCoderMt,
+ #endif
+ public CMyUnknownImp
+{
+ UInt32 m_BlockSizeMult;
+ bool m_OptimizeNumTables;
+
+ UInt32 m_NumPassesPrev;
+
+ UInt32 m_NumThreadsPrev;
+public:
+ CInBuffer m_InStream;
+ Byte MtPad[1 << 8]; // It's pad for Multi-Threading. Must be >= Cache_Line_Size.
+ CBitmEncoder<COutBuffer> m_OutStream;
+ UInt32 NumPasses;
+ CBZip2CombinedCrc CombinedCrc;
+
+ #ifndef _7ZIP_ST
+ CThreadInfo *ThreadsInfo;
+ NWindows::NSynchronization::CManualResetEvent CanProcessEvent;
+ NWindows::NSynchronization::CCriticalSection CS;
+ UInt32 NumThreads;
+ bool MtMode;
+ UInt32 NextBlockIndex;
+
+ bool CloseThreads;
+ bool StreamWasFinished;
+ NWindows::NSynchronization::CManualResetEvent CanStartWaitingEvent;
+
+ HRESULT Result;
+ ICompressProgressInfo *Progress;
+ #else
+ CThreadInfo ThreadsInfo;
+ #endif
+
+ UInt32 ReadRleBlock(Byte *buffer);
+ void WriteBytes(const Byte *data, UInt32 sizeInBits, Byte lastByte);
+
+ void WriteBits(UInt32 value, UInt32 numBits);
+ void WriteByte(Byte b);
+ void WriteBit(bool v);
+ void WriteCrc(UInt32 v);
+
+ #ifndef _7ZIP_ST
+ HRESULT Create();
+ void Free();
+ #endif
+
+public:
+ CEncoder();
+ #ifndef _7ZIP_ST
+ ~CEncoder();
+ #endif
+
+ HRESULT Flush() { return m_OutStream.Flush(); }
+
+ void ReleaseStreams()
+ {
+ m_InStream.ReleaseStream();
+ m_OutStream.ReleaseStream();
+ }
+
+ class CFlusher
+ {
+ CEncoder *_coder;
+ public:
+ CFlusher(CEncoder *coder): _coder(coder) {}
+ ~CFlusher()
+ {
+ _coder->ReleaseStreams();
+ }
+ };
+
+ #ifndef _7ZIP_ST
+ MY_UNKNOWN_IMP2(ICompressSetCoderMt, ICompressSetCoderProperties)
+ #else
+ MY_UNKNOWN_IMP1(ICompressSetCoderProperties)
+ #endif
+
+ HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+ STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);
+
+ #ifndef _7ZIP_ST
+ STDMETHOD(SetNumberOfThreads)(UInt32 numThreads);
+ #endif
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Register.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Register.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Register.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BZip2Register.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,20 @@
+// BZip2Register.cpp
+
+#include "StdAfx.h"
+
+#include "../Common/RegisterCodec.h"
+
+#include "BZip2Decoder.h"
+
+static void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NBZip2::CDecoder); }
+#if !defined(EXTRACT_ONLY) && !defined(BZIP2_EXTRACT_ONLY)
+#include "BZip2Encoder.h"
+static void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NBZip2::CEncoder); }
+#else
+#define CreateCodecOut 0
+#endif
+
+static CCodecInfo g_CodecInfo =
+ { CreateCodec, CreateCodecOut, 0x040202, L"BZip2", 1, false };
+
+REGISTER_CODEC(BZip2)
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Bcj2Coder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Bcj2Coder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Bcj2Coder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Bcj2Coder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,386 @@
+// Bcj2Coder.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/Alloc.h"
+
+#include "Bcj2Coder.h"
+
+namespace NCompress {
+namespace NBcj2 {
+
+inline bool IsJcc(Byte b0, Byte b1) { return (b0 == 0x0F && (b1 & 0xF0) == 0x80); }
+inline bool IsJ(Byte b0, Byte b1) { return ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)); }
+inline unsigned GetIndex(Byte b0, Byte b1) { return ((b1 == 0xE8) ? b0 : ((b1 == 0xE9) ? 256 : 257)); }
+
+#ifndef EXTRACT_ONLY
+
+static const int kBufferSize = 1 << 17;
+
+static bool inline Test86MSByte(Byte b)
+{
+ return (b == 0 || b == 0xFF);
+}
+
+bool CEncoder::Create()
+{
+ if (!_mainStream.Create(1 << 18))
+ return false;
+ if (!_callStream.Create(1 << 18))
+ return false;
+ if (!_jumpStream.Create(1 << 18))
+ return false;
+ if (!_rangeEncoder.Create(1 << 20))
+ return false;
+ if (_buffer == 0)
+ {
+ _buffer = (Byte *)MidAlloc(kBufferSize);
+ if (_buffer == 0)
+ return false;
+ }
+ return true;
+}
+
+CEncoder::~CEncoder()
+{
+ ::MidFree(_buffer);
+}
+
+HRESULT CEncoder::Flush()
+{
+ RINOK(_mainStream.Flush());
+ RINOK(_callStream.Flush());
+ RINOK(_jumpStream.Flush());
+ _rangeEncoder.FlushData();
+ return _rangeEncoder.FlushStream();
+}
+
+const UInt32 kDefaultLimit = (1 << 24);
+
+HRESULT CEncoder::CodeReal(ISequentialInStream **inStreams, const UInt64 **inSizes, UInt32 numInStreams,
+ ISequentialOutStream **outStreams, const UInt64 ** /* outSizes */, UInt32 numOutStreams,
+ ICompressProgressInfo *progress)
+{
+ if (numInStreams != 1 || numOutStreams != 4)
+ return E_INVALIDARG;
+
+ if (!Create())
+ return E_OUTOFMEMORY;
+
+ bool sizeIsDefined = false;
+ UInt64 inSize = 0;
+ if (inSizes != NULL)
+ if (inSizes[0] != NULL)
+ {
+ inSize = *inSizes[0];
+ if (inSize <= kDefaultLimit)
+ sizeIsDefined = true;
+ }
+
+ CCoderReleaser releaser(this);
+
+ ISequentialInStream *inStream = inStreams[0];
+
+ _mainStream.SetStream(outStreams[0]);
+ _mainStream.Init();
+ _callStream.SetStream(outStreams[1]);
+ _callStream.Init();
+ _jumpStream.SetStream(outStreams[2]);
+ _jumpStream.Init();
+ _rangeEncoder.SetStream(outStreams[3]);
+ _rangeEncoder.Init();
+ for (int i = 0; i < 256 + 2; i++)
+ _statusEncoder[i].Init();
+
+ CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;
+ {
+ inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);
+ }
+
+ UInt32 nowPos = 0;
+ UInt64 nowPos64 = 0;
+ UInt32 bufferPos = 0;
+
+ Byte prevByte = 0;
+
+ UInt64 subStreamIndex = 0;
+ UInt64 subStreamStartPos = 0;
+ UInt64 subStreamEndPos = 0;
+
+ for (;;)
+ {
+ UInt32 processedSize = 0;
+ for (;;)
+ {
+ UInt32 size = kBufferSize - (bufferPos + processedSize);
+ UInt32 processedSizeLoc;
+ if (size == 0)
+ break;
+ RINOK(inStream->Read(_buffer + bufferPos + processedSize, size, &processedSizeLoc));
+ if (processedSizeLoc == 0)
+ break;
+ processedSize += processedSizeLoc;
+ }
+ UInt32 endPos = bufferPos + processedSize;
+
+ if (endPos < 5)
+ {
+ // change it
+ for (bufferPos = 0; bufferPos < endPos; bufferPos++)
+ {
+ Byte b = _buffer[bufferPos];
+ _mainStream.WriteByte(b);
+ UInt32 index;
+ if (b == 0xE8)
+ index = prevByte;
+ else if (b == 0xE9)
+ index = 256;
+ else if (IsJcc(prevByte, b))
+ index = 257;
+ else
+ {
+ prevByte = b;
+ continue;
+ }
+ _statusEncoder[index].Encode(&_rangeEncoder, 0);
+ prevByte = b;
+ }
+ return Flush();
+ }
+
+ bufferPos = 0;
+
+ UInt32 limit = endPos - 5;
+ while(bufferPos <= limit)
+ {
+ Byte b = _buffer[bufferPos];
+ _mainStream.WriteByte(b);
+ if (!IsJ(prevByte, b))
+ {
+ bufferPos++;
+ prevByte = b;
+ continue;
+ }
+ Byte nextByte = _buffer[bufferPos + 4];
+ UInt32 src =
+ (UInt32(nextByte) << 24) |
+ (UInt32(_buffer[bufferPos + 3]) << 16) |
+ (UInt32(_buffer[bufferPos + 2]) << 8) |
+ (_buffer[bufferPos + 1]);
+ UInt32 dest = (nowPos + bufferPos + 5) + src;
+ // if (Test86MSByte(nextByte))
+ bool convert;
+ if (getSubStreamSize != NULL)
+ {
+ UInt64 currentPos = (nowPos64 + bufferPos);
+ while (subStreamEndPos < currentPos)
+ {
+ UInt64 subStreamSize;
+ HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);
+ if (result == S_OK)
+ {
+ subStreamStartPos = subStreamEndPos;
+ subStreamEndPos += subStreamSize;
+ subStreamIndex++;
+ }
+ else if (result == S_FALSE || result == E_NOTIMPL)
+ {
+ getSubStreamSize.Release();
+ subStreamStartPos = 0;
+ subStreamEndPos = subStreamStartPos - 1;
+ }
+ else
+ return result;
+ }
+ if (getSubStreamSize == NULL)
+ {
+ if (sizeIsDefined)
+ convert = (dest < inSize);
+ else
+ convert = Test86MSByte(nextByte);
+ }
+ else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)
+ convert = Test86MSByte(nextByte);
+ else
+ {
+ UInt64 dest64 = (currentPos + 5) + Int64(Int32(src));
+ convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);
+ }
+ }
+ else if (sizeIsDefined)
+ convert = (dest < inSize);
+ else
+ convert = Test86MSByte(nextByte);
+ unsigned index = GetIndex(prevByte, b);
+ if (convert)
+ {
+ _statusEncoder[index].Encode(&_rangeEncoder, 1);
+ bufferPos += 5;
+ COutBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;
+ for (int i = 24; i >= 0; i -= 8)
+ s.WriteByte((Byte)(dest >> i));
+ prevByte = nextByte;
+ }
+ else
+ {
+ _statusEncoder[index].Encode(&_rangeEncoder, 0);
+ bufferPos++;
+ prevByte = b;
+ }
+ }
+ nowPos += bufferPos;
+ nowPos64 += bufferPos;
+
+ if (progress != NULL)
+ {
+ /*
+ const UInt64 compressedSize =
+ _mainStream.GetProcessedSize() +
+ _callStream.GetProcessedSize() +
+ _jumpStream.GetProcessedSize() +
+ _rangeEncoder.GetProcessedSize();
+ */
+ RINOK(progress->SetRatioInfo(&nowPos64, NULL));
+ }
+
+ UInt32 i = 0;
+ while(bufferPos < endPos)
+ _buffer[i++] = _buffer[bufferPos++];
+ bufferPos = i;
+ }
+}
+
+STDMETHODIMP CEncoder::Code(ISequentialInStream **inStreams, const UInt64 **inSizes, UInt32 numInStreams,
+ ISequentialOutStream **outStreams, const UInt64 **outSizes, UInt32 numOutStreams,
+ ICompressProgressInfo *progress)
+{
+ try
+ {
+ return CodeReal(inStreams, inSizes, numInStreams, outStreams, outSizes,numOutStreams, progress);
+ }
+ catch(const COutBufferException &e) { return e.ErrorCode; }
+ catch(...) { return S_FALSE; }
+}
+
+#endif
+
+
+STDMETHODIMP CDecoder::SetInBufSize(UInt32 streamIndex, UInt32 size) { _inBufSizes[streamIndex] = size; return S_OK; }
+STDMETHODIMP CDecoder::SetOutBufSize(UInt32 , UInt32 size) { _outBufSize = size; return S_OK; }
+
+CDecoder::CDecoder():
+ _outBufSize(1 << 16)
+{
+ _inBufSizes[0] = 1 << 20;
+ _inBufSizes[1] = 1 << 20;
+ _inBufSizes[2] = 1 << 20;
+ _inBufSizes[3] = 1 << 20;
+}
+
+HRESULT CDecoder::CodeReal(ISequentialInStream **inStreams, const UInt64 ** /* inSizes */, UInt32 numInStreams,
+ ISequentialOutStream **outStreams, const UInt64 ** /* outSizes */, UInt32 numOutStreams,
+ ICompressProgressInfo *progress)
+{
+ if (numInStreams != 4 || numOutStreams != 1)
+ return E_INVALIDARG;
+
+ if (!_mainInStream.Create(_inBufSizes[0]))
+ return E_OUTOFMEMORY;
+ if (!_callStream.Create(_inBufSizes[1]))
+ return E_OUTOFMEMORY;
+ if (!_jumpStream.Create(_inBufSizes[2]))
+ return E_OUTOFMEMORY;
+ if (!_rangeDecoder.Create(_inBufSizes[3]))
+ return E_OUTOFMEMORY;
+ if (!_outStream.Create(_outBufSize))
+ return E_OUTOFMEMORY;
+
+ CCoderReleaser releaser(this);
+
+ _mainInStream.SetStream(inStreams[0]);
+ _callStream.SetStream(inStreams[1]);
+ _jumpStream.SetStream(inStreams[2]);
+ _rangeDecoder.SetStream(inStreams[3]);
+ _outStream.SetStream(outStreams[0]);
+
+ _mainInStream.Init();
+ _callStream.Init();
+ _jumpStream.Init();
+ _rangeDecoder.Init();
+ _outStream.Init();
+
+ for (int i = 0; i < 256 + 2; i++)
+ _statusDecoder[i].Init();
+
+ Byte prevByte = 0;
+ UInt32 processedBytes = 0;
+ for (;;)
+ {
+ if (processedBytes >= (1 << 20) && progress != NULL)
+ {
+ /*
+ const UInt64 compressedSize =
+ _mainInStream.GetProcessedSize() +
+ _callStream.GetProcessedSize() +
+ _jumpStream.GetProcessedSize() +
+ _rangeDecoder.GetProcessedSize();
+ */
+ const UInt64 nowPos64 = _outStream.GetProcessedSize();
+ RINOK(progress->SetRatioInfo(NULL, &nowPos64));
+ processedBytes = 0;
+ }
+ UInt32 i;
+ Byte b = 0;
+ const UInt32 kBurstSize = (1 << 18);
+ for (i = 0; i < kBurstSize; i++)
+ {
+ if (!_mainInStream.ReadByte(b))
+ return Flush();
+ _outStream.WriteByte(b);
+ if (IsJ(prevByte, b))
+ break;
+ prevByte = b;
+ }
+ processedBytes += i;
+ if (i == kBurstSize)
+ continue;
+ unsigned index = GetIndex(prevByte, b);
+ if (_statusDecoder[index].Decode(&_rangeDecoder) == 1)
+ {
+ UInt32 src = 0;
+ CInBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;
+ for (int i = 0; i < 4; i++)
+ {
+ Byte b0;
+ if(!s.ReadByte(b0))
+ return S_FALSE;
+ src <<= 8;
+ src |= ((UInt32)b0);
+ }
+ UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ;
+ _outStream.WriteByte((Byte)(dest));
+ _outStream.WriteByte((Byte)(dest >> 8));
+ _outStream.WriteByte((Byte)(dest >> 16));
+ _outStream.WriteByte((Byte)(dest >> 24));
+ prevByte = (Byte)(dest >> 24);
+ processedBytes += 4;
+ }
+ else
+ prevByte = b;
+ }
+}
+
+STDMETHODIMP CDecoder::Code(ISequentialInStream **inStreams, const UInt64 **inSizes, UInt32 numInStreams,
+ ISequentialOutStream **outStreams, const UInt64 **outSizes, UInt32 numOutStreams,
+ ICompressProgressInfo *progress)
+{
+ try
+ {
+ return CodeReal(inStreams, inSizes, numInStreams, outStreams, outSizes,numOutStreams, progress);
+ }
+ catch(const CInBufferException &e) { return e.ErrorCode; }
+ catch(const COutBufferException &e) { return e.ErrorCode; }
+ catch(...) { return S_FALSE; }
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Bcj2Coder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Bcj2Coder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Bcj2Coder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Bcj2Coder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,115 @@
+// Bcj2Coder.h
+
+#ifndef __COMPRESS_BCJ2_CODER_H
+#define __COMPRESS_BCJ2_CODER_H
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+#include "RangeCoderBit.h"
+
+namespace NCompress {
+namespace NBcj2 {
+
+const int kNumMoveBits = 5;
+
+#ifndef EXTRACT_ONLY
+
+class CEncoder:
+ public ICompressCoder2,
+ public CMyUnknownImp
+{
+ Byte *_buffer;
+ bool Create();
+
+ COutBuffer _mainStream;
+ COutBuffer _callStream;
+ COutBuffer _jumpStream;
+ NCompress::NRangeCoder::CEncoder _rangeEncoder;
+ NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusEncoder[256 + 2];
+
+ HRESULT Flush();
+public:
+ void ReleaseStreams()
+ {
+ _mainStream.ReleaseStream();
+ _callStream.ReleaseStream();
+ _jumpStream.ReleaseStream();
+ _rangeEncoder.ReleaseStream();
+ }
+
+ class CCoderReleaser
+ {
+ CEncoder *_coder;
+ public:
+ CCoderReleaser(CEncoder *coder): _coder(coder) {}
+ ~CCoderReleaser() { _coder->ReleaseStreams(); }
+ };
+
+public:
+ MY_UNKNOWN_IMP
+
+ HRESULT CodeReal(ISequentialInStream **inStreams, const UInt64 **inSizes, UInt32 numInStreams,
+ ISequentialOutStream **outStreams, const UInt64 **outSizes, UInt32 numOutStreams,
+ ICompressProgressInfo *progress);
+ STDMETHOD(Code)(ISequentialInStream **inStreams, const UInt64 **inSizes, UInt32 numInStreams,
+ ISequentialOutStream **outStreams, const UInt64 **outSizes, UInt32 numOutStreams,
+ ICompressProgressInfo *progress);
+ CEncoder(): _buffer(0) {};
+ ~CEncoder();
+};
+
+#endif
+
+class CDecoder:
+ public ICompressCoder2,
+ public ICompressSetBufSize,
+ public CMyUnknownImp
+{
+ CInBuffer _mainInStream;
+ CInBuffer _callStream;
+ CInBuffer _jumpStream;
+ NCompress::NRangeCoder::CDecoder _rangeDecoder;
+ NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusDecoder[256 + 2];
+
+ COutBuffer _outStream;
+ UInt32 _inBufSizes[4];
+ UInt32 _outBufSize;
+
+public:
+ void ReleaseStreams()
+ {
+ _mainInStream.ReleaseStream();
+ _callStream.ReleaseStream();
+ _jumpStream.ReleaseStream();
+ _rangeDecoder.ReleaseStream();
+ _outStream.ReleaseStream();
+ }
+
+ HRESULT Flush() { return _outStream.Flush(); }
+ class CCoderReleaser
+ {
+ CDecoder *_coder;
+ public:
+ CCoderReleaser(CDecoder *coder): _coder(coder) {}
+ ~CCoderReleaser() { _coder->ReleaseStreams(); }
+ };
+
+public:
+ MY_UNKNOWN_IMP1(ICompressSetBufSize);
+ HRESULT CodeReal(ISequentialInStream **inStreams, const UInt64 **inSizes, UInt32 numInStreams,
+ ISequentialOutStream **outStreams, const UInt64 **outSizes, UInt32 numOutStreams,
+ ICompressProgressInfo *progress);
+ STDMETHOD(Code)(ISequentialInStream **inStreams, const UInt64 **inSizes, UInt32 numInStreams,
+ ISequentialOutStream **outStreams, const UInt64 **outSizes, UInt32 numOutStreams,
+ ICompressProgressInfo *progress);
+
+ STDMETHOD(SetInBufSize)(UInt32 streamIndex, UInt32 size);
+ STDMETHOD(SetOutBufSize)(UInt32 streamIndex, UInt32 size);
+ CDecoder();
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Bcj2Register.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Bcj2Register.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Bcj2Register.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Bcj2Register.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,19 @@
+// Bcj2Register.cpp
+
+#include "StdAfx.h"
+
+#include "../Common/RegisterCodec.h"
+
+#include "Bcj2Coder.h"
+
+static void *CreateCodec() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CDecoder()); }
+#ifndef EXTRACT_ONLY
+static void *CreateCodecOut() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CEncoder()); }
+#else
+#define CreateCodecOut 0
+#endif
+
+static CCodecInfo g_CodecInfo =
+ { CreateCodec, CreateCodecOut, 0x0303011B, L"BCJ2", 4, false };
+
+REGISTER_CODEC(BCJ2)
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BcjCoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BcjCoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BcjCoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BcjCoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,15 @@
+// BcjCoder.cpp
+
+#include "StdAfx.h"
+
+#include "BcjCoder.h"
+
+UInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size)
+{
+ return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 1);
+}
+
+UInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size)
+{
+ return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 0);
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BcjCoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BcjCoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BcjCoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BcjCoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,19 @@
+// BcjCoder.h
+
+#ifndef __COMPRESS_BCJ_CODER_H
+#define __COMPRESS_BCJ_CODER_H
+
+#include "../../../C/Bra.h"
+
+#include "BranchCoder.h"
+
+struct CBranch86
+{
+ UInt32 _prevMask;
+ void x86Init() { x86_Convert_Init(_prevMask); }
+};
+
+MyClassB(BCJ_x86, 0x01, 3, CBranch86 ,
+ virtual void SubInit() { x86Init(); })
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BcjRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BcjRegister.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BcjRegister.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BcjRegister.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,19 @@
+// BcjRegister.cpp
+
+#include "StdAfx.h"
+
+#include "../Common/RegisterCodec.h"
+
+#include "BcjCoder.h"
+
+static void *CreateCodec() { return (void *)(ICompressFilter *)(new CBCJ_x86_Decoder()); }
+#ifndef EXTRACT_ONLY
+static void *CreateCodecOut() { return (void *)(ICompressFilter *)(new CBCJ_x86_Encoder()); }
+#else
+#define CreateCodecOut 0
+#endif
+
+static CCodecInfo g_CodecInfo =
+ { CreateCodec, CreateCodecOut, 0x03030103, L"BCJ", 1, true };
+
+REGISTER_CODEC(BCJ)
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitlDecoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitlDecoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitlDecoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitlDecoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,24 @@
+// BitlDecoder.cpp
+
+#include "StdAfx.h"
+
+#include "BitlDecoder.h"
+
+namespace NBitl {
+
+Byte kInvertTable[256];
+
+struct CInverterTableInitializer
+{
+ CInverterTableInitializer()
+ {
+ for (int i = 0; i < 256; i++)
+ {
+ int x = ((i & 0x55) << 1) | ((i & 0xAA) >> 1);
+ x = ((x & 0x33) << 2) | ((x & 0xCC) >> 2);
+ kInvertTable[i] = (Byte)(((x & 0x0F) << 4) | ((x & 0xF0) >> 4));
+ }
+ }
+} g_InverterTableInitializer;
+
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitlDecoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitlDecoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitlDecoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitlDecoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,141 @@
+// BitlDecoder.h -- the Least Significant Bit of byte is First
+
+#ifndef __BITL_DECODER_H
+#define __BITL_DECODER_H
+
+#include "../IStream.h"
+
+namespace NBitl {
+
+const unsigned kNumBigValueBits = 8 * 4;
+const unsigned kNumValueBytes = 3;
+const unsigned kNumValueBits = 8 * kNumValueBytes;
+
+const UInt32 kMask = (1 << kNumValueBits) - 1;
+
+extern Byte kInvertTable[256];
+
+template<class TInByte>
+class CBaseDecoder
+{
+protected:
+ unsigned m_BitPos;
+ UInt32 m_Value;
+ TInByte m_Stream;
+public:
+ UInt32 NumExtraBytes;
+ bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
+ void SetStream(ISequentialInStream *inStream) { m_Stream.SetStream(inStream); }
+ void ReleaseStream() { m_Stream.ReleaseStream(); }
+ void Init()
+ {
+ m_Stream.Init();
+ m_BitPos = kNumBigValueBits;
+ m_Value = 0;
+ NumExtraBytes = 0;
+ }
+ UInt64 GetProcessedSize() const { return m_Stream.GetProcessedSize() + NumExtraBytes - (kNumBigValueBits - m_BitPos) / 8; }
+
+ void Normalize()
+ {
+ for (; m_BitPos >= 8; m_BitPos -= 8)
+ {
+ Byte b = 0;
+ if (!m_Stream.ReadByte(b))
+ {
+ b = 0xFF; // check it
+ NumExtraBytes++;
+ }
+ m_Value = (b << (kNumBigValueBits - m_BitPos)) | m_Value;
+ }
+ }
+
+ UInt32 ReadBits(unsigned numBits)
+ {
+ Normalize();
+ UInt32 res = m_Value & ((1 << numBits) - 1);
+ m_BitPos += numBits;
+ m_Value >>= numBits;
+ return res;
+ }
+
+ bool ExtraBitsWereRead() const
+ {
+ if (NumExtraBytes == 0)
+ return false;
+ return ((UInt32)(kNumBigValueBits - m_BitPos) < (NumExtraBytes << 3));
+ }
+};
+
+template<class TInByte>
+class CDecoder: public CBaseDecoder<TInByte>
+{
+ UInt32 m_NormalValue;
+
+public:
+ void Init()
+ {
+ CBaseDecoder<TInByte>::Init();
+ m_NormalValue = 0;
+ }
+
+ void Normalize()
+ {
+ for (; this->m_BitPos >= 8; this->m_BitPos -= 8)
+ {
+ Byte b = 0;
+ if (!this->m_Stream.ReadByte(b))
+ {
+ b = 0xFF; // check it
+ this->NumExtraBytes++;
+ }
+ m_NormalValue = (b << (kNumBigValueBits - this->m_BitPos)) | m_NormalValue;
+ this->m_Value = (this->m_Value << 8) | kInvertTable[b];
+ }
+ }
+
+ UInt32 GetValue(unsigned numBits)
+ {
+ Normalize();
+ return ((this->m_Value >> (8 - this->m_BitPos)) & kMask) >> (kNumValueBits - numBits);
+ }
+
+ void MovePos(unsigned numBits)
+ {
+ this->m_BitPos += numBits;
+ m_NormalValue >>= numBits;
+ }
+
+ UInt32 ReadBits(unsigned numBits)
+ {
+ Normalize();
+ UInt32 res = m_NormalValue & ((1 << numBits) - 1);
+ MovePos(numBits);
+ return res;
+ }
+
+ void AlignToByte() { MovePos((32 - this->m_BitPos) & 7); }
+
+ Byte ReadByte()
+ {
+ if (this->m_BitPos == kNumBigValueBits)
+ {
+ Byte b = 0;
+ if (!this->m_Stream.ReadByte(b))
+ {
+ b = 0xFF;
+ this->NumExtraBytes++;
+ }
+ return b;
+ }
+ {
+ Byte b = (Byte)(m_NormalValue & 0xFF);
+ MovePos(8);
+ return b;
+ }
+ }
+};
+
+}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitlEncoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitlEncoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitlEncoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitlEncoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,57 @@
+// BitlEncoder.h -- the Least Significant Bit of byte is First
+
+#ifndef __BITL_ENCODER_H
+#define __BITL_ENCODER_H
+
+#include "../Common/OutBuffer.h"
+
+class CBitlEncoder
+{
+ COutBuffer m_Stream;
+ unsigned m_BitPos;
+ Byte m_CurByte;
+public:
+ bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
+ void SetStream(ISequentialOutStream *outStream) { m_Stream.SetStream(outStream); }
+ void ReleaseStream() { m_Stream.ReleaseStream(); }
+ UInt32 GetBitPosition() const { return (8 - m_BitPos); }
+ UInt64 GetProcessedSize() const { return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) /8; }
+ void Init()
+ {
+ m_Stream.Init();
+ m_BitPos = 8;
+ m_CurByte = 0;
+ }
+ HRESULT Flush()
+ {
+ FlushByte();
+ return m_Stream.Flush();
+ }
+ void FlushByte()
+ {
+ if (m_BitPos < 8)
+ m_Stream.WriteByte(m_CurByte);
+ m_BitPos = 8;
+ m_CurByte = 0;
+ }
+ void WriteBits(UInt32 value, unsigned numBits)
+ {
+ while (numBits > 0)
+ {
+ if (numBits < m_BitPos)
+ {
+ m_CurByte |= (value & ((1 << numBits) - 1)) << (8 - m_BitPos);
+ m_BitPos -= numBits;
+ return;
+ }
+ numBits -= m_BitPos;
+ m_Stream.WriteByte((Byte)(m_CurByte | (value << (8 - m_BitPos))));
+ value >>= m_BitPos;
+ m_BitPos = 8;
+ m_CurByte = 0;
+ }
+ }
+ void WriteByte(Byte b) { m_Stream.WriteByte(b);}
+};
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitmDecoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitmDecoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitmDecoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitmDecoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,66 @@
+// BitmDecoder.h -- the Most Significant Bit of byte is First
+
+#ifndef __BITM_DECODER_H
+#define __BITM_DECODER_H
+
+#include "../IStream.h"
+
+namespace NBitm {
+
+const unsigned kNumBigValueBits = 8 * 4;
+const unsigned kNumValueBytes = 3;
+const unsigned kNumValueBits = 8 * kNumValueBytes;
+
+const UInt32 kMask = (1 << kNumValueBits) - 1;
+
+template<class TInByte>
+class CDecoder
+{
+ unsigned m_BitPos;
+ UInt32 m_Value;
+public:
+ TInByte m_Stream;
+ bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
+ void SetStream(ISequentialInStream *inStream) { m_Stream.SetStream(inStream);}
+ void ReleaseStream() { m_Stream.ReleaseStream();}
+
+ void Init()
+ {
+ m_Stream.Init();
+ m_BitPos = kNumBigValueBits;
+ Normalize();
+ }
+
+ UInt64 GetProcessedSize() const { return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; }
+
+ void Normalize()
+ {
+ for (;m_BitPos >= 8; m_BitPos -= 8)
+ m_Value = (m_Value << 8) | m_Stream.ReadByte();
+ }
+
+ UInt32 GetValue(unsigned numBits) const
+ {
+ // return (m_Value << m_BitPos) >> (kNumBigValueBits - numBits);
+ return ((m_Value >> (8 - m_BitPos)) & kMask) >> (kNumValueBits - numBits);
+ }
+
+ void MovePos(unsigned numBits)
+ {
+ m_BitPos += numBits;
+ Normalize();
+ }
+
+ UInt32 ReadBits(unsigned numBits)
+ {
+ UInt32 res = GetValue(numBits);
+ MovePos(numBits);
+ return res;
+ }
+
+ void AlignToByte() { MovePos((32 - m_BitPos) & 7); }
+};
+
+}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitmEncoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitmEncoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitmEncoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BitmEncoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,50 @@
+// BitmEncoder.h -- the Most Significant Bit of byte is First
+
+#ifndef __BITM_ENCODER_H
+#define __BITM_ENCODER_H
+
+#include "../IStream.h"
+
+template<class TOutByte>
+class CBitmEncoder
+{
+ TOutByte m_Stream;
+ unsigned m_BitPos;
+ Byte m_CurByte;
+public:
+ bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
+ void SetStream(ISequentialOutStream *outStream) { m_Stream.SetStream(outStream);}
+ void ReleaseStream() { m_Stream.ReleaseStream(); }
+ UInt64 GetProcessedSize() const { return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) / 8; }
+ void Init()
+ {
+ m_Stream.Init();
+ m_BitPos = 8;
+ m_CurByte = 0;
+ }
+ HRESULT Flush()
+ {
+ if (m_BitPos < 8)
+ WriteBits(0, m_BitPos);
+ return m_Stream.Flush();
+ }
+ void WriteBits(UInt32 value, unsigned numBits)
+ {
+ while (numBits > 0)
+ {
+ if (numBits < m_BitPos)
+ {
+ m_CurByte |= ((Byte)value << (m_BitPos -= numBits));
+ return;
+ }
+ numBits -= m_BitPos;
+ UInt32 newBits = (value >> numBits);
+ value -= (newBits << numBits);
+ m_Stream.WriteByte((Byte)(m_CurByte | newBits));
+ m_BitPos = 8;
+ m_CurByte = 0;
+ }
+ }
+};
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchCoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchCoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchCoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchCoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,19 @@
+// BranchCoder.cpp
+
+#include "StdAfx.h"
+
+#include "BranchCoder.h"
+
+STDMETHODIMP CBranchConverter::Init()
+{
+ _bufferPos = 0;
+ SubInit();
+ return S_OK;
+}
+
+STDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size)
+{
+ UInt32 processedSize = SubFilter(data, size);
+ _bufferPos += processedSize;
+ return processedSize;
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchCoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchCoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchCoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchCoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,44 @@
+// BranchCoder.h
+
+#ifndef __COMPRESS_BRANCH_CODER_H
+#define __COMPRESS_BRANCH_CODER_H
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+class CBranchConverter:
+ public ICompressFilter,
+ public CMyUnknownImp
+{
+protected:
+ UInt32 _bufferPos;
+ virtual void SubInit() {}
+ virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0;
+public:
+ MY_UNKNOWN_IMP;
+ STDMETHOD(Init)();
+ STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
+};
+
+#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \
+ { public: UInt32 SubFilter(Byte *data, UInt32 size); };
+
+#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \
+ { public: UInt32 SubFilter(Byte *data, UInt32 size); };
+
+#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \
+ { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};
+
+#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \
+ { public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};
+
+#define MyClassA(Name, id, subId) \
+MyClassEncoderA(Name ## _Encoder) \
+MyClassDecoderA(Name ## _Decoder)
+
+#define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT) \
+MyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \
+MyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT)
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchMisc.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchMisc.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchMisc.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchMisc.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,37 @@
+// BranchMisc.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/Bra.h"
+
+#include "BranchMisc.h"
+
+UInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::ARM_Convert(data, size, _bufferPos, 1); }
+
+UInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::ARM_Convert(data, size, _bufferPos, 0); }
+
+UInt32 CBC_ARMT_Encoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 1); }
+
+UInt32 CBC_ARMT_Decoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 0); }
+
+UInt32 CBC_PPC_Encoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::PPC_Convert(data, size, _bufferPos, 1); }
+
+UInt32 CBC_PPC_Decoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::PPC_Convert(data, size, _bufferPos, 0); }
+
+UInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 1); }
+
+UInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 0); }
+
+UInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::IA64_Convert(data, size, _bufferPos, 1); }
+
+UInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size)
+ { return (UInt32)::IA64_Convert(data, size, _bufferPos, 0); }
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchMisc.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchMisc.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchMisc.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchMisc.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,14 @@
+// BranchMisc.h
+
+#ifndef __COMPRESS_BRANCH_MISC_H
+#define __COMPRESS_BRANCH_MISC_H
+
+#include "BranchCoder.h"
+
+MyClassA(BC_ARM, 0x05, 1)
+MyClassA(BC_ARMT, 0x07, 1)
+MyClassA(BC_PPC, 0x02, 5)
+MyClassA(BC_SPARC, 0x08, 5)
+MyClassA(BC_IA64, 0x04, 1)
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchRegister.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchRegister.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/BranchRegister.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,30 @@
+// BranchRegister.cpp
+
+#include "StdAfx.h"
+
+#include "../Common/RegisterCodec.h"
+
+#include "BranchMisc.h"
+
+#define CREATE_CODEC(x) \
+ static void *CreateCodec ## x() { return (void *)(ICompressFilter *)(new C ## x ## _Decoder); } \
+ static void *CreateCodec ## x ## Out() { return (void *)(ICompressFilter *)(new C ## x ## _Encoder); }
+
+CREATE_CODEC(BC_PPC)
+CREATE_CODEC(BC_IA64)
+CREATE_CODEC(BC_ARM)
+CREATE_CODEC(BC_ARMT)
+CREATE_CODEC(BC_SPARC)
+
+#define METHOD_ITEM(x, id1, id2, name) { CreateCodec ## x, CreateCodec ## x ## Out, 0x03030000 + (id1 * 256) + id2, name, 1, true }
+
+static CCodecInfo g_CodecsInfo[] =
+{
+ METHOD_ITEM(BC_PPC, 0x02, 0x05, L"PPC"),
+ METHOD_ITEM(BC_IA64, 0x04, 1, L"IA64"),
+ METHOD_ITEM(BC_ARM, 0x05, 1, L"ARM"),
+ METHOD_ITEM(BC_ARMT, 0x07, 1, L"ARMT"),
+ METHOD_ITEM(BC_SPARC, 0x08, 0x05, L"SPARC")
+};
+
+REGISTER_CODECS(Branch)
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ByteSwap.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ByteSwap.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ByteSwap.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ByteSwap.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,73 @@
+// ByteSwap.cpp
+
+#include "StdAfx.h"
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+#include "../Common/RegisterCodec.h"
+
+class CByteSwap2:
+ public ICompressFilter,
+ public CMyUnknownImp
+{
+public:
+ MY_UNKNOWN_IMP
+ STDMETHOD(Init)();
+ STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
+};
+
+class CByteSwap4:
+ public ICompressFilter,
+ public CMyUnknownImp
+{
+public:
+ MY_UNKNOWN_IMP
+ STDMETHOD(Init)();
+ STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
+};
+
+STDMETHODIMP CByteSwap2::Init() { return S_OK; }
+
+STDMETHODIMP_(UInt32) CByteSwap2::Filter(Byte *data, UInt32 size)
+{
+ const UInt32 kStep = 2;
+ UInt32 i;
+ for (i = 0; i + kStep <= size; i += kStep)
+ {
+ Byte b = data[i];
+ data[i] = data[i + 1];
+ data[i + 1] = b;
+ }
+ return i;
+}
+
+STDMETHODIMP CByteSwap4::Init() { return S_OK; }
+
+STDMETHODIMP_(UInt32) CByteSwap4::Filter(Byte *data, UInt32 size)
+{
+ const UInt32 kStep = 4;
+ UInt32 i;
+ for (i = 0; i + kStep <= size; i += kStep)
+ {
+ Byte b0 = data[i];
+ Byte b1 = data[i + 1];
+ data[i] = data[i + 3];
+ data[i + 1] = data[i + 2];
+ data[i + 2] = b1;
+ data[i + 3] = b0;
+ }
+ return i;
+}
+
+static void *CreateCodec2() { return (void *)(ICompressFilter *)(new CByteSwap2); }
+static void *CreateCodec4() { return (void *)(ICompressFilter *)(new CByteSwap4); }
+
+static CCodecInfo g_CodecsInfo[] =
+{
+ { CreateCodec2, CreateCodec2, 0x020302, L"Swap2", 1, true },
+ { CreateCodec4, CreateCodec4, 0x020304, L"Swap4", 1, true }
+};
+
+REGISTER_CODECS(ByteSwap)
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CodecExports.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CodecExports.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CodecExports.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CodecExports.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,160 @@
+// CodecExports.cpp
+
+#include "StdAfx.h"
+
+#include "../../Common/ComTry.h"
+
+#include "../../Windows/PropVariant.h"
+
+#include "../ICoder.h"
+
+#include "../Common/RegisterCodec.h"
+
+extern unsigned int g_NumCodecs;
+extern const CCodecInfo *g_Codecs[];
+
+static const UInt16 kDecodeId = 0x2790;
+
+DEFINE_GUID(CLSID_CCodec,
+0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+
+static inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)
+{
+ if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)
+ value->vt = VT_BSTR;
+ return S_OK;
+}
+
+static inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)
+{
+ return SetPropString((const char *)&guid, sizeof(GUID), value);
+}
+
+static HRESULT SetClassID(CMethodId id, bool encode, PROPVARIANT *value)
+{
+ GUID clsId = CLSID_CCodec;
+ for (int i = 0; i < sizeof(id); i++, id >>= 8)
+ clsId.Data4[i] = (Byte)(id & 0xFF);
+ if (encode)
+ clsId.Data3++;
+ return SetPropGUID(clsId, value);
+}
+
+static HRESULT FindCodecClassId(const GUID *clsID, UInt32 isCoder2, bool isFilter, bool &encode, int &index)
+{
+ index = -1;
+ if (clsID->Data1 != CLSID_CCodec.Data1 ||
+ clsID->Data2 != CLSID_CCodec.Data2 ||
+ (clsID->Data3 & ~1) != kDecodeId)
+ return S_OK;
+ encode = (clsID->Data3 != kDecodeId);
+ UInt64 id = 0;
+ for (int j = 0; j < 8; j++)
+ id |= ((UInt64)clsID->Data4[j]) << (8 * j);
+ for (unsigned i = 0; i < g_NumCodecs; i++)
+ {
+ const CCodecInfo &codec = *g_Codecs[i];
+ if (id != codec.Id || encode && !codec.CreateEncoder || !encode && !codec.CreateDecoder)
+ continue;
+ if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||
+ codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)
+ return E_NOINTERFACE;
+ index = i;
+ return S_OK;
+ }
+ return S_OK;
+}
+
+STDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject)
+{
+ COM_TRY_BEGIN
+ *outObject = 0;
+ bool isCoder = (*iid == IID_ICompressCoder) != 0;
+ bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;
+ bool isFilter = (*iid == IID_ICompressFilter) != 0;
+ const CCodecInfo &codec = *g_Codecs[index];
+ if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||
+ codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)
+ return E_NOINTERFACE;
+ if (encode)
+ {
+ if (!codec.CreateEncoder)
+ return CLASS_E_CLASSNOTAVAILABLE;
+ *outObject = codec.CreateEncoder();
+ }
+ else
+ {
+ if (!codec.CreateDecoder)
+ return CLASS_E_CLASSNOTAVAILABLE;
+ *outObject = codec.CreateDecoder();
+ }
+ if (isCoder)
+ ((ICompressCoder *)*outObject)->AddRef();
+ else if (isCoder2)
+ ((ICompressCoder2 *)*outObject)->AddRef();
+ else
+ ((ICompressFilter *)*outObject)->AddRef();
+ return S_OK;
+ COM_TRY_END
+}
+
+STDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject)
+{
+ *outObject = 0;
+ bool isCoder = (*iid == IID_ICompressCoder) != 0;
+ bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;
+ bool isFilter = (*iid == IID_ICompressFilter) != 0;
+ if (!isCoder && !isCoder2 && !isFilter)
+ return E_NOINTERFACE;
+ bool encode;
+ int codecIndex;
+ HRESULT res = FindCodecClassId(clsid, isCoder2, isFilter, encode, codecIndex);
+ if (res != S_OK)
+ return res;
+ if (codecIndex < 0)
+ return CLASS_E_CLASSNOTAVAILABLE;
+ return CreateCoder2(encode, codecIndex, iid, outObject);
+}
+
+STDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value)
+{
+ ::VariantClear((VARIANTARG *)value);
+ const CCodecInfo &codec = *g_Codecs[codecIndex];
+ switch(propID)
+ {
+ case NMethodPropID::kID:
+ {
+ value->uhVal.QuadPart = (UInt64)codec.Id;
+ value->vt = VT_UI8;
+ break;
+ }
+ case NMethodPropID::kName:
+ if ((value->bstrVal = ::SysAllocString(codec.Name)) != 0)
+ value->vt = VT_BSTR;
+ break;
+ case NMethodPropID::kDecoder:
+ if (codec.CreateDecoder)
+ return SetClassID(codec.Id, false, value);
+ break;
+ case NMethodPropID::kEncoder:
+ if (codec.CreateEncoder)
+ return SetClassID(codec.Id, true, value);
+ break;
+ case NMethodPropID::kInStreams:
+ {
+ if (codec.NumInStreams != 1)
+ {
+ value->vt = VT_UI4;
+ value->ulVal = (ULONG)codec.NumInStreams;
+ }
+ break;
+ }
+ }
+ return S_OK;
+}
+
+STDAPI GetNumberOfMethods(UINT32 *numCodecs)
+{
+ *numCodecs = g_NumCodecs;
+ return S_OK;
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CopyCoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CopyCoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CopyCoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CopyCoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,67 @@
+// Compress/CopyCoder.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/Alloc.h"
+
+#include "../Common/StreamUtils.h"
+
+#include "CopyCoder.h"
+
+namespace NCompress {
+
+static const UInt32 kBufferSize = 1 << 17;
+
+CCopyCoder::~CCopyCoder()
+{
+ ::MidFree(_buffer);
+}
+
+STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,
+ ISequentialOutStream *outStream,
+ const UInt64 * /* inSize */, const UInt64 *outSize,
+ ICompressProgressInfo *progress)
+{
+ if (_buffer == 0)
+ {
+ _buffer = (Byte *)::MidAlloc(kBufferSize);
+ if (_buffer == 0)
+ return E_OUTOFMEMORY;
+ }
+
+ TotalSize = 0;
+ for (;;)
+ {
+ UInt32 size = kBufferSize;
+ if (outSize != 0)
+ if (size > *outSize - TotalSize)
+ size = (UInt32)(*outSize - TotalSize);
+ RINOK(inStream->Read(_buffer, size, &size));
+ if (size == 0)
+ break;
+ if (outStream)
+ {
+ RINOK(WriteStream(outStream, _buffer, size));
+ }
+ TotalSize += size;
+ if (progress != NULL)
+ {
+ RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));
+ }
+ }
+ return S_OK;
+}
+
+STDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value)
+{
+ *value = TotalSize;
+ return S_OK;
+}
+
+HRESULT CopyStream(ISequentialInStream *inStream, ISequentialOutStream *outStream, ICompressProgressInfo *progress)
+{
+ CMyComPtr<ICompressCoder> copyCoder = new NCompress::CCopyCoder;
+ return copyCoder->Code(inStream, outStream, NULL, NULL, progress);
+}
+
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CopyCoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CopyCoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CopyCoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CopyCoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,34 @@
+// Compress/CopyCoder.h
+
+#ifndef __COMPRESS_COPY_CODER_H
+#define __COMPRESS_COPY_CODER_H
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+namespace NCompress {
+
+class CCopyCoder:
+ public ICompressCoder,
+ public ICompressGetInStreamProcessedSize,
+ public CMyUnknownImp
+{
+ Byte *_buffer;
+public:
+ UInt64 TotalSize;
+ CCopyCoder(): TotalSize(0), _buffer(0) {};
+ ~CCopyCoder();
+
+ MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+ STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);
+};
+
+HRESULT CopyStream(ISequentialInStream *inStream, ISequentialOutStream *outStream, ICompressProgressInfo *progress);
+
+}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CopyRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CopyRegister.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CopyRegister.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/CopyRegister.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,14 @@
+// CopyRegister.cpp
+
+#include "StdAfx.h"
+
+#include "../Common/RegisterCodec.h"
+
+#include "CopyCoder.h"
+
+static void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::CCopyCoder); }
+
+static CCodecInfo g_CodecInfo =
+{ CreateCodec, CreateCodec, 0x00, L"Copy", 1, false };
+
+REGISTER_CODEC(Copy)
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Deflate64Register.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Deflate64Register.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Deflate64Register.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Deflate64Register.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,20 @@
+// Deflate64Register.cpp
+
+#include "StdAfx.h"
+
+#include "../Common/RegisterCodec.h"
+
+#include "DeflateDecoder.h"
+
+static void *CreateCodecDeflate64() { return (void *)(ICompressCoder *)(new NCompress::NDeflate::NDecoder::CCOMCoder64); }
+#if !defined(EXTRACT_ONLY) && !defined(DEFLATE_EXTRACT_ONLY)
+#include "DeflateEncoder.h"
+static void *CreateCodecOutDeflate64() { return (void *)(ICompressCoder *)(new NCompress::NDeflate::NEncoder::CCOMCoder64); }
+#else
+#define CreateCodecOutDeflate64 0
+#endif
+
+static CCodecInfo g_CodecInfo =
+ { CreateCodecDeflate64, CreateCodecOutDeflate64, 0x040109, L"Deflate64", 1, false };
+
+REGISTER_CODEC(Deflate64)
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateConst.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateConst.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateConst.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateConst.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,134 @@
+// DeflateConst.h
+
+#ifndef __DEFLATE_CONST_H
+#define __DEFLATE_CONST_H
+
+namespace NCompress {
+namespace NDeflate {
+
+const int kNumHuffmanBits = 15;
+
+const UInt32 kHistorySize32 = (1 << 15);
+const UInt32 kHistorySize64 = (1 << 16);
+
+const UInt32 kDistTableSize32 = 30;
+const UInt32 kDistTableSize64 = 32;
+
+const UInt32 kNumLenSymbols32 = 256;
+const UInt32 kNumLenSymbols64 = 255; // don't change it. It must be <= 255.
+const UInt32 kNumLenSymbolsMax = kNumLenSymbols32;
+
+const UInt32 kNumLenSlots = 29;
+
+const UInt32 kFixedDistTableSize = 32;
+const UInt32 kFixedLenTableSize = 31;
+
+const UInt32 kSymbolEndOfBlock = 0x100;
+const UInt32 kSymbolMatch = kSymbolEndOfBlock + 1;
+
+const UInt32 kMainTableSize = kSymbolMatch + kNumLenSlots;
+const UInt32 kFixedMainTableSize = kSymbolMatch + kFixedLenTableSize;
+
+const UInt32 kLevelTableSize = 19;
+
+const UInt32 kTableDirectLevels = 16;
+const UInt32 kTableLevelRepNumber = kTableDirectLevels;
+const UInt32 kTableLevel0Number = kTableLevelRepNumber + 1;
+const UInt32 kTableLevel0Number2 = kTableLevel0Number + 1;
+
+const UInt32 kLevelMask = 0xF;
+
+const Byte kLenStart32[kFixedLenTableSize] =
+ {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, 255, 0, 0};
+const Byte kLenStart64[kFixedLenTableSize] =
+ {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, 0, 0, 0};
+
+const Byte kLenDirectBits32[kFixedLenTableSize] =
+ {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, 0, 0, 0};
+const Byte kLenDirectBits64[kFixedLenTableSize] =
+ {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, 16, 0, 0};
+
+const UInt32 kDistStart[kDistTableSize64] =
+ {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,32768,49152};
+const Byte kDistDirectBits[kDistTableSize64] =
+ {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};
+
+const Byte kLevelDirectBits[3] = {2, 3, 7};
+
+const Byte kCodeLengthAlphabetOrder[kLevelTableSize] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
+
+const UInt32 kMatchMinLen = 3;
+const UInt32 kMatchMaxLen32 = kNumLenSymbols32 + kMatchMinLen - 1; //256 + 2
+const UInt32 kMatchMaxLen64 = kNumLenSymbols64 + kMatchMinLen - 1; //255 + 2
+const UInt32 kMatchMaxLen = kMatchMaxLen32;
+
+const int kFinalBlockFieldSize = 1;
+
+namespace NFinalBlockField
+{
+ enum
+ {
+ kNotFinalBlock = 0,
+ kFinalBlock = 1
+ };
+}
+
+const int kBlockTypeFieldSize = 2;
+
+namespace NBlockType
+{
+ enum
+ {
+ kStored = 0,
+ kFixedHuffman = 1,
+ kDynamicHuffman = 2
+ };
+}
+
+const int kNumLenCodesFieldSize = 5;
+const int kNumDistCodesFieldSize = 5;
+const int kNumLevelCodesFieldSize = 4;
+
+const UInt32 kNumLitLenCodesMin = 257;
+const UInt32 kNumDistCodesMin = 1;
+const UInt32 kNumLevelCodesMin = 4;
+
+const int kLevelFieldSize = 3;
+
+const int kStoredBlockLengthFieldSize = 16;
+
+struct CLevels
+{
+ Byte litLenLevels[kFixedMainTableSize];
+ Byte distLevels[kFixedDistTableSize];
+
+ void SubClear()
+ {
+ UInt32 i;
+ for(i = kNumLitLenCodesMin; i < kFixedMainTableSize; i++)
+ litLenLevels[i] = 0;
+ for(i = 0; i < kFixedDistTableSize; i++)
+ distLevels[i] = 0;
+ }
+
+ void SetFixedLevels()
+ {
+ int i;
+
+ for (i = 0; i < 144; i++)
+ litLenLevels[i] = 8;
+ for (; i < 256; i++)
+ litLenLevels[i] = 9;
+ for (; i < 280; i++)
+ litLenLevels[i] = 7;
+ for (; i < 288; i++)
+ litLenLevels[i] = 8;
+ for (i = 0; i < kFixedDistTableSize; i++) // test it: InfoZip only uses kDistTableSize
+ distLevels[i] = 5;
+ }
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateDecoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateDecoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateDecoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateDecoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,353 @@
+// DeflateDecoder.cpp
+
+#include "StdAfx.h"
+
+#include "DeflateDecoder.h"
+
+namespace NCompress {
+namespace NDeflate {
+namespace NDecoder {
+
+static const int kLenIdFinished = -1;
+static const int kLenIdNeedInit = -2;
+
+CCoder::CCoder(bool deflate64Mode, bool deflateNSIS):
+ _deflate64Mode(deflate64Mode),
+ _deflateNSIS(deflateNSIS),
+ _keepHistory(false),
+ _needInitInStream(true),
+ ZlibMode(false) {}
+
+UInt32 CCoder::ReadBits(int numBits)
+{
+ return m_InBitStream.ReadBits(numBits);
+}
+
+bool CCoder::DeCodeLevelTable(Byte *values, int numSymbols)
+{
+ int i = 0;
+ do
+ {
+ UInt32 number = m_LevelDecoder.DecodeSymbol(&m_InBitStream);
+ if (number < kTableDirectLevels)
+ values[i++] = (Byte)number;
+ else if (number < kLevelTableSize)
+ {
+ if (number == kTableLevelRepNumber)
+ {
+ if (i == 0)
+ return false;
+ int num = ReadBits(2) + 3;
+ for (; num > 0 && i < numSymbols; num--, i++)
+ values[i] = values[i - 1];
+ }
+ else
+ {
+ int num;
+ if (number == kTableLevel0Number)
+ num = ReadBits(3) + 3;
+ else
+ num = ReadBits(7) + 11;
+ for (;num > 0 && i < numSymbols; num--)
+ values[i++] = 0;
+ }
+ }
+ else
+ return false;
+ }
+ while(i < numSymbols);
+ return true;
+}
+
+#define RIF(x) { if (!(x)) return false; }
+
+bool CCoder::ReadTables(void)
+{
+ m_FinalBlock = (ReadBits(kFinalBlockFieldSize) == NFinalBlockField::kFinalBlock);
+ UInt32 blockType = ReadBits(kBlockTypeFieldSize);
+ if (blockType > NBlockType::kDynamicHuffman)
+ return false;
+
+ if (blockType == NBlockType::kStored)
+ {
+ m_StoredMode = true;
+ m_InBitStream.AlignToByte();
+ m_StoredBlockSize = ReadBits(kStoredBlockLengthFieldSize);
+ if (_deflateNSIS)
+ return true;
+ return (m_StoredBlockSize == (UInt16)~ReadBits(kStoredBlockLengthFieldSize));
+ }
+
+ m_StoredMode = false;
+
+ CLevels levels;
+ if (blockType == NBlockType::kFixedHuffman)
+ {
+ levels.SetFixedLevels();
+ _numDistLevels = _deflate64Mode ? kDistTableSize64 : kDistTableSize32;
+ }
+ else
+ {
+ int numLitLenLevels = ReadBits(kNumLenCodesFieldSize) + kNumLitLenCodesMin;
+ _numDistLevels = ReadBits(kNumDistCodesFieldSize) + kNumDistCodesMin;
+ int numLevelCodes = ReadBits(kNumLevelCodesFieldSize) + kNumLevelCodesMin;
+
+ if (!_deflate64Mode)
+ if (_numDistLevels > kDistTableSize32)
+ return false;
+
+ Byte levelLevels[kLevelTableSize];
+ for (int i = 0; i < kLevelTableSize; i++)
+ {
+ int position = kCodeLengthAlphabetOrder[i];
+ if(i < numLevelCodes)
+ levelLevels[position] = (Byte)ReadBits(kLevelFieldSize);
+ else
+ levelLevels[position] = 0;
+ }
+
+ RIF(m_LevelDecoder.SetCodeLengths(levelLevels));
+
+ Byte tmpLevels[kFixedMainTableSize + kFixedDistTableSize];
+ if (!DeCodeLevelTable(tmpLevels, numLitLenLevels + _numDistLevels))
+ return false;
+
+ levels.SubClear();
+ memcpy(levels.litLenLevels, tmpLevels, numLitLenLevels);
+ memcpy(levels.distLevels, tmpLevels + numLitLenLevels, _numDistLevels);
+ }
+ RIF(m_MainDecoder.SetCodeLengths(levels.litLenLevels));
+ return m_DistDecoder.SetCodeLengths(levels.distLevels);
+}
+
+HRESULT CCoder::CodeSpec(UInt32 curSize)
+{
+ if (_remainLen == kLenIdFinished)
+ return S_OK;
+ if (_remainLen == kLenIdNeedInit)
+ {
+ if (!_keepHistory)
+ if (!m_OutWindowStream.Create(_deflate64Mode ? kHistorySize64: kHistorySize32))
+ return E_OUTOFMEMORY;
+ RINOK(InitInStream(_needInitInStream));
+ m_OutWindowStream.Init(_keepHistory);
+ m_FinalBlock = false;
+ _remainLen = 0;
+ _needReadTable = true;
+ }
+
+ if (curSize == 0)
+ return S_OK;
+
+ while(_remainLen > 0 && curSize > 0)
+ {
+ _remainLen--;
+ Byte b = m_OutWindowStream.GetByte(_rep0);
+ m_OutWindowStream.PutByte(b);
+ curSize--;
+ }
+
+ while(curSize > 0)
+ {
+ if (_needReadTable)
+ {
+ if (m_FinalBlock)
+ {
+ _remainLen = kLenIdFinished;
+ break;
+ }
+ if (!ReadTables())
+ return S_FALSE;
+ _needReadTable = false;
+ }
+
+ if(m_StoredMode)
+ {
+ for (; m_StoredBlockSize > 0 && curSize > 0; m_StoredBlockSize--, curSize--)
+ m_OutWindowStream.PutByte(m_InBitStream.ReadByte());
+ _needReadTable = (m_StoredBlockSize == 0);
+ continue;
+ }
+ while(curSize > 0)
+ {
+ if (m_InBitStream.NumExtraBytes > 4)
+ return S_FALSE;
+
+ UInt32 number = m_MainDecoder.DecodeSymbol(&m_InBitStream);
+ if (number < 0x100)
+ {
+ m_OutWindowStream.PutByte((Byte)number);
+ curSize--;
+ continue;
+ }
+ else if (number == kSymbolEndOfBlock)
+ {
+ _needReadTable = true;
+ break;
+ }
+ else if (number < kMainTableSize)
+ {
+ number -= kSymbolMatch;
+ UInt32 len;
+ {
+ int numBits;
+ if (_deflate64Mode)
+ {
+ len = kLenStart64[number];
+ numBits = kLenDirectBits64[number];
+ }
+ else
+ {
+ len = kLenStart32[number];
+ numBits = kLenDirectBits32[number];
+ }
+ len += kMatchMinLen + m_InBitStream.ReadBits(numBits);
+ }
+ UInt32 locLen = len;
+ if (locLen > curSize)
+ locLen = (UInt32)curSize;
+ number = m_DistDecoder.DecodeSymbol(&m_InBitStream);
+ if (number >= _numDistLevels)
+ return S_FALSE;
+ UInt32 distance = kDistStart[number] + m_InBitStream.ReadBits(kDistDirectBits[number]);
+ if (!m_OutWindowStream.CopyBlock(distance, locLen))
+ return S_FALSE;
+ curSize -= locLen;
+ len -= locLen;
+ if (len != 0)
+ {
+ _remainLen = (Int32)len;
+ _rep0 = distance;
+ break;
+ }
+ }
+ else
+ return S_FALSE;
+ }
+ }
+ return S_OK;
+}
+
+#ifdef _NO_EXCEPTIONS
+
+#define DEFLATE_TRY_BEGIN
+#define DEFLATE_TRY_END
+
+#else
+
+#define DEFLATE_TRY_BEGIN try {
+#define DEFLATE_TRY_END } \
+ catch(const CInBufferException &e) { return e.ErrorCode; } \
+ catch(const CLzOutWindowException &e) { return e.ErrorCode; } \
+ catch(...) { return S_FALSE; }
+
+#endif
+
+HRESULT CCoder::CodeReal(ISequentialOutStream *outStream,
+ const UInt64 *outSize, ICompressProgressInfo *progress)
+{
+ DEFLATE_TRY_BEGIN
+ m_OutWindowStream.SetStream(outStream);
+ CCoderReleaser flusher(this);
+
+ const UInt64 inStart = _needInitInStream ? 0 : m_InBitStream.GetProcessedSize();
+ const UInt64 start = m_OutWindowStream.GetProcessedSize();
+ for (;;)
+ {
+ UInt32 curSize = 1 << 18;
+ if (outSize != 0)
+ {
+ const UInt64 rem = *outSize - (m_OutWindowStream.GetProcessedSize() - start);
+ if (curSize > rem)
+ curSize = (UInt32)rem;
+ }
+ if (curSize == 0)
+ break;
+ RINOK(CodeSpec(curSize));
+ if (_remainLen == kLenIdFinished)
+ break;
+ if (progress != NULL)
+ {
+ const UInt64 inSize = m_InBitStream.GetProcessedSize() - inStart;
+ const UInt64 nowPos64 = m_OutWindowStream.GetProcessedSize() - start;
+ RINOK(progress->SetRatioInfo(&inSize, &nowPos64));
+ }
+ }
+ if (_remainLen == kLenIdFinished && ZlibMode)
+ {
+ m_InBitStream.AlignToByte();
+ for (int i = 0; i < 4; i++)
+ ZlibFooter[i] = m_InBitStream.ReadByte();
+ }
+ flusher.NeedFlush = false;
+ HRESULT res = Flush();
+ if (res == S_OK && InputEofError())
+ return S_FALSE;
+ return res;
+ DEFLATE_TRY_END
+}
+
+HRESULT CCoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)
+{
+ SetInStream(inStream);
+ SetOutStreamSize(outSize);
+ HRESULT res = CodeReal(outStream, outSize, progress);
+ ReleaseInStream();
+ return res;
+}
+
+STDMETHODIMP CCoder::GetInStreamProcessedSize(UInt64 *value)
+{
+ if (value == NULL)
+ return E_INVALIDARG;
+ *value = m_InBitStream.GetProcessedSize();
+ return S_OK;
+}
+
+STDMETHODIMP CCoder::SetInStream(ISequentialInStream *inStream)
+{
+ m_InBitStream.SetStream(inStream);
+ return S_OK;
+}
+
+STDMETHODIMP CCoder::ReleaseInStream()
+{
+ m_InBitStream.ReleaseStream();
+ return S_OK;
+}
+
+STDMETHODIMP CCoder::SetOutStreamSize(const UInt64 * /* outSize */)
+{
+ _remainLen = kLenIdNeedInit;
+ _needInitInStream = true;
+ m_OutWindowStream.Init(_keepHistory);
+ return S_OK;
+}
+
+#ifndef NO_READ_FROM_CODER
+
+STDMETHODIMP CCoder::Read(void *data, UInt32 size, UInt32 *processedSize)
+{
+ DEFLATE_TRY_BEGIN
+ if (processedSize)
+ *processedSize = 0;
+ const UInt64 startPos = m_OutWindowStream.GetProcessedSize();
+ m_OutWindowStream.SetMemStream((Byte *)data);
+ RINOK(CodeSpec(size));
+ if (processedSize)
+ *processedSize = (UInt32)(m_OutWindowStream.GetProcessedSize() - startPos);
+ return Flush();
+ DEFLATE_TRY_END
+}
+
+#endif
+
+STDMETHODIMP CCoder::CodeResume(ISequentialOutStream *outStream, const UInt64 *outSize, ICompressProgressInfo *progress)
+{
+ _remainLen = kLenIdNeedInit;
+ m_OutWindowStream.Init(_keepHistory);
+ return CodeReal(outStream, outSize, progress);
+}
+
+}}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateDecoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateDecoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateDecoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateDecoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,157 @@
+// DeflateDecoder.h
+
+#ifndef __DEFLATE_DECODER_H
+#define __DEFLATE_DECODER_H
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+#include "../Common/InBuffer.h"
+
+#include "BitlDecoder.h"
+#include "DeflateConst.h"
+#include "HuffmanDecoder.h"
+#include "LzOutWindow.h"
+
+namespace NCompress {
+namespace NDeflate {
+namespace NDecoder {
+
+class CCoder:
+ public ICompressCoder,
+ public ICompressGetInStreamProcessedSize,
+ #ifndef NO_READ_FROM_CODER
+ public ICompressSetInStream,
+ public ICompressSetOutStreamSize,
+ public ISequentialInStream,
+ #endif
+ public CMyUnknownImp
+{
+ CLzOutWindow m_OutWindowStream;
+ NBitl::CDecoder<CInBuffer> m_InBitStream;
+ NCompress::NHuffman::CDecoder<kNumHuffmanBits, kFixedMainTableSize> m_MainDecoder;
+ NCompress::NHuffman::CDecoder<kNumHuffmanBits, kFixedDistTableSize> m_DistDecoder;
+ NCompress::NHuffman::CDecoder<kNumHuffmanBits, kLevelTableSize> m_LevelDecoder;
+
+ UInt32 m_StoredBlockSize;
+
+ bool m_FinalBlock;
+ bool m_StoredMode;
+ UInt32 _numDistLevels;
+
+
+ bool _deflateNSIS;
+ bool _deflate64Mode;
+ bool _keepHistory;
+ bool _needInitInStream;
+ Int32 _remainLen;
+ UInt32 _rep0;
+ bool _needReadTable;
+
+ UInt32 ReadBits(int numBits);
+
+ bool DeCodeLevelTable(Byte *values, int numSymbols);
+ bool ReadTables();
+
+ HRESULT Flush() { return m_OutWindowStream.Flush(); }
+ class CCoderReleaser
+ {
+ CCoder *_coder;
+ public:
+ bool NeedFlush;
+ CCoderReleaser(CCoder *coder): _coder(coder), NeedFlush(true) {}
+ ~CCoderReleaser()
+ {
+ if (NeedFlush)
+ _coder->Flush();
+ _coder->ReleaseOutStream();
+ }
+ };
+ friend class CCoderReleaser;
+
+ HRESULT CodeSpec(UInt32 curSize);
+public:
+ bool ZlibMode;
+ Byte ZlibFooter[4];
+
+ CCoder(bool deflate64Mode, bool deflateNSIS = false);
+ virtual ~CCoder() {};
+
+ void SetKeepHistory(bool keepHistory) { _keepHistory = keepHistory; }
+
+ void ReleaseOutStream()
+ {
+ m_OutWindowStream.ReleaseStream();
+ }
+
+ HRESULT CodeReal(ISequentialOutStream *outStream,
+ const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ #ifndef NO_READ_FROM_CODER
+ MY_UNKNOWN_IMP4(
+ ICompressGetInStreamProcessedSize,
+ ICompressSetInStream,
+ ICompressSetOutStreamSize,
+ ISequentialInStream
+ )
+ #else
+ MY_UNKNOWN_IMP1(
+ ICompressGetInStreamProcessedSize)
+ #endif
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ STDMETHOD(SetInStream)(ISequentialInStream *inStream);
+ STDMETHOD(ReleaseInStream)();
+ STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);
+
+ #ifndef NO_READ_FROM_CODER
+ STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
+ #endif
+
+ STDMETHOD(CodeResume)(ISequentialOutStream *outStream, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ HRESULT InitInStream(bool needInit)
+ {
+ if (!m_InBitStream.Create(1 << 17))
+ return E_OUTOFMEMORY;
+ if (needInit)
+ {
+ m_InBitStream.Init();
+ _needInitInStream = false;
+ }
+ return S_OK;
+ }
+
+ void AlignToByte() { m_InBitStream.AlignToByte(); }
+ Byte ReadByte() { return (Byte)m_InBitStream.ReadBits(8); }
+ bool InputEofError() const { return m_InBitStream.ExtraBitsWereRead(); }
+ UInt64 GetInputProcessedSize() const { return m_InBitStream.GetProcessedSize(); }
+
+ // IGetInStreamProcessedSize
+ STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);
+};
+
+class CCOMCoder : public CCoder
+{
+public:
+ CCOMCoder(): CCoder(false) {}
+};
+
+class CNsisCOMCoder : public CCoder
+{
+public:
+ CNsisCOMCoder(): CCoder(false, true) {}
+};
+
+class CCOMCoder64 : public CCoder
+{
+public:
+ CCOMCoder64(): CCoder(true) {}
+};
+
+}}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateEncoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateEncoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateEncoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateEncoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,986 @@
+// DeflateEncoder.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/Alloc.h"
+#include "../../../C/HuffEnc.h"
+
+#include "Common/ComTry.h"
+
+#include "DeflateEncoder.h"
+
+#undef NO_INLINE
+
+#ifdef _MSC_VER
+#define NO_INLINE MY_NO_INLINE
+#else
+#define NO_INLINE
+#endif
+
+namespace NCompress {
+namespace NDeflate {
+namespace NEncoder {
+
+const int kNumDivPassesMax = 10; // [0, 16); ratio/speed/ram tradeoff; use big value for better compression ratio.
+const UInt32 kNumTables = (1 << kNumDivPassesMax);
+
+static UInt32 kFixedHuffmanCodeBlockSizeMax = (1 << 8); // [0, (1 << 32)); ratio/speed tradeoff; use big value for better compression ratio.
+static UInt32 kDivideCodeBlockSizeMin = (1 << 7); // [1, (1 << 32)); ratio/speed tradeoff; use small value for better compression ratio.
+static UInt32 kDivideBlockSizeMin = (1 << 6); // [1, (1 << 32)); ratio/speed tradeoff; use small value for better compression ratio.
+
+static const UInt32 kMaxUncompressedBlockSize = ((1 << 16) - 1) * 1; // [1, (1 << 32))
+static const UInt32 kMatchArraySize = kMaxUncompressedBlockSize * 10; // [kMatchMaxLen * 2, (1 << 32))
+static const UInt32 kMatchArrayLimit = kMatchArraySize - kMatchMaxLen * 4 * sizeof(UInt16);
+static const UInt32 kBlockUncompressedSizeThreshold = kMaxUncompressedBlockSize -
+ kMatchMaxLen - kNumOpts;
+
+static const int kMaxCodeBitLength = 11;
+static const int kMaxLevelBitLength = 7;
+
+static Byte kNoLiteralStatPrice = 11;
+static Byte kNoLenStatPrice = 11;
+static Byte kNoPosStatPrice = 6;
+
+static Byte g_LenSlots[kNumLenSymbolsMax];
+static Byte g_FastPos[1 << 9];
+
+class CFastPosInit
+{
+public:
+ CFastPosInit()
+ {
+ int i;
+ for(i = 0; i < kNumLenSlots; i++)
+ {
+ int c = kLenStart32[i];
+ int j = 1 << kLenDirectBits32[i];
+ for(int k = 0; k < j; k++, c++)
+ g_LenSlots[c] = (Byte)i;
+ }
+
+ const int kFastSlots = 18;
+ int c = 0;
+ for (Byte slotFast = 0; slotFast < kFastSlots; slotFast++)
+ {
+ UInt32 k = (1 << kDistDirectBits[slotFast]);
+ for (UInt32 j = 0; j < k; j++, c++)
+ g_FastPos[c] = slotFast;
+ }
+ }
+};
+
+static CFastPosInit g_FastPosInit;
+
+
+inline UInt32 GetPosSlot(UInt32 pos)
+{
+ if (pos < 0x200)
+ return g_FastPos[pos];
+ return g_FastPos[pos >> 8] + 16;
+}
+
+static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
+static void SzFree(void *p, void *address) { p = p; MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
+
+CCoder::CCoder(bool deflate64Mode):
+ m_Deflate64Mode(deflate64Mode),
+ m_NumPasses(1),
+ m_NumDivPasses(1),
+ m_NumFastBytes(32),
+ _fastMode(false),
+ _btMode(true),
+ m_OnePosMatchesMemory(0),
+ m_DistanceMemory(0),
+ m_Created(false),
+ m_Values(0),
+ m_Tables(0),
+ m_MatchFinderCycles(0)
+ // m_SetMfPasses(0)
+{
+ m_MatchMaxLen = deflate64Mode ? kMatchMaxLen64 : kMatchMaxLen32;
+ m_NumLenCombinations = deflate64Mode ? kNumLenSymbols64 : kNumLenSymbols32;
+ m_LenStart = deflate64Mode ? kLenStart64 : kLenStart32;
+ m_LenDirectBits = deflate64Mode ? kLenDirectBits64 : kLenDirectBits32;
+ MatchFinder_Construct(&_lzInWindow);
+}
+
+HRESULT CCoder::Create()
+{
+ COM_TRY_BEGIN
+ if (m_Values == 0)
+ {
+ m_Values = (CCodeValue *)MyAlloc((kMaxUncompressedBlockSize) * sizeof(CCodeValue));
+ if (m_Values == 0)
+ return E_OUTOFMEMORY;
+ }
+ if (m_Tables == 0)
+ {
+ m_Tables = (CTables *)MyAlloc((kNumTables) * sizeof(CTables));
+ if (m_Tables == 0)
+ return E_OUTOFMEMORY;
+ }
+
+ if (m_IsMultiPass)
+ {
+ if (m_OnePosMatchesMemory == 0)
+ {
+ m_OnePosMatchesMemory = (UInt16 *)::MidAlloc(kMatchArraySize * sizeof(UInt16));
+ if (m_OnePosMatchesMemory == 0)
+ return E_OUTOFMEMORY;
+ }
+ }
+ else
+ {
+ if (m_DistanceMemory == 0)
+ {
+ m_DistanceMemory = (UInt16 *)MyAlloc((kMatchMaxLen + 2) * 2 * sizeof(UInt16));
+ if (m_DistanceMemory == 0)
+ return E_OUTOFMEMORY;
+ m_MatchDistances = m_DistanceMemory;
+ }
+ }
+
+ if (!m_Created)
+ {
+ _lzInWindow.btMode = _btMode ? 1 : 0;
+ _lzInWindow.numHashBytes = 3;
+ if (!MatchFinder_Create(&_lzInWindow,
+ m_Deflate64Mode ? kHistorySize64 : kHistorySize32,
+ kNumOpts + kMaxUncompressedBlockSize,
+ m_NumFastBytes, m_MatchMaxLen - m_NumFastBytes, &g_Alloc))
+ return E_OUTOFMEMORY;
+ if (!m_OutStream.Create(1 << 20))
+ return E_OUTOFMEMORY;
+ }
+ if (m_MatchFinderCycles != 0)
+ _lzInWindow.cutValue = m_MatchFinderCycles;
+ m_Created = true;
+ return S_OK;
+ COM_TRY_END
+}
+
+HRESULT CCoder::BaseSetEncoderProperties2(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps)
+{
+ for (UInt32 i = 0; i < numProps; i++)
+ {
+ const PROPVARIANT &prop = props[i];
+ switch(propIDs[i])
+ {
+ case NCoderPropID::kNumPasses:
+ if (prop.vt != VT_UI4)
+ return E_INVALIDARG;
+ m_NumDivPasses = prop.ulVal;
+ if (m_NumDivPasses == 0)
+ m_NumDivPasses = 1;
+ if (m_NumDivPasses == 1)
+ m_NumPasses = 1;
+ else if (m_NumDivPasses <= kNumDivPassesMax)
+ m_NumPasses = 2;
+ else
+ {
+ m_NumPasses = 2 + (m_NumDivPasses - kNumDivPassesMax);
+ m_NumDivPasses = kNumDivPassesMax;
+ }
+ break;
+ case NCoderPropID::kNumFastBytes:
+ if (prop.vt != VT_UI4)
+ return E_INVALIDARG;
+ m_NumFastBytes = prop.ulVal;
+ if(m_NumFastBytes < kMatchMinLen || m_NumFastBytes > m_MatchMaxLen)
+ return E_INVALIDARG;
+ break;
+ case NCoderPropID::kMatchFinderCycles:
+ {
+ if (prop.vt != VT_UI4)
+ return E_INVALIDARG;
+ m_MatchFinderCycles = prop.ulVal;
+ break;
+ }
+ case NCoderPropID::kAlgorithm:
+ {
+ if (prop.vt != VT_UI4)
+ return E_INVALIDARG;
+ UInt32 maximize = prop.ulVal;
+ _fastMode = (maximize == 0);
+ _btMode = !_fastMode;
+ break;
+ }
+ default:
+ return E_INVALIDARG;
+ }
+ }
+ return S_OK;
+}
+
+void CCoder::Free()
+{
+ ::MidFree(m_OnePosMatchesMemory); m_OnePosMatchesMemory = 0;
+ ::MyFree(m_DistanceMemory); m_DistanceMemory = 0;
+ ::MyFree(m_Values); m_Values = 0;
+ ::MyFree(m_Tables); m_Tables = 0;
+}
+
+CCoder::~CCoder()
+{
+ Free();
+ MatchFinder_Free(&_lzInWindow, &g_Alloc);
+}
+
+NO_INLINE void CCoder::GetMatches()
+{
+ if (m_IsMultiPass)
+ {
+ m_MatchDistances = m_OnePosMatchesMemory + m_Pos;
+ if (m_SecondPass)
+ {
+ m_Pos += *m_MatchDistances + 1;
+ return;
+ }
+ }
+
+ UInt32 distanceTmp[kMatchMaxLen * 2 + 3];
+
+ UInt32 numPairs = (_btMode) ?
+ Bt3Zip_MatchFinder_GetMatches(&_lzInWindow, distanceTmp):
+ Hc3Zip_MatchFinder_GetMatches(&_lzInWindow, distanceTmp);
+
+ *m_MatchDistances = (UInt16)numPairs;
+
+ if (numPairs > 0)
+ {
+ UInt32 i;
+ for(i = 0; i < numPairs; i += 2)
+ {
+ m_MatchDistances[i + 1] = (UInt16)distanceTmp[i];
+ m_MatchDistances[i + 2] = (UInt16)distanceTmp[i + 1];
+ }
+ UInt32 len = distanceTmp[numPairs - 2];
+ if (len == m_NumFastBytes && m_NumFastBytes != m_MatchMaxLen)
+ {
+ UInt32 numAvail = Inline_MatchFinder_GetNumAvailableBytes(&_lzInWindow) + 1;
+ const Byte *pby = Inline_MatchFinder_GetPointerToCurrentPos(&_lzInWindow) - 1;
+ const Byte *pby2 = pby - (distanceTmp[numPairs - 1] + 1);
+ if (numAvail > m_MatchMaxLen)
+ numAvail = m_MatchMaxLen;
+ for (; len < numAvail && pby[len] == pby2[len]; len++);
+ m_MatchDistances[i - 1] = (UInt16)len;
+ }
+ }
+ if (m_IsMultiPass)
+ m_Pos += numPairs + 1;
+ if (!m_SecondPass)
+ m_AdditionalOffset++;
+}
+
+void CCoder::MovePos(UInt32 num)
+{
+ if (!m_SecondPass && num > 0)
+ {
+ if (_btMode)
+ Bt3Zip_MatchFinder_Skip(&_lzInWindow, num);
+ else
+ Hc3Zip_MatchFinder_Skip(&_lzInWindow, num);
+ m_AdditionalOffset += num;
+ }
+}
+
+static const UInt32 kIfinityPrice = 0xFFFFFFF;
+
+NO_INLINE UInt32 CCoder::Backward(UInt32 &backRes, UInt32 cur)
+{
+ m_OptimumEndIndex = cur;
+ UInt32 posMem = m_Optimum[cur].PosPrev;
+ UInt16 backMem = m_Optimum[cur].BackPrev;
+ do
+ {
+ UInt32 posPrev = posMem;
+ UInt16 backCur = backMem;
+ backMem = m_Optimum[posPrev].BackPrev;
+ posMem = m_Optimum[posPrev].PosPrev;
+ m_Optimum[posPrev].BackPrev = backCur;
+ m_Optimum[posPrev].PosPrev = (UInt16)cur;
+ cur = posPrev;
+ }
+ while(cur > 0);
+ backRes = m_Optimum[0].BackPrev;
+ m_OptimumCurrentIndex = m_Optimum[0].PosPrev;
+ return m_OptimumCurrentIndex;
+}
+
+NO_INLINE UInt32 CCoder::GetOptimal(UInt32 &backRes)
+{
+ if(m_OptimumEndIndex != m_OptimumCurrentIndex)
+ {
+ UInt32 len = m_Optimum[m_OptimumCurrentIndex].PosPrev - m_OptimumCurrentIndex;
+ backRes = m_Optimum[m_OptimumCurrentIndex].BackPrev;
+ m_OptimumCurrentIndex = m_Optimum[m_OptimumCurrentIndex].PosPrev;
+ return len;
+ }
+ m_OptimumCurrentIndex = m_OptimumEndIndex = 0;
+
+ GetMatches();
+
+ UInt32 numDistancePairs = m_MatchDistances[0];
+ if(numDistancePairs == 0)
+ return 1;
+
+ const UInt16 *matchDistances = m_MatchDistances + 1;
+ UInt32 lenMain = matchDistances[numDistancePairs - 2];
+
+ if(lenMain > m_NumFastBytes)
+ {
+ backRes = matchDistances[numDistancePairs - 1];
+ MovePos(lenMain - 1);
+ return lenMain;
+ }
+ m_Optimum[1].Price = m_LiteralPrices[Inline_MatchFinder_GetIndexByte(&_lzInWindow, 0 - m_AdditionalOffset)];
+ m_Optimum[1].PosPrev = 0;
+
+ m_Optimum[2].Price = kIfinityPrice;
+ m_Optimum[2].PosPrev = 1;
+
+
+ UInt32 offs = 0;
+ for(UInt32 i = kMatchMinLen; i <= lenMain; i++)
+ {
+ UInt32 distance = matchDistances[offs + 1];
+ m_Optimum[i].PosPrev = 0;
+ m_Optimum[i].BackPrev = (UInt16)distance;
+ m_Optimum[i].Price = m_LenPrices[i - kMatchMinLen] + m_PosPrices[GetPosSlot(distance)];
+ if (i == matchDistances[offs])
+ offs += 2;
+ }
+
+ UInt32 cur = 0;
+ UInt32 lenEnd = lenMain;
+ for (;;)
+ {
+ ++cur;
+ if(cur == lenEnd || cur == kNumOptsBase || m_Pos >= kMatchArrayLimit)
+ return Backward(backRes, cur);
+ GetMatches();
+ matchDistances = m_MatchDistances + 1;
+
+ UInt32 numDistancePairs = m_MatchDistances[0];
+ UInt32 newLen = 0;
+ if(numDistancePairs != 0)
+ {
+ newLen = matchDistances[numDistancePairs - 2];
+ if(newLen > m_NumFastBytes)
+ {
+ UInt32 len = Backward(backRes, cur);
+ m_Optimum[cur].BackPrev = matchDistances[numDistancePairs - 1];
+ m_OptimumEndIndex = cur + newLen;
+ m_Optimum[cur].PosPrev = (UInt16)m_OptimumEndIndex;
+ MovePos(newLen - 1);
+ return len;
+ }
+ }
+ UInt32 curPrice = m_Optimum[cur].Price;
+ UInt32 curAnd1Price = curPrice + m_LiteralPrices[Inline_MatchFinder_GetIndexByte(&_lzInWindow, cur - m_AdditionalOffset)];
+ COptimal &optimum = m_Optimum[cur + 1];
+ if (curAnd1Price < optimum.Price)
+ {
+ optimum.Price = curAnd1Price;
+ optimum.PosPrev = (UInt16)cur;
+ }
+ if(numDistancePairs == 0)
+ continue;
+ while(lenEnd < cur + newLen)
+ m_Optimum[++lenEnd].Price = kIfinityPrice;
+ offs = 0;
+ UInt32 distance = matchDistances[offs + 1];
+ curPrice += m_PosPrices[GetPosSlot(distance)];
+ for(UInt32 lenTest = kMatchMinLen; ; lenTest++)
+ {
+ UInt32 curAndLenPrice = curPrice + m_LenPrices[lenTest - kMatchMinLen];
+ COptimal &optimum = m_Optimum[cur + lenTest];
+ if (curAndLenPrice < optimum.Price)
+ {
+ optimum.Price = curAndLenPrice;
+ optimum.PosPrev = (UInt16)cur;
+ optimum.BackPrev = (UInt16)distance;
+ }
+ if (lenTest == matchDistances[offs])
+ {
+ offs += 2;
+ if (offs == numDistancePairs)
+ break;
+ curPrice -= m_PosPrices[GetPosSlot(distance)];
+ distance = matchDistances[offs + 1];
+ curPrice += m_PosPrices[GetPosSlot(distance)];
+ }
+ }
+ }
+}
+
+UInt32 CCoder::GetOptimalFast(UInt32 &backRes)
+{
+ GetMatches();
+ UInt32 numDistancePairs = m_MatchDistances[0];
+ if (numDistancePairs == 0)
+ return 1;
+ UInt32 lenMain = m_MatchDistances[numDistancePairs - 1];
+ backRes = m_MatchDistances[numDistancePairs];
+ MovePos(lenMain - 1);
+ return lenMain;
+}
+
+void CTables::InitStructures()
+{
+ UInt32 i;
+ for(i = 0; i < 256; i++)
+ litLenLevels[i] = 8;
+ litLenLevels[i++] = 13;
+ for(;i < kFixedMainTableSize; i++)
+ litLenLevels[i] = 5;
+ for(i = 0; i < kFixedDistTableSize; i++)
+ distLevels[i] = 5;
+}
+
+NO_INLINE void CCoder::LevelTableDummy(const Byte *levels, int numLevels, UInt32 *freqs)
+{
+ int prevLen = 0xFF;
+ int nextLen = levels[0];
+ int count = 0;
+ int maxCount = 7;
+ int minCount = 4;
+ if (nextLen == 0)
+ {
+ maxCount = 138;
+ minCount = 3;
+ }
+ for (int n = 0; n < numLevels; n++)
+ {
+ int curLen = nextLen;
+ nextLen = (n < numLevels - 1) ? levels[n + 1] : 0xFF;
+ count++;
+ if (count < maxCount && curLen == nextLen)
+ continue;
+
+ if (count < minCount)
+ freqs[curLen] += (UInt32)count;
+ else if (curLen != 0)
+ {
+ if (curLen != prevLen)
+ {
+ freqs[curLen]++;
+ count--;
+ }
+ freqs[kTableLevelRepNumber]++;
+ }
+ else if (count <= 10)
+ freqs[kTableLevel0Number]++;
+ else
+ freqs[kTableLevel0Number2]++;
+
+ count = 0;
+ prevLen = curLen;
+
+ if (nextLen == 0)
+ {
+ maxCount = 138;
+ minCount = 3;
+ }
+ else if (curLen == nextLen)
+ {
+ maxCount = 6;
+ minCount = 3;
+ }
+ else
+ {
+ maxCount = 7;
+ minCount = 4;
+ }
+ }
+}
+
+NO_INLINE void CCoder::WriteBits(UInt32 value, int numBits)
+{
+ m_OutStream.WriteBits(value, numBits);
+}
+
+#define WRITE_HF2(codes, lens, i) m_OutStream.WriteBits(codes[i], lens[i])
+#define WRITE_HF(i) WriteBits(codes[i], lens[i])
+
+NO_INLINE void CCoder::LevelTableCode(const Byte *levels, int numLevels, const Byte *lens, const UInt32 *codes)
+{
+ int prevLen = 0xFF;
+ int nextLen = levels[0];
+ int count = 0;
+ int maxCount = 7;
+ int minCount = 4;
+ if (nextLen == 0)
+ {
+ maxCount = 138;
+ minCount = 3;
+ }
+ for (int n = 0; n < numLevels; n++)
+ {
+ int curLen = nextLen;
+ nextLen = (n < numLevels - 1) ? levels[n + 1] : 0xFF;
+ count++;
+ if (count < maxCount && curLen == nextLen)
+ continue;
+
+ if (count < minCount)
+ for(int i = 0; i < count; i++)
+ WRITE_HF(curLen);
+ else if (curLen != 0)
+ {
+ if (curLen != prevLen)
+ {
+ WRITE_HF(curLen);
+ count--;
+ }
+ WRITE_HF(kTableLevelRepNumber);
+ WriteBits(count - 3, 2);
+ }
+ else if (count <= 10)
+ {
+ WRITE_HF(kTableLevel0Number);
+ WriteBits(count - 3, 3);
+ }
+ else
+ {
+ WRITE_HF(kTableLevel0Number2);
+ WriteBits(count - 11, 7);
+ }
+
+ count = 0;
+ prevLen = curLen;
+
+ if (nextLen == 0)
+ {
+ maxCount = 138;
+ minCount = 3;
+ }
+ else if (curLen == nextLen)
+ {
+ maxCount = 6;
+ minCount = 3;
+ }
+ else
+ {
+ maxCount = 7;
+ minCount = 4;
+ }
+ }
+}
+
+NO_INLINE void CCoder::MakeTables(unsigned maxHuffLen)
+{
+ Huffman_Generate(mainFreqs, mainCodes, m_NewLevels.litLenLevels, kFixedMainTableSize, maxHuffLen);
+ Huffman_Generate(distFreqs, distCodes, m_NewLevels.distLevels, kDistTableSize64, maxHuffLen);
+}
+
+NO_INLINE UInt32 Huffman_GetPrice(const UInt32 *freqs, const Byte *lens, UInt32 num)
+{
+ UInt32 price = 0;
+ UInt32 i;
+ for (i = 0; i < num; i++)
+ price += lens[i] * freqs[i];
+ return price;
+}
+
+NO_INLINE UInt32 Huffman_GetPrice_Spec(const UInt32 *freqs, const Byte *lens, UInt32 num, const Byte *extraBits, UInt32 extraBase)
+{
+ return Huffman_GetPrice(freqs, lens, num) +
+ Huffman_GetPrice(freqs + extraBase, extraBits, num - extraBase);
+}
+
+NO_INLINE UInt32 CCoder::GetLzBlockPrice() const
+{
+ return
+ Huffman_GetPrice_Spec(mainFreqs, m_NewLevels.litLenLevels, kFixedMainTableSize, m_LenDirectBits, kSymbolMatch) +
+ Huffman_GetPrice_Spec(distFreqs, m_NewLevels.distLevels, kDistTableSize64, kDistDirectBits, 0);
+}
+
+NO_INLINE void CCoder::TryBlock()
+{
+ memset(mainFreqs, 0, sizeof(mainFreqs));
+ memset(distFreqs, 0, sizeof(distFreqs));
+
+ m_ValueIndex = 0;
+ UInt32 blockSize = BlockSizeRes;
+ BlockSizeRes = 0;
+ for (;;)
+ {
+ if (m_OptimumCurrentIndex == m_OptimumEndIndex)
+ {
+ if (m_Pos >= kMatchArrayLimit || BlockSizeRes >= blockSize || !m_SecondPass &&
+ ((Inline_MatchFinder_GetNumAvailableBytes(&_lzInWindow) == 0) || m_ValueIndex >= m_ValueBlockSize))
+ break;
+ }
+ UInt32 pos;
+ UInt32 len;
+ if (_fastMode)
+ len = GetOptimalFast(pos);
+ else
+ len = GetOptimal(pos);
+ CCodeValue &codeValue = m_Values[m_ValueIndex++];
+ if (len >= kMatchMinLen)
+ {
+ UInt32 newLen = len - kMatchMinLen;
+ codeValue.Len = (UInt16)newLen;
+ mainFreqs[kSymbolMatch + g_LenSlots[newLen]]++;
+ codeValue.Pos = (UInt16)pos;
+ distFreqs[GetPosSlot(pos)]++;
+ }
+ else
+ {
+ Byte b = Inline_MatchFinder_GetIndexByte(&_lzInWindow, 0 - m_AdditionalOffset);
+ mainFreqs[b]++;
+ codeValue.SetAsLiteral();
+ codeValue.Pos = b;
+ }
+ m_AdditionalOffset -= len;
+ BlockSizeRes += len;
+ }
+ mainFreqs[kSymbolEndOfBlock]++;
+ m_AdditionalOffset += BlockSizeRes;
+ m_SecondPass = true;
+}
+
+NO_INLINE void CCoder::SetPrices(const CLevels &levels)
+{
+ if (_fastMode)
+ return;
+ UInt32 i;
+ for(i = 0; i < 256; i++)
+ {
+ Byte price = levels.litLenLevels[i];
+ m_LiteralPrices[i] = ((price != 0) ? price : kNoLiteralStatPrice);
+ }
+
+ for(i = 0; i < m_NumLenCombinations; i++)
+ {
+ UInt32 slot = g_LenSlots[i];
+ Byte price = levels.litLenLevels[kSymbolMatch + slot];
+ m_LenPrices[i] = (Byte)(((price != 0) ? price : kNoLenStatPrice) + m_LenDirectBits[slot]);
+ }
+
+ for(i = 0; i < kDistTableSize64; i++)
+ {
+ Byte price = levels.distLevels[i];
+ m_PosPrices[i] = (Byte)(((price != 0) ? price: kNoPosStatPrice) + kDistDirectBits[i]);
+ }
+}
+
+NO_INLINE void Huffman_ReverseBits(UInt32 *codes, const Byte *lens, UInt32 num)
+{
+ for (UInt32 i = 0; i < num; i++)
+ {
+ UInt32 x = codes[i];
+ x = ((x & 0x5555) << 1) | ((x & 0xAAAA) >> 1);
+ x = ((x & 0x3333) << 2) | ((x & 0xCCCC) >> 2);
+ x = ((x & 0x0F0F) << 4) | ((x & 0xF0F0) >> 4);
+ codes[i] = (((x & 0x00FF) << 8) | ((x & 0xFF00) >> 8)) >> (16 - lens[i]);
+ }
+}
+
+NO_INLINE void CCoder::WriteBlock()
+{
+ Huffman_ReverseBits(mainCodes, m_NewLevels.litLenLevels, kFixedMainTableSize);
+ Huffman_ReverseBits(distCodes, m_NewLevels.distLevels, kDistTableSize64);
+
+ for (UInt32 i = 0; i < m_ValueIndex; i++)
+ {
+ const CCodeValue &codeValue = m_Values[i];
+ if (codeValue.IsLiteral())
+ WRITE_HF2(mainCodes, m_NewLevels.litLenLevels, codeValue.Pos);
+ else
+ {
+ UInt32 len = codeValue.Len;
+ UInt32 lenSlot = g_LenSlots[len];
+ WRITE_HF2(mainCodes, m_NewLevels.litLenLevels, kSymbolMatch + lenSlot);
+ m_OutStream.WriteBits(len - m_LenStart[lenSlot], m_LenDirectBits[lenSlot]);
+ UInt32 dist = codeValue.Pos;
+ UInt32 posSlot = GetPosSlot(dist);
+ WRITE_HF2(distCodes, m_NewLevels.distLevels, posSlot);
+ m_OutStream.WriteBits(dist - kDistStart[posSlot], kDistDirectBits[posSlot]);
+ }
+ }
+ WRITE_HF2(mainCodes, m_NewLevels.litLenLevels, kSymbolEndOfBlock);
+}
+
+static UInt32 GetStorePrice(UInt32 blockSize, int bitPosition)
+{
+ UInt32 price = 0;
+ do
+ {
+ UInt32 nextBitPosition = (bitPosition + kFinalBlockFieldSize + kBlockTypeFieldSize) & 7;
+ int numBitsForAlign = nextBitPosition > 0 ? (8 - nextBitPosition): 0;
+ UInt32 curBlockSize = (blockSize < (1 << 16)) ? blockSize : (1 << 16) - 1;
+ price += kFinalBlockFieldSize + kBlockTypeFieldSize + numBitsForAlign + (2 + 2) * 8 + curBlockSize * 8;
+ bitPosition = 0;
+ blockSize -= curBlockSize;
+ }
+ while(blockSize != 0);
+ return price;
+}
+
+void CCoder::WriteStoreBlock(UInt32 blockSize, UInt32 additionalOffset, bool finalBlock)
+{
+ do
+ {
+ UInt32 curBlockSize = (blockSize < (1 << 16)) ? blockSize : (1 << 16) - 1;
+ blockSize -= curBlockSize;
+ WriteBits((finalBlock && (blockSize == 0) ? NFinalBlockField::kFinalBlock: NFinalBlockField::kNotFinalBlock), kFinalBlockFieldSize);
+ WriteBits(NBlockType::kStored, kBlockTypeFieldSize);
+ m_OutStream.FlushByte();
+ WriteBits((UInt16)curBlockSize, kStoredBlockLengthFieldSize);
+ WriteBits((UInt16)~curBlockSize, kStoredBlockLengthFieldSize);
+ const Byte *data = Inline_MatchFinder_GetPointerToCurrentPos(&_lzInWindow)- additionalOffset;
+ for(UInt32 i = 0; i < curBlockSize; i++)
+ m_OutStream.WriteByte(data[i]);
+ additionalOffset -= curBlockSize;
+ }
+ while(blockSize != 0);
+}
+
+NO_INLINE UInt32 CCoder::TryDynBlock(int tableIndex, UInt32 numPasses)
+{
+ CTables &t = m_Tables[tableIndex];
+ BlockSizeRes = t.BlockSizeRes;
+ UInt32 posTemp = t.m_Pos;
+ SetPrices(t);
+
+ for (UInt32 p = 0; p < numPasses; p++)
+ {
+ m_Pos = posTemp;
+ TryBlock();
+ unsigned numHuffBits =
+ (m_ValueIndex > 18000 ? 12 :
+ (m_ValueIndex > 7000 ? 11 :
+ (m_ValueIndex > 2000 ? 10 : 9)));
+ MakeTables(numHuffBits);
+ SetPrices(m_NewLevels);
+ }
+
+ (CLevels &)t = m_NewLevels;
+
+ m_NumLitLenLevels = kMainTableSize;
+ while(m_NumLitLenLevels > kNumLitLenCodesMin && m_NewLevels.litLenLevels[m_NumLitLenLevels - 1] == 0)
+ m_NumLitLenLevels--;
+
+ m_NumDistLevels = kDistTableSize64;
+ while(m_NumDistLevels > kNumDistCodesMin && m_NewLevels.distLevels[m_NumDistLevels - 1] == 0)
+ m_NumDistLevels--;
+
+ UInt32 levelFreqs[kLevelTableSize];
+ memset(levelFreqs, 0, sizeof(levelFreqs));
+
+ LevelTableDummy(m_NewLevels.litLenLevels, m_NumLitLenLevels, levelFreqs);
+ LevelTableDummy(m_NewLevels.distLevels, m_NumDistLevels, levelFreqs);
+
+ Huffman_Generate(levelFreqs, levelCodes, levelLens, kLevelTableSize, kMaxLevelBitLength);
+
+ m_NumLevelCodes = kNumLevelCodesMin;
+ for (UInt32 i = 0; i < kLevelTableSize; i++)
+ {
+ Byte level = levelLens[kCodeLengthAlphabetOrder[i]];
+ if (level > 0 && i >= m_NumLevelCodes)
+ m_NumLevelCodes = i + 1;
+ m_LevelLevels[i] = level;
+ }
+
+ return GetLzBlockPrice() +
+ Huffman_GetPrice_Spec(levelFreqs, levelLens, kLevelTableSize, kLevelDirectBits, kTableDirectLevels) +
+ kNumLenCodesFieldSize + kNumDistCodesFieldSize + kNumLevelCodesFieldSize +
+ m_NumLevelCodes * kLevelFieldSize + kFinalBlockFieldSize + kBlockTypeFieldSize;
+}
+
+NO_INLINE UInt32 CCoder::TryFixedBlock(int tableIndex)
+{
+ CTables &t = m_Tables[tableIndex];
+ BlockSizeRes = t.BlockSizeRes;
+ m_Pos = t.m_Pos;
+ m_NewLevels.SetFixedLevels();
+ SetPrices(m_NewLevels);
+ TryBlock();
+ return kFinalBlockFieldSize + kBlockTypeFieldSize + GetLzBlockPrice();
+}
+
+NO_INLINE UInt32 CCoder::GetBlockPrice(int tableIndex, int numDivPasses)
+{
+ CTables &t = m_Tables[tableIndex];
+ t.StaticMode = false;
+ UInt32 price = TryDynBlock(tableIndex, m_NumPasses);
+ t.BlockSizeRes = BlockSizeRes;
+ UInt32 numValues = m_ValueIndex;
+ UInt32 posTemp = m_Pos;
+ UInt32 additionalOffsetEnd = m_AdditionalOffset;
+
+ if (m_CheckStatic && m_ValueIndex <= kFixedHuffmanCodeBlockSizeMax)
+ {
+ const UInt32 fixedPrice = TryFixedBlock(tableIndex);
+ t.StaticMode = (fixedPrice < price);
+ if (t.StaticMode)
+ price = fixedPrice;
+ }
+
+ const UInt32 storePrice = GetStorePrice(BlockSizeRes, 0); // bitPosition
+ t.StoreMode = (storePrice <= price);
+ if (t.StoreMode)
+ price = storePrice;
+
+ t.UseSubBlocks = false;
+
+ if (numDivPasses > 1 && numValues >= kDivideCodeBlockSizeMin)
+ {
+ CTables &t0 = m_Tables[(tableIndex << 1)];
+ (CLevels &)t0 = t;
+ t0.BlockSizeRes = t.BlockSizeRes >> 1;
+ t0.m_Pos = t.m_Pos;
+ UInt32 subPrice = GetBlockPrice((tableIndex << 1), numDivPasses - 1);
+
+ UInt32 blockSize2 = t.BlockSizeRes - t0.BlockSizeRes;
+ if (t0.BlockSizeRes >= kDivideBlockSizeMin && blockSize2 >= kDivideBlockSizeMin)
+ {
+ CTables &t1 = m_Tables[(tableIndex << 1) + 1];
+ (CLevels &)t1 = t;
+ t1.BlockSizeRes = blockSize2;
+ t1.m_Pos = m_Pos;
+ m_AdditionalOffset -= t0.BlockSizeRes;
+ subPrice += GetBlockPrice((tableIndex << 1) + 1, numDivPasses - 1);
+ t.UseSubBlocks = (subPrice < price);
+ if (t.UseSubBlocks)
+ price = subPrice;
+ }
+ }
+ m_AdditionalOffset = additionalOffsetEnd;
+ m_Pos = posTemp;
+ return price;
+}
+
+void CCoder::CodeBlock(int tableIndex, bool finalBlock)
+{
+ CTables &t = m_Tables[tableIndex];
+ if (t.UseSubBlocks)
+ {
+ CodeBlock((tableIndex << 1), false);
+ CodeBlock((tableIndex << 1) + 1, finalBlock);
+ }
+ else
+ {
+ if (t.StoreMode)
+ WriteStoreBlock(t.BlockSizeRes, m_AdditionalOffset, finalBlock);
+ else
+ {
+ WriteBits((finalBlock ? NFinalBlockField::kFinalBlock: NFinalBlockField::kNotFinalBlock), kFinalBlockFieldSize);
+ if (t.StaticMode)
+ {
+ WriteBits(NBlockType::kFixedHuffman, kBlockTypeFieldSize);
+ TryFixedBlock(tableIndex);
+ int i;
+ const int kMaxStaticHuffLen = 9;
+ for (i = 0; i < kFixedMainTableSize; i++)
+ mainFreqs[i] = (UInt32)1 << (kMaxStaticHuffLen - m_NewLevels.litLenLevels[i]);
+ for (i = 0; i < kFixedDistTableSize; i++)
+ distFreqs[i] = (UInt32)1 << (kMaxStaticHuffLen - m_NewLevels.distLevels[i]);
+ MakeTables(kMaxStaticHuffLen);
+ }
+ else
+ {
+ if (m_NumDivPasses > 1 || m_CheckStatic)
+ TryDynBlock(tableIndex, 1);
+ WriteBits(NBlockType::kDynamicHuffman, kBlockTypeFieldSize);
+ WriteBits(m_NumLitLenLevels - kNumLitLenCodesMin, kNumLenCodesFieldSize);
+ WriteBits(m_NumDistLevels - kNumDistCodesMin, kNumDistCodesFieldSize);
+ WriteBits(m_NumLevelCodes - kNumLevelCodesMin, kNumLevelCodesFieldSize);
+
+ for (UInt32 i = 0; i < m_NumLevelCodes; i++)
+ WriteBits(m_LevelLevels[i], kLevelFieldSize);
+
+ Huffman_ReverseBits(levelCodes, levelLens, kLevelTableSize);
+ LevelTableCode(m_NewLevels.litLenLevels, m_NumLitLenLevels, levelLens, levelCodes);
+ LevelTableCode(m_NewLevels.distLevels, m_NumDistLevels, levelLens, levelCodes);
+ }
+ WriteBlock();
+ }
+ m_AdditionalOffset -= t.BlockSizeRes;
+ }
+}
+
+SRes Read(void *object, void *data, size_t *size)
+{
+ const UInt32 kStepSize = (UInt32)1 << 31;
+ UInt32 curSize = ((*size < kStepSize) ? (UInt32)*size : kStepSize);
+ HRESULT res = ((CSeqInStream *)object)->RealStream->Read(data, curSize, &curSize);
+ *size = curSize;
+ return (SRes)res;
+}
+
+HRESULT CCoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 * /* inSize */ , const UInt64 * /* outSize */ , ICompressProgressInfo *progress)
+{
+ m_CheckStatic = (m_NumPasses != 1 || m_NumDivPasses != 1);
+ m_IsMultiPass = (m_CheckStatic || (m_NumPasses != 1 || m_NumDivPasses != 1));
+
+ RINOK(Create());
+
+ m_ValueBlockSize = (7 << 10) + (1 << 12) * m_NumDivPasses;
+
+ UInt64 nowPos = 0;
+
+ _seqInStream.RealStream = inStream;
+ _seqInStream.SeqInStream.Read = Read;
+ _lzInWindow.stream = &_seqInStream.SeqInStream;
+
+ MatchFinder_Init(&_lzInWindow);
+ m_OutStream.SetStream(outStream);
+ m_OutStream.Init();
+
+ CCoderReleaser coderReleaser(this);
+
+ m_OptimumEndIndex = m_OptimumCurrentIndex = 0;
+
+ CTables &t = m_Tables[1];
+ t.m_Pos = 0;
+ t.InitStructures();
+
+ m_AdditionalOffset = 0;
+ do
+ {
+ t.BlockSizeRes = kBlockUncompressedSizeThreshold;
+ m_SecondPass = false;
+ GetBlockPrice(1, m_NumDivPasses);
+ CodeBlock(1, Inline_MatchFinder_GetNumAvailableBytes(&_lzInWindow) == 0);
+ nowPos += m_Tables[1].BlockSizeRes;
+ if (progress != NULL)
+ {
+ UInt64 packSize = m_OutStream.GetProcessedSize();
+ RINOK(progress->SetRatioInfo(&nowPos, &packSize));
+ }
+ }
+ while (Inline_MatchFinder_GetNumAvailableBytes(&_lzInWindow) != 0);
+ if (_lzInWindow.result != SZ_OK)
+ return _lzInWindow.result;
+ return m_OutStream.Flush();
+}
+
+HRESULT CCoder::BaseCode(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
+{
+ try { return CodeReal(inStream, outStream, inSize, outSize, progress); }
+ catch(const COutBufferException &e) { return e.ErrorCode; }
+ catch(...) { return E_FAIL; }
+}
+
+STDMETHODIMP CCOMCoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
+ { return BaseCode(inStream, outStream, inSize, outSize, progress); }
+
+STDMETHODIMP CCOMCoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps)
+ { return BaseSetEncoderProperties2(propIDs, props, numProps); }
+
+STDMETHODIMP CCOMCoder64::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
+ { return BaseCode(inStream, outStream, inSize, outSize, progress); }
+
+STDMETHODIMP CCOMCoder64::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps)
+ { return BaseSetEncoderProperties2(propIDs, props, numProps); }
+
+}}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateEncoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateEncoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateEncoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateEncoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,211 @@
+// DeflateEncoder.h
+
+#ifndef __DEFLATE_ENCODER_H
+#define __DEFLATE_ENCODER_H
+
+#include "../../../C/LzFind.h"
+
+#include "Common/MyCom.h"
+
+#include "../ICoder.h"
+
+#include "BitlEncoder.h"
+#include "DeflateConst.h"
+
+namespace NCompress {
+namespace NDeflate {
+namespace NEncoder {
+
+struct CCodeValue
+{
+ UInt16 Len;
+ UInt16 Pos;
+ void SetAsLiteral() { Len = (1 << 15); }
+ bool IsLiteral() const { return (Len >= (1 << 15)); }
+};
+
+struct COptimal
+{
+ UInt32 Price;
+ UInt16 PosPrev;
+ UInt16 BackPrev;
+};
+
+const UInt32 kNumOptsBase = 1 << 12;
+const UInt32 kNumOpts = kNumOptsBase + kMatchMaxLen;
+
+class CCoder;
+
+struct CTables: public CLevels
+{
+ bool UseSubBlocks;
+ bool StoreMode;
+ bool StaticMode;
+ UInt32 BlockSizeRes;
+ UInt32 m_Pos;
+ void InitStructures();
+};
+
+typedef struct _CSeqInStream
+{
+ ISeqInStream SeqInStream;
+ CMyComPtr<ISequentialInStream> RealStream;
+} CSeqInStream;
+
+class CCoder
+{
+ CMatchFinder _lzInWindow;
+ CBitlEncoder m_OutStream;
+
+ CSeqInStream _seqInStream;
+
+public:
+ CCodeValue *m_Values;
+
+ UInt16 *m_MatchDistances;
+ UInt32 m_NumFastBytes;
+ bool _fastMode;
+ bool _btMode;
+
+ UInt16 *m_OnePosMatchesMemory;
+ UInt16 *m_DistanceMemory;
+
+ UInt32 m_Pos;
+
+ int m_NumPasses;
+ int m_NumDivPasses;
+ bool m_CheckStatic;
+ bool m_IsMultiPass;
+ UInt32 m_ValueBlockSize;
+
+ UInt32 m_NumLenCombinations;
+ UInt32 m_MatchMaxLen;
+ const Byte *m_LenStart;
+ const Byte *m_LenDirectBits;
+
+ bool m_Created;
+ bool m_Deflate64Mode;
+
+ Byte m_LevelLevels[kLevelTableSize];
+ int m_NumLitLenLevels;
+ int m_NumDistLevels;
+ UInt32 m_NumLevelCodes;
+ UInt32 m_ValueIndex;
+
+ bool m_SecondPass;
+ UInt32 m_AdditionalOffset;
+
+ UInt32 m_OptimumEndIndex;
+ UInt32 m_OptimumCurrentIndex;
+
+ Byte m_LiteralPrices[256];
+ Byte m_LenPrices[kNumLenSymbolsMax];
+ Byte m_PosPrices[kDistTableSize64];
+
+ CLevels m_NewLevels;
+ UInt32 mainFreqs[kFixedMainTableSize];
+ UInt32 distFreqs[kDistTableSize64];
+ UInt32 mainCodes[kFixedMainTableSize];
+ UInt32 distCodes[kDistTableSize64];
+ UInt32 levelCodes[kLevelTableSize];
+ Byte levelLens[kLevelTableSize];
+
+ UInt32 BlockSizeRes;
+
+ CTables *m_Tables;
+ COptimal m_Optimum[kNumOpts];
+
+ UInt32 m_MatchFinderCycles;
+ // IMatchFinderSetNumPasses *m_SetMfPasses;
+
+ void GetMatches();
+ void MovePos(UInt32 num);
+ UInt32 Backward(UInt32 &backRes, UInt32 cur);
+ UInt32 GetOptimal(UInt32 &backRes);
+ UInt32 GetOptimalFast(UInt32 &backRes);
+
+ void LevelTableDummy(const Byte *levels, int numLevels, UInt32 *freqs);
+
+ void WriteBits(UInt32 value, int numBits);
+ void LevelTableCode(const Byte *levels, int numLevels, const Byte *lens, const UInt32 *codes);
+
+ void MakeTables(unsigned maxHuffLen);
+ UInt32 GetLzBlockPrice() const;
+ void TryBlock();
+ UInt32 TryDynBlock(int tableIndex, UInt32 numPasses);
+
+ UInt32 TryFixedBlock(int tableIndex);
+
+ void SetPrices(const CLevels &levels);
+ void WriteBlock();
+
+ HRESULT Create();
+ void Free();
+
+ void WriteStoreBlock(UInt32 blockSize, UInt32 additionalOffset, bool finalBlock);
+ void WriteTables(bool writeMode, bool finalBlock);
+
+ void WriteBlockData(bool writeMode, bool finalBlock);
+
+ void ReleaseStreams()
+ {
+ _seqInStream.RealStream.Release();
+ m_OutStream.ReleaseStream();
+ }
+ class CCoderReleaser
+ {
+ CCoder *m_Coder;
+ public:
+ CCoderReleaser(CCoder *coder): m_Coder(coder) {}
+ ~CCoderReleaser() { m_Coder->ReleaseStreams(); }
+ };
+ friend class CCoderReleaser;
+
+ UInt32 GetBlockPrice(int tableIndex, int numDivPasses);
+ void CodeBlock(int tableIndex, bool finalBlock);
+
+public:
+ CCoder(bool deflate64Mode = false);
+ ~CCoder();
+
+ HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ HRESULT BaseCode(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ HRESULT BaseSetEncoderProperties2(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);
+};
+
+
+class CCOMCoder :
+ public ICompressCoder,
+ public ICompressSetCoderProperties,
+ public CMyUnknownImp,
+ public CCoder
+{
+public:
+ MY_UNKNOWN_IMP1(ICompressSetCoderProperties)
+ CCOMCoder(): CCoder(false) {};
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+ STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);
+};
+
+class CCOMCoder64 :
+ public ICompressCoder,
+ public ICompressSetCoderProperties,
+ public CMyUnknownImp,
+ public CCoder
+{
+public:
+ MY_UNKNOWN_IMP1(ICompressSetCoderProperties)
+ CCOMCoder64(): CCoder(true) {};
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+ STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);
+};
+
+}}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateRegister.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateRegister.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeflateRegister.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,21 @@
+// DeflateRegister.cpp
+
+#include "StdAfx.h"
+
+#include "../Common/RegisterCodec.h"
+
+#include "DeflateDecoder.h"
+
+static void *CreateCodecDeflate() { return (void *)(ICompressCoder *)(new NCompress::NDeflate::NDecoder::CCOMCoder); }
+
+#if !defined(EXTRACT_ONLY) && !defined(DEFLATE_EXTRACT_ONLY)
+#include "DeflateEncoder.h"
+static void *CreateCodecOutDeflate() { return (void *)(ICompressCoder *)(new NCompress::NDeflate::NEncoder::CCOMCoder); }
+#else
+#define CreateCodecOutDeflate 0
+#endif
+
+static CCodecInfo g_CodecInfo =
+ { CreateCodecDeflate, CreateCodecOutDeflate, 0x040108, L"Deflate", 1, false };
+
+REGISTER_CODEC(Deflate)
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeltaFilter.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeltaFilter.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeltaFilter.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DeltaFilter.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,112 @@
+// DeltaFilter.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/Delta.h"
+
+#include "../Common/RegisterCodec.h"
+
+#include "BranchCoder.h"
+
+struct CDelta
+{
+ unsigned _delta;
+ Byte _state[DELTA_STATE_SIZE];
+ CDelta(): _delta(1) {}
+ void DeltaInit() { Delta_Init(_state); }
+};
+
+class CDeltaEncoder:
+ public ICompressFilter,
+ public ICompressSetCoderProperties,
+ public ICompressWriteCoderProperties,
+ CDelta,
+ public CMyUnknownImp
+{
+public:
+ MY_UNKNOWN_IMP2(ICompressSetCoderProperties, ICompressWriteCoderProperties)
+ STDMETHOD(Init)();
+ STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
+ STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);
+ STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
+};
+
+class CDeltaDecoder:
+ public ICompressFilter,
+ public ICompressSetDecoderProperties2,
+ CDelta,
+ public CMyUnknownImp
+{
+public:
+ MY_UNKNOWN_IMP1(ICompressSetDecoderProperties2)
+ STDMETHOD(Init)();
+ STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
+ STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
+};
+
+STDMETHODIMP CDeltaEncoder::Init()
+{
+ DeltaInit();
+ return S_OK;
+}
+
+STDMETHODIMP_(UInt32) CDeltaEncoder::Filter(Byte *data, UInt32 size)
+{
+ Delta_Encode(_state, _delta, data, size);
+ return size;
+}
+
+STDMETHODIMP CDeltaEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps)
+{
+ UInt32 delta = _delta;
+ for (UInt32 i = 0; i < numProps; i++)
+ {
+ const PROPVARIANT &prop = props[i];
+ if (propIDs[i] != NCoderPropID::kDefaultProp || prop.vt != VT_UI4 || prop.ulVal < 1 || prop.ulVal > 256)
+ return E_INVALIDARG;
+ delta = prop.ulVal;
+ }
+ _delta = delta;
+ return S_OK;
+}
+
+STDMETHODIMP CDeltaEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
+{
+ Byte prop = (Byte)(_delta - 1);
+ return outStream->Write(&prop, 1, NULL);
+}
+
+STDMETHODIMP CDeltaDecoder::Init()
+{
+ DeltaInit();
+ return S_OK;
+}
+
+STDMETHODIMP_(UInt32) CDeltaDecoder::Filter(Byte *data, UInt32 size)
+{
+ Delta_Decode(_state, _delta, data, size);
+ return size;
+}
+
+STDMETHODIMP CDeltaDecoder::SetDecoderProperties2(const Byte *props, UInt32 size)
+{
+ if (size != 1)
+ return E_INVALIDARG;
+ _delta = (unsigned)props[0] + 1;
+ return S_OK;
+}
+
+#define CREATE_CODEC(x) \
+ static void *CreateCodec ## x() { return (void *)(ICompressFilter *)(new C ## x ## Decoder); } \
+ static void *CreateCodec ## x ## Out() { return (void *)(ICompressFilter *)(new C ## x ## Encoder); }
+
+CREATE_CODEC(Delta)
+
+#define METHOD_ITEM(x, id, name) { CreateCodec ## x, CreateCodec ## x ## Out, id, name, 1, true }
+
+static CCodecInfo g_CodecsInfo[] =
+{
+ METHOD_ITEM(Delta, 3, L"Delta")
+};
+
+REGISTER_CODECS(Delta)
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DllExports.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DllExports.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DllExports.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DllExports.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,39 @@
+// DllExports.cpp
+
+#include "StdAfx.h"
+
+#include "../../Common/MyInitGuid.h"
+
+#include "../ICoder.h"
+
+#include "../Common/RegisterCodec.h"
+
+static const unsigned int kNumCodecsMax = 32;
+unsigned int g_NumCodecs = 0;
+const CCodecInfo *g_Codecs[kNumCodecsMax];
+void RegisterCodec(const CCodecInfo *codecInfo)
+{
+ if (g_NumCodecs < kNumCodecsMax)
+ g_Codecs[g_NumCodecs++] = codecInfo;
+}
+
+#ifdef _WIN32
+extern "C"
+BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /*lpReserved*/)
+{
+ return TRUE;
+}
+#endif
+
+static const UInt16 kDecodeId = 0x2790;
+
+DEFINE_GUID(CLSID_CCodec,
+0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+
+STDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject);
+
+STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)
+{
+ return CreateCoder(clsid, iid, outObject);
+}
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DllExports2.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DllExports2.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DllExports2.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/DllExports2.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,28 @@
+// DllExports.cpp
+
+#include "StdAfx.h"
+
+#include "../../Common/MyInitGuid.h"
+
+#include "../ICoder.h"
+
+#include "../Common/RegisterCodec.h"
+
+extern "C"
+BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /*lpReserved*/)
+{
+ return TRUE;
+}
+
+static const UInt16 kDecodeId = 0x2790;
+
+DEFINE_GUID(CLSID_CCodec,
+0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
+
+STDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject);
+
+STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)
+{
+ return CreateCoder(clsid, iid, outObject);
+}
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/HuffmanDecoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/HuffmanDecoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/HuffmanDecoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/HuffmanDecoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,89 @@
+// Compress/HuffmanDecoder.h
+
+#ifndef __COMPRESS_HUFFMAN_DECODER_H
+#define __COMPRESS_HUFFMAN_DECODER_H
+
+#include "../../Common/Types.h"
+
+namespace NCompress {
+namespace NHuffman {
+
+const int kNumTableBits = 9;
+
+template <int kNumBitsMax, UInt32 m_NumSymbols>
+class CDecoder
+{
+ UInt32 m_Limits[kNumBitsMax + 1]; // m_Limits[i] = value limit for symbols with length = i
+ UInt32 m_Positions[kNumBitsMax + 1]; // m_Positions[i] = index in m_Symbols[] of first symbol with length = i
+ UInt32 m_Symbols[m_NumSymbols];
+ Byte m_Lengths[1 << kNumTableBits]; // Table oh length for short codes.
+
+public:
+
+ bool SetCodeLengths(const Byte *codeLengths)
+ {
+ int lenCounts[kNumBitsMax + 1];
+ UInt32 tmpPositions[kNumBitsMax + 1];
+ int i;
+ for(i = 1; i <= kNumBitsMax; i++)
+ lenCounts[i] = 0;
+ UInt32 symbol;
+ for (symbol = 0; symbol < m_NumSymbols; symbol++)
+ {
+ int len = codeLengths[symbol];
+ if (len > kNumBitsMax)
+ return false;
+ lenCounts[len]++;
+ m_Symbols[symbol] = 0xFFFFFFFF;
+ }
+ lenCounts[0] = 0;
+ m_Positions[0] = m_Limits[0] = 0;
+ UInt32 startPos = 0;
+ UInt32 index = 0;
+ const UInt32 kMaxValue = (1 << kNumBitsMax);
+ for (i = 1; i <= kNumBitsMax; i++)
+ {
+ startPos += lenCounts[i] << (kNumBitsMax - i);
+ if (startPos > kMaxValue)
+ return false;
+ m_Limits[i] = (i == kNumBitsMax) ? kMaxValue : startPos;
+ m_Positions[i] = m_Positions[i - 1] + lenCounts[i - 1];
+ tmpPositions[i] = m_Positions[i];
+ if(i <= kNumTableBits)
+ {
+ UInt32 limit = (m_Limits[i] >> (kNumBitsMax - kNumTableBits));
+ for (; index < limit; index++)
+ m_Lengths[index] = (Byte)i;
+ }
+ }
+ for (symbol = 0; symbol < m_NumSymbols; symbol++)
+ {
+ int len = codeLengths[symbol];
+ if (len != 0)
+ m_Symbols[tmpPositions[len]++] = symbol;
+ }
+ return true;
+ }
+
+ template <class TBitDecoder>
+ UInt32 DecodeSymbol(TBitDecoder *bitStream)
+ {
+ int numBits;
+ UInt32 value = bitStream->GetValue(kNumBitsMax);
+ if (value < m_Limits[kNumTableBits])
+ numBits = m_Lengths[value >> (kNumBitsMax - kNumTableBits)];
+ else
+ for (numBits = kNumTableBits + 1; value >= m_Limits[numBits]; numBits++);
+ bitStream->MovePos(numBits);
+ UInt32 index = m_Positions[numBits] +
+ ((value - m_Limits[numBits - 1]) >> (kNumBitsMax - numBits));
+ if (index >= m_NumSymbols)
+ // throw CDecoderException(); // test it
+ return 0xFFFFFFFF;
+ return m_Symbols[index];
+ }
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeDecoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeDecoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeDecoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeDecoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,219 @@
+// Implode/Decoder.cpp
+
+#include "StdAfx.h"
+
+#include "ImplodeDecoder.h"
+#include "Common/Defs.h"
+
+namespace NCompress {
+namespace NImplode {
+namespace NDecoder {
+
+class CException
+{
+public:
+ enum ECauseType
+ {
+ kData
+ } m_Cause;
+ CException(ECauseType cause): m_Cause(cause) {}
+};
+
+static const int kNumDistanceLowDirectBitsForBigDict = 7;
+static const int kNumDistanceLowDirectBitsForSmallDict = 6;
+
+static const int kNumBitsInByte = 8;
+
+// static const int kLevelStructuresNumberFieldSize = kNumBitsInByte;
+static const int kLevelStructuresNumberAdditionalValue = 1;
+
+static const int kNumLevelStructureLevelBits = 4;
+static const int kLevelStructureLevelAdditionalValue = 1;
+
+static const int kNumLevelStructureRepNumberBits = 4;
+static const int kLevelStructureRepNumberAdditionalValue = 1;
+
+
+static const int kLiteralTableSize = (1 << kNumBitsInByte);
+static const int kDistanceTableSize = 64;
+static const int kLengthTableSize = 64;
+
+static const UInt32 kHistorySize =
+ (1 << MyMax(kNumDistanceLowDirectBitsForBigDict,
+ kNumDistanceLowDirectBitsForSmallDict)) *
+ kDistanceTableSize; // = 8 KB;
+
+static const int kNumAdditionalLengthBits = 8;
+
+static const UInt32 kMatchMinLenWhenLiteralsOn = 3;
+static const UInt32 kMatchMinLenWhenLiteralsOff = 2;
+
+static const UInt32 kMatchMinLenMax = MyMax(kMatchMinLenWhenLiteralsOn,
+ kMatchMinLenWhenLiteralsOff); // 3
+
+// static const UInt32 kMatchMaxLenMax = kMatchMinLenMax + (kLengthTableSize - 1) + (1 << kNumAdditionalLengthBits) - 1; // or 2
+
+enum
+{
+ kMatchId = 0,
+ kLiteralId = 1
+};
+
+
+CCoder::CCoder():
+ m_LiteralDecoder(kLiteralTableSize),
+ m_LengthDecoder(kLengthTableSize),
+ m_DistanceDecoder(kDistanceTableSize)
+{
+}
+
+void CCoder::ReleaseStreams()
+{
+ m_OutWindowStream.ReleaseStream();
+ m_InBitStream.ReleaseStream();
+}
+
+bool CCoder::ReadLevelItems(NImplode::NHuffman::CDecoder &decoder,
+ Byte *levels, int numLevelItems)
+{
+ int numCodedStructures = m_InBitStream.ReadBits(kNumBitsInByte) +
+ kLevelStructuresNumberAdditionalValue;
+ int currentIndex = 0;
+ for(int i = 0; i < numCodedStructures; i++)
+ {
+ int level = m_InBitStream.ReadBits(kNumLevelStructureLevelBits) +
+ kLevelStructureLevelAdditionalValue;
+ int rep = m_InBitStream.ReadBits(kNumLevelStructureRepNumberBits) +
+ kLevelStructureRepNumberAdditionalValue;
+ if (currentIndex + rep > numLevelItems)
+ throw CException(CException::kData);
+ for(int j = 0; j < rep; j++)
+ levels[currentIndex++] = (Byte)level;
+ }
+ if (currentIndex != numLevelItems)
+ return false;
+ return decoder.SetCodeLengths(levels);
+}
+
+
+bool CCoder::ReadTables(void)
+{
+ if (m_LiteralsOn)
+ {
+ Byte literalLevels[kLiteralTableSize];
+ if (!ReadLevelItems(m_LiteralDecoder, literalLevels, kLiteralTableSize))
+ return false;
+ }
+
+ Byte lengthLevels[kLengthTableSize];
+ if (!ReadLevelItems(m_LengthDecoder, lengthLevels, kLengthTableSize))
+ return false;
+
+ Byte distanceLevels[kDistanceTableSize];
+ return ReadLevelItems(m_DistanceDecoder, distanceLevels, kDistanceTableSize);
+}
+
+class CCoderReleaser
+{
+ CCoder *m_Coder;
+public:
+ CCoderReleaser(CCoder *coder): m_Coder(coder) {}
+ ~CCoderReleaser() { m_Coder->ReleaseStreams(); }
+};
+
+HRESULT CCoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)
+{
+ if (!m_InBitStream.Create(1 << 20))
+ return E_OUTOFMEMORY;
+ if (!m_OutWindowStream.Create(kHistorySize))
+ return E_OUTOFMEMORY;
+ if (outSize == NULL)
+ return E_INVALIDARG;
+ UInt64 pos = 0, unPackSize = *outSize;
+
+ m_OutWindowStream.SetStream(outStream);
+ m_OutWindowStream.Init(false);
+ m_InBitStream.SetStream(inStream);
+ m_InBitStream.Init();
+ CCoderReleaser coderReleaser(this);
+
+ if (!ReadTables())
+ return S_FALSE;
+
+ while(pos < unPackSize)
+ {
+ if (progress != NULL && pos % (1 << 16) == 0)
+ {
+ UInt64 packSize = m_InBitStream.GetProcessedSize();
+ RINOK(progress->SetRatioInfo(&packSize, &pos));
+ }
+ if(m_InBitStream.ReadBits(1) == kMatchId) // match
+ {
+ UInt32 lowDistBits = m_InBitStream.ReadBits(m_NumDistanceLowDirectBits);
+ UInt32 distance = m_DistanceDecoder.DecodeSymbol(&m_InBitStream);
+ if (distance >= kDistanceTableSize)
+ return S_FALSE;
+ distance = (distance << m_NumDistanceLowDirectBits) + lowDistBits;
+ UInt32 lengthSymbol = m_LengthDecoder.DecodeSymbol(&m_InBitStream);
+ if (lengthSymbol >= kLengthTableSize)
+ return S_FALSE;
+ UInt32 length = lengthSymbol + m_MinMatchLength;
+ if (lengthSymbol == kLengthTableSize - 1) // special symbol = 63
+ length += m_InBitStream.ReadBits(kNumAdditionalLengthBits);
+ while(distance >= pos && length > 0)
+ {
+ m_OutWindowStream.PutByte(0);
+ pos++;
+ length--;
+ }
+ if (length > 0)
+ m_OutWindowStream.CopyBlock(distance, length);
+ pos += length;
+ }
+ else
+ {
+ Byte b;
+ if (m_LiteralsOn)
+ {
+ UInt32 temp = m_LiteralDecoder.DecodeSymbol(&m_InBitStream);
+ if (temp >= kLiteralTableSize)
+ return S_FALSE;
+ b = (Byte)temp;
+ }
+ else
+ b = (Byte)m_InBitStream.ReadBits(kNumBitsInByte);
+ m_OutWindowStream.PutByte(b);
+ pos++;
+ }
+ }
+ if (pos > unPackSize)
+ return S_FALSE;
+ return m_OutWindowStream.Flush();
+}
+
+STDMETHODIMP CCoder::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 CCoder::SetDecoderProperties2(const Byte *data, UInt32 size)
+{
+ if (size < 1)
+ return E_INVALIDARG;
+ Byte flag = data[0];
+ m_BigDictionaryOn = ((flag & 2) != 0);
+ m_NumDistanceLowDirectBits = m_BigDictionaryOn ?
+ kNumDistanceLowDirectBitsForBigDict:
+ kNumDistanceLowDirectBitsForSmallDict;
+ m_LiteralsOn = ((flag & 4) != 0);
+ m_MinMatchLength = m_LiteralsOn ?
+ kMatchMinLenWhenLiteralsOn :
+ kMatchMinLenWhenLiteralsOff;
+ return S_OK;
+}
+
+}}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeDecoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeDecoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeDecoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeDecoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,57 @@
+// ImplodeDecoder.h
+
+#ifndef __COMPRESS_IMPLODE_DECODER_H
+#define __COMPRESS_IMPLODE_DECODER_H
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+#include "ImplodeHuffmanDecoder.h"
+#include "LzOutWindow.h"
+
+namespace NCompress {
+namespace NImplode {
+namespace NDecoder {
+
+class CCoder:
+ public ICompressCoder,
+ public ICompressSetDecoderProperties2,
+ public CMyUnknownImp
+{
+ CLzOutWindow m_OutWindowStream;
+ NBitl::CDecoder<CInBuffer> m_InBitStream;
+
+ NImplode::NHuffman::CDecoder m_LiteralDecoder;
+ NImplode::NHuffman::CDecoder m_LengthDecoder;
+ NImplode::NHuffman::CDecoder m_DistanceDecoder;
+
+ bool m_BigDictionaryOn;
+ bool m_LiteralsOn;
+
+ int m_NumDistanceLowDirectBits;
+ UInt32 m_MinMatchLength;
+
+ bool ReadLevelItems(NImplode::NHuffman::CDecoder &table, Byte *levels, int numLevelItems);
+ bool ReadTables();
+ void DeCodeLevelTable(Byte *newLevels, int numLevels);
+public:
+ CCoder();
+
+ MY_UNKNOWN_IMP1(ICompressSetDecoderProperties2)
+
+ void ReleaseStreams();
+ HRESULT Flush() { return m_OutWindowStream.Flush(); }
+
+ HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
+};
+
+}}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,89 @@
+// ImplodeHuffmanDecoder.cpp
+
+#include "StdAfx.h"
+
+#include "ImplodeHuffmanDecoder.h"
+
+namespace NCompress {
+namespace NImplode {
+namespace NHuffman {
+
+CDecoder::CDecoder(UInt32 numSymbols):
+ m_NumSymbols(numSymbols)
+{
+ m_Symbols = new UInt32[m_NumSymbols];
+}
+
+CDecoder::~CDecoder()
+{
+ delete []m_Symbols;
+}
+
+bool CDecoder::SetCodeLengths(const Byte *codeLengths)
+{
+ // int lenCounts[kNumBitsInLongestCode + 1], tmpPositions[kNumBitsInLongestCode + 1];
+ int lenCounts[kNumBitsInLongestCode + 2], tmpPositions[kNumBitsInLongestCode + 1];
+ int i;
+ for(i = 0; i <= kNumBitsInLongestCode; i++)
+ lenCounts[i] = 0;
+ UInt32 symbolIndex;
+ for (symbolIndex = 0; symbolIndex < m_NumSymbols; symbolIndex++)
+ lenCounts[codeLengths[symbolIndex]]++;
+ // lenCounts[0] = 0;
+
+ // tmpPositions[0] = m_Positions[0] = m_Limitits[0] = 0;
+ m_Limitits[kNumBitsInLongestCode + 1] = 0;
+ m_Positions[kNumBitsInLongestCode + 1] = 0;
+ lenCounts[kNumBitsInLongestCode + 1] = 0;
+
+
+ UInt32 startPos = 0;
+ static const UInt32 kMaxValue = (1 << kNumBitsInLongestCode);
+
+ for (i = kNumBitsInLongestCode; i > 0; i--)
+ {
+ startPos += lenCounts[i] << (kNumBitsInLongestCode - i);
+ if (startPos > kMaxValue)
+ return false;
+ m_Limitits[i] = startPos;
+ m_Positions[i] = m_Positions[i + 1] + lenCounts[i + 1];
+ tmpPositions[i] = m_Positions[i] + lenCounts[i];
+
+ }
+
+ // if _ZIP_MODE do not throw exception for trees containing only one node
+ // #ifndef _ZIP_MODE
+ if (startPos != kMaxValue)
+ return false;
+ // #endif
+
+ for (symbolIndex = 0; symbolIndex < m_NumSymbols; symbolIndex++)
+ if (codeLengths[symbolIndex] != 0)
+ m_Symbols[--tmpPositions[codeLengths[symbolIndex]]] = symbolIndex;
+ return true;
+}
+
+UInt32 CDecoder::DecodeSymbol(CInBit *inStream)
+{
+ UInt32 numBits = 0;
+ UInt32 value = inStream->GetValue(kNumBitsInLongestCode);
+ int i;
+ for(i = kNumBitsInLongestCode; i > 0; i--)
+ {
+ if (value < m_Limitits[i])
+ {
+ numBits = i;
+ break;
+ }
+ }
+ if (i == 0)
+ return 0xFFFFFFFF;
+ inStream->MovePos(numBits);
+ UInt32 index = m_Positions[numBits] +
+ ((value - m_Limitits[numBits + 1]) >> (kNumBitsInLongestCode - numBits));
+ if (index >= m_NumSymbols)
+ return 0xFFFFFFFF;
+ return m_Symbols[index];
+}
+
+}}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ImplodeHuffmanDecoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,34 @@
+// ImplodeHuffmanDecoder.h
+
+#ifndef __IMPLODE_HUFFMAN_DECODER_H
+#define __IMPLODE_HUFFMAN_DECODER_H
+
+#include "../Common/InBuffer.h"
+
+#include "BitlDecoder.h"
+
+namespace NCompress {
+namespace NImplode {
+namespace NHuffman {
+
+const int kNumBitsInLongestCode = 16;
+
+typedef NBitl::CDecoder<CInBuffer> CInBit;
+
+class CDecoder
+{
+ UInt32 m_Limitits[kNumBitsInLongestCode + 2]; // m_Limitits[i] = value limit for symbols with length = i
+ UInt32 m_Positions[kNumBitsInLongestCode + 2]; // m_Positions[i] = index in m_Symbols[] of first symbol with length = i
+ UInt32 m_NumSymbols; // number of symbols in m_Symbols
+ UInt32 *m_Symbols; // symbols: at first with len=1 then 2, ... 15.
+public:
+ CDecoder(UInt32 numSymbols);
+ ~CDecoder();
+
+ bool SetCodeLengths(const Byte *codeLengths);
+ UInt32 DecodeSymbol(CInBit *inStream);
+};
+
+}}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,531 @@
+// LzmaAlone.cpp
+
+#include "StdAfx.h"
+
+#include "../../../Common/MyWindows.h"
+#include "../../../Common/MyInitGuid.h"
+
+#include <stdio.h>
+
+#if defined(_WIN32) || defined(OS2) || defined(MSDOS)
+#include <fcntl.h>
+#include <io.h>
+#define MY_SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)
+#else
+#define MY_SET_BINARY_MODE(file)
+#endif
+
+#include "../../../Common/CommandLineParser.h"
+#include "../../../Common/StringConvert.h"
+#include "../../../Common/StringToInt.h"
+
+#include "../../Common/FileStreams.h"
+#include "../../Common/StreamUtils.h"
+
+#include "../LzmaDecoder.h"
+#include "../LzmaEncoder.h"
+
+#include "LzmaBenchCon.h"
+
+#ifndef _7ZIP_ST
+#include "../../../Windows/System.h"
+#endif
+
+#include "../../../../C/7zVersion.h"
+#include "../../../../C/Alloc.h"
+#include "../../../../C/LzmaUtil/Lzma86Dec.h"
+#include "../../../../C/LzmaUtil/Lzma86Enc.h"
+
+using namespace NCommandLineParser;
+
+#ifdef _WIN32
+bool g_IsNT = false;
+static inline bool IsItWindowsNT()
+{
+ OSVERSIONINFO versionInfo;
+ versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
+ if (!::GetVersionEx(&versionInfo))
+ return false;
+ return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
+}
+#endif
+
+static const char *kCantAllocate = "Can not allocate memory";
+static const char *kReadError = "Read error";
+static const char *kWriteError = "Write error";
+
+namespace NKey {
+enum Enum
+{
+ kHelp1 = 0,
+ kHelp2,
+ kAlgo,
+ kDict,
+ kFb,
+ kMc,
+ kLc,
+ kLp,
+ kPb,
+ kMatchFinder,
+ kMultiThread,
+ kEOS,
+ kStdIn,
+ kStdOut,
+ kFilter86
+};
+}
+
+static const CSwitchForm kSwitchForms[] =
+{
+ { L"?", NSwitchType::kSimple, false },
+ { L"H", NSwitchType::kSimple, false },
+ { L"A", NSwitchType::kUnLimitedPostString, false, 1 },
+ { L"D", NSwitchType::kUnLimitedPostString, false, 1 },
+ { L"FB", NSwitchType::kUnLimitedPostString, false, 1 },
+ { L"MC", NSwitchType::kUnLimitedPostString, false, 1 },
+ { L"LC", NSwitchType::kUnLimitedPostString, false, 1 },
+ { L"LP", NSwitchType::kUnLimitedPostString, false, 1 },
+ { L"PB", NSwitchType::kUnLimitedPostString, false, 1 },
+ { L"MF", NSwitchType::kUnLimitedPostString, false, 1 },
+ { L"MT", NSwitchType::kUnLimitedPostString, false, 0 },
+ { L"EOS", NSwitchType::kSimple, false },
+ { L"SI", NSwitchType::kSimple, false },
+ { L"SO", NSwitchType::kSimple, false },
+ { L"F86", NSwitchType::kPostChar, false, 0, 0, L"+" }
+};
+
+static const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);
+
+static void PrintHelp()
+{
+ fprintf(stderr, "\nUsage: LZMA <e|d> inputFile outputFile [<switches>...]\n"
+ " e: encode file\n"
+ " d: decode file\n"
+ " b: Benchmark\n"
+ "<Switches>\n"
+ " -a{N}: set compression mode - [0, 1], default: 1 (max)\n"
+ " -d{N}: set dictionary size - [12, 30], default: 23 (8MB)\n"
+ " -fb{N}: set number of fast bytes - [5, 273], default: 128\n"
+ " -mc{N}: set number of cycles for match finder\n"
+ " -lc{N}: set number of literal context bits - [0, 8], default: 3\n"
+ " -lp{N}: set number of literal pos bits - [0, 4], default: 0\n"
+ " -pb{N}: set number of pos bits - [0, 4], default: 2\n"
+ " -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, hc4], default: bt4\n"
+ " -mt{N}: set number of CPU threads\n"
+ " -eos: write End Of Stream marker\n"
+ " -si: read data from stdin\n"
+ " -so: write data to stdout\n"
+ );
+}
+
+static void PrintHelpAndExit(const char *s)
+{
+ fprintf(stderr, "\nError: %s\n\n", s);
+ PrintHelp();
+ throw -1;
+}
+
+static void IncorrectCommand()
+{
+ PrintHelpAndExit("Incorrect command");
+}
+
+static void WriteArgumentsToStringList(int numArguments, const char *arguments[],
+ UStringVector &strings)
+{
+ for(int i = 1; i < numArguments; i++)
+ strings.Add(MultiByteToUnicodeString(arguments[i]));
+}
+
+static bool GetNumber(const wchar_t *s, UInt32 &value)
+{
+ value = 0;
+ if (MyStringLen(s) == 0)
+ return false;
+ const wchar_t *end;
+ UInt64 res = ConvertStringToUInt64(s, &end);
+ if (*end != L'\0')
+ return false;
+ if (res > 0xFFFFFFFF)
+ return false;
+ value = UInt32(res);
+ return true;
+}
+
+static void ParseUInt32(const CParser &parser, int index, UInt32 &res)
+{
+ if (parser[index].ThereIs)
+ if (!GetNumber(parser[index].PostStrings[0], res))
+ IncorrectCommand();
+}
+
+int main2(int n, const char *args[])
+{
+ #ifdef _WIN32
+ g_IsNT = IsItWindowsNT();
+ #endif
+
+ fprintf(stderr, "\nLZMA " MY_VERSION_COPYRIGHT_DATE "\n");
+
+ if (n == 1)
+ {
+ PrintHelp();
+ return 0;
+ }
+
+ bool unsupportedTypes = (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4);
+ if (unsupportedTypes)
+ {
+ fprintf(stderr, "Unsupported base types. Edit Common/Types.h and recompile");
+ return 1;
+ }
+
+ UStringVector commandStrings;
+ WriteArgumentsToStringList(n, args, commandStrings);
+ CParser parser(kNumSwitches);
+ try
+ {
+ parser.ParseStrings(kSwitchForms, commandStrings);
+ }
+ catch(...)
+ {
+ IncorrectCommand();
+ }
+
+ if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)
+ {
+ PrintHelp();
+ return 0;
+ }
+ const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;
+
+ int paramIndex = 0;
+ if (paramIndex >= nonSwitchStrings.Size())
+ IncorrectCommand();
+ const UString &command = nonSwitchStrings[paramIndex++];
+
+ bool dictDefined = false;
+ UInt32 dict = (UInt32)-1;
+ if(parser[NKey::kDict].ThereIs)
+ {
+ UInt32 dicLog;
+ if (!GetNumber(parser[NKey::kDict].PostStrings[0], dicLog))
+ IncorrectCommand();
+ dict = 1 << dicLog;
+ dictDefined = true;
+ }
+ UString mf = L"BT4";
+ if (parser[NKey::kMatchFinder].ThereIs)
+ mf = parser[NKey::kMatchFinder].PostStrings[0];
+
+ UInt32 numThreads = (UInt32)-1;
+
+ #ifndef _7ZIP_ST
+ if (parser[NKey::kMultiThread].ThereIs)
+ {
+ UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();
+ const UString &s = parser[NKey::kMultiThread].PostStrings[0];
+ if (s.IsEmpty())
+ numThreads = numCPUs;
+ else
+ if (!GetNumber(s, numThreads))
+ IncorrectCommand();
+ }
+ #endif
+
+ if (command.CompareNoCase(L"b") == 0)
+ {
+ const UInt32 kNumDefaultItereations = 1;
+ UInt32 numIterations = kNumDefaultItereations;
+ {
+ if (paramIndex < nonSwitchStrings.Size())
+ if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))
+ numIterations = kNumDefaultItereations;
+ }
+ return LzmaBenchCon(stderr, numIterations, numThreads, dict);
+ }
+
+ if (numThreads == (UInt32)-1)
+ numThreads = 1;
+
+ bool encodeMode = false;
+ if (command.CompareNoCase(L"e") == 0)
+ encodeMode = true;
+ else if (command.CompareNoCase(L"d") == 0)
+ encodeMode = false;
+ else
+ IncorrectCommand();
+
+ bool stdInMode = parser[NKey::kStdIn].ThereIs;
+ bool stdOutMode = parser[NKey::kStdOut].ThereIs;
+
+ CMyComPtr<ISequentialInStream> inStream;
+ CInFileStream *inStreamSpec = 0;
+ if (stdInMode)
+ {
+ inStream = new CStdInFileStream;
+ MY_SET_BINARY_MODE(stdin);
+ }
+ else
+ {
+ if (paramIndex >= nonSwitchStrings.Size())
+ IncorrectCommand();
+ const UString &inputName = nonSwitchStrings[paramIndex++];
+ inStreamSpec = new CInFileStream;
+ inStream = inStreamSpec;
+ if (!inStreamSpec->Open(GetSystemString(inputName)))
+ {
+ fprintf(stderr, "\nError: can not open input file %s\n",
+ (const char *)GetOemString(inputName));
+ return 1;
+ }
+ }
+
+ CMyComPtr<ISequentialOutStream> outStream;
+ COutFileStream *outStreamSpec = NULL;
+ if (stdOutMode)
+ {
+ outStream = new CStdOutFileStream;
+ MY_SET_BINARY_MODE(stdout);
+ }
+ else
+ {
+ if (paramIndex >= nonSwitchStrings.Size())
+ IncorrectCommand();
+ const UString &outputName = nonSwitchStrings[paramIndex++];
+ outStreamSpec = new COutFileStream;
+ outStream = outStreamSpec;
+ if (!outStreamSpec->Create(GetSystemString(outputName), true))
+ {
+ fprintf(stderr, "\nError: can not open output file %s\n",
+ (const char *)GetOemString(outputName));
+ return 1;
+ }
+ }
+
+ if (parser[NKey::kFilter86].ThereIs)
+ {
+ // -f86 switch is for x86 filtered mode: BCJ + LZMA.
+ if (parser[NKey::kEOS].ThereIs || stdInMode)
+ throw "Can not use stdin in this mode";
+ UInt64 fileSize;
+ inStreamSpec->File.GetLength(fileSize);
+ if (fileSize > 0xF0000000)
+ throw "File is too big";
+ size_t inSize = (size_t)fileSize;
+ Byte *inBuffer = 0;
+ if (inSize != 0)
+ {
+ inBuffer = (Byte *)MyAlloc((size_t)inSize);
+ if (inBuffer == 0)
+ throw kCantAllocate;
+ }
+
+ if (ReadStream_FAIL(inStream, inBuffer, inSize) != S_OK)
+ throw "Can not read";
+
+ Byte *outBuffer = 0;
+ size_t outSize;
+ if (encodeMode)
+ {
+ // we allocate 105% of original size for output buffer
+ outSize = (size_t)fileSize / 20 * 21 + (1 << 16);
+ if (outSize != 0)
+ {
+ outBuffer = (Byte *)MyAlloc((size_t)outSize);
+ if (outBuffer == 0)
+ throw kCantAllocate;
+ }
+ if (!dictDefined)
+ dict = 1 << 23;
+ int res = Lzma86_Encode(outBuffer, &outSize, inBuffer, inSize,
+ 5, dict, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO);
+ if (res != 0)
+ {
+ fprintf(stderr, "\nEncoder error = %d\n", (int)res);
+ return 1;
+ }
+ }
+ else
+ {
+ UInt64 outSize64;
+ if (Lzma86_GetUnpackSize(inBuffer, inSize, &outSize64) != 0)
+ throw "data error";
+ outSize = (size_t)outSize64;
+ if (outSize != outSize64)
+ throw "too big";
+ if (outSize != 0)
+ {
+ outBuffer = (Byte *)MyAlloc(outSize);
+ if (outBuffer == 0)
+ throw kCantAllocate;
+ }
+ int res = Lzma86_Decode(outBuffer, &outSize, inBuffer, &inSize);
+ if (inSize != (size_t)fileSize)
+ throw "incorrect processed size";
+ if (res != 0)
+ throw "LzmaDecoder error";
+ }
+ if (WriteStream(outStream, outBuffer, outSize) != S_OK)
+ throw kWriteError;
+ MyFree(outBuffer);
+ MyFree(inBuffer);
+ return 0;
+ }
+
+
+ UInt64 fileSize;
+ if (encodeMode)
+ {
+ NCompress::NLzma::CEncoder *encoderSpec = new NCompress::NLzma::CEncoder;
+ CMyComPtr<ICompressCoder> encoder = encoderSpec;
+
+ if (!dictDefined)
+ dict = 1 << 23;
+
+ UInt32 pb = 2;
+ UInt32 lc = 3; // = 0; for 32-bit data
+ UInt32 lp = 0; // = 2; for 32-bit data
+ UInt32 algo = 1;
+ UInt32 fb = 128;
+ UInt32 mc = 16 + fb / 2;
+ bool mcDefined = false;
+
+ bool eos = parser[NKey::kEOS].ThereIs || stdInMode;
+
+ ParseUInt32(parser, NKey::kAlgo, algo);
+ ParseUInt32(parser, NKey::kFb, fb);
+ ParseUInt32(parser, NKey::kLc, lc);
+ ParseUInt32(parser, NKey::kLp, lp);
+ ParseUInt32(parser, NKey::kPb, pb);
+
+ mcDefined = parser[NKey::kMc].ThereIs;
+ if (mcDefined)
+ if (!GetNumber(parser[NKey::kMc].PostStrings[0], mc))
+ IncorrectCommand();
+
+ PROPID propIDs[] =
+ {
+ NCoderPropID::kDictionarySize,
+ NCoderPropID::kPosStateBits,
+ NCoderPropID::kLitContextBits,
+ NCoderPropID::kLitPosBits,
+ NCoderPropID::kAlgorithm,
+ NCoderPropID::kNumFastBytes,
+ NCoderPropID::kMatchFinder,
+ NCoderPropID::kEndMarker,
+ NCoderPropID::kNumThreads,
+ NCoderPropID::kMatchFinderCycles,
+ };
+ const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);
+
+ PROPVARIANT props[kNumPropsMax];
+ for (int p = 0; p < 6; p++)
+ props[p].vt = VT_UI4;
+
+ props[0].ulVal = (UInt32)dict;
+ props[1].ulVal = (UInt32)pb;
+ props[2].ulVal = (UInt32)lc;
+ props[3].ulVal = (UInt32)lp;
+ props[4].ulVal = (UInt32)algo;
+ props[5].ulVal = (UInt32)fb;
+
+ props[6].vt = VT_BSTR;
+ props[6].bstrVal = (BSTR)(const wchar_t *)mf;
+
+ props[7].vt = VT_BOOL;
+ props[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;
+
+ props[8].vt = VT_UI4;
+ props[8].ulVal = (UInt32)numThreads;
+
+ // it must be last in property list
+ props[9].vt = VT_UI4;
+ props[9].ulVal = (UInt32)mc;
+
+ int numProps = kNumPropsMax;
+ if (!mcDefined)
+ numProps--;
+
+ if (encoderSpec->SetCoderProperties(propIDs, props, numProps) != S_OK)
+ IncorrectCommand();
+ encoderSpec->WriteCoderProperties(outStream);
+
+ if (eos || stdInMode)
+ fileSize = (UInt64)(Int64)-1;
+ else
+ inStreamSpec->File.GetLength(fileSize);
+
+ for (int i = 0; i < 8; i++)
+ {
+ Byte b = Byte(fileSize >> (8 * i));
+ if (outStream->Write(&b, 1, 0) != S_OK)
+ {
+ fprintf(stderr, kWriteError);
+ return 1;
+ }
+ }
+ HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);
+ if (result == E_OUTOFMEMORY)
+ {
+ fprintf(stderr, "\nError: Can not allocate memory\n");
+ return 1;
+ }
+ else if (result != S_OK)
+ {
+ fprintf(stderr, "\nEncoder error = %X\n", (unsigned int)result);
+ return 1;
+ }
+ }
+ else
+ {
+ NCompress::NLzma::CDecoder *decoderSpec = new NCompress::NLzma::CDecoder;
+ CMyComPtr<ICompressCoder> decoder = decoderSpec;
+ decoderSpec->FinishStream = true;
+ const UInt32 kPropertiesSize = 5;
+ Byte header[kPropertiesSize + 8];
+ if (ReadStream_FALSE(inStream, header, kPropertiesSize + 8) != S_OK)
+ {
+ fprintf(stderr, kReadError);
+ return 1;
+ }
+ if (decoderSpec->SetDecoderProperties2(header, kPropertiesSize) != S_OK)
+ {
+ fprintf(stderr, "SetDecoderProperties error");
+ return 1;
+ }
+ fileSize = 0;
+ for (int i = 0; i < 8; i++)
+ fileSize |= ((UInt64)header[kPropertiesSize + i]) << (8 * i);
+
+ if (decoder->Code(inStream, outStream, 0, (fileSize == (UInt64)(Int64)-1) ? 0 : &fileSize, 0) != S_OK)
+ {
+ fprintf(stderr, "Decoder error");
+ return 1;
+ }
+ }
+ if (outStreamSpec != NULL)
+ {
+ if (outStreamSpec->Close() != S_OK)
+ {
+ fprintf(stderr, "File closing error");
+ return 1;
+ }
+ }
+ return 0;
+}
+
+int MY_CDECL main(int n, const char *args[])
+{
+ try { return main2(n, args); }
+ catch(const char *s)
+ {
+ fprintf(stderr, "\nError: %s\n", s);
+ return 1;
+ }
+ catch(...)
+ {
+ fprintf(stderr, "\nError\n");
+ return 1;
+ }
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,1018 @@
+// LzmaBench.cpp
+
+#include "StdAfx.h"
+
+#include "LzmaBench.h"
+
+#ifndef _WIN32
+#define USE_POSIX_TIME
+#define USE_POSIX_TIME2
+#endif
+
+#ifdef USE_POSIX_TIME
+#include <time.h>
+#ifdef USE_POSIX_TIME2
+#include <sys/time.h>
+#endif
+#endif
+
+#ifdef _WIN32
+#define USE_ALLOCA
+#endif
+
+#ifdef USE_ALLOCA
+#ifdef _WIN32
+#include <malloc.h>
+#else
+#include <stdlib.h>
+#endif
+#endif
+
+#include "../../../../C/7zCrc.h"
+#include "../../../../C/Alloc.h"
+
+#include "../../../Common/MyCom.h"
+
+#ifdef BENCH_MT
+#include "../../../Windows/Synchronization.h"
+#include "../../../Windows/Thread.h"
+#endif
+
+#ifdef EXTERNAL_LZMA
+#include "../../../Windows/PropVariant.h"
+#include "../../ICoder.h"
+#else
+#include "../LzmaDecoder.h"
+#include "../LzmaEncoder.h"
+#endif
+
+static const UInt32 kUncompressMinBlockSize = 1 << 26;
+static const UInt32 kAdditionalSize = (1 << 16);
+static const UInt32 kCompressedAdditionalSize = (1 << 10);
+static const UInt32 kMaxLzmaPropSize = 5;
+
+class CBaseRandomGenerator
+{
+ UInt32 A1;
+ UInt32 A2;
+public:
+ CBaseRandomGenerator() { Init(); }
+ void Init() { A1 = 362436069; A2 = 521288629;}
+ UInt32 GetRnd()
+ {
+ return
+ ((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) +
+ ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );
+ }
+};
+
+class CBenchBuffer
+{
+public:
+ size_t BufferSize;
+ Byte *Buffer;
+ CBenchBuffer(): Buffer(0) {}
+ virtual ~CBenchBuffer() { Free(); }
+ void Free()
+ {
+ ::MidFree(Buffer);
+ Buffer = 0;
+ }
+ bool Alloc(size_t bufferSize)
+ {
+ if (Buffer != 0 && BufferSize == bufferSize)
+ return true;
+ Free();
+ Buffer = (Byte *)::MidAlloc(bufferSize);
+ BufferSize = bufferSize;
+ return (Buffer != 0);
+ }
+};
+
+class CBenchRandomGenerator: public CBenchBuffer
+{
+ CBaseRandomGenerator *RG;
+public:
+ void Set(CBaseRandomGenerator *rg) { RG = rg; }
+ UInt32 GetVal(UInt32 &res, int numBits)
+ {
+ UInt32 val = res & (((UInt32)1 << numBits) - 1);
+ res >>= numBits;
+ return val;
+ }
+ UInt32 GetLen(UInt32 &res)
+ {
+ UInt32 len = GetVal(res, 2);
+ return GetVal(res, 1 + len);
+ }
+ void Generate()
+ {
+ UInt32 pos = 0;
+ UInt32 rep0 = 1;
+ while (pos < BufferSize)
+ {
+ UInt32 res = RG->GetRnd();
+ res >>= 1;
+ if (GetVal(res, 1) == 0 || pos < 1024)
+ Buffer[pos++] = (Byte)(res & 0xFF);
+ else
+ {
+ UInt32 len;
+ len = 1 + GetLen(res);
+ if (GetVal(res, 3) != 0)
+ {
+ len += GetLen(res);
+ do
+ {
+ UInt32 ppp = GetVal(res, 5) + 6;
+ res = RG->GetRnd();
+ if (ppp > 30)
+ continue;
+ rep0 = /* (1 << ppp) +*/ GetVal(res, ppp);
+ res = RG->GetRnd();
+ }
+ while (rep0 >= pos);
+ rep0++;
+ }
+
+ for (UInt32 i = 0; i < len && pos < BufferSize; i++, pos++)
+ Buffer[pos] = Buffer[pos - rep0];
+ }
+ }
+ }
+};
+
+
+class CBenchmarkInStream:
+ public ISequentialInStream,
+ public CMyUnknownImp
+{
+ const Byte *Data;
+ size_t Pos;
+ size_t Size;
+public:
+ MY_UNKNOWN_IMP
+ void Init(const Byte *data, size_t size)
+ {
+ Data = data;
+ Size = size;
+ Pos = 0;
+ }
+ STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
+};
+
+STDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
+{
+ size_t remain = Size - Pos;
+ UInt32 kMaxBlockSize = (1 << 20);
+ if (size > kMaxBlockSize)
+ size = kMaxBlockSize;
+ if (size > remain)
+ size = (UInt32)remain;
+ for (UInt32 i = 0; i < size; i++)
+ ((Byte *)data)[i] = Data[Pos + i];
+ Pos += size;
+ if(processedSize != NULL)
+ *processedSize = size;
+ return S_OK;
+}
+
+class CBenchmarkOutStream:
+ public ISequentialOutStream,
+ public CBenchBuffer,
+ public CMyUnknownImp
+{
+ // bool _overflow;
+public:
+ UInt32 Pos;
+ // CBenchmarkOutStream(): _overflow(false) {}
+ void Init()
+ {
+ // _overflow = false;
+ Pos = 0;
+ }
+ MY_UNKNOWN_IMP
+ STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
+};
+
+STDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
+{
+ size_t curSize = BufferSize - Pos;
+ if (curSize > size)
+ curSize = size;
+ memcpy(Buffer + Pos, data, curSize);
+ Pos += (UInt32)curSize;
+ if(processedSize != NULL)
+ *processedSize = (UInt32)curSize;
+ if (curSize != size)
+ {
+ // _overflow = true;
+ return E_FAIL;
+ }
+ return S_OK;
+}
+
+class CCrcOutStream:
+ public ISequentialOutStream,
+ public CMyUnknownImp
+{
+public:
+ UInt32 Crc;
+ MY_UNKNOWN_IMP
+ void Init() { Crc = CRC_INIT_VAL; }
+ STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
+};
+
+STDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
+{
+ Crc = CrcUpdate(Crc, data, size);
+ if (processedSize != NULL)
+ *processedSize = size;
+ return S_OK;
+}
+
+static UInt64 GetTimeCount()
+{
+ #ifdef USE_POSIX_TIME
+ #ifdef USE_POSIX_TIME2
+ timeval v;
+ if (gettimeofday(&v, 0) == 0)
+ return (UInt64)(v.tv_sec) * 1000000 + v.tv_usec;
+ return (UInt64)time(NULL) * 1000000;
+ #else
+ return time(NULL);
+ #endif
+ #else
+ /*
+ LARGE_INTEGER value;
+ if (::QueryPerformanceCounter(&value))
+ return value.QuadPart;
+ */
+ return GetTickCount();
+ #endif
+}
+
+static UInt64 GetFreq()
+{
+ #ifdef USE_POSIX_TIME
+ #ifdef USE_POSIX_TIME2
+ return 1000000;
+ #else
+ return 1;
+ #endif
+ #else
+ /*
+ LARGE_INTEGER value;
+ if (::QueryPerformanceFrequency(&value))
+ return value.QuadPart;
+ */
+ return 1000;
+ #endif
+}
+
+#ifndef USE_POSIX_TIME
+static inline UInt64 GetTime64(const FILETIME &t) { return ((UInt64)t.dwHighDateTime << 32) | t.dwLowDateTime; }
+#endif
+static UInt64 GetUserTime()
+{
+ #ifdef USE_POSIX_TIME
+ return clock();
+ #else
+ FILETIME creationTime, exitTime, kernelTime, userTime;
+ if (::GetProcessTimes(::GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime) != 0)
+ return GetTime64(userTime) + GetTime64(kernelTime);
+ return (UInt64)GetTickCount() * 10000;
+ #endif
+}
+
+static UInt64 GetUserFreq()
+{
+ #ifdef USE_POSIX_TIME
+ return CLOCKS_PER_SEC;
+ #else
+ return 10000000;
+ #endif
+}
+
+class CBenchProgressStatus
+{
+ #ifdef BENCH_MT
+ NWindows::NSynchronization::CCriticalSection CS;
+ #endif
+public:
+ HRESULT Res;
+ bool EncodeMode;
+ void SetResult(HRESULT res)
+ {
+ #ifdef BENCH_MT
+ NWindows::NSynchronization::CCriticalSectionLock lock(CS);
+ #endif
+ Res = res;
+ }
+ HRESULT GetResult()
+ {
+ #ifdef BENCH_MT
+ NWindows::NSynchronization::CCriticalSectionLock lock(CS);
+ #endif
+ return Res;
+ }
+};
+
+class CBenchProgressInfo:
+ public ICompressProgressInfo,
+ public CMyUnknownImp
+{
+public:
+ CBenchProgressStatus *Status;
+ CBenchInfo BenchInfo;
+ HRESULT Res;
+ IBenchCallback *callback;
+ CBenchProgressInfo(): callback(0) {}
+ MY_UNKNOWN_IMP
+ STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
+};
+
+void SetStartTime(CBenchInfo &bi)
+{
+ bi.GlobalFreq = GetFreq();
+ bi.UserFreq = GetUserFreq();
+ bi.GlobalTime = ::GetTimeCount();
+ bi.UserTime = ::GetUserTime();
+}
+
+void SetFinishTime(const CBenchInfo &biStart, CBenchInfo &dest)
+{
+ dest.GlobalFreq = GetFreq();
+ dest.UserFreq = GetUserFreq();
+ dest.GlobalTime = ::GetTimeCount() - biStart.GlobalTime;
+ dest.UserTime = ::GetUserTime() - biStart.UserTime;
+}
+
+STDMETHODIMP CBenchProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
+{
+ HRESULT res = Status->GetResult();
+ if (res != S_OK)
+ return res;
+ if (!callback)
+ return res;
+ CBenchInfo info = BenchInfo;
+ SetFinishTime(BenchInfo, info);
+ if (Status->EncodeMode)
+ {
+ info.UnpackSize = *inSize;
+ info.PackSize = *outSize;
+ res = callback->SetEncodeResult(info, false);
+ }
+ else
+ {
+ info.PackSize = BenchInfo.PackSize + *inSize;
+ info.UnpackSize = BenchInfo.UnpackSize + *outSize;
+ res = callback->SetDecodeResult(info, false);
+ }
+ if (res != S_OK)
+ Status->SetResult(res);
+ return res;
+}
+
+static const int kSubBits = 8;
+
+static UInt32 GetLogSize(UInt32 size)
+{
+ for (int i = kSubBits; i < 32; i++)
+ for (UInt32 j = 0; j < (1 << kSubBits); j++)
+ if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))
+ return (i << kSubBits) + j;
+ return (32 << kSubBits);
+}
+
+static void NormalizeVals(UInt64 &v1, UInt64 &v2)
+{
+ while (v1 > 1000000)
+ {
+ v1 >>= 1;
+ v2 >>= 1;
+ }
+}
+
+UInt64 GetUsage(const CBenchInfo &info)
+{
+ UInt64 userTime = info.UserTime;
+ UInt64 userFreq = info.UserFreq;
+ UInt64 globalTime = info.GlobalTime;
+ UInt64 globalFreq = info.GlobalFreq;
+ NormalizeVals(userTime, userFreq);
+ NormalizeVals(globalFreq, globalTime);
+ if (userFreq == 0)
+ userFreq = 1;
+ if (globalTime == 0)
+ globalTime = 1;
+ return userTime * globalFreq * 1000000 / userFreq / globalTime;
+}
+
+UInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating)
+{
+ UInt64 userTime = info.UserTime;
+ UInt64 userFreq = info.UserFreq;
+ UInt64 globalTime = info.GlobalTime;
+ UInt64 globalFreq = info.GlobalFreq;
+ NormalizeVals(userFreq, userTime);
+ NormalizeVals(globalTime, globalFreq);
+ if (globalFreq == 0)
+ globalFreq = 1;
+ if (userTime == 0)
+ userTime = 1;
+ return userFreq * globalTime / globalFreq * rating / userTime;
+}
+
+static UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)
+{
+ UInt64 elTime = elapsedTime;
+ NormalizeVals(freq, elTime);
+ if (elTime == 0)
+ elTime = 1;
+ return value * freq / elTime;
+}
+
+UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size)
+{
+ UInt64 t = GetLogSize(dictionarySize) - (kBenchMinDicLogSize << kSubBits);
+ UInt64 numCommandsForOne = 870 + ((t * t * 5) >> (2 * kSubBits));
+ UInt64 numCommands = (UInt64)(size) * numCommandsForOne;
+ return MyMultDiv64(numCommands, elapsedTime, freq);
+}
+
+UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations)
+{
+ UInt64 numCommands = (inSize * 200 + outSize * 4) * numIterations;
+ return MyMultDiv64(numCommands, elapsedTime, freq);
+}
+
+#ifdef EXTERNAL_LZMA
+typedef UInt32 (WINAPI * CreateObjectPointer)(const GUID *clsID,
+ const GUID *interfaceID, void **outObject);
+#endif
+
+struct CEncoderInfo;
+
+struct CEncoderInfo
+{
+ #ifdef BENCH_MT
+ NWindows::CThread thread[2];
+ #endif
+ CMyComPtr<ICompressCoder> encoder;
+ CBenchProgressInfo *progressInfoSpec[2];
+ CMyComPtr<ICompressProgressInfo> progressInfo[2];
+ UInt32 NumIterations;
+ #ifdef USE_ALLOCA
+ size_t AllocaSize;
+ #endif
+
+ struct CDecoderInfo
+ {
+ CEncoderInfo *Encoder;
+ UInt32 DecoderIndex;
+ #ifdef USE_ALLOCA
+ size_t AllocaSize;
+ #endif
+ bool CallbackMode;
+ };
+ CDecoderInfo decodersInfo[2];
+
+ CMyComPtr<ICompressCoder> decoders[2];
+ HRESULT Results[2];
+ CBenchmarkOutStream *outStreamSpec;
+ CMyComPtr<ISequentialOutStream> outStream;
+ IBenchCallback *callback;
+ UInt32 crc;
+ UInt32 kBufferSize;
+ UInt32 compressedSize;
+ CBenchRandomGenerator rg;
+ CBenchmarkOutStream *propStreamSpec;
+ CMyComPtr<ISequentialOutStream> propStream;
+ HRESULT Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rg);
+ HRESULT Encode();
+ HRESULT Decode(UInt32 decoderIndex);
+
+ CEncoderInfo(): outStreamSpec(0), callback(0), propStreamSpec(0) {}
+
+ #ifdef BENCH_MT
+ static THREAD_FUNC_DECL EncodeThreadFunction(void *param)
+ {
+ CEncoderInfo *encoder = (CEncoderInfo *)param;
+ #ifdef USE_ALLOCA
+ alloca(encoder->AllocaSize);
+ #endif
+ HRESULT res = encoder->Encode();
+ encoder->Results[0] = res;
+ if (res != S_OK)
+ encoder->progressInfoSpec[0]->Status->SetResult(res);
+
+ return 0;
+ }
+ static THREAD_FUNC_DECL DecodeThreadFunction(void *param)
+ {
+ CDecoderInfo *decoder = (CDecoderInfo *)param;
+ #ifdef USE_ALLOCA
+ alloca(decoder->AllocaSize);
+ #endif
+ CEncoderInfo *encoder = decoder->Encoder;
+ encoder->Results[decoder->DecoderIndex] = encoder->Decode(decoder->DecoderIndex);
+ return 0;
+ }
+
+ HRESULT CreateEncoderThread()
+ {
+ return thread[0].Create(EncodeThreadFunction, this);
+ }
+
+ HRESULT CreateDecoderThread(int index, bool callbackMode
+ #ifdef USE_ALLOCA
+ , size_t allocaSize
+ #endif
+ )
+ {
+ CDecoderInfo &decoder = decodersInfo[index];
+ decoder.DecoderIndex = index;
+ decoder.Encoder = this;
+ #ifdef USE_ALLOCA
+ decoder.AllocaSize = allocaSize;
+ #endif
+ decoder.CallbackMode = callbackMode;
+ return thread[index].Create(DecodeThreadFunction, &decoder);
+ }
+ #endif
+};
+
+HRESULT CEncoderInfo::Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rgLoc)
+{
+ rg.Set(rgLoc);
+ kBufferSize = dictionarySize + kAdditionalSize;
+ UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;
+ if (!rg.Alloc(kBufferSize))
+ return E_OUTOFMEMORY;
+ rg.Generate();
+ crc = CrcCalc(rg.Buffer, rg.BufferSize);
+
+ outStreamSpec = new CBenchmarkOutStream;
+ if (!outStreamSpec->Alloc(kCompressedBufferSize))
+ return E_OUTOFMEMORY;
+
+ outStream = outStreamSpec;
+
+ propStreamSpec = 0;
+ if (!propStream)
+ {
+ propStreamSpec = new CBenchmarkOutStream;
+ propStream = propStreamSpec;
+ }
+ if (!propStreamSpec->Alloc(kMaxLzmaPropSize))
+ return E_OUTOFMEMORY;
+ propStreamSpec->Init();
+
+ PROPID propIDs[] =
+ {
+ NCoderPropID::kDictionarySize,
+ NCoderPropID::kNumThreads
+ };
+ const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);
+ PROPVARIANT props[kNumProps];
+ props[0].vt = VT_UI4;
+ props[0].ulVal = dictionarySize;
+
+ props[1].vt = VT_UI4;
+ props[1].ulVal = numThreads;
+
+ {
+ CMyComPtr<ICompressSetCoderProperties> setCoderProperties;
+ RINOK(encoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties));
+ if (!setCoderProperties)
+ return E_FAIL;
+ RINOK(setCoderProperties->SetCoderProperties(propIDs, props, kNumProps));
+
+ CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;
+ encoder.QueryInterface(IID_ICompressWriteCoderProperties, &writeCoderProperties);
+ if (writeCoderProperties)
+ {
+ RINOK(writeCoderProperties->WriteCoderProperties(propStream));
+ }
+ }
+ return S_OK;
+}
+
+HRESULT CEncoderInfo::Encode()
+{
+ CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;
+ CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
+ inStreamSpec->Init(rg.Buffer, rg.BufferSize);
+ outStreamSpec->Init();
+
+ RINOK(encoder->Code(inStream, outStream, 0, 0, progressInfo[0]));
+ compressedSize = outStreamSpec->Pos;
+ encoder.Release();
+ return S_OK;
+}
+
+HRESULT CEncoderInfo::Decode(UInt32 decoderIndex)
+{
+ CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;
+ CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
+ CMyComPtr<ICompressCoder> &decoder = decoders[decoderIndex];
+
+ CMyComPtr<ICompressSetDecoderProperties2> compressSetDecoderProperties;
+ decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &compressSetDecoderProperties);
+ if (!compressSetDecoderProperties)
+ return E_FAIL;
+
+ CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;
+ CMyComPtr<ISequentialOutStream> crcOutStream = crcOutStreamSpec;
+
+ CBenchProgressInfo *pi = progressInfoSpec[decoderIndex];
+ pi->BenchInfo.UnpackSize = 0;
+ pi->BenchInfo.PackSize = 0;
+
+ for (UInt32 j = 0; j < NumIterations; j++)
+ {
+ inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);
+ crcOutStreamSpec->Init();
+
+ RINOK(compressSetDecoderProperties->SetDecoderProperties2(propStreamSpec->Buffer, propStreamSpec->Pos));
+ UInt64 outSize = kBufferSize;
+ RINOK(decoder->Code(inStream, crcOutStream, 0, &outSize, progressInfo[decoderIndex]));
+ if (CRC_GET_DIGEST(crcOutStreamSpec->Crc) != crc)
+ return S_FALSE;
+ pi->BenchInfo.UnpackSize += kBufferSize;
+ pi->BenchInfo.PackSize += compressedSize;
+ }
+ decoder.Release();
+ return S_OK;
+}
+
+static const UInt32 kNumThreadsMax = (1 << 16);
+
+struct CBenchEncoders
+{
+ CEncoderInfo *encoders;
+ CBenchEncoders(UInt32 num): encoders(0) { encoders = new CEncoderInfo[num]; }
+ ~CBenchEncoders() { delete []encoders; }
+};
+
+HRESULT LzmaBench(
+ #ifdef EXTERNAL_LZMA
+ CCodecs *codecs,
+ #endif
+ UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback)
+{
+ UInt32 numEncoderThreads =
+ #ifdef BENCH_MT
+ (numThreads > 1 ? numThreads / 2 : 1);
+ #else
+ 1;
+ #endif
+ UInt32 numSubDecoderThreads =
+ #ifdef BENCH_MT
+ (numThreads > 1 ? 2 : 1);
+ #else
+ 1;
+ #endif
+ if (dictionarySize < (1 << kBenchMinDicLogSize) || numThreads < 1 || numEncoderThreads > kNumThreadsMax)
+ {
+ return E_INVALIDARG;
+ }
+
+ CBenchEncoders encodersSpec(numEncoderThreads);
+ CEncoderInfo *encoders = encodersSpec.encoders;
+
+ #ifdef EXTERNAL_LZMA
+ UString name = L"LZMA";
+ #endif
+
+ UInt32 i;
+ for (i = 0; i < numEncoderThreads; i++)
+ {
+ CEncoderInfo &encoder = encoders[i];
+ encoder.callback = (i == 0) ? callback : 0;
+
+ #ifdef EXTERNAL_LZMA
+ RINOK(codecs->CreateCoder(name, true, encoder.encoder));
+ #else
+ encoder.encoder = new NCompress::NLzma::CEncoder;
+ #endif
+ for (UInt32 j = 0; j < numSubDecoderThreads; j++)
+ {
+ #ifdef EXTERNAL_LZMA
+ RINOK(codecs->CreateCoder(name, false, encoder.decoders[j]));
+ #else
+ encoder.decoders[j] = new NCompress::NLzma::CDecoder;
+ #endif
+ }
+ }
+
+ CBaseRandomGenerator rg;
+ rg.Init();
+ for (i = 0; i < numEncoderThreads; i++)
+ {
+ RINOK(encoders[i].Init(dictionarySize, numThreads, &rg));
+ }
+
+ CBenchProgressStatus status;
+ status.Res = S_OK;
+ status.EncodeMode = true;
+
+ for (i = 0; i < numEncoderThreads; i++)
+ {
+ CEncoderInfo &encoder = encoders[i];
+ for (int j = 0; j < 2; j++)
+ {
+ encoder.progressInfo[j] = encoder.progressInfoSpec[j] = new CBenchProgressInfo;
+ encoder.progressInfoSpec[j]->Status = &status;
+ }
+ if (i == 0)
+ {
+ encoder.progressInfoSpec[0]->callback = callback;
+ encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numEncoderThreads;
+ SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);
+ }
+
+ #ifdef BENCH_MT
+ if (numEncoderThreads > 1)
+ {
+ #ifdef USE_ALLOCA
+ encoder.AllocaSize = (i * 16 * 21) & 0x7FF;
+ #endif
+ RINOK(encoder.CreateEncoderThread())
+ }
+ else
+ #endif
+ {
+ RINOK(encoder.Encode());
+ }
+ }
+ #ifdef BENCH_MT
+ if (numEncoderThreads > 1)
+ for (i = 0; i < numEncoderThreads; i++)
+ encoders[i].thread[0].Wait();
+ #endif
+
+ RINOK(status.Res);
+
+ CBenchInfo info;
+
+ SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);
+ info.UnpackSize = 0;
+ info.PackSize = 0;
+ info.NumIterations = 1; // progressInfoSpec->NumIterations;
+ for (i = 0; i < numEncoderThreads; i++)
+ {
+ CEncoderInfo &encoder = encoders[i];
+ info.UnpackSize += encoder.kBufferSize;
+ info.PackSize += encoder.compressedSize;
+ }
+ RINOK(callback->SetEncodeResult(info, true));
+
+
+ status.Res = S_OK;
+ status.EncodeMode = false;
+
+ UInt32 numDecoderThreads = numEncoderThreads * numSubDecoderThreads;
+ for (i = 0; i < numEncoderThreads; i++)
+ {
+ CEncoderInfo &encoder = encoders[i];
+ encoder.NumIterations = 2 + kUncompressMinBlockSize / encoder.kBufferSize;
+
+ if (i == 0)
+ {
+ encoder.progressInfoSpec[0]->callback = callback;
+ encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numDecoderThreads;
+ SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);
+ }
+
+ #ifdef BENCH_MT
+ if (numDecoderThreads > 1)
+ {
+ for (UInt32 j = 0; j < numSubDecoderThreads; j++)
+ {
+ HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0)
+ #ifdef USE_ALLOCA
+ , ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF
+ #endif
+ );
+ RINOK(res);
+ }
+ }
+ else
+ #endif
+ {
+ RINOK(encoder.Decode(0));
+ }
+ }
+ #ifdef BENCH_MT
+ HRESULT res = S_OK;
+ if (numDecoderThreads > 1)
+ for (i = 0; i < numEncoderThreads; i++)
+ for (UInt32 j = 0; j < numSubDecoderThreads; j++)
+ {
+ CEncoderInfo &encoder = encoders[i];
+ encoder.thread[j].Wait();
+ if (encoder.Results[j] != S_OK)
+ res = encoder.Results[j];
+ }
+ RINOK(res);
+ #endif
+ RINOK(status.Res);
+ SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);
+ info.UnpackSize = 0;
+ info.PackSize = 0;
+ info.NumIterations = numSubDecoderThreads * encoders[0].NumIterations;
+ for (i = 0; i < numEncoderThreads; i++)
+ {
+ CEncoderInfo &encoder = encoders[i];
+ info.UnpackSize += encoder.kBufferSize;
+ info.PackSize += encoder.compressedSize;
+ }
+ RINOK(callback->SetDecodeResult(info, false));
+ RINOK(callback->SetDecodeResult(info, true));
+ return S_OK;
+}
+
+
+inline UInt64 GetLZMAUsage(bool multiThread, UInt32 dictionary)
+{
+ UInt32 hs = dictionary - 1;
+ hs |= (hs >> 1);
+ hs |= (hs >> 2);
+ hs |= (hs >> 4);
+ hs |= (hs >> 8);
+ hs >>= 1;
+ hs |= 0xFFFF;
+ if (hs > (1 << 24))
+ hs >>= 1;
+ hs++;
+ return ((hs + (1 << 16)) + (UInt64)dictionary * 2) * 4 + (UInt64)dictionary * 3 / 2 +
+ (1 << 20) + (multiThread ? (6 << 20) : 0);
+}
+
+UInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary)
+{
+ const UInt32 kBufferSize = dictionary;
+ const UInt32 kCompressedBufferSize = (kBufferSize / 2);
+ UInt32 numSubThreads = (numThreads > 1) ? 2 : 1;
+ UInt32 numBigThreads = numThreads / numSubThreads;
+ return (kBufferSize + kCompressedBufferSize +
+ GetLZMAUsage((numThreads > 1), dictionary) + (2 << 20)) * numBigThreads;
+}
+
+static bool CrcBig(const void *data, UInt32 size, UInt32 numCycles, UInt32 crcBase)
+{
+ for (UInt32 i = 0; i < numCycles; i++)
+ if (CrcCalc(data, size) != crcBase)
+ return false;
+ return true;
+}
+
+#ifdef BENCH_MT
+struct CCrcInfo
+{
+ NWindows::CThread Thread;
+ const Byte *Data;
+ UInt32 Size;
+ UInt32 NumCycles;
+ UInt32 Crc;
+ bool Res;
+ void Wait()
+ {
+ Thread.Wait();
+ Thread.Close();
+ }
+};
+
+static THREAD_FUNC_DECL CrcThreadFunction(void *param)
+{
+ CCrcInfo *p = (CCrcInfo *)param;
+ p->Res = CrcBig(p->Data, p->Size, p->NumCycles, p->Crc);
+ return 0;
+}
+
+struct CCrcThreads
+{
+ UInt32 NumThreads;
+ CCrcInfo *Items;
+ CCrcThreads(): Items(0), NumThreads(0) {}
+ void WaitAll()
+ {
+ for (UInt32 i = 0; i < NumThreads; i++)
+ Items[i].Wait();
+ NumThreads = 0;
+ }
+ ~CCrcThreads()
+ {
+ WaitAll();
+ delete []Items;
+ }
+};
+#endif
+
+static UInt32 CrcCalc1(const Byte *buf, UInt32 size)
+{
+ UInt32 crc = CRC_INIT_VAL;;
+ for (UInt32 i = 0; i < size; i++)
+ crc = CRC_UPDATE_BYTE(crc, buf[i]);
+ return CRC_GET_DIGEST(crc);
+}
+
+static void RandGen(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)
+{
+ for (UInt32 i = 0; i < size; i++)
+ buf[i] = (Byte)RG.GetRnd();
+}
+
+static UInt32 RandGenCrc(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)
+{
+ RandGen(buf, size, RG);
+ return CrcCalc1(buf, size);
+}
+
+bool CrcInternalTest()
+{
+ CBenchBuffer buffer;
+ const UInt32 kBufferSize0 = (1 << 8);
+ const UInt32 kBufferSize1 = (1 << 10);
+ const UInt32 kCheckSize = (1 << 5);
+ if (!buffer.Alloc(kBufferSize0 + kBufferSize1))
+ return false;
+ Byte *buf = buffer.Buffer;
+ UInt32 i;
+ for (i = 0; i < kBufferSize0; i++)
+ buf[i] = (Byte)i;
+ UInt32 crc1 = CrcCalc1(buf, kBufferSize0);
+ if (crc1 != 0x29058C73)
+ return false;
+ CBaseRandomGenerator RG;
+ RandGen(buf + kBufferSize0, kBufferSize1, RG);
+ for (i = 0; i < kBufferSize0 + kBufferSize1 - kCheckSize; i++)
+ for (UInt32 j = 0; j < kCheckSize; j++)
+ if (CrcCalc1(buf + i, j) != CrcCalc(buf + i, j))
+ return false;
+ return true;
+}
+
+HRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed)
+{
+ if (numThreads == 0)
+ numThreads = 1;
+
+ CBenchBuffer buffer;
+ size_t totalSize = (size_t)bufferSize * numThreads;
+ if (totalSize / numThreads != bufferSize)
+ return E_OUTOFMEMORY;
+ if (!buffer.Alloc(totalSize))
+ return E_OUTOFMEMORY;
+
+ Byte *buf = buffer.Buffer;
+ CBaseRandomGenerator RG;
+ UInt32 numCycles = ((UInt32)1 << 30) / ((bufferSize >> 2) + 1) + 1;
+
+ UInt64 timeVal;
+ #ifdef BENCH_MT
+ CCrcThreads threads;
+ if (numThreads > 1)
+ {
+ threads.Items = new CCrcInfo[numThreads];
+ UInt32 i;
+ for (i = 0; i < numThreads; i++)
+ {
+ CCrcInfo &info = threads.Items[i];
+ Byte *data = buf + (size_t)bufferSize * i;
+ info.Data = data;
+ info.NumCycles = numCycles;
+ info.Size = bufferSize;
+ info.Crc = RandGenCrc(data, bufferSize, RG);
+ }
+ timeVal = GetTimeCount();
+ for (i = 0; i < numThreads; i++)
+ {
+ CCrcInfo &info = threads.Items[i];
+ RINOK(info.Thread.Create(CrcThreadFunction, &info));
+ threads.NumThreads++;
+ }
+ threads.WaitAll();
+ for (i = 0; i < numThreads; i++)
+ if (!threads.Items[i].Res)
+ return S_FALSE;
+ }
+ else
+ #endif
+ {
+ UInt32 crc = RandGenCrc(buf, bufferSize, RG);
+ timeVal = GetTimeCount();
+ if (!CrcBig(buf, bufferSize, numCycles, crc))
+ return S_FALSE;
+ }
+ timeVal = GetTimeCount() - timeVal;
+ if (timeVal == 0)
+ timeVal = 1;
+
+ UInt64 size = (UInt64)numCycles * totalSize;
+ speed = MyMultDiv64(size, timeVal, GetFreq());
+ return S_OK;
+}
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBench.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,48 @@
+// LzmaBench.h
+
+#ifndef __LZMABENCH_H
+#define __LZMABENCH_H
+
+#include <stdio.h>
+#include "../../../Common/Types.h"
+#ifdef EXTERNAL_LZMA
+#include "../../UI/Common/LoadCodecs.h"
+#endif
+
+struct CBenchInfo
+{
+ UInt64 GlobalTime;
+ UInt64 GlobalFreq;
+ UInt64 UserTime;
+ UInt64 UserFreq;
+ UInt64 UnpackSize;
+ UInt64 PackSize;
+ UInt32 NumIterations;
+ CBenchInfo(): NumIterations(0) {}
+};
+
+struct IBenchCallback
+{
+ virtual HRESULT SetEncodeResult(const CBenchInfo &info, bool final) = 0;
+ virtual HRESULT SetDecodeResult(const CBenchInfo &info, bool final) = 0;
+};
+
+UInt64 GetUsage(const CBenchInfo &benchOnfo);
+UInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating);
+UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size);
+UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations);
+
+HRESULT LzmaBench(
+ #ifdef EXTERNAL_LZMA
+ CCodecs *codecs,
+ #endif
+ UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback);
+
+const int kBenchMinDicLogSize = 18;
+
+UInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary);
+
+bool CrcInternalTest();
+HRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed);
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,311 @@
+// LzmaBenchCon.cpp
+
+#include "StdAfx.h"
+
+#include <stdio.h>
+
+#include "LzmaBench.h"
+#include "LzmaBenchCon.h"
+#include "../../../Common/IntToString.h"
+
+#if defined(BENCH_MT) || defined(_WIN32)
+#include "../../../Windows/System.h"
+#endif
+
+#ifdef BREAK_HANDLER
+#include "../../UI/Console/ConsoleClose.h"
+#endif
+#include "../../../Common/MyCom.h"
+
+struct CTotalBenchRes
+{
+ UInt64 NumIterations;
+ UInt64 Rating;
+ UInt64 Usage;
+ UInt64 RPU;
+ void Init() { NumIterations = 0; Rating = 0; Usage = 0; RPU = 0; }
+ void Normalize()
+ {
+ if (NumIterations == 0)
+ return;
+ Rating /= NumIterations;
+ Usage /= NumIterations;
+ RPU /= NumIterations;
+ NumIterations = 1;
+ }
+ void SetMid(const CTotalBenchRes &r1, const CTotalBenchRes &r2)
+ {
+ Rating = (r1.Rating + r2.Rating) / 2;
+ Usage = (r1.Usage + r2.Usage) / 2;
+ RPU = (r1.RPU + r2.RPU) / 2;
+ NumIterations = (r1.NumIterations + r2.NumIterations) / 2;
+ }
+};
+
+struct CBenchCallback: public IBenchCallback
+{
+ CTotalBenchRes EncodeRes;
+ CTotalBenchRes DecodeRes;
+ FILE *f;
+ void Init() { EncodeRes.Init(); DecodeRes.Init(); }
+ void Normalize() { EncodeRes.Normalize(); DecodeRes.Normalize(); }
+ UInt32 dictionarySize;
+ HRESULT SetEncodeResult(const CBenchInfo &info, bool final);
+ HRESULT SetDecodeResult(const CBenchInfo &info, bool final);
+};
+
+static void NormalizeVals(UInt64 &v1, UInt64 &v2)
+{
+ while (v1 > 1000000)
+ {
+ v1 >>= 1;
+ v2 >>= 1;
+ }
+}
+
+static UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)
+{
+ UInt64 elTime = elapsedTime;
+ NormalizeVals(freq, elTime);
+ if (elTime == 0)
+ elTime = 1;
+ return value * freq / elTime;
+}
+
+static void PrintNumber(FILE *f, UInt64 value, int size)
+{
+ char s[32];
+ ConvertUInt64ToString(value, s);
+ fprintf(f, " ");
+ for (int len = (int)strlen(s); len < size; len++)
+ fprintf(f, " ");
+ fprintf(f, "%s", s);
+}
+
+static void PrintRating(FILE *f, UInt64 rating)
+{
+ PrintNumber(f, rating / 1000000, 6);
+}
+
+static void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating)
+{
+ PrintNumber(f, (usage + 5000) / 10000, 5);
+ PrintRating(f, rpu);
+ PrintRating(f, rating);
+}
+
+
+static void PrintResults(FILE *f, const CBenchInfo &info, UInt64 rating, CTotalBenchRes &res)
+{
+ UInt64 speed = MyMultDiv64(info.UnpackSize, info.GlobalTime, info.GlobalFreq);
+ PrintNumber(f, speed / 1024, 7);
+ UInt64 usage = GetUsage(info);
+ UInt64 rpu = GetRatingPerUsage(info, rating);
+ PrintResults(f, usage, rpu, rating);
+ res.NumIterations++;
+ res.RPU += rpu;
+ res.Rating += rating;
+ res.Usage += usage;
+}
+
+static void PrintTotals(FILE *f, const CTotalBenchRes &res)
+{
+ fprintf(f, " ");
+ PrintResults(f, res.Usage, res.RPU, res.Rating);
+}
+
+
+HRESULT CBenchCallback::SetEncodeResult(const CBenchInfo &info, bool final)
+{
+ #ifdef BREAK_HANDLER
+ if (NConsoleClose::TestBreakSignal())
+ return E_ABORT;
+ #endif
+
+ if (final)
+ {
+ UInt64 rating = GetCompressRating(dictionarySize, info.GlobalTime, info.GlobalFreq, info.UnpackSize);
+ PrintResults(f, info, rating, EncodeRes);
+ }
+ return S_OK;
+}
+
+static const char *kSep = " | ";
+
+
+HRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final)
+{
+ #ifdef BREAK_HANDLER
+ if (NConsoleClose::TestBreakSignal())
+ return E_ABORT;
+ #endif
+ if (final)
+ {
+ UInt64 rating = GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations);
+ fprintf(f, kSep);
+ CBenchInfo info2 = info;
+ info2.UnpackSize *= info2.NumIterations;
+ info2.PackSize *= info2.NumIterations;
+ info2.NumIterations = 1;
+ PrintResults(f, info2, rating, DecodeRes);
+ }
+ return S_OK;
+}
+
+static void PrintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads)
+{
+ fprintf(f, "\nRAM %s ", sizeString);
+ PrintNumber(f, (size >> 20), 5);
+ fprintf(f, " MB, # %s %3d", threadsString, (unsigned int)numThreads);
+}
+
+HRESULT LzmaBenchCon(
+ #ifdef EXTERNAL_LZMA
+ CCodecs *codecs,
+ #endif
+ FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)
+{
+ if (!CrcInternalTest())
+ return S_FALSE;
+ #ifdef BENCH_MT
+ UInt64 ramSize = NWindows::NSystem::GetRamSize(); //
+ UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();
+ PrintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs);
+ if (numThreads == (UInt32)-1)
+ numThreads = numCPUs;
+ if (numThreads > 1)
+ numThreads &= ~1;
+ if (dictionary == (UInt32)-1)
+ {
+ int dicSizeLog;
+ for (dicSizeLog = 25; dicSizeLog > kBenchMinDicLogSize; dicSizeLog--)
+ if (GetBenchMemoryUsage(numThreads, ((UInt32)1 << dicSizeLog)) + (8 << 20) <= ramSize)
+ break;
+ dictionary = (1 << dicSizeLog);
+ }
+ #else
+ if (dictionary == (UInt32)-1)
+ dictionary = (1 << 22);
+ numThreads = 1;
+ #endif
+
+ PrintRequirements(f, "usage:", GetBenchMemoryUsage(numThreads, dictionary), "Benchmark threads: ", numThreads);
+
+ CBenchCallback callback;
+ callback.Init();
+ callback.f = f;
+
+ fprintf(f, "\n\nDict Compressing | Decompressing\n ");
+ int j;
+ for (j = 0; j < 2; j++)
+ {
+ fprintf(f, " Speed Usage R/U Rating");
+ if (j == 0)
+ fprintf(f, kSep);
+ }
+ fprintf(f, "\n ");
+ for (j = 0; j < 2; j++)
+ {
+ fprintf(f, " KB/s %% MIPS MIPS");
+ if (j == 0)
+ fprintf(f, kSep);
+ }
+ fprintf(f, "\n\n");
+ for (UInt32 i = 0; i < numIterations; i++)
+ {
+ const int kStartDicLog = 22;
+ int pow = (dictionary < ((UInt32)1 << kStartDicLog)) ? kBenchMinDicLogSize : kStartDicLog;
+ while (((UInt32)1 << pow) > dictionary)
+ pow--;
+ for (; ((UInt32)1 << pow) <= dictionary; pow++)
+ {
+ fprintf(f, "%2d:", pow);
+ callback.dictionarySize = (UInt32)1 << pow;
+ HRESULT res = LzmaBench(
+ #ifdef EXTERNAL_LZMA
+ codecs,
+ #endif
+ numThreads, callback.dictionarySize, &callback);
+ fprintf(f, "\n");
+ RINOK(res);
+ }
+ }
+ callback.Normalize();
+ fprintf(f, "----------------------------------------------------------------\nAvr:");
+ PrintTotals(f, callback.EncodeRes);
+ fprintf(f, " ");
+ PrintTotals(f, callback.DecodeRes);
+ fprintf(f, "\nTot:");
+ CTotalBenchRes midRes;
+ midRes.SetMid(callback.EncodeRes, callback.DecodeRes);
+ PrintTotals(f, midRes);
+ fprintf(f, "\n");
+ return S_OK;
+}
+
+struct CTempValues
+{
+ UInt64 *Values;
+ CTempValues(UInt32 num) { Values = new UInt64[num]; }
+ ~CTempValues() { delete []Values; }
+};
+
+HRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)
+{
+ if (!CrcInternalTest())
+ return S_FALSE;
+
+ #ifdef BENCH_MT
+ UInt64 ramSize = NWindows::NSystem::GetRamSize();
+ UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();
+ PrintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs);
+ if (numThreads == (UInt32)-1)
+ numThreads = numCPUs;
+ #else
+ numThreads = 1;
+ #endif
+ if (dictionary == (UInt32)-1)
+ dictionary = (1 << 24);
+
+ CTempValues speedTotals(numThreads);
+ fprintf(f, "\n\nSize");
+ for (UInt32 ti = 0; ti < numThreads; ti++)
+ {
+ fprintf(f, " %5d", ti + 1);
+ speedTotals.Values[ti] = 0;
+ }
+ fprintf(f, "\n\n");
+
+ UInt64 numSteps = 0;
+ for (UInt32 i = 0; i < numIterations; i++)
+ {
+ for (int pow = 10; pow < 32; pow++)
+ {
+ UInt32 bufSize = (UInt32)1 << pow;
+ if (bufSize > dictionary)
+ break;
+ fprintf(f, "%2d: ", pow);
+ UInt64 speed;
+ for (UInt32 ti = 0; ti < numThreads; ti++)
+ {
+ #ifdef BREAK_HANDLER
+ if (NConsoleClose::TestBreakSignal())
+ return E_ABORT;
+ #endif
+ RINOK(CrcBench(ti + 1, bufSize, speed));
+ PrintNumber(f, (speed >> 20), 5);
+ speedTotals.Values[ti] += speed;
+ }
+ fprintf(f, "\n");
+ numSteps++;
+ }
+ }
+ if (numSteps != 0)
+ {
+ fprintf(f, "\nAvg:");
+ for (UInt32 ti = 0; ti < numThreads; ti++)
+ PrintNumber(f, ((speedTotals.Values[ti] / numSteps) >> 20), 5);
+ fprintf(f, "\n");
+ }
+ return S_OK;
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/LzmaBenchCon.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,20 @@
+// LzmaBenchCon.h
+
+#ifndef __LZMABENCHCON_H
+#define __LZMABENCHCON_H
+
+#include <stdio.h>
+#include "../../../Common/Types.h"
+#ifdef EXTERNAL_LZMA
+#include "../../UI/Common/LoadCodecs.h"
+#endif
+HRESULT LzmaBenchCon(
+ #ifdef EXTERNAL_LZMA
+ CCodecs *codecs,
+ #endif
+ FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);
+
+HRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);
+
+#endif
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/makefile
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/makefile?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/makefile (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LZMA_Alone/makefile Sun Dec 16 23:23:25 2012
@@ -0,0 +1,173 @@
+include ../../../../makefile.machine
+
+PROG = lzma
+LIB = $(LOCAL_LIBS)
+RM = rm -f
+CFLAGS = -c -I. -I../../../ -I../../../myWindows -I../../../include_windows \
+ -UENV_UNIX -DCOMPRESS_MF_MT -DBENCH_MT
+
+CXXFLAGS=$(CFLAGS)
+
+OBJS = \
+ LzmaAlone.o \
+ LzmaBench.o \
+ LzmaBenchCon.o \
+ LzmaDecoder.o \
+ LzmaEncoder.o \
+ CWrappers.o \
+ InBuffer.o \
+ OutBuffer.o \
+ FileStreams.o \
+ StreamUtils.o \
+ C_FileIO.o \
+ CommandLineParser.o \
+ CRC.o \
+ IntToString.o \
+ MyString.o \
+ StringConvert.o \
+ UTFConvert.o \
+ StringToInt.o \
+ MyVector.o \
+ 7zCrc.o \
+ 7zCrcOpt.o \
+ Alloc.o \
+ Bra86.o \
+ LzFind.o \
+ LzFindMt.o \
+ LzmaDec.o \
+ LzmaEnc.o \
+ Lzma86Dec.o \
+ Lzma86Enc.o \
+ System.o \
+ Threads.o
+
+all: $(PROG)
+
+$(PROG): $(OBJS)
+ $(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB)
+
+LzmaAlone.o: LzmaAlone.cpp
+ $(CXX) $(CXXFLAGS) LzmaAlone.cpp
+
+LzmaBench.o: LzmaBench.cpp
+ $(CXX) $(CXXFLAGS) LzmaBench.cpp
+
+LzmaBenchCon.o: LzmaBenchCon.cpp
+ $(CXX) $(CXXFLAGS) LzmaBenchCon.cpp
+
+LzmaRam.o: LzmaRam.cpp
+ $(CXX) $(CXXFLAGS) LzmaRam.cpp
+
+LzmaDecoder.o: ../LzmaDecoder.cpp
+ $(CXX) $(CXXFLAGS) ../LzmaDecoder.cpp
+
+LzmaEncoder.o: ../LzmaEncoder.cpp
+ $(CXX) $(CXXFLAGS) ../LzmaEncoder.cpp
+
+RangeCoderBit.o: ../RangeCoderBit.cpp
+ $(CXX) $(CXXFLAGS) ../RangeCoderBit.cpp
+
+CWrappers.o: ../../Common/CWrappers.cpp
+ $(CXX) $(CXXFLAGS) ../../Common/CWrappers.cpp
+
+InBuffer.o: ../../Common/InBuffer.cpp
+ $(CXX) $(CXXFLAGS) ../../Common/InBuffer.cpp
+
+OutBuffer.o: ../../Common/OutBuffer.cpp
+ $(CXX) $(CXXFLAGS) ../../Common/OutBuffer.cpp
+
+FileStreams.o: ../../Common/FileStreams.cpp
+ $(CXX) $(CXXFLAGS) ../../Common/FileStreams.cpp
+
+StreamUtils.o: ../../Common/StreamUtils.cpp
+ $(CXX) $(CXXFLAGS) ../../Common/StreamUtils.cpp
+
+C_FileIO.o: ../../../Common/C_FileIO.cpp
+ $(CXX) $(CXXFLAGS) ../../../Common/C_FileIO.cpp
+
+CommandLineParser.o: ../../../Common/CommandLineParser.cpp
+ $(CXX) $(CXXFLAGS) ../../../Common/CommandLineParser.cpp
+
+CRC.o: ../../../Common/CRC.cpp
+ $(CXX) $(CXXFLAGS) ../../../Common/CRC.cpp
+
+MyWindows.o: ../../../Common/MyWindows.cpp
+ $(CXX) $(CXXFLAGS) ../../../Common/MyWindows.cpp
+
+IntToString.o: ../../../Common/IntToString.cpp
+ $(CXX) $(CXXFLAGS) ../../../Common/IntToString.cpp
+
+MyString.o: ../../../Common/MyString.cpp
+ $(CXX) $(CXXFLAGS) ../../../Common/MyString.cpp
+
+StringConvert.o: ../../../Common/StringConvert.cpp
+ $(CXX) $(CXXFLAGS) ../../../Common/StringConvert.cpp
+
+UTFConvert.o: ../../../Common/UTFConvert.cpp
+ $(CXX) $(CXXFLAGS) ../../../Common/UTFConvert.cpp
+
+StringToInt.o: ../../../Common/StringToInt.cpp
+ $(CXX) $(CXXFLAGS) ../../../Common/StringToInt.cpp
+
+MyVector.o: ../../../Common/MyVector.cpp
+ $(CXX) $(CXXFLAGS) ../../../Common/MyVector.cpp
+
+7zCrc.o: ../../../../C/7zCrc.c
+ $(CC) $(CFLAGS) ../../../../C/7zCrc.c
+
+7zCrcOpt.o: ../../../../C/7zCrcOpt.c
+ $(CC) $(CFLAGS) ../../../../C/7zCrcOpt.c
+
+LzmaRamDecode.o: LzmaRamDecode.c
+ $(CC) $(CFLAGS) LzmaRamDecode.c
+
+System.o : ../../../Windows/System.cpp
+ $(CXX) $(CXXFLAGS) ../../../Windows/System.cpp
+
+Threads.o : ../../../../C/Threads.c
+ $(CC) $(CFLAGS) ../../../../C/Threads.c
+
+Alloc.o: ../../../../C/Alloc.c
+ $(CC) $(CFLAGS) ../../../../C/Alloc.c
+
+Bra86.o: ../../../../C/Bra86.c
+ $(CC) $(CFLAGS) ../../../../C/Bra86.c
+
+LzFind.o: ../../../../C/LzFind.c
+ $(CC) $(CFLAGS) ../../../../C/LzFind.c
+
+LzFindMt.o: ../../../../C/LzFindMt.c
+ $(CC) $(CFLAGS) ../../../../C/LzFindMt.c
+
+LzmaDec.o: ../../../../C/LzmaDec.c
+ $(CC) $(CFLAGS) ../../../../C/LzmaDec.c
+
+LzmaEnc.o: ../../../../C/LzmaEnc.c
+ $(CC) $(CFLAGS) ../../../../C/LzmaEnc.c
+
+Lzma86Dec.o: ../../../../C/LzmaUtil/Lzma86Dec.c
+ $(CC) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Dec.c
+
+Lzma86Enc.o: ../../../../C/LzmaUtil/Lzma86Enc.c
+ $(CC) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Enc.c
+
+clean:
+ -$(RM) $(PROG) $(OBJS) testfile* *.exe ir.out
+ -$(RM) -fr SunWS_cache
+
+test: $(PROG)
+ cp LzmaAlone.cpp testfile
+ ./$(PROG) e testfile testfile.lzma
+ ./$(PROG) d testfile.lzma testfile.lzma.d
+ diff -s testfile testfile.lzma.d
+ ./$(PROG) e testfile testfile.lzma
+ ./$(PROG) d testfile.lzma testfile.lzma.d
+ diff -s testfile testfile.lzma.d
+ ./$(PROG) e -si -so < testfile > testfile.lzma.2
+ ./$(PROG) d -si -so < testfile.lzma.2 > testfile.lzma.2.d
+ diff -s testfile testfile.lzma.2.d
+ @echo =========
+ @echo All Done
+ @echo =========
+
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzOutWindow.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzOutWindow.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzOutWindow.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzOutWindow.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,14 @@
+// LzOutWindow.cpp
+
+#include "StdAfx.h"
+
+#include "LzOutWindow.h"
+
+void CLzOutWindow::Init(bool solid)
+{
+ if (!solid)
+ COutBuffer::Init();
+ #ifdef _NO_EXCEPTIONS
+ ErrorCode = S_OK;
+ #endif
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzOutWindow.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzOutWindow.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzOutWindow.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzOutWindow.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,66 @@
+// LzOutWindow.h
+
+#ifndef __LZ_OUT_WINDOW_H
+#define __LZ_OUT_WINDOW_H
+
+#include "../IStream.h"
+
+#include "../Common/OutBuffer.h"
+
+#ifndef _NO_EXCEPTIONS
+typedef COutBufferException CLzOutWindowException;
+#endif
+
+class CLzOutWindow: public COutBuffer
+{
+public:
+ void Init(bool solid = false);
+
+ // distance >= 0, len > 0,
+ bool CopyBlock(UInt32 distance, UInt32 len)
+ {
+ UInt32 pos = _pos - distance - 1;
+ if (distance >= _pos)
+ {
+ if (!_overDict || distance >= _bufferSize)
+ return false;
+ pos += _bufferSize;
+ }
+ if (_limitPos - _pos > len && _bufferSize - pos > len)
+ {
+ const Byte *src = _buffer + pos;
+ Byte *dest = _buffer + _pos;
+ _pos += len;
+ do
+ *dest++ = *src++;
+ while(--len != 0);
+ }
+ else do
+ {
+ if (pos == _bufferSize)
+ pos = 0;
+ _buffer[_pos++] = _buffer[pos++];
+ if (_pos == _limitPos)
+ FlushWithCheck();
+ }
+ while(--len != 0);
+ return true;
+ }
+
+ void PutByte(Byte b)
+ {
+ _buffer[_pos++] = b;
+ if (_pos == _limitPos)
+ FlushWithCheck();
+ }
+
+ Byte GetByte(UInt32 distance) const
+ {
+ UInt32 pos = _pos - distance - 1;
+ if (pos >= _bufferSize)
+ pos += _bufferSize;
+ return _buffer[pos];
+ }
+};
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzhDecoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzhDecoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzhDecoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzhDecoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,220 @@
+// LzhDecoder.cpp
+
+#include "StdAfx.h"
+
+#include "LzhDecoder.h"
+
+#include "Windows/Defs.h"
+
+namespace NCompress{
+namespace NLzh {
+namespace NDecoder {
+
+static const UInt32 kHistorySize = (1 << 16);
+
+static const int kBlockSizeBits = 16;
+static const int kNumCBits = 9;
+static const int kNumLevelBits = 5; // smallest integer such that (1 << kNumLevelBits) > kNumLevelSymbols/
+
+UInt32 CCoder::ReadBits(int numBits) { return m_InBitStream.ReadBits(numBits); }
+
+HRESULT CCoder::ReadLevelTable()
+{
+ int n = ReadBits(kNumLevelBits);
+ if (n == 0)
+ {
+ m_LevelHuffman.Symbol = ReadBits(kNumLevelBits);
+ if (m_LevelHuffman.Symbol >= kNumLevelSymbols)
+ return S_FALSE;
+ }
+ else
+ {
+ if (n > kNumLevelSymbols)
+ return S_FALSE;
+ m_LevelHuffman.Symbol = -1;
+ Byte lens[kNumLevelSymbols];
+ int i = 0;
+ while (i < n)
+ {
+ int c = m_InBitStream.ReadBits(3);
+ if (c == 7)
+ while (ReadBits(1))
+ if (c++ > kMaxHuffmanLen)
+ return S_FALSE;
+ lens[i++] = (Byte)c;
+ if (i == kNumSpecLevelSymbols)
+ {
+ c = ReadBits(2);
+ while (--c >= 0)
+ lens[i++] = 0;
+ }
+ }
+ while (i < kNumLevelSymbols)
+ lens[i++] = 0;
+ m_LevelHuffman.SetCodeLengths(lens);
+ }
+ return S_OK;
+}
+
+HRESULT CCoder::ReadPTable(int numBits)
+{
+ int n = ReadBits(numBits);
+ if (n == 0)
+ {
+ m_PHuffmanDecoder.Symbol = ReadBits(numBits);
+ if (m_PHuffmanDecoder.Symbol >= kNumDistanceSymbols)
+ return S_FALSE;
+ }
+ else
+ {
+ if (n > kNumDistanceSymbols)
+ return S_FALSE;
+ m_PHuffmanDecoder.Symbol = -1;
+ Byte lens[kNumDistanceSymbols];
+ int i = 0;
+ while (i < n)
+ {
+ int c = m_InBitStream.ReadBits(3);
+ if (c == 7)
+ while (ReadBits(1))
+ {
+ if (c > kMaxHuffmanLen)
+ return S_FALSE;
+ c++;
+ }
+ lens[i++] = (Byte)c;
+ }
+ while (i < kNumDistanceSymbols)
+ lens[i++] = 0;
+ m_PHuffmanDecoder.SetCodeLengths(lens);
+ }
+ return S_OK;
+}
+
+HRESULT CCoder::ReadCTable()
+{
+ int n = ReadBits(kNumCBits);
+ if (n == 0)
+ {
+ m_CHuffmanDecoder.Symbol = ReadBits(kNumCBits);
+ if (m_CHuffmanDecoder.Symbol >= kNumCSymbols)
+ return S_FALSE;
+ }
+ else
+ {
+ if (n > kNumCSymbols)
+ return S_FALSE;
+ m_CHuffmanDecoder.Symbol = -1;
+ Byte lens[kNumCSymbols];
+ int i = 0;
+ while (i < n)
+ {
+ int c = m_LevelHuffman.Decode(&m_InBitStream);
+ if (c < kNumSpecLevelSymbols)
+ {
+ if (c == 0)
+ c = 1;
+ else if (c == 1)
+ c = ReadBits(4) + 3;
+ else
+ c = ReadBits(kNumCBits) + 20;
+ while (--c >= 0)
+ {
+ if (i > kNumCSymbols)
+ return S_FALSE;
+ lens[i++] = 0;
+ }
+ }
+ else
+ lens[i++] = (Byte)(c - 2);
+ }
+ while (i < kNumCSymbols)
+ lens[i++] = 0;
+ m_CHuffmanDecoder.SetCodeLengths(lens);
+ }
+ return S_OK;
+}
+
+STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
+ ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize,
+ ICompressProgressInfo *progress)
+{
+ if (outSize == NULL)
+ return E_INVALIDARG;
+
+ if (!m_OutWindowStream.Create(kHistorySize))
+ return E_OUTOFMEMORY;
+ if (!m_InBitStream.Create(1 << 20))
+ return E_OUTOFMEMORY;
+
+ UInt64 pos = 0;
+ m_OutWindowStream.SetStream(outStream);
+ m_OutWindowStream.Init(false);
+ m_InBitStream.SetStream(inStream);
+ m_InBitStream.Init();
+
+ CCoderReleaser coderReleaser(this);
+
+ int pbit;
+ if (m_NumDictBits <= 13)
+ pbit = 4;
+ else
+ pbit = 5;
+
+ UInt32 blockSize = 0;
+
+ while(pos < *outSize)
+ {
+ // for (i = 0; i < dictSize; i++) dtext[i] = 0x20;
+
+ if (blockSize == 0)
+ {
+ if (progress != NULL)
+ {
+ UInt64 packSize = m_InBitStream.GetProcessedSize();
+ RINOK(progress->SetRatioInfo(&packSize, &pos));
+ }
+ blockSize = ReadBits(kBlockSizeBits);
+ ReadLevelTable();
+ ReadCTable();
+ RINOK(ReadPTable(pbit));
+ }
+ blockSize--;
+ UInt32 c = m_CHuffmanDecoder.Decode(&m_InBitStream);
+ if (c < 256)
+ {
+ m_OutWindowStream.PutByte((Byte)c);
+ pos++;
+ }
+ else if (c >= kNumCSymbols)
+ return S_FALSE;
+ else
+ {
+ // offset = (interface->method == LARC_METHOD_NUM) ? 0x100 - 2 : 0x100 - 3;
+ UInt32 len = c - 256 + kMinMatch;
+ UInt32 distance = m_PHuffmanDecoder.Decode(&m_InBitStream);
+ if (distance != 0)
+ distance = (1 << (distance - 1)) + ReadBits(distance - 1);
+ if (distance >= pos)
+ return S_FALSE;
+ if (pos + len > *outSize)
+ len = (UInt32)(*outSize - pos);
+ pos += len;
+ m_OutWindowStream.CopyBlock(distance, len);
+ }
+ }
+ coderReleaser.NeedFlush = false;
+ return m_OutWindowStream.Flush();
+}
+
+STDMETHODIMP CCoder::Code(ISequentialInStream *inStream,
+ ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
+ ICompressProgressInfo *progress)
+{
+ try { return CodeReal(inStream, outStream, inSize, outSize, progress);}
+ catch(const CInBufferException &e) { return e.ErrorCode; }
+ catch(const CLzOutWindowException &e) { return e.ErrorCode; }
+ catch(...) { return S_FALSE; }
+}
+
+}}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzhDecoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzhDecoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzhDecoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzhDecoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,106 @@
+// LzhDecoder.h
+
+#ifndef __COMPRESS_LZH_DECODER_H
+#define __COMPRESS_LZH_DECODER_H
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+#include "../Common/InBuffer.h"
+
+#include "BitmDecoder.h"
+#include "HuffmanDecoder.h"
+#include "LzOutWindow.h"
+
+namespace NCompress {
+namespace NLzh {
+namespace NDecoder {
+
+const int kMaxHuffmanLen = 16; // Check it
+
+const int kNumSpecLevelSymbols = 3;
+const int kNumLevelSymbols = kNumSpecLevelSymbols + kMaxHuffmanLen;
+
+const int kDictBitsMax = 16;
+const int kNumDistanceSymbols = kDictBitsMax + 1;
+
+const int kMaxMatch = 256;
+const int kMinMatch = 3;
+const int kNumCSymbols = 256 + kMaxMatch + 2 - kMinMatch;
+
+template <UInt32 m_NumSymbols>
+class CHuffmanDecoder:public NCompress::NHuffman::CDecoder<kMaxHuffmanLen, m_NumSymbols>
+{
+public:
+ int Symbol;
+ template <class TBitDecoder>
+ UInt32 Decode(TBitDecoder *bitStream)
+ {
+ if (Symbol >= 0)
+ return (UInt32)Symbol;
+ return this->DecodeSymbol(bitStream);
+ }
+};
+
+class CCoder :
+ public ICompressCoder,
+ public CMyUnknownImp
+{
+ CLzOutWindow m_OutWindowStream;
+ NBitm::CDecoder<CInBuffer> m_InBitStream;
+
+ int m_NumDictBits;
+
+ CHuffmanDecoder<kNumLevelSymbols> m_LevelHuffman;
+ CHuffmanDecoder<kNumDistanceSymbols> m_PHuffmanDecoder;
+ CHuffmanDecoder<kNumCSymbols> m_CHuffmanDecoder;
+
+ void ReleaseStreams()
+ {
+ m_OutWindowStream.ReleaseStream();
+ m_InBitStream.ReleaseStream();
+ }
+
+ class CCoderReleaser
+ {
+ CCoder *m_Coder;
+ public:
+ bool NeedFlush;
+ CCoderReleaser(CCoder *coder): m_Coder(coder), NeedFlush(true) {}
+ ~CCoderReleaser()
+ {
+ if (NeedFlush)
+ m_Coder->m_OutWindowStream.Flush();
+ m_Coder->ReleaseStreams();
+ }
+ };
+ friend class CCoderReleaser;
+
+ void MakeTable(int nchar, Byte *bitlen, int tablebits,
+ UInt32 *table, int tablesize);
+
+ UInt32 ReadBits(int numBits);
+ HRESULT ReadLevelTable();
+ HRESULT ReadPTable(int numBits);
+ HRESULT ReadCTable();
+
+public:
+
+ MY_UNKNOWN_IMP
+
+ STDMETHOD(CodeReal)(ISequentialInStream *inStream,
+ ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
+ ICompressProgressInfo *progress);
+
+ STDMETHOD(Code)(ISequentialInStream *inStream,
+ ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
+ ICompressProgressInfo *progress);
+
+ void SetDictionary(int numDictBits) { m_NumDictBits = numDictBits; }
+ CCoder(): m_NumDictBits(0) {}
+};
+
+}}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Decoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Decoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Decoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Decoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,189 @@
+// Lzma2Decoder.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/Alloc.h"
+
+#include "../Common/StreamUtils.h"
+
+#include "Lzma2Decoder.h"
+
+static HRESULT SResToHRESULT(SRes res)
+{
+ switch(res)
+ {
+ case SZ_OK: return S_OK;
+ case SZ_ERROR_MEM: return E_OUTOFMEMORY;
+ case SZ_ERROR_PARAM: return E_INVALIDARG;
+ // case SZ_ERROR_PROGRESS: return E_ABORT;
+ case SZ_ERROR_DATA: return S_FALSE;
+ }
+ return E_FAIL;
+}
+
+namespace NCompress {
+namespace NLzma2 {
+
+static const UInt32 kInBufSize = 1 << 20;
+
+CDecoder::CDecoder(): _inBuf(0), _outSizeDefined(false)
+{
+ Lzma2Dec_Construct(&_state);
+}
+
+static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
+static void SzFree(void *p, void *address) { p = p; MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
+
+CDecoder::~CDecoder()
+{
+ Lzma2Dec_Free(&_state, &g_Alloc);
+ MyFree(_inBuf);
+}
+
+STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *prop, UInt32 size)
+{
+ if (size != 1) return SZ_ERROR_UNSUPPORTED;
+ RINOK(SResToHRESULT(Lzma2Dec_Allocate(&_state, prop[0], &g_Alloc)));
+ if (_inBuf == 0)
+ {
+ _inBuf = (Byte *)MyAlloc(kInBufSize);
+ if (_inBuf == 0)
+ return E_OUTOFMEMORY;
+ }
+
+ return S_OK;
+}
+
+STDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value) { *value = _inSizeProcessed; return S_OK; }
+STDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream) { _inStream = inStream; return S_OK; }
+STDMETHODIMP CDecoder::ReleaseInStream() { _inStream.Release(); return S_OK; }
+
+STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)
+{
+ _outSizeDefined = (outSize != NULL);
+ if (_outSizeDefined)
+ _outSize = *outSize;
+
+ Lzma2Dec_Init(&_state);
+
+ _inPos = _inSize = 0;
+ _inSizeProcessed = _outSizeProcessed = 0;
+ return S_OK;
+}
+
+STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
+ ISequentialOutStream *outStream, const UInt64 * /* inSize */,
+ const UInt64 *outSize, ICompressProgressInfo *progress)
+{
+ if (_inBuf == 0)
+ return S_FALSE;
+ SetOutStreamSize(outSize);
+
+ for (;;)
+ {
+ if (_inPos == _inSize)
+ {
+ _inPos = _inSize = 0;
+ RINOK(inStream->Read(_inBuf, kInBufSize, &_inSize));
+ }
+
+ SizeT dicPos = _state.decoder.dicPos;
+ SizeT curSize = _state.decoder.dicBufSize - dicPos;
+ const UInt32 kStepSize = ((UInt32)1 << 22);
+ if (curSize > kStepSize)
+ curSize = (SizeT)kStepSize;
+
+ ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
+ if (_outSizeDefined)
+ {
+ const UInt64 rem = _outSize - _outSizeProcessed;
+ if (rem < curSize)
+ {
+ curSize = (SizeT)rem;
+ /*
+ // finishMode = LZMA_FINISH_END;
+ we can't use LZMA_FINISH_END here to allow partial decoding
+ */
+ }
+ }
+
+ SizeT inSizeProcessed = _inSize - _inPos;
+ ELzmaStatus status;
+ SRes res = Lzma2Dec_DecodeToDic(&_state, dicPos + curSize, _inBuf + _inPos, &inSizeProcessed, finishMode, &status);
+
+ _inPos += (UInt32)inSizeProcessed;
+ _inSizeProcessed += inSizeProcessed;
+ SizeT outSizeProcessed = _state.decoder.dicPos - dicPos;
+ _outSizeProcessed += outSizeProcessed;
+
+ bool finished = (inSizeProcessed == 0 && outSizeProcessed == 0);
+ bool stopDecoding = (_outSizeDefined && _outSizeProcessed >= _outSize);
+
+ if (res != 0 || _state.decoder.dicPos == _state.decoder.dicBufSize || finished || stopDecoding)
+ {
+ HRESULT res2 = WriteStream(outStream, _state.decoder.dic, _state.decoder.dicPos);
+ if (res != 0)
+ return S_FALSE;
+ RINOK(res2);
+ if (stopDecoding)
+ return S_OK;
+ if (finished)
+ return (status == LZMA_STATUS_FINISHED_WITH_MARK ? S_OK : S_FALSE);
+ }
+ if (_state.decoder.dicPos == _state.decoder.dicBufSize)
+ _state.decoder.dicPos = 0;
+
+ if (progress != NULL)
+ {
+ RINOK(progress->SetRatioInfo(&_inSizeProcessed, &_outSizeProcessed));
+ }
+ }
+}
+
+#ifndef NO_READ_FROM_CODER
+
+STDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)
+{
+ if (processedSize)
+ *processedSize = 0;
+ do
+ {
+ if (_inPos == _inSize)
+ {
+ _inPos = _inSize = 0;
+ RINOK(_inStream->Read(_inBuf, kInBufSize, &_inSize));
+ }
+ {
+ SizeT inProcessed = _inSize - _inPos;
+
+ if (_outSizeDefined)
+ {
+ const UInt64 rem = _outSize - _outSizeProcessed;
+ if (rem < size)
+ size = (UInt32)rem;
+ }
+
+ SizeT outProcessed = size;
+ ELzmaStatus status;
+ SRes res = Lzma2Dec_DecodeToBuf(&_state, (Byte *)data, &outProcessed,
+ _inBuf + _inPos, &inProcessed, LZMA_FINISH_ANY, &status);
+ _inPos += (UInt32)inProcessed;
+ _inSizeProcessed += inProcessed;
+ _outSizeProcessed += outProcessed;
+ size -= (UInt32)outProcessed;
+ data = (Byte *)data + outProcessed;
+ if (processedSize)
+ *processedSize += (UInt32)outProcessed;
+ RINOK(SResToHRESULT(res));
+ if (inProcessed == 0 && outProcessed == 0)
+ return S_OK;
+ }
+ }
+ while (size != 0);
+ return S_OK;
+}
+
+#endif
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Decoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Decoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Decoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Decoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,73 @@
+// Lzma2Decoder.h
+
+#ifndef __LZMA2_DECODER_H
+#define __LZMA2_DECODER_H
+
+#include "../../../C/Lzma2Dec.h"
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+namespace NCompress {
+namespace NLzma2 {
+
+class CDecoder:
+ public ICompressCoder,
+ public ICompressSetDecoderProperties2,
+ public ICompressGetInStreamProcessedSize,
+ #ifndef NO_READ_FROM_CODER
+ public ICompressSetInStream,
+ public ICompressSetOutStreamSize,
+ public ISequentialInStream,
+ #endif
+ public CMyUnknownImp
+{
+ CMyComPtr<ISequentialInStream> _inStream;
+ Byte *_inBuf;
+ UInt32 _inPos;
+ UInt32 _inSize;
+ CLzma2Dec _state;
+ bool _outSizeDefined;
+ UInt64 _outSize;
+ UInt64 _inSizeProcessed;
+ UInt64 _outSizeProcessed;
+public:
+
+ #ifndef NO_READ_FROM_CODER
+ MY_UNKNOWN_IMP5(
+ ICompressSetDecoderProperties2,
+ ICompressGetInStreamProcessedSize,
+ ICompressSetInStream,
+ ICompressSetOutStreamSize,
+ ISequentialInStream)
+ #else
+ MY_UNKNOWN_IMP2(
+ ICompressSetDecoderProperties2,
+ ICompressGetInStreamProcessedSize)
+ #endif
+
+ STDMETHOD(Code)(ISequentialInStream *inStream,
+ ISequentialOutStream *outStream, const UInt64 *_inSize, const UInt64 *outSize,
+ ICompressProgressInfo *progress);
+
+ STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
+
+ STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);
+
+ STDMETHOD(SetInStream)(ISequentialInStream *inStream);
+ STDMETHOD(ReleaseInStream)();
+ STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);
+
+ #ifndef NO_READ_FROM_CODER
+ STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
+ #endif
+
+ CDecoder();
+ virtual ~CDecoder();
+
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Encoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Encoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Encoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Encoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,94 @@
+// Lzma2Encoder.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/Alloc.h"
+
+#include "../Common/CWrappers.h"
+#include "../Common/StreamUtils.h"
+
+#include "Lzma2Encoder.h"
+
+namespace NCompress {
+
+namespace NLzma {
+
+HRESULT SetLzmaProp(PROPID propID, const PROPVARIANT &prop, CLzmaEncProps &ep);
+
+}
+
+namespace NLzma2 {
+
+static void *SzBigAlloc(void *, size_t size) { return BigAlloc(size); }
+static void SzBigFree(void *, void *address) { BigFree(address); }
+static ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };
+
+static void *SzAlloc(void *, size_t size) { return MyAlloc(size); }
+static void SzFree(void *, void *address) { MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
+
+CEncoder::CEncoder()
+{
+ _encoder = 0;
+ _encoder = Lzma2Enc_Create(&g_Alloc, &g_BigAlloc);
+ if (_encoder == 0)
+ throw 1;
+}
+
+CEncoder::~CEncoder()
+{
+ if (_encoder != 0)
+ Lzma2Enc_Destroy(_encoder);
+}
+
+HRESULT SetLzma2Prop(PROPID propID, const PROPVARIANT &prop, CLzma2EncProps &lzma2Props)
+{
+ switch (propID)
+ {
+ case NCoderPropID::kBlockSize:
+ if (prop.vt != VT_UI4) return E_INVALIDARG; lzma2Props.blockSize = prop.ulVal; break;
+ case NCoderPropID::kNumThreads:
+ if (prop.vt != VT_UI4) return E_INVALIDARG; lzma2Props.numTotalThreads = (int)(prop.ulVal); break;
+ default:
+ RINOK(NLzma::SetLzmaProp(propID, prop, lzma2Props.lzmaProps));
+ }
+ return S_OK;
+}
+
+STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
+ const PROPVARIANT *coderProps, UInt32 numProps)
+{
+ CLzma2EncProps lzma2Props;
+ Lzma2EncProps_Init(&lzma2Props);
+
+ for (UInt32 i = 0; i < numProps; i++)
+ {
+ RINOK(SetLzma2Prop(propIDs[i], coderProps[i], lzma2Props));
+ }
+ return SResToHRESULT(Lzma2Enc_SetProps(_encoder, &lzma2Props));
+}
+
+STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
+{
+ Byte prop = Lzma2Enc_WriteProperties(_encoder);
+ return WriteStream(outStream, &prop, 1);
+}
+
+STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)
+{
+ CSeqInStreamWrap inWrap(inStream);
+ CSeqOutStreamWrap outWrap(outStream);
+ CCompressProgressWrap progressWrap(progress);
+
+ SRes res = Lzma2Enc_Encode(_encoder, &outWrap.p, &inWrap.p, progress ? &progressWrap.p : NULL);
+ if (res == SZ_ERROR_READ && inWrap.Res != S_OK)
+ return inWrap.Res;
+ if (res == SZ_ERROR_WRITE && outWrap.Res != S_OK)
+ return outWrap.Res;
+ if (res == SZ_ERROR_PROGRESS && progressWrap.Res != S_OK)
+ return progressWrap.Res;
+ return SResToHRESULT(res);
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Encoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Encoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Encoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Encoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,36 @@
+// Lzma2Encoder.h
+
+#ifndef __LZMA2_ENCODER_H
+#define __LZMA2_ENCODER_H
+
+#include "../../../C/Lzma2Enc.h"
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+namespace NCompress {
+namespace NLzma2 {
+
+class CEncoder:
+ public ICompressCoder,
+ public ICompressSetCoderProperties,
+ public ICompressWriteCoderProperties,
+ public CMyUnknownImp
+{
+ CLzma2EncHandle _encoder;
+public:
+ MY_UNKNOWN_IMP2(ICompressSetCoderProperties, ICompressWriteCoderProperties)
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+ STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);
+ STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
+
+ CEncoder();
+ virtual ~CEncoder();
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Register.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Register.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Register.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzma2Register.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,20 @@
+// Lzma2Register.cpp
+
+#include "StdAfx.h"
+
+#include "../Common/RegisterCodec.h"
+
+#include "Lzma2Decoder.h"
+
+static void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NLzma2::CDecoder); }
+#ifndef EXTRACT_ONLY
+#include "Lzma2Encoder.h"
+static void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NLzma2::CEncoder); }
+#else
+#define CreateCodecOut 0
+#endif
+
+static CCodecInfo g_CodecInfo =
+ { CreateCodec, CreateCodecOut, 0x21, L"LZMA2", 1, false };
+
+REGISTER_CODEC(LZMA2)
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaDecoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaDecoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaDecoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaDecoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,252 @@
+// LzmaDecoder.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/Alloc.h"
+
+#include "../Common/StreamUtils.h"
+
+#include "LzmaDecoder.h"
+
+static HRESULT SResToHRESULT(SRes res)
+{
+ switch(res)
+ {
+ case SZ_OK: return S_OK;
+ case SZ_ERROR_MEM: return E_OUTOFMEMORY;
+ case SZ_ERROR_PARAM: return E_INVALIDARG;
+ case SZ_ERROR_UNSUPPORTED: return E_NOTIMPL;
+ case SZ_ERROR_DATA: return S_FALSE;
+ }
+ return E_FAIL;
+}
+
+namespace NCompress {
+namespace NLzma {
+
+CDecoder::CDecoder(): _inBuf(0), _propsWereSet(false), _outSizeDefined(false),
+ _inBufSize(1 << 20),
+ _outBufSize(1 << 22),
+ FinishStream(false)
+{
+ _inSizeProcessed = 0;
+ _inPos = _inSize = 0;
+ LzmaDec_Construct(&_state);
+}
+
+static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
+static void SzFree(void *p, void *address) { p = p; MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
+
+CDecoder::~CDecoder()
+{
+ LzmaDec_Free(&_state, &g_Alloc);
+ MyFree(_inBuf);
+}
+
+STDMETHODIMP CDecoder::SetInBufSize(UInt32 , UInt32 size) { _inBufSize = size; return S_OK; }
+STDMETHODIMP CDecoder::SetOutBufSize(UInt32 , UInt32 size) { _outBufSize = size; return S_OK; }
+
+HRESULT CDecoder::CreateInputBuffer()
+{
+ if (_inBuf == 0 || _inBufSize != _inBufSizeAllocated)
+ {
+ MyFree(_inBuf);
+ _inBuf = (Byte *)MyAlloc(_inBufSize);
+ if (_inBuf == 0)
+ return E_OUTOFMEMORY;
+ _inBufSizeAllocated = _inBufSize;
+ }
+ return S_OK;
+}
+
+STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *prop, UInt32 size)
+{
+ RINOK(SResToHRESULT(LzmaDec_Allocate(&_state, prop, size, &g_Alloc)));
+ _propsWereSet = true;
+ return CreateInputBuffer();
+}
+
+void CDecoder::SetOutStreamSizeResume(const UInt64 *outSize)
+{
+ _outSizeDefined = (outSize != NULL);
+ if (_outSizeDefined)
+ _outSize = *outSize;
+ _outSizeProcessed = 0;
+ _wrPos = 0;
+ LzmaDec_Init(&_state);
+}
+
+STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)
+{
+ _inSizeProcessed = 0;
+ _inPos = _inSize = 0;
+ SetOutStreamSizeResume(outSize);
+ return S_OK;
+}
+
+HRESULT CDecoder::CodeSpec(ISequentialInStream *inStream, ISequentialOutStream *outStream, ICompressProgressInfo *progress)
+{
+ if (_inBuf == 0 || !_propsWereSet)
+ return S_FALSE;
+
+ UInt64 startInProgress = _inSizeProcessed;
+
+ SizeT next = (_state.dicBufSize - _state.dicPos < _outBufSize) ? _state.dicBufSize : (_state.dicPos + _outBufSize);
+ for (;;)
+ {
+ if (_inPos == _inSize)
+ {
+ _inPos = _inSize = 0;
+ RINOK(inStream->Read(_inBuf, _inBufSizeAllocated, &_inSize));
+ }
+
+ SizeT dicPos = _state.dicPos;
+ SizeT curSize = next - dicPos;
+
+ ELzmaFinishMode finishMode = LZMA_FINISH_ANY;
+ if (_outSizeDefined)
+ {
+ const UInt64 rem = _outSize - _outSizeProcessed;
+ if (rem <= curSize)
+ {
+ curSize = (SizeT)rem;
+ if (FinishStream)
+ finishMode = LZMA_FINISH_END;
+ }
+ }
+
+ SizeT inSizeProcessed = _inSize - _inPos;
+ ELzmaStatus status;
+ SRes res = LzmaDec_DecodeToDic(&_state, dicPos + curSize, _inBuf + _inPos, &inSizeProcessed, finishMode, &status);
+
+ _inPos += (UInt32)inSizeProcessed;
+ _inSizeProcessed += inSizeProcessed;
+ SizeT outSizeProcessed = _state.dicPos - dicPos;
+ _outSizeProcessed += outSizeProcessed;
+
+ bool finished = (inSizeProcessed == 0 && outSizeProcessed == 0);
+ bool stopDecoding = (_outSizeDefined && _outSizeProcessed >= _outSize);
+
+ if (res != 0 || _state.dicPos == next || finished || stopDecoding)
+ {
+ HRESULT res2 = WriteStream(outStream, _state.dic + _wrPos, _state.dicPos - _wrPos);
+
+ _wrPos = _state.dicPos;
+ if (_state.dicPos == _state.dicBufSize)
+ {
+ _state.dicPos = 0;
+ _wrPos = 0;
+ }
+ next = (_state.dicBufSize - _state.dicPos < _outBufSize) ? _state.dicBufSize : (_state.dicPos + _outBufSize);
+
+ if (res != 0)
+ return S_FALSE;
+ RINOK(res2);
+ if (stopDecoding)
+ return S_OK;
+ if (finished)
+ return (status == LZMA_STATUS_FINISHED_WITH_MARK ? S_OK : S_FALSE);
+ }
+ if (progress)
+ {
+ UInt64 inSize = _inSizeProcessed - startInProgress;
+ RINOK(progress->SetRatioInfo(&inSize, &_outSizeProcessed));
+ }
+ }
+}
+
+STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)
+{
+ if (_inBuf == 0)
+ return E_INVALIDARG;
+ SetOutStreamSize(outSize);
+ return CodeSpec(inStream, outStream, progress);
+}
+
+#ifndef NO_READ_FROM_CODER
+
+STDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream) { _inStream = inStream; return S_OK; }
+STDMETHODIMP CDecoder::ReleaseInStream() { _inStream.Release(); return S_OK; }
+
+STDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)
+{
+ if (processedSize)
+ *processedSize = 0;
+ do
+ {
+ if (_inPos == _inSize)
+ {
+ _inPos = _inSize = 0;
+ RINOK(_inStream->Read(_inBuf, _inBufSizeAllocated, &_inSize));
+ }
+ {
+ SizeT inProcessed = _inSize - _inPos;
+
+ if (_outSizeDefined)
+ {
+ const UInt64 rem = _outSize - _outSizeProcessed;
+ if (rem < size)
+ size = (UInt32)rem;
+ }
+
+ SizeT outProcessed = size;
+ ELzmaStatus status;
+ SRes res = LzmaDec_DecodeToBuf(&_state, (Byte *)data, &outProcessed,
+ _inBuf + _inPos, &inProcessed, LZMA_FINISH_ANY, &status);
+ _inPos += (UInt32)inProcessed;
+ _inSizeProcessed += inProcessed;
+ _outSizeProcessed += outProcessed;
+ size -= (UInt32)outProcessed;
+ data = (Byte *)data + outProcessed;
+ if (processedSize)
+ *processedSize += (UInt32)outProcessed;
+ RINOK(SResToHRESULT(res));
+ if (inProcessed == 0 && outProcessed == 0)
+ return S_OK;
+ }
+ }
+ while (size != 0);
+ return S_OK;
+}
+
+HRESULT CDecoder::CodeResume(ISequentialOutStream *outStream, const UInt64 *outSize, ICompressProgressInfo *progress)
+{
+ SetOutStreamSizeResume(outSize);
+ return CodeSpec(_inStream, outStream, progress);
+}
+
+HRESULT CDecoder::ReadFromInputStream(void *data, UInt32 size, UInt32 *processedSize)
+{
+ RINOK(CreateInputBuffer());
+ if (processedSize)
+ *processedSize = 0;
+ while (size > 0)
+ {
+ if (_inPos == _inSize)
+ {
+ _inPos = _inSize = 0;
+ RINOK(_inStream->Read(_inBuf, _inBufSizeAllocated, &_inSize));
+ if (_inSize == 0)
+ break;
+ }
+ {
+ UInt32 curSize = _inSize - _inPos;
+ if (curSize > size)
+ curSize = size;
+ memcpy(data, _inBuf + _inPos, curSize);
+ _inPos += curSize;
+ _inSizeProcessed += curSize;
+ size -= curSize;
+ data = (Byte *)data + curSize;
+ if (processedSize)
+ *processedSize += curSize;
+ }
+ }
+ return S_OK;
+}
+
+#endif
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaDecoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaDecoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaDecoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaDecoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,84 @@
+// LzmaDecoder.h
+
+#ifndef __LZMA_DECODER_H
+#define __LZMA_DECODER_H
+
+#include "../../../C/LzmaDec.h"
+
+#include "../../Common/MyCom.h"
+#include "../ICoder.h"
+
+namespace NCompress {
+namespace NLzma {
+
+class CDecoder:
+ public ICompressCoder,
+ public ICompressSetDecoderProperties2,
+ public ICompressSetBufSize,
+ #ifndef NO_READ_FROM_CODER
+ public ICompressSetInStream,
+ public ICompressSetOutStreamSize,
+ public ISequentialInStream,
+ #endif
+ public CMyUnknownImp
+{
+ CMyComPtr<ISequentialInStream> _inStream;
+ Byte *_inBuf;
+ UInt32 _inPos;
+ UInt32 _inSize;
+ CLzmaDec _state;
+ bool _propsWereSet;
+ bool _outSizeDefined;
+ UInt64 _outSize;
+ UInt64 _inSizeProcessed;
+ UInt64 _outSizeProcessed;
+
+ UInt32 _inBufSizeAllocated;
+ UInt32 _inBufSize;
+ UInt32 _outBufSize;
+ SizeT _wrPos;
+
+ HRESULT CreateInputBuffer();
+ HRESULT CodeSpec(ISequentialInStream *inStream, ISequentialOutStream *outStream, ICompressProgressInfo *progress);
+ void SetOutStreamSizeResume(const UInt64 *outSize);
+
+public:
+ MY_QUERYINTERFACE_BEGIN2(ICompressCoder)
+ MY_QUERYINTERFACE_ENTRY(ICompressSetDecoderProperties2)
+ MY_QUERYINTERFACE_ENTRY(ICompressSetBufSize)
+ #ifndef NO_READ_FROM_CODER
+ MY_QUERYINTERFACE_ENTRY(ICompressSetInStream)
+ MY_QUERYINTERFACE_ENTRY(ICompressSetOutStreamSize)
+ MY_QUERYINTERFACE_ENTRY(ISequentialInStream)
+ #endif
+ MY_QUERYINTERFACE_END
+ MY_ADDREF_RELEASE
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+ STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
+ STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);
+ STDMETHOD(SetInBufSize)(UInt32 streamIndex, UInt32 size);
+ STDMETHOD(SetOutBufSize)(UInt32 streamIndex, UInt32 size);
+
+ #ifndef NO_READ_FROM_CODER
+
+ STDMETHOD(SetInStream)(ISequentialInStream *inStream);
+ STDMETHOD(ReleaseInStream)();
+ STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
+
+ HRESULT CodeResume(ISequentialOutStream *outStream, const UInt64 *outSize, ICompressProgressInfo *progress);
+ HRESULT ReadFromInputStream(void *data, UInt32 size, UInt32 *processedSize);
+ UInt64 GetInputProcessedSize() const { return _inSizeProcessed; }
+
+ #endif
+
+ bool FinishStream;
+
+ CDecoder();
+ virtual ~CDecoder();
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaEncoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaEncoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaEncoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaEncoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,149 @@
+// LzmaEncoder.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/Alloc.h"
+
+#include "../Common/CWrappers.h"
+#include "../Common/StreamUtils.h"
+
+#include "LzmaEncoder.h"
+
+namespace NCompress {
+namespace NLzma {
+
+static void *SzBigAlloc(void *, size_t size) { return BigAlloc(size); }
+static void SzBigFree(void *, void *address) { BigFree(address); }
+static ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };
+
+static void *SzAlloc(void *, size_t size) { return MyAlloc(size); }
+static void SzFree(void *, void *address) { MyFree(address); }
+static ISzAlloc g_Alloc = { SzAlloc, SzFree };
+
+CEncoder::CEncoder()
+{
+ _encoder = 0;
+ _encoder = LzmaEnc_Create(&g_Alloc);
+ if (_encoder == 0)
+ throw 1;
+}
+
+CEncoder::~CEncoder()
+{
+ if (_encoder != 0)
+ LzmaEnc_Destroy(_encoder, &g_Alloc, &g_BigAlloc);
+}
+
+inline wchar_t GetUpperChar(wchar_t c)
+{
+ if (c >= 'a' && c <= 'z')
+ c -= 0x20;
+ return c;
+}
+
+static int ParseMatchFinder(const wchar_t *s, int *btMode, int *numHashBytes)
+{
+ wchar_t c = GetUpperChar(*s++);
+ if (c == L'H')
+ {
+ if (GetUpperChar(*s++) != L'C')
+ return 0;
+ int numHashBytesLoc = (int)(*s++ - L'0');
+ if (numHashBytesLoc < 4 || numHashBytesLoc > 4)
+ return 0;
+ if (*s++ != 0)
+ return 0;
+ *btMode = 0;
+ *numHashBytes = numHashBytesLoc;
+ return 1;
+ }
+ if (c != L'B')
+ return 0;
+
+ if (GetUpperChar(*s++) != L'T')
+ return 0;
+ int numHashBytesLoc = (int)(*s++ - L'0');
+ if (numHashBytesLoc < 2 || numHashBytesLoc > 4)
+ return 0;
+ c = GetUpperChar(*s++);
+ if (c != L'\0')
+ return 0;
+ *btMode = 1;
+ *numHashBytes = numHashBytesLoc;
+ return 1;
+}
+
+HRESULT SetLzmaProp(PROPID propID, const PROPVARIANT &prop, CLzmaEncProps &ep)
+{
+ if (propID == NCoderPropID::kMatchFinder)
+ {
+ if (prop.vt != VT_BSTR)
+ return E_INVALIDARG;
+ return ParseMatchFinder(prop.bstrVal, &ep.btMode, &ep.numHashBytes) ? S_OK : E_INVALIDARG;
+ }
+ if (prop.vt != VT_UI4)
+ return E_INVALIDARG;
+ UInt32 v = prop.ulVal;
+ switch (propID)
+ {
+ case NCoderPropID::kNumFastBytes: ep.fb = v; break;
+ case NCoderPropID::kMatchFinderCycles: ep.mc = v; break;
+ case NCoderPropID::kAlgorithm: ep.algo = v; break;
+ case NCoderPropID::kDictionarySize: ep.dictSize = v; break;
+ case NCoderPropID::kPosStateBits: ep.pb = v; break;
+ case NCoderPropID::kLitPosBits: ep.lp = v; break;
+ case NCoderPropID::kLitContextBits: ep.lc = v; break;
+ default: return E_INVALIDARG;
+ }
+ return S_OK;
+}
+
+STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
+ const PROPVARIANT *coderProps, UInt32 numProps)
+{
+ CLzmaEncProps props;
+ LzmaEncProps_Init(&props);
+
+ for (UInt32 i = 0; i < numProps; i++)
+ {
+ const PROPVARIANT &prop = coderProps[i];
+ PROPID propID = propIDs[i];
+ switch (propID)
+ {
+ case NCoderPropID::kEndMarker:
+ if (prop.vt != VT_BOOL) return E_INVALIDARG; props.writeEndMark = (prop.boolVal == VARIANT_TRUE); break;
+ case NCoderPropID::kNumThreads:
+ if (prop.vt != VT_UI4) return E_INVALIDARG; props.numThreads = prop.ulVal; break;
+ default:
+ RINOK(SetLzmaProp(propID, prop, props));
+ }
+ }
+ return SResToHRESULT(LzmaEnc_SetProps(_encoder, &props));
+}
+
+STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
+{
+ Byte props[LZMA_PROPS_SIZE];
+ size_t size = LZMA_PROPS_SIZE;
+ RINOK(LzmaEnc_WriteProperties(_encoder, props, &size));
+ return WriteStream(outStream, props, size);
+}
+
+STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)
+{
+ CSeqInStreamWrap inWrap(inStream);
+ CSeqOutStreamWrap outWrap(outStream);
+ CCompressProgressWrap progressWrap(progress);
+
+ SRes res = LzmaEnc_Encode(_encoder, &outWrap.p, &inWrap.p, progress ? &progressWrap.p : NULL, &g_Alloc, &g_BigAlloc);
+ if (res == SZ_ERROR_READ && inWrap.Res != S_OK)
+ return inWrap.Res;
+ if (res == SZ_ERROR_WRITE && outWrap.Res != S_OK)
+ return outWrap.Res;
+ if (res == SZ_ERROR_PROGRESS && progressWrap.Res != S_OK)
+ return progressWrap.Res;
+ return SResToHRESULT(res);
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaEncoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaEncoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaEncoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaEncoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,36 @@
+// LzmaEncoder.h
+
+#ifndef __LZMA_ENCODER_H
+#define __LZMA_ENCODER_H
+
+#include "../../../C/LzmaEnc.h"
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+namespace NCompress {
+namespace NLzma {
+
+class CEncoder:
+ public ICompressCoder,
+ public ICompressSetCoderProperties,
+ public ICompressWriteCoderProperties,
+ public CMyUnknownImp
+{
+ CLzmaEncHandle _encoder;
+public:
+ MY_UNKNOWN_IMP2(ICompressSetCoderProperties, ICompressWriteCoderProperties)
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+ STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);
+ STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
+
+ CEncoder();
+ virtual ~CEncoder();
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaRegister.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaRegister.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzmaRegister.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,20 @@
+// LzmaRegister.cpp
+
+#include "StdAfx.h"
+
+#include "../Common/RegisterCodec.h"
+
+#include "LzmaDecoder.h"
+
+static void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NLzma::CDecoder); }
+#ifndef EXTRACT_ONLY
+#include "LzmaEncoder.h"
+static void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NLzma::CEncoder); }
+#else
+#define CreateCodecOut 0
+#endif
+
+static CCodecInfo g_CodecInfo =
+ { CreateCodec, CreateCodecOut, 0x030101, L"LZMA", 1, false };
+
+REGISTER_CODEC(LZMA)
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzx.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzx.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzx.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzx.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,61 @@
+// Lzx.h
+
+#ifndef __COMPRESS_LZX_H
+#define __COMPRESS_LZX_H
+
+namespace NCompress {
+namespace NLzx {
+
+const unsigned kNumHuffmanBits = 16;
+const UInt32 kNumRepDistances = 3;
+
+const UInt32 kNumLenSlots = 8;
+const UInt32 kMatchMinLen = 2;
+const UInt32 kNumLenSymbols = 249;
+const UInt32 kMatchMaxLen = kMatchMinLen + (kNumLenSlots - 1) + kNumLenSymbols - 1;
+
+const unsigned kNumAlignBits = 3;
+const UInt32 kAlignTableSize = 1 << kNumAlignBits;
+
+const UInt32 kNumPosSlots = 50;
+const UInt32 kNumPosLenSlots = kNumPosSlots * kNumLenSlots;
+
+const UInt32 kMainTableSize = 256 + kNumPosLenSlots;
+const UInt32 kLevelTableSize = 20;
+const UInt32 kMaxTableSize = kMainTableSize;
+
+const unsigned kNumBlockTypeBits = 3;
+const unsigned kBlockTypeVerbatim = 1;
+const unsigned kBlockTypeAligned = 2;
+const unsigned kBlockTypeUncompressed = 3;
+
+const unsigned kUncompressedBlockSizeNumBits = 24;
+
+const unsigned kNumBitsForPreTreeLevel = 4;
+
+const unsigned kLevelSymbolZeros = 17;
+const unsigned kLevelSymbolZerosBig = 18;
+const unsigned kLevelSymbolSame = 19;
+
+const unsigned kLevelSymbolZerosStartValue = 4;
+const unsigned kLevelSymbolZerosNumBits = 4;
+
+const unsigned kLevelSymbolZerosBigStartValue = kLevelSymbolZerosStartValue +
+ (1 << kLevelSymbolZerosNumBits);
+const unsigned kLevelSymbolZerosBigNumBits = 5;
+
+const unsigned kLevelSymbolSameNumBits = 1;
+const unsigned kLevelSymbolSameStartValue = 4;
+
+const unsigned kNumBitsForAlignLevel = 3;
+
+const unsigned kNumDictionaryBitsMin = 15;
+const unsigned kNumDictionaryBitsMax = 21;
+const UInt32 kDictionarySizeMax = (1 << kNumDictionaryBitsMax);
+
+const unsigned kNumLinearPosSlotBits = 17;
+const UInt32 kNumPowerPosSlots = 0x26;
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzx86Converter.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzx86Converter.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzx86Converter.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzx86Converter.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,90 @@
+// Lzx86Converter.cpp
+
+#include "StdAfx.h"
+
+#include "../../Common/Defs.h"
+
+#include "Lzx86Converter.h"
+
+namespace NCompress {
+namespace NLzx {
+
+static const int kResidue = 6 + 4;
+
+void Cx86ConvertOutStream::MakeTranslation()
+{
+ if (m_Pos <= kResidue)
+ return;
+ UInt32 numBytes = m_Pos - kResidue;
+ Byte *buffer = m_Buffer;
+ for (UInt32 i = 0; i < numBytes;)
+ {
+ if (buffer[i++] == 0xE8)
+ {
+ Int32 absValue = 0;
+ int j;
+ for(j = 0; j < 4; j++)
+ absValue += (UInt32)buffer[i + j] << (j * 8);
+ Int32 pos = (Int32)(m_ProcessedSize + i - 1);
+ if (absValue >= -pos && absValue < (Int32)m_TranslationSize)
+ {
+ UInt32 offset = (absValue >= 0) ?
+ absValue - pos :
+ absValue + m_TranslationSize;
+ for(j = 0; j < 4; j++)
+ {
+ buffer[i + j] = (Byte)(offset & 0xFF);
+ offset >>= 8;
+ }
+ }
+ i += 4;
+ }
+ }
+}
+
+STDMETHODIMP Cx86ConvertOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
+{
+ if (processedSize != NULL)
+ *processedSize = 0;
+ if (!m_TranslationMode)
+ return m_Stream->Write(data, size, processedSize);
+ UInt32 realProcessedSize = 0;
+ while (realProcessedSize < size)
+ {
+ UInt32 writeSize = MyMin(size - realProcessedSize, kUncompressedBlockSize - m_Pos);
+ memmove(m_Buffer + m_Pos, (const Byte *)data + realProcessedSize, writeSize);
+ m_Pos += writeSize;
+ realProcessedSize += writeSize;
+ if (m_Pos == kUncompressedBlockSize)
+ {
+ RINOK(Flush());
+ }
+ }
+ if (processedSize != NULL)
+ *processedSize = realProcessedSize;
+ return S_OK;
+}
+
+HRESULT Cx86ConvertOutStream::Flush()
+{
+ if (m_Pos == 0)
+ return S_OK;
+ if (m_TranslationMode)
+ MakeTranslation();
+ UInt32 pos = 0;
+ do
+ {
+ UInt32 processed;
+ RINOK(m_Stream->Write(m_Buffer + pos, m_Pos - pos, &processed));
+ if (processed == 0)
+ return E_FAIL;
+ pos += processed;
+ }
+ while(pos < m_Pos);
+ m_ProcessedSize += m_Pos;
+ m_Pos = 0;
+ m_TranslationMode = (m_TranslationMode && (m_ProcessedSize < (1 << 30)));
+ return S_OK;
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzx86Converter.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzx86Converter.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzx86Converter.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Lzx86Converter.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,46 @@
+// Lzx86Converter.h
+
+#ifndef __LZX_86_CONVERTER_H
+#define __LZX_86_CONVERTER_H
+
+#include "../../Common/MyCom.h"
+
+#include "../IStream.h"
+
+namespace NCompress {
+namespace NLzx {
+
+const int kUncompressedBlockSize = 1 << 15;
+
+class Cx86ConvertOutStream:
+ public ISequentialOutStream,
+ public CMyUnknownImp
+{
+ CMyComPtr<ISequentialOutStream> m_Stream;
+ UInt32 m_ProcessedSize;
+ UInt32 m_Pos;
+ UInt32 m_TranslationSize;
+ bool m_TranslationMode;
+ Byte m_Buffer[kUncompressedBlockSize];
+
+ void MakeTranslation();
+public:
+ void SetStream(ISequentialOutStream *outStream) { m_Stream = outStream; }
+ void ReleaseStream() { m_Stream.Release(); }
+ void Init(bool translationMode, UInt32 translationSize)
+ {
+ m_TranslationMode = translationMode;
+ m_TranslationSize = translationSize;
+ m_ProcessedSize = 0;
+ m_Pos = 0;
+ }
+ HRESULT Flush();
+
+ MY_UNKNOWN_IMP
+
+ STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzxDecoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzxDecoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzxDecoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzxDecoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,387 @@
+// LzxDecoder.cpp
+
+#include "StdAfx.h"
+
+#include "../../Common/Defs.h"
+
+#include "LzxDecoder.h"
+
+namespace NCompress {
+namespace NLzx {
+
+const int kLenIdNeedInit = -2;
+
+CDecoder::CDecoder(bool wimMode):
+ _keepHistory(false),
+ _skipByte(false),
+ _wimMode(wimMode)
+{
+ m_x86ConvertOutStreamSpec = new Cx86ConvertOutStream;
+ m_x86ConvertOutStream = m_x86ConvertOutStreamSpec;
+}
+
+void CDecoder::ReleaseStreams()
+{
+ m_OutWindowStream.ReleaseStream();
+ m_InBitStream.ReleaseStream();
+ m_x86ConvertOutStreamSpec->ReleaseStream();
+}
+
+STDMETHODIMP CDecoder::Flush()
+{
+ RINOK(m_OutWindowStream.Flush());
+ return m_x86ConvertOutStreamSpec->Flush();
+}
+
+UInt32 CDecoder::ReadBits(unsigned numBits) { return m_InBitStream.ReadBits(numBits); }
+
+#define RIF(x) { if (!(x)) return false; }
+
+bool CDecoder::ReadTable(Byte *lastLevels, Byte *newLevels, UInt32 numSymbols)
+{
+ Byte levelLevels[kLevelTableSize];
+ UInt32 i;
+ for (i = 0; i < kLevelTableSize; i++)
+ levelLevels[i] = (Byte)ReadBits(kNumBitsForPreTreeLevel);
+ RIF(m_LevelDecoder.SetCodeLengths(levelLevels));
+ unsigned num = 0;
+ Byte symbol = 0;
+ for (i = 0; i < numSymbols;)
+ {
+ if (num != 0)
+ {
+ lastLevels[i] = newLevels[i] = symbol;
+ i++;
+ num--;
+ continue;
+ }
+ UInt32 number = m_LevelDecoder.DecodeSymbol(&m_InBitStream);
+ if (number == kLevelSymbolZeros)
+ {
+ num = kLevelSymbolZerosStartValue + (unsigned)ReadBits(kLevelSymbolZerosNumBits);
+ symbol = 0;
+ }
+ else if (number == kLevelSymbolZerosBig)
+ {
+ num = kLevelSymbolZerosBigStartValue + (unsigned)ReadBits(kLevelSymbolZerosBigNumBits);
+ symbol = 0;
+ }
+ else if (number == kLevelSymbolSame || number <= kNumHuffmanBits)
+ {
+ if (number <= kNumHuffmanBits)
+ num = 1;
+ else
+ {
+ num = kLevelSymbolSameStartValue + (unsigned)ReadBits(kLevelSymbolSameNumBits);
+ number = m_LevelDecoder.DecodeSymbol(&m_InBitStream);
+ if (number > kNumHuffmanBits)
+ return false;
+ }
+ symbol = Byte((17 + lastLevels[i] - number) % (kNumHuffmanBits + 1));
+ }
+ else
+ return false;
+ }
+ return true;
+}
+
+bool CDecoder::ReadTables(void)
+{
+ Byte newLevels[kMaxTableSize];
+ {
+ if (_skipByte)
+ m_InBitStream.DirectReadByte();
+ m_InBitStream.Normalize();
+
+ unsigned blockType = (unsigned)ReadBits(kNumBlockTypeBits);
+ if (blockType > kBlockTypeUncompressed)
+ return false;
+ if (_wimMode)
+ if (ReadBits(1) == 1)
+ m_UnCompressedBlockSize = (1 << 15);
+ else
+ m_UnCompressedBlockSize = ReadBits(16);
+ else
+ m_UnCompressedBlockSize = m_InBitStream.ReadBitsBig(kUncompressedBlockSizeNumBits);
+
+ m_IsUncompressedBlock = (blockType == kBlockTypeUncompressed);
+
+ _skipByte = (m_IsUncompressedBlock && ((m_UnCompressedBlockSize & 1) != 0));
+
+ if (m_IsUncompressedBlock)
+ {
+ ReadBits(16 - m_InBitStream.GetBitPosition());
+ if (!m_InBitStream.ReadUInt32(m_RepDistances[0]))
+ return false;
+ m_RepDistances[0]--;
+ for (unsigned i = 1; i < kNumRepDistances; i++)
+ {
+ UInt32 rep = 0;
+ for (unsigned j = 0; j < 4; j++)
+ rep |= (UInt32)m_InBitStream.DirectReadByte() << (8 * j);
+ m_RepDistances[i] = rep - 1;
+ }
+ return true;
+ }
+ m_AlignIsUsed = (blockType == kBlockTypeAligned);
+ if (m_AlignIsUsed)
+ {
+ for (unsigned i = 0; i < kAlignTableSize; i++)
+ newLevels[i] = (Byte)ReadBits(kNumBitsForAlignLevel);
+ RIF(m_AlignDecoder.SetCodeLengths(newLevels));
+ }
+ }
+
+ RIF(ReadTable(m_LastMainLevels, newLevels, 256));
+ RIF(ReadTable(m_LastMainLevels + 256, newLevels + 256, m_NumPosLenSlots));
+ for (UInt32 i = 256 + m_NumPosLenSlots; i < kMainTableSize; i++)
+ newLevels[i] = 0;
+ RIF(m_MainDecoder.SetCodeLengths(newLevels));
+
+ RIF(ReadTable(m_LastLenLevels, newLevels, kNumLenSymbols));
+ return m_LenDecoder.SetCodeLengths(newLevels);
+}
+
+class CDecoderFlusher
+{
+ CDecoder *m_Decoder;
+public:
+ bool NeedFlush;
+ CDecoderFlusher(CDecoder *decoder): m_Decoder(decoder), NeedFlush(true) {}
+ ~CDecoderFlusher()
+ {
+ if (NeedFlush)
+ m_Decoder->Flush();
+ m_Decoder->ReleaseStreams();
+ }
+};
+
+
+void CDecoder::ClearPrevLevels()
+{
+ unsigned i;
+ for (i = 0; i < kMainTableSize; i++)
+ m_LastMainLevels[i] = 0;
+ for (i = 0; i < kNumLenSymbols; i++)
+ m_LastLenLevels[i] = 0;
+}
+
+
+HRESULT CDecoder::CodeSpec(UInt32 curSize)
+{
+ if (_remainLen == kLenIdNeedInit)
+ {
+ _remainLen = 0;
+ m_InBitStream.Init();
+ if (!_keepHistory || !m_IsUncompressedBlock)
+ m_InBitStream.Normalize();
+ if (!_keepHistory)
+ {
+ _skipByte = false;
+ m_UnCompressedBlockSize = 0;
+ ClearPrevLevels();
+ UInt32 i86TranslationSize = 12000000;
+ bool translationMode = true;
+ if (!_wimMode)
+ {
+ translationMode = (ReadBits(1) != 0);
+ if (translationMode)
+ {
+ i86TranslationSize = ReadBits(16) << 16;
+ i86TranslationSize |= ReadBits(16);
+ }
+ }
+ m_x86ConvertOutStreamSpec->Init(translationMode, i86TranslationSize);
+
+ for (unsigned i = 0 ; i < kNumRepDistances; i++)
+ m_RepDistances[i] = 0;
+ }
+ }
+
+ while (_remainLen > 0 && curSize > 0)
+ {
+ m_OutWindowStream.PutByte(m_OutWindowStream.GetByte(m_RepDistances[0]));
+ _remainLen--;
+ curSize--;
+ }
+
+ while (curSize > 0)
+ {
+ if (m_UnCompressedBlockSize == 0)
+ if (!ReadTables())
+ return S_FALSE;
+ UInt32 next = (Int32)MyMin(m_UnCompressedBlockSize, curSize);
+ curSize -= next;
+ m_UnCompressedBlockSize -= next;
+ if (m_IsUncompressedBlock)
+ {
+ while (next > 0)
+ {
+ m_OutWindowStream.PutByte(m_InBitStream.DirectReadByte());
+ next--;
+ }
+ }
+ else while (next > 0)
+ {
+ UInt32 number = m_MainDecoder.DecodeSymbol(&m_InBitStream);
+ if (number < 256)
+ {
+ m_OutWindowStream.PutByte((Byte)number);
+ next--;
+ }
+ else
+ {
+ UInt32 posLenSlot = number - 256;
+ if (posLenSlot >= m_NumPosLenSlots)
+ return S_FALSE;
+ UInt32 posSlot = posLenSlot / kNumLenSlots;
+ UInt32 lenSlot = posLenSlot % kNumLenSlots;
+ UInt32 len = kMatchMinLen + lenSlot;
+ if (lenSlot == kNumLenSlots - 1)
+ {
+ UInt32 lenTemp = m_LenDecoder.DecodeSymbol(&m_InBitStream);
+ if (lenTemp >= kNumLenSymbols)
+ return S_FALSE;
+ len += lenTemp;
+ }
+
+ if (posSlot < kNumRepDistances)
+ {
+ UInt32 distance = m_RepDistances[posSlot];
+ m_RepDistances[posSlot] = m_RepDistances[0];
+ m_RepDistances[0] = distance;
+ }
+ else
+ {
+ UInt32 distance;
+ unsigned numDirectBits;
+ if (posSlot < kNumPowerPosSlots)
+ {
+ numDirectBits = (unsigned)(posSlot >> 1) - 1;
+ distance = ((2 | (posSlot & 1)) << numDirectBits);
+ }
+ else
+ {
+ numDirectBits = kNumLinearPosSlotBits;
+ distance = ((posSlot - 0x22) << kNumLinearPosSlotBits);
+ }
+
+ if (m_AlignIsUsed && numDirectBits >= kNumAlignBits)
+ {
+ distance += (m_InBitStream.ReadBits(numDirectBits - kNumAlignBits) << kNumAlignBits);
+ UInt32 alignTemp = m_AlignDecoder.DecodeSymbol(&m_InBitStream);
+ if (alignTemp >= kAlignTableSize)
+ return S_FALSE;
+ distance += alignTemp;
+ }
+ else
+ distance += m_InBitStream.ReadBits(numDirectBits);
+ m_RepDistances[2] = m_RepDistances[1];
+ m_RepDistances[1] = m_RepDistances[0];
+ m_RepDistances[0] = distance - kNumRepDistances;
+ }
+
+ UInt32 locLen = len;
+ if (locLen > next)
+ locLen = next;
+
+ if (!m_OutWindowStream.CopyBlock(m_RepDistances[0], locLen))
+ return S_FALSE;
+
+ len -= locLen;
+ next -= locLen;
+ if (len != 0)
+ {
+ _remainLen = (int)len;
+ return S_OK;
+ }
+ }
+ }
+ }
+ return S_OK;
+}
+
+HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *, const UInt64 *outSize, ICompressProgressInfo *progress)
+{
+ if (outSize == NULL)
+ return E_INVALIDARG;
+ UInt64 size = *outSize;
+
+ RINOK(SetInStream(inStream));
+ m_x86ConvertOutStreamSpec->SetStream(outStream);
+ m_OutWindowStream.SetStream(m_x86ConvertOutStream);
+ RINOK(SetOutStreamSize(outSize));
+
+ CDecoderFlusher flusher(this);
+
+ const UInt64 start = m_OutWindowStream.GetProcessedSize();
+ for (;;)
+ {
+ UInt32 curSize = 1 << 18;
+ UInt64 rem = size - (m_OutWindowStream.GetProcessedSize() - start);
+ if (curSize > rem)
+ curSize = (UInt32)rem;
+ if (curSize == 0)
+ break;
+ RINOK(CodeSpec(curSize));
+ if (progress != NULL)
+ {
+ UInt64 inSize = m_InBitStream.GetProcessedSize();
+ UInt64 nowPos64 = m_OutWindowStream.GetProcessedSize() - start;
+ RINOK(progress->SetRatioInfo(&inSize, &nowPos64));
+ }
+ }
+ flusher.NeedFlush = false;
+ return Flush();
+}
+
+HRESULT 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::SetInStream(ISequentialInStream *inStream)
+{
+ m_InBitStream.SetStream(inStream);
+ return S_OK;
+}
+
+STDMETHODIMP CDecoder::ReleaseInStream()
+{
+ m_InBitStream.ReleaseStream();
+ return S_OK;
+}
+
+STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)
+{
+ if (outSize == NULL)
+ return E_FAIL;
+ _remainLen = kLenIdNeedInit;
+ m_OutWindowStream.Init(_keepHistory);
+ return S_OK;
+}
+
+HRESULT CDecoder::SetParams(unsigned numDictBits)
+{
+ if (numDictBits < kNumDictionaryBitsMin || numDictBits > kNumDictionaryBitsMax)
+ return E_INVALIDARG;
+ UInt32 numPosSlots;
+ if (numDictBits < 20)
+ numPosSlots = 30 + (numDictBits - 15) * 2;
+ else if (numDictBits == 20)
+ numPosSlots = 42;
+ else
+ numPosSlots = 50;
+ m_NumPosLenSlots = numPosSlots * kNumLenSlots;
+ if (!m_OutWindowStream.Create(kDictionarySizeMax))
+ return E_OUTOFMEMORY;
+ if (!m_InBitStream.Create(1 << 16))
+ return E_OUTOFMEMORY;
+ return S_OK;
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzxDecoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzxDecoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzxDecoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/LzxDecoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,159 @@
+// LzxDecoder.h
+
+#ifndef __LZX_DECODER_H
+#define __LZX_DECODER_H
+
+#include "../ICoder.h"
+
+#include "../Common/InBuffer.h"
+
+#include "HuffmanDecoder.h"
+#include "LzOutWindow.h"
+#include "Lzx.h"
+#include "Lzx86Converter.h"
+
+namespace NCompress {
+namespace NLzx {
+
+namespace NBitStream {
+
+const unsigned kNumBigValueBits = 8 * 4;
+const unsigned kNumValueBits = 17;
+const UInt32 kBitDecoderValueMask = (1 << kNumValueBits) - 1;
+
+class CDecoder
+{
+ CInBuffer m_Stream;
+ UInt32 m_Value;
+ unsigned m_BitPos;
+public:
+ CDecoder() {}
+ bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
+
+ void SetStream(ISequentialInStream *s) { m_Stream.SetStream(s); }
+ void ReleaseStream() { m_Stream.ReleaseStream(); }
+
+ void Init()
+ {
+ m_Stream.Init();
+ m_BitPos = kNumBigValueBits;
+ }
+
+ UInt64 GetProcessedSize() const { return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; }
+
+ unsigned GetBitPosition() const { return m_BitPos & 0xF; }
+
+ void Normalize()
+ {
+ for (; m_BitPos >= 16; m_BitPos -= 16)
+ {
+ Byte b0 = m_Stream.ReadByte();
+ Byte b1 = m_Stream.ReadByte();
+ m_Value = (m_Value << 8) | b1;
+ m_Value = (m_Value << 8) | b0;
+ }
+ }
+
+ UInt32 GetValue(unsigned numBits) const
+ {
+ return ((m_Value >> ((32 - kNumValueBits) - m_BitPos)) & kBitDecoderValueMask) >> (kNumValueBits - numBits);
+ }
+
+ void MovePos(unsigned numBits)
+ {
+ m_BitPos += numBits;
+ Normalize();
+ }
+
+ UInt32 ReadBits(unsigned numBits)
+ {
+ UInt32 res = GetValue(numBits);
+ MovePos(numBits);
+ return res;
+ }
+
+ UInt32 ReadBitsBig(unsigned numBits)
+ {
+ unsigned numBits0 = numBits / 2;
+ unsigned numBits1 = numBits - numBits0;
+ UInt32 res = ReadBits(numBits0) << numBits1;
+ return res + ReadBits(numBits1);
+ }
+
+ bool ReadUInt32(UInt32 &v)
+ {
+ if (m_BitPos != 0)
+ return false;
+ v = ((m_Value >> 16) & 0xFFFF) | ((m_Value << 16) & 0xFFFF0000);
+ m_BitPos = kNumBigValueBits;
+ return true;
+ }
+
+ Byte DirectReadByte() { return m_Stream.ReadByte(); }
+
+};
+}
+
+class CDecoder :
+ public ICompressCoder,
+ public CMyUnknownImp
+{
+ NBitStream::CDecoder m_InBitStream;
+ CLzOutWindow m_OutWindowStream;
+
+ UInt32 m_RepDistances[kNumRepDistances];
+ UInt32 m_NumPosLenSlots;
+
+ bool m_IsUncompressedBlock;
+ bool m_AlignIsUsed;
+
+ NCompress::NHuffman::CDecoder<kNumHuffmanBits, kMainTableSize> m_MainDecoder;
+ NCompress::NHuffman::CDecoder<kNumHuffmanBits, kNumLenSymbols> m_LenDecoder;
+ NCompress::NHuffman::CDecoder<kNumHuffmanBits, kAlignTableSize> m_AlignDecoder;
+ NCompress::NHuffman::CDecoder<kNumHuffmanBits, kLevelTableSize> m_LevelDecoder;
+
+ Byte m_LastMainLevels[kMainTableSize];
+ Byte m_LastLenLevels[kNumLenSymbols];
+
+ Cx86ConvertOutStream *m_x86ConvertOutStreamSpec;
+ CMyComPtr<ISequentialOutStream> m_x86ConvertOutStream;
+
+ UInt32 m_UnCompressedBlockSize;
+
+ bool _keepHistory;
+ int _remainLen;
+ bool _skipByte;
+
+ bool _wimMode;
+
+ UInt32 ReadBits(unsigned numBits);
+ bool ReadTable(Byte *lastLevels, Byte *newLevels, UInt32 numSymbols);
+ bool ReadTables();
+ void ClearPrevLevels();
+
+ HRESULT CodeSpec(UInt32 size);
+
+ HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+public:
+ CDecoder(bool wimMode = false);
+
+ MY_UNKNOWN_IMP
+
+ void ReleaseStreams();
+ STDMETHOD(Flush)();
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ STDMETHOD(SetInStream)(ISequentialInStream *inStream);
+ STDMETHOD(ReleaseInStream)();
+ STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);
+
+ HRESULT SetParams(unsigned numDictBits);
+ void SetKeepHistory(bool keepHistory) { _keepHistory = keepHistory; }
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Mtf8.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Mtf8.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Mtf8.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Mtf8.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,193 @@
+// Mtf8.h
+
+#ifndef __COMPRESS_MTF8_H
+#define __COMPRESS_MTF8_H
+
+#include "../../../C/CpuArch.h"
+
+#include "../../Common/Types.h"
+
+namespace NCompress {
+
+struct CMtf8Encoder
+{
+ Byte Buf[256];
+
+ int FindAndMove(Byte v)
+ {
+ int pos;
+ for (pos = 0; Buf[pos] != v; pos++);
+ int resPos = pos;
+ for (; pos >= 8; pos -= 8)
+ {
+ Buf[pos] = Buf[pos - 1];
+ Buf[pos - 1] = Buf[pos - 2];
+ Buf[pos - 2] = Buf[pos - 3];
+ Buf[pos - 3] = Buf[pos - 4];
+ Buf[pos - 4] = Buf[pos - 5];
+ Buf[pos - 5] = Buf[pos - 6];
+ Buf[pos - 6] = Buf[pos - 7];
+ Buf[pos - 7] = Buf[pos - 8];
+ }
+ for (; pos > 0; pos--)
+ Buf[pos] = Buf[pos - 1];
+ Buf[0] = v;
+ return resPos;
+ }
+};
+
+/*
+struct CMtf8Decoder
+{
+ Byte Buf[256];
+
+ void Init(int) {};
+ Byte GetHead() const { return Buf[0]; }
+ Byte GetAndMove(int pos)
+ {
+ Byte res = Buf[pos];
+ for (; pos >= 8; pos -= 8)
+ {
+ Buf[pos] = Buf[pos - 1];
+ Buf[pos - 1] = Buf[pos - 2];
+ Buf[pos - 2] = Buf[pos - 3];
+ Buf[pos - 3] = Buf[pos - 4];
+ Buf[pos - 4] = Buf[pos - 5];
+ Buf[pos - 5] = Buf[pos - 6];
+ Buf[pos - 6] = Buf[pos - 7];
+ Buf[pos - 7] = Buf[pos - 8];
+ }
+ for (; pos > 0; pos--)
+ Buf[pos] = Buf[pos - 1];
+ Buf[0] = res;
+ return res;
+ }
+};
+*/
+
+#ifdef MY_CPU_64BIT
+typedef UInt64 CMtfVar;
+#define MTF_MOVS 3
+#else
+typedef UInt32 CMtfVar;
+#define MTF_MOVS 2
+#endif
+
+#define MTF_MASK ((1 << MTF_MOVS) - 1)
+
+
+struct CMtf8Decoder
+{
+ CMtfVar Buf[256 >> MTF_MOVS];
+
+ void StartInit() { memset(Buf, 0, sizeof(Buf)); }
+ void Add(unsigned int pos, Byte val) { Buf[pos >> MTF_MOVS] |= ((CMtfVar)val << ((pos & MTF_MASK) << 3)); }
+ Byte GetHead() const { return (Byte)Buf[0]; }
+ Byte GetAndMove(unsigned int pos)
+ {
+ UInt32 lim = ((UInt32)pos >> MTF_MOVS);
+ pos = (pos & MTF_MASK) << 3;
+ CMtfVar prev = (Buf[lim] >> pos) & 0xFF;
+
+ UInt32 i = 0;
+ if ((lim & 1) != 0)
+ {
+ CMtfVar next = Buf[0];
+ Buf[0] = (next << 8) | prev;
+ prev = (next >> (MTF_MASK << 3));
+ i = 1;
+ lim -= 1;
+ }
+ for (; i < lim; i += 2)
+ {
+ CMtfVar n0 = Buf[i];
+ CMtfVar n1 = Buf[i + 1];
+ Buf[i ] = (n0 << 8) | prev;
+ Buf[i + 1] = (n1 << 8) | (n0 >> (MTF_MASK << 3));
+ prev = (n1 >> (MTF_MASK << 3));
+ }
+ CMtfVar next = Buf[i];
+ CMtfVar mask = (((CMtfVar)0x100 << pos) - 1);
+ Buf[i] = (next & ~mask) | (((next << 8) | prev) & mask);
+ return (Byte)Buf[0];
+ }
+};
+
+/*
+const int kSmallSize = 64;
+class CMtf8Decoder
+{
+ Byte SmallBuffer[kSmallSize];
+ int SmallSize;
+ Byte Counts[16];
+ int Size;
+public:
+ Byte Buf[256];
+
+ Byte GetHead() const
+ {
+ if (SmallSize > 0)
+ return SmallBuffer[kSmallSize - SmallSize];
+ return Buf[0];
+ }
+
+ void Init(int size)
+ {
+ Size = size;
+ SmallSize = 0;
+ for (int i = 0; i < 16; i++)
+ {
+ Counts[i] = ((size >= 16) ? 16 : size);
+ size -= Counts[i];
+ }
+ }
+
+ Byte GetAndMove(int pos)
+ {
+ if (pos < SmallSize)
+ {
+ Byte *p = SmallBuffer + kSmallSize - SmallSize;
+ Byte res = p[pos];
+ for (; pos > 0; pos--)
+ p[pos] = p[pos - 1];
+ SmallBuffer[kSmallSize - SmallSize] = res;
+ return res;
+ }
+ if (SmallSize == kSmallSize)
+ {
+ int i = Size - 1;
+ int g = 16;
+ do
+ {
+ g--;
+ int offset = (g << 4);
+ for (int t = Counts[g] - 1; t >= 0; t--, i--)
+ Buf[i] = Buf[offset + t];
+ }
+ while(g != 0);
+
+ for (i = kSmallSize - 1; i >= 0; i--)
+ Buf[i] = SmallBuffer[i];
+ Init(Size);
+ }
+ pos -= SmallSize;
+ int g;
+ for (g = 0; pos >= Counts[g]; g++)
+ pos -= Counts[g];
+ int offset = (g << 4);
+ Byte res = Buf[offset + pos];
+ for (pos; pos < 16 - 1; pos++)
+ Buf[offset + pos] = Buf[offset + pos + 1];
+
+ SmallSize++;
+ SmallBuffer[kSmallSize - SmallSize] = res;
+
+ Counts[g]--;
+ return res;
+ }
+};
+*/
+
+}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdDecoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdDecoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdDecoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdDecoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,167 @@
+// PpmdDecoder.cpp
+// 2009-03-11 : Igor Pavlov : Public domain
+
+#include "StdAfx.h"
+
+#include "../../../C/Alloc.h"
+#include "../../../C/CpuArch.h"
+
+#include "../Common/StreamUtils.h"
+
+#include "PpmdDecoder.h"
+
+namespace NCompress {
+namespace NPpmd {
+
+static const UInt32 kBufSize = (1 << 20);
+
+enum
+{
+ kStatus_NeedInit,
+ kStatus_Normal,
+ kStatus_Finished,
+ kStatus_Error
+};
+
+static void *SzBigAlloc(void *, size_t size) { return BigAlloc(size); }
+static void SzBigFree(void *, void *address) { BigFree(address); }
+static ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };
+
+CDecoder::~CDecoder()
+{
+ ::MidFree(_outBuf);
+ Ppmd7_Free(&_ppmd, &g_BigAlloc);
+}
+
+STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *props, UInt32 size)
+{
+ if (size < 5)
+ return E_INVALIDARG;
+ _order = props[0];
+ UInt32 memSize = GetUi32(props + 1);
+ if (_order < PPMD7_MIN_ORDER ||
+ _order > PPMD7_MAX_ORDER ||
+ memSize < PPMD7_MIN_MEM_SIZE ||
+ memSize > PPMD7_MAX_MEM_SIZE)
+ return E_NOTIMPL;
+ if (!_inStream.Alloc(1 << 20))
+ return E_OUTOFMEMORY;
+ if (!Ppmd7_Alloc(&_ppmd, memSize, &g_BigAlloc))
+ return E_OUTOFMEMORY;
+ return S_OK;
+}
+
+HRESULT CDecoder::CodeSpec(Byte *memStream, UInt32 size)
+{
+ switch(_status)
+ {
+ case kStatus_Finished: return S_OK;
+ case kStatus_Error: return S_FALSE;
+ case kStatus_NeedInit:
+ _inStream.Init();
+ if (!Ppmd7z_RangeDec_Init(&_rangeDec))
+ {
+ _status = kStatus_Error;
+ return S_FALSE;
+ }
+ _status = kStatus_Normal;
+ Ppmd7_Init(&_ppmd, _order);
+ break;
+ }
+ if (_outSizeDefined)
+ {
+ const UInt64 rem = _outSize - _processedSize;
+ if (size > rem)
+ size = (UInt32)rem;
+ }
+
+ UInt32 i;
+ int sym = 0;
+ for (i = 0; i != size; i++)
+ {
+ sym = Ppmd7_DecodeSymbol(&_ppmd, &_rangeDec.p);
+ if (_inStream.Extra || sym < 0)
+ break;
+ memStream[i] = (Byte)sym;
+ }
+
+ _processedSize += i;
+ if (_inStream.Extra)
+ {
+ _status = kStatus_Error;
+ return _inStream.Res;
+ }
+ if (sym < 0)
+ _status = (sym < -1) ? kStatus_Error : kStatus_Finished;
+ return S_OK;
+}
+
+STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)
+{
+ if (!_outBuf)
+ {
+ _outBuf = (Byte *)::MidAlloc(kBufSize);
+ if (!_outBuf)
+ return E_OUTOFMEMORY;
+ }
+
+ _inStream.Stream = inStream;
+ SetOutStreamSize(outSize);
+
+ do
+ {
+ const UInt64 startPos = _processedSize;
+ HRESULT res = CodeSpec(_outBuf, kBufSize);
+ size_t processed = (size_t)(_processedSize - startPos);
+ RINOK(WriteStream(outStream, _outBuf, processed));
+ RINOK(res);
+ if (_status == kStatus_Finished)
+ break;
+ if (progress)
+ {
+ UInt64 inSize = _inStream.GetProcessed();
+ RINOK(progress->SetRatioInfo(&inSize, &_processedSize));
+ }
+ }
+ while (!_outSizeDefined || _processedSize < _outSize);
+ return S_OK;
+}
+
+STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)
+{
+ _outSizeDefined = (outSize != NULL);
+ if (_outSizeDefined)
+ _outSize = *outSize;
+ _processedSize = 0;
+ _status = kStatus_NeedInit;
+ return S_OK;
+}
+
+#ifndef NO_READ_FROM_CODER
+
+STDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream)
+{
+ InSeqStream = inStream;
+ _inStream.Stream = inStream;
+ return S_OK;
+}
+
+STDMETHODIMP CDecoder::ReleaseInStream()
+{
+ InSeqStream.Release();
+ return S_OK;
+}
+
+STDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)
+{
+ const UInt64 startPos = _processedSize;
+ HRESULT res = CodeSpec((Byte *)data, size);
+ if (processedSize)
+ *processedSize = (UInt32)(_processedSize - startPos);
+ return res;
+}
+
+#endif
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdDecoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdDecoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdDecoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdDecoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,78 @@
+// PpmdDecoder.h
+// 2009-03-11 : Igor Pavlov : Public domain
+
+#ifndef __COMPRESS_PPMD_DECODER_H
+#define __COMPRESS_PPMD_DECODER_H
+
+#include "../../../C/Ppmd7.h"
+
+#include "../../Common/MyCom.h"
+
+#include "../Common/CWrappers.h"
+
+#include "../ICoder.h"
+
+namespace NCompress {
+namespace NPpmd {
+
+class CDecoder :
+ public ICompressCoder,
+ public ICompressSetDecoderProperties2,
+ #ifndef NO_READ_FROM_CODER
+ public ICompressSetInStream,
+ public ICompressSetOutStreamSize,
+ public ISequentialInStream,
+ #endif
+ public CMyUnknownImp
+{
+ Byte *_outBuf;
+ CPpmd7z_RangeDec _rangeDec;
+ CByteInBufWrap _inStream;
+ CPpmd7 _ppmd;
+
+ Byte _order;
+ bool _outSizeDefined;
+ int _status;
+ UInt64 _outSize;
+ UInt64 _processedSize;
+
+ HRESULT CodeSpec(Byte *memStream, UInt32 size);
+
+public:
+
+ #ifndef NO_READ_FROM_CODER
+ CMyComPtr<ISequentialInStream> InSeqStream;
+ MY_UNKNOWN_IMP4(
+ ICompressSetDecoderProperties2,
+ ICompressSetInStream,
+ ICompressSetOutStreamSize,
+ ISequentialInStream)
+ #else
+ MY_UNKNOWN_IMP1(
+ ICompressSetDecoderProperties2)
+ #endif
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+ STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
+ STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);
+
+ #ifndef NO_READ_FROM_CODER
+ STDMETHOD(SetInStream)(ISequentialInStream *inStream);
+ STDMETHOD(ReleaseInStream)();
+ STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
+ #endif
+
+ CDecoder(): _outBuf(NULL), _outSizeDefined(false)
+ {
+ Ppmd7z_RangeDec_CreateVTable(&_rangeDec);
+ _rangeDec.Stream = &_inStream.p;
+ Ppmd7_Construct(&_ppmd);
+ }
+
+ ~CDecoder();
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdEncoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdEncoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdEncoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdEncoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,119 @@
+// PpmdEncoder.cpp
+// 2009-03-11 : Igor Pavlov : Public domain
+
+#include "StdAfx.h"
+
+#include "../../../C/Alloc.h"
+#include "../../../C/CpuArch.h"
+
+#include "../Common/StreamUtils.h"
+
+#include "PpmdEncoder.h"
+
+namespace NCompress {
+namespace NPpmd {
+
+static const UInt32 kBufSize = (1 << 20);
+
+static void *SzBigAlloc(void *, size_t size) { return BigAlloc(size); }
+static void SzBigFree(void *, void *address) { BigFree(address); }
+static ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };
+
+CEncoder::CEncoder():
+ _inBuf(NULL),
+ _usedMemSize(1 << 24),
+ _order(6)
+{
+ _rangeEnc.Stream = &_outStream.p;
+ Ppmd7_Construct(&_ppmd);
+}
+
+CEncoder::~CEncoder()
+{
+ ::MidFree(_inBuf);
+ Ppmd7_Free(&_ppmd, &g_BigAlloc);
+}
+
+STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps)
+{
+ for (UInt32 i = 0; i < numProps; i++)
+ {
+ const PROPVARIANT &prop = props[i];
+ if (prop.vt != VT_UI4)
+ return E_INVALIDARG;
+ UInt32 v = (UInt32)prop.ulVal;
+ switch(propIDs[i])
+ {
+ case NCoderPropID::kUsedMemorySize:
+ if (v < (1 << 16) || v > PPMD7_MAX_MEM_SIZE || (v & 3) != 0)
+ return E_INVALIDARG;
+ _usedMemSize = v;
+ break;
+ case NCoderPropID::kOrder:
+ if (v < 2 || v > 32)
+ return E_INVALIDARG;
+ _order = (Byte)v;
+ break;
+ default:
+ return E_INVALIDARG;
+ }
+ }
+ return S_OK;
+}
+
+STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
+{
+ const UInt32 kPropSize = 5;
+ Byte props[kPropSize];
+ props[0] = _order;
+ SetUi32(props + 1, _usedMemSize);
+ return WriteStream(outStream, props, kPropSize);
+}
+
+HRESULT CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)
+{
+ if (!_inBuf)
+ {
+ _inBuf = (Byte *)::MidAlloc(kBufSize);
+ if (!_inBuf)
+ return E_OUTOFMEMORY;
+ }
+ if (!_outStream.Alloc(1 << 20))
+ return E_OUTOFMEMORY;
+ if (!Ppmd7_Alloc(&_ppmd, _usedMemSize, &g_BigAlloc))
+ return E_OUTOFMEMORY;
+
+ _outStream.Stream = outStream;
+ _outStream.Init();
+
+ Ppmd7z_RangeEnc_Init(&_rangeEnc);
+ Ppmd7_Init(&_ppmd, _order);
+
+ UInt64 processed = 0;
+ for (;;)
+ {
+ UInt32 size;
+ RINOK(inStream->Read(_inBuf, kBufSize, &size));
+ if (size == 0)
+ {
+ // We don't write EndMark in PPMD-7z.
+ // Ppmd7_EncodeSymbol(&_ppmd, &_rangeEnc, -1);
+ Ppmd7z_RangeEnc_FlushData(&_rangeEnc);
+ return _outStream.Flush();
+ }
+ for (UInt32 i = 0; i < size; i++)
+ {
+ Ppmd7_EncodeSymbol(&_ppmd, &_rangeEnc, _inBuf[i]);
+ RINOK(_outStream.Res);
+ }
+ processed += size;
+ if (progress)
+ {
+ UInt64 outSize = _outStream.GetProcessed();
+ RINOK(progress->SetRatioInfo(&processed, &outSize));
+ }
+ }
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdEncoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdEncoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdEncoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdEncoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,48 @@
+// PpmdEncoder.h
+// 2009-03-11 : Igor Pavlov : Public domain
+
+#ifndef __COMPRESS_PPMD_ENCODER_H
+#define __COMPRESS_PPMD_ENCODER_H
+
+#include "../../../C/Ppmd7.h"
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+#include "../Common/CWrappers.h"
+
+namespace NCompress {
+namespace NPpmd {
+
+class CEncoder :
+ public ICompressCoder,
+ public ICompressSetCoderProperties,
+ public ICompressWriteCoderProperties,
+ public CMyUnknownImp
+{
+ Byte *_inBuf;
+ CByteOutBufWrap _outStream;
+ CPpmd7z_RangeEnc _rangeEnc;
+ CPpmd7 _ppmd;
+
+ UInt32 _usedMemSize;
+ Byte _order;
+
+public:
+ MY_UNKNOWN_IMP2(
+ ICompressSetCoderProperties,
+ ICompressWriteCoderProperties)
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+ STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);
+ STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
+
+ CEncoder();
+ ~CEncoder();
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdRegister.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdRegister.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdRegister.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,21 @@
+// PpmdRegister.cpp
+// 2009-05-30 : Igor Pavlov : Public domain
+
+#include "StdAfx.h"
+
+#include "../Common/RegisterCodec.h"
+
+#include "PpmdDecoder.h"
+
+static void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NPpmd::CDecoder); }
+#ifndef EXTRACT_ONLY
+#include "PpmdEncoder.h"
+static void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NPpmd::CEncoder); }
+#else
+#define CreateCodecOut 0
+#endif
+
+static CCodecInfo g_CodecInfo =
+ { CreateCodec, CreateCodecOut, 0x030401, L"PPMD", 1, false };
+
+REGISTER_CODEC(PPMD)
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdZip.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdZip.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdZip.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdZip.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,223 @@
+// PpmdZip.cpp
+// 2010-03-24 : Igor Pavlov : Public domain
+
+#include "StdAfx.h"
+
+#include "../../../C/CpuArch.h"
+
+#include "../Common/StreamUtils.h"
+
+#include "PpmdZip.h"
+
+namespace NCompress {
+namespace NPpmdZip {
+
+static void *SzBigAlloc(void *, size_t size) { return BigAlloc(size); }
+static void SzBigFree(void *, void *address) { BigFree(address); }
+static ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };
+
+CDecoder::CDecoder(bool fullFileMode):
+ _fullFileMode(fullFileMode)
+{
+ _ppmd.Stream.In = &_inStream.p;
+ Ppmd8_Construct(&_ppmd);
+}
+
+CDecoder::~CDecoder()
+{
+ Ppmd8_Free(&_ppmd, &g_BigAlloc);
+}
+
+STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress)
+{
+ if (!_outStream.Alloc())
+ return E_OUTOFMEMORY;
+ if (!_inStream.Alloc(1 << 20))
+ return E_OUTOFMEMORY;
+
+ _inStream.Stream = inStream;
+ _inStream.Init();
+
+ {
+ Byte buf[2];
+ for (int i = 0; i < 2; i++)
+ buf[i] = _inStream.ReadByte();
+ if (_inStream.Extra)
+ return S_FALSE;
+
+ UInt32 val = GetUi16(buf);
+ UInt32 order = (val & 0xF) + 1;
+ UInt32 mem = ((val >> 4) & 0xFF) + 1;
+ UInt32 restor = (val >> 12);
+ if (order < 2 || restor > 2)
+ return S_FALSE;
+
+ #ifndef PPMD8_FREEZE_SUPPORT
+ if (restor == 2)
+ return E_NOTIMPL;
+ #endif
+
+ if (!Ppmd8_Alloc(&_ppmd, mem << 20, &g_BigAlloc))
+ return E_OUTOFMEMORY;
+
+ if (!Ppmd8_RangeDec_Init(&_ppmd))
+ return S_FALSE;
+ Ppmd8_Init(&_ppmd, order, restor);
+ }
+
+ bool wasFinished = false;
+ UInt64 processedSize = 0;
+ while (!outSize || processedSize < *outSize)
+ {
+ size_t size = kBufSize;
+ if (outSize != NULL)
+ {
+ const UInt64 rem = *outSize - processedSize;
+ if (size > rem)
+ size = (size_t)rem;
+ }
+ Byte *data = _outStream.Buf;
+ size_t i = 0;
+ int sym = 0;
+ do
+ {
+ sym = Ppmd8_DecodeSymbol(&_ppmd);
+ if (_inStream.Extra || sym < 0)
+ break;
+ data[i] = (Byte)sym;
+ }
+ while (++i != size);
+ processedSize += i;
+
+ RINOK(WriteStream(outStream, _outStream.Buf, i));
+
+ RINOK(_inStream.Res);
+ if (_inStream.Extra)
+ return S_FALSE;
+
+ if (sym < 0)
+ {
+ if (sym != -1)
+ return S_FALSE;
+ wasFinished = true;
+ break;
+ }
+ if (progress)
+ {
+ UInt64 inSize = _inStream.GetProcessed();
+ RINOK(progress->SetRatioInfo(&inSize, &processedSize));
+ }
+ }
+ RINOK(_inStream.Res);
+ if (_fullFileMode)
+ {
+ if (!wasFinished)
+ {
+ int res = Ppmd8_DecodeSymbol(&_ppmd);
+ RINOK(_inStream.Res);
+ if (_inStream.Extra || res != -1)
+ return S_FALSE;
+ }
+ if (!Ppmd8_RangeDec_IsFinishedOK(&_ppmd))
+ return S_FALSE;
+ }
+ return S_OK;
+}
+
+
+// ---------- Encoder ----------
+
+CEncoder::~CEncoder()
+{
+ Ppmd8_Free(&_ppmd, &g_BigAlloc);
+}
+
+HRESULT CEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps)
+{
+ for (UInt32 i = 0; i < numProps; i++)
+ {
+ const PROPVARIANT &prop = props[i];
+ if (prop.vt != VT_UI4)
+ return E_INVALIDARG;
+ UInt32 v = (UInt32)prop.ulVal;
+ switch(propIDs[i])
+ {
+ case NCoderPropID::kAlgorithm:
+ if (v > 1)
+ return E_INVALIDARG;
+ _restor = v;
+ break;
+ case NCoderPropID::kUsedMemorySize:
+ if (v < (1 << 20) || v > (1 << 28))
+ return E_INVALIDARG;
+ _usedMemInMB = v >> 20;
+ break;
+ case NCoderPropID::kOrder:
+ if (v < PPMD8_MIN_ORDER || v > PPMD8_MAX_ORDER)
+ return E_INVALIDARG;
+ _order = (Byte)v;
+ break;
+ default:
+ return E_INVALIDARG;
+ }
+ }
+ return S_OK;
+}
+
+CEncoder::CEncoder():
+ _usedMemInMB(16),
+ _order(6),
+ _restor(PPMD8_RESTORE_METHOD_RESTART)
+{
+ _ppmd.Stream.Out = &_outStream.p;
+ Ppmd8_Construct(&_ppmd);
+}
+
+HRESULT CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)
+{
+ if (!_inStream.Alloc())
+ return E_OUTOFMEMORY;
+ if (!_outStream.Alloc(1 << 20))
+ return E_OUTOFMEMORY;
+ if (!Ppmd8_Alloc(&_ppmd, _usedMemInMB << 20, &g_BigAlloc))
+ return E_OUTOFMEMORY;
+
+ _outStream.Stream = outStream;
+ _outStream.Init();
+
+ Ppmd8_RangeEnc_Init(&_ppmd);
+ Ppmd8_Init(&_ppmd, _order, _restor);
+
+ UInt32 val = (UInt32)((_order - 1) + ((_usedMemInMB - 1) << 4) + (_restor << 12));
+ _outStream.WriteByte((Byte)(val & 0xFF));
+ _outStream.WriteByte((Byte)(val >> 8));
+ RINOK(_outStream.Res);
+
+ UInt64 processed = 0;
+ for (;;)
+ {
+ UInt32 size;
+ RINOK(inStream->Read(_inStream.Buf, kBufSize, &size));
+ if (size == 0)
+ {
+ Ppmd8_EncodeSymbol(&_ppmd, -1);
+ Ppmd8_RangeEnc_FlushData(&_ppmd);
+ return _outStream.Flush();
+ }
+ for (UInt32 i = 0; i < size; i++)
+ {
+ Ppmd8_EncodeSymbol(&_ppmd, _inStream.Buf[i]);
+ RINOK(_outStream.Res);
+ }
+ processed += size;
+ if (progress != NULL)
+ {
+ UInt64 outSize = _outStream.GetProcessed();
+ RINOK(progress->SetRatioInfo(&processed, &outSize));
+ }
+ }
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdZip.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdZip.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdZip.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/PpmdZip.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,72 @@
+// PpmdZip.h
+// 2010-03-11 : Igor Pavlov : Public domain
+
+#ifndef __COMPRESS_PPMD_ZIP_H
+#define __COMPRESS_PPMD_ZIP_H
+
+#include "../../../C/Alloc.h"
+#include "../../../C/Ppmd8.h"
+
+#include "../../Common/MyCom.h"
+
+#include "../Common/CWrappers.h"
+
+#include "../ICoder.h"
+
+namespace NCompress {
+namespace NPpmdZip {
+
+static const UInt32 kBufSize = (1 << 20);
+
+struct CBuf
+{
+ Byte *Buf;
+
+ CBuf(): Buf(0) {}
+ ~CBuf() { ::MidFree(Buf); }
+ bool Alloc()
+ {
+ if (!Buf)
+ Buf = (Byte *)::MidAlloc(kBufSize);
+ return (Buf != 0);
+ }
+};
+
+class CDecoder :
+ public ICompressCoder,
+ public CMyUnknownImp
+{
+ CByteInBufWrap _inStream;
+ CBuf _outStream;
+ CPpmd8 _ppmd;
+ bool _fullFileMode;
+public:
+ MY_UNKNOWN_IMP
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+ CDecoder(bool fullFileMode);
+ ~CDecoder();
+};
+
+class CEncoder :
+ public ICompressCoder,
+ public CMyUnknownImp
+{
+ CByteOutBufWrap _outStream;
+ CBuf _inStream;
+ CPpmd8 _ppmd;
+ UInt32 _usedMemInMB;
+ unsigned _order;
+ unsigned _restor;
+public:
+ MY_UNKNOWN_IMP
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+ HRESULT SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps);
+ CEncoder();
+ ~CEncoder();
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/QuantumDecoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/QuantumDecoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/QuantumDecoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/QuantumDecoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,175 @@
+// QuantumDecoder.cpp
+
+#include "StdAfx.h"
+
+#include "../../Common/Defs.h"
+
+#include "QuantumDecoder.h"
+
+namespace NCompress {
+namespace NQuantum {
+
+static const int kLenIdNeedInit = -2;
+
+static const unsigned kNumLenSymbols = 27;
+static const unsigned kMatchMinLen = 3;
+static const unsigned kNumSimplePosSlots = 4;
+static const unsigned kNumSimpleLenSlots = 6;
+
+void CDecoder::Init()
+{
+ m_Selector.Init(kNumSelectors);
+ unsigned i;
+ for (i = 0; i < kNumLitSelectors; i++)
+ m_Literals[i].Init(kNumLitSymbols);
+ unsigned numItems = (_numDictBits == 0 ? 1 : (_numDictBits << 1));
+ const unsigned kNumPosSymbolsMax[kNumMatchSelectors] = { 24, 36, 42 };
+ for (i = 0; i < kNumMatchSelectors; i++)
+ m_PosSlot[i].Init(MyMin(numItems, kNumPosSymbolsMax[i]));
+ m_LenSlot.Init(kNumLenSymbols);
+}
+
+HRESULT CDecoder::CodeSpec(UInt32 curSize)
+{
+ if (_remainLen == kLenIdNeedInit)
+ {
+ if (!_keepHistory)
+ {
+ if (!_outWindowStream.Create((UInt32)1 << _numDictBits))
+ return E_OUTOFMEMORY;
+ Init();
+ }
+ if (!_rangeDecoder.Create(1 << 20))
+ return E_OUTOFMEMORY;
+ _rangeDecoder.Init();
+ _remainLen = 0;
+ }
+ if (curSize == 0)
+ return S_OK;
+
+ while (_remainLen > 0 && curSize > 0)
+ {
+ _remainLen--;
+ Byte b = _outWindowStream.GetByte(_rep0);
+ _outWindowStream.PutByte(b);
+ curSize--;
+ }
+
+ while (curSize > 0)
+ {
+ if (_rangeDecoder.Stream.WasFinished())
+ return S_FALSE;
+
+ unsigned selector = m_Selector.Decode(&_rangeDecoder);
+ if (selector < kNumLitSelectors)
+ {
+ Byte b = (Byte)((selector << (8 - kNumLitSelectorBits)) + m_Literals[selector].Decode(&_rangeDecoder));
+ _outWindowStream.PutByte(b);
+ curSize--;
+ }
+ else
+ {
+ selector -= kNumLitSelectors;
+ unsigned len = selector + kMatchMinLen;
+ if (selector == 2)
+ {
+ unsigned lenSlot = m_LenSlot.Decode(&_rangeDecoder);
+ if (lenSlot >= kNumSimpleLenSlots)
+ {
+ lenSlot -= 2;
+ int numDirectBits = (int)(lenSlot >> 2);
+ len += ((4 | (lenSlot & 3)) << numDirectBits) - 2;
+ if (numDirectBits < 6)
+ len += _rangeDecoder.Stream.ReadBits(numDirectBits);
+ }
+ else
+ len += lenSlot;
+ }
+ UInt32 rep0 = m_PosSlot[selector].Decode(&_rangeDecoder);
+ if (rep0 >= kNumSimplePosSlots)
+ {
+ int numDirectBits = (int)((rep0 >> 1) - 1);
+ rep0 = ((2 | (rep0 & 1)) << numDirectBits) + _rangeDecoder.Stream.ReadBits(numDirectBits);
+ }
+ unsigned locLen = len;
+ if (len > curSize)
+ locLen = (unsigned)curSize;
+ if (!_outWindowStream.CopyBlock(rep0, locLen))
+ return S_FALSE;
+ curSize -= locLen;
+ len -= locLen;
+ if (len != 0)
+ {
+ _remainLen = (int)len;
+ _rep0 = rep0;
+ break;
+ }
+ }
+ }
+ return _rangeDecoder.Stream.WasFinished() ? S_FALSE : S_OK;
+}
+
+HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *, const UInt64 *outSize, ICompressProgressInfo *progress)
+{
+ if (outSize == NULL)
+ return E_INVALIDARG;
+ UInt64 size = *outSize;
+
+ SetInStream(inStream);
+ _outWindowStream.SetStream(outStream);
+ SetOutStreamSize(outSize);
+ CDecoderFlusher flusher(this);
+
+ const UInt64 start = _outWindowStream.GetProcessedSize();
+ for (;;)
+ {
+ UInt32 curSize = 1 << 18;
+ UInt64 rem = size - (_outWindowStream.GetProcessedSize() - start);
+ if (curSize > rem)
+ curSize = (UInt32)rem;
+ if (curSize == 0)
+ break;
+ RINOK(CodeSpec(curSize));
+ if (progress != NULL)
+ {
+ UInt64 inSize = _rangeDecoder.GetProcessedSize();
+ UInt64 nowPos64 = _outWindowStream.GetProcessedSize() - start;
+ RINOK(progress->SetRatioInfo(&inSize, &nowPos64));
+ }
+ }
+ flusher.NeedFlush = false;
+ return 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 CInBufferException &e) { return e.ErrorCode; }
+ catch(const CLzOutWindowException &e) { return e.ErrorCode; }
+ catch(...) { return S_FALSE; }
+}
+
+STDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream)
+{
+ _rangeDecoder.SetStream(inStream);
+ return S_OK;
+}
+
+STDMETHODIMP CDecoder::ReleaseInStream()
+{
+ _rangeDecoder.ReleaseStream();
+ return S_OK;
+}
+
+STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)
+{
+ if (outSize == NULL)
+ return E_FAIL;
+ _remainLen = kLenIdNeedInit;
+ _outWindowStream.Init(_keepHistory);
+ return S_OK;
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/QuantumDecoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/QuantumDecoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/QuantumDecoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/QuantumDecoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,264 @@
+// QuantumDecoder.h
+
+#ifndef __COMPRESS_QUANTUM_DECODER_H
+#define __COMPRESS_QUANTUM_DECODER_H
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+#include "../Common/InBuffer.h"
+
+#include "LzOutWindow.h"
+
+namespace NCompress {
+namespace NQuantum {
+
+class CStreamBitDecoder
+{
+ UInt32 Value;
+ CInBuffer Stream;
+public:
+ bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }
+ void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }
+ void ReleaseStream() { Stream.ReleaseStream(); }
+
+ void Finish() { Value = 0x10000; }
+
+ void Init()
+ {
+ Stream.Init();
+ Value = 0x10000;
+ }
+
+ UInt64 GetProcessedSize() const { return Stream.GetProcessedSize(); }
+ bool WasFinished() const { return Stream.WasFinished(); }
+
+ UInt32 ReadBit()
+ {
+ if (Value >= 0x10000)
+ Value = 0x100 | Stream.ReadByte();
+ UInt32 res = (Value >> 7) & 1;
+ Value <<= 1;
+ return res;
+ }
+
+ UInt32 ReadBits(int numBits) // numBits > 0
+ {
+ UInt32 res = 0;
+ do
+ res = (res << 1) | ReadBit();
+ while (--numBits != 0);
+ return res;
+ }
+};
+
+const unsigned kNumLitSelectorBits = 2;
+const unsigned kNumLitSelectors = (1 << kNumLitSelectorBits);
+const unsigned kNumLitSymbols = 1 << (8 - kNumLitSelectorBits);
+const unsigned kNumMatchSelectors = 3;
+const unsigned kNumSelectors = kNumLitSelectors + kNumMatchSelectors;
+const unsigned kNumSymbolsMax = kNumLitSymbols; // 64
+
+namespace NRangeCoder {
+
+class CDecoder
+{
+ UInt32 Low;
+ UInt32 Range;
+ UInt32 Code;
+public:
+ CStreamBitDecoder Stream;
+ bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }
+ void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }
+ void ReleaseStream() { Stream.ReleaseStream(); }
+
+ void Init()
+ {
+ Stream.Init();
+ Low = 0;
+ Range = 0x10000;
+ Code = Stream.ReadBits(16);
+ }
+
+ void Finish()
+ {
+ // we need these extra two Bit_reads
+ Stream.ReadBit();
+ Stream.ReadBit();
+ Stream.Finish();
+ }
+
+ UInt64 GetProcessedSize() const { return Stream.GetProcessedSize(); }
+
+ UInt32 GetThreshold(UInt32 total) const
+ {
+ return ((Code + 1) * total - 1) / Range; // & 0xFFFF is not required;
+ }
+
+ void Decode(UInt32 start, UInt32 end, UInt32 total)
+ {
+ UInt32 high = Low + end * Range / total - 1;
+ UInt32 offset = start * Range / total;
+ Code -= offset;
+ Low += offset;
+ for (;;)
+ {
+ if ((Low & 0x8000) != (high & 0x8000))
+ {
+ if ((Low & 0x4000) == 0 || (high & 0x4000) != 0)
+ break;
+ Low &= 0x3FFF;
+ high |= 0x4000;
+ }
+ Low = (Low << 1) & 0xFFFF;
+ high = ((high << 1) | 1) & 0xFFFF;
+ Code = ((Code << 1) | Stream.ReadBit());
+ }
+ Range = high - Low + 1;
+ }
+};
+
+const UInt16 kUpdateStep = 8;
+const UInt16 kFreqSumMax = 3800;
+const UInt16 kReorderCountStart = 4;
+const UInt16 kReorderCount = 50;
+
+class CModelDecoder
+{
+ unsigned NumItems;
+ unsigned ReorderCount;
+ UInt16 Freqs[kNumSymbolsMax + 1];
+ Byte Values[kNumSymbolsMax];
+public:
+ void Init(unsigned numItems)
+ {
+ NumItems = numItems;
+ ReorderCount = kReorderCountStart;
+ for (unsigned i = 0; i < numItems; i++)
+ {
+ Freqs[i] = (UInt16)(numItems - i);
+ Values[i] = (Byte)i;
+ }
+ Freqs[numItems] = 0;
+ }
+
+ unsigned Decode(CDecoder *rangeDecoder)
+ {
+ UInt32 threshold = rangeDecoder->GetThreshold(Freqs[0]);
+ unsigned i;
+ for (i = 1; Freqs[i] > threshold; i++);
+ rangeDecoder->Decode(Freqs[i], Freqs[i - 1], Freqs[0]);
+ unsigned res = Values[--i];
+ do
+ Freqs[i] += kUpdateStep;
+ while (i-- != 0);
+
+ if (Freqs[0] > kFreqSumMax)
+ {
+ if (--ReorderCount == 0)
+ {
+ ReorderCount = kReorderCount;
+ for (i = 0; i < NumItems; i++)
+ Freqs[i] = (UInt16)(((Freqs[i] - Freqs[i + 1]) + 1) >> 1);
+ for (i = 0; i < NumItems - 1; i++)
+ for (unsigned j = i + 1; j < NumItems; j++)
+ if (Freqs[i] < Freqs[j])
+ {
+ UInt16 tmpFreq = Freqs[i];
+ Byte tmpVal = Values[i];
+ Freqs[i] = Freqs[j];
+ Values[i] = Values[j];
+ Freqs[j] = tmpFreq;
+ Values[j] = tmpVal;
+ }
+ do
+ Freqs[i] = (UInt16)(Freqs[i] + Freqs[i + 1]);
+ while (i-- != 0);
+ }
+ else
+ {
+ i = NumItems - 1;
+ do
+ {
+ Freqs[i] >>= 1;
+ if (Freqs[i] <= Freqs[i + 1])
+ Freqs[i] = (UInt16)(Freqs[i + 1] + 1);
+ }
+ while (i-- != 0);
+ }
+ }
+ return res;
+ }
+};
+
+}
+
+class CDecoder:
+ public ICompressCoder,
+ public ICompressSetInStream,
+ public ICompressSetOutStreamSize,
+ public CMyUnknownImp
+{
+ CLzOutWindow _outWindowStream;
+ NRangeCoder::CDecoder _rangeDecoder;
+
+ UInt64 _outSize;
+ int _remainLen; // -1 means end of stream. // -2 means need Init
+ UInt32 _rep0;
+
+ int _numDictBits;
+ bool _keepHistory;
+
+ NRangeCoder::CModelDecoder m_Selector;
+ NRangeCoder::CModelDecoder m_Literals[kNumLitSelectors];
+ NRangeCoder::CModelDecoder m_PosSlot[kNumMatchSelectors];
+ NRangeCoder::CModelDecoder m_LenSlot;
+ void Init();
+ HRESULT CodeSpec(UInt32 size);
+public:
+ MY_UNKNOWN_IMP2(
+ ICompressSetInStream,
+ ICompressSetOutStreamSize)
+
+ void ReleaseStreams()
+ {
+ _outWindowStream.ReleaseStream();
+ ReleaseInStream();
+ }
+
+ class CDecoderFlusher
+ {
+ CDecoder *_decoder;
+ public:
+ bool NeedFlush;
+ CDecoderFlusher(CDecoder *decoder): _decoder(decoder), NeedFlush(true) {}
+ ~CDecoderFlusher()
+ {
+ if (NeedFlush)
+ _decoder->Flush();
+ _decoder->ReleaseStreams();
+ }
+ };
+
+ HRESULT Flush() { return _outWindowStream.Flush(); }
+
+ HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ STDMETHOD(SetInStream)(ISequentialInStream *inStream);
+ STDMETHOD(ReleaseInStream)();
+ STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);
+
+ void SetParams(int numDictBits) { _numDictBits = numDictBits; }
+ void SetKeepHistory(bool keepHistory) { _keepHistory = keepHistory; }
+ CDecoder(): _keepHistory(false) {}
+ virtual ~CDecoder() {}
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/RangeCoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/RangeCoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/RangeCoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/RangeCoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,205 @@
+// Compress/RangeCoder.h
+// 2009-05-30 : Igor Pavlov : Public domain
+
+#ifndef __COMPRESS_RANGE_CODER_H
+#define __COMPRESS_RANGE_CODER_H
+
+#include "../Common/InBuffer.h"
+#include "../Common/OutBuffer.h"
+
+namespace NCompress {
+namespace NRangeCoder {
+
+const int kNumTopBits = 24;
+const UInt32 kTopValue = (1 << kNumTopBits);
+
+class CEncoder
+{
+ UInt32 _cacheSize;
+ Byte _cache;
+public:
+ UInt64 Low;
+ UInt32 Range;
+ COutBuffer Stream;
+ bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }
+
+ void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }
+ void Init()
+ {
+ Stream.Init();
+ Low = 0;
+ Range = 0xFFFFFFFF;
+ _cacheSize = 1;
+ _cache = 0;
+ }
+
+ void FlushData()
+ {
+ // Low += 1;
+ for(int i = 0; i < 5; i++)
+ ShiftLow();
+ }
+
+ HRESULT FlushStream() { return Stream.Flush(); }
+
+ void ReleaseStream() { Stream.ReleaseStream(); }
+
+ void Encode(UInt32 start, UInt32 size, UInt32 total)
+ {
+ Low += start * (Range /= total);
+ Range *= size;
+ while (Range < kTopValue)
+ {
+ Range <<= 8;
+ ShiftLow();
+ }
+ }
+
+ void ShiftLow()
+ {
+ if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0)
+ {
+ Byte temp = _cache;
+ do
+ {
+ Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));
+ temp = 0xFF;
+ }
+ while(--_cacheSize != 0);
+ _cache = (Byte)((UInt32)Low >> 24);
+ }
+ _cacheSize++;
+ Low = (UInt32)Low << 8;
+ }
+
+ void EncodeDirectBits(UInt32 value, int numBits)
+ {
+ for (numBits--; numBits >= 0; numBits--)
+ {
+ Range >>= 1;
+ Low += Range & (0 - ((value >> numBits) & 1));
+ if (Range < kTopValue)
+ {
+ Range <<= 8;
+ ShiftLow();
+ }
+ }
+ }
+
+ void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)
+ {
+ UInt32 newBound = (Range >> numTotalBits) * size0;
+ if (symbol == 0)
+ Range = newBound;
+ else
+ {
+ Low += newBound;
+ Range -= newBound;
+ }
+ while (Range < kTopValue)
+ {
+ Range <<= 8;
+ ShiftLow();
+ }
+ }
+
+ UInt64 GetProcessedSize() { return Stream.GetProcessedSize() + _cacheSize + 4; }
+};
+
+class CDecoder
+{
+public:
+ CInBuffer Stream;
+ UInt32 Range;
+ UInt32 Code;
+ bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }
+
+ void Normalize()
+ {
+ while (Range < kTopValue)
+ {
+ Code = (Code << 8) | Stream.ReadByte();
+ Range <<= 8;
+ }
+ }
+
+ void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }
+ void Init()
+ {
+ Stream.Init();
+ Code = 0;
+ Range = 0xFFFFFFFF;
+ for(int i = 0; i < 5; i++)
+ Code = (Code << 8) | Stream.ReadByte();
+ }
+
+ void ReleaseStream() { Stream.ReleaseStream(); }
+
+ UInt32 GetThreshold(UInt32 total)
+ {
+ return (Code) / ( Range /= total);
+ }
+
+ void Decode(UInt32 start, UInt32 size)
+ {
+ Code -= start * Range;
+ Range *= size;
+ Normalize();
+ }
+
+ UInt32 DecodeDirectBits(int numTotalBits)
+ {
+ UInt32 range = Range;
+ UInt32 code = Code;
+ UInt32 result = 0;
+ for (int i = numTotalBits; i != 0; i--)
+ {
+ range >>= 1;
+ /*
+ result <<= 1;
+ if (code >= range)
+ {
+ code -= range;
+ result |= 1;
+ }
+ */
+ UInt32 t = (code - range) >> 31;
+ code -= range & (t - 1);
+ result = (result << 1) | (1 - t);
+
+ if (range < kTopValue)
+ {
+ code = (code << 8) | Stream.ReadByte();
+ range <<= 8;
+ }
+ }
+ Range = range;
+ Code = code;
+ return result;
+ }
+
+ UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)
+ {
+ UInt32 newBound = (Range >> numTotalBits) * size0;
+ UInt32 symbol;
+ if (Code < newBound)
+ {
+ symbol = 0;
+ Range = newBound;
+ }
+ else
+ {
+ symbol = 1;
+ Code -= newBound;
+ Range -= newBound;
+ }
+ Normalize();
+ return symbol;
+ }
+
+ UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/RangeCoderBit.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/RangeCoderBit.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/RangeCoderBit.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/RangeCoderBit.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,114 @@
+// Compress/RangeCoderBit.h
+// 2009-05-30 : Igor Pavlov : Public domain
+
+#ifndef __COMPRESS_RANGE_CODER_BIT_H
+#define __COMPRESS_RANGE_CODER_BIT_H
+
+#include "RangeCoder.h"
+
+namespace NCompress {
+namespace NRangeCoder {
+
+const int kNumBitModelTotalBits = 11;
+const UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);
+
+const int kNumMoveReducingBits = 4;
+
+const int kNumBitPriceShiftBits = 4;
+const UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;
+
+extern UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
+
+template <int numMoveBits>
+class CBitModel
+{
+public:
+ UInt32 Prob;
+ void UpdateModel(UInt32 symbol)
+ {
+ /*
+ Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;
+ Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);
+ */
+ if (symbol == 0)
+ Prob += (kBitModelTotal - Prob) >> numMoveBits;
+ else
+ Prob -= (Prob) >> numMoveBits;
+ }
+public:
+ void Init() { Prob = kBitModelTotal / 2; }
+};
+
+template <int numMoveBits>
+class CBitEncoder: public CBitModel<numMoveBits>
+{
+public:
+ void Encode(CEncoder *encoder, UInt32 symbol)
+ {
+ /*
+ encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);
+ this->UpdateModel(symbol);
+ */
+ UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;
+ if (symbol == 0)
+ {
+ encoder->Range = newBound;
+ this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;
+ }
+ else
+ {
+ encoder->Low += newBound;
+ encoder->Range -= newBound;
+ this->Prob -= (this->Prob) >> numMoveBits;
+ }
+ if (encoder->Range < kTopValue)
+ {
+ encoder->Range <<= 8;
+ encoder->ShiftLow();
+ }
+ }
+ UInt32 GetPrice(UInt32 symbol) const
+ {
+ return ProbPrices[(this->Prob ^ ((-(int)symbol)) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];
+ }
+ UInt32 GetPrice0() const { return ProbPrices[this->Prob >> kNumMoveReducingBits]; }
+ UInt32 GetPrice1() const { return ProbPrices[(this->Prob ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]; }
+};
+
+
+template <int numMoveBits>
+class CBitDecoder: public CBitModel<numMoveBits>
+{
+public:
+ UInt32 Decode(CDecoder *decoder)
+ {
+ UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;
+ if (decoder->Code < newBound)
+ {
+ decoder->Range = newBound;
+ this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;
+ if (decoder->Range < kTopValue)
+ {
+ decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();
+ decoder->Range <<= 8;
+ }
+ return 0;
+ }
+ else
+ {
+ decoder->Range -= newBound;
+ decoder->Code -= newBound;
+ this->Prob -= (this->Prob) >> numMoveBits;
+ if (decoder->Range < kTopValue)
+ {
+ decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();
+ decoder->Range <<= 8;
+ }
+ return 1;
+ }
+ }
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar/makefile
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar/makefile?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar/makefile (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar/makefile Sun Dec 16 23:23:25 2012
@@ -0,0 +1,34 @@
+PROG=../../../../bin/Codecs/Rar29.so
+
+LOCAL_FLAGS=$(CC_SHARED) -DUNICODE -D_UNICODE
+
+MY_WINDOWS=
+
+include ../../../../makefile.crc32
+include ../../../../makefile.machine
+
+LOCAL_SHARED=$(LINK_SHARED)
+LIBS=$(LOCAL_LIBS)
+
+OBJS = \
+MyWindows.o \
+CRC.o\
+MyVector.o\
+CodecExports.o \
+DllExports.o \
+Rar1Decoder.o \
+Rar2Decoder.o \
+Rar3Decoder.o \
+Rar3Vm.o \
+RarCodecsRegister.o \
+$(OBJ_CRC32) \
+InBuffer.o \
+OutBuffer.o \
+StreamUtils.o \
+LzOutWindow.o \
+Ppmd7.o \
+Ppmd7Dec.o \
+Alloc.o
+
+include ../../../../makefile.glb
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar/makefile.depend
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar/makefile.depend?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar/makefile.depend (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar/makefile.depend Sun Dec 16 23:23:25 2012
@@ -0,0 +1,158 @@
+CRC.o: ../../../Common/CRC.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Common/../../C/7zCrc.h \
+ ../../../Common/../../C/Types.h
+MyWindows.o: ../../../Common/MyWindows.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Common/MyWindows.h
+MyVector.o: ../../../Common/MyVector.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Common/MyVector.h \
+ ../../../Common/Defs.h
+InBuffer.o: ../../Common/InBuffer.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../Common/../../../C/Alloc.h \
+ ../../Common/InBuffer.h ../../Common/../IStream.h \
+ ../../Common/../../Common/MyUnknown.h \
+ ../../Common/../../Common/MyWindows.h ../../Common/../../Common/Types.h \
+ ../../Common/../IDecl.h ../../Common/../../Common/MyCom.h \
+ ../../Common/../../Common/MyException.h
+StreamUtils.o: ../../Common/StreamUtils.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../Common/StreamUtils.h \
+ ../../Common/../IStream.h ../../Common/../../Common/MyUnknown.h \
+ ../../Common/../../Common/MyWindows.h ../../Common/../../Common/Types.h \
+ ../../Common/../IDecl.h
+OutBuffer.o: ../../Common/OutBuffer.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../Common/../../../C/Alloc.h \
+ ../../Common/OutBuffer.h ../../Common/../IStream.h \
+ ../../Common/../../Common/MyUnknown.h \
+ ../../Common/../../Common/MyWindows.h ../../Common/../../Common/Types.h \
+ ../../Common/../IDecl.h ../../Common/../../Common/MyCom.h \
+ ../../Common/../../Common/MyException.h
+LzOutWindow.o: ../LzOutWindow.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../LzOutWindow.h ../../IStream.h \
+ ../../../Common/MyUnknown.h ../../../Common/MyWindows.h \
+ ../../../Common/Types.h ../../IDecl.h ../../Common/OutBuffer.h \
+ ../../Common/../IStream.h ../../Common/../../Common/MyCom.h \
+ ../../Common/../../Common/MyWindows.h \
+ ../../Common/../../Common/MyException.h
+CodecExports.o: ../CodecExports.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Common/ComTry.h \
+ ../../../Common/MyWindows.h ../../../Windows/PropVariant.h \
+ ../../../Windows/../Common/MyWindows.h \
+ ../../../Windows/../Common/Types.h ../../ICoder.h ../../IStream.h \
+ ../../../Common/MyUnknown.h ../../../Common/Types.h ../../IDecl.h \
+ ../../Common/RegisterCodec.h ../../Common/../Common/MethodId.h \
+ ../../Common/../Common/../../Common/Types.h
+DllExports.o: ../DllExports.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Common/MyInitGuid.h \
+ ../../ICoder.h ../../IStream.h ../../../Common/MyUnknown.h \
+ ../../../Common/MyWindows.h ../../../Common/Types.h ../../IDecl.h \
+ ../../Common/RegisterCodec.h ../../Common/../Common/MethodId.h \
+ ../../Common/../Common/../../Common/Types.h
+Rar1Decoder.o: ../Rar1Decoder.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../Rar1Decoder.h \
+ ../../../Common/MyCom.h ../../../Common/MyWindows.h ../../ICoder.h \
+ ../../IStream.h ../../../Common/MyUnknown.h ../../../Common/Types.h \
+ ../../IDecl.h ../../Common/InBuffer.h ../../Common/../IStream.h \
+ ../../Common/../../Common/MyCom.h \
+ ../../Common/../../Common/MyException.h \
+ ../../Common/../../Common/MyWindows.h ../BitmDecoder.h ../../IStream.h \
+ ../HuffmanDecoder.h ../../../Common/Types.h ../LzOutWindow.h \
+ ../../Common/OutBuffer.h
+Rar2Decoder.o: ../Rar2Decoder.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../Rar2Decoder.h \
+ ../../../Common/MyCom.h ../../../Common/MyWindows.h ../../ICoder.h \
+ ../../IStream.h ../../../Common/MyUnknown.h ../../../Common/Types.h \
+ ../../IDecl.h ../../Common/InBuffer.h ../../Common/../IStream.h \
+ ../../Common/../../Common/MyCom.h \
+ ../../Common/../../Common/MyException.h \
+ ../../Common/../../Common/MyWindows.h ../BitmDecoder.h ../../IStream.h \
+ ../HuffmanDecoder.h ../../../Common/Types.h ../LzOutWindow.h \
+ ../../Common/OutBuffer.h
+Rar3Decoder.o: ../Rar3Decoder.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../../C/Alloc.h \
+ ../../Common/StreamUtils.h ../../Common/../IStream.h \
+ ../../Common/../../Common/MyUnknown.h \
+ ../../Common/../../Common/MyWindows.h ../../Common/../../Common/Types.h \
+ ../../Common/../IDecl.h ../Rar3Decoder.h ../../../../C/Ppmd7.h \
+ ../../../../C/Ppmd.h ../../../../C/Types.h ../../../../C/CpuArch.h \
+ ../../../Common/MyCom.h ../../../Common/MyWindows.h ../../ICoder.h \
+ ../../IStream.h ../../Common/InBuffer.h \
+ ../../Common/../../Common/MyCom.h \
+ ../../Common/../../Common/MyException.h ../BitmDecoder.h ../../IStream.h \
+ ../HuffmanDecoder.h ../../../Common/Types.h ../Rar3Vm.h \
+ ../../../../C/CpuArch.h ../../../Common/MyVector.h \
+ ../../../Common/Defs.h
+Rar3Vm.o: ../Rar3Vm.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../../C/7zCrc.h \
+ ../../../../C/Types.h ../../../../C/Alloc.h ../Rar3Vm.h \
+ ../../../../C/CpuArch.h ../../../Common/MyVector.h \
+ ../../../Common/Defs.h
+RarCodecsRegister.o: ../RarCodecsRegister.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../Common/RegisterCodec.h \
+ ../../Common/../Common/MethodId.h \
+ ../../Common/../Common/../../Common/Types.h ../Rar1Decoder.h \
+ ../../../Common/MyCom.h ../../../Common/MyWindows.h ../../ICoder.h \
+ ../../IStream.h ../../../Common/MyUnknown.h ../../../Common/Types.h \
+ ../../IDecl.h ../../Common/InBuffer.h ../../Common/../IStream.h \
+ ../../Common/../../Common/MyCom.h \
+ ../../Common/../../Common/MyException.h \
+ ../../Common/../../Common/MyWindows.h ../BitmDecoder.h ../../IStream.h \
+ ../HuffmanDecoder.h ../../../Common/Types.h ../LzOutWindow.h \
+ ../../Common/OutBuffer.h ../Rar2Decoder.h ../Rar3Decoder.h \
+ ../../../../C/Ppmd7.h ../../../../C/Ppmd.h ../../../../C/Types.h \
+ ../../../../C/CpuArch.h ../Rar3Vm.h ../../../../C/CpuArch.h \
+ ../../../Common/MyVector.h ../../../Common/Defs.h
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar/makefile.list
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar/makefile.list?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar/makefile.list (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar/makefile.list Sun Dec 16 23:23:25 2012
@@ -0,0 +1,64 @@
+SRCS=\
+ ../../../Common/CRC.cpp \
+ ../../../Common/MyWindows.cpp \
+ ../../../Common/MyVector.cpp \
+ ../../Common/InBuffer.cpp \
+ ../../Common/StreamUtils.cpp \
+ ../../Common/OutBuffer.cpp \
+../LzOutWindow.cpp \
+../CodecExports.cpp \
+../DllExports.cpp \
+../Rar1Decoder.cpp \
+../Rar2Decoder.cpp \
+../Rar3Decoder.cpp \
+../Rar3Vm.cpp \
+../RarCodecsRegister.cpp
+
+SRCS_C=\
+ ../../../../C/Alloc.c \
+ ../../../../C/Ppmd7.c \
+ ../../../../C/Ppmd7Dec.c
+
+CRC.o : ../../../Common/CRC.cpp
+ $(CXX) $(CC_SHARED) $(CXXFLAGS) ../../../Common/CRC.cpp
+MyWindows.o : ../../../Common/MyWindows.cpp
+ $(CXX) $(CC_SHARED) $(CXXFLAGS) ../../../Common/MyWindows.cpp
+MyVector.o : ../../../Common/MyVector.cpp
+ $(CXX) $(CC_SHARED) $(CXXFLAGS) ../../../Common/MyVector.cpp
+DllExports.o : ../DllExports.cpp
+ $(CXX) $(CC_SHARED) $(CXXFLAGS) ../DllExports.cpp
+CodecExports.o : ../CodecExports.cpp
+ $(CXX) $(CC_SHARED) $(CXXFLAGS) ../CodecExports.cpp
+InBuffer.o : ../../Common/InBuffer.cpp
+ $(CXX) $(CC_SHARED) $(CXXFLAGS) ../../Common/InBuffer.cpp
+LzOutWindow.o : ../LzOutWindow.cpp
+ $(CXX) $(CC_SHARED) $(CXXFLAGS) ../LzOutWindow.cpp
+StreamUtils.o : ../../Common/StreamUtils.cpp
+ $(CXX) $(CC_SHARED) $(CXXFLAGS) ../../Common/StreamUtils.cpp
+OutBuffer.o : ../../Common/OutBuffer.cpp
+ $(CXX) $(CC_SHARED) $(CXXFLAGS) ../../Common/OutBuffer.cpp
+Rar1Decoder.o : ../Rar1Decoder.cpp
+ $(CXX) $(CC_SHARED) $(CXXFLAGS) ../Rar1Decoder.cpp
+Rar2Decoder.o : ../Rar2Decoder.cpp
+ $(CXX) $(CC_SHARED) $(CXXFLAGS) ../Rar2Decoder.cpp
+Rar3Decoder.o : ../Rar3Decoder.cpp
+ $(CXX) $(CC_SHARED) $(CXXFLAGS) ../Rar3Decoder.cpp
+Rar3Vm.o : ../Rar3Vm.cpp
+ $(CXX) $(CC_SHARED) $(CXXFLAGS) ../Rar3Vm.cpp
+RarCodecsRegister.o : ../RarCodecsRegister.cpp
+ $(CXX) $(CC_SHARED) $(CXXFLAGS) ../RarCodecsRegister.cpp
+Alloc.o : ../../../../C/Alloc.c
+ $(CC) $(CC_SHARED) $(CFLAGS) ../../../../C/Alloc.c
+Ppmd7.o : ../../../../C/Ppmd7.c
+ $(CC) $(CC_SHARED) $(CFLAGS) ../../../../C/Ppmd7.c
+Ppmd7Dec.o : ../../../../C/Ppmd7Dec.c
+ $(CC) $(CC_SHARED) $(CFLAGS) ../../../../C/Ppmd7Dec.c
+
+# CRC32, C version
+7zCrc.o : ../../../../C/7zCrc.c
+ $(CC) $(CC_SHARED) $(CFLAGS) ../../../../C/7zCrc.c
+7zCrcOpt.o : ../../../../C/7zCrcOpt.c
+ $(CC) $(CC_SHARED) $(CFLAGS) ../../../../C/7zCrcOpt.c
+# CRC32, ASM version
+7zCrcT8.o : ../../../../C/7zCrcT8.c
+ $(CC) $(CC_SHARED) $(CFLAGS) ../../../../C/7zCrcT8.c
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar1Decoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar1Decoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar1Decoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar1Decoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,480 @@
+// Rar1Decoder.cpp
+// According to unRAR license, this code may not be used to develop
+// a program that creates RAR archives
+
+#include "StdAfx.h"
+
+#include "Rar1Decoder.h"
+
+namespace NCompress {
+namespace NRar1 {
+
+static UInt32 PosL1[]={0,0,0,2,3,5,7,11,16,20,24,32,32, 256};
+static UInt32 PosL2[]={0,0,0,0,5,7,9,13,18,22,26,34,36, 256};
+static UInt32 PosHf0[]={0,0,0,0,0,8,16,24,33,33,33,33,33, 257};
+static UInt32 PosHf1[]={0,0,0,0,0,0,4,44,60,76,80,80,127, 257};
+static UInt32 PosHf2[]={0,0,0,0,0,0,2,7,53,117,233, 257,0};
+static UInt32 PosHf3[]={0,0,0,0,0,0,0,2,16,218,251, 257,0};
+static UInt32 PosHf4[]={0,0,0,0,0,0,0,0,0,255, 257,0,0};
+
+static const UInt32 kHistorySize = (1 << 16);
+
+class CCoderReleaser
+{
+ CDecoder *m_Coder;
+public:
+ CCoderReleaser(CDecoder *coder): m_Coder(coder) {}
+ ~CCoderReleaser() { m_Coder->ReleaseStreams(); }
+};
+
+CDecoder::CDecoder(): m_IsSolid(false) { }
+
+void CDecoder::InitStructures()
+{
+ for(int i = 0; i < kNumRepDists; i++)
+ m_RepDists[i] = 0;
+ m_RepDistPtr = 0;
+ LastLength = 0;
+ LastDist = 0;
+}
+
+UInt32 CDecoder::ReadBits(int numBits) { return m_InBitStream.ReadBits(numBits); }
+
+HRESULT CDecoder::CopyBlock(UInt32 distance, UInt32 len)
+{
+ if (len == 0)
+ return S_FALSE;
+ m_UnpackSize -= len;
+ return m_OutWindowStream.CopyBlock(distance, len) ? S_OK : S_FALSE;
+}
+
+
+UInt32 CDecoder::DecodeNum(const UInt32 *posTab)
+{
+ UInt32 startPos = 2;
+ UInt32 num = m_InBitStream.GetValue(12);
+ for (;;)
+ {
+ UInt32 cur = (posTab[startPos + 1] - posTab[startPos]) << (12 - startPos);
+ if (num < cur)
+ break;
+ startPos++;
+ num -= cur;
+ }
+ m_InBitStream.MovePos(startPos);
+ return((num >> (12 - startPos)) + posTab[startPos]);
+}
+
+static Byte kShortLen1[] = {1,3,4,4,5,6,7,8,8,4,4,5,6,6 };
+static Byte kShortLen1a[] = {1,4,4,4,5,6,7,8,8,4,4,5,6,6,4 };
+static Byte kShortLen2[] = {2,3,3,3,4,4,5,6,6,4,4,5,6,6 };
+static Byte kShortLen2a[] = {2,3,3,4,4,4,5,6,6,4,4,5,6,6,4 };
+static UInt32 kShortXor1[] = {0,0xa0,0xd0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0xc0,0x80,0x90,0x98,0x9c,0xb0};
+static UInt32 kShortXor2[] = {0,0x40,0x60,0xa0,0xd0,0xe0,0xf0,0xf8,0xfc,0xc0,0x80,0x90,0x98,0x9c,0xb0};
+
+HRESULT CDecoder::ShortLZ()
+{
+ UInt32 len, saveLen, dist;
+ int distancePlace;
+ Byte *kShortLen;
+ const UInt32 *kShortXor;
+ NumHuf = 0;
+
+ if (LCount == 2)
+ {
+ if (ReadBits(1))
+ return CopyBlock(LastDist, LastLength);
+ LCount = 0;
+ }
+
+ UInt32 bitField = m_InBitStream.GetValue(8);
+
+ if (AvrLn1 < 37)
+ {
+ kShortLen = Buf60 ? kShortLen1a : kShortLen1;
+ kShortXor = kShortXor1;
+ }
+ else
+ {
+ kShortLen = Buf60 ? kShortLen2a : kShortLen2;
+ kShortXor = kShortXor2;
+ }
+
+ for (len = 0; ((bitField ^ kShortXor[len]) & (~(0xff >> kShortLen[len]))) != 0; len++);
+ m_InBitStream.MovePos(kShortLen[len]);
+
+ if (len >= 9)
+ {
+ if (len == 9)
+ {
+ LCount++;
+ return CopyBlock(LastDist, LastLength);
+ }
+ if (len == 14)
+ {
+ LCount = 0;
+ len = DecodeNum(PosL2) + 5;
+ dist = 0x8000 + ReadBits(15) - 1;
+ LastLength = len;
+ LastDist = dist;
+ return CopyBlock(dist, len);
+ }
+
+ LCount = 0;
+ saveLen = len;
+ dist = m_RepDists[(m_RepDistPtr - (len - 9)) & 3];
+ len = DecodeNum(PosL1) + 2;
+ if (len == 0x101 && saveLen == 10)
+ {
+ Buf60 ^= 1;
+ return S_OK;
+ }
+ if (dist >= 256)
+ len++;
+ if (dist >= MaxDist3 - 1)
+ len++;
+ }
+ else
+ {
+ LCount = 0;
+ AvrLn1 += len;
+ AvrLn1 -= AvrLn1 >> 4;
+
+ distancePlace = DecodeNum(PosHf2) & 0xff;
+ dist = ChSetA[distancePlace];
+ if (--distancePlace != -1)
+ {
+ PlaceA[dist]--;
+ UInt32 lastDistance = ChSetA[distancePlace];
+ PlaceA[lastDistance]++;
+ ChSetA[distancePlace + 1] = lastDistance;
+ ChSetA[distancePlace] = dist;
+ }
+ len += 2;
+ }
+ m_RepDists[m_RepDistPtr++] = dist;
+ m_RepDistPtr &= 3;
+ LastLength = len;
+ LastDist = dist;
+ return CopyBlock(dist, len);
+}
+
+
+HRESULT CDecoder::LongLZ()
+{
+ UInt32 len;
+ UInt32 dist;
+ UInt32 distancePlace, newDistancePlace;
+ UInt32 oldAvr2, oldAvr3;
+
+ NumHuf = 0;
+ Nlzb += 16;
+ if (Nlzb > 0xff)
+ {
+ Nlzb = 0x90;
+ Nhfb >>= 1;
+ }
+ oldAvr2=AvrLn2;
+
+ if (AvrLn2 >= 122)
+ len = DecodeNum(PosL2);
+ else if (AvrLn2 >= 64)
+ len = DecodeNum(PosL1);
+ else
+ {
+ UInt32 bitField = m_InBitStream.GetValue(16);
+ if (bitField < 0x100)
+ {
+ len = bitField;
+ m_InBitStream.MovePos(16);
+ }
+ else
+ {
+ for (len = 0; ((bitField << len) & 0x8000) == 0; len++)
+ ;
+ m_InBitStream.MovePos(len + 1);
+ }
+ }
+
+ AvrLn2 += len;
+ AvrLn2 -= AvrLn2 >> 5;
+
+ if (AvrPlcB > 0x28ff)
+ distancePlace = DecodeNum(PosHf2);
+ else if (AvrPlcB > 0x6ff)
+ distancePlace = DecodeNum(PosHf1);
+ else
+ distancePlace = DecodeNum(PosHf0);
+
+ AvrPlcB += distancePlace;
+ AvrPlcB -= AvrPlcB >> 8;
+ for (;;)
+ {
+ dist = ChSetB[distancePlace & 0xff];
+ newDistancePlace = NToPlB[dist++ & 0xff]++;
+ if (!(dist & 0xff))
+ CorrHuff(ChSetB,NToPlB);
+ else
+ break;
+ }
+
+ ChSetB[distancePlace] = ChSetB[newDistancePlace];
+ ChSetB[newDistancePlace] = dist;
+
+ dist = ((dist & 0xff00) >> 1) | ReadBits(7);
+
+ oldAvr3 = AvrLn3;
+ if (len != 1 && len != 4)
+ if (len == 0 && dist <= MaxDist3)
+ {
+ AvrLn3++;
+ AvrLn3 -= AvrLn3 >> 8;
+ }
+ else
+ if (AvrLn3 > 0)
+ AvrLn3--;
+ len += 3;
+ if (dist >= MaxDist3)
+ len++;
+ if (dist <= 256)
+ len += 8;
+ if (oldAvr3 > 0xb0 || AvrPlc >= 0x2a00 && oldAvr2 < 0x40)
+ MaxDist3 = 0x7f00;
+ else
+ MaxDist3 = 0x2001;
+ m_RepDists[m_RepDistPtr++] = --dist;
+ m_RepDistPtr &= 3;
+ LastLength = len;
+ LastDist = dist;
+ return CopyBlock(dist, len);
+}
+
+
+HRESULT CDecoder::HuffDecode()
+{
+ UInt32 curByte, newBytePlace;
+ UInt32 len;
+ UInt32 dist;
+ int bytePlace;
+
+ if (AvrPlc > 0x75ff) bytePlace = DecodeNum(PosHf4);
+ else if (AvrPlc > 0x5dff) bytePlace = DecodeNum(PosHf3);
+ else if (AvrPlc > 0x35ff) bytePlace = DecodeNum(PosHf2);
+ else if (AvrPlc > 0x0dff) bytePlace = DecodeNum(PosHf1);
+ else bytePlace = DecodeNum(PosHf0);
+ if (StMode)
+ {
+ if (--bytePlace == -1)
+ {
+ if (ReadBits(1))
+ {
+ NumHuf = StMode = 0;
+ return S_OK;
+ }
+ else
+ {
+ len = (ReadBits(1)) ? 4 : 3;
+ dist = DecodeNum(PosHf2);
+ dist = (dist << 5) | ReadBits(5);
+ return CopyBlock(dist - 1, len);
+ }
+ }
+ }
+ else if (NumHuf++ >= 16 && FlagsCnt == 0)
+ StMode = 1;
+ bytePlace &= 0xff;
+ AvrPlc += bytePlace;
+ AvrPlc -= AvrPlc >> 8;
+ Nhfb+=16;
+ if (Nhfb > 0xff)
+ {
+ Nhfb=0x90;
+ Nlzb >>= 1;
+ }
+
+ m_UnpackSize --;
+ m_OutWindowStream.PutByte((Byte)(ChSet[bytePlace] >> 8));
+
+ for (;;)
+ {
+ curByte = ChSet[bytePlace];
+ newBytePlace = NToPl[curByte++ & 0xff]++;
+ if ((curByte & 0xff) > 0xa1)
+ CorrHuff(ChSet, NToPl);
+ else
+ break;
+ }
+
+ ChSet[bytePlace] = ChSet[newBytePlace];
+ ChSet[newBytePlace] = curByte;
+ return S_OK;
+}
+
+
+void CDecoder::GetFlagsBuf()
+{
+ UInt32 flags, newFlagsPlace;
+ UInt32 flagsPlace = DecodeNum(PosHf2);
+
+ for (;;)
+ {
+ flags = ChSetC[flagsPlace];
+ FlagBuf = flags >> 8;
+ newFlagsPlace = NToPlC[flags++ & 0xff]++;
+ if ((flags & 0xff) != 0)
+ break;
+ CorrHuff(ChSetC, NToPlC);
+ }
+
+ ChSetC[flagsPlace] = ChSetC[newFlagsPlace];
+ ChSetC[newFlagsPlace] = flags;
+}
+
+void CDecoder::InitData()
+{
+ if (!m_IsSolid)
+ {
+ AvrPlcB = AvrLn1 = AvrLn2 = AvrLn3 = NumHuf = Buf60 = 0;
+ AvrPlc = 0x3500;
+ MaxDist3 = 0x2001;
+ Nhfb = Nlzb = 0x80;
+ }
+ FlagsCnt = 0;
+ FlagBuf = 0;
+ StMode = 0;
+ LCount = 0;
+}
+
+void CDecoder::CorrHuff(UInt32 *CharSet,UInt32 *NumToPlace)
+{
+ int i;
+ for (i = 7; i >= 0; i--)
+ for (int j = 0; j < 32; j++, CharSet++)
+ *CharSet = (*CharSet & ~0xff) | i;
+ memset(NumToPlace, 0, sizeof(NToPl));
+ for (i = 6; i >= 0; i--)
+ NumToPlace[i] = (7 - i) * 32;
+}
+
+void CDecoder::InitHuff()
+{
+ for (UInt32 i = 0; i < 256; i++)
+ {
+ Place[i] = PlaceA[i] = PlaceB[i] = i;
+ PlaceC[i] = (~i + 1) & 0xff;
+ ChSet[i] = ChSetB[i] = i << 8;
+ ChSetA[i] = i;
+ ChSetC[i] = ((~i + 1) & 0xff) << 8;
+ }
+ memset(NToPl, 0, sizeof(NToPl));
+ memset(NToPlB, 0, sizeof(NToPlB));
+ memset(NToPlC, 0, sizeof(NToPlC));
+ CorrHuff(ChSetB, NToPlB);
+}
+
+HRESULT 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_UnpackSize = (Int64)*outSize;
+ m_OutWindowStream.SetStream(outStream);
+ m_OutWindowStream.Init(m_IsSolid);
+ m_InBitStream.SetStream(inStream);
+ m_InBitStream.Init();
+
+ CCoderReleaser coderReleaser(this);
+ InitData();
+ if (!m_IsSolid)
+ {
+ InitStructures();
+ InitHuff();
+ }
+ if (m_UnpackSize > 0)
+ {
+ GetFlagsBuf();
+ FlagsCnt = 8;
+ }
+
+ while (m_UnpackSize > 0)
+ {
+ if (StMode)
+ {
+ RINOK(HuffDecode());
+ continue;
+ }
+
+ if (--FlagsCnt < 0)
+ {
+ GetFlagsBuf();
+ FlagsCnt=7;
+ }
+
+ if (FlagBuf & 0x80)
+ {
+ FlagBuf <<= 1;
+ if (Nlzb > Nhfb)
+ {
+ RINOK(LongLZ());
+ }
+ else
+ {
+ RINOK(HuffDecode());
+ }
+ }
+ else
+ {
+ FlagBuf <<= 1;
+ if (--FlagsCnt < 0)
+ {
+ GetFlagsBuf();
+ FlagsCnt = 7;
+ }
+ if (FlagBuf & 0x80)
+ {
+ FlagBuf <<= 1;
+ if (Nlzb > Nhfb)
+ {
+ RINOK(HuffDecode());
+ }
+ else
+ {
+ RINOK(LongLZ());
+ }
+ }
+ else
+ {
+ FlagBuf <<= 1;
+ RINOK(ShortLZ());
+ }
+ }
+ }
+ if (m_UnpackSize < 0)
+ 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 CInBufferException &e) { return e.ErrorCode; }
+ 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;
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar1Decoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar1Decoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar1Decoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar1Decoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,88 @@
+// Rar1Decoder.h
+// According to unRAR license, this code may not be used to develop
+// a program that creates RAR archives
+
+#ifndef __COMPRESS_RAR1_DECODER_H
+#define __COMPRESS_RAR1_DECODER_H
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+#include "../Common/InBuffer.h"
+
+#include "BitmDecoder.h"
+#include "HuffmanDecoder.h"
+#include "LzOutWindow.h"
+
+namespace NCompress {
+namespace NRar1 {
+
+const UInt32 kNumRepDists = 4;
+
+typedef NBitm::CDecoder<CInBuffer> CBitDecoder;
+
+class CDecoder :
+ public ICompressCoder,
+ public ICompressSetDecoderProperties2,
+ public CMyUnknownImp
+{
+public:
+ CLzOutWindow m_OutWindowStream;
+ CBitDecoder m_InBitStream;
+
+ UInt32 m_RepDists[kNumRepDists];
+ UInt32 m_RepDistPtr;
+
+ UInt32 LastDist;
+ UInt32 LastLength;
+
+ Int64 m_UnpackSize;
+ bool m_IsSolid;
+
+ UInt32 ReadBits(int numBits);
+ HRESULT CopyBlock(UInt32 distance, UInt32 len);
+
+ UInt32 DecodeNum(const UInt32 *posTab);
+ HRESULT ShortLZ();
+ HRESULT LongLZ();
+ HRESULT HuffDecode();
+ void GetFlagsBuf();
+ void InitData();
+ void InitHuff();
+ void CorrHuff(UInt32 *CharSet, UInt32 *NumToPlace);
+ void OldUnpWriteBuf();
+
+ UInt32 ChSet[256],ChSetA[256],ChSetB[256],ChSetC[256];
+ UInt32 Place[256],PlaceA[256],PlaceB[256],PlaceC[256];
+ UInt32 NToPl[256],NToPlB[256],NToPlC[256];
+ UInt32 FlagBuf,AvrPlc,AvrPlcB,AvrLn1,AvrLn2,AvrLn3;
+ int Buf60,NumHuf,StMode,LCount,FlagsCnt;
+ UInt32 Nhfb,Nlzb,MaxDist3;
+
+ void InitStructures();
+
+ HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+public:
+ CDecoder();
+
+ MY_UNKNOWN_IMP1(ICompressSetDecoderProperties2)
+
+ void ReleaseStreams()
+ {
+ m_OutWindowStream.ReleaseStream();
+ m_InBitStream.ReleaseStream();
+ }
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
+
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar2Decoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar2Decoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar2Decoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar2Decoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,391 @@
+// Rar2Decoder.cpp
+// According to unRAR license, this code may not be used to develop
+// a program that creates RAR archives
+
+#include "StdAfx.h"
+
+#include "Rar2Decoder.h"
+
+namespace NCompress {
+namespace NRar2 {
+
+namespace NMultimedia {
+
+Byte CFilter::Decode(int &channelDelta, Byte deltaByte)
+{
+ D4 = D3;
+ D3 = D2;
+ D2 = LastDelta - D1;
+ D1 = LastDelta;
+ int predictedValue = ((8 * LastChar + K1 * D1 + K2 * D2 + K3 * D3 + K4 * D4 + K5 * channelDelta) >> 3);
+
+ Byte realValue = (Byte)(predictedValue - deltaByte);
+ int i = ((int)(signed char)deltaByte) << 3;
+
+ Dif[0] += abs(i);
+ Dif[1] += abs(i - D1);
+ Dif[2] += abs(i + D1);
+ Dif[3] += abs(i - D2);
+ Dif[4] += abs(i + D2);
+ Dif[5] += abs(i - D3);
+ Dif[6] += abs(i + D3);
+ Dif[7] += abs(i - D4);
+ Dif[8] += abs(i + D4);
+ Dif[9] += abs(i - channelDelta);
+ Dif[10] += abs(i + channelDelta);
+
+ channelDelta = LastDelta = (signed char)(realValue - LastChar);
+ LastChar = realValue;
+
+ if (((++ByteCount) & 0x1F) == 0)
+ {
+ UInt32 minDif = Dif[0];
+ UInt32 numMinDif = 0;
+ Dif[0] = 0;
+ for (i = 1; i < sizeof(Dif) / sizeof(Dif[0]); i++)
+ {
+ if (Dif[i] < minDif)
+ {
+ minDif = Dif[i];
+ numMinDif = i;
+ }
+ Dif[i] = 0;
+ }
+ switch(numMinDif)
+ {
+ case 1: if (K1 >= -16) K1--; break;
+ case 2: if (K1 < 16) K1++; break;
+ case 3: if (K2 >= -16) K2--; break;
+ case 4: if (K2 < 16) K2++; break;
+ case 5: if (K3 >= -16) K3--; break;
+ case 6: if (K3 < 16) K3++; break;
+ case 7: if (K4 >= -16) K4--; break;
+ case 8: if (K4 < 16) K4++; break;
+ case 9: if (K5 >= -16) K5--; break;
+ case 10:if (K5 < 16) K5++; break;
+ }
+ }
+ return realValue;
+}
+}
+
+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_MmFilter.Init();
+ for(int i = 0; i < kNumRepDists; i++)
+ m_RepDists[i] = 0;
+ m_RepDistPtr = 0;
+ m_LastLength = 0;
+ memset(m_LastLevels, 0, kMaxTableSize);
+}
+
+UInt32 CDecoder::ReadBits(int numBits) { return m_InBitStream.ReadBits(numBits); }
+
+#define RIF(x) { if (!(x)) return false; }
+
+bool CDecoder::ReadTables(void)
+{
+ Byte levelLevels[kLevelTableSize];
+ Byte newLevels[kMaxTableSize];
+ m_AudioMode = (ReadBits(1) == 1);
+
+ if (ReadBits(1) == 0)
+ memset(m_LastLevels, 0, kMaxTableSize);
+ int numLevels;
+ if (m_AudioMode)
+ {
+ m_NumChannels = ReadBits(2) + 1;
+ if (m_MmFilter.CurrentChannel >= m_NumChannels)
+ m_MmFilter.CurrentChannel = 0;
+ numLevels = m_NumChannels * kMMTableSize;
+ }
+ else
+ numLevels = kHeapTablesSizesSum;
+
+ int i;
+ for (i = 0; i < kLevelTableSize; i++)
+ levelLevels[i] = (Byte)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 = 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 = ReadBits(3) + 3;
+ else if (number == kTableLevel0Number2)
+ num = 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_MmFilter.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();
+ }
+};
+
+bool CDecoder::DecodeMm(UInt32 pos)
+{
+ while (pos-- > 0)
+ {
+ UInt32 symbol = m_MMDecoders[m_MmFilter.CurrentChannel].DecodeSymbol(&m_InBitStream);
+ if (symbol == 256)
+ return true;
+ if (symbol >= kMMTableSize)
+ return false;
+ /*
+ Byte byPredict = m_Predictor.Predict();
+ Byte byReal = (Byte)(byPredict - (Byte)symbol);
+ m_Predictor.Update(byReal, byPredict);
+ */
+ Byte byReal = m_MmFilter.Decode((Byte)symbol);
+ m_OutWindowStream.PutByte(byReal);
+ if (++m_MmFilter.CurrentChannel == m_NumChannels)
+ m_MmFilter.CurrentChannel = 0;
+ }
+ return true;
+}
+
+bool CDecoder::DecodeLz(Int32 pos)
+{
+ while (pos > 0)
+ {
+ 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 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;
+ if (length == 0)
+ return false;
+ 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 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)
+ return true;
+ else
+ return false;
+ m_RepDists[m_RepDistPtr++ & 3] = distance;
+ m_LastLength = length;
+ if (!m_OutWindowStream.CopyBlock(distance, length))
+ return false;
+ pos -= length;
+ }
+ return true;
+}
+
+HRESULT 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;
+ }
+
+ UInt64 startPos = m_OutWindowStream.GetProcessedSize();
+ while(pos < unPackSize)
+ {
+ UInt32 blockSize = 1 << 20;
+ if (blockSize > unPackSize - pos)
+ blockSize = (UInt32)(unPackSize - pos);
+ UInt64 blockStartPos = m_OutWindowStream.GetProcessedSize();
+ if (m_AudioMode)
+ {
+ if (!DecodeMm(blockSize))
+ return S_FALSE;
+ }
+ else
+ {
+ if (!DecodeLz((Int32)blockSize))
+ return S_FALSE;
+ }
+ UInt64 globalPos = m_OutWindowStream.GetProcessedSize();
+ pos = globalPos - blockStartPos;
+ if (pos < blockSize)
+ if (!ReadTables())
+ return S_FALSE;
+ pos = globalPos - startPos;
+ if (progress != 0)
+ {
+ UInt64 packSize = m_InBitStream.GetProcessedSize();
+ RINOK(progress->SetRatioInfo(&packSize, &pos));
+ }
+ }
+ if (pos > unPackSize)
+ return S_FALSE;
+
+ 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 CInBufferException &e) { return e.ErrorCode; }
+ 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;
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar2Decoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar2Decoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar2Decoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar2Decoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,174 @@
+// Rar2Decoder.h
+// According to unRAR license, this code may not be used to develop
+// a program that creates RAR archives
+
+#ifndef __COMPRESS_RAR2_DECODER_H
+#define __COMPRESS_RAR2_DECODER_H
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+#include "../Common/InBuffer.h"
+
+#include "BitmDecoder.h"
+#include "HuffmanDecoder.h"
+#include "LzOutWindow.h"
+
+namespace NCompress {
+namespace NRar2 {
+
+const UInt32 kNumRepDists = 4;
+const UInt32 kDistTableSize = 48;
+
+const int kMMTableSize = 256 + 1;
+
+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;
+
+namespace NMultimedia {
+
+struct CFilter
+{
+ int K1,K2,K3,K4,K5;
+ int D1,D2,D3,D4;
+ int LastDelta;
+ UInt32 Dif[11];
+ UInt32 ByteCount;
+ int LastChar;
+
+ Byte Decode(int &channelDelta, Byte delta);
+
+ void Init() { memset(this, 0, sizeof(*this)); }
+
+};
+
+const int kNumChanelsMax = 4;
+
+class CFilter2
+{
+public:
+ CFilter m_Filters[kNumChanelsMax];
+ int m_ChannelDelta;
+ int CurrentChannel;
+
+ void Init() { memset(this, 0, sizeof(*this)); }
+ Byte Decode(Byte delta)
+ {
+ return m_Filters[CurrentChannel].Decode(m_ChannelDelta, delta);
+ }
+
+};
+
+}
+
+typedef NBitm::CDecoder<CInBuffer> CBitDecoder;
+
+const int kNumHuffmanBits = 15;
+
+class CDecoder :
+ public ICompressCoder,
+ public ICompressSetDecoderProperties2,
+ public CMyUnknownImp
+{
+ CLzOutWindow m_OutWindowStream;
+ CBitDecoder m_InBitStream;
+ NHuffman::CDecoder<kNumHuffmanBits, kMainTableSize> m_MainDecoder;
+ NHuffman::CDecoder<kNumHuffmanBits, kDistTableSize> m_DistDecoder;
+ NHuffman::CDecoder<kNumHuffmanBits, kLenTableSize> m_LenDecoder;
+ NHuffman::CDecoder<kNumHuffmanBits, kMMTableSize> m_MMDecoders[NMultimedia::kNumChanelsMax];
+ NHuffman::CDecoder<kNumHuffmanBits, kLevelTableSize> m_LevelDecoder;
+
+ bool m_AudioMode;
+
+ NMultimedia::CFilter2 m_MmFilter;
+ int m_NumChannels;
+
+ UInt32 m_RepDists[kNumRepDists];
+ UInt32 m_RepDistPtr;
+
+ UInt32 m_LastLength;
+
+ Byte m_LastLevels[kMaxTableSize];
+
+ UInt64 m_PackSize;
+ bool m_IsSolid;
+
+ void InitStructures();
+ UInt32 ReadBits(int numBits);
+ bool ReadTables();
+ bool ReadLastTables();
+
+ bool DecodeMm(UInt32 pos);
+ bool DecodeLz(Int32 pos);
+
+ HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+public:
+ CDecoder();
+
+ MY_UNKNOWN_IMP1(ICompressSetDecoderProperties2)
+
+ void ReleaseStreams()
+ {
+ m_OutWindowStream.ReleaseStream();
+ m_InBitStream.ReleaseStream();
+ }
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
+
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Decoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Decoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Decoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Decoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,897 @@
+// Rar3Decoder.cpp
+// According to unRAR license, this code may not be used to develop
+// a program that creates RAR archives
+
+/* This code uses Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
+
+#include "StdAfx.h"
+
+#include "../../../C/Alloc.h"
+
+#include "../Common/StreamUtils.h"
+
+#include "Rar3Decoder.h"
+
+namespace NCompress {
+namespace NRar3 {
+
+static void *SzBigAlloc(void *, size_t size) { return BigAlloc(size); }
+static void SzBigFree(void *, void *address) { BigFree(address); }
+static ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree };
+
+static const UInt32 kNumAlignReps = 15;
+
+static const UInt32 kSymbolReadTable = 256;
+static const UInt32 kSymbolRep = 259;
+static const UInt32 kSymbolLen2 = kSymbolRep + kNumReps;
+
+static 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};
+static 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};
+
+static 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,
+ 18,18,18,18,18,18,18,18,18,18,18,18};
+
+static const Byte kLevelDirectBits[kLevelTableSize] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
+
+static const Byte kLen2DistStarts[kNumLen2Symbols]={0,4,8,16,32,64,128,192};
+static const Byte kLen2DistDirectBits[kNumLen2Symbols]={2,2,3, 4, 5, 6, 6, 6};
+
+static const UInt32 kDistLimit3 = 0x2000 - 2;
+static const UInt32 kDistLimit4 = 0x40000 - 2;
+
+static const UInt32 kNormalMatchMinLen = 3;
+
+static const UInt32 kVmDataSizeMax = 1 << 16;
+static const UInt32 kVmCodeSizeMax = 1 << 16;
+
+extern "C" {
+
+static UInt32 Range_GetThreshold(void *pp, UInt32 total)
+{
+ CRangeDecoder *p = (CRangeDecoder *)pp;
+ return p->Code / (p->Range /= total);
+}
+
+static void Range_Decode(void *pp, UInt32 start, UInt32 size)
+{
+ CRangeDecoder *p = (CRangeDecoder *)pp;
+ start *= p->Range;
+ p->Low += start;
+ p->Code -= start;
+ p->Range *= size;
+ p->Normalize();
+}
+
+static UInt32 Range_DecodeBit(void *pp, UInt32 size0)
+{
+ CRangeDecoder *p = (CRangeDecoder *)pp;
+ if (p->Code / (p->Range >>= 14) < size0)
+ {
+ Range_Decode(p, 0, size0);
+ return 0;
+ }
+ else
+ {
+ Range_Decode(p, size0, (1 << 14) - size0);
+ return 1;
+ }
+}
+
+}
+
+CRangeDecoder::CRangeDecoder()
+{
+ s.GetThreshold = Range_GetThreshold;
+ s.Decode = Range_Decode;
+ s.DecodeBit = Range_DecodeBit;
+}
+
+CDecoder::CDecoder():
+ _window(0),
+ _winPos(0),
+ _wrPtr(0),
+ _lzSize(0),
+ _writtenFileSize(0),
+ _vmData(0),
+ _vmCode(0),
+ m_IsSolid(false)
+{
+ Ppmd7_Construct(&_ppmd);
+}
+
+CDecoder::~CDecoder()
+{
+ InitFilters();
+ ::MidFree(_vmData);
+ ::MidFree(_window);
+ Ppmd7_Free(&_ppmd, &g_BigAlloc);
+}
+
+HRESULT CDecoder::WriteDataToStream(const Byte *data, UInt32 size)
+{
+ return WriteStream(_outStream, data, size);
+}
+
+HRESULT CDecoder::WriteData(const Byte *data, UInt32 size)
+{
+ HRESULT res = S_OK;
+ if (_writtenFileSize < _unpackSize)
+ {
+ UInt32 curSize = size;
+ UInt64 remain = _unpackSize - _writtenFileSize;
+ if (remain < curSize)
+ curSize = (UInt32)remain;
+ res = WriteDataToStream(data, curSize);
+ }
+ _writtenFileSize += size;
+ return res;
+}
+
+HRESULT CDecoder::WriteArea(UInt32 startPtr, UInt32 endPtr)
+{
+ if (startPtr <= endPtr)
+ return WriteData(_window + startPtr, endPtr - startPtr);
+ RINOK(WriteData(_window + startPtr, kWindowSize - startPtr));
+ return WriteData(_window, endPtr);
+}
+
+void CDecoder::ExecuteFilter(int tempFilterIndex, NVm::CBlockRef &outBlockRef)
+{
+ CTempFilter *tempFilter = _tempFilters[tempFilterIndex];
+ tempFilter->InitR[6] = (UInt32)_writtenFileSize;
+ NVm::SetValue32(&tempFilter->GlobalData[0x24], (UInt32)_writtenFileSize);
+ NVm::SetValue32(&tempFilter->GlobalData[0x28], (UInt32)(_writtenFileSize >> 32));
+ CFilter *filter = _filters[tempFilter->FilterIndex];
+ _vm.Execute(filter, tempFilter, outBlockRef, filter->GlobalData);
+ delete tempFilter;
+ _tempFilters[tempFilterIndex] = 0;
+}
+
+HRESULT CDecoder::WriteBuf()
+{
+ UInt32 writtenBorder = _wrPtr;
+ UInt32 writeSize = (_winPos - writtenBorder) & kWindowMask;
+ for (int i = 0; i < _tempFilters.Size(); i++)
+ {
+ CTempFilter *filter = _tempFilters[i];
+ if (filter == NULL)
+ continue;
+ if (filter->NextWindow)
+ {
+ filter->NextWindow = false;
+ continue;
+ }
+ UInt32 blockStart = filter->BlockStart;
+ UInt32 blockSize = filter->BlockSize;
+ if (((blockStart - writtenBorder) & kWindowMask) < writeSize)
+ {
+ if (writtenBorder != blockStart)
+ {
+ RINOK(WriteArea(writtenBorder, blockStart));
+ writtenBorder = blockStart;
+ writeSize = (_winPos - writtenBorder) & kWindowMask;
+ }
+ if (blockSize <= writeSize)
+ {
+ UInt32 blockEnd = (blockStart + blockSize) & kWindowMask;
+ if (blockStart < blockEnd || blockEnd == 0)
+ _vm.SetMemory(0, _window + blockStart, blockSize);
+ else
+ {
+ UInt32 tailSize = kWindowSize - blockStart;
+ _vm.SetMemory(0, _window + blockStart, tailSize);
+ _vm.SetMemory(tailSize, _window, blockEnd);
+ }
+ NVm::CBlockRef outBlockRef;
+ ExecuteFilter(i, outBlockRef);
+ while (i + 1 < _tempFilters.Size())
+ {
+ CTempFilter *nextFilter = _tempFilters[i + 1];
+ if (nextFilter == NULL || nextFilter->BlockStart != blockStart ||
+ nextFilter->BlockSize != outBlockRef.Size || nextFilter->NextWindow)
+ break;
+ _vm.SetMemory(0, _vm.GetDataPointer(outBlockRef.Offset), outBlockRef.Size);
+ ExecuteFilter(++i, outBlockRef);
+ }
+ WriteDataToStream(_vm.GetDataPointer(outBlockRef.Offset), outBlockRef.Size);
+ _writtenFileSize += outBlockRef.Size;
+ writtenBorder = blockEnd;
+ writeSize = (_winPos - writtenBorder) & kWindowMask;
+ }
+ else
+ {
+ for (int j = i; j < _tempFilters.Size(); j++)
+ {
+ CTempFilter *filter = _tempFilters[j];
+ if (filter != NULL && filter->NextWindow)
+ filter->NextWindow = false;
+ }
+ _wrPtr = writtenBorder;
+ return S_OK; // check it
+ }
+ }
+ }
+
+ _wrPtr = _winPos;
+ return WriteArea(writtenBorder, _winPos);
+}
+
+void CDecoder::InitFilters()
+{
+ _lastFilter = 0;
+ int i;
+ for (i = 0; i < _tempFilters.Size(); i++)
+ delete _tempFilters[i];
+ _tempFilters.Clear();
+ for (i = 0; i < _filters.Size(); i++)
+ delete _filters[i];
+ _filters.Clear();
+}
+
+bool CDecoder::AddVmCode(UInt32 firstByte, UInt32 codeSize)
+{
+ CMemBitDecoder inp;
+ inp.Init(_vmData, codeSize);
+
+ UInt32 filterIndex;
+ if (firstByte & 0x80)
+ {
+ filterIndex = NVm::ReadEncodedUInt32(inp);
+ if (filterIndex == 0)
+ InitFilters();
+ else
+ filterIndex--;
+ }
+ else
+ filterIndex = _lastFilter;
+ if (filterIndex > (UInt32)_filters.Size())
+ return false;
+ _lastFilter = filterIndex;
+ bool newFilter = (filterIndex == (UInt32)_filters.Size());
+
+ CFilter *filter;
+ if (newFilter)
+ {
+ // check if too many filters
+ if (filterIndex > 1024)
+ return false;
+ filter = new CFilter;
+ _filters.Add(filter);
+ }
+ else
+ {
+ filter = _filters[filterIndex];
+ filter->ExecCount++;
+ }
+
+ int numEmptyItems = 0;
+ int i;
+ for (i = 0; i < _tempFilters.Size(); i++)
+ {
+ _tempFilters[i - numEmptyItems] = _tempFilters[i];
+ if (_tempFilters[i] == NULL)
+ numEmptyItems++;
+ if (numEmptyItems > 0)
+ _tempFilters[i] = NULL;
+ }
+ if (numEmptyItems == 0)
+ {
+ _tempFilters.Add(NULL);
+ numEmptyItems = 1;
+ }
+ CTempFilter *tempFilter = new CTempFilter;
+ _tempFilters[_tempFilters.Size() - numEmptyItems] = tempFilter;
+ tempFilter->FilterIndex = filterIndex;
+ tempFilter->ExecCount = filter->ExecCount;
+
+ UInt32 blockStart = NVm::ReadEncodedUInt32(inp);
+ if (firstByte & 0x40)
+ blockStart += 258;
+ tempFilter->BlockStart = (blockStart + _winPos) & kWindowMask;
+ if (firstByte & 0x20)
+ filter->BlockSize = NVm::ReadEncodedUInt32(inp);
+ tempFilter->BlockSize = filter->BlockSize;
+ tempFilter->NextWindow = _wrPtr != _winPos && ((_wrPtr - _winPos) & kWindowMask) <= blockStart;
+
+ memset(tempFilter->InitR, 0, sizeof(tempFilter->InitR));
+ tempFilter->InitR[3] = NVm::kGlobalOffset;
+ tempFilter->InitR[4] = tempFilter->BlockSize;
+ tempFilter->InitR[5] = tempFilter->ExecCount;
+ if (firstByte & 0x10)
+ {
+ UInt32 initMask = inp.ReadBits(NVm::kNumGpRegs);
+ for (int i = 0; i < NVm::kNumGpRegs; i++)
+ if (initMask & (1 << i))
+ tempFilter->InitR[i] = NVm::ReadEncodedUInt32(inp);
+ }
+ if (newFilter)
+ {
+ UInt32 vmCodeSize = NVm::ReadEncodedUInt32(inp);
+ if (vmCodeSize >= kVmCodeSizeMax || vmCodeSize == 0)
+ return false;
+ for (UInt32 i = 0; i < vmCodeSize; i++)
+ _vmCode[i] = (Byte)inp.ReadBits(8);
+ _vm.PrepareProgram(_vmCode, vmCodeSize, filter);
+ }
+
+ tempFilter->AllocateEmptyFixedGlobal();
+
+ Byte *globalData = &tempFilter->GlobalData[0];
+ for (i = 0; i < NVm::kNumGpRegs; i++)
+ NVm::SetValue32(&globalData[i * 4], tempFilter->InitR[i]);
+ NVm::SetValue32(&globalData[NVm::NGlobalOffset::kBlockSize], tempFilter->BlockSize);
+ NVm::SetValue32(&globalData[NVm::NGlobalOffset::kBlockPos], 0); // It was commented. why?
+ NVm::SetValue32(&globalData[NVm::NGlobalOffset::kExecCount], tempFilter->ExecCount);
+
+ if (firstByte & 8)
+ {
+ UInt32 dataSize = NVm::ReadEncodedUInt32(inp);
+ if (dataSize > NVm::kGlobalSize - NVm::kFixedGlobalSize)
+ return false;
+ CRecordVector<Byte> &globalData = tempFilter->GlobalData;
+ int requredSize = (int)(dataSize + NVm::kFixedGlobalSize);
+ if (globalData.Size() < requredSize)
+ {
+ globalData.Reserve(requredSize);
+ for (; globalData.Size() < requredSize; i++)
+ globalData.Add(0);
+ }
+ for (UInt32 i = 0; i < dataSize; i++)
+ globalData[NVm::kFixedGlobalSize + i] = (Byte)inp.ReadBits(8);
+ }
+ return true;
+}
+
+bool CDecoder::ReadVmCodeLZ()
+{
+ UInt32 firstByte = ReadBits(8);
+ UInt32 length = (firstByte & 7) + 1;
+ if (length == 7)
+ length = ReadBits(8) + 7;
+ else if (length == 8)
+ length = ReadBits(16);
+ if (length > kVmDataSizeMax)
+ return false;
+ for (UInt32 i = 0; i < length; i++)
+ _vmData[i] = (Byte)ReadBits(8);
+ return AddVmCode(firstByte, length);
+}
+
+bool CDecoder::ReadVmCodePPM()
+{
+ int firstByte = DecodePpmSymbol();
+ if (firstByte < 0)
+ return false;
+ UInt32 length = (firstByte & 7) + 1;
+ if (length == 7)
+ {
+ int b1 = DecodePpmSymbol();
+ if (b1 < 0)
+ return false;
+ length = b1 + 7;
+ }
+ else if (length == 8)
+ {
+ int b1 = DecodePpmSymbol();
+ if (b1 < 0)
+ return false;
+ int b2 = DecodePpmSymbol();
+ if (b2 < 0)
+ return false;
+ length = b1 * 256 + b2;
+ }
+ if (length > kVmDataSizeMax)
+ return false;
+ for (UInt32 i = 0; i < length; i++)
+ {
+ int b = DecodePpmSymbol();
+ if (b < 0)
+ return false;
+ _vmData[i] = (Byte)b;
+ }
+ return AddVmCode(firstByte, length);
+}
+
+#define RIF(x) { if (!(x)) return S_FALSE; }
+
+UInt32 CDecoder::ReadBits(int numBits) { return m_InBitStream.bitDecoder.ReadBits(numBits); }
+
+/////////////////////////////////////////////////
+// PPM
+
+HRESULT CDecoder::InitPPM()
+{
+ Byte maxOrder = (Byte)ReadBits(7);
+
+ bool reset = ((maxOrder & 0x20) != 0);
+ int maxMB = 0;
+ if (reset)
+ maxMB = (Byte)ReadBits(8);
+ else
+ {
+ if (PpmError || !Ppmd7_WasAllocated(&_ppmd))
+ return S_FALSE;
+ }
+ if (maxOrder & 0x40)
+ PpmEscChar = (Byte)ReadBits(8);
+ m_InBitStream.InitRangeCoder();
+ /*
+ if (m_InBitStream.m_BitPos != 0)
+ return S_FALSE;
+ */
+ if (reset)
+ {
+ PpmError = true;
+ maxOrder = (maxOrder & 0x1F) + 1;
+ if (maxOrder > 16)
+ maxOrder = 16 + (maxOrder - 16) * 3;
+ if (maxOrder == 1)
+ {
+ Ppmd7_Free(&_ppmd, &g_BigAlloc);
+ return S_FALSE;
+ }
+ if (!Ppmd7_Alloc(&_ppmd, (maxMB + 1) << 20, &g_BigAlloc))
+ return E_OUTOFMEMORY;
+ Ppmd7_Init(&_ppmd, maxOrder);
+ PpmError = false;
+ }
+ return S_OK;
+}
+
+int CDecoder::DecodePpmSymbol() { return Ppmd7_DecodeSymbol(&_ppmd, &m_InBitStream.s); }
+
+HRESULT CDecoder::DecodePPM(Int32 num, bool &keepDecompressing)
+{
+ keepDecompressing = false;
+ if (PpmError)
+ return S_FALSE;
+ do
+ {
+ if (((_wrPtr - _winPos) & kWindowMask) < 260 && _wrPtr != _winPos)
+ {
+ RINOK(WriteBuf());
+ if (_writtenFileSize > _unpackSize)
+ {
+ keepDecompressing = false;
+ return S_OK;
+ }
+ }
+ int c = DecodePpmSymbol();
+ if (c < 0)
+ {
+ PpmError = true;
+ return S_FALSE;
+ }
+ if (c == PpmEscChar)
+ {
+ int nextCh = DecodePpmSymbol();
+ if (nextCh < 0)
+ {
+ PpmError = true;
+ return S_FALSE;
+ }
+ if (nextCh == 0)
+ return ReadTables(keepDecompressing);
+ if (nextCh == 2 || nextCh == -1)
+ return S_OK;
+ if (nextCh == 3)
+ {
+ if (!ReadVmCodePPM())
+ {
+ PpmError = true;
+ return S_FALSE;
+ }
+ continue;
+ }
+ if (nextCh == 4 || nextCh == 5)
+ {
+ UInt32 distance = 0;
+ UInt32 length = 4;
+ if (nextCh == 4)
+ {
+ for (int i = 0; i < 3; i++)
+ {
+ int c = DecodePpmSymbol();
+ if (c < 0)
+ {
+ PpmError = true;
+ return S_FALSE;
+ }
+ distance = (distance << 8) + (Byte)c;
+ }
+ distance++;
+ length += 28;
+ }
+ int c = DecodePpmSymbol();
+ if (c < 0)
+ {
+ PpmError = true;
+ return S_FALSE;
+ }
+ length += c;
+ if (distance >= _lzSize)
+ return S_FALSE;
+ CopyBlock(distance, length);
+ num -= (Int32)length;
+ continue;
+ }
+ }
+ PutByte((Byte)c);
+ num--;
+ }
+ while (num >= 0);
+ keepDecompressing = true;
+ return S_OK;
+}
+
+/////////////////////////////////////////////////
+// LZ
+
+HRESULT CDecoder::ReadTables(bool &keepDecompressing)
+{
+ keepDecompressing = true;
+ ReadBits((8 - m_InBitStream.bitDecoder.GetBitPosition()) & 7);
+ if (ReadBits(1) != 0)
+ {
+ _lzMode = false;
+ return InitPPM();
+ }
+
+ _lzMode = true;
+ PrevAlignBits = 0;
+ PrevAlignCount = 0;
+
+ Byte levelLevels[kLevelTableSize];
+ Byte newLevels[kTablesSizesSum];
+
+ if (ReadBits(1) == 0)
+ memset(m_LastLevels, 0, kTablesSizesSum);
+
+ int i;
+ for (i = 0; i < kLevelTableSize; i++)
+ {
+ UInt32 length = ReadBits(4);
+ if (length == 15)
+ {
+ UInt32 zeroCount = ReadBits(4);
+ if (zeroCount != 0)
+ {
+ zeroCount += 2;
+ while (zeroCount-- > 0 && i < kLevelTableSize)
+ levelLevels[i++]=0;
+ i--;
+ continue;
+ }
+ }
+ levelLevels[i] = (Byte)length;
+ }
+ RIF(m_LevelDecoder.SetCodeLengths(levelLevels));
+ i = 0;
+ while (i < kTablesSizesSum)
+ {
+ UInt32 number = m_LevelDecoder.DecodeSymbol(&m_InBitStream.bitDecoder);
+ if (number < 16)
+ {
+ newLevels[i] = Byte((number + m_LastLevels[i]) & 15);
+ i++;
+ }
+ else if (number > kLevelTableSize)
+ return S_FALSE;
+ else
+ {
+ int num;
+ if (((number - 16) & 1) == 0)
+ num = ReadBits(3) + 3;
+ else
+ num = ReadBits(7) + 11;
+ if (number < 18)
+ {
+ if (i == 0)
+ return S_FALSE;
+ for (; num > 0 && i < kTablesSizesSum; num--, i++)
+ newLevels[i] = newLevels[i - 1];
+ }
+ else
+ {
+ for (; num > 0 && i < kTablesSizesSum; num--)
+ newLevels[i++] = 0;
+ }
+ }
+ }
+ TablesRead = true;
+
+ // original code has check here:
+ /*
+ if (InAddr > ReadTop)
+ {
+ keepDecompressing = false;
+ return true;
+ }
+ */
+
+ RIF(m_MainDecoder.SetCodeLengths(&newLevels[0]));
+ RIF(m_DistDecoder.SetCodeLengths(&newLevels[kMainTableSize]));
+ RIF(m_AlignDecoder.SetCodeLengths(&newLevels[kMainTableSize + kDistTableSize]));
+ RIF(m_LenDecoder.SetCodeLengths(&newLevels[kMainTableSize + kDistTableSize + kAlignTableSize]));
+
+ memcpy(m_LastLevels, newLevels, kTablesSizesSum);
+ return S_OK;
+}
+
+class CCoderReleaser
+{
+ CDecoder *m_Coder;
+public:
+ CCoderReleaser(CDecoder *coder): m_Coder(coder) {}
+ ~CCoderReleaser()
+ {
+ m_Coder->ReleaseStreams();
+ }
+};
+
+HRESULT CDecoder::ReadEndOfBlock(bool &keepDecompressing)
+{
+ if (ReadBits(1) != 0)
+ {
+ // old file
+ TablesRead = false;
+ return ReadTables(keepDecompressing);
+ }
+ // new file
+ keepDecompressing = false;
+ TablesRead = (ReadBits(1) == 0);
+ return S_OK;
+}
+
+UInt32 kDistStart[kDistTableSize];
+
+class CDistInit
+{
+public:
+ CDistInit() { Init(); }
+ void Init()
+ {
+ UInt32 start = 0;
+ for (UInt32 i = 0; i < kDistTableSize; i++)
+ {
+ kDistStart[i] = start;
+ start += (1 << kDistDirectBits[i]);
+ }
+ }
+} g_DistInit;
+
+HRESULT CDecoder::DecodeLZ(bool &keepDecompressing)
+{
+ UInt32 rep0 = _reps[0];
+ UInt32 rep1 = _reps[1];
+ UInt32 rep2 = _reps[2];
+ UInt32 rep3 = _reps[3];
+ UInt32 length = _lastLength;
+ for (;;)
+ {
+ if (((_wrPtr - _winPos) & kWindowMask) < 260 && _wrPtr != _winPos)
+ {
+ RINOK(WriteBuf());
+ if (_writtenFileSize > _unpackSize)
+ {
+ keepDecompressing = false;
+ return S_OK;
+ }
+ }
+ UInt32 number = m_MainDecoder.DecodeSymbol(&m_InBitStream.bitDecoder);
+ if (number < 256)
+ {
+ PutByte((Byte)number);
+ continue;
+ }
+ else if (number == kSymbolReadTable)
+ {
+ RINOK(ReadEndOfBlock(keepDecompressing));
+ break;
+ }
+ else if (number == 257)
+ {
+ if (!ReadVmCodeLZ())
+ return S_FALSE;
+ continue;
+ }
+ else if (number == 258)
+ {
+ if (length == 0)
+ return S_FALSE;
+ }
+ else if (number < kSymbolRep + 4)
+ {
+ if (number != kSymbolRep)
+ {
+ UInt32 distance;
+ if (number == kSymbolRep + 1)
+ distance = rep1;
+ else
+ {
+ if (number == kSymbolRep + 2)
+ distance = rep2;
+ else
+ {
+ distance = rep3;
+ rep3 = rep2;
+ }
+ rep2 = rep1;
+ }
+ rep1 = rep0;
+ rep0 = distance;
+ }
+
+ UInt32 number = m_LenDecoder.DecodeSymbol(&m_InBitStream.bitDecoder);
+ if (number >= kLenTableSize)
+ return S_FALSE;
+ length = 2 + kLenStart[number] + m_InBitStream.bitDecoder.ReadBits(kLenDirectBits[number]);
+ }
+ else
+ {
+ rep3 = rep2;
+ rep2 = rep1;
+ rep1 = rep0;
+ if (number < 271)
+ {
+ number -= 263;
+ rep0 = kLen2DistStarts[number] + m_InBitStream.bitDecoder.ReadBits(kLen2DistDirectBits[number]);
+ length = 2;
+ }
+ else if (number < 299)
+ {
+ number -= 271;
+ length = kNormalMatchMinLen + (UInt32)kLenStart[number] + m_InBitStream.bitDecoder.ReadBits(kLenDirectBits[number]);
+ UInt32 number = m_DistDecoder.DecodeSymbol(&m_InBitStream.bitDecoder);
+ if (number >= kDistTableSize)
+ return S_FALSE;
+ rep0 = kDistStart[number];
+ int numBits = kDistDirectBits[number];
+ if (number >= (kNumAlignBits * 2) + 2)
+ {
+ if (numBits > kNumAlignBits)
+ rep0 += (m_InBitStream.bitDecoder.ReadBits(numBits - kNumAlignBits) << kNumAlignBits);
+ if (PrevAlignCount > 0)
+ {
+ PrevAlignCount--;
+ rep0 += PrevAlignBits;
+ }
+ else
+ {
+ UInt32 number = m_AlignDecoder.DecodeSymbol(&m_InBitStream.bitDecoder);
+ if (number < (1 << kNumAlignBits))
+ {
+ rep0 += number;
+ PrevAlignBits = number;
+ }
+ else if (number == (1 << kNumAlignBits))
+ {
+ PrevAlignCount = kNumAlignReps;
+ rep0 += PrevAlignBits;
+ }
+ else
+ return S_FALSE;
+ }
+ }
+ else
+ rep0 += m_InBitStream.bitDecoder.ReadBits(numBits);
+ length += ((kDistLimit4 - rep0) >> 31) + ((kDistLimit3 - rep0) >> 31);
+ }
+ else
+ return S_FALSE;
+ }
+ if (rep0 >= _lzSize)
+ return S_FALSE;
+ CopyBlock(rep0, length);
+ }
+ _reps[0] = rep0;
+ _reps[1] = rep1;
+ _reps[2] = rep2;
+ _reps[3] = rep3;
+ _lastLength = length;
+
+ return S_OK;
+}
+
+HRESULT CDecoder::CodeReal(ICompressProgressInfo *progress)
+{
+ _writtenFileSize = 0;
+ if (!m_IsSolid)
+ {
+ _lzSize = 0;
+ _winPos = 0;
+ _wrPtr = 0;
+ for (int i = 0; i < kNumReps; i++)
+ _reps[i] = 0;
+ _lastLength = 0;
+ memset(m_LastLevels, 0, kTablesSizesSum);
+ TablesRead = false;
+ PpmEscChar = 2;
+ PpmError = true;
+ InitFilters();
+ }
+ if (!m_IsSolid || !TablesRead)
+ {
+ bool keepDecompressing;
+ RINOK(ReadTables(keepDecompressing));
+ if (!keepDecompressing)
+ return S_OK;
+ }
+
+ for (;;)
+ {
+ bool keepDecompressing;
+ if (_lzMode)
+ {
+ RINOK(DecodeLZ(keepDecompressing))
+ }
+ else
+ {
+ RINOK(DecodePPM(1 << 18, keepDecompressing))
+ }
+ UInt64 packSize = m_InBitStream.bitDecoder.GetProcessedSize();
+ RINOK(progress->SetRatioInfo(&packSize, &_writtenFileSize));
+ if (!keepDecompressing)
+ break;
+ }
+ RINOK(WriteBuf());
+ UInt64 packSize = m_InBitStream.bitDecoder.GetProcessedSize();
+ RINOK(progress->SetRatioInfo(&packSize, &_writtenFileSize));
+ if (_writtenFileSize < _unpackSize)
+ return S_FALSE;
+ return S_OK;
+}
+
+STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
+{
+ try
+ {
+ if (inSize == NULL || outSize == NULL)
+ return E_INVALIDARG;
+
+ if (_vmData == 0)
+ {
+ _vmData = (Byte *)::MidAlloc(kVmDataSizeMax + kVmCodeSizeMax);
+ if (_vmData == 0)
+ return E_OUTOFMEMORY;
+ _vmCode = _vmData + kVmDataSizeMax;
+ }
+
+ if (_window == 0)
+ {
+ _window = (Byte *)::MidAlloc(kWindowSize);
+ if (_window == 0)
+ return E_OUTOFMEMORY;
+ }
+ if (!m_InBitStream.bitDecoder.Create(1 << 20))
+ return E_OUTOFMEMORY;
+ if (!_vm.Create())
+ return E_OUTOFMEMORY;
+
+
+ m_InBitStream.bitDecoder.SetStream(inStream);
+ m_InBitStream.bitDecoder.Init();
+ _outStream = outStream;
+
+ CCoderReleaser coderReleaser(this);
+ _unpackSize = *outSize;
+ return CodeReal(progress);
+ }
+ catch(const CInBufferException &e) { return e.ErrorCode; }
+ catch(...) { return S_FALSE; }
+ // CNewException is possible here. But probably CNewException is caused
+ // by error in data stream.
+}
+
+STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
+{
+ if (size < 1)
+ return E_INVALIDARG;
+ m_IsSolid = (data[0] != 0);
+ return S_OK;
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Decoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Decoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Decoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Decoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,267 @@
+// Rar3Decoder.h
+// According to unRAR license, this code may not be used to develop
+// a program that creates RAR archives
+
+/* This code uses Carryless rangecoder (1999): Dmitry Subbotin : Public domain */
+
+#ifndef __COMPRESS_RAR3_DECODER_H
+#define __COMPRESS_RAR3_DECODER_H
+
+#include "../../../C/Ppmd7.h"
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+#include "../Common/InBuffer.h"
+
+#include "BitmDecoder.h"
+#include "HuffmanDecoder.h"
+#include "Rar3Vm.h"
+
+namespace NCompress {
+namespace NRar3 {
+
+const UInt32 kWindowSize = 1 << 22;
+const UInt32 kWindowMask = (kWindowSize - 1);
+
+const UInt32 kNumReps = 4;
+const UInt32 kNumLen2Symbols = 8;
+const UInt32 kLenTableSize = 28;
+const UInt32 kMainTableSize = 256 + 1 + 1 + 1 + kNumReps + kNumLen2Symbols + kLenTableSize;
+const UInt32 kDistTableSize = 60;
+
+const int kNumAlignBits = 4;
+const UInt32 kAlignTableSize = (1 << kNumAlignBits) + 1;
+
+const UInt32 kLevelTableSize = 20;
+
+const UInt32 kTablesSizesSum = kMainTableSize + kDistTableSize + kAlignTableSize + kLenTableSize;
+
+class CBitDecoder
+{
+ UInt32 m_Value;
+ unsigned m_BitPos;
+public:
+ CInBuffer m_Stream;
+ bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
+ void SetStream(ISequentialInStream *inStream) { m_Stream.SetStream(inStream);}
+ void ReleaseStream() { m_Stream.ReleaseStream();}
+
+ void Init()
+ {
+ m_Stream.Init();
+ m_BitPos = 0;
+ m_Value = 0;
+ }
+
+ UInt64 GetProcessedSize() const { return m_Stream.GetProcessedSize() - (m_BitPos) / 8; }
+ UInt32 GetBitPosition() const { return ((8 - m_BitPos) & 7); }
+
+ UInt32 GetValue(unsigned numBits)
+ {
+ if (m_BitPos < numBits)
+ {
+ m_BitPos += 8;
+ m_Value = (m_Value << 8) | m_Stream.ReadByte();
+ if (m_BitPos < numBits)
+ {
+ m_BitPos += 8;
+ m_Value = (m_Value << 8) | m_Stream.ReadByte();
+ }
+ }
+ return m_Value >> (m_BitPos - numBits);
+ }
+
+ void MovePos(unsigned numBits)
+ {
+ m_BitPos -= numBits;
+ m_Value = m_Value & ((1 << m_BitPos) - 1);
+ }
+
+ UInt32 ReadBits(unsigned numBits)
+ {
+ UInt32 res = GetValue(numBits);
+ MovePos(numBits);
+ return res;
+ }
+};
+
+const UInt32 kTopValue = (1 << 24);
+const UInt32 kBot = (1 << 15);
+
+struct CRangeDecoder
+{
+ IPpmd7_RangeDec s;
+ UInt32 Range;
+ UInt32 Code;
+ UInt32 Low;
+ CBitDecoder bitDecoder;
+ SRes Res;
+
+public:
+ void InitRangeCoder()
+ {
+ Code = 0;
+ Low = 0;
+ Range = 0xFFFFFFFF;
+ for (int i = 0; i < 4; i++)
+ Code = (Code << 8) | bitDecoder.ReadBits(8);
+ }
+
+ void Normalize()
+ {
+ while ((Low ^ (Low + Range)) < kTopValue ||
+ Range < kBot && ((Range = (0 - Low) & (kBot - 1)), 1))
+ {
+ Code = (Code << 8) | bitDecoder.m_Stream.ReadByte();
+ Range <<= 8;
+ Low <<= 8;
+ }
+ }
+
+ CRangeDecoder();
+};
+
+struct CFilter: public NVm::CProgram
+{
+ CRecordVector<Byte> GlobalData;
+ UInt32 BlockStart;
+ UInt32 BlockSize;
+ UInt32 ExecCount;
+ CFilter(): BlockStart(0), BlockSize(0), ExecCount(0) {}
+};
+
+struct CTempFilter: public NVm::CProgramInitState
+{
+ UInt32 BlockStart;
+ UInt32 BlockSize;
+ UInt32 ExecCount;
+ bool NextWindow;
+
+ UInt32 FilterIndex;
+};
+
+const int kNumHuffmanBits = 15;
+
+class CDecoder:
+ public ICompressCoder,
+ public ICompressSetDecoderProperties2,
+ public CMyUnknownImp
+{
+ CRangeDecoder m_InBitStream;
+ Byte *_window;
+ UInt32 _winPos;
+ UInt32 _wrPtr;
+ UInt64 _lzSize;
+ UInt64 _unpackSize;
+ UInt64 _writtenFileSize; // if it's > _unpackSize, then _unpackSize only written
+ CMyComPtr<ISequentialOutStream> _outStream;
+ NHuffman::CDecoder<kNumHuffmanBits, kMainTableSize> m_MainDecoder;
+ NHuffman::CDecoder<kNumHuffmanBits, kDistTableSize> m_DistDecoder;
+ NHuffman::CDecoder<kNumHuffmanBits, kAlignTableSize> m_AlignDecoder;
+ NHuffman::CDecoder<kNumHuffmanBits, kLenTableSize> m_LenDecoder;
+ NHuffman::CDecoder<kNumHuffmanBits, kLevelTableSize> m_LevelDecoder;
+
+ UInt32 _reps[kNumReps];
+ UInt32 _lastLength;
+
+ Byte m_LastLevels[kTablesSizesSum];
+
+ Byte *_vmData;
+ Byte *_vmCode;
+ NVm::CVm _vm;
+ CRecordVector<CFilter *> _filters;
+ CRecordVector<CTempFilter *> _tempFilters;
+ UInt32 _lastFilter;
+
+ bool m_IsSolid;
+
+ bool _lzMode;
+
+ UInt32 PrevAlignBits;
+ UInt32 PrevAlignCount;
+
+ bool TablesRead;
+
+ CPpmd7 _ppmd;
+ int PpmEscChar;
+ bool PpmError;
+
+ HRESULT WriteDataToStream(const Byte *data, UInt32 size);
+ HRESULT WriteData(const Byte *data, UInt32 size);
+ HRESULT WriteArea(UInt32 startPtr, UInt32 endPtr);
+ void ExecuteFilter(int tempFilterIndex, NVm::CBlockRef &outBlockRef);
+ HRESULT WriteBuf();
+
+ void InitFilters();
+ bool AddVmCode(UInt32 firstByte, UInt32 codeSize);
+ bool ReadVmCodeLZ();
+ bool ReadVmCodePPM();
+
+ UInt32 ReadBits(int numBits);
+
+ HRESULT InitPPM();
+ int DecodePpmSymbol();
+ HRESULT DecodePPM(Int32 num, bool &keepDecompressing);
+
+ HRESULT ReadTables(bool &keepDecompressing);
+ HRESULT ReadEndOfBlock(bool &keepDecompressing);
+ HRESULT DecodeLZ(bool &keepDecompressing);
+ HRESULT CodeReal(ICompressProgressInfo *progress);
+public:
+ CDecoder();
+ ~CDecoder();
+
+ MY_UNKNOWN_IMP1(ICompressSetDecoderProperties2)
+
+ void ReleaseStreams()
+ {
+ _outStream.Release();
+ m_InBitStream.bitDecoder.ReleaseStream();
+ }
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
+
+ void CopyBlock(UInt32 distance, UInt32 len)
+ {
+ _lzSize += len;
+ UInt32 pos = (_winPos - distance - 1) & kWindowMask;
+ Byte *window = _window;
+ UInt32 winPos = _winPos;
+ if (kWindowSize - winPos > len && kWindowSize - pos > len)
+ {
+ const Byte *src = window + pos;
+ Byte *dest = window + winPos;
+ _winPos += len;
+ do
+ *dest++ = *src++;
+ while(--len != 0);
+ return;
+ }
+ do
+ {
+ window[winPos] = window[pos];
+ winPos = (winPos + 1) & kWindowMask;
+ pos = (pos + 1) & kWindowMask;
+ }
+ while(--len != 0);
+ _winPos = winPos;
+ }
+
+ void PutByte(Byte b)
+ {
+ _window[_winPos] = b;
+ _winPos = (_winPos + 1) & kWindowMask;
+ _lzSize++;
+ }
+
+
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Vm.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Vm.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Vm.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Vm.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,1091 @@
+// Rar3Vm.cpp
+// According to unRAR license, this code may not be used to develop
+// a program that creates RAR archives
+
+/*
+Note:
+ Due to performance considerations Rar VM may set Flags C incorrectly
+ for some operands (SHL x, 0, ... ).
+ Check implementation of concrete VM command
+ to see if it sets flags right.
+*/
+
+#include "StdAfx.h"
+
+#include "../../../C/7zCrc.h"
+#include "../../../C/Alloc.h"
+
+#include "Rar3Vm.h"
+
+namespace NCompress {
+namespace NRar3 {
+
+UInt32 CMemBitDecoder::ReadBits(int numBits)
+{
+ UInt32 res = 0;
+ for (;;)
+ {
+ Byte b = _bitPos < _bitSize ? _data[_bitPos >> 3] : 0;
+ int avail = (int)(8 - (_bitPos & 7));
+ if (numBits <= avail)
+ {
+ _bitPos += numBits;
+ return res | (b >> (avail - numBits)) & ((1 << numBits) - 1);
+ }
+ numBits -= avail;
+ res |= (UInt32)(b & ((1 << avail) - 1)) << numBits;
+ _bitPos += avail;
+ }
+}
+
+UInt32 CMemBitDecoder::ReadBit() { return ReadBits(1); }
+
+namespace NVm {
+
+static const UInt32 kStackRegIndex = kNumRegs - 1;
+
+static const UInt32 FLAG_C = 1;
+static const UInt32 FLAG_Z = 2;
+static const UInt32 FLAG_S = 0x80000000;
+
+static const Byte CF_OP0 = 0;
+static const Byte CF_OP1 = 1;
+static const Byte CF_OP2 = 2;
+static const Byte CF_OPMASK = 3;
+static const Byte CF_BYTEMODE = 4;
+static const Byte CF_JUMP = 8;
+static const Byte CF_PROC = 16;
+static const Byte CF_USEFLAGS = 32;
+static const Byte CF_CHFLAGS = 64;
+
+static Byte kCmdFlags[]=
+{
+ /* CMD_MOV */ CF_OP2 | CF_BYTEMODE,
+ /* CMD_CMP */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
+ /* CMD_ADD */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
+ /* CMD_SUB */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
+ /* CMD_JZ */ CF_OP1 | CF_JUMP | CF_USEFLAGS,
+ /* CMD_JNZ */ CF_OP1 | CF_JUMP | CF_USEFLAGS,
+ /* CMD_INC */ CF_OP1 | CF_BYTEMODE | CF_CHFLAGS,
+ /* CMD_DEC */ CF_OP1 | CF_BYTEMODE | CF_CHFLAGS,
+ /* CMD_JMP */ CF_OP1 | CF_JUMP,
+ /* CMD_XOR */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
+ /* CMD_AND */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
+ /* CMD_OR */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
+ /* CMD_TEST */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
+ /* CMD_JS */ CF_OP1 | CF_JUMP | CF_USEFLAGS,
+ /* CMD_JNS */ CF_OP1 | CF_JUMP | CF_USEFLAGS,
+ /* CMD_JB */ CF_OP1 | CF_JUMP | CF_USEFLAGS,
+ /* CMD_JBE */ CF_OP1 | CF_JUMP | CF_USEFLAGS,
+ /* CMD_JA */ CF_OP1 | CF_JUMP | CF_USEFLAGS,
+ /* CMD_JAE */ CF_OP1 | CF_JUMP | CF_USEFLAGS,
+ /* CMD_PUSH */ CF_OP1,
+ /* CMD_POP */ CF_OP1,
+ /* CMD_CALL */ CF_OP1 | CF_PROC,
+ /* CMD_RET */ CF_OP0 | CF_PROC,
+ /* CMD_NOT */ CF_OP1 | CF_BYTEMODE,
+ /* CMD_SHL */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
+ /* CMD_SHR */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
+ /* CMD_SAR */ CF_OP2 | CF_BYTEMODE | CF_CHFLAGS,
+ /* CMD_NEG */ CF_OP1 | CF_BYTEMODE | CF_CHFLAGS,
+ /* CMD_PUSHA */ CF_OP0,
+ /* CMD_POPA */ CF_OP0,
+ /* CMD_PUSHF */ CF_OP0 | CF_USEFLAGS,
+ /* CMD_POPF */ CF_OP0 | CF_CHFLAGS,
+ /* CMD_MOVZX */ CF_OP2,
+ /* CMD_MOVSX */ CF_OP2,
+ /* CMD_XCHG */ CF_OP2 | CF_BYTEMODE,
+ /* CMD_MUL */ CF_OP2 | CF_BYTEMODE,
+ /* CMD_DIV */ CF_OP2 | CF_BYTEMODE,
+ /* CMD_ADC */ CF_OP2 | CF_BYTEMODE | CF_USEFLAGS | CF_CHFLAGS ,
+ /* CMD_SBB */ CF_OP2 | CF_BYTEMODE | CF_USEFLAGS | CF_CHFLAGS ,
+ /* CMD_PRINT */ CF_OP0
+};
+
+CVm::CVm(): Mem(NULL) {}
+
+bool CVm::Create()
+{
+ if (Mem == NULL)
+ Mem = (Byte *)::MyAlloc(kSpaceSize + 4);
+ return (Mem != NULL);
+}
+
+CVm::~CVm()
+{
+ ::MyFree(Mem);
+}
+
+// CVm::Execute can change CProgram object: it clears progarm if VM returns error.
+
+bool CVm::Execute(CProgram *prg, const CProgramInitState *initState,
+ CBlockRef &outBlockRef, CRecordVector<Byte> &outGlobalData)
+{
+ memcpy(R, initState->InitR, sizeof(initState->InitR));
+ R[kStackRegIndex] = kSpaceSize;
+ R[kNumRegs] = 0;
+ Flags = 0;
+
+ UInt32 globalSize = MyMin((UInt32)initState->GlobalData.Size(), kGlobalSize);
+ if (globalSize != 0)
+ memcpy(Mem + kGlobalOffset, &initState->GlobalData[0], globalSize);
+ UInt32 staticSize = MyMin((UInt32)prg->StaticData.Size(), kGlobalSize - globalSize);
+ if (staticSize != 0)
+ memcpy(Mem + kGlobalOffset + globalSize, &prg->StaticData[0], staticSize);
+
+ bool res = true;
+ #ifdef RARVM_STANDARD_FILTERS
+ if (prg->StandardFilterIndex >= 0)
+ ExecuteStandardFilter(prg->StandardFilterIndex);
+ else
+ #endif
+ {
+ res = ExecuteCode(prg);
+ if (!res)
+ prg->Commands[0].OpCode = CMD_RET;
+ }
+ UInt32 newBlockPos = GetFixedGlobalValue32(NGlobalOffset::kBlockPos) & kSpaceMask;
+ UInt32 newBlockSize = GetFixedGlobalValue32(NGlobalOffset::kBlockSize) & kSpaceMask;
+ if (newBlockPos + newBlockSize >= kSpaceSize)
+ newBlockPos = newBlockSize = 0;
+ outBlockRef.Offset = newBlockPos;
+ outBlockRef.Size = newBlockSize;
+
+ outGlobalData.Clear();
+ UInt32 dataSize = GetFixedGlobalValue32(NGlobalOffset::kGlobalMemOutSize);
+ dataSize = MyMin(dataSize, kGlobalSize - kFixedGlobalSize);
+ if (dataSize != 0)
+ {
+ dataSize += kFixedGlobalSize;
+ outGlobalData.Reserve(dataSize);
+ for (UInt32 i = 0; i < dataSize; i++)
+ outGlobalData.Add(Mem[kGlobalOffset + i]);
+ }
+ return res;
+}
+
+
+#define SET_IP(IP) \
+ if ((IP) >= numCommands) return true; \
+ if (--maxOpCount <= 0) return false; \
+ cmd = commands + (IP);
+
+#define GET_FLAG_S_B(res) (((res) & 0x80) ? FLAG_S : 0)
+#define SET_IP_OP1 { UInt32 val = GetOperand32(&cmd->Op1); SET_IP(val); }
+#define FLAGS_UPDATE_SZ Flags = res == 0 ? FLAG_Z : res & FLAG_S
+#define FLAGS_UPDATE_SZ_B Flags = (res & 0xFF) == 0 ? FLAG_Z : GET_FLAG_S_B(res)
+
+UInt32 CVm::GetOperand32(const COperand *op) const
+{
+ switch(op->Type)
+ {
+ case OP_TYPE_REG: return R[op->Data];
+ case OP_TYPE_REGMEM: return GetValue32(&Mem[(op->Base + R[op->Data]) & kSpaceMask]);
+ default: return op->Data;
+ }
+}
+
+void CVm::SetOperand32(const COperand *op, UInt32 val)
+{
+ switch(op->Type)
+ {
+ case OP_TYPE_REG: R[op->Data] = val; return;
+ case OP_TYPE_REGMEM: SetValue32(&Mem[(op->Base + R[op->Data]) & kSpaceMask], val); return;
+ }
+}
+
+Byte CVm::GetOperand8(const COperand *op) const
+{
+ switch(op->Type)
+ {
+ case OP_TYPE_REG: return (Byte)R[op->Data];
+ case OP_TYPE_REGMEM: return Mem[(op->Base + R[op->Data]) & kSpaceMask];;
+ default: return (Byte)op->Data;
+ }
+}
+
+void CVm::SetOperand8(const COperand *op, Byte val)
+{
+ switch(op->Type)
+ {
+ case OP_TYPE_REG: R[op->Data] = (R[op->Data] & 0xFFFFFF00) | val; return;
+ case OP_TYPE_REGMEM: Mem[(op->Base + R[op->Data]) & kSpaceMask] = val; return;
+ }
+}
+
+UInt32 CVm::GetOperand(bool byteMode, const COperand *op) const
+{
+ if (byteMode)
+ return GetOperand8(op);
+ return GetOperand32(op);
+}
+
+void CVm::SetOperand(bool byteMode, const COperand *op, UInt32 val)
+{
+ if (byteMode)
+ SetOperand8(op, (Byte)(val & 0xFF));
+ else
+ SetOperand32(op, val);
+}
+
+bool CVm::ExecuteCode(const CProgram *prg)
+{
+ Int32 maxOpCount = 25000000;
+ const CCommand *commands = &prg->Commands[0];
+ const CCommand *cmd = commands;
+ UInt32 numCommands = prg->Commands.Size();
+ for (;;)
+ {
+ switch(cmd->OpCode)
+ {
+ #ifndef RARVM_NO_VM
+
+ case CMD_MOV:
+ SetOperand32(&cmd->Op1, GetOperand32(&cmd->Op2));
+ break;
+ case CMD_MOVB:
+ SetOperand8(&cmd->Op1, GetOperand8(&cmd->Op2));
+ break;
+ case CMD_CMP:
+ {
+ UInt32 v1 = GetOperand32(&cmd->Op1);
+ UInt32 res = v1 - GetOperand32(&cmd->Op2);
+ Flags = res == 0 ? FLAG_Z : (res > v1) | (res & FLAG_S);
+ }
+ break;
+ case CMD_CMPB:
+ {
+ Byte v1 = GetOperand8(&cmd->Op1);
+ Byte res = v1 - GetOperand8(&cmd->Op2);
+ res &= 0xFF;
+ Flags = res == 0 ? FLAG_Z : (res > v1) | GET_FLAG_S_B(res);
+ }
+ break;
+ case CMD_ADD:
+ {
+ UInt32 v1 = GetOperand32(&cmd->Op1);
+ UInt32 res = v1 + GetOperand32(&cmd->Op2);
+ SetOperand32(&cmd->Op1, res);
+ Flags = (res < v1) | (res == 0 ? FLAG_Z : (res & FLAG_S));
+ }
+ break;
+ case CMD_ADDB:
+ {
+ Byte v1 = GetOperand8(&cmd->Op1);
+ Byte res = v1 + GetOperand8(&cmd->Op2);
+ res &= 0xFF;
+ SetOperand8(&cmd->Op1, (Byte)res);
+ Flags = (res < v1) | (res == 0 ? FLAG_Z : GET_FLAG_S_B(res));
+ }
+ break;
+ case CMD_ADC:
+ {
+ UInt32 v1 = GetOperand(cmd->ByteMode, &cmd->Op1);
+ UInt32 FC = (Flags & FLAG_C);
+ UInt32 res = v1 + GetOperand(cmd->ByteMode, &cmd->Op2) + FC;
+ if (cmd->ByteMode)
+ res &= 0xFF;
+ SetOperand(cmd->ByteMode, &cmd->Op1, res);
+ Flags = (res < v1 || res == v1 && FC) | (res == 0 ? FLAG_Z : (res & FLAG_S));
+ }
+ break;
+ case CMD_SUB:
+ {
+ UInt32 v1 = GetOperand32(&cmd->Op1);
+ UInt32 res = v1 - GetOperand32(&cmd->Op2);
+ SetOperand32(&cmd->Op1, res);
+ Flags = res == 0 ? FLAG_Z : (res > v1) | (res & FLAG_S);
+ }
+ break;
+ case CMD_SUBB:
+ {
+ UInt32 v1 = GetOperand8(&cmd->Op1);
+ UInt32 res = v1 - GetOperand8(&cmd->Op2);
+ SetOperand8(&cmd->Op1, (Byte)res);
+ Flags = res == 0 ? FLAG_Z : (res > v1) | (res & FLAG_S);
+ }
+ break;
+ case CMD_SBB:
+ {
+ UInt32 v1 = GetOperand(cmd->ByteMode, &cmd->Op1);
+ UInt32 FC = (Flags & FLAG_C);
+ UInt32 res = v1 - GetOperand(cmd->ByteMode, &cmd->Op2) - FC;
+ // Flags = res == 0 ? FLAG_Z : (res > v1 || res == v1 && FC) | (res & FLAG_S);
+ if (cmd->ByteMode)
+ res &= 0xFF;
+ SetOperand(cmd->ByteMode, &cmd->Op1, res);
+ Flags = (res > v1 || res == v1 && FC) | (res == 0 ? FLAG_Z : (res & FLAG_S));
+ }
+ break;
+ case CMD_INC:
+ {
+ UInt32 res = GetOperand32(&cmd->Op1) + 1;
+ SetOperand32(&cmd->Op1, res);
+ FLAGS_UPDATE_SZ;
+ }
+ break;
+ case CMD_INCB:
+ {
+ Byte res = GetOperand8(&cmd->Op1) + 1;
+ SetOperand8(&cmd->Op1, res);;
+ FLAGS_UPDATE_SZ_B;
+ }
+ break;
+ case CMD_DEC:
+ {
+ UInt32 res = GetOperand32(&cmd->Op1) - 1;
+ SetOperand32(&cmd->Op1, res);
+ FLAGS_UPDATE_SZ;
+ }
+ break;
+ case CMD_DECB:
+ {
+ Byte res = GetOperand8(&cmd->Op1) - 1;
+ SetOperand8(&cmd->Op1, res);;
+ FLAGS_UPDATE_SZ_B;
+ }
+ break;
+ case CMD_XOR:
+ {
+ UInt32 res = GetOperand32(&cmd->Op1) ^ GetOperand32(&cmd->Op2);
+ SetOperand32(&cmd->Op1, res);
+ FLAGS_UPDATE_SZ;
+ }
+ break;
+ case CMD_XORB:
+ {
+ Byte res = GetOperand8(&cmd->Op1) ^ GetOperand8(&cmd->Op2);
+ SetOperand8(&cmd->Op1, res);
+ FLAGS_UPDATE_SZ_B;
+ }
+ break;
+ case CMD_AND:
+ {
+ UInt32 res = GetOperand32(&cmd->Op1) & GetOperand32(&cmd->Op2);
+ SetOperand32(&cmd->Op1, res);
+ FLAGS_UPDATE_SZ;
+ }
+ break;
+ case CMD_ANDB:
+ {
+ Byte res = GetOperand8(&cmd->Op1) & GetOperand8(&cmd->Op2);
+ SetOperand8(&cmd->Op1, res);
+ FLAGS_UPDATE_SZ_B;
+ }
+ break;
+ case CMD_OR:
+ {
+ UInt32 res = GetOperand32(&cmd->Op1) | GetOperand32(&cmd->Op2);
+ SetOperand32(&cmd->Op1, res);
+ FLAGS_UPDATE_SZ;
+ }
+ break;
+ case CMD_ORB:
+ {
+ Byte res = GetOperand8(&cmd->Op1) | GetOperand8(&cmd->Op2);
+ SetOperand8(&cmd->Op1, res);
+ FLAGS_UPDATE_SZ_B;
+ }
+ break;
+ case CMD_TEST:
+ {
+ UInt32 res = GetOperand32(&cmd->Op1) & GetOperand32(&cmd->Op2);
+ FLAGS_UPDATE_SZ;
+ }
+ break;
+ case CMD_TESTB:
+ {
+ Byte res = GetOperand8(&cmd->Op1) & GetOperand8(&cmd->Op2);
+ FLAGS_UPDATE_SZ_B;
+ }
+ break;
+ case CMD_NOT:
+ SetOperand(cmd->ByteMode, &cmd->Op1, ~GetOperand(cmd->ByteMode, &cmd->Op1));
+ break;
+ case CMD_NEG:
+ {
+ UInt32 res = 0 - GetOperand32(&cmd->Op1);
+ SetOperand32(&cmd->Op1, res);
+ Flags = res == 0 ? FLAG_Z : FLAG_C | (res & FLAG_S);
+ }
+ break;
+ case CMD_NEGB:
+ {
+ Byte res = (Byte)(0 - GetOperand8(&cmd->Op1));
+ SetOperand8(&cmd->Op1, res);
+ Flags = res == 0 ? FLAG_Z : FLAG_C | GET_FLAG_S_B(res);
+ }
+ break;
+
+ case CMD_SHL:
+ {
+ UInt32 v1 = GetOperand32(&cmd->Op1);
+ int v2 = (int)GetOperand32(&cmd->Op2);
+ UInt32 res = v1 << v2;
+ SetOperand32(&cmd->Op1, res);
+ Flags = (res == 0 ? FLAG_Z : (res & FLAG_S)) | ((v1 << (v2 - 1)) & 0x80000000 ? FLAG_C : 0);
+ }
+ break;
+ case CMD_SHLB:
+ {
+ Byte v1 = GetOperand8(&cmd->Op1);
+ int v2 = (int)GetOperand8(&cmd->Op2);
+ Byte res = (Byte)(v1 << v2);
+ SetOperand8(&cmd->Op1, res);
+ Flags = (res == 0 ? FLAG_Z : GET_FLAG_S_B(res)) | ((v1 << (v2 - 1)) & 0x80 ? FLAG_C : 0);
+ }
+ break;
+ case CMD_SHR:
+ {
+ UInt32 v1 = GetOperand32(&cmd->Op1);
+ int v2 = (int)GetOperand32(&cmd->Op2);
+ UInt32 res = v1 >> v2;
+ SetOperand32(&cmd->Op1, res);
+ Flags = (res == 0 ? FLAG_Z : (res & FLAG_S)) | ((v1 >> (v2 - 1)) & FLAG_C);
+ }
+ break;
+ case CMD_SHRB:
+ {
+ Byte v1 = GetOperand8(&cmd->Op1);
+ int v2 = (int)GetOperand8(&cmd->Op2);
+ Byte res = (Byte)(v1 >> v2);
+ SetOperand8(&cmd->Op1, res);
+ Flags = (res == 0 ? FLAG_Z : GET_FLAG_S_B(res)) | ((v1 >> (v2 - 1)) & FLAG_C);
+ }
+ break;
+ case CMD_SAR:
+ {
+ UInt32 v1 = GetOperand32(&cmd->Op1);
+ int v2 = (int)GetOperand32(&cmd->Op2);
+ UInt32 res = UInt32(((Int32)v1) >> v2);
+ SetOperand32(&cmd->Op1, res);
+ Flags= (res == 0 ? FLAG_Z : (res & FLAG_S)) | ((v1 >> (v2 - 1)) & FLAG_C);
+ }
+ break;
+ case CMD_SARB:
+ {
+ Byte v1 = GetOperand8(&cmd->Op1);
+ int v2 = (int)GetOperand8(&cmd->Op2);
+ Byte res = (Byte)(((signed char)v1) >> v2);
+ SetOperand8(&cmd->Op1, res);
+ Flags= (res == 0 ? FLAG_Z : GET_FLAG_S_B(res)) | ((v1 >> (v2 - 1)) & FLAG_C);
+ }
+ break;
+
+ case CMD_JMP:
+ SET_IP_OP1;
+ continue;
+ case CMD_JZ:
+ if ((Flags & FLAG_Z) != 0)
+ {
+ SET_IP_OP1;
+ continue;
+ }
+ break;
+ case CMD_JNZ:
+ if ((Flags & FLAG_Z) == 0)
+ {
+ SET_IP_OP1;
+ continue;
+ }
+ break;
+ case CMD_JS:
+ if ((Flags & FLAG_S) != 0)
+ {
+ SET_IP_OP1;
+ continue;
+ }
+ break;
+ case CMD_JNS:
+ if ((Flags & FLAG_S) == 0)
+ {
+ SET_IP_OP1;
+ continue;
+ }
+ break;
+ case CMD_JB:
+ if ((Flags & FLAG_C) != 0)
+ {
+ SET_IP_OP1;
+ continue;
+ }
+ break;
+ case CMD_JBE:
+ if ((Flags & (FLAG_C | FLAG_Z)) != 0)
+ {
+ SET_IP_OP1;
+ continue;
+ }
+ break;
+ case CMD_JA:
+ if ((Flags & (FLAG_C | FLAG_Z)) == 0)
+ {
+ SET_IP_OP1;
+ continue;
+ }
+ break;
+ case CMD_JAE:
+ if ((Flags & FLAG_C) == 0)
+ {
+ SET_IP_OP1;
+ continue;
+ }
+ break;
+
+ case CMD_PUSH:
+ R[kStackRegIndex] -= 4;
+ SetValue32(&Mem[R[kStackRegIndex] & kSpaceMask], GetOperand32(&cmd->Op1));
+ break;
+ case CMD_POP:
+ SetOperand32(&cmd->Op1, GetValue32(&Mem[R[kStackRegIndex] & kSpaceMask]));
+ R[kStackRegIndex] += 4;
+ break;
+ case CMD_CALL:
+ R[kStackRegIndex] -= 4;
+ SetValue32(&Mem[R[kStackRegIndex] & kSpaceMask], (UInt32)(cmd - commands + 1));
+ SET_IP_OP1;
+ continue;
+
+ case CMD_PUSHA:
+ {
+ for (UInt32 i = 0, SP = R[kStackRegIndex] - 4; i < kNumRegs; i++, SP -= 4)
+ SetValue32(&Mem[SP & kSpaceMask], R[i]);
+ R[kStackRegIndex] -= kNumRegs * 4;
+ }
+ break;
+ case CMD_POPA:
+ {
+ for (UInt32 i = 0, SP = R[kStackRegIndex]; i < kNumRegs; i++, SP += 4)
+ R[kStackRegIndex - i] = GetValue32(&Mem[SP & kSpaceMask]);
+ }
+ break;
+ case CMD_PUSHF:
+ R[kStackRegIndex] -= 4;
+ SetValue32(&Mem[R[kStackRegIndex]&kSpaceMask], Flags);
+ break;
+ case CMD_POPF:
+ Flags = GetValue32(&Mem[R[kStackRegIndex] & kSpaceMask]);
+ R[kStackRegIndex] += 4;
+ break;
+
+ case CMD_MOVZX:
+ SetOperand32(&cmd->Op1, GetOperand8(&cmd->Op2));
+ break;
+ case CMD_MOVSX:
+ SetOperand32(&cmd->Op1, (UInt32)(Int32)(signed char)GetOperand8(&cmd->Op2));
+ break;
+ case CMD_XCHG:
+ {
+ UInt32 v1 = GetOperand(cmd->ByteMode, &cmd->Op1);
+ SetOperand(cmd->ByteMode, &cmd->Op1, GetOperand(cmd->ByteMode, &cmd->Op2));
+ SetOperand(cmd->ByteMode, &cmd->Op2, v1);
+ }
+ break;
+ case CMD_MUL:
+ {
+ UInt32 res = GetOperand32(&cmd->Op1) * GetOperand32(&cmd->Op2);
+ SetOperand32(&cmd->Op1, res);
+ }
+ break;
+ case CMD_MULB:
+ {
+ Byte res = GetOperand8(&cmd->Op1) * GetOperand8(&cmd->Op2);
+ SetOperand8(&cmd->Op1, res);
+ }
+ break;
+ case CMD_DIV:
+ {
+ UInt32 divider = GetOperand(cmd->ByteMode, &cmd->Op2);
+ if (divider != 0)
+ {
+ UInt32 res = GetOperand(cmd->ByteMode, &cmd->Op1) / divider;
+ SetOperand(cmd->ByteMode, &cmd->Op1, res);
+ }
+ }
+ break;
+
+ #endif
+
+ case CMD_RET:
+ {
+ if (R[kStackRegIndex] >= kSpaceSize)
+ return true;
+ UInt32 ip = GetValue32(&Mem[R[kStackRegIndex] & kSpaceMask]);
+ SET_IP(ip);
+ R[kStackRegIndex] += 4;
+ continue;
+ }
+ case CMD_PRINT:
+ break;
+ }
+ cmd++;
+ --maxOpCount;
+ }
+}
+
+
+//////////////////////////////////////////////////////
+// Read program
+
+UInt32 ReadEncodedUInt32(CMemBitDecoder &inp)
+{
+ switch(inp.ReadBits(2))
+ {
+ case 0:
+ return inp.ReadBits(4);
+ case 1:
+ {
+ UInt32 v = inp.ReadBits(4);
+ if (v == 0)
+ return 0xFFFFFF00 | inp.ReadBits(8);
+ else
+ return (v << 4) | inp.ReadBits(4);
+ }
+ case 2:
+ return inp.ReadBits(16);
+ default:
+ return inp.ReadBits(32);
+ }
+}
+
+void CVm::DecodeArg(CMemBitDecoder &inp, COperand &op, bool byteMode)
+{
+ if (inp.ReadBit())
+ {
+ op.Type = OP_TYPE_REG;
+ op.Data = inp.ReadBits(kNumRegBits);
+ }
+ else if (inp.ReadBit() == 0)
+ {
+ op.Type = OP_TYPE_INT;
+ if (byteMode)
+ op.Data = inp.ReadBits(8);
+ else
+ op.Data = ReadEncodedUInt32(inp);
+ }
+ else
+ {
+ op.Type = OP_TYPE_REGMEM;
+ if (inp.ReadBit() == 0)
+ {
+ op.Data = inp.ReadBits(kNumRegBits);
+ op.Base = 0;
+ }
+ else
+ {
+ if (inp.ReadBit() == 0)
+ op.Data = inp.ReadBits(kNumRegBits);
+ else
+ op.Data = kNumRegs;
+ op.Base = ReadEncodedUInt32(inp);
+ }
+ }
+}
+
+void CVm::ReadVmProgram(const Byte *code, UInt32 codeSize, CProgram *prg)
+{
+ CMemBitDecoder inp;
+ inp.Init(code, codeSize);
+
+ prg->StaticData.Clear();
+ if (inp.ReadBit())
+ {
+ UInt32 dataSize = ReadEncodedUInt32(inp) + 1;
+ for (UInt32 i = 0; inp.Avail() && i < dataSize; i++)
+ prg->StaticData.Add((Byte)inp.ReadBits(8));
+ }
+ while (inp.Avail())
+ {
+ prg->Commands.Add(CCommand());
+ CCommand *cmd = &prg->Commands.Back();
+ if (inp.ReadBit() == 0)
+ cmd->OpCode = (ECommand)inp.ReadBits(3);
+ else
+ cmd->OpCode = (ECommand)(8 + inp.ReadBits(5));
+ if (kCmdFlags[cmd->OpCode] & CF_BYTEMODE)
+ cmd->ByteMode = (inp.ReadBit()) ? true : false;
+ else
+ cmd->ByteMode = 0;
+ int opNum = (kCmdFlags[cmd->OpCode] & CF_OPMASK);
+ if (opNum > 0)
+ {
+ DecodeArg(inp, cmd->Op1, cmd->ByteMode);
+ if (opNum == 2)
+ DecodeArg(inp, cmd->Op2, cmd->ByteMode);
+ else
+ {
+ if (cmd->Op1.Type == OP_TYPE_INT && (kCmdFlags[cmd->OpCode] & (CF_JUMP | CF_PROC)))
+ {
+ int Distance = cmd->Op1.Data;
+ if (Distance >= 256)
+ Distance -= 256;
+ else
+ {
+ if (Distance >= 136)
+ Distance -= 264;
+ else if (Distance >= 16)
+ Distance -= 8;
+ else if (Distance >= 8)
+ Distance -= 16;
+ Distance += prg->Commands.Size() - 1;
+ }
+ cmd->Op1.Data = Distance;
+ }
+ }
+ }
+ if (cmd->ByteMode)
+ {
+ switch (cmd->OpCode)
+ {
+ case CMD_MOV: cmd->OpCode = CMD_MOVB; break;
+ case CMD_CMP: cmd->OpCode = CMD_CMPB; break;
+ case CMD_ADD: cmd->OpCode = CMD_ADDB; break;
+ case CMD_SUB: cmd->OpCode = CMD_SUBB; break;
+ case CMD_INC: cmd->OpCode = CMD_INCB; break;
+ case CMD_DEC: cmd->OpCode = CMD_DECB; break;
+ case CMD_XOR: cmd->OpCode = CMD_XORB; break;
+ case CMD_AND: cmd->OpCode = CMD_ANDB; break;
+ case CMD_OR: cmd->OpCode = CMD_ORB; break;
+ case CMD_TEST: cmd->OpCode = CMD_TESTB; break;
+ case CMD_NEG: cmd->OpCode = CMD_NEGB; break;
+ case CMD_SHL: cmd->OpCode = CMD_SHLB; break;
+ case CMD_SHR: cmd->OpCode = CMD_SHRB; break;
+ case CMD_SAR: cmd->OpCode = CMD_SARB; break;
+ case CMD_MUL: cmd->OpCode = CMD_MULB; break;
+ }
+ }
+ }
+}
+
+#ifdef RARVM_STANDARD_FILTERS
+
+enum EStandardFilter
+{
+ SF_E8,
+ SF_E8E9,
+ SF_ITANIUM,
+ SF_RGB,
+ SF_AUDIO,
+ SF_DELTA,
+ SF_UPCASE
+};
+
+struct StandardFilterSignature
+{
+ UInt32 Length;
+ UInt32 CRC;
+ EStandardFilter Type;
+}
+kStdFilters[]=
+{
+ { 53, 0xad576887, SF_E8 },
+ { 57, 0x3cd7e57e, SF_E8E9 },
+ { 120, 0x3769893f, SF_ITANIUM },
+ { 29, 0x0e06077d, SF_DELTA },
+ { 149, 0x1c2c5dc8, SF_RGB },
+ { 216, 0xbc85e701, SF_AUDIO },
+ { 40, 0x46b9c560, SF_UPCASE }
+};
+
+static int FindStandardFilter(const Byte *code, UInt32 codeSize)
+{
+ UInt32 crc = CrcCalc(code, codeSize);
+ for (int i = 0; i < sizeof(kStdFilters) / sizeof(kStdFilters[0]); i++)
+ {
+ StandardFilterSignature &sfs = kStdFilters[i];
+ if (sfs.CRC == crc && sfs.Length == codeSize)
+ return i;
+ }
+ return -1;
+}
+
+#endif
+
+void CVm::PrepareProgram(const Byte *code, UInt32 codeSize, CProgram *prg)
+{
+ Byte xorSum = 0;
+ for (UInt32 i = 1; i < codeSize; i++)
+ xorSum ^= code[i];
+
+ prg->Commands.Clear();
+ #ifdef RARVM_STANDARD_FILTERS
+ prg->StandardFilterIndex = -1;
+ #endif
+
+ if (xorSum == code[0] && codeSize > 0)
+ {
+ #ifdef RARVM_STANDARD_FILTERS
+ prg->StandardFilterIndex = FindStandardFilter(code, codeSize);
+ if (prg->StandardFilterIndex >= 0)
+ return;
+ #endif
+ // 1 byte for checksum
+ ReadVmProgram(code + 1, codeSize - 1, prg);
+ }
+ prg->Commands.Add(CCommand());
+ CCommand *cmd = &prg->Commands.Back();
+ cmd->OpCode = CMD_RET;
+}
+
+void CVm::SetMemory(UInt32 pos, const Byte *data, UInt32 dataSize)
+{
+ if (pos < kSpaceSize && data != Mem + pos)
+ memmove(Mem + pos, data, MyMin(dataSize, kSpaceSize - pos));
+}
+
+#ifdef RARVM_STANDARD_FILTERS
+
+static void E8E9Decode(Byte *data, UInt32 dataSize, UInt32 fileOffset, bool e9)
+{
+ if (dataSize <= 4)
+ return;
+ dataSize -= 4;
+ const UInt32 kFileSize = 0x1000000;
+ Byte cmpByte2 = (e9 ? 0xE9 : 0xE8);
+ for (UInt32 curPos = 0; curPos < dataSize;)
+ {
+ Byte curByte = *(data++);
+ curPos++;
+ if (curByte == 0xE8 || curByte == cmpByte2)
+ {
+ UInt32 offset = curPos + fileOffset;
+ UInt32 addr = (Int32)GetValue32(data);
+ if (addr < kFileSize)
+ SetValue32(data, addr - offset);
+ else if ((Int32)addr < 0 && (Int32)(addr + offset) >= 0)
+ SetValue32(data, addr + kFileSize);
+ data += 4;
+ curPos += 4;
+ }
+ }
+}
+
+static inline UInt32 ItaniumGetOpType(const Byte *data, int bitPos)
+{
+ return (data[(unsigned int)bitPos >> 3] >> (bitPos & 7)) & 0xF;
+}
+
+
+static void ItaniumDecode(Byte *data, UInt32 dataSize, UInt32 fileOffset)
+{
+ UInt32 curPos = 0;
+ fileOffset >>= 4;
+ while (curPos < dataSize - 21)
+ {
+ int b = (data[0] & 0x1F) - 0x10;
+ if (b >= 0)
+ {
+ static Byte kCmdMasks[16] = {4,4,6,6,0,0,7,7,4,4,0,0,4,4,0,0};
+ Byte cmdMask = kCmdMasks[b];
+ if (cmdMask != 0)
+ for (int i = 0; i < 3; i++)
+ if (cmdMask & (1 << i))
+ {
+ int startPos = i * 41 + 18;
+ if (ItaniumGetOpType(data, startPos + 24) == 5)
+ {
+ const UInt32 kMask = 0xFFFFF;
+ Byte *p = data + ((unsigned int)startPos >> 3);
+ UInt32 bitField = ((UInt32)p[0]) | ((UInt32)p[1] << 8) | ((UInt32)p[2] << 16);
+ int inBit = (startPos & 7);
+ UInt32 offset = (bitField >> inBit) & kMask;
+ UInt32 andMask = ~(kMask << inBit);
+ bitField = ((offset - fileOffset) & kMask) << inBit;
+ for (int j = 0; j < 3; j++)
+ {
+ p[j] &= andMask;
+ p[j] |= bitField;
+ andMask >>= 8;
+ bitField >>= 8;
+ }
+ }
+ }
+ }
+ data += 16;
+ curPos += 16;
+ fileOffset++;
+ }
+}
+
+static void DeltaDecode(Byte *data, UInt32 dataSize, UInt32 numChannels)
+{
+ UInt32 srcPos = 0;
+ UInt32 border = dataSize * 2;
+ for (UInt32 curChannel = 0; curChannel < numChannels; curChannel++)
+ {
+ Byte prevByte = 0;
+ for (UInt32 destPos = dataSize + curChannel; destPos < border; destPos += numChannels)
+ data[destPos] = (prevByte = prevByte - data[srcPos++]);
+ }
+}
+
+static void RgbDecode(Byte *srcData, UInt32 dataSize, UInt32 width, UInt32 posR)
+{
+ Byte *destData = srcData + dataSize;
+ const UInt32 numChannels = 3;
+ for (UInt32 curChannel = 0; curChannel < numChannels; curChannel++)
+ {
+ Byte prevByte = 0;
+
+ for (UInt32 i = curChannel; i < dataSize; i+= numChannels)
+ {
+ unsigned int predicted;
+ if (i < width)
+ predicted = prevByte;
+ else
+ {
+ unsigned int upperLeftByte = destData[i - width];
+ unsigned int upperByte = destData[i - width + 3];
+ predicted = prevByte + upperByte - upperLeftByte;
+ int pa = abs((int)(predicted - prevByte));
+ int pb = abs((int)(predicted - upperByte));
+ int pc = abs((int)(predicted - upperLeftByte));
+ if (pa <= pb && pa <= pc)
+ predicted = prevByte;
+ else
+ if (pb <= pc)
+ predicted = upperByte;
+ else
+ predicted = upperLeftByte;
+ }
+ destData[i] = prevByte = (Byte)(predicted - *(srcData++));
+ }
+ }
+ if (dataSize < 3)
+ return;
+ for (UInt32 i = posR, border = dataSize - 2; i < border; i += 3)
+ {
+ Byte g = destData[i + 1];
+ destData[i] = destData[i] + g;
+ destData[i + 2] = destData[i + 2] + g;
+ }
+}
+
+static void AudioDecode(Byte *srcData, UInt32 dataSize, UInt32 numChannels)
+{
+ Byte *destData = srcData + dataSize;
+ for (UInt32 curChannel = 0; curChannel < numChannels; curChannel++)
+ {
+ UInt32 prevByte = 0, prevDelta = 0, dif[7];
+ Int32 D1 = 0, D2 = 0, D3;
+ Int32 K1 = 0, K2 = 0, K3 = 0;
+ memset(dif, 0, sizeof(dif));
+
+ for (UInt32 i = curChannel, byteCount = 0; i < dataSize; i += numChannels, byteCount++)
+ {
+ D3 = D2;
+ D2 = prevDelta - D1;
+ D1 = prevDelta;
+
+ UInt32 predicted = 8 * prevByte + K1 * D1 + K2 * D2 + K3 * D3;
+ predicted = (predicted >> 3) & 0xFF;
+
+ UInt32 curByte = *(srcData++);
+
+ predicted -= curByte;
+ destData[i] = (Byte)predicted;
+ prevDelta = (UInt32)(Int32)(signed char)(predicted - prevByte);
+ prevByte = predicted;
+
+ Int32 D = ((Int32)(signed char)curByte) << 3;
+
+ dif[0] += abs(D);
+ dif[1] += abs(D - D1);
+ dif[2] += abs(D + D1);
+ dif[3] += abs(D - D2);
+ dif[4] += abs(D + D2);
+ dif[5] += abs(D - D3);
+ dif[6] += abs(D + D3);
+
+ if ((byteCount & 0x1F) == 0)
+ {
+ UInt32 minDif = dif[0], numMinDif = 0;
+ dif[0] = 0;
+ for (int j = 1; j < sizeof(dif) / sizeof(dif[0]); j++)
+ {
+ if (dif[j] < minDif)
+ {
+ minDif = dif[j];
+ numMinDif = j;
+ }
+ dif[j] = 0;
+ }
+ switch (numMinDif)
+ {
+ case 1: if (K1 >= -16) K1--; break;
+ case 2: if (K1 < 16) K1++; break;
+ case 3: if (K2 >= -16) K2--; break;
+ case 4: if (K2 < 16) K2++; break;
+ case 5: if (K3 >= -16) K3--; break;
+ case 6: if (K3 < 16) K3++; break;
+ }
+ }
+ }
+ }
+}
+
+static UInt32 UpCaseDecode(Byte *data, UInt32 dataSize)
+{
+ UInt32 srcPos = 0, destPos = dataSize;
+ while (srcPos < dataSize)
+ {
+ Byte curByte = data[srcPos++];
+ if (curByte == 2 && (curByte = data[srcPos++]) != 2)
+ curByte -= 32;
+ data[destPos++] = curByte;
+ }
+ return destPos - dataSize;
+}
+
+void CVm::ExecuteStandardFilter(int filterIndex)
+{
+ UInt32 dataSize = R[4];
+ if (dataSize >= kGlobalOffset)
+ return;
+ EStandardFilter filterType = kStdFilters[filterIndex].Type;
+
+ switch (filterType)
+ {
+ case SF_E8:
+ case SF_E8E9:
+ E8E9Decode(Mem, dataSize, R[6], (filterType == SF_E8E9));
+ break;
+ case SF_ITANIUM:
+ ItaniumDecode(Mem, dataSize, R[6]);
+ break;
+ case SF_DELTA:
+ if (dataSize >= kGlobalOffset / 2)
+ break;
+ SetBlockPos(dataSize);
+ DeltaDecode(Mem, dataSize, R[0]);
+ break;
+ case SF_RGB:
+ if (dataSize >= kGlobalOffset / 2)
+ break;
+ {
+ UInt32 width = R[0];
+ if (width <= 3)
+ break;
+ SetBlockPos(dataSize);
+ RgbDecode(Mem, dataSize, width, R[1]);
+ }
+ break;
+ case SF_AUDIO:
+ if (dataSize >= kGlobalOffset / 2)
+ break;
+ SetBlockPos(dataSize);
+ AudioDecode(Mem, dataSize, R[0]);
+ break;
+ case SF_UPCASE:
+ if (dataSize >= kGlobalOffset / 2)
+ break;
+ UInt32 destSize = UpCaseDecode(Mem, dataSize);
+ SetBlockSize(destSize);
+ SetBlockPos(dataSize);
+ break;
+ }
+}
+
+#endif
+
+}}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Vm.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Vm.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Vm.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/Rar3Vm.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,179 @@
+// Rar3Vm.h
+// According to unRAR license, this code may not be used to develop
+// a program that creates RAR archives
+
+#ifndef __COMPRESS_RAR3_VM_H
+#define __COMPRESS_RAR3_VM_H
+
+#include "../../../C/CpuArch.h"
+
+#include "Common/MyVector.h"
+#include "Common/Types.h"
+
+#define RARVM_STANDARD_FILTERS
+
+namespace NCompress {
+namespace NRar3 {
+
+class CMemBitDecoder
+{
+ const Byte *_data;
+ UInt32 _bitSize;
+ UInt32 _bitPos;
+public:
+ void Init(const Byte *data, UInt32 byteSize)
+ {
+ _data = data;
+ _bitSize = (byteSize << 3);
+ _bitPos = 0;
+ }
+ UInt32 ReadBits(int numBits);
+ UInt32 ReadBit();
+ bool Avail() const { return (_bitPos < _bitSize); }
+};
+
+namespace NVm {
+
+inline UInt32 GetValue32(const void *addr) { return GetUi32(addr); }
+inline void SetValue32(void *addr, UInt32 value) { SetUi32(addr, value); }
+
+UInt32 ReadEncodedUInt32(CMemBitDecoder &inp);
+
+const int kNumRegBits = 3;
+const UInt32 kNumRegs = 1 << kNumRegBits;
+const UInt32 kNumGpRegs = kNumRegs - 1;
+
+const UInt32 kSpaceSize = 0x40000;
+const UInt32 kSpaceMask = kSpaceSize -1;
+const UInt32 kGlobalOffset = 0x3C000;
+const UInt32 kGlobalSize = 0x2000;
+const UInt32 kFixedGlobalSize = 64;
+
+namespace NGlobalOffset
+{
+ const UInt32 kBlockSize = 0x1C;
+ const UInt32 kBlockPos = 0x20;
+ const UInt32 kExecCount = 0x2C;
+ const UInt32 kGlobalMemOutSize = 0x30;
+}
+
+enum ECommand
+{
+ CMD_MOV, CMD_CMP, CMD_ADD, CMD_SUB, CMD_JZ, CMD_JNZ, CMD_INC, CMD_DEC,
+ CMD_JMP, CMD_XOR, CMD_AND, CMD_OR, CMD_TEST, CMD_JS, CMD_JNS, CMD_JB,
+ CMD_JBE, CMD_JA, CMD_JAE, CMD_PUSH, CMD_POP, CMD_CALL, CMD_RET, CMD_NOT,
+ CMD_SHL, CMD_SHR, CMD_SAR, CMD_NEG, CMD_PUSHA,CMD_POPA, CMD_PUSHF,CMD_POPF,
+ CMD_MOVZX,CMD_MOVSX,CMD_XCHG, CMD_MUL, CMD_DIV, CMD_ADC, CMD_SBB, CMD_PRINT,
+
+ CMD_MOVB, CMD_CMPB, CMD_ADDB, CMD_SUBB, CMD_INCB, CMD_DECB,
+ CMD_XORB, CMD_ANDB, CMD_ORB, CMD_TESTB,CMD_NEGB,
+ CMD_SHLB, CMD_SHRB, CMD_SARB, CMD_MULB
+};
+
+enum EOpType {OP_TYPE_REG, OP_TYPE_INT, OP_TYPE_REGMEM, OP_TYPE_NONE};
+
+// Addr in COperand object can link (point) to CVm object!!!
+
+struct COperand
+{
+ EOpType Type;
+ UInt32 Data;
+ UInt32 Base;
+ COperand(): Type(OP_TYPE_NONE), Data(0), Base(0) {}
+};
+
+struct CCommand
+{
+ ECommand OpCode;
+ bool ByteMode;
+ COperand Op1, Op2;
+};
+
+struct CBlockRef
+{
+ UInt32 Offset;
+ UInt32 Size;
+};
+
+struct CProgram
+{
+ CRecordVector<CCommand> Commands;
+ #ifdef RARVM_STANDARD_FILTERS
+ int StandardFilterIndex;
+ #endif
+ CRecordVector<Byte> StaticData;
+};
+
+struct CProgramInitState
+{
+ UInt32 InitR[kNumGpRegs];
+ CRecordVector<Byte> GlobalData;
+
+ void AllocateEmptyFixedGlobal()
+ {
+ GlobalData.Clear();
+ GlobalData.Reserve(NVm::kFixedGlobalSize);
+ for (UInt32 i = 0; i < NVm::kFixedGlobalSize; i++)
+ GlobalData.Add(0);
+ }
+};
+
+class CVm
+{
+ static UInt32 GetValue(bool byteMode, const void *addr)
+ {
+ if (byteMode)
+ return(*(const Byte *)addr);
+ else
+ return GetUi32(addr);
+ }
+
+ static void SetValue(bool byteMode, void *addr, UInt32 value)
+ {
+ if (byteMode)
+ *(Byte *)addr = (Byte)value;
+ else
+ SetUi32(addr, value);
+ }
+
+ UInt32 GetFixedGlobalValue32(UInt32 globalOffset) { return GetValue(false, &Mem[kGlobalOffset + globalOffset]); }
+
+ void SetBlockSize(UInt32 v) { SetValue(&Mem[kGlobalOffset + NGlobalOffset::kBlockSize], v); }
+ void SetBlockPos(UInt32 v) { SetValue(&Mem[kGlobalOffset + NGlobalOffset::kBlockPos], v); }
+public:
+ static void SetValue(void *addr, UInt32 value) { SetValue(false, addr, value); }
+private:
+ UInt32 GetOperand32(const COperand *op) const;
+ void SetOperand32(const COperand *op, UInt32 val);
+ Byte GetOperand8(const COperand *op) const;
+ void SetOperand8(const COperand *op, Byte val);
+ UInt32 GetOperand(bool byteMode, const COperand *op) const;
+ void SetOperand(bool byteMode, const COperand *op, UInt32 val);
+
+ void DecodeArg(CMemBitDecoder &inp, COperand &op, bool byteMode);
+
+ bool ExecuteCode(const CProgram *prg);
+
+ #ifdef RARVM_STANDARD_FILTERS
+ void ExecuteStandardFilter(int filterIndex);
+ #endif
+
+ Byte *Mem;
+ UInt32 R[kNumRegs + 1]; // R[kNumRegs] = 0 always (speed optimization)
+ UInt32 Flags;
+ void ReadVmProgram(const Byte *code, UInt32 codeSize, CProgram *prg);
+public:
+ CVm();
+ ~CVm();
+ bool Create();
+ void PrepareProgram(const Byte *code, UInt32 codeSize, CProgram *prg);
+ void SetMemory(UInt32 pos, const Byte *data, UInt32 dataSize);
+ bool Execute(CProgram *prg, const CProgramInitState *initState,
+ CBlockRef &outBlockRef, CRecordVector<Byte> &outGlobalData);
+ const Byte *GetDataPointer(UInt32 offset) const { return Mem + offset; }
+
+};
+
+#endif
+
+}}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/RarCodecsRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/RarCodecsRegister.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/RarCodecsRegister.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/RarCodecsRegister.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,26 @@
+// RarCodecsRegister.cpp
+
+#include "StdAfx.h"
+
+#include "../Common/RegisterCodec.h"
+
+#include "Rar1Decoder.h"
+#include "Rar2Decoder.h"
+#include "Rar3Decoder.h"
+
+#define CREATE_CODEC(x) static void *CreateCodec ## x() { return (void *)(ICompressCoder *)(new NCompress::NRar ## x::CDecoder); }
+
+CREATE_CODEC(1)
+CREATE_CODEC(2)
+CREATE_CODEC(3)
+
+#define RAR_CODEC(x, name) { CreateCodec ## x, 0, 0x040300 + x, L"Rar" name, 1, false }
+
+static CCodecInfo g_CodecsInfo[] =
+{
+ RAR_CODEC(1, L"1"),
+ RAR_CODEC(2, L"2"),
+ RAR_CODEC(3, L"3"),
+};
+
+REGISTER_CODECS(Rar)
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ShrinkDecoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ShrinkDecoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ShrinkDecoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ShrinkDecoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,145 @@
+// ShrinkDecoder.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/Alloc.h"
+
+#include "../Common/InBuffer.h"
+#include "../Common/OutBuffer.h"
+
+#include "BitlDecoder.h"
+#include "ShrinkDecoder.h"
+
+namespace NCompress {
+namespace NShrink {
+
+static const UInt32 kBufferSize = (1 << 20);
+static const int kNumMinBits = 9;
+
+HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)
+{
+ NBitl::CBaseDecoder<CInBuffer> inBuffer;
+ COutBuffer outBuffer;
+
+ if (!inBuffer.Create(kBufferSize))
+ return E_OUTOFMEMORY;
+ inBuffer.SetStream(inStream);
+ inBuffer.Init();
+
+ if (!outBuffer.Create(kBufferSize))
+ return E_OUTOFMEMORY;
+ outBuffer.SetStream(outStream);
+ outBuffer.Init();
+
+ UInt64 prevPos = 0;
+ int numBits = kNumMinBits;
+ UInt32 head = 257;
+ bool needPrev = false;
+ UInt32 lastSymbol = 0;
+
+ int i;
+ for (i = 0; i < kNumItems; i++)
+ _parents[i] = 0;
+ for (i = 0; i < kNumItems; i++)
+ _suffixes[i] = 0;
+ for (i = 0; i < 257; i++)
+ _isFree[i] = false;
+ for (; i < kNumItems; i++)
+ _isFree[i] = true;
+
+ for (;;)
+ {
+ UInt32 symbol = inBuffer.ReadBits(numBits);
+ if (inBuffer.ExtraBitsWereRead())
+ break;
+ if (_isFree[symbol])
+ return S_FALSE;
+ if (symbol == 256)
+ {
+ UInt32 symbol = inBuffer.ReadBits(numBits);
+ if (symbol == 1)
+ {
+ if (numBits < kNumMaxBits)
+ numBits++;
+ }
+ else if (symbol == 2)
+ {
+ if (needPrev)
+ _isFree[head - 1] = true;
+ for (i = 257; i < kNumItems; i++)
+ _isParent[i] = false;
+ for (i = 257; i < kNumItems; i++)
+ if (!_isFree[i])
+ _isParent[_parents[i]] = true;
+ for (i = 257; i < kNumItems; i++)
+ if (!_isParent[i])
+ _isFree[i] = true;
+ head = 257;
+ while (head < kNumItems && !_isFree[head])
+ head++;
+ if (head < kNumItems)
+ {
+ needPrev = true;
+ _isFree[head] = false;
+ _parents[head] = (UInt16)lastSymbol;
+ head++;
+ }
+ }
+ else
+ return S_FALSE;
+ continue;
+ }
+ UInt32 cur = symbol;
+ i = 0;
+ int corectionIndex = -1;
+ while (cur >= 256)
+ {
+ if (cur == head - 1)
+ corectionIndex = i;
+ _stack[i++] = _suffixes[cur];
+ cur = _parents[cur];
+ }
+ _stack[i++] = (Byte)cur;
+ if (needPrev)
+ {
+ _suffixes[head - 1] = (Byte)cur;
+ if (corectionIndex >= 0)
+ _stack[corectionIndex] = (Byte)cur;
+ }
+ while (i > 0)
+ outBuffer.WriteByte((_stack[--i]));
+ while (head < kNumItems && !_isFree[head])
+ head++;
+ if (head < kNumItems)
+ {
+ needPrev = true;
+ _isFree[head] = false;
+ _parents[head] = (UInt16)symbol;
+ head++;
+ }
+ else
+ needPrev = false;
+ lastSymbol = symbol;
+
+ UInt64 nowPos = outBuffer.GetProcessedSize();
+ if (progress != NULL && nowPos - prevPos > (1 << 18))
+ {
+ prevPos = nowPos;
+ UInt64 packSize = inBuffer.GetProcessedSize();
+ RINOK(progress->SetRatioInfo(&packSize, &nowPos));
+ }
+ }
+ return outBuffer.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 CInBufferException &e) { return e.ErrorCode; }
+ catch(const COutBufferException &e) { return e.ErrorCode; }
+ catch(...) { return S_FALSE; }
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ShrinkDecoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ShrinkDecoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ShrinkDecoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ShrinkDecoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,38 @@
+// ShrinkDecoder.h
+
+#ifndef __COMPRESS_SHRINK_DECODER_H
+#define __COMPRESS_SHRINK_DECODER_H
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+namespace NCompress {
+namespace NShrink {
+
+const int kNumMaxBits = 13;
+const UInt32 kNumItems = 1 << kNumMaxBits;
+
+class CDecoder :
+ public ICompressCoder,
+ public CMyUnknownImp
+{
+ UInt16 _parents[kNumItems];
+ Byte _suffixes[kNumItems];
+ Byte _stack[kNumItems];
+ bool _isFree[kNumItems];
+ bool _isParent[kNumItems];
+
+public:
+ MY_UNKNOWN_IMP
+
+ HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZDecoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZDecoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZDecoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZDecoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,159 @@
+// ZDecoder.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/Alloc.h"
+
+#include "../Common/InBuffer.h"
+#include "../Common/OutBuffer.h"
+
+#include "ZDecoder.h"
+
+namespace NCompress {
+namespace NZ {
+
+static const UInt32 kBufferSize = (1 << 20);
+static const Byte kNumBitsMask = 0x1F;
+static const Byte kBlockModeMask = 0x80;
+static const int kNumMinBits = 9;
+static const int kNumMaxBits = 16;
+
+void CDecoder::Free()
+{
+ MyFree(_parents); _parents = 0;
+ MyFree(_suffixes); _suffixes = 0;
+ MyFree(_stack); _stack = 0;
+}
+
+CDecoder::~CDecoder() { Free(); }
+
+HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 * /* inSize */, const UInt64 * /* outSize */, ICompressProgressInfo *progress)
+{
+ CInBuffer inBuffer;
+ COutBuffer outBuffer;
+
+ if (!inBuffer.Create(kBufferSize))
+ return E_OUTOFMEMORY;
+ inBuffer.SetStream(inStream);
+ inBuffer.Init();
+
+ if (!outBuffer.Create(kBufferSize))
+ return E_OUTOFMEMORY;
+ outBuffer.SetStream(outStream);
+ outBuffer.Init();
+
+ int maxbits = _properties & kNumBitsMask;
+ if (maxbits < kNumMinBits || maxbits > kNumMaxBits)
+ return S_FALSE;
+ UInt32 numItems = 1 << maxbits;
+ bool blockMode = ((_properties & kBlockModeMask) != 0);
+
+ if (maxbits != _numMaxBits || _parents == 0 || _suffixes == 0 || _stack == 0)
+ {
+ Free();
+ _parents = (UInt16 *)MyAlloc(numItems * sizeof(UInt16)); if (_parents == 0) return E_OUTOFMEMORY;
+ _suffixes = (Byte *)MyAlloc(numItems * sizeof(Byte)); if (_suffixes == 0) return E_OUTOFMEMORY;
+ _stack = (Byte *)MyAlloc(numItems * sizeof(Byte)); if (_stack == 0) return E_OUTOFMEMORY;
+ _numMaxBits = maxbits;
+ }
+
+ UInt64 prevPos = 0;
+ int numBits = kNumMinBits;
+ UInt32 head = blockMode ? 257 : 256;
+
+ bool needPrev = false;
+
+ unsigned bitPos = 0;
+ unsigned numBufBits = 0;
+
+ Byte buf[kNumMaxBits + 4];
+
+ _parents[256] = 0; // virus protection
+ _suffixes[256] = 0;
+
+ for (;;)
+ {
+ if (numBufBits == bitPos)
+ {
+ numBufBits = (unsigned)inBuffer.ReadBytes(buf, numBits) * 8;
+ bitPos = 0;
+ UInt64 nowPos = outBuffer.GetProcessedSize();
+ if (progress != NULL && nowPos - prevPos >= (1 << 18))
+ {
+ prevPos = nowPos;
+ UInt64 packSize = inBuffer.GetProcessedSize();
+ RINOK(progress->SetRatioInfo(&packSize, &nowPos));
+ }
+ }
+ unsigned bytePos = bitPos >> 3;
+ UInt32 symbol = buf[bytePos] | ((UInt32)buf[bytePos + 1] << 8) | ((UInt32)buf[bytePos + 2] << 16);
+ symbol >>= (bitPos & 7);
+ symbol &= (1 << numBits) - 1;
+ bitPos += numBits;
+ if (bitPos > numBufBits)
+ break;
+ if (symbol >= head)
+ return S_FALSE;
+ if (blockMode && symbol == 256)
+ {
+ numBufBits = bitPos = 0;
+ numBits = kNumMinBits;
+ head = 257;
+ needPrev = false;
+ continue;
+ }
+ UInt32 cur = symbol;
+ int i = 0;
+ while (cur >= 256)
+ {
+ _stack[i++] = _suffixes[cur];
+ cur = _parents[cur];
+ }
+ _stack[i++] = (Byte)cur;
+ if (needPrev)
+ {
+ _suffixes[head - 1] = (Byte)cur;
+ if (symbol == head - 1)
+ _stack[0] = (Byte)cur;
+ }
+ do
+ outBuffer.WriteByte((_stack[--i]));
+ while (i > 0);
+ if (head < numItems)
+ {
+ needPrev = true;
+ _parents[head++] = (UInt16)symbol;
+ if (head > ((UInt32)1 << numBits))
+ {
+ if (numBits < maxbits)
+ {
+ numBufBits = bitPos = 0;
+ numBits++;
+ }
+ }
+ }
+ else
+ needPrev = false;
+ }
+ return outBuffer.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 CInBufferException &e) { return e.ErrorCode; }
+ catch(const COutBufferException &e) { return e.ErrorCode; }
+ catch(...) { return S_FALSE; }
+}
+
+STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
+{
+ if (size < 1)
+ return E_INVALIDARG;
+ _properties = data[0];
+ return S_OK;
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZDecoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZDecoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZDecoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZDecoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,42 @@
+// ZDecoder.h
+
+#ifndef __COMPRESS_Z_DECODER_H
+#define __COMPRESS_Z_DECODER_H
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+namespace NCompress {
+namespace NZ {
+
+class CDecoder:
+ public ICompressCoder,
+ public ICompressSetDecoderProperties2,
+ public CMyUnknownImp
+{
+ UInt16 *_parents;
+ Byte *_suffixes;
+ Byte *_stack;
+ Byte _properties;
+ int _numMaxBits;
+
+public:
+ CDecoder(): _parents(0), _suffixes(0), _stack(0), _properties(0), _numMaxBits(0) {};
+ ~CDecoder();
+ void Free();
+
+ MY_UNKNOWN_IMP1(ICompressSetDecoderProperties2)
+
+ HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibDecoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibDecoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibDecoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibDecoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,89 @@
+// ZlibDecoder.cpp
+
+#include "StdAfx.h"
+
+#include "../Common/StreamUtils.h"
+
+#include "ZlibDecoder.h"
+
+namespace NCompress {
+namespace NZlib {
+
+#define DEFLATE_TRY_BEGIN try {
+#define DEFLATE_TRY_END } catch(...) { return S_FALSE; }
+
+#define ADLER_MOD 65521
+#define ADLER_LOOP_MAX 5550
+
+UInt32 Adler32_Update(UInt32 adler, const Byte *buf, size_t size)
+{
+ UInt32 a = adler & 0xFFFF;
+ UInt32 b = (adler >> 16) & 0xFFFF;
+ while (size > 0)
+ {
+ unsigned curSize = (size > ADLER_LOOP_MAX) ? ADLER_LOOP_MAX : (unsigned )size;
+ unsigned i;
+ for (i = 0; i < curSize; i++)
+ {
+ a += buf[i];
+ b += a;
+ }
+ buf += curSize;
+ size -= curSize;
+ a %= ADLER_MOD;
+ b %= ADLER_MOD;
+ }
+ return (b << 16) + a;
+}
+
+STDMETHODIMP COutStreamWithAdler::Write(const void *data, UInt32 size, UInt32 *processedSize)
+{
+ HRESULT result = _stream->Write(data, size, &size);
+ _adler = Adler32_Update(_adler, (const Byte *)data, size);
+ if (processedSize != NULL)
+ *processedSize = size;
+ return result;
+}
+
+STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
+{
+ DEFLATE_TRY_BEGIN
+ if (!AdlerStream)
+ AdlerStream = AdlerSpec = new COutStreamWithAdler;
+ if (!DeflateDecoder)
+ {
+ DeflateDecoderSpec = new NDeflate::NDecoder::CCOMCoder;
+ DeflateDecoderSpec->ZlibMode = true;
+ DeflateDecoder = DeflateDecoderSpec;
+ }
+
+ Byte buf[2];
+ RINOK(ReadStream_FALSE(inStream, buf, 2));
+ int method = buf[0] & 0xF;
+ if (method != 8)
+ return S_FALSE;
+ // int dicSize = buf[0] >> 4;
+ if ((((UInt32)buf[0] << 8) + buf[1]) % 31 != 0)
+ return S_FALSE;
+ if ((buf[1] & 0x20) != 0) // dictPresent
+ return S_FALSE;
+ // int level = (buf[1] >> 6);
+
+ AdlerSpec->SetStream(outStream);
+ AdlerSpec->Init();
+ HRESULT res = DeflateDecoder->Code(inStream, AdlerStream, inSize, outSize, progress);
+ AdlerSpec->ReleaseStream();
+
+ if (res == S_OK)
+ {
+ const Byte *p = DeflateDecoderSpec->ZlibFooter;
+ UInt32 adler = ((UInt32)p[0] << 24) | ((UInt32)p[1] << 16) | ((UInt32)p[2] << 8) | p[3];
+ if (adler != AdlerSpec->GetAdler())
+ return S_FALSE;
+ }
+ return res;
+ DEFLATE_TRY_END
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibDecoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibDecoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibDecoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibDecoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,48 @@
+// ZlibDecoder.h
+
+#ifndef __ZLIB_DECODER_H
+#define __ZLIB_DECODER_H
+
+#include "DeflateDecoder.h"
+
+namespace NCompress {
+namespace NZlib {
+
+const UInt32 ADLER_INIT_VAL = 1;
+
+class COutStreamWithAdler:
+ public ISequentialOutStream,
+ public CMyUnknownImp
+{
+ CMyComPtr<ISequentialOutStream> _stream;
+ UInt32 _adler;
+public:
+ MY_UNKNOWN_IMP
+ STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
+ void SetStream(ISequentialOutStream *stream) { _stream = stream; }
+ void ReleaseStream() { _stream.Release(); }
+ void Init() { _adler = ADLER_INIT_VAL; }
+ UInt32 GetAdler() const { return _adler; }
+};
+
+class CDecoder:
+ public ICompressCoder,
+ public CMyUnknownImp
+{
+ COutStreamWithAdler *AdlerSpec;
+ CMyComPtr<ISequentialOutStream> AdlerStream;
+
+ NCompress::NDeflate::NDecoder::CCOMCoder *DeflateDecoderSpec;
+ CMyComPtr<ICompressCoder> DeflateDecoder;
+public:
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+
+ UInt64 GetInputProcessedSize() const { return DeflateDecoderSpec->GetInputProcessedSize() + 2; }
+
+ MY_UNKNOWN_IMP
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibEncoder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibEncoder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibEncoder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibEncoder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,61 @@
+// ZlibEncoder.cpp
+
+#include "StdAfx.h"
+
+#include "../Common/StreamUtils.h"
+
+#include "ZlibEncoder.h"
+
+namespace NCompress {
+namespace NZlib {
+
+#define DEFLATE_TRY_BEGIN try {
+#define DEFLATE_TRY_END } catch(...) { return S_FALSE; }
+
+UInt32 Adler32_Update(UInt32 adler, const Byte *buf, size_t size);
+
+STDMETHODIMP CInStreamWithAdler::Read(void *data, UInt32 size, UInt32 *processedSize)
+{
+ HRESULT result = _stream->Read(data, size, &size);
+ _adler = Adler32_Update(_adler, (const Byte *)data, size);
+ _size += size;
+ if (processedSize != NULL)
+ *processedSize = size;
+ return result;
+}
+
+void CEncoder::Create()
+{
+ if (!DeflateEncoder)
+ DeflateEncoder = DeflateEncoderSpec = new NDeflate::NEncoder::CCOMCoder;
+}
+
+STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 * /* outSize */, ICompressProgressInfo *progress)
+{
+ DEFLATE_TRY_BEGIN
+ if (!AdlerStream)
+ AdlerStream = AdlerSpec = new CInStreamWithAdler;
+ Create();
+
+ {
+ Byte buf[2] = { 0x78, 0xDA };
+ RINOK(WriteStream(outStream, buf, 2));
+ }
+
+ AdlerSpec->SetStream(inStream);
+ AdlerSpec->Init();
+ HRESULT res = DeflateEncoder->Code(AdlerStream, outStream, inSize, NULL, progress);
+ AdlerSpec->ReleaseStream();
+
+ RINOK(res);
+
+ {
+ UInt32 a = AdlerSpec->GetAdler();
+ Byte buf[4] = { (Byte)(a >> 24), (Byte)(a >> 16), (Byte)(a >> 8), (Byte)(a) };
+ return WriteStream(outStream, buf, 4);
+ }
+ DEFLATE_TRY_END
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibEncoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibEncoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibEncoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Compress/ZlibEncoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,48 @@
+// ZlibEncoder.h
+
+#ifndef __ZLIB_ENCODER_H
+#define __ZLIB_ENCODER_H
+
+#include "DeflateEncoder.h"
+
+namespace NCompress {
+namespace NZlib {
+
+class CInStreamWithAdler:
+ public ISequentialInStream,
+ public CMyUnknownImp
+{
+ CMyComPtr<ISequentialInStream> _stream;
+ UInt32 _adler;
+ UInt64 _size;
+public:
+ MY_UNKNOWN_IMP
+ STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
+ void SetStream(ISequentialInStream *stream) { _stream = stream; }
+ void ReleaseStream() { _stream.Release(); }
+ void Init() { _adler = 1; _size = 0; } // ADLER_INIT_VAL
+ UInt32 GetAdler() const { return _adler; }
+ UInt64 GetSize() const { return _size; }
+};
+
+class CEncoder:
+ public ICompressCoder,
+ public CMyUnknownImp
+{
+ CInStreamWithAdler *AdlerSpec;
+ CMyComPtr<ISequentialInStream> AdlerStream;
+ CMyComPtr<ICompressCoder> DeflateEncoder;
+public:
+ NCompress::NDeflate::NEncoder::CCOMCoder *DeflateEncoderSpec;
+
+ void Create();
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
+ UInt64 GetInputProcessedSize() const { return AdlerSpec->GetSize(); }
+
+ MY_UNKNOWN_IMP
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/7zAes.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/7zAes.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/7zAes.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/7zAes.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,244 @@
+// 7zAes.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/Sha256.h"
+
+#include "Windows/Synchronization.h"
+
+#include "../Common/StreamObjects.h"
+#include "../Common/StreamUtils.h"
+
+#include "7zAes.h"
+#include "MyAes.h"
+
+#ifndef EXTRACT_ONLY
+#include "RandGen.h"
+#endif
+
+using namespace NWindows;
+
+namespace NCrypto {
+namespace NSevenZ {
+
+bool CKeyInfo::IsEqualTo(const CKeyInfo &a) const
+{
+ if (SaltSize != a.SaltSize || NumCyclesPower != a.NumCyclesPower)
+ return false;
+ for (UInt32 i = 0; i < SaltSize; i++)
+ if (Salt[i] != a.Salt[i])
+ return false;
+ return (Password == a.Password);
+}
+
+void CKeyInfo::CalculateDigest()
+{
+ if (NumCyclesPower == 0x3F)
+ {
+ UInt32 pos;
+ for (pos = 0; pos < SaltSize; pos++)
+ Key[pos] = Salt[pos];
+ for (UInt32 i = 0; i < Password.GetCapacity() && pos < kKeySize; i++)
+ Key[pos++] = Password[i];
+ for (; pos < kKeySize; pos++)
+ Key[pos] = 0;
+ }
+ else
+ {
+ CSha256 sha;
+ Sha256_Init(&sha);
+ const UInt64 numRounds = (UInt64)1 << NumCyclesPower;
+ Byte temp[8] = { 0,0,0,0,0,0,0,0 };
+ for (UInt64 round = 0; round < numRounds; round++)
+ {
+ Sha256_Update(&sha, Salt, (size_t)SaltSize);
+ Sha256_Update(&sha, Password, Password.GetCapacity());
+ Sha256_Update(&sha, temp, 8);
+ for (int i = 0; i < 8; i++)
+ if (++(temp[i]) != 0)
+ break;
+ }
+ Sha256_Final(&sha, Key);
+ }
+}
+
+bool CKeyInfoCache::Find(CKeyInfo &key)
+{
+ for (int i = 0; i < Keys.Size(); i++)
+ {
+ const CKeyInfo &cached = Keys[i];
+ if (key.IsEqualTo(cached))
+ {
+ for (int j = 0; j < kKeySize; j++)
+ key.Key[j] = cached.Key[j];
+ if (i != 0)
+ {
+ Keys.Insert(0, cached);
+ Keys.Delete(i+1);
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
+void CKeyInfoCache::Add(CKeyInfo &key)
+{
+ if (Find(key))
+ return;
+ if (Keys.Size() >= Size)
+ Keys.DeleteBack();
+ Keys.Insert(0, key);
+}
+
+static CKeyInfoCache g_GlobalKeyCache(32);
+static NSynchronization::CCriticalSection g_GlobalKeyCacheCriticalSection;
+
+CBase::CBase():
+ _cachedKeys(16),
+ _ivSize(0)
+{
+ for (int i = 0; i < sizeof(_iv); i++)
+ _iv[i] = 0;
+}
+
+void CBase::CalculateDigest()
+{
+ NSynchronization::CCriticalSectionLock lock(g_GlobalKeyCacheCriticalSection);
+ if (_cachedKeys.Find(_key))
+ g_GlobalKeyCache.Add(_key);
+ else
+ {
+ if (!g_GlobalKeyCache.Find(_key))
+ {
+ _key.CalculateDigest();
+ g_GlobalKeyCache.Add(_key);
+ }
+ _cachedKeys.Add(_key);
+ }
+}
+
+#ifndef EXTRACT_ONLY
+
+/*
+STDMETHODIMP CEncoder::ResetSalt()
+{
+ _key.SaltSize = 4;
+ g_RandomGenerator.Generate(_key.Salt, _key.SaltSize);
+ return S_OK;
+}
+*/
+
+STDMETHODIMP CEncoder::ResetInitVector()
+{
+ _ivSize = 8;
+ g_RandomGenerator.Generate(_iv, (unsigned)_ivSize);
+ return S_OK;
+}
+
+STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
+{
+ // _key.Init();
+ for (UInt32 i = _ivSize; i < sizeof(_iv); i++)
+ _iv[i] = 0;
+
+ UInt32 ivSize = _ivSize;
+
+ // _key.NumCyclesPower = 0x3F;
+ _key.NumCyclesPower = 19;
+
+ Byte firstByte = (Byte)(_key.NumCyclesPower |
+ (((_key.SaltSize == 0) ? 0 : 1) << 7) |
+ (((ivSize == 0) ? 0 : 1) << 6));
+ RINOK(outStream->Write(&firstByte, 1, NULL));
+ if (_key.SaltSize == 0 && ivSize == 0)
+ return S_OK;
+ Byte saltSizeSpec = (Byte)((_key.SaltSize == 0) ? 0 : (_key.SaltSize - 1));
+ Byte ivSizeSpec = (Byte)((ivSize == 0) ? 0 : (ivSize - 1));
+ Byte secondByte = (Byte)(((saltSizeSpec) << 4) | ivSizeSpec);
+ RINOK(outStream->Write(&secondByte, 1, NULL));
+ if (_key.SaltSize > 0)
+ {
+ RINOK(WriteStream(outStream, _key.Salt, _key.SaltSize));
+ }
+ if (ivSize > 0)
+ {
+ RINOK(WriteStream(outStream, _iv, ivSize));
+ }
+ return S_OK;
+}
+
+HRESULT CEncoder::CreateFilter()
+{
+ _aesFilter = new CAesCbcEncoder;
+ return S_OK;
+}
+
+#endif
+
+STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
+{
+ _key.Init();
+ UInt32 i;
+ for (i = 0; i < sizeof(_iv); i++)
+ _iv[i] = 0;
+ if (size == 0)
+ return S_OK;
+ UInt32 pos = 0;
+ Byte firstByte = data[pos++];
+
+ _key.NumCyclesPower = firstByte & 0x3F;
+ if ((firstByte & 0xC0) == 0)
+ return S_OK;
+ _key.SaltSize = (firstByte >> 7) & 1;
+ UInt32 ivSize = (firstByte >> 6) & 1;
+
+ if (pos >= size)
+ return E_INVALIDARG;
+ Byte secondByte = data[pos++];
+
+ _key.SaltSize += (secondByte >> 4);
+ ivSize += (secondByte & 0x0F);
+
+ if (pos + _key.SaltSize + ivSize > size)
+ return E_INVALIDARG;
+ for (i = 0; i < _key.SaltSize; i++)
+ _key.Salt[i] = data[pos++];
+ for (i = 0; i < ivSize; i++)
+ _iv[i] = data[pos++];
+ return (_key.NumCyclesPower <= 24) ? S_OK : E_NOTIMPL;
+}
+
+STDMETHODIMP CBaseCoder::CryptoSetPassword(const Byte *data, UInt32 size)
+{
+ _key.Password.SetCapacity((size_t)size);
+ memcpy(_key.Password, data, (size_t)size);
+ return S_OK;
+}
+
+STDMETHODIMP CBaseCoder::Init()
+{
+ CalculateDigest();
+ if (_aesFilter == 0)
+ {
+ RINOK(CreateFilter());
+ }
+ CMyComPtr<ICryptoProperties> cp;
+ RINOK(_aesFilter.QueryInterface(IID_ICryptoProperties, &cp));
+ RINOK(cp->SetKey(_key.Key, sizeof(_key.Key)));
+ RINOK(cp->SetInitVector(_iv, sizeof(_iv)));
+ return S_OK;
+}
+
+STDMETHODIMP_(UInt32) CBaseCoder::Filter(Byte *data, UInt32 size)
+{
+ return _aesFilter->Filter(data, size);
+}
+
+HRESULT CDecoder::CreateFilter()
+{
+ _aesFilter = new CAesCbcDecoder;
+ return S_OK;
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/7zAes.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/7zAes.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/7zAes.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/7zAes.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,117 @@
+// 7zAes.h
+
+#ifndef __CRYPTO_7Z_AES_H
+#define __CRYPTO_7Z_AES_H
+
+#include "Common/Buffer.h"
+#include "Common/MyCom.h"
+#include "Common/MyVector.h"
+
+#include "../ICoder.h"
+#include "../IPassword.h"
+
+namespace NCrypto {
+namespace NSevenZ {
+
+const int kKeySize = 32;
+
+class CKeyInfo
+{
+public:
+ int NumCyclesPower;
+ UInt32 SaltSize;
+ Byte Salt[16];
+ CByteBuffer Password;
+ Byte Key[kKeySize];
+
+ bool IsEqualTo(const CKeyInfo &a) const;
+ void CalculateDigest();
+
+ CKeyInfo() { Init(); }
+ void Init()
+ {
+ NumCyclesPower = 0;
+ SaltSize = 0;
+ for (int i = 0; i < sizeof(Salt); i++)
+ Salt[i] = 0;
+ }
+};
+
+class CKeyInfoCache
+{
+ int Size;
+ CObjectVector<CKeyInfo> Keys;
+public:
+ CKeyInfoCache(int size): Size(size) {}
+ bool Find(CKeyInfo &key);
+ // HRESULT Calculate(CKeyInfo &key);
+ void Add(CKeyInfo &key);
+};
+
+class CBase
+{
+ CKeyInfoCache _cachedKeys;
+protected:
+ CKeyInfo _key;
+ Byte _iv[16];
+ UInt32 _ivSize;
+ void CalculateDigest();
+ CBase();
+};
+
+class CBaseCoder:
+ public ICompressFilter,
+ public ICryptoSetPassword,
+ public CMyUnknownImp,
+ public CBase
+{
+protected:
+ CMyComPtr<ICompressFilter> _aesFilter;
+
+ virtual HRESULT CreateFilter() = 0;
+ #ifndef CRYPTO_AES
+ HRESULT CreateFilterFromDLL(REFCLSID clsID);
+ #endif
+public:
+ STDMETHOD(Init)();
+ STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
+
+ STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
+};
+
+#ifndef EXTRACT_ONLY
+
+class CEncoder:
+ public CBaseCoder,
+ public ICompressWriteCoderProperties,
+ // public ICryptoResetSalt,
+ public ICryptoResetInitVector
+{
+ virtual HRESULT CreateFilter();
+public:
+ MY_UNKNOWN_IMP3(
+ ICryptoSetPassword,
+ ICompressWriteCoderProperties,
+ // ICryptoResetSalt,
+ ICryptoResetInitVector)
+ STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
+ // STDMETHOD(ResetSalt)();
+ STDMETHOD(ResetInitVector)();
+};
+#endif
+
+class CDecoder:
+ public CBaseCoder,
+ public ICompressSetDecoderProperties2
+{
+ virtual HRESULT CreateFilter();
+public:
+ MY_UNKNOWN_IMP2(
+ ICryptoSetPassword,
+ ICompressSetDecoderProperties2)
+ STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/7zAesRegister.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/7zAesRegister.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/7zAesRegister.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/7zAesRegister.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,18 @@
+// 7zAesRegister.cpp
+
+#include "StdAfx.h"
+
+#include "../Common/RegisterCodec.h"
+#include "7zAes.h"
+
+static void *CreateCodec() { return (void *)(ICompressFilter *)(new NCrypto::NSevenZ::CDecoder()); }
+#ifndef EXTRACT_ONLY
+static void *CreateCodecOut() { return (void *)(ICompressFilter *)(new NCrypto::NSevenZ::CEncoder()); }
+#else
+#define CreateCodecOut 0
+#endif
+
+static CCodecInfo g_CodecInfo =
+ { CreateCodec, CreateCodecOut, 0x06F10701, L"7zAES", 1, true };
+
+REGISTER_CODEC(7zAES)
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/HmacSha1.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/HmacSha1.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/HmacSha1.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/HmacSha1.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,109 @@
+// HmacSha1.cpp
+
+#include "StdAfx.h"
+
+#include "HmacSha1.h"
+
+namespace NCrypto {
+namespace NSha1 {
+
+void CHmac::SetKey(const Byte *key, size_t keySize)
+{
+ Byte keyTemp[kBlockSize];
+ size_t i;
+ for (i = 0; i < kBlockSize; i++)
+ keyTemp[i] = 0;
+ if(keySize > kBlockSize)
+ {
+ _sha.Init();
+ _sha.Update(key, keySize);
+ _sha.Final(keyTemp);
+ keySize = kDigestSize;
+ }
+ else
+ for (i = 0; i < keySize; i++)
+ keyTemp[i] = key[i];
+ for (i = 0; i < kBlockSize; i++)
+ keyTemp[i] ^= 0x36;
+ _sha.Init();
+ _sha.Update(keyTemp, kBlockSize);
+ for (i = 0; i < kBlockSize; i++)
+ keyTemp[i] ^= 0x36 ^ 0x5C;
+ _sha2.Init();
+ _sha2.Update(keyTemp, kBlockSize);
+}
+
+void CHmac::Final(Byte *mac, size_t macSize)
+{
+ Byte digest[kDigestSize];
+ _sha.Final(digest);
+ _sha2.Update(digest, kDigestSize);
+ _sha2.Final(digest);
+ for(size_t i = 0; i < macSize; i++)
+ mac[i] = digest[i];
+}
+
+
+void CHmac32::SetKey(const Byte *key, size_t keySize)
+{
+ UInt32 keyTemp[kBlockSizeInWords];
+ size_t i;
+ for (i = 0; i < kBlockSizeInWords; i++)
+ keyTemp[i] = 0;
+ if(keySize > kBlockSize)
+ {
+ CContext sha;
+ sha.Init();
+ sha.Update(key, keySize);
+ Byte digest[kDigestSize];
+ sha.Final(digest);
+
+ for (int i = 0 ; i < kDigestSizeInWords; i++)
+ keyTemp[i] =
+ ((UInt32)(digest[i * 4 + 0]) << 24) |
+ ((UInt32)(digest[i * 4 + 1]) << 16) |
+ ((UInt32)(digest[i * 4 + 2]) << 8) |
+ ((UInt32)(digest[i * 4 + 3]));
+ keySize = kDigestSizeInWords;
+ }
+ else
+ for (size_t i = 0; i < keySize; i++)
+ keyTemp[i / 4] |= (key[i] << (24 - 8 * (i & 3)));
+ for (i = 0; i < kBlockSizeInWords; i++)
+ keyTemp[i] ^= 0x36363636;
+ _sha.Init();
+ _sha.Update(keyTemp, kBlockSizeInWords);
+ for (i = 0; i < kBlockSizeInWords; i++)
+ keyTemp[i] ^= 0x36363636 ^ 0x5C5C5C5C;
+ _sha2.Init();
+ _sha2.Update(keyTemp, kBlockSizeInWords);
+}
+
+void CHmac32::Final(UInt32 *mac, size_t macSize)
+{
+ UInt32 digest[kDigestSizeInWords];
+ _sha.Final(digest);
+ _sha2.Update(digest, kDigestSizeInWords);
+ _sha2.Final(digest);
+ for(size_t i = 0; i < macSize; i++)
+ mac[i] = digest[i];
+}
+
+void CHmac32::GetLoopXorDigest(UInt32 *mac, UInt32 numIteration)
+{
+ UInt32 block[kBlockSizeInWords];
+ UInt32 block2[kBlockSizeInWords];
+ _sha.PrepareBlock(block, kDigestSizeInWords);
+ _sha2.PrepareBlock(block2, kDigestSizeInWords);
+ for(unsigned int s = 0; s < kDigestSizeInWords; s++)
+ block[s] = mac[s];
+ for(UInt32 i = 0; i < numIteration; i++)
+ {
+ _sha.GetBlockDigest(block, block2);
+ _sha2.GetBlockDigest(block2, block);
+ for (unsigned int s = 0; s < kDigestSizeInWords; s++)
+ mac[s] ^= block[s];
+ }
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/HmacSha1.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/HmacSha1.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/HmacSha1.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/HmacSha1.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,39 @@
+// HmacSha1.h
+// Implements HMAC-SHA-1 (RFC2104, FIPS-198)
+
+#ifndef __CRYPTO_HMAC_SHA1_H
+#define __CRYPTO_HMAC_SHA1_H
+
+#include "Sha1.h"
+
+namespace NCrypto {
+namespace NSha1 {
+
+// Use: SetKey(key, keySize); for () Update(data, size); Final(mac, macSize);
+
+class CHmac
+{
+ CContext _sha;
+ CContext _sha2;
+public:
+ void SetKey(const Byte *key, size_t keySize);
+ void Update(const Byte *data, size_t dataSize) { _sha.Update(data, dataSize); }
+ void Final(Byte *mac, size_t macSize = kDigestSize);
+};
+
+class CHmac32
+{
+ CContext32 _sha;
+ CContext32 _sha2;
+public:
+ void SetKey(const Byte *key, size_t keySize);
+ void Update(const UInt32 *data, size_t dataSize) { _sha.Update(data, dataSize); }
+ void Final(UInt32 *mac, size_t macSize = kDigestSizeInWords);
+
+ // It'sa for hmac function. in,out: mac[kDigestSizeInWords].
+ void GetLoopXorDigest(UInt32 *mac, UInt32 numIteration);
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/MyAes.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/MyAes.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/MyAes.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/MyAes.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,48 @@
+// Crypto/MyAes.cpp
+
+#include "StdAfx.h"
+
+#include "MyAes.h"
+
+namespace NCrypto {
+
+struct CAesTabInit { CAesTabInit() { AesGenTables();} } g_AesTabInit;
+
+CAesCbcCoder::CAesCbcCoder()
+{
+ _offset = ((0 - (unsigned)(ptrdiff_t)_aes) & 0xF) / sizeof(UInt32);
+}
+
+STDMETHODIMP CAesCbcCoder::Init() { return S_OK; }
+
+STDMETHODIMP_(UInt32) CAesCbcCoder::Filter(Byte *data, UInt32 size)
+{
+ if (size == 0)
+ return 0;
+ if (size < AES_BLOCK_SIZE)
+ return AES_BLOCK_SIZE;
+ size >>= 4;
+ _codeFunc(_aes + _offset, data, size);
+ return size << 4;
+}
+
+STDMETHODIMP CAesCbcCoder::SetKey(const Byte *data, UInt32 size)
+{
+ if ((size & 0x7) != 0 || size < 16 || size > 32)
+ return E_INVALIDARG;
+ _setKeyFunc(_aes + _offset + 4, data, size);
+ return S_OK;
+}
+
+STDMETHODIMP CAesCbcCoder::SetInitVector(const Byte *data, UInt32 size)
+{
+ if (size != AES_BLOCK_SIZE)
+ return E_INVALIDARG;
+ AesCbc_Init(_aes + _offset, data);
+ return S_OK;
+}
+
+CAesCbcEncoder::CAesCbcEncoder() { _codeFunc = g_AesCbc_Encode; _setKeyFunc = Aes_SetKey_Enc; }
+CAesCbcDecoder::CAesCbcDecoder() { _codeFunc = g_AesCbc_Decode; _setKeyFunc = Aes_SetKey_Dec; }
+
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/MyAes.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/MyAes.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/MyAes.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/MyAes.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,38 @@
+// Crypto/MyAes.h
+
+#ifndef __CRYPTO_MY_AES_H
+#define __CRYPTO_MY_AES_H
+
+#include "../../../C/Aes.h"
+
+#include "../../Common/MyCom.h"
+
+#include "../ICoder.h"
+
+namespace NCrypto {
+
+class CAesCbcCoder:
+ public ICompressFilter,
+ public ICryptoProperties,
+ public CMyUnknownImp
+{
+protected:
+ AES_CODE_FUNC _codeFunc;
+ AES_SET_KEY_FUNC _setKeyFunc;
+ unsigned _offset;
+ UInt32 _aes[AES_NUM_IVMRK_WORDS + 3];
+public:
+ CAesCbcCoder();
+ MY_UNKNOWN_IMP1(ICryptoProperties)
+ STDMETHOD(Init)();
+ STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
+ STDMETHOD(SetKey)(const Byte *data, UInt32 size);
+ STDMETHOD(SetInitVector)(const Byte *data, UInt32 size);
+};
+
+struct CAesCbcEncoder: public CAesCbcCoder { CAesCbcEncoder(); };
+struct CAesCbcDecoder: public CAesCbcCoder { CAesCbcDecoder(); };
+
+}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,83 @@
+// Pbkdf2HmacSha1.cpp
+
+#include "StdAfx.h"
+
+#include "HmacSha1.h"
+
+namespace NCrypto {
+namespace NSha1 {
+
+void Pbkdf2Hmac(const Byte *pwd, size_t pwdSize, const Byte *salt, size_t saltSize,
+ UInt32 numIterations, Byte *key, size_t keySize)
+{
+ CHmac baseCtx;
+ baseCtx.SetKey(pwd, pwdSize);
+ for (UInt32 i = 1; keySize > 0; i++)
+ {
+ CHmac ctx = baseCtx;
+ ctx.Update(salt, saltSize);
+ Byte u[kDigestSize] = { (Byte)(i >> 24), (Byte)(i >> 16), (Byte)(i >> 8), (Byte)(i) };
+ const unsigned int curSize = (keySize < kDigestSize) ? (unsigned int)keySize : kDigestSize;
+ ctx.Update(u, 4);
+ ctx.Final(u, kDigestSize);
+
+ unsigned int s;
+ for (s = 0; s < curSize; s++)
+ key[s] = u[s];
+
+ for (UInt32 j = numIterations; j > 1; j--)
+ {
+ ctx = baseCtx;
+ ctx.Update(u, kDigestSize);
+ ctx.Final(u, kDigestSize);
+ for (s = 0; s < curSize; s++)
+ key[s] ^= u[s];
+ }
+
+ key += curSize;
+ keySize -= curSize;
+ }
+}
+
+void Pbkdf2Hmac32(const Byte *pwd, size_t pwdSize, const UInt32 *salt, size_t saltSize,
+ UInt32 numIterations, UInt32 *key, size_t keySize)
+{
+ CHmac32 baseCtx;
+ baseCtx.SetKey(pwd, pwdSize);
+ for (UInt32 i = 1; keySize > 0; i++)
+ {
+ CHmac32 ctx = baseCtx;
+ ctx.Update(salt, saltSize);
+ UInt32 u[kDigestSizeInWords] = { i };
+ const unsigned int curSize = (keySize < kDigestSizeInWords) ? (unsigned int)keySize : kDigestSizeInWords;
+ ctx.Update(u, 1);
+ ctx.Final(u, kDigestSizeInWords);
+
+ // Speed-optimized code start
+ ctx = baseCtx;
+ ctx.GetLoopXorDigest(u, numIterations - 1);
+ // Speed-optimized code end
+
+ unsigned int s;
+ for (s = 0; s < curSize; s++)
+ key[s] = u[s];
+
+ /*
+ // Default code start
+ for (UInt32 j = numIterations; j > 1; j--)
+ {
+ ctx = baseCtx;
+ ctx.Update(u, kDigestSizeInWords);
+ ctx.Final(u, kDigestSizeInWords);
+ for (s = 0; s < curSize; s++)
+ key[s] ^= u[s];
+ }
+ // Default code end
+ */
+
+ key += curSize;
+ keySize -= curSize;
+ }
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Pbkdf2HmacSha1.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,21 @@
+// Pbkdf2HmacSha1.h
+// Password-Based Key Derivation Function (RFC 2898, PKCS #5) based on HMAC-SHA-1
+
+#ifndef __CRYPTO_PBKDF2_HMAC_SHA1_H
+#define __CRYPTO_PBKDF2_HMAC_SHA1_H
+
+#include <stddef.h>
+#include "../../Common/Types.h"
+
+namespace NCrypto {
+namespace NSha1 {
+
+void Pbkdf2Hmac(const Byte *pwd, size_t pwdSize, const Byte *salt, size_t saltSize,
+ UInt32 numIterations, Byte *key, size_t keySize);
+
+void Pbkdf2Hmac32(const Byte *pwd, size_t pwdSize, const UInt32 *salt, size_t saltSize,
+ UInt32 numIterations, UInt32 *key, size_t keySize);
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RandGen.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RandGen.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RandGen.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RandGen.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,107 @@
+// RandGen.cpp
+
+#include "StdAfx.h"
+
+#include <stdio.h>
+#include "Windows/Synchronization.h"
+#include "RandGen.h"
+
+#ifndef _WIN32
+#include <unistd.h>
+#define USE_POSIX_TIME
+#define USE_POSIX_TIME2
+#endif
+
+#ifdef USE_POSIX_TIME
+#include <time.h>
+#ifdef USE_POSIX_TIME2
+#include <sys/time.h>
+#endif
+#endif
+
+// This is not very good random number generator.
+// Please use it only for salt.
+// First generated data block depends from timer and processID.
+// Other generated data blocks depend from previous state
+// Maybe it's possible to restore original timer value from generated value.
+
+void CRandomGenerator::Init()
+{
+ NCrypto::NSha1::CContext hash;
+ hash.Init();
+
+ #ifdef _WIN32
+ DWORD w = ::GetCurrentProcessId();
+ hash.Update((const Byte *)&w, sizeof(w));
+ w = ::GetCurrentThreadId();
+ hash.Update((const Byte *)&w, sizeof(w));
+ #else
+ pid_t pid = getpid();
+ hash.Update((const Byte *)&pid, sizeof(pid));
+ pid = getppid();
+ hash.Update((const Byte *)&pid, sizeof(pid));
+ #endif
+
+ for (int i = 0; i < 1000; i++)
+ {
+ #ifdef _WIN32
+ LARGE_INTEGER v;
+ if (::QueryPerformanceCounter(&v))
+ hash.Update((const Byte *)&v.QuadPart, sizeof(v.QuadPart));
+ #endif
+
+ #ifdef USE_POSIX_TIME
+ #ifdef USE_POSIX_TIME2
+ timeval v;
+ if (gettimeofday(&v, 0) == 0)
+ {
+ hash.Update((const Byte *)&v.tv_sec, sizeof(v.tv_sec));
+ hash.Update((const Byte *)&v.tv_usec, sizeof(v.tv_usec));
+ }
+ #endif
+ time_t v2 = time(NULL);
+ hash.Update((const Byte *)&v2, sizeof(v2));
+ #endif
+
+ DWORD tickCount = ::GetTickCount();
+ hash.Update((const Byte *)&tickCount, sizeof(tickCount));
+
+ for (int j = 0; j < 100; j++)
+ {
+ hash.Final(_buff);
+ hash.Init();
+ hash.Update(_buff, NCrypto::NSha1::kDigestSize);
+ }
+ }
+ hash.Final(_buff);
+ _needInit = false;
+}
+
+static NWindows::NSynchronization::CCriticalSection g_CriticalSection;
+
+void CRandomGenerator::Generate(Byte *data, unsigned int size)
+{
+ g_CriticalSection.Enter();
+ if (_needInit)
+ Init();
+ while (size > 0)
+ {
+ NCrypto::NSha1::CContext hash;
+
+ hash.Init();
+ hash.Update(_buff, NCrypto::NSha1::kDigestSize);
+ hash.Final(_buff);
+
+ hash.Init();
+ UInt32 salt = 0xF672ABD1;
+ hash.Update((const Byte *)&salt, sizeof(salt));
+ hash.Update(_buff, NCrypto::NSha1::kDigestSize);
+ Byte buff[NCrypto::NSha1::kDigestSize];
+ hash.Final(buff);
+ for (unsigned int i = 0; i < NCrypto::NSha1::kDigestSize && size > 0; i++, size--)
+ *data++ = buff[i];
+ }
+ g_CriticalSection.Leave();
+}
+
+CRandomGenerator g_RandomGenerator;
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RandGen.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RandGen.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RandGen.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RandGen.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,21 @@
+// RandGen.h
+
+#ifndef __CRYPTO_RAND_GEN_H
+#define __CRYPTO_RAND_GEN_H
+
+#include "Sha1.h"
+
+class CRandomGenerator
+{
+ Byte _buff[NCrypto::NSha1::kDigestSize];
+ bool _needInit;
+
+ void Init();
+public:
+ CRandomGenerator(): _needInit(true) {};
+ void Generate(Byte *data, unsigned size);
+};
+
+extern CRandomGenerator g_RandomGenerator;
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Rar20Crypto.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Rar20Crypto.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Rar20Crypto.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Rar20Crypto.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,133 @@
+// Crypto/Rar20Crypto.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/7zCrc.h"
+#include "../../../C/CpuArch.h"
+#include "../../../C/RotateDefs.h"
+
+#include "Rar20Crypto.h"
+
+namespace NCrypto {
+namespace NRar20 {
+
+static const int kNumRounds = 32;
+
+static const Byte InitSubstTable[256] = {
+ 215, 19,149, 35, 73,197,192,205,249, 28, 16,119, 48,221, 2, 42,
+ 232, 1,177,233, 14, 88,219, 25,223,195,244, 90, 87,239,153,137,
+ 255,199,147, 70, 92, 66,246, 13,216, 40, 62, 29,217,230, 86, 6,
+ 71, 24,171,196,101,113,218,123, 93, 91,163,178,202, 67, 44,235,
+ 107,250, 75,234, 49,167,125,211, 83,114,157,144, 32,193,143, 36,
+ 158,124,247,187, 89,214,141, 47,121,228, 61,130,213,194,174,251,
+ 97,110, 54,229,115, 57,152, 94,105,243,212, 55,209,245, 63, 11,
+ 164,200, 31,156, 81,176,227, 21, 76, 99,139,188,127, 17,248, 51,
+ 207,120,189,210, 8,226, 41, 72,183,203,135,165,166, 60, 98, 7,
+ 122, 38,155,170, 69,172,252,238, 39,134, 59,128,236, 27,240, 80,
+ 131, 3, 85,206,145, 79,154,142,159,220,201,133, 74, 64, 20,129,
+ 224,185,138,103,173,182, 43, 34,254, 82,198,151,231,180, 58, 10,
+ 118, 26,102, 12, 50,132, 22,191,136,111,162,179, 45, 4,148,108,
+ 161, 56, 78,126,242,222, 15,175,146, 23, 33,241,181,190, 77,225,
+ 0, 46,169,186, 68, 95,237, 65, 53,208,253,168, 9, 18,100, 52,
+ 116,184,160, 96,109, 37, 30,106,140,104,150, 5,204,117,112, 84
+};
+
+void CData::UpdateKeys(const Byte *data)
+{
+ for (int i = 0; i < 16; i += 4)
+ for (int j = 0; j < 4; j++)
+ Keys[j] ^= g_CrcTable[data[i + j]];
+}
+
+static void Swap(Byte *b1, Byte *b2)
+{
+ Byte b = *b1;
+ *b1 = *b2;
+ *b2 = b;
+}
+
+void CData::SetPassword(const Byte *password, UInt32 passwordLen)
+{
+ Keys[0] = 0xD3A3B879L;
+ Keys[1] = 0x3F6D12F7L;
+ Keys[2] = 0x7515A235L;
+ Keys[3] = 0xA4E7F123L;
+
+ Byte psw[256];
+ memset(psw, 0, sizeof(psw));
+ memcpy(psw, password, passwordLen);
+ memcpy(SubstTable, InitSubstTable, sizeof(SubstTable));
+
+ for (UInt32 j = 0; j < 256; j++)
+ for (UInt32 i = 0; i < passwordLen; i += 2)
+ {
+ UInt32 n2 = (Byte)g_CrcTable[(psw[i + 1] + j) & 0xFF];
+ UInt32 n1 = (Byte)g_CrcTable[(psw[i] - j) & 0xFF];
+ for (UInt32 k = 1; (n1 & 0xFF) != n2; n1++, k++)
+ Swap(&SubstTable[n1 & 0xFF], &SubstTable[(n1 + i + k) & 0xFF]);
+ }
+ for (UInt32 i = 0; i < passwordLen; i+= 16)
+ EncryptBlock(&psw[i]);
+}
+
+void CData::CryptBlock(Byte *buf, bool encrypt)
+{
+ Byte inBuf[16];
+ UInt32 A, B, C, D, T, TA, TB;
+
+ A = GetUi32(buf + 0) ^ Keys[0];
+ B = GetUi32(buf + 4) ^ Keys[1];
+ C = GetUi32(buf + 8) ^ Keys[2];
+ D = GetUi32(buf + 12) ^ Keys[3];
+
+ if (!encrypt)
+ memcpy(inBuf, buf, sizeof(inBuf));
+
+ for (int i = 0; i < kNumRounds; i++)
+ {
+ UInt32 key = Keys[(encrypt ? i : (kNumRounds - 1 - i)) & 3];
+ T = ((C + rotlFixed(D, 11)) ^ key);
+ TA = A ^ SubstLong(T);
+ T = ((D ^ rotlFixed(C, 17)) + key);
+ TB = B ^ SubstLong(T);
+ A = C;
+ B = D;
+ C = TA;
+ D = TB;
+ }
+
+ SetUi32(buf + 0, C ^ Keys[0]);
+ SetUi32(buf + 4, D ^ Keys[1]);
+ SetUi32(buf + 8, A ^ Keys[2]);
+ SetUi32(buf + 12, B ^ Keys[3]);
+
+ UpdateKeys(encrypt ? buf : inBuf);
+}
+
+STDMETHODIMP CDecoder::CryptoSetPassword(const Byte *data, UInt32 size)
+{
+ _cipher.SetPassword(data, size);
+ return S_OK;
+}
+
+STDMETHODIMP CDecoder::Init()
+{
+ return S_OK;
+}
+
+static const UInt32 kBlockSize = 16;
+
+STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size)
+{
+ if (size == 0)
+ return 0;
+ if (size < kBlockSize)
+ return kBlockSize;
+ UInt32 i;
+ size -= kBlockSize;
+ for (i = 0; i <= size; i += kBlockSize)
+ _cipher.DecryptBlock(data + i);
+ return i;
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Rar20Crypto.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Rar20Crypto.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Rar20Crypto.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Rar20Crypto.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,50 @@
+// Crypto/Rar20Crypto.h
+
+#ifndef __CRYPTO_RAR20_CRYPTO_H
+#define __CRYPTO_RAR20_CRYPTO_H
+
+#include "Common/MyCom.h"
+
+#include "../ICoder.h"
+#include "../IPassword.h"
+
+namespace NCrypto {
+namespace NRar20 {
+
+class CData
+{
+ Byte SubstTable[256];
+ UInt32 Keys[4];
+
+ UInt32 SubstLong(UInt32 t)
+ {
+ return (UInt32)SubstTable[(int)t & 255] |
+ ((UInt32)SubstTable[(int)(t >> 8) & 255] << 8) |
+ ((UInt32)SubstTable[(int)(t >> 16) & 255] << 16) |
+ ((UInt32)SubstTable[(int)(t >> 24) & 255] << 24);
+ }
+ void UpdateKeys(const Byte *data);
+ void CryptBlock(Byte *buf, bool encrypt);
+public:
+ void EncryptBlock(Byte *buf) { CryptBlock(buf, true); }
+ void DecryptBlock(Byte *buf) { CryptBlock(buf, false); }
+ void SetPassword(const Byte *password, UInt32 passwordLen);
+};
+
+class CDecoder:
+ public ICompressFilter,
+ public ICryptoSetPassword,
+ public CMyUnknownImp
+{
+ CData _cipher;
+public:
+ MY_UNKNOWN_IMP1(ICryptoSetPassword)
+
+ STDMETHOD(Init)();
+ STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
+ STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RarAes.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RarAes.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RarAes.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RarAes.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,134 @@
+// Crypto/RarAes.cpp
+// Note: you must include MyAes.cpp to project to initialize AES tables
+
+#include "StdAfx.h"
+
+#include "RarAes.h"
+#include "Sha1.h"
+
+namespace NCrypto {
+namespace NRar29 {
+
+CDecoder::CDecoder():
+ _thereIsSalt(false),
+ _needCalculate(true),
+ _rar350Mode(false)
+{
+ for (int i = 0; i < sizeof(_salt); i++)
+ _salt[i] = 0;
+}
+
+STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
+{
+ bool thereIsSaltPrev = _thereIsSalt;
+ _thereIsSalt = false;
+ if (size == 0)
+ return S_OK;
+ if (size < 8)
+ return E_INVALIDARG;
+ _thereIsSalt = true;
+ bool same = false;
+ if (_thereIsSalt == thereIsSaltPrev)
+ {
+ same = true;
+ if (_thereIsSalt)
+ {
+ for (unsigned i = 0; i < sizeof(_salt); i++)
+ if (_salt[i] != data[i])
+ {
+ same = false;
+ break;
+ }
+ }
+ }
+ for (unsigned i = 0; i < sizeof(_salt); i++)
+ _salt[i] = data[i];
+ if (!_needCalculate && !same)
+ _needCalculate = true;
+ return S_OK;
+}
+
+static const unsigned kMaxPasswordLength = 127 * 2;
+
+STDMETHODIMP CDecoder::CryptoSetPassword(const Byte *data, UInt32 size)
+{
+ if (size > kMaxPasswordLength)
+ size = kMaxPasswordLength;
+ bool same = false;
+ if (size == buffer.GetCapacity())
+ {
+ same = true;
+ for (UInt32 i = 0; i < size; i++)
+ if (data[i] != buffer[i])
+ {
+ same = false;
+ break;
+ }
+ }
+ if (!_needCalculate && !same)
+ _needCalculate = true;
+ buffer.SetCapacity(size);
+ memcpy(buffer, data, size);
+ return S_OK;
+}
+
+STDMETHODIMP CDecoder::Init()
+{
+ Calculate();
+ SetKey(aesKey, kRarAesKeySize);
+ AesCbc_Init(_aes + _offset, _aesInit);
+ return S_OK;
+}
+
+void CDecoder::Calculate()
+{
+ if (_needCalculate)
+ {
+ const unsigned kSaltSize = 8;
+
+ Byte rawPassword[kMaxPasswordLength + kSaltSize];
+
+ memcpy(rawPassword, buffer, buffer.GetCapacity());
+
+ size_t rawLength = buffer.GetCapacity();
+
+ if (_thereIsSalt)
+ {
+ memcpy(rawPassword + rawLength, _salt, kSaltSize);
+ rawLength += kSaltSize;
+ }
+
+ NSha1::CContext sha;
+ sha.Init();
+
+ // rar reverts hash for sha.
+ const unsigned kNumRounds = (1 << 18);
+ unsigned i;
+ for (i = 0; i < kNumRounds; i++)
+ {
+ sha.UpdateRar(rawPassword, rawLength, _rar350Mode);
+ Byte pswNum[3] = { (Byte)i, (Byte)(i >> 8), (Byte)(i >> 16) };
+ sha.UpdateRar(pswNum, 3, _rar350Mode);
+ if (i % (kNumRounds / 16) == 0)
+ {
+ NSha1::CContext shaTemp = sha;
+ Byte digest[NSha1::kDigestSize];
+ shaTemp.Final(digest);
+ _aesInit[i / (kNumRounds / 16)] = (Byte)digest[4 * 4 + 3];
+ }
+ }
+ /*
+ // it's test message for sha
+ const char *message = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
+ sha.Update((const Byte *)message, strlen(message));
+ */
+ Byte digest[20];
+ sha.Final(digest);
+ for (i = 0; i < 4; i++)
+ for (unsigned j = 0; j < 4; j++)
+ aesKey[i * 4 + j] = (digest[i * 4 + 3 - j]);
+ }
+ _needCalculate = false;
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RarAes.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RarAes.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RarAes.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/RarAes.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,47 @@
+// Crypto/RarAes.h
+
+#ifndef __CRYPTO_RAR_AES_H
+#define __CRYPTO_RAR_AES_H
+
+#include "../../../C/Aes.h"
+
+#include "Common/Buffer.h"
+
+#include "../IPassword.h"
+
+#include "MyAes.h"
+
+namespace NCrypto {
+namespace NRar29 {
+
+const UInt32 kRarAesKeySize = 16;
+
+class CDecoder:
+ public CAesCbcDecoder,
+ public ICompressSetDecoderProperties2,
+ public ICryptoSetPassword
+{
+ Byte _salt[8];
+ bool _thereIsSalt;
+ CByteBuffer buffer;
+ Byte aesKey[kRarAesKeySize];
+ Byte _aesInit[AES_BLOCK_SIZE];
+ bool _needCalculate;
+ bool _rar350Mode;
+
+ void Calculate();
+public:
+ MY_UNKNOWN_IMP2(
+ ICryptoSetPassword,
+ ICompressSetDecoderProperties2)
+ STDMETHOD(Init)();
+ STDMETHOD(CryptoSetPassword)(const Byte *aData, UInt32 aSize);
+ STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
+
+ CDecoder();
+ void SetRar350Mode(bool rar350Mode) { _rar350Mode = rar350Mode; }
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Sha1.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Sha1.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Sha1.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Sha1.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,229 @@
+// Crypto/Sha1.cpp
+// This file is based on public domain
+// Steve Reid and Wei Dai's code from Crypto++
+
+#include "StdAfx.h"
+
+#include "../../../C/RotateDefs.h"
+
+#include "Sha1.h"
+
+namespace NCrypto {
+namespace NSha1 {
+
+// define it for speed optimization
+// #define _SHA1_UNROLL
+
+static const unsigned kNumW =
+ #ifdef _SHA1_UNROLL
+ 16;
+ #else
+ 80;
+ #endif
+
+
+#define w0(i) (W[(i)] = data[(i)])
+
+#ifdef _SHA1_UNROLL
+#define w1(i) (W[(i)&15] = rotlFixed(W[((i)-3)&15] ^ W[((i)-8)&15] ^ W[((i)-14)&15] ^ W[((i)-16)&15], 1))
+#else
+#define w1(i) (W[(i)] = rotlFixed(W[(i)-3] ^ W[(i)-8] ^ W[(i)-14] ^ W[(i)-16], 1))
+#endif
+
+#define f1(x,y,z) (z^(x&(y^z)))
+#define f2(x,y,z) (x^y^z)
+#define f3(x,y,z) ((x&y)|(z&(x|y)))
+#define f4(x,y,z) (x^y^z)
+
+#define RK1(a,b,c,d,e,i, f, w, k) e += f(b,c,d) + w(i) + k + rotlFixed(a,5); b = rotlFixed(b,30);
+
+#define R0(a,b,c,d,e,i) RK1(a,b,c,d,e,i, f1, w0, 0x5A827999)
+#define R1(a,b,c,d,e,i) RK1(a,b,c,d,e,i, f1, w1, 0x5A827999)
+#define R2(a,b,c,d,e,i) RK1(a,b,c,d,e,i, f2, w1, 0x6ED9EBA1)
+#define R3(a,b,c,d,e,i) RK1(a,b,c,d,e,i, f3, w1, 0x8F1BBCDC)
+#define R4(a,b,c,d,e,i) RK1(a,b,c,d,e,i, f4, w1, 0xCA62C1D6)
+
+#define RX_1_4(rx1, rx4, i) rx1(a,b,c,d,e,i); rx4(e,a,b,c,d,i+1); rx4(d,e,a,b,c,i+2); rx4(c,d,e,a,b,i+3); rx4(b,c,d,e,a,i+4);
+#define RX_5(rx, i) RX_1_4(rx, rx, i);
+
+void CContextBase::Init()
+{
+ _state[0] = 0x67452301;
+ _state[1] = 0xEFCDAB89;
+ _state[2] = 0x98BADCFE;
+ _state[3] = 0x10325476;
+ _state[4] = 0xC3D2E1F0;
+ _count = 0;
+}
+
+void CContextBase::GetBlockDigest(UInt32 *data, UInt32 *destDigest, bool returnRes)
+{
+ UInt32 a, b, c, d, e;
+ UInt32 W[kNumW];
+
+ a = _state[0];
+ b = _state[1];
+ c = _state[2];
+ d = _state[3];
+ e = _state[4];
+ #ifdef _SHA1_UNROLL
+ RX_5(R0, 0); RX_5(R0, 5); RX_5(R0, 10);
+ #else
+ int i;
+ for (i = 0; i < 15; i += 5) { RX_5(R0, i); }
+ #endif
+
+ RX_1_4(R0, R1, 15);
+
+
+ #ifdef _SHA1_UNROLL
+ RX_5(R2, 20); RX_5(R2, 25); RX_5(R2, 30); RX_5(R2, 35);
+ RX_5(R3, 40); RX_5(R3, 45); RX_5(R3, 50); RX_5(R3, 55);
+ RX_5(R4, 60); RX_5(R4, 65); RX_5(R4, 70); RX_5(R4, 75);
+ #else
+ i = 20;
+ for (; i < 40; i += 5) { RX_5(R2, i); }
+ for (; i < 60; i += 5) { RX_5(R3, i); }
+ for (; i < 80; i += 5) { RX_5(R4, i); }
+ #endif
+
+ destDigest[0] = _state[0] + a;
+ destDigest[1] = _state[1] + b;
+ destDigest[2] = _state[2] + c;
+ destDigest[3] = _state[3] + d;
+ destDigest[4] = _state[4] + e;
+
+ if (returnRes)
+ for (int i = 0 ; i < 16; i++)
+ data[i] = W[kNumW - 16 + i];
+
+ // Wipe variables
+ // a = b = c = d = e = 0;
+}
+
+void CContextBase::PrepareBlock(UInt32 *block, unsigned size) const
+{
+ unsigned curBufferPos = size & 0xF;
+ block[curBufferPos++] = 0x80000000;
+ while (curBufferPos != (16 - 2))
+ block[curBufferPos++] = 0;
+ const UInt64 lenInBits = (_count << 9) + ((UInt64)size << 5);
+ block[curBufferPos++] = (UInt32)(lenInBits >> 32);
+ block[curBufferPos++] = (UInt32)(lenInBits);
+}
+
+void CContext::Update(const Byte *data, size_t size)
+{
+ unsigned curBufferPos = _count2;
+ while (size--)
+ {
+ int pos = (int)(curBufferPos & 3);
+ if (pos == 0)
+ _buffer[curBufferPos >> 2] = 0;
+ _buffer[curBufferPos >> 2] |= ((UInt32)*data++) << (8 * (3 - pos));
+ if (++curBufferPos == kBlockSize)
+ {
+ curBufferPos = 0;
+ CContextBase::UpdateBlock(_buffer, false);
+ }
+ }
+ _count2 = curBufferPos;
+}
+
+void CContext::UpdateRar(Byte *data, size_t size, bool rar350Mode)
+{
+ bool returnRes = false;
+ unsigned curBufferPos = _count2;
+ while (size--)
+ {
+ int pos = (int)(curBufferPos & 3);
+ if (pos == 0)
+ _buffer[curBufferPos >> 2] = 0;
+ _buffer[curBufferPos >> 2] |= ((UInt32)*data++) << (8 * (3 - pos));
+ if (++curBufferPos == kBlockSize)
+ {
+ curBufferPos = 0;
+ CContextBase::UpdateBlock(_buffer, returnRes);
+ if (returnRes)
+ for (int i = 0; i < kBlockSizeInWords; i++)
+ {
+ UInt32 d = _buffer[i];
+ data[i * 4 + 0 - kBlockSize] = (Byte)(d);
+ data[i * 4 + 1 - kBlockSize] = (Byte)(d >> 8);
+ data[i * 4 + 2 - kBlockSize] = (Byte)(d >> 16);
+ data[i * 4 + 3 - kBlockSize] = (Byte)(d >> 24);
+ }
+ returnRes = rar350Mode;
+ }
+ }
+ _count2 = curBufferPos;
+}
+
+void CContext::Final(Byte *digest)
+{
+ const UInt64 lenInBits = (_count << 9) + ((UInt64)_count2 << 3);
+ unsigned curBufferPos = _count2;
+ int pos = (int)(curBufferPos & 3);
+ curBufferPos >>= 2;
+ if (pos == 0)
+ _buffer[curBufferPos] = 0;
+ _buffer[curBufferPos++] |= ((UInt32)0x80) << (8 * (3 - pos));
+
+ while (curBufferPos != (16 - 2))
+ {
+ curBufferPos &= 0xF;
+ if (curBufferPos == 0)
+ UpdateBlock();
+ _buffer[curBufferPos++] = 0;
+ }
+ _buffer[curBufferPos++] = (UInt32)(lenInBits >> 32);
+ _buffer[curBufferPos++] = (UInt32)(lenInBits);
+ UpdateBlock();
+
+ int i;
+ for (i = 0; i < kDigestSizeInWords; i++)
+ {
+ UInt32 state = _state[i] & 0xFFFFFFFF;
+ *digest++ = (Byte)(state >> 24);
+ *digest++ = (Byte)(state >> 16);
+ *digest++ = (Byte)(state >> 8);
+ *digest++ = (Byte)(state);
+ }
+ Init();
+}
+
+///////////////////////////
+// Words version
+
+void CContext32::Update(const UInt32 *data, size_t size)
+{
+ while (size--)
+ {
+ _buffer[_count2++] = *data++;
+ if (_count2 == kBlockSizeInWords)
+ {
+ _count2 = 0;
+ UpdateBlock();
+ }
+ }
+}
+
+void CContext32::Final(UInt32 *digest)
+{
+ const UInt64 lenInBits = (_count << 9) + ((UInt64)_count2 << 5);
+ unsigned curBufferPos = _count2;
+ _buffer[curBufferPos++] = 0x80000000;
+ while (curBufferPos != (16 - 2))
+ {
+ curBufferPos &= 0xF;
+ if (curBufferPos == 0)
+ UpdateBlock();
+ _buffer[curBufferPos++] = 0;
+ }
+ _buffer[curBufferPos++] = (UInt32)(lenInBits >> 32);
+ _buffer[curBufferPos++] = (UInt32)(lenInBits);
+ GetBlockDigest(_buffer, digest);
+ Init();
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Sha1.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Sha1.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Sha1.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/Sha1.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,68 @@
+// Crypto/Sha1.h
+// This file is based on public domain
+// Steve Reid and Wei Dai's code from Crypto++
+
+#ifndef __CRYPTO_SHA1_H
+#define __CRYPTO_SHA1_H
+
+#include <stddef.h>
+#include "../../Common/Types.h"
+
+// Sha1 implementation in RAR before version 3.60 has bug:
+// it changes data bytes in some cases.
+// So this class supports both versions: normal_SHA and rar3Mode
+
+namespace NCrypto {
+namespace NSha1 {
+
+const unsigned kBlockSize = 64;
+const unsigned kDigestSize = 20;
+
+const unsigned kBlockSizeInWords = (kBlockSize >> 2);
+const unsigned kDigestSizeInWords = (kDigestSize >> 2);
+
+class CContextBase
+{
+protected:
+ UInt32 _state[5];
+ UInt64 _count;
+ void UpdateBlock(UInt32 *data, bool returnRes = false)
+ {
+ GetBlockDigest(data, _state, returnRes);
+ _count++;
+ }
+public:
+ void Init();
+ void GetBlockDigest(UInt32 *blockData, UInt32 *destDigest, bool returnRes = false);
+ // PrepareBlock can be used only when size <= 13. size in Words
+ void PrepareBlock(UInt32 *block, unsigned int size) const;
+};
+
+class CContextBase2: public CContextBase
+{
+protected:
+ unsigned _count2;
+ UInt32 _buffer[kBlockSizeInWords];
+ void UpdateBlock() { CContextBase::UpdateBlock(_buffer); }
+public:
+ void Init() { CContextBase::Init(); _count2 = 0; }
+};
+
+class CContext: public CContextBase2
+{
+public:
+ void Update(const Byte *data, size_t size);
+ void UpdateRar(Byte *data, size_t size, bool rar350Mode);
+ void Final(Byte *digest);
+};
+
+class CContext32: public CContextBase2
+{
+public:
+ void Update(const UInt32 *data, size_t size);
+ void Final(UInt32 *digest);
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/WzAes.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/WzAes.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/WzAes.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/WzAes.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,221 @@
+// Crypto/WzAes.cpp
+/*
+This code implements Brian Gladman's scheme
+specified in password Based File Encryption Utility.
+
+Note: you must include MyAes.cpp to project to initialize AES tables
+*/
+
+#include "StdAfx.h"
+
+#include "../Common/StreamObjects.h"
+#include "../Common/StreamUtils.h"
+
+#include "Pbkdf2HmacSha1.h"
+#include "RandGen.h"
+#include "WzAes.h"
+
+// define it if you don't want to use speed-optimized version of Pbkdf2HmacSha1
+// #define _NO_WZAES_OPTIMIZATIONS
+
+namespace NCrypto {
+namespace NWzAes {
+
+const unsigned kAesKeySizeMax = 32;
+
+static const UInt32 kNumKeyGenIterations = 1000;
+
+STDMETHODIMP CBaseCoder::CryptoSetPassword(const Byte *data, UInt32 size)
+{
+ if(size > kPasswordSizeMax)
+ return E_INVALIDARG;
+ _key.Password.SetCapacity(size);
+ memcpy(_key.Password, data, size);
+ return S_OK;
+}
+
+#ifndef _NO_WZAES_OPTIMIZATIONS
+
+static void BytesToBeUInt32s(const Byte *src, UInt32 *dest, unsigned destSize)
+{
+ for (unsigned i = 0; i < destSize; i++)
+ dest[i] =
+ ((UInt32)(src[i * 4 + 0]) << 24) |
+ ((UInt32)(src[i * 4 + 1]) << 16) |
+ ((UInt32)(src[i * 4 + 2]) << 8) |
+ ((UInt32)(src[i * 4 + 3]));
+}
+
+#endif
+
+STDMETHODIMP CBaseCoder::Init()
+{
+ UInt32 keySize = _key.GetKeySize();
+ UInt32 keysTotalSize = 2 * keySize + kPwdVerifCodeSize;
+ Byte buf[2 * kAesKeySizeMax + kPwdVerifCodeSize];
+
+ // for (unsigned ii = 0; ii < 1000; ii++)
+ {
+ #ifdef _NO_WZAES_OPTIMIZATIONS
+
+ NSha1::Pbkdf2Hmac(
+ _key.Password, _key.Password.GetCapacity(),
+ _key.Salt, _key.GetSaltSize(),
+ kNumKeyGenIterations,
+ buf, keysTotalSize);
+
+ #else
+
+ UInt32 buf32[(2 * kAesKeySizeMax + kPwdVerifCodeSize + 3) / 4];
+ UInt32 key32SizeTotal = (keysTotalSize + 3) / 4;
+ UInt32 salt[kSaltSizeMax * 4];
+ UInt32 saltSizeInWords = _key.GetSaltSize() / 4;
+ BytesToBeUInt32s(_key.Salt, salt, saltSizeInWords);
+ NSha1::Pbkdf2Hmac32(
+ _key.Password, _key.Password.GetCapacity(),
+ salt, saltSizeInWords,
+ kNumKeyGenIterations,
+ buf32, key32SizeTotal);
+ for (UInt32 j = 0; j < keysTotalSize; j++)
+ buf[j] = (Byte)(buf32[j / 4] >> (24 - 8 * (j & 3)));
+
+ #endif
+ }
+
+ _hmac.SetKey(buf + keySize, keySize);
+ memcpy(_key.PwdVerifComputed, buf + 2 * keySize, kPwdVerifCodeSize);
+
+ AesCtr2_Init(&_aes);
+ Aes_SetKey_Enc(_aes.aes + _aes.offset + 8, buf, keySize);
+ return S_OK;
+}
+
+HRESULT CEncoder::WriteHeader(ISequentialOutStream *outStream)
+{
+ UInt32 saltSize = _key.GetSaltSize();
+ g_RandomGenerator.Generate(_key.Salt, saltSize);
+ Init();
+ RINOK(WriteStream(outStream, _key.Salt, saltSize));
+ return WriteStream(outStream, _key.PwdVerifComputed, kPwdVerifCodeSize);
+}
+
+HRESULT CEncoder::WriteFooter(ISequentialOutStream *outStream)
+{
+ Byte mac[kMacSize];
+ _hmac.Final(mac, kMacSize);
+ return WriteStream(outStream, mac, kMacSize);
+}
+
+STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size)
+{
+ if (size != 1)
+ return E_INVALIDARG;
+ _key.Init();
+ return SetKeyMode(data[0]) ? S_OK : E_INVALIDARG;
+}
+
+HRESULT CDecoder::ReadHeader(ISequentialInStream *inStream)
+{
+ UInt32 saltSize = _key.GetSaltSize();
+ UInt32 extraSize = saltSize + kPwdVerifCodeSize;
+ Byte temp[kSaltSizeMax + kPwdVerifCodeSize];
+ RINOK(ReadStream_FAIL(inStream, temp, extraSize));
+ UInt32 i;
+ for (i = 0; i < saltSize; i++)
+ _key.Salt[i] = temp[i];
+ for (i = 0; i < kPwdVerifCodeSize; i++)
+ _pwdVerifFromArchive[i] = temp[saltSize + i];
+ return S_OK;
+}
+
+static bool CompareArrays(const Byte *p1, const Byte *p2, UInt32 size)
+{
+ for (UInt32 i = 0; i < size; i++)
+ if (p1[i] != p2[i])
+ return false;
+ return true;
+}
+
+bool CDecoder::CheckPasswordVerifyCode()
+{
+ return CompareArrays(_key.PwdVerifComputed, _pwdVerifFromArchive, kPwdVerifCodeSize);
+}
+
+HRESULT CDecoder::CheckMac(ISequentialInStream *inStream, bool &isOK)
+{
+ isOK = false;
+ Byte mac1[kMacSize];
+ RINOK(ReadStream_FAIL(inStream, mac1, kMacSize));
+ Byte mac2[kMacSize];
+ _hmac.Final(mac2, kMacSize);
+ isOK = CompareArrays(mac1, mac2, kMacSize);
+ return S_OK;
+}
+
+CAesCtr2::CAesCtr2()
+{
+ offset = ((0 - (unsigned)(ptrdiff_t)aes) & 0xF) / sizeof(UInt32);
+}
+
+void AesCtr2_Init(CAesCtr2 *p)
+{
+ UInt32 *ctr = p->aes + p->offset + 4;
+ unsigned i;
+ for (i = 0; i < 4; i++)
+ ctr[i] = 0;
+ p->pos = AES_BLOCK_SIZE;
+}
+
+void AesCtr2_Code(CAesCtr2 *p, Byte *data, SizeT size)
+{
+ unsigned pos = p->pos;
+ UInt32 *buf32 = p->aes + p->offset;
+ if (size == 0)
+ return;
+ if (pos != AES_BLOCK_SIZE)
+ {
+ const Byte *buf = (const Byte *)buf32;
+ do
+ *data++ ^= buf[pos++];
+ while (--size != 0 && pos != AES_BLOCK_SIZE);
+ }
+ if (size >= 16)
+ {
+ SizeT size2 = size >> 4;
+ g_AesCtr_Code(buf32 + 4, data, size2);
+ size2 <<= 4;
+ data += size2;
+ size -= size2;
+ pos = AES_BLOCK_SIZE;
+ }
+ if (size != 0)
+ {
+ unsigned j;
+ const Byte *buf;
+ for (j = 0; j < 4; j++)
+ buf32[j] = 0;
+ g_AesCtr_Code(buf32 + 4, (Byte *)buf32, 1);
+ buf = (const Byte *)buf32;
+ pos = 0;
+ do
+ *data++ ^= buf[pos++];
+ while (--size != 0 && pos != AES_BLOCK_SIZE);
+ }
+ p->pos = pos;
+}
+
+STDMETHODIMP_(UInt32) CEncoder::Filter(Byte *data, UInt32 size)
+{
+ AesCtr2_Code(&_aes, data, size);
+ _hmac.Update(data, size);
+ return size;
+}
+
+STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size)
+{
+ _hmac.Update(data, size);
+ AesCtr2_Code(&_aes, data, size);
+ return size;
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/WzAes.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/WzAes.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/WzAes.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/WzAes.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,125 @@
+// Crypto/WzAes.h
+/*
+This code implements Brian Gladman's scheme
+specified in password Based File Encryption Utility:
+ - AES encryption (128,192,256-bit) in Counter (CTR) mode.
+ - HMAC-SHA1 authentication for encrypted data (10 bytes)
+ - Keys are derived by PPKDF2(RFC2898)-HMAC-SHA1 from ASCII password and
+ Salt (saltSize = aesKeySize / 2).
+ - 2 bytes contain Password Verifier's Code
+*/
+
+#ifndef __CRYPTO_WZ_AES_H
+#define __CRYPTO_WZ_AES_H
+
+#include "../../../C/Aes.h"
+
+#include "Common/Buffer.h"
+#include "Common/MyCom.h"
+#include "Common/MyVector.h"
+
+#include "../ICoder.h"
+#include "../IPassword.h"
+
+#include "HmacSha1.h"
+
+namespace NCrypto {
+namespace NWzAes {
+
+const unsigned kSaltSizeMax = 16;
+const unsigned kMacSize = 10;
+
+const UInt32 kPasswordSizeMax = 99; // 128;
+
+// Password Verification Code Size
+const unsigned kPwdVerifCodeSize = 2;
+
+enum EKeySizeMode
+{
+ kKeySizeMode_AES128 = 1,
+ kKeySizeMode_AES192 = 2,
+ kKeySizeMode_AES256 = 3
+};
+
+class CKeyInfo
+{
+public:
+ EKeySizeMode KeySizeMode;
+ Byte Salt[kSaltSizeMax];
+ Byte PwdVerifComputed[kPwdVerifCodeSize];
+
+ CByteBuffer Password;
+
+ UInt32 GetKeySize() const { return (8 * (KeySizeMode & 3) + 8); }
+ UInt32 GetSaltSize() const { return (4 * (KeySizeMode & 3) + 4); }
+
+ CKeyInfo() { Init(); }
+ void Init() { KeySizeMode = kKeySizeMode_AES256; }
+};
+
+struct CAesCtr2
+{
+ unsigned pos;
+ unsigned offset;
+ UInt32 aes[4 + AES_NUM_IVMRK_WORDS + 3];
+ CAesCtr2();
+};
+
+void AesCtr2_Init(CAesCtr2 *p);
+void AesCtr2_Code(CAesCtr2 *p, Byte *data, SizeT size);
+
+class CBaseCoder:
+ public ICompressFilter,
+ public ICryptoSetPassword,
+ public CMyUnknownImp
+{
+protected:
+ CKeyInfo _key;
+ NSha1::CHmac _hmac;
+ Byte _pwdVerifFromArchive[kPwdVerifCodeSize];
+ CAesCtr2 _aes;
+
+public:
+ STDMETHOD(Init)();
+ STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) = 0;
+
+ STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
+
+ UInt32 GetHeaderSize() const { return _key.GetSaltSize() + kPwdVerifCodeSize; }
+ bool SetKeyMode(unsigned mode)
+ {
+ if (mode < kKeySizeMode_AES128 || mode > kKeySizeMode_AES256)
+ return false;
+ _key.KeySizeMode = (EKeySizeMode)mode;
+ return true;
+ }
+};
+
+class CEncoder:
+ public CBaseCoder
+{
+public:
+ MY_UNKNOWN_IMP1(ICryptoSetPassword)
+ STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
+ HRESULT WriteHeader(ISequentialOutStream *outStream);
+ HRESULT WriteFooter(ISequentialOutStream *outStream);
+};
+
+class CDecoder:
+ public CBaseCoder,
+ public ICompressSetDecoderProperties2
+{
+public:
+ MY_UNKNOWN_IMP2(
+ ICryptoSetPassword,
+ ICompressSetDecoderProperties2)
+ STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
+ STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
+ HRESULT ReadHeader(ISequentialInStream *inStream);
+ bool CheckPasswordVerifyCode();
+ HRESULT CheckMac(ISequentialInStream *inStream, bool &isOK);
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipCrypto.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipCrypto.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipCrypto.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipCrypto.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,88 @@
+// Crypto/ZipCrypto.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/7zCrc.h"
+
+#include "../Common/StreamUtils.h"
+
+#include "RandGen.h"
+#include "ZipCrypto.h"
+
+namespace NCrypto {
+namespace NZip {
+
+void CCipher::UpdateKeys(Byte b)
+{
+ Keys[0] = CRC_UPDATE_BYTE(Keys[0], b);
+ Keys[1] = (Keys[1] + (Keys[0] & 0xFF)) * 0x8088405 + 1;
+ Keys[2] = CRC_UPDATE_BYTE(Keys[2], (Byte)(Keys[1] >> 24));
+}
+
+STDMETHODIMP CCipher::CryptoSetPassword(const Byte *password, UInt32 passwordLen)
+{
+ Keys[0] = 0x12345678;
+ Keys[1] = 0x23456789;
+ Keys[2] = 0x34567890;
+ UInt32 i;
+ for (i = 0; i < passwordLen; i++)
+ UpdateKeys(password[i]);
+ for (i = 0; i < 3; i++)
+ Keys2[i] = Keys[i];
+ return S_OK;
+}
+
+STDMETHODIMP CCipher::Init()
+{
+ return S_OK;
+}
+
+Byte CCipher::DecryptByteSpec()
+{
+ UInt32 temp = Keys[2] | 2;
+ return (Byte)((temp * (temp ^ 1)) >> 8);
+}
+
+HRESULT CEncoder::WriteHeader(ISequentialOutStream *outStream, UInt32 crc)
+{
+ Byte h[kHeaderSize];
+ g_RandomGenerator.Generate(h, kHeaderSize - 2);
+ h[kHeaderSize - 1] = (Byte)(crc >> 24);
+ h[kHeaderSize - 2] = (Byte)(crc >> 16);
+ RestoreKeys();
+ Filter(h, kHeaderSize);
+ return WriteStream(outStream, h, kHeaderSize);
+}
+
+STDMETHODIMP_(UInt32) CEncoder::Filter(Byte *data, UInt32 size)
+{
+ for (UInt32 i = 0; i < size; i++)
+ {
+ Byte b = data[i];
+ data[i] = (Byte)(b ^ DecryptByteSpec());;
+ UpdateKeys(b);
+ }
+ return size;
+}
+
+HRESULT CDecoder::ReadHeader(ISequentialInStream *inStream)
+{
+ Byte h[kHeaderSize];
+ RINOK(ReadStream_FAIL(inStream, h, kHeaderSize));
+ RestoreKeys();
+ Filter(h, kHeaderSize);
+ return S_OK;
+}
+
+STDMETHODIMP_(UInt32) CDecoder::Filter(Byte *data, UInt32 size)
+{
+ for (UInt32 i = 0; i < size; i++)
+ {
+ Byte c = (Byte)(data[i] ^ DecryptByteSpec());
+ UpdateKeys(c);
+ data[i] = c;
+ }
+ return size;
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipCrypto.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipCrypto.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipCrypto.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipCrypto.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,56 @@
+// Crypto/ZipCrypto.h
+
+#ifndef __CRYPTO_ZIP_CRYPTO_H
+#define __CRYPTO_ZIP_CRYPTO_H
+
+#include "Common/MyCom.h"
+
+#include "../ICoder.h"
+#include "../IPassword.h"
+
+namespace NCrypto {
+namespace NZip {
+
+const unsigned kHeaderSize = 12;
+
+class CCipher:
+ public ICompressFilter,
+ public ICryptoSetPassword,
+ public CMyUnknownImp
+{
+ UInt32 Keys[3];
+ UInt32 Keys2[3];
+
+protected:
+ void UpdateKeys(Byte b);
+ Byte DecryptByteSpec();
+ void RestoreKeys()
+ {
+ for (int i = 0; i < 3; i++)
+ Keys[i] = Keys2[i];
+ }
+
+public:
+ STDMETHOD(Init)();
+ STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
+};
+
+class CEncoder: public CCipher
+{
+public:
+ MY_UNKNOWN_IMP1(ICryptoSetPassword)
+ STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
+ HRESULT WriteHeader(ISequentialOutStream *outStream, UInt32 crc);
+};
+
+class CDecoder: public CCipher
+{
+public:
+ MY_UNKNOWN_IMP1(ICryptoSetPassword)
+ STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
+ HRESULT ReadHeader(ISequentialInStream *inStream);
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipStrong.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipStrong.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipStrong.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipStrong.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,164 @@
+// Crypto/ZipStrong.cpp
+
+#include "StdAfx.h"
+
+#include "../../../C/7zCrc.h"
+#include "../../../C/CpuArch.h"
+
+#include "../Common/StreamUtils.h"
+
+#include "MyAes.h"
+#include "Sha1.h"
+#include "ZipStrong.h"
+
+namespace NCrypto {
+namespace NZipStrong {
+
+static const UInt16 kAES128 = 0x660E;
+
+// DeriveKey* function is similar to CryptDeriveKey() from Windows.
+// But MSDN tells that we need such scheme only if
+// "the required key length is longer than the hash value"
+// but ZipStrong uses it always.
+
+static void DeriveKey2(const Byte *digest, Byte c, Byte *dest)
+{
+ Byte buf[64];
+ memset(buf, c, 64);
+ for (unsigned i = 0; i < NSha1::kDigestSize; i++)
+ buf[i] ^= digest[i];
+ NSha1::CContext sha;
+ sha.Init();
+ sha.Update(buf, 64);
+ sha.Final(dest);
+}
+
+static void DeriveKey(NSha1::CContext &sha, Byte *key)
+{
+ Byte digest[NSha1::kDigestSize];
+ sha.Final(digest);
+ Byte temp[NSha1::kDigestSize * 2];
+ DeriveKey2(digest, 0x36, temp);
+ DeriveKey2(digest, 0x5C, temp + NSha1::kDigestSize);
+ memcpy(key, temp, 32);
+}
+
+void CKeyInfo::SetPassword(const Byte *data, UInt32 size)
+{
+ NSha1::CContext sha;
+ sha.Init();
+ sha.Update(data, size);
+ DeriveKey(sha, MasterKey);
+}
+
+STDMETHODIMP CBaseCoder::CryptoSetPassword(const Byte *data, UInt32 size)
+{
+ _key.SetPassword(data, size);
+ return S_OK;
+}
+
+HRESULT CDecoder::ReadHeader(ISequentialInStream *inStream, UInt32 /* crc */, UInt64 /* unpackSize */)
+{
+ Byte temp[4];
+ RINOK(ReadStream_FALSE(inStream, temp, 2));
+ _ivSize = GetUi16(temp);
+ if (_ivSize == 0)
+ {
+ return E_NOTIMPL;
+ /*
+ SetUi32(_iv, crc);
+ for (int i = 0; i < 8; i++)
+ _iv[4 + i] = (Byte)(unpackSize >> (8 * i));
+ SetUi32(_iv + 12, 0);
+ */
+ }
+ else if (_ivSize == 16)
+ {
+ RINOK(ReadStream_FALSE(inStream, _iv, _ivSize));
+ }
+ else
+ return E_NOTIMPL;
+ RINOK(ReadStream_FALSE(inStream, temp, 4));
+ _remSize = GetUi32(temp);
+ const UInt32 kAlign = 16;
+ if (_remSize < 16 || _remSize > (1 << 18))
+ return E_NOTIMPL;
+ if (_remSize + kAlign > _buf.GetCapacity())
+ {
+ _buf.Free();
+ _buf.SetCapacity(_remSize + kAlign);
+ _bufAligned = (Byte *)((ptrdiff_t)((Byte *)_buf + kAlign - 1) & ~(ptrdiff_t)(kAlign - 1));
+ }
+ return ReadStream_FALSE(inStream, _bufAligned, _remSize);
+}
+
+HRESULT CDecoder::CheckPassword(bool &passwOK)
+{
+ passwOK = false;
+ if (_remSize < 16)
+ return E_NOTIMPL;
+ Byte *p = _bufAligned;
+ UInt16 format = GetUi16(p);
+ if (format != 3)
+ return E_NOTIMPL;
+ UInt16 algId = GetUi16(p + 2);
+ if (algId < kAES128)
+ return E_NOTIMPL;
+ algId -= kAES128;
+ if (algId > 2)
+ return E_NOTIMPL;
+ UInt16 bitLen = GetUi16(p + 4);
+ UInt16 flags = GetUi16(p + 6);
+ if (algId * 64 + 128 != bitLen)
+ return E_NOTIMPL;
+ _key.KeySize = 16 + algId * 8;
+ if ((flags & 1) == 0)
+ return E_NOTIMPL;
+ if ((flags & 0x4000) != 0)
+ {
+ // Use 3DES
+ return E_NOTIMPL;
+ }
+
+ UInt32 rdSize = GetUi16(p + 8);
+ if ((rdSize & 0xF) != 0 || rdSize + 16 > _remSize)
+ return E_NOTIMPL;
+ memmove(p, p + 10, rdSize);
+ Byte *validData = p + rdSize + 16;
+ if (GetUi32(validData - 6) != 0) // reserved
+ return E_NOTIMPL;
+ UInt32 validSize = GetUi16(validData - 2);
+ if ((validSize & 0xF) != 0 || 16 + rdSize + validSize != _remSize)
+ return E_NOTIMPL;
+
+
+ {
+ RINOK(SetKey(_key.MasterKey, _key.KeySize));
+ RINOK(SetInitVector(_iv, 16));
+ Init();
+ Filter(p, rdSize);
+ }
+
+ Byte fileKey[32];
+ NSha1::CContext sha;
+ sha.Init();
+ sha.Update(_iv, 16);
+ sha.Update(p, rdSize - 16); // we don't use last 16 bytes (PAD bytes)
+ DeriveKey(sha, fileKey);
+
+ RINOK(SetKey(fileKey, _key.KeySize));
+ RINOK(SetInitVector(_iv, 16));
+ Init();
+ Filter(validData, validSize);
+
+ if (validSize < 4)
+ return E_NOTIMPL;
+ validSize -= 4;
+ if (GetUi32(validData + validSize) != CrcCalc(validData, validSize))
+ return S_OK;
+ passwOK = true;
+ Init();
+ return S_OK;
+}
+
+}}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipStrong.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipStrong.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipStrong.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Crypto/ZipStrong.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,47 @@
+// Crypto/ZipStrong.h
+
+#ifndef __CRYPTO_ZIP_STRONG_H
+#define __CRYPTO_ZIP_STRONG_H
+
+#include "Common/Buffer.h"
+
+#include "../IPassword.h"
+
+#include "MyAes.h"
+
+namespace NCrypto {
+namespace NZipStrong {
+
+struct CKeyInfo
+{
+ Byte MasterKey[32];
+ UInt32 KeySize;
+ void SetPassword(const Byte *data, UInt32 size);
+};
+
+class CBaseCoder:
+ public CAesCbcDecoder,
+ public ICryptoSetPassword
+{
+protected:
+ CKeyInfo _key;
+ CByteBuffer _buf;
+ Byte *_bufAligned;
+public:
+ STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size);
+};
+
+class CDecoder: public CBaseCoder
+{
+ UInt32 _ivSize;
+ Byte _iv[16];
+ UInt32 _remSize;
+public:
+ MY_UNKNOWN_IMP1(ICryptoSetPassword)
+ HRESULT ReadHeader(ISequentialInStream *inStream, UInt32 crc, UInt64 unpackSize);
+ HRESULT CheckPassword(bool &passwOK);
+};
+
+}}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Guid.txt
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Guid.txt?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Guid.txt (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/Guid.txt Sun Dec 16 23:23:25 2012
@@ -0,0 +1,170 @@
+{23170F69-40C1-278A-0000-00yy00xx0000}
+
+00 IProgress.h
+
+ 05 IProgress
+
+01 IFolderArchive.h
+
+ 05 IArchiveFolder
+ // 06 IInFolderArchive // old
+ 07 IFileExtractCallback.h::IFolderArchiveExtractCallback
+ 0A IOutFolderArchive
+ 0B IFolderArchiveUpdateCallback
+ 0C Agent.h::IArchiveFolderInternal
+ 0D
+ 0E IInFolderArchive
+
+03 IStream.h
+
+ 01 ISequentialInStream
+ 02 ISequentialOutStream
+ 03 IInStream
+ 04 IOutStream
+ 06 IStreamGetSize
+ 07 IOutStreamFlush
+
+
+04 ICoder.h
+
+ 04 ICompressProgressInfo
+ 05 ICompressCoder
+ 18 ICompressCoder2
+ 20 ICompressSetCoderProperties
+ 21 ICompressSetDecoderProperties //
+ 22 ICompressSetDecoderProperties2
+ 23 ICompressWriteCoderProperties
+ 24 ICompressGetInStreamProcessedSize
+ 25 ICompressSetCoderMt
+ 30 ICompressGetSubStreamSize
+ 31 ICompressSetInStream
+ 32 ICompressSetOutStream
+ 33 ICompressSetInStreamSize
+ 34 ICompressSetOutStreamSize
+ 35 ICompressSetBufSize
+ 40 ICompressFilter
+ 60 ICompressCodecsInfo
+ 61 ISetCompressCodecsInfo
+ 80 ICryptoProperties
+ 88 ICryptoResetSalt
+ 8C ICryptoResetInitVector
+ 90 ICryptoSetPassword
+ A0 ICryptoSetCRC
+
+
+05 IPassword.h
+
+ 10 ICryptoGetTextPassword
+ 11 ICryptoGetTextPassword2
+
+
+06 IArchive.h
+
+ 03 ISetProperties
+
+ 10 IArchiveOpenCallback
+ 20 IArchiveExtractCallback
+ 30 IArchiveOpenVolumeCallback
+ 40 IInArchiveGetStream
+ 50 IArchiveOpenSetSubArchiveName
+ 60 IInArchive
+ 61 IArchiveOpenSeq
+
+ 80 IArchiveUpdateCallback
+ 82 IArchiveUpdateCallback2
+ A0 IOutArchive
+
+
+
+08 IFolder.h
+
+ 00 IFolderFolder
+ 01 IEnumProperties
+ 02 IFolderGetTypeID
+ 03 IFolderGetPath
+ 04 IFolderWasChanged
+ 05 // IFolderReload
+ 06 IFolderOperations
+ 07 IFolderGetSystemIconIndex
+ 08 IFolderGetItemFullSize
+ 09 IFolderClone
+ 0A IFolderSetFlatMode
+ 0B IFolderOperationsExtractCallback
+ 0C //
+ 0D //
+ 0E IFolderProperties
+ 0F
+ 10 IFolderArcProps
+ 11 IGetFolderArcProps
+
+
+09 IFolder.h :: FOLDER_MANAGER_INTERFACE
+
+ 00 - 04 // old IFolderManager
+ 05 IFolderManager
+
+
+// 0A PluginInterface.h
+ 00 IInitContextMenu
+ 01 IPluginOptionsCallback
+ 02 IPluginOptions
+
+
+Handler GUIDs:
+
+{23170F69-40C1-278A-1000-000110xx0000}
+
+ 01 Zip
+ 02 BZip2
+ 03 Rar
+ 04 Arj
+ 05 Z
+ 06 Lzh
+ 07 7z
+ 08 Cab
+ 09 Nsis
+ 0A lzma
+ 0B lzma86
+ 0C xz
+ 0D ppmd
+
+ D2 SquashFS
+ D3 CramFS
+ D4 APM
+ D5 Mslz
+ D6 Flv
+ D7 Swf
+ D8 Swfc
+ D9 Ntfs
+ DA Fat
+ DB Mbr
+ DC Vhd
+ DD Pe
+ DE Elf
+ DF Mach-O
+ E0 Udf
+ E1 Xar
+ E2 Mub
+ E3 Hfs
+ E4 Dmg
+ E5 Compound
+ E6 Wim
+ E7 Iso
+ E8 Bkf
+ E9 Chm
+ EA Split
+ EB Rpm
+ EC Deb
+ ED Cpio
+ EE Tar
+ EF GZip
+
+{23170F69-40C1-278A-1000-000100030000} CAgentArchiveHandle
+{23170F69-40C1-278A-1000-000100020000} ContextMenu.h::CZipContextMenu
+
+{23170F69-40C1-278B- old codecs clsids
+
+{23170F69-40C1-278D-1000-000100020000} OptionsDialog.h::CLSID_CSevenZipOptions
+
+{23170F69-40C1-2790-id} Codec Decoders
+{23170F69-40C1-2791-id} Codec Encoders
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/ICoder.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/ICoder.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/ICoder.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/ICoder.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,186 @@
+// ICoder.h
+
+#ifndef __ICODER_H
+#define __ICODER_H
+
+#include "IStream.h"
+
+#define CODER_INTERFACE(i, x) DECL_INTERFACE(i, 4, x)
+
+CODER_INTERFACE(ICompressProgressInfo, 0x04)
+{
+ STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;
+};
+
+CODER_INTERFACE(ICompressCoder, 0x05)
+{
+ STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
+ const UInt64 *inSize, const UInt64 *outSize,
+ ICompressProgressInfo *progress) PURE;
+};
+
+CODER_INTERFACE(ICompressCoder2, 0x18)
+{
+ STDMETHOD(Code)(ISequentialInStream **inStreams, const UInt64 **inSizes, UInt32 numInStreams,
+ ISequentialOutStream **outStreams, const UInt64 **outSizes, UInt32 numOutStreams,
+ ICompressProgressInfo *progress) PURE;
+};
+
+namespace NCoderPropID
+{
+ enum EEnum
+ {
+ kDefaultProp = 0,
+ kDictionarySize,
+ kUsedMemorySize,
+ kOrder,
+ kBlockSize,
+ kPosStateBits,
+ kLitContextBits,
+ kLitPosBits,
+ kNumFastBytes,
+ kMatchFinder,
+ kMatchFinderCycles,
+ kNumPasses,
+ kAlgorithm,
+ kNumThreads,
+ kEndMarker
+ };
+}
+
+CODER_INTERFACE(ICompressSetCoderProperties, 0x20)
+{
+ STDMETHOD(SetCoderProperties)(const PROPID *propIDs, const PROPVARIANT *props, UInt32 numProps) PURE;
+};
+
+/*
+CODER_INTERFACE(ICompressSetCoderProperties, 0x21)
+{
+ STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;
+};
+*/
+
+CODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)
+{
+ STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;
+};
+
+CODER_INTERFACE(ICompressWriteCoderProperties, 0x23)
+{
+ STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream) PURE;
+};
+
+CODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)
+{
+ STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;
+};
+
+CODER_INTERFACE(ICompressSetCoderMt, 0x25)
+{
+ STDMETHOD(SetNumberOfThreads)(UInt32 numThreads) PURE;
+};
+
+CODER_INTERFACE(ICompressGetSubStreamSize, 0x30)
+{
+ STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;
+};
+
+CODER_INTERFACE(ICompressSetInStream, 0x31)
+{
+ STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;
+ STDMETHOD(ReleaseInStream)() PURE;
+};
+
+CODER_INTERFACE(ICompressSetOutStream, 0x32)
+{
+ STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;
+ STDMETHOD(ReleaseOutStream)() PURE;
+};
+
+CODER_INTERFACE(ICompressSetInStreamSize, 0x33)
+{
+ STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;
+};
+
+CODER_INTERFACE(ICompressSetOutStreamSize, 0x34)
+{
+ STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;
+};
+
+CODER_INTERFACE(ICompressSetBufSize, 0x35)
+{
+ STDMETHOD(SetInBufSize)(UInt32 streamIndex, UInt32 size) PURE;
+ STDMETHOD(SetOutBufSize)(UInt32 streamIndex, UInt32 size) PURE;
+};
+
+CODER_INTERFACE(ICompressFilter, 0x40)
+{
+ STDMETHOD(Init)() PURE;
+ STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;
+ // Filter converts as most as possible bytes
+ // Filter return outSize (UInt32)
+ // if (outSize <= size): Filter have converted outSize bytes
+ // if (outSize > size): Filter have not converted anything.
+ // and it needs at least outSize bytes to convert one block
+ // (it's for crypto block algorithms).
+};
+
+CODER_INTERFACE(ICompressCodecsInfo, 0x60)
+{
+ STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods) PURE;
+ STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value) PURE;
+ STDMETHOD(CreateDecoder)(UInt32 index, const GUID *iid, void **coder) PURE;
+ STDMETHOD(CreateEncoder)(UInt32 index, const GUID *iid, void **coder) PURE;
+};
+CODER_INTERFACE(ISetCompressCodecsInfo, 0x61)
+{
+ STDMETHOD(SetCompressCodecsInfo)(ICompressCodecsInfo *compressCodecsInfo) PURE;
+};
+
+CODER_INTERFACE(ICryptoProperties, 0x80)
+{
+ STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;
+ STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;
+};
+
+/*
+CODER_INTERFACE(ICryptoResetSalt, 0x88)
+{
+ STDMETHOD(ResetSalt)() PURE;
+};
+*/
+
+CODER_INTERFACE(ICryptoResetInitVector, 0x8C)
+{
+ STDMETHOD(ResetInitVector)() PURE;
+};
+
+CODER_INTERFACE(ICryptoSetPassword, 0x90)
+{
+ STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;
+};
+
+CODER_INTERFACE(ICryptoSetCRC, 0xA0)
+{
+ STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;
+};
+
+//////////////////////
+// It's for DLL file
+namespace NMethodPropID
+{
+ enum EEnum
+ {
+ kID,
+ kName,
+ kDecoder,
+ kEncoder,
+ kInStreams,
+ kOutStreams,
+ kDescription,
+ kDecoderIsAssigned,
+ kEncoderIsAssigned
+ };
+}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IDecl.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IDecl.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IDecl.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IDecl.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,15 @@
+// IDecl.h
+
+#ifndef __IDECL_H
+#define __IDECL_H
+
+#include "../Common/MyUnknown.h"
+
+#define DECL_INTERFACE_SUB(i, base, groupId, subId) \
+DEFINE_GUID(IID_ ## i, \
+0x23170F69, 0x40C1, 0x278A, 0, 0, 0, (groupId), 0, (subId), 0, 0); \
+struct i: public base
+
+#define DECL_INTERFACE(i, groupId, subId) DECL_INTERFACE_SUB(i, IUnknown, groupId, subId)
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IPassword.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IPassword.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IPassword.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IPassword.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,24 @@
+// IPassword.h
+
+#ifndef __IPASSWORD_H
+#define __IPASSWORD_H
+
+#include "../Common/MyUnknown.h"
+#include "../Common/Types.h"
+
+#include "IDecl.h"
+
+#define PASSWORD_INTERFACE(i, x) DECL_INTERFACE(i, 5, x)
+
+PASSWORD_INTERFACE(ICryptoGetTextPassword, 0x10)
+{
+ STDMETHOD(CryptoGetTextPassword)(BSTR *password) PURE;
+};
+
+PASSWORD_INTERFACE(ICryptoGetTextPassword2, 0x11)
+{
+ STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password) PURE;
+};
+
+#endif
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IProgress.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IProgress.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IProgress.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IProgress.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,33 @@
+// Interface/IProgress.h
+
+#ifndef __IPROGRESS_H
+#define __IPROGRESS_H
+
+#include "../Common/MyUnknown.h"
+#include "../Common/Types.h"
+
+#include "IDecl.h"
+
+#define INTERFACE_IProgress(x) \
+ STDMETHOD(SetTotal)(UInt64 total) x; \
+ STDMETHOD(SetCompleted)(const UInt64 *completeValue) x; \
+
+DECL_INTERFACE(IProgress, 0, 5)
+{
+ INTERFACE_IProgress(PURE)
+};
+
+/*
+// {23170F69-40C1-278A-0000-000000050002}
+DEFINE_GUID(IID_IProgress2,
+0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x02);
+MIDL_INTERFACE("23170F69-40C1-278A-0000-000000050002")
+IProgress2: public IUnknown
+{
+public:
+ STDMETHOD(SetTotal)(const UInt64 *total) PURE;
+ STDMETHOD(SetCompleted)(const UInt64 *completeValue) PURE;
+};
+*/
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IStream.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IStream.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IStream.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/IStream.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,58 @@
+// IStream.h
+
+#ifndef __ISTREAM_H
+#define __ISTREAM_H
+
+#include "../Common/MyUnknown.h"
+#include "../Common/Types.h"
+
+#include "IDecl.h"
+
+#define STREAM_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 3, x)
+#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)
+
+STREAM_INTERFACE(ISequentialInStream, 0x01)
+{
+ STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;
+ /*
+ Out: if size != 0, return_value = S_OK and (*processedSize == 0),
+ then there are no more bytes in stream.
+ if (size > 0) && there are bytes in stream,
+ this function must read at least 1 byte.
+ This function is allowed to read less than number of remaining bytes in stream.
+ You must call Read function in loop, if you need exact amount of data
+ */
+};
+
+STREAM_INTERFACE(ISequentialOutStream, 0x02)
+{
+ STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;
+ /*
+ if (size > 0) this function must write at least 1 byte.
+ This function is allowed to write less than "size".
+ You must call Write function in loop, if you need to write exact amount of data
+ */
+};
+
+STREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)
+{
+ STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;
+};
+
+STREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)
+{
+ STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;
+ STDMETHOD(SetSize)(UInt64 newSize) PURE;
+};
+
+STREAM_INTERFACE(IStreamGetSize, 0x06)
+{
+ STDMETHOD(GetSize)(UInt64 *size) PURE;
+};
+
+STREAM_INTERFACE(IOutStreamFlush, 0x07)
+{
+ STDMETHOD(Flush)() PURE;
+};
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/MyVersion.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/MyVersion.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/MyVersion.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/MyVersion.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,11 @@
+#define MY_VER_MAJOR 9
+#define MY_VER_MINOR 20
+#define MY_VER_BUILD 0
+#define MY_VERSION "9.20"
+#define MY_7ZIP_VERSION "7-Zip 9.20"
+#define MY_DATE "2010-11-18"
+#define MY_COPYRIGHT "Copyright (c) 1999-2010 Igor Pavlov"
+#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " " MY_DATE
+
+#define P7ZIP_VERSION "9.20"
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PREMAKE/generate.sh
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PREMAKE/generate.sh?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PREMAKE/generate.sh (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PREMAKE/generate.sh Sun Dec 16 23:23:25 2012
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+set -x
+
+doit()
+{
+ rm -fr P7ZIP.$1
+ mkdir P7ZIP.$1
+ cd P7ZIP.$1
+ cp ../premake4.lua premake4.lua
+ ${HOME}/PREMAKE/premake4 $1
+ cd ..
+}
+
+doit codeblocks
+doit codelite
+doit gmake
+
Propchange: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PREMAKE/generate.sh
------------------------------------------------------------------------------
svn:executable = *
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PREMAKE/premake4.lua
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PREMAKE/premake4.lua?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PREMAKE/premake4.lua (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PREMAKE/premake4.lua Sun Dec 16 23:23:25 2012
@@ -0,0 +1,263 @@
+-- A solution contains projects, and defines the available configurations
+solution "p7zip"
+ configurations { "Debug", "Release" }
+
+-- includes for all projects
+ includedirs {
+ "../../../myWindows",
+ "../../../",
+ "../../../include_windows"
+ }
+
+ configuration "Debug"
+ defines { "DEBUG", "_FILE_OFFSET_BITS=64", "_LARGEFILE_SOURCE", "_REENTRANT", "ENV_UNIX", "BREAK_HANDLER", "UNICODE", "_UNICODE" }
+ flags { "Symbols" }
+
+ configuration "Release"
+ defines { "NDEBUG", "_FILE_OFFSET_BITS=64", "_LARGEFILE_SOURCE", "_REENTRANT", "ENV_UNIX", "BREAK_HANDLER", "UNICODE", "_UNICODE" }
+ flags { "Optimize" }
+
+---------------------------------
+ project "all_c_code"
+ kind "StaticLib"
+ language "C"
+ files {
+ "../../../../C/Aes.c",
+ "../../../../C/7zStream.c",
+ "../../../../C/Alloc.c",
+ "../../../../C/Bra.c",
+ "../../../../C/Bra86.c",
+ "../../../../C/BraIA64.c",
+ "../../../../C/BwtSort.c",
+ "../../../../C/Delta.c",
+ "../../../../C/HuffEnc.c",
+ "../../../../C/LzFind.c",
+ "../../../../C/LzFindMt.c",
+ "../../../../C/Lzma2Dec.c",
+ "../../../../C/Lzma2Enc.c",
+ "../../../../C/LzmaDec.c",
+ "../../../../C/LzmaEnc.c",
+ "../../../../C/MtCoder.c",
+ "../../../../C/Ppmd7.c",
+ "../../../../C/Ppmd7Dec.c",
+ "../../../../C/Ppmd7Enc.c",
+ "../../../../C/Ppmd8.c",
+ "../../../../C/Ppmd8Dec.c",
+ "../../../../C/Ppmd8Enc.c",
+ "../../../../C/Sha256.c",
+ "../../../../C/Sort.c",
+ "../../../../C/Threads.c",
+ "../../../../C/Xz.c",
+ "../../../../C/XzCrc64.c",
+ "../../../../C/XzDec.c",
+ "../../../../C/XzEnc.c",
+ "../../../../C/XzIn.c",
+
+ "../../../../C/7zCrc.c",
+ "../../../../C/7zCrcOpt.c"
+ }
+
+---------------------------------
+ project "7za"
+ kind "ConsoleApp"
+ language "C++"
+ files {
+ "../../../myWindows/myGetTickCount.cpp",
+ "../../../myWindows/wine_date_and_time.cpp",
+ "../../../myWindows/myAddExeFlag.cpp",
+ "../../../myWindows/mySplitCommandLine.cpp",
+
+ "../../UI/Console/BenchCon.cpp",
+ "../../UI/Console/ConsoleClose.cpp",
+ "../../UI/Console/ExtractCallbackConsole.cpp",
+ "../../UI/Console/List.cpp",
+ "../../UI/Console/Main.cpp",
+ "../../UI/Console/MainAr.cpp",
+ "../../UI/Console/OpenCallbackConsole.cpp",
+ "../../UI/Console/PercentPrinter.cpp",
+ "../../UI/Console/UpdateCallbackConsole.cpp",
+ "../../UI/Console/UserInputUtils.cpp",
+
+ "../../../Common/CommandLineParser.cpp",
+ "../../../Common/CRC.cpp",
+ "../../../Common/IntToString.cpp",
+ "../../../Common/ListFileUtils.cpp",
+ "../../../Common/StdInStream.cpp",
+ "../../../Common/StdOutStream.cpp",
+ "../../../Common/MyString.cpp",
+ "../../../Common/MyWindows.cpp",
+ "../../../Common/StringConvert.cpp",
+ "../../../Common/StringToInt.cpp",
+ "../../../Common/UTFConvert.cpp",
+ "../../../Common/MyVector.cpp",
+ "../../../Common/Wildcard.cpp",
+
+ "../../../Windows/Error.cpp",
+ "../../../Windows/FileDir.cpp",
+ "../../../Windows/FileFind.cpp",
+ "../../../Windows/FileIO.cpp",
+ "../../../Windows/FileName.cpp",
+ "../../../Windows/PropVariant.cpp",
+ "../../../Windows/PropVariantConversions.cpp",
+ "../../../Windows/Synchronization.cpp",
+ "../../../Windows/System.cpp",
+ "../../../Windows/Time.cpp",
+
+ "../../Common/CreateCoder.cpp",
+ "../../Common/CWrappers.cpp",
+ "../../Common/FilePathAutoRename.cpp",
+ "../../Common/FileStreams.cpp",
+ "../../Common/FilterCoder.cpp",
+ "../../Common/InBuffer.cpp",
+ "../../Common/InOutTempBuffer.cpp",
+ "../../Common/LimitedStreams.cpp",
+ "../../Common/LockedStream.cpp",
+ "../../Common/MemBlocks.cpp",
+ "../../Common/MethodId.cpp",
+ "../../Common/MethodProps.cpp",
+ "../../Common/OffsetStream.cpp",
+ "../../Common/OutBuffer.cpp",
+ "../../Common/OutMemStream.cpp",
+ "../../Common/ProgressMt.cpp",
+ "../../Common/ProgressUtils.cpp",
+ "../../Common/StreamBinder.cpp",
+ "../../Common/StreamObjects.cpp",
+ "../../Common/StreamUtils.cpp",
+ "../../Common/VirtThread.cpp",
+
+ "../../UI/Common/ArchiveCommandLine.cpp",
+ "../../UI/Common/ArchiveExtractCallback.cpp",
+ "../../UI/Common/ArchiveOpenCallback.cpp",
+ "../../UI/Common/Bench.cpp",
+ "../../UI/Common/DefaultName.cpp",
+ "../../UI/Common/EnumDirItems.cpp",
+ "../../UI/Common/Extract.cpp",
+ "../../UI/Common/ExtractingFilePath.cpp",
+ "../../UI/Common/LoadCodecs.cpp",
+ "../../UI/Common/OpenArchive.cpp",
+ "../../UI/Common/PropIDUtils.cpp",
+ "../../UI/Common/SetProperties.cpp",
+ "../../UI/Common/SortUtils.cpp",
+ "../../UI/Common/TempFiles.cpp",
+ "../../UI/Common/Update.cpp",
+ "../../UI/Common/UpdateAction.cpp",
+ "../../UI/Common/UpdateCallback.cpp",
+ "../../UI/Common/UpdatePair.cpp",
+ "../../UI/Common/UpdateProduce.cpp",
+
+ "../../Archive/Bz2Handler.cpp",
+ "../../Archive/DeflateProps.cpp",
+ "../../Archive/GzHandler.cpp",
+ "../../Archive/LzmaHandler.cpp",
+ "../../Archive/PpmdHandler.cpp",
+ "../../Archive/SplitHandler.cpp",
+ "../../Archive/XzHandler.cpp",
+ "../../Archive/ZHandler.cpp",
+
+ "../../Archive/Common/CoderMixer2.cpp",
+ "../../Archive/Common/CoderMixer2MT.cpp",
+ "../../Archive/Common/CrossThreadProgress.cpp",
+ "../../Archive/Common/DummyOutStream.cpp",
+ "../../Archive/Common/FindSignature.cpp",
+ "../../Archive/Common/HandlerOut.cpp",
+ "../../Archive/Common/InStreamWithCRC.cpp",
+ "../../Archive/Common/ItemNameUtils.cpp",
+ "../../Archive/Common/MultiStream.cpp",
+ "../../Archive/Common/OutStreamWithCRC.cpp",
+ "../../Archive/Common/ParseProperties.cpp",
+
+ "../../Archive/7z/7zCompressionMode.cpp",
+ "../../Archive/7z/7zDecode.cpp",
+ "../../Archive/7z/7zEncode.cpp",
+ "../../Archive/7z/7zExtract.cpp",
+ "../../Archive/7z/7zFolderInStream.cpp",
+ "../../Archive/7z/7zFolderOutStream.cpp",
+ "../../Archive/7z/7zHandler.cpp",
+ "../../Archive/7z/7zHandlerOut.cpp",
+ "../../Archive/7z/7zHeader.cpp",
+ "../../Archive/7z/7zIn.cpp",
+ "../../Archive/7z/7zOut.cpp",
+ "../../Archive/7z/7zProperties.cpp",
+ "../../Archive/7z/7zSpecStream.cpp",
+ "../../Archive/7z/7zUpdate.cpp",
+ "../../Archive/7z/7zRegister.cpp",
+
+ "../../Archive/Cab/CabBlockInStream.cpp",
+ "../../Archive/Cab/CabHandler.cpp",
+ "../../Archive/Cab/CabHeader.cpp",
+ "../../Archive/Cab/CabIn.cpp",
+ "../../Archive/Cab/CabRegister.cpp",
+
+ "../../Archive/Tar/TarHandler.cpp",
+ "../../Archive/Tar/TarHandlerOut.cpp",
+ "../../Archive/Tar/TarHeader.cpp",
+ "../../Archive/Tar/TarIn.cpp",
+ "../../Archive/Tar/TarOut.cpp",
+ "../../Archive/Tar/TarRegister.cpp",
+ "../../Archive/Tar/TarUpdate.cpp",
+
+ "../../Archive/Zip/ZipAddCommon.cpp",
+ "../../Archive/Zip/ZipHandler.cpp",
+ "../../Archive/Zip/ZipHandlerOut.cpp",
+ "../../Archive/Zip/ZipHeader.cpp",
+ "../../Archive/Zip/ZipIn.cpp",
+ "../../Archive/Zip/ZipItem.cpp",
+ "../../Archive/Zip/ZipOut.cpp",
+ "../../Archive/Zip/ZipUpdate.cpp",
+ "../../Archive/Zip/ZipRegister.cpp",
+
+ "../../Compress/Bcj2Coder.cpp",
+ "../../Compress/Bcj2Register.cpp",
+ "../../Compress/BcjCoder.cpp",
+ "../../Compress/BcjRegister.cpp",
+ "../../Compress/BitlDecoder.cpp",
+ "../../Compress/BranchCoder.cpp",
+ "../../Compress/BranchMisc.cpp",
+ "../../Compress/BranchRegister.cpp",
+ "../../Compress/ByteSwap.cpp",
+ "../../Compress/BZip2Crc.cpp",
+ "../../Compress/BZip2Decoder.cpp",
+ "../../Compress/BZip2Encoder.cpp",
+ "../../Compress/BZip2Register.cpp",
+ "../../Compress/CopyCoder.cpp",
+ "../../Compress/CopyRegister.cpp",
+ "../../Compress/Deflate64Register.cpp",
+ "../../Compress/DeflateDecoder.cpp",
+ "../../Compress/DeflateEncoder.cpp",
+ "../../Compress/DeflateRegister.cpp",
+ "../../Compress/DeltaFilter.cpp",
+ "../../Compress/ImplodeDecoder.cpp",
+ "../../Compress/ImplodeHuffmanDecoder.cpp",
+ "../../Compress/Lzma2Decoder.cpp",
+ "../../Compress/Lzma2Encoder.cpp",
+ "../../Compress/Lzma2Register.cpp",
+ "../../Compress/LzmaDecoder.cpp",
+ "../../Compress/LzmaEncoder.cpp",
+ "../../Compress/LzmaRegister.cpp",
+ "../../Compress/LzOutWindow.cpp",
+ "../../Compress/Lzx86Converter.cpp",
+ "../../Compress/LzxDecoder.cpp",
+ "../../Compress/PpmdDecoder.cpp",
+ "../../Compress/PpmdEncoder.cpp",
+ "../../Compress/PpmdRegister.cpp",
+ "../../Compress/PpmdZip.cpp",
+ "../../Compress/QuantumDecoder.cpp",
+ "../../Compress/ShrinkDecoder.cpp",
+ "../../Compress/ZDecoder.cpp",
+
+ "../../Crypto/7zAes.cpp",
+ "../../Crypto/7zAesRegister.cpp",
+ "../../Crypto/HmacSha1.cpp",
+ "../../Crypto/MyAes.cpp",
+ "../../Crypto/Pbkdf2HmacSha1.cpp",
+ "../../Crypto/RandGen.cpp",
+ "../../Crypto/Sha1.cpp",
+ "../../Crypto/WzAes.cpp",
+ "../../Crypto/ZipCrypto.cpp",
+ "../../Crypto/ZipStrong.cpp"
+
+ }
+
+ configuration "linux"
+ links { "all_c_code", "pthread" }
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PropID.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PropID.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PropID.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/PropID.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,76 @@
+// PropID.h
+
+#ifndef __7ZIP_PROPID_H
+#define __7ZIP_PROPID_H
+
+enum
+{
+ kpidNoProperty = 0,
+ kpidMainSubfile = 1,
+ kpidHandlerItemIndex = 2,
+ kpidPath,
+ kpidName,
+ kpidExtension,
+ kpidIsDir,
+ kpidSize,
+ kpidPackSize,
+ kpidAttrib,
+ kpidCTime,
+ kpidATime,
+ kpidMTime,
+ kpidSolid,
+ kpidCommented,
+ kpidEncrypted,
+ kpidSplitBefore,
+ kpidSplitAfter,
+ kpidDictionarySize,
+ kpidCRC,
+ kpidType,
+ kpidIsAnti,
+ kpidMethod,
+ kpidHostOS,
+ kpidFileSystem,
+ kpidUser,
+ kpidGroup,
+ kpidBlock,
+ kpidComment,
+ kpidPosition,
+ kpidPrefix,
+ kpidNumSubDirs,
+ kpidNumSubFiles,
+ kpidUnpackVer,
+ kpidVolume,
+ kpidIsVolume,
+ kpidOffset,
+ kpidLinks,
+ kpidNumBlocks,
+ kpidNumVolumes,
+ kpidTimeType,
+ kpidBit64,
+ kpidBigEndian,
+ kpidCpu,
+ kpidPhySize,
+ kpidHeadersSize,
+ kpidChecksum,
+ kpidCharacts,
+ kpidVa,
+ kpidId,
+ kpidShortName,
+ kpidCreatorApp,
+ kpidSectorSize,
+ kpidPosixAttrib,
+ kpidLink,
+ kpidError,
+
+ kpidTotalSize = 0x1100,
+ kpidFreeSpace,
+ kpidClusterSize,
+ kpidVolumeName,
+
+ kpidLocalName = 0x1200,
+ kpidProvider,
+
+ kpidUserDefined = 0x10000
+};
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/7ZA/7ZA.pro
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/7ZA/7ZA.pro?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/7ZA/7ZA.pro (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/7ZA/7ZA.pro Sun Dec 16 23:23:25 2012
@@ -0,0 +1,228 @@
+
+QT -= core \
+ gui
+TARGET = 7za.x
+CONFIG += console
+CONFIG -= app_bundle
+TEMPLATE = app
+SOURCES += \
+ ../../../myWindows/myGetTickCount.cpp \
+ ../../../myWindows/wine_date_and_time.cpp \
+ ../../../myWindows/myAddExeFlag.cpp \
+ ../../../myWindows/mySplitCommandLine.cpp \
+ ../../UI/Console/BenchCon.cpp \
+ ../../UI/Console/ConsoleClose.cpp \
+ ../../UI/Console/ExtractCallbackConsole.cpp \
+ ../../UI/Console/List.cpp \
+ ../../UI/Console/Main.cpp \
+ ../../UI/Console/MainAr.cpp \
+ ../../UI/Console/OpenCallbackConsole.cpp \
+ ../../UI/Console/PercentPrinter.cpp \
+ ../../UI/Console/UpdateCallbackConsole.cpp \
+ ../../UI/Console/UserInputUtils.cpp \
+\
+ ../../../Common/CommandLineParser.cpp \
+ ../../../Common/CRC.cpp \
+ ../../../Common/IntToString.cpp \
+ ../../../Common/ListFileUtils.cpp \
+ ../../../Common/StdInStream.cpp \
+ ../../../Common/StdOutStream.cpp \
+ ../../../Common/MyString.cpp \
+ ../../../Common/MyWindows.cpp \
+ ../../../Common/StringConvert.cpp \
+ ../../../Common/StringToInt.cpp \
+ ../../../Common/UTFConvert.cpp \
+ ../../../Common/MyVector.cpp \
+ ../../../Common/Wildcard.cpp \
+ ../../../Windows/Error.cpp \
+ ../../../Windows/FileDir.cpp \
+ ../../../Windows/FileFind.cpp \
+ ../../../Windows/FileIO.cpp \
+ ../../../Windows/FileName.cpp \
+ ../../../Windows/PropVariant.cpp \
+ ../../../Windows/PropVariantConversions.cpp \
+ ../../../Windows/Synchronization.cpp \
+ ../../../Windows/System.cpp \
+ ../../../Windows/Time.cpp \
+ ../../Common/CreateCoder.cpp \
+ ../../Common/CWrappers.cpp \
+ ../../Common/FilePathAutoRename.cpp \
+ ../../Common/FileStreams.cpp \
+ ../../Common/FilterCoder.cpp \
+ ../../Common/InBuffer.cpp \
+ ../../Common/InOutTempBuffer.cpp \
+ ../../Common/LimitedStreams.cpp \
+ ../../Common/LockedStream.cpp \
+ ../../Common/MemBlocks.cpp \
+ ../../Common/MethodId.cpp \
+ ../../Common/MethodProps.cpp \
+ ../../Common/OffsetStream.cpp \
+ ../../Common/OutBuffer.cpp \
+ ../../Common/OutMemStream.cpp \
+ ../../Common/ProgressMt.cpp \
+ ../../Common/ProgressUtils.cpp \
+ ../../Common/StreamBinder.cpp \
+ ../../Common/StreamObjects.cpp \
+ ../../Common/StreamUtils.cpp \
+ ../../Common/VirtThread.cpp \
+ ../../UI/Common/ArchiveCommandLine.cpp \
+ ../../UI/Common/ArchiveExtractCallback.cpp \
+ ../../UI/Common/ArchiveOpenCallback.cpp \
+ ../../UI/Common/Bench.cpp \
+ ../../UI/Common/DefaultName.cpp \
+ ../../UI/Common/EnumDirItems.cpp \
+ ../../UI/Common/Extract.cpp \
+ ../../UI/Common/ExtractingFilePath.cpp \
+ ../../UI/Common/LoadCodecs.cpp \
+ ../../UI/Common/OpenArchive.cpp \
+ ../../UI/Common/PropIDUtils.cpp \
+ ../../UI/Common/SetProperties.cpp \
+ ../../UI/Common/SortUtils.cpp \
+ ../../UI/Common/TempFiles.cpp \
+ ../../UI/Common/Update.cpp \
+ ../../UI/Common/UpdateAction.cpp \
+ ../../UI/Common/UpdateCallback.cpp \
+ ../../UI/Common/UpdatePair.cpp \
+ ../../UI/Common/UpdateProduce.cpp \
+ ../../Archive/Bz2Handler.cpp \
+ ../../Archive/DeflateProps.cpp \
+ ../../Archive/GzHandler.cpp \
+ ../../Archive/LzmaHandler.cpp \
+ ../../Archive/PpmdHandler.cpp \
+ ../../Archive/SplitHandler.cpp \
+ ../../Archive/XzHandler.cpp \
+ ../../Archive/ZHandler.cpp \
+ ../../Archive/Common/CoderMixer2.cpp \
+ ../../Archive/Common/CoderMixer2MT.cpp \
+ ../../Archive/Common/CrossThreadProgress.cpp \
+ ../../Archive/Common/DummyOutStream.cpp \
+ ../../Archive/Common/FindSignature.cpp \
+ ../../Archive/Common/HandlerOut.cpp \
+ ../../Archive/Common/InStreamWithCRC.cpp \
+ ../../Archive/Common/ItemNameUtils.cpp \
+ ../../Archive/Common/MultiStream.cpp \
+ ../../Archive/Common/OutStreamWithCRC.cpp \
+ ../../Archive/Common/ParseProperties.cpp \
+ ../../Archive/7z/7zCompressionMode.cpp \
+ ../../Archive/7z/7zDecode.cpp \
+ ../../Archive/7z/7zEncode.cpp \
+ ../../Archive/7z/7zExtract.cpp \
+ ../../Archive/7z/7zFolderInStream.cpp \
+ ../../Archive/7z/7zFolderOutStream.cpp \
+ ../../Archive/7z/7zHandler.cpp \
+ ../../Archive/7z/7zHandlerOut.cpp \
+ ../../Archive/7z/7zHeader.cpp \
+ ../../Archive/7z/7zIn.cpp \
+ ../../Archive/7z/7zOut.cpp \
+ ../../Archive/7z/7zProperties.cpp \
+ ../../Archive/7z/7zSpecStream.cpp \
+ ../../Archive/7z/7zUpdate.cpp \
+ ../../Archive/7z/7zRegister.cpp \
+ ../../Archive/Cab/CabBlockInStream.cpp \
+ ../../Archive/Cab/CabHandler.cpp \
+ ../../Archive/Cab/CabHeader.cpp \
+ ../../Archive/Cab/CabIn.cpp \
+ ../../Archive/Cab/CabRegister.cpp \
+ ../../Archive/Tar/TarHandler.cpp \
+ ../../Archive/Tar/TarHandlerOut.cpp \
+ ../../Archive/Tar/TarHeader.cpp \
+ ../../Archive/Tar/TarIn.cpp \
+ ../../Archive/Tar/TarOut.cpp \
+ ../../Archive/Tar/TarRegister.cpp \
+ ../../Archive/Tar/TarUpdate.cpp \
+ ../../Archive/Zip/ZipAddCommon.cpp \
+ ../../Archive/Zip/ZipHandler.cpp \
+ ../../Archive/Zip/ZipHandlerOut.cpp \
+ ../../Archive/Zip/ZipHeader.cpp \
+ ../../Archive/Zip/ZipIn.cpp \
+ ../../Archive/Zip/ZipItem.cpp \
+ ../../Archive/Zip/ZipOut.cpp \
+ ../../Archive/Zip/ZipUpdate.cpp \
+ ../../Archive/Zip/ZipRegister.cpp \
+ ../../Compress/Bcj2Coder.cpp \
+ ../../Compress/Bcj2Register.cpp \
+ ../../Compress/BcjCoder.cpp \
+ ../../Compress/BcjRegister.cpp \
+ ../../Compress/BitlDecoder.cpp \
+ ../../Compress/BranchCoder.cpp \
+ ../../Compress/BranchMisc.cpp \
+ ../../Compress/BranchRegister.cpp \
+ ../../Compress/ByteSwap.cpp \
+ ../../Compress/BZip2Crc.cpp \
+ ../../Compress/BZip2Decoder.cpp \
+ ../../Compress/BZip2Encoder.cpp \
+ ../../Compress/BZip2Register.cpp \
+ ../../Compress/CopyCoder.cpp \
+ ../../Compress/CopyRegister.cpp \
+ ../../Compress/Deflate64Register.cpp \
+ ../../Compress/DeflateDecoder.cpp \
+ ../../Compress/DeflateEncoder.cpp \
+ ../../Compress/DeflateRegister.cpp \
+ ../../Compress/DeltaFilter.cpp \
+ ../../Compress/ImplodeDecoder.cpp \
+ ../../Compress/ImplodeHuffmanDecoder.cpp \
+ ../../Compress/Lzma2Decoder.cpp \
+ ../../Compress/Lzma2Encoder.cpp \
+ ../../Compress/Lzma2Register.cpp \
+ ../../Compress/LzmaDecoder.cpp \
+ ../../Compress/LzmaEncoder.cpp \
+ ../../Compress/LzmaRegister.cpp \
+ ../../Compress/LzOutWindow.cpp \
+ ../../Compress/Lzx86Converter.cpp \
+ ../../Compress/LzxDecoder.cpp \
+ ../../Compress/PpmdDecoder.cpp \
+ ../../Compress/PpmdEncoder.cpp \
+ ../../Compress/PpmdRegister.cpp \
+ ../../Compress/PpmdZip.cpp \
+ ../../Compress/QuantumDecoder.cpp \
+ ../../Compress/ShrinkDecoder.cpp \
+ ../../Compress/ZDecoder.cpp \
+ ../../Crypto/7zAes.cpp \
+ ../../Crypto/7zAesRegister.cpp \
+ ../../Crypto/HmacSha1.cpp \
+ ../../Crypto/MyAes.cpp \
+ ../../Crypto/Pbkdf2HmacSha1.cpp \
+ ../../Crypto/RandGen.cpp \
+ ../../Crypto/Sha1.cpp \
+ ../../Crypto/WzAes.cpp \
+ ../../Crypto/ZipCrypto.cpp \
+ ../../Crypto/ZipStrong.cpp \
+ ../../../../C/Aes.c \
+ ../../../../C/7zStream.c \
+ ../../../../C/Alloc.c \
+ ../../../../C/Bra.c \
+ ../../../../C/Bra86.c \
+ ../../../../C/BraIA64.c \
+ ../../../../C/BwtSort.c \
+ ../../../../C/Delta.c \
+ ../../../../C/HuffEnc.c \
+ ../../../../C/LzFind.c \
+ ../../../../C/LzFindMt.c \
+ ../../../../C/Lzma2Dec.c \
+ ../../../../C/Lzma2Enc.c \
+ ../../../../C/LzmaDec.c \
+ ../../../../C/LzmaEnc.c \
+ ../../../../C/MtCoder.c \
+ ../../../../C/Ppmd7.c \
+ ../../../../C/Ppmd7Dec.c \
+ ../../../../C/Ppmd7Enc.c \
+ ../../../../C/Ppmd8.c \
+ ../../../../C/Ppmd8Dec.c \
+ ../../../../C/Ppmd8Enc.c \
+ ../../../../C/Sha256.c \
+ ../../../../C/Sort.c \
+ ../../../../C/Threads.c \
+ ../../../../C/Xz.c \
+ ../../../../C/XzCrc64.c \
+ ../../../../C/XzDec.c \
+ ../../../../C/XzEnc.c \
+ ../../../../C/XzIn.c \
+ ../../../../C/7zCrc.c \
+ ../../../../C/7zCrcOpt.c
+
+
+INCLUDEPATH = ../../../myWindows \
+ ../../../ \
+ ../../../include_windows
+
+DEFINES += _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE NDEBUG _REENTRANT ENV_UNIX BREAK_HANDLER UNICODE _UNICODE
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/7ZA/7ZA_osx.pro
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/7ZA/7ZA_osx.pro?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/7ZA/7ZA_osx.pro (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/7ZA/7ZA_osx.pro Sun Dec 16 23:23:25 2012
@@ -0,0 +1,228 @@
+
+QT -= core \
+ gui
+TARGET = 7za.x
+CONFIG += console
+CONFIG -= app_bundle
+TEMPLATE = app
+SOURCES += \
+ ../../../myWindows/myGetTickCount.cpp \
+ ../../../myWindows/wine_date_and_time.cpp \
+ ../../../myWindows/myAddExeFlag.cpp \
+ ../../../myWindows/mySplitCommandLine.cpp \
+ ../../UI/Console/BenchCon.cpp \
+ ../../UI/Console/ConsoleClose.cpp \
+ ../../UI/Console/ExtractCallbackConsole.cpp \
+ ../../UI/Console/List.cpp \
+ ../../UI/Console/Main.cpp \
+ ../../UI/Console/MainAr.cpp \
+ ../../UI/Console/OpenCallbackConsole.cpp \
+ ../../UI/Console/PercentPrinter.cpp \
+ ../../UI/Console/UpdateCallbackConsole.cpp \
+ ../../UI/Console/UserInputUtils.cpp \
+\
+ ../../../Common/CommandLineParser.cpp \
+ ../../../Common/CRC.cpp \
+ ../../../Common/IntToString.cpp \
+ ../../../Common/ListFileUtils.cpp \
+ ../../../Common/StdInStream.cpp \
+ ../../../Common/StdOutStream.cpp \
+ ../../../Common/MyString.cpp \
+ ../../../Common/MyWindows.cpp \
+ ../../../Common/StringConvert.cpp \
+ ../../../Common/StringToInt.cpp \
+ ../../../Common/UTFConvert.cpp \
+ ../../../Common/MyVector.cpp \
+ ../../../Common/Wildcard.cpp \
+ ../../../Windows/Error.cpp \
+ ../../../Windows/FileDir.cpp \
+ ../../../Windows/FileFind.cpp \
+ ../../../Windows/FileIO.cpp \
+ ../../../Windows/FileName.cpp \
+ ../../../Windows/PropVariant.cpp \
+ ../../../Windows/PropVariantConversions.cpp \
+ ../../../Windows/Synchronization.cpp \
+ ../../../Windows/System.cpp \
+ ../../../Windows/Time.cpp \
+ ../../Common/CreateCoder.cpp \
+ ../../Common/CWrappers.cpp \
+ ../../Common/FilePathAutoRename.cpp \
+ ../../Common/FileStreams.cpp \
+ ../../Common/FilterCoder.cpp \
+ ../../Common/InBuffer.cpp \
+ ../../Common/InOutTempBuffer.cpp \
+ ../../Common/LimitedStreams.cpp \
+ ../../Common/LockedStream.cpp \
+ ../../Common/MemBlocks.cpp \
+ ../../Common/MethodId.cpp \
+ ../../Common/MethodProps.cpp \
+ ../../Common/OffsetStream.cpp \
+ ../../Common/OutBuffer.cpp \
+ ../../Common/OutMemStream.cpp \
+ ../../Common/ProgressMt.cpp \
+ ../../Common/ProgressUtils.cpp \
+ ../../Common/StreamBinder.cpp \
+ ../../Common/StreamObjects.cpp \
+ ../../Common/StreamUtils.cpp \
+ ../../Common/VirtThread.cpp \
+ ../../UI/Common/ArchiveCommandLine.cpp \
+ ../../UI/Common/ArchiveExtractCallback.cpp \
+ ../../UI/Common/ArchiveOpenCallback.cpp \
+ ../../UI/Common/Bench.cpp \
+ ../../UI/Common/DefaultName.cpp \
+ ../../UI/Common/EnumDirItems.cpp \
+ ../../UI/Common/Extract.cpp \
+ ../../UI/Common/ExtractingFilePath.cpp \
+ ../../UI/Common/LoadCodecs.cpp \
+ ../../UI/Common/OpenArchive.cpp \
+ ../../UI/Common/PropIDUtils.cpp \
+ ../../UI/Common/SetProperties.cpp \
+ ../../UI/Common/SortUtils.cpp \
+ ../../UI/Common/TempFiles.cpp \
+ ../../UI/Common/Update.cpp \
+ ../../UI/Common/UpdateAction.cpp \
+ ../../UI/Common/UpdateCallback.cpp \
+ ../../UI/Common/UpdatePair.cpp \
+ ../../UI/Common/UpdateProduce.cpp \
+ ../../Archive/Bz2Handler.cpp \
+ ../../Archive/DeflateProps.cpp \
+ ../../Archive/GzHandler.cpp \
+ ../../Archive/LzmaHandler.cpp \
+ ../../Archive/PpmdHandler.cpp \
+ ../../Archive/SplitHandler.cpp \
+ ../../Archive/XzHandler.cpp \
+ ../../Archive/ZHandler.cpp \
+ ../../Archive/Common/CoderMixer2.cpp \
+ ../../Archive/Common/CoderMixer2MT.cpp \
+ ../../Archive/Common/CrossThreadProgress.cpp \
+ ../../Archive/Common/DummyOutStream.cpp \
+ ../../Archive/Common/FindSignature.cpp \
+ ../../Archive/Common/HandlerOut.cpp \
+ ../../Archive/Common/InStreamWithCRC.cpp \
+ ../../Archive/Common/ItemNameUtils.cpp \
+ ../../Archive/Common/MultiStream.cpp \
+ ../../Archive/Common/OutStreamWithCRC.cpp \
+ ../../Archive/Common/ParseProperties.cpp \
+ ../../Archive/7z/7zCompressionMode.cpp \
+ ../../Archive/7z/7zDecode.cpp \
+ ../../Archive/7z/7zEncode.cpp \
+ ../../Archive/7z/7zExtract.cpp \
+ ../../Archive/7z/7zFolderInStream.cpp \
+ ../../Archive/7z/7zFolderOutStream.cpp \
+ ../../Archive/7z/7zHandler.cpp \
+ ../../Archive/7z/7zHandlerOut.cpp \
+ ../../Archive/7z/7zHeader.cpp \
+ ../../Archive/7z/7zIn.cpp \
+ ../../Archive/7z/7zOut.cpp \
+ ../../Archive/7z/7zProperties.cpp \
+ ../../Archive/7z/7zSpecStream.cpp \
+ ../../Archive/7z/7zUpdate.cpp \
+ ../../Archive/7z/7zRegister.cpp \
+ ../../Archive/Cab/CabBlockInStream.cpp \
+ ../../Archive/Cab/CabHandler.cpp \
+ ../../Archive/Cab/CabHeader.cpp \
+ ../../Archive/Cab/CabIn.cpp \
+ ../../Archive/Cab/CabRegister.cpp \
+ ../../Archive/Tar/TarHandler.cpp \
+ ../../Archive/Tar/TarHandlerOut.cpp \
+ ../../Archive/Tar/TarHeader.cpp \
+ ../../Archive/Tar/TarIn.cpp \
+ ../../Archive/Tar/TarOut.cpp \
+ ../../Archive/Tar/TarRegister.cpp \
+ ../../Archive/Tar/TarUpdate.cpp \
+ ../../Archive/Zip/ZipAddCommon.cpp \
+ ../../Archive/Zip/ZipHandler.cpp \
+ ../../Archive/Zip/ZipHandlerOut.cpp \
+ ../../Archive/Zip/ZipHeader.cpp \
+ ../../Archive/Zip/ZipIn.cpp \
+ ../../Archive/Zip/ZipItem.cpp \
+ ../../Archive/Zip/ZipOut.cpp \
+ ../../Archive/Zip/ZipUpdate.cpp \
+ ../../Archive/Zip/ZipRegister.cpp \
+ ../../Compress/Bcj2Coder.cpp \
+ ../../Compress/Bcj2Register.cpp \
+ ../../Compress/BcjCoder.cpp \
+ ../../Compress/BcjRegister.cpp \
+ ../../Compress/BitlDecoder.cpp \
+ ../../Compress/BranchCoder.cpp \
+ ../../Compress/BranchMisc.cpp \
+ ../../Compress/BranchRegister.cpp \
+ ../../Compress/ByteSwap.cpp \
+ ../../Compress/BZip2Crc.cpp \
+ ../../Compress/BZip2Decoder.cpp \
+ ../../Compress/BZip2Encoder.cpp \
+ ../../Compress/BZip2Register.cpp \
+ ../../Compress/CopyCoder.cpp \
+ ../../Compress/CopyRegister.cpp \
+ ../../Compress/Deflate64Register.cpp \
+ ../../Compress/DeflateDecoder.cpp \
+ ../../Compress/DeflateEncoder.cpp \
+ ../../Compress/DeflateRegister.cpp \
+ ../../Compress/DeltaFilter.cpp \
+ ../../Compress/ImplodeDecoder.cpp \
+ ../../Compress/ImplodeHuffmanDecoder.cpp \
+ ../../Compress/Lzma2Decoder.cpp \
+ ../../Compress/Lzma2Encoder.cpp \
+ ../../Compress/Lzma2Register.cpp \
+ ../../Compress/LzmaDecoder.cpp \
+ ../../Compress/LzmaEncoder.cpp \
+ ../../Compress/LzmaRegister.cpp \
+ ../../Compress/LzOutWindow.cpp \
+ ../../Compress/Lzx86Converter.cpp \
+ ../../Compress/LzxDecoder.cpp \
+ ../../Compress/PpmdDecoder.cpp \
+ ../../Compress/PpmdEncoder.cpp \
+ ../../Compress/PpmdRegister.cpp \
+ ../../Compress/PpmdZip.cpp \
+ ../../Compress/QuantumDecoder.cpp \
+ ../../Compress/ShrinkDecoder.cpp \
+ ../../Compress/ZDecoder.cpp \
+ ../../Crypto/7zAes.cpp \
+ ../../Crypto/7zAesRegister.cpp \
+ ../../Crypto/HmacSha1.cpp \
+ ../../Crypto/MyAes.cpp \
+ ../../Crypto/Pbkdf2HmacSha1.cpp \
+ ../../Crypto/RandGen.cpp \
+ ../../Crypto/Sha1.cpp \
+ ../../Crypto/WzAes.cpp \
+ ../../Crypto/ZipCrypto.cpp \
+ ../../Crypto/ZipStrong.cpp \
+ ../../../../C/Aes.c \
+ ../../../../C/7zStream.c \
+ ../../../../C/Alloc.c \
+ ../../../../C/Bra.c \
+ ../../../../C/Bra86.c \
+ ../../../../C/BraIA64.c \
+ ../../../../C/BwtSort.c \
+ ../../../../C/Delta.c \
+ ../../../../C/HuffEnc.c \
+ ../../../../C/LzFind.c \
+ ../../../../C/LzFindMt.c \
+ ../../../../C/Lzma2Dec.c \
+ ../../../../C/Lzma2Enc.c \
+ ../../../../C/LzmaDec.c \
+ ../../../../C/LzmaEnc.c \
+ ../../../../C/MtCoder.c \
+ ../../../../C/Ppmd7.c \
+ ../../../../C/Ppmd7Dec.c \
+ ../../../../C/Ppmd7Enc.c \
+ ../../../../C/Ppmd8.c \
+ ../../../../C/Ppmd8Dec.c \
+ ../../../../C/Ppmd8Enc.c \
+ ../../../../C/Sha256.c \
+ ../../../../C/Sort.c \
+ ../../../../C/Threads.c \
+ ../../../../C/Xz.c \
+ ../../../../C/XzCrc64.c \
+ ../../../../C/XzDec.c \
+ ../../../../C/XzEnc.c \
+ ../../../../C/XzIn.c \
+ ../../../../C/7zCrc.c \
+ ../../../../C/7zCrcOpt.c
+
+
+INCLUDEPATH = ../../../myWindows \
+ ../../../ \
+ ../../../include_windows
+
+DEFINES += _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE NDEBUG _REENTRANT ENV_UNIX BREAK_HANDLER UNICODE _UNICODE ENV_MACOSX
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/test_emul/test_emul.pro
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/test_emul/test_emul.pro?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/test_emul/test_emul.pro (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/QMAKE/test_emul/test_emul.pro Sun Dec 16 23:23:25 2012
@@ -0,0 +1,26 @@
+
+QT -= core \
+ gui
+TARGET = test_emul.x
+CONFIG += console
+CONFIG -= app_bundle
+TEMPLATE = app
+SOURCES += \
+ ../../../myWindows/myGetTickCount.cpp \
+ ../../../myWindows/wine_date_and_time.cpp \
+ ../../../myWindows/myAddExeFlag.cpp \
+ ../../../myWindows/mySplitCommandLine.cpp \
+ ../../../myWindows/wine_GetXXXDefaultLangID.cpp \
+ ../../../myWindows/test_emul.cpp \
+ ../../../Common/MyString.cpp \
+ ../../../Common/MyWindows.cpp \
+ ../../../Common/MyVector.cpp \
+ ../../../../C/7zCrc.c \
+ ../../../../C/7zCrcOpt.c
+
+
+INCLUDEPATH = ../../../myWindows \
+ ../../../ \
+ ../../../include_windows
+
+DEFINES += _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE NDEBUG _REENTRANT ENV_UNIX BREAK_HANDLER UNICODE _UNICODE
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/TestUI.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/TestUI.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/TestUI.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/TestUI.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,560 @@
+// wxGUI.cpp
+
+#include "StdAfx.h"
+
+// For compilers that support precompilation, includes "wx/wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+// for all others, include the necessary headers (this file is usually all you
+// need because it includes almost all "standard" wxWidgets headers)
+#ifndef WX_PRECOMP
+ #include "wx/wx.h"
+#endif
+
+#undef _WIN32
+
+#ifdef __WXMAC__
+
+#define UInt32 max_UInt32
+#include <ApplicationServices/ApplicationServices.h>
+#undef UInt32
+
+#endif
+
+#define static const
+#include "../GUI/p7zip_32.xpm"
+#undef static
+
+#undef ACTIVATE_DIALOG_TESTS
+
+#include "../../UI/FileManager/PasswordDialog.h"
+
+#include "Windows/Window.h"
+#include "Windows/Control/DialogImpl.h"
+
+wxWindow * g_window=0;
+
+static pthread_t g_main_thread;
+
+bool is_main_thread(void)
+{
+ return ( g_main_thread == pthread_self() );
+}
+
+void verify_main_thread(void)
+{
+ if ( ! is_main_thread() )
+ {
+ printf("verify_main_thread-wxGUI\n");
+ abort();
+ }
+}
+
+
+struct CIDLangPair
+{
+ int ControlID;
+ UInt32 LangID;
+};
+
+
+void LangSetWindowText(HWND window, UInt32 langID)
+{
+
+}
+
+void LangSetDlgItemsText(HWND dialogWindow, CIDLangPair *idLangPairs, int numItems)
+{
+
+}
+
+
+#if 0
+
+int Main1(int argc,TCHAR **argv);
+
+#include "Windows/Registry.h"
+using namespace NWindows;
+using namespace NRegistry;
+
+
+#include "Common/StringConvert.h"
+#include "Windows/FileDir.h"
+#include "Windows/Synchronization.h"
+
+#include "ExtractRes.h"
+#include "../Explorer/MyMessages.h"
+
+#include "ExtractGUI.h"
+#include "UpdateGUI.h"
+#include "BenchmarkDialog.h"
+#include "../FileManager/RegistryUtils.h"
+
+using namespace NWindows;
+using namespace NFile;
+
+////////////////////////////// TRIES ///////////////////////////////////
+
+#ifdef ACTIVATE_DIALOG_TESTS
+static void ErrorMessage(const wchar_t *message)
+{
+ MessageBox(0,message, wxT("7-Zip GUI"),wxICON_ERROR);
+}
+
+#include "../FileManager/PasswordDialog.h"
+#include "../FileManager/MessagesDialog.h"
+#include "../FileManager/OverwriteDialog.h"
+#include "Windows/Thread.h"
+
+void testCMessagesDialog()
+{
+ UStringVector Messages;
+
+ Messages.Add(L"message 1");
+ Messages.Add(L"message 2");
+ Messages.Add(L"message 3");
+ Messages.Add(L"message 4");
+ Messages.Add(L"message 5");
+ Messages.Add(L"message 6");
+ Messages.Add(L"message 7");
+ Messages.Add(L"message 8");
+ Messages.Add(L"message 9");
+
+ CMessagesDialog messagesDialog;
+ messagesDialog.Messages = &Messages;
+ int ret = messagesDialog.Create( 0 ); // ParentWindow
+
+ if (ret == IDOK) myErrorMsg(wxT("CMessagesDialog => IDOK"));
+ else if (ret == IDCANCEL) myErrorMsg(wxT("CMessagesDialog => IDCANCEL"));
+ else myErrorMsg(wxT("CMessagesDialog => ?"));
+
+}
+
+void testCOverwriteDialog()
+{
+SYSTEMTIME systemTime;
+GetSystemTime( &systemTime );
+
+
+const wchar_t *existName = L"existName";
+FILETIME data_existTime;
+FILETIME *existTime = &data_existTime ;
+UInt64 data_existSize = 1234;
+UInt64 *existSize = &data_existSize;
+const wchar_t *newName = L"newName";
+FILETIME data_newTime;
+FILETIME *newTime = &data_newTime;
+UInt64 data_newSize = 45678;
+UInt64 *newSize = &data_newSize;
+Int32 data_answer=0;
+Int32 *answer = &data_answer;
+
+SystemTimeToFileTime( &systemTime , &data_existTime);
+SystemTimeToFileTime( &systemTime , &data_newTime);
+
+ COverwriteDialog dialog;
+
+ dialog.OldFileInfo.Time = *existTime;
+ dialog.OldFileInfo.TimeIsDefined = true; // FIXME : look again at the sample !
+
+ dialog.OldFileInfo.SizeIsDefined = (existSize != NULL);
+ if (dialog.OldFileInfo.SizeIsDefined)
+ dialog.OldFileInfo.Size = *existSize;
+ dialog.OldFileInfo.Name = existName;
+
+ if (newTime == 0)
+ dialog.NewFileInfo.TimeIsDefined = false;
+ else
+ {
+ dialog.NewFileInfo.TimeIsDefined = true;
+ dialog.NewFileInfo.Time = *newTime;
+ }
+
+ dialog.NewFileInfo.SizeIsDefined = (newSize != NULL);
+ if (dialog.NewFileInfo.SizeIsDefined)
+ dialog.NewFileInfo.Size = *newSize;
+ dialog.NewFileInfo.Name = newName;
+
+ /*
+ NOverwriteDialog::NResult::EEnum writeAnswer =
+ NOverwriteDialog::Execute(oldFileInfo, newFileInfo);
+ */
+ INT_PTR writeAnswer = dialog.Create(NULL); // ParentWindow doesn't work with 7z
+
+ switch(writeAnswer)
+ {
+ case IDCANCEL: myErrorMsg(wxT("COverwriteDialog => IDCANCEL")); break;
+ case IDNO: myErrorMsg(wxT("COverwriteDialog => IDNO")); break;
+ case IDC_BUTTON_OVERWRITE_NO_TO_ALL: myErrorMsg(wxT("COverwriteDialog => IDC_BUTTON_OVERWRITE_NO_TO_ALL")); break;
+ case IDC_BUTTON_OVERWRITE_YES_TO_ALL:myErrorMsg(wxT("COverwriteDialog => IDC_BUTTON_OVERWRITE_YES_TO_ALL")); break;
+ case IDC_BUTTON_OVERWRITE_AUTO_RENAME:myErrorMsg(wxT("COverwriteDialog => IDC_BUTTON_OVERWRITE_AUTO_RENAME")); break;
+ case IDYES: myErrorMsg(wxT("COverwriteDialog => IDYES")); break;
+ default: myErrorMsg(wxT("COverwriteDialog => default")); break;
+ }
+}
+
+struct CThreadProgressDialog
+{
+ CProgressDialog * ProgressDialog;
+ static THREAD_FUNC_DECL MyThreadFunction(void *param)
+ {
+ ((CThreadProgressDialog *)param)->Result = ((CThreadProgressDialog *)param)->Process();
+ return 0;
+ }
+ HRESULT Result;
+ HRESULT Process()
+ {
+ Sleep(1000);
+ int total = 1000;
+
+ ProgressDialog->ProgressSynch.SetTitleFileName(L"SetTitleFileName");
+ ProgressDialog->ProgressSynch.SetNumFilesTotal(100);
+ ProgressDialog->ProgressSynch.SetNumFilesCur(1);
+ ProgressDialog->ProgressSynch.SetProgress(total, 0);
+ // ProgressDialog.ProgressSynch.SetRatioInfo(inSize, outSize);
+ // ProgressDialog.ProgressSynch.SetCurrentFileName(name);
+
+ ProgressDialog->ProgressSynch.SetPos(total/10);
+ ProgressDialog->ProgressSynch.SetCurrentFileName(L"File1");
+ Sleep(1000);
+ ProgressDialog->ProgressSynch.SetPos(total/2);
+ ProgressDialog->ProgressSynch.SetCurrentFileName(L"File2");
+ Sleep(1000);
+ ProgressDialog->ProgressSynch.SetPos(total);
+ ProgressDialog->ProgressSynch.SetCurrentFileName(L"File3");
+ Sleep(1000);
+ ProgressDialog->MyClose();
+ return 0;
+ }
+};
+
+void testCProgressDialog()
+{
+ CProgressDialog ProgressDialog;
+
+ CThreadProgressDialog benchmarker;
+ benchmarker.ProgressDialog = &ProgressDialog;
+ NWindows::CThread thread;
+ thread.Create(CThreadProgressDialog::MyThreadFunction, &benchmarker);
+
+ // void StartProgressDialog(const UString &title)
+ int ret = ProgressDialog.Create(L"testCProgressDialog", 0);
+
+ if (ret == IDOK) myErrorMsg(wxT("CProgressDialog => IDOK"));
+ else if (ret == IDCANCEL) myErrorMsg(wxT("CProgressDialog => IDCANCEL"));
+ else myErrorMsg(wxT("CProgressDialog => ?"));
+
+}
+
+void testDialog(int num)
+{
+ NWindows::NControl::CModalDialog dialog;
+
+ printf("Generic Dialog(%d)\n",num);
+ int ret = dialog.Create(num, 0);
+ if (ret == IDOK) myErrorMsg(wxT("Generic Dialog => IDOK"));
+ else if (ret == IDCANCEL) myErrorMsg(wxT("Generic Dialog => IDCANCEL"));
+ else myErrorMsg(wxT("Generic Dialog => ?"));
+}
+
+void testMessageBox()
+{
+ int ret = MessageBoxW(0, L"test yes/no/cancel",
+ L"7-Zip", MB_YESNOCANCEL | MB_ICONQUESTION | MB_TASKMODAL);
+ if (ret == IDYES) myErrorMsg(wxT("MessageBoxW => IDYES"));
+ else if (ret == IDNO) myErrorMsg(wxT("MessageBoxW => IDNO"));
+ else if (ret == IDCANCEL) myErrorMsg(wxT("MessageBoxW => IDCANCEL"));
+ else myErrorMsg(wxT("MessageBoxW => ?"));
+}
+
+static void testRegistry()
+{
+ SaveRegLang(L"fr");
+
+ UString langFile;
+ ReadRegLang(langFile);
+
+ printf("testRegistry : -%ls-\n",(const wchar_t *)langFile);
+}
+
+
+int Main2(int argc,TCHAR **argv);
+
+int Main3(int argc,wxChar **argv)
+{
+ testRegistry();
+
+ int num = -1;
+
+ if (argc >=2 )
+ {
+ num = argv[1][0] - L'0';
+ }
+ printf("num=%d\n",num);
+
+
+ switch(num)
+ {
+ case 0:
+ {
+ TCHAR **argv2 = (TCHAR **)calloc(argc,sizeof(*argv));
+
+ argv2[0] = argv[0];
+ for(int i = 2; i < argc; i++) argv2[i-1] = argv[i];
+
+ return Main2(argc-1,argv2);
+ }
+ // TODO Benchmark
+ // TODO CCompressDialog
+ // TODO CExtractDialog ?
+ case 1 : testCMessagesDialog(); break;
+ case 2 : testCOverwriteDialog(); break;
+ case 3 : testCPasswordDialog(); break;
+ case 4 : testCProgressDialog(); break;
+ case 5 : testMessageBox(); break;
+ case 9 :
+ if (argc >= 3)
+ {
+ AString str = GetAnsiString(argv[2]);
+ int num = atoi((const char*)str);
+ testDialog(num);
+ }
+ else
+ {
+ printf("usage : 7zG 9 <windowID>\n");
+ }
+ break;
+ default :
+ printf("usage : 7zG number\n");
+
+ };
+
+ return 0;
+}
+
+#endif // ACTIVATE_DIALOG_TESTS
+
+//////////////////////////////////
+
+#define NEED_NAME_WINDOWS_TO_UNIX
+#include "myPrivate.h" // global_use_utf16_conversion
+
+void mySplitCommandLineW(int numArguments, TCHAR **arguments,UStringVector &parts) {
+
+ parts.Clear();
+ for(int ind=0;ind < numArguments; ind++) {
+ UString tmp = arguments[ind];
+ // tmp.Trim(); " " is a valid filename ...
+ if (!tmp.IsEmpty()) {
+ parts.Add(tmp);
+// DEBUG printf("ARG %d : '%ls'\n",ind,(const wchar_t *)tmp);
+ }
+ }
+}
+
+#endif
+
+void myErrorMsg(const wchar_t *message)
+{
+ MessageBox(0,message, wxT("Message"),wxICON_ERROR);
+}
+
+
+void testCPasswordDialog()
+{
+ CPasswordDialog dialog;
+
+ int ret = dialog.Create(0);
+ if (ret == IDOK) {
+ UString Password = dialog.Password;
+ UString msg = wxT("CPasswordDialog => IDOK password=\"");
+ msg += Password;
+ msg += wxT("\"");
+ myErrorMsg(msg);
+ }
+ else if (ret == IDCANCEL) myErrorMsg(wxT("CPasswordDialog => IDCANCEL"));
+ else myErrorMsg(wxT("CPasswordDialog => ?"));
+
+}
+
+
+int Main3(int argc,wxChar **argv)
+{
+ testCPasswordDialog();
+/*
+ testRegistry();
+
+ int num = -1;
+
+ if (argc >=2 )
+ {
+ num = argv[1][0] - L'0';
+ }
+ printf("num=%d\n",num);
+
+
+ switch(num)
+ {
+ case 0:
+ {
+ TCHAR **argv2 = (TCHAR **)calloc(argc,sizeof(*argv));
+
+ argv2[0] = argv[0];
+ for(int i = 2; i < argc; i++) argv2[i-1] = argv[i];
+
+ return Main2(argc-1,argv2);
+ }
+ // TODO Benchmark
+ // TODO CCompressDialog
+ // TODO CExtractDialog ?
+ case 1 : testCMessagesDialog(); break;
+ case 2 : testCOverwriteDialog(); break;
+ case 3 : testCPasswordDialog(); break;
+ case 4 : testCProgressDialog(); break;
+ case 5 : testMessageBox(); break;
+ case 9 :
+ if (argc >= 3)
+ {
+ AString str = GetAnsiString(argv[2]);
+ int num = atoi((const char*)str);
+ testDialog(num);
+ }
+ else
+ {
+ printf("usage : 7zG 9 <windowID>\n");
+ }
+ break;
+ default :
+ printf("usage : 7zG number\n");
+
+ };
+*/
+ return 0;
+}
+
+// ----------------------------------------------------------------------------
+// private classes
+// ----------------------------------------------------------------------------
+
+// Define a new frame type
+class MyFrame: public wxFrame
+{
+public:
+ // ctor
+ MyFrame(wxFrame *frame, const wxString& title, int x, int y, int w, int h);
+ // virtual ~MyFrame();
+
+ // operations
+ void WriteText(const wxString& text) { m_txtctrl->WriteText(text); }
+
+protected:
+ // callbacks
+ void OnWorkerEvent(wxCommandEvent& event);
+private:
+ // just some place to put our messages in
+ wxTextCtrl *m_txtctrl;
+ DECLARE_EVENT_TABLE()
+};
+
+BEGIN_EVENT_TABLE(MyFrame, wxFrame)
+ EVT_MENU(WORKER_EVENT, MyFrame::OnWorkerEvent)
+ // EVT_IDLE(MyFrame::OnIdle)
+END_EVENT_TABLE()
+
+// My frame constructor
+MyFrame::MyFrame(wxFrame *frame, const wxString& title,
+ int x, int y, int w, int h)
+ : wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
+{
+ this->SetIcon(wxICON(p7zip_32));
+
+#if wxUSE_STATUSBAR
+ CreateStatusBar(2);
+#endif // wxUSE_STATUSBAR
+
+ m_txtctrl = new wxTextCtrl(this, wxID_ANY, _T(""), wxPoint(0, 0), wxSize(0, 0), wxTE_MULTILINE | wxTE_READONLY);
+}
+
+void myCreateHandle(int n);
+
+void MyFrame::OnWorkerEvent(wxCommandEvent& event)
+{
+ int n = event.GetInt();
+ myCreateHandle(n);
+}
+
+
+// Define a new application type, each program should derive a class from wxApp
+class MyApp : public wxApp
+{
+public:
+ // override base class virtuals
+ // ----------------------------
+
+ // this one is called on application startup and is a good place for the app
+ // initialization (doing it here and not in the ctor allows to have an error
+ // return: if OnInit() returns false, the application terminates)
+ virtual bool OnInit();
+};
+
+// Create a new application object: this macro will allow wxWidgets to create
+// the application object during program execution (it's better than using a
+// static object for many reasons) and also implements the accessor function
+// wxGetApp() which will return the reference of the right type (i.e. MyApp and
+// not wxApp)
+IMPLEMENT_APP(MyApp)
+
+class MyThread : public wxThread
+{
+ int _argc;
+ TCHAR **_argv;
+public:
+ MyThread(int argc,TCHAR **argv): wxThread(),_argc(argc), _argv(argv) {}
+
+ // thread execution starts here
+ virtual void *Entry()
+ {
+ int ret = Main3(_argc,_argv);
+ exit(ret);
+ }
+};
+
+// 'Main program' equivalent: the program execution "starts" here
+bool MyApp::OnInit()
+{
+ // don't parse the command-line options !
+ // : if ( !wxApp::OnInit() ) return false;
+
+#ifdef __WXMAC__
+ProcessSerialNumber PSN;
+GetCurrentProcess(&PSN);
+TransformProcessType(&PSN,kProcessTransformToForegroundApplication);
+#endif
+
+g_main_thread = pthread_self();
+
+ // DEBUG printf("MAIN Thread : 0x%lx\n",wxThread::GetCurrentId());
+
+ // Create the main frame window
+ MyFrame *frame = new MyFrame((wxFrame *)NULL, _T("7-zip Main Window"), 50, 50, 450, 340);
+ // Don't Show the frame !
+ // frame->Show(true);
+
+ g_window = frame;
+
+ SetTopWindow(frame);
+
+ MyThread *thread = new MyThread(wxApp::argc,wxApp::argv);
+ thread->Create(); // != wxTHREAD_NO_ERROR
+ thread->Run();
+
+ // success: wxApp::OnRun() will be called which will enter the main message
+ // loop and the application will run. If we returned false here, the
+ // application would exit immediately.
+ return true;
+}
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/makefile
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/makefile?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/makefile (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/makefile Sun Dec 16 23:23:25 2012
@@ -0,0 +1,33 @@
+PROG=../../../../bin/TestUI$(BINSUFFIX)
+
+LOCAL_FLAGS=\
+ -DUNICODE -D_UNICODE \
+ -DLANG \
+ -DEXTERNAL_LZMA \
+ -DEXTERNAL_CODECS \
+ -DBENCH_MT \
+ -I. \
+ `wx-config --unicode=yes --cxxflags`
+
+include ../../../../makefile.crc32
+include ../../../../makefile.machine
+
+PCH_NAME=$(PRE_COMPILED_HEADER)
+
+LIBS=`wx-config --unicode=yes --libs` $(LOCAL_LIBS_DLL)
+
+C_OBJS = \
+ Threads.o \
+
+OBJS=\
+PasswordDialog.o \
+PasswordDialog_rc.o \
+Window.o \
+Dialog.o \
+Controls.o \
+ $(C_OBJS) \
+TestUI.o
+
+
+include ../../../../makefile.glb
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/makefile.depend
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/makefile.depend?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/makefile.depend (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/makefile.depend Sun Dec 16 23:23:25 2012
@@ -0,0 +1,577 @@
+PasswordDialog.o: ../../UI/FileManager/PasswordDialog.cpp \
+ ../../../myWindows/StdAfx.h ../../../myWindows/config.h \
+ ../../../Common/MyWindows.h ../../../Common/MyGuidDef.h \
+ ../../../Common/Types.h ../../../Common/../../C/Types.h \
+ ../../../Common/Types.h ../../../include_windows/windows.h \
+ ../../../include_windows/basetyps.h ../../../include_windows/tchar.h \
+ ../../UI/FileManager/PasswordDialog.h ../../../Windows/Control/Dialog.h \
+ ../../../Windows/Window.h ../../../Windows/Defs.h \
+ ../../../Windows/../Common/MyWindows.h ../../../Common/MyString.h \
+ ../../../Common/MyVector.h ../../../Common/Defs.h \
+ ../../../Windows/Control/Edit.h \
+ ../../UI/FileManager/PasswordDialogRes.h \
+ ../../UI/FileManager/LangUtils.h ../../../Common/Lang.h \
+ ../../../Common/MyString.h ../../../Windows/ResourceString.h
+PasswordDialog_rc.o: ../../UI/FileManager/PasswordDialog_rc.cpp \
+ ../../../myWindows/StdAfx.h ../../../myWindows/config.h \
+ ../../../Common/MyWindows.h ../../../Common/MyGuidDef.h \
+ ../../../Common/Types.h ../../../Common/../../C/Types.h \
+ ../../../Common/Types.h ../../../include_windows/windows.h \
+ ../../../include_windows/basetyps.h ../../../include_windows/tchar.h \
+ /usr/include/wx-2.8/wx/wxprec.h /usr/include/wx-2.8/wx/defs.h \
+ /usr/include/wx-2.8/wx/platform.h \
+ /usr/lib/wx/include/gtk2-unicode-release-2.8/wx/setup.h \
+ /usr/include/wx-2.8/wx/chkconf.h /usr/include/wx-2.8/wx/features.h \
+ /usr/include/wx-2.8/wx/version.h /usr/include/wx-2.8/wx/cpp.h \
+ /usr/include/wx-2.8/wx/dlimpexp.h /usr/include/wx-2.8/wx/debug.h \
+ /usr/include/wx-2.8/wx/wxchar.h /usr/include/wx-2.8/wx/wx.h \
+ /usr/include/wx-2.8/wx/object.h /usr/include/wx-2.8/wx/memory.h \
+ /usr/include/wx-2.8/wx/string.h /usr/include/wx-2.8/wx/buffer.h \
+ /usr/include/wx-2.8/wx/strconv.h /usr/include/wx-2.8/wx/fontenc.h \
+ /usr/include/wx-2.8/wx/beforestd.h /usr/include/wx-2.8/wx/afterstd.h \
+ /usr/include/wx-2.8/wx/iosfwrap.h /usr/include/wx-2.8/wx/msgout.h \
+ /usr/include/wx-2.8/wx/dynarray.h /usr/include/wx-2.8/wx/list.h \
+ /usr/include/wx-2.8/wx/hash.h /usr/include/wx-2.8/wx/hashmap.h \
+ /usr/include/wx-2.8/wx/arrstr.h /usr/include/wx-2.8/wx/intl.h \
+ /usr/include/wx-2.8/wx/log.h /usr/include/wx-2.8/wx/generic/logg.h \
+ /usr/include/wx-2.8/wx/event.h /usr/include/wx-2.8/wx/clntdata.h \
+ /usr/include/wx-2.8/wx/vector.h /usr/include/wx-2.8/wx/gdicmn.h \
+ /usr/include/wx-2.8/wx/math.h /usr/include/wx-2.8/wx/cursor.h \
+ /usr/include/wx-2.8/wx/gtk/cursor.h /usr/include/wx-2.8/wx/utils.h \
+ /usr/include/wx-2.8/wx/filefn.h /usr/include/wx-2.8/wx/longlong.h \
+ /usr/include/wx-2.8/wx/platinfo.h /usr/include/wx-2.8/wx/thread.h \
+ /usr/include/wx-2.8/wx/app.h /usr/include/wx-2.8/wx/build.h \
+ /usr/include/wx-2.8/wx/init.h /usr/include/wx-2.8/wx/gtk/app.h \
+ /usr/include/wx-2.8/wx/stream.h /usr/include/wx-2.8/wx/stopwatch.h \
+ /usr/include/wx-2.8/wx/module.h /usr/include/wx-2.8/wx/window.h \
+ /usr/include/wx-2.8/wx/font.h /usr/include/wx-2.8/wx/gdiobj.h \
+ /usr/include/wx-2.8/wx/gtk/font.h /usr/include/wx-2.8/wx/colour.h \
+ /usr/include/wx-2.8/wx/variant.h /usr/include/wx-2.8/wx/datetime.h \
+ /usr/include/wx-2.8/wx/gtk/colour.h /usr/include/wx-2.8/wx/region.h \
+ /usr/include/wx-2.8/wx/gtk/region.h /usr/include/wx-2.8/wx/validate.h \
+ /usr/include/wx-2.8/wx/palette.h \
+ /usr/include/wx-2.8/wx/generic/paletteg.h \
+ /usr/include/wx-2.8/wx/accel.h /usr/include/wx-2.8/wx/gtk/accel.h \
+ /usr/include/wx-2.8/wx/generic/accel.h \
+ /usr/include/wx-2.8/wx/gtk/window.h /usr/include/wx-2.8/wx/containr.h \
+ /usr/include/wx-2.8/wx/panel.h /usr/include/wx-2.8/wx/generic/panelg.h \
+ /usr/include/wx-2.8/wx/toplevel.h /usr/include/wx-2.8/wx/iconbndl.h \
+ /usr/include/wx-2.8/wx/gtk/toplevel.h /usr/include/wx-2.8/wx/frame.h \
+ /usr/include/wx-2.8/wx/gtk/frame.h /usr/include/wx-2.8/wx/bitmap.h \
+ /usr/include/wx-2.8/wx/gtk/bitmap.h /usr/include/wx-2.8/wx/image.h \
+ /usr/include/wx-2.8/wx/imagbmp.h /usr/include/wx-2.8/wx/imagpng.h \
+ /usr/include/wx-2.8/wx/imaggif.h /usr/include/wx-2.8/wx/imagpcx.h \
+ /usr/include/wx-2.8/wx/imagjpeg.h /usr/include/wx-2.8/wx/imagtga.h \
+ /usr/include/wx-2.8/wx/imagtiff.h /usr/include/wx-2.8/wx/imagpnm.h \
+ /usr/include/wx-2.8/wx/imagxpm.h /usr/include/wx-2.8/wx/imagiff.h \
+ /usr/include/wx-2.8/wx/dc.h /usr/include/wx-2.8/wx/brush.h \
+ /usr/include/wx-2.8/wx/gtk/brush.h /usr/include/wx-2.8/wx/pen.h \
+ /usr/include/wx-2.8/wx/gtk/pen.h /usr/include/wx-2.8/wx/gtk/dc.h \
+ /usr/include/wx-2.8/wx/dcgraph.h /usr/include/wx-2.8/wx/geometry.h \
+ /usr/include/wx-2.8/wx/graphics.h /usr/include/wx-2.8/wx/dcclient.h \
+ /usr/include/wx-2.8/wx/gtk/dcclient.h /usr/include/wx-2.8/wx/dcmemory.h \
+ /usr/include/wx-2.8/wx/gtk/dcmemory.h /usr/include/wx-2.8/wx/dcprint.h \
+ /usr/include/wx-2.8/wx/dcscreen.h /usr/include/wx-2.8/wx/gtk/dcscreen.h \
+ /usr/include/wx-2.8/wx/button.h /usr/include/wx-2.8/wx/control.h \
+ /usr/include/wx-2.8/wx/gtk/control.h \
+ /usr/include/wx-2.8/wx/gtk/button.h /usr/include/wx-2.8/wx/menuitem.h \
+ /usr/include/wx-2.8/wx/gtk/menuitem.h /usr/include/wx-2.8/wx/menu.h \
+ /usr/include/wx-2.8/wx/gtk/menu.h /usr/include/wx-2.8/wx/icon.h \
+ /usr/include/wx-2.8/wx/iconloc.h /usr/include/wx-2.8/wx/generic/icon.h \
+ /usr/include/wx-2.8/wx/dialog.h /usr/include/wx-2.8/wx/gtk/dialog.h \
+ /usr/include/wx-2.8/wx/timer.h /usr/include/wx-2.8/wx/gtk/timer.h \
+ /usr/include/wx-2.8/wx/settings.h /usr/include/wx-2.8/wx/msgdlg.h \
+ /usr/include/wx-2.8/wx/gtk/msgdlg.h /usr/include/wx-2.8/wx/cmndata.h \
+ /usr/include/wx-2.8/wx/encinfo.h /usr/include/wx-2.8/wx/dataobj.h \
+ /usr/include/wx-2.8/wx/gtk/dataform.h \
+ /usr/include/wx-2.8/wx/gtk/dataobj.h \
+ /usr/include/wx-2.8/wx/gtk/dataobj2.h /usr/include/wx-2.8/wx/ctrlsub.h \
+ /usr/include/wx-2.8/wx/bmpbuttn.h /usr/include/wx-2.8/wx/gtk/bmpbuttn.h \
+ /usr/include/wx-2.8/wx/checkbox.h /usr/include/wx-2.8/wx/gtk/checkbox.h \
+ /usr/include/wx-2.8/wx/checklst.h /usr/include/wx-2.8/wx/listbox.h \
+ /usr/include/wx-2.8/wx/gtk/listbox.h \
+ /usr/include/wx-2.8/wx/gtk/checklst.h /usr/include/wx-2.8/wx/choice.h \
+ /usr/include/wx-2.8/wx/gtk/choice.h /usr/include/wx-2.8/wx/scrolbar.h \
+ /usr/include/wx-2.8/wx/gtk/scrolbar.h /usr/include/wx-2.8/wx/stattext.h \
+ /usr/include/wx-2.8/wx/gtk/stattext.h /usr/include/wx-2.8/wx/statbmp.h \
+ /usr/include/wx-2.8/wx/gtk/statbmp.h /usr/include/wx-2.8/wx/statbox.h \
+ /usr/include/wx-2.8/wx/gtk/statbox.h /usr/include/wx-2.8/wx/radiobox.h \
+ /usr/include/wx-2.8/wx/gtk/radiobox.h /usr/include/wx-2.8/wx/radiobut.h \
+ /usr/include/wx-2.8/wx/gtk/radiobut.h /usr/include/wx-2.8/wx/textctrl.h \
+ /usr/include/wx-2.8/wx/ioswrap.h /usr/include/wx-2.8/wx/gtk/textctrl.h \
+ /usr/include/wx-2.8/wx/slider.h /usr/include/wx-2.8/wx/gtk/slider.h \
+ /usr/include/wx-2.8/wx/gauge.h /usr/include/wx-2.8/wx/gtk/gauge.h \
+ /usr/include/wx-2.8/wx/scrolwin.h /usr/include/wx-2.8/wx/gtk/scrolwin.h \
+ /usr/include/wx-2.8/wx/dirdlg.h /usr/include/wx-2.8/wx/gtk/dirdlg.h \
+ /usr/include/wx-2.8/wx/generic/dirdlgg.h \
+ /usr/include/wx-2.8/wx/toolbar.h /usr/include/wx-2.8/wx/tbarbase.h \
+ /usr/include/wx-2.8/wx/gtk/tbargtk.h /usr/include/wx-2.8/wx/combobox.h \
+ /usr/include/wx-2.8/wx/gtk/combobox.h /usr/include/wx-2.8/wx/layout.h \
+ /usr/include/wx-2.8/wx/sizer.h /usr/include/wx-2.8/wx/mdi.h \
+ /usr/include/wx-2.8/wx/gtk/mdi.h /usr/include/wx-2.8/wx/statusbr.h \
+ /usr/include/wx-2.8/wx/generic/statusbr.h \
+ /usr/include/wx-2.8/wx/choicdlg.h \
+ /usr/include/wx-2.8/wx/generic/choicdgg.h \
+ /usr/include/wx-2.8/wx/textdlg.h \
+ /usr/include/wx-2.8/wx/generic/textdlgg.h \
+ /usr/include/wx-2.8/wx/valtext.h /usr/include/wx-2.8/wx/filedlg.h \
+ /usr/include/wx-2.8/wx/gtk/filedlg.h \
+ /usr/include/wx-2.8/wx/generic/filedlgg.h \
+ /usr/include/wx-2.8/wx/listctrl.h /usr/include/wx-2.8/wx/listbase.h \
+ /usr/include/wx-2.8/wx/generic/listctrl.h \
+ ../../../Windows/Control/DialogImpl.h ../../../Windows/Window.h \
+ ../../../Windows/Defs.h ../../../Windows/../Common/MyWindows.h \
+ ../../../Common/MyString.h ../../../Common/MyVector.h \
+ ../../../Common/Defs.h ../../../Windows/Control/Dialog.h \
+ ../../UI/FileManager/PasswordDialogRes.h
+Window.o: ../../../Windows/Window.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h /usr/include/wx-2.8/wx/wxprec.h \
+ /usr/include/wx-2.8/wx/defs.h /usr/include/wx-2.8/wx/platform.h \
+ /usr/lib/wx/include/gtk2-unicode-release-2.8/wx/setup.h \
+ /usr/include/wx-2.8/wx/chkconf.h /usr/include/wx-2.8/wx/features.h \
+ /usr/include/wx-2.8/wx/version.h /usr/include/wx-2.8/wx/cpp.h \
+ /usr/include/wx-2.8/wx/dlimpexp.h /usr/include/wx-2.8/wx/debug.h \
+ /usr/include/wx-2.8/wx/wxchar.h /usr/include/wx-2.8/wx/wx.h \
+ /usr/include/wx-2.8/wx/object.h /usr/include/wx-2.8/wx/memory.h \
+ /usr/include/wx-2.8/wx/string.h /usr/include/wx-2.8/wx/buffer.h \
+ /usr/include/wx-2.8/wx/strconv.h /usr/include/wx-2.8/wx/fontenc.h \
+ /usr/include/wx-2.8/wx/beforestd.h /usr/include/wx-2.8/wx/afterstd.h \
+ /usr/include/wx-2.8/wx/iosfwrap.h /usr/include/wx-2.8/wx/msgout.h \
+ /usr/include/wx-2.8/wx/dynarray.h /usr/include/wx-2.8/wx/list.h \
+ /usr/include/wx-2.8/wx/hash.h /usr/include/wx-2.8/wx/hashmap.h \
+ /usr/include/wx-2.8/wx/arrstr.h /usr/include/wx-2.8/wx/intl.h \
+ /usr/include/wx-2.8/wx/log.h /usr/include/wx-2.8/wx/generic/logg.h \
+ /usr/include/wx-2.8/wx/event.h /usr/include/wx-2.8/wx/clntdata.h \
+ /usr/include/wx-2.8/wx/vector.h /usr/include/wx-2.8/wx/gdicmn.h \
+ /usr/include/wx-2.8/wx/math.h /usr/include/wx-2.8/wx/cursor.h \
+ /usr/include/wx-2.8/wx/gtk/cursor.h /usr/include/wx-2.8/wx/utils.h \
+ /usr/include/wx-2.8/wx/filefn.h /usr/include/wx-2.8/wx/longlong.h \
+ /usr/include/wx-2.8/wx/platinfo.h /usr/include/wx-2.8/wx/thread.h \
+ /usr/include/wx-2.8/wx/app.h /usr/include/wx-2.8/wx/build.h \
+ /usr/include/wx-2.8/wx/init.h /usr/include/wx-2.8/wx/gtk/app.h \
+ /usr/include/wx-2.8/wx/stream.h /usr/include/wx-2.8/wx/stopwatch.h \
+ /usr/include/wx-2.8/wx/module.h /usr/include/wx-2.8/wx/window.h \
+ /usr/include/wx-2.8/wx/font.h /usr/include/wx-2.8/wx/gdiobj.h \
+ /usr/include/wx-2.8/wx/gtk/font.h /usr/include/wx-2.8/wx/colour.h \
+ /usr/include/wx-2.8/wx/variant.h /usr/include/wx-2.8/wx/datetime.h \
+ /usr/include/wx-2.8/wx/gtk/colour.h /usr/include/wx-2.8/wx/region.h \
+ /usr/include/wx-2.8/wx/gtk/region.h /usr/include/wx-2.8/wx/validate.h \
+ /usr/include/wx-2.8/wx/palette.h \
+ /usr/include/wx-2.8/wx/generic/paletteg.h \
+ /usr/include/wx-2.8/wx/accel.h /usr/include/wx-2.8/wx/gtk/accel.h \
+ /usr/include/wx-2.8/wx/generic/accel.h \
+ /usr/include/wx-2.8/wx/gtk/window.h /usr/include/wx-2.8/wx/containr.h \
+ /usr/include/wx-2.8/wx/panel.h /usr/include/wx-2.8/wx/generic/panelg.h \
+ /usr/include/wx-2.8/wx/toplevel.h /usr/include/wx-2.8/wx/iconbndl.h \
+ /usr/include/wx-2.8/wx/gtk/toplevel.h /usr/include/wx-2.8/wx/frame.h \
+ /usr/include/wx-2.8/wx/gtk/frame.h /usr/include/wx-2.8/wx/bitmap.h \
+ /usr/include/wx-2.8/wx/gtk/bitmap.h /usr/include/wx-2.8/wx/image.h \
+ /usr/include/wx-2.8/wx/imagbmp.h /usr/include/wx-2.8/wx/imagpng.h \
+ /usr/include/wx-2.8/wx/imaggif.h /usr/include/wx-2.8/wx/imagpcx.h \
+ /usr/include/wx-2.8/wx/imagjpeg.h /usr/include/wx-2.8/wx/imagtga.h \
+ /usr/include/wx-2.8/wx/imagtiff.h /usr/include/wx-2.8/wx/imagpnm.h \
+ /usr/include/wx-2.8/wx/imagxpm.h /usr/include/wx-2.8/wx/imagiff.h \
+ /usr/include/wx-2.8/wx/dc.h /usr/include/wx-2.8/wx/brush.h \
+ /usr/include/wx-2.8/wx/gtk/brush.h /usr/include/wx-2.8/wx/pen.h \
+ /usr/include/wx-2.8/wx/gtk/pen.h /usr/include/wx-2.8/wx/gtk/dc.h \
+ /usr/include/wx-2.8/wx/dcgraph.h /usr/include/wx-2.8/wx/geometry.h \
+ /usr/include/wx-2.8/wx/graphics.h /usr/include/wx-2.8/wx/dcclient.h \
+ /usr/include/wx-2.8/wx/gtk/dcclient.h /usr/include/wx-2.8/wx/dcmemory.h \
+ /usr/include/wx-2.8/wx/gtk/dcmemory.h /usr/include/wx-2.8/wx/dcprint.h \
+ /usr/include/wx-2.8/wx/dcscreen.h /usr/include/wx-2.8/wx/gtk/dcscreen.h \
+ /usr/include/wx-2.8/wx/button.h /usr/include/wx-2.8/wx/control.h \
+ /usr/include/wx-2.8/wx/gtk/control.h \
+ /usr/include/wx-2.8/wx/gtk/button.h /usr/include/wx-2.8/wx/menuitem.h \
+ /usr/include/wx-2.8/wx/gtk/menuitem.h /usr/include/wx-2.8/wx/menu.h \
+ /usr/include/wx-2.8/wx/gtk/menu.h /usr/include/wx-2.8/wx/icon.h \
+ /usr/include/wx-2.8/wx/iconloc.h /usr/include/wx-2.8/wx/generic/icon.h \
+ /usr/include/wx-2.8/wx/dialog.h /usr/include/wx-2.8/wx/gtk/dialog.h \
+ /usr/include/wx-2.8/wx/timer.h /usr/include/wx-2.8/wx/gtk/timer.h \
+ /usr/include/wx-2.8/wx/settings.h /usr/include/wx-2.8/wx/msgdlg.h \
+ /usr/include/wx-2.8/wx/gtk/msgdlg.h /usr/include/wx-2.8/wx/cmndata.h \
+ /usr/include/wx-2.8/wx/encinfo.h /usr/include/wx-2.8/wx/dataobj.h \
+ /usr/include/wx-2.8/wx/gtk/dataform.h \
+ /usr/include/wx-2.8/wx/gtk/dataobj.h \
+ /usr/include/wx-2.8/wx/gtk/dataobj2.h /usr/include/wx-2.8/wx/ctrlsub.h \
+ /usr/include/wx-2.8/wx/bmpbuttn.h /usr/include/wx-2.8/wx/gtk/bmpbuttn.h \
+ /usr/include/wx-2.8/wx/checkbox.h /usr/include/wx-2.8/wx/gtk/checkbox.h \
+ /usr/include/wx-2.8/wx/checklst.h /usr/include/wx-2.8/wx/listbox.h \
+ /usr/include/wx-2.8/wx/gtk/listbox.h \
+ /usr/include/wx-2.8/wx/gtk/checklst.h /usr/include/wx-2.8/wx/choice.h \
+ /usr/include/wx-2.8/wx/gtk/choice.h /usr/include/wx-2.8/wx/scrolbar.h \
+ /usr/include/wx-2.8/wx/gtk/scrolbar.h /usr/include/wx-2.8/wx/stattext.h \
+ /usr/include/wx-2.8/wx/gtk/stattext.h /usr/include/wx-2.8/wx/statbmp.h \
+ /usr/include/wx-2.8/wx/gtk/statbmp.h /usr/include/wx-2.8/wx/statbox.h \
+ /usr/include/wx-2.8/wx/gtk/statbox.h /usr/include/wx-2.8/wx/radiobox.h \
+ /usr/include/wx-2.8/wx/gtk/radiobox.h /usr/include/wx-2.8/wx/radiobut.h \
+ /usr/include/wx-2.8/wx/gtk/radiobut.h /usr/include/wx-2.8/wx/textctrl.h \
+ /usr/include/wx-2.8/wx/ioswrap.h /usr/include/wx-2.8/wx/gtk/textctrl.h \
+ /usr/include/wx-2.8/wx/slider.h /usr/include/wx-2.8/wx/gtk/slider.h \
+ /usr/include/wx-2.8/wx/gauge.h /usr/include/wx-2.8/wx/gtk/gauge.h \
+ /usr/include/wx-2.8/wx/scrolwin.h /usr/include/wx-2.8/wx/gtk/scrolwin.h \
+ /usr/include/wx-2.8/wx/dirdlg.h /usr/include/wx-2.8/wx/gtk/dirdlg.h \
+ /usr/include/wx-2.8/wx/generic/dirdlgg.h \
+ /usr/include/wx-2.8/wx/toolbar.h /usr/include/wx-2.8/wx/tbarbase.h \
+ /usr/include/wx-2.8/wx/gtk/tbargtk.h /usr/include/wx-2.8/wx/combobox.h \
+ /usr/include/wx-2.8/wx/gtk/combobox.h /usr/include/wx-2.8/wx/layout.h \
+ /usr/include/wx-2.8/wx/sizer.h /usr/include/wx-2.8/wx/mdi.h \
+ /usr/include/wx-2.8/wx/gtk/mdi.h /usr/include/wx-2.8/wx/statusbr.h \
+ /usr/include/wx-2.8/wx/generic/statusbr.h \
+ /usr/include/wx-2.8/wx/choicdlg.h \
+ /usr/include/wx-2.8/wx/generic/choicdgg.h \
+ /usr/include/wx-2.8/wx/textdlg.h \
+ /usr/include/wx-2.8/wx/generic/textdlgg.h \
+ /usr/include/wx-2.8/wx/valtext.h /usr/include/wx-2.8/wx/filedlg.h \
+ /usr/include/wx-2.8/wx/gtk/filedlg.h \
+ /usr/include/wx-2.8/wx/generic/filedlgg.h \
+ /usr/include/wx-2.8/wx/listctrl.h /usr/include/wx-2.8/wx/listbase.h \
+ /usr/include/wx-2.8/wx/generic/listctrl.h ../../../Windows/Window.h \
+ ../../../Windows/Defs.h ../../../Windows/../Common/MyWindows.h \
+ ../../../Common/MyString.h ../../../Common/MyVector.h \
+ ../../../Common/Defs.h
+Dialog.o: ../../../Windows/Control/Dialog.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h /usr/include/wx-2.8/wx/wxprec.h \
+ /usr/include/wx-2.8/wx/defs.h /usr/include/wx-2.8/wx/platform.h \
+ /usr/lib/wx/include/gtk2-unicode-release-2.8/wx/setup.h \
+ /usr/include/wx-2.8/wx/chkconf.h /usr/include/wx-2.8/wx/features.h \
+ /usr/include/wx-2.8/wx/version.h /usr/include/wx-2.8/wx/cpp.h \
+ /usr/include/wx-2.8/wx/dlimpexp.h /usr/include/wx-2.8/wx/debug.h \
+ /usr/include/wx-2.8/wx/wxchar.h /usr/include/wx-2.8/wx/wx.h \
+ /usr/include/wx-2.8/wx/object.h /usr/include/wx-2.8/wx/memory.h \
+ /usr/include/wx-2.8/wx/string.h /usr/include/wx-2.8/wx/buffer.h \
+ /usr/include/wx-2.8/wx/strconv.h /usr/include/wx-2.8/wx/fontenc.h \
+ /usr/include/wx-2.8/wx/beforestd.h /usr/include/wx-2.8/wx/afterstd.h \
+ /usr/include/wx-2.8/wx/iosfwrap.h /usr/include/wx-2.8/wx/msgout.h \
+ /usr/include/wx-2.8/wx/dynarray.h /usr/include/wx-2.8/wx/list.h \
+ /usr/include/wx-2.8/wx/hash.h /usr/include/wx-2.8/wx/hashmap.h \
+ /usr/include/wx-2.8/wx/arrstr.h /usr/include/wx-2.8/wx/intl.h \
+ /usr/include/wx-2.8/wx/log.h /usr/include/wx-2.8/wx/generic/logg.h \
+ /usr/include/wx-2.8/wx/event.h /usr/include/wx-2.8/wx/clntdata.h \
+ /usr/include/wx-2.8/wx/vector.h /usr/include/wx-2.8/wx/gdicmn.h \
+ /usr/include/wx-2.8/wx/math.h /usr/include/wx-2.8/wx/cursor.h \
+ /usr/include/wx-2.8/wx/gtk/cursor.h /usr/include/wx-2.8/wx/utils.h \
+ /usr/include/wx-2.8/wx/filefn.h /usr/include/wx-2.8/wx/longlong.h \
+ /usr/include/wx-2.8/wx/platinfo.h /usr/include/wx-2.8/wx/thread.h \
+ /usr/include/wx-2.8/wx/app.h /usr/include/wx-2.8/wx/build.h \
+ /usr/include/wx-2.8/wx/init.h /usr/include/wx-2.8/wx/gtk/app.h \
+ /usr/include/wx-2.8/wx/stream.h /usr/include/wx-2.8/wx/stopwatch.h \
+ /usr/include/wx-2.8/wx/module.h /usr/include/wx-2.8/wx/window.h \
+ /usr/include/wx-2.8/wx/font.h /usr/include/wx-2.8/wx/gdiobj.h \
+ /usr/include/wx-2.8/wx/gtk/font.h /usr/include/wx-2.8/wx/colour.h \
+ /usr/include/wx-2.8/wx/variant.h /usr/include/wx-2.8/wx/datetime.h \
+ /usr/include/wx-2.8/wx/gtk/colour.h /usr/include/wx-2.8/wx/region.h \
+ /usr/include/wx-2.8/wx/gtk/region.h /usr/include/wx-2.8/wx/validate.h \
+ /usr/include/wx-2.8/wx/palette.h \
+ /usr/include/wx-2.8/wx/generic/paletteg.h \
+ /usr/include/wx-2.8/wx/accel.h /usr/include/wx-2.8/wx/gtk/accel.h \
+ /usr/include/wx-2.8/wx/generic/accel.h \
+ /usr/include/wx-2.8/wx/gtk/window.h /usr/include/wx-2.8/wx/containr.h \
+ /usr/include/wx-2.8/wx/panel.h /usr/include/wx-2.8/wx/generic/panelg.h \
+ /usr/include/wx-2.8/wx/toplevel.h /usr/include/wx-2.8/wx/iconbndl.h \
+ /usr/include/wx-2.8/wx/gtk/toplevel.h /usr/include/wx-2.8/wx/frame.h \
+ /usr/include/wx-2.8/wx/gtk/frame.h /usr/include/wx-2.8/wx/bitmap.h \
+ /usr/include/wx-2.8/wx/gtk/bitmap.h /usr/include/wx-2.8/wx/image.h \
+ /usr/include/wx-2.8/wx/imagbmp.h /usr/include/wx-2.8/wx/imagpng.h \
+ /usr/include/wx-2.8/wx/imaggif.h /usr/include/wx-2.8/wx/imagpcx.h \
+ /usr/include/wx-2.8/wx/imagjpeg.h /usr/include/wx-2.8/wx/imagtga.h \
+ /usr/include/wx-2.8/wx/imagtiff.h /usr/include/wx-2.8/wx/imagpnm.h \
+ /usr/include/wx-2.8/wx/imagxpm.h /usr/include/wx-2.8/wx/imagiff.h \
+ /usr/include/wx-2.8/wx/dc.h /usr/include/wx-2.8/wx/brush.h \
+ /usr/include/wx-2.8/wx/gtk/brush.h /usr/include/wx-2.8/wx/pen.h \
+ /usr/include/wx-2.8/wx/gtk/pen.h /usr/include/wx-2.8/wx/gtk/dc.h \
+ /usr/include/wx-2.8/wx/dcgraph.h /usr/include/wx-2.8/wx/geometry.h \
+ /usr/include/wx-2.8/wx/graphics.h /usr/include/wx-2.8/wx/dcclient.h \
+ /usr/include/wx-2.8/wx/gtk/dcclient.h /usr/include/wx-2.8/wx/dcmemory.h \
+ /usr/include/wx-2.8/wx/gtk/dcmemory.h /usr/include/wx-2.8/wx/dcprint.h \
+ /usr/include/wx-2.8/wx/dcscreen.h /usr/include/wx-2.8/wx/gtk/dcscreen.h \
+ /usr/include/wx-2.8/wx/button.h /usr/include/wx-2.8/wx/control.h \
+ /usr/include/wx-2.8/wx/gtk/control.h \
+ /usr/include/wx-2.8/wx/gtk/button.h /usr/include/wx-2.8/wx/menuitem.h \
+ /usr/include/wx-2.8/wx/gtk/menuitem.h /usr/include/wx-2.8/wx/menu.h \
+ /usr/include/wx-2.8/wx/gtk/menu.h /usr/include/wx-2.8/wx/icon.h \
+ /usr/include/wx-2.8/wx/iconloc.h /usr/include/wx-2.8/wx/generic/icon.h \
+ /usr/include/wx-2.8/wx/dialog.h /usr/include/wx-2.8/wx/gtk/dialog.h \
+ /usr/include/wx-2.8/wx/timer.h /usr/include/wx-2.8/wx/gtk/timer.h \
+ /usr/include/wx-2.8/wx/settings.h /usr/include/wx-2.8/wx/msgdlg.h \
+ /usr/include/wx-2.8/wx/gtk/msgdlg.h /usr/include/wx-2.8/wx/cmndata.h \
+ /usr/include/wx-2.8/wx/encinfo.h /usr/include/wx-2.8/wx/dataobj.h \
+ /usr/include/wx-2.8/wx/gtk/dataform.h \
+ /usr/include/wx-2.8/wx/gtk/dataobj.h \
+ /usr/include/wx-2.8/wx/gtk/dataobj2.h /usr/include/wx-2.8/wx/ctrlsub.h \
+ /usr/include/wx-2.8/wx/bmpbuttn.h /usr/include/wx-2.8/wx/gtk/bmpbuttn.h \
+ /usr/include/wx-2.8/wx/checkbox.h /usr/include/wx-2.8/wx/gtk/checkbox.h \
+ /usr/include/wx-2.8/wx/checklst.h /usr/include/wx-2.8/wx/listbox.h \
+ /usr/include/wx-2.8/wx/gtk/listbox.h \
+ /usr/include/wx-2.8/wx/gtk/checklst.h /usr/include/wx-2.8/wx/choice.h \
+ /usr/include/wx-2.8/wx/gtk/choice.h /usr/include/wx-2.8/wx/scrolbar.h \
+ /usr/include/wx-2.8/wx/gtk/scrolbar.h /usr/include/wx-2.8/wx/stattext.h \
+ /usr/include/wx-2.8/wx/gtk/stattext.h /usr/include/wx-2.8/wx/statbmp.h \
+ /usr/include/wx-2.8/wx/gtk/statbmp.h /usr/include/wx-2.8/wx/statbox.h \
+ /usr/include/wx-2.8/wx/gtk/statbox.h /usr/include/wx-2.8/wx/radiobox.h \
+ /usr/include/wx-2.8/wx/gtk/radiobox.h /usr/include/wx-2.8/wx/radiobut.h \
+ /usr/include/wx-2.8/wx/gtk/radiobut.h /usr/include/wx-2.8/wx/textctrl.h \
+ /usr/include/wx-2.8/wx/ioswrap.h /usr/include/wx-2.8/wx/gtk/textctrl.h \
+ /usr/include/wx-2.8/wx/slider.h /usr/include/wx-2.8/wx/gtk/slider.h \
+ /usr/include/wx-2.8/wx/gauge.h /usr/include/wx-2.8/wx/gtk/gauge.h \
+ /usr/include/wx-2.8/wx/scrolwin.h /usr/include/wx-2.8/wx/gtk/scrolwin.h \
+ /usr/include/wx-2.8/wx/dirdlg.h /usr/include/wx-2.8/wx/gtk/dirdlg.h \
+ /usr/include/wx-2.8/wx/generic/dirdlgg.h \
+ /usr/include/wx-2.8/wx/toolbar.h /usr/include/wx-2.8/wx/tbarbase.h \
+ /usr/include/wx-2.8/wx/gtk/tbargtk.h /usr/include/wx-2.8/wx/combobox.h \
+ /usr/include/wx-2.8/wx/gtk/combobox.h /usr/include/wx-2.8/wx/layout.h \
+ /usr/include/wx-2.8/wx/sizer.h /usr/include/wx-2.8/wx/mdi.h \
+ /usr/include/wx-2.8/wx/gtk/mdi.h /usr/include/wx-2.8/wx/statusbr.h \
+ /usr/include/wx-2.8/wx/generic/statusbr.h \
+ /usr/include/wx-2.8/wx/choicdlg.h \
+ /usr/include/wx-2.8/wx/generic/choicdgg.h \
+ /usr/include/wx-2.8/wx/textdlg.h \
+ /usr/include/wx-2.8/wx/generic/textdlgg.h \
+ /usr/include/wx-2.8/wx/valtext.h /usr/include/wx-2.8/wx/filedlg.h \
+ /usr/include/wx-2.8/wx/gtk/filedlg.h \
+ /usr/include/wx-2.8/wx/generic/filedlgg.h \
+ /usr/include/wx-2.8/wx/listctrl.h /usr/include/wx-2.8/wx/listbase.h \
+ /usr/include/wx-2.8/wx/generic/listctrl.h \
+ ../../../Windows/Control/DialogImpl.h ../../../Windows/Window.h \
+ ../../../Windows/Defs.h ../../../Windows/../Common/MyWindows.h \
+ ../../../Common/MyString.h ../../../Common/MyVector.h \
+ ../../../Common/Defs.h ../../../Windows/Control/Dialog.h \
+ ../../../Windows/Synchronization.h ../../../Windows/Defs.h \
+ ../../../Windows/../../C/Threads.h ../../../Windows/../../C/Types.h \
+ ../../../Windows/Synchronization2.h
+Controls.o: ../../../Windows/Control/Controls.cpp \
+ ../../../myWindows/StdAfx.h ../../../myWindows/config.h \
+ ../../../Common/MyWindows.h ../../../Common/MyGuidDef.h \
+ ../../../Common/Types.h ../../../Common/../../C/Types.h \
+ ../../../Common/Types.h ../../../include_windows/windows.h \
+ ../../../include_windows/basetyps.h ../../../include_windows/tchar.h \
+ /usr/include/wx-2.8/wx/wxprec.h /usr/include/wx-2.8/wx/defs.h \
+ /usr/include/wx-2.8/wx/platform.h \
+ /usr/lib/wx/include/gtk2-unicode-release-2.8/wx/setup.h \
+ /usr/include/wx-2.8/wx/chkconf.h /usr/include/wx-2.8/wx/features.h \
+ /usr/include/wx-2.8/wx/version.h /usr/include/wx-2.8/wx/cpp.h \
+ /usr/include/wx-2.8/wx/dlimpexp.h /usr/include/wx-2.8/wx/debug.h \
+ /usr/include/wx-2.8/wx/wxchar.h /usr/include/wx-2.8/wx/wx.h \
+ /usr/include/wx-2.8/wx/object.h /usr/include/wx-2.8/wx/memory.h \
+ /usr/include/wx-2.8/wx/string.h /usr/include/wx-2.8/wx/buffer.h \
+ /usr/include/wx-2.8/wx/strconv.h /usr/include/wx-2.8/wx/fontenc.h \
+ /usr/include/wx-2.8/wx/beforestd.h /usr/include/wx-2.8/wx/afterstd.h \
+ /usr/include/wx-2.8/wx/iosfwrap.h /usr/include/wx-2.8/wx/msgout.h \
+ /usr/include/wx-2.8/wx/dynarray.h /usr/include/wx-2.8/wx/list.h \
+ /usr/include/wx-2.8/wx/hash.h /usr/include/wx-2.8/wx/hashmap.h \
+ /usr/include/wx-2.8/wx/arrstr.h /usr/include/wx-2.8/wx/intl.h \
+ /usr/include/wx-2.8/wx/log.h /usr/include/wx-2.8/wx/generic/logg.h \
+ /usr/include/wx-2.8/wx/event.h /usr/include/wx-2.8/wx/clntdata.h \
+ /usr/include/wx-2.8/wx/vector.h /usr/include/wx-2.8/wx/gdicmn.h \
+ /usr/include/wx-2.8/wx/math.h /usr/include/wx-2.8/wx/cursor.h \
+ /usr/include/wx-2.8/wx/gtk/cursor.h /usr/include/wx-2.8/wx/utils.h \
+ /usr/include/wx-2.8/wx/filefn.h /usr/include/wx-2.8/wx/longlong.h \
+ /usr/include/wx-2.8/wx/platinfo.h /usr/include/wx-2.8/wx/thread.h \
+ /usr/include/wx-2.8/wx/app.h /usr/include/wx-2.8/wx/build.h \
+ /usr/include/wx-2.8/wx/init.h /usr/include/wx-2.8/wx/gtk/app.h \
+ /usr/include/wx-2.8/wx/stream.h /usr/include/wx-2.8/wx/stopwatch.h \
+ /usr/include/wx-2.8/wx/module.h /usr/include/wx-2.8/wx/window.h \
+ /usr/include/wx-2.8/wx/font.h /usr/include/wx-2.8/wx/gdiobj.h \
+ /usr/include/wx-2.8/wx/gtk/font.h /usr/include/wx-2.8/wx/colour.h \
+ /usr/include/wx-2.8/wx/variant.h /usr/include/wx-2.8/wx/datetime.h \
+ /usr/include/wx-2.8/wx/gtk/colour.h /usr/include/wx-2.8/wx/region.h \
+ /usr/include/wx-2.8/wx/gtk/region.h /usr/include/wx-2.8/wx/validate.h \
+ /usr/include/wx-2.8/wx/palette.h \
+ /usr/include/wx-2.8/wx/generic/paletteg.h \
+ /usr/include/wx-2.8/wx/accel.h /usr/include/wx-2.8/wx/gtk/accel.h \
+ /usr/include/wx-2.8/wx/generic/accel.h \
+ /usr/include/wx-2.8/wx/gtk/window.h /usr/include/wx-2.8/wx/containr.h \
+ /usr/include/wx-2.8/wx/panel.h /usr/include/wx-2.8/wx/generic/panelg.h \
+ /usr/include/wx-2.8/wx/toplevel.h /usr/include/wx-2.8/wx/iconbndl.h \
+ /usr/include/wx-2.8/wx/gtk/toplevel.h /usr/include/wx-2.8/wx/frame.h \
+ /usr/include/wx-2.8/wx/gtk/frame.h /usr/include/wx-2.8/wx/bitmap.h \
+ /usr/include/wx-2.8/wx/gtk/bitmap.h /usr/include/wx-2.8/wx/image.h \
+ /usr/include/wx-2.8/wx/imagbmp.h /usr/include/wx-2.8/wx/imagpng.h \
+ /usr/include/wx-2.8/wx/imaggif.h /usr/include/wx-2.8/wx/imagpcx.h \
+ /usr/include/wx-2.8/wx/imagjpeg.h /usr/include/wx-2.8/wx/imagtga.h \
+ /usr/include/wx-2.8/wx/imagtiff.h /usr/include/wx-2.8/wx/imagpnm.h \
+ /usr/include/wx-2.8/wx/imagxpm.h /usr/include/wx-2.8/wx/imagiff.h \
+ /usr/include/wx-2.8/wx/dc.h /usr/include/wx-2.8/wx/brush.h \
+ /usr/include/wx-2.8/wx/gtk/brush.h /usr/include/wx-2.8/wx/pen.h \
+ /usr/include/wx-2.8/wx/gtk/pen.h /usr/include/wx-2.8/wx/gtk/dc.h \
+ /usr/include/wx-2.8/wx/dcgraph.h /usr/include/wx-2.8/wx/geometry.h \
+ /usr/include/wx-2.8/wx/graphics.h /usr/include/wx-2.8/wx/dcclient.h \
+ /usr/include/wx-2.8/wx/gtk/dcclient.h /usr/include/wx-2.8/wx/dcmemory.h \
+ /usr/include/wx-2.8/wx/gtk/dcmemory.h /usr/include/wx-2.8/wx/dcprint.h \
+ /usr/include/wx-2.8/wx/dcscreen.h /usr/include/wx-2.8/wx/gtk/dcscreen.h \
+ /usr/include/wx-2.8/wx/button.h /usr/include/wx-2.8/wx/control.h \
+ /usr/include/wx-2.8/wx/gtk/control.h \
+ /usr/include/wx-2.8/wx/gtk/button.h /usr/include/wx-2.8/wx/menuitem.h \
+ /usr/include/wx-2.8/wx/gtk/menuitem.h /usr/include/wx-2.8/wx/menu.h \
+ /usr/include/wx-2.8/wx/gtk/menu.h /usr/include/wx-2.8/wx/icon.h \
+ /usr/include/wx-2.8/wx/iconloc.h /usr/include/wx-2.8/wx/generic/icon.h \
+ /usr/include/wx-2.8/wx/dialog.h /usr/include/wx-2.8/wx/gtk/dialog.h \
+ /usr/include/wx-2.8/wx/timer.h /usr/include/wx-2.8/wx/gtk/timer.h \
+ /usr/include/wx-2.8/wx/settings.h /usr/include/wx-2.8/wx/msgdlg.h \
+ /usr/include/wx-2.8/wx/gtk/msgdlg.h /usr/include/wx-2.8/wx/cmndata.h \
+ /usr/include/wx-2.8/wx/encinfo.h /usr/include/wx-2.8/wx/dataobj.h \
+ /usr/include/wx-2.8/wx/gtk/dataform.h \
+ /usr/include/wx-2.8/wx/gtk/dataobj.h \
+ /usr/include/wx-2.8/wx/gtk/dataobj2.h /usr/include/wx-2.8/wx/ctrlsub.h \
+ /usr/include/wx-2.8/wx/bmpbuttn.h /usr/include/wx-2.8/wx/gtk/bmpbuttn.h \
+ /usr/include/wx-2.8/wx/checkbox.h /usr/include/wx-2.8/wx/gtk/checkbox.h \
+ /usr/include/wx-2.8/wx/checklst.h /usr/include/wx-2.8/wx/listbox.h \
+ /usr/include/wx-2.8/wx/gtk/listbox.h \
+ /usr/include/wx-2.8/wx/gtk/checklst.h /usr/include/wx-2.8/wx/choice.h \
+ /usr/include/wx-2.8/wx/gtk/choice.h /usr/include/wx-2.8/wx/scrolbar.h \
+ /usr/include/wx-2.8/wx/gtk/scrolbar.h /usr/include/wx-2.8/wx/stattext.h \
+ /usr/include/wx-2.8/wx/gtk/stattext.h /usr/include/wx-2.8/wx/statbmp.h \
+ /usr/include/wx-2.8/wx/gtk/statbmp.h /usr/include/wx-2.8/wx/statbox.h \
+ /usr/include/wx-2.8/wx/gtk/statbox.h /usr/include/wx-2.8/wx/radiobox.h \
+ /usr/include/wx-2.8/wx/gtk/radiobox.h /usr/include/wx-2.8/wx/radiobut.h \
+ /usr/include/wx-2.8/wx/gtk/radiobut.h /usr/include/wx-2.8/wx/textctrl.h \
+ /usr/include/wx-2.8/wx/ioswrap.h /usr/include/wx-2.8/wx/gtk/textctrl.h \
+ /usr/include/wx-2.8/wx/slider.h /usr/include/wx-2.8/wx/gtk/slider.h \
+ /usr/include/wx-2.8/wx/gauge.h /usr/include/wx-2.8/wx/gtk/gauge.h \
+ /usr/include/wx-2.8/wx/scrolwin.h /usr/include/wx-2.8/wx/gtk/scrolwin.h \
+ /usr/include/wx-2.8/wx/dirdlg.h /usr/include/wx-2.8/wx/gtk/dirdlg.h \
+ /usr/include/wx-2.8/wx/generic/dirdlgg.h \
+ /usr/include/wx-2.8/wx/toolbar.h /usr/include/wx-2.8/wx/tbarbase.h \
+ /usr/include/wx-2.8/wx/gtk/tbargtk.h /usr/include/wx-2.8/wx/combobox.h \
+ /usr/include/wx-2.8/wx/gtk/combobox.h /usr/include/wx-2.8/wx/layout.h \
+ /usr/include/wx-2.8/wx/sizer.h /usr/include/wx-2.8/wx/mdi.h \
+ /usr/include/wx-2.8/wx/gtk/mdi.h /usr/include/wx-2.8/wx/statusbr.h \
+ /usr/include/wx-2.8/wx/generic/statusbr.h \
+ /usr/include/wx-2.8/wx/choicdlg.h \
+ /usr/include/wx-2.8/wx/generic/choicdgg.h \
+ /usr/include/wx-2.8/wx/textdlg.h \
+ /usr/include/wx-2.8/wx/generic/textdlgg.h \
+ /usr/include/wx-2.8/wx/valtext.h /usr/include/wx-2.8/wx/filedlg.h \
+ /usr/include/wx-2.8/wx/gtk/filedlg.h \
+ /usr/include/wx-2.8/wx/generic/filedlgg.h \
+ /usr/include/wx-2.8/wx/listctrl.h /usr/include/wx-2.8/wx/listbase.h \
+ /usr/include/wx-2.8/wx/generic/listctrl.h \
+ /usr/include/wx-2.8/wx/imaglist.h \
+ /usr/include/wx-2.8/wx/generic/imaglist.h \
+ ../../../Windows/Control/Dialog.h ../../../Windows/Window.h \
+ ../../../Windows/Defs.h ../../../Windows/../Common/MyWindows.h \
+ ../../../Common/MyString.h ../../../Common/MyVector.h \
+ ../../../Common/Defs.h ../../../Windows/Control/ComboBox.h \
+ ../../../Windows/Control/Edit.h ../../../Windows/Control/ProgressBar.h \
+ ../../../Windows/Control/StatusBar.h \
+ ../../../Windows/Control/ListView.h
+TestUI.o: TestUI.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h /usr/include/wx-2.8/wx/wxprec.h \
+ /usr/include/wx-2.8/wx/defs.h /usr/include/wx-2.8/wx/platform.h \
+ /usr/lib/wx/include/gtk2-unicode-release-2.8/wx/setup.h \
+ /usr/include/wx-2.8/wx/chkconf.h /usr/include/wx-2.8/wx/features.h \
+ /usr/include/wx-2.8/wx/version.h /usr/include/wx-2.8/wx/cpp.h \
+ /usr/include/wx-2.8/wx/dlimpexp.h /usr/include/wx-2.8/wx/debug.h \
+ /usr/include/wx-2.8/wx/wxchar.h /usr/include/wx-2.8/wx/wx.h \
+ /usr/include/wx-2.8/wx/object.h /usr/include/wx-2.8/wx/memory.h \
+ /usr/include/wx-2.8/wx/string.h /usr/include/wx-2.8/wx/buffer.h \
+ /usr/include/wx-2.8/wx/strconv.h /usr/include/wx-2.8/wx/fontenc.h \
+ /usr/include/wx-2.8/wx/beforestd.h /usr/include/wx-2.8/wx/afterstd.h \
+ /usr/include/wx-2.8/wx/iosfwrap.h /usr/include/wx-2.8/wx/msgout.h \
+ /usr/include/wx-2.8/wx/dynarray.h /usr/include/wx-2.8/wx/list.h \
+ /usr/include/wx-2.8/wx/hash.h /usr/include/wx-2.8/wx/hashmap.h \
+ /usr/include/wx-2.8/wx/arrstr.h /usr/include/wx-2.8/wx/intl.h \
+ /usr/include/wx-2.8/wx/log.h /usr/include/wx-2.8/wx/generic/logg.h \
+ /usr/include/wx-2.8/wx/event.h /usr/include/wx-2.8/wx/clntdata.h \
+ /usr/include/wx-2.8/wx/vector.h /usr/include/wx-2.8/wx/gdicmn.h \
+ /usr/include/wx-2.8/wx/math.h /usr/include/wx-2.8/wx/cursor.h \
+ /usr/include/wx-2.8/wx/gtk/cursor.h /usr/include/wx-2.8/wx/utils.h \
+ /usr/include/wx-2.8/wx/filefn.h /usr/include/wx-2.8/wx/longlong.h \
+ /usr/include/wx-2.8/wx/platinfo.h /usr/include/wx-2.8/wx/thread.h \
+ /usr/include/wx-2.8/wx/app.h /usr/include/wx-2.8/wx/build.h \
+ /usr/include/wx-2.8/wx/init.h /usr/include/wx-2.8/wx/gtk/app.h \
+ /usr/include/wx-2.8/wx/stream.h /usr/include/wx-2.8/wx/stopwatch.h \
+ /usr/include/wx-2.8/wx/module.h /usr/include/wx-2.8/wx/window.h \
+ /usr/include/wx-2.8/wx/font.h /usr/include/wx-2.8/wx/gdiobj.h \
+ /usr/include/wx-2.8/wx/gtk/font.h /usr/include/wx-2.8/wx/colour.h \
+ /usr/include/wx-2.8/wx/variant.h /usr/include/wx-2.8/wx/datetime.h \
+ /usr/include/wx-2.8/wx/gtk/colour.h /usr/include/wx-2.8/wx/region.h \
+ /usr/include/wx-2.8/wx/gtk/region.h /usr/include/wx-2.8/wx/validate.h \
+ /usr/include/wx-2.8/wx/palette.h \
+ /usr/include/wx-2.8/wx/generic/paletteg.h \
+ /usr/include/wx-2.8/wx/accel.h /usr/include/wx-2.8/wx/gtk/accel.h \
+ /usr/include/wx-2.8/wx/generic/accel.h \
+ /usr/include/wx-2.8/wx/gtk/window.h /usr/include/wx-2.8/wx/containr.h \
+ /usr/include/wx-2.8/wx/panel.h /usr/include/wx-2.8/wx/generic/panelg.h \
+ /usr/include/wx-2.8/wx/toplevel.h /usr/include/wx-2.8/wx/iconbndl.h \
+ /usr/include/wx-2.8/wx/gtk/toplevel.h /usr/include/wx-2.8/wx/frame.h \
+ /usr/include/wx-2.8/wx/gtk/frame.h /usr/include/wx-2.8/wx/bitmap.h \
+ /usr/include/wx-2.8/wx/gtk/bitmap.h /usr/include/wx-2.8/wx/image.h \
+ /usr/include/wx-2.8/wx/imagbmp.h /usr/include/wx-2.8/wx/imagpng.h \
+ /usr/include/wx-2.8/wx/imaggif.h /usr/include/wx-2.8/wx/imagpcx.h \
+ /usr/include/wx-2.8/wx/imagjpeg.h /usr/include/wx-2.8/wx/imagtga.h \
+ /usr/include/wx-2.8/wx/imagtiff.h /usr/include/wx-2.8/wx/imagpnm.h \
+ /usr/include/wx-2.8/wx/imagxpm.h /usr/include/wx-2.8/wx/imagiff.h \
+ /usr/include/wx-2.8/wx/dc.h /usr/include/wx-2.8/wx/brush.h \
+ /usr/include/wx-2.8/wx/gtk/brush.h /usr/include/wx-2.8/wx/pen.h \
+ /usr/include/wx-2.8/wx/gtk/pen.h /usr/include/wx-2.8/wx/gtk/dc.h \
+ /usr/include/wx-2.8/wx/dcgraph.h /usr/include/wx-2.8/wx/geometry.h \
+ /usr/include/wx-2.8/wx/graphics.h /usr/include/wx-2.8/wx/dcclient.h \
+ /usr/include/wx-2.8/wx/gtk/dcclient.h /usr/include/wx-2.8/wx/dcmemory.h \
+ /usr/include/wx-2.8/wx/gtk/dcmemory.h /usr/include/wx-2.8/wx/dcprint.h \
+ /usr/include/wx-2.8/wx/dcscreen.h /usr/include/wx-2.8/wx/gtk/dcscreen.h \
+ /usr/include/wx-2.8/wx/button.h /usr/include/wx-2.8/wx/control.h \
+ /usr/include/wx-2.8/wx/gtk/control.h \
+ /usr/include/wx-2.8/wx/gtk/button.h /usr/include/wx-2.8/wx/menuitem.h \
+ /usr/include/wx-2.8/wx/gtk/menuitem.h /usr/include/wx-2.8/wx/menu.h \
+ /usr/include/wx-2.8/wx/gtk/menu.h /usr/include/wx-2.8/wx/icon.h \
+ /usr/include/wx-2.8/wx/iconloc.h /usr/include/wx-2.8/wx/generic/icon.h \
+ /usr/include/wx-2.8/wx/dialog.h /usr/include/wx-2.8/wx/gtk/dialog.h \
+ /usr/include/wx-2.8/wx/timer.h /usr/include/wx-2.8/wx/gtk/timer.h \
+ /usr/include/wx-2.8/wx/settings.h /usr/include/wx-2.8/wx/msgdlg.h \
+ /usr/include/wx-2.8/wx/gtk/msgdlg.h /usr/include/wx-2.8/wx/cmndata.h \
+ /usr/include/wx-2.8/wx/encinfo.h /usr/include/wx-2.8/wx/dataobj.h \
+ /usr/include/wx-2.8/wx/gtk/dataform.h \
+ /usr/include/wx-2.8/wx/gtk/dataobj.h \
+ /usr/include/wx-2.8/wx/gtk/dataobj2.h /usr/include/wx-2.8/wx/ctrlsub.h \
+ /usr/include/wx-2.8/wx/bmpbuttn.h /usr/include/wx-2.8/wx/gtk/bmpbuttn.h \
+ /usr/include/wx-2.8/wx/checkbox.h /usr/include/wx-2.8/wx/gtk/checkbox.h \
+ /usr/include/wx-2.8/wx/checklst.h /usr/include/wx-2.8/wx/listbox.h \
+ /usr/include/wx-2.8/wx/gtk/listbox.h \
+ /usr/include/wx-2.8/wx/gtk/checklst.h /usr/include/wx-2.8/wx/choice.h \
+ /usr/include/wx-2.8/wx/gtk/choice.h /usr/include/wx-2.8/wx/scrolbar.h \
+ /usr/include/wx-2.8/wx/gtk/scrolbar.h /usr/include/wx-2.8/wx/stattext.h \
+ /usr/include/wx-2.8/wx/gtk/stattext.h /usr/include/wx-2.8/wx/statbmp.h \
+ /usr/include/wx-2.8/wx/gtk/statbmp.h /usr/include/wx-2.8/wx/statbox.h \
+ /usr/include/wx-2.8/wx/gtk/statbox.h /usr/include/wx-2.8/wx/radiobox.h \
+ /usr/include/wx-2.8/wx/gtk/radiobox.h /usr/include/wx-2.8/wx/radiobut.h \
+ /usr/include/wx-2.8/wx/gtk/radiobut.h /usr/include/wx-2.8/wx/textctrl.h \
+ /usr/include/wx-2.8/wx/ioswrap.h /usr/include/wx-2.8/wx/gtk/textctrl.h \
+ /usr/include/wx-2.8/wx/slider.h /usr/include/wx-2.8/wx/gtk/slider.h \
+ /usr/include/wx-2.8/wx/gauge.h /usr/include/wx-2.8/wx/gtk/gauge.h \
+ /usr/include/wx-2.8/wx/scrolwin.h /usr/include/wx-2.8/wx/gtk/scrolwin.h \
+ /usr/include/wx-2.8/wx/dirdlg.h /usr/include/wx-2.8/wx/gtk/dirdlg.h \
+ /usr/include/wx-2.8/wx/generic/dirdlgg.h \
+ /usr/include/wx-2.8/wx/toolbar.h /usr/include/wx-2.8/wx/tbarbase.h \
+ /usr/include/wx-2.8/wx/gtk/tbargtk.h /usr/include/wx-2.8/wx/combobox.h \
+ /usr/include/wx-2.8/wx/gtk/combobox.h /usr/include/wx-2.8/wx/layout.h \
+ /usr/include/wx-2.8/wx/sizer.h /usr/include/wx-2.8/wx/mdi.h \
+ /usr/include/wx-2.8/wx/gtk/mdi.h /usr/include/wx-2.8/wx/statusbr.h \
+ /usr/include/wx-2.8/wx/generic/statusbr.h \
+ /usr/include/wx-2.8/wx/choicdlg.h \
+ /usr/include/wx-2.8/wx/generic/choicdgg.h \
+ /usr/include/wx-2.8/wx/textdlg.h \
+ /usr/include/wx-2.8/wx/generic/textdlgg.h \
+ /usr/include/wx-2.8/wx/valtext.h /usr/include/wx-2.8/wx/filedlg.h \
+ /usr/include/wx-2.8/wx/gtk/filedlg.h \
+ /usr/include/wx-2.8/wx/generic/filedlgg.h \
+ /usr/include/wx-2.8/wx/listctrl.h /usr/include/wx-2.8/wx/listbase.h \
+ /usr/include/wx-2.8/wx/generic/listctrl.h ../../../../GUI/p7zip_32.xpm \
+ ../../UI/FileManager/PasswordDialog.h ../../../Windows/Control/Dialog.h \
+ ../../../Windows/Window.h ../../../Windows/Defs.h \
+ ../../../Windows/../Common/MyWindows.h ../../../Common/MyString.h \
+ ../../../Common/MyVector.h ../../../Common/Defs.h \
+ ../../../Windows/Control/Edit.h \
+ ../../UI/FileManager/PasswordDialogRes.h \
+ ../../../Windows/Control/DialogImpl.h
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/makefile.list
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/makefile.list?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/makefile.list (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/TEST/TestUI/makefile.list Sun Dec 16 23:23:25 2012
@@ -0,0 +1,16 @@
+SRCS=\
+ ../../UI/FileManager/PasswordDialog.cpp \
+ ../../UI/FileManager/PasswordDialog_rc.cpp \
+ ../../../Windows/Window.cpp \
+ ../../../Windows/Control/Dialog.cpp \
+ ../../../Windows/Control/Controls.cpp \
+ TestUI.cpp \
+
+SRCS_C=\
+ ../../../../C/Threads.c
+
+include ../../../../makefile.rules
+
+TestUI.o : TestUI.cpp
+ $(CXX) $(CXXFLAGS) TestUI.cpp
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/Agent.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/Agent.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/Agent.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/Agent.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,645 @@
+// Agent.cpp
+
+#include "StdAfx.h"
+
+#include "../../../../C/Sort.h"
+
+#include "Common/ComTry.h"
+
+#include "../Common/ArchiveExtractCallback.h"
+
+#include "Agent.h"
+
+using namespace NWindows;
+
+STDMETHODIMP CAgentFolder::GetAgentFolder(CAgentFolder **agentFolder)
+{
+ *agentFolder = this;
+ return S_OK;
+}
+
+void CAgentFolder::LoadFolder(CProxyFolder *folder)
+{
+ int i;
+ CProxyItem item;
+ item.Folder = folder;
+ for (i = 0; i < folder->Folders.Size(); i++)
+ {
+ item.Index = i;
+ _items.Add(item);
+ LoadFolder(&folder->Folders[i]);
+ }
+ int start = folder->Folders.Size();
+ for (i = 0; i < folder->Files.Size(); i++)
+ {
+ item.Index = start + i;
+ _items.Add(item);
+ }
+}
+
+STDMETHODIMP CAgentFolder::LoadItems()
+{
+ if (!_agentSpec->_archiveLink.IsOpen)
+ return E_FAIL;
+ _items.Clear();
+ if (_flatMode)
+ LoadFolder(_proxyFolderItem);
+ return S_OK;
+}
+
+STDMETHODIMP CAgentFolder::GetNumberOfItems(UInt32 *numItems)
+{
+ if (_flatMode)
+ *numItems = _items.Size();
+ else
+ *numItems = _proxyFolderItem->Folders.Size() +_proxyFolderItem->Files.Size();
+ return S_OK;
+}
+
+UString CAgentFolder::GetName(UInt32 index) const
+{
+ UInt32 realIndex;
+ const CProxyFolder *folder;
+ if (_flatMode)
+ {
+ const CProxyItem &item = _items[index];
+ folder = item.Folder;
+ realIndex = item.Index;
+ }
+ else
+ {
+ folder = _proxyFolderItem;
+ realIndex = index;
+ }
+
+ if (realIndex < (UInt32)folder->Folders.Size())
+ return folder->Folders[realIndex].Name;
+ return folder->Files[realIndex - folder->Folders.Size()].Name;
+}
+
+UString CAgentFolder::GetPrefix(UInt32 index) const
+{
+ if (!_flatMode)
+ return UString();
+ const CProxyItem &item = _items[index];
+ const CProxyFolder *folder = item.Folder;
+ UString path;
+ while (folder != _proxyFolderItem)
+ {
+ path = folder->Name + UString(WCHAR_PATH_SEPARATOR) + path;
+ folder = folder->Parent;
+ }
+ return path;
+}
+
+UString CAgentFolder::GetFullPathPrefixPlusPrefix(UInt32 index) const
+{
+ return _proxyFolderItem->GetFullPathPrefix() + GetPrefix(index);
+}
+
+void CAgentFolder::GetPrefixIfAny(UInt32 index, NCOM::CPropVariant &prop) const
+{
+ if (!_flatMode)
+ return;
+ prop = GetPrefix(index);
+}
+
+
+STDMETHODIMP CAgentFolder::GetProperty(UInt32 itemIndex, PROPID propID, PROPVARIANT *value)
+{
+ NCOM::CPropVariant prop;
+ const CProxyFolder *folder;
+ UInt32 realIndex;
+ if (_flatMode)
+ {
+ const CProxyItem &item = _items[itemIndex];
+ folder = item.Folder;
+ realIndex = item.Index;
+ }
+ else
+ {
+ folder = _proxyFolderItem;
+ realIndex = itemIndex;
+ }
+
+ if (realIndex < (UInt32)folder->Folders.Size())
+ {
+ const CProxyFolder &item = folder->Folders[realIndex];
+ if (!_flatMode && propID == kpidSize)
+ prop = item.Size;
+ else if (!_flatMode && propID == kpidPackSize)
+ prop = item.PackSize;
+ else
+ switch(propID)
+ {
+ case kpidIsDir: prop = true; break;
+ case kpidNumSubDirs: prop = item.NumSubFolders; break;
+ case kpidNumSubFiles: prop = item.NumSubFiles; break;
+ case kpidName: prop = item.Name; break;
+ case kpidCRC:
+ {
+ if (item.IsLeaf)
+ {
+ RINOK(_agentSpec->GetArchive()->GetProperty(item.Index, propID, value));
+ }
+ if (item.CrcIsDefined && value->vt == VT_EMPTY)
+ prop = item.Crc;
+ break;
+ }
+ case kpidPrefix: GetPrefixIfAny(itemIndex, prop); break;
+
+ default:
+ if (item.IsLeaf)
+ return _agentSpec->GetArchive()->GetProperty(item.Index, propID, value);
+ }
+ }
+ else
+ {
+ realIndex -= folder->Folders.Size();
+ const CProxyFile &item = folder->Files[realIndex];
+ switch(propID)
+ {
+ case kpidIsDir: prop = false; break;
+ case kpidName: prop = item.Name; break;
+ case kpidPrefix: GetPrefixIfAny(itemIndex, prop); break;
+ default:
+ return _agentSpec->GetArchive()->GetProperty(item.Index, propID, value);
+ }
+ }
+ prop.Detach(value);
+ return S_OK;
+}
+
+HRESULT CAgentFolder::BindToFolder(CProxyFolder *folder, IFolderFolder **resultFolder)
+{
+ CMyComPtr<IFolderFolder> parentFolder;
+ if (folder->Parent != _proxyFolderItem)
+ {
+ RINOK(BindToFolder(folder->Parent, &parentFolder));
+ }
+ else
+ parentFolder = this;
+ CAgentFolder *folderSpec = new CAgentFolder;
+ CMyComPtr<IFolderFolder> agentFolder = folderSpec;
+ folderSpec->Init(_proxyArchive, folder, parentFolder, _agentSpec);
+ *resultFolder = agentFolder.Detach();
+ return S_OK;
+}
+
+STDMETHODIMP CAgentFolder::BindToFolder(UInt32 index, IFolderFolder **resultFolder)
+{
+ COM_TRY_BEGIN
+
+ CProxyFolder *folder;
+ UInt32 realIndex;
+ if (_flatMode)
+ {
+ const CProxyItem &item = _items[index];
+ folder = item.Folder;
+ realIndex = item.Index;
+ }
+ else
+ {
+ folder = _proxyFolderItem;
+ realIndex = index;
+ }
+ if (realIndex >= (UInt32)folder->Folders.Size())
+ return E_INVALIDARG;
+ return BindToFolder(&folder->Folders[realIndex], resultFolder);
+ COM_TRY_END
+}
+
+STDMETHODIMP CAgentFolder::BindToFolder(const wchar_t *name, IFolderFolder **resultFolder)
+{
+ COM_TRY_BEGIN
+ int index = _proxyFolderItem->FindDirSubItemIndex(name);
+ if (index < 0)
+ return E_INVALIDARG;
+ return BindToFolder(index, resultFolder);
+ COM_TRY_END
+}
+
+STDMETHODIMP CAgentFolder::BindToParentFolder(IFolderFolder **resultFolder)
+{
+ COM_TRY_BEGIN
+ CMyComPtr<IFolderFolder> parentFolder = _parentFolder;
+ *resultFolder = parentFolder.Detach();
+ return S_OK;
+ COM_TRY_END
+}
+
+STDMETHODIMP CAgentFolder::GetStream(UInt32 index, ISequentialInStream **stream)
+{
+ CMyComPtr<IInArchiveGetStream> getStream;
+ _agentSpec->GetArchive()->QueryInterface(IID_IInArchiveGetStream, (void **)&getStream);
+ if (!getStream)
+ return S_OK;
+
+ const CProxyFolder *folder;
+ UInt32 realIndex;
+ if (_flatMode)
+ {
+ const CProxyItem &item = _items[index];
+ folder = item.Folder;
+ realIndex = item.Index;
+ }
+ else
+ {
+ folder = _proxyFolderItem;
+ realIndex = index;
+ }
+
+ UInt32 indexInArchive;
+ if (realIndex < (UInt32)folder->Folders.Size())
+ {
+ const CProxyFolder &item = folder->Folders[realIndex];
+ if (!item.IsLeaf)
+ return S_OK;
+ indexInArchive = item.Index;
+ }
+ else
+ indexInArchive = folder->Files[realIndex - folder->Folders.Size()].Index;
+ return getStream->GetStream(indexInArchive, stream);
+}
+
+STATPROPSTG kProperties[] =
+{
+ { NULL, kpidNumSubDirs, VT_UI4},
+ { NULL, kpidNumSubFiles, VT_UI4},
+ { NULL, kpidPrefix, VT_BSTR}
+};
+
+static const UInt32 kNumProperties = sizeof(kProperties) / sizeof(kProperties[0]);
+
+struct CArchiveItemPropertyTemp
+{
+ UString Name;
+ PROPID ID;
+ VARTYPE Type;
+};
+
+STDMETHODIMP CAgentFolder::GetNumberOfProperties(UInt32 *numProps)
+{
+ COM_TRY_BEGIN
+ RINOK(_agentSpec->GetArchive()->GetNumberOfProperties(numProps));
+ *numProps += kNumProperties;
+ if (!_flatMode)
+ (*numProps)--;
+ if (!_agentSpec->_proxyArchive->ThereIsPathProp)
+ (*numProps)++;
+ return S_OK;
+ COM_TRY_END
+}
+
+STDMETHODIMP CAgentFolder::GetPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType)
+{
+ COM_TRY_BEGIN
+ UInt32 numProps;
+ _agentSpec->GetArchive()->GetNumberOfProperties(&numProps);
+ if (!_agentSpec->_proxyArchive->ThereIsPathProp)
+ {
+ if (index == 0)
+ {
+ *propID = kpidName;
+ *varType = VT_BSTR;
+ *name = 0;
+ return S_OK;
+ }
+ index--;
+ }
+
+ if (index < numProps)
+ {
+ RINOK(_agentSpec->GetArchive()->GetPropertyInfo(index, name, propID, varType));
+ if (*propID == kpidPath)
+ *propID = kpidName;
+ }
+ else
+ {
+ const STATPROPSTG &srcItem = kProperties[index - numProps];
+ *propID = srcItem.propid;
+ *varType = srcItem.vt;
+ *name = 0;
+ }
+ return S_OK;
+ COM_TRY_END
+}
+
+STATPROPSTG kFolderProps[] =
+{
+ { NULL, kpidSize, VT_UI8},
+ { NULL, kpidPackSize, VT_UI8},
+ { NULL, kpidNumSubDirs, VT_UI4},
+ { NULL, kpidNumSubFiles, VT_UI4},
+ { NULL, kpidCRC, VT_UI4}
+};
+
+static const UInt32 kNumFolderProps = sizeof(kFolderProps) / sizeof(kFolderProps[0]);
+
+STDMETHODIMP CAgentFolder::GetFolderProperty(PROPID propID, PROPVARIANT *value)
+{
+ COM_TRY_BEGIN
+ NWindows::NCOM::CPropVariant prop;
+ switch(propID)
+ {
+ case kpidSize: prop = _proxyFolderItem->Size; break;
+ case kpidPackSize: prop = _proxyFolderItem->PackSize; break;
+ case kpidNumSubDirs: prop = _proxyFolderItem->NumSubFolders; break;
+ case kpidNumSubFiles: prop = _proxyFolderItem->NumSubFiles; break;
+ case kpidName: prop = _proxyFolderItem->Name; break;
+ case kpidPath: prop = _proxyFolderItem->GetFullPathPrefix(); break;
+ case kpidType: prop = UString(L"7-Zip.") + _agentSpec->ArchiveType; break;
+ case kpidCRC: if (_proxyFolderItem->CrcIsDefined) prop = _proxyFolderItem->Crc; break;
+ }
+ prop.Detach(value);
+ return S_OK;
+ COM_TRY_END
+}
+
+STDMETHODIMP CAgentFolder::GetNumberOfFolderProperties(UInt32 *numProps)
+{
+ *numProps = kNumFolderProps;
+ return S_OK;
+}
+
+STDMETHODIMP CAgentFolder::GetFolderPropertyInfo(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType)
+{
+ // if (index < kNumFolderProps)
+ {
+ const STATPROPSTG &srcItem = kFolderProps[index];
+ *propID = srcItem.propid;
+ *varType = srcItem.vt;
+ *name = 0;
+ return S_OK;
+ }
+}
+
+STDMETHODIMP CAgentFolder::GetFolderArcProps(IFolderArcProps **object)
+{
+ CMyComPtr<IFolderArcProps> temp = _agentSpec;
+ *object = temp.Detach();
+ return S_OK;
+}
+
+#ifdef NEW_FOLDER_INTERFACE
+
+STDMETHODIMP CAgentFolder::SetFlatMode(Int32 flatMode)
+{
+ _flatMode = IntToBool(flatMode);
+ return S_OK;
+}
+
+#endif
+
+void CAgentFolder::GetRealIndices(const UInt32 *indices, UInt32 numItems, CUIntVector &realIndices) const
+{
+ if (!_flatMode)
+ {
+ _proxyFolderItem->GetRealIndices(indices, numItems, realIndices);
+ return;
+ }
+ realIndices.Clear();
+ for(UInt32 i = 0; i < numItems; i++)
+ {
+ const CProxyItem &item = _items[indices[i]];
+ const CProxyFolder *folder = item.Folder;
+ UInt32 realIndex = item.Index;
+ if (realIndex < (UInt32)folder->Folders.Size())
+ continue;
+ realIndices.Add(folder->Files[realIndex - folder->Folders.Size()].Index);
+ }
+ HeapSort(&realIndices.Front(), realIndices.Size());
+}
+
+STDMETHODIMP CAgentFolder::Extract(const UInt32 *indices,
+ UInt32 numItems,
+ NExtract::NPathMode::EEnum pathMode,
+ NExtract::NOverwriteMode::EEnum overwriteMode,
+ const wchar_t *path,
+ Int32 testMode,
+ IFolderArchiveExtractCallback *extractCallback2)
+{
+ COM_TRY_BEGIN
+ CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;
+ CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;
+ UStringVector pathParts;
+ CProxyFolder *currentProxyFolder = _proxyFolderItem;
+ while (currentProxyFolder->Parent)
+ {
+ pathParts.Insert(0, currentProxyFolder->Name);
+ currentProxyFolder = currentProxyFolder->Parent;
+ }
+
+ /*
+ if (_flatMode)
+ pathMode = NExtract::NPathMode::kNoPathnames;
+ */
+
+ extractCallbackSpec->InitForMulti(false, pathMode, overwriteMode);
+
+ extractCallbackSpec->Init(NULL, &_agentSpec->GetArc(),
+ extractCallback2,
+ false, testMode ? true : false, false,
+ (path ? path : L""),
+ pathParts,
+ (UInt64)(Int64)-1);
+ CUIntVector realIndices;
+ GetRealIndices(indices, numItems, realIndices);
+ return _agentSpec->GetArchive()->Extract(&realIndices.Front(),
+ realIndices.Size(), testMode, extractCallback);
+ COM_TRY_END
+}
+
+/////////////////////////////////////////
+// CAgent
+
+CAgent::CAgent():
+ _proxyArchive(NULL),
+ _codecs(0)
+{
+}
+
+CAgent::~CAgent()
+{
+ if (_proxyArchive != NULL)
+ delete _proxyArchive;
+}
+
+STDMETHODIMP CAgent::Open(
+ IInStream *inStream,
+ const wchar_t *filePath,
+ const wchar_t *arcFormat,
+ BSTR *archiveType,
+ IArchiveOpenCallback *openArchiveCallback)
+{
+ COM_TRY_BEGIN
+ _archiveFilePath = filePath;
+ NFile::NFind::CFileInfoW fi;
+ if (!inStream)
+ {
+ if (!fi.Find(_archiveFilePath))
+ return ::GetLastError();
+ if (fi.IsDir())
+ return E_FAIL;
+ }
+ CArcInfoEx archiverInfo0, archiverInfo1;
+
+ _compressCodecsInfo.Release();
+ _codecs = new CCodecs;
+ _compressCodecsInfo = _codecs;
+ RINOK(_codecs->Load());
+
+ CIntVector formatIndices;
+ if (!_codecs->FindFormatForArchiveType(arcFormat, formatIndices))
+ return S_FALSE;
+
+ RINOK(_archiveLink.Open(_codecs, formatIndices, false, inStream, _archiveFilePath, openArchiveCallback));
+
+ CArc &arc = _archiveLink.Arcs.Back();
+ if (!inStream)
+ {
+ arc.MTimeDefined = !fi.IsDevice;
+ arc.MTime = fi.MTime;
+ }
+
+ ArchiveType = _codecs->Formats[arc.FormatIndex].Name;
+ if (archiveType == 0)
+ return S_OK;
+ return StringToBstr(ArchiveType, archiveType);
+ COM_TRY_END
+}
+
+STDMETHODIMP CAgent::ReOpen(IArchiveOpenCallback *openArchiveCallback)
+{
+ COM_TRY_BEGIN
+ if (_proxyArchive != NULL)
+ {
+ delete _proxyArchive;
+ _proxyArchive = NULL;
+ }
+ RINOK(_archiveLink.ReOpen(_codecs, _archiveFilePath, openArchiveCallback));
+ return ReadItems();
+ COM_TRY_END
+}
+
+STDMETHODIMP CAgent::Close()
+{
+ COM_TRY_BEGIN
+ return _archiveLink.Close();
+ COM_TRY_END
+}
+
+/*
+STDMETHODIMP CAgent::EnumProperties(IEnumSTATPROPSTG **EnumProperties)
+{
+ return _archive->EnumProperties(EnumProperties);
+}
+*/
+
+HRESULT CAgent::ReadItems()
+{
+ if (_proxyArchive != NULL)
+ return S_OK;
+ _proxyArchive = new CProxyArchive();
+ return _proxyArchive->Load(GetArc(), NULL);
+}
+
+STDMETHODIMP CAgent::BindToRootFolder(IFolderFolder **resultFolder)
+{
+ COM_TRY_BEGIN
+ RINOK(ReadItems());
+ CAgentFolder *folderSpec = new CAgentFolder;
+ CMyComPtr<IFolderFolder> rootFolder = folderSpec;
+ folderSpec->Init(_proxyArchive, &_proxyArchive->RootFolder, NULL, this);
+ *resultFolder = rootFolder.Detach();
+ return S_OK;
+ COM_TRY_END
+}
+
+
+STDMETHODIMP CAgent::Extract(
+ NExtract::NPathMode::EEnum pathMode,
+ NExtract::NOverwriteMode::EEnum overwriteMode,
+ const wchar_t *path,
+ Int32 testMode,
+ IFolderArchiveExtractCallback *extractCallback2)
+{
+ COM_TRY_BEGIN
+ CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;
+ CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;
+ extractCallbackSpec->InitForMulti(false, pathMode, overwriteMode);
+ extractCallbackSpec->Init(NULL, &GetArc(),
+ extractCallback2,
+ false, testMode ? true : false, false,
+ path,
+ UStringVector(),
+ (UInt64)(Int64)-1);
+ return GetArchive()->Extract(0, (UInt32)(Int32)-1, testMode, extractCallback);
+ COM_TRY_END
+}
+
+STDMETHODIMP CAgent::GetNumberOfProperties(UInt32 *numProps)
+{
+ COM_TRY_BEGIN
+ return GetArchive()->GetNumberOfProperties(numProps);
+ COM_TRY_END
+}
+
+STDMETHODIMP CAgent::GetPropertyInfo(UInt32 index,
+ BSTR *name, PROPID *propID, VARTYPE *varType)
+{
+ COM_TRY_BEGIN
+ RINOK(GetArchive()->GetPropertyInfo(index, name, propID, varType));
+ if (*propID == kpidPath)
+ *propID = kpidName;
+ return S_OK;
+ COM_TRY_END
+}
+
+STDMETHODIMP CAgent::GetArcNumLevels(UInt32 *numLevels)
+{
+ *numLevels = _archiveLink.Arcs.Size();
+ return S_OK;
+}
+
+STDMETHODIMP CAgent::GetArcProp(UInt32 level, PROPID propID, PROPVARIANT *value)
+{
+ COM_TRY_BEGIN
+ NWindows::NCOM::CPropVariant prop;
+ CArc &arc = _archiveLink.Arcs[level];
+ switch(propID)
+ {
+ case kpidType: prop = GetTypeOfArc(arc); break;
+ case kpidPath: prop = arc.Path; break;
+ default: return arc.Archive->GetArchiveProperty(propID, value);
+ }
+ prop.Detach(value);
+ return S_OK;
+ COM_TRY_END
+}
+
+STDMETHODIMP CAgent::GetArcNumProps(UInt32 level, UInt32 *numProps)
+{
+ return _archiveLink.Arcs[level].Archive->GetNumberOfArchiveProperties(numProps);
+}
+
+STDMETHODIMP CAgent::GetArcPropInfo(UInt32 level, UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType)
+{
+ return _archiveLink.Arcs[level].Archive->GetArchivePropertyInfo(index, name, propID, varType);
+}
+
+// MainItemProperty
+STDMETHODIMP CAgent::GetArcProp2(UInt32 level, PROPID propID, PROPVARIANT *value)
+{
+ return _archiveLink.Arcs[level - 1].Archive->GetProperty(_archiveLink.Arcs[level].SubfileIndex, propID, value);
+}
+
+STDMETHODIMP CAgent::GetArcNumProps2(UInt32 level, UInt32 *numProps)
+{
+ return _archiveLink.Arcs[level - 1].Archive->GetNumberOfProperties(numProps);
+}
+
+STDMETHODIMP CAgent::GetArcPropInfo2(UInt32 level, UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType)
+{
+ return _archiveLink.Arcs[level - 1].Archive->GetPropertyInfo(index, name, propID, varType);
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/Agent.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/Agent.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/Agent.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/Agent.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,251 @@
+// Agent/Agent.h
+
+#ifndef __AGENT_AGENT_H
+#define __AGENT_AGENT_H
+
+#include "Common/MyCom.h"
+
+#include "Windows/PropVariant.h"
+
+#include "../Common/OpenArchive.h"
+#include "../Common/UpdateAction.h"
+
+#ifdef NEW_FOLDER_INTERFACE
+#include "../FileManager/IFolder.h"
+#include "../Common/LoadCodecs.h"
+#endif
+
+#include "AgentProxy.h"
+#include "IFolderArchive.h"
+
+class CAgentFolder;
+
+DECL_INTERFACE(IArchiveFolderInternal, 0x01, 0xC)
+{
+ STDMETHOD(GetAgentFolder)(CAgentFolder **agentFolder) PURE;
+};
+
+struct CProxyItem
+{
+ CProxyFolder *Folder;
+ UInt32 Index;
+};
+
+class CAgent;
+
+class CAgentFolder:
+ public IFolderFolder,
+ public IFolderProperties,
+ public IGetFolderArcProps,
+ public IArchiveFolder,
+ public IArchiveFolderInternal,
+ public IInArchiveGetStream,
+#ifdef NEW_FOLDER_INTERFACE
+ public IFolderOperations,
+ public IFolderSetFlatMode,
+#endif
+ public CMyUnknownImp
+{
+public:
+
+ MY_QUERYINTERFACE_BEGIN2(IFolderFolder)
+ MY_QUERYINTERFACE_ENTRY(IFolderProperties)
+ MY_QUERYINTERFACE_ENTRY(IGetFolderArcProps)
+ MY_QUERYINTERFACE_ENTRY(IArchiveFolder)
+ MY_QUERYINTERFACE_ENTRY(IArchiveFolderInternal)
+ MY_QUERYINTERFACE_ENTRY(IInArchiveGetStream)
+ #ifdef NEW_FOLDER_INTERFACE
+ MY_QUERYINTERFACE_ENTRY(IFolderOperations)
+ MY_QUERYINTERFACE_ENTRY(IFolderSetFlatMode)
+ #endif
+ MY_QUERYINTERFACE_END
+ MY_ADDREF_RELEASE
+
+ void LoadFolder(CProxyFolder *folder);
+ HRESULT BindToFolder(CProxyFolder *folder, IFolderFolder **resultFolder);
+ void GetRealIndices(const UINT32 *indices, UINT32 numItems, CUIntVector &realIndices) const;
+
+ INTERFACE_FolderFolder(;)
+ INTERFACE_FolderProperties(;)
+
+ STDMETHOD(GetFolderArcProps)(IFolderArcProps **object);
+
+ // IArchiveFolder
+ STDMETHOD(Extract)(const UINT32 *indices, UINT32 numItems,
+ NExtract::NPathMode::EEnum pathMode,
+ NExtract::NOverwriteMode::EEnum overwriteMode,
+ const wchar_t *path,
+ Int32 testMode,
+ IFolderArchiveExtractCallback *extractCallback);
+
+ STDMETHOD(GetAgentFolder)(CAgentFolder **agentFolder);
+
+ STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **stream);
+
+ #ifdef NEW_FOLDER_INTERFACE
+ INTERFACE_FolderOperations(;)
+
+ STDMETHOD(SetFlatMode)(Int32 flatMode);
+ #endif
+
+ CAgentFolder(): _proxyFolderItem(NULL), _flatMode(0) {}
+
+ void Init(CProxyArchive *proxyHandler,
+ CProxyFolder *proxyFolderItem,
+ IFolderFolder *parentFolder,
+ CAgent *agent)
+ {
+ _proxyArchive = proxyHandler;
+ _proxyFolderItem = proxyFolderItem;
+ _parentFolder = parentFolder;
+ _agent = (IInFolderArchive *)agent;
+ _agentSpec = agent;
+ }
+
+ void GetPathParts(UStringVector &pathParts);
+ HRESULT CommonUpdateOperation(
+ bool deleteOperation,
+ bool createFolderOperation,
+ bool renameOperation,
+ const wchar_t *newItemName,
+ const NUpdateArchive::CActionSet *actionSet,
+ const UINT32 *indices, UINT32 numItems,
+ IFolderArchiveUpdateCallback *updateCallback100);
+
+
+ UString GetPrefix(UInt32 index) const;
+ UString GetName(UInt32 index) const;
+ UString GetFullPathPrefixPlusPrefix(UInt32 index) const;
+ void GetPrefixIfAny(UInt32 index, NWindows::NCOM::CPropVariant &propVariant) const;
+
+public:
+ CProxyArchive *_proxyArchive;
+ CProxyFolder *_proxyFolderItem;
+ CMyComPtr<IFolderFolder> _parentFolder;
+ CMyComPtr<IInFolderArchive> _agent;
+ CAgent *_agentSpec;
+
+ CRecordVector<CProxyItem> _items;
+ bool _flatMode;
+private:
+};
+
+class CAgent:
+ public IInFolderArchive,
+ public IFolderArcProps,
+ #ifndef EXTRACT_ONLY
+ public IOutFolderArchive,
+ public ISetProperties,
+ #endif
+ public CMyUnknownImp
+{
+public:
+
+ MY_QUERYINTERFACE_BEGIN2(IInFolderArchive)
+ MY_QUERYINTERFACE_ENTRY(IFolderArcProps)
+ #ifndef EXTRACT_ONLY
+ MY_QUERYINTERFACE_ENTRY(IOutFolderArchive)
+ MY_QUERYINTERFACE_ENTRY(ISetProperties)
+ #endif
+ MY_QUERYINTERFACE_END
+ MY_ADDREF_RELEASE
+
+ INTERFACE_IInFolderArchive(;)
+ INTERFACE_IFolderArcProps(;)
+
+ #ifndef EXTRACT_ONLY
+ INTERFACE_IOutFolderArchive(;)
+
+ HRESULT CommonUpdate(
+ const wchar_t *newArchiveName,
+ int numUpdateItems,
+ IArchiveUpdateCallback *updateCallback);
+
+ HRESULT CreateFolder(
+ const wchar_t *newArchiveName,
+ const wchar_t *folderName,
+ IFolderArchiveUpdateCallback *updateCallback100);
+
+ HRESULT RenameItem(
+ const wchar_t *newArchiveName,
+ const UINT32 *indices, UINT32 numItems,
+ const wchar_t *newItemName,
+ IFolderArchiveUpdateCallback *updateCallback100);
+
+ // ISetProperties
+ STDMETHOD(SetProperties)(const wchar_t **names, const PROPVARIANT *values, Int32 numProperties);
+ #endif
+
+ CCodecs *_codecs;
+ CMyComPtr<ICompressCodecsInfo> _compressCodecsInfo;
+
+ CAgent();
+ ~CAgent();
+private:
+ HRESULT ReadItems();
+public:
+ CProxyArchive *_proxyArchive;
+ CArchiveLink _archiveLink;
+
+
+ UString ArchiveType;
+
+ UStringVector _names;
+ UString _folderPrefix;
+
+ UString _archiveNamePrefix;
+ CAgentFolder *_agentFolder;
+
+ UString _archiveFilePath;
+
+ #ifndef EXTRACT_ONLY
+ CObjectVector<UString> m_PropNames;
+ CObjectVector<NWindows::NCOM::CPropVariant> m_PropValues;
+ #endif
+
+ const CArc &GetArc() { return _archiveLink.Arcs.Back(); }
+ IInArchive *GetArchive() { if ( _archiveLink.Arcs.IsEmpty()) return 0; return GetArc().Archive; }
+ bool CanUpdate() const { return _archiveLink.Arcs.Size() <= 1; }
+
+ UString GetTypeOfArc(const CArc &arc) const { return _codecs->Formats[arc.FormatIndex].Name; }
+ UString GetErrorMessage() const
+ {
+ UString s;
+ for (int i = _archiveLink.Arcs.Size() - 1; i >= 0; i--)
+ {
+ const CArc &arc = _archiveLink.Arcs[i];
+ if (arc.ErrorMessage.IsEmpty())
+ continue;
+ if (!s.IsEmpty())
+ s += L"--------------------\n";
+ s += arc.ErrorMessage;
+ s += L"\n\n[";
+ s += GetTypeOfArc(arc);
+ s += L"] ";
+ s += arc.Path;
+ s += L"\n";
+ }
+ return s;
+ }
+};
+
+#ifdef NEW_FOLDER_INTERFACE
+class CArchiveFolderManager:
+ public IFolderManager,
+ public CMyUnknownImp
+{
+public:
+ MY_UNKNOWN_IMP1(IFolderManager)
+
+ INTERFACE_IFolderManager(;)
+
+ CArchiveFolderManager(): _codecs(0) {}
+private:
+ void LoadFormats();
+ int FindFormat(const UString &type);
+ CCodecs *_codecs;
+ CMyComPtr<ICompressCodecsInfo> _compressCodecsInfo;
+};
+#endif
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/AgentOut.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/AgentOut.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/AgentOut.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/AgentOut.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,533 @@
+// AgentOut.cpp
+
+#include "StdAfx.h"
+
+#include "Common/IntToString.h"
+#include "Common/StringConvert.h"
+
+#include "Windows/FileDir.h"
+#include "Windows/PropVariant.h"
+#include "Windows/PropVariantConversions.h"
+#include "Windows/Time.h"
+
+#include "../../Compress/CopyCoder.h"
+
+#include "../../Common/FileStreams.h"
+
+#include "../Common/EnumDirItems.h"
+#include "../Common/OpenArchive.h"
+#include "../Common/UpdateCallback.h"
+#include "../Common/UpdatePair.h"
+
+#include "Agent.h"
+#include "UpdateCallbackAgent.h"
+
+using namespace NWindows;
+using namespace NCOM;
+
+STDMETHODIMP CAgent::SetFolder(IFolderFolder *folder)
+{
+ _archiveNamePrefix.Empty();
+ if (folder == NULL)
+ {
+ _agentFolder = NULL;
+ return S_OK;
+ }
+ else
+ {
+ CMyComPtr<IFolderFolder> archiveFolder = folder;
+ CMyComPtr<IArchiveFolderInternal> archiveFolderInternal;
+ RINOK(archiveFolder.QueryInterface(IID_IArchiveFolderInternal, &archiveFolderInternal));
+ RINOK(archiveFolderInternal->GetAgentFolder(&_agentFolder));
+ }
+
+ UStringVector pathParts;
+ pathParts.Clear();
+ CMyComPtr<IFolderFolder> folderItem = folder;
+ if (folderItem != NULL)
+ for (;;)
+ {
+ CMyComPtr<IFolderFolder> newFolder;
+ folderItem->BindToParentFolder(&newFolder);
+ if (newFolder == NULL)
+ break;
+
+ NCOM::CPropVariant prop;
+ if (folderItem->GetFolderProperty(kpidName, &prop) == S_OK)
+ if (prop.vt == VT_BSTR)
+ pathParts.Insert(0, (const wchar_t *)prop.bstrVal);
+ folderItem = newFolder;
+ }
+
+ for (int i = 0; i < pathParts.Size(); i++)
+ {
+ _archiveNamePrefix += pathParts[i];
+ _archiveNamePrefix += WCHAR_PATH_SEPARATOR;
+ }
+ return S_OK;
+}
+
+STDMETHODIMP CAgent::SetFiles(const wchar_t *folderPrefix,
+ const wchar_t **names, UInt32 numNames)
+{
+ _folderPrefix = folderPrefix;
+ _names.Clear();
+ _names.Reserve(numNames);
+ for (UInt32 i = 0; i < numNames; i++)
+ _names.Add(names[i]);
+ return S_OK;
+}
+
+static HRESULT EnumerateArchiveItems(CAgent *agent,
+ const CProxyFolder &item,
+ const UString &prefix,
+ CObjectVector<CArcItem> &arcItems)
+{
+ int i;
+ for (i = 0; i < item.Files.Size(); i++)
+ {
+ const CProxyFile &fileItem = item.Files[i];
+ CArcItem ai;
+ RINOK(agent->GetArc().GetItemMTime(fileItem.Index, ai.MTime, ai.MTimeDefined));
+
+ CPropVariant property;
+ agent->GetArchive()->GetProperty(fileItem.Index, kpidSize, &property);
+ ai.SizeDefined = (property.vt != VT_EMPTY);
+ if (ai.SizeDefined)
+ ai.Size = ConvertPropVariantToUInt64(property);
+ ai.IsDir = false;
+ ai.Name = prefix + fileItem.Name;
+ ai.Censored = true; // test it
+ ai.IndexInServer = fileItem.Index;
+ arcItems.Add(ai);
+ }
+ for (i = 0; i < item.Folders.Size(); i++)
+ {
+ const CProxyFolder &dirItem = item.Folders[i];
+ UString fullName = prefix + dirItem.Name;
+ if (dirItem.IsLeaf)
+ {
+ CArcItem ai;
+ RINOK(agent->GetArc().GetItemMTime(dirItem.Index, ai.MTime, ai.MTimeDefined));
+ ai.IsDir = true;
+ ai.SizeDefined = false;
+ ai.Name = fullName;
+ ai.Censored = true; // test it
+ ai.IndexInServer = dirItem.Index;
+ arcItems.Add(ai);
+ }
+ RINOK(EnumerateArchiveItems(agent, dirItem, fullName + UString(WCHAR_PATH_SEPARATOR), arcItems));
+ }
+ return S_OK;
+}
+
+struct CAgUpCallbackImp: public IUpdateProduceCallback
+{
+ const CObjectVector<CArcItem> *_arcItems;
+ IFolderArchiveUpdateCallback *_callback;
+
+ CAgUpCallbackImp(const CObjectVector<CArcItem> *a,
+ IFolderArchiveUpdateCallback *callback): _arcItems(a), _callback(callback) {}
+ HRESULT ShowDeleteFile(int arcIndex);
+};
+
+HRESULT CAgUpCallbackImp::ShowDeleteFile(int arcIndex)
+{
+ return _callback->DeleteOperation((*_arcItems)[arcIndex].Name);
+}
+
+STDMETHODIMP CAgent::DoOperation(
+ CCodecs *codecs,
+ int formatIndex,
+ const wchar_t *newArchiveName,
+ const Byte *stateActions,
+ const wchar_t *sfxModule,
+ IFolderArchiveUpdateCallback *updateCallback100)
+{
+ if (!CanUpdate())
+ return E_NOTIMPL;
+ NUpdateArchive::CActionSet actionSet;
+ int i;
+ for (i = 0; i < NUpdateArchive::NPairState::kNumValues; i++)
+ actionSet.StateActions[i] = (NUpdateArchive::NPairAction::EEnum)stateActions[i];
+
+ CDirItems dirItems;
+
+ {
+ UString folderPrefix = _folderPrefix;
+ NFile::NName::NormalizeDirPathPrefix(folderPrefix);
+ UStringVector errorPaths;
+ CRecordVector<DWORD> errorCodes;
+ dirItems.EnumerateDirItems2(folderPrefix, _archiveNamePrefix, _names, errorPaths, errorCodes);
+ if (errorCodes.Size() > 0)
+ return errorCodes.Front();
+ }
+
+ CMyComPtr<IOutArchive> outArchive;
+ if (GetArchive())
+ {
+ RINOK(GetArchive()->QueryInterface(IID_IOutArchive, (void **)&outArchive));
+ }
+ else
+ {
+ if (formatIndex < 0)
+ return E_FAIL;
+ RINOK(codecs->CreateOutArchive(formatIndex, outArchive));
+ #ifdef EXTERNAL_CODECS
+ {
+ CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;
+ outArchive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);
+ if (setCompressCodecsInfo)
+ {
+ RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));
+ }
+ }
+ #endif
+
+ }
+
+ NFileTimeType::EEnum fileTimeType;
+ UInt32 value;
+ RINOK(outArchive->GetFileTimeType(&value));
+
+ switch(value)
+ {
+ case NFileTimeType::kWindows:
+ case NFileTimeType::kDOS:
+ case NFileTimeType::kUnix:
+ fileTimeType = NFileTimeType::EEnum(value);
+ break;
+ default:
+ return E_FAIL;
+ }
+
+
+ CObjectVector<CArcItem> arcItems;
+ if (GetArchive())
+ {
+ RINOK(ReadItems());
+ EnumerateArchiveItems(this, _proxyArchive->RootFolder, L"", arcItems);
+ }
+
+ CRecordVector<CUpdatePair2> updatePairs2;
+
+ {
+ CRecordVector<CUpdatePair> updatePairs;
+ GetUpdatePairInfoList(dirItems, arcItems, fileTimeType, updatePairs);
+ CAgUpCallbackImp upCallback(&arcItems, updateCallback100);
+ UpdateProduce(updatePairs, actionSet, updatePairs2, &upCallback);
+ }
+
+ UInt32 numFiles = 0;
+ for (i = 0; i < updatePairs2.Size(); i++)
+ if (updatePairs2[i].NewData)
+ numFiles++;
+
+ if (updateCallback100)
+ {
+ RINOK(updateCallback100->SetNumFiles(numFiles));
+ }
+
+ CUpdateCallbackAgent updateCallbackAgent;
+ updateCallbackAgent.SetCallback(updateCallback100);
+ CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;
+ CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec );
+
+ updateCallbackSpec->DirItems = &dirItems;
+ updateCallbackSpec->ArcItems = &arcItems;
+ updateCallbackSpec->UpdatePairs = &updatePairs2;
+ updateCallbackSpec->Archive = GetArchive();
+ updateCallbackSpec->Callback = &updateCallbackAgent;
+
+ COutFileStream *outStreamSpec = new COutFileStream;
+ CMyComPtr<IOutStream> outStream(outStreamSpec);
+ UString archiveName = newArchiveName;
+ {
+ UString resultPath;
+ int pos;
+ if (!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))
+ return E_FAIL;
+ NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));
+ }
+ if (!outStreamSpec->Create(archiveName, true))
+ {
+ // ShowLastErrorMessage();
+ return E_FAIL;
+ }
+
+ CMyComPtr<ISetProperties> setProperties;
+ if (outArchive->QueryInterface(IID_ISetProperties, (void **)&setProperties) == S_OK)
+ {
+ if (m_PropNames.Size() == 0)
+ {
+ RINOK(setProperties->SetProperties(0, 0, 0));
+ }
+ else
+ {
+ CRecordVector<const wchar_t *> names;
+ for(i = 0; i < m_PropNames.Size(); i++)
+ names.Add((const wchar_t *)m_PropNames[i]);
+
+ NWindows::NCOM::CPropVariant *propValues = new NWindows::NCOM::CPropVariant[m_PropValues.Size()];
+ try
+ {
+ for (int i = 0; i < m_PropValues.Size(); i++)
+ propValues[i] = m_PropValues[i];
+ RINOK(setProperties->SetProperties(&names.Front(), propValues, names.Size()));
+ }
+ catch(...)
+ {
+ delete []propValues;
+ return E_FAIL;
+ }
+ delete []propValues;
+ }
+ }
+ m_PropNames.Clear();
+ m_PropValues.Clear();
+
+ if (sfxModule != NULL)
+ {
+ CInFileStream *sfxStreamSpec = new CInFileStream;
+ CMyComPtr<IInStream> sfxStream(sfxStreamSpec);
+ if (!sfxStreamSpec->Open(sfxModule))
+ return E_FAIL;
+ // throw "Can't open sfx module";
+ RINOK(NCompress::CopyStream(sfxStream, outStream, NULL));
+ }
+
+ RINOK(outArchive->UpdateItems(outStream, updatePairs2.Size(),updateCallback));
+ return outStreamSpec->Close();
+}
+
+STDMETHODIMP CAgent::DoOperation2(
+ const wchar_t *newArchiveName,
+ const Byte *stateActions,
+ const wchar_t *sfxModule,
+ IFolderArchiveUpdateCallback *updateCallback100)
+{
+ return DoOperation(_codecs, -1, newArchiveName,
+ stateActions, sfxModule, updateCallback100);
+}
+
+HRESULT CAgent::CommonUpdate(
+ const wchar_t *newArchiveName,
+ int numUpdateItems,
+ IArchiveUpdateCallback *updateCallback)
+{
+ if (!CanUpdate())
+ return E_NOTIMPL;
+ CMyComPtr<IOutArchive> outArchive;
+ RINOK(GetArchive()->QueryInterface(IID_IOutArchive, (void **)&outArchive));
+
+ COutFileStream *outStreamSpec = new COutFileStream;
+ CMyComPtr<IOutStream> outStream(outStreamSpec);
+
+ UString archiveName = newArchiveName;
+ {
+ UString resultPath;
+ int pos;
+ if (!NFile::NDirectory::MyGetFullPathName(archiveName, resultPath, pos))
+ throw 141716;
+ NFile::NDirectory::CreateComplexDirectory(resultPath.Left(pos));
+ }
+
+ /*
+ bool isOK = false;
+ for (int i = 0; i < (1 << 16); i++)
+ {
+ resultName = newArchiveName;
+ if (i > 0)
+ {
+ wchar_t s[16];
+ ConvertUInt32ToString(i, s);
+ resultName += s;
+ }
+ if (outStreamSpec->Open(realPath))
+ {
+ isOK = true;
+ break;
+ }
+ if (::GetLastError() != ERROR_FILE_EXISTS)
+ return ::GetLastError();
+ }
+ if (!isOK)
+ return ::GetLastError();
+ */
+ if (!outStreamSpec->Create(archiveName, true))
+ {
+ // ShowLastErrorMessage();
+ return E_FAIL;
+ }
+
+ RINOK(outArchive->UpdateItems(outStream, numUpdateItems, updateCallback));
+ return outStreamSpec->Close();
+}
+
+
+STDMETHODIMP CAgent::DeleteItems(
+ const wchar_t *newArchiveName,
+ const UInt32 *indices, UInt32 numItems,
+ IFolderArchiveUpdateCallback *updateCallback100)
+{
+ if (!CanUpdate())
+ return E_NOTIMPL;
+ CUpdateCallbackAgent updateCallbackAgent;
+ updateCallbackAgent.SetCallback(updateCallback100);
+ CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;
+ CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);
+
+ CUIntVector realIndices;
+ _agentFolder->GetRealIndices(indices, numItems, realIndices);
+ CRecordVector<CUpdatePair2> updatePairs;
+ int curIndex = 0;
+ UInt32 numItemsInArchive;
+ RINOK(GetArchive()->GetNumberOfItems(&numItemsInArchive));
+ for (UInt32 i = 0; i < numItemsInArchive; i++)
+ {
+ if (curIndex < realIndices.Size())
+ if (realIndices[curIndex] == i)
+ {
+ curIndex++;
+ continue;
+ }
+ CUpdatePair2 up2;
+ up2.NewData = up2.NewProps = false;
+ up2.IsAnti = false; // check it. Maybe it can be undefined
+ up2.ArcIndex = i;
+ updatePairs.Add(up2);
+ }
+ updateCallbackSpec->UpdatePairs = &updatePairs;
+ updateCallbackSpec->Archive = GetArchive();
+ updateCallbackSpec->Callback = &updateCallbackAgent;
+ return CommonUpdate(newArchiveName, updatePairs.Size(), updateCallback);
+}
+
+HRESULT CAgent::CreateFolder(
+ const wchar_t *newArchiveName,
+ const wchar_t *folderName,
+ IFolderArchiveUpdateCallback *updateCallback100)
+{
+ if (!CanUpdate())
+ return E_NOTIMPL;
+ CUpdateCallbackAgent updateCallbackAgent;
+ updateCallbackAgent.SetCallback(updateCallback100);
+ CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;
+ CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);
+
+ CRecordVector<CUpdatePair2> updatePairs;
+ UInt32 numItemsInArchive;
+ RINOK(GetArchive()->GetNumberOfItems(&numItemsInArchive));
+ for (UInt32 i = 0; i < numItemsInArchive; i++)
+ {
+ CUpdatePair2 up2;
+ up2.NewData = up2.NewProps = false;
+ up2.IsAnti = false; // check it.
+ up2.ArcIndex = i;
+ updatePairs.Add(up2);
+ }
+ CUpdatePair2 up2;
+ up2.NewData = up2.NewProps = true;
+ up2.IsAnti = false;
+ up2.DirIndex = 0;
+
+ updatePairs.Add(up2);
+
+ updatePairs.ReserveDown();
+
+ CDirItems dirItems;
+ CDirItem di;
+
+ di.Attrib = FILE_ATTRIBUTE_DIRECTORY;
+ di.Size = 0;
+ di.Name = _agentFolder->_proxyFolderItem->GetFullPathPrefix() + folderName;
+
+ FILETIME ft;
+ NTime::GetCurUtcFileTime(ft);
+ di.CTime = di.ATime = di.MTime = ft;
+
+ dirItems.Items.Add(di);
+
+ updateCallbackSpec->Callback = &updateCallbackAgent;
+ updateCallbackSpec->DirItems = &dirItems;
+ updateCallbackSpec->UpdatePairs = &updatePairs;
+ updateCallbackSpec->Archive = GetArchive();
+ return CommonUpdate(newArchiveName, updatePairs.Size(), updateCallback);
+}
+
+
+HRESULT CAgent::RenameItem(
+ const wchar_t *newArchiveName,
+ const UInt32 *indices, UInt32 numItems,
+ const wchar_t *newItemName,
+ IFolderArchiveUpdateCallback *updateCallback100)
+{
+ if (!CanUpdate())
+ return E_NOTIMPL;
+ if (numItems != 1)
+ return E_INVALIDARG;
+ CUpdateCallbackAgent updateCallbackAgent;
+ updateCallbackAgent.SetCallback(updateCallback100);
+ CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;
+ CMyComPtr<IArchiveUpdateCallback> updateCallback(updateCallbackSpec);
+
+ CUIntVector realIndices;
+ _agentFolder->GetRealIndices(indices, numItems, realIndices);
+
+ UString fullPrefix = _agentFolder->GetFullPathPrefixPlusPrefix(indices[0]);
+ UString oldItemPath = fullPrefix + _agentFolder->GetName(indices[0]);
+ UString newItemPath = fullPrefix + newItemName;
+
+ CRecordVector<CUpdatePair2> updatePairs;
+ UStringVector newNames;
+
+ int curIndex = 0;
+ UInt32 numItemsInArchive;
+ RINOK(GetArchive()->GetNumberOfItems(&numItemsInArchive));
+ for (UInt32 i = 0; i < numItemsInArchive; i++)
+ {
+ if (curIndex < realIndices.Size())
+ if (realIndices[curIndex] == i)
+ {
+ CUpdatePair2 up2;
+ up2.NewData = false;
+ up2.NewProps = true;
+ RINOK(GetArc().IsItemAnti(i, up2.IsAnti));
+ up2.ArcIndex = i;
+
+ UString oldFullPath;
+ RINOK(GetArc().GetItemPath(i, oldFullPath));
+
+ if (oldItemPath.CompareNoCase(oldFullPath.Left(oldItemPath.Length())) != 0)
+ return E_INVALIDARG;
+
+ up2.NewNameIndex = newNames.Add(newItemPath + oldFullPath.Mid(oldItemPath.Length()));
+ updatePairs.Add(up2);
+ curIndex++;
+ continue;
+ }
+ CUpdatePair2 up2;
+ up2.NewData = up2.NewProps = false;
+ up2.IsAnti = false;
+ up2.ArcIndex = i;
+ updatePairs.Add(up2);
+ }
+ updateCallbackSpec->Callback = &updateCallbackAgent;
+ updateCallbackSpec->UpdatePairs = &updatePairs;
+ updateCallbackSpec->NewNames = &newNames;
+ updateCallbackSpec->Archive = GetArchive();
+ return CommonUpdate(newArchiveName, updatePairs.Size(), updateCallback);
+}
+
+STDMETHODIMP CAgent::SetProperties(const wchar_t **names,
+ const PROPVARIANT *values, Int32 numProperties)
+{
+ m_PropNames.Clear();
+ m_PropValues.Clear();
+ for (int i = 0; i < numProperties; i++)
+ {
+ m_PropNames.Add(names[i]);
+ m_PropValues.Add(values[i]);
+ }
+ return S_OK;
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/AgentProxy.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/AgentProxy.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/AgentProxy.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/AgentProxy.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,246 @@
+// AgentProxy.cpp
+
+#include "StdAfx.h"
+
+#include "../../../../C/Sort.h"
+
+#include "Windows/PropVariant.h"
+#include "Windows/PropVariantConversions.h"
+
+#include "../Common/OpenArchive.h"
+
+#include "AgentProxy.h"
+
+using namespace NWindows;
+
+int CProxyFolder::FindDirSubItemIndex(const UString &name, int &insertPos) const
+{
+ int left = 0, right = Folders.Size();
+ for (;;)
+ {
+ if (left == right)
+ {
+ insertPos = left;
+ return -1;
+ }
+ int mid = (left + right) / 2;
+ int compare = name.CompareNoCase(Folders[mid].Name);
+ if (compare == 0)
+ return mid;
+ if (compare < 0)
+ right = mid;
+ else
+ left = mid + 1;
+ }
+}
+
+int CProxyFolder::FindDirSubItemIndex(const UString &name) const
+{
+ int insertPos;
+ return FindDirSubItemIndex(name, insertPos);
+}
+
+void CProxyFolder::AddFileSubItem(UInt32 index, const UString &name)
+{
+ Files.Add(CProxyFile());
+ Files.Back().Name = name;
+ Files.Back().Index = index;
+}
+
+CProxyFolder* CProxyFolder::AddDirSubItem(UInt32 index, bool leaf, const UString &name)
+{
+ int insertPos;
+ int folderIndex = FindDirSubItemIndex(name, insertPos);
+ if (folderIndex >= 0)
+ {
+ CProxyFolder *item = &Folders[folderIndex];
+ if (leaf)
+ {
+ item->Index = index;
+ item->IsLeaf = true;
+ }
+ return item;
+ }
+ Folders.Insert(insertPos, CProxyFolder());
+ CProxyFolder *item = &Folders[insertPos];
+ item->Name = name;
+ item->Index = index;
+ item->Parent = this;
+ item->IsLeaf = leaf;
+ return item;
+}
+
+void CProxyFolder::Clear()
+{
+ Folders.Clear();
+ Files.Clear();
+}
+
+void CProxyFolder::GetPathParts(UStringVector &pathParts) const
+{
+ pathParts.Clear();
+ UString result;
+ const CProxyFolder *current = this;
+ while (current->Parent != NULL)
+ {
+ pathParts.Insert(0, (const wchar_t *)current->Name);
+ current = current->Parent;
+ }
+}
+
+UString CProxyFolder::GetFullPathPrefix() const
+{
+ UString result;
+ const CProxyFolder *current = this;
+ while (current->Parent != NULL)
+ {
+ result = current->Name + UString(WCHAR_PATH_SEPARATOR) + result;
+ current = current->Parent;
+ }
+ return result;
+}
+
+UString CProxyFolder::GetItemName(UInt32 index) const
+{
+ if (index < (UInt32)Folders.Size())
+ return Folders[index].Name;
+ return Files[index - Folders.Size()].Name;
+}
+
+void CProxyFolder::AddRealIndices(CUIntVector &realIndices) const
+{
+ if (IsLeaf)
+ realIndices.Add(Index);
+ int i;
+ for (i = 0; i < Folders.Size(); i++)
+ Folders[i].AddRealIndices(realIndices);
+ for (i = 0; i < Files.Size(); i++)
+ realIndices.Add(Files[i].Index);
+}
+
+void CProxyFolder::GetRealIndices(const UInt32 *indices, UInt32 numItems, CUIntVector &realIndices) const
+{
+ realIndices.Clear();
+ for (UInt32 i = 0; i < numItems; i++)
+ {
+ int index = indices[i];
+ int numDirItems = Folders.Size();
+ if (index < numDirItems)
+ Folders[index].AddRealIndices(realIndices);
+ else
+ realIndices.Add(Files[index - numDirItems].Index);
+ }
+ HeapSort(&realIndices.Front(), realIndices.Size());
+}
+
+///////////////////////////////////////////////
+// CProxyArchive
+
+static UInt64 GetSize(IInArchive *archive, UInt32 index, PROPID propID)
+{
+ NCOM::CPropVariant prop;
+ if (archive->GetProperty(index, propID, &prop) == S_OK)
+ if (prop.vt != VT_EMPTY)
+ return ConvertPropVariantToUInt64(prop);
+ return 0;
+}
+
+void CProxyFolder::CalculateSizes(IInArchive *archive)
+{
+ Size = PackSize = 0;
+ NumSubFolders = Folders.Size();
+ NumSubFiles = Files.Size();
+ CrcIsDefined = true;
+ Crc = 0;
+ int i;
+ for (i = 0; i < Files.Size(); i++)
+ {
+ UInt32 index = Files[i].Index;
+ Size += GetSize(archive, index, kpidSize);
+ PackSize += GetSize(archive, index, kpidPackSize);
+ {
+ NCOM::CPropVariant prop;
+ if (archive->GetProperty(index, kpidCRC, &prop) == S_OK && prop.vt == VT_UI4)
+ Crc += prop.ulVal;
+ else
+ CrcIsDefined = false;
+ }
+ }
+ for (i = 0; i < Folders.Size(); i++)
+ {
+ CProxyFolder &f = Folders[i];
+ f.CalculateSizes(archive);
+ Size += f.Size;
+ PackSize += f.PackSize;
+ NumSubFiles += f.NumSubFiles;
+ NumSubFolders += f.NumSubFolders;
+ Crc += f.Crc;
+ if (!f.CrcIsDefined)
+ CrcIsDefined = false;
+ }
+}
+
+HRESULT CProxyArchive::Load(const CArc &arc, IProgress *progress)
+{
+ RootFolder.Clear();
+ IInArchive *archive = arc.Archive;
+ {
+ ThereIsPathProp = false;
+ UInt32 numProps;
+ archive->GetNumberOfProperties(&numProps);
+ for (UInt32 i = 0; i < numProps; i++)
+ {
+ CMyComBSTR name;
+ PROPID propID;
+ VARTYPE varType;
+ RINOK(archive->GetPropertyInfo(i, &name, &propID, &varType));
+ if (propID == kpidPath)
+ {
+ ThereIsPathProp = true;
+ break;
+ }
+ }
+ }
+
+ UInt32 numItems;
+ RINOK(archive->GetNumberOfItems(&numItems));
+ if (progress != NULL)
+ {
+ UInt64 totalItems = numItems;
+ RINOK(progress->SetTotal(totalItems));
+ }
+ UString fileName;
+ for (UInt32 i = 0; i < numItems; i++)
+ {
+ if (progress != NULL && (i & 0xFFFFF) == 0)
+ {
+ UInt64 currentItemIndex = i;
+ RINOK(progress->SetCompleted(¤tItemIndex));
+ }
+ UString filePath;
+ RINOK(arc.GetItemPath(i, filePath));
+ CProxyFolder *curItem = &RootFolder;
+ int len = filePath.Length();
+ fileName.Empty();
+ for (int j = 0; j < len; j++)
+ {
+ wchar_t c = filePath[j];
+ if (c == WCHAR_PATH_SEPARATOR || c == L'/')
+ {
+ curItem = curItem->AddDirSubItem((UInt32)(Int32)-1, false, fileName);
+ fileName.Empty();
+ }
+ else
+ fileName += c;
+ }
+
+ bool isFolder;
+ RINOK(IsArchiveItemFolder(archive, i, isFolder));
+ if (isFolder)
+ curItem->AddDirSubItem(i, true, fileName);
+ else
+ curItem->AddFileSubItem(i, fileName);
+ }
+ RootFolder.CalculateSizes(archive);
+ return S_OK;
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/AgentProxy.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/AgentProxy.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/AgentProxy.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/AgentProxy.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,53 @@
+// AgentProxy.h
+
+#ifndef __AGENT_PROXY_H
+#define __AGENT_PROXY_H
+
+#include "Common/MyString.h"
+
+#include "../Common/OpenArchive.h"
+
+struct CProxyFile
+{
+ UInt32 Index;
+ UString Name;
+};
+
+struct CProxyFolder: public CProxyFile
+{
+ CProxyFolder *Parent;
+ CObjectVector<CProxyFolder> Folders;
+ CObjectVector<CProxyFile> Files;
+ bool IsLeaf;
+
+ bool CrcIsDefined;
+ UInt64 Size;
+ UInt64 PackSize;
+ UInt32 Crc;
+ UInt32 NumSubFolders;
+ UInt32 NumSubFiles;
+
+ CProxyFolder(): Parent(NULL) {};
+ int FindDirSubItemIndex(const UString &name, int &insertPos) const;
+ int FindDirSubItemIndex(const UString &name) const;
+ CProxyFolder* AddDirSubItem(UInt32 index, bool leaf, const UString &name);
+ void AddFileSubItem(UInt32 index, const UString &name);
+ void Clear();
+
+ void GetPathParts(UStringVector &pathParts) const;
+ UString GetFullPathPrefix() const;
+ UString GetItemName(UInt32 index) const;
+ void AddRealIndices(CUIntVector &realIndices) const;
+ void GetRealIndices(const UInt32 *indices, UInt32 numItems, CUIntVector &realIndices) const;
+ void CalculateSizes(IInArchive *archive);
+};
+
+struct CProxyArchive
+{
+ CProxyFolder RootFolder;
+ bool ThereIsPathProp;
+
+ HRESULT Load(const CArc &arc, IProgress *progress);
+};
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/ArchiveFolder.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/ArchiveFolder.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/ArchiveFolder.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/ArchiveFolder.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,59 @@
+// Agent/ArchiveFolder.cpp
+
+#include "StdAfx.h"
+
+#include "Common/ComTry.h"
+
+#include "../Common/ArchiveExtractCallback.h"
+
+#include "Agent.h"
+
+using namespace NWindows;
+using namespace NCOM;
+
+STDMETHODIMP CAgentFolder::CopyTo(const UInt32 *indices, UInt32 numItems,
+ const wchar_t *path, IFolderOperationsExtractCallback *callback)
+{
+ COM_TRY_BEGIN
+ CArchiveExtractCallback *extractCallbackSpec = new
+ CArchiveExtractCallback;
+ CMyComPtr<IArchiveExtractCallback> extractCallback = extractCallbackSpec;
+ UStringVector pathParts;
+ CProxyFolder *currentProxyFolder = _proxyFolderItem;
+ while (currentProxyFolder->Parent)
+ {
+ pathParts.Insert(0, currentProxyFolder->Name);
+ currentProxyFolder = currentProxyFolder->Parent;
+ }
+
+ CMyComPtr<IFolderArchiveExtractCallback> extractCallback2;
+ {
+ CMyComPtr<IFolderOperationsExtractCallback> callbackWrap = callback;
+ RINOK(callbackWrap.QueryInterface(
+ IID_IFolderArchiveExtractCallback, &extractCallback2));
+ }
+
+ NExtract::NPathMode::EEnum pathMode = _flatMode ?
+ NExtract::NPathMode::kNoPathnames :
+ NExtract::NPathMode::kCurrentPathnames;
+
+ extractCallbackSpec->InitForMulti(false, pathMode, NExtract::NOverwriteMode::kAskBefore);
+ extractCallbackSpec->Init(NULL, &_agentSpec->GetArc(),
+ extractCallback2,
+ false, false, false,
+ path,
+ pathParts,
+ (UInt64)(Int64)-1);
+ CUIntVector realIndices;
+ GetRealIndices(indices, numItems, realIndices);
+ return _agentSpec->GetArchive()->Extract(&realIndices.Front(),
+ realIndices.Size(), BoolToInt(false), extractCallback);
+ COM_TRY_END
+}
+
+STDMETHODIMP CAgentFolder::MoveTo(const UInt32 * /* indices */, UInt32 /* numItems */,
+ const wchar_t * /* path */, IFolderOperationsExtractCallback * /* callback */)
+{
+ return E_NOTIMPL;
+}
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/ArchiveFolderOpen.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/ArchiveFolderOpen.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/ArchiveFolderOpen.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/ArchiveFolderOpen.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,144 @@
+// Zip/ArchiveFolder.cpp
+
+#include "StdAfx.h"
+
+#include "Agent.h"
+
+#include "Common/StringConvert.h"
+
+extern HINSTANCE g_hInstance;
+
+static inline UINT GetCurrentFileCodePage()
+{
+ #ifdef UNDER_CE
+ return CP_ACP;
+ #else
+ return AreFileApisANSI() ? CP_ACP : CP_OEMCP;
+ #endif
+}
+
+void CArchiveFolderManager::LoadFormats()
+{
+ if (!_codecs)
+ {
+ _compressCodecsInfo = _codecs = new CCodecs;
+ _codecs->Load();
+ }
+}
+
+int CArchiveFolderManager::FindFormat(const UString &type)
+{
+ for (int i = 0; i < _codecs->Formats.Size(); i++)
+ if (type.CompareNoCase(_codecs->Formats[i].Name) == 0)
+ return i;
+ return -1;
+}
+
+STDMETHODIMP CArchiveFolderManager::OpenFolderFile(IInStream *inStream,
+ const wchar_t *filePath, const wchar_t *arcFormat,
+ IFolderFolder **resultFolder, IProgress *progress)
+{
+ CMyComPtr<IArchiveOpenCallback> openArchiveCallback;
+ if (progress != 0)
+ {
+ CMyComPtr<IProgress> progressWrapper = progress;
+ progressWrapper.QueryInterface(IID_IArchiveOpenCallback, &openArchiveCallback);
+ }
+ CAgent *agent = new CAgent();
+ CMyComPtr<IInFolderArchive> archive = agent;
+ RINOK(agent->Open(inStream, filePath, arcFormat, NULL, openArchiveCallback));
+ return agent->BindToRootFolder(resultFolder);
+}
+
+/*
+HRESULT CAgent::FolderReOpen(
+ IArchiveOpenCallback *openArchiveCallback)
+{
+ return ReOpenArchive(_archive, _archiveFilePath);
+}
+*/
+
+
+/*
+STDMETHODIMP CArchiveFolderManager::GetExtensions(const wchar_t *type, BSTR *extensions)
+{
+ *extensions = 0;
+ int formatIndex = FindFormat(type);
+ if (formatIndex < 0)
+ return E_INVALIDARG;
+ // Exts[0].Ext;
+ return StringToBstr(_codecs.Formats[formatIndex].GetAllExtensions(), extensions);
+}
+*/
+
+static void AddIconExt(const CCodecIcons &lib, UString &dest)
+{
+ for (int j = 0; j < lib.IconPairs.Size(); j++)
+ {
+ if (!dest.IsEmpty())
+ dest += L' ';
+ dest += lib.IconPairs[j].Ext;
+ }
+}
+
+STDMETHODIMP CArchiveFolderManager::GetExtensions(BSTR *extensions)
+{
+ LoadFormats();
+ *extensions = 0;
+ UString res;
+ for (int i = 0; i < _codecs->Libs.Size(); i++)
+ AddIconExt(_codecs->Libs[i], res);
+ AddIconExt(_codecs->InternalIcons, res);
+ return StringToBstr(res, extensions);
+}
+
+STDMETHODIMP CArchiveFolderManager::GetIconPath(const wchar_t *ext, BSTR *iconPath, Int32 *iconIndex)
+{
+ *iconPath = 0;
+ *iconIndex = 0;
+#ifdef _WIN32
+ LoadFormats();
+ for (int i = 0; i < _codecs->Libs.Size(); i++)
+ {
+ const CCodecLib &lib = _codecs->Libs[i];
+ int ii;
+ if (lib.FindIconIndex(ext, ii))
+ {
+ *iconIndex = ii;
+ return StringToBstr(GetUnicodeString(lib.Path, GetCurrentFileCodePage()), iconPath);
+ }
+ }
+ int ii;
+ if (_codecs->InternalIcons.FindIconIndex(ext, ii))
+ {
+ *iconIndex = ii;
+ UString path;
+ NWindows::NDLL::MyGetModuleFileName(g_hInstance, path);
+ return StringToBstr(path, iconPath);
+ }
+#endif // #ifdef _WIN32
+ return S_OK;
+}
+
+/*
+STDMETHODIMP CArchiveFolderManager::GetTypes(BSTR *types)
+{
+ LoadFormats();
+ UString typesStrings;
+ for(int i = 0; i < _codecs.Formats.Size(); i++)
+ {
+ const CArcInfoEx &ai = _codecs.Formats[i];
+ if (ai.AssociateExts.Size() == 0)
+ continue;
+ if (i != 0)
+ typesStrings += L' ';
+ typesStrings += ai.Name;
+ }
+ return StringToBstr(typesStrings, types);
+}
+STDMETHODIMP CArchiveFolderManager::CreateFolderFile(const wchar_t * type,
+ const wchar_t * filePath, IProgress progress)
+{
+ return E_NOTIMPL;
+}
+*/
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/ArchiveFolderOut.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/ArchiveFolderOut.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/ArchiveFolderOut.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/ArchiveFolderOut.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,214 @@
+// FolderOut.cpp
+
+#include "StdAfx.h"
+
+#include "Common/ComTry.h"
+
+#include "Windows/FileDir.h"
+
+#include "../Common/WorkDir.h"
+
+#include "Agent.h"
+
+using namespace NWindows;
+using namespace NFile;
+using namespace NDirectory;
+
+static LPCWSTR kTempArcivePrefix = L"7zA";
+
+void CAgentFolder::GetPathParts(UStringVector &pathParts)
+{
+ _proxyFolderItem->GetPathParts(pathParts);
+}
+
+HRESULT CAgentFolder::CommonUpdateOperation(
+ bool deleteOperation,
+ bool createFolderOperation,
+ bool renameOperation,
+ const wchar_t *newItemName,
+ const NUpdateArchive::CActionSet *actionSet,
+ const UINT32 *indices, UINT32 numItems,
+ IFolderArchiveUpdateCallback *updateCallback100)
+{
+ NWorkDir::CInfo workDirInfo;
+ workDirInfo.Load();
+ UString archiveFilePath = _agentSpec->_archiveFilePath;
+ UString workDir = GetWorkDir(workDirInfo, archiveFilePath);
+ CreateComplexDirectory(workDir);
+
+ CTempFileW tempFile;
+ UString tempFileName;
+ if (tempFile.Create(workDir, kTempArcivePrefix, tempFileName) == 0)
+ return E_FAIL;
+
+ /*
+ if (SetOutProperties(anOutArchive, aCompressionInfo.Method) != S_OK)
+ return NFileOperationReturnCode::kError;
+ */
+
+ ////////////////////////////
+ // Save FolderItem;
+
+ UStringVector pathParts;
+ GetPathParts(pathParts);
+
+ HRESULT result;
+ if (deleteOperation)
+ result = _agentSpec->DeleteItems(tempFileName,
+ indices, numItems, updateCallback100);
+ else if (createFolderOperation)
+ {
+ result = _agentSpec->CreateFolder(tempFileName,
+ newItemName, updateCallback100);
+ }
+ else if (renameOperation)
+ {
+ result = _agentSpec->RenameItem(
+ tempFileName,
+ indices, numItems,
+ newItemName,
+ updateCallback100);
+ }
+ else
+ {
+ Byte actionSetByte[NUpdateArchive::NPairState::kNumValues];
+ for (int i = 0; i < NUpdateArchive::NPairState::kNumValues; i++)
+ actionSetByte[i] = (Byte)actionSet->StateActions[i];
+ result = _agentSpec->DoOperation2(tempFileName, actionSetByte, NULL, updateCallback100);
+ }
+
+ if (result != S_OK)
+ return result;
+
+ _agentSpec->Close();
+
+ // m_FolderItem = NULL;
+
+ if (NFind::DoesFileExist(archiveFilePath))
+ if (!DeleteFileAlways(archiveFilePath))
+ return GetLastError();
+
+ tempFile.DisableDeleting();
+ if (!MyMoveFile(tempFileName, archiveFilePath))
+ return GetLastError();
+
+ {
+ CMyComPtr<IArchiveOpenCallback> openCallback;
+ if (updateCallback100)
+ {
+ RINOK(updateCallback100->QueryInterface(IID_IArchiveOpenCallback, (void **)&openCallback));
+ }
+ RINOK(_agentSpec->ReOpen(openCallback));
+ }
+
+ ////////////////////////////
+ // Restore FolderItem;
+
+ CMyComPtr<IFolderFolder> archiveFolder;
+ RINOK(_agentSpec->BindToRootFolder(&archiveFolder));
+ for (int i = 0; i < pathParts.Size(); i++)
+ {
+ CMyComPtr<IFolderFolder> newFolder;
+ archiveFolder->BindToFolder(pathParts[i], &newFolder);
+ if(!newFolder)
+ break;
+ archiveFolder = newFolder;
+ }
+
+ CMyComPtr<IArchiveFolderInternal> archiveFolderInternal;
+ RINOK(archiveFolder.QueryInterface(IID_IArchiveFolderInternal, &archiveFolderInternal));
+ CAgentFolder *agentFolder;
+ RINOK(archiveFolderInternal->GetAgentFolder(&agentFolder));
+ _proxyFolderItem = agentFolder->_proxyFolderItem;
+ _proxyArchive = agentFolder->_proxyArchive;
+ _parentFolder = agentFolder->_parentFolder;
+
+ return S_OK;
+}
+
+STDMETHODIMP CAgentFolder::CopyFrom(
+ const wchar_t *fromFolderPath, // test it
+ const wchar_t **itemsPaths,
+ UINT32 numItems,
+ IProgress *progress)
+{
+ COM_TRY_BEGIN
+ CMyComPtr<IFolderArchiveUpdateCallback> updateCallback100;
+ if (progress != 0)
+ {
+ RINOK(progress->QueryInterface(IID_IFolderArchiveUpdateCallback, (void **)&updateCallback100));
+ }
+ try
+ {
+ RINOK(_agentSpec->SetFiles(fromFolderPath, itemsPaths, numItems));
+ RINOK(_agentSpec->SetFolder(this));
+ return CommonUpdateOperation(false, false, false, NULL,
+ &NUpdateArchive::kAddActionSet, 0, 0, updateCallback100);
+ }
+ catch(const UString &s)
+ {
+ RINOK(updateCallback100->UpdateErrorMessage(UString(L"Error: ") + s));
+ return E_FAIL;
+ }
+ COM_TRY_END
+}
+
+STDMETHODIMP CAgentFolder::Delete(const UINT32 *indices, UINT32 numItems, IProgress *progress)
+{
+ COM_TRY_BEGIN
+ RINOK(_agentSpec->SetFolder(this));
+ CMyComPtr<IFolderArchiveUpdateCallback> updateCallback100;
+ if (progress != 0)
+ {
+ CMyComPtr<IProgress> progressWrapper = progress;
+ RINOK(progressWrapper.QueryInterface(
+ IID_IFolderArchiveUpdateCallback, &updateCallback100));
+ }
+ return CommonUpdateOperation(true, false, false, NULL,
+ &NUpdateArchive::kDeleteActionSet, indices, numItems, updateCallback100);
+ COM_TRY_END
+}
+
+STDMETHODIMP CAgentFolder::CreateFolder(const wchar_t *name, IProgress *progress)
+{
+ COM_TRY_BEGIN
+ if (_proxyFolderItem->FindDirSubItemIndex(name) >= 0)
+ return ERROR_ALREADY_EXISTS;
+ RINOK(_agentSpec->SetFolder(this));
+ CMyComPtr<IFolderArchiveUpdateCallback> updateCallback100;
+ if (progress != 0)
+ {
+ CMyComPtr<IProgress> progressWrapper = progress;
+ RINOK(progressWrapper.QueryInterface(IID_IFolderArchiveUpdateCallback, &updateCallback100));
+ }
+ return CommonUpdateOperation(false, true, false, name, NULL, NULL, 0, updateCallback100);
+ COM_TRY_END
+}
+
+STDMETHODIMP CAgentFolder::Rename(UINT32 index, const wchar_t *newName, IProgress *progress)
+{
+ COM_TRY_BEGIN
+ CUIntVector indices;
+ indices.Add(index);
+ RINOK(_agentSpec->SetFolder(this));
+ CMyComPtr<IFolderArchiveUpdateCallback> updateCallback100;
+ if (progress != 0)
+ {
+ CMyComPtr<IProgress> progressWrapper = progress;
+ RINOK(progressWrapper.QueryInterface(IID_IFolderArchiveUpdateCallback, &updateCallback100));
+ }
+ return CommonUpdateOperation(false, false, true, newName, NULL, &indices.Front(),
+ indices.Size(), updateCallback100);
+ COM_TRY_END
+}
+
+STDMETHODIMP CAgentFolder::CreateFile(const wchar_t * /* name */, IProgress * /* progress */)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP CAgentFolder::SetProperty(UINT32 /* index */, PROPID /* propID */,
+ const PROPVARIANT * /* value */, IProgress * /* progress */)
+{
+ return E_NOTIMPL;
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/IFolderArchive.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/IFolderArchive.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/IFolderArchive.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/IFolderArchive.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,73 @@
+// IFolderArchive.h
+
+#ifndef __IFOLDER_ARCHIVE_H
+#define __IFOLDER_ARCHIVE_H
+
+#include "../../IDecl.h"
+#include "../../Archive/IArchive.h"
+#include "../../UI/Common/LoadCodecs.h"
+#include "../../UI/FileManager/IFolder.h"
+
+#include "../Common/ExtractMode.h"
+#include "../Common/IFileExtractCallback.h"
+
+#define FOLDER_ARCHIVE_INTERFACE_SUB(i, base, x) DECL_INTERFACE_SUB(i, base, 0x01, x)
+#define FOLDER_ARCHIVE_INTERFACE(i, x) FOLDER_ARCHIVE_INTERFACE_SUB(i, IUnknown, x)
+
+#define INTERFACE_IArchiveFolder(x) \
+ STDMETHOD(Extract)(const UInt32 *indices, UInt32 numItems, \
+ NExtract::NPathMode::EEnum pathMode, \
+ NExtract::NOverwriteMode::EEnum overwriteMode, \
+ const wchar_t *path, Int32 testMode, \
+ IFolderArchiveExtractCallback *extractCallback2) x; \
+
+FOLDER_ARCHIVE_INTERFACE(IArchiveFolder, 0x05)
+{
+ INTERFACE_IArchiveFolder(PURE)
+};
+
+#define INTERFACE_IInFolderArchive(x) \
+ STDMETHOD(Open)(IInStream *inStream, const wchar_t *filePath, const wchar_t *arcFormat, BSTR *archiveTypeRes, IArchiveOpenCallback *openArchiveCallback) x; \
+ STDMETHOD(ReOpen)(IArchiveOpenCallback *openArchiveCallback) x; \
+ STDMETHOD(Close)() x; \
+ STDMETHOD(GetNumberOfProperties)(UInt32 *numProperties) x; \
+ STDMETHOD(GetPropertyInfo)(UInt32 index, BSTR *name, PROPID *propID, VARTYPE *varType) x; \
+ STDMETHOD(BindToRootFolder)(IFolderFolder **resultFolder) x; \
+ STDMETHOD(Extract)(NExtract::NPathMode::EEnum pathMode, \
+ NExtract::NOverwriteMode::EEnum overwriteMode, const wchar_t *path, \
+ Int32 testMode, IFolderArchiveExtractCallback *extractCallback2) x; \
+
+FOLDER_ARCHIVE_INTERFACE(IInFolderArchive, 0x0E)
+{
+ INTERFACE_IInFolderArchive(PURE)
+};
+
+#define INTERFACE_IFolderArchiveUpdateCallback(x) \
+ STDMETHOD(CompressOperation)(const wchar_t *name) x; \
+ STDMETHOD(DeleteOperation)(const wchar_t *name) x; \
+ STDMETHOD(OperationResult)(Int32 operationResult) x; \
+ STDMETHOD(UpdateErrorMessage)(const wchar_t *message) x; \
+ STDMETHOD(SetNumFiles)(UInt64 numFiles) x; \
+
+FOLDER_ARCHIVE_INTERFACE_SUB(IFolderArchiveUpdateCallback, IProgress, 0x0B)
+{
+ INTERFACE_IFolderArchiveUpdateCallback(PURE)
+};
+
+#define INTERFACE_IOutFolderArchive(x) \
+ STDMETHOD(SetFolder)(IFolderFolder *folder) x; \
+ STDMETHOD(SetFiles)(const wchar_t *folderPrefix, const wchar_t **names, UInt32 numNames) x; \
+ STDMETHOD(DeleteItems)(const wchar_t *newArchiveName, \
+ const UInt32 *indices, UInt32 numItems, IFolderArchiveUpdateCallback *updateCallback) x; \
+ STDMETHOD(DoOperation)(CCodecs *codecs, int index, \
+ const wchar_t *newArchiveName, const Byte *stateActions, const wchar_t *sfxModule, \
+ IFolderArchiveUpdateCallback *updateCallback) x; \
+ STDMETHOD(DoOperation2)(const wchar_t *newArchiveName, const Byte *stateActions, \
+ const wchar_t *sfxModule, IFolderArchiveUpdateCallback *updateCallback) x; \
+
+FOLDER_ARCHIVE_INTERFACE(IOutFolderArchive, 0x0A)
+{
+ INTERFACE_IOutFolderArchive(PURE)
+};
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/UpdateCallbackAgent.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/UpdateCallbackAgent.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/UpdateCallbackAgent.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/UpdateCallbackAgent.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,121 @@
+// UpdateCallbackAgent.h
+
+#include "StdAfx.h"
+
+#include "Windows/Error.h"
+#include "Common/IntToString.h"
+
+#include "UpdateCallbackAgent.h"
+
+using namespace NWindows;
+
+void CUpdateCallbackAgent::SetCallback(IFolderArchiveUpdateCallback *callback)
+{
+ Callback = callback;
+ _compressProgress.Release();
+ if (Callback)
+ Callback.QueryInterface(IID_ICompressProgressInfo, &_compressProgress);
+}
+
+HRESULT CUpdateCallbackAgent::SetNumFiles(UInt64 numFiles)
+{
+ if (Callback)
+ return Callback->SetNumFiles(numFiles);
+ return S_OK;
+}
+
+
+HRESULT CUpdateCallbackAgent::SetTotal(UINT64 size)
+{
+ if (Callback)
+ return Callback->SetTotal(size);
+ return S_OK;
+}
+
+HRESULT CUpdateCallbackAgent::SetCompleted(const UINT64 *completeValue)
+{
+ if (Callback)
+ return Callback->SetCompleted(completeValue);
+ return S_OK;
+}
+
+HRESULT CUpdateCallbackAgent::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
+{
+ if (_compressProgress)
+ return _compressProgress->SetRatioInfo(inSize, outSize);
+ return S_OK;
+}
+
+HRESULT CUpdateCallbackAgent::CheckBreak()
+{
+ return S_OK;
+}
+
+HRESULT CUpdateCallbackAgent::Finilize()
+{
+ return S_OK;
+}
+
+HRESULT CUpdateCallbackAgent::OpenFileError(const wchar_t *name, DWORD systemError)
+{
+ // if (systemError == ERROR_SHARING_VIOLATION)
+ {
+ if (Callback)
+ {
+ RINOK(Callback->UpdateErrorMessage(
+ UString(L"WARNING: ") +
+ NError::MyFormatMessageW(systemError) +
+ UString(L": ") +
+ UString(name)));
+ return S_FALSE;
+ }
+ }
+ // FailedFiles.Add(name);
+ return systemError;
+}
+
+HRESULT CUpdateCallbackAgent::GetStream(const wchar_t *name, bool /* isAnti */)
+{
+ if (Callback)
+ return Callback->CompressOperation(name);
+ return S_OK;
+}
+
+HRESULT CUpdateCallbackAgent::SetOperationResult(Int32 operationResult)
+{
+ if (Callback)
+ return Callback->OperationResult(operationResult);
+ return S_OK;
+}
+
+HRESULT CUpdateCallbackAgent::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)
+{
+ *password = NULL;
+ *passwordIsDefined = BoolToInt(false);
+ if (!_cryptoGetTextPassword)
+ {
+ if (!Callback)
+ return S_OK;
+ Callback.QueryInterface(IID_ICryptoGetTextPassword2, &_cryptoGetTextPassword);
+ if (!_cryptoGetTextPassword)
+ return S_OK;
+ }
+ return _cryptoGetTextPassword->CryptoGetTextPassword2(passwordIsDefined, password);
+}
+
+HRESULT CUpdateCallbackAgent::CryptoGetTextPassword(BSTR *password)
+{
+ *password = NULL;
+ CMyComPtr<ICryptoGetTextPassword> getTextPassword;
+ Callback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);
+ if (!getTextPassword)
+ return E_NOTIMPL;
+ return getTextPassword->CryptoGetTextPassword(password);
+}
+
+/*
+HRESULT CUpdateCallbackAgent::ShowDeleteFile(const wchar_t *name)
+{
+ return Callback->DeleteOperation(name);
+}
+*/
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/UpdateCallbackAgent.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/UpdateCallbackAgent.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/UpdateCallbackAgent.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Agent/UpdateCallbackAgent.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,19 @@
+// UpdateCallbackAgent.h
+
+#ifndef __UPDATECALLBACKAGENT_H
+#define __UPDATECALLBACKAGENT_H
+
+#include "../Common/UpdateCallback.h"
+#include "IFolderArchive.h"
+
+class CUpdateCallbackAgent: public IUpdateCallbackUI
+{
+ INTERFACE_IUpdateCallbackUI(;)
+ CMyComPtr<ICryptoGetTextPassword2> _cryptoGetTextPassword;
+ CMyComPtr<IFolderArchiveUpdateCallback> Callback;
+ CMyComPtr<ICompressProgressInfo> _compressProgress;
+public:
+ void SetCallback(IFolderArchiveUpdateCallback *callback);
+};
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/Client7z.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/Client7z.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/Client7z.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/Client7z.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,871 @@
+// Client7z.cpp
+
+#include "StdAfx.h"
+
+#include "Common/IntToString.h"
+#include "Common/MyInitGuid.h"
+#include "Common/StringConvert.h"
+
+#include "Windows/DLL.h"
+#include "Windows/FileDir.h"
+#include "Windows/FileFind.h"
+#include "Windows/FileName.h"
+#include "Windows/NtCheck.h"
+#include "Windows/PropVariant.h"
+#include "Windows/PropVariantConversions.h"
+
+#include "../../Common/FileStreams.h"
+
+#include "../../Archive/IArchive.h"
+
+#include "../../IPassword.h"
+#include "../../MyVersion.h"
+
+// use another CLSIDs, if you want to support other formats (zip, rar, ...).
+// {23170F69-40C1-278A-1000-000110070000}
+DEFINE_GUID(CLSID_CFormat7z,
+ 0x23170F69, 0x40C1, 0x278A, 0x10, 0x00, 0x00, 0x01, 0x10, 0x07, 0x00, 0x00);
+
+using namespace NWindows;
+
+#define kDllName "7z.dll"
+
+static const char *kCopyrightString = MY_7ZIP_VERSION
+" (" kDllName " client) "
+MY_COPYRIGHT " " MY_DATE;
+
+static const char *kHelpString =
+"Usage: Client7z.exe [a | l | x ] archive.7z [fileName ...]\n"
+"Examples:\n"
+" Client7z.exe a archive.7z f1.txt f2.txt : compress two files to archive.7z\n"
+" Client7z.exe l archive.7z : List contents of archive.7z\n"
+" Client7z.exe x archive.7z : eXtract files from archive.7z\n";
+
+
+typedef UINT32 (WINAPI * CreateObjectFunc)(
+ const GUID *clsID,
+ const GUID *interfaceID,
+ void **outObject);
+
+
+void PrintString(const UString &s)
+{
+ printf("%s", (LPCSTR)GetOemString(s));
+}
+
+void PrintString(const AString &s)
+{
+ printf("%s", (LPCSTR)s);
+}
+
+void PrintNewLine()
+{
+ PrintString("\n");
+}
+
+void PrintStringLn(const AString &s)
+{
+ PrintString(s);
+ PrintNewLine();
+}
+
+void PrintError(const AString &s)
+{
+ PrintNewLine();
+ PrintString(s);
+ PrintNewLine();
+}
+
+static HRESULT IsArchiveItemProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)
+{
+ NCOM::CPropVariant prop;
+ RINOK(archive->GetProperty(index, propID, &prop));
+ if (prop.vt == VT_BOOL)
+ result = VARIANT_BOOLToBool(prop.boolVal);
+ else if (prop.vt == VT_EMPTY)
+ result = false;
+ else
+ return E_FAIL;
+ return S_OK;
+}
+
+static HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)
+{
+ return IsArchiveItemProp(archive, index, kpidIsDir, result);
+}
+
+
+static const wchar_t *kEmptyFileAlias = L"[Content]";
+
+
+//////////////////////////////////////////////////////////////
+// Archive Open callback class
+
+
+class CArchiveOpenCallback:
+ public IArchiveOpenCallback,
+ public ICryptoGetTextPassword,
+ public CMyUnknownImp
+{
+public:
+ MY_UNKNOWN_IMP1(ICryptoGetTextPassword)
+
+ STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes);
+ STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes);
+
+ STDMETHOD(CryptoGetTextPassword)(BSTR *password);
+
+ bool PasswordIsDefined;
+ UString Password;
+
+ CArchiveOpenCallback() : PasswordIsDefined(false) {}
+};
+
+STDMETHODIMP CArchiveOpenCallback::SetTotal(const UInt64 * /* files */, const UInt64 * /* bytes */)
+{
+ return S_OK;
+}
+
+STDMETHODIMP CArchiveOpenCallback::SetCompleted(const UInt64 * /* files */, const UInt64 * /* bytes */)
+{
+ return S_OK;
+}
+
+STDMETHODIMP CArchiveOpenCallback::CryptoGetTextPassword(BSTR *password)
+{
+ if (!PasswordIsDefined)
+ {
+ // You can ask real password here from user
+ // Password = GetPassword(OutStream);
+ // PasswordIsDefined = true;
+ PrintError("Password is not defined");
+ return E_ABORT;
+ }
+ return StringToBstr(Password, password);
+}
+
+
+//////////////////////////////////////////////////////////////
+// Archive Extracting callback class
+
+static const wchar_t *kCantDeleteOutputFile = L"ERROR: Can not delete output file ";
+
+static const char *kTestingString = "Testing ";
+static const char *kExtractingString = "Extracting ";
+static const char *kSkippingString = "Skipping ";
+
+static const char *kUnsupportedMethod = "Unsupported Method";
+static const char *kCRCFailed = "CRC Failed";
+static const char *kDataError = "Data Error";
+static const char *kUnknownError = "Unknown Error";
+
+class CArchiveExtractCallback:
+ public IArchiveExtractCallback,
+ public ICryptoGetTextPassword,
+ public CMyUnknownImp
+{
+public:
+ MY_UNKNOWN_IMP1(ICryptoGetTextPassword)
+
+ // IProgress
+ STDMETHOD(SetTotal)(UInt64 size);
+ STDMETHOD(SetCompleted)(const UInt64 *completeValue);
+
+ // IArchiveExtractCallback
+ STDMETHOD(GetStream)(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode);
+ STDMETHOD(PrepareOperation)(Int32 askExtractMode);
+ STDMETHOD(SetOperationResult)(Int32 resultEOperationResult);
+
+ // ICryptoGetTextPassword
+ STDMETHOD(CryptoGetTextPassword)(BSTR *aPassword);
+
+private:
+ CMyComPtr<IInArchive> _archiveHandler;
+ UString _directoryPath; // Output directory
+ UString _filePath; // name inside arcvhive
+ UString _diskFilePath; // full path to file on disk
+ bool _extractMode;
+ struct CProcessedFileInfo
+ {
+ FILETIME MTime;
+ UInt32 Attrib;
+ bool isDir;
+ bool AttribDefined;
+ bool MTimeDefined;
+ } _processedFileInfo;
+
+ COutFileStream *_outFileStreamSpec;
+ CMyComPtr<ISequentialOutStream> _outFileStream;
+
+public:
+ void Init(IInArchive *archiveHandler, const UString &directoryPath);
+
+ UInt64 NumErrors;
+ bool PasswordIsDefined;
+ UString Password;
+
+ CArchiveExtractCallback() : PasswordIsDefined(false) {}
+};
+
+void CArchiveExtractCallback::Init(IInArchive *archiveHandler, const UString &directoryPath)
+{
+ NumErrors = 0;
+ _archiveHandler = archiveHandler;
+ _directoryPath = directoryPath;
+ NFile::NName::NormalizeDirPathPrefix(_directoryPath);
+}
+
+STDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 /* size */)
+{
+ return S_OK;
+}
+
+STDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 * /* completeValue */)
+{
+ return S_OK;
+}
+
+STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index,
+ ISequentialOutStream **outStream, Int32 askExtractMode)
+{
+ *outStream = 0;
+ _outFileStream.Release();
+
+ {
+ // Get Name
+ NCOM::CPropVariant prop;
+ RINOK(_archiveHandler->GetProperty(index, kpidPath, &prop));
+
+ UString fullPath;
+ if (prop.vt == VT_EMPTY)
+ fullPath = kEmptyFileAlias;
+ else
+ {
+ if (prop.vt != VT_BSTR)
+ return E_FAIL;
+ fullPath = prop.bstrVal;
+ }
+ _filePath = fullPath;
+ }
+
+ if (askExtractMode != NArchive::NExtract::NAskMode::kExtract)
+ return S_OK;
+
+ {
+ // Get Attrib
+ NCOM::CPropVariant prop;
+ RINOK(_archiveHandler->GetProperty(index, kpidAttrib, &prop));
+ if (prop.vt == VT_EMPTY)
+ {
+ _processedFileInfo.Attrib = 0;
+ _processedFileInfo.AttribDefined = false;
+ }
+ else
+ {
+ if (prop.vt != VT_UI4)
+ return E_FAIL;
+ _processedFileInfo.Attrib = prop.ulVal;
+ _processedFileInfo.AttribDefined = true;
+ }
+ }
+
+ RINOK(IsArchiveItemFolder(_archiveHandler, index, _processedFileInfo.isDir));
+
+ {
+ // Get Modified Time
+ NCOM::CPropVariant prop;
+ RINOK(_archiveHandler->GetProperty(index, kpidMTime, &prop));
+ _processedFileInfo.MTimeDefined = false;
+ switch(prop.vt)
+ {
+ case VT_EMPTY:
+ // _processedFileInfo.MTime = _utcMTimeDefault;
+ break;
+ case VT_FILETIME:
+ _processedFileInfo.MTime = prop.filetime;
+ _processedFileInfo.MTimeDefined = true;
+ break;
+ default:
+ return E_FAIL;
+ }
+
+ }
+ {
+ // Get Size
+ NCOM::CPropVariant prop;
+ RINOK(_archiveHandler->GetProperty(index, kpidSize, &prop));
+ bool newFileSizeDefined = (prop.vt != VT_EMPTY);
+ UInt64 newFileSize;
+ if (newFileSizeDefined)
+ newFileSize = ConvertPropVariantToUInt64(prop);
+ }
+
+
+ {
+ // Create folders for file
+ int slashPos = _filePath.ReverseFind(WCHAR_PATH_SEPARATOR);
+ if (slashPos >= 0)
+ NFile::NDirectory::CreateComplexDirectory(_directoryPath + _filePath.Left(slashPos));
+ }
+
+ UString fullProcessedPath = _directoryPath + _filePath;
+ _diskFilePath = fullProcessedPath;
+
+ if (_processedFileInfo.isDir)
+ {
+ NFile::NDirectory::CreateComplexDirectory(fullProcessedPath);
+ }
+ else
+ {
+ NFile::NFind::CFileInfoW fi;
+ if (fi.Find(fullProcessedPath))
+ {
+ if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))
+ {
+ PrintString(UString(kCantDeleteOutputFile) + fullProcessedPath);
+ return E_ABORT;
+ }
+ }
+
+ _outFileStreamSpec = new COutFileStream;
+ CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);
+ if (!_outFileStreamSpec->Open(fullProcessedPath, CREATE_ALWAYS))
+ {
+ PrintString((UString)L"can not open output file " + fullProcessedPath);
+ return E_ABORT;
+ }
+ _outFileStream = outStreamLoc;
+ *outStream = outStreamLoc.Detach();
+ }
+ return S_OK;
+}
+
+STDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)
+{
+ _extractMode = false;
+ switch (askExtractMode)
+ {
+ case NArchive::NExtract::NAskMode::kExtract: _extractMode = true; break;
+ };
+ switch (askExtractMode)
+ {
+ case NArchive::NExtract::NAskMode::kExtract: PrintString(kExtractingString); break;
+ case NArchive::NExtract::NAskMode::kTest: PrintString(kTestingString); break;
+ case NArchive::NExtract::NAskMode::kSkip: PrintString(kSkippingString); break;
+ };
+ PrintString(_filePath);
+ return S_OK;
+}
+
+STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)
+{
+ switch(operationResult)
+ {
+ case NArchive::NExtract::NOperationResult::kOK:
+ break;
+ default:
+ {
+ NumErrors++;
+ PrintString(" ");
+ switch(operationResult)
+ {
+ case NArchive::NExtract::NOperationResult::kUnSupportedMethod:
+ PrintString(kUnsupportedMethod);
+ break;
+ case NArchive::NExtract::NOperationResult::kCRCError:
+ PrintString(kCRCFailed);
+ break;
+ case NArchive::NExtract::NOperationResult::kDataError:
+ PrintString(kDataError);
+ break;
+ default:
+ PrintString(kUnknownError);
+ }
+ }
+ }
+
+ if (_outFileStream != NULL)
+ {
+ if (_processedFileInfo.MTimeDefined)
+ _outFileStreamSpec->SetMTime(&_processedFileInfo.MTime);
+ RINOK(_outFileStreamSpec->Close());
+ }
+ _outFileStream.Release();
+ if (_extractMode && _processedFileInfo.AttribDefined)
+ NFile::NDirectory::MySetFileAttributes(_diskFilePath, _processedFileInfo.Attrib);
+ PrintNewLine();
+ return S_OK;
+}
+
+
+STDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)
+{
+ if (!PasswordIsDefined)
+ {
+ // You can ask real password here from user
+ // Password = GetPassword(OutStream);
+ // PasswordIsDefined = true;
+ PrintError("Password is not defined");
+ return E_ABORT;
+ }
+ return StringToBstr(Password, password);
+}
+
+
+
+//////////////////////////////////////////////////////////////
+// Archive Creating callback class
+
+struct CDirItem
+{
+ UInt64 Size;
+ FILETIME CTime;
+ FILETIME ATime;
+ FILETIME MTime;
+ UString Name;
+ UString FullPath;
+ UInt32 Attrib;
+
+ bool isDir() const { return (Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }
+};
+
+class CArchiveUpdateCallback:
+ public IArchiveUpdateCallback2,
+ public ICryptoGetTextPassword2,
+ public CMyUnknownImp
+{
+public:
+ MY_UNKNOWN_IMP2(IArchiveUpdateCallback2, ICryptoGetTextPassword2)
+
+ // IProgress
+ STDMETHOD(SetTotal)(UInt64 size);
+ STDMETHOD(SetCompleted)(const UInt64 *completeValue);
+
+ // IUpdateCallback2
+ STDMETHOD(EnumProperties)(IEnumSTATPROPSTG **enumerator);
+ STDMETHOD(GetUpdateItemInfo)(UInt32 index,
+ Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive);
+ STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);
+ STDMETHOD(GetStream)(UInt32 index, ISequentialInStream **inStream);
+ STDMETHOD(SetOperationResult)(Int32 operationResult);
+ STDMETHOD(GetVolumeSize)(UInt32 index, UInt64 *size);
+ STDMETHOD(GetVolumeStream)(UInt32 index, ISequentialOutStream **volumeStream);
+
+ STDMETHOD(CryptoGetTextPassword2)(Int32 *passwordIsDefined, BSTR *password);
+
+public:
+ CRecordVector<UInt64> VolumesSizes;
+ UString VolName;
+ UString VolExt;
+
+ UString DirPrefix;
+ const CObjectVector<CDirItem> *DirItems;
+
+ bool PasswordIsDefined;
+ UString Password;
+ bool AskPassword;
+
+ bool m_NeedBeClosed;
+
+ UStringVector FailedFiles;
+ CRecordVector<HRESULT> FailedCodes;
+
+ CArchiveUpdateCallback(): PasswordIsDefined(false), AskPassword(false), DirItems(0) {};
+
+ ~CArchiveUpdateCallback() { Finilize(); }
+ HRESULT Finilize();
+
+ void Init(const CObjectVector<CDirItem> *dirItems)
+ {
+ DirItems = dirItems;
+ m_NeedBeClosed = false;
+ FailedFiles.Clear();
+ FailedCodes.Clear();
+ }
+};
+
+STDMETHODIMP CArchiveUpdateCallback::SetTotal(UInt64 /* size */)
+{
+ return S_OK;
+}
+
+STDMETHODIMP CArchiveUpdateCallback::SetCompleted(const UInt64 * /* completeValue */)
+{
+ return S_OK;
+}
+
+
+STDMETHODIMP CArchiveUpdateCallback::EnumProperties(IEnumSTATPROPSTG ** /* enumerator */)
+{
+ return E_NOTIMPL;
+}
+
+STDMETHODIMP CArchiveUpdateCallback::GetUpdateItemInfo(UInt32 /* index */,
+ Int32 *newData, Int32 *newProperties, UInt32 *indexInArchive)
+{
+ if (newData != NULL)
+ *newData = BoolToInt(true);
+ if (newProperties != NULL)
+ *newProperties = BoolToInt(true);
+ if (indexInArchive != NULL)
+ *indexInArchive = (UInt32)-1;
+ return S_OK;
+}
+
+STDMETHODIMP CArchiveUpdateCallback::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
+{
+ NWindows::NCOM::CPropVariant prop;
+
+ if (propID == kpidIsAnti)
+ {
+ prop = false;
+ prop.Detach(value);
+ return S_OK;
+ }
+
+ {
+ const CDirItem &dirItem = (*DirItems)[index];
+ switch(propID)
+ {
+ case kpidPath: prop = dirItem.Name; break;
+ case kpidIsDir: prop = dirItem.isDir(); break;
+ case kpidSize: prop = dirItem.Size; break;
+ case kpidAttrib: prop = dirItem.Attrib; break;
+ case kpidCTime: prop = dirItem.CTime; break;
+ case kpidATime: prop = dirItem.ATime; break;
+ case kpidMTime: prop = dirItem.MTime; break;
+ }
+ }
+ prop.Detach(value);
+ return S_OK;
+}
+
+HRESULT CArchiveUpdateCallback::Finilize()
+{
+ if (m_NeedBeClosed)
+ {
+ PrintNewLine();
+ m_NeedBeClosed = false;
+ }
+ return S_OK;
+}
+
+static void GetStream2(const wchar_t *name)
+{
+ PrintString("Compressing ");
+ if (name[0] == 0)
+ name = kEmptyFileAlias;
+ PrintString(name);
+}
+
+STDMETHODIMP CArchiveUpdateCallback::GetStream(UInt32 index, ISequentialInStream **inStream)
+{
+ RINOK(Finilize());
+
+ const CDirItem &dirItem = (*DirItems)[index];
+ GetStream2(dirItem.Name);
+
+ if (dirItem.isDir())
+ return S_OK;
+
+ {
+ CInFileStream *inStreamSpec = new CInFileStream;
+ CMyComPtr<ISequentialInStream> inStreamLoc(inStreamSpec);
+ UString path = DirPrefix + dirItem.FullPath;
+ if (!inStreamSpec->Open(path))
+ {
+ DWORD sysError = ::GetLastError();
+ FailedCodes.Add(sysError);
+ FailedFiles.Add(path);
+ // if (systemError == ERROR_SHARING_VIOLATION)
+ {
+ PrintNewLine();
+ PrintError("WARNING: can't open file");
+ // PrintString(NError::MyFormatMessageW(systemError));
+ return S_FALSE;
+ }
+ // return sysError;
+ }
+ *inStream = inStreamLoc.Detach();
+ }
+ return S_OK;
+}
+
+STDMETHODIMP CArchiveUpdateCallback::SetOperationResult(Int32 /* operationResult */)
+{
+ m_NeedBeClosed = true;
+ return S_OK;
+}
+
+STDMETHODIMP CArchiveUpdateCallback::GetVolumeSize(UInt32 index, UInt64 *size)
+{
+ if (VolumesSizes.Size() == 0)
+ return S_FALSE;
+ if (index >= (UInt32)VolumesSizes.Size())
+ index = VolumesSizes.Size() - 1;
+ *size = VolumesSizes[index];
+ return S_OK;
+}
+
+STDMETHODIMP CArchiveUpdateCallback::GetVolumeStream(UInt32 index, ISequentialOutStream **volumeStream)
+{
+ wchar_t temp[16];
+ ConvertUInt32ToString(index + 1, temp);
+ UString res = temp;
+ while (res.Length() < 2)
+ res = UString(L'0') + res;
+ UString fileName = VolName;
+ fileName += L'.';
+ fileName += res;
+ fileName += VolExt;
+ COutFileStream *streamSpec = new COutFileStream;
+ CMyComPtr<ISequentialOutStream> streamLoc(streamSpec);
+ if (!streamSpec->Create(fileName, false))
+ return ::GetLastError();
+ *volumeStream = streamLoc.Detach();
+ return S_OK;
+}
+
+STDMETHODIMP CArchiveUpdateCallback::CryptoGetTextPassword2(Int32 *passwordIsDefined, BSTR *password)
+{
+ if (!PasswordIsDefined)
+ {
+ if (AskPassword)
+ {
+ // You can ask real password here from user
+ // Password = GetPassword(OutStream);
+ // PasswordIsDefined = true;
+ PrintError("Password is not defined");
+ return E_ABORT;
+ }
+ }
+ *passwordIsDefined = BoolToInt(PasswordIsDefined);
+ return StringToBstr(Password, password);
+}
+
+
+
+//////////////////////////////////////////////////////////////////////////
+// Main function
+
+#define NT_CHECK_FAIL_ACTION PrintError("Unsupported Windows version"); return 1;
+
+int MY_CDECL main(int numArgs, const char *args[])
+{
+ NT_CHECK
+
+ PrintStringLn(kCopyrightString);
+
+ if (numArgs < 3)
+ {
+ PrintStringLn(kHelpString);
+ return 1;
+ }
+ NWindows::NDLL::CLibrary lib;
+ if (!lib.Load(TEXT(kDllName)))
+ {
+ PrintError("Can not load 7-zip library");
+ return 1;
+ }
+ CreateObjectFunc createObjectFunc = (CreateObjectFunc)lib.GetProc("CreateObject");
+ if (createObjectFunc == 0)
+ {
+ PrintError("Can not get CreateObject");
+ return 1;
+ }
+
+ char c;
+ {
+ AString command = args[1];
+ if (command.Length() != 1)
+ {
+ PrintError("incorrect command");
+ return 1;
+ }
+ c = MyCharLower(command[0]);
+ }
+ UString archiveName = GetUnicodeString(args[2]);
+ if (c == 'a')
+ {
+ // create archive command
+ if (numArgs < 4)
+ {
+ PrintStringLn(kHelpString);
+ return 1;
+ }
+ CObjectVector<CDirItem> dirItems;
+ int i;
+ for (i = 3; i < numArgs; i++)
+ {
+ CDirItem di;
+ UString name = GetUnicodeString(args[i]);
+
+ NFile::NFind::CFileInfoW fi;
+ if (!fi.Find(name))
+ {
+ PrintString(UString(L"Can't find file") + name);
+ return 1;
+ }
+
+ di.Attrib = fi.Attrib;
+ di.Size = fi.Size;
+ di.CTime = fi.CTime;
+ di.ATime = fi.ATime;
+ di.MTime = fi.MTime;
+ di.Name = name;
+ di.FullPath = name;
+ dirItems.Add(di);
+ }
+ COutFileStream *outFileStreamSpec = new COutFileStream;
+ CMyComPtr<IOutStream> outFileStream = outFileStreamSpec;
+ if (!outFileStreamSpec->Create(archiveName, false))
+ {
+ PrintError("can't create archive file");
+ return 1;
+ }
+
+ CMyComPtr<IOutArchive> outArchive;
+ if (createObjectFunc(&CLSID_CFormat7z, &IID_IOutArchive, (void **)&outArchive) != S_OK)
+ {
+ PrintError("Can not get class object");
+ return 1;
+ }
+
+ CArchiveUpdateCallback *updateCallbackSpec = new CArchiveUpdateCallback;
+ CMyComPtr<IArchiveUpdateCallback2> updateCallback(updateCallbackSpec);
+ updateCallbackSpec->Init(&dirItems);
+ // updateCallbackSpec->PasswordIsDefined = true;
+ // updateCallbackSpec->Password = L"1";
+
+ /*
+ {
+ const wchar_t *names[] =
+ {
+ L"s",
+ L"x"
+ };
+ const int kNumProps = sizeof(names) / sizeof(names[0]);
+ NWindows::NCOM::CPropVariant values[kNumProps] =
+ {
+ false, // solid mode OFF
+ (UInt32)9 // compression level = 9 - ultra
+ };
+ CMyComPtr<ISetProperties> setProperties;
+ outArchive->QueryInterface(IID_ISetProperties, (void **)&setProperties);
+ if (!setProperties)
+ {
+ PrintError("ISetProperties unsupported");
+ return 1;
+ }
+ RINOK(setProperties->SetProperties(names, values, kNumProps));
+ }
+ */
+
+ HRESULT result = outArchive->UpdateItems(outFileStream, dirItems.Size(), updateCallback);
+ updateCallbackSpec->Finilize();
+ if (result != S_OK)
+ {
+ PrintError("Update Error");
+ return 1;
+ }
+ for (i = 0; i < updateCallbackSpec->FailedFiles.Size(); i++)
+ {
+ PrintNewLine();
+ PrintString((UString)L"Error for file: " + updateCallbackSpec->FailedFiles[i]);
+ }
+ if (updateCallbackSpec->FailedFiles.Size() != 0)
+ return 1;
+ }
+ else
+ {
+ if (numArgs != 3)
+ {
+ PrintStringLn(kHelpString);
+ return 1;
+ }
+
+ bool listCommand;
+ if (c == 'l')
+ listCommand = true;
+ else if (c == 'x')
+ listCommand = false;
+ else
+ {
+ PrintError("incorrect command");
+ return 1;
+ }
+
+ CMyComPtr<IInArchive> archive;
+ if (createObjectFunc(&CLSID_CFormat7z, &IID_IInArchive, (void **)&archive) != S_OK)
+ {
+ PrintError("Can not get class object");
+ return 1;
+ }
+
+ CInFileStream *fileSpec = new CInFileStream;
+ CMyComPtr<IInStream> file = fileSpec;
+
+ if (!fileSpec->Open(archiveName))
+ {
+ PrintError("Can not open archive file");
+ return 1;
+ }
+
+ {
+ CArchiveOpenCallback *openCallbackSpec = new CArchiveOpenCallback;
+ CMyComPtr<IArchiveOpenCallback> openCallback(openCallbackSpec);
+ openCallbackSpec->PasswordIsDefined = false;
+ // openCallbackSpec->PasswordIsDefined = true;
+ // openCallbackSpec->Password = L"1";
+
+ if (archive->Open(file, 0, openCallback) != S_OK)
+ {
+ PrintError("Can not open archive");
+ return 1;
+ }
+ }
+
+ if (listCommand)
+ {
+ // List command
+ UInt32 numItems = 0;
+ archive->GetNumberOfItems(&numItems);
+ for (UInt32 i = 0; i < numItems; i++)
+ {
+ {
+ // Get uncompressed size of file
+ NWindows::NCOM::CPropVariant prop;
+ archive->GetProperty(i, kpidSize, &prop);
+ UString s = ConvertPropVariantToString(prop);
+ PrintString(s);
+ PrintString(" ");
+ }
+ {
+ // Get name of file
+ NWindows::NCOM::CPropVariant prop;
+ archive->GetProperty(i, kpidPath, &prop);
+ UString s = ConvertPropVariantToString(prop);
+ PrintString(s);
+ }
+ PrintString("\n");
+ }
+ }
+ else
+ {
+ // Extract command
+ CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;
+ CMyComPtr<IArchiveExtractCallback> extractCallback(extractCallbackSpec);
+ extractCallbackSpec->Init(archive, L""); // second parameter is output folder path
+ extractCallbackSpec->PasswordIsDefined = false;
+ // extractCallbackSpec->PasswordIsDefined = true;
+ // extractCallbackSpec->Password = L"1";
+ HRESULT result = archive->Extract(NULL, (UInt32)(Int32)(-1), false, extractCallback);
+ if (result != S_OK)
+ {
+ PrintError("Extract Error");
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/makefile
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/makefile?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/makefile (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/makefile Sun Dec 16 23:23:25 2012
@@ -0,0 +1,33 @@
+PROG=../../../../bin/Client7z$(BINSUFFIX)
+
+LOCAL_FLAGS=-DUNICODE -D_UNICODE
+
+include ../../../../makefile.crc32
+include ../../../../makefile.machine
+
+PCH_NAME=$(PRE_COMPILED_HEADER)
+
+LIBS=$(LOCAL_LIBS_DLL)
+
+OBJS = \
+wine_date_and_time.o \
+MyWindows.o \
+DLL.o \
+FileDir.o \
+FileFind.o \
+FileIO.o \
+FileName.o \
+PropVariant.o \
+PropVariantConversions.o \
+IntToString.o \
+MyString.o \
+StringConvert.o \
+UTFConvert.o \
+MyVector.o \
+Wildcard.o \
+FileStreams.o \
+Threads.o \
+Client7z.o
+
+include ../../../../makefile.glb
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/makefile.depend
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/makefile.depend?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/makefile.depend (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/makefile.depend Sun Dec 16 23:23:25 2012
@@ -0,0 +1,180 @@
+wine_date_and_time.o: ../../../myWindows/wine_date_and_time.cpp \
+ ../../../myWindows/config.h ../../../include_windows/windows.h \
+ ../../../Common/MyWindows.h ../../../Common/MyGuidDef.h \
+ ../../../Common/Types.h ../../../Common/../../C/Types.h \
+ ../../../include_windows/basetyps.h
+DLL.o: ../../../Windows/DLL.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Windows/DLL.h \
+ ../../../Windows/../Common/MyString.h \
+ ../../../Windows/../Common/MyVector.h ../../../Windows/../Common/Defs.h \
+ ../../../Windows/Defs.h ../../../Windows/../Common/MyWindows.h \
+ ../../../Windows/../Common/StringConvert.h \
+ ../../../Windows/../Common/MyWindows.h \
+ ../../../Windows/../Common/MyString.h ../../../Windows/../Common/Types.h \
+ ../../../myWindows/myPrivate.h
+FileDir.o: ../../../Windows/FileDir.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Windows/FileDir.h \
+ ../../../Windows/../Common/MyString.h \
+ ../../../Windows/../Common/MyVector.h ../../../Windows/../Common/Defs.h \
+ ../../../Windows/Defs.h ../../../Windows/../Common/MyWindows.h \
+ ../../../Windows/FileName.h ../../../Windows/../../C/Types.h \
+ ../../../Windows/FileFind.h ../../../Windows/../Common/StringConvert.h \
+ ../../../Windows/../Common/MyWindows.h \
+ ../../../Windows/../Common/MyString.h ../../../Windows/../Common/Types.h \
+ ../../../Windows/../Common/IntToString.h ../../../myWindows/myPrivate.h \
+ ../../../Windows/Synchronization.h ../../../Windows/../../C/Threads.h \
+ ../../../Windows/../../C/Types.h ../../../Windows/Synchronization2.h
+FileFind.o: ../../../Windows/FileFind.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Windows/FileFind.h \
+ ../../../Windows/../Common/MyString.h \
+ ../../../Windows/../Common/MyVector.h ../../../Windows/../Common/Defs.h \
+ ../../../Windows/FileName.h ../../../Windows/../../C/Types.h \
+ ../../../Windows/Defs.h ../../../Windows/../Common/MyWindows.h \
+ ../../../Windows/../Common/StringConvert.h \
+ ../../../Windows/../Common/MyWindows.h \
+ ../../../Windows/../Common/MyString.h ../../../Windows/../Common/Types.h \
+ ../../../myWindows/myPrivate.h
+FileIO.o: ../../../Windows/FileIO.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Windows/FileIO.h \
+ ../../../Common/MyString.h ../../../Common/MyVector.h \
+ ../../../Common/Defs.h ../../../Windows/Defs.h \
+ ../../../Windows/../Common/MyWindows.h \
+ ../../../Windows/../Common/StringConvert.h \
+ ../../../Windows/../Common/MyWindows.h \
+ ../../../Windows/../Common/MyString.h ../../../Windows/../Common/Types.h \
+ ../../../myWindows/myPrivate.h
+FileName.o: ../../../Windows/FileName.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Windows/FileName.h \
+ ../../../Windows/../../C/Types.h ../../../Windows/../Common/MyString.h \
+ ../../../Windows/../Common/MyVector.h ../../../Windows/../Common/Defs.h \
+ ../../../Common/Wildcard.h ../../../Common/MyString.h
+PropVariant.o: ../../../Windows/PropVariant.cpp \
+ ../../../myWindows/StdAfx.h ../../../myWindows/config.h \
+ ../../../Common/MyWindows.h ../../../Common/MyGuidDef.h \
+ ../../../Common/Types.h ../../../Common/../../C/Types.h \
+ ../../../Common/Types.h ../../../include_windows/windows.h \
+ ../../../include_windows/basetyps.h ../../../include_windows/tchar.h \
+ ../../../Windows/PropVariant.h ../../../Windows/../Common/MyWindows.h \
+ ../../../Windows/../Common/Types.h ../../../Windows/../Common/Defs.h
+PropVariantConversions.o: ../../../Windows/PropVariantConversions.cpp \
+ ../../../myWindows/StdAfx.h ../../../myWindows/config.h \
+ ../../../Common/MyWindows.h ../../../Common/MyGuidDef.h \
+ ../../../Common/Types.h ../../../Common/../../C/Types.h \
+ ../../../Common/Types.h ../../../include_windows/windows.h \
+ ../../../include_windows/basetyps.h ../../../include_windows/tchar.h \
+ ../../../Common/IntToString.h ../../../Common/StringConvert.h \
+ ../../../Common/MyWindows.h ../../../Common/MyString.h \
+ ../../../Common/MyVector.h ../../../Common/Defs.h \
+ ../../../Windows/Defs.h ../../../Windows/../Common/MyWindows.h \
+ ../../../Windows/PropVariantConversions.h ../../../Common/MyString.h
+IntToString.o: ../../../Common/IntToString.cpp \
+ ../../../myWindows/StdAfx.h ../../../myWindows/config.h \
+ ../../../Common/MyWindows.h ../../../Common/MyGuidDef.h \
+ ../../../Common/Types.h ../../../Common/../../C/Types.h \
+ ../../../Common/Types.h ../../../include_windows/windows.h \
+ ../../../include_windows/basetyps.h ../../../include_windows/tchar.h \
+ ../../../Common/IntToString.h
+MyWindows.o: ../../../Common/MyWindows.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Common/MyWindows.h
+MyString.o: ../../../Common/MyString.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Common/StringConvert.h \
+ ../../../Common/MyWindows.h ../../../Common/MyString.h \
+ ../../../Common/MyVector.h ../../../Common/Defs.h \
+ ../../../myWindows/myPrivate.h
+StringConvert.o: ../../../Common/StringConvert.cpp \
+ ../../../myWindows/StdAfx.h ../../../myWindows/config.h \
+ ../../../Common/MyWindows.h ../../../Common/MyGuidDef.h \
+ ../../../Common/Types.h ../../../Common/../../C/Types.h \
+ ../../../Common/Types.h ../../../include_windows/windows.h \
+ ../../../include_windows/basetyps.h ../../../include_windows/tchar.h \
+ ../../../Common/StringConvert.h ../../../Common/MyWindows.h \
+ ../../../Common/MyString.h ../../../Common/MyVector.h \
+ ../../../Common/Defs.h
+UTFConvert.o: ../../../Common/UTFConvert.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Common/UTFConvert.h \
+ ../../../Common/MyString.h ../../../Common/MyVector.h \
+ ../../../Common/Defs.h
+MyVector.o: ../../../Common/MyVector.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Common/MyVector.h \
+ ../../../Common/Defs.h
+Wildcard.o: ../../../Common/Wildcard.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Common/Wildcard.h \
+ ../../../Common/MyString.h ../../../Common/MyVector.h \
+ ../../../Common/Defs.h
+FileStreams.o: ../../Common/FileStreams.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../Common/FileStreams.h \
+ ../../Common/../../Windows/FileIO.h ../../../Common/MyString.h \
+ ../../../Common/MyVector.h ../../../Common/Defs.h \
+ ../../Common/../../Common/MyCom.h ../../Common/../../Common/MyWindows.h \
+ ../../Common/../IStream.h ../../Common/../../Common/MyUnknown.h \
+ ../../Common/../../Common/Types.h ../../Common/../IDecl.h
+Client7z.o: Client7z.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/../../C/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Common/IntToString.h \
+ ../../../Common/MyInitGuid.h ../../../Common/StringConvert.h \
+ ../../../Common/MyWindows.h ../../../Common/MyString.h \
+ ../../../Common/MyVector.h ../../../Common/Defs.h ../../../Windows/DLL.h \
+ ../../../Windows/../Common/MyString.h ../../../Windows/FileDir.h \
+ ../../../Windows/Defs.h ../../../Windows/../Common/MyWindows.h \
+ ../../../Windows/FileFind.h ../../../Windows/FileName.h \
+ ../../../Windows/../../C/Types.h ../../../Windows/FileName.h \
+ ../../../Windows/NtCheck.h ../../../Windows/PropVariant.h \
+ ../../../Windows/../Common/Types.h \
+ ../../../Windows/PropVariantConversions.h ../../../Common/MyString.h \
+ ../../Common/FileStreams.h ../../Common/../../Windows/FileIO.h \
+ ../../Common/../../Common/MyCom.h ../../Common/../../Common/MyWindows.h \
+ ../../Common/../IStream.h ../../Common/../../Common/MyUnknown.h \
+ ../../Common/../../Common/Types.h ../../Common/../IDecl.h \
+ ../../Archive/IArchive.h ../../Archive/../IProgress.h \
+ ../../Archive/../../Common/MyUnknown.h \
+ ../../Archive/../../Common/Types.h ../../Archive/../IDecl.h \
+ ../../Archive/../IStream.h ../../Archive/../PropID.h ../../IPassword.h \
+ ../../../Common/MyUnknown.h ../../../Common/Types.h ../../IDecl.h \
+ ../../MyVersion.h
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/makefile.list
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/makefile.list?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/makefile.list (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Client7z/makefile.list Sun Dec 16 23:23:25 2012
@@ -0,0 +1,23 @@
+SRCS=\
+../../../myWindows/wine_date_and_time.cpp \
+../../../Windows/DLL.cpp \
+../../../Windows/FileDir.cpp \
+../../../Windows/FileFind.cpp \
+../../../Windows/FileIO.cpp \
+../../../Windows/FileName.cpp \
+../../../Windows/PropVariant.cpp \
+../../../Windows/PropVariantConversions.cpp \
+../../../Common/IntToString.cpp \
+../../../Common/MyWindows.cpp \
+../../../Common/MyString.cpp \
+../../../Common/StringConvert.cpp \
+../../../Common/UTFConvert.cpp \
+../../../Common/MyVector.cpp \
+../../../Common/Wildcard.cpp \
+../../Common/FileStreams.cpp \
+./Client7z.cpp
+
+include ../../../../makefile.rules
+
+Client7z.o : ./Client7z.cpp
+ $(CXX) $(CXXFLAGS) ./Client7z.cpp
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/ClientCodec.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/ClientCodec.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/ClientCodec.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/ClientCodec.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,370 @@
+// Client7z.cpp
+
+#include "StdAfx.h"
+
+#ifdef _WIN32
+#include <initguid.h>
+#else
+#include "Common/MyInitGuid.h"
+#endif
+
+#include "Windows/DLL.h"
+#include "../../ICoder.h"
+#include "Windows/PropVariant.h"
+#include "Common/MyCom.h"
+
+using namespace NWindows;
+
+class CFileIn : public ISequentialInStream, public CMyUnknownImp
+{
+ FILE *file_;
+ size_t pos_;
+ public:
+ MY_UNKNOWN_IMP
+
+ CFileIn() : file_(0) , pos_(0) { }
+ ~CFileIn() { this->close(); }
+
+ HRESULT open(const char *name)
+ {
+ file_ = fopen(name,"rb");
+ if (file_) return S_OK;
+ return E_FAIL;
+ }
+ void close()
+ {
+ if (file_) fclose(file_);
+ file_ = 0;
+ pos_ = 0;
+ }
+ HRESULT Read(void *data, UInt32 size, UInt32 *processedSize)
+ {
+ if (file_)
+ {
+ size_t ret = fread (data, 1, size, file_);
+ *processedSize = ret;
+ pos_ += ret;
+ // TBD : if ret == 0, test for feof/ferror
+ return S_OK;
+ }
+ return E_FAIL;
+ }
+ size_t pos() { return pos_; }
+};
+
+class CFileOut : public ISequentialOutStream, public CMyUnknownImp
+{
+ FILE *file_;
+ size_t pos_;
+ public:
+ MY_UNKNOWN_IMP
+
+ CFileOut() : file_(0) { }
+ ~CFileOut() { this->close(); }
+
+ HRESULT open(const char *name)
+ {
+ file_ = fopen(name,"wb");
+ if (file_) return S_OK;
+ return E_FAIL;
+ }
+ void close()
+ {
+ if (file_) fclose(file_);
+ file_ = 0;
+ }
+ HRESULT Write(const void *data, UInt32 size, UInt32 *processedSize)
+ {
+ if (file_)
+ {
+ size_t ret = fwrite(data, 1, size, file_);
+ *processedSize = ret;
+ pos_ += ret;
+ // TBD : if ret == 0, test for feof/ferror
+ return S_OK;
+ }
+ return E_FAIL;
+ }
+ size_t pos() { return pos_; }
+};
+
+//////////////////////////////////////////////////////////////////////////
+// Main function
+
+static const char *kHelpString =
+"Usage: ClientCodec codec.so [c | d | i] [file_in file_out]\n"
+"Examples:\n"
+" ClientCodec LZMA.so i : info about the codec\n"
+" ClientCodec LZMA.so e file_in file_out : encodes file_in to file_out\n"
+" ClientCodec LZMA.so d file_in file_out : decodes file_in to file_out\n"
+;
+
+typedef UINT32 (WINAPI * CreateObjectFunc)(
+ const GUID *clsID,
+ const GUID *interfaceID,
+ void **outObject);
+
+typedef UINT32 (WINAPI * GetNumberOfMethodsFunc)(UINT32 *numMethods);
+
+typedef UINT32 (WINAPI * GetMethodPropertyFunc)(UINT32 index, PROPID propID, PROPVARIANT *value);
+
+int main(int argc, char* argv[])
+{
+ if ((argc != 3) && (argc != 5))
+ {
+ printf(kHelpString);
+ return 1;
+ }
+
+ if ((argc == 3) && (strcmp(argv[2],"i") != 0))
+ {
+ printf(kHelpString);
+ return 1;
+ }
+
+ NWindows::NDLL::CLibrary library;
+ if (!library.Load(argv[1]))
+ {
+ printf("Can not load library %s\n",argv[1]);
+ return 1;
+ }
+ CreateObjectFunc createObjectFunc = (CreateObjectFunc)library.GetProcAddress("CreateObject");
+ if (createObjectFunc == 0)
+ {
+ printf("Can not get CreateObject\n");
+ return 1;
+ }
+
+ GetNumberOfMethodsFunc getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)library.GetProcAddress("GetNumberOfMethods");
+ if (getNumberOfMethodsFunc == 0)
+ {
+ printf("Can not get GetNumberOfMethodsFunc\n");
+ return 1;
+ }
+
+ UINT32 numMethods = 0;
+ HRESULT res = getNumberOfMethodsFunc(&numMethods);
+ if (res != S_OK)
+ {
+ printf("Error in GetNumberOfMethods\n");
+ return 1;
+ }
+
+ GetMethodPropertyFunc getMethodPropertyFunc = (GetMethodPropertyFunc)library.GetProcAddress("GetMethodProperty");
+ if (getMethodPropertyFunc == 0)
+ {
+ printf("Can not get GetMethodProperty\n");
+ return 1;
+ }
+
+ if (argv[2][0] == 'i')
+ {
+ printf("%s has %d method(s)\n",argv[1],(int)numMethods);
+
+ for(UINT32 m = 0; m < numMethods ; m++)
+ {
+ printf("\tMethod %d :\n",(int)m);
+ NCOM::CPropVariant propVariant;
+ res = getMethodPropertyFunc(m,NMethodPropID::kName,&propVariant);
+ if (res == S_OK)
+ {
+ if (propVariant.vt == VT_BSTR)
+ {
+ printf("\t\tName : %ls\n",propVariant.bstrVal); // Unicode Name
+ } else {
+ printf("\t\tName : Error\n");
+ }
+ } else {
+ printf("\t\tName : Unknown\n");
+ }
+ res = getMethodPropertyFunc(m,NMethodPropID::kDecoder,&propVariant);
+ if ((res == S_OK) && (propVariant.vt == VT_BSTR)) printf("\t\tDecoder : YES\n");
+ else printf("\t\tDecoder : NO\n");
+
+ res = getMethodPropertyFunc(m,NMethodPropID::kEncoder,&propVariant);
+ if ((res == S_OK) && (propVariant.vt == VT_BSTR)) printf("\t\tEncoder : YES\n");
+ else printf("\t\tEncoder : NO\n");
+ }
+ }
+
+ int numMethod = 0; // TBD
+
+ if (argv[2][0] == 'e')
+ {
+ NCOM::CPropVariant propVariant;
+ res = getMethodPropertyFunc(numMethod,NMethodPropID::kEncoder,&propVariant);
+ if ((res == S_OK) && (propVariant.vt == VT_BSTR))
+ {
+ CMyComPtr<ICompressCoder> outCoder;
+ if (createObjectFunc((const GUID *)propVariant.bstrVal, &IID_ICompressCoder, (void **)&outCoder) != S_OK)
+ {
+ printf("Can not get class object\n");
+ return 1;
+ }
+ printf("Encoding : ...\n");
+
+ CMyComPtr<CFileIn> inStream = new CFileIn;
+ res = inStream->open(argv[3]);
+ if (res != S_OK)
+ {
+ printf("cannot open %s\n",argv[3]);
+ return 1;
+ }
+
+ CMyComPtr<CFileOut> outStream = new CFileOut;
+ res = outStream->open(argv[4]);
+ if (res != S_OK)
+ {
+ printf("cannot open %s\n",argv[4]);
+ return 1;
+ }
+{
+ CMyComPtr<ICompressSetCoderProperties> setCoderProperties;
+ outCoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties);
+ if (setCoderProperties != NULL)
+ {
+ printf("IID_ICompressSetCoderProperties : Found\n");
+ PROPID propID = NCoderPropID::kEndMarker;
+ NWindows::NCOM::CPropVariant value = true;
+ res = setCoderProperties->SetCoderProperties(&propID, &value, 1);
+ if (res = S_OK) printf("kEndMarker : ON\n");
+ else printf("kEndMarker : KO KO\n");
+ }
+ else
+ {
+ printf("IID_ICompressSetCoderProperties : NOT Found\n");
+ }
+}
+
+{
+ CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;
+
+ outCoder.QueryInterface(IID_ICompressWriteCoderProperties, &writeCoderProperties);
+
+ if (writeCoderProperties != NULL)
+ {
+ UINT32 len = 5; // TBD
+ UInt32 processedSize;
+ outStream->Write(&len, sizeof(len), &processedSize);
+
+ printf("IID_ICompressWriteCoderProperties : Found\n");
+ size_t pos1 = outStream->pos();
+ writeCoderProperties->WriteCoderProperties(outStream);
+ size_t pos2 = outStream->pos();
+ printf("SizeOfProp : %d\n",(int)(pos2-pos1));
+/*
+ CSequentialOutStreamImp *outStreamSpec = new CSequentialOutStreamImp;
+ CMyComPtr<ISequentialOutStream> outStream(outStreamSpec);
+ outStreamSpec->Init();
+ writeCoderProperties->WriteCoderProperties(outStream);
+
+ size_t size = outStreamSpec->GetSize();
+
+ // encodingInfo.Properties.SetCapacity(size);
+ if (encodingInfo.AltCoders.Size() == 0)
+ encodingInfo.AltCoders.Add(CAltCoderInfo());
+ CAltCoderInfo &altCoderInfo = encodingInfo.AltCoders.Front();
+ altCoderInfo.Properties.SetCapacity(size);
+
+ memmove(altCoderInfo.Properties, outStreamSpec->GetBuffer(), size);
+*/
+ }
+ else
+ {
+ printf("IID_ICompressWriteCoderProperties : NOT Found\n");
+ UINT32 len = 0;
+ UInt32 processedSize;
+ outStream->Write(&len, sizeof(len), &processedSize);
+ }
+}
+
+ res = outCoder->Code(inStream,outStream,0,0,0);
+ inStream->close();
+ outStream->close();
+
+ if (res == S_OK)
+ {
+ printf("Encoding : Done\n");
+ } else {
+ printf("Encoding : Error\n");
+ return 1;
+ }
+ }
+ else
+ {
+ printf("Encoder not available\n");
+ return 1;
+ }
+ }
+
+ if (argv[2][0] == 'd')
+ {
+ NCOM::CPropVariant propVariant;
+ res = getMethodPropertyFunc(numMethod,NMethodPropID::kDecoder,&propVariant);
+ if ((res == S_OK) && (propVariant.vt == VT_BSTR))
+ {
+ CMyComPtr<ICompressCoder> outCoder;
+ if (createObjectFunc((const GUID *)propVariant.bstrVal, &IID_ICompressCoder, (void **)&outCoder) != S_OK)
+ {
+ printf("Can not get class object\n");
+ return 1;
+ }
+ printf("Decoding : ...\n");
+
+ CMyComPtr<CFileIn> inStream = new CFileIn;
+ res = inStream->open(argv[3]);
+ if (res != S_OK)
+ {
+ printf("cannot open %s\n",argv[3]);
+ return 1;
+ }
+
+ CMyComPtr<CFileOut> outStream = new CFileOut;
+ res = outStream->open(argv[4]);
+ if (res != S_OK)
+ {
+ printf("cannot open %s\n",argv[4]);
+ return 1;
+ }
+{
+ UINT32 len = 0;
+ UInt32 processedSize;
+ inStream->Read(&len, sizeof(len), &processedSize);
+
+ if (len > 0)
+ {
+ Byte props[256]; // TBD
+ inStream->Read(props, len, &processedSize);
+
+ CMyComPtr<ICompressSetDecoderProperties2> setDecoderProperties;
+ outCoder->QueryInterface(IID_ICompressSetDecoderProperties2, (void **)&setDecoderProperties);
+ if (setDecoderProperties)
+ {
+ setDecoderProperties->SetDecoderProperties2(props, len);
+ printf("IID_ICompressSetDecoderProperties2 : Found (%d)\n",(int)len);
+ }
+ }
+}
+
+ // FIXME UInt64 outSize = 10511; // res = outCoder->Code(inStream,outStream,0,&outSize,0);
+ res = outCoder->Code(inStream,outStream,0,0,0);
+ inStream->close();
+ outStream->close();
+
+ if (res == S_OK)
+ {
+ printf("Decoding : Done\n");
+ } else {
+ printf("Decoding : Error\n");
+ return 1;
+ }
+ }
+ else
+ {
+ printf("Decoder not available\n");
+ return 1;
+ }
+ }
+
+ return 0;
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/makefile
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/makefile?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/makefile (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/makefile Sun Dec 16 23:23:25 2012
@@ -0,0 +1,41 @@
+PROG=../../../../bin/ClientCodec
+
+LOCAL_FLAGS=-DUNICODE -D_UNICODE
+
+include ../../../../makefile.crc32
+include ../../../../makefile.machine
+
+LIBS=$(LOCAL_LIBS_DLL)
+
+OBJS = \
+wine_date_and_time.o \
+MyWindows.o \
+ClientCodec.o \
+MyString.o \
+StringConvert.o \
+PropVariant.o \
+DLL.o
+
+
+
+.PHONY: test
+
+#CODER=../../../bin/Codecs/BZip2.so # OK - ICompressWriteCoderProperties : NOT Found
+#CODER=../../../bin/Codecs/Copy.so # OK - ICompressWriteCoderProperties : NOT Found
+#CODER=../../../bin/Codecs/Deflate.so # OK - ICompressWriteCoderProperties : NOT Found
+CODER=../../../bin/Codecs/LZMA.so # OK - ICompressWriteCoderProperties=5
+#CODER=../../../bin/Codecs/PPMD.so # KO Encoder - ICompressWriteCoderProperties=5
+
+
+test : all
+ cp ClientCodec.cpp f1
+ ../../../../bin/ClientCodec $(CODER) i
+ ../../../../bin/ClientCodec $(CODER) e f1 f2
+ ../../../../bin/ClientCodec $(CODER) d f2 f3
+ diff -q f1 f3
+
+clean2:
+ rm -f f1 f2 f3
+
+include ../../../../makefile.glb
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/makefile.depend
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/makefile.depend?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/makefile.depend (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/makefile.depend Sun Dec 16 23:23:25 2012
@@ -0,0 +1,62 @@
+wine_date_and_time.o: ../../../myWindows/wine_date_and_time.cpp \
+ ../../../myWindows/config.h ../../../include_windows/windows.h \
+ ../../../Common/MyWindows.h ../../../Common/MyGuidDef.h \
+ ../../../Common/Types.h ../../../include_windows/basetyps.h
+MyWindows.o: ../../../Common/MyWindows.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/Types.h ../../../include_windows/windows.h \
+ ../../../Common/MyWindows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Common/MyWindows.h
+MyString.o: ../../../Common/MyString.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/Types.h ../../../include_windows/windows.h \
+ ../../../Common/MyWindows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Common/StringConvert.h \
+ ../../../Common/MyWindows.h ../../../Common/MyString.h \
+ ../../../Common/MyVector.h ../../../Common/Defs.h \
+ ../../../myWindows/myPrivate.h
+StringConvert.o: ../../../Common/StringConvert.cpp \
+ ../../../myWindows/StdAfx.h ../../../myWindows/config.h \
+ ../../../Common/MyWindows.h ../../../Common/MyGuidDef.h \
+ ../../../Common/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../Common/MyWindows.h \
+ ../../../include_windows/basetyps.h ../../../include_windows/tchar.h \
+ ../../../Common/StringConvert.h ../../../Common/MyWindows.h \
+ ../../../Common/MyString.h ../../../Common/MyVector.h \
+ ../../../Common/Defs.h ../../../Common/UTFConvert.cpp \
+ ../../../Common/UTFConvert.h
+PropVariant.o: ../../../Windows/PropVariant.cpp \
+ ../../../myWindows/StdAfx.h ../../../myWindows/config.h \
+ ../../../Common/MyWindows.h ../../../Common/MyGuidDef.h \
+ ../../../Common/Types.h ../../../Common/Types.h \
+ ../../../include_windows/windows.h ../../../Common/MyWindows.h \
+ ../../../include_windows/basetyps.h ../../../include_windows/tchar.h \
+ ../../../Windows/PropVariant.h ../../../Windows/../Common/MyWindows.h \
+ ../../../Windows/../Common/Types.h ../../../Windows/../Common/Defs.h
+DLL.o: ../../../Windows/DLL.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/Types.h ../../../include_windows/windows.h \
+ ../../../Common/MyWindows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Windows/DLL.h \
+ ../../../Windows/../Common/MyString.h \
+ ../../../Windows/../Common/MyVector.h ../../../Windows/../Common/Defs.h \
+ ../../../Windows/Defs.h ../../../Windows/../Common/StringConvert.h \
+ ../../../Windows/../Common/MyWindows.h \
+ ../../../Windows/../Common/MyString.h \
+ ../../../Windows/../Common/Types.h ../../../myWindows/myPrivate.h
+ClientCodec.o: ClientCodec.cpp ../../../myWindows/StdAfx.h \
+ ../../../myWindows/config.h ../../../Common/MyWindows.h \
+ ../../../Common/MyGuidDef.h ../../../Common/Types.h \
+ ../../../Common/Types.h ../../../include_windows/windows.h \
+ ../../../Common/MyWindows.h ../../../include_windows/basetyps.h \
+ ../../../include_windows/tchar.h ../../../Common/MyInitGuid.h \
+ ../../../Windows/DLL.h ../../../Windows/../Common/MyString.h \
+ ../../../Windows/../Common/MyVector.h ../../../Windows/../Common/Defs.h \
+ ../../ICoder.h ../../IStream.h ../../../Common/MyUnknown.h \
+ ../../../Common/MyWindows.h ../../../Common/Types.h \
+ ../../../Windows/PropVariant.h ../../../Windows/../Common/MyWindows.h \
+ ../../../Windows/../Common/Types.h ../../../Common/MyCom.h \
+ ../../../Common/MyWindows.h
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/makefile.list
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/makefile.list?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/makefile.list (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/ClientCodec/makefile.list Sun Dec 16 23:23:25 2012
@@ -0,0 +1,24 @@
+SRCS=\
+../../../myWindows/wine_date_and_time.cpp \
+../../../Common/MyWindows.cpp \
+../../../Common/MyString.cpp \
+../../../Common/StringConvert.cpp \
+../../../Windows/PropVariant.cpp \
+../../../Windows/DLL.cpp \
+./ClientCodec.cpp
+
+wine_date_and_time.o : ../../../myWindows/wine_date_and_time.cpp
+ $(CXX) $(CXXFLAGS) ../../../myWindows/wine_date_and_time.cpp
+MyWindows.o : ../../../Common/MyWindows.cpp
+ $(CXX) $(CXXFLAGS) ../../../Common/MyWindows.cpp
+MyString.o : ../../../Common/MyString.cpp
+ $(CXX) $(CXXFLAGS) ../../../Common/MyString.cpp
+StringConvert.o : ../../../Common/StringConvert.cpp
+ $(CXX) $(CXXFLAGS) ../../../Common/StringConvert.cpp
+PropVariant.o : ../../../Windows/PropVariant.cpp
+ $(CXX) $(CXXFLAGS) ../../../Windows/PropVariant.cpp
+DLL.o : ../../../Windows/DLL.cpp
+ $(CXX) $(CXXFLAGS) ../../../Windows/DLL.cpp
+ClientCodec.o : ./ClientCodec.cpp
+ $(CXX) $(CXXFLAGS) ./ClientCodec.cpp
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveCommandLine.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,1010 @@
+// ArchiveCommandLine.cpp
+
+#include "StdAfx.h"
+
+#ifdef _WIN32
+#ifndef UNDER_CE
+#include <io.h>
+#endif
+#endif
+#include <stdio.h>
+
+#include "Common/ListFileUtils.h"
+#include "Common/StringConvert.h"
+#include "Common/StringToInt.h"
+
+#include "Windows/FileDir.h"
+#include "Windows/FileName.h"
+#ifdef _WIN32
+#include "Windows/FileMapping.h"
+#include "Windows/Synchronization.h"
+#else
+#include "myPrivate.h"
+#endif
+
+#include "ArchiveCommandLine.h"
+#include "EnumDirItems.h"
+#include "SortUtils.h"
+#include "Update.h"
+#include "UpdateAction.h"
+
+extern bool g_CaseSensitive;
+
+#ifdef UNDER_CE
+
+#define MY_IS_TERMINAL(x) false;
+
+#else
+
+#if _MSC_VER >= 1400
+#define MY_isatty_fileno(x) _isatty(_fileno(x))
+#else
+#define MY_isatty_fileno(x) isatty(fileno(x))
+#endif
+
+#define MY_IS_TERMINAL(x) (MY_isatty_fileno(x) != 0);
+
+#endif
+
+using namespace NCommandLineParser;
+using namespace NWindows;
+using namespace NFile;
+
+namespace NKey {
+enum Enum
+{
+ kHelp1 = 0,
+ kHelp2,
+ kHelp3,
+ kDisableHeaders,
+ kDisablePercents,
+ kArchiveType,
+ kYes,
+ #ifndef _NO_CRYPTO
+ kPassword,
+ #endif
+ kProperty,
+ kOutputDir,
+ kWorkingDir,
+ kInclude,
+ kExclude,
+ kArInclude,
+ kArExclude,
+ kNoArName,
+ kUpdate,
+ kVolume,
+ kRecursed,
+ kSfx,
+ kStdIn,
+ kStdOut,
+ kOverwrite,
+ kEmail,
+ kShowDialog,
+ kLargePages,
+ kUseLStat,
+ kTechMode,
+ kCaseSensitive,
+ kCalcCrc
+};
+
+}
+
+
+static const wchar_t kRecursedIDChar = 'R';
+static const wchar_t *kRecursedPostCharSet = L"0-";
+
+namespace NRecursedPostCharIndex {
+ enum EEnum
+ {
+ kWildCardRecursionOnly = 0,
+ kNoRecursion = 1
+ };
+}
+
+static const char kImmediateNameID = '!';
+static const char kMapNameID = '#';
+static const char kFileListID = '@';
+
+static const char kSomeCludePostStringMinSize = 2; // at least <@|!><N>ame must be
+static const char kSomeCludeAfterRecursedPostStringMinSize = 2; // at least <@|!><N>ame must be
+
+static const wchar_t *kOverwritePostCharSet = L"asut";
+
+NExtract::NOverwriteMode::EEnum k_OverwriteModes[] =
+{
+ NExtract::NOverwriteMode::kWithoutPrompt,
+ NExtract::NOverwriteMode::kSkipExisting,
+ NExtract::NOverwriteMode::kAutoRename,
+ NExtract::NOverwriteMode::kAutoRenameExisting
+};
+
+static const CSwitchForm kSwitchForms[] =
+ {
+ { L"?", NSwitchType::kSimple, false },
+ { L"H", NSwitchType::kSimple, false },
+ { L"-HELP", NSwitchType::kSimple, false },
+ { L"BA", NSwitchType::kSimple, false },
+ { L"BD", NSwitchType::kSimple, false },
+ { L"T", NSwitchType::kUnLimitedPostString, false, 1 },
+ { L"Y", NSwitchType::kSimple, false },
+ #ifndef _NO_CRYPTO
+ { L"P", NSwitchType::kUnLimitedPostString, false, 0 },
+ #endif
+ { L"M", NSwitchType::kUnLimitedPostString, true, 1 },
+ { L"O", NSwitchType::kUnLimitedPostString, false, 1 },
+ { L"W", NSwitchType::kUnLimitedPostString, false, 0 },
+ { L"I", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},
+ { L"X", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},
+ { L"AI", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},
+ { L"AX", NSwitchType::kUnLimitedPostString, true, kSomeCludePostStringMinSize},
+ { L"AN", NSwitchType::kSimple, false },
+ { L"U", NSwitchType::kUnLimitedPostString, true, 1},
+ { L"V", NSwitchType::kUnLimitedPostString, true, 1},
+ { L"R", NSwitchType::kPostChar, false, 0, 0, kRecursedPostCharSet },
+ { L"SFX", NSwitchType::kUnLimitedPostString, false, 0 },
+ { L"SI", NSwitchType::kUnLimitedPostString, false, 0 },
+ { L"SO", NSwitchType::kSimple, false, 0 },
+ { L"AO", NSwitchType::kPostChar, false, 1, 1, kOverwritePostCharSet},
+ { L"SEML", NSwitchType::kUnLimitedPostString, false, 0},
+ { L"AD", NSwitchType::kSimple, false },
+ { L"SLP", NSwitchType::kUnLimitedPostString, false, 0},
+ { L"L", NSwitchType::kSimple, false },
+ { L"SLT", NSwitchType::kSimple, false },
+ { L"SSC", NSwitchType::kPostChar, false, 0, 0, L"-" },
+ { L"SCRC", NSwitchType::kSimple, false }
+ };
+
+static const CCommandForm g_CommandForms[] =
+{
+ { L"A", false },
+ { L"U", false },
+ { L"D", false },
+ { L"T", false },
+ { L"E", false },
+ { L"X", false },
+ { L"L", false },
+ { L"B", false },
+ { L"I", false }
+};
+
+static const int kNumCommandForms = sizeof(g_CommandForms) / sizeof(g_CommandForms[0]);
+
+static const wchar_t *kUniversalWildcard = L"*";
+static const int kMinNonSwitchWords = 1;
+static const int kCommandIndex = 0;
+
+// ---------------------------
+// exception messages
+
+static const char *kUserErrorMessage = "Incorrect command line";
+static const char *kCannotFindListFile = "Cannot find listfile";
+static const char *kIncorrectListFile = "Incorrect item in listfile.\nCheck charset encoding and -scs switch.";
+static const char *kIncorrectWildCardInListFile = "Incorrect wildcard in listfile";
+static const char *kIncorrectWildCardInCommandLine = "Incorrect wildcard in command line";
+static const char *kTerminalOutError = "I won't write compressed data to a terminal";
+static const char *kSameTerminalError = "I won't write data and program's messages to same terminal";
+static const char *kEmptyFilePath = "Empty file path";
+
+static void ThrowException(const char *errorMessage)
+{
+ throw CArchiveCommandLineException(errorMessage);
+}
+
+static void ThrowUserErrorException()
+{
+ ThrowException(kUserErrorMessage);
+}
+
+// ---------------------------
+
+bool CArchiveCommand::IsFromExtractGroup() const
+{
+ switch(CommandType)
+ {
+ case NCommandType::kTest:
+ case NCommandType::kExtract:
+ case NCommandType::kFullExtract:
+ return true;
+ default:
+ return false;
+ }
+}
+
+NExtract::NPathMode::EEnum CArchiveCommand::GetPathMode() const
+{
+ switch(CommandType)
+ {
+ case NCommandType::kTest:
+ case NCommandType::kFullExtract:
+ return NExtract::NPathMode::kFullPathnames;
+ default:
+ return NExtract::NPathMode::kNoPathnames;
+ }
+}
+
+bool CArchiveCommand::IsFromUpdateGroup() const
+{
+ return (CommandType == NCommandType::kAdd ||
+ CommandType == NCommandType::kUpdate ||
+ CommandType == NCommandType::kDelete);
+}
+
+static NRecursedType::EEnum GetRecursedTypeFromIndex(int index)
+{
+ switch (index)
+ {
+ case NRecursedPostCharIndex::kWildCardRecursionOnly:
+ return NRecursedType::kWildCardOnlyRecursed;
+ case NRecursedPostCharIndex::kNoRecursion:
+ return NRecursedType::kNonRecursed;
+ default:
+ return NRecursedType::kRecursed;
+ }
+}
+
+static bool ParseArchiveCommand(const UString &commandString, CArchiveCommand &command)
+{
+ UString commandStringUpper = commandString;
+ commandStringUpper.MakeUpper();
+ UString postString;
+ int commandIndex = ParseCommand(kNumCommandForms, g_CommandForms, commandStringUpper,
+ postString) ;
+ if (commandIndex < 0)
+ return false;
+ command.CommandType = (NCommandType::EEnum)commandIndex;
+ return true;
+}
+
+// ------------------------------------------------------------------
+// filenames functions
+
+static void AddNameToCensor(NWildcard::CCensor &wildcardCensor,
+ const UString &name, bool include, NRecursedType::EEnum type)
+{
+ bool recursed = false;
+
+ switch (type)
+ {
+ case NRecursedType::kWildCardOnlyRecursed:
+ recursed = DoesNameContainWildCard(name);
+ break;
+ case NRecursedType::kRecursed:
+ recursed = true;
+ break;
+ }
+ wildcardCensor.AddItem(include, name, recursed);
+}
+
+static void AddToCensorFromListFile(NWildcard::CCensor &wildcardCensor,
+ LPCWSTR fileName, bool include, NRecursedType::EEnum type, UINT codePage)
+{
+ UStringVector names;
+ if (!NFind::DoesFileExist(fileName))
+ throw kCannotFindListFile;
+ if (!ReadNamesFromListFile(fileName, names, codePage))
+ throw kIncorrectListFile;
+ for (int i = 0; i < names.Size(); i++)
+ AddNameToCensor(wildcardCensor, names[i], include, type);
+}
+
+static void AddToCensorFromNonSwitchesStrings(
+ int startIndex,
+ NWildcard::CCensor &wildcardCensor,
+ const UStringVector &nonSwitchStrings, NRecursedType::EEnum type,
+ bool thereAreSwitchIncludes, UINT codePage)
+{
+ if (nonSwitchStrings.Size() == startIndex && (!thereAreSwitchIncludes))
+ AddNameToCensor(wildcardCensor, kUniversalWildcard, true, type);
+ for (int i = startIndex; i < nonSwitchStrings.Size(); i++)
+ {
+ const UString &s = nonSwitchStrings[i];
+ if (s.IsEmpty())
+ throw kEmptyFilePath;
+ if (s[0] == kFileListID)
+ AddToCensorFromListFile(wildcardCensor, s.Mid(1), true, type, codePage);
+ else
+ AddNameToCensor(wildcardCensor, s, true, type);
+ }
+}
+
+#ifdef _WIN32
+static void ParseMapWithPaths(NWildcard::CCensor &wildcardCensor,
+ const UString &switchParam, bool include,
+ NRecursedType::EEnum commonRecursedType)
+{
+ int splitPos = switchParam.Find(L':');
+ if (splitPos < 0)
+ ThrowUserErrorException();
+ UString mappingName = switchParam.Left(splitPos);
+
+ UString switchParam2 = switchParam.Mid(splitPos + 1);
+ splitPos = switchParam2.Find(L':');
+ if (splitPos < 0)
+ ThrowUserErrorException();
+
+ UString mappingSize = switchParam2.Left(splitPos);
+ UString eventName = switchParam2.Mid(splitPos + 1);
+
+ UInt64 dataSize64 = ConvertStringToUInt64(mappingSize, NULL);
+ UInt32 dataSize = (UInt32)dataSize64;
+ {
+ CFileMapping fileMapping;
+ if (fileMapping.Open(FILE_MAP_READ, GetSystemString(mappingName)) != 0)
+ ThrowException("Can not open mapping");
+ LPVOID data = fileMapping.Map(FILE_MAP_READ, 0, dataSize);
+ if (data == NULL)
+ ThrowException("MapViewOfFile error");
+ try
+ {
+ const wchar_t *curData = (const wchar_t *)data;
+ if (*curData != 0)
+ ThrowException("Incorrect mapping data");
+ UInt32 numChars = dataSize / sizeof(wchar_t);
+ UString name;
+ for (UInt32 i = 1; i < numChars; i++)
+ {
+ wchar_t c = curData[i];
+ if (c == L'\0')
+ {
+ AddNameToCensor(wildcardCensor, name, include, commonRecursedType);
+ name.Empty();
+ }
+ else
+ name += c;
+ }
+ if (!name.IsEmpty())
+ ThrowException("data error");
+ }
+ catch(...)
+ {
+ UnmapViewOfFile(data);
+ throw;
+ }
+ UnmapViewOfFile(data);
+ }
+
+ {
+ NSynchronization::CManualResetEvent event;
+ if (event.Open(EVENT_MODIFY_STATE, false, GetSystemString(eventName)) == S_OK)
+ event.Set();
+ }
+}
+#endif
+
+static void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor,
+ const UStringVector &strings, bool include,
+ NRecursedType::EEnum commonRecursedType, UINT codePage)
+{
+ for (int i = 0; i < strings.Size(); i++)
+ {
+ const UString &name = strings[i];
+ NRecursedType::EEnum recursedType;
+ int pos = 0;
+ if (name.Length() < kSomeCludePostStringMinSize)
+ ThrowUserErrorException();
+ if (::MyCharUpper(name[pos]) == kRecursedIDChar)
+ {
+ pos++;
+ int index = UString(kRecursedPostCharSet).Find(name[pos]);
+ recursedType = GetRecursedTypeFromIndex(index);
+ if (index >= 0)
+ pos++;
+ }
+ else
+ recursedType = commonRecursedType;
+ if (name.Length() < pos + kSomeCludeAfterRecursedPostStringMinSize)
+ ThrowUserErrorException();
+ UString tail = name.Mid(pos + 1);
+ if (name[pos] == kImmediateNameID)
+ AddNameToCensor(wildcardCensor, tail, include, recursedType);
+ else if (name[pos] == kFileListID)
+ AddToCensorFromListFile(wildcardCensor, tail, include, recursedType, codePage);
+ #ifdef _WIN32
+ else if (name[pos] == kMapNameID)
+ ParseMapWithPaths(wildcardCensor, tail, include, recursedType);
+ #endif
+ else
+ ThrowUserErrorException();
+ }
+}
+
+#ifdef _WIN32
+
+// This code converts all short file names to long file names.
+
+static void ConvertToLongName(const UString &prefix, UString &name)
+{
+ if (name.IsEmpty() || DoesNameContainWildCard(name))
+ return;
+ NFind::CFileInfoW fi;
+ if (fi.Find(prefix + name))
+ name = fi.Name;
+}
+
+static void ConvertToLongNames(const UString &prefix, CObjectVector<NWildcard::CItem> &items)
+{
+ for (int i = 0; i < items.Size(); i++)
+ {
+ NWildcard::CItem &item = items[i];
+ if (item.Recursive || item.PathParts.Size() != 1)
+ continue;
+ ConvertToLongName(prefix, item.PathParts.Front());
+ }
+}
+
+static void ConvertToLongNames(const UString &prefix, NWildcard::CCensorNode &node)
+{
+ ConvertToLongNames(prefix, node.IncludeItems);
+ ConvertToLongNames(prefix, node.ExcludeItems);
+ int i;
+ for (i = 0; i < node.SubNodes.Size(); i++)
+ ConvertToLongName(prefix, node.SubNodes[i].Name);
+ // mix folders with same name
+ for (i = 0; i < node.SubNodes.Size(); i++)
+ {
+ NWildcard::CCensorNode &nextNode1 = node.SubNodes[i];
+ for (int j = i + 1; j < node.SubNodes.Size();)
+ {
+ const NWildcard::CCensorNode &nextNode2 = node.SubNodes[j];
+ if (nextNode1.Name.CompareNoCase(nextNode2.Name) == 0)
+ {
+ nextNode1.IncludeItems += nextNode2.IncludeItems;
+ nextNode1.ExcludeItems += nextNode2.ExcludeItems;
+ node.SubNodes.Delete(j);
+ }
+ else
+ j++;
+ }
+ }
+ for (i = 0; i < node.SubNodes.Size(); i++)
+ {
+ NWildcard::CCensorNode &nextNode = node.SubNodes[i];
+ ConvertToLongNames(prefix + nextNode.Name + wchar_t(NFile::NName::kDirDelimiter), nextNode);
+ }
+}
+
+static void ConvertToLongNames(NWildcard::CCensor &censor)
+{
+ for (int i = 0; i < censor.Pairs.Size(); i++)
+ {
+ NWildcard::CPair &pair = censor.Pairs[i];
+ ConvertToLongNames(pair.Prefix, pair.Head);
+ }
+}
+
+#endif
+
+static NUpdateArchive::NPairAction::EEnum GetUpdatePairActionType(int i)
+{
+ switch(i)
+ {
+ case NUpdateArchive::NPairAction::kIgnore: return NUpdateArchive::NPairAction::kIgnore;
+ case NUpdateArchive::NPairAction::kCopy: return NUpdateArchive::NPairAction::kCopy;
+ case NUpdateArchive::NPairAction::kCompress: return NUpdateArchive::NPairAction::kCompress;
+ case NUpdateArchive::NPairAction::kCompressAsAnti: return NUpdateArchive::NPairAction::kCompressAsAnti;
+ }
+ throw 98111603;
+}
+
+const UString kUpdatePairStateIDSet = L"PQRXYZW";
+const int kUpdatePairStateNotSupportedActions[] = {2, 2, 1, -1, -1, -1, -1};
+
+const UString kUpdatePairActionIDSet = L"0123"; //Ignore, Copy, Compress, Create Anti
+
+const wchar_t *kUpdateIgnoreItselfPostStringID = L"-";
+const wchar_t kUpdateNewArchivePostCharID = '!';
+
+
+static bool ParseUpdateCommandString2(const UString &command,
+ NUpdateArchive::CActionSet &actionSet, UString &postString)
+{
+ for (int i = 0; i < command.Length();)
+ {
+ wchar_t c = MyCharUpper(command[i]);
+ int statePos = kUpdatePairStateIDSet.Find(c);
+ if (statePos < 0)
+ {
+ postString = command.Mid(i);
+ return true;
+ }
+ i++;
+ if (i >= command.Length())
+ return false;
+ int actionPos = kUpdatePairActionIDSet.Find(::MyCharUpper(command[i]));
+ if (actionPos < 0)
+ return false;
+ actionSet.StateActions[statePos] = GetUpdatePairActionType(actionPos);
+ if (kUpdatePairStateNotSupportedActions[statePos] == actionPos)
+ return false;
+ i++;
+ }
+ postString.Empty();
+ return true;
+}
+
+static void ParseUpdateCommandString(CUpdateOptions &options,
+ const UStringVector &updatePostStrings,
+ const NUpdateArchive::CActionSet &defaultActionSet)
+{
+ for (int i = 0; i < updatePostStrings.Size(); i++)
+ {
+ const UString &updateString = updatePostStrings[i];
+ if (updateString.CompareNoCase(kUpdateIgnoreItselfPostStringID) == 0)
+ {
+ if (options.UpdateArchiveItself)
+ {
+ options.UpdateArchiveItself = false;
+ options.Commands.Delete(0);
+ }
+ }
+ else
+ {
+ NUpdateArchive::CActionSet actionSet = defaultActionSet;
+
+ UString postString;
+ if (!ParseUpdateCommandString2(updateString, actionSet, postString))
+ ThrowUserErrorException();
+ if (postString.IsEmpty())
+ {
+ if (options.UpdateArchiveItself)
+ options.Commands[0].ActionSet = actionSet;
+ }
+ else
+ {
+ if (MyCharUpper(postString[0]) != kUpdateNewArchivePostCharID)
+ ThrowUserErrorException();
+ CUpdateArchiveCommand uc;
+ UString archivePath = postString.Mid(1);
+ if (archivePath.IsEmpty())
+ ThrowUserErrorException();
+ uc.UserArchivePath = archivePath;
+ uc.ActionSet = actionSet;
+ options.Commands.Add(uc);
+ }
+ }
+ }
+}
+
+static const char kByteSymbol = 'B';
+static const char kKiloSymbol = 'K';
+static const char kMegaSymbol = 'M';
+static const char kGigaSymbol = 'G';
+
+static bool ParseComplexSize(const UString &src, UInt64 &result)
+{
+ UString s = src;
+ s.MakeUpper();
+
+ const wchar_t *start = s;
+ const wchar_t *end;
+ UInt64 number = ConvertStringToUInt64(start, &end);
+ int numDigits = (int)(end - start);
+ if (numDigits == 0 || s.Length() > numDigits + 1)
+ return false;
+ if (s.Length() == numDigits)
+ {
+ result = number;
+ return true;
+ }
+ int numBits;
+ switch (s[numDigits])
+ {
+ case kByteSymbol:
+ result = number;
+ return true;
+ case kKiloSymbol:
+ numBits = 10;
+ break;
+ case kMegaSymbol:
+ numBits = 20;
+ break;
+ case kGigaSymbol:
+ numBits = 30;
+ break;
+ default:
+ return false;
+ }
+ if (number >= ((UInt64)1 << (64 - numBits)))
+ return false;
+ result = number << numBits;
+ return true;
+}
+
+static void SetAddCommandOptions(
+ NCommandType::EEnum commandType,
+ const CParser &parser,
+ CUpdateOptions &options)
+{
+ NUpdateArchive::CActionSet defaultActionSet;
+ switch(commandType)
+ {
+ case NCommandType::kAdd:
+ defaultActionSet = NUpdateArchive::kAddActionSet;
+ break;
+ case NCommandType::kDelete:
+ defaultActionSet = NUpdateArchive::kDeleteActionSet;
+ break;
+ default:
+ defaultActionSet = NUpdateArchive::kUpdateActionSet;
+ }
+
+ options.UpdateArchiveItself = true;
+
+ options.Commands.Clear();
+ CUpdateArchiveCommand updateMainCommand;
+ updateMainCommand.ActionSet = defaultActionSet;
+ options.Commands.Add(updateMainCommand);
+ if (parser[NKey::kUpdate].ThereIs)
+ ParseUpdateCommandString(options, parser[NKey::kUpdate].PostStrings,
+ defaultActionSet);
+ if (parser[NKey::kWorkingDir].ThereIs)
+ {
+ const UString &postString = parser[NKey::kWorkingDir].PostStrings[0];
+ if (postString.IsEmpty())
+ NDirectory::MyGetTempPath(options.WorkingDir);
+ else
+ options.WorkingDir = postString;
+ }
+ options.SfxMode = parser[NKey::kSfx].ThereIs;
+ if (options.SfxMode)
+ options.SfxModule = parser[NKey::kSfx].PostStrings[0];
+
+ if (parser[NKey::kVolume].ThereIs)
+ {
+ const UStringVector &sv = parser[NKey::kVolume].PostStrings;
+ for (int i = 0; i < sv.Size(); i++)
+ {
+ UInt64 size;
+ if (!ParseComplexSize(sv[i], size))
+ ThrowException("Incorrect volume size");
+ options.VolumesSizes.Add(size);
+ }
+ }
+}
+
+static void SetMethodOptions(const CParser &parser, CObjectVector<CProperty> &properties)
+{
+ if (parser[NKey::kProperty].ThereIs)
+ {
+ // options.MethodMode.Properties.Clear();
+ for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)
+ {
+ CProperty property;
+ const UString &postString = parser[NKey::kProperty].PostStrings[i];
+ int index = postString.Find(L'=');
+ if (index < 0)
+ property.Name = postString;
+ else
+ {
+ property.Name = postString.Left(index);
+ property.Value = postString.Mid(index + 1);
+ }
+ properties.Add(property);
+ }
+ }
+}
+
+CArchiveCommandLineParser::CArchiveCommandLineParser():
+ parser(sizeof(kSwitchForms) / sizeof(kSwitchForms[0])) {}
+
+void CArchiveCommandLineParser::Parse1(const UStringVector &commandStrings,
+ CArchiveCommandLineOptions &options)
+{
+ try
+ {
+ parser.ParseStrings(kSwitchForms, commandStrings);
+ }
+ catch(...)
+ {
+ ThrowUserErrorException();
+ }
+
+ options.IsInTerminal = MY_IS_TERMINAL(stdin);
+ options.IsStdOutTerminal = MY_IS_TERMINAL(stdout);
+ options.IsStdErrTerminal = MY_IS_TERMINAL(stderr);
+ options.StdInMode = parser[NKey::kStdIn].ThereIs;
+ options.StdOutMode = parser[NKey::kStdOut].ThereIs;
+ options.EnableHeaders = !parser[NKey::kDisableHeaders].ThereIs;
+ options.HelpMode = parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs || parser[NKey::kHelp3].ThereIs;
+
+ #ifdef _7ZIP_LARGE_PAGES
+ options.LargePages = false;
+ if (parser[NKey::kLargePages].ThereIs)
+ {
+ const UString &postString = parser[NKey::kLargePages].PostStrings.Front();
+ if (postString.IsEmpty())
+ options.LargePages = true;
+ }
+ #endif
+}
+
+static bool ConvertStringToUInt32(const wchar_t *s, UInt32 &v)
+{
+ const wchar_t *end;
+ UInt64 number = ConvertStringToUInt64(s, &end);
+ if (*end != 0)
+ return false;
+ if (number > (UInt32)0xFFFFFFFF)
+ return false;
+ v = (UInt32)number;
+ return true;
+}
+
+void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)
+{
+ const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;
+ int numNonSwitchStrings = nonSwitchStrings.Size();
+ if (numNonSwitchStrings < kMinNonSwitchWords)
+ ThrowUserErrorException();
+
+ if (!ParseArchiveCommand(nonSwitchStrings[kCommandIndex], options.Command))
+ ThrowUserErrorException();
+
+ options.TechMode = parser[NKey::kTechMode].ThereIs;
+ options.CalcCrc = parser[NKey::kCalcCrc].ThereIs;
+
+ if (parser[NKey::kCaseSensitive].ThereIs)
+ g_CaseSensitive = (parser[NKey::kCaseSensitive].PostCharIndex < 0);
+
+ NRecursedType::EEnum recursedType;
+ if (parser[NKey::kRecursed].ThereIs)
+ recursedType = GetRecursedTypeFromIndex(parser[NKey::kRecursed].PostCharIndex);
+ else
+ recursedType = NRecursedType::kNonRecursed;
+
+ UINT codePage = CP_ACP;
+
+ bool thereAreSwitchIncludes = false;
+ if (parser[NKey::kInclude].ThereIs)
+ {
+ thereAreSwitchIncludes = true;
+ AddSwitchWildCardsToCensor(options.WildcardCensor,
+ parser[NKey::kInclude].PostStrings, true, recursedType, codePage);
+ }
+ if (parser[NKey::kExclude].ThereIs)
+ AddSwitchWildCardsToCensor(options.WildcardCensor,
+ parser[NKey::kExclude].PostStrings, false, recursedType, codePage);
+
+ int curCommandIndex = kCommandIndex + 1;
+ bool thereIsArchiveName = !parser[NKey::kNoArName].ThereIs &&
+ options.Command.CommandType != NCommandType::kBenchmark &&
+ options.Command.CommandType != NCommandType::kInfo;
+
+ bool isExtractGroupCommand = options.Command.IsFromExtractGroup();
+ bool isExtractOrList = isExtractGroupCommand || options.Command.CommandType == NCommandType::kList;
+
+ if (isExtractOrList && options.StdInMode)
+ thereIsArchiveName = false;
+
+ if (thereIsArchiveName)
+ {
+ if (curCommandIndex >= numNonSwitchStrings)
+ ThrowUserErrorException();
+ options.ArchiveName = nonSwitchStrings[curCommandIndex++];
+ if (options.ArchiveName.IsEmpty())
+ ThrowUserErrorException();
+ }
+
+ AddToCensorFromNonSwitchesStrings(
+ curCommandIndex, options.WildcardCensor,
+ nonSwitchStrings, recursedType, thereAreSwitchIncludes, codePage);
+
+ options.YesToAll = parser[NKey::kYes].ThereIs;
+
+#ifdef ENV_HAVE_LSTAT
+ global_use_lstat = !parser[NKey::kUseLStat].ThereIs;
+#endif
+
+ #ifndef _NO_CRYPTO
+ options.PasswordEnabled = parser[NKey::kPassword].ThereIs;
+ if (options.PasswordEnabled)
+ options.Password = parser[NKey::kPassword].PostStrings[0];
+ #endif
+
+ options.ShowDialog = parser[NKey::kShowDialog].ThereIs;
+
+ if (parser[NKey::kArchiveType].ThereIs)
+ options.ArcType = parser[NKey::kArchiveType].PostStrings[0];
+
+ if (isExtractOrList)
+ {
+ if (!options.WildcardCensor.AllAreRelative())
+ ThrowException("Cannot use absolute pathnames for this command");
+
+ NWildcard::CCensor archiveWildcardCensor;
+
+ if (parser[NKey::kArInclude].ThereIs)
+ AddSwitchWildCardsToCensor(archiveWildcardCensor,
+ parser[NKey::kArInclude].PostStrings, true, NRecursedType::kNonRecursed, codePage);
+ if (parser[NKey::kArExclude].ThereIs)
+ AddSwitchWildCardsToCensor(archiveWildcardCensor,
+ parser[NKey::kArExclude].PostStrings, false, NRecursedType::kNonRecursed, codePage);
+
+ bool directlyAddArchiveName = false;
+ if (thereIsArchiveName) {
+ if ((options.ArchiveName.Find(kUniversalWildcard) == -1) && (options.ArchiveName.Find(L"?") == -1)) {
+ // no wildcard => no need to scan
+ directlyAddArchiveName = true;
+ } else {
+ AddNameToCensor(archiveWildcardCensor, options.ArchiveName, true, NRecursedType::kNonRecursed);
+ }
+ }
+
+ #ifdef _WIN32
+ ConvertToLongNames(archiveWildcardCensor);
+ #endif
+
+ archiveWildcardCensor.ExtendExclude();
+
+ if (options.StdInMode)
+ {
+ UString arcName = parser[NKey::kStdIn].PostStrings.Front();
+ options.ArchivePathsSorted.Add(arcName);
+ options.ArchivePathsFullSorted.Add(arcName);
+ }
+ else
+ {
+
+ UStringVector archivePaths;
+
+ {
+ CDirItems dirItems;
+ {
+ UStringVector errorPaths;
+ CRecordVector<DWORD> errorCodes;
+ HRESULT res = EnumerateItems(archiveWildcardCensor, dirItems, NULL, errorPaths, errorCodes);
+ if (res != S_OK || errorPaths.Size() > 0)
+ throw "cannot find archive";
+ }
+ for (int i = 0; i < dirItems.Items.Size(); i++)
+ {
+ const CDirItem &dirItem = dirItems.Items[i];
+ if (!dirItem.IsDir())
+ archivePaths.Add(dirItems.GetPhyPath(i));
+ }
+ }
+
+ // Because the pathname of archive can be a symbolic link
+ // do not use "AddCommandLineWildCardToCensr(archiveWildcardCensor, options.ArchiveName"
+ if (directlyAddArchiveName)
+ archivePaths.Add(options.ArchiveName);
+
+ if (archivePaths.Size() == 0)
+ throw "there is no such archive";
+
+ UStringVector archivePathsFull;
+
+ int i;
+ for (i = 0; i < archivePaths.Size(); i++)
+ {
+ UString fullPath;
+ NFile::NDirectory::MyGetFullPathName(archivePaths[i], fullPath);
+ archivePathsFull.Add(fullPath);
+ }
+ CIntVector indices;
+ SortFileNames(archivePathsFull, indices);
+ options.ArchivePathsSorted.Reserve(indices.Size());
+ options.ArchivePathsFullSorted.Reserve(indices.Size());
+ for (i = 0; i < indices.Size(); i++)
+ {
+ options.ArchivePathsSorted.Add(archivePaths[indices[i]]);
+ options.ArchivePathsFullSorted.Add(archivePathsFull[indices[i]]);
+ }
+
+ }
+
+ if (isExtractGroupCommand)
+ {
+ SetMethodOptions(parser, options.ExtractProperties);
+ if (options.StdOutMode && options.IsStdOutTerminal && options.IsStdErrTerminal)
+ throw kSameTerminalError;
+ if (parser[NKey::kOutputDir].ThereIs)
+ {
+ options.OutputDir = parser[NKey::kOutputDir].PostStrings[0];
+ NFile::NName::NormalizeDirPathPrefix(options.OutputDir);
+ }
+
+ options.OverwriteMode = NExtract::NOverwriteMode::kAskBefore;
+ if (parser[NKey::kOverwrite].ThereIs)
+ options.OverwriteMode = k_OverwriteModes[parser[NKey::kOverwrite].PostCharIndex];
+ else if (options.YesToAll)
+ options.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;
+ }
+ }
+ else if (options.Command.IsFromUpdateGroup())
+ {
+ CUpdateOptions &updateOptions = options.UpdateOptions;
+
+ SetAddCommandOptions(options.Command.CommandType, parser, updateOptions);
+
+ SetMethodOptions(parser, updateOptions.MethodMode.Properties);
+
+ options.EnablePercents = !parser[NKey::kDisablePercents].ThereIs;
+
+ if (options.EnablePercents)
+ {
+ if ((options.StdOutMode && !options.IsStdErrTerminal) ||
+ (!options.StdOutMode && !options.IsStdOutTerminal))
+ options.EnablePercents = false;
+ }
+
+ updateOptions.EMailMode = parser[NKey::kEmail].ThereIs;
+ if (updateOptions.EMailMode)
+ {
+ updateOptions.EMailAddress = parser[NKey::kEmail].PostStrings.Front();
+ if (updateOptions.EMailAddress.Length() > 0)
+ if (updateOptions.EMailAddress[0] == L'.')
+ {
+ updateOptions.EMailRemoveAfter = true;
+ updateOptions.EMailAddress.Delete(0);
+ }
+ }
+
+ updateOptions.StdOutMode = options.StdOutMode;
+ updateOptions.StdInMode = options.StdInMode;
+
+ if (updateOptions.StdOutMode && updateOptions.EMailMode)
+ throw "stdout mode and email mode cannot be combined";
+ if (updateOptions.StdOutMode && options.IsStdOutTerminal)
+ throw kTerminalOutError;
+ if (updateOptions.StdInMode)
+ updateOptions.StdInFileName = parser[NKey::kStdIn].PostStrings.Front();
+
+ #ifdef _WIN32
+ ConvertToLongNames(options.WildcardCensor);
+ #endif
+ }
+ else if (options.Command.CommandType == NCommandType::kBenchmark)
+ {
+ options.NumThreads = (UInt32)-1;
+ options.DictionarySize = (UInt32)-1;
+ options.NumIterations = 1;
+ if (curCommandIndex < numNonSwitchStrings)
+ {
+ if (!ConvertStringToUInt32(nonSwitchStrings[curCommandIndex++], options.NumIterations))
+ ThrowUserErrorException();
+ }
+ for (int i = 0; i < parser[NKey::kProperty].PostStrings.Size(); i++)
+ {
+ UString postString = parser[NKey::kProperty].PostStrings[i];
+ postString.MakeUpper();
+ if (postString.Length() < 2)
+ ThrowUserErrorException();
+ if (postString[0] == 'D')
+ {
+ int pos = 1;
+ if (postString[pos] == '=')
+ pos++;
+ UInt32 logSize;
+ if (!ConvertStringToUInt32((const wchar_t *)postString + pos, logSize))
+ ThrowUserErrorException();
+ if (logSize > 31)
+ ThrowUserErrorException();
+ options.DictionarySize = 1 << logSize;
+ }
+ else if (postString[0] == 'M' && postString[1] == 'T' )
+ {
+ int pos = 2;
+ if (postString[pos] == '=')
+ pos++;
+ if (postString[pos] != 0)
+ if (!ConvertStringToUInt32((const wchar_t *)postString + pos, options.NumThreads))
+ ThrowUserErrorException();
+ }
+ else if (postString[0] == 'M' && postString[1] == '=' )
+ {
+ int pos = 2;
+ if (postString[pos] != 0)
+ options.Method = postString.Mid(2);
+ }
+ else
+ ThrowUserErrorException();
+ }
+ }
+ else if (options.Command.CommandType == NCommandType::kInfo)
+ {
+ }
+ else
+ ThrowUserErrorException();
+ options.WildcardCensor.ExtendExclude();
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveCommandLine.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveCommandLine.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveCommandLine.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveCommandLine.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,111 @@
+// ArchiveCommandLine.h
+
+#ifndef __ARCHIVE_COMMAND_LINE_H
+#define __ARCHIVE_COMMAND_LINE_H
+
+#include "Common/CommandLineParser.h"
+#include "Common/Wildcard.h"
+
+#include "Extract.h"
+#include "Update.h"
+
+struct CArchiveCommandLineException: public AString
+{
+ CArchiveCommandLineException(const char *errorMessage): AString(errorMessage) {}
+};
+
+namespace NCommandType { enum EEnum
+{
+ kAdd = 0,
+ kUpdate,
+ kDelete,
+ kTest,
+ kExtract,
+ kFullExtract,
+ kList,
+ kBenchmark,
+ kInfo
+};}
+
+namespace NRecursedType { enum EEnum
+{
+ kRecursed,
+ kWildCardOnlyRecursed,
+ kNonRecursed
+};}
+
+struct CArchiveCommand
+{
+ NCommandType::EEnum CommandType;
+ bool IsFromExtractGroup() const;
+ bool IsFromUpdateGroup() const;
+ bool IsTestMode() const { return CommandType == NCommandType::kTest; }
+ NExtract::NPathMode::EEnum GetPathMode() const;
+};
+
+struct CArchiveCommandLineOptions
+{
+ bool HelpMode;
+
+ #ifdef _7ZIP_LARGE_PAGES
+ bool LargePages;
+ #endif
+
+ bool IsInTerminal;
+ bool IsStdOutTerminal;
+ bool IsStdErrTerminal;
+ bool StdInMode;
+ bool StdOutMode;
+ bool EnableHeaders;
+
+ bool YesToAll;
+ bool ShowDialog;
+ // NWildcard::CCensor ArchiveWildcardCensor;
+ NWildcard::CCensor WildcardCensor;
+
+ CArchiveCommand Command;
+ UString ArchiveName;
+
+ #ifndef _NO_CRYPTO
+ bool PasswordEnabled;
+ UString Password;
+ #endif
+
+ bool TechMode;
+ // Extract
+ bool CalcCrc;
+ bool AppendName;
+ UString OutputDir;
+ NExtract::NOverwriteMode::EEnum OverwriteMode;
+ UStringVector ArchivePathsSorted;
+ UStringVector ArchivePathsFullSorted;
+ CObjectVector<CProperty> ExtractProperties;
+
+ CUpdateOptions UpdateOptions;
+ UString ArcType;
+ bool EnablePercents;
+
+ // Benchmark
+ UInt32 NumIterations;
+ UInt32 NumThreads;
+ UInt32 DictionarySize;
+ UString Method;
+
+
+ CArchiveCommandLineOptions(): StdInMode(false), StdOutMode(false) {};
+};
+
+class CArchiveCommandLineParser
+{
+ NCommandLineParser::CParser parser;
+public:
+ CArchiveCommandLineParser();
+ void Parse1(const UStringVector &commandStrings, CArchiveCommandLineOptions &options);
+ void Parse2(CArchiveCommandLineOptions &options);
+};
+
+void EnumerateDirItemsAndSort(NWildcard::CCensor &wildcardCensor,
+ UStringVector &sortedPaths,
+ UStringVector &sortedFullPaths);
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveExtractCallback.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,488 @@
+// ArchiveExtractCallback.cpp
+
+#include "StdAfx.h"
+
+#include "Common/ComTry.h"
+#include "Common/Wildcard.h"
+
+#include "Windows/FileDir.h"
+#include "Windows/FileFind.h"
+#include "Windows/PropVariant.h"
+#include "Windows/PropVariantConversions.h"
+
+#include "../../Common/FilePathAutoRename.h"
+
+#include "../Common/ExtractingFilePath.h"
+
+#include "ArchiveExtractCallback.h"
+
+using namespace NWindows;
+
+static const wchar_t *kCantAutoRename = L"ERROR: Can not create file with auto name";
+static const wchar_t *kCantRenameFile = L"ERROR: Can not rename existing file ";
+static const wchar_t *kCantDeleteOutputFile = L"ERROR: Can not delete output file ";
+
+void CArchiveExtractCallback::Init(
+ const NWildcard::CCensorNode *wildcardCensor,
+ const CArc *arc,
+ IFolderArchiveExtractCallback *extractCallback2,
+ bool stdOutMode, bool testMode, bool crcMode,
+ const UString &directoryPath,
+ const UStringVector &removePathParts,
+ UInt64 packSize)
+{
+ _wildcardCensor = wildcardCensor;
+
+ _stdOutMode = stdOutMode;
+ _testMode = testMode;
+ _crcMode = crcMode;
+ _unpTotal = 1;
+ _packTotal = packSize;
+
+ _extractCallback2 = extractCallback2;
+ _compressProgress.Release();
+ _extractCallback2.QueryInterface(IID_ICompressProgressInfo, &_compressProgress);
+
+ LocalProgressSpec->Init(extractCallback2, true);
+ LocalProgressSpec->SendProgress = false;
+
+
+ _removePathParts = removePathParts;
+ _arc = arc;
+ _directoryPath = directoryPath;
+ NFile::NName::NormalizeDirPathPrefix(_directoryPath);
+}
+
+STDMETHODIMP CArchiveExtractCallback::SetTotal(UInt64 size)
+{
+ COM_TRY_BEGIN
+ _unpTotal = size;
+ if (!_multiArchives && _extractCallback2)
+ return _extractCallback2->SetTotal(size);
+ return S_OK;
+ COM_TRY_END
+}
+
+static void NormalizeVals(UInt64 &v1, UInt64 &v2)
+{
+ const UInt64 kMax = (UInt64)1 << 31;
+ while (v1 > kMax)
+ {
+ v1 >>= 1;
+ v2 >>= 1;
+ }
+}
+
+static UInt64 MyMultDiv64(UInt64 unpCur, UInt64 unpTotal, UInt64 packTotal)
+{
+ NormalizeVals(packTotal, unpTotal);
+ NormalizeVals(unpCur, unpTotal);
+ if (unpTotal == 0)
+ unpTotal = 1;
+ return unpCur * packTotal / unpTotal;
+}
+
+STDMETHODIMP CArchiveExtractCallback::SetCompleted(const UInt64 *completeValue)
+{
+ COM_TRY_BEGIN
+ if (!_extractCallback2)
+ return S_OK;
+
+ if (_multiArchives)
+ {
+ if (completeValue != NULL)
+ {
+ UInt64 packCur = LocalProgressSpec->InSize + MyMultDiv64(*completeValue, _unpTotal, _packTotal);
+ return _extractCallback2->SetCompleted(&packCur);
+ }
+ }
+ return _extractCallback2->SetCompleted(completeValue);
+ COM_TRY_END
+}
+
+STDMETHODIMP CArchiveExtractCallback::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
+{
+ COM_TRY_BEGIN
+ return _localProgress->SetRatioInfo(inSize, outSize);
+ COM_TRY_END
+}
+
+void CArchiveExtractCallback::CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath)
+{
+ fullPath = _directoryPath;
+ for (int i = 0; i < dirPathParts.Size(); i++)
+ {
+ if (i > 0)
+ fullPath += wchar_t(NFile::NName::kDirDelimiter);
+ fullPath += dirPathParts[i];
+ NFile::NDirectory::MyCreateDirectory(fullPath);
+ }
+}
+
+HRESULT CArchiveExtractCallback::GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined)
+{
+ filetimeIsDefined = false;
+ NCOM::CPropVariant prop;
+ RINOK(_arc->Archive->GetProperty(index, propID, &prop));
+ if (prop.vt == VT_FILETIME)
+ {
+ filetime = prop.filetime;
+ filetimeIsDefined = (filetime.dwHighDateTime != 0 || filetime.dwLowDateTime != 0);
+ }
+ else if (prop.vt != VT_EMPTY)
+ return E_FAIL;
+ return S_OK;
+}
+
+HRESULT CArchiveExtractCallback::GetUnpackSize()
+{
+ NCOM::CPropVariant prop;
+ RINOK(_arc->Archive->GetProperty(_index, kpidSize, &prop));
+ _curSizeDefined = (prop.vt != VT_EMPTY);
+ if (_curSizeDefined)
+ _curSize = ConvertPropVariantToUInt64(prop);
+ return S_OK;
+}
+
+STDMETHODIMP CArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode)
+{
+ COM_TRY_BEGIN
+ _crcStream.Release();
+ *outStream = 0;
+ _outFileStream.Release();
+
+ _encrypted = false;
+ _isSplit = false;
+ _curSize = 0;
+ _curSizeDefined = false;
+ _index = index;
+
+ UString fullPath;
+
+ IInArchive *archive = _arc->Archive;
+ RINOK(_arc->GetItemPath(index, fullPath));
+ RINOK(IsArchiveItemFolder(archive, index, _fi.IsDir));
+
+ _filePath = fullPath;
+
+ {
+ NCOM::CPropVariant prop;
+ RINOK(archive->GetProperty(index, kpidPosition, &prop));
+ if (prop.vt != VT_EMPTY)
+ {
+ if (prop.vt != VT_UI8)
+ return E_FAIL;
+ _position = prop.uhVal.QuadPart;
+ _isSplit = true;
+ }
+ }
+
+ RINOK(GetArchiveItemBoolProp(archive, index, kpidEncrypted, _encrypted));
+
+ RINOK(GetUnpackSize());
+
+ if (_wildcardCensor)
+ {
+ if (!_wildcardCensor->CheckPath(fullPath, !_fi.IsDir))
+ return S_OK;
+ }
+
+ if (askExtractMode == NArchive::NExtract::NAskMode::kExtract && !_testMode)
+ {
+ if (_stdOutMode)
+ {
+ CMyComPtr<ISequentialOutStream> outStreamLoc = new CStdOutFileStream;
+ *outStream = outStreamLoc.Detach();
+ return S_OK;
+ }
+
+ {
+ NCOM::CPropVariant prop;
+ RINOK(archive->GetProperty(index, kpidAttrib, &prop));
+ if (prop.vt == VT_UI4)
+ {
+ _fi.Attrib = prop.ulVal;
+ _fi.AttribDefined = true;
+ }
+ else if (prop.vt == VT_EMPTY)
+ _fi.AttribDefined = false;
+ else
+ return E_FAIL;
+ }
+
+ RINOK(GetTime(index, kpidCTime, _fi.CTime, _fi.CTimeDefined));
+ RINOK(GetTime(index, kpidATime, _fi.ATime, _fi.ATimeDefined));
+ RINOK(GetTime(index, kpidMTime, _fi.MTime, _fi.MTimeDefined));
+
+ bool isAnti = false;
+ RINOK(_arc->IsItemAnti(index, isAnti));
+
+ UStringVector pathParts;
+ SplitPathToParts(fullPath, pathParts);
+
+ if (pathParts.IsEmpty())
+ return E_FAIL;
+ int numRemovePathParts = 0;
+ switch(_pathMode)
+ {
+ case NExtract::NPathMode::kFullPathnames:
+ break;
+ case NExtract::NPathMode::kCurrentPathnames:
+ {
+ numRemovePathParts = _removePathParts.Size();
+ if (pathParts.Size() <= numRemovePathParts)
+ return E_FAIL;
+ for (int i = 0; i < numRemovePathParts; i++)
+ if (_removePathParts[i].CompareNoCase(pathParts[i]) != 0)
+ return E_FAIL;
+ break;
+ }
+ case NExtract::NPathMode::kNoPathnames:
+ {
+ numRemovePathParts = pathParts.Size() - 1;
+ break;
+ }
+ }
+ pathParts.Delete(0, numRemovePathParts);
+ MakeCorrectPath(pathParts);
+ UString processedPath = MakePathNameFromParts(pathParts);
+ if (!isAnti)
+ {
+ if (!_fi.IsDir)
+ {
+ if (!pathParts.IsEmpty())
+ pathParts.DeleteBack();
+ }
+
+ if (!pathParts.IsEmpty())
+ {
+ UString fullPathNew;
+ CreateComplexDirectory(pathParts, fullPathNew);
+ if (_fi.IsDir)
+ NFile::NDirectory::SetDirTime(fullPathNew,
+ (WriteCTime && _fi.CTimeDefined) ? &_fi.CTime : NULL,
+ (WriteATime && _fi.ATimeDefined) ? &_fi.ATime : NULL,
+ (WriteMTime && _fi.MTimeDefined) ? &_fi.MTime : (_arc->MTimeDefined ? &_arc->MTime : NULL));
+ }
+ }
+
+
+ UString fullProcessedPath = _directoryPath + processedPath;
+
+ if (_fi.IsDir)
+ {
+ _diskFilePath = fullProcessedPath;
+ if (isAnti)
+ NFile::NDirectory::MyRemoveDirectory(_diskFilePath);
+ return S_OK;
+ }
+
+ if (!_isSplit)
+ {
+ NFile::NFind::CFileInfoW fileInfo;
+ if (fileInfo.Find(fullProcessedPath))
+ {
+ switch(_overwriteMode)
+ {
+ case NExtract::NOverwriteMode::kSkipExisting:
+ return S_OK;
+ case NExtract::NOverwriteMode::kAskBefore:
+ {
+ Int32 overwiteResult;
+ RINOK(_extractCallback2->AskOverwrite(
+ fullProcessedPath, &fileInfo.MTime, &fileInfo.Size, fullPath,
+ _fi.MTimeDefined ? &_fi.MTime : NULL,
+ _curSizeDefined ? &_curSize : NULL,
+ &overwiteResult))
+
+ switch(overwiteResult)
+ {
+ case NOverwriteAnswer::kCancel:
+ return E_ABORT;
+ case NOverwriteAnswer::kNo:
+ return S_OK;
+ case NOverwriteAnswer::kNoToAll:
+ _overwriteMode = NExtract::NOverwriteMode::kSkipExisting;
+ return S_OK;
+ case NOverwriteAnswer::kYesToAll:
+ _overwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;
+ break;
+ case NOverwriteAnswer::kYes:
+ break;
+ case NOverwriteAnswer::kAutoRename:
+ _overwriteMode = NExtract::NOverwriteMode::kAutoRename;
+ break;
+ default:
+ return E_FAIL;
+ }
+ }
+ }
+ if (_overwriteMode == NExtract::NOverwriteMode::kAutoRename)
+ {
+ if (!AutoRenamePath(fullProcessedPath))
+ {
+ UString message = UString(kCantAutoRename) + fullProcessedPath;
+ RINOK(_extractCallback2->MessageError(message));
+ return E_FAIL;
+ }
+ }
+ else if (_overwriteMode == NExtract::NOverwriteMode::kAutoRenameExisting)
+ {
+ UString existPath = fullProcessedPath;
+ if (!AutoRenamePath(existPath))
+ {
+ UString message = kCantAutoRename + fullProcessedPath;
+ RINOK(_extractCallback2->MessageError(message));
+ return E_FAIL;
+ }
+ if (!NFile::NDirectory::MyMoveFile(fullProcessedPath, existPath))
+ {
+ UString message = UString(kCantRenameFile) + fullProcessedPath;
+ RINOK(_extractCallback2->MessageError(message));
+ return E_FAIL;
+ }
+ }
+ else
+ if (!NFile::NDirectory::DeleteFileAlways(fullProcessedPath))
+ {
+ UString message = UString(kCantDeleteOutputFile) + fullProcessedPath;
+ RINOK(_extractCallback2->MessageError(message));
+ return S_OK;
+ // return E_FAIL;
+ }
+ }
+ }
+ if (!isAnti)
+ {
+ _outFileStreamSpec = new COutFileStream;
+ CMyComPtr<ISequentialOutStream> outStreamLoc(_outFileStreamSpec);
+ if (!_outFileStreamSpec->Open(fullProcessedPath, _isSplit ? OPEN_ALWAYS: CREATE_ALWAYS))
+ {
+ // if (::GetLastError() != ERROR_FILE_EXISTS || !isSplit)
+ {
+ UString message = L"can not open output file " + fullProcessedPath;
+ RINOK(_extractCallback2->MessageError(message));
+ return S_OK;
+ }
+ }
+ if (_isSplit)
+ {
+ RINOK(_outFileStreamSpec->Seek(_position, STREAM_SEEK_SET, NULL));
+ }
+ _outFileStream = outStreamLoc;
+ *outStream = outStreamLoc.Detach();
+ }
+ _diskFilePath = fullProcessedPath;
+ }
+ else
+ {
+ *outStream = NULL;
+ }
+ if (_crcMode)
+ {
+ _crcStreamSpec = new COutStreamWithCRC;
+ _crcStream = _crcStreamSpec;
+ CMyComPtr<ISequentialOutStream> crcStream = _crcStreamSpec;
+ _crcStreamSpec->SetStream(*outStream);
+ if (*outStream)
+ (*outStream)->Release();
+ *outStream = crcStream.Detach();
+ _crcStreamSpec->Init(true);
+ }
+ return S_OK;
+ COM_TRY_END
+}
+
+STDMETHODIMP CArchiveExtractCallback::PrepareOperation(Int32 askExtractMode)
+{
+ COM_TRY_BEGIN
+ _extractMode = false;
+ switch (askExtractMode)
+ {
+ case NArchive::NExtract::NAskMode::kExtract:
+ if (_testMode)
+ askExtractMode = NArchive::NExtract::NAskMode::kTest;
+ else
+ _extractMode = true;
+ break;
+ };
+ return _extractCallback2->PrepareOperation(_filePath, _fi.IsDir,
+ askExtractMode, _isSplit ? &_position: 0);
+ COM_TRY_END
+}
+
+STDMETHODIMP CArchiveExtractCallback::SetOperationResult(Int32 operationResult)
+{
+ COM_TRY_BEGIN
+ switch(operationResult)
+ {
+ case NArchive::NExtract::NOperationResult::kOK:
+ case NArchive::NExtract::NOperationResult::kUnSupportedMethod:
+ case NArchive::NExtract::NOperationResult::kCRCError:
+ case NArchive::NExtract::NOperationResult::kDataError:
+ break;
+ default:
+ _outFileStream.Release();
+ return E_FAIL;
+ }
+ if (_crcStream)
+ {
+ CrcSum += _crcStreamSpec->GetCRC();
+ _curSize = _crcStreamSpec->GetSize();
+ _curSizeDefined = true;
+ _crcStream.Release();
+ }
+ if (_outFileStream)
+ {
+ _outFileStreamSpec->SetTime(
+ (WriteCTime && _fi.CTimeDefined) ? &_fi.CTime : NULL,
+ (WriteATime && _fi.ATimeDefined) ? &_fi.ATime : NULL,
+ (WriteMTime && _fi.MTimeDefined) ? &_fi.MTime : (_arc->MTimeDefined ? &_arc->MTime : NULL));
+ _curSize = _outFileStreamSpec->ProcessedSize;
+ _curSizeDefined = true;
+ RINOK(_outFileStreamSpec->Close());
+ _outFileStream.Release();
+ }
+ if (!_curSizeDefined)
+ GetUnpackSize();
+ if (_curSizeDefined)
+ UnpackSize += _curSize;
+ if (_fi.IsDir)
+ NumFolders++;
+ else
+ NumFiles++;
+
+ if (_extractMode && _fi.AttribDefined)
+ NFile::NDirectory::MySetFileAttributes(_diskFilePath, _fi.Attrib);
+ RINOK(_extractCallback2->SetOperationResult(operationResult, _encrypted));
+ return S_OK;
+ COM_TRY_END
+}
+
+/*
+STDMETHODIMP CArchiveExtractCallback::GetInStream(
+ const wchar_t *name, ISequentialInStream **inStream)
+{
+ COM_TRY_BEGIN
+ CInFileStream *inFile = new CInFileStream;
+ CMyComPtr<ISequentialInStream> inStreamTemp = inFile;
+ if (!inFile->Open(_srcDirectoryPrefix + name))
+ return ::GetLastError();
+ *inStream = inStreamTemp.Detach();
+ return S_OK;
+ COM_TRY_END
+}
+*/
+
+STDMETHODIMP CArchiveExtractCallback::CryptoGetTextPassword(BSTR *password)
+{
+ COM_TRY_BEGIN
+ if (!_cryptoGetTextPassword)
+ {
+ RINOK(_extractCallback2.QueryInterface(IID_ICryptoGetTextPassword,
+ &_cryptoGetTextPassword));
+ }
+ return _cryptoGetTextPassword->CryptoGetTextPassword(password);
+ COM_TRY_END
+}
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveExtractCallback.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveExtractCallback.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveExtractCallback.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveExtractCallback.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,143 @@
+// ArchiveExtractCallback.h
+
+#ifndef __ARCHIVE_EXTRACT_CALLBACK_H
+#define __ARCHIVE_EXTRACT_CALLBACK_H
+
+#include "Common/MyCom.h"
+#include "Common/Wildcard.h"
+
+#include "../../IPassword.h"
+
+#include "../../Common/FileStreams.h"
+#include "../../Common/ProgressUtils.h"
+
+#include "../../Archive/IArchive.h"
+
+#include "../../Archive/Common/OutStreamWithCRC.h"
+
+#include "ExtractMode.h"
+#include "IFileExtractCallback.h"
+#include "OpenArchive.h"
+
+class CArchiveExtractCallback:
+ public IArchiveExtractCallback,
+ // public IArchiveVolumeExtractCallback,
+ public ICryptoGetTextPassword,
+ public ICompressProgressInfo,
+ public CMyUnknownImp
+{
+ const CArc *_arc;
+ const NWildcard::CCensorNode *_wildcardCensor;
+ CMyComPtr<IFolderArchiveExtractCallback> _extractCallback2;
+ CMyComPtr<ICompressProgressInfo> _compressProgress;
+ CMyComPtr<ICryptoGetTextPassword> _cryptoGetTextPassword;
+ UString _directoryPath;
+ NExtract::NPathMode::EEnum _pathMode;
+ NExtract::NOverwriteMode::EEnum _overwriteMode;
+
+ UString _diskFilePath;
+ UString _filePath;
+ UInt64 _position;
+ bool _isSplit;
+
+ bool _extractMode;
+
+ bool WriteCTime;
+ bool WriteATime;
+ bool WriteMTime;
+
+ bool _encrypted;
+
+ struct CProcessedFileInfo
+ {
+ FILETIME CTime;
+ FILETIME ATime;
+ FILETIME MTime;
+ UInt32 Attrib;
+
+ bool CTimeDefined;
+ bool ATimeDefined;
+ bool MTimeDefined;
+ bool AttribDefined;
+
+ bool IsDir;
+ } _fi;
+
+ UInt32 _index;
+ UInt64 _curSize;
+ bool _curSizeDefined;
+ COutFileStream *_outFileStreamSpec;
+ CMyComPtr<ISequentialOutStream> _outFileStream;
+
+ COutStreamWithCRC *_crcStreamSpec;
+ CMyComPtr<ISequentialOutStream> _crcStream;
+
+ UStringVector _removePathParts;
+
+ bool _stdOutMode;
+ bool _testMode;
+ bool _crcMode;
+ bool _multiArchives;
+
+ CMyComPtr<ICompressProgressInfo> _localProgress;
+ UInt64 _packTotal;
+ UInt64 _unpTotal;
+
+ void CreateComplexDirectory(const UStringVector &dirPathParts, UString &fullPath);
+ HRESULT GetTime(int index, PROPID propID, FILETIME &filetime, bool &filetimeIsDefined);
+ HRESULT GetUnpackSize();
+
+public:
+
+ CLocalProgress *LocalProgressSpec;
+
+ UInt64 NumFolders;
+ UInt64 NumFiles;
+ UInt64 UnpackSize;
+ UInt32 CrcSum;
+
+ MY_UNKNOWN_IMP2(ICryptoGetTextPassword, ICompressProgressInfo)
+ // COM_INTERFACE_ENTRY(IArchiveVolumeExtractCallback)
+
+ INTERFACE_IArchiveExtractCallback(;)
+
+ STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
+
+ // IArchiveVolumeExtractCallback
+ // STDMETHOD(GetInStream)(const wchar_t *name, ISequentialInStream **inStream);
+
+ STDMETHOD(CryptoGetTextPassword)(BSTR *password);
+
+ CArchiveExtractCallback():
+ WriteCTime(true),
+ WriteATime(true),
+ WriteMTime(true),
+ _multiArchives(false)
+ {
+ LocalProgressSpec = new CLocalProgress();
+ _localProgress = LocalProgressSpec;
+ }
+
+ void InitForMulti(bool multiArchives,
+ NExtract::NPathMode::EEnum pathMode,
+ NExtract::NOverwriteMode::EEnum overwriteMode)
+ {
+ _multiArchives = multiArchives;
+ _pathMode = pathMode;
+ _overwriteMode = overwriteMode;
+ NumFolders = NumFiles = UnpackSize = 0;
+ CrcSum = 0;
+ }
+
+ void Init(
+ const NWildcard::CCensorNode *wildcardCensor,
+ const CArc *arc,
+ IFolderArchiveExtractCallback *extractCallback2,
+ bool stdOutMode, bool testMode, bool crcMode,
+ const UString &directoryPath,
+ const UStringVector &removePathParts,
+ UInt64 packSize);
+
+};
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveName.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveName.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveName.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveName.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,54 @@
+// ArchiveName.cpp
+
+#include "StdAfx.h"
+
+#include "Windows/FileDir.h"
+#include "Windows/FileFind.h"
+
+#include "ExtractingFilePath.h"
+
+using namespace NWindows;
+
+static UString CreateArchiveName2(const UString &srcName, bool fromPrev, bool keepName)
+{
+ UString resultName = L"Archive";
+ if (fromPrev)
+ {
+ UString dirPrefix;
+ if (NFile::NDirectory::GetOnlyDirPrefix(srcName, dirPrefix))
+ {
+ if (dirPrefix.Length() > 0)
+ if (dirPrefix[dirPrefix.Length() - 1] == WCHAR_PATH_SEPARATOR)
+ {
+ dirPrefix.Delete(dirPrefix.Length() - 1);
+ NFile::NFind::CFileInfoW fileInfo;
+ if (fileInfo.Find(dirPrefix))
+ resultName = fileInfo.Name;
+ }
+ }
+ }
+ else
+ {
+ NFile::NFind::CFileInfoW fileInfo;
+ if (!fileInfo.Find(srcName))
+ // return resultName;
+ return srcName;
+ resultName = fileInfo.Name;
+ if (!fileInfo.IsDir() && !keepName)
+ {
+ int dotPos = resultName.ReverseFind('.');
+ if (dotPos > 0)
+ {
+ UString archiveName2 = resultName.Left(dotPos);
+ if (archiveName2.ReverseFind('.') < 0)
+ resultName = archiveName2;
+ }
+ }
+ }
+ return resultName;
+}
+
+UString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName)
+{
+ return GetCorrectFsPath(CreateArchiveName2(srcName, fromPrev, keepName));
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveName.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveName.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveName.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveName.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,10 @@
+// ArchiveName.h
+
+#ifndef __ARCHIVENAME_H
+#define __ARCHIVENAME_H
+
+#include "Common/MyString.h"
+
+UString CreateArchiveName(const UString &srcName, bool fromPrev, bool keepName);
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveOpenCallback.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,133 @@
+// ArchiveOpenCallback.cpp
+
+#include "StdAfx.h"
+
+#include "Common/StringConvert.h"
+#include "Common/ComTry.h"
+
+#include "Windows/PropVariant.h"
+
+#include "../../Common/FileStreams.h"
+
+#include "ArchiveOpenCallback.h"
+
+using namespace NWindows;
+
+STDMETHODIMP COpenCallbackImp::SetTotal(const UInt64 *files, const UInt64 *bytes)
+{
+ COM_TRY_BEGIN
+ if (ReOpenCallback)
+ return ReOpenCallback->SetTotal(files, bytes);
+ if (!Callback)
+ return S_OK;
+ return Callback->Open_SetTotal(files, bytes);
+ COM_TRY_END
+}
+
+STDMETHODIMP COpenCallbackImp::SetCompleted(const UInt64 *files, const UInt64 *bytes)
+{
+ COM_TRY_BEGIN
+ if (ReOpenCallback)
+ return ReOpenCallback->SetCompleted(files, bytes);
+ if (!Callback)
+ return S_OK;
+ return Callback->Open_SetCompleted(files, bytes);
+ COM_TRY_END
+}
+
+STDMETHODIMP COpenCallbackImp::GetProperty(PROPID propID, PROPVARIANT *value)
+{
+ COM_TRY_BEGIN
+ NCOM::CPropVariant prop;
+ if (_subArchiveMode)
+ switch(propID)
+ {
+ case kpidName: prop = _subArchiveName; break;
+ }
+ else
+ switch(propID)
+ {
+ case kpidName: prop = _fileInfo.Name; break;
+ case kpidIsDir: prop = _fileInfo.IsDir(); break;
+ case kpidSize: prop = _fileInfo.Size; break;
+ case kpidAttrib: prop = (UInt32)_fileInfo.Attrib; break;
+ case kpidCTime: prop = _fileInfo.CTime; break;
+ case kpidATime: prop = _fileInfo.ATime; break;
+ case kpidMTime: prop = _fileInfo.MTime; break;
+ }
+ prop.Detach(value);
+ return S_OK;
+ COM_TRY_END
+}
+
+int COpenCallbackImp::FindName(const UString &name)
+{
+ for (int i = 0; i < FileNames.Size(); i++)
+ if (name.CompareNoCase(FileNames[i]) == 0)
+ return i;
+ return -1;
+}
+
+struct CInFileStreamVol: public CInFileStream
+{
+ UString Name;
+ COpenCallbackImp *OpenCallbackImp;
+ CMyComPtr<IArchiveOpenCallback> OpenCallbackRef;
+ ~CInFileStreamVol()
+ {
+ if (OpenCallbackRef)
+ {
+ int index = OpenCallbackImp->FindName(Name);
+ if (index >= 0)
+ OpenCallbackImp->FileNames.Delete(index);
+ }
+ }
+};
+
+STDMETHODIMP COpenCallbackImp::GetStream(const wchar_t *name, IInStream **inStream)
+{
+ COM_TRY_BEGIN
+ if (_subArchiveMode)
+ return S_FALSE;
+ if (Callback)
+ {
+ RINOK(Callback->Open_CheckBreak());
+ }
+ *inStream = NULL;
+ UString fullPath = _folderPrefix + name;
+ if (!_fileInfo.Find(fullPath))
+ return S_FALSE;
+ if (_fileInfo.IsDir())
+ return S_FALSE;
+ CInFileStreamVol *inFile = new CInFileStreamVol;
+ CMyComPtr<IInStream> inStreamTemp = inFile;
+ if (!inFile->Open(fullPath))
+ return ::GetLastError();
+ *inStream = inStreamTemp.Detach();
+ inFile->Name = name;
+ inFile->OpenCallbackImp = this;
+ inFile->OpenCallbackRef = this;
+ FileNames.Add(name);
+ TotalSize += _fileInfo.Size;
+ return S_OK;
+ COM_TRY_END
+}
+
+#ifndef _NO_CRYPTO
+STDMETHODIMP COpenCallbackImp::CryptoGetTextPassword(BSTR *password)
+{
+ COM_TRY_BEGIN
+ if (ReOpenCallback)
+ {
+ CMyComPtr<ICryptoGetTextPassword> getTextPassword;
+ ReOpenCallback.QueryInterface(IID_ICryptoGetTextPassword, &getTextPassword);
+ if (getTextPassword)
+ return getTextPassword->CryptoGetTextPassword(password);
+ }
+ if (!Callback)
+ return E_NOTIMPL;
+ return Callback->Open_CryptoGetTextPassword(password);
+ COM_TRY_END
+}
+#endif
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveOpenCallback.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveOpenCallback.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveOpenCallback.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ArchiveOpenCallback.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,103 @@
+// ArchiveOpenCallback.h
+
+#ifndef __ARCHIVE_OPEN_CALLBACK_H
+#define __ARCHIVE_OPEN_CALLBACK_H
+
+#include "Common/MyCom.h"
+#include "Common/MyString.h"
+
+#include "Windows/FileFind.h"
+
+#ifndef _NO_CRYPTO
+#include "../../IPassword.h"
+#endif
+#include "../../Archive/IArchive.h"
+
+#ifdef _NO_CRYPTO
+
+#define INTERFACE_IOpenCallbackUI_Crypto(x)
+
+#else
+
+#define INTERFACE_IOpenCallbackUI_Crypto(x) \
+ virtual HRESULT Open_CryptoGetTextPassword(BSTR *password) x; \
+ virtual HRESULT Open_GetPasswordIfAny(UString &password) x; \
+ virtual bool Open_WasPasswordAsked() x; \
+ virtual void Open_ClearPasswordWasAskedFlag() x; \
+
+#endif
+
+#define INTERFACE_IOpenCallbackUI(x) \
+ virtual HRESULT Open_CheckBreak() x; \
+ virtual HRESULT Open_SetTotal(const UInt64 *files, const UInt64 *bytes) x; \
+ virtual HRESULT Open_SetCompleted(const UInt64 *files, const UInt64 *bytes) x; \
+ INTERFACE_IOpenCallbackUI_Crypto(x)
+
+struct IOpenCallbackUI
+{
+ INTERFACE_IOpenCallbackUI(=0)
+};
+
+class COpenCallbackImp:
+ public IArchiveOpenCallback,
+ public IArchiveOpenVolumeCallback,
+ public IArchiveOpenSetSubArchiveName,
+ #ifndef _NO_CRYPTO
+ public ICryptoGetTextPassword,
+ #endif
+ public CMyUnknownImp
+{
+public:
+ #ifndef _NO_CRYPTO
+ MY_UNKNOWN_IMP3(
+ IArchiveOpenVolumeCallback,
+ ICryptoGetTextPassword,
+ IArchiveOpenSetSubArchiveName
+ )
+ #else
+ MY_UNKNOWN_IMP2(
+ IArchiveOpenVolumeCallback,
+ IArchiveOpenSetSubArchiveName
+ )
+ #endif
+
+ INTERFACE_IArchiveOpenCallback(;)
+ INTERFACE_IArchiveOpenVolumeCallback(;)
+
+ #ifndef _NO_CRYPTO
+ STDMETHOD(CryptoGetTextPassword)(BSTR *password);
+ #endif
+
+ STDMETHOD(SetSubArchiveName(const wchar_t *name))
+ {
+ _subArchiveMode = true;
+ _subArchiveName = name;
+ TotalSize = 0;
+ return S_OK;
+ }
+
+private:
+ UString _folderPrefix;
+ NWindows::NFile::NFind::CFileInfoW _fileInfo;
+ bool _subArchiveMode;
+ UString _subArchiveName;
+public:
+ UStringVector FileNames;
+ IOpenCallbackUI *Callback;
+ CMyComPtr<IArchiveOpenCallback> ReOpenCallback;
+ UInt64 TotalSize;
+
+ COpenCallbackImp(): Callback(NULL) {}
+ void Init(const UString &folderPrefix, const UString &fileName)
+ {
+ _folderPrefix = folderPrefix;
+ if (!_fileInfo.Find(_folderPrefix + fileName))
+ throw 1;
+ FileNames.Clear();
+ _subArchiveMode = false;
+ TotalSize = 0;
+ }
+ int FindName(const UString &name);
+};
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Bench.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Bench.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Bench.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Bench.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,1028 @@
+// Bench.cpp
+
+#include "StdAfx.h"
+
+#include "Bench.h"
+
+#ifndef _WIN32
+#define USE_POSIX_TIME
+#define USE_POSIX_TIME2
+#endif
+
+#ifdef USE_POSIX_TIME
+#include <time.h>
+#ifdef USE_POSIX_TIME2
+#include <sys/time.h>
+#endif
+#endif
+
+#ifdef _WIN32
+#define USE_ALLOCA
+#endif
+
+#ifdef USE_ALLOCA
+#ifdef _WIN32
+#include <malloc.h>
+#else
+#include <stdlib.h>
+#endif
+#endif
+
+#include "../../../../C/7zCrc.h"
+#include "../../../../C/Alloc.h"
+
+#ifndef _7ZIP_ST
+#include "../../../Windows/Synchronization.h"
+#include "../../../Windows/Thread.h"
+#endif
+
+#include "../../../Windows/PropVariant.h"
+
+static const UInt32 kUncompressMinBlockSize =
+#ifdef UNDER_CE
+1 << 24;
+#else
+1 << 26;
+#endif
+
+static const UInt32 kCrcBlockSize =
+#ifdef UNDER_CE
+1 << 25;
+#else
+1 << 30;
+#endif
+
+static const UInt32 kAdditionalSize = (1 << 16);
+static const UInt32 kCompressedAdditionalSize = (1 << 10);
+static const UInt32 kMaxLzmaPropSize = 5;
+
+class CBaseRandomGenerator
+{
+ UInt32 A1;
+ UInt32 A2;
+public:
+ CBaseRandomGenerator() { Init(); }
+ void Init() { A1 = 362436069; A2 = 521288629;}
+ UInt32 GetRnd()
+ {
+ return
+ ((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) +
+ ((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );
+ }
+};
+
+class CBenchBuffer
+{
+public:
+ size_t BufferSize;
+ Byte *Buffer;
+ CBenchBuffer(): Buffer(0) {}
+ virtual ~CBenchBuffer() { Free(); }
+ void Free()
+ {
+ ::MidFree(Buffer);
+ Buffer = 0;
+ }
+ bool Alloc(size_t bufferSize)
+ {
+ if (Buffer != 0 && BufferSize == bufferSize)
+ return true;
+ Free();
+ Buffer = (Byte *)::MidAlloc(bufferSize);
+ BufferSize = bufferSize;
+ return (Buffer != 0);
+ }
+};
+
+class CBenchRandomGenerator: public CBenchBuffer
+{
+ CBaseRandomGenerator *RG;
+public:
+ void Set(CBaseRandomGenerator *rg) { RG = rg; }
+ UInt32 GetVal(UInt32 &res, int numBits)
+ {
+ UInt32 val = res & (((UInt32)1 << numBits) - 1);
+ res >>= numBits;
+ return val;
+ }
+ UInt32 GetLen(UInt32 &res)
+ {
+ UInt32 len = GetVal(res, 2);
+ return GetVal(res, 1 + len);
+ }
+ void Generate()
+ {
+ UInt32 pos = 0;
+ UInt32 rep0 = 1;
+ while (pos < BufferSize)
+ {
+ UInt32 res = RG->GetRnd();
+ res >>= 1;
+ if (GetVal(res, 1) == 0 || pos < 1024)
+ Buffer[pos++] = (Byte)(res & 0xFF);
+ else
+ {
+ UInt32 len;
+ len = 1 + GetLen(res);
+ if (GetVal(res, 3) != 0)
+ {
+ len += GetLen(res);
+ do
+ {
+ UInt32 ppp = GetVal(res, 5) + 6;
+ res = RG->GetRnd();
+ if (ppp > 30)
+ continue;
+ rep0 = /* (1 << ppp) +*/ GetVal(res, ppp);
+ res = RG->GetRnd();
+ }
+ while (rep0 >= pos);
+ rep0++;
+ }
+
+ for (UInt32 i = 0; i < len && pos < BufferSize; i++, pos++)
+ Buffer[pos] = Buffer[pos - rep0];
+ }
+ }
+ }
+};
+
+
+class CBenchmarkInStream:
+ public ISequentialInStream,
+ public CMyUnknownImp
+{
+ const Byte *Data;
+ size_t Pos;
+ size_t Size;
+public:
+ MY_UNKNOWN_IMP
+ void Init(const Byte *data, size_t size)
+ {
+ Data = data;
+ Size = size;
+ Pos = 0;
+ }
+ STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
+};
+
+STDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processedSize)
+{
+ size_t remain = Size - Pos;
+ UInt32 kMaxBlockSize = (1 << 20);
+ if (size > kMaxBlockSize)
+ size = kMaxBlockSize;
+ if (size > remain)
+ size = (UInt32)remain;
+ for (UInt32 i = 0; i < size; i++)
+ ((Byte *)data)[i] = Data[Pos + i];
+ Pos += size;
+ if(processedSize != NULL)
+ *processedSize = size;
+ return S_OK;
+}
+
+class CBenchmarkOutStream:
+ public ISequentialOutStream,
+ public CBenchBuffer,
+ public CMyUnknownImp
+{
+ // bool _overflow;
+public:
+ UInt32 Pos;
+ // CBenchmarkOutStream(): _overflow(false) {}
+ void Init()
+ {
+ // _overflow = false;
+ Pos = 0;
+ }
+ MY_UNKNOWN_IMP
+ STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
+};
+
+STDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
+{
+ size_t curSize = BufferSize - Pos;
+ if (curSize > size)
+ curSize = size;
+ memcpy(Buffer + Pos, data, curSize);
+ Pos += (UInt32)curSize;
+ if(processedSize != NULL)
+ *processedSize = (UInt32)curSize;
+ if (curSize != size)
+ {
+ // _overflow = true;
+ return E_FAIL;
+ }
+ return S_OK;
+}
+
+class CCrcOutStream:
+ public ISequentialOutStream,
+ public CMyUnknownImp
+{
+public:
+ UInt32 Crc;
+ MY_UNKNOWN_IMP
+ void Init() { Crc = CRC_INIT_VAL; }
+ STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
+};
+
+STDMETHODIMP CCrcOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
+{
+ Crc = CrcUpdate(Crc, data, size);
+ if (processedSize != NULL)
+ *processedSize = size;
+ return S_OK;
+}
+
+static UInt64 GetTimeCount()
+{
+ #ifdef USE_POSIX_TIME
+ #ifdef USE_POSIX_TIME2
+ timeval v;
+ if (gettimeofday(&v, 0) == 0)
+ return (UInt64)(v.tv_sec) * 1000000 + v.tv_usec;
+ return (UInt64)time(NULL) * 1000000;
+ #else
+ return time(NULL);
+ #endif
+ #else
+ /*
+ LARGE_INTEGER value;
+ if (::QueryPerformanceCounter(&value))
+ return value.QuadPart;
+ */
+ return GetTickCount();
+ #endif
+}
+
+static UInt64 GetFreq()
+{
+ #ifdef USE_POSIX_TIME
+ #ifdef USE_POSIX_TIME2
+ return 1000000;
+ #else
+ return 1;
+ #endif
+ #else
+ /*
+ LARGE_INTEGER value;
+ if (::QueryPerformanceFrequency(&value))
+ return value.QuadPart;
+ */
+ return 1000;
+ #endif
+}
+
+#ifndef USE_POSIX_TIME
+static inline UInt64 GetTime64(const FILETIME &t) { return ((UInt64)t.dwHighDateTime << 32) | t.dwLowDateTime; }
+#endif
+
+static UInt64 GetUserTime()
+{
+ #ifdef USE_POSIX_TIME
+ return clock();
+ #else
+ FILETIME creationTime, exitTime, kernelTime, userTime;
+ if (
+ #ifdef UNDER_CE
+ ::GetThreadTimes(::GetCurrentThread()
+ #else
+ ::GetProcessTimes(::GetCurrentProcess()
+ #endif
+ , &creationTime, &exitTime, &kernelTime, &userTime) != 0)
+ return GetTime64(userTime) + GetTime64(kernelTime);
+ return (UInt64)GetTickCount() * 10000;
+ #endif
+}
+
+static UInt64 GetUserFreq()
+{
+ #ifdef USE_POSIX_TIME
+ return CLOCKS_PER_SEC;
+ #else
+ return 10000000;
+ #endif
+}
+
+class CBenchProgressStatus
+{
+ #ifndef _7ZIP_ST
+ NWindows::NSynchronization::CCriticalSection CS;
+ #endif
+public:
+ HRESULT Res;
+ bool EncodeMode;
+ void SetResult(HRESULT res)
+ {
+ #ifndef _7ZIP_ST
+ NWindows::NSynchronization::CCriticalSectionLock lock(CS);
+ #endif
+ Res = res;
+ }
+ HRESULT GetResult()
+ {
+ #ifndef _7ZIP_ST
+ NWindows::NSynchronization::CCriticalSectionLock lock(CS);
+ #endif
+ return Res;
+ }
+};
+
+class CBenchProgressInfo:
+ public ICompressProgressInfo,
+ public CMyUnknownImp
+{
+public:
+ CBenchProgressStatus *Status;
+ CBenchInfo BenchInfo;
+ HRESULT Res;
+ IBenchCallback *callback;
+ CBenchProgressInfo(): callback(0) {}
+ MY_UNKNOWN_IMP
+ STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize);
+};
+
+static void SetStartTime(CBenchInfo &bi)
+{
+ bi.GlobalFreq = GetFreq();
+ bi.UserFreq = GetUserFreq();
+ bi.GlobalTime = ::GetTimeCount();
+ bi.UserTime = ::GetUserTime();
+}
+
+static void SetFinishTime(const CBenchInfo &biStart, CBenchInfo &dest)
+{
+ dest.GlobalFreq = GetFreq();
+ dest.UserFreq = GetUserFreq();
+ dest.GlobalTime = ::GetTimeCount() - biStart.GlobalTime;
+ dest.UserTime = ::GetUserTime() - biStart.UserTime;
+}
+
+STDMETHODIMP CBenchProgressInfo::SetRatioInfo(const UInt64 *inSize, const UInt64 *outSize)
+{
+ HRESULT res = Status->GetResult();
+ if (res != S_OK)
+ return res;
+ if (!callback)
+ return res;
+ CBenchInfo info = BenchInfo;
+ SetFinishTime(BenchInfo, info);
+ if (Status->EncodeMode)
+ {
+ info.UnpackSize = *inSize;
+ info.PackSize = *outSize;
+ res = callback->SetEncodeResult(info, false);
+ }
+ else
+ {
+ info.PackSize = BenchInfo.PackSize + *inSize;
+ info.UnpackSize = BenchInfo.UnpackSize + *outSize;
+ res = callback->SetDecodeResult(info, false);
+ }
+ if (res != S_OK)
+ Status->SetResult(res);
+ return res;
+}
+
+static const int kSubBits = 8;
+
+static UInt32 GetLogSize(UInt32 size)
+{
+ for (int i = kSubBits; i < 32; i++)
+ for (UInt32 j = 0; j < (1 << kSubBits); j++)
+ if (size <= (((UInt32)1) << i) + (j << (i - kSubBits)))
+ return (i << kSubBits) + j;
+ return (32 << kSubBits);
+}
+
+static void NormalizeVals(UInt64 &v1, UInt64 &v2)
+{
+ while (v1 > 1000000)
+ {
+ v1 >>= 1;
+ v2 >>= 1;
+ }
+}
+
+UInt64 GetUsage(const CBenchInfo &info)
+{
+ UInt64 userTime = info.UserTime;
+ UInt64 userFreq = info.UserFreq;
+ UInt64 globalTime = info.GlobalTime;
+ UInt64 globalFreq = info.GlobalFreq;
+ NormalizeVals(userTime, userFreq);
+ NormalizeVals(globalFreq, globalTime);
+ if (userFreq == 0)
+ userFreq = 1;
+ if (globalTime == 0)
+ globalTime = 1;
+ return userTime * globalFreq * 1000000 / userFreq / globalTime;
+}
+
+UInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating)
+{
+ UInt64 userTime = info.UserTime;
+ UInt64 userFreq = info.UserFreq;
+ UInt64 globalTime = info.GlobalTime;
+ UInt64 globalFreq = info.GlobalFreq;
+ NormalizeVals(userFreq, userTime);
+ NormalizeVals(globalTime, globalFreq);
+ if (globalFreq == 0)
+ globalFreq = 1;
+ if (userTime == 0)
+ userTime = 1;
+ return userFreq * globalTime / globalFreq * rating / userTime;
+}
+
+static UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)
+{
+ UInt64 elTime = elapsedTime;
+ NormalizeVals(freq, elTime);
+ if (elTime == 0)
+ elTime = 1;
+ return value * freq / elTime;
+}
+
+UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size)
+{
+ UInt64 t = GetLogSize(dictionarySize) - (kBenchMinDicLogSize << kSubBits);
+ UInt64 numCommandsForOne = 870 + ((t * t * 5) >> (2 * kSubBits));
+ UInt64 numCommands = (UInt64)(size) * numCommandsForOne;
+ return MyMultDiv64(numCommands, elapsedTime, freq);
+}
+
+UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations)
+{
+ UInt64 numCommands = (inSize * 200 + outSize * 4) * numIterations;
+ return MyMultDiv64(numCommands, elapsedTime, freq);
+}
+
+struct CEncoderInfo;
+
+struct CEncoderInfo
+{
+ #ifndef _7ZIP_ST
+ NWindows::CThread thread[2];
+ #endif
+ CMyComPtr<ICompressCoder> encoder;
+ CBenchProgressInfo *progressInfoSpec[2];
+ CMyComPtr<ICompressProgressInfo> progressInfo[2];
+ UInt32 NumIterations;
+ #ifdef USE_ALLOCA
+ size_t AllocaSize;
+ #endif
+
+ struct CDecoderInfo
+ {
+ CEncoderInfo *Encoder;
+ UInt32 DecoderIndex;
+ #ifdef USE_ALLOCA
+ size_t AllocaSize;
+ #endif
+ bool CallbackMode;
+ };
+ CDecoderInfo decodersInfo[2];
+
+ CMyComPtr<ICompressCoder> decoders[2];
+ HRESULT Results[2];
+ CBenchmarkOutStream *outStreamSpec;
+ CMyComPtr<ISequentialOutStream> outStream;
+ IBenchCallback *callback;
+ UInt32 crc;
+ UInt32 kBufferSize;
+ UInt32 compressedSize;
+ CBenchRandomGenerator rg;
+ CBenchmarkOutStream *propStreamSpec;
+ CMyComPtr<ISequentialOutStream> propStream;
+ HRESULT Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rg);
+ HRESULT Encode();
+ HRESULT Decode(UInt32 decoderIndex);
+
+ CEncoderInfo(): outStreamSpec(0), callback(0), propStreamSpec(0) {}
+
+ #ifndef _7ZIP_ST
+ static THREAD_FUNC_DECL EncodeThreadFunction(void *param)
+ {
+ CEncoderInfo *encoder = (CEncoderInfo *)param;
+ #ifdef USE_ALLOCA
+ alloca(encoder->AllocaSize);
+ #endif
+ HRESULT res = encoder->Encode();
+ encoder->Results[0] = res;
+ if (res != S_OK)
+ encoder->progressInfoSpec[0]->Status->SetResult(res);
+
+ return 0;
+ }
+ static THREAD_FUNC_DECL DecodeThreadFunction(void *param)
+ {
+ CDecoderInfo *decoder = (CDecoderInfo *)param;
+ #ifdef USE_ALLOCA
+ alloca(decoder->AllocaSize);
+ #endif
+ CEncoderInfo *encoder = decoder->Encoder;
+ encoder->Results[decoder->DecoderIndex] = encoder->Decode(decoder->DecoderIndex);
+ return 0;
+ }
+
+ HRESULT CreateEncoderThread()
+ {
+ return thread[0].Create(EncodeThreadFunction, this);
+ }
+
+ HRESULT CreateDecoderThread(int index, bool callbackMode
+ #ifdef USE_ALLOCA
+ , size_t allocaSize
+ #endif
+ )
+ {
+ CDecoderInfo &decoder = decodersInfo[index];
+ decoder.DecoderIndex = index;
+ decoder.Encoder = this;
+ #ifdef USE_ALLOCA
+ decoder.AllocaSize = allocaSize;
+ #endif
+ decoder.CallbackMode = callbackMode;
+ return thread[index].Create(DecodeThreadFunction, &decoder);
+ }
+ #endif
+};
+
+HRESULT CEncoderInfo::Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandomGenerator *rgLoc)
+{
+ rg.Set(rgLoc);
+ kBufferSize = dictionarySize + kAdditionalSize;
+ UInt32 kCompressedBufferSize = (kBufferSize / 2) + kCompressedAdditionalSize;
+ if (!rg.Alloc(kBufferSize))
+ return E_OUTOFMEMORY;
+ rg.Generate();
+ crc = CrcCalc(rg.Buffer, rg.BufferSize);
+
+ outStreamSpec = new CBenchmarkOutStream;
+ if (!outStreamSpec->Alloc(kCompressedBufferSize))
+ return E_OUTOFMEMORY;
+
+ outStream = outStreamSpec;
+
+ propStreamSpec = 0;
+ if (!propStream)
+ {
+ propStreamSpec = new CBenchmarkOutStream;
+ propStream = propStreamSpec;
+ }
+ if (!propStreamSpec->Alloc(kMaxLzmaPropSize))
+ return E_OUTOFMEMORY;
+ propStreamSpec->Init();
+
+ PROPID propIDs[] =
+ {
+ NCoderPropID::kDictionarySize,
+ NCoderPropID::kNumThreads
+ };
+ const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);
+ PROPVARIANT props[kNumProps];
+ props[0].vt = VT_UI4;
+ props[0].ulVal = dictionarySize;
+
+ props[1].vt = VT_UI4;
+ props[1].ulVal = numThreads;
+
+ {
+ CMyComPtr<ICompressSetCoderProperties> setCoderProperties;
+ RINOK(encoder.QueryInterface(IID_ICompressSetCoderProperties, &setCoderProperties));
+ if (!setCoderProperties)
+ return E_FAIL;
+ RINOK(setCoderProperties->SetCoderProperties(propIDs, props, kNumProps));
+
+ CMyComPtr<ICompressWriteCoderProperties> writeCoderProperties;
+ encoder.QueryInterface(IID_ICompressWriteCoderProperties, &writeCoderProperties);
+ if (writeCoderProperties)
+ {
+ RINOK(writeCoderProperties->WriteCoderProperties(propStream));
+ }
+ }
+ return S_OK;
+}
+
+HRESULT CEncoderInfo::Encode()
+{
+ CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;
+ CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
+ inStreamSpec->Init(rg.Buffer, rg.BufferSize);
+ outStreamSpec->Init();
+
+ RINOK(encoder->Code(inStream, outStream, 0, 0, progressInfo[0]));
+ compressedSize = outStreamSpec->Pos;
+ encoder.Release();
+ return S_OK;
+}
+
+HRESULT CEncoderInfo::Decode(UInt32 decoderIndex)
+{
+ CBenchmarkInStream *inStreamSpec = new CBenchmarkInStream;
+ CMyComPtr<ISequentialInStream> inStream = inStreamSpec;
+ CMyComPtr<ICompressCoder> &decoder = decoders[decoderIndex];
+
+ CMyComPtr<ICompressSetDecoderProperties2> compressSetDecoderProperties;
+ decoder.QueryInterface(IID_ICompressSetDecoderProperties2, &compressSetDecoderProperties);
+ if (!compressSetDecoderProperties)
+ return E_FAIL;
+
+ CCrcOutStream *crcOutStreamSpec = new CCrcOutStream;
+ CMyComPtr<ISequentialOutStream> crcOutStream = crcOutStreamSpec;
+
+ CBenchProgressInfo *pi = progressInfoSpec[decoderIndex];
+ pi->BenchInfo.UnpackSize = 0;
+ pi->BenchInfo.PackSize = 0;
+
+ for (UInt32 j = 0; j < NumIterations; j++)
+ {
+ inStreamSpec->Init(outStreamSpec->Buffer, compressedSize);
+ crcOutStreamSpec->Init();
+
+ RINOK(compressSetDecoderProperties->SetDecoderProperties2(propStreamSpec->Buffer, propStreamSpec->Pos));
+ UInt64 outSize = kBufferSize;
+ RINOK(decoder->Code(inStream, crcOutStream, 0, &outSize, progressInfo[decoderIndex]));
+ if (CRC_GET_DIGEST(crcOutStreamSpec->Crc) != crc)
+ return S_FALSE;
+ pi->BenchInfo.UnpackSize += kBufferSize;
+ pi->BenchInfo.PackSize += compressedSize;
+ }
+ decoder.Release();
+ return S_OK;
+}
+
+static const UInt32 kNumThreadsMax = (1 << 16);
+
+struct CBenchEncoders
+{
+ CEncoderInfo *encoders;
+ CBenchEncoders(UInt32 num): encoders(0) { encoders = new CEncoderInfo[num]; }
+ ~CBenchEncoders() { delete []encoders; }
+};
+
+HRESULT LzmaBench(
+ DECL_EXTERNAL_CODECS_LOC_VARS
+ UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback)
+{
+ UInt32 numEncoderThreads =
+ #ifndef _7ZIP_ST
+ (numThreads > 1 ? numThreads / 2 : 1);
+ #else
+ 1;
+ #endif
+ UInt32 numSubDecoderThreads =
+ #ifndef _7ZIP_ST
+ (numThreads > 1 ? 2 : 1);
+ #else
+ 1;
+ #endif
+ if (dictionarySize < (1 << kBenchMinDicLogSize) || numThreads < 1 || numEncoderThreads > kNumThreadsMax)
+ {
+ return E_INVALIDARG;
+ }
+
+ CBenchEncoders encodersSpec(numEncoderThreads);
+ CEncoderInfo *encoders = encodersSpec.encoders;
+
+
+ UInt32 i;
+ for (i = 0; i < numEncoderThreads; i++)
+ {
+ CEncoderInfo &encoder = encoders[i];
+ encoder.callback = (i == 0) ? callback : 0;
+
+ const UInt32 kLzmaId = 0x030101;
+ RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS kLzmaId, encoder.encoder, true));
+ if (!encoder.encoder)
+ return E_NOTIMPL;
+ for (UInt32 j = 0; j < numSubDecoderThreads; j++)
+ {
+ RINOK(CreateCoder(EXTERNAL_CODECS_LOC_VARS kLzmaId, encoder.decoders[j], false));
+ if (!encoder.decoders[j])
+ return E_NOTIMPL;
+ }
+ }
+
+ CBaseRandomGenerator rg;
+ rg.Init();
+ for (i = 0; i < numEncoderThreads; i++)
+ {
+ RINOK(encoders[i].Init(dictionarySize, numThreads, &rg));
+ }
+
+ CBenchProgressStatus status;
+ status.Res = S_OK;
+ status.EncodeMode = true;
+
+ for (i = 0; i < numEncoderThreads; i++)
+ {
+ CEncoderInfo &encoder = encoders[i];
+ for (int j = 0; j < 2; j++)
+ {
+ encoder.progressInfo[j] = encoder.progressInfoSpec[j] = new CBenchProgressInfo;
+ encoder.progressInfoSpec[j]->Status = &status;
+ }
+ if (i == 0)
+ {
+ encoder.progressInfoSpec[0]->callback = callback;
+ encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numEncoderThreads;
+ SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);
+ }
+
+ #ifndef _7ZIP_ST
+ if (numEncoderThreads > 1)
+ {
+ #ifdef USE_ALLOCA
+ encoder.AllocaSize = (i * 16 * 21) & 0x7FF;
+ #endif
+ RINOK(encoder.CreateEncoderThread())
+ }
+ else
+ #endif
+ {
+ RINOK(encoder.Encode());
+ }
+ }
+ #ifndef _7ZIP_ST
+ if (numEncoderThreads > 1)
+ for (i = 0; i < numEncoderThreads; i++)
+ encoders[i].thread[0].Wait();
+ #endif
+
+ RINOK(status.Res);
+
+ CBenchInfo info;
+
+ SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);
+ info.UnpackSize = 0;
+ info.PackSize = 0;
+ info.NumIterations = 1; // progressInfoSpec->NumIterations;
+ for (i = 0; i < numEncoderThreads; i++)
+ {
+ CEncoderInfo &encoder = encoders[i];
+ info.UnpackSize += encoder.kBufferSize;
+ info.PackSize += encoder.compressedSize;
+ }
+ RINOK(callback->SetEncodeResult(info, true));
+
+
+ status.Res = S_OK;
+ status.EncodeMode = false;
+
+ UInt32 numDecoderThreads = numEncoderThreads * numSubDecoderThreads;
+ for (i = 0; i < numEncoderThreads; i++)
+ {
+ CEncoderInfo &encoder = encoders[i];
+ encoder.NumIterations = 2 + kUncompressMinBlockSize / encoder.kBufferSize;
+
+ if (i == 0)
+ {
+ encoder.progressInfoSpec[0]->callback = callback;
+ encoder.progressInfoSpec[0]->BenchInfo.NumIterations = numDecoderThreads;
+ SetStartTime(encoder.progressInfoSpec[0]->BenchInfo);
+ }
+
+ #ifndef _7ZIP_ST
+ if (numDecoderThreads > 1)
+ {
+ for (UInt32 j = 0; j < numSubDecoderThreads; j++)
+ {
+ HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0)
+ #ifdef USE_ALLOCA
+ , ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF
+ #endif
+ );
+ RINOK(res);
+ }
+ }
+ else
+ #endif
+ {
+ RINOK(encoder.Decode(0));
+ }
+ }
+ #ifndef _7ZIP_ST
+ HRESULT res = S_OK;
+ if (numDecoderThreads > 1)
+ for (i = 0; i < numEncoderThreads; i++)
+ for (UInt32 j = 0; j < numSubDecoderThreads; j++)
+ {
+ CEncoderInfo &encoder = encoders[i];
+ encoder.thread[j].Wait();
+ if (encoder.Results[j] != S_OK)
+ res = encoder.Results[j];
+ }
+ RINOK(res);
+ #endif
+ RINOK(status.Res);
+ SetFinishTime(encoders[0].progressInfoSpec[0]->BenchInfo, info);
+ #ifndef _7ZIP_ST
+ #ifdef UNDER_CE
+ if (numDecoderThreads > 1)
+ for (i = 0; i < numEncoderThreads; i++)
+ for (UInt32 j = 0; j < numSubDecoderThreads; j++)
+ {
+ FILETIME creationTime, exitTime, kernelTime, userTime;
+ if (::GetThreadTimes(encoders[i].thread[j], &creationTime, &exitTime, &kernelTime, &userTime) != 0)
+ info.UserTime += GetTime64(userTime) + GetTime64(kernelTime);
+ }
+ #endif
+ #endif
+ info.UnpackSize = 0;
+ info.PackSize = 0;
+ info.NumIterations = numSubDecoderThreads * encoders[0].NumIterations;
+ for (i = 0; i < numEncoderThreads; i++)
+ {
+ CEncoderInfo &encoder = encoders[i];
+ info.UnpackSize += encoder.kBufferSize;
+ info.PackSize += encoder.compressedSize;
+ }
+ RINOK(callback->SetDecodeResult(info, false));
+ RINOK(callback->SetDecodeResult(info, true));
+ return S_OK;
+}
+
+
+inline UInt64 GetLZMAUsage(bool multiThread, UInt32 dictionary)
+{
+ UInt32 hs = dictionary - 1;
+ hs |= (hs >> 1);
+ hs |= (hs >> 2);
+ hs |= (hs >> 4);
+ hs |= (hs >> 8);
+ hs >>= 1;
+ hs |= 0xFFFF;
+ if (hs > (1 << 24))
+ hs >>= 1;
+ hs++;
+ return ((hs + (1 << 16)) + (UInt64)dictionary * 2) * 4 + (UInt64)dictionary * 3 / 2 +
+ (1 << 20) + (multiThread ? (6 << 20) : 0);
+}
+
+UInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary)
+{
+ const UInt32 kBufferSize = dictionary;
+ const UInt32 kCompressedBufferSize = (kBufferSize / 2);
+ UInt32 numSubThreads = (numThreads > 1) ? 2 : 1;
+ UInt32 numBigThreads = numThreads / numSubThreads;
+ return (kBufferSize + kCompressedBufferSize +
+ GetLZMAUsage((numThreads > 1), dictionary) + (2 << 20)) * numBigThreads;
+}
+
+static bool CrcBig(const void *data, UInt32 size, UInt32 numCycles, UInt32 crcBase)
+{
+ for (UInt32 i = 0; i < numCycles; i++)
+ if (CrcCalc(data, size) != crcBase)
+ return false;
+ return true;
+}
+
+#ifndef _7ZIP_ST
+struct CCrcInfo
+{
+ NWindows::CThread Thread;
+ const Byte *Data;
+ UInt32 Size;
+ UInt32 NumCycles;
+ UInt32 Crc;
+ bool Res;
+ void Wait()
+ {
+ Thread.Wait();
+ Thread.Close();
+ }
+};
+
+static THREAD_FUNC_DECL CrcThreadFunction(void *param)
+{
+ CCrcInfo *p = (CCrcInfo *)param;
+ p->Res = CrcBig(p->Data, p->Size, p->NumCycles, p->Crc);
+ return 0;
+}
+
+struct CCrcThreads
+{
+ UInt32 NumThreads;
+ CCrcInfo *Items;
+ CCrcThreads(): Items(0), NumThreads(0) {}
+ void WaitAll()
+ {
+ for (UInt32 i = 0; i < NumThreads; i++)
+ Items[i].Wait();
+ NumThreads = 0;
+ }
+ ~CCrcThreads()
+ {
+ WaitAll();
+ delete []Items;
+ }
+};
+#endif
+
+static UInt32 CrcCalc1(const Byte *buf, UInt32 size)
+{
+ UInt32 crc = CRC_INIT_VAL;;
+ for (UInt32 i = 0; i < size; i++)
+ crc = CRC_UPDATE_BYTE(crc, buf[i]);
+ return CRC_GET_DIGEST(crc);
+}
+
+static void RandGen(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)
+{
+ for (UInt32 i = 0; i < size; i++)
+ buf[i] = (Byte)RG.GetRnd();
+}
+
+static UInt32 RandGenCrc(Byte *buf, UInt32 size, CBaseRandomGenerator &RG)
+{
+ RandGen(buf, size, RG);
+ return CrcCalc1(buf, size);
+}
+
+bool CrcInternalTest()
+{
+ CBenchBuffer buffer;
+ const UInt32 kBufferSize0 = (1 << 8);
+ const UInt32 kBufferSize1 = (1 << 10);
+ const UInt32 kCheckSize = (1 << 5);
+ if (!buffer.Alloc(kBufferSize0 + kBufferSize1))
+ return false;
+ Byte *buf = buffer.Buffer;
+ UInt32 i;
+ for (i = 0; i < kBufferSize0; i++)
+ buf[i] = (Byte)i;
+ UInt32 crc1 = CrcCalc1(buf, kBufferSize0);
+ if (crc1 != 0x29058C73)
+ return false;
+ CBaseRandomGenerator RG;
+ RandGen(buf + kBufferSize0, kBufferSize1, RG);
+ for (i = 0; i < kBufferSize0 + kBufferSize1 - kCheckSize; i++)
+ for (UInt32 j = 0; j < kCheckSize; j++)
+ if (CrcCalc1(buf + i, j) != CrcCalc(buf + i, j))
+ return false;
+ return true;
+}
+
+HRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed)
+{
+ if (numThreads == 0)
+ numThreads = 1;
+
+ CBenchBuffer buffer;
+ size_t totalSize = (size_t)bufferSize * numThreads;
+ if (totalSize / numThreads != bufferSize)
+ return E_OUTOFMEMORY;
+ if (!buffer.Alloc(totalSize))
+ return E_OUTOFMEMORY;
+
+ Byte *buf = buffer.Buffer;
+ CBaseRandomGenerator RG;
+ UInt32 numCycles = (kCrcBlockSize) / ((bufferSize >> 2) + 1) + 1;
+
+ UInt64 timeVal;
+ #ifndef _7ZIP_ST
+ CCrcThreads threads;
+ if (numThreads > 1)
+ {
+ threads.Items = new CCrcInfo[numThreads];
+ UInt32 i;
+ for (i = 0; i < numThreads; i++)
+ {
+ CCrcInfo &info = threads.Items[i];
+ Byte *data = buf + (size_t)bufferSize * i;
+ info.Data = data;
+ info.NumCycles = numCycles;
+ info.Size = bufferSize;
+ info.Crc = RandGenCrc(data, bufferSize, RG);
+ }
+ timeVal = GetTimeCount();
+ for (i = 0; i < numThreads; i++)
+ {
+ CCrcInfo &info = threads.Items[i];
+ RINOK(info.Thread.Create(CrcThreadFunction, &info));
+ threads.NumThreads++;
+ }
+ threads.WaitAll();
+ for (i = 0; i < numThreads; i++)
+ if (!threads.Items[i].Res)
+ return S_FALSE;
+ }
+ else
+ #endif
+ {
+ UInt32 crc = RandGenCrc(buf, bufferSize, RG);
+ timeVal = GetTimeCount();
+ if (!CrcBig(buf, bufferSize, numCycles, crc))
+ return S_FALSE;
+ }
+ timeVal = GetTimeCount() - timeVal;
+ if (timeVal == 0)
+ timeVal = 1;
+
+ UInt64 size = (UInt64)numCycles * totalSize;
+ speed = MyMultDiv64(size, timeVal, GetFreq());
+ return S_OK;
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Bench.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Bench.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Bench.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Bench.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,42 @@
+// Bench.h
+
+#ifndef __7ZIP_BENCH_H
+#define __7ZIP_BENCH_H
+
+#include "../../Common/CreateCoder.h"
+
+struct CBenchInfo
+{
+ UInt64 GlobalTime;
+ UInt64 GlobalFreq;
+ UInt64 UserTime;
+ UInt64 UserFreq;
+ UInt64 UnpackSize;
+ UInt64 PackSize;
+ UInt32 NumIterations;
+ CBenchInfo(): NumIterations(0) {}
+};
+
+struct IBenchCallback
+{
+ virtual HRESULT SetEncodeResult(const CBenchInfo &info, bool final) = 0;
+ virtual HRESULT SetDecodeResult(const CBenchInfo &info, bool final) = 0;
+};
+
+UInt64 GetUsage(const CBenchInfo &benchOnfo);
+UInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating);
+UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size);
+UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations);
+
+HRESULT LzmaBench(
+ DECL_EXTERNAL_CODECS_LOC_VARS
+ UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback);
+
+const int kBenchMinDicLogSize = 18;
+
+UInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary);
+
+bool CrcInternalTest();
+HRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed);
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/CompressCall.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/CompressCall.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/CompressCall.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/CompressCall.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,470 @@
+// CompressCall.cpp
+
+#include "StdAfx.h"
+
+// For compilers that support precompilation, includes "wx/wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include "wx/wx.h"
+#endif
+
+#undef _WIN32
+
+#include "CompressCall.h"
+
+// FIXME #include "Common/Random.h"
+#include "Common/IntToString.h"
+#include "Common/MyCom.h"
+#include "Common/StringConvert.h"
+
+#include "Windows/Synchronization.h"
+// FIXME #include "Windows/FileMapping.h"
+#include "Windows/FileDir.h"
+
+#include "../FileManager/ProgramLocation.h"
+#include "../FileManager/RegistryUtils.h"
+
+#define NEED_NAME_WINDOWS_TO_UNIX
+#include "myPrivate.h"
+
+#ifndef _UNICODE
+extern bool g_IsNT;
+#endif // _UNICODE
+
+using namespace NWindows;
+
+static LPCWSTR kShowDialogSwitch = L" -ad";
+static LPCWSTR kEmailSwitch = L" -seml.";
+static LPCWSTR kMapSwitch = L" -i#";
+static LPCWSTR kArchiveNoNameSwitch = L" -an";
+static LPCWSTR kArchiveTypeSwitch = L" -t";
+static LPCWSTR kArchiveMapSwitch = L" -ai#";
+static LPCWSTR kStopSwitchParsing = L" --";
+static LPCWSTR kLargePagesDisable = L" -slp-";
+
+static void AddLagePagesSwitch(UString ¶ms)
+{
+#ifdef _WIN32
+ if (!ReadLockMemoryEnable())
+ params += kLargePagesDisable;
+#endif
+}
+
+HRESULT MyCreateProcess(const UString ¶ms,
+ LPCWSTR curDir, bool waitFinish,
+ NWindows::NSynchronization::CBaseEvent *event)
+{
+ printf("MyCreateProcess: waitFinish=%d event=%p\n",(unsigned)waitFinish,event);
+ printf("\tparams : %ls\n",(const wchar_t*)params);
+ printf("\tcurDir : %ls\n",(const wchar_t*)curDir);
+
+ wxString cmd(params);
+ wxString memoCurDir = wxGetCwd();
+
+ if (curDir) { // FIXME
+ wxSetWorkingDirectory(wxString(curDir));
+
+
+ // under MacOSX, a bundle does not keep the current directory
+ // between 7zFM and 7zG ...
+ // So, try to use the environment variable P7ZIP_CURRENT_DIR
+
+ char p7zip_current_dir[MAX_PATH];
+
+ AString aCurPath = GetAnsiString(curDir);
+
+ const char *dir2 = nameWindowToUnix((const char *)aCurPath);
+
+ snprintf(p7zip_current_dir,sizeof(p7zip_current_dir),"P7ZIP_CURRENT_DIR=%s/",dir2);
+
+ p7zip_current_dir[sizeof(p7zip_current_dir)-1] = 0;
+
+ putenv(p7zip_current_dir);
+
+ printf("putenv(%s)\n",p7zip_current_dir);
+
+ }
+
+
+ printf("MyCreateProcess: cmd='%ls'\n",(const wchar_t *)cmd);
+ long pid = 0;
+ if (waitFinish) pid = wxExecute(cmd, wxEXEC_SYNC); // FIXME process never ends and stays zombie ...
+ else pid = wxExecute(cmd, wxEXEC_ASYNC);
+
+ if (curDir) wxSetWorkingDirectory(memoCurDir);
+
+
+ // FIXME if (pid == 0) return E_FAIL;
+
+ return S_OK;
+#ifdef _WIN32 // FIXME
+ const UString params2 = params;
+ BOOL result;
+ {
+ STARTUPINFOW startupInfo;
+ startupInfo.cb = sizeof(startupInfo);
+ startupInfo.lpReserved = 0;
+ startupInfo.lpDesktop = 0;
+ startupInfo.lpTitle = 0;
+ startupInfo.dwFlags = 0;
+ startupInfo.cbReserved2 = 0;
+ startupInfo.lpReserved2 = 0;
+
+ result = ::CreateProcessW(NULL, (LPWSTR)(LPCWSTR)params,
+ NULL, NULL, FALSE, 0, NULL,
+ curDir,
+ &startupInfo, &processInformation);
+ }
+ if (result == 0)
+ return ::GetLastError();
+ else
+ {
+ ::CloseHandle(processInformation.hThread);
+ if (waitFinish)
+ WaitForSingleObject(processInformation.hProcess, INFINITE);
+ else if (event != NULL)
+ {
+ HANDLE handles[] = {processInformation.hProcess, *event };
+ ::WaitForMultipleObjects(sizeof(handles) / sizeof(handles[0]),
+ handles, FALSE, INFINITE);
+ }
+ ::CloseHandle(processInformation.hProcess);
+ }
+ return S_OK;
+#endif
+}
+
+UString GetQuotedString(const UString &s)
+{
+ return UString(L"\"") + s + UString(L"\"");
+}
+
+static UString Get7zGuiPath()
+{
+ UString path;
+ UString folder;
+ if (GetProgramFolderPath(folder))
+ path += folder;
+#ifdef _WIN32
+ path += L"7zG.exe";
+#else
+ path += L"7zG";
+#endif
+ return GetQuotedString(path);
+}
+
+#ifdef _WIN32
+static HRESULT CreateTempEvent(const wchar_t *name,
+ NSynchronization::CManualResetEvent &event, UString &eventName)
+{
+ CRandom random;
+ random.Init(GetTickCount());
+ for (;;)
+ {
+ int number = random.Generate();
+ wchar_t temp[32];
+ ConvertUInt64ToString((UInt32)number, temp);
+ eventName = name;
+ eventName += temp;
+ RINOK(event.CreateWithName(false, GetSystemString(eventName)));
+ if (::GetLastError() != ERROR_ALREADY_EXISTS)
+ return S_OK;
+ event.Close();
+ }
+}
+
+static HRESULT CreateMap(const UStringVector &names,
+ const UString &id,
+ CFileMapping &fileMapping, NSynchronization::CManualResetEvent &event,
+ UString ¶ms)
+{
+ UInt32 extraSize = 2;
+ UInt32 dataSize = 0;
+ for (int i = 0; i < names.Size(); i++)
+ dataSize += (names[i].Length() + 1) * sizeof(wchar_t);
+ UInt32 totalSize = extraSize + dataSize;
+
+ UString mappingName;
+
+ CRandom random;
+ random.Init(GetTickCount());
+ for (;;)
+ {
+ int number = random.Generate();
+ wchar_t temp[32];
+ ConvertUInt64ToString(UInt32(number), temp);
+ mappingName = id;
+ mappingName += L"Mapping";
+ mappingName += temp;
+ if (!fileMapping.Create(INVALID_HANDLE_VALUE, NULL,
+ PAGE_READWRITE, totalSize, GetSystemString(mappingName)))
+ return E_FAIL;
+ if (::GetLastError() != ERROR_ALREADY_EXISTS)
+ break;
+ fileMapping.Close();
+ }
+
+ UString eventName;
+ RINOK(CreateTempEvent(id + L"MappingEndEvent", event, eventName));
+
+ params += mappingName;
+ params += L":";
+ wchar_t string[10];
+ ConvertUInt64ToString(totalSize, string);
+ params += string;
+
+ params += L":";
+ params += eventName;
+
+ LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_WRITE, 0, totalSize);
+ if (data == NULL)
+ return E_FAIL;
+ {
+ wchar_t *curData = (wchar_t *)data;
+ *curData = 0;
+ curData++;
+ for (int i = 0; i < names.Size(); i++)
+ {
+ const UString &s = names[i];
+ memcpy(curData, (const wchar_t *)s, s.Length() * sizeof(wchar_t));
+ curData += s.Length();
+ *curData++ = L'\0';
+ }
+ }
+ return S_OK;
+}
+#endif
+
+HRESULT CompressFiles(
+ const UString &curDir,
+ const UString &archiveName,
+ const UString &archiveType,
+ const UStringVector &names,
+ // const UString &outFolder,
+ bool email,
+ bool showDialog,
+ bool waitFinish)
+{
+ /*
+ UString curDir;
+ if (names.Size() > 0)
+ {
+ NFile::NDirectory::GetOnlyDirPrefix(names[0], curDir);
+ }
+ */
+ UString params;
+ params = Get7zGuiPath();
+ params += L" a";
+#ifdef _WIN32
+ params += kMapSwitch;
+ // params += _fileNames[0];
+
+ UInt32 extraSize = 2;
+ UInt32 dataSize = 0;
+ for (int i = 0; i < names.Size(); i++)
+ dataSize += (names[i].Length() + 1) * sizeof(wchar_t);
+ UInt32 totalSize = extraSize + dataSize;
+
+ UString mappingName;
+
+ CFileMapping fileMapping;
+ CRandom random;
+ random.Init(GetTickCount());
+ for (;;)
+ {
+ int number = random.Generate();
+ wchar_t temp[32];
+ ConvertUInt64ToString(UInt32(number), temp);
+ mappingName = L"7zCompressMapping";
+ mappingName += temp;
+ if (!fileMapping.Create(INVALID_HANDLE_VALUE, NULL,
+ PAGE_READWRITE, totalSize, GetSystemString(mappingName)))
+ {
+ // MyMessageBox(IDS_ERROR, 0x02000605);
+ return E_FAIL;
+ }
+ if (::GetLastError() != ERROR_ALREADY_EXISTS)
+ break;
+ fileMapping.Close();
+ }
+
+ NSynchronization::CManualResetEvent event;
+ UString eventName;
+ RINOK(CreateTempEvent(L"7zCompressMappingEndEvent", event, eventName));
+
+ params += mappingName;
+ params += L":";
+ wchar_t string[10];
+ ConvertUInt64ToString(totalSize, string);
+ params += string;
+
+ params += L":";
+ params += eventName;
+#else
+ char tempFile[256];
+ static int count = 1000;
+
+ sprintf(tempFile,"/tmp/7zCompress_%d_%d.tmp",(int)getpid(),count++);
+
+ FILE * file = fopen(tempFile,"w");
+ if (file)
+ {
+ for (int i = 0; i < names.Size(); i++) {
+ fprintf(file,"%ls\n",(const wchar_t *)names[i]);
+ printf(" TMP_%d : '%ls'\n",i,(const wchar_t *)names[i]);
+ }
+
+ fclose(file);
+ }
+ params += L" -i@";
+ params += GetUnicodeString(tempFile);
+#endif
+
+ if (!archiveType.IsEmpty())
+ {
+ params += kArchiveTypeSwitch;
+ params += archiveType;
+ }
+
+ if (email)
+ params += kEmailSwitch;
+
+ if (showDialog)
+ params += kShowDialogSwitch;
+
+ AddLagePagesSwitch(params);
+
+ params += kStopSwitchParsing;
+ params += L" ";
+
+ params += GetQuotedString(archiveName);
+
+#ifdef _WIN32
+ LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_WRITE, 0, totalSize);
+ if (data == NULL)
+ {
+ // MyMessageBox(IDS_ERROR, 0x02000605);
+ return E_FAIL;
+ }
+ try
+ {
+ wchar_t *curData = (wchar_t *)data;
+ *curData = 0;
+ curData++;
+ for (int i = 0; i < names.Size(); i++)
+ {
+ const UString &unicodeString = names[i];
+ memcpy(curData, (const wchar_t *)unicodeString ,
+ unicodeString .Length() * sizeof(wchar_t));
+ curData += unicodeString.Length();
+ *curData++ = L'\0';
+ }
+ // MessageBox(0, params, 0, 0);
+ RINOK(MyCreateProcess(params,
+ (curDir.IsEmpty()? 0: (LPCWSTR)curDir),
+ waitFinish, &event));
+ }
+ catch(...)
+ {
+ UnmapViewOfFile(data);
+ throw;
+ }
+ UnmapViewOfFile(data);
+
+
+ /*
+ CThreadCompressMain *compressor = new CThreadCompressMain();;
+ compressor->FileNames = _fileNames;
+ CThread thread;
+ if (!thread.Create(CThreadCompressMain::MyThreadFunction, compressor))
+ throw 271824;
+ */
+#else
+ printf("CompressFiles : -%ls-\n",(const wchar_t *)params);
+ HRESULT res = MyCreateProcess(params,
+ (curDir.IsEmpty()? 0: (LPCWSTR)curDir),
+ true, /* &event FIXME */ 0);
+ printf("CompressFiles : END\n");
+
+ remove(tempFile);
+#endif
+ return S_OK;
+}
+
+static HRESULT ExtractGroupCommand(const UStringVector &archivePaths,
+ const UString ¶ms)
+{
+ UString params2 = params;
+ AddLagePagesSwitch(params2);
+ params2 += kArchiveNoNameSwitch;
+#ifdef _WIN32
+ params2 += kArchiveMapSwitch;
+ CFileMapping fileMapping;
+ NSynchronization::CManualResetEvent event;
+ RINOK(CreateMap(archivePaths, L"7zExtract", fileMapping, event, params2));
+ return MyCreateProcess(params2, 0, false, &event);
+#else
+ char tempFile[256];
+ static int count = 1000;
+
+ sprintf(tempFile,"/tmp/7zExtract_%d_%d.tmp",(int)getpid(),count++);
+
+ FILE * file = fopen(tempFile,"w");
+ if (file)
+ {
+ for (int i = 0; i < archivePaths.Size(); i++) {
+ fprintf(file,"%ls\n",(const wchar_t *)archivePaths[i]);
+ printf(" TMP_%d : '%ls'\n",i,(const wchar_t *)archivePaths[i]);
+ }
+
+ fclose(file);
+ }
+ params2 += L" -ai@";
+ params2 += GetUnicodeString(tempFile);
+ printf("ExtractGroupCommand : -%ls-\n",(const wchar_t *)params2);
+ HRESULT res = MyCreateProcess(params2, 0, true, /* &event FIXME */ 0);
+ printf("ExtractGroupCommand : END\n");
+
+ remove(tempFile);
+
+ return res;
+#endif
+}
+
+HRESULT ExtractArchives(const UStringVector &archivePaths,
+ const UString &outFolder, bool showDialog)
+{
+ UString params;
+ params = Get7zGuiPath();
+ params += L" x";
+ if (!outFolder.IsEmpty())
+ {
+ params += L" \"-o";
+ params += outFolder;
+ params += L"\"";
+ }
+ if (showDialog)
+ params += kShowDialogSwitch;
+ return ExtractGroupCommand(archivePaths, params);
+}
+
+HRESULT TestArchives(const UStringVector &archivePaths)
+{
+ UString params;
+ params = Get7zGuiPath();
+ params += L" t";
+ return ExtractGroupCommand(archivePaths, params);
+}
+
+HRESULT Benchmark()
+{
+ UString params;
+ params = Get7zGuiPath();
+ params += L" b";
+ return MyCreateProcess(params, 0, false, NULL);
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/CompressCall.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/CompressCall.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/CompressCall.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/CompressCall.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,24 @@
+// CompressCall.h
+
+#ifndef __COMPRESS_CALL_H
+#define __COMPRESS_CALL_H
+
+#include "Common/MyString.h"
+
+UString GetQuotedString(const UString &s);
+
+extern HWND g_HWND;
+UString HResultToMessage(HRESULT errorCode);
+
+HRESULT CompressFiles(
+ const UString &arcPathPrefix,
+ const UString &arcName,
+ const UString &arcType,
+ const UStringVector &names,
+ bool email, bool showDialog, bool waitFinish);
+
+HRESULT ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog);
+HRESULT TestArchives(const UStringVector &arcPaths);
+HRESULT Benchmark();
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/DefaultName.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/DefaultName.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/DefaultName.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/DefaultName.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,35 @@
+// DefaultName.cpp
+
+#include "StdAfx.h"
+
+#include "DefaultName.h"
+
+static UString GetDefaultName3(const UString &fileName,
+ const UString &extension, const UString &addSubExtension)
+{
+ int extLength = extension.Length();
+ int fileNameLength = fileName.Length();
+ if (fileNameLength > extLength + 1)
+ {
+ int dotPos = fileNameLength - (extLength + 1);
+ if (fileName[dotPos] == '.')
+ if (extension.CompareNoCase(fileName.Mid(dotPos + 1)) == 0)
+ return fileName.Left(dotPos) + addSubExtension;
+ }
+ int dotPos = fileName.ReverseFind(L'.');
+ if (dotPos > 0)
+ return fileName.Left(dotPos) + addSubExtension;
+
+ if (addSubExtension.IsEmpty())
+ return fileName + L"~";
+ else
+ return fileName + addSubExtension;
+}
+
+UString GetDefaultName2(const UString &fileName,
+ const UString &extension, const UString &addSubExtension)
+{
+ UString name = GetDefaultName3(fileName, extension, addSubExtension);
+ name.TrimRight();
+ return name;
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/DefaultName.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/DefaultName.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/DefaultName.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/DefaultName.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,11 @@
+// DefaultName.h
+
+#ifndef __DEFAULTNAME_H
+#define __DEFAULTNAME_H
+
+#include "Common/MyString.h"
+
+UString GetDefaultName2(const UString &fileName,
+ const UString &extension, const UString &addSubExtension);
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/DirItem.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/DirItem.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/DirItem.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/DirItem.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,69 @@
+// DirItem.h
+
+#ifndef __DIR_ITEM_H
+#define __DIR_ITEM_H
+
+#include "Common/MyString.h"
+#include "Common/Types.h"
+#include "../../Archive/IArchive.h"
+
+struct CDirItem
+{
+ UInt64 Size;
+ FILETIME CTime;
+ FILETIME ATime;
+ FILETIME MTime;
+ UString Name;
+ UInt32 Attrib;
+ int PhyParent;
+ int LogParent;
+
+ CDirItem(): PhyParent(-1), LogParent(-1) {}
+ bool IsDir() const { return (Attrib & FILE_ATTRIBUTE_DIRECTORY) != 0 ; }
+};
+
+class CDirItems
+{
+ UStringVector Prefixes;
+ CIntVector PhyParents;
+ CIntVector LogParents;
+
+ UString GetPrefixesPath(const CIntVector &parents, int index, const UString &name) const;
+public:
+ CObjectVector<CDirItem> Items;
+
+ int GetNumFolders() const { return Prefixes.Size(); }
+ UString GetPhyPath(int index) const;
+ UString GetLogPath(int index) const;
+
+ int AddPrefix(int phyParent, int logParent, const UString &prefix);
+ void DeleteLastPrefix();
+
+ void EnumerateDirectory(int phyParent, int logParent, const UString &phyPrefix,
+ UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes);
+
+ void EnumerateDirItems2(
+ const UString &phyPrefix,
+ const UString &logPrefix,
+ const UStringVector &filePaths,
+ UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes);
+
+ void ReserveDown();
+};
+
+struct CArcItem
+{
+ UInt64 Size;
+ FILETIME MTime;
+ UString Name;
+ bool IsDir;
+ bool SizeDefined;
+ bool MTimeDefined;
+ bool Censored;
+ UInt32 IndexInServer;
+ int TimeType;
+
+ CArcItem(): IsDir(false), SizeDefined(false), MTimeDefined(false), Censored(false), TimeType(-1) {}
+};
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/EnumDirItems.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/EnumDirItems.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/EnumDirItems.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/EnumDirItems.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,361 @@
+// EnumDirItems.cpp
+
+#include "StdAfx.h"
+
+#include "EnumDirItems.h"
+
+using namespace NWindows;
+using namespace NFile;
+using namespace NName;
+
+void AddDirFileInfo(int phyParent, int logParent,
+ const NFind::CFileInfoW &fi, CObjectVector<CDirItem> &dirItems)
+{
+ CDirItem di;
+ di.Size = fi.Size;
+ di.CTime = fi.CTime;
+ di.ATime = fi.ATime;
+ di.MTime = fi.MTime;
+ di.Attrib = fi.Attrib;
+ di.PhyParent = phyParent;
+ di.LogParent = logParent;
+ di.Name = fi.Name;
+ dirItems.Add(di);
+}
+
+UString CDirItems::GetPrefixesPath(const CIntVector &parents, int index, const UString &name) const
+{
+ UString path;
+ int len = name.Length();
+ int i;
+ for (i = index; i >= 0; i = parents[i])
+ len += Prefixes[i].Length();
+ int totalLen = len;
+ wchar_t *p = path.GetBuffer(len);
+ p[len] = 0;
+ len -= name.Length();
+ memcpy(p + len, (const wchar_t *)name, name.Length() * sizeof(wchar_t));
+ for (i = index; i >= 0; i = parents[i])
+ {
+ const UString &s = Prefixes[i];
+ len -= s.Length();
+ memcpy(p + len, (const wchar_t *)s, s.Length() * sizeof(wchar_t));
+ }
+ path.ReleaseBuffer(totalLen);
+ return path;
+}
+
+UString CDirItems::GetPhyPath(int index) const
+{
+ const CDirItem &di = Items[index];
+ return GetPrefixesPath(PhyParents, di.PhyParent, di.Name);
+}
+
+UString CDirItems::GetLogPath(int index) const
+{
+ const CDirItem &di = Items[index];
+ return GetPrefixesPath(LogParents, di.LogParent, di.Name);
+}
+
+void CDirItems::ReserveDown()
+{
+ Prefixes.ReserveDown();
+ PhyParents.ReserveDown();
+ LogParents.ReserveDown();
+ Items.ReserveDown();
+}
+
+int CDirItems::AddPrefix(int phyParent, int logParent, const UString &prefix)
+{
+ PhyParents.Add(phyParent);
+ LogParents.Add(logParent);
+ return Prefixes.Add(prefix);
+}
+
+void CDirItems::DeleteLastPrefix()
+{
+ PhyParents.DeleteBack();
+ LogParents.DeleteBack();
+ Prefixes.DeleteBack();
+}
+
+void CDirItems::EnumerateDirectory(int phyParent, int logParent, const UString &phyPrefix,
+ UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes)
+{
+ NFind::CEnumeratorW enumerator(phyPrefix + (wchar_t)kAnyStringWildcard);
+ for (;;)
+ {
+ NFind::CFileInfoW fi;
+ bool found;
+ if (!enumerator.Next(fi, found))
+ {
+ errorCodes.Add(::GetLastError());
+ errorPaths.Add(phyPrefix);
+ return;
+ }
+ if (!found)
+ break;
+ AddDirFileInfo(phyParent, logParent, fi, Items);
+ if (fi.IsDir())
+ {
+ const UString name2 = fi.Name + (wchar_t)kDirDelimiter;
+ int parent = AddPrefix(phyParent, logParent, name2);
+ EnumerateDirectory(parent, parent, phyPrefix + name2, errorPaths, errorCodes);
+ }
+ }
+}
+
+void CDirItems::EnumerateDirItems2(const UString &phyPrefix, const UString &logPrefix,
+ const UStringVector &filePaths, UStringVector &errorPaths, CRecordVector<DWORD> &errorCodes)
+{
+ int phyParent = phyPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, phyPrefix);
+ int logParent = logPrefix.IsEmpty() ? -1 : AddPrefix(-1, -1, logPrefix);
+
+ for (int i = 0; i < filePaths.Size(); i++)
+ {
+ const UString &filePath = filePaths[i];
+ NFind::CFileInfoW fi;
+ const UString phyPath = phyPrefix + filePath;
+ if (!fi.Find(phyPath))
+ {
+ errorCodes.Add(::GetLastError());
+ errorPaths.Add(phyPath);
+ continue;
+ }
+ int delimiter = filePath.ReverseFind((wchar_t)kDirDelimiter);
+ UString phyPrefixCur;
+ int phyParentCur = phyParent;
+ if (delimiter >= 0)
+ {
+ phyPrefixCur = filePath.Left(delimiter + 1);
+ phyParentCur = AddPrefix(phyParent, logParent, phyPrefixCur);
+ }
+ AddDirFileInfo(phyParentCur, logParent, fi, Items);
+ if (fi.IsDir())
+ {
+ const UString name2 = fi.Name + (wchar_t)kDirDelimiter;
+ int parent = AddPrefix(phyParentCur, logParent, name2);
+ EnumerateDirectory(parent, parent, phyPrefix + phyPrefixCur + name2, errorPaths, errorCodes);
+ }
+ }
+ ReserveDown();
+}
+
+static HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,
+ int phyParent, int logParent, const UString &phyPrefix,
+ const UStringVector &addArchivePrefix,
+ CDirItems &dirItems,
+ bool enterToSubFolders,
+ IEnumDirItemCallback *callback,
+ UStringVector &errorPaths,
+ CRecordVector<DWORD> &errorCodes);
+
+static HRESULT EnumerateDirItems_Spec(const NWildcard::CCensorNode &curNode,
+ int phyParent, int logParent, const UString &curFolderName,
+ const UString &phyPrefix,
+ const UStringVector &addArchivePrefix,
+ CDirItems &dirItems,
+ bool enterToSubFolders,
+ IEnumDirItemCallback *callback,
+ UStringVector &errorPaths,
+ CRecordVector<DWORD> &errorCodes)
+
+{
+ const UString name2 = curFolderName + (wchar_t)kDirDelimiter;
+ int parent = dirItems.AddPrefix(phyParent, logParent, name2);
+ int numItems = dirItems.Items.Size();
+ HRESULT res = EnumerateDirItems(curNode, parent, parent, phyPrefix + name2,
+ addArchivePrefix, dirItems, enterToSubFolders, callback, errorPaths, errorCodes);
+ if (numItems == dirItems.Items.Size())
+ dirItems.DeleteLastPrefix();
+ return res;
+}
+
+
+static HRESULT EnumerateDirItems(const NWildcard::CCensorNode &curNode,
+ int phyParent, int logParent, const UString &phyPrefix,
+ const UStringVector &addArchivePrefix, // prefix from curNode
+ CDirItems &dirItems,
+ bool enterToSubFolders,
+ IEnumDirItemCallback *callback,
+ UStringVector &errorPaths,
+ CRecordVector<DWORD> &errorCodes)
+{
+ if (!enterToSubFolders)
+ if (curNode.NeedCheckSubDirs())
+ enterToSubFolders = true;
+ if (callback)
+ RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), phyPrefix));
+
+ // try direct_names case at first
+ if (addArchivePrefix.IsEmpty() && !enterToSubFolders)
+ {
+ // check that all names are direct
+ int i;
+ for (i = 0; i < curNode.IncludeItems.Size(); i++)
+ {
+ const NWildcard::CItem &item = curNode.IncludeItems[i];
+ if (item.Recursive || item.PathParts.Size() != 1)
+ break;
+ const UString &name = item.PathParts.Front();
+ if (name.IsEmpty() || DoesNameContainWildCard(name))
+ break;
+ }
+ if (i == curNode.IncludeItems.Size())
+ {
+ // all names are direct (no wildcards)
+ // so we don't need file_system's dir enumerator
+ CRecordVector<bool> needEnterVector;
+ for (i = 0; i < curNode.IncludeItems.Size(); i++)
+ {
+ const NWildcard::CItem &item = curNode.IncludeItems[i];
+ const UString &name = item.PathParts.Front();
+ const UString fullPath = phyPrefix + name;
+ NFind::CFileInfoW fi;
+ if (!fi.Find(fullPath))
+ {
+ errorCodes.Add(::GetLastError());
+ errorPaths.Add(fullPath);
+ continue;
+ }
+ bool isDir = fi.IsDir();
+ if (isDir && !item.ForDir || !isDir && !item.ForFile)
+ {
+ errorCodes.Add((DWORD)E_FAIL);
+ errorPaths.Add(fullPath);
+ continue;
+ }
+ {
+ UStringVector pathParts;
+ pathParts.Add(fi.Name);
+ if (curNode.CheckPathToRoot(false, pathParts, !isDir))
+ continue;
+ }
+ AddDirFileInfo(phyParent, logParent, fi, dirItems.Items);
+ if (!isDir)
+ continue;
+
+ UStringVector addArchivePrefixNew;
+ const NWildcard::CCensorNode *nextNode = 0;
+ int index = curNode.FindSubNode(name);
+ if (index >= 0)
+ {
+ for (int t = needEnterVector.Size(); t <= index; t++)
+ needEnterVector.Add(true);
+ needEnterVector[index] = false;
+ nextNode = &curNode.SubNodes[index];
+ }
+ else
+ {
+ nextNode = &curNode;
+ addArchivePrefixNew.Add(name); // don't change it to fi.Name. It's for shortnames support
+ }
+
+ RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, fi.Name, phyPrefix,
+ addArchivePrefixNew, dirItems, true, callback, errorPaths, errorCodes));
+ }
+ for (i = 0; i < curNode.SubNodes.Size(); i++)
+ {
+ if (i < needEnterVector.Size())
+ if (!needEnterVector[i])
+ continue;
+ const NWildcard::CCensorNode &nextNode = curNode.SubNodes[i];
+ const UString fullPath = phyPrefix + nextNode.Name;
+ NFind::CFileInfoW fi;
+ if (!fi.Find(fullPath))
+ {
+ if (!nextNode.AreThereIncludeItems())
+ continue;
+ errorCodes.Add(::GetLastError());
+ errorPaths.Add(fullPath);
+ continue;
+ }
+ if (!fi.IsDir())
+ {
+ errorCodes.Add((DWORD)E_FAIL);
+ errorPaths.Add(fullPath);
+ continue;
+ }
+
+ RINOK(EnumerateDirItems_Spec(nextNode, phyParent, logParent, fi.Name, phyPrefix,
+ UStringVector(), dirItems, false, callback, errorPaths, errorCodes));
+ }
+ return S_OK;
+ }
+ }
+
+
+ NFind::CEnumeratorW enumerator(phyPrefix + wchar_t(kAnyStringWildcard));
+ for (int ttt = 0; ; ttt++)
+ {
+ NFind::CFileInfoW fi;
+ bool found;
+ if (!enumerator.Next(fi, found))
+ {
+ errorCodes.Add(::GetLastError());
+ errorPaths.Add(phyPrefix);
+ break;
+ }
+ if (!found)
+ break;
+
+ if (callback && (ttt & 0xFF) == 0xFF)
+ RINOK(callback->ScanProgress(dirItems.GetNumFolders(), dirItems.Items.Size(), phyPrefix));
+ const UString &name = fi.Name;
+ bool enterToSubFolders2 = enterToSubFolders;
+ UStringVector addArchivePrefixNew = addArchivePrefix;
+ addArchivePrefixNew.Add(name);
+ {
+ UStringVector addArchivePrefixNewTemp(addArchivePrefixNew);
+ if (curNode.CheckPathToRoot(false, addArchivePrefixNewTemp, !fi.IsDir()))
+ continue;
+ }
+ if (curNode.CheckPathToRoot(true, addArchivePrefixNew, !fi.IsDir()))
+ {
+ AddDirFileInfo(phyParent, logParent, fi, dirItems.Items);
+ if (fi.IsDir())
+ enterToSubFolders2 = true;
+ }
+ if (!fi.IsDir())
+ continue;
+
+ const NWildcard::CCensorNode *nextNode = 0;
+ if (addArchivePrefix.IsEmpty())
+ {
+ int index = curNode.FindSubNode(name);
+ if (index >= 0)
+ nextNode = &curNode.SubNodes[index];
+ }
+ if (!enterToSubFolders2 && nextNode == 0)
+ continue;
+
+ addArchivePrefixNew = addArchivePrefix;
+ if (nextNode == 0)
+ {
+ nextNode = &curNode;
+ addArchivePrefixNew.Add(name);
+ }
+
+ RINOK(EnumerateDirItems_Spec(*nextNode, phyParent, logParent, name, phyPrefix,
+ addArchivePrefixNew, dirItems, enterToSubFolders2, callback, errorPaths, errorCodes));
+ }
+ return S_OK;
+}
+
+HRESULT EnumerateItems(
+ const NWildcard::CCensor &censor,
+ CDirItems &dirItems,
+ IEnumDirItemCallback *callback,
+ UStringVector &errorPaths,
+ CRecordVector<DWORD> &errorCodes)
+{
+ for (int i = 0; i < censor.Pairs.Size(); i++)
+ {
+ const NWildcard::CPair &pair = censor.Pairs[i];
+ int phyParent = pair.Prefix.IsEmpty() ? -1 : dirItems.AddPrefix(-1, -1, pair.Prefix);
+ RINOK(EnumerateDirItems(pair.Head, phyParent, -1, pair.Prefix, UStringVector(), dirItems, false,
+ callback, errorPaths, errorCodes));
+ }
+ dirItems.ReserveDown();
+ return S_OK;
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/EnumDirItems.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/EnumDirItems.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/EnumDirItems.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/EnumDirItems.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,25 @@
+// EnumDirItems.h
+
+#ifndef __ENUM_DIR_ITEMS_H
+#define __ENUM_DIR_ITEMS_H
+
+#include "Common/Wildcard.h"
+#include "Windows/FileFind.h"
+#include "DirItem.h"
+
+void AddDirFileInfo(int phyParent, int logParent,
+ const NWindows::NFile::NFind::CFileInfoW &fi, CObjectVector<CDirItem> &dirItems);
+
+struct IEnumDirItemCallback
+{
+ virtual HRESULT ScanProgress(UInt64 numFolders, UInt64 numFiles, const wchar_t *path) = 0;
+};
+
+HRESULT EnumerateItems(
+ const NWildcard::CCensor &censor,
+ CDirItems &dirItems,
+ IEnumDirItemCallback *callback,
+ UStringVector &errorPaths,
+ CRecordVector<DWORD> &errorCodes);
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExitCode.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExitCode.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExitCode.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExitCode.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,27 @@
+// ExitCode.h
+
+#ifndef __EXIT_CODE_H
+#define __EXIT_CODE_H
+
+namespace NExitCode {
+
+enum EEnum {
+
+ kSuccess = 0, // Successful operation
+ kWarning = 1, // Non fatal error(s) occurred
+ kFatalError = 2, // A fatal error occurred
+ // kCRCError = 3, // A CRC error occurred when unpacking
+ // kLockedArchive = 4, // Attempt to modify an archive previously locked
+ // kWriteError = 5, // Write to disk error
+ // kOpenError = 6, // Open file error
+ kUserError = 7, // Command line option error
+ kMemoryError = 8, // Not enough memory for operation
+ // kCreateFileError = 9, // Create file error
+
+ kUserBreak = 255 // User stopped the process
+
+};
+
+}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Extract.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Extract.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Extract.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Extract.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,263 @@
+// Extract.cpp
+
+#include "StdAfx.h"
+
+#include <stdio.h>
+
+#include "Windows/FileDir.h"
+#include "Windows/PropVariant.h"
+#include "Windows/PropVariantConversions.h"
+
+#include "../Common/ExtractingFilePath.h"
+
+#include "Extract.h"
+#include "SetProperties.h"
+
+using namespace NWindows;
+
+static HRESULT DecompressArchive(
+ const CArc &arc,
+ UInt64 packSize,
+ const NWildcard::CCensorNode &wildcardCensor,
+ const CExtractOptions &options,
+ IExtractCallbackUI *callback,
+ CArchiveExtractCallback *extractCallbackSpec,
+ UString &errorMessage,
+ UInt64 &stdInProcessed)
+{
+ stdInProcessed = 0;
+ IInArchive *archive = arc.Archive;
+ CRecordVector<UInt32> realIndices;
+ if (!options.StdInMode)
+ {
+ UInt32 numItems;
+ RINOK(archive->GetNumberOfItems(&numItems));
+
+ for (UInt32 i = 0; i < numItems; i++)
+ {
+ UString filePath;
+ RINOK(arc.GetItemPath(i, filePath));
+ bool isFolder;
+ RINOK(IsArchiveItemFolder(archive, i, isFolder));
+ if (!wildcardCensor.CheckPath(filePath, !isFolder))
+ continue;
+ realIndices.Add(i);
+ }
+ if (realIndices.Size() == 0)
+ {
+ callback->ThereAreNoFiles();
+ return S_OK;
+ }
+ }
+
+ UStringVector removePathParts;
+
+ UString outDir = options.OutputDir;
+ outDir.Replace(L"*", GetCorrectFsPath(arc.DefaultName));
+ #ifdef _WIN32
+ // GetCorrectFullFsPath doesn't like "..".
+ // outDir.TrimRight();
+ // outDir = GetCorrectFullFsPath(outDir);
+ #endif
+
+ if (!outDir.IsEmpty())
+ if (!NFile::NDirectory::CreateComplexDirectory(outDir))
+ {
+ HRESULT res = ::GetLastError();
+ if (res == S_OK)
+ res = E_FAIL;
+ errorMessage = ((UString)L"Can not create output directory ") + outDir;
+ return res;
+ }
+
+ extractCallbackSpec->Init(
+ options.StdInMode ? &wildcardCensor : NULL,
+ &arc,
+ callback,
+ options.StdOutMode, options.TestMode, options.CalcCrc,
+ outDir,
+ removePathParts,
+ packSize);
+
+ #if !defined(_7ZIP_ST) && !defined(_SFX)
+ RINOK(SetProperties(archive, options.Properties));
+ #endif
+
+ HRESULT result;
+ Int32 testMode = (options.TestMode && !options.CalcCrc) ? 1: 0;
+ if (options.StdInMode)
+ {
+ result = archive->Extract(NULL, (UInt32)(Int32)-1, testMode, extractCallbackSpec);
+ NCOM::CPropVariant prop;
+ if (archive->GetArchiveProperty(kpidPhySize, &prop) == S_OK)
+ if (prop.vt == VT_UI8 || prop.vt == VT_UI4)
+ stdInProcessed = ConvertPropVariantToUInt64(prop);
+ }
+ else
+ result = archive->Extract(&realIndices.Front(), realIndices.Size(), testMode, extractCallbackSpec);
+
+ return callback->ExtractResult(result);
+}
+
+HRESULT DecompressArchives(
+ CCodecs *codecs, const CIntVector &formatIndices,
+ UStringVector &arcPaths, UStringVector &arcPathsFull,
+ const NWildcard::CCensorNode &wildcardCensor,
+ const CExtractOptions &options,
+ IOpenCallbackUI *openCallback,
+ IExtractCallbackUI *extractCallback,
+ UString &errorMessage,
+ CDecompressStat &stat)
+{
+ stat.Clear();
+ int i;
+ UInt64 totalPackSize = 0;
+ CRecordVector<UInt64> archiveSizes;
+
+ int numArcs = options.StdInMode ? 1 : arcPaths.Size();
+
+ for (i = 0; i < numArcs; i++)
+ {
+ NFile::NFind::CFileInfoW fi;
+ fi.Size = 0;
+ if (!options.StdInMode)
+ {
+ const UString &arcPath = arcPaths[i];
+ if (!fi.Find(arcPath))
+ throw "there is no such archive";
+ if (fi.IsDir())
+ throw "can't decompress folder";
+ }
+ archiveSizes.Add(fi.Size);
+ totalPackSize += fi.Size;
+ }
+ CArchiveExtractCallback *extractCallbackSpec = new CArchiveExtractCallback;
+ CMyComPtr<IArchiveExtractCallback> ec(extractCallbackSpec);
+ bool multi = (numArcs > 1);
+ extractCallbackSpec->InitForMulti(multi, options.PathMode, options.OverwriteMode);
+ if (multi)
+ {
+ RINOK(extractCallback->SetTotal(totalPackSize));
+ }
+ for (i = 0; i < numArcs; i++)
+ {
+ const UString &arcPath = arcPaths[i];
+ NFile::NFind::CFileInfoW fi;
+ if (options.StdInMode)
+ {
+ fi.Size = 0;
+ fi.Attrib = 0;
+ }
+ else
+ {
+ if (!fi.Find(arcPath) || fi.IsDir())
+ throw "there is no such archive";
+ }
+
+ #ifndef _NO_CRYPTO
+ openCallback->Open_ClearPasswordWasAskedFlag();
+ #endif
+
+ RINOK(extractCallback->BeforeOpen(arcPath));
+ CArchiveLink archiveLink;
+
+ CIntVector formatIndices2 = formatIndices;
+ #ifndef _SFX
+ if (formatIndices.IsEmpty())
+ {
+ int pos = arcPath.ReverseFind(L'.');
+ if (pos >= 0)
+ {
+ UString s = arcPath.Mid(pos + 1);
+ int index = codecs->FindFormatForExtension(s);
+ if (index >= 0 && s == L"001")
+ {
+ s = arcPath.Left(pos);
+ pos = s.ReverseFind(L'.');
+ if (pos >= 0)
+ {
+ int index2 = codecs->FindFormatForExtension(s.Mid(pos + 1));
+ if (index2 >= 0 && s.CompareNoCase(L"rar") != 0)
+ {
+ formatIndices2.Add(index2);
+ formatIndices2.Add(index);
+ }
+ }
+ }
+ }
+ }
+ #endif
+ HRESULT result = archiveLink.Open2(codecs, formatIndices2, options.StdInMode, NULL, arcPath, openCallback);
+ if (result == E_ABORT)
+ return result;
+
+ bool crypted = false;
+ #ifndef _NO_CRYPTO
+ crypted = openCallback->Open_WasPasswordAsked();
+ #endif
+
+ RINOK(extractCallback->OpenResult(arcPath, result, crypted));
+ if (result != S_OK)
+ continue;
+
+ if (!options.StdInMode)
+ for (int v = 0; v < archiveLink.VolumePaths.Size(); v++)
+ {
+ int index = arcPathsFull.FindInSorted(archiveLink.VolumePaths[v]);
+ if (index >= 0 && index > i)
+ {
+ arcPaths.Delete(index);
+ arcPathsFull.Delete(index);
+ totalPackSize -= archiveSizes[index];
+ archiveSizes.Delete(index);
+ numArcs = arcPaths.Size();
+ }
+ }
+ if (archiveLink.VolumePaths.Size() != 0)
+ {
+ totalPackSize += archiveLink.VolumesSize;
+ RINOK(extractCallback->SetTotal(totalPackSize));
+ }
+
+ #ifndef _NO_CRYPTO
+ UString password;
+ RINOK(openCallback->Open_GetPasswordIfAny(password));
+ if (!password.IsEmpty())
+ {
+ RINOK(extractCallback->SetPassword(password));
+ }
+ #endif
+
+ for (int v = 0; v < archiveLink.Arcs.Size(); v++)
+ {
+ const UString &s = archiveLink.Arcs[v].ErrorMessage;
+ if (!s.IsEmpty())
+ {
+ RINOK(extractCallback->MessageError(s));
+ }
+ }
+
+ CArc &arc = archiveLink.Arcs.Back();
+ arc.MTimeDefined = (!options.StdInMode && !fi.IsDevice);
+ arc.MTime = fi.MTime;
+
+ UInt64 packProcessed;
+ RINOK(DecompressArchive(arc,
+ fi.Size + archiveLink.VolumesSize,
+ wildcardCensor, options, extractCallback, extractCallbackSpec, errorMessage, packProcessed));
+ if (!options.StdInMode)
+ packProcessed = fi.Size + archiveLink.VolumesSize;
+ extractCallbackSpec->LocalProgressSpec->InSize += packProcessed;
+ extractCallbackSpec->LocalProgressSpec->OutSize = extractCallbackSpec->UnpackSize;
+ if (!errorMessage.IsEmpty())
+ return E_FAIL;
+ }
+ stat.NumFolders = extractCallbackSpec->NumFolders;
+ stat.NumFiles = extractCallbackSpec->NumFiles;
+ stat.UnpackSize = extractCallbackSpec->UnpackSize;
+ stat.CrcSum = extractCallbackSpec->CrcSum;
+
+ stat.NumArchives = arcPaths.Size();
+ stat.PackSize = extractCallbackSpec->LocalProgressSpec->InSize;
+ return S_OK;
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Extract.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Extract.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Extract.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Extract.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,76 @@
+// Extract.h
+
+#ifndef __EXTRACT_H
+#define __EXTRACT_H
+
+#include "Windows/FileFind.h"
+
+#include "../../Archive/IArchive.h"
+
+#include "ArchiveExtractCallback.h"
+#include "ArchiveOpenCallback.h"
+#include "ExtractMode.h"
+#include "Property.h"
+
+#include "../Common/LoadCodecs.h"
+
+struct CExtractOptions
+{
+ bool StdInMode;
+ bool StdOutMode;
+ bool YesToAll;
+ bool TestMode;
+ bool CalcCrc;
+ NExtract::NPathMode::EEnum PathMode;
+ NExtract::NOverwriteMode::EEnum OverwriteMode;
+ UString OutputDir;
+
+ // bool ShowDialog;
+ // bool PasswordEnabled;
+ // UString Password;
+ #if !defined(_7ZIP_ST) && !defined(_SFX)
+ CObjectVector<CProperty> Properties;
+ #endif
+
+ #ifdef EXTERNAL_CODECS
+ CCodecs *Codecs;
+ #endif
+
+ CExtractOptions():
+ StdInMode(false),
+ StdOutMode(false),
+ YesToAll(false),
+ TestMode(false),
+ CalcCrc(false),
+ PathMode(NExtract::NPathMode::kFullPathnames),
+ OverwriteMode(NExtract::NOverwriteMode::kAskBefore)
+ {}
+};
+
+struct CDecompressStat
+{
+ UInt64 NumArchives;
+ UInt64 UnpackSize;
+ UInt64 PackSize;
+ UInt64 NumFolders;
+ UInt64 NumFiles;
+ UInt32 CrcSum;
+
+ void Clear()
+ {
+ NumArchives = UnpackSize = PackSize = NumFolders = NumFiles = 0;
+ CrcSum = 0;
+ }
+};
+
+HRESULT DecompressArchives(
+ CCodecs *codecs, const CIntVector &formatIndices,
+ UStringVector &archivePaths, UStringVector &archivePathsFull,
+ const NWildcard::CCensorNode &wildcardCensor,
+ const CExtractOptions &options,
+ IOpenCallbackUI *openCallback,
+ IExtractCallbackUI *extractCallback,
+ UString &errorMessage,
+ CDecompressStat &stat);
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExtractMode.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExtractMode.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExtractMode.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExtractMode.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,31 @@
+// ExtractMode.h
+
+#ifndef __EXTRACT_MODE_H
+#define __EXTRACT_MODE_H
+
+namespace NExtract {
+
+ namespace NPathMode
+ {
+ enum EEnum
+ {
+ kFullPathnames,
+ kCurrentPathnames,
+ kNoPathnames
+ };
+ }
+
+ namespace NOverwriteMode
+ {
+ enum EEnum
+ {
+ kAskBefore,
+ kWithoutPrompt,
+ kSkipExisting,
+ kAutoRename,
+ kAutoRenameExisting
+ };
+ }
+}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExtractingFilePath.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExtractingFilePath.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExtractingFilePath.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExtractingFilePath.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,142 @@
+// ExtractingFilePath.cpp
+
+#include "StdAfx.h"
+
+#include "../../../../C/Types.h"
+
+#include "Common/Wildcard.h"
+
+#include "ExtractingFilePath.h"
+
+static UString ReplaceIncorrectChars(const UString &s)
+{
+ #ifdef _WIN32
+ UString res;
+ for (int i = 0; i < s.Length(); i++)
+ {
+ wchar_t c = s[i];
+ if (c < 0x20 || c == '*' || c == '?' || c == '<' || c == '>' || c == '|' || c == ':' || c == '"')
+ c = '_';
+ res += c;
+ }
+ res.TrimRight();
+ while (!res.IsEmpty() && res[res.Length() - 1] == '.')
+ res.Delete(res.Length() - 1);
+ return res;
+ #else
+ return s;
+ #endif
+}
+
+#ifdef _WIN32
+static const wchar_t *g_ReservedNames[] =
+{
+ L"CON", L"PRN", L"AUX", L"NUL"
+};
+
+static bool CheckTail(const UString &name, int len)
+{
+ int dotPos = name.Find(L'.');
+ if (dotPos < 0)
+ dotPos = name.Length();
+ UString s = name.Left(dotPos);
+ s.TrimRight();
+ return (s.Length() != len);
+}
+
+static bool CheckNameNum(const UString &name, const wchar_t *reservedName)
+{
+ int len = MyStringLen(reservedName);
+ if (name.Length() <= len)
+ return true;
+ if (name.Left(len).CompareNoCase(reservedName) != 0)
+ return true;
+ wchar_t c = name[len];
+ if (c < L'0' || c > L'9')
+ return true;
+ return CheckTail(name, len + 1);
+}
+
+static bool IsSupportedName(const UString &name)
+{
+ for (int i = 0; i < sizeof(g_ReservedNames) / sizeof(g_ReservedNames[0]); i++)
+ {
+ const wchar_t *reservedName = g_ReservedNames[i];
+ int len = MyStringLen(reservedName);
+ if (name.Length() < len)
+ continue;
+ if (name.Left(len).CompareNoCase(reservedName) != 0)
+ continue;
+ if (!CheckTail(name, len))
+ return false;
+ }
+ if (!CheckNameNum(name, L"COM"))
+ return false;
+ return CheckNameNum(name, L"LPT");
+}
+#endif
+
+static UString GetCorrectFileName(const UString &path)
+{
+ if (path == L".." || path == L".")
+ return UString();
+ return ReplaceIncorrectChars(path);
+}
+
+void MakeCorrectPath(UStringVector &pathParts)
+{
+ for (int i = 0; i < pathParts.Size();)
+ {
+ UString &s = pathParts[i];
+ s = GetCorrectFileName(s);
+ if (s.IsEmpty())
+ pathParts.Delete(i);
+ else
+ {
+ #ifdef _WIN32
+ if (!IsSupportedName(s))
+ s = (UString)L"_" + s;
+ #endif
+ i++;
+ }
+ }
+}
+
+UString MakePathNameFromParts(const UStringVector &parts)
+{
+ UString result;
+ for (int i = 0; i < parts.Size(); i++)
+ {
+ if (i != 0)
+ result += WCHAR_PATH_SEPARATOR;
+ result += parts[i];
+ }
+ return result;
+}
+
+UString GetCorrectFsPath(const UString &path)
+{
+ UString res = GetCorrectFileName(path);
+ #ifdef _WIN32
+ if (!IsSupportedName(res))
+ res = (UString)L"_" + res;
+ #endif
+ return res;
+}
+
+UString GetCorrectFullFsPath(const UString &path)
+{
+ UStringVector parts;
+ SplitPathToParts(path, parts);
+ for (int i = 0; i < parts.Size(); i++)
+ {
+ UString &s = parts[i];
+ #ifdef _WIN32
+ while (!s.IsEmpty() && s[s.Length() - 1] == '.')
+ s.Delete(s.Length() - 1);
+ if (!IsSupportedName(s))
+ s = (UString)L"_" + s;
+ #endif
+ }
+ return MakePathNameFromParts(parts);
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExtractingFilePath.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExtractingFilePath.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExtractingFilePath.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/ExtractingFilePath.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,13 @@
+// ExtractingFilePath.h
+
+#ifndef __EXTRACTING_FILE_PATH_H
+#define __EXTRACTING_FILE_PATH_H
+
+#include "Common/MyString.h"
+
+UString MakePathNameFromParts(const UStringVector &parts);
+void MakeCorrectPath(UStringVector &pathParts);
+UString GetCorrectFsPath(const UString &path);
+UString GetCorrectFullFsPath(const UString &path);
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/IFileExtractCallback.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/IFileExtractCallback.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/IFileExtractCallback.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/IFileExtractCallback.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,46 @@
+// IFileExtractCallback.h
+
+#ifndef __IFILEEXTRACTCALLBACK_H
+#define __IFILEEXTRACTCALLBACK_H
+
+#include "Common/MyString.h"
+#include "../../IDecl.h"
+
+namespace NOverwriteAnswer
+{
+ enum EEnum
+ {
+ kYes,
+ kYesToAll,
+ kNo,
+ kNoToAll,
+ kAutoRename,
+ kCancel
+ };
+}
+
+DECL_INTERFACE_SUB(IFolderArchiveExtractCallback, IProgress, 0x01, 0x07)
+{
+public:
+ STDMETHOD(AskOverwrite)(
+ const wchar_t *existName, const FILETIME *existTime, const UInt64 *existSize,
+ const wchar_t *newName, const FILETIME *newTime, const UInt64 *newSize,
+ Int32 *answer) PURE;
+ STDMETHOD(PrepareOperation)(const wchar_t *name, bool isFolder, Int32 askExtractMode, const UInt64 *position) PURE;
+ STDMETHOD(MessageError)(const wchar_t *message) PURE;
+ STDMETHOD(SetOperationResult)(Int32 operationResult, bool encrypted) PURE;
+};
+
+struct IExtractCallbackUI: IFolderArchiveExtractCallback
+{
+ virtual HRESULT BeforeOpen(const wchar_t *name) = 0;
+ virtual HRESULT OpenResult(const wchar_t *name, HRESULT result, bool encrypted) = 0;
+ virtual HRESULT ThereAreNoFiles() = 0;
+ virtual HRESULT ExtractResult(HRESULT result) = 0;
+
+ #ifndef _NO_CRYPTO
+ virtual HRESULT SetPassword(const UString &password) = 0;
+ #endif
+};
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/LoadCodecs.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/LoadCodecs.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/LoadCodecs.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/LoadCodecs.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,716 @@
+// LoadCodecs.cpp
+
+#include "StdAfx.h"
+
+#include "LoadCodecs.h"
+
+#include "../../../Common/MyCom.h"
+#ifdef NEW_FOLDER_INTERFACE
+#include "../../../Common/StringToInt.h"
+#endif
+#include "../../../Windows/PropVariant.h"
+
+#include "../../ICoder.h"
+#include "../../Common/RegisterArc.h"
+
+#ifdef EXTERNAL_CODECS
+#include "../../../Windows/FileFind.h"
+#include "../../../Windows/DLL.h"
+#ifdef NEW_FOLDER_INTERFACE
+#include "../../../Windows/ResourceString.h"
+static const UINT kIconTypesResId = 100;
+#endif
+
+#ifdef _WIN32
+#include "Windows/Registry.h"
+#else
+#include "Common/StringConvert.h"
+#endif
+
+using namespace NWindows;
+using namespace NFile;
+
+#ifdef _WIN32
+extern HINSTANCE g_hInstance;
+#endif
+
+static CSysString GetLibraryFolderPrefix()
+{
+ #ifdef _WIN32
+ TCHAR fullPath[MAX_PATH + 1];
+ ::GetModuleFileName(g_hInstance, fullPath, MAX_PATH);
+ CSysString path = fullPath;
+ int pos = path.ReverseFind(TEXT(CHAR_PATH_SEPARATOR));
+ return path.Left(pos + 1);
+ #else
+ const char *p7zip_home_dir = getenv("P7ZIP_HOME_DIR");
+ if (p7zip_home_dir == 0) p7zip_home_dir="./";
+#ifdef _UNICODE
+ return MultiByteToUnicodeString(p7zip_home_dir);
+#else
+ return p7zip_home_dir;
+#endif
+ #endif
+}
+
+#define kCodecsFolderName TEXT("Codecs")
+#define kFormatsFolderName TEXT("Formats")
+static const TCHAR *kMainDll = TEXT("7z.dll");
+
+#ifdef _WIN32
+static LPCTSTR kRegistryPath = TEXT("Software") TEXT(STRING_PATH_SEPARATOR) TEXT("7-zip");
+static LPCTSTR kProgramPathValue = TEXT("Path");
+static bool ReadPathFromRegistry(HKEY baseKey, CSysString &path)
+{
+ NRegistry::CKey key;
+ if(key.Open(baseKey, kRegistryPath, KEY_READ) == ERROR_SUCCESS)
+ if (key.QueryValue(kProgramPathValue, path) == ERROR_SUCCESS)
+ {
+ NName::NormalizeDirPathPrefix(path);
+ return true;
+ }
+ return false;
+}
+
+#endif
+
+CSysString GetBaseFolderPrefixFromRegistry()
+{
+ CSysString moduleFolderPrefix = GetLibraryFolderPrefix();
+#ifdef _UNICODE
+ NFind::CFileInfoW fi;
+#else
+ NFind::CFileInfo fi;
+#endif
+ if (NFind::FindFile(moduleFolderPrefix + kMainDll, fi))
+ if (!fi.IsDir())
+ return moduleFolderPrefix;
+ if (NFind::FindFile(moduleFolderPrefix + kCodecsFolderName, fi))
+ if (fi.IsDir())
+ return moduleFolderPrefix;
+ if (NFind::FindFile(moduleFolderPrefix + kFormatsFolderName, fi))
+ if (fi.IsDir())
+ return moduleFolderPrefix;
+ #ifdef _WIN32
+ if (!NFind::DoesFileExist(moduleFolderPrefix + kMainDll) &&
+ !NFind::DoesDirExist(moduleFolderPrefix + kCodecsFolderName) &&
+ !NFind::DoesDirExist(moduleFolderPrefix + kFormatsFolderName))
+ {
+ CSysString path;
+ if (ReadPathFromRegistry(HKEY_CURRENT_USER, path))
+ return path;
+ if (ReadPathFromRegistry(HKEY_LOCAL_MACHINE, path))
+ return path;
+ }
+ #endif
+ return moduleFolderPrefix;
+}
+
+typedef UInt32 (WINAPI *GetNumberOfMethodsFunc)(UInt32 *numMethods);
+typedef UInt32 (WINAPI *GetNumberOfFormatsFunc)(UInt32 *numFormats);
+typedef UInt32 (WINAPI *GetHandlerPropertyFunc)(PROPID propID, PROPVARIANT *value);
+typedef UInt32 (WINAPI *GetHandlerPropertyFunc2)(UInt32 index, PROPID propID, PROPVARIANT *value);
+typedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *iid, void **outObject);
+typedef UInt32 (WINAPI *SetLargePageModeFunc)();
+
+
+static HRESULT GetCoderClass(GetMethodPropertyFunc getMethodProperty, UInt32 index,
+ PROPID propId, CLSID &clsId, bool &isAssigned)
+{
+ NWindows::NCOM::CPropVariant prop;
+ isAssigned = false;
+ RINOK(getMethodProperty(index, propId, &prop));
+ if (prop.vt == VT_BSTR)
+ {
+ isAssigned = true;
+ clsId = *(const GUID *)prop.bstrVal;
+ }
+ else if (prop.vt != VT_EMPTY)
+ return E_FAIL;
+ return S_OK;
+}
+
+HRESULT CCodecs::LoadCodecs()
+{
+ CCodecLib &lib = Libs.Back();
+ lib.GetMethodProperty = (GetMethodPropertyFunc)lib.Lib.GetProc("GetMethodProperty");
+ if (lib.GetMethodProperty == NULL)
+ return S_OK;
+
+ UInt32 numMethods = 1;
+ GetNumberOfMethodsFunc getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)lib.Lib.GetProc("GetNumberOfMethods");
+ if (getNumberOfMethodsFunc != NULL)
+ {
+ RINOK(getNumberOfMethodsFunc(&numMethods));
+ }
+
+ for(UInt32 i = 0; i < numMethods; i++)
+ {
+ CDllCodecInfo info;
+ info.LibIndex = Libs.Size() - 1;
+ info.CodecIndex = i;
+
+ RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kEncoder, info.Encoder, info.EncoderIsAssigned));
+ RINOK(GetCoderClass(lib.GetMethodProperty, i, NMethodPropID::kDecoder, info.Decoder, info.DecoderIsAssigned));
+
+ Codecs.Add(info);
+ }
+ return S_OK;
+}
+
+static HRESULT ReadProp(
+ GetHandlerPropertyFunc getProp,
+ GetHandlerPropertyFunc2 getProp2,
+ UInt32 index, PROPID propID, NCOM::CPropVariant &prop)
+{
+ if (getProp2)
+ return getProp2(index, propID, &prop);;
+ return getProp(propID, &prop);
+}
+
+static HRESULT ReadBoolProp(
+ GetHandlerPropertyFunc getProp,
+ GetHandlerPropertyFunc2 getProp2,
+ UInt32 index, PROPID propID, bool &res)
+{
+ NCOM::CPropVariant prop;
+ RINOK(ReadProp(getProp, getProp2, index, propID, prop));
+ if (prop.vt == VT_BOOL)
+ res = VARIANT_BOOLToBool(prop.boolVal);
+ else if (prop.vt != VT_EMPTY)
+ return E_FAIL;
+ return S_OK;
+}
+
+static HRESULT ReadStringProp(
+ GetHandlerPropertyFunc getProp,
+ GetHandlerPropertyFunc2 getProp2,
+ UInt32 index, PROPID propID, UString &res)
+{
+ NCOM::CPropVariant prop;
+ RINOK(ReadProp(getProp, getProp2, index, propID, prop));
+ if (prop.vt == VT_BSTR)
+ res = prop.bstrVal;
+ else if (prop.vt != VT_EMPTY)
+ return E_FAIL;
+ return S_OK;
+}
+
+#endif
+
+static const unsigned int kNumArcsMax = 48;
+static unsigned int g_NumArcs = 0;
+static const CArcInfo *g_Arcs[kNumArcsMax];
+void RegisterArc(const CArcInfo *arcInfo)
+{
+ if (g_NumArcs < kNumArcsMax)
+ g_Arcs[g_NumArcs++] = arcInfo;
+}
+
+static void SplitString(const UString &srcString, UStringVector &destStrings)
+{
+ destStrings.Clear();
+ UString s;
+ int len = srcString.Length();
+ if (len == 0)
+ return;
+ for (int i = 0; i < len; i++)
+ {
+ wchar_t c = srcString[i];
+ if (c == L' ')
+ {
+ if (!s.IsEmpty())
+ {
+ destStrings.Add(s);
+ s.Empty();
+ }
+ }
+ else
+ s += c;
+ }
+ if (!s.IsEmpty())
+ destStrings.Add(s);
+}
+
+void CArcInfoEx::AddExts(const wchar_t *ext, const wchar_t *addExt)
+{
+ UStringVector exts, addExts;
+ if (ext != 0)
+ SplitString(ext, exts);
+ if (addExt != 0)
+ SplitString(addExt, addExts);
+ for (int i = 0; i < exts.Size(); i++)
+ {
+ CArcExtInfo extInfo;
+ extInfo.Ext = exts[i];
+ if (i < addExts.Size())
+ {
+ extInfo.AddExt = addExts[i];
+ if (extInfo.AddExt == L"*")
+ extInfo.AddExt.Empty();
+ }
+ Exts.Add(extInfo);
+ }
+}
+
+#ifdef EXTERNAL_CODECS
+
+HRESULT CCodecs::LoadFormats()
+{
+ const NDLL::CLibrary &lib = Libs.Back().Lib;
+ GetHandlerPropertyFunc getProp = 0;
+ GetHandlerPropertyFunc2 getProp2 = (GetHandlerPropertyFunc2)lib.GetProc("GetHandlerProperty2");
+ if (getProp2 == NULL)
+ {
+ getProp = (GetHandlerPropertyFunc)lib.GetProc("GetHandlerProperty");
+ if (getProp == NULL)
+ return S_OK;
+ }
+
+ UInt32 numFormats = 1;
+ GetNumberOfFormatsFunc getNumberOfFormats = (GetNumberOfFormatsFunc)lib.GetProc("GetNumberOfFormats");
+ if (getNumberOfFormats != NULL)
+ {
+ RINOK(getNumberOfFormats(&numFormats));
+ }
+ if (getProp2 == NULL)
+ numFormats = 1;
+
+ for(UInt32 i = 0; i < numFormats; i++)
+ {
+ CArcInfoEx item;
+ item.LibIndex = Libs.Size() - 1;
+ item.FormatIndex = i;
+
+ RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kName, item.Name));
+
+ NCOM::CPropVariant prop;
+ if (ReadProp(getProp, getProp2, i, NArchive::kClassID, prop) != S_OK)
+ continue;
+ if (prop.vt != VT_BSTR)
+ continue;
+ item.ClassID = *(const GUID *)prop.bstrVal;
+ prop.Clear();
+
+ UString ext, addExt;
+ RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kExtension, ext));
+ RINOK(ReadStringProp(getProp, getProp2, i, NArchive::kAddExtension, addExt));
+ item.AddExts(ext, addExt);
+
+ ReadBoolProp(getProp, getProp2, i, NArchive::kUpdate, item.UpdateEnabled);
+ if (item.UpdateEnabled)
+ ReadBoolProp(getProp, getProp2, i, NArchive::kKeepName, item.KeepName);
+
+ if (ReadProp(getProp, getProp2, i, NArchive::kStartSignature, prop) == S_OK)
+ if (prop.vt == VT_BSTR)
+ {
+ UINT len = ::SysStringByteLen(prop.bstrVal);
+ item.StartSignature.SetCapacity(len);
+ memmove((Byte *)item.StartSignature, prop.bstrVal, len);
+ }
+ Formats.Add(item);
+ }
+ return S_OK;
+}
+
+#ifdef NEW_FOLDER_INTERFACE
+void CCodecIcons::LoadIcons(HMODULE m)
+{
+#ifdef _WIN32
+ UString iconTypes = MyLoadStringW(m, kIconTypesResId);
+ UStringVector pairs;
+ SplitString(iconTypes, pairs);
+ for (int i = 0; i < pairs.Size(); i++)
+ {
+ const UString &s = pairs[i];
+ int pos = s.Find(L':');
+ CIconPair iconPair;
+ iconPair.IconIndex = -1;
+ if (pos < 0)
+ pos = s.Length();
+ else
+ {
+ UString num = s.Mid(pos + 1);
+ if (!num.IsEmpty())
+ {
+ const wchar_t *end;
+ iconPair.IconIndex = (UInt32)ConvertStringToUInt64(num, &end);
+ if (*end != L'\0')
+ continue;
+ }
+ }
+ iconPair.Ext = s.Left(pos);
+ IconPairs.Add(iconPair);
+ }
+#endif // #ifdef _WIN32
+}
+
+bool CCodecIcons::FindIconIndex(const UString &ext, int &iconIndex) const
+{
+#ifdef _WIN32
+ iconIndex = -1;
+ for (int i = 0; i < IconPairs.Size(); i++)
+ {
+ const CIconPair &pair = IconPairs[i];
+ if (ext.CompareNoCase(pair.Ext) == 0)
+ {
+ iconIndex = pair.IconIndex;
+ return true;
+ }
+ }
+#endif // #ifdef _WIN32
+ return false;
+}
+#endif
+
+#ifdef _7ZIP_LARGE_PAGES
+extern "C"
+{
+ extern size_t g_LargePageSize;
+}
+#endif
+
+HRESULT CCodecs::LoadDll(const CSysString &dllPath, bool needCheckDll)
+{
+#ifdef _WIN32
+ if (needCheckDll)
+ {
+ NDLL::CLibrary library;
+ if (!library.LoadEx(dllPath, LOAD_LIBRARY_AS_DATAFILE))
+ return S_OK;
+ }
+#endif
+ Libs.Add(CCodecLib());
+ CCodecLib &lib = Libs.Back();
+ #ifdef NEW_FOLDER_INTERFACE
+ lib.Path = dllPath;
+ #endif
+ bool used = false;
+ HRESULT res = S_OK;
+ if (lib.Lib.Load(dllPath))
+ {
+ #ifdef NEW_FOLDER_INTERFACE
+ lib.LoadIcons();
+ #endif
+
+ #ifdef _7ZIP_LARGE_PAGES
+ if (g_LargePageSize != 0)
+ {
+ SetLargePageModeFunc setLargePageMode = (SetLargePageModeFunc)lib.Lib.GetProc("SetLargePageMode");
+ if (setLargePageMode != 0)
+ setLargePageMode();
+ }
+ #endif
+
+ lib.CreateObject = (CreateObjectFunc)lib.Lib.GetProc("CreateObject");
+ if (lib.CreateObject != 0)
+ {
+ int startSize = Codecs.Size();
+ res = LoadCodecs();
+ used = (Codecs.Size() != startSize);
+ if (res == S_OK)
+ {
+ startSize = Formats.Size();
+ res = LoadFormats();
+ used = used || (Formats.Size() != startSize);
+ }
+ }
+ }
+ if (!used)
+ Libs.DeleteBack();
+ return res;
+}
+
+HRESULT CCodecs::LoadDllsFromFolder(const CSysString &folderPrefix)
+{
+#ifdef _UNICODE
+ NFile::NFind::CEnumeratorW enumerator(folderPrefix + CSysString(TEXT("*")));
+ NFile::NFind::CFileInfoW fi;
+#else
+ NFile::NFind::CEnumerator enumerator(folderPrefix + CSysString(TEXT("*")));
+ NFile::NFind::CFileInfo fi;
+#endif
+ while (enumerator.Next(fi))
+ {
+ if (fi.IsDir())
+ continue;
+ RINOK(LoadDll(folderPrefix + fi.Name, true));
+ }
+ return S_OK;
+}
+
+#endif
+
+#ifndef _SFX
+static inline void SetBuffer(CByteBuffer &bb, const Byte *data, int size)
+{
+ bb.SetCapacity(size);
+ memmove((Byte *)bb, data, size);
+}
+#endif
+
+HRESULT CCodecs::Load()
+{
+ #ifdef NEW_FOLDER_INTERFACE
+ #ifdef _WIN32
+ InternalIcons.LoadIcons(g_hInstance);
+ #endif
+ #endif
+
+ Formats.Clear();
+ #ifdef EXTERNAL_CODECS
+ Codecs.Clear();
+ #endif
+ for (UInt32 i = 0; i < g_NumArcs; i++)
+ {
+ const CArcInfo &arc = *g_Arcs[i];
+ CArcInfoEx item;
+ item.Name = arc.Name;
+ item.CreateInArchive = arc.CreateInArchive;
+ item.CreateOutArchive = arc.CreateOutArchive;
+ item.AddExts(arc.Ext, arc.AddExt);
+ item.UpdateEnabled = (arc.CreateOutArchive != 0);
+ item.KeepName = arc.KeepName;
+
+ #ifndef _SFX
+ SetBuffer(item.StartSignature, arc.Signature, arc.SignatureSize);
+ #endif
+ Formats.Add(item);
+ }
+ #ifdef EXTERNAL_CODECS
+ const CSysString baseFolder = GetBaseFolderPrefixFromRegistry();
+ RINOK(LoadDll(baseFolder + kMainDll, false));
+ RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName TEXT(STRING_PATH_SEPARATOR)));
+ RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName TEXT(STRING_PATH_SEPARATOR)));
+ #endif
+ return S_OK;
+}
+
+#ifndef _SFX
+
+int CCodecs::FindFormatForArchiveName(const UString &arcPath) const
+{
+ int slashPos1 = arcPath.ReverseFind(WCHAR_PATH_SEPARATOR);
+ int slashPos2 = arcPath.ReverseFind(L'.');
+ int dotPos = arcPath.ReverseFind(L'.');
+ if (dotPos < 0 || dotPos < slashPos1 || dotPos < slashPos2)
+ return -1;
+ UString ext = arcPath.Mid(dotPos + 1);
+ for (int i = 0; i < Formats.Size(); i++)
+ {
+ const CArcInfoEx &arc = Formats[i];
+ if (!arc.UpdateEnabled)
+ continue;
+ if (arc.FindExtension(ext) >= 0)
+ return i;
+ }
+ return -1;
+}
+
+int CCodecs::FindFormatForExtension(const UString &ext) const
+{
+ if (ext.IsEmpty())
+ return -1;
+ for (int i = 0; i < Formats.Size(); i++)
+ if (Formats[i].FindExtension(ext) >= 0)
+ return i;
+ return -1;
+}
+
+int CCodecs::FindFormatForArchiveType(const UString &arcType) const
+{
+ for (int i = 0; i < Formats.Size(); i++)
+ if (Formats[i].Name.CompareNoCase(arcType) == 0)
+ return i;
+ return -1;
+}
+
+bool CCodecs::FindFormatForArchiveType(const UString &arcType, CIntVector &formatIndices) const
+{
+ formatIndices.Clear();
+ for (int pos = 0; pos < arcType.Length();)
+ {
+ int pos2 = arcType.Find('.', pos);
+ if (pos2 < 0)
+ pos2 = arcType.Length();
+ const UString name = arcType.Mid(pos, pos2 - pos);
+ int index = FindFormatForArchiveType(name);
+ if (index < 0 && name != L"*")
+ {
+ formatIndices.Clear();
+ return false;
+ }
+ formatIndices.Add(index);
+ pos = pos2 + 1;
+ }
+ return true;
+}
+
+#endif
+
+#ifdef EXTERNAL_CODECS
+
+#ifdef EXPORT_CODECS
+extern unsigned int g_NumCodecs;
+STDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject);
+STDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value);
+// STDAPI GetNumberOfMethods(UInt32 *numCodecs);
+#endif
+
+STDMETHODIMP CCodecs::GetNumberOfMethods(UInt32 *numMethods)
+{
+ *numMethods =
+ #ifdef EXPORT_CODECS
+ g_NumCodecs +
+ #endif
+ Codecs.Size();
+ return S_OK;
+}
+
+STDMETHODIMP CCodecs::GetProperty(UInt32 index, PROPID propID, PROPVARIANT *value)
+{
+ #ifdef EXPORT_CODECS
+ if (index < g_NumCodecs)
+ return GetMethodProperty(index, propID, value);
+ #endif
+
+ const CDllCodecInfo &ci = Codecs[index
+ #ifdef EXPORT_CODECS
+ - g_NumCodecs
+ #endif
+ ];
+
+ if (propID == NMethodPropID::kDecoderIsAssigned)
+ {
+ NWindows::NCOM::CPropVariant propVariant;
+ propVariant = ci.DecoderIsAssigned;
+ propVariant.Detach(value);
+ return S_OK;
+ }
+ if (propID == NMethodPropID::kEncoderIsAssigned)
+ {
+ NWindows::NCOM::CPropVariant propVariant;
+ propVariant = ci.EncoderIsAssigned;
+ propVariant.Detach(value);
+ return S_OK;
+ }
+ return Libs[ci.LibIndex].GetMethodProperty(ci.CodecIndex, propID, value);
+}
+
+STDMETHODIMP CCodecs::CreateDecoder(UInt32 index, const GUID *iid, void **coder)
+{
+ #ifdef EXPORT_CODECS
+ if (index < g_NumCodecs)
+ return CreateCoder2(false, index, iid, coder);
+ #endif
+ const CDllCodecInfo &ci = Codecs[index
+ #ifdef EXPORT_CODECS
+ - g_NumCodecs
+ #endif
+ ];
+ if (ci.DecoderIsAssigned)
+ return Libs[ci.LibIndex].CreateObject(&ci.Decoder, iid, (void **)coder);
+ return S_OK;
+}
+
+STDMETHODIMP CCodecs::CreateEncoder(UInt32 index, const GUID *iid, void **coder)
+{
+ #ifdef EXPORT_CODECS
+ if (index < g_NumCodecs)
+ return CreateCoder2(true, index, iid, coder);
+ #endif
+ const CDllCodecInfo &ci = Codecs[index
+ #ifdef EXPORT_CODECS
+ - g_NumCodecs
+ #endif
+ ];
+ if (ci.EncoderIsAssigned)
+ return Libs[ci.LibIndex].CreateObject(&ci.Encoder, iid, (void **)coder);
+ return S_OK;
+}
+
+HRESULT CCodecs::CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const
+{
+ for (int i = 0; i < Codecs.Size(); i++)
+ {
+ const CDllCodecInfo &codec = Codecs[i];
+ if (encode && !codec.EncoderIsAssigned || !encode && !codec.DecoderIsAssigned)
+ continue;
+ const CCodecLib &lib = Libs[codec.LibIndex];
+ UString res;
+ NWindows::NCOM::CPropVariant prop;
+ RINOK(lib.GetMethodProperty(codec.CodecIndex, NMethodPropID::kName, &prop));
+ if (prop.vt == VT_BSTR)
+ res = prop.bstrVal;
+ else if (prop.vt != VT_EMPTY)
+ continue;
+ if (name.CompareNoCase(res) == 0)
+ return lib.CreateObject(encode ? &codec.Encoder : &codec.Decoder, &IID_ICompressCoder, (void **)&coder);
+ }
+ return CLASS_E_CLASSNOTAVAILABLE;
+}
+
+int CCodecs::GetCodecLibIndex(UInt32 index)
+{
+ #ifdef EXPORT_CODECS
+ if (index < g_NumCodecs)
+ return -1;
+ #endif
+ #ifdef EXTERNAL_CODECS
+ const CDllCodecInfo &ci = Codecs[index
+ #ifdef EXPORT_CODECS
+ - g_NumCodecs
+ #endif
+ ];
+ return ci.LibIndex;
+ #else
+ return -1;
+ #endif
+}
+
+bool CCodecs::GetCodecEncoderIsAssigned(UInt32 index)
+{
+ #ifdef EXPORT_CODECS
+ if (index < g_NumCodecs)
+ {
+ NWindows::NCOM::CPropVariant prop;
+ if (GetProperty(index, NMethodPropID::kEncoder, &prop) == S_OK)
+ if (prop.vt != VT_EMPTY)
+ return true;
+ return false;
+ }
+ #endif
+ #ifdef EXTERNAL_CODECS
+ const CDllCodecInfo &ci = Codecs[index
+ #ifdef EXPORT_CODECS
+ - g_NumCodecs
+ #endif
+ ];
+ return ci.EncoderIsAssigned;
+ #else
+ return false;
+ #endif
+}
+
+HRESULT CCodecs::GetCodecId(UInt32 index, UInt64 &id)
+{
+ UString s;
+ NWindows::NCOM::CPropVariant prop;
+ RINOK(GetProperty(index, NMethodPropID::kID, &prop));
+ if (prop.vt != VT_UI8)
+ return E_INVALIDARG;
+ id = prop.uhVal.QuadPart;
+ return S_OK;
+}
+
+UString CCodecs::GetCodecName(UInt32 index)
+{
+ UString s;
+ NWindows::NCOM::CPropVariant prop;
+ if (GetProperty(index, NMethodPropID::kName, &prop) == S_OK)
+ if (prop.vt == VT_BSTR)
+ s = prop.bstrVal;
+ return s;
+}
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/LoadCodecs.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/LoadCodecs.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/LoadCodecs.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/LoadCodecs.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,235 @@
+// LoadCodecs.h
+
+#ifndef __LOADCODECS_H
+#define __LOADCODECS_H
+
+#include "../../../Common/Types.h"
+#include "../../../Common/MyCom.h"
+#include "../../../Common/MyString.h"
+#include "../../../Common/Buffer.h"
+#include "../../ICoder.h"
+
+#ifdef EXTERNAL_CODECS
+#include "../../../Windows/DLL.h"
+#endif
+
+struct CDllCodecInfo
+{
+ CLSID Encoder;
+ CLSID Decoder;
+ bool EncoderIsAssigned;
+ bool DecoderIsAssigned;
+ int LibIndex;
+ UInt32 CodecIndex;
+};
+
+#include "../../Archive/IArchive.h"
+
+typedef IInArchive * (*CreateInArchiveP)();
+typedef IOutArchive * (*CreateOutArchiveP)();
+
+struct CArcExtInfo
+{
+ UString Ext;
+ UString AddExt;
+ CArcExtInfo() {}
+ CArcExtInfo(const UString &ext): Ext(ext) {}
+ CArcExtInfo(const UString &ext, const UString &addExt): Ext(ext), AddExt(addExt) {}
+};
+
+
+struct CArcInfoEx
+{
+ #ifdef EXTERNAL_CODECS
+ int LibIndex;
+ UInt32 FormatIndex;
+ CLSID ClassID;
+ #endif
+ bool UpdateEnabled;
+ CreateInArchiveP CreateInArchive;
+ CreateOutArchiveP CreateOutArchive;
+ UString Name;
+ CObjectVector<CArcExtInfo> Exts;
+ #ifndef _SFX
+ CByteBuffer StartSignature;
+ // CByteBuffer FinishSignature;
+ #ifdef NEW_FOLDER_INTERFACE
+ UStringVector AssociateExts;
+ #endif
+ #endif
+ bool KeepName;
+ UString GetMainExt() const
+ {
+ if (Exts.IsEmpty())
+ return UString();
+ return Exts[0].Ext;
+ }
+ int FindExtension(const UString &ext) const
+ {
+ for (int i = 0; i < Exts.Size(); i++)
+ if (ext.CompareNoCase(Exts[i].Ext) == 0)
+ return i;
+ return -1;
+ }
+ UString GetAllExtensions() const
+ {
+ UString s;
+ for (int i = 0; i < Exts.Size(); i++)
+ {
+ if (i > 0)
+ s += ' ';
+ s += Exts[i].Ext;
+ }
+ return s;
+ }
+
+ void AddExts(const wchar_t* ext, const wchar_t* addExt);
+
+ CArcInfoEx():
+ #ifdef EXTERNAL_CODECS
+ LibIndex(-1),
+ #endif
+ UpdateEnabled(false),
+ CreateInArchive(0), CreateOutArchive(0),
+ KeepName(false)
+ #ifndef _SFX
+ #endif
+ {}
+};
+
+#ifdef EXTERNAL_CODECS
+typedef UInt32 (WINAPI *GetMethodPropertyFunc)(UInt32 index, PROPID propID, PROPVARIANT *value);
+typedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *interfaceID, void **outObject);
+
+
+#ifdef NEW_FOLDER_INTERFACE
+struct CCodecIcons
+{
+ struct CIconPair
+ {
+ UString Ext;
+ int IconIndex;
+ };
+ CObjectVector<CIconPair> IconPairs;
+ void LoadIcons(HMODULE m);
+ bool FindIconIndex(const UString &ext, int &iconIndex) const;
+};
+#endif
+
+struct CCodecLib
+#ifdef NEW_FOLDER_INTERFACE
+: public CCodecIcons
+#endif
+{
+ NWindows::NDLL::CLibrary Lib;
+ GetMethodPropertyFunc GetMethodProperty;
+ CreateObjectFunc CreateObject;
+ #ifdef NEW_FOLDER_INTERFACE
+ CSysString Path;
+ void LoadIcons() { CCodecIcons::LoadIcons((HMODULE)Lib); }
+ #endif
+ CCodecLib(): GetMethodProperty(0) {}
+};
+#endif
+
+class CCodecs:
+ #ifdef EXTERNAL_CODECS
+ public ICompressCodecsInfo,
+ #else
+ public IUnknown,
+ #endif
+ public CMyUnknownImp
+{
+public:
+ #ifdef EXTERNAL_CODECS
+ CObjectVector<CCodecLib> Libs;
+ CObjectVector<CDllCodecInfo> Codecs;
+
+ #ifdef NEW_FOLDER_INTERFACE
+ CCodecIcons InternalIcons;
+ #endif
+
+ HRESULT LoadCodecs();
+ HRESULT LoadFormats();
+ HRESULT LoadDll(const CSysString &path, bool needCheckDll);
+ HRESULT LoadDllsFromFolder(const CSysString &folderPrefix);
+
+ HRESULT CreateArchiveHandler(const CArcInfoEx &ai, void **archive, bool outHandler) const
+ {
+ return Libs[ai.LibIndex].CreateObject(&ai.ClassID, outHandler ? &IID_IOutArchive : &IID_IInArchive, (void **)archive);
+ }
+ #endif
+
+public:
+ CObjectVector<CArcInfoEx> Formats;
+ HRESULT Load();
+
+ #ifndef _SFX
+ int FindFormatForArchiveName(const UString &arcPath) const;
+ int FindFormatForExtension(const UString &ext) const;
+ int FindFormatForArchiveType(const UString &arcType) const;
+ bool FindFormatForArchiveType(const UString &arcType, CIntVector &formatIndices) const;
+ #endif
+
+ MY_UNKNOWN_IMP
+
+ #ifdef EXTERNAL_CODECS
+ STDMETHOD(GetNumberOfMethods)(UInt32 *numMethods);
+ STDMETHOD(GetProperty)(UInt32 index, PROPID propID, PROPVARIANT *value);
+ STDMETHOD(CreateDecoder)(UInt32 index, const GUID *interfaceID, void **coder);
+ STDMETHOD(CreateEncoder)(UInt32 index, const GUID *interfaceID, void **coder);
+ #endif
+
+ int GetCodecLibIndex(UInt32 index);
+ bool GetCodecEncoderIsAssigned(UInt32 index);
+ HRESULT GetCodecId(UInt32 index, UInt64 &id);
+ UString GetCodecName(UInt32 index);
+
+ HRESULT CreateInArchive(int formatIndex, CMyComPtr<IInArchive> &archive) const
+ {
+ const CArcInfoEx &ai = Formats[formatIndex];
+ #ifdef EXTERNAL_CODECS
+ if (ai.LibIndex < 0)
+ #endif
+ {
+ archive = ai.CreateInArchive();
+ return S_OK;
+ }
+ #ifdef EXTERNAL_CODECS
+ return CreateArchiveHandler(ai, (void **)&archive, false);
+ #endif
+ }
+ HRESULT CreateOutArchive(int formatIndex, CMyComPtr<IOutArchive> &archive) const
+ {
+ const CArcInfoEx &ai = Formats[formatIndex];
+ #ifdef EXTERNAL_CODECS
+ if (ai.LibIndex < 0)
+ #endif
+ {
+ archive = ai.CreateOutArchive();
+ return S_OK;
+ }
+ #ifdef EXTERNAL_CODECS
+ return CreateArchiveHandler(ai, (void **)&archive, true);
+ #endif
+ }
+ int FindOutFormatFromName(const UString &name) const
+ {
+ for (int i = 0; i < Formats.Size(); i++)
+ {
+ const CArcInfoEx &arc = Formats[i];
+ if (!arc.UpdateEnabled)
+ continue;
+ if (arc.Name.CompareNoCase(name) == 0)
+ return i;
+ }
+ return -1;
+ }
+
+ #ifdef EXTERNAL_CODECS
+ HRESULT CreateCoder(const UString &name, bool encode, CMyComPtr<ICompressCoder> &coder) const;
+ #endif
+
+};
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/OpenArchive.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/OpenArchive.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/OpenArchive.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/OpenArchive.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,536 @@
+// OpenArchive.cpp
+
+#include "StdAfx.h"
+
+#include "Common/Wildcard.h"
+
+#include "Windows/FileDir.h"
+#include "Windows/PropVariant.h"
+
+#include "../../Common/FileStreams.h"
+#include "../../Common/StreamUtils.h"
+
+#include "DefaultName.h"
+#include "OpenArchive.h"
+
+using namespace NWindows;
+
+// Static-SFX (for Linux) can be big.
+const UInt64 kMaxCheckStartPosition = 1 << 22;
+
+HRESULT GetArchiveItemBoolProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result)
+{
+ NCOM::CPropVariant prop;
+ result = false;
+ RINOK(archive->GetProperty(index, propID, &prop));
+ if (prop.vt == VT_BOOL)
+ result = VARIANT_BOOLToBool(prop.boolVal);
+ else if (prop.vt != VT_EMPTY)
+ return E_FAIL;
+ return S_OK;
+}
+
+HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result)
+{
+ return GetArchiveItemBoolProp(archive, index, kpidIsDir, result);
+}
+
+HRESULT CArc::GetItemPath(UInt32 index, UString &result) const
+{
+ {
+ NCOM::CPropVariant prop;
+ RINOK(Archive->GetProperty(index, kpidPath, &prop));
+ if (prop.vt == VT_BSTR)
+ result = prop.bstrVal;
+ else if (prop.vt == VT_EMPTY)
+ result.Empty();
+ else
+ return E_FAIL;
+ }
+ if (result.IsEmpty())
+ {
+ result = DefaultName;
+ NCOM::CPropVariant prop;
+ RINOK(Archive->GetProperty(index, kpidExtension, &prop));
+ if (prop.vt == VT_BSTR)
+ {
+ result += L'.';
+ result += prop.bstrVal;
+ }
+ else if (prop.vt != VT_EMPTY)
+ return E_FAIL;
+ }
+ return S_OK;
+}
+
+HRESULT CArc::GetItemMTime(UInt32 index, FILETIME &ft, bool &defined) const
+{
+ NCOM::CPropVariant prop;
+ defined = false;
+ ft.dwHighDateTime = ft.dwLowDateTime = 0;
+ RINOK(Archive->GetProperty(index, kpidMTime, &prop));
+ if (prop.vt == VT_FILETIME)
+ {
+ ft = prop.filetime;
+ defined = true;
+ }
+ else if (prop.vt != VT_EMPTY)
+ return E_FAIL;
+ else if (MTimeDefined)
+ {
+ ft = MTime;
+ defined = true;
+ }
+ return S_OK;
+}
+
+#ifndef _SFX
+static inline bool TestSignature(const Byte *p1, const Byte *p2, size_t size)
+{
+ for (size_t i = 0; i < size; i++)
+ if (p1[i] != p2[i])
+ return false;
+ return true;
+}
+#endif
+
+#ifdef UNDER_CE
+static const int kNumHashBytes = 1;
+#define HASH_VAL(buf, pos) ((buf)[pos])
+#else
+static const int kNumHashBytes = 2;
+#define HASH_VAL(buf, pos) ((buf)[pos] | ((UInt32)(buf)[pos + 1] << 8))
+#endif
+
+
+HRESULT CArc::OpenStream(
+ CCodecs *codecs,
+ int formatIndex,
+ IInStream *stream,
+ ISequentialInStream *seqStream,
+ IArchiveOpenCallback *callback)
+{
+ Archive.Release();
+ ErrorMessage.Empty();
+ const UString fileName = ExtractFileNameFromPath(Path);
+ UString extension;
+ {
+ int dotPos = fileName.ReverseFind(L'.');
+ if (dotPos >= 0)
+ extension = fileName.Mid(dotPos + 1);
+ }
+ CIntVector orderIndices;
+ if (formatIndex >= 0)
+ orderIndices.Add(formatIndex);
+ else
+ {
+
+ int i;
+ int numFinded = 0;
+ for (i = 0; i < codecs->Formats.Size(); i++)
+ if (codecs->Formats[i].FindExtension(extension) >= 0)
+ orderIndices.Insert(numFinded++, i);
+ else
+ orderIndices.Add(i);
+
+ if (!stream)
+ {
+ if (numFinded != 1)
+ return E_NOTIMPL;
+ orderIndices.DeleteFrom(1);
+ }
+
+ #ifndef _SFX
+ if (orderIndices.Size() >= 2 && (numFinded == 0 || extension.CompareNoCase(L"exe") == 0))
+ {
+ CIntVector orderIndices2;
+ CByteBuffer byteBuffer;
+ const size_t kBufferSize = (1 << 21);
+ byteBuffer.SetCapacity(kBufferSize);
+ RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
+ size_t processedSize = kBufferSize;
+ RINOK(ReadStream(stream, byteBuffer, &processedSize));
+ if (processedSize == 0)
+ return S_FALSE;
+
+ const Byte *buf = byteBuffer;
+ CByteBuffer hashBuffer;
+ const UInt32 kNumVals = 1 << (kNumHashBytes * 8);
+ hashBuffer.SetCapacity(kNumVals);
+ Byte *hash = hashBuffer;
+ memset(hash, 0xFF, kNumVals);
+ Byte prevs[256];
+ if (orderIndices.Size() >= 256)
+ return S_FALSE;
+ int i;
+ for (i = 0; i < orderIndices.Size(); i++)
+ {
+ const CArcInfoEx &ai = codecs->Formats[orderIndices[i]];
+ const CByteBuffer &sig = ai.StartSignature;
+ if (sig.GetCapacity() < kNumHashBytes)
+ continue;
+ UInt32 v = HASH_VAL(sig, 0);
+ prevs[i] = hash[v];
+ hash[v] = (Byte)i;
+ }
+
+ processedSize -= (kNumHashBytes - 1);
+ for (UInt32 pos = 0; pos < processedSize; pos++)
+ {
+ for (; pos < processedSize && hash[HASH_VAL(buf, pos)] == 0xFF; pos++);
+ if (pos == processedSize)
+ break;
+ UInt32 v = HASH_VAL(buf, pos);
+ Byte *ptr = &hash[v];
+ int i = *ptr;
+ do
+ {
+ int index = orderIndices[i];
+ const CArcInfoEx &ai = codecs->Formats[index];
+ const CByteBuffer &sig = ai.StartSignature;
+ if (sig.GetCapacity() != 0 && pos + sig.GetCapacity() <= processedSize + (kNumHashBytes - 1) &&
+ TestSignature(buf + pos, sig, sig.GetCapacity()))
+ {
+ orderIndices2.Add(index);
+ orderIndices[i] = 0xFF;
+ *ptr = prevs[i];
+ }
+ else
+ ptr = &prevs[i];
+ i = *ptr;
+ }
+ while (i != 0xFF);
+ }
+
+ for (i = 0; i < orderIndices.Size(); i++)
+ {
+ int val = orderIndices[i];
+ if (val != 0xFF)
+ orderIndices2.Add(val);
+ }
+ orderIndices = orderIndices2;
+ }
+ else if (extension == L"000" || extension == L"001")
+ {
+ CByteBuffer byteBuffer;
+ const size_t kBufferSize = (1 << 10);
+ byteBuffer.SetCapacity(kBufferSize);
+ Byte *buffer = byteBuffer;
+ RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
+ size_t processedSize = kBufferSize;
+ RINOK(ReadStream(stream, buffer, &processedSize));
+ if (processedSize >= 16)
+ {
+ Byte kRarHeader[] = {0x52 , 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00};
+ if (TestSignature(buffer, kRarHeader, 7) && buffer[9] == 0x73 && (buffer[10] & 1) != 0)
+ {
+ for (int i = 0; i < orderIndices.Size(); i++)
+ {
+ int index = orderIndices[i];
+ const CArcInfoEx &ai = codecs->Formats[index];
+ if (ai.Name.CompareNoCase(L"rar") != 0)
+ continue;
+ orderIndices.Delete(i--);
+ orderIndices.Insert(0, index);
+ break;
+ }
+ }
+ }
+ }
+ if (orderIndices.Size() >= 2)
+ {
+ int isoIndex = codecs->FindFormatForArchiveType(L"iso");
+ int udfIndex = codecs->FindFormatForArchiveType(L"udf");
+ int iIso = -1;
+ int iUdf = -1;
+ for (int i = 0; i < orderIndices.Size(); i++)
+ {
+ if (orderIndices[i] == isoIndex) iIso = i;
+ if (orderIndices[i] == udfIndex) iUdf = i;
+ }
+ if (iUdf > iIso && iIso >= 0)
+ {
+ orderIndices[iUdf] = isoIndex;
+ orderIndices[iIso] = udfIndex;
+ }
+ }
+
+ #endif
+ }
+
+ for (int i = 0; i < orderIndices.Size(); i++)
+ {
+ if (stream)
+ {
+ RINOK(stream->Seek(0, STREAM_SEEK_SET, NULL));
+ }
+ CMyComPtr<IInArchive> archive;
+
+ FormatIndex = orderIndices[i];
+ RINOK(codecs->CreateInArchive(FormatIndex, archive));
+ if (!archive)
+ continue;
+
+ #ifdef EXTERNAL_CODECS
+ {
+ CMyComPtr<ISetCompressCodecsInfo> setCompressCodecsInfo;
+ archive.QueryInterface(IID_ISetCompressCodecsInfo, (void **)&setCompressCodecsInfo);
+ if (setCompressCodecsInfo)
+ {
+ RINOK(setCompressCodecsInfo->SetCompressCodecsInfo(codecs));
+ }
+ }
+ #endif
+
+ // OutputDebugStringW(codecs->Formats[FormatIndex].Name);
+
+ HRESULT result;
+ if (stream)
+ result = archive->Open(stream, &kMaxCheckStartPosition, callback);
+ else
+ {
+ CMyComPtr<IArchiveOpenSeq> openSeq;
+ archive.QueryInterface(IID_IArchiveOpenSeq, (void **)&openSeq);
+ if (!openSeq)
+ return E_NOTIMPL;
+ result = openSeq->OpenSeq(seqStream);
+ }
+
+ if (result == S_FALSE)
+ continue;
+ RINOK(result);
+
+ {
+ NCOM::CPropVariant prop;
+ archive->GetArchiveProperty(kpidError, &prop);
+ if (prop.vt != VT_EMPTY)
+ ErrorMessage = (prop.vt == VT_BSTR) ? prop.bstrVal : L"Unknown error";
+ }
+
+ Archive = archive;
+ const CArcInfoEx &format = codecs->Formats[FormatIndex];
+ if (format.Exts.Size() == 0)
+ DefaultName = GetDefaultName2(fileName, L"", L"");
+ else
+ {
+ int subExtIndex = format.FindExtension(extension);
+ if (subExtIndex < 0)
+ subExtIndex = 0;
+ const CArcExtInfo &extInfo = format.Exts[subExtIndex];
+ DefaultName = GetDefaultName2(fileName, extInfo.Ext, extInfo.AddExt);
+ }
+ return S_OK;
+ }
+ return S_FALSE;
+}
+
+HRESULT CArc::OpenStreamOrFile(
+ CCodecs *codecs,
+ int formatIndex,
+ bool stdInMode,
+ IInStream *stream,
+ IArchiveOpenCallback *callback)
+{
+ CMyComPtr<IInStream> fileStream;
+ CMyComPtr<ISequentialInStream> seqStream;
+ if (stdInMode)
+ seqStream = new CStdInFileStream;
+ else if (!stream)
+ {
+ CInFileStream *fileStreamSpec = new CInFileStream(true);
+ fileStream = fileStreamSpec;
+ if (!fileStreamSpec->Open(Path))
+ return GetLastError();
+ stream = fileStream;
+ }
+
+ /*
+ if (callback)
+ {
+ UInt64 fileSize;
+ RINOK(stream->Seek(0, STREAM_SEEK_END, &fileSize));
+ RINOK(callback->SetTotal(NULL, &fileSize))
+ }
+ */
+
+ return OpenStream(codecs, formatIndex, stream, seqStream, callback);
+}
+
+HRESULT CArchiveLink::Close()
+{
+ for (int i = Arcs.Size() - 1; i >= 0; i--)
+ {
+ RINOK(Arcs[i].Archive->Close());
+ }
+ IsOpen = false;
+ return S_OK;
+}
+
+void CArchiveLink::Release()
+{
+ while (!Arcs.IsEmpty())
+ Arcs.DeleteBack();
+}
+
+HRESULT CArchiveLink::Open(
+ CCodecs *codecs,
+ const CIntVector &formatIndices,
+ bool stdInMode,
+ IInStream *stream,
+ const UString &filePath,
+ IArchiveOpenCallback *callback)
+{
+ Release();
+ if (formatIndices.Size() >= 32)
+ return E_NOTIMPL;
+
+ HRESULT resSpec;
+
+ for (;;)
+ {
+ resSpec = S_OK;
+ int formatIndex = -1;
+ if (formatIndices.Size() >= 1)
+ {
+ if (Arcs.Size() >= formatIndices.Size())
+ break;
+ formatIndex = formatIndices[formatIndices.Size() - Arcs.Size() - 1];
+ }
+ else if (Arcs.Size() >= 32)
+ break;
+
+ if (Arcs.IsEmpty())
+ {
+ CArc arc;
+ arc.Path = filePath;
+ arc.SubfileIndex = (UInt32)(Int32)-1;
+ RINOK(arc.OpenStreamOrFile(codecs, formatIndex, stdInMode, stream, callback));
+ Arcs.Add(arc);
+ continue;
+ }
+
+ const CArc &arc = Arcs.Back();
+
+ resSpec = (formatIndices.Size() == 0 ? S_OK : E_NOTIMPL);
+
+ UInt32 mainSubfile;
+ {
+ NCOM::CPropVariant prop;
+ RINOK(arc.Archive->GetArchiveProperty(kpidMainSubfile, &prop));
+ if (prop.vt == VT_UI4)
+ mainSubfile = prop.ulVal;
+ else
+ break;
+ UInt32 numItems;
+ RINOK(arc.Archive->GetNumberOfItems(&numItems));
+ if (mainSubfile >= numItems)
+ break;
+ }
+
+
+ CMyComPtr<IInArchiveGetStream> getStream;
+ if (arc.Archive->QueryInterface(IID_IInArchiveGetStream, (void **)&getStream) != S_OK || !getStream)
+ break;
+
+ CMyComPtr<ISequentialInStream> subSeqStream;
+ if (getStream->GetStream(mainSubfile, &subSeqStream) != S_OK || !subSeqStream)
+ break;
+
+ CMyComPtr<IInStream> subStream;
+ if (subSeqStream.QueryInterface(IID_IInStream, &subStream) != S_OK || !subStream)
+ break;
+
+ CArc arc2;
+ RINOK(arc.GetItemPath(mainSubfile, arc2.Path));
+
+ CMyComPtr<IArchiveOpenSetSubArchiveName> setSubArchiveName;
+ callback->QueryInterface(IID_IArchiveOpenSetSubArchiveName, (void **)&setSubArchiveName);
+ if (setSubArchiveName)
+ setSubArchiveName->SetSubArchiveName(arc2.Path);
+
+ arc2.SubfileIndex = mainSubfile;
+ HRESULT result = arc2.OpenStream(codecs, formatIndex, subStream, NULL, callback);
+ resSpec = (formatIndices.Size() == 0 ? S_OK : S_FALSE);
+ if (result == S_FALSE)
+ break;
+ RINOK(result);
+ RINOK(arc.GetItemMTime(mainSubfile, arc2.MTime, arc2.MTimeDefined));
+ Arcs.Add(arc2);
+ }
+ IsOpen = !Arcs.IsEmpty();
+ return S_OK;
+}
+
+static void SetCallback(const UString &filePath,
+ IOpenCallbackUI *callbackUI,
+ IArchiveOpenCallback *reOpenCallback,
+ CMyComPtr<IArchiveOpenCallback> &callback)
+{
+ COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;
+ callback = openCallbackSpec;
+ openCallbackSpec->Callback = callbackUI;
+ openCallbackSpec->ReOpenCallback = reOpenCallback;
+
+ UString fullName;
+ int fileNamePartStartIndex;
+ NFile::NDirectory::MyGetFullPathName(filePath, fullName, fileNamePartStartIndex);
+ openCallbackSpec->Init(
+ fullName.Left(fileNamePartStartIndex),
+ fullName.Mid(fileNamePartStartIndex));
+}
+
+HRESULT CArchiveLink::Open2(CCodecs *codecs,
+ const CIntVector &formatIndices,
+ bool stdInMode,
+ IInStream *stream,
+ const UString &filePath,
+ IOpenCallbackUI *callbackUI)
+{
+ VolumesSize = 0;
+ COpenCallbackImp *openCallbackSpec = new COpenCallbackImp;
+ CMyComPtr<IArchiveOpenCallback> callback = openCallbackSpec;
+ openCallbackSpec->Callback = callbackUI;
+
+ UString fullName, prefix, name;
+ if (!stream && !stdInMode)
+ {
+ int fileNamePartStartIndex;
+ if (!NFile::NDirectory::MyGetFullPathName(filePath, fullName, fileNamePartStartIndex))
+ return GetLastError();
+ prefix = fullName.Left(fileNamePartStartIndex);
+ name = fullName.Mid(fileNamePartStartIndex);
+ openCallbackSpec->Init(prefix, name);
+ }
+ else
+ {
+ openCallbackSpec->SetSubArchiveName(filePath);
+ }
+
+ RINOK(Open(codecs, formatIndices, stdInMode, stream, filePath, callback));
+ VolumePaths.Add(prefix + name);
+ for (int i = 0; i < openCallbackSpec->FileNames.Size(); i++)
+ VolumePaths.Add(prefix + openCallbackSpec->FileNames[i]);
+ VolumesSize = openCallbackSpec->TotalSize;
+ return S_OK;
+}
+
+HRESULT CArchiveLink::ReOpen(CCodecs *codecs, const UString &filePath,
+ IArchiveOpenCallback *callback)
+{
+ if (Arcs.Size() > 1)
+ return E_NOTIMPL;
+
+ if (Arcs.Size() == 0)
+ return Open2(codecs, CIntVector(), false, NULL, filePath, 0);
+
+ CMyComPtr<IArchiveOpenCallback> openCallbackNew;
+ SetCallback(filePath, NULL, callback, openCallbackNew);
+
+ CInFileStream *fileStreamSpec = new CInFileStream(true);
+ CMyComPtr<IInStream> stream(fileStreamSpec);
+ if (!fileStreamSpec->Open(filePath))
+ return GetLastError();
+ HRESULT res = GetArchive()->Open(stream, &kMaxCheckStartPosition, callback);
+ IsOpen = (res == S_OK);
+ return res;
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/OpenArchive.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/OpenArchive.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/OpenArchive.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/OpenArchive.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,87 @@
+// OpenArchive.h
+
+#ifndef __OPEN_ARCHIVE_H
+#define __OPEN_ARCHIVE_H
+
+#include "Common/MyString.h"
+
+#include "Windows/FileFind.h"
+
+#include "../../Archive/IArchive.h"
+
+#include "ArchiveOpenCallback.h"
+#include "LoadCodecs.h"
+
+HRESULT GetArchiveItemBoolProp(IInArchive *archive, UInt32 index, PROPID propID, bool &result);
+HRESULT IsArchiveItemFolder(IInArchive *archive, UInt32 index, bool &result);
+
+struct CArc
+{
+ CMyComPtr<IInArchive> Archive;
+ UString Path;
+ UString DefaultName;
+ int FormatIndex;
+ int SubfileIndex;
+ FILETIME MTime;
+ bool MTimeDefined;
+ UString ErrorMessage;
+
+ CArc(): MTimeDefined(false) {}
+
+ HRESULT GetItemPath(UInt32 index, UString &result) const;
+ HRESULT GetItemMTime(UInt32 index, FILETIME &ft, bool &defined) const;
+ HRESULT IsItemAnti(UInt32 index, bool &result) const
+ { return GetArchiveItemBoolProp(Archive, index, kpidIsAnti, result); }
+
+ HRESULT OpenStream(
+ CCodecs *codecs,
+ int formatIndex,
+ IInStream *stream,
+ ISequentialInStream *seqStream,
+ IArchiveOpenCallback *callback);
+
+ HRESULT OpenStreamOrFile(
+ CCodecs *codecs,
+ int formatIndex,
+ bool stdInMode,
+ IInStream *stream,
+ IArchiveOpenCallback *callback);
+};
+
+struct CArchiveLink
+{
+ CObjectVector<CArc> Arcs;
+ UStringVector VolumePaths;
+ UInt64 VolumesSize;
+ bool IsOpen;
+
+ CArchiveLink(): VolumesSize(0), IsOpen(false) {}
+ HRESULT Close();
+ void Release();
+ ~CArchiveLink() { Release(); }
+
+ IInArchive *GetArchive() const { return Arcs.Back().Archive; }
+
+ HRESULT Open(
+ CCodecs *codecs,
+ const CIntVector &formatIndices,
+ bool stdInMode,
+ IInStream *stream,
+ const UString &filePath,
+ IArchiveOpenCallback *callback);
+
+ HRESULT Open2(
+ CCodecs *codecs,
+ const CIntVector &formatIndices,
+ bool stdInMode,
+ IInStream *stream,
+ const UString &filePath,
+ IOpenCallbackUI *callbackUI);
+
+ HRESULT ReOpen(
+ CCodecs *codecs,
+ const UString &filePath,
+ IArchiveOpenCallback *callback);
+};
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/PropIDUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/PropIDUtils.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/PropIDUtils.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/PropIDUtils.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,120 @@
+// PropIDUtils.cpp
+
+#include "StdAfx.h"
+
+#include "Common/IntToString.h"
+
+#include "Windows/FileFind.h"
+#include "Windows/PropVariantConversions.h"
+
+#include "../../PropID.h"
+
+#include "PropIDUtils.h"
+
+using namespace NWindows;
+
+void ConvertUInt32ToHex(UInt32 value, wchar_t *s)
+{
+ for (int i = 0; i < 8; i++)
+ {
+ int t = value & 0xF;
+ value >>= 4;
+ s[7 - i] = (wchar_t)((t < 10) ? (L'0' + t) : (L'A' + (t - 10)));
+ }
+ s[8] = L'\0';
+}
+
+static const char g_WinAttrib[17] = "RHS8DAdNTsrCOnE_";
+/*
+0 READONLY
+1 HIDDEN
+3 SYSTEM
+
+4 DIRECTORY
+5 ARCHIVE
+6 DEVICE
+7 NORMAL
+8 TEMPORARY
+9 SPARSE_FILE
+10 REPARSE_POINT
+11 COMPRESSED
+12 OFFLINE
+13 NOT_CONTENT_INDEXED
+14 ENCRYPTED
+
+16 VIRTUAL
+*/
+
+static const char kPosixTypes[16] = { '0', 'p', 'c', '3', 'd', '5', 'b', '7', '-', '9', 'l', 'B', 's', 'D', 'E', 'F' };
+#define MY_ATTR_CHAR(a, n, c) ((a )& (1 << (n))) ? c : L'-';
+
+UString ConvertPropertyToString(const PROPVARIANT &prop, PROPID propID, bool full)
+{
+ switch(propID)
+ {
+ case kpidCTime:
+ case kpidATime:
+ case kpidMTime:
+ {
+ if (prop.vt != VT_FILETIME)
+ break;
+ FILETIME localFileTime;
+ if ((prop.filetime.dwHighDateTime == 0 &&
+ prop.filetime.dwLowDateTime == 0) ||
+ !::FileTimeToLocalFileTime(&prop.filetime, &localFileTime))
+ return UString();
+ return ConvertFileTimeToString(localFileTime, true, full);
+ }
+ case kpidCRC:
+ {
+ if (prop.vt != VT_UI4)
+ break;
+ wchar_t temp[12];
+ ConvertUInt32ToHex(prop.ulVal, temp);
+ return temp;
+ }
+ case kpidAttrib:
+ {
+ if (prop.vt != VT_UI4)
+ break;
+ UInt32 a = prop.ulVal;
+ wchar_t sz[32];
+ int pos = 0;
+ for (int i = 0; i < 16; i++)
+ if (a & (1 << i) && i != 7)
+ sz[pos++] = g_WinAttrib[i];
+ sz[pos] = '\0';
+ return sz;
+ }
+ case kpidPosixAttrib:
+ {
+ if (prop.vt != VT_UI4)
+ break;
+ UString res;
+ UInt32 a = prop.ulVal;
+ wchar_t temp[16];
+
+ temp[0] = kPosixTypes[(a >> 12) & 0xF];
+ for (int i = 6; i >= 0; i -= 3)
+ {
+ temp[7 - i] = MY_ATTR_CHAR(a, i + 2, L'r');
+ temp[8 - i] = MY_ATTR_CHAR(a, i + 1, L'w');
+ temp[9 - i] = MY_ATTR_CHAR(a, i + 0, L'x');
+ }
+ if ((a & 0x800) != 0) temp[3] = ((a & (1 << 6)) ? 's' : 'S');
+ if ((a & 0x400) != 0) temp[6] = ((a & (1 << 3)) ? 's' : 'S');
+ if ((a & 0x200) != 0) temp[9] = ((a & (1 << 0)) ? 't' : 'T');
+ temp[10] = 0;
+ res = temp;
+
+ a &= ~(UInt32)0xFFFF;
+ if (a != 0)
+ {
+ ConvertUInt32ToHex(a, temp);
+ res = UString(temp) + L' ' + res;
+ }
+ return res;
+ }
+ }
+ return ConvertPropVariantToString(prop);
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/PropIDUtils.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/PropIDUtils.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/PropIDUtils.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/PropIDUtils.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,12 @@
+// PropIDUtils.h
+
+#ifndef __PROPID_UTILS_H
+#define __PROPID_UTILS_H
+
+#include "Common/MyString.h"
+#include "Common/Types.h"
+
+void ConvertUInt32ToHex(UInt32 value, wchar_t *s);
+UString ConvertPropertyToString(const PROPVARIANT &propVariant, PROPID propID, bool full = true);
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Property.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Property.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Property.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/Property.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,14 @@
+// Property.h
+
+#ifndef __PROPERTY_H
+#define __PROPERTY_H
+
+#include "Common/MyString.h"
+
+struct CProperty
+{
+ UString Name;
+ UString Value;
+};
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SetProperties.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SetProperties.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SetProperties.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SetProperties.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,79 @@
+// SetProperties.cpp
+
+#include "StdAfx.h"
+
+#include "SetProperties.h"
+
+#include "Windows/PropVariant.h"
+#include "Common/MyString.h"
+#include "Common/StringToInt.h"
+#include "Common/MyCom.h"
+
+#include "../../Archive/IArchive.h"
+
+using namespace NWindows;
+using namespace NCOM;
+
+static void ParseNumberString(const UString &s, NCOM::CPropVariant &prop)
+{
+ const wchar_t *endPtr;
+ UInt64 result = ConvertStringToUInt64(s, &endPtr);
+ if (endPtr - (const wchar_t *)s != s.Length())
+ prop = s;
+ else if (result <= 0xFFFFFFFF)
+ prop = (UInt32)result;
+ else
+ prop = result;
+}
+
+HRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties)
+{
+ if (properties.IsEmpty())
+ return S_OK;
+ CMyComPtr<ISetProperties> setProperties;
+ unknown->QueryInterface(IID_ISetProperties, (void **)&setProperties);
+ if (!setProperties)
+ return S_OK;
+
+ UStringVector realNames;
+ CPropVariant *values = new CPropVariant[properties.Size()];
+ try
+ {
+ int i;
+ for(i = 0; i < properties.Size(); i++)
+ {
+ const CProperty &property = properties[i];
+ NCOM::CPropVariant propVariant;
+ UString name = property.Name;
+ if (property.Value.IsEmpty())
+ {
+ if (!name.IsEmpty())
+ {
+ wchar_t c = name[name.Length() - 1];
+ if (c == L'-')
+ propVariant = false;
+ else if (c == L'+')
+ propVariant = true;
+ if (propVariant.vt != VT_EMPTY)
+ name = name.Left(name.Length() - 1);
+ }
+ }
+ else
+ ParseNumberString(property.Value, propVariant);
+ realNames.Add(name);
+ values[i] = propVariant;
+ }
+ CRecordVector<const wchar_t *> names;
+ for(i = 0; i < realNames.Size(); i++)
+ names.Add((const wchar_t *)realNames[i]);
+
+ RINOK(setProperties->SetProperties(&names.Front(), values, names.Size()));
+ }
+ catch(...)
+ {
+ delete []values;
+ throw;
+ }
+ delete []values;
+ return S_OK;
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SetProperties.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SetProperties.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SetProperties.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SetProperties.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,10 @@
+// SetProperties.h
+
+#ifndef __SETPROPERTIES_H
+#define __SETPROPERTIES_H
+
+#include "Property.h"
+
+HRESULT SetProperties(IUnknown *unknown, const CObjectVector<CProperty> &properties);
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SortUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SortUtils.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SortUtils.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SortUtils.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,22 @@
+// SortUtils.cpp
+
+#include "StdAfx.h"
+
+#include "SortUtils.h"
+#include "Common/Wildcard.h"
+
+static int CompareStrings(const int *p1, const int *p2, void *param)
+{
+ const UStringVector &strings = *(const UStringVector *)param;
+ return CompareFileNames(strings[*p1], strings[*p2]);
+}
+
+void SortFileNames(const UStringVector &strings, CIntVector &indices)
+{
+ indices.Clear();
+ int numItems = strings.Size();
+ indices.Reserve(numItems);
+ for(int i = 0; i < numItems; i++)
+ indices.Add(i);
+ indices.Sort(CompareStrings, (void *)&strings);
+}
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SortUtils.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SortUtils.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SortUtils.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/SortUtils.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,10 @@
+// SortUtils.h
+
+#ifndef __SORTUTLS_H
+#define __SORTUTLS_H
+
+#include "Common/MyString.h"
+
+void SortFileNames(const UStringVector &strings, CIntVector &indices);
+
+#endif
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/TempFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/TempFiles.cpp?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/TempFiles.cpp (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/TempFiles.cpp Sun Dec 16 23:23:25 2012
@@ -0,0 +1,22 @@
+// TempFiles.cpp
+
+#include "StdAfx.h"
+
+#include "TempFiles.h"
+
+#include "Windows/FileDir.h"
+#include "Windows/FileIO.h"
+
+using namespace NWindows;
+using namespace NFile;
+
+void CTempFiles::Clear()
+{
+ while(!Paths.IsEmpty())
+ {
+ NDirectory::DeleteFileAlways((LPCWSTR)Paths.Back());
+ Paths.DeleteBack();
+ }
+}
+
+
Added: test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/TempFiles.h
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/TempFiles.h?rev=170306&view=auto
==============================================================================
--- test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/TempFiles.h (added)
+++ test-suite/trunk/MultiSource/Benchmarks/7zip/CPP/7zip/UI/Common/TempFiles.h Sun Dec 16 23:23:25 2012
@@ -0,0 +1,16 @@
+// TempFiles.h
+
+#ifndef __TEMPFILES_H
+#define __TEMPFILES_H
+
+#include "Common/MyString.h"
+
+class CTempFiles
+{
+ void Clear();
+public:
+ UStringVector Paths;
+ ~CTempFiles() { Clear(); }
+};
+
+#endif
More information about the llvm-commits
mailing list